From c9fabe0b5459eb549e3cff0ce408dc73adcc383d Mon Sep 17 00:00:00 2001 From: in2 Date: Thu, 7 Mar 2002 15:13:44 +0000 Subject: Initial revision git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@1 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/.cvsignore | 2 + pttbbs/LICENSE | 340 ++++ pttbbs/Makefile | 9 + pttbbs/README | 12 + pttbbs/docs/ANCESTOR | 23 + pttbbs/docs/CHANGE | 76 + pttbbs/docs/FAQ | 146 ++ pttbbs/docs/INSTALL | 49 + pttbbs/include/common.h | 198 ++ pttbbs/include/config.h | 197 ++ pttbbs/include/gomo.h | 2156 ++++++++++++++++++++ pttbbs/include/modes.h | 152 ++ pttbbs/include/perm.h | 56 + pttbbs/include/proto.h | 522 +++++ pttbbs/include/pttbbs.conf | 17 + pttbbs/include/pttstruct.h | 390 ++++ pttbbs/include/pttstruct.h.save | 363 ++++ pttbbs/innbbsd/.cvsignore | 6 + pttbbs/innbbsd/Makefile | 206 ++ pttbbs/innbbsd/antisplam.h | 37 + pttbbs/innbbsd/bbslib.c | 712 +++++++ pttbbs/innbbsd/bbslib.h | 62 + pttbbs/innbbsd/bbslink.c | 2021 ++++++++++++++++++ pttbbs/innbbsd/bbslink2.c | 2017 ++++++++++++++++++ pttbbs/innbbsd/bbsnnrp.c | 1187 +++++++++++ pttbbs/innbbsd/clibrary.h | 131 ++ pttbbs/innbbsd/closeonexec.c | 66 + pttbbs/innbbsd/connectsock.c | 452 ++++ pttbbs/innbbsd/ctlinnbbsd.c | 160 ++ pttbbs/innbbsd/daemon.c | 173 ++ pttbbs/innbbsd/daemon.h | 54 + pttbbs/innbbsd/dbz.c | 1918 +++++++++++++++++ pttbbs/innbbsd/dbz.h | 32 + pttbbs/innbbsd/dbztool.c | 88 + pttbbs/innbbsd/echobbslib.c | 713 +++++++ pttbbs/innbbsd/externs.h | 16 + pttbbs/innbbsd/file.c | 185 ++ pttbbs/innbbsd/his.c | 474 +++++ pttbbs/innbbsd/his.h | 80 + pttbbs/innbbsd/innbbsconf.h | 192 ++ pttbbs/innbbsd/innbbsd.c | 775 +++++++ pttbbs/innbbsd/innbbsd.h | 9 + pttbbs/innbbsd/inndchannel.c | 657 ++++++ pttbbs/innbbsd/inntobbs.c | 323 +++ pttbbs/innbbsd/inntobbs.h | 39 + pttbbs/innbbsd/mkhistory.c | 14 + pttbbs/innbbsd/nntp.h | 145 ++ pttbbs/innbbsd/pmain.c | 62 + pttbbs/innbbsd/port.c | 28 + pttbbs/innbbsd/receive_article.c | 1204 +++++++++++ pttbbs/innbbsd/rfc931.c | 144 ++ pttbbs/mbbsd/.cvsignore | 2 + pttbbs/mbbsd/Makefile | 45 + pttbbs/mbbsd/admin.c | 1105 ++++++++++ pttbbs/mbbsd/announce.c | 1590 +++++++++++++++ pttbbs/mbbsd/args.c | 62 + pttbbs/mbbsd/bbcall.c | 268 +++ pttbbs/mbbsd/bbs.c | 1904 +++++++++++++++++ pttbbs/mbbsd/board.c | 1098 ++++++++++ pttbbs/mbbsd/cache.c | 1053 ++++++++++ pttbbs/mbbsd/cal.c | 512 +++++ pttbbs/mbbsd/calendar.c | 284 +++ pttbbs/mbbsd/card.c | 625 ++++++ pttbbs/mbbsd/chat.c | 623 ++++++ pttbbs/mbbsd/chc_draw.c | 187 ++ pttbbs/mbbsd/chc_net.c | 28 + pttbbs/mbbsd/chc_play.c | 277 +++ pttbbs/mbbsd/chc_rule.c | 186 ++ pttbbs/mbbsd/chicken.c | 989 +++++++++ pttbbs/mbbsd/dark.c | 456 +++++ pttbbs/mbbsd/descrypt.c | 616 ++++++ pttbbs/mbbsd/dice.c | 447 ++++ pttbbs/mbbsd/edit.c | 2256 ++++++++++++++++++++ pttbbs/mbbsd/friend.c | 509 +++++ pttbbs/mbbsd/gamble.c | 361 ++++ pttbbs/mbbsd/gomo.c | 417 ++++ pttbbs/mbbsd/gomo1.c | 136 ++ pttbbs/mbbsd/guess.c | 364 ++++ pttbbs/mbbsd/indict.c | 184 ++ pttbbs/mbbsd/io.c | 611 ++++++ pttbbs/mbbsd/kaede.c | 95 + pttbbs/mbbsd/lovepaper.c | 120 ++ pttbbs/mbbsd/mail.c | 1675 +++++++++++++++ pttbbs/mbbsd/mbbsd.c | 1465 +++++++++++++ pttbbs/mbbsd/menu.c | 596 ++++++ pttbbs/mbbsd/more.c | 931 +++++++++ pttbbs/mbbsd/name.c | 473 +++++ pttbbs/mbbsd/osdep.c | 79 + pttbbs/mbbsd/othello.c | 541 +++++ pttbbs/mbbsd/page.c | 130 ++ pttbbs/mbbsd/passwd.c | 138 ++ pttbbs/mbbsd/read.c | 998 +++++++++ pttbbs/mbbsd/record.c | 536 +++++ pttbbs/mbbsd/register.c | 339 +++ pttbbs/mbbsd/screen.c | 559 +++++ pttbbs/mbbsd/stuff.c | 524 +++++ pttbbs/mbbsd/syspost.c | 102 + pttbbs/mbbsd/talk.c | 2663 ++++++++++++++++++++++++ pttbbs/mbbsd/term.c | 144 ++ pttbbs/mbbsd/toolkit.c | 14 + pttbbs/mbbsd/topsong.c | 79 + pttbbs/mbbsd/uptime | 23 + pttbbs/mbbsd/user.c | 980 +++++++++ pttbbs/mbbsd/var.c | 268 +++ pttbbs/mbbsd/vice.c | 151 ++ pttbbs/mbbsd/vote.c | 1068 ++++++++++ pttbbs/mbbsd/voteboard.c | 447 ++++ pttbbs/mbbsd/xyz.c | 448 ++++ pttbbs/sample/Makefile | 11 + pttbbs/sample/crontab | 56 + pttbbs/sample/etc/Logout | 20 + pttbbs/sample/etc/Makefile | 18 + pttbbs/sample/etc/Welcome | 18 + pttbbs/sample/etc/Welcome_birth | 23 + pttbbs/sample/etc/Welcome_login | 12 + pttbbs/sample/etc/chickens/Makefile | 23 + pttbbs/sample/etc/chickens/a0 | 11 + pttbbs/sample/etc/chickens/a1 | 11 + pttbbs/sample/etc/chickens/a10 | 15 + pttbbs/sample/etc/chickens/a11 | 15 + pttbbs/sample/etc/chickens/a12 | 13 + pttbbs/sample/etc/chickens/a13 | 14 + pttbbs/sample/etc/chickens/a14 | 17 + pttbbs/sample/etc/chickens/a15 | 15 + pttbbs/sample/etc/chickens/a16 | 15 + pttbbs/sample/etc/chickens/a2 | 14 + pttbbs/sample/etc/chickens/a3 | 13 + pttbbs/sample/etc/chickens/a4 | 13 + pttbbs/sample/etc/chickens/a5 | 15 + pttbbs/sample/etc/chickens/a6 | 13 + pttbbs/sample/etc/chickens/a7 | 16 + pttbbs/sample/etc/chickens/a8 | 13 + pttbbs/sample/etc/chickens/a9 | 14 + pttbbs/sample/etc/chickens/b0 | 9 + pttbbs/sample/etc/chickens/b1 | 9 + pttbbs/sample/etc/chickens/b10 | 14 + pttbbs/sample/etc/chickens/b11 | 14 + pttbbs/sample/etc/chickens/b12 | 15 + pttbbs/sample/etc/chickens/b13 | 17 + pttbbs/sample/etc/chickens/b14 | 16 + pttbbs/sample/etc/chickens/b15 | 17 + pttbbs/sample/etc/chickens/b16 | 18 + pttbbs/sample/etc/chickens/b2 | 11 + pttbbs/sample/etc/chickens/b3 | 10 + pttbbs/sample/etc/chickens/b4 | 11 + pttbbs/sample/etc/chickens/b5 | 12 + pttbbs/sample/etc/chickens/b6 | 12 + pttbbs/sample/etc/chickens/b7 | 12 + pttbbs/sample/etc/chickens/b8 | 13 + pttbbs/sample/etc/chickens/b9 | 13 + pttbbs/sample/etc/chickens/buymedicine | 14 + pttbbs/sample/etc/chickens/buyoo | 14 + pttbbs/sample/etc/chickens/c0 | 8 + pttbbs/sample/etc/chickens/c1 | 9 + pttbbs/sample/etc/chickens/c10 | 11 + pttbbs/sample/etc/chickens/c11 | 10 + pttbbs/sample/etc/chickens/c12 | 12 + pttbbs/sample/etc/chickens/c13 | 11 + pttbbs/sample/etc/chickens/c14 | 12 + pttbbs/sample/etc/chickens/c15 | 12 + pttbbs/sample/etc/chickens/c16 | 11 + pttbbs/sample/etc/chickens/c2 | 9 + pttbbs/sample/etc/chickens/c3 | 8 + pttbbs/sample/etc/chickens/c4 | 11 + pttbbs/sample/etc/chickens/c5 | 12 + pttbbs/sample/etc/chickens/c6 | 10 + pttbbs/sample/etc/chickens/c7 | 12 + pttbbs/sample/etc/chickens/c8 | 12 + pttbbs/sample/etc/chickens/c9 | 11 + pttbbs/sample/etc/chickens/clean | 14 + pttbbs/sample/etc/chickens/d0 | 10 + pttbbs/sample/etc/chickens/d1 | 9 + pttbbs/sample/etc/chickens/d10 | 11 + pttbbs/sample/etc/chickens/d11 | 15 + pttbbs/sample/etc/chickens/d12 | 13 + pttbbs/sample/etc/chickens/d13 | 13 + pttbbs/sample/etc/chickens/d14 | 13 + pttbbs/sample/etc/chickens/d15 | 11 + pttbbs/sample/etc/chickens/d16 | 11 + pttbbs/sample/etc/chickens/d2 | 11 + pttbbs/sample/etc/chickens/d3 | 16 + pttbbs/sample/etc/chickens/d4 | 12 + pttbbs/sample/etc/chickens/d5 | 14 + pttbbs/sample/etc/chickens/d6 | 12 + pttbbs/sample/etc/chickens/d7 | 16 + pttbbs/sample/etc/chickens/d8 | 14 + pttbbs/sample/etc/chickens/d9 | 13 + pttbbs/sample/etc/chickens/deadth | 15 + pttbbs/sample/etc/chickens/e0 | 6 + pttbbs/sample/etc/chickens/e1 | 6 + pttbbs/sample/etc/chickens/e10 | 12 + pttbbs/sample/etc/chickens/e11 | 14 + pttbbs/sample/etc/chickens/e12 | 15 + pttbbs/sample/etc/chickens/e13 | 14 + pttbbs/sample/etc/chickens/e14 | 13 + pttbbs/sample/etc/chickens/e15 | 13 + pttbbs/sample/etc/chickens/e16 | 14 + pttbbs/sample/etc/chickens/e2 | 6 + pttbbs/sample/etc/chickens/e3 | 6 + pttbbs/sample/etc/chickens/e4 | 8 + pttbbs/sample/etc/chickens/e5 | 9 + pttbbs/sample/etc/chickens/e6 | 9 + pttbbs/sample/etc/chickens/e7 | 11 + pttbbs/sample/etc/chickens/e8 | 11 + pttbbs/sample/etc/chickens/e9 | 12 + pttbbs/sample/etc/chickens/eat | 14 + pttbbs/sample/etc/chickens/f0 | 9 + pttbbs/sample/etc/chickens/f1 | 9 + pttbbs/sample/etc/chickens/f10 | 15 + pttbbs/sample/etc/chickens/f11 | 14 + pttbbs/sample/etc/chickens/f12 | 14 + pttbbs/sample/etc/chickens/f13 | 14 + pttbbs/sample/etc/chickens/f14 | 14 + pttbbs/sample/etc/chickens/f15 | 15 + pttbbs/sample/etc/chickens/f16 | 15 + pttbbs/sample/etc/chickens/f2 | 12 + pttbbs/sample/etc/chickens/f3 | 12 + pttbbs/sample/etc/chickens/f4 | 13 + pttbbs/sample/etc/chickens/f5 | 13 + pttbbs/sample/etc/chickens/f6 | 14 + pttbbs/sample/etc/chickens/f7 | 14 + pttbbs/sample/etc/chickens/f8 | 15 + pttbbs/sample/etc/chickens/f9 | 15 + pttbbs/sample/etc/chickens/food | 14 + pttbbs/sample/etc/chickens/g0 | 5 + pttbbs/sample/etc/chickens/g1 | 5 + pttbbs/sample/etc/chickens/g10 | 13 + pttbbs/sample/etc/chickens/g11 | 15 + pttbbs/sample/etc/chickens/g12 | 15 + pttbbs/sample/etc/chickens/g13 | 14 + pttbbs/sample/etc/chickens/g14 | 14 + pttbbs/sample/etc/chickens/g15 | 14 + pttbbs/sample/etc/chickens/g16 | 14 + pttbbs/sample/etc/chickens/g2 | 5 + pttbbs/sample/etc/chickens/g3 | 6 + pttbbs/sample/etc/chickens/g4 | 6 + pttbbs/sample/etc/chickens/g5 | 8 + pttbbs/sample/etc/chickens/g6 | 10 + pttbbs/sample/etc/chickens/g7 | 11 + pttbbs/sample/etc/chickens/g8 | 14 + pttbbs/sample/etc/chickens/g9 | 14 + pttbbs/sample/etc/chickens/h0 | 9 + pttbbs/sample/etc/chickens/h1 | 9 + pttbbs/sample/etc/chickens/h10 | 15 + pttbbs/sample/etc/chickens/h11 | 14 + pttbbs/sample/etc/chickens/h12 | 14 + pttbbs/sample/etc/chickens/h13 | 14 + pttbbs/sample/etc/chickens/h14 | 14 + pttbbs/sample/etc/chickens/h15 | 15 + pttbbs/sample/etc/chickens/h16 | 15 + pttbbs/sample/etc/chickens/h2 | 12 + pttbbs/sample/etc/chickens/h3 | 12 + pttbbs/sample/etc/chickens/h4 | 13 + pttbbs/sample/etc/chickens/h5 | 13 + pttbbs/sample/etc/chickens/h6 | 14 + pttbbs/sample/etc/chickens/h7 | 14 + pttbbs/sample/etc/chickens/h8 | 15 + pttbbs/sample/etc/chickens/h9 | 15 + pttbbs/sample/etc/chickens/hit | 14 + pttbbs/sample/etc/chickens/i0 | 9 + pttbbs/sample/etc/chickens/i1 | 9 + pttbbs/sample/etc/chickens/i10 | 15 + pttbbs/sample/etc/chickens/i11 | 14 + pttbbs/sample/etc/chickens/i12 | 14 + pttbbs/sample/etc/chickens/i13 | 14 + pttbbs/sample/etc/chickens/i14 | 14 + pttbbs/sample/etc/chickens/i15 | 15 + pttbbs/sample/etc/chickens/i16 | 15 + pttbbs/sample/etc/chickens/i2 | 12 + pttbbs/sample/etc/chickens/i3 | 12 + pttbbs/sample/etc/chickens/i4 | 13 + pttbbs/sample/etc/chickens/i5 | 13 + pttbbs/sample/etc/chickens/i6 | 14 + pttbbs/sample/etc/chickens/i7 | 14 + pttbbs/sample/etc/chickens/i8 | 15 + pttbbs/sample/etc/chickens/i9 | 15 + pttbbs/sample/etc/chickens/j0 | 8 + pttbbs/sample/etc/chickens/j1 | 9 + pttbbs/sample/etc/chickens/j10 | 12 + pttbbs/sample/etc/chickens/j11 | 12 + pttbbs/sample/etc/chickens/j12 | 11 + pttbbs/sample/etc/chickens/j13 | 12 + pttbbs/sample/etc/chickens/j14 | 13 + pttbbs/sample/etc/chickens/j15 | 13 + pttbbs/sample/etc/chickens/j16 | 13 + pttbbs/sample/etc/chickens/j2 | 7 + pttbbs/sample/etc/chickens/j3 | 10 + pttbbs/sample/etc/chickens/j4 | 9 + pttbbs/sample/etc/chickens/j5 | 12 + pttbbs/sample/etc/chickens/j6 | 9 + pttbbs/sample/etc/chickens/j7 | 10 + pttbbs/sample/etc/chickens/j8 | 10 + pttbbs/sample/etc/chickens/j9 | 11 + pttbbs/sample/etc/chickens/k0 | 13 + pttbbs/sample/etc/chickens/k1 | 11 + pttbbs/sample/etc/chickens/k10 | 13 + pttbbs/sample/etc/chickens/k11 | 13 + pttbbs/sample/etc/chickens/k12 | 12 + pttbbs/sample/etc/chickens/k13 | 12 + pttbbs/sample/etc/chickens/k14 | 12 + pttbbs/sample/etc/chickens/k15 | 14 + pttbbs/sample/etc/chickens/k16 | 14 + pttbbs/sample/etc/chickens/k2 | 10 + pttbbs/sample/etc/chickens/k3 | 11 + pttbbs/sample/etc/chickens/k4 | 12 + pttbbs/sample/etc/chickens/k5 | 12 + pttbbs/sample/etc/chickens/k6 | 13 + pttbbs/sample/etc/chickens/k7 | 14 + pttbbs/sample/etc/chickens/k8 | 10 + pttbbs/sample/etc/chickens/k9 | 11 + pttbbs/sample/etc/chickens/kiss | 14 + pttbbs/sample/etc/chickens/l0 | 9 + pttbbs/sample/etc/chickens/l1 | 9 + pttbbs/sample/etc/chickens/l10 | 15 + pttbbs/sample/etc/chickens/l11 | 14 + pttbbs/sample/etc/chickens/l12 | 14 + pttbbs/sample/etc/chickens/l13 | 14 + pttbbs/sample/etc/chickens/l14 | 14 + pttbbs/sample/etc/chickens/l15 | 15 + pttbbs/sample/etc/chickens/l16 | 15 + pttbbs/sample/etc/chickens/l2 | 12 + pttbbs/sample/etc/chickens/l3 | 12 + pttbbs/sample/etc/chickens/l4 | 13 + pttbbs/sample/etc/chickens/l5 | 13 + pttbbs/sample/etc/chickens/l6 | 14 + pttbbs/sample/etc/chickens/l7 | 14 + pttbbs/sample/etc/chickens/l8 | 15 + pttbbs/sample/etc/chickens/l9 | 15 + pttbbs/sample/etc/chickens/m0 | 9 + pttbbs/sample/etc/chickens/m1 | 9 + pttbbs/sample/etc/chickens/m10 | 15 + pttbbs/sample/etc/chickens/m11 | 14 + pttbbs/sample/etc/chickens/m12 | 14 + pttbbs/sample/etc/chickens/m13 | 14 + pttbbs/sample/etc/chickens/m14 | 14 + pttbbs/sample/etc/chickens/m15 | 15 + pttbbs/sample/etc/chickens/m16 | 15 + pttbbs/sample/etc/chickens/m2 | 12 + pttbbs/sample/etc/chickens/m3 | 12 + pttbbs/sample/etc/chickens/m4 | 13 + pttbbs/sample/etc/chickens/m5 | 13 + pttbbs/sample/etc/chickens/m6 | 14 + pttbbs/sample/etc/chickens/m7 | 14 + pttbbs/sample/etc/chickens/m8 | 15 + pttbbs/sample/etc/chickens/m9 | 15 + pttbbs/sample/etc/chickens/medicine | 14 + pttbbs/sample/etc/chickens/nofood | 18 + pttbbs/sample/etc/chickens/nohp | 16 + pttbbs/sample/etc/chickens/nosatis | 6 + pttbbs/sample/etc/chickens/oo | 14 + pttbbs/sample/etc/chickens/read | 14 + pttbbs/sample/etc/chickens/sell | 23 + pttbbs/sample/etc/chickens/toofat | 17 + pttbbs/sample/etc/chickens/tootired | 15 + pttbbs/sample/etc/domain_name_query | 256 +++ pttbbs/sample/etc/feast | 47 + pttbbs/sample/etc/goodbye | 19 + pttbbs/sample/etc/register | 17 + pttbbs/sample/etc/registered | 21 + pttbbs/sample/etc/today_boring | 22 + pttbbs/sample/etc/ve.hlp | 127 ++ pttbbs/sample/innd/Makefile | 9 + pttbbs/sample/innd/bbsname.bbs | 1 + pttbbs/sample/innd/newsfeeds.bbs | 3 + pttbbs/sample/innd/nodelist.bbs | 4 + pttbbs/sample/innd/ntu.active | 1 + pttbbs/sample/pttbbs.conf | 10 + pttbbs/sample/rc.local | 4 + pttbbs/util/.cvsignore | 42 + pttbbs/util/BM_money.c | 117 ++ pttbbs/util/BM_money.sh | 5 + pttbbs/util/BOARDS.bid | Bin 0 -> 1006592 bytes pttbbs/util/DEADJOE | 9 + pttbbs/util/LocalVars.pm.sample | 22 + pttbbs/util/Makefile | 167 ++ pttbbs/util/Makefile.save | 152 ++ pttbbs/util/a.out | Bin 0 -> 14661 bytes pttbbs/util/account.c | 414 ++++ pttbbs/util/antispam.c | 122 ++ pttbbs/util/backpasswd.sh | 11 + pttbbs/util/bbsctl.c | 63 + pttbbs/util/bbsmail.c | 239 +++ pttbbs/util/bbsrf.c | 148 ++ pttbbs/util/birth.c | 99 + pttbbs/util/buildAnnounce.c | 69 + pttbbs/util/buildAnnounce.sh | 5 + pttbbs/util/buildir.c | 124 ++ pttbbs/util/countalldice.c | 95 + pttbbs/util/cpdeadbrd.c | 41 + pttbbs/util/dailybackup.pl | 48 + pttbbs/util/daymandex.c | 269 +++ pttbbs/util/deluserfile.c | 147 ++ pttbbs/util/descrypt.c | 616 ++++++ pttbbs/util/expire.c | 226 ++ pttbbs/util/horoscope.c | 157 ++ pttbbs/util/in2outmail | Bin 0 -> 39392 bytes pttbbs/util/in2outmail.c | 288 +++ pttbbs/util/initbbs.c | 223 ++ pttbbs/util/inndBM.c | 194 ++ pttbbs/util/jungo.c | 202 ++ pttbbs/util/kenben.c | 44 + pttbbs/util/mailog.sh | 9 + pttbbs/util/mandex.c | 263 +++ pttbbs/util/merge_board.c | 106 + pttbbs/util/merge_passwd.c | 106 + pttbbs/util/opendice.sh | 10 + pttbbs/util/openticket.c | 198 ++ pttbbs/util/openticket.sh | 10 + pttbbs/util/openvice.c | 54 + pttbbs/util/outmail.c | 274 +++ pttbbs/util/parse_news.c | 78 + pttbbs/util/post.c | 61 + pttbbs/util/poststat.c | 497 +++++ pttbbs/util/reaper.c | 69 + pttbbs/util/rmuid.c | 50 + pttbbs/util/shmsweep.c | 43 + pttbbs/util/showboard.c | 70 + pttbbs/util/smtest.c | 296 +++ pttbbs/util/smtest.c.save | 172 ++ pttbbs/util/smtest.result1 | 191 ++ pttbbs/util/smtest.result2 | 3 + pttbbs/util/smtest.temp | 231 +++ pttbbs/util/stock.perl | 31 + pttbbs/util/stock.sh | 5 + pttbbs/util/tarqueue.pl | 75 + pttbbs/util/testkenben.txt | 11 + pttbbs/util/toplazyBBM.c | 203 ++ pttbbs/util/toplazyBBM.sh | 3 + pttbbs/util/toplazyBM.c | 211 ++ pttbbs/util/toplazyBM.sh | 3 + pttbbs/util/topsong.sh | 5 + pttbbs/util/topusr.c | 205 ++ pttbbs/util/tunepasswd.c | 77 + pttbbs/util/uhash_loader.c | 129 ++ pttbbs/util/userlist.c | 48 + pttbbs/util/util.h | 31 + pttbbs/util/util_cache.c | 518 +++++ pttbbs/util/util_passwd.c | 139 ++ pttbbs/util/util_record.c | 245 +++ pttbbs/util/waterball.pl | 149 ++ pttbbs/util/weather.perl | 31 + pttbbs/util/weather.sh | 5 + pttbbs/util/webgrep.c | 46 + pttbbs/util/xchatd.c | 3504 ++++++++++++++++++++++++++++++++ pttbbs/util/xchatd.h | 111 + pttbbs/util/yearsold.c | 112 + 446 files changed, 68629 insertions(+) create mode 100644 pttbbs/.cvsignore create mode 100644 pttbbs/LICENSE create mode 100644 pttbbs/Makefile create mode 100644 pttbbs/README create mode 100644 pttbbs/docs/ANCESTOR create mode 100644 pttbbs/docs/CHANGE create mode 100644 pttbbs/docs/FAQ create mode 100644 pttbbs/docs/INSTALL create mode 100644 pttbbs/include/common.h create mode 100644 pttbbs/include/config.h create mode 100644 pttbbs/include/gomo.h create mode 100644 pttbbs/include/modes.h create mode 100644 pttbbs/include/perm.h create mode 100644 pttbbs/include/proto.h create mode 100644 pttbbs/include/pttbbs.conf create mode 100644 pttbbs/include/pttstruct.h create mode 100644 pttbbs/include/pttstruct.h.save create mode 100644 pttbbs/innbbsd/.cvsignore create mode 100644 pttbbs/innbbsd/Makefile create mode 100644 pttbbs/innbbsd/antisplam.h create mode 100644 pttbbs/innbbsd/bbslib.c create mode 100644 pttbbs/innbbsd/bbslib.h create mode 100644 pttbbs/innbbsd/bbslink.c create mode 100644 pttbbs/innbbsd/bbslink2.c create mode 100644 pttbbs/innbbsd/bbsnnrp.c create mode 100644 pttbbs/innbbsd/clibrary.h create mode 100644 pttbbs/innbbsd/closeonexec.c create mode 100644 pttbbs/innbbsd/connectsock.c create mode 100644 pttbbs/innbbsd/ctlinnbbsd.c create mode 100644 pttbbs/innbbsd/daemon.c create mode 100644 pttbbs/innbbsd/daemon.h create mode 100644 pttbbs/innbbsd/dbz.c create mode 100644 pttbbs/innbbsd/dbz.h create mode 100644 pttbbs/innbbsd/dbztool.c create mode 100644 pttbbs/innbbsd/echobbslib.c create mode 100644 pttbbs/innbbsd/externs.h create mode 100644 pttbbs/innbbsd/file.c create mode 100644 pttbbs/innbbsd/his.c create mode 100644 pttbbs/innbbsd/his.h create mode 100644 pttbbs/innbbsd/innbbsconf.h create mode 100644 pttbbs/innbbsd/innbbsd.c create mode 100644 pttbbs/innbbsd/innbbsd.h create mode 100644 pttbbs/innbbsd/inndchannel.c create mode 100644 pttbbs/innbbsd/inntobbs.c create mode 100644 pttbbs/innbbsd/inntobbs.h create mode 100644 pttbbs/innbbsd/mkhistory.c create mode 100644 pttbbs/innbbsd/nntp.h create mode 100644 pttbbs/innbbsd/pmain.c create mode 100644 pttbbs/innbbsd/port.c create mode 100644 pttbbs/innbbsd/receive_article.c create mode 100644 pttbbs/innbbsd/rfc931.c create mode 100644 pttbbs/mbbsd/.cvsignore create mode 100644 pttbbs/mbbsd/Makefile create mode 100644 pttbbs/mbbsd/admin.c create mode 100644 pttbbs/mbbsd/announce.c create mode 100644 pttbbs/mbbsd/args.c create mode 100644 pttbbs/mbbsd/bbcall.c create mode 100644 pttbbs/mbbsd/bbs.c create mode 100644 pttbbs/mbbsd/board.c create mode 100644 pttbbs/mbbsd/cache.c create mode 100644 pttbbs/mbbsd/cal.c create mode 100644 pttbbs/mbbsd/calendar.c create mode 100644 pttbbs/mbbsd/card.c create mode 100644 pttbbs/mbbsd/chat.c create mode 100644 pttbbs/mbbsd/chc_draw.c create mode 100644 pttbbs/mbbsd/chc_net.c create mode 100644 pttbbs/mbbsd/chc_play.c create mode 100644 pttbbs/mbbsd/chc_rule.c create mode 100644 pttbbs/mbbsd/chicken.c create mode 100644 pttbbs/mbbsd/dark.c create mode 100644 pttbbs/mbbsd/descrypt.c create mode 100644 pttbbs/mbbsd/dice.c create mode 100644 pttbbs/mbbsd/edit.c create mode 100644 pttbbs/mbbsd/friend.c create mode 100644 pttbbs/mbbsd/gamble.c create mode 100644 pttbbs/mbbsd/gomo.c create mode 100644 pttbbs/mbbsd/gomo1.c create mode 100644 pttbbs/mbbsd/guess.c create mode 100644 pttbbs/mbbsd/indict.c create mode 100644 pttbbs/mbbsd/io.c create mode 100644 pttbbs/mbbsd/kaede.c create mode 100644 pttbbs/mbbsd/lovepaper.c create mode 100644 pttbbs/mbbsd/mail.c create mode 100644 pttbbs/mbbsd/mbbsd.c create mode 100644 pttbbs/mbbsd/menu.c create mode 100644 pttbbs/mbbsd/more.c create mode 100644 pttbbs/mbbsd/name.c create mode 100644 pttbbs/mbbsd/osdep.c create mode 100644 pttbbs/mbbsd/othello.c create mode 100644 pttbbs/mbbsd/page.c create mode 100644 pttbbs/mbbsd/passwd.c create mode 100644 pttbbs/mbbsd/read.c create mode 100644 pttbbs/mbbsd/record.c create mode 100644 pttbbs/mbbsd/register.c create mode 100644 pttbbs/mbbsd/screen.c create mode 100644 pttbbs/mbbsd/stuff.c create mode 100644 pttbbs/mbbsd/syspost.c create mode 100644 pttbbs/mbbsd/talk.c create mode 100644 pttbbs/mbbsd/term.c create mode 100644 pttbbs/mbbsd/toolkit.c create mode 100644 pttbbs/mbbsd/topsong.c create mode 100644 pttbbs/mbbsd/uptime create mode 100644 pttbbs/mbbsd/user.c create mode 100644 pttbbs/mbbsd/var.c create mode 100644 pttbbs/mbbsd/vice.c create mode 100644 pttbbs/mbbsd/vote.c create mode 100644 pttbbs/mbbsd/voteboard.c create mode 100644 pttbbs/mbbsd/xyz.c create mode 100644 pttbbs/sample/Makefile create mode 100644 pttbbs/sample/crontab create mode 100644 pttbbs/sample/etc/Logout create mode 100644 pttbbs/sample/etc/Makefile create mode 100644 pttbbs/sample/etc/Welcome create mode 100644 pttbbs/sample/etc/Welcome_birth create mode 100644 pttbbs/sample/etc/Welcome_login create mode 100644 pttbbs/sample/etc/chickens/Makefile create mode 100644 pttbbs/sample/etc/chickens/a0 create mode 100644 pttbbs/sample/etc/chickens/a1 create mode 100644 pttbbs/sample/etc/chickens/a10 create mode 100644 pttbbs/sample/etc/chickens/a11 create mode 100644 pttbbs/sample/etc/chickens/a12 create mode 100644 pttbbs/sample/etc/chickens/a13 create mode 100644 pttbbs/sample/etc/chickens/a14 create mode 100644 pttbbs/sample/etc/chickens/a15 create mode 100644 pttbbs/sample/etc/chickens/a16 create mode 100644 pttbbs/sample/etc/chickens/a2 create mode 100644 pttbbs/sample/etc/chickens/a3 create mode 100644 pttbbs/sample/etc/chickens/a4 create mode 100644 pttbbs/sample/etc/chickens/a5 create mode 100644 pttbbs/sample/etc/chickens/a6 create mode 100644 pttbbs/sample/etc/chickens/a7 create mode 100644 pttbbs/sample/etc/chickens/a8 create mode 100644 pttbbs/sample/etc/chickens/a9 create mode 100644 pttbbs/sample/etc/chickens/b0 create mode 100644 pttbbs/sample/etc/chickens/b1 create mode 100644 pttbbs/sample/etc/chickens/b10 create mode 100644 pttbbs/sample/etc/chickens/b11 create mode 100644 pttbbs/sample/etc/chickens/b12 create mode 100644 pttbbs/sample/etc/chickens/b13 create mode 100644 pttbbs/sample/etc/chickens/b14 create mode 100644 pttbbs/sample/etc/chickens/b15 create mode 100644 pttbbs/sample/etc/chickens/b16 create mode 100644 pttbbs/sample/etc/chickens/b2 create mode 100644 pttbbs/sample/etc/chickens/b3 create mode 100644 pttbbs/sample/etc/chickens/b4 create mode 100644 pttbbs/sample/etc/chickens/b5 create mode 100644 pttbbs/sample/etc/chickens/b6 create mode 100644 pttbbs/sample/etc/chickens/b7 create mode 100644 pttbbs/sample/etc/chickens/b8 create mode 100644 pttbbs/sample/etc/chickens/b9 create mode 100644 pttbbs/sample/etc/chickens/buymedicine create mode 100644 pttbbs/sample/etc/chickens/buyoo create mode 100644 pttbbs/sample/etc/chickens/c0 create mode 100644 pttbbs/sample/etc/chickens/c1 create mode 100644 pttbbs/sample/etc/chickens/c10 create mode 100644 pttbbs/sample/etc/chickens/c11 create mode 100644 pttbbs/sample/etc/chickens/c12 create mode 100644 pttbbs/sample/etc/chickens/c13 create mode 100644 pttbbs/sample/etc/chickens/c14 create mode 100644 pttbbs/sample/etc/chickens/c15 create mode 100644 pttbbs/sample/etc/chickens/c16 create mode 100644 pttbbs/sample/etc/chickens/c2 create mode 100644 pttbbs/sample/etc/chickens/c3 create mode 100644 pttbbs/sample/etc/chickens/c4 create mode 100644 pttbbs/sample/etc/chickens/c5 create mode 100644 pttbbs/sample/etc/chickens/c6 create mode 100644 pttbbs/sample/etc/chickens/c7 create mode 100644 pttbbs/sample/etc/chickens/c8 create mode 100644 pttbbs/sample/etc/chickens/c9 create mode 100644 pttbbs/sample/etc/chickens/clean create mode 100644 pttbbs/sample/etc/chickens/d0 create mode 100644 pttbbs/sample/etc/chickens/d1 create mode 100644 pttbbs/sample/etc/chickens/d10 create mode 100644 pttbbs/sample/etc/chickens/d11 create mode 100644 pttbbs/sample/etc/chickens/d12 create mode 100644 pttbbs/sample/etc/chickens/d13 create mode 100644 pttbbs/sample/etc/chickens/d14 create mode 100644 pttbbs/sample/etc/chickens/d15 create mode 100644 pttbbs/sample/etc/chickens/d16 create mode 100644 pttbbs/sample/etc/chickens/d2 create mode 100644 pttbbs/sample/etc/chickens/d3 create mode 100644 pttbbs/sample/etc/chickens/d4 create mode 100644 pttbbs/sample/etc/chickens/d5 create mode 100644 pttbbs/sample/etc/chickens/d6 create mode 100644 pttbbs/sample/etc/chickens/d7 create mode 100644 pttbbs/sample/etc/chickens/d8 create mode 100644 pttbbs/sample/etc/chickens/d9 create mode 100644 pttbbs/sample/etc/chickens/deadth create mode 100644 pttbbs/sample/etc/chickens/e0 create mode 100644 pttbbs/sample/etc/chickens/e1 create mode 100644 pttbbs/sample/etc/chickens/e10 create mode 100644 pttbbs/sample/etc/chickens/e11 create mode 100644 pttbbs/sample/etc/chickens/e12 create mode 100644 pttbbs/sample/etc/chickens/e13 create mode 100644 pttbbs/sample/etc/chickens/e14 create mode 100644 pttbbs/sample/etc/chickens/e15 create mode 100644 pttbbs/sample/etc/chickens/e16 create mode 100644 pttbbs/sample/etc/chickens/e2 create mode 100644 pttbbs/sample/etc/chickens/e3 create mode 100644 pttbbs/sample/etc/chickens/e4 create mode 100644 pttbbs/sample/etc/chickens/e5 create mode 100644 pttbbs/sample/etc/chickens/e6 create mode 100644 pttbbs/sample/etc/chickens/e7 create mode 100644 pttbbs/sample/etc/chickens/e8 create mode 100644 pttbbs/sample/etc/chickens/e9 create mode 100644 pttbbs/sample/etc/chickens/eat create mode 100644 pttbbs/sample/etc/chickens/f0 create mode 100644 pttbbs/sample/etc/chickens/f1 create mode 100644 pttbbs/sample/etc/chickens/f10 create mode 100644 pttbbs/sample/etc/chickens/f11 create mode 100644 pttbbs/sample/etc/chickens/f12 create mode 100644 pttbbs/sample/etc/chickens/f13 create mode 100644 pttbbs/sample/etc/chickens/f14 create mode 100644 pttbbs/sample/etc/chickens/f15 create mode 100644 pttbbs/sample/etc/chickens/f16 create mode 100644 pttbbs/sample/etc/chickens/f2 create mode 100644 pttbbs/sample/etc/chickens/f3 create mode 100644 pttbbs/sample/etc/chickens/f4 create mode 100644 pttbbs/sample/etc/chickens/f5 create mode 100644 pttbbs/sample/etc/chickens/f6 create mode 100644 pttbbs/sample/etc/chickens/f7 create mode 100644 pttbbs/sample/etc/chickens/f8 create mode 100644 pttbbs/sample/etc/chickens/f9 create mode 100644 pttbbs/sample/etc/chickens/food create mode 100644 pttbbs/sample/etc/chickens/g0 create mode 100644 pttbbs/sample/etc/chickens/g1 create mode 100644 pttbbs/sample/etc/chickens/g10 create mode 100644 pttbbs/sample/etc/chickens/g11 create mode 100644 pttbbs/sample/etc/chickens/g12 create mode 100644 pttbbs/sample/etc/chickens/g13 create mode 100644 pttbbs/sample/etc/chickens/g14 create mode 100644 pttbbs/sample/etc/chickens/g15 create mode 100644 pttbbs/sample/etc/chickens/g16 create mode 100644 pttbbs/sample/etc/chickens/g2 create mode 100644 pttbbs/sample/etc/chickens/g3 create mode 100644 pttbbs/sample/etc/chickens/g4 create mode 100644 pttbbs/sample/etc/chickens/g5 create mode 100644 pttbbs/sample/etc/chickens/g6 create mode 100644 pttbbs/sample/etc/chickens/g7 create mode 100644 pttbbs/sample/etc/chickens/g8 create mode 100644 pttbbs/sample/etc/chickens/g9 create mode 100644 pttbbs/sample/etc/chickens/h0 create mode 100644 pttbbs/sample/etc/chickens/h1 create mode 100644 pttbbs/sample/etc/chickens/h10 create mode 100644 pttbbs/sample/etc/chickens/h11 create mode 100644 pttbbs/sample/etc/chickens/h12 create mode 100644 pttbbs/sample/etc/chickens/h13 create mode 100644 pttbbs/sample/etc/chickens/h14 create mode 100644 pttbbs/sample/etc/chickens/h15 create mode 100644 pttbbs/sample/etc/chickens/h16 create mode 100644 pttbbs/sample/etc/chickens/h2 create mode 100644 pttbbs/sample/etc/chickens/h3 create mode 100644 pttbbs/sample/etc/chickens/h4 create mode 100644 pttbbs/sample/etc/chickens/h5 create mode 100644 pttbbs/sample/etc/chickens/h6 create mode 100644 pttbbs/sample/etc/chickens/h7 create mode 100644 pttbbs/sample/etc/chickens/h8 create mode 100644 pttbbs/sample/etc/chickens/h9 create mode 100644 pttbbs/sample/etc/chickens/hit create mode 100644 pttbbs/sample/etc/chickens/i0 create mode 100644 pttbbs/sample/etc/chickens/i1 create mode 100644 pttbbs/sample/etc/chickens/i10 create mode 100644 pttbbs/sample/etc/chickens/i11 create mode 100644 pttbbs/sample/etc/chickens/i12 create mode 100644 pttbbs/sample/etc/chickens/i13 create mode 100644 pttbbs/sample/etc/chickens/i14 create mode 100644 pttbbs/sample/etc/chickens/i15 create mode 100644 pttbbs/sample/etc/chickens/i16 create mode 100644 pttbbs/sample/etc/chickens/i2 create mode 100644 pttbbs/sample/etc/chickens/i3 create mode 100644 pttbbs/sample/etc/chickens/i4 create mode 100644 pttbbs/sample/etc/chickens/i5 create mode 100644 pttbbs/sample/etc/chickens/i6 create mode 100644 pttbbs/sample/etc/chickens/i7 create mode 100644 pttbbs/sample/etc/chickens/i8 create mode 100644 pttbbs/sample/etc/chickens/i9 create mode 100644 pttbbs/sample/etc/chickens/j0 create mode 100644 pttbbs/sample/etc/chickens/j1 create mode 100644 pttbbs/sample/etc/chickens/j10 create mode 100644 pttbbs/sample/etc/chickens/j11 create mode 100644 pttbbs/sample/etc/chickens/j12 create mode 100644 pttbbs/sample/etc/chickens/j13 create mode 100644 pttbbs/sample/etc/chickens/j14 create mode 100644 pttbbs/sample/etc/chickens/j15 create mode 100644 pttbbs/sample/etc/chickens/j16 create mode 100644 pttbbs/sample/etc/chickens/j2 create mode 100644 pttbbs/sample/etc/chickens/j3 create mode 100644 pttbbs/sample/etc/chickens/j4 create mode 100644 pttbbs/sample/etc/chickens/j5 create mode 100644 pttbbs/sample/etc/chickens/j6 create mode 100644 pttbbs/sample/etc/chickens/j7 create mode 100644 pttbbs/sample/etc/chickens/j8 create mode 100644 pttbbs/sample/etc/chickens/j9 create mode 100644 pttbbs/sample/etc/chickens/k0 create mode 100644 pttbbs/sample/etc/chickens/k1 create mode 100644 pttbbs/sample/etc/chickens/k10 create mode 100644 pttbbs/sample/etc/chickens/k11 create mode 100644 pttbbs/sample/etc/chickens/k12 create mode 100644 pttbbs/sample/etc/chickens/k13 create mode 100644 pttbbs/sample/etc/chickens/k14 create mode 100644 pttbbs/sample/etc/chickens/k15 create mode 100644 pttbbs/sample/etc/chickens/k16 create mode 100644 pttbbs/sample/etc/chickens/k2 create mode 100644 pttbbs/sample/etc/chickens/k3 create mode 100644 pttbbs/sample/etc/chickens/k4 create mode 100644 pttbbs/sample/etc/chickens/k5 create mode 100644 pttbbs/sample/etc/chickens/k6 create mode 100644 pttbbs/sample/etc/chickens/k7 create mode 100644 pttbbs/sample/etc/chickens/k8 create mode 100644 pttbbs/sample/etc/chickens/k9 create mode 100644 pttbbs/sample/etc/chickens/kiss create mode 100644 pttbbs/sample/etc/chickens/l0 create mode 100644 pttbbs/sample/etc/chickens/l1 create mode 100644 pttbbs/sample/etc/chickens/l10 create mode 100644 pttbbs/sample/etc/chickens/l11 create mode 100644 pttbbs/sample/etc/chickens/l12 create mode 100644 pttbbs/sample/etc/chickens/l13 create mode 100644 pttbbs/sample/etc/chickens/l14 create mode 100644 pttbbs/sample/etc/chickens/l15 create mode 100644 pttbbs/sample/etc/chickens/l16 create mode 100644 pttbbs/sample/etc/chickens/l2 create mode 100644 pttbbs/sample/etc/chickens/l3 create mode 100644 pttbbs/sample/etc/chickens/l4 create mode 100644 pttbbs/sample/etc/chickens/l5 create mode 100644 pttbbs/sample/etc/chickens/l6 create mode 100644 pttbbs/sample/etc/chickens/l7 create mode 100644 pttbbs/sample/etc/chickens/l8 create mode 100644 pttbbs/sample/etc/chickens/l9 create mode 100644 pttbbs/sample/etc/chickens/m0 create mode 100644 pttbbs/sample/etc/chickens/m1 create mode 100644 pttbbs/sample/etc/chickens/m10 create mode 100644 pttbbs/sample/etc/chickens/m11 create mode 100644 pttbbs/sample/etc/chickens/m12 create mode 100644 pttbbs/sample/etc/chickens/m13 create mode 100644 pttbbs/sample/etc/chickens/m14 create mode 100644 pttbbs/sample/etc/chickens/m15 create mode 100644 pttbbs/sample/etc/chickens/m16 create mode 100644 pttbbs/sample/etc/chickens/m2 create mode 100644 pttbbs/sample/etc/chickens/m3 create mode 100644 pttbbs/sample/etc/chickens/m4 create mode 100644 pttbbs/sample/etc/chickens/m5 create mode 100644 pttbbs/sample/etc/chickens/m6 create mode 100644 pttbbs/sample/etc/chickens/m7 create mode 100644 pttbbs/sample/etc/chickens/m8 create mode 100644 pttbbs/sample/etc/chickens/m9 create mode 100644 pttbbs/sample/etc/chickens/medicine create mode 100644 pttbbs/sample/etc/chickens/nofood create mode 100644 pttbbs/sample/etc/chickens/nohp create mode 100644 pttbbs/sample/etc/chickens/nosatis create mode 100644 pttbbs/sample/etc/chickens/oo create mode 100644 pttbbs/sample/etc/chickens/read create mode 100644 pttbbs/sample/etc/chickens/sell create mode 100644 pttbbs/sample/etc/chickens/toofat create mode 100644 pttbbs/sample/etc/chickens/tootired create mode 100644 pttbbs/sample/etc/domain_name_query create mode 100644 pttbbs/sample/etc/feast create mode 100644 pttbbs/sample/etc/goodbye create mode 100644 pttbbs/sample/etc/register create mode 100644 pttbbs/sample/etc/registered create mode 100644 pttbbs/sample/etc/today_boring create mode 100644 pttbbs/sample/etc/ve.hlp create mode 100644 pttbbs/sample/innd/Makefile create mode 100644 pttbbs/sample/innd/bbsname.bbs create mode 100644 pttbbs/sample/innd/newsfeeds.bbs create mode 100644 pttbbs/sample/innd/nodelist.bbs create mode 100644 pttbbs/sample/innd/ntu.active create mode 100644 pttbbs/sample/pttbbs.conf create mode 100644 pttbbs/sample/rc.local create mode 100644 pttbbs/util/.cvsignore create mode 100644 pttbbs/util/BM_money.c create mode 100644 pttbbs/util/BM_money.sh create mode 100644 pttbbs/util/BOARDS.bid create mode 100644 pttbbs/util/DEADJOE create mode 100644 pttbbs/util/LocalVars.pm.sample create mode 100644 pttbbs/util/Makefile create mode 100644 pttbbs/util/Makefile.save create mode 100644 pttbbs/util/a.out create mode 100644 pttbbs/util/account.c create mode 100644 pttbbs/util/antispam.c create mode 100644 pttbbs/util/backpasswd.sh create mode 100644 pttbbs/util/bbsctl.c create mode 100644 pttbbs/util/bbsmail.c create mode 100644 pttbbs/util/bbsrf.c create mode 100644 pttbbs/util/birth.c create mode 100644 pttbbs/util/buildAnnounce.c create mode 100644 pttbbs/util/buildAnnounce.sh create mode 100644 pttbbs/util/buildir.c create mode 100644 pttbbs/util/countalldice.c create mode 100644 pttbbs/util/cpdeadbrd.c create mode 100644 pttbbs/util/dailybackup.pl create mode 100644 pttbbs/util/daymandex.c create mode 100644 pttbbs/util/deluserfile.c create mode 100644 pttbbs/util/descrypt.c create mode 100644 pttbbs/util/expire.c create mode 100644 pttbbs/util/horoscope.c create mode 100644 pttbbs/util/in2outmail create mode 100644 pttbbs/util/in2outmail.c create mode 100644 pttbbs/util/initbbs.c create mode 100644 pttbbs/util/inndBM.c create mode 100644 pttbbs/util/jungo.c create mode 100644 pttbbs/util/kenben.c create mode 100644 pttbbs/util/mailog.sh create mode 100644 pttbbs/util/mandex.c create mode 100644 pttbbs/util/merge_board.c create mode 100644 pttbbs/util/merge_passwd.c create mode 100644 pttbbs/util/opendice.sh create mode 100644 pttbbs/util/openticket.c create mode 100644 pttbbs/util/openticket.sh create mode 100644 pttbbs/util/openvice.c create mode 100644 pttbbs/util/outmail.c create mode 100644 pttbbs/util/parse_news.c create mode 100644 pttbbs/util/post.c create mode 100644 pttbbs/util/poststat.c create mode 100644 pttbbs/util/reaper.c create mode 100644 pttbbs/util/rmuid.c create mode 100644 pttbbs/util/shmsweep.c create mode 100644 pttbbs/util/showboard.c create mode 100644 pttbbs/util/smtest.c create mode 100644 pttbbs/util/smtest.c.save create mode 100644 pttbbs/util/smtest.result1 create mode 100644 pttbbs/util/smtest.result2 create mode 100644 pttbbs/util/smtest.temp create mode 100644 pttbbs/util/stock.perl create mode 100644 pttbbs/util/stock.sh create mode 100644 pttbbs/util/tarqueue.pl create mode 100644 pttbbs/util/testkenben.txt create mode 100644 pttbbs/util/toplazyBBM.c create mode 100644 pttbbs/util/toplazyBBM.sh create mode 100644 pttbbs/util/toplazyBM.c create mode 100644 pttbbs/util/toplazyBM.sh create mode 100644 pttbbs/util/topsong.sh create mode 100644 pttbbs/util/topusr.c create mode 100644 pttbbs/util/tunepasswd.c create mode 100644 pttbbs/util/uhash_loader.c create mode 100644 pttbbs/util/userlist.c create mode 100644 pttbbs/util/util.h create mode 100644 pttbbs/util/util_cache.c create mode 100644 pttbbs/util/util_passwd.c create mode 100644 pttbbs/util/util_record.c create mode 100644 pttbbs/util/waterball.pl create mode 100644 pttbbs/util/weather.perl create mode 100644 pttbbs/util/weather.sh create mode 100644 pttbbs/util/webgrep.c create mode 100644 pttbbs/util/xchatd.c create mode 100644 pttbbs/util/xchatd.h create mode 100644 pttbbs/util/yearsold.c diff --git a/pttbbs/.cvsignore b/pttbbs/.cvsignore new file mode 100644 index 00000000..80c7b7f0 --- /dev/null +++ b/pttbbs/.cvsignore @@ -0,0 +1,2 @@ +tmp +pttbbs.conf diff --git a/pttbbs/LICENSE b/pttbbs/LICENSE new file mode 100644 index 00000000..d60c31a9 --- /dev/null +++ b/pttbbs/LICENSE @@ -0,0 +1,340 @@ + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1989, 1991 Free Software Foundation, Inc. + 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Library General Public License instead.) You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + + To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must show them these terms so they know their +rights. + + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + + The precise terms and conditions for copying, distribution and +modification follow. + + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + + 1. You may copy and distribute verbatim copies of the Program's +source code as you receive it, in any medium, provided that you +conspicuously and appropriately publish on each copy an appropriate +copyright notice and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + + 2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices + stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in + whole or in part contains or is derived from the Program or any + part thereof, to be licensed as a whole at no charge to all third + parties under the terms of this License. + + c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a + notice that there is no warranty (or else, saying that you provide + a warranty) and that users may redistribute the program under + these conditions, and telling the user how to view a copy of this + License. (Exception: if the Program itself is interactive but + does not normally print such an announcement, your work based on + the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable + source code, which must be distributed under the terms of Sections + 1 and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your + cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a medium + customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer + to distribute corresponding source code. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form with such + an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + + 4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + + 5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + + 6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + + 9. The Free Software Foundation may publish revised and/or new versions +of the General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + +Each version is given a distinguishing version number. If the Program +specifies a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + + 10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + + 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, +REPAIR OR CORRECTION. + + 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + + Gnomovision version 69, Copyright (C) year name of author + Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the program + `Gnomovision' (which makes passes at compilers) written by James Hacker. + + , 1 April 1989 + Ty Coon, President of Vice + +This General Public License does not permit incorporating your program into +proprietary programs. If your program is a subroutine library, you may +consider it more useful to permit linking proprietary applications with the +library. If this is what you want to do, use the GNU Library General +Public License instead of this License. diff --git a/pttbbs/Makefile b/pttbbs/Makefile new file mode 100644 index 00000000..dabc6044 --- /dev/null +++ b/pttbbs/Makefile @@ -0,0 +1,9 @@ +SUBDIR= mbbsd util innbbsd +BBSHOME?=$(HOME) + +all install clean: + @for i in $(SUBDIR); do\ + cd $$i;\ + make BBSHOME=$(BBSHOME) OSTYPE=$(OSTYPE) $@;\ + cd ..;\ + done diff --git a/pttbbs/README b/pttbbs/README new file mode 100644 index 00000000..672bb33c --- /dev/null +++ b/pttbbs/README @@ -0,0 +1,12 @@ + +快速安裝方法請參閱 INSTALL + +常見問題及 sendmail.cf 的設法請見 FAQ + +sample 下有 crontab 及 rc.local 的範例 + +有任何問題請mail給 pttbbs@ptt2.csie.ntu.edu.tw + +也可到 ptt2.csie.ntu.edu.tw / ptt2.twbbs.org 的 PttSrc 板詢問 + +謝謝 :) diff --git a/pttbbs/docs/ANCESTOR b/pttbbs/docs/ANCESTOR new file mode 100644 index 00000000..269e7cea --- /dev/null +++ b/pttbbs/docs/ANCESTOR @@ -0,0 +1,23 @@ +Pirate Bulletin Board System Version: 1.00 +Copyright (C) 1990 Edward A. Luke + +Eagles Bulletin Board System Version: 2.00-3.00 +Copyright (C) 1992, 1993, 1994 Raymond R. Rocker, Dominic B. Tynes + Guy T. Vega + +Phoenix Bulletin Board System Version: 3.00-4.0 +Copyright (C) 1993, 1994 Ming-Feng Chen, Ji-Tzay Yang + Tsun-Yi Wen + +秘密情人資訊站 Version: 3.1-4.0 +Copyright (C) 1994 簡顯鑑, 劉佳峰 + +MapleBridge Bulletin Board System Version: 2.36 +Copyright (C) 1994-1995 Jeng-Hermes Lin, Hung-Pin Chen + SoC, Xshadow + +SunOfBeach Bulletin Board System Version: 0.22 +Copyleft ($) 1996 Kaede, woju + +Ptt Bulletin Board System Ptt, Jaky, Action, Heat, Dunk +批踢踢實業坊 CharlieL, DickG, DavidYu diff --git a/pttbbs/docs/CHANGE b/pttbbs/docs/CHANGE new file mode 100644 index 00000000..2ddb6869 --- /dev/null +++ b/pttbbs/docs/CHANGE @@ -0,0 +1,76 @@ +Version 1.0.2 2001/07/17 + +* 新增 util/merge_passwd +* 新增 util/merge_board +* 修正 load fromcache 超過 300 行會 segfault 的 bug +* 修正來源字串在 FreeBSD 下會有亂碼的問題 +* 修正 mbbsd 中 select() 不好的用法 +* 修正 more.c 中的安全問題 (by kcwu) + +-------------------------------------------------- +Version 1.0.1 2001/04/26 + +* 將文件搬至 docs 目錄下 +* 修改 config.h 中的 MAX_ACTIVE, MAX_CPULOAD + 並加入 FORCE_PROCESS_REGISTER_FORM 的選項 +* 新增修復遺失看板的功能 (press 'R') +* 修正訊息的錯誤 +* 修正幽靈水球 +* 移除在使用者名單按'N'修改暱稱的功能, 該功能可能有bug存在 +* 新增 util/shmsweep + +-------------------------------------------------- +Version 1.0.0 2000/09/16 + +* 修正 Select 看板的 bug +* 新增 Reaper, 刪除過期帳號 +* 新增 chickens 到 sample 中 +* 新增 initbbs 的功能: 初始化動態看板, 範本精靈 +* 新增 FAQ + +-------------------------------------------------- +Version 0.9.7 2000/08/31 + +* 新增 tunepasswd +* 修正 innbbsd 的 bug +* xchatd 運作正常 +* 整合 buildir +* 修正 Makefile 在某些 Linux 上無法正常工作的 bug +* 在 sample 的目錄下打 make install 即可自動安裝 sample 設定檔 + +-------------------------------------------------- +Version 0.9.6 2000/06/28 + +* 修正使用暫存檔會當掉的 bug +* 整合 FreeBSD 和 Linux 的 Makefile, 不需要再手動修改 +* 把 pttbbs.conf 從 include 搬到 pttsrc 下 +* 新增 outmail 取代 bmda +* 整合 xchatd (未測試) +* 整合 innbbsd (未測試) + +-------------------------------------------------- +Version 0.9.5 2000/06/07 + +* 修正在 Linux 無法 talk 的 bug +* 如果看板列表是空的的話, 自動進入開板功能 +* 新增 initbbs 工具程式 +* 新增 BBSHOME environment variable 的使用 (見 INSTALL) +* 搬移部份設定到 include/pttbbs.conf +* 修正在FreeBSD上無法取得 swapinfo 的 bug + +-------------------------------------------------- +Version 0.9.4 2000/06/03 + +* 把程式中有用到 ncurses 的地方移除, 不再需要 -ltermcap, -lncurses +* 修正一個造成無窮迴圈的 Bug +* 移除以使用者名稱搜尋全站文章的功能 + +-------------------------------------------------- +Version 0.9.3 2000/05/23 + +* 修正在 Linux 上 Makefile 的問題 + +-------------------------------------------------- +Version 0.9.2 2000/05/20 + +* port 到 Linux 上 diff --git a/pttbbs/docs/FAQ b/pttbbs/docs/FAQ new file mode 100644 index 00000000..bc2904a0 --- /dev/null +++ b/pttbbs/docs/FAQ @@ -0,0 +1,146 @@ + 作者 DavidYu (^^Y) 看板 PttSrc + 標題 Re: 安裝完連線時..... + 時間 Thu May 18 15:08:04 2000 +─────────────────────────────────────── + +※ 引述《JamesCheng (網球比排球好玩啦!)》之銘言: +: 我在安裝完之後 用root執行 mbbsd 23 +: 連線看出現 +: Escape character is '^]'. +: 【物治樂園】◎ 物治第二站 ◎(pt.mc.ntu.edu.tw) +: 調幅(140.112.122.44) 系統負荷 0.00 0.01 0.00 +: Connection closed by foreign host. +: 然後系統出現下列訊息 +: [shmget error] key = 8ab +: errno = 12: Cannot allocate memory +: 這是何原因呢? +shared memory要加大 +在kernel config file中加一行 +options SHMMAXPGS=4100 +重新make kernel + +-- +※ 發信站: 批踢踢實業坊(ptt.twbbs.org) +◆ From: oio.m6.ntu.edu.t + + 作者 DavidYu (Do it YOURSELF!) 看板 PttSrc + 標題 Re: 請問一下... + 時間 Sat May 27 18:41:39 2000 +─────────────────────────────────────── + +※ 引述《clifflu ( 煩呀煩呀煩~~~)》之銘言: +: ※ 引述《hscat (復站了!)》之銘言: +: : 不過我有一個小小的問題 +: : 能不能指導一下...想要開新的版應該從哪邊開呢? +: 主選單下的 (0)Admin ?? +: : 因為我實在找不到怎麼開新看板...:~~~~... +不不不.. +開板要從分類看板的地方開,這部份有點小小的複雜, +和以往的版本不一樣,我來簡單說明一下: + +首先介紹看板. +看板有兩種, 一般看板和群組看板. 如果用檔案系統的架構來看的話, +一般看板如同 file, 而群組看板就是 directory +(在所有看板列表的地方只會出現一般看板) + +一個看板有UID及GID這兩個屬性. UID是unique的,從1開始分配,系統在開板時會 +菾佧llocate一個. 而GID是指定這個看板在哪一個群組看板之下(看板是樹狀架構的) +所以如果有一個群組看板的UID是x, 則GID為x的看板都會擺在該群組看板之下 +而如果看板GID為0(保留的UID)的話,該看板就會出現在一開始從主選單進CLASS的 +那個地方 + +至於開板的方法. +首先從CLASS進到你想要開新板的類別下,然後按大B設定 +如此新開的板就會自動assign GID 到那個類別下 + +如果要般動一個已經開好的板到其他類別的話 +先找出那個類別(群組看板)的UID, 按大E可以看到 +然後把要搬動的板的GID設成那個UID及可 + +值得注意的是, 如果把某個使用者設成某群組看板的板主的話 +則當他從CLASS進到那個群組時會獲得小組長的權限(可以開板,設定看板等等) +要特別小心 + +比較麻煩的地方: +一個新開的群組裡面並沒有任何看板,所以無法從選單進去裡面開板 +這時候就需要在可開板的地方先開個板,然後再把那個板的GID設過去即可 +(這也是為什麼需要一個initial的.BOARDS的原因 :p) + +-- +※ 發信站: 批踢踢實業坊(ptt.twbbs.org) +◆ From: meow.cc.ntu.edu. + + 作者 DavidYu (軱~~~~~~~~~~) 看板 PttSrc + 標題 sendmail.cf要改的地方(參考用) + 時間 Sun Jul 9 09:39:53 2000 +─────────────────────────────────────── + +有顏色的是要加上去的 +要注意,tab和space不能混用 + +###################################### +### Ruleset 0 -- Parse Address ### +###################################### +S0 + +R$* $: $>Parse0 $1 initial parsing +R<@> $#local $: <@> special case error msgs +R$* $: $>98 $1 handle local hacks +R$+.bbs < @ $=w .> $#bbsmail $: $1 bbs mail gateway +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +R$* $: $>Parse1 $1 final parsing + +...... + +# handle locally delivered names +R$+.bbs $#bbsmail $:$1 bbs mail gateway +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +R$=L $#local $: @ $1 special local names +R$+ $#local $: $1 regular local names + +########################################################################### +### Ruleset 5 -- special rewriting after aliases have been expanded ### +########################################################################### + +...... + +################################################## +### Local and Program Mailer specification ### +################################################## + +##### @(#)local.m4 8.30 (Berkeley) 6/30/1998 ##### + +Mlocal, P=/usr/libexec/mail.local, F=lsDFMAw5:/|@qSXfmnz9P, S=10/30, R= + T=DNS/RFC822/X-Unix, + A=mail.local -l +Mprog, P=/bin/sh, F=lsDFMoqeu9, S=10/30, R=20/40, D=$z:/, + T=X-Unix, + A=sh -c $u +Mbbsmail, P=/home/bbs/bin/bbsmail, F=lsSDFMhPu, U=bbs, S=10,R=20/40, +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + A=bbsmail $u +^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +-- +※ 發信站: 批踢踢實業坊(ptt.twbbs.org) +◆ From: oio.m6.ntu.edu.t + + 作者 DavidYu (鴰~~~~~~~~~~~~~~) 看板 PttSrc + 標題 [anno] tunepasswd + 時間 Sat Jul 29 09:18:06 2000 +─────────────────────────────────────── + +新增了一個 tunepasswd 的程式 + +如果你在 .PASSWD 建立後又改過了 MAX_USERS + +你必須要執行 tunepasswd 一次來修改 .PASSWD 檔的大小 + +執行的時候不可以有任何BBS的程式在執行 + +shared memory 也應該要清除, 否則會有不預期的錯誤發生 + +執行 tunepasswd 會產生一個原來的備份檔 .PASSWD~ + +-- +※ 發信站: 批踢踢實業坊(ptt.twbbs.org) +◆ From: oio.m6.ntu.edu.t diff --git a/pttbbs/docs/INSTALL b/pttbbs/docs/INSTALL new file mode 100644 index 00000000..5bd484d5 --- /dev/null +++ b/pttbbs/docs/INSTALL @@ -0,0 +1,49 @@ +底下是快速安裝的方法 + +== + +先取得 root 權限 + +1. 打 vipw, 加入底下兩行 + + bbs:*:9999:99::0:0:Ptt BBS:/home/bbs:/home/bbs/bin/bbsrf + bbsadm::9999:99::0:0:Ptt BBS:/home/bbs:/bin/csh + +2. 執行 passwd bbsadm 設 bbsadm的密碼 +3. 在 /etc/group 中加入一行 + + bbs:*:99: + +4. 執行 mkdir /home/bbs +5. 執行 chown bbs.bbs /home/bbs +6. 執行 chmod 700 /home/bbs + +然後切換成 bbsadm 的身份 + +7. 取得解開 pttbbs-VERSION.tar.gz (任何目錄下皆可). +8. 執行 cd pttbbs +9. 如果之前沒有設定過 pttbbs.conf 的話, 請 cp sample/pttbbs.conf pttbbs.conf +10. 修改 pttbbs.conf +11. 執行 make OSTYPE=FreeBSD BBSHOME=/home/bbs all install + (Linux使用者請把 "FreeBSD" 改成 "linux") +12. 如果是新架起來的站, 請執行 cd sample; make install +12. 執行 cd /home/bbs; bin/initbbs + +假如一切都很順利的話,這樣子大概就安裝完了 +接下來是啟動 bbs 的部份 + +13. 執行 bin/uhash_loader (*註1) +14. 用 root 執行 bin/mbbsd 23 (註2) + +telnet localhost 23 看看 +new一個帳號叫SYSOP,然後logout再login, 這樣子就會擁有站長權限囉~ +再new一個帳號叫 guest, 這樣子別人就可以用 guest 參觀你的站了 +開板,開群組,以及搬動群組的方法請看 PttSrc 板的文摘 + +註: +1. 這個程式是在 initial shared memory 用的, 只有開機後第一次執行, 或是 + 你手動清除 shm 後才需要執行 + +2. bin/mbbsd 23 是指定要 bind 23 port, 依照 UNIX 規定, 1024 以下的 port + 須要有 root 權限, 所以如果要 bind 23 port 的話就要用 root 去執行, + 3000 port 則不需要 diff --git a/pttbbs/include/common.h b/pttbbs/include/common.h new file mode 100644 index 00000000..333bed8c --- /dev/null +++ b/pttbbs/include/common.h @@ -0,0 +1,198 @@ +/* $Id: common.h,v 1.1 2002/03/07 15:13:48 in2 Exp $ */ +#ifndef INCLUDE_COMMON_H +#define INCLUDE_COMMON_H + +#define STR_GUEST "guest" +#define DEFAULT_BOARD str_sysop + +#define FN_PASSWD BBSHOME "/.PASSWDS" /* User records */ +#define FN_USSONG "ussong" /* 點歌統計 */ +#define FN_POST_NOTE "post.note" /* po文章備忘錄 */ +#define FN_APPLICATION "application" +#define FN_MONEY "etc/money" +#define FN_OVERRIDES "overrides" +#define FN_REJECT "reject" +#define FN_WATER "water" +#define FN_CANVOTE "can_vote" +#define FN_VISABLE "visable" +#define FN_USIES "usies" /* BBS log */ +#define FN_BOARD ".BRD" /* board list */ +#define FN_USEBOARD "usboard" /* 看版統計 */ +#define FN_NOTE_ANS "note.ans" +#define FN_TOPSONG "etc/topsong" +#define FN_OVERRIDES "overrides" +#define FN_TICKET "ticket" +#define FN_TICKET_END "ticket.end" +#define FN_TICKET_ITEMS "ticket.items" +#define FN_TICKET_RECORD "ticket.data" +#define FN_TICKET_USER "ticket.user" +#define FN_TICKET_OUTCOME "ticket.outcome" +#define FN_TICKET_BRDLIST "boardlist" + +#define MSG_DEL_CANCEL "取消刪除" +#define MSG_SELECT_BOARD "\033[7m【 選擇看板 】\033[m\n" \ + "請輸入看板名稱(按空白鍵自動搜尋):" +#define MSG_CLOAKED "哈哈!我隱形了!看不到勒... :P" +#define MSG_UNCLOAK "我要重現江湖了...." +#define MSG_BIG_BOY "我是大帥哥! ^o^Y" +#define MSG_BIG_GIRL "世紀大美女 *^-^*" +#define MSG_LITTLE_BOY "我是底迪啦... =)" +#define MSG_LITTLE_GIRL "最可愛的美眉! :>" +#define MSG_MAN "麥當勞叔叔 (^O^)" +#define MSG_WOMAN "叫我小阿姨!! /:>" +#define MSG_PLANT "植物也有性別喔.." +#define MSG_MIME "礦物總沒性別了吧" +#define MSG_PASSWD "請輸入您的密碼: " +#define MSG_POSTER "\033[34;46m 文章選讀 "\ + "\033[31;47m (y)\033[30m回信 "\ + "\033[31m(=[]<>)\033[30m相關主題 "\ + "\033[31m(/?)\033[30m搜尋標題 "\ + "\033[31m(aA)\033[30m搜尋作者 "\ + "\033[31m(x)\033[30m轉錄 "\ + "\033[31m(V)\033[30m投票 \033[m" +#define MSG_SEPERATOR "\ +───────────────────────────────────────" + +#define MSG_CLOAKED "哈哈!我隱形了!看不到勒... :P" +#define MSG_UNCLOAK "我要重現江湖了...." + +#define MSG_WORKING "處理中,請稍候..." + +#define MSG_CANCEL "取消。" +#define MSG_USR_LEFT "User 已經離開了" +#define MSG_NOBODY "目前無人上線" + +#define MSG_DEL_OK "刪除完畢" +#define MSG_DEL_CANCEL "取消刪除" +#define MSG_DEL_ERROR "刪除錯誤" +#define MSG_DEL_NY "請確定刪除(Y/N)?[N] " + +#define MSG_FWD_OK "文章轉寄完成!" +#define MSG_FWD_ERR1 "轉寄失誤: system error" +#define MSG_FWD_ERR2 "轉寄失誤: address error" + +#define MSG_SURE_NY "請您確定(Y/N)?[N] " +#define MSG_SURE_YN "請您確定(Y/N)?[Y] " + +#define MSG_BID "請輸入看板名稱:" +#define MSG_UID "請輸入使用者代號:" +#define MSG_PASSWD "請輸入您的密碼: " + +#define MSG_BIG_BOY "我是大帥哥! ^o^Y" +#define MSG_BIG_GIRL "世紀大美女 *^-^*" +#define MSG_LITTLE_BOY "我是底迪啦... =)" +#define MSG_LITTLE_GIRL "最可愛的美眉! :>" +#define MSG_MAN "麥當勞叔叔 (^O^)" +#define MSG_WOMAN "叫我小阿姨!! /:>" +#define MSG_PLANT "植物也有性別喔.." +#define MSG_MIME "礦物總沒性別了吧" + +#define ERR_BOARD_OPEN ".BOARD 開啟錯誤" +#define ERR_BOARD_UPDATE ".BOARD 更新有誤" +#define ERR_PASSWD_OPEN ".PASSWDS 開啟錯誤" + +#define ERR_BID "你搞錯了啦!沒有這個板喔!" +#define ERR_UID "這裡沒有這個人啦!" +#define ERR_PASSWD "密碼不對喔!你有沒有冒用人家的名字啊?" +#define ERR_FILENAME "檔名不合法!" +#define MSG_MAILER \ +"\033[34;46m 鴻雁往返 \033[31;47m(R)\033[30m回信\033[31m(x)\033[30m轉達\ +\033[31m(y)\033[30m群組回信\033[31m(D)\033[30m刪除\ +\033[31m(c)\033[30m收入信件夾\033[31m(z)\033[30m信件夾 \033[31m[G]\033[30m繼續?\033[0m" +#define MSG_SHORTULIST "\033[7m\ +使用者代號 目前狀態 │使用者代號 目前狀態 │使用者代號 目前狀態 \033[0m" + + +#define STR_AUTHOR1 "作者:" +#define STR_AUTHOR2 "發信人:" +#define STR_POST1 "看板:" +#define STR_POST2 "站內:" + +/* Flags to getdata input function */ +#define NOECHO 0 +#define DOECHO 1 +#define LCECHO 2 + +#define YEA 1 /* Booleans (Yep, for true and false) */ +#define NA 0 + + +#define IRH 1 /* 好友關係 */ +#define HRM 2 +#define IBH 4 +#define IFH 8 +#define HFM 16 +#define ST_FRIEND (IBH | IFH | HFM) +#define ST_REJECT (IRH | HRM) + +/* 鍵盤設定 */ +#define KEY_TAB 9 +#define KEY_ESC 27 +#define KEY_UP 0x0101 +#define KEY_DOWN 0x0102 +#define KEY_RIGHT 0x0103 +#define KEY_LEFT 0x0104 +#define KEY_HOME 0x0201 +#define KEY_INS 0x0202 +#define KEY_DEL 0x0203 +#define KEY_END 0x0204 +#define KEY_PGUP 0x0205 +#define KEY_PGDN 0x0206 + +#define QCAST int (*)(const void *, const void *) +#define Ctrl(c) (c & 037) +#define chartoupper(c) ((c >= 'a' && c <= 'z') ? c+'A'-'a' : c) + +#define LEN_AUTHOR1 5 +#define LEN_AUTHOR2 7 + +/* ----------------------------------------------------- */ +/* 群組名單模式 Ptt */ +/* ----------------------------------------------------- */ +#define FRIEND_OVERRIDE 0 +#define FRIEND_REJECT 1 +#define FRIEND_ALOHA 2 +#define FRIEND_POST 3 +#define FRIEND_SPECIAL 4 +#define FRIEND_CANVOTE 5 +#define BOARD_WATER 6 +#define BOARD_VISABLE 7 + +#define LOCK_THIS 1 // lock這線不能重複玩 +#define LOCK_MULTI 2 // lock所有線不能重複玩 + +#define I_TIMEOUT (-2) /* Used for the getchar routine select call */ +#define I_OTHERDATA (-333) /* interface, (-3) will conflict with chinese */ + +#define CHE_O(c) ((c) >> 3) +#define CHE_P(c) ((c) & 7) +#define RTL(x) (((x) - 3) >> 1) +#define dim(x) (sizeof(x) / sizeof(x[0])) +#define LTR(x) ((x) * 2 + 3) +#define CHE(a, b) ((a) | ((b) << 3)) + +#define BRD_NOZAP 00001 /* 不可zap */ +#define BRD_NOCOUNT 00002 /* 不列入統計 */ +#define BRD_NOTRAN 00004 /* 不轉信 */ +#define BRD_GROUPBOARD 00010 /* 群組板 */ +#define BRD_HIDE 00020 /* 隱藏板 (看板好友才可看) */ +#define BRD_POSTMASK 00040 /* 限制發表或閱讀 */ +#define BRD_ANONYMOUS 00100 /* 匿名板 */ +#define BRD_DEFAULTANONYMOUS 00200 /* 預設匿名板 */ +#define BRD_BAD 00400 /* 違法改進中看板 */ +#define BRD_VOTEBOARD 01000 /* 連署機看板 */ + +#define MAX_MODES 80 + +#ifndef MIN +#define MIN(a,b) ((ab)?a:b) +#endif + +#define char_lower(c) ((c >= 'A' && c <= 'Z') ? c|32 : c) + +#define STR_CURSOR "●" +#define STR_UNCUR " " +#endif diff --git a/pttbbs/include/config.h b/pttbbs/include/config.h new file mode 100644 index 00000000..3eb6e64a --- /dev/null +++ b/pttbbs/include/config.h @@ -0,0 +1,197 @@ +/* $Id: config.h,v 1.1 2002/03/07 15:13:48 in2 Exp $ */ +#ifndef INCLUDE_CONFIG_H +#define INCLUDE_CONFIG_H + +#include +#include "../pttbbs.conf" + +#define BBSPROG BBSHOME "/bin/mbbsd" /* 主程式 */ +#define BAN_FILE "BAN" /* 關站通告檔 */ +#define LOAD_FILE "/proc/loadavg" /* for Linux */ + +#ifndef RELAY_SERVER_IP /* 寄站外信的 mail server */ +#define RELAY_SERVER_IP "127.0.0.1" +#endif + +#ifndef MAX_USERS /* 最高註冊人數 */ +#define MAX_USERS (150000) +#endif + +#ifndef MAX_ACTIVE +#define MAX_ACTIVE (1024) /* 最多同時上站人數 */ +#endif + +#ifndef MAX_CPULOAD +#define MAX_CPULOAD (70) /* CPU 最高load */ +#endif + +#ifndef MAX_POST_MONEY /* 發表文章稿費的上限 */ +#define MAX_POST_MONEY 100 +#endif + +#ifndef MAX_CHICKEN_MONEY /* 養雞場穫利上限 */ +#define MAX_CHICKEN_MONEY 100 +#endif + +#ifndef MAX_GUEST_LIFE /* 最長未認證使用者保留時間(秒) */ +#define MAX_GUEST_LIFE (3 * 24 * 60 * 60) +#endif + +#ifndef MAX_LIFE /* 最長使用者保留時間(秒) */ +#define MAX_LIFE (120 * 24 * 60 * 60) +#endif + +#ifndef MAX_FROM +#define MAX_FROM (300) /* 最多故鄉數 */ +#endif + +#ifndef HAVE_JCEE /* 大學聯考查榜系統 */ +#define HAVE_JCEE 1 +#endif + +#ifndef HAVE_FREECLOAK +#define HAVE_FREECLOAK 0 +#endif + +#ifndef FORCE_PROCESS_REGISTER_FORM +#define FORCE_PROCESS_REGISTER_FORM 0 +#endif + +#ifndef TITLE_COLOR +#define TITLE_COLOR "\033[0;1;37;46m" +#endif + +#ifndef SYSLOG_FACILITY +#define SYSLOG_FACILITY LOG_LOCAL0 +#endif + +#ifndef TAR_PATH +#define TAR_PATH "tar" +#endif + +#ifndef HBFLexpire +#define HBFLexpire (432000) /* 5 days */ +#endif + +/* 以下還未整理 */ +#define DIRCACHESIZE (40) /* cache 文章列表中最後40篇 */ +#define MAX_FRIEND (256) /* 載入 cache 之最多朋友數目 */ +#define MAX_REJECT (32) /* 載入 cache 之最多壞人數目 */ +#define MAX_MSGS (10) /* 水球(熱訊)忍耐上限 */ +#define MAX_BOARD (8192) /* 最大開版個數 */ +#define MAX_MOVIE (999) /* 最多動態看版數 */ +#define MAX_MOVIE_SECTION (10) /* 最多動態看板類別 */ +#define MAX_ITEMS (1000) /* 一個目錄最多有幾項 */ +#define MAX_HISTORY (12) /* 動態看板保持 12 筆歷史記錄 */ +#define MAX_CROSSNUM (9) /* 最多crosspost次數 */ +#define MAX_QUERYLINES (16) /* 顯示 Query/Plan 訊息最大行數 */ +#define MAX_LOGIN_INFO (128) /* 最多上線通知人數 */ +#define MAX_POST_INFO (32) /* 最多新文章通知人數 */ +#define MAX_NAMELIST (128) /* 最多其他特別名單人數 */ +#define MAX_PAGES (999) /* more.c 中文章頁數上限(lines/22) */ +#define MAX_KEEPMAIL (200) /* 最多保留幾封 MAIL? */ +#define MAX_EXKEEPMAIL (1000) /* 最多信箱加大多少封 */ +#define MAX_NOTE (20) /* 最多保留幾篇留言? */ +#define MAX_SIGLINES (6) /* 簽名檔引入最大行數 */ +#define MAX_CROSSNUM (9) /* 最多crosspost次數 */ +#define MAX_REVIEW (7) /* 最多水球回顧 */ +#define NUMVIEWFILE (14) /* 進站畫面最多數 */ +#define MAX_SWAPUSED (0.7) /* SWAP最高使用率 */ +#define LOGINATTEMPTS (3) /* 最大進站失誤次數 */ +#define WHERE /* 是否有故鄉功能 */ +#undef LOG_BOARD /* 看版是否log */ +#undef SUPPORT_GB /* 是否支援gb */ + + +#define DEFAULTBOARD "SYSOP" /* 預設看板 */ +#define LOGINASNEW /* 採用上站申請帳號制度 */ +#define NO_WATER_POST /* 防止BlahBlah式灌水 */ +#define USE_BSMTP /* 使用opus的BSMTP 寄收信? */ +#define HAVE_ANONYMOUS /* 提供 Anonymous 板 */ +#undef POSTNOTIFY /* 新文章通知功能 */ +#define INTERNET_EMAIL /* 支援 InterNet Email 功能(含 Forward) */ +#define HAVE_ORIGIN /* 顯示 author 來自何處 */ +#undef HAVE_MAILCLEAN /* 清理所有使用者個人信箱 */ +#undef HAVE_SUICIDE /* 提供使用者自殺功能 */ +#undef HAVE_REPORT /* 系統追蹤報告 */ +#undef HAVE_INFO /* 顯示程式版本說明 */ +#undef HAVE_LICENSE /* 顯示 GNU 版權畫面 */ +#undef HAVE_TIN /* 提供 news reader */ +#undef HAVE_GOPHER /* 提供 gopher */ +#undef HAVE_WWW /* 提供 www browser */ +#define FAST_LOGIN /* Login 不檢查遠端使用者 */ +#define HAVE_CAL /* 提功計算機 */ +#undef HAVE_ARCHIE /* have arche */ +#undef POSTBUG /* board/mail post 沒有 bug 了 */ +#undef HAVE_REPORT /* 系統追蹤報告 */ +#undef EMAIL_JUSTIFY /* 發出 InterNet Email 身份認證信函 */ +#undef NEWUSER_LIMIT /* 新手上路的三天限制 */ +#undef HAVE_X_BOARDS + +#define USE_LYNX /* 使用外部lynx dump ? */ +#undef USE_PROXY +#ifdef USE_PROXY +#define PROXYSERVER "140.112.28.165" +#define PROXYPORT 3128 +#endif +#define LOCAL_PROXY /* 是否開啟local 的proxy */ +#ifdef LOCAL_PROXY +#define HPROXYDAY 1 /* local的proxy refresh天數 */ +#endif + +#define SHOWMIND /* 看見心情 */ +#define SHOWUID /* 看見使用者 UID */ +#define SHOWBOARD /* 看見使用者看板 */ +#define SHOWPID /* 看見使用者 PID */ + +#define REALINFO /* 真實姓名 */ +#ifdef REALINFO +#undef ACTS_REALNAMES /* 主目錄的 (U)ser 顯示真實姓名 */ +#undef POST_REALNAMES /* 貼文件時附上真實姓名 */ +#undef MAIL_REALNAMES /* 寄站內信件時附上真實姓名 */ +#endif + +#define DOTIMEOUT +#ifdef DOTIMEOUT +#define IDLE_TIMEOUT (30*60) /* 一般情況之 timeout */ +#define MONITOR_TIMEOUT (20*60) /* monitor 時之 timeout */ +#define SHOW_IDLE_TIME /* 顯示閒置時間 */ +#endif + +#define SEM_ENTER -1 /* enter semaphore */ +#define SEM_LEAVE 1 /* leave semaphore */ +#define SEM_RESET 0 /* reset semaphore */ + +#define MAGIC_KEY 1234 /* 身分認證信函編碼 */ + +#define BRDSHM_KEY 1208 +#define UHASH_KEY 1218 /* userid->uid hash */ +#define UTMPSHM_KEY 2221 +#define PTTSHM_KEY 1220 /* 動態看版 , 節日 */ +#define FROMSHM_KEY 1223 /* whereis, 最多使用者 */ + +#define BRDSEM_KEY 2005 /* semaphore key */ +#define PTTSEM_KEY 2000 /* semaphore key */ +#define FROMSEM_KEY 2003 /* semaphore key */ +#define PASSWDSEM_KEY 2010 + +#define NEW_CHATPORT 3838 +#define CHATPORT 5722 + +#define MAX_ROOM 16 /* 最多有幾間包廂? */ + +#define EXIT_LOGOUT 0 +#define EXIT_LOSTCONN -1 +#define EXIT_CLIERROR -2 +#define EXIT_TIMEDOUT -3 +#define EXIT_KICK -4 + +#define CHAT_LOGIN_OK "OK" +#define CHAT_LOGIN_EXISTS "EX" +#define CHAT_LOGIN_INVALID "IN" +#define CHAT_LOGIN_BOGUS "BG" +#define BADCIDCHARS " *" /* Chat Room 中禁用於 nick 的字元 */ + +#define ALLPOST "ALLPOST" + +#endif diff --git a/pttbbs/include/gomo.h b/pttbbs/include/gomo.h new file mode 100644 index 00000000..c51bb283 --- /dev/null +++ b/pttbbs/include/gomo.h @@ -0,0 +1,2156 @@ + +#define BBLANK (0) /* 空白 */ +#define BBLACK (1) /* 黑子, 先手 */ +#define BWHITE (2) /* 白子, 後手 */ +#define MAX_TIME (300) /*最長idle秒數*/ +#ifndef BRDSIZ +#define BRDSIZ (15) /* 棋盤單邊大小 */ +#endif + +#define BGOTO(x, y) move( 16 - y , x * 2 + 3) +#define BGOTOCUR(x, y) move(16 - y, x * 2 + 4) + +/* + 0 0 0 = #@# : len= 3 : NO 00 NO + 1 1 0 = #_@# : len= 4 : NO 00 NO + 2 1 1 = #_@_# : len= 5 : NO 00 NO + 3 2 0 = #O@# : len= 4 : NO 00 NO + 4 2 1 = #O@_# : len= 5 : NO 00 NO + 5 2 2 = #O@O# : len= 5 : NO 00 NO + 6 3 0 = #__@# : len= 5 : NO 00 NO + 7 3 1 = #__@_# : len= 6 : NO 00 NO + 8 3 2 = #__@O# : len= 6 : NO 00 NO + 9 3 3 = #__@__# : len= 7 : NO 00 NO + 10 4 0 = #_O@# : len= 5 : NO 00 NO + 11 4 1 = #_O@_# : len= 6 : NO 00 NO + 12 4 2 = #_O@O# : len= 6 : NO 00 NO + 13 4 3 = #_O@__# : len= 7 : NO 00 NO + 14 4 4 = #_O@O_# : len= 7 : NO 00 NO + 15 5 0 = #O_@# : len= 5 : NO 00 NO + 16 5 1 = #O_@_# : len= 6 : NO 00 NO + 17 5 2 = #O_@O# : len= 6 : NO 00 NO + 18 5 3 = #O_@__# : len= 7 : NO 00 NO + 19 5 4 = #O_@O_# : len= 7 : NO 00 NO + 20 5 5 = #O_@_O# : len= 7 : NO 00 NO + 21 6 0 = #OO@# : len= 5 : NO 00 NO + 22 6 1 = #OO@_# : len= 6 : NO 00 NO + 23 6 2 = #OO@O# : len= 6 : NO 00 NO + 24 6 3 = #OO@__# : len= 7 : NO 00 NO + 25 6 4 = #OO@O_# : len= 7 : S4 00 S4 + 26 6 5 = #OO@_O# : len= 7 : D4 00 D4 + 27 6 6 = #OO@OO# : len= 7 : L5 00 L5 + 28 7 0 = #___@# : len= 6 : NO 00 NO + 29 7 1 = #___@_# : len= 7 : NO 00 NO + 30 7 2 = #___@O# : len= 7 : NO 00 NO + 31 7 3 = #___@__# : len= 8 : NO 00 NO + 32 7 4 = #___@O_# : len= 8 : NO 00 NO + 33 7 5 = #___@_O# : len= 8 : NO 00 NO + 34 7 6 = #___@OO# : len= 8 : NO 00 NO + 35 7 7 = #___@___# : len= 9 : NO 00 NO + 36 8 0 = #__O@# : len= 6 : NO 00 NO + 37 8 1 = #__O@_# : len= 7 : NO 00 NO + 38 8 2 = #__O@O# : len= 7 : NO 00 NO + 39 8 3 = #__O@__# : len= 8 : NO 00 NO + 40 8 4 = #__O@O_# : len= 8 : H3 22 H3 + 41 8 5 = #__O@_O# : len= 8 : NO 00 NO + 42 8 6 = #__O@OO# : len= 8 : S4 00 S4 + 43 8 7 = #__O@___# : len= 9 : NO 00 NO + 44 8 8 = #__O@O__# : len= 9 : H3 22 H3 + 45 9 0 = #_O_@# : len= 6 : NO 00 NO + 46 9 1 = #_O_@_# : len= 7 : NO 00 NO + 47 9 2 = #_O_@O# : len= 7 : NO 00 NO + 48 9 3 = #_O_@__# : len= 8 : NO 00 NO + 49 9 4 = #_O_@O_# : len= 8 : D3 10 D3 + 50 9 5 = #_O_@_O# : len= 8 : NO 00 NO + 51 9 6 = #_O_@OO# : len= 8 : D4 00 D4 + 52 9 7 = #_O_@___# : len= 9 : NO 00 NO + 53 9 8 = #_O_@O__# : len= 9 : D3 10 D3 + 54 9 9 = #_O_@_O_# : len= 9 : NO 00 NO + 55 10 0 = #_OO@# : len= 6 : NO 00 NO + 56 10 1 = #_OO@_# : len= 7 : NO 00 NO + 57 10 2 = #_OO@O# : len= 7 : S4 00 S4 + 58 10 3 = #_OO@__# : len= 8 : H3 31 H3 + 59 10 4 = #_OO@O_# : len= 8 : H4 00 H4 + 60 10 5 = #_OO@_O# : len= 8 : D4 00 D4 + 61 10 6 = #_OO@OO# : len= 8 : L5 00 L5 + 62 10 7 = #_OO@___# : len= 9 : H3 31 H3 + 63 10 8 = #_OO@O__# : len= 9 : H4 00 H4 + 64 10 9 = #_OO@_O_# : len= 9 : D4 00 D4 + 65 10 10 = #_OO@OO_# : len= 9 : L5 00 L5 + 66 11 0 = #O__@# : len= 6 : NO 00 NO + 67 11 1 = #O__@_# : len= 7 : NO 00 NO + 68 11 2 = #O__@O# : len= 7 : NO 00 NO + 69 11 3 = #O__@__# : len= 8 : NO 00 NO + 70 11 4 = #O__@O_# : len= 8 : NO 00 NO + 71 11 5 = #O__@_O# : len= 8 : NO 00 NO + 72 11 6 = #O__@OO# : len= 8 : NO 00 NO + 73 11 7 = #O__@___# : len= 9 : NO 00 NO + 74 11 8 = #O__@O__# : len= 9 : NO 00 NO + 75 11 9 = #O__@_O_# : len= 9 : NO 00 NO + 76 11 10 = #O__@OO_# : len= 9 : NO 00 H3 + 77 11 11 = #O__@__O# : len= 9 : NO 00 NO + 78 12 0 = #O_O@# : len= 6 : NO 00 NO + 79 12 1 = #O_O@_# : len= 7 : NO 00 NO + 80 12 2 = #O_O@O# : len= 7 : D4 00 D4 + 81 12 3 = #O_O@__# : len= 8 : NO 00 NO + 82 12 4 = #O_O@O_# : len= 8 : D4 00 D4 + 83 12 5 = #O_O@_O# : len= 8 : NO 00 NO + 84 12 6 = #O_O@OO# : len= 8 : NO 00 D4 + 85 12 7 = #O_O@___# : len= 9 : NO 00 NO + 86 12 8 = #O_O@O__# : len= 9 : D4 00 D4 + 87 12 9 = #O_O@_O_# : len= 9 : NO 00 D3 + 88 12 10 = #O_O@OO_# : len= 9 : S4 00 H4 + 89 12 11 = #O_O@__O# : len= 9 : NO 00 NO + 90 12 12 = #O_O@O_O# : len= 9 : X4 00 X4 + 91 13 0 = #OO_@# : len= 6 : NO 00 NO + 92 13 1 = #OO_@_# : len= 7 : NO 00 NO + 93 13 2 = #OO_@O# : len= 7 : D4 00 D4 + 94 13 3 = #OO_@__# : len= 8 : NO 00 NO + 95 13 4 = #OO_@O_# : len= 8 : D4 00 D4 + 96 13 5 = #OO_@_O# : len= 8 : NO 00 NO + 97 13 6 = #OO_@OO# : len= 8 : NO 00 D4 + 98 13 7 = #OO_@___# : len= 9 : NO 00 NO + 99 13 8 = #OO_@O__# : len= 9 : D4 00 D4 + 100 13 9 = #OO_@_O_# : len= 9 : NO 00 NO + 101 13 10 = #OO_@OO_# : len= 9 : NO 00 D4 + 102 13 11 = #OO_@__O# : len= 9 : NO 00 NO + 103 13 12 = #OO_@O_O# : len= 9 : D4 00 D4 + 104 13 13 = #OO_@_OO# : len= 9 : NO 00 NO + 105 14 0 = #OOO@# : len= 6 : NO 00 NO + 106 14 1 = #OOO@_# : len= 7 : S4 00 S4 + 107 14 2 = #OOO@O# : len= 7 : L5 00 L5 + 108 14 3 = #OOO@__# : len= 8 : S4 00 S4 + 109 14 4 = #OOO@O_# : len= 8 : L5 00 L5 + 110 14 5 = #OOO@_O# : len= 8 : NO 00 D4 + 111 14 6 = #OOO@OO# : len= 8 : L6 00 L6 + 112 14 7 = #OOO@___# : len= 9 : S4 00 S4 + 113 14 8 = #OOO@O__# : len= 9 : L5 00 L5 + 114 14 9 = #OOO@_O_# : len= 9 : NO 00 D4 + 115 14 10 = #OOO@OO_# : len= 9 : L6 00 L6 + 116 14 11 = #OOO@__O# : len= 9 : S4 00 S4 + 117 14 12 = #OOO@O_O# : len= 9 : L5 00 L5 + 118 14 13 = #OOO@_OO# : len= 9 : NO 00 D4 + 119 14 14 = #OOO@OOO# : len= 9 : L6 00 L6 + 120 15 0 = #____@# : len= 7 : NO 00 NO + 121 15 1 = #____@_# : len= 8 : NO 00 NO + 122 15 2 = #____@O# : len= 8 : NO 00 NO + 123 15 3 = #____@__# : len= 9 : NO 00 NO + 124 15 4 = #____@O_# : len= 9 : NO 00 NO + 125 15 5 = #____@_O# : len= 9 : NO 00 NO + 126 15 6 = #____@OO# : len= 9 : NO 00 NO + 127 15 7 = #____@___# : len=10 : NO 00 NO + 128 15 8 = #____@O__# : len=10 : NO 00 NO + 129 15 9 = #____@_O_# : len=10 : NO 00 NO + 130 15 10 = #____@OO_# : len=10 : H3 13 H3 + 131 15 11 = #____@__O# : len=10 : NO 00 NO + 132 15 12 = #____@O_O# : len=10 : NO 00 NO + 133 15 13 = #____@_OO# : len=10 : NO 00 NO + 134 15 14 = #____@OOO# : len=10 : S4 00 S4 + 135 15 15 = #____@____# : len=11 : NO 00 NO + 136 16 0 = #___O@# : len= 7 : NO 00 NO + 137 16 1 = #___O@_# : len= 8 : NO 00 NO + 138 16 2 = #___O@O# : len= 8 : NO 00 NO + 139 16 3 = #___O@__# : len= 9 : NO 00 NO + 140 16 4 = #___O@O_# : len= 9 : H3 22 H3 + 141 16 5 = #___O@_O# : len= 9 : NO 00 NO + 142 16 6 = #___O@OO# : len= 9 : S4 00 S4 + 143 16 7 = #___O@___# : len=10 : NO 00 NO + 144 16 8 = #___O@O__# : len=10 : H3 22 H3 + 145 16 9 = #___O@_O_# : len=10 : D3 01 D3 + 146 16 10 = #___O@OO_# : len=10 : H4 00 H4 + 147 16 11 = #___O@__O# : len=10 : NO 00 NO + 148 16 12 = #___O@O_O# : len=10 : D4 00 D4 + 149 16 13 = #___O@_OO# : len=10 : D4 00 D4 + 150 16 14 = #___O@OOO# : len=10 : L5 00 L5 + 151 16 15 = #___O@____# : len=11 : NO 00 NO + 152 16 16 = #___O@O___# : len=11 : H3 22 H3 + 153 17 0 = #__O_@# : len= 7 : NO 00 NO + 154 17 1 = #__O_@_# : len= 8 : NO 00 NO + 155 17 2 = #__O_@O# : len= 8 : NO 00 NO + 156 17 3 = #__O_@__# : len= 9 : NO 00 NO + 157 17 4 = #__O_@O_# : len= 9 : D3 10 D3 + 158 17 5 = #__O_@_O# : len= 9 : NO 00 NO + 159 17 6 = #__O_@OO# : len= 9 : D4 00 D4 + 160 17 7 = #__O_@___# : len=10 : NO 00 NO + 161 17 8 = #__O_@O__# : len=10 : D3 10 D3 + 162 17 9 = #__O_@_O_# : len=10 : NO 00 NO + 163 17 10 = #__O_@OO_# : len=10 : D4 00 D4 + 164 17 11 = #__O_@__O# : len=10 : NO 00 NO + 165 17 12 = #__O_@O_O# : len=10 : NO 00 D3 + 166 17 13 = #__O_@_OO# : len=10 : NO 00 NO + 167 17 14 = #__O_@OOO# : len=10 : NO 00 D4 + 168 17 15 = #__O_@____# : len=11 : NO 00 NO + 169 17 16 = #__O_@O___# : len=11 : D3 10 D3 + 170 17 17 = #__O_@_O__# : len=11 : NO 00 NO + 171 18 0 = #__OO@# : len= 7 : NO 00 NO + 172 18 1 = #__OO@_# : len= 8 : H3 31 H3 + 173 18 2 = #__OO@O# : len= 8 : S4 00 S4 + 174 18 3 = #__OO@__# : len= 9 : H3 31 H3 + 175 18 4 = #__OO@O_# : len= 9 : H4 00 H4 + 176 18 5 = #__OO@_O# : len= 9 : D4 00 D4 + 177 18 6 = #__OO@OO# : len= 9 : L5 00 L5 + 178 18 7 = #__OO@___# : len=10 : H3 31 H3 + 179 18 8 = #__OO@O__# : len=10 : H4 00 H4 + 180 18 9 = #__OO@_O_# : len=10 : D4 00 D4 + 181 18 10 = #__OO@OO_# : len=10 : L5 00 L5 + 182 18 11 = #__OO@__O# : len=10 : H3 31 H3 + 183 18 12 = #__OO@O_O# : len=10 : S4 00 H4 + 184 18 13 = #__OO@_OO# : len=10 : NO 00 D4 + 185 18 14 = #__OO@OOO# : len=10 : L6 00 L6 + 186 18 15 = #__OO@____# : len=11 : H3 31 H3 + 187 18 16 = #__OO@O___# : len=11 : H4 00 H4 + 188 18 17 = #__OO@_O__# : len=11 : D4 00 D4 + 189 18 18 = #__OO@OO__# : len=11 : L5 00 L5 + 190 19 0 = #_O__@# : len= 7 : NO 00 NO + 191 19 1 = #_O__@_# : len= 8 : NO 00 NO + 192 19 2 = #_O__@O# : len= 8 : NO 00 NO + 193 19 3 = #_O__@__# : len= 9 : NO 00 NO + 194 19 4 = #_O__@O_# : len= 9 : NO 00 NO + 195 19 5 = #_O__@_O# : len= 9 : NO 00 NO + 196 19 6 = #_O__@OO# : len= 9 : NO 00 NO + 197 19 7 = #_O__@___# : len=10 : NO 00 NO + 198 19 8 = #_O__@O__# : len=10 : NO 00 NO + 199 19 9 = #_O__@_O_# : len=10 : NO 00 NO + 200 19 10 = #_O__@OO_# : len=10 : NO 00 H3 + 201 19 11 = #_O__@__O# : len=10 : NO 00 NO + 202 19 12 = #_O__@O_O# : len=10 : NO 00 NO + 203 19 13 = #_O__@_OO# : len=10 : NO 00 NO + 204 19 14 = #_O__@OOO# : len=10 : S4 00 S4 + 205 19 15 = #_O__@____# : len=11 : NO 00 NO + 206 19 16 = #_O__@O___# : len=11 : NO 00 NO + 207 19 17 = #_O__@_O__# : len=11 : NO 00 NO + 208 19 18 = #_O__@OO__# : len=11 : H3 13 H3 + 209 19 19 = #_O__@__O_# : len=11 : NO 00 NO + 210 20 0 = #_O_O@# : len= 7 : NO 00 NO + 211 20 1 = #_O_O@_# : len= 8 : D3 20 D3 + 212 20 2 = #_O_O@O# : len= 8 : D4 00 D4 + 213 20 3 = #_O_O@__# : len= 9 : D3 20 D3 + 214 20 4 = #_O_O@O_# : len= 9 : D4 00 D4 + 215 20 5 = #_O_O@_O# : len= 9 : NO 00 D3 + 216 20 6 = #_O_O@OO# : len= 9 : NO 00 D4 + 217 20 7 = #_O_O@___# : len=10 : D3 20 D3 + 218 20 8 = #_O_O@O__# : len=10 : D4 00 D4 + 219 20 9 = #_O_O@_O_# : len=10 : NO 00 D3 + 220 20 10 = #_O_O@OO_# : len=10 : S4 00 H4 + 221 20 11 = #_O_O@__O# : len=10 : D3 20 D3 + 222 20 12 = #_O_O@O_O# : len=10 : X4 00 X4 + 223 20 13 = #_O_O@_OO# : len=10 : D4 00 D4 + 224 20 14 = #_O_O@OOO# : len=10 : L5 00 L5 + 225 20 15 = #_O_O@____# : len=11 : D3 20 D3 + 226 20 16 = #_O_O@O___# : len=11 : D4 00 D4 + 227 20 17 = #_O_O@_O__# : len=11 : NO 00 D3 + 228 20 18 = #_O_O@OO__# : len=11 : S4 00 H4 + 229 20 19 = #_O_O@__O_# : len=11 : D3 20 D3 + 230 20 20 = #_O_O@O_O_# : len=11 : X4 00 X4 + 231 21 0 = #_OO_@# : len= 7 : NO 00 NO + 232 21 1 = #_OO_@_# : len= 8 : D3 10 D3 + 233 21 2 = #_OO_@O# : len= 8 : D4 00 D4 + 234 21 3 = #_OO_@__# : len= 9 : D3 10 D3 + 235 21 4 = #_OO_@O_# : len= 9 : D4 00 D4 + 236 21 5 = #_OO_@_O# : len= 9 : NO 00 D3 + 237 21 6 = #_OO_@OO# : len= 9 : NO 00 D4 + 238 21 7 = #_OO_@___# : len=10 : D3 10 D3 + 239 21 8 = #_OO_@O__# : len=10 : D4 00 D4 + 240 21 9 = #_OO_@_O_# : len=10 : NO 00 D3 + 241 21 10 = #_OO_@OO_# : len=10 : NO 00 D4 + 242 21 11 = #_OO_@__O# : len=10 : D3 10 D3 + 243 21 12 = #_OO_@O_O# : len=10 : D4 00 D4 + 244 21 13 = #_OO_@_OO# : len=10 : NO 00 D3 + 245 21 14 = #_OO_@OOO# : len=10 : NO 00 D4 + 246 21 15 = #_OO_@____# : len=11 : D3 10 D3 + 247 21 16 = #_OO_@O___# : len=11 : D4 00 D4 + 248 21 17 = #_OO_@_O__# : len=11 : NO 00 D3 + 249 21 18 = #_OO_@OO__# : len=11 : NO 00 D4 + 250 21 19 = #_OO_@__O_# : len=11 : D3 10 D3 + 251 21 20 = #_OO_@O_O_# : len=11 : D4 00 D4 + 252 21 21 = #_OO_@_OO_# : len=11 : NO 00 D3 + 253 22 0 = #_OOO@# : len= 7 : S4 00 S4 + 254 22 1 = #_OOO@_# : len= 8 : H4 00 H4 + 255 22 2 = #_OOO@O# : len= 8 : L5 00 L5 + 256 22 3 = #_OOO@__# : len= 9 : H4 00 H4 + 257 22 4 = #_OOO@O_# : len= 9 : L5 00 L5 + 258 22 5 = #_OOO@_O# : len= 9 : S4 00 H4 + 259 22 6 = #_OOO@OO# : len= 9 : L6 00 L6 + 260 22 7 = #_OOO@___# : len=10 : H4 00 H4 + 261 22 8 = #_OOO@O__# : len=10 : L5 00 L5 + 262 22 9 = #_OOO@_O_# : len=10 : S4 00 H4 + 263 22 10 = #_OOO@OO_# : len=10 : L6 00 L6 + 264 22 11 = #_OOO@__O# : len=10 : H4 00 H4 + 265 22 12 = #_OOO@O_O# : len=10 : L5 00 L5 + 266 22 13 = #_OOO@_OO# : len=10 : S4 00 H4 + 267 22 14 = #_OOO@OOO# : len=10 : L6 00 L6 + 268 22 15 = #_OOO@____# : len=11 : H4 00 H4 + 269 22 16 = #_OOO@O___# : len=11 : L5 00 L5 + 270 22 17 = #_OOO@_O__# : len=11 : S4 00 H4 + 271 22 18 = #_OOO@OO__# : len=11 : L6 00 L6 + 272 22 19 = #_OOO@__O_# : len=11 : H4 00 H4 + 273 22 20 = #_OOO@O_O_# : len=11 : L5 00 L5 + 274 22 21 = #_OOO@_OO_# : len=11 : S4 00 H4 + 275 22 22 = #_OOO@OOO_# : len=11 : L6 00 L6 + 276 23 0 = #O___@# : len= 7 : NO 00 NO + 277 23 1 = #O___@_# : len= 8 : NO 00 NO + 278 23 2 = #O___@O# : len= 8 : NO 00 NO + 279 23 3 = #O___@__# : len= 9 : NO 00 NO + 280 23 4 = #O___@O_# : len= 9 : NO 00 NO + 281 23 5 = #O___@_O# : len= 9 : NO 00 NO + 282 23 6 = #O___@OO# : len= 9 : NO 00 NO + 283 23 7 = #O___@___# : len=10 : NO 00 NO + 284 23 8 = #O___@O__# : len=10 : NO 00 NO + 285 23 9 = #O___@_O_# : len=10 : NO 00 NO + 286 23 10 = #O___@OO_# : len=10 : H3 13 H3 + 287 23 11 = #O___@__O# : len=10 : NO 00 NO + 288 23 12 = #O___@O_O# : len=10 : NO 00 NO + 289 23 13 = #O___@_OO# : len=10 : NO 00 NO + 290 23 14 = #O___@OOO# : len=10 : S4 00 S4 + 291 23 15 = #O___@____# : len=11 : NO 00 NO + 292 23 16 = #O___@O___# : len=11 : NO 00 NO + 293 23 17 = #O___@_O__# : len=11 : NO 00 NO + 294 23 18 = #O___@OO__# : len=11 : H3 13 H3 + 295 23 19 = #O___@__O_# : len=11 : NO 00 NO + 296 23 20 = #O___@O_O_# : len=11 : D3 02 D3 + 297 23 21 = #O___@_OO_# : len=11 : D3 01 D3 + 298 23 22 = #O___@OOO_# : len=11 : H4 00 H4 + 299 23 23 = #O___@___O# : len=11 : NO 00 NO + 300 24 0 = #O__O@# : len= 7 : NO 00 NO + 301 24 1 = #O__O@_# : len= 8 : NO 00 NO + 302 24 2 = #O__O@O# : len= 8 : NO 00 NO + 303 24 3 = #O__O@__# : len= 9 : NO 00 NO + 304 24 4 = #O__O@O_# : len= 9 : NO 00 H3 + 305 24 5 = #O__O@_O# : len= 9 : NO 00 NO + 306 24 6 = #O__O@OO# : len= 9 : S4 00 S4 + 307 24 7 = #O__O@___# : len=10 : NO 00 NO + 308 24 8 = #O__O@O__# : len=10 : H3 22 H3 + 309 24 9 = #O__O@_O_# : len=10 : D3 01 D3 + 310 24 10 = #O__O@OO_# : len=10 : H4 00 H4 + 311 24 11 = #O__O@__O# : len=10 : NO 00 NO + 312 24 12 = #O__O@O_O# : len=10 : D4 00 D4 + 313 24 13 = #O__O@_OO# : len=10 : D4 00 D4 + 314 24 14 = #O__O@OOO# : len=10 : L5 00 L5 + 315 24 15 = #O__O@____# : len=11 : NO 00 NO + 316 24 16 = #O__O@O___# : len=11 : H3 22 H3 + 317 24 17 = #O__O@_O__# : len=11 : D3 01 D3 + 318 24 18 = #O__O@OO__# : len=11 : H4 00 H4 + 319 24 19 = #O__O@__O_# : len=11 : NO 00 NO + 320 24 20 = #O__O@O_O_# : len=11 : D4 00 D4 + 321 24 21 = #O__O@_OO_# : len=11 : D4 00 D4 + 322 24 22 = #O__O@OOO_# : len=11 : L5 00 L5 + 323 24 23 = #O__O@___O# : len=11 : NO 00 NO + 324 24 24 = #O__O@O__O# : len=11 : NO 00 H3 + 325 25 0 = #O_O_@# : len= 7 : NO 00 NO + 326 25 1 = #O_O_@_# : len= 8 : NO 00 NO + 327 25 2 = #O_O_@O# : len= 8 : NO 00 NO + 328 25 3 = #O_O_@__# : len= 9 : NO 00 NO + 329 25 4 = #O_O_@O_# : len= 9 : NO 00 D3 + 330 25 5 = #O_O_@_O# : len= 9 : NO 00 NO + 331 25 6 = #O_O_@OO# : len= 9 : D4 00 D4 + 332 25 7 = #O_O_@___# : len=10 : NO 00 NO + 333 25 8 = #O_O_@O__# : len=10 : NO 00 D3 + 334 25 9 = #O_O_@_O_# : len=10 : NO 00 NO + 335 25 10 = #O_O_@OO_# : len=10 : D4 00 D4 + 336 25 11 = #O_O_@__O# : len=10 : NO 00 NO + 337 25 12 = #O_O_@O_O# : len=10 : NO 00 D3 + 338 25 13 = #O_O_@_OO# : len=10 : NO 00 NO + 339 25 14 = #O_O_@OOO# : len=10 : NO 00 D4 + 340 25 15 = #O_O_@____# : len=11 : NO 00 NO + 341 25 16 = #O_O_@O___# : len=11 : NO 00 D3 + 342 25 17 = #O_O_@_O__# : len=11 : NO 00 NO + 343 25 18 = #O_O_@OO__# : len=11 : D4 00 D4 + 344 25 19 = #O_O_@__O_# : len=11 : NO 00 NO + 345 25 20 = #O_O_@O_O_# : len=11 : NO 00 D3 + 346 25 21 = #O_O_@_OO_# : len=11 : NO 00 D3 + 347 25 22 = #O_O_@OOO_# : len=11 : S4 00 H4 + 348 25 23 = #O_O_@___O# : len=11 : NO 00 NO + 349 25 24 = #O_O_@O__O# : len=11 : NO 00 D3 + 350 25 25 = #O_O_@_O_O# : len=11 : NO 00 NO + 351 26 0 = #O_OO@# : len= 7 : D4 00 D4 + 352 26 1 = #O_OO@_# : len= 8 : D4 00 D4 + 353 26 2 = #O_OO@O# : len= 8 : NO 00 D4 + 354 26 3 = #O_OO@__# : len= 9 : D4 00 D4 + 355 26 4 = #O_OO@O_# : len= 9 : S4 00 H4 + 356 26 5 = #O_OO@_O# : len= 9 : X4 00 X4 + 357 26 6 = #O_OO@OO# : len= 9 : L5 00 L5 + 358 26 7 = #O_OO@___# : len=10 : D4 00 D4 + 359 26 8 = #O_OO@O__# : len=10 : S4 00 H4 + 360 26 9 = #O_OO@_O_# : len=10 : X4 00 X4 + 361 26 10 = #O_OO@OO_# : len=10 : L5 00 L5 + 362 26 11 = #O_OO@__O# : len=10 : D4 00 D4 + 363 26 12 = #O_OO@O_O# : len=10 : NO 00 H4 + 364 26 13 = #O_OO@_OO# : len=10 : D4 00 X4 + 365 26 14 = #O_OO@OOO# : len=10 : L6 00 L6 + 366 26 15 = #O_OO@____# : len=11 : D4 00 D4 + 367 26 16 = #O_OO@O___# : len=11 : S4 00 H4 + 368 26 17 = #O_OO@_O__# : len=11 : X4 00 X4 + 369 26 18 = #O_OO@OO__# : len=11 : L5 00 L5 + 370 26 19 = #O_OO@__O_# : len=11 : D4 00 D4 + 371 26 20 = #O_OO@O_O_# : len=11 : NO 00 H4 + 372 26 21 = #O_OO@_OO_# : len=11 : D4 00 X4 + 373 26 22 = #O_OO@OOO_# : len=11 : L6 00 L6 + 374 26 23 = #O_OO@___O# : len=11 : D4 00 D4 + 375 26 24 = #O_OO@O__O# : len=11 : S4 00 H4 + 376 26 25 = #O_OO@_O_O# : len=11 : X4 00 X4 + 377 26 26 = #O_OO@OO_O# : len=11 : L5 00 L5 + 378 27 0 = #OO__@# : len= 7 : NO 00 NO + 379 27 1 = #OO__@_# : len= 8 : NO 00 NO + 380 27 2 = #OO__@O# : len= 8 : NO 00 NO + 381 27 3 = #OO__@__# : len= 9 : NO 00 NO + 382 27 4 = #OO__@O_# : len= 9 : NO 00 NO + 383 27 5 = #OO__@_O# : len= 9 : NO 00 NO + 384 27 6 = #OO__@OO# : len= 9 : NO 00 NO + 385 27 7 = #OO__@___# : len=10 : NO 00 NO + 386 27 8 = #OO__@O__# : len=10 : NO 00 NO + 387 27 9 = #OO__@_O_# : len=10 : NO 00 NO + 388 27 10 = #OO__@OO_# : len=10 : NO 00 H3 + 389 27 11 = #OO__@__O# : len=10 : NO 00 NO + 390 27 12 = #OO__@O_O# : len=10 : NO 00 NO + 391 27 13 = #OO__@_OO# : len=10 : NO 00 NO + 392 27 14 = #OO__@OOO# : len=10 : S4 00 S4 + 393 27 15 = #OO__@____# : len=11 : NO 00 NO + 394 27 16 = #OO__@O___# : len=11 : NO 00 NO + 395 27 17 = #OO__@_O__# : len=11 : NO 00 NO + 396 27 18 = #OO__@OO__# : len=11 : H3 13 H3 + 397 27 19 = #OO__@__O_# : len=11 : NO 00 NO + 398 27 20 = #OO__@O_O_# : len=11 : D3 02 D3 + 399 27 21 = #OO__@_OO_# : len=11 : D3 01 D3 + 400 27 22 = #OO__@OOO_# : len=11 : H4 00 H4 + 401 27 23 = #OO__@___O# : len=11 : NO 00 NO + 402 27 24 = #OO__@O__O# : len=11 : NO 00 NO + 403 27 25 = #OO__@_O_O# : len=11 : NO 00 NO + 404 27 26 = #OO__@OO_O# : len=11 : D4 00 D4 + 405 27 27 = #OO__@__OO# : len=11 : NO 00 NO + 406 28 0 = #OO_O@# : len= 7 : D4 00 D4 + 407 28 1 = #OO_O@_# : len= 8 : D4 00 D4 + 408 28 2 = #OO_O@O# : len= 8 : NO 00 D4 + 409 28 3 = #OO_O@__# : len= 9 : D4 00 D4 + 410 28 4 = #OO_O@O_# : len= 9 : NO 00 D4 + 411 28 5 = #OO_O@_O# : len= 9 : D4 00 D4 + 412 28 6 = #OO_O@OO# : len= 9 : NO 00 D4 + 413 28 7 = #OO_O@___# : len=10 : D4 00 D4 + 414 28 8 = #OO_O@O__# : len=10 : NO 00 D4 + 415 28 9 = #OO_O@_O_# : len=10 : D4 00 D4 + 416 28 10 = #OO_O@OO_# : len=10 : S4 00 H4 + 417 28 11 = #OO_O@__O# : len=10 : D4 00 D4 + 418 28 12 = #OO_O@O_O# : len=10 : D4 00 X4 + 419 28 13 = #OO_O@_OO# : len=10 : X4 00 X4 + 420 28 14 = #OO_O@OOO# : len=10 : L5 00 L5 + 421 28 15 = #OO_O@____# : len=11 : D4 00 D4 + 422 28 16 = #OO_O@O___# : len=11 : NO 00 D4 + 423 28 17 = #OO_O@_O__# : len=11 : D4 00 D4 + 424 28 18 = #OO_O@OO__# : len=11 : S4 00 H4 + 425 28 19 = #OO_O@__O_# : len=11 : D4 00 D4 + 426 28 20 = #OO_O@O_O_# : len=11 : D4 00 X4 + 427 28 21 = #OO_O@_OO_# : len=11 : X4 00 X4 + 428 28 22 = #OO_O@OOO_# : len=11 : L5 00 L5 + 429 28 23 = #OO_O@___O# : len=11 : D4 00 D4 + 430 28 24 = #OO_O@O__O# : len=11 : NO 00 D4 + 431 28 25 = #OO_O@_O_O# : len=11 : D4 00 D4 + 432 28 26 = #OO_O@OO_O# : len=11 : NO 00 H4 + 433 28 27 = #OO_O@__OO# : len=11 : D4 00 D4 + 434 28 28 = #OO_O@O_OO# : len=11 : NO 00 X4 + 435 29 0 = #OOO_@# : len= 7 : D4 00 D4 + 436 29 1 = #OOO_@_# : len= 8 : D4 00 D4 + 437 29 2 = #OOO_@O# : len= 8 : NO 00 D4 + 438 29 3 = #OOO_@__# : len= 9 : D4 00 D4 + 439 29 4 = #OOO_@O_# : len= 9 : NO 00 D4 + 440 29 5 = #OOO_@_O# : len= 9 : D4 00 D4 + 441 29 6 = #OOO_@OO# : len= 9 : NO 00 D4 + 442 29 7 = #OOO_@___# : len=10 : D4 00 D4 + 443 29 8 = #OOO_@O__# : len=10 : NO 00 D4 + 444 29 9 = #OOO_@_O_# : len=10 : D4 00 D4 + 445 29 10 = #OOO_@OO_# : len=10 : NO 00 D4 + 446 29 11 = #OOO_@__O# : len=10 : D4 00 D4 + 447 29 12 = #OOO_@O_O# : len=10 : NO 00 D4 + 448 29 13 = #OOO_@_OO# : len=10 : D4 00 D4 + 449 29 14 = #OOO_@OOO# : len=10 : NO 00 D4 + 450 29 15 = #OOO_@____# : len=11 : D4 00 D4 + 451 29 16 = #OOO_@O___# : len=11 : NO 00 D4 + 452 29 17 = #OOO_@_O__# : len=11 : D4 00 D4 + 453 29 18 = #OOO_@OO__# : len=11 : NO 00 D4 + 454 29 19 = #OOO_@__O_# : len=11 : D4 00 D4 + 455 29 20 = #OOO_@O_O_# : len=11 : NO 00 D4 + 456 29 21 = #OOO_@_OO_# : len=11 : D4 00 D4 + 457 29 22 = #OOO_@OOO_# : len=11 : S4 00 H4 + 458 29 23 = #OOO_@___O# : len=11 : D4 00 D4 + 459 29 24 = #OOO_@O__O# : len=11 : NO 00 D4 + 460 29 25 = #OOO_@_O_O# : len=11 : D4 00 D4 + 461 29 26 = #OOO_@OO_O# : len=11 : D4 00 X4 + 462 29 27 = #OOO_@__OO# : len=11 : D4 00 D4 + 463 29 28 = #OOO_@O_OO# : len=11 : D4 00 X4 + 464 29 29 = #OOO_@_OOO# : len=11 : X4 00 X4 + 465 30 0 = #OOOO@# : len= 7 : L5 00 L5 + 466 30 1 = #OOOO@_# : len= 8 : L5 00 L5 + 467 30 2 = #OOOO@O# : len= 8 : L6 00 L6 + 468 30 3 = #OOOO@__# : len= 9 : L5 00 L5 + 469 30 4 = #OOOO@O_# : len= 9 : L6 00 L6 + 470 30 5 = #OOOO@_O# : len= 9 : L5 00 L5 + 471 30 6 = #OOOO@OO# : len= 9 : L6 00 L6 + 472 30 7 = #OOOO@___# : len=10 : L5 00 L5 + 473 30 8 = #OOOO@O__# : len=10 : L6 00 L6 + 474 30 9 = #OOOO@_O_# : len=10 : L5 00 L5 + 475 30 10 = #OOOO@OO_# : len=10 : L6 00 L6 + 476 30 11 = #OOOO@__O# : len=10 : L5 00 L5 + 477 30 12 = #OOOO@O_O# : len=10 : L6 00 L6 + 478 30 13 = #OOOO@_OO# : len=10 : L5 00 L5 + 479 30 14 = #OOOO@OOO# : len=10 : L6 00 L6 + 480 30 15 = #OOOO@____# : len=11 : L5 00 L5 + 481 30 16 = #OOOO@O___# : len=11 : L6 00 L6 + 482 30 17 = #OOOO@_O__# : len=11 : L5 00 L5 + 483 30 18 = #OOOO@OO__# : len=11 : L6 00 L6 + 484 30 19 = #OOOO@__O_# : len=11 : L5 00 L5 + 485 30 20 = #OOOO@O_O_# : len=11 : L6 00 L6 + 486 30 21 = #OOOO@_OO_# : len=11 : L5 00 L5 + 487 30 22 = #OOOO@OOO_# : len=11 : L6 00 L6 + 488 30 23 = #OOOO@___O# : len=11 : L5 00 L5 + 489 30 24 = #OOOO@O__O# : len=11 : L6 00 L6 + 490 30 25 = #OOOO@_O_O# : len=11 : L5 00 L5 + 491 30 26 = #OOOO@OO_O# : len=11 : L6 00 L6 + 492 30 27 = #OOOO@__OO# : len=11 : L5 00 L5 + 493 30 28 = #OOOO@O_OO# : len=11 : L6 00 L6 + 494 30 29 = #OOOO@_OOO# : len=11 : L5 00 L5 + 495 30 30 = #OOOO@OOOO# : len=11 : L6 00 L6 + 496 31 0 = _____@# : len= 7 : NO 00 NO + 497 31 1 = _____@_# : len= 8 : NO 00 NO + 498 31 2 = _____@O# : len= 8 : NO 00 NO + 499 31 3 = _____@__# : len= 9 : NO 00 NO + 500 31 4 = _____@O_# : len= 9 : NO 00 NO + 501 31 5 = _____@_O# : len= 9 : NO 00 NO + 502 31 6 = _____@OO# : len= 9 : NO 00 NO + 503 31 7 = _____@___# : len=10 : NO 00 NO + 504 31 8 = _____@O__# : len=10 : NO 00 NO + 505 31 9 = _____@_O_# : len=10 : NO 00 NO + 506 31 10 = _____@OO_# : len=10 : H3 13 H3 + 507 31 11 = _____@__O# : len=10 : NO 00 NO + 508 31 12 = _____@O_O# : len=10 : NO 00 NO + 509 31 13 = _____@_OO# : len=10 : NO 00 NO + 510 31 14 = _____@OOO# : len=10 : S4 00 S4 + 511 31 15 = _____@____# : len=11 : NO 00 NO + 512 31 16 = _____@O___# : len=11 : NO 00 NO + 513 31 17 = _____@_O__# : len=11 : NO 00 NO + 514 31 18 = _____@OO__# : len=11 : H3 13 H3 + 515 31 19 = _____@__O_# : len=11 : NO 00 NO + 516 31 20 = _____@O_O_# : len=11 : D3 02 D3 + 517 31 21 = _____@_OO_# : len=11 : D3 01 D3 + 518 31 22 = _____@OOO_# : len=11 : H4 00 H4 + 519 31 23 = _____@___O# : len=11 : NO 00 NO + 520 31 24 = _____@O__O# : len=11 : NO 00 NO + 521 31 25 = _____@_O_O# : len=11 : NO 00 NO + 522 31 26 = _____@OO_O# : len=11 : D4 00 D4 + 523 31 27 = _____@__OO# : len=11 : NO 00 NO + 524 31 28 = _____@O_OO# : len=11 : D4 00 D4 + 525 31 29 = _____@_OOO# : len=11 : D4 00 D4 + 526 31 30 = _____@OOOO# : len=11 : L5 00 L5 + 527 31 31 = _____@_____ : len=11 : NO 00 NO + 528 32 0 = ____O@# : len= 7 : NO 00 NO + 529 32 1 = ____O@_# : len= 8 : NO 00 NO + 530 32 2 = ____O@O# : len= 8 : NO 00 NO + 531 32 3 = ____O@__# : len= 9 : NO 00 NO + 532 32 4 = ____O@O_# : len= 9 : H3 22 H3 + 533 32 5 = ____O@_O# : len= 9 : NO 00 NO + 534 32 6 = ____O@OO# : len= 9 : S4 00 S4 + 535 32 7 = ____O@___# : len=10 : NO 00 NO + 536 32 8 = ____O@O__# : len=10 : H3 22 H3 + 537 32 9 = ____O@_O_# : len=10 : D3 01 D3 + 538 32 10 = ____O@OO_# : len=10 : H4 00 H4 + 539 32 11 = ____O@__O# : len=10 : NO 00 NO + 540 32 12 = ____O@O_O# : len=10 : D4 00 D4 + 541 32 13 = ____O@_OO# : len=10 : D4 00 D4 + 542 32 14 = ____O@OOO# : len=10 : L5 00 L5 + 543 32 15 = ____O@____# : len=11 : NO 00 NO + 544 32 16 = ____O@O___# : len=11 : H3 22 H3 + 545 32 17 = ____O@_O__# : len=11 : D3 01 D3 + 546 32 18 = ____O@OO__# : len=11 : H4 00 H4 + 547 32 19 = ____O@__O_# : len=11 : NO 00 NO + 548 32 20 = ____O@O_O_# : len=11 : D4 00 D4 + 549 32 21 = ____O@_OO_# : len=11 : D4 00 D4 + 550 32 22 = ____O@OOO_# : len=11 : L5 00 L5 + 551 32 23 = ____O@___O# : len=11 : NO 00 NO + 552 32 24 = ____O@O__O# : len=11 : H3 22 H3 + 553 32 25 = ____O@_O_O# : len=11 : NO 00 D3 + 554 32 26 = ____O@OO_O# : len=11 : S4 00 H4 + 555 32 27 = ____O@__OO# : len=11 : NO 00 NO + 556 32 28 = ____O@O_OO# : len=11 : NO 00 D4 + 557 32 29 = ____O@_OOO# : len=11 : NO 00 D4 + 558 32 30 = ____O@OOOO# : len=11 : L6 00 L6 + 559 32 31 = ____O@_____ : len=11 : NO 00 NO + 560 32 32 = ____O@O____ : len=11 : H3 22 H3 + 561 33 0 = ___O_@# : len= 7 : NO 00 NO + 562 33 1 = ___O_@_# : len= 8 : NO 00 NO + 563 33 2 = ___O_@O# : len= 8 : NO 00 NO + 564 33 3 = ___O_@__# : len= 9 : NO 00 NO + 565 33 4 = ___O_@O_# : len= 9 : D3 10 D3 + 566 33 5 = ___O_@_O# : len= 9 : NO 00 NO + 567 33 6 = ___O_@OO# : len= 9 : D4 00 D4 + 568 33 7 = ___O_@___# : len=10 : NO 00 NO + 569 33 8 = ___O_@O__# : len=10 : D3 10 D3 + 570 33 9 = ___O_@_O_# : len=10 : NO 00 NO + 571 33 10 = ___O_@OO_# : len=10 : D4 00 D4 + 572 33 11 = ___O_@__O# : len=10 : NO 00 NO + 573 33 12 = ___O_@O_O# : len=10 : NO 00 D3 + 574 33 13 = ___O_@_OO# : len=10 : NO 00 NO + 575 33 14 = ___O_@OOO# : len=10 : NO 00 D4 + 576 33 15 = ___O_@____# : len=11 : NO 00 NO + 577 33 16 = ___O_@O___# : len=11 : D3 10 D3 + 578 33 17 = ___O_@_O__# : len=11 : NO 00 NO + 579 33 18 = ___O_@OO__# : len=11 : D4 00 D4 + 580 33 19 = ___O_@__O_# : len=11 : NO 00 NO + 581 33 20 = ___O_@O_O_# : len=11 : NO 00 D3 + 582 33 21 = ___O_@_OO_# : len=11 : NO 00 D3 + 583 33 22 = ___O_@OOO_# : len=11 : S4 00 H4 + 584 33 23 = ___O_@___O# : len=11 : NO 00 NO + 585 33 24 = ___O_@O__O# : len=11 : D3 10 D3 + 586 33 25 = ___O_@_O_O# : len=11 : NO 00 NO + 587 33 26 = ___O_@OO_O# : len=11 : X4 00 X4 + 588 33 27 = ___O_@__OO# : len=11 : NO 00 NO + 589 33 28 = ___O_@O_OO# : len=11 : D4 00 D4 + 590 33 29 = ___O_@_OOO# : len=11 : D4 00 D4 + 591 33 30 = ___O_@OOOO# : len=11 : L5 00 L5 + 592 33 31 = ___O_@_____ : len=11 : NO 00 NO + 593 33 32 = ___O_@O____ : len=11 : D3 10 D3 + 594 33 33 = ___O_@_O___ : len=11 : NO 00 NO + 595 34 0 = ___OO@# : len= 7 : NO 00 NO + 596 34 1 = ___OO@_# : len= 8 : H3 31 H3 + 597 34 2 = ___OO@O# : len= 8 : S4 00 S4 + 598 34 3 = ___OO@__# : len= 9 : H3 31 H3 + 599 34 4 = ___OO@O_# : len= 9 : H4 00 H4 + 600 34 5 = ___OO@_O# : len= 9 : D4 00 D4 + 601 34 6 = ___OO@OO# : len= 9 : L5 00 L5 + 602 34 7 = ___OO@___# : len=10 : H3 31 H3 + 603 34 8 = ___OO@O__# : len=10 : H4 00 H4 + 604 34 9 = ___OO@_O_# : len=10 : D4 00 D4 + 605 34 10 = ___OO@OO_# : len=10 : L5 00 L5 + 606 34 11 = ___OO@__O# : len=10 : H3 31 H3 + 607 34 12 = ___OO@O_O# : len=10 : S4 00 H4 + 608 34 13 = ___OO@_OO# : len=10 : NO 00 D4 + 609 34 14 = ___OO@OOO# : len=10 : L6 00 L6 + 610 34 15 = ___OO@____# : len=11 : H3 31 H3 + 611 34 16 = ___OO@O___# : len=11 : H4 00 H4 + 612 34 17 = ___OO@_O__# : len=11 : D4 00 D4 + 613 34 18 = ___OO@OO__# : len=11 : L5 00 L5 + 614 34 19 = ___OO@__O_# : len=11 : H3 31 H3 + 615 34 20 = ___OO@O_O_# : len=11 : S4 00 H4 + 616 34 21 = ___OO@_OO_# : len=11 : NO 00 D4 + 617 34 22 = ___OO@OOO_# : len=11 : L6 00 L6 + 618 34 23 = ___OO@___O# : len=11 : H3 31 H3 + 619 34 24 = ___OO@O__O# : len=11 : H4 00 H4 + 620 34 25 = ___OO@_O_O# : len=11 : D4 00 D4 + 621 34 26 = ___OO@OO_O# : len=11 : L5 00 L5 + 622 34 27 = ___OO@__OO# : len=11 : H3 31 H3 + 623 34 28 = ___OO@O_OO# : len=11 : S4 00 H4 + 624 34 29 = ___OO@_OOO# : len=11 : NO 00 D4 + 625 34 30 = ___OO@OOOO# : len=11 : L6 00 L6 + 626 34 31 = ___OO@_____ : len=11 : H3 31 H3 + 627 34 32 = ___OO@O____ : len=11 : H4 00 H4 + 628 34 33 = ___OO@_O___ : len=11 : D4 00 D4 + 629 34 34 = ___OO@OO___ : len=11 : L5 00 L5 + 630 35 0 = __O__@# : len= 7 : NO 00 NO + 631 35 1 = __O__@_# : len= 8 : NO 00 NO + 632 35 2 = __O__@O# : len= 8 : NO 00 NO + 633 35 3 = __O__@__# : len= 9 : NO 00 NO + 634 35 4 = __O__@O_# : len= 9 : NO 00 NO + 635 35 5 = __O__@_O# : len= 9 : NO 00 NO + 636 35 6 = __O__@OO# : len= 9 : NO 00 NO + 637 35 7 = __O__@___# : len=10 : NO 00 NO + 638 35 8 = __O__@O__# : len=10 : NO 00 NO + 639 35 9 = __O__@_O_# : len=10 : NO 00 NO + 640 35 10 = __O__@OO_# : len=10 : NO 00 H3 + 641 35 11 = __O__@__O# : len=10 : NO 00 NO + 642 35 12 = __O__@O_O# : len=10 : NO 00 NO + 643 35 13 = __O__@_OO# : len=10 : NO 00 NO + 644 35 14 = __O__@OOO# : len=10 : S4 00 S4 + 645 35 15 = __O__@____# : len=11 : NO 00 NO + 646 35 16 = __O__@O___# : len=11 : NO 00 NO + 647 35 17 = __O__@_O__# : len=11 : NO 00 NO + 648 35 18 = __O__@OO__# : len=11 : H3 13 H3 + 649 35 19 = __O__@__O_# : len=11 : NO 00 NO + 650 35 20 = __O__@O_O_# : len=11 : D3 02 D3 + 651 35 21 = __O__@_OO_# : len=11 : D3 01 D3 + 652 35 22 = __O__@OOO_# : len=11 : H4 00 H4 + 653 35 23 = __O__@___O# : len=11 : NO 00 NO + 654 35 24 = __O__@O__O# : len=11 : NO 00 NO + 655 35 25 = __O__@_O_O# : len=11 : NO 00 NO + 656 35 26 = __O__@OO_O# : len=11 : D4 00 D4 + 657 35 27 = __O__@__OO# : len=11 : NO 00 NO + 658 35 28 = __O__@O_OO# : len=11 : D4 00 D4 + 659 35 29 = __O__@_OOO# : len=11 : D4 00 D4 + 660 35 30 = __O__@OOOO# : len=11 : L5 00 L5 + 661 35 31 = __O__@_____ : len=11 : NO 00 NO + 662 35 32 = __O__@O____ : len=11 : NO 00 NO + 663 35 33 = __O__@_O___ : len=11 : NO 00 NO + 664 35 34 = __O__@OO___ : len=11 : H3 13 H3 + 665 35 35 = __O__@__O__ : len=11 : NO 00 NO + 666 36 0 = __O_O@# : len= 7 : NO 00 NO + 667 36 1 = __O_O@_# : len= 8 : D3 20 D3 + 668 36 2 = __O_O@O# : len= 8 : D4 00 D4 + 669 36 3 = __O_O@__# : len= 9 : D3 20 D3 + 670 36 4 = __O_O@O_# : len= 9 : D4 00 D4 + 671 36 5 = __O_O@_O# : len= 9 : NO 00 D3 + 672 36 6 = __O_O@OO# : len= 9 : NO 00 D4 + 673 36 7 = __O_O@___# : len=10 : D3 20 D3 + 674 36 8 = __O_O@O__# : len=10 : D4 00 D4 + 675 36 9 = __O_O@_O_# : len=10 : NO 00 D3 + 676 36 10 = __O_O@OO_# : len=10 : S4 00 H4 + 677 36 11 = __O_O@__O# : len=10 : D3 20 D3 + 678 36 12 = __O_O@O_O# : len=10 : X4 00 X4 + 679 36 13 = __O_O@_OO# : len=10 : D4 00 D4 + 680 36 14 = __O_O@OOO# : len=10 : L5 00 L5 + 681 36 15 = __O_O@____# : len=11 : D3 20 D3 + 682 36 16 = __O_O@O___# : len=11 : D4 00 D4 + 683 36 17 = __O_O@_O__# : len=11 : NO 00 D3 + 684 36 18 = __O_O@OO__# : len=11 : S4 00 H4 + 685 36 19 = __O_O@__O_# : len=11 : D3 20 D3 + 686 36 20 = __O_O@O_O_# : len=11 : X4 00 X4 + 687 36 21 = __O_O@_OO_# : len=11 : D4 00 D4 + 688 36 22 = __O_O@OOO_# : len=11 : L5 00 L5 + 689 36 23 = __O_O@___O# : len=11 : D3 20 D3 + 690 36 24 = __O_O@O__O# : len=11 : D4 00 D4 + 691 36 25 = __O_O@_O_O# : len=11 : NO 00 D3 + 692 36 26 = __O_O@OO_O# : len=11 : NO 00 H4 + 693 36 27 = __O_O@__OO# : len=11 : D3 20 D3 + 694 36 28 = __O_O@O_OO# : len=11 : D4 00 X4 + 695 36 29 = __O_O@_OOO# : len=11 : NO 00 D4 + 696 36 30 = __O_O@OOOO# : len=11 : L6 00 L6 + 697 36 31 = __O_O@_____ : len=11 : D3 20 D3 + 698 36 32 = __O_O@O____ : len=11 : D4 00 D4 + 699 36 33 = __O_O@_O___ : len=11 : NO 00 D3 + 700 36 34 = __O_O@OO___ : len=11 : S4 00 H4 + 701 36 35 = __O_O@__O__ : len=11 : D3 20 D3 + 702 36 36 = __O_O@O_O__ : len=11 : X4 00 X4 + 703 37 0 = __OO_@# : len= 7 : NO 00 NO + 704 37 1 = __OO_@_# : len= 8 : D3 10 D3 + 705 37 2 = __OO_@O# : len= 8 : D4 00 D4 + 706 37 3 = __OO_@__# : len= 9 : D3 10 D3 + 707 37 4 = __OO_@O_# : len= 9 : D4 00 D4 + 708 37 5 = __OO_@_O# : len= 9 : NO 00 D3 + 709 37 6 = __OO_@OO# : len= 9 : NO 00 D4 + 710 37 7 = __OO_@___# : len=10 : D3 10 D3 + 711 37 8 = __OO_@O__# : len=10 : D4 00 D4 + 712 37 9 = __OO_@_O_# : len=10 : NO 00 D3 + 713 37 10 = __OO_@OO_# : len=10 : NO 00 D4 + 714 37 11 = __OO_@__O# : len=10 : D3 10 D3 + 715 37 12 = __OO_@O_O# : len=10 : D4 00 D4 + 716 37 13 = __OO_@_OO# : len=10 : NO 00 D3 + 717 37 14 = __OO_@OOO# : len=10 : NO 00 D4 + 718 37 15 = __OO_@____# : len=11 : D3 10 D3 + 719 37 16 = __OO_@O___# : len=11 : D4 00 D4 + 720 37 17 = __OO_@_O__# : len=11 : NO 00 D3 + 721 37 18 = __OO_@OO__# : len=11 : NO 00 D4 + 722 37 19 = __OO_@__O_# : len=11 : D3 10 D3 + 723 37 20 = __OO_@O_O_# : len=11 : D4 00 D4 + 724 37 21 = __OO_@_OO_# : len=11 : NO 00 D3 + 725 37 22 = __OO_@OOO_# : len=11 : S4 00 H4 + 726 37 23 = __OO_@___O# : len=11 : D3 10 D3 + 727 37 24 = __OO_@O__O# : len=11 : D4 00 D4 + 728 37 25 = __OO_@_O_O# : len=11 : NO 00 D3 + 729 37 26 = __OO_@OO_O# : len=11 : D4 00 X4 + 730 37 27 = __OO_@__OO# : len=11 : D3 10 D3 + 731 37 28 = __OO_@O_OO# : len=11 : X4 00 X4 + 732 37 29 = __OO_@_OOO# : len=11 : D4 00 D4 + 733 37 30 = __OO_@OOOO# : len=11 : L5 00 L5 + 734 37 31 = __OO_@_____ : len=11 : D3 10 D3 + 735 37 32 = __OO_@O____ : len=11 : D4 00 D4 + 736 37 33 = __OO_@_O___ : len=11 : NO 00 D3 + 737 37 34 = __OO_@OO___ : len=11 : NO 00 D4 + 738 37 35 = __OO_@__O__ : len=11 : D3 10 D3 + 739 37 36 = __OO_@O_O__ : len=11 : D4 00 D4 + 740 37 37 = __OO_@_OO__ : len=11 : NO 00 D3 + 741 38 0 = __OOO@# : len= 7 : S4 00 S4 + 742 38 1 = __OOO@_# : len= 8 : H4 00 H4 + 743 38 2 = __OOO@O# : len= 8 : L5 00 L5 + 744 38 3 = __OOO@__# : len= 9 : H4 00 H4 + 745 38 4 = __OOO@O_# : len= 9 : L5 00 L5 + 746 38 5 = __OOO@_O# : len= 9 : S4 00 H4 + 747 38 6 = __OOO@OO# : len= 9 : L6 00 L6 + 748 38 7 = __OOO@___# : len=10 : H4 00 H4 + 749 38 8 = __OOO@O__# : len=10 : L5 00 L5 + 750 38 9 = __OOO@_O_# : len=10 : S4 00 H4 + 751 38 10 = __OOO@OO_# : len=10 : L6 00 L6 + 752 38 11 = __OOO@__O# : len=10 : H4 00 H4 + 753 38 12 = __OOO@O_O# : len=10 : L5 00 L5 + 754 38 13 = __OOO@_OO# : len=10 : S4 00 H4 + 755 38 14 = __OOO@OOO# : len=10 : L6 00 L6 + 756 38 15 = __OOO@____# : len=11 : H4 00 H4 + 757 38 16 = __OOO@O___# : len=11 : L5 00 L5 + 758 38 17 = __OOO@_O__# : len=11 : S4 00 H4 + 759 38 18 = __OOO@OO__# : len=11 : L6 00 L6 + 760 38 19 = __OOO@__O_# : len=11 : H4 00 H4 + 761 38 20 = __OOO@O_O_# : len=11 : L5 00 L5 + 762 38 21 = __OOO@_OO_# : len=11 : S4 00 H4 + 763 38 22 = __OOO@OOO_# : len=11 : L6 00 L6 + 764 38 23 = __OOO@___O# : len=11 : H4 00 H4 + 765 38 24 = __OOO@O__O# : len=11 : L5 00 L5 + 766 38 25 = __OOO@_O_O# : len=11 : S4 00 H4 + 767 38 26 = __OOO@OO_O# : len=11 : L6 00 L6 + 768 38 27 = __OOO@__OO# : len=11 : H4 00 H4 + 769 38 28 = __OOO@O_OO# : len=11 : L5 00 L5 + 770 38 29 = __OOO@_OOO# : len=11 : S4 00 H4 + 771 38 30 = __OOO@OOOO# : len=11 : L6 00 L6 + 772 38 31 = __OOO@_____ : len=11 : H4 00 H4 + 773 38 32 = __OOO@O____ : len=11 : L5 00 L5 + 774 38 33 = __OOO@_O___ : len=11 : S4 00 H4 + 775 38 34 = __OOO@OO___ : len=11 : L6 00 L6 + 776 38 35 = __OOO@__O__ : len=11 : H4 00 H4 + 777 38 36 = __OOO@O_O__ : len=11 : L5 00 L5 + 778 38 37 = __OOO@_OO__ : len=11 : S4 00 H4 + 779 38 38 = __OOO@OOO__ : len=11 : L6 00 L6 + 780 39 0 = _O___@# : len= 7 : NO 00 NO + 781 39 1 = _O___@_# : len= 8 : NO 00 NO + 782 39 2 = _O___@O# : len= 8 : NO 00 NO + 783 39 3 = _O___@__# : len= 9 : NO 00 NO + 784 39 4 = _O___@O_# : len= 9 : NO 00 NO + 785 39 5 = _O___@_O# : len= 9 : NO 00 NO + 786 39 6 = _O___@OO# : len= 9 : NO 00 NO + 787 39 7 = _O___@___# : len=10 : NO 00 NO + 788 39 8 = _O___@O__# : len=10 : NO 00 NO + 789 39 9 = _O___@_O_# : len=10 : NO 00 NO + 790 39 10 = _O___@OO_# : len=10 : H3 13 H3 + 791 39 11 = _O___@__O# : len=10 : NO 00 NO + 792 39 12 = _O___@O_O# : len=10 : NO 00 NO + 793 39 13 = _O___@_OO# : len=10 : NO 00 NO + 794 39 14 = _O___@OOO# : len=10 : S4 00 S4 + 795 39 15 = _O___@____# : len=11 : NO 00 NO + 796 39 16 = _O___@O___# : len=11 : NO 00 NO + 797 39 17 = _O___@_O__# : len=11 : NO 00 NO + 798 39 18 = _O___@OO__# : len=11 : H3 13 H3 + 799 39 19 = _O___@__O_# : len=11 : NO 00 NO + 800 39 20 = _O___@O_O_# : len=11 : D3 02 D3 + 801 39 21 = _O___@_OO_# : len=11 : D3 01 D3 + 802 39 22 = _O___@OOO_# : len=11 : H4 00 H4 + 803 39 23 = _O___@___O# : len=11 : NO 00 NO + 804 39 24 = _O___@O__O# : len=11 : NO 00 NO + 805 39 25 = _O___@_O_O# : len=11 : NO 00 NO + 806 39 26 = _O___@OO_O# : len=11 : D4 00 D4 + 807 39 27 = _O___@__OO# : len=11 : NO 00 NO + 808 39 28 = _O___@O_OO# : len=11 : D4 00 D4 + 809 39 29 = _O___@_OOO# : len=11 : D4 00 D4 + 810 39 30 = _O___@OOOO# : len=11 : L5 00 L5 + 811 39 31 = _O___@_____ : len=11 : NO 00 NO + 812 39 32 = _O___@O____ : len=11 : NO 00 NO + 813 39 33 = _O___@_O___ : len=11 : NO 00 NO + 814 39 34 = _O___@OO___ : len=11 : H3 13 H3 + 815 39 35 = _O___@__O__ : len=11 : NO 00 NO + 816 39 36 = _O___@O_O__ : len=11 : D3 02 D3 + 817 39 37 = _O___@_OO__ : len=11 : D3 01 D3 + 818 39 38 = _O___@OOO__ : len=11 : H4 00 H4 + 819 39 39 = _O___@___O_ : len=11 : NO 00 NO + 820 40 0 = _O__O@# : len= 7 : NO 00 NO + 821 40 1 = _O__O@_# : len= 8 : NO 00 NO + 822 40 2 = _O__O@O# : len= 8 : NO 00 NO + 823 40 3 = _O__O@__# : len= 9 : NO 00 NO + 824 40 4 = _O__O@O_# : len= 9 : NO 00 H3 + 825 40 5 = _O__O@_O# : len= 9 : NO 00 NO + 826 40 6 = _O__O@OO# : len= 9 : S4 00 S4 + 827 40 7 = _O__O@___# : len=10 : NO 00 NO + 828 40 8 = _O__O@O__# : len=10 : H3 22 H3 + 829 40 9 = _O__O@_O_# : len=10 : D3 01 D3 + 830 40 10 = _O__O@OO_# : len=10 : H4 00 H4 + 831 40 11 = _O__O@__O# : len=10 : NO 00 NO + 832 40 12 = _O__O@O_O# : len=10 : D4 00 D4 + 833 40 13 = _O__O@_OO# : len=10 : D4 00 D4 + 834 40 14 = _O__O@OOO# : len=10 : L5 00 L5 + 835 40 15 = _O__O@____# : len=11 : NO 00 NO + 836 40 16 = _O__O@O___# : len=11 : H3 22 H3 + 837 40 17 = _O__O@_O__# : len=11 : D3 01 D3 + 838 40 18 = _O__O@OO__# : len=11 : H4 00 H4 + 839 40 19 = _O__O@__O_# : len=11 : NO 00 NO + 840 40 20 = _O__O@O_O_# : len=11 : D4 00 D4 + 841 40 21 = _O__O@_OO_# : len=11 : D4 00 D4 + 842 40 22 = _O__O@OOO_# : len=11 : L5 00 L5 + 843 40 23 = _O__O@___O# : len=11 : NO 00 NO + 844 40 24 = _O__O@O__O# : len=11 : NO 00 H3 + 845 40 25 = _O__O@_O_O# : len=11 : NO 00 D3 + 846 40 26 = _O__O@OO_O# : len=11 : S4 00 H4 + 847 40 27 = _O__O@__OO# : len=11 : NO 00 NO + 848 40 28 = _O__O@O_OO# : len=11 : NO 00 D4 + 849 40 29 = _O__O@_OOO# : len=11 : NO 00 D4 + 850 40 30 = _O__O@OOOO# : len=11 : L6 00 L6 + 851 40 31 = _O__O@_____ : len=11 : NO 00 NO + 852 40 32 = _O__O@O____ : len=11 : H3 22 H3 + 853 40 33 = _O__O@_O___ : len=11 : D3 01 D3 + 854 40 34 = _O__O@OO___ : len=11 : H4 00 H4 + 855 40 35 = _O__O@__O__ : len=11 : NO 00 NO + 856 40 36 = _O__O@O_O__ : len=11 : D4 00 D4 + 857 40 37 = _O__O@_OO__ : len=11 : D4 00 D4 + 858 40 38 = _O__O@OOO__ : len=11 : L5 00 L5 + 859 40 39 = _O__O@___O_ : len=11 : NO 00 NO + 860 40 40 = _O__O@O__O_ : len=11 : NO 00 H3 + 861 41 0 = _O_O_@# : len= 7 : NO 00 NO + 862 41 1 = _O_O_@_# : len= 8 : NO 00 NO + 863 41 2 = _O_O_@O# : len= 8 : NO 00 NO + 864 41 3 = _O_O_@__# : len= 9 : NO 00 NO + 865 41 4 = _O_O_@O_# : len= 9 : NO 00 D3 + 866 41 5 = _O_O_@_O# : len= 9 : NO 00 NO + 867 41 6 = _O_O_@OO# : len= 9 : D4 00 D4 + 868 41 7 = _O_O_@___# : len=10 : NO 00 NO + 869 41 8 = _O_O_@O__# : len=10 : NO 00 D3 + 870 41 9 = _O_O_@_O_# : len=10 : NO 00 NO + 871 41 10 = _O_O_@OO_# : len=10 : D4 00 D4 + 872 41 11 = _O_O_@__O# : len=10 : NO 00 NO + 873 41 12 = _O_O_@O_O# : len=10 : NO 00 D3 + 874 41 13 = _O_O_@_OO# : len=10 : NO 00 NO + 875 41 14 = _O_O_@OOO# : len=10 : NO 00 D4 + 876 41 15 = _O_O_@____# : len=11 : NO 00 NO + 877 41 16 = _O_O_@O___# : len=11 : NO 00 D3 + 878 41 17 = _O_O_@_O__# : len=11 : NO 00 NO + 879 41 18 = _O_O_@OO__# : len=11 : D4 00 D4 + 880 41 19 = _O_O_@__O_# : len=11 : NO 00 NO + 881 41 20 = _O_O_@O_O_# : len=11 : NO 00 D3 + 882 41 21 = _O_O_@_OO_# : len=11 : NO 00 D3 + 883 41 22 = _O_O_@OOO_# : len=11 : S4 00 H4 + 884 41 23 = _O_O_@___O# : len=11 : NO 00 NO + 885 41 24 = _O_O_@O__O# : len=11 : NO 00 D3 + 886 41 25 = _O_O_@_O_O# : len=11 : NO 00 NO + 887 41 26 = _O_O_@OO_O# : len=11 : X4 00 X4 + 888 41 27 = _O_O_@__OO# : len=11 : NO 00 NO + 889 41 28 = _O_O_@O_OO# : len=11 : D4 00 D4 + 890 41 29 = _O_O_@_OOO# : len=11 : D4 00 D4 + 891 41 30 = _O_O_@OOOO# : len=11 : L5 00 L5 + 892 41 31 = _O_O_@_____ : len=11 : NO 00 NO + 893 41 32 = _O_O_@O____ : len=11 : NO 00 D3 + 894 41 33 = _O_O_@_O___ : len=11 : NO 00 NO + 895 41 34 = _O_O_@OO___ : len=11 : D4 00 D4 + 896 41 35 = _O_O_@__O__ : len=11 : NO 00 NO + 897 41 36 = _O_O_@O_O__ : len=11 : NO 00 D3 + 898 41 37 = _O_O_@_OO__ : len=11 : NO 00 D3 + 899 41 38 = _O_O_@OOO__ : len=11 : S4 00 H4 + 900 41 39 = _O_O_@___O_ : len=11 : NO 00 NO + 901 41 40 = _O_O_@O__O_ : len=11 : NO 00 D3 + 902 41 41 = _O_O_@_O_O_ : len=11 : NO 00 NO + 903 42 0 = _O_OO@# : len= 7 : D4 00 D4 + 904 42 1 = _O_OO@_# : len= 8 : D4 00 D4 + 905 42 2 = _O_OO@O# : len= 8 : NO 00 D4 + 906 42 3 = _O_OO@__# : len= 9 : D4 00 D4 + 907 42 4 = _O_OO@O_# : len= 9 : S4 00 H4 + 908 42 5 = _O_OO@_O# : len= 9 : X4 00 X4 + 909 42 6 = _O_OO@OO# : len= 9 : L5 00 L5 + 910 42 7 = _O_OO@___# : len=10 : D4 00 D4 + 911 42 8 = _O_OO@O__# : len=10 : S4 00 H4 + 912 42 9 = _O_OO@_O_# : len=10 : X4 00 X4 + 913 42 10 = _O_OO@OO_# : len=10 : L5 00 L5 + 914 42 11 = _O_OO@__O# : len=10 : D4 00 D4 + 915 42 12 = _O_OO@O_O# : len=10 : NO 00 H4 + 916 42 13 = _O_OO@_OO# : len=10 : D4 00 X4 + 917 42 14 = _O_OO@OOO# : len=10 : L6 00 L6 + 918 42 15 = _O_OO@____# : len=11 : D4 00 D4 + 919 42 16 = _O_OO@O___# : len=11 : S4 00 H4 + 920 42 17 = _O_OO@_O__# : len=11 : X4 00 X4 + 921 42 18 = _O_OO@OO__# : len=11 : L5 00 L5 + 922 42 19 = _O_OO@__O_# : len=11 : D4 00 D4 + 923 42 20 = _O_OO@O_O_# : len=11 : NO 00 H4 + 924 42 21 = _O_OO@_OO_# : len=11 : D4 00 X4 + 925 42 22 = _O_OO@OOO_# : len=11 : L6 00 L6 + 926 42 23 = _O_OO@___O# : len=11 : D4 00 D4 + 927 42 24 = _O_OO@O__O# : len=11 : S4 00 H4 + 928 42 25 = _O_OO@_O_O# : len=11 : X4 00 X4 + 929 42 26 = _O_OO@OO_O# : len=11 : L5 00 L5 + 930 42 27 = _O_OO@__OO# : len=11 : D4 00 D4 + 931 42 28 = _O_OO@O_OO# : len=11 : NO 00 H4 + 932 42 29 = _O_OO@_OOO# : len=11 : D4 00 X4 + 933 42 30 = _O_OO@OOOO# : len=11 : L6 00 L6 + 934 42 31 = _O_OO@_____ : len=11 : D4 00 D4 + 935 42 32 = _O_OO@O____ : len=11 : S4 00 H4 + 936 42 33 = _O_OO@_O___ : len=11 : X4 00 X4 + 937 42 34 = _O_OO@OO___ : len=11 : L5 00 L5 + 938 42 35 = _O_OO@__O__ : len=11 : D4 00 D4 + 939 42 36 = _O_OO@O_O__ : len=11 : NO 00 H4 + 940 42 37 = _O_OO@_OO__ : len=11 : D4 00 X4 + 941 42 38 = _O_OO@OOO__ : len=11 : L6 00 L6 + 942 42 39 = _O_OO@___O_ : len=11 : D4 00 D4 + 943 42 40 = _O_OO@O__O_ : len=11 : S4 00 H4 + 944 42 41 = _O_OO@_O_O_ : len=11 : X4 00 X4 + 945 42 42 = _O_OO@OO_O_ : len=11 : L5 00 L5 + 946 43 0 = _OO__@# : len= 7 : NO 00 NO + 947 43 1 = _OO__@_# : len= 8 : NO 00 NO + 948 43 2 = _OO__@O# : len= 8 : NO 00 NO + 949 43 3 = _OO__@__# : len= 9 : NO 00 NO + 950 43 4 = _OO__@O_# : len= 9 : NO 00 NO + 951 43 5 = _OO__@_O# : len= 9 : NO 00 NO + 952 43 6 = _OO__@OO# : len= 9 : NO 00 NO + 953 43 7 = _OO__@___# : len=10 : NO 00 NO + 954 43 8 = _OO__@O__# : len=10 : NO 00 NO + 955 43 9 = _OO__@_O_# : len=10 : NO 00 NO + 956 43 10 = _OO__@OO_# : len=10 : NO 00 H3 + 957 43 11 = _OO__@__O# : len=10 : NO 00 NO + 958 43 12 = _OO__@O_O# : len=10 : NO 00 NO + 959 43 13 = _OO__@_OO# : len=10 : NO 00 NO + 960 43 14 = _OO__@OOO# : len=10 : S4 00 S4 + 961 43 15 = _OO__@____# : len=11 : NO 00 NO + 962 43 16 = _OO__@O___# : len=11 : NO 00 NO + 963 43 17 = _OO__@_O__# : len=11 : NO 00 NO + 964 43 18 = _OO__@OO__# : len=11 : H3 13 H3 + 965 43 19 = _OO__@__O_# : len=11 : NO 00 NO + 966 43 20 = _OO__@O_O_# : len=11 : D3 02 D3 + 967 43 21 = _OO__@_OO_# : len=11 : D3 01 D3 + 968 43 22 = _OO__@OOO_# : len=11 : H4 00 H4 + 969 43 23 = _OO__@___O# : len=11 : NO 00 NO + 970 43 24 = _OO__@O__O# : len=11 : NO 00 NO + 971 43 25 = _OO__@_O_O# : len=11 : NO 00 NO + 972 43 26 = _OO__@OO_O# : len=11 : D4 00 D4 + 973 43 27 = _OO__@__OO# : len=11 : NO 00 NO + 974 43 28 = _OO__@O_OO# : len=11 : D4 00 D4 + 975 43 29 = _OO__@_OOO# : len=11 : D4 00 D4 + 976 43 30 = _OO__@OOOO# : len=11 : L5 00 L5 + 977 43 31 = _OO__@_____ : len=11 : NO 00 NO + 978 43 32 = _OO__@O____ : len=11 : NO 00 NO + 979 43 33 = _OO__@_O___ : len=11 : NO 00 NO + 980 43 34 = _OO__@OO___ : len=11 : H3 13 H3 + 981 43 35 = _OO__@__O__ : len=11 : NO 00 NO + 982 43 36 = _OO__@O_O__ : len=11 : D3 02 D3 + 983 43 37 = _OO__@_OO__ : len=11 : D3 01 D3 + 984 43 38 = _OO__@OOO__ : len=11 : H4 00 H4 + 985 43 39 = _OO__@___O_ : len=11 : NO 00 NO + 986 43 40 = _OO__@O__O_ : len=11 : NO 00 NO + 987 43 41 = _OO__@_O_O_ : len=11 : NO 00 NO + 988 43 42 = _OO__@OO_O_ : len=11 : D4 00 D4 + 989 43 43 = _OO__@__OO_ : len=11 : NO 00 NO + 990 44 0 = _OO_O@# : len= 7 : D4 00 D4 + 991 44 1 = _OO_O@_# : len= 8 : D4 00 D4 + 992 44 2 = _OO_O@O# : len= 8 : NO 00 D4 + 993 44 3 = _OO_O@__# : len= 9 : D4 00 D4 + 994 44 4 = _OO_O@O_# : len= 9 : NO 00 D4 + 995 44 5 = _OO_O@_O# : len= 9 : D4 00 D4 + 996 44 6 = _OO_O@OO# : len= 9 : NO 00 D4 + 997 44 7 = _OO_O@___# : len=10 : D4 00 D4 + 998 44 8 = _OO_O@O__# : len=10 : NO 00 D4 + 999 44 9 = _OO_O@_O_# : len=10 : D4 00 D4 + 1000 44 10 = _OO_O@OO_# : len=10 : S4 00 H4 + 1001 44 11 = _OO_O@__O# : len=10 : D4 00 D4 + 1002 44 12 = _OO_O@O_O# : len=10 : D4 00 X4 + 1003 44 13 = _OO_O@_OO# : len=10 : X4 00 X4 + 1004 44 14 = _OO_O@OOO# : len=10 : L5 00 L5 + 1005 44 15 = _OO_O@____# : len=11 : D4 00 D4 + 1006 44 16 = _OO_O@O___# : len=11 : NO 00 D4 + 1007 44 17 = _OO_O@_O__# : len=11 : D4 00 D4 + 1008 44 18 = _OO_O@OO__# : len=11 : S4 00 H4 + 1009 44 19 = _OO_O@__O_# : len=11 : D4 00 D4 + 1010 44 20 = _OO_O@O_O_# : len=11 : D4 00 X4 + 1011 44 21 = _OO_O@_OO_# : len=11 : X4 00 X4 + 1012 44 22 = _OO_O@OOO_# : len=11 : L5 00 L5 + 1013 44 23 = _OO_O@___O# : len=11 : D4 00 D4 + 1014 44 24 = _OO_O@O__O# : len=11 : NO 00 D4 + 1015 44 25 = _OO_O@_O_O# : len=11 : D4 00 D4 + 1016 44 26 = _OO_O@OO_O# : len=11 : NO 00 H4 + 1017 44 27 = _OO_O@__OO# : len=11 : D4 00 D4 + 1018 44 28 = _OO_O@O_OO# : len=11 : NO 00 X4 + 1019 44 29 = _OO_O@_OOO# : len=11 : D4 00 X4 + 1020 44 30 = _OO_O@OOOO# : len=11 : L6 00 L6 + 1021 44 31 = _OO_O@_____ : len=11 : D4 00 D4 + 1022 44 32 = _OO_O@O____ : len=11 : NO 00 D4 + 1023 44 33 = _OO_O@_O___ : len=11 : D4 00 D4 + 1024 44 34 = _OO_O@OO___ : len=11 : S4 00 H4 + 1025 44 35 = _OO_O@__O__ : len=11 : D4 00 D4 + 1026 44 36 = _OO_O@O_O__ : len=11 : D4 00 X4 + 1027 44 37 = _OO_O@_OO__ : len=11 : X4 00 X4 + 1028 44 38 = _OO_O@OOO__ : len=11 : L5 00 L5 + 1029 44 39 = _OO_O@___O_ : len=11 : D4 00 D4 + 1030 44 40 = _OO_O@O__O_ : len=11 : NO 00 D4 + 1031 44 41 = _OO_O@_O_O_ : len=11 : D4 00 D4 + 1032 44 42 = _OO_O@OO_O_ : len=11 : NO 00 H4 + 1033 44 43 = _OO_O@__OO_ : len=11 : D4 00 D4 + 1034 44 44 = _OO_O@O_OO_ : len=11 : NO 00 X4 + 1035 45 0 = _OOO_@# : len= 7 : D4 00 D4 + 1036 45 1 = _OOO_@_# : len= 8 : D4 00 D4 + 1037 45 2 = _OOO_@O# : len= 8 : NO 00 D4 + 1038 45 3 = _OOO_@__# : len= 9 : D4 00 D4 + 1039 45 4 = _OOO_@O_# : len= 9 : NO 00 D4 + 1040 45 5 = _OOO_@_O# : len= 9 : D4 00 D4 + 1041 45 6 = _OOO_@OO# : len= 9 : NO 00 D4 + 1042 45 7 = _OOO_@___# : len=10 : D4 00 D4 + 1043 45 8 = _OOO_@O__# : len=10 : NO 00 D4 + 1044 45 9 = _OOO_@_O_# : len=10 : D4 00 D4 + 1045 45 10 = _OOO_@OO_# : len=10 : NO 00 D4 + 1046 45 11 = _OOO_@__O# : len=10 : D4 00 D4 + 1047 45 12 = _OOO_@O_O# : len=10 : NO 00 D4 + 1048 45 13 = _OOO_@_OO# : len=10 : D4 00 D4 + 1049 45 14 = _OOO_@OOO# : len=10 : NO 00 D4 + 1050 45 15 = _OOO_@____# : len=11 : D4 00 D4 + 1051 45 16 = _OOO_@O___# : len=11 : NO 00 D4 + 1052 45 17 = _OOO_@_O__# : len=11 : D4 00 D4 + 1053 45 18 = _OOO_@OO__# : len=11 : NO 00 D4 + 1054 45 19 = _OOO_@__O_# : len=11 : D4 00 D4 + 1055 45 20 = _OOO_@O_O_# : len=11 : NO 00 D4 + 1056 45 21 = _OOO_@_OO_# : len=11 : D4 00 D4 + 1057 45 22 = _OOO_@OOO_# : len=11 : S4 00 H4 + 1058 45 23 = _OOO_@___O# : len=11 : D4 00 D4 + 1059 45 24 = _OOO_@O__O# : len=11 : NO 00 D4 + 1060 45 25 = _OOO_@_O_O# : len=11 : D4 00 D4 + 1061 45 26 = _OOO_@OO_O# : len=11 : D4 00 X4 + 1062 45 27 = _OOO_@__OO# : len=11 : D4 00 D4 + 1063 45 28 = _OOO_@O_OO# : len=11 : D4 00 X4 + 1064 45 29 = _OOO_@_OOO# : len=11 : X4 00 X4 + 1065 45 30 = _OOO_@OOOO# : len=11 : L5 00 L5 + 1066 45 31 = _OOO_@_____ : len=11 : D4 00 D4 + 1067 45 32 = _OOO_@O____ : len=11 : NO 00 D4 + 1068 45 33 = _OOO_@_O___ : len=11 : D4 00 D4 + 1069 45 34 = _OOO_@OO___ : len=11 : NO 00 D4 + 1070 45 35 = _OOO_@__O__ : len=11 : D4 00 D4 + 1071 45 36 = _OOO_@O_O__ : len=11 : NO 00 D4 + 1072 45 37 = _OOO_@_OO__ : len=11 : D4 00 D4 + 1073 45 38 = _OOO_@OOO__ : len=11 : S4 00 H4 + 1074 45 39 = _OOO_@___O_ : len=11 : D4 00 D4 + 1075 45 40 = _OOO_@O__O_ : len=11 : NO 00 D4 + 1076 45 41 = _OOO_@_O_O_ : len=11 : D4 00 D4 + 1077 45 42 = _OOO_@OO_O_ : len=11 : D4 00 X4 + 1078 45 43 = _OOO_@__OO_ : len=11 : D4 00 D4 + 1079 45 44 = _OOO_@O_OO_ : len=11 : D4 00 X4 + 1080 45 45 = _OOO_@_OOO_ : len=11 : X4 00 X4 + 1081 46 0 = _OOOO@# : len= 7 : L5 00 L5 + 1082 46 1 = _OOOO@_# : len= 8 : L5 00 L5 + 1083 46 2 = _OOOO@O# : len= 8 : L6 00 L6 + 1084 46 3 = _OOOO@__# : len= 9 : L5 00 L5 + 1085 46 4 = _OOOO@O_# : len= 9 : L6 00 L6 + 1086 46 5 = _OOOO@_O# : len= 9 : L5 00 L5 + 1087 46 6 = _OOOO@OO# : len= 9 : L6 00 L6 + 1088 46 7 = _OOOO@___# : len=10 : L5 00 L5 + 1089 46 8 = _OOOO@O__# : len=10 : L6 00 L6 + 1090 46 9 = _OOOO@_O_# : len=10 : L5 00 L5 + 1091 46 10 = _OOOO@OO_# : len=10 : L6 00 L6 + 1092 46 11 = _OOOO@__O# : len=10 : L5 00 L5 + 1093 46 12 = _OOOO@O_O# : len=10 : L6 00 L6 + 1094 46 13 = _OOOO@_OO# : len=10 : L5 00 L5 + 1095 46 14 = _OOOO@OOO# : len=10 : L6 00 L6 + 1096 46 15 = _OOOO@____# : len=11 : L5 00 L5 + 1097 46 16 = _OOOO@O___# : len=11 : L6 00 L6 + 1098 46 17 = _OOOO@_O__# : len=11 : L5 00 L5 + 1099 46 18 = _OOOO@OO__# : len=11 : L6 00 L6 + 1100 46 19 = _OOOO@__O_# : len=11 : L5 00 L5 + 1101 46 20 = _OOOO@O_O_# : len=11 : L6 00 L6 + 1102 46 21 = _OOOO@_OO_# : len=11 : L5 00 L5 + 1103 46 22 = _OOOO@OOO_# : len=11 : L6 00 L6 + 1104 46 23 = _OOOO@___O# : len=11 : L5 00 L5 + 1105 46 24 = _OOOO@O__O# : len=11 : L6 00 L6 + 1106 46 25 = _OOOO@_O_O# : len=11 : L5 00 L5 + 1107 46 26 = _OOOO@OO_O# : len=11 : L6 00 L6 + 1108 46 27 = _OOOO@__OO# : len=11 : L5 00 L5 + 1109 46 28 = _OOOO@O_OO# : len=11 : L6 00 L6 + 1110 46 29 = _OOOO@_OOO# : len=11 : L5 00 L5 + 1111 46 30 = _OOOO@OOOO# : len=11 : L6 00 L6 + 1112 46 31 = _OOOO@_____ : len=11 : L5 00 L5 + 1113 46 32 = _OOOO@O____ : len=11 : L6 00 L6 + 1114 46 33 = _OOOO@_O___ : len=11 : L5 00 L5 + 1115 46 34 = _OOOO@OO___ : len=11 : L6 00 L6 + 1116 46 35 = _OOOO@__O__ : len=11 : L5 00 L5 + 1117 46 36 = _OOOO@O_O__ : len=11 : L6 00 L6 + 1118 46 37 = _OOOO@_OO__ : len=11 : L5 00 L5 + 1119 46 38 = _OOOO@OOO__ : len=11 : L6 00 L6 + 1120 46 39 = _OOOO@___O_ : len=11 : L5 00 L5 + 1121 46 40 = _OOOO@O__O_ : len=11 : L6 00 L6 + 1122 46 41 = _OOOO@_O_O_ : len=11 : L5 00 L5 + 1123 46 42 = _OOOO@OO_O_ : len=11 : L6 00 L6 + 1124 46 43 = _OOOO@__OO_ : len=11 : L5 00 L5 + 1125 46 44 = _OOOO@O_OO_ : len=11 : L6 00 L6 + 1126 46 45 = _OOOO@_OOO_ : len=11 : L5 00 L5 + 1127 46 46 = _OOOO@OOOO_ : len=11 : L6 00 L6 + 1128 47 0 = O____@# : len= 7 : NO 00 NO + 1129 47 1 = O____@_# : len= 8 : NO 00 NO + 1130 47 2 = O____@O# : len= 8 : NO 00 NO + 1131 47 3 = O____@__# : len= 9 : NO 00 NO + 1132 47 4 = O____@O_# : len= 9 : NO 00 NO + 1133 47 5 = O____@_O# : len= 9 : NO 00 NO + 1134 47 6 = O____@OO# : len= 9 : NO 00 NO + 1135 47 7 = O____@___# : len=10 : NO 00 NO + 1136 47 8 = O____@O__# : len=10 : NO 00 NO + 1137 47 9 = O____@_O_# : len=10 : NO 00 NO + 1138 47 10 = O____@OO_# : len=10 : H3 13 H3 + 1139 47 11 = O____@__O# : len=10 : NO 00 NO + 1140 47 12 = O____@O_O# : len=10 : NO 00 NO + 1141 47 13 = O____@_OO# : len=10 : NO 00 NO + 1142 47 14 = O____@OOO# : len=10 : S4 00 S4 + 1143 47 15 = O____@____# : len=11 : NO 00 NO + 1144 47 16 = O____@O___# : len=11 : NO 00 NO + 1145 47 17 = O____@_O__# : len=11 : NO 00 NO + 1146 47 18 = O____@OO__# : len=11 : H3 13 H3 + 1147 47 19 = O____@__O_# : len=11 : NO 00 NO + 1148 47 20 = O____@O_O_# : len=11 : D3 02 D3 + 1149 47 21 = O____@_OO_# : len=11 : D3 01 D3 + 1150 47 22 = O____@OOO_# : len=11 : H4 00 H4 + 1151 47 23 = O____@___O# : len=11 : NO 00 NO + 1152 47 24 = O____@O__O# : len=11 : NO 00 NO + 1153 47 25 = O____@_O_O# : len=11 : NO 00 NO + 1154 47 26 = O____@OO_O# : len=11 : D4 00 D4 + 1155 47 27 = O____@__OO# : len=11 : NO 00 NO + 1156 47 28 = O____@O_OO# : len=11 : D4 00 D4 + 1157 47 29 = O____@_OOO# : len=11 : D4 00 D4 + 1158 47 30 = O____@OOOO# : len=11 : L5 00 L5 + 1159 47 31 = O____@_____ : len=11 : NO 00 NO + 1160 47 32 = O____@O____ : len=11 : NO 00 NO + 1161 47 33 = O____@_O___ : len=11 : NO 00 NO + 1162 47 34 = O____@OO___ : len=11 : H3 13 H3 + 1163 47 35 = O____@__O__ : len=11 : NO 00 NO + 1164 47 36 = O____@O_O__ : len=11 : D3 02 D3 + 1165 47 37 = O____@_OO__ : len=11 : D3 01 D3 + 1166 47 38 = O____@OOO__ : len=11 : H4 00 H4 + 1167 47 39 = O____@___O_ : len=11 : NO 00 NO + 1168 47 40 = O____@O__O_ : len=11 : NO 00 NO + 1169 47 41 = O____@_O_O_ : len=11 : NO 00 NO + 1170 47 42 = O____@OO_O_ : len=11 : D4 00 D4 + 1171 47 43 = O____@__OO_ : len=11 : NO 00 NO + 1172 47 44 = O____@O_OO_ : len=11 : D4 00 D4 + 1173 47 45 = O____@_OOO_ : len=11 : D4 00 D4 + 1174 47 46 = O____@OOOO_ : len=11 : L5 00 L5 + 1175 47 47 = O____@____O : len=11 : NO 00 NO + 1176 48 0 = O___O@# : len= 7 : NO 00 NO + 1177 48 1 = O___O@_# : len= 8 : NO 00 NO + 1178 48 2 = O___O@O# : len= 8 : NO 00 NO + 1179 48 3 = O___O@__# : len= 9 : NO 00 NO + 1180 48 4 = O___O@O_# : len= 9 : H3 22 H3 + 1181 48 5 = O___O@_O# : len= 9 : NO 00 NO + 1182 48 6 = O___O@OO# : len= 9 : S4 00 S4 + 1183 48 7 = O___O@___# : len=10 : NO 00 NO + 1184 48 8 = O___O@O__# : len=10 : H3 22 H3 + 1185 48 9 = O___O@_O_# : len=10 : D3 01 D3 + 1186 48 10 = O___O@OO_# : len=10 : H4 00 H4 + 1187 48 11 = O___O@__O# : len=10 : NO 00 NO + 1188 48 12 = O___O@O_O# : len=10 : D4 00 D4 + 1189 48 13 = O___O@_OO# : len=10 : D4 00 D4 + 1190 48 14 = O___O@OOO# : len=10 : L5 00 L5 + 1191 48 15 = O___O@____# : len=11 : NO 00 NO + 1192 48 16 = O___O@O___# : len=11 : H3 22 H3 + 1193 48 17 = O___O@_O__# : len=11 : D3 01 D3 + 1194 48 18 = O___O@OO__# : len=11 : H4 00 H4 + 1195 48 19 = O___O@__O_# : len=11 : NO 00 NO + 1196 48 20 = O___O@O_O_# : len=11 : D4 00 D4 + 1197 48 21 = O___O@_OO_# : len=11 : D4 00 D4 + 1198 48 22 = O___O@OOO_# : len=11 : L5 00 L5 + 1199 48 23 = O___O@___O# : len=11 : NO 00 NO + 1200 48 24 = O___O@O__O# : len=11 : H3 22 H3 + 1201 48 25 = O___O@_O_O# : len=11 : NO 00 D3 + 1202 48 26 = O___O@OO_O# : len=11 : S4 00 H4 + 1203 48 27 = O___O@__OO# : len=11 : NO 00 NO + 1204 48 28 = O___O@O_OO# : len=11 : NO 00 D4 + 1205 48 29 = O___O@_OOO# : len=11 : NO 00 D4 + 1206 48 30 = O___O@OOOO# : len=11 : L6 00 L6 + 1207 48 31 = O___O@_____ : len=11 : NO 00 NO + 1208 48 32 = O___O@O____ : len=11 : H3 22 H3 + 1209 48 33 = O___O@_O___ : len=11 : D3 01 D3 + 1210 48 34 = O___O@OO___ : len=11 : H4 00 H4 + 1211 48 35 = O___O@__O__ : len=11 : NO 00 NO + 1212 48 36 = O___O@O_O__ : len=11 : D4 00 D4 + 1213 48 37 = O___O@_OO__ : len=11 : D4 00 D4 + 1214 48 38 = O___O@OOO__ : len=11 : L5 00 L5 + 1215 48 39 = O___O@___O_ : len=11 : NO 00 NO + 1216 48 40 = O___O@O__O_ : len=11 : H3 22 H3 + 1217 48 41 = O___O@_O_O_ : len=11 : NO 00 D3 + 1218 48 42 = O___O@OO_O_ : len=11 : S4 00 H4 + 1219 48 43 = O___O@__OO_ : len=11 : NO 00 NO + 1220 48 44 = O___O@O_OO_ : len=11 : NO 00 D4 + 1221 48 45 = O___O@_OOO_ : len=11 : NO 00 D4 + 1222 48 46 = O___O@OOOO_ : len=11 : L6 00 L6 + 1223 48 47 = O___O@____O : len=11 : NO 00 NO + 1224 48 48 = O___O@O___O : len=11 : H3 22 H3 + 1225 49 0 = O__O_@# : len= 7 : NO 00 NO + 1226 49 1 = O__O_@_# : len= 8 : NO 00 NO + 1227 49 2 = O__O_@O# : len= 8 : NO 00 NO + 1228 49 3 = O__O_@__# : len= 9 : NO 00 NO + 1229 49 4 = O__O_@O_# : len= 9 : D3 10 D3 + 1230 49 5 = O__O_@_O# : len= 9 : NO 00 NO + 1231 49 6 = O__O_@OO# : len= 9 : D4 00 D4 + 1232 49 7 = O__O_@___# : len=10 : NO 00 NO + 1233 49 8 = O__O_@O__# : len=10 : D3 10 D3 + 1234 49 9 = O__O_@_O_# : len=10 : NO 00 NO + 1235 49 10 = O__O_@OO_# : len=10 : D4 00 D4 + 1236 49 11 = O__O_@__O# : len=10 : NO 00 NO + 1237 49 12 = O__O_@O_O# : len=10 : NO 00 D3 + 1238 49 13 = O__O_@_OO# : len=10 : NO 00 NO + 1239 49 14 = O__O_@OOO# : len=10 : NO 00 D4 + 1240 49 15 = O__O_@____# : len=11 : NO 00 NO + 1241 49 16 = O__O_@O___# : len=11 : D3 10 D3 + 1242 49 17 = O__O_@_O__# : len=11 : NO 00 NO + 1243 49 18 = O__O_@OO__# : len=11 : D4 00 D4 + 1244 49 19 = O__O_@__O_# : len=11 : NO 00 NO + 1245 49 20 = O__O_@O_O_# : len=11 : NO 00 D3 + 1246 49 21 = O__O_@_OO_# : len=11 : NO 00 D3 + 1247 49 22 = O__O_@OOO_# : len=11 : S4 00 H4 + 1248 49 23 = O__O_@___O# : len=11 : NO 00 NO + 1249 49 24 = O__O_@O__O# : len=11 : D3 10 D3 + 1250 49 25 = O__O_@_O_O# : len=11 : NO 00 NO + 1251 49 26 = O__O_@OO_O# : len=11 : X4 00 X4 + 1252 49 27 = O__O_@__OO# : len=11 : NO 00 NO + 1253 49 28 = O__O_@O_OO# : len=11 : D4 00 D4 + 1254 49 29 = O__O_@_OOO# : len=11 : D4 00 D4 + 1255 49 30 = O__O_@OOOO# : len=11 : L5 00 L5 + 1256 49 31 = O__O_@_____ : len=11 : NO 00 NO + 1257 49 32 = O__O_@O____ : len=11 : D3 10 D3 + 1258 49 33 = O__O_@_O___ : len=11 : NO 00 NO + 1259 49 34 = O__O_@OO___ : len=11 : D4 00 D4 + 1260 49 35 = O__O_@__O__ : len=11 : NO 00 NO + 1261 49 36 = O__O_@O_O__ : len=11 : NO 00 D3 + 1262 49 37 = O__O_@_OO__ : len=11 : NO 00 D3 + 1263 49 38 = O__O_@OOO__ : len=11 : S4 00 H4 + 1264 49 39 = O__O_@___O_ : len=11 : NO 00 NO + 1265 49 40 = O__O_@O__O_ : len=11 : D3 10 D3 + 1266 49 41 = O__O_@_O_O_ : len=11 : NO 00 NO + 1267 49 42 = O__O_@OO_O_ : len=11 : X4 00 X4 + 1268 49 43 = O__O_@__OO_ : len=11 : NO 00 NO + 1269 49 44 = O__O_@O_OO_ : len=11 : D4 00 D4 + 1270 49 45 = O__O_@_OOO_ : len=11 : D4 00 D4 + 1271 49 46 = O__O_@OOOO_ : len=11 : L5 00 L5 + 1272 49 47 = O__O_@____O : len=11 : NO 00 NO + 1273 49 48 = O__O_@O___O : len=11 : D3 10 D3 + 1274 49 49 = O__O_@_O__O : len=11 : NO 00 NO + 1275 50 0 = O__OO@# : len= 7 : NO 00 NO + 1276 50 1 = O__OO@_# : len= 8 : NO 00 H3 + 1277 50 2 = O__OO@O# : len= 8 : S4 00 S4 + 1278 50 3 = O__OO@__# : len= 9 : H3 31 H3 + 1279 50 4 = O__OO@O_# : len= 9 : H4 00 H4 + 1280 50 5 = O__OO@_O# : len= 9 : D4 00 D4 + 1281 50 6 = O__OO@OO# : len= 9 : L5 00 L5 + 1282 50 7 = O__OO@___# : len=10 : H3 31 H3 + 1283 50 8 = O__OO@O__# : len=10 : H4 00 H4 + 1284 50 9 = O__OO@_O_# : len=10 : D4 00 D4 + 1285 50 10 = O__OO@OO_# : len=10 : L5 00 L5 + 1286 50 11 = O__OO@__O# : len=10 : NO 00 H3 + 1287 50 12 = O__OO@O_O# : len=10 : S4 00 H4 + 1288 50 13 = O__OO@_OO# : len=10 : NO 00 D4 + 1289 50 14 = O__OO@OOO# : len=10 : L6 00 L6 + 1290 50 15 = O__OO@____# : len=11 : H3 31 H3 + 1291 50 16 = O__OO@O___# : len=11 : H4 00 H4 + 1292 50 17 = O__OO@_O__# : len=11 : D4 00 D4 + 1293 50 18 = O__OO@OO__# : len=11 : L5 00 L5 + 1294 50 19 = O__OO@__O_# : len=11 : NO 00 H3 + 1295 50 20 = O__OO@O_O_# : len=11 : S4 00 H4 + 1296 50 21 = O__OO@_OO_# : len=11 : NO 00 D4 + 1297 50 22 = O__OO@OOO_# : len=11 : L6 00 L6 + 1298 50 23 = O__OO@___O# : len=11 : H3 31 H3 + 1299 50 24 = O__OO@O__O# : len=11 : H4 00 H4 + 1300 50 25 = O__OO@_O_O# : len=11 : D4 00 D4 + 1301 50 26 = O__OO@OO_O# : len=11 : L5 00 L5 + 1302 50 27 = O__OO@__OO# : len=11 : NO 00 H3 + 1303 50 28 = O__OO@O_OO# : len=11 : S4 00 H4 + 1304 50 29 = O__OO@_OOO# : len=11 : NO 00 D4 + 1305 50 30 = O__OO@OOOO# : len=11 : L6 00 L6 + 1306 50 31 = O__OO@_____ : len=11 : H3 31 H3 + 1307 50 32 = O__OO@O____ : len=11 : H4 00 H4 + 1308 50 33 = O__OO@_O___ : len=11 : D4 00 D4 + 1309 50 34 = O__OO@OO___ : len=11 : L5 00 L5 + 1310 50 35 = O__OO@__O__ : len=11 : NO 00 H3 + 1311 50 36 = O__OO@O_O__ : len=11 : S4 00 H4 + 1312 50 37 = O__OO@_OO__ : len=11 : NO 00 D4 + 1313 50 38 = O__OO@OOO__ : len=11 : L6 00 L6 + 1314 50 39 = O__OO@___O_ : len=11 : H3 31 H3 + 1315 50 40 = O__OO@O__O_ : len=11 : H4 00 H4 + 1316 50 41 = O__OO@_O_O_ : len=11 : D4 00 D4 + 1317 50 42 = O__OO@OO_O_ : len=11 : L5 00 L5 + 1318 50 43 = O__OO@__OO_ : len=11 : NO 00 H3 + 1319 50 44 = O__OO@O_OO_ : len=11 : S4 00 H4 + 1320 50 45 = O__OO@_OOO_ : len=11 : NO 00 D4 + 1321 50 46 = O__OO@OOOO_ : len=11 : L6 00 L6 + 1322 50 47 = O__OO@____O : len=11 : H3 31 H3 + 1323 50 48 = O__OO@O___O : len=11 : H4 00 H4 + 1324 50 49 = O__OO@_O__O : len=11 : D4 00 D4 + 1325 50 50 = O__OO@OO__O : len=11 : L5 00 L5 + 1326 51 0 = O_O__@# : len= 7 : NO 00 NO + 1327 51 1 = O_O__@_# : len= 8 : NO 00 NO + 1328 51 2 = O_O__@O# : len= 8 : NO 00 NO + 1329 51 3 = O_O__@__# : len= 9 : NO 00 NO + 1330 51 4 = O_O__@O_# : len= 9 : NO 00 NO + 1331 51 5 = O_O__@_O# : len= 9 : NO 00 NO + 1332 51 6 = O_O__@OO# : len= 9 : NO 00 NO + 1333 51 7 = O_O__@___# : len=10 : NO 00 NO + 1334 51 8 = O_O__@O__# : len=10 : NO 00 NO + 1335 51 9 = O_O__@_O_# : len=10 : NO 00 NO + 1336 51 10 = O_O__@OO_# : len=10 : NO 00 H3 + 1337 51 11 = O_O__@__O# : len=10 : NO 00 NO + 1338 51 12 = O_O__@O_O# : len=10 : NO 00 NO + 1339 51 13 = O_O__@_OO# : len=10 : NO 00 NO + 1340 51 14 = O_O__@OOO# : len=10 : S4 00 S4 + 1341 51 15 = O_O__@____# : len=11 : NO 00 NO + 1342 51 16 = O_O__@O___# : len=11 : NO 00 NO + 1343 51 17 = O_O__@_O__# : len=11 : NO 00 NO + 1344 51 18 = O_O__@OO__# : len=11 : H3 13 H3 + 1345 51 19 = O_O__@__O_# : len=11 : NO 00 NO + 1346 51 20 = O_O__@O_O_# : len=11 : D3 02 D3 + 1347 51 21 = O_O__@_OO_# : len=11 : D3 01 D3 + 1348 51 22 = O_O__@OOO_# : len=11 : H4 00 H4 + 1349 51 23 = O_O__@___O# : len=11 : NO 00 NO + 1350 51 24 = O_O__@O__O# : len=11 : NO 00 NO + 1351 51 25 = O_O__@_O_O# : len=11 : NO 00 NO + 1352 51 26 = O_O__@OO_O# : len=11 : D4 00 D4 + 1353 51 27 = O_O__@__OO# : len=11 : NO 00 NO + 1354 51 28 = O_O__@O_OO# : len=11 : D4 00 D4 + 1355 51 29 = O_O__@_OOO# : len=11 : D4 00 D4 + 1356 51 30 = O_O__@OOOO# : len=11 : L5 00 L5 + 1357 51 31 = O_O__@_____ : len=11 : NO 00 NO + 1358 51 32 = O_O__@O____ : len=11 : NO 00 NO + 1359 51 33 = O_O__@_O___ : len=11 : NO 00 NO + 1360 51 34 = O_O__@OO___ : len=11 : H3 13 H3 + 1361 51 35 = O_O__@__O__ : len=11 : NO 00 NO + 1362 51 36 = O_O__@O_O__ : len=11 : D3 02 D3 + 1363 51 37 = O_O__@_OO__ : len=11 : D3 01 D3 + 1364 51 38 = O_O__@OOO__ : len=11 : H4 00 H4 + 1365 51 39 = O_O__@___O_ : len=11 : NO 00 NO + 1366 51 40 = O_O__@O__O_ : len=11 : NO 00 NO + 1367 51 41 = O_O__@_O_O_ : len=11 : NO 00 NO + 1368 51 42 = O_O__@OO_O_ : len=11 : D4 00 D4 + 1369 51 43 = O_O__@__OO_ : len=11 : NO 00 NO + 1370 51 44 = O_O__@O_OO_ : len=11 : D4 00 D4 + 1371 51 45 = O_O__@_OOO_ : len=11 : D4 00 D4 + 1372 51 46 = O_O__@OOOO_ : len=11 : L5 00 L5 + 1373 51 47 = O_O__@____O : len=11 : NO 00 NO + 1374 51 48 = O_O__@O___O : len=11 : NO 00 NO + 1375 51 49 = O_O__@_O__O : len=11 : NO 00 NO + 1376 51 50 = O_O__@OO__O : len=11 : NO 00 H3 + 1377 51 51 = O_O__@__O_O : len=11 : NO 00 NO + 1378 52 0 = O_O_O@# : len= 7 : NO 00 NO + 1379 52 1 = O_O_O@_# : len= 8 : NO 00 D3 + 1380 52 2 = O_O_O@O# : len= 8 : D4 00 D4 + 1381 52 3 = O_O_O@__# : len= 9 : NO 00 D3 + 1382 52 4 = O_O_O@O_# : len= 9 : D4 00 D4 + 1383 52 5 = O_O_O@_O# : len= 9 : NO 00 D3 + 1384 52 6 = O_O_O@OO# : len= 9 : NO 00 D4 + 1385 52 7 = O_O_O@___# : len=10 : NO 00 D3 + 1386 52 8 = O_O_O@O__# : len=10 : D4 00 D4 + 1387 52 9 = O_O_O@_O_# : len=10 : NO 00 D3 + 1388 52 10 = O_O_O@OO_# : len=10 : S4 00 H4 + 1389 52 11 = O_O_O@__O# : len=10 : NO 00 D3 + 1390 52 12 = O_O_O@O_O# : len=10 : X4 00 X4 + 1391 52 13 = O_O_O@_OO# : len=10 : D4 00 D4 + 1392 52 14 = O_O_O@OOO# : len=10 : L5 00 L5 + 1393 52 15 = O_O_O@____# : len=11 : NO 00 D3 + 1394 52 16 = O_O_O@O___# : len=11 : D4 00 D4 + 1395 52 17 = O_O_O@_O__# : len=11 : NO 00 D3 + 1396 52 18 = O_O_O@OO__# : len=11 : S4 00 H4 + 1397 52 19 = O_O_O@__O_# : len=11 : NO 00 D3 + 1398 52 20 = O_O_O@O_O_# : len=11 : X4 00 X4 + 1399 52 21 = O_O_O@_OO_# : len=11 : D4 00 D4 + 1400 52 22 = O_O_O@OOO_# : len=11 : L5 00 L5 + 1401 52 23 = O_O_O@___O# : len=11 : NO 00 D3 + 1402 52 24 = O_O_O@O__O# : len=11 : D4 00 D4 + 1403 52 25 = O_O_O@_O_O# : len=11 : NO 00 D3 + 1404 52 26 = O_O_O@OO_O# : len=11 : NO 00 H4 + 1405 52 27 = O_O_O@__OO# : len=11 : NO 00 D3 + 1406 52 28 = O_O_O@O_OO# : len=11 : D4 00 X4 + 1407 52 29 = O_O_O@_OOO# : len=11 : NO 00 D4 + 1408 52 30 = O_O_O@OOOO# : len=11 : L6 00 L6 + 1409 52 31 = O_O_O@_____ : len=11 : NO 00 D3 + 1410 52 32 = O_O_O@O____ : len=11 : D4 00 D4 + 1411 52 33 = O_O_O@_O___ : len=11 : NO 00 D3 + 1412 52 34 = O_O_O@OO___ : len=11 : S4 00 H4 + 1413 52 35 = O_O_O@__O__ : len=11 : NO 00 D3 + 1414 52 36 = O_O_O@O_O__ : len=11 : X4 00 X4 + 1415 52 37 = O_O_O@_OO__ : len=11 : D4 00 D4 + 1416 52 38 = O_O_O@OOO__ : len=11 : L5 00 L5 + 1417 52 39 = O_O_O@___O_ : len=11 : NO 00 D3 + 1418 52 40 = O_O_O@O__O_ : len=11 : D4 00 D4 + 1419 52 41 = O_O_O@_O_O_ : len=11 : NO 00 D3 + 1420 52 42 = O_O_O@OO_O_ : len=11 : NO 00 H4 + 1421 52 43 = O_O_O@__OO_ : len=11 : NO 00 D3 + 1422 52 44 = O_O_O@O_OO_ : len=11 : D4 00 X4 + 1423 52 45 = O_O_O@_OOO_ : len=11 : NO 00 D4 + 1424 52 46 = O_O_O@OOOO_ : len=11 : L6 00 L6 + 1425 52 47 = O_O_O@____O : len=11 : NO 00 D3 + 1426 52 48 = O_O_O@O___O : len=11 : D4 00 D4 + 1427 52 49 = O_O_O@_O__O : len=11 : NO 00 D3 + 1428 52 50 = O_O_O@OO__O : len=11 : S4 00 H4 + 1429 52 51 = O_O_O@__O_O : len=11 : NO 00 D3 + 1430 52 52 = O_O_O@O_O_O : len=11 : X4 00 X4 + 1431 53 0 = O_OO_@# : len= 7 : NO 00 NO + 1432 53 1 = O_OO_@_# : len= 8 : NO 00 D3 + 1433 53 2 = O_OO_@O# : len= 8 : D4 00 D4 + 1434 53 3 = O_OO_@__# : len= 9 : NO 00 D3 + 1435 53 4 = O_OO_@O_# : len= 9 : D4 00 D4 + 1436 53 5 = O_OO_@_O# : len= 9 : NO 00 D3 + 1437 53 6 = O_OO_@OO# : len= 9 : NO 00 D4 + 1438 53 7 = O_OO_@___# : len=10 : NO 00 D3 + 1439 53 8 = O_OO_@O__# : len=10 : D4 00 D4 + 1440 53 9 = O_OO_@_O_# : len=10 : NO 00 D3 + 1441 53 10 = O_OO_@OO_# : len=10 : NO 00 D4 + 1442 53 11 = O_OO_@__O# : len=10 : NO 00 D3 + 1443 53 12 = O_OO_@O_O# : len=10 : D4 00 D4 + 1444 53 13 = O_OO_@_OO# : len=10 : NO 00 D3 + 1445 53 14 = O_OO_@OOO# : len=10 : NO 00 D4 + 1446 53 15 = O_OO_@____# : len=11 : NO 00 D3 + 1447 53 16 = O_OO_@O___# : len=11 : D4 00 D4 + 1448 53 17 = O_OO_@_O__# : len=11 : NO 00 D3 + 1449 53 18 = O_OO_@OO__# : len=11 : NO 00 D4 + 1450 53 19 = O_OO_@__O_# : len=11 : NO 00 D3 + 1451 53 20 = O_OO_@O_O_# : len=11 : D4 00 D4 + 1452 53 21 = O_OO_@_OO_# : len=11 : NO 00 D3 + 1453 53 22 = O_OO_@OOO_# : len=11 : S4 00 H4 + 1454 53 23 = O_OO_@___O# : len=11 : NO 00 D3 + 1455 53 24 = O_OO_@O__O# : len=11 : D4 00 D4 + 1456 53 25 = O_OO_@_O_O# : len=11 : NO 00 D3 + 1457 53 26 = O_OO_@OO_O# : len=11 : D4 00 X4 + 1458 53 27 = O_OO_@__OO# : len=11 : NO 00 D3 + 1459 53 28 = O_OO_@O_OO# : len=11 : X4 00 X4 + 1460 53 29 = O_OO_@_OOO# : len=11 : D4 00 D4 + 1461 53 30 = O_OO_@OOOO# : len=11 : L5 00 L5 + 1462 53 31 = O_OO_@_____ : len=11 : NO 00 D3 + 1463 53 32 = O_OO_@O____ : len=11 : D4 00 D4 + 1464 53 33 = O_OO_@_O___ : len=11 : NO 00 D3 + 1465 53 34 = O_OO_@OO___ : len=11 : NO 00 D4 + 1466 53 35 = O_OO_@__O__ : len=11 : NO 00 D3 + 1467 53 36 = O_OO_@O_O__ : len=11 : D4 00 D4 + 1468 53 37 = O_OO_@_OO__ : len=11 : NO 00 D3 + 1469 53 38 = O_OO_@OOO__ : len=11 : S4 00 H4 + 1470 53 39 = O_OO_@___O_ : len=11 : NO 00 D3 + 1471 53 40 = O_OO_@O__O_ : len=11 : D4 00 D4 + 1472 53 41 = O_OO_@_O_O_ : len=11 : NO 00 D3 + 1473 53 42 = O_OO_@OO_O_ : len=11 : D4 00 X4 + 1474 53 43 = O_OO_@__OO_ : len=11 : NO 00 D3 + 1475 53 44 = O_OO_@O_OO_ : len=11 : X4 00 X4 + 1476 53 45 = O_OO_@_OOO_ : len=11 : D4 00 D4 + 1477 53 46 = O_OO_@OOOO_ : len=11 : L5 00 L5 + 1478 53 47 = O_OO_@____O : len=11 : NO 00 D3 + 1479 53 48 = O_OO_@O___O : len=11 : D4 00 D4 + 1480 53 49 = O_OO_@_O__O : len=11 : NO 00 D3 + 1481 53 50 = O_OO_@OO__O : len=11 : NO 00 D4 + 1482 53 51 = O_OO_@__O_O : len=11 : NO 00 D3 + 1483 53 52 = O_OO_@O_O_O : len=11 : D4 00 D4 + 1484 53 53 = O_OO_@_OO_O : len=11 : NO 00 D3 + 1485 54 0 = O_OOO@# : len= 7 : NO 00 D4 + 1486 54 1 = O_OOO@_# : len= 8 : S4 00 H4 + 1487 54 2 = O_OOO@O# : len= 8 : L5 00 L5 + 1488 54 3 = O_OOO@__# : len= 9 : S4 00 H4 + 1489 54 4 = O_OOO@O_# : len= 9 : L5 00 L5 + 1490 54 5 = O_OOO@_O# : len= 9 : NO 00 H4 + 1491 54 6 = O_OOO@OO# : len= 9 : L6 00 L6 + 1492 54 7 = O_OOO@___# : len=10 : S4 00 H4 + 1493 54 8 = O_OOO@O__# : len=10 : L5 00 L5 + 1494 54 9 = O_OOO@_O_# : len=10 : NO 00 H4 + 1495 54 10 = O_OOO@OO_# : len=10 : L6 00 L6 + 1496 54 11 = O_OOO@__O# : len=10 : S4 00 H4 + 1497 54 12 = O_OOO@O_O# : len=10 : L5 00 L5 + 1498 54 13 = O_OOO@_OO# : len=10 : NO 00 H4 + 1499 54 14 = O_OOO@OOO# : len=10 : L6 00 L6 + 1500 54 15 = O_OOO@____# : len=11 : S4 00 H4 + 1501 54 16 = O_OOO@O___# : len=11 : L5 00 L5 + 1502 54 17 = O_OOO@_O__# : len=11 : NO 00 H4 + 1503 54 18 = O_OOO@OO__# : len=11 : L6 00 L6 + 1504 54 19 = O_OOO@__O_# : len=11 : S4 00 H4 + 1505 54 20 = O_OOO@O_O_# : len=11 : L5 00 L5 + 1506 54 21 = O_OOO@_OO_# : len=11 : NO 00 H4 + 1507 54 22 = O_OOO@OOO_# : len=11 : L6 00 L6 + 1508 54 23 = O_OOO@___O# : len=11 : S4 00 H4 + 1509 54 24 = O_OOO@O__O# : len=11 : L5 00 L5 + 1510 54 25 = O_OOO@_O_O# : len=11 : NO 00 H4 + 1511 54 26 = O_OOO@OO_O# : len=11 : L6 00 L6 + 1512 54 27 = O_OOO@__OO# : len=11 : S4 00 H4 + 1513 54 28 = O_OOO@O_OO# : len=11 : L5 00 L5 + 1514 54 29 = O_OOO@_OOO# : len=11 : NO 00 H4 + 1515 54 30 = O_OOO@OOOO# : len=11 : L6 00 L6 + 1516 54 31 = O_OOO@_____ : len=11 : S4 00 H4 + 1517 54 32 = O_OOO@O____ : len=11 : L5 00 L5 + 1518 54 33 = O_OOO@_O___ : len=11 : NO 00 H4 + 1519 54 34 = O_OOO@OO___ : len=11 : L6 00 L6 + 1520 54 35 = O_OOO@__O__ : len=11 : S4 00 H4 + 1521 54 36 = O_OOO@O_O__ : len=11 : L5 00 L5 + 1522 54 37 = O_OOO@_OO__ : len=11 : NO 00 H4 + 1523 54 38 = O_OOO@OOO__ : len=11 : L6 00 L6 + 1524 54 39 = O_OOO@___O_ : len=11 : S4 00 H4 + 1525 54 40 = O_OOO@O__O_ : len=11 : L5 00 L5 + 1526 54 41 = O_OOO@_O_O_ : len=11 : NO 00 H4 + 1527 54 42 = O_OOO@OO_O_ : len=11 : L6 00 L6 + 1528 54 43 = O_OOO@__OO_ : len=11 : S4 00 H4 + 1529 54 44 = O_OOO@O_OO_ : len=11 : L5 00 L5 + 1530 54 45 = O_OOO@_OOO_ : len=11 : NO 00 H4 + 1531 54 46 = O_OOO@OOOO_ : len=11 : L6 00 L6 + 1532 54 47 = O_OOO@____O : len=11 : S4 00 H4 + 1533 54 48 = O_OOO@O___O : len=11 : L5 00 L5 + 1534 54 49 = O_OOO@_O__O : len=11 : NO 00 H4 + 1535 54 50 = O_OOO@OO__O : len=11 : L6 00 L6 + 1536 54 51 = O_OOO@__O_O : len=11 : S4 00 H4 + 1537 54 52 = O_OOO@O_O_O : len=11 : L5 00 L5 + 1538 54 53 = O_OOO@_OO_O : len=11 : NO 00 H4 + 1539 54 54 = O_OOO@OOO_O : len=11 : L6 00 L6 + 1540 55 0 = OO___@# : len= 7 : NO 00 NO + 1541 55 1 = OO___@_# : len= 8 : NO 00 NO + 1542 55 2 = OO___@O# : len= 8 : NO 00 NO + 1543 55 3 = OO___@__# : len= 9 : NO 00 NO + 1544 55 4 = OO___@O_# : len= 9 : NO 00 NO + 1545 55 5 = OO___@_O# : len= 9 : NO 00 NO + 1546 55 6 = OO___@OO# : len= 9 : NO 00 NO + 1547 55 7 = OO___@___# : len=10 : NO 00 NO + 1548 55 8 = OO___@O__# : len=10 : NO 00 NO + 1549 55 9 = OO___@_O_# : len=10 : NO 00 NO + 1550 55 10 = OO___@OO_# : len=10 : H3 13 H3 + 1551 55 11 = OO___@__O# : len=10 : NO 00 NO + 1552 55 12 = OO___@O_O# : len=10 : NO 00 NO + 1553 55 13 = OO___@_OO# : len=10 : NO 00 NO + 1554 55 14 = OO___@OOO# : len=10 : S4 00 S4 + 1555 55 15 = OO___@____# : len=11 : NO 00 NO + 1556 55 16 = OO___@O___# : len=11 : NO 00 NO + 1557 55 17 = OO___@_O__# : len=11 : NO 00 NO + 1558 55 18 = OO___@OO__# : len=11 : H3 13 H3 + 1559 55 19 = OO___@__O_# : len=11 : NO 00 NO + 1560 55 20 = OO___@O_O_# : len=11 : D3 02 D3 + 1561 55 21 = OO___@_OO_# : len=11 : D3 01 D3 + 1562 55 22 = OO___@OOO_# : len=11 : H4 00 H4 + 1563 55 23 = OO___@___O# : len=11 : NO 00 NO + 1564 55 24 = OO___@O__O# : len=11 : NO 00 NO + 1565 55 25 = OO___@_O_O# : len=11 : NO 00 NO + 1566 55 26 = OO___@OO_O# : len=11 : D4 00 D4 + 1567 55 27 = OO___@__OO# : len=11 : NO 00 NO + 1568 55 28 = OO___@O_OO# : len=11 : D4 00 D4 + 1569 55 29 = OO___@_OOO# : len=11 : D4 00 D4 + 1570 55 30 = OO___@OOOO# : len=11 : L5 00 L5 + 1571 55 31 = OO___@_____ : len=11 : NO 00 NO + 1572 55 32 = OO___@O____ : len=11 : NO 00 NO + 1573 55 33 = OO___@_O___ : len=11 : NO 00 NO + 1574 55 34 = OO___@OO___ : len=11 : H3 13 H3 + 1575 55 35 = OO___@__O__ : len=11 : NO 00 NO + 1576 55 36 = OO___@O_O__ : len=11 : D3 02 D3 + 1577 55 37 = OO___@_OO__ : len=11 : D3 01 D3 + 1578 55 38 = OO___@OOO__ : len=11 : H4 00 H4 + 1579 55 39 = OO___@___O_ : len=11 : NO 00 NO + 1580 55 40 = OO___@O__O_ : len=11 : NO 00 NO + 1581 55 41 = OO___@_O_O_ : len=11 : NO 00 NO + 1582 55 42 = OO___@OO_O_ : len=11 : D4 00 D4 + 1583 55 43 = OO___@__OO_ : len=11 : NO 00 NO + 1584 55 44 = OO___@O_OO_ : len=11 : D4 00 D4 + 1585 55 45 = OO___@_OOO_ : len=11 : D4 00 D4 + 1586 55 46 = OO___@OOOO_ : len=11 : L5 00 L5 + 1587 55 47 = OO___@____O : len=11 : NO 00 NO + 1588 55 48 = OO___@O___O : len=11 : NO 00 NO + 1589 55 49 = OO___@_O__O : len=11 : NO 00 NO + 1590 55 50 = OO___@OO__O : len=11 : H3 13 H3 + 1591 55 51 = OO___@__O_O : len=11 : NO 00 NO + 1592 55 52 = OO___@O_O_O : len=11 : NO 00 D3 + 1593 55 53 = OO___@_OO_O : len=11 : NO 00 D3 + 1594 55 54 = OO___@OOO_O : len=11 : S4 00 H4 + 1595 55 55 = OO___@___OO : len=11 : NO 00 NO + 1596 56 0 = OO__O@# : len= 7 : NO 00 NO + 1597 56 1 = OO__O@_# : len= 8 : NO 00 NO + 1598 56 2 = OO__O@O# : len= 8 : NO 00 NO + 1599 56 3 = OO__O@__# : len= 9 : NO 00 NO + 1600 56 4 = OO__O@O_# : len= 9 : NO 00 H3 + 1601 56 5 = OO__O@_O# : len= 9 : NO 00 NO + 1602 56 6 = OO__O@OO# : len= 9 : S4 00 S4 + 1603 56 7 = OO__O@___# : len=10 : NO 00 NO + 1604 56 8 = OO__O@O__# : len=10 : H3 22 H3 + 1605 56 9 = OO__O@_O_# : len=10 : D3 01 D3 + 1606 56 10 = OO__O@OO_# : len=10 : H4 00 H4 + 1607 56 11 = OO__O@__O# : len=10 : NO 00 NO + 1608 56 12 = OO__O@O_O# : len=10 : D4 00 D4 + 1609 56 13 = OO__O@_OO# : len=10 : D4 00 D4 + 1610 56 14 = OO__O@OOO# : len=10 : L5 00 L5 + 1611 56 15 = OO__O@____# : len=11 : NO 00 NO + 1612 56 16 = OO__O@O___# : len=11 : H3 22 H3 + 1613 56 17 = OO__O@_O__# : len=11 : D3 01 D3 + 1614 56 18 = OO__O@OO__# : len=11 : H4 00 H4 + 1615 56 19 = OO__O@__O_# : len=11 : NO 00 NO + 1616 56 20 = OO__O@O_O_# : len=11 : D4 00 D4 + 1617 56 21 = OO__O@_OO_# : len=11 : D4 00 D4 + 1618 56 22 = OO__O@OOO_# : len=11 : L5 00 L5 + 1619 56 23 = OO__O@___O# : len=11 : NO 00 NO + 1620 56 24 = OO__O@O__O# : len=11 : NO 00 H3 + 1621 56 25 = OO__O@_O_O# : len=11 : NO 00 D3 + 1622 56 26 = OO__O@OO_O# : len=11 : S4 00 H4 + 1623 56 27 = OO__O@__OO# : len=11 : NO 00 NO + 1624 56 28 = OO__O@O_OO# : len=11 : NO 00 D4 + 1625 56 29 = OO__O@_OOO# : len=11 : NO 00 D4 + 1626 56 30 = OO__O@OOOO# : len=11 : L6 00 L6 + 1627 56 31 = OO__O@_____ : len=11 : NO 00 NO + 1628 56 32 = OO__O@O____ : len=11 : H3 22 H3 + 1629 56 33 = OO__O@_O___ : len=11 : D3 01 D3 + 1630 56 34 = OO__O@OO___ : len=11 : H4 00 H4 + 1631 56 35 = OO__O@__O__ : len=11 : NO 00 NO + 1632 56 36 = OO__O@O_O__ : len=11 : D4 00 D4 + 1633 56 37 = OO__O@_OO__ : len=11 : D4 00 D4 + 1634 56 38 = OO__O@OOO__ : len=11 : L5 00 L5 + 1635 56 39 = OO__O@___O_ : len=11 : NO 00 NO + 1636 56 40 = OO__O@O__O_ : len=11 : NO 00 H3 + 1637 56 41 = OO__O@_O_O_ : len=11 : NO 00 D3 + 1638 56 42 = OO__O@OO_O_ : len=11 : S4 00 H4 + 1639 56 43 = OO__O@__OO_ : len=11 : NO 00 NO + 1640 56 44 = OO__O@O_OO_ : len=11 : NO 00 D4 + 1641 56 45 = OO__O@_OOO_ : len=11 : NO 00 D4 + 1642 56 46 = OO__O@OOOO_ : len=11 : L6 00 L6 + 1643 56 47 = OO__O@____O : len=11 : NO 00 NO + 1644 56 48 = OO__O@O___O : len=11 : H3 22 H3 + 1645 56 49 = OO__O@_O__O : len=11 : D3 01 D3 + 1646 56 50 = OO__O@OO__O : len=11 : H4 00 H4 + 1647 56 51 = OO__O@__O_O : len=11 : NO 00 NO + 1648 56 52 = OO__O@O_O_O : len=11 : D4 00 D4 + 1649 56 53 = OO__O@_OO_O : len=11 : D4 00 D4 + 1650 56 54 = OO__O@OOO_O : len=11 : L5 00 L5 + 1651 56 55 = OO__O@___OO : len=11 : NO 00 NO + 1652 56 56 = OO__O@O__OO : len=11 : NO 00 H3 + 1653 57 0 = OO_O_@# : len= 7 : NO 00 NO + 1654 57 1 = OO_O_@_# : len= 8 : NO 00 NO + 1655 57 2 = OO_O_@O# : len= 8 : NO 00 NO + 1656 57 3 = OO_O_@__# : len= 9 : NO 00 NO + 1657 57 4 = OO_O_@O_# : len= 9 : NO 00 D3 + 1658 57 5 = OO_O_@_O# : len= 9 : NO 00 NO + 1659 57 6 = OO_O_@OO# : len= 9 : D4 00 D4 + 1660 57 7 = OO_O_@___# : len=10 : NO 00 NO + 1661 57 8 = OO_O_@O__# : len=10 : NO 00 D3 + 1662 57 9 = OO_O_@_O_# : len=10 : NO 00 NO + 1663 57 10 = OO_O_@OO_# : len=10 : D4 00 D4 + 1664 57 11 = OO_O_@__O# : len=10 : NO 00 NO + 1665 57 12 = OO_O_@O_O# : len=10 : NO 00 D3 + 1666 57 13 = OO_O_@_OO# : len=10 : NO 00 NO + 1667 57 14 = OO_O_@OOO# : len=10 : NO 00 D4 + 1668 57 15 = OO_O_@____# : len=11 : NO 00 NO + 1669 57 16 = OO_O_@O___# : len=11 : NO 00 D3 + 1670 57 17 = OO_O_@_O__# : len=11 : NO 00 NO + 1671 57 18 = OO_O_@OO__# : len=11 : D4 00 D4 + 1672 57 19 = OO_O_@__O_# : len=11 : NO 00 NO + 1673 57 20 = OO_O_@O_O_# : len=11 : NO 00 D3 + 1674 57 21 = OO_O_@_OO_# : len=11 : NO 00 D3 + 1675 57 22 = OO_O_@OOO_# : len=11 : S4 00 H4 + 1676 57 23 = OO_O_@___O# : len=11 : NO 00 NO + 1677 57 24 = OO_O_@O__O# : len=11 : NO 00 D3 + 1678 57 25 = OO_O_@_O_O# : len=11 : NO 00 NO + 1679 57 26 = OO_O_@OO_O# : len=11 : X4 00 X4 + 1680 57 27 = OO_O_@__OO# : len=11 : NO 00 NO + 1681 57 28 = OO_O_@O_OO# : len=11 : D4 00 D4 + 1682 57 29 = OO_O_@_OOO# : len=11 : D4 00 D4 + 1683 57 30 = OO_O_@OOOO# : len=11 : L5 00 L5 + 1684 57 31 = OO_O_@_____ : len=11 : NO 00 NO + 1685 57 32 = OO_O_@O____ : len=11 : NO 00 D3 + 1686 57 33 = OO_O_@_O___ : len=11 : NO 00 NO + 1687 57 34 = OO_O_@OO___ : len=11 : D4 00 D4 + 1688 57 35 = OO_O_@__O__ : len=11 : NO 00 NO + 1689 57 36 = OO_O_@O_O__ : len=11 : NO 00 D3 + 1690 57 37 = OO_O_@_OO__ : len=11 : NO 00 D3 + 1691 57 38 = OO_O_@OOO__ : len=11 : S4 00 H4 + 1692 57 39 = OO_O_@___O_ : len=11 : NO 00 NO + 1693 57 40 = OO_O_@O__O_ : len=11 : NO 00 D3 + 1694 57 41 = OO_O_@_O_O_ : len=11 : NO 00 NO + 1695 57 42 = OO_O_@OO_O_ : len=11 : X4 00 X4 + 1696 57 43 = OO_O_@__OO_ : len=11 : NO 00 NO + 1697 57 44 = OO_O_@O_OO_ : len=11 : D4 00 D4 + 1698 57 45 = OO_O_@_OOO_ : len=11 : D4 00 D4 + 1699 57 46 = OO_O_@OOOO_ : len=11 : L5 00 L5 + 1700 57 47 = OO_O_@____O : len=11 : NO 00 NO + 1701 57 48 = OO_O_@O___O : len=11 : NO 00 D3 + 1702 57 49 = OO_O_@_O__O : len=11 : NO 00 NO + 1703 57 50 = OO_O_@OO__O : len=11 : D4 00 D4 + 1704 57 51 = OO_O_@__O_O : len=11 : NO 00 NO + 1705 57 52 = OO_O_@O_O_O : len=11 : NO 00 D3 + 1706 57 53 = OO_O_@_OO_O : len=11 : NO 00 D3 + 1707 57 54 = OO_O_@OOO_O : len=11 : NO 00 H4 + 1708 57 55 = OO_O_@___OO : len=11 : NO 00 NO + 1709 57 56 = OO_O_@O__OO : len=11 : NO 00 D3 + 1710 57 57 = OO_O_@_O_OO : len=11 : NO 00 NO + 1711 58 0 = OO_OO@# : len= 7 : NO 00 D4 + 1712 58 1 = OO_OO@_# : len= 8 : NO 00 D4 + 1713 58 2 = OO_OO@O# : len= 8 : NO 00 D4 + 1714 58 3 = OO_OO@__# : len= 9 : NO 00 D4 + 1715 58 4 = OO_OO@O_# : len= 9 : S4 00 H4 + 1716 58 5 = OO_OO@_O# : len= 9 : D4 00 X4 + 1717 58 6 = OO_OO@OO# : len= 9 : L5 00 L5 + 1718 58 7 = OO_OO@___# : len=10 : NO 00 D4 + 1719 58 8 = OO_OO@O__# : len=10 : S4 00 H4 + 1720 58 9 = OO_OO@_O_# : len=10 : D4 00 X4 + 1721 58 10 = OO_OO@OO_# : len=10 : L5 00 L5 + 1722 58 11 = OO_OO@__O# : len=10 : NO 00 D4 + 1723 58 12 = OO_OO@O_O# : len=10 : NO 00 H4 + 1724 58 13 = OO_OO@_OO# : len=10 : NO 00 X4 + 1725 58 14 = OO_OO@OOO# : len=10 : L6 00 L6 + 1726 58 15 = OO_OO@____# : len=11 : NO 00 D4 + 1727 58 16 = OO_OO@O___# : len=11 : S4 00 H4 + 1728 58 17 = OO_OO@_O__# : len=11 : D4 00 X4 + 1729 58 18 = OO_OO@OO__# : len=11 : L5 00 L5 + 1730 58 19 = OO_OO@__O_# : len=11 : NO 00 D4 + 1731 58 20 = OO_OO@O_O_# : len=11 : NO 00 H4 + 1732 58 21 = OO_OO@_OO_# : len=11 : NO 00 X4 + 1733 58 22 = OO_OO@OOO_# : len=11 : L6 00 L6 + 1734 58 23 = OO_OO@___O# : len=11 : NO 00 D4 + 1735 58 24 = OO_OO@O__O# : len=11 : S4 00 H4 + 1736 58 25 = OO_OO@_O_O# : len=11 : D4 00 X4 + 1737 58 26 = OO_OO@OO_O# : len=11 : L5 00 L5 + 1738 58 27 = OO_OO@__OO# : len=11 : NO 00 D4 + 1739 58 28 = OO_OO@O_OO# : len=11 : NO 00 H4 + 1740 58 29 = OO_OO@_OOO# : len=11 : NO 00 X4 + 1741 58 30 = OO_OO@OOOO# : len=11 : L6 00 L6 + 1742 58 31 = OO_OO@_____ : len=11 : NO 00 D4 + 1743 58 32 = OO_OO@O____ : len=11 : S4 00 H4 + 1744 58 33 = OO_OO@_O___ : len=11 : D4 00 X4 + 1745 58 34 = OO_OO@OO___ : len=11 : L5 00 L5 + 1746 58 35 = OO_OO@__O__ : len=11 : NO 00 D4 + 1747 58 36 = OO_OO@O_O__ : len=11 : NO 00 H4 + 1748 58 37 = OO_OO@_OO__ : len=11 : NO 00 X4 + 1749 58 38 = OO_OO@OOO__ : len=11 : L6 00 L6 + 1750 58 39 = OO_OO@___O_ : len=11 : NO 00 D4 + 1751 58 40 = OO_OO@O__O_ : len=11 : S4 00 H4 + 1752 58 41 = OO_OO@_O_O_ : len=11 : D4 00 X4 + 1753 58 42 = OO_OO@OO_O_ : len=11 : L5 00 L5 + 1754 58 43 = OO_OO@__OO_ : len=11 : NO 00 D4 + 1755 58 44 = OO_OO@O_OO_ : len=11 : NO 00 H4 + 1756 58 45 = OO_OO@_OOO_ : len=11 : NO 00 X4 + 1757 58 46 = OO_OO@OOOO_ : len=11 : L6 00 L6 + 1758 58 47 = OO_OO@____O : len=11 : NO 00 D4 + 1759 58 48 = OO_OO@O___O : len=11 : S4 00 H4 + 1760 58 49 = OO_OO@_O__O : len=11 : D4 00 X4 + 1761 58 50 = OO_OO@OO__O : len=11 : L5 00 L5 + 1762 58 51 = OO_OO@__O_O : len=11 : NO 00 D4 + 1763 58 52 = OO_OO@O_O_O : len=11 : NO 00 H4 + 1764 58 53 = OO_OO@_OO_O : len=11 : NO 00 X4 + 1765 58 54 = OO_OO@OOO_O : len=11 : L6 00 L6 + 1766 58 55 = OO_OO@___OO : len=11 : NO 00 D4 + 1767 58 56 = OO_OO@O__OO : len=11 : S4 00 H4 + 1768 58 57 = OO_OO@_O_OO : len=11 : D4 00 X4 + 1769 58 58 = OO_OO@OO_OO : len=11 : L5 00 L5 + 1770 59 0 = OOO__@# : len= 7 : NO 00 NO + 1771 59 1 = OOO__@_# : len= 8 : NO 00 NO + 1772 59 2 = OOO__@O# : len= 8 : NO 00 NO + 1773 59 3 = OOO__@__# : len= 9 : NO 00 NO + 1774 59 4 = OOO__@O_# : len= 9 : NO 00 NO + 1775 59 5 = OOO__@_O# : len= 9 : NO 00 NO + 1776 59 6 = OOO__@OO# : len= 9 : NO 00 NO + 1777 59 7 = OOO__@___# : len=10 : NO 00 NO + 1778 59 8 = OOO__@O__# : len=10 : NO 00 NO + 1779 59 9 = OOO__@_O_# : len=10 : NO 00 NO + 1780 59 10 = OOO__@OO_# : len=10 : NO 00 H3 + 1781 59 11 = OOO__@__O# : len=10 : NO 00 NO + 1782 59 12 = OOO__@O_O# : len=10 : NO 00 NO + 1783 59 13 = OOO__@_OO# : len=10 : NO 00 NO + 1784 59 14 = OOO__@OOO# : len=10 : S4 00 S4 + 1785 59 15 = OOO__@____# : len=11 : NO 00 NO + 1786 59 16 = OOO__@O___# : len=11 : NO 00 NO + 1787 59 17 = OOO__@_O__# : len=11 : NO 00 NO + 1788 59 18 = OOO__@OO__# : len=11 : H3 13 H3 + 1789 59 19 = OOO__@__O_# : len=11 : NO 00 NO + 1790 59 20 = OOO__@O_O_# : len=11 : D3 02 D3 + 1791 59 21 = OOO__@_OO_# : len=11 : D3 01 D3 + 1792 59 22 = OOO__@OOO_# : len=11 : H4 00 H4 + 1793 59 23 = OOO__@___O# : len=11 : NO 00 NO + 1794 59 24 = OOO__@O__O# : len=11 : NO 00 NO + 1795 59 25 = OOO__@_O_O# : len=11 : NO 00 NO + 1796 59 26 = OOO__@OO_O# : len=11 : D4 00 D4 + 1797 59 27 = OOO__@__OO# : len=11 : NO 00 NO + 1798 59 28 = OOO__@O_OO# : len=11 : D4 00 D4 + 1799 59 29 = OOO__@_OOO# : len=11 : D4 00 D4 + 1800 59 30 = OOO__@OOOO# : len=11 : L5 00 L5 + 1801 59 31 = OOO__@_____ : len=11 : NO 00 NO + 1802 59 32 = OOO__@O____ : len=11 : NO 00 NO + 1803 59 33 = OOO__@_O___ : len=11 : NO 00 NO + 1804 59 34 = OOO__@OO___ : len=11 : H3 13 H3 + 1805 59 35 = OOO__@__O__ : len=11 : NO 00 NO + 1806 59 36 = OOO__@O_O__ : len=11 : D3 02 D3 + 1807 59 37 = OOO__@_OO__ : len=11 : D3 01 D3 + 1808 59 38 = OOO__@OOO__ : len=11 : H4 00 H4 + 1809 59 39 = OOO__@___O_ : len=11 : NO 00 NO + 1810 59 40 = OOO__@O__O_ : len=11 : NO 00 NO + 1811 59 41 = OOO__@_O_O_ : len=11 : NO 00 NO + 1812 59 42 = OOO__@OO_O_ : len=11 : D4 00 D4 + 1813 59 43 = OOO__@__OO_ : len=11 : NO 00 NO + 1814 59 44 = OOO__@O_OO_ : len=11 : D4 00 D4 + 1815 59 45 = OOO__@_OOO_ : len=11 : D4 00 D4 + 1816 59 46 = OOO__@OOOO_ : len=11 : L5 00 L5 + 1817 59 47 = OOO__@____O : len=11 : NO 00 NO + 1818 59 48 = OOO__@O___O : len=11 : NO 00 NO + 1819 59 49 = OOO__@_O__O : len=11 : NO 00 NO + 1820 59 50 = OOO__@OO__O : len=11 : NO 00 H3 + 1821 59 51 = OOO__@__O_O : len=11 : NO 00 NO + 1822 59 52 = OOO__@O_O_O : len=11 : NO 00 D3 + 1823 59 53 = OOO__@_OO_O : len=11 : NO 00 D3 + 1824 59 54 = OOO__@OOO_O : len=11 : S4 00 H4 + 1825 59 55 = OOO__@___OO : len=11 : NO 00 NO + 1826 59 56 = OOO__@O__OO : len=11 : NO 00 NO + 1827 59 57 = OOO__@_O_OO : len=11 : NO 00 NO + 1828 59 58 = OOO__@OO_OO : len=11 : NO 00 D4 + 1829 59 59 = OOO__@__OOO : len=11 : NO 00 NO + 1830 60 0 = OOO_O@# : len= 7 : NO 00 D4 + 1831 60 1 = OOO_O@_# : len= 8 : NO 00 D4 + 1832 60 2 = OOO_O@O# : len= 8 : NO 00 D4 + 1833 60 3 = OOO_O@__# : len= 9 : NO 00 D4 + 1834 60 4 = OOO_O@O_# : len= 9 : NO 00 D4 + 1835 60 5 = OOO_O@_O# : len= 9 : NO 00 D4 + 1836 60 6 = OOO_O@OO# : len= 9 : NO 00 D4 + 1837 60 7 = OOO_O@___# : len=10 : NO 00 D4 + 1838 60 8 = OOO_O@O__# : len=10 : NO 00 D4 + 1839 60 9 = OOO_O@_O_# : len=10 : NO 00 D4 + 1840 60 10 = OOO_O@OO_# : len=10 : S4 00 H4 + 1841 60 11 = OOO_O@__O# : len=10 : NO 00 D4 + 1842 60 12 = OOO_O@O_O# : len=10 : D4 00 X4 + 1843 60 13 = OOO_O@_OO# : len=10 : D4 00 X4 + 1844 60 14 = OOO_O@OOO# : len=10 : L5 00 L5 + 1845 60 15 = OOO_O@____# : len=11 : NO 00 D4 + 1846 60 16 = OOO_O@O___# : len=11 : NO 00 D4 + 1847 60 17 = OOO_O@_O__# : len=11 : NO 00 D4 + 1848 60 18 = OOO_O@OO__# : len=11 : S4 00 H4 + 1849 60 19 = OOO_O@__O_# : len=11 : NO 00 D4 + 1850 60 20 = OOO_O@O_O_# : len=11 : D4 00 X4 + 1851 60 21 = OOO_O@_OO_# : len=11 : D4 00 X4 + 1852 60 22 = OOO_O@OOO_# : len=11 : L5 00 L5 + 1853 60 23 = OOO_O@___O# : len=11 : NO 00 D4 + 1854 60 24 = OOO_O@O__O# : len=11 : NO 00 D4 + 1855 60 25 = OOO_O@_O_O# : len=11 : NO 00 D4 + 1856 60 26 = OOO_O@OO_O# : len=11 : NO 00 H4 + 1857 60 27 = OOO_O@__OO# : len=11 : NO 00 D4 + 1858 60 28 = OOO_O@O_OO# : len=11 : NO 00 X4 + 1859 60 29 = OOO_O@_OOO# : len=11 : NO 00 X4 + 1860 60 30 = OOO_O@OOOO# : len=11 : L6 00 L6 + 1861 60 31 = OOO_O@_____ : len=11 : NO 00 D4 + 1862 60 32 = OOO_O@O____ : len=11 : NO 00 D4 + 1863 60 33 = OOO_O@_O___ : len=11 : NO 00 D4 + 1864 60 34 = OOO_O@OO___ : len=11 : S4 00 H4 + 1865 60 35 = OOO_O@__O__ : len=11 : NO 00 D4 + 1866 60 36 = OOO_O@O_O__ : len=11 : D4 00 X4 + 1867 60 37 = OOO_O@_OO__ : len=11 : D4 00 X4 + 1868 60 38 = OOO_O@OOO__ : len=11 : L5 00 L5 + 1869 60 39 = OOO_O@___O_ : len=11 : NO 00 D4 + 1870 60 40 = OOO_O@O__O_ : len=11 : NO 00 D4 + 1871 60 41 = OOO_O@_O_O_ : len=11 : NO 00 D4 + 1872 60 42 = OOO_O@OO_O_ : len=11 : NO 00 H4 + 1873 60 43 = OOO_O@__OO_ : len=11 : NO 00 D4 + 1874 60 44 = OOO_O@O_OO_ : len=11 : NO 00 X4 + 1875 60 45 = OOO_O@_OOO_ : len=11 : NO 00 X4 + 1876 60 46 = OOO_O@OOOO_ : len=11 : L6 00 L6 + 1877 60 47 = OOO_O@____O : len=11 : NO 00 D4 + 1878 60 48 = OOO_O@O___O : len=11 : NO 00 D4 + 1879 60 49 = OOO_O@_O__O : len=11 : NO 00 D4 + 1880 60 50 = OOO_O@OO__O : len=11 : S4 00 H4 + 1881 60 51 = OOO_O@__O_O : len=11 : NO 00 D4 + 1882 60 52 = OOO_O@O_O_O : len=11 : D4 00 X4 + 1883 60 53 = OOO_O@_OO_O : len=11 : D4 00 X4 + 1884 60 54 = OOO_O@OOO_O : len=11 : L5 00 L5 + 1885 60 55 = OOO_O@___OO : len=11 : NO 00 D4 + 1886 60 56 = OOO_O@O__OO : len=11 : NO 00 D4 + 1887 60 57 = OOO_O@_O_OO : len=11 : NO 00 D4 + 1888 60 58 = OOO_O@OO_OO : len=11 : NO 00 H4 + 1889 60 59 = OOO_O@__OOO : len=11 : NO 00 D4 + 1890 60 60 = OOO_O@O_OOO : len=11 : NO 00 X4 + 1891 61 0 = OOOO_@# : len= 7 : NO 00 D4 + 1892 61 1 = OOOO_@_# : len= 8 : NO 00 D4 + 1893 61 2 = OOOO_@O# : len= 8 : NO 00 D4 + 1894 61 3 = OOOO_@__# : len= 9 : NO 00 D4 + 1895 61 4 = OOOO_@O_# : len= 9 : NO 00 D4 + 1896 61 5 = OOOO_@_O# : len= 9 : NO 00 D4 + 1897 61 6 = OOOO_@OO# : len= 9 : NO 00 D4 + 1898 61 7 = OOOO_@___# : len=10 : NO 00 D4 + 1899 61 8 = OOOO_@O__# : len=10 : NO 00 D4 + 1900 61 9 = OOOO_@_O_# : len=10 : NO 00 D4 + 1901 61 10 = OOOO_@OO_# : len=10 : NO 00 D4 + 1902 61 11 = OOOO_@__O# : len=10 : NO 00 D4 + 1903 61 12 = OOOO_@O_O# : len=10 : NO 00 D4 + 1904 61 13 = OOOO_@_OO# : len=10 : NO 00 D4 + 1905 61 14 = OOOO_@OOO# : len=10 : NO 00 D4 + 1906 61 15 = OOOO_@____# : len=11 : NO 00 D4 + 1907 61 16 = OOOO_@O___# : len=11 : NO 00 D4 + 1908 61 17 = OOOO_@_O__# : len=11 : NO 00 D4 + 1909 61 18 = OOOO_@OO__# : len=11 : NO 00 D4 + 1910 61 19 = OOOO_@__O_# : len=11 : NO 00 D4 + 1911 61 20 = OOOO_@O_O_# : len=11 : NO 00 D4 + 1912 61 21 = OOOO_@_OO_# : len=11 : NO 00 D4 + 1913 61 22 = OOOO_@OOO_# : len=11 : S4 00 H4 + 1914 61 23 = OOOO_@___O# : len=11 : NO 00 D4 + 1915 61 24 = OOOO_@O__O# : len=11 : NO 00 D4 + 1916 61 25 = OOOO_@_O_O# : len=11 : NO 00 D4 + 1917 61 26 = OOOO_@OO_O# : len=11 : D4 00 X4 + 1918 61 27 = OOOO_@__OO# : len=11 : NO 00 D4 + 1919 61 28 = OOOO_@O_OO# : len=11 : D4 00 X4 + 1920 61 29 = OOOO_@_OOO# : len=11 : D4 00 X4 + 1921 61 30 = OOOO_@OOOO# : len=11 : L5 00 L5 + 1922 61 31 = OOOO_@_____ : len=11 : NO 00 D4 + 1923 61 32 = OOOO_@O____ : len=11 : NO 00 D4 + 1924 61 33 = OOOO_@_O___ : len=11 : NO 00 D4 + 1925 61 34 = OOOO_@OO___ : len=11 : NO 00 D4 + 1926 61 35 = OOOO_@__O__ : len=11 : NO 00 D4 + 1927 61 36 = OOOO_@O_O__ : len=11 : NO 00 D4 + 1928 61 37 = OOOO_@_OO__ : len=11 : NO 00 D4 + 1929 61 38 = OOOO_@OOO__ : len=11 : S4 00 H4 + 1930 61 39 = OOOO_@___O_ : len=11 : NO 00 D4 + 1931 61 40 = OOOO_@O__O_ : len=11 : NO 00 D4 + 1932 61 41 = OOOO_@_O_O_ : len=11 : NO 00 D4 + 1933 61 42 = OOOO_@OO_O_ : len=11 : D4 00 X4 + 1934 61 43 = OOOO_@__OO_ : len=11 : NO 00 D4 + 1935 61 44 = OOOO_@O_OO_ : len=11 : D4 00 X4 + 1936 61 45 = OOOO_@_OOO_ : len=11 : D4 00 X4 + 1937 61 46 = OOOO_@OOOO_ : len=11 : L5 00 L5 + 1938 61 47 = OOOO_@____O : len=11 : NO 00 D4 + 1939 61 48 = OOOO_@O___O : len=11 : NO 00 D4 + 1940 61 49 = OOOO_@_O__O : len=11 : NO 00 D4 + 1941 61 50 = OOOO_@OO__O : len=11 : NO 00 D4 + 1942 61 51 = OOOO_@__O_O : len=11 : NO 00 D4 + 1943 61 52 = OOOO_@O_O_O : len=11 : NO 00 D4 + 1944 61 53 = OOOO_@_OO_O : len=11 : NO 00 D4 + 1945 61 54 = OOOO_@OOO_O : len=11 : NO 00 H4 + 1946 61 55 = OOOO_@___OO : len=11 : NO 00 D4 + 1947 61 56 = OOOO_@O__OO : len=11 : NO 00 D4 + 1948 61 57 = OOOO_@_O_OO : len=11 : NO 00 D4 + 1949 61 58 = OOOO_@OO_OO : len=11 : NO 00 X4 + 1950 61 59 = OOOO_@__OOO : len=11 : NO 00 D4 + 1951 61 60 = OOOO_@O_OOO : len=11 : NO 00 X4 + 1952 61 61 = OOOO_@_OOOO : len=11 : NO 00 X4 +*/ + +unsigned char *pat_gomoku /* [1954] */ = +/* 0 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" +/* 16 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x44\x55\xcc\x00\x00\x00\x00" +/* 32 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x33\x00\x44\x00\x33\x00\x00\x00" +/* 48 */ "\x00\x22\x00\x55\x00\x22\x00\x00\x00\x44\x33\x66\x55\xcc\x33\x66" +/* 64 */ "\x55\xcc\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x03\x00\x00\x00" +/* 80 */ "\x55\x00\x55\x00\x05\x00\x55\x02\x46\x00\xaa\x00\x00\x55\x00\x55" +/* 96 */ "\x00\x05\x00\x55\x00\x05\x00\x55\x00\x00\x44\xcc\x44\xcc\x05\xbb" +/* 112 */ "\x44\xcc\x05\xbb\x44\xcc\x05\xbb\x00\x00\x00\x00\x00\x00\x00\x00" +/* 128 */ "\x00\x00\x33\x00\x00\x00\x44\x00\x00\x00\x00\x00\x33\x00\x44\x00" +/* 144 */ "\x33\x22\x66\x00\x55\x55\xcc\x00\x33\x00\x00\x00\x00\x22\x00\x55" +/* 160 */ "\x00\x22\x00\x55\x00\x02\x00\x05\x00\x22\x00\x00\x33\x44\x33\x66" +/* 176 */ "\x55\xcc\x33\x66\x55\xcc\x33\x46\x05\xbb\x33\x66\x55\xcc\x00\x00" +/* 192 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x03\x00\x00\x00\x44\x00\x00\x00" +/* 208 */ "\x33\x00\x00\x22\x55\x22\x55\x02\x05\x22\x55\x02\x46\x22\xaa\x55" +/* 224 */ "\xcc\x22\x55\x02\x46\x22\xaa\x00\x22\x55\x22\x55\x02\x05\x22\x55" +/* 240 */ "\x02\x05\x22\x55\x02\x05\x22\x55\x02\x05\x22\x55\x02\x44\x66\xcc" +/* 256 */ "\x66\xcc\x46\xbb\x66\xcc\x46\xbb\x66\xcc\x46\xbb\x66\xcc\x46\xbb" +/* 272 */ "\x66\xcc\x46\xbb\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x33\x00" +/* 288 */ "\x00\x00\x44\x00\x00\x00\x33\x00\x22\x22\x66\x00\x00\x00\x00\x00" +/* 304 */ "\x03\x00\x44\x00\x33\x22\x66\x00\x55\x55\xcc\x00\x33\x22\x66\x00" +/* 320 */ "\x55\x55\xcc\x00\x03\x00\x00\x00\x00\x02\x00\x55\x00\x02\x00\x55" +/* 336 */ "\x00\x02\x00\x05\x00\x02\x00\x55\x00\x02\x02\x46\x00\x02\x00\x55" +/* 352 */ "\x55\x05\x55\x46\xaa\xcc\x55\x46\xaa\xcc\x55\x06\x5a\xbb\x55\x46" +/* 368 */ "\xaa\xcc\x55\x06\x5a\xbb\x55\x46\xaa\xcc\x00\x00\x00\x00\x00\x00" +/* 384 */ "\x00\x00\x00\x00\x03\x00\x00\x00\x44\x00\x00\x00\x33\x00\x22\x22" +/* 400 */ "\x66\x00\x00\x00\x55\x00\x55\x55\x05\x55\x05\x55\x05\x55\x05\x55" +/* 416 */ "\x46\x55\x5a\xaa\xcc\x55\x05\x55\x46\x55\x5a\xaa\xcc\x55\x05\x55" +/* 432 */ "\x06\x55\x0a\x55\x55\x05\x55\x05\x55\x05\x55\x05\x55\x05\x55\x05" +/* 448 */ "\x55\x05\x55\x05\x55\x05\x55\x05\x55\x46\x55\x05\x55\x5a\x55\x5a" +/* 464 */ "\xaa\xcc\xcc\xbb\xcc\xbb\xcc\xbb\xcc\xbb\xcc\xbb\xcc\xbb\xcc\xbb" +/* 480 */ "\xcc\xbb\xcc\xbb\xcc\xbb\xcc\xbb\xcc\xbb\xcc\xbb\xcc\xbb\xcc\xbb" +/* 496 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x33\x00\x00\x00\x44\x00" +/* 512 */ "\x00\x00\x33\x00\x22\x22\x66\x00\x00\x00\x55\x00\x55\x55\xcc\x00" +/* 528 */ "\x00\x00\x00\x00\x33\x00\x44\x00\x33\x22\x66\x00\x55\x55\xcc\x00" +/* 544 */ "\x33\x22\x66\x00\x55\x55\xcc\x00\x33\x02\x46\x00\x05\x05\xbb\x00" +/* 560 */ "\x33\x00\x00\x00\x00\x22\x00\x55\x00\x22\x00\x55\x00\x02\x00\x05" +/* 576 */ "\x00\x22\x00\x55\x00\x02\x02\x46\x00\x22\x00\xaa\x00\x55\x55\xcc" +/* 592 */ "\x00\x22\x00\x00\x33\x44\x33\x66\x55\xcc\x33\x66\x55\xcc\x33\x46" +/* 608 */ "\x05\xbb\x33\x66\x55\xcc\x33\x46\x05\xbb\x33\x66\x55\xcc\x33\x46" +/* 624 */ "\x05\xbb\x33\x66\x55\xcc\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" +/* 640 */ "\x03\x00\x00\x00\x44\x00\x00\x00\x33\x00\x22\x22\x66\x00\x00\x00" +/* 656 */ "\x55\x00\x55\x55\xcc\x00\x00\x00\x33\x00\x00\x22\x55\x22\x55\x02" +/* 672 */ "\x05\x22\x55\x02\x46\x22\xaa\x55\xcc\x22\x55\x02\x46\x22\xaa\x55" +/* 688 */ "\xcc\x22\x55\x02\x06\x22\x5a\x05\xbb\x22\x55\x02\x46\x22\xaa\x00" +/* 704 */ "\x22\x55\x22\x55\x02\x05\x22\x55\x02\x05\x22\x55\x02\x05\x22\x55" +/* 720 */ "\x02\x05\x22\x55\x02\x46\x22\x55\x02\x5a\x22\xaa\x55\xcc\x22\x55" +/* 736 */ "\x02\x05\x22\x55\x02\x44\x66\xcc\x66\xcc\x46\xbb\x66\xcc\x46\xbb" +/* 752 */ "\x66\xcc\x46\xbb\x66\xcc\x46\xbb\x66\xcc\x46\xbb\x66\xcc\x46\xbb" +/* 768 */ "\x66\xcc\x46\xbb\x66\xcc\x46\xbb\x66\xcc\x46\xbb\x00\x00\x00\x00" +/* 784 */ "\x00\x00\x00\x00\x00\x00\x33\x00\x00\x00\x44\x00\x00\x00\x33\x00" +/* 800 */ "\x22\x22\x66\x00\x00\x00\x55\x00\x55\x55\xcc\x00\x00\x00\x33\x00" +/* 816 */ "\x22\x22\x66\x00\x00\x00\x00\x00\x03\x00\x44\x00\x33\x22\x66\x00" +/* 832 */ "\x55\x55\xcc\x00\x33\x22\x66\x00\x55\x55\xcc\x00\x03\x02\x46\x00" +/* 848 */ "\x05\x05\xbb\x00\x33\x22\x66\x00\x55\x55\xcc\x00\x03\x00\x00\x00" +/* 864 */ "\x00\x02\x00\x55\x00\x02\x00\x55\x00\x02\x00\x05\x00\x02\x00\x55" +/* 880 */ "\x00\x02\x02\x46\x00\x02\x00\xaa\x00\x55\x55\xcc\x00\x02\x00\x55" +/* 896 */ "\x00\x02\x02\x46\x00\x02\x00\x55\x55\x05\x55\x46\xaa\xcc\x55\x46" +/* 912 */ "\xaa\xcc\x55\x06\x5a\xbb\x55\x46\xaa\xcc\x55\x06\x5a\xbb\x55\x46" +/* 928 */ "\xaa\xcc\x55\x06\x5a\xbb\x55\x46\xaa\xcc\x55\x06\x5a\xbb\x55\x46" +/* 944 */ "\xaa\xcc\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x03\x00\x00\x00" +/* 960 */ "\x44\x00\x00\x00\x33\x00\x22\x22\x66\x00\x00\x00\x55\x00\x55\x55" +/* 976 */ "\xcc\x00\x00\x00\x33\x00\x22\x22\x66\x00\x00\x00\x55\x00\x55\x55" +/* 992 */ "\x05\x55\x05\x55\x05\x55\x05\x55\x46\x55\x5a\xaa\xcc\x55\x05\x55" +/* 1008 */ "\x46\x55\x5a\xaa\xcc\x55\x05\x55\x06\x55\x0a\x5a\xbb\x55\x05\x55" +/* 1024 */ "\x46\x55\x5a\xaa\xcc\x55\x05\x55\x06\x55\x0a\x55\x55\x05\x55\x05" +/* 1040 */ "\x55\x05\x55\x05\x55\x05\x55\x05\x55\x05\x55\x05\x55\x05\x55\x05" +/* 1056 */ "\x55\x46\x55\x05\x55\x5a\x55\x5a\xaa\xcc\x55\x05\x55\x05\x55\x05" +/* 1072 */ "\x55\x46\x55\x05\x55\x5a\x55\x5a\xaa\xcc\xcc\xbb\xcc\xbb\xcc\xbb" +/* 1088 */ "\xcc\xbb\xcc\xbb\xcc\xbb\xcc\xbb\xcc\xbb\xcc\xbb\xcc\xbb\xcc\xbb" +/* 1104 */ "\xcc\xbb\xcc\xbb\xcc\xbb\xcc\xbb\xcc\xbb\xcc\xbb\xcc\xbb\xcc\xbb" +/* 1120 */ "\xcc\xbb\xcc\xbb\xcc\xbb\xcc\xbb\x00\x00\x00\x00\x00\x00\x00\x00" +/* 1136 */ "\x00\x00\x33\x00\x00\x00\x44\x00\x00\x00\x33\x00\x22\x22\x66\x00" +/* 1152 */ "\x00\x00\x55\x00\x55\x55\xcc\x00\x00\x00\x33\x00\x22\x22\x66\x00" +/* 1168 */ "\x00\x00\x55\x00\x55\x55\xcc\x00\x00\x00\x00\x00\x33\x00\x44\x00" +/* 1184 */ "\x33\x22\x66\x00\x55\x55\xcc\x00\x33\x22\x66\x00\x55\x55\xcc\x00" +/* 1200 */ "\x33\x02\x46\x00\x05\x05\xbb\x00\x33\x22\x66\x00\x55\x55\xcc\x00" +/* 1216 */ "\x33\x02\x46\x00\x05\x05\xbb\x00\x33\x00\x00\x00\x00\x22\x00\x55" +/* 1232 */ "\x00\x22\x00\x55\x00\x02\x00\x05\x00\x22\x00\x55\x00\x02\x02\x46" +/* 1248 */ "\x00\x22\x00\xaa\x00\x55\x55\xcc\x00\x22\x00\x55\x00\x02\x02\x46" +/* 1264 */ "\x00\x22\x00\xaa\x00\x55\x55\xcc\x00\x22\x00\x00\x03\x44\x33\x66" +/* 1280 */ "\x55\xcc\x33\x66\x55\xcc\x03\x46\x05\xbb\x33\x66\x55\xcc\x03\x46" +/* 1296 */ "\x05\xbb\x33\x66\x55\xcc\x03\x46\x05\xbb\x33\x66\x55\xcc\x03\x46" +/* 1312 */ "\x05\xbb\x33\x66\x55\xcc\x03\x46\x05\xbb\x33\x66\x55\xcc\x00\x00" +/* 1328 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x03\x00\x00\x00\x44\x00\x00\x00" +/* 1344 */ "\x33\x00\x22\x22\x66\x00\x00\x00\x55\x00\x55\x55\xcc\x00\x00\x00" +/* 1360 */ "\x33\x00\x22\x22\x66\x00\x00\x00\x55\x00\x55\x55\xcc\x00\x00\x00" +/* 1376 */ "\x03\x00\x00\x02\x55\x02\x55\x02\x05\x02\x55\x02\x46\x02\xaa\x55" +/* 1392 */ "\xcc\x02\x55\x02\x46\x02\xaa\x55\xcc\x02\x55\x02\x06\x02\x5a\x05" +/* 1408 */ "\xbb\x02\x55\x02\x46\x02\xaa\x55\xcc\x02\x55\x02\x06\x02\x5a\x05" +/* 1424 */ "\xbb\x02\x55\x02\x46\x02\xaa\x00\x02\x55\x02\x55\x02\x05\x02\x55" +/* 1440 */ "\x02\x05\x02\x55\x02\x05\x02\x55\x02\x05\x02\x55\x02\x46\x02\x55" +/* 1456 */ "\x02\x5a\x02\xaa\x55\xcc\x02\x55\x02\x05\x02\x55\x02\x46\x02\x55" +/* 1472 */ "\x02\x5a\x02\xaa\x55\xcc\x02\x55\x02\x05\x02\x55\x02\x05\x46\xcc" +/* 1488 */ "\x46\xcc\x06\xbb\x46\xcc\x06\xbb\x46\xcc\x06\xbb\x46\xcc\x06\xbb" +/* 1504 */ "\x46\xcc\x06\xbb\x46\xcc\x06\xbb\x46\xcc\x06\xbb\x46\xcc\x06\xbb" +/* 1520 */ "\x46\xcc\x06\xbb\x46\xcc\x06\xbb\x46\xcc\x06\xbb\x46\xcc\x06\xbb" +/* 1536 */ "\x46\xcc\x06\xbb\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x33\x00" +/* 1552 */ "\x00\x00\x44\x00\x00\x00\x33\x00\x22\x22\x66\x00\x00\x00\x55\x00" +/* 1568 */ "\x55\x55\xcc\x00\x00\x00\x33\x00\x22\x22\x66\x00\x00\x00\x55\x00" +/* 1584 */ "\x55\x55\xcc\x00\x00\x00\x33\x00\x02\x02\x46\x00\x00\x00\x00\x00" +/* 1600 */ "\x03\x00\x44\x00\x33\x22\x66\x00\x55\x55\xcc\x00\x33\x22\x66\x00" +/* 1616 */ "\x55\x55\xcc\x00\x03\x02\x46\x00\x05\x05\xbb\x00\x33\x22\x66\x00" +/* 1632 */ "\x55\x55\xcc\x00\x03\x02\x46\x00\x05\x05\xbb\x00\x33\x22\x66\x00" +/* 1648 */ "\x55\x55\xcc\x00\x03\x00\x00\x00\x00\x02\x00\x55\x00\x02\x00\x55" +/* 1664 */ "\x00\x02\x00\x05\x00\x02\x00\x55\x00\x02\x02\x46\x00\x02\x00\xaa" +/* 1680 */ "\x00\x55\x55\xcc\x00\x02\x00\x55\x00\x02\x02\x46\x00\x02\x00\xaa" +/* 1696 */ "\x00\x55\x55\xcc\x00\x02\x00\x55\x00\x02\x02\x06\x00\x02\x00\x05" +/* 1712 */ "\x05\x05\x05\x46\x5a\xcc\x05\x46\x5a\xcc\x05\x06\x0a\xbb\x05\x46" +/* 1728 */ "\x5a\xcc\x05\x06\x0a\xbb\x05\x46\x5a\xcc\x05\x06\x0a\xbb\x05\x46" +/* 1744 */ "\x5a\xcc\x05\x06\x0a\xbb\x05\x46\x5a\xcc\x05\x06\x0a\xbb\x05\x46" +/* 1760 */ "\x5a\xcc\x05\x06\x0a\xbb\x05\x46\x5a\xcc\x00\x00\x00\x00\x00\x00" +/* 1776 */ "\x00\x00\x00\x00\x03\x00\x00\x00\x44\x00\x00\x00\x33\x00\x22\x22" +/* 1792 */ "\x66\x00\x00\x00\x55\x00\x55\x55\xcc\x00\x00\x00\x33\x00\x22\x22" +/* 1808 */ "\x66\x00\x00\x00\x55\x00\x55\x55\xcc\x00\x00\x00\x03\x00\x02\x02" +/* 1824 */ "\x46\x00\x00\x00\x05\x00\x05\x05\x05\x05\x05\x05\x05\x05\x05\x05" +/* 1840 */ "\x46\x05\x5a\x5a\xcc\x05\x05\x05\x46\x05\x5a\x5a\xcc\x05\x05\x05" +/* 1856 */ "\x06\x05\x0a\x0a\xbb\x05\x05\x05\x46\x05\x5a\x5a\xcc\x05\x05\x05" +/* 1872 */ "\x06\x05\x0a\x0a\xbb\x05\x05\x05\x46\x05\x5a\x5a\xcc\x05\x05\x05" +/* 1888 */ "\x06\x05\x0a\x05\x05\x05\x05\x05\x05\x05\x05\x05\x05\x05\x05\x05" +/* 1904 */ "\x05\x05\x05\x05\x05\x05\x05\x05\x05\x46\x05\x05\x05\x5a\x05\x5a" +/* 1920 */ "\x5a\xcc\x05\x05\x05\x05\x05\x05\x05\x46\x05\x05\x05\x5a\x05\x5a" +/* 1936 */ "\x5a\xcc\x05\x05\x05\x05\x05\x05\x05\x06\x05\x05\x05\x0a\x05\x0a" +/* 1952 */ "\x0a"; + +unsigned char *adv_gomoku /* [978] */ = +/* 0 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" +/* 16 */ "\x00\x00\x00\x00\xa0\x00\xa0\x00\x04\x00\x04\x00\x00\xd0\x00\xd0" +/* 32 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" +/* 48 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" +/* 64 */ "\x00\x70\x00\x00\x00\x00\xa0\x00\xa1\x00\x00\x00\xa0\x00\x04\x00" +/* 80 */ "\x04\x00\x00\x00\x04\x00\xd0\xd0\x00\xd0\x00\xd0\x00\xd0\x00\x00" +/* 96 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x70\x08\x08\x00\x08\x00\x08\x00" +/* 112 */ "\x08\x00\x08\x00\x40\x40\x00\x40\x00\x40\x00\x40\x00\x40\x00\x00" +/* 128 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x70" +/* 144 */ "\x00\x00\x00\x70\x21\x00\x00\x00\x00\x00\xa1\x00\x00\x00\xa1\x00" +/* 160 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" +/* 176 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" +/* 192 */ "\x00\x00\x00\x00\x00\x00\x70\x21\x00\x00\x00\x00\x00\x00\x00\x00" +/* 208 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" +/* 224 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" +/* 240 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x70\x00\x00" +/* 256 */ "\x00\x70\x21\x00\x00\x00\x00\x00\x00\x00\xa0\x00\xa1\x00\x00\x00" +/* 272 */ "\xa1\x00\x00\x00\xa0\x00\x00\x00\xa0\x00\x04\x00\x04\x00\x00\x00" +/* 288 */ "\x04\x00\x00\x00\x04\x00\x00\x00\x04\x00\xd0\xd0\x00\xd0\x00\xd0" +/* 304 */ "\x00\xd0\x00\xd0\x00\xd0\x00\xd0\x00\xd0\x00\x00\x00\x00\x00\x00" +/* 320 */ "\x00\x00\x00\x00\x70\x21\x00\x00\x00\x00\x00\x00\x70\x08\x08\x00" +/* 336 */ "\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00" +/* 352 */ "\x40\x40\x00\x40\x00\x40\x00\x40\x00\x40\x00\x40\x00\x40\x00\x40" +/* 368 */ "\x00\x40\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" +/* 384 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x70\x00\x00\x00\x70" +/* 400 */ "\x21\x00\x00\x00\x00\x00\x00\x70\x21\x00\x00\x00\x00\x00\xa1\x00" +/* 416 */ "\x00\x00\xa1\x00\x00\x00\x00\x00\x00\x00\xa1\x00\x00\x00\x00\x00" +/* 432 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" +/* 448 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" +/* 464 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" +/* 480 */ "\x00\x00\x70\x21\x00\x00\x00\x00\x00\x00\x70\x21\x00\x00\x00\x00" +/* 496 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" +/* 512 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" +/* 528 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" +/* 544 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" +/* 560 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x70\x00\x00\x00\x70\x21\x00" +/* 576 */ "\x00\x00\x00\x00\x00\x70\x21\x00\x00\x00\x00\x00\x00\x00\xa0\x00" +/* 592 */ "\xa1\x00\x00\x00\xa1\x00\x00\x00\xa0\x00\x00\x00\xa1\x00\x00\x00" +/* 608 */ "\xa0\x00\x00\x00\xa0\x00\x04\x00\x04\x00\x00\x00\x04\x00\x00\x00" +/* 624 */ "\x04\x00\x00\x00\x04\x00\x00\x00\x04\x00\x00\x00\x04\x00\x00\xd0" +/* 640 */ "\x00\xd0\x00\x00\x00\xd0\x00\x00\x00\xd0\x00\x00\x00\xd0\x00\x00" +/* 656 */ "\x00\xd0\x00\x00\x00\xd0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" +/* 672 */ "\x70\x21\x00\x00\x00\x00\x00\x00\x70\x21\x00\x00\x00\x00\x00\x00" +/* 688 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" +/* 704 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" +/* 720 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" +/* 736 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" +/* 752 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" +/* 768 */ "\x00\x00\x00\x00\x00\x00\x00\x70\x00\x00\x00\x70\x21\x00\x00\x00" +/* 784 */ "\x00\x00\x00\x70\x21\x00\x00\x00\x00\x00\x00\x70\x00\x00\x00\x00" +/* 800 */ "\x00\x00\xa1\x00\x00\x00\xa1\x00\x00\x00\x00\x00\x00\x00\xa1\x00" +/* 816 */ "\x00\x00\x00\x00\x00\x00\xa1\x00\x00\x00\x00\x00\x00\x00\x00\x00" +/* 832 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" +/* 848 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" +/* 864 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" +/* 880 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x70\x21" +/* 896 */ "\x00\x00\x00\x00\x00\x00\x70\x21\x00\x00\x00\x00\x00\x00\x00\x00" +/* 912 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" +/* 928 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" +/* 944 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" +/* 960 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" +/* 976 */ "\x00"; diff --git a/pttbbs/include/modes.h b/pttbbs/include/modes.h new file mode 100644 index 00000000..fe3a6b79 --- /dev/null +++ b/pttbbs/include/modes.h @@ -0,0 +1,152 @@ +/* $Id: modes.h,v 1.1 2002/03/07 15:13:48 in2 Exp $ */ +#ifndef INCLUDE_MODES_H +#define INCLUDE_MODES_H + +#define DONOTHING 0 /* Read menu command return states */ +#define FULLUPDATE 1 /* Entire screen was destroyed in this oper */ +#define PARTUPDATE 2 /* Only the top three lines were destroyed */ +#define DOQUIT 3 /* Exit read menu was executed */ +#define NEWDIRECT 4 /* Directory has changed, re-read files */ +#define READ_NEXT 5 /* Direct read next file */ +#define READ_PREV 6 /* Direct read prev file */ +#define DIRCHANGED 8 /* Index file was changed */ +#define READ_REDRAW 9 +#define PART_REDRAW 10 +#define POS_NEXT 101 /* cursor_pos(locmem, locmem->crs_ln + 1, 1);*/ + +/* user 操作狀態與模式 */ +#define IDLE 0 +#define MMENU 1 /* menu mode */ +#define ADMIN 2 +#define MAIL 3 +#define TMENU 4 +#define UMENU 5 +#define XMENU 6 +#define CLASS 7 +#define PMENU 8 +#define NMENU 9 +#define PSALE 10 +#define POSTING 11 /* boards & class */ +#define READBRD 12 +#define READING 13 +#define READNEW 14 +#define SELECT 15 +#define RMAIL 16 /* mail menu */ +#define SMAIL 17 +#define CHATING 18 /* talk menu */ +#define XMODE 19 +#define FRIEND 20 +#define LAUSERS 21 +#define LUSERS 22 +#define MONITOR 23 +#define PAGE 24 +#define TQUERY 25 +#define TALK 26 +#define EDITPLAN 27 /* user menu */ +#define EDITSIG 28 +#define VOTING 29 +#define XINFO 30 +#define MSYSOP 31 +#define WWW 32 +#define BIG2 33 +#define REPLY 34 +#define HIT 35 +#define DBACK 36 +#define NOTE 37 +#define EDITING 38 +#define MAILALL 39 +#define MJ 40 +#define P_FRIEND 41 +#define LOGIN 42 /* main menu */ +#define DICT 43 +#define BRIDGE 44 +#define ARCHIE 45 +#define GOPHER 46 +#define NEWS 47 +#define LOVE 48 +#define EDITEXP 49 +#define IPREG 50 +#define NADM 51 +#define DRINK 52 +#define CAL 53 +#define PROVERB 54 +#define ANNOUNCE 55 /* announce */ +#define EDNOTE 56 +#define CDICT 57 +#define LOBJ 58 +#define OSONG 59 +#define CHICKEN 60 +#define TICKET 61 +#define GUESSNUM 62 +#define AMUSE 63 +#define OTHELLO 64 +#define DICE 65 +#define VICE 66 +#define BBCALL 67 +#define VIOLATELAW 68 +#define M_FIVE 69 +#define JACK_CARD 70 +#define TENHALF 71 +#define CARD_99 72 +#define RAIL_WAY 73 +#define SREG 74 +#define CHC 75 /* Chinese chess */ +#define DARK 76 /* 中國暗琪 */ +#define TMPJACK 77 +#define JCEE 78 +#define REEDIT 79 + +/* menu.c 中的模式 */ +#define QUIT 0x666 /* Return value to abort recursive functions */ +#define XEASY 0x333 /* Return value to un-redraw screen */ + +/* for currmode */ +#define MODE_STARTED 1 /* 是否已經進入系統 */ +#define MODE_POST 2 /* 是否可以在 currboard 發表文章 */ +#define MODE_BOARD 4 /* 是否可以在 currboard 刪除、mark文章 */ +#define MODE_MENU 8 /* 是否可以在 MENU 開板 */ +#define MODE_DIGEST 0x10 /* 是否為 digest mode */ +#define MODE_ETC 0x20 /* 是否為 etc mode */ +#define MODE_SELECT 0x40 /* 搜尋使用者標題 */ +#define MODE_DIRTY 0x80 /* 是否更動過 userflag */ + +/* for curredit */ +#define EDIT_MAIL 1 /* 目前是 mail/board ? */ +#define EDIT_LIST 2 /* 是否為 mail list ? */ +#define EDIT_BOTH 4 /* both reply to author/board ? */ +#define EDIT_ITEM 8 /* ITEM ? */ + +/* read.c 中的模式 */ +#define TAG_NIN 0 /* 不屬於 TagList */ +#define TAG_TOGGLE 1 /* 切換 Taglist */ +#define TAG_INSERT 2 /* 加入 TagList */ + + +#define RS_FORWARD 0x01 /* backward */ +#define RS_TITLE 0x02 /* author/title */ +#define RS_RELATED 0x04 +#define RS_FIRST 0x08 /* find first article */ +#define RS_CURRENT 0x10 /* match current read article */ +#define RS_THREAD 0x20 /* search the first article */ +#define RS_AUTHOR 0x40 /* search author's article */ +#define RS_NEWPOST 0x80 /* search new posts */ + +#define CURSOR_FIRST (RS_RELATED | RS_TITLE | RS_FIRST) +#define CURSOR_NEXT (RS_RELATED | RS_TITLE | RS_FORWARD) +#define CURSOR_PREV (RS_RELATED | RS_TITLE) +#define RELATE_FIRST (RS_RELATED | RS_TITLE | RS_FIRST | RS_CURRENT) +#define RELATE_NEXT (RS_RELATED | RS_TITLE | RS_FORWARD | RS_CURRENT) +#define RELATE_PREV (RS_RELATED | RS_TITLE | RS_CURRENT) +#define THREAD_NEXT (RS_THREAD | RS_FORWARD) +#define THREAD_PREV (RS_THREAD) + +enum {STRIP_ALL = 0, ONLY_COLOR, NO_RELOAD}; + +#define SIG_PK 0 +#define SIG_TALK 1 +#define SIG_BROADCAST 2 +#define SIG_GOMO 3 +#define SIG_CHC 4 +#define SIG_DARK 5 + +#endif diff --git a/pttbbs/include/perm.h b/pttbbs/include/perm.h new file mode 100644 index 00000000..eece624e --- /dev/null +++ b/pttbbs/include/perm.h @@ -0,0 +1,56 @@ +/* $Id: perm.h,v 1.1 2002/03/07 15:13:48 in2 Exp $ */ +#ifndef INCLUDE_PERM_H +#define INCLUDE_PERM_H + +#define PERM_BASIC 000000000001 +#define PERM_CHAT 000000000002 +#define PERM_PAGE 000000000004 +#define PERM_POST 000000000010 +#define PERM_LOGINOK 000000000020 +#define PERM_MAILLIMIT 000000000040 +#define PERM_CLOAK 000000000100 +#define PERM_SEECLOAK 000000000200 +#define PERM_XEMPT 000000000400 +#define PERM_DENYPOST 000000001000 +#define PERM_BM 000000002000 +#define PERM_ACCOUNTS 000000004000 +#define PERM_CHATROOM 000000010000 +#define PERM_BOARD 000000020000 +#define PERM_SYSOP 000000040000 +#define PERM_BBSADM 000000100000 +#define PERM_NOTOP 000000200000 +#define PERM_VIOLATELAW 000000400000 +#define PERM_NOOUTMAIL 000001000000 +#define PERM_20 000002000000 +#define PERM_VIEWSYSOP 000004000000 +#define PERM_LOGUSER 000010000000 +#define PERM_ANNOUNCE 000020000000 +#define PERM_RELATION 000040000000 +#define PERM_SMG 000100000000 +#define PERM_PRG 000200000000 +#define PERM_ACTION 000400000000 +#define PERM_PAINT 001000000000 +#define PERM_LAW 002000000000 +#define PERM_SYSSUBOP 004000000000 +#define PERM_MSYSOP 010000000000 +#define PERM_PTT 020000000000 + +#define NUMPERMS 32 + +#define PERM_DEFAULT (PERM_BASIC | PERM_CHAT | PERM_PAGE ) +#define PERM_MANAGER (PERM_RELATION | PERM_SMG | PERM_ACTION | PERM_PAINT | PERM_LAW) +#define PERM_ADMIN (PERM_ACCOUNTS | PERM_SYSOP | PERM_SYSSUBOP | PERM_MANAGER | PERM_BM) +#define PERM_ALLBOARD (PERM_SYSOP | PERM_BOARD) +#define PERM_LOGINCLOAK (PERM_SYSOP | PERM_ACCOUNTS) +#define PERM_SEEULEVELS (PERM_SYSOP) +#define PERM_SEEBLEVELS (PERM_SYSOP | PERM_BM) +#define PERM_NOTIMEOUT (PERM_SYSOP) +#define PERM_READMAIL (PERM_BASIC) +#define PERM_FORWARD (PERM_BASIC) /* to do the forwarding */ +#define PERM_INTERNET (PERM_LOGINOK) /* 身份認證過關的才能寄信到 Internet */ + +#define HAS_PERM(x) ((x) ? cuser.userlevel & (x) : 1) +#define HAVE_PERM(x) (cuser.userlevel&(x)) +#define PERM_HIDE(u) ((u)->userlevel & PERM_SYSOP && \ + (u)->userlevel & PERM_DENYPOST) +#endif diff --git a/pttbbs/include/proto.h b/pttbbs/include/proto.h new file mode 100644 index 00000000..8122f5d5 --- /dev/null +++ b/pttbbs/include/proto.h @@ -0,0 +1,522 @@ +/* $Id: proto.h,v 1.1 2002/03/07 15:13:48 in2 Exp $ */ +#ifndef INCLUDE_PROTO_H +#define INCLUDE_PROTO_H + +/* admin */ +int m_mod_board(char *bname); +int m_newbrd(int recover); +int scan_register_form(char *regfile, int automode, int neednum); +int m_user(); +int search_user_bypwd(); +int search_user_bybakpwd(); +int m_board(); +int m_register(); +int cat_register(); +unsigned int setperms(unsigned int pbits, char *pstring[]); +void setup_man(boardheader_t * board); + +/* announce */ +int a_menu(char *maintitle, char *path, int lastlevel); +void a_copyitem(char* fpath, char* title, char* owner, int mode); +int Announce(); +void gem(char* maintitle, item_t* path, int update); + +/* args */ +void initsetproctitle(int argc, char **argv, char **envp); +void setproctitle(const char* format, ...); + +/* bbcall */ +int main_bbcall(); + +/* bbs */ +void make_blist(); +int invalid_brdname(char *brd); +int del_range(int ent, fileheader_t *fhdr, char *direct); +int cmpfowner(fileheader_t *fhdr); +int b_note_edit_bname(int bid); +int Read(); +void anticrosspost(); +int Select(); +void do_reply_title(int row, char *title); +int cmpfmode(fileheader_t *fhdr); +int cmpfilename(fileheader_t *fhdr); +int getindex(char *fpath, char *fname, int size); +void outgo_post(fileheader_t *fh, char *board); +int edit_title(int ent, fileheader_t *fhdr, char *direct); +int whereami(int ent, fileheader_t *fhdr, char *direct); +void set_board(); +int do_post(); +void ReadSelect(); +int save_violatelaw(); +int board_select(); +int board_etc(); +int board_digest(); + +/* board */ +int brc_unread(char *fname, int bnum, int *blist); +int brc_initial(char *boardname); +void brc_update(); +int Ben_Perm(boardheader_t *bptr); +int New(); +int Boards(); +int root_board(); +void save_brdbuf(void); +void init_brdbuf(void); + +/* cache */ +int moneyof(int uid); +int getuser(char *userid); +void setuserid(int num, char *userid); +int searchuser(char *userid); +int getbnum(char *bname); +void reset_board(int bid); +void touch_boards(); +void addbrd_touchcache(); +void setapath(char *buf, char *boardname); +void setutmpmode(int mode); +void setadir(char *buf, char *path); +boardheader_t *getbcache(int bid); +int apply_boards(int (*func)(boardheader_t *)); +int haspostperm(char *bname); +void inbtotal(int bid, int add); +void brc_addlist(char *fname); +void setbtotal(int bid); +unsigned int safe_sleep(unsigned int seconds); +int apply_ulist(int (*fptr)(userinfo_t *)); +userinfo_t *search_ulistn(int uid, int unum); +void purge_utmp(userinfo_t *uentp); +userinfo_t *search_ulist(int uid); +int count_multi(); +void resolve_utmp(); +void attach_uhash(); +void getnewutmpent(userinfo_t *up); +void resolve_garbage(); +void resolve_boards(); +void resolve_fcache(); +void sem_init(int semkey,int *semid); +void sem_lock(int op,int semid); +int count_ulist(); +char *u_namearray(char buf[][IDLEN + 1], int *pnum, char *tag); +char *getuserid(int num); +int searchnewuser(int mode); +int count_logins(int uid, int show); +void remove_from_uhash(int n); +void add_to_uhash(int n, char *id); +int setumoney(int uid, int money); +int getbtotal(int bid); +userinfo_t *search_ulist_pid(int pid); +int moneyof(int uid); +void hbflreload(int bid); +int hbflcheck(int bid, int uid); + +/* cal */ +int vice(int money, char* item); +int inumoney(char *tuser, int money); +int cal(); +#define reload_money() cuser.money=moneyof(usernum) +int demoney(int money); +int deumoney(int uid, int money); +int lockutmpmode(int unmode, int state); +int unlockutmpmode(); +int p_touch_boards(); +int x_file(); +int give_money(); +int p_sysinfo(); +int p_give(); +int p_cloak(); +int p_from(); +int ordersong(); +int p_exmail(); +void mail_redenvelop(char* from, char* to, int money, char mode); + +/* card */ +int g_card_jack(); +int g_ten_helf(); +int card_99(); + +/* chat */ +int t_chat(); + +/* chc_draw */ +void chc_drawline(board_t board, int line); +void chc_movecur(int r, int c); +void chc_redraw(board_t board); + +/* chc_net */ +void chc_sendmove(int s); +int chc_recvmove(int s); + +/* chc_play */ +void chc(int s); + +/* chc_rule */ +void chc_movechess(board_t board); +int chc_canmove(board_t board, rc_t from, rc_t to); +int chc_iskfk(board_t board); +int chc_ischeck(board_t board, int turn); +void chc_init_board(board_t board); + +/* chicken */ +int show_file(char *filename, int y, int lines, int mode); +void ch_buyitem(int money, char *picture, int *item); +int chicken_main(); +int chickenpk(int fd); +void time_diff(chicken_t *thechicken); +int isdeadth(chicken_t *thechicken); +void show_chicken_data(chicken_t *thechicken, chicken_t *pkchicken); +int reload_chicken(); + +/* dark */ +int main_dark(int fd,userinfo_t *uin); + +/* dice */ +int IsSNum(char *a); +int dice_main(); +int IsNum(char *a, int n); + +/* edit */ +int vedit(char *fpath, int saveheader, int *islocal); +void write_header(FILE *fp); +void addsignature(FILE *fp, int ifuseanony); +void auto_backup(); +void restore_backup(); +char *ask_tmpbuf(int y); +char *strcasestr(const char* big, const char* little); + +/* friend */ +void friend_edit(int type); +void friend_load(); +int t_override(); +int t_reject(); +void friend_add(char *uident, int type); +void friend_delete(char *uident, int type); + +/* gamble */ +int ticket_main(); +int post_msg(char* bname, char* title, char *msg, char* author); +int openticket(int bid); +int ticket(int bid); + +/* gomo */ +int gomoku(int fd); + +/* gomo1 */ +int getstyle(int x, int y, int color, int limit); +int chkwin(int style, int limit); + +/* guess */ +int guess_main(); + +/* indict */ +int x_dict(); +int use_dict(); + +/* io */ +int getdata(int line, int col, char *prompt, char *buf, int len, int echo); +int igetch(); +int getdata_str(int line, int col, char *prompt, char *buf, int len, int echo, char *defaultstr); +int getdata_buf(int line, int col, char *prompt, char *buf, int len, int echo); +int i_get_key(); +void add_io(int fd, int timeout); +int igetkey(); +void oflush(); +int oldgetdata(int line, int col, char *prompt, char *buf, int len, int echo); +void output(char *s, int len); +void init_alarm(); +int num_in_buf(); +int ochar(int c); + +/* kaede */ +int Rename(char* src, char* dst); +int Link(char* src, char* dst); +char *Ptt_prints(char *str, int mode); +char *my_ctime(const time_t *t); + +/* lovepaper */ +int x_love(); + +/* mail */ +int load_mailalert(char *userid); +int mail_muser(userec_t muser, char *title, char *filename); +int mail_id(char* id, char *title, char *filename, char *owner); +int m_read(); +int doforward(char *direct, fileheader_t *fh, int mode); +int mail_reply(int ent, fileheader_t *fhdr, char *direct); +int bsmtp(char *fpath, char *title, char *rcpt, int method); +void hold_mail(char *fpath, char *receiver); +int chkmail(int rechk); +void m_init(); +int chkmailbox(); +int mail_man(); +int m_new(); +int m_send(); +int mail_list(); +int setforward(); +int m_internet(); +int mail_mbox(); +int built_mail_index(); +int mail_all(); +int invalidaddr(char *addr); +int do_send(char *userid, char *title); +void my_send(char *uident); + +/* mbbsd */ +void log_usies(char *mode, char *mesg); +void log_user(char *msg); +void abort_bbs(int sig); +void del_distinct(char *fname, char *line); +void add_distinct(char *fname, char *line); +void show_last_call_in(int save); +int dosearchuser(char *userid); +void u_exit(char *mode); + +/* menu */ +void showtitle(char *title, char *mid); +int egetch(); +void movie(int i); +void domenu(int cmdmode, char *cmdtitle, int cmd, commands_t cmdtable[]); + +/* more */ +int more(char *fpath, int promptend); + +/* name */ +void usercomplete(char *prompt, char *data); +void namecomplete(char *prompt, char *data); +void AddNameList(char *name); +void CreateNameList(); +int chkstr(char *otag, char *tag, char *name); +int InNameList(char *name); +void ShowNameList(int row, int column, char *prompt); +int RemoveNameList(char *name); +void ToggleNameList(int *reciper, char *listfile, char *msg); + +/* osdep */ +int cpuload(char *str); +double swapused(long *total, long *used); + +/* othello */ +int othello_main(); + +/* page */ +int main_railway(); + +/* read */ +void z_download(char *fpath); +void i_read(int cmdmode, char *direct, void (*dotitle)(), void (*doentry)(), onekey_t *rcmdlist, int bidcache); +void fixkeep(char *s, int first); +keeploc_t *getkeep(char *s, int def_topline, int def_cursline); +int Tagger(time_t chrono, int recno, int mode); + +/* record */ +int substitute_record(char *fpath, void *rptr, int size, int id); +int get_record(char *fpath, void *rptr, int size, int id); +void prints(char *fmt, ...); +int append_record(char *fpath, fileheader_t *record, int size); +int stampfile(char *fpath, fileheader_t *fh); +void stampdir(char *fpath, fileheader_t *fh); +int get_num_records(char *fpath, int size); +int get_records(char *fpath, void *rptr, int size, int id, int number); +void stamplink(char *fpath, fileheader_t *fh); +int delete_record(char fpath[], int size, int id); +int delete_files(char* dirname, int (*filecheck)(), int record); +int delete_file(char *dirname, int size, int ent, int (*filecheck)()); +int delete_range(char *fpath, int id1, int id2); +int apply_record(char *fpath, int (*fptr)(), int size); +int search_rec(char* dirname, int (*filecheck)()); +int do_append(char *fpath, fileheader_t *record, int size); +int get_sum_records(char* fpath, int size); + +/* register */ +int getnewuserid(); +int bad_user_id(char *userid); +void new_register(); +int checkpasswd(char *passwd, char *test); +void check_register(); +char *genpasswd(char *pw); + +/* screen */ +void move(int y, int x); +void outs(char *str); +void clrtoeol(); +void clear(); +void refresh(); +void clrtobot(); +void mprints(int y, int x, char *str); +void outmsg(char *msg); +void region_scroll_up(int top, int bottom); +void outc(unsigned char ch); +void redoscr(); +void clrtoline(int line); +void standout(); +void standend(); +int edit_outs(char *text); +void outch(unsigned char c); +void rscroll(); +void scroll(); +void getyx(int *y, int *x); +void initscr(); +void Jaky_outs(char *str, int line); + +/* stuff */ +void setcalfile(char *buf, char *userid); +void stand_title(char *title); +void pressanykey(); +int vmsg (const char *fmt,...); +void trim(char *buf); +void bell(); +void setbpath(char *buf, char *boardname); +int dashf(char *fname); +void sethomepath(char *buf, char *userid); +void sethomedir(char *buf, char *userid); +char *Cdate(time_t *clock); +void sethomefile(char *buf, char *userid, char *fname); +int log_file(char *filename,char *buf); +void str_lower(char *t, char *s); +int strstr_lower(char *str, char *tag); +int cursor_key(int row, int column); +int search_num(int ch, int max); +void setuserfile(char *buf, char *fname); +int is_BM(char *list); +long dasht(char *fname); +int dashd(char *fname); +int invalid_pname(char *str); +void setbdir(char *buf, char *boardname); +void setbfile(char *buf, char *boardname, char *fname); +int dashl(char *fname); +char *subject(char *title); +int not_alnum(char ch); +void setdirpath(char *buf, char *direct, char *fname); +int str_checksum(char *str); +void show_help(char *helptext[]); +int belong(char *filelist, char *key); +char *Cdatedate(time_t *clock); +int isprint2(char ch); +void sethomeman(char *buf, char *userid); +off_t dashs(char *fname); +void cursor_clear(int row, int column); +void cursor_show(int row, int column); +void printdash(char *mesg); +char *Cdatelite(time_t *clock); +int not_alpha(char ch); +int valid_ident(char *ident); +int userid_is_BM(char *userid, char *list); +int is_uBM(char *list, char *id); + +/* syspost */ +void post_newboard(char *bgroup, char *bname, char *bms); +void post_violatelaw(char *crime, char *police, char *reason, char *result); +void post_change_perm(int oldperm, int newperm, char *sysopid, char *userid); + +/* talk */ +int cmpwatermtime(const void *a, const void *b); +void water_scr(water_t **currwater, int which, char type); +void my_write2(void); +int t_idle(); +char *modestring(userinfo_t * uentp, int simple); +int isvisible(userinfo_t * me, userinfo_t * uentp); +int t_users(); +int cmpuids(int uid, userinfo_t * urec); +int my_write(pid_t pid, char *hint, char *id, int flag); +void t_display_new(); +void talkreply(); +int t_monitor(); +int t_pager(); +int t_query(); +int t_qchicken(); +int t_talk(); +int t_display(); +int my_query(char *uident); +int logout_friend_online(); +int login_friend_online(); +int isvisible_uid(int tuid); +int friend_stat(userinfo_t *me, userinfo_t * ui); + +/* tmpjack */ +int reg_barbq(); +int p_ticket_main(); +int j_ticket_main(); + +/* term */ +void init_tty(); +int term_init(); +void save_cursor(); +void restore_cursor(); +void do_move(int destcol, int destline); +void scroll_forward(); +void change_scroll_range(int top, int bottom); + +/* topsong */ +void sortsong(); +int topsong(); + +/* user */ +int u_editcalendar(); +void user_display(userec_t *u, int real); +void uinfo_query(userec_t *u, int real, int unum); +int showsignature(char *fname); +void mail_violatelaw(char* crime, char* police, char* reason, char* result); +void showplans(char *uid); +int u_info(); +int u_loginview(); +int u_ansi(); +int u_editplan(); +int u_editsig(); +int u_switchproverb(); +int u_editproverb(); +int u_cloak(); +int u_register(); +int u_list(); + +/* vote */ +int strip_ansi(char *buf, char *str, int mode); +void b_suckinfile(FILE *fp, char *fname); +int b_results(); +int b_vote(); +int b_vote_maintain(); +int b_closepolls(); + +/* vice */ +int vice_main(); + +/* voteboard */ +int do_voteboard(); +void do_voteboardreply(fileheader_t *fhdr); + +/* xyz */ +int m_sysop(); +int x_boardman(); +int x_note(); +int x_login(); +int x_week(); +int x_issue(); +int x_today(); +int x_yesterday(); +int x_user100(); +int x_birth(); +int x_90(); +int x_89(); +int x_88(); +int x_87(); +int x_86(); +int x_history(); +int x_weather(); +int x_stock(); +int note(); +int Goodbye(); + +/* toolkit */ +unsigned StringHash(unsigned char *s); + +/* passwd */ +int passwd_mmap(); +int passwd_update(int num, userec_t *buf); +int passwd_query(int num, userec_t *buf); +int passwd_apply(int (*fptr)(userec_t *)); +void passwd_lock(); +void passwd_unlock(); +int passwd_update_money(int num); + +/* calendar */ +int calendar(); + +#endif diff --git a/pttbbs/include/pttbbs.conf b/pttbbs/include/pttbbs.conf new file mode 100644 index 00000000..9bd4722d --- /dev/null +++ b/pttbbs/include/pttbbs.conf @@ -0,0 +1,17 @@ +/* 定義 BBS 站名位址 */ +#define BBSNAME "批踢踢實業坊" /* 中文站名 */ +#define MYHOSTNAME "ptt.csie.ntu.edu.tw" /* 網路位址 */ +#define MYIP "140.112.30.142" /* IP位址 */ +#define BBSUSER "bbs" +#define BBSUID 9999 +#define BBSGID 99 + +#define MAX_USERS 150000 +#define MAX_ACTIVE 4096 +#define MAX_CPULOAD 50 +#define MAX_FROM 512 +#define RELAY_SERVER_IP "140.112.30.143" +#define MAX_POST_MONEY 1000 +#define MAX_CHICKEN_MONEY 10000 +#define HAVE_JCEE 0 +#define TITLE_COLOR "\33[0;1;37;44m" diff --git a/pttbbs/include/pttstruct.h b/pttbbs/include/pttstruct.h new file mode 100644 index 00000000..76a196a9 --- /dev/null +++ b/pttbbs/include/pttstruct.h @@ -0,0 +1,390 @@ +/* $Id: pttstruct.h,v 1.1 2002/03/07 15:13:48 in2 Exp $ */ +#ifndef INCLUDE_STRUCT_H +#define INCLUDE_STRUCT_H + +/* 小雞的資料 */ +typedef struct chicken_t { + char name[20]; + char type; /* 物種 */ + unsigned char tech[16]; /* 技能 */ + time_t birthday; /* 生日 */ + time_t lastvisit; /* 上次照顧時間 */ + int oo; /* 補品 */ + int food; /* 食物 */ + int medicine; /* 藥品 */ + int weight; /* 體重 */ + int clean; /* 乾淨 */ + int run; /* 敏捷度 */ + int attack; /* 攻擊力 */ + int book; /* 知識 */ + int happy; /* 快樂 */ + int satis; /* 滿意度 */ + int temperament; /* 氣質 */ + int tiredstrong; /* 疲勞度 */ + int sick; /* 病氣指數 */ + int hp; /* 血量 */ + int hp_max; /* 滿血量 */ + int mm; /* 法力 */ + int mm_max; /* 滿法力 */ + time_t cbirth; /* 實際計算用的生日 */ + int pad[2]; /* 留著以後用 */ +} chicken_t; + +#define IDLEN 12 /* Length of bid/uid */ +#define PASSLEN 14 /* Length of encrypted passwd field */ +#define REGLEN 38 /* Length of registration data */ + +typedef struct userec_t { + char userid[IDLEN + 1]; + char realname[20]; + char username[24]; + char passwd[PASSLEN]; + unsigned char uflag; + unsigned int userlevel; + unsigned short numlogins; + unsigned short numposts; + time_t firstlogin; + time_t lastlogin; + char lasthost[16]; + int money; + char remoteuser[3]; /* 保留 目前沒用到的 */ + char proverb; + char email[50]; + char address[50]; + char justify[REGLEN + 1]; + unsigned char month; + unsigned char day; + unsigned char year; + unsigned char sex; + unsigned char state; + unsigned char pager; + unsigned char invisible; + unsigned int exmailbox; + chicken_t mychicken; + time_t lastsong; + unsigned int loginview; + unsigned char channel; /* 動態看板 */ + unsigned short vl_count; /* ViolateLaw counter */ + unsigned short five_win; + unsigned short five_lose; + unsigned short five_tie; + unsigned short chc_win; + unsigned short chc_lose; + unsigned short chc_tie; + int mobile; + int mind; + char ident[11]; + unsigned int uflag2; + char pad[72]; +} userec_t; +/* these are flags in userec_t.uflag */ +#define SIG_FLAG 0x3 /* signature number, 2 bits */ +#define PAGER_FLAG 0x4 /* true if pager was OFF last session */ +#define CLOAK_FLAG 0x8 /* true if cloak was ON last session */ +#define FRIEND_FLAG 0x10 /* true if show friends only */ +#define BRDSORT_FLAG 0x20 /* true if the boards sorted alphabetical */ +#define MOVIE_FLAG 0x40 /* true if show movie */ +#define COLOR_FLAG 0x80 /* true if the color mode open */ +#define MIND_FLAG 0x100 /* true if mind search mode open <-Heat*/ +/* these are flags in userec_t.uflag2 */ +#define WATER_MASK 000003 /* water mask */ +#define WATER_ORIG 0 +#define WATER_NEW 1 +#define WATER_OFO 2 +#define WATERMODE(mode) ((cuser.uflag2 & WATER_MASK) == mode) + + +#define BTLEN 48 /* Length of board title */ + +typedef struct boardheader_t { + char brdname[IDLEN + 1]; /* bid */ + char title[BTLEN + 1]; + char BM[IDLEN * 3 + 3]; /* BMs' uid, token '/' */ + unsigned int brdattr; /* board的屬性 */ + char pad[3]; /* 沒用到的 */ + time_t bupdate; /* note update time */ + char pad2[3]; /* 沒用到的 */ + unsigned char bvote; /* Vote flags */ + time_t vtime; /* Vote close time */ + unsigned int level; /* 可以看此板的權限 */ + int unused; /* 還沒用到 */ + int gid; /* 看板所屬的類別 ID */ + void *next[2]; /* 在同一個gid下一個看板 動態產生*/ + void *firstchild[2]; /* 屬於這個看板的第一個子看板 */ + void *parent; + char pad3[100]; +} boardheader_t; + +#define BRD_NOZAP 00001 /* 不可zap */ +#define BRD_NOCOUNT 00002 /* 不列入統計 */ +#define BRD_NOTRAN 00004 /* 不轉信 */ +#define BRD_GROUPBOARD 00010 /* 群組板 */ +#define BRD_HIDE 00020 /* 隱藏板 (看板好友才可看) */ +#define BRD_POSTMASK 00040 /* 限制發表或閱讀 */ +#define BRD_ANONYMOUS 00100 /* 匿名板? */ +#define BRD_DEFAULTANONYMOUS 00200 /* 預設匿名板 */ +#define BRD_BAD 00400 /* 違法改進中看板 */ +#define BRD_VOTEBOARD 01000 /* 連署機看板 */ +#define BRD_WARNDEL 02000 /* 已警告要廢除的看板 */ + +#define TTLEN 64 /* Length of title */ +#define FNLEN 33 /* Length of filename */ + +#define FHR_REFERENCE (1<<31) + +typedef struct fileheader_t { + char filename[FNLEN]; /* M.9876543210.A */ + char savemode; /* file save mode */ + char owner[IDLEN + 2]; /* uid[.] */ + char date[6]; /* [02/02] or space(5) */ + char title[TTLEN + 1]; + int money; /* rocker: if bit32 on ==> reference */ + unsigned char filemode; /* must be last field @ boards.c */ +} fileheader_t; + +#define FILE_LOCAL 0x1 /* local saved */ +#define FILE_READ 0x1 /* already read : mail only */ +#define FILE_MARKED 0x2 /* opus: 0x8 */ +#define FILE_DIGEST 0x4 /* digest */ +#define FILE_SOLVED 0x10 /* problem solved, sysop only */ +#define FILE_HIDE 0x20 /* hild */ +#define FILE_BM 0x40 /* BM only */ + +#define STRLEN 80 /* Length of most string data */ + + +/* uhash is a userid->uid hash table -- jochang */ + +#define HASH_BITS 16 +typedef struct uhash_t { + char userid[MAX_USERS][IDLEN + 1]; + int next_in_hash[MAX_USERS]; + int money[MAX_USERS]; + int hash_head[1 << HASH_BITS]; + int number; /* # of users total */ + int loaded; /* .PASSWD has been loaded? */ + int hbfl[MAX_BOARD][MAX_FRIEND + 1]; +} uhash_t; + +union xitem_t { + struct { /* bbs_item */ + char fdate[9]; /* [mm/dd/yy] */ + char editor[13]; /* user ID */ + char fname[31]; + } B; + struct { /* gopher_item */ + char path[81]; + char server[48]; + int port; + } G; +}; + +typedef struct { + char title[63]; + union xitem_t X; +} item_t; + +typedef struct { + item_t *item[MAX_ITEMS]; + char mtitle[STRLEN]; + char *path; + int num, page, now, level; +} gmenu_t; + +typedef struct msgque_t { + pid_t pid; + char userid[IDLEN + 1]; + char last_call_in[80]; +} msgque_t; + +typedef struct water_t { + pid_t pid; + char userid[IDLEN + 1]; + msgque_t msg[MAX_REVIEW]; + int top, count; +} water_t; + +#define FAVMAX 74 /* Max boards of Myfavorite */ +#define FAVGMAX 16 /* Max groups of Myfavorite */ +#define FAVGSLEN 8 /* Max Length of Description String */ + +typedef struct userinfo_t { + int uid; /* Used to find user name in passwd file */ + pid_t pid; /* kill() to notify user of talk request */ + int sockaddr; /* ... */ + int destuid; /* talk uses this to identify who called */ + int destuip; /* dest index in utmpshm->uinfo[] */ + unsigned char active; /* When allocated this field is true */ + unsigned char invisible; /* Used by cloaking function in Xyz menu */ + unsigned char sockactive; /* Used to coordinate talk requests */ + unsigned int userlevel; + unsigned char mode; /* UL/DL, Talk Mode, Chat Mode, ... */ + unsigned char pager; /* pager toggle, YEA, or NA */ + unsigned char in_chat; /* for in_chat commands */ + unsigned char sig; /* signal type */ + char userid[IDLEN + 1]; + char chatid[11]; /* chat id, if in chat mode */ + char realname[20]; + char username[24]; + char from[27]; /* machine name the user called in from */ + int from_alias; + char birth; /* 是否是生日 Ptt*/ + char tty[11]; /* tty port */ + int friend[MAX_FRIEND]; + int friend_online[MAX_FRIEND]; /* point到線上好友 utmpshm的位置 */ + /* 好友比較的cache 前兩個bit是狀態 */ + int reject[MAX_REJECT]; + int pad[3]; + int friendtotal; /* 好友比較的cache 大小 */ + unsigned char msgcount; + msgque_t msgs[MAX_MSGS]; + time_t uptime; + time_t lastact; /* 上次使用者動的時間 */ + unsigned int brc_id; + unsigned char lockmode; /* 不准 multi_login 玩的東西 */ + char turn; /* for gomo */ + char mateid[IDLEN + 1]; /* for gomo */ + unsigned short int five_win; + unsigned short int five_lose; + unsigned short int five_tie; + int myfavorite[FAVMAX]; + char gfavorite[FAVGMAX][FAVGSLEN+1]; + int ninGroup[FAVGMAX]; + int nGroup; + int ninRoot; + int mailalert; + int sex; + char color; + int mind; +} userinfo_t; + +typedef struct { + fileheader_t *header; + char mtitle[STRLEN]; + char *path; + int num, page, now, level; +} menu_t; + +typedef struct onekey_t { /* Used to pass commands to the readmenu */ + int key; + int (*fptr)(); +} onekey_t; + +#define ANSILINELEN (511) /* Maximum Screen width in chars */ + +/* anti_crosspost */ +typedef struct crosspost_t { + int checksum[4]; /* 0 -> 'X' cross post 1-3 -> 簡查文章行 */ + int times; /* 第幾次 */ +} crosspost_t; + +#define SORT_BY_ID 0 +#define SORT_BY_CLASS 1 +#define SORT_BY_STAT 1 +#define SORT_BY_IDLE 2 +#define SORT_BY_FROM 3 +#define SORT_BY_FIVE 4 +#define SORT_BY_SEX 5 + +typedef struct bcache_t { + boardheader_t bcache[MAX_BOARD]; + boardheader_t *sorted[2][MAX_BOARD]; /* 0: by name 1: by class */ + fileheader_t dircache[MAX_BOARD][DIRCACHESIZE]; + int cachetotal[MAX_BOARD]; + int total[MAX_BOARD]; + time_t lastposttime[MAX_BOARD]; + time_t uptime; + time_t touchtime; + int number; + int busystate; +} bcache_t; + +typedef struct keeploc_t { + char *key; + int top_ln; + int crs_ln; + struct keeploc_t *next; +} keeploc_t; + +#define USHM_SIZE (MAX_ACTIVE + 4) /* why+4? */ + +struct utmpfile_t { + userinfo_t uinfo[USHM_SIZE]; + userinfo_t *sorted[2][8][USHM_SIZE]; + /* 第一維double buffer 由currsorted指向目前使用的 + 第二維sort type */ + int currsorted; + time_t uptime; + int number; + int busystate; +}; + +struct pttcache_t { + char notes[MAX_MOVIE][200*11]; + char today_is[20]; + int n_notes[MAX_MOVIE_SECTION]; /* 一節中有幾個 看板 */ + int next_refresh[MAX_MOVIE_SECTION]; /* 下一次要refresh的 看板 */ + int max_film; + int max_history; + time_t uptime; + time_t touchtime; + int busystate; +}; + +typedef struct fromcache_t { + char domain[MAX_FROM][50]; + char replace[MAX_FROM][50]; + int top; + int max_user; + time_t max_time; + time_t uptime; + time_t touchtime; + int busystate; +} fromcache_t; + +typedef struct { + unsigned char oldlen; /* previous line length */ + unsigned char len; /* current length of line */ + unsigned char mode; /* status of line, as far as update */ + unsigned char smod; /* start of modified data */ + unsigned char emod; /* end of modified data */ + unsigned char sso; /* start stand out */ + unsigned char eso; /* end stand out */ + unsigned char data[ANSILINELEN + 1]; +} screenline_t; + +typedef struct { + int r, c; +} rc_t; + +#define BRD_ROW 10 +#define BRD_COL 9 + +typedef int board_t[BRD_ROW][BRD_COL]; + +/* name.c 中運用的資料結構 */ +typedef struct word_t { + char *word; + struct word_t *next; +} word_t; + +typedef struct commands_t { + int (*cmdfunc)(); + int level; + char *desc; /* next/key/description */ +} commands_t; + +typedef struct MailQueue { + char filepath[FNLEN]; + char subject[STRLEN]; + time_t mailtime; + char sender[IDLEN + 1]; + char username[24]; + char rcpt[50]; + int method; + char * niamod; +} MailQueue; + +enum {MQ_TEXT, MQ_UUENCODE, MQ_JUSTIFY}; + +#endif diff --git a/pttbbs/include/pttstruct.h.save b/pttbbs/include/pttstruct.h.save new file mode 100644 index 00000000..f73f6413 --- /dev/null +++ b/pttbbs/include/pttstruct.h.save @@ -0,0 +1,363 @@ +/* $Id: pttstruct.h.save,v 1.1 2002/03/07 15:13:48 in2 Exp $ */ +~#ifndef INCLUDE_STRUCT_H +#define INCLUDE_STRUCT_H + +/* 小雞的資料 */ +typedef struct chicken_t { + char name[20]; + char type; /* 物種 */ + unsigned char tech[16]; /* 技能 */ + time_t birthday; /* 生日 */ + time_t lastvisit; /* 上次照顧時間 */ + int oo; /* 補品 */ + int food; /* 食物 */ + int medicine; /* 藥品 */ + int weight; /* 體重 */ + int clean; /* 乾淨 */ + int run; /* 敏捷度 */ + int attack; /* 攻擊力 */ + int book; /* 知識 */ + int happy; /* 快樂 */ + int satis; /* 滿意度 */ + int temperament; /* 氣質 */ + int tiredstrong; /* 疲勞度 */ + int sick; /* 病氣指數 */ + int hp; /* 血量 */ + int hp_max; /* 滿血量 */ + int mm; /* 法力 */ + int mm_max; /* 滿法力 */ + time_t cbirth; /* 實際計算用的生日 */ + int pad[2]; /* 留著以後用 */ +} chicken_t; + +#define IDLEN 12 /* Length of bid/uid */ +#define PASSLEN 14 /* Length of encrypted passwd field */ +#define REGLEN 38 /* Length of registration data */ + +typedef struct userec_t { + char userid[IDLEN + 1]; + char realname[20]; + char username[24]; + char passwd[PASSLEN]; + unsigned char uflag; + unsigned int userlevel; + unsigned short numlogins; + unsigned short numposts; + time_t firstlogin; + time_t lastlogin; + char lasthost[16]; + int money; + char remoteuser[3]; /* 保留 目前沒用到的 */ + char proverb; + char email[50]; + char address[50]; + char justify[REGLEN + 1]; + unsigned char month; + unsigned char day; + unsigned char year; + unsigned char sex; + unsigned char state; + unsigned char pager; + unsigned char invisible; + unsigned int exmailbox; + chicken_t mychicken; + time_t lastsong; + unsigned int loginview; + unsigned char channel; /* 動態看板 */ + unsigned short vl_count; /* ViolateLaw counter */ + unsigned short five_win; + unsigned short five_lose; + unsigned short five_tie; + unsigned short chc_win; + unsigned short chc_lose; + unsigned short chc_tie; + char pad[95]; +} userec_t; +/* these are flags in userec_t.uflag */ +#define SIG_FLAG 0x3 /* signature number, 2 bits */ +#define PAGER_FLAG 0x4 /* true if pager was OFF last session */ +#define CLOAK_FLAG 0x8 /* true if cloak was ON last session */ +#define FRIEND_FLAG 0x10 /* true if show friends only */ +#define BRDSORT_FLAG 0x20 /* true if the boards sorted alphabetical */ +#define MOVIE_FLAG 0x40 /* true if show movie */ +#define COLOR_FLAG 0x80 /* true if the color mode open */ +#define MIND_FLAG 0x100 /* true if mind search mode open <-Heat*/ + +#define BTLEN 48 /* Length of board title */ + +typedef struct boardheader_t { + char brdname[IDLEN + 1]; /* bid */ + char title[BTLEN + 1]; + char BM[IDLEN * 3 + 3]; /* BMs' uid, token '/' */ + unsigned int brdattr; /* board的屬性 */ + char pad[3]; /* 沒用到的 */ + time_t bupdate; /* note update time */ + char pad2[3]; /* 沒用到的 */ + unsigned char bvote; /* Vote flags */ + time_t vtime; /* Vote close time */ + unsigned int level; /* 可以看此板的權限 */ + int uid; /* 看板的類別 ID */ + int gid; /* 看板所屬的類別 ID */ + void *next[2]; /* 在同一個gid下一個看板 動態產生*/ + void *firstchild[2]; /* 屬於這個看板的第一個子看板 */ + void *parent; + char pad3[100]; +} boardheader_t; + +#define BRD_NOZAP 00001 /* 不可zap */ +#define BRD_NOCOUNT 00002 /* 不列入統計 */ +#define BRD_NOTRAN 00004 /* 不轉信 */ +#define BRD_GROUPBOARD 00010 /* 群組板 */ +#define BRD_HIDE 00020 /* 隱藏板 (看板好友才可看) */ +#define BRD_POSTMASK 00040 /* 限制發表或閱讀 */ +#define BRD_ANONYMOUS 00100 /* 匿名板? */ +#define BRD_DEFAULTANONYMOUS 00200 /* 預設匿名板 */ +#define BRD_BAD 00400 /* 違法改進中看板 */ +#define BRD_VOTEBOARD 01000 /* 連署機看板 */ + +#define TTLEN 64 /* Length of title */ +#define FNLEN 33 /* Length of filename */ + +#define FHR_REFERENCE (1<<31) + +typedef struct fileheader_t { + char filename[FNLEN]; /* M.9876543210.A */ + char savemode; /* file save mode */ + char owner[IDLEN + 2]; /* uid[.] */ + char date[6]; /* [02/02] or space(5) */ + char title[TTLEN + 1]; + int money; /* rocker: if bit32 on ==> reference */ + unsigned char filemode; /* must be last field @ boards.c */ +} fileheader_t; + +#define FILE_LOCAL 0x1 /* local saved */ +#define FILE_READ 0x1 /* already read : mail only */ +#define FILE_MARKED 0x2 /* opus: 0x8 */ +#define FILE_DIGEST 0x4 /* digest */ +#define FILE_TAGED 0x8 /* taged */ +#define FILE_SOLVED 0x10 /* problem solved, sysop only */ + +#define STRLEN 80 /* Length of most string data */ + + +/* uhash is a userid->uid hash table -- jochang */ + +#define HASH_BITS 16 +typedef struct uhash_t { + char userid[MAX_USERS][IDLEN + 1]; + int money[MAX_USERS]; + int next_in_hash[MAX_USERS]; + int hash_head[1 << HASH_BITS]; + int number; /* # of users total */ + int loaded; /* .PASSWD has been loaded? */ +} uhash_t; + +union xitem_t { + struct { /* bbs_item */ + char fdate[9]; /* [mm/dd/yy] */ + char editor[13]; /* user ID */ + char fname[31]; + } B; + struct { /* gopher_item */ + char path[81]; + char server[48]; + int port; + } G; +}; + +typedef struct { + char title[63]; + union xitem_t X; +} item_t; + +typedef struct { + item_t *item[MAX_ITEMS]; + char mtitle[STRLEN]; + char *path; + int num, page, now, level; +} gmenu_t; + +typedef struct msgque_t { + pid_t last_pid; + char last_userid[IDLEN + 1]; + char last_call_in[80]; +} msgque_t; + +#define FAVMAX 74 /* Max boards of Myfavorite */ +#define FAVGMAX 16 /* Max groups of Myfavorite */ +#define FAVGSLEN 8 /* Max Length of Description String */ + +typedef struct userinfo_t { + int uid; /* Used to find user name in passwd file */ + pid_t pid; /* kill() to notify user of talk request */ + int sockaddr; /* ... */ + int destuid; /* talk uses this to identify who called */ + int destuip; /* dest index in utmpshm->uinfo[] */ + unsigned char active; /* When allocated this field is true */ + unsigned char invisible; /* Used by cloaking function in Xyz menu */ + unsigned char sockactive; /* Used to coordinate talk requests */ + unsigned int userlevel; + unsigned char mode; /* UL/DL, Talk Mode, Chat Mode, ... */ + unsigned char pager; /* pager toggle, YEA, or NA */ + unsigned char in_chat; /* for in_chat commands */ + unsigned char sig; /* signal type */ + char userid[IDLEN + 1]; + char chatid[11]; /* chat id, if in chat mode */ + char realname[20]; + char username[24]; + char from[27]; /* machine name the user called in from */ + int from_alias; + char birth; /* 是否是生日 Ptt*/ + char tty[11]; /* tty port */ + int friend[MAX_FRIEND]; + void *friend_online[MAX_FRIEND]; /* point到線上好友 */ + int friend_state[MAX_FRIEND]; /* 對應到friend_online的狀態 */ + int reject[MAX_REJECT]; + unsigned char msgcount; + msgque_t msgs[MAX_MSGS]; + time_t uptime; + time_t lastact; /* 上次使用者動的時間 */ + unsigned int brc_id; + unsigned char lockmode; /* 不准 multi_login 玩的東西 */ + char turn; /* for gomo */ + char mateid[IDLEN + 1]; /* for gomo */ + unsigned short int five_win; + unsigned short int five_lose; + unsigned short int five_tie; + int myfavorite[FAVMAX]; + char gfavorite[FAVGMAX][FAVGSLEN+1]; + int ninGroup[FAVGMAX]; + int nGroup; + int ninRoot; + int mailalert; + int sex; + char color; + int mind; +} userinfo_t; + +typedef struct { + fileheader_t *header; + char mtitle[STRLEN]; + char *path; + int num, page, now, level; +} menu_t; + +typedef struct onekey_t { /* Used to pass commands to the readmenu */ + int key; + int (*fptr)(); +} onekey_t; + +#define ANSILINELEN (511) /* Maximum Screen width in chars */ + +/* anti_crosspost */ +typedef struct crosspost_t { + int checksum[4]; /* 0 -> 'X' cross post 1-3 -> 簡查文章行 */ + int times; /* 第幾次 */ +} crosspost_t; + +#define SORT_BY_ID 0 +#define SORT_BY_CLASS 1 +#define SORT_BY_STAT 1 +#define SORT_BY_IDLE 2 +#define SORT_BY_FROM 3 +#define SORT_BY_FIVE 4 +#define SORT_BY_SEX 5 + +typedef struct bcache_t { + boardheader_t bcache[MAX_BOARD]; + boardheader_t *sorted[2][MAX_BOARD]; /* 0: by name 1: by class */ + fileheader_t dircache[MAX_BOARD][DIRCACHESIZE]; + unsigned int total[MAX_BOARD]; + time_t lastposttime[MAX_BOARD]; + time_t uptime; + time_t touchtime; + int number; + int busystate; +} bcache_t; + +typedef struct keeploc_t { + char *key; + int top_ln; + int crs_ln; + struct keeploc_t *next; +} keeploc_t; + +#define USHM_SIZE (MAX_ACTIVE + 4) /* why+4? */ + +struct utmpfile_t { + userinfo_t uinfo[USHM_SIZE]; + userinfo_t *sorted[8][USHM_SIZE]; + time_t uptime; + int number; + int busystate; +}; + +struct pttcache_t { + char notes[MAX_MOVIE][200*11]; + char today_is[20]; + int n_notes[MAX_MOVIE_SECTION]; /* 一節中有幾個 看板 */ + int next_refresh[MAX_MOVIE_SECTION]; /* 下一次要refresh的 看板 */ + int max_film; + int max_history; + time_t uptime; + time_t touchtime; + int busystate; +}; + +typedef struct fromcache_t { + char domain[MAX_FROM][50]; + char replace[MAX_FROM][50]; + int top; + int max_user; + time_t max_time; + time_t uptime; + time_t touchtime; + int busystate; +} fromcache_t; + +typedef struct { + unsigned char oldlen; /* previous line length */ + unsigned char len; /* current length of line */ + unsigned char mode; /* status of line, as far as update */ + unsigned char smod; /* start of modified data */ + unsigned char emod; /* end of modified data */ + unsigned char sso; /* start stand out */ + unsigned char eso; /* end stand out */ + unsigned char data[ANSILINELEN + 1]; +} screenline_t; + +typedef struct { + int r, c; +} rc_t; + +#define BRD_ROW 10 +#define BRD_COL 9 + +typedef int board_t[BRD_ROW][BRD_COL]; + +/* name.c 中運用的資料結構 */ +typedef struct word_t { + char *word; + struct word_t *next; +} word_t; + +typedef struct commands_t { + int (*cmdfunc)(); + int level; + char *desc; /* next/key/description */ +} commands_t; + +typedef struct MailQueue { + char filepath[FNLEN]; + char subject[STRLEN]; + time_t mailtime; + char sender[IDLEN + 1]; + char username[24]; + char rcpt[50]; + int method; + char * niamod; +} MailQueue; + +enum {MQ_TEXT, MQ_UUENCODE, MQ_JUSTIFY}; + +#endif diff --git a/pttbbs/innbbsd/.cvsignore b/pttbbs/innbbsd/.cvsignore new file mode 100644 index 00000000..91b3d99d --- /dev/null +++ b/pttbbs/innbbsd/.cvsignore @@ -0,0 +1,6 @@ +bbslink +bbsnnrp +ctlinnbbsd +innbbsd +mkhistory +*.o diff --git a/pttbbs/innbbsd/Makefile b/pttbbs/innbbsd/Makefile new file mode 100644 index 00000000..fb82be2a --- /dev/null +++ b/pttbbs/innbbsd/Makefile @@ -0,0 +1,206 @@ +# ------------------------------------------------------- # +# innbbsd/Makefile ( NTHU CS MapleBBS Ver 2.36 ) # +# ------------------------------------------------------- # +# target : Makefile for 轉信程式 innbbsd by skhuang # +# create : 95/03/29 # +# update : 95/12/15 # +# ------------------------------------------------------- # + +#################################################### +# this is a bbs <--> news gateway +##################################################### +VERSION=0.50beta-4 +LASTVERSION=0.50beta-3 +ADMINUSER= root@your.domain.name +BBSHOME?=$(HOME) +BBS_SRC = .. +TARGET = $(INNBBSD) $(BBSNNRP) $(BBSLINK) +#################################################### +CC=gcc +INSTALL=cp +# +OPT= -O3 -s -pipe -fomit-frame-pointer -g + +BBS_DEP = MapleBBS +BBS_UTIL = $(BBS_SRC)/util +BBS_REC = $(BBS_UTIL)/util_record.o $(BBS_UTIL)/util_cache.o $(BBS_UTIL)/util_passwd.o + +######################### +# +############### +DEBUGOBJ = /usr/lib/debug/mallocmap.o +CFLAGS= -c -I. -I$(BBS_SRC)/include -I$(BBS_SRC)/mbbsd -D$(BBS_DEP) \ +$(EXTRAFLAGS) -DDBZDEBUG -DBBSHOME='"$(BBSHOME)"' \ +-D_PATH_BBSHOME=\"$(BBSHOME)\" \ +-DVERSION=\"$(VERSION)\" -DADMINUSER=\"$(ADMINUSER)\" +# +#################################################### + +OBJS = inndchannel.o innbbsd.o connectsock.o rfc931.o \ + daemon.o file.o pmain.o his.o dbz.o \ + closeonexec.o dbztool.o inntobbs.o receive_article.o \ + echobbslib.o $(BBS_REC) + # $(BBS_REC) +SRCS = inndchannel.c innbbsd.c connectsock.c rfc931.c \ + daemon.c file.c pmain.c parsdate.y his.c dbz.c \ + closeonexec.c dbztool.c inntobbs.c bbslib.c receive_article.c \ + port.c + +MOBJS = makedbz.o bbslib.o file.o dbz.o closeonexec.o +HOBJS = mkhistory.o bbslib.o file.o his.o dbz.o port.o closeonexec.o +DBZOBJS = dbzserver.o dbzinnbbsd.o pmain.o connectsock.o bbslib.o his.o \ + daemon.o file.o dbz.o dbztool.o rfc931.o port.o closeonexec.o \ + morelog.o +NNRPOBJS = bbsnnrp.o pmain.o bbslib.o connectsock.o file.o +LINKOBJS = bbslink.o pmain.o inntobbs.o echobbslib.o connectsock.o file.o port.o +LINKOBJS2 = bbslink2.o pmain.o inntobbs.o echobbslib.o connectsock.o file.o port.o +CTLOBJS = ctlinnbbsd.o pmain.o bbslib.o connectsock.o file.o +INNBBSD = innbbsd mkhistory bbsnnrp ctlinnbbsd $(BBSLINK) +BBSNNRP = bbsnnrp +BBSLINK = bbslink +BBSLINK2 = bbslink2 +EXES = $(TARGET) + +.c.o: + $(CC) $(OPT) $(CFLAGS) $*.c + + +all: $(OSTYPE) + +sun: + @$(MAKE) EXTRAFLAGS="-DMMAP -DGETRUSAGE -DMALLOCMAP" LDFLAGS="$(DEBUGOBJ)" target + + +aix: + @$(MAKE) CC=cc EXTRAFLAGS="-DMMAP -DGETRUSAGE -DAIX -DSYSV" target + +linux: + @$(MAKE) EXTRAFLAGS="-DLINUX -DGETRUSAGE" target + +hpux: + @$(MAKE) OPT= EXTRAFLAGS="-DMMAP -DHPUX -DSYSV" target + +irix: + @$(MAKE) EXTRAFLAGS="-DMMAP -DIRIX -DSYSV" target + +solaris: + @$(MAKE) EXTRAFLAGS="-DMMAP -DSOLARIS -DSYSV" LDFLAGS="-lsocket -lnsl" YACC="bison -y" target + +FreeBSD: + @$(MAKE) CC=cc EXTRAFLAGS="-DBSD44 -DMMAP -DGETRUSAGE" LIBCRYPT=-lcrypt target + +bsd: + @$(MAKE) CC=cc EXTRAFLAGS="-DMMAP -DGETRUSAGE" target + +alpha: + @$(MAKE) CC=cc EXTRAFLAGS="-DMMAP -DDEC_ALPHA -DGETRUSAGE" target + +sysv: + @$(MAKE) OPT= EXTRAFLAGS="-DMMAP -DSYSV" target + +target: $(EXES) + +r_port.o: r_port.c + $(CC) $(OPT) $(CFLAGS) -DWITH_RECORD_O r_port.c + +echobbslib.o: echobbslib.c + $(CC) $(OPT) $(CFLAGS) -DWITH_ECHOMAIL echobbslib.c + +tar: + test -d innbbsd-$(VERSION) || mkdir innbbsd-$(VERSION) + cp *.c *.h Makefile innbbsd-$(VERSION) + tar zcf innbbsd-$(VERSION).tar.gz innbbsd-$(VERSION) + cp innbbsd-$(VERSION).tar.gz /net/ftphome/CSIE/innbbsd + +patch: + rm -rf /tmp/innbbsd-$(LASTVERSION) + zcat /net/ftphome/ftp-data/bbs/misc/innbbsd/innbbsd-$(LASTVERSION).tar.gz | (cd /tmp; tar xf -) + (cd /tmp/innbbsd-$(VERSION); make clean; rm -f r_port.c dbzserver.c dbzinnbbsd.c echobbslib.c ) + (cd /tmp/innbbsd-$(LASTVERSION); make clean; rm -f r_port.c dbzserver.c dbzinnbbsd.c echobbslib.c ) + (cd /tmp; diff -rcs innbbsd-$(LASTVERSION) innbbsd-$(VERSION) > /tmp/innbbsd-patch.$(LASTVERSION)-$(VERSION); echo "diff -rcs") + (cd /tmp/innbbsd-$(VERSION); ln -s port.c r_port.c) + (cd /tmp/innbbsd-$(VERSION); ln -s inndchannel.c dbzserver.c) + (cd /tmp/innbbsd-$(VERSION); ln -s innbbsd.c dbzinnbbsd.c) + (cd /tmp/innbbsd-$(VERSION); ln -s bbslib.c echobbslib.c) + + +distribution: + rm -rf /tmp/innbbsd-$(VERSION) + test -d /tmp/innbbsd-$(VERSION) || mkdir /tmp/innbbsd-$(VERSION) + test -d /tmp/innbbsd-$(VERSION)/innd || mkdir /tmp/innbbsd-$(VERSION)/innd + rm -f r_port.c + rm -f dbzserver.c + rm -f dbzinnbbsd.c + rm -f echobbslib.c + cp -r doc hisconvert FEATURES CHANGES README* TODO *.c *.h *.y Makefile boards /tmp/innbbsd-$(VERSION) + (cd /tmp/innbbsd-$(VERSION); ln -s port.c r_port.c) + (cd /tmp/innbbsd-$(VERSION); ln -s inndchannel.c dbzserver.c) + (cd /tmp/innbbsd-$(VERSION); ln -s innbbsd.c dbzinnbbsd.c) + (cd /tmp/innbbsd-$(VERSION); ln -s bbslib.c echobbslib.c) + (cd innd ; cp -r Makefile README innbbs.conf in.bntpd mailpost *.pl bntplink bntplink.palmbbs *.active* *.c *.y *.bbs src /tmp/innbbsd-$(VERSION)/innd) + (cd /tmp/innbbsd-$(VERSION); make clean) + (cd /tmp; tar zcf innbbsd-$(VERSION).tar.gz innbbsd-$(VERSION) ) + ln -s port.c r_port.c + ln -s inndchannel.c dbzserver.c + ln -s innbbsd.c dbzinnbbsd.c + ln -s bbslib.c echobbslib.c + +remotetest: distribution + /usr/local/krb4/rcp /tmp/innbbsd-$(VERSION).tar.gz bbs_src.tar.gz skhuang:/tmp + /usr/local/krb4/rcp /tmp/innbbsd-$(VERSION).tar.gz bbs_src.tar.gz linux:/tmp + mv /u/staff/skhuang/.tcshrc /u/staff/skhuang/skhuang.tcshrc + rcp /tmp/innbbsd-$(VERSION).tar.gz bbs_src.tar.gz ccsun36:/tmp + rcp /tmp/innbbsd-$(VERSION).tar.gz bbs_src.tar.gz ccibm1:/tmp + mv /u/staff/skhuang/skhuang.tcshrc /u/staff/skhuang/.tcshrc + rcp /tmp/innbbsd-$(VERSION).tar.gz bbs_src.tar.gz cciris3:/tmp + +ftp: distribution patch + rsh ccsun42 mv /home8/ftp/pub/bbs/misc/innbbsd/innbbsd-$(VERSION).tar.gz /home8/ftp/pub/bbs/misc/innbbsd/.innbbsd-$(VERSION).tar.gz + rcp /tmp/innbbsd-$(VERSION).tar.gz ccsun42:/home8/ftp/pub/bbs/misc/innbbsd + rcp README* ccsun42:/home8/ftp/pub/bbs/misc/innbbsd + rcp /tmp/innbbsd-patch.$(LASTVERSION)-$(VERSION) ccsun42:/home8/ftp/pub/bbs/misc/innbbsd + +innbbspost.o: innbbspost.c + $(CC) $(CFLAGS) -I$(BBS_SRC) -c innbbspost.c + +makedbz: $(MOBJS) + $(CC) $(OPT) -o makedbz $(MOBJS) $(LDFLAGS) + +dbzserver.o: dbzserver.c + $(CC) $(CFLAGS) -DDBZSERVER -I$(BBS_SRC) -c dbzserver.c + +dbzinnbbsd.o: dbzinnbbsd.c + $(CC) $(CFLAGS) -DDBZSERVER -I$(BBS_SRC) -c dbzinnbbsd.c + +dbzserver: $(DBZOBJS) + $(CC) $(OPT) -o dbzserver $(DBZOBJS) $(LDFLAGS) + +bbsnnrp: $(NNRPOBJS) + $(CC) -o bbsnnrp $(NNRPOBJS) $(OPT) $(LDFLAGS) + +bbslink: $(LINKOBJS) + $(CC) -o bbslink $(LINKOBJS) $(OPT) $(LDFLAGS) + +bbslink2: $(LINKOBJS2) + $(CC) -o bbslink2 $(LINKOBJS2) $(OPT) $(LDFLAGS) + +ctlinnbbsd: $(CTLOBJS) + $(CC) $(OPT) -o ctlinnbbsd $(CTLOBJS) $(LDFLAGS) + +mkhistory: $(HOBJS) + $(CC) $(OPT) -o mkhistory $(HOBJS) $(LDFLAGS) + +dbz_query_sample: dbz_query_sample.o + $(CC) $(OPT) -o dbz_query_sample dbz_query_sample.o $(LDFLAGS) + + +innbbsd: $(OBJS) +# mv tnrpd.exe tnrpd.exe.old + $(CC) -o innbbsd $(OBJS) $(OPT) $(LDFLAGS) + +install: $(EXES) + install -d $(BBSHOME)/innd/ + install -c -m 755 $(EXES) $(BBSHOME)/innd/ + +clean: + rm -f *.o $(EXES) core innd/src/*.o diff --git a/pttbbs/innbbsd/antisplam.h b/pttbbs/innbbsd/antisplam.h new file mode 100644 index 00000000..30289da1 --- /dev/null +++ b/pttbbs/innbbsd/antisplam.h @@ -0,0 +1,37 @@ +#define char_lower(c) ((c >= 'A' && c <= 'Z') ? c|32 : c) + +/*void +str_lower(t, s) + char *t, *s;*/ +void str_lower(char *t, char *s) +{ + register char ch; + do + { + ch = *s++; + *t++ = char_lower(ch); + } while (ch); +} + +#if 0 /* string.h , libc */ +int +strcasestr(str, tag) + char *str, *tag; /* tag : lower-case string */ +{ + char buf[256]; + + str_lower(buf, str); + return (int) strstr(buf, tag); +} +#endif + +int +bad_subject(char *subject) +{ + char *badkey[] = {"無碼","avcd","mp3",NULL}; + int i; + for(i=0; badkey[i]; i++) + if(strcasestr(subject, badkey[i])) return 1; + return 0; +} + diff --git a/pttbbs/innbbsd/bbslib.c b/pttbbs/innbbsd/bbslib.c new file mode 100644 index 00000000..0dc808c3 --- /dev/null +++ b/pttbbs/innbbsd/bbslib.c @@ -0,0 +1,712 @@ +#if defined( LINUX ) +# include "innbbsconf.h" +# include "bbslib.h" +# include +#else +# include +# include "innbbsconf.h" +# include "bbslib.h" +#endif + +char INNBBSCONF[MAXPATHLEN]; +char INNDHOME[MAXPATHLEN]; +char HISTORY[MAXPATHLEN]; +char LOGFILE[MAXPATHLEN]; +char MYBBSID[MAXPATHLEN]; +char ECHOMAIL[MAXPATHLEN]; +char BBSFEEDS[MAXPATHLEN]; +char LOCALDAEMON[MAXPATHLEN]; + +int His_Maint_Min= HIS_MAINT_MIN; +int His_Maint_Hour= HIS_MAINT_HOUR; +int Expiredays = EXPIREDAYS; + +nodelist_t *NODELIST=NULL, **NODELIST_BYNODE=NULL; +newsfeeds_t *NEWSFEEDS=NULL, **NEWSFEEDS_BYBOARD=NULL; +static char *NODELIST_BUF, *NEWSFEEDS_BUF; +int NFCOUNT, NLCOUNT; +int LOCALNODELIST=0, NONENEWSFEEDS=0; + +#ifndef _PATH_BBSHOME +# define _PATH_BBSHOME "/u/staff/bbsroot/csie_util/bntpd/home" +#endif + +static FILE *bbslogfp; + +static int +verboseFlag=0; + +static char* +verboseFilename=NULL; +static char verbosename[MAXPATHLEN]; + +verboseon(filename) +char *filename; +{ + verboseFlag = 1; + if ( filename != NULL ) { + if (strchr(filename,'/') == NULL) { + sprintf(verbosename,"%s/innd/%s",BBSHOME,filename); + filename = verbosename; + } + } + verboseFilename = filename; +} +verboseoff() +{ + verboseFlag = 0; +} + +setverboseon() +{ + verboseFlag = 1; +} + +isverboselog() +{ + return verboseFlag; +} + +setverboseoff() +{ + verboseoff(); + if (bbslogfp != NULL) { + fclose(bbslogfp); + bbslogfp = NULL; + } +} + +verboselog(va_alist) +va_dcl +{ + va_list ap; + register char* fmt; + char datebuf[40]; + time_t now; + + if (verboseFlag == 0) return; + + va_start(ap); + + time(&now); + strftime(datebuf, sizeof(datebuf), "%b %d %X ", localtime(&now)); + + if (bbslogfp == NULL) { + if (verboseFilename != NULL) + bbslogfp = fopen(verboseFilename, "a"); + else + bbslogfp = fdopen(1, "a"); + } + if (bbslogfp == NULL) { va_end(ap); return; } + fmt = va_arg(ap, char *) ; + fprintf(bbslogfp,"%s[%d] ",datebuf, getpid()); + vfprintf(bbslogfp, fmt, ap); + fflush(bbslogfp); + va_end(ap); +} + +#ifdef PalmBBS +xbbslog(va_alist) +#else +bbslog(va_alist) +#endif +va_dcl +{ + va_list ap; + register char* fmt; + char datebuf[40]; + time_t now; + + va_start(ap); + + time(&now); + strftime(datebuf, sizeof(datebuf), "%b %d %X ", localtime(&now)); + + if (bbslogfp == NULL) { + bbslogfp = fopen(LOGFILE, "a"); + } + if (bbslogfp == NULL) { va_end(ap); return; } + fmt = va_arg(ap, char *) ; + fprintf(bbslogfp,"%s[%d] ",datebuf,getpid()); + vfprintf(bbslogfp, fmt, ap); + fflush(bbslogfp); + va_end(ap); +} + +initial_bbs(outgoing) +char *outgoing; +{ + FILE* FN; + struct stat st; + int fd, i; + char *bbsnameptr=NULL; + +/* reopen bbslog */ + if (bbslogfp != NULL) { + fclose(bbslogfp); + bbslogfp = NULL; + } + +#ifdef WITH_ECHOMAIL + init_echomailfp(); + init_bbsfeedsfp(); +#endif + + LOCALNODELIST=0, NONENEWSFEEDS =0; + sprintf(INNDHOME,"%s/innd",BBSHOME); + sprintf(HISTORY, "%s/history",INNDHOME); + sprintf(LOGFILE, "%s/bbslog",INNDHOME); + sprintf(ECHOMAIL,"%s/echomail.log",BBSHOME); + sprintf(LOCALDAEMON,"%s/.innbbsd",INNDHOME); + sprintf(INNBBSCONF,"%s/innbbs.conf",INNDHOME); + sprintf(BBSFEEDS,"%s/bbsfeeds.log",INNDHOME); + + if (isfile(INNBBSCONF)) { + FILE *conf; + char buffer[MAXPATHLEN]; + conf = fopen(INNBBSCONF,"r"); + if (conf != NULL) { + while (fgets( buffer, sizeof buffer, conf) != NULL) { + char *ptr, *front=NULL, *value=NULL, *value2=NULL, *value3=NULL; + if ( buffer[0] == '#' || buffer[0] == '\n') continue; + for ( front = buffer; *front && isspace(*front); front++); + for ( ptr = front; *ptr && !isspace(*ptr) ; ptr++) ; + if (*ptr == '\0') continue; + *ptr++ = '\0'; + for ( ; *ptr && isspace(*ptr) ; ptr++) ; + if (*ptr == '\0') continue; + value = ptr++; + for ( ; *ptr && !isspace(*ptr) ; ptr++) ; + if (*ptr) { + *ptr++ = '\0'; + for ( ; *ptr && isspace(*ptr) ; ptr++) ; + value2 = ptr++; + for ( ; *ptr && !isspace(*ptr) ; ptr++) ; + if (*ptr) { + *ptr++ = '\0'; + for ( ; *ptr && isspace(*ptr) ; ptr++) ; + value3 = ptr++; + for ( ; *ptr && !isspace(*ptr) ; ptr++) ; + if (*ptr) { + *ptr++ = '\0'; + } + } + } + if ( strcasecmp(front,"expiredays") == 0) { + Expiredays = atoi(value); + if (Expiredays < 0) { + Expiredays = EXPIREDAYS; + } + } else if ( strcasecmp(front,"expiretime") == 0) { + ptr = strchr(value,':'); + if (ptr == NULL) { + fprintf(stderr, "Syntax error in innbbs.conf\n"); + } else { + *ptr++ = '\0'; + His_Maint_Hour = atoi(value); + His_Maint_Min = atoi(ptr); + if (His_Maint_Hour < 0) + His_Maint_Hour = HIS_MAINT_HOUR; + if (His_Maint_Min < 0) + His_Maint_Min = HIS_MAINT_MIN; + } + } else if ( strcasecmp(front,"newsfeeds") == 0) { + if (strcmp(value,"none")==0) + NONENEWSFEEDS = 1; + } else if ( strcasecmp(front,"nodelist") == 0) { + if (strcmp(value,"local")==0) + LOCALNODELIST = 1; + } /*else if ( strcasecmp(front,"newsfeeds") == 0) { + printf("newsfeeds %s\n", value); + } else if ( strcasecmp(front,"nodelist") == 0) { + printf("nodelist %s\n", value); + } else if ( strcasecmp(front,"bbsname") == 0) { + printf("bbsname %s\n", value); + } */ + } + fclose(conf); + } + } + +#ifdef WITH_ECHOMAIL + bbsnameptr = (char*) fileglue("%s/bbsname.bbs",INNDHOME); + if ((FN = fopen( bbsnameptr ,"r" ))==NULL) { + fprintf(stderr,"can't open file %s\n", bbsnameptr); + return 0; + } + while ( fscanf(FN,"%s", MYBBSID) != EOF); + fclose(FN); + if( ! isdir(fileglue("%s/out.going",BBSHOME)) ) { + mkdir( (char*)fileglue("%s/out.going",BBSHOME), 0750 ); + } + if (NONENEWSFEEDS == 0) + readnffile(INNDHOME); + if (LOCALNODELIST == 0) { + if (readnlfile(INNDHOME, outgoing) != 0) return 0; + } + +#endif + return 1; +} + +static int +nf_byboardcmp(a,b) +newsfeeds_t **a, **b; +{ +/* + if (!a || !*a || !(*a)->board) return -1; + if (!b || !*b || !(*b)->board) return 1; +*/ + return strcasecmp((*a)->board, (*b)->board); +} + +static int +nfcmp(a,b) +newsfeeds_t *a, *b; +{ +/* + if (!a || !a->newsgroups) return -1; + if (!b || !b->newsgroups) return 1; +*/ + return strcasecmp(a->newsgroups, b->newsgroups); +} + +static int +nlcmp(a,b) +nodelist_t *a, *b; +{ +/* + if (!a || !a->host) return -1; + if (!b || !b->host) return 1; +*/ + return strcasecmp(a->host, b->host); +} + +static int +nl_bynodecmp(a,b) +nodelist_t **a, **b; +{ +/* + if (!a || !*a || !(*a)->node) return -1; + if (!b || !*b || !(*b)->node) return 1; +*/ + return strcasecmp((*a)->node, (*b)->node); +} + +/* read in newsfeeds.bbs and nodelist.bbs */ +readnlfile(inndhome, outgoing) +char *inndhome; +char *outgoing; +{ + FILE *fp; + char buff[1024]; + struct stat st; + int i, count, j; + char *ptr, *nodelistptr; + static lastcount=0; + + sprintf(buff,"%s/nodelist.bbs", inndhome); + fp = fopen(buff,"r"); + if (fp == NULL) { + fprintf(stderr,"open fail %s",buff); + return -1; + } + if (fstat(fileno(fp),&st) != 0) { + fprintf(stderr,"stat fail %s", buff); + return -1; + } + if (NODELIST_BUF == NULL) { + NODELIST_BUF = (char*) mymalloc( st.st_size +1); + } else { + NODELIST_BUF = (char*) myrealloc( NODELIST_BUF, st.st_size +1); + } + i = 0, count =0; + while (fgets(buff, sizeof buff, fp) != NULL) { + if (buff[0] == '#') continue; + if (buff[0] == '\n') continue; + strcpy(NODELIST_BUF+i, buff); + i += strlen(buff); + count ++; + } + fclose(fp); + if (NODELIST == NULL) { + NODELIST = (nodelist_t*) mymalloc(sizeof(nodelist_t) * (count+1)); + NODELIST_BYNODE = (nodelist_t**) mymalloc(sizeof(nodelist_t*) * (count+1)); + } else { + NODELIST = (nodelist_t*) myrealloc(NODELIST, sizeof(nodelist_t) * (count+1)); + NODELIST_BYNODE = (nodelist_t**) myrealloc(NODELIST_BYNODE, sizeof(nodelist_t*) * (count+1)); + } + for (i=lastcount; i< count; i++) { + NODELIST[i].feedfp = NULL; + } + lastcount = count; + NLCOUNT = 0; + for (ptr = NODELIST_BUF; (nodelistptr = (char*)strchr(ptr,'\n')) != NULL; ptr = nodelistptr +1, NLCOUNT++) { + char *nptr , *bptr, *pptr, *tptr; + *nodelistptr = '\0'; + NODELIST[NLCOUNT].host = ""; + NODELIST[NLCOUNT].exclusion = ""; + NODELIST[NLCOUNT].node = ""; + NODELIST[NLCOUNT].protocol = "IHAVE(119)"; + NODELIST[NLCOUNT].comments = ""; + NODELIST_BYNODE[NLCOUNT] = NODELIST+NLCOUNT; + for (nptr= ptr ;*nptr && isspace(*nptr); ) nptr++; + if (*nptr == '\0') { + bbslog("nodelist.bbs %d entry read error\n", NLCOUNT); + return -1; + } + /*NODELIST[NLCOUNT].id = nptr;*/ + NODELIST[NLCOUNT].node = nptr; + for (nptr++; *nptr && !isspace(*nptr); ) nptr++; + if (*nptr == '\0') { + bbslog("nodelist.bbs node %d entry read error\n", NLCOUNT); + return -1; + } + *nptr = '\0'; + if ((tptr = strchr(NODELIST[NLCOUNT].node,'/'))) { + *tptr = '\0'; + NODELIST[NLCOUNT].exclusion = tptr + 1; + } else { + NODELIST[NLCOUNT].exclusion = ""; + } + for (nptr++ ;*nptr && isspace(*nptr); ) nptr++; + if (*nptr == '\0') continue; + if (*nptr=='+' || *nptr=='-') { + NODELIST[NLCOUNT].feedtype = *nptr; + if (NODELIST[NLCOUNT].feedfp != NULL) { + fclose(NODELIST[NLCOUNT].feedfp); + } + if ( NODELIST[NLCOUNT].feedtype == '+') + if (outgoing != NULL) { + NODELIST[NLCOUNT].feedfp = fopen((char*)fileglue("%s/out.going/%s.%s",BBSHOME, NODELIST[NLCOUNT].node, outgoing),"a"); + } + nptr++; + } else { + NODELIST[NLCOUNT].feedtype = ' '; + } + NODELIST[NLCOUNT].host = nptr; + for (nptr++; *nptr && !isspace(*nptr); ) nptr++; + if (*nptr == '\0') { + continue; + } + *nptr = '\0'; + for (nptr++;*nptr && isspace(*nptr); ) nptr++; + if (*nptr == '\0') continue; + NODELIST[NLCOUNT].protocol = nptr; + for (nptr++; *nptr && !isspace(*nptr); ) nptr++; + if (*nptr == '\0') continue; + *nptr = '\0'; + for (nptr++;*nptr && strchr(" \t\r\n",*nptr); ) nptr++; + if (*nptr == '\0') continue; + NODELIST[NLCOUNT].comments = nptr; + } + qsort(NODELIST, NLCOUNT, sizeof(nodelist_t), nlcmp); + qsort(NODELIST_BYNODE, NLCOUNT, sizeof(nodelist_t*), nl_bynodecmp); + return 0; +} + +readnffile(inndhome) +char *inndhome; +{ + FILE *fp; + char buff[1024]; + struct stat st; + int i, count; + char *ptr, *newsfeedsptr; + + sprintf(buff,"%s/newsfeeds.bbs", inndhome); + fp = fopen(buff,"r"); + if (fp == NULL) { + fprintf(stderr,"open fail %s",buff); + return -1; + } + if (fstat(fileno(fp),&st) != 0) { + fprintf(stderr,"stat fail %s", buff); + return -1; + } + if (NEWSFEEDS_BUF == NULL) { + NEWSFEEDS_BUF = (char*) mymalloc( st.st_size +1); + } else { + NEWSFEEDS_BUF = (char*) myrealloc( NEWSFEEDS_BUF, st.st_size +1); + } + i = 0, count =0; + while (fgets(buff, sizeof buff, fp) != NULL) { + if (buff[0] == '#') continue; + if (buff[0] == '\n') continue; + strcpy(NEWSFEEDS_BUF+i, buff); + i += strlen(buff); + count ++; + } + fclose(fp); + if (NEWSFEEDS == NULL) { + NEWSFEEDS = (newsfeeds_t*) mymalloc(sizeof(newsfeeds_t) * (count+1)); + NEWSFEEDS_BYBOARD = (newsfeeds_t**) mymalloc(sizeof(newsfeeds_t*) * (count+1)); + } else { + NEWSFEEDS = (newsfeeds_t*) myrealloc(NEWSFEEDS, sizeof(newsfeeds_t) * (count+1)); + NEWSFEEDS_BYBOARD = (newsfeeds_t**) myrealloc(NEWSFEEDS_BYBOARD, sizeof(newsfeeds_t*) * (count+1)); + } + NFCOUNT = 0; + for (ptr = NEWSFEEDS_BUF; (newsfeedsptr = (char*)strchr(ptr,'\n')) != NULL; ptr = newsfeedsptr +1, NFCOUNT++) { + char *nptr , *bptr, *pptr; + *newsfeedsptr = '\0'; + NEWSFEEDS[NFCOUNT].newsgroups = ""; + NEWSFEEDS[NFCOUNT].board = ""; + NEWSFEEDS[NFCOUNT].path = NULL; + NEWSFEEDS_BYBOARD[NFCOUNT] = NEWSFEEDS+NFCOUNT; + for (nptr= ptr ;*nptr && isspace(*nptr); ) nptr++; + if (*nptr == '\0') continue; + NEWSFEEDS[NFCOUNT].newsgroups = nptr; + for (nptr++; *nptr && !isspace(*nptr); ) nptr++; + if (*nptr == '\0') continue; + *nptr = '\0'; + for (nptr++ ;*nptr && isspace(*nptr); ) nptr++; + if (*nptr == '\0') continue; + NEWSFEEDS[NFCOUNT].board = nptr; + for (nptr++; *nptr && !isspace(*nptr); ) nptr++; + if (*nptr == '\0') continue; + *nptr = '\0'; + for (nptr++;*nptr && isspace(*nptr); ) nptr++; + if (*nptr == '\0') continue; + NEWSFEEDS[NFCOUNT].path = nptr; + for (nptr++; *nptr && !strchr("\r\n",*nptr); ) nptr++; + *nptr = '\0'; + } + qsort(NEWSFEEDS, NFCOUNT, sizeof(newsfeeds_t), nfcmp); + qsort(NEWSFEEDS_BYBOARD, NFCOUNT, sizeof(newsfeeds_t*), nf_byboardcmp); +} + +newsfeeds_t *search_board(board) +char *board; +{ + newsfeeds_t nft, *nftptr, **find; + if (NONENEWSFEEDS) return NULL; + nft.board = board; + nftptr = &nft; + find = (newsfeeds_t**)bsearch((char*)&nftptr, NEWSFEEDS_BYBOARD, NFCOUNT, sizeof(newsfeeds_t*), nf_byboardcmp); + if (find != NULL) return *find; + return NULL; +} + +nodelist_t *search_nodelist_bynode(node) +char *node; +{ + nodelist_t nlt, *nltptr, **find; + if (LOCALNODELIST) return NULL; + nlt.node = node; + nltptr = ≮ + find = (nodelist_t**)bsearch((char*)&nltptr, NODELIST_BYNODE, NLCOUNT, sizeof(nodelist_t*), nl_bynodecmp); + if (find != NULL) return *find; + return NULL; +} + + +nodelist_t *search_nodelist(site, identuser) +char *site; +char *identuser; +{ + nodelist_t nlt, *find; + char buffer[1024]; + if (LOCALNODELIST) return NULL; + nlt.host = site; + find = (nodelist_t*)bsearch((char*)&nlt, NODELIST, NLCOUNT, sizeof(nodelist_t), nlcmp); + if (find == NULL && identuser != NULL) { + sprintf(buffer,"%s@%s", identuser, site); + nlt.host = buffer; + find = (nodelist_t*)bsearch((char*)&nlt, NODELIST, NLCOUNT, sizeof(nodelist_t), nlcmp); + } + return find; +} + +newsfeeds_t *search_group(newsgroup) +char *newsgroup; +{ + newsfeeds_t nft, *find; + if (NONENEWSFEEDS) return NULL; + nft.newsgroups = newsgroup; + find = (newsfeeds_t*)bsearch((char*)&nft, NEWSFEEDS, NFCOUNT, sizeof(newsfeeds_t), nfcmp); + return find; +} + +char *ascii_date(now) +time_t now; +{ + static char datebuf[40]; + /*time_t now; + time(&now);*/ + strftime(datebuf, sizeof(datebuf), "%d %b %Y %X GMT", gmtime(&now)); + return datebuf; +} + +char * +restrdup(ptr, string) +char *ptr; +char *string; +{ + int len ; + if (string == NULL) { + if (ptr != NULL) *ptr = '\0'; + return ptr; + } + len = strlen(string) + 1; + if (ptr != NULL) { + ptr = (char*)myrealloc(ptr, len); + } else + ptr = (char*)mymalloc(len); + strcpy(ptr, string); + return ptr; +} + + + +void * +mymalloc(size) +int size; +{ + char *ptr = (char*)malloc(size); + if (ptr == NULL) { + fprintf(stderr, "cant allocate memory\n"); + syslog(LOG_ERR, "cant allocate memory %m"); + exit(1); + } + return ptr; +} + +void * +myrealloc(optr, size) +void *optr; +int size; +{ + char *ptr = (char*)realloc(optr, size); + if (ptr == NULL) { + fprintf(stderr, "cant allocate memory\n"); + syslog(LOG_ERR, "cant allocate memory %m"); + exit(1); + } + return ptr; +} + +testandmkdir(dir) +char *dir; +{ + if (!isdir(dir)) { + char path[MAXPATHLEN+12]; + sprintf(path,"mkdir -p %s",dir); + system(path); + } +} + +static char splitbuf[2048]; +static char joinbuf[1024]; +#define MAXTOK 50 +static char* Splitptr[MAXTOK]; +char **split(line,pat) +char *line,*pat; +{ + char *p; + int i; + + for (i=0;iboard,nf2->board)==0) { + *ptr[j] = '\0'; + continue; + } + for (n11 = nf1->board, n12 = (char*)strchr(n11,','); + n11 && *n11 ; n12 = (char*) strchr(n11,',')) { + if (n12) *n12 = '\0'; + for (n21 = nf2->board, n22 = (char*)strchr(n21,','); + n21 && *n21 ; n22 = (char*) strchr(n21,',')) { + if (n22) *n22 = '\0'; + if (strcmp(n11,n21)==0) { + *n21 = '\t'; + } + if (n22) { + *n22 = ','; + n21 = n22 + 1; + } else + break; + } + if (n12) { + *n12 = ','; + n11 = n12 +1; + } else + break; + } + } + } + } + return ptr; +} + +char **ssplit(line,pat) +char *line,*pat; +{ + char *p; + int i; + for (i=0;i +#else +# include +# include "innbbsconf.h" +# include "bbslib.h" +#endif +#include "antisplam.h" + +#include + +#ifndef AIX +# include +#endif + +#if defined(PalmBBS) +#include +#endif + + +#include "daemon.h" +#include "nntp.h" +#include "externs.h" + +/* + * TODO 1. read newsfeeds.bbs, read nodelist.bbs, read bbsname.bbs 2. scan + * new posts and append to .link 3. rename .link to .send (must lock) 4. + * start to send .send out and append not sent to .link + * + * 5. node.LOCK (with pid) 6. log articles sent + */ + + +#ifndef MAXBUFLEN +#define MAXBUFLEN 256 +#endif + +#define MAX_OUTGO_POST 100 /* bbslink 一次處理的轉出最大文章數量 */ + +typedef struct my_out_bntp +{ + char *board, *filename, *userid, *nickname, *subject; +} my_out_bntp; +struct my_out_bntp out_bntp[MAX_OUTGO_POST]; + +int outgo_post=0; + +typedef struct Over_t +{ + time_t mtime; + char date[MAXBUFLEN]; + char nickname[MAXBUFLEN]; + char subject[MAXBUFLEN]; + char from[MAXBUFLEN]; + char msgid[MAXBUFLEN]; + char site[MAXBUFLEN]; + char board[MAXBUFLEN]; +} linkoverview_t; + +typedef struct SendOver_t +{ + char *board, *filename, *group, *from, *subject; + char *outgoingtype, *msgid, *path; + char *date, *control; + time_t mtime; +} soverview_t; + +typedef struct Stat_t +{ + int localsendout; + int localfailed; + int remotesendout; + int remotefailed; +} stat_t; + +static stat_t *BBSLINK_STAT; + +static int NoAction = 0; +static int Verbose = 0; +static int VisitOnly = 0; +static int NoVisit = 0; +static char *DefaultFeedSite = ""; +static int KillFormerBBSLINK = 0; + +extern char *SITE; +extern char *GROUPS; + +char NICKNAME[MAXBUFLEN]; + +char DATE_BUF[MAXBUFLEN]; +extern char *DATE; + +char FROM_BUF[MAXBUFLEN]; +extern char *FROM; + +#ifndef MapleBBS +char POSTER_BUF[MAXBUFLEN]; +char *POSTER; +#endif + +char MYADDR[MAXBUFLEN]; +char MYSITE[MAXBUFLEN]; + +char SUBJECT_BUF[MAXBUFLEN]; +extern char *SUBJECT; + +char MSGID_BUF[MAXBUFLEN]; +extern char *MSGID; + +char LINKPROTOCOL[MAXBUFLEN]; +int LINKPORT; +char ORGANIZATION[MAXBUFLEN]; +char NEWSCONTROL[MAXBUFLEN]; +char NEWSAPPROVED[MAXBUFLEN]; +char NNTPHOST_BUF[MAXBUFLEN]; +extern char *NNTPHOST; +char PATH_BUF[MAXBUFLEN]; +extern char *PATH; + +char CONTROL_BUF[MAXBUFLEN]; +extern char *CONTROL; + +char *BODY, *HEAD; + +int USEIHAVE = 1; +int USEPOST = 0; +int USEDATA = 0; +int FEEDTYPE = ' '; + +int NNTP = -1; +FILE *NNTPrfp = NULL; +FILE *NNTPwfp = NULL; +char NNTPbuffer[1024]; +static char *NEWSFEED; +static char *REMOTE = "REMOTE"; +static char *LOCAL = "LOCAL"; + +static int FD, FD_SIZE; +static char *FD_BUF; +static char *FD_END; + +static char *COMMENT = "\n"; +/*"[Ptt 送出]\n";*/ + +char *fileglue(); +int +is_outgo_post(board, filename, userid, nickname, subject) + char *board, *filename, *userid, *nickname, *subject; +{ + int mypost; + + for (mypost = 0; mypost < outgo_post; mypost++) + { + if (!strcmp(out_bntp[mypost].filename, filename)) + if (!strcmp(out_bntp[mypost].userid, userid)) + if (!strcmp(out_bntp[mypost].board, board)) + if (!strcmp(out_bntp[mypost].nickname, nickname)) + if (!strcmp(out_bntp[mypost].subject, subject)){ + if (Verbose) + printf("bad_cancel: %s, %s(%s), %s, %s\n", + board, userid, nickname, subject, filename); + bbslog("bad_cancel: %s, %s(%s), %s, %s\n", + board, userid, nickname, subject, filename); + return 1; + } + } + return 0; +} +/* +woju +Cross-fs rename() +*/ + +Rename(char* src, char* dst) +{ + char cmd[200]; + + if (rename(src, dst) == 0) + return 0; + + sprintf(cmd, "/bin/mv %s %s", src, dst); + return system(cmd); + +} + + +bbslink_un_lock(file) + char *file; +{ + char *lockfile = fileglue("%s.LOCK", file); + + if (isfile(lockfile)) + unlink(lockfile); +} + +bbslink_get_lock(file) + char *file; +{ + int lockfd; + char LockFile[MAXPATHLEN]; + + strncpy(LockFile, (char *) fileglue("%s.LOCK", file), sizeof LockFile); + if ((lockfd = open(LockFile, O_RDONLY)) >= 0) + { + char buf[10]; + int pid; + + if (read(lockfd, buf, sizeof buf) > 0 && + (pid = atoi(buf)) > 0 && kill(pid, 0) == 0) + { + if (KillFormerBBSLINK) + { + kill(pid, SIGTERM); + unlink(LockFile); + } + else + { + fprintf(stderr, "another process [%d] running\n", pid); + return 0; + } + } + else + { + fprintf(stderr, "no process [%d] running, but lock file existed, unlinked\n", pid); + unlink(LockFile); + } + close(lockfd); + } + + if ((lockfd = open(LockFile, O_RDWR | O_CREAT | O_EXCL, 0644)) < 0) + { + fprintf(stderr, "lock %s error: another bbslink process running\n", LockFile); + return 0; + } + else + { + char buf[10]; + int pid; + + sprintf(buf, "%-.8d\n", getpid()); + write(lockfd, buf, strlen(buf)); + close(lockfd); + return 1; + } +} + + +int +tcpcommand(va_alist) +va_dcl +{ + va_list ap; + register char *fmt; + char *ptr; + + va_start(ap); + fmt = va_arg(ap, char *); + vfprintf(NNTPwfp, fmt, ap); + fprintf(NNTPwfp, "\r\n"); + fflush(NNTPwfp); + + fgets(NNTPbuffer, sizeof NNTPbuffer, NNTPrfp); + ptr = strchr(NNTPbuffer, '\r'); + if (ptr) + *ptr = '\0'; + ptr = strchr(NNTPbuffer, '\n'); + if (ptr) + *ptr = '\0'; + va_end(ap); + return atoi(NNTPbuffer); +} + +char * +tcpmessage() +{ + char *ptr; + + ptr = strchr(NNTPbuffer, ' '); + if (ptr) + return ptr; + return NNTPbuffer; +} + +read_article(lover, filename, userid) + linkoverview_t *lover; + char *filename, *userid; +{ + FILE *fp; + int fd; + struct stat st; + time_t mtime; + char *buffer; + char *artptr, *artend, *artback; + + if (stat(filename, &st) != 0) + return 0; + lover->mtime = st.st_mtime; + fd = open(filename, O_RDONLY); + if (fd < 0) + { + bbslog(" Err: can't open %s\n", filename); + return 0; + } + + if (FD_BUF == NULL) + { + FD_BUF = mymalloc(st.st_size + 1 + strlen(COMMENT)); + } + else + { + FD_BUF = myrealloc(FD_BUF, st.st_size + 1 + strlen(COMMENT)); + } + FD_BUF[st.st_size] = '\0'; + read(fd, FD_BUF, st.st_size); + sprintf(FD_BUF + st.st_size, "%s", COMMENT); + st.st_size += strlen(COMMENT); + FD_SIZE = st.st_size; + for (buffer = FD_BUF, artend = FD_BUF + st.st_size, + artback = strchr(buffer, '\n'); + buffer && buffer < artend && *buffer; + artback = strchr(buffer, '\n') + ) + { + /* while( fgets(buffer, sizeof buffer, fp) != NULL) { */ + char *m, *n; + char *ptr; + + if (artback != NULL) + *artback = '\0'; + if (*buffer == '\0') + break; + +#ifndef MapleBBS + if (strstr(buffer, userid) != NULL) + { + m = strchr(buffer, '('); + n = strrchr(buffer, ')'); + if (m != NULL && n != NULL) + { + strncpy(lover->nickname, m + 1, n - m - 1); + lover->nickname[n - m - 1] = '\0'; + } + else + { + *lover->nickname = '\0'; + } + } + else if (strncmp(buffer, "Date: ", 11) == 0) + { + strcpy(lover->date, buffer + 11); + } + else if (strncmp(buffer, "發信站: ", 8) == 0) + { + m = strchr(buffer, '('); + n = strrchr(buffer, ')'); + strncpy(lover->date, m + 1, n - m - 1); + lover->date[n - m - 1] = '\0'; + } +#endif + + if (artback != NULL) + { + *artback = '\n'; + buffer = artback + 1; + } + else + { + break; + } + } + if (artback != NULL) + BODY = artback + 1; + else + BODY = ""; + close(fd); + return 1; +} + +save_outgoing(sover, filename, userid, poster, mtime) + soverview_t *sover, *filename, *userid, *poster; + time_t mtime; +{ + newsfeeds_t *nf; + char *group, *server, *serveraddr; + char *subject, *path; + char *board; + char *ptr1, *ptr2; + + board = sover->board; + + PATH = MYBBSID; + nf = (newsfeeds_t *) search_board(board); + if (nf == NULL) + { + bbslog(" save_outgoing: No such board %s\n", board); + return; + } + else + { + group = nf->newsgroups; + server = nf->path; + } + if (!server || !*server) + { + sprintf(PATH_BUF, "%.*s (local)", sizeof PATH_BUF - 9, MYBBSID); + PATH = PATH_BUF; + serveraddr = ""; + sover->path = PATH; + } + for (ptr1 = server; ptr1 && *ptr1;) + { + nodelist_t *nl; + char savech; + + for (; *ptr1 && isspace(*ptr1); ptr1++); + if (!*ptr1) + break; + for (ptr2 = ptr1; *ptr2 && !isspace(*ptr2); ptr2++); + savech = *ptr2; + *ptr2 = '\0'; + nl = (nodelist_t *) search_nodelist_bynode(ptr1); + *ptr2 = savech; + ptr1 = ptr2++; + if (nl == NULL) + continue; + /* if (nl->feedfp == NULL) continue; */ + + if (nl->host && *nl->host) + { + if (nl->feedfp == NULL) + { + nl->feedfp = fopen(fileglue("%s/%s.link", INNDHOME, nl->node), "a"); + if (nl->feedfp == NULL) + { + bbslog(" append failed for %s/%s.link", INNDHOME, nl->node); + } + } + if (nl->feedfp != NULL) + { + flock(fileno(nl->feedfp), LOCK_EX); + fprintf(nl->feedfp, "%s\t%s\t%s\t%ld\t%s\t%s\n", sover->board, filename, group, mtime, FROM, sover->subject); + fflush(nl->feedfp); + flock(fileno(nl->feedfp), LOCK_UN); + } + } + if (savech == '\0') + break; + } +} + + +#ifndef MapleBBS +save_article(board, filename, sover) + char *board, *filename; + soverview_t *sover; +{ + FILE *FN; + + if (Verbose) + printf(" %s %s\n", board, filename); + FN = fopen(fileglue("%s/boards/%s/%s", BBSHOME, board, filename), "w"); + if (FN == NULL) + { + bbslog(" err: %s %s\n", board, filename); + if (Verbose) + printf(" err: %s %s\n", board, filename); + return 0; + } + flock(fileno(FN), LOCK_EX); + fprintf(FN, "發信人: %s, 信區: %s\n", POSTER, sover->board); + fprintf(FN, "標 題: %s\n", sover->subject); + fprintf(FN, "發信站: %s (%s)\n", MYSITE, sover->date); + fprintf(FN, "轉信站: %s\n", sover->path); + fprintf(FN, "\n"); + fputs(BODY, FN); + flock(fileno(FN), LOCK_UN); + fclose(FN); + +#if defined(PalmBBS) + { + struct utimbuf times; + + times.actime = sover->mtime; + times.modtime = sover->mtime; + utime(fileglue("%s/boards/%s/%s", BBSHOME, board, filename), ×); + utime(fileglue("%s/.bcache/%s", BBSHOME, board), NULL); + } +#endif +} +#endif + +/* process_article() read_article() save_outgoing() save_article() */ + +process_article(board, filename, userid, nickname, subject) + char *board, *filename, *userid, *nickname, *subject; +{ + char *n, *filepath; + char poster[MAXBUFLEN]; + soverview_t sover; + + if (!*userid) + { + return; + } + else if (!subject || !*subject) + { + subject = "無題"; + } + filepath = fileglue("%s/boards/%s/%s", BBSHOME, board, filename); + if (isfile(filepath)) + { + linkoverview_t lover; + + if (read_article(&lover, filepath, userid)) + { + +#ifndef MapleBBS + strncpy(POSTER_BUF, fileglue("%s@%s (%s)", userid, MYBBSID, nickname), sizeof POSTER_BUF); + POSTER = POSTER_BUF; +#endif + + strncpy(FROM_BUF, fileglue("%s.bbs@%s (%s)", userid, MYADDR, nickname), sizeof FROM_BUF); + FROM = FROM_BUF; + sover.from = FROM; + sover.board = board; + sover.subject = subject; + PATH = MYBBSID; + sover.path = MYBBSID; + sover.date = lover.date; + sover.mtime = lover.mtime; + if (!VisitOnly) + { + save_outgoing(&sover, filename, userid, poster, lover.mtime); + +#ifndef MapleBBS + save_article(board, filename, &sover); +#endif + } + } + } +} + + +char * +baseN(val, base, len) + int val, base, len; +{ + int n, ans; + static char str[MAXBUFLEN]; + char *pstr = str; + int index; + + for (index = len - 1; index >= 0; index--) + { + n = val % base; + val /= base; + if (n < 10) + { + n += '0'; + } + else if (n < 36) + { + n += 'A' - 10; + } + else if (n < 62) + { + n += 'a' - 36; + } + else + { + n = '_'; + } + str[index] = n; + } + str[len] = '\0'; + return str; +} + +char * +hash_value(str) + char *str; +{ + int val, n; + char *ptr; + + if (*str) + ptr = str + strlen(str) - 1; + else + ptr = str; + val = 0; + while (ptr >= str) + { + n = *ptr; + val = (val + n * 0x100) ^ n; + ptr--; + } + return baseN(val, 64, 3); +} + +/* process_cancel() save_outgoing() hash_value(); baseN(); ascii_date(); */ + + +read_outgoing(sover) + soverview_t *sover; +{ + char *board, *filename, *group, *from, *subject, *outgoingtype, *msgid, *path; + char *buffer, *bufferp; + FILE *ECHOMAIL, *FN; + char *hash; + char times[MAXBUFLEN]; + time_t mtime; + + board = sover->board; + filename = sover->filename; + group = sover->group; + mtime = sover->mtime; + from = sover->from; + subject = sover->subject; + outgoingtype = sover->outgoingtype; + msgid = sover->msgid; + path = sover->path; + if (Verbose) + { + printf(" %s:%s:%s\n", board, filename, group); + printf(" => %ld:%s\n", mtime, from); + printf(" => %s\n", subject); + printf(" => %s:%s\n", outgoingtype, msgid); + printf(" => %s\n", path); + } + if (NEWSFEED == LOCAL) + { + char *end = strrchr(filename, '.'); + + if (end) + *end = '\0'; + strncpy(times, baseN(atol(filename + 2), 48, 6), sizeof times); + if (end) + *end = '.'; + hash = hash_value(fileglue("%s.%s", filename, board)); + sprintf(MSGID_BUF, "%s$%s@%s", times, hash, MYADDR); + } + else + { + strncpy(MSGID_BUF, msgid, sizeof MSGID_BUF); + } + sover->msgid = MSGID; + if (mtime == -1) + { + static char BODY_BUF[MAXBUFLEN]; + + strncpy(BODY_BUF, fileglue("%s\r\n", subject), sizeof BODY_BUF); + BODY = BODY_BUF; + sprintf(SUBJECT_BUF, "cmsg cancel <%s>", MSGID); + SUBJECT = SUBJECT_BUF; + sprintf(CONTROL_BUF, "cancel <%s>", MSGID); + CONTROL = CONTROL_BUF; + strncpy(MSGID_BUF, fileglue("%d.%s", getpid(), MSGID_BUF), sizeof MSGID_BUF); + sprintf(DATE_BUF, "%s", ascii_date(time(NULL))); + DATE = DATE_BUF; + sover->subject = SUBJECT; + sover->control = CONTROL; + sover->msgid = MSGID; + sover->date = DATE; + } + else + { + sover->control = CONTROL; + sover->date = DATE_BUF; + DATE = DATE_BUF; + *CONTROL = '\0'; + sprintf(DATE, "%s", ascii_date((mtime))); + if (NEWSFEED == LOCAL && !NoAction) + { + SITE = MYSITE; + PATH = MYBBSID; + GROUPS = group; + +#ifndef MapleBBS + echomaillog(); +#endif + } + BODY = ""; + FD = open(fileglue("%s/boards/%s/%s", BBSHOME, board, filename), O_RDONLY); + if (FD < 0) + { + if (Verbose) + printf(" !! can't open %s/boards/%s/%s\n", BBSHOME, board, filename); + else + fprintf(stderr, "can't open %s/boards/%s/%s\n", BBSHOME, board, filename); + return -1; + } + + FD_SIZE = filesize(fileglue("%s/boards/%s/%s", BBSHOME, board, filename)); + if (FD_BUF == NULL) + { + FD_BUF = (char *) mymalloc(FD_SIZE + 1 + strlen(COMMENT)); + } + else + { + FD_BUF = (char *) myrealloc(FD_BUF, FD_SIZE + 1 + strlen(COMMENT)); + } + FD_END = FD_BUF + FD_SIZE; + *FD_END = '\0'; + read(FD, FD_BUF, FD_SIZE); + sprintf(FD_END, "%s", COMMENT); + FD_SIZE += strlen(COMMENT); + FD_END += strlen(COMMENT); + if (Verbose) + { + printf(" %s/boards/%s/%s\n", BBSHOME, board, filename); + } + + *ORGANIZATION = '\0'; + *NEWSCONTROL = '\0'; + *NEWSAPPROVED = '\0'; + *NNTPHOST_BUF = '\0'; + NNTPHOST = NULL; + + for (buffer = FD_BUF, bufferp = strchr(buffer, '\n'); + buffer && *buffer; bufferp = strchr(buffer, '\n')) + { + if (bufferp) + *bufferp = '\0'; + if (*buffer == '\0') + { + break; + } + /* printf("get buffer %s\n", buffer); */ + if (NEWSFEED == REMOTE) + { + if (strncmp(buffer, "Date: ", 11) == 0) + { + strcpy(DATE_BUF, buffer + 11); + DATE = DATE_BUF; + } + else if (strncmp(buffer, "發信站: ", 8) == 0) + { + char *m, *n; + + m = strchr(buffer, '('); + n = strrchr(buffer, ')'); + if (m && n) + { + strncpy(DATE_BUF, m + 1, n - m - 1); + DATE_BUF[n - m - 1] = '\0'; + DATE = DATE_BUF; + strncpy(ORGANIZATION, buffer + 8, m - 8 - buffer - 1); + ORGANIZATION[m - 8 - buffer - 1] = '\0'; + } + } + else if (strncmp(buffer, "Control: ", 9) == 0) + { + strcpy(NEWSCONTROL, buffer + 9); + } + else if (strncmp(buffer, "Approved: ", 10) == 0) + { + strcpy(NEWSAPPROVED, buffer + 10); + } + else if (strncmp(buffer, "Origin: ", 8) == 0) + { + strcpy(NNTPHOST_BUF, buffer + 8); + NNTPHOST = NNTPHOST_BUF; + } + } + if (bufferp) + { + *bufferp = '\n'; + buffer = bufferp + 1; + } + else + { + break; + } + } + if (bufferp) + { + BODY = bufferp + 1; + } + else + BODY = ""; + if (bufferp) + for (buffer = bufferp + 1, bufferp = strchr(buffer, '\n'); + buffer && *buffer; bufferp = strchr(buffer, '\n')) + { + if (bufferp) + *bufferp = '\0'; + /* printf("get line (%s)\n", buffer); */ + /* if( strcmp(buffer,".")==0 ) { buffer[1]='.'; buffer[2]='\0'; } */ + if (NEWSFEED == REMOTE && + strncmp(NEWSCONTROL, "cancel", 5) == 0 && + strncmp(buffer, "------------------", 18) == 0) + { + break; + } + else if (strncmp(buffer, "◆ From: ", 9) == 0) + { + strcpy(NNTPHOST_BUF, buffer + 9); + NNTPHOST = NNTPHOST_BUF; + } + /* $BODY[ @BODY ] = "$_\r\n"; */ + if (bufferp) + { + *bufferp = '\n'; + buffer = bufferp + 1; + } + else + { + break; + } + } + /* # fprintf("BODY @BODY\n"; */ + close(FD); + } + return 0; +} + +#ifdef TEST +#endif + +openfeed(node) + nodelist_t *node; +{ + if (node->feedfp == NULL) + { + node->feedfp = fopen(fileglue("%s/%s.link", INNDHOME, node->node), "a"); + } +} + +queuefeed(node, textline) + nodelist_t *node; + char *textline; +{ + openfeed(node); + if (node->feedfp != NULL) + { + flock(fileno(node->feedfp), LOCK_EX); + fprintf(node->feedfp, "%s", textline); + fflush(node->feedfp); + flock(fileno(node->feedfp), LOCK_UN); + } +} + +post_article(node, site, sover, textline) + nodelist_t *node; + char *site; + soverview_t *sover; + char *textline; +{ + int status; + char *filename = sover->filename; + char *msgid = sover->msgid; + char *board = sover->board; + char *bodyp, *body; + + if (Verbose) + fprintf(stdout, " %s %s %s\n", site, filename, msgid); + if (NoAction && Verbose) + { + printf(" ==>%s\n", sover->path); + printf(" ==>%s:%s\n", sover->from, sover->group); + printf(" ==>%s:%s\n", sover->subject, sover->date); + body = BODY; + bodyp = strchr(body, '\n'); + if (bodyp) + *bodyp = '\0'; + printf(" ==>%s\n", body); + if (bodyp) + *bodyp = '\n'; + if (bodyp) + { + body = bodyp + 1; + bodyp = strchr(body, '\n'); + if (bodyp) + *bodyp = '\0'; + printf(" ==>%s\n", body); + if (bodyp) + *bodyp = '\n'; + } + } + if (NoAction) + return 1; + if (NEWSFEED == REMOTE) + { + fprintf(NNTPwfp, "Path: %s\r\n", sover->path); + fprintf(NNTPwfp, "From: %s\r\n", sover->from); + fprintf(NNTPwfp, "Newsgroups: %s\r\n", sover->group); + fprintf(NNTPwfp, "Subject: %s\r\n", sover->subject); + /* # fprintf( NNTPwfp,"Post with subject ($subject)\n"); */ + fprintf(NNTPwfp, "Date: %s\r\n", sover->date); + if (*ORGANIZATION) + fprintf(NNTPwfp, "Organization: %s\r\n", ORGANIZATION); + fprintf(NNTPwfp, "Message-ID: <%s>\r\n", sover->msgid); + if (*NEWSCONTROL) + fprintf(NNTPwfp, "Control: %s\r\n", NEWSCONTROL); + if (*NEWSAPPROVED) + fprintf(NNTPwfp, "Approved: %s\r\n", NEWSAPPROVED); + } + else + { + fprintf(NNTPwfp, "Path: %s\r\n", MYBBSID); + fprintf(NNTPwfp, "From: %s\r\n", sover->from); + fprintf(NNTPwfp, "Newsgroups: %s\r\n", sover->group); + fprintf(NNTPwfp, "Subject: %s\r\n", sover->subject); + fprintf(NNTPwfp, "Date: %s\r\n", sover->date); + fprintf(NNTPwfp, "Organization: %s\r\n", MYSITE); + fprintf(NNTPwfp, "Message-ID: <%s>\r\n", sover->msgid); + fprintf(NNTPwfp, "X-Filename: %s/%s\r\n", sover->board, sover->filename); + } + if (NNTPHOST && *NNTPHOST && USEIHAVE) + fprintf(NNTPwfp, "NNTP-Posting-Host: %s\r\n", NNTPHOST); + else if (NNTPHOST && *NNTPHOST) + fprintf(NNTPwfp, "X-Auth-From: %s\r\n", NNTPHOST); + if (*CONTROL) + { + fprintf(NNTPwfp, "Control: %s\r\n", CONTROL); + } + fputs("\r\n", NNTPwfp); + for (body = BODY, bodyp = strchr(body, '\n'); + body && *body; bodyp = strchr(body, '\n')) + { + if (bodyp) + *bodyp = '\0'; + + fputs(body, NNTPwfp); + if (body[0] == '.' && body[1] == '\0') + fputs(".", NNTPwfp); + fputs("\r\n", NNTPwfp); + if (bodyp) + { + *bodyp = '\n'; + body = bodyp + 1; + } + else + { + break; + } + } + /* print "send out @BODY\n"; */ + status = tcpcommand("."); + /* 435 duplicated article 437 invalid header */ + + if (USEIHAVE) + { + if (status == 235) + { + if (NEWSFEED == LOCAL) + { + bbslog("Sendout <%s> from %s/%s\n", msgid, board, filename); + } + } + else if (status == 437 || status == 435) + { + bbslog(" :Warn: %d %s <%s>\n", status, (char *) tcpmessage(), msgid); + if (Verbose) + printf(":Warn: %d %s <%s>\n", status, (char *) tcpmessage(), msgid); + return 0; + } + else + { + bbslog(" :Err: %d %s of <%s>\n", status, (char *) tcpmessage(), msgid); + if (Verbose) + printf(":Err: %d %s of <%s>\n", status, (char *) tcpmessage(), msgid); + if (!strstr(tcpmessage(), "Article not posted")) + queuefeed(node, textline); + return 0; + } + } + else if (USEPOST) + { + if (status == 240) + { + bbslog("Sendout <%s> from %s/%s\n", msgid, board, filename); + } + else if (status == 437 || status == 435) + { + bbslog(" :Warn: %d %s <%s>\n", status, (char *) tcpmessage(), msgid); + if (Verbose) + printf(":Warn: %d %s <%s>\n", status, (char *) tcpmessage(), msgid); + return 0; + } + else + { + bbslog(" :Err: %d %s of <%s>\n", status, (char *) tcpmessage(), msgid); + if (!strstr(tcpmessage(), "Article not posted")) + queuefeed(node, textline); + return 0; + } + } + else + { + if (status == 250) + { + bbslog(" DATA Sendout <%s> from %s/%s\n", msgid, board, filename); + if (Verbose) + printf(" <%s> from %s/%s\n", msgid, board, filename); + } + else + { + bbslog(" :Err: %d %s of <%s>\n", status, (char *) tcpmessage(), msgid); + if (Verbose) + printf(":Err: %d %s of <%s>\n", status, (char *) tcpmessage(), msgid); + if (!strstr(tcpmessage(), "Article not posted")) + queuefeed(node, textline); + return 0; + } + } + return 1; +} + +process_cancel(board, filename, userid, nickname, subject) + char *board, *filename, *userid, *nickname, *subject; +{ + time_t mtime; + soverview_t sover; + + if (!userid || !*userid) + { + return; + } + mtime = -1; + strncpy(FROM_BUF, fileglue("%s.bbs@%s (%s)", userid, MYADDR, nickname), sizeof FROM_BUF); + FROM = FROM_BUF; + sover.from = FROM; + sover.board = board; + sover.subject = subject; + PATH = MYBBSID; + sover.path = MYBBSID; + /* save_outgoing(&sover, filename, userid, poster, -1); */ + save_outgoing(&sover, filename, userid, userid, -1); +} + +open_link(hostname, hostprot, hostport) + char *hostname, *hostprot, *hostport; +{ + USEIHAVE = 1; + USEPOST = 0; + USEDATA = 0; + FEEDTYPE = ' '; + if (Verbose) + printf(" %s %s %s\n", hostname, hostprot, hostport); + if (strncasecmp(hostprot, "IHAVE", 5) != 0) + { + USEIHAVE = 0; + USEPOST = 1; + if (strncasecmp(hostprot, "POST", 4) == 0) + { + USEPOST = 1; + } + else if (strncasecmp(hostprot, "DATA", 4) == 0) + { + USEPOST = 0; + USEDATA = 1; + } + } + + FEEDTYPE = hostname[0]; + if (!USEDATA) + { + char *atsign; + + if (FEEDTYPE == '-' || FEEDTYPE == '+') + { + hostname = hostname + 1; + } + atsign = strchr(hostname, '@'); + if (atsign != NULL) + { + hostname = atsign + 1; + } + if (!NoAction) + { + if (Verbose) + printf(" %s %s\n", hostname, hostport); + if ((NNTP = inetclient(hostname, hostport, "tcp")) < 0) + { + bbslog(" :Err: server %s %s error: cant connect\n", hostname, hostport); + if (Verbose) + printf(":Err: server %s %s error: cant connect\n", hostname, hostport); + return 0; + /* exit( 0 ); */ + /* return; */ + } + NNTPrfp = fdopen(NNTP, "r"); + NNTPwfp = fdopen(NNTP, "w"); + fgets(NNTPbuffer, sizeof NNTPbuffer, NNTPrfp); + if (atoi(NNTPbuffer) != 200) + { + bbslog(" :Err: server error: %s", NNTPbuffer); + if (Verbose) + printf(":Err: server error: %s", NNTPbuffer); + return 0; + /* exit( 0 ); */ + } + } + else + { + if (Verbose) + printf(" %s %s\n", hostname, hostport); + } + } + else + { + if (!NoAction) + { + if (Verbose) + printf(" localhost %s\n", hostport); + if ((NNTP = inetclient("localhost", hostport, "tcp")) < 0) + { + bbslog(" :Err: server %s port %s error: cant connect\n", hostname, hostport); + if (Verbose) + printf(":Err: server error: cant connect"); + return 0; + /* exit( 0 ); */ + /* return; */ + } + NNTPrfp = fdopen(NNTP, "r"); + NNTPwfp = fdopen(NNTP, "w"); + fgets(NNTPbuffer, sizeof NNTPbuffer, NNTPrfp); + if (strncmp(NNTPbuffer, "220", 3) != 0) + { + bbslog(" :Err: server error: %s", NNTPbuffer); + if (Verbose) + printf(":Err: server error: %s", NNTPbuffer); + return 0; + /* exit( 0 ); */ + } + if (strncmp(NNTPbuffer, "220-", 4) == 0) + { + fgets(NNTPbuffer, sizeof NNTPbuffer, NNTPrfp); + } + } + else + { + if (Verbose) + printf(" %s %s\n", hostname, hostport); + } + } + return 1; +} + +send_outgoing(node, site, hostname, sover, textline) + nodelist_t *node; + soverview_t *sover; + char *hostname, *site; + char *textline; +{ + int status; + char *board, *filepath, *msgid; + int returnstatus = 0; + + board = sover->board; + filepath = sover->filename; + msgid = sover->msgid; + + if (Verbose) + printf(" %s:%s:%s:%s\n", site, board, filepath, msgid); + if (BODY != NULL && !NoAction) + { + if (USEIHAVE) + { +/* status = tcpcommand("IHAVE <%s>", msgid);*/ + char buf[80]; + sprintf(buf, "IHAVE <%s>", msgid); + status = tcpcommand(buf); + if (status == 335) + { + returnstatus = post_article(node, site, sover, textline); + } + else if (status == 435) + { + bbslog(" :Warn: %d %s, IHAVE <%s>\n", status, (char *) tcpmessage(), msgid); + if (Verbose) + printf(":Warn: %d %s, IHAVE <%s>\n", status, (char *) tcpmessage(), msgid); + returnstatus = 0; + } + else + { + bbslog(" :Err: %d %s, IHAVE <%s>\n", status, (char *) tcpmessage(), msgid); + if (Verbose) + printf(":Err: %d %s, IHAVE <%s>\n", status, (char *) tcpmessage(), msgid); + if (!strstr(tcpmessage(), "Article not posted")) + queuefeed(node, textline); + returnstatus = 0; + } + } + else if (USEPOST) + { + tcpcommand("MODE READER"); + status = tcpcommand("POST"); + if (status == 340) + { + returnstatus = post_article(node, site, sover, textline); + } + else if (status == 441) + { + bbslog(" :Warn: %d %s, POST <%s>\n", status, (char *) tcpmessage(), msgid); + if (Verbose) + printf(":Warn: %d %s, POST <%s>\n", status, (char *) tcpmessage(), msgid); + returnstatus = 0; + } + else + { + bbslog(" :Err: %d %s, POST <%s>\n", status, (char *) tcpmessage(), msgid); + if (Verbose) + printf(":Err: %d %s, POST <%s>\n", status, (char *) tcpmessage(), msgid); + if (!strstr(tcpmessage(), "Article not posted")) + queuefeed(node, textline); + returnstatus = 0; + } + } + else + { + tcpcommand("HELO"); + tcpcommand("MAIL FROM: bbs"); + tcpcommand("RCPT TO: %s", hostname); + status = tcpcommand("DATA"); + if (status == 354) + { + returnstatus = post_article(node, site, sover, textline); + } + else + { + bbslog(" :Err: %d %s, DATA <%s>\n", status, (char *) tcpmessage(), msgid); + if (Verbose) + printf(":Err: %d %s, DATA <%s>\n", status, (char *) tcpmessage(), msgid); + if (!strstr(tcpmessage(), "Article not posted")) + queuefeed(node, textline); + returnstatus = 0; + } + } + } + else if (NoAction) + { + returnstatus = post_article(node, site, sover, textline); + } + return returnstatus; +} + +save_nntplink(node, overview) + nodelist_t *node; + char *overview; +{ + FILE *POSTS; + char buffer[1024]; + + openfeed(node); + POSTS = fopen(overview, "r"); + if (POSTS == NULL) + return 0; + openfeed(node); + /* if (node->feedfp == NULL) return 0; */ + flock(fileno(node->feedfp), LOCK_EX); + while (fgets(buffer, sizeof buffer, POSTS) != NULL) + { + fputs(buffer, node->feedfp); + fflush(node->feedfp); + } + flock(fileno(node->feedfp), LOCK_UN); + fclose(POSTS); + if (Verbose) + printf(" %s\n", overview); + if (!NoAction) + unlink(overview); + return 1; +} + + +char * +get_tmpfile(tmpfile) + char *tmpfile; +{ + FILE *FN; + static char result[256]; + + FN = fopen(tmpfile, "r"); + fgets(result, sizeof result, FN); + fclose(FN); + unlink(tmpfile); + return (result); +} + +/* cancel moderating posts */ + +cancel_outgoing(board, filename, from, subject) + char *board, *filename, *from, *subject; +{ + char *base, filepath[MAXPATHLEN]; + FILE *FN; + char *result; + char TMPFILE[MAXPATHLEN]; + + if (Verbose) + { + printf(" %s %s %s %s\n", board, filename, from, subject); + } + + sprintf(TMPFILE, "/tmp/cancel_outgoing.%d.%d", getuid(), getpid()); + + bbslog(" Try to move moderated post from %s to deleted\n", board); + if (Verbose) + printf("Try to move moderated post from %s to deleted\n", board); + FN = popen(fileglue("%s/bbspost post %s/boards/deleted > %s", + INNDHOME, BBSHOME, TMPFILE), "w"); + if (FN == NULL) + { + bbslog(" can't run %s/bbspost\n", INNDHOME); + if (Verbose) + printf(" can't run %s/bbspost\n", INNDHOME); + return 0; + } + fprintf(FN, "%s\n", from); + fprintf(FN, "%s\n", subject); + fprintf(FN, "發信人: %s, 信區: %s\n", from, board); + fprintf(FN, "標 題: %s\n", subject); + fprintf(FN, "發信站: %s (%s)\n", MYSITE, DATE); + fprintf(FN, "轉信站: %s\n", MYBBSID); + fputs("\n", FN); + fputs(BODY, FN); + pclose(FN); + result = (char *) get_tmpfile(TMPFILE); + if (strncmp(result, "post to ", 8) == 0) + { + /* try to remove it */ + strncpy(filepath, fileglue("%s/boards/%s/%s", BBSHOME, board, filename), sizeof filepath); + if (isfile(filepath)) + { + Rename(filepath, fileglue("%s.cancel", filepath)); + } + FN = fopen(filepath, "w"); + + fprintf(FN, "發信人: %s, 信區: %s\n", from, board); + fprintf(FN, "標 題:
%s %s %s %s\n", site, hostname, hostprot, hostport); + printf(" ==> %s\n", overview); + } + if (!open_link(hostname, hostprot, hostport)) + { + save_nntplink(node, overview); + return 0; + } + POSTS = fopen(overview, "r"); + if (POSTS == NULL) + { + if (Verbose) + printf("open %s failed\n", overview); + return 0; + } + while (fgets(textline, sizeof textline, POSTS) != NULL) + { + char *linebreak = strchr(textline, '\n'); + char *ptr; + char *board, *filename, *subject, *group, *mtime, *from; + char *outgoingtype; + char *msgid, *path; + soverview_t soverview; + + strcpy(baktextline, textline); + if (linebreak) + *linebreak = '\0'; + + board = "", filename = "", mtime = "", group = "", from = "", subject = ""; + outgoingtype = "", msgid = "", path = ""; + /* get board field */ + board = textline; + ptr = strchr(textline, '\t'); + if (ptr == NULL) + continue; + *ptr++ = '\0'; + + /* filename field */ + filename = ptr; + + ptr = strchr(ptr, '\t'); + if (ptr == NULL) + continue; + + *ptr++ = '\0'; + + /* group field */ + group = ptr; + ptr = strchr(ptr, '\t'); + if (ptr == NULL) + continue; + *ptr++ = '\0'; + + /* mtime field */ + mtime = ptr; + ptr = strchr(ptr, '\t'); + if (ptr == NULL) + continue; + *ptr++ = '\0'; + + /* from field */ + from = ptr; + ptr = strchr(ptr, '\t'); + if (ptr == NULL) + continue; + *ptr++ = '\0'; + + /* subject */ + subject = ptr; + ptr = strchr(ptr, '\t'); + if (ptr == NULL) + goto try_read_outgoing; + *ptr++ = '\0'; + + /* outgoing type field */ + outgoingtype = ptr; + ptr = strchr(ptr, '\t'); + if (ptr == NULL) + goto try_read_outgoing; + *ptr++ = '\0'; + + /* msgid */ + msgid = ptr; + ptr = strchr(ptr, '\t'); + if (ptr == NULL) + goto try_read_outgoing; + *ptr++ = '\0'; + + /* path */ + path = ptr; + ptr = strchr(ptr, '\t'); + if (ptr == NULL) + goto try_read_outgoing; + +try_read_outgoing: + + NEWSFEED = LOCAL; + if (outgoingtype && msgid && path && *outgoingtype && *msgid && *path) + { + char *left, *right; + + NEWSFEED = REMOTE; + left = strchr(msgid, '<'); + right = strrchr(msgid, '>'); + if (left) + msgid = left + 1; + if (right) + *right = '\0'; + } + soverview.board = board; + soverview.filename = filename; + soverview.group = group; + soverview.mtime = atol(mtime); + soverview.from = from; + soverview.subject = subject; + soverview.outgoingtype = outgoingtype; + soverview.msgid = msgid; + soverview.path = path; + if (read_outgoing(&soverview) == 0) + { + int sendresult = send_outgoing(node, site, hostname, &soverview, baktextline); + int sendfailed = 1 - sendresult; + + if (NEWSFEED == REMOTE) + { + BBSLINK_STAT[nlcount].remotesendout += sendresult; + BBSLINK_STAT[nlcount].remotefailed += sendfailed; + } + else + { + BBSLINK_STAT[nlcount].localsendout += sendresult; + BBSLINK_STAT[nlcount].localfailed += sendfailed; + } + if (node->feedtype == '-') + { + if (!NoAction && sendresult) + cancel_outgoing(board, filename, from, subject); + } + } + } + fclose(POSTS); + close_link(); + if (Verbose) + printf(" %s\n", overview); + if (!NoAction) + unlink(overview); +} + +close_link() +{ + int status; + + if (Verbose) + printf("\n"); + if (NoAction) + return; + status = tcpcommand("QUIT"); + if (status != 205 && status != 221) + { + bbslog(" :Err: Cannot quit message '%d %s'\n", status, (char *) tcpmessage()); + if (Verbose) + printf(":Err: Cannot quit message '%d %s'\n", status, (char *) tcpmessage()); + } + fclose(NNTPwfp); + fclose(NNTPrfp); + close(NNTP); +} + + +/* + * send_article() send_nntplink() read_outgoing() + * + */ + +send_article() +{ + char *site, *addr, *protocol, *port, *op; + char *nntphost; + int nlcount; + + chdir(INNDHOME); + + for (nlcount = 0; nlcount < NLCOUNT; nlcount++) + { + nodelist_t *node; + char linkfile[MAXPATHLEN]; + char sendfile[MAXPATHLEN]; + char feedfile[MAXPATHLEN]; + char feedingfile[MAXPATHLEN]; + char protocol[MAXBUFLEN], port[MAXBUFLEN]; + + node = NODELIST + nlcount; + site = node->node; + nntphost = node->host; + op = node->protocol; + + if (DefaultFeedSite && *DefaultFeedSite) + { + if (strcmp(node->node, DefaultFeedSite) != 0) + continue; + } + + if (op && (strncasecmp(op, "ihave", 5) == 0 || + strncasecmp(op, "post", 4) == 0 || + strncasecmp(op, "data", 4) == 0)) + { + char *left, *right; + + left = strchr(op, '('), right = strrchr(op, ')'); + if (left && right) + { + *left = '\0'; + *right = '\0'; + strncpy(protocol, op, sizeof protocol); + strncpy(port, left + 1, sizeof port); + *left = '('; + *right = ')'; + } + else + { + strncpy(protocol, op, sizeof protocol); + strncpy(port, "nntp", sizeof port); + } + } + else + { + strcpy(protocol, "IHAVE"); + strcpy(port, "nntp"); + } + sprintf(linkfile, "%s.link", site); + sprintf(sendfile, "%s.sending", site); + sprintf(feedfile, "%s.feed", site); + sprintf(feedingfile, "%s.feeding", site); + if (isfile(sendfile) && !iszerofile(sendfile)) + { + if (bbslink_get_lock(sendfile)) + { + send_nntplink(node, site, nntphost, protocol, port, sendfile, nlcount); + bbslink_un_lock(sendfile); + } + } + if (isfile(linkfile) && !iszerofile(linkfile)) + { + if (!NoAction) + { + if (bbslink_get_lock(sendfile) && bbslink_get_lock(linkfile) && + bbslink_get_lock(feedingfile)) + { + if (isfile(sendfile) && !iszerofile(sendfile)) + { + save_nntplink(node, sendfile); + } + if (node->feedfp) + { + fclose(node->feedfp); + node->feedfp = NULL; + } + Rename(linkfile, sendfile); + send_nntplink(node, site, nntphost, protocol, port, sendfile, nlcount); + bbslink_un_lock(linkfile); + bbslink_un_lock(sendfile); + bbslink_un_lock(feedingfile); + } + } + else + { + send_nntplink(node, site, nntphost, protocol, port, linkfile, nlcount); + } + } + if (isfile(feedingfile) && !iszerofile(feedingfile)) + { + if (bbslink_get_lock(feedingfile)) + { + send_nntplink(node, site, nntphost, protocol, port, feedingfile, nlcount); + bbslink_un_lock(feedingfile); + } + } + if (isfile(feedfile) && !iszerofile(feedfile)) + { + if (!NoAction) + { + if (bbslink_get_lock(feedfile) && bbslink_get_lock(feedingfile)) + { + if (isfile(feedingfile) && !iszerofile(feedingfile)) + { + save_nntplink(node, feedingfile); + if (node->feedfp) + { + fclose(node->feedfp); + node->feedfp = NULL; + } + } + Rename(feedfile, feedingfile); + system(fileglue("%s/ctlinnbbsd reload > /dev/null", INNDHOME)); + send_nntplink(node, site, nntphost, protocol, port, feedingfile, nlcount); + bbslink_un_lock(feedfile); + bbslink_un_lock(feedingfile); + } + } + else + { + send_nntplink(node, site, nntphost, protocol, port, feedfile, nlcount); + } + } + } +} + +/* bntplink() bbspost() process_article() process_cancel() send_article() */ + + +show_usage(argv) + char *argv; +{ + fprintf(stderr, "%s initialization failed or improper options !!\n", argv); + fprintf(stderr, "Usage: %s [options] bbs_home\n", argv); + fprintf(stderr, " -v (show transmission status)\n"); + fprintf(stderr, " -n (dont send out articles and leave queue untouched)\n"); + fprintf(stderr, " -s site (only process articles sent to site)\n"); + fprintf(stderr, " -V (visit only: bbspost visit)\n"); + fprintf(stderr, " -N (no visit, and only process batch queue)\n"); + fprintf(stderr, " -k (kill the former bbslink process before started)\n\n"); + fprintf(stderr, "本程式要正常執行必須將以下檔案置於 %s/innd 下:\n", BBSHOME); + fprintf(stderr, "bbsname.bbs 設定貴站的 BBS ID (請儘量簡短)\n"); + fprintf(stderr, "nodelist.bbs 設定網路各 BBS 站的 ID, Address 和 fullname\n"); + fprintf(stderr, "newsfeeds.bbs 設定網路信件的 newsgroup board nodelist ...\n"); +} + + +bntplink(argc, argv) + int argc; + char **argv; +{ + static char *OUTING = ".outing"; + nodelist_t *nl; + int linkport; + char result[4096]; + char cancelfile[MAXPATHLEN], cancelpost[MAXPATHLEN]; + char bbslink_lockfile[MAXPATHLEN]; + FILE *NEWPOST; + char *left, *right; + int nlcount; + +// strcpy(BBSHOME, argv[0]); + if (initial_bbs("link") == 0) + { + return -1; + } + + BBSLINK_STAT = (stat_t *) malloc(sizeof(stat_t) * (NLCOUNT + 1)); + for (nlcount = 0; nlcount < NLCOUNT; nlcount++) + { + BBSLINK_STAT[nlcount].localsendout = 0; + BBSLINK_STAT[nlcount].remotesendout = 0; + BBSLINK_STAT[nlcount].localfailed = 0; + BBSLINK_STAT[nlcount].remotefailed = 0; + } + + nl = (nodelist_t *) search_nodelist_bynode(MYBBSID); + if (nl == NULL) + { + *MYADDR = '\0'; + *MYSITE = '\0'; + *LINKPROTOCOL = '\0'; + } + else + { + strncpy(MYADDR, nl->host, sizeof MYADDR); + strncpy(LINKPROTOCOL, nl->protocol, sizeof LINKPROTOCOL); + strncpy(MYSITE, nl->comments, sizeof MYSITE); + } + if (Verbose) + { + printf("MYADDR: %s\n", MYADDR); + printf("MYSITE: %s\n", MYSITE); + } + left = strchr(nl->protocol, '('); + right = strrchr(nl->protocol, ')'); + if (left && right) + { + *right = '\0'; + strncpy(LINKPROTOCOL, nl->protocol, sizeof LINKPROTOCOL); + LINKPORT = atoi(left + 1); + *right = ')'; + } + + if (!NoVisit) + { + sprintf(bbslink_lockfile, "%s/.bbslink.visit", INNDHOME); + if (!Rename(fileglue("%s/out.bntp", INNDHOME), OUTING) && bbslink_get_lock(bbslink_lockfile)) + { + /* When try to visit new post, try to lock it */ + NEWPOST = fopen(OUTING, "r"); + if (NEWPOST == NULL) + { + bbslog(" Err: can't open %s\n", OUTING); + bbslink_un_lock(bbslink_lockfile); + return -1; + } + while (fgets(result, sizeof result, NEWPOST)) + { + /* chop( $_ ); */ + char *board, *filename, *userid, *nickname, *subject; + char *ptr; + + ptr = strchr(result, '\n'); + if (ptr) + *ptr = '\0'; + + board = filename = userid = nickname = subject = NULL; + /* board field */ + board = result; + ptr = strchr(result, '\t'); + if (ptr == NULL) + continue; + *ptr++ = '\0'; + + /* filename field */ + filename = ptr; + ptr = strchr(ptr, '\t'); + if (ptr == NULL) + continue; + *ptr++ = '\0'; + + /* userid field */ + userid = ptr; + ptr = strchr(ptr, '\t'); + if (ptr == NULL) + continue; + *ptr++ = '\0'; + + /* nickname field */ + nickname = ptr; + ptr = strchr(ptr, '\t'); + if (ptr == NULL) + continue; + *ptr++ = '\0'; + + /* subject field */ + subject = ptr; + /* ptr = strchr(ptr, '\t'); if (ptr == NULL) continue; ptr++ = '\0'; */ + + if(bad_subject(subject)) continue; + + if(outgo_post < MAX_OUTGO_POST){ + out_bntp[outgo_post].board = board; + out_bntp[outgo_post].filename = filename; + out_bntp[outgo_post].userid = userid; + out_bntp[outgo_post].nickname = nickname; + out_bntp[outgo_post].subject = subject; + outgo_post++; + } + + process_article(board, filename, userid, nickname, subject); + } + fclose(NEWPOST); + unlink(OUTING); + bbslink_un_lock(bbslink_lockfile); + } /* getlock */ + } /* if NoVisit is false */ + + sprintf(cancelpost, "%s/cancel.bntp", INNDHOME); + if (isfile(cancelpost)) + { + FILE *CANCELFILE; + + if (bbslink_get_lock(cancelpost) && bbslink_get_lock(cancelfile)) + { + sprintf(cancelfile, "%s.%d", cancelpost, getpid()); + Rename(cancelpost, cancelfile); + CANCELFILE = fopen(cancelfile, "r"); + while (fgets(result, sizeof result, CANCELFILE) != NULL) + { + /* chop( $_ ); */ + char *board, *filename, *userid, *nickname, *subject; + char *ptr, **sptr; + + ptr = strchr(result, '\n'); + if (ptr) + *ptr = '\0'; + board = filename = userid = nickname = subject = NULL; + + /* board field */ + board = result; + ptr = strchr(result, '\t'); + if (ptr == NULL) + continue; + *ptr++ = '\0'; + + /* filename field */ + filename = ptr; + ptr = strchr(ptr, '\t'); + if (ptr == NULL) + continue; + *ptr++ = '\0'; + + /* userid field */ + userid = ptr; + ptr = strchr(ptr, '\t'); + if (ptr == NULL) + continue; + *ptr++ = '\0'; + + /* nickname field */ + nickname = ptr; + ptr = strchr(ptr, '\t'); + if (ptr == NULL) + continue; + *ptr++ = '\0'; + + /* subject field */ + subject = ptr; + /* ptr = strchr(ptr, '\t'); if (ptr == NULL) continue; ptr++ = '\0'; */ + if(!is_outgo_post(board, filename, userid, nickname, subject)) + process_cancel(board, filename, userid, nickname, subject); + } + fclose(CANCELFILE); + if (Verbose) + printf("Unlinking %s\n", cancelfile); + if (!NoAction) + unlink(cancelfile); + bbslink_un_lock(cancelfile); + bbslink_un_lock(cancelpost); + } + } + + for (nlcount = 0; nlcount < NLCOUNT; nlcount++) + { + if (NODELIST[nlcount].feedfp != NULL) + { + fclose(NODELIST[nlcount].feedfp); + NODELIST[nlcount].feedfp = NULL; + } + } + + send_article(); + for (nlcount = 0; nlcount < NLCOUNT; nlcount++) + { + int localsendout, remotesendout, localfailed, remotefailed; + + localsendout = BBSLINK_STAT[nlcount].localsendout; + remotesendout = BBSLINK_STAT[nlcount].remotesendout; + localfailed = BBSLINK_STAT[nlcount].localfailed; + remotefailed = BBSLINK_STAT[nlcount].remotefailed; + if (localsendout || remotesendout || localfailed || remotefailed) + bbslog(" [%s]%s lsend:%d rsend:%d lfail:%d rfail:%d\n", + NODELIST[nlcount].node, NoAction ? "NoAction" : "", localsendout, remotesendout, + localfailed, remotefailed); + if (NODELIST[nlcount].feedfp != NULL) + { + fclose(NODELIST[nlcount].feedfp); + NODELIST[nlcount].feedfp = NULL; + } + } + if (BBSLINK_STAT); + free(BBSLINK_STAT); + return 0; +} +/* +termbbslink(sig) + int sig; +{ + bbslog("kill signal received %d, terminated\n", sig); + if (Verbose) + printf("kill signal received %d, terminated\n", sig); + exit(0); +} +*/ +void +termbbslink() +{ + bbslog("kill signal received ??, terminated\n"); + if (Verbose) + printf("kill signal received ??, terminated\n"); + exit(0); +} + +char *REMOTEUSERNAME = ""; +char *REMOTEHOSTNAME = ""; + +extern char *optarg; +extern int opterr, optind; + +main(argc, argv) + int argc; + char **argv; +{ + int c, errflag = 0; + + CONTROL = CONTROL_BUF; + MSGID = MSGID_BUF; + + /* For debug Only */ +#define DEBUGBBSLINK + +#ifdef DEBUGBBSLINK + NoAction = 0; + Verbose = 0; + VisitOnly = 0; + NoVisit = 0; + DefaultFeedSite = ""; +#endif + + while ((c = getopt(argc, argv, "s:hnvVNk")) != -1) + switch (c) + { + case 's': + DefaultFeedSite = optarg; + break; + case 'n': + NoAction = 1; + break; + case 'v': + Verbose = 1; + break; + case 'V': + VisitOnly = 1; + break; + case 'N': + NoVisit = 1; + break; + case 'k': + KillFormerBBSLINK = 1; + break; + case 'h': + default: + errflag++; + break; + } + if (errflag > 0) + { + show_usage(argv[0]); + return (1); + } + if (argc - optind < 1) + { + show_usage(argv[0]); + exit(1); + } + signal(SIGTERM, termbbslink); + if (bntplink(argc - optind, argv + optind) != 0) + { + show_usage(argv[0]); + exit(1); + } + return 0; +} diff --git a/pttbbs/innbbsd/bbslink2.c b/pttbbs/innbbsd/bbslink2.c new file mode 100644 index 00000000..d79c23a9 --- /dev/null +++ b/pttbbs/innbbsd/bbslink2.c @@ -0,0 +1,2017 @@ +#if defined( LINUX ) +# include "innbbsconf.h" +# include "bbslib.h" +# include +#else +# include +# include "innbbsconf.h" +# include "bbslib.h" +#endif + +#include + +#ifndef AIX +# include +#endif + +#if defined(PalmBBS) +#include +#endif + + +#include "daemon.h" +#include "nntp.h" +#include "externs.h" + +/* + * TODO 1. read newsfeeds.bbs, read nodelist.bbs, read bbsname.bbs 2. scan + * new posts and append to .link 3. rename .link to .send (must lock) 4. + * start to send .send out and append not sent to .link + * + * 5. node.LOCK (with pid) 6. log articles sent + */ + + +#ifndef MAXBUFLEN +#define MAXBUFLEN 256 +#endif + +typedef struct Over_t +{ + time_t mtime; + char date[MAXBUFLEN]; + char nickname[MAXBUFLEN]; + char subject[MAXBUFLEN]; + char from[MAXBUFLEN]; + char msgid[MAXBUFLEN]; + char site[MAXBUFLEN]; + char board[MAXBUFLEN]; +} linkoverview_t; + +typedef struct SendOver_t +{ + char *board, *filename, *group, *from, *subject; + char *outgoingtype, *msgid, *path; + char *date, *control; + time_t mtime; +} soverview_t; + +typedef struct Stat_t +{ + int localsendout; + int localfailed; + int remotesendout; + int remotefailed; +} stat_t; + +static stat_t *BBSLINK_STAT; + +static int NoAction = 0; +static int Verbose = 0; +static int VisitOnly = 0; +static int NoVisit = 0; +static char *DefaultFeedSite = ""; +static int KillFormerBBSLINK = 0; + +extern char *SITE; +extern char *GROUPS; + +char NICKNAME[MAXBUFLEN]; + +char DATE_BUF[MAXBUFLEN]; +extern char *DATE; + +char FROM_BUF[MAXBUFLEN]; +extern char *FROM; + +#ifndef MapleBBS +char POSTER_BUF[MAXBUFLEN]; +char *POSTER; +#endif + +char MYADDR[MAXBUFLEN]; +char MYSITE[MAXBUFLEN]; + +char SUBJECT_BUF[MAXBUFLEN]; +extern char *SUBJECT; + +char MSGID_BUF[MAXBUFLEN]; +extern char *MSGID; + +char LINKPROTOCOL[MAXBUFLEN]; +int LINKPORT; +char ORGANIZATION[MAXBUFLEN]; +char NEWSCONTROL[MAXBUFLEN]; +char NEWSAPPROVED[MAXBUFLEN]; +char NNTPHOST_BUF[MAXBUFLEN]; +extern char *NNTPHOST; +char PATH_BUF[MAXBUFLEN]; +extern char *PATH; + +char CONTROL_BUF[MAXBUFLEN]; +extern char *CONTROL; + +char *BODY, *HEAD; + +int USEIHAVE = 1; +int USEPOST = 0; +int USEDATA = 0; +int FEEDTYPE = ' '; + +int NNTP = -1; +FILE *NNTPrfp = NULL; +FILE *NNTPwfp = NULL; +char NNTPbuffer[1024]; +static char *NEWSFEED; +static char *REMOTE = "REMOTE"; +static char *LOCAL = "LOCAL"; + +static int FD, FD_SIZE; +static char *FD_BUF; +static char *FD_END; + +static char *COMMENT = +"[Ptt 送出]\n"; + +char *fileglue(); + +/* +woju +Cross-fs rename() +*/ + +Rename(char* src, char* dst) +{ + char cmd[200]; + + if (rename(src, dst) == 0) + return 0; + + sprintf(cmd, "/bin/mv %s %s", src, dst); + return system(cmd); + +} + + +bbslink_un_lock(file) + char *file; +{ + char *lockfile = fileglue("%s.LOCK", file); + + if (isfile(lockfile)) + unlink(lockfile); +} + +bbslink_get_lock(file) + char *file; +{ + int lockfd; + char LockFile[MAXPATHLEN]; + + strncpy(LockFile, (char *) fileglue("%s.LOCK", file), sizeof LockFile); + if ((lockfd = open(LockFile, O_RDONLY)) >= 0) + { + char buf[10]; + int pid; + + if (read(lockfd, buf, sizeof buf) > 0 && + (pid = atoi(buf)) > 0 && kill(pid, 0) == 0) + { + if (KillFormerBBSLINK) + { + kill(pid, SIGTERM); + unlink(LockFile); + } + else + { + fprintf(stderr, "another process [%d] running\n", pid); + return 0; + } + } + else + { + fprintf(stderr, "no process [%d] running, but lock file existed, unlinked\n", pid); + unlink(LockFile); + } + close(lockfd); + } + + if ((lockfd = open(LockFile, O_RDWR | O_CREAT | O_EXCL, 0644)) < 0) + { + fprintf(stderr, "lock %s error: another bbslink process running\n", LockFile); + return 0; + } + else + { + char buf[10]; + int pid; + + sprintf(buf, "%-.8d\n", getpid()); + write(lockfd, buf, strlen(buf)); + close(lockfd); + return 1; + } +} + + +int +tcpcommand(va_alist) +va_dcl +{ + va_list ap; + register char *fmt; + char *ptr; + + va_start(ap); + fmt = va_arg(ap, char *); + vfprintf(NNTPwfp, fmt, ap); + fprintf(NNTPwfp, "\r\n"); + fflush(NNTPwfp); + + fgets(NNTPbuffer, sizeof NNTPbuffer, NNTPrfp); + ptr = strchr(NNTPbuffer, '\r'); + if (ptr) + *ptr = '\0'; + ptr = strchr(NNTPbuffer, '\n'); + if (ptr) + *ptr = '\0'; + va_end(ap); + return atoi(NNTPbuffer); +} + +char * +tcpmessage() +{ + char *ptr; + + ptr = strchr(NNTPbuffer, ' '); + if (ptr) + return ptr; + return NNTPbuffer; +} + +read_article(lover, filename, userid) + linkoverview_t *lover; + char *filename, *userid; +{ + FILE *fp; + int fd; + struct stat st; + time_t mtime; + char *buffer; + char *artptr, *artend, *artback; + + if (stat(filename, &st) != 0) + return 0; + lover->mtime = st.st_mtime; + fd = open(filename, O_RDONLY); + if (fd < 0) + { + bbslog(" Err: can't open %s\n", filename); + return 0; + } + + if (FD_BUF == NULL) + { + FD_BUF = mymalloc(st.st_size + 1 + strlen(COMMENT)); + } + else + { + FD_BUF = myrealloc(FD_BUF, st.st_size + 1 + strlen(COMMENT)); + } + FD_BUF[st.st_size] = '\0'; + read(fd, FD_BUF, st.st_size); + sprintf(FD_BUF + st.st_size, "%s", COMMENT); + st.st_size += strlen(COMMENT); + FD_SIZE = st.st_size; + for (buffer = FD_BUF, artend = FD_BUF + st.st_size, + artback = strchr(buffer, '\n'); + buffer && buffer < artend && *buffer; + artback = strchr(buffer, '\n') + ) + { + /* while( fgets(buffer, sizeof buffer, fp) != NULL) { */ + char *m, *n; + char *ptr; + + if (artback != NULL) + *artback = '\0'; + if (*buffer == '\0') + break; + +#ifndef MapleBBS + if (strstr(buffer, userid) != NULL) + { + m = strchr(buffer, '('); + n = strrchr(buffer, ')'); + if (m != NULL && n != NULL) + { + strncpy(lover->nickname, m + 1, n - m - 1); + lover->nickname[n - m - 1] = '\0'; + } + else + { + *lover->nickname = '\0'; + } + } + else if (strncmp(buffer, "Date: ", 11) == 0) + { + strcpy(lover->date, buffer + 11); + } + else if (strncmp(buffer, "發信站: ", 8) == 0) + { + m = strchr(buffer, '('); + n = strrchr(buffer, ')'); + strncpy(lover->date, m + 1, n - m - 1); + lover->date[n - m - 1] = '\0'; + } +#endif + + if (artback != NULL) + { + *artback = '\n'; + buffer = artback + 1; + } + else + { + break; + } + } + if (artback != NULL) + BODY = artback + 1; + else + BODY = ""; + close(fd); + return 1; +} + +save_outgoing(sover, filename, userid, poster, mtime) + soverview_t *sover, *filename, *userid, *poster; + time_t mtime; +{ + newsfeeds_t *nf; + char *group, *server, *serveraddr; + char *subject, *path; + char *board; + char *ptr1, *ptr2; + + board = sover->board; + + PATH = MYBBSID; + nf = (newsfeeds_t *) search_board(board); + if (nf == NULL) + { + bbslog(" save_outgoing: No such board %s\n", board); + return; + } + else + { + group = nf->newsgroups; + server = nf->path; + } + if (!server || !*server) + { + sprintf(PATH_BUF, "%.*s (local)", sizeof PATH_BUF - 9, MYBBSID); + PATH = PATH_BUF; + serveraddr = ""; + sover->path = PATH; + } + for (ptr1 = server; ptr1 && *ptr1;) + { + nodelist_t *nl; + char savech; + + for (; *ptr1 && isspace(*ptr1); ptr1++); + if (!*ptr1) + break; + for (ptr2 = ptr1; *ptr2 && !isspace(*ptr2); ptr2++); + savech = *ptr2; + *ptr2 = '\0'; + nl = (nodelist_t *) search_nodelist_bynode(ptr1); + *ptr2 = savech; + ptr1 = ptr2++; + if (nl == NULL) + continue; + /* if (nl->feedfp == NULL) continue; */ + + if (nl->host && *nl->host) + { + if (nl->feedfp == NULL) + { + nl->feedfp = fopen(fileglue("%s/%s.link", INNDHOME, nl->node), "a"); + if (nl->feedfp == NULL) + { + bbslog(" append failed for %s/%s.link", INNDHOME, nl->node); + } + } + if (nl->feedfp != NULL) + { + flock(fileno(nl->feedfp), LOCK_EX); + fprintf(nl->feedfp, "%s\t%s\t%s\t%ld\t%s\t%s\n", sover->board, filename, group, mtime, FROM, sover->subject); + fflush(nl->feedfp); + flock(fileno(nl->feedfp), LOCK_UN); + } + } + if (savech == '\0') + break; + } +} + + +#ifndef MapleBBS +save_article(board, filename, sover) + char *board, *filename; + soverview_t *sover; +{ + FILE *FN; + + if (Verbose) + printf(" %s %s\n", board, filename); + FN = fopen(fileglue("%s/boards/%s/%s", BBSHOME, board, filename), "w"); + if (FN == NULL) + { + bbslog(" err: %s %s\n", board, filename); + if (Verbose) + printf(" err: %s %s\n", board, filename); + return 0; + } + flock(fileno(FN), LOCK_EX); + fprintf(FN, "發信人: %s, 信區: %s\n", POSTER, sover->board); + fprintf(FN, "標 題: %s\n", sover->subject); + fprintf(FN, "發信站: %s (%s)\n", MYSITE, sover->date); + fprintf(FN, "轉信站: %s\n", sover->path); + fprintf(FN, "\n"); + fputs(BODY, FN); + flock(fileno(FN), LOCK_UN); + fclose(FN); + +#if defined(PalmBBS) + { + struct utimbuf times; + + times.actime = sover->mtime; + times.modtime = sover->mtime; + utime(fileglue("%s/boards/%s/%s", BBSHOME, board, filename), ×); + utime(fileglue("%s/.bcache/%s", BBSHOME, board), NULL); + } +#endif +} +#endif + +/* process_article() read_article() save_outgoing() save_article() */ + +process_article(board, filename, userid, nickname, subject) + char *board, *filename, *userid, *nickname, *subject; +{ + char *n, *filepath; + char poster[MAXBUFLEN]; + soverview_t sover; + + if (!*userid) + { + return; + } + else if (!subject || !*subject) + { + subject = "無題"; + } + filepath = fileglue("%s/boards/%s/%s", BBSHOME, board, filename); + if (isfile(filepath)) + { + linkoverview_t lover; + + if (read_article(&lover, filepath, userid)) + { + +#ifndef MapleBBS + strncpy(POSTER_BUF, fileglue("%s@%s (%s)", userid, MYBBSID, nickname), sizeof POSTER_BUF); + POSTER = POSTER_BUF; +#endif + + strncpy(FROM_BUF, fileglue("%s.bbs@%s (%s)", userid, MYADDR, nickname), sizeof FROM_BUF); + FROM = FROM_BUF; + sover.from = FROM; + sover.board = board; + sover.subject = subject; + PATH = MYBBSID; + sover.path = MYBBSID; + sover.date = lover.date; + sover.mtime = lover.mtime; + if (!VisitOnly) + { + save_outgoing(&sover, filename, userid, poster, lover.mtime); + +#ifndef MapleBBS + save_article(board, filename, &sover); +#endif + } + } + } +} + + +char * +baseN(val, base, len) + int val, base, len; +{ + int n, ans; + static char str[MAXBUFLEN]; + char *pstr = str; + int index; + + for (index = len - 1; index >= 0; index--) + { + n = val % base; + val /= base; + if (n < 10) + { + n += '0'; + } + else if (n < 36) + { + n += 'A' - 10; + } + else if (n < 62) + { + n += 'a' - 36; + } + else + { + n = '_'; + } + str[index] = n; + } + str[len] = '\0'; + return str; +} + +char * +hash_value(str) + char *str; +{ + int val, n; + char *ptr; + + if (*str) + ptr = str + strlen(str) - 1; + else + ptr = str; + val = 0; + while (ptr >= str) + { + n = *ptr; + val = (val + n * 0x100) ^ n; + ptr--; + } + return baseN(val, 64, 3); +} + +/* process_cancel() save_outgoing() hash_value(); baseN(); ascii_date(); */ + + +read_outgoing(sover) + soverview_t *sover; +{ + char *board, *filename, *group, *from, *subject, *outgoingtype, *msgid, *path; + char *buffer, *bufferp; + FILE *ECHOMAIL, *FN; + char *hash; + char times[MAXBUFLEN]; + time_t mtime; + + board = sover->board; + filename = sover->filename; + group = sover->group; + mtime = sover->mtime; + from = sover->from; + subject = sover->subject; + outgoingtype = sover->outgoingtype; + msgid = sover->msgid; + path = sover->path; + if (Verbose) + { + printf(" %s:%s:%s\n", board, filename, group); + printf(" => %ld:%s\n", mtime, from); + printf(" => %s\n", subject); + printf(" => %s:%s\n", outgoingtype, msgid); + printf(" => %s\n", path); + } + if (NEWSFEED == LOCAL) + { + char *end = strrchr(filename, '.'); + + if (end) + *end = '\0'; + strncpy(times, baseN(atol(filename + 2), 48, 6), sizeof times); + if (end) + *end = '.'; + hash = hash_value(fileglue("%s.%s", filename, board)); + sprintf(MSGID_BUF, "%s$%s@%s", times, hash, MYADDR); + } + else + { + strncpy(MSGID_BUF, msgid, sizeof MSGID_BUF); + } + sover->msgid = MSGID; + if (mtime == -1) + { + static char BODY_BUF[MAXBUFLEN]; + + strncpy(BODY_BUF, fileglue("%s\r\n", subject), sizeof BODY_BUF); + BODY = BODY_BUF; + sprintf(SUBJECT_BUF, "cmsg cancel <%s>", MSGID); + SUBJECT = SUBJECT_BUF; + sprintf(CONTROL_BUF, "cancel <%s>", MSGID); + CONTROL = CONTROL_BUF; + strncpy(MSGID_BUF, fileglue("%d.%s", getpid(), MSGID_BUF), sizeof MSGID_BUF); + sprintf(DATE_BUF, "%s", ascii_date(time(NULL))); + DATE = DATE_BUF; + sover->subject = SUBJECT; + sover->control = CONTROL; + sover->msgid = MSGID; + sover->date = DATE; + } + else + { + sover->control = CONTROL; + sover->date = DATE_BUF; + DATE = DATE_BUF; + *CONTROL = '\0'; + sprintf(DATE, "%s", ascii_date((mtime))); + if (NEWSFEED == LOCAL && !NoAction) + { + SITE = MYSITE; + PATH = MYBBSID; + GROUPS = group; + +#ifndef MapleBBS + echomaillog(); +#endif + } + BODY = ""; + FD = open(fileglue("%s/boards/%s/%s", BBSHOME, board, filename), O_RDONLY); + if (FD < 0) + { + if (Verbose) + printf(" !! can't open %s/boards/%s/%s\n", BBSHOME, board, filename); + else + fprintf(stderr, "can't open %s/boards/%s/%s\n", BBSHOME, board, filename); + return -1; + } + + FD_SIZE = filesize(fileglue("%s/boards/%s/%s", BBSHOME, board, filename)); + if (FD_BUF == NULL) + { + FD_BUF = (char *) mymalloc(FD_SIZE + 1 + strlen(COMMENT)); + } + else + { + FD_BUF = (char *) myrealloc(FD_BUF, FD_SIZE + 1 + strlen(COMMENT)); + } + FD_END = FD_BUF + FD_SIZE; + *FD_END = '\0'; + read(FD, FD_BUF, FD_SIZE); + sprintf(FD_END, "%s", COMMENT); + FD_SIZE += strlen(COMMENT); + FD_END += strlen(COMMENT); + if (Verbose) + { + printf(" %s/boards/%s/%s\n", BBSHOME, board, filename); + } + + *ORGANIZATION = '\0'; + *NEWSCONTROL = '\0'; + *NEWSAPPROVED = '\0'; + *NNTPHOST_BUF = '\0'; + NNTPHOST = NULL; + + for (buffer = FD_BUF, bufferp = strchr(buffer, '\n'); + buffer && *buffer; bufferp = strchr(buffer, '\n')) + { + if (bufferp) + *bufferp = '\0'; + if (*buffer == '\0') + { + break; + } + /* printf("get buffer %s\n", buffer); */ + if (NEWSFEED == REMOTE) + { + if (strncmp(buffer, "Date: ", 11) == 0) + { + strcpy(DATE_BUF, buffer + 11); + DATE = DATE_BUF; + } + else if (strncmp(buffer, "發信站: ", 8) == 0) + { + char *m, *n; + + m = strchr(buffer, '('); + n = strrchr(buffer, ')'); + if (m && n) + { + strncpy(DATE_BUF, m + 1, n - m - 1); + DATE_BUF[n - m - 1] = '\0'; + DATE = DATE_BUF; + strncpy(ORGANIZATION, buffer + 8, m - 8 - buffer - 1); + ORGANIZATION[m - 8 - buffer - 1] = '\0'; + } + } + else if (strncmp(buffer, "Control: ", 9) == 0) + { + strcpy(NEWSCONTROL, buffer + 9); + } + else if (strncmp(buffer, "Approved: ", 10) == 0) + { + strcpy(NEWSAPPROVED, buffer + 10); + } + else if (strncmp(buffer, "Origin: ", 8) == 0) + { + strcpy(NNTPHOST_BUF, buffer + 8); + NNTPHOST = NNTPHOST_BUF; + } + } + if (bufferp) + { + *bufferp = '\n'; + buffer = bufferp + 1; + } + else + { + break; + } + } + if (bufferp) + { + BODY = bufferp + 1; + } + else + BODY = ""; + if (bufferp) + for (buffer = bufferp + 1, bufferp = strchr(buffer, '\n'); + buffer && *buffer; bufferp = strchr(buffer, '\n')) + { + if (bufferp) + *bufferp = '\0'; + /* printf("get line (%s)\n", buffer); */ + /* if( strcmp(buffer,".")==0 ) { buffer[1]='.'; buffer[2]='\0'; } */ + if (NEWSFEED == REMOTE && + strncmp(NEWSCONTROL, "cancel", 5) == 0 && + strncmp(buffer, "------------------", 18) == 0) + { + break; + } + /* $BODY[ @BODY ] = "$_\r\n"; */ + if (bufferp) + { + *bufferp = '\n'; + buffer = bufferp + 1; + } + else + { + break; + } + } + /* # fprintf("BODY @BODY\n"; */ + close(FD); + } + return 0; +} + +#ifdef TEST +#endif + +openfeed(node) + nodelist_t *node; +{ + if (node->feedfp == NULL) + { + node->feedfp = fopen(fileglue("%s/%s.link", INNDHOME, node->node), "a"); + } +} + +queuefeed(node, textline) + nodelist_t *node; + char *textline; +{ + openfeed(node); + if (node->feedfp != NULL) + { + flock(fileno(node->feedfp), LOCK_EX); + fprintf(node->feedfp, "%s", textline); + fflush(node->feedfp); + flock(fileno(node->feedfp), LOCK_UN); + } +} + +post_article(node, site, sover, textline) + nodelist_t *node; + char *site; + soverview_t *sover; + char *textline; +{ + int status; + char *filename = sover->filename; + char *msgid = sover->msgid; + char *board = sover->board; + char *bodyp, *body; + + if (Verbose) + fprintf(stdout, " %s %s %s\n", site, filename, msgid); + if (NoAction && Verbose) + { + printf(" ==>%s\n", sover->path); + printf(" ==>%s:%s\n", sover->from, sover->group); + printf(" ==>%s:%s\n", sover->subject, sover->date); + body = BODY; + bodyp = strchr(body, '\n'); + if (bodyp) + *bodyp = '\0'; + printf(" ==>%s\n", body); + if (bodyp) + *bodyp = '\n'; + if (bodyp) + { + body = bodyp + 1; + bodyp = strchr(body, '\n'); + if (bodyp) + *bodyp = '\0'; + printf(" ==>%s\n", body); + if (bodyp) + *bodyp = '\n'; + } + } + if (NoAction) + return 1; + if (NEWSFEED == REMOTE) + { + fprintf(NNTPwfp, "Path: %s\r\n", sover->path); + fprintf(NNTPwfp, "From: %s\r\n", sover->from); + fprintf(NNTPwfp, "Newsgroups: %s\r\n", sover->group); + fprintf(NNTPwfp, "Subject: %s\r\n", sover->subject); + /* # fprintf( NNTPwfp,"Post with subject ($subject)\n"); */ + fprintf(NNTPwfp, "Date: %s\r\n", sover->date); + if (*ORGANIZATION) + fprintf(NNTPwfp, "Organization: %s\r\n", ORGANIZATION); + fprintf(NNTPwfp, "Message-ID: <%s>\r\n", sover->msgid); + if (*NEWSCONTROL) + fprintf(NNTPwfp, "Control: %s\r\n", NEWSCONTROL); + if (*NEWSAPPROVED) + fprintf(NNTPwfp, "Approved: %s\r\n", NEWSAPPROVED); + } + else + { + fprintf(NNTPwfp, "Path: %s\r\n", MYBBSID); + fprintf(NNTPwfp, "From: %s\r\n", sover->from); + fprintf(NNTPwfp, "Newsgroups: %s\r\n", sover->group); + fprintf(NNTPwfp, "Subject: %s\r\n", sover->subject); + fprintf(NNTPwfp, "Date: %s\r\n", sover->date); + fprintf(NNTPwfp, "Organization: %s\r\n", MYSITE); + fprintf(NNTPwfp, "Message-ID: <%s>\r\n", sover->msgid); + fprintf(NNTPwfp, "X-Filename: %s/%s\r\n", sover->board, sover->filename); + } + if (NNTPHOST && *NNTPHOST && USEIHAVE) + fprintf(NNTPwfp, "NNTP-Posting-Host: %s\r\n", NNTPHOST); + else if (NNTPHOST && *NNTPHOST) + fprintf(NNTPwfp, "X-Auth-From: %s\r\n", NNTPHOST); + if (*CONTROL) + { + fprintf(NNTPwfp, "Control: %s\r\n", CONTROL); + } + fputs("\r\n", NNTPwfp); + for (body = BODY, bodyp = strchr(body, '\n'); + body && *body; bodyp = strchr(body, '\n')) + { + if (bodyp) + *bodyp = '\0'; + + fputs(body, NNTPwfp); + if (body[0] == '.' && body[1] == '\0') + fputs(".", NNTPwfp); + fputs("\r\n", NNTPwfp); + if (bodyp) + { + *bodyp = '\n'; + body = bodyp + 1; + } + else + { + break; + } + } + /* print "send out @BODY\n"; */ + status = tcpcommand("."); + /* 435 duplicated article 437 invalid header */ + + if (USEIHAVE) + { + if (status == 235) + { + if (NEWSFEED == LOCAL) + { + bbslog("Sendout <%s> from %s/%s\n", msgid, board, filename); + } + } + else if (status == 437 || status == 435) + { + bbslog(" :Warn: %d %s <%s>\n", status, (char *) tcpmessage(), msgid); + if (Verbose) + printf(":Warn: %d %s <%s>\n", status, (char *) tcpmessage(), msgid); + return 0; + } + else + { + bbslog(" :Err: %d %s of <%s>\n", status, (char *) tcpmessage(), msgid); + if (Verbose) + printf(":Err: %d %s of <%s>\n", status, (char *) tcpmessage(), msgid); + queuefeed(node, textline); + return 0; + } + } + else if (USEPOST) + { + if (status == 240) + { + bbslog("Sendout <%s> from %s/%s\n", msgid, board, filename); + } + else + { + bbslog(" :Err: %d %s of <%s>\n", status, (char *) tcpmessage(), msgid); + queuefeed(node, textline); + return 0; + } + } + else + { + if (status == 250) + { + bbslog(" DATA Sendout <%s> from %s/%s\n", msgid, board, filename); + if (Verbose) + printf(" <%s> from %s/%s\n", msgid, board, filename); + } + else + { + bbslog(" :Err: %d %s of <%s>\n", status, (char *) tcpmessage(), msgid); + if (Verbose) + printf(":Err: %d %s of <%s>\n", status, (char *) tcpmessage(), msgid); + queuefeed(node, textline); + return 0; + } + } + return 1; +} + +process_cancel(board, filename, userid, nickname, subject) + char *board, *filename, *userid, *nickname, *subject; +{ + time_t mtime; + soverview_t sover; + + if (!userid || !*userid) + { + return; + } + mtime = -1; + strncpy(FROM_BUF, fileglue("%s.bbs@%s (%s)", userid, MYADDR, nickname), sizeof FROM_BUF); + FROM = FROM_BUF; + sover.from = FROM; + sover.board = board; + sover.subject = subject; + PATH = MYBBSID; + sover.path = MYBBSID; + /* save_outgoing(&sover, filename, userid, poster, -1); */ + save_outgoing(&sover, filename, userid, userid, -1); +} + +open_link(hostname, hostprot, hostport) + char *hostname, *hostprot, *hostport; +{ + USEIHAVE = 1; + USEPOST = 0; + USEDATA = 0; + FEEDTYPE = ' '; + if (Verbose) + printf(" %s %s %s\n", hostname, hostprot, hostport); + if (strncasecmp(hostprot, "IHAVE", 5) != 0) + { + USEIHAVE = 0; + USEPOST = 1; + if (strncasecmp(hostprot, "POST", 4) == 0) + { + USEPOST = 1; + } + else if (strncasecmp(hostprot, "DATA", 4) == 0) + { + USEPOST = 0; + USEDATA = 1; + } + } + + FEEDTYPE = hostname[0]; + if (!USEDATA) + { + char *atsign; + + if (FEEDTYPE == '-' || FEEDTYPE == '+') + { + hostname = hostname + 1; + } + atsign = strchr(hostname, '@'); + if (atsign != NULL) + { + hostname = atsign + 1; + } + if (!NoAction) + { + if (Verbose) + printf(" %s %s\n", hostname, hostport); + if ((NNTP = inetclient(hostname, hostport, "tcp")) < 0) + { + bbslog(" :Err: server %s %s error: cant connect\n", hostname, hostport); + if (Verbose) + printf(":Err: server %s %s error: cant connect\n", hostname, hostport); + return 0; + /* exit( 0 ); */ + /* return; */ + } + NNTPrfp = fdopen(NNTP, "r"); + NNTPwfp = fdopen(NNTP, "w"); + fgets(NNTPbuffer, sizeof NNTPbuffer, NNTPrfp); + if (atoi(NNTPbuffer) != 200) + { + bbslog(" :Err: server error: %s", NNTPbuffer); + if (Verbose) + printf(":Err: server error: %s", NNTPbuffer); + return 0; + /* exit( 0 ); */ + } + } + else + { + if (Verbose) + printf(" %s %s\n", hostname, hostport); + } + } + else + { + if (!NoAction) + { + if (Verbose) + printf(" localhost %s\n", hostport); + if ((NNTP = inetclient("localhost", hostport, "tcp")) < 0) + { + bbslog(" :Err: server %s port %s error: cant connect\n", hostname, hostport); + if (Verbose) + printf(":Err: server error: cant connect"); + return 0; + /* exit( 0 ); */ + /* return; */ + } + NNTPrfp = fdopen(NNTP, "r"); + NNTPwfp = fdopen(NNTP, "w"); + fgets(NNTPbuffer, sizeof NNTPbuffer, NNTPrfp); + if (strncmp(NNTPbuffer, "220", 3) != 0) + { + bbslog(" :Err: server error: %s", NNTPbuffer); + if (Verbose) + printf(":Err: server error: %s", NNTPbuffer); + return 0; + /* exit( 0 ); */ + } + if (strncmp(NNTPbuffer, "220-", 4) == 0) + { + fgets(NNTPbuffer, sizeof NNTPbuffer, NNTPrfp); + } + } + else + { + if (Verbose) + printf(" %s %s\n", hostname, hostport); + } + } + return 1; +} + +send_outgoing(node, site, hostname, sover, textline) + nodelist_t *node; + soverview_t *sover; + char *hostname, *site; + char *textline; +{ + int status; + char *board, *filepath, *msgid; + int returnstatus = 0; + + board = sover->board; + filepath = sover->filename; + msgid = sover->msgid; + + if (Verbose) + printf(" %s:%s:%s:%s\n", site, board, filepath, msgid); + if (BODY != NULL && !NoAction) + { + if (USEIHAVE) + { + status = tcpcommand("IHAVE <%s>", msgid); + if (status == 335) + { + returnstatus = post_article(node, site, sover, textline); + } + else if (status == 435) + { + bbslog(" :Warn: %d %s, IHAVE <%s>\n", status, (char *) tcpmessage(), msgid); + if (Verbose) + printf(":Warn: %d %s, IHAVE <%s>\n", status, (char *) tcpmessage(), msgid); + returnstatus = 0; + } + else + { + bbslog(" :Err: %d %s, IHAVE <%s>\n", status, (char *) tcpmessage(), msgid); + if (Verbose) + printf(":Err: %d %s, IHAVE <%s>\n", status, (char *) tcpmessage(), msgid); + queuefeed(node, textline); + returnstatus = 0; + } + } + else if (USEPOST) + { + tcpcommand("MODE READER"); + status = tcpcommand("POST"); + if (status == 340) + { + returnstatus = post_article(node, site, sover, textline); + } + else if (status == 441) + { + bbslog(" :Warn: %d %s, POST <%s>\n", status, (char *) tcpmessage(), msgid); + if (Verbose) + printf(":Warn: %d %s, POST <%s>\n", status, (char *) tcpmessage(), msgid); + returnstatus = 0; + } + else + { + bbslog(" :Err: %d %s, POST <%s>\n", status, (char *) tcpmessage(), msgid); + if (Verbose) + printf(":Err: %d %s, POST <%s>\n", status, (char *) tcpmessage(), msgid); + queuefeed(node, textline); + returnstatus = 0; + } + } + else + { + tcpcommand("HELO"); + tcpcommand("MAIL FROM: bbs"); + tcpcommand("RCPT TO: %s", hostname); + status = tcpcommand("DATA"); + if (status == 354) + { + returnstatus = post_article(node, site, sover, textline); + } + else + { + bbslog(" :Err: %d %s, DATA <%s>\n", status, (char *) tcpmessage(), msgid); + if (Verbose) + printf(":Err: %d %s, DATA <%s>\n", status, (char *) tcpmessage(), msgid); + + queuefeed(node, textline); + returnstatus = 0; + } + } + } + else if (NoAction) + { + returnstatus = post_article(node, site, sover, textline); + } + return returnstatus; +} + +save_nntplink(node, overview) + nodelist_t *node; + char *overview; +{ + FILE *POSTS; + char buffer[1024]; + + openfeed(node); + POSTS = fopen(overview, "r"); + if (POSTS == NULL) + return 0; + openfeed(node); + /* if (node->feedfp == NULL) return 0; */ + flock(fileno(node->feedfp), LOCK_EX); + while (fgets(buffer, sizeof buffer, POSTS) != NULL) + { + fputs(buffer, node->feedfp); + fflush(node->feedfp); + } + flock(fileno(node->feedfp), LOCK_UN); + fclose(POSTS); + if (Verbose) + printf(" %s\n", overview); + if (!NoAction) + unlink(overview); + return 1; +} + + +char * +get_tmpfile(tmpfile) + char *tmpfile; +{ + FILE *FN; + static char result[256]; + + FN = fopen(tmpfile, "r"); + fgets(result, sizeof result, FN); + fclose(FN); + unlink(tmpfile); + return (result); +} + +/* cancel moderating posts */ + +cancel_outgoing(board, filename, from, subject) + char *board, *filename, *from, *subject; +{ + char *base, filepath[MAXPATHLEN]; + FILE *FN; + char *result; + char TMPFILE[MAXPATHLEN]; + + if (Verbose) + { + printf(" %s %s %s %s\n", board, filename, from, subject); + } + + sprintf(TMPFILE, "/tmp/cancel_outgoing.%d.%d", getuid(), getpid()); + + bbslog(" Try to move moderated post from %s to deleted\n", board); + if (Verbose) + printf("Try to move moderated post from %s to deleted\n", board); + FN = popen(fileglue("%s/bbspost post %s/boards/deleted > %s", + INNDHOME, BBSHOME, TMPFILE), "w"); + if (FN == NULL) + { + bbslog(" can't run %s/bbspost\n", INNDHOME); + if (Verbose) + printf(" can't run %s/bbspost\n", INNDHOME); + return 0; + } + fprintf(FN, "%s\n", from); + fprintf(FN, "%s\n", subject); + fprintf(FN, "發信人: %s, 信區: %s\n", from, board); + fprintf(FN, "標 題: %s\n", subject); + fprintf(FN, "發信站: %s (%s)\n", MYSITE, DATE); + fprintf(FN, "轉信站: %s\n", MYBBSID); + fputs("\n", FN); + fputs(BODY, FN); + pclose(FN); + result = (char *) get_tmpfile(TMPFILE); + if (strncmp(result, "post to ", 8) == 0) + { + /* try to remove it */ + strncpy(filepath, fileglue("%s/boards/%s/%s", BBSHOME, board, filename), sizeof filepath); + if (isfile(filepath)) + { + Rename(filepath, fileglue("%s.cancel", filepath)); + } + FN = fopen(filepath, "w"); + + fprintf(FN, "發信人: %s, 信區: %s\n", from, board); + fprintf(FN, "標 題:
%s %s %s %s\n", site, hostname, hostprot, hostport); + printf(" ==> %s\n", overview); + } + if (!open_link(hostname, hostprot, hostport)) + { + save_nntplink(node, overview); + return 0; + } + POSTS = fopen(overview, "r"); + if (POSTS == NULL) + { + if (Verbose) + printf("open %s failed\n", overview); + return 0; + } + while (fgets(textline, sizeof textline, POSTS) != NULL) + { + char *linebreak = strchr(textline, '\n'); + char *ptr; + char *board, *filename, *subject, *group, *mtime, *from; + char *outgoingtype; + char *msgid, *path; + soverview_t soverview; + + strcpy(baktextline, textline); + if (linebreak) + *linebreak = '\0'; + + board = "", filename = "", mtime = "", group = "", from = "", subject = ""; + outgoingtype = "", msgid = "", path = ""; + /* get board field */ + board = textline; + ptr = strchr(textline, '\t'); + if (ptr == NULL) + continue; + *ptr++ = '\0'; + + /* filename field */ + filename = ptr; + ptr = strchr(ptr, '\t'); + if (ptr == NULL) + continue; + *ptr++ = '\0'; + + /* group field */ + group = ptr; + ptr = strchr(ptr, '\t'); + if (ptr == NULL) + continue; + *ptr++ = '\0'; + + /* mtime field */ + mtime = ptr; + ptr = strchr(ptr, '\t'); + if (ptr == NULL) + continue; + *ptr++ = '\0'; + + /* from field */ + from = ptr; + ptr = strchr(ptr, '\t'); + if (ptr == NULL) + continue; + *ptr++ = '\0'; + + /* subject */ + subject = ptr; + ptr = strchr(ptr, '\t'); + if (ptr == NULL) + goto try_read_outgoing; + *ptr++ = '\0'; + + /* outgoing type field */ + outgoingtype = ptr; + ptr = strchr(ptr, '\t'); + if (ptr == NULL) + goto try_read_outgoing; + *ptr++ = '\0'; + + /* msgid */ + msgid = ptr; + ptr = strchr(ptr, '\t'); + if (ptr == NULL) + goto try_read_outgoing; + *ptr++ = '\0'; + + /* path */ + path = ptr; + ptr = strchr(ptr, '\t'); + if (ptr == NULL) + goto try_read_outgoing; + +try_read_outgoing: + + NEWSFEED = LOCAL; + if (outgoingtype && msgid && path && *outgoingtype && *msgid && *path) + { + char *left, *right; + + NEWSFEED = REMOTE; + left = strchr(msgid, '<'); + right = strrchr(msgid, '>'); + if (left) + msgid = left + 1; + if (right) + *right = '\0'; + } + soverview.board = board; + soverview.filename = filename; + soverview.group = group; + soverview.mtime = atol(mtime); + soverview.from = from; + soverview.subject = subject; + soverview.outgoingtype = outgoingtype; + soverview.msgid = msgid; + soverview.path = path; + if (read_outgoing(&soverview) == 0) + { + int sendresult = send_outgoing(node, site, hostname, &soverview, baktextline); + int sendfailed = 1 - sendresult; + + if (NEWSFEED == REMOTE) + { + BBSLINK_STAT[nlcount].remotesendout += sendresult; + BBSLINK_STAT[nlcount].remotefailed += sendfailed; + } + else + { + BBSLINK_STAT[nlcount].localsendout += sendresult; + BBSLINK_STAT[nlcount].localfailed += sendfailed; + } + if (node->feedtype == '-') + { + if (!NoAction && sendresult) + cancel_outgoing(board, filename, from, subject); + } + } + } + fclose(POSTS); + close_link(); + if (Verbose) + printf(" %s\n", overview); + if (!NoAction) + unlink(overview); +} + +close_link() +{ + int status; + + if (Verbose) + printf("\n"); + if (NoAction) + return; + status = tcpcommand("QUIT"); + if (status != 205 && status != 221) + { + bbslog(" :Err: Cannot quit message '%d %s'\n", status, (char *) tcpmessage()); + if (Verbose) + printf(":Err: Cannot quit message '%d %s'\n", status, (char *) tcpmessage()); + } + fclose(NNTPwfp); + fclose(NNTPrfp); + close(NNTP); +} + + +/* + * send_article() send_nntplink() read_outgoing() + * + */ + +send_article() +{ + char *site, *addr, *protocol, *port, *op; + char *nntphost; + int nlcount; + + chdir(INNDHOME); + + for (nlcount = 0; nlcount < NLCOUNT; nlcount++) + { + nodelist_t *node; + char linkfile[MAXPATHLEN]; + char sendfile[MAXPATHLEN]; + char feedfile[MAXPATHLEN]; + char feedingfile[MAXPATHLEN]; + char protocol[MAXBUFLEN], port[MAXBUFLEN]; + + node = NODELIST + nlcount; + site = node->node; + nntphost = node->host; + op = node->protocol; + + if (DefaultFeedSite && *DefaultFeedSite) + { + if (strcmp(node->node, DefaultFeedSite) != 0) + continue; + } + + if (op && (strncasecmp(op, "ihave", 5) == 0 || + strncasecmp(op, "post", 4) == 0 || + strncasecmp(op, "data", 4) == 0)) + { + char *left, *right; + + left = strchr(op, '('), right = strrchr(op, ')'); + if (left && right) + { + *left = '\0'; + *right = '\0'; + strncpy(protocol, op, sizeof protocol); + strncpy(port, left + 1, sizeof port); + *left = '('; + *right = ')'; + } + else + { + strncpy(protocol, op, sizeof protocol); + strncpy(port, "nntp", sizeof port); + } + } + else + { + strcpy(protocol, "IHAVE"); + strcpy(port, "nntp"); + } + sprintf(linkfile, "%s.link", site); + sprintf(sendfile, "%s.sending", site); + sprintf(feedfile, "%s.feed", site); + sprintf(feedingfile, "%s.feeding", site); + if (isfile(sendfile) && !iszerofile(sendfile)) + { + if (bbslink_get_lock(sendfile)) + { + send_nntplink(node, site, nntphost, protocol, port, sendfile, nlcount); + bbslink_un_lock(sendfile); + } + } + if (isfile(linkfile) && !iszerofile(linkfile)) + { + if (!NoAction) + { + if (bbslink_get_lock(sendfile) && bbslink_get_lock(linkfile) && + bbslink_get_lock(feedingfile)) + { + if (isfile(sendfile) && !iszerofile(sendfile)) + { + save_nntplink(node, sendfile); + } + if (node->feedfp) + { + fclose(node->feedfp); + node->feedfp = NULL; + } + Rename(linkfile, sendfile); + send_nntplink(node, site, nntphost, protocol, port, sendfile, nlcount); + bbslink_un_lock(linkfile); + bbslink_un_lock(sendfile); + bbslink_un_lock(feedingfile); + } + } + else + { + send_nntplink(node, site, nntphost, protocol, port, linkfile, nlcount); + } + } + if (isfile(feedingfile) && !iszerofile(feedingfile)) + { + if (bbslink_get_lock(feedingfile)) + { + send_nntplink(node, site, nntphost, protocol, port, feedingfile, nlcount); + bbslink_un_lock(feedingfile); + } + } + if (isfile(feedfile) && !iszerofile(feedfile)) + { + if (!NoAction) + { + if (bbslink_get_lock(feedfile) && bbslink_get_lock(feedingfile)) + { + if (isfile(feedingfile) && !iszerofile(feedingfile)) + { + save_nntplink(node, feedingfile); + if (node->feedfp) + { + fclose(node->feedfp); + node->feedfp = NULL; + } + } + Rename(feedfile, feedingfile); + system(fileglue("%s/ctlinnbbsd reload > /dev/null", INNDHOME)); + send_nntplink(node, site, nntphost, protocol, port, feedingfile, nlcount); + bbslink_un_lock(feedfile); + bbslink_un_lock(feedingfile); + } + } + else + { + send_nntplink(node, site, nntphost, protocol, port, feedfile, nlcount); + } + } + } +} + +/* bntplink() bbspost() process_article() process_cancel() send_article() */ + + +show_usage(argv) + char *argv; +{ + fprintf(stderr, "%s initialization failed or improper options !!\n", argv); +/* +woju +*/ + fprintf(stderr, "Usage: %s [options] bbs_home board\n", argv); + fprintf(stderr, " -v (show transmission status)\n"); + fprintf(stderr, " -n (dont send out articles and leave queue untouched)\n"); + fprintf(stderr, " -s site (only process articles sent to site)\n"); + fprintf(stderr, " -V (visit only: bbspost visit)\n"); + fprintf(stderr, " -N (no visit, and only process batch queue)\n"); + fprintf(stderr, " -k (kill the former bbslink process before started)\n\n"); + fprintf(stderr, "本程式要正常執行必須將以下檔案置於 %s/innd 下:\n", BBSHOME); + fprintf(stderr, "bbsname.bbs 設定貴站的 BBS ID (請儘量簡短)\n"); + fprintf(stderr, "nodelist.bbs 設定網路各 BBS 站的 ID, Address 和 fullname\n"); + fprintf(stderr, "newsfeeds.bbs 設定網路信件的 newsgroup board nodelist ...\n"); +} + + +/* +woju +*/ +struct fileheader +{ + char filename[33]; /* M.9876543210.A */ + char savemode; /* file save mode */ + char owner[12 + 2]; /* uid[.] */ + char date[6]; /* [02/02] or space(5) */ + char title[72+ 1]; + unsigned char filemode; /* must be last field @ boards.c */ +}; +typedef struct fileheader fileheader; + + +bntplink(argc, argv) + int argc; + char **argv; +{ +/* +woju + static char *OUTING = ".outing"; +*/ + static char OUTING[MAXPATHLEN]; + fileheader fhdr; + char *fname, *s1, *s2; + char nick[100]; + FILE* fp; + + nodelist_t *nl; + int linkport; + char result[4096]; + char cancelfile[MAXPATHLEN], cancelpost[MAXPATHLEN]; + char bbslink_lockfile[MAXPATHLEN]; + FILE *NEWPOST; + char *left, *right; + int nlcount; + + strcpy(BBSHOME, argv[0]); +/* +woju +*/ + sprintf(OUTING, "%s/boards/%s/", BBSHOME, argv[1]); + fname = OUTING + strlen(OUTING); + + if (initial_bbs("link") == 0) + { + return -1; + } + + BBSLINK_STAT = (stat_t *) malloc(sizeof(stat_t) * (NLCOUNT + 1)); + for (nlcount = 0; nlcount < NLCOUNT; nlcount++) + { + BBSLINK_STAT[nlcount].localsendout = 0; + BBSLINK_STAT[nlcount].remotesendout = 0; + BBSLINK_STAT[nlcount].localfailed = 0; + BBSLINK_STAT[nlcount].remotefailed = 0; + } + + nl = (nodelist_t *) search_nodelist_bynode(MYBBSID); + if (nl == NULL) + { + *MYADDR = '\0'; + *MYSITE = '\0'; + *LINKPROTOCOL = '\0'; + } + else + { + strncpy(MYADDR, nl->host, sizeof MYADDR); + strncpy(LINKPROTOCOL, nl->protocol, sizeof LINKPROTOCOL); + strncpy(MYSITE, nl->comments, sizeof MYSITE); + } + if (Verbose) + { + printf("MYADDR: %s\n", MYADDR); + printf("MYSITE: %s\n", MYSITE); + } + left = strchr(nl->protocol, '('); + right = strrchr(nl->protocol, ')'); + if (left && right) + { + *right = '\0'; + strncpy(LINKPROTOCOL, nl->protocol, sizeof LINKPROTOCOL); + LINKPORT = atoi(left + 1); + *right = ')'; + } + + if (!NoVisit) + { + sprintf(bbslink_lockfile, "%s/.bbslink.visit", INNDHOME); +/* +woju + if (!Rename(fileglue("%s/out.bntp", INNDHOME), OUTING) && bbslink_get_lock(bbslink_lockfile)) +*/ + if (strcpy(fname, ".DIR")) + { + /* When try to visit new post, try to lock it */ + NEWPOST = fopen(OUTING, "r"); + if (NEWPOST == NULL) + { + bbslog(" Err: can't open %s\n", OUTING); +/* +woju + bbslink_un_lock(bbslink_lockfile); +*/ + return -1; + } +#ifdef 0 +woju + while (fgets(result, sizeof result, NEWPOST)) + { + /* chop( $_ ); */ + char *board, *filename, *userid, *nickname, *subject; + char *ptr; + + ptr = strchr(result, '\n'); + if (ptr) + *ptr = '\0'; + + board = filename = userid = nickname = subject = NULL; + /* board field */ + board = result; + ptr = strchr(result, '\t'); + if (ptr == NULL) + continue; + *ptr++ = '\0'; + + /* filename field */ + filename = ptr; + ptr = strchr(ptr, '\t'); + if (ptr == NULL) + continue; + *ptr++ = '\0'; + + /* userid field */ + userid = ptr; + ptr = strchr(ptr, '\t'); + if (ptr == NULL) + continue; + *ptr++ = '\0'; + + /* nickname field */ + nickname = ptr; + ptr = strchr(ptr, '\t'); + if (ptr == NULL) + continue; + *ptr++ = '\0'; + + /* subject field */ + subject = ptr; + /* ptr = strchr(ptr, '\t'); if (ptr == NULL) continue; ptr++ = '\0'; */ + + process_article(board, filename, userid, nickname, subject); + } +#endif + while (fread(&fhdr, sizeof(fhdr), 1, NEWPOST) == 1) { + nick[1] = 0; + strcpy(fname, fhdr.filename); + if (fp = fopen(OUTING, "r")) { + fgets(nick, 100, fp); + if ((s1 = strchr(nick, '(')) && (s2 = strrchr(nick, ')'))) + *s2 = 0; + else + s1 = nick; + fclose(fp); + } + printf("%s\n", fhdr.title); + process_article(argv[1], fhdr.filename, fhdr.owner, s1 + 1, fhdr.title); + } + fclose(NEWPOST); +/* +woju + unlink(OUTING); + bbslink_un_lock(bbslink_lockfile); +*/ + } /* getlock */ + } /* if NoVisit is false */ + +#if 0 +woju + sprintf(cancelpost, "%s/cancel.bntp", INNDHOME); + if (isfile(cancelpost)) + { + FILE *CANCELFILE; + + if (bbslink_get_lock(cancelpost) && bbslink_get_lock(cancelfile)) + { + sprintf(cancelfile, "%s.%d", cancelpost, getpid()); + Rename(cancelpost, cancelfile); + CANCELFILE = fopen(cancelfile, "r"); + while (fgets(result, sizeof result, CANCELFILE) != NULL) + { + /* chop( $_ ); */ + char *board, *filename, *userid, *nickname, *subject; + char *ptr, **sptr; + + ptr = strchr(result, '\n'); + if (ptr) + *ptr = '\0'; + board = filename = userid = nickname = subject = NULL; + + /* board field */ + board = result; + ptr = strchr(result, '\t'); + if (ptr == NULL) + continue; + *ptr++ = '\0'; + + /* filename field */ + filename = ptr; + ptr = strchr(ptr, '\t'); + if (ptr == NULL) + continue; + *ptr++ = '\0'; + + /* userid field */ + userid = ptr; + ptr = strchr(ptr, '\t'); + if (ptr == NULL) + continue; + *ptr++ = '\0'; + + /* nickname field */ + nickname = ptr; + ptr = strchr(ptr, '\t'); + if (ptr == NULL) + continue; + *ptr++ = '\0'; + + /* subject field */ + subject = ptr; + /* ptr = strchr(ptr, '\t'); if (ptr == NULL) continue; ptr++ = '\0'; */ + process_cancel(board, filename, userid, nickname, subject); + } + fclose(CANCELFILE); + if (Verbose) + printf("Unlinking %s\n", cancelfile); + if (!NoAction) + unlink(cancelfile); + bbslink_un_lock(cancelfile); + bbslink_un_lock(cancelpost); + } + } +#endif + + for (nlcount = 0; nlcount < NLCOUNT; nlcount++) + { + if (NODELIST[nlcount].feedfp != NULL) + { + fclose(NODELIST[nlcount].feedfp); + NODELIST[nlcount].feedfp = NULL; + } + } + + send_article(); + for (nlcount = 0; nlcount < NLCOUNT; nlcount++) + { + int localsendout, remotesendout, localfailed, remotefailed; + + localsendout = BBSLINK_STAT[nlcount].localsendout; + remotesendout = BBSLINK_STAT[nlcount].remotesendout; + localfailed = BBSLINK_STAT[nlcount].localfailed; + remotefailed = BBSLINK_STAT[nlcount].remotefailed; + if (localsendout || remotesendout || localfailed || remotefailed) + bbslog(" [%s]%s lsend:%d rsend:%d lfail:%d rfail:%d\n", + NODELIST[nlcount].node, NoAction ? "NoAction" : "", localsendout, remotesendout, + localfailed, remotefailed); + if (NODELIST[nlcount].feedfp != NULL) + { + fclose(NODELIST[nlcount].feedfp); + NODELIST[nlcount].feedfp = NULL; + } + } + if (BBSLINK_STAT); + free(BBSLINK_STAT); + return 0; +} +/* +termbbslink(sig) + int sig; +{ + bbslog("kill signal received %d, terminated\n", sig); + if (Verbose) + printf("kill signal received %d, terminated\n", sig); + exit(0); +} +*/ +void +termbbslink() +{ + bbslog("kill signal received ??, terminated\n"); + if (Verbose) + printf("kill signal received ??, terminated\n"); + exit(0); +} + +char *REMOTEUSERNAME = ""; +char *REMOTEHOSTNAME = ""; + +extern char *optarg; +extern int opterr, optind; + +main(argc, argv) + int argc; + char **argv; +{ + int c, errflag = 0; + + CONTROL = CONTROL_BUF; + MSGID = MSGID_BUF; + + /* For debug Only */ +#define DEBUGBBSLINK + +#ifdef DEBUGBBSLINK + NoAction = 0; + Verbose = 0; + VisitOnly = 0; + NoVisit = 0; + DefaultFeedSite = ""; +#endif + + while ((c = getopt(argc, argv, "s:hnvVNk")) != -1) + switch (c) + { + case 's': + DefaultFeedSite = optarg; + break; + case 'n': + NoAction = 1; + break; + case 'v': + Verbose = 1; + break; + case 'V': + VisitOnly = 1; + break; + case 'N': + NoVisit = 1; + break; + case 'k': + KillFormerBBSLINK = 1; + break; + case 'h': + default: + errflag++; + break; + } + if (errflag > 0) + { + show_usage(argv[0]); + return (1); + } + if (argc - optind < 2) + { + show_usage(argv[0]); + exit(1); + } + signal(SIGTERM, termbbslink); + if (bntplink(argc - optind, argv + optind) != 0) + { + show_usage(argv[0]); + exit(1); + } + return 0; +} diff --git a/pttbbs/innbbsd/bbsnnrp.c b/pttbbs/innbbsd/bbsnnrp.c new file mode 100644 index 00000000..11993629 --- /dev/null +++ b/pttbbs/innbbsd/bbsnnrp.c @@ -0,0 +1,1187 @@ +/* + Usage: bbsnnrp [options] nntpserver activefile + -h|? (help) + -v (verbose protocol transactions) + -c (reset active files only; don't receive articles) + -r remotehost(send articles to remotehost, default=local) + -p port|(send articles to remotehost at port, default=7777) + path(send articles to local at path, default=~bbs/innd/.innbbsd) + -n (don't ask innbbsd server and stat articles) + -w seconds (wait for seconds and run infinitely, default=once) + -a max_art (maximum number of articles received for a group each time) + -s max_stat(maximum number of articles stated for a group each time) + -t stdin|nntp (default=nntp) +*/ + +#include "innbbsconf.h" +#include +#ifndef AIX +# include +#endif +#include "bbslib.h" +#include "daemon.h" +#include "nntp.h" + +#ifndef MAX_ARTS +# define MAX_ARTS 100 +#endif +#ifndef MAX_STATS +# define MAX_STATS 1000 +#endif + +#if defined(__linux) +#define NO_USE_MMAP +#else +#define USE_MMAP +#endif + +int Max_Arts= MAX_ARTS; +int Max_Stats = MAX_STATS; + +typedef struct NEWSRC_T { + char *nameptr, *lowptr, *highptr, *modeptr; + int namelen, lowlen, highlen; + ULONG low, high; + int mode, subscribe; +} newsrc_t; + +typedef struct NNRP_T { + int nnrpfd; + int innbbsfd; + FILE *nnrpin, *nnrpout; + FILE *innbbsin, *innbbsout; + char activefile[MAXPATHLEN]; + char rcfile[MAXPATHLEN]; + newsrc_t *newsrc; + char *actpointer, *actend; + int actsize, actfd, actdirty; +} nnrp_t; + +typedef struct XHDR_T { + char *header; + ULONG artno; +} xhdr_t; + +xhdr_t XHDR[MAX_ARTS]; +char LockFile[1024]; + +#define NNRPGroupOK NNTP_GROUPOK_VAL +#define NNRPXhdrOK NNTP_HEAD_FOLLOWS_VAL +#define NNRParticleOK NNTP_ARTICLE_FOLLOWS_VAL +#define INNBBSstatOK NNTP_NOTHING_FOLLOWS_VAL +#define INNBBSihaveOK NNTP_SENDIT_VAL +#define NNRPconnectOK NNTP_POSTOK_VAL +#define NNRPstatOK NNTP_NOTHING_FOLLOWS_VAL +#define INNBBSconnectOK NNTP_POSTOK_VAL + +nnrp_t BBSNNRP; + +void doterm(s) +int s; +{ + printf("bbsnnrp terminated. Signal %d\n", s); + writerc(&BBSNNRP); + if (isfile(LockFile)) + unlink(LockFile); + exit(1); +} + +extern char *optarg; +extern int opterr, optind; + +#ifndef MIN_WAIT +# define MIN_WAIT 60 +#endif + +int ResetActive = 0; +int StatHistory = 1; +int AskLocal = 1; +int RunOnce = 1; + +int DefaultWait = MIN_WAIT; + +char *DefaultPort = DefaultINNBBSPort; +char *DefaultPath = LOCALDAEMON; +char *DefaultRemoteHost; + +#ifndef MAXBUFLEN +#define MAXBUFLEN 256 +#endif +char DefaultNewsgroups[MAXBUFLEN]; +char DefaultOrganization[MAXBUFLEN]; +char DefaultModerator[MAXBUFLEN]; +char DefaultTrustfrom[MAXBUFLEN]; +char DefaultTrustFrom[MAXBUFLEN]; + +usage(arg) +char *arg; +{ +fprintf(stderr,"Usage: %s [options] nntpserver activefile\n", arg); +fprintf(stderr," -h|? (help) \n"); +fprintf(stderr," -v (verbose protocol transactions)\n"); +fprintf(stderr," -c (reset active files only; don't receive articles)\n"); +fprintf(stderr," -r [proto:]remotehost\n"); +fprintf(stderr," (send articles to remotehost, default=ihave:local)\n"); +fprintf(stderr," -p port|(send articles to remotehost at port, default=%s)\n",DefaultINNBBSPort); +fprintf(stderr," path(send articles to local at path, default=~bbs/innd/.innbbsd)\n"); +fprintf(stderr," -w seconds ( > 1 wait for seconds and run infinitely, default=once)\n"); +fprintf(stderr," -n (don't ask innbbsd server and stat articles)\n"); +fprintf(stderr," -a max_art(maximum number of articles received for a group each time)\n"); +fprintf(stderr," default=%d\n", MAX_ARTS); +fprintf(stderr," -s max_stat(maximum number of articles stated for a group each time)\n"); +fprintf(stderr," default=%d\n", MAX_STATS); +fprintf(stderr," -t stdin|nntp (default=nntp)\n"); +fprintf(stderr," -g newsgroups\n"); +fprintf(stderr," -m moderator\n"); +fprintf(stderr," -o organization\n"); +fprintf(stderr," -f trust_user (From: trust_user)\n"); +fprintf(stderr," -F trust_user (From trust_user)\n"); +fprintf(stderr," Please E-mail bug to skhuang@csie.nctu.edu.tw or\n"); +fprintf(stderr," post to tw.bbs.admin.installbbs\n"); +} + +static char *StdinInputType="stdin"; +static char *NntpInputType="nntp"; +static char *NntpIhaveProtocol="ihave"; +static char *NntpPostProtocol="post"; +static char *DefaultNntpProtocol ; +main(argc, argv) +int argc; +char **argv; +{ + char *ptr, *server, *active; + int c, errflag=0; + int lockfd; + char *inputtype; + + DefaultNntpProtocol = NntpIhaveProtocol; + *DefaultNewsgroups = '\0'; + *DefaultModerator = '\0'; + *DefaultOrganization = '\0'; + *DefaultTrustFrom = '\0'; + *DefaultTrustfrom = '\0'; + inputtype = NntpInputType; + while ((c = getopt(argc,argv,"f:F:m:o:g:w:r:p:a:s:t:h?ncv"))!= -1) + switch (c) { + case 'v': + verboseon("bbsnnrp.log"); + break; + case 'c': + ResetActive = 1; + break; + case 'g': + strncpy(DefaultNewsgroups, optarg, sizeof DefaultNewsgroups); + break; + case 'm': + strncpy(DefaultModerator, optarg, sizeof DefaultModerator); + break; + case 'o': + strncpy(DefaultOrganization, optarg, sizeof DefaultOrganization); + break; + case 'f': + strncpy(DefaultTrustfrom, optarg, sizeof DefaultTrustfrom); + break; + case 'F': + strncpy(DefaultTrustFrom, optarg, sizeof DefaultTrustFrom); + break; + case 'r': { + char *hostptr; + AskLocal = 0; + DefaultRemoteHost = optarg; + if ((hostptr = strchr(optarg,':')) != NULL) { + *hostptr = '\0'; + DefaultRemoteHost = hostptr+1; + if (strcasecmp( optarg, "post" ) == 0) + DefaultNntpProtocol = NntpPostProtocol; + *hostptr = ':'; + } + break; + } + case 'w': + RunOnce = 0; + DefaultWait = atoi(optarg); + if (DefaultWait < MIN_WAIT) + DefaultWait = MIN_WAIT; + break; + case 'p': + if (AskLocal == 0) { + DefaultPort = optarg; + } else { + DefaultPath = optarg; + } + break; + case 'n': + StatHistory = 0; + break; + case 'a': + Max_Arts = atol(optarg); + if (Max_Arts < 0) Max_Arts = 0; + break; + case 's': + Max_Stats = atol(optarg); + if (Max_Stats < 0) Max_Stats = 0; + break; + case 't': + if ( strcasecmp(optarg,StdinInputType) == 0) { + inputtype = StdinInputType; + } + break; + case 'h': + case '?': + default: + errflag ++; + } + if (errflag > 0) { + usage(argv[0]); + return(1); + } + if (inputtype == NntpInputType && argc - optind < 2) { + usage(argv[0]); + exit(1); + } + if (inputtype == NntpInputType) { + server = argv[optind]; + active = argv[optind+1]; + if ( isfile(active) ) { + strncpy(BBSNNRP.activefile, active, sizeof BBSNNRP.activefile); + } else if ( strchr(active,'/') == NULL) { + sprintf(BBSNNRP.activefile, "%s/innd/%.*s",BBSHOME, sizeof BBSNNRP.activefile - 7 - strlen(BBSHOME), active); + } else { + strncpy(BBSNNRP.activefile, active, sizeof BBSNNRP.activefile); + } + + strncpy(LockFile , (char*)fileglue("%s.lock",active), sizeof LockFile); + if ((lockfd = open(LockFile, O_RDONLY)) >= 0) { + char buf[10]; + int pid; + + if (read(lockfd, buf, sizeof buf) > 0 && (pid = atoi(buf))>0 && kill(pid,0)==0) { + fprintf(stderr, "another process [%d] running\n", pid); + exit(1); + } else { + fprintf(stderr, "no process [%d] running, but lock file existed, unlinked\n", pid); + unlink(LockFile); + } + close(lockfd); + } + if ((lockfd = open(LockFile, O_RDWR|O_CREAT|O_EXCL,0644)) < 0) { + fprintf( stderr, "maybe another %s process running\n",argv[0]); + exit(1); + } else { + char buf[10]; + int pid; + sprintf(buf,"%-.8d\n",getpid()); + write(lockfd, buf, strlen(buf)); + close(lockfd); + } + for (;;) { + if (!initial_bbs(NULL)) { + fprintf(stderr, "Initial BBS failed\n"); + exit(1); + } + initsockets(server, &BBSNNRP, inputtype); + ptr = (char*)strrchr(active,'/'); + if (ptr != NULL) + ptr++; + else + ptr = active; + sprintf(BBSNNRP.rcfile,"%s/.newsrc.%s.%s",INNDHOME, server, ptr); + initrcfiles(&BBSNNRP); + + signal(SIGTERM, doterm); + signal(SIGKILL, doterm); + signal(SIGHUP, doterm); + signal(SIGPIPE, doterm); + + readnews(&BBSNNRP); + writerc(&BBSNNRP); + closesockets(); + + if (RunOnce) break; + sleep(DefaultWait); + } + unlink(LockFile); + } /* NntpInputType */ + else { + if (!initial_bbs(NULL)) { + fprintf(stderr, "Initial BBS failed\n"); + exit(1); + } + initsockets(server, &BBSNNRP, inputtype); + signal(SIGTERM, doterm); + signal(SIGKILL, doterm); + signal(SIGHUP, doterm); + signal(SIGPIPE, doterm); + + stdinreadnews(&BBSNNRP); + closesockets(); + } /* stdin input type */ + return 0; +} + +headbegin(buffer) +char *buffer; +{ + if (strncmp(buffer,"Path: ",6)==0 ) { + if (strchr(buffer+6,'!') != NULL) + return 1; + } + if (strncmp(buffer,"From ",5)== 0 ) { + if (strchr(buffer+5,':') != NULL) + return 1; + } + return 0; +} + +stdinreadnews(bbsnnrp) +nnrp_t *bbsnnrp; +{ + int i; + char buffer[4096]; + ULONG low, high; + char tmpfilename[MAXPATHLEN]; + FILE *tmpfp = NULL; + char mid[1024]; + int pathagain; + int ngmet, submet, midmet, pathmet, orgmet, approvedmet; + int discard; + char sending_path[MAXPATHLEN]; + int sending_path_len=0; + + strncpy(tmpfilename,(char*)fileglue("/tmp/bbsnnrp-stdin-%d-%d",getuid(),getpid()),sizeof tmpfilename); + fgets(buffer, sizeof buffer, bbsnnrp->innbbsin); + verboselog("innbbsGet: %s", buffer); + if (atoi(buffer) != INNBBSconnectOK) { + fprintf(stderr, "INNBBS server not OK\n"); + return; + } + + if ( DefaultNntpProtocol == NntpPostProtocol ) { + fputs("MODE READER\r\n", bbsnnrp->innbbsout); + fflush(bbsnnrp->innbbsout); + verboselog("innbbsPut: MODE READER\n"); + fgets(buffer, sizeof buffer, bbsnnrp->innbbsin); + verboselog("innbbsGet: %s",buffer); + } + + if (StatHistory == 0) { + fputs("MIDCHECK OFF\r\n", bbsnnrp->innbbsout); + fflush(bbsnnrp->innbbsout); + verboselog("innbbsPut: MIDCHECK OFF\n"); + fgets(buffer, sizeof buffer, bbsnnrp->innbbsin); + verboselog("innbbsGet: %s",buffer); + } + tmpfp = fopen(tmpfilename,"w"); + if (tmpfp == NULL) return; + *mid = '\0'; + for (;;) { + fprintf(stderr,"Try to read from stdin ...\n"); + ngmet = 0, submet = 0, midmet = 0, pathmet = 0, orgmet = 0, approvedmet=0; + discard = 0; + while (fgets(buffer, sizeof buffer, stdin) != NULL) { + char *tmpptr; + tmpptr = strchr(buffer,'\n'); + if (tmpptr != NULL) *tmpptr = '\0'; + if (strncasecmp(buffer,"Message-ID: ",12)==0) { + strncpy(mid, buffer+12,sizeof mid); + midmet = 1; + } else if (strncmp(buffer,"Subject: ",9)==0) { + submet = 1; + } else if (strncmp(buffer,"Path: ",6)==0) { + pathmet = 1; + } else if (strncmp(buffer,"Organization: ",14)==0) { + orgmet = 1; + } else if (strncmp(buffer,"Approved: ",10) == 0) { + approvedmet = 1; + } else if (strncmp(buffer,"From: ",6)==0 && *DefaultTrustfrom ) { + if (strstr(buffer+6, DefaultTrustfrom)==NULL) { + discard = 1; + verboselog("Discard: %s for %s",buffer, DefaultTrustfrom); + } + } else if (strncmp(buffer,"From ",5)==0 && *DefaultTrustFrom ) { + if (strstr(buffer+5, DefaultTrustFrom)==NULL) { + discard = 1; + verboselog("Discard: %s for %s",buffer, DefaultTrustFrom); + } + } else if (strncmp(buffer,"Received: ",10)==0) { + char *rptr=buffer+10, *rrptr; + int savech, len; + if (strncmp(buffer+10,"from ",5)==0) { + rptr +=5; + rrptr = strchr(rptr,'('); + if (rrptr != NULL) rptr = rrptr + 1; + rrptr = strchr(rptr,' '); + savech = *rrptr; + if (rrptr != NULL) *rrptr = '\0'; + } else if (strncmp(buffer+10,"(from ",6)==0) { + rptr +=6; + rrptr = strchr(rptr,')'); + savech = *rrptr; + if (rrptr != NULL) *rrptr = '\0'; + } + len = strlen(rptr) +1; + if (*rptr && sending_path_len + len < sizeof(sending_path)) { + if (*sending_path) + strcat(sending_path, "!"); + strcat(sending_path, rptr); + sending_path_len += len ; + } + if (rrptr != NULL) *rrptr = savech; + } + + if (strncmp(buffer,"Newsgroups: ",12)==0) { + if (*DefaultNewsgroups){ + fprintf(tmpfp,"Newsgroups: %s\r\n",DefaultNewsgroups); + } else { + fprintf(tmpfp,"%s\r\n",buffer); + } + ngmet = 1; + } else { + if (buffer[0] == '\0') { + if (!ngmet && *DefaultNewsgroups) { + fprintf(tmpfp,"Newsgroups: %s\r\n",DefaultNewsgroups); + } + if (!submet) { + fprintf(tmpfp,"Subject: (no subject)\r\n"); + } + if (!pathmet) { + fprintf(tmpfp,"Path: from-mail\r\n"); + } + if (!midmet) { + static int seed; + time_t now; + time(&now); + fprintf(tmpfp,"Message-ID: <%d@%d.%d.%d>\r\n",now,getpid(), getuid(), seed); + sprintf(mid, "<%d@%d.%d.%d>", now, getpid(), getuid(), seed); + seed++; + } + if (!orgmet && *DefaultOrganization) { + fprintf(tmpfp,"Organization: %s\r\n", DefaultOrganization); + } + if (!approvedmet && *DefaultModerator) { + fprintf(tmpfp,"Approved: %s\r\n", DefaultModerator); + } + } + if (strncmp(buffer,"From ",5) != 0 && strncmp(buffer,"To: ",4) !=0) { + if (buffer[0] == '\0') { + if (*sending_path) { + fprintf(tmpfp,"X-Sending-Path: %s\r\n",sending_path); + } + } + fprintf(tmpfp,"%s\r\n",buffer); + } + } + if (buffer[0]=='\0') break; + } + fprintf(stderr,"Article Body begin ...\n"); + pathagain = 0; + while (fgets(buffer, sizeof buffer, stdin) != NULL) { + char *tmpptr; + tmpptr = strchr(buffer,'\n'); + if (tmpptr != NULL) *tmpptr = '\0'; + if ( headbegin(buffer) ) { + FILE *oldfp = bbsnnrp->nnrpin; + pathagain = 1; + fputs(".\r\n",tmpfp); + fclose(tmpfp); + fprintf(stderr,"Try to post ...\n"); + tmpfp = fopen(tmpfilename,"r"); + bbsnnrp->nnrpin = tmpfp; + if (!discard) + if (INNBBSihave(bbsnnrp, -1, mid)== -1) { + fprintf(stderr,"post failed\n"); + } + bbsnnrp->nnrpin = oldfp; + fclose(tmpfp); + *mid = '\0'; + tmpfp = fopen(tmpfilename,"w"); + fprintf(tmpfp,"%s\r\n",buffer); + break; + } else { + fprintf(tmpfp,"%s\r\n",buffer); + } + } + if (!pathagain) break; + } + if (!pathagain && tmpfp) { + FILE *oldfp = bbsnnrp->nnrpin; + fputs(".\r\n",tmpfp); + fclose(tmpfp); + fprintf(stderr,"Try to post ...\n"); + tmpfp = fopen(tmpfilename,"r"); + bbsnnrp->nnrpin = tmpfp; + if (!discard) + if (INNBBSihave(bbsnnrp, -1, mid)== -1) { + fprintf(stderr,"post failed\n"); + } + bbsnnrp->nnrpin = oldfp; + fclose(tmpfp); + } + if (isfile(tmpfilename)) { + unlink(tmpfilename); + } +} + +static char *ACT_BUF, *RC_BUF; +int ACT_COUNT; + +initrcfiles(bbsnnrp) +nnrp_t *bbsnnrp; +{ + FILE *actfp, *rcfp; + char buff[1024]; + int actfd, i, count, actcount=0, rcount=0, maxcount; + struct stat st; + char *actlistptr, *ptr; + + actfd = open(bbsnnrp->activefile, O_RDWR); + if (actfd < 0) { + fprintf( stderr, "can't read/write %s\n", bbsnnrp->activefile ); + exit(1); + } + if (fstat(actfd, &st) != 0) { + fprintf( stderr, "can't stat %s\n", bbsnnrp->activefile ); + exit(1); + } + + bbsnnrp->actfd = actfd; + bbsnnrp->actsize = st.st_size; +#ifdef USE_MMAP + bbsnnrp->actpointer = mmap(0, st.st_size, PROT_WRITE | PROT_READ, + MAP_SHARED, actfd, 0); + if (bbsnnrp->actpointer == (char*)-1) { + fprintf( stderr, "mmap error \n"); + exit(1); + } +#else + if (bbsnnrp->actpointer == NULL) { + bbsnnrp->actpointer = (char*)mymalloc(st.st_size); + } else { + bbsnnrp->actpointer = (char*)myrealloc(bbsnnrp->actpointer,st.st_size); + } + if (bbsnnrp->actpointer == NULL || read(actfd, bbsnnrp->actpointer, st.st_size) <= 0) { + fprintf( stderr, "read act error \n"); + exit(1); + } +#endif + bbsnnrp->actend = bbsnnrp->actpointer + st.st_size; + i = 0, count = 0; + for (ptr = bbsnnrp->actpointer; ptr < bbsnnrp->actend && (actlistptr = (char*)strchr(ptr,'\n')) != NULL; ptr = actlistptr +1, ACT_COUNT++) { + if (*ptr == '\n') continue; + if (*ptr == '#') continue; + count ++; + } + bbsnnrp->newsrc = (newsrc_t*) mymalloc( sizeof(newsrc_t) * count); + ACT_COUNT = 0; + for (ptr = bbsnnrp->actpointer; ptr < bbsnnrp->actend && (actlistptr = (char*)strchr(ptr,'\n')) != NULL; ptr = actlistptr +1 ) { + register newsrc_t *rcptr; + char *nptr; + /**actlistptr = '\0';*/ + if (*ptr == '\n') continue; + if (*ptr == '#') continue; + rcptr = &bbsnnrp->newsrc[ACT_COUNT]; + rcptr->nameptr = NULL; + rcptr->namelen = 0; + rcptr->lowptr = NULL; + rcptr->lowlen = 0; + rcptr->highptr = NULL; + rcptr->highlen = 0; + rcptr->modeptr = NULL; + rcptr->low = 0; + rcptr->high = 0; + rcptr->mode = 'y'; + for (nptr= ptr ;*nptr && isspace(*nptr); ) nptr++; + if ( nptr == actlistptr ) continue; + rcptr->nameptr = nptr; + for (nptr++; *nptr && !isspace(*nptr); ) nptr++; + rcptr->namelen = (int)(nptr - rcptr->nameptr); + if ( nptr == actlistptr) continue; + for (nptr++ ;*nptr && isspace(*nptr); ) nptr++; + if ( nptr == actlistptr) continue; + rcptr->highptr = nptr; + rcptr->high = atol(nptr); + for (nptr++; *nptr && !isspace(*nptr); ) nptr++; + rcptr->highlen = (int)(nptr - rcptr->highptr); + if ( nptr == actlistptr) continue; + for (nptr++ ;*nptr && isspace(*nptr); ) nptr++; + if ( nptr == actlistptr) continue; + rcptr->lowptr = nptr; + rcptr->low = atol(nptr); + for (nptr++; *nptr && !isspace(*nptr); ) nptr++; + rcptr->lowlen = (int)(nptr - rcptr->lowptr); + if ( nptr == actlistptr) continue; + for (nptr++ ;*nptr && isspace(*nptr); ) nptr++; + if ( nptr == actlistptr) continue; + rcptr->mode = *nptr; + rcptr->modeptr = nptr; + ACT_COUNT ++; + } +} + +initsockets(server, bbsnnrp, type) +char *server; +nnrp_t *bbsnnrp; +char *type; +{ + int nnrpfd ; + int innbbsfd; + if (AskLocal) { + innbbsfd = unixclient(DefaultPath,"tcp"); + if (innbbsfd < 0) { + fprintf(stderr, "Connect to %s error. You may not run innbbsd\n", LOCALDAEMON); + /* unix connect fail, may run by inetd, try to connect to local once */ + innbbsfd = inetclient("localhost",DefaultPort,"tcp"); + if (innbbsfd < 0) { + exit(2); + } + close(innbbsfd); + /* try again */ + innbbsfd = unixclient(DefaultPath,"tcp"); + if (innbbsfd < 0) { + exit(3); + } + } + verboselog("INNBBS connect to %s\n",DefaultPath); + } else { + innbbsfd = inetclient(DefaultRemoteHost,DefaultPort,"tcp"); + if (innbbsfd < 0) { + fprintf(stderr, "Connect to %s at %s error. Remote Server not Ready\n", DefaultRemoteHost, DefaultPort); + exit(2); + } + verboselog("INNBBS connect to %s\n",DefaultRemoteHost); + } + if (type == StdinInputType) { + bbsnnrp->nnrpfd = 0; + bbsnnrp->innbbsfd = innbbsfd; + if ((bbsnnrp->nnrpin = fdopen(0,"r")) == NULL || + (bbsnnrp->nnrpout= fdopen(1,"w")) == NULL || + (bbsnnrp->innbbsin= fdopen(innbbsfd,"r")) == NULL || + (bbsnnrp->innbbsout= fdopen(innbbsfd,"w"))== NULL ) { + fprintf( stderr, "fdopen error\n"); + exit(3); + } + return; + } + nnrpfd = inetclient(server, "nntp","tcp"); + if (nnrpfd < 0) { + fprintf(stderr, " connect to %s error \n", server); + exit(2); + } + verboselog("NNRP connect to %s\n", server); + bbsnnrp->nnrpfd = nnrpfd; + bbsnnrp->innbbsfd = innbbsfd; + if ((bbsnnrp->nnrpin = fdopen(nnrpfd,"r")) == NULL || + (bbsnnrp->nnrpout= fdopen(nnrpfd,"w")) == NULL || + (bbsnnrp->innbbsin= fdopen(innbbsfd,"r")) == NULL || + (bbsnnrp->innbbsout= fdopen(innbbsfd,"w"))== NULL ) { + fprintf( stderr, "fdopen error\n"); + exit(3); + } +} + +closesockets() +{ + fclose(BBSNNRP.nnrpin); + fclose(BBSNNRP.nnrpout); + fclose(BBSNNRP.innbbsin); + fclose(BBSNNRP.innbbsout); + close(BBSNNRP.nnrpfd); + close(BBSNNRP.innbbsfd); +} + +updaterc(actptr, len, value) +char *actptr; +int len; +ULONG value; +{ + for (actptr += len -1; len -- >0; ) { + *actptr-- = value % 10 + '0'; + value /= 10; + } +} + +/* + if old file is empty, don't need to update + prevent from disk full +*/ +int +myrename(old,new) +char *old, *new; +{ + struct stat st; + if (stat(old,&st) != 0) return -1; + if (st.st_size <= 0) return -1; + return rename(old,new); +} + +flushrc(bbsnnrp) +nnrp_t *bbsnnrp; +{ + int backfd; + char *bak1; + if (bbsnnrp->actdirty == 0) return; + bak1 = (char*)strdup((char*)fileglue("%s.BAK",bbsnnrp->activefile)); + if (isfile(bak1)) { + myrename(bak1, (char*)fileglue("%s.BAK.OLD",bbsnnrp->activefile)); + } +#ifdef USE_MMAP + if ((backfd=open((char*)fileglue("%s.BAK",bbsnnrp->activefile),O_WRONLY | O_TRUNC | O_CREAT, 0664)) < 0 || write(backfd, bbsnnrp->actpointer, bbsnnrp->actsize) < bbsnnrp->actsize) +#else + myrename(bbsnnrp->activefile, bak1); + if ((backfd=open(bbsnnrp->activefile,O_WRONLY | O_TRUNC | O_CREAT, 0664)) < 0 || write(backfd, bbsnnrp->actpointer, bbsnnrp->actsize) < bbsnnrp->actsize) +#endif + { + char emergent[128]; + sprintf(emergent,"/tmp/bbsnnrp.%d.active",getpid()); + fprintf(stderr, "write to backup active fail. Maybe disk full\n"); + fprintf(stderr, "try to write in %s\n",emergent); + if ((backfd = open(emergent,O_WRONLY | O_TRUNC | O_CREAT, 0644))<0 || write(backfd, bbsnnrp->actpointer, bbsnnrp->actsize) < bbsnnrp->actsize) + { + fprintf(stderr, "write to %sfail.\n", emergent); + } else { + close(backfd); + } + /* if write fail, should leave */ + /*exit(1);*/ + } else { + close(backfd); + } + free(bak1); + bbsnnrp->actdirty = 0; +} + +writerc(bbsnnrp) +nnrp_t *bbsnnrp; +{ + if (bbsnnrp->actpointer) { + flushrc(bbsnnrp); +#ifdef USE_MMAP + if (munmap(bbsnnrp->actpointer, bbsnnrp->actsize) < 0) + fprintf(stderr, "can't unmap\n"); + /*free(bbsnnrp->actpointer);*/ + bbsnnrp->actpointer = NULL; +#endif + if (close(bbsnnrp->actfd) < 0) + fprintf(stderr, "can't close actfd\n"); + } +} + +static FILE* Xhdrfp; +static char NNRPbuffer[4096]; +static char INNBBSbuffer[4096]; + +char * +NNRPgets(string, len, fp) +char *string; +int len; +FILE *fp; +{ + char* re = fgets(string, len, fp); + char *ptr; + if (re != NULL) { + if ((ptr = (char*)strchr(string,'\r'))!=NULL) + *ptr = '\0'; + if ((ptr = (char*)strchr(string,'\n'))!=NULL) + *ptr = '\0'; + } + return re; +} + +int NNRPstat(bbsnnrp, artno, mid) +nnrp_t *bbsnnrp; + ULONG artno; +char **mid; +{ + char *ptr; + int code; + + *mid = NULL; + fprintf(bbsnnrp->nnrpout,"STAT %d\r\n",artno); + fflush(bbsnnrp->nnrpout); + verboselog("nnrpPut: STAT %d\n",artno); + NNRPgets(NNRPbuffer, sizeof NNRPbuffer, bbsnnrp->nnrpin); + verboselog("nnrpGet: %s\n",NNRPbuffer); + + ptr = (char*) strchr(NNRPbuffer, ' '); + if (ptr != NULL) *ptr++ = '\0'; + code = atoi(NNRPbuffer); + ptr = (char*) strchr(ptr, ' '); + if (ptr != NULL) *ptr++ = '\0'; + *mid = ptr; + ptr = (char*) strchr(ptr, ' '); + if (ptr != NULL) *ptr++ = '\0'; + return code; +} + +int +NNRPxhdr(pattern, bbsnnrp, i, low, high) +char *pattern; +nnrp_t *bbsnnrp; +int i; +ULONG low, high; +{ + newsrc_t *rcptr = &bbsnnrp->newsrc[i]; + int size, code; + + Xhdrfp = bbsnnrp->nnrpin; + fprintf(bbsnnrp->nnrpout,"XHDR %s %d-%d\r\n",pattern,low, high ); +#ifdef BBSNNRPDEBUG + printf("XHDR %s %d-%d\r\n",pattern,low, high ); +#endif + fflush(bbsnnrp->nnrpout); + verboselog("nnrpPut: XHDR %s %d-%d\n",pattern,low, high ); + NNRPgets(NNRPbuffer, sizeof NNRPbuffer, bbsnnrp->nnrpin); + verboselog("nnrpGet: %s\n", NNRPbuffer); + code = atoi(NNRPbuffer); + return code; +} + +int NNRPxhdrget(artno, mid, iscontrol) +int *artno; +char **mid; +int iscontrol; +{ + *mid = NULL; + *artno = 0; + if (NNRPgets(NNRPbuffer, sizeof NNRPbuffer, Xhdrfp) == NULL) + return 0; + else { + char *ptr, *s; + if (strcmp(NNRPbuffer,".")==0) return 0; + ptr = (char*)strchr(NNRPbuffer,' '); + if (!ptr) return 1; + *ptr++ = '\0'; + *artno = atol(NNRPbuffer); + if (iscontrol) { + ptr = (char*)strchr(s=ptr,' '); + if (!ptr) return 1; + *ptr++ = '\0'; + if (strcmp(s,"cancel") != 0) return 1; + } + *mid = ptr; + return 1; + } +} + +int INNBBSstat(bbsnnrp, i, mid) +nnrp_t *bbsnnrp; +int i; +char *mid; +{ + newsrc_t *rcptr = &bbsnnrp->newsrc[i]; + int size, code; + + fprintf(bbsnnrp->innbbsout,"STAT %s\r\n", mid); + fflush(bbsnnrp->innbbsout); + verboselog("innbbsPut: STAT %s\n", mid); + NNRPgets(INNBBSbuffer, sizeof INNBBSbuffer, bbsnnrp->innbbsin); + verboselog("innbbsGet: %s\n", INNBBSbuffer); + return atol(INNBBSbuffer); +} + +int INNBBSihave(bbsnnrp, artno, mid) +nnrp_t *bbsnnrp; +ULONG artno; +char *mid; +{ + int size, code; + int header=1; + + if (DefaultNntpProtocol == NntpPostProtocol) { + fprintf(bbsnnrp->innbbsout,"POST\r\n"); + fflush(bbsnnrp->innbbsout); + verboselog("innbbsPut: POST %s\n", mid); + } else { + fprintf(bbsnnrp->innbbsout,"IHAVE %s\r\n", mid); + fflush(bbsnnrp->innbbsout); + verboselog("innbbsPut: IHAVE %s\n", mid); + } + if (NNRPgets(INNBBSbuffer, sizeof INNBBSbuffer, bbsnnrp->innbbsin)==NULL){ + return -1; + } + verboselog("innbbsGet: %s\n", INNBBSbuffer); +#ifdef BBSNNRPDEBUG + printf("ihave got %s\n", INNBBSbuffer); +#endif + + if (DefaultNntpProtocol == NntpPostProtocol) { + if ((code=atol(INNBBSbuffer)) != NNTP_START_POST_VAL) { + if (code == NNTP_POSTFAIL_VAL) + return 0; + else + return -1; + } + } else { + if ((code=atol(INNBBSbuffer)) != INNBBSihaveOK) { + if (code == 435 || code == 437) + return 0; + else + return -1; + } + } + if (artno != -1) { + fprintf(bbsnnrp->nnrpout,"ARTICLE %d\r\n", artno); + verboselog("nnrpPut: ARTICLE %d\n", artno); +#ifdef BBSNNRPDEBUG + printf("ARTICLE %d\r\n", artno); +#endif + fflush(bbsnnrp->nnrpout); + if (NNRPgets(NNRPbuffer, sizeof NNRPbuffer, bbsnnrp->nnrpin)==NULL) { + return -1; + } + verboselog("nnrpGet: %s\n", NNRPbuffer); +#ifdef BBSNNRPDEBUG + printf("article got %s\n", NNRPbuffer); +#endif + if (atol(NNRPbuffer) != NNRParticleOK) { + fputs(".\r\n",bbsnnrp->innbbsout); + fflush(bbsnnrp->innbbsout); + NNRPgets(INNBBSbuffer, sizeof INNBBSbuffer, bbsnnrp->innbbsin); + verboselog("innbbsGet: %s\n",INNBBSbuffer); + return 0; + } + } + header = 1; + while ( fgets(NNRPbuffer, sizeof NNRPbuffer, bbsnnrp->nnrpin) != NULL) + { + if (strcmp(NNRPbuffer,"\r\n") == 0) + header = 0; + if (strcmp(NNRPbuffer,".\r\n")==0) { + verboselog("nnrpGet: .\n"); + fputs(NNRPbuffer,bbsnnrp->innbbsout); + fflush(bbsnnrp->innbbsout); + verboselog("innbbsPut: .\n"); + if (NNRPgets(INNBBSbuffer, sizeof INNBBSbuffer, bbsnnrp->innbbsin)==NULL) + return -1; + verboselog("innbbsGet: %s\n",INNBBSbuffer); +#ifdef BBSNNRPDEBUG + printf("end ihave got %s\n", INNBBSbuffer); +#endif + code = atol(INNBBSbuffer); + if (DefaultNntpProtocol == NntpPostProtocol) { + if (code == NNTP_POSTEDOK_VAL) + return 1; + if (code == NNTP_POSTFAIL_VAL) + return 0; + } else { + if (code == 235) + return 1; + if (code == 437 || code == 435) + return 0; + } + break; + } + if ( DefaultNntpProtocol == NntpPostProtocol && + header && strncasecmp(NNRPbuffer,"NNTP-Posting-Host: ",19)==0) { + fprintf(bbsnnrp->innbbsout,"X-%s",NNRPbuffer); + } else { + fputs(NNRPbuffer,bbsnnrp->innbbsout); + } + } + fflush(bbsnnrp->innbbsout); + return -1; +} + +int +NNRPgroup(bbsnnrp, i, low, high) +nnrp_t *bbsnnrp; +int i; +ULONG *low, *high; +{ + newsrc_t *rcptr = &bbsnnrp->newsrc[i]; + int size, code; + ULONG tmp; + + fprintf(bbsnnrp->nnrpout,"GROUP %-.*s\r\n", + rcptr->namelen, rcptr->nameptr ); + printf("GROUP %-.*s\r\n", rcptr->namelen, rcptr->nameptr ); + verboselog("nnrpPut: GROUP %-.*s\n", rcptr->namelen, rcptr->nameptr ); + fflush(bbsnnrp->nnrpout); + NNRPgets(NNRPbuffer, sizeof NNRPbuffer, bbsnnrp->nnrpin); + verboselog("nnrpGet: %s\n",NNRPbuffer); + printf("%s\n",NNRPbuffer); + sscanf(NNRPbuffer, "%d %d %ld %ld", &code, &size, low, high); + if (*low > *high) { + tmp = *low; + *low = *high; + *high = tmp; + } + return code; +} + + +readnews(bbsnnrp) +nnrp_t *bbsnnrp; +{ + int i; + char buffer[4096]; + ULONG low, high; + + fgets(buffer, sizeof buffer, bbsnnrp->innbbsin); + verboselog("innbbsGet: %s", buffer); + if (atoi(buffer) != INNBBSconnectOK) { + fprintf(stderr, "INNBBS server not OK\n"); + return; + } +#ifdef BBSNNRPDEBUG + printf("%s",buffer); +#endif + fgets(buffer, sizeof buffer, bbsnnrp->nnrpin); + verboselog("nnrpGet: %s", buffer); + if (buffer[0] != '2') { + /*if (atoi(buffer) != NNRPconnectOK && atoi(buffer) != NNTP_NOPOSTOK_VAL) {*/ + fprintf(stderr, "NNRP server not OK\n"); + return; + } +#ifdef BBSNNRPDEBUG + printf("%s",buffer); +#endif + fputs("MODE READER\r\n", bbsnnrp->nnrpout); + fflush(bbsnnrp->nnrpout); + verboselog("nnrpPut: MODE READER\n"); + fgets(buffer, sizeof buffer, bbsnnrp->nnrpin); + verboselog("nnrpGet: %s",buffer); + + if ( DefaultNntpProtocol == NntpPostProtocol ) { + fputs("MODE READER\r\n", bbsnnrp->innbbsout); + fflush(bbsnnrp->innbbsout); + verboselog("innbbsPut: MODE READER\n"); + fgets(buffer, sizeof buffer, bbsnnrp->innbbsin); + verboselog("innbbsGet: %s",buffer); + } + +#ifdef BBSNNRPDEBUG + printf("%s",buffer); +#endif + + if (StatHistory == 0) { + fputs("MIDCHECK OFF\r\n", bbsnnrp->innbbsout); + fflush(bbsnnrp->innbbsout); + verboselog("innbbsPut: MIDCHECK OFF\n"); + fgets(buffer, sizeof buffer, bbsnnrp->innbbsin); + verboselog("innbbsGet: %s",buffer); + } + bbsnnrp->actdirty = 0; + for (i =0; i< ACT_COUNT; i++) { + int code = NNRPgroup(bbsnnrp, i, &low, &high); + newsrc_t *rcptr = &bbsnnrp->newsrc[i]; + int j; + ULONG artno; + char *mid; + int artcount; + +#ifdef BBSNNRPDEBUG + printf("got reply %d %ld %ld\n",code, low, high); +#endif + artcount = 0; + if (code == NNRPGroupOK) { + int xcount; + ULONG maxartno= rcptr->high; + int isCancelControl = (strncmp(rcptr->nameptr,"control",rcptr->namelen)==0) + || + (strncmp(rcptr->nameptr,"control.cancel",rcptr->namelen)==0) ; + +/* less than or equal to high, for server renumber */ + if (rcptr->low != low) { + bbsnnrp->actdirty = 1; + rcptr->low = low; + updaterc(rcptr->lowptr, rcptr->lowlen, rcptr->low); + } + if (ResetActive) { + if (rcptr->high != high) { + bbsnnrp->actdirty = 1; + rcptr->high = high; + updaterc(rcptr->highptr, rcptr->highlen, rcptr->high); + } + } else if (rcptr->high < high) { + int xhdrcode; + ULONG maxget=high; + int exception=0; + if (rcptr->high < low) { + bbsnnrp->actdirty = 1; + rcptr->high = low; + updaterc(rcptr->highptr, rcptr->highlen, low); + } + if (high > rcptr->high + Max_Stats) { + maxget = rcptr->high + Max_Stats; + } + if ( isCancelControl ) + xhdrcode = NNRPxhdr("Control",bbsnnrp, i, rcptr->high+1, maxget); + else + xhdrcode = NNRPxhdr("Message-ID",bbsnnrp, i, rcptr->high+1, maxget); + + maxartno = maxget; + if ( xhdrcode == NNRPXhdrOK) { + while (NNRPxhdrget(&artno, &mid, isCancelControl)) { +/*#define DEBUG*/ +#ifdef DEBUG + printf("no %d id %s\n",artno, mid); +#endif + if (artcount < Max_Arts) { + if (mid != NULL && !isCancelControl) { + if (!StatHistory || INNBBSstat(bbsnnrp,i,mid) != INNBBSstatOK) { + printf("** %d ** %d need it %s\n", artcount, artno,mid); + XHDR[artcount].artno = artno; + XHDR[artcount].header = restrdup(XHDR[artcount].header,mid); + /*INNBBSihave(bbsnnrp,i,artno,mid);*/ + /* to get it */ + artcount++; + } + } else if (mid != NULL) { + if (INNBBSstat(bbsnnrp,i,mid) == INNBBSstatOK) { + printf("** %d ** %d need cancel %s\n", artcount, artno,mid); + XHDR[artcount].artno = artno; + XHDR[artcount].header = restrdup(XHDR[artcount].header,mid); + artcount++; + } + } + maxartno = artno; + } + } + }/* while xhdr OK */ + exception = 0; + for (xcount = 0; xcount < artcount; xcount++) { + ULONG artno; + char *mid; + artno = XHDR[xcount].artno; + mid = XHDR[xcount].header; + if (isCancelControl) { + if (NNRPstat(bbsnnrp,artno,&mid) == NNRPstatOK) { + } + } + printf("** %d ** %d i have it %s\n", xcount, artno, mid); + if (!ResetActive && mid != NULL) + exception = INNBBSihave(bbsnnrp,artno,mid); + if (exception == -1) break; + if (rcptr->high != artno) { + rcptr->high = artno; + updaterc(rcptr->highptr, rcptr->highlen, rcptr->high); + } + } + if (rcptr->high != maxartno && exception != -1) { + bbsnnrp->actdirty = 1; + rcptr->high = maxartno; + updaterc(rcptr->highptr, rcptr->highlen, maxartno); + } + } + } + /* + flushrc(bbsnnrp); + */ + } + fprintf(bbsnnrp->innbbsout,"quit\r\n"); + fprintf(bbsnnrp->nnrpout,"quit\r\n"); + fflush(bbsnnrp->innbbsout); + fflush(bbsnnrp->nnrpout); + fgets(NNRPbuffer, sizeof NNRPbuffer, bbsnnrp->nnrpin); + fgets(INNBBSbuffer, sizeof INNBBSbuffer, bbsnnrp->innbbsin); + +/* bbsnnrp->newsrc[0].high = 1900; + updaterc(bbsnnrp->newsrc[0].highptr, bbsnnrp->newsrc[0].highlen, + bbsnnrp->newsrc[0].high); +*/ +} + +INNBBSDhalt() +{ +} diff --git a/pttbbs/innbbsd/clibrary.h b/pttbbs/innbbsd/clibrary.h new file mode 100644 index 00000000..92ec82e0 --- /dev/null +++ b/pttbbs/innbbsd/clibrary.h @@ -0,0 +1,131 @@ +/* $Revision: 1.1 $ +** +** Here be declarations of routines and variables in the C library. +** You must #include and before this file. +*/ + +#if defined(DO_HAVE_UNISTD) +#include +#endif /* defined(DO_HAVE_UNISTD) */ + +#if defined(DO_HAVE_VFORK) +#include +#endif /* defined(DO_HAVE_VFORK) */ + + /* Generic pointer, used by memcpy, malloc, etc. */ + /* =()@ *POINTER;>()= */ +typedef char *POINTER; + /* What is a file offset? Will not work unless long! */ + /* =()@ OFFSET_T;>()= */ +typedef long OFFSET_T; + /* What is the type of an object size? */ + /* =()@ SIZE_T;>()= */ +typedef int SIZE_T; + /* What is the type of a passwd uid and gid, for use in chown(2)? */ + /* =()@ UID_T;>()= */ +typedef int UID_T; + /* =()@ GID_T;>()= */ +typedef int GID_T; + /* =()@ PID_T;>()= */ +typedef int PID_T; + /* What should a signal handler return? */ + /* =()<#define SIGHANDLER @@>()= */ +#define SIGHANDLER void + +#if defined(SIG_DFL) + /* What types of variables can be modified in a signal handler? */ + /* =()@ SIGVAR;>()= */ +typedef int SIGVAR; +#endif /* defined(SIG_DFL) */ + +/* =()<#include @@>()= */ +#include +/* =()<#include @@>()= */ +#include + + +/* +** It's a pity we have to go through these contortions, for broken +** systems that have fd_set but not the FD_SET. +*/ +#if defined(FD_SETSIZE) +#define FDSET fd_set +#else +#include +#if !defined(NOFILE) + error -- #define NOFILE to the number of files allowed on your machine! +#endif /* !defined(NOFILE) */ +#if !defined(howmany) +#define howmany(x, y) (((x) + ((y) - 1)) / (y)) +#endif /* !defined(howmany) */ +#define FD_SETSIZE NOFILE +#define NFDBITS (sizeof (long) * 8) +typedef struct _FDSET { + long fds_bits[howmany(FD_SETSIZE, NFDBITS)]; +} FDSET; +#define FD_SET(n, p) (p)->fds_bits[(n) / NFDBITS] |= (1 << ((n) % NFDBITS)) +#define FD_CLR(n, p) (p)->fds_bits[(n) / NFDBITS] &= ~(1 << ((n) % NFDBITS)) +#define FD_ISSET(n, p) ((p)->fds_bits[(n) / NFDBITS] & (1 << ((n) % NFDBITS))) +#define FD_ZERO(p) (void)memset((POINTER)(p), 0, sizeof *(p)) +#endif /* defined(FD_SETSIZE) */ + + +#if !defined(SEEK_SET) +#define SEEK_SET 0 +#endif /* !defined(SEEK_SET) */ +#if !defined(SEEK_END) +#define SEEK_END 2 +#endif /* !defined(SEEK_END) */ + +/* +** We must use #define to set FREEVAL, since "typedef void FREEVAL;" doesn't +** work on some broken compilers, sigh. +*/ +/* =()<#define FREEVAL @@>()= */ +#define FREEVAL int + +extern int optind; +extern char *optarg; +#if !defined(__STDC__) +extern int errno; +#endif /* !defined(__STDC__) */ + +extern char *getenv(); +extern char *inet_ntoa(); +extern char *mktemp(); +#if !defined(strerror) +extern char *strerror(); +#endif /* !defined(strerror) */ +extern long atol(); +extern time_t time(); +extern unsigned long inet_addr(); +extern FREEVAL free(); +extern POINTER malloc(); +extern POINTER realloc(); +#if defined(ACT_MMAP) +extern char *mmap(); +#endif /* defined(ACT_MMAP) */ + +/* Some backward systems need this. */ +extern FILE *popen(); + +/* This is in , but not in some system string headers, + * so we put it here just in case. */ +extern int strncasecmp(); + +/* =()@ abort();>()= */ +extern int abort(); +/* =()@ alarm();>()= */ +extern int alarm(); +/* =()@ exit();>()= */ +extern void exit(); +/* =()@ getpid();>()= */ +extern int getpid(); +/* =()@ lseek();>()= */ +extern off_t lseek(); +/* =()@ qsort();>()= */ +extern int qsort(); +/* =()@ sleep();>()= */ +extern int sleep(); +/* =()@ _exit();>()= */ +extern int _exit(); diff --git a/pttbbs/innbbsd/closeonexec.c b/pttbbs/innbbsd/closeonexec.c new file mode 100644 index 00000000..e005e51b --- /dev/null +++ b/pttbbs/innbbsd/closeonexec.c @@ -0,0 +1,66 @@ +/* $Revision: 1.1 $ +** +*/ +/*#include "configdata.h"*/ +#include +#include +#include +#include +#include "clibrary.h" + +#ifndef CLX_IOCTL +# define CLX_IOCTL +#endif +#ifndef CLX_FCNTL +# define CLX_FCNTL +#endif + + + +#if defined(CLX_IOCTL) && !defined(IRIX) +#ifdef __linux +# include +#else +# include +#endif + + +/* +** Mark a file close-on-exec so that it doesn't get shared with our +** children. Ignore any error codes. +*/ +void +closeOnExec(fd, flag) + int fd; + int flag; +{ + int oerrno; + + oerrno = errno; + (void)ioctl(fd, flag ? FIOCLEX : FIONCLEX, (char *)NULL); + errno = oerrno; +} +#endif /* defined(CLX_IOCTL) */ + + + +#if defined(CLX_FCNTL) +#include + + +/* +** Mark a file close-on-exec so that it doesn't get shared with our +** children. Ignore any error codes. +*/ +void +CloseOnExec(fd, flag) + int fd; + int flag; +{ + int oerrno; + + oerrno = errno; + (void)fcntl(fd, F_SETFD, flag ? 1 : 0); + errno = oerrno; +} +#endif /* defined(CLX_FCNTL) */ diff --git a/pttbbs/innbbsd/connectsock.c b/pttbbs/innbbsd/connectsock.c new file mode 100644 index 00000000..71203cfe --- /dev/null +++ b/pttbbs/innbbsd/connectsock.c @@ -0,0 +1,452 @@ +#include "innbbsconf.h" +#include "daemon.h" +#include +#include + +static jmp_buf timebuf; + +static void +timeout(sig) + int sig; +{ + longjmp(timebuf, sig); +} + +extern int errno; +static void reapchild (s) +int s; +{ + int state; + while (waitpid(-1,&state,WNOHANG|WUNTRACED)>0) { + /* printf("reaping child\n");*/ + } +} + +void dokill(s) +int s; +{ + kill(0,SIGKILL); +} + +static INETDstart = 0; +int startfrominetd(flag) +{ + INETDstart = flag ; +} + + +int standalonesetup(fd) +int fd; +{ + int on =1; + struct linger foobar; + if (setsockopt(fd,SOL_SOCKET, SO_REUSEADDR,(char *)&on,sizeof(on)) < 0) + syslog(LOG_ERR, "setsockopt (SO_REUSEADDR): %m"); + foobar.l_onoff = 0; + if (setsockopt(fd, SOL_SOCKET, SO_LINGER, (char*)&foobar, sizeof (foobar))<0) + syslog(LOG_ERR, "setsockopt (SO_LINGER): %m"); +} + +static char *UNIX_SERVER_PATH; +static int (*halt)(); + +sethaltfunction(haltfunc) +int (*haltfunc)(); +{ + halt = haltfunc; +} + +void docompletehalt(s) +int s; +{ + /*printf("try to remove %s\n", UNIX_SERVER_PATH); + unlink(UNIX_SERVER_PATH);*/ + exit(0); + /*dokill();*/ +} + +void doremove(s) +int s; +{ + if (halt != NULL) + (*halt)(s); + else + docompletehalt(s); +} + + +initunixserver(path, protocol) +char *path; +char *protocol; +{ + struct sockaddr_un s_un; + /* unix endpoint address */ + struct protoent *pe; /*protocol information entry*/ + int s; + char *ptr; + + bzero((char*)&s_un,sizeof(s_un)); + s_un.sun_family= AF_UNIX; + strcpy(s_un.sun_path, path); + if (protocol==NULL) + protocol="tcp"; + /* map protocol name to protocol number */ + pe=getprotobyname(protocol); + if (pe==NULL) { + fprintf(stderr,"%s: Unknown protocol.\n",protocol); + return (-1); + } + + /* Allocate a socket */ + s = socket(PF_UNIX,strcmp(protocol,"tcp")?SOCK_DGRAM:SOCK_STREAM,0); + if (s<0) { + printf("protocol %d\n", pe->p_proto); + perror("socket"); + return -1; + } + /*standalonesetup(s);*/ + signal(SIGHUP, SIG_IGN); + signal(SIGUSR1, SIG_IGN); + signal(SIGCHLD,reapchild); + UNIX_SERVER_PATH = path; + signal(SIGINT,doremove); + signal(SIGTERM,doremove); + + chdir("/"); + if (bind(s,(struct sockaddr*)&s_un,sizeof (struct sockaddr_un))<0){ + perror("bind"); + perror(path); + return -1; + } + listen(s,10); + return s; +} + +initinetserver(service,protocol) +char *service; +char *protocol; +{ + struct servent *se; /*service information entry*/ + struct hostent *he; /*host information entry*/ + struct protoent *pe; /*protocol information entry*/ + struct sockaddr_in sin;/*Internet endpoint address*/ + int port,s; + int randomport=0; + + bzero((char*)&sin,sizeof(sin)); + sin.sin_family= AF_INET; + if (!strcmp("0",service)) { + randomport = 1; + sin.sin_addr.s_addr = INADDR_ANY; + } + + if (service==NULL) + service=DEFAULTPORT; + if (protocol==NULL) + protocol="tcp"; + /* map service name to port number */ + /* service ---> port */ + se = getservbyname(service,protocol); + if (se==NULL) { + port = htons((u_short)atoi(service)); + if (port==0 && !randomport) { + fprintf (stderr, "%s/%s: Unknown service.\n",service,protocol); + return (-1); + } + } else + port=se->s_port; + sin.sin_port = port; + + /* map protocol name to protocol number */ + pe=getprotobyname(protocol); + if (pe==NULL) { + fprintf(stderr,"%s: Unknown protocol.\n",protocol); + return (-1); + } + + /* Allocate a socket */ + s = socket(PF_INET,strcmp(protocol,"tcp")?SOCK_DGRAM:SOCK_STREAM,pe->p_proto); + if (s<0) { + perror("socket"); + return -1; + } + standalonesetup(s); + signal(SIGHUP, SIG_IGN); + signal(SIGUSR1, SIG_IGN); + signal(SIGCHLD,reapchild); + signal(SIGINT,dokill); + signal(SIGTERM,dokill); + + chdir("/"); + if (bind(s,(struct sockaddr*)&sin,sizeof (struct sockaddr_in))<0){ + perror("bind"); + return -1; + } + listen(s,10); +#ifdef DEBUG + { int length=sizeof(sin); + getsockname(s,&sin,&length); + printf("portnum alocalted %d\n",sin.sin_port); + } +#endif + return s; +} + +int open_unix_listen(path,protocol,initfunc) +char *path; +char *protocol; +int (*initfunc) ARG((int)); +{ + int s; + s = initunixserver(path,protocol); + if (s<0) { + return -1; + } + if (initfunc != NULL) { + printf("in inetsingleserver before initfunc s %d\n",s); + if ((*initfunc)(s)<0) { + perror("initfunc error"); + return -1; + } + printf("end inetsingleserver before initfunc \n"); + } + return s; +} + +int open_listen(service,protocol,initfunc) +char *service; +char *protocol; +int (*initfunc) ARG((int)); +{ + int s; + if (! INETDstart) + s = initinetserver(service,protocol); + else + s = 0; + if (s<0) { + return -1; + } + if (initfunc != NULL) { + printf("in inetsingleserver before initfunc s %d\n",s); + if ((*initfunc)(s)<0) { + perror("initfunc error"); + return -1; + } + printf("end inetsingleserver before initfunc \n"); + } + return s; +} + +int inetsingleserver(service,protocol,serverfunc,initfunc) +char *service; +char *protocol; +int (*initfunc) ARG((int)); +int (*serverfunc) ARG((int)); +{ + int s; + if (!INETDstart) + s = initinetserver(service,protocol); + else + s = 0; + if (s<0) { + return -1; + } + if (initfunc != NULL) { + printf("in inetsingleserver before initfunc s %d\n",s); + if ((*initfunc)(s)<0) { + perror("initfunc error"); + return -1; + } + printf("end inetsingleserver before initfunc \n"); + } + { + int ns=tryaccept(s); + int result=0; + if (ns < 0 && errno != EINTR){ +#ifdef DEBUGSERVER + perror("accept"); +#endif + } + close(s); + if (serverfunc != NULL) + result = (*serverfunc)(ns); + close(ns); + return(result); + } +} + + +int tryaccept(s) +int s; +{ + int ns,fromlen; + struct sockaddr sockaddr;/*Internet endpoint address*/ + fromlen=sizeof (struct sockaddr_in); + +#ifdef DEBUGSERVER + fputs("Listening again\n",stdout); +#endif + do { + ns = accept(s,&sockaddr,&fromlen); + errno = 0; + } while ( ns < 0 && errno == EINTR ); + return ns; +} + +int inetserver(service,protocol,serverfunc) +char *service; +char *protocol; +int (*serverfunc) ARG((int)); +{ + int port,s; + + if (!INETDstart) + s = initinetserver(service,protocol); + else + s = 0; + if (s<0) { + return -1; + } + for (;;) { + int ns=tryaccept(s); + int result=0; + int pid; + if (ns < 0 && errno != EINTR){ +#ifdef DEBUGSERVER + perror("accept"); +#endif + continue; + } +#ifdef DEBUGSERVER + fputs("Accept OK\n",stdout); +#endif + pid = fork(); + if (pid==0) { + close(s); + if (serverfunc != NULL) + result = (*serverfunc)(ns); + close(ns); + exit(result); + } else if (pid < 0) { + perror("fork"); + return -1; + } + close(ns); + } + return 0; +} + +int inetclient(server,service,protocol) +char *server; +char *protocol; +char *service; +{ + struct servent *se; /*service information entry*/ + struct hostent *he; /*host information entry*/ + struct protoent *pe; /*protocol information entry*/ + struct sockaddr_in sin;/*Internet endpoint address*/ + int port,s; + + bzero((char*)&sin,sizeof(sin)); + sin.sin_family= AF_INET; + + if (service==NULL) + service=DEFAULTPORT; + if (protocol==NULL) + protocol="tcp"; + if (server==NULL) + server=DEFAULTSERVER; + /* map service name to port number */ + /* service ---> port */ + se = getservbyname(service,protocol); + if (se==NULL) { + port = htons((u_short)atoi(service)); + if (port==0) { + fprintf (stderr, "%s/%s: Unknown service.\n",service,protocol); + return (-1); + } + } else + port=se->s_port; + sin.sin_port = port; + + /* map server hostname to IP address, allowing for dotted decimal */ + he=gethostbyname(server); + if (he==NULL) { + sin.sin_addr.s_addr = inet_addr(server); + if (sin.sin_addr.s_addr==INADDR_NONE) { + fprintf (stderr, "%s: Unknown host.\n",server); + return (-1); + } + } else + bcopy(he->h_addr,(char*)&sin.sin_addr,he->h_length); + + /* map protocol name to protocol number */ + pe=getprotobyname(protocol); + if (pe==NULL) { + fprintf(stderr,"%s: Unknown protocol.\n",protocol); + return (-1); + } + + /* Allocate a socket */ + s = socket(PF_INET,strcmp(protocol,"tcp")?SOCK_DGRAM:SOCK_STREAM,pe->p_proto); + if (s<0) { + perror("socket"); + return -1; + } + + if (setjmp(timebuf) == 0) + { + signal(SIGALRM, timeout); + alarm(5); + if (connect(s,(struct sockaddr*)&sin,sizeof(sin))<0) + { + alarm(0); + return -1; + } + } + else + { + alarm(0); + return -1; + } + alarm(0); + + return s; +} + +int unixclient(path,protocol) +char *path; +char *protocol; +{ + struct protoent *pe; /*protocol information entry*/ + struct sockaddr_un s_un;/*unix endpoint address*/ + int s; + + bzero((char*)&s_un,sizeof(s_un)); + s_un.sun_family= AF_UNIX; + + if (path==NULL) + path=DEFAULTPATH; + if (protocol==NULL) + protocol="tcp"; + strcpy(s_un.sun_path , path); + + /* map protocol name to protocol number */ + pe=getprotobyname(protocol); + if (pe==NULL) { + fprintf(stderr,"%s: Unknown protocol.\n",protocol); + return (-1); + } + /* Allocate a socket */ + s = socket(PF_UNIX,strcmp(protocol,"tcp")?SOCK_DGRAM:SOCK_STREAM,0); + if (s<0) { + perror("socket"); + return -1; + } + /* Connect the socket to the server */ + if (connect(s,(struct sockaddr*)&s_un,sizeof(s_un))<0) { + /*perror("connect");*/ + return -1; + } + return s; +} diff --git a/pttbbs/innbbsd/ctlinnbbsd.c b/pttbbs/innbbsd/ctlinnbbsd.c new file mode 100644 index 00000000..4ba77b52 --- /dev/null +++ b/pttbbs/innbbsd/ctlinnbbsd.c @@ -0,0 +1,160 @@ +#include "innbbsconf.h" +#include "bbslib.h" + +extern char *optarg; +extern int opterr, optind; + +usage(name) +char *name; +{ + fprintf(stderr, "Usage: %s [-p path] commands\n",name); + fprintf(stderr, " where available commands:\n"); + fprintf(stderr," ctlinnbbsd reload : reload datafiles for innbbsd\n"); + fprintf(stderr," ctlinnbbsd shutdown : shutdown innbbsd gracefully\n"); + fprintf(stderr," ctlinnbbsd mode : examine mode of innbbsd\n"); + fprintf(stderr," ctlinnbbsd addhist path: add history\n"); + fprintf(stderr," ctlinnbbsd grephist : query history\n"); + fprintf(stderr," ctlinnbbsd verboselog on|off : verboselog on/off\n"); + fprintf(stderr," ctlinnbbsd hismaint : maintain history\n"); + fprintf(stderr," ctlinnbbsd listnodelist : list nodelist.bbs\n"); + fprintf(stderr," ctlinnbbsd listnewsfeeds : list newsfeeds.bbs\n"); +#ifdef GETRUSAGE + fprintf(stderr," ctlinnbbsd getrusage: get resource usage\n"); +#endif +#ifdef MALLOCMAP + fprintf(stderr," ctlinnbbsd mallocmap: get malloc map\n"); +#endif +} + + +char *DefaultPath = LOCALDAEMON; +char INNBBSbuffer[4096]; + +FILE *innbbsin, *innbbsout; +int innbbsfd; + +ctlinnbbsd(argc, argv) +int argc; +char **argv; +{ + fgets(INNBBSbuffer, sizeof INNBBSbuffer, innbbsin); + printf("%s",INNBBSbuffer); + if (strcasecmp(argv[0], "shutdown")==0 || + strcasecmp(argv[0], "reload")==0 || + strcasecmp(argv[0], "hismaint")==0 || +#ifdef GETRUSAGE + strcasecmp(argv[0], "getrusage")==0 || +#endif +#ifdef MALLOCMAP + strcasecmp(argv[0], "mallocmap")==0 || +#endif + strcasecmp(argv[0], "mode")==0 || + strcasecmp(argv[0], "listnodelist")==0 || + strcasecmp(argv[0], "listnewsfeeds")==0 + ) { + fprintf( innbbsout, "%s\r\n", argv[0]); + fflush( innbbsout); + fgets(INNBBSbuffer, sizeof INNBBSbuffer, innbbsin); + printf("%s",INNBBSbuffer); + if (strcasecmp(argv[0], "mode") ==0 +#ifdef GETRUSAGE + || + strcasecmp(argv[0], "getrusage") ==0 + || + strcasecmp(argv[0], "mallocmap") ==0 +#endif + || + strcasecmp(argv[0], "listnodelist")==0 + || + strcasecmp(argv[0], "listnewsfeeds")==0 + ) { + while (fgets(INNBBSbuffer, sizeof INNBBSbuffer, innbbsin) != NULL) { + if (strcmp(INNBBSbuffer,".\r\n")==0) { + break; + } + printf("%s",INNBBSbuffer); + } + } + } else if (strcasecmp(argv[0], "grephist")==0 || + strcasecmp(argv[0], "verboselog")==0 ) { + if (argc < 2) { + usage("ctlinnbbsd"); + } else { + fprintf( innbbsout, "%s %s\r\n", argv[0], argv[1]); + fflush( innbbsout); + fgets(INNBBSbuffer, sizeof INNBBSbuffer, innbbsin); + printf("%s\n",INNBBSbuffer); + } + } else if (strcasecmp(argv[0], "addhist")==0) { + if (argc < 3) { + usage("ctlinnbbsd"); + } else { + fprintf( innbbsout, "%s %s %s\r\n", argv[0], argv[1], argv[2]); + fflush( innbbsout); + fgets(INNBBSbuffer, sizeof INNBBSbuffer, innbbsin); + printf("%s",INNBBSbuffer); + } + } else { + fprintf(stderr, "invalid command %s\n", argv[0]); + } + if (strcasecmp(argv[0],"shutdown") != 0) { + fprintf( innbbsout, "QUIT\r\n"); + fflush(innbbsout); + fgets(INNBBSbuffer, sizeof INNBBSbuffer, innbbsin); + } +} + +initsocket() +{ + innbbsfd = unixclient(DefaultPath,"tcp"); + if (innbbsfd < 0) { + fprintf(stderr, "Connect to %s error. You may not run innbbsd\n", DefaultPath); + exit(2); + } + if ( (innbbsin= fdopen(innbbsfd,"r")) == NULL || + (innbbsout= fdopen(innbbsfd,"w"))== NULL ) { + fprintf( stderr, "fdopen error\n"); + exit(3); + } +} + +closesocket() +{ + if (innbbsin != NULL) + fclose(innbbsin); + if (innbbsout != NULL) + fclose(innbbsout); + if (innbbsfd >= 0) + close(innbbsfd); +} + +main(argc, argv) +int argc; +char **argv; +{ + int c, errflag=0; + + while ((c = getopt(argc,argv,"p:h?"))!= -1) + switch (c) { + case 'p': + DefaultPath = optarg; + break; + case 'h': + case '?': + default: + errflag ++; + break; + } + if (errflag > 0) { + usage(argv[0]); + return(1); + } + if (argc - optind < 1) { + usage(argv[0]); + exit(1); + } + initial_bbs(NULL); + initsocket(); + ctlinnbbsd(argc-optind, argv+optind); + closesocket(); +} diff --git a/pttbbs/innbbsd/daemon.c b/pttbbs/innbbsd/daemon.c new file mode 100644 index 00000000..973a96c8 --- /dev/null +++ b/pttbbs/innbbsd/daemon.c @@ -0,0 +1,173 @@ +#include "daemon.h" +/* +typedef struct daemoncmd { + char *cmdname; + char *usage; + int argc; + int (*main) ARG((FILE*,FILE*,int,char**,char*)); +} daemoncmd_t; + +*/ + +void deargify ARG((char ***)); +static daemoncmd_t *dcmdp=NULL; +static char *startupmessage=NULL; +static int startupcode=100; +static FILE *DIN,*DOUT,*DIO; +typedef int (*F)(); + +void installdaemon(cmds,code,startupmsg) +daemoncmd_t *cmds; +int code; +char *startupmsg; +{ + dcmdp = cmds; + startupcode = code; + startupmessage = startupmsg; +} + +daemoncmd_t *searchcmd(cmd) +char *cmd; +{ + daemoncmd_t *p; + for (p=dcmdp;p->name != NULL ; p++) { +#ifdef DEBUGCMD + printf("searching name %s for cmd %s\n",p->name,cmd); +#endif + if (!strncasecmp(p->name,cmd,1024)) + return p; + } + return NULL; +} + +#if 0 +int daemon(dfd) +int dfd; +{ + static char BUF[1024]; + /*hash_init();*/ + if (dfd > 0) { + DIO = fdopen(dfd,"rw"); + DIN = fdopen(dfd,"r"); + DOUT = fdopen(dfd,"w"); + if (DIO == NULL || DIN == NULL || DOUT == NULL) { + perror("fdopen"); + return -1; + } + } + if (startupmessage) { + fprintf(DOUT,"%d %s\n",startupcode,startupmessage); + fflush(DOUT); + } + while (fgets(BUF,1024,DIN) != NULL) { + int i; + int (*Main)(); + daemoncmd_t *dp; + argv_t Argv; + + char *p=(char*)strchr(BUF,'\r'); + if (p == NULL) p=(char*)strchr(BUF,'\n'); + if (p == NULL) continue; + *p='\0'; + if (p==BUF) continue; + + Argv.argc = 0, Argv.argv = NULL, Argv.inputline=BUF; + Argv.in = DIN, Argv.out = DOUT; + printf("command entered: %s\n",BUF); +#ifdef DEBUGSERVER + fprintf(DOUT,"BUF in client %s\n",BUF); + fprintf(stdout,"BUF in server %s\n",BUF); + fflush(DOUT); +#endif + Argv.argc = argify(BUF,&Argv.argv); +#ifdef DEBUGSERVER + fprintf(stdout,"argc %d argv ",Argv.argc); + for (i=0;iname,dp->usage); +#endif + if (Argv.argc < dp->argc) { + fprintf(DOUT,"%d Usage: %s\n",dp->errorcode,dp->usage); + fflush(DOUT); + goto cont; + } + if (dp->argno != 0 && Argv.argc > dp->argno) { + fprintf(DOUT,"%d Usage: %s\n",dp->errorcode,dp->usage); + fflush(DOUT); + goto cont; + } + Main=dp->main; + if (Main) { + fflush(stdout); + (*Main)(&Argv); + } + } + else { + fprintf(DOUT,"99 command %s not available\n",Argv.argv[0]); + fflush(DOUT); + } +cont: + deargify(&Argv.argv); + } + /*hash_reclaim();*/ +} +#endif + +#define MAX_ARG 32 +#define MAX_ARG_SIZE 16384 + +int argify(line, argvp) +char *line, ***argvp; +{ + static char *argvbuffer[MAX_ARG+2]; + char **argv = argvbuffer; + int i; + static char argifybuffer[MAX_ARG_SIZE]; + char *p; + while (strchr("\t\n\r ",*line)) line++; + i=strlen(line); + /*p=(char*) mymalloc(i+1);*/ + p = argifybuffer; + strncpy(p,line, sizeof argifybuffer); + for (*argvp = argv, i=0 ;*p && i < MAX_ARG;){ + for (*argv++=p;*p && !strchr("\t\r\n ",*p);p++); + if (*p=='\0') break; + for (*p++='\0'; strchr("\t\r\n ",*p) && *p;p++); + } + *argv = NULL; + return argv - *argvp; +} + +void deargify (argv) +char ***argv; +{ + return; + /*if (*argv != NULL) { + if (*argv[0] != NULL){ + free(*argv[0]); + *argv[0] = NULL; + } + free(*argv); + *argv = NULL; + }*/ +} + +int daemonprintf(format) +char *format; +{ + fprintf(DOUT,format); + fflush(DOUT); +} + +int daemonputs(output) +char* output; +{ + fputs(output, DOUT); + fflush(DOUT); +} diff --git a/pttbbs/innbbsd/daemon.h b/pttbbs/innbbsd/daemon.h new file mode 100644 index 00000000..d056051f --- /dev/null +++ b/pttbbs/innbbsd/daemon.h @@ -0,0 +1,54 @@ +#ifndef DAEMON_H +#define DAEMON_H + +#include +#include + +#ifndef ARG +# ifdef __STDC__ +# define ARG(x) x +# else +# define ARG(x) () +# endif +#endif + + +struct Argv_t { + FILE *in,*out; + int argc; + char **argv; + char *inputline; + struct Daemoncmd *dc; +}; + +typedef struct Argv_t argv_t; + +typedef struct Buffer_t { + char *data; + int used, left, lastread; +} buffer_t; + +typedef struct ClientType { + char hostname[1024]; + char username[32]; + char buffer[4096]; + int mode; + argv_t Argv; + int fd, access, lastread, midcheck; + buffer_t in,out; + int ihavecount, ihavesize, ihaveduplicate, ihavefail; + int statcount, statfail; + time_t begin; +} ClientType; + +typedef struct Daemoncmd { + char *name; + char *usage; + int argc, argno, errorcode, normalcode; + int (*main) ARG(( ClientType*)); +} daemoncmd_t; + +extern void installdaemon ARG((daemoncmd_t *,int,char*)); +extern ClientType *Channel; + +#endif diff --git a/pttbbs/innbbsd/dbz.c b/pttbbs/innbbsd/dbz.c new file mode 100644 index 00000000..6fd15df8 --- /dev/null +++ b/pttbbs/innbbsd/dbz.c @@ -0,0 +1,1918 @@ +/* + +dbz.c V3.2 + +Copyright 1988 Jon Zeeff (zeeff@b-tech.ann-arbor.mi.us) +You can use this code in any manner, as long as you leave my name on it +and don't hold me responsible for any problems with it. + +Hacked on by gdb@ninja.UUCP (David Butler); Sun Jun 5 00:27:08 CDT 1988 + +Various improvments + INCORE by moraes@ai.toronto.edu (Mark Moraes) + +Major reworking by Henry Spencer as part of the C News project. + +Minor lint and CodeCenter (Saber) fluff removal by Rich $alz (March, 1991). +Non-portable CloseOnExec() calls added by Rich $alz (September, 1991). +Added "writethrough" and tagmask calculation code from + and by Rich $alz (December, 1992). +Merged in MMAP code by David Robinson, formerly +now (January, 1993). + +These routines replace dbm as used by the usenet news software +(it's not a full dbm replacement by any means). It's fast and +simple. It contains no AT&T code. + +In general, dbz's files are 1/20 the size of dbm's. Lookup performance +is somewhat better, while file creation is spectacularly faster, especially +if the incore facility is used. + +*/ + +#include +#include +#include +#include +#include +#ifndef __STDC__ +extern int errno; +#endif +#include +#include "clibrary.h" + +/* + * #ifdef index. "LIA" = "leave it alone unless you know what you're doing". + * + * FUNNYSEEKS SEEK_SET is not 0, get it from + * INDEX_SIZE backward compatibility with old dbz; avoid using this + * NMEMORY number of days of memory for use in sizing new table (LIA) + * INCORE backward compatibility with old dbz; use dbzincore() instead + * DBZDEBUG enable debugging + * DEFSIZE default table size (not as critical as in old dbz) + * OLDBNEWS default case mapping as in old B News; set NOBUFFER + * BNEWS default case mapping as in current B News; set NOBUFFER + * DEFCASE default case-map algorithm selector + * NOTAGS fseek offsets are strange, do not do tagging (see below) + * NPAGBUF size of .pag buffer, in longs (LIA) + * SHISTBUF size of ASCII-file buffer, in bytes (LIA) + * MAXRUN length of run which shifts to next table (see below) (LIA) + * OVERFLOW long-int arithmetic overflow must be avoided, will trap + * NOBUFFER do not buffer hash-table i/o, B News locking is defective + * MMAP Use SunOS style mmap() for efficient incore + */ +/* SUPPRESS 530 *//* Empty body for statement */ +/* SUPPRESS 701 on free *//* Conflicting declaration */ + +#ifdef FUNNYSEEKS +#include +#else +#define SEEK_SET 0 +#endif +#ifdef OVERFLOW +#include +#endif + +static int dbzversion = 3; /* for validating .dir file format */ + +/* + * The dbz database exploits the fact that when news stores a + * tuple, the `value' part is a seek offset into a text file, pointing to + * a copy of the `key' part. This avoids the need to store a copy of + * the key in the dbz files. However, the text file *must* exist and be + * consistent with the dbz files, or things will fail. + * + * The basic format of the database is a simple hash table containing the + * values. A value is stored by indexing into the table using a hash value + * computed from the key; collisions are resolved by linear probing (just + * search forward for an empty slot, wrapping around to the beginning of + * the table if necessary). Linear probing is a performance disaster when + * the table starts to get full, so a complication is introduced. The + * database is actually one *or more* tables, stored sequentially in the + * .pag file, and the length of linear-probe sequences is limited. The + * search (for an existing item or an empty slot) always starts in the + * first table, and whenever MAXRUN probes have been done in table N, + * probing continues in table N+1. This behaves reasonably well even in + * cases of massive overflow. There are some other small complications + * added, see comments below. + * + * The table size is fixed for any particular database, but is determined + * dynamically when a database is rebuilt. The strategy is to try to pick + * the size so the first table will be no more than 2/3 full, that being + * slightly before the point where performance starts to degrade. (It is + * desirable to be a bit conservative because the overflow strategy tends + * to produce files with holes in them, which is a nuisance.) + */ + +/* + * The following is for backward compatibility. + */ +#ifdef INDEX_SIZE +#define DEFSIZE INDEX_SIZE +#endif + +/* + * ANSI C says an offset into a file is a long, not an off_t, for some + * reason. This actually does simplify life a bit, but it's still nice + * to have a distinctive name for it. Beware, this is just for readability, + * don't try to change this. + */ +#define of_t long +#define SOF (sizeof(of_t)) + +/* + * We assume that unused areas of a binary file are zeros, and that the + * bit pattern of `(of_t)0' is all zeros. The alternative is rather + * painful file initialization. Note that okayvalue(), if OVERFLOW is + * defined, knows what value of an offset would cause overflow. + */ +#define VACANT ((of_t)0) +#define BIAS(o) ((o)+1) /* make any valid of_t non-VACANT */ +#define UNBIAS(o) ((o)-1) /* reverse BIAS() effect */ + +/* + * In a Unix implementation, or indeed any in which an of_t is a byte + * count, there are a bunch of high bits free in an of_t. There is a + * use for them. Checking a possible hit by looking it up in the base + * file is relatively expensive, and the cost can be dramatically reduced + * by using some of those high bits to tag the value with a few more bits + * of the key's hash. This detects most false hits without the overhead of + * seek+read+strcmp. We use the top bit to indicate whether the value is + * tagged or not, and don't tag a value which is using the tag bits itself. + * We're in trouble if the of_t representation wants to use the top bit. + * The actual bitmasks and offset come from the configuration stuff, + * which permits fiddling with them as necessary, and also suppressing + * them completely (by defining the masks to 0). We build pre-shifted + * versions of the masks for efficiency. + */ +static of_t tagbits; /* pre-shifted tag mask */ +static of_t taghere; /* pre-shifted tag-enable bit */ +static of_t tagboth; /* tagbits|taghere */ +#define HASTAG(o) ((o)&taghere) +#define TAG(o) ((o)&tagbits) +#define NOTAG(o) ((o)&~tagboth) +#define CANTAG(o) (((o)&tagboth) == 0) +#define MKTAG(v) (((v)< +#ifdef MAP_FILE +#define MAP__ARG (MAP_FILE | MAP_SHARED) +#else +#define MAP__ARG (MAP_SHARED) +#endif +#ifndef INCORE +#define INCORE +#endif +#endif + +/* + * For a program that makes many, many references to the database, it + * is a large performance win to keep the table in core, if it will fit. + * Note that this does hurt robustness in the event of crashes, and + * dbmclose() *must* be called to flush the in-core database to disk. + * The code is prepared to deal with the possibility that there isn't + * enough memory. There *is* an assumption that a size_t is big enough + * to hold the size (in bytes) of one table, so dbminit() tries to figure + * out whether this is possible first. + * + * The preferred way to ask for an in-core table is to do dbzincore(1) + * before dbminit(). The default is not to do it, although -DINCORE + * overrides this for backward compatibility with old dbz. + * + * We keep only the first table in core. This greatly simplifies the + * code, and bounds memory demand. Furthermore, doing this is a large + * performance win even in the event of massive overflow. + */ +#ifdef INCORE +static int incore = 1; +#else +static int incore = 0; +#endif + +/* + * Write to filesystem even if incore? This replaces a single multi- + * megabyte write when doing a dbzsync with a multi-byte write each + * time an article is added. On most systems, this will give an overall + * performance boost. + */ +static int writethrough = 0; + +/* + * Stdio buffer for .pag reads. Buffering more than about 16 does not help + * significantly at the densities we try to maintain, and the much larger + * buffers that most stdios default to are much more expensive to fill. + * With small buffers, stdio is performance-competitive with raw read(), + * and it's much more portable. + */ +#ifndef NPAGBUF +#define NPAGBUF 16 +#endif +#ifndef NOBUFFER +#ifdef _IOFBF +static of_t pagbuf[NPAGBUF]; /* only needed if !NOBUFFER && _IOFBF */ +#endif +#endif + +/* + * Stdio buffer for base-file reads. Message-IDs (all news ever needs to + * read) are essentially never longer than 64 bytes, and the typical stdio + * buffer is so much larger that it is much more expensive to fill. + */ +#ifndef SHISTBUF +#define SHISTBUF 64 +#endif +#ifdef _IOFBF +static char basebuf[SHISTBUF]; /* only needed if _IOFBF exists */ +#endif + +/* + * Data structure for recording info about searches. + */ +struct searcher { + of_t place; /* current location in file */ + int tabno; /* which table we're in */ + int run; /* how long we'll stay in this table */ +# ifndef MAXRUN +# define MAXRUN 100 +# endif + long hash; /* the key's hash code (for optimization) */ + of_t tag; /* tag we are looking for */ + int seen; /* have we examined current location? */ + int aborted; /* has i/o error aborted search? */ +}; +static void start(); +#define FRESH ((struct searcher *)NULL) +static of_t search(); +#define NOTFOUND ((of_t)-1) +static int okayvalue(); +static int set(); + +/* + * Arguably the searcher struct for a given routine ought to be local to + * it, but a fetch() is very often immediately followed by a store(), and + * in some circumstances it is a useful performance win to remember where + * the fetch() completed. So we use a global struct and remember whether + * it is current. + */ +static struct searcher srch; +static struct searcher *prevp; /* &srch or FRESH */ + +/* byte-ordering stuff */ +static int mybmap[SOF]; /* my byte order (see mybytemap()) */ +static int bytesame; /* is database order same as mine? */ +#define MAPIN(o) ((bytesame) ? (o) : bytemap((o), conf.bytemap, mybmap)) +#define MAPOUT(o) ((bytesame) ? (o) : bytemap((o), mybmap, conf.bytemap)) + +/* + * The double parentheses needed to make this work are ugly, but the + * alternative (under most compilers) is to pack around 2K of unused + * strings -- there's just no way to get rid of them. + */ +#ifdef DBZDEBUG +static int debug; /* controlled by dbzdebug() */ +#define DEBUG(args) if (debug) { (void) printf args ; } else +#else +#define DEBUG(args) ; +#endif + +/* externals used */ +#if 0 +extern char *memcpy(); +extern char *memchr(); +extern char *malloc(); +extern char *calloc(); +extern void free(); /* ANSI C; some old implementations say int */ +#endif /* 0 */ +extern int atoi(); +extern long atol(); +extern void CloseOnExec(); + +/* misc. forwards */ +static long hash(); +static void crcinit(); +static char *cipoint(); +static char *mapcase(); +static int isprime(); +static FILE *latebase(); + +/* file-naming stuff */ +static char dir[] = ".dir"; +static char pag[] = ".pag"; +static char *enstring(); + +/* central data structures */ +static FILE *basef; /* descriptor for base file */ +static char *basefname; /* name for not-yet-opened base file */ +static FILE *dirf; /* descriptor for .dir file */ +static int dirronly; /* dirf open read-only? */ +static FILE *pagf = NULL; /* descriptor for .pag file */ +static of_t pagpos; /* posn in pagf; only search may set != -1 */ +static int pagronly; /* pagf open read-only? */ +static of_t *corepag; /* incore version of .pag file, if any */ +static FILE *bufpagf; /* well-buffered pagf, for incore rewrite */ +static of_t *getcore(); +#ifndef MMAP +static int putcore(); +#endif +static int written; /* has a store() been done? */ + +/* + - dbzfresh - set up a new database, no historical info + */ +int /* 0 success, -1 failure */ +dbzfresh(name, size, fs, cmap, tagmask) +char *name; /* base name; .dir and .pag must exist */ +long size; /* table size (0 means default) */ +int fs; /* field-separator character in base file */ +int cmap; /* case-map algorithm (0 means default) */ +of_t tagmask; /* 0 default, 1 no tags */ +{ + register char *fn; + struct dbzconfig c; + register of_t m; + register FILE *f; + + if (pagf != NULL) { + DEBUG(("dbzfresh: database already open\n")); + return(-1); + } + if (size != 0 && size < 2) { + DEBUG(("dbzfresh: preposterous size (%ld)\n", size)); + return(-1); + } + + /* get default configuration */ + if (getconf((FILE *)NULL, (FILE *)NULL, &c) < 0) + return(-1); /* "can't happen" */ + + /* and mess with it as specified */ + if (size != 0) + c.tsize = size; + c.fieldsep = fs; + switch (cmap) { + case 0: + case '0': + case 'B': /* 2.10 compat */ + c.casemap = '0'; /* '\0' nicer, but '0' printable! */ + break; + case '=': + case 'b': /* 2.11 compat */ + c.casemap = '='; + break; + case 'C': + c.casemap = 'C'; + break; + case '?': + c.casemap = DEFCASE; + break; + default: + DEBUG(("dbzfresh case map `%c' unknown\n", cmap)); + return(-1); + } + switch ((int)tagmask) { + case 0: /* default */ + break; + case 1: /* no tags */ + c.tagshift = 0; + c.tagmask = 0; + c.tagenb = 0; + break; + default: + m = tagmask; + c.tagshift = 0; + while (!(m&01)) { + m >>= 1; + c.tagshift++; + } + c.tagmask = m; + c.tagenb = (m << 1) & ~m; + break; + } + + /* write it out */ + fn = enstring(name, dir); + if (fn == NULL) + return(-1); + f = fopen(fn, "w"); + free((POINTER)fn); + if (f == NULL) { + DEBUG(("dbzfresh: unable to write config\n")); + return(-1); + } + if (putconf(f, &c) < 0) { + (void) fclose(f); + return(-1); + } + if (fclose(f) == EOF) { + DEBUG(("dbzfresh: fclose failure\n")); + return(-1); + } + + /* create/truncate .pag */ + fn = enstring(name, pag); + if (fn == NULL) + return(-1); + f = fopen(fn, "w"); + free((POINTER)fn); + if (f == NULL) { + DEBUG(("dbzfresh: unable to create/truncate .pag file\n")); + return(-1); + } else + (void) fclose(f); + + /* and punt to dbminit for the hard work */ + return(dbminit(name)); +} + +/* + - dbzsize - what's a good table size to hold this many entries? + */ +long +dbzsize(contents) +long contents; /* 0 means what's the default */ +{ + register long n; + + if (contents <= 0) { /* foulup or default inquiry */ + DEBUG(("dbzsize: preposterous input (%ld)\n", contents)); + return(DEFSIZE); + } + n = (contents/2)*3; /* try to keep table at most 2/3 full */ + if (!(n&01)) /* make it odd */ + n++; + DEBUG(("dbzsize: tentative size %ld\n", n)); + while (!isprime(n)) /* and look for a prime */ + n += 2; + DEBUG(("dbzsize: final size %ld\n", n)); + + return(n); +} + +/* + - isprime - is a number prime? + * + * This is not a terribly efficient approach. + */ +static int /* predicate */ +isprime(x) +register long x; +{ + static int quick[] = { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 0 }; + register int *ip; + register long div; + register long stop; + + /* hit the first few primes quickly to eliminate easy ones */ + /* this incidentally prevents ridiculously small tables */ + for (ip = quick; (div = *ip) != 0; ip++) + if (x%div == 0) { + DEBUG(("isprime: quick result on %ld\n", (long)x)); + return(0); + } + + /* approximate square root of x */ + for (stop = x; x/stop < stop; stop >>= 1) + continue; + stop <<= 1; + + /* try odd numbers up to stop */ + for (div = *--ip; div < stop; div += 2) + if (x%div == 0) + return(0); + + return(1); +} + +/* + - dbzagain - set up a new database to be a rebuild of an old one + */ +int /* 0 success, -1 failure */ +dbzagain(name, oldname) +char *name; /* base name; .dir and .pag must exist */ +char *oldname; /* base name; all must exist */ +{ + register char *fn; + struct dbzconfig c; + register int i; + register long top; + register FILE *f; + register int newtable; + register of_t newsize; + struct stat sb; + register of_t m; + + if (pagf != NULL) { + DEBUG(("dbzagain: database already open\n")); + return(-1); + } + + /* pick up the old configuration */ + fn = enstring(oldname, dir); + if (fn == NULL) + return(-1); + f = fopen(fn, "r"); + free((POINTER)fn); + if (f == NULL) { + DEBUG(("dbzagain: cannot open old .dir file\n")); + return(-1); + } + i = getconf(f, (FILE *)NULL, &c); + (void) fclose(f); + if (i < 0) { + DEBUG(("dbzagain: getconf failed\n")); + return(-1); + } + + /* calculate tagging from old file */ + if (stat(oldname, &sb) != -1) { + for (m = 1, i = 0; m < sb.st_size; i++, m <<= 1) + continue; + + /* if we had more tags than the default, use the new data */ + if ((c.tagmask | c.tagenb) && m > (1 << TAGSHIFT)) { + c.tagshift = i; + c.tagmask = (~(unsigned long)0) >> (i + 1); + c.tagenb = (c.tagmask << 1) & ~c.tagmask; + } + } + + /* tinker with it */ + top = 0; + newtable = 0; + for (i = 0; i < NUSEDS; i++) { + if (top < c.used[i]) + top = c.used[i]; + if (c.used[i] == 0) + newtable = 1; /* hasn't got full usage history yet */ + } + if (top == 0) { + DEBUG(("dbzagain: old table has no contents!\n")); + newtable = 1; + } + for (i = NUSEDS-1; i > 0; i--) + c.used[i] = c.used[i-1]; + c.used[0] = 0; + newsize = dbzsize(top); + if (!newtable || newsize > c.tsize) /* don't shrink new table */ + c.tsize = newsize; + + /* write it out */ + fn = enstring(name, dir); + if (fn == NULL) + return(-1); + f = fopen(fn, "w"); + free((POINTER)fn); + if (f == NULL) { + DEBUG(("dbzagain: unable to write new .dir\n")); + return(-1); + } + i = putconf(f, &c); + (void) fclose(f); + if (i < 0) { + DEBUG(("dbzagain: putconf failed\n")); + return(-1); + } + + /* create/truncate .pag */ + fn = enstring(name, pag); + if (fn == NULL) + return(-1); + f = fopen(fn, "w"); + free((POINTER)fn); + if (f == NULL) { + DEBUG(("dbzagain: unable to create/truncate .pag file\n")); + return(-1); + } else + (void) fclose(f); + + /* and let dbminit do the work */ + return(dbminit(name)); +} + +/* + - dbminit - open a database, creating it (using defaults) if necessary + * + * We try to leave errno set plausibly, to the extent that underlying + * functions permit this, since many people consult it if dbminit() fails. + */ +int /* 0 success, -1 failure */ +dbminit(name) +char *name; +{ + register int i; + register size_t s; + register char *dirfname; + register char *pagfname; + + if (pagf != NULL) { + DEBUG(("dbminit: dbminit already called once\n")); + errno = 0; + return(-1); + } + + /* open the .dir file */ + dirfname = enstring(name, dir); + if (dirfname == NULL) + return(-1); + dirf = fopen(dirfname, "r+"); + if (dirf == NULL) { + dirf = fopen(dirfname, "r"); + dirronly = 1; + } else + dirronly = 0; + free((POINTER)dirfname); + if (dirf == NULL) { + DEBUG(("dbminit: can't open .dir file\n")); + return(-1); + } + CloseOnExec((int)fileno(dirf), 1); + + /* open the .pag file */ + pagfname = enstring(name, pag); + if (pagfname == NULL) { + (void) fclose(dirf); + return(-1); + } + pagf = fopen(pagfname, "r+b"); + if (pagf == NULL) { + pagf = fopen(pagfname, "rb"); + if (pagf == NULL) { + DEBUG(("dbminit: .pag open failed\n")); + (void) fclose(dirf); + free((POINTER)pagfname); + return(-1); + } + pagronly = 1; + } else if (dirronly) + pagronly = 1; + else + pagronly = 0; + if (pagf != NULL) + CloseOnExec((int)fileno(pagf), 1); +#ifdef NOBUFFER + /* + * B News does not do adequate locking on its database accesses. + * Why it doesn't get into trouble using dbm is a mystery. In any + * case, doing unbuffered i/o does not cure the problem, but does + * enormously reduce its incidence. + */ + (void) setbuf(pagf, (char *)NULL); +#else +#ifdef _IOFBF + (void) setvbuf(pagf, (char *)pagbuf, _IOFBF, sizeof(pagbuf)); +#endif +#endif + pagpos = -1; + /* don't free pagfname, need it below */ + + /* open the base file */ + basef = fopen(name, "r"); + if (basef == NULL) { + DEBUG(("dbminit: basefile open failed\n")); + basefname = enstring(name, ""); + if (basefname == NULL) { + (void) fclose(pagf); + (void) fclose(dirf); + free((POINTER)pagfname); + pagf = NULL; + return(-1); + } + } else + basefname = NULL; + if (basef != NULL) + CloseOnExec((int)fileno(basef), 1); +#ifdef _IOFBF + if (basef != NULL) + (void) setvbuf(basef, basebuf, _IOFBF, sizeof(basebuf)); +#endif + + /* pick up configuration */ + if (getconf(dirf, pagf, &conf) < 0) { + DEBUG(("dbminit: getconf failure\n")); + (void) fclose(basef); + (void) fclose(pagf); + (void) fclose(dirf); + free((POINTER)pagfname); + pagf = NULL; + errno = EDOM; /* kind of a kludge, but very portable */ + return(-1); + } + tagbits = conf.tagmask << conf.tagshift; + taghere = conf.tagenb << conf.tagshift; + tagboth = tagbits | taghere; + mybytemap(mybmap); + bytesame = 1; + for (i = 0; i < SOF; i++) + if (mybmap[i] != conf.bytemap[i]) + bytesame = 0; + + /* get first table into core, if it looks desirable and feasible */ + s = (size_t)conf.tsize * SOF; + if (incore && (of_t)(s/SOF) == conf.tsize) { + bufpagf = fopen(pagfname, (pagronly) ? "rb" : "r+b"); + if (bufpagf != NULL) { + corepag = getcore(bufpagf); + CloseOnExec((int)fileno(bufpagf), 1); + } + } else { + bufpagf = NULL; + corepag = NULL; + } + free((POINTER)pagfname); + + /* misc. setup */ + crcinit(); + written = 0; + prevp = FRESH; + DEBUG(("dbminit: succeeded\n")); + return(0); +} + +/* + - enstring - concatenate two strings into a malloced area + */ +static char * /* NULL if malloc fails */ +enstring(s1, s2) +char *s1; +char *s2; +{ + register char *p; + + p = malloc((size_t)strlen(s1) + (size_t)strlen(s2) + 1); + if (p != NULL) { + (void) strcpy(p, s1); + (void) strcat(p, s2); + } else { + DEBUG(("enstring(%s, %s) out of memory\n", s1, s2)); + } + return(p); +} + +/* + - dbmclose - close a database + */ +int +dbmclose() +{ + register int ret = 0; + + if (pagf == NULL) { + DEBUG(("dbmclose: not opened!\n")); + return(-1); + } + + if (fclose(pagf) == EOF) { + DEBUG(("dbmclose: fclose(pagf) failed\n")); + ret = -1; + } + pagf = basef; /* ensure valid pointer; dbzsync checks it */ + if (dbzsync() < 0) + ret = -1; + if (bufpagf != NULL && fclose(bufpagf) == EOF) { + DEBUG(("dbmclose: fclose(bufpagf) failed\n")); + ret = -1; + } + if (corepag != NULL) +#ifdef MMAP + if (munmap((caddr_t)corepag, (int)conf.tsize * SOF) == -1) { + DEBUG(("dbmclose: munmap failed\n")); + ret = -1; + } +#else + free((POINTER)corepag); +#endif + corepag = NULL; + if (basef) { + if (fclose(basef) == EOF) { + DEBUG(("dbmclose: fclose(basef) failed\n")); + ret = -1; + } + } + if (basefname != NULL) + free((POINTER)basefname); + basef = NULL; + pagf = NULL; + if (fclose(dirf) == EOF) { + DEBUG(("dbmclose: fclose(dirf) failed\n")); + ret = -1; + } + + DEBUG(("dbmclose: %s\n", (ret == 0) ? "succeeded" : "failed")); + return(ret); +} + +/* + - dbzsync - push all in-core data out to disk + */ +int +dbzsync() +{ + register int ret = 0; + + if (pagf == NULL) { + DEBUG(("dbzsync: not opened!\n")); + return(-1); + } + if (!written) + return(0); + +#ifndef MMAP + if (corepag != NULL && !writethrough) { + if (putcore(corepag, bufpagf) < 0) { + DEBUG(("dbzsync: putcore failed\n")); + ret = -1; + } + } +#endif + if (!conf.olddbz) + if (putconf(dirf, &conf) < 0) + ret = -1; + + DEBUG(("dbzsync: %s\n", (ret == 0) ? "succeeded" : "failed")); + return(ret); +} + +/* + - dbzcancel - cancel writing of in-core data + * Mostly for use from child processes. + * Note that we don't need to futz around with stdio buffers, because we + * always fflush them immediately anyway and so they never have stale data. + */ +int +dbzcancel() +{ + if (pagf == NULL) { + DEBUG(("dbzcancel: not opened!\n")); + return(-1); + } + + written = 0; + return(0); +} + +/* + - dbzfetch - fetch() with case mapping built in + */ +datum +dbzfetch(key) +datum key; +{ + char buffer[DBZMAXKEY + 1]; + datum mappedkey; + register size_t keysize; + + DEBUG(("dbzfetch: (%s)\n", key.dptr)); + + /* Key is supposed to be less than DBZMAXKEY */ + keysize = key.dsize; + if (keysize >= DBZMAXKEY) { + keysize = DBZMAXKEY; + DEBUG(("keysize is %d - truncated to %d\n", key.dsize, DBZMAXKEY)); + } + + mappedkey.dptr = mapcase(buffer, key.dptr, keysize); + buffer[keysize] = '\0'; /* just a debug aid */ + mappedkey.dsize = keysize; + + return(fetch(mappedkey)); +} + +/* + - fetch - get an entry from the database + * + * Disgusting fine point, in the name of backward compatibility: if the + * last character of "key" is a NUL, that character is (effectively) not + * part of the comparison against the stored keys. + */ +datum /* dptr NULL, dsize 0 means failure */ +fetch(key) +datum key; +{ + char buffer[DBZMAXKEY + 1]; + static of_t key_ptr; /* return value points here */ + datum output; + register size_t keysize; + register size_t cmplen; + register char *sepp; + + DEBUG(("fetch: (%s)\n", key.dptr)); + output.dptr = NULL; + output.dsize = 0; + prevp = FRESH; + + /* Key is supposed to be less than DBZMAXKEY */ + keysize = key.dsize; + if (keysize >= DBZMAXKEY) { + keysize = DBZMAXKEY; + DEBUG(("keysize is %d - truncated to %d\n", key.dsize, DBZMAXKEY)); + } + + if (pagf == NULL) { + DEBUG(("fetch: database not open!\n")); + return(output); + } else if (basef == NULL) { /* basef didn't exist yet */ + basef = latebase(); + if (basef == NULL) + return(output); + } + + cmplen = keysize; + sepp = &conf.fieldsep; + if (key.dptr[keysize-1] == '\0') { + cmplen--; + sepp = &buffer[keysize-1]; + } + start(&srch, &key, FRESH); + while ((key_ptr = search(&srch)) != NOTFOUND) { + DEBUG(("got 0x%lx\n", key_ptr)); + + /* fetch the key */ + if (fseek(basef, key_ptr, SEEK_SET) != 0) { + DEBUG(("fetch: seek failed\n")); + return(output); + } + if (fread((POINTER)buffer, 1, keysize, basef) != keysize) { + DEBUG(("fetch: read failed\n")); + return(output); + } + + /* try it */ + buffer[keysize] = '\0'; /* terminated for DEBUG */ + (void) mapcase(buffer, buffer, keysize); + DEBUG(("fetch: buffer (%s) looking for (%s) size = %d\n", + buffer, key.dptr, keysize)); + if (memcmp((POINTER)key.dptr, (POINTER)buffer, cmplen) == 0 && + (*sepp == conf.fieldsep || *sepp == '\0')) { + /* we found it */ + output.dptr = (char *)&key_ptr; + output.dsize = SOF; + DEBUG(("fetch: successful\n")); + return(output); + } + } + + /* we didn't find it */ + DEBUG(("fetch: failed\n")); + prevp = &srch; /* remember where we stopped */ + return(output); +} + +/* + - latebase - try to open a base file that wasn't there at the start + */ +static FILE * +latebase() +{ + register FILE *it; + + if (basefname == NULL) { + DEBUG(("latebase: name foulup\n")); + return(NULL); + } + it = fopen(basefname, "r"); + if (it == NULL) { + DEBUG(("latebase: still can't open base\n")); + } else { + DEBUG(("latebase: late open succeeded\n")); + free((POINTER)basefname); + basefname = NULL; +#ifdef _IOFBF + (void) setvbuf(it, basebuf, _IOFBF, sizeof(basebuf)); +#endif + } + if (it != NULL) + CloseOnExec((int)fileno(it), 1); + return(it); +} + +/* + - dbzstore - store() with case mapping built in + */ +int +dbzstore(key, data) +datum key; +datum data; +{ + char buffer[DBZMAXKEY + 1]; + datum mappedkey; + register size_t keysize; + + DEBUG(("dbzstore: (%s)\n", key.dptr)); + + /* Key is supposed to be less than DBZMAXKEY */ + keysize = key.dsize; + if (keysize >= DBZMAXKEY) { + DEBUG(("dbzstore: key size too big (%d)\n", key.dsize)); + return(-1); + } + + mappedkey.dptr = mapcase(buffer, key.dptr, keysize); + buffer[keysize] = '\0'; /* just a debug aid */ + mappedkey.dsize = keysize; + + return(store(mappedkey, data)); +} + +/* + - store - add an entry to the database + */ +int /* 0 success, -1 failure */ +store(key, data) +datum key; +datum data; +{ + of_t value; + + if (pagf == NULL) { + DEBUG(("store: database not open!\n")); + return(-1); + } else if (basef == NULL) { /* basef didn't exist yet */ + basef = latebase(); + if (basef == NULL) + return(-1); + } + if (pagronly) { + DEBUG(("store: database open read-only\n")); + return(-1); + } + if (data.dsize != SOF) { + DEBUG(("store: value size wrong (%d)\n", data.dsize)); + return(-1); + } + if (key.dsize >= DBZMAXKEY) { + DEBUG(("store: key size too big (%d)\n", key.dsize)); + return(-1); + } + + /* copy the value in to ensure alignment */ + (void) memcpy((POINTER)&value, (POINTER)data.dptr, SOF); + DEBUG(("store: (%s, %ld)\n", key.dptr, (long)value)); + if (!okayvalue(value)) { + DEBUG(("store: reserved bit or overflow in 0x%lx\n", value)); + return(-1); + } + + /* find the place, exploiting previous search if possible */ + start(&srch, &key, prevp); + while (search(&srch) != NOTFOUND) + continue; + + prevp = FRESH; + conf.used[0]++; + DEBUG(("store: used count %ld\n", conf.used[0])); + written = 1; + return(set(&srch, value)); +} + +/* + - dbzincore - control attempts to keep .pag file in core + */ +int /* old setting */ +dbzincore(value) +int value; +{ + register int old = incore; + +#ifndef MMAP + incore = value; +#endif + return(old); +} + +/* + - dbzwritethrough - write through the pag file in core + */ +int /* old setting */ +dbzwritethrough(value) +int value; +{ + register int old = writethrough; + + writethrough = value; + return(old); +} + +/* + - dbztagmask - calculate the correct tagmask for the given base file size + */ +long +dbztagmask(size) +register long size; +{ + register long m; + register long tagmask; + register int i; + + if (size <= 0) + return(0L); /* silly size */ + + for (m = 1, i = 0; m < size; i++, m <<= 1) + continue; + + if (m < (1 << TAGSHIFT)) + return(0L); /* not worth tagging */ + + tagmask = (~(unsigned long)0) >> (i + 1); + tagmask = tagmask << i; + return(tagmask); +} + +/* + - getconf - get configuration from .dir file + */ +static int /* 0 success, -1 failure */ +getconf(df, pf, cp) +register FILE *df; /* NULL means just give me the default */ +register FILE *pf; /* NULL means don't care about .pag */ +register struct dbzconfig *cp; +{ + register int c; + register int i; + int err = 0; + + c = (df != NULL) ? getc(df) : EOF; + if (c == EOF) { /* empty file, no configuration known */ + cp->olddbz = 0; + if (df != NULL && pf != NULL && getc(pf) != EOF) + cp->olddbz = 1; + cp->tsize = DEFSIZE; + cp->fieldsep = '\t'; + for (i = 0; i < NUSEDS; i++) + cp->used[i] = 0; + cp->valuesize = SOF; + mybytemap(cp->bytemap); + cp->casemap = DEFCASE; + cp->tagenb = TAGENB; + cp->tagmask = TAGMASK; + cp->tagshift = TAGSHIFT; + DEBUG(("getconf: defaults (%ld, %c, (0x%lx/0x%lx<<%d))\n", + cp->tsize, cp->casemap, cp->tagenb, + cp->tagmask, cp->tagshift)); + return(0); + } + (void) ungetc(c, df); + + /* first line, the vital stuff */ + if (getc(df) != 'd' || getc(df) != 'b' || getc(df) != 'z') + err = -1; + if (getno(df, &err) != dbzversion) + err = -1; + cp->tsize = getno(df, &err); + cp->fieldsep = (int)getno(df, &err); + while ((c = getc(df)) == ' ') + continue; + cp->casemap = c; + cp->tagenb = getno(df, &err); + cp->tagmask = getno(df, &err); + cp->tagshift = getno(df, &err); + cp->valuesize = getno(df, &err); + if (cp->valuesize != SOF) { + DEBUG(("getconf: wrong of_t size (%d)\n", cp->valuesize)); + err = -1; + cp->valuesize = SOF; /* to protect the loops below */ + } + for (i = 0; i < cp->valuesize; i++) + cp->bytemap[i] = getno(df, &err); + if (getc(df) != '\n') + err = -1; +#ifdef DBZDEBUG + DEBUG(("size %ld, sep %d, cmap %c, tags 0x%lx/0x%lx<<%d, ", cp->tsize, + cp->fieldsep, cp->casemap, cp->tagenb, cp->tagmask, + cp->tagshift)); + DEBUG(("bytemap (%d)", cp->valuesize)); + for (i = 0; i < cp->valuesize; i++) { + DEBUG((" %d", cp->bytemap[i])); + } + DEBUG(("\n")); +#endif + + /* second line, the usages */ + for (i = 0; i < NUSEDS; i++) + cp->used[i] = getno(df, &err); + if (getc(df) != '\n') + err = -1; + DEBUG(("used %ld %ld %ld...\n", cp->used[0], cp->used[1], cp->used[2])); + + if (err < 0) { + DEBUG(("getconf error\n")); + return(-1); + } + return(0); +} + +/* + - getno - get a long + */ +static long +getno(f, ep) +FILE *f; +int *ep; +{ + register char *p; +# define MAXN 50 + char getbuf[MAXN]; + register int c; + + while ((c = getc(f)) == ' ') + continue; + if (c == EOF || c == '\n') { + DEBUG(("getno: missing number\n")); + *ep = -1; + return(0); + } + p = getbuf; + *p++ = c; + while ((c = getc(f)) != EOF && c != '\n' && c != ' ') + if (p < &getbuf[MAXN-1]) + *p++ = c; + if (c == EOF) { + DEBUG(("getno: EOF\n")); + *ep = -1; + } else + (void) ungetc(c, f); + *p = '\0'; + + if (strspn(getbuf, "-1234567890") != strlen(getbuf)) { + DEBUG(("getno: `%s' non-numeric\n", getbuf)); + *ep = -1; + } + return(atol(getbuf)); +} + +/* + - putconf - write configuration to .dir file + */ +static int /* 0 success, -1 failure */ +putconf(f, cp) +register FILE *f; +register struct dbzconfig *cp; +{ + register int i; + register int ret = 0; + + if (fseek(f, (of_t)0, SEEK_SET) != 0) { + DEBUG(("fseek failure in putconf\n")); + ret = -1; + } + (void) fprintf(f, "dbz %d %ld %d %c %ld %ld %d %d", dbzversion, cp->tsize, + cp->fieldsep, cp->casemap, cp->tagenb, + cp->tagmask, cp->tagshift, cp->valuesize); + for (i = 0; i < cp->valuesize; i++) + (void) fprintf(f, " %d", cp->bytemap[i]); + (void) fprintf(f, "\n"); + for (i = 0; i < NUSEDS; i++) + (void) fprintf(f, "%ld%c", cp->used[i], (i < NUSEDS-1) ? ' ' : '\n'); + + (void) fflush(f); + if (ferror(f)) + ret = -1; + + DEBUG(("putconf status %d\n", ret)); + return(ret); +} + +/* + - getcore - try to set up an in-core copy of .pag file + */ +static of_t * /* pointer to copy, or NULL */ +getcore(f) +FILE *f; +{ + register of_t *p; + register size_t i; + register size_t nread; + register char *it; +#ifdef MMAP + struct stat st; + + if (fstat(fileno(f), &st) == -1) { + DEBUG(("getcore: fstat failed\n")); + return(NULL); + } + if (((size_t)conf.tsize * SOF) > st.st_size) { + /* file too small; extend it */ + if (ftruncate((int)fileno(f), conf.tsize * SOF) == -1) { + DEBUG(("getcore: ftruncate failed\n")); + return(NULL); + } + } + it = mmap((caddr_t)0, (size_t)conf.tsize * SOF, + pagronly ? PROT_READ : PROT_WRITE | PROT_READ, MAP__ARG, + (int)fileno(f), (off_t)0); + if (it == (char *)-1) { + DEBUG(("getcore: mmap failed\n")); + return(NULL); + } +#ifdef MC_ADVISE + /* not present in all versions of mmap() */ + madvise(it, (size_t)conf.tsize * SOF, MADV_RANDOM); +#endif +#else + it = malloc((size_t)conf.tsize * SOF); + if (it == NULL) { + DEBUG(("getcore: malloc failed\n")); + return(NULL); + } + + nread = fread((POINTER)it, SOF, (size_t)conf.tsize, f); + if (ferror(f)) { + DEBUG(("getcore: read failed\n")); + free((POINTER)it); + return(NULL); + } + + /* NOSTRICT *//* Possible pointer alignment problem */ + p = (of_t *)it + nread; + i = (size_t)conf.tsize - nread; + while (i-- > 0) + *p++ = VACANT; +#endif + /* NOSTRICT *//* Possible pointer alignment problem */ + return((of_t *)it); +} + +#ifndef MMAP +/* + - putcore - try to rewrite an in-core table + */ +static int /* 0 okay, -1 fail */ +putcore(tab, f) +of_t *tab; +FILE *f; +{ + if (fseek(f, (of_t)0, SEEK_SET) != 0) { + DEBUG(("fseek failure in putcore\n")); + return(-1); + } + (void) fwrite((POINTER)tab, SOF, (size_t)conf.tsize, f); + (void) fflush(f); + return((ferror(f)) ? -1 : 0); +} +#endif + +/* + - start - set up to start or restart a search + */ +static void +start(sp, kp, osp) +register struct searcher *sp; +register datum *kp; +register struct searcher *osp; /* may be FRESH, i.e. NULL */ +{ + register long h; + + h = hash(kp->dptr, kp->dsize); + if (osp != FRESH && osp->hash == h) { + if (sp != osp) + *sp = *osp; + DEBUG(("search restarted\n")); + } else { + sp->hash = h; + sp->tag = MKTAG(h / conf.tsize); + DEBUG(("tag 0x%lx\n", sp->tag)); + sp->place = h % conf.tsize; + sp->tabno = 0; + sp->run = (conf.olddbz) ? conf.tsize : MAXRUN; + sp->aborted = 0; + } + sp->seen = 0; +} + +/* + - search - conduct part of a search + */ +static of_t /* NOTFOUND if we hit VACANT or error */ +search(sp) +register struct searcher *sp; +{ + register of_t dest; + register of_t value; + of_t val; /* buffer for value (can't fread register) */ + register of_t place; + + if (sp->aborted) + return(NOTFOUND); + + for (;;) { + /* determine location to be examined */ + place = sp->place; + if (sp->seen) { + /* go to next location */ + if (--sp->run <= 0) { + sp->tabno++; + sp->run = MAXRUN; + } + place = (place+1)%conf.tsize + sp->tabno*conf.tsize; + sp->place = place; + } else + sp->seen = 1; /* now looking at current location */ + DEBUG(("search @ %ld\n", place)); + + /* get the tagged value */ + if (corepag != NULL && place < conf.tsize) { + DEBUG(("search: in core\n")); + value = MAPIN(corepag[place]); + } else { + /* seek, if necessary */ + dest = place * SOF; + if (pagpos != dest) { + if (fseek(pagf, dest, SEEK_SET) != 0) { + DEBUG(("search: seek failed\n")); + pagpos = -1; + sp->aborted = 1; + return(NOTFOUND); + } + pagpos = dest; + } + + /* read it */ + if (fread((POINTER)&val, sizeof(val), 1, pagf) == 1) + value = MAPIN(val); + else if (ferror(pagf)) { + DEBUG(("search: read failed\n")); + pagpos = -1; + sp->aborted = 1; + return(NOTFOUND); + } else + value = VACANT; + + /* and finish up */ + pagpos += sizeof(val); + } + + /* vacant slot is always cause to return */ + if (value == VACANT) { + DEBUG(("search: empty slot\n")); + return(NOTFOUND); + }; + + /* check the tag */ + value = UNBIAS(value); + DEBUG(("got 0x%lx\n", value)); + if (!HASTAG(value)) { + DEBUG(("tagless\n")); + return(value); + } else if (TAG(value) == sp->tag) { + DEBUG(("match\n")); + return(NOTAG(value)); + } else { + DEBUG(("mismatch 0x%lx\n", TAG(value))); + } + } + /* NOTREACHED */ +} + +/* + - okayvalue - check that a value can be stored + */ +static int /* predicate */ +okayvalue(value) +of_t value; +{ + if (HASTAG(value)) + return(0); +#ifdef OVERFLOW + if (value == LONG_MAX) /* BIAS() and UNBIAS() will overflow */ + return(0); +#endif + return(1); +} + +/* + - set - store a value into a location previously found by search + */ +static int /* 0 success, -1 failure */ +set(sp, value) +register struct searcher *sp; +of_t value; +{ + register of_t place = sp->place; + register of_t v = value; + + if (sp->aborted) + return(-1); + + if (CANTAG(v) && !conf.olddbz) { + v |= sp->tag | taghere; + if (v != UNBIAS(VACANT)) /* BIAS(v) won't look VACANT */ +#ifdef OVERFLOW + if (v != LONG_MAX) /* and it won't overflow */ +#endif + value = v; + } + DEBUG(("tagged value is 0x%lx\n", value)); + value = BIAS(value); + value = MAPOUT(value); + + /* If we have the index file in memory, use it */ + if (corepag != NULL && place < conf.tsize) { + corepag[place] = value; + DEBUG(("set: incore\n")); +#ifdef MMAP + return(0); +#else + if (!writethrough) + return(0); +#endif + } + + /* seek to spot */ + pagpos = -1; /* invalidate position memory */ + if (fseek(pagf, (of_t)(place * SOF), SEEK_SET) != 0) { + DEBUG(("set: seek failed\n")); + sp->aborted = 1; + return(-1); + } + + /* write in data */ + if (fwrite((POINTER)&value, SOF, 1, pagf) != 1) { + DEBUG(("set: write failed\n")); + sp->aborted = 1; + return(-1); + } + /* fflush improves robustness, and buffer re-use is rare anyway */ + if (fflush(pagf) == EOF) { + DEBUG(("set: fflush failed\n")); + sp->aborted = 1; + return(-1); + } + + DEBUG(("set: succeeded\n")); + return(0); +} + +/* + - mybytemap - determine this machine's byte map + * + * A byte map is an array of ints, sizeof(of_t) of them. The 0th int + * is the byte number of the high-order byte in my of_t, and so forth. + */ +static void +mybytemap(map) +int map[]; /* -> int[SOF] */ +{ + union { + of_t o; + char c[SOF]; + } u; + register int *mp = &map[SOF]; + register int ntodo; + register int i; + + u.o = 1; + for (ntodo = (int)SOF; ntodo > 0; ntodo--) { + for (i = 0; i < SOF; i++) + /* SUPPRESS 112 *//* Retrieving char where long is stored */ + if (u.c[i] != 0) + break; + if (i == SOF) { + /* trouble -- set it to *something* consistent */ + DEBUG(("mybytemap: nonexistent byte %d!!!\n", ntodo)); + for (i = 0; i < SOF; i++) + map[i] = i; + return; + } + DEBUG(("mybytemap: byte %d\n", i)); + *--mp = i; + /* SUPPRESS 112 *//* Retrieving char where long is stored */ + while (u.c[i] != 0) + u.o <<= 1; + } +} + +/* + - bytemap - transform an of_t from byte ordering map1 to map2 + */ +static of_t /* transformed result */ +bytemap(ino, map1, map2) +of_t ino; +int *map1; +int *map2; +{ + union oc { + of_t o; + char c[SOF]; + }; + union oc in; + union oc out; + register int i; + + in.o = ino; + for (i = 0; i < SOF; i++) + out.c[map2[i]] = in.c[map1[i]]; + return(out.o); +} + +/* + * This is a simplified version of the pathalias hashing function. + * Thanks to Steve Belovin and Peter Honeyman + * + * hash a string into a long int. 31 bit crc (from andrew appel). + * the crc table is computed at run time by crcinit() -- we could + * precompute, but it takes 1 clock tick on a 750. + * + * This fast table calculation works only if POLY is a prime polynomial + * in the field of integers modulo 2. Since the coefficients of a + * 32-bit polynomial won't fit in a 32-bit word, the high-order bit is + * implicit. IT MUST ALSO BE THE CASE that the coefficients of orders + * 31 down to 25 are zero. Happily, we have candidates, from + * E. J. Watson, "Primitive Polynomials (Mod 2)", Math. Comp. 16 (1962): + * x^32 + x^7 + x^5 + x^3 + x^2 + x^1 + x^0 + * x^31 + x^3 + x^0 + * + * We reverse the bits to get: + * 111101010000000000000000000000001 but drop the last 1 + * f 5 0 0 0 0 0 0 + * 010010000000000000000000000000001 ditto, for 31-bit crc + * 4 8 0 0 0 0 0 0 + */ + +#define POLY 0x48000000L /* 31-bit polynomial (avoids sign problems) */ + +static long CrcTable[128]; + +/* + - crcinit - initialize tables for hash function + */ +static void +crcinit() +{ + register int i, j; + register long sum; + + for (i = 0; i < 128; ++i) { + sum = 0L; + for (j = 7 - 1; j >= 0; --j) + if (i & (1 << j)) + sum ^= POLY >> j; + CrcTable[i] = sum; + } + DEBUG(("crcinit: done\n")); +} + +/* + - hash - Honeyman's nice hashing function + */ +static long +hash(name, size) +register char *name; +register int size; +{ + register long sum = 0L; + + while (size--) { + sum = (sum >> 7) ^ CrcTable[(sum ^ (*name++)) & 0x7f]; + } + DEBUG(("hash: returns (%ld)\n", sum)); + return(sum); +} + +/* + * case-mapping stuff + * + * Borrowed from C News, by permission of the authors. Somewhat modified. + * + * We exploit the fact that we are dealing only with headers here, and + * headers are limited to the ASCII characters by RFC822. It is barely + * possible that we might be dealing with a translation into another + * character set, but in particular it's very unlikely for a header + * character to be outside -128..255. + * + * Life would be a whole lot simpler if tolower() could safely and portably + * be applied to any char. + */ + +#define OFFSET 128 /* avoid trouble with negative chars */ + +/* must call casencmp before invoking TOLOW... */ +#define TOLOW(c) (cmap[(c)+OFFSET]) + +/* ...but the use of it in CISTREQN is safe without the preliminary call (!) */ +/* CISTREQN is an optimised case-insensitive strncmp(a,b,n)==0; n > 0 */ +#define CISTREQN(a, b, n) \ + (TOLOW((a)[0]) == TOLOW((b)[0]) && casencmp(a, b, n) == 0) + +#define MAPSIZE (256+OFFSET) +static char cmap[MAPSIZE]; /* relies on init to '\0' */ +static int mprimed = 0; /* has cmap been set up? */ + +/* + - mapprime - set up case-mapping stuff + */ +static void +mapprime() +{ + register char *lp; + register char *up; + register int c; + register int i; + static char lower[] = "abcdefghijklmnopqrstuvwxyz"; + static char upper[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; + + for (lp = lower, up = upper; *lp != '\0'; lp++, up++) { + c = *lp; + cmap[c+OFFSET] = c; + cmap[*up+OFFSET] = c; + } + for (i = 0; i < MAPSIZE; i++) + if (cmap[i] == '\0') + cmap[i] = (char)(i-OFFSET); + mprimed = 1; +} + +/* + - casencmp - case-independent strncmp + */ +static int /* < == > 0 */ +casencmp(s1, s2, len) +char *s1; +char *s2; +int len; +{ + register char *p1; + register char *p2; + register int n; + + if (!mprimed) + mapprime(); + + p1 = s1; + p2 = s2; + n = len; + while (--n >= 0 && *p1 != '\0' && TOLOW(*p1) == TOLOW(*p2)) { + p1++; + p2++; + } + if (n < 0) + return(0); + + /* + * The following case analysis is necessary so that characters + * which look negative collate low against normal characters but + * high against the end-of-string NUL. + */ + if (*p1 == '\0' && *p2 == '\0') + return(0); + else if (*p1 == '\0') + return(-1); + else if (*p2 == '\0') + return(1); + else + return(TOLOW(*p1) - TOLOW(*p2)); +} + +/* + - mapcase - do case-mapped copy + */ +static char * /* returns src or dst */ +mapcase(dst, src, siz) +char *dst; /* destination, used only if mapping needed */ +char *src; /* source; src == dst is legal */ +size_t siz; +{ + register char *s; + register char *d; + register char *c; /* case break */ + register char *e; /* end of source */ + + + c = cipoint(src, siz); + if (c == NULL) + return(src); + + if (!mprimed) + mapprime(); + s = src; + e = s + siz; + d = dst; + + while (s < c) + *d++ = *s++; + while (s < e) + *d++ = TOLOW(*s++); + + return(dst); +} + +/* + - cipoint - where in this message-ID does it become case-insensitive? + * + * The RFC822 code is not quite complete. Absolute, total, full RFC822 + * compliance requires a horrible parsing job, because of the arcane + * quoting conventions -- abc"def"ghi is not equivalent to abc"DEF"ghi, + * for example. There are three or four things that might occur in the + * domain part of a message-id that are case-sensitive. They don't seem + * to ever occur in real news, thank Cthulhu. (What? You were expecting + * a merciful and forgiving deity to be invoked in connection with RFC822? + * Forget it; none of them would come near it.) + */ +static char * /* pointer into s, or NULL for "nowhere" */ +cipoint(s, siz) +char *s; +size_t siz; +{ + register char *p; + static char post[] = "postmaster"; + static int plen = sizeof(post)-1; + + switch (conf.casemap) { + case '0': /* unmapped, sensible */ + return(NULL); + case 'C': /* C News, RFC 822 conformant (approx.) */ + p = memchr((POINTER)s, '@', siz); + if (p == NULL) /* no local/domain split */ + return(NULL); /* assume all local */ + if (p - (s+1) == plen && CISTREQN(s+1, post, plen)) { + /* crazy -- "postmaster" is case-insensitive */ + return(s); + } + return(p); + case '=': /* 2.11, neither sensible nor conformant */ + return(s); /* all case-insensitive */ + } + + DEBUG(("cipoint: unknown case mapping `%c'\n", conf.casemap)); + return(NULL); /* just leave it alone */ +} + +/* + - dbzdebug - control dbz debugging at run time + */ +#ifdef DBZDEBUG +int /* old value */ +dbzdebug(value) +int value; +{ + register int old = debug; + + debug = value; + return(old); +} +#endif diff --git a/pttbbs/innbbsd/dbz.h b/pttbbs/innbbsd/dbz.h new file mode 100644 index 00000000..3d7e8ed7 --- /dev/null +++ b/pttbbs/innbbsd/dbz.h @@ -0,0 +1,32 @@ +/* for dbm and dbz */ +typedef struct { + char *dptr; + int dsize; +} datum; + +/* standard dbm functions */ +extern int dbminit(); +extern datum fetch(); +extern int store(); +extern int delete(); /* not in dbz */ +extern datum firstkey(); /* not in dbz */ +extern datum nextkey(); /* not in dbz */ +extern int dbmclose(); /* in dbz, but not in old dbm */ + +/* new stuff for dbz */ +extern int dbzfresh(); +extern int dbzagain(); +extern datum dbzfetch(); +extern int dbzstore(); +extern int dbzsync(); +extern long dbzsize(); +extern int dbzincore(); +extern int dbzcancel(); +extern int dbzdebug(); + +/* + * In principle we could handle unlimited-length keys by operating a chunk + * at a time, but it's not worth it in practice. Setting a nice large + * bound on them simplifies the code and doesn't hurt anything. + */ +#define DBZMAXKEY 255 diff --git a/pttbbs/innbbsd/dbztool.c b/pttbbs/innbbsd/dbztool.c new file mode 100644 index 00000000..5318721b --- /dev/null +++ b/pttbbs/innbbsd/dbztool.c @@ -0,0 +1,88 @@ +#include +#include "his.h" + +#define DEBUG 1 +#undef DEBUG + +static datum content, inputkey, inputvalue; +static char dboutput[1025]; +static char dbinput[1025]; +static char valueinput[100]; + +enum {SUBJECT, FROM, NAME}; +char *DBfetch(key) +char *key; +{ + int i; + char *tail, *ptr; + if (key == NULL) return NULL; + sprintf(dbinput,"%.510s",key); + inputkey.dptr = dbinput; + inputkey.dsize = strlen(dbinput); + content.dptr = dboutput; + ptr = (char*)HISfilesfor(&inputkey,&content); + if (ptr == NULL) { + return NULL; + } + return ptr; +} + +DBstore(key,paths) +char *key; +char *paths; +{ + int i; + char *tail; + time_t now; + time(&now); + if (key == NULL) return -1; + sprintf(dbinput,"%.510s",key); + inputkey.dptr = dbinput; + inputkey.dsize = strlen(dbinput); + if (HISwrite(&inputkey, now, paths ) == FALSE) { + return -1; + } else { + return 0; + } +} + +int storeDB(mid,paths) +char *mid; +char *paths; +{ + char *key,*ptr; + int rel; + ptr = DBfetch(mid); + if (ptr != NULL) { + return 0; + } else { + return DBstore(mid , paths); + } +} + +my_mkdir (idir,mode) +char *idir; +int mode; +{ + char buffer[LEN]; + char *ptr, *dir = buffer; + struct stat st; + strncpy(dir, idir, LEN - 1); + for (;dir!=NULL && *dir;) { + ptr = (char*)strchr(dir,'/'); + if (ptr != NULL) { + *ptr = '\0'; + } + if (stat(dir,&st) != 0) { + if (mkdir(dir,mode) != 0 ) + return -1; + } + chdir(dir); + if (ptr != NULL) + dir = ptr +1; + else + dir = ptr; + } + return 0; +} + diff --git a/pttbbs/innbbsd/echobbslib.c b/pttbbs/innbbsd/echobbslib.c new file mode 100644 index 00000000..84d77de6 --- /dev/null +++ b/pttbbs/innbbsd/echobbslib.c @@ -0,0 +1,713 @@ +#if defined( LINUX ) +# include "innbbsconf.h" +# include "bbslib.h" +# include +#else +# include +# include "innbbsconf.h" +# include "bbslib.h" +#endif + +char INNBBSCONF[MAXPATHLEN]; +char INNDHOME[MAXPATHLEN]; +char HISTORY[MAXPATHLEN]; +char LOGFILE[MAXPATHLEN]; +char MYBBSID[MAXPATHLEN]; +char ECHOMAIL[MAXPATHLEN]; +char BBSFEEDS[MAXPATHLEN]; +char LOCALDAEMON[MAXPATHLEN]; + +int His_Maint_Min= HIS_MAINT_MIN; +int His_Maint_Hour= HIS_MAINT_HOUR; +int Expiredays = EXPIREDAYS; + +nodelist_t *NODELIST=NULL, **NODELIST_BYNODE=NULL; +newsfeeds_t *NEWSFEEDS=NULL, **NEWSFEEDS_BYBOARD=NULL; +static char *NODELIST_BUF, *NEWSFEEDS_BUF; +int NFCOUNT, NLCOUNT; +int LOCALNODELIST=0, NONENEWSFEEDS=0; + +#ifndef _PATH_BBSHOME +# define _PATH_BBSHOME "/u/staff/bbsroot/csie_util/bntpd/home" +#endif + +static FILE *bbslogfp; + +static int +verboseFlag=0; + +static char* +verboseFilename=NULL; +static char verbosename[MAXPATHLEN]; + +verboseon(filename) +char *filename; +{ + verboseFlag = 1; + if ( filename != NULL ) { + if (strchr(filename,'/') == NULL) { + sprintf(verbosename,"%s/innd/%s",BBSHOME,filename); + filename = verbosename; + } + } + verboseFilename = filename; +} +verboseoff() +{ + verboseFlag = 0; +} + +setverboseon() +{ + verboseFlag = 1; +} + +isverboselog() +{ + return verboseFlag; +} + +setverboseoff() +{ + verboseoff(); + if (bbslogfp != NULL) { + fclose(bbslogfp); + bbslogfp = NULL; + } +} + +verboselog(va_alist) +va_dcl +{ + va_list ap; + register char* fmt; + char datebuf[40]; + time_t now; + + if (verboseFlag == 0) return; + + va_start(ap); + + time(&now); + strftime(datebuf, sizeof(datebuf), "%b %d %X ", localtime(&now)); + + if (bbslogfp == NULL) { + if (verboseFilename != NULL) + bbslogfp = fopen(verboseFilename, "a"); + else + bbslogfp = fdopen(1, "a"); + } + if (bbslogfp == NULL) { va_end(ap); return; } + fmt = va_arg(ap, char *) ; + fprintf(bbslogfp,"%s[%d] ",datebuf, getpid()); + vfprintf(bbslogfp, fmt, ap); + fflush(bbslogfp); + va_end(ap); +} + +#ifdef PalmBBS +xbbslog(va_alist) +#else +bbslog(va_alist) +#endif +va_dcl +{ + va_list ap; + register char* fmt; + char datebuf[40]; + time_t now; + + va_start(ap); + + time(&now); + strftime(datebuf, sizeof(datebuf), "%b %d %X ", localtime(&now)); + + if (bbslogfp == NULL) { + bbslogfp = fopen(LOGFILE, "a"); + } + if (bbslogfp == NULL) { va_end(ap); return; } + fmt = va_arg(ap, char *) ; + fprintf(bbslogfp,"%s[%d] ",datebuf,getpid()); + vfprintf(bbslogfp, fmt, ap); + fflush(bbslogfp); + va_end(ap); +} + +initial_bbs(outgoing) +char *outgoing; +{ + FILE* FN; + struct stat st; + int fd, i; + char *bbsnameptr=NULL; + +/* reopen bbslog */ + if (bbslogfp != NULL) { + fclose(bbslogfp); + bbslogfp = NULL; + } + +#ifdef WITH_ECHOMAIL + init_echomailfp(); + init_bbsfeedsfp(); +#endif + + LOCALNODELIST=0, NONENEWSFEEDS =0; + sprintf(INNDHOME,"%s/innd",BBSHOME); + sprintf(HISTORY, "%s/history",INNDHOME); + sprintf(LOGFILE, "%s/bbslog",INNDHOME); + sprintf(ECHOMAIL,"%s/echomail.log",BBSHOME); + sprintf(LOCALDAEMON,"%s/.innbbsd",INNDHOME); + sprintf(INNBBSCONF,"%s/innbbs.conf",INNDHOME); + sprintf(BBSFEEDS,"%s/bbsfeeds.log",INNDHOME); + + if (isfile(INNBBSCONF)) { + FILE *conf; + char buffer[MAXPATHLEN]; + conf = fopen(INNBBSCONF,"r"); + if (conf != NULL) { + while (fgets( buffer, sizeof buffer, conf) != NULL) { + char *ptr, *front=NULL, *value=NULL, *value2=NULL, *value3=NULL; + if ( buffer[0] == '#' || buffer[0] == '\n') continue; + for ( front = buffer; *front && isspace(*front); front++); + for ( ptr = front; *ptr && !isspace(*ptr) ; ptr++) ; + if (*ptr == '\0') continue; + *ptr++ = '\0'; + for ( ; *ptr && isspace(*ptr) ; ptr++) ; + if (*ptr == '\0') continue; + value = ptr++; + for ( ; *ptr && !isspace(*ptr) ; ptr++) ; + if (*ptr) { + *ptr++ = '\0'; + for ( ; *ptr && isspace(*ptr) ; ptr++) ; + value2 = ptr++; + for ( ; *ptr && !isspace(*ptr) ; ptr++) ; + if (*ptr) { + *ptr++ = '\0'; + for ( ; *ptr && isspace(*ptr) ; ptr++) ; + value3 = ptr++; + for ( ; *ptr && !isspace(*ptr) ; ptr++) ; + if (*ptr) { + *ptr++ = '\0'; + } + } + } + if ( strcasecmp(front,"expiredays") == 0) { + Expiredays = atoi(value); + if (Expiredays < 0) { + Expiredays = EXPIREDAYS; + } + } else if ( strcasecmp(front,"expiretime") == 0) { + ptr = strchr(value,':'); + if (ptr == NULL) { + fprintf(stderr, "Syntax error in innbbs.conf\n"); + } else { + *ptr++ = '\0'; + His_Maint_Hour = atoi(value); + His_Maint_Min = atoi(ptr); + if (His_Maint_Hour < 0) + His_Maint_Hour = HIS_MAINT_HOUR; + if (His_Maint_Min < 0) + His_Maint_Min = HIS_MAINT_MIN; + } + } else if ( strcasecmp(front,"newsfeeds") == 0) { + if (strcmp(value,"none")==0) + NONENEWSFEEDS = 1; + } else if ( strcasecmp(front,"nodelist") == 0) { + if (strcmp(value,"local")==0) + LOCALNODELIST = 1; + } /*else if ( strcasecmp(front,"newsfeeds") == 0) { + printf("newsfeeds %s\n", value); + } else if ( strcasecmp(front,"nodelist") == 0) { + printf("nodelist %s\n", value); + } else if ( strcasecmp(front,"bbsname") == 0) { + printf("bbsname %s\n", value); + } */ + } + fclose(conf); + } + } + +#ifdef WITH_ECHOMAIL + bbsnameptr = (char*) fileglue("%s/bbsname.bbs",INNDHOME); + if ((FN = fopen( bbsnameptr ,"r" ))==NULL) { + fprintf(stderr,"can't open file %s\n", bbsnameptr); + return 0; + } + while ( fscanf(FN,"%s", MYBBSID) != EOF); + fclose(FN); + if( ! isdir(fileglue("%s/out.going",BBSHOME)) ) { + mkdir( (char*)fileglue("%s/out.going",BBSHOME), 0750 ); + } + if (NONENEWSFEEDS == 0) + readnffile(INNDHOME); + if (LOCALNODELIST == 0) { + if (readnlfile(INNDHOME, outgoing) != 0) return 0; + } + +#endif + return 1; +} + +static int +nf_byboardcmp(a,b) +newsfeeds_t **a, **b; +{ +/* + if (!a || !*a || !(*a)->board) return -1; + if (!b || !*b || !(*b)->board) return 1; +*/ + return strcasecmp((*a)->board, (*b)->board); +} + +static int +nfcmp(a,b) +newsfeeds_t *a, *b; +{ +/* + if (!a || !a->newsgroups) return -1; + if (!b || !b->newsgroups) return 1; +*/ + return strcasecmp(a->newsgroups, b->newsgroups); +} + +static int +nlcmp(a,b) +nodelist_t *a, *b; +{ +/* + if (!a || !a->host) return -1; + if (!b || !b->host) return 1; +*/ + return strcasecmp(a->host, b->host); +} + +static int +nl_bynodecmp(a,b) +nodelist_t **a, **b; +{ +/* + if (!a || !*a || !(*a)->node) return -1; + if (!b || !*b || !(*b)->node) return 1; +*/ + return strcasecmp((*a)->node, (*b)->node); +} + +/* read in newsfeeds.bbs and nodelist.bbs */ +readnlfile(inndhome, outgoing) +char *inndhome; +char *outgoing; +{ + FILE *fp; + char buff[1024]; + struct stat st; + int i, count, j; + char *ptr, *nodelistptr; + static lastcount=0; + + sprintf(buff,"%s/nodelist.bbs", inndhome); + fp = fopen(buff,"r"); + if (fp == NULL) { + fprintf(stderr,"open fail %s",buff); + return -1; + } + if (fstat(fileno(fp),&st) != 0) { + fprintf(stderr,"stat fail %s", buff); + return -1; + } + if (NODELIST_BUF == NULL) { + NODELIST_BUF = (char*) mymalloc( st.st_size +1); + } else { + NODELIST_BUF = (char*) myrealloc( NODELIST_BUF, st.st_size +1); + } + i = 0, count =0; + while (fgets(buff, sizeof buff, fp) != NULL) { + if (buff[0] == '#') continue; + if (buff[0] == '\n') continue; + strcpy(NODELIST_BUF+i, buff); + i += strlen(buff); + count ++; + } + fclose(fp); + if (NODELIST == NULL) { + NODELIST = (nodelist_t*) mymalloc(sizeof(nodelist_t) * (count+1)); + NODELIST_BYNODE = (nodelist_t**) mymalloc(sizeof(nodelist_t*) * (count+1)); + } else { + NODELIST = (nodelist_t*) myrealloc(NODELIST, sizeof(nodelist_t) * (count+1)); + NODELIST_BYNODE = (nodelist_t**) myrealloc(NODELIST_BYNODE, sizeof(nodelist_t*) * (count+1)); + } + for (i=lastcount; i< count; i++) { + NODELIST[i].feedfp = NULL; + } + lastcount = count; + NLCOUNT = 0; + for (ptr = NODELIST_BUF; (nodelistptr = (char*)strchr(ptr,'\n')) != NULL; ptr = nodelistptr +1, NLCOUNT++) { + char *nptr , *bptr, *pptr, *tptr; + *nodelistptr = '\0'; + NODELIST[NLCOUNT].host = ""; + NODELIST[NLCOUNT].exclusion = ""; + NODELIST[NLCOUNT].node = ""; + NODELIST[NLCOUNT].protocol = "IHAVE(119)"; + NODELIST[NLCOUNT].comments = ""; + NODELIST_BYNODE[NLCOUNT] = NODELIST+NLCOUNT; + for (nptr= ptr ;*nptr && isspace(*nptr); ) nptr++; + if (*nptr == '\0') { + bbslog("nodelist.bbs %d entry read error\n", NLCOUNT); + return -1; + } + /*NODELIST[NLCOUNT].id = nptr;*/ + NODELIST[NLCOUNT].node = nptr; + for (nptr++; *nptr && !isspace(*nptr); ) nptr++; + if (*nptr == '\0') { + bbslog("nodelist.bbs node %d entry read error\n", NLCOUNT); + return -1; + } + *nptr = '\0'; + if ((tptr = strchr(NODELIST[NLCOUNT].node,'/'))) { + *tptr = '\0'; + NODELIST[NLCOUNT].exclusion = tptr + 1; + } else { + NODELIST[NLCOUNT].exclusion = ""; + } + for (nptr++ ;*nptr && isspace(*nptr); ) nptr++; + if (*nptr == '\0') continue; + if (*nptr=='+' || *nptr=='-') { + NODELIST[NLCOUNT].feedtype = *nptr; + if (NODELIST[NLCOUNT].feedfp != NULL) { + fclose(NODELIST[NLCOUNT].feedfp); + } + if ( NODELIST[NLCOUNT].feedtype == '+') + if (outgoing != NULL) { + NODELIST[NLCOUNT].feedfp = fopen((char*)fileglue("%s/out.going/%s.%s",BBSHOME, NODELIST[NLCOUNT].node, outgoing),"a"); + } + nptr++; + } else { + NODELIST[NLCOUNT].feedtype = ' '; + } + NODELIST[NLCOUNT].host = nptr; + for (nptr++; *nptr && !isspace(*nptr); ) nptr++; + if (*nptr == '\0') { + continue; + } + *nptr = '\0'; + for (nptr++;*nptr && isspace(*nptr); ) nptr++; + if (*nptr == '\0') continue; + NODELIST[NLCOUNT].protocol = nptr; + for (nptr++; *nptr && !isspace(*nptr); ) nptr++; + if (*nptr == '\0') continue; + *nptr = '\0'; + for (nptr++;*nptr && strchr(" \t\r\n",*nptr); ) nptr++; + if (*nptr == '\0') continue; + NODELIST[NLCOUNT].comments = nptr; + } + qsort(NODELIST, NLCOUNT, sizeof(nodelist_t), nlcmp); + qsort(NODELIST_BYNODE, NLCOUNT, sizeof(nodelist_t*), nl_bynodecmp); + return 0; +} + +readnffile(inndhome) +char *inndhome; +{ + FILE *fp; + char buff[1024]; + struct stat st; + int i, count; + char *ptr, *newsfeedsptr; + + sprintf(buff,"%s/newsfeeds.bbs", inndhome); + fp = fopen(buff,"r"); + if (fp == NULL) { + fprintf(stderr,"open fail %s",buff); + return -1; + } + if (fstat(fileno(fp),&st) != 0) { + fprintf(stderr,"stat fail %s", buff); + return -1; + } + if (NEWSFEEDS_BUF == NULL) { + NEWSFEEDS_BUF = (char*) mymalloc( st.st_size +1); + } else { + NEWSFEEDS_BUF = (char*) myrealloc( NEWSFEEDS_BUF, st.st_size +1); + } + i = 0, count =0; + while (fgets(buff, sizeof buff, fp) != NULL) { + if (buff[0] == '#') continue; + if (buff[0] == '\n') continue; + strcpy(NEWSFEEDS_BUF+i, buff); + i += strlen(buff); + count ++; + } + fclose(fp); + if (NEWSFEEDS == NULL) { + NEWSFEEDS = (newsfeeds_t*) mymalloc(sizeof(newsfeeds_t) * (count+1)); + NEWSFEEDS_BYBOARD = (newsfeeds_t**) mymalloc(sizeof(newsfeeds_t*) * (count+1)); + } else { + NEWSFEEDS = (newsfeeds_t*) myrealloc(NEWSFEEDS, sizeof(newsfeeds_t) * (count+1)); + NEWSFEEDS_BYBOARD = (newsfeeds_t**) myrealloc(NEWSFEEDS_BYBOARD, sizeof(newsfeeds_t*) * (count+1)); + } + NFCOUNT = 0; + for (ptr = NEWSFEEDS_BUF; (newsfeedsptr = (char*)strchr(ptr,'\n')) != NULL; ptr = newsfeedsptr +1, NFCOUNT++) { + char *nptr , *bptr, *pptr; + *newsfeedsptr = '\0'; + NEWSFEEDS[NFCOUNT].newsgroups = ""; + NEWSFEEDS[NFCOUNT].board = ""; + NEWSFEEDS[NFCOUNT].path = NULL; + NEWSFEEDS_BYBOARD[NFCOUNT] = NEWSFEEDS+NFCOUNT; + for (nptr= ptr ;*nptr && isspace(*nptr); ) nptr++; + if (*nptr == '\0') continue; + NEWSFEEDS[NFCOUNT].newsgroups = nptr; + for (nptr++; *nptr && !isspace(*nptr); ) nptr++; + if (*nptr == '\0') continue; + *nptr = '\0'; + for (nptr++ ;*nptr && isspace(*nptr); ) nptr++; + if (*nptr == '\0') continue; + NEWSFEEDS[NFCOUNT].board = nptr; + for (nptr++; *nptr && !isspace(*nptr); ) nptr++; + if (*nptr == '\0') continue; + *nptr = '\0'; + for (nptr++;*nptr && isspace(*nptr); ) nptr++; + if (*nptr == '\0') continue; + NEWSFEEDS[NFCOUNT].path = nptr; + for (nptr++; *nptr && !strchr("\r\n",*nptr); ) nptr++; + /*if (*nptr == '\0') continue;*/ + *nptr = '\0'; + } + qsort(NEWSFEEDS, NFCOUNT, sizeof(newsfeeds_t), nfcmp); + qsort(NEWSFEEDS_BYBOARD, NFCOUNT, sizeof(newsfeeds_t*), nf_byboardcmp); +} + +newsfeeds_t *search_board(board) +char *board; +{ + newsfeeds_t nft, *nftptr, **find; + if (NONENEWSFEEDS) return NULL; + nft.board = board; + nftptr = &nft; + find = (newsfeeds_t**)bsearch((char*)&nftptr, NEWSFEEDS_BYBOARD, NFCOUNT, sizeof(newsfeeds_t*), nf_byboardcmp); + if (find != NULL) return *find; + return NULL; +} + +nodelist_t *search_nodelist_bynode(node) +char *node; +{ + nodelist_t nlt, *nltptr, **find; + if (LOCALNODELIST) return NULL; + nlt.node = node; + nltptr = ≮ + find = (nodelist_t**)bsearch((char*)&nltptr, NODELIST_BYNODE, NLCOUNT, sizeof(nodelist_t*), nl_bynodecmp); + if (find != NULL) return *find; + return NULL; +} + + +nodelist_t *search_nodelist(site, identuser) +char *site; +char *identuser; +{ + nodelist_t nlt, *find; + char buffer[1024]; + if (LOCALNODELIST) return NULL; + nlt.host = site; + find = (nodelist_t*)bsearch((char*)&nlt, NODELIST, NLCOUNT, sizeof(nodelist_t), nlcmp); + if (find == NULL && identuser != NULL) { + sprintf(buffer,"%s@%s", identuser, site); + nlt.host = buffer; + find = (nodelist_t*)bsearch((char*)&nlt, NODELIST, NLCOUNT, sizeof(nodelist_t), nlcmp); + } + return find; +} + +newsfeeds_t *search_group(newsgroup) +char *newsgroup; +{ + newsfeeds_t nft, *find; + if (NONENEWSFEEDS) return NULL; + nft.newsgroups = newsgroup; + find = (newsfeeds_t*)bsearch((char*)&nft, NEWSFEEDS, NFCOUNT, sizeof(newsfeeds_t), nfcmp); + return find; +} + +char *ascii_date(now) +time_t now; +{ + static char datebuf[40]; + /*time_t now; + time(&now);*/ + strftime(datebuf, sizeof(datebuf), "%d %b %Y %X GMT", gmtime(&now)); + return datebuf; +} + +char * +restrdup(ptr, string) +char *ptr; +char *string; +{ + int len ; + if (string == NULL) { + if (ptr != NULL) *ptr = '\0'; + return ptr; + } + len = strlen(string) + 1; + if (ptr != NULL) { + ptr = (char*)myrealloc(ptr, len); + } else + ptr = (char*)mymalloc(len); + strcpy(ptr, string); + return ptr; +} + + + +void * +mymalloc(size) +int size; +{ + char *ptr = (char*)malloc(size); + if (ptr == NULL) { + fprintf(stderr, "cant allocate memory\n"); + syslog(LOG_ERR, "cant allocate memory %m"); + exit(1); + } + return ptr; +} + +void * +myrealloc(optr, size) +void *optr; +int size; +{ + char *ptr = (char*)realloc(optr, size); + if (ptr == NULL) { + fprintf(stderr, "cant allocate memory\n"); + syslog(LOG_ERR, "cant allocate memory %m"); + exit(1); + } + return ptr; +} + +testandmkdir(dir) +char *dir; +{ + if (!isdir(dir)) { + char path[MAXPATHLEN+12]; + sprintf(path,"mkdir -p %s",dir); + system(path); + } +} + +static char splitbuf[2048]; +static char joinbuf[1024]; +#define MAXTOK 50 +static char* Splitptr[MAXTOK]; +char **split(line,pat) +char *line,*pat; +{ + char *p; + int i; + + for (i=0;iboard,nf2->board)==0) { + *ptr[j] = '\0'; + continue; + } + for (n11 = nf1->board, n12 = (char*)strchr(n11,','); + n11 && *n11 ; n12 = (char*) strchr(n11,',')) { + if (n12) *n12 = '\0'; + for (n21 = nf2->board, n22 = (char*)strchr(n21,','); + n21 && *n21 ; n22 = (char*) strchr(n21,',')) { + if (n22) *n22 = '\0'; + if (strcmp(n11,n21)==0) { + *n21 = '\t'; + } + if (n22) { + *n22 = ','; + n21 = n22 + 1; + } else + break; + } + if (n12) { + *n12 = ','; + n11 = n12 +1; + } else + break; + } + } + } + } + return ptr; +} + +char **ssplit(line,pat) +char *line,*pat; +{ + char *p; + int i; + for (i=0;i +#include +#include +#include +#define MAXARGS 100 + +/* isfile is called by + * isfile(filenamecomp1, filecomp2, filecomp3, ..., (char *)0); + * extern "C" int isfile(const char *, const char *[]) ; +*/ + + +char FILEBUF[4096]; + + +static char DOLLAR_[8192]; +char *getstream(fp) +FILE *fp; +{ + return fgets(DOLLAR_, sizeof(DOLLAR_) -1 , fp); +} + +/* + The same as sprintf, but return the new string + fileglue("%s/%s",home,".newsrc"); +*/ + +char *fileglue(va_alist) +va_dcl +{ + va_list ap; + register char* fmt; + static char *newstring; + static char gluebuffer[8192]; + + va_start(ap); + fmt = va_arg(ap, char *) ; + vsprintf(gluebuffer, fmt, ap); + newstring = gluebuffer; + va_end(ap); + return newstring; +} + +long +filesize(filename) +char* filename; +{ + struct stat st; + + if (stat(filename,&st)) return 0; + return st.st_size; +} + +int iszerofile(filename) +char* filename; +{ + struct stat st; + + if (stat(filename,&st)) return 0; + if (st.st_size == 0) return 1; + return 0; +} + +int isfile(filename) +char* filename; +{ + struct stat st; + + if (stat(filename,&st)) return 0; + if (!S_ISREG(st.st_mode)) return 0; + return 1; +} + +int isfilev(va_alist) +va_dcl +{ + va_list ap; + struct stat st; + char *p; + va_start(ap); + + FILEBUF[0]='\0'; + while ((p = va_arg(ap, char *)) != (char *)0) { + strcat(FILEBUF,p); + } + printf("file %s\n",FILEBUF); + + va_end(ap); + return isfile(FILEBUF); +} + + +int isdir(filename) +char* filename; +{ + struct stat st; + + if (stat(filename,&st)) return 0; + if (!S_ISDIR(st.st_mode)) return 0; + return 1; +} + +int isdirv(va_alist) +va_dcl +{ + va_list ap; + struct stat st; + char *p; + va_start(ap); + + FILEBUF[0]='\0'; + while ((p = va_arg(ap, char *)) != (char *)0) { + strcat(FILEBUF,p); + } + + va_end(ap); + return isdir(FILEBUF); +} + +unsigned long mtime(filename) +char* filename; +{ + struct stat st; + if (stat(filename,&st)) return 0; + return st.st_mtime; +} + +unsigned long mtimev(va_alist) +va_dcl +{ + va_list ap; + struct stat st; + char *p; + va_start(ap); + + FILEBUF[0]='\0'; + while ((p = va_arg(ap, char *)) != (char *)0) { + strcat(FILEBUF,p); + } + + va_end(ap); + return mtime(FILEBUF); +} + +unsigned long atime(filename) +char *filename; +{ + struct stat st; + if (stat(filename,&st)) return 0; + return st.st_atime; +} + +unsigned long atimev(va_alist) +va_dcl +{ + va_list ap; + struct stat st; + char *p; + va_start(ap); + + FILEBUF[0]='\0'; + while ((p = va_arg(ap, char *)) != (char *)0) { + strcat(FILEBUF,p); + } + + va_end(ap); + return atime(FILEBUF); +} + +/*#undef TEST*/ +#ifdef TEST +main(argc,argv) +int argc; +char **argv; +{ + int i; + if (argc > 3) { + if (isfilev(argv[1],argv[2],(char*)0)) printf("%s %s %s is file\n",argv[1],argv[2],argv[3]); + if (isdirv(argv[1],argv[2],(char*)0)) printf("%s %s %s is dir\n",argv[1],argv[2],argv[3]); + printf("mtime %d\n",mtimev(argv[1],argv[2],(char*)0)); + printf("atime %d\n",atimev(argv[1],argv[2],(char*)0)); + } + printf("fileglue %s\n", fileglue("%s/%s","home",".test")); +} +#endif diff --git a/pttbbs/innbbsd/his.c b/pttbbs/innbbsd/his.c new file mode 100644 index 00000000..7fe48dc3 --- /dev/null +++ b/pttbbs/innbbsd/his.c @@ -0,0 +1,474 @@ +/* $Revision: 1.1 $ +** +** History file routines. +*/ +#include "innbbsconf.h" +#include "bbslib.h" +#include "his.h" + +#define STATIC static +/*STATIC char HIShistpath[] = _PATH_HISTORY;*/ +STATIC FILE *HISwritefp; +STATIC int HISreadfd; +STATIC int HISdirty; +STATIC int HISincore = XINDEX_DBZINCORE; +STATIC char *LogName = "xindexchan"; + +#ifndef EXPIREDAYS +# define EXPIREDAYS 4 +#endif + +#ifndef DEFAULT_HIST_SIZE +# define DEFAULT_HIST_SIZE 100000 +#endif + +hisincore(flag) +int flag; +{ + HISincore = flag; +} + +makedbz(histpath, entry) +char *histpath; +long entry; +{ + long size; + size = dbzsize(entry); + dbzfresh(histpath,size,'\t',0, 1); + dbmclose(); +} + +void HISsetup(); +void HISclose(); + +void +mkhistory(srchist) +char *srchist; +{ + FILE *hismaint ; + time_t lasthist, now; + char maintbuff[256]; + char *ptr; + hismaint= fopen(srchist, "r"); + if (hismaint == NULL) { + return; + } + { + char newhistpath[1024]; + char newhistdirpath[1024]; + char newhistpagpath[1024]; + sprintf(newhistpath,"%s.n",srchist); + sprintf(newhistdirpath,"%s.n.dir",srchist); + sprintf(newhistpagpath,"%s.n.pag",srchist); + if (!isfile(newhistdirpath) || !isfile(newhistpagpath)) { + makedbz(newhistpath, DEFAULT_HIST_SIZE); + } + myHISsetup(newhistpath); + while ( fgets(maintbuff, sizeof(maintbuff), hismaint) != NULL) { + datum key; + ptr = (char*) strchr(maintbuff,'\t'); + if (ptr != NULL) { *ptr = '\0'; ptr++;} + key.dptr = maintbuff; + key.dsize = strlen(maintbuff); + myHISwrite(&key, ptr); + } + (void) HISclose(); + /*rename(newhistpath, srchist); + rename(newhistdirpath, fileglue("%s.dir", srchist)); + rename(newhistpagpath, fileglue("%s.pag", srchist));*/ + } + fclose(hismaint); +} + +time_t +gethisinfo() +{ + FILE *hismaint ; + time_t lasthist, now; + char maintbuff[4096]; + char *ptr; + hismaint= fopen(HISTORY, "r"); + if (hismaint == NULL) { + return 0; + } + fgets(maintbuff,sizeof(maintbuff), hismaint); + fclose(hismaint); + ptr = (char*)strchr(maintbuff,'\t'); + if (ptr != NULL) { + ptr++; + lasthist = atol(ptr); + return lasthist; + } + return 0; +} + +void +HISmaint() +{ + FILE *hismaint ; + time_t lasthist, now; + char maintbuff[4096]; + char *ptr; + + if (!isfile(HISTORY)) { + makedbz(HISTORY, DEFAULT_HIST_SIZE); + } + hismaint= fopen(HISTORY, "r"); + if (hismaint == NULL) { + return; + } + fgets(maintbuff,sizeof(maintbuff), hismaint); + ptr = (char*)strchr(maintbuff,'\t'); + if (ptr != NULL) { + ptr++; + lasthist = atol(ptr); + time(&now); + if ( lasthist + 86400 * Expiredays * 2 < now ) { + char newhistpath[1024]; + char newhistdirpath[1024]; + char newhistpagpath[1024]; + (void) HISclose(); + sprintf(newhistpath,"%s.n",HISTORY); + sprintf(newhistdirpath,"%s.n.dir",HISTORY); + sprintf(newhistpagpath,"%s.n.pag",HISTORY); + if (!isfile(newhistdirpath)) { + makedbz(newhistpath, DEFAULT_HIST_SIZE); + } + myHISsetup(newhistpath); + while ( fgets(maintbuff, sizeof(maintbuff), hismaint) != NULL) { + datum key; + ptr = (char*) strchr(maintbuff,'\t'); + if (ptr != NULL) { + *ptr = '\0'; ptr++; + lasthist = atol(ptr); + } else { + continue ; + } + if ( lasthist + 99600 * Expiredays < now ) continue; + key.dptr = maintbuff; + key.dsize = strlen(maintbuff); + myHISwrite(&key, ptr); + } + (void) HISclose(); + rename(HISTORY, (char*)fileglue("%s.o",HISTORY)); + rename(newhistpath, HISTORY); + rename(newhistdirpath, (char*)fileglue("%s.dir", HISTORY)); + rename(newhistpagpath, (char*)fileglue("%s.pag", HISTORY)); + (void) HISsetup(); + } + } + fclose(hismaint); +} + + +/* +** Set up the history files. +*/ +void +HISsetup() +{ + myHISsetup(HISTORY); +} + +int +myHISsetup(histpath) +char *histpath; +{ + if (HISwritefp == NULL) { + /* Open the history file for appending formatted I/O. */ + if ((HISwritefp = fopen(histpath, "a")) == NULL) { + syslog(LOG_CRIT, "%s cant fopen %s %m", LogName, histpath); + exit(1); + } + CloseOnExec((int)fileno(HISwritefp), TRUE); + + /* Open the history file for reading. */ + if ((HISreadfd = open(histpath, O_RDONLY)) < 0) { + syslog(LOG_CRIT, "%s cant open %s %m", LogName, histpath); + exit(1); + } + CloseOnExec(HISreadfd, TRUE); + + /* Open the DBZ file. */ + /*(void)dbzincore(HISincore);*/ + (void)dbzincore(HISincore); + (void)dbzwritethrough(1); + if (dbminit(histpath) < 0) { + syslog(LOG_CRIT, "%s cant dbminit %s %m", histpath, LogName); + exit(1); + } + } +} + + +/* +** Synchronize the in-core history file (flush it). +*/ +void +HISsync() +{ + if (HISdirty) { + if (dbzsync()) { + syslog(LOG_CRIT, "%s cant dbzsync %m", LogName); + exit(1); + } + HISdirty = 0; + } +} + + +/* +** Close the history files. +*/ +void +HISclose() +{ + if (HISwritefp != NULL) { + /* Since dbmclose calls dbzsync we could replace this line with + * "HISdirty = 0;". Oh well, it keeps the abstraction clean. */ + HISsync(); + if (dbmclose() < 0) + syslog(LOG_ERR, "%s cant dbmclose %m", LogName); + if (fclose(HISwritefp) == EOF) + syslog(LOG_ERR, "%s cant fclose history %m", LogName); + HISwritefp = NULL; + if (close(HISreadfd) < 0) + syslog(LOG_ERR, "%s cant close history %m", LogName); + HISreadfd = -1; + } +} + + +#ifdef HISset +/* +** File in the DBZ datum for a Message-ID, making sure not to copy any +** illegal characters. +*/ +STATIC void +HISsetkey(p, keyp) + register char *p; + datum *keyp; +{ + static BUFFER MessageID; + register char *dest; + register int i; + + /* Get space to hold the ID. */ + i = strlen(p); + if (MessageID.Data == NULL) { + MessageID.Data = NEW(char, i + 1); + MessageID.Size = i; + } + else if (MessageID.Size < i) { + RENEW(MessageID.Data, char, i + 1); + MessageID.Size = i; + } + + for (keyp->dptr = dest = MessageID.Data; *p; p++) + if (*p == HIS_FIELDSEP || *p == '\n') + *dest++ = HIS_BADCHAR; + else + *dest++ = *p; + *dest = '\0'; + + keyp->dsize = dest - MessageID.Data + 1; +} + +#endif +/* +** Get the list of files under which a Message-ID is stored. +*/ +char * +HISfilesfor(key,output) + datum *key; + datum *output; +{ + char *dest; + datum val; + long offset; + register char *p; + register int i; + int Used; + + /* Get the seek value into the history file. */ + val = dbzfetch(*key); + if (val.dptr == NULL || val.dsize != sizeof offset){ + /*printf("fail here val.dptr %d\n",val.dptr);*/ + return NULL; + } + + /* Get space. */ + if (output->dptr == NULL) { + printf("fail here output->dptr null\n"); + return NULL; + } + + /* Copy the value to an aligned spot. */ + for (p = val.dptr, dest = (char *)&offset, i = sizeof offset; --i >= 0; ) + *dest++ = *p++; + if (lseek(HISreadfd, offset, SEEK_SET) == -1) { + printf("fail here lseek %d\n",offset); + return NULL; + } + + /* Read the text until \n or EOF. */ + for (output->dsize = 0,Used=0; ; ) { + i = read(HISreadfd, + &output->dptr[output->dsize], LEN - 1); + if (i <= 0) { + printf("fail here i %d\n",i); + return NULL; + } + Used += i; + output->dptr[Used] = '\0'; + if ((p = (char*)strchr(output->dptr, '\n')) != NULL) { + *p = '\0'; + break; + } + } + + /* Move past the first two fields -- Message-ID and date info. */ + if ((p = (char*)strchr(output->dptr, HIS_FIELDSEP)) == NULL) { + printf("fail here no HIS_FILE\n"); + return NULL; + } + return p+1; + /*if ((p = (char*)strchr(p + 1, HIS_FIELDSEP)) == NULL) + return NULL;*/ + + /* Translate newsgroup separators to slashes, return the fieldstart. */ +} + +/* +** Have we already seen an article? +*/ +#ifdef HISh +BOOL +HIShavearticle(MessageID) + char *MessageID; +{ + datum key; + datum val; + + HISsetkey(MessageID, &key); + val = dbzfetch(key); + return val.dptr != NULL; +} +#endif + + +/* +** Turn a history filename entry from slashes to dots. It's a pity +** we have to do this. +*/ +STATIC void +HISslashify(p) + register char *p; +{ + register char *last; + + for (last = NULL; *p; p++) { + if (*p == '/') { + *p = '.'; + last = p; + } + else if (*p == ' ' && last != NULL) + *last = '/'; + } + if (last) + *last = '/'; +} + + +IOError(error) +char *error; +{ + fprintf(stderr,"%s\n",error); +} + +/*BOOL*/ +myHISwrite(key, remain) + datum *key; + char *remain; +{ + static char NOPATHS[] = ""; + long offset; + datum val; + int i; + + val = dbzfetch(*key); + if (val.dptr != NULL){ + return FALSE; + } + + flock(fileno(HISwritefp),LOCK_EX); + offset = ftell(HISwritefp); + i = fprintf(HISwritefp, "%s%c%s", + key->dptr, HIS_FIELDSEP, remain); + if (i == EOF || fflush(HISwritefp) == EOF) { + /* The history line is now an orphan... */ + IOError("history"); + syslog(LOG_ERR, "%s cant write history %m", LogName); + flock(fileno(HISwritefp),LOCK_UN); + return FALSE; + } + + /* Set up the database values and write them. */ + val.dptr = (char *)&offset; + val.dsize = sizeof offset; + if (dbzstore(*key, val) < 0) { + IOError("my history database"); + syslog(LOG_ERR, "%s cant dbzstore %m", LogName); + flock(fileno(HISwritefp),LOCK_UN); + return FALSE; + } + + if (++HISdirty >= ICD_SYNC_COUNT) + HISsync(); + flock(fileno(HISwritefp),LOCK_UN); + return TRUE; +} + + +/* +** Write a history entry. +*/ +BOOL +HISwrite(key, date, paths) + datum *key; + char *paths; + long date; +{ + static char NOPATHS[] = ""; + long offset; + datum val; + int i; + + flock(fileno(HISwritefp),LOCK_EX); + offset = ftell(HISwritefp); + i = fprintf(HISwritefp, "%s%c%ld%c%s\n", + key->dptr, HIS_FIELDSEP, (long)date, HIS_FIELDSEP, + paths); + if (i == EOF || fflush(HISwritefp) == EOF) { + /* The history line is now an orphan... */ + IOError("history"); + syslog(LOG_ERR, "%s cant write history %m", LogName); + flock(fileno(HISwritefp),LOCK_UN); + return FALSE; + } + + /* Set up the database values and write them. */ + val.dptr = (char *)&offset; + val.dsize = sizeof offset; + if (dbzstore(*key, val) < 0) { + IOError("history database"); + syslog(LOG_ERR, "%s cant dbzstore %m", LogName); + flock(fileno(HISwritefp),LOCK_UN); + return FALSE; + } + + if (++HISdirty >= ICD_SYNC_COUNT) + HISsync(); + flock(fileno(HISwritefp),LOCK_UN); + return TRUE; +} diff --git a/pttbbs/innbbsd/his.h b/pttbbs/innbbsd/his.h new file mode 100644 index 00000000..f54efc01 --- /dev/null +++ b/pttbbs/innbbsd/his.h @@ -0,0 +1,80 @@ +#ifndef HIS_H +#define HIS_H +#include +#include +#include +#include +#include +#ifndef SEEK_SET +#include +#endif +#include "dbz.h" + +#ifndef XINDEXDIR +# define XINDEXDIR "/homec/xindex" +#endif +#ifndef _PATH_HISTORY +# define _PATH_HISTORY "/u/staff/bbsroot/csie_util/bntpd/history" +#endif + +#ifndef _PATH_COVERVIEW +# define _PATH_COVERVIEW ".coverview" +#endif + +#ifndef _PATH_COVERVIEWDIR +# define _PATH_COVERVIEWDIR "/homec/xindex" +#endif + +#ifndef XINDEX_DBZINCORE +# define XINDEX_DBZINCORE 1 +#endif +#ifndef XINDEXNAME +# define XINDEXNAME ".index" +#endif +#ifndef XINDEXDBM +# define XINDEXDBM ".dbm" +#endif +#ifndef XINDEXINFO +# define XINDEXINFO ".info" +#endif + +#define LEN 1024 +struct t_article { + long artnum; + char subject[LEN]; /* Subject: line from mail header */ + char from[LEN]; /* From: line from mail header (address) + */ + char name[LEN]; /* From: line from mail header (full nam +e) */ + long date; /* Date: line from header in seconds */ + char xref[LEN]; /* Xref: cross posted article reference +line */ + int lines; /* Lines: number of lines in article */ + char *archive; /* Archive-name: line from mail header */ + char *part; /* part no. of archive */ + char *patch; /* patch no. of archive */ +}; + +typedef struct t_article art_t; + +#define HIS_BADCHAR '_' +#define HIS_FIELDSEP '\t' +#define HIS_NOEXP "-" +#define HIS_SUBFIELDSEP '~' +/*#define HIS_FIELDSEP2 '\034'*/ +#define HIS_FIELDSEP2 'I' + +#ifndef TRUE +# define TRUE 1 +# define FALSE 0 +#endif + +#ifndef BOOL +typedef unsigned char BOOL; +#endif + +#ifndef ICD_SYNC_COUNT +# define ICD_SYNC_COUNT 1 +#endif + +#endif diff --git a/pttbbs/innbbsd/innbbsconf.h b/pttbbs/innbbsd/innbbsconf.h new file mode 100644 index 00000000..6521dde6 --- /dev/null +++ b/pttbbs/innbbsd/innbbsconf.h @@ -0,0 +1,192 @@ +#ifndef INNBBSCONF_H +#define INNBBSCONF_H +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#ifndef BSD44 +# include +#endif +#include +#include +#include + +/*#include "bbs.h"*/ +#if defined(AIX) +# include +#endif + +/* + BBS home directory + It has been overridden in Makefile +*/ +#ifndef _PATH_BBSHOME +# define _PATH_BBSHOME "/u/staff/bbsroot/csie_util/bntpd/home" +/*# define _PATH_BBSHOME "/home/bbs"*/ +#endif + +#ifndef EXPIREDAYS +# define EXPIREDAYS 7 +#endif + +#ifndef DEFAULT_HIST_SIZE +# define DEFAULT_HIST_SIZE 100000 +#endif + +/* + Maximum number of connections accepted by innbbsd +*/ +#ifndef MAXCLIENT +# define MAXCLIENT 500 +#endif + +/* + Maximum number of articles received for a newsgroup by bbsnnrp each time +*/ +#ifndef MAX_ARTS +# define MAX_ARTS 100 +#endif + +/* + Maximum size of articles received +*/ +#ifndef MAX_ART_SIZE +# define MAX_ART_SIZE 1000000L +#endif + + +/* + Maximum number of articles stated for a newsgroup by bbsnnrp each time +*/ +#ifndef MAX_STATS +# define MAX_STATS 1000 +#endif + +/* + Mininum wait interval for bbsnnrp +*/ +#ifndef MIN_WAIT +# define MIN_WAIT 60 +#endif + + +#ifndef DefaultINNBBSPort +# define DefaultINNBBSPort "7777" +#endif + +/* + time to maintain history database +*/ +#ifndef HIS_MAINT +# define HIS_MAINT +# define HIS_MAINT_HOUR 4 +# define HIS_MAINT_MIN 30 +#endif + +#ifndef ChannelSize +# define ChannelSize 4096 +#endif + +#ifndef ReadSize +# define ReadSize 1024 +#endif + +#ifndef MAXPATHLEN +# define MAXPATHLEN 1024 +#endif + +#ifndef CLX_IOCTL +# define CLX_IOCTL +#endif + +#define DEFAULTSERVER "your.favorite.news.server" +#define DEFAULTPORT "nntp" +#define DEFAULTPROTOCOL "tcp" +#define DEFAULTPATH ".innbbsd" + +#ifndef INADDR_NONE +#define INADDR_NONE 0xffffffff +#endif + +/* +# ifndef ARG +# ifdef __STDC__ +# define ARG(x) (x) +# else +# define ARG(x) () +# endif +# endif +*/ +/* machine dependend */ +#if defined(__linux) +# ifndef LINUX +# define LINUX +# endif +#endif + +#if !defined(__svr4__) || defined(sun) +# define WITH_TM_GMTOFF +#endif +#if (defined(__svr4__) && defined(sun)) || defined(SOLARIS) +# ifndef SOLARIS +# define SOLARIS +# endif +# define NO_getdtablesize +# define NO_bcopy +# define NO_bzero +# define NO_flock +# define WITH_lockf +#endif + +#if defined(AIX) +# define NO_flock +# define WITH_lockf +#endif + +#if defined(HPUX) +# define NO_getdtablesize +# define NO_flock +# define WITH_lockf +#endif + +#ifdef NO_bcopy +# ifndef bcopy +# define bcopy(a,b,c) memcpy(b,a,c) +# endif +#endif + +#ifdef NO_bzero +# ifndef bzero +# define bzero(mem, size) memset(mem,'\0',size) +# endif +#endif + +#ifndef LOCK_EX +# define LOCK_EX 2 /* exclusive lock */ +# define LOCK_UN 8 /* unlock */ +#endif + +#ifdef DEC_ALPHA +# define ULONG unsigned int +#else +# define ULONG unsigned long +#endif + +#ifdef PalmBBS +#undef WITH_RECORD_O +#endif + +#endif diff --git a/pttbbs/innbbsd/innbbsd.c b/pttbbs/innbbsd/innbbsd.c new file mode 100644 index 00000000..f35c1cfb --- /dev/null +++ b/pttbbs/innbbsd/innbbsd.c @@ -0,0 +1,775 @@ +#include "innbbsconf.h" +#include "daemon.h" +#include "innbbsd.h" +#include +#include "bbslib.h" +#include "inntobbs.h" +#include "nntp.h" + +#ifdef GETRUSAGE +#include +#include +#endif + +#ifdef STDC +# ifndef ARG +# define ARG(x) (x) +# else +# define ARG(x) () +# endif +#endif + +/*< add ... +> 200 OK +< quit + 500 BYE + +> 300 DBZ Server ... +< query +> 250 ... +> 450 NOT FOUND! +*/ + +static int CMDhelp ARG((ClientType*)); +static int CMDquit ARG((ClientType*)); +static int CMDihave ARG((ClientType*)); +static int CMDstat ARG((ClientType*)); +static int CMDaddhist ARG((ClientType*)); +static int CMDgrephist ARG((ClientType*)); +static int CMDmidcheck ARG((ClientType*)); +static int CMDshutdown ARG((ClientType*)); +static int CMDmode ARG((ClientType*)); +static int CMDreload ARG((ClientType*)); +static int CMDhismaint ARG((ClientType*)); +static int CMDverboselog ARG((ClientType*)); +static int CMDlistnodelist ARG((ClientType*)); +static int CMDlistnewsfeeds ARG((ClientType*)); + +#ifdef GETRUSAGE +static int CMDgetrusage ARG((ClientType*)); +static int CMDmallocmap ARG((ClientType*)); +#endif + +static daemoncmd_t cmds[]= +/* cmd-name, cmd-usage, min-argc, max-argc, errorcode, normalcode, cmd-func */ +{ {"help","help [cmd]",1,2,99,100,CMDhelp}, + {"quit","quit",1,0,99,100,CMDquit}, +#ifndef DBZSERVER + {"ihave","ihave mid",2,2,435,335,CMDihave}, +#endif + {"stat","stat mid",2,2,223,430,CMDstat}, + {"addhist","addhist ",3,3, NNTP_ADDHIST_BAD, NNTP_ADDHIST_OK,CMDaddhist}, + {"grephist","grephist ",2,2, NNTP_GREPHIST_BAD, NNTP_GREPHIST_OK, CMDgrephist}, + {"midcheck","midcheck [on|off]",1,2, NNTP_MIDCHECK_BAD, NNTP_MIDCHECK_OK, CMDmidcheck}, + {"shutdown","shutdown (local)",1,1, NNTP_SHUTDOWN_BAD, NNTP_SHUTDOWN_OK, CMDshutdown}, + {"mode","mode (local)",1,1, NNTP_MODE_BAD, NNTP_MODE_OK, CMDmode}, + {"listnodelist","listnodelist (local)",1,1, NNTP_MODE_BAD, NNTP_MODE_OK, CMDlistnodelist}, + {"listnewsfeeds","listnewsfeeds (local)",1,1, NNTP_MODE_BAD, NNTP_MODE_OK, CMDlistnewsfeeds}, + {"reload","reload (local)",1,1, NNTP_RELOAD_BAD, NNTP_RELOAD_OK, CMDreload}, + {"hismaint","hismaint (local)",1,1, NNTP_RELOAD_BAD, NNTP_RELOAD_OK, CMDhismaint}, + {"verboselog","verboselog [on|off](local)",1,2, NNTP_VERBOSELOG_BAD, NNTP_VERBOSELOG_OK, CMDverboselog}, +#ifdef GETRUSAGE + {"getrusage","getrusage (local)",1,1, NNTP_MODE_BAD, NNTP_MODE_OK, CMDgetrusage}, +#endif +#ifdef MALLOCMAP + {"mallocmap","mallocmap (local)",1,1, NNTP_MODE_BAD, NNTP_MODE_OK, CMDmallocmap}, +#endif + {NULL,NULL,0,0,99,100,NULL} +}; + +installinnbbsd() +{ + installdaemon(cmds,100,NULL); +} + +#ifdef OLDLIBINBBSINND +testandmkdir(dir) +char *dir; +{ + if (!isdir(dir)) { + char path[MAXPATHLEN+12]; + sprintf(path,"mkdir -p %s",dir); + system(path); + } +} + +static char splitbuf[2048]; +static char joinbuf[1024]; +#define MAXTOK 50 +static char* Splitptr[MAXTOK]; +char **split(line,pat) +char *line,*pat; +{ + char *p; + int i; + + for (i=0;iboard,nf2->board)==0) { + *ptr[j] = '\0'; + continue; + } + for (n11 = nf1->board, n12 = (char*)strchr(n11,','); + n11 && *n11 ; n12 = (char*) strchr(n11,',')) { + if (n12) *n12 = '\0'; + for (n21 = nf2->board, n22 = (char*)strchr(n21,','); + n21 && *n21 ; n22 = (char*) strchr(n21,',')) { + if (n22) *n22 = '\0'; + if (strcmp(n11,n21)==0) { + *n21 = '\t'; + } + if (n22) { + *n22 = ','; + n21 = n22 + 1; + } else + break; + } + if (n12) { + *n12 = ','; + n11 = n12 +1; + } else + break; + } + } + } + } + return ptr; +} + +char **ssplit(line,pat) +char *line,*pat; +{ + char *p; + int i; + for (i=0;iArgv; + fprintf(argv->out,"%d %s\n",argv->dc->usage); + return 0; +} + +islocalconnect(client) +ClientType *client; +{ + if (strcmp(client->username,"localuser") != 0 || + strcmp(client->hostname,"localhost") != 0) + return 0; + return 1; +} + +static shutdownflag = 0; +INNBBSDhalt() +{ + shutdownflag = 1; +} + +int INNBBSDshutdown() +{ + return shutdownflag; +} + +static int CMDshutdown(client) +ClientType *client; +{ + argv_t *argv = &client->Argv; + buffer_t *in = &client->in; + daemoncmd_t *p = argv->dc; + if (!islocalconnect(client)) { + fprintf(argv->out,"%d shutdown access denied\r\n", p->errorcode); + fflush(argv->out); + verboselog("Shutdown Put: %d shutdown access denied\n", p->errorcode); + return 1; + } + shutdownflag = 1; + fprintf(argv->out,"%d shutdown starting\r\n", p->normalcode); + fflush(argv->out); + verboselog("Shutdown Put: %d shutdown starting\n", p->normalcode); + return 1; +} + +static int CMDmode(client) +ClientType *client; +{ + /*char cwdpath[MAXPATHLEN+1];*/ + argv_t *argv = &client->Argv; + extern ClientType INNBBSD_STAT; + buffer_t *in = &client->in; + daemoncmd_t *p = argv->dc; + time_t uptime, now; + int i,j; + time_t lasthist; + ClientType *client1 = &INNBBSD_STAT; + + if (!islocalconnect(client)) { + fprintf(argv->out,"%d mode access denied\r\n", p->errorcode); + fflush(argv->out); + verboselog("Mode Put: %d mode access denied\n", p->errorcode); + return 1; + } + fprintf(argv->out,"%d mode\r\n", p->normalcode); + fflush(argv->out); + verboselog("Mode Put: %d mode\n", p->normalcode); + uptime = innbbsdstartup(); + time(&now); + fprintf(argv->out,"up since %salive %.2f days\r\n", ctime(&uptime), (double)(now - innbbsdstartup())/86400); + fprintf(argv->out,"BBSHOME %s\r\n", BBSHOME); + fprintf(argv->out,"MYBBSID %s\r\n", MYBBSID); + fprintf(argv->out,"ECHOMAIL %s\r\n", ECHOMAIL); + fprintf(argv->out,"INNDHOME %s\r\n", INNDHOME); + fprintf(argv->out,"HISTORY %s\r\n", HISTORY); + fprintf(argv->out,"LOGFILE %s\r\n", LOGFILE); + fprintf(argv->out,"INNBBSCONF %s\r\n", INNBBSCONF); + fprintf(argv->out,"BBSFEEDS %s\r\n", BBSFEEDS); + fprintf(argv->out,"Verbose log: %s\r\n", isverboselog() ?"ON":"OFF"); + fprintf(argv->out,"History Expire Days %d\r\n", Expiredays); + fprintf(argv->out,"History Expire Time %d:%d\r\n", His_Maint_Hour, His_Maint_Min); + lasthist = gethisinfo(); + if (lasthist > 0) { + time_t keep = lasthist, keep1; + time(&now); + fprintf(argv->out,"Oldest history entry created: %s",(char*)ctime(&keep)); + keep = Expiredays * 86400 * 2 + lasthist; + keep1 = keep - now ; + fprintf(argv->out,"Next time to maintain history: (%.2f days later) %s",(double)keep1/86400, (char*)ctime(&keep)); + } + fprintf(argv->out,"PID is %d\r\n", getpid()); + fprintf(argv->out,"LOCAL ONLY %d\r\n", LOCALNODELIST); + fprintf(argv->out,"NONE NEWSFEEDS %d\r\n", NONENEWSFEEDS); + fprintf(argv->out,"Max connections %d\r\n", Maxclient); +#ifdef DEBUGCWD + getwd(cwdpath); + fprintf(argv->out,"Working directory %s\r\n", cwdpath); +#endif + if (Channel) + for (i=0, j=0; i< Maxclient; ++i) { + if (Channel[i].fd == -1) continue; + if (Channel+i == client) continue; + j++; + fprintf(argv->out," %d) in->used %d, in->left %d %s@%s\r\n",i, + Channel[i].in.used, Channel[i].in.left, + Channel[i].username,Channel[i].hostname); + } + fprintf(argv->out,"Total connections %d\r\n", j); + fprintf(argv->out,"Total rec: %d dup: %d fail: %d size: %d, stat rec: %d fail: %d\n", client1->ihavecount, client1->ihaveduplicate, client1->ihavefail, client1->ihavesize, client1->statcount, client1->statfail); + fprintf(argv->out,".\r\n"); + fflush(argv->out); + return 1; +} + +static int +CMDlistnodelist(client) +ClientType *client; +{ + int nlcount; + argv_t *argv = &client->Argv; + buffer_t *in = &client->in; + daemoncmd_t *p = argv->dc; + if (!islocalconnect(client)) { + fprintf(argv->out,"%d listnodelist access denied\r\n", p->errorcode); + fflush(argv->out); + verboselog("Mallocmap Put: %d listnodelist access denied\n", p->errorcode); + return 1; + } + fprintf(argv->out,"%d listnodelist\r\n", p->normalcode); + for (nlcount =0; nlcount < NLCOUNT; nlcount++) { + nodelist_t *nl = NODELIST+nlcount; + fprintf(argv->out,"%2d %s /\\/\\ %s\r\n", nlcount+1, nl->node==NULL?"":nl->node, nl->exclusion==NULL?"":nl->exclusion); + fprintf(argv->out," %s:%s:%s\r\n",nl->host==NULL?"":nl->host, nl->protocol==NULL?"":nl->protocol, nl->comments == NULL ? "": nl->comments); + } + fprintf(argv->out,".\r\n"); + fflush(argv->out); + verboselog("Listnodelist Put: %d listnodelist complete\n", p->normalcode); + return 1; +} + +static int +CMDlistnewsfeeds(client) +ClientType *client; +{ + argv_t *argv = &client->Argv; + buffer_t *in = &client->in; + daemoncmd_t *p = argv->dc; + int nfcount; + if (!islocalconnect(client)) { + fprintf(argv->out,"%d listnewsfeeds access denied\r\n", p->errorcode); + fflush(argv->out); + verboselog("Mallocmap Put: %d listnewsfeeds access denied\n", p->errorcode); + return 1; + } + fprintf(argv->out,"%d listnewsfeeds\r\n", p->normalcode); + for (nfcount =0; nfcount < NFCOUNT; nfcount++) { + newsfeeds_t *nf = NEWSFEEDS + nfcount; + fprintf(argv->out,"%3d %s<=>%s\r\n",nfcount+1, nf->newsgroups, nf->board); + fprintf(argv->out," %s\r\n",nf->path==NULL?"(Null)":nf->path); + } + fprintf(argv->out,".\r\n"); + fflush(argv->out); + verboselog("Listnewsfeeds Put: %d listnewsfeeds complete\n", p->normalcode); + return 1; +} + +#ifdef MALLOCMAP +static int CMDmallocmap(client) +ClientType *client; +{ + argv_t *argv = &client->Argv; + buffer_t *in = &client->in; + daemoncmd_t *p = argv->dc; + struct rusage ru; + int savefd ; + if (!islocalconnect(client)) { + fprintf(argv->out,"%d mallocmap access denied\r\n", p->errorcode); + fflush(argv->out); + verboselog("Mallocmap Put: %d mallocmap access denied\n", p->errorcode); + return 1; + } + fprintf(argv->out,"%d mallocmap\r\n", p->normalcode); + savefd = dup(1); + dup2(client->fd, 1); + mallocmap(); + dup2(savefd, 1); + close(savefd); + fprintf(argv->out,".\r\n"); + fflush(argv->out); + verboselog("Mallocmap Put: %d mallocmap complete\n", p->normalcode); + return 1; +} +#endif + +#ifdef GETRUSAGE +static int CMDgetrusage(client) +ClientType *client; +{ + argv_t *argv = &client->Argv; + buffer_t *in = &client->in; + daemoncmd_t *p = argv->dc; + struct rusage ru; + if (!islocalconnect(client)) { + fprintf(argv->out,"%d getrusage access denied\r\n", p->errorcode); + fflush(argv->out); + verboselog("Getrusage Put: %d getrusage access denied\n", p->errorcode); + return 1; + } + fprintf(argv->out,"%d getrusage\r\n", p->normalcode); + if (getrusage(RUSAGE_SELF,&ru) == 0) { + fprintf(argv->out,"user time used: %.6f\r\n",(double)ru.ru_utime.tv_sec + (double)ru.ru_utime.tv_usec/1000000.0); + fprintf(argv->out,"system time used: %.6f\r\n",(double)ru.ru_stime.tv_sec + (double)ru.ru_stime.tv_usec/1000000.0); + fprintf(argv->out,"maximum resident set size: %lu\r\n",ru.ru_maxrss * getpagesize()); + fprintf(argv->out,"integral resident set size: %lu\r\n",ru.ru_idrss * getpagesize()); + fprintf(argv->out,"page faults not requiring physical I/O: %d\r\n",ru.ru_minflt); + fprintf(argv->out,"page faults requiring physical I/O: %d\r\n",ru.ru_majflt); + fprintf(argv->out,"swaps: %d\r\n",ru.ru_nswap); + fprintf(argv->out,"block input operations: %d\r\n",ru.ru_inblock); + fprintf(argv->out,"block output operations: %d\r\n",ru.ru_oublock); + fprintf(argv->out,"messages sent: %d\r\n",ru.ru_msgsnd); + fprintf(argv->out,"messages received: %d\r\n",ru.ru_msgrcv); + fprintf(argv->out,"signals received: %d\r\n",ru.ru_nsignals); + fprintf(argv->out,"voluntary context switches: %d\r\n",ru.ru_nvcsw); + fprintf(argv->out,"involuntary context switches: %d\r\n",ru.ru_nivcsw); + } + fprintf(argv->out,".\r\n"); + fflush(argv->out); + verboselog("Getrusage Put: %d getrusage complete\n", p->normalcode); + return 1; +} + +#endif + +static int CMDhismaint(client) +ClientType *client; +{ + argv_t *argv = &client->Argv; + buffer_t *in = &client->in; + daemoncmd_t *p = argv->dc; + if (!islocalconnect(client)) { + fprintf(argv->out,"%d hismaint access denied\r\n", p->errorcode); + fflush(argv->out); + verboselog("Hismaint Put: %d hismaint access denied\n", p->errorcode); + return 1; + } + verboselog("Hismaint Put: %d hismaint start\n", p->normalcode); + HISmaint(); + fprintf(argv->out,"%d hismaint complete\r\n", p->normalcode); + fflush(argv->out); + verboselog("Hismaint Put: %d hismaint complete\n", p->normalcode); + return 1; +} + +static int CMDreload(client) +ClientType *client; +{ + argv_t *argv = &client->Argv; + buffer_t *in = &client->in; + daemoncmd_t *p = argv->dc; + if (!islocalconnect(client)) { + fprintf(argv->out,"%d reload access denied\r\n", p->errorcode); + fflush(argv->out); + verboselog("Reload Put: %d reload access denied\n", p->errorcode); + return 1; + } + initial_bbs("feed"); + fprintf(argv->out,"%d reload complete\r\n", p->normalcode); + fflush(argv->out); + verboselog("Reload Put: %d reload complete\n", p->normalcode); + return 1; +} + +static int CMDverboselog(client) +ClientType *client; +{ + argv_t *argv = &client->Argv; + buffer_t *in = &client->in; + daemoncmd_t *p = argv->dc; + if (!islocalconnect(client)) { + fprintf(argv->out,"%d verboselog access denied\r\n", p->errorcode); + fflush(argv->out); + verboselog("Reload Put: %d verboselog access denied\n", p->errorcode); + return 1; + } + if (client->mode == 0) { + if (argv->argc > 1) { + if (strcasecmp(argv->argv[1],"off")==0) { + setverboseoff(); + } else { + setverboseon(); + } + } + } + fprintf(argv->out,"%d verboselog %s\r\n",p->normalcode, + isverboselog() ?"ON":"OFF"); + fflush(argv->out); + verboselog("%d verboselog %s\r\n",p->normalcode, + isverboselog()?"ON":"OFF"); +} + +static int CMDmidcheck(client) +ClientType *client; +{ + argv_t *argv = &client->Argv; + buffer_t *in = &client->in; + daemoncmd_t *p = argv->dc; + if (client->mode == 0) { + if (argv->argc > 1) { + if (strcasecmp(argv->argv[1],"off")==0) { + client->midcheck = 0; + } else { + client->midcheck = 1; + } + } + } + fprintf(argv->out,"%d mid check %s\r\n",p->normalcode, + client->midcheck == 1?"ON":"OFF"); + fflush(argv->out); + verboselog("%d mid check %s\r\n",p->normalcode, + client->midcheck == 1?"ON":"OFF"); +} + +static int CMDgrephist(client) +ClientType *client; +{ + argv_t *argv = &client->Argv; + buffer_t *in = &client->in; + daemoncmd_t *p = argv->dc; + if (client->mode == 0) { + if (argv->argc > 1) { + char *ptr; + ptr = (char*)DBfetch(argv->argv[1]); + if (ptr != NULL) { + fprintf(argv->out,"%d %s OK\r\n", p->normalcode, ptr); + fflush(argv->out); + verboselog("Addhist Put: %d %s OK\n", p->normalcode, ptr); + return 0; + } else { + fprintf(argv->out,"%d %s not found\r\n", p->errorcode,argv->argv[1]); + fflush(argv->out); + verboselog("Addhist Put: %d %s not found\n", p->errorcode, argv->argv[1]); + return 1; + } + } + } + fprintf(argv->out,"%d grephist error\r\n", p->errorcode); + fflush(argv->out); + verboselog("Addhist Put: %d grephist error\n", p->errorcode); + return 1; +} + + +static int CMDaddhist(client) +ClientType *client; +{ + argv_t *argv = &client->Argv; + buffer_t *in = &client->in; + daemoncmd_t *p = argv->dc; + /* + if (strcmp(client->username,"localuser") != 0 || + strcmp(client->hostname,"localhost") != 0) { + fprintf(argv->out,"%d add hist access denied\r\n", p->errorcode); + fflush(argv->out); + verboselog("Addhist Put: %d add hist access denied\n", p->errorcode); + return 1; + } + */ + if (client->mode == 0) { + if (argv->argc > 2) { + char *ptr; + ptr = (char*)DBfetch(argv->argv[1]); + if (ptr == NULL) { + if (storeDB(argv->argv[1], argv->argv[2]) < 0) { + fprintf(argv->out,"%d add hist store DB error\r\n", p->errorcode); + fflush(argv->out); + verboselog("Addhist Put: %d add hist store DB error\n", p->errorcode); + return 1; + } else { + fprintf(argv->out,"%d add hist OK\r\n", p->normalcode); + fflush(argv->out); + verboselog("Addhist Put: %d add hist OK\n", p->normalcode); + return 0; + } + } else { + fprintf(argv->out,"%d add hist duplicate error\r\n", p->errorcode); + fflush(argv->out); + verboselog("Addhist Put: %d add hist duplicate error\n", p->errorcode); + return 1; + } + } + } + fprintf(argv->out,"%d add hist error\r\n", p->errorcode); + fflush(argv->out); + verboselog("Addhist Put: %d add hist error\n", p->errorcode); + return 1; +} + +static int CMDstat(client) +ClientType *client; +{ + argv_t *argv = &client->Argv; + char *ptr, *frontptr; + buffer_t *in = &client->in; + daemoncmd_t *p; + if (client->mode == 0) { + client->statcount++; + if (argv->argc > 1) { + if (argv->argv[1][0] != '<') { + fprintf(argv->out,"430 No such article\r\n"); + fflush(argv->out); + verboselog("Stat Put: 430 No such article\n"); + client->statfail++; + return 0; + } + ptr = (char*)DBfetch(argv->argv[1]); + if (ptr != NULL) { + fprintf(argv->out,"223 0 status %s\r\n",argv->argv[1]); + fflush(argv->out); + client->mode = 0; + verboselog("Stat Put: 223 0 status %s\n",argv->argv[1]); + return 1; + } else { + fprintf(argv->out,"430 No such article\r\n"); + fflush(argv->out); + verboselog("Stat Put: 430 No such article\n"); + client->mode = 0; + client->statfail++; + } + } + } +} + +#ifndef DBZSERVER +static int CMDihave(client) +ClientType *client; +{ + argv_t *argv = &client->Argv; + char *ptr=NULL, *frontptr; + buffer_t *in = &client->in; + daemoncmd_t *p; + if (client->mode == 0) { + client->ihavecount++; + if (argv->argc > 1) { + if (argv->argv[1][0] != '<') { + fprintf(argv->out,"435 Bad Message-ID\r\n"); + fflush(argv->out); + verboselog("Ihave Put: 435 Bad Message-ID\n"); + client->ihavefail++; + return 0; + } + if (client->midcheck == 1) + ptr = (char*)DBfetch(argv->argv[1]); + if (ptr != NULL && client->midcheck == 1) { + fprintf(argv->out,"435 Duplicate\r\n"); + fflush(argv->out); + client->mode = 0; + verboselog("Ihave Put: 435 Duplicate\n"); + client->ihaveduplicate++; + client->ihavefail++; + return 1; + } else { + fprintf(argv->out,"335\r\n"); + fflush(argv->out); + client->mode = 1; + verboselog("Ihave Put: 335\n"); + } + } + } else { + client->mode = 0; + readlines(client); + if (HEADER[SUBJECT_H] && HEADER[FROM_H] && HEADER[DATE_H] && + HEADER[MID_H] && HEADER[NEWSGROUPS_H] ) { + char *path1, *path2; + int rel ; + rel = 0; + path1 = (char*)mymalloc(strlen(HEADER[PATH_H]) + 3); + path2 = (char*)mymalloc(strlen(MYBBSID) + 3); + sprintf(path1, "!%s!",HEADER[PATH_H]); + sprintf(path2, "!%s!",MYBBSID); + if (HEADER[CONTROL_H]) { + bbslog( "Control: %s\n", HEADER[CONTROL_H] ); + if (strncasecmp(HEADER[CONTROL_H],"cancel ",7)==0) { + rel = cancel_article_front(HEADER[CONTROL_H]+7); + } else { + rel = receive_control(); + } + } else if ( (char*)strstr(path1, path2) != NULL) { + bbslog( ":Warn: Loop back article: %s!%s\n",MYBBSID,HEADER[PATH_H] ); + } else { + rel = receive_article(); + } + free(path1); + free(path2); + if (rel == -1) { + fprintf(argv->out,"400 server side failed\r\n"); + fflush(argv->out); + verboselog("Ihave Put: 400\n"); + clearfdset(client->fd); + fclose(client->Argv.in); + fclose(client->Argv.out); + close(client->fd); + client->fd = -1; + client->mode = 0; + client->ihavefail++; + return; + } else { + fprintf(argv->out,"235\r\n"); + verboselog("Ihave Put: 235\n"); + } + fflush(argv->out); + } else if (!HEADER[PATH_H]) { + fprintf(argv->out,"437 No Path in \"ihave %s\" header\r\n",HEADER[MID_H]); + fflush(argv->out); + verboselog("Put: 437 No Path in \"ihave %s\" header\n",HEADER[MID_H]); + client->ihavefail++; + } else { + fprintf(argv->out,"437 No colon-space in \"ihave %s\" header\r\n",HEADER[MID_H]); + fflush(argv->out); + verboselog("Ihave Put: 437 No colon-space in \"ihave %s\" header\n",HEADER[MID_H]); + client->ihavefail++; + } +#ifdef DEBUG + printf("subject is %s\n",HEADER[SUBJECT_H]); + printf("from is %s\n",HEADER[FROM_H]); + printf("Date is %s\n",HEADER[DATE_H]); + printf("Newsgroups is %s\n",HEADER[NEWSGROUPS_H]); + printf("mid is %s\n",HEADER[MID_H]); + printf("path is %s\n",HEADER[PATH_H]); +#endif + } + fflush(argv->out); + return 0; +} +#endif + +static int CMDhelp(client) +ClientType *client; +{ + argv_t *argv = &client->Argv; + daemoncmd_t *p; + if (argv->argc>=1) { + fprintf(argv->out,"%d Available Commands\r\n",argv->dc->normalcode); + for (p=cmds;p->name !=NULL;p++) { + fprintf(argv->out," %s\r\n",p->usage); + } + fprintf(argv->out,"Report problems to %s\r\n",ADMINUSER); + } + fputs(".\r\n",argv->out); + fflush(argv->out); + client->mode = 0; + return 0; +} + +static int CMDquit(client) +ClientType *client; +{ + argv_t *argv = &client->Argv; + fprintf(argv->out,"205 quit\r\n"); + fflush(argv->out); + verboselog("Quit Put: 205 quit\n"); + clearfdset(client->fd); + fclose(client->Argv.in); + fclose(client->Argv.out); + close(client->fd); + client->fd = -1; + client->mode = 0; + channeldestroy(client); + /*exit(0);*/ +} diff --git a/pttbbs/innbbsd/innbbsd.h b/pttbbs/innbbsd/innbbsd.h new file mode 100644 index 00000000..ba667ee6 --- /dev/null +++ b/pttbbs/innbbsd/innbbsd.h @@ -0,0 +1,9 @@ +#ifndef INNBBSD_H +#define INNBBSD_H +#include "daemon.h" + +#ifndef ADMINUSER +# define ADMINUSER "usenet@csie.nctu.edu.tw" +#endif + +#endif diff --git a/pttbbs/innbbsd/inndchannel.c b/pttbbs/innbbsd/inndchannel.c new file mode 100644 index 00000000..439b2af0 --- /dev/null +++ b/pttbbs/innbbsd/inndchannel.c @@ -0,0 +1,657 @@ +#include "innbbsconf.h" +#include "daemon.h" +#include "bbslib.h" +#include "config.h" + +#define DEBUG +#undef DEBUG + +#ifndef MAXCLIENT +#define MAXCLIENT 500 +#endif + +#ifndef ChannelSize +#define ChannelSize 4096 +#endif + +#ifndef ReadSize +#define ReadSize 1024 +#endif + +#ifndef DefaultINNBBSPort +# define DefaultINNBBSPort "7777" +#endif + +#ifndef HIS_MAINT +# define HIS_MAINT +# define HIS_MAINT_HOUR 5 +# define HIS_MAINT_MIN 30 +#endif + +int Maxclient=MAXCLIENT; +ClientType *Channel=NULL; +ClientType INNBBSD_STAT; + +int Max_Art_Size = MAX_ART_SIZE; + +int inetdstart = 0; + +int Junkhistory = 0; + +char *REMOTEUSERNAME, *REMOTEHOSTNAME; + +static fd_set rfd,wfd,efd,orfd,owfd,oefd; + +clearfdset(fd) +int fd; +{ + FD_CLR(fd,&rfd); +} + +static +channelcreate(client) +ClientType *client; +{ + buffer_t *in, *out; + in = &client->in; + out = &client->out; + if (in->data != NULL) + free(in->data); + in->data = (char*)mymalloc( ChannelSize ); + in->left = ChannelSize; + in->used = 0; + if (out->data != NULL) + free(out->data); + out->data = (char*)mymalloc( ChannelSize ); + out->used = 0; + out->left = ChannelSize; + client->ihavecount = 0; + client->ihaveduplicate = 0; + client->ihavefail = 0; + client->ihavesize = 0; + client->statcount = 0; + client->statfail = 0; + client->begin = time(NULL); +} + +channeldestroy(client) +ClientType *client; +{ + if (client->in.data != NULL) { + free(client->in.data); + client->in.data = NULL; + } + if (client->out.data != NULL) { + free(client->out.data); + client->out.data = NULL; + } +#if !defined(PowerBBS) && !defined(DBZSERVER) + if (client->ihavecount >0 || client->statcount >0) { + bbslog("%s@%s rec: %d dup: %d fail: %d size: %d, stat rec: %d fail: %d, time sec: %d\n", + client->username, client->hostname, client->ihavecount, + client->ihaveduplicate, client->ihavefail, client->ihavesize, + client->statcount, client->statfail, time(NULL) - client->begin); + INNBBSD_STAT.ihavecount += client->ihavecount; + INNBBSD_STAT.ihaveduplicate += client->ihaveduplicate; + INNBBSD_STAT.ihavefail += client->ihavefail; + INNBBSD_STAT.ihavesize += client->ihavesize; + INNBBSD_STAT.statcount += client->statcount; + INNBBSD_STAT.statfail += client->statfail; + } +#endif +} + +inndchannel(port, path) +char *port, *path; +{ + time_t tvec; + int i; + int bbsinnd ; + int localbbsinnd; + char obuf[4096]; + struct timeval tout; + ClientType *client = (ClientType *)mymalloc( sizeof(ClientType) * Maxclient); + int localdaemonready = 0; + Channel = client; + + bbsinnd = pmain(port); + if (bbsinnd < 0) { + perror("pmain, existing"); + docompletehalt(); + return(-1); + } + + FD_ZERO(&rfd); FD_ZERO(&wfd); FD_ZERO(&efd); + + localbbsinnd = p_unix_main(path); + if (localbbsinnd < 0) { + perror("local pmain, existing"); +/* Kaede + if (!inetdstart) + fprintf(stderr, "if no other innbbsd running, try to remove %s\n",path); +*/ + close(bbsinnd); + return(-1); + } else { + FD_SET(localbbsinnd,&rfd); + localdaemonready = 1; + } + + FD_SET(bbsinnd,&rfd); + tvec = time((time_t *)0); + for (i=0;i< Maxclient ;++i) { + client[i].fd = -1; + client[i].access=0; + client[i].buffer[0] = '\0'; + client[i].mode = 0; + client[i].in.left = 0; + client[i].in.used = 0; + client[i].in.data = NULL; + client[i].out.left = 0; + client[i].out.used = 0; + client[i].out.data = NULL; + client[i].midcheck = 1; + } + for (;;) { + int nsel,i; + +/* + When to maintain history files. +*/ + time_t now; + static int maint = 0; + struct tm *local; + + if (INNBBSDshutdown()) { + HISclose(); + bbslog(" Shutdown Complete \n"); + docompletehalt(); + exit(0); + } + + time(&now); + local = localtime(&now); + if (local != NULL & local->tm_hour == His_Maint_Hour && + local->tm_min >= His_Maint_Min ) { + if (!maint) { + bbslog(":Maint: start (%d:%d).\n",local->tm_hour,local->tm_min); + HISmaint(); + time(&now); + local = localtime(&now); + if (local != NULL) + bbslog(":Maint: end (%d:%d).\n",local->tm_hour,local->tm_min); + maint = 1; + } + } else { + maint = 0; + } +/* +*/ +/* + in order to maintain history, timeout every 60 seconds in case + no connections +*/ + tout.tv_sec = 60; + tout.tv_usec = 0; + orfd = rfd; + if ((nsel=select(FD_SETSIZE,&orfd, NULL , NULL , &tout))<0){ + continue; + } + if (localdaemonready && FD_ISSET(localbbsinnd,&orfd)) { + int ns,length; + int cc; + ns=tryaccept(localbbsinnd); + if (ns < 0) continue; + for (i=0;i< Maxclient ;++i) { + if (client[i].fd==-1) break; + } + if (i== Maxclient) { + static char msg[]="502 no free descriptors\r\n"; + printf("%s",msg); + write(ns, msg, sizeof(msg)); + close(ns); + continue; + } + client[i].fd=ns; + client[i].buffer[0] = '\0'; + client[i].mode = 0; + client[i].midcheck = 1; + channelcreate(&client[i]); + FD_SET(ns,&rfd); /*FD_SET(ns,&wfd);*/ + { + strncpy(client[i].username,"localuser",20); + strncpy(client[i].hostname,"localhost",128); + client[i].Argv.in = fdopen( ns,"r"); + client[i].Argv.out = fdopen( ns,"w"); +#if !defined(PowerBBS) && !defined(DBZSERVER) + bbslog("connected from (%s@%s).\n",client[i].username, client[i].hostname); +#endif +#ifdef INNBBSDEBUG + printf("connected from (%s@%s).\n",client[i].username, client[i].hostname); +#endif +#ifdef DBZSERVER + fprintf(client[i].Argv.out,"200 %s InterNetNews DBZSERVER server %s (%s@%s).\r\n",MYBBSID, VERSION, client[i].username, client[i].hostname); +#else + fprintf(client[i].Argv.out,"200 %s InterNetNews INNBBSD server %s (%s@%s).\r\n", MYBBSID, VERSION, client[i].username, client[i].hostname ); +#endif + fflush(client[i].Argv.out); + verboselog("UNIX Connect from %s@%s\n",client[i].username, client[i].hostname); + } + } + + if (FD_ISSET(bbsinnd,&orfd)) { + int ns=tryaccept(bbsinnd), length; + struct sockaddr_in there; + char *name; + struct hostent *hp; + int cc; + if (ns < 0) continue; + for (i=0;i< Maxclient ;++i) { + if (client[i].fd==-1) break; + } + if (i== Maxclient) { + static char msg[]="502 no free descriptors\r\n"; + printf("%s",msg); + write(ns, msg, sizeof(msg)); + close(ns); + continue; + } + client[i].fd=ns; + client[i].buffer[0] = '\0'; + client[i].mode = 0; + client[i].midcheck = 1; + channelcreate(&client[i]); + FD_SET(ns,&rfd); /*FD_SET(ns,&wfd);*/ + length = sizeof(there); + if (getpeername(ns,(struct sockaddr *)&there,&length)>=0){ + time_t now=time((time_t *)0); + name=(char*)my_rfc931_name(ns,&there); + strncpy(client[i].username,name,20); + hp = (struct hostent*)gethostbyaddr((char*)&there.sin_addr, sizeof (struct in_addr), there.sin_family); + if (hp) + strncpy(client[i].hostname,hp->h_name,128); + else + strncpy(client[i].hostname,(char*)inet_ntoa(there.sin_addr),128); + + client[i].Argv.in = fdopen( ns,"r"); + client[i].Argv.out = fdopen( ns,"w"); + if ((char*)search_nodelist(client[i].hostname,client[i].username) == NULL) { + bbslog(":Err: invalid connection (%s@%s).\n",client[i].username, client[i].hostname); + fprintf(client[i].Argv.out,"502 You are not in my access file. (%s@%s)\r\n", client[i].username, client[i].hostname); + fflush(client[i].Argv.out); + fclose(client[i].Argv.in); + fclose(client[i].Argv.out); + close(client[i].fd); + FD_CLR(client[i].fd,&rfd); + client[i].fd = -1; + continue; + } + bbslog("connected from (%s@%s).\n",client[i].username, client[i].hostname); +#ifdef INNBBSDEBUG + printf("connected from (%s@%s).\n",client[i].username, client[i].hostname); +#endif +#ifdef DBZSERVER + fprintf(client[i].Argv.out,"200 %s InterNetNews DBZSERVER server %s (%s@%s).\r\n",MYBBSID, VERSION, client[i].username, client[i].hostname ); +#else + fprintf(client[i].Argv.out,"200 %s InterNetNews INNBBSD server %s (%s@%s).\r\n",MYBBSID, VERSION, client[i].username, client[i].hostname ); +#endif + fflush(client[i].Argv.out); + verboselog("INET Connect from %s@%s\n",client[i].username, client[i].hostname); + } else { + } + + } + for (i=0;i< Maxclient ;++i) { + int fd=client[i].fd; + if (fd < 0) { + continue; + } + if (FD_ISSET(fd,&orfd)) { + int nr; +#ifdef DEBUG + printf("before read i %d in.used %d in.left %d\n",i,client[i].in.used, client[i].in.left); +#endif + nr=channelreader(client+i); +#ifdef DEBUG + printf("after read i %d in.used %d in.left %d\n",i,client[i].in.used, client[i].in.left); +#endif + /*int nr=read(fd,client[i].buffer,1024);*/ + if (nr <= 0) { + FD_CLR(fd,&rfd); + fclose(client[i].Argv.in); + fclose(client[i].Argv.out); + close(fd); + client[i].fd = -1; + channeldestroy(client+i); + continue; + } +#ifdef DEBUG + printf("nr %d %.*s", nr, nr, client[i].buffer); +#endif + if (client[i].access==0) { + continue; + } + } + } + } +} + +int channelreader(client) +ClientType *client; +{ + int len, clientlen; + char buffer1[8192], buffer2[4096]; + char *ptr; + buffer_t *in = &client->in; + + if (in->left < ReadSize+3) { + int need = in->used + in->left + ReadSize + 3; + need += need/5 ; + in->data = (char*)myrealloc(in->data, need); + in->left = need - in->used; + verboselog("channelreader realloc %d\n",need); + } + len = read(client->fd, in->data+in->used, ReadSize); + + if (len <=0) return len; + + in->data[len+in->used] = '\0'; + in->lastread = len; +#ifdef DEBUG + printf("after read lastread %d\n", in->lastread); + printf("len %d client %d\n", len, strlen(in->data+in->used)); +#endif + + REMOTEHOSTNAME = client->hostname; + REMOTEUSERNAME = client->username; + if (client->mode == 0) { + if ( (ptr=(char*)strchr(in->data,'\n')) != NULL) { + if (in->data[0] != '\r') + commandparse(client); + } + } else { + commandparse(client); + } + return len; +} + +commandparse(client) +ClientType *client; +{ + char *ptr, *lastend; + argv_t *Argv = &client->Argv; + int (*Main)(); + char *buffer = client->in.data; + int fd = client->fd; + buffer_t *in = &client->in; + int dataused; + int dataleft; + +#ifdef DEBUG + printf("%s %s buffer %s",client->username, client->hostname, buffer); +#endif + ptr= (char*) strchr(in->data+in->used,'\n'); + if (client->mode == 0) { + if (ptr == NULL) { + in->used += in->lastread; + in->left -= in->lastread; + return; + } else { + dataused = ptr - (in->data + in->used) + 1; + dataleft = in->lastread - dataused; + lastend = ptr + 1; + } + } else { + if (in->used >= 5) { + ptr = (char*) strstr(in->data+in->used-5,"\r\n.\r\n"); + } else if (strncmp(in->data,".\r\n",3)==0) { + ptr = in->data; + } else { + ptr = (char*) strstr(in->data+in->used,"\r\n.\r\n"); + } + if (ptr == NULL) { + in->used += in->lastread; + in->left -= in->lastread; + return; + } else { + ptr[2]='\0'; + if ( strncmp(in->data,".\r\n",3)==0) + dataused = 3; + else + dataused = ptr - (in->data + in->used) + 5; + dataleft = in->lastread - dataused; + lastend = ptr + 5; + verboselog("Get: %s@%s end of data . size %d\n", client->username, client->hostname, in->used + dataused); + client->ihavesize += in->used + dataused; + } + } + if (client->mode == 0) { + struct Daemoncmd * dp; + Argv->argc = 0, Argv->argv = NULL, + Argv->inputline= buffer; + if ( ptr != NULL) *ptr = '\0'; + verboselog("Get: %s\n",Argv->inputline); + Argv->argc = argify( in->data + in->used,&Argv->argv); + if ( ptr != NULL) *ptr = '\n'; + dp = (struct Daemoncmd *) searchcmd(Argv->argv[0]); + Argv->dc = dp; + if (Argv->dc) { +#ifdef DEBUG + printf("enter command %s\n",Argv->argv[0]); +#endif + if (Argv->argc < dp->argc) { + fprintf(Argv->out,"%d Usage: %s\r\n",dp->errorcode,dp->usage); + fflush(Argv->out); + verboselog("Put: %d Usage: %s\n",dp->errorcode,dp->usage); + } else if (dp->argno != 0 && Argv->argc > dp->argno) { + fprintf(Argv->out,"%d Usage: %s\r\n",dp->errorcode,dp->usage); + fflush(Argv->out); + verboselog("Put: %d Usage: %s\n",dp->errorcode,dp->usage); + } else { + Main=Argv->dc->main; + if (Main) { + fflush(stdout); + (*Main)(client); + } + } + } else { + fprintf(Argv->out,"500 Syntax error or bad command\r\n"); + fflush(Argv->out); + verboselog("Put: 500 Syntax error or bad command\r\n"); + } + deargify(&Argv->argv); + } else { + if (Argv->dc) { +#ifdef DEBUG + printf("enter data mode\n"); +#endif + Main=Argv->dc->main; + if (Main) { + fflush(stdout); + (*Main)(client); + } + } + } + if (client->mode == 0) { + if (dataleft > 0) { + strncpy(in->data, lastend, dataleft); +#ifdef INNBBSDEBUG + printf("***** try to copy %x %x %d bytes\n",in->data, lastend, dataleft); +#endif + } else { + dataleft = 0; + } + in->left += in->used - dataleft; + in->used = dataleft; + } +} + +do_command() +{ +} + +void dopipesig(s) +int s; +{ + printf("catch sigpipe\n"); + signal(SIGPIPE, dopipesig); +} + +int standaloneinit(port) +char *port ; +{ + int ndescriptors; + FILE *pf; + char pidfile[24]; + ndescriptors = getdtablesize(); +/*#ifndef NOFORK*/ + if (!inetdstart) + if (fork()) + exit(0); +/*#endif*/ + + sprintf(pidfile,"/tmp/innbbsd-%s.pid",port); +/* Kaede + if (!inetdstart) + fprintf(stderr, "PID file is in %s\n", pidfile); +*/ + { int s; + for (s = 3; s < ndescriptors; s++) + (void) close(s); + } + pf=fopen(pidfile,"w"); + if (pf != NULL) { + fprintf(pf,"%d\n",getpid()); + fclose(pf); + } +} + +extern char *optarg; +extern int opterr, optind; + +innbbsusage(name) +char *name; +{ + fprintf(stderr,"Usage: %s [options] [port [path]]\n",name); + fprintf(stderr," -v (verbose log)\n"); + fprintf(stderr," -h|? (help)\n"); + fprintf(stderr," -n (not to use in core dbz)\n"); + fprintf(stderr," -i (start from inetd with wait option)\n"); + fprintf(stderr," -c connections (maximum number of connections accepted)\n"); + fprintf(stderr," default=%d\n",Maxclient); + fprintf(stderr," -j (keep history of junk article, default=none)\n"); +} + + +#ifdef DEBUGNGSPLIT +main() +{ + char **ngptr ; + char buf[1024]; + gets(buf); + ngptr = (char**)BNGsplit(buf); + printf("line %s\n",buf); + while ( *ngptr != NULL) { + printf("%s\n",*ngptr); + ngptr++; + } +} +#endif + +static time_t INNBBSDstartup; +innbbsdstartup() +{ + return INNBBSDstartup; +} + +main(argc,argv) +int argc; +char **argv; +{ + + char *port, *path; + int c, errflag=0; + extern INNBBSDhalt(); +/* +woju +*/ + setgid(BBSGID); + setuid(BBSUID); + chdir(BBSHOME); + resolve_boards(); + + port = DefaultINNBBSPort; + path = LOCALDAEMON; + Junkhistory = 0; + + time(&INNBBSDstartup); + openlog("innbbsd", LOG_PID | LOG_ODELAY, LOG_DAEMON); + while ((c = getopt(argc,argv,"c:f:s:vhidn?j"))!= -1) + switch (c) { + case 'j': + Junkhistory = 1; + break; + case 'v': + verboseon("innbbsd.log"); + break; + case 'n': + hisincore(0); + break; + case 'c': + Maxclient = atoi(optarg); + if (Maxclient < 0) Maxclient = 0; + break; + case 'i': { + struct sockaddr_in there; + int len = sizeof(there); + int rel; + if ((rel=getsockname(0,(struct sockaddr *)&there,&len))< 0){ + fprintf(stdout,"You must run -i from inetd with inetd.conf line: \n"); + fprintf(stdout,"service-port stream tcp wait bbs /home/bbs/innbbsd innbbsd -i port\n"); + fflush(stdout); + exit(5); + } + inetdstart = 1; + startfrominetd(1); + } + break; + case 'd': + dbzdebug(1); + break; + case 's': + Max_Art_Size = atol(optarg); + if (Max_Art_Size < 0) Max_Art_Size = 0; + break; + case 'h': + case '?': + default: + errflag ++; + } + if (errflag > 0) { + innbbsusage(argv[0]); + return(1); + } + if (argc - optind >= 1) { + port = argv[optind]; + } + if (argc - optind >= 2) { + path = argv[optind+1]; + } + + standaloneinit(port); + + initial_bbs("feed"); + +/* Kaede + if (!inetdstart) + fprintf(stderr, "Try to listen in port %s and path %s\n", port, path); +*/ + HISmaint(); + HISsetup(); + installinnbbsd(); + sethaltfunction(INNBBSDhalt); + + signal(SIGPIPE, dopipesig); + inndchannel(port, path); + HISclose(); +} diff --git a/pttbbs/innbbsd/inntobbs.c b/pttbbs/innbbsd/inntobbs.c new file mode 100644 index 00000000..b57d8bb1 --- /dev/null +++ b/pttbbs/innbbsd/inntobbs.c @@ -0,0 +1,323 @@ +#include +#include "daemon.h" +#include "bbslib.h" +#include + +#define INNTOBBS +#include "inntobbs.h" + +typedef struct Header { + char *name; + int id; +} header_t; + +/*enum HeaderValue { +SUBJECT_H, FROM_H, DATE_H, MID_H, NEWSGROUPS_H, +NNTPPOSTINGHOST_H, NNTPHOST_H, CONTROL_H, PATH_H, +ORGANIZATION_H, LASTHEADER, +}; +*/ + +char *strchr ARG((char*,int)); +char *strrchr ARG((char*,int)); +char *strstr ARG((char*,char*)); + +header_t headertable[] = { +"Subject" ,SUBJECT_H, +"From" ,FROM_H, +"Date" ,DATE_H, +"Message-ID",MID_H, +"Newsgroups",NEWSGROUPS_H, +"NNTP-Posting-Host",NNTPPOSTINGHOST_H, +"NNTP-Host", NNTPHOST_H, +"Control", CONTROL_H, +"Path", PATH_H, +"Organization", ORGANIZATION_H, +"X-Auth-From", X_Auth_From_H, +"Approved", APPROVED_H, +"Distribution", DISTRIBUTION_H, +"Keywords", KEYWORDS_H, +"Summary", SUMMARY_H, +"References",REFERENCES_H, +}; + +char *HEADER[LASTHEADER]; +char *BODY; +char *FROM, *SUBJECT, *SITE, *DATE, *POSTHOST, + *NNTPHOST, *PATH, *GROUPS, *MSGID, *CONTROL; + +#ifdef PalmBBS +char **XHEADER; +char *XPATH; +#endif + + +int +isexcluded(path1, nl) +char *path1; +nodelist_t *nl; +{ + char path2[1024]; + /*path2 = (char*)mymalloc(strlen(nl->node) + 3);*/ + sprintf(path2, "!%.*s!",sizeof path2 - 3, nl->node); + if (strstr(path1, path2) != NULL) return 1; + if (nl->exclusion && *nl->exclusion) { + char *exclude, *ptr; + for (exclude = nl->exclusion, ptr = strchr(exclude,','); + exclude && *exclude; ptr = strchr(exclude,',')) { + if (ptr) *ptr = '\0'; + sprintf(path2, "!%.*s!",sizeof path2 - 3, exclude); + if (strstr(path1, path2) != NULL) return 1; + if (ptr) { + *ptr = ','; + exclude = ptr+1; + } else { + break; + } + } + } + return 0; +} + +feedfplog(nf, filepath, type) +newsfeeds_t *nf; +char *filepath; +int type; +{ + char *path1, *path2, *hostptr; + nodelist_t *nl; + if (nf == NULL) return; + if( nf->path != NULL ) { + char *ptr1, *ptr2; + char savech; + path1 = (char*)mymalloc(strlen(HEADER[PATH_H]) + 3); + sprintf(path1, "!%s!",HEADER[PATH_H]); + for (ptr1 = nf->path; ptr1 && *ptr1;) { + for (; *ptr1 && isspace(*ptr1); ptr1++); + if (!*ptr1) break; + for (ptr2 = ptr1; *ptr2 && !isspace(*ptr2); ptr2++); + savech = *ptr2; + *ptr2 = '\0'; + /* + bbslog("search node %s\n",ptr1); + */ + nl = (nodelist_t*) search_nodelist_bynode(ptr1); + /* + bbslog("search node node %s, host %s fp %d\n",nl->node, nl->host, nl->feedfp); + */ + *ptr2 = savech; + ptr1 = ptr2++; + if (nl == NULL) continue; + if (nl->feedfp == NULL) continue; + if (isexcluded(path1,nl)) continue; + /*path2 = (char*)mymalloc(strlen(nl->node) + 3); + sprintf(path2, "!%s!",nl->node); + free(path2); + */ + /* + bbslog("path1 %s path2 %s\n",path1, path2); + */ + /*if (strstr(path1, path2) != NULL) return;*/ + /* to conform to the bntplink batch file */ + { + char *slash = strrchr(filepath,'/'); + if (slash != NULL) *slash = '\t'; + fprintf(nl->feedfp,"%s\t%s\t\t%s\t%s\t%c\t%s\t%s!%s\n", + filepath == NULL ? "": filepath, + GROUPS, FROM, SUBJECT, type, MSGID, MYBBSID, HEADER[PATH_H]); + if (slash != NULL) *slash = '/'; + } + fflush(nl->feedfp); + if (savech == '\0') break; + } + free(path1); + } +} + +static FILE* bbsfeedsfp = NULL; +static bbsfeedson = -1; + +init_bbsfeedsfp() +{ + if (bbsfeedsfp != NULL) { + fclose(bbsfeedsfp); + bbsfeedsfp = NULL; + } + bbsfeedson = -1; +} + +bbsfeedslog(filepath, type) +char *filepath; +int type; +{ + + char datebuf[40]; + time_t now; + + if (bbsfeedson ==0) return; + if (bbsfeedson == -1) { + if (!isfile(BBSFEEDS)) { + bbsfeedson = 0; + return; + } + bbsfeedson = 1; + } + + if (bbsfeedsfp == NULL) { + bbsfeedsfp = fopen(BBSFEEDS,"a"); + } + time(&now); + strftime(datebuf, sizeof(datebuf), "%b %d %X ", localtime(&now)); + + if( bbsfeedsfp != NULL ) { + fprintf(bbsfeedsfp,"%s %c %s %s %s %s!%s %s\n", datebuf, type, + REMOTEHOSTNAME, GROUPS, MSGID, MYBBSID, HEADER[PATH_H], filepath==NULL? "": filepath); + fflush(bbsfeedsfp); + } +} + +static FILE* echomailfp = NULL; +static echomaillogon = -1; + +init_echomailfp() +{ + if (echomailfp != NULL) { + fclose(echomailfp); + echomailfp = NULL; + } + echomaillogon = -1; +} + +echomaillog() +{ + + if (echomaillogon ==0) return; + if (echomaillogon == -1) { + if (!isfile(ECHOMAIL)) { + echomaillogon = 0; + return; + } + echomaillogon = 1; + } + + if (echomailfp == NULL) { + echomailfp = fopen(ECHOMAIL,"a"); + } + + if( echomailfp != NULL ) { + fprintf(echomailfp,"\n"); + fprintf(echomailfp,"發信人: %s, 信區: %s\n", FROM, GROUPS); + fprintf(echomailfp,"標 題: %s\n", SUBJECT); + fprintf(echomailfp,"發信站: %s (%s)\n", SITE, DATE); + fprintf(echomailfp,"轉信站: %s (%s)\n", PATH, REMOTEHOSTNAME); + fflush(echomailfp); + } +} + +int headercmp(a,b) +header_t *a, *b; +{ + return strcasecmp(a->name, b->name); +} + +int readlines(client) +ClientType *client; +{ + int fd = client->fd; + char *buffer = client->buffer; + buffer_t *in = &client->in; + char *front = in->data, *ptr, *hptr; + int i; + + for (i=0; i < LASTHEADER; i++ ) + HEADER[i] = NULL; + for (ptr = (char*)strchr(in->data,'\n'); ptr != NULL && *ptr != '\0' ; front = ptr+1, ptr = (char*)strchr(front,'\n')) { + *ptr = '\0'; + if (front[0] == '\r' || front[1] == '\n') { + BODY = front+2; + break; + } + hptr = (char*)strchr(front,':'); + if (hptr != NULL && hptr[1] == ' ') { + int value; + *hptr = '\0'; + value = headervalue(front); + if (value != -1) { + char *tp; + HEADER[value] = hptr + 2; + if ((tp = (char*)strchr(HEADER[value],'\r'))!=NULL) + *tp = '\0'; + } + *hptr = ':'; + } + /**ptr = '\n';*/ + } + NNTPHOST = HEADER[NNTPHOST_H]; + PATH = HEADER[PATH_H]; + FROM = HEADER[FROM_H]; + GROUPS = HEADER[NEWSGROUPS_H]; + SUBJECT = HEADER[SUBJECT_H]; + DATE = HEADER[DATE_H]; + SITE = HEADER[ORGANIZATION_H]; + MSGID = HEADER[MID_H]; + CONTROL = HEADER[CONTROL_H]; + POSTHOST = HEADER[NNTPPOSTINGHOST_H]; + if (POSTHOST == NULL) { + if (HEADER[X_Auth_From_H] != NULL) { + POSTHOST = HEADER[X_Auth_From_H]; + HEADER[NNTPPOSTINGHOST_H] = POSTHOST; + } + } +#ifdef PalmBBS + XPATH = PATH; + XHEADER = HEADER; +#endif +} + +int headervalue(inputheader) +char *inputheader; +{ + header_t key, *findkey; + static int hasinit=0; + + if (hasinit == 0) { + article_init(); + hasinit = 1; + } + + key.name = inputheader; + findkey = ( header_t *)bsearch ( + (char *) &key, (char *) headertable, + sizeof(headertable)/ sizeof(header_t), sizeof (key), + headercmp); + if (findkey != NULL) return findkey->id; + return -1; +} + +article_init() +{ + int i; + static int article_inited = 0; + + if (article_inited) return; + article_inited = 1; + + qsort(headertable, sizeof(headertable)/ sizeof(header_t), sizeof(header_t), + headercmp); + for (i=0; i < LASTHEADER; i++ ) + HEADER[i] = NULL; +} + +#ifdef INNTOBBS_MAIN +main() +{ + int i,j,k,l,m,n,o,p,q; + article_init(); + i = headervalue("Subject"); + j = headervalue("From"); + k = headervalue("Date"); + l = headervalue("NNTP-Posting-Host"); + m = headervalue("Newsgroups"); + n = headervalue("Message-ID"); +} +#endif diff --git a/pttbbs/innbbsd/inntobbs.h b/pttbbs/innbbsd/inntobbs.h new file mode 100644 index 00000000..1026e6d7 --- /dev/null +++ b/pttbbs/innbbsd/inntobbs.h @@ -0,0 +1,39 @@ +#ifndef INNTOBBS_H +#define INNTOBBS_H + +enum HeaderValue { +SUBJECT_H, FROM_H, DATE_H, MID_H, NEWSGROUPS_H, +NNTPPOSTINGHOST_H, NNTPHOST_H, CONTROL_H, PATH_H, +ORGANIZATION_H, X_Auth_From_H, APPROVED_H, DISTRIBUTION_H, +REFERENCES_H, KEYWORDS_H, SUMMARY_H, +LASTHEADER, +}; + +#if !defined(PalmBBS) +extern char *HEADER[]; +extern char *BODY; +extern char *FROM, *SUBJECT, *SITE, *DATE, *POSTHOST, + *NNTPHOST, *PATH, *GROUPS, *MSGID, *CONTROL; +extern char *REMOTEHOSTNAME, *REMOTEUSERNAME; +#else +extern char **XHEADER; +extern char *BODY; +extern char *FROM, *SUBJECT, *SITE, *DATE, *POSTHOST, + *NNTPHOST, *XPATH, *GROUPS, *MSGID, *CONTROL; +extern char *REMOTEHOSTNAME, *REMOTEUSERNAME; +#endif + +int receive_article(); + +#if defined(PalmBBS) +#ifndef INNTOBBS +#ifndef PATH +# define PATH XPATH +#endif +#ifndef HEADER +# define HEADER XHEADER +#endif +#endif +#endif + +#endif diff --git a/pttbbs/innbbsd/mkhistory.c b/pttbbs/innbbsd/mkhistory.c new file mode 100644 index 00000000..4be980ea --- /dev/null +++ b/pttbbs/innbbsd/mkhistory.c @@ -0,0 +1,14 @@ +#include "innbbsconf.h" +#include "bbslib.h" + +main(argc,argv) +int argc; +char *argv[]; +{ + if (argc < 2) { + fprintf(stderr,"Usage: %s history-file\n",argv[0]); + exit(1); + } + initial_bbs(NULL); + mkhistory(argv[1]); +} diff --git a/pttbbs/innbbsd/nntp.h b/pttbbs/innbbsd/nntp.h new file mode 100644 index 00000000..489f3502 --- /dev/null +++ b/pttbbs/innbbsd/nntp.h @@ -0,0 +1,145 @@ +/* $Revision: 1.1 $ +** +** Here be a set of NNTP response codes as defined in RFC977 and elsewhere. +** The reponse codes are three digits, RFI, defined like this: +** R, Response: +** 1xx Informative message +** 2xx Command ok +** 3xx Command ok so far, send the rest of it. +** 4xx Command was correct, but couldn't be performed for +** some reason. +** 5xx Command unimplemented, or incorrect, or a serious +** program error occurred. +** F, Function: +** x0x Connection, setup, and miscellaneous messages +** x1x Newsgroup selection +** x2x Article selection +** x3x Distribution functions +** x4x Posting +** x8x Nonstandard extensions (AUTHINFO, XGTITLE) +** x9x Debugging output +** I, Information: +** No defined semantics +*/ +#define NNTP_HELPOK_VAL 100 +#define NNTP_BAD_COMMAND_VAL 500 +#define NNTP_BAD_COMMAND "500 Syntax error or bad command" +#define NNTP_TEMPERR_VAL 503 +#define NNTP_ACCESS "502 Permission denied" +#define NNTP_ACCESS_VAL 502 +#define NNTP_GOODBYE_ACK "205" +#define NNTP_GOODBYE_ACK_VAL 205 +#define NNTP_GOODBYE "400" +#define NNTP_GOODBYE_VAL 400 +#define NNTP_HAVEIT "435 Duplicate" +#define NNTP_HAVEIT_BADID "435 Bad Message-ID" +#define NNTP_HAVEIT_VAL 435 +#define NNTP_LIST_FOLLOWS "215" +#define NNTP_LIST_FOLLOWS_VAL 215 +#define NNTP_HELP_FOLLOWS "100 Legal commands" +#define NNTP_HELP_FOLLOWS_VAL 100 +#define NNTP_NOTHING_FOLLOWS_VAL 223 +#define NNTP_ARTICLE_FOLLOWS "220" +#define NNTP_ARTICLE_FOLLOWS_VAL 220 +#define NNTP_NEWGROUPS_FOLLOWS_VAL 231 +#define NNTP_HEAD_FOLLOWS "221" +#define NNTP_HEAD_FOLLOWS_VAL 221 +#define NNTP_BODY_FOLLOWS_VAL 222 +#define NNTP_OVERVIEW_FOLLOWS_VAL 224 +#define NNTP_DATE_FOLLOWS_VAL 111 +#define NNTP_POSTOK "200" +#define NNTP_POSTOK_VAL 200 +#define NNTP_START_POST_VAL 340 +#define NNTP_NOPOSTOK_VAL 201 +#define NNTP_SLAVEOK_VAL 202 +#define NNTP_REJECTIT_VAL 437 +#define NNTP_REJECTIT_EMPTY "437 Empty article" +#define NNTP_DONTHAVEIT "430" +#define NNTP_DONTHAVEIT_VAL 430 +#define NNTP_RESENDIT_NOHIST "436 Can't write history" +#define NNTP_RESENDIT_NOSPACE "436 No space" +#define NNTP_RESENDIT_VAL 436 +#define NNTP_POSTEDOK "240 Article posted" +#define NNTP_POSTEDOK_VAL 240 +#define NNTP_POSTFAIL_VAL 441 +#define NNTP_GROUPOK_VAL 211 +#define NNTP_SENDIT "335" +#define NNTP_SENDIT_VAL 335 +#define NNTP_SYNTAX_USE "501 Bad command use" +#define NNTP_SYNTAX_VAL 501 +#define NNTP_TOOKIT "235" +#define NNTP_TOOKIT_VAL 235 +#define NNTP_NOTINGROUP "412 Not in a newsgroup" +#define NNTP_NOTINGROUP_VAL 412 +#define NNTP_NOSUCHGROUP "411 No such group" +#define NNTP_NOSUCHGROUP_VAL 411 +#define NNTP_NEWNEWSOK "230 New news follows" +#define NNTP_NOARTINGRP "423 Bad article number" +#define NNTP_NOARTINGRP_VAL 423 +#define NNTP_NOCURRART "420 No current article" +#define NNTP_NOCURRART_VAL 420 +#define NNTP_NONEXT_VAL 421 +#define NNTP_NOPREV_VAL 422 +#define NNTP_CANTPOST "440 Posting not allowed" +#define NNTP_CANTPOST_VAL 440 + + +/* +** The first character of an NNTP reply can be used as a category class. +*/ +#define NNTP_CLASS_OK '2' +#define NNTP_CLASS_ERROR '4' +#define NNTP_CLASS_FATAL '5' + + +/* +** The NNTP protocol currently has no way to say "offer me this article +** later, but don't close the connection." That will be fixed in NNTP2. +#define NNTP_RESENDIT_LATER "?" +#define NNTP_RESENDIT_LATER_VAL ? +*/ + + +/* +** Authentication commands from the RFC update (not official). +*/ +#define NNTP_AUTH_NEEDED "480" +#define NNTP_AUTH_NEEDED_VAL 480 +#define NNTP_AUTH_BAD "481" +#define NNTP_AUTH_NEXT "381" +#define NNTP_AUTH_NEXT_VAL 381 +#define NNTP_AUTH_OK "281" +#define NNTP_AUTH_OK_VAL 281 +#define NNTP_AUTH_REJECT_VAL 482 + +/* +** XGTITLE, from ANU news. +*/ +#define NNTP_XGTITLE_BAD 481 /* Yes, 481. */ +#define NNTP_XGTITLE_OK 282 + +#define NNTP_STRLEN 512 + +/* +** For tin newsreader +*/ +#define OK_XINDEX 218 /* Tin style group index file follows */ +#define OK_XMOTD 217 /* Motd (message of the day) file follows */ +#define ERR_XINDEX 418 /* No tin style index file for newsgroup */ +#define ERR_XMOTD 417 /* No motd (message of the day) file */ + +/* For DBZ server */ +#define NNTP_ADDHIST_OK 283 /* addhist OK */ +#define NNTP_GREPHIST_OK 284 /* grephist OK */ +#define NNTP_MIDCHECK_OK 285 /* grephist OK */ +#define NNTP_SHUTDOWN_OK 286 /* grephist OK */ +#define NNTP_RELOAD_OK 287 /* grephist OK */ +#define NNTP_MODE_OK 101 /* grephist OK */ +#define NNTP_VERBOSELOG_OK 289 /* grephist OK */ +#define NNTP_ADDHIST_BAD 483 /* addhist fail */ +#define NNTP_GREPHIST_BAD 484 /* grephist fail */ +#define NNTP_MIDCHECK_BAD 485 /* grephist fail */ +#define NNTP_SHUTDOWN_BAD 486 /* grephist fail */ +#define NNTP_RELOAD_BAD 487 /* grephist fail */ +#define NNTP_MODE_BAD 488 /* grephist fail */ +#define NNTP_VERBOSELOG_BAD 489 /* grephist fail */ diff --git a/pttbbs/innbbsd/pmain.c b/pttbbs/innbbsd/pmain.c new file mode 100644 index 00000000..39ddba22 --- /dev/null +++ b/pttbbs/innbbsd/pmain.c @@ -0,0 +1,62 @@ +#include "innbbsconf.h" +#include "daemon.h" + +/*char *AccessFile=ACCESSFILE;*/ +#define INNBBSDPORT1 "1904" +#define INNBBSDPORT2 "1234" +#define INNBBSDPATH1 ".innbbsd1" +#define INNBBSDPATH2 ".innbbsd2" + +pmain(port) +char *port; +{ + if (port == NULL) { + int rel; +/* installbbstalkd(); */ + fprintf(stderr,"Trying to listen in port %s\n",INNBBSDPORT1); + rel = open_listen(INNBBSDPORT1,"tcp",NULL); +#ifdef DEBUG + printf("port fd %d allocated\n",rel); +#endif + if (rel<0) { + fprintf(stderr,"Trying to listen in port %s\n",INNBBSDPORT2); + return open_listen(INNBBSDPORT2,"tcp",NULL); + } + return rel; + } else { +#ifdef DEBUG + printf("start to allocate port\n"); +#endif + return open_listen(port,"tcp",NULL); + } +} + +p_unix_main(path) +char *path; +{ + if (path == NULL) { + int rel; +/* installbbstalkd(); */ + fprintf(stderr,"Trying to listen in port %s\n",INNBBSDPATH1); + rel = open_unix_listen(INNBBSDPATH1,"tcp",NULL); +#ifdef DEBUG + printf("port fd %d allocated\n",rel); +#endif + if (rel<0) { + fprintf(stderr,"Trying to listen in port %s\n",INNBBSDPATH2); + return open_listen(INNBBSDPATH2,"tcp",NULL); + } + return rel; + } else { +#ifdef DEBUG + printf("start to allocate path %s\n", path); +#endif + int fd = unixclient(path,"tcp"); + if (fd < 0) + unlink(path); + else + close(fd); + return open_unix_listen(path,"tcp",NULL); + } +} + diff --git a/pttbbs/innbbsd/port.c b/pttbbs/innbbsd/port.c new file mode 100644 index 00000000..65e91fa4 --- /dev/null +++ b/pttbbs/innbbsd/port.c @@ -0,0 +1,28 @@ +#include "innbbsconf.h" + +#ifdef NO_getdtablesize +#include +#include +getdtablesize() +{ + struct rlimit limit; + if (getrlimit(RLIMIT_NOFILE, &limit) >= 0){ + return limit.rlim_cur; + } + return -1; +} +#endif + +#if defined(SYSV) && !defined(WITH_RECORD_O) +#include +flock(fd, op) +int fd,op; +{ + switch (op) { + case LOCK_EX: op = F_LOCK; break; + case LOCK_UN: op = F_ULOCK; break; + default: return -1; + } + return lockf(fd, op, 0L); +} +#endif diff --git a/pttbbs/innbbsd/receive_article.c b/pttbbs/innbbsd/receive_article.c new file mode 100644 index 00000000..40f2609c --- /dev/null +++ b/pttbbs/innbbsd/receive_article.c @@ -0,0 +1,1204 @@ +/* + * BBS implementation dependendent part + * + * The only two interfaces you must provide + * + * #include "inntobbs.h" int receive_article(); 0 success not 0 fail + * + * if (storeDB(HEADER[MID_H], hispaths) < 0) { .... fail } + * + * int cancel_article_front( char *msgid ); 0 success not 0 fail + * + * char *ptr = (char*)DBfetch(msgid); + * + * 收到之文章內容 (body)在 char *BODY, 檔頭 (header)在 char *HEADER[] SUBJECT_H, + * FROM_H, DATE_H, MID_H, NEWSGROUPS_H, NNTPPOSTINGHOST_H, NNTPHOST_H, + * CONTROL_H, PATH_H, ORGANIZATION_H + */ + +/* + * Sample Implementation + * + * receive_article() --> post_article() --> bbspost_write_post(); + * cacnel_article_front(mid) --> cancel_article() --> bbspost_write_cancel(); + */ + + +#ifndef PowerBBS +#include "innbbsconf.h" +#include "daemon.h" +#include "bbslib.h" +#include "inntobbs.h" +#include "antisplam.h" + +extern int Junkhistory; + +char *post_article ARG((char *, char *, char *, int (*) (), char *, char *)); +int cancel_article ARG((char *, char *, char *)); + + +#ifdef MapleBBS +#include "config.h" +#include "pttstruct.h" +#define _BBS_UTIL_C_ +#else +report() +{ + /* Function called from record.o */ + /* Please leave this function empty */ +} +#endif + + +#if defined(PalmBBS) + +#ifndef PATH +# define PATH XPATH +#endif + +#ifndef HEADER +# define HEADER XHEADER +#endif + +#endif + +/* process post write */ +bbspost_write_post(fh, board, filename) + int fh; + char *board; + char *filename; +{ + char *fptr, *ptr; + FILE *fhfd = fdopen(fh, "w"); + + if (fhfd == NULL) + { + bbslog("can't fdopen, maybe disk full\n"); + return -1; + } + + fprintf(fhfd, "發信人: %.60s, 看板: %s\n", FROM, board); + fprintf(fhfd, "標 題: %.70s\n", SUBJECT); + fprintf(fhfd, "發信站: %.43s (%s)\n", SITE, DATE); + fprintf(fhfd, "轉信站: %.70s\n", PATH); + +#ifndef MapleBBS + if (POSTHOST != NULL) + { + fprintf(fhfd, "Origin: %.70s\n", POSTHOST); + } +#endif + + fprintf(fhfd, "\n"); + for (fptr = BODY, ptr = strchr(fptr, '\r'); ptr != NULL && *ptr != '\0'; fptr = ptr + 1, ptr = strchr(fptr, '\r')) + { + int ch = *ptr; + *ptr = '\0'; + fputs(fptr, fhfd); + *ptr = ch; + } + fputs(fptr, fhfd); + + fflush(fhfd); + fclose(fhfd); + return 0; +} + +#ifdef KEEP_NETWORK_CANCEL +/* process cancel write */ +bbspost_write_cancel(fh, board, filename) + int fh; + char *board, *filename; +{ + char *fptr, *ptr; + FILE *fhfd = fdopen(fh, "w"), *fp; + char buffer[256]; + + if (fhfd == NULL) + { + bbslog("can't fdopen, maybe disk full\n"); + return -1; + } + + fprintf(fhfd, "發信人: %s, 信區: %s\n", FROM, board); + fprintf(fhfd, "標 題: %s\n", SUBJECT); + fprintf(fhfd, "發信站: %.43s (%s)\n", SITE, DATE); + fprintf(fhfd, "轉信站: %.70s\n", PATH); + if (HEADER[CONTROL_H] != NULL) + { + fprintf(fhfd, "Control: %s\n", HEADER[CONTROL_H]); + } + if (POSTHOST != NULL) + { + fprintf(fhfd, "Origin: %s\n", POSTHOST); + } + fprintf(fhfd, "\n"); + for (fptr = BODY, ptr = strchr(fptr, '\r'); ptr != NULL && *ptr != '\0'; fptr = ptr + 1, ptr = strchr(fptr, '\r')) + { + int ch = *ptr; + *ptr = '\0'; + fputs(fptr, fhfd); + *ptr = ch; + } + fputs(fptr, fhfd); + if (POSTHOST != NULL) + { + fprintf(fhfd, "\n * Origin: ● %.26s ● From: %.40s\n", SITE, POSTHOST); + } + fprintf(fhfd, "\n---------------------\n"); + fp = fopen(filename, "r"); + if (fp == NULL) + { + bbslog("can't open %s\n", filename); + return -1; + } + while (fgets(buffer, sizeof buffer, fp) != NULL) + { + fputs(buffer, fhfd); + } + fclose(fp); + fflush(fhfd); + fclose(fhfd); + + { + fp = fopen(filename, "w"); + if (fp == NULL) + { + bbslog("can't write %s\n", filename); + return -1; + } + fprintf(fp, "發信人: %s, 信區: %s\n", FROM, board); + fprintf(fp, "標 題: %.70s\n", SUBJECT); + fprintf(fp, "發信站: %.43s (%s)\n", SITE, DATE); + fprintf(fp, "轉信站: %.70s\n", PATH); + if (POSTHOST != NULL) + { + fprintf(fhfd, "Origin: %s\n", POSTHOST); + } + if (HEADER[CONTROL_H] != NULL) + { + fprintf(fhfd, "Control: %s\n", HEADER[CONTROL_H]); + } + fprintf(fp, "\n"); + for (fptr = BODY, ptr = strchr(fptr, '\r'); ptr != NULL && *ptr != '\0'; fptr = ptr + 1, ptr = strchr(fptr, '\r')) + { + *ptr = '\0'; + fputs(fptr, fp); + } + fputs(fptr, fp); + if (POSTHOST != NULL) + { + fprintf(fp, "\n * Origin: ● %.26s ● From: %.40s\n", SITE, POSTHOST); + } + fclose(fp); + } + return 0; +} +#endif + + +bbspost_write_control(fh, board, filename) + int fh; + char *board; + char *filename; +{ + char *fptr, *ptr; + FILE *fhfd = fdopen(fh, "w"); + + if (fhfd == NULL) + { + bbslog("can't fdopen, maybe disk full\n"); + return -1; + } + + fprintf(fhfd, "Path: %s!%s\n", MYBBSID, HEADER[PATH_H]); + fprintf(fhfd, "From: %s\n", FROM); + fprintf(fhfd, "Newsgroups: %s\n", GROUPS); + fprintf(fhfd, "Subject: %s\n", SUBJECT); + fprintf(fhfd, "Date: %s\n", DATE); + fprintf(fhfd, "Organization: %s\n", SITE); + if (POSTHOST != NULL) + { + fprintf(fhfd, "NNTP-Posting-Host: %.70s\n", POSTHOST); + } + if (HEADER[CONTROL_H] != NULL) + { + fprintf(fhfd, "Control: %s\n", HEADER[CONTROL_H]); + } + if (HEADER[APPROVED_H] != NULL) + { + fprintf(fhfd, "Approved: %s\n", HEADER[APPROVED_H]); + } + if (HEADER[DISTRIBUTION_H] != NULL) + { + fprintf(fhfd, "Distribution: %s\n", HEADER[DISTRIBUTION_H]); + } + fprintf(fhfd, "\n"); + for (fptr = BODY, ptr = strchr(fptr, '\r'); ptr != NULL && *ptr != '\0'; fptr = ptr + 1, ptr = strchr(fptr, '\r')) + { + int ch = *ptr; + *ptr = '\0'; + fputs(fptr, fhfd); + *ptr = ch; + } + fputs(fptr, fhfd); + + + fflush(fhfd); + fclose(fhfd); + return 0; +} + + +time_t datevalue; + + +/* process cancel write */ +receive_article() +{ + int i; + char *user, *userptr; + char *ngptr, *nngptr, *pathptr; + char **splitptr; + static char userid[32]; + static char xdate[32]; + static char xpath[180]; + newsfeeds_t *nf; + char *boardhome; + char hispaths[4096]; + char firstpath[MAXPATHLEN], *firstpathbase; + char *lesssym, *nameptrleft, *nameptrright; + static char sitebuf[80]; + +#ifdef HMM_USE_ANTI_SPAM + char *notitle[] = + {"行銷", "業務代表", "徵", "資訊", "免費", "大贈送", "傳銷", "未滿", + "年費", "傳呼", "價", "操你媽", "未成年", "馬賽克", "信用", "賺錢", + "=?", "!!!", + "操你", "操你", "幹妳", "操妳","**","★★","**","$$","泡麵", NULL}, + *nofrom[] = + {"TaipeiNet.Net", "hotmail.com", "mt.touc.edu.tw", "ms11.hinet.net", NULL}, + *nocont[] = + {"名額有限", "優惠價", "動作要快", "訂購", "特價", "專賣", "BBC", + "幹你", "操你", "幹妳", "操妳","每片","最新目錄", "http://", "收錢", + "創業", "付款", "廣告信", "只賣", "市價", "NCg", "ICAg", NULL}; +#endif + + if (FROM == NULL) + { + bbslog(":Err: article without usrid %s\n", MSGID); + return 0; + } + else + { +#ifdef HMM_USE_ANTI_SPAM + for(i=0; nofrom[i]; i++) + if(strstr(FROM, nofrom[i])) + { + morelog_to(INNBBSD_SPAM, "spam from [%s]: %s\n", nofrom[i], FROM); + morelog_to(INNBBSD_SPAM, " %s %s %s %s\n", FROM, PATH, GROUPS, SUBJECT); + bbslog(":Ptt: spam from [%s]: %s\n", nofrom[i], FROM); + return 0; + } +#endif + } + + if(!BODY) + { + bbslog(":Err: article without body %s\n", MSGID); + return 0; + } + else + { +#ifdef HMM_USE_ANTI_SPAM + for(i=0; nocont[i]; i++) + if(strstr(BODY, nocont[i])) + { + morelog_to(INNBBSD_SPAM, "spam body [%s]: %s\n", nocont[i]); + morelog_to(INNBBSD_SPAM, " %s %s %s %s\n", FROM, PATH, GROUPS, SUBJECT); + bbslog(":Ptt: spam body [%s]: %s\n", nocont[i]); + return 0; + } +#endif + } + + if(!SUBJECT) + { + bbslog(":Err: article without subject %s\n", MSGID); + return 0; + } + else + { +#ifdef HMM_USE_ANTI_SPAM + for(i=0; notitle[i]; i++) + if(strstr(SUBJECT, notitle[i])) + { + morelog_to(INNBBSD_SPAM, "spam title [%s]: %s\n", notitle[i], SUBJECT); + morelog_to(INNBBSD_SPAM, " %s %s %s %s\n", FROM, PATH, GROUPS, SUBJECT); + bbslog(":Ptt: spam title [%s]: %s\n", notitle[i], SUBJECT); + return 0; + } +#endif + } + + + user = (char *) strchr(FROM, '@'); + lesssym = (char *) strchr(FROM, '<'); + nameptrleft = NULL, nameptrright = NULL; + if (lesssym == NULL || lesssym >= user) + { + lesssym = FROM; + nameptrleft = strchr(FROM, '('); + if (nameptrleft != NULL) + nameptrleft++; + nameptrright = strrchr(FROM, ')'); + } + else + { + nameptrleft = FROM; + nameptrright = strrchr(FROM, '<'); + lesssym++; + } + if (user != NULL) + { + *user = '\0'; + userptr = (char *) strchr(FROM, '.'); + if (userptr != NULL) + { + *userptr = '\0'; + strncpy(userid, lesssym, sizeof userid); + *userptr = '.'; + } + else + { + strncpy(userid, lesssym, sizeof userid); + } + *user = '@'; + } + else + { + strncpy(userid, lesssym, sizeof userid); + } + strcat(userid, "."); + + { + struct tm tmbuf; + + strptime(DATE, "%d %b %Y %X GMT", &tmbuf); + datevalue = timegm(&tmbuf); + } + + if (datevalue > 0) + { + char *p; + strncpy(xdate, ctime(&datevalue), sizeof(xdate)); + p = (char *) strchr(xdate, '\n'); + if (p != NULL) + *p = '\0'; + DATE = xdate; + } + +#ifndef MapleBBS + if (SITE == NULL || *SITE == '\0') + { + if (nameptrleft != NULL && nameptrright != NULL) + { + char savech = *nameptrright; + *nameptrright = '\0'; + strncpy(sitebuf, nameptrleft, sizeof sitebuf); + *nameptrright = savech; + SITE = sitebuf; + } + else + /* SITE = "(Unknown)"; */ + SITE = ""; + } + if (strlen(MYBBSID) > 70) + { + bbslog(" :Err: your bbsid %s too long\n", MYBBSID); + return 0; + } +#endif + + sprintf(xpath, "%s!%.*s", MYBBSID, sizeof(xpath) - strlen(MYBBSID) - 2, PATH); + PATH = xpath; + for (pathptr = PATH; pathptr != NULL && (pathptr = strstr(pathptr, ".edu.tw")) != NULL;) + { + if (pathptr != NULL) + { + strcpy(pathptr, pathptr + 7); + } + } + xpath[71] = '\0'; + +#ifndef MapleBBS + echomaillog(); +#endif + + *hispaths = '\0'; + splitptr = (char **) BNGsplit(GROUPS); + firstpath[0] = '\0'; + firstpathbase = firstpath; + + for (ngptr = *splitptr; ngptr != NULL; ngptr = *(++splitptr)) + { + char *boardptr, *nboardptr; + + if (*ngptr == '\0') + continue; + nf = (newsfeeds_t *) search_group(ngptr); + if (nf == NULL) + { + bbslog("unwanted \'%s\'\n", ngptr); + continue; + } + if (nf->board == NULL || !*nf->board) + continue; + if (nf->path == NULL || !*nf->path) + continue; + for (boardptr = nf->board, nboardptr = (char *) strchr(boardptr, ','); boardptr != NULL && *boardptr != '\0'; nboardptr = (char *) strchr(boardptr, ',')) + { + if (nboardptr != NULL) + { + *nboardptr = '\0'; + } + if (*boardptr == '\t') + { + goto boardcont; + } + boardhome = (char *) fileglue("%s/boards/%s", BBSHOME, boardptr); + if (!isdir(boardhome)) + { + bbslog(":Err: unable to write %s\n", boardhome); + } + else + { + char *fname; + /* + * if ( !isdir( boardhome )) { bbslog( ":Err: unable to write + * %s\n",boardhome); testandmkdir(boardhome); } + */ + fname = (char *) post_article(boardhome, userid, boardptr, + bbspost_write_post, NULL, firstpath); + if (fname != NULL) + { + fname = (char *) fileglue("%s/%s", boardptr, fname); + if (firstpath[0] == '\0') + { + sprintf(firstpath, "%s/boards/%s", BBSHOME, fname); + firstpathbase = firstpath + strlen(BBSHOME) + strlen("/boards/"); + } + if (strlen(fname) + strlen(hispaths) + 1 < sizeof(hispaths)) + { + strcat(hispaths, fname); + strcat(hispaths, " "); + } + } + else + { + bbslog("fname is null %s\n", boardhome); + return -1; + } + } + + boardcont: + if (nboardptr != NULL) + { + *nboardptr = ','; + boardptr = nboardptr + 1; + } + else + break; + + } /* for board1,board2,... */ + /* + * if (nngptr != NULL) ngptr = nngptr + 1; else break; + */ + if (*firstpathbase) + feedfplog(nf, firstpathbase, 'P'); + } + if (*hispaths) + bbsfeedslog(hispaths, 'P'); + + if (Junkhistory || *hispaths) + { + if (storeDB(HEADER[MID_H], hispaths) < 0) + { + bbslog("store DB fail\n"); + /* I suspect here will introduce duplicated articles */ + /* return -1; */ + } + } + return 0; +} + +receive_control() +{ + char *boardhome, *fname; + char firstpath[MAXPATHLEN], *firstpathbase; + char **splitptr, *ngptr; + newsfeeds_t *nf; + + bbslog("control post %s\n", HEADER[CONTROL_H]); + boardhome = (char *) fileglue("%s/boards/control", BBSHOME); + testandmkdir(boardhome); + *firstpath = '\0'; + if (isdir(boardhome)) + { + fname = (char *) post_article(boardhome, FROM, "control", bbspost_write_control, NULL, firstpath); + if (fname != NULL) + { + if (firstpath[0] == '\0') + sprintf(firstpath, "%s/boards/control/%s", BBSHOME, fname); + if (storeDB(HEADER[MID_H], (char *) fileglue("control/%s", fname)) < 0) + { + } + bbsfeedslog(fileglue("control/%s", fname), 'C'); + firstpathbase = firstpath + strlen(BBSHOME) + strlen("/boards/"); + splitptr = (char **) BNGsplit(GROUPS); + for (ngptr = *splitptr; ngptr != NULL; ngptr = *(++splitptr)) + { + if (*ngptr == '\0') + continue; + nf = (newsfeeds_t *) search_group(ngptr); + if (nf == NULL) + continue; + if (nf->board == NULL) + continue; + if (nf->path == NULL) + continue; + feedfplog(nf, firstpathbase, 'C'); + } + } + } + return 0; +} + +cancel_article_front(msgid) + char *msgid; +{ + char *ptr = (char *) DBfetch(msgid); + char *filelist, filename[2048]; + char histent[4096]; + char firstpath[MAXPATHLEN], *firstpathbase; + if (ptr == NULL) + { + bbslog("cancel failed(DBfetch): %s\n", msgid); + return 0; + } + strncpy(histent, ptr, sizeof histent); + ptr = histent; + +#ifdef DEBUG + printf("**** try to cancel %s *****\n", ptr); +#endif + + filelist = strchr(ptr, '\t'); + if (filelist != NULL) + { + filelist++; + } + *firstpath = '\0'; + for (ptr = filelist; ptr && *ptr;) + { + char *file; + for (; *ptr && isspace(*ptr); ptr++); + if (*ptr == '\0') + break; + file = ptr; + for (ptr++; *ptr && !isspace(*ptr); ptr++); + if (*ptr != '\0') + { + *ptr++ = '\0'; + } + sprintf(filename, "%s/boards/%s", BBSHOME, file); + bbslog("cancel post %s\n", filename); + if (isfile(filename)) + { + FILE *fp = fopen(filename, "r"); + char buffer[1024]; + char xfrom0[100], xfrom[100], xpath[1024], *boardhome; + + if (fp == NULL) + continue; + strncpy(xfrom0, HEADER[FROM_H], 99); + xfrom0[99] = 0; + strtok(xfrom0, ", "); + while (fgets(buffer, sizeof buffer, fp) != NULL) + { + char *hptr; + if (buffer[0] == '\n') + break; + hptr = strchr(buffer, '\n'); + if (hptr != NULL) + *hptr = '\0'; + if (strncmp(buffer, "發信人: ", 8) == 0) + { + strncpy(xfrom, buffer + 8, 99); + xfrom[99] = 0; + strtok(xfrom, ", "); + } + else if (strncmp(buffer, "轉信站: ", 8) == 0) + { + strcpy(xpath, buffer + 8); + } + } + fclose(fp); + if (strcmp(xfrom0, xfrom)) + { + bbslog("Invalid cancel %s, path: %s!%s, [`%s` != `%s`]\n", + FROM, MYBBSID, PATH, xfrom0, xfrom); + return 0; + } + +#ifdef KEEP_NETWORK_CANCEL + bbslog("cancel post %s\n", filename); + boardhome = (char *) fileglue("%s/boards/deleted", BBSHOME); + testandmkdir(boardhome); + if (isdir(boardhome)) + { + char subject[1024]; + char *fname; + if (POSTHOST) + { + sprintf(subject, "cancel by: %.1000s", POSTHOST); + } + else + { + char *body, *body2; + body = strchr(BODY, '\r'); + if (body != NULL) + *body = '\0'; + body2 = strchr(BODY, '\n'); + if (body2 != NULL) + *body = '\0'; + sprintf(subject, "%.1000s", BODY); + if (body != NULL) + *body = '\r'; + if (body2 != NULL) + *body = '\n'; + } + if (*subject) + SUBJECT = subject; + fname = (char *) post_article(boardhome, FROM, "deleted", bbspost_write_cancel, filename, firstpath); + if (fname != NULL) + { + if (firstpath[0] == '\0') + { + sprintf(firstpath, "%s/boards/deleted/%s", BBSHOME, fname); + firstpathbase = firstpath + strlen(BBSHOME) + strlen("/boards/"); + } + if (storeDB(HEADER[MID_H], (char *) fileglue("deleted/%s", fname)) < 0) + { + /* should do something */ + bbslog("store DB fail\n"); + /* return -1; */ + } + bbsfeedslog(fileglue("deleted/%s", fname), 'D'); + +#ifdef OLDDISPATCH + { + char board[256]; + newsfeeds_t *nf; + char *filebase = filename + strlen(BBSHOME) + strlen("/boards/"); + char *filetail = strrchr(filename, '/'); + if (filetail != NULL) + { + strncpy(board, filebase, filetail - filebase); + nf = (newsfeeds_t *) search_board(board); + if (nf != NULL && nf->board && nf->path) + { + feedfplog(nf, firstpathbase, 'D'); + } + } + } +#endif + } + else + { + bbslog(" fname is null %s %s\n", boardhome, filename); + return -1; + } + } +#else + /* bbslog("**** %s should be removed\n", filename); */ +/* + unlink(filename); +*/ +#endif + + { + char *fp = strrchr(file, '/'); + if (fp != NULL) + { + *fp = '\0'; + cancel_article(BBSHOME, file, fp + 1); + *fp = '/'; + } + } + } + } + if (*firstpath) + { + char **splitptr, *ngptr; + newsfeeds_t *nf; + splitptr = (char **) BNGsplit(GROUPS); + for (ngptr = *splitptr; ngptr != NULL; ngptr = *(++splitptr)) + { + if (*ngptr == '\0') + continue; + nf = (newsfeeds_t *) search_group(ngptr); + if (nf == NULL) + continue; + if (nf->board == NULL) + continue; + if (nf->path == NULL) + continue; + feedfplog(nf, firstpathbase, 'D'); + } + } + return 0; +} + + +#if defined(PhoenixBBS) || defined(SecretBBS) || defined(PivotBBS) || defined(MapleBBS) +/* for PhoenixBBS's post article and cancel article */ +#include "config.h" + + +char * +post_article(homepath, userid, board, writebody, pathname, firstpath) + char *homepath; + char *userid, *board; + int (*writebody) (); +char *pathname, *firstpath; +{ + struct userec_t record; + struct fileheader_t header; + char *subject = SUBJECT; + char index[MAXPATHLEN]; + static char name[MAXPATHLEN]; + char article[MAXPATHLEN]; + char buf[MAXPATHLEN], *ptr; + FILE *fidx; + int fh, bid; + time_t now; + int linkflag; +/* Ptt + if(bad_subject(subject)) return NULL; +*/ + sprintf(index, "%s/.DIR", homepath); + if ((fidx = fopen(index, "r")) == NULL) + { + if ((fidx = fopen(index, "w")) == NULL) + { + bbslog(":Err: Unable to post in %s.\n", homepath); + return NULL; + } + } + fclose(fidx); + + now = time(NULL); + while (1) + { + sprintf(name, "M.%d.A", ++now); + sprintf(article, "%s/%s", homepath, name); + fh = open(article, O_CREAT | O_EXCL | O_WRONLY, 0644); + if (fh >= 0) + break; + if (errno != EEXIST) + { + bbslog(" Err: can't writable or other errors\n"); + return NULL; + } + } + +#ifdef DEBUG + printf("post to %s\n", article); +#endif + + linkflag = 1; + if (firstpath && *firstpath) + { + close(fh); + unlink(article); + +#ifdef DEBUGLINK + bbslog("try to link %s to %s", firstpath, article); +#endif + + linkflag = link(firstpath, article); + if (linkflag) + { + fh = open(article, O_CREAT | O_EXCL | O_WRONLY, 0644); + } + } + if (linkflag) + { + if (writebody) + { + if ((*writebody) (fh, board, pathname) < 0) + return NULL; + } + else + { + if (bbspost_write_post(fh, board, pathname) < 0) + return NULL; + } + close(fh); + } + + bzero((void *) &header, sizeof(header)); + +#ifndef MapleBBS + strcpy(header.filename, name); + strncpy(header.owner, userid, IDLEN); + strncpy(header.title, subject, STRLEN); + header.filename[STRLEN - 1] = 'M'; +#else + + strcpy(header.filename, name); + if (userid[IDLEN]) + strcpy(&userid[IDLEN], "."); + strcpy(header.owner, userid); + strncpy(header.title, subject, TTLEN); + header.savemode = 'M'; + { + struct tm *ptime; + ptime = localtime(&datevalue); + sprintf(header.date, "%2d/%02d", ptime->tm_mon + 1, ptime->tm_mday); + } +#endif + + append_record(index, &header, sizeof(header)); + + if((bid = getbnum(board)) > 0) + touchbtotal(bid); + return name; +} + +/* +woju +Cross-fs rename() +*/ + +Rename(char* src, char* dst) +{ + char cmd[200]; + + bbslog("Rename: %s -> %s\n", src, dst); + if (rename(src, dst) == 0) + return 0; + + sprintf(cmd, "/bin/mv %s %s", src, dst); + return system(cmd); +} + + +cancelpost(fileheader_t *fhdr, char* boardname) +{ + int fd; + char fpath[MAXPATHLEN]; + + sprintf(fpath, BBSHOME "/boards/%s/%s", boardname, fhdr->filename); + if ((fd = open(fpath, O_RDONLY)) >= 0) { + fileheader_t postfile; + char fn2[MAXPATHLEN] = BBSHOME "/boards/deleted", *junkdir; + + stampfile(fn2, &postfile); + memcpy(postfile.owner, fhdr->owner, IDLEN + TTLEN + 10); + postfile.savemode = 'D'; + close(fd); + Rename(fpath, fn2); + strcpy(strrchr(fn2, '/') + 1, ".DIR"); + append_record(fn2, &postfile, sizeof(postfile)); + } + else + bbslog("cancelpost: %s opened error\n", fpath); +} + + +/* ---------------------------- */ +/* new/old/lock file processing */ +/* ---------------------------- */ + +typedef struct +{ + char newfn[MAXPATHLEN]; + char oldfn[MAXPATHLEN]; + char lockfn[MAXPATHLEN]; +} nol; + + +static void +nolfilename(n, fpath) + nol *n; + char *fpath; +{ + sprintf(n->newfn, "%s.new", fpath); + sprintf(n->oldfn, "%s.old", fpath); + sprintf(n->lockfn, "%s.lock", fpath); +} + + + +int +delete_record(char *fpath, int size, int id) +{ + nol my; + char abuf[512]; + int fdr, fdw, fd; + int count; + fileheader_t fhdr; + + nolfilename(&my, fpath); + + if ((fd = open(my.lockfn, O_RDWR | O_CREAT | O_APPEND, 0644)) == -1) + return -1; + flock(fd, LOCK_EX); + + if ((fdr = open(fpath, O_RDONLY, 0)) == -1) + { + +#ifdef HAVE_REPORT + report("delete_record failed!!! (open)"); +#endif + + flock(fd, LOCK_UN); + close(fd); + return -1; + } + if ((fdw = open(my.newfn, O_WRONLY | O_CREAT | O_EXCL, 0644)) == -1) + { + flock(fd, LOCK_UN); + +#ifdef HAVE_REPORT + report("delete_record failed!!! (open tmpfile)"); +#endif + + close(fd); + close(fdr); + return -1; + } + count = 1; + while (read(fdr, abuf, size) == size) + { + if (id == count) { + memcpy(&fhdr, abuf, sizeof(fhdr)); + bbslog("delete_record: %d, %s, %s\n", count, fhdr.owner, fhdr.title); + } + if (id != count++ && (write(fdw, abuf, size) == -1)) + { + + bbslog("delete_record: %s failed!!! (write)\n", fpath); +#ifdef HAVE_REPORT + report("delete_record failed!!! (write)"); +#endif + + unlink(my.newfn); + close(fdr); + close(fdw); + flock(fd, LOCK_UN); + close(fd); + return -1; + } + } + close(fdr); + close(fdw); + if (Rename(fpath, my.oldfn) == -1 || Rename(my.newfn, fpath) == -1) + { + +#ifdef HAVE_REPORT + report("delete_record failed!!! (Rename)"); +#endif + + flock(fd, LOCK_UN); + close(fd); + return -1; + } + flock(fd, LOCK_UN); + close(fd); + return 0; +} + +cancel_article(homepath, board, file) + char *homepath; + char *board, *file; +{ + struct fileheader_t header; + struct stat state; + char dirname[MAXPATHLEN]; + char buf[MAXPATHLEN]; + long numents, size, time, now; + int fd, lower, ent; + + + if (file == NULL || file[0] != 'M' || file[1] != '.' || + (time = atoi(file + 2)) <= 0) { + bbslog("cancel_article: invalid filename `%s`\n", file); + return 0; + } + size = sizeof(header); + sprintf(dirname, "%s/boards/%s/.DIR", homepath, board); + if ((fd = open(dirname, O_RDONLY)) == -1) { + bbslog("cancel_article: open `%s` error\n", dirname); + return 0; + } + fstat(fd, &state); + ent = ((long) state.st_size) / size; + lower = 0; + while (1) + { + ent -= 8; + if (ent <= 0 || lower >= 2) + break; + lseek(fd, size * ent, SEEK_SET); + if (read(fd, &header, size) != size) + { + ent = 0; + break; + } + now = atoi(header.filename + 2); + lower = (now < time) ? lower + 1 : 0; + } + if (ent < 0) + ent = 0; + while (read(fd, &header, size) == size) + { + if (strcmp(file, header.filename) == 0) + { + if ((header.filemode & FILE_MARKED) + || (header.filemode & FILE_DIGEST) || (header.owner[0] == '-')) + break; + delete_record(dirname, sizeof(fileheader_t), lseek(fd, 0, SEEK_CUR) / size); + cancelpost(&header, board); + break; + } + now = atoi(header.filename + 2); + if (now > time) + break; + } + close(fd); + return 0; +} + +#elif defined(PalmBBS) +# undef PATH XPATH +# undef HEADER XHEADER +#include "server.h" + +char * +post_article(homepath, userid, board, writebody, pathname, firstpath) + char *homepath; + char *userid, *board; + int (*writebody) (); +char *pathname, *firstpath; +{ + PATH msgdir, msgfile; + static PATH name; + + READINFO readinfo; + SHORT fileid; + char buf[MAXPATHLEN]; + struct stat stbuf; + int fh; + + strcpy(msgdir, homepath); + if (stat(msgdir, &stbuf) == -1 || !S_ISDIR(stbuf.st_mode)) + { + /* A directory is missing! */ + bbslog(":Err: Unable to post in %s.\n", msgdir); + return NULL; + } + get_filelist_ids(msgdir, &readinfo); + + for (fileid = 1; fileid <= BBS_MAX_FILES; fileid++) + { + int oumask; + if (test_readbit(&readinfo, fileid)) + continue; + fileid_to_fname(msgdir, fileid, msgfile); + sprintf(name, "%04x", fileid); + +#ifdef DEBUG + printf("post to %s\n", msgfile); +#endif + + if (firstpath && *firstpath) + { + +#ifdef DEBUGLINK + bbslog("try to link %s to %s", firstpath, msgfile); +#endif + + if (link(firstpath, msgfile) == 0) + break; + } + oumask = umask(0); + fh = open(msgfile, O_CREAT | O_EXCL | O_WRONLY, 0664); + umask(oumask); + if (writebody) + { + if ((*writebody) (fh, board, pathname) < 0) + return NULL; + } + else + { + if (bbspost_write_post(fh, board, pathname) < 0) + return NULL; + } + close(fh); + break; + } + +#ifdef CACHED_OPENBOARD + { + char *bname; + bname = strrchr(msgdir, '/'); + if (bname) + notify_new_post(++bname, 1, fileid, stbuf.st_mtime); + } +#endif + + return name; +} + +cancel_article(homepath, board, file) + char *homepath; + char *board, *file; +{ + PATH fname; + +#ifdef CACHED_OPENBOARD + PATH bdir; + struct stat stbuf; + + sprintf(bdir, "%s/boards/%s", homepath, board); + stat(bdir, &stbuf); +#endif + + sprintf(fname, "%s/boards/%s/%s", homepath, board, file); + unlink(fname); + /* kill it now! the function is far small then original.. :) */ + /* because it won't make system load heavy like before */ + +#ifdef CACHED_OPENBOARD + notify_new_post(board, -1, hex2SHORT(file), stbuf.st_mtime); +#endif +} + +#else +error("You should choose one of the systems: PhoenixBBS, PowerBBS, or PalmBBS") +#endif + +#else + +receive_article() +{ +} + +cancel_article_front(msgid) + char *msgid; +{ +} +#endif diff --git a/pttbbs/innbbsd/rfc931.c b/pttbbs/innbbsd/rfc931.c new file mode 100644 index 00000000..0d59d771 --- /dev/null +++ b/pttbbs/innbbsd/rfc931.c @@ -0,0 +1,144 @@ + /* + * rfc931_user() speaks a common subset of the RFC 931, AUTH, TAP and IDENT + * protocols. It consults an RFC 931 etc. compatible daemon on the client + * host to look up the remote user name. The information should not be used + * for authentication purposes. + * + * Diagnostics are reported through syslog(3). + * + * Author: Wietse Venema, Eindhoven University of Technology, The Netherlands. + * + * Inspired by the authutil package (comp.sources.unix volume 22) by Dan + * Bernstein (brnstnd@kramden.acf.nyu.edu). + */ + +#ifndef lint +static char sccsid[] = "@(#) rfc931.c 1.4 93/03/07 22:47:52"; +#endif + +#include +#include +#include +#include +#include +#include +#include + +/*#include "log_tcp.h"*/ + +#define RFC931_PORT 113 /* Semi-well-known port */ + +#ifndef RFC931_TIMEOUT +#define RFC931_TIMEOUT 30 /* wait for at most 30 seconds */ +#endif + +extern char *strchr(); +extern char *inet_ntoa(); + +static jmp_buf timebuf; + +/* timeout - handle timeouts */ + +static void timeout(sig) +int sig; +{ + longjmp(timebuf, sig); +} + +/* rfc931_name - return remote user name */ + +char *my_rfc931_name(herefd,there) +int herefd; +struct sockaddr_in *there; /* remote link information */ +{ + struct sockaddr_in here; /* local link information */ + struct sockaddr_in sin; /* for talking to RFC931 daemon */ + int length; + int s; + unsigned remote; + unsigned local; + static char user[256]; /* XXX */ + char buffer[512]; /* YYY */ + FILE *fp; + char *cp; + char *result = "unknown"; + + /* Find out local address and port number of stdin. */ + + length = sizeof(here); + if (getsockname(herefd, (struct sockaddr *) & here, &length) == -1) { + syslog(LOG_ERR, "getsockname: %m"); + return (result); + } + + /* + * The socket that will be used for user name lookups should be bound to + * the same local IP address as stdin. This will automagically happen on + * hosts that have only one IP network address. When the local host has + * more than one IP network address, we must do an explicit bind() call. + */ + + if ((s = socket(AF_INET, SOCK_STREAM, 0)) == -1) + return (result); + + sin = here; + sin.sin_port = 0; + if (bind(s, (struct sockaddr *) & sin, sizeof sin) < 0) { + syslog(LOG_ERR, "bind: %s: %m", inet_ntoa(here.sin_addr)); + return (result); + } + /* Set up timer so we won't get stuck. */ + + signal(SIGALRM, timeout); + if (setjmp(timebuf)) { + close(s); /* not: fclose(fp) */ + return (result); + } + alarm(RFC931_TIMEOUT); + + /* Connect to the RFC931 daemon. */ + + sin = *there; + sin.sin_port = htons(RFC931_PORT); + if (connect(s, (struct sockaddr *) & sin, sizeof(sin)) == -1 + || (fp = fdopen(s, "w+")) == 0) { + close(s); + alarm(0); + return (result); + } + + /* + * Use unbuffered I/O or we may read back our own query. setbuf() must be + * called before doing any I/O on the stream. Thanks for the reminder, + * Paul Kranenburg ! + */ + + setbuf(fp, (char *) 0); + + /* Query the RFC 931 server. Would 13-byte writes ever be broken up? */ + + fprintf(fp, "%u,%u\r\n", ntohs(there->sin_port), ntohs(here.sin_port)); + fflush(fp); + + /* + * Read response from server. Use fgets()/sscanf() instead of fscanf() + * because there is no buffer for pushback. Thanks, Chris Turbeville + * . + */ + + if (fgets(buffer, sizeof(buffer), fp) != 0 + && ferror(fp) == 0 && feof(fp) == 0 + && sscanf(buffer, "%u , %u : USERID :%*[^:]:%255s", + &remote, &local, user) == 3 + && ntohs(there->sin_port) == remote + && ntohs(here.sin_port) == local) { + /* Strip trailing carriage return. */ + + if (cp = strchr(user, '\r')) + *cp = 0; + result = user; + } + alarm(0); + fclose(fp); + return (result); +} diff --git a/pttbbs/mbbsd/.cvsignore b/pttbbs/mbbsd/.cvsignore new file mode 100644 index 00000000..35f9f2d1 --- /dev/null +++ b/pttbbs/mbbsd/.cvsignore @@ -0,0 +1,2 @@ +*.o +mbbsd diff --git a/pttbbs/mbbsd/Makefile b/pttbbs/mbbsd/Makefile new file mode 100644 index 00000000..886944f3 --- /dev/null +++ b/pttbbs/mbbsd/Makefile @@ -0,0 +1,45 @@ +# $Id: Makefile,v 1.1 2002/03/07 15:13:48 in2 Exp $ + +BBSHOME?=$(HOME) +OSTYPE=FreeBSD + +# FreeBSD +CFLAGS_FreeBSD= -pipe -Wall -g -O3 -DHAVE_SETPROCTITLE -DBBSHOME='"$(BBSHOME)"' -DFreeBSD -I../include +LDFLAGS_FreeBSD=-pipe -Wall -g -O3 +LIBS_FreeBSD= -lutil -lkvm + +# Linux +CFLAGS_linux= -pipe -Wall -g -O3 -DHAVE_DES_CRYPT -DBBSHOME='"$(BBSHOME)"' -DLinux -I../include -s +LDFLAGS_linux= -pipe -Wall -g -O3 +LIBS_linux= -lcrypt + +CFLAGS= $(CFLAGS_$(OSTYPE)) +LDFLAGS=$(LDFLAGS_$(OSTYPE)) +LIBS= $(LIBS_$(OSTYPE)) + +CC= gcc +PROG= mbbsd +OBJS= admin.o announce.o args.o bbcall.o bbs.o board.o cache.o cal.o card.o\ + chat.o chc_draw.o chc_net.o chc_play.o chc_rule.o chicken.o dark.o\ + dice.o edit.o friend.o gamble.o gomo.o gomo1.o guess.o indict.o io.o\ + kaede.o lovepaper.o mail.o mbbsd.o menu.o more.o name.o osdep.o\ + othello.o page.o read.o record.o register.o screen.o stuff.o\ + talk.o term.o topsong.o user.o vice.o vote.o xyz.o\ + voteboard.o syspost.o var.o descrypt.o toolkit.o passwd.o\ + calendar.o + +.SUFFIXES: .c .o +.c.o: + $(CC) $(CFLAGS) -c $*.c + +all: $(PROG) + +$(PROG): $(OBJS) + $(CC) $(LDFLAGS) -o $(PROG) $(OBJS) $(LIBS) + +install: $(PROG) + install -d $(BBSHOME)/bin/ + install -c -m 755 $(PROG) $(BBSHOME)/bin/ + +clean: + rm -f $(OBJS) $(PROG) diff --git a/pttbbs/mbbsd/admin.c b/pttbbs/mbbsd/admin.c new file mode 100644 index 00000000..14bc9721 --- /dev/null +++ b/pttbbs/mbbsd/admin.c @@ -0,0 +1,1105 @@ +/* $Id: admin.c,v 1.1 2002/03/07 15:13:48 in2 Exp $ */ +#include +#include +#include +#include +#include +#include +#include +#include +#include "config.h" +#include "pttstruct.h" +#include "common.h" +#include "perm.h" +#include "modes.h" +#include "proto.h" + +extern char *msg_uid; +extern userec_t xuser; +extern char *err_uid; +extern boardheader_t *bcache; + +/* 使用者管理 */ +int m_user() { + userec_t muser; + int id; + char genbuf[200]; + + stand_title("使用者設定"); + usercomplete(msg_uid, genbuf); + if(*genbuf) { + move(2, 0); + if((id = getuser(genbuf))) { + memcpy(&muser, &xuser, sizeof(muser)); + user_display(&muser, 1); + uinfo_query(&muser, 1, id); + } else { + outs(err_uid); + clrtoeol(); + pressanykey(); + } + } + return 0; +} + +extern int b_lines; + +static int search_key_user(char *passwdfile, int mode) { + userec_t user; + int ch; + int coun = 0; + FILE *fp1 = fopen(passwdfile, "r"); + char buf[128], key[22], genbuf[8]; + + clear(); + getdata(0, 0, mode ? "請輸入使用者關鍵字[電話|地址|姓名|上站地點|" + "email|小雞id] :" : "請輸入id :", key, 21, DOECHO); + while((fread(&user, sizeof(user), 1, fp1)) > 0 && coun < MAX_USERS) { + if(!(++coun & 15)) { + move(1, 0); + sprintf(buf, "第 [%d] 筆資料\n", coun); + outs(buf); + refresh(); + } + if(!strcasecmp(user.userid, key) || + (mode && ( + strstr(user.realname, key) || strstr(user.username, key) || + strstr(user.lasthost, key) || strstr(user.email, key) || + strstr(user.address, key) || strstr(user.justify, key) || + strstr(user.mychicken.name, key)))) { + move(1, 0); + sprintf(buf, "第 [%d] 筆資料\n", coun); + outs(buf); + refresh(); + + user_display(&user, 1); + uinfo_query(&user, 1, coun); + outs("\033[44m 空白鍵\033[37m:搜尋下一個" + " \033[33m Q\033[37m: 離開"); + outs(mode ? " \033[m " : + " S: 取用備份資料 \033[m "); + while(1) { + while((ch = igetch()) == 0); + if(ch == ' ') + break; + if(ch == 'q' || ch == 'Q') + return 0; + if(ch == 's' && !mode) { + if((ch = searchuser(user.userid))) { + setumoney(ch,user.money); + passwd_update(ch, &user); + return 0; + } else { + move(b_lines - 1, 0); + genbuf[0] = 'n'; + getdata(0, 0, + "目前的 PASSWD 檔沒有此 ID,新增嗎?[y/N]", + genbuf, 3, LCECHO); + if(genbuf[0] == 'n') { + outs("目前的PASSWDS檔沒有此id " + "請先new一個這個id的帳號"); + } else { + int allocid = getnewuserid(); + + if(allocid > MAX_USERS || allocid <= 0) { + fprintf(stderr, "本站人口已達飽和!\n"); + exit(1); + } + + if(passwd_update(allocid, &user) == -1) { + fprintf(stderr, "客滿了,再見!\n"); + exit(1); + } + setuserid(allocid, user.userid); + if(!searchuser(user.userid)) { + fprintf(stderr, "無法建立帳號\n"); + exit(1); + } + return 0; + } + } + } + } + } + } + + fclose(fp1); + return 0; +} + +/* 以任意 key 尋找使用者 */ +int search_user_bypwd() { + search_key_user(FN_PASSWD, 1); + return 0; +} + +/* 尋找備份的使用者資料 */ +int search_user_bybakpwd() { + char *choice[] = { + "PASSWDS.NEW1", "PASSWDS.NEW2", "PASSWDS.NEW3", + "PASSWDS.NEW4", "PASSWDS.NEW5", "PASSWDS.NEW6", + "PASSWDS.BAK" + }; + int ch; + + clear(); + move(1, 1); + outs("請輸入你要用來尋找備份的檔案 或按 'q' 離開\n"); + outs(" [\033[1;31m1\033[m]一天前, [\033[1;31m2\033[m]兩天前, " + "[\033[1;31m3\033[m]三天前\n"); + outs(" [\033[1;31m4\033[m]四天前, [\033[1;31m5\033[m]五天前, " + "[\033[1;31m6\033[m]六天前\n"); + outs(" [7]備份的\n"); + do { + move(5, 1); + outs("選擇 => "); + ch = igetch(); + if(ch == 'q' || ch == 'Q') + return 0; + } while (ch < '1' || ch > '8'); + ch -= '1'; + search_key_user(choice[ch], 0); + return 0; +} + +static void bperm_msg(boardheader_t *board) { + prints("\n設定 [%s] 看板之(%s)權限:", board->brdname, + board->brdattr & BRD_POSTMASK ? "發表" : "閱\讀"); +} + +extern char* str_permboard[]; + +unsigned int setperms(unsigned int pbits, char *pstring[]) { + register int i; + char choice[4]; + + move(4, 0); + for(i = 0; i < NUMPERMS / 2; i++) { + prints("%c. %-20s %-15s %c. %-20s %s\n", + 'A' + i, pstring[i], + ((pbits >> i) & 1 ? "ˇ" : "X"), + i < 10 ? 'Q' + i : '0' + i - 10, + pstring[i + 16], + ((pbits >> (i + 16)) & 1 ? "ˇ" : "X")); + } + clrtobot(); + while(getdata(b_lines - 1, 0, "請按 [A-5] 切換設定,按 [Return] 結束:", + choice, 3, LCECHO)) { + i = choice[0] - 'a'; + if(i < 0) + i = choice[0] - '0' + 26; + if(i >= NUMPERMS) + bell(); + else { + pbits ^= (1 << i); + move(i % 16 + 4, i <= 15 ? 24 : 64); + prints((pbits >> i) & 1 ? "ˇ" : "X"); + } + } + return pbits; +} + +/* 自動設立精華區 */ +void setup_man(boardheader_t * board) { + char genbuf[200]; + + setapath(genbuf, board->brdname); + mkdir(genbuf, 0755); +} + +extern char *fn_board; +extern char *err_bid; +extern userec_t cuser; +extern char *msg_sure_ny; +extern char* str_permid[]; + +int m_mod_board(char *bname) { + boardheader_t bh, newbh; + int bid; + char genbuf[256], ans[4]; + + bid = getbnum(bname); + if(!bid || !bname[0] || get_record(fn_board, &bh, sizeof(bh), bid) == -1) { + outs(err_bid); + pressanykey(); + return -1; + } + + prints("看板名稱:%s\n看板說明:%s\n看板bid:%d\n看板GID:%d\n" + "板主名單:%s", bh.brdname, bh.title, bid, bh.gid, bh.BM); + bperm_msg(&bh); + + /* Ptt 這邊斷行會檔到下面 */ + move(9, 0); + sprintf(genbuf, "看板 (E)設定 (V)違法/解除 %s (D)刪除 [Q]取消?", + HAS_PERM(PERM_SYSOP) ? + " (B)BVote (S)救回文章" : ""); + getdata(10, 0, genbuf, ans, 3, LCECHO); + + switch(*ans) { + case 's': + if(HAS_PERM(PERM_SYSOP) ) { + char actionbuf[512]; + + sprintf(actionbuf, BBSHOME "/bin/buildir boards/%s &", + bh.brdname); + system(actionbuf); + } + break; + case 'b': + if(HAS_PERM(PERM_SYSOP)) { + char bvotebuf[10]; + + memcpy(&newbh, &bh, sizeof(bh)); + sprintf(bvotebuf, "%d", newbh.bvote); + move(20, 0); + prints("看版 %s 原來的 BVote:%d", bh.brdname, bh.bvote); + getdata_str(21, 0, "新的 Bvote:", genbuf, 5, LCECHO, bvotebuf); + newbh.bvote = atoi(genbuf); + substitute_record(fn_board, &newbh, sizeof(newbh), bid); + reset_board(bid); + log_usies("SetBoardBvote", newbh.brdname); + break; + } else + break; + case 'v': + memcpy(&newbh, &bh, sizeof(bh)); + outs("看版目前為"); + outs((bh.brdattr & BRD_BAD) ? "違法" : "正常"); + getdata(21, 0, "確定更改?", genbuf, 5, LCECHO); + if(genbuf[0] == 'y') { + if(newbh.brdattr & BRD_BAD) + newbh.brdattr = newbh.brdattr & (!BRD_BAD); + else + newbh.brdattr = newbh.brdattr | BRD_BAD; + substitute_record(fn_board, &newbh, sizeof(newbh), bid); + reset_board(bid); + log_usies("ViolateLawSet", newbh.brdname); + } + break; + case 'd': + getdata_str(9, 0, msg_sure_ny, genbuf, 3, LCECHO, "N"); + if(genbuf[0] != 'y' || !bname[0]) + outs(MSG_DEL_CANCEL); + else { + strcpy(bname, bh.brdname); + sprintf(genbuf, + "/bin/tar zcvf tmp/board_%s.tgz boards/%s man/%s >/dev/null 2>&1;" + "/bin/rm -fr boards/%s man/%s", + bname, bname, bname, bname, bname); + system(genbuf); + memset(&bh, 0, sizeof(bh)); + sprintf(bh.title, "%s 看板 %s 刪除", bname, cuser.userid); + post_msg("Security", bh.title,"請注意刪除的合法性","[系統安全局]"); + substitute_record(fn_board, &bh, sizeof(bh), bid); + reset_board(bid); + log_usies("DelBoard", bh.title); + outs("刪板完畢"); + } + break; + case 'e': + move(8, 0); + outs("直接按 [Return] 不修改該項設定"); + memcpy(&newbh, &bh, sizeof(bh)); + + while(getdata(9, 0, "新看板名稱:", genbuf, IDLEN + 1, DOECHO)) { + if(getbnum(genbuf)) { + move(3, 0); + outs("錯誤! 板名雷同"); + } else if(!invalid_brdname(genbuf)) { + strcpy(newbh.brdname, genbuf); + break; + } + } + + do { + getdata_str(12, 0, "看板類別:", genbuf, 5, DOECHO, bh.title); + if(strlen(genbuf) == 4) + break; + } while (1); + + if(strlen(genbuf) >= 4) + strncpy(newbh.title, genbuf, 4); + + newbh.title[4] = ' '; + + getdata_str(14, 0, "看板主題:", genbuf, BTLEN + 1, DOECHO, + bh.title + 7); + if(genbuf[0]) + strcpy(newbh.title + 7, genbuf); + if(getdata_str(15, 0, "新板主名單:", genbuf, IDLEN * 3 + 3, DOECHO, + bh.BM)) { + trim(genbuf); + strcpy(newbh.BM, genbuf); + } + + if(HAS_PERM(PERM_SYSOP)) { + move(1, 0); + clrtobot(); + newbh.brdattr = setperms(newbh.brdattr, str_permboard); + move(1, 0); + clrtobot(); + } + + if(newbh.brdattr & BRD_GROUPBOARD) + strncpy(newbh.title + 5, "Σ", 2); + else if(newbh.brdattr & BRD_NOTRAN) + strncpy(newbh.title + 5, "◎", 2); + else + strncpy(newbh.title + 5, "●", 2); + + if(HAS_PERM(PERM_SYSOP) && !(newbh.brdattr & BRD_HIDE)) { + getdata_str(14, 0, "設定讀寫權限(Y/N)?", ans, 4, LCECHO, "N"); + if(*ans == 'y') { + getdata_str(15, 0, "限制 [R]閱\讀 (P)發表?", ans, 4, LCECHO, + "R"); + if(*ans == 'p') + newbh.brdattr |= BRD_POSTMASK; + else + newbh.brdattr &= ~BRD_POSTMASK; + + move(1, 0); + clrtobot(); + bperm_msg(&newbh); + newbh.level = setperms(newbh.level, str_permid); + clear(); + } + } + + getdata_str(b_lines - 1, 0, msg_sure_ny, genbuf, 4, LCECHO, "Y"); + + if((*genbuf == 'y') && memcmp(&newbh, &bh, sizeof(bh))) { + if(strcmp(bh.brdname, newbh.brdname)) { + char src[60], tar[60]; + + setbpath(src, bh.brdname); + setbpath(tar, newbh.brdname); + Rename(src, tar); + + setapath(src, bh.brdname); + setapath(tar, newbh.brdname); + Rename(src, tar); + } + setup_man(&newbh); + substitute_record(fn_board, &newbh, sizeof(newbh), bid); + reset_board(bid); + log_usies("SetBoard", newbh.brdname); + } + } + return 0; +} + +extern char *msg_bid; + +/* 設定看版 */ +int m_board() { + char bname[32]; + + stand_title("看板設定"); + make_blist(); + namecomplete(msg_bid, bname); + if(!*bname) + return 0; + m_mod_board(bname); + return 0; +} + +/* 設定系統檔案 */ +int x_file() { + int aborted; + char ans[4], *fpath; + + move(b_lines - 4, 0); + /* Ptt */ + outs("設定 (1)身份確認信 (4)post注意事項 (5)錯誤登入訊息 (6)註冊範例 (7)通過確認通知\n"); + outs(" (8)email post通知 (9)系統功\能精靈 (A)茶樓 (B)站長名單 (C)email通過確認\n"); + outs(" (D)新使用者需知 (E)身份確認方法 (F)歡迎畫面 (G)進站畫面 " +#ifdef MULTI_WELCOME_LOGIN +"(X)刪除進站畫面" +#endif +"\n"); + getdata(b_lines - 1, 0, " (H)看板期限 (I)故鄉 (J)出站畫面 (K)生日卡 (L)節日 [Q]取消?", ans, 3, LCECHO); + + switch(ans[0]) { + case '1': + fpath = "etc/confirm"; + break; + case '4': + fpath = "etc/post.note"; + break; + case '5': + fpath = "etc/goodbye"; + break; + case '6': + fpath = "etc/register"; + break; + case '7': + fpath = "etc/registered"; + break; + case '8': + fpath = "etc/emailpost"; + break; + case '9': + fpath = "etc/hint"; + break; + case 'a': + fpath = "etc/teashop"; + break; + case 'b': + fpath = "etc/sysop"; + break; + case 'c': + fpath = "etc/bademail"; + break; + case 'd': + fpath = "etc/newuser"; + break; + case 'e': + fpath = "etc/justify"; + break; + case 'f': + fpath = "etc/Welcome"; + break; + case 'g': +#ifdef MULTI_WELCOME_LOGIN + getdata(b_lines - 1, 0, "第幾個進站畫面[0-4]", ans, 3, LCECHO); + if( ans[0] == '1' ) { fpath = "etc/Welcome_login.1"; } + else if( ans[0] == '2' ){ fpath = "etc/Welcome_login.2"; } + else if( ans[0] == '3' ){ fpath = "etc/Welcome_login.3"; } + else if( ans[0] == '4' ){ fpath = "etc/Welcome_login.4"; } + else { fpath = "etc/Welcome_login.0"; } +#else + fpath = "etc/Welcome_login"; +#endif + break; + +#ifdef MULTI_WELCOME_LOGIN + case 'x': + getdata(b_lines - 1, 0, "第幾個進站畫面[1-4]", ans, 3, LCECHO); + if( ans[0] == '1' ) { unlink("etc/Welcome_login.1"); outs("ok"); } + else if( ans[0] == '2' ){ unlink("etc/Welcome_login.2"); outs("ok"); } + else if( ans[0] == '3' ){ unlink("etc/Welcome_login.3"); outs("ok"); } + else if( ans[0] == '4' ){ unlink("etc/Welcome_login.4"); outs("ok"); } + else {outs("所指定的進站畫面無法刪除"); } + pressanykey(); + return FULLUPDATE; + +#endif + + case 'h': + fpath = "etc/expire.conf"; + break; + case 'i': + fpath = "etc/domain_name_query"; + break; + case 'j': + fpath = "etc/Logout"; + break; + case 'k': + fpath = "etc/Welcome_birth"; + break; + case 'l': + fpath = "etc/feast"; + break; + default: + return FULLUPDATE; + } + aborted = vedit(fpath, NA, NULL); + prints("\n\n系統檔案[%s]:%s", fpath, + (aborted == -1) ? "未改變" : "更新完畢"); + pressanykey(); + return FULLUPDATE; +} + +extern int numboards; +extern int class_bid; + +int m_newbrd(int recover) { + boardheader_t newboard; + char ans[4]; + int bid; + char genbuf[200]; + + stand_title("建立新板"); + memset(&newboard, 0, sizeof(newboard)); + + newboard.gid = class_bid; + if (newboard.gid == 0) { + move(6, 0); + outs("請先選擇一個類別再開板!"); + pressanykey(); + return -1; + } + + do { + if(!getdata(3, 0, msg_bid, newboard.brdname, IDLEN + 1, DOECHO)) + return -1; + } while(invalid_brdname(newboard.brdname)); + + do { + getdata(6, 0, "看板類別:", genbuf, 5, DOECHO); + if(strlen(genbuf) == 4) + break; + } while (1); + + if(strlen(genbuf) >= 4) + strncpy(newboard.title, genbuf, 4); + + newboard.title[4] = ' '; + + getdata(8, 0, "看板主題:", genbuf, BTLEN + 1, DOECHO); + if(genbuf[0]) + strcpy(newboard.title + 7, genbuf); + setbpath(genbuf, newboard.brdname); + + if(recover) { + struct stat sb; + + if(stat(genbuf, &sb) == -1 || !(sb.st_mode & S_IFDIR)) { + outs("此看板已經存在! 請取不同英文板名"); + pressanykey(); + return -1; + } + } else if(getbnum(newboard.brdname) > 0 || mkdir(genbuf, 0755) == -1) { + outs("此看板已經存在! 請取不同英文板名"); + pressanykey(); + return -1; + } + + newboard.brdattr = BRD_NOTRAN; + + if(HAS_PERM(PERM_SYSOP)) { + move(1, 0); + clrtobot(); + newboard.brdattr = setperms(newboard.brdattr, str_permboard); + move(1, 0); + clrtobot(); + } + getdata(9, 0, "是看板? (N:目錄) (Y/n):", genbuf, 3, LCECHO); + if(genbuf[0]=='n') + newboard.brdattr |= BRD_GROUPBOARD; + + if(newboard.brdattr & BRD_GROUPBOARD) + strncpy(newboard.title + 5, "Σ", 2); + else if(newboard.brdattr & BRD_NOTRAN) + strncpy(newboard.title + 5, "◎", 2); + else + strncpy(newboard.title + 5, "●", 2); + + newboard.level = 0; + getdata(11, 0, "板主名單:", newboard.BM, IDLEN * 3 + 3, DOECHO); + + if(HAS_PERM(PERM_SYSOP) && !(newboard.brdattr & BRD_HIDE)) { + getdata_str(14, 0, "設定讀寫權限(Y/N)?", ans, 3, LCECHO, "N"); + if(*ans == 'y') { + getdata_str(15, 0, "限制 [R]閱\讀 (P)發表?", ans, 4, LCECHO, "R"); + if(*ans == 'p') + newboard.brdattr |= BRD_POSTMASK; + else + newboard.brdattr &= (~BRD_POSTMASK); + + move(1, 0); + clrtobot(); + bperm_msg(&newboard); + newboard.level = setperms(newboard.level, str_permid); + clear(); + } + } + + if((bid = getbnum("")) > 0) + { + substitute_record(fn_board, &newboard, sizeof(newboard), bid); + reset_board(bid); + } + else if(append_record(fn_board, (fileheader_t *) & newboard, + sizeof(newboard)) == -1) { + pressanykey(); + return -1; + } + else + { + addbrd_touchcache(); + } + setup_man(&newboard); + + outs("\n新板成立"); + post_newboard(newboard.title, newboard.brdname, newboard.BM); + log_usies("NewBoard", newboard.title); + pressanykey(); + return 0; +} + +static int auto_scan(char fdata[][STRLEN], char ans[]) { + int good = 0; + int count = 0; + int i; + char temp[10]; + + if(!strncmp(fdata[2], "小", 2) || strstr(fdata[2], "丫") + || strstr(fdata[2], "誰") || strstr(fdata[2], "不")) { + ans[0] = '0'; + return 1; + } + + strncpy(temp, fdata[2], 2); + temp[2] = '\0'; + + /* 疊字 */ + if(!strncmp(temp, &(fdata[2][2]), 2)) { + ans[0] = '0'; + return 1; + } + + if(strlen(fdata[2]) >= 6) { + if(strstr(fdata[2], "陳水扁")) { + ans[0] = '0'; + return 1; + } + + if(strstr("趙錢孫李周吳鄭王", temp)) + good++; + else if(strstr("杜顏黃林陳官余辛劉", temp)) + good++; + else if(strstr("蘇方吳呂李邵張廖應蘇", temp)) + good++; + else if(strstr("徐謝石盧施戴翁唐", temp)) + good++; + } + + if(!good) + return 0; + + if(!strcmp(fdata[3], fdata[4]) || + !strcmp(fdata[3], fdata[5]) || + !strcmp(fdata[4], fdata[5])) { + ans[0] = '4'; + return 5; + } + + if(strstr(fdata[3], "大")) { + if (strstr(fdata[3], "台") || strstr(fdata[3], "淡") || + strstr(fdata[3], "交") || strstr(fdata[3], "政") || + strstr(fdata[3], "清") || strstr(fdata[3], "警") || + strstr(fdata[3], "師") || strstr(fdata[3], "銘傳") || + strstr(fdata[3], "中央") || strstr(fdata[3], "成") || + strstr(fdata[3], "輔") || strstr(fdata[3], "東吳")) + good++; + } else if(strstr(fdata[3], "女中")) + good++; + + if(strstr(fdata[4], "地球") || strstr(fdata[4], "宇宙") || + strstr(fdata[4], "信箱")) { + ans[0] = '2'; + return 3; + } + + if(strstr(fdata[4], "市") || strstr(fdata[4], "縣")) { + if(strstr(fdata[4], "路") || strstr(fdata[4], "街")) { + if(strstr(fdata[4], "號")) + good++; + } + } + + for(i = 0; fdata[5][i]; i++) { + if(isdigit(fdata[5][i])) + count++; + } + + if(count <= 4) { + ans[0] = '3'; + return 4; + } else if(count >= 7) + good++; + + if(good >= 3) { + ans[0] = 'y'; + return -1; + } else + return 0; +} + +/* 處理 Register Form */ +int scan_register_form(char *regfile, int automode, int neednum) { + char genbuf[200]; + static char *logfile = "register.log"; + static char *field[] = { + "uid", "ident", "name", "career", "addr", "phone", "email", NULL + }; + static char *finfo[] = { + "帳號", "身分證號", "真實姓名", "服務單位", "目前住址", + "連絡電話", "電子郵件信箱", NULL + }; + static char *reason[] = { + "輸入真實姓名", "詳填學校科系與年級", "填寫完整的住址資料", + "詳填連絡電話", "確實填寫註冊申請表", "用中文填寫申請單", NULL + }; + static char *autoid = "AutoScan"; + userec_t muser; + FILE *fn, *fout, *freg; + char fdata[7][STRLEN]; + char fname[STRLEN], buf[STRLEN]; + char ans[4], *ptr, *uid; + int n, unum; + int nSelf = 0, nAuto = 0; + + uid = cuser.userid; + sprintf(fname, "%s.tmp", regfile); + move(2, 0); + if(dashf(fname)) { + if(neednum == 0) { /* 自己進 Admin 來審的 */ + outs("其他 SYSOP 也在審核註冊申請單"); + pressanykey(); + } + return -1; + } + Rename(regfile, fname); + if((fn = fopen(fname, "r")) == NULL) { + prints("系統錯誤,無法讀取註冊資料檔: %s", fname); + pressanykey(); + return -1; + } + if(neednum) { /* 被強迫審的 */ + move(1, 0); + clrtobot(); + prints("各位具有站長權限的人,註冊單累積超過一百份了,麻煩您幫忙審 %d 份\n", neednum); + prints("也就是大概二十分之一的數量,當然,您也可以多審\n沒審完之前,系統不會讓你跳出喲!謝謝"); + pressanykey(); + } + memset(fdata, 0, sizeof(fdata)); + while(fgets(genbuf, STRLEN, fn)) { + if ((ptr = (char *) strstr(genbuf, ": "))) { + *ptr = '\0'; + for(n = 0; field[n]; n++) { + if(strcmp(genbuf, field[n]) == 0) { + strcpy(fdata[n], ptr + 2); + if((ptr = (char *) strchr(fdata[n], '\n'))) + *ptr = '\0'; + } + } + } else if ((unum = getuser(fdata[0])) == 0) { + move(2, 0); + clrtobot(); + outs("系統錯誤,查無此人\n\n"); + for (n = 0; field[n]; n++) + prints("%s : %s\n", finfo[n], fdata[n]); + pressanykey(); + neednum--; + } else { + neednum--; + memcpy(&muser, &xuser, sizeof(muser)); + if(automode) + uid = autoid; + + if(!automode || !auto_scan(fdata, ans)) { + uid = cuser.userid; + + move(1, 0); + prints("帳號位置 :%d\n", unum); + user_display(&muser, 1); + move(14, 0); + prints("\033[1;32m------------- 請站長嚴格審核使用者資料,您還有 %d 份---------------\033[m\n", neednum); + for(n = 0; field[n]; n++) { + if(n >= 2 && n <= 5) + prints("%d.", n - 2); + else + prints(" "); + prints("%-12s:%s\n", finfo[n], fdata[n]); + } + if(muser.userlevel & PERM_LOGINOK) { + getdata(b_lines - 1, 0, "\033[1;32m此帳號已經完成註冊, " + "更新(Y/N/Skip)?\033[m[N] ", ans, 3, LCECHO); + if(ans[0] != 'y' && ans[0] != 's') + ans[0] = 'd'; + } else { + getdata(b_lines - 1, 0, + "是否接受此資料(Y/N/Q/Del/Skip)?[Y] ", + ans, 3, LCECHO); + } + nSelf++; + } else + nAuto++; + if(neednum > 0 && ans[0] == 'q') { + move(2, 0); + clrtobot(); + prints("沒審完不能退出"); + pressanykey(); + ans[0] = 's'; + } + + switch(ans[0]) { + case 'q': + if((freg = fopen(regfile, "a"))) { + for(n = 0; field[n]; n++) + fprintf(freg, "%s: %s\n", field[n], fdata[n]); + fprintf(freg, "----\n"); + while(fgets(genbuf, STRLEN, fn)) + fputs(genbuf, freg); + fclose(freg); + } + case 'd': + break; + case '0': + case '1': + case '2': + case '3': + case '4': + case 'n': + if(ans[0] == 'n') { + for(n = 0; field[n]; n++) + prints("%s: %s\n", finfo[n], fdata[n]); + move(9, 0); + prints("請提出退回申請表原因,按 取消\n"); + for (n = 0; reason[n]; n++) + prints("%d) 請%s\n", n, reason[n]); + } else + buf[0] = ans[0]; + if(ans[0] != 'n' || + getdata(10 + n, 0, "退回原因:", buf, 60, DOECHO)) + if((buf[0] - '0') >= 0 && (buf[0] - '0') < n) { + int i; + fileheader_t mhdr; + char title[128], buf1[80]; + FILE *fp; + + i = buf[0] - '0'; + strcpy(buf, reason[i]); + sprintf(genbuf, "[退回原因] 請%s", buf); + + sethomepath(buf1, muser.userid); + stampfile(buf1, &mhdr); + strcpy(mhdr.owner, cuser.userid); + strncpy(mhdr.title, "[註冊失敗]", TTLEN); + mhdr.savemode = 0; + mhdr.filemode = 0; + sethomedir(title, muser.userid); + if(append_record(title, &mhdr, sizeof(mhdr)) != -1) { + fp = fopen(buf1, "w"); + fprintf(fp, "%s\n", genbuf); + fclose(fp); + } + if((fout = fopen(logfile, "a"))) { + for(n = 0; field[n]; n++) + fprintf(fout, "%s: %s\n", field[n], fdata[n]); + n = time(NULL); + fprintf(fout, "Date: %s\n", Cdate((time_t *) & n)); + fprintf(fout, "Rejected: %s [%s]\n----\n", + uid, buf); + fclose(fout); + } + break; + } + move(10, 0); + clrtobot(); + prints("取消退回此註冊申請表"); + case 's': + if((freg = fopen(regfile, "a"))) { + for(n = 0; field[n]; n++) + fprintf(freg, "%s: %s\n", field[n], fdata[n]); + fprintf(freg, "----\n"); + fclose(freg); + } + break; + default: + prints("以下使用者資料已經更新:\n"); + mail_muser(muser, "[註冊成功\囉]", "etc/registered"); + muser.userlevel |= (PERM_LOGINOK | PERM_POST); + strcpy(muser.realname, fdata[2]); + strcpy(muser.address, fdata[4]); + strcpy(muser.email, fdata[6]); + sprintf(genbuf, "%s:%s:%s", fdata[5], fdata[3], uid); + strncpy(muser.justify, genbuf, REGLEN); + sethomefile(buf, muser.userid, "justify"); + log_file(buf, genbuf); + passwd_update(unum, &muser); + + if((fout = fopen(logfile, "a"))) { + for(n = 0; field[n]; n++) + fprintf(fout, "%s: %s\n", field[n], fdata[n]); + n = time(NULL); + fprintf(fout, "Date: %s\n", Cdate((time_t *) & n)); + fprintf(fout, "Approved: %s\n", uid); + fprintf(fout, "----\n"); + fclose(fout); + } + break; + } + } + } + fclose(fn); + unlink(fname); + + move(0, 0); + clrtobot(); + + move(5, 0); + prints("您審了 %d 份註冊單,AutoScan 審了 %d 份", nSelf, nAuto); + +/** DickG: 將審了幾份的相關資料 post 到 Security 板上 ***********/ +/* DickG: 因應新的站長上站需審核方案,是故沒有必要留下 record 而關掉 + strftime(buf, 200, "%Y/%m/%d/%H:%M", pt); + + strcpy(xboard, "Security"); + setbpath(xfpath, xboard); + stampfile(xfpath, &xfile); + strcpy(xfile.owner, "系統"); + strcpy(xfile.title, "[報告] 審核記錄"); + xfile.savemode = 'S'; + xptr = fopen(xfpath, "w"); + fprintf(xptr, "\n時間:%s + %s 審了 %d 份註冊單\n + AutoScan 審了 %d 份註冊單\n + 共計 %d 份。", + buf, cuser.userid, nSelf, nAuto, nSelf+nAuto); + fclose(xptr); + setbdir(fname, xboard); + append_record(fname, &xfile, sizeof(xfile)); + outgo_post(&xfile, xboard); + touchbtotal(getbnum(xboard)); + cuser.numposts++; +*/ +/*********************************************/ + pressanykey(); + return (0); +} + +extern char* fn_register; +extern int t_lines; + +int m_register() { + FILE *fn; + int x, y, wid, len; + char ans[4]; + char genbuf[200]; + + if((fn = fopen(fn_register, "r")) == NULL) { + outs("目前並無新註冊資料"); + return XEASY; + } + + stand_title("審核使用者註冊資料"); + y = 2; + x = wid = 0; + + while(fgets(genbuf, STRLEN, fn) && x < 65) { + if(strncmp(genbuf, "uid: ", 5) == 0) { + move(y++, x); + outs(genbuf + 5); + len = strlen(genbuf + 5); + if(len > wid) + wid = len; + if(y >= t_lines - 3) { + y = 2; + x += wid + 2; + } + } + } + fclose(fn); + getdata(b_lines - 1, 0, "開始審核嗎(Auto/Yes/No)?[N] ", ans, 3, LCECHO); + if(ans[0] == 'a') + scan_register_form(fn_register, 1, 0); + else if(ans[0] == 'y') + scan_register_form(fn_register, 0, 0); + + return 0; +} + +int cat_register() { + if(system("cat register.new.tmp >> register.new") == 0 && + system("rm -f register.new.tmp") == 0) + mprints(22, 0, "OK 嚕~~ 繼續去奮鬥吧!! "); + else + mprints(22, 0, "沒辦法CAT過去呢 去檢查一下系統吧!! "); + pressanykey(); + return 0; +} + +static void give_id_money(char *user_id, int money, FILE *log_fp, char *mail_title, time_t t) { + char tt[TTLEN + 1] = {0}; + + if(deumoney(searchuser(user_id), money) < 0) { + move(12, 0); + clrtoeol(); + prints("id:%s money:%d 不對吧!!", user_id, money); + pressanykey(); + } else { + fprintf(log_fp, "%ld %s %d", t, user_id, money); + sprintf(tt, "%s : %d ptt 幣", mail_title, money); + mail_id(user_id, tt, "~bbs/etc/givemoney.why", "[PTT 銀行]"); + } +} + +int give_money() { + FILE *fp, *fp2; + char *ptr, *id, *mn; + char buf[200] = {0}, tt[TTLEN + 1] = {0}; + time_t t = time(NULL); + struct tm *pt = localtime(&t); + int to_all = 0, money = 0; + + getdata(0, 0, "指定使用者(S) 全站使用者(A) 取消(Q)?[S]", buf, 3, LCECHO); + if(buf[0] == 'q') + return 1; + else if( buf[0] == 'a') { + to_all = 1; + getdata(1, 0, "發多少錢呢?", buf, 20, DOECHO); + money = atoi(buf); + if(money <= 0) { + move(2, 0); + prints("輸入錯誤!!"); + pressanykey(); + return 1; + } + } else { + if(vedit("etc/givemoney.txt", NA, NULL) < 0) + return 1; + } + + clear(); + getdata(0, 0, "要發錢了嗎(Y/N)[N]", buf, 3, LCECHO); + if(buf[0] != 'y') + return 1; + + if(!(fp2 = fopen("etc/givemoney.log", "a"))) + return 1; + strftime(buf, 200, "%Y/%m/%d/%H:%M", pt); + fprintf(fp2, "%s\n", buf); + + getdata(1, 0, "紅包袋標題 :", tt, TTLEN, DOECHO); + move(2, 0); + + prints("編紅包袋內容"); + pressanykey(); + if(vedit("etc/givemoney.why", NA, NULL) < 0) + return 1; + + stand_title("發錢中..."); + if(to_all) { + extern struct uhash_t *uhash; + int i, unum; + for(unum = uhash->number, i=0; iuserid[i])) + continue; + id = uhash->userid[i]; + give_id_money(id, money, fp2, tt, t); + } + } else { + if(!(fp = fopen("etc/givemoney.txt", "r+"))) { + fclose(fp2); + return 1; + } + while(fgets(buf, 255, fp)) { +// clear(); + if (!(ptr = strchr(buf, ':'))) + continue; + *ptr = '\0'; + id = buf; + mn = ptr + 1; + give_id_money(id, atoi(mn), fp2, tt, t); + } + fclose(fp); + } + + fclose(fp2); + pressanykey(); + return FULLUPDATE; +} diff --git a/pttbbs/mbbsd/announce.c b/pttbbs/mbbsd/announce.c new file mode 100644 index 00000000..960a45aa --- /dev/null +++ b/pttbbs/mbbsd/announce.c @@ -0,0 +1,1590 @@ +/* $Id: announce.c,v 1.1 2002/03/07 15:13:48 in2 Exp $ */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "config.h" +#include "pttstruct.h" +#include "perm.h" +#include "common.h" +#include "modes.h" +#include "proto.h" + +extern int b_lines; +extern int p_lines; +extern int TagNum; +extern int currbid; +static void g_showmenu(gmenu_t *pm) { + static char *mytype = "編 選 絲路之旅"; + char *title, ch; + int n, max; + item_t *item; + + showtitle("精華文章", pm->mtitle); + prints(" \033[1;36m編號 標 題%56s\033[m", mytype); + + if(pm->num) { + n = pm->page; + max = n + p_lines; + if(max > pm->num) + max = pm->num; + while(n < max) { + item = pm->item[n++]; + title = item->title; + ch = title[1]; + prints("\n%5d. %-72.71s", n, title); + } + } else + outs("\n 《精華區》尚在吸取天地間的日精月華 :)"); + + move(b_lines, 1); + outs(pm->level ? + "\033[34;46m 【板 主】 \033[31;47m (h)\033[30m說明 " + "\033[31m(q/←)\033[30m離開 \033[31m(n)\033[30m新增文章 " + "\033[31m(g)\033[30m新增目錄 \033[31m(e)\033[30m編輯檔案 \033[m" : + "\033[34;46m 【功\能鍵】 \033[31;47m (h)\033[30m說明 " + "\033[31m(q/←)\033[30m離開 \033[31m(k↑j↓)\033[30m移動游標 " + "\033[31m(enter/→)\033[30m讀取資料 \033[m"); +} + +static FILE *go_cmd(item_t *node, int *sock) { + struct sockaddr_in sin; + struct hostent *host; + char *site; + FILE *fp; + + *sock = socket(AF_INET, SOCK_STREAM, 0); + + if(*sock < 0) { + syslog(LOG_ERR, "socket(): %m"); + return NULL; + } + memset((char *)&sin, 0, sizeof(sin)); + sin.sin_family = AF_INET; + sin.sin_port = htons(node->X.G.port); + + host = gethostbyname(site = node->X.G.server); + if(host == NULL) + sin.sin_addr.s_addr = inet_addr(site); + else + memcpy(&sin.sin_addr.s_addr, host->h_addr, host->h_length); + + if(connect(*sock, (struct sockaddr *)&sin, sizeof(sin)) < 0) { + syslog(LOG_ERR, "connect(): %m"); + return NULL; + } + fp = fdopen(*sock, "r+"); + if(fp != NULL) { + setbuf(fp, (char *) 0); + fprintf(fp, "%s\r\n", node->X.G.path); + fflush(fp); + } else + close(*sock); + return fp; +} + +static char *nextfield(char *data, char *field) { + register int ch; + + while((ch = *data)) { + data++; + if((ch == '\t') || (ch == '\r' && *data == '\n')) + break; + *field++ = ch; + } + *field = '\0'; + return data; +} + +extern char *str_author1; + +static FILE* my_open(char* path) { + FILE* ans = 0; + char buf[80]; + struct stat st; + time_t now = time(0); + + if(stat(path, &st) == 0 && st.st_mtime < now - 3600 * 24 * 7) { + return fopen(path, "w"); + } + + if((ans = fopen(path, "r+"))) { + fclose(ans); + return 0; + /* + return directly due to currutmp->pager > 1 mode (real copy) + */ + fgets(buf, 80, ans); + if(!strncmp(buf, str_author1, strlen(str_author1)) || + *buf == '0' || *buf == '1') { + fclose(ans); + return 0; + } + + rewind(ans); + } else + ans = fopen(path, "w"); + return ans; +} + +static jmp_buf jbuf; + +static void isig(int sig) { + longjmp(jbuf, 1); +} + +#define PROXY_HOME "proxy/" +extern userec_t cuser; +extern userinfo_t *currutmp; + +static void go_proxy(char* fpath, item_t *node, int update) { + char *ptr, *str, *server; + int ch; + static FILE *fo; + + strcpy(fpath, PROXY_HOME); + ptr = fpath + sizeof(PROXY_HOME) - 1; + str = server = node->X.G.server; + while((ch = *str)) { + str++; + if(ch == '.') { + if(!strcmp(str, "edu.tw")) + break; + } else if(ch >= 'A' && ch <= 'Z') { + ch |= 0x20; + } + *ptr++ = ch; + } + *ptr = '\0'; + mkdir(fpath, 0755); + + *ptr++ = '/'; + str = node->X.G.path; + while((ch = *str)) { + str++; + if(ch == '/') { + ch = '.'; + } + *ptr++ = ch; + } + *ptr = '\0'; + + /* expire proxy data */ + + if((fo = update ? fopen(fpath, "w") : my_open(fpath))) { + FILE *fp; + char buf[512]; + int sock; + + if(fo == NULL) + return; + + outmsg("★ 建立 proxy 資料連線中 ... "); + refresh(); + + sock = -1; + if(setjmp(jbuf)) { + if(sock != -1) + close(sock); + fseek(fo, 0, SEEK_SET); + fwrite("", 0, 0, fo); + fclose(fo); + alarm(0); + return; + } + + signal(SIGALRM, isig); + alarm(5); + fp = go_cmd(node, &sock); + alarm(0); + + str = node->title; + ch = str[1]; + if(ch == (char) 0xbc && + !(HAS_PERM(PERM_SYSOP) && currutmp->pager > 1)) { + time_t now; + + time(&now); + fprintf(fo, "作者: %s (連線精華區)\n標題: %s\n時間: %s\n", + server, str + 3, ctime(&now) + ); + } + + while(fgets(buf, 511, fp)) { + if(!strcmp(buf, ".\r\n")) + break; + if((ptr = strstr(buf, "\r\n"))) + strcpy(ptr, "\n"); + fputs(buf, fo); + } + fclose(fo); + fclose(fp); + } +} + +static void g_additem(gmenu_t *pm, item_t *myitem) { + if(pm->num < MAX_ITEMS) { + item_t *newitem = (item_t *)malloc(sizeof(item_t)); + + memcpy(newitem, myitem, sizeof(item_t)); + pm->item[(pm->num)++] = newitem; + } +} + +static void go_menu(gmenu_t *pm, item_t *node, int update) { + FILE *fp; + char buf[512], *ptr, *title; + item_t item; + int ch; + + go_proxy(buf, node, update); + pm->num = 0; + if((fp = fopen(buf, "r"))) { + title = item.title; + while(fgets(buf, 511, fp)) { + ptr = buf; + ch = *ptr++; + if(ch != '0' && ch != '1') + continue; + + strcpy(title, "□ "); + if(ch == '1') + title[1] = (char) 0xbd; + + ptr = nextfield(ptr, title + 3); + if(!*ptr) + continue; + title[sizeof(item.title) - 1] = '\0'; + + ptr = nextfield(ptr, item.X.G.path); + if(!*ptr) + continue; + + ptr = nextfield(ptr, item.X.G.server); + if(!*ptr) + continue; + + nextfield(ptr, buf); + item.X.G.port = atoi(buf); + + g_additem(pm, &item); + } + fclose(fp); + } +} + +static int g_searchtitle(gmenu_t* pm, int rev) { + static char search_str[30] = ""; + int pos; + + if(getdata(b_lines - 1, 1,"[搜尋]關鍵字:", search_str, 40, DOECHO)) + if(!*search_str) + return pm->now; + + str_lower(search_str, search_str); + + rev = rev ? -1 : 1; + pos = pm->now; + do { + pos += rev; + if(pos == pm->num) + pos = 0; + else if(pos < 0) + pos = pm->num - 1; + if(strstr_lower(pm->item[pos]->title, search_str)) + return pos; + } while(pos != pm->now); + return pm->now; +} + +static void g_showhelp() { + clear(); + outs("\033[36m【 " BBSNAME "連線精華區使用說明 】\033[m\n\n" + "[←][q] 離開到上一層目錄\n" + "[↑][k] 上一個選項\n" + "[↓][j] 下一個選項\n" + "[→][r][enter] 進入目錄/讀取文章\n" + "[b][PgUp] 上頁選單\n" + "[^F][PgDn][Spc] 下頁選單\n" + "[##] 移到該選項\n" + "[^S] 將文章存到信箱\n" + "[R] 更新資料\n" + "[N] 查詢檔名\n" + "[c][C][^C] 拷貝文章/並跳至上次貼文章的地方/" + "直接貼到上次貼的地方\n"); + pressanykey(); +} + +#define PATHLEN 256 + +static char paste_fname[200]; +extern time_t paste_time; +extern char paste_path[]; +extern char paste_title[]; +extern int paste_level; + +static void load_paste() { + struct stat st; + FILE *fp; + + if(!*paste_fname) + setuserfile(paste_fname, "paste_path"); + if(stat(paste_fname, &st) == 0 && st.st_mtime > paste_time && + (fp = fopen(paste_fname, "r"))) { + int i; + fgets(paste_path, PATHLEN, fp); + i = strlen(paste_path) - 1; + if(paste_path[i] == '\n') + paste_path[i] = 0; + fgets(paste_title, STRLEN, fp); + i = strlen(paste_title) - 1; + if(paste_title[i] == '\n') + paste_title[i] = 0; + fscanf(fp, "%d", &paste_level); + paste_time = st.st_mtime; + fclose(fp); + } +} + +static char copyfile[PATHLEN]; +static char copytitle[TTLEN+1]; +static char copyowner[IDLEN + 2]; + +void a_copyitem(char* fpath, char* title, char* owner, int mode) { + strcpy(copyfile, fpath); + strcpy(copytitle, title); + if(owner) + strcpy(copyowner, owner); + else + *copyowner = 0; + if(mode) { + outmsg("檔案標記完成。[注意] 拷貝後才能刪除原文!"); + igetch(); + } +} + +#define FHSZ sizeof(fileheader_t) + +static void a_loadname(menu_t *pm) { + char buf[PATHLEN]; + int len; + + setadir(buf, pm->path); + len = get_records(buf, pm->header, FHSZ, pm->page+1, p_lines); + if(len < p_lines) + bzero(&pm->header[len], FHSZ*(p_lines-len)); +} + +static void a_timestamp(char *buf, time_t *time) { + struct tm *pt = localtime(time); + + sprintf(buf, "%02d/%02d/%02d", pt->tm_mon + 1, pt->tm_mday, (pt->tm_year + 1900) % 100); +} + +static void a_showmenu(menu_t *pm) { + char *title, *editor; + int n; + fileheader_t *item; + char buf[PATHLEN]; + time_t dtime; + + showtitle("精華文章", pm->mtitle); + prints(" \033[1;36m編號 標 題%56s\033[0m", + "編 選 日 期"); + + if(pm->num) { + setadir(buf, pm->path); + a_loadname(pm); + for(n = 0; n < p_lines && pm->page + n < pm->num; n++) { + item = &pm->header[n]; + title = item->title; + editor = item->owner; + /* Ptt 把時間改為取檔案時間 + dtime = atoi(&item->filename[2]); + */ + sprintf(buf,"%s/%s",pm->path,item->filename); + dtime = dasht(buf); + a_timestamp(buf, &dtime); + prints("\n%6d%c %-47.46s%-13s[%s]", pm->page+n+1, + (item->filemode & FILE_BM) ?'X': + (item->filemode & FILE_HIDE) ?')':'.', + title, editor, + buf); + } + } else + outs("\n 《精華區》尚在吸取天地間的日月精華中... :)"); + + move(b_lines, 1); + outs(pm->level ? + "\033[34;46m 【板 主】 \033[31;47m (h)\033[30m說明 " + "\033[31m(q/←)\033[30m離開 \033[31m(n)\033[30m新增文章 " + "\033[31m(g)\033[30m新增目錄 \033[31m(e)\033[30m編輯檔案 \033[m" : + "\033[34;46m 【功\能鍵】 \033[31;47m (h)\033[30m說明 " + "\033[31m(q/←)\033[30m離開 \033[31m(k↑j↓)\033[30m移動游標 " + "\033[31m(enter/→)\033[30m讀取資料 \033[m"); +} + +static int a_searchtitle(menu_t *pm, int rev) { + static char search_str[40] = ""; + int pos; + + getdata(b_lines - 1, 1, "[搜尋]關鍵字:", search_str, 40, DOECHO); + + if(!*search_str) + return pm->now; + + str_lower(search_str, search_str); + + rev = rev ? -1 : 1; + pos = pm->now; + do { + pos += rev; + if(pos == pm->num) + pos = 0; + else if(pos < 0) + pos = pm->num - 1; + if(pos < pm->page || pos >= pm->page + p_lines) { + pm->page = pos - pos % p_lines; + a_loadname(pm); + } + if(strstr_lower(pm->header[pos - pm->page].title, search_str)) + return pos; + } while(pos != pm->now); + return pm->now; +} + +enum {NOBODY, MANAGER, SYSOP}; + +static void a_showhelp(int level) { + clear(); + outs("\033[36m【 " BBSNAME "公佈欄使用說明 】\033[m\n\n" + "[←][q] 離開到上一層目錄\n" + "[↑][k] 上一個選項\n" + "[↓][j] 下一個選項\n" + "[→][r][enter] 進入目錄/讀取文章\n" + "[^B][PgUp] 上頁選單\n" + "[^F][PgDn][Spc] 下頁選單\n" + "[##] 移到該選項\n" + "[F][U] 將文章寄回 Internet 郵箱/" + "將文章 uuencode 後寄回郵箱\n"); + if(level >= MANAGER) { + outs("\n\033[36m【 板主專用鍵 】\033[m\n" + "[H] 切換為 公開/會員/版主 才能閱\讀\n" + "[n/g/G] 收錄精華文章/開闢目錄/建立連線\n" + "[m/d/D] 移動/刪除文章/刪除一個範圍的文章\n" + "[f/T/e] 編輯標題符號/修改文章標題/內容\n" + "[c/p/a] 拷貝/粘貼/附加文章\n" + "[^P/^A] 粘貼/附加已用't'標記文章\n"); + } + + if(level >= SYSOP) { + outs("\n\033[36m【 站長專用鍵 】\033[m\n" + "[l] 建 symbolic link\n" + "[N] 查詢檔名\n"); + } + pressanykey(); +} + +static int AnnounceSelect() { + static char xboard[20]; + char buf[20]; + char fpath[256]; + boardheader_t *bp; + + move(2, 0); + clrtoeol(); + move(3, 0); + clrtoeol(); + move(1, 0); + make_blist(); + namecomplete("選擇精華區看板:", buf); + if(*buf) + strcpy(xboard, buf); + if(*xboard && (bp = getbcache(getbnum(xboard)))) { + setapath(fpath, xboard); + setutmpmode(ANNOUNCE); + a_menu(xboard, fpath, + (HAS_PERM(PERM_ALLBOARD) || + (HAS_PERM(PERM_BM) && is_BM(bp->BM))) ? 1 : 0); + } + return FULLUPDATE; +} + +extern char vetitle[]; + +void gem(char* maintitle, item_t* path, int update) { + gmenu_t me; + int ch; + char fname[PATHLEN]; + + strncpy(me.mtitle, maintitle, 40); + me.mtitle[40] = 0; + go_menu(&me, path, update); + + /* 精華區-tree 中部份結構屬於 cuser ==> BM */ + + me.level = 0; + me.page = 9999; + me.now = 0; + for(;;) { + if(me.now >= me.num && me.num > 0) + me.now = me.num - 1; + else if(me.now < 0) + me.now = 0; + + if(me.now < me.page || me.now >= me.page + p_lines) { + me.page = me.now - (me.now % p_lines); + g_showmenu(&me); + } + ch = cursor_key(2 + me.now - me.page, 0); + if(ch == 'q' || ch == 'Q' || ch == KEY_LEFT) + break; + + if(ch >= '0' && ch <= '9') { + if((ch = search_num(ch, me.num)) != -1) + me.now = ch; + me.page = 9999; + continue; + } + + switch(ch) { + case KEY_UP: + case 'k': + if(--me.now < 0) + me.now = me.num - 1; + break; + case KEY_DOWN: + case 'j': + if(++me.now >= me.num) + me.now = 0; + break; + case KEY_PGUP: + case 'b': + if(me.now >= p_lines) + me.now -= p_lines; + else if(me.now > 0) + me.now = 0; + else + me.now = me.num - 1; + break; + case ' ': + case KEY_PGDN: + case Ctrl('F'): + if(me.now < me.num - p_lines) + me.now += p_lines; + else if(me.now < me.num - 1) + me.now = me.num - 1; + else + me.now = 0; + break; + case 'h': + g_showhelp(); + me.page = 9999; + break; + case '?': + case '/': + me.now = g_searchtitle(&me, ch == '?'); + me.page = 9999; + break; + case 'N': + if(HAS_PERM(PERM_SYSOP)) { + go_proxy(fname, me.item[me.now], 0); + move(b_lines - 1, 0); + outs(fname); + pressanykey(); + me.page = 9999; + } + break; + case 'c': + case 'C': + case Ctrl('C'): + if(me.now < me.num) { + item_t *node = me.item[me.now]; + char *title = node->title; + int mode = title[1]; + + load_paste(); + if(mode == (char) 0xbc || ch == Ctrl('C')) { + if(mode == (char) 0xbc) + go_proxy(fname, node, 0); + if(ch == Ctrl('C') && *paste_path && paste_level) { + char newpath[PATHLEN]; + fileheader_t item; + + strcpy(newpath, paste_path); + if(mode == (char) 0xbc) { + stampfile(newpath, &item); + unlink(newpath); + Link(fname, newpath); + } else + stampdir(newpath, &item); + strcpy(item.owner, cuser.userid); + sprintf(item.title, "%s%.72s", + (currutmp->pager > 1) ? "" : + (mode == (char) 0xbc) ? "◇ " : "◆ ", + title + 3); + strcpy(strrchr(newpath, '/') + 1, ".DIR"); + append_record(newpath, &item, FHSZ); + if(++me.now >= me.num) + me.now = 0; + break; + } + if(mode == (char) 0xbc) { + a_copyitem(fname, + title + ((currutmp->pager > 1) ? 3 : 0), + 0, 1); + if(ch == 'C' && *paste_path) { + setutmpmode(ANNOUNCE); + a_menu(paste_title, paste_path, paste_level); + } + me.page = 9999; + } else + bell(); + } + } + break; + case Ctrl('B'): + m_read(); + me.page = 9999; + break; + case Ctrl('I'): + t_idle(); + me.page = 9999; + break; + case 's': + AnnounceSelect(); + me.page = 9999; + break; + case '\n': + case '\r': + case KEY_RIGHT: + case 'r': + case 'R': + if(me.now < me.num) { + item_t *node = me.item[me.now]; + char *title = node->title; + int mode = title[1]; + int update = (ch == 'R') ? 1 : 0; + + title += 3; + + if(mode == (char) 0xbc) { + int more_result; + + go_proxy(fname, node, update); + strcpy(vetitle, title); + while((more_result = more(fname, YEA))) { + if(more_result == 1) { + if(--me.now < 0) { + me.now = 0; + break; + } + } else if(more_result == 3) { + if(++me.now >= me.num) { + me.now = me.num - 1; + break; + } + } else + break; + node = me.item[me.now]; + if(node->title[1] != (char) 0xbc) + break; + go_proxy(fname, node, update); + strcpy(vetitle, title); + } + } else if(mode == (char) 0xbd) { + gem(title, node, update); + } + me.page = 9999; + } + break; + } + } + for(ch = 0; ch < me.num; ch++) + free(me.item[ch]); +} + +extern char *msg_fwd_ok; +extern char *msg_fwd_err1; +extern char *msg_fwd_err2; + +static void a_forward(char *path, fileheader_t *pitem, int mode) { + fileheader_t fhdr; + + strcpy(fhdr.filename, pitem->filename); + strcpy(fhdr.title, pitem->title); + switch(doforward(path, &fhdr, mode)) { + case 0: + outmsg(msg_fwd_ok); + break; + case -1: + outmsg(msg_fwd_err1); + break; + case -2: + outmsg(msg_fwd_err2); + break; + } +} + +static void a_additem(menu_t *pm, fileheader_t *myheader) { + char buf[PATHLEN]; + + setadir(buf, pm->path); + if(append_record(buf, myheader, FHSZ) == -1) + return; + pm->now = pm->num++; + + if(pm->now >= pm->page + p_lines) { + pm->page = pm->now - ((pm->page == 10000 && pm->now > p_lines / 2) ? + (p_lines / 2) : (pm->now % p_lines)); + } + + /*Ptt*/ + strcpy(pm->header[pm->now - pm->page].filename, myheader->filename); +} + +#define ADDITEM 0 +#define ADDGROUP 1 +#define ADDGOPHER 2 +#define ADDLINK 3 +extern char currboard[]; + +static void a_newitem(menu_t *pm, int mode) { + static char *mesg[4] = { + "[新增文章] 請輸入標題:", /* ADDITEM */ + "[新增目錄] 請輸入標題:", /* ADDGROUP */ + "[新增連線] 請輸入標題:", /* ADDGOPHER */ + "請輸入標題:" /* ADDLINK */ + }; + + char fpath[PATHLEN], buf[PATHLEN], lpath[PATHLEN]; + fileheader_t item; + int d; + + strcpy(fpath, pm->path); + + switch(mode) { + case ADDITEM: + stampfile(fpath, &item); + strcpy(item.title, "◇ "); /* A1BA */ + break; + + case ADDGROUP: + stampdir(fpath, &item); + strcpy(item.title, "◆ "); /* A1BB */ + break; + case ADDGOPHER: + bzero(&item, sizeof(item)); + strcpy(item.title, "☉ "); /* A1BB */ + if(!getdata(b_lines - 2, 1, "輸入URL位址:", + item.filename+2,61, DOECHO)) + return; + break; + case ADDLINK: + stamplink(fpath, &item); + if (!getdata(b_lines - 2, 1, "新增連線:", buf, 61, DOECHO)) + return; + if(invalid_pname(buf)) { + unlink(fpath); + outs("目的地路徑不合法!"); + igetch(); + return; + } + + item.title[0] = 0; + for(d = 0; d <= 3; d++) { + switch(d) { + case 0: + sprintf(lpath, "%s%s%s/%s", + BBSHOME, "/man/boards/",currboard , buf); + break; + case 1: + sprintf(lpath, "%s%s%s", + BBSHOME, "/man/boards/" , buf); + break; + case 2: + sprintf(lpath, "%s%s%s", + BBSHOME, "/" , buf); + break; + case 3: + sprintf(lpath, "%s%s%s", + BBSHOME, "/etc/" , buf); + break; + } + if(dashf(lpath)) { + strcpy(item.title, "☆ "); /* A1B3 */ + break; + } else if (dashd(lpath)) { + strcpy(item.title, "★ "); /* A1B4 */ + break; + } + if(!HAS_PERM(PERM_BBSADM) && d==1) + break; + } + + if(!item.title[0]) { + unlink(fpath); + outs("目的地路徑不合法!"); + igetch(); + return; + } + } + + if(!getdata(b_lines - 1, 1, mesg[mode], &item.title[3], 55, DOECHO)) { + if(mode == ADDGROUP) + rmdir(fpath); + else if(mode != ADDGOPHER) + unlink(fpath); + return; + } + + switch(mode) { + case ADDITEM: + if(vedit(fpath, 0, NULL) == -1) { + unlink(fpath); + pressanykey(); + return; + } + break; + case ADDLINK: + unlink(fpath); + if(symlink(lpath, fpath) == -1) { + outs("無法建立 symbolic link"); + igetch(); + return; + } + break; + case ADDGOPHER: + strcpy(item.date, "70"); + strncpy(item.filename, "H.",2); + break; + } + + strcpy(item.owner, cuser.userid); + a_additem(pm, &item); +} + +static void a_pasteitem(menu_t *pm, int mode) { + char newpath[PATHLEN]; + char buf[PATHLEN]; + char ans[2]; + int i; + fileheader_t item; + + move(b_lines - 1, 1); + if(copyfile[0]) { + if(dashd(copyfile)) { + for(i = 0; copyfile[i] && copyfile[i] == pm->path[i]; i++); + if(!copyfile[i]) { + outs("將目錄拷進自己的子目錄中,會造成無窮迴圈!"); + igetch(); + return; + } + } + if(mode) { + sprintf(buf, "確定要拷貝[%s]嗎(Y/N)?[N] ", copytitle); + getdata(b_lines - 1, 1, buf, ans, 3, LCECHO); + } else + ans[0]='y'; + if(ans[0] == 'y') { + strcpy(newpath, pm->path); + + if(*copyowner) { + char* fname = strrchr(copyfile, '/'); + + if(fname) + strcat(newpath, fname); + else + return; + if(access(pm->path, X_OK | R_OK | W_OK)) + mkdir(pm->path, 0755); + memset(&item, 0, sizeof(fileheader_t)); + strcpy(item.filename, fname + 1); + memcpy(copytitle, "◎", 2); + if(HAS_PERM(PERM_BBSADM)) + Link(copyfile, newpath); + else { + sprintf(buf, "/bin/cp %s %s", copyfile, newpath); + system(buf); + } + } else if(dashf(copyfile)) { + stampfile(newpath, &item); + memcpy(copytitle, "◇", 2); + sprintf(buf, "/bin/cp %s %s", copyfile, newpath); + } else if(dashd(copyfile)) { + stampdir(newpath, &item); + memcpy(copytitle, "◆", 2); + sprintf(buf, "/bin/cp -r %s/* %s/.D* %s", copyfile, copyfile, + newpath); + } else { + outs("無法拷貝!"); + igetch(); + return; + } + strcpy(item.owner, *copyowner ? copyowner : cuser.userid); + strcpy(item.title, copytitle); + if(!*copyowner) + system(buf); + a_additem(pm, &item); + copyfile[0] = '\0'; + } + } else { + outs("請先執行 copy 命令後再 paste"); + igetch(); + } +} + +static void a_appenditem(menu_t *pm, int isask) { + char fname[PATHLEN]; + char buf[ANSILINELEN]; + char ans[2] = "y"; + FILE *fp, *fin; + + move(b_lines - 1, 1); + if(copyfile[0]) { + if(dashf(copyfile)) { + sprintf(fname, "%s/%s", pm->path, + pm->header[pm->now-pm->page].filename); + if(dashf(fname)) { + if(isask) { + sprintf(buf, "確定要將[%s]附加於此嗎(Y/N)?[N] ", + copytitle); + getdata(b_lines - 2, 1, buf, ans, 3, LCECHO); + } + if(ans[0] == 'y') { + if((fp = fopen(fname, "a+"))) { + if((fin = fopen(copyfile, "r"))) { + memset(buf, '-', 74); + buf[74] = '\0'; + fprintf(fp, "\n> %s <\n\n", buf); + if(isask) + getdata(b_lines - 1, 1, + "是否收錄簽名檔部份(Y/N)?[Y] ", + ans, 3, LCECHO); + while(fgets(buf, sizeof(buf), fin)) { + if((ans[0] == 'n' ) && + !strcmp(buf, "--\n")) + break; + fputs(buf, fp); + } + fclose(fin); + copyfile[0] = '\0'; + } + fclose(fp); + } + } + } else { + outs("檔案不得附加於此!"); + igetch(); + } + } else { + outs("不得附加整個目錄於檔案後!"); + igetch(); + } + } else { + outs("請先執行 copy 命令後再 append"); + igetch(); + } +} + +static int a_pastetagpost(menu_t *pm, int mode) { + extern int TagNum; + extern void EnumTagFhdr(); + extern void UnTagger(int locus); + fileheader_t fhdr; + int ans = 0, ent=0, tagnum; + char title[TTLEN + 1]= "◇ "; + char dirname[200],buf[200]; + + setbdir(dirname, currboard); + tagnum = TagNum; + + if (!tagnum) return ans; + + while (tagnum--) + { + EnumTagFhdr (&fhdr, dirname, ent++); + setbfile (buf, currboard, fhdr.filename); + + if (dashf (buf)) + { + strncpy(title+3, fhdr.title, TTLEN-3); + title[TTLEN] = '\0'; + a_copyitem(buf, title, 0, 0); + if(mode) + { + mode--; + a_pasteitem(pm,0); + } + else a_appenditem(pm, 0); + ++ans; + UnTagger (tagnum); + } + + }; + + return ans; +} + +static void a_moveitem(menu_t *pm) { + fileheader_t *tmp; + char newnum[4]; + int num, max, min; + char buf[PATHLEN]; + int fail; + + sprintf(buf, "請輸入第 %d 選項的新次序:", pm->now + 1); + if(!getdata(b_lines - 1, 1, buf, newnum, 6, DOECHO)) + return; + num = (newnum[0] == '$') ? 9999 : atoi(newnum) - 1; + if(num >= pm->num) + num = pm->num - 1; + else if(num < 0) + num = 0; + setadir(buf, pm->path); + min = num < pm->now ? num : pm->now; + max = num > pm->now ? num : pm->now; + tmp = (fileheader_t *) calloc(max + 1, FHSZ); + + fail = 0; + if(get_records(buf, tmp, FHSZ, 1, min) != min) + fail = 1; + if(num > pm->now) { + if(get_records(buf, &tmp[min], FHSZ, pm->now+2, max-min) != max-min) + fail = 1; + if(get_records(buf, &tmp[max], FHSZ, pm->now+1, 1) != 1) + fail = 1; + } else { + if(get_records(buf, &tmp[min], FHSZ, pm->now+1, 1) != 1) + fail = 1; + if(get_records(buf, &tmp[min+1], FHSZ, num+1, max-min) != max-min) + fail = 1; + } + if(!fail) + substitute_record(buf, tmp, FHSZ * (max + 1), 1); + pm->now = num; + free(tmp); +} + +static void a_delrange(menu_t *pm) { + char fname[256]; + + sprintf(fname,"%s/.DIR",pm->path); + del_range(0, NULL, fname); + pm->num = get_num_records(fname, FHSZ); +} + +static void a_delete(menu_t *pm) { + char fpath[PATHLEN], buf[PATHLEN], cmd[PATHLEN]; + char ans[4]; + fileheader_t backup; + + sprintf(fpath, "%s/%s", pm->path, pm->header[pm->now - pm->page].filename); + setadir(buf, pm->path); + + if(pm->header[pm->now - pm->page].filename[0] == 'H' && + pm->header[pm->now - pm->page].filename[1] == '.') { + getdata(b_lines - 1, 1, "您確定要刪除此精華區連線嗎(Y/N)?[N] ", + ans, 3, LCECHO); + if(ans[0] != 'y') + return; + if(delete_record(buf, FHSZ, pm->now + 1) == -1) + return; + } else if (dashl(fpath)) { + getdata(b_lines - 1, 1, "您確定要刪除此 symbolic link 嗎(Y/N)?[N] ", + ans, 3, LCECHO); + if(ans[0] != 'y') + return; + if(delete_record(buf, FHSZ, pm->now + 1) == -1) + return; + unlink(fpath); + } else if(dashf(fpath)) { + getdata(b_lines - 1, 1, "您確定要刪除此檔案嗎(Y/N)?[N] ", ans, 3, + LCECHO); + if(ans[0] != 'y') + return; + if(delete_record(buf, FHSZ, pm->now + 1) == -1) + return; + + setbpath(buf, "deleted"); + stampfile(buf, &backup); + strcpy(backup.owner, cuser.userid); + strcpy(backup.title,pm->header[pm->now - pm->page].title + 2); + backup.savemode = 'D'; + + sprintf(cmd, "mv -f %s %s", fpath,buf); + system(cmd); + setbdir(buf, "deleted"); + append_record(buf, &backup, sizeof(backup)); + } else if (dashd(fpath)) { + getdata(b_lines - 1, 1, "您確定要刪除整個目錄嗎(Y/N)?[N] ", ans, 3, + LCECHO); + if(ans[0] != 'y') + return; + if(delete_record(buf, FHSZ, pm->now + 1) == -1) + return; + + setapath(buf, "deleted"); + stampdir(buf, &backup); + + sprintf(cmd, "rm -rf %s;/bin/mv -f %s %s",buf,fpath,buf); + system(cmd); + + strcpy(backup.owner, cuser.userid); + strcpy(backup.title,pm->header[pm->now - pm->page].title +2); + setapath(buf, "deleted"); + setadir(buf,buf); + append_record(buf, &backup, sizeof(backup)); + } else { /* Ptt 損毀的項目 */ + getdata(b_lines - 1, 1, "您確定要刪除此損毀的項目嗎(Y/N)?[N] ", + ans, 3, LCECHO); + if(ans[0] != 'y') + return; + if(delete_record(buf, FHSZ, pm->now + 1) == -1) + return; + } + pm->num--; +} + +static void a_newtitle(menu_t *pm) { + char buf[PATHLEN]; + fileheader_t item; + + memcpy(&item, &pm->header[pm->now - pm->page], FHSZ); + strcpy(buf,item.title + 3); + if(getdata_buf(b_lines - 1, 1, "新標題:", buf, 60, DOECHO)) { + strcpy(item.title + 3, buf); + setadir(buf, pm->path); + substitute_record(buf, &item, FHSZ, pm->now + 1); + } +} +static void a_hideitem(menu_t *pm) { + fileheader_t *item=&pm->header[pm->now - pm->page]; + char buf[PATHLEN]; + if(item->filemode&FILE_BM) + { + item->filemode &= ~FILE_BM; + item->filemode &= ~FILE_HIDE; + } + else if(item->filemode&FILE_HIDE) + item->filemode |= FILE_BM; + else item->filemode |= FILE_HIDE; + setadir(buf, pm->path); + substitute_record(buf, item, FHSZ, pm->now + 1); +} +static void a_editsign(menu_t *pm) { + char buf[PATHLEN]; + fileheader_t item; + + memcpy(&item, &pm->header[pm->now - pm->page], FHSZ); + sprintf(buf, "%c%c", item.title[0], item.title[1]); + if(getdata_buf(b_lines - 1, 1, "符號", buf, 5, DOECHO)) { + item.title[0] = buf[0] ? buf[0] : ' '; + item.title[1] = buf[1] ? buf[1] : ' '; + item.title[2] = buf[2] ? buf[2] : ' '; + setadir(buf, pm->path); + substitute_record(buf, &item, FHSZ, pm->now + 1); + } +} + +static void a_showname(menu_t *pm) { + char buf[PATHLEN]; + int len; + int i; + int sym; + + move(b_lines - 1, 1); + sprintf(buf, "%s/%s", pm->path, pm->header[pm->now - pm->page].filename); + if(dashl(buf)) { + prints("此 symbolic link 名稱為 %s\n", + pm->header[pm->now - pm->page].filename); + if((len = readlink(buf, buf, PATHLEN-1)) >= 0) { + buf[len] = '\0'; + for(i = 0; BBSHOME[i] && buf[i] == BBSHOME[i]; i++); + if(!BBSHOME[i] && buf[i] == '/') { + if(HAS_PERM(PERM_BBSADM)) + sym = 1; + else { + sym = 0; + for(i++; BBSHOME "/man"[i] && buf[i] == BBSHOME "/man"[i]; + i++); + if(!BBSHOME "/man"[i] && buf[i] == '/') + sym = 1; + } + if(sym) { + pressanykey(); + move(b_lines - 1, 1); + prints("此 symbolic link 指向 %s\n", &buf[i+1]); + } + } + } + } else if(dashf(buf)) + prints("此文章名稱為 %s", pm->header[pm->now - pm->page].filename); + else if(dashd(buf)) + prints("此目錄名稱為 %s", pm->header[pm->now - pm->page].filename); + else + outs("此項目已損毀, 建議將其刪除!"); + pressanykey(); +} + +static char *a_title; + +static void atitle() { + showtitle("精華文章", a_title); + outs("[←]離開 [→]閱\讀 [^P]發表文章 [b]備忘錄 [d]刪除 [q]精華區 " + "[TAB]文摘 [h]elp\n\033[7m 編號 日 期 作 者 " + "文 章 標 題\033[m"); +} + +extern char currtitle[]; + +char trans_buffer[256]; +extern char quote_file[]; +extern unsigned int currstat; + +static int isvisible_man(menu_t *me) +{ + fileheader_t *fhdr = &me->header[me->now-me->page]; + if( me->levelfilemode & FILE_BM) || + ((fhdr->filemode & FILE_HIDE) && + hbflcheck(currbid, currutmp->uid)))) + return 0; + return 1; +} +int a_menu(char *maintitle, char *path, int lastlevel) { + static char Fexit; + menu_t me; + char fname[PATHLEN]; + int ch, returnvalue = FULLUPDATE; + + trans_buffer[0] = 0; + + Fexit = 0; + me.header = (fileheader_t *)calloc(p_lines, FHSZ); + me.path = path; + strcpy(me.mtitle, maintitle); + setadir(fname, me.path); + me.num = get_num_records(fname, FHSZ); + + /* 精華區-tree 中部份結構屬於 cuser ==> BM */ + + if(!(me.level = lastlevel)) { + char *ptr; + + if((ptr = strrchr(me.mtitle, '['))) + me.level = is_BM(ptr + 1); + } + + me.page = 9999; + me.now = 0; + for(;;) { + if(me.now >= me.num) + me.now = me.num - 1; + if(me.now < 0) + me.now = 0; + + if(me.now < me.page || me.now >= me.page + p_lines) { + me.page = me.now - ((me.page == 10000 && me.now > p_lines / 2) ? + (p_lines / 2) : (me.now % p_lines)); + a_showmenu(&me); + } + + ch = cursor_key(2 + me.now - me.page, 0); + + if(ch == 'q' || ch == 'Q' || ch == KEY_LEFT) + break; + + if(ch >= '1' && ch <= '9') { + if((ch = search_num(ch, me.num)) != -1) + me.now = ch; + me.page = 10000; + continue; + } + + switch(ch) { + case KEY_UP: + case 'k': + if(--me.now < 0) + me.now = me.num - 1; + break; + + case KEY_DOWN: + case 'j': + if(++me.now >= me.num) + me.now = 0; + break; + + case KEY_PGUP: + case Ctrl('B'): + if(me.now >= p_lines) + me.now -= p_lines; + else if (me.now > 0) + me.now = 0; + else + me.now = me.num - 1; + break; + + case ' ': + case KEY_PGDN: + case Ctrl('F'): + if(me.now < me.num - p_lines) + me.now += p_lines; + else if(me.now < me.num - 1) + me.now = me.num - 1; + else + me.now = 0; + break; + + case '0': + me.now = 0; + break; + case '?': + case '/': + me.now = a_searchtitle(&me, ch == '?'); + me.page = 9999; + break; + case '$': + me.now = me.num -1; + break; + case 'h': + a_showhelp(me.level); + me.page = 9999; + break; + case Ctrl('C'): + cal(); + me.page = 9999; + break; + + case Ctrl('I'): + t_idle(); + me.page = 9999; + break; + + case 's': + AnnounceSelect(); + me.page = 9999; + break; + + case 'e': + case 'E': + sprintf(fname, "%s/%s", path, me.header[me.now-me.page].filename); + if(dashf(fname) && me.level >= MANAGER) { + *quote_file = 0; + if(vedit(fname, NA, NULL) != -1) { + char fpath[200]; + fileheader_t fhdr; + + strcpy(fpath, path); + stampfile(fpath, &fhdr); + unlink(fpath); + Rename(fname, fpath); + strcpy(me.header[me.now-me.page].filename, fhdr.filename); + strcpy(me.header[me.now-me.page].owner, cuser.userid); + setadir(fpath, path); + substitute_record(fpath, me.header+me.now-me.page, + sizeof(fhdr), me.now + 1); + } + me.page = 9999; + } + break; + + case 'c': + if(me.now < me.num) { + if(!isvisible_man(&me)) break; + sprintf(fname, "%s/%s", path, + me.header[me.now-me.page].filename); + a_copyitem(fname, me.header[me.now-me.page].title, 0, 1); + me.page = 9999; + break; + } + + case '\n': + case '\r': + case KEY_RIGHT: + case 'r': + if(me.now < me.num) { + fileheader_t *fhdr = &me.header[me.now-me.page]; + if(!isvisible_man(&me)) break; + sprintf(fname, "%s/%s", path, fhdr->filename); + if(*fhdr->filename == 'H' && fhdr->filename[1] == '.') { + item_t item; + strcpy(item.X.G.server, fhdr->filename + 2); + strcpy(item.X.G.path, "1/"); + item.X.G.port = 70; + gem(fhdr->title, &item, (ch == 'R') ? 1 : 0); + } else if (dashf(fname)) { + int more_result; + + while((more_result = more(fname, YEA))) { + /* Ptt 範本精靈 plugin */ + if(currstat == EDITEXP || currstat == OSONG) { + char ans[4]; + + move(22, 0); + clrtoeol(); + getdata(22, 1, + currstat == EDITEXP ? + "要把範例 Plugin 到文章嗎?[y/N]": + "確定要點這首歌嗎?[y/N]", + ans, 3, LCECHO); + if(ans[0]=='y') { + strcpy(trans_buffer,fname); + Fexit = 1; + free(me.header); + if(currstat == OSONG){ + log_file(FN_USSONG,fhdr->title); + } + return FULLUPDATE; + } + } + if(more_result == 1) { + if(--me.now < 0) { + me.now = 0; + break; + } + } else if(more_result == 3) { + if(++me.now >= me.num) { + me.now = me.num - 1; + break; + } + } else + break; + if(!isvisible_man(&me)) break; + sprintf(fname, "%s/%s", path, + me.header[me.now-me.page].filename); + if(!dashf(fname)) + break; + } + } else if(dashd(fname)) { + a_menu(me.header[me.now-me.page].title, fname, me.level); + /* Ptt 強力跳出recursive */ + if(Fexit) { + free(me.header); + return FULLUPDATE; + } + } + me.page = 9999; + } + break; + + case 'F': + case 'U': + sprintf(fname, "%s/%s", path, me.header[me.now-me.page].filename); + if(me.now < me.num && HAS_PERM(PERM_BASIC) && dashf(fname)) { + a_forward(path, &me.header[me.now-me.page], ch /*== 'U'*/); + /*By CharlieL*/ + } else + outmsg("無法轉寄此項目"); + + me.page = 9999; + refresh(); + sleep(1); + break; + } + + if(me.level >= MANAGER) { + int page0 = me.page; + + switch(ch) { + case 'n': + a_newitem(&me, ADDITEM); + me.page = 9999; + break; + case 'g': + a_newitem(&me, ADDGROUP); + me.page = 9999; + break; + case 'G': + a_newitem(&me, ADDGOPHER); + me.page = 9999; + break; + case 'p': + a_pasteitem(&me,1); + me.page = 9999; + break; + case 'f': + a_editsign(&me); + me.page = 9999; + break; + case Ctrl('P'): + a_pastetagpost(&me, -1); + returnvalue = DIRCHANGED; + me.page = 9999; + break; + case Ctrl('A'): + a_pastetagpost(&me, 1); + returnvalue = DIRCHANGED; + me.page = 9999; + break; + case 'a': + a_appenditem(&me, 1); + me.page = 9999; + break; + default: + me.page = page0; + break; + } + + if(me.num) + switch(ch) { + case 'm': + a_moveitem(&me); + me.page = 9999; + break; + + case 'D': + /* Ptt me.page = -1;*/ + a_delrange(&me); + me.page = 9999; + break; + case 'd': + a_delete(&me); + me.page = 9999; + break; + case 'H': + a_hideitem(&me); + me.page = 9999; + break; + case 'T': + a_newtitle(&me); + me.page = 9999; + break; + } + } + + if(me.level == SYSOP) { + switch(ch) { + case 'l': + a_newitem(&me, ADDLINK); + me.page = 9999; + break; + case 'N': + a_showname(&me); + me.page = 9999; + break; + } + } + } + free(me.header); + return returnvalue; +} + +static char *mytitle = BBSNAME "佈告欄"; + +int Announce() { + setutmpmode(ANNOUNCE); + a_menu(mytitle, "man", + ((HAS_PERM(PERM_SYSOP) || HAS_PERM(PERM_ANNOUNCE)) ? SYSOP : + NOBODY)); + return 0; +} diff --git a/pttbbs/mbbsd/args.c b/pttbbs/mbbsd/args.c new file mode 100644 index 00000000..4d1d6ceb --- /dev/null +++ b/pttbbs/mbbsd/args.c @@ -0,0 +1,62 @@ +/* $Id: args.c,v 1.1 2002/03/07 15:13:48 in2 Exp $ */ +#ifdef HAVE_SETPROCTITLE + +void initsetproctitle(int argc, char **argv, char **envp) { +} + +#else + +#include +#include +#include +#include + +char **Argv = NULL; /* pointer to argument vector */ +char *LastArgv = NULL; /* end of argv */ +extern char **environ; + +void initsetproctitle(int argc, char **argv, char **envp) { + register int i; + + /* Move the environment so setproctitle can use the space at + the top of memory. */ + for(i = 0; envp[i]; i++); + environ = malloc(sizeof(char *) * (i + 1)); + for(i = 0; envp[i]; i++) + environ[i] = strdup(envp[i]); + environ[i] = NULL; + + /* Save start and extent of argv for setproctitle. */ + Argv = argv; + if(i > 0) + LastArgv = envp[i - 1] + strlen(envp[i - 1]); + else + LastArgv = argv[argc - 1] + strlen(argv[argc - 1]); +} + +static void do_setproctitle(const char *cmdline) { + char buf[256], *p; + int i; + + strncpy(buf, cmdline, 256); + buf[255] = '\0'; + i = strlen(buf); + if(i > LastArgv - Argv[0] - 2) { + i = LastArgv - Argv[0] - 2; + } + strcpy(Argv[0], buf); + p = &Argv[0][i]; + while(p < LastArgv) + *p++='\0'; + Argv[1] = NULL; +} + +void setproctitle(const char* format, ...) { + char buf[256]; + va_list args; + va_start(args, format); + vsprintf(buf, format,args); + do_setproctitle(buf); + va_end(args); +} +#endif diff --git a/pttbbs/mbbsd/bbcall.c b/pttbbs/mbbsd/bbcall.c new file mode 100644 index 00000000..d7b2d33b --- /dev/null +++ b/pttbbs/mbbsd/bbcall.c @@ -0,0 +1,268 @@ +/* $Id: bbcall.c,v 1.1 2002/03/07 15:13:48 in2 Exp $ */ +#include +#include +#include +#include +#include +#include +#include +#include +#include "config.h" +#include "pttstruct.h" +#include "common.h" +#include "proto.h" + +#define SERVER_0941 "www.chips.com.tw" +#define SERVER_0943 "www.pager.com.tw" +#define SERVER_0948 "www.fitel.net.tw" +#define SERVER_0947 "www.hoyard.com.tw" +#define SERVER_0945 "203.73.181.254" + +#define CGI_0948 "/cgi-bin/Webpage.dll" +#define CGI_0941 "/cgi-bin/paging1.pl" +#define CGI_0947 "/scripts/fp_page1.dll" +#define CGI_0945 "/Scripts/fiss/PageForm.exe" +#define CGI_0943 "/tpn/tpnasp/dowebcall.asp" + +#define CGI_RAILWAY "http://www.railway.gov.tw/cgi-bin/timetk.cgi" + +#define REFER_0943 "http://www.pager.com.tw/tpn/webcall/webcall.asp" +#define REFER_0948 "http://www.fitel.net.tw/html/svc03.htm" +#define REFER_0941 "http://www.chips.com.tw:9100/WEB2P/page_1.htm" +#define REFER_0947 "http://web1.hoyard.com.tw/freeway/freewayi.html" +#define REFER_0945 "http://203.73.181.254/call.HTM" + +static void pager_msg_encode(char *field, char *buf) { + char *cc = field; + unsigned char *p; + + for(p = (unsigned char *)buf; *p; p++) { + if((*p >= '0' && *p <= '9') || + (*p >= 'A' && *p <= 'Z') || + (*p >= 'a' && *p <= 'z') || + *p == ' ') + *cc++ = *p == ' ' ? '+' : (char)*p; + else { + sprintf(cc, "%%%02X", (int)*p); + cc += 3; + } + } + *cc = 0; +} + +static void gettime(int flag, int *Year, int *Month, int *Day, int *Hour, + int *Minute) { + char ans[5]; + + do { + getdata(10, 0, "年[20-]:", ans, 3, LCECHO); + *Year = atoi(ans); + } while(*Year < 00 || *Year > 02); + do { + getdata(10, 15, "月[1-12]:", ans, 3, LCECHO); + } while(!IsSNum(ans) || (*Month = atoi(ans)) > 12 || *Month < 1); + do { + getdata(10,30, "日[1-31]:", ans, 3, LCECHO); + } while(!IsSNum(ans) || (*Day = atoi(ans)) > 31 || *Day < 1); + do { + getdata(10,45, "時[0-23]:", ans, 3, LCECHO); + } while(!IsSNum(ans) || (*Hour = atoi(ans)) > 23 || *Hour < 0); + do { + getdata(10,60, "分[0-59]:", ans, 3, LCECHO); + } while(!IsSNum(ans) || (*Minute=atoi(ans))>59 || *Minute<0); + if(flag == 1) + *Year-=11; +} + +#define hpressanykey(a) {move(22, 0); prints(a); pressanykey();} + +static int Connect(char *s, char *server) { + FILE *fp = fopen(BBSHOME "/log/bbcall.log", "a"); + int sockfd; + char result[2048]; + struct sockaddr_in serv_addr; + struct hostent *hp; + + sockfd = socket(AF_INET, SOCK_STREAM, 0); + if(sockfd < 0) + return 0; + + memset((char *)&serv_addr, 0, sizeof(serv_addr)); + serv_addr.sin_family = AF_INET; + + if((hp = gethostbyname(server)) == NULL) + return 0; + + memcpy(&serv_addr.sin_addr, hp->h_addr, hp->h_length); + + if(!strcmp(server, SERVER_0941)) + serv_addr.sin_port = htons(9100); + else + serv_addr.sin_port = htons(80); + + if(connect(sockfd, (struct sockaddr *) &serv_addr, sizeof serv_addr)) { + hpressanykey("無法與伺服器取得連結,傳呼失敗"); + return 0; + } else { + mprints(20, 0, "\033[1;33m伺服器已經連接上,請稍後" + ".....................\033[m"); + refresh(); + } + + write(sockfd, s, strlen(s)); + shutdown(sockfd, 1); + + while(read(sockfd, result, sizeof(result)) > 0) { + fprintf(fp, "%s\n", result); + fflush(fp); + if(strstr(result, "正確") || + strstr(result,"等待") || + strstr(result,"再度") || + strstr(result,"完 成 回 應") || + strstr(result, "預約中") || + strstr(result,"傳送中")) { + close(sockfd); + hpressanykey("順利送出傳呼"); + return 0; + } + memset(result, 0, sizeof(result)); + } + fclose(fp); + close(sockfd); + hpressanykey("無法順利送出傳呼"); + return 0; +} + +#define PARA \ +"Connection: Keep-Alive\r\n"\ +"User-Agent: Lynx/2.6 libwww-FM/2.14\r\n"\ +"Content-type: application/x-www-form-urlencoded\r\n"\ +"Accept: text/html, text/plain, application/x-wais-source, "\ +"application/html, */*;q=0.001\r\n"\ +"Accept-Encoding: gzip\r\n"\ +"Accept-Language: en\r\n"\ +"Accept-Charset: iso-8859-1,*,utf-8\r\n" + +static void halpha0943(char* CoId) { + char tmpbuf[64],ans[2]; + char ID[8]; + char Msg[64], atrn[512], sendform[1024]; + int Year = 99, Month = 1, Day = 15, Hour = 13, Minute = 8; + + sprintf(tmpbuf, "\033[1;37m請輸入您要傳呼的號碼\033[m : %s-", CoId); + if(!getdata(7,0, tmpbuf, ID, 7, LCECHO) || + !getdata(8,0, "\033[1;37m請輸入傳呼訊息\033[m:", tmpbuf, 63, LCECHO)) { + hpressanykey("放棄傳呼"); + return; + } + pager_msg_encode(Msg,tmpbuf); + getdata(9, 0, "\033[1;37m如果你要馬上送請按 '1' " + "如果要定時送請按 '2': \033[m", ans, 2, LCECHO); + + if(ans[0] != '1') + gettime(0, &Year, &Month, &Day, &Hour, &Minute); + + sprintf(atrn, "CoId=%s&ID=%s&Year=19%02d&Month=%02d&Day=%02d" + "&Hour=%02d&Minute=%02d&Msg=%s", + CoId, ID,Year,Month,Day,Hour,Minute,Msg); + sprintf(sendform, "POST %s HTTP/1.0\nReferer: " + "%s\n%sContent-length:%d\n\n%s", + CGI_0943, REFER_0943, PARA, strlen(atrn), atrn); + Connect(sendform, SERVER_0943); + return ; +} + +static void hcall0941() { + char ans[2]; + char PAGER_NO[8], TRAN_MSG[18], TIME[8]; + char trn[512], sendform[512]; + int year = 98, month = 12, day = 4, hour = 13, min = 8; + + if(!getdata(7, 0, "\033[1;37 請您輸入您要傳呼的號碼 : 0941- \033[m", + PAGER_NO, 7, LCECHO) || + !getdata(8, 0, "\033[1;37m請輸入傳呼訊息\033[m:", trn, 17, LCECHO)) { + hpressanykey("放棄傳呼"); + return; + } + pager_msg_encode(TRAN_MSG,trn); + getdata(9,0, "\033[1;37m如果你要馬上送請按 '1' " + "如果要定時送請按 '2': \033[m", ans, 2, LCECHO); + if(ans[0] != '1') { + strcpy(TIME,"DELAY"); + gettime(0, &year, &month, &day, &hour, &min); + } else + strcpy(TIME,"NOW"); + sprintf(trn,"PAGER_NO=%s&TRAN_MSG=%s&MSG_TYPE=NUMERIC&%s=1" + "&year=19%02d&month=%02d&day=%02d&hour=%02d&min=%02d", + PAGER_NO, TRAN_MSG, TIME,year,month,day,hour,min); + + sprintf(sendform, "POST %s HTTP/1.0\nReferer: %s\n%s" + "Content-length:%d\n\n%s", + CGI_0941, REFER_0941, PARA, strlen(trn), trn); + + Connect(sendform, SERVER_0941); + return ; +} + +static void hcall0948() { + int year = 87, month = 12, day = 19, hour = 12, min = 0, ya = 0; + char svc_no[8], message[64], trn[256], sendform[512], ans[3]; + + move(7,0); + clrtoeol(); + + if(!getdata(7, 0, "\033[1;37m請輸入您要傳呼的號碼\033[m:0948-", + svc_no, 7, LCECHO) || + !getdata(8, 0, "\033[1;37m請輸入傳呼訊息\033[m:", trn, 61, LCECHO)) { + hpressanykey("放棄傳呼"); + return; + } + pager_msg_encode(message, trn); + getdata(9, 0, "\033[1;37m如果你要馬上送請按 '1' " + "如果要定時送請按 '2'\033[m: ", ans, 2, LCECHO); + if(ans[0] != '1') { + gettime(1, &year, &month, &day, &hour, &min); + ya = 1; + } + + sprintf(trn, "MfcISAPICommand=SinglePage&svc_no=%s&reminder=%d" + "&year=%02d&month=%02d&day=%02d&hour=%02d&min=%02d&message=%s", + svc_no, ya, year, month, day, hour, min, message); + + sprintf(sendform, "GET %s?%s Http/1.0\n\n", CGI_0948, trn); + + Connect(sendform, SERVER_0948); + return; +} + +int main_bbcall() { + char ch[2]; + + clear(); + move(0, 30); + prints("\033[1;37;45m 逼逼摳機 \033[m"); + move(3, 0); + prints("\033[1;31m ┌────────────────────" + "─────────┐\033[m\n"); + prints("\033[1;33m (1)0941 (2)0943 (3)0946 " + " (4)0948 \033[m\n"); + prints("\033[1;31m └────────────────────" + "─────────┘\033[m\n"); + getdata(7, 8, "\033[1;37m你的選擇? [1-4]\033[m", ch, 2, LCECHO); + + switch(ch[0]) { + case '1': + hcall0941(); + break; + case '2': + halpha0943("0943"); + break; + case '3': + halpha0943("0946"); + break; + case '4': + hcall0948(); + break; + } + return 0; +} diff --git a/pttbbs/mbbsd/bbs.c b/pttbbs/mbbsd/bbs.c new file mode 100644 index 00000000..15db1c91 --- /dev/null +++ b/pttbbs/mbbsd/bbs.c @@ -0,0 +1,1904 @@ +/* $Id: bbs.c,v 1.1 2002/03/07 15:13:48 in2 Exp $ */ +#include +#include +#include +#include +#include +#include +#include +#include +#include "config.h" +#include "pttstruct.h" +#include "perm.h" +#include "modes.h" +#include "common.h" +#include "proto.h" + +static int g_board_names(boardheader_t *fhdr) { + AddNameList(fhdr->brdname); + return 0; +} + +extern userec_t cuser; +extern void touchdircache(int bid); +extern int TagNum; + +static void mail_by_link(char* owner, char* title, char* path) { + char genbuf[200]; + fileheader_t mymail; + + sprintf(genbuf,BBSHOME"/home/%c/%s", cuser.userid[0], cuser.userid); + stampfile(genbuf, &mymail); + strcpy(mymail.owner, owner); + sprintf(mymail.title, title); + mymail.savemode = 0; + unlink(genbuf); + Link(path, genbuf); + sprintf(genbuf,BBSHOME"/home/%c/%s/.DIR",cuser.userid[0],cuser.userid); + + append_record(genbuf, &mymail, sizeof(mymail)); +} + +extern int usernum; + +void anticrosspost() { + char buf[200]; + time_t now = time(NULL); + + sprintf(buf, + "\033[1;33;46m%s \033[37;45mcross post 文章 \033[37m %s\033[m", + cuser.userid, ctime(&now)); + log_file("etc/illegal_money", buf); + + post_violatelaw(cuser.userid, "Ptt系統警察", "Cross-post", "罰單處份"); + cuser.userlevel |= PERM_VIOLATELAW; + cuser.vl_count ++; + mail_by_link("Ptt警察部隊", "Cross-Post罰單", + BBSHOME "/etc/crosspost.txt"); + passwd_update(usernum, &cuser); + exit(0); +} + +/* Heat CharlieL*/ +int save_violatelaw() { + char buf[128], ok[3]; + + setutmpmode(VIOLATELAW); + clear(); + stand_title("繳罰單中心"); + + if(!(cuser.userlevel & PERM_VIOLATELAW)) { + mprints(22, 0, "\033[1;31m你無聊啊? 你又沒有被開罰單~~\033[m"); + pressanykey(); + return 0; + } + + reload_money(); + if(cuser.money < (int)cuser.vl_count*1000) { + sprintf(buf, "\033[1;31m這是你第 %d 次違反本站法規" + "必須繳出 %d $Ptt ,你只有 %d 元, 錢不夠啦!!\033[m", + (int)cuser.vl_count, (int)cuser.vl_count * 1000, cuser.money); + mprints(22, 0, buf); + pressanykey(); + return 0; + } + + move(5,0); + prints("\033[1;37m你知道嗎? 因為你的違法 " + "已經造成很多人的不便\033[m\n"); + prints("\033[1;37m你是否確定以後不會再犯了?\033[m\n"); + + if(!getdata(10,0,"確定嗎?[y/n]:", ok, 2, LCECHO) || + ok[0] == 'n' || ok[0] == 'N') { + mprints(22,0,"\033[1;31m等你想通了再來吧!! " + "我相信你不會知錯不改的~~~\033[m"); + pressanykey(); + return 0; + } + + sprintf(buf, "這是你第 %d 次違法 必須繳出 %d $Ptt", + cuser.vl_count, cuser.vl_count*1000); + mprints(11,0,buf); + + if(!getdata(10, 0, "要付錢[y/n]:", ok, 2, LCECHO) || + ok[0] == 'N' || ok[0] == 'n') { + + mprints(22,0, "\033[1;31m 嗯 存夠錢 再來吧!!!\033[m"); + pressanykey(); + return 0; + } + + demoney(-1000*cuser.vl_count); + cuser.userlevel &= (~PERM_VIOLATELAW); + passwd_update(usernum, &cuser); + return 0; +} + +void make_blist() { + CreateNameList(); + apply_boards(g_board_names); +} + +extern int currbid; +extern char currBM[]; +extern int currmode; +extern char currboard[]; +static time_t board_note_time; +static char *brd_title; + +void set_board() { + boardheader_t *bp; + + bp = getbcache(currbid); + board_note_time = bp->bupdate; + brd_title = bp->BM; + if(brd_title[0] <= ' ') + brd_title = "徵求中"; + sprintf(currBM, "板主:%s", brd_title); + brd_title = ((bp->bvote != 2 && bp->bvote) ? "本看板進行投票中" : + bp->title + 7); + currmode = (currmode & (MODE_DIRTY | MODE_MENU)) | MODE_STARTED ; + + if (HAS_PERM(PERM_ALLBOARD) || is_BM(bp->BM)) + currmode = currmode | MODE_BOARD | MODE_POST; + else if(haspostperm(currboard)) + currmode |= MODE_POST; +} + +static void readtitle() { + showtitle(currBM, brd_title); + outs("[←]離開 [→]閱\讀 [^P]發表文章 [b]備忘錄 [d]刪除 [z]精華區 " + "[TAB]文摘 [h]elp\n\033[7m 編號 日 期 作 者 文 章 標 題" + " \033[m"); +} + +extern int brc_num; +extern int brc_list[]; +extern char currtitle[]; + +extern int Tagger(); + +static void readdoent(int num, fileheader_t *ent) { + int type; + char *mark, *title, color; + + type = brc_unread(ent->filename,brc_num,brc_list) ? '+' : ' '; + + if((currmode & MODE_BOARD) && (ent->filemode & FILE_DIGEST)) + type = (type == ' ') ? '*' : '#'; + else if(currmode & MODE_BOARD || HAS_PERM(PERM_LOGINOK)) { + if(ent->filemode & FILE_MARKED) + type = (type == ' ') ? 'm' : 'M'; + + else if (TagNum && !Tagger(atoi(ent->filename + 2), 0, TAG_NIN)) + type = 'D'; + + else if (ent->filemode & FILE_SOLVED) + type = 's'; + } + + title = subject(mark = ent->title); + if(title == mark) + color = '1', mark = "□"; + else + color = '3', mark = "R:"; + + if(title[47]) + strcpy(title + 44, " …"); /* 把多餘的 string 砍掉 */ + + if(strncmp(currtitle, title, 40)) + prints("%6d %c %-7s%-13.12s%s %s\n", num, type, + ent->date, ent->owner, mark, title); + else + prints("%6d %c %-7s%-13.12s\033[1;3%cm%s %s\033[m\n", num, type, + ent->date, ent->owner, color, mark, title); +} + +extern char currfile[]; + +int cmpfilename(fileheader_t *fhdr) { + return (!strcmp(fhdr->filename, currfile)); +} + +extern unsigned char currfmode; + +int cmpfmode(fileheader_t *fhdr) { + return (fhdr->filemode & currfmode); +} + +extern char currowner[]; + +int cmpfowner(fileheader_t *fhdr) { + return !strcasecmp(fhdr->owner, currowner); +} + +extern char *err_bid; +extern userinfo_t *currutmp; + +int whereami(int ent, fileheader_t *fhdr, char *direct) { + boardheader_t *bh, *p[32], *root; + int i,j; + + if(!currutmp->brc_id) return 0; + + move(1,0); + clrtobot(); + bh=getbcache(currutmp->brc_id); + root=getbcache(1); + p[0]=bh; + for(i=0;i<31 && p[i]->parent!=root && p[i]->parent;i++) + p[i+1]=p[i]->parent; + j=i; + prints("我在哪?\n%-40.40s %.13s\n", p[j]->title+7, p[j]->BM); + for(j--;j>=0;j--) + prints("%*s %-13.13s %-37.37s %.13s\n", (i-j)*2, "", + p[j]->brdname, p[j]->title, + p[j]->BM); + + pressanykey(); + return FULLUPDATE; +} +static int do_select(int ent, fileheader_t *fhdr, char *direct) { + char bname[20]; + char bpath[60]; + boardheader_t *bh; + struct stat st; + int i; + + move(0, 0); + clrtoeol(); + make_blist(); + namecomplete(MSG_SELECT_BOARD, bname); + if(bname[0]=='\0' || !(i = getbnum(bname))) + return FULLUPDATE; + bh = getbcache(i); + if(!Ben_Perm(bh)) return FULLUPDATE; + strcpy(bname, bh->brdname); + currbid=i; + + setbpath(bpath, bname); + if((*bname == '\0') || (stat(bpath, &st) == -1)) { + move(2, 0); + clrtoeol(); + outs(err_bid); + return FULLUPDATE; + } + + currutmp->brc_id = currbid; + + brc_initial(bname); + set_board(); + setbdir(direct, currboard); + + move(1, 0); + clrtoeol(); + return NEWDIRECT; +} + +/* ----------------------------------------------------- */ +/* 改良 innbbsd 轉出信件、連線砍信之處理程序 */ +/* ----------------------------------------------------- */ +void outgo_post(fileheader_t *fh, char *board) { + FILE *foo; + + if((foo = fopen("innd/out.bntp", "a"))) { + fprintf(foo, "%s\t%s\t%s\t%s\t%s\n", board, + fh->filename, cuser.userid, cuser.username, fh->title); + fclose(foo); + } +} + +extern char *str_author1; +extern char *str_author2; + +static void cancelpost(fileheader_t *fh, int by_BM) { + FILE *fin, *fout; + char *ptr, *brd; + fileheader_t postfile; + char genbuf[200]; + char nick[STRLEN], fn1[STRLEN], fn2[STRLEN]; + + setbfile(fn1, currboard, fh->filename); + if((fin = fopen(fn1, "r"))) { + brd = by_BM ? "deleted" : "junk"; + + setbpath(fn2, brd); + stampfile(fn2, &postfile); + memcpy(postfile.owner, fh->owner, IDLEN + TTLEN + 10); + postfile.savemode = 'D'; + + if(fh->savemode == 'S') { + nick[0] = '\0'; + while(fgets(genbuf, sizeof(genbuf), fin)) { + if (!strncmp(genbuf, str_author1, LEN_AUTHOR1) || + !strncmp(genbuf, str_author2, LEN_AUTHOR2)) { + if((ptr = strrchr(genbuf, ')'))) + *ptr = '\0'; + if((ptr = (char *)strchr(genbuf, '('))) + strcpy(nick, ptr + 1); + break; + } + } + + if((fout = fopen("innd/cancel.bntp", "a"))) { + fprintf(fout, "%s\t%s\t%s\t%s\t%s\n", currboard, fh->filename, + cuser.userid, nick, fh->title); + fclose(fout); + } + } + + fclose(fin); + Rename(fn1, fn2); + setbdir(genbuf, brd); + append_record(genbuf, &postfile, sizeof(postfile)); + } +} + +extern char *str_reply; +extern char save_title[]; + +/* ----------------------------------------------------- */ +/* 發表、回應、編輯、轉錄文章 */ +/* ----------------------------------------------------- */ +void do_reply_title(int row, char *title) { + char genbuf[200]; + char genbuf2[4]; + + if(strncasecmp(title, str_reply, 4)) + sprintf(save_title, "Re: %s", title); + else + strcpy(save_title, title); + save_title[TTLEN - 1] = '\0'; + sprintf(genbuf, "採用原標題《%.60s》嗎?[Y] ", save_title); + getdata(row, 0, genbuf, genbuf2, 4, LCECHO); + if(genbuf2[0] == 'n' || genbuf2[0] == 'N') + getdata(++row, 0, "標題:", save_title, TTLEN, DOECHO); +} + +static void do_unanonymous_post(char* fpath) { + fileheader_t mhdr; + char title[128]; + char genbuf[200]; + + setbpath(genbuf, "UnAnonymous"); + if(dashd(genbuf)) { + stampfile(genbuf, &mhdr); + unlink(genbuf); + Link(fpath, genbuf); + strcpy(mhdr.owner, cuser.userid); + strcpy(mhdr.title, save_title); + mhdr.savemode = 0; + mhdr.filemode = 0; + setbdir(title, "UnAnonymous"); + append_record(title, &mhdr, sizeof(mhdr)); + } +} + +extern char quote_file[]; +extern char quote_user[]; +extern int curredit; +extern unsigned int currbrdattr; +extern char currdirect[]; +extern char *err_uid; + +#ifdef NO_WATER_POST +static time_t last_post_time = 0; +static time_t water_counts = 0; +#endif +int local_article; +char real_name[20]; + +static int do_general() { + fileheader_t postfile; + char fpath[80], buf[80]; + int aborted, defanony, ifuseanony; + char genbuf[200],*owner; + boardheader_t *bp; + int islocal; + + ifuseanony = 0; + bp = getbcache(currbid); + + clear(); + if(!(currmode & MODE_POST)) { + move(5, 10); + outs("對不起,您目前無法在此發表文章!"); + pressanykey(); + return FULLUPDATE; + } + +#ifdef NO_WATER_POST + /* 三分鐘內最多發表五篇文章 */ + if(currutmp->lastact - last_post_time < 60 * 3) { + if(water_counts >= 5) { + move(5, 10); + outs("對不起,您的文章太水囉,多思考一下,待會再post吧!"); + pressanykey(); + return FULLUPDATE; + } + } else { + last_post_time = currutmp->lastact; + water_counts = 0; + } +#endif + + setbfile(genbuf, currboard, FN_POST_NOTE ); + + if(more(genbuf,NA) == -1) + more("etc/"FN_POST_NOTE , NA); + + move(19,0); + prints("發表文章於【\033[33m %s\033[m 】 \033[32m%s\033[m 看板\n\n", + currboard, bp->title + 7); + + if(quote_file[0]) + do_reply_title(20, currtitle); + else { + getdata(21, 0, "標題:", save_title, TTLEN, DOECHO); + strip_ansi(save_title,save_title,0); + } + if(save_title[0] == '\0') + return FULLUPDATE; + + curredit &= ~EDIT_MAIL; + curredit &= ~EDIT_ITEM; + setutmpmode(POSTING); + + /* 未具備 Internet 權限者,只能在站內發表文章 */ + if(HAS_PERM(PERM_INTERNET)) + local_article = 0; + else + local_article = 1; + + /* build filename */ + setbpath(fpath, currboard); + stampfile(fpath, &postfile); + + aborted = vedit(fpath, YEA, &islocal); + if(aborted == -1) { + unlink(fpath); + pressanykey(); + return FULLUPDATE; + } + water_counts++; /* po成功 */ + + /* set owner to Anonymous , for Anonymous board */ + +#ifdef HAVE_ANONYMOUS + /* Ptt and Jaky */ + defanony=currbrdattr & BRD_DEFAULTANONYMOUS; + if((currbrdattr & BRD_ANONYMOUS) && + ((strcmp(real_name,"r") && defanony) || (real_name[0] && !defanony)) + ) { + strcat(real_name,"."); + owner = real_name; + ifuseanony=1; + } else + owner = cuser.userid; +#else + owner = cuser.userid; +#endif + /* 錢 */ + aborted = (aborted > MAX_POST_MONEY * 2) ? MAX_POST_MONEY : aborted / 2; + postfile.money = aborted; + strcpy(postfile.owner, owner); + strcpy(postfile.title, save_title); + if(islocal) { /* local save */ + postfile.savemode = 'L'; + postfile.filemode = FILE_LOCAL; + } else + postfile.savemode = 'S'; + + setbdir(buf, currboard); + if(append_record(buf, &postfile, sizeof(postfile)) != -1) { + setbtotal(currbid); + + if(currmode & MODE_SELECT) + append_record(currdirect,&postfile,sizeof(postfile)); + if(!islocal && !(bp->brdattr & BRD_NOTRAN)) + outgo_post(&postfile, currboard); + brc_addlist(postfile.filename); + + if(!(currbrdattr & BRD_HIDE) && + (!bp->level || (currbrdattr & BRD_POSTMASK))) { + setbpath(genbuf, ALLPOST); + stampfile(genbuf, &postfile); + unlink(genbuf); + + /* jochang: boards may spread across many disk */ + /* link doesn't work across device, + Link doesn't work if we have same-time-across-device posts, + we try symlink now */ + { + /* we need absolute path for symlink */ + char abspath[256]=BBSHOME"/"; + strcat(abspath,fpath); + symlink(abspath,genbuf); + } + strcpy(postfile.owner, owner); + strcpy(postfile.title, save_title); + postfile.savemode = 'L'; + setbdir(genbuf, ALLPOST); + if(append_record(genbuf, &postfile, sizeof(postfile)) != -1) { + setbtotal(getbnum(ALLPOST)); + } + } + + outs("順利貼出佈告,"); + +#ifdef MAX_POST_MONEY + aborted = (aborted > MAX_POST_MONEY) ? MAX_POST_MONEY : aborted; +#endif + if(strcmp(currboard, "Test") && !ifuseanony) { + prints("這是您的第 %d 篇文章。 稿酬 %d 銀。", + ++cuser.numposts, aborted ); + demoney(aborted); + passwd_update(usernum, &cuser); /* post 數 */ + } else + outs("測試信件不列入紀錄,敬請包涵。"); + + /* 回應到原作者信箱 */ + + if(curredit & EDIT_BOTH) { + char *str, *msg = "回應至作者信箱"; + + if((str = strchr(quote_user, '.'))) { + if( +#ifndef USE_BSMTP + bbs_sendmail(fpath, save_title, str + 1) +#else + bsmtp(fpath, save_title, str + 1 ,0) +#endif + < 0) + msg = "作者無法收信"; + } else { + sethomepath(genbuf, quote_user); + stampfile(genbuf, &postfile); + unlink(genbuf); + Link(fpath, genbuf); + + strcpy(postfile.owner, cuser.userid); + strcpy(postfile.title, save_title); + postfile.savemode = 'B';/* both-reply flag */ + sethomedir(genbuf, quote_user); + if(append_record(genbuf, &postfile, sizeof(postfile)) == -1) + msg = err_uid; + } + outs(msg); + curredit ^= EDIT_BOTH; + } + if(currbrdattr & BRD_ANONYMOUS) + do_unanonymous_post(fpath); + } + pressanykey(); + return FULLUPDATE; +} + +int do_post() { + boardheader_t *bp; + bp = getbcache(currbid); + if(bp->brdattr & BRD_VOTEBOARD) + return do_voteboard(); + else if(!(bp->brdattr & BRD_GROUPBOARD)) + return do_general(); + touchdircache(currbid); + return 0; +} + +extern int b_lines; +extern int curredit; + +static void do_generalboardreply(fileheader_t *fhdr){ + char genbuf[200]; + getdata(b_lines - 1, 0, + "▲ 回應至 (F)看板 (M)作者信箱 (B)二者皆是 (Q)取消?[F] ", + genbuf, 3, LCECHO); + switch(genbuf[0]) { + case 'm': + mail_reply(0, fhdr, 0); + case 'q': + break; + + case 'b': + curredit = EDIT_BOTH; + default: + strcpy(currtitle, fhdr->title); + strcpy(quote_user, fhdr->owner); + quote_file[79] = fhdr->savemode; + do_post(); + } + *quote_file = 0; +} + +int getindex(char *fpath, char *fname, int size) { + int fd, now=0; + fileheader_t fhdr; + + if((fd = open(fpath, O_RDONLY, 0)) != -1) { + while((read(fd, &fhdr, size) == size)) { + now++; + if(!strcmp(fhdr.filename,fname)) { + close(fd); + return now; + } + } + close(fd); + } + return 0; +} + +int invalid_brdname(char *brd) { + register char ch; + + ch = *brd++; + if(not_alnum(ch)) + return 1; + while((ch = *brd++)) { + if(not_alnum(ch) && ch != '_' && ch != '-' && ch != '.') + return 1; + } + return 0; +} + +static void do_reply(fileheader_t *fhdr) { + boardheader_t *bp; + bp = getbcache(currbid); + if (bp->brdattr & BRD_VOTEBOARD) + do_voteboardreply(fhdr); + else + do_generalboardreply(fhdr); +} + +static int reply_post(int ent, fileheader_t *fhdr, char *direct) { + if(!(currmode & MODE_POST)) + return DONOTHING; + + setdirpath(quote_file, direct, fhdr->filename); + do_reply(fhdr); + *quote_file = 0; + return FULLUPDATE; +} + +static int edit_post(int ent, fileheader_t *fhdr, char *direct) { + char fpath[80], fpath0[80]; + char genbuf[200]; + fileheader_t postfile; + boardheader_t *bp; + bp = getbcache(currbid); + if (!HAS_PERM(PERM_SYSOP) && (bp->brdattr & BRD_VOTEBOARD)) + return DONOTHING; + + if ((!HAS_PERM(PERM_SYSOP)) && + strcmp(fhdr->owner, cuser.userid)) + return DONOTHING; + setutmpmode(REEDIT); + setdirpath(genbuf, direct, fhdr->filename); + local_article = fhdr->filemode & FILE_LOCAL; + strcpy(save_title, fhdr->title); + +/* rocker.011018: 這裡是不是該檢查一下修改文章後的money和原有的比較? */ + if(vedit(genbuf, 0, NULL) != -1) { + setbpath(fpath, currboard); + stampfile(fpath, &postfile); + unlink(fpath); + setbfile(fpath0, currboard, fhdr->filename); + + Rename(fpath0, fpath); + +/* rocker.011018: fix 串接模式改文章後文章就不見的bug */ + if ((currmode & MODE_SELECT) && (fhdr->money & FHR_REFERENCE)) + { + fileheader_t hdr; + int num; + + num = fhdr->money & ~FHR_REFERENCE; + setbdir(fpath0, currboard); + get_record(fpath0, &hdr, sizeof (hdr), num); + + /* 再這裡要check一下原來的dir裡面是不是有被人動過... */ + if (!strcmp (hdr.filename, fhdr->filename)) + { + strcpy(hdr.filename, postfile.filename); + strcpy(hdr.title, save_title); + substitute_record(fpath0, &hdr, sizeof(hdr), num); + } + } + + strcpy(fhdr->filename, postfile.filename); + strcpy(fhdr->title, save_title); + brc_addlist(postfile.filename); + substitute_record(direct, fhdr, sizeof(*fhdr), ent); +/* rocker.011018: 順便更新一下cache */ + touchdircache(currbid); + } + return FULLUPDATE; +} + +extern crosspost_t postrecord; +#define UPDATE_USEREC (currmode |= MODE_DIRTY) + +static int cross_post(int ent, fileheader_t *fhdr, char *direct) { + char xboard[20], fname[80], xfpath[80], xtitle[80], inputbuf[10]; + fileheader_t xfile; + FILE *xptr; + int author = 0; + char genbuf[200]; + char genbuf2[4]; + boardheader_t *bp; + make_blist(); + move(2, 0); + clrtoeol(); + move(3, 0); + clrtoeol(); + move(1, 0); + bp = getbcache(currbid); + if (bp && (bp->brdattr & BRD_VOTEBOARD)) + return FULLUPDATE; + namecomplete("轉錄本文章於看板:", xboard); + if(*xboard == '\0' || !haspostperm(xboard)) + return FULLUPDATE; + + if((ent = str_checksum(fhdr->title)) != 0 && + ent == postrecord.checksum[0]) { + /* 檢查 cross post 次數 */ + if(postrecord.times++ > MAX_CROSSNUM) + anticrosspost(); + } else { + postrecord.times = 0; + postrecord.checksum[0] = ent; + } + + ent = 1; + if(HAS_PERM(PERM_SYSOP) || !strcmp(fhdr->owner, cuser.userid)) { + getdata(2, 0, "(1)原文轉載 (2)舊轉錄格式?[1] ", + genbuf, 3, DOECHO); + if(genbuf[0] != '2') { + ent = 0; + getdata(2, 0, "保留原作者名稱嗎?[Y] ", inputbuf, 3, DOECHO); + if (inputbuf[0] != 'n' && inputbuf[0] != 'N') author = 1; + } + } + + if(ent) + sprintf(xtitle, "[轉錄]%.66s", fhdr->title); + else + strcpy(xtitle, fhdr->title); + + sprintf(genbuf, "採用原標題《%.60s》嗎?[Y] ", xtitle); + getdata(2, 0, genbuf, genbuf2, 4, LCECHO); + if(genbuf2[0] == 'n' || genbuf2[0] == 'N') { + if(getdata_str(2, 0, "標題:", genbuf, TTLEN, DOECHO,xtitle)) + strcpy(xtitle, genbuf); + } + + getdata(2, 0, "(S)存檔 (L)站內 (Q)取消?[Q] ", genbuf, 3, LCECHO); + if(genbuf[0] == 'l' || genbuf[0] == 's') { + int currmode0 = currmode; + + currmode = 0; + setbpath(xfpath, xboard); + stampfile(xfpath, &xfile); + if(author) + strcpy(xfile.owner, fhdr->owner); + else + strcpy(xfile.owner, cuser.userid); + strcpy(xfile.title, xtitle); + if(genbuf[0] == 'l') { + xfile.savemode = 'L'; + xfile.filemode = FILE_LOCAL; + } else + xfile.savemode = 'S'; + + setbfile(fname, currboard, fhdr->filename); +// if(ent) { + xptr = fopen(xfpath, "w"); + + strcpy(save_title, xfile.title); + strcpy(xfpath, currboard); + strcpy(currboard, xboard); + write_header(xptr); + strcpy(currboard, xfpath); + + fprintf(xptr, "※ [本文轉錄自 %s 看板]\n\n", currboard); + + b_suckinfile(xptr, fname); + addsignature(xptr,0); + fclose(xptr); +/* Cross fs有問題 + } else { + unlink(xfpath); + link(fname, xfpath); + } +*/ + setbdir(fname, xboard); + append_record(fname, &xfile, sizeof(xfile)); + bp = getbcache(getbnum(xboard)); + if(!xfile.filemode && !(bp->brdattr && BRD_NOTRAN)) + outgo_post(&xfile, xboard); + setbtotal(getbnum(xboard)); + cuser.numposts++; + UPDATE_USEREC; + outs("文章轉錄完成"); + pressanykey(); + currmode = currmode0; + } + return FULLUPDATE; +} + +static int read_post(int ent, fileheader_t *fhdr, char *direct) { + char genbuf[200]; + int more_result; + + if(fhdr->owner[0] == '-') + return DONOTHING; + + setdirpath(genbuf, direct, fhdr->filename); + + if((more_result = more(genbuf, YEA)) == -1) + return DONOTHING; + + brc_addlist(fhdr->filename); + strncpy(currtitle, subject(fhdr->title), 40); + strncpy(currowner, subject(fhdr->owner), IDLEN + 2); + + switch (more_result) { + case 1: + return READ_PREV; + case 2: + return RELATE_PREV; + case 3: + return READ_NEXT; + case 4: + return RELATE_NEXT; + case 5: + return RELATE_FIRST; + case 6: + return FULLUPDATE; + case 7: + case 8: + if((currmode & MODE_POST)) { + strcpy(quote_file, genbuf); + do_reply(fhdr); + *quote_file = 0; + } + return FULLUPDATE; + case 9: + return 'A'; + case 10: + return 'a'; + case 11: + return '/'; + case 12: + return '?'; + } + + + outmsg("\033[34;46m 閱\讀文章 \033[31;47m (R/Y)\033[30m回信 \033[31m" + "(=[]<>)\033[30m相關主題 \033[31m(↑↓)\033[30m上下封 \033[31m(←)" + "\033[30m離開 \033[m"); + + switch(egetch()) { + case 'q': + case 'Q': + case KEY_LEFT: + break; + + case ' ': + case KEY_RIGHT: + case KEY_DOWN: + case KEY_PGDN: + case 'n': + case Ctrl('N'): + return READ_NEXT; + + case KEY_UP: + case 'p': + case Ctrl('P'): + case KEY_PGUP: + return READ_PREV; + + case '=': + return RELATE_FIRST; + + case ']': + case 't': + return RELATE_NEXT; + + case '[': + return RELATE_PREV; + + case '.': + case '>': + return THREAD_NEXT; + + case ',': + case '<': + return THREAD_PREV; + + case Ctrl('C'): + cal(); + return FULLUPDATE; + break; + + case Ctrl('I'): + t_idle(); + return FULLUPDATE; + case 'y': + case 'r': + case 'R': + case 'Y': + if((currmode & MODE_POST)) { + strcpy(quote_file, genbuf); + do_reply(fhdr); + *quote_file = 0; + } + } + return FULLUPDATE; +} + +/* ----------------------------------------------------- */ +/* 採集精華區 */ +/* ----------------------------------------------------- */ +static int b_man() { + char buf[64]; + + setapath(buf, currboard); + if( (currmode & MODE_BOARD) || HAS_PERM(PERM_SYSOP) ){ + char genbuf[128]; + int fd; + sprintf(genbuf, "%s/.rebuild", buf); + if( (fd = open(genbuf, O_CREAT, 0640)) > 0 ) + close(fd); + } + return a_menu(currboard, buf, HAS_PERM(PERM_ALLBOARD) ? 2 : + (currmode & MODE_BOARD ? 1 : 0)); +} + +#ifndef NO_GAMBLE +static int join_gamble(int ent, fileheader_t *fhdr, char *direct) { + ticket(currbid); + return FULLUPDATE; +} +static int hold_gamble(int ent, fileheader_t *fhdr, char *direct) { + char fn_ticket[128],fn_ticket_end[128],genbuf[128], + msg[256]="",yn[10]=""; + int i; + FILE *fp=NULL; + + if(!(currmode & MODE_BOARD)) return 0; + setbfile(fn_ticket, currboard, FN_TICKET); + setbfile(fn_ticket_end, currboard, FN_TICKET_END); + if(dashf(fn_ticket)) + { + getdata(b_lines - 1, 0, "已經有舉辦賭盤, " + "是否要 [停止下注]?(N/y):", yn, 3, LCECHO); + if(yn[0]!='y') return FULLUPDATE; + rename(fn_ticket, fn_ticket_end); + return FULLUPDATE; + } + + if(dashf(fn_ticket_end)) + { + getdata(b_lines - 1, 0, "已經有舉辦賭盤, " + "是否要 [開獎]?(N/y):", yn, 3, LCECHO); + if(yn[0]!='y') return FULLUPDATE; + openticket(currbid); + return FULLUPDATE; + } + getdata(b_lines - 2, 0, "要舉辦賭盤 (N/y):", yn, 3, LCECHO); + if(yn[0]!='y') return FULLUPDATE; + getdata(b_lines - 1, 0, "賭什麼? 請輸入主題 (輸入後編輯內容):", + msg, 20, DOECHO); + if(msg[0]==0 || + vedit(fn_ticket_end, NA, NULL)<0) + return FULLUPDATE; + + clear(); + showtitle("舉辦賭盤",BBSNAME); + setbfile(genbuf, currboard, FN_TICKET_ITEMS); + +// sprintf(genbuf, "%s/"FN_TICKET_ITEMS, direct); + + if(!(fp=fopen(genbuf,"w"))) return FULLUPDATE; + do + { + getdata(2, 0, "輸入彩票價格 (價格:10-10000):",yn,6, LCECHO); + i=atoi(yn); + } while( i<10 || i>10000); + fprintf(fp,"%d\n",i); + move(3,0); + sprintf(genbuf,"請到 %s 版 按'f'參與賭博!\n\n一張 %d Ptt幣, 這是%s的賭博\n", + currboard, + i, i<100 ? "小賭式" : i<500 ? "平民級": + i<1000 ?"貴族級" : i<5000 ?"富豪級" : "傾家蕩產"); + strcat(msg, genbuf); + prints("請依次輸入彩票名稱, 需提供2~8項. (未滿八項, 輸入直接按enter)\n"); + for(i=0; i<8; i++) + { + sprintf(yn, " %d)",i+1); + getdata(6+i, 0, yn, genbuf, 9, DOECHO); + if(!genbuf[0] && i>1) + break; + fprintf(fp,"%s\n",genbuf); + } + fclose(fp); + move(8+i,0); + prints("賭盤設定完成"); + sprintf(genbuf,"[公告] %s 版 開始賭博!", currboard); + post_msg(currboard, genbuf, msg, cuser.userid); + post_msg("Record", genbuf+7, msg, "[馬路探子]"); + /* Tim 控制CS, 以免正在玩的user把資料已經寫進來 */ + rename(fn_ticket_end, fn_ticket); // 設定完才把檔名改過來 + + return FULLUPDATE; +} +#endif + +static int cite_post(int ent, fileheader_t *fhdr, char *direct) { + char fpath[256]; + char title[TTLEN + 1]; + + setbfile(fpath, currboard, fhdr->filename); + strcpy(title, "◇ "); + strncpy(title+3, fhdr->title, TTLEN-3); + title[TTLEN] = '\0'; + a_copyitem(fpath, title, 0, 1); + b_man(); + return FULLUPDATE; +} + +int edit_title(int ent, fileheader_t *fhdr, char *direct) { + char genbuf[200]; + fileheader_t tmpfhdr = *fhdr; + int dirty = 0; + + if(currmode & MODE_BOARD || !strcmp(cuser.userid,fhdr->owner)) { + if(getdata(b_lines - 1, 0, "標題:", genbuf, TTLEN, DOECHO)) { + strcpy(tmpfhdr.title, genbuf); + dirty++; + } + } + + if(HAS_PERM(PERM_SYSOP)) { + if(getdata(b_lines - 1, 0, "作者:", genbuf, IDLEN + 2, DOECHO)) { + strcpy(tmpfhdr.owner, genbuf); + dirty++; + } + + if(getdata(b_lines - 1, 0, "日期:", genbuf, 6, DOECHO)) { + sprintf(tmpfhdr.date, "%.5s", genbuf); + dirty++; + } + } + + if(currmode & MODE_BOARD || !strcmp(cuser.userid,fhdr->owner)) { + getdata(b_lines-1, 0, "確定(Y/N)?[n] ", genbuf, 3, DOECHO); + if((genbuf[0] == 'y' || genbuf[0] == 'Y') && dirty) { + *fhdr = tmpfhdr; + substitute_record(direct, fhdr, sizeof(*fhdr), ent); +/* rocker.011018: 這裡應該改成用reference的方式取得原來的檔案 */ +#if 0 + if((currmode & MODE_SELECT)) { + int now; + + setbdir(genbuf, currboard); + now = getindex(genbuf, fhdr->filename, sizeof(fileheader_t)); + substitute_record(genbuf, fhdr, sizeof(*fhdr), now); + } +#else + if ((currmode & MODE_SELECT) && (fhdr->money & FHR_REFERENCE)) + { + fileheader_t hdr; + int num; + + num = fhdr->money & ~FHR_REFERENCE; + setbdir(genbuf, currboard); + get_record(genbuf, &hdr, sizeof (hdr), num); + + /* 再這裡要check一下原來的dir裡面是不是有被人動過... */ + if (strcmp (hdr.filename, fhdr->filename)) + num = getindex(genbuf, fhdr->filename, sizeof(fileheader_t)); + + substitute_record(genbuf, fhdr, sizeof(*fhdr), num); + } +#endif + touchdircache(currbid); + } + return FULLUPDATE; + } + return DONOTHING; +} + +extern unsigned int currstat; + +static int solve_post(int ent, fileheader_t * fhdr, char *direct){ + if (HAS_PERM(PERM_SYSOP)) { + fhdr->filemode ^= FILE_SOLVED; + substitute_record(direct, fhdr, sizeof(*fhdr), ent); + touchdircache(currbid); + return PART_REDRAW; + } + return DONOTHING; +} + +static int mark_post(int ent, fileheader_t *fhdr, char *direct) { + + if(!(currmode & MODE_BOARD)) return DONOTHING; + + fhdr->filemode ^= FILE_MARKED; + substitute_record(direct, fhdr, sizeof(*fhdr), ent); + + /* rocker.011018: 串接模式用reference增進效率 */ + if ((currmode & MODE_SELECT) && (fhdr->money & FHR_REFERENCE)) + { + fileheader_t hdr; + char genbuf[100]; + int num; + + num = fhdr->money & ~FHR_REFERENCE; + setbdir(genbuf, currboard); + get_record(genbuf, &hdr, sizeof (hdr), num); + + /* 再這裡要check一下原來的dir裡面是不是有被人動過... */ + if (strcmp (hdr.filename, fhdr->filename)) + num = getindex(genbuf, fhdr->filename, sizeof(fileheader_t)); + + substitute_record(genbuf, fhdr, sizeof(*fhdr), num); + } + touchdircache(currbid); + return PART_REDRAW; +} + +extern char *msg_sure_ny; + +int del_range(int ent, fileheader_t *fhdr, char *direct) { + char num1[8], num2[8]; + int inum1, inum2; + +/* rocker.011018: 串接模式下還是不允許刪除比較好 */ + if(currmode & MODE_SELECT) { + outmsg("請先回到正常模式後再進行刪除..."); + refresh(); + /*safe_sleep(1);*/ + return FULLUPDATE; + } + + if((currstat != READING) || (currmode & MODE_BOARD)) { + getdata(1, 0, "[設定刪除範圍] 起點:", num1, 5, DOECHO); + inum1 = atoi(num1); + if(inum1 <= 0) { + outmsg("起點有誤"); + refresh(); + /*safe_sleep(1);*/ + return FULLUPDATE; + } + getdata(1, 28, "終點:", num2, 5, DOECHO); + inum2 = atoi(num2); + if(inum2 < inum1) { + outmsg("終點有誤"); + refresh(); + /*safe_sleep(1);*/ + return FULLUPDATE; + } + getdata(1, 48, msg_sure_ny, num1, 3, LCECHO); + if(*num1 == 'y') { + outmsg("處理中,請稍後..."); + refresh(); + if(currmode & MODE_SELECT) { + int fd,size = sizeof(fileheader_t); + char genbuf[100]; + fileheader_t rsfh; + int i = inum1,now; + if(currstat == RMAIL) + sethomedir(genbuf, cuser.userid); + else + setbdir(genbuf,currboard); + if((fd = (open(direct, O_RDONLY, 0))) != -1) { + if(lseek(fd, (off_t)(size * (inum1 - 1)), SEEK_SET) != + -1) { + while(read(fd,&rsfh,size) == size) { + if(i > inum2) + break; + now = getindex(genbuf, rsfh.filename, size); + strcpy(currfile, rsfh.filename); + delete_file(genbuf, sizeof(fileheader_t), now, + cmpfilename); + i++; + } + } + close(fd); + } + } + + delete_range(direct, inum1, inum2); + fixkeep(direct, inum1); + + if(currmode & MODE_BOARD) + setbtotal(currbid); + + return DIRCHANGED; + } + return FULLUPDATE; + } + return DONOTHING; +} + +extern char *msg_del_ny; +extern char *msg_del_ok; + +static int del_post(int ent, fileheader_t *fhdr, char *direct) { + char genbuf[100]; + int not_owned; + boardheader_t *bp; + + bp = getbcache(currbid); + + if((fhdr->filemode & FILE_MARKED) || (fhdr->filemode & FILE_DIGEST) || + (fhdr->owner[0] == '-')) + return DONOTHING; + + not_owned = strcmp(fhdr->owner, cuser.userid); + if((!(currmode & MODE_BOARD) && not_owned) || + ((bp->brdattr & BRD_VOTEBOARD) && !HAS_PERM(PERM_SYSOP)) || + !strcmp(cuser.userid, STR_GUEST)) + return DONOTHING; + + getdata(1, 0, msg_del_ny, genbuf, 3, LCECHO); + if(genbuf[0] == 'y' || genbuf[0] == 'Y') { + strcpy(currfile, fhdr->filename); + + setbfile(genbuf,currboard,fhdr->filename); + if(!delete_file (direct, sizeof(fileheader_t), ent, cmpfilename)) { + + if(currmode & MODE_SELECT) + { + /* rocker.011018: 利用reference減低loading */ + fileheader_t hdr; + int num; + + num = fhdr->money & ~FHR_REFERENCE; + setbdir(genbuf, currboard); + get_record(genbuf, &hdr, sizeof (hdr), num); + + /* 再這裡要check一下原來的dir裡面是不是有被人動過... */ + if (strcmp (hdr.filename, fhdr->filename)) + { + num=getindex(genbuf,fhdr->filename,sizeof(fileheader_t)); + get_record(genbuf, &hdr, sizeof (hdr), num); + } + + /* rocker.011018: 這裡要還原被破壞的money */ + fhdr->money = hdr.money; + delete_file (genbuf, sizeof(fileheader_t), num, cmpfilename); + } + +#if 0 + { + setbdir(genbuf,currboard); + now=getindex(genbuf,fhdr->filename,sizeof(fileheader_t)); + delete_file (genbuf, sizeof(fileheader_t),now,cmpfilename); + } +#endif + cancelpost(fhdr, not_owned); + + setbtotal(currbid); + if (fhdr->money < 0) + fhdr->money = 0; + if (not_owned && strcmp(currboard, "Test")){ + deumoney(searchuser(fhdr->owner), -fhdr->money); + } + if(!not_owned && strcmp(currboard, "Test")) { + if(cuser.numposts) + cuser.numposts--; + move(b_lines - 1, 0); + clrtoeol(); + demoney(-fhdr->money); + passwd_update(usernum, &cuser); /* post 數 */ + prints("%s,您的文章減為 %d 篇,支付清潔費 %d 銀", msg_del_ok, + cuser.numposts,fhdr->money); + refresh(); + pressanykey(); + } + return DIRCHANGED; + } + } + return FULLUPDATE; +} + +static int view_postmoney(int ent, fileheader_t *fhdr, char *direct) { + move(b_lines - 1, 0); + clrtoeol(); + prints("這一篇文章值 %d 銀", fhdr->money); + refresh(); + pressanykey(); + return FULLUPDATE; +} + +#ifdef OUTJOBSPOOL +/* 看版備份 */ +static int tar_addqueue(int ent, fileheader_t *fhdr, char *direct) { + char email[60], qfn[80], ans[2]; + FILE *fp; + char bakboard, bakman; + clear(); + showtitle("看版備份", BBSNAME); + move(2, 0); + if( !((currmode & MODE_BOARD) || HAS_PERM(PERM_SYSOP)) ) { + move(5, 10); + outs("妳要是版主或是站長才能醬醬啊 -.-\"\""); + pressanykey(); + return FULLUPDATE; + } + + sprintf(qfn, BBSHOME "/jobspool/tarqueue.%s", currboard); + if( access(qfn, 0) == 0 ){ + outs("已經排定行程, 稍後會進行備份"); + pressanykey(); + return FULLUPDATE; + } + if( !getdata(4, 0, "請輸入目的信箱:", email, sizeof(email), DOECHO) ) + return FULLUPDATE; + + /* check email -.-"" */ + if( strstr(email, "@") == NULL || strstr(email, ".bbs@") != NULL ){ + move(6, 0); + outs("您指定的信箱不正確! "); + pressanykey(); + return FULLUPDATE; + } + + getdata(6, 0, "要備份看版內容嗎(Y/N)?[Y]", ans, 2, LCECHO); + bakboard = (ans[0] == 'n' || ans[0] =='N') ? 0 : 1; + getdata(7, 0, "要備份精華區內容嗎(Y/N)?[N]", ans, 2, LCECHO); + bakman = (ans[0] == 'y' || ans[0] =='Y') ? 1 : 0; + if( !bakboard && !bakman ){ + move(8, 0); + outs("可是我們只能備份看版或精華區的耶 ^^\"\"\""); + pressanykey(); + return FULLUPDATE; + } + + fp = fopen(qfn, "w"); + fprintf(fp, "%s\n", cuser.userid); + fprintf(fp, "%s\n", email); + fprintf(fp, "%d,%d\n", bakboard, bakman); + fclose(fp); + + move(10, 0); + outs("系統已經將您的備份排入行程, \n"); + outs("稍後將會在系統負荷較低的時候將資料寄給您~ :) "); + pressanykey(); + return FULLUPDATE; +} +#endif + +static int sequent_ent; +static int continue_flag; + +/* ----------------------------------------------------- */ +/* 依序讀新文章 */ +/* ----------------------------------------------------- */ +static int sequent_messages(fileheader_t *fptr) { + static int idc; + char genbuf[200]; + + if(fptr == NULL) + return (idc = 0); + + if(++idc < sequent_ent) + return 0; + + if(!brc_unread(fptr->filename,brc_num,brc_list)) + return 0; + + if(continue_flag) + genbuf[0] = 'y'; + else { + prints("讀取文章於:[%s] 作者:[%s]\n標題:[%s]", + currboard, fptr->owner, fptr->title); + getdata(3, 0, "(Y/N/Quit) [Y]: ", genbuf, 3, LCECHO); + } + + if(genbuf[0] != 'y' && genbuf[0]) { + clear(); + return (genbuf[0] == 'q' ? QUIT : 0); + } + + setbfile(genbuf, currboard, fptr->filename); + brc_addlist(fptr->filename); + + if(more(genbuf, YEA) == 0) + outmsg("\033[31;47m \033[31m(R)\033[30m回信 \033[31m(↓,n)" + "\033[30m下一封 \033[31m(←,q)\033[30m離開 \033[m"); + continue_flag = 0; + + switch(egetch()) { + case KEY_LEFT: + case 'e': + case 'q': + case 'Q': + break; + + case 'y': + case 'r': + case 'Y': + case 'R': + if(currmode & MODE_POST) { + strcpy(quote_file, genbuf); + do_reply(fptr); + *quote_file = 0; + } + break; + + case ' ': + case KEY_DOWN: + case '\n': + case 'n': + continue_flag = 1; + } + + clear(); + return 0; +} + +static int sequential_read(int ent, fileheader_t *fhdr, char *direct) { + char buf[40]; + + clear(); + sequent_messages((fileheader_t *) NULL); + sequent_ent = ent; + continue_flag = 0; + setbdir(buf, currboard); + apply_record(buf, sequent_messages, sizeof(fileheader_t)); + return FULLUPDATE; +} + +extern char *fn_notes; +extern char *msg_cancel; +extern char *fn_board; + +/* ----------------------------------------------------- */ +/* 看板備忘錄、文摘、精華區 */ +/* ----------------------------------------------------- */ +int b_note_edit_bname(int bid) { + char buf[64]; + int aborted; + boardheader_t *fh=getbcache(bid); + + setbfile(buf, fh->brdname, fn_notes); + aborted = vedit(buf, NA, NULL); + if(aborted == -1) { + clear(); + outs(msg_cancel); + pressanykey(); + } else { + aborted = (fh->bupdate - time(0)) / 86400 + 1; + sprintf(buf,"%d", aborted > 0 ? aborted : 0); + getdata_buf(3, 0, "請設定有效期限(0 - 9999)天?", buf, 5, DOECHO); + aborted = atoi(buf); + fh->bupdate = aborted ? time(0) + aborted * 86400 : 0; + substitute_record(fn_board, fh, sizeof(boardheader_t), bid); + } + return 0; +} + +static int b_notes_edit() { + if(currmode & MODE_BOARD) { + b_note_edit_bname(currbid); + return FULLUPDATE; + } + return 0; +} + +static int b_water_edit() { + if(currmode & MODE_BOARD) { + friend_edit(BOARD_WATER); + return FULLUPDATE; + } + return 0; +} + +static int visable_list_edit() { + if(currmode & MODE_BOARD) { + friend_edit(BOARD_VISABLE); + hbflreload(currbid); + return FULLUPDATE; + } + return 0; +} + +static int b_post_note() { + char buf[200], yn[3]; + + if(currmode & MODE_BOARD) { + setbfile(buf, currboard, FN_POST_NOTE ); + if(more(buf,NA) == -1) more("etc/"FN_POST_NOTE , NA); + getdata(b_lines - 2, 0, "是否要用自訂post注意事項?", yn, 3, LCECHO); + if(yn[0] == 'y') + vedit(buf, NA, NULL); + else + unlink(buf); + return FULLUPDATE; + } + return 0; +} + +static int b_application() { + char buf[200]; + + if(currmode & MODE_BOARD) { + setbfile(buf, currboard, FN_APPLICATION); + vedit(buf, NA, NULL); + return FULLUPDATE; + } + return 0; +} + +static int can_vote_edit() { + if(currmode & MODE_BOARD) { + friend_edit(FRIEND_CANVOTE); + return FULLUPDATE; + } + return 0; +} + +static int bh_title_edit() { + boardheader_t *bp; + + if(currmode & MODE_BOARD) { + char genbuf[BTLEN]; + + bp = getbcache(currbid); + move(1,0); + clrtoeol(); + getdata_str(1,0,"請輸入看板新中文敘述:", genbuf,BTLEN - + 16,DOECHO, bp->title + 7); + + if(!genbuf[0]) + return 0; + strip_ansi( genbuf,genbuf,0); + strcpy(bp->title + 7,genbuf); + substitute_record(fn_board, bp, sizeof(boardheader_t), currbid); + log_usies("SetBoard", currboard); + return FULLUPDATE; + } + return 0; +} + +static int b_notes() { + char buf[64]; + + setbfile(buf, currboard, fn_notes); + if(more(buf, NA) == -1) { + clear(); + move(4, 20); + outs("本看板尚無「備忘錄」。"); + } + pressanykey(); + return FULLUPDATE; +} + +int board_select() { + char fpath[80]; + char genbuf[100]; + + currmode &= ~MODE_SELECT; + sprintf(fpath, "SR.%s", cuser.userid); + setbfile(genbuf, currboard, fpath); + unlink(genbuf); + if(currstat == RMAIL) + sethomedir(currdirect, cuser.userid); + else + setbdir(currdirect, currboard); + return NEWDIRECT; +} + +int board_digest() { + if(currmode & MODE_SELECT) + board_select(); + currmode ^= MODE_DIGEST; + if(currmode & MODE_DIGEST) + currmode &= ~MODE_POST; + else if (haspostperm(currboard)) + currmode |= MODE_POST; + + setbdir(currdirect, currboard); + return NEWDIRECT; +} + +int board_etc() { + if(!HAS_PERM(PERM_SYSOP)) + return DONOTHING; + currmode ^= MODE_ETC; + if(currmode & MODE_ETC) + currmode &= ~MODE_POST; + else if(haspostperm(currboard)) + currmode |= MODE_POST; + + setbdir(currdirect, currboard); + return NEWDIRECT; +} + +extern char *fn_mandex; + +static int good_post(int ent, fileheader_t *fhdr, char *direct) { + char genbuf[200]; + char genbuf2[200]; + int delta = 0; + + if((currmode & MODE_DIGEST) || !(currmode & MODE_BOARD)) + return DONOTHING; + + if(fhdr->filemode & FILE_DIGEST) { + fhdr->filemode = (fhdr->filemode & ~FILE_DIGEST); + if(!strcmp(currboard,"Note") || !strcmp(currboard,"PttBug") || + !strcmp(currboard,"Artdsn") || !strcmp(currboard, "PttLaw")) { + deumoney(searchuser(fhdr->owner),-1000); + if(!(currmode & MODE_SELECT)) + fhdr->money -= 1000; + else + delta = -1000; + } + } else { + fileheader_t digest; + char *ptr, buf[64]; + + memcpy(&digest, fhdr, sizeof(digest)); + digest.filename[0] = 'G'; + strcpy(buf, direct); + ptr = strrchr(buf, '/') + 1; + ptr[0] = '\0'; + sprintf(genbuf, "%s%s", buf, digest.filename); + + if(dashf(genbuf)) unlink (genbuf); + + digest.savemode = digest.filemode = 0; + sprintf(genbuf2, "%s%s", buf, fhdr->filename); + Link(genbuf2, genbuf); + strcpy(ptr, fn_mandex); + append_record(buf, &digest, sizeof(digest)); + + fhdr->filemode = (fhdr->filemode & ~FILE_MARKED) | FILE_DIGEST; + if(!strcmp(currboard, "Note") || !strcmp(currboard, "PttBug") || + !strcmp(currboard,"Artdsn") || !strcmp(currboard, "PttLaw")) { + deumoney(searchuser(fhdr->owner), 1000); + if(!(currmode & MODE_SELECT)) fhdr->money += 1000; + else delta = 1000; + } + } + substitute_record(direct, fhdr, sizeof(*fhdr), ent); + touchdircache(currbid); +/* rocker.011018: 串接模式用reference增進效率 */ + if ((currmode & MODE_SELECT) && (fhdr->money & FHR_REFERENCE)) + { + fileheader_t hdr; + char genbuf[100]; + int num; + + num = fhdr->money & ~FHR_REFERENCE; + setbdir(genbuf, currboard); + get_record(genbuf, &hdr, sizeof (hdr), num); + + /* 再這裡要check一下原來的dir裡面是不是有被人動過... */ + if (strcmp (hdr.filename, fhdr->filename)) + { + num = getindex(genbuf, fhdr->filename, sizeof(fileheader_t)); + get_record(genbuf, &hdr, sizeof (hdr), num); + } + fhdr->money = hdr.money + delta; + + substitute_record(genbuf, fhdr, sizeof(*fhdr), num); + } +#if 0 + if(currmode & MODE_SELECT) { + int now; + char genbuf[100]; + + setbdir(genbuf, currboard); + now=getindex(genbuf, fhdr->filename, sizeof(fileheader_t)); + substitute_record(genbuf, fhdr, sizeof(*fhdr), now); + } +#endif + return PART_REDRAW; +} + +/* help for board reading */ +static char *board_help[] = { + "\0全功\能看板操作說明", + "\01基本命令", + "(p)(↑) 上移一篇文章 (^P) 發表文章", + "(n)(↓) 下移一篇文章 (d) 刪除文章", + "(P)(PgUp) 上移一頁 (S) 串連相關文章", + "(N)(PgDn) 下移一頁 (##) 跳到 ## 號文章", + "(r)(→) 閱\讀此篇文章 ($) 跳到最後一篇文章", + "\01進階命令", + "(tab)/z 文摘模式/精華區 (a)(A) 找尋作者", + "(b/f) 展讀備忘錄/參與賭盤 (?)(/) 找尋標題", + "(V/R) 投票/查詢投票結果 (^W) 我在哪裡可看到看板的分類", + "(x) 轉錄文章到其他看板 (=)/([]<>-+) 找尋首篇文章/主題式閱\讀", +#ifdef INTERNET_EMAIL + "(F) 文章寄回Internet郵箱 (U) 將文章 uuencode 後寄回郵箱", +#endif + "(E) 重編文章 (^H) 列出所有的 New Post(s)", + "\01板主命令", + "(G) 舉辦賭盤/停止下注/開獎(W/w/v) 編輯備忘錄/水桶名單/可看見名單", + "(M/o) 舉行投票/編私投票名單 (m/c/g) 保留文章/選錄精華/文摘", + "(D) 刪除一段範圍的文章 (T/B) 重編文章標題/重編看版標題", + "(i) 編輯申請入會表格 (t/^D) 標記文章/砍除標記的文章", + "(O) 編輯Post注意事項 (H) 看板隱藏/現身", + NULL +}; + +static int b_help() { + show_help(board_help); + return FULLUPDATE; +} + +/* ----------------------------------------------------- */ +/* 板主設定隱形/ 解隱形 */ +/* ----------------------------------------------------- */ +char board_hidden_status; +#ifdef BMCHS +extern char *fn_board; +static int change_hidden(int ent, fileheader_t *fhdr, char *direct) +{ + boardheader_t bh; + int bid; + char ans[4]; + + if( !((currmode & MODE_BOARD) || HAS_PERM(PERM_SYSOP)) || + currboard[0] == 0 || + (bid = getbnum(currboard)) < 0 || + get_record(fn_board, &bh, sizeof(bh), bid) == -1 ) + return DONOTHING; + + if( ((bh.brdattr & BRD_HIDE) && (bh.brdattr & BRD_POSTMASK)) ){ + getdata(1, 0, "目前板在隱形狀態, 要解隱形嘛(Y/N)?[N]", ans, 2, LCECHO); + if( ans[0] != 'y' && ans[0] != 'Y' ) + return FULLUPDATE; + getdata(2, 0, "再確認一次, 真的要把板板公開嘛 @____@(Y/N)?[N]", + ans, 2, LCECHO); + if( ans[0] != 'y' && ans[0] != 'Y' ) + return FULLUPDATE; + if( bh.brdattr & BRD_HIDE ) bh.brdattr -= BRD_HIDE; + if( bh.brdattr & BRD_POSTMASK ) bh.brdattr -= BRD_POSTMASK; + log_usies("OpenBoard", bh.brdname); + outs("君心今傳眾人,無處不聞弦歌。\n"); + board_hidden_status = 0; + hbflreload(bid); + } + else{ + getdata(1, 0, "目前板在現形狀態, 要隱形嘛(Y/N)?[N]", ans, 2, LCECHO); + if( ans[0] != 'y' && ans[0] != 'Y' ) + return FULLUPDATE; + bh.brdattr |= BRD_HIDE; + bh.brdattr |= BRD_POSTMASK; + log_usies("CloseBoard", bh.brdname); + outs("君心今已掩抑,惟盼善自珍重。\n"); + board_hidden_status = 1; + } + setup_man(&bh); + substitute_record(fn_board, &bh, sizeof(bh), bid); + reset_board(bid); + log_usies("SetBoard", bh.brdname); + pressanykey(); + return FULLUPDATE; +} +#endif + +/* ----------------------------------------------------- */ +/* 看板功能表 */ +/* ----------------------------------------------------- */ +struct onekey_t read_comms[] = { + {KEY_TAB, board_digest}, + {'C', board_etc}, + {'b', b_notes}, + {'c', cite_post}, + {'r', read_post}, + {'z', b_man}, + {'D', del_range}, + {'S', sequential_read}, + {'E', edit_post}, + {'T', edit_title}, + {'s', do_select}, + {'R', b_results}, + {'V', b_vote}, + {'M', b_vote_maintain}, + {'B', bh_title_edit}, + {'W', b_notes_edit}, + {'O', b_post_note}, + {'w', b_water_edit}, + {'v', visable_list_edit}, + {'i', b_application}, + {'o', can_vote_edit}, + {'x', cross_post}, + {'h', b_help}, +#ifndef NO_GAMBLE + {'f', join_gamble}, + {'G', hold_gamble}, +#endif + {'g', good_post}, + {'y', reply_post}, + {'d', del_post}, + {'m', mark_post}, + {'L', solve_post}, + {Ctrl('P'), do_post}, + {Ctrl('W'), whereami}, + {'Q', view_postmoney}, +#ifdef OUTJOBSPOOL + {'u', tar_addqueue}, +#endif +#ifdef BMCHS + {'H', change_hidden}, +#endif + {'\0', NULL} +}; + +time_t board_visit_time; + +int Read() { + int mode0 = currutmp->mode; + int stat0 = currstat, tmpbid=currutmp->brc_id; + char buf[40]; +#ifdef LOG_BOARD + time_t usetime = time(0); +#endif + + setutmpmode(READING); + set_board(); + + if(board_visit_time < board_note_time) { + setbfile(buf, currboard, fn_notes); + more(buf, NA); + pressanykey(); + } + currutmp->brc_id = currbid; + setbdir(buf, currboard); + curredit &= ~EDIT_MAIL; + i_read(READING, buf, readtitle, readdoent, read_comms, + currbid); +#ifdef LOG_BOARD + log_board(currboard, time(0) - usetime); +#endif + brc_update(); + + currutmp->brc_id =tmpbid; + currutmp->mode = mode0; + currstat = stat0; + return 0; +} + +void ReadSelect() { + int mode0 = currutmp->mode; + int stat0 = currstat; + char genbuf[200]; + + currstat = XMODE; + if(do_select(0, 0, genbuf) == NEWDIRECT) + Read(); + currutmp->brc_id=0; + currutmp->mode = mode0; + currstat = stat0; +} + +#ifdef LOG_BOARD +static void log_board(char *mode, time_t usetime) { + time_t now; + char buf[ 256 ]; + + if(usetime > 30) { + now = time(0); + sprintf(buf, "USE %-20.20s Stay: %5ld (%s) %s", + mode, usetime ,cuser.userid ,ctime(&now)); + log_file(FN_USEBOARD,buf); + } +} +#endif + +int Select() { + char genbuf[200]; + + setutmpmode(SELECT); + do_select(0, NULL, genbuf); + return 0; +} diff --git a/pttbbs/mbbsd/board.c b/pttbbs/mbbsd/board.c new file mode 100644 index 00000000..44b4b842 --- /dev/null +++ b/pttbbs/mbbsd/board.c @@ -0,0 +1,1098 @@ +/* $Id: board.c,v 1.1 2002/03/07 15:13:48 in2 Exp $ */ +#include +#include +#include +#include +#include +#include +#include +#include +#include "config.h" +#include "pttstruct.h" +#include "perm.h" +#include "modes.h" +#include "common.h" +#include "proto.h" + +#define BRC_STRLEN 15 /* Length of board name */ +#define BRC_MAXSIZE 24576 +#define BRC_ITEMSIZE (BRC_STRLEN + 1 + BRC_MAXNUM * sizeof( int )) +#define BRC_MAXNUM 80 + +extern userinfo_t *currutmp; +static char *brc_getrecord(char *ptr, char *name, int *pnum, int *list) { + int num; + char *tmp; + + strncpy(name, ptr, BRC_STRLEN); + ptr += BRC_STRLEN; + num = (*ptr++) & 0xff; + tmp = ptr + num * sizeof(int); + if (num > BRC_MAXNUM) + num = BRC_MAXNUM; + *pnum = num; + memcpy(list, ptr, num * sizeof(int)); + return tmp; +} + +static time_t brc_expire_time; + +static char *brc_putrecord(char *ptr, char *name, int num, int *list) { + if(num > 0 && list[0] > brc_expire_time) { + if (num > BRC_MAXNUM) + num = BRC_MAXNUM; + + while(num > 1 && list[num - 1] < brc_expire_time) + num--; + + strncpy(ptr, name, BRC_STRLEN); + ptr += BRC_STRLEN; + *ptr++ = num; + memcpy(ptr, list, num * sizeof(int)); + ptr += num * sizeof(int); + } + return ptr; +} + +extern userec_t cuser; +extern char currboard[]; /* name of currently selected board */ +static int brc_changed = 0; +static char brc_buf[BRC_MAXSIZE]; +int brc_num; +static char brc_name[BRC_STRLEN]; +int brc_list[BRC_MAXNUM]; +static char *fn_boardrc = ".boardrc"; +static int brc_size; + +void brc_update() { + if(brc_changed && cuser.userlevel) { + char dirfile[STRLEN], *ptr; + char tmp_buf[BRC_MAXSIZE - BRC_ITEMSIZE], *tmp; + char tmp_name[BRC_STRLEN]; + int tmp_list[BRC_MAXNUM], tmp_num; + int fd, tmp_size; + + ptr = brc_buf; + if(brc_num > 0) + ptr = brc_putrecord(ptr, brc_name, brc_num, brc_list); + + setuserfile(dirfile, fn_boardrc); + if((fd = open(dirfile, O_RDONLY)) != -1) { + tmp_size = read(fd, tmp_buf, sizeof(tmp_buf)); + close(fd); + } else { + tmp_size = 0; + } + + tmp = tmp_buf; + while(tmp < &tmp_buf[tmp_size] && (*tmp >= ' ' && *tmp <= 'z')) { + tmp = brc_getrecord(tmp, tmp_name, &tmp_num, tmp_list); + if(strncmp(tmp_name, currboard, BRC_STRLEN)) + ptr = brc_putrecord(ptr, tmp_name, tmp_num, tmp_list); + } + brc_size = (int)(ptr - brc_buf); + + if((fd = open(dirfile, O_WRONLY | O_CREAT, 0644)) != -1) { + ftruncate(fd, 0); + write(fd, brc_buf, brc_size); + close(fd); + } + brc_changed = 0; + } +} + +static void read_brc_buf() { + char dirfile[STRLEN]; + int fd; + + if(brc_buf[0] == '\0') { + setuserfile(dirfile, fn_boardrc); + if((fd = open(dirfile, O_RDONLY)) != -1) { + brc_size = read(fd, brc_buf, sizeof(brc_buf)); + close(fd); + } else { + brc_size = 0; + } + } +} + +extern int currbid; +extern unsigned int currbrdattr; +extern boardheader_t *bcache; + +int brc_initial(char *boardname) { + char *ptr; + if(strcmp(currboard, boardname) == 0) { + return brc_num; + } + brc_update(); + strcpy(currboard, boardname); + currbid = getbnum(currboard); + currbrdattr = bcache[currbid - 1].brdattr; + read_brc_buf(); + + ptr = brc_buf; + while(ptr < &brc_buf[brc_size] && (*ptr >= ' ' && *ptr <= 'z')) { + ptr = brc_getrecord(ptr, brc_name, &brc_num, brc_list); + if (strncmp(brc_name, currboard, BRC_STRLEN) == 0) + return brc_num; + } + strncpy(brc_name, boardname, BRC_STRLEN); + brc_num = brc_list[0] = 1; + return 0; +} + +void brc_addlist(char *fname) { + int ftime, n, i; + + if(!cuser.userlevel) + return; + + ftime = atoi(&fname[2]); + if(ftime <= brc_expire_time + /* || fname[0] != 'M' || fname[1] != '.' */ ) { + return; + } + if(brc_num <= 0) { + brc_list[brc_num++] = ftime; + brc_changed = 1; + return; + } + if((brc_num == 1) && (ftime < brc_list[0])) + return; + for(n = 0; n < brc_num; n++) { + if(ftime == brc_list[n]) { + return; + } else if(ftime > brc_list[n]) { + if(brc_num < BRC_MAXNUM) + brc_num++; + for(i = brc_num - 1; --i >= n; brc_list[i + 1] = brc_list[i]); + brc_list[n] = ftime; + brc_changed = 1; + return; + } + } + if(brc_num < BRC_MAXNUM) { + brc_list[brc_num++] = ftime; + brc_changed = 1; + } +} + +static int brc_unread_time(time_t ftime, int bnum, int *blist) { + int n; + + if(ftime <= brc_expire_time ) + return 0; + + if(brc_num <= 0) + return 1; + for(n = 0; n < bnum; n++) { + if(ftime > blist[n]) + return 1; + else if(ftime == blist[n]) + return 0; + } + return 0; +} + +int brc_unread(char *fname, int bnum, int *blist) { + int ftime, n; + + ftime = atoi(&fname[2]); + + if(ftime <= brc_expire_time ) + return 0; + + if(brc_num <= 0) + return 1; + for(n = 0; n < bnum; n++) { + if(ftime > blist[n]) + return 1; + else if(ftime == blist[n]) + return 0; + } + return 0; +} + +#define BRD_UNREAD 1 +#define BRD_FAV 2 +#define BRD_ZAP 4 +#define BRD_TAG 8 + +typedef struct { + int bid, *total; + time_t *lastposttime; + boardheader_t *bh; + unsigned int myattr; +} boardstat_t; + +extern time_t login_start_time; +extern int numboards; +static int *zapbuf=NULL,*favbuf; +static boardstat_t *nbrd; + +#define STR_BBSRC ".bbsrc" +#define STR_FAV ".fav" + +void init_brdbuf() { + register int n, size; + char fname[60]; + + /* MAXBOARDS ==> 至多看得見 4 個新板 */ + n = numboards + 4; + size = n * sizeof(int); + zapbuf = (int *) malloc(size); + favbuf = (int *) malloc(size); + + memset(favbuf,0,size); + + while(n) + zapbuf[--n] = login_start_time; + setuserfile(fname, STR_BBSRC); + if((n = open(fname, O_RDONLY, 0600)) != -1) { + read(n, zapbuf, size); + close(n); + } + setuserfile(fname, STR_FAV); + if((n = open(fname, O_RDONLY, 0600)) != -1) { + read(n, favbuf, size); + close(n); + } + + if(!nbrd) + nbrd = (boardstat_t *)malloc(MAX_BOARD * sizeof(boardstat_t)); + brc_expire_time = login_start_time - 365 * 86400; +} + +void save_brdbuf() { + int fd, size; + char fname[60]; + + if(!zapbuf) return; + setuserfile(fname, STR_BBSRC); + if((fd = open(fname, O_WRONLY | O_CREAT, 0600)) != -1) { + size = numboards * sizeof(int); + write(fd, zapbuf, size); + close(fd); + } + setuserfile(fname, STR_FAV); + if((fd = open(fname, O_WRONLY | O_CREAT, 0600)) != -1) { + size = numboards * sizeof(int); + write(fd, favbuf, size); + close(fd); + } +} + +extern char *fn_visable; + +int Ben_Perm(boardheader_t *bptr) { + register int level,brdattr; + register char *ptr; + + level = bptr->level; + brdattr = bptr->brdattr; + + if(HAS_PERM(PERM_SYSOP)) + return 1; + + ptr = bptr->BM; + if(is_BM(ptr)) + return 1; + + /* 祕密看板:核對首席板主的好友名單 */ + + if(brdattr & BRD_HIDE) { /* 隱藏 */ + if( hbflcheck((int)(bptr-bcache) + 1, currutmp->uid) ){ + if(brdattr & BRD_POSTMASK) + return 0; + else + return 2; + } else + return 1; + } + /* 限制閱讀權限 */ + if(level && !(brdattr & BRD_POSTMASK) && !HAS_PERM(level)) + return 0; + + return 1; +} + +extern char currauthor[]; +extern int b_lines; +extern char currowner[]; + +static int have_author(char* brdname) { + char dirname[100]; + + sprintf(dirname, "正在搜尋作者%s 看板:%s.....", + currauthor,brdname); + move(b_lines, 0); + clrtoeol(); + outs(dirname); + refresh(); + + setbdir(dirname, brdname); + str_lower(currowner, currauthor); + + return search_rec(dirname, cmpfowner); +} + +static int check_newpost(boardstat_t *ptr) { /* Ptt 改 */ + int tbrc_list[BRC_MAXNUM], tbrc_num; + char bname[BRC_STRLEN]; + char *po; + time_t ftime; + + ptr->myattr &= ~BRD_UNREAD; + if(ptr->bh->brdattr & BRD_GROUPBOARD) + return 0; + + if(*(ptr->total) == 0) + setbtotal(ptr->bid); + if(*(ptr->total) == 0) return 0; + ftime = *(ptr->lastposttime); + read_brc_buf(); + po = brc_buf; + while(po < &brc_buf[brc_size] && (*po >= ' ' && *po <= 'z')) { + po = brc_getrecord(po, bname, &tbrc_num, tbrc_list); + if(strncmp(bname, ptr->bh->brdname, BRC_STRLEN) == 0) { + if(brc_unread_time(ftime,tbrc_num,tbrc_list)) { + ptr->myattr |= BRD_UNREAD; + } + return 1; + } + } + + ptr->myattr |= BRD_UNREAD; + return 1; +} + +extern int currmode; +extern struct bcache_t *brdshm; +static int brdnum; +int class_bid = 0; +static int yank_flag = 1; +static void load_uidofgid(const int gid, const int type){ + boardheader_t *bptr,*currbptr; + int n; + currbptr = &bcache[gid-1]; + for(n=0;nsorted[type][n]; + if(bptr->brdname[0]=='\0') continue; + if(bptr->gid == gid) + { + if(currbptr == &bcache[gid-1]) + currbptr->firstchild[type]=bptr; + else + { + currbptr->next[type]=bptr; + currbptr->parent=&bcache[gid-1]; + } + currbptr=bptr; + } + } + if(currbptr == &bcache[gid-1]) + currbptr->firstchild[type]=(boardheader_t *) ~0; + else + currbptr->next[type]=(boardheader_t *) ~0; +} +static boardstat_t * addnewbrdstat(int n, int state) +{ + boardstat_t *ptr=&nbrd[brdnum++]; + boardheader_t *bptr = &bcache[n]; + ptr->total = &(brdshm->total[n]); + ptr->lastposttime = &(brdshm->lastposttime[n]); + ptr->bid = n+1; + ptr->myattr=0; + ptr->myattr=(favbuf[n]&~BRD_ZAP); + if(zapbuf[n] == 0) + ptr->myattr|=BRD_ZAP; + ptr->bh = bptr; + if((bptr->brdattr & BRD_HIDE) && state == 1) + bptr->brdattr |= BRD_POSTMASK; + check_newpost(ptr); + return ptr; +} + +static void load_boards(char *key) { + boardheader_t *bptr = NULL; + int type=cuser.uflag & BRDSORT_FLAG?1:0; + register int i,n; + register int state ; + + if(class_bid>0) + { + bptr = &bcache[class_bid-1]; + if(bptr->firstchild[type]==NULL) + load_uidofgid(class_bid,type); + } + brdnum = 0; + if(class_bid==0) + for(i=0 ; i < numboards; i++) + { + + if( (bptr = brdshm->sorted[type][i]) == NULL ) + continue; + n = (int)( bptr - bcache); + if(!bptr->brdname[0] || bptr->brdattr & BRD_GROUPBOARD || + !((state = Ben_Perm(bptr)) || (currmode & MODE_MENU)) || + (yank_flag == 0 && !(favbuf[n]&BRD_FAV)) || + (yank_flag == 1 && !zapbuf[n]) || + (key[0] && !strcasestr(bptr->title, key)) + ) continue; + addnewbrdstat(n, state); + } + else + for(bptr=bptr->firstchild[type]; bptr!=(boardheader_t *)~0; + bptr=bptr->next[type]) + { + n = (int)( bptr - bcache); + if(!((state = Ben_Perm(bptr)) || (currmode & MODE_MENU)) + ||(yank_flag == 0 && !(favbuf[n]&BRD_FAV)) + ||(yank_flag == 1 && !zapbuf[n]) || + (key[0] && !strcasestr(bptr->title, key))) continue; + addnewbrdstat(n, state); + } +} + +static int search_board() { + int num; + char genbuf[IDLEN + 2]; + move(0, 0); + clrtoeol(); + CreateNameList(); + for(num = 0; num < brdnum; num++) + AddNameList(nbrd[num].bh->brdname); + namecomplete(MSG_SELECT_BOARD, genbuf); + + for (num = 0; num < brdnum; num++) + if (!strcasecmp(nbrd[num].bh->brdname, genbuf)) + return num; + return -1; +} + +static int unread_position(char *dirfile, boardstat_t *ptr) { + fileheader_t fh; + char fname[FNLEN]; + register int num, fd, step, total; + + total = *(ptr->total); + num = total + 1; + if((ptr->myattr&BRD_UNREAD) &&(fd = open(dirfile, O_RDWR)) > 0) { + if(!brc_initial(ptr->bh->brdname)) { + num = 1; + } else { + num = total - 1; + step = 4; + while(num > 0) { + lseek(fd, (off_t)(num * sizeof(fh)), SEEK_SET); + if(read(fd, fname, FNLEN) <= 0 || + !brc_unread(fname,brc_num,brc_list)) + break; + num -= step; + if(step < 32) + step += step >> 1; + } + if(num < 0) + num = 0; + while(num < total) { + lseek(fd, (off_t)(num * sizeof(fh)), SEEK_SET); + if(read(fd, fname, FNLEN) <= 0 || + brc_unread(fname,brc_num,brc_list)) + break; + num++; + } + } + close(fd); + } + if(num < 0) + num = 0; + return num; +} + +static void brdlist_foot() { + prints("\033[34;46m 選擇看板 \033[31;47m (c)\033[30m新文章模式 " + "\033[31m(v/V)\033[30m標記已讀/未讀 \033[31m(y)\033[30m篩選%s" + " \033[31m(z)\033[30m切換選擇 \033[m", + yank_flag==0 ? "最愛" : yank_flag==1 ? "部份" : "全部"); +} + +extern unsigned int currstat; +extern char *BBSName; + +static void show_brdlist(int head, int clsflag, int newflag) { + int myrow = 2; + if(class_bid == 1) { + currstat = CLASS; + myrow = 6; + showtitle("分類看板", BBSName); + movie(0); + move(1, 0); + prints( + " " + "◣ ╭—\033[33m●\n" + " 寣X \033[m " + "◢█\033[47m☉\033[40m██◣蔌n"); + prints( + " \033[44m ︿︿︿︿︿︿︿︿ " + "\033[33m鱋033[m\033[44m ◣◢███▼▼▼ \033[m\n" + " \033[44m " + "\033[33m \033[m\033[44m ◤◥███▲▲▲ 鱋033[m\n" + " ︿︿︿︿︿︿︿︿ \033[33m" + "│\033[m ◥████◤ 鱋n" + " \033[33m" + "——\033[m ◤ —+\033[m"); + } else if (clsflag) { + showtitle("看板列表", BBSName); + prints("[←]主選單 [→]閱\讀 [↑↓]選擇 [y]載入 [S]排序 [/]搜尋 " + "[TAB]文摘•看板 [h]求助\n" + "\033[7m%-20s 類別 轉信%-31s投票 板 主 \033[m", + newflag ? "總數 未讀 看 板" : " 編號 看 板", + " 中 文 敘 述"); + move(b_lines, 0); + brdlist_foot(); + } + + if(brdnum > 0) { + boardstat_t *ptr; + static char *color[8]={"","\033[32m", + "\033[33m","\033[36m","\033[34m","\033[1m", + "\033[1;32m","\033[1;33m"}; + static char *unread[2]={"\33[37m \033[m","\033[1;31mˇ\033[m"}; + + while(++myrow < b_lines) { + move(myrow, 0); + clrtoeol(); + if(head < brdnum) { + ptr = &nbrd[head++]; + if(class_bid == 1) + prints(" "); + if(!newflag) { + prints("%5d%c%s", head, + !(ptr->bh->brdattr & BRD_HIDE) ? ' ': + (ptr->bh->brdattr & BRD_POSTMASK) ? ')' : '-', + (ptr->myattr & BRD_TAG) ? "D " : + (ptr->myattr & BRD_ZAP) ? "- " : + (ptr->bh->brdattr & BRD_GROUPBOARD) ? " " : + unread[ptr->myattr&BRD_UNREAD]); + } else if(ptr->myattr&BRD_ZAP) { + ptr->myattr &= ~BRD_UNREAD; + prints(" ﹣ ﹣"); + } else { + if(newflag) { + if((ptr->bh->brdattr & BRD_GROUPBOARD)) + prints(" "); + else + prints("%6d%s", (int)(*(ptr->total)), + unread[ptr->myattr&BRD_UNREAD]); + } + } + if(class_bid != 1) { + prints("%s%-13s\033[m%s%5.5s\033[0;37m%2.2s\033[m" + "%-35.35s%c %.13s", + (ptr->myattr & BRD_FAV)?"\033[1;36m":"", + ptr->bh->brdname, + color[(unsigned int) + (ptr->bh->title[1] + ptr->bh->title[2] + + ptr->bh->title[3] + ptr->bh->title[0]) & 07], + ptr->bh->title, ptr->bh->title+5, ptr->bh->title+7, + (ptr->bh->brdattr & BRD_BAD) ? 'X' : + " ARBCDEFGHI"[ptr->bh->bvote], + ptr->bh->BM); + refresh(); + } else { + prints("%-40.40s %.13s", ptr->bh->title + 7, ptr->bh->BM); + } + } + clrtoeol(); + } + } +} + +static char *choosebrdhelp[] = { + "\0看板選單輔助說明", + "\01基本指令", + "(p)(↑)/(n)(↓)上一個看板 / 下一個看板", + "(P)(^B)(PgUp) 上一頁看板", + "(N)(^F)(PgDn) 下一頁看板", + "($)/(s)/(/) 最後一個看板 / 搜尋看板 / 以中文搜尋看板關鍵字", + "(數字) 跳至該項目", + "\01進階指令", + "(^W) 迷路了 我在哪裡", + "(r)(→)(Rtn) 進入多功\能閱\讀選單", + "(q)(←) 回到主選單", + "(z)(Z) 訂閱\/反訂閱\看板 訂閱\/反訂閱\所有看板", + "(y) 我的最愛/訂閱\看板/出所有看板", + "(v/V) 通通看完/全部未讀", + "(S) 按照字母/分類排序", + "(t/^T/^A/^D) 標記看板/取消所有標記/已標記的加入我的最愛/取消我的最愛", + "(m) 把看板加入我的最愛", + "\01小組長指令", + "(E/W/B) 設定看板/設定小組備忘/開新看板", + "(^P) 移動已標記看板到此分類", + NULL +}; + + +static void set_menu_BM(char *BM) { + if(HAS_PERM(PERM_ALLBOARD) || is_BM(BM)) { + currmode |= MODE_MENU; + cuser.userlevel |= PERM_SYSSUBOP; + } +} + +extern int p_lines; /* a Page of Screen line numbers: tlines-4 */ +extern int t_lines; +extern char *fn_notes; +static char *privateboard = +"\n\n\n\n 對不起 此板目前只准看板好友進入 請先向板主申請入境許\可"; +static void dozap(int num){ + boardstat_t *ptr; + ptr = &nbrd[num]; + ptr->myattr ^= BRD_ZAP; + if(ptr->bh->brdattr & BRD_NOZAP) ptr->myattr &= ~BRD_ZAP; + if(!(ptr->myattr & BRD_ZAP) ) check_newpost(ptr); + zapbuf[ptr->bid-1] = (ptr->myattr&BRD_ZAP?0:login_start_time); +} +static void choose_board(int newflag) { + static int num = 0; + boardstat_t *ptr; + int head = -1, ch = 0, currmodetmp, tmp,tmp1, bidtmp; + char keyword[13]=""; +#if HAVE_SEARCH_ALL + char genbuf[200]; +#endif + extern time_t board_visit_time; + + setutmpmode(newflag ? READNEW : READBRD); + brdnum = 0; + if(!cuser.userlevel) /* guest yank all boards */ + yank_flag = 2; + + do { + if(brdnum <= 0) { + load_boards(keyword); + if(brdnum <= 0) { + if(keyword[0]!=0) + { + mprints(b_lines-1,0,"沒有任何看板標題有此關鍵字 " + "(版主應注意看板標題命名)"); + pressanykey(); + keyword[0]=0; + brdnum = -1; + continue; + } + if(yank_flag<2) + { + brdnum = -1; + yank_flag++; + continue; + } + if(HAS_PERM(PERM_SYSOP) || (currmode & MODE_MENU)) { + if(m_newbrd(0) == -1) + break; + brdnum = -1; + continue; + } else + break; + } + head = -1; + } + + if(num < 0) + num = 0; + else if(num >= brdnum) + num = brdnum - 1; + + if(head < 0) { + if(newflag) { + tmp = num; + while(num < brdnum) { + ptr = &nbrd[num]; + if(ptr->myattr&BRD_UNREAD) + break; + num++; + } + if(num >= brdnum) + num = tmp; + } + head = (num / p_lines) * p_lines; + show_brdlist(head, 1, newflag); + } else if(num < head || num >= head + p_lines) { + head = (num / p_lines) * p_lines; + show_brdlist(head, 0, newflag); + } + if(class_bid == 1) + ch = cursor_key(7 + num - head, 10); + else + ch = cursor_key(3 + num - head, 0); + + switch(ch) { + case Ctrl('W'): + whereami(0,NULL,NULL); + head=-1; + break; + case 'e': + case KEY_LEFT: + case EOF: + ch = 'q'; + case 'q': + if(keyword[0]) + { + keyword[0]=0; + brdnum=-1; + ch=' '; + } + break; + case 'c': + show_brdlist(head, 1, newflag ^= 1); + break; + case KEY_PGUP: + case 'P': + case 'b': + case Ctrl('B'): + if(num) { + num -= p_lines; + break; + } + case KEY_END: + case '$': + num = brdnum - 1; + break; + case ' ': + case KEY_PGDN: + case 'N': + case Ctrl('F'): + if(num == brdnum - 1) + num = 0; + else + num += p_lines; + break; + case Ctrl('C'): + cal(); + show_brdlist(head, 1, newflag); + break; + case Ctrl('I'): + t_idle(); + show_brdlist(head, 1, newflag); + break; + case KEY_UP: + case 'p': + case 'k': + if (num-- <= 0) + num = brdnum - 1; + break; + case 't': + ptr = &nbrd[num]; + ptr->myattr ^= BRD_TAG; + favbuf[ptr->bid-1]=ptr->myattr; + head = 9999; + case KEY_DOWN: + case 'n': + case 'j': + if (++num < brdnum) + break; + case '0': + case KEY_HOME: + num = 0; + break; + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + if((tmp = search_num(ch, brdnum)) >= 0) + num = tmp; + brdlist_foot(); + break; + case 'F': + case 'f': + if(class_bid && HAS_PERM(PERM_SYSOP)) + { + bcache[class_bid-1].firstchild[cuser.uflag&BRDSORT_FLAG?1:0] + =NULL; + brdnum = -1; + } + break; + case 'h': + show_help(choosebrdhelp); + show_brdlist(head, 1, newflag); + break; + case '/': + getdata_buf(b_lines-1,0,"請輸入看板中文關鍵字:",keyword, 12, DOECHO); + brdnum=-1; + break; + case 'S': + cuser.uflag ^= BRDSORT_FLAG; + brdnum = -1; + break; + case 'y': + if(class_bid==0) + yank_flag = (yank_flag+1)%3; + else + yank_flag = yank_flag%2+1; + brdnum = -1; + break; + case Ctrl('D'): + for(tmp = 0; tmp < numboards; tmp++) + { + if(favbuf[tmp] & BRD_TAG) + { + favbuf[tmp] &= ~BRD_FAV; + favbuf[tmp] &= ~BRD_TAG; + } + } + brdnum = -1; + break; + case Ctrl('A'): + for(tmp = 0; tmp < numboards; tmp++) + { + if(favbuf[tmp] & BRD_TAG) + { + favbuf[tmp] |= BRD_FAV; + favbuf[tmp] &= ~BRD_TAG; + } + } + brdnum = -1; + break; + case Ctrl('T'): + for(tmp = 0; tmp < numboards; tmp++) + favbuf[tmp] &= ~BRD_TAG; + brdnum = -1; + break; + case Ctrl('P'): + if(class_bid!=0 && + (HAS_PERM(PERM_SYSOP) || (currmode & MODE_MENU))) { + for(tmp = 0; tmp < numboards; tmp++) { + boardheader_t *bh=&bcache[tmp]; + if(!(favbuf[tmp]&BRD_TAG) || bh->gid==class_bid) + continue; + favbuf[tmp] &= ~BRD_TAG; + if(bh->gid != class_bid) + { + bh->gid = class_bid; + substitute_record(FN_BOARD, bh, + sizeof(boardheader_t), tmp+1); + reset_board(tmp+1); + log_usies("SetBoardGID", bh->brdname); + } + } + brdnum = -1; + } + break; + case 'm': + if(HAS_PERM(PERM_BASIC)) { + ptr = &nbrd[num]; + ptr->myattr ^= BRD_FAV; + favbuf[ptr->bid-1]=ptr->myattr; + head = 9999; + } + break; + case 'z': + if(HAS_PERM(PERM_BASIC)) { + dozap(num); + head = 9999; + } + break; + case 'Z': /* Ptt */ + if(HAS_PERM(PERM_BASIC)) { + for(tmp = 0; tmp < brdnum; tmp++) { + dozap(tmp); + } + head = 9999; + } + break; + case 'v': + case 'V': + ptr = &nbrd[num]; + brc_initial(ptr->bh->brdname); + if(ch == 'v') { + ptr->myattr &= ~BRD_UNREAD; + zapbuf[ptr->bid-1] = time((time_t *) &brc_list[0]); + } else + { + zapbuf[ptr->bid-1] = brc_list[0] = 1; + ptr->myattr |= BRD_UNREAD; + } + brc_num = brc_changed = 1; + brc_update(); + show_brdlist(head, 0, newflag); + break; + case 's': + if((tmp = search_board()) == -1) { + show_brdlist(head, 1, newflag); + break; + } + num = tmp; + case 'E': + if(HAS_PERM(PERM_SYSOP) || (currmode & MODE_MENU)) { + ptr = &nbrd[num]; + move(1,1); + clrtobot(); + m_mod_board(ptr->bh->brdname); + brdnum = -1; + } + break; + case 'R': + if(HAS_PERM(PERM_SYSOP) || (currmode & MODE_MENU)) { + m_newbrd(1); + brdnum = -1; + } + break; + case 'B': + if(HAS_PERM(PERM_SYSOP) || (currmode & MODE_MENU)) { + m_newbrd(0); + brdnum = -1; + } + break; + case 'W': + if(class_bid > 0 && + (HAS_PERM(PERM_SYSOP) || (currmode & MODE_MENU))) { + b_note_edit_bname(class_bid); + brdnum = -1; + } + break; + case KEY_RIGHT: + case '\n': + case '\r': + case 'r': + { + char buf[STRLEN]; + + ptr = &nbrd[num]; + + if(!(ptr->bh->brdattr & BRD_GROUPBOARD)) { /* 非sub class */ + if(!(ptr->bh->brdattr & BRD_HIDE) || + (ptr->bh->brdattr & BRD_POSTMASK)) { + brc_initial(ptr->bh->brdname); + + if(newflag) { + setbdir(buf, currboard); + tmp = unread_position(buf, ptr); + head = tmp - t_lines / 2; + getkeep(buf, head > 1 ? head : 1, tmp + 1); + } + board_visit_time = zapbuf[ptr->bid-1]; + if(!(ptr->myattr&BRD_ZAP)) + time((time_t *) &zapbuf[ptr->bid-1]); + Read(); + check_newpost(ptr); + head = -1; + setutmpmode(newflag ? READNEW : READBRD); + } else { + setbfile(buf, ptr->bh->brdname, FN_APPLICATION); + if(more(buf,YEA)==-1) { + move(1,0); + clrtobot(); + outs(privateboard); + pressanykey(); + } + head = -1; + } + } else { /* sub class */ + move(12,1); + bidtmp = class_bid; + currmodetmp =currmode; + tmp1=num; + num=0; + class_bid = ptr->bid; + if (!(currmode & MODE_MENU))/*如果還沒有小組長權限 */ + set_menu_BM(ptr->bh->BM); + + if(time(NULL) < ptr->bh->bupdate) { + setbfile(buf, ptr->bh->brdname, fn_notes); + if(more(buf, NA) != -1) + pressanykey(); + } + tmp=currutmp->brc_id; + currutmp->brc_id=ptr->bid; + choose_board(0); + currmode = currmodetmp; /* 離開版版後就把權限拿掉喔 */ + num=tmp1; + class_bid = bidtmp; + currutmp->brc_id=tmp; + brdnum = -1; + } + } + } + } while(ch != 'q'); + save_brdbuf(); +} + +int root_board() { + class_bid = 1; + yank_flag = 1; + choose_board(0); + return 0; +} + +int Boards() { + class_bid = 0; + yank_flag = 0; + choose_board(0); + return 0; +} + + +int New() { + int mode0 = currutmp->mode; + int stat0 = currstat; + + class_bid = 0; + choose_board(1); + currutmp->mode = mode0; + currstat = stat0; + return 0; +} + +/* +int v_favorite(){ + char fname[256]; + char inbuf[2048]; + FILE* fp; + int nGroup; + char* strtmp; + + setuserfile(fname,str_favorite); + + if (!(fp=fopen(fname,"r"))) + return -1; + move(0,0); + clrtobot(); + fgets(inbuf,sizeof(inbuf),fp); + nGroup=atoi(inbuf); + + currutmp->nGroup=0; + currutmp->ninRoot=0; + + while(nGroup!=currutmp->nGroup+1){ + fgets(inbuf,sizeof(inbuf),fp); + prints("%s\n",strtmp=strtok(inbuf," \n")); + strcpy(currutmp->gfavorite[currutmp->nGroup++],strtmp); + while((strtmp=strtok(NULL, " \n"))){ + prints(" %s %d\n",strtmp,getbnum(strtmp)); + } + currutmp->nGroup++; + } + prints("+++%d+++\n",currutmp->nGroup); + + fgets(inbuf,sizeof(inbuf),fp); + + for(strtmp=strtok(inbuf, " \n");strtmp;strtmp=strtok(NULL, " \n")){ + if (strtmp[0]!='#') + prints("*** %s %d\n",strtmp, getbnum(strtmp)); + else + prints("*** %s %d\n",strtmp+1, -1); + currutmp->ninRoot++; + } + + fclose(fp); + pressanykey(); + return 0; +} +*/ diff --git a/pttbbs/mbbsd/cache.c b/pttbbs/mbbsd/cache.c new file mode 100644 index 00000000..73f8ac5b --- /dev/null +++ b/pttbbs/mbbsd/cache.c @@ -0,0 +1,1053 @@ +/* $Id: cache.c,v 1.1 2002/03/07 15:13:48 in2 Exp $ */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#ifdef __FreeBSD__ +#include +#endif + +#include "config.h" +#include "pttstruct.h" +#include "common.h" +#include "perm.h" +#include "modes.h" +#include "proto.h" + +#ifndef __FreeBSD__ +union semun { + int val; /* value for SETVAL */ + struct semid_ds *buf; /* buffer for IPC_STAT, IPC_SET */ + unsigned short int *array; /* array for GETALL, SETALL */ + struct seminfo *__buf; /* buffer for IPC_INFO */ +}; +#endif + +int fcache_semid; + +/* the reason for "safe_sleep" is that we may call sleep during + SIGALRM handler routine, while SIGALRM is blocked. + if we use the original sleep, we'll never wake up. */ +unsigned int safe_sleep(unsigned int seconds) { + /* jochang sleep有問題時用*/ + sigset_t set,oldset; + + sigemptyset(&set); + sigprocmask(SIG_BLOCK, &set, &oldset); + if(sigismember(&oldset, SIGALRM)) { + unsigned long retv; +#if !defined(_BBS_UTIL_C_) + log_usies("SAFE_SLEEP ", "avoid hang"); +#endif + sigemptyset(&set); + sigaddset(&set,SIGALRM); + sigprocmask(SIG_UNBLOCK,&set,NULL); + retv=sleep(seconds); + sigprocmask(SIG_BLOCK,&set,NULL); + return retv; + } + return sleep(seconds); +} + +#if defined(_BBS_UTIL_C_) +static void setapath(char *buf, char *boardname) { + sprintf(buf, "man/boards/%s", boardname); +} + +static char *str_dotdir = ".DIR"; + +static void setadir(char *buf, char *path) { + sprintf(buf, "%s/%s", path, str_dotdir); +} +#endif + +static void attach_err(int shmkey, char *name) { + fprintf(stderr, "[%s error] key = %x\n", name, shmkey); + fprintf(stderr, "errno = %d: %s\n", errno, strerror(errno)); + exit(1); +} + +static void *attach_shm(int shmkey, int shmsize) { + void *shmptr; + int shmid; + + char *empty_addr; + /* set up one page in-accessible -- jochang */ + { + int fd = open("/dev/zero",O_RDONLY); + int size = ((shmsize + 4095) / 4096) * 4096; + + munmap( + (empty_addr=mmap(0,4096+size,PROT_NONE,MAP_PRIVATE,fd,0))+4096 + ,size); + + close(fd); + } + + shmid = shmget(shmkey, shmsize, 0); + if(shmid < 0) { + shmid = shmget(shmkey, shmsize, IPC_CREAT | 0600); + if(shmid < 0) + attach_err(shmkey, "shmget"); + shmptr = (void *)shmat(shmid, NULL, 0); + if(shmptr == (void *)-1) + attach_err(shmkey, "shmat"); + } else { + shmptr = (void *)shmat(shmid, NULL, 0); + if(shmptr == (void *)-1) + attach_err(shmkey, "shmat"); + } + + /* unmap the page -- jochang */ + { + munmap(empty_addr,4096); + } + return shmptr; +} + + +#define SEM_FLG 0600 /* semaphore mode */ + +/* ----------------------------------------------------- */ +/* semaphore : for critical section */ +/* ----------------------------------------------------- */ +void sem_init(int semkey,int *semid) { + union semun s; + + s.val=1; + *semid = semget(semkey, 1, 0); + if(*semid == -1) { + *semid = semget(semkey, 1, IPC_CREAT | SEM_FLG); + if(*semid == -1) + attach_err(semkey, "semget"); + semctl(*semid, 0, SETVAL, s); + } +} + +void sem_lock(int op,int semid) { + struct sembuf sops; + + sops.sem_num = 0; + sops.sem_flg = SEM_UNDO; + sops.sem_op = op; + semop(semid, &sops, 1); +} + +/* uhash *******************************************/ +/* the design is this: + we use another stand-alone program to create and load data into the hash. + (that program could be run in rc-scripts or something like that) + after loading completes, the stand-alone program sets loaded to 1 and exits. + + the bbs exits if it can't attach to the shared memory or + the hash is not loaded yet. +*/ +uhash_t *uhash; + +/* attach_uhash should be called before using uhash */ +void attach_uhash() { + uhash = attach_shm(UHASH_KEY, sizeof(*uhash)); + if(!uhash->loaded) /* assume fresh shared memory is zeroed */ + exit(1); +} + +void add_to_uhash(int n, char *id) { + int *p, h = StringHash(id); + strcpy(uhash->userid[n], id); + + p = &(uhash->hash_head[h]); + + while(*p != -1) + p = &(uhash->next_in_hash[*p]); + + uhash->next_in_hash[*p = n] = -1; +} + +/* note: after remove_from_uhash(), you should add_to_uhash() + (likely with a different name) */ +void remove_from_uhash(int n) { + int h = StringHash(uhash->userid[n]); + int *p = &(uhash->hash_head[h]); + + while(*p != -1 && *p != n) + p = &(uhash->next_in_hash[*p]); + if(*p == n) + *p = uhash->next_in_hash[n]; +} + +int setumoney(int uid, int money) { + uhash->money[uid-1]=money; + passwd_update_money(uid); + return uhash->money[uid-1]; +} + +int deumoney(int uid, int money) { + if(money<0 && uhash->money[uid-1]<-money) + return setumoney(uid,0); + else + return setumoney(uid,uhash->money[uid-1]+money); +} +int demoney(int money) { + extern int usernum; + return deumoney(usernum,money); +} +int moneyof(int uid){ /* ptt 改進金錢處理效率 */ + return uhash->money[uid-1]; +} +int searchuser(char *userid) { + int h,p; + + h = StringHash(userid); + p = uhash->hash_head[h]; + + while(p != -1) { + if(strcasecmp(uhash->userid[p],userid) == 0) { + strcpy(userid,uhash->userid[p]); + return p + 1; + } + p = uhash->next_in_hash[p]; + } + return 0; +} + +#if !defined(_BBS_UTIL_C_) +extern userec_t xuser; + +int getuser(char *userid) { + int uid; + + if((uid = searchuser(userid))) + passwd_query(uid, &xuser); + return uid; +} + +char *getuserid(int num) { + if(--num >= 0 && num < MAX_USERS) + return ((char *) uhash->userid[num]); + return NULL; +} + +void setuserid(int num, char *userid) { + if(num > 0 && num <= MAX_USERS) { + if(num > uhash->number) + uhash->number = num; + else + remove_from_uhash(num-1); + add_to_uhash(num-1,userid); + } +} + +/* 0 ==> 找過期帳號 */ +/* 1 ==> 建立新帳號 */ +/* should do it by searching "" in the hash */ +int searchnewuser(int mode) { + register int i, num; + + num = uhash->number; + i = 0; + + /* 為什麼這邊不用 hash table 去找而要用 linear search? */ + while(i < num) { + if(!uhash->userid[i++][0]) + return i; + } + if(mode && (num < MAX_USERS)) + return num + 1; + return 0; +} + +char *u_namearray(char buf[][IDLEN + 1], int *pnum, char *tag) { + register struct uhash_t *reg_ushm = uhash; + register char *ptr, tmp; + register int n, total; + char tagbuf[STRLEN]; + int ch, ch2, num; + + if(*tag == '\0') { + *pnum = reg_ushm->number; + return reg_ushm->userid[0]; + } + for(n = 0; tag[n]; n++) + tagbuf[n] = chartoupper(tag[n]); + tagbuf[n] = '\0'; + ch = tagbuf[0]; + ch2 = ch - 'A' + 'a'; + total = reg_ushm->number; + for(n = num = 0; n < total; n++) { + ptr = reg_ushm->userid[n]; + tmp = *ptr; + if(tmp == ch || tmp == ch2) { + if(chkstr(tag, tagbuf, ptr)) + strcpy(buf[num++], ptr); + } + } + *pnum = num; + return buf[0]; +} +#endif + +/*-------------------------------------------------------*/ +/* .UTMP cache */ +/*-------------------------------------------------------*/ +struct utmpfile_t *utmpshm=NULL; + +void resolve_utmp() { + if(utmpshm == NULL) { + utmpshm = attach_shm(UTMPSHM_KEY, sizeof(*utmpshm)); + } +} + +userinfo_t *currutmp = NULL; + +#if !defined(_BBS_UTIL_C_) +extern unsigned int currstat; +extern userec_t cuser; + +void setutmpmode(int mode) { + if(currstat != mode) + currutmp->mode = currstat = mode; + + /* 追蹤使用者 */ + if(HAS_PERM(PERM_LOGUSER)) { + time_t now = time(NULL); + char msg[200]; + sprintf(msg, "%s setutmpmode to %s(%d) at %s", + cuser.userid, modestring(currutmp, 0), mode, Cdate(&now)); + log_user(msg); + } +} +#endif +/* +static int cmputmpuserid(userinfo_t ** i, userinfo_t ** j) { + return strcasecmp((*i)->userid, (*j)->userid); +} + +static int cmputmpmode(userinfo_t ** i, userinfo_t ** j) { + return (*i)->mode-(*j)->mode; +} + +static int cmputmpidle(userinfo_t ** i, userinfo_t ** j) { + return (*i)->lastact-(*j)->lastact; +} + +static int cmputmpfrom(userinfo_t ** i, userinfo_t ** j) { + return strcasecmp((*i)->from, (*j)->from); +} + +static int cmputmpfive(userinfo_t ** i, userinfo_t ** j) { + int type; + if((type=(*j)->five_win - (*i)->five_win)) + return type; + if((type=(*i)->five_lose - (*j)->five_lose)) + return type; + return (*i)->five_tie-(*j)->five_tie; +} +static int cmputmpsex(userinfo_t ** i, userinfo_t ** j) { + static int ladyfirst[]={1,0,1,0,1,0,3,3}; + return ladyfirst[(*i)->sex]-ladyfirst[(*j)->sex]; +} +static int cmputmppid(userinfo_t ** i, userinfo_t ** j) { + return (*i)->pid-(*j)->pid; +} +static int cmputmpuid(userinfo_t ** i, userinfo_t ** j) { + return (*i)->uid-(*j)->uid; +} +*/ +static int cmputmpuserid(const void *i, const void *j){ + return strcasecmp((*((userinfo_t**)i))->userid, (*((userinfo_t**)j))->userid); +} + +static int cmputmpmode(const void *i, const void *j){ + return (*((userinfo_t**)i))->mode-(*((userinfo_t**)j))->mode; +} + +static int cmputmpidle(const void *i, const void *j){ + return (*((userinfo_t**)i))->lastact-(*((userinfo_t**)j))->lastact; +} + +static int cmputmpfrom(const void *i, const void *j){ + return strcasecmp((*((userinfo_t**)i))->from, (*((userinfo_t**)j))->from); +} + +static int cmputmpfive(const void *i, const void *j){ + int type; + if((type=(*((userinfo_t**)j))->five_win - (*((userinfo_t**)i))->five_win)) + return type; + if((type=(*((userinfo_t**)i))->five_lose - (*((userinfo_t**)j))->five_lose)) + return type; + return (*((userinfo_t**)i))->five_tie-(*((userinfo_t**)j))->five_tie; +} + +static int cmputmpsex(const void *i, const void *j){ + static int ladyfirst[]={1,0,1,0,1,0,3,3}; + return ladyfirst[(*((userinfo_t**)i))->sex]-ladyfirst[(*((userinfo_t**)j))->sex]; +} +static int cmputmppid(const void *i, const void *j){ + return (*((userinfo_t**)i))->pid-(*((userinfo_t**)j))->pid; +} +static int cmputmpuid(const void *i, const void *j){ + return (*((userinfo_t**)i))->uid-(*((userinfo_t**)j))->uid; +} +void sort_utmp() +{ + time_t now=time(NULL); + int count, i, ns; + userinfo_t *uentp; + + if(now-utmpshm->uptime<60 && (now==utmpshm->uptime || utmpshm->busystate)) + return; /* lazy sort */ + utmpshm->busystate=1; + utmpshm->uptime = now; + ns=(utmpshm->currsorted?0:1); + + for(uentp = &utmpshm->uinfo[0], count=0, i=0; + i< USHM_SIZE; i++,uentp = &utmpshm->uinfo[i]) + if(uentp->pid) + { + utmpshm->sorted[ns][0][count++]= uentp; + } + utmpshm->number = count; + qsort(utmpshm->sorted[ns][0],count,sizeof(userinfo_t*),cmputmpuserid); + memcpy(utmpshm->sorted[ns][1],utmpshm->sorted[ns][0], + sizeof(userinfo_t *)*count); + memcpy(utmpshm->sorted[ns][2],utmpshm->sorted[ns][0], + sizeof(userinfo_t *)*count); + memcpy(utmpshm->sorted[ns][3],utmpshm->sorted[ns][0], + sizeof(userinfo_t *)*count); + memcpy(utmpshm->sorted[ns][4],utmpshm->sorted[ns][0], + sizeof(userinfo_t *)*count); + memcpy(utmpshm->sorted[ns][5],utmpshm->sorted[ns][0], + sizeof(userinfo_t *)*count); + memcpy(utmpshm->sorted[ns][6],utmpshm->sorted[ns][0], + sizeof(userinfo_t *)*count); + memcpy(utmpshm->sorted[ns][7],utmpshm->sorted[ns][0], + sizeof(userinfo_t *)*count); + qsort(utmpshm->sorted[ns][1], count, sizeof(userinfo_t *), cmputmpmode ); + qsort(utmpshm->sorted[ns][2], count, sizeof(userinfo_t *), cmputmpidle ); + qsort(utmpshm->sorted[ns][3], count, sizeof(userinfo_t *), cmputmpfrom ); + qsort(utmpshm->sorted[ns][4], count, sizeof(userinfo_t *), cmputmpfive ); + qsort(utmpshm->sorted[ns][5], count, sizeof(userinfo_t *), cmputmpsex ); + qsort(utmpshm->sorted[ns][6], count, sizeof(userinfo_t *), cmputmpuid ); + qsort(utmpshm->sorted[ns][7], count, sizeof(userinfo_t *), cmputmppid ); + utmpshm->currsorted=ns; + utmpshm->busystate=0; +} +// Ptt:這邊加入hash觀念 找空的utmp +void getnewutmpent(userinfo_t *up) { + extern int errno; + register int i, p ; + register userinfo_t *uentp; + for(i = 0, p=StringHash(up->userid)%USHM_SIZE; i < USHM_SIZE; i++, p++) { + if(p==USHM_SIZE) p=0; + uentp = &(utmpshm->uinfo[p]); + if(!(uentp->pid)) { + memcpy(uentp, up, sizeof(userinfo_t)); + currutmp = uentp; + sort_utmp(); + return; + } + } + exit(1); +} + +int apply_ulist(int (*fptr)(userinfo_t *)) { + register userinfo_t *uentp; + register int i, state; + + for(i = 0; i < USHM_SIZE; i++) { + uentp = &(utmpshm->uinfo[i]); + if(uentp->pid && (PERM_HIDE(currutmp) || !PERM_HIDE(uentp))) + if((state = (*fptr) (uentp))) + return state; + } + return 0; +} + +userinfo_t *search_ulist(int uid) { + return search_ulistn(uid,1); +} + +#if !defined(_BBS_UTIL_C_) +extern int usernum; + +userinfo_t *search_ulist_pid(int pid) { + register int i=0, j, start = 0, end = utmpshm->number - 1; + register userinfo_t **ulist; + ulist=utmpshm->sorted[utmpshm->currsorted][7]; + for(i=((start+end)/2); ;i=(start+end)/2) + { + j=pid-ulist[i]->pid; + if(!j) + { + return (userinfo_t *) (ulist[i]); + } + if(end==start) + { + break; + } + else if(i==start) + { + i=end; + start=end; + } + else if(j>0) start = i; + else end = i; + } + return 0; +} +userinfo_t *search_ulistn(int uid, int unum) { + register int i=0, j, start = 0, end = utmpshm->number - 1; + register userinfo_t **ulist; + ulist=utmpshm->sorted[utmpshm->currsorted][6]; + for(i=((start+end)/2); ;i=(start+end)/2) + { + j= uid - ulist[i]->uid; + if(!j) + { + for(;i>0 && uid==ulist[i-1]->uid;i--);/* 指到第一筆 */ + if(uid==ulist[i+unum-1]->uid) + return (userinfo_t *) (ulist[i+unum-1]); + break; /* 超過範圍 */ + } + if(end==start) + { + break; + } + else if(i==start) + { + i=end; + start=end; + } + else if(j>0) start = i; + else end = i; + } + return 0; +} + +int count_logins(int uid, int show) { + register int i=0, j, start = 0, end = utmpshm->number - 1, count; + register userinfo_t **ulist; + ulist=utmpshm->sorted[utmpshm->currsorted][6]; + for(i=((start+end)/2); ;i=(start+end)/2) + { + j = uid-ulist[i]->uid; + if(!j) + { + for(;i>0 && uid==ulist[i-1]->uid;i--);/* 指到第一筆 */ + for(count=0;uid==ulist[i+count]->uid;count++) + { + if(show) + prints("(%d) 目前狀態為: %-17.16s(來自 %s)\n", + count+1, modestring(ulist[i+count], 0), + ulist[i+count]->from); + } + return count; + } + if(end==start) + { + break; + } + else if(i==start) + { + i=end; + start=end; + } + else if(j>0) start = i; + else end = i; + } + return 0; +} + + +void purge_utmp(userinfo_t *uentp) { + logout_friend_online(); + memset(uentp, 0, sizeof(userinfo_t)); +} + +#endif + +/*-------------------------------------------------------*/ +/* .BOARDS cache */ +/*-------------------------------------------------------*/ +extern char *fn_board; +extern int currbid; +bcache_t *brdshm; +boardheader_t *bcache; + +void touchdircache(int bid) +{ + int *i= (int *)&brdshm->dircache[bid - 1][0].filename[0]; + *i=0; +} + +void load_fileheader_cache(int bid, char *direct) +{ + int num=getbtotal(bid); + int n = num-DIRCACHESIZE+1; + if (brdshm->busystate!=1) + { + brdshm->busystate = 1; + get_records(direct, brdshm->dircache[bid - 1] , + sizeof(fileheader_t),n<1?1:n, DIRCACHESIZE); + brdshm->cachetotal[bid-1]=num; // cachetotal先設 以後再改不用全部load + brdshm->busystate = 0; + } + else + {safe_sleep(1);} +} + +int get_fileheader_cache(int bid, char *direct, fileheader_t *headers, + int recbase, int nlines) +{ + int ret, n,num; + + num=getbtotal(bid); + + ret = num-recbase+1, + n = (num - DIRCACHESIZE+1); + + + if(brdshm->dircache[bid - 1][0].filename[0]=='\0') + load_fileheader_cache(bid, direct); + if (n<1) + n=recbase-1; + else + n=recbase-n; + if(n<0) n=0; + if (ret>nlines) ret=nlines; + memcpy(headers, &(brdshm->dircache[bid - 1][n]),sizeof(fileheader_t)*ret); + return ret; +} +static int cmpboardname(boardheader_t **brd, boardheader_t **tmp) { + return strcasecmp((*brd)->brdname, (*tmp)->brdname); +} +static int cmpboardclass(boardheader_t **brd, boardheader_t **tmp) { + return (strncmp((*brd)->title, (*tmp)->title, 4)<<8)+ + strcasecmp((*brd)->brdname, (*tmp)->brdname); +} +static void sort_bcache(){ + int i;/*critical section 不能單獨呼叫 呼叫reload_bcache or reset_board */ + for(i=0;inumber;i++) + { + brdshm->sorted[1][i]=brdshm->sorted[0][i]=&bcache[i]; + } + qsort(brdshm->sorted[0], brdshm->number, sizeof(boardheader_t *), + (QCAST)cmpboardname); + qsort(brdshm->sorted[1], brdshm->number, sizeof(boardheader_t *), + (QCAST)cmpboardclass); +} +static void reload_bcache() { + if(brdshm->busystate) { + safe_sleep(1); + } +#if !defined(_BBS_UTIL_C_) + else { + int fd,i; + + brdshm->busystate = 1; + if((fd = open(fn_board, O_RDONLY)) > 0) { + brdshm->number = + read(fd, bcache, MAX_BOARD * sizeof(boardheader_t)) / + sizeof(boardheader_t); + close(fd); + } + memset(brdshm->lastposttime, 0, MAX_BOARD * sizeof(time_t)); + /* 等所有 boards 資料更新後再設定 uptime */ + brdshm->uptime = brdshm->touchtime; + log_usies("CACHE", "reload bcache"); + sort_bcache(); + for(i=0;inumber;i++) + { + bcache[i].firstchild[0]=NULL; + bcache[i].firstchild[1]=NULL; + } + brdshm->busystate = 0; + } +#endif +} + +int numboards = -1; + +void resolve_boards() { + if(brdshm == NULL) { + brdshm = attach_shm(BRDSHM_KEY, sizeof(*brdshm)); + if(brdshm->touchtime == 0) + brdshm->touchtime = 1; + bcache = brdshm->bcache; + } + + while(brdshm->uptime < brdshm->touchtime) + {reload_bcache();} + numboards = brdshm->number; +} + +void touch_boards() { + time(&(brdshm->touchtime)); + numboards = -1; + resolve_boards(); +} +void addbrd_touchcache() +{ + brdshm->number++; + numboards=brdshm->number; + reset_board(numboards); +} +#if !defined(_BBS_UTIL_C_) +void reset_board(int bid) { /* Ptt: 這樣就不用老是touch board了 */ + int fd,i; + boardheader_t *bhdr; + + if(--bid < 0) + return; + if(brdshm->busystate) { + safe_sleep(1); + } else { + brdshm->busystate = 1; + bhdr = bcache; + bhdr += bid; + if((fd = open(fn_board, O_RDONLY)) > 0) { + lseek(fd, (off_t)(bid * sizeof(boardheader_t)), SEEK_SET); + read(fd, bhdr, sizeof(boardheader_t)); + close(fd); + } + sort_bcache(); + for(i=0;inumber;i++) + { + bcache[i].firstchild[0]=NULL; + bcache[i].firstchild[1]=NULL; + } + brdshm->busystate = 0; + } +} + +int apply_boards(int (*func)(boardheader_t *)) { + register int i; + register boardheader_t *bhdr; + + for(i = 0, bhdr = bcache; i < numboards; i++, bhdr++) { + if(!(bhdr->brdattr & BRD_GROUPBOARD) && Ben_Perm(bhdr) && + (*func)(bhdr) == QUIT) + return QUIT; + } + return 0; +} +#endif + +boardheader_t *getbcache(int bid) { /* Ptt改寫 */ + return bcache + bid - 1; +} +int getbtotal(int bid) +{ + return brdshm->total[bid - 1]; +} +void setbtotal(int bid) { + boardheader_t *bh = getbcache(bid); + struct stat st; + char genbuf[256]; + int num,fd; + + sprintf(genbuf, "boards/%s/.DIR", bh->brdname); + + if((fd = open(genbuf, O_RDWR)) < 0) + return; /* .DIR掛了 */ + fstat(fd, &st); + num = st.st_size / sizeof(fileheader_t); + brdshm->total[bid - 1] = num; + + if(num>0) + { + lseek(fd, (off_t) (num - 1) * sizeof(fileheader_t), SEEK_SET); + if(read(fd, genbuf, FNLEN)>=0) + { + brdshm->lastposttime[bid - 1]=(time_t) atoi(&genbuf[2]); + } + } + else + brdshm->lastposttime[bid - 1] = 0; + close(fd); + if(num) + touchdircache(bid); +} + +void +touchbpostnum(int bid, int delta) { + int *total = &brdshm->total[bid - 1]; + if (*total) *total += delta; +} + + +int getbnum(char *bname) { + register int i=0, j, start = 0, end = brdshm->number - 1; + register boardheader_t **bhdr; + bhdr=brdshm->sorted[0]; + for(i=((start+end)/2); ;i=(start+end)/2) + { + if(! (j=strcasecmp(bname,bhdr[i]->brdname))) + return (int) (bhdr[i] - bcache +1); + if(end==start) + { + break; + } + else if(i==start) + { + i=end; + start=end; + } + else if(j>0) start = i; + else end = i; + } + return 0; +} + +#if !defined(_BBS_UTIL_C_) +extern char *fn_water; +extern char *str_sysop; + +int haspostperm(char *bname) { + register int i; + char buf[200]; + + setbfile(buf, bname, fn_water); + if(belong(buf, cuser.userid)) + return 0; + + if(!strcasecmp(bname, DEFAULT_BOARD)) + return 1; + + if (!strcasecmp(bname, "PttLaw")) + return 1; + + if(!HAS_PERM(PERM_POST)) + return 0; + + if(!(i = getbnum(bname))) + return 0; + + /* 秘密看板特別處理 */ + if(bcache[i - 1].brdattr & BRD_HIDE) + return 1; + + i = bcache[i - 1].level; + + if (HAS_PERM(PERM_VIOLATELAW) && (i & PERM_VIOLATELAW)) + return 1; + else if (HAS_PERM(PERM_VIOLATELAW)) + return 0; + + return HAS_PERM(i & ~PERM_POST); +} +#endif + +/*-------------------------------------------------------*/ +/* PTT cache */ +/*-------------------------------------------------------*/ +/* cachefor 動態看版 */ +struct pttcache_t *ptt; + +static void reload_pttcache() { + if(ptt->busystate) + safe_sleep(1); + else { /* jochang: temporary workaround */ + fileheader_t item, subitem; + char pbuf[256], buf[256], *chr; + FILE *fp, *fp1, *fp2; + int id, section = 0; + + ptt->busystate = 1; + ptt->max_film = 0; + bzero(ptt->notes, sizeof ptt->notes); + setapath(pbuf, "Note"); + setadir(buf, pbuf); + id = 0; + if((fp = fopen(buf, "r"))) { + while(fread(&item, sizeof(item), 1, fp)) { + if(item.title[3]=='<' && item.title[8]=='>') { + sprintf(buf,"%s/%s", pbuf, item.filename); + setadir(buf, buf); + if(!(fp1 = fopen(buf, "r"))) + continue; + ptt->next_refresh[section] = ptt->n_notes[section] = id; + section ++; + while(fread(&subitem, sizeof(subitem), 1, fp1)) { + sprintf(buf,"%s/%s/%s", pbuf, item.filename , + subitem.filename); + if(!(fp2=fopen(buf,"r"))) + continue; + fread(ptt->notes[id],sizeof(char), 200*11, fp2); + ptt->notes[id][200*11 - 1]=0; + id++; + fclose(fp2); + if(id >= MAX_MOVIE) + break; + } + fclose(fp1); + if(id >= MAX_MOVIE || section >= MAX_MOVIE_SECTION) + break; + } + } + fclose(fp); + } + ptt->next_refresh[section] = -1; + ptt->n_notes[section] = ptt->max_film = id-1; + ptt->max_history = ptt->max_film - 2; + if(ptt->max_history > MAX_HISTORY - 1) + ptt->max_history = MAX_HISTORY - 1; + if(ptt->max_history <0) ptt->max_history=0; + + fp = fopen("etc/today_is","r"); + if(fp) { + fgets(ptt->today_is,15,fp); + if((chr = strchr(ptt->today_is,'\n'))) + *chr = 0; + ptt->today_is[15] = 0; + fclose(fp); + } + + /* 等所有資料更新後再設定 uptime */ + + ptt->uptime = ptt->touchtime ; +#if !defined(_BBS_UTIL_C_) + log_usies("CACHE", "reload pttcache"); +#endif + ptt->busystate = 0; + } +} + +void resolve_garbage() { + int count=0; + + if(ptt == NULL) { + ptt = attach_shm(PTTSHM_KEY, sizeof(*ptt)); + if(ptt->touchtime == 0) + ptt->touchtime = 1; + } + while(ptt->uptime < ptt->touchtime) { /* 不用while等 */ + reload_pttcache(); + if(count ++ > 10 && ptt->busystate) { +/* Ptt: 這邊會有問題 load超過10 秒會所有進loop的process都讓 busystate = 0 + 這樣會所有prcosee都會在load 動態看板 會造成load大增 + 但沒有用這個function的話 萬一load passwd檔的process死了 又沒有人把他 + 解開 同樣的問題發生在reload passwd +*/ + ptt->busystate = 0; +#ifndef _BBS_UTIL_C_ + log_usies("CACHE", "refork Ptt dead lock"); +#endif + } + } +} + +/*-------------------------------------------------------*/ +/* PTT's cache */ +/*-------------------------------------------------------*/ +/* cachefor from host 與最多上線人數 */ +struct fromcache_t *fcache; + +static void reload_fcache() { + if(fcache->busystate) + safe_sleep(1); + else { + FILE *fp; + + fcache->busystate = 1; + bzero(fcache->domain, sizeof fcache->domain); + if((fp = fopen("etc/domain_name_query","r"))) { + char buf[256],*po; + + fcache->top=0; + while(fgets(buf, sizeof(buf),fp)) { + if(buf[0] && buf[0] != '#' && buf[0] != ' ' && + buf[0] != '\n') { + sscanf(buf,"%s",fcache->domain[fcache->top]); + po = buf + strlen(fcache->domain[fcache->top]); + while(*po == ' ') + po++; + strncpy(fcache->replace[fcache->top],po,49); + fcache->replace[fcache->top] + [strlen(fcache->replace[fcache->top])-1] = 0; + (fcache->top)++; + if(fcache->top == MAX_FROM) + break; + } + } + } + + fcache->max_user=0; + + /* 等所有資料更新後再設定 uptime */ + fcache->uptime = fcache->touchtime; +#if !defined(_BBS_UTIL_C_) + log_usies("CACHE", "reload fcache"); +#endif + fcache->busystate = 0; + } +} + +void resolve_fcache() { + if(fcache == NULL) { + fcache = attach_shm(FROMSHM_KEY, sizeof(*fcache)); + if(fcache->touchtime == 0) + fcache->touchtime = 1; + } + while(fcache->uptime < fcache->touchtime) + reload_fcache(); +} + +extern time_t login_start_time; +extern char *fn_visable; +FILE *DEBUG = NULL; + +void hbflreload(int bid) +{ + int hbfl[MAX_FRIEND + 1], i, num, uid; + char buf[128]; + FILE *fp; + + memset(hbfl, 0, sizeof(hbfl)); + setbfile(buf, bcache[bid-1].brdname, fn_visable); + if( (fp = fopen(buf, "r")) != NULL ){ + for( num = 1 ; num <= MAX_FRIEND ; ++num ){ + if( fgets(buf, sizeof(buf), fp) == NULL ) + break; + for( i = 0 ; buf[i] != 0 ; ++i ) + if( buf[i] == ' ' ){ + buf[i] = 0; + break; + } + if( strcasecmp("guest", buf) == 0 || + (uid = searchuser(buf)) == 0 ) { + --num; + continue; + } + hbfl[num] = uid; + } + fclose(fp); + } + hbfl[0] = time(NULL); + memcpy(uhash->hbfl[bid], hbfl, sizeof(hbfl)); +} + +int hbflcheck(int bid, int uid) +{ + int i; + + if( uhash->hbfl[bid][0] < login_start_time - HBFLexpire ) + hbflreload(bid); + for( i = 1 ; uhash->hbfl[bid][i] != 0 && i <= MAX_FRIEND ; ++i ){ + if( uhash->hbfl[bid][i] == uid ) + return 0; + } + return 1; +} diff --git a/pttbbs/mbbsd/cal.c b/pttbbs/mbbsd/cal.c new file mode 100644 index 00000000..680ee9d6 --- /dev/null +++ b/pttbbs/mbbsd/cal.c @@ -0,0 +1,512 @@ +/* $Id: cal.c,v 1.1 2002/03/07 15:13:48 in2 Exp $ */ +#include +#include +#include +#include +#include +#include +#include "config.h" +#include "pttstruct.h" +#include "common.h" +#include "modes.h" +#include "perm.h" +#include "proto.h" + +extern struct utmpfile_t *utmpshm; +extern int usernum; + +/* 防堵 Multi play */ +static int count_multiplay(int unmode) { + register int i, j; + register userinfo_t *uentp; + extern struct utmpfile_t *utmpshm; + + for(i = j = 0; i < USHM_SIZE; i++) { + uentp = &(utmpshm->uinfo[i]); + if(uentp->uid == usernum) + if(uentp->lockmode == unmode) + j++; + } + return j; +} + +extern userinfo_t *currutmp; +extern char *ModeTypeTable[]; + +int lockutmpmode(int unmode, int state) { + int errorno = 0; + + if(currutmp->lockmode) + errorno = 1; + else if(count_multiplay(unmode)) + errorno = 2; + + if(errorno && !(state == LOCK_THIS && errorno == LOCK_MULTI)) { + clear(); + move(10,20); + if(errorno == 1) + prints("請先離開 %s 才能再 %s ", + ModeTypeTable[currutmp->lockmode], + ModeTypeTable[unmode]); + else + prints("抱歉! 您已有其他線相同的ID正在%s", + ModeTypeTable[unmode]); + pressanykey(); + return errorno; + } + + setutmpmode(unmode); + currutmp->lockmode = unmode; + return 0; +} + +int unlockutmpmode() { + currutmp->lockmode = 0; + return 0; +} + +extern userec_t cuser; +extern userec_t xuser; + +/* 使用錢的函數 */ +#define VICE_NEW "vice.new" + +/* Heat:發票 */ +int vice(int money, char* item) { + char buf[128]; + unsigned int viceserial=(currutmp->lastact%1000000)*100+rand()%100; + FILE *fp; + demoney(-money); + sprintf(buf, BBSHOME"/home/%c/%s/%s", + cuser.userid[0], cuser.userid, VICE_NEW); + fp = fopen(buf, "a"); + if(!fp ) + {return 0;} + + fprintf(fp, "%08d\n", viceserial); + fclose(fp); + sprintf(buf, "%s 花了%d$ 編號[%08d]",item, money, viceserial); + mail_id(cuser.userid, buf, "etc/vice.txt", "Ptt經濟部"); + return 0; +} + +#define lockreturn(unmode, state) if(lockutmpmode(unmode, state)) return +#define lockreturn0(unmode, state) if(lockutmpmode(unmode, state)) return 0 +#define lockbreak(unmode, state) if(lockutmpmode(unmode, state)) break +#define SONGBOOK "etc/SONGBOOK" +#define OSONGPATH "etc/SONGO" +extern char trans_buffer[]; +extern char save_title[]; + +static int osong(char *defaultid) { + char destid[IDLEN + 1],buf[200],genbuf[200],filename[256],say[51]; + char receiver[60],ano[2]; + FILE *fp,*fp1;// *fp2; + fileheader_t mail; + time_t now; + int nsongs; + + now = time(NULL); + strcpy(buf, Cdatedate(&now)); + + lockreturn0(OSONG, LOCK_MULTI); + + /* Jaky 一人一天點一首 */ + if(!strcmp(buf, Cdatedate(&cuser.lastsong)) && !HAS_PERM(PERM_SYSOP)) { + move(22,0); + outs("你今天已經點過囉,明天再點吧...."); + refresh(); + pressanykey(); + + unlockutmpmode(); + return 0; + } + + if(cuser.money < 200) { + move(22, 0); + outs("點歌要200銀唷!...."); + refresh(); + pressanykey(); + unlockutmpmode(); + return 0; + } + move(12, 0); + clrtobot(); + sprintf(buf, "親愛的 %s 歡迎來到歐桑自動點歌系統\n", cuser.userid); + outs(buf); + trans_buffer[0] = 0; + if(!defaultid){ + getdata(13, 0, "要點給誰呢:[可直接按 Enter 先選歌]", destid, IDLEN + 1, DOECHO); + while (!destid[0]){ + a_menu("點歌歌本", SONGBOOK,0 ); + clear(); + getdata(13, 0, "要點給誰呢:[可按 Enter 重新選歌]", destid, IDLEN + 1, DOECHO); + } + } + else + strcpy(destid,defaultid); + + /* Heat:點歌者匿名功能 */ + getdata(14,0, "要匿名嗎?[y/n]:", ano, 2, DOECHO); + + if(!destid[0]) { + unlockutmpmode(); + return 0; + } + + getdata_str(14, 0, "想要要對他(她)說..:", say, 51, DOECHO, "我愛妳.."); + sprintf(save_title, "%s:%s", (ano[0]=='y')?"匿名者":cuser.userid, say); + getdata_str(16, 0, "寄到誰的信箱(可用E-mail)?", receiver, 45, + LCECHO, destid); + + + + if (!trans_buffer[0]){ + outs("\n接著要選歌囉..進入歌本好好的選一首歌吧..^o^"); + pressanykey(); + a_menu("點歌歌本", SONGBOOK,0 ); + } + if(!trans_buffer[0] || strstr(trans_buffer, "home") || + strstr(trans_buffer, "boards") || !(fp = fopen(trans_buffer, "r"))) { + unlockutmpmode(); + return 0; + } + + strcpy(filename, OSONGPATH); + + stampfile(filename, &mail); + + unlink(filename); + + if(!(fp1 = fopen(filename, "w"))) { + fclose(fp); + unlockutmpmode(); + return 0; + } + + strcpy(mail.owner, "點歌機"); + sprintf(mail.title, "◇ %s 點給 %s ", (ano[0]=='y')?"匿名者":cuser.userid, destid); + mail.savemode = 0; + + while(fgets(buf, 200, fp)) { + char *po; + if(!strncmp(buf, "標題: ", 6)) { + clear(); + move(10,10);prints("%s", buf); + pressanykey(); + fclose(fp); + unlockutmpmode(); + return 0; + } + while((po = strstr(buf, "<~Src~>"))) { + po[0] = 0; + sprintf(genbuf,"%s%s%s",buf,(ano[0]=='y')?"匿名者":cuser.userid,po+7); + strcpy(buf,genbuf); + } + while((po = strstr(buf, "<~Des~>"))) { + po[0] = 0; + sprintf(genbuf,"%s%s%s",buf,destid,po+7); + strcpy(buf,genbuf); + } + while((po = strstr(buf, "<~Say~>"))) { + po[0] = 0; + sprintf(genbuf,"%s%s%s",buf,say,po+7); + strcpy(buf,genbuf); + } + fputs(buf,fp1); + } + fclose(fp1); + fclose(fp); + +// do_append(OSONGMAIL "/.DIR", &mail2, sizeof(mail2)); + + if(do_append(OSONGPATH "/.DIR", &mail, sizeof(mail)) != -1) { + cuser.lastsong = time(NULL); + /* Jaky 超過 500 首歌就開始砍 */ + nsongs=get_num_records(OSONGPATH "/.DIR", sizeof(mail)); + if (nsongs > 500){ + delete_range(OSONGPATH "/.DIR", 1, nsongs-500); + } + /* 把第一首拿掉 */ + vice(200, "點歌"); + } + sprintf(save_title, "%s:%s", (ano[0]=='y')?"匿名者":cuser.userid, say); + hold_mail(filename, destid); + + if(receiver[0]) { +#ifndef USE_BSMTP + bbs_sendmail(filename, save_title, receiver); +#else + bsmtp(filename, save_title, receiver,0); +#endif + } + clear(); + outs( + "\n\n 恭喜您點歌完成囉..\n" + " 一小時內動態看板會自動重新更新\n" + " 大家就可以看到您點的歌囉\n\n" + " 點歌有任何問題可以到Note板的精華區找答案\n" + " 也可在Note板精華區看到自己的點歌記錄\n" + " 有任何保貴的意見也歡迎到Note板留話\n" + " 讓親切的板主為您服務\n"); + pressanykey(); + sortsong(); + topsong(); + + unlockutmpmode(); + return 1; +} + +int ordersong() { + osong(NULL); + return 0; +} + +static int inmailbox(int m) { + passwd_query(usernum, &xuser); + cuser.exmailbox = xuser.exmailbox + m; + passwd_update(usernum, &cuser); + return cuser.exmailbox; +} + + +extern int b_lines; + +#if !HAVE_FREECLOAK +/* 花錢選單 */ +int p_cloak() { + char buf[4]; + getdata(b_lines-1, 0, + currutmp->invisible ? "確定要現身?[y/N]" : "確定要隱身?[y/N]", + buf, 3, LCECHO); + if(buf[0] != 'y') + return 0; + if(cuser.money >= 19) { + vice(19, "cloak"); + currutmp->invisible %= 2; + outs((currutmp->invisible ^= 1) ? MSG_CLOAKED : MSG_UNCLOAK); + refresh(); + safe_sleep(1); + } + return 0; +} +#endif + +int p_from() { + char ans[4]; + + getdata(b_lines-2, 0, "確定要改故鄉?[y/N]", ans, 3, LCECHO); + if(ans[0] != 'y') + return 0; + reload_money(); + if(cuser.money < 49) + return 0; + if(getdata_buf(b_lines-1, 0, "請輸入新故鄉:", + currutmp->from, 17, DOECHO)) { + vice(49,"home"); + currutmp->from_alias=0; + } + return 0; +} + +int p_exmail() { + char ans[4],buf[200]; + int n; + + if(cuser.exmailbox >= MAX_EXKEEPMAIL) { + sprintf(buf,"容量最多增加 %d 封,不能再買了。", MAX_EXKEEPMAIL); + outs(buf); + refresh(); + return 0; + } + sprintf(buf,"您曾增購 %d 封容量,還要再買多少?", + cuser.exmailbox); + + getdata_str(b_lines-2, 0, buf, ans, 3, LCECHO, "10"); + + n = atoi(ans); + if(!ans[0] || !n) + return 0; + if(n + cuser.exmailbox > MAX_EXKEEPMAIL) + n = MAX_EXKEEPMAIL - cuser.exmailbox; + reload_money(); + if(cuser.money < n * 1000) + return 0; + vice(n * 1000, "mail"); + inmailbox(n); + return 0; +} + +void mail_redenvelop(char* from, char* to, int money, char mode){ + char genbuf[200]; + fileheader_t fhdr; + time_t now; + FILE* fp; + sprintf(genbuf, "home/%c/%s", to[0], to); + stampfile(genbuf, &fhdr); + if (!(fp = fopen(genbuf, "w"))) + return; + now = time(NULL); + fprintf(fp, "作者: %s\n" + "標題: 招財進寶\n" + "時間: %s\n" + "\033[1;33m親愛的 %s :\n\n\033[m" + "\033[1;31m 我包給你一個 %d 元的大紅包喔 ^_^\n\n" + " 禮輕情意重,請笑納...... ^_^\033[m\n" + , from, ctime(&now), to, money); + fclose(fp); + sprintf(fhdr.title, "招財進寶"); + strcpy(fhdr.owner, from); + + if (mode == 'y') + vedit(genbuf, NA, NULL); + sprintf(genbuf, "home/%c/%s/.DIR", to[0], to); + append_record(genbuf, &fhdr, sizeof(fhdr)); +} + +int p_give() { + int money; + char id[IDLEN + 1], genbuf[90]; + time_t now = time(0); + + move(1,0); + usercomplete("這位幸運兒的id:", id); + if(!id[0] || !strcmp(cuser.userid,id) || + !getdata(2, 0, "要給多少錢:", genbuf, 7, LCECHO)) + return 0; + money = atoi(genbuf); + reload_money(); + if(money > 0 && cuser.money >= money ) { + deumoney(searchuser(id), money); + demoney(-money); + now = time(NULL); + sprintf(genbuf,"%s\t給%s\t%d\t%s", cuser.userid, id, money, + ctime(&now)); + log_file(FN_MONEY, genbuf); + genbuf[0] = 'n'; + getdata(3, 0, "要自行書寫紅包袋嗎?[y/N]", genbuf, 2, LCECHO); + mail_redenvelop(cuser.userid, id, money, genbuf[0]); + } + return 0; +} + +int p_sysinfo() { + char buf[100]; + long int total,used; + float p; + + move(b_lines-1,0); + clrtoeol(); + cpuload(buf); + outs("CPU 負荷 : "); + outs(buf); + + p = swapused(&total,&used); + sprintf(buf, " 虛擬記憶體: %.1f%%(全部:%ldMB 用掉:%ldMB)\n", + p*100, total >> 20, used >> 20); + outs(buf); + pressanykey(); + return 0; +} + +/* 小計算機 */ +static void ccount(float *a, float b, int cmode) { + switch(cmode) { + case 0: + case 1: + case 2: + *a += b; + break; + case 3: + *a -= b; + break; + case 4: + *a *= b; + break; + case 5: + *a /= b; + break; + } +} + +int cal() { + float a = 0; + char flo = 0, ch = 0; + char mode[6] = {' ','=','+','-','*','/'} , cmode = 0; + char buf[100] = "[ 0] [ ] ", b[20] = "0"; + + move(b_lines - 1, 0); + clrtoeol(); + outs(buf); + move(b_lines, 0); + clrtoeol(); + outs("\033[44m 小計算機 \033[31;47m (0123456789+-*/=) " + "\033[30m輸入 \033[31m " + "(Q)\033[30m 離開 \033[m"); + while(1) { + ch = igetch(); + switch(ch) { + case '\r': + ch = '='; + case '=': + case '+': + case '-': + case '*': + case '/': + ccount(&a, atof(b), cmode); + flo = 0; + b[0] = '0'; + b[1] = 0; + move(b_lines - 1, 0); + sprintf(buf, "[%13.2f] [%c] ", a, ch); + outs(buf); + break; + case '.': + if(!flo) + flo = 1; + else + break; + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + case '0': + if(strlen(b) > 13) + break; + if(flo || b[0] != '0') + sprintf(b,"%s%c",b,ch); + else + b[0]=ch; + move(b_lines - 1, 0); + sprintf(buf, "[%13s] [%c]", b, mode[(int)cmode]); + outs(buf); + break; + case 'q': + return 0; + } + + switch(ch) { + case '=': + a = 0; + cmode = 0; + break; + case '+': + cmode = 2; + break; + case '-': + cmode = 3; + break; + case '*': + cmode = 4; + break; + case '/': + cmode = 5; + break; + } + } +} diff --git a/pttbbs/mbbsd/calendar.c b/pttbbs/mbbsd/calendar.c new file mode 100644 index 00000000..78ca46cf --- /dev/null +++ b/pttbbs/mbbsd/calendar.c @@ -0,0 +1,284 @@ +/* $Id: calendar.c,v 1.1 2002/03/07 15:13:48 in2 Exp $ */ +#include +#include +#include +#include +#include +#include "config.h" +#include "pttstruct.h" +#include "proto.h" +#include "modes.h" + +typedef struct event_t { + int year, month, day, days; + int color; + char *content; + struct event_t *next; +} event_t; + +static int MonthDay(int m, int leap) { + static int day[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; + + return leap && m == 2 ? 29 : day[m - 1]; +} + +static int IsLeap(int y) { + if(y % 400 == 0 || (y % 4 == 0 && y % 100 != 0)) + return 1; + else + return 0; +} + +static int Days(int y, int m, int d) { + int i, w; + + w = 1 + 365 * (y - 1) + + ((y - 1) / 4) - ((y - 1) / 100) + ((y - 1) / 400) + + d - 1; + for(i = 1; i < m; i++) + w += MonthDay(i, IsLeap(y)); + return w; +} + +static int ParseDate(char *date, event_t *t) { + char *y, *m, *d; + + y = strtok(date, "/"); + m = strtok(NULL, "/"); + d = strtok(NULL, ""); + if(!y || !m || !d) + return 1; + + t->year = atoi(y); + t->month = atoi(m); + t->day = atoi(d); + if(t->year < 1 || t->month < 1 || t->month > 12 || + t->day < 1 || t->day > 31) + return 1; + t->days = Days(t->year, t->month, t->day); + return 0; +} + +static int ParseColor(char *color) { + struct { + char *str; + int val; + } c[] = { + {"black", 0}, + {"red", 1}, + {"green", 2}, + {"yellow", 3}, + {"blue", 4}, + {"magenta", 5}, + {"cyan", 6}, + {"white", 7} + }; + int i; + + for(i = 0; i < sizeof(c) / sizeof(c[0]); i++) + if(strcasecmp(color, c[i].str) == 0) + return c[i].val; + return 7; +} + +static void InsertEvent(event_t *head, event_t *t) { + event_t *p; + + for(p = head; p->next && p->next->days < t->days; p = p->next); + t->next = p->next; + p->next = t; +} + +static void FreeEvent(event_t *e) { + event_t *n; + + while(e) { + n = e->next; + free(e); + e = n; + } +} + +extern userec_t cuser; + +static event_t *ReadEvent(int today) { + FILE *fp; + char buf[256]; + static event_t head; + + head.next = NULL; + setcalfile(buf, cuser.userid); + fp = fopen(buf, "r"); + if(fp) { + while(fgets(buf, sizeof(buf), fp)) { + char *date, *color, *content; + event_t *t; + + if(buf[0] == '#') + continue; + + date = strtok(buf, " \t\n"); + color = strtok(NULL, " \t\n"); + content = strtok(NULL, "\n"); + if(!date || !color || !content) + continue; + + t = malloc(sizeof(event_t)); + if(ParseDate(date, t) || t->days < today) { + free(t); + continue; + } + t->color = ParseColor(color) + 30; + for(; *content == ' ' || *content == '\t'; content++); + t->content = strdup(content); + InsertEvent(&head, t); + } + fclose(fp); + } + return head.next; +} + +static char **AllocCalBuffer(int line, int len) { + int i; + char **p; + + p = malloc(sizeof(char *) * line); + p[0] = malloc(sizeof(char) * line * len); + for(i = 1; i < line; i++) + p[i] = p[i - 1] + len; + return p; +} + +static void FreeCalBuffer(char **buf) { + free(buf[0]); + free(buf); +} + +#define CALENDAR_COLOR "\33[0;30;47m" +#define HEADER_COLOR "\33[1;44m" +#define HEADER_SUNDAY_COLOR "\33[31m" +#define HEADER_DAY_COLOR "\33[33m" + +static int GenerateCalendar(char **buf, int y, int m, int today, event_t *e) { + static char *week_str[7] = {"日", "一", "二", "三", "四", "五", "六"}; + static char *month_color[12] = { + "\33[1;32m", "\33[1;33m", "\33[1;35m", "\33[1;36m", + "\33[1;32m", "\33[1;33m", "\33[1;35m", "\33[1;36m", + "\33[1;32m", "\33[1;33m", "\33[1;35m", "\33[1;36m" + }; + static char *month_str[12] = { + "一月 ", "二月 ", "三月 ", "四月 ", "五月 ", "六月 ", + "七月 ", "八月 ", "九月 ", "十月 ", "十一月", "十二月" + }; + + char *p, attr1[16], *attr2; + int i, d, w, line = 0, first_day = Days(y, m, 1); + + + /* week day banner */ + p = buf[line]; + p += sprintf(p, " %s%s%s%s", HEADER_COLOR, HEADER_SUNDAY_COLOR, + week_str[0], HEADER_DAY_COLOR); + for(i = 1; i < 7; i++) + p += sprintf(p, " %s", week_str[i]); + p += sprintf(p, "\33[m"); + + /* indent for first line */ + p = buf[++line]; + p += sprintf(p, " %s", CALENDAR_COLOR); + for(i = 0, w = first_day % 7; i < w; i++) + p += sprintf(p, " "); + + /* initial event */ + for(; e && e->days < first_day; e = e->next); + + d = MonthDay(m, IsLeap(y)); + for(i = 1; i <= d; i++, w = (w + 1) % 7) { + attr1[0] = 0; + attr2 = ""; + while(e && e->days == first_day + i - 1) { + sprintf(attr1, "\33[1;%dm", e->color); + attr2 = CALENDAR_COLOR; + e = e->next; + } + if(today == first_day + i - 1) { + strcpy(attr1, "\33[1;37;42m"); + attr2 = CALENDAR_COLOR; + } + p += sprintf(p, "%s%2d%s", attr1, i, attr2); + + if(w == 6) { + p += sprintf(p, "\33[m"); + p = buf[++line]; + /* show month */ + if(line >= 2 && line <= 4) + p += sprintf(p, "%s%2.2s\33[m %s", month_color[m - 1], + month_str[m - 1] + (line - 2) * 2, + CALENDAR_COLOR); + else if(i < d) + p += sprintf(p, " %s", CALENDAR_COLOR); + } else + *p++ = ' '; + } + + /* fill up the last line */ + if(w) { + for(w = 7 - w; w; w--) + p += sprintf(p, w == 1 ? " " : " "); + p += sprintf(p, "\33[m"); + } + return line + 1; +} + +int calendar() { + char **buf; + time_t t; + struct tm now; + int i, y, m, today, lines = 0; + event_t *head = NULL, *e = NULL; + + /* initialize date */ + time(&t); + memcpy(&now, localtime(&t), sizeof(struct tm)); + today = Days(now.tm_year + 1900, now.tm_mon + 1, now.tm_mday); + y = now.tm_year + 1900, m = now.tm_mon + 1; + + /* read event */ + head = e = ReadEvent(today); + + /* generate calendar */ + buf = AllocCalBuffer(22, 256); + for(i = 0; i < 22; i++) + sprintf(buf[i], "%24s", ""); + for(i = 0; i < 3; i++) { + lines += GenerateCalendar(buf + lines, y, m, today, e) + 1; + if(m == 12) + y++, m = 1; + else + m++; + } + + /* output */ + clear(); + outc('\n'); + for(i = 0; i < 22; i++) { + outs(buf[i]); + if(i == 0) { + prints("\t\33[1;37m現在是 %d.%02d.%02d %2d:%02d:%02d%cm\33[m", + now.tm_year + 1900, now.tm_mon + 1, now.tm_mday, + (now.tm_hour == 0 || now.tm_hour == 12) ? + 12 : now.tm_hour % 12, now.tm_min, now.tm_sec, + now.tm_hour >= 12 ? 'p' : 'a'); + } else if(i >= 2 && e) { + prints("\t\33[1;37m(\33[%dm%3d\33[37m)\33[m %02d/%02d %s", + e->color, e->days - today, + e->month, e->day, e->content); + e = e->next; + } + outc('\n'); + } + FreeEvent(head); + FreeCalBuffer(buf); + pressanykey(); + return 0; +} diff --git a/pttbbs/mbbsd/card.c b/pttbbs/mbbsd/card.c new file mode 100644 index 00000000..cfa10b0c --- /dev/null +++ b/pttbbs/mbbsd/card.c @@ -0,0 +1,625 @@ +/* $Id: card.c,v 1.1 2002/03/07 15:13:48 in2 Exp $ */ +#include +#include +#include +#include "config.h" +#include "pttstruct.h" +#include "common.h" +#include "modes.h" +#include "proto.h" +extern int usernum; + +static int card_remain(int cards[]) { + int i, temp = 0; + + for(i = 0; i < 52; i++) + temp += cards[i]; + if(temp == 52) + return 1; + return 0; +} + +/* 0 Spare , 1 heart , ...3 dimon */ +static int card_flower(int card) { + return (card / 13); +} + +/* 1...13 */ +static int card_number(int card) { + return (card % 13 + 1); +} + +static int card_select(int *now) { + char *cc[2] = {"\033[44m \033[m", + "\033[1;33;41m △ \033[m"}; + + while(1) { + move(20, 0); + clrtoeol(); + prints("%s%s%s%s%s", (*now == 0) ? cc[1] : cc[0], + (*now == 1) ? cc[1] : cc[0], + (*now == 2) ? cc[1] : cc[0], + (*now == 3) ? cc[1] : cc[0], + (*now == 4) ? cc[1] : cc[0]); + switch(egetch()) { + case 'Q': + case 'q': + return 0; + case '+': + case ',': + return 1; + case '\r': + return -1; + case KEY_LEFT: + *now = (*now + 4) % 5; + break; + case KEY_RIGHT: + *now = (*now + 1) % 5; + break; + case '1': + *now = 0; + break; + case '2': + *now = 1; + break; + case '3': + *now = 2; + break; + case '4': + *now = 3; + break; + case '5': + *now = 4; + break; + } + } +} + +static void card_display(int cline, int number, int flower, int show) { + int color = 31; + char *cn[13] = {"A", "2", "3", "4", "5", "6", + "7", "8", "9", "10", "J", "Q", "K"}; + if(flower == 0 || flower == 3) + color = 36; + if((show < 0) && (cline > 1 && cline < 8)) + prints("│\033[1;33;42m※※※※\033[m│"); + else + switch(cline) { + case 1: + prints("╭────╮"); + break; + case 2: + prints("│\033[1;%dm%s\033[m │", color, cn[number - 1]); + break; + case 3: + if(flower == 1) + prints("│\033[1;%dm◢◣◢◣\033[m│", color); + else + prints("│\033[1;%dm ◢◣ \033[m│", color); + break; + case 4: + if(flower == 1) + prints("│\033[1;%dm████\033[m│", color); + else if (flower == 3) + prints("│\033[1;%dm◣██◢\033[m│", color); + else + prints("│\033[1;%dm◢██◣\033[m│", color); + break; + case 5: + if(flower == 0) + prints("│\033[1;%dm████\033[m│", color); + else if (flower == 3) + prints("│\033[1;%dm█◥◤█\033[m│", color); + else + prints("│\033[1;%dm◥██◤\033[m│", color); + break; + case 6: + if(flower == 0) + prints("│\033[1;%dm ◢◣ \033[m│", color); + else if (flower == 3) + prints("│\033[1;%dm◥◢◣◤\033[m│", color); + else + prints("│\033[1;%dm ◥◤ \033[m│", color); + break; + case 7: + prints("│ \033[1;%dm%s\033[m│", color, cn[number - 1]); + break; + case 8: + prints("╰────╯"); + break; + } +} + +static void card_show(int cpu[], int c[], int me[], int m[]) { + int i, j; + + for(j = 0; j < 8; j++) { + move(2 + j, 0); + clrtoeol(); + for(i = 0; i < 5 && cpu[i] >= 0; i++) + card_display(j + 1, card_number(cpu[i]), + card_flower(cpu[i]), c[i]); + } + + for(j = 0; j < 8; j++) { + move(11 + j, 0); + clrtoeol(); + for(i = 0; i < 5 && me[i] >= 0; i++) + card_display(j + 1, card_number(me[i]), card_flower(me[i]), m[i]); + } +} +static void card_new(int cards[]) { + memset(cards, 0, sizeof(int)*52); +} + +static int card_give(int cards[]) { + int i, error; + for(error=0, i=rand()%52; cards[i] == 1 && error<52; error++, i=rand()%52); + if(error==52) card_new(cards); // Ptt:這邊有dead lock問題 + cards[i] = 1; + return i; +} + +static void card_start(char name[]) { + clear(); + stand_title(name); + move(1, 0); + prints(" \033[1;33;41m 電 腦 \033[m"); + move(10, 0); + prints("\033[1;34;44m◆∼◆∼◆∼◆∼◆∼◆∼◆∼◆∼◆∼◆∼◆∼◆∼" + "◆∼◆∼◆∼◆∼◆∼◆∼◆∼◆\033[m"); + move(19, 0); + prints(" \033[1;37;42m 自 己 \033[m"); +} + +static int card_99_add(int i, int aom, int count) { + if (i == 4 || i == 5 || i == 11) + return count; + else if(i == 12) + return count + 20 * aom; + else if(i == 10) + return count + 10 * aom; + else if(i == 13) + return 99; + else + return count + i; +} + +static int card_99_cpu(int cpu[], int *count) { + int stop = -1; + int twenty = -1; + int ten = -1; + int kill = -1; + int temp, num[10]; + int other = -1; + int think = 99-(*count); + int i, j; + + for(i = 0; i < 10; i++) + num[i] = -1; + for(i = 0; i < 5; i++) { + temp = card_number(cpu[i]); + if(temp == 4 || temp == 5 || temp == 11) + stop = i; + else if(temp == 12) + twenty = i; + else if (temp == 10) + ten = i; + else if (temp == 13) + kill = i; + else { + other = i; + num[temp] = i; + } + } + for(j = 9; j > 0; j--) + if(num[j] >= 0 && j != 4 && j != 5 && think >= j) { + (*count) += j; + return num[j]; + } + if((think >= 20) && (twenty >= 0)) { + (*count) += 20; + return twenty; + } else if((think >= 10) && (ten >= 0)) { + (*count) += 10; + return ten; + } else if(stop >= 0) + return stop; + else if (kill >= 0) { + (*count) = 99; + return kill; + } else if(ten >= 0) { + (*count) -= 10; + return ten; + } else if(twenty >= 0) { + (*count) -= 20; + return twenty; + } else { + (*count) += card_number(cpu[0]); + return 0; + } +} + +int card_99() { + int i, j, turn; + int cpu[5], c[5], me[5], m[5]; + int cards[52]; + int count = 0; + char *ff[4] = {"\033[1;36m黑桃", "\033[1;31m紅心", + "\033[1;31m方塊", "\033[1;36m黑花"}; + char *cn[13] = {"A", "2", "3", "4", "5", "6", + "7", "8", "9", "10", "J", "Q", "K"}; + for(i = 0; i < 5; i++) + cpu[i] = c[i] = me[i] = m[i] = -1; + setutmpmode(CARD_99); + card_start("天長地久"); + card_new(cards); + for(i = 0; i < 5; i++) { + cpu[i] = card_give(cards); + me[i] = card_give(cards); + m[i] = 1; + } + card_show(cpu, c, me, m); + j = 0; + turn = 1; + move(21, 0); + clrtoeol(); + prints("[0]目前 %d , 殘 %d 點\n", count, 99 - count); + prints("左右鍵移動游標, [Enter]確定, [ + ]表加二十(加十), [Q/q]放棄遊戲"); + while(1) { + i = card_select(&j); + if(i == 0) /*放棄遊戲*/ + return 0; + count = card_99_add(card_number(me[j]), i, count); + move(21 + (turn / 2) % 2, 0); + clrtoeol(); + prints("[%d]您出 %s%s\033[m 目前 \033[1;31m%d/\033[34m%d\033[m 點", + turn, ff[card_flower(me[j])], + cn[card_number(me[j]) - 1], count, 99 - count); + me[j] = card_give(cards); + turn++; + if(count < 0) + count = 0; + card_show(cpu, c, me, m); + pressanykey(); + if(count > 99) { + move(22, 0); + clrtoeol(); + prints("[%d]結果..YOU LOSS..目前 \033[1;31m%d/\033[34m%d\033[m 點", + turn, count, 99 - count); + pressanykey(); + return 0; + } + i = card_99_cpu(cpu, &count); + move(21 + (turn / 2 + 1) % 2, 40); + prints("[%d]電腦出 %s%s\033[m 目前 \033[1;31m%d/\033[34m%d\033[m 點", + turn, ff[card_flower(cpu[i])], + cn[card_number(cpu[i]) - 1], count, 99 - count); + cpu[i] = card_give(cards); + turn++; + if(count < 0) + count = 0; + if(count > 99) { + move(22, 0); + clrtoeol(); + prints("[%d]結果..YOU WIN!..目前 \033[1;31m%d/\033[34m%d\033[m 點", + turn, count, 99 - count); + pressanykey(); + return 0; + } + if(!card_remain(cards)) { + card_new(cards); + for(i = 0; i < 5; i++) { + cards[me[i]] = 1; + cards[cpu[i]] = 1; + } + } + } +} + +#define PMONEY (10) +#define TEN_HALF (5) /*十點半的Ticket*/ +#define JACK (10) /*黑傑克的Ticket*/ +#define NINE99 (99) /*99 的Ticket*/ + +extern userec_t cuser; + +static int game_log(int type, int money) { + FILE *fp; + + if(money > 0) + demoney(money); + + switch(type) { + case JACK: + fp = fopen(BBSHOME "/etc/card/jack.log", "a"); + if(!fp) + return 0; + fprintf(fp, "%s win:%d\n", cuser.userid, money); + fclose(fp); + break; + case TEN_HALF: + fp = fopen(BBSHOME "/etc/card/tenhalf.log", "a"); + if(!fp) + return 0; + fprintf(fp, "%s win:%d\n", cuser.userid, money); + fclose(fp); + break; + } + return 0; +} + +static int card_double_ask() { + char buf[100], buf2[3]; + + sprintf(buf, "[ %s ]您現在共有 %d P幣, 現在要分組(加收 %d 元)嗎? [y/N]", + cuser.userid, cuser.money, JACK); + reload_money(); + if(cuser.money < JACK) + return 0; + getdata(20, 0, buf, buf2, 2, LCECHO); + if(buf2[0] == 'y' || buf2[0] == 'Y') + return 1; + return 0; +} + +static int card_ask() { + char buf[100], buf2[3]; + + sprintf(buf, "[ %s ]您現在共有 %d P幣, 還要加牌嗎? [y/N]", + cuser.userid, cuser.money); + getdata(20, 0 , buf, buf2, 2, LCECHO); + if(buf2[0] == 'y' || buf2[0] == 'Y') + return 1; + return 0; +} + +static int card_alls_lower(int all[]) { + int i, count = 0; + for (i = 0; i < 5 && all[i] >= 0; i++) + if(card_number(all[i]) <= 10) + count += card_number(all[i]); + else + count += 10; + return count; +} + +static int card_alls_upper(int all[]) { + int i, count; + + count = card_alls_lower(all); + for (i = 0; i < 5 && all[i] >= 0 && count <= 11; i++) + if (card_number(all[i]) == 1) + count += 10; + return count; +} + +extern int b_lines; + +static int card_jack(int *db) { + int i, j; + int cpu[5], c[5], me[5], m[5]; + int cards[52]; + + for(i = 0;i<5;i++) + cpu[i] = c[i] = me[i] = m[i] = -1; + + if((*db)<0) { + card_new(cards); + card_start("黑傑克"); + for(i = 0; i < 2; i++) { + cpu[i] = card_give(cards); + me[i] = card_give(cards); + } + } else { + card_start("黑傑克DOUBLE追加局"); + cpu[0] = card_give(cards); + cpu[1] = card_give(cards); + me[0] = *db; + me[1] = card_give(cards); + } + c[1] = m[0] = m[1] = 1; + card_show(cpu, c, me, m); + if((card_number(me[0]) == 0 && card_number(me[1]) == 12) || + (card_number(me[1]) == 0 && card_number(me[0]) == 12)) { + if(card_flower(me[0]) == 0 && card_flower(me[1]) == 0) { + move(b_lines - 1, 0); + prints("非常不錯唷! (超級黑傑克!! 加 %d 元)", JACK * 10); + game_log(JACK, JACK * 10); + pressanykey(); + return 0; + } else { + move(b_lines - 1, 0); + prints("很不錯唷! (黑傑克!! 加 %d 元)", JACK * 5); + game_log(JACK, JACK * 5); + pressanykey(); + return 0; + } + } + if((card_number(cpu[0]) == 0 && card_number(cpu[1]) == 12) || + (card_number(cpu[1]) == 0 && card_number(cpu[0]) == 12)) { + c[0] = 1; + card_show(cpu, c, me, m); + move(b_lines - 1, 0); + prints("嘿嘿...不好意思....黑傑克!!"); + game_log(JACK, 0); + pressanykey(); + return 0; + } + if((*db < 0)&& (card_number(me[0]) == card_number(me[1])) && + (card_double_ask())) { + *db = me[1]; + me[1] = card_give(cards); + card_show(cpu, c, me, m); + } + i = 2; + while(i < 5 && card_ask()) { + me[i] = card_give(cards); + m[i] = 1; + card_show(cpu, c, me, m); + if(card_alls_lower(me) > 21) { + move(b_lines - 1, 0); + prints("嗚嗚...爆掉了!"); + game_log(JACK, 0); + pressanykey(); + return 0; + } + i++; + if((i == 3) && (card_number(me[0]) == 7) && + (card_number(me[1]) == 7) && (card_number(me[2]) == 7)) { + move(b_lines - 1, 0); + prints("很不錯唷! (幸運七號!! 加 %d 元)", JACK * 7); + game_log(JACK, JACK * 7); + pressanykey(); + return 0; + } + } + if(i == 5) {/*過五關*/ + move(b_lines - 1, 0); + prints("好厲害唷! 過五關嘍! 加P幣 %d 元!", 5 * JACK); + game_log(JACK, JACK * 5); + pressanykey(); + return 0; + } + j = 2; + c[0] = 1; + while((card_alls_upper(cpu) < card_alls_upper(me))|| + ((card_alls_upper(cpu) == card_alls_upper(me) && j < i ) && j < 5)) { + cpu[j] = card_give(cards); + c[j] = 1; + if(card_alls_lower(cpu) > 21) { + card_show(cpu, c, me, m); + move(b_lines - 1, 0); + prints("呵呵...電腦爆掉了! 你贏了! 可得P幣 %d 元", JACK * 2); + game_log(JACK, JACK * 2); + pressanykey(); + return 0; + } + j++; + } + card_show(cpu, c, me, m); + move(b_lines - 1, 0); + prints("哇哇...電腦贏了!"); + game_log(JACK, 0); + pressanykey(); + return 0; +} + +int g_card_jack() { + int db; + char buf[3]; + + setutmpmode(JACK_CARD); + while(1) { + reload_money(); + if(cuser.money < JACK) { + outs("您的錢不夠唷!去多發表些有意義的文章再來~~~"); + return 0; + } + getdata(b_lines - 1, 0, "確定要玩黑傑克嗎 一次十元唷?(Y/N)?[N]", + buf, 3, LCECHO); + if((*buf != 'y') && (*buf != 'Y')) + break; + else { + db = -1; + vice(PMONEY, "黑傑克"); + card_jack(&db); + if(db >= 0) + card_jack(&db); + } + } + return 0; +} + +static int card_all(int all[]) { + int i, count = 0; + + for (i = 0; i < 5 && all[i] >= 0; i++) + if(card_number(all[i]) <= 10) + count += 2 * card_number(all[i]); + else + count += 1; + return count; +} + +static int ten_helf() { + int i, j; + int cpu[5], c[5], me[5], m[5]; + int cards[52]; + + card_start("十點半"); + card_new(cards); + for (i = 0; i < 5; i++) + cpu[i] = c[i] = me[i] = m[i] = -1; + + cpu[0] = card_give(cards); + me[0] = card_give(cards); + m[0] = 1; + card_show(cpu, c, me, m); + i = 1; + while(i < 5 && card_ask()) { + me[i] = card_give(cards); + m[i] = 1; + card_show(cpu, c, me, m); + if(card_all(me) > 21) { + move(b_lines - 1, 0); + prints("嗚嗚...爆掉了!"); + game_log(TEN_HALF, 0); + pressanykey(); + return 0; + } + i++; + } + if(i == 5) {/*過五關*/ + move(b_lines - 1, 0); + prints("好厲害唷! 過五關嘍! 加P幣 %d 元!", 5 * PMONEY); + game_log(TEN_HALF, PMONEY * 5); + pressanykey(); + return 0; + } + j = 1; + c[0] = 1; + while( j<5 && ((card_all(cpu) < card_all(me)) || + (card_all(cpu) == card_all(me) && j < i))) { + cpu[j] = card_give(cards); + c[j] = 1; + if(card_all(cpu) > 21) { + card_show(cpu, c, me, m); + move(b_lines - 1, 0); + prints("呵呵...電腦爆掉了! 你贏了! 可得P幣 %d 元", PMONEY * 2); + game_log(TEN_HALF, PMONEY * 2); + pressanykey(); + return 0; + } + j++; + } + card_show(cpu, c, me, m); + move(b_lines - 1, 0); + prints("哇哇...電腦贏了!"); + game_log(TEN_HALF, 0); + pressanykey(); + return 0; +} + +int g_ten_helf() { + char buf[3]; + + setutmpmode(TENHALF); + while(1) { + reload_money(); + if(cuser.money < TEN_HALF) { + outs("您的錢不夠唷!去多發表些有意義的文章再來~~~"); + return 0; + } + getdata(b_lines - 1, 0, + "\033[1;37m確定要玩十點半嗎 一次十元唷?(Y/N)?[N]\033[m", + buf, 3, LCECHO); + if(buf[0] != 'y' && buf[0] != 'Y') + return 0; + else { + vice(PMONEY, "十點半"); + ten_helf(); + } + } + return 0; +} diff --git a/pttbbs/mbbsd/chat.c b/pttbbs/mbbsd/chat.c new file mode 100644 index 00000000..f75383a8 --- /dev/null +++ b/pttbbs/mbbsd/chat.c @@ -0,0 +1,623 @@ +/* $Id: chat.c,v 1.1 2002/03/07 15:13:48 in2 Exp $ */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "config.h" +#include "pttstruct.h" +#include "perm.h" +#include "common.h" +#include "modes.h" +#include "proto.h" + +extern userinfo_t *currutmp; +static int chatline; +static int stop_line; /* next line of bottom of message window area */ +static FILE *flog; + +static void printchatline(char *str) { + move(chatline, 0); + if(*str == '>' && !PERM_HIDE(currutmp)) + return; + else if(chatline < stop_line - 1) + chatline++; + else { + region_scroll_up(2, stop_line - 2); + move(stop_line - 2, 0); + } + outs(str); + outc('\n'); + outs("→"); + + if(flog) + fprintf(flog, "%s\n", str); +} + +extern int b_lines; /* Screen bottom line number: t_lines-1 */ + +static void chat_clear() { + for(chatline = 2; chatline < stop_line; chatline++) { + move(chatline, 0); + clrtoeol(); + } + move(b_lines, 0); + clrtoeol(); + move(chatline = 2, 0); + outs("→"); +} + +static void print_chatid(char *chatid) { + move(b_lines - 1, 0); + clrtoeol(); + outs(chatid); + outc(':'); +} + +static int chat_send(int fd, char *buf) { + int len; + char genbuf[200]; + + sprintf(genbuf, "%s\n", buf); + len = strlen(genbuf); + return (send(fd, genbuf, len, 0) == len); +} + +static char chatroom[IDLEN]; /* Chat-Room Name */ + +static int chat_recv(int fd, char *chatid) { + static char buf[512]; + static int bufstart = 0; + char genbuf[200]; + int c, len; + char *bptr; + + len = sizeof(buf) - bufstart - 1; + if((c = recv(fd, buf + bufstart, len, 0)) <= 0) + return -1; + c += bufstart; + + bptr = buf; + while(c > 0) { + len = strlen(bptr) + 1; + if(len > c && len < (sizeof buf / 2)) + break; + + if(*bptr == '/') { + switch(bptr[1]) { + case 'c': + chat_clear(); + break; + case 'n': + strncpy(chatid, bptr + 2, 8); + print_chatid(chatid); + clrtoeol(); + break; + case 'r': + strncpy(chatroom, bptr + 2, IDLEN - 1); + break; + case 't': + move(0, 0); + clrtoeol(); + sprintf(genbuf, "談天室 [%s]", chatroom); + prints("\033[1;37;46m %-21s \033[45m 話題:%-48s\033[m", + genbuf, bptr + 2); + } + } else + printchatline(bptr); + + c -= len; + bptr += len; + } + + if(c > 0) { + strcpy(genbuf, bptr); + strcpy(buf, genbuf); + bufstart = len - 1; + } else + bufstart = 0; + return 0; +} + +extern userec_t cuser; + +static int printuserent(userinfo_t *uentp) { + static char uline[80]; + static int cnt; + char pline[30]; + + if(!uentp) { + if(cnt) + printchatline(uline); + bzero(uline, 80); + cnt = 0; + return 0; + } + if(!HAS_PERM(PERM_SYSOP) && !HAS_PERM(PERM_SEECLOAK) && uentp->invisible) + return 0; + + sprintf(pline, "%-13s%c%-10s ", uentp->userid, + uentp->invisible ? '#' : ' ', + modestring(uentp, 1)); + if(cnt < 2) + strcat(pline, "│"); + strcat(uline, pline); + if(++cnt == 3) { + printchatline(uline); + memset(uline, 0, 80); + cnt = 0; + } + return 0; +} + +static void chathelp(char *cmd, char *desc) { + char buf[STRLEN]; + + sprintf(buf, " %-20s- %s", cmd, desc); + printchatline(buf); +} + +static void chat_help(char *arg) { + if(strstr(arg, " op")) { + printchatline("談天室管理員專用指令"); + chathelp("[/f]lag [+-][ls]", "設定鎖定、秘密狀態"); + chathelp("[/i]nvite ", "邀請 加入談天室"); + chathelp("[/k]ick ", "將 踢出談天室"); + chathelp("[/o]p ", "將 Op 的權力轉移給 "); + chathelp("[/t]opic ", "換個話題"); + chathelp("[/w]all", "廣播 (站長專用)"); + } else { + chathelp("[//]help", "MUD-like 社交動詞"); + chathelp("[/.]help", "chicken 鬥雞用指令"); + chathelp("[/h]elp op", "談天室管理員專用指令"); + chathelp("[/a]ct ", "做一個動作"); + chathelp("[/b]ye [msg]", "道別"); + chathelp("[/c]lear", "清除螢幕"); + chathelp("[/j]oin ", "建立或加入談天室"); + chathelp("[/l]ist [room]", "列出談天室使用者"); + chathelp("[/m]sg ", "跟 說悄悄話"); + chathelp("[/n]ick ", "將談天代號換成 "); + chathelp("[/p]ager", "切換呼叫器"); + chathelp("[/q]uery", "查詢網友"); + chathelp("[/r]oom", "列出一般談天室"); + chathelp("[/u]sers", "列出站上使用者"); + chathelp("[/w]ho", "列出本談天室使用者"); + chathelp("[/w]hoin ", "列出談天室 的使用者"); + } +} + +static void chat_date() { + time_t thetime; + char genbuf[200]; + + time(&thetime); + sprintf(genbuf, "◆ " BBSNAME "標準時間: %s", Cdate(&thetime)); + printchatline(genbuf); +} + +static void chat_pager() { + char genbuf[200]; + + char *msgs[] = {"關閉", "打開", "拔掉", "防水","好友"}; + sprintf(genbuf, "◆ 您的呼叫器:[%s]", + msgs[currutmp->pager = (currutmp->pager+1)%5]); + printchatline(genbuf); +} + +extern char *str_space; +extern userec_t xuser; +extern char *fn_plans; +extern char *err_uid; + +static void chat_query(char *arg) { + char *uid; + int tuid; + + printchatline(""); + strtok(arg, str_space); + if((uid = strtok(NULL, str_space)) && (tuid = getuser(uid))) { + char buf[128], *ptr; + FILE *fp; + + sprintf(buf, "%s(%s) 共上站 %d 次,發表過 %d 篇文章", + xuser.userid, xuser.username, xuser.numlogins, xuser.numposts); + printchatline(buf); + + sprintf(buf, "最近(%s)從[%s]上站", Cdate(&xuser.lastlogin), + (xuser.lasthost[0] ? xuser.lasthost : "(不詳)")); + printchatline(buf); + + sethomefile(buf, xuser.userid, fn_plans); + if((fp = fopen(buf, "r"))) { + tuid = 0; + while(tuid++ < MAX_QUERYLINES && fgets(buf, 128, fp)) { + if((ptr = strchr(buf, '\n'))) + ptr[0] = '\0'; + printchatline(buf); + } + fclose(fp); + } + } else + printchatline(err_uid); +} + +extern char *msg_shortulist; + +static void chat_users() { + printchatline(""); + printchatline("【 " BBSNAME "的遊客列表 】"); + printchatline(msg_shortulist); + + if(apply_ulist(printuserent) == -1) + printchatline("空無一人"); + printuserent(NULL); +} + +typedef struct chat_command_t { + char *cmdname; /* Chatroom command length */ + void (*cmdfunc) (); /* Pointer to function */ +} chat_command_t; + +static chat_command_t chat_cmdtbl[] = { + {"help", chat_help}, + {"clear", chat_clear}, + {"date", chat_date}, + {"pager", chat_pager}, + {"query", chat_query}, + {"users", chat_users}, + {NULL, NULL} +}; + +static int chat_cmd_match(char *buf, char *str) { + while(*str && *buf && !isspace(*buf)) + if(tolower(*buf++) != *str++) + return 0; + return 1; +} + +static int chat_cmd(char *buf, int fd) { + int i; + + if(*buf++ != '/') + return 0; + + for(i = 0; chat_cmdtbl[i].cmdname; i++) { + if(chat_cmd_match(buf, chat_cmdtbl[i].cmdname)) { + chat_cmdtbl[i].cmdfunc(buf); + return 1; + } + } + return 0; +} + +extern char trans_buffer[256]; /* 一般傳遞變數 add by Ptt */ + +#if 0 +static char *select_address() { + int c; + FILE *fp; + char nametab[25][90]; + char iptab[25][18], buf[80]; + + move(1, 0); + clrtobot(); + outs("\n \033[36m【找個地方抬抬槓吧!】\033[m " + "◎ 【以下為本站登記有案的茶樓】 \n"); + trans_buffer[0]=0; + if((fp = fopen("etc/teashop", "r"))) { + for(c = 0; fscanf(fp, "%s%s", iptab[c], nametab[c]) != EOF; c++) { + sprintf(buf,"\n (\033[36m%d\033[0m) %-30s [%s]", + c + 1, nametab[c], iptab[c]); + outs(buf); + } + getdata(20, 10, "★\033[32m 請選擇,[0]離開:\033[0m", buf, 3, + LCECHO); + if(buf[1]) + buf[0] = (buf[0] + 1) * 10 + (buf[1] - '1'); + else + buf[0] -= '1'; + if(buf[0] >= 0 && buf[0] < c) + strcpy(trans_buffer,iptab[(int)buf[0]]); + } else { + outs("本站沒有登記任何合格茶樓"); + pressanykey(); + } + return trans_buffer; +} +#endif + +extern int usernum; +extern int t_lines; +extern char *msg_seperator; +#define MAXLASTCMD 6 +static int chatid_len = 10; + +int t_chat() { + char inbuf[80], chatid[20], lastcmd[MAXLASTCMD][80], *ptr = ""; + struct sockaddr_in sin; + struct hostent *h; + int cfd, cmdpos, ch; + int currchar; + int newmail; + int chatting = YEA; + char fpath[80]; + char genbuf[200]; + char roomtype; + + if(inbuf[0] == 0) + return -1; + + outs(" 驅車前往 請梢候........ "); + if(!(h = gethostbyname("localhost"))) { + perror("gethostbyname"); + return -1; + } + memset(&sin, 0, sizeof sin); +#ifdef FreeBSD + sin.sin_len = sizeof(sin); +#endif + sin.sin_family = PF_INET; + memcpy(&sin.sin_addr, h->h_addr, h->h_length); + sin.sin_port = htons(NEW_CHATPORT); + cfd = socket(sin.sin_family, SOCK_STREAM, 0); + if(!(connect(cfd, (struct sockaddr *) & sin, sizeof sin))) + roomtype = 1; + else { + sin.sin_port = CHATPORT; + cfd = socket(sin.sin_family, SOCK_STREAM, 0); + if(!(connect(cfd, (struct sockaddr *) & sin, sizeof sin))) + roomtype = 2; + else { + outs("\n " + "哇! 沒人在那邊耶...要有那地方的人先去開門啦!..."); + system("bin/xchatd"); + pressanykey(); + return -1; + } + } + + while(1) { + getdata(b_lines - 1, 0, "請輸入聊天代號:", inbuf, 9, DOECHO); + sprintf(chatid, "%s", (inbuf[0] ? inbuf : cuser.userid)); + chatid[8] = '\0'; +/* + 舊格式: /! 使用者編號 使用者等級 UserID ChatID + 新格式: /! UserID ChatID Password +*/ + if(roomtype == 1) + sprintf(inbuf, "/! %s %s %s", + cuser.userid, chatid, cuser.passwd); + else + sprintf(inbuf, "/! %d %d %s %s", + usernum, cuser.userlevel, cuser.userid, chatid); + chat_send(cfd, inbuf); + if(recv(cfd, inbuf, 3, 0) != 3) + return 0; + if(!strcmp(inbuf, CHAT_LOGIN_OK)) + break; + else if(!strcmp(inbuf, CHAT_LOGIN_EXISTS)) + ptr = "這個代號已經有人用了"; + else if(!strcmp(inbuf, CHAT_LOGIN_INVALID)) + ptr = "這個代號是錯誤的"; + else if(!strcmp(inbuf, CHAT_LOGIN_BOGUS)) + ptr = "請勿派遣分身進入聊天室 !!"; + + move(b_lines - 2, 0); + outs(ptr); + clrtoeol(); + bell(); + } + + add_io(cfd, 0); + + newmail = currchar = 0; + cmdpos = -1; + memset(lastcmd, 0, MAXLASTCMD * 80); + + setutmpmode(CHATING); + currutmp->in_chat = YEA; + strcpy(currutmp->chatid, chatid); + + clear(); + chatline = 2; + strcpy(inbuf, chatid); + stop_line = t_lines - 3; + + move(stop_line, 0); + outs(msg_seperator); + move(1, 0); + outs(msg_seperator); + print_chatid(chatid); + memset(inbuf, 0, 80); + + sethomepath(fpath, cuser.userid); + strcpy(fpath, tempnam(fpath, "chat_")); + flog = fopen(fpath, "w"); + + while(chatting) { + move(b_lines - 1, currchar + chatid_len); + ch = igetkey(); + + switch(ch) { + case KEY_DOWN: + cmdpos += MAXLASTCMD - 2; + case KEY_UP: + cmdpos++; + cmdpos %= MAXLASTCMD; + strcpy(inbuf, lastcmd[cmdpos]); + move(b_lines - 1, chatid_len); + clrtoeol(); + outs(inbuf); + currchar = strlen(inbuf); + continue; + case KEY_LEFT: + if(currchar) + --currchar; + continue; + case KEY_RIGHT: + if(inbuf[currchar]) + ++currchar; + continue; + } + + if(!newmail && currutmp->mailalert ) { + newmail = 1; + printchatline("◆ 噹!郵差又來了..."); + } + + if(ch == I_OTHERDATA) { /* incoming */ + if(chat_recv(cfd, chatid) == -1) { + chatting = chat_send(cfd, "/b"); + break; + } + continue; + } + if(isprint2(ch)) { + if(currchar < 68) { + if(inbuf[currchar]) { /* insert */ + int i; + + for(i = currchar; inbuf[i] && i < 68; i++); + inbuf[i + 1 ] = '\0'; + for(; i > currchar; i--) + inbuf[i] = inbuf[i - 1]; + } else /* append */ + inbuf[currchar + 1] = '\0'; + inbuf[currchar] = ch; + move(b_lines - 1, currchar + chatid_len); + outs(&inbuf[currchar++]); + } + continue; + } + + if(ch == '\n' || ch == '\r') { + if(*inbuf) { + chatting = chat_cmd(inbuf, cfd); + if(chatting == 0) + chatting = chat_send(cfd, inbuf); + if(!strncmp(inbuf, "/b", 2)) + break; + + for(cmdpos = MAXLASTCMD - 1; cmdpos; cmdpos--) + strcpy(lastcmd[cmdpos], lastcmd[cmdpos - 1]); + strcpy(lastcmd[0], inbuf); + + inbuf[0] = '\0'; + currchar = 0; + cmdpos = -1; + } + print_chatid(chatid); + move(b_lines - 1, chatid_len); + continue; + } + + if(ch == Ctrl('H') || ch == '\177') { + if(currchar) { + currchar--; + inbuf[69] = '\0'; + memcpy(&inbuf[currchar], &inbuf[currchar + 1], 69 - currchar); + move(b_lines - 1, currchar + chatid_len); + clrtoeol(); + outs(&inbuf[currchar]); + } + continue; + } + if(ch == Ctrl('Z') || ch == Ctrl('Y')) { + inbuf[0] = '\0'; + currchar = 0; + print_chatid(chatid); + move(b_lines - 1, chatid_len); + continue; + } + + if(ch == Ctrl('C')) { + chat_send(cfd, "/b"); + break; + } + if(ch == Ctrl('D')) { + if(currchar < strlen(inbuf)) { + inbuf[69] = '\0'; + memcpy(&inbuf[currchar], &inbuf[currchar + 1], 69 - currchar); + move(b_lines - 1, currchar + chatid_len); + clrtoeol(); + outs(&inbuf[currchar]); + } + continue; + } + if(ch == Ctrl('K')) { + inbuf[currchar] = 0; + move(b_lines - 1, currchar + chatid_len); + clrtoeol(); + continue; + } + if(ch == Ctrl('A')) { + currchar = 0; + continue; + } + if(ch == Ctrl('E')) { + currchar = strlen(inbuf); + continue; + } + if(ch == Ctrl('I')) { + extern screenline_t *big_picture; + screenline_t *screen0 = calloc(t_lines, sizeof(screenline_t)); + + memcpy(screen0, big_picture, t_lines * sizeof(screenline_t)); + add_io(0, 0); + t_idle(); + memcpy(big_picture, screen0, t_lines * sizeof(screenline_t)); + free(screen0); + redoscr(); + add_io(cfd, 0); + continue; + } + if(ch == Ctrl('Q')) { + print_chatid(chatid); + move(b_lines - 1, chatid_len); + outs(inbuf); + continue; + } + } + + close(cfd); + add_io(0, 0); + currutmp->in_chat = currutmp->chatid[0] = 0; + + if(flog) { + char ans[4]; + + fclose(flog); + more(fpath, NA); + getdata(b_lines - 1, 0, "清除(C) 移至備忘錄(M) (C/M)?[C]", + ans, 4, LCECHO); + if (*ans == 'm') { + fileheader_t mymail; + char title[128]; + + sethomepath(genbuf, cuser.userid); + stampfile(genbuf, &mymail); + mymail.savemode = 'H'; /* hold-mail flag */ + mymail.filemode = FILE_READ; + strcpy(mymail.owner, "[備.忘.錄]"); + strcpy(mymail.title, "會議\033[1;33m記錄\033[m"); + sethomedir(title, cuser.userid); + append_record(title, &mymail, sizeof(mymail)); + Rename(fpath, genbuf); + } else + unlink(fpath); + } + + return 0; +} +/* -------------------------------------------------- */ +#if 0 + +extern char page_requestor[]; +extern userinfo_t *currutmp; + +#endif diff --git a/pttbbs/mbbsd/chc_draw.c b/pttbbs/mbbsd/chc_draw.c new file mode 100644 index 00000000..b3bd216f --- /dev/null +++ b/pttbbs/mbbsd/chc_draw.c @@ -0,0 +1,187 @@ +/* $Id: chc_draw.c,v 1.1 2002/03/07 15:13:48 in2 Exp $ */ +#include +#include +#include "config.h" +#include "pttstruct.h" +#include "common.h" +#include "proto.h" + +#define SIDE_ROW 10 +#define TURN_ROW 11 +#define STEP_ROW 12 +#define TIME_ROW 13 +#define WARN_ROW 15 +#define MYWIN_ROW 17 +#define HISWIN_ROW 18 + +extern char chc_warnmsg[64], *chc_mateid; +extern rc_t chc_from, chc_to, chc_select; +extern int chc_selected, chc_my, chc_turn, chc_firststep; +extern int chc_lefttime; +extern int chc_hiswin, chc_hislose, chc_histie; + +static char *turn_str[2] = {"黑的", "紅的"}; + +static char *num_str[10] = { + "", "一", "二", "三", "四", "五", "六", "七", "八", "九" +}; + +static char *chess_str[2][8] = { + /* 0 1 2 3 4 5 6 7 */ + {" ", "將", "士", "象", "車", "馬", "包", "卒"}, + {" ", "帥", "仕", "相", "車", "傌", "炮", "兵"} +}; + +static char *chess_brd[BRD_ROW * 2 - 1] = { + /*0 1 2 3 4 5 6 7 8*/ + "┌─┬─┬─┬─┬─┬─┬─┬─┐", /* 0 */ + "│ │ │ │\│/│ │ │ │", + "├─┼─┼─┼─┼─┼─┼─┼─┤", /* 1 */ + "│ │ │ │/│\│ │ │ │", + "├─┼─┼─┼─┼─┼─┼─┼─┤", /* 2 */ + "│ │ │ │ │ │ │ │ │", + "├─┼─┼─┼─┼─┼─┼─┼─┤", /* 3 */ + "│ │ │ │ │ │ │ │ │", + "├─┴─┴─┴─┴─┴─┴─┴─┤", /* 4 */ + "│ 楚 河 漢 界 │", + "├─┬─┬─┬─┬─┬─┬─┬─┤", /* 5 */ + "│ │ │ │ │ │ │ │ │", + "├─┼─┼─┼─┼─┼─┼─┼─┤", /* 6 */ + "│ │ │ │ │ │ │ │ │", + "├─┼─┼─┼─┼─┼─┼─┼─┤", /* 7 */ + "│ │ │ │\│/│ │ │ │", + "├─┼─┼─┼─┼─┼─┼─┼─┤", /* 8 */ + "│ │ │ │/│\│ │ │ │", + "└─┴─┴─┴─┴─┴─┴─┴─┘" /* 9 */ +}; + +static char *hint_str[] = { + " q 認輸離開", + " p 要求和棋", + "方向鍵 移動遊標", + "Enter 選擇/移動" +}; + +void chc_movecur(int r, int c) { + move(r * 2 + 3, c * 4 + 4); +} + +#define BLACK_COLOR "\033[1;36m" +#define RED_COLOR "\033[1;31m" +#define BLACK_REVERSE "\033[1;37;46m" +#define RED_REVERSE "\033[1;37;41m" +#define TURN_COLOR "\033[1;33m" + +static void showstep(board_t board) { + int turn, fc, tc, eatten; + char *dir; + + turn = CHE_O(board[chc_from.r][chc_from.c]); + fc = (turn == (chc_my ^ 1) ? chc_from.c + 1 : 9 - chc_from.c); + tc = (turn == (chc_my ^ 1) ? chc_to.c + 1 : 9 - chc_to.c); + if(chc_from.r == chc_to.r) + dir = "平"; + else { + if(chc_from.c == chc_to.c) + tc = chc_from.r - chc_to.r; + if(tc < 0) tc = -tc; + + if((turn == (chc_my ^ 1) && chc_to.r > chc_from.r) || + (turn == chc_my && chc_to.r < chc_from.r)) + dir = "進"; + else + dir = "退"; + } + prints("%s%s%s%s%s", + turn == 0 ? BLACK_COLOR : RED_COLOR, + chess_str[turn][CHE_P(board[chc_from.r][chc_from.c])], + num_str[fc], dir, num_str[tc]); + eatten = board[chc_to.r][chc_to.c]; + if(eatten) + prints(": %s%s", + CHE_O(eatten) == 0 ? BLACK_COLOR : RED_COLOR, + chess_str[CHE_O(eatten)][CHE_P(eatten)]); + prints("\033[m"); +} + +extern userec_t cuser; + +void chc_drawline(board_t board, int line) { + int i, j; + + move(line, 0); + clrtoeol(); + if(line == 0) { + prints("\033[1;46m 象棋對戰 \033[45m%30s VS %-30s\033[m", + cuser.userid, chc_mateid); + } else if(line >= 3 && line <= 21) { + outs(" "); + for(i = 0; i < 9; i++) { + j = board[RTL(line)][i]; + if((line & 1) == 1 && j) { + if(chc_selected && + chc_select.r == RTL(line) && chc_select.c == i) + prints("%s%s\033[m", + CHE_O(j) == 0 ? BLACK_REVERSE : RED_REVERSE, + chess_str[CHE_O(j)][CHE_P(j)]); + else + prints("%s%s\033[m", + CHE_O(j) == 0 ? BLACK_COLOR : RED_COLOR, + chess_str[CHE_O(j)][CHE_P(j)]); + } else + prints("%c%c", chess_brd[line - 3][i * 4], + chess_brd[line - 3][i * 4 + 1]); + if(i != 8) + prints("%c%c", chess_brd[line - 3][i * 4 + 2], + chess_brd[line - 3][i * 4 + 3]); + } + outs(" "); + + if(line >= 3 && line < 3 + dim(hint_str)) { + outs(hint_str[line - 3]); + } else if(line == SIDE_ROW) { + prints("\033[1m你是%s%s\033[m", + chc_my == 0 ? BLACK_COLOR : RED_COLOR, + turn_str[chc_my]); + } else if(line == TURN_ROW) { + prints("%s%s\033[m", + TURN_COLOR, + chc_my == chc_turn ? "輪到你下棋了" : "等待對方下棋"); + } else if(line == STEP_ROW && !chc_firststep) { + showstep(board); + } else if(line == TIME_ROW) { + prints("剩餘時間 %d:%02d", chc_lefttime / 60, chc_lefttime % 60); + } else if(line == WARN_ROW) { + outs(chc_warnmsg); + } else if(line == MYWIN_ROW) { + prints("\033[1;33m%12.12s " + "\033[1;31m%2d\033[37m勝 " + "\033[34m%2d\033[37m敗 " + "\033[36m%2d\033[37m和\033[m", + cuser.userid, + cuser.chc_win, cuser.chc_lose - 1, cuser.chc_tie); + } else if(line == HISWIN_ROW) { + prints("\033[1;33m%12.12s " + "\033[1;31m%2d\033[37m勝 " + "\033[34m%2d\033[37m敗 " + "\033[36m%2d\033[37m和\033[m", + chc_mateid, + chc_hiswin, chc_hislose - 1, chc_histie); + } + } else if(line == 2 || line == 22) { + outs(" "); + if(line == 2) + for(i = 1; i <= 9; i++) + prints("%s ", num_str[i]); + else + for(i = 9; i >= 1; i--) + prints("%s ", num_str[i]); + } +} + +void chc_redraw(board_t board) { + int i; + + for(i = 0; i <= 22; i++) + chc_drawline(board, i); +} diff --git a/pttbbs/mbbsd/chc_net.c b/pttbbs/mbbsd/chc_net.c new file mode 100644 index 00000000..d094d5f2 --- /dev/null +++ b/pttbbs/mbbsd/chc_net.c @@ -0,0 +1,28 @@ +/* $Id: chc_net.c,v 1.1 2002/03/07 15:13:48 in2 Exp $ */ +#include +#include +#include +#include "config.h" +#include "pttstruct.h" + +extern rc_t chc_from, chc_to; + +typedef struct drc_t { + rc_t from, to; +} drc_t; + +int chc_recvmove(int s) { + drc_t buf; + + if(read(s, &buf, sizeof(buf)) != sizeof(buf)) + return 1; + chc_from = buf.from, chc_to = buf.to; + return 0; +} + +void chc_sendmove(int s) { + drc_t buf; + + buf.from = chc_from, buf.to = chc_to; + write(s, &buf, sizeof(buf)); +} diff --git a/pttbbs/mbbsd/chc_play.c b/pttbbs/mbbsd/chc_play.c new file mode 100644 index 00000000..86c17fbc --- /dev/null +++ b/pttbbs/mbbsd/chc_play.c @@ -0,0 +1,277 @@ +/* $Id: chc_play.c,v 1.1 2002/03/07 15:13:48 in2 Exp $ */ +#include +#include +#include +#include +#include +#include "config.h" +#include "pttstruct.h" +#include "common.h" +#include "modes.h" +#include "proto.h" + +extern userinfo_t *currutmp; +extern int usernum; + +typedef int (*play_func_t)(int, board_t, board_t); + +static int chc_ipass = 0, chc_hepass = 0; +int chc_lefttime; +int chc_my, chc_turn, chc_selected, chc_firststep; +char chc_warnmsg[64], *chc_mateid; +rc_t chc_from, chc_to, chc_select, chc_cursor; +int chc_hiswin, chc_hislose, chc_histie; + +#define CHC_TIMEOUT 300 +#define SIDE_ROW 10 +#define TURN_ROW 11 +#define STEP_ROW 12 +#define TIME_ROW 13 +#define WARN_ROW 15 +#define MYWIN_ROW 17 +#define HISWIN_ROW 18 + +static int hisplay(int s, board_t board, board_t tmpbrd) { + int start_time; + int endgame = 0, endturn = 0; + + start_time = time(NULL); + while(!endturn) { + chc_lefttime = CHC_TIMEOUT - (time(NULL) - start_time); + if(chc_lefttime < 0) { + chc_lefttime = 0; + + /* to make him break out igetkey() */ + chc_from.r = -2; + chc_sendmove(s); + } + chc_drawline(board, TIME_ROW); + move(1, 0); + oflush(); + switch(igetkey()) { + case 'q': + endgame = 2; + endturn = 1; + break; + case 'p': + if(chc_hepass) { + chc_from.r = -1; + chc_sendmove(s); + endgame = 3; + endturn = 1; + } + break; + case I_OTHERDATA: + if(chc_recvmove(s)) { /* disconnect */ + endturn = 1; + endgame = 1; + } else { + if(chc_from.r == -1) { + chc_hepass = 1; + strcpy(chc_warnmsg, "\033[1;33m要求和局!\033[m"); + chc_drawline(board, WARN_ROW); + } else { + chc_from.r = 9 - chc_from.r, chc_from.c = 8 - chc_from.c; + chc_to.r = 9 - chc_to.r, chc_to.c = 8 - chc_to.c; + chc_cursor = chc_to; + if(CHE_P(board[chc_to.r][chc_to.c]) == 1) + endgame = 2; + endturn = 1; + chc_hepass = 0; + chc_drawline(board, STEP_ROW); + chc_movechess(board); + chc_drawline(board, LTR(chc_from.r)); + chc_drawline(board, LTR(chc_to.r)); + } + } + break; + } + } + return endgame; +} + +static int myplay(int s, board_t board, board_t tmpbrd) { + int ch, start_time; + int endgame = 0, endturn = 0; + + chc_ipass = 0, chc_selected = 0; + start_time = time(NULL); + chc_lefttime = CHC_TIMEOUT - (time(NULL) - start_time); + bell(); + while(!endturn) { + chc_drawline(board, TIME_ROW); + chc_movecur(chc_cursor.r, chc_cursor.c); + oflush(); + ch = igetkey(); + chc_lefttime = CHC_TIMEOUT - (time(NULL) - start_time); + if(chc_lefttime < 0) + ch = 'q'; + switch(ch) { + case I_OTHERDATA: + if(chc_recvmove(s)) { /* disconnect */ + endgame = 1; + endturn = 1; + } else if(chc_from.r == -1 && chc_ipass) { + endgame = 3; + endturn = 1; + } + break; + case KEY_UP: + chc_cursor.r--; + if(chc_cursor.r < 0) + chc_cursor.r = BRD_ROW - 1; + break; + case KEY_DOWN: + chc_cursor.r++; + if(chc_cursor.r >= BRD_ROW) + chc_cursor.r = 0; + break; + case KEY_LEFT: + chc_cursor.c--; + if(chc_cursor.c < 0) + chc_cursor.c = BRD_COL - 1; + break; + case KEY_RIGHT: + chc_cursor.c++; + if(chc_cursor.c >= BRD_COL) + chc_cursor.c = 0; + break; + case 'q': + endgame = 2; + endturn = 1; + break; + case 'p': + chc_ipass = 1; + chc_from.r = -1; + chc_sendmove(s); + strcpy(chc_warnmsg, "\033[1;33m要求和棋!\033[m"); + chc_drawline(board, WARN_ROW); + bell(); + break; + case '\r': + case '\n': + case ' ': + if(chc_selected) { + if(chc_cursor.r == chc_select.r && + chc_cursor.c == chc_select.c) { + chc_selected = 0; + chc_drawline(board, LTR(chc_cursor.r)); + } else if(chc_canmove(board, chc_select, chc_cursor)) { + if(CHE_P(board[chc_cursor.r][chc_cursor.c]) == 1) + endgame = 1; + chc_from = chc_select; + chc_to = chc_cursor; + if(!endgame) { + memcpy(tmpbrd, board, sizeof(board_t)); + chc_movechess(tmpbrd); + } + if(endgame || !chc_iskfk(tmpbrd)) { + chc_drawline(board, STEP_ROW); + chc_movechess(board); + chc_sendmove(s); + chc_selected = 0; + chc_drawline(board, LTR(chc_from.r)); + chc_drawline(board, LTR(chc_to.r)); + endturn = 1; + } else { + strcpy(chc_warnmsg, "\033[1;33m不可以王見王\033[m"); + bell(); + chc_drawline(board, WARN_ROW); + } + } + } else if(board[chc_cursor.r][chc_cursor.c] && + CHE_O(board[chc_cursor.r][chc_cursor.c]) == chc_turn) { + chc_selected = 1; + chc_select = chc_cursor; + chc_drawline(board, LTR(chc_cursor.r)); + } + break; + } + } + return endgame; +} + +extern userec_t cuser; + +static void mainloop(int s, board_t board) { + int endgame; + board_t tmpbrd; + play_func_t play_func[2]; + + play_func[chc_my] = myplay; + play_func[chc_my ^ 1] = hisplay; + for(chc_turn = 1, endgame = 0; !endgame; chc_turn ^= 1) { + chc_firststep = 0; + chc_drawline(board, TURN_ROW); + if(chc_ischeck(board, chc_turn)) { + strcpy(chc_warnmsg, "\033[1;31m將軍!\033[m"); + bell(); + } else + chc_warnmsg[0] = 0; + chc_drawline(board, WARN_ROW); + endgame = play_func[chc_turn](s, board, tmpbrd); + } + + if(endgame == 1) { + strcpy(chc_warnmsg, "對方認輸了!"); + cuser.chc_win++; + } else if(endgame == 2) { + strcpy(chc_warnmsg, "你認輸了!"); + cuser.chc_lose++; + } else { + strcpy(chc_warnmsg, "和棋"); + cuser.chc_tie++; + } + cuser.chc_lose--; + passwd_update(usernum, &cuser); + chc_drawline(board, WARN_ROW); + bell(); + oflush(); +} + +extern userec_t xuser; + +static void chc_init(int s, board_t board) { + userinfo_t *my = currutmp; + + setutmpmode(CHC); + clear(); + chc_warnmsg[0] = 0; + chc_my = my->turn; + chc_mateid = my->mateid; + chc_firststep = 1; + chc_init_board(board); + chc_redraw(board); + chc_cursor.r = 9, chc_cursor.c = 0; + add_io(s, 0); + + if(my->turn) chc_recvmove(s); + passwd_query(usernum, &xuser); + cuser.chc_win = xuser.chc_win; + cuser.chc_lose = xuser.chc_lose + 1; + cuser.chc_tie = xuser.chc_tie; + cuser.money = xuser.money; + passwd_update(usernum, &cuser); + + getuser(chc_mateid); + chc_hiswin = xuser.chc_win; + chc_hislose = xuser.chc_lose; + chc_histie = xuser.chc_tie; + + if(!my->turn) { + chc_sendmove(s); + chc_hislose++; + } + + chc_redraw(board); +} + +void chc(int s) { + board_t board; + + chc_init(s, board); + mainloop(s, board); + close(s); + add_io(0, 0); + if(chc_my) pressanykey(); +} diff --git a/pttbbs/mbbsd/chc_rule.c b/pttbbs/mbbsd/chc_rule.c new file mode 100644 index 00000000..35d8fe6a --- /dev/null +++ b/pttbbs/mbbsd/chc_rule.c @@ -0,0 +1,186 @@ +/* $Id: chc_rule.c,v 1.1 2002/03/07 15:13:48 in2 Exp $ */ +#include +#include +#include +#include "config.h" +#include "pttstruct.h" +#include "common.h" +#include "proto.h" + +extern rc_t chc_from, chc_to; +extern int chc_my; + +#define CENTER(a, b) (((a) + (b)) >> 1) + +void chc_init_board(board_t board) { + memset(board, 0, sizeof(board_t)); + board[0][4] = CHE(1, chc_my ^ 1); /* 將 */ + board[0][3] = board[0][5] = CHE(2, chc_my ^ 1); /* 士 */ + board[0][2] = board[0][6] = CHE(3, chc_my ^ 1); /* 象 */ + board[0][0] = board[0][8] = CHE(4, chc_my ^ 1); /* 車 */ + board[0][1] = board[0][7] = CHE(5, chc_my ^ 1); /* 馬 */ + board[2][1] = board[2][7] = CHE(6, chc_my ^ 1); /* 包 */ + board[3][0] = board[3][2] = board[3][4] = + board[3][6] = board[3][8] = CHE(7, chc_my ^ 1); /* 卒 */ + + board[9][4] = CHE(1, chc_my); /* 帥 */ + board[9][3] = board[9][5] = CHE(2, chc_my); /* 仕 */ + board[9][2] = board[9][6] = CHE(3, chc_my); /* 相 */ + board[9][0] = board[9][8] = CHE(4, chc_my); /* 車 */ + board[9][1] = board[9][7] = CHE(5, chc_my); /* 傌 */ + board[7][1] = board[7][7] = CHE(6, chc_my); /* 炮 */ + board[6][0] = board[6][2] = board[6][4] = + board[6][6] = board[6][8] = CHE(7, chc_my); /* 兵 */ +} + +void chc_movechess(board_t board) { + board[chc_to.r][chc_to.c] = board[chc_from.r][chc_from.c]; + board[chc_from.r][chc_from.c] = 0; +} + +static int dist(rc_t from, rc_t to, int rowcol) { + int d; + + d = rowcol ? from.c - to.c : from.r - to.r; + return d > 0 ? d : -d; +} + +static int between(board_t board, rc_t from, rc_t to, int rowcol) { + int i, rtv = 0; + + if(rowcol) { + if(from.c > to.c) + i = from.c, from.c = to.c, to.c = i; + for(i = from.c + 1; i < to.c; i++) + if(board[to.r][i]) rtv++; + } else { + if(from.r > to.r) + i = from.r, from.r = to.r, to.r = i; + for(i = from.r + 1; i < to.r; i++) + if(board[i][to.c]) rtv++; + } + return rtv; +} + +int chc_canmove(board_t board, rc_t from, rc_t to) { + int i; + int rd, cd, turn; + + rd = dist(from, to, 0); + cd = dist(from, to, 1); + turn = CHE_O(board[from.r][from.c]); + + /* general check */ + if(board[to.r][to.c] && CHE_O(board[to.r][to.c]) == turn) + return 0; + + /* individual check */ + switch(CHE_P(board[from.r][from.c])) { + case 1: /* 將 帥 */ + if(!(rd == 1 && cd == 0) && + !(rd == 0 && cd == 1)) + return 0; + if((turn == (chc_my ^ 1) && to.r > 2) || + (turn == chc_my && to.r < 7) || + to.c < 3 || to.c > 5) + return 0; + break; + case 2: /* 士 仕 */ + if(!(rd == 1 && cd == 1)) + return 0; + if((turn == (chc_my ^ 1) && to.r > 2) || + (turn == chc_my && to.r < 7) || + to.c < 3 || to.c > 5) + return 0; + break; + case 3: /* 象 相 */ + if(!(rd == 2 && cd == 2)) + return 0; + if((turn == (chc_my ^ 1) && to.r > 4) || + (turn == chc_my && to.r < 5)) + return 0; + /* 拐象腿 */ + if(board[CENTER(from.r, to.r)][CENTER(from.c, to.c)]) + return 0; + break; + case 4: /* 車 */ + if(!(rd > 0 && cd == 0) && + !(rd == 0 && cd > 0)) + return 0; + if(between(board, from, to, rd == 0)) + return 0; + break; + case 5: /* 馬 傌 */ + if(!(rd == 2 && cd == 1) && + !(rd == 1 && cd == 2)) + return 0; + /* 拐馬腳 */ + if(rd == 2) { + if(board[CENTER(from.r, to.r)][from.c]) + return 0; + } else { + if(board[from.r][CENTER(from.c, to.c)]) + return 0; + } + break; + case 6: /* 包 炮 */ + if(!(rd > 0 && cd == 0) && + !(rd == 0 && cd > 0)) + return 0; + i = between(board, from, to, rd == 0); + if((i > 1) || + (i == 1 && !board[to.r][to.c]) || + (i == 0 && board[to.r][to.c])) + return 0; + break; + case 7: /* 卒 兵 */ + if(!(rd == 1 && cd == 0) && + !(rd == 0 && cd == 1)) + return 0; + if(((turn == (chc_my ^ 1) && to.r < 5) || + (turn == chc_my && to.r > 4)) && + cd != 0) + return 0; + if((turn == (chc_my ^ 1) && to.r < from.r) || + (turn == chc_my && to.r > from.r)) + return 0; + break; + } + return 1; +} + +static void findking(board_t board, int turn, rc_t *buf) { + int i, r, c; + + r = (turn == (chc_my ^ 1)) ? 0 : 7; + for(i = 0; i < 3; r++, i++) + for(c = 3; c < 6; c++) + if(CHE_P(board[r][c]) == 1 && + CHE_O(board[r][c]) == turn) { + buf->r = r, buf->c = c; + return ; + } +} + +int chc_iskfk(board_t board) { + rc_t from, to; + + findking(board, 0, &to); + findking(board, 1, &from); + if(from.c == to.c && between(board, from, to, 0) == 0) + return 1; + return 0; +} + +int chc_ischeck(board_t board, int turn) { + rc_t from, to; + + findking(board, turn, &to); + for(from.r = 0;from.r < BRD_ROW; from.r++) + for(from.c = 0; from.c < BRD_COL; from.c++) + if(board[from.r][from.c] && + CHE_O(board[from.r][from.c]) != turn) + if(chc_canmove(board, from, to)) + return 1; + return 0; +} diff --git a/pttbbs/mbbsd/chicken.c b/pttbbs/mbbsd/chicken.c new file mode 100644 index 00000000..f789925f --- /dev/null +++ b/pttbbs/mbbsd/chicken.c @@ -0,0 +1,989 @@ +/* $Id: chicken.c,v 1.1 2002/03/07 15:13:48 in2 Exp $ */ +#include +#include +#include +#include +#include +#include +#include +#include "config.h" +#include "pttstruct.h" +#include "common.h" +#include "modes.h" +#include "proto.h" + +#define NUM_KINDS 13 /* 有多少種動物 */ + +static const char *cage[17] = { + "誕生", "週歲", "幼年", "少年", "青春", "青年", + "青年", "活力", "壯年", "壯年", "壯年", "中年", + "中年", "老年", "老年", "老摳摳", "古希"}; +static const char *chicken_type[NUM_KINDS] = { + "小雞", "美少女", "勇士", "蜘蛛", + "恐龍", "老鷹", "貓", "蠟筆小新", + "狗狗", "惡魔", "忍者", "ㄚ扁", + "馬英九"}; +static const char *chicken_food[NUM_KINDS] = { + "雞飼料", "營養厚片", "雞排便當", "死蝴蝶", + "屍體", "小雞", "貓餅乾", "小熊餅乾", + "寶錄", "靈氣", "飯團", "便當", + "雞腿"}; +static const int egg_price[NUM_KINDS] = { + 5, 25, 30, 40, + 80, 50, 15, 35, + 17, 100, 85, 200, + 200}; +static const int food_price[NUM_KINDS] = { + 4, 6, 8, 10, + 12, 12, 5, 6, + 5, 20, 15, 23, + 23}; +static const char *attack_type[NUM_KINDS] = { + "啄", "鞭打", "槌", "咬", + "撞擊", "啄", "抓", "踢", + "咬","燃燒","暗擊","棍打", + "劍擊"}; + +static const char *damage_degree[] = { + "蚊子似的", "騷癢似的", "小力的", "輕微的", + "有點疼的", "使力的", "傷人的", "重重的", + "使全力的", "惡狠狠的", "危險的", "瘋狂的", + "猛烈的", "狂風暴雨似的", "驚天動地的", + "致命的", NULL}; + +enum { + OO, FOOD, WEIGHT, CLEAN, RUN, ATTACK, BOOK, HAPPY, SATIS, + TEMPERAMENT, TIREDSTRONG, SICK, HP_MAX, MM_MAX +}; + +extern userec_t cuser; + +static chicken_t *mychicken = &cuser.mychicken; +static int age; + +static const int time_change[NUM_KINDS][14] = +/* 補品 食物 體重 乾淨 敏捷 攻擊力 知識 快樂 滿意 氣質 疲勞 病氣 滿血 滿法*/ +{ +/*雞*/ + { 1, 1, 30, 3, 8, 3, 3, 40, 9, 1, 7, 3, 30, 1}, +/*美少女*/ + { 1, 1, 110, 1, 4, 7, 41, 20, 9, 25, 25, 7, 110, 15}, +/*勇士*/ + { 1, 1, 200, 5, 4, 10, 33, 20, 15, 10, 27, 1, 200, 9}, +/*蜘蛛*/ + { 1, 1, 10, 5, 8, 1, 1, 5, 3, 1, 4, 1, 10, 30}, +/*恐龍*/ + { 1, 1,1000, 9, 1, 13, 4, 12, 3, 1, 200, 1, 1000, 3}, +/*老鷹*/ + { 1, 1, 90, 7, 10, 7, 4, 12, 3, 30, 20, 5, 90, 20}, +/*貓*/ + { 1, 1, 30, 5, 5, 6, 4, 8, 3, 15, 7, 4, 30, 21}, +/*蠟筆小新*/ + { 1, 1, 100, 9, 7, 7, 20, 50, 10, 8, 24, 4, 100, 9}, +/*狗*/ + { 1, 1, 45, 8, 7, 9, 3, 40, 20, 3, 9, 5, 45, 1}, +/* 惡魔 */ + { 1, 1, 45, 10, 11, 11, 5, 21, 11, 1, 9, 5, 45, 25}, +/* 忍者 */ + { 1, 1, 45, 2, 12, 10, 25, 1, 1, 10, 9, 5, 45, 26}, +/* 阿扁 */ + { 1, 1, 150, 4, 8, 13, 95, 25, 7, 10, 25, 5, 175, 85}, +/* 馬英九 */ + { 1, 1, 147, 2, 10, 10, 85, 20, 4, 25, 25, 5, 145, 95} +}; + +extern userec_t xuser; +extern int usernum; + +int reload_chicken() { + passwd_query(usernum, &xuser); + memcpy(mychicken, &xuser.mychicken, sizeof(chicken_t)); + if(!mychicken->name[0]) + return 0; + else return 1; +} + +#define CHICKENLOG "etc/chicken" + +static int new_chicken() { + char buf[150]; + int price; + time_t now; + + clear(); + move(2,0); + outs("歡迎觀臨 \033[33m◎\033[37;44m Ptt寵物市場 \033[33;40m◎\033[m.. " + "目前蛋價:\n" + "(a)小雞 $5 (b)美少女 $25 (c)勇士 $30 (d)蜘蛛 $40 " + "(e)恐龍 $80\n" + "(f)老鷹 $50 (g)貓 $15 (h)蠟筆小新$35 (i)狗狗 $17 " + "(j)惡魔 $100\n" + "(k)忍者 $85 (l)阿扁 $200 (m)馬英九 $200\n" + "[0]自己 $0\n"); + getdata_str(6, 0, "請選擇你要養的動物:", buf, 3, LCECHO, "0"); + + buf[0] -= 'a'; + if(buf[0]<0 || buf[0]>NUM_KINDS-1) + return 0; + + mychicken->type = buf[0]; + + reload_money(); + price = egg_price[(int)mychicken->type]; + if(cuser.money < price) { + prints("\n 錢不夠買蛋蛋,蛋蛋要 %d 元", price); + refresh(); + return 0; + } + vice(price,"寵物蛋"); + while(strlen(mychicken->name)<3) + getdata(8, 0, "幫牠取個好名字:", mychicken->name, 18, DOECHO); + + now = time(NULL); + sprintf(buf,"\033[31m%s \033[m養了一隻叫\033[33m %s \033[m的 " + "\033[32m%s\033[m 於 %s",cuser.userid, + mychicken->name,chicken_type[(int)mychicken->type],ctime(&now)); + log_file(CHICKENLOG,buf); + mychicken->lastvisit = mychicken->birthday = mychicken->cbirth = now; + mychicken->food = 0; + mychicken->weight = time_change[(int)mychicken->type][WEIGHT]/3; + mychicken->clean = 0; + mychicken->run = time_change[(int)mychicken->type][RUN]; + mychicken->attack = time_change[(int)mychicken->type][ATTACK]; + mychicken->book = time_change[(int)mychicken->type][BOOK]; + mychicken->happy = time_change[(int)mychicken->type][HAPPY]; + mychicken->satis = time_change[(int)mychicken->type][SATIS]; + mychicken->temperament = time_change[(int)mychicken->type][TEMPERAMENT]; + mychicken->tiredstrong = 0; + mychicken->sick = 0; + mychicken->hp = time_change[(int)mychicken->type][WEIGHT]; + mychicken->hp_max = time_change[(int)mychicken->type][WEIGHT]; + mychicken->mm = 0; + mychicken->mm_max = 0; + return 1; +} + +int show_file(char *filename, int y, int lines, int mode) { + FILE *fp; + char buf[256]; + + if(y >= 0) + move(y,0); + clrtoline(lines + y); + if((fp=fopen(filename,"r"))) { + while(fgets(buf,256,fp) && lines--) + outs(Ptt_prints(buf,mode)); + fclose(fp); + } else + return 0; + return 1; +} + +static void show_chicken_stat(chicken_t *thechicken) { + struct tm *ptime; + + ptime = localtime(&thechicken->birthday); + prints(" Name :\033[33m%s\033[m (\033[32m%s\033[m)%*s生日 " + ":\033[31m%02d\033[m年\033[31m%2d\033[m月\033[31m%2d\033[m日 " + "(\033[32m%s %d歲\033[m)\n" + " 體:\033[33m%5d/%-5d\033[m 法:\033[33m%5d/%-5d\033[m 攻擊力:" + "\033[33m%-7d\033[m 敏捷 :\033[33m%-7d\033[m 知識 :\033[33m%-7d" + "\033[m \n" + " 快樂 :\033[33m%-7d\033[m 滿意 :\033[33m%-7d\033[m 疲勞 :" + "\033[33m%-7d\033[m 氣質 :\033[33m%-7d \033[m體重 :" + "\033[33m%-5.2f\033[m \n" + " 病氣 :\033[33m%-7d\033[m 乾淨 :\033[33m%-7d\033[m 食物 :" + "\033[33m%-7d\033[m 大補丸:\033[33m%-7d\033[m 藥品 :\033[33m%-7d" + "\033[m \n", + thechicken->name, chicken_type[(int)thechicken->type], + 15 - strlen(thechicken->name), "", + ptime->tm_year % 100, ptime->tm_mon + 1, ptime->tm_mday, + cage[age > 16 ? 16 : age], age, thechicken->hp, thechicken->hp_max, + thechicken->mm, thechicken->mm_max, + thechicken->attack, thechicken->run, thechicken->book, + thechicken->happy, thechicken->satis, thechicken->tiredstrong, + thechicken->temperament, + ((float)(thechicken->hp_max+(thechicken->weight/50))) / 100, + thechicken->sick, thechicken->clean, thechicken->food, + thechicken->oo, thechicken->medicine); +} + +#define CHICKEN_PIC "etc/chickens" +extern char *BBSName; + +void show_chicken_data(chicken_t *thechicken, chicken_t *pkchicken) { + char buf[1024]; + age = ((time(NULL) - thechicken->cbirth)/ (60*60*24)); + if(age < 0) { + thechicken->birthday = thechicken->cbirth = time(NULL)-10*(60*60*24); + age = 10; + } + /*Ptt:debug*/ + thechicken->type %= NUM_KINDS; + clear(); + showtitle(pkchicken ? "Ptt鬥雞場" : "Ptt養雞場", BBSName); + move(1,0); + + show_chicken_stat(thechicken); + + sprintf(buf, CHICKEN_PIC "/%c%d", thechicken->type + 'a', + age > 16 ? 16 : age); + show_file(buf, 5, 14, NO_RELOAD); + + move(18,0); + + if(thechicken->sick) + outs("生病了..."); + if(thechicken->sick > thechicken->hp / 5) + outs("\033[5;31m擔心...病重!!\033[m"); + + if(thechicken->clean > 150) + outs("\033[31m又臭又髒的..\033[m"); + else if(thechicken->clean > 80) + outs("有點髒.."); + else if(thechicken->clean < 20) + outs("\033[32m很乾淨..\033[m"); + + if(thechicken->weight > thechicken->hp_max*4) + outs("\033[31m快飽死了!.\033[m"); + else if(thechicken->weight > thechicken->hp_max*3) + outs("\033[32m飽嘟嘟..\033[m"); + else if(thechicken->weight < (thechicken->hp_max / 4)) + outs("\033[31m快餓死了!..\033[m"); + else if(thechicken->weight < (thechicken->hp_max / 2)) + outs("餓了.."); + + if(thechicken->tiredstrong > thechicken->hp * 1.7) + outs("\033[31m累得昏迷了...\033[m"); + else if(thechicken->tiredstrong > thechicken->hp) + outs("累了.."); + else if(thechicken->tiredstrong < thechicken->hp / 4) + outs("\033[32m精力旺盛...\033[m"); + + if(thechicken->hp < thechicken->hp_max / 4) + outs("\033[31m體力用盡..奄奄一息..\033[m"); + if(thechicken->happy > 500) + outs("\033[32m很快樂..\033[m"); + else if(thechicken->happy < 100) + outs("不快樂.."); + if(thechicken->satis > 500) + outs("\033[32m很滿足..\033[m"); + else if(thechicken->satis < 50) + outs("不滿足.."); + + if(pkchicken) { + outs("\n"); + show_chicken_stat(pkchicken); + outs("[任意鍵] 攻擊對方 [q] 落跑 [o] 吃大補丸"); + } +} + +static void ch_eat() { + if(mychicken->food) { + mychicken->weight += time_change[(int)mychicken->type][WEIGHT] + + mychicken->hp_max/5 ; + mychicken->tiredstrong += + time_change[(int)mychicken->type][TIREDSTRONG] / 2; + mychicken->hp_max++; + mychicken->happy += 5; + mychicken->satis += 7; + mychicken->food--; + move(10, 10); + + show_file(CHICKEN_PIC "/eat", 5, 14, NO_RELOAD); + pressanykey(); + } +} + +static void ch_clean() { + mychicken->clean = 0; + mychicken->tiredstrong += + time_change[(int)mychicken->type][TIREDSTRONG] / 3; + show_file(CHICKEN_PIC "/clean", 5, 14, NO_RELOAD); + pressanykey(); +} + +static void ch_guess() { + char *guess[3] = {"剪刀", "石頭", "布"}, me, ch, win; + + mychicken->happy += time_change[(int)mychicken->type][HAPPY]*1.5; + mychicken->satis += time_change[(int)mychicken->type][SATIS]; + mychicken->tiredstrong += time_change[(int)mychicken->type][TIREDSTRONG]; + mychicken->attack += time_change[(int)mychicken->type][ATTACK]/4; + move(20,0); + clrtobot(); + outs("你要出[\033[32m1\033[m]\033[33m剪刀\033[m(\033[32m2\033[m)" + "\033[33m石頭\033[m(\033[32m3\033[m)\033[33m布\033[m:\n"); + me = igetch(); + me -= '1'; + if(me > 2 || me < 0) + me = 0; + win = (int)(3.0 * rand()/(RAND_MAX + 1.0)) - 1; + ch = (me + win + 3)%3; + prints("%s:%s ! %s:%s !.....%s", + cuser.userid, guess[(int)me], mychicken->name, guess[(int)ch], + win==0 ? "平手" : win < 0 ? "耶..贏了 :D!!" : "嗚..我輸了 :~"); + pressanykey(); +} + +static void ch_book() { + mychicken->book += time_change[(int)mychicken->type][BOOK]; + mychicken->tiredstrong += time_change[(int)mychicken->type][TIREDSTRONG]; + show_file(CHICKEN_PIC "/read", 5, 14, NO_RELOAD); + pressanykey(); +} + +static void ch_kiss() { + mychicken->happy += time_change[(int)mychicken->type][HAPPY]; + mychicken->satis += time_change[(int)mychicken->type][SATIS]; + mychicken->tiredstrong += + time_change[(int)mychicken->type][TIREDSTRONG] / 2; + show_file(CHICKEN_PIC "/kiss", 5, 14, NO_RELOAD); + pressanykey(); +} + +static void ch_hit() { + mychicken->attack += time_change[(int)mychicken->type][ATTACK]; + mychicken->run += time_change[(int)mychicken->type][RUN]; + mychicken->mm_max += time_change[(int)mychicken->type][MM_MAX]/15; + mychicken->weight -= mychicken->hp_max / 15 ; + mychicken->hp -= (int)((float)time_change[(int)mychicken->type][HP_MAX] * + rand()/(RAND_MAX+1.0)) / 2 + 1; + + if(mychicken->book > 2) + mychicken->book -= 2; + if(mychicken->happy > 2) + mychicken->happy -= 2; + if(mychicken->satis > 2) + mychicken->satis -= 2; + mychicken->tiredstrong += time_change[(int)mychicken->type][TIREDSTRONG]; + show_file(CHICKEN_PIC "/hit", 5, 14, NO_RELOAD); + pressanykey(); +} + +extern int b_lines; /* Screen bottom line number: t_lines-1 */ + +void ch_buyitem(int money, char *picture, int *item) { + int num = 0; + char buf[5]; + + getdata_str(b_lines - 1, 0, "要買多少份呢:", buf, 4, DOECHO, "1"); + num = atoi(buf); + if(num < 1) + return; + reload_money(); + if(cuser.money > money*num) { + *item += num; + vice(money*num,"購買寵物,賭盤項目"); + show_file(picture, 5, 14, NO_RELOAD); + } else { + move(b_lines-1,0); + clrtoeol(); + outs("現金不夠 !!!"); + } + pressanykey(); +} + +static void ch_eatoo() { + if(mychicken->oo > 0) { + mychicken->oo--; + mychicken->tiredstrong = 0; + if(mychicken->happy > 5) + mychicken->happy -= 5; + show_file(CHICKEN_PIC "/oo", 5, 14, NO_RELOAD); + pressanykey(); + } +} + +static void ch_eatmedicine() { + if(mychicken->medicine > 0) { + mychicken->medicine--; + mychicken->sick = 0; + if(mychicken->hp_max > 10) + mychicken->hp_max -= 3; + mychicken->hp = mychicken->hp_max; + if(mychicken->happy>10) + mychicken->happy -= 10; + show_file(CHICKEN_PIC "/medicine", 5, 14, NO_RELOAD); + pressanykey(); + } +} + +static void ch_kill() { + char buf[150],ans[4]; + + sprintf(buf, "棄養這%s要被罰 100 元, 是否要棄養?(y/N)", + chicken_type[(int)mychicken->type]); + getdata_str(23, 0, buf, ans, 3, DOECHO, "N"); + if(ans[0] == 'y') { + time_t now = time(NULL); + + vice(100,"棄養寵物費"); + more(CHICKEN_PIC "/deadth",YEA); + sprintf(buf, "\033[31m%s \033[m把 \033[33m%s\033[m\033[32m %s " + "\033[m宰了 於 %s", cuser.userid, + mychicken->name, chicken_type[(int)mychicken->type], ctime(&now)); + log_file(CHICKENLOG, buf); + mychicken->name[0]=0; + } +} + +static int ch_sell() { +/* + int money = (mychicken->weight - time_change[(int)mychicken->type][WEIGHT]) + *(food_price[(int)mychicken->type])/4 + + ( + + ((mychicken->clean / time_change[(int)mychicken->type][CLEAN]) + + (mychicken->run / time_change[(int)mychicken->type][RUN]) + + (mychicken->attack / time_change[(int)mychicken->type][ATTACK]) + + (mychicken->book / time_change[(int)mychicken->type][BOOK]) + + (mychicken->happy / time_change[(int)mychicken->type][HAPPY]) + + (mychicken->satis / time_change[(int)mychicken->type][SATIS]) + + (mychicken->temperament / time_change[(int)mychicken->type][TEMPERAMENT]) + - (mychicken->tiredstrong / time_change[(int)mychicken->type][TIREDSTRONG]) + - (mychicken->sick / time_change[(int)mychicken->type][SICK]) + + (mychicken->hp / time_change[(int)mychicken->type][HP_MAX]) + + (mychicken->mm / time_change[(int)mychicken->type][MM_MAX]) + + 7 - abs(age - 7)) * 3 + ; +*/ + int money = (age * food_price[(int)mychicken->type] * 3 + + (mychicken->hp_max * 10 + mychicken->weight) / + time_change[(int)mychicken->type][HP_MAX]) * 3 / 2 - + mychicken->sick; + char buf[150],ans[4]; + time_t now = time(NULL); + + if(money < 0) + money =0 ; + else if(money > MAX_CHICKEN_MONEY) + money = MAX_CHICKEN_MONEY; //防止怪雞 + if(mychicken->type == 1 || mychicken->type == 7) { + outs("\n\033[31m ㄜ..親愛的..販賣人口是會犯法的唷..\033[m"); + pressanykey(); + return 0; + } + if(age < 5) { + outs("\n 還未成年不能賣"); + pressanykey(); + return 0; + } + if(age > 30) { + outs("\n\033[31m 這..太老沒人要了\033[m"); + pressanykey(); + return 0; + } + + sprintf(buf, "這隻%d歲%s可以賣 %d 元, 是否要賣?(y/N)", age, + chicken_type[(int)mychicken->type], money); + getdata_str(23, 0, buf, ans, 3, DOECHO, "N"); + if(ans[0]=='y') { + sprintf(buf, "\033[31m%s\033[m 把 \033[33m%s\033[m " + "\033[32m%s\033[m 用 \033[36m%d\033[m 賣了 於 %s", + cuser.userid, mychicken->name, + chicken_type[(int)mychicken->type],money,ctime(&now)); + log_file(CHICKENLOG, buf); + mychicken->lastvisit = mychicken->name[0]=0; + passwd_update(usernum, &cuser); + more(CHICKEN_PIC "/sell",YEA); + demoney(money); + return 1; + } + return 0; +} + +static void geting_old(int *hp, int *weight, int diff, int age) { + float ex = 0.9; + + if(age > 70) + ex = 0.1; + else if(age > 30) + ex = 0.5; + else if(age > 20) + ex = 0.7; + + diff /= 60*6; + while(diff--) { + *hp *= ex; + *weight *= ex; + } +} + +/* 依時間變動的資料 */ +void time_diff(chicken_t *thechicken) { + int diff; + int theage = ((time(NULL) - thechicken->cbirth)/ (60 * 60 * 24)); + + thechicken->type %= NUM_KINDS ; + diff = (time(NULL)-thechicken->lastvisit)/60; + + if((diff) < 1) + return; + + if(theage > 13 ) /* 老死 */ + geting_old(&thechicken->hp_max, &thechicken->weight, diff, age); + + thechicken->lastvisit = time(NULL); + thechicken->weight -= thechicken->hp_max * diff / 540; /* 體重 */ + if(thechicken->weight < 1) { + thechicken->sick -= thechicken->weight / 10; /* 餓得病氣上升 */ + thechicken->weight =1; + } + + /* 清潔度 */ + thechicken->clean += diff * time_change[(int)thechicken->type][CLEAN] / 30; + + /* 快樂度 */ + thechicken->happy -= diff / 60; + if(thechicken->happy < 0) + thechicken->happy=0; + thechicken->attack -= + time_change[(int)thechicken->type][ATTACK] * diff / (60 * 32); + if(thechicken->attack < 0) + thechicken->attack = 0; + /* 攻擊力 */ + thechicken->run -= time_change[(int)thechicken->type][RUN] * diff / (60 * 32); + /* 敏捷 */ + if(thechicken->run < 0) + thechicken->run = 0; + thechicken->book -= time_change[(int)thechicken->type][BOOK]*diff/ (60*32); + /* 知識 */ + if(thechicken->book < 0) + thechicken->book = 0; + /* 氣質 */ + thechicken->temperament++; + + thechicken->satis -= diff / 60 / 3 * time_change[(int)thechicken->type][SATIS]; + /* 滿意度 */ + if(thechicken->satis < 0) + thechicken->satis = 0; + + /* 髒病的 */ + if(mychicken->clean > 1000) + mychicken->sick += (mychicken->clean - 400) / 10; + + if(thechicken->weight > 1) + thechicken->sick -= diff / 60; + /* 病氣恢護 */ + if(thechicken->sick < 0) + thechicken->sick = 0; + thechicken->tiredstrong -= diff * + time_change[(int)thechicken->type][TIREDSTRONG] / 4; + /* 疲勞 */ + if(thechicken->tiredstrong < 0) + thechicken->tiredstrong = 0; + /* hp_max */ + if(thechicken->hp >= thechicken->hp_max/2) + thechicken->hp_max += + time_change[(int)thechicken->type][HP_MAX]*diff/ (60*12); + /* hp恢護 */ + if(!thechicken->sick) + thechicken->hp += + time_change[(int)thechicken->type][HP_MAX]*diff/ (60*6); + if(thechicken->hp>thechicken->hp_max) + thechicken->hp = thechicken->hp_max; + /* mm_max */ + if(thechicken->mm >= thechicken->mm_max/2) + thechicken->mm_max += + time_change[(int)thechicken->type][MM_MAX]*diff/ (60*8); + /* mm恢護 */ + if(!thechicken->sick) + thechicken->mm += diff; + if(thechicken->mm>thechicken->mm_max) + thechicken->mm = thechicken->mm_max; +} + +static void check_sick() { + /* 髒病的 */ + if(mychicken->tiredstrong > mychicken->hp * 0.3 && mychicken->clean > 150) + mychicken->sick += (mychicken->clean - 150) / 10; + /* 累病的 */ + if(mychicken->tiredstrong > mychicken->hp*1.3) + mychicken->sick += time_change[(int)mychicken->type][SICK]; + /* 病氣太重還做事減hp */ + if(mychicken->sick > mychicken->hp / 5) { + mychicken->hp -= (mychicken->sick - mychicken->hp / 5)/4; + if(mychicken->hp < 0 ) + mychicken->hp = 0; + } +} + +static int deadtype(chicken_t *thechicken) { + int i; + char buf[150]; + time_t now = time(NULL); + + if(thechicken->hp <= 0) /* hp用盡 */ + i = 1; + else if(thechicken->tiredstrong > thechicken->hp * 3 ) /* 操勞過度 */ + i = 2; + else if(thechicken->weight > thechicken->hp_max*5) /* 肥胖過度 */ + i = 3; + else if(thechicken->weight == 1 && + thechicken->sick > thechicken->hp_max / 4) + i = 4; /* 餓死了 */ + else if(thechicken->satis <= 0) /* 很不滿意 */ + i = 5; + else + return 0; + + if(thechicken == mychicken) { + sprintf(buf,"\033[31m%s\033[m 所疼愛的\033[33m %s\033[32m %s " + "\033[m掛了 於 %s", + cuser.userid, thechicken->name, + chicken_type[(int)thechicken->type], + ctime(&now)); + log_file(CHICKENLOG, buf); + mychicken->name[0] = 0; + passwd_update(usernum, &cuser); + } + return i; +} + +int showdeadth(int type) { + switch(type) { + case 1: + more(CHICKEN_PIC "/nohp",YEA); + break; + case 2: + more(CHICKEN_PIC "/tootired",YEA); + break; + case 3: + more(CHICKEN_PIC "/toofat",YEA); + break; + case 4: + more(CHICKEN_PIC "/nofood",YEA); + break; + case 5: + more(CHICKEN_PIC "/nosatis", YEA); + break; + default: + return 0; + } + more(CHICKEN_PIC "/deadth",YEA); + return type; +} + +int isdeadth(chicken_t *thechicken) { + int i; + + if(!(i = deadtype(thechicken))) + return 0; + return showdeadth(i); +} + +static void ch_changename() { + char buf[150], newname[20] = ""; + time_t now = time(NULL); + + getdata_str(b_lines - 1, 0, "嗯..改個好名字吧:", newname, 18, DOECHO, + mychicken->name); + + if(strlen(newname) >= 3 && strcmp(newname,mychicken->name)) { + sprintf(buf, "\033[31m%s\033[m 把疼愛的\033[33m %s\033[32m %s " + "\033[m改名為\033[33m %s\033[m 於 %s", + cuser.userid, mychicken->name, + chicken_type[(int)mychicken->type], + newname, ctime(&now)); + strcpy(mychicken->name, newname); + log_file(CHICKENLOG,buf); + } +} + +static int select_menu() { + char ch; + + reload_money(); + move(19,0); + prints("\033[44;37m 錢 :\033[33m %-10d " + " \033[m\n" + "\033[33m(\033[37m1\033[33m)清理 (\033[37m2\033[33m)吃飯 " + "(\033[37m3\033[33m)猜拳 (\033[37m4\033[33m)唸書 " + "(\033[37m5\033[33m)親他 (\033[37m6\033[33m)打他 " + "(\033[37m7\033[33m)買%s$%d (\033[37m8\033[33m)吃補丸\n" + "(\033[37m9\033[33m)吃病藥 (\033[37mo\033[33m)買大補丸$100 " + "(\033[37mm\033[33m)買藥$10 (\033[37mk\033[33m)棄養 " + "(\033[37ms\033[33m)賣掉 (\033[37mn\033[33m)改名 " + "(\033[37mq\033[33m)離開:\033[m", + cuser.money, + /*chicken_food[(int)mychicken->type], + chicken_type[(int)mychicken->type], + chicken_type[(int)mychicken->type],*/ + chicken_food[(int)mychicken->type], + food_price[(int)mychicken->type]); + do { + switch(ch = igetch()) { + case '1': + ch_clean(); + check_sick(); + break; + case '2': + ch_eat(); + check_sick(); + break; + case '3': + ch_guess(); + check_sick(); + break; + case '4': + ch_book(); + check_sick(); + break; + case '5': + ch_kiss(); + break; + case '6': + ch_hit(); + check_sick(); + break; + case '7': + ch_buyitem(food_price[(int)mychicken->type], CHICKEN_PIC "/food", + &mychicken->food); + break; + case '8': + ch_eatoo(); + break; + case '9': + ch_eatmedicine(); + break; + case 'O': + case 'o': + ch_buyitem(100, CHICKEN_PIC "/buyoo", &mychicken->oo); + break; + case 'M': + case 'm': + ch_buyitem(10, CHICKEN_PIC "/buymedicine", &mychicken->medicine); + break; + case 'N': + case 'n': + ch_changename(); + break; + case 'K': + case 'k': + ch_kill(); + return 0; + case 'S': + case 's': + if(!ch_sell()) break; + case 'Q': + case 'q': + return 0; + } + } while(ch < ' ' || ch>'z'); + return 1; +} + +static int recover_chicken(chicken_t *thechicken) { + char buf[200]; + int price = egg_price[(int)thechicken->type], + money = price + (rand() % price); + + if(time(NULL) - thechicken->lastvisit > (60 * 60 * 24 * 7)) + return 0; + outmsg("\033[33;44m★靈界守衛\033[37;45m 別害怕 我是來幫你的 \033[m"); + bell(); + igetch(); + outmsg("\033[33;44m★靈界守衛\033[37;45m 你無法丟到我水球 因為我是聖靈, " + "最近缺錢想賺外快 \033[m"); + bell(); + igetch(); + sprintf(buf, "\033[33;44m★靈界守衛\033[37;45m " + "你有一個剛走不久的%s要招換回來嗎? 只要%d元唷 \033[m", + chicken_type[(int)thechicken->type], price*2); + outmsg(buf); + bell(); + getdata_str(21, 0, " 選擇:(N:坑人嘛/y:請幫幫我)", buf, 3, LCECHO, "N"); + if(buf[0] == 'y' || buf[0] == 'Y') { + reload_money(); + if(cuser.money < price*2) { + outmsg("\033[33;44m★靈界守衛\033[37;45m 什麼 錢沒帶夠 " + "沒錢的小鬼 快去籌錢吧 \033[m"); + bell(); + igetch(); + return 0; + } + strcpy(thechicken->name, "[撿回來的]"); + thechicken->hp = thechicken->hp_max; + thechicken->sick = 0; + thechicken->satis = 2; + vice(money,"靈界守衛"); + sprintf(buf, "\033[33;44m★靈界守衛\033[37;45m OK了 記得餵他點東西 " + "不然可能失效 念在我也有玩Ptt 拿你%d就好 \033[m", money); + outmsg(buf); + bell(); + igetch(); + return 1; + } + outmsg("\033[33;44m★靈界守衛\033[37;45m 竟然說我坑人! 這年頭命真不值錢 " + "除非我再來找你 你再也沒機會了 \033[m"); + bell(); + igetch(); + thechicken->lastvisit = 0; + passwd_update(usernum, &cuser); + return 0; +} + +#define lockreturn0(unmode, state) if(lockutmpmode(unmode, state)) return 0 + +int chicken_main() { + lockreturn0(CHICKEN, LOCK_MULTI); + + reload_chicken(); + age = ((time(NULL) - mychicken->cbirth)/ (60*60*24)); + if(!mychicken->name[0] && !recover_chicken(mychicken) && !new_chicken()) { + unlockutmpmode(); + return 0; + } + + do { + time_diff(mychicken); + if(isdeadth(mychicken)) + break; + show_chicken_data(mychicken, NULL); + } while(select_menu()); + reload_money(); + passwd_update(usernum, &cuser); + unlockutmpmode(); + return 0; +} + +extern userinfo_t *currutmp; +extern struct utmpfile_t *utmpshm; + +int chickenpk(int fd) { + char mateid[IDLEN + 1], data[200], buf[200]; + int ch = 0; + + userinfo_t *uin = &utmpshm->uinfo[currutmp->destuip]; + userec_t ouser; + chicken_t *ochicken = &ouser.mychicken; + int r, attmax, i, datac, duid = currutmp->destuid, catched=0, count=0; + + lockreturn0(CHICKEN, LOCK_MULTI); + + strcpy(mateid, currutmp->mateid); /*把對手的id用local buffer記住*/ + + getuser(mateid) ; + memcpy(&ouser, &xuser, sizeof(userec_t)); + reload_chicken(); + if(!ochicken->name[0] || !mychicken->name[0]) { + outmsg("有一方沒有寵物"); /* Ptt:妨止page時把寵物賣掉 */ + bell(); + refresh(); + add_io(0, 0); + close(fd); + unlockutmpmode(); + sleep(1); + return 0; + } + + show_chicken_data(ochicken, mychicken); + add_io(fd, 3); /* 把fd加到igetch監視 */ + while(1) { + r = rand(); + ch = igetkey(); + getuser(mateid) ; + memcpy(&ouser, &xuser, sizeof(userec_t)); + reload_chicken(); + show_chicken_data(ochicken, mychicken); + time_diff(mychicken); + + i = mychicken->attack* mychicken->hp / mychicken->hp_max; + for(attmax=2; (i = i*9/10); attmax++); + + if(ch == I_OTHERDATA) { + count =0; + datac = recv(fd, data, sizeof(data), 0); + if(datac <= 1) + break; + move(17,0); + outs(data+1); + switch(data[0]) { + case 'c': + catched=1; + move(16,0); + outs("要放他走嗎?(y/N)"); + break; + case 'd': + move(16,0); + outs("阿~倒下了!!"); + break; + } + if(data[0] == 'd' || data[0]=='q' || data[0]=='l') + break; + continue; + } else if(currutmp->turn) { + count = 0; + currutmp->turn = 0; + uin->turn = 1; + mychicken->tiredstrong ++; + switch(ch) { + case 'y': + if(catched == 1) { + sprintf(data, "l讓 %s 落跑了\n", + ochicken->name); + } + break; + case 'n': + catched =0; + default: + case 'k': + r = r % (attmax + 2); + if(r) { + sprintf(data, "M%s %s%s %s 傷了 %d 點\n", mychicken->name, + damage_degree[r/3>15 ? 15:r/3], + attack_type[(int)mychicken->type], + ochicken->name, r); + ochicken->hp-=r; + } else + sprintf(data, "M%s 覺得手軟出擊無效\n", mychicken->name); + break; + case 'o': + if(mychicken->oo > 0) { + mychicken->oo--; + mychicken->hp += 300; + if(mychicken->hp > mychicken->hp_max) + mychicken->hp = mychicken->hp_max; + mychicken->tiredstrong = 0; + sprintf(data, "M%s 吃了顆大補丸補充體力\n", + mychicken->name); + } else + sprintf(data, "M%s 想吃大補丸, 可是沒有大補丸可吃\n", + mychicken->name); + break; + case 'q': + if(r % (mychicken->run+1) > r % (ochicken->run+1)) + sprintf(data, "q%s 落跑了\n", + mychicken->name); + else + sprintf(data, "c%s 想落跑, 但被 %s 抓到了\n", + mychicken->name, ochicken->name); + break; + } + if(deadtype(ochicken)) { + strtok(data,"\n"); + strcpy(buf, data); + sprintf(data, "d%s , %s 被 %s 打死了\n", + buf + 1, ochicken->name, mychicken->name); + } + move(17,0); + outs(data+1); + i = strlen(data) +1; + passwd_update(duid, &ouser); + passwd_update(usernum, &cuser); + send(fd, data, i, 0); + if(data[0]=='q' || data[0]=='d') + break; + } else { + move(17, 0); + if(count++ > 30) + break; + } + } + add_io(0, 0); /* 把igetch恢護回 */ + pressanykey(); + close(fd); + if(!showdeadth(deadtype(mychicken))); + unlockutmpmode(); + return 0; +} diff --git a/pttbbs/mbbsd/dark.c b/pttbbs/mbbsd/dark.c new file mode 100644 index 00000000..52741617 --- /dev/null +++ b/pttbbs/mbbsd/dark.c @@ -0,0 +1,456 @@ +/* $Id: dark.c,v 1.1 2002/03/07 15:13:48 in2 Exp $ */ +#include +#include +#include +#include +#include +#include +#include +#include "config.h" +#include "pttstruct.h" +#include "common.h" +#include "proto.h" + +#define RED 1 +#define BLACK 0 +typedef short int sint; + +typedef struct item { + short int color,value,die,out; +} item; + +typedef struct cur{ + short int y,x,end; +} cur; + +static item brd[4][8]; +static cur curr; /* 6 個 bytes */ +extern userinfo_t *currutmp; + +static char *rname[]={"兵","炮","傌","車","相","仕","帥"}; +static char *bname[]={"卒","包","馬","車","象","士","將"}; + +static sint cury[]={3,5,7,9}, curx[]={5,9,13,17,21,25,29,33}; +static sint rcount,bcount,cont,fix; /* cont:是否可連吃 */ +static sint my=0,mx=0,mly=-1,mlx=-1; /* 移動的座標 跟 選子的座標 */ + +static sint cur_eaty,cur_eatx; /* 吃掉對方其子的秀出座標 */ +static void brdswap(sint y,sint x,sint ly,sint lx) { + memcpy(&brd[y][x],&brd[ly][lx],sizeof(item)); + brd[ly][lx].die=1; + brd[ly][lx].color=-1; /* 沒這個color */ + brd[ly][lx].value=-1; +} + +static void pprints(sint y,sint x,char* s) { + move(y,x); + clrtoeol(); + prints("%s",s); +} + +static sint Is_win(item att, item det, sint y, sint x, sint ly, sint lx) { + sint i,c=0,min,max; + if(att.value == 1) /* 砲 */ + { + if(y!=ly && x!=lx) return 0; + if((abs(ly-y)==1 && brd[y][x].die==0)|| + (abs(lx-x)==1 && brd[y][x].die==0)) + return 0; + if(y==ly){ + if(x>lx) {max=x;min=lx;} + else {max=lx;min=x;} + for(i=min+1;ily) {max=y;min=ly;} + else {max=ly;min=y;} + for(i=min+1;i= det.value) return 1; + else return 0; + } + return 0; +} + +static sint Is_move(sint y,sint x, sint ly, sint lx) { + if(brd[y][x].die==1 && ((abs(ly-y)==1&&x==lx) || (abs(lx-x)==1&&ly==y))) + return 1; + return 0; +} + +static void brd_rand() { + sint y,x,index; + sint tem[32]; + sint value[32]={0,0,0,0,0,1,1,2,2,3,3,4,4,5,5,6, + 0,0,0,0,0,1,1,2,2,3,3,4,4,5,5,6}; + + bzero(brd, sizeof(brd)); + bzero(tem, sizeof(tem)); + bzero(&curr, sizeof(curr)); + srand(getpid()%2731+time(NULL)%3219); + for(y=0;y<4;y++) + for(x=0;x<8;x++) + while(1) { + index=rand()%32; + if(tem[index]) continue; + brd[y][x].color=(index>15)?0:1; + brd[y][x].value=value[index]; + tem[index]=1; + break; + } +} + +static void brd_prints() { + clear(); + move(1,0); + outs(" + ╭─┬─┬─┬─┬─┬─┬─┬─╮ + │●│●│●│●│●│●│●│●│ + ├─┼─┼─┼─┼─┼─┼─┼─┤ + │●│●│●│●│●│●│●│●│ + ├─┼─┼─┼─┼─┼─┼─┼─┤ + │●│●│●│●│●│●│●│●│ + ├─┼─┼─┼─┼─┼─┼─┼─┤ + │●│●│●│●│●│●│●│●│ + ╰─┴─┴─┴─┴─┴─┴─┴─╯ + "); +} + +static void draw_line(sint y, sint f) { + sint i; + char buf[1024],tmp[256]; + + *buf = 0; + *tmp = 0; + strcpy(buf,"\033[43;30m"); + for(i=0; i<8; i++) + { + if(brd[y][i].die==1) + sprintf(tmp,"│ "); + else if(brd[y][i].out==0) + sprintf(tmp,"│●"); + else { + sprintf(tmp, "│\033[%s1;%dm%s\033[m\033[43;30m", + (f==i)?"1;47;":"",(brd[y][i].color)?31:34, + (brd[y][i].color)?rname[brd[y][i].value]: + bname[brd[y][i].value]); + } + strcat(buf,tmp); + } + strcat(buf,"│\033[m"); + + move(cury[y],3); + clrtoeol(); + prints("%s",buf); +} + +static void redraw() { + sint i=0; + for(;i<4;i++) + draw_line(i,-1); +} + +static sint playing(sint fd, sint color,sint ch,sint *b, userinfo_t *uin) { + curr.end = 0; + move(cury[my],curx[mx]); + + if(fix) { + if(ch=='s') { + fix=0; *b=0; return 0; + } else { + draw_line(mly,-1); + } + } + + switch(ch) { + case KEY_LEFT: + if(mx == 0) mx=7; + else mx--; + move(cury[my],curx[mx]); + *b=-1; + break; + case KEY_RIGHT: + if(mx==7) mx=0; + else mx++; + move(cury[my],curx[mx]); + *b=-1; + break; + case KEY_UP: + if(my==0) my=3; + else my--; + move(cury[my],curx[mx]); + *b=-1; + break; + case KEY_DOWN: + if(my==3) my=0; + else my++; + move(cury[my],curx[mx]); + *b=-1; + break; + case 'q':case 'Q': + if(!color) bcount=0; + else rcount=0; + *b=0; + return -2; + case 'p':case 'P': + return -3; + case 'c': + return -4; + case 'g': + return -5; + case 's': /* 翻開棋子 或是選擇棋子 */ + /* 選擇棋子 */ + if(brd[my][mx].out==1) + { + if(brd[my][mx].color != color) + { + *b=-1; + break; + } + if(mly<0) /*可以選擇*/ + { + mly=my;mlx=mx; + draw_line(my,mx); + *b=-1; + break; + } + else if(mly == my && mlx == mx) /*不選了*/ + { + mly=-1;mlx=-1; + draw_line(my,-1); + }else + { + draw_line(mly,-1); + mly=my;mlx=mx; + if(brd[mly][mlx].value == 1) fix=1; + draw_line(my,mx); + } + *b=-1; + break; + } + /* 翻開棋子 */ + if(mly >=0 ){ *b=-1; break;} /*本來就是翻開的*/ + /* 決定一開始的顏色 */ + if(currutmp->color=='.'){ + if(uin->color!='1' && uin->color!='0') + currutmp->color=(brd[my][mx].color)?'1':'0'; + else + currutmp->color=(uin->color=='0')?'1':'0';} + brd[my][mx].out=1; + draw_line(my,-1); + move(cury[my],curx[mx]); + *b=0; + break; + case 'u': + move(0,0);clrtoeol(); + prints("%s色%s cont=%d",(brd[my][mx].color == RED)?"紅":"黑",rname[brd[my][mx].value],cont); + *b=-1; + break; + case '\r': /* 吃 or 移動 ly跟lx必須大於0*/ + case '\n': + if( + mly >= 0 /* 要先選子 */ + && + brd[mly][mlx].color != brd[my][mx].color /* 同色不能移動也不能吃 */ + && + (Is_move(my,mx,mly,mlx) || Is_win(brd[mly][mlx],brd[my][mx],my,mx,mly,mlx)) + ) + { + if(fix && brd[my][mx].value<0) + { + *b=-1;return 0; + } + if(brd[my][mx].value>=0&&brd[my][mx].die==0) + { + if(!color) bcount--; + else rcount--; + move(cur_eaty,cur_eatx); + prints("%s",(color)?bname[brd[my][mx].value]:rname[brd[my][mx].value]); + if(cur_eatx>=26) + { cur_eatx=5;cur_eaty++; } + else + cur_eatx+=3; + } + brdswap(my,mx,mly,mlx); + draw_line(mly,-1); + draw_line( my,-1); + if(fix==1) *b=-1; + else { mly=-1;mlx=-1;*b=0; } + } + else *b=-1; + break; + default: + *b=-1; + } + + if(!rcount) + return -1; + else if(!bcount) + return -1; + if(*b == -1) return 0; + curr.y = my;curr.x = mx; curr.end=(!*b)?1:0; + send(fd,&curr,sizeof(curr),0); + send(fd,&brd,sizeof(brd),0); + return 0; +} + +int main_dark(int fd,userinfo_t *uin) { + sint end=0,ch=1,go_on,i=0,cont=0; + char buf[16]; + *buf=0;fix=0; + currutmp->color='.'; // '.' 表示還沒決定顏色 + rcount=16;bcount=16; // initialize + cur_eaty=18,cur_eatx=5; + brd_prints(); + if(currutmp->turn) + { + brd_rand(); + send(fd,&brd,sizeof(brd),0); + pprints(21,0," ◆你是先手"); + pprints(22,0," ◆輪到你下了"); + }else + { + recv(fd,&brd,sizeof(brd),0); + pprints(21,0," ◆你是後手"); + } + move(12,3); + prints("%s[0勝0敗]vs.%s[0勝0敗]",currutmp->userid,currutmp->mateid); + outs(" + ╳╱功\能表╲╳╲╱╳╲ + ╱ ↑←↓→: 移動 + ╳ s:  選子,翻子 + ╱ enter:  吃棋,放棋 + 已經解決的:   ╳ p:  合棋 +    ╱ q:  認輸 + ╳ c:  換邊"); + + if(currutmp->turn) move(cury[0],curx[0]); + + add_io(fd, 0); + while(end<=0) + { + if(uin->turn=='w' || currutmp->turn=='w') { end=-1; break; } + + ch = igetkey(); + if(ch == I_OTHERDATA) + { + ch=recv(fd,&curr,sizeof(curr),0); + if(ch!=sizeof(curr)) + { + if(uin->turn=='e') { end=-3;break; } + else if(uin->turn!='w') { end=-1; currutmp->turn='w'; break; } + end=-1; break; + } + + if(curr.end==-3) pprints(23,30,"\033[33m要求合棋\033[m"); + else if(curr.end==-4) pprints(23,30,"\033[33m要求換邊\033[m"); + else if(curr.end==-5) pprints(23,30,"\033[33m要求連吃\033[m"); + else pprints(23,30,""); + + recv(fd,&brd,sizeof(brd),0); + my=curr.y;mx=curr.x; + redraw(); + if(curr.end) + pprints(22,0," ◆輪到你下了"); + move(cury[my],curx[mx]); + }else + { + if(currutmp->turn=='p') + { + if(ch=='y') { end=-3; currutmp->turn='e'; break; } + else { pprints(23,30,""); *buf=0; currutmp->turn=(uin->turn)?0:1; } + }else if(currutmp->turn=='c') + { + if(ch=='y') { currutmp->color=(currutmp->color=='1')?'0':'1'; + uin->color=(uin->color=='1')?'0':'1'; + pprints(21,0,(currutmp->color=='1')?" \033[1;33m◆你持紅色棋\033[m":" \033[1;33m◆你持黑色棋\033[m"); + } + else { pprints(23,30,""); currutmp->turn=(uin->turn)?0:1; } + }else if(currutmp->turn=='g') + { + if(ch=='y') { + cont=1; + pprints(21,0," \033[1;33m◆你持紅色棋\033[m 可連吃"); + } + else { pprints(23,30,""); currutmp->turn=(uin->turn)?0:1; } + } + + if(currutmp->turn==1) + { + if(uin->turn=='g') { cont=1;uin->turn=(currutmp->turn)?0:1; pprints(21,10,"可連吃"); } + end=playing(fd,currutmp->color-'0',ch,&go_on,uin); + + if(end == -1) { currutmp->turn='w';break; } + else if(end == -2) { uin->turn='w';break; } + else if(end == -3) { + uin->turn='p';curr.end=-3; + send(fd,&curr,sizeof(curr),0); + send(fd,&brd,sizeof(buf),0); + continue; + } + else if(end == -4) { + if(currutmp->color!='1'&&currutmp->color!='0') + continue; + uin->turn='c';i=0;curr.end=-4; + send(fd,&curr,sizeof(curr),0); + send(fd,&brd,sizeof(buf),0); + continue; + } + else if(end == -5) { + uin->turn='g';curr.end=-5; + send(fd,&curr,sizeof(curr),0); + send(fd,&brd,sizeof(buf),0); + continue; + } + if(!i && currutmp->color=='1') + { pprints(21,0," \033[1;33m◆你持紅色棋\033[m");i++;move(cury[my],curx[mx]); } + if(!i && currutmp->color=='0') + { pprints(21,0," \033[1;33m◆你持黑色棋\033[m");i++;move(cury[my],curx[mx]); } + + if(uin->turn == 'e') { end=-3; break; } + if(go_on < 0) continue; + + move(22,0);clrtoeol(); + prints(" ◆輪到%s下 別怕別怕 他算啥米",currutmp->mateid); + currutmp->turn = 0; + uin->turn = 1; + }else + { + if(ch == 'q'){uin->turn='w';break;} + move(22,0);clrtoeol(); + prints(" ◆輪到%s下 別怕別怕 他算啥米",currutmp->mateid); + } + } + } + + switch(end) + { + case -1: + case -2: + if(currutmp->turn=='w'){ move(22,0);clrtoeol();prints("你贏了.. 真是恭喜~~");} + else {move(22,0);clrtoeol();prints("輸掉了啦.....下次讓他好看!!");} + break; + case -3: + pprints(22,0,"合棋唷!! 下次在分高下吧 ^_^"); + break; + default: + add_io(0,0); + close(fd); + pressanykey(); + return 0; + } + add_io(0,0); + close(fd); + pressanykey(); + return 0; +} diff --git a/pttbbs/mbbsd/descrypt.c b/pttbbs/mbbsd/descrypt.c new file mode 100644 index 00000000..3bb0a5e5 --- /dev/null +++ b/pttbbs/mbbsd/descrypt.c @@ -0,0 +1,616 @@ +/* $Id: descrypt.c,v 1.1 2002/03/07 15:13:48 in2 Exp $ */ + +/* + * FreeSec: libcrypt for NetBSD + * + * Copyright (c) 1994 David Burren + * All rights reserved. + * + * Adapted for FreeBSD-2.0 by Geoffrey M. Rehmet + * crypt.c should now *only* export crypt(), in order to make + * binaries of libcrypt exportable from the USA + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 4. Neither the name of the author nor the names of other contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD: src/secure/lib/libcrypt/crypt.c,v 1.11 1999/08/28 01:30:24 peter Exp $ + * + * This is an original implementation of the DES and the crypt(3) interfaces + * by David Burren . + * + * An excellent reference on the underlying algorithm (and related + * algorithms) is: + * + * B. Schneier, Applied Cryptography: protocols, algorithms, + * and source code in C, John Wiley & Sons, 1994. + * + * Note that in that book's description of DES the lookups for the initial, + * pbox, and final permutations are inverted (this has been brought to the + * attention of the author). A list of errata for this book has been + * posted to the sci.crypt newsgroup by the author and is available for FTP. + * + * ARCHITECTURE ASSUMPTIONS: + * This code assumes that u_longs are 32 bits. It will probably not + * operate on 64-bit machines without modifications. + * It is assumed that the 8-byte arrays passed by reference can be + * addressed as arrays of u_longs (ie. the CPU is not picky about + * alignment). + */ + +#ifndef HAVE_DES_CRYPT + +#include +#include +#include +#include + +static unsigned char IP[64] = { + 58, 50, 42, 34, 26, 18, 10, 2, 60, 52, 44, 36, 28, 20, 12, 4, + 62, 54, 46, 38, 30, 22, 14, 6, 64, 56, 48, 40, 32, 24, 16, 8, + 57, 49, 41, 33, 25, 17, 9, 1, 59, 51, 43, 35, 27, 19, 11, 3, + 61, 53, 45, 37, 29, 21, 13, 5, 63, 55, 47, 39, 31, 23, 15, 7 +}; + +static unsigned char inv_key_perm[64]; +static unsigned char u_key_perm[56]; +static unsigned char key_perm[56] = { + 57, 49, 41, 33, 25, 17, 9, 1, 58, 50, 42, 34, 26, 18, + 10, 2, 59, 51, 43, 35, 27, 19, 11, 3, 60, 52, 44, 36, + 63, 55, 47, 39, 31, 23, 15, 7, 62, 54, 46, 38, 30, 22, + 14, 6, 61, 53, 45, 37, 29, 21, 13, 5, 28, 20, 12, 4 +}; + +static unsigned char key_shifts[16] = { + 1, 1, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 1 +}; + +static unsigned char inv_comp_perm[56]; +static unsigned char comp_perm[48] = { + 14, 17, 11, 24, 1, 5, 3, 28, 15, 6, 21, 10, + 23, 19, 12, 4, 26, 8, 16, 7, 27, 20, 13, 2, + 41, 52, 31, 37, 47, 55, 30, 40, 51, 45, 33, 48, + 44, 49, 39, 56, 34, 53, 46, 42, 50, 36, 29, 32 +}; + +/* + * No E box is used, as it's replaced by some ANDs, shifts, and ORs. + */ + +static unsigned char u_sbox[8][64]; +static unsigned char sbox[8][64] = { + { + 14, 4, 13, 1, 2, 15, 11, 8, 3, 10, 6, 12, 5, 9, 0, 7, + 0, 15, 7, 4, 14, 2, 13, 1, 10, 6, 12, 11, 9, 5, 3, 8, + 4, 1, 14, 8, 13, 6, 2, 11, 15, 12, 9, 7, 3, 10, 5, 0, + 15, 12, 8, 2, 4, 9, 1, 7, 5, 11, 3, 14, 10, 0, 6, 13 + }, + { + 15, 1, 8, 14, 6, 11, 3, 4, 9, 7, 2, 13, 12, 0, 5, 10, + 3, 13, 4, 7, 15, 2, 8, 14, 12, 0, 1, 10, 6, 9, 11, 5, + 0, 14, 7, 11, 10, 4, 13, 1, 5, 8, 12, 6, 9, 3, 2, 15, + 13, 8, 10, 1, 3, 15, 4, 2, 11, 6, 7, 12, 0, 5, 14, 9 + }, + { + 10, 0, 9, 14, 6, 3, 15, 5, 1, 13, 12, 7, 11, 4, 2, 8, + 13, 7, 0, 9, 3, 4, 6, 10, 2, 8, 5, 14, 12, 11, 15, 1, + 13, 6, 4, 9, 8, 15, 3, 0, 11, 1, 2, 12, 5, 10, 14, 7, + 1, 10, 13, 0, 6, 9, 8, 7, 4, 15, 14, 3, 11, 5, 2, 12 + }, + { + 7, 13, 14, 3, 0, 6, 9, 10, 1, 2, 8, 5, 11, 12, 4, 15, + 13, 8, 11, 5, 6, 15, 0, 3, 4, 7, 2, 12, 1, 10, 14, 9, + 10, 6, 9, 0, 12, 11, 7, 13, 15, 1, 3, 14, 5, 2, 8, 4, + 3, 15, 0, 6, 10, 1, 13, 8, 9, 4, 5, 11, 12, 7, 2, 14 + }, + { + 2, 12, 4, 1, 7, 10, 11, 6, 8, 5, 3, 15, 13, 0, 14, 9, + 14, 11, 2, 12, 4, 7, 13, 1, 5, 0, 15, 10, 3, 9, 8, 6, + 4, 2, 1, 11, 10, 13, 7, 8, 15, 9, 12, 5, 6, 3, 0, 14, + 11, 8, 12, 7, 1, 14, 2, 13, 6, 15, 0, 9, 10, 4, 5, 3 + }, + { + 12, 1, 10, 15, 9, 2, 6, 8, 0, 13, 3, 4, 14, 7, 5, 11, + 10, 15, 4, 2, 7, 12, 9, 5, 6, 1, 13, 14, 0, 11, 3, 8, + 9, 14, 15, 5, 2, 8, 12, 3, 7, 0, 4, 10, 1, 13, 11, 6, + 4, 3, 2, 12, 9, 5, 15, 10, 11, 14, 1, 7, 6, 0, 8, 13 + }, + { + 4, 11, 2, 14, 15, 0, 8, 13, 3, 12, 9, 7, 5, 10, 6, 1, + 13, 0, 11, 7, 4, 9, 1, 10, 14, 3, 5, 12, 2, 15, 8, 6, + 1, 4, 11, 13, 12, 3, 7, 14, 10, 15, 6, 8, 0, 5, 9, 2, + 6, 11, 13, 8, 1, 4, 10, 7, 9, 5, 0, 15, 14, 2, 3, 12 + }, + { + 13, 2, 8, 4, 6, 15, 11, 1, 10, 9, 3, 14, 5, 0, 12, 7, + 1, 15, 13, 8, 10, 3, 7, 4, 12, 5, 6, 11, 0, 14, 9, 2, + 7, 11, 4, 1, 9, 12, 14, 2, 0, 6, 10, 13, 15, 3, 5, 8, + 2, 1, 14, 7, 4, 10, 8, 13, 15, 12, 9, 0, 3, 5, 6, 11 + } +}; + +static unsigned char un_pbox[32]; +static unsigned char pbox[32] = { + 16, 7, 20, 21, 29, 12, 28, 17, 1, 15, 23, 26, 5, 18, 31, 10, + 2, 8, 24, 14, 32, 27, 3, 9, 19, 13, 30, 6, 22, 11, 4, 25 +}; + +static unsigned long bits32[32] = { + 0x80000000, 0x40000000, 0x20000000, 0x10000000, + 0x08000000, 0x04000000, 0x02000000, 0x01000000, + 0x00800000, 0x00400000, 0x00200000, 0x00100000, + 0x00080000, 0x00040000, 0x00020000, 0x00010000, + 0x00008000, 0x00004000, 0x00002000, 0x00001000, + 0x00000800, 0x00000400, 0x00000200, 0x00000100, + 0x00000080, 0x00000040, 0x00000020, 0x00000010, + 0x00000008, 0x00000004, 0x00000002, 0x00000001 +}; + +static unsigned char bits8[8] = { 0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01 }; + +static unsigned long saltbits; +static long old_salt; +static unsigned long *bits28, *bits24; +static unsigned char init_perm[64], final_perm[64]; +static unsigned long en_keysl[16], en_keysr[16]; +static unsigned long de_keysl[16], de_keysr[16]; +static int des_initialised = 0; +static unsigned char m_sbox[4][4096]; +static unsigned long psbox[4][256]; +static unsigned long ip_maskl[8][256], ip_maskr[8][256]; +static unsigned long fp_maskl[8][256], fp_maskr[8][256]; +static unsigned long key_perm_maskl[8][128], key_perm_maskr[8][128]; +static unsigned long comp_maskl[8][128], comp_maskr[8][128]; +static unsigned long old_rawkey0, old_rawkey1; + +static unsigned char ascii64[] = +"./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; +/* 0000000000111111111122222222223333333333444444444455555555556666 */ +/* 0123456789012345678901234567890123456789012345678901234567890123 */ + +static int ascii_to_bin(char ch) { + if(ch > 'z') + return 0; + if(ch >= 'a') + return ch - 'a' + 38; + if(ch > 'Z') + return 0; + if(ch >= 'A') + return ch - 'A' + 12; + if(ch > '9') + return 0; + if(ch >= '.') + return ch - '.'; + return 0; +} + +static void des_init() { + int i, j, b, k, inbit, obit; + unsigned long *p, *il, *ir, *fl, *fr; + + old_rawkey0 = old_rawkey1 = 0L; + saltbits = 0L; + old_salt = 0L; + bits24 = (bits28 = bits32 + 4) + 4; + + /* + * Invert the S-boxes, reordering the input bits. + */ + for(i = 0; i < 8; i++) + for(j = 0; j < 64; j++) { + b = (j & 0x20) | ((j & 1) << 4) | ((j >> 1) & 0xf); + u_sbox[i][j] = sbox[i][b]; + } + + /* + * Convert the inverted S-boxes into 4 arrays of 8 bits. + * Each will handle 12 bits of the S-box input. + */ + for(b = 0; b < 4; b++) + for(i = 0; i < 64; i++) + for(j = 0; j < 64; j++) + m_sbox[b][(i << 6) | j] = + (u_sbox[(b << 1)][i] << 4) | + u_sbox[(b << 1) + 1][j]; + + /* + * Set up the initial & final permutations into a useful form, and + * initialise the inverted key permutation. + */ + for(i = 0; i < 64; i++) { + init_perm[final_perm[i] = IP[i] - 1] = i; + inv_key_perm[i] = 255; + } + + /* + * Invert the key permutation and initialise the inverted key + * compression permutation. + */ + for(i = 0; i < 56; i++) { + u_key_perm[i] = key_perm[i] - 1; + inv_key_perm[key_perm[i] - 1] = i; + inv_comp_perm[i] = 255; + } + + /* + * Invert the key compression permutation. + */ + for(i = 0; i < 48; i++) { + inv_comp_perm[comp_perm[i] - 1] = i; + } + + /* + * Set up the OR-mask arrays for the initial and final permutations, + * and for the key initial and compression permutations. + */ + for(k = 0; k < 8; k++) { + for(i = 0; i < 256; i++) { + *(il = &ip_maskl[k][i]) = 0L; + *(ir = &ip_maskr[k][i]) = 0L; + *(fl = &fp_maskl[k][i]) = 0L; + *(fr = &fp_maskr[k][i]) = 0L; + for(j = 0; j < 8; j++) { + inbit = 8 * k + j; + if(i & bits8[j]) { + if((obit = init_perm[inbit]) < 32) + *il |= bits32[obit]; + else + *ir |= bits32[obit-32]; + if ((obit = final_perm[inbit]) < 32) + *fl |= bits32[obit]; + else + *fr |= bits32[obit - 32]; + } + } + } + for(i = 0; i < 128; i++) { + *(il = &key_perm_maskl[k][i]) = 0L; + *(ir = &key_perm_maskr[k][i]) = 0L; + for(j = 0; j < 7; j++) { + inbit = 8 * k + j; + if(i & bits8[j + 1]) { + if((obit = inv_key_perm[inbit]) == 255) + continue; + if(obit < 28) + *il |= bits28[obit]; + else + *ir |= bits28[obit - 28]; + } + } + *(il = &comp_maskl[k][i]) = 0L; + *(ir = &comp_maskr[k][i]) = 0L; + for(j = 0; j < 7; j++) { + inbit = 7 * k + j; + if(i & bits8[j + 1]) { + if((obit=inv_comp_perm[inbit]) == 255) + continue; + if(obit < 24) + *il |= bits24[obit]; + else + *ir |= bits24[obit - 24]; + } + } + } + } + + /* + * Invert the P-box permutation, and convert into OR-masks for + * handling the output of the S-box arrays setup above. + */ + for(i = 0; i < 32; i++) + un_pbox[pbox[i] - 1] = i; + + for(b = 0; b < 4; b++) + for(i = 0; i < 256; i++) { + *(p = &psbox[b][i]) = 0L; + for (j = 0; j < 8; j++) { + if (i & bits8[j]) + *p |= bits32[un_pbox[8 * b + j]]; + } + } + + des_initialised = 1; +} + +static void setup_salt(long salt) { + unsigned long obit, saltbit; + int i; + + if (salt == old_salt) + return; + old_salt = salt; + + saltbits = 0L; + saltbit = 1; + obit = 0x800000; + for (i = 0; i < 24; i++) { + if (salt & saltbit) + saltbits |= obit; + saltbit <<= 1; + obit >>= 1; + } +} + +static int des_setkey(const char *key) { + unsigned long k0, k1, rawkey0, rawkey1; + int shifts, round; + + if(!des_initialised) + des_init(); + + rawkey0 = ntohl(*(unsigned long *) key); + rawkey1 = ntohl(*(unsigned long *) (key + 4)); + + if((rawkey0 | rawkey1) + && rawkey0 == old_rawkey0 + && rawkey1 == old_rawkey1) { + /* + * Already setup for this key. + * This optimisation fails on a zero key (which is weak and + * has bad parity anyway) in order to simplify the starting + * conditions. + */ + return 0; + } + old_rawkey0 = rawkey0; + old_rawkey1 = rawkey1; + + /* + * Do key permutation and split into two 28-bit subkeys. + */ + k0 = key_perm_maskl[0][rawkey0 >> 25] + | key_perm_maskl[1][(rawkey0 >> 17) & 0x7f] + | key_perm_maskl[2][(rawkey0 >> 9) & 0x7f] + | key_perm_maskl[3][(rawkey0 >> 1) & 0x7f] + | key_perm_maskl[4][rawkey1 >> 25] + | key_perm_maskl[5][(rawkey1 >> 17) & 0x7f] + | key_perm_maskl[6][(rawkey1 >> 9) & 0x7f] + | key_perm_maskl[7][(rawkey1 >> 1) & 0x7f]; + k1 = key_perm_maskr[0][rawkey0 >> 25] + | key_perm_maskr[1][(rawkey0 >> 17) & 0x7f] + | key_perm_maskr[2][(rawkey0 >> 9) & 0x7f] + | key_perm_maskr[3][(rawkey0 >> 1) & 0x7f] + | key_perm_maskr[4][rawkey1 >> 25] + | key_perm_maskr[5][(rawkey1 >> 17) & 0x7f] + | key_perm_maskr[6][(rawkey1 >> 9) & 0x7f] + | key_perm_maskr[7][(rawkey1 >> 1) & 0x7f]; + /* + * Rotate subkeys and do compression permutation. + */ + shifts = 0; + for(round = 0; round < 16; round++) { + unsigned long t0, t1; + + shifts += key_shifts[round]; + + t0 = (k0 << shifts) | (k0 >> (28 - shifts)); + t1 = (k1 << shifts) | (k1 >> (28 - shifts)); + + de_keysl[15 - round] = + en_keysl[round] = comp_maskl[0][(t0 >> 21) & 0x7f] + | comp_maskl[1][(t0 >> 14) & 0x7f] + | comp_maskl[2][(t0 >> 7) & 0x7f] + | comp_maskl[3][t0 & 0x7f] + | comp_maskl[4][(t1 >> 21) & 0x7f] + | comp_maskl[5][(t1 >> 14) & 0x7f] + | comp_maskl[6][(t1 >> 7) & 0x7f] + | comp_maskl[7][t1 & 0x7f]; + + de_keysr[15 - round] = en_keysr[round] = + comp_maskr[0][(t0 >> 21) & 0x7f] + | comp_maskr[1][(t0 >> 14) & 0x7f] + | comp_maskr[2][(t0 >> 7) & 0x7f] + | comp_maskr[3][t0 & 0x7f] + | comp_maskr[4][(t1 >> 21) & 0x7f] + | comp_maskr[5][(t1 >> 14) & 0x7f] + | comp_maskr[6][(t1 >> 7) & 0x7f] + | comp_maskr[7][t1 & 0x7f]; + } + return 0; +} + +static int do_des(unsigned long l_in, unsigned long r_in, unsigned long *l_out, + unsigned long *r_out, int count) { + /* + * l_in, r_in, l_out, and r_out are in pseudo-"big-endian" format. + */ + unsigned long l, r, *kl, *kr, *kl1, *kr1; + unsigned long f, r48l, r48r; + int round; + + if(count == 0) { + return 1; + } else if(count > 0) { + /* + * Encrypting + */ + kl1 = en_keysl; + kr1 = en_keysr; + } else { + /* + * Decrypting + */ + count = -count; + kl1 = de_keysl; + kr1 = de_keysr; + } + + /* + * Do initial permutation (IP). + */ + l = ip_maskl[0][l_in >> 24] + | ip_maskl[1][(l_in >> 16) & 0xff] + | ip_maskl[2][(l_in >> 8) & 0xff] + | ip_maskl[3][l_in & 0xff] + | ip_maskl[4][r_in >> 24] + | ip_maskl[5][(r_in >> 16) & 0xff] + | ip_maskl[6][(r_in >> 8) & 0xff] + | ip_maskl[7][r_in & 0xff]; + r = ip_maskr[0][l_in >> 24] + | ip_maskr[1][(l_in >> 16) & 0xff] + | ip_maskr[2][(l_in >> 8) & 0xff] + | ip_maskr[3][l_in & 0xff] + | ip_maskr[4][r_in >> 24] + | ip_maskr[5][(r_in >> 16) & 0xff] + | ip_maskr[6][(r_in >> 8) & 0xff] + | ip_maskr[7][r_in & 0xff]; + + while(count--) { + /* + * Do each round. + */ + kl = kl1; + kr = kr1; + round = 16; + while(round--) { + /* + * Expand R to 48 bits (simulate the E-box). + */ + r48l = ((r & 0x00000001) << 23) + | ((r & 0xf8000000) >> 9) + | ((r & 0x1f800000) >> 11) + | ((r & 0x01f80000) >> 13) + | ((r & 0x001f8000) >> 15); + + r48r = ((r & 0x0001f800) << 7) + | ((r & 0x00001f80) << 5) + | ((r & 0x000001f8) << 3) + | ((r & 0x0000001f) << 1) + | ((r & 0x80000000) >> 31); + /* + * Do salting for crypt() and friends, and + * XOR with the permuted key. + */ + f = (r48l ^ r48r) & saltbits; + r48l ^= f ^ *kl++; + r48r ^= f ^ *kr++; + /* + * Do sbox lookups (which shrink it back to 32 bits) + * and do the pbox permutation at the same time. + */ + f = psbox[0][m_sbox[0][r48l >> 12]] + | psbox[1][m_sbox[1][r48l & 0xfff]] + | psbox[2][m_sbox[2][r48r >> 12]] + | psbox[3][m_sbox[3][r48r & 0xfff]]; + /* + * Now that we've permuted things, complete f(). + */ + f ^= l; + l = r; + r = f; + } + r = l; + l = f; + } + /* + * Do final permutation (inverse of IP). + */ + *l_out = fp_maskl[0][l >> 24] + | fp_maskl[1][(l >> 16) & 0xff] + | fp_maskl[2][(l >> 8) & 0xff] + | fp_maskl[3][l & 0xff] + | fp_maskl[4][r >> 24] + | fp_maskl[5][(r >> 16) & 0xff] + | fp_maskl[6][(r >> 8) & 0xff] + | fp_maskl[7][r & 0xff]; + *r_out = fp_maskr[0][l >> 24] + | fp_maskr[1][(l >> 16) & 0xff] + | fp_maskr[2][(l >> 8) & 0xff] + | fp_maskr[3][l & 0xff] + | fp_maskr[4][r >> 24] + | fp_maskr[5][(r >> 16) & 0xff] + | fp_maskr[6][(r >> 8) & 0xff] + | fp_maskr[7][r & 0xff]; + return 0; +} + +char *crypt(char *key, char *setting) { + unsigned long count, salt, l, r0, r1, keybuf[2]; + unsigned char *p, *q; + static unsigned char output[21]; + + if(!des_initialised) + des_init(); + /* + * Copy the key, shifting each character up by one bit + * and padding with zeros. + */ + q = (unsigned char *)keybuf; + while(q - (unsigned char *)keybuf - 8) { + if((*q++ = *key << 1)) + key++; + } + if(des_setkey((unsigned char *)keybuf)) + return NULL; + + /* + * "old"-style: + * setting - 2 bytes of salt + * key - up to 8 characters + */ + count = 25; + + salt = (ascii_to_bin(setting[1]) << 6) + | ascii_to_bin(setting[0]); + + output[0] = setting[0]; + /* + * If the encrypted password that the salt was extracted from + * is only 1 character long, the salt will be corrupted. We + * need to ensure that the output string doesn't have an extra + * NUL in it! + */ + output[1] = setting[1] ? setting[1] : output[0]; + + p = output + 2; + + setup_salt(salt); + /* + * Do it. + */ + if(do_des(0L, 0L, &r0, &r1, count)) + return NULL; + /* + * Now encode the result... + */ + l = (r0 >> 8); + *p++ = ascii64[(l >> 18) & 0x3f]; + *p++ = ascii64[(l >> 12) & 0x3f]; + *p++ = ascii64[(l >> 6) & 0x3f]; + *p++ = ascii64[l & 0x3f]; + + l = (r0 << 16) | ((r1 >> 16) & 0xffff); + *p++ = ascii64[(l >> 18) & 0x3f]; + *p++ = ascii64[(l >> 12) & 0x3f]; + *p++ = ascii64[(l >> 6) & 0x3f]; + *p++ = ascii64[l & 0x3f]; + + l = r1 << 2; + *p++ = ascii64[(l >> 12) & 0x3f]; + *p++ = ascii64[(l >> 6) & 0x3f]; + *p++ = ascii64[l & 0x3f]; + *p = 0; + + return output; +} +#endif diff --git a/pttbbs/mbbsd/dice.c b/pttbbs/mbbsd/dice.c new file mode 100644 index 00000000..d64ce63c --- /dev/null +++ b/pttbbs/mbbsd/dice.c @@ -0,0 +1,447 @@ +/* $Id: dice.c,v 1.1 2002/03/07 15:13:48 in2 Exp $ */ +#include +#include +#include +#include +#include "config.h" +#include "pttstruct.h" +#include "common.h" +#include "modes.h" +#include "proto.h" + +#define DICE_TXT BBSHOME "/etc/dice.txt" +#define DICE_DATA BBSHOME "/etc/dice.data" +#define DICE_WIN BBSHOME "/etc/windice.log" +#define DICE_LOST BBSHOME "/etc/lostdice.log" + +#define B_MAX 500 +#define B_MIN 10 +#define B_COMMON 1 +#define B_TIMES 5 +#define B_THIRD 3 + +extern int usernum; +static int flag[100], value[100]; + +typedef struct dicedata_t { + int mybet; + int mymoney; +} dicedata_t; + +static void set_bingo(int bet[]) { + int i, j = 0, k = 0, m = 0; + + for(i = 0; i < 3; i++) + for(j = 2; j > i; j--) + if(bet[j] < bet[j - 1]) { + m = bet[j]; + bet[j] = bet[j - 1]; + bet[j - 1]=m; + } + + for(i = 0; i < 100; i++) + flag[i] = 0; + + for(i = 0; i < 3; i++) + flag[bet[i]]++; + j = bet[0] + bet[1] + bet[2]; + + if((abs(bet[1] - bet[0]) == 1 && abs(bet[2] - bet[0]) == 2) || + (abs(bet[2] - bet[0]) == 1 && abs(bet[1] - bet[0]) == 2)) + flag[66] = B_TIMES; + + if(j < 10){ + flag[7] = B_COMMON; + for(i = 0; i < 3; i++) + if(bet[i] == 4) + flag[74] = B_TIMES; + } else if(j > 11) { + flag[8] = B_COMMON; + for(i = 0; i < 3; i++) + if(bet[i] == 3) + flag[83]=B_TIMES; + } else + flag[11] = B_THIRD; + + for(i = 0; i < 3; i++) + for(j = i; j < 3; j++) { + m = bet[i]; + k = bet[j]; + if(m != k) + flag[m * 10 + k] = B_TIMES; + } +} + +static int bingo(int mybet) { + return flag[mybet]; +} + +int IsNum(char *a, int n) { + int i; + + for(i = 0; i < n; i++) + if (a[i] > '9' || a[i] < '0' ) + return 0; + return 1; +} + +int IsSNum(char *a) { + int i; + + for(i = 0; a[i]; i++) + if(a[i] > '9' || a[i] < '0') + return 0; + return 1; +} + +static void show_data(void) { + move(0, 0); + prints("\033[31m ┌───────────────────────" + "──────────┐\033[m\n"); + prints("\033[45;37m倍率一\033[m\033[31m │ \033[33m[1]押一點 [2]押二點 " + "[3]押三點 [4]押四點 [5]押五點 [6]押六點 \033[31m │\033[m\n"); + prints("\033[31m │ \033[33m[7]押小 [8]押大 " + " \033[31m │\033[m\n"); + prints("\033[31m │ " + " │\033[m\n"); + prints("\033[45;37m賠率三\033[m\033[31m │ \033[33m[11]押中(總點數等於11" + "或10) \033[31m │\033[m\n"); + prints("\033[31m │ " + " │\033[m\n"); + prints("\033[45;37m賠率五\033[m\033[31m │ \033[33m[74]押小且四點 [83]押" + "大且三點 [66]押連號 \033[31m │\033[m\n"); + prints("\033[31m │ " + " │\033[m\n"); + prints("\033[31m │ \033[33m[12]押一二點 [13]押一三點 [14]押一四點" + " [15]押一五點 [16]押一六點\033[31m │\033[m\n"); + prints("\033[31m │ \033[33m[23]押二三點 [24]押二四點 [25]押二五點" + " [26]押二六點 [34]押三四點\033[31m │\033[m\n"); + prints("\033[31m │ \033[33m[35]押三五點 [36]押三六點 [45]押四五點" + " [46]押四六點 [56]押五六點\033[31m │\033[m\n"); + prints("\033[31m └────────────────────────" + "─────────┘\033[m\n"); +} + +static void show_count(int index, int money) { + int i = 0, count = 2, j, k; + + value[index] += money; + move(14,0); + clrtoline(18); + for(i = 1, j = 13; i <= 8; i++, count += 12) { + if(i == 6) { + j = 14; + count = 2; + } + move(j,count); + prints("[%2d]:%d ", i, value[i]); + } + + count = 2; + i = 15; + for(j = 1; j <= 5; j++) + for(k = j + 1; k <= 6; k++, count += 12) { + if(j == 2 && k == 4) { + i = 16; + count = 2; + } else if(j==4 && k==5) { + i = 17; + count = 2; + } + move(i,count); + prints("[%d%d]:%d ", j, k, value[j * 10 + k]); + } + + move(18,2); + prints("[11]:%d",value[11]); + move(18,14); + prints("[66]:%d",value[66]); + move(18,26); + prints("[74]:%d",value[74]); + move(18,38); + prints("[83]:%d",value[83]); +} + +static int check_index(int index) { + int i,tp[] = {1, 2, 3, 4, 5, 6, 7, 8, 11, 12, 13, 14, 15, 16, 23, 24, 25, + 26, 34, 35, 36, 45, 46, 56, 66, 74, 83}; + if(index < 0 || index > 100) + return 0; + for(i = 0; i < 27; i++) + if(index == tp[i]) + return 1; + return 0; +} + +extern userec_t cuser; + +static int del(int total, dicedata_t *table) { + int index, money; + char data[10]; + int i; + + while(1) { + do { + move(22,0); + clrtoeol(); + getdata(21, 0, "輸入退選的數字(打q離開): ", data, 3, LCECHO); + if(data[0] == 'q' || data[0] == 'Q') + return 0; + } while(!IsNum(data,strlen(data))); + + index = atoi(data); + for(i = 0; i < total; i++) { + if(table[i].mybet == index){ + do { + getdata(21, 0, "多少錢: ", data, 10, LCECHO); + } while(!IsNum(data,strlen(data))); + money = atoi(data); + if(money>table[i].mymoney) { + move(22,0); + clrtoeol(); + prints("不夠扣啦"); + i--; + continue; + } + demoney(money); + move(19,0); + clrtoeol(); + prints("你現在有 %u Ptt$歐", cuser.money); + table[i].mymoney -= money; + show_count(index, -money); + break; + } + } + } + return 0; +} + +static int IsLegal(char *data) { + int money = atoi(data); + if(IsNum(data,strlen(data)) && money<=B_MAX && money>=B_MIN) + return money; + return 0; +} + +static void show_output(int bet[]) { + int i, j = 10; + + move(12,0); + clrtoline(17); + /* 暫時降啦 因為那各clrtoline怪怪的 */ + for(i = 13; i <= 18; i++) { + move(i,0); + prints(" "); + } + move(12,0); + prints("\033[1;31m ┌──────────────────────" + "─┐\033[m\n\n\n\n\n\n"); + prints("\033[1;31m └──────────────────────" + "─┘\033[m"); + for(i = 0; i < 3; i++, j += 25) { + switch(bet[i]) { + case 1: + move(13, j);prints("\033[37m╭────╮\033[m"); + move(14, j);prints("\033[37m│ │\033[m"); + move(15, j);prints("\033[37m│ ● │\033[m"); + move(16, j);prints("\033[37m│ │\033[m"); + move(17, j);prints("\033[37m╰────╯\033[m"); + break; + case 2: + move(13, j);prints("\033[37m╭────╮\033[m"); + move(14, j);prints("\033[37m│ ●│\033[m"); + move(15, j);prints("\033[37m│ │\033[m"); + move(16, j);prints("\033[37m│● │\033[m"); + move(17, j);prints("\033[37m╰────╯\033[m"); + break; + case 3: + move(13, j);prints("\033[37m╭────╮\033[m"); + move(14, j);prints("\033[37m│ ●│\033[m"); + move(15, j);prints("\033[37m│ ● │\033[m"); + move(16, j);prints("\033[37m│● │\033[m"); + move(17, j);prints("\033[37m╰────╯\033[m"); + break; + case 4: + move(13, j);prints("\033[37m╭────╮\033[m"); + move(14, j);prints("\033[37m│● ●│\033[m"); + move(15, j);prints("\033[37m│ │\033[m"); + move(16, j);prints("\033[37m│● ●│\033[m"); + move(17, j);prints("\033[37m╰────╯\033[m"); + break; + case 5: + move(13, j);prints("\033[37m╭────╮\033[m"); + move(14, j);prints("\033[37m│● ●│\033[m"); + move(15, j);prints("\033[37m│ ● │\033[m"); + move(16, j);prints("\033[37m│● ●│\033[m"); + move(17, j);prints("\033[37m╰────╯\033[m"); + break; + case 6: + move(13, j);prints("\033[37m╭────╮\033[m"); + move(14, j);prints("\033[37m│● ●│\033[m"); + move(15, j);prints("\033[37m│● ●│\033[m"); + move(16, j);prints("\033[37m│● ●│\033[m"); + move(17, j);prints("\033[37m╰────╯\033[m"); + break; + } + } +} + +#define lockreturn0(unmode, state) if(lockutmpmode(unmode, state)) return 0 + +int dice_main(void) { + char input[10],data[256], ch; + dicedata_t table[256]; + int bet[3], index, money = 0, i, ya = 0, j, total, sig = 0; + FILE *winfp/* , *lostfp */; + + more(DICE_TXT, NA); + reload_money(); + if(cuser.money < 10){ + move(19,0); + prints("\033[1;37m超過十元再來玩吧~~\033[m"); + pressanykey(); + return 0; + } + + lockreturn0(DICE, LOCK_MULTI); + winfp = fopen(DICE_WIN,"a"); + /*lostfp = fopen(DICE_LOST,"a");*/ + if(!winfp /*|| !lostfp*/) + return 0; + + do { + total = 0; i = 0; + ch = 'y'; + clear(); + show_data(); + for(j = 0; j < 3; j++) + bet[j] = rand() % 6 + 1; + + for(j = 0; j < 100; j++) + value[j] = 0; + + while(1) { + move(19,0); + prints("\033[1;32m你現在有\033[1;31m %u \033[1;32mPtt$歐\033[m", + cuser.money); + getdata(20, 0, "\033[1;37m數字:加選 d:退選 s:開始或離開\033[m: ", + input, 5, LCECHO); + reload_money(); + if(input[0] != 's' && input[0] != 'd' && cuser.money < 10) { + move(21, 0); + clrtoeol(); + prints("\033[1;37m超過十元才能賭~\033[m"); + continue; + } + if(input[0] == 'd' || input[0] == 'D') { + del(i, table); + continue; + } + if(input[0] == 's' || input[0] == 'S') + break; + + if(!IsNum(input,strlen(input))) + continue; + + index=atoi(input); + if(check_index(index) == 0) + continue; +/*輸入錢的loop*/ + while(1) { + if(cuser.money < 10) + break; + getdata(21, 0, "\033[1;32m賭多少錢呢\033[1;37m(大於10 小於500)" + "\033[m: ", input, 9, LCECHO); + if(!(money = IsLegal(input))||input[0] == '0') + continue; + reload_money(); + if(money > cuser.money) + continue; + for(j = 0, sig = 0; j < i; j++) + if(table[j].mybet == index) { + if(table[j].mymoney == B_MAX) + sig = 2; + else if(table[j].mymoney+money>B_MAX) { + sig = 1; + break; + } else { + vice(money,"骰子"); + table[j].mymoney += money; + j = -1; + break; + } + } + if(sig == 2) + break; + if(sig == 1) + continue; + if(j != -1) { + bzero((char*)&table[i], sizeof(dicedata_t)); + table[i].mybet = index; + table[i++].mymoney = money; + vice(money,"骰子"); + } + break; + } + reload_money(); + move(19,0); + prints("\033[1;32m你現在有 \033[1;31m%u\033[1;32m Ptt$歐", + cuser.money); + if(sig != 2) + show_count(index, money); + } + + if(i == 0) { + fclose(winfp); + /*fclose(lostfp);*/ + unlockutmpmode(); + return 0; + } + + show_output(bet); + set_bingo(bet); + + for(j = 0; j < i; j++) { + if(table[j].mymoney <= 0) + continue; + ya = bingo(table[j].mybet); + if(ya == 0) { + /*sprintf(data, "%-15s 輸了 %-8d $", cuser.userid, + table[j].mymoney); + fprintf(lostfp, "%s\n", data);*/ + continue; + } + demoney(table[j].mymoney * ya + table[j].mymoney); + total += table[j].mymoney * ya; + if (table[j].mymoney * ya > 500){ /* 超過500塊錢才做log 減少io */ + sprintf(data, "%-15s 押%-2d選項%-8d塊錢 中了%d倍 淨賺:%-8d\n", + cuser.userid,table[j].mybet, + table[j].mymoney, ya, table[j].mymoney * ya); + fputs(data,winfp); + } + ya = 0; + } + + if(total > 0) { + move(21,0); + prints("\033[1;32m你贏了 \033[1;31m%d\033[1;32m Ptt$ 唷~~" + " \033[m", total); + } else { + move(21,0); + clrtoeol(); + prints("\033[1;32m真可惜 下次再來碰碰運氣吧\033[m"); + } + + move(19,0); + clrtoeol(); + prints("\033[1;32m你現在有 \033[1;31m%u\033[1;32m Ptt$歐\033[m", + cuser.money); + + getdata(23, 0, "\033[1;32m繼續奮鬥[\033[1;37my/n\033[1;32m]\033[m: ", + input, 2, LCECHO); + } while(input[0] != 'n' && input[0] != 'N'); + fclose(winfp); + /*fclose(lostfp);*/ + unlockutmpmode(); + return 0; +} diff --git a/pttbbs/mbbsd/edit.c b/pttbbs/mbbsd/edit.c new file mode 100644 index 00000000..19f437af --- /dev/null +++ b/pttbbs/mbbsd/edit.c @@ -0,0 +1,2256 @@ +/* $Id: edit.c,v 1.1 2002/03/07 15:13:48 in2 Exp $ */ +#include +#include +#include +#include +#include +#include +#include +#include "config.h" +#include "pttstruct.h" +#include "config.h" +#include "common.h" +#include "modes.h" +#include "perm.h" +#include "proto.h" + +#define WRAPMARGIN (511) + +typedef struct textline_t { + struct textline_t *prev; + struct textline_t *next; + int len; + char data[WRAPMARGIN + 1]; +} textline_t; + +extern int current_font_type; +extern char *str_author1; +extern char *str_author2; +extern int t_lines, t_columns; /* Screen size / width */ +extern int b_lines; /* Screen bottom line number: t_lines-1 */ +extern char quote_file[80]; +extern char quote_user[80]; +extern int curredit; +extern unsigned int currbrdattr; +extern char currboard[]; /* name of currently selected board */ +extern char *str_reply; +extern char *str_post1; +extern char *str_post2; +extern char *BBSName; +extern char fromhost[]; +extern unsigned int currstat; +extern crosspost_t postrecord; +extern userinfo_t *currutmp; +extern int KEY_ESC_arg; +extern char reset_color[]; +extern char trans_buffer[256]; + +#define KEEP_EDITING -2 +#define BACKUP_LIMIT 100 +#define SCR_WIDTH 80 + +enum { + NOBODY, MANAGER, SYSOP +}; + +static textline_t *firstline = NULL; +static textline_t *lastline = NULL; +static textline_t *currline = NULL; +static textline_t *blockline = NULL; +static textline_t *top_of_win = NULL; +static textline_t *deleted_lines = NULL; + +extern int local_article; +extern char real_name[20]; +static char line[WRAPMARGIN + 2]; +static int ifuseanony=0; +static int currpnt, currln, totaln; +static int curr_window_line; +static int redraw_everything; +static int insert_character; +static int my_ansimode; +static int raw_mode; +static int edit_margin; +static int blockln = -1; +static int blockpnt; +static int prevln = -1; +static int prevpnt; +static int line_dirty; +static int indent_mode; +static int insert_c = ' '; + +static char fp_bak[] = "bak"; + +char save_title[STRLEN]; + +/* 記憶體管理與編輯處理 */ +static void indigestion(i) { + fprintf(stderr, "嚴重內傷 %d\n", i); +} + +/* Thor: ansi 座標轉換 for color 編輯模式 */ +static int ansi2n(int ansix, textline_t * line) { + register char *data, *tmp; + register char ch; + + data = tmp = line->data; + + while(*tmp) { + if(*tmp == KEY_ESC) { + while((ch = *tmp) && !isalpha(ch)) + tmp++; + if(ch) + tmp++; + continue; + } + if(ansix <= 0) + break; + tmp++; + ansix--; + } + return tmp - data; +} + +static int n2ansi(int nx, textline_t * line) { + register int ansix = 0; + register char *tmp,*nxp; + register char ch; + + tmp = nxp = line->data; + nxp += nx; + + while(*tmp) { + if(*tmp == KEY_ESC) { + while((ch = *tmp) && !isalpha(ch)) + tmp++; + if(ch) + tmp++; + continue; + } + if(tmp >= nxp) + break; + tmp++; + ansix++; + } + return ansix; +} + +/* 螢幕處理:輔助訊息、顯示編輯內容 */ +static void edit_msg() { + static char *edit_mode[2] = {"取代", "插入"}; + register int n = currpnt; + + if(my_ansimode) /* Thor: 作 ansi 編輯 */ + n = n2ansi(n, currline); + n++; + move(b_lines, 0); + clrtoeol(); + prints("\033[%sm 編輯文章 \033[31;47m (Ctrl-Z)\033[30m輔助說明 " + "\033[31;47m(^G)\033[30m插入圖文庫 \033[31m(^X,^Q)" + "\033[30m離開%s│%c%c%c%c %3d:%3d \033[m", + "37;44", + edit_mode[insert_character], + my_ansimode ? 'A' : 'a', indent_mode ? 'I' : 'i', + 'P' , raw_mode ? 'R' : 'r', + currln + 1, n); +} + +static textline_t *back_line(textline_t *pos, int num) { + while(num-- > 0) { + register textline_t *item; + + if(pos && (item = pos->prev)) { + pos = item; + currln--; + } + } + return pos; +} + +static textline_t *forward_line(textline_t *pos, int num) { + while(num-- > 0) { + register textline_t *item; + + if(pos && (item = pos->next)) { + pos = item; + currln++; + } + } + return pos; +} + +static int getlineno() { + int cnt = 0; + textline_t *p = currline; + + while(p && (p != top_of_win)) { + cnt++; + p = p->prev; + } + return cnt; +} + +static char *killsp(char *s) { + while(*s == ' ') + s++; + return s; +} + +static textline_t *alloc_line() { + register textline_t *p; + + if((p = (textline_t *)malloc(sizeof(textline_t)))) { + memset(p, 0, sizeof(textline_t)); + return p; + } + + indigestion(13); + abort_bbs(0); + return NULL; +} + +/* append p after line in list. keeps up with last line */ +static void append(textline_t *p, textline_t *line) { + register textline_t *n; + + if((p->next = n = line->next)) + n->prev = p; + else + lastline = p; + line->next = p; + p->prev = line; +} + +/* + delete_line deletes 'line' from the list, + and maintains the lastline, and firstline pointers. +*/ + +static void delete_line(textline_t *line) { + register textline_t *p = line->prev; + register textline_t *n = line->next; + + if(!p && !n) { + line->data[0] = line->len = 0; + return; + } + if(n) + n->prev = p; + else + lastline = p; + if(p) + p->next = n; + else + firstline = n; + strcat(line->data, "\n"); + line->prev = deleted_lines; + deleted_lines = line; + totaln--; +} + +static int ask(char *prompt) { + int ch; + + move (0, 0); + clrtoeol (); + standout (); + prints ("%s", prompt); + standend (); + ch = igetkey (); + move (0, 0); + clrtoeol (); + return (ch); +} + +static int indent_spcs() { + textline_t* p; + int spcs; + + if(!indent_mode) + return 0; + + for(p = currline; p; p = p->prev) { + for(spcs = 0; p->data[spcs] == ' '; ++spcs); + if (p->data[spcs]) + return spcs; + } + return 0; +} + +/* split 'line' right before the character pos */ +static void split(textline_t *line, int pos) { + if(pos <= line->len) { + register textline_t *p = alloc_line(); + register char *ptr; + int spcs = indent_spcs(); + + totaln++; + + p->len = line->len - pos + spcs; + line->len = pos; + + memset(p->data, ' ', spcs); + p->data[spcs] = 0; + strcat(p->data, (ptr = line->data + pos)); + ptr[0] = '\0'; + append(p, line); + if(line == currline && pos <= currpnt) { + currline = p; + if(pos == currpnt) + currpnt = spcs; + else + currpnt -= pos; + curr_window_line++; + currln++; + } + redraw_everything = YEA; + } +} + +static void insert_char(int ch) { + register textline_t *p = currline; + register int i = p->len; + register char *s; + int wordwrap = YEA; + + if(currpnt > i) { + indigestion(1); + return; + } + if(currpnt < i && !insert_character) { + p->data[currpnt++] = ch; + /* Thor: ansi 編輯, 可以overwrite, 不蓋到 ansi code */ + if(my_ansimode) + currpnt = ansi2n(n2ansi(currpnt, p),p); + } else { + while(i >= currpnt) { + p->data[i + 1] = p->data[i]; + i--; + } + p->data[currpnt++] = ch; + i = ++(p->len); + } + if(i < WRAPMARGIN) + return; + s = p->data + (i - 1); + while(s != p->data && *s == ' ') + s--; + while(s != p->data && *s != ' ') + s--; + if(s == p->data) { + wordwrap = NA; + s = p->data + (i - 2); + } + split(p, (s - p->data) + 1); + p = p->next; + i = p->len; + if(wordwrap && i >= 1) { + if(p->data[i - 1] != ' ') { + p->data[i] = ' '; + p->data[i + 1] = '\0'; + p->len++; + } + } +} + +static void insert_string(char *str) { + int ch; + + while((ch = *str++)) { + if(isprint2(ch) || ch == '\033') + insert_char(ch); + else if(ch == '\t') { + do { + insert_char(' '); + } while(currpnt & 0x7); + } else if(ch == '\n') + split(currline, currpnt); + } +} + +static int undelete_line() { + textline_t* p = deleted_lines; + textline_t* currline0 = currline; + textline_t* top_of_win0 = top_of_win; + int currpnt0 = currpnt; + int currln0 = currln; + int curr_window_line0 = curr_window_line; + int indent_mode0 = indent_mode; + + if(!deleted_lines) + return 0; + + indent_mode = 0; + insert_string(deleted_lines->data); + indent_mode = indent_mode0; + deleted_lines = deleted_lines->prev; + free(p); + + currline = currline0; + top_of_win = top_of_win0; + currpnt = currpnt0; + currln = currln0; + curr_window_line = curr_window_line0; + return 0; +} + +/* + 1) lines were joined and one was deleted + 2) lines could not be joined + 3) next line is empty + returns false if: + 1) Some of the joined line wrapped +*/ +static int join(textline_t *line) { + register textline_t *n; + register int ovfl; + + if(!(n = line->next)) + return YEA; + if(!*killsp(n->data)) + return YEA; + + ovfl = line->len + n->len - WRAPMARGIN; + if(ovfl < 0) { + strcat(line->data, n->data); + line->len += n->len; + delete_line(n); + return YEA; + } else { + register char *s; + + s = n->data + n->len - ovfl - 1; + while(s != n->data && *s == ' ') + s--; + while(s != n->data && *s != ' ') + s--; + if(s == n->data) + return YEA; + split(n, (s - n->data) + 1); + if(line->len + n->len >= WRAPMARGIN) { + indigestion(0); + return YEA; + } + join(line); + n = line->next; + ovfl = n->len - 1; + if(ovfl >= 0 && ovfl < WRAPMARGIN - 2) { + s = &(n->data[ovfl]); + if(*s != ' ') { + strcpy(s, " "); + n->len++; + } + } + return NA; + } +} + +static void delete_char() { + register int len; + + if((len = currline->len)) { + register int i; + register char *s; + + if(currpnt >= len) { + indigestion(1); + return; + } + for(i = currpnt, s = currline->data + i; i != len; i++, s++) + s[0] = s[1]; + currline->len--; + } +} + +static void load_file(FILE *fp) { + int indent_mode0 = indent_mode; + + indent_mode = 0; + while(fgets(line, WRAPMARGIN + 2, fp)) + insert_string(line); + fclose(fp); + indent_mode = indent_mode0; +} + +/* 暫存檔 */ +char *ask_tmpbuf(int y) { + static char fp_buf[10] = "buf.0"; + static char msg[] = "請選擇暫存檔 (0-9)[0]: "; + + msg[19] = fp_buf[4]; + do { + if(!getdata(y, 0, msg, fp_buf + 4, 4, DOECHO)) + fp_buf[4] = msg[19]; + } while(fp_buf[4] < '0' || fp_buf[4] > '9'); + return fp_buf; +} + +static void read_tmpbuf(int n) { + FILE *fp; + char fp_tmpbuf[80]; + char tmpfname[] = "buf.0"; + char *tmpf; + char ans[4] = "y"; + + if(0 <= n && n <= 9) { + tmpfname[4] = '0' + n; + tmpf = tmpfname; + } else { + tmpf = ask_tmpbuf(3); + n = tmpf[4] - '0'; + } + + setuserfile(fp_tmpbuf, tmpf); + if(n != 0 && n != 5 && more(fp_tmpbuf, NA) != -1) + getdata(b_lines - 1, 0, "確定讀入嗎(Y/N)?[Y]", ans, 4, LCECHO); + if(*ans != 'n' && (fp = fopen(fp_tmpbuf, "r"))) { + prevln = currln; + prevpnt = currpnt; + load_file(fp); + while(curr_window_line >= b_lines) { + curr_window_line--; + top_of_win = top_of_win->next; + } + } +} + +static void write_tmpbuf() { + FILE *fp; + char fp_tmpbuf[80], ans[4]; + textline_t *p; + + setuserfile(fp_tmpbuf, ask_tmpbuf(3)); + if(dashf(fp_tmpbuf)) { + more(fp_tmpbuf, NA); + getdata(b_lines - 1, 0, "暫存檔已有資料 (A)附加 (W)覆寫 (Q)取消?[A] ", + ans, 4, LCECHO); + + if(ans[0] == 'q') + return; + } + + if((fp = fopen(fp_tmpbuf, (ans[0] == 'w' ? "w" : "a+")))) { + for(p = firstline; p; p = p->next) { + if(p->next || p->data[0]) + fprintf(fp, "%s\n", p->data); + } + fclose(fp); + } +} + +static void erase_tmpbuf() { + char fp_tmpbuf[80]; + char ans[4] = "n"; + + setuserfile(fp_tmpbuf, ask_tmpbuf(3)); + if(more(fp_tmpbuf, NA) != -1) + getdata(b_lines - 1, 0, "確定刪除嗎(Y/N)?[N]", ans, 4, LCECHO); + if(*ans == 'y') + unlink(fp_tmpbuf); +} + +/* 編輯器自動備份 */ +void auto_backup() { + if(currline) { + FILE *fp; + textline_t *p, *v; + char bakfile[64]; + int count = 0; + + setuserfile(bakfile, fp_bak); + if((fp = fopen(bakfile, "w"))) { + for(p = firstline; p != NULL && count < 512; p = v,count++) { + v = p->next; + fprintf(fp, "%s\n", p->data); + free(p); + } + fclose(fp); + } + currline = NULL; + } +} + +void restore_backup() { + char bakfile[80], buf[80]; + + setuserfile(bakfile, fp_bak); + if(dashf(bakfile)) { + stand_title("編輯器自動復原"); + getdata(1, 0, "您有一篇文章尚未完成,(S)寫入暫存檔 (Q)算了?[S] ", + buf, 4, LCECHO); + if(buf[0] != 'q') { + setuserfile(buf, ask_tmpbuf(3)); + Rename(bakfile, buf); + } else + unlink(bakfile); + } +} + +/* 引用文章 */ +static int garbage_line(char *str) { + int qlevel = 0; + + while(*str == ':' || *str == '>') { + if(*(++str) == ' ') + str++; + if(qlevel++ >= 1) + return 1; + } + while(*str == ' ' || *str == '\t') + str++; + if(qlevel >= 1) { + if(!strncmp(str, "※ ", 3) || !strncmp(str, "==>", 3) || + strstr(str, ") 提到:\n")) + return 1; + } + return (*str == '\n'); +} + +static void do_quote() { + int op; + char buf[256]; + + getdata(b_lines - 1, 0, "請問要引用原文嗎(Y/N/All/Repost)?[Y] ", + buf, 3, LCECHO); + op = buf[0]; + + if(op != 'n') { + FILE *inf; + + if((inf = fopen(quote_file, "r"))) { + char *ptr; + int indent_mode0 = indent_mode; + + fgets(buf, 256, inf); + if((ptr = strrchr(buf, ')'))) + ptr[1] = '\0'; + else if((ptr = strrchr(buf, '\n'))) + ptr[0] = '\0'; + + if((ptr = strchr(buf, ':'))) { + char *str; + + while(*(++ptr) == ' '); + + /* 順手牽羊,取得 author's address */ + if((curredit & EDIT_BOTH) && (str = strchr(quote_user, '.'))) { + strcpy(++str, ptr); + str = strchr(str, ' '); + str[0] = '\0'; + } + } else + ptr = quote_user; + + indent_mode = 0; + insert_string("※ 引述《"); + insert_string(ptr); + insert_string("》之銘言:\n"); + + if(op != 'a') /* 去掉 header */ + while(fgets(buf, 256, inf) && buf[0] != '\n'); + + if(op == 'a') + while(fgets(buf, 256, inf)) { + insert_char(':'); + insert_char(' '); + insert_string(Ptt_prints(buf,STRIP_ALL)); + } + else if(op == 'r') + while(fgets(buf, 256, inf)) + insert_string(Ptt_prints(buf,NO_RELOAD)); + else { + if(curredit & EDIT_LIST) /* 去掉 mail list 之 header */ + while (fgets(buf, 256, inf) && (!strncmp(buf, "※ ", 3))); + while(fgets(buf, 256, inf)) { + if(!strcmp(buf, "--\n")) + break; + if(!garbage_line(buf)) { + insert_char(':'); + insert_char(' '); + insert_string(Ptt_prints(buf,STRIP_ALL)); + } + } + } + indent_mode = indent_mode0; + fclose(inf); + } + } +} + +/* 審查 user 引言的使用 */ +static int check_quote() { + register textline_t *p = firstline; + register char *str; + int post_line; + int included_line; + + post_line = included_line = 0; + while(p) { + if(!strcmp(str = p->data, "--")) + break; + if(str[1] == ' ' && ((str[0] == ':') || (str[0] == '>'))) + included_line++; + else { + while(*str == ' ' || *str == '\t') + str++; + if(*str) + post_line++; + } + p = p->next; + } + + if((included_line >> 2) > post_line) { + move(4, 0); + outs("本篇文章的引言比例超過 80%,請您做些微的修正:\n\n" + "\033[1;33m1) 增加一些文章 或 2) 刪除不必要之引言\033[m"); + { + char ans[4]; + + getdata(12, 12, "(E)繼續編輯 (W)強制寫入?[E] ", ans, 4, LCECHO); + if(ans[0] == 'w') + return 0; + } + return 1; + } + return 0; +} + +/* 檔案處理:讀檔、存檔、標題、簽名檔 */ +static void read_file(char *fpath) { + FILE *fp; + + if((fp = fopen(fpath, "r")) == NULL) { + if((fp = fopen(fpath, "w+"))) { + fclose(fp); + return; + } + indigestion(4); + abort_bbs(0); + } + load_file(fp); +} + +extern userec_t cuser; + +void write_header(FILE *fp) { + time_t now = time(0); + + if(curredit & EDIT_MAIL || curredit & EDIT_LIST) { + fprintf(fp, "%s %s (%s)\n", str_author1, cuser.userid, +#if defined(REALINFO) && defined(MAIL_REALNAMES) + cuser.realname +#else + cuser.username +#endif + ); + } else { + char *ptr; + struct { + char author[IDLEN + 1]; + char board[IDLEN + 1]; + char title[66]; + time_t date; /* last post's date */ + int number; /* post number */ + } postlog; + + strcpy(postlog.author, cuser.userid); + ifuseanony=0; +#ifdef HAVE_ANONYMOUS + if(currbrdattr& BRD_ANONYMOUS) { + int defanony = (currbrdattr & BRD_DEFAULTANONYMOUS); + if(defanony) + getdata(3, 0, "請輸入你想用的ID,也可直接按[Enter]," + "或是按[r]用真名:", real_name, 12, DOECHO); + else + getdata(3, 0, "請輸入你想用的ID,也可直接按[Enter]使用原ID:", + real_name, 12, DOECHO); + if(!real_name[0] && defanony) { + strcpy(real_name, "Anonymous"); + strcpy(postlog.author, real_name); + ifuseanony = 1; + } else { + if(!strcmp("r",real_name) || (!defanony && !real_name[0])) + sprintf(postlog.author,"%s",cuser.userid); + else { + sprintf(postlog.author,"%s.",real_name); + ifuseanony=1; + } + } + } +#endif + strcpy(postlog.board, currboard); + ptr = save_title; + if(!strncmp(ptr, str_reply, 4)) + ptr += 4; + strncpy(postlog.title, ptr, 65); + postlog.date = now; + postlog.number = 1; + append_record(".post", (fileheader_t *)&postlog, sizeof(postlog)); +#ifdef HAVE_ANONYMOUS + if(currbrdattr & BRD_ANONYMOUS) { + int defanony = (currbrdattr & BRD_DEFAULTANONYMOUS); + + fprintf(fp, "%s %s (%s) %s %s\n", str_author1, postlog.author , + (((!strcmp(real_name,"r") && defanony) || + (!real_name[0] && (!defanony))) ? cuser.username : + "猜猜我是誰 ? ^o^"), + local_article ? str_post2 : str_post1, currboard); + } else { + fprintf(fp, "%s %s (%s) %s %s\n", str_author1, cuser.userid, +#if defined(REALINFO) && defined(POSTS_REALNAMES) + cuser.realname, +#else + cuser.username, +#endif + local_article ? str_post2 : str_post1, currboard); + } +#else /* HAVE_ANONYMOUS */ + fprintf(fp, "%s %s (%s) %s %s\n", str_author1, cuser.userid, +#if defined(REALINFO) && defined(POSTS_REALNAMES) + cuser.realname, +#else + cuser.username, +#endif + local_article ? str_post2 : str_post1, currboard); +#endif /* HAVE_ANONYMOUS */ + + } + save_title[72] = '\0'; + fprintf(fp, "標題: %s\n時間: %s\n", save_title, ctime(&now)); +} + +void addsignature(FILE *fp, int ifuseanony) { + FILE *fs; + int i; + char buf[WRAPMARGIN + 1]; + char fpath[STRLEN]; + + static char msg[] = "請選擇簽名檔 (1-9, 0=不加)[0]: "; + char ch; + + if(!strcmp(cuser.userid,STR_GUEST)) { + fprintf(fp, "\n--\n※ 發信站 :" BBSNAME "(" MYHOSTNAME + ") \n◆ From: %s\n", fromhost); + return; + } + if(!ifuseanony) { + i = showsignature(fpath); + msg[27] = ch = '0' | (cuser.uflag & SIG_FLAG); + getdata(0, 0, msg, buf, 4, DOECHO); + + if(ch != buf[0] && buf[0] >= '0' && buf[0] <= '9') { + ch = buf[0]; + cuser.uflag = (cuser.uflag & ~SIG_FLAG) | (ch & SIG_FLAG); + } + + if(ch != '0') { + fpath[i] = ch; + if((fs = fopen(fpath, "r"))) { + fputs("\n--\n", fp); + for(i = 0; i < MAX_SIGLINES && + fgets(buf, sizeof(buf), fs); i++) + fputs(buf, fp); + fclose(fs); + } + } + } +#ifdef HAVE_ORIGIN +#ifdef HAVE_ANONYMOUS + if(ifuseanony) + fprintf(fp, "\n--\n※ 發信站: " BBSNAME "(" MYHOSTNAME + ") \n◆ From: %s\n", "暱名天使的家"); + else { + char temp[32]; + + strncpy(temp, fromhost, 31); + temp[32] = '\0'; + fprintf(fp, "\n--\n※ 發信站: " BBSNAME "(" MYHOSTNAME + ") \n◆ From: %s\n", temp); + } +#else + strncpy (temp,fromhost,15); + fprintf(fp, "\n--\n※ 發信站: " BBSNAME "(" MYHOSTNAME + ") \n◆ From: %s\n", temp); +#endif +#endif +} + +static int +write_file(char *fpath, int saveheader, int *islocal) { + time_t now; + struct tm *ptime; + FILE *fp = NULL; + textline_t *p, *v; + char ans[TTLEN], *msg; + int aborted = 0, line = 0, checksum[3], sum = 0, po = 1; + + stand_title("檔案處理"); + if(currstat == SMAIL) + msg = "[S]儲存 (A)放棄 (T)改標題 (E)繼續 (R/W/D)讀寫刪暫存檔?"; + else if(local_article) + msg = "[L]站內信件 (S)儲存 (A)放棄 (T)改標題 (E)繼續 " + "(R/W/D)讀寫刪暫存檔?"; + else + msg = "[S]儲存 (L)站內信件 (A)放棄 (T)改標題 (E)繼續 " + "(R/W/D)讀寫刪暫存檔?"; + getdata(1, 0, msg, ans, 3, LCECHO); + + switch(ans[0]) { + case 'a': + outs("文章\033[1m 沒有 \033[m存入"); + safe_sleep(1); + aborted = -1; + break; + case 'r': + read_tmpbuf(-1); + case 'e': + return KEEP_EDITING; + case 'w': + write_tmpbuf(); + return KEEP_EDITING; + case 'd': + erase_tmpbuf(); + return KEEP_EDITING; + case 't': + move(3, 0); + prints("舊標題:%s", save_title); + strcpy(ans,save_title); + if(getdata_buf(4, 0, "新標題:", ans, TTLEN, DOECHO)) + strcpy(save_title, ans); + return KEEP_EDITING; + case 's': + if(!HAS_PERM(PERM_LOGINOK)) { + local_article = 1; + move(2, 0); + prints("您尚未通過身份確認,只能 Local Save。\n"); + pressanykey(); + } else + local_article = 0; + break; + case 'l': + local_article = 1; + } + + if(!aborted) { + if(saveheader && !(curredit & EDIT_MAIL) && check_quote()) + return KEEP_EDITING; + + if(!*fpath) { + sethomepath(fpath, cuser.userid); + strcpy(fpath, tempnam(fpath, "ve_")); + } + + if((fp = fopen(fpath, "w")) == NULL) { + indigestion(5); + abort_bbs(0); + } + if(saveheader) + write_header(fp); + } + + for(p = firstline; p; p = v) { + v = p->next; + if(!aborted) { + msg = p->data; + if(v || msg[0]) { + trim(msg); + + line++; + if(currstat == POSTING && po) { + saveheader = str_checksum(msg); + if(saveheader) { + if(postrecord.checksum[po] == saveheader) { + po++; + if(po > 3) { + postrecord.times++; + po =0; + } + } else + po = 1; + if(currstat == POSTING && line >= totaln/2 && + sum < 3) { + checksum[sum++] = saveheader; + } + } + } +#ifdef SUPPORT_GB + if(current_font_type == TYPE_GB) + { + fprintf(fp, "%s\n", hc_convert_str(msg, HC_GBtoBIG, HC_DO_SINGLE)); + } + else +#endif + fprintf(fp, "%s\n", msg); + } + } + free(p); + } + currline = NULL; + + if(postrecord.times > MAX_CROSSNUM - 1) + anticrosspost(); + + if(po && sum == 3) { + memcpy(&postrecord.checksum[1], checksum, sizeof(int) * 3); + postrecord.times =0; + } + if(!aborted) { + if(islocal) + *islocal = (local_article == 1); + if(currstat == POSTING || currstat == SMAIL) + addsignature(fp,ifuseanony); + else if(currstat == REEDIT +#ifndef ALL_REEDIT_LOG + && strcmp(currboard, "SYSOP") == 0 +#endif + ) + { + time(&now); + ptime = localtime(&now); + fprintf(fp, + "※ 編輯: %-15s 來自: %-20s (%02d/%02d %02d:%02d)\n", + cuser.userid, fromhost, + ptime->tm_mon+1,ptime->tm_mday,ptime->tm_hour,ptime->tm_min); + } + + fclose(fp); + if(local_article && (currstat == POSTING)) + return 0; + return 0; + } + return aborted; +} + + +static void display_buffer() { + register textline_t *p; + register int i; + int inblock; + char buf[WRAPMARGIN + 2]; + int min, max; + + if(currpnt > blockpnt) { + min = blockpnt; + max = currpnt; + } else { + min = currpnt; + max = blockpnt; + } + + for(p = top_of_win, i = 0; i < b_lines; i++) { + move(i, 0); + clrtoeol(); + if(blockln >= 0 && + ((blockln <= currln && blockln <= (currln - curr_window_line + i) && + (currln - curr_window_line + i) <= currln) || + (currln <= (currln - curr_window_line + i) && + (currln - curr_window_line + i) <= blockln))) { + outs("\033[7m"); + inblock = 1; + } else + inblock = 0; + if(p) { + if(my_ansimode) + if(currln == blockln && p == currline && max > min) { + outs("\033[m"); + strncpy(buf, p->data, min); + buf[min] = 0; + outs(buf); + outs("\033[7m"); + strncpy(buf, p->data + min, max - min); + buf[max - min] = 0; + outs(buf); + outs("\033[m"); + outs(p->data + max); + } else + outs(p->data); + else if(currln == blockln && p == currline && max > min) { + outs("\033[m"); + strncpy(buf, p->data, min); + buf[min] = 0; + edit_outs(buf); + outs("\033[7m"); + strncpy(buf, p->data + min, max - min); + buf[max - min] = 0; + edit_outs(buf); + outs("\033[m"); + edit_outs(p->data + max); + } else + edit_outs(&p->data[edit_margin]); + p = p->next; + if(inblock) + outs("\033[m"); + } else + outch('~'); + } + edit_msg(); +} + +static void goto_line(int lino) { + char buf[10]; + + if(lino > 0 || + (getdata(b_lines - 1, 0, "跳至第幾行:", buf, 10, DOECHO) && + sscanf(buf, "%d", &lino) && lino > 0)) { + textline_t* p; + + prevln = currln; + prevpnt = currpnt; + p = firstline; + currln = lino - 1; + + while(--lino && p->next) + p = p->next; + + if(p) + currline = p; + else { + currln = totaln; + currline = lastline; + } + currpnt = 0; + if(currln < 11) { + top_of_win = firstline; + curr_window_line = currln; + } else { + int i; + + curr_window_line = 11; + for(i = curr_window_line; i; i--) + p = p->prev; + top_of_win = p; + } + } + redraw_everything = YEA; +} + +char *strcasestr(const char* big, const char* little) { + char* ans = (char*)big; + int len = strlen(little); + char* endptr = (char*)big + strlen(big) - len; + + while(ans <= endptr) + if(!strncasecmp(ans, little, len)) + return ans; + else + ans++; + return 0; +} + +/* + mode: + 0: prompt + 1: forward + -1: backward +*/ +static void search_str(int mode) { + static char str[80]; + typedef char* (*FPTR)(); + static FPTR fptr; + char ans[4] = "n"; + + if(!mode) { + if(getdata_buf(b_lines - 1, 0,"[搜尋]關鍵字:",str, 65, DOECHO)) + if(*str) { + if(getdata(b_lines - 1, 0, "區分大小寫(Y/N/Q)? [N] ", + ans, 4, LCECHO) && *ans == 'y') + fptr = strstr; + else + fptr = strcasestr; + } + } + + if(*str && *ans != 'q') { + textline_t* p; + char *pos = NULL; + int lino; + + if(mode >= 0) { + for(lino = currln, p = currline; p; p = p->next, lino++) + if((pos = fptr(p->data + (lino == currln ? currpnt + 1 : 0), + str)) && (lino != currln || + pos - p->data != currpnt)) + break; + } else { + for(lino = currln, p = currline; p; p = p->prev, lino--) + if((pos = fptr(p->data, str)) && + (lino != currln || pos - p->data != currpnt)) + break; + } + if(pos) { + prevln = currln; + prevpnt = currpnt; + currline = p; + currln = lino; + currpnt = pos - p->data; + if(lino < 11) { + top_of_win = firstline; + curr_window_line = currln; + } else { + int i; + + curr_window_line = 11; + for(i = curr_window_line; i; i--) + p = p->prev; + top_of_win = p; + } + redraw_everything = YEA; + } + } + if(!mode) + redraw_everything = YEA; +} + +static void match_paren() { + static char parens[] = "()[]{}"; + int type; + int parenum = 0; + char *ptype; + textline_t* p; + int lino; + int c, i = 0; + + if(!(ptype = strchr(parens, currline->data[currpnt]))) + return; + + type = (ptype - parens) / 2; + parenum += ((ptype - parens) % 2) ? -1 : 1; + + if(parenum > 0) { + for(lino = currln, p = currline; p; p = p->next, lino++) { + lino = lino; + for(i = (lino == currln) ? currpnt + 1 : 0; + i < strlen(p->data); i++) + if(p->data[i] == '/' && p->data[++i] == '*') { + ++i; + while(1) { + while(i < strlen(p->data) - 1 && + !(p->data[i] == '*' && p->data[i + 1] == '/')) + i++; + if(i >= strlen(p->data) - 1 && p->next) { + p = p->next; + ++lino; + i = 0; + } else + break; + } + } else if((c = p->data[i]) == '\'' || c == '"') { + while(1) { + while(i < (int)(strlen(p->data) - 1)) + if(p->data[++i] == '\\' && i < strlen(p->data) - 2) + ++i; + else if(p->data[i] == c) + goto end_quote; + if(i >= strlen(p->data) - 1 && p->next) { + p = p->next; + ++lino; + i = -1; + } else + break; + } +end_quote: + ; + } else if((ptype = strchr(parens, p->data[i])) && + (ptype - parens) / 2 == type) + if(!(parenum += ((ptype - parens) % 2) ? -1 : 1)) + goto p_outscan; + } + } else { + for(lino = currln, p = currline; p; p = p->prev, lino--) + for(i = (lino == currln) ? currpnt - 1 : strlen(p->data) - 1; + i >= 0; i--) + if(p->data[i] == '/' && p->data[--i] == '*' && i > 0) { + --i; + while(1) { + while(i > 0 && + !(p->data[i] == '*' && p->data[i - 1] == '/')) + i--; + if(i <= 0 && p->prev) { + p = p->prev; + --lino; + i = strlen(p->data) - 1; + } else + break; + } + } else if((c = p->data[i]) == '\'' || c == '"') { + while(1) { + while(i > 0) + if(i > 1 && p->data[i - 2] == '\\') + i -= 2; + else if((p->data[--i]) == c) + goto begin_quote; + if(i <= 0 && p->prev) { + p = p->prev; + --lino; + i = strlen(p->data); + } else + break; + } +begin_quote: + ; + } else if((ptype = strchr(parens, p->data[i])) && + (ptype - parens) / 2 == type) + if(!(parenum += ((ptype - parens) % 2) ? -1 : 1)) + goto p_outscan; + } +p_outscan: + if(!parenum) { + int top = currln - curr_window_line; + int bottom = currln - curr_window_line + b_lines - 1; + + currpnt = i; + currline = p; + curr_window_line += lino - currln; + currln = lino; + + if(lino < top || lino > bottom) { + if(lino < 11) { + top_of_win = firstline; + curr_window_line = currln; + } else { + int i; + + curr_window_line = 11; + for(i = curr_window_line; i; i--) + p = p->prev; + top_of_win = p; + } + redraw_everything = YEA; + } + } +} + +static void block_del(int hide) { + if(blockln < 0) { + blockln = currln; + blockpnt = currpnt; + blockline = currline; + } else { + char fp_tmpbuf[80]; + FILE* fp; + textline_t *begin, *end, *p; + char tmpfname[10] = "buf.0"; + char ans[6] = "w+n"; + + move(b_lines - 1, 0); + clrtoeol(); + if(hide == 1) + tmpfname[4] = 'q'; + else if(!hide && !getdata(b_lines - 1, 0, "把區塊移至暫存檔 " + "(0:Cut, 5:Copy, 6-9, q: Cancel)[0] ", + tmpfname + 4, 4, LCECHO)) + tmpfname[4] = '0'; + if(tmpfname[4] < '0' || tmpfname[4] > '9') + tmpfname[4] = 'q'; + if('1' <= tmpfname[4] && tmpfname[4] <= '9') { + setuserfile(fp_tmpbuf, tmpfname); + if(tmpfname[4] != '5' && dashf(fp_tmpbuf)) { + more(fp_tmpbuf, NA); + getdata(b_lines - 1, 0, "暫存檔已有資料 (A)附加 (W)覆寫 " + "(Q)取消?[W] ", ans, 4, LCECHO); + if(*ans == 'q') + tmpfname[4] = 'q'; + else if(*ans != 'a') + *ans = 'w'; + } + if(tmpfname[4] != '5') { + getdata(b_lines - 1, 0, "刪除區塊(Y/N)?[N] ", + ans + 2, 4, LCECHO); + if(ans[2] != 'y') + ans[2] = 'n'; + } + } else if(hide != 3) + ans[2] = 'y'; + + tmpfname[5] = ans[1] = ans[3] = 0; + if(tmpfname[4] != 'q') { + if(currln >= blockln) { + begin = blockline; + end = currline; + if(ans[2] == 'y' && !(begin == end && currpnt != blockpnt)) { + curr_window_line -= (currln - blockln); + if(curr_window_line < 0) { + curr_window_line = 0; + if(end->next) + (top_of_win = end->next)->prev = begin->prev; + else + top_of_win = (lastline = begin->prev); + } + currln -= (currln - blockln); + } + } else { + begin = currline; + end = blockline; + } + if(ans[2] == 'y' && !(begin == end && currpnt != blockpnt)) { + if(begin->prev) + begin->prev->next = end->next; + else if(end->next) + top_of_win = firstline = end->next; + else { + currline = top_of_win = firstline = + lastline = alloc_line(); + currln = curr_window_line = edit_margin = 0; + } + + if(end->next) + (currline = end->next)->prev = begin->prev; + else if(begin->prev) { + currline = (lastline = begin->prev); + currln--; + if(curr_window_line > 0) + curr_window_line--; + } + } + + setuserfile(fp_tmpbuf, tmpfname); + if((fp = fopen(fp_tmpbuf, ans))) { + if(begin == end && currpnt != blockpnt) { + char buf[WRAPMARGIN + 2]; + + if(currpnt > blockpnt) { + strcpy(buf, begin->data + blockpnt); + buf[currpnt - blockpnt] = 0; + } else { + strcpy(buf, begin->data + currpnt); + buf[blockpnt - currpnt] = 0; + } + fputs(buf, fp); + } else { + for(p = begin; p != end; p = p->next) + fprintf(fp, "%s\n", p->data); + fprintf(fp, "%s\n", end->data); + } + fclose(fp); + } + + if(ans[2] == 'y') { + if(begin == end && currpnt != blockpnt) { + int min, max; + + if(currpnt > blockpnt) { + min = blockpnt; + max = currpnt; + } else { + min = currpnt; + max = blockpnt; + } + strcpy(begin->data + min, begin->data + max); + begin->len -= max - min; + currpnt = min; + } else { + for(p = begin; p != end; totaln--) + free((p = p->next)->prev); + free(end); + totaln--; + currpnt = 0; + } + } + } + blockln = -1; + redraw_everything = YEA; + } +} + +static void block_shift_left() { + textline_t *begin, *end, *p; + + if(currln >= blockln) { + begin = blockline; + end = currline; + } else { + begin = currline; + end = blockline; + } + p = begin; + while(1) { + if(p->len) { + strcpy(p->data, p->data + 1); + --p->len; + } + if(p == end) + break; + else + p = p->next; + } + if(currpnt > currline->len) + currpnt = currline->len; + redraw_everything = YEA; +} + +static void block_shift_right() { + textline_t *begin, *end, *p; + + if(currln >= blockln) { + begin = blockline; + end = currline; + } else { + begin = currline; + end = blockline; + } + p = begin; + while(1) { + if(p->len < WRAPMARGIN) { + int i = p->len + 1; + + while(i--) + p->data[i + 1] = p->data[i]; + p->data[0] = insert_character ? ' ' : insert_c; + ++p->len; + } + if(p == end) + break; + else + p = p->next; + } + if(currpnt > currline->len) + currpnt = currline->len; + redraw_everything = YEA; +} + +static void transform_to_color(char* line) { + while(line[0] && line[1]) + if(line[0] == '*' && line[1] == '[') { + line[0] = KEY_ESC; + line += 2; + } else + ++line; +} + +static void block_color() { + textline_t *begin, *end, *p; + + if(currln >= blockln) { + begin = blockline; + end = currline; + } else { + begin = currline; + end = blockline; + } + p = begin; + while(1) { + transform_to_color(p->data); + if(p == end) + break; + else + p = p->next; + } + block_del(1); +} + +/* 編輯處理:主程式、鍵盤處理 */ +int vedit(char *fpath, int saveheader, int *islocal) { + FILE *fp1; + char last = 0, buf[200]; /* the last key you press */ + int ch, foo; + int lastindent = -1; + int last_margin; + int mode0 = currutmp->mode; + int destuid0 = currutmp->destuid; + unsigned int money=0; + unsigned short int interval=0; + time_t now=0,th; + + textline_t* firstline0 = firstline; + textline_t* lastline0 = lastline; + textline_t* currline0 = currline; + textline_t* blockline0 = blockline; + textline_t* top_of_win0 = top_of_win; + int local_article0 = local_article; + int currpnt0 = currpnt; + int currln0 = currln; + int totaln0 = totaln; + int curr_window_line0 = curr_window_line; + int insert_character0 = insert_character; + int my_ansimode0 = my_ansimode; + int edit_margin0 = edit_margin; + int blockln0 = blockln, count=0, tin=0; + + currutmp->mode = EDITING; + currutmp->destuid = currstat; + insert_character = redraw_everything = 1; + prevln = blockln = -1; + + line_dirty = currpnt = totaln = my_ansimode = 0; + currline = top_of_win = firstline = lastline = alloc_line(); + + if(*fpath) + read_file(fpath); + + if(*quote_file) { + do_quote(); + *quote_file = '\0'; + if(quote_file[79] == 'L') + local_article = 1; + } + + currline = firstline; + currpnt = currln = curr_window_line = edit_margin = last_margin = 0; + + while(1) { + if(redraw_everything || blockln >= 0) { + display_buffer(); + redraw_everything = NA; + } + if(my_ansimode) + ch = n2ansi(currpnt, currline); + else + ch = currpnt - edit_margin; + move(curr_window_line, ch); + if(!line_dirty && strcmp(line, currline->data)) + strcpy(line, currline->data); + ch = igetkey(); + /* jochang debug */ + if((interval = (unsigned short int)((th = currutmp->lastact) - now))) { + now = th; + if((char)ch != last) { + money++; + last = (char)ch; + } + } + if(interval && interval == tin) + count++; + else + { + count=0; + tin = interval; + } + /* 連續240個interval一樣 , 分明是在斂財 */ + if(count >= 240) { + sprintf(buf, "\033[1;33;46m%s\033[37m在\033[37;45m%s" + "\033[37m板違法賺錢 , %s\033[m", cuser.userid, + currboard,ctime(&now)); + log_file ("etc/illegal_money",buf); + money = 0 ; + post_violatelaw(cuser.userid, "Ptt 系統警察", "違法賺錢", "扣除不法所得"); + mail_violatelaw(cuser.userid, "Ptt 系統警察", "違法賺錢", "扣除不法所得"); +// demoney(10000); +// abort_bbs(0); + } + + if(raw_mode) + switch (ch) { + case Ctrl('S'): + case Ctrl('Q'): + case Ctrl('T'): + continue; + break; + } + if(ch < 0x100 && isprint2(ch)) { + insert_char(ch); + lastindent = -1; + line_dirty = 1; + } else { + if(ch == Ctrl('P') || ch == KEY_UP || ch == KEY_DOWN || + ch == Ctrl('N')) { + if(lastindent == -1) + lastindent = currpnt; + } else + lastindent = -1; + if(ch == KEY_ESC) + switch(KEY_ESC_arg) { + case ',': + ch = Ctrl(']'); + break; + case '.': + ch = Ctrl('T'); + break; + case 'v': + ch = KEY_PGUP; + break; + case 'a': + case 'A': + ch = Ctrl('V'); + break; + case 'X': + ch = Ctrl('X'); + break; + case 'q': + ch = Ctrl('Q'); + break; + case 'o': + ch = Ctrl('O'); + break; + case '-': + ch = Ctrl('_'); + break; + case 's': + ch = Ctrl('S'); + break; + } + + switch(ch) { + case Ctrl('X'): /* Save and exit */ + foo = write_file(fpath, saveheader, islocal); + if(foo != KEEP_EDITING) { + currutmp->mode = mode0; + currutmp->destuid = destuid0; + firstline = firstline0; + lastline = lastline0; + currline = currline0; + blockline = blockline0; + top_of_win = top_of_win0; + local_article = local_article0; + currpnt = currpnt0; + currln = currln0; + totaln = totaln0; + curr_window_line = curr_window_line0; + insert_character = insert_character0; + my_ansimode = my_ansimode0; + edit_margin = edit_margin0; + blockln = blockln0; + if(!foo) + return money; + else + return foo; + } + line_dirty = 1; + redraw_everything = YEA; + break; + case Ctrl('W'): + if(blockln >= 0) + block_del(2); + line_dirty = 1; + break; + case Ctrl('Q'): /* Quit without saving */ + ch = ask("結束但不儲存 (Y/N)? [N]: "); + if(ch == 'y' || ch == 'Y') { + currutmp->mode = mode0; + currutmp->destuid = destuid0; + firstline = firstline0; + lastline = lastline0; + currline = currline0; + blockline = blockline0; + top_of_win = top_of_win0; + local_article = local_article0; + currpnt = currpnt0; + currln = currln0; + totaln = totaln0; + curr_window_line = curr_window_line0; + insert_character = insert_character0; + my_ansimode = my_ansimode0; + edit_margin = edit_margin0; + blockln = blockln0; + return -1; + } + line_dirty = 1; + redraw_everything = YEA; + break; + case Ctrl('C'): + ch = insert_character; + insert_character = redraw_everything = YEA; + if(!my_ansimode) + insert_string(reset_color); + else { + char ans[4]; + move(b_lines - 2, 55); + outs("\033[1;33;40mB\033[41mR\033[42mG\033[43mY\033[44mL" + "\033[45mP\033[46mC\033[47mW\033[m"); + if(getdata(b_lines - 1, 0, + "請輸入 亮度/前景/背景[正常白字黑底][0wb]:", + ans, 4, LCECHO)) { + char t[] = "BRGYLPCW"; + char color[15]; + char *tmp, *apos = ans; + int fg, bg; + + strcpy(color, "\033["); + if(isdigit(*apos)) { + sprintf(color, "%s%c", color, *(apos++)); + if(*apos) + sprintf(color, "%s;", color); + } + if(*apos) { + if((tmp = strchr(t, toupper(*(apos++))))) + fg = tmp - t + 30; + else + fg = 37; + sprintf(color, "%s%d", color, fg); + } + if(*apos) { + if((tmp = strchr(t, toupper(*(apos++))))) + bg = tmp - t + 40; + else + bg = 40; + sprintf(color, "%s;%d", color, bg); + } + sprintf(color, "%sm", color); + insert_string(color); + } else + insert_string(reset_color); + } + insert_character = ch; + line_dirty = 1; + break; + case KEY_ESC: + line_dirty = 0; + switch(KEY_ESC_arg) { + case 'U': + t_users(); + redraw_everything = YEA; + line_dirty = 1; + break; + case 'i': + t_idle(); + redraw_everything = YEA; + line_dirty = 1; + break; + case 'n': + search_str(1); + break; + case 'p': + search_str(-1); + break; + case 'L': + case 'J': + goto_line(0); + break; + case ']': + match_paren(); + break; + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + read_tmpbuf(KEY_ESC_arg - '0'); + redraw_everything = YEA; + break; + case 'l': /* block delete */ + case ' ': + block_del(0); + line_dirty = 1; + break; + case 'u': + if(blockln >= 0) + block_del(1); + line_dirty = 1; + break; + case 'c': + if(blockln >= 0) + block_del(3); + line_dirty = 1; + break; + case 'y': + undelete_line(); + break; + case 'R': + raw_mode ^= 1; + line_dirty = 1; + break; + case 'I': + indent_mode ^= 1; + line_dirty = 1; + break; + case 'j': + if(blockln >= 0) + block_shift_left(); + else if(currline->len) { + int currpnt0 = currpnt; + currpnt = 0; + delete_char(); + currpnt = (currpnt0 <= currline->len) ? currpnt0 : + currpnt0 - 1; + if(my_ansimode) + currpnt = ansi2n(n2ansi(currpnt, currline), + currline); + } + line_dirty = 1; + break; + case 'k': + if(blockln >= 0) + block_shift_right(); + else { + int currpnt0 = currpnt; + + currpnt = 0; + insert_char(' '); + currpnt = currpnt0; + } + line_dirty = 1; + break; + case 'f': + while(currpnt < currline->len && + isalnum(currline->data[++currpnt])); + while(currpnt < currline->len && + isspace(currline->data[++currpnt])); + line_dirty = 1; + break; + case 'b': + while(currpnt && isalnum(currline->data[--currpnt])); + while(currpnt && isspace(currline->data[--currpnt])); + line_dirty = 1; + break; + case 'd': + while(currpnt < currline->len) { + delete_char(); + if(!isalnum(currline->data[currpnt])) + break; + } + while(currpnt < currline->len) { + delete_char(); + if(!isspace(currline->data[currpnt])) + break; + } + line_dirty = 1; + break; + default: + line_dirty = 1; + } + break; + case Ctrl('_'): + if(strcmp(line, currline->data)) { + char buf[WRAPMARGIN]; + + strcpy(buf, currline->data); + strcpy(currline->data, line); + strcpy(line, buf); + currline->len = strlen(currline->data); + currpnt = 0; + line_dirty = 1; + } + break; + case Ctrl('S'): + search_str(0); + break; + case Ctrl('U'): + insert_char('\033'); + line_dirty = 1; + break; + case Ctrl('V'): /* Toggle ANSI color */ + my_ansimode ^= 1; + if(my_ansimode && blockln >= 0) + block_color(); + clear(); + redraw_everything = YEA; + line_dirty = 1; + break; + case Ctrl('I'): + do { + insert_char(' '); + } while(currpnt & 0x7); + line_dirty = 1; + break; + case '\r': + case '\n': + split(currline, currpnt); + line_dirty = 0; + break; + case Ctrl('G'): + { + unsigned int currstat0 = currstat; + setutmpmode(EDITEXP); + a_menu("編輯輔助器", "etc/editexp", + (HAS_PERM(PERM_SYSOP) ? SYSOP : NOBODY)); + currstat = currstat0; + } + if(trans_buffer[0]) { + if((fp1 = fopen(trans_buffer, "r"))) { + int indent_mode0 = indent_mode; + + indent_mode = 0; + prevln = currln; + prevpnt = currpnt; + while(fgets(line, WRAPMARGIN + 2, fp1)) { + if(!strncmp(line,"作者:",5) || + !strncmp(line,"標題:",5) || + !strncmp(line,"時間:",5)) + continue; + insert_string(line); + } + fclose(fp1); + indent_mode = indent_mode0; + while(curr_window_line >= b_lines) { + curr_window_line--; + top_of_win = top_of_win->next; + } + } + } + redraw_everything = YEA; + line_dirty = 1; + break; + case Ctrl('Z'): /* Help */ + more("etc/ve.hlp",YEA); + redraw_everything = YEA; + line_dirty = 1; + break; + case Ctrl('L'): + clear(); + redraw_everything = YEA; + line_dirty = 1; + break; + case KEY_LEFT: + if(currpnt) { + if(my_ansimode) + currpnt = n2ansi(currpnt, currline); + currpnt--; + if(my_ansimode) + currpnt = ansi2n(currpnt, currline); + line_dirty = 1; + } else if(currline->prev) { + curr_window_line--; + currln--; + currline = currline->prev; + currpnt = currline->len; + line_dirty = 0; + } + break; + case KEY_RIGHT: + if(currline->len != currpnt) { + if(my_ansimode) + currpnt = n2ansi(currpnt, currline); + currpnt++; + if(my_ansimode) + currpnt = ansi2n(currpnt, currline); + line_dirty = 1; + } else if(currline->next) { + currpnt = 0; + curr_window_line++; + currln++; + currline = currline->next; + line_dirty = 0; + } + break; + case KEY_UP: + case Ctrl('P'): + if(currline->prev) { + if(my_ansimode) + ch = n2ansi(currpnt,currline); + curr_window_line--; + currln--; + currline = currline->prev; + if(my_ansimode) + currpnt = ansi2n(ch , currline); + else + currpnt = (currline->len > lastindent) ? lastindent : + currline->len; + line_dirty = 0; + } + break; + case KEY_DOWN: + case Ctrl('N'): + if(currline->next) { + if(my_ansimode) + ch = n2ansi(currpnt,currline); + currline = currline->next; + curr_window_line++; + currln++; + if(my_ansimode) + currpnt = ansi2n(ch , currline); + else + currpnt = (currline->len > lastindent) ? lastindent : + currline->len; + line_dirty = 0; + } + break; + case Ctrl('B'): + case KEY_PGUP: + redraw_everything = currln; + top_of_win = back_line(top_of_win, 22); + currln = redraw_everything; + currline = back_line(currline, 22); + curr_window_line = getlineno(); + if(currpnt > currline->len) + currpnt = currline->len; + redraw_everything = YEA; + line_dirty = 0; + break; + case KEY_PGDN: + case Ctrl('F'): + redraw_everything = currln; + top_of_win = forward_line(top_of_win, 22); + currln = redraw_everything; + currline = forward_line(currline, 22); + curr_window_line = getlineno(); + if(currpnt > currline->len) + currpnt = currline->len; + redraw_everything = YEA; + line_dirty = 0; + break; + case KEY_END: + case Ctrl('E'): + currpnt = currline->len; + line_dirty = 1; + break; + case Ctrl(']'): /* start of file */ + prevln = currln; + prevpnt = currpnt; + currline = top_of_win = firstline; + currpnt = currln = curr_window_line = 0; + redraw_everything = YEA; + line_dirty = 0; + break; + case Ctrl('T'): /* tail of file */ + prevln = currln; + prevpnt = currpnt; + top_of_win = back_line(lastline, 23); + currline = lastline; + curr_window_line = getlineno(); + currln = totaln; + redraw_everything = YEA; + currpnt = 0; + line_dirty = 0; + break; + case KEY_HOME: + case Ctrl('A'): + currpnt = 0; + line_dirty = 1; + break; + case KEY_INS: /* Toggle insert/overwrite */ + case Ctrl('O'): + if(blockln >= 0 && insert_character) { + char ans[4]; + + getdata(b_lines - 1, 0, + "區塊微調右移插入字元(預設為空白字元)", + ans, 4, LCECHO); + insert_c = (*ans) ? *ans : ' '; + } + insert_character ^= 1; + line_dirty = 1; + break; + case Ctrl('H'): + case '\177': /* backspace */ + line_dirty = 1; + if(my_ansimode) { + my_ansimode = 0; + clear(); + redraw_everything = YEA; + } else { + if(currpnt == 0) { + textline_t *p; + + if(!currline->prev) + break; + line_dirty = 0; + curr_window_line--; + currln--; + currline = currline->prev; + currpnt = currline->len; + redraw_everything = YEA; + if(*killsp(currline->next->data) == '\0') { + delete_line(currline->next); + break; + } + p = currline; + while(!join(p)) { + p = p->next; + if(p == NULL) { + indigestion(2); + abort_bbs(0); + } + } + break; + } + currpnt--; + delete_char(); + } + break; + case Ctrl('D'): + case KEY_DEL: /* delete current character */ + line_dirty = 1; + if(currline->len == currpnt) { + textline_t *p = currline; + + while(!join(p)) { + p = p->next; + if(p == NULL) { + indigestion(2); + abort_bbs(0); + } + } + line_dirty = 0; + redraw_everything = YEA; + } else { + delete_char(); + if(my_ansimode) + currpnt = ansi2n(n2ansi(currpnt, currline), currline); + } + break; + case Ctrl('Y'): /* delete current line */ + currline->len = currpnt = 0; + case Ctrl('K'): /* delete to end of line */ + if(currline->len == 0) { + textline_t *p = currline->next; + if(!p) { + p = currline->prev; + if(!p) + break; + if(curr_window_line > 0) { + curr_window_line--; + currln--; + } + } + if(currline == top_of_win) + top_of_win = p; + delete_line(currline); + currline = p; + redraw_everything = YEA; + line_dirty = 0; + break; + } + if(currline->len == currpnt) { + textline_t *p = currline; + + while(!join(p)) { + p = p->next; + if(p == NULL) { + indigestion(2); + abort_bbs(0); + } + } + redraw_everything = YEA; + line_dirty = 0; + break; + } + currline->len = currpnt; + currline->data[currpnt] = '\0'; + line_dirty = 1; + break; + } + if(currln < 0) + currln = 0; + if(curr_window_line < 0) { + curr_window_line = 0; + if(!top_of_win->prev) + indigestion(6); + else { + top_of_win = top_of_win->prev; + rscroll(); + } + } + if(curr_window_line == b_lines) { + curr_window_line = t_lines - 2; + if(!top_of_win->next) + indigestion(7); + else { + top_of_win = top_of_win->next; + move(b_lines, 0); + clrtoeol(); + scroll(); + } + } + } + edit_margin = currpnt < SCR_WIDTH - 1 ? 0 : currpnt / 72 * 72; + + if(!redraw_everything) { + if(edit_margin != last_margin) { + last_margin = edit_margin; + redraw_everything = YEA; + } else { + move(curr_window_line, 0); + clrtoeol(); + if(my_ansimode) + outs(currline->data); + else + edit_outs(&currline->data[edit_margin]); + edit_msg(); + } + } + } +} diff --git a/pttbbs/mbbsd/friend.c b/pttbbs/mbbsd/friend.c new file mode 100644 index 00000000..3d2167ae --- /dev/null +++ b/pttbbs/mbbsd/friend.c @@ -0,0 +1,509 @@ +/* $Id: friend.c,v 1.1 2002/03/07 15:13:48 in2 Exp $ */ +#include +#include +#include +#include +#include +#include +#include "config.h" +#include "pttstruct.h" +#include "common.h" +#include "perm.h" +#include "proto.h" + +extern char currboard[]; /* name of currently selected board */ +extern char *fn_overrides; +extern userinfo_t *currutmp; +extern char *fn_reject; +extern int usernum; +extern char *str_space; +extern char *msg_uid; + +/* ------------------------------------- */ +/* 特別名單 */ +/* ------------------------------------- */ + +/* Ptt 其他特別名單的檔名 */ +static char special_list[] = "list.0"; +static char special_des[] = "ldes.0"; + +/* 特別名單的上限 */ +static unsigned int friend_max[8] = { + MAX_FRIEND, + MAX_REJECT, + MAX_LOGIN_INFO, + MAX_POST_INFO, + MAX_NAMELIST, + MAX_NAMELIST, + MAX_NAMELIST, + MAX_NAMELIST +}; +/* 雖然好友跟壞人名單都是 * 2 但是一次最多load到shm只能有128 */ + +/* Ptt 各種特別名單的檔名 */ +char *friend_file[8] = { + FN_OVERRIDES, + FN_REJECT, + "alohaed", + "postlist", + "", + FN_CANVOTE, + FN_WATER, + FN_VISABLE +}; + +/* Ptt 各種特別名單的補述 */ +static char *friend_desc[8] = { + "友誼描述:", + "惡形惡狀:", + "", + "", + "描述一下:", + "投票者描述:", + "惡形惡狀:", + "看板好友描述" +}; + +/* Ptt 各種特別名單的中文敘述 */ +static char *friend_list[8] = { + "好友名單", + "壞人名單", + "上線通知", + "新文章通知", + "其它特別名單", + "私人投票名單", + "看板禁聲名單", + "看板好友名單" +}; + +static void setfriendfile(char *fpath, int type) { + if (type <= 4) /* user list Ptt */ + setuserfile(fpath, friend_file[type]); + else /* board list */ + setbfile(fpath, currboard, friend_file[type]); +} + +static int friend_count(char *fname) { + FILE *fp; + int count = 0; + char buf[200]; + +#if 0 + if ((fp = fopen(fname, "r"))) + while (fgets(buf, 200, fp)) + count++; +#endif + +/*rocker.011018: 忘記關檔了... */ + if ((fp = fopen(fname, "r"))) + { + while (fgets(buf, 200, fp)) count++; + fclose (fp); + } + + return count; +} + +void friend_add(char *uident, int type) { + char fpath[80]; + + setfriendfile(fpath, type); + if (friend_count(fpath) > friend_max[type]) + return; + + if ((uident[0] > ' ') && !belong(fpath, uident)) + { + FILE *fp; + char buf[40] = ""; + char t_uident[IDLEN + 1]; + + /* Thor: avoid uident run away when get data */ + strcpy(t_uident, uident); + + if (type != FRIEND_ALOHA && type != FRIEND_POST) + getdata(2, 0, friend_desc[type], buf, 40, DOECHO); + + if ((fp = fopen(fpath, "a"))) + { + flock(fileno(fp), LOCK_EX); + fprintf(fp, "%-13s%s\n", t_uident, buf); + flock(fileno(fp), LOCK_UN); + fclose(fp); + } + } +} + +static void friend_special() { + char genbuf[70], i, fname[70]; + + friend_file[FRIEND_SPECIAL] = special_list; + for (i = 0; i <= 9; i++) + { + sprintf(genbuf, " (\033[36m%d\033[m) .. ", i); + special_des[5] = i + '0'; + setuserfile(fname, special_des); + if (dashf(fname)) + { + /* no NULL check?? */ + FILE *fp = fopen(fname, "r"); + + fgets(genbuf + 15, 40, fp); + genbuf[47] = 0; + } + move(i + 12, 0); + clrtoeol(); + outs(genbuf); + } + getdata(22, 0, "請選擇第幾號特別名單 (0~9)[0]?", genbuf, 3, LCECHO); + if (genbuf[0] >= '0' && genbuf[0] <= '9') + { + special_list[5] = genbuf[0]; + special_des[5] = genbuf[0]; + } + else + { + special_list[5] = '0'; + special_des[5] = '0'; + } +} + +static void friend_append(int type, int count) { + char fpath[80], i, j, buf[80], sfile[80]; + FILE *fp, *fp1; + + setfriendfile(fpath, type); + + do + { + move(2, 0); + clrtobot(); + outs("要引入哪一個名單?\n"); + for (i = 0, j = 0; i <= 7; i++) + { + if (i == type) + continue; + j++; + if (i <= 4) + sprintf(buf, " (%d) %-s\n", j, friend_list[(int) i]); + else + sprintf(buf, " (%d) %s 版的 %s\n", j, currboard, + friend_list[(int) i]); + outs(buf); + } + outs(" (S) 選擇其他看板的特別名單"); + getdata(11, 0, "請選擇 或 直接[Enter] 放棄:", buf, 3, LCECHO); + if (!buf[0]) + return; + if (buf[0] == 's') + Select(); + } + while (buf[0] < '1' || buf[0] > '9'); + + j = buf[0] - '1'; + if (j >= type) + j++; + if (j == FRIEND_SPECIAL) + friend_special(); + + setfriendfile(sfile, j); + + fp = fopen(sfile, "r"); + while (fgets(buf, 80, fp) && count <= friend_max[type]) + { + char the_id[15]; + + sscanf(buf, "%s", the_id); + if (!belong(fpath, the_id)) + { + if ((fp1 = fopen(fpath, "a"))) + { + flock(fileno(fp1), LOCK_EX); + fputs(buf, fp1); + flock(fileno(fp1), LOCK_UN); + fclose(fp1); + } + } + } + fclose(fp); +} + +void friend_delete(char *uident, int type) { + FILE *fp, *nfp; + char fn[80], fnnew[80]; + char genbuf[200]; + + setfriendfile(fn, type); + + sprintf(fnnew, "%s-", fn); + if ((fp = fopen(fn, "r")) && (nfp = fopen(fnnew, "w"))) + { + int length = strlen(uident); + + while (fgets(genbuf, STRLEN, fp)) + if ((genbuf[0] > ' ') && strncmp(genbuf, uident, length)) + fputs(genbuf, nfp); + fclose(fp); + fclose(nfp); + Rename(fnnew, fn); + } +} + +static void friend_editdesc(char *uident, int type) { + FILE *fp, *nfp; + char fnnew[200], genbuf[200], fn[200]; + setfriendfile(fn, type); + sprintf(fnnew, "%s-", fn); + if ((fp = fopen(fn, "r")) && (nfp = fopen(fnnew, "w"))) + { + int length = strlen(uident); + + while (fgets(genbuf, STRLEN, fp)) + { + if ((genbuf[0] > ' ') && strncmp(genbuf, uident, length)) + fputs(genbuf, nfp); + else if (!strncmp(genbuf, uident, length)) + { + char buf[50] = ""; + getdata(2, 0, "修改描述:", buf, 40, DOECHO); + fprintf(nfp, "%-13s%s\n", uident, buf); + } + } + fclose(fp); + fclose(nfp); + Rename(fnnew, fn); + } +} + +void friend_load() { + FILE *fp; + int myfriends[MAX_FRIEND]; + int myrejects[MAX_REJECT]; + int friendcount, rejectedcount; + char genbuf[200]; + + memset(myfriends, 0, sizeof(myfriends)); + friendcount = 0; + setuserfile(genbuf, fn_overrides); + if ((fp = fopen(genbuf, "r"))) + { + int unum; + + while (fgets(genbuf, STRLEN, fp) && friendcount < MAX_FRIEND - 1) + if (strtok(genbuf, str_space)) + if ((unum = searchuser(genbuf))) + myfriends[friendcount++] = unum; + fclose(fp); + } + memcpy(currutmp->friend, myfriends, sizeof(myfriends)); + + memset(myrejects, 0, sizeof(myrejects)); + rejectedcount = 0; + setuserfile(genbuf, fn_reject); + if ((fp = fopen(genbuf, "r"))) + { + int unum; + + while (fgets(genbuf, STRLEN, fp) && rejectedcount < MAX_REJECT - 1) + if (strtok(genbuf, str_space)) + if ((unum = searchuser(genbuf))) + myrejects[rejectedcount++] = unum; + fclose(fp); + } + memcpy(currutmp->reject, myrejects, sizeof(myrejects)); + if(currutmp->friendtotal) logout_friend_online(); + login_friend_online(); +} + +extern userec_t cuser; + +static void friend_water(char *message, int type) { /* 群體水球 added by Ptt */ + char fpath[80], line[80], userid[IDLEN + 1]; + FILE *fp; + + setfriendfile(fpath, type); + if ((fp = fopen(fpath, "r"))) + while(fgets(line, 80, fp)) { + userinfo_t *uentp; + int tuid; + + sscanf(line, "%s", userid); + if((tuid = searchuser(userid)) && tuid != usernum && + (uentp = (userinfo_t *) search_ulist(tuid)) && + isvisible_uid(tuid)) + my_write(uentp->pid, message, uentp->userid, 1); + } + fclose(fp); +} + +void friend_edit(int type) { + char fpath[80], line[80], uident[20]; + int count, column, dirty; + FILE *fp; + char genbuf[200]; + + if (type == FRIEND_SPECIAL) + friend_special(); + setfriendfile(fpath, type); + + if (type == FRIEND_ALOHA || type == FRIEND_POST) + { + if (dashf(fpath)) + { + sprintf(genbuf, "/bin/cp %s %s.old", fpath, fpath); + system(genbuf); + } + } + + dirty = 0; + while (1) + { + stand_title(friend_list[type]); + move(0, 40); + sprintf(line, "(名單上限:%d個人)", friend_max[type]); + outs(line); + count = 0; + CreateNameList(); + + if ((fp = fopen(fpath, "r"))) + { + move(3, 0); + column = 0; + while (fgets(genbuf, STRLEN, fp)) + { + if (genbuf[0] <= ' ') + continue; + strtok(genbuf, str_space); + AddNameList(genbuf); + prints("%-13s", genbuf); + count++; + if (++column > 5) + { + column = 0; + outc('\n'); + } + } + fclose(fp); + } + getdata(1, 0, (count ? + "(A)增加(D)刪除(E)修改(P)引入(L)詳細列出" + "(K)刪除整個名單(W)丟水球(Q)結束?[Q]" : + "(A)增加 (P)引入其他名單 (Q)結束?[Q]"), + uident, 3, LCECHO); + if (*uident == 'a') + { + move(1, 0); + usercomplete(msg_uid, uident); + if (uident[0] && searchuser(uident) && !InNameList(uident)) + { + friend_add(uident, type); + dirty = 1; + } + } + else if (*uident == 'p') + { + friend_append(type, count); + dirty = 1; + } + else if (*uident == 'e' && count) + { + move(1, 0); + namecomplete(msg_uid, uident); + if (uident[0] && InNameList(uident)) + { + friend_editdesc(uident, type); + } + } + else if (*uident == 'd' && count) + { + move(1, 0); + namecomplete(msg_uid, uident); + if (uident[0] && InNameList(uident)) + { + friend_delete(uident, type); + dirty = 1; + } + } + else if (*uident == 'l' && count) + more(fpath, YEA); + else if (*uident == 'k' && count) + { + getdata(2, 0, "整份名單將會被刪除,您確定嗎 (a/N)?", uident, 3, + LCECHO); + if (*uident == 'a') + unlink(fpath); + dirty = 1; + } + else if (*uident == 'w' && count) + { + if (!getdata(0, 0, "群體水球:", uident, 60, DOECHO)) + continue; + if (getdata(0, 0, "確定丟出群體水球? [Y]", line, 4, LCECHO) && + *line == 'n') + continue; + friend_water(uident, type); + } + else + break; + } + if (dirty) + { + move(2, 0); + outs("更新資料中..請稍候....."); + refresh(); + if (type == FRIEND_ALOHA || type == FRIEND_POST) + { + sprintf(genbuf, "%s.old", fpath); + if ((fp = fopen(genbuf, "r"))) + { + while (fgets(line, 80, fp)) + { + sscanf(line, "%s", uident); + sethomefile(genbuf, uident, + type == FRIEND_ALOHA ? "aloha" : "postnotify"); + del_distinct(genbuf, cuser.userid); + } + fclose(fp); + } + sprintf(genbuf, "%s", fpath); + if ((fp = fopen(genbuf, "r"))) + { + while (fgets(line, 80, fp)) + { + sscanf(line, "%s", uident); + sethomefile(genbuf, uident, + type == FRIEND_ALOHA ? "aloha" : "postnotify"); + add_distinct(genbuf, cuser.userid); + } + fclose(fp); + } + } + else if (type == FRIEND_SPECIAL) + { + genbuf[0] = 0; + setuserfile(line, special_des); + if ((fp = fopen(line, "r"))) + { + fgets(genbuf, 30, fp); + fclose(fp); + } + getdata_buf(2, 0, " 請為此特別名單取一個簡短名稱:", genbuf, 30, + DOECHO); + if ((fp = fopen(line, "w"))) + { + fprintf(fp, "%s", genbuf); + fclose(fp); + } + } + friend_load(); + } +} + +int t_override() { + friend_edit(FRIEND_OVERRIDE); + return 0; +} + +int t_reject() { + friend_edit(FRIEND_REJECT); + return 0; +} diff --git a/pttbbs/mbbsd/gamble.c b/pttbbs/mbbsd/gamble.c new file mode 100644 index 00000000..23867450 --- /dev/null +++ b/pttbbs/mbbsd/gamble.c @@ -0,0 +1,361 @@ +/* $Id: gamble.c,v 1.1 2002/03/07 15:13:48 in2 Exp $ */ +#include +#include +#include +#include +#include +#include +#include "config.h" +#include "pttstruct.h" +#include "common.h" +#include "modes.h" +#include "proto.h" +extern int usernum; + +#ifndef _BBS_UTIL_C_ +extern userec_t cuser; +extern int b_lines; + +#define MAX_ITEM 8 //最大 賭項(item) 個數 +#define MAX_ITEM_LEN 30 //最大 每一賭項名字長度 +#define MAX_SUBJECT_LEN 650 //8*81 = 648 最大 主題長度 + +static char betname[MAX_ITEM][MAX_ITEM_LEN]; +static int currbid; + +int post_msg(char* bname, char* title, char *msg, char* author) +{ + FILE *fp; + int bid; + fileheader_t fhdr; + time_t now = time(0); + char genbuf[256]; + + /* 在 bname 版發表新文章 */ + sprintf(genbuf, "boards/%s", bname); + stampfile(genbuf, &fhdr); + fp = fopen(genbuf,"w"); + + if(!fp) + return -1; + + fprintf(fp, "作者: %s 看板: %s\n標題: %s \n",author,bname,title); + fprintf(fp, "時間: %s\n", ctime(&now)); + + /* 文章的內容 */ + fprintf(fp, "%s", msg); + fclose(fp); + + /* 將檔案加入列表 */ + strcpy(fhdr.title, title); + strcpy(fhdr.owner, author); + setbdir(genbuf,bname); + if(append_record(genbuf, &fhdr, sizeof(fhdr))!=-1) + if((bid = getbnum(bname)) > 0) + setbtotal(bid); + return 0; +} + +int post_file(char* bname, char* title, char *filename, char* author) +{ + int size=dashs(filename); + char *msg; + FILE *fp; + + if(size<=0) return -1; + if(!(fp=fopen(filename,"r")) ) return -1; + msg= (char *)malloc(size); + fread(msg,1,size,fp); + size= post_msg(bname, title, msg, author); + fclose(fp); + free(msg); + return size; +} + + +static int load_ticket_record(char *direct, int ticket[]) +{ + char buf[256]; + int i, total=0; + FILE *fp; + sprintf(buf,"%s/"FN_TICKET_RECORD,direct); + if(!(fp=fopen(buf,"r"))) return 0; + for(i=0;ibrdname); + showtitle(genbuf, BBSNAME); + } + else + showtitle("Ptt賭盤", BBSNAME); + move(2, 0); + sprintf(genbuf, "%s/"FN_TICKET_ITEMS, direct); + if(!(fp = fopen(genbuf,"r"))) + { + prints("\n目前並沒有舉辦賭盤\n"); + sprintf(genbuf, "%s/"FN_TICKET_OUTCOME, direct); + if(more(genbuf, NA)); + return 0; + } + fgets(genbuf,MAX_ITEM_LEN,fp); + *price=atoi(genbuf); + for(count=0; fgets(betname[count],MAX_ITEM_LEN,fp)&&countbrdname); + setbfile(fn_ticket, bh->brdname, FN_TICKET); + currbid = bid; + } + else + strcpy(path,"etc/"); + + lockreturn0(TICKET, LOCK_MULTI); + while(1) { + count=show_ticket_data(path, &price, bh); + if(count<=0) + { + pressanykey(); + break; + } + move(20, 0); + reload_money(); + prints("\033[44m錢: %-10d \033[m\n\033[1m請選擇要購買的種類(1~%d)" + "[Q:離開]\033[m:", cuser.money,count); + ch = igetch(); + /*-- + Tim011127 + 為了控制CS問題 但是這邊還不能完全解決這問題, + 若user通過檢查下去, 剛好版主開獎, 還是會造成user的這次紀錄 + 很有可能跑到下次賭盤的紀錄去, 也很有可能被版主新開賭盤時洗掉 + 不過這邊至少可以做到的是, 頂多只會有一筆資料是錯的 + --*/ + if(bid && !dashf(fn_ticket)) + { + move(b_lines-1,0); + prints("哇!! 耐ㄚ捏...版主已經停止下注了 不能賭嚕"); + pressanykey(); + break; + } + + if(ch=='q' || ch == 'Q') + break; + ch-='1'; + if(end || ch >= count || ch < 0) + continue; + n=0; + ch_buyitem(price, "etc/buyticket", &n); + if(n > 0) + append_ticket_record(path,ch,n,count); + } + unlockutmpmode(); + return 0; +} + +int openticket(int bid) { + char path[128],buf[256],outcome[128]; + int i, money=0, count, bet, price, total = 0, ticket[8]={0,0,0,0,0,0,0,0}; + boardheader_t *bh=getbcache(bid); + time_t now = time(NULL); + FILE *fp, *fp1; + + setbpath(path, bh->brdname); + count=-show_ticket_data(path, &price, bh); + if(count==0) + { + setbfile(buf,bh->brdname,FN_TICKET_END); + unlink(buf); //Ptt: 有bug + return 0; + } + lockreturn0(TICKET, LOCK_MULTI); + do + { + do + { + getdata(20, 0, "\033[1m選擇中獎的號碼(0:取消)\033[m:", buf, 3, LCECHO); + bet=atoi(buf); + move(0,0); + clrtoeol(); + } while(bet<0 || bet>count); + if(bet==0) + {unlockutmpmode(); return 0;} + getdata(21, 0, "\033[1m再次確認中獎的號碼\033[m:", buf, 3, LCECHO); + }while(bet!=atoi(buf)); + + bet -= 1; //轉成矩陣的index + + total=load_ticket_record(path, ticket); + setbfile(buf,bh->brdname,FN_TICKET_END); + if(!(fp1 = fopen(buf,"r"))) + { + unlockutmpmode(); + return 0; + } + // 還沒開完獎不能賭博 只要mv一項就好 + money=total*price; + demoney(money*0.02); + mail_redenvelop("[賭場抽頭]", cuser.userid, money*0.02, 'n'); + money = ticket[bet] ? money*0.95/ticket[bet]:9999999; + setbfile(outcome,bh->brdname,FN_TICKET_OUTCOME); + if((fp = fopen(outcome, "w"))) + { + fprintf(fp,"賭盤說明\n"); + while(fgets(buf,256,fp1)) + { + buf[255]=0; + fprintf(fp,"%s",buf); + } + fprintf(fp,"下注情況\n"); + + fprintf(fp, "\033[33m"); + for(i = 0 ; ibrdname, FN_TICKET_END); + unlink(buf); +/* + if(fork()) + { + more(outcome,YEA); + unlockutmpmode(); + return 0; + } +*/ + sprintf(buf, "[公告] %s 賭盤開獎", bh->brdname); + post_file(bh->brdname, buf, outcome, "[賭神]"); + post_file("Record", buf+7, outcome, "[馬路探子]"); + /* + 以下是給錢動作 + */ + setbfile(buf, bh->brdname, FN_TICKET_USER); + if (ticket[bet] && (fp = fopen(buf, "r"))) + { + int mybet, uid; + char userid[IDLEN]; + + while (fscanf(fp, "%s %d %d\n", userid, &mybet, &i) != EOF) + { + if (mybet == bet) + { + printf("恭喜 %-15s買了%9d 張 %s, 獲得 %d 枚P幣\n" + ,userid, i, betname[mybet], money * i); + if((uid=getuser(userid))==0) continue; + deumoney(uid, money * i); + sprintf(buf, "%s 中獎咧! $ %d", bh->brdname, money * i); + mail_id(userid, buf, outcome, "Ptt賭場"); + } + } + } + setbfile(buf, bh->brdname, FN_TICKET_RECORD); + unlink(buf); + setbfile(buf, bh->brdname, FN_TICKET_USER); + unlink(buf); + return 0; +} + +int ticket_main() { + ticket(0); + return 0; +} +#endif diff --git a/pttbbs/mbbsd/gomo.c b/pttbbs/mbbsd/gomo.c new file mode 100644 index 00000000..06062ce4 --- /dev/null +++ b/pttbbs/mbbsd/gomo.c @@ -0,0 +1,417 @@ +/* $Id: gomo.c,v 1.1 2002/03/07 15:13:48 in2 Exp $ */ +#include +#include +#include +#include +#include +#include +#include +#include "config.h" +#include "pttstruct.h" +#include "gomo.h" +#include "common.h" +#include "modes.h" +#include "proto.h" + +extern int usernum; +extern userinfo_t *currutmp; + +char ku[BRDSIZ][BRDSIZ]; +static char *chess[] = { "●", "○" }; +static int tick, lastcount, mylasttick, hislasttick; + +unsigned char *pat, *adv; + +typedef struct { + char x; + char y; +} Horder_t; + +static Horder_t *v, pool[225]; + +static void HO_init() { + memset(pool, 0, sizeof(pool)); + v = pool; + pat = pat_gomoku; + adv = adv_gomoku; + memset(ku, 0, sizeof(ku)); +} + +static void HO_add(Horder_t *mv) { + *v++ = *mv; +} + +static void HO_undo(Horder_t *mv) { + char *str = "┌┬┐├┼┤└┴┘"; + int n1, n2, loc; + + *mv = *(--v); + ku[(int)mv->x][(int)mv->y] = BBLANK; + BGOTO(mv->x, mv->y); + n1 = (mv->x == 0) ? 0 : (mv->x == 14) ? 2 : 1; + n2 = (mv->y == 14)? 0 : (mv->y == 0) ? 2 : 1; + loc= 2 * ( n2 * 3 + n1); + prints("%.2s", str + loc); +} + +extern userec_t cuser; + +static void HO_log(char *user) { + int i; + FILE *log; + char buf[80]; + char buf1[80]; + char title[80]; + Horder_t *ptr = pool; + extern screenline_t *big_picture; + fileheader_t mymail; + + sprintf(buf, "home/%c/%s/F.%d", cuser.userid[0], cuser.userid, + rand() & 65535); + log = fopen(buf, "w"); + + for(i = 1; i < 17; i++) + fprintf(log, "%.*s\n", big_picture[i].len, big_picture[i].data); + + i = 0; + do { + fprintf(log, "[%2d]%s ==> %c%d%c", i + 1, chess[i % 2], + 'A' + ptr->x, ptr->y + 1, (i % 2) ? '\n' : '\t'); + i++; + } while( ++ptr < v); + fclose(log); + + sethomepath(buf1, cuser.userid); + stampfile(buf1, &mymail); + + mymail.savemode = 'H'; /* hold-mail flag */ + mymail.filemode = FILE_READ; + strcpy(mymail.owner, "[備.忘.錄]"); + sprintf(mymail.title, "\033[37;41m棋譜\033[m %s VS %s", + cuser.userid, user); + sethomedir(title, cuser.userid); + Rename(buf, buf1); + append_record(title, &mymail, sizeof(mymail)); + + unlink(buf); +} + +static int countgomo() { + Horder_t *ptr; + int i; + + ptr = pool; + i = 0; + do { + i++; + } while(++ptr < v); + return i; +} + +static int chkmv(Horder_t *mv, int color, int limit) { + char *xtype[] = {"\033[1;31m跳三\033[m", "\033[1;31m活三\033[m", + "\033[1;31m死四\033[m", "\033[1;31m跳四\033[m", + "\033[1;31m活四\033[m", "\033[1;31m四三\033[m", + "\033[1;31m雙三\033[m", "\033[1;31m雙四\033[m", + "\033[1;31m雙四\033[m", "\033[1;31m連六\033[m", + "\033[1;31m連五\033[m"}; + int rule = getstyle(mv->x, mv->y, color, limit); + if(rule > 1 && rule < 13) { + move(15, 40); + outs(xtype[rule - 2]); + bell(); + } + return chkwin(rule, limit); +} + +static int gomo_key(int fd, int ch, Horder_t *mv) { + if( ch >= 'a' && ch <= 'o') { + char pbuf[4], vx, vy; + + *pbuf = ch; + if(fd) + add_io(0, 0); + oldgetdata(17, 0, "直接指定位置 :", pbuf, 4, DOECHO); + if(fd) + add_io(fd, 0); + vx = pbuf[0] - 'a'; + vy = atoi(pbuf + 1) - 1; + if(vx >= 0 && vx < 15 && vy >= 0 && vy < 15 && + ku[(int)vx][(int)vy] == BBLANK) { + mv->x = vx; + mv->y = vy; + return 1; + } + } else { + switch(ch) { + case KEY_RIGHT: + mv->x = (mv->x == BRDSIZ - 1) ? mv->x : mv->x + 1; + break; + case KEY_LEFT: + mv->x = (mv->x == 0 ) ? 0 : mv->x - 1; + break; + case KEY_UP: + mv->y = (mv->y == BRDSIZ - 1) ? mv->y : mv->y + 1; + break; + case KEY_DOWN: + mv->y = (mv->y == 0 ) ? 0 : mv->y - 1; + break; + case ' ': + case '\r': + if(ku[(int)mv->x][(int)mv->y] == BBLANK) + return 1; + } + } + return 0; +} + +extern userec_t xuser; + +static int reload_gomo() { + passwd_query(usernum, &xuser); + cuser.five_win = xuser.five_win; + cuser.five_lose = xuser.five_lose; + cuser.five_tie = xuser.five_tie; + return 0; +} + +int gomoku(int fd) { + Horder_t mv; + int me, he, win, ch; + int hewantpass, iwantpass; + userinfo_t *my = currutmp; + + HO_init(); + me = !(my->turn) + 1; + he = my->turn + 1; + win = 1; + tick=time(0) + MAX_TIME; + lastcount = MAX_TIME; + setutmpmode(M_FIVE); + clear(); + + prints("\033[1;46m 五子棋對戰 \033[45m%30s VS %-30s\033[m", + cuser.userid, my->mateid); + show_file("etc/@five", 1, -1, ONLY_COLOR); + move(11, 40); + prints("我是 %s", me == BBLACK ? "先手 ●, 有禁手" : "後手 ○"); + move(16, 40); + prints("\033[1;33m%s", cuser.userid); + move(17, 40); + prints("\033[1;33m%s", my->mateid); + + reload_gomo(); + move(16, 60); + prints("\033[1;31m%d\033[37m勝 \033[34m%d\033[37m敗 \033[36m%d\033[37m和" + "\033[m", cuser.five_win, cuser.five_lose, cuser.five_tie); + + getuser(my->mateid); + move(17, 60); + prints("\033[1;31m%d\033[37m勝 \033[34m%d\033[37m敗 \033[36m%d\033[37m" + "和\033[m", xuser.five_win, xuser.five_lose, xuser.five_tie); + + cuser.five_lose++; + /* 一進來先加一場敗場, 贏了後再扣回去, 避免快輸了惡意斷線 */ + passwd_update(usernum, &cuser); + + add_io(fd, 0); + + hewantpass = iwantpass = 0; + mv.x = mv.y = 7; + move(18, 40); + prints("%s時間還剩%d:%02d\n", my->turn ? "你的" : "對方", + MAX_TIME / 60, MAX_TIME % 60); + for(;;) { + move(13, 40); + outs(my->turn ? "輪到自己下了!": "等待對方下子.."); + if(lastcount != tick-time(0)) { + lastcount = tick-time(0); + move(18, 40); + prints("%s時間還剩%d:%02d\n", my->turn ? "你的" : "對方", + lastcount / 60, lastcount % 60); + if(lastcount <= 0 && my->turn) { + move(19, 40); + outs("時間已到, 你輸了"); + my->five_lose++; + send(fd, '\0', 1, 0); + break; + } + if(lastcount <= -5 && !my->turn) { + move(19, 40); + outs("對手太久沒下, 你贏了!"); + win = 1; + cuser.five_lose--; + cuser.five_win++; + my->five_win++; + passwd_update(usernum, &cuser); + mv.x = mv.y = -2; + send(fd, &mv, sizeof(Horder_t), 0); + mv = *(v - 1); + break; + } + } + move(14, 40); + if(hewantpass) { + outs("\033[1;32m和棋要求!\033[m"); + bell(); + } else + clrtoeol(); + BGOTOCUR(mv.x, mv.y); + ch = igetkey(); + if(ch != I_OTHERDATA) + iwantpass = 0; + if(ch == 'q') { + if(countgomo() < 10) { + cuser.five_lose--; + passwd_update(usernum, &cuser); + } + send(fd, '\0', 1, 0); + break; + } else if(ch == 'u' && !my->turn && v > pool) { + mv.x = mv.y = -1; + ch = send(fd, &mv, sizeof(Horder_t), 0); + if(ch == sizeof(Horder_t)) { + HO_undo(&mv); + tick = mylasttick; + my->turn = 1; + continue; + } else + break; + } + if(ch == 'p') { + if(my->turn ) { + if(iwantpass == 0) { + iwantpass = 1; + mv.x = mv.y = -2; + send(fd, &mv, sizeof(Horder_t), 0); + mv = *(v - 1); + } + continue; + } else if(hewantpass) { + win = 0; + cuser.five_lose--; + cuser.five_tie++; + my->five_tie++; + passwd_update(usernum, &cuser); + mv.x=mv.y=-2; + send(fd, &mv, sizeof(Horder_t), 0); + mv = *(v - 1); + break; + } + } + + if(ch == I_OTHERDATA) { + ch = recv(fd, &mv, sizeof(Horder_t), 0); + if(ch != sizeof(Horder_t)) { + lastcount=tick-time(0); + if(lastcount >=0) { + win = 1; + cuser.five_lose--; + if(countgomo() >=10) { + cuser.five_win++; + my->five_win++; + } + passwd_update(usernum, &cuser); + outmsg("對方認輸了!!"); + break; + } else { + win = 0; + outmsg("你超過時間未下子, 輸了!"); + my->five_lose++; + break; + } + } else if(mv.x == -2 && mv.y == -2) { + if(iwantpass == 1) { + win = 0; + cuser.five_lose--; + cuser.five_tie++; + my->five_tie++; + passwd_update(usernum, &cuser); + break; + } else { + hewantpass = 1; + mv = *(v - 1); + continue; + } + } + if(my->turn && mv.x == -1 && mv.y == -1) { + outmsg("對方悔棋"); + tick = hislasttick; + HO_undo(&mv); + my->turn = 0; + continue; + } + + if(!my->turn) { + win = chkmv(&mv, he, he == BBLACK); + HO_add(&mv); + hislasttick = tick; + tick = time(0) + MAX_TIME; + ku[(int)mv.x][(int)mv.y] = he; + bell(); + BGOTO(mv.x, mv.y); + outs(chess[he - 1]); + + if(win) { + outmsg(win == 1 ? "對方贏了!" : "對方禁手"); + if(win != 1) { + cuser.five_lose--; + cuser.five_win++; + my->five_win++; + passwd_update(usernum, &cuser); + } else + my->five_lose++; + win = -win; + break; + } + my->turn = 1; + } + continue; + } + + if(my->turn) { + if(gomo_key(fd, ch, &mv)) + my->turn = 0; + else + continue; + + if(!my->turn) { + HO_add(&mv); + BGOTO(mv.x, mv.y); + outs(chess[me - 1]); + win = chkmv( &mv, me, me == BBLACK); + ku[(int)mv.x][(int)mv.y] = me; + mylasttick = tick; + tick = time(0) + MAX_TIME; /*倒數*/ + lastcount = MAX_TIME; + if(send(fd, &mv, sizeof(Horder_t), 0) != sizeof(Horder_t)) + break; + if(win) { + outmsg(win == 1 ? "我贏囉~~" : "禁手輸了" ); + if(win == 1) { + cuser.five_lose--; + cuser.five_win++; + my->five_win++; + passwd_update(usernum, &cuser); + } else + my->five_lose++; + break; + } + move(15, 40); + clrtoeol(); + } + } + } + add_io(0, 0); + close(fd); + + igetch(); + if(v > pool) { + char ans[4]; + + getdata(19 , 0, "要保留本局成棋譜嗎?(y/N)", ans, 4, LCECHO); + if(*ans == 'y') + HO_log(my->mateid); + } + return 0; +} diff --git a/pttbbs/mbbsd/gomo1.c b/pttbbs/mbbsd/gomo1.c new file mode 100644 index 00000000..953bad2d --- /dev/null +++ b/pttbbs/mbbsd/gomo1.c @@ -0,0 +1,136 @@ +/* $Id: gomo1.c,v 1.1 2002/03/07 15:13:48 in2 Exp $ */ +#include +#include +#include +#include "config.h" +#include "pttstruct.h" +#include "proto.h" + +#define QCAST int (*)(const void *, const void *) + +#define BBLANK (0) /* 空白 */ +#define BBLACK (1) /* 黑子, 先手 */ +#define BWHITE (2) /* 白子, 後手 */ +#ifndef BRDSIZ +#define BRDSIZ (15) /* 棋盤單邊大小 */ +#endif + +extern char ku[BRDSIZ][BRDSIZ]; + +/* pattern and advance map */ +extern unsigned char *pat, *adv; + +static int intrevcmp(const void *a, const void *b) { + return (*(int *)b - *(int *)a); +} + +/* x,y: 0..BRDSIZ-1 ; color: CBLACK,CWHITE ; dx,dy: -1,0,+1 */ +static int gomo_getindex(int x, int y, int color, int dx, int dy) { + int i, k, n; + for(n = -1, i = 0, k = 1; i < 5; i++, k <<= 1) { + x += dx; + y += dy; + + if((x < 0) || (x >= BRDSIZ) || ( y < 0) || ( y >= BRDSIZ)) { + n += k; + break; + } else if(ku[x][y] != BBLANK) { + n += k; + if(ku[x][y] != color) + break; + } + } + + if(i >= 5) + n += k; + + return n; +} + +int chkwin(int style, int limit) { + if(style == 0x0c) + return 1 /* style */; + else if(limit == 0) { + if(style == 0x0b) + return 1 /* style */; + return 0; + } + if((style < 0x0c) && (style > 0x07)) + return -1 /* -style */; + return 0; +} + +/* x,y: 0..BRDSIZ-1 ; color: CBLACK,CWHITE ; limit:1,0 ; dx,dy: 0,1 */ +static int dirchk(int x, int y, int color, int limit, int dx, int dy) { + int le, ri, loc, style; + + le = gomo_getindex(x, y, color, -dx, -dy); + ri = gomo_getindex(x, y, color, dx, dy); + + loc = (le > ri) ? (((le * (le + 1)) >> 1) + ri) : + (((ri * (ri + 1)) >> 1) + le); + + style = pat[loc]; + + if(limit == 0) + return (style & 0x0f); + + style >>= 4; + + if((style == 3) || (style == 2)) { + int i, n, tmp, nx, ny; + + n = adv[loc >> 1]; + + ((loc & 1) == 0) ? (n >>= 4) : (n &= 0x0f); + + ku[x][y] = color; + + for(i = 0; i < 2; i++) { + if((tmp = (i == 0) ? (-(n >> 2)):(n & 3)) != 0) { + nx = x + (le > ri ? 1 : -1) * tmp * dx; + ny = y + (le > ri ? 1 : -1) * tmp * dy; + + if((dirchk(nx, ny, color, 0, dx, dy) == 0x06) && + (chkwin(getstyle(nx, ny, color, limit), limit) >= 0)) + break; + } + } + if(i >= 2) + style = 0; + ku[x][y] = BBLANK; + } + return style; +} + +/* 例外=F 錯誤=E 有子=D 連五=C 連六=B 雙四=A 四四=9 三三=8 */ +/* 四三=7 活四=6 斷四=5 死四=4 活三=3 斷三=2 保留=1 無效=0 */ + +/* x,y: 0..BRDSIZ-1 ; color: CBLACK,CWHITE ; limit: 1,0 */ +int getstyle(int x, int y, int color, int limit) { + int i, j, dir[4], style; + + if((x < 0) || (x >= BRDSIZ) || ( y < 0) || (y >= BRDSIZ)) + return 0x0f; + if(ku[x][y] != BBLANK) + return 0x0d; + + for(i = 0; i < 4; i++) + dir[i] = dirchk(x, y, color, limit, i ? (i>>1) : -1, i ? (i&1) : 1); + + qsort(dir, 4, sizeof(int), (QCAST)intrevcmp); + + if((style = dir[0]) >= 2) { + for(i = 1, j = 6 + (limit ? 1 : 0); i < 4; i++) { + if((style > j) || (dir[i] < 2)) + break; + if(dir[i] > 3) + style = 9; + else if((style < 7) && (style > 3)) + style = 7; + else + style = 8; + } + } + return style; +} diff --git a/pttbbs/mbbsd/guess.c b/pttbbs/mbbsd/guess.c new file mode 100644 index 00000000..27a337f7 --- /dev/null +++ b/pttbbs/mbbsd/guess.c @@ -0,0 +1,364 @@ +/* $Id: guess.c,v 1.1 2002/03/07 15:13:48 in2 Exp $ */ +#include +#include +#include +#include +#include "config.h" +#include "pttstruct.h" +#include "common.h" +#include "modes.h" +#include "proto.h" + +extern char *BBSName; +extern int usernum; +#define LOGPASS BBSHOME "/etc/winguess.log" + +static void show_table(char TABLE[], char ifcomputer) { + int i; + + move(0, 35); + prints("\033[1;44;33m 【 猜數字 】 \033[m"); + move(8, 1); + prints("\033[1;44;36m目 前 倍 率\033[m\n"); + prints("\033[1;33m=================\033[m\n"); + if(ifcomputer) { + prints("贏電腦: 2 倍\n"); + prints("輸電腦: 0 倍\n"); + } else { + for(i = 1; i <= 6; i++) + prints("第%d次, %02d倍\n",i,TABLE[i]); + } + prints("\033[33m=================\033[m"); +} + +extern userec_t cuser; + +static unsigned long int get_money(void) { + int money, i; + char data[20]; + + move(1, 0); + prints("您目前有:%d Ptt$", cuser.money); + do { + getdata(2, 0, "要賭多少(5-10或按q離開): ", data, 9, LCECHO); + money = strlen(data); + if(data[0] == 'q' || data[0] == 'Q') { + unlockutmpmode(); + return 0; + } + for(i = 0; i < money; i++) + if(data[i]<'0' || data[i]>'9') { + money = -1; + break; + } + if(money != -1){ + money = atol(data); + reload_money(); + if(money > cuser.money || money <= 4 || money > 10 || + money < 1) + money = -1; + } + } while(money == -1); + move(1,0); + clrtoeol(); + reload_money(); + prints("您目前有:%d Ptt$", cuser.money - money); + return money; +} + +static int check_data(char *str) { + int i, j; + + if(strlen(str) != 4) + return -1; + for(i = 0; i < 4; i++) + if(str[i] < '0' || str[i] > '9') + return -1; + for(i = 0; i < 4; i++) + for(j = i + 1; j < 4; j++) + if(str[i] == str[j]) + return -1; + return 1; +} + +static char *get_data(int count) { + static char data[5]; + while(1) { + getdata(6, 0, "輸入四位數字(不重複): ", data, 5, LCECHO); + if(check_data(data) == 1) + break; + } + return data; +} + +static int guess_play(char *data, char *answer, int count) { + int A_num = 0, B_num = 0; + int i, j; + + for(i = 0; i < 4; i++) { + if(data[i] == answer[i]) + A_num++; + for(j = 0; j < 4; j++) + if(i == j) + continue; + else if(data[i] == answer[j]) { + B_num++; + break; + } + } + if(A_num == 4) + return 1; + move(count + 8,55); + prints("%s => \033[1;32m%dA %dB\033[m", data, A_num, B_num); + return 0; +} + +static int result(int correct, int number) { + char a = 0, b = 0, i, j; + char n1[5], n2[5]; + + sprintf(n1, "%04d",correct); + sprintf(n2, "%04d",number); + for(i = 0; i < 4; i++) + for(j = 0; j < 4; j++) + if(n1[(int)i] == n2[(int)j]) + b++; + for(i = 0; i < 4; i++) + if(n1[(int)i] == n2[(int)i]) { + b--; + a++; + } + return 10 * a + b; +} + +static int legal(int number) { + char i, j; + char temp[5]; + + sprintf(temp, "%04d", number); + for(i = 0; i < 4; i++) + for(j = i + 1; j < 4; j++) + if(temp[(int)i] == temp[(int)j]) + return 0; + return 1; +} + +static void initcomputer(char flag[]) { + int i; + + for(i = 0; i < 10000; i++) + if(legal(i)) + flag[i] = 1; + else + flag[i] = 0; +} + +static int computer(int correct, int total, char flag[], int n[]) { + int guess; + static int j; + int k,i; + char data[5]; + + if(total == 1) { + do { + guess = rand() % 10000; + } while(!legal(guess)); + } else + guess = n[rand() % j]; + k = result(correct, guess); + if(k == 40) { + move(total + 8, 25); + sprintf(data, "%04d", guess); + prints("%s => 猜中了!!", data); + return 1; + } else { + move(total + 8, 25); + sprintf(data, "%04d", guess); + prints("%s => \033[1;32m%dA %dB\033[m", data, k / 10, k % 10); + } + j = 0; + for(i = 0; i < 10000; i++) + if(flag[i]) { + if(result(i, guess) != k) + flag[i] = 0; + else + n[j++] = i; + } + return 0; +} + +static void Diff_Random(char *answer) { + register int i = 0, j, k; + + while(i < 4) { + k = rand() % 10 + '0'; + for(j = 0; j < i; j++) + if(k == answer[j]) + break; + if(j == i) { + answer[j] = k; + i++; + } + } + answer[4] = 0; +} + +#define lockreturn0(unmode, state) if(lockutmpmode(unmode, state)) return 0 + +int guess_main() { + unsigned long int money; + char computerwin = 0,youwin = 0; + int count = 0,c_count = 0; + char ifcomputer; + char answer[5]; + int *n = NULL; + char yournum[5]; + char *flag = NULL; + static char TABLE[]={0,10,8,4,2,1,0,0,0,0,0}; + FILE *file; + + clear(); + showtitle("猜數字", BBSName); + lockreturn0(GUESSNUM, LOCK_MULTI); + + reload_money(); + if(cuser.money < 5) { + clear(); + move(12, 35); + prints("錢不夠啦 至少要 5 Ptt$"); + unlockutmpmode(); + pressanykey(); + return 1; + } + if((money = get_money()) == 0) + return 1; + vice(money,"猜數字"); + + Diff_Random(answer); + move(2, 0); + clrtoeol(); + prints("您下注 :%d Ptt$", money); + + getdata_str(4, 0, "您要和電腦比賽嗎? [y]:", &ifcomputer, 2, + LCECHO, "y"); + if(ifcomputer == 'y') { + ifcomputer = 1; + show_table(TABLE, 1); + } else { + ifcomputer = 0; + show_table(TABLE, 0); + } + if(ifcomputer) { + do { + getdata(5, 0, "請輸入您要讓電腦猜的數字: ", yournum, 5, LCECHO); + } while(!legal(atoi(yournum))); + move(8, 25); + prints("電腦猜"); + flag = malloc(sizeof(char) * 10000); + n = malloc(sizeof(int) * 1500); + initcomputer(flag); + } + move(8, 55); + prints("你猜"); + while(((!computerwin || !youwin) && count <10 && (ifcomputer)) || + (!ifcomputer && count < 10 && !youwin)) { + if(!computerwin && ifcomputer) { + ++c_count; + if(computer(atoi(yournum), c_count, flag, n)) + computerwin = 1; + } + move(20, 55); + prints("第 %d 次機會 ", count + 1); + if(!youwin) { + ++count; + if(guess_play(get_data(count),answer,count)) + youwin=1; + } + } + move(17, 35); + if(ifcomputer) { + free(flag); + free(n); + if(count > c_count) { + prints("你輸給電腦了"); + move(18, 35); + prints("你賠了 %d ", money); + if((file = fopen(LOGPASS,"a"))) { + fprintf(file, "電腦第%d次猜中, ", c_count); + if(youwin) + fprintf(file, "%s 第%d次猜中, ", cuser.userid, count); + else + fprintf(file, "%s 沒猜中, ", cuser.userid); + fprintf(file,"電腦賺走了%s %ld Ptt$\n", cuser.userid, money); + fclose(file); + } + unlockutmpmode(); + pressanykey(); + return 1; + } else if(count < c_count) { + prints("真厲害, 讓你賺到囉"); + move(18,35);prints("你賺走了 %d ",money*2); + demoney(money*2); + if((file = fopen(LOGPASS,"a"))) { + fprintf(file, "id: %s, 第%d次猜中, 電腦第%d次猜中, " + "贏了電腦 %ld Ptt$\n", cuser.userid, count, + c_count, money * 2); + fclose(file); + } + unlockutmpmode(); + pressanykey(); + return 1; + } else { + prints("真厲害, 和電腦打成平手了, 拿回本錢%d\n", money); + demoney(money); + if((file = fopen(LOGPASS,"a"))) { + fprintf(file, "id: %s 和電腦打成了平手\n", cuser.userid); + fclose(file); + } + unlockutmpmode(); + pressanykey(); + return 1; + } + } + if(youwin) { + demoney(TABLE[count]*money); + if(count < 5) { + prints("真厲害, 錢被你賺走了"); + if((file = fopen(LOGPASS,"a"))) { + fprintf(file, "id: %s, 第%d次猜中, 贏了 %ld Ptt$\n", + cuser.userid, count, TABLE[count] * money); + fclose(file); + } + } else if(count > 5) { + prints("唉, 太多次才猜出來了"); + if((file = fopen(LOGPASS,"a"))) { + fprintf(file, "id: %s, 第%d次才猜中, 賠了 %ld Ptt$\n", + cuser.userid, count, money); + fclose(file); + } + } + else { + prints("五次猜出來, 還你本錢吧"); + move(18,35); + clrtoeol(); + prints("你拿回了%d Ptt$\n", money); + if((file = fopen(LOGPASS,"a"))) { + fprintf(file, "id: %s, 第%d次猜中, 拿回了本錢 %ld Ptt$\n", + cuser.userid, count, money); + fclose(file); + } + } + unlockutmpmode(); + pressanykey(); + return 1; + } + move(17,35); + prints("嘿嘿 標準答案是 %s ", answer); + move(18,35); + prints("下次再來吧"); + if((file = fopen(BBSHOME "/etc/loseguess.log","a"))) { + fprintf(file,"id: %s 賭了 %ld Ptt$\n",cuser.userid,money); + fclose(file); + } + return 1; +} diff --git a/pttbbs/mbbsd/indict.c b/pttbbs/mbbsd/indict.c new file mode 100644 index 00000000..407b5ae9 --- /dev/null +++ b/pttbbs/mbbsd/indict.c @@ -0,0 +1,184 @@ +/* $Id: indict.c,v 1.1 2002/03/07 15:13:48 in2 Exp $ */ +#include +#include +#include +#include "config.h" +#include "pttstruct.h" +#include "perm.h" +#include "common.h" +#include "modes.h" +#include "proto.h" + +#define REFER "etc/dicts" + +extern userec_t cuser; +char dict[41],database[41]; + +static void addword(char word[]) { + char buf[150],temp[150],a[3]; + FILE *fp = fopen(database,"r+"); + + fgets(buf,130,fp); + fseek(fp,0,2); + if(HAVE_PERM(PERM_LOGINOK)) { + clear(); + move(4,0); + outs(" \033[31m警告\033[m:若蓄意填寫假資料將\033[36m砍id\033[m處份\n"); + sprintf(temp, "\n輸入範利\n:\033[33m%s\033[m", buf); + outs(temp); + outs("\n請依上列範例輸入一行資料(直接enter放棄)\n"); + getdata(10, 0, ":", buf, 65, DOECHO); + if(buf[0]) { + getdata(13, 0, "確定新增?(Y/n)", a, 2, LCECHO); + if(a[0] != 'n') + fprintf(fp, "%-65s[%s]\n", buf, cuser.userid); + } + } + fclose(fp); + clear(); +} + +static int choose_dict(void) { + int c; + FILE *fp; + char buf[10][21], data[10][21], cho[130]; + + move(12, 0); + clrtobot(); + outs(" " + "● \033[45;33m字典唷 ◇ 要查哪一本?\033[m ●"); + + if((fp = fopen(REFER, "r"))) { + for(c = 0; fscanf(fp, "%s %s", buf[c], data[c]) != EOF; c++ ) { + sprintf(cho,"\n " + "(\033[36m%d\033[m) %-20s大字典",c+1,buf[c]); + outs(cho); + } + + getdata(22, 14, " ★ 請選擇,[Enter]離開:", cho, 3, LCECHO); + cho[0] -= '1'; + if(cho[1]) + cho[0] = (cho[0] + 1) * 10 + (cho[1] - '1'); + + if(cho[0] >= 0 && cho[0] < c) { + strcpy(dict, buf[(int)cho[0]]); + strcpy(database, data[(int)cho[0]]); + return 1; + } else + return 0; + } + return 0; +} + +static char *lower(char str[]) { + int c; + static char temp[200]; + + strcpy(temp,str); + for(c = 0; temp[c] !=0; c++) + if(temp[c] >= 'A' && temp[c] <= 'Z') + temp[c] += 'a' - 'A'; + return temp; +} + +int use_dict() { + FILE *fp; + char lang[150], word[80] = ""; + char j, f, buf[120], sys[] = "|\033[31me\033[m:編籍字典"; + int i = 0; + + setutmpmode(DICT); + if(!HAS_PERM(PERM_SYSOP)) + sys[0]=0; + + clear(); + + sprintf(buf,"\033[45m ●\033[1;44;33m" + " %-14s\033[3;45m ● ", dict); + strcpy(&buf[100],"\033[m\n"); + for(;;) { + move(0, 0); + sprintf(lang, " 請輸入關鍵字串(%s) 或指令(h,t,a)\n", dict); + outs(lang); + sprintf(lang, "[\033[32m<關鍵字>\033[m|\033[32mh\033[m:help|\033[32m" + "t\033[m:所有資料|\033[32ma\033[m:新增資料%s]\n:", sys); + outs(lang); + getdata(2, 0, ":", word, 18, DOECHO); + outs("資料搜尋中請稍候...."); + strcpy(word,lower(word)); + if(word[0] == 0) + return 0; + clear(); + move(4, 0); + outs(buf); + if(strlen(word) == 1) { + if(word[0] == 'a') { + clear(); + move(4,0); + outs(buf); + addword(word); + continue; + } else if(word[0] == 't') + word[0] = 0; + else if(word[0] == 'h') { + more("etc/dict.hlp",YEA); + clear(); + continue; + } else if(word[0]=='e') { + vedit(database,NA, NULL); + clear(); + continue; + } else { + outs("字串太短,請輸入多一點關鍵字"); + continue; + } + } + + if((fp = fopen(database,"r"))) { + i = 0; + while(fgets(lang,150,fp) != NULL) { + if(lang[65] == '[') { + lang[65] = 0; + f = 1; + } else + f = 0; + if(strstr(lower(lang),word)) { + if(f == 1) + lang[65] = '['; + outs(lang); + i++; + if(!((i+1)%17)) { + move(23, 0); + outs("\033[45m " + "任意鍵繼續 Q:離開 " + "\033[m "); + j = igetch(); + if(j == 'q') + break; + else { + clear(); + move(4,0); + outs(buf); + } + } + } + } + } + fclose(fp); + if(i == 0) { + getdata(5, 0, "沒這個資料耶,新增嗎?(y/N)", lang, 3, LCECHO); + if(lang[0] == 'y') { + clear(); + move(4,0); + outs(buf); + addword(word); + } + } + } +} + +int x_dict() { + if(choose_dict()) + use_dict(); + return 0; +} diff --git a/pttbbs/mbbsd/io.c b/pttbbs/mbbsd/io.c new file mode 100644 index 00000000..e3d03b9b --- /dev/null +++ b/pttbbs/mbbsd/io.c @@ -0,0 +1,611 @@ +/* $Id: io.c,v 1.1 2002/03/07 15:13:48 in2 Exp $ */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "config.h" +#include "pttstruct.h" +#include "perm.h" +#include "modes.h" +#include "common.h" +#include "proto.h" + +#if defined(linux) +#define OBUFSIZE 2048 +#define IBUFSIZE 128 +#else +#define OBUFSIZE 4096 +#define IBUFSIZE 256 +#endif + +extern int current_font_type; +extern char *fn_proverb; +extern userinfo_t *currutmp; +extern unsigned int currstat; +extern pid_t currpid; +extern int errno; +extern screenline_t *big_picture; +extern int t_lines, t_columns; /* Screen size / width */ +extern int curr_idle_timeout; +extern water_t water[6], *swater[5], *water_which; +extern char water_usies; + +static char outbuf[OBUFSIZE], inbuf[IBUFSIZE]; +static int obufsize = 0, ibufsize = 0; +static int icurrchar = 0; + +/* ----------------------------------------------------- */ +/* 定時顯示動態看板 */ +/* ----------------------------------------------------- */ +extern userec_t cuser; + +static void hit_alarm_clock() { + if(HAS_PERM(PERM_NOTIMEOUT) || PERM_HIDE(currutmp) || currstat == MAILALL) + return; +// if(time(0) - currutmp->lastact > IDLE_TIMEOUT - 2) { + if(time(0) - currutmp->lastact > curr_idle_timeout - 2) { + clear(); + if(currpid > 0) kill(currpid, SIGHUP); + } +// alarm(IDLE_TIMEOUT); + alarm(curr_idle_timeout); +} + +void init_alarm() { + signal(SIGALRM, (void (*)(int))hit_alarm_clock); +// alarm(IDLE_TIMEOUT); + alarm(curr_idle_timeout); +} + +/* ----------------------------------------------------- */ +/* output routines */ +/* ----------------------------------------------------- */ + +void oflush() { + if(obufsize) { + write(1, outbuf, obufsize); + obufsize = 0; + } +} + +void init_buf() +{ + + memset(inbuf,0,IBUFSIZE); +} +void output(char *s, int len) { + /* Invalid if len >= OBUFSIZE */ + + if(obufsize + len > OBUFSIZE) { + write(1, outbuf, obufsize); + obufsize = 0; + } + memcpy(outbuf + obufsize, s, len); + obufsize += len; +} + +int ochar(int c) { + if(obufsize > OBUFSIZE - 1) { + write(1, outbuf, obufsize); + obufsize = 0; + } + outbuf[obufsize++] = c; + return 0; +} + +/* ----------------------------------------------------- */ +/* input routines */ +/* ----------------------------------------------------- */ + +static int i_newfd = 0; +static struct timeval i_to, *i_top = NULL; +static int (*flushf) () = NULL; + +void add_io(int fd, int timeout) { + i_newfd = fd; + if(timeout) { + i_to.tv_sec = timeout; + i_to.tv_usec = 16384; /* Ptt: 改成16384 避免不按時for loop吃cpu time + 16384 約每秒64次 */ + i_top = &i_to; + } else + i_top = NULL; +} + +int num_in_buf() { + return icurrchar - ibufsize; +} + +int watermode = -1; +/* Ptt 水球回顧用的參數 */ +/* watermode = -1 沒在回水球 + = 0 在回上一顆水球 (Ctrl-R) + > 0 在回前 n 顆水球 (Ctrl-R Ctrl-R) */ + +/* + dogetch() is not reentrant-safe. SIGUSR[12] might happen at any time, + and dogetch() might be called again, and then ibufsize/icurrchar/inbuf + might be inconsistent. + We try to not segfault here... +*/ + +static int dogetch() { + int len; + + if(ibufsize <= icurrchar) { + + if(flushf) + (*flushf)(); + + refresh(); + + if(i_newfd) { + + struct timeval timeout; + fd_set readfds; + + if(i_top) timeout=*i_top; /* copy it because select() might change it */ + + FD_ZERO(&readfds); + FD_SET(0, &readfds); + FD_SET(i_newfd, &readfds); + + /* jochang: modify first argument of select from FD_SETSIZE */ + /* since we are only waiting input from fd 0 and i_newfd(>0) */ + + while((len = select(i_newfd+1, &readfds, NULL, NULL, i_top?&timeout:NULL))<0) + { + if(errno != EINTR) + abort_bbs(0); + /* raise(SIGHUP); */ + } + + if(len == 0) + return I_TIMEOUT; + + if(i_newfd && FD_ISSET(i_newfd, &readfds)) + return I_OTHERDATA; + } + + while((len = read(0, inbuf, IBUFSIZE)) <= 0) { + if(len == 0 || errno != EINTR) + abort_bbs(0); + /* raise(SIGHUP); */ + } + ibufsize = len; + icurrchar = 0; + } + + if(currutmp) + currutmp->lastact = time(0); + return inbuf[icurrchar++]; +} + +static int water_which_flag=0; +int igetch() { + register int ch; + while((ch = dogetch())) { + switch(ch) { + case Ctrl('L'): + redoscr(); + continue; + case Ctrl('U'): + if(currutmp != NULL && currutmp->mode != EDITING + && currutmp->mode != LUSERS && currutmp->mode) { + + screenline_t *screen0 = calloc(t_lines, sizeof(screenline_t)); + int y, x, my_newfd; + + getyx(&y, &x); + memcpy(screen0, big_picture, t_lines * sizeof(screenline_t)); + my_newfd = i_newfd; + i_newfd = 0; + t_users(); + i_newfd = my_newfd; + memcpy(big_picture, screen0, t_lines * sizeof(screenline_t)); + move(y, x); + free(screen0); + redoscr(); + continue; + } else + return (ch); + case KEY_TAB: + if( WATERMODE(WATER_ORIG) || WATERMODE(WATER_NEW) ) + if( currutmp != NULL && watermode > 0 ){ + watermode = (watermode + water_which->count) + % water_which->count + 1; + t_display_new(); + continue; + } + return ch; + break; + + case Ctrl('R'): + if(currutmp == NULL) + return (ch); + if( WATERMODE(WATER_ORIG) || WATERMODE(WATER_NEW) ){ + if( watermode > 0 ){ + watermode = (watermode + water_which->count) + % water_which->count + 1; + t_display_new(); + continue; + } + else if( currutmp->mode == 0 && + (currutmp->chatid[0]==2 || currutmp->chatid[0]==3) && + water_which->count != 0 && watermode == 0) { + /* 第二次按 Ctrl-R */ + watermode = 1; + t_display_new(); + continue; + } + else if(currutmp->msgs[0].pid) { + /* 第一次按 Ctrl-R (必須先被丟過水球) */ + screenline_t *screen0; + int y, x, my_newfd; + screen0 = calloc(t_lines, sizeof(screenline_t)); + getyx(&y, &x); + memcpy(screen0, big_picture, t_lines*sizeof(screenline_t)); + + /* 如果正在talk的話先不處理對方送過來的封包 (不去select) */ + my_newfd = i_newfd; + i_newfd = 0; + show_last_call_in(0); + watermode = 0; + my_write(currutmp->msgs[0].pid, "水球丟過去 : ", + currutmp->msgs[0].userid, 0); + i_newfd = my_newfd; + + /* 還原螢幕 */ + memcpy(big_picture, screen0, t_lines*sizeof(screenline_t)); + move(y, x); + free(screen0); + redoscr(); + continue; + } + else + return ch; + } + + if( currutmp->msgs[0].pid && + WATERMODE(WATER_OFO) && watermode == -1 ){ + int y, x, my_newfd; + screenline_t *screen0 = calloc(t_lines, sizeof(screenline_t)); + memcpy(screen0, big_picture, t_lines * sizeof(screenline_t)); + getyx(&y, &x); + my_newfd = i_newfd; + i_newfd = 0; + my_write2(); + memcpy(big_picture, screen0, t_lines * sizeof(screenline_t)); + i_newfd = my_newfd; + move(y, x); + free(screen0); + redoscr(); + continue; + } + + return ch; + case '\n': /* Ptt把 \n拿掉 */ + continue; + case Ctrl('T'): + if( WATERMODE(WATER_ORIG) || WATERMODE(WATER_NEW) ){ + if(watermode > 0) { + if(watermode>1) + watermode--; + else + watermode = water_which->count; + t_display_new(); + continue; + } + } + return (ch); + + case Ctrl('E'): + if( WATERMODE(WATER_ORIG) || WATERMODE(WATER_NEW) ){ + if(watermode >0){ + if( water_which_flag == (int)water_usies ) + water_which_flag = 0; + else + water_which_flag = + (water_which_flag+1) % (int)(water_usies+1); + if(water_which_flag==0) + water_which = &water[0]; + else + water_which = swater[water_which_flag-1]; + watermode = 1; + t_display_new(); + continue; + } + } + return ch; + + case Ctrl('W'): + if(watermode >0) + { + water_which_flag=(water_which_flag+water_usies)%(water_usies+1); + if(water_which_flag==0) + water_which = &water[0]; + else + water_which = swater[water_which_flag-1]; + watermode = 1; + t_display_new(); + continue; + } + else return ch; + default: + return ch; + } + } + return 0; +} + +int oldgetdata(int line, int col, char *prompt, char *buf, int len, int echo) { + register int ch, i; + int clen; + int x = col, y = line; + extern unsigned char scr_cols; +#define MAXLASTCMD 12 + static char lastcmd[MAXLASTCMD][80]; + + strip_ansi(buf, buf, STRIP_ALL); + + if(prompt) { + + move(line, col); + + clrtoeol(); + + outs(prompt); + + x += strip_ansi(NULL,prompt,0); + } + + if(!echo) { + len--; + clen = 0; + while((ch = igetch()) != '\r') { + if(ch == '\177' || ch == Ctrl('H')) { + if(!clen) { + bell(); + continue; + } + clen--; + if(echo) { + ochar(Ctrl('H')); + ochar(' '); + ochar(Ctrl('H')); + } + continue; + } +// Ptt +#ifdef BIT8 + if(!isprint2(ch)) +#else + if(!isprint(ch)) +#endif + { + if(echo) + bell(); + continue; + } + + if(clen >= len) { + if(echo) + bell(); + continue; + } + buf[clen++] = ch; + if(echo) + ochar(ch); + } + buf[clen] = '\0'; + outc('\n'); + oflush(); + } else { + int cmdpos = -1; + int currchar = 0; + + standout(); + for(clen = len--; clen; clen--) + outc(' '); + standend(); + buf[len] = 0; + move(y, x); + edit_outs(buf); + clen = currchar = strlen(buf); + + while(move(y, x + currchar), (ch = igetkey()) != '\r') { + switch(ch) { + case KEY_DOWN: + case Ctrl('N'): + buf[clen] = '\0'; /* Ptt */ + strncpy(lastcmd[cmdpos], buf, 79); + cmdpos += MAXLASTCMD - 2; + case Ctrl('P'): + case KEY_UP: + if(ch == KEY_UP || ch == Ctrl('P')) { + buf[clen] = '\0'; /* Ptt */ + strncpy(lastcmd[cmdpos], buf, 79); + } + cmdpos++; + cmdpos %= MAXLASTCMD; + strncpy(buf, lastcmd[cmdpos], len); + buf[len] = 0; + + move(y, x); /* clrtoeof */ + for(i = 0; i <= clen; i++) + outc(' '); + move(y, x); + edit_outs(buf); + clen = currchar = strlen(buf); + break; + case KEY_LEFT: + if(currchar) + --currchar; + break; + case KEY_RIGHT: + if(buf[currchar]) + ++currchar; + break; + case '\177': + case Ctrl('H'): + if(currchar) { + currchar--; + clen--; + for(i = currchar; i <= clen; i++) + buf[i] = buf[i + 1]; + move(y, x + clen); + outc(' '); + move(y, x); + edit_outs(buf); + } + break; + case Ctrl('Y'): + currchar = 0; + case Ctrl('K'): + buf[currchar] = 0; + move(y, x + currchar); + for(i = currchar; i < clen; i++) + outc(' '); + clen = currchar; + break; + case Ctrl('D'): + if(buf[currchar]) { + clen--; + for(i = currchar; i <= clen; i++) + buf[i] = buf[i + 1]; + move(y, x + clen); + outc(' '); + move(y, x); + edit_outs(buf); + } + break; + case Ctrl('A'): + currchar = 0; + break; + case Ctrl('E'): + currchar = clen; + break; + default: + if(isprint2(ch) && clen < len && x + clen < scr_cols) { + for(i = clen + 1; i > currchar;i--) + buf[i] = buf[i - 1]; + buf[currchar] = ch; + move(y, x + currchar); + edit_outs(buf + currchar); + currchar++; + clen++; + } + break; + }/* end case */ + } /* end while */ + + if(clen > 1) + for(cmdpos = MAXLASTCMD - 1; cmdpos; cmdpos--) { + strcpy(lastcmd[cmdpos], lastcmd[cmdpos - 1]); + strncpy(lastcmd[0], buf, len); + } + if(echo) + outc('\n'); + refresh(); + } + if((echo == LCECHO) && ((ch = buf[0]) >= 'A') && (ch <= 'Z')) + buf[0] = ch | 32; +#ifdef SUPPORT_GB + if(echo == DOECHO && current_font_type == TYPE_GB) + { + strcpy(buf,hc_convert_str(buf, HC_GBtoBIG, HC_DO_SINGLE)); + } +#endif + return clen; +} + +/* Ptt */ +int getdata_buf(int line, int col, char *prompt, char *buf, int len, int echo) { + return oldgetdata(line, col, prompt, buf, len, echo); +} + +char +getans(char *prompt) +{ + char ans[5]; + + getdata(t_lines-1, 0, prompt, ans, 4, LCECHO); + return ans[0]; +} + +int getdata_str(int line, int col, char *prompt, char *buf, int len, int echo, char *defaultstr) { + strncpy(buf, defaultstr, len); + + buf[len] = 0; + return oldgetdata(line, col, prompt, buf, len, echo); +} + +int getdata(int line, int col, char *prompt, char *buf, int len, int echo) { + buf[0] = 0; + return oldgetdata(line, col, prompt, buf, len, echo); +} + +int +rget(int x,char *prompt) +{ + register int ch; + + move(x,0); + clrtobot(); + outs(prompt); + refresh(); + + ch = igetch(); + if( ch >= 'A' && ch <= 'Z') ch |= 32; + + return ch; +} + + +int KEY_ESC_arg; + +int igetkey() { + int mode; + int ch, last; + + mode = last = 0; + while(1) { + ch = igetch(); + if(mode == 0) { + if(ch == KEY_ESC) + mode = 1; + else + return ch; /* Normal Key */ + } else if (mode == 1) { /* Escape sequence */ + if(ch == '[' || ch == 'O') + mode = 2; + else if(ch == '1' || ch == '4') + mode = 3; + else { + KEY_ESC_arg = ch; + return KEY_ESC; + } + } else if(mode == 2) { /* Cursor key */ + if(ch >= 'A' && ch <= 'D') + return KEY_UP + (ch - 'A'); + else if(ch >= '1' && ch <= '6') + mode = 3; + else + return ch; + } else if (mode == 3) { /* Ins Del Home End PgUp PgDn */ + if(ch == '~') + return KEY_HOME + (last - '1'); + else + return ch; + } + last = ch; + } +} + diff --git a/pttbbs/mbbsd/kaede.c b/pttbbs/mbbsd/kaede.c new file mode 100644 index 00000000..c0bd5103 --- /dev/null +++ b/pttbbs/mbbsd/kaede.c @@ -0,0 +1,95 @@ +/* $Id: kaede.c,v 1.1 2002/03/07 15:13:48 in2 Exp $ */ +#include +#include +#include +#include +#include +#include +#include "config.h" +#include "pttstruct.h" +#include "proto.h" + +extern struct utmpfile_t *utmpshm; +extern userec_t cuser; + +char *Ptt_prints(char *str, int mode) { + char *po , strbuf[256]; + + while((po = strstr(str, "\033*s"))) { + po[0] = 0; + sprintf(strbuf, "%s%s%s", str, cuser.userid, po + 3); + strcpy(str, strbuf); + } + while((po = strstr(str, "\033*t"))) { + time_t now = time(0); + + po[0] = 0; + sprintf(strbuf, "%s%s", str, Cdate(&now)); + str[strlen(strbuf)-1] = 0; + strcat(strbuf, po + 3); + strcpy(str, strbuf); + } + while((po = strstr(str, "\033*u"))) { + int attempts; + + attempts = utmpshm->number; + po[0] = 0; + sprintf(strbuf, "%s%d%s", str, attempts, po + 3); + strcpy(str, strbuf); + } + while((po = strstr(str, "\033*b"))) { + po[0] = 0; + sprintf(strbuf, "%s%d/%d%s", str, cuser.month, cuser.day, po + 3); + strcpy(str, strbuf); + } + while((po = strstr(str, "\033*l"))) { + po[0] = 0; + sprintf(strbuf, "%s%d%s", str, cuser.numlogins, po + 3); + strcpy(str, strbuf); + } + while((po = strstr(str, "\033*p"))) { + po[0] = 0; + sprintf(strbuf, "%s%d%s", str, cuser.numposts, po + 3); + strcpy(str, strbuf); + } + while((po = strstr(str, "\033*n"))) { + po[0] = 0; + sprintf(strbuf, "%s%s%s", str, cuser.username, po + 3); + strcpy(str, strbuf); + } + while((po = strstr(str, "\033*m"))) { + po[0] = 0; + sprintf(strbuf, "%s%d%s", str, cuser.money, po + 3); + strcpy(str, strbuf); + } + strip_ansi(str, str ,mode); + return str; +} + +int Rename(char* src, char* dst) { + if(rename(src, dst) == 0) + return 0; + return -1; +} + +int Link(char* src, char* dst) { + char cmd[200]; + + if(strcmp(src, BBSHOME "/home") == 0) + return 1; + if(link(src, dst) == 0) + return 0; + + sprintf(cmd, "/bin/cp -R %s %s", src, dst); + return system(cmd); +} + +char *my_ctime(const time_t *t) { + struct tm *tp; + static char ans[100]; + + tp = localtime(t); + sprintf(ans, "%02d/%02d/%02d %02d:%02d:%02d", (tp->tm_year % 100), + tp->tm_mon + 1,tp->tm_mday, tp->tm_hour, tp->tm_min, tp->tm_sec); + return ans; +} diff --git a/pttbbs/mbbsd/lovepaper.c b/pttbbs/mbbsd/lovepaper.c new file mode 100644 index 00000000..52e8cbd5 --- /dev/null +++ b/pttbbs/mbbsd/lovepaper.c @@ -0,0 +1,120 @@ +/* $Id: lovepaper.c,v 1.1 2002/03/07 15:13:48 in2 Exp $ */ +#include +#include +#include +#include +#include +#include +#include "config.h" +#include "pttstruct.h" +#include "modes.h" +#include "common.h" +#include "proto.h" + +#define DATA "etc/lovepaper.dat" + +extern userec_t cuser; + +int x_love() { + char buf1[200], save_title[TTLEN + 1]; + char receiver[61], path[STRLEN] = "home/"; + int x, y = 0, tline = 0, poem = 0; + FILE *fp, *fpo; + time_t timenow; + struct tm *gtime; + fileheader_t mhdr; + + setutmpmode(LOVE); + time(&timenow); + gtime = localtime(&timenow); + sprintf(buf1,"%c/%s/love%d%d", + cuser.userid[0], cuser.userid,gtime->tm_sec,gtime->tm_min); + strcat(path,buf1); + move(1,0); + clrtobot(); + + outs("\n歡迎使用情書產生器 v0.00 版 \n"); + outs("有何難以啟齒的話,交由系統幫你說吧.\n爸爸說 : 濫情不犯法.\n"); + + if(!getdata(7, 0, "收信人:", receiver, 60, DOECHO)) return 0; + if(receiver[0] && !(searchuser(receiver) && + getdata(8, 0, "主 題:", save_title, + TTLEN, DOECHO))) { + move(10, 0); + outs("收信人或主題不正確, 情書無法傳遞. "); + pressanykey(); + return 0; + } + + fpo = fopen(path, "w"); + fprintf(fpo, "\n"); + if((fp = fopen(DATA, "r"))) { + while(fgets(buf1,100, fp)) { + switch(buf1[0]) { + case '#': + break; + case '@': + if(!strncmp(buf1, "@begin", 6) || !strncmp(buf1, "@end", 4)) + tline=3; + else if(!strncmp(buf1,"@poem",5)) { + poem = 1; + tline = 1; + fprintf(fpo, "\n\n"); + } else + tline=2; + break; + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + sscanf(buf1,"%d",&x); + y = (rand() % (x - 1)) * tline; + break; + default: + if(!poem) { + if(y > 0) + y = y - 1; + else { + if(tline > 0) { + fprintf(fpo, "%s", buf1); + tline--; + } + } + } else { + if(buf1[0] == '$') + y--; + else if(y == 0) + fprintf(fpo,"%s",buf1); + } + } + + } + + fclose(fp); + fclose(fpo); + if(vedit(path, YEA, NULL) == -1) { + unlink(path); + clear(); + outs("\n\n 放棄寄情書\n"); + pressanykey(); + return -2; + } + sethomepath(buf1, receiver); + stampfile(buf1, &mhdr); + Rename(path, buf1); + strncpy(mhdr.title, save_title, TTLEN); + strcpy(mhdr.owner, cuser.userid); + mhdr.savemode = '\0'; + sethomedir(path, receiver ); + if(append_record(path, &mhdr, sizeof(mhdr)) == -1) + return -1; + hold_mail(buf1, receiver); + return 1; + } + return 0; +} diff --git a/pttbbs/mbbsd/mail.c b/pttbbs/mbbsd/mail.c new file mode 100644 index 00000000..e480abb2 --- /dev/null +++ b/pttbbs/mbbsd/mail.c @@ -0,0 +1,1675 @@ +/* $Id: mail.c,v 1.1 2002/03/07 15:13:48 in2 Exp $ */ +#include +#include +#include +#include +#include +#include +#include +#include +#include "config.h" +#include "pttstruct.h" +#include "common.h" +#include "perm.h" +#include "modes.h" +#include "proto.h" + +extern int TagNum; +extern int b_lines; /* Screen bottom line number: t_lines-1 */ +extern char save_title[]; /* used by editor when inserting */ +extern int curredit; +extern char *err_uid; +extern char *msg_cancel; +extern char *msg_uid; +extern char *fn_overrides; +extern char quote_file[80]; +extern char quote_user[80]; +extern char *fn_notes; +extern char *msg_mailer; +extern char *msg_sure_ny; +extern char *BBSName; +extern char currtitle[44]; +extern unsigned char currfmode; /* current file mode */ +extern char *msg_del_ny; +extern char currfile[FNLEN]; +extern int currmode; +extern char currboard[]; /* name of currently selected board */ +extern char *str_space; +extern char *str_author1; +extern char *str_author2; +extern userinfo_t *currutmp; +extern unsigned int currstat; +extern pid_t currpid; +extern int usernum; +extern char *str_mail_address; +extern userec_t cuser; + +char currmaildir[32]; +static char msg_cc[] = "\033[32m[群組名單]\033[m\n"; +static char listfile[] = "list.0"; +static int mailkeep = 0, mailsum = 0; +static int mailsumlimit = 0,mailmaxkeep = 0; + +int setforward() { + char buf[80], ip[50] = "", yn[4]; + FILE *fp; + + sethomepath(buf, cuser.userid); + strcat(buf,"/.forward"); + if((fp = fopen(buf,"r"))) { + fscanf(fp,"%s",ip); + fclose(fp); + } + getdata_buf(b_lines - 1, 0, "請輸入信箱自動轉寄的email地址:", + ip, 41, DOECHO); + if(ip[0] && ip[0] != ' ') { + getdata(b_lines, 0, "確定開啟自動轉信功\能?(Y/n)", yn, 3, + LCECHO); + if(yn[0] != 'n' && (fp = fopen(buf, "w"))) { + move(b_lines,0); + clrtoeol(); + fprintf(fp,"%s",ip); + fclose(fp); + outs("設定完成!"); + refresh(); + return 0; + } + } + move(b_lines,0); + clrtoeol(); + outs("取消自動轉信!"); + unlink(buf); + refresh(); + return 0; +} + +int built_mail_index() { + char genbuf[128]; + + getdata(b_lines, 0, + "重建信箱?(警告:請確定信箱有問題時才使用)(y/N)", genbuf, 3, + LCECHO); + if(genbuf[0] != 'y') return 0; + + sprintf(genbuf, BBSHOME "/bin/buildir " BBSHOME "/home/%c/%s", + cuser.userid[0], cuser.userid); + move(22,0); + prints("\033[1;31m已經處理完畢!! 諸多不便 敬請原諒~\033[m");pressanykey(); + system(genbuf); + return 0; +} + +int mailalert(char *userid) +{ + userinfo_t *uentp=NULL; + int n,tuid,i; + + if((tuid=searchuser(userid))==0) return -1; + + n=count_logins(tuid, 0); + for(i=1;i<=n;i++) + if((uentp = (userinfo_t *)search_ulistn(tuid, i))) + uentp->mailalert=1; + return 0; +} + +int mail_muser(userec_t muser, char *title, char *filename) { + return mail_id(muser.userid, title, filename, cuser.userid); +} + +/* Heat: 用id來寄信,內容則link準備好的檔案 */ +int mail_id(char* id, char *title, char *filename, char *owner) { + fileheader_t mhdr; + char genbuf[128]; + sethomepath(genbuf, id); + if(stampfile(genbuf, &mhdr)) + return 0; + strcpy(mhdr.owner, owner); + strncpy(mhdr.title, title, TTLEN); + mhdr.savemode = 0; + mhdr.filemode = 0; + Link(filename, genbuf); + sethomedir(genbuf,id); + append_record(genbuf, &mhdr, sizeof(mhdr)); + mailalert(id); + return 0; +} + +int invalidaddr(char *addr) { + if(*addr == '\0') + return 1; /* blank */ + while(*addr) { + if(not_alnum(*addr) && !strchr("[].%!@:-_;", *addr)) + return 1; + addr++; + } + return 0; +} + +int m_internet() { + char receiver[60]; + + getdata(20, 0, "收信人:", receiver, 60, DOECHO); + if(strchr(receiver, '@') && !invalidaddr(receiver) && + getdata(21, 0, "主 題:", save_title, TTLEN, DOECHO)) + do_send(receiver, save_title); + else { + move(22, 0); + outs("收信人或主題不正確, 請重新選取指令"); + pressanykey(); + } + return 0; +} + +void m_init() { + sethomedir(currmaildir, cuser.userid); +} + +int chkmailbox() { + if(!HAVE_PERM(PERM_SYSOP) && !HAVE_PERM(PERM_MAILLIMIT)) { + int max_keepmail = MAX_KEEPMAIL; + if ( HAS_PERM(PERM_SYSSUBOP) || HAS_PERM(PERM_SMG) || + HAS_PERM(PERM_PRG) || HAS_PERM(PERM_ACTION) || HAS_PERM(PERM_PAINT)) + { + mailsumlimit = 700; + max_keepmail = 500; + } + else if(HAS_PERM(PERM_BM)) + { + mailsumlimit = 500; + max_keepmail = 300; + } + else if(HAS_PERM(PERM_LOGINOK)) + mailsumlimit = 200; + else + mailsumlimit = 50; + mailsumlimit += cuser.exmailbox * 10; + mailmaxkeep = max_keepmail + cuser.exmailbox; + m_init(); + if((mailkeep = get_num_records(currmaildir, sizeof(fileheader_t))) > + mailmaxkeep) { + move(b_lines, 0); + clrtoeol(); + bell(); + prints("您保存信件數目 %d 超出上限 %d, 請整理", + mailkeep, mailmaxkeep); + bell(); + refresh(); + igetch(); + return mailkeep; + } + if((mailsum = get_sum_records(currmaildir, sizeof(fileheader_t))) > + mailsumlimit) { + move(b_lines, 0); + clrtoeol(); + bell(); + prints("您保存信件容量 %d(k)超出上限 %d(k), 請整理", + mailsum, mailsumlimit); + bell(); + refresh(); + igetch(); + return mailkeep; + } + } + return 0; +} + +static void do_hold_mail(char *fpath, char *receiver, char *holder) { + char buf[80], title[128]; + + fileheader_t mymail; + + sethomepath(buf, holder); + stampfile(buf, &mymail); + + mymail.savemode = 'H'; /* hold-mail flag */ + mymail.filemode = FILE_READ; + strcpy(mymail.owner, "[備.忘.錄]"); + if(receiver) { + sprintf(title, "(%s) %s", receiver, save_title); + strncpy(mymail.title, title, TTLEN); + } else + strcpy(mymail.title, save_title); + + sethomedir(title, holder); + + unlink(buf); + Link(fpath, buf); + /* Ptt: append_record->do_append */ + do_append(title, &mymail, sizeof(mymail)); +} + +extern userec_t xuser; + +void hold_mail(char *fpath, char *receiver) { + char buf[4]; + + getdata(b_lines - 1, 0, "已順利寄出,是否自存底稿(Y/N)?[N] ", + buf, 4, LCECHO); + + if(buf[0] == 'y') + do_hold_mail(fpath, receiver, cuser.userid); +} + +int do_send(char *userid, char *title) { + fileheader_t mhdr; + char fpath[STRLEN]; + char receiver[IDLEN]; + char genbuf[200]; + int internet_mail, i; + + if(strchr(userid, '@')) + internet_mail = 1; + else { + internet_mail = 0; + if(!getuser(userid)) + return -1; + if(!(xuser.userlevel & PERM_READMAIL)) + return -3; + + if(!title) + getdata(2, 0, "主題:", save_title, TTLEN, DOECHO); + curredit |= EDIT_MAIL; + curredit &= ~EDIT_ITEM; + } + + setutmpmode(SMAIL); + + fpath[0] = '\0'; + + if(internet_mail) { + int res, ch; + + if(vedit(fpath, NA, NULL) == -1) { + unlink(fpath); + clear(); + return -2; + } + clear(); + prints("信件即將寄給 %s\n標題為:%s\n確定要寄出嗎? (Y/N) [Y]", + userid, title); + ch = igetch(); + switch(ch) { + case 'N': + case 'n': + outs("N\n信件已取消"); + res = -2; + break; + default: + outs("Y\n請稍候, 信件傳遞中...\n"); + res = +#ifndef USE_BSMTP + bbs_sendmail(fpath, title, userid); +#else + bsmtp(fpath, title, userid,0); +#endif + hold_mail(fpath, userid); + } + unlink(fpath); + return res; + } else { + strcpy(receiver, userid); + sethomepath(genbuf, userid); + stampfile(genbuf, &mhdr); + strcpy(mhdr.owner, cuser.userid); + strncpy(mhdr.title, save_title, TTLEN); + mhdr.savemode = '\0'; + if(vedit(genbuf, YEA, NULL) == -1) { + unlink(genbuf); + clear(); + return -2; + } + clear(); + sethomefile(fpath, userid, FN_OVERRIDES); + i=belong(fpath, cuser.userid); + sethomefile(fpath, userid, FN_REJECT); + + if(i || !belong(fpath, cuser.userid)) //Ptt:用belong有點討厭 + { + sethomedir(fpath, userid); + if(append_record(fpath, &mhdr, sizeof(mhdr)) == -1) + return -1; + mailalert(userid); + } + hold_mail(genbuf, userid); + return 0; + } +} + +void my_send(char *uident) { + switch(do_send(uident, NULL)) { + case -1: + outs(err_uid); + break; + case -2: + outs(msg_cancel); + break; + case -3: + prints("使用者 [%s] 無法收信", uident); + break; + } + pressanykey(); +} + +int m_send() { + char uident[40]; + + stand_title("且聽風的話"); + usercomplete(msg_uid, uident); + showplans(uident); + if(uident[0]) + my_send(uident); + return 0; +} + +/* 群組寄信、回信 : multi_send, multi_reply */ +extern struct word_t *toplev; + +static void multi_list(int *reciper) { + char uid[16]; + char genbuf[200]; + + while(1) { + stand_title("群組寄信名單"); + ShowNameList(3, 0, msg_cc); + getdata(1, 0, + "(I)引入好友 (O)引入上線通知 (N)引入新文章通知 " + "(0-9)引入其他特別名單\n" + "(A)增加 (D)刪除 (M)確認寄信名單 (Q)取消 ?[M]", + genbuf, 4, LCECHO); + switch(genbuf[0]) { + case 'a': + while(1) { + move(1, 0); + usercomplete("請輸入要增加的代號(只按 ENTER 結束新增): ", uid); + if(uid[0] == '\0') + break; + + move(2, 0); + clrtoeol(); + + if(!searchuser(uid)) + outs(err_uid); + else if(!InNameList(uid)) { + AddNameList(uid); + (*reciper)++; + } + ShowNameList(3, 0, msg_cc); + } + break; + case 'd': + while(*reciper) { + move(1, 0); + namecomplete("請輸入要刪除的代號(只按 ENTER 結束刪除): ", uid); + if(uid[0] == '\0') + break; + if(RemoveNameList(uid)) + (*reciper)--; + ShowNameList(3, 0, msg_cc); + } + break; + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + listfile[5] = genbuf[0]; + genbuf[0] = '1'; + case 'i': + setuserfile(genbuf, genbuf[0] == '1' ? listfile : fn_overrides); + ToggleNameList(reciper, genbuf, msg_cc); + break; + case 'o': + setuserfile(genbuf, "alohaed"); + ToggleNameList(reciper, genbuf, msg_cc); + break; + case 'n': + setuserfile(genbuf, "postlist"); + ToggleNameList(reciper, genbuf, msg_cc); + break; + case 'q': + *reciper = 0; + return; + default: + return; + } + } +} + +static void multi_send(char *title) { + FILE *fp; + struct word_t *p; + fileheader_t mymail; + char fpath[TTLEN], *ptr; + int reciper, listing; + char genbuf[256]; + + CreateNameList(); + listing = reciper = 0; + if(*quote_file) { + AddNameList(quote_user); + reciper = 1; + fp = fopen(quote_file, "r"); + while(fgets(genbuf, 256, fp)) { + if(strncmp(genbuf, "※ ", 3)) { + if(listing) + break; + } else { + if(listing) { + strtok(ptr = genbuf + 3, " \n\r"); + do { + if(searchuser(ptr) && !InNameList(ptr) && + strcmp(cuser.userid, ptr)) { + AddNameList(ptr); + reciper++; + } + } while((ptr = (char *)strtok(NULL, " \n\r"))); + } else if(!strncmp(genbuf + 3, "[通告]", 6)) + listing = 1; + } + } + ShowNameList(3, 0, msg_cc); + } + + multi_list(&reciper); + move(1, 0); + clrtobot(); + + if(reciper) { + setutmpmode(SMAIL); + if(title) + do_reply_title(2, title); + else { + getdata(2, 0, "主題:", fpath, 64, DOECHO); + sprintf(save_title, "[通告] %s", fpath); + } + + setuserfile(fpath, fn_notes); + + if((fp = fopen(fpath, "w"))) { + fprintf(fp, "※ [通告] 共 %d 人收件", reciper); + listing = 80; + + for(p = toplev; p; p = p->next) { + reciper = strlen(p->word) + 1; + if(listing + reciper > 75) { + listing = reciper; + fprintf(fp, "\n※"); + } else + listing += reciper; + + fprintf(fp, " %s", p->word); + } + memset(genbuf, '-', 75); + genbuf[75] = '\0'; + fprintf(fp, "\n%s\n\n", genbuf); + fclose(fp); + } + + curredit |= EDIT_LIST; + + if(vedit(fpath, YEA, NULL) == -1) { + unlink(fpath); + curredit = 0; + outs(msg_cancel); + pressanykey(); + return; + } + + stand_title("寄信中..."); + refresh(); + + listing = 80; + + for(p = toplev; p; p = p->next) { + reciper = strlen(p->word) + 1; + if(listing + reciper > 75) { + listing = reciper; + outc('\n'); + } else { + listing += reciper; + outc(' '); + } + outs(p->word); + if(searchuser(p->word) && strcmp(STR_GUEST, p->word) ) + sethomepath(genbuf, p->word); + else + continue; + stampfile(genbuf, &mymail); + unlink(genbuf); + Link(fpath, genbuf); + + strcpy(mymail.owner, cuser.userid); + strcpy(mymail.title, save_title); + mymail.savemode = 'M'; /* multi-send flag */ + sethomedir(genbuf, p->word); + if(append_record(genbuf, &mymail, sizeof(mymail)) == -1) + outs(err_uid); + mailalert(p->word); + } + hold_mail(fpath, NULL); + unlink(fpath); + curredit = 0; + } else + outs(msg_cancel); + pressanykey(); +} + +static int multi_reply(int ent, fileheader_t *fhdr, char *direct) { + if(fhdr->savemode != 'M') + return mail_reply(ent, fhdr, direct); + + stand_title("群組回信"); + strcpy(quote_user, fhdr->owner); + setuserfile(quote_file, fhdr->filename); + multi_send(fhdr->title); + return 0; +} + +int mail_list() { + stand_title("群組作業"); + multi_send(NULL); + return 0; +} + +int mail_all() { + FILE *fp; + fileheader_t mymail; + char fpath[TTLEN]; + char genbuf[200]; + extern struct uhash_t *uhash; + int i, unum; + char *userid; + + stand_title("給所有使用者的系統通告"); + setutmpmode(SMAIL); + getdata(2, 0, "主題:", fpath, 64, DOECHO); + sprintf(save_title, "[系統通告]\033[1;32m %s\033[m", fpath); + + setuserfile(fpath, fn_notes); + + if((fp = fopen(fpath, "w"))) { + fprintf(fp, "※ [\033[1m系統通告\033[m] 這是封給所有使用者的信\n"); + fprintf(fp, "-----------------------------------------------------" + "----------------------\n"); + fclose(fp); + } + + *quote_file = 0; + + curredit |= EDIT_MAIL; + curredit &= ~EDIT_ITEM; + if(vedit(fpath, YEA, NULL) == -1) { + curredit = 0; + unlink(fpath); + outs(msg_cancel); + pressanykey(); + return 0; + } + curredit = 0; + + setutmpmode(MAILALL); + stand_title("寄信中..."); + + sethomepath(genbuf, cuser.userid); + stampfile(genbuf, &mymail); + unlink(genbuf); + Link(fpath, genbuf); + unlink(fpath); + strcpy(fpath, genbuf); + + strcpy(mymail.owner, cuser.userid); /*站長 ID*/ + strcpy(mymail.title, save_title); + mymail.savemode = 0; + + sethomedir(genbuf, cuser.userid); + if(append_record(genbuf, &mymail, sizeof(mymail)) == -1) + outs(err_uid); + + for(unum = uhash->number, i = 0; i < unum; i++) { + if(bad_user_id(uhash->userid[i])) + continue; /* Ptt */ + + userid = uhash->userid[i]; + if(strcmp(userid,STR_GUEST) && strcmp(userid, "new") && + strcmp(userid, cuser.userid)) { + sethomepath(genbuf, userid); + stampfile(genbuf, &mymail); + unlink(genbuf); + Link(fpath, genbuf); + + strcpy(mymail.owner, cuser.userid); + strcpy(mymail.title, save_title); + mymail.savemode = 0; + /* mymail.filemode |= FILE_MARKED; Ptt 公告改成不會mark */ + sethomedir(genbuf, userid); + if(append_record(genbuf, &mymail, sizeof(mymail)) == -1) + outs(err_uid); + sprintf(genbuf, "%*s %5d / %5d", IDLEN + 1, userid, i + 1, unum); + outmsg(genbuf); + refresh(); + } + } + return 0; +} + +int mail_mbox() { + char cmd[100]; + fileheader_t fhdr; + + sprintf(cmd, "/tmp/%s.uu", cuser.userid); + sprintf(fhdr.title, "%s 私人資料", cuser.userid); + doforward(cmd, &fhdr, 'Z'); + return 0; +} + +static int m_forward(int ent, fileheader_t *fhdr, char *direct) { + char uid[STRLEN]; + + stand_title("轉達信件"); + usercomplete(msg_uid, uid); + if(uid[0] == '\0') + return FULLUPDATE; + + strcpy(quote_user, fhdr->owner); + setuserfile(quote_file, fhdr->filename); + sprintf(save_title, "%.64s (fwd)", fhdr->title); + move(1, 0); + clrtobot(); + prints("轉信給: %s\n標 題: %s\n", uid, save_title); + + switch(do_send(uid, save_title)) { + case -1: + outs(err_uid); + break; + case -2: + outs(msg_cancel); + break; + case -3: + prints("使用者 [%s] 無法收信", uid); + break; + } + pressanykey(); + return FULLUPDATE; +} + +static int delmsgs[128]; +static int delcnt; +static int mrd; + +static int read_new_mail(fileheader_t *fptr) { + static int idc; + char done = NA, delete_it; + char fname[256]; + char genbuf[4]; + + if(fptr == NULL) { + delcnt = 0; + idc = 0; + return 0; + } + idc++; + if(fptr->filemode) + return 0; + clear(); + move(10, 0); + prints("您要讀來自[%s]的訊息(%s)嗎?", fptr->owner, fptr->title); + getdata(11, 0, "請您確定(Y/N/Q)?[Y] ", genbuf, 3, DOECHO); + if(genbuf[0] == 'q') + return QUIT; + if(genbuf[0] == 'n') + return 0; + + setuserfile(fname, fptr->filename); + fptr->filemode |= FILE_READ; + if(substitute_record(currmaildir, fptr, sizeof(*fptr), idc)) + return -1; + + mrd = 1; + delete_it = NA; + while(!done) { + int more_result = more(fname, YEA); + + switch(more_result) { + case 1: + return READ_PREV; + case 2: + return RELATE_PREV; + case 3: + return READ_NEXT; + case 4: + return RELATE_NEXT; + case 5: + return RELATE_FIRST; + case 6: + return 0; + case 7: + mail_reply(idc, fptr, currmaildir); + return FULLUPDATE; + case 8: + multi_reply(idc, fptr, currmaildir); + return FULLUPDATE; + } + move(b_lines, 0); + clrtoeol(); + outs(msg_mailer); + refresh(); + + switch(egetch()) { + case 'r': + case 'R': + mail_reply(idc, fptr, currmaildir); + break; + case 'x': + m_forward(idc, fptr, currmaildir); + break; + case 'y': + multi_reply(idc, fptr, currmaildir); + break; + case 'd': + case 'D': + delete_it = YEA; + default: + done = YEA; + } + } + if(delete_it) { + clear(); + prints("刪除信件《%s》", fptr->title); + getdata(1, 0, msg_sure_ny, genbuf, 2, LCECHO); + if(genbuf[0] == 'y') { + unlink(fname); + delmsgs[delcnt++] = idc; + } + } + clear(); + return 0; +} + +int m_new() { + clear(); + mrd = 0; + setutmpmode(RMAIL); + read_new_mail(NULL); + clear(); + curredit |= EDIT_MAIL; + curredit &= ~EDIT_ITEM; + if(apply_record(currmaildir, read_new_mail, sizeof(fileheader_t)) == -1) { + outs("沒有新信件了"); + pressanykey(); + return -1; + } + curredit = 0; + if(delcnt) { + while(delcnt--) + delete_record(currmaildir, sizeof(fileheader_t), delmsgs[delcnt]); + } + outs(mrd ? "信已閱\畢" : "沒有新信件了"); + pressanykey(); + return -1; +} + +static void mailtitle() { + char buf[256] = ""; + + showtitle("\0郵件選單", BBSName); + sprintf(buf,"[←]離開[↑↓]選擇[→]閱\讀信件 [R]回信 [x]轉達 " + "[y]群組回信 [O]站外信:%s [h]求助\n\033[7m" + "編號 日 期 作 者 信 件 標 題 \033[32m", + HAS_PERM(PERM_NOOUTMAIL)? "\033[31m關\033[m":"開"); + outs(buf); + buf[0]=0; + if(mailsumlimit) { + sprintf(buf,"(容量:%d/%dk %d/%d篇)", mailsum, mailsumlimit, + mailkeep, mailmaxkeep); + } + sprintf(buf, "%s%*s\033[m", buf, 29 - (int) strlen(buf), ""); + outs(buf); +} + +static void maildoent(int num, fileheader_t *ent) { + char *title, *mark, color, type = "+ Mm"[ent->filemode]; + + if (TagNum && !Tagger(atoi(ent->filename + 2), 0, TAG_NIN)) + type = 'D'; + + title = subject(mark = ent->title); + if(title == mark) { + color = '1'; + mark = "◇"; + } else { + color = '3'; + mark = "R:"; + } + + if(strncmp(currtitle, title, 40)) + prints("%5d %c %-7s%-15.14s%s %.46s\n", num, type, + ent->date, ent->owner, mark, title); + else + prints("%5d %c %-7s%-15.14s\033[1;3%cm%s %.46s\033[0m\n", num, type, + ent->date, ent->owner, color, mark, title); +} + +#ifdef POSTBUG +extern int bug_possible; +#endif + + +static int m_idle(int ent, fileheader_t *fhdr, char *direct) { + t_idle(); + return FULLUPDATE; +} + +static int mail_del(int ent, fileheader_t *fhdr, char *direct) { + char genbuf[200]; + + if(fhdr->filemode & FILE_MARKED) + return DONOTHING; + + getdata(1, 0, msg_del_ny, genbuf, 3, LCECHO); + if(genbuf[0] == 'y') { + strcpy(currfile, fhdr->filename); + if(!delete_file(direct, sizeof(*fhdr), ent, cmpfilename)) { + setdirpath(genbuf, direct, fhdr->filename); + unlink(genbuf); + if((currmode & MODE_SELECT)) { + int now; + + sethomedir(genbuf, cuser.userid); + now = getindex(genbuf, fhdr->filename, sizeof(fileheader_t)); + delete_file(genbuf, sizeof(fileheader_t), now, cmpfilename); + } + return DIRCHANGED; + } + } + return FULLUPDATE; +} + +static int mail_read(int ent, fileheader_t *fhdr, char *direct) { + char buf[64]; + char done, delete_it, replied; + + clear(); + setdirpath(buf, direct, fhdr->filename); + strncpy(currtitle, subject(fhdr->title), 40); + done = delete_it = replied = NA; + while(!done) { + int more_result = more(buf, YEA); + + if(more_result != -1) { + fhdr->filemode |= FILE_READ; + if((currmode & MODE_SELECT)) { + int now; + + now = getindex(currmaildir, fhdr->filename, + sizeof(fileheader_t)); + substitute_record(currmaildir, fhdr, sizeof(*fhdr), now); + substitute_record(direct, fhdr, sizeof(*fhdr), ent); + } + else + substitute_record(currmaildir, fhdr, sizeof(*fhdr), ent); + } + switch(more_result) { + case 1: + return READ_PREV; + case 2: + return RELATE_PREV; + case 3: + return READ_NEXT; + case 4: + return RELATE_NEXT; + case 5: + return RELATE_FIRST; + case 6: + return FULLUPDATE; + case 7: + mail_reply(ent, fhdr, direct); + return FULLUPDATE; + case 8: + multi_reply(ent, fhdr, direct); + return FULLUPDATE; + } + move(b_lines, 0); + clrtoeol(); + refresh(); + outs(msg_mailer); + + switch(egetch()) { + case 'r': + case 'R': + replied = YEA; + mail_reply(ent, fhdr, direct); + break; + case 'x': + m_forward(ent, fhdr, direct); + break; + case 'y': + multi_reply(ent, fhdr, direct); + break; + case 'd': + delete_it = YEA; + default: + done = YEA; + } + } + if(delete_it) + mail_del(ent, fhdr, direct); + else { + fhdr->filemode |= FILE_READ; +#ifdef POSTBUG + if(replied) + bug_possible = YEA; +#endif + if((currmode & MODE_SELECT)) { + int now; + + now = getindex(currmaildir, fhdr->filename, sizeof(fileheader_t)); + substitute_record(currmaildir, fhdr, sizeof(*fhdr), now); + substitute_record(direct, fhdr, sizeof(*fhdr), ent); + } else + substitute_record(currmaildir, fhdr, sizeof(*fhdr), ent); +#ifdef POSTBUG + bug_possible = NA; +#endif + } + return FULLUPDATE; +} + +/* in boards/mail 回信給原作者,轉信站亦可 */ +int mail_reply(int ent, fileheader_t *fhdr, char *direct) { + char uid[STRLEN]; + char *t; + FILE *fp; + char genbuf[512]; + + stand_title("回 信"); + + /* 判斷是 boards 或 mail */ + if(curredit & EDIT_MAIL) + setuserfile(quote_file, fhdr->filename); + else + setbfile(quote_file, currboard, fhdr->filename); + + /* find the author */ + strcpy(quote_user, fhdr->owner); + if(strchr(quote_user, '.')) { + genbuf[0] = '\0'; + if((fp = fopen(quote_file, "r"))) { + fgets(genbuf, 512, fp); + fclose(fp); + } + + t = strtok(genbuf, str_space); + if(!strcmp(t, str_author1) || !strcmp(t, str_author2)) + strcpy(uid, strtok(NULL, str_space)); + else { + outs("錯誤: 找不到作者。"); + pressanykey(); + return FULLUPDATE; + } + } else + strcpy(uid, quote_user); + + /* make the title */ + do_reply_title(3, fhdr->title); + prints("\n收信人: %s\n標 題: %s\n", uid, save_title); + + /* edit, then send the mail */ + ent = curredit; + switch(do_send(uid, save_title)) { + case -1: + outs(err_uid); + break; + case -2: + outs(msg_cancel); + break; + case -3: + prints("使用者 [%s] 無法收信", uid); + break; + } + curredit = ent; + pressanykey(); + return FULLUPDATE; +} + +static int mail_edit(int ent, fileheader_t *fhdr, char *direct) { + char genbuf[200]; + + if(!HAS_PERM(PERM_SYSOP) && + strcmp(cuser.userid, fhdr->owner) && + strcmp("[備.忘.錄]", fhdr->owner)) + return DONOTHING; + + setdirpath(genbuf, direct, fhdr->filename); + vedit(genbuf, NA, NULL); + return FULLUPDATE; +} + +static int mail_nooutmail(int ent, fileheader_t *fhdr, char *direct) +{ + cuser.userlevel ^= PERM_NOOUTMAIL; + passwd_update(usernum, &cuser); + return FULLUPDATE; + +} + +static int mail_mark(int ent, fileheader_t *fhdr, char *direct) { + fhdr->filemode ^= FILE_MARKED; + + if((currmode & MODE_SELECT)) { + int now; + + now = getindex(currmaildir, fhdr->filename, sizeof(fileheader_t)); + substitute_record(currmaildir, fhdr, sizeof(*fhdr), now); + substitute_record(direct, fhdr, sizeof(*fhdr), ent); + } else + substitute_record(currmaildir, fhdr, sizeof(*fhdr), ent); + return PART_REDRAW; +} + +/* help for mail reading */ +static char *mail_help[] = { + "\0電子信箱操作說明", + "\01基本命令", + "(p)(↑) 前一篇文章", + "(n)(↓) 下一篇文章", + "(P)(PgUp) 前一頁", + "(N)(PgDn) 下一頁", + "(##)(cr) 跳到第 ## 筆", + "($) 跳到最後一筆", + "\01進階命令", + "(r)(→)/(R)讀信 / 回信", + "(O) 關閉/開啟 站外信件轉入", + "(c/z) 收入此信件進入私人信件夾/進入私人信件夾", + "(x/X) 轉達信件/轉錄文章到其他看板", + "(y) 群組回信", + "(F) 將信傳送回您的電子信箱 (u)水球整理寄回信箱", + "(d) 殺掉此信", + "(D) 殺掉指定範圍的信", + "(m) 將信標記,以防被清除", + "(^G) 立即重建信箱 (信箱毀損時用)", + "(t) 標記欲刪除信件", + "(^D) 刪除已標記信件", + NULL +}; + +static int m_help() { + show_help(mail_help); + return FULLUPDATE; +} + +static int mail_cross_post(int ent, fileheader_t *fhdr, char *direct) { + char xboard[20], fname[80], xfpath[80], xtitle[80], inputbuf[10]; + fileheader_t xfile; + FILE *xptr; + int author = 0; + char genbuf[200]; + char genbuf2[4]; + + make_blist(); + move(2, 0); + clrtoeol(); + move(3, 0); + clrtoeol(); + move(1, 0); + namecomplete("轉錄本文章於看板:", xboard); + if(*xboard == '\0' || !haspostperm(xboard)) + return FULLUPDATE; + + ent = 1; + if(HAS_PERM(PERM_SYSOP) || !strcmp(fhdr->owner, cuser.userid)) { + getdata(2, 0, "(1)原文轉載 (2)舊轉錄格式?[1] ", + genbuf, 3, DOECHO); + if(genbuf[0] != '2') { + ent = 0; + getdata(2, 0, "保留原作者名稱嗎?[Y] ", inputbuf, 3, DOECHO); + if(inputbuf[0] != 'n' && inputbuf[0] != 'N') + author = 1; + } + } + + if(ent) + sprintf(xtitle, "[轉錄]%.66s", fhdr->title); + else + strcpy(xtitle, fhdr->title); + + sprintf(genbuf, "採用原標題《%.60s》嗎?[Y] ", xtitle); + getdata(2, 0, genbuf, genbuf2, 4, LCECHO); + if(*genbuf2 == 'n') + if(getdata(2, 0, "標題:", genbuf, TTLEN, DOECHO)) + strcpy(xtitle, genbuf); + + getdata(2, 0, "(S)存檔 (L)站內 (Q)取消?[Q] ", genbuf, 3, LCECHO); + if(genbuf[0] == 'l' || genbuf[0] == 's') { + int currmode0 = currmode; + + currmode = 0; + setbpath(xfpath, xboard); + stampfile(xfpath, &xfile); + if(author) + strcpy(xfile.owner, fhdr->owner); + else + strcpy(xfile.owner, cuser.userid); + strcpy(xfile.title, xtitle); + if(genbuf[0] == 'l') { + xfile.savemode = 'L'; + xfile.filemode = FILE_LOCAL; + } else + xfile.savemode = 'S'; + + setuserfile(fname, fhdr->filename); + if(ent) { + xptr = fopen(xfpath, "w"); + + strcpy(save_title, xfile.title); + strcpy(xfpath, currboard); + strcpy(currboard, xboard); + write_header(xptr); + strcpy(currboard, xfpath); + + fprintf(xptr, "※ [本文轉錄自 %s 信箱]\n\n", cuser.userid); + + b_suckinfile(xptr, fname); + addsignature(xptr,0); + fclose(xptr); + } else { + unlink(xfpath); + Link(fname, xfpath); + } + + setbdir(fname, xboard); + append_record(fname, &xfile, sizeof(xfile)); + setbtotal(getbnum(xboard)); + if(!xfile.filemode) + outgo_post(&xfile, xboard); + cuser.numposts++; + passwd_update(usernum, &cuser); + outs("文章轉錄完成"); + pressanykey(); + currmode = currmode0; + } + return FULLUPDATE; +} + +int mail_man() { + char buf[64],buf1[64]; + if (HAS_PERM(PERM_MAILLIMIT)) { + int mode0 = currutmp->mode; + int stat0 = currstat; + + sethomeman(buf, cuser.userid); + sprintf(buf1, "%s 的信件夾", cuser.userid); + a_menu(buf1, buf, 1); + currutmp->mode = mode0; + currstat = stat0; + return FULLUPDATE; + } + return DONOTHING; +} + +static int mail_cite(int ent, fileheader_t *fhdr, char *direct) { + char fpath[256]; + char title[TTLEN + 1]; + static char xboard[20]; + char buf[20]; + boardheader_t *bp; + + setuserfile(fpath, fhdr->filename); + strcpy(title, "◇ "); + strncpy(title+3, fhdr->title, TTLEN-3); + title[TTLEN] = '\0'; + a_copyitem(fpath, title, 0, 1); + + if(cuser.userlevel >= PERM_BM) { + move(2, 0); + clrtoeol(); + move(3, 0); + clrtoeol(); + move(1, 0); + make_blist(); + namecomplete("輸入看版名稱 (直接Enter進入私人信件夾):", buf); + if(*buf) + strcpy(xboard, buf); + if(*xboard && (bp = getbcache(getbnum(xboard)))) { + setapath(fpath, xboard); + setutmpmode(ANNOUNCE); + a_menu(xboard, fpath, HAS_PERM(PERM_ALLBOARD) ? 2 : + is_BM(bp->BM) ? 1 : 0); + } else { + mail_man(); + } + return FULLUPDATE; + } else { + mail_man(); + return FULLUPDATE; + } +} + +static int mail_save(int ent, fileheader_t *fhdr, char *direct) { + char fpath[256]; + char title[TTLEN+1]; + + if(HAS_PERM(PERM_MAILLIMIT)) { + setuserfile(fpath, fhdr->filename); + strcpy(title, "◇ "); + strncpy(title + 3, fhdr->title, TTLEN - 3); + title[TTLEN] = '\0'; + a_copyitem(fpath, title, fhdr->owner, 1); + sethomeman(fpath, cuser.userid); + a_menu(cuser.userid, fpath, 1); + return FULLUPDATE; + } + return DONOTHING; +} + +#ifdef OUTJOBSPOOL +static int mail_waterball(int ent, fileheader_t *fhdr, char *direct) +{ + static char address[60], cmode = 1; + char fname[500], genbuf[200]; + FILE *fp; + int now; + + if(!address[0]) + strcpy(address, cuser.email); + if(address[0]) { + sprintf(genbuf, "寄給 [%s] 嗎(Y/N/Q)?[Y] ", address); + getdata(b_lines - 2, 0, genbuf, fname, 3, LCECHO); + if(fname[0] == 'q') { outmsg("取消處理"); return 1; } + if(fname[0] == 'n') + address[0] = '\0'; + } + + if(!address[0]) { + getdata(b_lines - 2, 0, "請輸入郵件地址:", fname, 60, DOECHO); + if(fname[0] && strchr(fname, '.')) { + strcpy(address, fname); + } else { + outmsg("取消處理"); + return 1; + } + } + if(invalidaddr(address)) + return -2; + + // sprintf(fname, "%d\n", cmode); + getdata(b_lines - 1, 0, "使用模式(0/1)? [1]", fname, 3, LCECHO); + cmode = (fname[0] != '0' && fname[0] != '1') ? 1 : fname[0] - '0'; + + now = time(NULL); + sprintf(fname, BBSHOME "/jobspool/water.src.%s-%d", + cuser.userid, now); + sprintf(genbuf, "cp " BBSHOME "/home/%c/%s/%s %s", + cuser.userid[0], cuser.userid, fhdr->filename, fname); + system(genbuf); + /* dirty code ;x */ + sprintf(fname, BBSHOME "/jobspool/water.des.%s-%d", + cuser.userid, now); + fp = fopen(fname, "wt"); + fprintf(fp, "%s\n%s\n%d\n", cuser.userid, address, cmode); + fclose(fp); + return FULLUPDATE; +} +#endif +static struct onekey_t mail_comms[] = { + {'z', mail_man}, + {'c', mail_cite}, + {'s', mail_save}, + {'d', mail_del}, + {'D', del_range}, + {'r', mail_read}, + {'R', mail_reply}, + {'E', mail_edit}, + {'m', mail_mark}, + {'O', mail_nooutmail}, + {'T', edit_title}, + {'x', m_forward}, + {'X', mail_cross_post}, + {Ctrl('G'), built_mail_index}, /* 修信箱 */ + {'y', multi_reply}, + {Ctrl('I'), m_idle}, + {'h', m_help}, +#ifdef OUTJOBSPOOL + {'u', mail_waterball}, +#endif + {'\0', NULL} +}; + +int m_read() { + if(get_num_records(currmaildir, sizeof(fileheader_t))) { + curredit = EDIT_MAIL; + curredit &= ~EDIT_ITEM; + i_read(RMAIL, currmaildir, mailtitle, maildoent, mail_comms, -1); + curredit = 0; + currutmp->mailalert = load_mailalert(cuser.userid); + return 0; + } else { + outs("您沒有來信"); + return XEASY; + } +} + +/* 寄站內信 */ +static int send_inner_mail(char *fpath, char *title, char *receiver) { + char genbuf[256]; + fileheader_t mymail; + + if(!searchuser(receiver)) + return -2; + sethomepath(genbuf, receiver); + stampfile(genbuf, &mymail); + if(!strcmp(receiver, cuser.userid)) { + strcpy(mymail.owner, "[" BBSNAME "]"); + mymail.filemode = FILE_READ; + } else + strcpy(mymail.owner, cuser.userid); + strncpy(mymail.title, title, TTLEN); + unlink(genbuf); + Link(fpath, genbuf); + sethomedir(genbuf, receiver); + return do_append(genbuf, &mymail, sizeof(mymail)); +} + +#include +#include +#include + +#ifndef USE_BSMTP +static int bbs_sendmail(char *fpath, char *title, char *receiver) { + static int configured = 0; + static char myhostname[STRLEN]; + static char myusername[20]; + struct hostent *hbuf; + struct passwd *pbuf; + char *ptr; + char genbuf[256]; + FILE *fin, *fout; + + /* 中途攔截 */ + if((ptr = strchr(receiver, ';'))) { + struct tm *ptime; + time_t now; + + *ptr = '\0'; + } + + if((ptr = strstr(receiver, str_mail_address)) || !strchr(receiver,'@')) { + char hacker[20]; + int len; + + if(strchr(receiver,'@')) { + len = ptr - receiver; + memcpy(hacker, receiver, len); + hacker[len] = '\0'; + } else + strcpy(hacker,receiver); + return send_inner_mail(fpath, title, hacker); + } + + /* setup the hostname and username */ + if(!configured) { + /* get host name */ + hbuf = gethostbyname("localhost"); + if(hbuf) + strncpy(myhostname, hbuf->h_name, STRLEN); + + /* get bbs uident */ + pbuf = getpwuid(getuid()); + if(pbuf) + strncpy(myusername, pbuf->pw_name, 20); + if(hbuf && pbuf) + configured = 1; + else + return -1; + } + + /* Running the sendmail */ + if(fpath == NULL) { + sprintf(genbuf, "/usr/sbin/sendmail %s > /dev/null", receiver); + fin = fopen("etc/confirm", "r"); + } else { + sprintf(genbuf, "/usr/sbin/sendmail -f %s%s %s > /dev/null", + cuser.userid, str_mail_address, receiver); + fin = fopen(fpath, "r"); + } + fout = popen(genbuf, "w"); + if(fin == NULL || fout == NULL) + return -1; + + if(fpath) + fprintf(fout, "Reply-To: %s%s\nFrom: %s%s\n", + cuser.userid, str_mail_address, cuser.userid, + str_mail_address); + fprintf(fout, "To: %s\nSubject: %s\n", receiver, title); + fprintf(fout, "X-Disclaimer: " BBSNAME "對本信內容恕不負責。\n\n"); + + while(fgets(genbuf, 255, fin)) { + if(genbuf[0] == '.' && genbuf[1] == '\n') + fputs(". \n", fout); + else + fputs(genbuf, fout); + } + fclose(fin); + fprintf(fout, ".\n"); + pclose(fout); + return 0; +} +#else /* USE_BSMTP */ + +int bsmtp(char *fpath, char *title, char *rcpt, int method) { + char buf[80], *ptr; + time_t chrono; + MailQueue mqueue; + + /* check if the mail is a inner mail */ + if((ptr = strstr(rcpt, str_mail_address)) || !strchr(rcpt, '@')) { + char hacker[20]; + int len; + + if(strchr(rcpt,'@')) { + len = ptr - rcpt; + memcpy(hacker, rcpt, len); + hacker[len] = '\0'; + } else + strcpy(hacker, rcpt); + return send_inner_mail(fpath, title, hacker); + } + + chrono = time(NULL); + if(method != MQ_JUSTIFY) { /* 認證信 */ + /* stamp the queue file */ + strcpy(buf, "out/"); + for(;;) { + sprintf(buf + 4,"M.%ld.A", ++chrono); + if(!dashf(buf)) { + Link(fpath, buf); + break; + } + } + + fpath = buf; + + strcpy(mqueue.filepath, fpath); + strcpy(mqueue.subject, title); + } + /* setup mail queue */ + mqueue.mailtime = chrono; + mqueue.method = method; + strcpy(mqueue.sender, cuser.userid); + strcpy(mqueue.username, cuser.username); + strcpy(mqueue.rcpt, rcpt); + if(do_append("out/.DIR", (fileheader_t *)&mqueue, sizeof(mqueue)) < 0) + return 0; + return chrono; +} +#endif /* USE_BSMTP */ + +int doforward(char *direct, fileheader_t *fh, int mode) { + static char address[60]; + char fname[500]; + int return_no; + char genbuf[200]; + + if(!address[0]) + strcpy(address, cuser.email); + + if(address[0]) { + sprintf(genbuf, "確定轉寄給 [%s] 嗎(Y/N/Q)?[Y] ", address); + getdata(b_lines - 1, 0, genbuf, fname, 3, LCECHO); + + if(fname[0] == 'q') { + outmsg("取消轉寄"); + return 1; + } + if(fname[0] == 'n') + address[0] = '\0'; + } + + if(!address[0]) { + do{ + getdata(b_lines - 1, 0, "請輸入轉寄地址:", fname, 60, DOECHO); + if(fname[0]) { + if(strchr(fname, '.')) + strcpy(address, fname); + else + sprintf(address, "%s.bbs@%s", fname, MYHOSTNAME); + } else { + outmsg("取消轉寄"); + return 1; + } + }while(mode=='Z' && strstr(address, MYHOSTNAME)); + } + if(invalidaddr(address)) + return -2; + + sprintf(fname, "正轉寄給 %s, 請稍候...", address); + outmsg(fname); + move(b_lines - 1, 0); + refresh(); + + /* 追蹤使用者 */ + if(HAS_PERM(PERM_LOGUSER)) { + time_t now = time(NULL); + char msg[200]; + + sprintf(msg, "%s mailforward to %s at %s", + cuser.userid, address, Cdate(&now)); + log_user(msg); + } + + if(mode == 'Z') { + sprintf(fname, TAR_PATH " cfz - home/%c/%s | " + "/usr/bin/uuencode %s.tgz > %s", + cuser.userid[0], cuser.userid, cuser.userid, direct); + system(fname); + strcpy(fname, direct); + } else if(mode == 'U') { + char tmp_buf[128]; + + sprintf(fname, "/tmp/bbs.uu%05d", currpid); + sprintf(tmp_buf, "/usr/bin/uuencode %s/%s uu.%05d > %s", + direct, fh->filename, currpid, fname); + system(tmp_buf); + } else if (mode == 'F'){ + char tmp_buf[128]; + + sprintf(fname, "/tmp/bbs.f%05d", currpid); + sprintf(tmp_buf, "cp %s/%s %s",direct,fh->filename,fname); + system(tmp_buf); + } else + return -1; + + return_no = +#ifndef USE_BSMTP + bbs_sendmail(fname, fh->title, address); +#else + bsmtp(fname, fh->title, address,mode); +#endif + unlink(fname); + return (return_no); +} + +int load_mailalert(char *userid) { + struct stat st; + char maildir[256]; + int fd; + register int numfiles; + fileheader_t my_mail; + + sethomedir(maildir, userid); + if(!HAS_PERM(PERM_BASIC)) + return 0; + if(stat(maildir, &st) < 0) + return 0; + numfiles = st.st_size / sizeof(fileheader_t); + if(numfiles <= 0) + return 0; + + /* 看看有沒有信件還沒讀過?從檔尾回頭檢查,效率較高 */ + if((fd = open(maildir, O_RDONLY)) > 0) { + lseek(fd, st.st_size - sizeof(fileheader_t), SEEK_SET); + while(numfiles--) { + read(fd, &my_mail, sizeof(fileheader_t)); + if(!(my_mail.filemode & FILE_READ)) { + close(fd); + return 1; + } + lseek(fd, -(off_t)2 * sizeof(fileheader_t), SEEK_CUR); + } + close(fd); + } + return 0; +} + +#ifdef EMAIL_JUSTIFY +static void mail_justify(userec_t muser) { + fileheader_t mhdr; + char title[128], buf1[80]; + FILE* fp; + + sethomepath(buf1, muser.userid); + stampfile(buf1, &mhdr); + unlink(buf1); + strcpy(mhdr.owner, cuser.userid); + strncpy(mhdr.title, "[審核通過]", TTLEN); + mhdr.savemode = 0; + mhdr.filemode = 0; + + if(valid_ident(muser.email) && !invalidaddr(muser.email)) { + char title[80], *ptr; + unsigned short checksum; /* 16-bit is enough */ + char ch; + + checksum = searchuser(muser.userid); + ptr = muser.email; + while((ch = *ptr++)) { + if(ch <= ' ') + break; + if(ch >= 'A' && ch <= 'Z') + ch |= 0x20; + checksum = (checksum << 1) ^ ch; + } + + sprintf(title, "[PTT BBS]To %s(%d:%d) [User Justify]", + muser.userid, getuser(muser.userid) + MAGIC_KEY, checksum); + if( +#ifndef USE_BSMTP + bbs_sendmail(NULL, title, muser.email) +#else + bsmtp(NULL, title, muser.email, MQ_JUSTIFY); +#endif + < 0) + Link("etc/bademail", buf1); + else + Link("etc/replyemail", buf1); + } else + Link("etc/bademail", buf1); + sethomedir(title, muser.userid); + append_record(title, &mhdr, sizeof(mhdr)); +} +#endif /* EMAIL_JUSTIFY */ diff --git a/pttbbs/mbbsd/mbbsd.c b/pttbbs/mbbsd/mbbsd.c new file mode 100644 index 00000000..c4849da5 --- /dev/null +++ b/pttbbs/mbbsd/mbbsd.c @@ -0,0 +1,1465 @@ +/* $Id: mbbsd.c,v 1.1 2002/03/07 15:13:48 in2 Exp $ */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "config.h" +#include "pttstruct.h" +#include "common.h" +#include "perm.h" +#include "modes.h" +#include "proto.h" +#ifdef FreeBSD + #include +#else + #include +#endif + +#define SOCKET_QLEN 4 +#define TH_LOW 100 +#define TH_HIGH 120 + +extern int t_lines, t_columns; /* Screen size / width */ +extern int b_lines; /* Screen bottom line number: t_lines-1 */ +extern userinfo_t *currutmp; +extern int curr_idle_timeout; + +static void do_aloha (char *hello); + +static jmp_buf byebye; + +int talkrequest = NA; + +static char remoteusername[40] = "?"; + +extern struct fromcache_t *fcache; +extern struct utmpfile_t *utmpshm; +extern int fcache_semid; + +static unsigned char enter_uflag; +static int use_shell_login_mode = 0; + +char fromhost[STRLEN] = "\0"; + +static struct sockaddr_in xsin; + +/* set signal handler, which won't be reset once signal comes */ +static void +signal_restart (int signum, void (*handler) (int)) +{ + struct sigaction act; + act.sa_handler = handler; + memset (&(act.sa_mask), 0, sizeof (sigset_t)); + act.sa_flags = 0; + sigaction (signum, &act, NULL); +} + +static void +start_daemon () +{ + int n; + char buf[80]; + + /* + * More idiot speed-hacking --- the first time conversion makes the C + * library open the files containing the locale definition and time zone. + * If this hasn't happened in the parent process, it happens in the + * children, once per connection --- and it does add up. + */ + time_t dummy = time (NULL); + struct tm *dummy_time = localtime (&dummy); + + strftime (buf, 80, "%d/%b/%Y:%H:%M:%S", dummy_time); + + if ((n = fork ())){ + exit (0); + } + + /* rocker.011018: it's a good idea to close all unexcept fd!! */ + n = getdtablesize (); + while (n) + close (--n); + /* rocker.011018: we don't need to remember original tty, + so request a new session id */ + setsid (); + + /* rocker.011018: after new session, + we should insure the process is clean daemon */ + if ((n = fork ())){ + exit (0); + } +} + +static void +reapchild (int sig) +{ + int state, pid; + + while ((pid = waitpid (-1, &state, WNOHANG | WUNTRACED)) > 0) + ; +} + +#define BANNER \ +"【" BBSNAME "】◎ 台大流行網 ◎(" MYHOSTNAME ") 調幅(" MYIP ") " +/* +#define BANNER \ +"【" BBSNAME "】◎ 台大流行網 ◎(" MYHOSTNAME ")\r\n"\ +" 調幅(" MYIP ") " +*/ +/* check load and print approriate banner string in buf */ +static int +chkload (char *buf) +{ + char cpu_load[30]; + int i; + + i = cpuload (cpu_load); + + sprintf (buf, BANNER" 系統負荷\r\n %s %s \r\n", cpu_load, + (i > MAX_CPULOAD ? ",高負荷量,請稍後再來 " + "(請利用port 3000~3010連線)" : "")); +#ifdef INSCREEN + strcpy(buf, (i > MAX_CPULOAD ? BANNER + "高負荷量,請稍後再來(請利用port 3000~3010連線)" : "")); +#else + sprintf(buf, BANNER "%s\r\n", + (i > MAX_CPULOAD ? "高負荷量,請稍後再來(請利用port 3000~3010連線)":"")); +#endif + if (i > MAX_CPULOAD) + return 1; + else if (i > MAX_CPULOAD / 2) + curr_idle_timeout = 10 * 60; + else + curr_idle_timeout = 30 * 60; + + return 0; +} + +extern userec_t cuser; + +void +log_user (char *msg) +{ + char filename[200]; + + sprintf (filename, BBSHOME "/home/%c/%s/USERLOG", + cuser.userid[0], cuser.userid); + log_file (filename, msg); +} + +extern time_t login_start_time; + +void +log_usies (char *mode, char *mesg) +{ + char genbuf[200]; + time_t now = time (0); + + if (!mesg) + sprintf (genbuf, cuser.userid[0] ? "%s %s %-12s Stay:%d (%s)" : + "%s %s %s Stay:%d (%s)", + Cdate (&now), mode, cuser.userid, + (int)(now - login_start_time) / 60, cuser.username); + else + sprintf (genbuf, cuser.userid[0] ? "%s %s %-12s %s" : "%s %s %s%s", + Cdate (&now), mode, cuser.userid, mesg); + log_file (FN_USIES, genbuf); + + /* 追蹤使用者 */ + if (HAS_PERM (PERM_LOGUSER)) + log_user (genbuf); +} + +static void +setflags (int mask, int value) +{ + if (value) + cuser.uflag |= mask; + else + cuser.uflag &= ~mask; +} + +extern int usernum; +extern int currmode; + +void +u_exit (char *mode) +{ + //userec_t xuser; + int diff = (time (0) - login_start_time) / 60; + + reload_money(); + auto_backup (); + save_brdbuf(); + setflags (PAGER_FLAG, currutmp->pager != 1); + setflags (CLOAK_FLAG, currutmp->invisible); + + cuser.invisible = currutmp->invisible; + cuser.pager = currutmp->pager; + cuser.mind = currutmp->mind; + if (!(HAS_PERM (PERM_SYSOP) && HAS_PERM (PERM_DENYPOST)) && + !currutmp->invisible ) + do_aloha ("<<下站通知>> -- 我走囉!"); + + purge_utmp (currutmp); + if ((cuser.uflag != enter_uflag) || (currmode & MODE_DIRTY) || diff) + { + if (!diff && cuser.numlogins) + cuser.numlogins = --cuser.numlogins; + /* Leeym 上站停留時間限制式 */ + } + passwd_update (usernum, &cuser); + log_usies (mode, NULL); +} + +static void +system_abort () +{ + if (currmode) + u_exit ("ABORT"); + + clear (); + refresh (); + fprintf (stdout, "謝謝光臨, 記得常來喔 !\n"); + exit (0); +} + +void +abort_bbs (int sig) +{ + if (currmode) + u_exit ("AXXED"); + exit (0); +} + +static void +abort_bbs_debug (int sig) +{ + static int reentrant = 0; + + if (!reentrant){ + reentrant = 1; + if (currmode) + u_exit ("AXXED"); + setproctitle("debug me!(%d)",sig); + sleep(3600); /* wait 60 mins for debug */ + } + exit (0); +} + +/* 登錄 BBS 程式 */ +static void +mysrand () +{ + srand (time (NULL) + currutmp->pid); /* 時間跟 pid 當 rand 的 seed */ +} + +extern userec_t xuser; + +int +dosearchuser (char *userid) +{ + if ((usernum = getuser (userid))) + memcpy (&cuser, &xuser, sizeof (cuser)); + else + memset (&cuser, 0, sizeof (cuser)); + return usernum; +} + +static void +talk_request () +{ + bell (); + bell (); + if (currutmp->msgcount){ + char buf[200]; + time_t now = time (0); + + sprintf (buf, "\033[33;41m★%s\033[34;47m [%s] %s \033[0m", + utmpshm->uinfo[currutmp->destuip].userid, my_ctime (&now), + (currutmp->sig == 2)? "重要消息廣播!(請Ctrl-U,l查看熱訊記錄)" + : "呼叫、呼叫,聽到請回答"); + move (0, 0); + clrtoeol (); + outs (buf); + refresh (); + } + else{ + unsigned char mode0 = currutmp->mode; + char c0 = currutmp->chatid[0]; + screenline_t *screen0 = calloc (t_lines, sizeof (screenline_t)); + extern screenline_t *big_picture; + + currutmp->mode = 0; + currutmp->chatid[0] = 1; + memcpy (screen0, big_picture, t_lines * sizeof (screenline_t)); + talkreply (); + currutmp->mode = mode0; + currutmp->chatid[0] = c0; + memcpy (big_picture, screen0, t_lines * sizeof (screenline_t)); + free (screen0); + redoscr (); + } +} + +extern char *fn_writelog; +FILE *fp_writelog = NULL; + +void +show_last_call_in (int save) +{ + char buf[200]; + sprintf (buf, "\033[1;33;46m★%s\033[37;45m %s \033[m", + currutmp->msgs[0].userid, currutmp->msgs[0].last_call_in); + move (b_lines, 0); + clrtoeol (); + refresh (); + outmsg (buf); + + if (save){ + char genbuf[200]; + time_t now; + if (!fp_writelog){ + sethomefile (genbuf, cuser.userid, fn_writelog); + fp_writelog = fopen (genbuf, "a"); + } + if (fp_writelog){ + time (&now); + fprintf (fp_writelog, "%s \033[0m[%s]\n", buf, Cdatelite (&now)); + } + } +} + +extern unsigned int currstat; +water_t water[6], *swater[6], *water_which=&water[0]; +char water_usies=0; +extern int watermode; +static int add_history_water(water_t *w, msgque_t *msg) +{ + memcpy(&w->msg[w->top], msg, sizeof(msgque_t)); + w->top++; + w->top %= WATERMODE(WATER_OFO) ? 5 : MAX_REVIEW; + + if (w->count < MAX_REVIEW) + w->count++; + + return w->count; +} + +static int +add_history(msgque_t *msg) +{ + int i,j; + water_t *tmp; + add_history_water(&water[0], msg); + for(i = 0 ; i < 5 && swater[i] ; i++ ) + if( swater[i]->pid == msg->pid ) + break; + if( i != 5 ){ + if( !swater[i] ){ + water_usies = i + 1; + swater[i] = &water[i + 1]; + strcpy(swater[i]->userid, msg->userid); + swater[i]->pid = msg->pid; + } + tmp = swater[i]; + } + else{ + tmp = swater[4]; + memset(swater[4], 0, sizeof (water_t)); + strcpy(swater[4]->userid, msg->userid); + swater[4]->pid = msg->pid; + i = 4; + } + + for( j = i ; j > 0 ; j-- ) + swater[j] = swater[j - 1]; + swater[0] = tmp; + add_history_water(swater[0], msg); + + if(WATERMODE(WATER_ORIG) || WATERMODE(WATER_NEW) ){ + if( watermode > 0 && + (water_which == swater[0] || water_which == &water[0]) ){ + if (watermode < water_which->count) + watermode++; + t_display_new(); + } + } + return i; +} + +static void +write_request (int sig) +{ + struct tm *ptime; + time_t now; + + time (&now); + ptime = localtime (&now); + + if (currutmp->pager != 0 && + cuser.userlevel != 0 && + currutmp->msgcount != 0 && + currutmp->mode != TALK && + currutmp->mode != EDITING && + currutmp->mode != CHATING && + currutmp->mode != PAGE && + currutmp->mode != IDLE && + currutmp->mode != MAILALL && currutmp->mode != MONITOR) + { + int i; + char c0 = currutmp->chatid[0]; + int currstat0 = currstat; + unsigned char mode0 = currutmp->mode; + + currutmp->mode = 0; + currutmp->chatid[0] = 2; + currstat = XMODE; + + do + { + bell (); + show_last_call_in (1); + igetch (); + currutmp->msgcount--; + if (currutmp->msgcount >= MAX_MSGS) + { + /* this causes chaos... jochang */ + raise (SIGFPE); + } + + add_history(&currutmp->msgs[0]); + for (i = 0; i < currutmp->msgcount; i++) + currutmp->msgs[i] = currutmp->msgs[i + 1]; + } + while (currutmp->msgcount); + currutmp->chatid[0] = c0; + currutmp->mode = mode0; + currstat = currstat0; + } + else + { + bell (); + show_last_call_in (1); + add_history(&currutmp->msgs[0]); + + refresh (); + currutmp->msgcount = 0; + } +} + +#if 0 +static void +write_request (int sig) +{ + int i, mtimemin, wu; + static char inlock = 0; + if( inlock ) /* 如果已經進來了 (表示上個水球還沒有處理完, + 新的水球又進來) 則不做任何事直接 return */ + return; + inlock = 1; + do{ + for( wu = 0 ; wu < 5 ; ++wu ) + if( water[wu].pid == currutmp->msgs[0].pid ) + break; + if( wu == 5 ){ + for( i = 0, mtimemin = INT_MAX ; i < 5 ; ++i ) + if( water[i].pid == 0 ){ + ++water_usies; + wu = i; + break; + } + else if( water[i].mtime < mtimemin ){ + mtimemin = water[i].mtime; + wu = i; + } + water[wu].pid = currutmp->msgs[0].pid; + strcpy(water[wu].userid, currutmp->msgs[0].userid); + water[wu].msgtop = 0; + for( i = 0 ; i < 5 ; ++i ) + water[wu].msg[i][0] = 0; + } + water[wu].mtime = time(NULL); + strncpy(water[wu].msg[ (int)water[wu].msgtop ], + currutmp->msgs[0].last_call_in, 64); + ++water[wu].msgtop; + water[wu].msgtop %= 5; + + bell (); + show_last_call_in (1); + refresh(); + + if( watermode == 0 ){ /* in waterball selection mode + if( wu != 0 ){ + water_scr(water_which, 0); + qsort(water, 5, sizeof(water_t), cmpwatermtime); + for( i = 0 ; i < 5 ; ++i ) + if( water[i].pid == 0 ) + break; + else + water_scr(i, 0); + water_scr(water_which = 0, 1); + refresh(); + } */ + } + --currutmp->msgcount; + for( i = 0 ; i < currutmp->msgcount - 1 ; ++i ) + currutmp->msgs[i] = currutmp->msgs[i + 1]; + } while( currutmp->msgcount > 0 ); + inlock = 0; +} +#endif + +static void +multi_user_check () +{ + register userinfo_t *ui; + register pid_t pid; + char genbuf[3]; + + if (HAS_PERM (PERM_SYSOP)) + return; /* don't check sysops */ + + if (cuser.userlevel){ + if (!(ui = (userinfo_t *) search_ulist (usernum))) + return; /* user isn't logged in */ + + pid = ui->pid; + if (!pid /*|| (kill(pid, 0) == -1) */ ) + return; /* stale entry in utmp file */ + + getdata (b_lines - 1, 0, "您想刪除其他重複的 login (Y/N)嗎?[Y] ", + genbuf, 3, LCECHO); + + if (genbuf[0] != 'n'){ + if (pid > 0) + kill (pid, SIGHUP); + log_usies ("KICK ", cuser.username); + } + else{ + if (search_ulistn(usernum, 3)!=NULL) + system_abort (); /* Goodbye(); */ + } + } + else{ + /* allow multiple guest user */ + if (search_ulistn(usernum, 100)!=NULL){ + outs ("\n抱歉,目前已有太多 guest, 請稍後再試。\n"); + pressanykey (); + oflush (); + exit (1); + } + } +} + +/* bad login */ +static char str_badlogin[] = "logins.bad"; + +static void +logattempt (char *uid, char type) +{ + char fname[40]; + int fd, len; + char genbuf[200]; + + sprintf (genbuf, "%c%-12s[%s] %s@%s\n", type, uid, + Cdate (&login_start_time), remoteusername, fromhost); + len = strlen (genbuf); + if ((fd = open (str_badlogin, O_WRONLY | O_CREAT | O_APPEND, 0644)) > 0){ + write (fd, genbuf, len); + close (fd); + } + if (type == '-'){ + sprintf (genbuf, "[%s] %s\n", Cdate (&login_start_time), fromhost); + len = strlen (genbuf); + sethomefile (fname, uid, str_badlogin); + if ((fd = open (fname, O_WRONLY | O_CREAT | O_APPEND, 0644)) > 0){ + write (fd, genbuf, len); + close (fd); + } + } +} + +extern char *str_new; +extern char *err_uid; + +static void +login_query () +{ + char uid[IDLEN + 1], passbuf[PASSLEN]; + int attempts; + char genbuf[200]; + extern struct utmpfile_t *utmpshm; + resolve_utmp (); + attach_uhash (); + attempts = utmpshm->number; + show_file ("etc/Welcome", 1, -1, NO_RELOAD); + output ("1", 1); + if (attempts >= MAX_ACTIVE){ + outs ("由於人數太多,請您稍後再來。\n"); + refresh (); + exit (1); + } + + /* hint */ + + attempts = 0; + while (1){ + if (attempts++ >= LOGINATTEMPTS){ + more ("etc/goodbye", NA); + pressanykey (); + exit (1); + } + getdata (20, 0, "請輸入代號,或以[guest]參觀,以[new]註冊:", + uid, IDLEN + 1, DOECHO); + if (strcasecmp (uid, str_new) == 0){ +#ifdef LOGINASNEW + new_register (); + break; +#else + outs ("本系統目前無法以 new 註冊, 請用 guest 進入\n"); + continue; +#endif + } + else if (uid[0] == '\0' || !dosearchuser (uid)){ + outs (err_uid); + } + else if (strcmp (uid, STR_GUEST)){ + getdata (21, 0, MSG_PASSWD, passbuf, PASSLEN, NOECHO); + passbuf[8] = '\0'; + + if (!checkpasswd (cuser.passwd, passbuf) + /* || (HAS_PERM(PERM_SYSOP) && !use_shell_login_mode) */ ){ + logattempt (cuser.userid, '-'); + outs (ERR_PASSWD); + } + else{ + logattempt (cuser.userid, ' '); + if (strcasecmp ("SYSOP", cuser.userid) == 0) + cuser.userlevel = PERM_BASIC | PERM_CHAT | PERM_PAGE | + PERM_POST | PERM_LOGINOK | PERM_MAILLIMIT | + PERM_CLOAK | PERM_SEECLOAK | PERM_XEMPT | + PERM_DENYPOST | PERM_BM | PERM_ACCOUNTS | + PERM_CHATROOM | PERM_BOARD | PERM_SYSOP | PERM_BBSADM; + break; + } + } + else{ /* guest */ + cuser.userlevel = 0; + cuser.uflag = COLOR_FLAG | PAGER_FLAG | BRDSORT_FLAG | MOVIE_FLAG; + break; + } + } + multi_user_check (); + sethomepath (genbuf, cuser.userid); + mkdir (genbuf, 0755); +} + +void +add_distinct (char *fname, char *line) +{ + FILE *fp; + int n = 0; + + if ((fp = fopen (fname, "a+"))){ + char buffer[80]; + char tmpname[100]; + FILE *fptmp; + + strcpy (tmpname, fname); + strcat (tmpname, "_tmp"); + if (!(fptmp = fopen (tmpname, "w"))){ + fclose (fp); + return; + } + rewind (fp); + while (fgets (buffer, 80, fp)){ + char *p = buffer + strlen (buffer) - 1; + + if (p[-1] == '\n' || p[-1] == '\r') + p[-1] = 0; + if (!strcmp (buffer, line)) + break; + sscanf (buffer + strlen (buffer) + 2, "%d", &n); + fprintf (fptmp, "%s%c#%d\n", buffer, 0, n); + } + + if (feof (fp)) + fprintf (fptmp, "%s%c#1\n", line, 0); + else{ + sscanf (buffer + strlen (buffer) + 2, "%d", &n); + fprintf (fptmp, "%s%c#%d\n", buffer, 0, n + 1); + while (fgets (buffer, 80, fp)){ + sscanf (buffer + strlen (buffer) + 2, "%d", &n); + fprintf (fptmp, "%s%c#%d\n", buffer, 0, n); + } + } + fclose (fp); + fclose (fptmp); + unlink (fname); + rename (tmpname, fname); + } +} + +void +del_distinct (char *fname, char *line) +{ + FILE *fp; + int n = 0; + + if ((fp = fopen (fname, "r"))){ + char buffer[80]; + char tmpname[100]; + FILE *fptmp; + + strcpy (tmpname, fname); + strcat (tmpname, "_tmp"); + if (!(fptmp = fopen (tmpname, "w"))){ + fclose (fp); + return; + } + rewind (fp); + while (fgets (buffer, 80, fp)){ + char *p = buffer + strlen (buffer) - 1; + + if (p[-1] == '\n' || p[-1] == '\r') + p[-1] = 0; + if (!strcmp (buffer, line)) + break; + sscanf (buffer + strlen (buffer) + 2, "%d", &n); + fprintf (fptmp, "%s%c#%d\n", buffer, 0, n); + } + + if (!feof (fp)) + while (fgets (buffer, 80, fp)){ + sscanf (buffer + strlen (buffer) + 2, "%d", &n); + fprintf (fptmp, "%s%c#%d\n", buffer, 0, n); + } + fclose (fp); + fclose (fptmp); + unlink (fname); + rename (tmpname, fname); + } +} + +#ifdef WHERE +static int +where (char *from) +{ + register int i = 0, count = 0, j; + + for (j = 0; j < fcache->top; j++){ + char *token = strtok (fcache->domain[j], "&"); + + i = 0; + count = 0; + while (token){ + if (strstr (from, token)) + count++; + token = strtok (NULL, "&"); + i++; + } + if (i == count) + break; + } + if (i != count) + return 0; + return j; +} +#endif + +static void +check_BM () +{ + int i; + boardheader_t *bhdr; + extern boardheader_t *bcache; + extern int numboards; + + cuser.userlevel &= ~PERM_BM; + for (i = 0, bhdr = bcache; i < numboards && !is_BM (bhdr->BM); i++, bhdr++) + ; +} + +extern pid_t currpid; +extern crosspost_t postrecord; + +static void +setup_utmp (int mode) +{ + userinfo_t uinfo; + /* + char buf[80]; + char remotebuf[1024]; + time_t now = time(NULL); + */ + memset (&uinfo, 0, sizeof (uinfo)); + uinfo.pid = currpid = getpid (); + uinfo.uid = usernum; + uinfo.mode = currstat = mode; + uinfo.msgcount = 0; + uinfo.mailalert = load_mailalert (cuser.userid); + if (!(cuser.numlogins % 20) && cuser.userlevel & PERM_BM) + check_BM (); /* Ptt 自動取下離職板主權力 */ + + uinfo.userlevel = cuser.userlevel; + uinfo.sex = cuser.sex % 8; + uinfo.lastact = time (NULL); + + postrecord.times = 0; /* 計算crosspost數 */ + + strcpy (uinfo.userid, cuser.userid); + strcpy (uinfo.realname, cuser.realname); + strcpy (uinfo.username, cuser.username); + strncpy (uinfo.from, fromhost, 23); + + uinfo.five_win = cuser.five_win; + uinfo.five_lose = cuser.five_lose; + uinfo.five_tie = cuser.five_tie; + + uinfo.invisible = cuser.invisible % 2; + uinfo.pager = cuser.pager%5; + uinfo.mind = cuser.mind; + uinfo.brc_id = 0; +#ifdef WHERE + uinfo.from_alias = where (fromhost); +#else + uinfo.from_alias = 0; +#endif +#ifndef FAST_LOGIN + setuserfile (buf, "remoteuser"); + + strcpy (remotebuf, fromhost); + strcat (remotebuf, ctime (&now)); + remotebuf[strlen (remotebuf) - 1] = 0; + add_distinct (buf, remotebuf); +#endif + if (enter_uflag & CLOAK_FLAG) + uinfo.invisible = YEA; + getnewutmpent (&uinfo); +#ifndef _BBS_UTIL_C_ + friend_load (); +#endif +} + +extern char margs[]; +extern char *str_sysop; +extern char *loginview_file[NUMVIEWFILE][2]; + +static void +user_login () +{ + char ans[4], i; + char genbuf[200]; + struct tm *ptime, *tmp; + time_t now; + int a; + /*** Heat:廣告詞 + char *ADV[] = { + "7/17 @LIVE 亂彈, 何欣穗 的 入場卷要送給 ptt 的愛用者!", + "欲知詳情請看 PttAct 板!!", + }; ***/ + + log_usies ("ENTER", fromhost); + setproctitle ("%s: %s", margs, cuser.userid); + resolve_garbage (); + resolve_fcache (); + resolve_boards (); + memset( &water[0],0,sizeof(water_t) * 6); + strcpy(water[0].userid, " 全部 "); + /* 初始化 uinfo、flag、mode */ + setup_utmp (LOGIN); + mysrand (); /* 初始化: random number 增加user跟時間的差異 */ + currmode = MODE_STARTED; + enter_uflag = cuser.uflag; + + /* get local time */ + time (&now); + ptime = localtime (&now); + tmp = localtime (&cuser.lastlogin); + if ((a = utmpshm->number) > fcache->max_user){ + fcache->max_user = a; + fcache->max_time = now; + } + init_brdbuf(); + brc_initial (DEFAULT_BOARD); + set_board (); + /* 畫面處理開始 */ + if (!(HAS_PERM (PERM_SYSOP) && HAS_PERM (PERM_DENYPOST)) && !currutmp->invisible ) + do_aloha ("<<上站通知>> -- 我來啦!"); + if (ptime->tm_mday == cuser.day && ptime->tm_mon + 1 == cuser.month){ + more ("etc/Welcome_birth", NA); + currutmp->birth = 1; + } + else{ +#ifdef MULTI_WELCOME_LOGIN + char buf[80]; + int nScreens; + for( nScreens = 0 ; nScreens < 10 ; ++nScreens ){ + sprintf(buf, "etc/Welcome_login.%d", nScreens); + if( access(buf, 0) < 0 ) + break; + } + printf("%d\n", nScreens); + if( nScreens == 0 ){ // multi screen error? + more ("etc/Welcome_login", NA); + } + else{ + sprintf(buf, "etc/Welcome_login.%d", (int)login_start_time % nScreens); + more (buf, NA); + } +#else + more ("etc/Welcome_login", NA); +#endif +// pressanykey(); +// more("etc/CSIE_Week", NA); + currutmp->birth = 0; + } + + if (cuser.userlevel){/* not guest */ + move (t_lines - 4, 0); + prints (" 歡迎您第 \033[1;33m%d\033[0;37m 度拜訪本站," + "上次您是從 \033[1;33m%s\033[0;37m 連往本站,\n" + " 我記得那天是 \033[1;33m%s\033[0;37m。\n", + ++cuser.numlogins, cuser.lasthost, Cdate (&cuser.lastlogin)); + pressanykey (); + + if (currutmp->birth && tmp->tm_mday != ptime->tm_mday){ + more ("etc/birth.post", YEA); + brc_initial ("WhoAmI"); + set_board (); + do_post (); + } + setuserfile (genbuf, str_badlogin); + if (more (genbuf, NA) != -1){ + getdata (b_lines - 1, 0, "您要刪除以上錯誤嘗試的記錄嗎(Y/N)?[Y]", + ans, 3, LCECHO); + if (*ans != 'n') + unlink (genbuf); + } + check_register (); + strncpy (cuser.lasthost, fromhost, 16); + cuser.lasthost[15] = '\0'; + restore_backup (); + } + else if (!strcmp (cuser.userid, STR_GUEST)){ + char *nick[13] = { + "椰子", "貝殼", "內衣", "寶特瓶", "翻車魚", + "樹葉", "浮萍", "鞋子", "潛水艇", "魔王", + "鐵罐", "考卷", "大美女" + }; + char *name[13] = { + "大王椰子", "鸚鵡螺", "比基尼", "可口可樂", "仰泳的魚", + "憶", "高岡屋", "AIR Jordon", "紅色十月號", "批踢踢", + "SASAYA椰奶", "鴨蛋", "布魯克鱈魚香絲" + }; + char *addr[13] = { + "天堂樂園", "大海", "綠島小夜曲", "美國", "綠色珊瑚礁", + "遠方", "原本海", "NIKE", "蘇聯", "男八618室", + "愛之味", "天上", "藍色珊瑚礁" + }; + i = login_start_time % 13; + sprintf (cuser.username, "海邊漂來的%s", nick[(int) i]); + sprintf (currutmp->username, cuser.username); + sprintf (cuser.realname, name[(int) i]); + sprintf (currutmp->realname, cuser.realname); + sprintf (cuser.address, addr[(int) i]); + cuser.sex = i % 8; + currutmp->pager = 2; + pressanykey (); + } + else + pressanykey (); + + if (!PERM_HIDE (currutmp)) + cuser.lastlogin = login_start_time; + + passwd_update (usernum, &cuser); + + for (i = 0; i < NUMVIEWFILE; i++) + if ((cuser.loginview >> i) & 1) + more (loginview_file[(int) i][0], YEA); + + +} + +static void +do_aloha (char *hello) +{ + FILE *fp; + char userid[80]; + char genbuf[200]; + + setuserfile (genbuf, "aloha"); + if ((fp = fopen (genbuf, "r"))){ + sprintf (genbuf, hello); + while (fgets (userid, 80, fp)){ + userinfo_t *uentp; + int tuid; + + if ((tuid = searchuser (userid)) && tuid != usernum && + (uentp = (userinfo_t *) search_ulist (tuid)) && + isvisible(uentp, currutmp)){ + my_write (uentp->pid, genbuf, uentp->userid, 2); + } + } + fclose (fp); + } +} + +static void +do_term_init () +{ + term_init (); + initscr (); +} + +extern char *fn_register; +extern int showansi; + +static void +start_client () +{ + extern struct commands_t cmdlist[]; +#if FORCE_PROCESS_REGISTER_FORM + int nreg; +#endif + + /* system init */ + nice (2); /* Ptt: lower priority */ + login_start_time = time (0); + currmode = 0; + + signal (SIGHUP, abort_bbs); + signal (SIGTERM, abort_bbs); + signal (SIGPIPE, abort_bbs); + + signal (SIGINT, abort_bbs_debug); + signal (SIGQUIT, abort_bbs_debug); + signal (SIGILL, abort_bbs_debug); + signal (SIGABRT, abort_bbs_debug); + signal (SIGFPE, abort_bbs_debug); + signal (SIGBUS, abort_bbs_debug); + signal (SIGSEGV, abort_bbs_debug); + + signal_restart (SIGUSR1, talk_request); + signal_restart (SIGUSR2, write_request); + + dup2 (0, 1); + + do_term_init (); + signal (SIGALRM, abort_bbs); + alarm (600); + login_query (); /* Ptt 加上login time out */ + user_login (); + m_init (); + +#if FORCE_PROCESS_REGISTER_FORM + if (HAS_PERM (PERM_SYSOP) && (nreg = dashs (fn_register) / 163) > 100){ + char cpu_load[30]; + if (cpuload (cpu_load) > MAX_CPULOAD * 2 / 3) + /* DickG: 根據目前的 load 來決定要審核的數目 */ + scan_register_form (fn_register, 1, nreg / 20); + else + scan_register_form (fn_register, 1, nreg / 10); + } +#endif + if (HAVE_PERM (PERM_SYSOP | PERM_BM)) + b_closepolls (); + if (!(cuser.uflag & COLOR_FLAG)) + showansi = 0; +#ifdef DOTIMEOUT + /* init_alarm(); */// cause strange logout with saving post. + signal (SIGALRM, SIG_IGN); +#else + signal (SIGALRM, SIG_IGN); +#endif + if (chkmailbox ()) + m_read (); + + domenu (MMENU, "主功\能表", (currutmp->mailalert ? 'M' : 'C'), cmdlist); +} + +/* FSA (finite state automata) for telnet protocol */ +static void +telnet_init () +{ + static char svr[] = { + IAC, DO, TELOPT_TTYPE, + IAC, SB, TELOPT_TTYPE, TELQUAL_SEND, IAC, SE, + IAC, WILL, TELOPT_ECHO, + IAC, WILL, TELOPT_SGA + }; + char *cmd; + int n, len, rset; + struct timeval to; + char buf[64]; + for (n = 0, cmd = svr; n < 4; n++){ + len = (n == 1 ? 6 : 3); + write (0, cmd, len); + cmd += len; + to.tv_sec = 3; + to.tv_usec = 0; + rset=1; + if (select (1, (fd_set *) & rset, NULL, NULL, &to) > 0) + recv(0, buf, sizeof (buf),0); + } +} + +/* 取得 remote user name 以判定身份 */ +/* + * rfc931() speaks a common subset of the RFC 931, AUTH, TAP, IDENT and RFC + * 1413 protocols. It queries an RFC 931 etc. compatible daemon on a remote + * host to look up the owner of a connection. The information should not be + * used for authentication purposes. This routine intercepts alarm signals. + * + * Author: Wietse Venema, Eindhoven University of Technology, The Netherlands. + */ + +#define STRN_CPY(d,s,l) { strncpy((d),(s),(l)); (d)[(l)-1] = 0; } +#define RFC931_TIMEOUT 10 +#define RFC931_PORT 113 /* Semi-well-known port */ +#define ANY_PORT 0 /* Any old port will do */ + +/* timeout - handle timeouts */ +static void +timeout (int sig) +{ + longjmp (byebye, sig); +} + +static void +getremotename (struct sockaddr_in *from, char *rhost, char *rname) +{ + + /* get remote host name */ + +#ifdef FAST_LOGIN + strcpy (rhost, (char *) inet_ntoa (from->sin_addr)); +#else + struct sockaddr_in our_sin; + struct sockaddr_in rmt_sin; + unsigned rmt_port, rmt_pt; + unsigned our_port, our_pt; + FILE *fp; + char buffer[512], user[80], *cp; + int s; + static struct hostent *hp; + + + hp = NULL; + if (setjmp (byebye) == 0){ + signal (SIGALRM, timeout); + alarm (3); + hp = gethostbyaddr ((char *) &from->sin_addr, sizeof (struct in_addr), + from->sin_family); + alarm (0); + } + strcpy (rhost, hp ? hp->h_name : (char *) inet_ntoa (from->sin_addr)); + +/* + * Use one unbuffered stdio stream for writing to and for reading from the + * RFC931 etc. server. This is done because of a bug in the SunOS 4.1.x + * stdio library. The bug may live in other stdio implementations, too. + * When we use a single, buffered, bidirectional stdio stream ("r+" or "w+" + * mode) we read our own output. Such behaviour would make sense with + * resources that support random-access operations, but not with sockets. + */ + + s = sizeof (our_sin); + if (getsockname (0, (struct sockaddr *) &our_sin, &s) < 0) + return; + + if ((s = socket (AF_INET, SOCK_STREAM, 0)) < 0) + return; + + if (!(fp = fdopen (s, "r+"))){ + close (s); + return; + } + /* Set up a timer so we won't get stuck while waiting for the server. */ + if (setjmp (byebye) == 0){ + signal (SIGALRM, timeout); + alarm (RFC931_TIMEOUT); + +/* + * Bind the local and remote ends of the query socket to the same IP + * addresses as the connection under investigation. We go through all + * this trouble because the local or remote system might have more than + * one network address. The RFC931 etc. client sends only port numbers; + * the server takes the IP addresses from the query socket. + */ + our_pt = ntohs (our_sin.sin_port); + our_sin.sin_port = htons (ANY_PORT); + + rmt_sin = *from; + rmt_pt = ntohs (rmt_sin.sin_port); + rmt_sin.sin_port = htons (RFC931_PORT); + + setbuf (fp, (char *) 0); + s = fileno (fp); + + if (bind (s, (struct sockaddr *) &our_sin, sizeof (our_sin)) >= 0 && + connect (s, (struct sockaddr *) &rmt_sin, sizeof (rmt_sin)) >= 0){ +/* + * Send query to server. Neglect the risk that a 13-byte write would + * have to be fragmented by the local system and cause trouble with + * buggy System V stdio libraries. + */ + fprintf (fp, "%u,%u\r\n", rmt_pt, our_pt); + fflush (fp); +/* + * Read response from server. Use fgets()/sscanf() so we can work + * around System V stdio libraries that incorrectly assume EOF when a + * read from a socket returns less than requested. + */ + if (fgets (buffer, sizeof (buffer), fp) && !ferror (fp) + && !feof (fp) + && sscanf (buffer, "%u , %u : USERID :%*[^:]:%79s", &rmt_port, + &our_port, user) == 3 && rmt_pt == rmt_port + && our_pt == our_port){ + +/* + * Strip trailing carriage return. It is part of the protocol, not + * part of the data. + */ + if ((cp = (char *) strchr (user, '\r'))) + *cp = 0; + strcpy (rname, user); + } + } + alarm (0); + } + fclose (fp); +#endif +} + +static int +bind_port (int port) +{ + int sock, on; + + sock = socket (AF_INET, SOCK_STREAM, IPPROTO_TCP); + + on = 1; + setsockopt (sock, SOL_SOCKET, SO_REUSEADDR, (char *) &on, sizeof (on)); + setsockopt (sock, SOL_SOCKET, SO_KEEPALIVE, (char *) &on, sizeof (on)); + + on = 0; + setsockopt (sock, SOL_SOCKET, SO_LINGER, (char *) &on, sizeof (on)); + + xsin.sin_port = htons (port); + if (bind (sock, (struct sockaddr *) &xsin, sizeof xsin) < 0){ + syslog (LOG_INFO, "bbsd bind_port can't bind to %d", port); + exit (1); + } + if (listen (sock, SOCKET_QLEN) < 0){ + syslog (LOG_INFO, "bbsd bind_port can't listen to %d", port); + exit (1); + } + return sock; +} + + +/*******************************************************/ + + +static void shell_login (int argc, char *argv[], char *envp[]); +static void daemon_login (int argc, char *argv[], char *envp[]); +static int check_ban_and_load (int fd); +#ifdef SUPPORT_GB +extern int current_font_type; +#endif + +int +main (int argc, char *argv[], char *envp[]) +{ + /* avoid SIGPIPE */ + signal (SIGPIPE, SIG_IGN); + + /* avoid erroneous signal from other mbbsd */ + signal (SIGUSR1, SIG_IGN); + signal (SIGUSR2, SIG_IGN); + + /* check if invoked as "bbs" */ + if (argc == 3) + shell_login (argc, argv, envp); + else + daemon_login (argc, argv, envp); + + return 0; +} + +static void +shell_login (int argc, char *argv[], char *envp[]) +{ + + /* Give up root privileges: no way back from here */ + setgid (BBSGID); + setuid (BBSUID); + chdir (BBSHOME); + + /* mmap passwd file */ + if (passwd_mmap ()) + exit (1); + + use_shell_login_mode = 1; + initsetproctitle (argc, argv, envp); + + /* copy fromindent: Standard input:1138: Error:Unexpected end of file + the original "bbs" */ + if (argc > 1){ + strcpy (fromhost, argv[1]); + if (argc > 3) + strcpy (remoteusername, argv[3]); + } + + close (2); + /* don't close fd 1, at least init_tty need it */ + + init_tty (); + if (check_ban_and_load (0)){ + exit (0); + } + start_client (); +} + +static void +daemon_login (int argc, char *argv[], char *envp[]) +{ + int msock, csock; /* socket for Master and Child */ + FILE *fp; + int listen_port = 23; + int len_of_sock_addr; + char buf[256]; + + /* setup standalone */ + + start_daemon(); + + signal_restart(SIGCHLD, reapchild); + + /* choose port */ + if(argc == 1) + listen_port = 3006; + else if(argc >= 2) + listen_port = atoi(argv[1]); + + sprintf(margs, "%s %d ", argv[0],listen_port); + + /* port binding */ + xsin.sin_family = AF_INET; + msock = bind_port(listen_port); + if(msock<0) { + syslog(LOG_INFO, "mbbsd bind_port failed.\n"); + exit(1); + } + + + initsetproctitle(argc, argv, envp); + setproctitle("%s: listening ", margs); + + /* Give up root privileges: no way back from here */ + setgid(BBSGID); + setuid(BBSUID); + chdir(BBSHOME); + + /* mmap passwd file */ + if(passwd_mmap()) + { + exit(1); + } + sprintf(buf, "run/mbbsd.%d.pid", listen_port); + if((fp = fopen(buf, "w"))) { + fprintf(fp, "%d\n", getpid()); + fclose(fp); + } + + /* main loop */ + for(;;) { + len_of_sock_addr = sizeof(xsin); + csock = accept(msock, (struct sockaddr *)&xsin, &len_of_sock_addr); + + if(csock < 0) { + if(errno!=EINTR) sleep(1); + continue; + } + + if(check_ban_and_load(csock)) + { + close(csock); + continue; + } + + if(fork()==0) + break; + else + close(csock); + + } + /* here is only child running */ + + setproctitle("%s: ...login wait... ", margs); + close(msock); + dup2(csock, 0); + close(csock); + + getremotename(&xsin, fromhost, remoteusername); + telnet_init(); + start_client(); + close(0); + close(1); +} + +/* check if we're banning login and if the load is too high. + if login is permitted, return 0; + else return -1; + approriate message is output to fd. +*/ +static int check_ban_and_load(int fd) +{ + FILE *fp; + static char buf[256]; + static time_t chkload_time = 0; + static int overload = 0; /* overload or banned, update every 1 sec */ + static int banned = 0; + + if((time(0) - chkload_time) > 1) { + overload = chkload(buf); + banned = !access(BBSHOME "/BAN",R_OK) && + (strcmp(fromhost, "localhost") != 0); + chkload_time = time(0); + } + + write(fd, buf, strlen(buf)); + + if(banned && (fp = fopen(BBSHOME "/BAN", "r"))) { + while(fgets(buf, 256, fp)) + write(fd, buf, strlen(buf)); + fclose(fp); + } + + if(banned || overload) + return -1; + +#ifdef INSCREEN + write(fd, INSCREEN, strlen(INSCREEN)); +#endif + + return 0; +} diff --git a/pttbbs/mbbsd/menu.c b/pttbbs/mbbsd/menu.c new file mode 100644 index 00000000..d48670b3 --- /dev/null +++ b/pttbbs/mbbsd/menu.c @@ -0,0 +1,596 @@ +/* $Id: menu.c,v 1.1 2002/03/07 15:13:48 in2 Exp $ */ +#include +#include +#include +#include +#include +#include "config.h" +#include "pttstruct.h" +#include "common.h" +#include "perm.h" +#include "modes.h" +#include "proto.h" +extern int usernum; +extern int talkrequest; +extern char *fn_register; +extern char currboard[]; /* name of currently selected board */ +extern int currmode; +extern unsigned int currstat; +extern char reset_color[]; +extern userinfo_t *currutmp; +extern char *BBSName; +extern int b_lines; /* Screen bottom line number: t_lines-1 */ + +/* help & menu processring */ +static int refscreen = NA; +extern char *boardprefix; +extern struct utmpfile_t *utmpshm; + +int egetch() { + int rval; + + while(1) { + rval = igetkey(); + if(talkrequest) { + talkreply(); + refscreen = YEA; + return rval; + } + if(rval != Ctrl('L')) + return rval; + redoscr(); + } +} + +extern userec_t cuser; +extern char *fn_board; +extern char board_hidden_status; + +void showtitle(char *title, char *mid) { + char buf[40], numreg[50]; + int nreg, spc = 0, pad, bid; + boardheader_t bh; + static char lastboard[16] = {0}; + + spc = strlen(mid); + if(title[0] == 0) + title++; + else if(currutmp->mailalert) { + mid = "\033[41;5m 郵差來按鈴囉 " TITLE_COLOR; + spc = 22; + } else if(HAS_PERM(PERM_SYSOP) && (nreg = dashs(fn_register)/163) > 10) { + /* 超過十個人未審核 */ + sprintf(numreg, "\033[41;5m 有%03d/%03d未審核 " TITLE_COLOR, + nreg, + (int)dashs("register.new.tmp") / 163); + mid = numreg; + spc = 22; + } + spc = 66 - strlen(title) - spc - strlen(currboard); + if(spc < 0) + spc = 0; + pad = 1 - (spc & 1); + memset(buf, ' ', spc >>= 1); + buf[spc] = '\0'; + + clear(); + prints(TITLE_COLOR "【%s】%s\033[33m%s%s%s\033[3%s《", + title, buf, mid, buf, " " + pad, + currmode & MODE_SELECT ? "6m系列" : currmode & MODE_ETC ? "5m其他" : + currmode & MODE_DIGEST ? "2m文摘" : "7m看板"); + + if( strcmp(currboard, lastboard) ){ /* change board */ + if( currboard[0] != 0 && + (bid = getbnum(currboard)) > 0 && + (get_record(fn_board, &bh, sizeof(bh), bid) != -1) ){ + board_hidden_status = ((bh.brdattr & BRD_HIDE) && + (bh.brdattr & BRD_POSTMASK)); + strncpy(lastboard, currboard, sizeof(lastboard)); + } + } + + if( board_hidden_status ) + prints("\033[32m%s", currboard); + else + prints("%s", currboard); + prints("\033[3%dm》\033[0m\n", currmode & MODE_SELECT ? 6 : + currmode & MODE_ETC ? 5 : currmode & MODE_DIGEST ? 2 : 7); +} + +/* 動畫處理 */ +#define FILMROW 11 +static unsigned char menu_row = 12; +static unsigned char menu_column = 20; +static char mystatus[160]; + +static int u_movie() { + cuser.uflag ^= MOVIE_FLAG; + return 0; +} + +void movie(int i) { + extern struct pttcache_t *ptt; + static short history[MAX_HISTORY]; + static char myweek[] = "天一二三四五六"; + const char *msgs[] = {"關閉", "打開", "拔掉", "防水","好友"}; + time_t now = time(NULL); + struct tm *ptime = localtime(&now); + + if((currstat != CLASS) && (cuser.uflag & MOVIE_FLAG) && + !ptt->busystate && ptt->max_film > 0) { + if(currstat == PSALE) { + i = PSALE; + reload_money(); + } else { + do { + if(!i) + i = 1 + (int)(((float)ptt->max_film * + rand()) / (RAND_MAX + 1.0)); + + for(now = ptt->max_history; now >= 0; now--) + if(i == history[now]) { + i = 0; + break; + } + } while(i == 0); + } + + memcpy(history, &history[1], ptt->max_history * sizeof(short)); + history[ptt->max_history] = now = i; + + if(i == 999) /* Goodbye my friend */ + i = 0; + + move(1, 0); + clrtoline(1 + FILMROW); /* 清掉上次的 */ + Jaky_outs(ptt->notes[i], 11); /* 只印11行就好 */ + outs(reset_color); + } + i = ptime->tm_wday << 1; + sprintf(mystatus, "\033[34;46m[%d/%d 星期%c%c %d:%02d]\033[1;33;45m%-14s" + "\033[30;47m 目前坊裡有 \033[31m%d\033[30m人, 我是\033[31m%-12s" + "\033[30m[扣機]\033[31m%s\033[0m", + ptime->tm_mon + 1, ptime->tm_mday, myweek[i], myweek[i + 1], + ptime->tm_hour, ptime->tm_min, currutmp->birth ? + "生日要請客唷" : ptt->today_is, + utmpshm->number, cuser.userid, msgs[currutmp->pager]); + outmsg(mystatus); + refresh(); +} + +static int show_menu(commands_t *p) { + register int n = 0; + register char *s; + const char *state[4]={"用功\型", "安逸型", "自定型", "SHUTUP"}; + char buf[80]; + + movie(currstat); + + move(menu_row, 0); + while((s = p[n].desc)) { + if(HAS_PERM(p[n].level)) { + sprintf(buf, s + 2, state[cuser.proverb % 4]); + prints("%*s (\033[1;36m%c\033[0m)%s\n", menu_column, "", s[1], + buf); + } + n++; + } + return n - 1; +} + +void domenu(int cmdmode, char *cmdtitle, int cmd, commands_t cmdtable[]) { + int lastcmdptr; + int n, pos, total, i; + int err; + int chkmailbox(); + static char cmd0[LOGIN]; + + if(cmd0[cmdmode]) + cmd = cmd0[cmdmode]; + + setutmpmode(cmdmode); + + showtitle(cmdtitle, BBSName); + + total = show_menu(cmdtable); + + outmsg(mystatus); + lastcmdptr = pos = 0; + + do { + i = -1; + switch(cmd) { + case Ctrl('C'): + cal(); + i = lastcmdptr; + refscreen = YEA; + break; + case Ctrl('I'): + t_idle(); + refscreen = YEA; + i = lastcmdptr; + break; + case Ctrl('N'): + New(); + refscreen = YEA; + i = lastcmdptr; + break; + case Ctrl('A'): + if(mail_man() == FULLUPDATE) + refscreen = YEA; + i = lastcmdptr; + break; + case KEY_DOWN: + i = lastcmdptr; + case KEY_HOME: + case KEY_PGUP: + do { + if(++i > total) + i = 0; + } while(!HAS_PERM(cmdtable[i].level)); + break; + case KEY_END: + case KEY_PGDN: + i = total; + break; + case KEY_UP: + i = lastcmdptr; + do { + if(--i < 0) + i = total; + } while(!HAS_PERM(cmdtable[i].level)); + break; + case KEY_LEFT: + case 'e': + case 'E': + if(cmdmode == MMENU) + cmd = 'G'; + else if((cmdmode == MAIL) && chkmailbox()) + cmd = 'R'; + else + return; + default: + if((cmd == 's' || cmd == 'r') && + (currstat == MMENU || currstat == TMENU || currstat == XMENU)) { + if(cmd == 's') + ReadSelect(); + else + Read(); + refscreen = YEA; + i = lastcmdptr; + break; + } + + if(cmd == '\n' || cmd == '\r' || cmd == KEY_RIGHT) { + move(b_lines, 0); + clrtoeol(); + + currstat = XMODE; + + if((err = (*cmdtable[lastcmdptr].cmdfunc) ()) == QUIT) + return; + currutmp->mode = currstat = cmdmode; + + if(err == XEASY) { + refresh(); + safe_sleep(1); + } else if(err != XEASY + 1 || err == FULLUPDATE) + refscreen = YEA; + + if(err != -1) + cmd = cmdtable[lastcmdptr].desc[0]; + else + cmd = cmdtable[lastcmdptr].desc[1]; + cmd0[cmdmode] = cmdtable[lastcmdptr].desc[0]; + } + + if(cmd >= 'a' && cmd <= 'z') + cmd &= ~0x20; + while(++i <= total) + if(cmdtable[i].desc[1] == cmd) + break; + } + + if(i > total || !HAS_PERM(cmdtable[i].level)) + continue; + + if(refscreen) { + showtitle(cmdtitle, BBSName); + + show_menu(cmdtable); + + outmsg(mystatus); + refscreen = NA; + } + cursor_clear(menu_row + pos, menu_column); + n = pos = -1; + while(++n <= (lastcmdptr = i)) + if(HAS_PERM(cmdtable[n].level)) + pos++; + + cursor_show(menu_row + pos, menu_column); + } while(((cmd = egetch()) != EOF) || refscreen); + + abort_bbs(0); +} +/* INDENT OFF */ + +/* administrator's maintain menu */ +static commands_t adminlist[] = { + {m_user, PERM_ACCOUNTS, "UUser 使用者資料"}, + {search_user_bypwd, PERM_SYSOP, "SSearch User 特殊搜尋使用者"}, + {search_user_bybakpwd,PERM_SYSOP, "OOld User data 查閱\備份使用者資料"}, + {m_board, PERM_SYSOP, "BBoard 設定看板"}, + {m_register, PERM_SYSOP, "RRegister 審核註冊表單"}, + {cat_register, PERM_SYSOP, "CCatregister 無法審核時用的"}, + {x_file, PERM_SYSOP|PERM_VIEWSYSOP, "XXfile 編輯系統檔案"}, + {give_money, PERM_SYSOP|PERM_VIEWSYSOP, "GGivemoney 紅包雞"}, +#ifdef HAVE_MAILCLEAN + {m_mclean, PERM_SYSOP, "MMail Clean 清理使用者個人信箱"}, +#endif +#ifdef HAVE_REPORT + {m_trace, PERM_SYSOP, "TTrace 設定是否記錄除錯資訊"}, +#endif + {NULL, 0, NULL} +}; + +/* mail menu */ +static commands_t maillist[] = { + {m_new, PERM_READMAIL, "RNew 閱\讀新進郵件"}, + {m_read, PERM_READMAIL, "RRead 多功\能讀信選單"}, + {m_send, PERM_BASIC, "RSend 站內寄信"}, + {main_bbcall, PERM_LOGINOK, "BBBcall \033[1;31m電話秘書\033[m"}, + {x_love, PERM_LOGINOK, "PPaper \033[1;32m情書產生器\033[m "}, + {mail_list, PERM_BASIC, "RMail List 群組寄信"}, + {setforward, PERM_LOGINOK,"FForward \033[32m設定信箱自動轉寄\033[m"}, + {m_sysop, 0, "YYes, sir! 諂媚站長"}, + {m_internet, PERM_INTERNET, "RInternet 寄信到 Internet"}, + {mail_mbox, PERM_INTERNET, "RZip UserHome 把所有私人資料打包回去"}, + {built_mail_index, PERM_LOGINOK, "SSavemail 把信件救回來"}, + {mail_all, PERM_SYSOP, "RAll 寄信給所有使用者"}, + {NULL, 0, NULL} +}; + +/* Talk menu */ +static commands_t talklist[] = { + {t_users, 0, "UUsers 完全聊天手冊"}, + {t_pager, PERM_BASIC, "PPager 切換呼叫器"}, + {t_idle, 0, "IIdle 發呆"}, + {t_query, 0, "QQuery 查詢網友"}, + {t_qchicken, 0, "WWatch Pet 查詢寵物"}, + {t_talk, PERM_PAGE, "TTalk 找人聊聊"}, + {t_chat, PERM_CHAT, "CChat 找家茶坊喫茶去"}, +#ifdef HAVE_MUD + {x_mud, 0, "VVrChat \033[1;32m虛擬實業聊天廣場\033[m"}, +#endif + {t_display, 0, "DDisplay 顯示上幾次熱訊"}, + {NULL, 0, NULL} +}; + +/* name menu */ +static int t_aloha() { + friend_edit(FRIEND_ALOHA); + return 0; +} + +static int t_special() { + friend_edit(FRIEND_SPECIAL); + return 0; +} + +static commands_t namelist[] = { + {t_override, PERM_LOGINOK,"OOverRide 好友名單"}, + {t_reject, PERM_LOGINOK, "BBlack 壞人名單"}, + {t_aloha,PERM_LOGINOK, "AALOHA 上站通知名單"}, +#ifdef POSTNOTIFY + {t_post,PERM_LOGINOK, "NNewPost 新文章通知名單"}, +#endif + {t_special,PERM_LOGINOK, "SSpecial 其他特別名單"}, + {NULL, 0, NULL} +}; + +/* User menu */ +static commands_t userlist[] = { + {u_info, PERM_LOGINOK, "IInfo 設定個人資料與密碼"}, + {calendar, PERM_LOGINOK, "CCalendar 個人行事曆"}, + {u_editcalendar, PERM_LOGINOK, "CCalendarEdit 編輯個人行事曆"}, + {u_loginview, PERM_LOGINOK, "LLogin View 選擇進站畫面"}, + {u_ansi, 0, "AANSI 切換 ANSI \033[36m彩\033[35m色\033[37m/" + "\033[30;47m黑\033[1;37m白\033[m模示"}, + {u_movie, 0, "MMovie 切換動畫模示"}, +#ifdef HAVE_SUICIDE + {u_kill, PERM_BASIC, "IKill 自殺!!"}, +#endif + {u_editplan, PERM_LOGINOK, "QQueryEdit 編輯名片檔"}, + {u_editsig, PERM_LOGINOK, "SSignature 編輯簽名檔"}, +#if HAVE_FREECLOAK + {u_cloak, PERM_LOGINOK, "CCloak 隱身術"}, +#else + {u_cloak, PERM_CLOAK, "CCloak 隱身術"}, +#endif + {u_register, PERM_BASIC, "RRegister 填寫《註冊申請單》"}, + {u_list, PERM_SYSOP, "UUsers 列出註冊名單"}, + {NULL, 0, NULL} +}; + +/* XYZ tool menu */ +static commands_t xyzlist[] = { +#ifdef HAVE_LICENSE + {x_gpl, 0, "LLicense GNU 使用執照"}, +#endif +#ifdef HAVE_INFO + {x_program, 0, "PProgram 本程式之版本與版權宣告"}, +#endif + {x_boardman,0, "MMan Boards 《看版精華區排行榜》"}, +// {x_boards,0, "HHot Boards 《看版人氣排行榜》"}, + {x_history, 0, "HHistory 《我們的成長》"}, + {x_note, 0, "NNote 《酸甜苦辣流言版》"}, + {x_login,0, "SSystem 《系統重要公告》"}, + {x_week, 0, "WWeek 《本週五十大熱門話題》"}, + {x_issue, 0, "IIssue 《今日十大熱門話題》"}, + {x_today, 0, "TToday 《今日上線人次統計》"}, + {x_yesterday, 0, "YYesterday 《昨日上線人次統計》"}, + {x_user100 ,0, "UUsers 《使用者百大排行榜》"}, + {x_birth, 0, "BBirthday 《今日壽星大觀》"}, + {p_sysinfo, 0, "XXload 《查看系統負荷》"}, + {NULL, 0, NULL} +}; + +/* Ptt money menu */ +static commands_t moneylist[] = { + {p_give, 0, "00Give 給其他人錢"}, + {save_violatelaw, 0,"11ViolateLaw 繳罰單"}, +#if !HAVE_FREECLOAK + {p_cloak, 0, "22Cloak 切換 隱身/現身 $19 /次"}, +#endif + {p_from, 0, "33From 暫時修改故鄉 $49 /次"}, + {ordersong,0, "44OSong 歐桑動態點歌機 $200 /次"}, + {p_exmail, 0, "55Exmail 購買信箱 $1000/封"}, + {NULL, 0, NULL} +}; + +static int p_money() { + domenu(PSALE, "Ptt量販店", '0', moneylist); + return 0; +}; + +static commands_t jceelist[] = { + {x_90,PERM_LOGINOK, "0090 JCEE 【90學年度大學聯招查榜系統】"}, + {x_89,PERM_LOGINOK, "1189 JCEE 【89學年度大學聯招查榜系統】"}, + {x_88,PERM_LOGINOK, "2288 JCEE 【88學年度大學聯招查榜系統】"}, + {x_87,PERM_LOGINOK, "3387 JCEE 【87學年度大學聯招查榜系統】"}, + {x_86,PERM_LOGINOK, "4486 JCEE 【86學年度大學聯招查榜系統】"}, + {NULL, 0, NULL} +}; + +static int m_jcee() { + domenu(JCEE, "Ptt查榜系統", '0', jceelist); + return 0; +} + +static int forsearch(); +static int playground(); + +/* Ptt Play menu */ +static commands_t playlist[] = { +#if HAVE_JCEE + {m_jcee, PERM_LOGINOK, "JJCEE 【 大學聯考查榜系統 】"}, +#endif + {note, PERM_LOGINOK, "NNote 【 刻刻流言版 】"}, + {x_weather,0 , "WWeather 【 氣象預報 】"}, + {x_stock,0 , "SStock 【 股市行情 】"}, +#ifdef HAVE_BIG2 + {x_big2, 0, "BBig2 【 網路大老二 】"}, +#endif +#ifdef HAVE_MJ + {x_mj, PERM_LOGINOK, "QQkmj 【 網路打麻將 】"}, +#endif +#ifdef HAVE_BRIDGE + {x_bridge, PERM_LOGINOK, "OOkBridge 【 橋牌競技 】"}, +#endif +#ifdef HAVE_GOPHER + {x_gopher, PERM_LOGINOK, "GGopher 【 地鼠資料庫 】"}, +#endif +#ifdef HAVE_TIN + {x_tin, PERM_LOGINOK, "NNEWS 【 網際新聞 】"}, +#endif +#ifdef BBSDOORS + {x_bbsnet, PERM_LOGINOK, "BBBSNet 【 其他 BBS站 】"}, +#endif +#ifdef HAVE_WWW + {x_www, PERM_LOGINOK, "WWWW Browser 【 汪汪汪 】"}, +#endif + {forsearch,PERM_LOGINOK, "SSearchEngine【\033[1;35m Ptt搜尋器 \033[m】"}, + {topsong,PERM_LOGINOK, "TTop Songs 【\033[1;32m歐桑點歌排行榜\033[m】"}, + {p_money,PERM_LOGINOK, "PPay 【\033[1;31m Ptt量販店 \033[m】"}, + {chicken_main,PERM_LOGINOK, "CChicken " + "【\033[1;34m Ptt養雞場 \033[m】"}, + {playground,PERM_LOGINOK, "AAmusement 【\033[1;33m Ptt遊樂場 \033[m】"}, + {NULL, 0, NULL} +}; + +static commands_t plist[] = { + +/* {p_ticket_main, PERM_LOGINOK,"00Pre 【 總統機 】"}, + {alive, PERM_LOGINOK, "00Alive 【 訂票雞 】"}, +*/ + {ticket_main, PERM_LOGINOK, "11Gamble 【 Ptt賭場 】"}, + {guess_main, PERM_LOGINOK, "22Guess number【 猜數字 】"}, + {othello_main, PERM_LOGINOK, "33Othello 【 黑白棋 】"}, +// {dice_main, PERM_LOGINOK, "44Dice 【 玩骰子 】"}, + {vice_main, PERM_LOGINOK, "44Vice 【 發票對獎 】"}, + {g_card_jack, PERM_LOGINOK, "55Jack 【 黑傑克 】"}, + {g_ten_helf, PERM_LOGINOK, "66Tenhalf 【 十點半 】"}, + {card_99, PERM_LOGINOK, "77Nine 【 九十九 】"}, + {NULL, 0, NULL} +}; + +static int playground() { + domenu(AMUSE, "Ptt遊樂場",'1',plist); + return 0; +} + +static commands_t slist[] = { + {x_dict,0, "11Dictionary " + "【\033[1;33m 趣味大字典 \033[m】"}, + {main_railway, PERM_LOGINOK, "33Railway " + "【\033[1;32m 火車表查詢 \033[m】"}, + {NULL, 0, NULL} +}; + +static int forsearch() { + domenu(SREG, "Ptt搜尋器", '1', slist); + return 0; +} + +/* main menu */ + +static int admin() { + domenu(ADMIN, "系統維護", 'X', adminlist); + return 0; +} + +static int Mail() { + domenu(MAIL, "電子郵件", 'R', maillist); + return 0; +} + +static int Talk() { + domenu(TMENU, "聊天說話", 'U', talklist); + return 0; +} + +static int User() { + domenu(UMENU, "個人設定", 'A', userlist); + return 0; +} + +static int Xyz() { + domenu(XMENU, "工具程式", 'M', xyzlist); + return 0; +} + +static int Play_Play() { + domenu(PMENU, "網路遊樂場", 'A', playlist); + return 0; +} + +static int Name_Menu() { + domenu(NMENU, "白色恐怖", 'O', namelist); + return 0; +} + +commands_t cmdlist[] = { + {admin,PERM_SYSOP|PERM_VIEWSYSOP, "00Admin 【 系統維護區 】"}, + {Announce, 0, "AAnnounce 【 精華公佈欄 】"}, + {Boards, 0, "FFavorite 【 我 的 最愛 】"}, + {root_board, 0, "CClass 【 分組討論區 】"}, + {Mail, PERM_BASIC, "MMail 【 私人信件區 】"}, + {Talk, 0, "TTalk 【 休閒聊天區 】"}, + {User, 0, "UUser 【 個人設定區 】"}, + {Xyz, 0, "XXyz 【 系統工具區 】"}, + {Play_Play,0, "PPlay 【 遊樂場/大學查榜】"}, + {Name_Menu,PERM_LOGINOK, "NNamelist 【 編特別名單 】"}, + {Goodbye, 0, "GGoodbye 離開,再見……"}, + {NULL, 0, NULL} +}; diff --git a/pttbbs/mbbsd/more.c b/pttbbs/mbbsd/more.c new file mode 100644 index 00000000..f7755874 --- /dev/null +++ b/pttbbs/mbbsd/more.c @@ -0,0 +1,931 @@ +/* $Id: more.c,v 1.1 2002/03/07 15:13:48 in2 Exp $ */ +#include +#include +#include +#include +#include +#include +#include +#include + +#include "config.h" +#include "pttstruct.h" +#include "common.h" +#include "modes.h" +#include "perm.h" +#include "proto.h" + +extern int showansi; +extern int t_lines, t_columns; /* Screen size / width */ +extern int b_lines; /* Screen bottom line number: t_lines-1 */ +extern char *str_author1; +extern char *str_author2; +extern char *str_post1; +extern char *str_post2; +extern char *msg_seperator; +extern char reset_color[]; + +#define MORE_BUFSIZE 4096 +#define MORE_WINSIZE 4096 +#define STR_ANSICODE "[0123456789;," + +static int more_base, more_size, more_head; +static unsigned char more_pool[MORE_BUFSIZE]; + + +#define MAXPATHLEN 256 +static char *more_help[] = { + "\0閱\讀文章功\能鍵使用說明", + "\01游標移動功\能鍵", + "(↑) 上捲一行", + "(↓)(Enter) 下捲一行", + "(^B)(PgUp)(BackSpace) 上捲一頁", + "(→)(PgDn)(Space) 下捲一頁", + "(0)(g)(Home) 檔案開頭", + "($)(G) (End) 檔案結尾", + "\01其他功\能鍵", + "(/) 搜尋字串", + "(n/N) 重複正/反向搜尋", + "(TAB) URL連結", + "(Ctrl-T) 存到暫存檔", + "(:/f/b) 跳至某頁/下/上篇", + "(F/B) 跳至同一搜尋主題下/上篇", + "(a/A) 跳至同一作者下/上篇", + "([/]) 主題式閱\讀 上/下", + "(t) 主題式循序閱\讀", + "(Ctrl-C) 小計算機", + "(q)(←) 結束", + "(h)(H)(?) 輔助說明畫面", + NULL +}; + +int beep = 0; + +static void +more_goto (int fd, off_t off) +{ + int base = more_base; + + if (off < base || off >= base + more_size) + { + more_base = base = off & (-MORE_WINSIZE); + lseek (fd, base, SEEK_SET); + more_size = read (fd, more_pool, MORE_BUFSIZE); + } + more_head = off - base; +} + +static int +more_readln (int fd, unsigned char *buf) +{ + int ch; + + unsigned char *data, *tail, *cc; + int len, bytes, in_ansi; + int size, head, ansilen; + + len = bytes = in_ansi = ansilen = 0; + tail = buf + ANSILINELEN - 1; + size = more_size; + head = more_head; + data = &more_pool[head]; + + do + { + if (head >= size) + { + more_base += size; + data = more_pool; + more_size = size = read (fd, data, MORE_BUFSIZE); + if (size == 0) + break; + head = 0; + } + + ch = *data++; + head++; + bytes++; + if (ch == '\n') + { + break; + } + if (ch == '\t') + { + do + { + *buf++ = ' '; + } + while ((++len & 7) && len < 80); + } + else if (ch == '\033') + { + if (atoi (data + 1) > 47) + { + if ((cc = strchr (data + 1, 'm')) != NULL) + { + ch = cc - data + 1; + + data += ch; + head += ch; + bytes += ch; + } + } + else + { + if (showansi) + *buf++ = ch; + in_ansi = 1; + } + } + else if (in_ansi) + { + if (showansi) + *buf++ = ch; + if (!strchr (STR_ANSICODE, ch)) + in_ansi = 0; + } + else if (isprint2 (ch)) + { + len++; + *buf++ = ch; + } + } + while (len < 80 && buf < tail); + *buf = '\0'; + more_head = head; + return bytes; +} + +/* not used +static int readln(FILE *fp, char *buf) { + register int ch, i, len, bytes, in_ansi; + + len = bytes = in_ansi = i = 0; + while(len < 80 && i < ANSILINELEN && (ch = getc(fp)) != EOF) { + bytes++; + if(ch == '\n') + break; + else if(ch == '\t') + do { + buf[i++] = ' '; + } while((++len & 7) && len < 80); + else if(ch == '\a') + beep = 1; + else if(ch == '\033') { + if(showansi) + buf[i++] = ch; + in_ansi = 1; + } else if(in_ansi) { + if(showansi) + buf[i++] = ch; + if(!strchr("[0123456789;,", ch)) + in_ansi = 0; + } else if(isprint2(ch)) { + len++; + buf[i++] = ch; + } + } + buf[i] = '\0'; + return bytes; +} +*/ + +extern userec_t cuser; + +static int more_web(char *fpath, int promptend); + +int more(char *fpath, int promptend) { + extern char* strcasestr(); + static char *head[4] = {"作者", "標題", "時間" ,"轉信"}; + char *ptr, *word = NULL, buf[ANSILINELEN + 1], *ch1; + struct stat st; + +/* rocker */ + //FILE *fp; + int fd, fsize; + + unsigned int pagebreak[MAX_PAGES], pageno, lino = 0; + int line, ch, viewed, pos, numbytes; + int header = 0; + int local = 0; + char search_char0=0; + static char search_str[81]=""; + typedef char* (*FPTR)(); + static FPTR fptr; + int searching = 0; + int scrollup = 0; + char *printcolor[3]= {"44","33;45","0;34;46"}, color =0; + char *http[80]={NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL, + NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL, + NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL, + NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL, + NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL, + NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL, + NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL, + NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL}; + /* Ptt */ + char pagemode = 0; + char pagecount = 0; + + memset(pagebreak, 0, sizeof(pagebreak)); + if(*search_str) + search_char0 = *search_str; + *search_str = 0; + + + fd = open (fpath, O_RDONLY, 0600); + if (fd < 0) return -1; + + if(fstat(fd, &st) || ((fsize = st.st_size) <= 0) || S_ISDIR (st.st_mode)) + { + close(fd); //Ptt + return -1; + } + pagebreak[0] = pageno = viewed = line = pos = 0; + clear(); + +/* rocker */ + + more_base = more_head = more_size = 0; + + while((numbytes = more_readln(fd, buf)) || (line == t_lines)) { + if(scrollup) { + rscroll(); + move(0, 0); + } + if(numbytes) { /* 一般資料處理 */ + if(!viewed) { /* begin of file */ + if(showansi) { /* header processing */ + if(!strncmp(buf, str_author1, LEN_AUTHOR1)) { + line = 3; + word = buf + LEN_AUTHOR1; + local = 1; + } else if(!strncmp(buf, str_author2, LEN_AUTHOR2)) { + line = 4; + word = buf + LEN_AUTHOR2; + } + + while(pos < line) { + if(!pos && ((ptr = strstr(word, str_post1)) || + (ptr = strstr(word, str_post2)))) { + ptr[-1] = '\0'; + prints("\033[47;34m %s \033[44;37m%-53.53s" + "\033[47;34m %.4s \033[44;37m%-13s\033[m\n", + head[0], word, ptr, ptr + 5); + } else if (pos < 4) + prints("\033[47;34m %s \033[44;37m%-72.72s" + "\033[m\n", head[pos], word); + + viewed += numbytes; + numbytes = more_readln(fd, buf); + + /* 第一行太長了 */ + if(!pos && viewed > 79) { + /* 第二行不是 [標....] */ + if(memcmp( buf, head[1], 2)) { + /* 讀下一行進來處理 */ + viewed += numbytes; + numbytes = more_readln(fd, buf); + } + } + pos++; + } + if(pos) { + header = 1; + + prints("\033[36m%s\033[m\n", msg_seperator); + line = pos = 4; + } + } + lino = pos; + word = NULL; + } + + /* ※處理引用者 & 引言 */ + if((buf[1] == ' ') && (buf[0] == ':' || buf[0] == '>')) + word = "\033[36m"; + else if(!strncmp(buf, "※", 2) || !strncmp(buf, "==>", 3)) + word = "\033[32m"; + + ch1 = buf; + while(1) { + int i; + char e,*ch2; + + if((ch2 = strstr(ch1, "http://"))) + ; + else if((ch2 = strstr(ch1,"gopher://"))) + ; + else if((ch2 = strstr(ch1,"mailto:"))) + ; + else + break; + for(e = 0; ch2[(int)e] != ' ' && ch2[(int)e] != '\n' && + ch2[(int)e] != '\0' && ch2[(int)e] != '"' && + ch2[(int)e] != ';' && ch2[(int)e] != ']'; e++); + for(i = 0; http[i] && i < 80; i++) + if(!strncmp(http[i], ch2, e) && http[(int)e] == 0) + break; + if(!http[i]) { + http[i] = (char *)malloc(e + 1); + strncpy(http[i], ch2, e); + http[i][(int)e] = 0; + pagecount++; + } + ch1 = &ch2[7]; + } + if(word) + outs(word); + { + char msg[500], *pos; + + if(*search_str && (pos = fptr(buf, search_str))) { + char SearchStr[81]; + char buf1[100], *pos1; + + strncpy(SearchStr, pos, strlen(search_str)); + SearchStr[strlen(search_str)] = 0; + searching = 0; + sprintf(msg, "%.*s\033[7m%s\033[m", pos - buf, buf, + SearchStr); + while((pos = fptr(pos1 = pos + strlen(search_str), + search_str))) { + sprintf(buf1, "%.*s\033[7m%s\033[m", pos - pos1, + pos1, SearchStr); + strcat(msg, buf1); + } + strcat(msg, pos1); + outs(Ptt_prints(msg,NO_RELOAD)); + } else + outs(Ptt_prints(buf,NO_RELOAD)); + } + if(word) { + outs("\033[m"); + word = NULL; + } + outch('\n'); + + if(beep) { + bell(); + beep = 0; + } + + if(line < b_lines) /* 一般資料讀取 */ + line++; + + if(line == b_lines && searching == -1) { + if(pageno > 0) + more_goto(fd, viewed = pagebreak[--pageno]); + else + searching = 0; + lino = pos = line = 0; + clear(); + continue; + } + + if(scrollup) { + move(line = b_lines, 0); + clrtoeol(); + for(pos = 1; pos < b_lines; pos++) + viewed += more_readln(fd, buf); + } else if(pos == b_lines) /* 捲動螢幕 */ + scroll(); + else + pos++; + + if(!scrollup && ++lino >= b_lines && pageno < MAX_PAGES - 1) { + pagebreak[++pageno] = viewed; + lino = 1; + } + + if(scrollup) { + lino = scrollup; + scrollup = 0; + } + viewed += numbytes; /* 累計讀過資料 */ + } else + line = b_lines; /* end of END */ + + if(promptend && + ((!searching && line == b_lines) || viewed == fsize)) { + /* Kaede 剛好 100% 時不停 */ + move(b_lines, 0); + if(viewed == fsize) { + if(searching == 1) + searching = 0; + color = 0; + } else if(pageno == 1 && lino == 1) { + if(searching == -1) + searching = 0; + color = 1; + } else + color = 2; + + prints("\033[m\033[%sm 瀏覽 P.%d(%d%%) %s %-30.30s%s", + printcolor[(int)color], + pageno, + (int)((viewed * 100) / fsize), + pagemode ? "\033[30;47m" : "\033[31;47m", + pagemode ? http[pagemode-1] : "(h)\033[30m求助 \033[31m→↓[PgUp][", + pagemode ? "\033[31m[TAB]\033[30m切換 \033[31m[Enter]\033[30m選定 \033[31m←\033[30m放棄\033[m" : "PgDn][Home][End]\033[30m游標移動 \033[31m←[q]\033[30m結束 \033[m"); + + + while(line == b_lines || (line > 0 && viewed == fsize)) { + switch((ch = egetch())) { + case ':': + { + char buf[10]; + int i = 0; + + getdata(b_lines - 1, 0, "Goto Page: ", buf, 5, DOECHO); + sscanf(buf, "%d", &i); + if(0 < i && i < MAX_PAGES && (i == 1 || pagebreak[i - 1])) + pageno = i - 1; + else if(pageno) + pageno--; + lino = line = 0; + break; + } + case '/': + { + char ans[4] = "n"; + + *search_str = search_char0; + getdata_buf(b_lines - 1, 0,"[搜尋]關鍵字:", search_str, + 40, DOECHO); + if(*search_str) { + searching = 1; + if(getdata(b_lines - 1, 0, "區分大小寫(Y/N/Q)? [N] ", + ans, 4, LCECHO) && *ans == 'y') + fptr = strstr; + else + fptr = strcasestr; + } + if(*ans == 'q') + searching = 0; + if(pageno) + pageno--; + lino = line = 0; + break; + } + case 'n': + if(*search_str) { + searching = 1; + if(pageno) + pageno--; + lino = line = 0; + } + break; + case 'N': + if(*search_str) { + searching = -1; + if(pageno) + pageno--; + lino = line = 0; + } + break; + case 'r': + case 'R': + case 'Y': + close(fd); + return 7; + case 'y': + close(fd); + return 8; + case 'A': + close(fd); + return 9; + case 'a': + close(fd); + return 10; + case 'F': + close(fd); + return 11; + case 'B': + close(fd); + return 12; + case KEY_LEFT: + if(pagemode) { + pagemode = 0; + *search_str = 0; + if(pageno) + pageno--; + lino = line = 0; + break; + } + close(fd); + return 6; + case 'q': + close(fd); + return 0; + case 'b': + close(fd); + return 1; + case 'f': + close(fd); + return 3; + case ']': /* Kaede 為了主題閱讀方便 */ + close(fd); + return 4; + case '[': /* Kaede 為了主題閱讀方便 */ + close(fd); + return 2; + case '=': /* Kaede 為了主題閱讀方便 */ + close(fd); + return 5; + case Ctrl('F'): + case KEY_PGDN: + line = 1; + break; + case 't': + if(viewed == fsize) { + close(fd); + return 4; + } + line = 1; + break; + case ' ': + if(viewed == fsize) { + close(fd); + return 3; + } + line = 1; + break; + case KEY_RIGHT: + if(viewed == fsize) { + close(fd); + return 0; + } + line = 1; + break; + case '\r': + case '\n': + if(pagemode) { + more_web(http[pagemode-1],YEA); + pagemode = 0; + *search_str = 0; + if(pageno) + pageno--; + lino = line = 0; + break; + } + case KEY_DOWN: + if(viewed == fsize || + (promptend == 2 && (ch == '\r' || ch == '\n'))) { + close(fd); + return 3; + } + line = t_lines - 2; + break; + case '$': + case 'G': + case KEY_END: + line = t_lines; + break; + case '0': + case 'g': + case KEY_HOME: + pageno = line = 0; + break; + case 'h': + case 'H': + case '?': + /* Kaede Buggy ... */ + show_help(more_help); + if(pageno) + pageno--; + lino = line = 0; + break; + case 'E': + if(HAS_PERM(PERM_SYSOP) && strcmp(fpath, "etc/ve.hlp")) { + close(fd); + vedit(fpath, NA, NULL); + return 0; + } + break; + case Ctrl('C'): + cal(); + if(pageno) + pageno--; + lino = line = 0; + break; + + case Ctrl('T'): + getdata(b_lines - 2, 0, "把這篇文章收入到暫存檔?[y/N] ", + buf, 4, LCECHO); + if(buf[0] == 'y') { + char tmpbuf[128]; + + setuserfile(tmpbuf, ask_tmpbuf(b_lines - 1)); + sprintf(buf, "cp -f %s %s", fpath, tmpbuf); + system(buf); + } + if(pageno) + pageno--; + lino = line = 0; + break; +#if 0 + case Ctrl('I'): + if(!pagecount) + break; + pagemode = (pagemode % pagecount) + 1; + strncpy(search_str,http[pagemode-1],80); + search_str[80] =0; + fptr = strstr; + if(pageno) + pageno--; + lino = line = 0; + break; +#endif + case KEY_UP: + line = -1; + break; + case Ctrl('B'): + case KEY_PGUP: + if(pageno > 1) { + if(lino < 2) + pageno -= 2; + else + pageno--; + lino = line = 0; + } else if(pageno && lino > 1) + pageno = line = 0; + break; + case Ctrl('H'): + if(pageno > 1) { + if(lino < 2) + pageno -= 2; + else + pageno--; + lino = line = 0; + } else if(pageno && lino > 1) + pageno = line = 0; + else { + close(fd); + return 1; + } + } + } + + if(line > 0) { + move(b_lines, 0); + clrtoeol(); + refresh(); + } else if(line < 0) { /* Line scroll up */ + if(pageno <= 1) { + if(lino == 1 || !pageno) { + close(fd); + return 1; + } + if(header && lino <= 5) { + more_goto(fd, viewed = pagebreak[scrollup = lino = + pageno = 0] = 0); + clear(); + } + } + if(pageno && lino > 1 + local) { + line = (lino - 2) - local; + if(pageno > 1 && viewed == fsize) + line += local; + scrollup = lino - 1; + more_goto(fd, viewed = pagebreak[pageno - 1]); + while(line--) + viewed += more_readln(fd, buf); + } else if(pageno > 1) { + scrollup = b_lines - 1; + line = (b_lines - 2) - local; + more_goto(fd, viewed = pagebreak[--pageno - 1]); + while(line--) + viewed += more_readln(fd, buf); + } + line = pos = 0; + } else { + pos = 0; + more_goto (fd, viewed = pagebreak[pageno]); + move(0,0); + clear(); + } + } + } + + close(fd); + if(promptend) { + pressanykey(); + clear(); + } else + outs(reset_color); + return 0; +} + +static int more_web(char *fpath, int promptend) { + char *ch, *ch1 = NULL; + char *hostname = fpath,userfile[MAXPATHLEN],file[MAXPATHLEN]="/"; + char genbuf[200]; + time_t dtime; +#if !defined(USE_LYNX) && defined(USE_PROXY) + int a; + FILE *fp; + struct hostent *h; + struct sockaddr_in sin; +#endif + + if((ch = strstr(fpath, "mailto:"))) { + if(!HAS_PERM(PERM_LOGINOK)) { + move(b_lines - 1,0); + outs("\033[41m 您的權限不足無法使用internet mail... \033[m"); + refresh(); + return 0; + } + if(!invalidaddr(&ch[7]) && + getdata(b_lines - 1, 0, "[寄信]主題:", genbuf, 40, DOECHO)) + do_send(&ch[7], genbuf); + else { + move(b_lines - 1,0); + outs("\033[41m 收信人email 或 標題 有誤... \033[m"); + refresh(); + } + return 0; + } + if((ch = strstr(fpath, "gopher://"))) { + item_t item; + + strcpy(item.X.G.server, &ch[9]); + strcpy(item.X.G.path, "1/"); + item.X.G.port = 70; + gem(fpath , &item, 0); + return 0; + } + if((ch = strstr(fpath, "http://"))) + hostname=&ch[7]; + if((ch = strchr(hostname, '/'))) { + *ch = 0; + if(&ch1[1]) + strcat(file,&ch[1]); + } + if(file[strlen(file) - 1] == '/') + strcat(file,"index.html"); + move(b_lines-1,0); + clrtoeol(); +#ifdef USE_PROXY + sprintf(genbuf, "\033[33;44m 正在連往%s.(proxy:%s).....請稍候....\033[m", + hostname, PROXYSERVER); +#else + sprintf(genbuf, "\033[33;44m 正在連往%s......請稍候....\033[m", hostname); +#endif + outs(genbuf); + refresh(); + +#ifdef LOCAL_PROXY +/* 先找 local disk 的 proxy */ + time(&dtime); + sprintf(userfile,"hproxy/%s%s",hostname,file); + if(dashf(userfile) && (dtime - dasht(userfile)) < HPROXYDAY * 24 * 60 + && more(userfile,promptend)) { + return 1; + } + ch=userfile - 1; + while((ch1 = strchr(ch + 1,'/'))) { + *ch1 = 0; + if(!dashd(ch)) + mkdir(ch+1,0755); + chdir(ch+1); + *ch1 = '/'; + ch = ch1; + } + chdir(BBSHOME); +#endif + +#ifndef USE_LYNX +#ifdef USE_PROXY + if(!(h = gethostbyname(PROXYSERVER))) { + outs("\033[33;44m 找不到這個proxy server!..\033[m"); + refresh(); + return; + } + ()memset((char *)&sin, 0, sizeof(sin)); + sin.sin_family = AF_INET; + + if(h == NULL) + sin.sin_addr.s_addr = inet_addr(PROXYSERVER); + else + ()memcpy(&sin.sin_addr.s_addr, h->h_addr, h->h_length); + + sin.sin_port = htons((ushort)PROXYPORT); /* HTTP port */ + a = socket(AF_INET, SOCK_STREAM, 0); + if((connect(a, (struct sockaddr *) & sin, sizeof sin)) < 0) { + outs("\033[1;44m 連接到proxy受到拒絕 ! \033[m"); + refresh(); + return; + } + sprintf(genbuf,"GET http://%s/%s HTTP/1.1\n",hostname,file); +#else + if(!(h = gethostbyname(hostname))) { + outs("\033[33;44m 找不到這個server!..\033[m"); + refresh(); + return; + } + ()memset((char *) &sin, 0, sizeof(sin)); + sin.sin_family = AF_INET; + + if(h == NULL) + sin.sin_addr.s_addr = inet_addr(hostname); + else + ()memcpy(&sin.sin_addr.s_addr, h->h_addr, h->h_length); + + sin.sin_port = htons((ushort)80); + a = socket(AF_INET, SOCK_STREAM, 0); + if((connect(a, (struct sockaddr *) & sin, sizeof sin)) < 0) { + outs("\033[1;44m 連接受到拒絕 ! \033[m"); + refresh(); + return; + } + sprintf(genbuf, "GET %s\n", file); +#endif + + for(i = strlen(file); file[i - 1] != '/' && i > 0 ; i--); + file[i] = 0; + + i = strlen(genbuf); + write(a, genbuf, i); + +#define BLANK 001 +#define ISPRINT 002 +#define PRE 004 +#define CENTER 010 + if((fp = fopen(userfile,"w"))) { + int flag = 2, c; + char path[MAXPATHLEN]; + unsigned char j, k; + + while((i = read(a,genbuf,200))) { + if(i < 0) + return; + genbuf[i]=0; + + for(j = 0, k = 0; genbuf[j] && j < i; j++) { + if((flag & ISPRINT) && genbuf[j] == '<') + flag |= BLANK; + else if((flag & ISPRINT) && genbuf[j] == '>') + flag &= ~BLANK; + else { + if(!(flag & BLANK)) { + if(j != k && (genbuf[j] != '\n' || flag & PRE)) + genbuf[k++] = genbuf[j]; + } else { + switch(char_lower(genbuf[j])) { + case 'a': + break; + case 'b': + if(genbuf[j + 1] == 'r' && genbuf[j + 2] == '>') + genbuf[k++] = '\n'; + break; + case 'h': + if(genbuf[j + 1] == 'r' && + (genbuf[j + 2] == '>' || + genbuf[j + 2] == 's')) { + strncpy(&genbuf[k], "\n--\n", 4); + k += 4; + } + break; + case 'l': + if(genbuf[j + 1] == 'i' && genbuf[j + 2]=='>') { + strncpy(&genbuf[k], "\n◎ ", 4); + k += 4; + } + break; + case 'p': + if(genbuf[j + 1]=='>') { + genbuf[k++] = '\n'; + genbuf[k++] = '\n'; + } else if(genbuf[j + 1] == 'r' && + genbuf[j + 2] == 'e') + flag ^= PRE; + break; + case 't': + if(genbuf[j + 1] == 'd' && genbuf[j + 2]=='>') { + strncpy(&genbuf[k], "\n-\n", 3); + k += 3; + } + break; + } + } + if((genbuf[j] & 0x80) && (flag & ISPRINT)) + flag &= ~ISPRINT; + else + flag |= ISPRINT; + } + } + genbuf[k]=0; + fputs(genbuf, fp); + } + fclose(fp); + close(a); + return more(userfile, promptend); + } + return 0; +#else /* use lynx dump */ + sprintf(genbuf, "lynx -dump http://%s%s > %s", hostname, file, userfile); + system(genbuf); + return more(userfile, promptend); +#endif +} diff --git a/pttbbs/mbbsd/name.c b/pttbbs/mbbsd/name.c new file mode 100644 index 00000000..2f84a1fe --- /dev/null +++ b/pttbbs/mbbsd/name.c @@ -0,0 +1,473 @@ +/* $Id: name.c,v 1.1 2002/03/07 15:13:48 in2 Exp $ */ +#include +#include +#include +#include +#include +#include +#include "config.h" +#include "pttstruct.h" +#include "common.h" +#include "proto.h" + +extern char *str_space; +extern int p_lines; /* a Page of Screen line numbers: tlines-4 */ +extern int b_lines; /* Screen bottom line number: t_lines-1 */ + +word_t *toplev = NULL; +static word_t *current = NULL; +static char *msg_more = "\033[7m-- More --\033[m"; + +typedef char (*arrptr)[]; +/* name complete for user ID */ + +static int UserMaxLen(char cwlist[][IDLEN + 1], int cwnum, int morenum, + int count) { + int len, max = 0; + + while(count-- > 0 && morenum < cwnum) { + len = strlen(cwlist[morenum++]); + if (len > max) + max = len; + } + return max; +} + +static int UserSubArray(char cwbuf[][IDLEN + 1], char cwlist[][IDLEN + 1], + int cwnum, int key, int pos) { + int key2, num = 0; + int n, ch; + + key = chartoupper(key); + if(key >= 'A' && key <= 'Z') + key2 = key | 0x20; + else + key2 = key ; + + for(n = 0; n < cwnum; n++) { + ch = cwlist[n][pos]; + if(ch == key || ch == key2) + strcpy(cwbuf[num++], cwlist[n]); + } + return num; +} + +static void FreeNameList() { + word_t *p, *temp; + + for(p = toplev; p; p = temp) { + temp = p->next; + free(p->word); + free(p); + } +} + +void CreateNameList() { + if(toplev) + FreeNameList(); + toplev = current = NULL; +} + +void AddNameList(char *name) { + word_t *node; + + node = (word_t *)malloc(sizeof(word_t)); + node->next = NULL; + node->word = (char *)malloc(strlen(name) + 1); + strcpy(node->word, name); + + if(toplev) + current = current->next = node; + else + current = toplev = node; +} + +int RemoveNameList(char *name) { + word_t *curr, *prev = NULL; + + for(curr = toplev; curr; curr = curr->next) { + if(!strcmp(curr->word, name)) { + if(prev == NULL) + toplev = curr->next; + else + prev->next = curr->next; + + if(curr == current) + current = prev; + free(curr->word); + free(curr); + return 1; + } + prev = curr; + } + return 0; +} + +int InNameList(char *name) { + word_t *p; + + for(p = toplev; p; p = p->next) + if(!strcmp(p->word, name)) + return 1; + return 0; +} + +void ShowNameList(int row, int column, char *prompt) { + word_t *p; + + move(row, column); + clrtobot(); + outs(prompt); + + column = 80; + for(p = toplev; p; p = p->next) { + row = strlen(p->word) + 1; + if(column + row > 76) { + column = row; + outc('\n'); + } else { + column += row; + outc(' '); + } + outs(p->word); + } +} + +void ToggleNameList(int *reciper, char *listfile, char *msg) { + FILE *fp; + char genbuf[200]; + + if((fp = fopen(listfile, "r"))) { + while(fgets(genbuf, STRLEN, fp)) { + strtok(genbuf, str_space); + if(!InNameList(genbuf)) { + AddNameList(genbuf); + (*reciper)++; + } else { + RemoveNameList(genbuf); + (*reciper)--; + } + } + fclose(fp); + ShowNameList(3, 0, msg); + } +} + +static int NumInList(word_t *list) { + register int i; + + for(i = 0; list; i++) + list = list->next; + return i; +} + +int chkstr(char *otag, char *tag, char *name) { + char ch, *oname = name; + + while(*tag) { + ch = *name++; + if(*tag != chartoupper(ch)) + return 0; + tag++; + } + if(*tag && *name == '\0') + strcpy(otag, oname); + return 1; +} + +static word_t *GetSubList(char *tag, word_t *list) { + word_t *wlist, *wcurr; + char tagbuf[STRLEN]; + int n; + + wlist = wcurr = NULL; + for(n = 0; tag[n]; n++) + tagbuf[n] = chartoupper(tag[n]); + tagbuf[n] = '\0'; + + while(list) { + if(chkstr(tag, tagbuf, list->word)) { + register word_t *node; + + node = (word_t *)malloc(sizeof(word_t)); + node->word = list->word; + node->next = NULL; + if(wlist) + wcurr->next = node; + else + wlist = node; + wcurr = node; + } + list = list->next; + } + return wlist; +} + +static void ClearSubList(word_t *list) { + struct word_t *tmp_list; + + while(list) { + tmp_list = list->next; + free(list); + list = tmp_list; + } +} + +static int MaxLen(word_t *list, int count) { + int len = strlen(list->word); + int t; + + while(list && count) { + if((t = strlen(list->word)) > len) + len = t; + list = list->next; + count--; + } + return len; +} + +void namecomplete(char *prompt, char *data) { + char *temp; + word_t *cwlist, *morelist; + int x, y, origx, origy; + int ch; + int count = 0; + int clearbot = NA; + + if(toplev == NULL) + AddNameList(""); + cwlist = GetSubList("", toplev); + morelist = NULL; + temp = data; + + outs(prompt); + clrtoeol(); + getyx(&y, &x); + getyx(&origy, &origx); + standout(); + prints("%*s", IDLEN + 1, ""); + standend(); + move(y, x); + refresh(); + + while((ch = igetch()) != EOF) { + if(ch == '\n' || ch == '\r') { + *temp = '\0'; + outc('\n'); + if(NumInList(cwlist) == 1) + strcpy(data, cwlist->word); + ClearSubList(cwlist); + break; + } + if(ch == ' ') { + int col, len; + + if(NumInList(cwlist) == 1) { + strcpy(data, cwlist->word); + move(y, x); + outs(data + count); + count = strlen(data); + temp = data + count; + getyx(&y, &x); + continue; + } + clearbot = YEA; + col = 0; + if(!morelist) + morelist = cwlist; + len = MaxLen(morelist, p_lines); + move(2, 0); + clrtobot(); + printdash("相關資訊一覽表"); + while(len + col < 80) { + int i; + + for(i = p_lines; (morelist) && (i > 0); i--) { + move(3 + (p_lines - i), col); + outs(morelist->word); + morelist = morelist->next; + } + col += len + 2; + if(!morelist) + break; + len = MaxLen(morelist, p_lines); + } + if(morelist) { + move(b_lines, 0); + outs(msg_more); + } + move(y, x); + continue; + } + if(ch == '\177' || ch == '\010') { + if(temp == data) + continue; + temp--; + count--; + *temp = '\0'; + ClearSubList(cwlist); + cwlist = GetSubList(data, toplev); + morelist = NULL; + x--; + move(y, x); + outc(' '); + move(y, x); + continue; + } + + if(count < STRLEN && isprint(ch)) { + word_t *node; + + *temp++ = ch; + count++; + *temp = '\0'; + node = GetSubList(data, cwlist); + if(node == NULL) { + temp--; + *temp = '\0'; + count--; + continue; + } + ClearSubList(cwlist); + cwlist = node; + morelist = NULL; + move(y, x); + outc(ch); + x++; + } + } + if(ch == EOF) + /* longjmp(byebye, -1); */ + raise(SIGHUP); /* jochang: don't know if this is necessary... */ + outc('\n'); + refresh(); + if(clearbot) { + move(2, 0); + clrtobot(); + } + if(*data) { + move(origy, origx); + outs(data); + outc('\n'); + } +} + +void usercomplete(char *prompt, char *data) { + char *temp; + char *cwbuf, *cwlist; + int cwnum, x, y, origx, origy; + int clearbot = NA, count = 0, morenum = 0; + char ch; + + cwbuf = malloc(MAX_USERS * (IDLEN + 1)); + cwlist = u_namearray((arrptr)cwbuf, &cwnum, ""); + temp = data; + + outs(prompt); + clrtoeol(); + getyx(&y, &x); + getyx(&origy, &origx); + standout(); + prints("%*s", IDLEN + 1, ""); + standend(); + move(y, x); + while((ch = igetch()) != EOF) { + if(ch == '\n' || ch == '\r') { + int i; + char *ptr; + + *temp = '\0'; + outc('\n'); + ptr = (char *)cwlist; + for(i = 0; i < cwnum; i++) { + if(strncasecmp(data, ptr, IDLEN + 1) == 0) + strcpy(data, ptr); + ptr += IDLEN + 1; + } + break; + } else if(ch == ' ') { + int col, len; + + if(cwnum == 1) { + strcpy(data, (char *)cwlist); + move(y, x); + outs(data + count); + count = strlen(data); + temp = data + count; + getyx(&y, &x); + continue; + } + clearbot = YEA; + col = 0; + len = UserMaxLen((arrptr)cwlist, cwnum, morenum, p_lines); + move(2, 0); + clrtobot(); + printdash("使用者代號一覽表"); + while(len + col < 79) { + int i; + + for(i = 0; morenum < cwnum && i < p_lines; i++) { + move(3 + i, col); + prints("%s ", cwlist + (IDLEN + 1) * morenum++); + } + col += len + 2; + if(morenum >= cwnum) + break; + len = UserMaxLen((arrptr)cwlist, cwnum, morenum, p_lines); + } + if(morenum < cwnum) { + move(b_lines, 0); + outs(msg_more); + } else + morenum = 0; + move(y, x); + continue; + } else if(ch == '\177' || ch == '\010') { + if(temp == data) + continue; + temp--; + count--; + *temp = '\0'; + cwlist = u_namearray((arrptr)cwbuf, &cwnum, data); + morenum = 0; + x--; + move(y, x); + outc(' '); + move(y, x); + continue; + } else if(count < STRLEN && isprint(ch)) { + int n; + + *temp++ = ch; + *temp = '\0'; + n = UserSubArray((arrptr)cwbuf, (arrptr)cwlist, cwnum, ch, count); + if(n == 0) { + temp--; + *temp = '\0'; + continue; + } + cwlist = cwbuf; + count++; + cwnum = n; + morenum = 0; + move(y, x); + outc(ch); + x++; + } + } + free(cwbuf); + if(ch == EOF) + /* longjmp(byebye, -1); */ + raise(SIGHUP); /* jochang: don't know if this is necessary */ + outc('\n'); + refresh(); + if(clearbot) { + move(2, 0); + clrtobot(); + } + if(*data) { + move(origy, origx); + outs(data); + outc('\n'); + } +} diff --git a/pttbbs/mbbsd/osdep.c b/pttbbs/mbbsd/osdep.c new file mode 100644 index 00000000..967a4db0 --- /dev/null +++ b/pttbbs/mbbsd/osdep.c @@ -0,0 +1,79 @@ +/* $Id: osdep.c,v 1.1 2002/03/07 15:13:48 in2 Exp $ */ +#include +#include +#include +#include +#include + +#if defined(linux) +int cpuload(char *str) { + double l[3] = {-1, -1, -1}; + FILE *fp; + + if((fp = fopen("/proc/loadavg", "r"))) { + if(fscanf(fp, "%lf %lf %lf", &l[0], &l[1], &l[2]) != 3) + l[0] = -1; + fclose(fp); + } + if(str) { + if(l[0] != -1) + sprintf(str, " %.2f %.2f %.2f", l[0], l[1], l[2]); + else + strcpy(str, " (unknown) "); + } + return (int)l[0]; +} + +double swapused(long *total, long *used) { + double percent = -1; + char buf[101]; + FILE *fp; + + if((fp = fopen("/proc/meminfo","r"))) { + while(fgets(buf, 100, fp) && buf[0] != 'S'); + if(sscanf(buf + 6, "%ld %ld", total, used) == 2) + if(*total != 0) + percent = (double)*used / (double)*total; + fclose(fp); + } + return percent; +} + +#elif __FreeBSD__ >=4 + +#include + +int cpuload(char *str) { + double l[3] = {-1, -1, -1}; + if(getloadavg(l, 3) != 3) + l[0] = -1; + + if(str) { + if(l[0] != -1) + sprintf(str, " %.2f %.2f %.2f", l[0], l[1], l[2]); + else + strcpy(str, " (unknown) "); + } + return (int)l[0]; +} + +double swapused(long *total, long *used) { + double percent = -1; + kvm_t *kd; + struct kvm_swap swapinfo; + int pagesize; + + kd = kvm_open(NULL, NULL, NULL, O_RDONLY, NULL); + if(kd) { + if(kvm_getswapinfo(kd, &swapinfo, 1, 0) == 0) { + pagesize = getpagesize(); + *total = swapinfo.ksw_total * pagesize; + *used = swapinfo.ksw_used * pagesize; + if(*total != 0) + percent = (double)*used / (double)*total; + } + kvm_close(kd); + } + return percent; +} +#endif diff --git a/pttbbs/mbbsd/othello.c b/pttbbs/mbbsd/othello.c new file mode 100644 index 00000000..47b8cef3 --- /dev/null +++ b/pttbbs/mbbsd/othello.c @@ -0,0 +1,541 @@ +/* $Id: othello.c,v 1.1 2002/03/07 15:13:48 in2 Exp $ */ +#include +#include +#include +#include +#include "config.h" +#include "pttstruct.h" +#include "common.h" +#include "modes.h" +#include "proto.h" + +extern char *BBSName; + +#define LOGFILE "etc/othello.log" +#define SECRET "etc/othello.secret" +#define NR_TABLE 2 + +#define true 1 +#define false 0 +#define STARTX 3 +#define STARTY 20 +#define NONE_CHESS " " +#define WHITE_CHESS "●" +#define BLACK_CHESS "○" +#define HINT_CHESS "#" +#define NONE 0 +#define HINT 1 +#define BLACK 2 +#define WHITE 3 + +#define INVERT(COLOR) (((COLOR))==WHITE?BLACK:WHITE) + +static char nowx = 3, nowy = 3; +static char *CHESS_TYPE[] = {NONE_CHESS, HINT_CHESS, BLACK_CHESS, WHITE_CHESS}; +static char DIRX[] = {-1,-1,-1, 0, 1, 1, 1, 0}; +static char DIRY[] = {-1, 0, 1, 1, 1, 0,-1,-1}; +static char number[2]; + +static char pass = 0; +static char if_hint = 0; +static int think, which_table; + +static char nowboard[10][10]= +{{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, + {-1, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, -1}, + {-1, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, -1}, + {-1, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, -1}, + {-1, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, -1}, + {-1, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, -1}, + {-1, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, -1}, + {-1, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, -1}, + {-1, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, -1}, + {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1}}; +static char init_table[NR_TABLE+1][5][5] = { + {{ 0, 0, 0, 0, 0}, + { 0,30,-3, 2, 2}, + { 0,-3,-3,-1,-1}, + { 0, 2,-1, 1, 1}, + { 0, 2,-1, 1, 0}}, + + {{ 0, 0, 0, 0, 0}, + { 0,70, 5,20,30}, + { 0, 5,-5, 3, 3}, + { 0,20, 3, 5, 5}, + { 0,30, 3, 5, 5}}, + + {{ 0, 0, 0, 0, 0}, + { 0, 5, 2, 2, 2}, + { 0, 2, 1, 1, 1}, + { 0, 2, 1, 1, 1}, + { 0, 2, 1, 1, 1}} +}; + +static char table[NR_TABLE + 1][10][10]; +static void print_chess(int x, int y, char chess) { + move(STARTX - 1 + x * 2, STARTY - 2 + y * 4); + if(chess != HINT || if_hint == 1) + prints(CHESS_TYPE[(int)chess]); + else + prints(CHESS_TYPE[NONE]); + refresh(); +} + +extern userec_t cuser; + +static void printboard() { + int i; + + move(STARTX, STARTY); + prints("┌─┬─┬─┬─┬─┬─┬─┬─┐"); + for(i = 0; i < 7; i++) { + move(STARTX + 1 + i * 2, STARTY); + prints ("│ │ │ │ │ │ │ │ │"); + move(STARTX + 2 + i * 2, STARTY); + prints ("├─┼─┼─┼─┼─┼─┼─┼─┤"); + } + move(STARTX + 1 + i * 2, STARTY); + prints("│ │ │ │ │ │ │ │ │"); + move(STARTX + 2 + i * 2, STARTY); + prints("└─┴─┴─┴─┴─┴─┴─┴─┘"); + print_chess(4, 4, WHITE); + print_chess(5, 5, WHITE); + print_chess(4, 5, BLACK); + print_chess(5, 4, BLACK); + move(3, 56); + prints("(黑)%s",cuser.userid); + move(3, 72); + prints(": 02"); + move(4, 56); + prints("(白)電腦 : 02"); + move(6, 56); + prints("# 可以下之處"); + move(7, 56); + prints("[q] 退出"); + move(8, 56); + prints("[h] 開啟/關閉 提示"); + move(9,56); + prints("[Enter][Space] 下棋"); + move(10, 56); + prints("上:↑, i"); + move(11, 56); + prints("下:↓, k"); + move(12, 56); + prints("左:←, j"); + move(13, 56); + prints("右:→, l"); +} + +static int get_key(char nowx, char nowy) { + int ch; + + move(STARTX - 1 + nowx * 2, STARTY - 1 + nowy * 4); + ch = igetkey(); + move(STARTX - 1 + nowx * 2, STARTY - 2 + nowy * 4); + if(nowboard[(int)nowx][(int)nowy] != HINT || if_hint==1) + outs(CHESS_TYPE[(int)nowboard[(int)nowx][(int)nowy]]); + else + outs(CHESS_TYPE[NONE]); + return ch; +} + +static int eatline(int i, int j, char color, int dir, char chessboard[][10]) { + int tmpx,tmpy; + char tmpchess; + + tmpx = i + DIRX[dir]; + tmpy = j + DIRY[dir]; + tmpchess = chessboard[tmpx][tmpy]; + if(tmpchess == -1) + return false; + if(tmpchess != INVERT(color)) + return false; + + tmpx += DIRX[dir]; + tmpy += DIRY[dir]; + tmpchess = chessboard[tmpx][tmpy]; + while(tmpchess != -1) { + if(tmpchess < BLACK) + return false; + if(tmpchess == color) { + while(i != tmpx || j != tmpy) { + chessboard[i][j] = color; + i += DIRX[dir]; + j += DIRY[dir]; + } + return true; + } + tmpx += DIRX[dir]; + tmpy += DIRY[dir]; + tmpchess = chessboard[tmpx][tmpy]; + } + return false; +} + +static int if_can_put(int x, int y, char color, char chessboard[][10]) { + int i, temp, checkx, checky; + + if(chessboard[x][y] HINT) + if(chessboard[checkx][checky] == color) + return true; + } + return false; +} + +static int get_hint(char color) { + int i, j, temp = 0; + + for(i = 1; i <= 8; i++) + for(j = 1; j <= 8; j++) { + if(nowboard[i][j] == HINT) + nowboard[i][j] = NONE; + if(if_can_put(i, j, color, nowboard)) { + nowboard[i][j] = HINT; + temp++; + } + print_chess(i, j, nowboard[i][j]); + } + return temp; +} + +static void eat(int x, int y, int color, char chessboard[][10]) { + int k; + + for(k = 0; k < 8; k++) + eatline(x, y, color, k, chessboard); +} + +static void end_of_game(int quit) { + FILE *fp,*fp1; + char *opponent[] = {"","CD-65","","嬰兒","小孩","","大人","專家"}; + + move(STARTX - 1, 30); + prints (" "); + move(22, 35); + fp = fopen(LOGFILE, "a"); + if(!quit) { + fp1 = fopen(SECRET, "a"); + if(fp1) { + fprintf(fp1, "%d,%d,%s,%02d,%02d\n", think, which_table, + cuser.userid, number[0], number[1]); + fclose(fp1); + } + } + + if(quit) { + if(number[0] == 2 && number[1] == 2) { + if(fp) + fclose(fp); + return; + } + fprintf(fp, "在%s級中, %s臨陣脫逃\n", opponent[think], cuser.userid); + if(fp) + fclose(fp); + return; + } + if(number[0] > number[1]) { + prints("你贏了電腦%02d子", number[0] - number[1]); + if(think == 6 && number[0] - number[1] >= 50) + demoney(200); + if(think == 7 && number[0] - number[1] >= 40) + demoney(200); + if(fp) + fprintf(fp, "在%s級中, %s以 %02d:%02d 贏了電腦%02d子\n", + opponent[think], cuser.userid, number[0], number[1], + number[0] - number[1]); + } else if(number[1] > number[0]) { + prints("電腦贏了你%02d子", number[1] - number[0]); + if(fp) { + fprintf(fp, "在%s級中, ", opponent[think]); + if(number[1] - number[0] > 20) + fprintf(fp, "電腦以 %02d:%02d 慘電%s %02d子\n", number[1], + number[0], cuser.userid, number[1] - number[0]); + else + fprintf(fp, "電腦以 %02d:%02d 贏了%s %02d子\n", number[1], + number[0], cuser.userid, number[1] - number[0]); + } + } else { + prints("你和電腦打成平手!!"); + if(fp) + fprintf(fp, "在%s級中, %s和電腦以 %02d:%02d 打成了平手\n", + opponent[think], cuser.userid, number[1], number[0]); + } + if(fp) + fclose(fp); + move(1,1); + igetkey(); +} + +static void othello_redraw() { + int i, j; + + for(i = 1; i <= 8; i++) + for(j = 1; j <= 8; j++) + print_chess(i, j, nowboard[i][j]); +} + +static int player(char color) { + int ch; + + if(get_hint(color)) { + while(true) { + ch = get_key(nowx,nowy); + switch(ch) { + case 'J': + case 'j': + case KEY_LEFT: + nowy--; + break; + case 'L': + case 'l': + case KEY_RIGHT: + nowy++; + break; + case 'I': + case 'i': + case KEY_UP: + nowx--; + break; + case 'K': + case 'k': + case KEY_DOWN: + nowx++; + break; + case ' ': + case '\r': + if(nowboard[(int)nowx][(int)nowy] != HINT) + break; + pass = 0; + nowboard[(int)nowx][(int)nowy] = color; + eat(nowx, nowy, color, nowboard); + print_chess(nowx, nowy, color); + return true; + case 'q': + end_of_game(1); + return false; + case 'H': + case 'h': + if_hint = if_hint^1; + othello_redraw(); + break; + } + if(nowx == 9) + nowx=1; + if(nowx == 0) + nowx=8; + if(nowy == 9) + nowy=1; + if(nowy == 0) + nowy=8; + } + } else { + pass++; + if(pass == 1) { + move(23, 34); + prints("你必需放棄這一步!!"); + igetch(); + move(28,23); + prints(" "); + } else { + end_of_game(0); + return false; + } + } + return 0; +} + +static void init() { + int i, j, i1, j1; + + nowx = 4; + nowy = 4; + number[0] = number[1] = 2; + for(i = 1; i <= 8; i++) + for(j = 1;j <= 8; j++) { + i1 = 4.5 - abs(4.5 - i); + j1 = 4.5 - abs(4.5 - j); + table[0][i][j] = init_table[0][i1][j1]; + table[1][i][j] = init_table[1][i1][j1]; + } + for(i = 1; i <= 8; i++) + for(j = 1; j <= 8; j++) + nowboard[i][j] = NONE; + nowboard[4][4] = nowboard[5][5] = WHITE; + nowboard[4][5] = nowboard[5][4] = BLACK; +} + +static void report() { + int i, j; + + number[0] = number[1] = 0; + for(i = 1; i <= 8; i++) + for(j = 1; j <= 8; j++) + if(nowboard[i][j] == BLACK) + number[0]++; + else if(nowboard[i][j] == WHITE) + number[1]++; + move(3, 60); + prints("%s", cuser.userid); + move(3, 72); + prints(": %02d", number[0]); + move(4, 60); + prints("電腦 : %02d", number[1]); +} + +static int EVL(char chessboard[][10], int color, int table_number) { + int points = 0,a,b; + for(a = 1; a <= 8; a++) + for(b = 1; b <= 8; b++) + if(chessboard[a][b] > HINT) { + if(chessboard[a][b] == BLACK) + points += table[table_number][a][b]; + else + points -= table[table_number][a][b]; + } + return ((color == BLACK) ? points : -points); +} + +static int alphabeta(int alpha, int beta, int level, char chessboard[][10], + int thinkstep, int color, int table) { + int i, j, k, flag = 1; + char tempboard[10][10]; + if(level == thinkstep+1) + return EVL(chessboard, (level & 1 ? color : ((color - 2) ^ 1) + 2), + table); + for(i = 1; i <= 8; i++) { + for(j = 1; j <= 8; j++) { + if(if_can_put(i, j, color, chessboard)) { + flag = 0; + memcpy(tempboard, chessboard, sizeof(char) * 100); + eat(i, j, color, tempboard); + + k = alphabeta(alpha, beta, level + 1, tempboard, thinkstep, + ((color - 2) ^ 1) + 2, table); + if(((level & 1) && k > alpha)) + alpha = k; + else if(!(level & 1) && k < beta) + beta = k; + if(alpha >= beta) + break; + } + } + } + if(flag) + return EVL(chessboard, color, table); + return ((level & 1) ? alpha : beta); +} + +static int Computer(int thinkstep, int table) { + int i, j, maxi = 0, maxj = 0, level = 1; + char chessboard[10][10]; + int alpha = -10000, k; + if((number[0] + number[1]) > 44) + table = NR_TABLE; + for(i = 1; i <= 8; i++) + for(j = 1; j <= 8; j++) { + if(if_can_put(i,j,WHITE,nowboard)) { + memcpy(chessboard, nowboard, sizeof(char) * 100); + eat(i, j, WHITE, chessboard); + k = alphabeta(alpha, 10000, level + 1, chessboard, thinkstep, + BLACK, table); + if(k > alpha) { + alpha = k; + maxi = i; + maxj = j; + } + } + } + if(alpha != -10000) { + eat(maxi, maxj, WHITE, nowboard); + pass = 0; + nowx = maxi; + nowy = maxj; + } else { + move(23, 30); + prints("電腦放棄這一步棋!!"); + pass++; + if(pass == 2) { + move(23, 24); + prints(" "); + end_of_game(0); + return false; + } + igetch(); + move(23, 24); + prints(" "); + } + return true; +} + +static int choose() { + char thinkstep[2]; + + move(2, 0); + prints("請選擇難度:"); + move(5, 0); + prints("(1) CD-65\n"); /* 想 1 步 */ + prints("(2) 嬰兒\n"); /* 想 3 步 */ + prints("(3) 小孩\n"); /* 想 4 步 */ + do { + getdata(4, 0, "請選擇一個對象和您對打:(1~5)", thinkstep, 2, LCECHO); + } while(thinkstep[0] < '1' || thinkstep[0] > '3'); + clear(); + switch(thinkstep[0]) { + case '2': + thinkstep[0] = '3'; + break; + case '3': + thinkstep[0] = '4'; + break; + default: + thinkstep[0] = '1'; + break; + } + return atoi(thinkstep); +} + +#define lockreturn0(unmode, state) if(lockutmpmode(unmode, state)) return 0 + +int othello_main() { + lockreturn0(OTHELLO, LOCK_MULTI); + clear(); + init(); + think = choose(); + showtitle("黑白棋", BBSName); + printboard(); + which_table = rand() % NR_TABLE; + while(true) { + move(STARTX - 1, 30); + prints("輪到你下了..."); + if(!player(BLACK)) + break; + report(); + othello_redraw(); + if(number[0] + number[1] == 64) { + end_of_game(0); + break; + } + move(STARTX - 1, 30); + prints("電腦思考中..."); + refresh(); + if(!Computer(think, which_table)) + break; + report(); + othello_redraw(); + if(number[0] + number[1] == 64) { + end_of_game(0); + break; + } + } + more(LOGFILE, YEA); + unlockutmpmode(); + return 1; +} diff --git a/pttbbs/mbbsd/page.c b/pttbbs/mbbsd/page.c new file mode 100644 index 00000000..c77ef421 --- /dev/null +++ b/pttbbs/mbbsd/page.c @@ -0,0 +1,130 @@ +/* $Id: page.c,v 1.1 2002/03/07 15:13:48 in2 Exp $ */ +#include +#include +#include +#include +#include +#include "config.h" +#include "pttstruct.h" +#include "modes.h" +#include "common.h" +#include "proto.h" + +#define hpressanykey(a) {move(22, 0); prints(a); pressanykey();} +static void filt_railway(char* fpath) { + char buf[256], tmppath[32]; + FILE* fp = fopen(fpath, "w"), *tp; + + sprintf(tmppath, "%s.railway", fpath); + if(!fp || !(tp = fopen(tmppath, "r"))) + return; + + while(fgets(buf, 255, tp)) { + if(strstr(buf, "INLINE")) + continue; + if(strstr(buf, "LINK")) + break; + fprintf(fp, "%s", buf); + } + fclose(fp); + fclose(tp); + unlink(tmppath); +} + +extern userec_t cuser; + +int main_railway() { + fileheader_t mhdr; + char genbuf[200]; + int from, to, time_go, time_reach; + char tt[2], type[2]; + char command[256], buf[8]; + char *addr[]= { + "基隆", "八堵", "七堵", "五堵", "汐止", "南港", "松山", "台北", "萬華", + "板橋", "樹林", "山佳", "鶯歌", "桃園", "內壢", "中壢", "埔心", "楊梅", + "湖口", "新豐", "竹北", "新竹", "香山", "崎頂", "竹南", "造橋", "豐富", + "談文", "大山", "後龍", "龍港", "白沙屯", "新埔", "通霄", "苑裡", + "日南", "大甲", "臺中港", "清水", "沙鹿", "龍井", "大肚", "追分", + "苗栗", "南勢", "銅鑼", "三義", "勝興", "泰安", "后里", "豐原", "潭子", + "台中", "烏日", "成功\", "彰化", "花壇", "員林", "永靖", "社頭", + "田中", "二水", "林內", "石榴", "斗六", "斗南", "石龜", "大林", + "民雄", "嘉義", "水上", "南靖", "後壁", "新營", "柳營", "林鳳營", + "隆田", "拔林", "善化", "新市", "永康", "台南", "保安", "中洲", + "大湖", "路竹", "岡山", "橋頭", "楠梓", "左營", "高雄", "鳳山", + "九曲堂", "屏東", NULL, NULL + }; + + setutmpmode(RAIL_WAY); + clear(); + move(0,25); + prints("\033[1;37;45m 火車查詢系統 \033[1;44;33m作者:Heat\033[m"); + move(1,0); + outs("\033[1;33m + 1.基隆 16.中壢 31.龍港 46.銅鑼 61.田中 76.林鳳營 91.高雄 + 2.八堵 17.埔心 32.白沙屯 47.三義 62.二水 77.隆田 92.鳳山 + 3.七堵 18.楊梅 33.新埔 48.勝興 63.林內 78.拔林 93.九曲堂 + 4.五堵 19.湖口 34.通霄 49.泰安 64.石榴 79.善化 94.屏東 + 5.汐止 20.新豐 35.苑裡 50.后里 65.斗六 80.新市 + 6.南港 21.竹北 36.日南 51.豐原 66.斗南 81.永康 + 7.松山 22.新竹 37.大甲 52.潭子 67.石龜 82.台南 + 8.台北 23.香山 38.臺中港 53.台中 68.大林 83.保安 + 9.萬華 24.崎頂 39.清水 54.烏日 69.民雄 84.中洲 +10.板橋 25.竹南 40.沙鹿 55.成功\ 70.嘉義 85.大湖 +11.樹林 26.造橋 41.龍井 56.彰化 71.水上 86.路竹 +12.山佳 27.豐富 42.大肚 57.花壇 72.南靖 87.岡山 +13.鶯歌 28.談文 43.追分 58.員林 73.後壁 88.橋頭 +14.桃園 29.大山 44.苗栗 59.永靖 74.新營 89.楠梓 +15.內壢 30.後龍 45.南勢 60.社頭 75.柳營 90.左營\033[m"); + + getdata(17, 0, "\033[1;35m你確定要搜尋嗎?[y/n]:\033[m", buf, 2, LCECHO); + if(buf[0] != 'y' && buf[0] != 'Y') + return 0; + while(1) + if(getdata(18, 0, "\033[1;35m請輸入起站(1-94):\033[m", buf, 3, LCECHO) && + (from = atoi(buf)) >= 1 && from <= 94) + break; + while(1) + if(getdata(18, 40, "\033[1;35m請輸入目的地(1-94):\033[m", + buf, 3, LCECHO) && + (to = atoi(buf)) >= 1 && to <= 94) + break; + while(1) + if(getdata(19, 0, "\033[1;35m請輸入時間區段(0-23) 由:\033[m", + buf,3,LCECHO) && + (time_go = atoi(buf)) >= 0 && time_go <= 23) + break; + while(1) + if(getdata(19, 40, "\033[1;35m到:\033[m", buf, 3, LCECHO) && + (time_reach=atoi(buf)) >= 0 && time_reach <= 23) + break; + while(1) + if(getdata(20, 0, "\033[1;35m想查詢 1:對號快車 2:普通平快\033[m", + type,2,LCECHO) && (type[0] == '1' || type[0] == '2')) + break; + while(1) + if(getdata(21, 0, "\033[1;35m欲查詢 1:出發時間 2:到達時間\033[m", + tt, 2, LCECHO) && + (tt[0]=='1' || tt[0]=='2')) + break; + sethomepath(genbuf, cuser.userid); + stampfile(genbuf, &mhdr); + strcpy(mhdr.owner, "Ptt搜尋器"); + strncpy(mhdr.title, "火車時刻搜尋結果", TTLEN); + mhdr.savemode = '\0'; + + sprintf(command,"echo \"from-station=%s&to-station=%s" + "&from-time=%02d00&to-time=%02d00&tt=%s&type=%s\" | " + "lynx -dump -post_data " + "\"http://www.railway.gov.tw/cgi-bin/timetk.cgi\" > %s.railway", + addr[from - 1], addr[to - 1], time_go, time_reach, + (tt[0] == '1') ? "start" : "arriv", + (type[0] == '1') ? "fast" : "slow", genbuf); + + system(command); + filt_railway(genbuf); + sethomedir(genbuf, cuser.userid); + if(append_record(genbuf, &mhdr, sizeof(mhdr)) == -1) + return -1; + hpressanykey("\033[1;31m我們會把搜尋結果很快就寄給你唷 ^_^\033[m"); + return 0; +} diff --git a/pttbbs/mbbsd/passwd.c b/pttbbs/mbbsd/passwd.c new file mode 100644 index 00000000..28a31119 --- /dev/null +++ b/pttbbs/mbbsd/passwd.c @@ -0,0 +1,138 @@ +/* $Id: passwd.c,v 1.1 2002/03/07 15:13:48 in2 Exp $ */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "config.h" +#include "pttstruct.h" +#include "modes.h" +#include "proto.h" + +extern char *fn_passwd; + +static userec_t *passwd_image = NULL; +static int passwd_image_size; +static int semid = -1; + +#ifndef SEM_R +#define SEM_R 0400 +#endif + +#ifndef SEM_A +#define SEM_A 0200 +#endif + +#ifndef __FreeBSD__ +union semun { + int val; /* value for SETVAL */ + struct semid_ds *buf; /* buffer for IPC_STAT & IPC_SET */ + u_short *array; /* array for GETALL & SETALL */ + struct seminfo *__buf; /* buffer for IPC_INFO */ +}; +#endif + +int passwd_mmap() { + int fd; + + fd = open(fn_passwd, O_RDWR); + if(fd > 0) + { + struct stat st; + + fstat(fd, &st); + passwd_image_size = st.st_size; + passwd_image = mmap(NULL, passwd_image_size, + PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); + if(passwd_image == (userec_t *)-1) { + perror("mmap"); + return -1; + } +/* rocker 011018: after success get mmap, close file descript */ + close (fd); + + semid = semget(PASSWDSEM_KEY, 1, SEM_R | SEM_A | IPC_CREAT | IPC_EXCL); + if(semid == -1) { + if(errno == EEXIST) { + semid = semget(PASSWDSEM_KEY, 1, SEM_R | SEM_A); + if(semid == -1) { + perror("semget"); + exit(1); + } + } else { + perror("semget"); + exit(1); + } + } else { + union semun s; + + s.val = 1; + if(semctl(semid, 0, SETVAL, s) == -1) { + perror("semctl"); + exit(1); + } + } + } else { + perror(fn_passwd); + return -1; + } + return 0; +} + +extern int usernum; +int passwd_update_money(int num) { + int money; + if(num < 1 || num > MAX_USERS) + return -1; + money = moneyof(num); + memcpy(&passwd_image[num - 1].money, &money, sizeof(int)); + return 0; +} + +int passwd_update(int num, userec_t *buf) { + if(num < 1 || num > MAX_USERS) + return -1; + buf->money = moneyof(num); + memcpy(&passwd_image[num - 1], buf, sizeof(userec_t)); + return 0; +} + +int passwd_query(int num, userec_t *buf) { + if(num < 1 || num > MAX_USERS) + return -1; + memcpy(buf, &passwd_image[num - 1], sizeof(userec_t)); + return 0; +} + +int passwd_apply(int (*fptr)(userec_t *)) { + int i; + + for(i = 0; i < MAX_USERS; i++) + if((*fptr)(&passwd_image[i]) == QUIT) + return QUIT; + return 0; +} + +void passwd_lock() { + struct sembuf buf = { 0, -1, SEM_UNDO }; + + if(semop(semid, &buf, 1)) { + perror("semop"); + exit(1); + } +} + +void passwd_unlock() { + struct sembuf buf = { 0, 1, SEM_UNDO }; + + if(semop(semid, &buf, 1)) { + perror("semop"); + exit(1); + } +} diff --git a/pttbbs/mbbsd/read.c b/pttbbs/mbbsd/read.c new file mode 100644 index 00000000..b92f95e7 --- /dev/null +++ b/pttbbs/mbbsd/read.c @@ -0,0 +1,998 @@ +/* $Id: read.c,v 1.1 2002/03/07 15:13:48 in2 Exp $ */ +#include +#include +#include +#include +#include +#include +#include +#include +#include "config.h" +#include "pttstruct.h" +#include "modes.h" +#include "common.h" +#include "perm.h" +#include "proto.h" + +#define MAXPATHLEN 256 + +extern int p_lines; /* a Page of Screen line numbers: tlines-4 */ +extern int b_lines; /* Screen bottom line number: t_lines-1 */ +extern char currowner[IDLEN + 2]; +extern char currtitle[44]; +extern char currauthor[IDLEN + 2]; +extern char *str_reply; +extern char *msg_fwd_ok; +extern char *msg_fwd_err1; +extern char *msg_fwd_err2; +extern int currmode; +extern unsigned int currstat; +extern char currboard[]; /* name of currently selected board */ +extern int KEY_ESC_arg; +extern int curredit; +extern char *msg_mailer; +extern int currbid; +extern bcache_t *brdshm; + +char currdirect[64]; +static fileheader_t *headers = NULL; +static int last_line; +static int hit_thread; + +/* rocker.011018: add new tag */ + +extern int rget(); +extern char getans(); +extern void touchdircache(); +extern int get_fileheader_cache(); + +/* rocker.011018: 新的tag方式 */ + +#define MAXTAGS 256 + +#include + +typedef struct +{ + time_t chrono; + int recno; +} TagItem; + + +/* ----------------------------------------------------- */ +/* Tag List 標籤 */ +/* ----------------------------------------------------- */ + + +int TagNum; /* tag's number */ +TagItem TagList[MAXTAGS]; /* ascending list */ + +void +UnTagger (int locus) +{ + if (locus > TagNum) return; + + TagNum--; + + if (TagNum > locus) + memcpy(&TagList[locus], &TagList[locus + 1], + (TagNum - locus) * sizeof(TagItem)); +} + +int +Tagger(time_t chrono, int recno, int mode) +{ + int head, tail, posi = 0, comp; + + for (head = 0, tail = TagNum - 1, comp = 1; head <= tail;) + { + posi = (head + tail) >> 1; + comp = TagList[posi].chrono - chrono; + if (!comp) + { + break; + } + else if (comp < 0) + { + head = posi + 1; + } + else + { + tail = posi - 1; + } + } + + if (mode == TAG_NIN) + { + if (!comp && recno) /* 絕對嚴謹:連 recno 一起比對 */ + comp = recno - TagList[posi].recno; + return comp; + + } + + if (!comp) + { + if (mode != TAG_TOGGLE) + return NA; + + TagNum--; + memcpy(&TagList[posi], &TagList[posi + 1], + (TagNum - posi) * sizeof(TagItem)); + } + else if (TagNum < MAXTAGS) + { + TagItem *tagp, buf[MAXTAGS]; + + tail = (TagNum - head) * sizeof(TagItem); + tagp = &TagList[head]; + memcpy(buf, tagp, tail); + tagp->chrono = chrono; + tagp->recno = recno; + memcpy(++tagp, buf, tail); + TagNum++; + } + else + { + bell(); + return 0; /* full */ + } + return YEA; +} + + +void +EnumTagName( char *fname, int locus) +{ + sprintf(fname, "M.%d.A", (int) TagList[locus].chrono); +} + +void +EnumTagFhdr(fileheader_t *fhdr, char *direct, int locus) +{ + get_record(direct, fhdr, sizeof(fileheader_t), TagList[locus].recno); +} + +/* -1 : 取消 */ +/* 0 : single article */ +/* ow: whole tag list */ + +int +AskTag(char *msg) +{ + char buf[80]; + int num; + + num = TagNum; + sprintf(buf, "◆ %s A)文章 T)標記 Q)uit?", msg); + switch (rget(b_lines-1, buf)) + { + case 'q': + num = -1; + break; + case 'a': + num = 0; + } + return num; +} + + +#include + +#define BATCH_SIZE 65536 + +char * +f_map (char *fpath, int *fsize) +{ + int fd, size; + struct stat st; + + if ((fd = open(fpath, O_RDONLY)) < 0) + return (char *) -1; + + if (fstat(fd, &st) || !S_ISREG(st.st_mode) || (size = st.st_size) <= 0) + { + close(fd); + return (char *) -1; + } + + fpath = (char *) mmap(NULL, size, PROT_READ, MAP_SHARED, fd, 0); + close(fd); + *fsize = size; + return fpath; +} + + +static int +TagThread(char *direct) +{ + int fsize, count; + char *title, *fimage; + fileheader_t *head, *tail; + + fimage = f_map(direct, &fsize); + if ( fimage == (char *) -1) + return DONOTHING; + + head = (fileheader_t *) fimage; + tail = (fileheader_t *) (fimage + fsize); + count = 0; + do + { + count++; + title = subject(head->title); + if (!strncmp( currtitle, title,TTLEN)) + { + if (!Tagger(atoi (head->filename + 2), count, TAG_INSERT)) + break; + } + } while (++head < tail); + + munmap(fimage, fsize); + return FULLUPDATE; +} + + +int +TagPruner(int bid) +{ + if (TagNum && ((currstat != READING) || (currmode & MODE_BOARD))) + { + if(getans("刪除所有標記[N]?") != 'y') + return FULLUPDATE; + delete_range(currdirect, 0, 0); + TagNum = 0; + if(bid>0); + setbtotal(bid); + return NEWDIRECT; + } + return DONOTHING; +} + + +/* ----------------------------------------------------- */ +/* cursor & reading record position control */ +/* ----------------------------------------------------- */ +keeploc_t *getkeep(char *s, int def_topline, int def_cursline) { + static struct keeploc_t *keeplist = NULL; + struct keeploc_t *p; + void *malloc(); + + if(def_cursline >= 0) + for(p = keeplist; p; p = p->next) { + if(!strcmp(s, p->key)) { + if(p->crs_ln < 1) + p->crs_ln = 1; + return p; + } + } + else + def_cursline = -def_cursline; + p = (keeploc_t *)malloc(sizeof(keeploc_t)); + p->key = (char *)malloc(strlen(s) + 1); + strcpy(p->key, s); + p->top_ln = def_topline; + p->crs_ln = def_cursline; + p->next = keeplist; + return (keeplist = p); +} + +void fixkeep(char *s, int first) { + keeploc_t *k; + + k = getkeep(s, 1, 1); + if(k->crs_ln >= first) { + k->crs_ln = (first == 1 ? 1 : first - 1); + k->top_ln = (first < 11 ? 1 : first - 10); + } +} + +/* calc cursor pos and show cursor correctly */ +static int cursor_pos(keeploc_t *locmem, int val, int from_top) { + int top; + + if(val > last_line) { + bell(); + val = last_line; + } + if(val <= 0) { + bell(); + val = 1; + } + + top = locmem->top_ln; + if(val >= top && val < top + p_lines) { + cursor_clear(3 + locmem->crs_ln - top, 0); + locmem->crs_ln = val; + cursor_show(3 + val - top, 0); + return DONOTHING; + } + locmem->top_ln = val - from_top; + if(locmem->top_ln <= 0) + locmem->top_ln = 1; + locmem->crs_ln = val; + return PARTUPDATE; +} + +static int move_cursor_line(keeploc_t *locmem, int mode) { + int top, crs; + int reload = 0; + + top = locmem->top_ln; + crs = locmem->crs_ln; + if(mode == READ_PREV) { + if(crs <= top) { + top -= p_lines - 1; + if(top < 1) + top = 1; + reload = 1; + } + if(--crs < 1) { + crs = 1; + reload = -1; + } + } else if(mode == READ_NEXT) { + if(crs >= top + p_lines - 1) { + top += p_lines - 1; + reload = 1; + } + if(++crs > last_line) { + crs = last_line; + reload = -1; + } + } + locmem->top_ln = top; + locmem->crs_ln = crs; + return reload; +} + +static int thread(keeploc_t *locmem, int stype) { + static char a_ans[32], t_ans[32]; + char ans[32], s_pmt[64]; + register char *tag, *query = NULL; + register int now, pos, match, near = 0; + fileheader_t fh; + int circulate_flag = 1; /* circulate at end or begin */ + + match = hit_thread = 0; + now = pos = locmem->crs_ln; + if(stype == 'A') { + if(!*currowner) + return DONOTHING; + str_lower(a_ans, currowner); + query = a_ans; + circulate_flag = 0; + stype = 0; + } else if(stype == 'a') { + if(!*currowner) + return DONOTHING; + str_lower(a_ans, currowner); + query = a_ans; + circulate_flag = 0; + stype = RS_FORWARD; + } else if(stype == '/') { + if(!*t_ans) + return DONOTHING; + query = t_ans; + circulate_flag = 0; + stype = RS_TITLE | RS_FORWARD; + } else if(stype == '?') { + if(!*t_ans) + return DONOTHING; + circulate_flag = 0; + query = t_ans; + stype = RS_TITLE; + } else if(stype & RS_RELATED) { + tag = headers[pos - locmem->top_ln].title; + if(stype & RS_CURRENT) { + if(stype & RS_FIRST) { + if(!strncmp(currtitle, tag, 40)) + return DONOTHING; + near = 0; + } + query = currtitle; + } else { + query = subject(tag); + if(stype & RS_FIRST) { + if(query == tag) + return DONOTHING; + near = 0; + } + } + } else if(!(stype & RS_THREAD)) { + query = (stype & RS_TITLE) ? t_ans : a_ans; + if(!*query && query == a_ans) { + if(*currowner) + strcpy(a_ans, currowner); + else if (*currauthor) + strcpy(a_ans, currauthor); + } + sprintf(s_pmt, "%s搜尋%s [%s] ",(stype & RS_FORWARD) ? "往後":"往前", + (stype & RS_TITLE) ? "標題" : "作者", query); + getdata(b_lines - 1, 0, s_pmt, ans, 30, DOECHO); + if(*ans) + strcpy(query, ans); + else if(*query == '\0') + return DONOTHING; + } + + tag = fh.owner; + + do { + if(!circulate_flag || stype & RS_RELATED) { + if(stype & RS_FORWARD) { + if(++now > last_line) + return DONOTHING; + } else { + if(--now <= 0) { + if((stype & RS_FIRST) && (near)) { + hit_thread = 1; + return cursor_pos(locmem, near, 10); + } + return DONOTHING; + } + } + } else { + if(stype & RS_FORWARD) { + if(++now > last_line) + now = 1; + } else if(--now <= 0) + now = last_line; + } + + get_record(currdirect, &fh, sizeof(fileheader_t), now); + + if(fh.owner[0] == '-') + continue; + + if(stype & RS_THREAD) { + if(strncasecmp(fh.title, str_reply, 3)) { + hit_thread = 1; + return cursor_pos(locmem, now, 10); + } + continue; + } + + if(stype & RS_TITLE) + tag = subject(fh.title); + + if(((stype & RS_RELATED) && !strncmp(tag, query, 40)) || + (!(stype & RS_RELATED) && ((query == currowner) ? + !strcmp(tag, query) : + strstr_lower(tag, query)))) { + if((stype & RS_FIRST) && tag != fh.title) { + near = now; + continue; + } + + hit_thread = 1; + match = cursor_pos(locmem, now, 10); + if((!(stype & RS_CURRENT)) && + (stype & RS_RELATED) && + strncmp(currtitle, query, 40)) { + strncpy(currtitle, query, 40); + match = PARTUPDATE; + } + break; + } + } while(now != pos); + + return match; +} + + +#ifdef INTERNET_EMAIL +static void mail_forward(fileheader_t *fhdr, char *direct, int mode) { + int i; + char buf[STRLEN]; + char *p; + + strncpy(buf, direct, sizeof(buf)); + if((p = strrchr(buf, '/'))) + *p = '\0'; + switch(i = doforward(buf, fhdr, mode)) { + case 0: + outmsg(msg_fwd_ok); + break; + case -1: + outmsg(msg_fwd_err1); + break; + case -2: + outmsg(msg_fwd_err2); + break; + default: + break; + } + refresh(); + sleep(1); +} +#endif + +extern userec_t cuser; + +static int select_read(keeploc_t *locmem, int sr_mode) { + register char *tag,*query,*temp; + fileheader_t fh; + char fpath[80], genbuf[MAXPATHLEN], buf3[5]; + char static t_ans[TTLEN+1]=""; + char static a_ans[IDLEN+1]=""; + int fd, fr, size = sizeof(fileheader_t); + struct stat st; +/* rocker.011018: make a reference number for process article */ + int reference = 0; + + if((currmode & MODE_SELECT)) + return -1; + if(sr_mode == RS_TITLE) + query = subject(headers[locmem->crs_ln - locmem->top_ln].title); + else if(sr_mode == RS_NEWPOST) + { + strcpy(buf3, "Re: "); + query = buf3; + } + else + { + char buff[80]; + + query = (sr_mode == RS_RELATED) ? t_ans : a_ans; + sprintf(buff, "搜尋%s [%s] ", + (sr_mode == RS_RELATED) ? "標題" : "作者", query); + getdata(b_lines, 0,buff, query, 30, DOECHO); + if(!(*query)) + return DONOTHING; + } + + if((fd = open(currdirect, O_RDONLY, 0)) != -1) { + sprintf(genbuf,"SR.%s",cuser.userid); + if(currstat==RMAIL) + sethomefile(fpath,cuser.userid,genbuf); + else + setbfile(fpath,currboard,genbuf); + if(((fr = open(fpath,O_WRONLY | O_CREAT | O_TRUNC,0600)) != -1)) { + switch(sr_mode) { + case RS_TITLE: + while(read(fd,&fh,size) == size) { + ++reference; + tag = subject(fh.title); + if(!strncmp(tag, query, 40)) + { + fh.money = reference | FHR_REFERENCE; + write(fr,&fh,size); + } + } + break; + case RS_RELATED: + while(read(fd,&fh,size) == size) { + ++reference; + tag = fh.title; + if(strcasestr(tag,query)) + { + fh.money = reference | FHR_REFERENCE; + write(fr,&fh,size); + } + } + break; + case RS_NEWPOST: + while(read(fd, &fh, size) == size) { + ++reference; + tag = fh.title; + temp = strstr(tag, query); + if(temp == NULL || temp != tag) + { + write(fr, &fh, size); + fh.money = reference | FHR_REFERENCE; + } + } + case RS_AUTHOR: + while(read(fd,&fh,size) == size) { + ++reference; + tag = fh.owner; + if(strcasestr(tag,query)) + { + write(fr,&fh,size); + fh.money = reference | FHR_REFERENCE; + } + } + break; + } + fstat(fr,&st); + close(fr); + } + close(fd); + if(st.st_size) { + currmode |= MODE_SELECT; + strcpy(currdirect,fpath); + } + } + return st.st_size; +} + +extern userec_t xuser; + +static int i_read_key(onekey_t *rcmdlist, keeploc_t *locmem, int ch, int bid) { + int i, mode = DONOTHING; + + switch(ch) { + case 'q': + case 'e': + case KEY_LEFT: + return (currmode & MODE_SELECT) ? board_select() : + (currmode & MODE_ETC) ? board_etc() : + (currmode & MODE_DIGEST) ? board_digest() : DOQUIT; + case Ctrl('L'): + redoscr(); + break; +/* + case Ctrl('C'): + cal(); + return FULLUPDATE; + break; +*/ + case KEY_ESC: + if(KEY_ESC_arg == 'i') { + t_idle(); + return FULLUPDATE; + } + break; + case Ctrl('H'): + if(select_read(locmem, RS_NEWPOST)) + return NEWDIRECT; + else + return READ_REDRAW; + case 'a': + case 'A': + if(select_read(locmem,RS_AUTHOR)) + return NEWDIRECT; + else + return READ_REDRAW; + case '/': + case '?': + if(select_read(locmem,RS_RELATED)) + return NEWDIRECT; + else + return READ_REDRAW; + case 'S': + if(select_read(locmem,RS_TITLE)) + return NEWDIRECT; + else + return READ_REDRAW; + /* quick search title first */ + case '=': + return thread(locmem, RELATE_FIRST); + case '\\': + return thread(locmem, CURSOR_FIRST); + /* quick search title forword */ + case ']': + return thread(locmem, RELATE_NEXT); + case '+': + return thread(locmem, CURSOR_NEXT); + /* quick search title backword */ + case '[': + return thread(locmem, RELATE_PREV); + case '-': + return thread(locmem, CURSOR_PREV); + case '<': + case ',': + return thread(locmem, THREAD_PREV); + case '.': + case '>': + return thread(locmem, THREAD_NEXT); + case 'p': + case 'k': + case KEY_UP: + return cursor_pos(locmem, locmem->crs_ln - 1, p_lines - 2); + case 'n': + case 'j': + case KEY_DOWN: + return cursor_pos(locmem, locmem->crs_ln + 1, 1); + case ' ': + case KEY_PGDN: + case 'N': + case Ctrl('F'): + if(last_line >= locmem->top_ln + p_lines) { + if(last_line > locmem->top_ln + p_lines) + locmem->top_ln += p_lines; + else + locmem->top_ln += p_lines - 1; + locmem->crs_ln = locmem->top_ln; + return PARTUPDATE; + } + cursor_clear(3 + locmem->crs_ln - locmem->top_ln, 0); + locmem->crs_ln = last_line; + cursor_show(3 + locmem->crs_ln - locmem->top_ln, 0); + break; + case KEY_PGUP: + case Ctrl('B'): + case 'P': + if(locmem->top_ln > 1) { + locmem->top_ln -= p_lines; + if(locmem->top_ln <= 0) + locmem->top_ln = 1; + locmem->crs_ln = locmem->top_ln; + return PARTUPDATE; + } + break; + case KEY_END: + case '$': + if(last_line >= locmem->top_ln + p_lines) { + locmem->top_ln = last_line - p_lines + 1; + if(locmem->top_ln <= 0) + locmem->top_ln = 1; + locmem->crs_ln = last_line; + return PARTUPDATE; + } + cursor_clear(3 + locmem->crs_ln - locmem->top_ln, 0); + locmem->crs_ln = last_line; + cursor_show(3 + locmem->crs_ln - locmem->top_ln, 0); + break; + case 'F': + case 'U': + if(HAS_PERM(PERM_FORWARD)) { + mail_forward(&headers[locmem->crs_ln - locmem->top_ln], + currdirect, ch /*== 'U'*/); + /*by CharlieL*/ + return FULLUPDATE; + } + break; + case Ctrl('Q'): + return my_query(headers[locmem->crs_ln - locmem->top_ln].owner); + case Ctrl('S'): + if(HAS_PERM(PERM_ACCOUNTS)) { + int id; + userec_t muser; + + strcpy(currauthor, headers[locmem->crs_ln - locmem->top_ln].owner); + stand_title("使用者設定"); + move(1, 0); + if((id = getuser(headers[locmem->crs_ln - locmem->top_ln].owner))){ + memcpy(&muser, &xuser, sizeof(muser)); + user_display(&muser, 1); + uinfo_query(&muser, 1, id); + } + return FULLUPDATE; + } + break; + +/* rocker.011018: 採用新的tag模式 */ + case 't': +/* rocker.011112: 解決再select mode標記文章的問題 */ + if (Tagger(atoi(headers[locmem->crs_ln - locmem->top_ln].filename + 2), + (currmode & MODE_SELECT) ? + (headers[locmem->crs_ln - locmem->top_ln].money & ~FHR_REFERENCE) : + locmem->crs_ln, TAG_TOGGLE)) + return POS_NEXT; + return DONOTHING; + + case Ctrl('C'): + if (TagNum) + { + TagNum = 0; + return FULLUPDATE; + } + return DONOTHING; + + case Ctrl('T'): + return TagThread(currdirect); + case Ctrl('D'): + return TagPruner(bid); + case '\n': + case '\r': + case 'l': + case KEY_RIGHT: + ch = 'r'; + default: + for(i = 0; rcmdlist[i].fptr; i++) { + if(rcmdlist[i].key == ch) { + mode = (*(rcmdlist[i].fptr))(locmem->crs_ln, + &headers[locmem->crs_ln - + locmem->top_ln], currdirect); + break; + } + if(rcmdlist[i].key == 'h') + if(currmode & (MODE_ETC | MODE_DIGEST)) + return DONOTHING; + } + } + return mode; +} + +void i_read(int cmdmode, char *direct, void (*dotitle)(), void (*doentry)(), onekey_t *rcmdlist, int bidcache) { + keeploc_t *locmem = NULL; + int recbase = 0, mode, ch; + int num = 0, entries = 0; + int i; + int jump = 0; + char genbuf[4]; + char currdirect0[64]; + int last_line0 = last_line; + int hit_thread0 = hit_thread; + fileheader_t *headers0 = headers; + + strcpy(currdirect0 ,currdirect); +#define FHSZ sizeof(fileheader_t) +// Ptt:這邊headers 可以針對看板的最後60篇做cache + headers = (fileheader_t *)calloc(p_lines, FHSZ); + strcpy(currdirect, direct); + mode = NEWDIRECT; + +/* rocker.011018: 加入新的tag機制 */ + TagNum = 0; + + do { + /* 依據 mode 顯示 fileheader */ + setutmpmode(cmdmode); + switch(mode) { + case NEWDIRECT: /* 第一次載入此目錄 */ + case DIRCHANGED: + if(bidcache>0 && !(currmode & (MODE_SELECT| MODE_DIGEST)) ) + last_line=getbtotal(currbid); + else + last_line= get_num_records(currdirect, FHSZ); + + if(mode == NEWDIRECT) { + if(last_line == 0) { + if(curredit & EDIT_ITEM) { + outs("沒有物品"); + refresh(); + goto return_i_read; + } else if(curredit & EDIT_MAIL) { + outs("沒有來信"); + refresh(); + goto return_i_read; + } else if(currmode & MODE_ETC) { + board_etc(); /* Kaede */ + outmsg("尚未收錄其它文章"); + refresh(); + } else if(currmode & MODE_DIGEST) { + board_digest(); /* Kaede */ + outmsg("尚未收錄文摘"); + refresh(); + } else if(currmode & MODE_SELECT) { + board_select(); /* Leeym */ + outmsg("沒有此系列的文章"); + refresh(); + } else { + getdata(b_lines - 1, 0, + "看板新成立 (P)發表文章 (Q)離開?[Q] ", + genbuf, 4, LCECHO); + if(genbuf[0] == 'p') + do_post(); + goto return_i_read; + } + } + num = last_line - p_lines + 1; + locmem = getkeep(currdirect, num < 1 ? 1 : num, last_line); + } + recbase = -1; + + case FULLUPDATE: + (*dotitle)(); + + case PARTUPDATE: + if(last_line < locmem->top_ln + p_lines) { + if(bidcache>0 && !(currmode & (MODE_SELECT| MODE_DIGEST))) + num=getbtotal(currbid); + else + num = get_num_records(currdirect, FHSZ); + + if(last_line != num) { + last_line = num; + recbase = -1; + } + } + + if(last_line == 0) + goto return_i_read; + else if(recbase != locmem->top_ln) { + recbase = locmem->top_ln; + if(recbase > last_line) { + recbase = (last_line - p_lines) >> 1; + if(recbase < 1) + recbase = 1; + locmem->top_ln = recbase; + } + if(bidcache>0 && !(currmode & (MODE_SELECT| MODE_DIGEST)) + && (last_line - recbase) < DIRCACHESIZE ) + entries = get_fileheader_cache(currbid, currdirect, headers, + recbase, p_lines); + else + entries = get_records(currdirect, headers, FHSZ, recbase, + p_lines); + } + if(locmem->crs_ln > last_line) + locmem->crs_ln = last_line; + move(3, 0); + clrtobot(); + case PART_REDRAW: + move(3, 0); + for (i = 0; i < entries; i++) + (*doentry) (locmem->top_ln + i, &headers[i]); + case READ_REDRAW: + outmsg(curredit & EDIT_ITEM ? + "\033[44m 私人收藏 \033[30;47m 繼續? \033[m" : + curredit & EDIT_MAIL ? msg_mailer : MSG_POSTER); + break; + case READ_PREV: + case READ_NEXT: + case RELATE_PREV: + case RELATE_NEXT: + case RELATE_FIRST: + case POS_NEXT: + case 'A': + case 'a': + case '/': + case '?': + jump = 1; + break; + } + + /* 讀取鍵盤,加以處理,設定 mode */ + if(!jump) { + cursor_show(3 + locmem->crs_ln - locmem->top_ln, 0); + ch = egetch(); + mode = DONOTHING; + } else + ch = ' '; + + if(mode == POS_NEXT) { + mode = cursor_pos(locmem, locmem->crs_ln + 1, 1); + if(mode == DONOTHING) + mode = PART_REDRAW; + jump = 0; + } else if(ch >= '0' && ch <= '9') { + if((i = search_num(ch, last_line)) != -1) + mode = cursor_pos(locmem, i + 1, 10); + } else { + if(!jump) + mode = i_read_key(rcmdlist, locmem, ch, currbid); + while(mode == READ_NEXT || mode == READ_PREV || + mode == RELATE_FIRST || mode == RELATE_NEXT || + mode == RELATE_PREV || mode == THREAD_NEXT || + mode == THREAD_PREV || mode == 'A' || mode == 'a' || + mode == '/' || mode == '?') { + int reload; + + if(mode == READ_NEXT || mode == READ_PREV) + reload = move_cursor_line(locmem, mode); + else { + reload = thread(locmem, mode); + if(!hit_thread) { + mode = FULLUPDATE; + break; + } + } + + if(reload == -1) { + mode = FULLUPDATE; + break; + } else if(reload) { + recbase = locmem->top_ln; + + if(bidcache>0 && !(currmode &(MODE_SELECT| MODE_DIGEST)) + && last_line-recbasecrs_ln - locmem->top_ln; + if(headers[num].owner[0] != '-') + mode = i_read_key(rcmdlist, locmem, ch, bidcache); + } + } + } while(mode != DOQUIT); +#undef FHSZ + + return_i_read: + free(headers); + last_line = last_line0; + hit_thread = hit_thread0; + headers = headers0; + strcpy(currdirect ,currdirect0); + return; +} diff --git a/pttbbs/mbbsd/record.c b/pttbbs/mbbsd/record.c new file mode 100644 index 00000000..59bc6a75 --- /dev/null +++ b/pttbbs/mbbsd/record.c @@ -0,0 +1,536 @@ +/* $Id: record.c,v 1.1 2002/03/07 15:13:48 in2 Exp $ */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "config.h" +#include "pttstruct.h" +#include "modes.h" +#include "proto.h" + +#undef HAVE_MMAP +#define BUFSIZE 512 + +extern char *str_reply; + +static void PttLock(int fd, int size, int mode) { + static struct flock lock_it; + int ret; + + lock_it.l_whence = SEEK_CUR; /* from current point */ + lock_it.l_start = 0; /* -"- */ + lock_it.l_len = size; /* length of data */ + lock_it.l_type = mode; /* set exclusive/write lock */ + lock_it.l_pid = 0; /* pid not actually interesting */ + while((ret = fcntl(fd, F_SETLKW, &lock_it)) < 0 && errno == EINTR); +} + +#define safewrite write + +int get_num_records(char *fpath, int size) { + struct stat st; + if(stat(fpath, &st) == -1) + return 0; + return st.st_size / size; +} + +int get_sum_records(char* fpath, int size) { + struct stat st; + long ans = 0; + FILE* fp; + fileheader_t fhdr; + char buf[200], *p; + + if(!(fp = fopen(fpath, "r"))) + return -1; + + strcpy(buf, fpath); + p = strrchr(buf, '/') + 1; + + while(fread(&fhdr, size, 1, fp) == 1) { + strcpy(p, fhdr.filename); + if(stat(buf, &st) == 0 && S_ISREG(st.st_mode) && st.st_nlink == 1) + ans += st.st_size; + } + fclose(fp); + return ans / 1024; +} + +int get_record(char *fpath, void *rptr, int size, int id) { + int fd = -1; + + if(id < 1 || (fd = open(fpath, O_RDONLY, 0)) != -1) { + if(lseek(fd, (off_t)(size * (id - 1)), SEEK_SET) != -1) { + if(read(fd, rptr, size) == size) { + close(fd); + return 0; + } + } + close(fd); + } + return -1; +} + +int get_records(char *fpath, void *rptr, int size, int id, int number) { + int fd; + + if(id < 1 || (fd = open(fpath, O_RDONLY, 0)) == -1) + return -1; + + if(lseek(fd, (off_t)(size * (id - 1)), SEEK_SET) == -1) { + close(fd); + return 0; + } + if((id = read(fd, rptr, size * number)) == -1) { + close(fd); + return -1; + } + close(fd); + return id / size; +} + +int substitute_record(char *fpath, void *rptr, int size, int id) { + int fd; + + if(id < 1 || (fd = open(fpath, O_WRONLY | O_CREAT, 0644)) == -1) + return -1; + + lseek(fd, (off_t) (size * (id - 1)), SEEK_SET); + PttLock(fd, size, F_WRLCK); + safewrite(fd, rptr, size); + PttLock(fd, size, F_UNLCK); + close(fd); + + return 0; +} + +/* rocker.011022: 避免lock檔開啟時不正常斷線,造成永久lock */ +static int +force_open (char *fname) +{ + int fd; + time_t expire; + + expire = time(NULL) - 3600; /* lock 存在超過一個小時就是有問題! */ + + if (dasht (fname) < expire) return -1; + unlink(fname); + fd = open (fname, O_WRONLY|O_TRUNC, 0644); + + return fd; +} + + +#if !defined(_BBS_UTIL_C_) +/* new/old/lock file processing */ +typedef struct nol_t { + char newfn[256]; + char oldfn[256]; + char lockfn[256]; +} nol_t; + +static void nolfilename(nol_t *n, char *fpath) { + sprintf(n->newfn, "%s.new", fpath); + sprintf(n->oldfn, "%s.old", fpath); + sprintf(n->lockfn, "%s.lock", fpath); +} + +int delete_record(char fpath[], int size, int id) { + nol_t my; + char abuf[BUFSIZE]; + int fdr, fdw, fd; + int count; + + nolfilename(&my, fpath); + if((fd = open(my.lockfn, O_RDWR | O_CREAT | O_APPEND, 0644)) == -1) + return -1; + + flock(fd, LOCK_EX); + + if((fdr = open(fpath, O_RDONLY, 0)) == -1) { + move(10,10); + outs("delete_record failed!!! (open)"); + pressanykey(); + flock(fd, LOCK_UN); + close(fd); + return -1; + } + + if( + ((fdw = open(my.newfn, O_WRONLY | O_CREAT | O_EXCL, 0644)) == -1) && + ((fdw = force_open (my.newfn)) == -1)) { + flock(fd, LOCK_UN); + close(fd); + close(fdr); + return -1; + } + count = 1; + while(read(fdr, abuf, size) == size) { + if(id != count++ && (safewrite(fdw, abuf, size) == -1)) { + unlink(my.newfn); + close(fdr); + close(fdw); + flock(fd, LOCK_UN); + close(fd); + return -1; + } + } + close(fdr); + close(fdw); + if(Rename(fpath, my.oldfn) == -1 || Rename(my.newfn, fpath) == -1) { + flock(fd, LOCK_UN); + close(fd); + return -1; + } + flock(fd, LOCK_UN); + close(fd); + return 0; +} + +static char *title_body(char *title) { + if(!strncasecmp(title, str_reply, 3)) { + title += 3; + if(*title == ' ') + title++; + } + return title; +} + +int delete_range(char *fpath, int id1, int id2) { + fileheader_t fhdr; + nol_t my; + char fullpath[STRLEN], *t; + int fdr, fdw, fd; + int count; + extern int Tagger(); + + nolfilename(&my, fpath); + + if((fd = open(my.lockfn, O_RDWR | O_CREAT | O_APPEND, 0644)) == -1) + return -1; + + flock(fd, LOCK_EX); + + if((fdr = open(fpath, O_RDONLY, 0)) == -1) { + flock(fd, LOCK_UN); + close(fd); + return -1; + } + + if( + ((fdw = open(my.newfn, O_WRONLY | O_CREAT | O_EXCL, 0644)) == -1) && + ((fdw = force_open (my.newfn)) == -1)) { + close(fdr); + flock(fd, LOCK_UN); + close(fd); + return -1; + } + + count = 1; + strcpy(fullpath, fpath); + t = strrchr(fullpath, '/') + 1; + + while(read(fdr, &fhdr, sizeof(fileheader_t)) == sizeof(fileheader_t)) + { + strcpy(t, fhdr.filename); + +/* rocker.011018: add new tag delete */ + if ( + (fhdr.filemode & FILE_MARKED) || /* 標記 */ + (fhdr.filemode & FILE_DIGEST) || /* 文摘 */ + (id1 && (count < id1 || count > id2)) || /* range */ + (!id1 && Tagger(atoi (t + 2), count, TAG_NIN))) /* TagList */ + { + if((safewrite(fdw, &fhdr, sizeof(fileheader_t)) == -1)) { + close(fdr); + close(fdw); + unlink(my.newfn); + flock(fd, LOCK_UN); + close(fd); + return -1; + } + } + else + { + //if(dashd(fullpath)) + unlink(fullpath); + } + ++count; + } + close(fdr); + close(fdw); + if(Rename(fpath, my.oldfn) == -1 || Rename(my.newfn, fpath) == -1) { + flock(fd, LOCK_UN); + close(fd); + return -1; + } + flock(fd, LOCK_UN); + close(fd); + return 0; +} + +int search_rec(char* dirname, int (*filecheck)()) { + fileheader_t fhdr; + FILE *fp; + int ans = 0; + + if(!(fp = fopen(dirname, "r"))) + return 0; + + while(fread(&fhdr, sizeof(fhdr), 1, fp)) { + ans++; + if((*filecheck) (&fhdr)) { + fclose(fp); + return ans; + } + } + fclose(fp); + return 0; +} + +int delete_files(char* dirname, int (*filecheck)(), int record) { + fileheader_t fhdr; + FILE *fp, *fptmp; + int ans = 0; + char tmpfname[128]; + char genbuf[256]; + char deleted[256]; + fileheader_t delfh; + char deletedDIR[] = "boards/deleted/.DIR"; + + strcpy(deleted, "boards/deleted"); + + if(!(fp = fopen(dirname, "r"))) + return ans; + + strcpy(tmpfname, dirname); + strcat(tmpfname, "_tmp"); + + if(!(fptmp = fopen(tmpfname, "w"))) { + fclose(fp); + return ans; + } + + while(fread(&fhdr, sizeof(fhdr), 1, fp)){ + if((*filecheck)(&fhdr)) { + ans++; + setdirpath(genbuf, dirname, fhdr.filename); + if (record){ + deleted[14] = '\0'; + stampfile(deleted, &delfh); + strcpy(delfh.owner, fhdr.owner); + strcpy(delfh.title, fhdr.title); + Link(genbuf, deleted); + append_record(deletedDIR, &delfh, sizeof(delfh)); + } + unlink(genbuf); + } else + fwrite(&fhdr, sizeof(fhdr), 1, fptmp); + } + + fclose(fp); + fclose(fptmp); + unlink(dirname); + Rename(tmpfname, dirname); + + return ans; +} + +int delete_file(char *dirname, int size, int ent, int (*filecheck)()) { + char abuf[BUFSIZE]; + int fd; + struct stat st; + long numents; + + if(ent < 1 || (fd = open(dirname, O_RDWR)) == -1) + return -1; + flock(fd, LOCK_EX); + fstat(fd, &st); + numents = ((long) st.st_size) / size; + if(((long) st.st_size) % size) + fprintf(stderr, "align err\n"); + if(lseek(fd, (off_t) size * (ent - 1), SEEK_SET) != -1) { + if(read(fd, abuf, size) == size){ + if((*filecheck) (abuf)) { + int i; + + for(i = ent; i < numents; i++) { + if(lseek(fd, (off_t)((i) * size), SEEK_SET) == -1 || + read(fd, abuf, size) != size || + lseek(fd, (off_t)(i - 1) * size, SEEK_SET) == -1) + break; + if(safewrite(fd, abuf, size) != size) + break; + } + ftruncate(fd, (off_t) size * (numents - 1)); + flock(fd, LOCK_UN); + close(fd); + return 0; + } + } + } + lseek(fd, 0, SEEK_SET); + ent = 1; + while(read(fd, abuf, size) == size) { + if((*filecheck)(abuf)) { + int i; + + for(i = ent; i < numents; i++) { + if(lseek(fd, (off_t) (i + 1) * size, SEEK_SET) == -1 || + read(fd, abuf, size) != size || + lseek(fd, (off_t) (i) * size, SEEK_SET) == -1 || + safewrite(fd, abuf, size) != size) + break; + } + ftruncate(fd, (off_t) size * (numents - 1)); + flock(fd, LOCK_UN); + close(fd); + return 0; + } + ent++; + } + flock(fd, LOCK_UN); + close(fd); + return -1; +} + +#endif /* !defined(_BBS_UTIL_C_) */ + +int apply_record(char *fpath, int (*fptr)(), int size) { + char abuf[BUFSIZE]; + FILE* fp; + + if(!(fp = fopen(fpath, "r"))) + return -1; + + while(fread(abuf, 1, size, fp) == size) + if((*fptr) (abuf) == QUIT) { + fclose(fp); + return QUIT; + } + fclose(fp); + return 0; +} + +/* mail / post 時,依據時間建立檔案,加上郵戳 */ +int stampfile(char *fpath, fileheader_t *fh) { + register char *ip = fpath; + time_t dtime; + struct tm *ptime; + int fp = 0; + + if(access(fpath, X_OK | R_OK | W_OK)) + mkdir(fpath, 0755); + + time(&dtime); + while (*(++ip)); + *ip++ = '/'; + do { + sprintf(ip, "M.%ld.A", ++dtime ); + if(fp == -1 && errno != EEXIST) + return -1; + } while((fp = open(fpath, O_CREAT | O_EXCL | O_WRONLY, 0644)) == -1); + close(fp); + memset(fh, 0, sizeof(fileheader_t)); + strcpy(fh->filename, ip); + ptime = localtime(&dtime); + sprintf(fh->date, "%2d/%02d", ptime->tm_mon + 1, ptime->tm_mday); + return 0; +} + +void stampdir(char *fpath, fileheader_t *fh) { + register char *ip = fpath; + time_t dtime; + struct tm *ptime; + + if(access(fpath, X_OK | R_OK | W_OK)) + mkdir(fpath, 0755); + + time(&dtime); + while(*(++ip)); + *ip++ = '/'; + do { + sprintf(ip, "D%lX", ++dtime & 07777); + } while(mkdir(fpath, 0755) == -1); + memset(fh, 0, sizeof(fileheader_t)); + strcpy(fh->filename, ip); + ptime = localtime(&dtime); + sprintf(fh->date, "%2d/%02d", ptime->tm_mon + 1, ptime->tm_mday); +} + +void stamplink(char *fpath, fileheader_t *fh) { + register char *ip = fpath; + time_t dtime; + struct tm *ptime; + + if(access(fpath, X_OK | R_OK | W_OK)) + mkdir(fpath, 0755); + + time(&dtime); + while(*(++ip)); + *ip++ = '/'; + do { + sprintf(ip, "S%lX", ++dtime ); + } while(symlink("temp", fpath) == -1); + memset(fh, 0, sizeof(fileheader_t)); + strcpy(fh->filename, ip); + ptime = localtime(&dtime); + sprintf(fh->date, "%2d/%02d", ptime->tm_mon + 1, ptime->tm_mday); +} + +int do_append(char *fpath, fileheader_t *record, int size) { + int fd; + + if((fd = open(fpath, O_WRONLY | O_CREAT, 0644)) == -1) { + perror("open"); + return -1; + } + flock(fd, LOCK_EX); + lseek(fd, 0, SEEK_END); + + safewrite(fd, record, size); + + flock(fd, LOCK_UN); + close(fd); + return 0; +} + +int append_record(char *fpath, fileheader_t *record, int size) { +#if !defined(_BBS_UTIL_C_) + int m,n; + if(get_num_records(fpath, sizeof(fileheader_t)) <= MAX_KEEPMAIL * 2) { + FILE *fp; + char buf[512],address[200]; + + for(n = strlen(fpath) - 1 ; fpath[n] != '/' && n > 0; n--); + strncpy(buf, fpath, n + 1); + buf[n + 1] = 0; + for(m = strlen(buf) - 2 ; buf[m] != '/' && m > 0 ; m--); + strcat(buf, ".forward"); + if((fp = fopen(buf,"r"))) { + fscanf(fp,"%s",address); + fclose(fp); + if(buf[0] != 0 && buf[0] != ' ') { + buf[n + 1] = 0; + strcat(buf, record->filename); + do_append(fpath,record,size); +#ifndef USE_BSMTP + bbs_sendmail(buf,record->title,address); +#else + bsmtp(buf, record->title, address, 0); +#endif + return 0; + } + } + } +#endif + + do_append(fpath,record,size); + + return 0; +} diff --git a/pttbbs/mbbsd/register.c b/pttbbs/mbbsd/register.c new file mode 100644 index 00000000..e9c25be5 --- /dev/null +++ b/pttbbs/mbbsd/register.c @@ -0,0 +1,339 @@ +/* $Id: register.c,v 1.1 2002/03/07 15:13:48 in2 Exp $ */ +#define _XOPEN_SOURCE + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "config.h" +#include "pttstruct.h" +#include "perm.h" +#include "common.h" +#include "proto.h" + +extern char *str_new; +extern char *msg_uid; +extern int t_lines, t_columns; /* Screen size / width */ +extern char *str_mail_address; + +/* password encryption */ +static char pwbuf[14]; + +char *genpasswd(char *pw) { + if(pw[0]) { + char saltc[2], c; + int i; + + i = 9 * getpid(); + saltc[0] = i & 077; + saltc[1] = (i >> 6) & 077; + + for(i = 0; i < 2; i++) { + c = saltc[i] + '.'; + if(c > '9') + c += 7; + if(c > 'Z') + c += 6; + saltc[i] = c; + } + strcpy(pwbuf, pw); + return crypt(pwbuf, saltc); + } + return ""; +} + +int checkpasswd(char *passwd, char *test) { + char *pw; + + strncpy(pwbuf, test, 14); + pw = crypt(pwbuf, passwd); + return (!strncmp(pw, passwd, 14)); +} + +/* 檢查 user 註冊情況 */ +int bad_user_id(char *userid) { + int len, i; + len = strlen(userid); + + if(len < 2) + return 1; + + if (not_alpha(userid[0])) + return 1; + for (i=1; iuserid[0] == '\0') || (urec->userlevel & PERM_XEMPT) + /*|| (urec->userlevel & PERM_LOGINOK)*/ + || !strcmp(STR_GUEST,urec->userid)) + return 999999; + value = (clock - urec->lastlogin) / 60; /* minutes */ + + /* new user should register in 30 mins */ + if(strcmp(urec->userid, str_new) == 0) + return 30 - value; +#if 0 + if (!urec->numlogins) /* 未 login 成功者,不保留 */ + return -1; + if (urec->numlogins <= 3) /* #login 少於三者,保留 20 天 */ + return 20 * 24 * 60 - value; +#endif + /* 未完成註冊者,保留 15 天 */ + /* 一般情況,保留 120 天 */ + return (urec->userlevel & PERM_LOGINOK ? 120 : 15) * 24 * 60 - value; +} + +int check_and_expire_account(int uid,userec_t *urec) +{ + userec_t zerorec; + time_t now=time(NULL); + char genbuf[200],genbuf2[200]; + int val; + if((val = compute_user_value(urec, now)) < 0) { + sprintf(genbuf, "#%d %-12s %15.15s %d %d %d", + uid, urec->userid, ctime(&(urec->lastlogin)) + 4, + urec->numlogins, urec->numposts, val); + if(val > -1 * 60 * 24 * 365) { + memset(&zerorec, 0, sizeof(zerorec)); + log_usies("CLEAN", genbuf); + sprintf(genbuf, "home/%c/%s", urec->userid[0], + urec->userid); + sprintf(genbuf2, "tmp/%s", urec->userid); + if(dashd(genbuf) && Rename(genbuf, genbuf2)) { + sprintf(genbuf, "/bin/rm -fr home/%c/%s >/dev/null 2>&1", + urec->userid[0],urec->userid); + system(genbuf); + } + passwd_update(uid, &zerorec); + remove_from_uhash(uid - 1); + add_to_uhash(uid - 1, ""); + } + else + { + val=0; + log_usies("DATED", genbuf); + } + } + return val; +} + +extern char *fn_passwd; + +int getnewuserid() { + char genbuf[50]; + static char *fn_fresh = ".fresh"; + userec_t utmp,zerorec; + time_t clock; + struct stat st; + int fd, i; + + memset(&zerorec, 0, sizeof(zerorec)); + clock = time(NULL); + + /* Lazy method : 先找尋已經清除的過期帳號 */ + if((i = searchnewuser(0)) == 0) { + /* 每 1 個小時,清理 user 帳號一次 */ + if((stat(fn_fresh, &st) == -1) || (st.st_mtime < clock - 3600)) { + if((fd = open(fn_fresh, O_RDWR | O_CREAT, 0600)) == -1) + return -1; + write(fd, ctime(&clock), 25); + close(fd); + log_usies("CLEAN", "dated users"); + + fprintf(stdout, "尋找新帳號中, 請稍待片刻...\n\r"); + + if((fd = open(fn_passwd, O_RDWR | O_CREAT, 0600)) == -1) + return -1; + + /* 不曉得為什麼要從 2 開始... Ptt:因為SYSOP在1 */ + for(i = 2; i <= MAX_USERS; i++) { + passwd_query(i, &utmp); + check_and_expire_account(i,&utmp); + } + } + } + + passwd_lock(); + i = searchnewuser(1); + if((i <= 0) || (i > MAX_USERS)) { + passwd_unlock(); + if(more("etc/user_full", NA) == -1) + fprintf(stdout, "抱歉,使用者帳號已經滿了,無法註冊新的帳號\n\r"); + safe_sleep(2); + exit(1); + } + + sprintf(genbuf, "uid %d", i); + log_usies("APPLY", genbuf); + + strcpy(zerorec.userid, str_new); + zerorec.lastlogin = clock; + passwd_update(i, &zerorec); + setuserid(i, zerorec.userid); + passwd_unlock(); + return i; +} + +void new_register() { + extern userec_t xuser; + userec_t newuser; + char passbuf[STRLEN]; + int allocid, try, id; + + memset(&newuser, 0, sizeof(newuser)); + more("etc/register", NA); + try = 0; + while(1) { + if(++try >= 6) { + outs("\n您嘗試錯誤的輸入太多,請下次再來吧\n"); + refresh(); + + pressanykey(); + oflush(); + exit(1); + } + getdata(17, 0, msg_uid, newuser.userid, IDLEN + 1, DOECHO); + + if(bad_user_id(newuser.userid)) + outs("無法接受這個代號,請使用英文字母,並且不要包含空格\n"); + else if ((id=getuser(newuser.userid)) && + (id=check_and_expire_account(id,&xuser))>=0) + { + if(id==999999) + outs("此代號已經有人使用 是不死之身"); + else + { + sprintf(passbuf,"此代號已經有人使用 還有%d天才過期 \n",id/(60*24)); + outs(passbuf); + } + } + else + break; + } + + try = 0; + while(1) { + if(++try >= 6) { + outs("\n您嘗試錯誤的輸入太多,請下次再來吧\n"); + refresh(); + + pressanykey(); + oflush(); + exit(1); + } + if((getdata(19, 0, "請設定密碼:", passbuf, PASSLEN, NOECHO) < 3) || + !strcmp(passbuf, newuser.userid)) { + outs("密碼太簡單,易遭入侵,至少要 4 個字,請重新輸入\n"); + continue; + } + strncpy(newuser.passwd, passbuf, PASSLEN); + getdata(20, 0, "請檢查密碼:", passbuf, PASSLEN, NOECHO); + if(strncmp(passbuf, newuser.passwd, PASSLEN)) { + outs("密碼輸入錯誤, 請重新輸入密碼.\n"); + continue; + } + passbuf[8] = '\0'; + strncpy(newuser.passwd, genpasswd(passbuf), PASSLEN); + break; + } + newuser.userlevel = PERM_DEFAULT; + newuser.uflag = COLOR_FLAG | BRDSORT_FLAG | MOVIE_FLAG; + newuser.firstlogin = newuser.lastlogin = time(NULL); + newuser.money = 0; + newuser.pager = 1; + allocid = getnewuserid(); + if(allocid > MAX_USERS || allocid <= 0) { + fprintf(stderr, "本站人口已達飽和!\n"); + exit(1); + } + + if(passwd_update(allocid, &newuser) == -1) { + fprintf(stderr, "客滿了,再見!\n"); + exit(1); + } + setuserid(allocid, newuser.userid); + if(!dosearchuser(newuser.userid)) { + fprintf(stderr, "無法建立帳號\n"); + exit(1); + } +} + +extern userec_t cuser; + +void check_register() { + char *ptr = NULL; + + stand_title("請詳細填寫個人資料"); + + while(strlen(cuser.username) < 2) + getdata(2, 0, "綽號暱稱:", cuser.username, 24, DOECHO); + + for(ptr = cuser.username; *ptr; ptr++) { + if (*ptr == 9) /* TAB convert */ + *ptr = ' '; + } + while(strlen(cuser.realname) < 4) + getdata(4, 0, "真實姓名:", cuser.realname, 20, DOECHO); + + while(strlen(cuser.address) < 8) + getdata(6, 0, "聯絡地址:", cuser.address, 50, DOECHO); + + + if(!strchr(cuser.email, '@')) { + bell(); + move(t_lines - 4, 0); + prints("※ 為了您的權益,請填寫真實的 E-mail address, " + "以資確認閣下身份,\n" + "格式為 \033[44muser@domain_name\033[0m 或 \033[44muser" + "@\\[ip_number\\]\033[0m。\n\n" + "※ 如果您真的沒有 E-mail,請直接按 [return] 即可。"); + + do { + getdata(8, 0, "電子信箱:", cuser.email, 50, DOECHO); + if(!cuser.email[0]) + sprintf(cuser.email, "%s%s", cuser.userid, str_mail_address); + } while(!strchr(cuser.email, '@')); + + } + if(!HAS_PERM(PERM_SYSOP) && !HAS_PERM(PERM_LOGINOK)) { + /* 回覆過身份認證信函,或曾經 E-mail post 過 */ + clear(); + move(9,3); + prints("請詳填寫\033[32m註冊申請單\033[m," + "通告站長以獲得進階使用權力。\n\n\n\n"); + u_register(); + } + +#ifdef NEWUSER_LIMIT + if(!(cuser.userlevel & PERM_LOGINOK) && !HAS_PERM(PERM_SYSOP)) { + if(cuser.lastlogin - cuser.firstlogin < 3 * 86400) + cuser.userlevel &= ~PERM_POST; + more("etc/newuser", YEA); + } +#endif +} diff --git a/pttbbs/mbbsd/screen.c b/pttbbs/mbbsd/screen.c new file mode 100644 index 00000000..46ad5b38 --- /dev/null +++ b/pttbbs/mbbsd/screen.c @@ -0,0 +1,559 @@ +/* $Id: screen.c,v 1.1 2002/03/07 15:13:48 in2 Exp $ */ +#include +#include +#include +#include +#include +#include "config.h" +#include "pttstruct.h" +#include "common.h" +#include "proto.h" + +extern int t_lines, t_columns; /* Screen size / width */ +extern int b_lines; /* Screen bottom line number: t_lines-1 */ +extern int p_lines; /* a Page of Screen line numbers: tlines-4 */ +extern int showansi; + +extern char *clearbuf; +extern char *cleolbuf; +extern char *scrollrev; +extern char *strtstandout; +extern char *endstandout; +extern int clearbuflen; +extern int cleolbuflen; +extern int scrollrevlen; +extern int strtstandoutlen; +extern int endstandoutlen; +extern int automargins; +#ifdef SUPPORT_GB +static int current_font_type=TYPE_BIG5; +static int gbinited=0; +#endif +#define SCR_WIDTH 80 +#define o_clear() output(clearbuf,clearbuflen) +#define o_cleol() output(cleolbuf,cleolbuflen) +#define o_scrollrev() output(scrollrev,scrollrevlen) +#define o_standup() output(strtstandout,strtstandoutlen) +#define o_standdown() output(endstandout,endstandoutlen) + +unsigned char scr_lns, scr_cols; +static unsigned char cur_ln = 0, cur_col = 0; +static unsigned char docls, downfrom = 0; +static unsigned char standing = NA; +static char roll = 0; +static int scrollcnt, tc_col, tc_line; + +screenline_t *big_picture = NULL; + +#define MODIFIED (1) /* if line has been modifed, screen output */ +#define STANDOUT (2) /* if this line has a standout region */ + +int tputs(const char *str, int affcnt, int (*putc)(int)); + +void initscr() { + if(!big_picture) { + scr_lns = t_lines; + scr_cols = t_columns = ANSILINELEN; + /* scr_cols = MIN(t_columns, ANSILINELEN); */ + big_picture = (screenline_t *) calloc(scr_lns, sizeof(screenline_t)); + docls = YEA; + } +} + +void move(int y, int x) { + cur_col = x; + cur_ln = y; +} + +void getyx(int *y, int *x) { + *y = cur_ln; + *x = cur_col; +} + +static void rel_move(int was_col, int was_ln, int new_col, int new_ln) { + if(new_ln >= t_lines || new_col >= t_columns) + return; + + tc_col = new_col; + tc_line = new_ln; + if(new_col == 0) { + if(new_ln == was_ln) { + if(was_col) + ochar('\r'); + return; + } else if(new_ln == was_ln + 1) { + ochar('\n'); + if(was_col) + ochar('\r'); + return; + } + } + + if(new_ln == was_ln) { + if(was_col == new_col) + return; + + if(new_col == was_col - 1) { + ochar(Ctrl('H')); + return; + } + } + do_move(new_col, new_ln); +} + +static void standoutput(char *buf, int ds, int de, int sso, int eso) { + int st_start, st_end; + + if(eso <= ds || sso >= de) { + output(buf + ds, de - ds); + } else { + st_start = MAX(sso, ds); + st_end = MIN(eso, de); + if(sso > ds) + output(buf + ds, sso - ds); + o_standup(); + output(buf + st_start, st_end - st_start); + o_standdown(); + if(de > eso) + output(buf + eso, de - eso); + } +} + +void redoscr() { + register screenline_t *bp; + register int i, j, len; + + o_clear(); + for(tc_col = tc_line = i = 0, j = roll; i < scr_lns; i++, j++) { + if(j >= scr_lns) + j = 0; + bp = &big_picture[j]; + if((len = bp->len)) { + rel_move(tc_col, tc_line, 0, i); + if(bp->mode & STANDOUT) + standoutput(bp->data, 0, len, bp->sso, bp->eso); + else + output(bp->data, len); + tc_col += len; + if(tc_col >= t_columns) { + if (automargins) + tc_col = t_columns - 1; + else { + tc_col -= t_columns; + tc_line++; + if(tc_line >= t_lines) + tc_line = b_lines; + } + } + bp->mode &= ~(MODIFIED); + bp->oldlen = len; + } + } + rel_move(tc_col, tc_line, cur_col, cur_ln); + docls = scrollcnt = 0; + oflush(); +} + +void refresh() { + register screenline_t *bp = big_picture; + register int i, j, len; + extern int automargins; + extern int scrollrevlen; + if(num_in_buf()) + return; + + if((docls) || (abs(scrollcnt) >= (scr_lns - 3))) { + redoscr(); + return; + } + + if(scrollcnt < 0) { + if(!scrollrevlen) { + redoscr(); + return; + } + rel_move(tc_col, tc_line, 0, 0); + do { + o_scrollrev(); + } while(++scrollcnt); + } else if (scrollcnt > 0) { + rel_move(tc_col, tc_line, 0, b_lines); + do { + ochar('\n'); + } while(--scrollcnt); + } + + for(i = 0, j = roll; i < scr_lns; i++, j++) { + if(j >= scr_lns) + j = 0; + bp = &big_picture[j]; + len = bp->len; + if(bp->mode & MODIFIED && bp->smod < len) { + bp->mode &= ~(MODIFIED); + if(bp->emod >= len) + bp->emod = len - 1; + rel_move(tc_col, tc_line, bp->smod, i); + + if(bp->mode & STANDOUT) + standoutput(bp->data, bp->smod, bp->emod + 1, + bp->sso, bp->eso); + else + output(&bp->data[bp->smod], bp->emod - bp->smod + 1); + tc_col = bp->emod + 1; + if(tc_col >= t_columns) { + if(automargins) { + tc_col -= t_columns; + if(++tc_line >= t_lines) + tc_line = b_lines; + } else + tc_col = t_columns - 1; + } + } + + if(bp->oldlen > len) { + rel_move(tc_col, tc_line, len, i); + o_cleol(); + } + bp->oldlen = len; + + } + + rel_move(tc_col, tc_line, cur_col, cur_ln); + + oflush(); +} + +void clear() { + register screenline_t *slp; + + register int i; + + docls = YEA; + cur_col = cur_ln = roll = downfrom = i = 0; + do { + slp = &big_picture[i]; + slp->mode = slp->len = slp->oldlen = 0; + } while(++i < scr_lns); +} + +void clrtoeol() { + register screenline_t *slp; + register int ln; + + standing = NA; + if((ln = cur_ln + roll) >= scr_lns) + ln -= scr_lns; + slp = &big_picture[ln]; + if(cur_col <= slp->sso) + slp->mode &= ~STANDOUT; + + if(cur_col > slp->oldlen) { + for(ln = slp->len; ln <= cur_col; ln++) + slp->data[ln] = ' '; + } + + if(cur_col < slp->oldlen) { + for(ln = slp->len; ln >= cur_col; ln--) + slp->data[ln] = ' '; + } + + slp->len = cur_col; +} + +void clrtoline(int line) { + register screenline_t *slp; + register int i, j; + + for(i = cur_ln, j = i + roll; i < line; i++, j++) { + if(j >= scr_lns) + j -= scr_lns; + slp = &big_picture[j]; + slp->mode = slp->len = 0; + if(slp->oldlen) + slp->oldlen = 255; + } +} + +void clrtobot() { + clrtoline(scr_lns); +} + +void outch(unsigned char c) { + register screenline_t *slp; + register int i; + + if((i = cur_ln + roll) >= scr_lns) + i -= scr_lns; + slp = &big_picture[i]; + + if(c == '\n' || c == '\r') { + if(standing) { + slp->eso = MAX(slp->eso, cur_col); + standing = NA; + } + if((i = cur_col - slp->len) > 0) + memset(&slp->data[slp->len], ' ', i + 1); + slp->len = cur_col; + cur_col = 0; + if(cur_ln < scr_lns) + cur_ln++; + return; + } +/* + else if(c != '\033' && !isprint2(c)) + { + c = '*'; //substitute a '*' for non-printable + } +*/ + if(cur_col >= slp->len) { + for(i = slp->len; i < cur_col; i++) + slp->data[i] = ' '; + slp->data[cur_col] = '\0'; + slp->len = cur_col + 1; + } + + if(slp->data[cur_col] != c) { + slp->data[cur_col] = c; + if((slp->mode & MODIFIED) != MODIFIED) + slp->smod = slp->emod = cur_col; + slp->mode |= MODIFIED; + if(cur_col > slp->emod) + slp->emod = cur_col; + if(cur_col < slp->smod) + slp->smod = cur_col; + } + + if (++cur_col >= scr_cols) + { + if (standing && (slp->mode & STANDOUT)) + { + standing = 0; + slp->eso = MAX(slp->eso, cur_col); + } + cur_col = 0; + if (cur_ln < scr_lns) + cur_ln++; + } + +} + +static void parsecolor(char *buf) { + char *val; + char data[24]; + + data[0] = '\0'; + val = (char *)strtok(buf, ";"); + + while(val) { + if(atoi(val) < 30) { + if(data[0]) + strcat(data, ";"); + strcat(data, val); + } + val = (char *) strtok(NULL, ";"); + } + strcpy(buf, data); +} + +#define NORMAL (00) +#define ESCAPE (01) +#define VTKEYS (02) + +void outc(unsigned char ch) { + if(showansi) + outch(ch); + else { + static char buf[24]; + static int p = 0; + static int mode = NORMAL; + int i; + + switch(mode) { + case NORMAL: + if(ch == '\033') + mode = ESCAPE; + else + outch(ch); + return; + case ESCAPE: + if(ch == '[') + mode = VTKEYS; + else { + mode = NORMAL; + outch(''); + outch(ch); + } + return; + case VTKEYS: + if(ch == 'm') { + buf[p++] = '\0'; + parsecolor(buf); + } else if((p < 24) && (not_alpha(ch))) { + buf[p++] = ch; + return; + } + if(buf[0]) { + outch(''); + outch('['); + + for(i = 0; (p = buf[i]); i++) + outch(p); + outch(ch); + } + p = 0; + mode = NORMAL; + } + } +} + +static void do_outs(char *str) { + while(*str) + { + outc(*str++); + } +} +#ifdef SUPPORT_GB +static void gb_init() +{ + if(current_font_type == TYPE_GB) + { + hc_readtab(BBSHOME"/etc/hc.tab"); + } + gbinited = 1; +} + +static void gb_outs(char *str) +{ + do_outs(hc_convert_str(str, HC_BIGtoGB, HC_DO_SINGLE)); +} +#endif +int edit_outs(char *text) { + register int column = 0; + register char ch; +#ifdef SUPPORT_GB + if(current_font_type == TYPE_GB) + text = hc_convert_str(text, HC_BIGtoGB, HC_DO_SINGLE); +#endif + while((ch = *text++) && (++column < SCR_WIDTH)) + outch(ch == 27 ? '*' : ch); + + return 0; +} + +void outs(char *str) { +#ifdef SUPPORT_GB + if(current_font_type == TYPE_BIG5) +#endif + do_outs(str); +#ifdef SUPPORT_GB + else + { + if(!gbinited) gb_init(); + gb_outs(str); + } +#endif +} + + +/* Jaky */ +void Jaky_outs(char *str, int line) { +#ifdef SUPPORT_GB + if(current_font_type == TYPE_GB) + str = hc_convert_str(str, HC_BIGtoGB, HC_DO_SINGLE); +#endif + while(*str && line) { + outc(*str); + if(*str=='\n') + line--; + str++; + } +} + +void outmsg(char *msg) { + move(b_lines, 0); + clrtoeol(); +#ifdef SUPPORT_GB + if(current_font_type == TYPE_GB) + msg = hc_convert_str(msg, HC_BIGtoGB, HC_DO_SINGLE); +#endif + while(*msg) + outc(*msg++); +} + +void prints(char *fmt, ...) { + va_list args; + char buff[1024]; + + va_start(args, fmt); + vsprintf(buff, fmt, args); + va_end(args); + outs(buff); +} + +void mprints(int y, int x, char *str) { + move(y, x); + clrtoeol(); + prints(str); +} + +void scroll() { + scrollcnt++; + if(++roll >= scr_lns) + roll = 0; + move(b_lines, 0); + clrtoeol(); +} + +void rscroll() { + scrollcnt--; + if(--roll < 0) + roll = b_lines; + move(0, 0); + clrtoeol(); +} + +void region_scroll_up(int top, int bottom) { + int i; + + if(top > bottom) { + i = top; + top = bottom; + bottom = i; + } + + if(top < 0 || bottom >= scr_lns) + return; + + for(i = top; i < bottom; i++) + big_picture[i] = big_picture[i + 1]; + memset(big_picture + i, 0, sizeof(*big_picture)); + memset(big_picture[i].data, ' ', scr_cols); + save_cursor(); + change_scroll_range(top, bottom); + do_move(0, bottom); + scroll_forward(); + change_scroll_range(0, scr_lns - 1); + restore_cursor(); + refresh(); +} + +void standout() { + if(!standing && strtstandoutlen) { + register screenline_t *slp; + + slp = &big_picture[((cur_ln + roll) % scr_lns)]; + standing = YEA; + slp->sso = slp->eso = cur_col; + slp->mode |= STANDOUT; + } +} + +void standend() { + if(standing && strtstandoutlen) { + register screenline_t *slp; + + slp = &big_picture[((cur_ln + roll) % scr_lns)]; + standing = NA; + slp->eso = MAX(slp->eso, cur_col); + } +} diff --git a/pttbbs/mbbsd/stuff.c b/pttbbs/mbbsd/stuff.c new file mode 100644 index 00000000..9218b7f0 --- /dev/null +++ b/pttbbs/mbbsd/stuff.c @@ -0,0 +1,524 @@ +/* $Id: stuff.c,v 1.1 2002/03/07 15:13:48 in2 Exp $ */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "config.h" +#include "pttstruct.h" +#include "modes.h" +#include "common.h" +#include "perm.h" +#include "proto.h" + +extern int currmode; +extern char *fn_mandex; +extern char *str_reply; +extern char *str_space; +extern int b_lines; /* Screen bottom line number: t_lines-1 */ +extern userec_t cuser; + +/* ----------------------------------------------------- */ +/* set file path for boards/user home */ +/* ----------------------------------------------------- */ +static char *str_home_file = "home/%c/%s/%s"; +static char *str_board_file = "boards/%s/%s"; + +#define STR_DOTDIR ".DIR" +static char *str_dotdir = STR_DOTDIR; + +void setcalfile(char *buf, char *userid) { + sprintf(buf, "home/%c/%s/calendar", userid[0], userid); +} + +void sethomepath(char *buf, char *userid) { + sprintf(buf, "home/%c/%s", userid[0], userid); +} + +void sethomedir(char *buf, char *userid) { + sprintf(buf, str_home_file, userid[0], userid, str_dotdir); +} + +void sethomeman(char *buf, char *userid) { + sprintf(buf, str_home_file, userid[0], userid, "man"); +} + +void sethomefile(char *buf, char *userid, char *fname) { + sprintf(buf, str_home_file, userid[0], userid, fname); +} + +void setuserfile(char *buf, char *fname) { + sprintf(buf, str_home_file, cuser.userid[0], cuser.userid, fname); +} + +void setapath(char *buf, char *boardname) { + sprintf(buf, "man/boards/%s", boardname); +} + +void setadir(char *buf, char *path) { + sprintf(buf, "%s/%s", path, str_dotdir); +} + +void setbpath(char *buf, char *boardname) { + sprintf(buf, "boards/%s", boardname); +} + +void setbdir(char *buf, char *boardname) { + sprintf(buf, str_board_file, boardname, + currmode & MODE_ETC ? ".ETC" : + (currmode & MODE_DIGEST ? fn_mandex : str_dotdir)); +} + +void setbfile(char *buf, char *boardname, char *fname) { + sprintf(buf, str_board_file, boardname, fname); +} + +void setdirpath(char *buf, char *direct, char *fname) { + strcpy(buf, direct); + direct = strrchr(buf, '/'); + strcpy(direct + 1, fname); +} + +char *subject(char *title) { + if(!strncasecmp(title, str_reply, 3)) { + title += 3; + if(*title == ' ') + title++; + } + return title; +} + +/* ----------------------------------------------------- */ +/* 字串轉換檢查函數 */ +/* ----------------------------------------------------- */ +int str_checksum(char *str) { + int n = 1; + if(strlen(str) < 6) + return 0; + while(*str) + n += *(str++) * (n); + return n; +} + +void str_lower(char *t, char *s) { + register unsigned char ch; + + do { + ch = *s++; + *t++ = char_lower(ch); + } while(ch); +} + +int strstr_lower(char *str, char *tag) { + char buf[STRLEN]; + + str_lower(buf, str); + return (int)strstr(buf, tag); +} + +void trim(char *buf) { /* remove trailing space */ + char *p = buf; + + while(*p) + p++; + while(--p >= buf) { + if(*p == ' ') + *p = '\0'; + else + break; + } +} + +/* ----------------------------------------------------- */ +/* 字串檢查函數:英文、數字、檔名、E-mail address */ +/* ----------------------------------------------------- */ +int isprint2(char ch) { + return ((ch & 0x80) ? 1 : isprint(ch)); + //return 1; +} + +int not_alpha(char ch) { + return (ch < 'A' || (ch > 'Z' && ch < 'a') || ch > 'z'); +} + +int not_alnum(char ch) { + return (ch < '0' || (ch > '9' && ch < 'A') || + (ch > 'Z' && ch < 'a') || ch > 'z'); +} + +int invalid_pname(char *str) { + char *p1, *p2, *p3; + + p1 = str; + while(*p1) { + if(!(p2 = strchr(p1, '/'))) + p2 = str + strlen(str); + if(p1 + 1 > p2 || p1 + strspn(p1, ".") == p2) + return 1; + for(p3 = p1; p3 < p2; p3++) + if(not_alnum(*p3) && !strchr("@[]-._", *p3)) + return 1; + p1 = p2 + (*p2 ? 1 : 0); + } + return 0; +} + +int valid_ident(char *ident) { + static char *invalid[] = {"unknown@", "root@", "gopher@", "bbs@", + "@bbs", "guest@", "@ppp", "@slip", NULL}; + char buf[128]; + int i; + + str_lower(buf, ident); + for(i = 0; invalid[i]; i++) + if(strstr(buf, invalid[i])) + return 0; + return 1; +} + +int is_uBM(char *list, char *id) { + register int len; + + if(list[0] == '[') + list++; + if(list[0] > ' ') { + len = strlen(id); + do { + if(!strncasecmp(list, id, len)) { + list += len; + if((*list == 0) || (*list == '/') || + (*list == ']') || (*list == ' ')) + return 1; + } + if((list = strchr(list,'/')) != NULL) + list++; + else + break; + } while(1); + } + return 0; +} + +int is_BM(char *list) { + if(is_uBM(list,cuser.userid)) { + cuser.userlevel |= PERM_BM; /* Ptt 自動加上BM的權利 */ + return 1; + } + return 0; +} + +int userid_is_BM(char *userid, char *list) { + register int ch, len; + + ch = list[0]; + if((ch > ' ') && (ch < 128)) { + len = strlen(userid); + do { + if(!strncasecmp(list, userid, len)) { + ch = list[len]; + if((ch == 0) || (ch == '/') || (ch == ']')) + return 1; + } + while((ch = *list++)) { + if(ch == '/') + break; + } + } while(ch); + } + return 0; +} + +/* ----------------------------------------------------- */ +/* 檔案檢查函數:檔案、目錄、屬於 */ +/* ----------------------------------------------------- */ +off_t dashs(char *fname) { + struct stat st; + + if(!stat(fname, &st)) + return st.st_size; + else + return -1; +} + +long dasht(char *fname) { + struct stat st; + + if(!stat(fname, &st)) + return st.st_mtime; + else + return -1; +} + +int dashl(char *fname) { + struct stat st; + + return (lstat(fname, &st) == 0 && S_ISLNK(st.st_mode)); +} + +int dashf(char *fname) { + struct stat st; + + return (stat(fname, &st) == 0 && S_ISREG(st.st_mode)); +} + +int dashd(char *fname) { + struct stat st; + + return (stat(fname, &st) == 0 && S_ISDIR(st.st_mode)); +} + +int belong(char *filelist, char *key) { + FILE *fp; + int rc = 0; + + if((fp = fopen(filelist, "r"))) { + char buf[STRLEN], *ptr; + + while(fgets(buf, STRLEN, fp)) { + if((ptr = strtok(buf, str_space)) && !strcasecmp(ptr, key)) { + rc = 1; + break; + } + } + fclose(fp); + } + return rc; +} + +char *Cdate(time_t *clock) { + static char foo[32]; + struct tm *mytm = localtime(clock); + + strftime(foo, 32, "%m/%d/%Y %T %a", mytm); + return foo; +} + +char *Cdatelite(time_t *clock) { + static char foo[32]; + struct tm *mytm = localtime(clock); + + strftime(foo, 32, "%m/%d/%Y %T", mytm); + return foo; +} + +char *Cdatedate(time_t *clock){ + static char foo[32]; + struct tm *mytm = localtime(clock); + + strftime(foo, 32, "%m/%d/%Y", mytm); + return foo; +} + +static void capture_screen() { + char fname[200]; + FILE* fp; + extern screenline_t *big_picture; + extern unsigned char scr_lns; + int i; + + getdata(b_lines - 2, 0, "把這個畫面收入到暫存檔?[y/N] ", + fname, 4, LCECHO); + if(fname[0] != 'y' ) return; + + setuserfile(fname, ask_tmpbuf(b_lines - 1)); + if((fp = fopen(fname, "w"))) { + for(i = 0; i < scr_lns; i++) + fprintf(fp, "%.*s\n", big_picture[i].len, big_picture[i].data); + fclose(fp); + } +} + +void pressanykey() { + int ch; + + outmsg("\033[37;45;1m " + "● 請按 \033[33m(Space/Return)\033[37m 繼續 ●" + " \033[33m(^T)\033[37m 存暫存檔 \033[m"); + do { + ch = igetkey(); + + if(ch == Ctrl('T')) { + capture_screen(); + break; + } + } while((ch != ' ') && (ch != KEY_LEFT) && (ch != '\r') && (ch != '\n')); + move(b_lines, 0); + clrtoeol(); + refresh(); +} + +int vmsg (const char *fmt, ...) +{ + va_list ap; + char msg[80] = {0}; + int ch; + + va_start (ap, fmt); + vsprintf (msg, fmt, ap); + va_end (ap); + + move (b_lines, 0); + clrtoeol (); + + if (*msg) + prints ("\033[1;36;44m ◆ %-55.54s \033[33;46m \033[200m\033[1431m\033[506m[請按任意鍵繼續]\033[201m \033[m", msg); + else + outs ("\033[46;1m \033[37m" + "\033[200m\033[1431m\033[506m□ 請按 \033[33m(Space/Return)\033[37m 繼續 □\033[201m" + " \033[m"); + + do { + ch = igetkey(); + + if(ch == Ctrl('T')) { + capture_screen(); + break; + } + } while((ch != ' ') && (ch != KEY_LEFT) && (ch != '\r') && (ch != '\n')); + + + move (b_lines, 0); + clrtoeol (); + refresh (); + return ch; +} + +void bell() { + char c; + + c = Ctrl('G'); + write(1, &c, 1); +} + +int search_num(int ch, int max) { + int clen = 1; + int x, y; + extern unsigned char scr_cols; + char genbuf[10]; + + outmsg("\033[7m 跳至第幾項:\033[m"); + outc(ch); + genbuf[0] = ch; + getyx(&y, &x); + x--; + while((ch = igetch()) != '\r') { + if(ch == 'q' || ch == 'e') + return -1; + if(ch == '\n') + break; + if(ch == '\177' || ch == Ctrl('H')) { + if(clen == 0) { + bell(); + continue; + } + clen--; + move(y, x + clen); + outc(' '); + move(y, x + clen); + continue; + } + if(!isdigit(ch)) { + bell(); + continue; + } + if(x + clen >= scr_cols || clen >= 6) { + bell(); + continue; + } + genbuf[clen++] = ch; + outc(ch); + } + genbuf[clen] = '\0'; + move(b_lines, 0); + clrtoeol(); + if(genbuf[0] == '\0') + return -1; + clen = atoi(genbuf); + if(clen == 0) + return 0; + if(clen > max) + return max; + return clen - 1; +} + +void stand_title(char *title) { + clear(); + prints("\033[1;37;46m【 %s 】\033[m\n", title); +} + +void cursor_show(int row, int column) { + move(row, column); + outs(STR_CURSOR); + move(row, column + 1); +} + +void cursor_clear(int row, int column) { + move(row, column); + outs(STR_UNCUR); +} + +int cursor_key(int row, int column) { + int ch; + + cursor_show(row, column); + ch = egetch(); + move(row, column); + outs(STR_UNCUR); + return ch; +} + +void printdash(char *mesg) { + int head = 0, tail; + + if(mesg) + head = (strlen(mesg) + 1) >> 1; + + tail = head; + + while(head++ < 38) + outch('-'); + + if(tail) { + outch(' '); + outs(mesg); + outch(' '); + } + + while(tail++ < 38) + outch('-'); + outch('\n'); +} + +int log_file(char *filename,char *buf) { + FILE *fp; + + if((fp = fopen(filename, "a" )) != NULL ) { + fputs( buf, fp ); + if(!strchr(buf,'\n')) + fputc('\n',fp); + fclose( fp ); + return 0; + } + else + return -1; +} + +void show_help(char *helptext[]) { + char *str; + int i; + + clear(); + for(i = 0; (str = helptext[i]); i++) { + if(*str == '\0') + prints("\033[1m【 %s 】\033[0m\n", str + 1); + else if(*str == '\01') + prints("\n\033[36m【 %s 】\033[m\n", str + 1); + else + prints(" %s\n", str); + } + pressanykey(); +} diff --git a/pttbbs/mbbsd/syspost.c b/pttbbs/mbbsd/syspost.c new file mode 100644 index 00000000..b7aefe10 --- /dev/null +++ b/pttbbs/mbbsd/syspost.c @@ -0,0 +1,102 @@ +/* $Id: syspost.c,v 1.1 2002/03/07 15:13:48 in2 Exp $ */ +#include +#include +#include +#include +#include "config.h" +#include "pttstruct.h" +#include "perm.h" +#include "common.h" +#include "proto.h" + +extern char *str_permid[]; +extern userec_t cuser; + +void post_change_perm(int oldperm, int newperm, char *sysopid, char *userid) { + FILE *fp; + fileheader_t fhdr; + time_t now = time(0); + char genbuf[200], reason[30]; + int i, flag=0; + + strcpy(genbuf, "boards/Security"); + stampfile(genbuf, &fhdr); + if(!(fp = fopen(genbuf,"w"))) + return; + + fprintf(fp, "作者: [系統安全局] 看板: Security\n" + "標題: [公安報告] 站長修改權限報告\n" + "時間: %s\n", ctime(&now)); + for(i = 5; i < NUMPERMS; i++) { + if(((oldperm >> i) & 1) != ((newperm >> i) & 1)) { + fprintf (fp, " 站長\033[1;32m%s%s%s%s\033[m的權限\n", + sysopid, + (((oldperm >> i) & 1) ? "\033[1;33m關閉":"\033[1;33m開啟"), + userid, str_permid[i]); + flag++; + } + } + + if(flag) { + clrtobot(); + clear(); + while(!getdata_str(5, 0, "請輸入理由以示負責:", + reason, 60, DOECHO, "看版版主:")); + fprintf(fp, "\n \033[1;37m站長%s修改權限理由是:%s\033[m", + cuser.userid, reason); + fclose(fp); + + sprintf(fhdr.title, "[公安報告] 站長%s修改%s權限報告", + cuser.userid, userid); + strcpy(fhdr.owner, "[系統安全局]"); + append_record("boards/Security/.DIR", &fhdr, sizeof(fhdr)); + } +} + +void post_violatelaw(char* crime, char* police, char* reason, char* result){ + char genbuf[200]; + fileheader_t fhdr; + time_t now; + FILE *fp; + strcpy(genbuf, "boards/Security"); + stampfile(genbuf, &fhdr); + if(!(fp = fopen(genbuf,"w"))) + return; + now = time(NULL); + fprintf(fp, "作者: [Ptt法院] 看板: Security\n" + "標題: [報告] %-20s 違法判決報告\n" + "時間: %s\n" + "\033[1;32m%s\033[m判決:\n \033[1;32m%s\033[m" + "因\033[1;35m%s\033[m行為,\n違反本站站規,處以\033[1;35m%s\033[m,特此公告", + crime, ctime(&now), police, crime, reason, result); + fclose(fp); + sprintf(fhdr.title, "[報告] %-20s 違法判決報告", crime); + strcpy(fhdr.owner, "[Ptt法院]"); + append_record("boards/Security/.DIR", &fhdr, sizeof(fhdr)); + + strcpy(genbuf, "boards/ViolateLaw"); + stampfile(genbuf, &fhdr); + if(!(fp = fopen(genbuf,"w"))) + return; + now = time(NULL); + fprintf(fp, "作者: [Ptt法院] 看板: ViolateLaw\n" + "標題: [報告] %-20s 違法判決報告\n" + "時間: %s\n" + "\033[1;32m%s\033[m判決:\n \033[1;32m%s\033[m" + "因\033[1;35m%s\033[m行為,\n違反本站站規,處以\033[1;35m%s\033[m,特此公告", + crime, ctime(&now), police, crime, reason, result); + fclose(fp); + sprintf(fhdr.title, "[報告] %-20s 違法判決報告", crime); + strcpy(fhdr.owner, "[Ptt法院]"); + + append_record("boards/ViolateLaw/.DIR", &fhdr, sizeof(fhdr)); + +} + +void post_newboard(char* bgroup, char* bname, char* bms){ + char genbuf[256], title[128]; + sprintf(title, "[新版成立] %s", bname); + sprintf(genbuf, "%s 開了一個新版 %s : %s\n\n新任版主為 %s\n\n恭喜*^_^*\n", + cuser.userid, bname, bgroup, bms); + post_msg("Record", title, genbuf, "[系統]"); +} diff --git a/pttbbs/mbbsd/talk.c b/pttbbs/mbbsd/talk.c new file mode 100644 index 00000000..3012b2d2 --- /dev/null +++ b/pttbbs/mbbsd/talk.c @@ -0,0 +1,2663 @@ +/* $Id: talk.c,v 1.1 2002/03/07 15:13:48 in2 Exp $ */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "config.h" +#include "pttstruct.h" +#include "common.h" +#include "perm.h" +#include "modes.h" +#include "proto.h" + +#define QCAST int (*)(const void *, const void *) + +extern userinfo_t *currutmp; +extern char *ModeTypeTable[MAX_MODES]; +extern char *fn_overrides; +extern int usernum; +extern char *msg_sure_ny; +extern char *msg_cancel; +extern unsigned int currstat; +extern char *fn_writelog; +extern FILE *fp_writelog; +extern pid_t currpid; +extern int b_lines; /* Screen bottom line number: t_lines-1 */ +extern int t_lines, t_columns; /* Screen size / width */ +extern char *fn_talklog; +extern char currauthor[IDLEN + 2]; +extern char *msg_usr_left; +extern char *msg_uid; +extern char *BBSName; +extern int p_lines; /* a Page of Screen line numbers: tlines-4 */ +extern char fromhost[]; +extern char *err_uid; +extern int talkrequest; +extern char *msg_shortulist; +extern char *msg_nobody; +extern boardheader_t *bcache; +extern int curr_idle_timeout; +extern userec_t cuser; +extern userec_t xuser; + + +static char *IdleTypeTable[] = { + "偶在花呆啦", "情人來電", "覓食中", "拜見周公", "假死狀態", "我在思考" +}; +static char *sig_des[] = { + "鬥雞", "聊天", "", "下棋", "象棋", "暗棋" +}; + +#define MAX_SHOW_MODE 3 +#define M_INT 15 /* monitor mode update interval */ +#define P_INT 20 /* interval to check for page req. in + * talk/chat */ +#define BOARDFRI 1 + +typedef struct talkwin_t { + int curcol, curln; + int sline, eline; +} talkwin_t; + +typedef struct pickup_t { + userinfo_t *ui; + time_t idle; + int friend; +} pickup_t; + +extern int bind( /* int,struct sockaddr *, int */ ); +extern char *getuserid(); +extern struct utmpfile_t *utmpshm; +extern int watermode; +extern water_t water[6], *swater[5], *water_which; +extern char *friend_file[8], water_usies; + +/* 記錄 friend 的 user number */ +//#define PICKUP_WAYS 7 //關掉女士優先 +#define PICKUP_WAYS 6 + +static int pickup_way = 0; +static char *fcolor[11] = { + "", "\033[36m", "\033[32m", "\033[1;32m", + "\033[33m", "\033[1;33m", "\033[1;37m", "\033[1;37m", + "\033[31m", "\033[1;35m", "\033[1;36m" +}; +static char save_page_requestor[40]; +static char page_requestor[40]; +static char description[30]; +static FILE *flog; + + +char *modestring(userinfo_t * uentp, int simple) { + static char modestr[40]; + static char *notonline = "不在站上"; + register int mode = uentp->mode; + register char *word; + int fri_stat; + +/* for debugging */ + if (mode >= MAX_MODES) + { + syslog(LOG_WARNING, "what!? mode = %d", mode); + word = ModeTypeTable[mode % MAX_MODES]; + } + else + word = ModeTypeTable[mode]; + fri_stat = friend_stat(currutmp, uentp); + if (!(HAS_PERM(PERM_SYSOP) || HAS_PERM(PERM_SEECLOAK)) && + ( + (uentp->invisible || (fri_stat & HRM)) && + !((fri_stat & HFM) && (fri_stat & HRM)) + ) + ) + return notonline; + else if (mode == EDITING) + { + sprintf(modestr, "E:%s", + ModeTypeTable[uentp->destuid < EDITING ? uentp->destuid : + EDITING]); + word = modestr; + } + else if (!mode && *uentp->chatid == 1) + { + if (!simple) + sprintf(modestr, "回應 %s", getuserid(uentp->destuid)); + else + sprintf(modestr, "回應呼叫"); + } + else if (!mode && *uentp->chatid == 2) + if (uentp->msgcount < 10) + { + char *cnum[10] = + {"", "一", "兩", "三", "四", "五", "六", "七", + "八", "九"}; + sprintf(modestr, "中%s顆水球", cnum[uentp->msgcount]); + } + else + sprintf(modestr, "不行了 @_@"); + else if (!mode && *uentp->chatid == 3) + sprintf(modestr, "水球準備中"); + else if (!mode) + return (uentp->destuid == 6) ? uentp->chatid : + IdleTypeTable[(0 <= uentp->destuid && uentp->destuid < 6) ? + uentp->destuid : 0]; + else if (simple) + return word; + else if (uentp->in_chat && mode == CHATING) + sprintf(modestr, "%s (%s)", word, uentp->chatid); + else if (mode == TALK) + { + if (!isvisible_uid(uentp->destuid))/* Leeym 對方(紫色)隱形 */ + sprintf(modestr, "%s", "交談 空氣");/* Leeym 大家自己發揮吧! */ + else + sprintf(modestr, "%s %s", word, getuserid(uentp->destuid)); + } + else if (mode == M_FIVE) + { + if (!isvisible_uid(uentp->destuid)) + sprintf(modestr, "%s", "五子棋 空氣"); + else + sprintf(modestr, "%s %s", word, getuserid(uentp->destuid)); + } + else if (mode == CHC) + { + if (isvisible_uid(uentp->destuid)) + sprintf(modestr, "%s", "下象棋"); + else + sprintf(modestr, "下象棋 %s", getuserid(uentp->destuid)); + } + else if (mode != PAGE && mode != TQUERY) + return word; + else + sprintf(modestr, "%s %s", word, getuserid(uentp->destuid)); + + return (modestr); +} + +int set_friend_bit(userinfo_t * me, userinfo_t * ui) { + int unum, *myfriends, hit=0, n; + +/* 判斷對方是否為我的朋友 ? */ + unum = ui->uid; + myfriends = me->friend; + while ((n = *myfriends++)) + { + if (unum == n) + { + hit = IFH; + break; + } + } + +/* 判斷我是否為對方的朋友 ? */ + myfriends = ui->friend; + while ((unum = *myfriends++)) + { + if (unum == me->uid) + { + hit |= HFM; + break; + } + } + +/* 判斷對方是否為我的仇人 ? */ + + unum = ui->uid; + myfriends = me->reject; + while ((n = *myfriends++)) + { + if (unum == n) + { + hit |= IRH; + break; + } + } + +/* 判斷我是否為對方的仇人 ? */ + myfriends = ui->reject; + while ((unum = *myfriends++)) + { + if (unum == me->uid) + { + hit |= HRM; + break; + } + } + return hit; +} +int reverse_friend_stat(int stat) +{ + int stat1=0; + if(stat & IFH) + stat1 |=HFM; + if(stat & IRH) + stat1 |=HRM; + if(stat & HFM) + stat1 |=IFH; + if(stat & HRM) + stat1 |=IRH; + if(stat & IBH) + stat1 |=IBH; + return stat1; +} + +int login_friend_online(){ + userinfo_t *uentp; + int i, stat, stat1; + int offset=(int) (currutmp - &utmpshm->uinfo[0]); + for (i=0;inumber && currutmp->friendtotalsorted[utmpshm->currsorted][0][i]); + if(uentp && uentp->uid && (stat=set_friend_bit(currutmp,uentp))) + { + stat1=reverse_friend_stat(stat); + stat <<= 24; + stat |= (int) (uentp - &utmpshm->uinfo[0]); + currutmp->friend_online[currutmp->friendtotal++]=stat; + if(uentp!=currutmp && uentp->friendtotalfriend_online[uentp->friendtotal++]=stat1; + } + } + } + return 0; +} + +int logout_friend_online(){ + int i, j, k; + int offset=(int) (currutmp - &utmpshm->uinfo[0]); + userinfo_t *ui; + while(currutmp->friendtotal) + { + i = currutmp->friendtotal-1; + j = (currutmp->friend_online[i] & 0xFFFFFF); + currutmp->friend_online[i]=0; + ui = &utmpshm->uinfo[j]; + if(ui->pid && ui!=currutmp) + { + for(k=0; kfriendtotal && + (int)(ui->friend_online[k] & 0xFFFFFF) !=offset; k++); + if(kfriendtotal) + { + ui->friendtotal--; + ui->friend_online[k]=ui->friend_online[ui->friendtotal]; + ui->friend_online[ui->friendtotal]=0; + } + } + currutmp->friendtotal--; + currutmp->friend_online[currutmp->friendtotal]=0; + } + return 0; +} + + +int friend_stat(userinfo_t *me, userinfo_t * ui) +{ + int i, j, hit=0; +/* 看板好友 */ + if (me->brc_id && ui->brc_id == me->brc_id) + { + hit = IBH; + } + for(i=0;me->friend_online[i];i++) + { + j = (me->friend_online[i] & 0xFFFFFF); + if(ui == &utmpshm->uinfo[j]) + { + hit |= me->friend_online[i] >>24; + break; + } + } + if (PERM_HIDE(ui)) + return hit & ST_FRIEND; + return hit; +} + +int isvisible_stat(userinfo_t * me, userinfo_t * uentp, int fri_stat) { + if (uentp->userid[0] == 0) + return 0; + + if (PERM_HIDE(uentp) && !(PERM_HIDE(me)))/* 對方紫色隱形而你沒有 */ + return 0; + else if ((me->userlevel & PERM_SYSOP) || + ((fri_stat & HRM) && (fri_stat & HFM))) /* 站長看的見任何人 */ + return 1; + + if (uentp->invisible && !(me->userlevel & PERM_SEECLOAK)) return 0; + + return (fri_stat & HRM) ? 0 : 1; +} + +int isvisible(userinfo_t * me, userinfo_t * uentp) { + return isvisible_stat(currutmp, uentp, friend_stat(me, uentp)); +} + +int isvisible_uid(int tuid){ + userinfo_t *uentp; + + if(!tuid || !(uentp = search_ulist(tuid))) + return 1; + return isvisible(currutmp, uentp); +} + +/* 真實動作 */ +static void my_kick(userinfo_t * uentp) { + char genbuf[200]; + + getdata(1, 0, msg_sure_ny, genbuf, 4, LCECHO); + clrtoeol(); + if (genbuf[0] == 'y') + { + sprintf(genbuf, "%s (%s)", uentp->userid, uentp->username); + log_usies("KICK ", genbuf); + if((uentp->pid <= 0 || kill(uentp->pid, SIGHUP) == -1) && (errno == ESRCH)) + purge_utmp(uentp); + outs("踢出去囉"); + } + else + outs(msg_cancel); + pressanykey(); +} + +static void chicken_query(char *userid) { + char buf[100]; + + if (getuser(userid)) + { + if (xuser.mychicken.name[0]) + { + time_diff(&(xuser.mychicken)); + if (!isdeadth(&(xuser.mychicken))) + { + show_chicken_data(&(xuser.mychicken), NULL); + sprintf(buf, "\n\n以上是 %s 的寵物資料..", userid); + outs(buf); + } + } + else + { + move(1, 0); + clrtobot(); + sprintf(buf, "\n\n%s 並沒有養寵物..", userid); + outs(buf); + } + pressanykey(); + } +} + +int my_query(char *uident) { + userec_t muser; + int tuid, i, fri_stat=0; + unsigned long int j; + userinfo_t *uentp; + static const char *money[10] = + {"債台高築", "赤貧", "清寒", "普通", "小康", + "小富", "中富", "大富翁", "富可敵國", "比爾蓋\天"}, + *sex[8] = + {MSG_BIG_BOY, MSG_BIG_GIRL, + MSG_LITTLE_BOY, MSG_LITTLE_GIRL, + MSG_MAN, MSG_WOMAN, MSG_PLANT, MSG_MIME}; + + + if ((tuid = getuser(uident))) + { + memcpy(&muser, &xuser, sizeof(muser)); + move(1, 0); + clrtobot(); + move(1, 0); + setutmpmode(TQUERY); + currutmp->destuid = tuid; + + j = muser.money; + for (i = 0; i < 10 && j > 10; i++) + j /= 10; + prints("《ID暱稱》%s(%s)%*s《經濟狀況》%s\n", + muser.userid, + muser.username, + 26 - strlen(muser.userid) - strlen(muser.username), "", + money[i]); + prints("《上站次數》%d次", muser.numlogins); + move(2, 40); + prints("《文章篇數》%d篇\n", muser.numposts); + + if((uentp = (userinfo_t *) search_ulist(tuid))) + fri_stat=friend_stat(currutmp, uentp); + prints("\033[1;33m《目前動態》%-28.28s\033[m", + (uentp && isvisible_stat(currutmp, uentp, fri_stat)) ? + modestring(uentp, 0) : "不在站上"); + + outs(((uentp && uentp->mailalert) || load_mailalert(muser.userid)) + ? "《私人信箱》有新進信件還沒看\n" : + "《私人信箱》所有信件都看過了\n"); + prints("《上次上站》%-28.28s《上次故鄉》%s\n", + Cdate(&muser.lastlogin), + (muser.lasthost[0] ? muser.lasthost : "(不詳)")); + if ((uentp && fri_stat&HFM) || HAS_PERM(PERM_SYSOP)) + prints("《 性 別 》%-28.28s《私有財產》%ld 銀兩\n", + sex[muser.sex % 8], + muser.money); + prints("《五子棋戰績》%3d 勝 %3d 敗 %3d 和 " + "《象棋戰績》%3d 勝 %3d 敗 %3d 和", + muser.five_win, muser.five_lose, muser.five_tie, + muser.chc_win, muser.chc_lose, muser.chc_tie); + showplans(uident); + pressanykey(); + return FULLUPDATE; + } + return DONOTHING; +} + +static char t_last_write[200] = ""; + +void water_scr(water_t **currwater, int which, char type) +{ + if( type == 1 ){ + int i; + int colors[] = {33, 37, 33, 37, 33}; + move(8 + which, 28);prints(" "); + move(8 + which, 28); + prints("\033[1;37;45m %-14s \033[0m", currwater[which]->userid); + for( i = 0 ; i < 5 ; ++i ){ + move(16 + i, 4); + prints(" "); + move(16 + i, 4); + if( currwater[which]->msg[ (currwater[which]->top-i+4) % 5 ].last_call_in[0] != 0 ) + prints("\033[0m \033[1;%d;44m★%-64s\033[0m \n", + colors[i], + currwater[which]->msg[ (currwater[which]->top-i+4) % 5 ].last_call_in); + else + prints("\033[0m \n"); + } + move(0, 0);prints(" "); + move(0, 0); + prints("\033[0m反擊 %s:", currwater[which]->userid); + clrtoeol(); + move(0, strlen(currwater[which]->userid) + 6); + } + else{ + move(8 + which, 28); + prints("123456789012345678901234567890"); + // refresh(); + move(8 + which, 28); + prints("\033[1;37;44m %-13s \033[0m", currwater[which]->userid); + // refresh(); + } +} + +void my_write2(void) +{ + int i, ch, currstat0, currwater_usies; + char genbuf[256], msg[80], done = 0, c0, which; + water_t *tw, *currwater[5]; + unsigned char mode0; + + watermode = 0; + currstat0 = currstat; + c0 = currutmp->chatid[0]; + mode0 = currutmp->mode; + currutmp->mode = 0; + currutmp->chatid[0] = 3; + currstat = XMODE; + + // init screen + memcpy(currwater, swater, sizeof(water_t*) * 5); + currwater_usies = water_usies; + move(7, 28); + prints("\033[1;33;46m ↑ 水球反擊對象 ↓\033[0m"); + for( i = 0 ; i < 5 ; ++i ) + if( currwater[i] == NULL || currwater[i]->pid == 0 ) + break; + else + water_scr(currwater, i, 0); + move(15, 4); + prints("\033[0m \033[1;35m◇\033[1;36m────────────────" + "─────────────────\033[1;35m◇\033[0m "); + move(22, 4); + prints(" \033[1;35m◇\033[1;36m────────────────" + "─────────────────\033[1;35m◇\033[0m "); + move(21, 4);prints(" "); + move(21, 4); + prints("\033[0m \033[1;37;46m%-66s\033[0m \n", t_last_write); + water_scr(currwater, 0, 1); + refresh(); + + which = 0; + do{ + switch( (ch = igetkey()) ){ + case Ctrl('T'): + case KEY_UP: + if( currwater_usies != 1 ){ + water_scr(currwater, which, 0); + which = (which - 1 + currwater_usies) % currwater_usies; + water_scr(currwater, which, 1); + refresh(); + } + break; + + case KEY_DOWN: + case Ctrl('R'): + if( currwater_usies != 1 ){ + water_scr(currwater, which, 0); + which = (which + 1 + currwater_usies) % currwater_usies; + water_scr(currwater, which, 1); + refresh(); + } + break; + + case KEY_LEFT: + done = 1; + break; + + default: + done = 1; + watermode = 1; + tw = currwater[(int)which]; + + if( ch != '\r' && ch != '\n' ){ + msg[0] = ch, msg[1] = 0; + } + else + msg[0] = 0; + move(0, 0);prints("\033[m"); clrtoeol(); + refresh(); + sprintf(genbuf, "攻擊 %s:", tw->userid); + if( !oldgetdata(0, 0, genbuf, msg, + 80-strlen(tw->userid)-6, DOECHO) ) + break; + + my_write(tw->pid, msg, tw->userid, 4); + break; + } + } while( !done ); + + watermode = -1; + currstat = currstat0; + currutmp->chatid[0] = c0; + currutmp->mode = mode0; +} + +/* + 被呼叫的時機: + 1. 丟群組水球 flag = 1 (pre-edit) + 2. 回水球 flag = 0 + 3. 上站aloha flag = 2 (pre-edit) + 4. 廣播 flag = 3 if SYSOP, otherwise flag = 1 (pre-edit) + 5. 丟水球 flag = 0 + 6. my_write2 flag = 4 (pre-edit) but confirm +*/ +int my_write(pid_t pid, char *prompt, char *id, int flag) { + int len, currstat0 = currstat, fri_stat; + char msg[80], destid[IDLEN + 1]; + char genbuf[200], buf[200], c0 = currutmp->chatid[0]; + unsigned char mode0 = currutmp->mode; + time_t now; + struct tm *ptime; + userinfo_t *uin; + uin = (userinfo_t *)search_ulist_pid(pid); + strcpy(destid, id); + + if(!uin && !(flag == 0 && water_which->count> 0)) { + outmsg("\033[1;33;41m糟糕! 對方已落跑了(不在站上)! \033[37m~>_<~\033[m"); + clrtoeol(); + refresh(); + watermode = -1; + return 0; + } + currutmp->mode = 0; + currutmp->chatid[0] = 3; + currstat = XMODE; + + time(&now); + ptime = localtime(&now); + + if(flag == 0) { + /* 一般水球 */ + watermode = 0; + if(!(len = getdata(0, 0, prompt, msg, 56, DOECHO))) { + outmsg("\033[1;33;42m算了! 放你一馬...\033[m"); + clrtoeol(); + refresh(); + currutmp->chatid[0] = c0; + currutmp->mode = mode0; + currstat = currstat0; + watermode = -1; + return 0; + } + + if(watermode > 0) { + int i; + + i = (water_which->top- watermode + MAX_REVIEW) % MAX_REVIEW; + uin = (userinfo_t *)search_ulist_pid(water_which->msg[i].pid); + strcpy(destid, water_which->msg[i].userid); + } + } else { + /* pre-edit 的水球 */ + strcpy(msg, prompt); + len = strlen(msg); + } + + watermode = -1; + strip_ansi(msg, msg, 0); + if(uin && *uin->userid && (flag == 0 || flag == 4)) { + sprintf(buf, "丟給 %s : %s [Y/n]?", uin->userid, msg); + getdata(0, 0, buf, genbuf, 3, LCECHO); + if(genbuf[0] == 'n') { + outmsg("\033[1;33;42m算了! 放你一馬...\033[m"); + clrtoeol(); + refresh(); + currutmp->chatid[0] = c0; + currutmp->mode = mode0; + currstat = currstat0; + watermode = -1; + return 0; + } + } + + if(!uin || !*uin->userid || strcasecmp(destid, uin->userid)) { + outmsg("\033[1;33;41m糟糕! 對方已落跑了(不在站上)! \033[37m~>_<~\033[m"); + clrtoeol(); + refresh(); + currutmp->chatid[0] = c0; + currutmp->mode = mode0; + currstat = currstat0; + return 0; + } + + fri_stat=friend_stat(currutmp, uin); + time(&now); + if(flag != 2) { /* aloha 的水球不用存下來 */ + /* 存到自己的水球檔 */ + if(!fp_writelog) + { + sethomefile(genbuf, cuser.userid, fn_writelog); + fp_writelog = fopen(genbuf, "a"); + } + if(fp_writelog) { + fprintf(fp_writelog, "To %s: %s [%s]\n", + uin->userid, msg, Cdatelite(&now)); + snprintf(t_last_write, 66, "To %s: %s", uin->userid, msg); + } + } + + if(flag == 3 && uin->msgcount) { + /* 不懂 */ + uin->destuip = currutmp - &utmpshm->uinfo[0]; + uin->sig = 2; + if(uin->pid > 0) kill(uin->pid, SIGUSR1); + } else if(flag != 2 && + !HAS_PERM(PERM_SYSOP) && + (uin->pager == 3 || + uin->pager == 2 || + (uin->pager == 4 && + !(fri_stat & HFM)))) + outmsg("\033[1;33;41m糟糕! 對方防水了! \033[37m~>_<~\033[m"); + else { + if(uin->msgcount < MAX_MSGS) { + unsigned char pager0 = uin->pager; + + uin->pager = 2; + uin->msgs[uin->msgcount].pid = currpid; + strcpy(uin->msgs[uin->msgcount].userid, cuser.userid); + strcpy(uin->msgs[uin->msgcount++].last_call_in, msg); + uin->pager = pager0; + } else if (flag != 2) + outmsg("\033[1;33;41m糟糕! 對方不行了! (收到太多水球) \033[37m@_@\033[m"); + + if(uin->msgcount == 1 && (uin->pid <= 0 || kill(uin->pid, SIGUSR2) == -1) && flag != 2) + outmsg("\033[1;33;41m糟糕! 沒打中! \033[37m~>_<~\033[m"); + else if(uin->msgcount == 1 && flag != 2) + outmsg("\033[1;33;44m水球砸過去了! \033[37m*^o^*\033[m"); + else if(uin->msgcount > 1 && uin->msgcount < MAX_MSGS && flag != 2) + outmsg("\033[1;33;44m再補上一粒! \033[37m*^o^*\033[m"); + } + + clrtoeol(); + refresh(); + + currutmp->chatid[0] = c0; + currutmp->mode = mode0; + currstat = currstat0; + return 1; +} +void t_display_new() { + static int t_display_new_flag=0; + int i, off=2; + if (t_display_new_flag) + return; + else + t_display_new_flag = 1; + + if( WATERMODE(WATER_ORIG) ) + water_which = &water[0]; + else + off =3; + + if (water[0].count && watermode > 0){ + move(1, 0); + outs("───────水─球─回─顧───"); + outs(WATERMODE(WATER_ORIG) ? + "──────用[Ctrl-R Ctrl-T]鍵切換─────" : + "用[Ctrl-R Ctrl-T Ctrl-E Ctrl-W ]鍵切換────"); + if( WATERMODE(WATER_NEW) ){ + move(2, 0); + clrtoeol(); + for (i = 0; i<6 ; i++){ + if(i>0) + prints("%s%-13.13s\033[m", + swater[i-1]==water_which?"\033[1;33;47m ": + " ", + swater[i-1] ? swater[i-1]->userid:""); + else + prints("%s 全部 \033[m", + water_which==&water[0]?"\033[1;33;45m ": + " "); + } + } + + for (i = 0; i < water_which->count; i++){ + int a = (water_which->top - i - 1 + MAX_REVIEW) % MAX_REVIEW, + len = 75-strlen(water_which->msg[a].last_call_in) + -strlen(water_which->msg[a].userid); + if(len<0) len=0; + + move(i + (WATERMODE(WATER_ORIG)?2:3), 0); + clrtoeol(); + if (watermode - 1 != i) + prints("\033[1;33;46m %s \033[37;45m %s \033[m%*s", + water_which->msg[a].userid, + water_which->msg[a].last_call_in, len, + ""); + else + prints("\033[1;44m>\033[1;33;47m%s " + "\033[37;45m %s \033[m%*s", + water_which->msg[a].userid, + water_which->msg[a].last_call_in, + len,""); + } + + if (t_last_write[0]){ + move(i + off, 0); + clrtoeol(); + prints(t_last_write); + i++; + } + move(i + off, 0); + outs("──────────────────────" + "─────────────────"); + if( WATERMODE(WATER_NEW)) + while( i++ <= water[0].count ) { + move(i + off, 0); + clrtoeol(); + } + } + + t_display_new_flag = 0; +} +#if 0 +void t_display_new() { + int i, which=water_which; + char buf[200]; + + if (t_display_new_flag) + return; + else + t_display_new_flag = 1; + + if (oldmsg_count && watermode > 0) + { + move(1, 0); + outs( + "───────水─球─回─顧─────────" + "用[Ctrl-R Ctrl-T]鍵切換─────"); + move(2, 0); + prints(" |"); + for (i = 0; i<5 && water[i].pid != 0; i++) + prints(" %s%13.13s \033[m|",which==i?"\033[1;33m":"", + water[i].userid); + + for( i = 0 ; i < 5 && + water[which].msg[ (water[which].msgtop-i+4) % 5 ][0] != 0; ++i ){ + move(3 + i, 0); + if (watermode - 1 != i) + sprintf(buf, "\033[1;33;46m %s \033[37;45m %s \033[m", + water[which].userid, + water[which].msg[ (water[which].msgtop-i+4) % 5 ]); + else + sprintf(buf, "\033[1;44m>\033[1;33;47m%s \033[37;45m %s \033[m", + water[which].userid, + water[which].msg[ (water[which].msgtop-i+4) % 5 ]); + } + /* + for (i = 0; i < oldmsg_count; i++) + { + int a = (water[water_which].top - i - 1 + MAX_REVIEW) % MAX_REVIEW; + + move(i + 3, 0); + clrtoeol(); + if (watermode - 1 != i) + sprintf(buf, "\033[1;33;46m %s \033[37;45m %s \033[m", + oldmsg[a].userid, oldmsg[a].last_call_in); + else + sprintf(buf, "\033[1;44m>\033[1;33;47m%s " + "\033[37;45m %s \033[m", + oldmsg[a].userid, oldmsg[a].last_call_in); + outs(buf); + } +*/ + if (t_last_write[0]) + { + move(i + 3, 0); + clrtoeol(); + outs(t_last_write); + i++; + } + move(i + 3, 0); + outs("───────────────────────" + "─────────────────"); + } + t_display_new_flag = 0; +} +#endif + +int t_display() { + char genbuf[200], ans[4]; + if(fp_writelog) + { fclose(fp_writelog); fp_writelog=NULL;} + setuserfile(genbuf, fn_writelog); + if (more(genbuf, YEA) != -1) + { + getdata(b_lines - 1, 0, "清除(C) 移至備忘錄(M) 保留(R) (C/M/R)?[R]", + ans, 3, LCECHO); + if (*ans == 'm') + { + fileheader_t mymail; + char title[128], buf[80]; + + sethomepath(buf, cuser.userid); + stampfile(buf, &mymail); + + mymail.savemode = 'H'; /* hold-mail flag */ + mymail.filemode = FILE_READ; + strcpy(mymail.owner, "[備.忘.錄]"); + strcpy(mymail.title, "熱線\033[37;41m記錄\033[m"); + sethomedir(title, cuser.userid); + Rename(genbuf, buf); + append_record(title, &mymail, sizeof(mymail)); + } + else if (*ans == 'c') + unlink(genbuf); + return FULLUPDATE; + } + return DONOTHING; +} + +static void do_talk_nextline(talkwin_t * twin) { + twin->curcol = 0; + if (twin->curln < twin->eline) + ++(twin->curln); + else + region_scroll_up(twin->sline, twin->eline); + move(twin->curln, twin->curcol); +} + +static void do_talk_char(talkwin_t * twin, int ch) { + extern screenline_t *big_picture; + screenline_t *line; + int i; + char ch0, buf[81]; + + if (isprint2(ch)) + { + ch0 = big_picture[twin->curln].data[twin->curcol]; + if (big_picture[twin->curln].len < 79) + move(twin->curln, twin->curcol); + else + do_talk_nextline(twin); + outc(ch); + ++(twin->curcol); + line = big_picture + twin->curln; + if (twin->curcol < line->len) + { /* insert */ + ++(line->len); + memcpy(buf, line->data + twin->curcol, 80); + save_cursor(); + do_move(twin->curcol, twin->curln); + ochar(line->data[twin->curcol] = ch0); + for (i = twin->curcol + 1; i < line->len; i++) + ochar(line->data[i] = buf[i - twin->curcol - 1]); + restore_cursor(); + } + line->data[line->len] = 0; + return; + } + + switch (ch) + { + case Ctrl('H'): + case '\177': + if (twin->curcol == 0) + return; + line = big_picture + twin->curln; + --(twin->curcol); + if (twin->curcol < line->len) + { + --(line->len); + save_cursor(); + do_move(twin->curcol, twin->curln); + for (i = twin->curcol; i < line->len; i++) + ochar(line->data[i] = line->data[i + 1]); + line->data[i] = 0; + ochar(' '); + restore_cursor(); + } + move(twin->curln, twin->curcol); + return; + case Ctrl('D'): + line = big_picture + twin->curln; + if (twin->curcol < line->len) + { + --(line->len); + save_cursor(); + do_move(twin->curcol, twin->curln); + for (i = twin->curcol; i < line->len; i++) + ochar(line->data[i] = line->data[i + 1]); + line->data[i] = 0; + ochar(' '); + restore_cursor(); + } + return; + case Ctrl('G'): + bell(); + return; + case Ctrl('B'): + if (twin->curcol > 0) + { + --(twin->curcol); + move(twin->curln, twin->curcol); + } + return; + case Ctrl('F'): + if (twin->curcol < 79) + { + ++(twin->curcol); + move(twin->curln, twin->curcol); + } + return; + case KEY_TAB: + twin->curcol += 8; + if (twin->curcol > 80) + twin->curcol = 80; + move(twin->curln, twin->curcol); + return; + case Ctrl('A'): + twin->curcol = 0; + move(twin->curln, twin->curcol); + return; + case Ctrl('K'): + clrtoeol(); + return; + case Ctrl('Y'): + twin->curcol = 0; + move(twin->curln, twin->curcol); + clrtoeol(); + return; + case Ctrl('E'): + twin->curcol = big_picture[twin->curln].len; + move(twin->curln, twin->curcol); + return; + case Ctrl('M'): + case Ctrl('J'): + line = big_picture + twin->curln; + strncpy(buf, line->data, line->len); + buf[line->len] = 0; + do_talk_nextline(twin); + break; + case Ctrl('P'): + line = big_picture + twin->curln; + strncpy(buf, line->data, line->len); + buf[line->len] = 0; + if (twin->curln > twin->sline) + { + --(twin->curln); + move(twin->curln, twin->curcol); + } + break; + case Ctrl('N'): + line = big_picture + twin->curln; + strncpy(buf, line->data, line->len); + buf[line->len] = 0; + if (twin->curln < twin->eline) + { + ++(twin->curln); + move(twin->curln, twin->curcol); + } + break; + } + trim(buf); + if (*buf) + fprintf(flog, "%s%s: %s%s\n", + (twin->eline == b_lines - 1) ? "\033[1;35m" : "", + (twin->eline == b_lines - 1) ? + getuserid(currutmp->destuid) : cuser.userid, buf, + (ch == Ctrl('P')) ? "\033[37;45m(Up)\033[m" : "\033[m"); +} + +static void do_talk(int fd) { + struct talkwin_t mywin, itswin; + char mid_line[128], data[200]; + int i, datac, ch; + int im_leaving = 0; + FILE *log; + struct tm *ptime; + time_t now; + char genbuf[200], fpath[100]; + + time(&now); + ptime = localtime(&now); + + sethomepath(fpath, cuser.userid); + strcpy(fpath, tempnam(fpath, "talk_")); + flog = fopen(fpath, "w"); + + setuserfile(genbuf, fn_talklog); + + if ((log = fopen(genbuf, "w"))) + fprintf(log, "[%d/%d %d:%02d] & %s\n", + ptime->tm_mon + 1, ptime->tm_mday, ptime->tm_hour, + ptime->tm_min, save_page_requestor); + setutmpmode(TALK); + + ch = 58 - strlen(save_page_requestor); + sprintf(genbuf, "%s【%s", cuser.userid, cuser.username); + i = ch - strlen(genbuf); + if (i >= 0) + i = (i >> 1) + 1; + else + { + genbuf[ch] = '\0'; + i = 1; + } + memset(data, ' ', i); + data[i] = '\0'; + + sprintf(mid_line, "\033[1;46;37m 談天說地 \033[45m%s%s】" + " 與 %s%s\033[0m", data, genbuf, save_page_requestor, data); + + memset(&mywin, 0, sizeof(mywin)); + memset(&itswin, 0, sizeof(itswin)); + + i = b_lines >> 1; + mywin.eline = i - 1; + itswin.curln = itswin.sline = i + 1; + itswin.eline = b_lines - 1; + + clear(); + move(i, 0); + outs(mid_line); + move(0, 0); + + add_io(fd, 0); + + while (1) + { + ch = igetkey(); + if (ch == I_OTHERDATA) + { + datac = recv(fd, data, sizeof(data), 0); + if (datac <= 0) + break; + for (i = 0; i < datac; i++) + do_talk_char(&itswin, data[i]); + } + else + { + if (ch == Ctrl('C')) + { + if (im_leaving) + break; + move(b_lines, 0); + clrtoeol(); + outs("再按一次 Ctrl-C 就正式中止談話囉!"); + im_leaving = 1; + continue; + } + if (im_leaving) + { + move(b_lines, 0); + clrtoeol(); + im_leaving = 0; + } + switch (ch) + { + case KEY_LEFT: /* 把2byte的鍵改為一byte */ + ch = Ctrl('B'); + break; + case KEY_RIGHT: + ch = Ctrl('F'); + break; + case KEY_UP: + ch = Ctrl('P'); + break; + case KEY_DOWN: + ch = Ctrl('N'); + break; + } + data[0] = (char) ch; + if (send(fd, data, 1, 0) != 1) + break; + if (log) + fprintf(log, "%c", (ch == Ctrl('M')) ? '\n' : (char) *data); + do_talk_char(&mywin, *data); + } + } + if (log) + fclose(log); + + add_io(0, 0); + close(fd); + + if (flog) + { + char ans[4]; + extern screenline_t *big_picture; + extern unsigned char scr_lns; + int i; + + time(&now); + fprintf(flog, "\n\033[33;44m離別畫面 [%s] ... \033[m\n", + Cdatelite(&now)); + for (i = 0; i < scr_lns; i++) + fprintf(flog, "%.*s\n", big_picture[i].len, big_picture[i].data); + fclose(flog); + more(fpath, NA); + getdata(b_lines - 1, 0, "清除(C) 移至備忘錄(M). (C/M)?[C]", + ans, 4, LCECHO); + if (*ans == 'm') + { + fileheader_t mymail; + char title[128]; + + sethomepath(genbuf, cuser.userid); + stampfile(genbuf, &mymail); + mymail.savemode = 'H'; /* hold-mail flag */ + mymail.filemode = FILE_READ; + strcpy(mymail.owner, "[備.忘.錄]"); + sprintf(mymail.title, "對話記錄 \033[1;36m(%s)\033[m", + getuserid(currutmp->destuid)); + sethomedir(title, cuser.userid); + Rename(fpath, genbuf); + append_record(title, &mymail, sizeof(mymail)); + } + else + unlink(fpath); + flog = 0; + } + setutmpmode(XINFO); +} + +#define lockreturn(unmode, state) if(lockutmpmode(unmode, state)) return + +static void my_talk(userinfo_t * uin, int fri_stat) { + int sock, msgsock, length, ch, error = 0; + struct sockaddr_in server; + pid_t pid; + char c; + char genbuf[4]; + + unsigned char mode0 = currutmp->mode; + + ch = uin->mode; + strcpy(currauthor, uin->userid); + + if (ch == EDITING || ch == TALK || ch == CHATING || ch == PAGE || + ch == MAILALL || ch == MONITOR || ch == M_FIVE || ch == CHC || + (!ch && (uin->chatid[0] == 1 || uin->chatid[0] == 3)) || + uin->lockmode == M_FIVE || uin->lockmode == CHC) + { + outs("人家在忙啦"); + } + else if (!HAS_PERM(PERM_SYSOP) && + ( + ((fri_stat& HRM) && !(fri_stat& HFM)) || + ((!uin->pager) && !(fri_stat & HFM)) + ) + ) + { + outs("對方關掉呼叫器了"); + } + else if (!HAS_PERM(PERM_SYSOP) && + ( + ((fri_stat & HRM) && !(fri_stat& HFM)) || + uin->pager == 2 + ) + ) + { + outs("對方拔掉呼叫器了"); + } + else if (!HAS_PERM(PERM_SYSOP) && + !(fri_stat & HFM) && uin->pager == 4) + { + outs("對方只接受好友的呼叫"); + } + else if (!(pid = uin->pid) /*|| (kill(pid, 0) == -1) */ ) + { +// resetutmpent(); + outs(msg_usr_left); + } + else + { + showplans(uin->userid); + getdata(2, 0, "要和他(她) (T)談天(F)下五子棋(P)鬥寵物" + "(C)下象棋(D)下暗棋(N)沒事找錯人了?[N] ", genbuf, 4, LCECHO); + switch (*genbuf) + { + case 'y': + case 't': + uin->sig = SIG_TALK; + break; + case 'f': + lockreturn(M_FIVE, LOCK_THIS); + uin->sig = SIG_GOMO; + break; + case 'c': + lockreturn(CHC, LOCK_THIS); + uin->sig = SIG_CHC; + break; + case 'd': + uin->sig = SIG_DARK; + break; + case 'p': + reload_chicken(); + getuser(uin->userid); + if (uin->lockmode == CHICKEN || currutmp->lockmode == CHICKEN) + error = 1; + if (!cuser.mychicken.name[0] || !xuser.mychicken.name[0]) + error = 2; + if (error) + { + outmsg(error == 2 ? "並非兩人都養寵物" : + "有一方的寵物正在使用中"); + bell(); + refresh(); + sleep(1); + return; + } + uin->sig = SIG_PK; + break; + default: + return; + } + + uin->turn = 1; + currutmp->turn = 0; + strcpy(uin->mateid, currutmp->userid); + strcpy(currutmp->mateid, uin->userid); + + sock = socket(AF_INET, SOCK_STREAM, 0); + if (sock < 0) + { + perror("sock err"); + unlockutmpmode(); + return; + } + server.sin_family = PF_INET; + server.sin_addr.s_addr = INADDR_ANY; + server.sin_port = 0; + if (bind(sock, (struct sockaddr *) &server, sizeof(server)) < 0) + { + close(sock); + perror("bind err"); + unlockutmpmode(); + return; + } + length = sizeof(server); + if (getsockname(sock, (struct sockaddr *) &server, &length) < 0) + { + close(sock); + perror("sock name err"); + unlockutmpmode(); + return; + } + currutmp->sockactive = YEA; + currutmp->sockaddr = server.sin_port; + currutmp->destuid = uin->uid; + setutmpmode(PAGE); + uin->destuip = currutmp - &utmpshm->uinfo[0]; + if(pid > 0) kill(pid, SIGUSR1); + clear(); + prints("正呼叫 %s.....\n鍵入 Ctrl-D 中止....", uin->userid); + + listen(sock, 1); + add_io(sock, 5); + while (1) + { + ch = igetch(); + if (ch == I_TIMEOUT) + { + ch = uin->mode; + if (!ch && uin->chatid[0] == 1 && + uin->destuip == currutmp - &utmpshm->uinfo[0]) + { + bell(); + outmsg("對方回應中..."); + refresh(); + } + else if (ch == EDITING || ch == TALK || ch == CHATING || + ch == PAGE || ch == MAILALL || ch == MONITOR || + ch == M_FIVE || ch == CHC || + (!ch && (uin->chatid[0] == 1 || + uin->chatid[0] == 3))) + { + add_io(0, 0); + close(sock); + currutmp->sockactive = currutmp->destuid = 0; + outmsg("人家在忙啦"); + pressanykey(); + unlockutmpmode(); + return; + } + else + { +#ifdef linux + add_io(sock, 20); /* added for linux... achen */ +#endif + move(0, 0); + outs("再"); + bell(); + + uin->destuip = currutmp - &utmpshm->uinfo[0]; + if(pid <= 0 || kill(pid, SIGUSR1) == -1) + { +#ifdef linux + add_io(sock, 20); /* added 4 linux... achen */ +#endif + outmsg(msg_usr_left); + refresh(); + pressanykey(); + unlockutmpmode(); + return; + } + continue; + } + } + + if (ch == I_OTHERDATA) + break; + + if (ch == '\004') + { + add_io(0, 0); + close(sock); + currutmp->sockactive = currutmp->destuid = 0; + unlockutmpmode(); + return; + } + } + + msgsock = accept(sock, (struct sockaddr *) 0, (int *) 0); + if (msgsock == -1) + { + perror("accept"); + unlockutmpmode(); + return; + } + add_io(0, 0); + close(sock); + currutmp->sockactive = NA; + read(msgsock, &c, sizeof c); + + if (c == 'y') + { + sprintf(save_page_requestor, "%s (%s)", + uin->userid, uin->username); + /* gomo */ + switch (uin->sig) + { + case SIG_DARK: + main_dark(msgsock, uin); + break; + case SIG_PK: + chickenpk(msgsock); + break; + case SIG_GOMO: + gomoku(msgsock); + break; + case SIG_CHC: + chc(msgsock); + break; + case SIG_TALK: + default: + do_talk(msgsock); + } + } + else + { + move(9, 9); + outs("【回音】 "); + switch (c) + { + case 'a': + outs("我現在很忙,請等一會兒再 call 我,好嗎?"); + break; + case 'b': + prints("對不起,我有事情不能跟你 %s....", sig_des[uin->sig]); + break; + case 'd': + outs("我要離站囉..下次再聊吧.........."); + break; + case 'c': + outs("請不要吵我好嗎?"); + break; + case 'e': + outs("找我有事嗎?請先來信唷...."); + break; + case 'f': + { + char msgbuf[60]; + + read(msgsock, msgbuf, 60); + prints("對不起,我現在不能跟你 %s,因為\n", sig_des[uin->sig]); + move(10, 18); + outs(msgbuf); + } + break; + case '1': + prints("%s?先拿100銀兩來..", sig_des[uin->sig]); + break; + case '2': + prints("%s?先拿1000銀兩來..", sig_des[uin->sig]); + break; + default: + prints("我現在不想 %s 啦.....:)", sig_des[uin->sig]); + } + close(msgsock); + } + } + currutmp->mode = mode0; + currutmp->destuid = 0; + unlockutmpmode(); + pressanykey(); +} + +/* 選單式聊天介面 */ +#define US_PICKUP 1234 +#define US_RESORT 1233 +#define US_ACTION 1232 +#define US_REDRAW 1231 + +static void t_showhelp() { + clear(); + + outs("\033[36m【 休閒聊天使用說明 】\033[m\n\n" + "(←)(e) 結束離開 (h) 看使用說明\n" + "(↑)/(↓)(n) 上下移動 (TAB) 切換排序方式\n" + "(PgUp)(^B) 上頁選單 ( )(PgDn)(^F) 下頁選單\n" + "(Hm)/($)(Ed) 首/尾 (S) " + "來源/好友描述/戰績 切換\n" + "(m) 寄信 (q/c) " + "查詢網友/寵物\n" + "(r) 閱\讀信件 (l) 看上次熱訊\n" + "(f) 全部/好友列表 (數字) 跳至該使用者\n" + "(p) 切換呼叫器 (g/i) 給錢/切換心情\n" + "(a/d/o) 好友 增加/刪除/修改 (/)(s) 網友ID/暱稱搜尋"); + + if (HAS_PERM(PERM_PAGE)) + { + outs("\n\n\033[36m【 交談專用鍵 】\033[m\n\n" + "(→)(t)(Enter) 跟他/她聊天\n" + "(w) 熱線 Call in\n" + "(b) 對好友廣播 (一定要在好友列表中)\n" + "(^R) 即時回應 (有人 Call in 你時)"); + } + + if (HAS_PERM(PERM_SYSOP)) + { + outs("\n\n\033[36m【 站長專用鍵 】\033[m\n\n"); + if (HAS_PERM(PERM_SYSOP)) + outs("(u)/(H) 設定使用者資料/切換隱形模式\n"); + outs("(R)/(K) 查詢使用者的真實姓名/把壞蛋踢出去\n"); + } + pressanykey(); +} + +static int listcuent(userinfo_t * uentp) { + if((!uentp->invisible || HAS_PERM(PERM_SYSOP) || HAS_PERM(PERM_SEECLOAK))) + AddNameList(uentp->userid); + return 0; +} + +static void creat_list() { + CreateNameList(); + apply_ulist(listcuent); +} + +static int search_pickup(int num, int actor, pickup_t pklist[]) { + char genbuf[IDLEN + 2]; + + move(1, 0); + creat_list(); + namecomplete(msg_uid, genbuf); + if (genbuf[0]) + { + int n = (num + 1) % actor; + while (n != num) + { + if (!strcasecmp(pklist[n].ui->userid, genbuf)) + return n; + if (++n >= actor) + n = 0; + } + } + return -1; +} + +/* Kaede show friend description */ +static char *friend_descript(char *uident) { + static char *space_buf = " "; + static char desc_buf[80]; + char fpath[80], name[IDLEN + 2], *desc, *ptr; + int len, flag; + FILE *fp; + char genbuf[200]; + + setuserfile(fpath, friend_file[0]); + + if ((fp = fopen(fpath, "r"))) + { + sprintf(name, "%s ", uident); + len = strlen(name); + desc = genbuf + 13; + + while ((flag = (int) fgets(genbuf, STRLEN, fp))) + { + if (!memcmp(genbuf, name, len)) + { + if ((ptr = strchr(desc, '\n'))) + ptr[0] = '\0'; + if (desc) + break; + } + } + fclose(fp); + if (desc && flag) + strcpy(desc_buf, desc); + else + return space_buf; + + return desc_buf; + } + else + return space_buf; +} + +static char *descript(int show_mode, userinfo_t * uentp, time_t diff, + fromcache_t * fcache) { + switch (show_mode) + { + case 1: + return friend_descript(uentp->userid); + case 0: + return (((uentp->pager != 2 && uentp->pager != 3 && diff) || + HAS_PERM(PERM_SYSOP)) ? +#ifdef WHERE + uentp->from_alias ? fcache->replace[uentp->from_alias] : + uentp->from +#else + uentp->from +#endif + : "*"); + case 2: + sprintf(description, "%3d/%3d/%3d", uentp->five_win, + uentp->five_lose, uentp->five_tie); + description[20] = 0; + return description; + default: + syslog(LOG_WARNING, "damn!!! what's wrong?? show_mode = %d", + show_mode); + return ""; + } +} + +static int pickup_user_cmp(time_t now, int sortedway, int cmp_fri, + pickup_t pklist[], int *bfriends_number, int *ifh_number, + int *hfm_number,int *irh_number, char *keyword) +{ + int i, fri_stat, is_friend, count=0, diff; + userinfo_t *uentp; + for (i=0;inumber;i++) + { + uentp = (utmpshm->sorted[utmpshm->currsorted][sortedway][i]); + if (!uentp || !uentp->pid) continue; + fri_stat = friend_stat(currutmp, uentp); + if(uentp->uid==currutmp->uid) + fri_stat = fri_stat|IFH|HFM; + is_friend = (fri_stat & IRH) && !(fri_stat & IFH) ? 0 : + fri_stat & ST_FRIEND; + if (!isvisible_stat(currutmp, uentp, fri_stat) || + ((cmp_fri==1 && !is_friend) || + (cmp_fri==-1 && is_friend)) || + (keyword[0] && !strcasestr(uentp->username,keyword)) + ) continue; + if (bfriends_number && fri_stat & IBH) (*bfriends_number)++; + if (ifh_number && fri_stat & IFH) (*ifh_number)++; + if (hfm_number && fri_stat & HFM) (*hfm_number)++; + if (irh_number && fri_stat & IRH) (*irh_number)++; +#ifdef SHOW_IDLE_TIME + diff = now - uentp->lastact; +#ifdef DOTIMEOUT + /* prevent fault /dev mount from kicking out users */ + if ((diff > curr_idle_timeout + 10) && + (diff < 60 * 60 * 24 * 5)) + { + if ((uentp->pid <= 0 || kill(uentp->pid, SIGHUP) == -1) && + (errno == ESRCH)) + purge_utmp(uentp); + continue; + } +#endif + pklist[count].idle = diff; +#endif + pklist[count].friend = fri_stat; + pklist[count].ui = uentp; + count++; + } + return count; +} + +static int cmputmpfriend(const void *i, const void *j) +{ + if((((pickup_t*)j)->friend&ST_FRIEND)==(((pickup_t*)i)->friend&ST_FRIEND)) + return strcasecmp( ((pickup_t*)i)->ui->userid, + ((pickup_t*)j)->ui->userid); + else + return (((pickup_t*)j)->friend&ST_FRIEND) - + (((pickup_t*)i)->friend&ST_FRIEND); +} + +static void pickup_user() { + static int real_name = 0; + static int show_mode = 0; + static int show_uid = 0; + static int show_board = 0; + static int show_pid = 0; + static int num = 0; + char genbuf[200]; + +#ifdef WHERE + extern struct fromcache_t *fcache; +#endif + + register userinfo_t *uentp; + register pid_t pid0 = 0; /* Ptt 定位 */ + register int id0 = 0; /* US_PICKUP時的游標用 */ + register int state = US_PICKUP, ch; + register int actor = 0, head, foot; + int fri_stat, bfriends_number, ifh_number, irh_number, hfm_number; + int savemode = currstat; + int i, sortedway; /* 只是loop有用到 */ + time_t diff, freshtime; + pickup_t pklist[USHM_SIZE]; /* parameter Ptt註 */ +/* num : 現在的游標位 */ +/* foot: 此頁的腳腳 */ + char buf[20],keyword[13]=""; /* actor:共有多少user */ + char pagerchar[5] = "* -Wf"; + char *msg_pickup_way[PICKUP_WAYS] = + { + "嗨! 朋友", + "網友代號", + "網友動態", + "發呆時間", + "來自何方", + "五子棋 ", +// "女士優先" + }; + char *MODE_STRING[MAX_SHOW_MODE] = + { + "故鄉", + "好友描述", + "五子棋戰績" + }; + char + *Mind[] = + {" ", + "^-^", "^_^", "Q_Q", "@_@", "/_\\", "=_=", "-_-", "-.-", ">_<", + "-_+", "!_!", "o_o", "z_Z", "O_O", "O.O", "$_$", "^*^", "O_<", + "喜!", "怒!", "哀!", "樂!", ":) ", ":( ", ":~ ", ":q ", ":O ", + ":D ", ":p ", ";) ", ":> ", ";> ", ":< ", ":)~", ":D~", ">< ", + "^^;", "^^|", "哭;", NULL}; + + while (1) + { + if (utmpshm->uptime > freshtime || state == US_PICKUP || + state ==US_RESORT) + { + state = US_PICKUP; + time(&freshtime); + ifh_number=hfm_number=irh_number=bfriends_number = actor = ch = 0; + if(pickup_way==0) + sortedway=0; + else + sortedway=pickup_way-1; + + //qsort(pklist,actor,sizeof(pickup_t),cmputmpfriend); + if(pickup_way==0 || (cuser.uflag & FRIEND_FLAG)) + { + actor=pickup_user_cmp(freshtime, sortedway, 1, + pklist, &bfriends_number, &ifh_number, &hfm_number, + NULL,keyword); + if(sortedway==0) + qsort(pklist,actor,sizeof(pickup_t),cmputmpfriend); + if(!(cuser.uflag & FRIEND_FLAG)) + actor=pickup_user_cmp(freshtime, sortedway, -1, + pklist+actor, NULL, NULL, NULL, &irh_number, + keyword); + } + else + { + actor=pickup_user_cmp(freshtime, sortedway, 0, + pklist, &bfriends_number, &ifh_number, &hfm_number, + &irh_number, keyword); + } + + + if (!actor) + { + if(keyword[0]) + { + mprints(b_lines-1,0, + "搜尋不到任何人 !!"); + keyword[0]=0; + pressanykey(); + continue; + } + getdata(b_lines - 1, 0, + "你的朋友還沒上站,要看看一般網友嗎(Y/N)?[Y]", + genbuf, 4, LCECHO); + if (genbuf[0] != 'n') + { + cuser.uflag &= ~FRIEND_FLAG; + continue; + } + return; + } + } + if (state >= US_ACTION) + { + showtitle((cuser.uflag & FRIEND_FLAG) ? "好友列表" : "休閒聊天", + BBSName); + prints(" 排序:[%s] 上站人數:%-4d\033[1;32m我的朋友:%-3d" + "\033[33m與我為友:%-3d\033[36m板友:%-4d\033[31m壞人:" + "%-2d\033[m\n" + "\033[7m %s P%c代號 %-17s%-17s%-13s%-10s\033[m\n", + msg_pickup_way[pickup_way], actor, ifh_number, + hfm_number, bfriends_number, irh_number, + show_uid ? "UID" : "No.", + (HAS_PERM(PERM_SEECLOAK) || HAS_PERM(PERM_SYSOP)) ? 'C' : ' ', + real_name ? "姓名" : "暱稱", + MODE_STRING[show_mode], + show_board ? "Board" : "動態", + show_pid ? " PID" : "備註 發呆" + ); + } + else + { + move(3, 0); + clrtobot(); + } + if (pid0) + for (ch = 0; ch < actor; ch++) + { + if (pid0 == (pklist[ch].ui)->pid && + id0 == 256 * pklist[ch].ui->userid[0] + + pklist[ch].ui->userid[1]) + { + num = ch; + } + } + if (num < 0) + num = 0; + else if (num >= actor) + num = actor - 1; + head = (num / p_lines) * p_lines; + foot = head + p_lines; + if (foot > actor) + foot = actor; + for (ch = head; ch < foot; ch++) + { + uentp = pklist[ch].ui; + + if (!uentp->pid) + { + prints("%5d < 離站中..>\n",ch); + continue; + } +#ifdef SHOW_IDLE_TIME + diff = pklist[ch].idle; + if (diff > 59990) diff = 59990; /* Doma: 以免一大串的發呆時間 */ + if (diff > 0) + sprintf(buf, "%3ld'%02ld", diff / 60, diff % 60); + else + buf[0] = '\0'; +#else + buf[0] = '\0'; +#endif + i = pklist[ch].friend; +#ifdef SHOWPID + if (show_pid) + sprintf(buf, "%6d", uentp->pid); +#endif + if (PERM_HIDE(uentp)) + state = 9; + else if(currutmp == uentp) + state =10; + else if(i & IRH && !(i & IFH)) + state = 8; + else + state =(i&ST_FRIEND)>>2; + diff = uentp->pager & !(i&HRM); + prints("%5d %c%c%s%-13s%-17.16s\033[m%-17.16s%-13.13s" + "\33[33m%-4.4s\33[m%s\n", +#ifdef SHOWUID + show_uid ? uentp->uid : +#endif + (ch + 1), + (i & HRM) ? 'X' : + pagerchar[uentp->pager % 5], + (uentp->invisible ? ')' : ' '), + fcolor[state], + /* %s */ + uentp->userid, + + /* %-13s 暱稱 */ +#ifdef REALINFO + real_name ? uentp->realname : +#endif + uentp->username, + /* %-17.16s 故鄉 */ + descript(show_mode, uentp, diff, fcache), + + /* %-17.16s 看板 */ +#ifdef SHOWBOARD + show_board ? (uentp->brc_id == 0 ? "" : + bcache[uentp->brc_id - 1].brdname) : +#endif + /* %-13.13s */ + modestring(uentp, 0), + /* %4s 備註 */ + ((uentp->userlevel & PERM_VIOLATELAW) ? "通緝" : + (uentp->birth ? "壽星" : + Mind[uentp->mind])), + /* %s 發呆 */ + buf); + } + if (state == US_PICKUP) + continue; + + move(b_lines, 0); + outs("\033[31;47m(TAB/f)\033[30m排序/好友 \033[31m(t)\033[30m聊天 " + "\033[31m(a/d/o)\033[30m交友 \033[31m(q)\033[30m查詢 " + "\033[31m(w)\033[30m水球 \033[31m(m)\033[30m寄信 \033[31m(h)" + "\033[30m線上輔助 \033[m"); + state = 0; + while (!state) + { + ch = cursor_key(num + 3 - head, 0); + if (ch == KEY_RIGHT || ch == '\n' || ch == '\r') + ch = 't'; + + switch (ch) + { + case KEY_LEFT: + case 'e': + case 'E': + if(!keyword[0]) return; + keyword[0]=0; + state = US_PICKUP; + break; + + case KEY_TAB: + pickup_way = (pickup_way + 1) % PICKUP_WAYS; + state = US_RESORT; + num = 0; + break; + + case KEY_DOWN: + case 'n': + case 'j': + if (++num < actor) + { + if (num >= foot) + state = US_REDRAW; + break; + } + case '0': + case KEY_HOME: + num = 0; + if (head) + state = US_REDRAW; + break; + case 'H': + if (HAS_PERM(PERM_SYSOP)) + { + currutmp->userlevel ^= PERM_DENYPOST; + state = US_REDRAW; + } + break; + case 'D': + if (HAS_PERM(PERM_SYSOP)) + { + char buf[100]; + + sprintf(buf, "代號 [%s]:", currutmp->userid); + if (!getdata(1, 0, buf, currutmp->userid, IDLEN + 1, + DOECHO)) + strcpy(currutmp->userid, cuser.userid); + state = US_REDRAW; + } + break; + case 'F': + if (HAS_PERM(PERM_SYSOP)) + { + char buf[100]; + + sprintf(buf, "故鄉 [%s]:", currutmp->from); + if (!getdata(1, 0, buf, currutmp->from, 17, DOECHO)) + strncpy(currutmp->from, fromhost, 23); + state = US_REDRAW; + } + break; + case 'C': +#if !HAVE_FREECLOAK + if (HAS_PERM(PERM_CLOAK)) +#endif + { + currutmp->invisible ^= 1; + state = US_REDRAW; + } + break; + case ' ': + case KEY_PGDN: + case Ctrl('F'): + if (foot < actor) + { + num += p_lines; + state = US_REDRAW; + break; + } + if (head) + num = 0; + state = US_PICKUP; + break; + case KEY_UP: + case 'k': + if (--num < head) + { + if (num < 0) + { + num = actor - 1; + if (actor == foot) + break; + } + state = US_REDRAW; + } + break; + case KEY_PGUP: + case Ctrl('B'): + case 'P': + if (head) + { + num -= p_lines; + state = US_REDRAW; + break; + } + + case KEY_END: + case '$': + num = actor - 1; + if (foot < actor) + state = US_REDRAW; + break; + + case '/': + getdata_buf(b_lines-1,0,"請輸入暱稱關鍵字:",keyword, 12, + DOECHO); + state = US_PICKUP; + break; + case 's': + if ((i = search_pickup(num, actor, pklist)) >= 0) + num = i; + state = US_ACTION; + break; + + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + { /* Thor: 可以打數字跳到該人 */ + int tmp; + if ((tmp = search_num(ch, actor - 1)) >= 0) + num = tmp; + state = US_REDRAW; + } + break; +#ifdef REALINFO + case 'R': /* 顯示真實姓名 */ + if (HAS_PERM(PERM_SYSOP)) + real_name ^= 1; + state = US_PICKUP; + break; +#endif +#ifdef SHOWUID + case 'U': + if (HAS_PERM(PERM_SYSOP)) + show_uid ^= 1; + state = US_PICKUP; + break; +#endif +#ifdef SHOWBOARD + case 'Y': + if (HAS_PERM(PERM_SYSOP)) + show_board ^= 1; + state = US_PICKUP; + break; +#endif +#ifdef SHOWPID + case '#': + if (HAS_PERM(PERM_SYSOP)) + show_pid ^= 1; + state = US_PICKUP; + break; +#endif + + case 'b': /* broadcast */ + if (cuser.uflag & FRIEND_FLAG || HAS_PERM(PERM_SYSOP)) + { + int actor_pos = actor; + char ans[4]; + + state = US_PICKUP; + if (!getdata(0, 0, "廣播訊息:", genbuf, 60, DOECHO)) + break; + if (getdata(0, 0, "確定廣播? [Y]", ans, 4, LCECHO) && + *ans == 'n') + break; + while (actor_pos) + { + uentp = pklist[--actor_pos].ui; + fri_stat = pklist[actor_pos].friend; + if (uentp->pid && + currpid != uentp->pid && + uentp->pid > 0 && kill(uentp->pid, 0) != -1 && + (HAS_PERM(PERM_SYSOP) || + (uentp->pager != 3 && + (uentp->pager != 4 || fri_stat & HFM)))) + my_write(uentp->pid, genbuf, uentp->userid, HAS_PERM(PERM_SYSOP) ? 3 : 1); + } + } + break; + case 'S': /* 顯示好友描述 */ + show_mode = (++show_mode) % MAX_SHOW_MODE; + state = US_PICKUP; + break; + case 'u': /* 線上修改資料 */ + case 'K': /* 把壞蛋踢出去 */ + if (!HAS_PERM(PERM_ACCOUNTS)) + continue; + state = US_ACTION; + break; + case 'i': + state = US_ACTION; + break; + case Ctrl('S'): + state = US_ACTION; + break; + case 't': + case 'w': + if (!(cuser.userlevel & PERM_LOGINOK)) + continue; + state = US_ACTION; + break; + case 'a': + case 'd': + case 'o': + case 'f': + case 'g': + if (!HAS_PERM(PERM_LOGINOK)) + /* 註冊才有 Friend */ + break; + if (ch == 'f') + { + cuser.uflag ^= FRIEND_FLAG; + state = US_PICKUP; + break; + } + state = US_ACTION; + break; + case 'q': + case 'c': + case 'm': + case 'r': + case 'l': + /* guest 只能 query */ + if (!cuser.userlevel && ch != 'q' && ch != 'l') + break; + case 'h': + state = US_ACTION; + break; + case 'p': + if (HAS_PERM(PERM_BASIC)) + { + t_pager(); + state = US_REDRAW; + } + break; + case 'W': + { + int tmp; + char *wm[3] = {"一般", "進階", "未來"}; + tmp = cuser.uflag2 & WATER_MASK; + cuser.uflag2 -= tmp; + tmp = (tmp + 1) % 3; + cuser.uflag2 |= tmp; + prints("切換到 %s 水球模式", wm[tmp]); + refresh(); + sleep(1); + state = US_REDRAW; + } + default: /* refresh screen */ + state = US_REDRAW; + } + } + + if (state != US_ACTION) + { + pid0 = 0; + continue; + } + + /* Ptt decide cur */ + uentp = pklist[num].ui; + fri_stat = friend_stat(currutmp, uentp); + pid0 = uentp->pid; + id0 = 256 * uentp->userid[0] + uentp->userid[1]; + + if (ch == 'w') + { + if ((uentp->pid != currpid) && + (HAS_PERM(PERM_SYSOP) || + (uentp->pager != 3 && + (fri_stat & HFM || uentp->pager != 4)))) + { + cursor_show(num + 3 - head, 0); + sprintf(genbuf, "Call-In %s :", uentp->userid); + my_write(uentp->pid, genbuf, uentp->userid, 0); + } + } + else if (ch == 'l') + { /* Thor: 看 Last call in */ + t_display(); + } + else + { + switch (ch) + { + case 'r': + m_read(); + break; + case 'g': /* give money */ + move(b_lines - 2, 0); + if (strcmp(uentp->userid, cuser.userid)) + { + sprintf(genbuf, "要給 %s 多少錢呢? ", uentp->userid); + outs(genbuf); + if (getdata(b_lines - 1, 0, "[銀行轉帳]:", genbuf, 7, + LCECHO)) + { + clrtoeol(); + if ((ch = atoi(genbuf)) <= 0) + break; + reload_money(); + if (ch > cuser.money) + outs("\033[41m 現金不足~~\033[m"); + else + { + deumoney(uentp->uid, ch); + sprintf(genbuf, "\033[44m 嗯..還剩下 %d 錢.." + "\033[m", demoney(-1*ch)); + outs(genbuf); + sprintf(genbuf, "%s\t給%s\t%d\t%s", cuser.userid, + uentp->userid, ch, + ctime(&currutmp->lastact)); + log_file(FN_MONEY, genbuf); + mail_redenvelop(cuser.userid, uentp->userid, ch, 'Y'); + } + } + else + { + clrtoeol(); + outs("\033[41m 交易取消! \033[m"); + } + } + else + outs("\033[33m 自己給自己? 耍笨..\033[m"); + refresh(); + sleep(1); + break; +#ifdef SHOWMIND + case 'i': + move(3,0); + clrtobot(); + for (i = 1; Mind[i]!=NULL; i++) + { + move(5+(i-1)/7,((i-1)%7)*10); + prints("%2d: %s",i,Mind[i]); + } + getdata(b_lines - 1, 0, "你現在的心情 0:無 q不變 [q]:", + genbuf, 3, LCECHO); + if (genbuf[0] && genbuf[0] != 'q') + currutmp->mind=atoi(genbuf)%i; + state = US_REDRAW; + break; +#endif + case 'a': + friend_add(uentp->userid, FRIEND_OVERRIDE); + friend_load(); + state = US_PICKUP; + break; + case 'd': + friend_delete(uentp->userid, FRIEND_OVERRIDE); + friend_load(); + state = US_PICKUP; + break; + case 'o': + t_override(); + state = US_PICKUP; + break; + case 'K': + if (uentp->pid > 0 && kill(uentp->pid, 0) != -1) + { + move(1, 0); + clrtobot(); + move(2, 0); + my_kick(uentp); + state = US_PICKUP; + } + break; + case 'm': + stand_title("寄 信"); + prints("[寄信] 收信人:%s", uentp->userid); + my_send(uentp->userid); + break; + case 'q': + strcpy(currauthor, uentp->userid); + my_query(uentp->userid); + break; + case 'c': + chicken_query(uentp->userid); + break; + case 'u': /* Thor: 可線上查看及修改使用者 */ + { + int id; + userec_t muser; + + strcpy(currauthor, uentp->userid); + stand_title("使用者設定"); + move(1, 0); + if ((id = getuser(uentp->userid))) + { + memcpy(&muser, &xuser, sizeof(muser)); + user_display(&muser, 1); + uinfo_query(&muser, 1, id); + } + } + break; + + case 'h': /* Thor: 看 Help */ + t_showhelp(); + break; + + case 't': + if (uentp->pid != currpid && + (strcmp(uentp->userid, cuser.userid))) + { + move(1, 0); + clrtobot(); + move(3, 0); + my_talk(uentp, fri_stat); + state = US_PICKUP; + } + break; + } + } + setutmpmode(savemode); + } +} + +int t_users() { + int destuid0 = currutmp->destuid; + int mode0 = currutmp->mode; + int stat0 = currstat; + + setutmpmode(LUSERS); + pickup_user(); + currutmp->mode = mode0; + currutmp->destuid = destuid0; + currstat = stat0; + return 0; +} + +int t_pager() { + currutmp->pager = (currutmp->pager + 1) % 5; + return 0; +} + +int t_idle() { + int destuid0 = currutmp->destuid; + int mode0 = currutmp->mode; + int stat0 = currstat; + char genbuf[20]; + char buf[80], passbuf[PASSLEN]; + + setutmpmode(IDLE); + getdata(b_lines - 1, 0, "理由:[0]發呆 (1)接電話 (2)覓食 (3)打瞌睡 " + "(4)裝死 (5)羅丹 (6)其他 (Q)沒事?", genbuf, 3, DOECHO); + if (genbuf[0] == 'q' || genbuf[0] == 'Q') + { + currutmp->mode = mode0; + currstat = stat0; + return 0; + } + else if (genbuf[0] >= '1' && genbuf[0] <= '6') + currutmp->destuid = genbuf[0] - '0'; + else + currutmp->destuid = 0; + + if (currutmp->destuid == 6) + if (!cuser.userlevel || + !getdata(b_lines - 1, 0, "發呆的理由:", currutmp->chatid, 11, + DOECHO)) + currutmp->destuid = 0; + do + { + move(b_lines - 2, 0); + clrtoeol(); + sprintf(buf, "(鎖定螢幕)發呆原因: %s", (currutmp->destuid != 6) ? + IdleTypeTable[currutmp->destuid] : currutmp->chatid); + outs(buf); + refresh(); + getdata(b_lines - 1, 0, MSG_PASSWD, passbuf, PASSLEN, NOECHO); + passbuf[8] = '\0'; + } + while (!checkpasswd(cuser.passwd, passbuf) && + strcmp(STR_GUEST, cuser.userid)); + + currutmp->mode = mode0; + currutmp->destuid = destuid0; + currstat = stat0; + + return 0; +} + +int t_qchicken() { + char uident[STRLEN]; + + stand_title("查詢寵物"); + usercomplete(msg_uid, uident); + if (uident[0]) + chicken_query(uident); + return 0; +} + +int t_query() { + char uident[STRLEN]; + + stand_title("查詢網友"); + usercomplete(msg_uid, uident); + if (uident[0]) + my_query(uident); + return 0; +} + +int t_talk() { + char uident[16]; + int tuid, unum, ucount; + userinfo_t *uentp; + char genbuf[4]; +/* + if (count_ulist() <= 1) + { + outs("目前線上只有您一人,快邀請朋友來光臨【" BBSNAME "】吧!"); + return XEASY; + } +*/ + stand_title("打開話匣子"); + creat_list(); + namecomplete(msg_uid, uident); + if (uident[0] == '\0') + return 0; + + move(3, 0); + if (!(tuid = searchuser(uident)) || tuid == usernum) + { + outs(err_uid); + pressanykey(); + return 0; + } + +/* multi-login check */ + unum = 1; + while ((ucount = count_logins(tuid, 0)) > 1) + { + outs("(0) 不想 talk 了...\n"); + count_logins(tuid, 1); + getdata(1, 33, "請選擇一個聊天對象 [0]:", genbuf, 4, DOECHO); + unum = atoi(genbuf); + if (unum == 0) + return 0; + move(3, 0); + clrtobot(); + if (unum > 0 && unum <= ucount) + break; + } + + if ((uentp = (userinfo_t *) search_ulistn(tuid, unum))) + my_talk(uentp, friend_stat(currutmp, uentp)); + + return 0; +} + +/* 有人來串門子了,回應呼叫器 */ +static userinfo_t *uip; +void talkreply() { + struct hostent *h; + char buf[4]; + struct sockaddr_in sin; + char genbuf[200]; + int a, sig = currutmp->sig; + + talkrequest = NA; + uip = &utmpshm->uinfo[currutmp->destuip]; + sprintf(page_requestor, "%s (%s)", uip->userid, uip->username); + currutmp->destuid = uip->uid; + currstat = XMODE; /* 避免出現動畫 */ + + clear(); + + prints("\n\n"); + prints(" (Y) 讓我們 %s 吧!" + " (A) 我現在很忙,請等一會兒再 call 我\n", sig_des[sig]); + prints(" (N) 我現在不想 %s" + " (B) 對不起,我有事情不能跟你 %s\n", + sig_des[sig], sig_des[sig]); + prints(" (C) 請不要吵我好嗎?" + " (D) 我要離站囉..下次再聊吧.......\n"); + prints(" (E) 有事嗎?請先來信" + " (F) \033[1;33m我自己輸入理由好了...\033[m\n"); + prints(" (1) %s?先拿100銀兩來" + " (2) %s?先拿1000銀兩來..\n\n", sig_des[sig], sig_des[sig]); + + getuser(uip->userid); + currutmp->msgs[0].pid = uip->pid; + strcpy(currutmp->msgs[0].userid, uip->userid); + strcpy(currutmp->msgs[0].last_call_in, "呼叫、呼叫,聽到請回答 (Ctrl-R)"); + prints("對方來自 [%s],共上站 %d 次,文章 %d 篇\n", + uip->from, xuser.numlogins, xuser.numposts); + showplans(uip->userid); + show_last_call_in(0); + + sprintf(genbuf, "你想跟 %s %s啊?請選擇(Y/N/A/B/C/D/E/F/1/2)[N] ", + page_requestor, sig_des[sig]); + getdata(0, 0, genbuf, buf, 4, LCECHO); + + if (uip->mode != PAGE) + { + sprintf(genbuf, "%s已停止呼叫,按Enter繼續...", page_requestor); + getdata(0, 0, genbuf, buf, 4, LCECHO); + return; + } + currutmp->msgcount = 0; + strcpy(save_page_requestor, page_requestor); + memset(page_requestor, 0, sizeof(page_requestor)); + if (!(h = gethostbyname("localhost"))) + { + perror("gethostbyname"); + return; + } + memset(&sin, 0, sizeof(sin)); + sin.sin_family = h->h_addrtype; + memcpy(&sin.sin_addr, h->h_addr, h->h_length); + sin.sin_port = uip->sockaddr; + a = socket(sin.sin_family, SOCK_STREAM, 0); + if ((connect(a, (struct sockaddr *) &sin, sizeof(sin)))) + { + perror("connect err"); + return; + } + if (!buf[0] || !strchr("yabcdef12", buf[0])) + buf[0] = 'n'; + write(a, buf, 1); + if (buf[0] == 'f' || buf[0] == 'F') + { + if (!getdata(b_lines, 0, "不能的原因:", genbuf, 60, DOECHO)) + strcpy(genbuf, "不告訴你咧 !! ^o^"); + write(a, genbuf, 60); + } + uip->destuip = currutmp - &utmpshm->uinfo[0]; + if (buf[0] == 'y') + switch (sig) + { + case SIG_DARK: + main_dark(a, uip); + break; + case SIG_PK: + chickenpk(a); + break; + case SIG_GOMO: + gomoku(a); + break; + case SIG_CHC: + chc(a); + break; + case SIG_TALK: + default: + do_talk(a); + } + else + close(a); + clear(); +} + +/* 網友動態簡表 */ +/* not used +static int shortulist(userinfo_t * uentp) { + static int lineno, fullactive, linecnt; + static int moreactive, page, num; + char uentry[50]; + int state; + + if (!lineno) + { + lineno = 3; + page = moreactive ? (page + p_lines * 3) : 0; + linecnt = num = moreactive = 0; + move(1, 70); + prints("Page: %d", page / (p_lines) / 3 + 1); + move(lineno, 0); + } + + if (uentp == NULL) + { + int finaltally; + + clrtoeol(); + move(++lineno, 0); + clrtobot(); + finaltally = fullactive; + lineno = fullactive = 0; + return finaltally; + } + if ((!HAS_PERM(PERM_SYSOP) && + !HAS_PERM(PERM_SEECLOAK) && + uentp->invisible) || + ((friend_stat(currutmp, uentp) & HRM) && + !HAS_PERM(PERM_SYSOP))) + { + if (lineno >= b_lines) + return 0; + if (num++ < page) + return 0; + memset(uentry, ' ', 25); + uentry[25] = '\0'; + } + else + { + fullactive++; + if (lineno >= b_lines) + { + moreactive = 1; + return 0; + } + if (num++ < page) + return 0; + + state = (currutmp == uentp) ? 10 : + (friend_stat(currutmp,uentp)&ST_FRIEND)>>2; + + if (PERM_HIDE(uentp)) + state = 9; + + sprintf(uentry, "%s%-13s%c%-10s%s ", fcolor[state], + uentp->userid, uentp->invisible ? '#' : ' ', + modestring(uentp, 1), state ? "\033[0m" : ""); + } + if (++linecnt < 3) + { + strcat(uentry, "│"); + outs(uentry); + } + else + { + outs(uentry); + linecnt = 0; + clrtoeol(); + move(++lineno, 0); + } + return 0; +} +*/ diff --git a/pttbbs/mbbsd/term.c b/pttbbs/mbbsd/term.c new file mode 100644 index 00000000..61a0128d --- /dev/null +++ b/pttbbs/mbbsd/term.c @@ -0,0 +1,144 @@ +/* $Id: term.c,v 1.1 2002/03/07 15:13:48 in2 Exp $ */ +#include +#include +#include +#include +#include +#include +#include +#include +#include "config.h" +#include "pttstruct.h" +#include "common.h" +#include "proto.h" + +int tgetent(const char *bp, char *name); +char *tgetstr(const char *id, char **area); +int tgetflag(const char *id); +int tgetnum(const char *id); +int tputs(const char *str, int affcnt, int (*putc)(int)); +char *tparm(const char *str, ...); +char *tgoto(const char *cap, int col, int row); + +static struct termios tty_state, tty_new; + +/* ----------------------------------------------------- */ +/* basic tty control */ +/* ----------------------------------------------------- */ +void init_tty() { + if(tcgetattr(1, &tty_state) < 0) { + syslog(LOG_ERR, "tcgetattr(): %m"); + return; + } + memcpy(&tty_new, &tty_state, sizeof(tty_new)); + tty_new.c_lflag &= ~(ICANON | ECHO | ISIG); +/* tty_new.c_cc[VTIME] = 0; + tty_new.c_cc[VMIN] = 1; */ + tcsetattr(1, TCSANOW, &tty_new); + system("stty raw -echo"); +} + +/* ----------------------------------------------------- */ +/* init tty control code */ +/* ----------------------------------------------------- */ + + +#define TERMCOMSIZE (40) + +char *clearbuf = "\33[H\33[J"; +int clearbuflen = 6; + +char *cleolbuf = "\33[K"; +int cleolbuflen = 3; + +char *scrollrev = "\33M"; +int scrollrevlen = 2; + +char *strtstandout = "\33[7m"; +int strtstandoutlen = 4; + +char *endstandout = "\33[m"; +int endstandoutlen = 3; + +int t_lines = 24; +int b_lines = 23; +int p_lines = 20; +int t_columns = 80; + +int automargins = 1; + +static char *outp; +static int *outlp; + + +static int outcf(int ch) { + if(*outlp < TERMCOMSIZE) { + (*outlp)++; + *outp++ = ch; + } + return 0; +} + +extern screenline_t *big_picture; + +static void term_resize(int sig) { + struct winsize newsize; + screenline_t *new_picture; + + signal(SIGWINCH, SIG_IGN); /* Don't bother me! */ + ioctl(0, TIOCGWINSZ, &newsize); + if(newsize.ws_row > t_lines) { + new_picture = (screenline_t *)calloc(newsize.ws_row, + sizeof(screenline_t)); + if(new_picture == NULL) { + syslog(LOG_ERR, "calloc(): %m"); + return; + } + free(big_picture); + big_picture = new_picture; + } + + t_lines=newsize.ws_row; + b_lines=t_lines-1; + p_lines=t_lines-4; + + signal(SIGWINCH, term_resize); +} + +int term_init() { + signal(SIGWINCH, term_resize); + return YEA; +} + +char term_buf[32]; + +void do_move(int destcol, int destline) { + char buf[16], *p; + + sprintf(buf, "\33[%d;%dH", destline + 1, destcol + 1); + for(p = buf; *p; p++) + ochar(*p); +} + +void save_cursor() { + ochar('\33'); + ochar('7'); +} + +void restore_cursor() { + ochar('\33'); + ochar('8'); +} + +void change_scroll_range(int top, int bottom) { + char buf[16], *p; + + sprintf(buf, "\33[%d;%dr", top + 1, bottom + 1); + for(p = buf; *p; p++) + ochar(*p); +} + +void scroll_forward() { + ochar('\33'); + ochar('D'); +} diff --git a/pttbbs/mbbsd/toolkit.c b/pttbbs/mbbsd/toolkit.c new file mode 100644 index 00000000..81a0d6f0 --- /dev/null +++ b/pttbbs/mbbsd/toolkit.c @@ -0,0 +1,14 @@ +/* $Id: toolkit.c,v 1.1 2002/03/07 15:13:48 in2 Exp $ */ +#include +#include +#include "config.h" +#include "pttstruct.h" + +unsigned StringHash(unsigned char *s) { + unsigned int v=0; + while(*s) { + v = (v << 8) | (v >> 24); + v ^= toupper(*s++); /* note this is case insensitive */ + } + return (v * 2654435769UL) >> (32 - HASH_BITS); +} diff --git a/pttbbs/mbbsd/topsong.c b/pttbbs/mbbsd/topsong.c new file mode 100644 index 00000000..d3a65447 --- /dev/null +++ b/pttbbs/mbbsd/topsong.c @@ -0,0 +1,79 @@ +/* $Id: topsong.c,v 1.1 2002/03/07 15:13:48 in2 Exp $ */ +#include +#include +#include +#include +#include "config.h" +#include "pttstruct.h" +#include "common.h" +#include "proto.h" + +#define MAX_SONGS 300 +#define QCAST int (*)(const void *, const void *) + +typedef struct songcmp_t { + char name[100]; + char cname[100]; + long int count; +} songcmp_t; + +static long int totalcount=0; + +static int count_cmp(songcmp_t *b, songcmp_t *a) { + return (a->count - b->count); +} + +int topsong() { + more(FN_TOPSONG,YEA); + return 0; +} + +static int strip_blank(char *cbuf, char *buf) { + for(; *buf; buf++) + if(*buf != ' ') + *cbuf++ = *buf; + *cbuf = 0; + return 0; +} + +void sortsong() { + FILE *fo, *fp = fopen(BBSHOME "/" FN_USSONG, "r"); + songcmp_t songs[MAX_SONGS + 1]; + int n; + char buf[256], cbuf[256]; + + memset(songs , 0, sizeof(songs)); + if(!fp) return; + if(!(fo = fopen(FN_TOPSONG,"w"))) { + fclose(fp); + return; + } + + totalcount = 0; + while(fgets(buf, 200, fp)) { + strtok(buf, "\n\r"); + strip_blank(cbuf, buf); + if(!cbuf[0] || !isprint2(cbuf[0])) + continue; + + for(n = 0; n < MAX_SONGS && songs[n].name[0]; n++) + if(!strcmp(songs[n].cname,cbuf)) + break; + strcpy(songs[n].name, buf); + strcpy(songs[n].cname, cbuf); + songs[n].count++; + totalcount++; + } + qsort(songs, MAX_SONGS, sizeof(songcmp_t), (QCAST)count_cmp); + fprintf(fo, + " \033[36m──\033[37m名次\033[36m──────\033[37m歌" + " 名\033[36m───────────\033[37m次數\033[36m" + "──\033[32m共%ld次\033[36m──\033[m\n", totalcount); + for(n = 0; n < 100 && songs[n].name[0]; n++) { + fprintf(fo, " %5d. %-38.38s %4ld \033[32m[%.2f]\033[m\n", n + 1, + songs[n].name, songs[n].count, + (float)songs[n].count/totalcount); + } + fclose(fp); + fclose(fo); +} diff --git a/pttbbs/mbbsd/uptime b/pttbbs/mbbsd/uptime new file mode 100644 index 00000000..4f8281fb --- /dev/null +++ b/pttbbs/mbbsd/uptime @@ -0,0 +1,23 @@ +cache.c: if(fcache->busystate) +cache.c: fcache->busystate = 1; +cache.c: bzero(fcache->domain, sizeof fcache->domain); +cache.c: fcache->top=0; +cache.c: sscanf(buf,"%s",fcache->domain[fcache->top]); +cache.c: po = buf + strlen(fcache->domain[fcache->top]); +cache.c: strncpy(fcache->replace[fcache->top],po,49); +cache.c: fcache->replace[fcache->top] +cache.c: [strlen(fcache->replace[fcache->top])-1] = 0; +cache.c: (fcache->top)++; +cache.c: if(fcache->top == MAX_FROM) +cache.c: fcache->max_user=0; +cache.c: fcache->uptime = fcache->touchtime; +cache.c: fcache->busystate = 0; +cache.c: if(fcache->touchtime == 0) +cache.c: fcache->touchtime = 1; +cache.c: while(fcache->uptime < fcache->touchtime) +mbbsd.c: for (j = 0; j < fcache->top; j++){ +mbbsd.c: char *token = strtok (fcache->domain[j], "&"); +mbbsd.c: if ((a = utmpshm->number) > fcache->max_user){ +mbbsd.c: fcache->max_user = a; +mbbsd.c: fcache->max_time = now; +talk.c: uentp->from_alias ? fcache->replace[uentp->from_alias] : diff --git a/pttbbs/mbbsd/user.c b/pttbbs/mbbsd/user.c new file mode 100644 index 00000000..41aacfa9 --- /dev/null +++ b/pttbbs/mbbsd/user.c @@ -0,0 +1,980 @@ +/* $Id: user.c,v 1.1 2002/03/07 15:13:48 in2 Exp $ */ +#include +#include +#include +#include +#include +#include +#include +#include "config.h" +#include "pttstruct.h" +#include "common.h" +#include "perm.h" +#include "modes.h" +#include "proto.h" + +extern int numboards; +extern boardheader_t *bcache; +extern char *loginview_file[NUMVIEWFILE][2]; +extern int b_lines; /* Screen bottom line number: t_lines-1 */ +extern time_t login_start_time; +extern char *msg_uid; +extern int usernum; +extern char *msg_sure_ny; +extern userinfo_t *currutmp; +extern int showansi; +extern char reset_color[]; +extern char *fn_proverb; +extern char *fn_plans; +extern char *msg_del_ok; +extern char *fn_register; +extern char *msg_nobody; +extern userec_t cuser; +extern userec_t xuser; + +static char *sex[8] = { + MSG_BIG_BOY, MSG_BIG_GIRL, MSG_LITTLE_BOY, MSG_LITTLE_GIRL, + MSG_MAN, MSG_WOMAN, MSG_PLANT, MSG_MIME +}; + +int u_loginview() { + int i; + unsigned int pbits = cuser.loginview; + char choice[5]; + + clear(); + move(4,0); + for(i = 0; i < NUMVIEWFILE ; i++) + prints(" %c. %-20s %-15s \n", 'A' + i, + loginview_file[i][1],((pbits >> i) & 1 ? "ˇ" : "X")); + + clrtobot(); + while(getdata(b_lines - 1, 0, "請按 [A-N] 切換設定,按 [Return] 結束:", + choice, 3, LCECHO)) { + i = choice[0] - 'a'; + if(i >= NUMVIEWFILE || i < 0) + bell(); + else { + pbits ^= (1 << i); + move( i + 4 , 28 ); + prints((pbits >> i) & 1 ? "ˇ" : "X"); + } + } + + if(pbits != cuser.loginview) { + cuser.loginview = pbits ; + passwd_update(usernum, &cuser); + } + return 0; +} + +void user_display(userec_t *u, int real) { + int diff = 0; + char genbuf[200]; + + clrtobot(); + prints( + " \033[30;41m┴┬┴┬┴┬\033[m \033[1;30;45m 使 用 者" + " 資 料 " + " \033[m \033[30;41m┴┬┴┬┴┬\033[m\n"); + prints(" 代號暱稱: %s(%s)\n" + " 真實姓名: %s\n" + " 居住住址: %s\n" + " 電子信箱: %s\n" + " 性 別: %s\n" + " 銀行帳戶: %ld 銀兩\n", + u->userid, u->username, u->realname, u->address, u->email, + sex[u->sex % 8], u->money); + + sethomedir(genbuf, u->userid); + prints(" 私人信箱: %d 封 (購買信箱: %d 封)\n" + " 身分證號: %s\n" + " 手機號碼: %010d\n" + " 生 日: %02i/%02i/%02i\n" + " 小雞名字: %s\n", + get_num_records(genbuf, sizeof(fileheader_t)), + u->exmailbox, u->ident, u->mobile, + u->month, u->day, u->year % 100, u->mychicken.name); + prints(" 註冊日期: %s", ctime(&u->firstlogin)); + prints(" 前次光臨: %s", ctime(&u->lastlogin)); + prints(" 前次點歌: %s", ctime(&u->lastsong)); + prints(" 上站文章: %d 次 / %d 篇\n", + u->numlogins, u->numposts); + + if(real) { + strcpy(genbuf, "bTCPRp#@XWBA#VSM0123456789ABCDEF"); + for(diff = 0; diff < 32; diff++) + if(!(u->userlevel & (1 << diff))) + genbuf[diff] = '-'; + prints(" 認證資料: %s\n" + " user權限: %s\n", + u->justify, genbuf); + } else { + diff = (time(0) - login_start_time) / 60; + prints(" 停留期間: %d 小時 %2d 分\n", + diff / 60, diff % 60); + } + + /* Thor: 想看看這個 user 是那些版的版主 */ + if(u->userlevel >= PERM_BM) { + int i; + boardheader_t *bhdr; + + outs(" 擔任板主: "); + + for(i = 0, bhdr = bcache; i < numboards; i++, bhdr++) { + if(is_uBM(bhdr->BM,u->userid)) { + outs(bhdr->brdname); + outc(' '); + } + } + outc('\n'); + } + outs(" \033[30;41m┴┬┴┬┴┬┴┬┴┬┴┬┴┬┴┬┴┬┴┬┴┬┴" + "┬┴┬┴┬┴┬\033[m"); + + outs((u->userlevel & PERM_LOGINOK) ? + "\n您的註冊程序已經完成,歡迎加入本站" : + "\n如果要提昇權限,請參考本站公佈欄辦理註冊"); + +#ifdef NEWUSER_LIMIT + if((u->lastlogin - u->firstlogin < 3 * 86400) && !HAS_PERM(PERM_POST)) + outs("\n新手上路,三天後開放權限"); +#endif +} + +void mail_violatelaw(char* crime, char* police, char* reason, char* result){ + char genbuf[200]; + fileheader_t fhdr; + time_t now; + FILE *fp; + sprintf(genbuf, "home/%c/%s", crime[0], crime); + stampfile(genbuf, &fhdr); + if(!(fp = fopen(genbuf,"w"))) + return; + now = time(NULL); + fprintf(fp, "作者: [Ptt法院]\n" + "標題: [報告] 違法判決報告\n" + "時間: %s\n" + "\033[1;32m%s\033[m判決:\n \033[1;32m%s\033[m" + "因\033[1;35m%s\033[m行為,\n違反本站站規,處以\033[1;35m%s\033[m,特此通知" + "\n請到 PttLaw 查詢相關法規資訊,並到 Play-Pay-ViolateLaw 繳交罰單", + ctime(&now), police, crime, reason, result); + fclose(fp); + sprintf(fhdr.title, "[報告] 違法判決報告"); + strcpy(fhdr.owner, "[Ptt法院]"); + sprintf(genbuf, "home/%c/%s/.DIR", crime[0], crime); + append_record(genbuf, &fhdr, sizeof(fhdr)); +} + +static void violate_law(userec_t *u, int unum){ + char ans[4], ans2[4]; + char reason[128]; + move(1,0); + clrtobot(); + move(2,0); + prints("(1)Cross-post (2)亂發廣告信 (3)亂發連鎖信\n"); + prints("(4)騷擾站上使用者 (8)其他以罰單處置行為\n(9)砍 id 行為\n"); + getdata(5, 0, "(0)結束", + ans, 3, DOECHO); + switch(ans[0]){ + case '1': + sprintf(reason, "%s", "Cross-post"); + break; + case '2': + sprintf(reason, "%s", "亂發廣告信"); + break; + case '3': + sprintf(reason, "%s", "亂發連鎖信"); + break; + case '4': + while(!getdata(7, 0, "請輸入被檢舉理由以示負責:", reason, 50, DOECHO)); + strcat(reason, "[騷擾站上使用者]"); + break; + case '8': + case '9': + while(!getdata(6, 0, "請輸入理由以示負責:", reason, 50, DOECHO)); + break; + default: + return; + } + getdata(7, 0, msg_sure_ny, ans2, 3, LCECHO); + if(*ans2 != 'y') + return; + if (ans[0]=='9'){ + char src[STRLEN], dst[STRLEN]; + sprintf(src, "home/%c/%s", u->userid[0], u->userid); + sprintf(dst, "tmp/%s", u->userid); + Rename(src, dst); + log_usies("KILL", u->userid); + post_violatelaw(u->userid, cuser.userid, reason, "砍除 ID"); + u->userid[0] = '\0'; + setuserid(unum, u->userid); + passwd_update(unum, u); + } + else{ + u->userlevel |= PERM_VIOLATELAW; + u->vl_count ++; + passwd_update(unum, u); + post_violatelaw(u->userid, cuser.userid, reason, "罰單處份"); + mail_violatelaw(u->userid, cuser.userid, reason, "罰單處份"); + } + pressanykey(); +} + +extern char* str_permid[]; + +void uinfo_query(userec_t *u, int real, int unum) { + userec_t x; + register int i = 0, fail, mail_changed; + char ans[4], buf[STRLEN], *p; + char genbuf[200], reason[50]; + unsigned long int money = 0; + fileheader_t fhdr; + int flag = 0, temp = 0, money_change = 0; + time_t now; + + FILE *fp; + + fail = mail_changed = 0; + + memcpy(&x, u, sizeof(userec_t)); + getdata(b_lines - 1, 0, real ? + "(1)改資料(2)設密碼(3)設權限(4)砍帳號(5)改ID" + "(6)殺/復活寵物(7)審判 [0]結束 " : + "請選擇 (1)修改資料 (2)設定密碼 ==> [0]結束 ", + ans, 3, DOECHO); + + if(ans[0] > '2' && !real) + ans[0] = '0'; + + if(ans[0] == '1' || ans[0] == '3') { + clear(); + i = 2; + move(i++, 0); + outs(msg_uid); + outs(x.userid); + } + + switch(ans[0]) { + case '7': + violate_law(&x, unum); + return; + case '1': + move(0, 0); + outs("請逐項修改。"); + + getdata_buf(i++, 0," 暱 稱 :",x.username, 24, DOECHO); + if(real) { + getdata_buf(i++, 0, "真實姓名:", x.realname, 20, DOECHO); + getdata_buf(i++, 0, "身分證號:", x.ident, 11, DOECHO); + getdata_buf(i++, 0, "居住地址:", x.address, 50, DOECHO); + } + sprintf(buf, "%010d", x.mobile); + getdata_buf(i++, 0, "手機號碼:", buf, 11, LCECHO); + x.mobile=atoi(buf); + getdata_str(i++, 0, "電子信箱[變動要重新認證]:", buf, 50, DOECHO, + x.email); + if(strcmp(buf,x.email) && strchr(buf, '@')) { + strcpy(x.email,buf); + mail_changed = 1 - real; + } + + sprintf(genbuf, "%i", (u->sex + 1) % 8); + getdata_str(i++, 0, "性別 (1)葛格 (2)姐接 (3)底迪 (4)美眉 (5)薯叔 " + "(6)阿姨 (7)植物 (8)礦物:", + buf, 3, DOECHO,genbuf); + if(buf[0] >= '1' && buf[0] <= '8') + x.sex = (buf[0] - '1') % 8; + else + x.sex = u->sex % 8; + + while(1) { + int len; + + sprintf(genbuf, "%02i/%02i/%02i", + u->month, u->day, u->year % 100); + len = getdata_str(i, 0, "生日 月月/日日/西元:", buf, 9, + DOECHO,genbuf); + if(len && len != 8) + continue; + if(!len) { + x.month = u->month; + x.day = u->day; + x.year = u->year; + } else if(len == 8) { + x.month = (buf[0] - '0') * 10 + (buf[1] - '0'); + x.day = (buf[3] - '0') * 10 + (buf[4] - '0'); + x.year = (buf[6] - '0') * 10 + (buf[7] - '0'); + } else + continue; + if(!real && (x.month > 12 || x.month < 1 || x.day > 31 || + x.day < 1 || x.year > 90 || x.year < 40)) + continue; + i++; + break; + } + if(real) { + unsigned long int l; + if(HAS_PERM(PERM_BBSADM)) { + sprintf(genbuf, "%d", x.money); + if(getdata_str(i++, 0,"銀行帳戶:", buf, 10, DOECHO,genbuf)) + if((l = atol(buf)) >= 0) { + if(l != x.money) { + money_change = 1; + money = x.money; + x.money = l; + } + } + } + sprintf(genbuf, "%d", x.exmailbox); + if(getdata_str(i++, 0,"購買信箱數:", buf, 4, DOECHO,genbuf)) + if((l = atol(buf)) >= 0) + x.exmailbox = (int)l; + + getdata_buf(i++, 0, "認證資料:", x.justify, 44, DOECHO); + getdata_buf(i++, 0, "最近光臨機器:", x.lasthost, 16, DOECHO); + + sprintf(genbuf, "%d", x.numlogins); + if(getdata_str(i++, 0,"上線次數:", buf, 10, DOECHO,genbuf)) + if((fail = atoi(buf)) >= 0) + x.numlogins = fail; + + sprintf(genbuf,"%d", u->numposts); + if(getdata_str(i++, 0, "文章數目:", buf, 10, DOECHO,genbuf)) + if((fail = atoi(buf)) >= 0) + x.numposts = fail; + sprintf(genbuf, "%d", u->vl_count); + if (getdata_str(i++, 0, "違法記錄:", buf, 10, DOECHO, genbuf)) + if ((fail = atoi(buf)) >= 0) + x.vl_count = fail; + + sprintf(genbuf, "%d/%d/%d", u->five_win, u->five_lose, + u->five_tie); + if(getdata_str(i++, 0, "五子棋戰績 勝/敗/和:", buf, 16, DOECHO, + genbuf)) + while(1) { + p = strtok(buf, "/\r\n"); + if(!p) break; + x.five_win = atoi(p); + p = strtok(NULL, "/\r\n"); + if(!p) break; + x.five_lose = atoi(p); + p = strtok(NULL, "/\r\n"); + if(!p) break; + x.five_tie = atoi(p); + break; + } + sprintf(genbuf, "%d/%d/%d", u->chc_win, u->chc_lose, u->chc_tie); + if(getdata_str(i++, 0, "象棋戰績 勝/敗/和:", buf, 16, DOECHO, + genbuf)) + while(1) { + p = strtok(buf, "/\r\n"); + if(!p) break; + x.chc_win = atoi(p); + p = strtok(NULL, "/\r\n"); + if(!p) break; + x.chc_lose = atoi(p); + p = strtok(NULL, "/\r\n"); + if(!p) break; + x.chc_tie = atoi(p); + break; + } + fail = 0; + } + break; + + case '2': + i = 19; + if(!real) { + if(!getdata(i++, 0, "請輸入原密碼:", buf, PASSLEN, NOECHO) || + !checkpasswd(u->passwd, buf)) { + outs("\n\n您輸入的密碼不正確\n"); + fail++; + break; + } + } + else{ + char witness[3][32]; + time_t now = time(NULL); + for(i=0;i<3;i++){ + if(!getdata(19+i, 0, "請輸入協助證明之使用者:", witness[i], 32, DOECHO)){ + outs("\n不輸入則無法更改\n"); + fail++; + break; + } + else if (!getuser(witness[i])){ + outs("\n查無此使用者\n"); + fail++; + break; + } + else if (now - xuser.firstlogin < 6*30*24*60*60){ + outs("\n註冊未超過半年,請重新輸入\n"); + i--; + } + } + if (i < 3) + break; + else + i = 20; + } + + if(!getdata(i++, 0, "請設定新密碼:", buf, PASSLEN, NOECHO)) { + outs("\n\n密碼設定取消, 繼續使用舊密碼\n"); + fail++; + break; + } + strncpy(genbuf, buf, PASSLEN); + + getdata(i++, 0, "請檢查新密碼:", buf, PASSLEN, NOECHO); + if(strncmp(buf, genbuf, PASSLEN)) { + outs("\n\n新密碼確認失敗, 無法設定新密碼\n"); + fail++; + break; + } + buf[8] = '\0'; + strncpy(x.passwd, genpasswd(buf), PASSLEN); + if (real) + x.userlevel &= (!PERM_LOGINOK); + break; + + case '3': + i = setperms(x.userlevel, str_permid); + if(i == x.userlevel) + fail++; + else { + flag=1; + temp=x.userlevel; + x.userlevel = i; + } + break; + + case '4': + i = QUIT; + break; + + case '5': + if (getdata_str(b_lines - 3, 0, "新的使用者代號:", genbuf, IDLEN + 1, + DOECHO,x.userid)) { + if(searchuser(genbuf)) { + outs("錯誤! 已經有同樣 ID 的使用者"); + fail++; + } else + strcpy(x.userid, genbuf); + } + break; + case '6': + if(x.mychicken.name[0]) + x.mychicken.name[0] = 0; + else + strcpy(x.mychicken.name,"[死]"); + break; + default: + return; + } + + if(fail) { + pressanykey(); + return; + } + + getdata(b_lines - 1, 0, msg_sure_ny, ans, 3, LCECHO); + if(*ans == 'y') { + if(flag) + post_change_perm(temp,i,cuser.userid,x.userid); + if(strcmp(u->userid, x.userid)) { + char src[STRLEN], dst[STRLEN]; + + sethomepath(src, u->userid); + sethomepath(dst, x.userid); + Rename(src, dst); + setuserid(unum, x.userid); + } + memcpy(u, &x, sizeof(x)); + if(mail_changed) { +#ifdef EMAIL_JUSTIFY + x.userlevel &= ~PERM_LOGINOK; + mail_justify(); +#endif + } + + if(i == QUIT) { + char src[STRLEN], dst[STRLEN]; + + sprintf(src, "home/%c/%s", x.userid[0], x.userid); + sprintf(dst, "tmp/%s", x.userid); + if(Rename(src, dst)) { + sprintf(genbuf, "/bin/rm -fr %s >/dev/null 2>&1", src); +/* do not remove + system(genbuf); +*/ + } + log_usies("KILL", x.userid); + x.userid[0] = '\0'; + setuserid(unum, x.userid); + } else + log_usies("SetUser", x.userid); + if(money_change) + setumoney(unum,x.money); + passwd_update(unum, &x); + now = time(0); + if(money_change) { + strcpy(genbuf, "boards/Security"); + stampfile(genbuf, &fhdr); + if(!(fp = fopen(genbuf,"w"))) + return; + + now = time(NULL); + fprintf(fp, "作者: [系統安全局] 看板: Security\n" + "標題: [公安報告] 站長修改金錢報告\n" + "時間: %s\n" + " 站長\033[1;32m%s\033[m把\033[1;32m%s\033[m" + "的錢從\033[1;35m%ld\033[m改成\033[1;35m%d\033[m", + ctime(&now), cuser.userid, x.userid, money, x.money); + + clrtobot (); + clear(); + while(!getdata(5, 0, "請輸入理由以示負責:", reason, 60, DOECHO)); + + fprintf(fp, "\n \033[1;37m站長%s修改錢理由是:%s\033[m", + cuser.userid, reason); + fclose(fp); + sprintf(fhdr.title, "[公安報告] 站長%s修改%s錢報告", cuser.userid, + x.userid); + strcpy(fhdr.owner, "[系統安全局]"); + append_record("boards/Security/.DIR", &fhdr, sizeof(fhdr)); + } + } +} + +int u_info() { + move(2, 0); + user_display(&cuser, 0); + uinfo_query(&cuser, 0, usernum); + strcpy(currutmp->realname, cuser.realname); + strcpy(currutmp->username, cuser.username); + return 0; +} + +int u_ansi() { + showansi ^= 1; + cuser.uflag ^= COLOR_FLAG; + outs(reset_color); + return 0; +} + +int u_cloak() { + outs((currutmp->invisible ^= 1) ? MSG_CLOAKED : MSG_UNCLOAK); + return XEASY; +} + +int u_switchproverb() { +/* char *state[4]={"用功\型","安逸型","自定型","SHUTUP"}; */ + char buf[100]; + + cuser.proverb =(cuser.proverb +1) %4; + setuserfile(buf,fn_proverb); + if(cuser.proverb==2 && dashd(buf)) { + FILE *fp = fopen(buf,"a"); + + fprintf(fp,"座右銘狀態為[自定型]要記得設座右銘的內容唷!!"); + fclose(fp); + } + passwd_update(usernum, &cuser); + return 0; +} + +int u_editproverb() { + char buf[100]; + + setutmpmode(PROVERB); + setuserfile(buf,fn_proverb); + move(1,0); + clrtobot(); + outs("\n\n 請一行一行依序鍵入想系統提醒你的內容,\n" + " 儲存後記得把狀態設為 [自定型] 才有作用\n" + " 座右銘最多100條"); + pressanykey(); + vedit(buf,NA, NULL); + return 0; +} + +void showplans(char *uid) { + char genbuf[200]; + + sethomefile(genbuf, uid, fn_plans); + if(!show_file(genbuf, 7, MAX_QUERYLINES, ONLY_COLOR)) + prints("《個人名片》%s 目前沒有名片", uid); +} + +int showsignature(char *fname) { + FILE *fp; + char buf[256]; + int i, j; + char ch; + + clear(); + move(2, 0); + setuserfile(fname, "sig.0"); + j = strlen(fname) - 1; + + for(ch = '1'; ch <= '9'; ch++) { + fname[j] = ch; + if((fp = fopen(fname, "r"))) { + prints("\033[36m【 簽名檔.%c 】\033[m\n", ch); + for(i = 0; i++ < MAX_SIGLINES && fgets(buf, 256, fp); outs(buf)); + fclose(fp); + } + } + return j; +} + +int u_editsig() { + int aborted; + char ans[4]; + int j; + char genbuf[200]; + + j = showsignature(genbuf); + + getdata(0, 0, "簽名檔 (E)編輯 (D)刪除 (Q)取消?[Q] ", ans, 4, LCECHO); + + aborted = 0; + if(ans[0] == 'd') + aborted = 1; + if(ans[0] == 'e') + aborted = 2; + + if(aborted) { + if(!getdata(1, 0, "請選擇簽名檔(1-9)?[1] ", ans, 4, DOECHO)) + ans[0] = '1'; + if(ans[0] >= '1' && ans[0] <= '9') { + genbuf[j] = ans[0]; + if(aborted == 1) { + unlink(genbuf); + outs(msg_del_ok); + } else { + setutmpmode(EDITSIG); + aborted = vedit(genbuf, NA, NULL); + if(aborted != -1) + outs("簽名檔更新完畢"); + } + } + pressanykey(); + } + return 0; +} + +int u_editplan() { + char genbuf[200]; + + getdata(b_lines - 1, 0, "名片 (D)刪除 (E)編輯 [Q]取消?[Q] ", + genbuf, 3, LCECHO); + + if(genbuf[0] == 'e') { + int aborted; + + setutmpmode(EDITPLAN); + setuserfile(genbuf, fn_plans); + aborted = vedit(genbuf, NA, NULL); + if(aborted != -1) + outs("名片更新完畢"); + pressanykey(); + return 0; + } else if(genbuf[0] == 'd') { + setuserfile(genbuf, fn_plans); + unlink(genbuf); + outmsg("名片刪除完畢"); + } + return 0; +} + +int u_editcalendar() { + char genbuf[200]; + + getdata(b_lines - 1, 0, "行事曆 (D)刪除 (E)編輯 [Q]取消?[Q] ", + genbuf, 3, LCECHO); + + if(genbuf[0] == 'e') { + int aborted; + + setutmpmode(EDITPLAN); + setcalfile(genbuf, cuser.userid); + aborted = vedit(genbuf, NA, NULL); + if(aborted != -1) + outs("行事曆更新完畢"); + pressanykey(); + return 0; + } else if(genbuf[0] == 'd') { + setcalfile(genbuf, cuser.userid); + unlink(genbuf); + outmsg("行事曆刪除完畢"); + } + return 0; +} + +/* 使用者填寫註冊表格 */ +static void getfield(int line, char *info, char *desc, char *buf, int len) { + char prompt[STRLEN]; + char genbuf[200]; + + sprintf(genbuf, "原先設定:%-30.30s (%s)", buf, info); + move(line, 2); + outs(genbuf); + sprintf(prompt, "%s:", desc); + if(getdata_str(line + 1, 2, prompt, genbuf, len, DOECHO, buf)) + strcpy(buf, genbuf); + move(line, 2); + prints("%s:%s", desc, buf); + clrtoeol(); +} + +static int removespace(char* s){ + int i, index; + + for(i=0, index=0;s[i];i++){ + if (s[i] != ' ') + s[index++] = s[i]; + } + s[index] = '\0'; + return index; +} + +int u_register() { + char rname[20], addr[50], ident[11], mobile[20]; + char phone[20], career[40], email[50],birthday[9],sex_is[2],year,mon,day; + char ans[3], *ptr; + FILE *fn; + time_t now; + char genbuf[200]; + + if(cuser.userlevel & PERM_LOGINOK) { + outs("您的身份確認已經完成,不需填寫申請表"); + return XEASY; + } + if((fn = fopen(fn_register, "r"))) { + while(fgets(genbuf, STRLEN, fn)) { + if((ptr = strchr(genbuf, '\n'))) + *ptr = '\0'; + if(strncmp(genbuf, "uid: ", 5) == 0 && + strcmp(genbuf + 5, cuser.userid) == 0) { + fclose(fn); + outs("您的註冊申請單尚在處理中,請耐心等候"); + return XEASY; + } + } + fclose(fn); + } + + getdata(b_lines - 1, 0, "您確定要填寫註冊單嗎(Y/N)?[N] ", ans, 3, LCECHO); + if(ans[0] != 'y') + return FULLUPDATE; + + move(2, 0); + clrtobot(); + strcpy(ident, cuser.ident); + strcpy(rname, cuser.realname); + strcpy(addr, cuser.address); + strcpy(email, cuser.email); + sprintf(mobile,"0%09d",cuser.mobile); + sprintf(birthday, "%02i/%02i/%02i", + cuser.month, cuser.day, cuser.year % 100); + sex_is[0]=(cuser.sex % 8)+'1';sex_is[1]=0; + career[0] = phone[0] = '\0'; + while(1) { + clear(); + move(1, 0); + prints("%s(%s) 您好,請據實填寫以下的資料:", + cuser.userid, cuser.username); + do{ + getfield(3, "D120908396", "身分證號", ident, 11); + }while(removespace(ident)<10 || !isalpha(ident[0])); + do{ + getfield(5, "請用中文", "真實姓名", rname, 20); + }while(!removespace(rname) || isalpha(rname[0])); + do{ + getfield(7, "學校系級或單位職稱", "服務單位", career, 40); + }while(!removespace(career)); + do{ + getfield(9, "包括寢室或門牌號碼", "目前住址", addr, 50); + }while(!(addr[0])); + do{ + getfield(11, "包括長途撥號區域碼", "連絡電話", phone, 20); + }while(!removespace(phone)); + getfield(13, "只輸入數字 如:0912345678", "手機號碼", mobile, 20); + while(1) { + int len; + + getfield(15,"月月/日日/西元 如:09/27/76","生日",birthday,9); + len = strlen(birthday); + if(!len) { + sprintf(birthday, "%02i/%02i/%02i", + cuser.month, cuser.day, cuser.year % 100); + mon = cuser.month; + day = cuser.day; + year = cuser.year; + } else if(len == 8) { + mon = (birthday[0] - '0') * 10 + (birthday[1] - '0'); + day = (birthday[3] - '0') * 10 + (birthday[4] - '0'); + year = (birthday[6] - '0') * 10 + (birthday[7] - '0'); + } else + continue; + if(mon > 12 || mon < 1 || day > 31 || day < 1 || year > 90 || + year < 40) + continue; + break; + } + getfield(17, "1.葛格 2.姐接 ", "性別", sex_is, 2); + getfield(19, "身分認證用", "E-Mail Address", email, 50); + + getdata(b_lines - 1, 0, "以上資料是否正確(Y/N)?(Q)取消註冊 [N] ", + ans, 3, LCECHO); + if(ans[0] == 'q') + return 0; + if(ans[0] == 'y') + break; + } + strcpy(cuser.ident, ident); + strcpy(cuser.realname, rname); + strcpy(cuser.address, addr); + strcpy(cuser.email, email); + cuser.mobile = atoi(mobile); + cuser.sex= (sex_is[0] - '1') % 8; + cuser.month = mon; + cuser.day = day; + cuser.year = year; + if((fn = fopen(fn_register, "a"))) { + now = time(NULL); + trim(career); + trim(addr); + trim(phone); + fprintf(fn, "num: %d, %s", usernum, ctime(&now)); + fprintf(fn, "uid: %s\n", cuser.userid); + fprintf(fn, "ident: %s\n", ident); + fprintf(fn, "name: %s\n", rname); + fprintf(fn, "career: %s\n", career); + fprintf(fn, "addr: %s\n", addr); + fprintf(fn, "phone: %s\n", phone); + fprintf(fn, "mobile: %s\n", mobile); + fprintf(fn, "email: %s\n", email); + fprintf(fn, "----\n"); + fclose(fn); + } + clear(); + move(9,3); + prints("最後Post一篇\033[32m自我介紹文章\033[m給大家吧," + "告訴所有老骨頭\033[31m我來啦^$。\\n\n\n\n"); + pressanykey(); + cuser.userlevel |= PERM_POST; + brc_initial("WhoAmI"); + set_board(); + do_post(); + cuser.userlevel &= ~PERM_POST; + return 0; +} + +/* 列出所有註冊使用者 */ +extern struct uhash_t *uhash; +static int usercounter, totalusers, showrealname; +static ushort u_list_special; + +static int u_list_CB(userec_t *uentp) { + static int i; + char permstr[8], *ptr; + register int level; + + if(uentp == NULL) { + move(2, 0); + clrtoeol(); + prints("\033[7m 使用者代號 %-25s 上站 文章 %s " + "最近光臨日期 \033[0m\n", + showrealname ? "真實姓名" : "綽號暱稱", + HAS_PERM(PERM_SEEULEVELS) ? "等級" : ""); + i = 3; + return 0; + } + + if(bad_user_id(uentp->userid)) + return 0; + + if((uentp->userlevel & ~(u_list_special)) == 0) + return 0; + + if(i == b_lines) { + prints("\033[34;46m 已顯示 %d/%d 人(%d%%) \033[31;47m " + "(Space)\033[30m 看下一頁 \033[31m(Q)\033[30m 離開 \033[m", + usercounter, totalusers, usercounter * 100 / totalusers); + i = igetch(); + if(i == 'q' || i == 'Q') + return QUIT; + i = 3; + } + if(i == 3) { + move(3, 0); + clrtobot(); + } + + level = uentp->userlevel; + strcpy(permstr, "----"); + if(level & PERM_SYSOP) + permstr[0] = 'S'; + else if(level & PERM_ACCOUNTS) + permstr[0] = 'A'; + else if(level & PERM_DENYPOST) + permstr[0] = 'p'; + + if(level & (PERM_BOARD)) + permstr[1] = 'B'; + else if(level & (PERM_BM)) + permstr[1] = 'b'; + + if(level & (PERM_XEMPT)) + permstr[2] = 'X'; + else if(level & (PERM_LOGINOK)) + permstr[2] = 'R'; + + if(level & (PERM_CLOAK | PERM_SEECLOAK)) + permstr[3] = 'C'; + + ptr = (char *)Cdate(&uentp->lastlogin); + ptr[18] = '\0'; + prints("%-14s %-27.27s%5d %5d %s %s\n", + uentp->userid, + showrealname ? uentp->realname : uentp->username, + uentp->numlogins, uentp->numposts, + HAS_PERM(PERM_SEEULEVELS) ? permstr : "", ptr); + usercounter++; + i++; + return 0; +} + +int u_list() { + char genbuf[3]; + + setutmpmode(LAUSERS); + showrealname = u_list_special = usercounter = 0; + totalusers = uhash->number; + if(HAS_PERM(PERM_SEEULEVELS)) { + getdata(b_lines - 1, 0, "觀看 [1]特殊等級 (2)全部?", + genbuf, 3, DOECHO); + if(genbuf[0] != '2') + u_list_special = PERM_BASIC | PERM_CHAT | PERM_PAGE | PERM_POST | PERM_LOGINOK | PERM_BM; + } + if(HAS_PERM(PERM_CHATROOM) || HAS_PERM(PERM_SYSOP)) { + getdata(b_lines - 1, 0, "顯示 [1]真實姓名 (2)暱稱?", + genbuf, 3, DOECHO); + if(genbuf[0] != '2') + showrealname = 1; + } + u_list_CB(NULL); + if(passwd_apply(u_list_CB) == -1) { + outs(msg_nobody); + return XEASY; + } + move(b_lines, 0); + clrtoeol(); + prints("\033[34;46m 已顯示 %d/%d 的使用者(系統容量無上限) " + "\033[31;47m (請按任意鍵繼續) \033[m", usercounter, totalusers); + egetch(); + return 0; +} diff --git a/pttbbs/mbbsd/var.c b/pttbbs/mbbsd/var.c new file mode 100644 index 00000000..7b07f63b --- /dev/null +++ b/pttbbs/mbbsd/var.c @@ -0,0 +1,268 @@ +/* $Id: var.c,v 1.1 2002/03/07 15:13:48 in2 Exp $ */ +#include +#include +#include "config.h" +#include "pttstruct.h" +#include "common.h" + +char *str_permid[] = { + "基本權力", /* PERM_BASIC */ + "進入聊天室", /* PERM_CHAT */ + "找人聊天", /* PERM_PAGE */ + "發表文章", /* PERM_POST */ + "註冊程序認證", /* PERM_LOGINOK */ + "信件無上限", /* PERM_MAILLIMIT */ + "隱身術", /* PERM_CLOAK */ + "看見忍者", /* PERM_SEECLOAK */ + "永久保留帳號", /* PERM_XEMPT */ + "站長隱身術", /* PERM_DENYPOST */ + "板主", /* PERM_BM */ + "帳號總管", /* PERM_ACCOUNTS */ + "聊天室總管", /* PERM_CHATCLOAK */ + "看板總管", /* PERM_BOARD */ + "站長", /* PERM_SYSOP */ + "BBSADM", /* PERM_POSTMARK */ + "不列入排行榜", /* PERM_NOTOP */ + "違法通緝中", /* PERM_VIOLATELAW */ + "不接受站外的信", /* PERM_ */ + "沒想到", /* PERM_ */ + "視覺站長", /* PERM_VIEWSYSOP */ + "觀察使用者行蹤", /* PERM_LOGUSER */ + "精華區總整理權", /* PERM_Announce */ + "公關組", /* PERM_RELATION */ + "特務組", /* PERM_SMG */ + "程式組", /* PERM_PRG */ + "活動組", /* PERM_ACTION */ + "美工組", /* PERM_PAINT */ + "立法組", /* PERM_LAW */ + "小組長", /* PERM_SYSSUBOP */ + "一級主管", /* PERM_LSYSOP */ + "Ptt" /* PERM_PTT */ +}; + +char *str_permboard[] = { + "不可 Zap", /* BRD_NOZAP */ + "不列入統計", /* BRD_NOCOUNT */ + "不轉信", /* BRD_NOTRAN */ + "群組版", /* BRD_GROUP */ + "隱藏版", /* BRD_HIDE */ + "限制(不需設定)", /* BRD_POSTMASK */ + "匿名版", /* BRD_ANONYMOUS */ + "預設匿名版", /* BRD_DEFAULTANONYMOUS */ + "違法改進中看版", /* BRD_BAD */ + "連署專用看版", /* BRD_VOTEBOARD */ + "沒想到", + "沒想到", + "沒想到", + "沒想到", + "沒想到", + "沒想到", + "沒想到", + "沒想到", + "沒想到", + "沒想到", + "沒想到", + "沒想到", + "沒想到", + "沒想到", + "沒想到", + "沒想到", + "沒想到", + "沒想到", + "沒想到", + "沒想到", + "沒想到", + "沒想到", +}; + +int usernum; +pid_t currpid; /* current process ID */ +unsigned int currstat; +int currmode = 0; +int curredit = 0; +int showansi = 1; +int curr_idle_timeout = IDLE_TIMEOUT; +time_t login_start_time; +userec_t cuser; /* current user structure */ +userec_t xuser; /* lookup user structure */ +char quote_file[80] = "\0"; +char quote_user[80] = "\0"; +time_t paste_time; +char paste_title[STRLEN]; +char paste_path[256]; +int paste_level; +char currtitle[40] = "\0"; +char vetitle[40] = "\0"; +char currowner[IDLEN + 2] = "\0"; +char currauthor[IDLEN + 2] = "\0"; +char currfile[FNLEN]; /* current file name @ bbs.c mail.c */ +unsigned char currfmode; /* current file mode */ +char currboard[IDLEN + 2]; +int currbid; +unsigned int currbrdattr; +char currBM[IDLEN * 3 + 10]; +char reset_color[4] = "\033[m"; +char margs[64] = "\0"; /* main argv list*/ +crosspost_t postrecord; /* anti cross post */ + +/* global string variables */ +/* filename */ + +char *fn_passwd = FN_PASSWD; +char *fn_board = FN_BOARD; +char *fn_note_ans = FN_NOTE_ANS; +char *fn_register = "register.new"; +char *fn_plans = "plans"; +char *fn_writelog = "writelog"; +char *fn_talklog = "talklog"; +char *fn_overrides = FN_OVERRIDES; +char *fn_reject = FN_REJECT; +char *fn_canvote = FN_CANVOTE; +char *fn_notes = "notes"; +char *fn_water = FN_WATER; +char *fn_visable = FN_VISABLE; +char *fn_mandex = "/.Names"; +char *fn_proverb = "proverb"; + +/* are descript in userec.loginview */ + +char *loginview_file[NUMVIEWFILE][2] = { + {FN_NOTE_ANS ,"酸甜苦辣流言板"}, + {FN_TOPSONG ,"點歌排行榜" }, + {"etc/topusr" ,"十大排行榜" }, + {"etc/topusr100" ,"百大排行榜" }, + {"etc/birth.today" ,"今日壽星" }, + {"etc/weather.tmp" ,"天氣快報" }, + {"etc/stock.tmp" ,"股市快報" }, + {"etc/day" ,"今日十大話題" }, + {"etc/week" ,"一週五十大話題"}, + {"etc/today" ,"今天上站人次" }, + {"etc/yesterday" ,"昨日上站人次" }, + {"etc/history" ,"歷史上的今天" }, + {"etc/topboardman" ,"精華區排行榜" }, + {"etc/topboard.tmp","看板人氣排行榜"} +}; + +/* message */ +char *msg_seperator = MSG_SEPERATOR; +char *msg_mailer = MSG_MAILER; +char *msg_shortulist = MSG_SHORTULIST; + +char *msg_cancel = MSG_CANCEL; +char *msg_usr_left = MSG_USR_LEFT; +char *msg_nobody = MSG_NOBODY; + +char *msg_sure_ny = MSG_SURE_NY; +char *msg_sure_yn = MSG_SURE_YN; + +char *msg_bid = MSG_BID; +char *msg_uid = MSG_UID; + +char *msg_del_ok = MSG_DEL_OK; +char *msg_del_ny = MSG_DEL_NY; + +char *msg_fwd_ok = MSG_FWD_OK; +char *msg_fwd_err1 = MSG_FWD_ERR1; +char *msg_fwd_err2 = MSG_FWD_ERR2; + +char *err_board_update = ERR_BOARD_UPDATE; +char *err_bid = ERR_BID; +char *err_uid = ERR_UID; +char *err_filename = ERR_FILENAME; + +char *str_mail_address = "." BBSUSER "@" MYHOSTNAME; +char *str_new = "new"; +char *str_reply = "Re: "; +char *str_space = " \t\n\r"; +char *str_sysop = "SYSOP"; +char *str_author1 = STR_AUTHOR1; +char *str_author2 = STR_AUTHOR2; +char *str_post1 = STR_POST1; +char *str_post2 = STR_POST2; +char *BBSName = BBSNAME; + +/* #define MAX_MODES 78 */ +/* MAX_MODES is defined in common.h */ + +char *ModeTypeTable[MAX_MODES] = { + "發呆", /* IDLE */ + "主選單", /* MMENU */ + "系統維護", /* ADMIN */ + "郵件選單", /* MAIL */ + "交談選單", /* TMENU */ + "使用者選單", /* UMENU */ + "XYZ 選單", /* XMENU */ + "分類看板", /* CLASS */ + "Play選單", /* PMENU */ + "編特別名單", /* NMENU */ + "Ptt量販店", /* PSALE */ + "發表文章", /* POSTING */ + "看板列表", /* READBRD */ + "閱\讀文章", /* READING */ + "新文章列表", /* READNEW */ + "選擇看板", /* SELECT */ + "讀信", /* RMAIL */ + "寫信", /* SMAIL */ + "聊天室", /* CHATING */ + "其他", /* XMODE */ + "尋找好友", /* FRIEND */ + "上線使用者", /* LAUSERS */ + "使用者名單", /* LUSERS */ + "追蹤站友", /* MONITOR */ + "呼叫", /* PAGE */ + "查詢", /* TQUERY */ + "交談", /* TALK */ + "編名片檔", /* EDITPLAN */ + "編簽名檔", /* EDITSIG */ + "投票中", /* VOTING */ + "設定資料", /* XINFO */ + "寄給站長", /* MSYSOP */ + "汪汪汪", /* WWW */ + "打大老二", /* BIG2 */ + "回應", /* REPLY */ + "被水球打中", /* HIT */ + "水球準備中", /* DBACK */ + "筆記本", /* NOTE */ + "編輯文章", /* EDITING */ + "發系統通告", /* MAILALL */ + "摸兩圈", /* MJ */ + "電腦擇友", /* P_FRIEND */ + "上站途中", /* LOGIN */ + "查字典", /* DICT */ + "打橋牌", /* BRIDGE */ + "找檔案", /* ARCHIE */ + "打地鼠", /* GOPHER */ + "看News", /* NEWS */ + "情書產生器", /* LOVE */ + "編籍輔助器", /* EDITEXP */ + "申請IP位址", /* IPREG */ + "網管辦公中", /* NetAdm */ + "虛擬實業坊", /* DRINK */ + "計算機", /* CAL */ + "編籍座右銘", /* PROVERB */ + "公佈欄", /* ANNOUNCE */ + "刻流言版", /* EDNOTE */ + "英漢翻譯機", /* CDICT */ + "檢視自己物品", /* LOBJ */ + "點歌", /* OSONG */ + "正在玩小雞", /* CHICKEN */ + "玩彩券", /* TICKET */ + "猜數字", /* GUESSNUM */ + "遊樂場", /* AMUSE */ + "黑白棋", /* OTHELLO */ + "玩骰子", /* DICE*/ + "發票對獎", /* VICE */ + "逼逼摳ing", /* BBCALL */ + "繳罰單", /* CROSSPOST */ + "五子棋", /* M_FIVE */ + "21點ing", /* JACK_CARD */ + "10點半ing", /* TENHALF */ + "超級九十九", /* CARD_99 */ + "火車查詢", /* RAIL_WAY */ + "搜尋選單", /* SREG */ + "下象棋", /* CHC */ + "下暗琪", /* DARK */ + "NBA大猜測" /* TMPJACK */ + "Ptt查榜系統", /* JCEE */ + "重編文章" /* REEDIT */ +}; diff --git a/pttbbs/mbbsd/vice.c b/pttbbs/mbbsd/vice.c new file mode 100644 index 00000000..46f695d9 --- /dev/null +++ b/pttbbs/mbbsd/vice.c @@ -0,0 +1,151 @@ +/* $Id: vice.c,v 1.1 2002/03/07 15:13:48 in2 Exp $ */ +#include +#include +#include +#include +#include +#include "config.h" +#include "pttstruct.h" +#include "common.h" +#include "modes.h" +#include "proto.h" +extern int usernum; + +#define VICE_PLAY BBSHOME "/etc/vice/vice.play" +#define VICE_DATA "vice.new" +#define VICE_BINGO BBSHOME "/etc/vice.bingo" +#define VICE_SHOW BBSHOME "/etc/vice.show" +#define VICE_LOST BBSHOME "/etc/vice/vice.lost" +#define VICE_WIN BBSHOME "/etc/vice/vice.win" +#define VICE_END BBSHOME "/etc/vice/vice.end" +#define VICE_NO BBSHOME "/etc/vice/vice.no" +#define MAX_NO_PICTURE 2 +#define MAX_WIN_PICTURE 2 +#define MAX_LOST_PICTURE 3 +#define MAX_END_PICTURE 5 + + + +static int vice_load(char tbingo[6][15]) { + FILE *fb = fopen(VICE_BINGO, "r"); + char buf[16], *ptr; + int i = 0; + if(!fb) return -1; bzero((char*)tbingo, sizeof(tbingo)); + while(i < 6 && fgets(buf, 15, fb)) { + if((ptr = strchr(buf, '\n'))) + *ptr = 0; + strcpy(tbingo[i++], buf); + } + fclose(fb); + return 0; +} + +static int check(char tbingo[6][15], char *data) { + int i = 0, j; + + if(!strcmp(data, tbingo[0])) + return 8; + + for(j = 8; j > 0; j--) + for(i = 1; i < 6; i++) + if(!strncmp(data+8-j, tbingo[i]+8-j,j)) + return j - 1; + return 0; +} +// Ptt: showfile ran_showfile more 三者要整合 +static int ran_showfile(int y, int x, char *filename, int maxnum) { + FILE *fs; + char buf[512]; + + bzero(buf, sizeof(char) * 512); + sprintf(buf, "%s%d", filename, rand() % maxnum + 1); + if(!(fs = fopen(buf, "r"))) { + move(10,10); + prints("can't open file: %s", buf); + return 0; + } + + move(y, x); + + while(fgets(buf, 511, fs)) + prints("%s", buf); + + fclose(fs); + return 1; +} + +static int ran_showmfile(char *filename, int maxnum) { + char buf[256]; + + sprintf(buf, "%s%d", filename, rand() % maxnum + 1); + return more(buf, YEA); +} + +extern userec_t cuser; + +int vice_main() { + FILE *fd; + char tbingo[6][15]; + char buf_data[256] + , serial[16], ch[2], *ptr; + int TABLE[] = {0,10,200,1000,4000,10000,40000,100000,200000}; + int total = 0, money, i = 4, j = 0; + + setuserfile(buf_data, VICE_DATA); + if(!dashf(buf_data)) { + ran_showmfile(VICE_NO, MAX_NO_PICTURE); + return 0; + } + if(vice_load(tbingo)<0) return -1; + clear(); + ran_showfile(0, 0, VICE_PLAY, 1); + ran_showfile(10, 0, VICE_SHOW, 1); + + if(!(fd = fopen(buf_data, "r"))) + return 0; + j = 0; + i = 0; + move(10,24); + clrtoeol(); + prints("這一期的發票號碼"); + while(fgets(serial, 15, fd)) { + if((ptr = strchr(serial,'\r'))) + *ptr = 0; + if(j == 0) + i++; + move(10 + i, 24 + j); + prints("%s", serial); + j += 9; + j %= 45; + } + getdata(8, 0, "按'c'開始對獎了(或是任意鍵離開)): ", ch, 2, LCECHO); + if(ch[0] != 'c' || lockutmpmode(VICE, LOCK_MULTI)){ + fclose(fd); + return 0; + } + + showtitle("發票對獎", BBSNAME); + rewind(fd); + while(fgets(serial, 15, fd)) { + if((ptr = strchr(serial,'\n'))) + *ptr = 0; + money = TABLE[check(tbingo,serial)]; + total += money; + prints("%s 中了 %d\n", serial, money); + } + pressanykey(); + if(total > 0) { + ran_showmfile(VICE_WIN, MAX_WIN_PICTURE); + move(22,0); + clrtoeol(); + prints("全部的發票中了 %d 塊錢\n", total); + demoney(total); + } else + ran_showmfile(VICE_LOST, MAX_LOST_PICTURE); + + fclose(fd); + unlink(buf_data); + pressanykey(); + unlockutmpmode(); + return 0; +} diff --git a/pttbbs/mbbsd/vote.c b/pttbbs/mbbsd/vote.c new file mode 100644 index 00000000..62916c99 --- /dev/null +++ b/pttbbs/mbbsd/vote.c @@ -0,0 +1,1068 @@ +/* $Id: vote.c,v 1.1 2002/03/07 15:13:48 in2 Exp $ */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "config.h" +#include "pttstruct.h" +#include "modes.h" +#include "common.h" +#include "perm.h" +#include "proto.h" + +static int total; +extern int numboards; +extern boardheader_t *bcache; /* Thor: for speed up */ +extern char *err_board_update; +extern char *fn_board; +extern char *msg_seperator; +extern int t_lines, t_columns; /* Screen size / width */ +extern int b_lines; /* Screen bottom line number: t_lines-1 */ +extern int currmode; +extern int usernum; +extern char currboard[]; /* name of currently selected board */ +extern userec_t cuser; + +static char STR_bv_control[] = "control"; /* 投票日期 選項 */ +static char STR_bv_desc[] = "desc"; /* 投票目的 */ +static char STR_bv_ballots[] = "ballots"; +static char STR_bv_flags[] = "flags"; +static char STR_bv_comments[] = "comments"; /* 投票者的建意 */ +static char STR_bv_limited[] = "limited"; /* 私人投票 */ +static char STR_bv_title[] = "vtitle"; + +static char STR_bv_results[] = "results"; + +static char STR_new_control[] = "control0"; /* 投票日期 選項 */ +static char STR_new_desc[] = "desc0"; /* 投票目的 */ +static char STR_new_ballots[] = "ballots0"; +static char STR_new_flags[] = "flags0"; +static char STR_new_comments[] = "comments0"; /* 投票者的建意 */ +static char STR_new_limited[] = "limited0"; /* 私人投票 */ +static char STR_new_title[] = "vtitle0"; + +int strip_ansi(char *buf, char *str, int mode) { + register int ansi, count = 0; + + for(ansi = 0; *str /*&& *str != '\n' */; str++) { + if(*str == 27) { + if(mode) { + if(buf) + *buf++ = *str; + count++; + } + ansi = 1; + } else if(ansi && strchr("[;1234567890mfHABCDnsuJKc=n", *str)) { + if((mode == NO_RELOAD && !strchr("c=n", *str)) || + (mode == ONLY_COLOR && strchr("[;1234567890m", *str))) { + if(buf) + *buf++ = *str; + count++; + } + if(strchr("mHn ", *str)) + ansi = 0; + } else { + ansi =0; + if(buf) + *buf++ = *str; + count++; + } + } + if(buf) + *buf = '\0'; + return count; +} + +void b_suckinfile(FILE *fp, char *fname) { + FILE *sfp; + + if((sfp = fopen(fname, "r"))) { + char inbuf[256]; + + while(fgets(inbuf, sizeof(inbuf), sfp)) + fputs(inbuf, fp); + fclose(sfp); + } +} + +static void b_count(char *buf, int counts[]) { + char inchar; + int fd; + + memset(counts, 0, 31 * sizeof(counts[0])); + total = 0; + if((fd = open(buf, O_RDONLY)) != -1) { + flock(fd, LOCK_EX); /* Thor: 防止多人同時算 */ + while(read(fd, &inchar, 1) == 1) { + counts[(int)(inchar - 'A')]++; + total++; + } + flock(fd, LOCK_UN); + close(fd); + } +} + + +static int b_nonzeroNum(char *buf) { + int i = 0; + char inchar; + int fd; + + if((fd = open(buf, O_RDONLY)) != -1) { + while(read(fd, &inchar, 1) == 1) + if(inchar) + i++; + close(fd); + } + return i; +} + +static void vote_report(char *bname, char *fname, char *fpath) { + register char *ip; + time_t dtime; + int fd, bid; + fileheader_t header; + + ip = fpath; + while(*(++ip)); + *ip++ = '/'; + + /* get a filename by timestamp */ + + dtime = time(0); + for(;;) { + sprintf(ip, "M.%ld.A", ++dtime); + fd = open(fpath, O_CREAT | O_EXCL | O_WRONLY, 0644); + if(fd >= 0) + break; + dtime++; + } + close(fd); + + log_usies("TESTfn", fname); + log_usies("TESTfp", fpath); + + unlink(fpath); + link(fname, fpath); + + /* append record to .DIR */ + + memset(&header, 0, sizeof(fileheader_t)); + strcpy(header.owner, "[馬路探子]"); + sprintf(header.title, "[%s] 看板 選情報導", bname); + { + register struct tm *ptime = localtime(&dtime); + + sprintf(header.date, "%2d/%02d", ptime->tm_mon + 1, ptime->tm_mday); + } + strcpy(header.filename, ip); + + strcpy(ip, ".DIR"); + if((fd = open(fpath, O_WRONLY | O_CREAT, 0644)) >= 0) { + flock(fd, LOCK_EX); + lseek(fd, 0, SEEK_END); + write(fd, &header, sizeof(fileheader_t)); + flock(fd, LOCK_UN); + close(fd); + if((bid = getbnum(bname)) > 0) + setbtotal(bid); + + } + +} + +static void b_result_one(boardheader_t *fh, int ind) { + FILE *cfp, *tfp, *frp, *xfp; + char *bname ; + char buf[STRLEN]; + char inbuf[80]; + int counts[31]; + int num ; + int junk; + char b_control[64]; + char b_newresults[64]; + char b_report[64]; + time_t closetime, now; + + fh->bvote--; + + if(fh->bvote==0) + fh->bvote=2; + else if(fh->bvote==2) + fh->bvote=1; + + if(ind) { + sprintf(STR_new_ballots, "%s%d", STR_bv_ballots, ind); + sprintf(STR_new_control, "%s%d", STR_bv_control, ind); + sprintf(STR_new_desc, "%s%d", STR_bv_desc, ind); + sprintf(STR_new_flags, "%s%d", STR_bv_flags, ind); + sprintf(STR_new_comments, "%s%d", STR_bv_comments, ind); + sprintf(STR_new_limited, "%s%d", STR_bv_limited, ind); + sprintf(STR_new_title, "%s%d", STR_bv_title, ind); + } else { + strcpy(STR_new_ballots, STR_bv_ballots); + strcpy(STR_new_control, STR_bv_control); + strcpy(STR_new_desc, STR_bv_desc); + strcpy(STR_new_flags, STR_bv_flags); + strcpy(STR_new_comments, STR_bv_comments); + strcpy(STR_new_limited, STR_bv_limited); + strcpy(STR_new_title, STR_bv_title); + } + + bname = fh->brdname; + + setbfile(buf, bname, STR_new_control); + cfp = fopen(buf,"r"); + fscanf(cfp, "%d\n%lu\n", &junk, &closetime); + fclose(cfp); + + setbfile(b_control, bname, "tmp"); + if(rename(buf, b_control) == -1) + return; + setbfile(buf, bname, STR_new_flags); + num = b_nonzeroNum(buf); + unlink(buf); + setbfile(buf, bname, STR_new_ballots); + b_count(buf, counts); + unlink(buf); + + setbfile(b_newresults, bname, "newresults"); + if((tfp = fopen(b_newresults, "w")) == NULL) + return; + + now = time(NULL); + setbfile(buf, bname, STR_new_title); + + if((xfp=fopen(buf,"r"))) { + fgets(inbuf, sizeof(inbuf), xfp); + fprintf(tfp, "%s\n◆ 投票名稱: %s\n\n", msg_seperator, inbuf); + } + + fprintf(tfp, "%s\n◆ 投票中止於: %s\n\n◆ 票選題目描述:\n\n", + msg_seperator, ctime(&closetime)); + fh->vtime = now; + + setbfile(buf, bname, STR_new_desc); + + b_suckinfile(tfp, buf); + unlink(buf); + + if((cfp = fopen(b_control, "r"))) { + fgets(inbuf, sizeof(inbuf), cfp); + fgets(inbuf, sizeof(inbuf), cfp); + fprintf(tfp, "\n◆投票結果:(共有 %d 人投票,每人最多可投 %d 票)\n", + num, junk); + while(fgets(inbuf, sizeof(inbuf), cfp)) { + inbuf[(strlen(inbuf) - 1)] = '\0'; + num = counts[inbuf[0] - 'A']; + fprintf(tfp, " %-42s %3d 票 %02.2f%%\n", inbuf + 3, num, + (float)(num*100)/(float)(total)); + } + fclose(cfp); + } + unlink(b_control); + + fprintf(tfp, "%s\n◆ 使用者建議:\n\n", msg_seperator); + setbfile(buf, bname, STR_new_comments); + b_suckinfile(tfp, buf); + unlink(buf); + + fprintf(tfp, "%s\n◆ 總票數 = %d 票\n\n", msg_seperator, total); + fclose(tfp); + + setbfile(b_report, bname, "report"); + if((frp = fopen(b_report, "w"))) { + b_suckinfile(frp, b_newresults); + fclose(frp); + } + sprintf(inbuf, "boards/%s", bname); + vote_report(bname, b_report, inbuf); + if(!(fh->brdattr &BRD_NOCOUNT)) { + sprintf(inbuf, "boards/%s", "Record"); + vote_report(bname, b_report, inbuf); + } + unlink(b_report); + + tfp = fopen(b_newresults, "a"); + setbfile(buf, bname, STR_bv_results); + b_suckinfile(tfp, buf); + fclose(tfp); + Rename(b_newresults, buf); +} + +static void b_result(boardheader_t *fh) { + FILE *cfp; + time_t closetime, now; + int i; + char buf[STRLEN]; + char temp[STRLEN]; + + now = time(NULL); + for(i = 0; i < 9; i++) { + if(i) + sprintf(STR_new_control, "%s%d", STR_bv_control, i); + else + strcpy(STR_new_control, STR_bv_control); + + setbfile(buf, fh->brdname, STR_new_control); + cfp = fopen(buf,"r"); + if (!cfp) + continue; + fgets(temp,sizeof(temp),cfp); + fscanf(cfp, "%lu\n", &closetime); + fclose(cfp); + if(closetime < now) + b_result_one(fh,i); + } +} + +static int b_close(boardheader_t *fh) { + time_t now; + now = time(NULL); + + if(fh->bvote == 2) { + if(fh->vtime < now - 3 * 86400) { + fh->bvote = 0; + return 1; + } + else + return 0; + } + b_result(fh); + return 1; +} + +int b_closepolls() { + static char *fn_vote_polling = ".polling"; + boardheader_t *fhp; + FILE *cfp; + time_t now; + int pos, dirty; + time_t last; + char timebuf[100]; + + now = time(NULL); +/* Edited by CharlieL for can't auto poll bug */ + + if((cfp = fopen(fn_vote_polling,"r"))) { + fgets(timebuf,100*sizeof(char),cfp); + sscanf(timebuf, "%lu", &last); + fclose(cfp); + if(last + 3600 >= now) + return 0; + } + + if((cfp = fopen(fn_vote_polling, "w")) == NULL) + return 0; + fprintf(cfp, "%lu\n%s\n", now, ctime(&now)); + fclose(cfp); + + dirty = 0; + for(fhp = bcache, pos = 1; pos <= numboards; fhp++, pos++) { + if(fhp->bvote && b_close(fhp)) { + if(substitute_record(fn_board, fhp, sizeof(*fhp), pos) == -1) + outs(err_board_update); + dirty = 1; + } + } + if(dirty) /* vote flag changed */ + reset_board(pos); + + return 0; +} + +static int vote_view(char *bname, int index) { + boardheader_t *fhp; + FILE* fp; + char buf[STRLEN], genbuf[STRLEN], inbuf[STRLEN]; + struct stat stbuf; + int fd, num = 0, i, pos, counts[31]; + time_t closetime; + + if(index) { + sprintf(STR_new_ballots, "%s%d", STR_bv_ballots, index); + sprintf(STR_new_control, "%s%d", STR_bv_control, index); + sprintf(STR_new_desc, "%s%d", STR_bv_desc, index); + sprintf(STR_new_flags, "%s%d", STR_bv_flags, index); + sprintf(STR_new_comments, "%s%d", STR_bv_comments, index); + sprintf(STR_new_limited, "%s%d", STR_bv_limited, index); + sprintf(STR_new_title, "%s%d", STR_bv_title, index); + } else { + strcpy(STR_new_ballots, STR_bv_ballots); + strcpy(STR_new_control, STR_bv_control); + strcpy(STR_new_desc, STR_bv_desc); + strcpy(STR_new_flags, STR_bv_flags); + strcpy(STR_new_comments, STR_bv_comments); + strcpy(STR_new_limited, STR_bv_limited); + strcpy(STR_new_title, STR_bv_title); + } + + setbfile(buf, bname, STR_new_ballots); + if((fd = open(buf, O_RDONLY)) > 0) { + fstat(fd, &stbuf); + close(fd); + } else + stbuf.st_size = 0; + + setbfile(buf, bname, STR_new_title); + move(0, 0); + clrtobot(); + + if((fp = fopen(buf, "r"))) { + fgets(inbuf, sizeof(inbuf), fp); + prints("\n投票名稱: %s", inbuf); + } + + setbfile(buf, bname, STR_new_control); + fp = fopen(buf, "r"); + fgets(inbuf, sizeof(inbuf), fp); + fscanf(fp, "%lu\n", &closetime); + + prints("\n◆ 預知投票紀事: 每人最多可投 %d 票,目前共有 %d 票,\n" + "本次投票將結束於 %s", atoi(inbuf), stbuf.st_size, + ctime(&closetime)); + + /* Thor: 開放 票數 預知 */ + setbfile(buf, bname, STR_new_flags); + num = b_nonzeroNum(buf); + + setbfile(buf, bname, STR_new_ballots); + b_count(buf, counts); + + prints("共有 %d 人投票\n", num); + total = 0; + + while(fgets(inbuf, sizeof(inbuf), fp)) { + inbuf[(strlen(inbuf) - 1)] = '\0'; + inbuf[30] = '\0'; /* truncate */ + i = inbuf[0] - 'A'; + num = counts[i]; + move(i % 15 + 6, i / 15 * 40); + prints(" %-32s%3d 票", inbuf, num); + total += num; + } + fclose(fp); + pos = getbnum(bname); + fhp = bcache + pos - 1; + move(t_lines - 3, 0); + prints("◆ 目前總票數 = %d 票", total); + getdata(b_lines - 1, 0, "(A)取消投票 (B)提早開票 (C)繼續?[C] ", genbuf, + 4, LCECHO); + if(genbuf[0] == 'a') { + setbfile(buf, bname, STR_new_control); + unlink(buf); + setbfile(buf, bname, STR_new_flags); + unlink(buf); + setbfile(buf, bname, STR_new_ballots); + unlink(buf); + setbfile(buf, bname, STR_new_desc); + unlink(buf); + setbfile(buf, bname, STR_new_limited); + unlink(buf); + setbfile(buf,bname, STR_new_title); + unlink(buf); + + if(fhp->bvote) + fhp->bvote--; + if (fhp->bvote == 2) + fhp->bvote = 1; + + if(substitute_record(fn_board, fhp, sizeof(*fhp), pos) == -1) + outs(err_board_update); + reset_board(pos); + } else if(genbuf[0] == 'b') { + b_result_one(fhp,index); + if(substitute_record(fn_board, fhp, sizeof(*fhp), pos) == -1) + outs(err_board_update); + + reset_board(pos); + } + return FULLUPDATE; +} + +static int vote_view_all(char *bname) { + int i; + int x = -1; + FILE *fp, *xfp; + char buf[STRLEN], genbuf[STRLEN]; + char inbuf[80]; + + strcpy(STR_new_control, STR_bv_control); + strcpy(STR_new_title, STR_bv_title); + setbfile(buf, bname, STR_new_control); + move(0, 0); + if((fp=fopen(buf,"r"))) { + prints("(0) "); + x = 0; + fclose(fp); + + setbfile(buf, bname, STR_new_title); + if((xfp=fopen(buf,"r"))) + fgets(inbuf, sizeof(inbuf), xfp); + else + strcpy(inbuf, "無標題"); + prints("%s\n", inbuf); + fclose(xfp); + } + + for(i = 1; i < 9; i++) { + sprintf(STR_new_control, "%s%d", STR_bv_control, i); + sprintf(STR_new_title, "%s%d", STR_bv_title, i); + setbfile(buf, bname, STR_new_control); + if((fp=fopen(buf,"r"))) { + prints("(%d) ", i); + x = i; + fclose(fp); + + setbfile(buf, bname, STR_new_title); + if((xfp=fopen(buf,"r"))) + fgets(inbuf, sizeof(inbuf), xfp); + else + strcpy(inbuf, "無標題"); + prints("%s\n", inbuf); + fclose(xfp); + } + } + + if(x < 0) + return FULLUPDATE; + sprintf(buf, "要看幾號投票 [%d] ", x); + + getdata(b_lines - 1, 0, buf, genbuf, 4, LCECHO); + + if(genbuf[0] < '0' || genbuf[0] > '8') + genbuf[0] = '0'+x; + + if(genbuf[0] != '0') + sprintf(STR_new_control, "%s%c", STR_bv_control, genbuf[0]); + else + strcpy(STR_new_control, STR_bv_control); + + setbfile(buf, bname, STR_new_control); + + if((fp=fopen(buf,"r"))) { + fclose(fp); + return vote_view(bname, genbuf[0] - '0'); + } + else + return FULLUPDATE; +} + +static int vote_maintain(char *bname) { + FILE *fp = NULL; + char inbuf[STRLEN], buf[STRLEN]; + int num = 0, aborted, pos, x, i; + time_t closetime; + boardheader_t *fhp; + char genbuf[4]; + + if(!(currmode & MODE_BOARD)) + return 0; + if((pos = getbnum(bname)) <= 0) + return 0; + + stand_title("舉辦投票"); + fhp = bcache + pos - 1; + +/* CharlieL */ + if(fhp->bvote != 2 && fhp->bvote !=0) { + getdata(b_lines - 1, 0, + "(V)觀察目前投票 (M)舉辦新投票 (A)取消所有投票 (Q)繼續 [Q]", + genbuf, 4, LCECHO); + if(genbuf[0] == 'v') + return vote_view_all(bname); + else if(genbuf[0] == 'a') { + fhp->bvote=0; + + setbfile(buf, bname, STR_bv_control); + unlink(buf); + setbfile(buf, bname, STR_bv_flags); + unlink(buf); + setbfile(buf, bname, STR_bv_ballots); + unlink(buf); + setbfile(buf, bname, STR_bv_desc); + unlink(buf); + setbfile(buf, bname, STR_bv_limited); + unlink(buf); + setbfile(buf, bname, STR_bv_title); + unlink(buf); + + for(i = 1; i < 9; i++) { + sprintf(STR_new_ballots, "%s%d", STR_bv_ballots, i); + sprintf(STR_new_control, "%s%d", STR_bv_control, i); + sprintf(STR_new_desc, "%s%d", STR_bv_desc, i); + sprintf(STR_new_flags, "%s%d", STR_bv_flags, i); + sprintf(STR_new_comments, "%s%d", STR_bv_comments, i); + sprintf(STR_new_limited, "%s%d", STR_bv_limited, i); + sprintf(STR_new_title, "%s%d", STR_bv_title, i); + + setbfile(buf, bname, STR_new_control); + unlink(buf); + setbfile(buf, bname, STR_new_flags); + unlink(buf); + setbfile(buf, bname, STR_new_ballots); + unlink(buf); + setbfile(buf, bname, STR_new_desc); + unlink(buf); + setbfile(buf, bname, STR_new_limited); + unlink(buf); + setbfile(buf, bname, STR_new_title); + unlink(buf); + } + if(substitute_record(fn_board, fhp, sizeof(*fhp), pos) == -1) + outs(err_board_update); + + return FULLUPDATE; + } else if(genbuf[0] != 'm' || fhp->bvote > 10) + return FULLUPDATE; + } + + strcpy(STR_new_control, STR_bv_control); + setbfile(buf,bname, STR_new_control); + x = 0; + while(x < 9 && (fp = fopen(buf,"r")) != NULL) { + fclose(fp); + x++; + sprintf(STR_new_control, "%s%d", STR_bv_control, x); + setbfile(buf, bname, STR_new_control); + } + if(fp) + fclose(fp); + if(x >=9) + return FULLUPDATE; + if(x) { + sprintf(STR_new_ballots, "%s%d", STR_bv_ballots,x); + sprintf(STR_new_control, "%s%d", STR_bv_control,x); + sprintf(STR_new_desc, "%s%d", STR_bv_desc,x); + sprintf(STR_new_flags, "%s%d", STR_bv_flags,x); + sprintf(STR_new_comments, "%s%d", STR_bv_comments,x); + sprintf(STR_new_limited, "%s%d", STR_bv_limited,x); + sprintf(STR_new_title, "%s%d", STR_bv_title,x); + } else { + strcpy(STR_new_ballots, STR_bv_ballots); + strcpy(STR_new_control, STR_bv_control); + strcpy(STR_new_desc, STR_bv_desc); + strcpy(STR_new_flags, STR_bv_flags); + strcpy(STR_new_comments, STR_bv_comments); + strcpy(STR_new_limited, STR_bv_limited); + strcpy(STR_new_title, STR_bv_title); + } + clear(); + move(0,0); + prints("第 %d 號投票\n", x); + setbfile(buf, bname, STR_new_title); + getdata(4, 0, "請輸入投票名稱", inbuf, 30, LCECHO); + if(inbuf[0]=='\0') + strcpy(inbuf,"不知名的"); + fp = fopen(buf, "w"); + fprintf(fp, "%s", inbuf); + fclose(fp); + + prints("按任何鍵開始編輯此次 [投票宗旨]"); + pressanykey(); + setbfile(buf, bname, STR_new_desc); + aborted = vedit(buf, NA, NULL); + if(aborted== -1) { + clear(); + outs("取消此次投票"); + pressanykey(); + return FULLUPDATE; + } + aborted = 0; + setbfile(buf, bname, STR_new_flags); + unlink(buf); + + getdata(4, 0, + "是否限定投票者名單:(y)編籍可投票人員名單[n]任何人皆可投票:[N]", + inbuf, 2, LCECHO); + setbfile(buf, bname, STR_new_limited); + if(inbuf[0] == 'y') { + fp = fopen(buf, "w"); + fprintf(fp,"此次投票設限"); + fclose(fp); + friend_edit(FRIEND_CANVOTE); + } else { + if(dashf(buf)) + unlink(buf); + } + clear(); + getdata(0, 0, "此次投票進行幾天 (一到十天)?", inbuf, 4, DOECHO); + + closetime = atoi(inbuf); + if(closetime <= 0) + closetime = 1; + else if(closetime >10) + closetime = 10; + + closetime = closetime * 86400 + time(NULL); + setbfile(buf, bname, STR_new_control); + fp = fopen(buf, "w"); + fprintf(fp, "00\n%lu\n", closetime); + + outs("\n請依序輸入選項, 按 ENTER 完成設定"); + num = 0; + while(!aborted) { + sprintf(buf, "%c) ", num + 'A'); + getdata((num % 15) + 2, (num / 15) * 40, buf, inbuf, 36, DOECHO); + if(*inbuf) { + fprintf(fp, "%1c) %s\n", (num+'A'), inbuf); + num++; + } + if((*inbuf == '\0' && num >= 1) || num == 30) + aborted = 1; + } + sprintf(buf, "請問每人最多可投幾票?([1]∼%d): ", num); + + getdata(t_lines-3, 0, buf, inbuf, 3, DOECHO); + + if(atoi(inbuf) <= 0 || atoi(inbuf) > num) + strcpy(inbuf,"1"); + + rewind(fp); + fprintf(fp, "%2d\n", MAX(1, atoi(inbuf))); + fclose(fp); + + if(fhp->bvote == 2) + fhp->bvote = 0; + else if(fhp->bvote == 1) + fhp->bvote = 2; + else if(fhp->bvote == 2) + fhp->bvote = 1; + + fhp->bvote ++; + + if(substitute_record(fn_board, fhp, sizeof(*fhp), pos) == -1) + outs(err_board_update); + reset_board(pos); + outs("開始投票了!"); + + return FULLUPDATE; +} + +static int vote_flag(char *bname, int index, char val) { + char buf[256], flag; + int fd, num, size; + + if(index) + sprintf(STR_new_flags, "%s%d", STR_bv_flags, index); + else + strcpy(STR_new_flags, STR_bv_flags); + + num = usernum - 1; + setbfile(buf, bname, STR_new_flags); + if((fd = open(buf, O_RDWR | O_CREAT, 0600)) == -1) + return -1; + size = lseek(fd, 0, SEEK_END); + memset(buf, 0, sizeof(buf)); + while(size <= num) { + write(fd, buf, sizeof(buf)); + size += sizeof(buf); + } + lseek(fd, num, SEEK_SET); + read(fd, &flag, 1); + if(flag == 0 && val != 0) { + lseek(fd, num, SEEK_SET); + write(fd, &val, 1); + } + close(fd); + return flag; +} + +static int same(char compare, char list[], int num) { + int n; + int rep = 0; + + for(n = 0; n < num; n++) { + if(compare == list[n]) + rep = 1; + if(rep == 1) + list[n] = list[n + 1]; + } + return rep; +} + +static int user_vote_one(char *bname, int ind) { + FILE* cfp,*fcm; + char buf[STRLEN]; + boardheader_t *fhp; + int pos = 0, i = 0, count = 0, tickets, fd; + char inbuf[80], choices[31], vote[4], chosen[31]; + time_t closetime; + + if(ind) { + sprintf(STR_new_ballots, "%s%d", STR_bv_ballots, ind); + sprintf(STR_new_control, "%s%d", STR_bv_control, ind); + sprintf(STR_new_desc, "%s%d", STR_bv_desc, ind); + sprintf(STR_new_flags, "%s%d", STR_bv_flags, ind); + sprintf(STR_new_comments, "%s%d", STR_bv_comments, ind); + sprintf(STR_new_limited, "%s%d", STR_bv_limited, ind); + } else { + strcpy(STR_new_ballots, STR_bv_ballots); + strcpy(STR_new_control, STR_bv_control); + strcpy(STR_new_desc, STR_bv_desc); + strcpy(STR_new_flags, STR_bv_flags); + strcpy(STR_new_comments, STR_bv_comments); + strcpy(STR_new_limited, STR_bv_limited); + } + + setbfile(buf, bname, STR_new_control); + cfp = fopen(buf,"r"); + if(!cfp) + return FULLUPDATE; + + setbfile(buf, bname, STR_new_limited); /* Ptt */ + if(dashf(buf)) { + setbfile(buf, bname, FN_CANVOTE); + if(!belong(buf, cuser.userid)) { + fclose(cfp); + outs("\n\n對不起! 這是私人投票..你並沒有受邀唷!"); + pressanykey(); + return FULLUPDATE; + } else { + outs("\n\n恭喜你受邀此次私人投票....<按任意鍵檢視此次受邀名單>"); + pressanykey(); + more(buf, YEA); + } + } + if(vote_flag(bname, ind, '\0')) { + outs("\n\n此次投票,你已投過了!"); + pressanykey(); + return FULLUPDATE; + } + + setutmpmode(VOTING); + setbfile(buf, bname, STR_new_desc); + more(buf, YEA); + + stand_title("投票箱"); + if((pos = getbnum(bname)) <= 0) + return 0; + + fhp = bcache + pos - 1; + fgets(inbuf, sizeof(inbuf), cfp); + tickets = atoi(inbuf); + fscanf(cfp,"%lu\n", &closetime); + + prints("投票方式:確定好您的選擇後,輸入其代碼(A, B, C...)即可。\n" + "此次投票你可以投 %1d 票。" + "按 0 取消投票 , 1 完成投票\n" + "此次投票將結束於:%s \n", + tickets, ctime(&closetime)); + move(5, 0); + memset(choices, 0, sizeof(choices)); + memset(chosen , 0, sizeof(chosen)); + + while(fgets(inbuf, sizeof(inbuf), cfp)) { + move((count % 15) + 5, (count / 15) * 40); + prints( " %s", strtok(inbuf, "\n\0")); + choices[count++] = inbuf[0]; + } + fclose(cfp); + + while(1) { + vote[0] = vote[1] = '\0'; + move(t_lines - 2, 0); + prints("你還可以投 %2d 票", tickets - i); + getdata(t_lines - 4, 0, "輸入您的選擇: ", vote, 3, DOECHO); + *vote = toupper(*vote); + if(vote[0] == '0' || (!vote[0] && !i)) { + outs("記的再來投喔!!"); + break; + } else if(vote[0] == '1' && i) + ; + else if(!vote[0]) + continue; + else if(index(choices, vote[0]) == NULL) /* 無效 */ + continue; + else if(same(vote[0], chosen, i)) { + move(((vote[0] - 'A') % 15) + 5, (((vote[0] - 'A')) / 15) * 40); + prints(" "); + i--; + continue; + } else { + if(i == tickets) + continue; + chosen[i] = vote[0]; + move(((vote[0]-'A') % 15) + 5, (((vote[0] - 'A')) / 15) * 40); + prints("*"); + i++; + continue; + } + + if(vote_flag(bname, ind, vote[0]) != 0) + prints("重覆投票! 不予計票。"); + else { + setbfile(buf, bname, STR_new_ballots); + if((fd = open(buf, O_WRONLY | O_CREAT | O_APPEND, 0600)) == 0) + outs("無法投入票匭\n"); + else { + struct stat statb; + char buf[3], mycomments[3][74], b_comments[80]; + + for(i = 0; i < 3; i++) + strcpy(mycomments[i], "\n"); + + flock(fd, LOCK_EX); + for(count = 0; count < 31; count++) { + if(chosen[count]) + write(fd, &chosen[count], 1); + } + flock(fd, LOCK_UN); + fstat(fd, &statb); + close(fd); + getdata(b_lines - 2, 0, + "您對這次投票有什麼寶貴的意見嗎?(y/n)[N]", + buf, 3 ,DOECHO); + if(buf[0] == 'Y' || buf[0] == 'y'){ + do { + move(5,0);clrtobot(); + outs("請問您對這次投票有什麼寶貴的意見?" + "最多三行,按[Enter]結束"); + for(i = 0; (i < 3) && + getdata(7 + i, 0, ":", mycomments[i], 74, + DOECHO); i++); + getdata(b_lines-2,0, "(S)儲存 (E)重新來過 " + "(Q)取消?[S]", buf, 3, LCECHO); + } while(buf[0] == 'E' || buf[0] == 'e'); + if(buf[0] == 'Q' || buf[0] == 'q') + break; + setbfile(b_comments, bname, STR_new_comments); + if(mycomments[0]) + if((fcm = fopen(b_comments, "a"))){ + fprintf(fcm, + "\033[36m○使用者\033[1;36m %s " + "\033[;36m的建議:\033[m\n", + cuser.userid); + for(i = 0; i < 3; i++) + fprintf(fcm, " %s\n", mycomments[i]); + fprintf(fcm, "\n"); + fclose(fcm); + } + } + move(b_lines - 1 ,0); + prints("已完成投票!\n"); + } + } + break; + } + pressanykey(); + return FULLUPDATE; +} + +static int user_vote(char *bname) { + int pos; + boardheader_t *fhp; + char buf[STRLEN]; + FILE* fp,*xfp; + int i, x = -1; + char genbuf[STRLEN]; + char inbuf[80]; + + if((pos = getbnum(bname)) <= 0) + return 0; + + fhp = bcache + pos - 1; + + move(0,0); + clrtobot(); + + if(fhp->bvote == 2 || fhp->bvote == 0) { + outs("\n\n目前並沒有任何投票舉行。"); + pressanykey(); + return FULLUPDATE; + } + + if(!HAS_PERM(PERM_LOGINOK)) { + outs("\n對不起! 您未滿二十歲, 還沒有投票權喔!"); + pressanykey(); + return FULLUPDATE; + } + + strcpy(STR_new_control, STR_bv_control); + strcpy(STR_new_title, STR_bv_title); + setbfile(buf, bname, STR_new_control); + move(0, 0); + if((fp = fopen(buf, "r"))) { + prints("(0) "); + x = 0; + fclose(fp); + + setbfile(buf, bname, STR_new_title); + if((xfp = fopen(buf,"r"))) + fgets(inbuf, sizeof(inbuf), xfp); + else + strcpy(inbuf, "無標題"); + prints("%s\n", inbuf); + fclose(xfp); + } + + for(i = 1; i < 9; i++) { + sprintf(STR_new_control, "%s%d", STR_bv_control, i); + sprintf(STR_new_title, "%s%d", STR_bv_title, i); + setbfile(buf, bname, STR_new_control); + if((fp = fopen(buf, "r"))) { + prints("(%d) ", i); + x = i; + fclose(fp); + + setbfile(buf, bname, STR_new_title); + if((xfp = fopen(buf, "r"))) + fgets(inbuf, sizeof(inbuf), xfp); + else + strcpy(inbuf, "無標題"); + prints("%s\n", inbuf); + fclose(xfp); + } + } + + if(x < 0) + return FULLUPDATE; + + sprintf(buf, "要投幾號投票 [%d] ", x); + + getdata(b_lines - 1, 0, buf, genbuf, 4, LCECHO); + + if(genbuf[0] < '0' || genbuf[0] > '8') + genbuf[0] = x + '0'; + + if(genbuf[0] != '0') + sprintf(STR_new_control, "%s%c", STR_bv_control, genbuf[0]); + else + strcpy(STR_new_control, STR_bv_control); + + setbfile(buf, bname, STR_new_control); + + if((fp = fopen(buf, "r"))){ + fclose(fp); + + return user_vote_one(bname, genbuf[0] - '0'); + } else + return FULLUPDATE; +} + +static int vote_results(char *bname) { + char buf[STRLEN]; + + setbfile(buf, bname, STR_bv_results); + if(more(buf, YEA) == -1) + outs("\n目前沒有任何投票的結果。"); + return FULLUPDATE; +} + +int b_vote_maintain() { + return vote_maintain(currboard); +} + +int b_vote() { + return user_vote(currboard); +} + +int b_results() { + return vote_results(currboard); +} diff --git a/pttbbs/mbbsd/voteboard.c b/pttbbs/mbbsd/voteboard.c new file mode 100644 index 00000000..1286d986 --- /dev/null +++ b/pttbbs/mbbsd/voteboard.c @@ -0,0 +1,447 @@ +/* $Id: voteboard.c,v 1.1 2002/03/07 15:13:48 in2 Exp $ */ +#include +#include +#include +#include +#include +#include +#include +#include +#include "config.h" +#include "pttstruct.h" +#include "modes.h" +#include "common.h" +#include "perm.h" +#include "proto.h" + +#define VOTEBOARD "NewBoard" + +extern char currboard[]; +extern int currbid; +extern boardheader_t *bcache; +extern int currmode; +extern userec_t cuser; + +void do_voteboardreply(fileheader_t *fhdr){ + char genbuf[1024]; + char reason[60]; + char fpath[80]; + char oldfpath[80]; + char opnion[10]; + char *ptr; + FILE *fo, *fp; + fileheader_t votefile; + int len; + int i, j; + int fd; + time_t endtime, now = time(NULL); + int hastime = 0; + + + clear(); + if(!(currmode & MODE_POST)) { + move(5, 10); + outs("對不起,您目前無法在此發表文章!"); + pressanykey(); + return; + } + + setbpath(fpath, currboard); + stampfile(fpath, &votefile); + + setbpath(oldfpath, currboard); + + strcat(oldfpath, "/"); + strcat(oldfpath, fhdr->filename); + + fp = fopen(oldfpath, "r"); + + len = strlen(cuser.userid); + + while(fgets(genbuf, 1024, fp)){ + if (!strncmp(genbuf, "連署結束時間", 12)){ + hastime = 1; + ptr = strchr(genbuf, '('); + sscanf(ptr+1, "%ld", &endtime); + if (endtime < now){ + prints("連署時間已過"); + pressanykey(); + fclose(fp); + return; + } + } + if (!strncmp(genbuf+4, cuser.userid, len)){ + move(5, 10); + prints("您已經連署過本篇了"); + opnion[0] = 'n'; + getdata(7, 0, "要修改您之前的連署嗎?(Y/N) [N]", opnion, 3, LCECHO); + if (opnion[0] != 'y'){ + fclose(fp); + return; + } + strcpy(reason, genbuf+19); + } + } + fclose(fp); + + if((fd = open(oldfpath, O_RDONLY)) == -1) + return; + flock(fd, LOCK_EX); + + fo = fopen(fpath, "w"); + + if (!fo) + return; + i = 0; + while(fo){ + j = 0; + do{ + if (read(fd, genbuf+j, 1)<=0){ + flock(fd, LOCK_UN); + close(fd); + fclose(fo); + unlink(fpath); + return; + } + j++; + }while(genbuf[j-1] !='\n'); + genbuf[j] = '\0'; + i++; + if (!strncmp("----------", genbuf, 10)) + break; + if (i > 3) + prints(genbuf); + fprintf(fo, "%s", genbuf); + } + if (!hastime){ + now += 14*24*60*60; + fprintf(fo, "連署結束時間: (%ld)%s", now, ctime(&now)); + now -= 14*24*60*60; + } + + fprintf(fo, "%s", genbuf); + + do{ + if (!getdata(18, 0, "請問您 (Y)支持 (N)反對 這個議題:", opnion, 3, LCECHO)){ + flock(fd, LOCK_UN); + close(fd); + fclose(fo); + unlink(fpath); + return; + } + }while(opnion[0] != 'y' && opnion[0] != 'n'); + + if (!getdata(20, 0, "請問您與這個議題的關係或連署理由為何:", reason, 40, DOECHO)){ + flock(fd, LOCK_UN); + close(fd); + fclose(fo); + unlink(fpath); + return; + } + + i = 0; + + while(fo){ + i++; + j = 0; + do{ + if (read(fd, genbuf+j, 1)<=0){ + flock(fd, LOCK_UN); + close(fd); + fclose(fo); + unlink(fpath); + return; + } + j++; + }while(genbuf[j-1] !='\n'); + genbuf[j] = '\0'; + if (!strncmp("----------", genbuf, 10)) + break; + if (strncmp(genbuf+4, cuser.userid, len)) + fprintf(fo, "%3d.%s", i, genbuf+4); + else + i--; + } + if (opnion[0] == 'y') + fprintf(fo, "%3d.%-15s%-34s 來源:%s\n", i, cuser.userid, reason,cuser.lasthost); + i = 0; + fprintf(fo, "%s", genbuf); + while(fo){ + i++; + j = 0; + do{ + if (!read(fd, genbuf+j, 1)) + break; + j++; + }while(genbuf[j-1] !='\n'); + genbuf[j] = '\0'; + if (j <= 3) + break; + if (strncmp(genbuf+4, cuser.userid, len)) + fprintf(fo, "%3d.%s", i, genbuf+4); + else + i--; + } + if (opnion[0] == 'n') + fprintf(fo, "%3d.%-15s%-34s 來源:%s\n", i, cuser.userid, reason,cuser.lasthost); + flock(fd, LOCK_UN); + close(fd); + fclose(fo); + unlink(oldfpath); + rename(fpath, oldfpath); +} + +int do_voteboard() { + fileheader_t votefile; + char topic[100]; + char title[80]; + char genbuf[1024]; + char fpath[80]; + FILE* fp; + int temp, i; + time_t now = time(NULL); + + clear(); + if(!(currmode & MODE_POST)) { + move(5, 10); + outs("對不起,您目前無法在此發表文章!"); + pressanykey(); + return FULLUPDATE; + } + + move(0, 0); + clrtobot(); + prints("您正在使用 PTT 的連署系統\n"); + prints("本連署系統將詢問您一些問題,請小心回答才能開始連署\n"); + prints("任意提出連署案者,將被列入本系統不受歡迎使用者喔\n"); + pressanykey(); + move(0, 0); + clrtobot(); + prints("(1)申請新版 (2)廢除舊版 (3)連署版主 (4)罷免版主\n"); + if (!strcmp(currboard, VOTEBOARD)) + prints("(5)連署小組長 (6)罷免小組長 "); + if (!strcmp(currboard, VOTEBOARD) && HAS_PERM(PERM_SYSOP)) + prints("(7)站民公投"); + prints("(8)申請新群組"); + + do{ + getdata(3, 0, "請輸入連署類別:", topic, 3, DOECHO); + temp = atoi(topic); + }while(temp <= 0 && temp >= 9); + + switch(temp){ + case 1: + do{ + if (!getdata(4, 0, "請輸入看版英文名稱:", topic, IDLEN+1, DOECHO)) + return FULLUPDATE; + else if (invalid_brdname(topic)) + outs("不是正確的看版名稱"); + else if (getbnum(topic) > 0) + outs("本名稱已經存在"); + else + break; + }while(temp > 0); + sprintf(title, "[申請新版] %s", topic); + sprintf(genbuf, "%s\n\n%s%s\n%s","申請新版", "英文名稱: ", topic, "中文名稱: "); + + if (!getdata(5, 0, "請輸入看版中文名稱:", topic, 20, DOECHO)) + return FULLUPDATE; + strcat(genbuf, topic); + strcat(genbuf, "\n看版類別: "); + if (!getdata(6, 0, "請輸入看版類別:", topic, 20, DOECHO)) + return FULLUPDATE; + strcat(genbuf, topic); + strcat(genbuf, "\n版主名單: "); + getdata(7, 0, "請輸入版主名單:", topic, IDLEN * 3 + 3, DOECHO); + strcat(genbuf, topic); + strcat(genbuf, "\n申請原因: \n"); + outs("請輸入申請原因(至多五行),要清楚填寫不然不會核准喔"); + for(i= 8;i<13;i++){ + if (!getdata(i, 0, ":", topic, 60, DOECHO)) + break; + strcat(genbuf, topic); + strcat(genbuf, "\n"); + } + if (i==8) + return FULLUPDATE; + break; + case 2: + do{ + if (!getdata(4, 0, "請輸入看版英文名稱:", topic, IDLEN+1, DOECHO)) + return FULLUPDATE; + else if (getbnum(topic) <= 0) + outs("本名稱並不存在"); + else + break; + }while(temp > 0); + sprintf(title, "[廢除舊版] %s", topic); + sprintf(genbuf, "%s\n\n%s%s\n","廢除舊版", "英文名稱: ", topic); + strcat(genbuf, "\n廢除原因: \n"); + outs("請輸入廢除原因(至多五行),要清楚填寫不然不會核准喔"); + for(i= 8;i<13;i++){ + if (!getdata(i, 0, ":", topic, 60, DOECHO)) + break; + strcat(genbuf, topic); + strcat(genbuf, "\n"); + } + if (i==8) + return FULLUPDATE; + + break; + case 3: + do{ + if (!getdata(4, 0, "請輸入看版英文名稱:", topic, IDLEN+1, DOECHO)) + return FULLUPDATE; + else if (getbnum(topic) <= 0) + outs("本名稱並不存在"); + else + break; + }while(temp > 0); + sprintf(title, "[連署版主] %s", topic); + sprintf(genbuf, "%s\n\n%s%s\n%s%s","連署版主", "英文名稱: ", topic, "申請 ID : ", cuser.userid); + strcat(genbuf, "\n申請政見: \n"); + outs("請輸入申請政見(至多五行),要清楚填寫不然不會核准喔"); + for(i= 8;i<13;i++){ + if (!getdata(i, 0, ":", topic, 60, DOECHO)) + break; + strcat(genbuf, topic); + strcat(genbuf, "\n"); + } + if (i==8) + return FULLUPDATE; + break; + case 4: + do{ + if (!getdata(4, 0, "請輸入看版英文名稱:", topic, IDLEN+1, DOECHO)) + return FULLUPDATE; + else if ((i = getbnum(topic)) <= 0) + outs("本名稱並不存在"); + else + break; + }while(temp > 0); + sprintf(title, "[罷免版主] %s", topic); + sprintf(genbuf, "%s\n\n%s%s\n%s","罷免版主", "英文名稱: ", topic, "版主 ID : "); + do{ + if (!getdata(6, 0, "請輸入版主ID:", topic, IDLEN + 1, DOECHO)) + return FULLUPDATE; + else if (!userid_is_BM(topic, bcache[i-1].BM)) + outs("不是該版的版主"); + else + break; + }while(temp > 0); + strcat(genbuf, topic); + strcat(genbuf, "\n罷免原因: \n"); + outs("請輸入罷免原因(至多五行),要清楚填寫不然不會核准喔"); + for(i= 8;i<13;i++){ + if (!getdata(i, 0, ":", topic, 60, DOECHO)) + break; + strcat(genbuf, topic); + strcat(genbuf, "\n"); + } + if (i==8) + return FULLUPDATE; + break; + case 5: + if (!getdata(4, 0, "請輸入小組中英文名稱:", topic, 30, DOECHO)) + return FULLUPDATE; + sprintf(title, "[連署小組長] %s", topic); + sprintf(genbuf, "%s\n\n%s%s\n%s%s","連署小組長", "小組名稱: ", topic, "申請 ID : ", cuser.userid); + strcat(genbuf, "\n申請政見: \n"); + outs("請輸入申請政見(至多五行),要清楚填寫不然不會核准喔"); + for(i= 8;i<13;i++){ + if (!getdata(i, 0, ":", topic, 60, DOECHO)) + break; + strcat(genbuf, topic); + strcat(genbuf, "\n"); + } + if (i==8) + return FULLUPDATE; + break; + case 6: + + if (!getdata(4, 0, "請輸入小組中英文名稱:", topic, 30, DOECHO)) + return FULLUPDATE; + sprintf(title, "[罷免小組長] %s", topic); + sprintf(genbuf, "%s\n\n%s%s\n%s","罷免小組長", "小組名稱: ", topic, "小組長 ID : "); + if (!getdata(6, 0, "請輸入小組長ID:", topic, IDLEN + 1, DOECHO)) + return FULLUPDATE; + strcat(genbuf, topic); + strcat(genbuf, "\n罷免原因: \n"); + outs("請輸入罷免原因(至多五行),要清楚填寫不然不會核准喔"); + for(i= 8;i<13;i++){ + if (!getdata(i, 0, ":", topic, 60, DOECHO)) + break; + strcat(genbuf, topic); + strcat(genbuf, "\n"); + } + if (i==8) + return FULLUPDATE; + break; + case 7: + if (!HAS_PERM(PERM_SYSOP)) + return FULLUPDATE; + if (!getdata(4, 0, "請輸入公投主題:", topic, 30, DOECHO)) + return FULLUPDATE; + sprintf(title, "%s %s", "[站民公投]", topic); + sprintf(genbuf, "%s\n\n%s%s\n","站民公投", "公投主題: ", topic); + strcat(genbuf, "\n公投原因: \n"); + outs("請輸入公投原因(至多五行),要清楚填寫不然不會核准喔"); + for(i= 8;i<13;i++){ + if (!getdata(i, 0, ":", topic, 60, DOECHO)) + break; + strcat(genbuf, topic); + strcat(genbuf, "\n"); + } + if (i==8) + return FULLUPDATE; + break; + case 8: + if(!getdata(4, 0, "請輸入群組中英文名稱:", topic, 30, DOECHO)) + return FULLUPDATE; + sprintf(title, "[申請新群組] %s", topic); + sprintf(genbuf, "%s\n\n%s%s\n%s%s","申請群組", "群組名稱: ", topic, "申請 ID : ", cuser.userid); + strcat(genbuf, "\n申請政見: \n"); + outs("請輸入申請政見(至多五行),要清楚填寫不然不會核准喔"); + for(i= 8;i<13;i++){ + if (!getdata(i, 0, ":", topic, 60, DOECHO)) + break; + strcat(genbuf, topic); + strcat(genbuf, "\n"); + } + if (i==8) + return FULLUPDATE; + break; + default: + return FULLUPDATE; + } + strcat(genbuf, "連署結束時間: "); + now += 14*24*60*60; + sprintf(topic, "(%ld)", now); + strcat(genbuf, topic); + strcat(genbuf, ctime(&now)); + now -= 14*24*60*60; + strcat(genbuf, "----------支持----------\n"); + strcat(genbuf, "----------反對----------\n"); + outs("開始連署嘍"); + setbpath(fpath, currboard); + stampfile(fpath, &votefile); + + if (!(fp = fopen(fpath, "w"))){ + outs("開檔失敗,請稍候重來一次"); + return FULLUPDATE; + } + fprintf(fp, "%s%s %s%s\n%s%s\n%s%s", "作者: ", cuser.userid, + "看板: ", currboard, + "標題: ", title, + "時間: ", ctime(&now)); + fprintf(fp, "%s\n", genbuf); + fclose(fp); + strcpy(votefile.owner, cuser.userid); + strcpy(votefile.title, title); + votefile.savemode = 'S'; + setbdir(genbuf, currboard); + if(append_record(genbuf, &votefile, sizeof(votefile)) != -1) + setbtotal(currbid); + do_voteboardreply(&votefile); + return FULLUPDATE; +} diff --git a/pttbbs/mbbsd/xyz.c b/pttbbs/mbbsd/xyz.c new file mode 100644 index 00000000..786add30 --- /dev/null +++ b/pttbbs/mbbsd/xyz.c @@ -0,0 +1,448 @@ +/* $Id: xyz.c,v 1.1 2002/03/07 15:13:48 in2 Exp $ */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "config.h" +#include "pttstruct.h" +#include "common.h" +#include "modes.h" +#include "proto.h" + +extern char *fn_note_ans; +extern int b_lines; /* Screen bottom line number: t_lines-1 */ +extern char *BBSName; +extern char fromhost[]; +extern userinfo_t *currutmp; +extern int curr_idle_timeout; +extern userec_t cuser; + +/* 各種統計及相關資訊列表 */ +/* Ptt90年度大學聯招查榜系統 */ +int x_90() { + extern char dict[21], database[41]; + strcpy(dict, "(90)准考證號/姓名/學校/科系/類組"); + strcpy(database, "etc/90"); + use_dict(); + return 0; +} + +/* Ptt89年度大學聯招查榜系統 */ +int x_89() { + extern char dict[21], database[41]; + strcpy(dict, "(89)准考證號/姓名/學校/科系/類組"); + strcpy(database, "etc/89"); + use_dict(); + return 0; +} +/* Ptt88年度大學聯招查榜系統 */ +int x_88() { + extern char dict[21], database[41]; + + strcpy(dict, "(88)准考證號/姓名/學校/科系/類組"); + strcpy(database, "etc/88"); + use_dict(); + return 0; +} +/* Ptt87年度大學聯招查榜系統 */ +int x_87() { + extern char dict[21], database[41]; + + strcpy(dict, "(87)准考證號/姓名/學校/科系"); + strcpy(database, "etc/87"); + use_dict(); + return 0; +} + +/* Ptt86年度大學聯招查榜系統 */ +int x_86() { + extern char dict[21], database[41]; + + strcpy(dict, "(86)准考證號/姓名/學校/科系"); + strcpy(database, "etc/86"); + use_dict(); + return 0; +} + +int x_boardman() { + more("etc/topboardman", YEA); + return 0; +} + +int x_user100() { + more("etc/topusr100", YEA); + return 0; +} + +int x_history() { + more("etc/history", YEA); + return 0; +} + +#ifdef HAVE_X_BOARDS +static int x_boards() { + more("etc/topboard.tmp", YEA); + return 0; +} +#endif + +int x_birth() { + more("etc/birth.today", YEA); + return 0; +} + +int x_weather() { + more("etc/weather.tmp", YEA); + return 0; +} + +int x_stock() { + more("etc/stock.tmp", YEA); + return 0; +} + +int x_note() { + more(fn_note_ans, YEA); + return 0; +} + +int x_issue() { + more("etc/day", YEA); + return 0; +} + +int x_week() { + more("etc/week", YEA); + return 0; +} + +int x_today() { + more("etc/today", YEA); + return 0; +} + +int x_yesterday() { + more("etc/yesterday", YEA); + return 0; +} + +int x_login() { + more("etc/Welcome_login", YEA); + return 0; +} + +#ifdef HAVE_INFO +static int x_program() { + more("etc/version", YEA); + return 0; +} +#endif + +#ifdef HAVE_LICENSE +static int x_gpl() { + more("etc/GPL", YEA); + return 0; +} +#endif + +/* 離開 BBS 站 */ +int note() { + static char *fn_note_tmp = "note.tmp"; + static char *fn_note_dat = "note.dat"; + int total = 0, i, collect, len; + struct stat st; + char buf[256], buf2[80]; + int fd, fx; + FILE *fp, *foo; + + typedef struct notedata_t { + time_t date; + char userid[IDLEN + 1]; + char username[19]; + char buf[3][80]; + } notedata_t; + notedata_t myitem; + + if(cuser.money < 5) { + outmsg("\033[1;41m 哎呀! 要投五銀才能留言...沒錢耶..\033[m"); + clrtoeol(); + refresh(); + return 0; + } + + setutmpmode(EDNOTE); + do { + myitem.buf[0][0] = myitem.buf[1][0] = myitem.buf[2][0] = '\0'; + move(12, 0); + clrtobot(); + outs("\n投五銀... 嗶... 請留言 (至多三行),按[Enter]結束"); + for(i = 0; (i < 3) && getdata(16 + i, 0, ":", myitem.buf[i], 78, + DOECHO) && *myitem.buf[i]; i++); + getdata(b_lines - 1, 0, "(S)儲存 (E)重新來過 (Q)取消?[S] ", + buf, 3, LCECHO); + + if(buf[0] == 'q' || (i == 0 && *buf != 'e')) + return 0; + } while(buf[0] == 'e'); + demoney(-5); + strcpy(myitem.userid, cuser.userid); + strncpy(myitem.username, cuser.username, 18); + myitem.username[18] = '\0'; + time(&(myitem.date)); + + /* begin load file */ + if((foo = fopen(".note", "a")) == NULL) + return 0; + + if((fp = fopen(fn_note_ans, "w")) == NULL) + return 0; + + if((fx = open(fn_note_tmp, O_WRONLY | O_CREAT, 0644)) <= 0) + return 0; + + if((fd = open(fn_note_dat, O_RDONLY)) == -1) + total = 1; + else if(fstat(fd, &st) != -1) { + total = st.st_size / sizeof(notedata_t) + 1; + if (total > MAX_NOTE) + total = MAX_NOTE; + } + + fputs("\033[1;31;44m☉┬──────────────┤" + "\033[37m酸甜苦辣板\033[31m├──────────────┬☉" + "\033[m\n", fp); + collect = 1; + + while(total) { + sprintf(buf, "\033[1;31m╭┤\033[32m %s \033[37m(%s)", + myitem.userid, myitem.username); + len = strlen(buf); + + for(i = len ; i < 73; i++) + strcat(buf, " "); + sprintf(buf2, " \033[1;36m%.14s\033[31m ├╮\033[m\n", + Cdate(&(myitem.date))); + strcat(buf, buf2); + fputs(buf, fp); + if(collect) + fputs(buf, foo); + for(i = 0 ; i < 3 && *myitem.buf[i]; i++) { + fprintf(fp, "\033[1;31m│\033[m%-74.74s\033[1;31m│\033[m\n", + myitem.buf[i]); + if(collect) + fprintf(foo, "\033[1;31m│\033[m%-74.74s\033[1;31m│\033[m\n", + myitem.buf[i]); + } + fputs("\033[1;31m╰┬───────────────────────" + "────────────┬╯\033[m\n",fp); + + if(collect) { + fputs("\033[1;31m╰┬─────────────────────" + "──────────────┬╯\033[m\n", foo); + fclose(foo); + collect = 0; + } + + write(fx, &myitem, sizeof(myitem)); + + if(--total) + read(fd, (char *) &myitem, sizeof(myitem)); + } + fputs("\033[1;31;44m☉┴───────────────────────" + "────────────┴☉\033[m\n",fp); + fclose(fp); + close(fd); + close(fx); + Rename(fn_note_tmp, fn_note_dat); + more(fn_note_ans, YEA); + return 0; +} + +static void mail_sysop() { + FILE *fp; + char genbuf[200]; + + if((fp = fopen("etc/sysop", "r"))) { + int i, j; + char *ptr; + + typedef struct sysoplist_t { + char userid[IDLEN + 1]; + char duty[40]; + } sysoplist_t; + sysoplist_t sysoplist[9]; + + j = 0; + while(fgets(genbuf, 128, fp)) { + if((ptr = strchr(genbuf, '\n'))) { + *ptr = '\0'; + if((ptr = strchr(genbuf, ':'))) { + *ptr = '\0'; + do { + i = *++ptr; + } while(i == ' ' || i == '\t'); + if(i) { + strcpy(sysoplist[j].userid, genbuf); + strcpy(sysoplist[j++].duty, ptr); + } + } + } + } + + move(12, 0); + clrtobot(); + prints("%16s %-18s權責劃分\n\n", "編號", "站長 ID"); + + for(i = 0; i < j; i++) + prints("%15d. \033[1;%dm%-16s%s\033[0m\n", + i + 1, 31 + i % 7, sysoplist[i].userid, sysoplist[i].duty); + prints("%-14s0. \033[1;%dm離開\033[0m", "", 31 + j % 7); + getdata(b_lines - 1, 0, " 請輸入代碼[0]:", + genbuf, 4, DOECHO); + i = genbuf[0] - '0' - 1; + if(i >= 0 && i < j) { + clear(); + do_send(sysoplist[i].userid, NULL); + } + } +} + +int m_sysop() { + setutmpmode(MSYSOP); + mail_sysop(); + return 0; +} + +int Goodbye() { + extern void movie(); + char genbuf[100]; + + getdata(b_lines - 1, 0, "您確定要離開【 " BBSNAME " 】嗎(Y/N)?[N] ", + genbuf, 3, LCECHO); + + if(*genbuf != 'y') + return 0; + + movie(999); + if(cuser.userlevel) { + getdata(b_lines - 1, 0, + "(G)隨風而逝 (M)托夢站長 (N)酸甜苦辣流言版?[G] ", + genbuf, 3, LCECHO); + if(genbuf[0] == 'm') + mail_sysop(); + else if(genbuf[0] == 'n') + note(); + } + + clear(); + prints("\033[1;36m親愛的 \033[33m%s(%s)\033[36m,別忘了再度光臨\033[45;33m" + " %s \033[40;36m!\n以下是您在站內的註冊資料:\033[0m\n", + cuser.userid, cuser.username, BBSName); + user_display(&cuser, 0); + pressanykey(); + + more("etc/Logout",NA); + pressanykey(); + u_exit("EXIT "); + return QUIT; +} + +/* 支援外掛程式 : tin、gopher、www、bbsnet、game、csh */ +#define LOOKFIRST (0) +#define LOOKLAST (1) +#define QUOTEMODE (2) +#define MAXCOMSZ (1024) +#define MAXARGS (40) +#define MAXENVS (20) +#define BINDIR BBSHOME"/bin/" + +#define MAXPATHLEN 256 + +#ifdef HAVE_TIN +static int x_tin() { + clear(); + return exec_cmd(NEWS, YEA, "bin/tin.sh", "TIN"); +} +#endif + +#ifdef HAVE_GOPHER +static int x_gopher() { + clear(); + return exec_cmd(GOPHER, YEA, "bin/gopher.sh", "GOPHER"); +} +#endif + +#ifdef HAVE_WWW +static int x_www() { + return exec_cmd(WWW, NA, "bin/www.sh", "WWW"); +} +#endif + +#ifdef HAVE_IRC +static int x_irc() { + return exec_cmd(XMODE, NA, "bin/irc.sh", "IRC"); +} +#endif + +#ifdef HAVE_ARCHIE +static int x_archie() { + char buf[STRLEN], ans[4]; + char genbuf1[100], genbuf2[200]; + char *s; + + setutmpmode(ARCHIE); + clear(); + outs("\n歡迎光臨【\033[1;33;44m" BBSNAME "\033[m】使用 " + "\033[32mARCHIE\033[m 功\能\n"); + outs("\n本功\能將為您列出在哪個 FTP 站存有您欲尋找的檔案.\n"); + outs("\n請輸入欲搜尋的字串, 或直接按 取消。\n"); + outs("\n coder by Harimau\n"); + outs(" modified by Leeym\n"); + getdata(13,0,"搜尋字串:",buf,20,DOECHO,0); + if(buf[0]=='\0') { + prints("\n取消搜尋.....\n"); + pressanykey(); + return; + } + + for(s = buf; *s != '\0'; s++) { + if(isspace(*s)) { + prints("\n一次只能搜尋一個字串啦, 不能太貪心喔!!"); + pressanykey(); + return; + } + } + bbssetenv("ARCHIESTRING", buf); + exec_cmd(ARCHIE, YEA, "bin/archie.sh", ARCHIE); + log_usies("ARCHIE", ""); + strcpy(genbuf1, buf); + sprintf(buf, BBSHOME "/tmp/archie.%s", cuser.userid); + if(dashf(buf)) { + getdata(0, 0, "要將結果寄回信箱嗎(Y/N)?[N]", ans, 3, DOECHO,0); + if(*ans == 'y') { + fileheader_t mhdr; + char title[128], buf1[80]; + FILE* fp; + + sethomepath(buf1, cuser.userid); + stampfile(buf1, &mhdr); + strcpy(mhdr.owner, cuser.userid); + sprintf(genbuf2, "Archie 搜尋檔案: %s 結果", genbuf1); + strcpy(mhdr.title, genbuf2); + mhdr.savemode = 0; + mhdr.filemode = 0; + sethomedir(title, cuser.userid); + append_record(title, &mhdr, sizeof(mhdr)); + Link(buf, buf1); + } + more( buf, YEA); + unlink (buf); + } +} +#endif /* HAVE_ARCHIE */ diff --git a/pttbbs/sample/Makefile b/pttbbs/sample/Makefile new file mode 100644 index 00000000..7ba47da6 --- /dev/null +++ b/pttbbs/sample/Makefile @@ -0,0 +1,11 @@ +SUBDIR=etc innd +BBSHOME?=$(HOME) + +all: + +install: + @for i in $(SUBDIR); do\ + cd $$i;\ + make BBSHOME=$(BBSHOME) OSTYPE=$(OSTYPE) $@;\ + cd ..;\ + done diff --git a/pttbbs/sample/crontab b/pttbbs/sample/crontab new file mode 100644 index 00000000..5acc8403 --- /dev/null +++ b/pttbbs/sample/crontab @@ -0,0 +1,56 @@ +20 7 * * * bin/mailog.sh > /dev/null +20 6 * * * rm -f out/*; rm -f out/.DIR + +# 每天 12:00 17:00 20:00 00:00 開獎。 +0 2,11,16,21 * * * bin/openticket.sh > /dev/null + +# 每天早上清除過期使用者 +10 7 * * * bin/reaper > /dev/null 2> /dev/null + +# 每個小時 1 分執行上站人次統計 +1 * * * * bin/account > /dev/null 2> /dev/null + +# 每個小時 10 分執行熱門話題統計 +50 * * * * bin/parse_news +10 * * * * bin/poststat /home/bbs > /dev/null + +# 每天5:30執行使用者排行榜更新 +30 5 * * * bin/topusr 10 etc/topusr > /dev/null +30 3 * * * bin/topusr 100 etc/topusr100 > /dev/null +30 5 * * * bin/yearsold > /dev/null +30 5 * * * bin/horoscope + +# 每個月一, 十五號點歌排行榜 +20 6 1,15 * * bin/topsong.sh + +# 每週三,六統計轉信所有板 +35 6 * * 6 bin/showboard ~/.BOARDS > ~/etc/BOARD.rec + +# 每週一早上把user home清一清 +20 3 * * * (/bin/rm -f logins.bad; bin/expire ) > /dev/null +1 7 * * 1 bin/deluserfile > /dev/null + +# 每週二早上 4:30 , 將 BBS boards 中超過七天的 SR. 系列的檔案砍掉 +30 4 * * 2 /usr/bin/find /home/bbs/boards/ -mtime +7 -name SR\* -exec rm -f {} ';' +30 4 * * 2 /bin/rm -f ~/tmp/* + +# 每天執行一次生日程 +1 2 * * * bin/birth > /dev/null + +# 每天精華區index一次 index前砍掉deleted的精華區 +15 6 * * * rm -rf man/boards/deleted +20 6 * * * bin/mandex > /dev/null +30 6 * * * bin/openvice > /dev/null + +# 每天砍掉點歌超過5天檔案 +40 6 * * * ( find /home/bbs/etc/SONGO/M* -mtime +5 -exec rm -f {} ';' ) + +#天氣股票 +0 5,11,17,23 * * * bin/weather.sh > /dev/null +20 12 * * * bin/stock.sh > /dev/null + +# 每個月一號早上 3:50 , 將 BBS 系統中長度為零的檔案砍掉 +50 3 1 * * ( /usr/bin/find /home1/bbs -size 0 -exec rm -f {} ';' ) + +#每天早上 6:30 把bbs中的home和passwords備份 +30 6 * * * bin/backpasswd.sh > /dev/null diff --git a/pttbbs/sample/etc/Logout b/pttbbs/sample/etc/Logout new file mode 100644 index 00000000..c1552af8 --- /dev/null +++ b/pttbbs/sample/etc/Logout @@ -0,0 +1,20 @@ + +▆█ ▏  總 監 + ▍ ▏▋◤ ◥  (root) + ▎ ▌▌ PTT   DavidYu +  ︳ ▏▊◤ ◤ I`ll   +  / ▋▌  be back!  執行製作 + / ◢/  ◣   (bbsadm) + ▊◢◣●◤ ▆▃▃◣ ◢   DavidYu + ▋▂██  ◢ ◤  導 演 + ▋   (sysop) +   ─▏   DomaDoma Ricas  + ▄▄▂▍ ▍   keelar stary + ▋ ◥ ▌  + ▊▅▁ ◥╴ ▎  美術指導 +▇▄▂◥╴╴╴/◥▄▃▁   Skyline(視覺站長) Vica  + ◢█◤ ◥  精 華 區 + ◢◤◢▅▂ ▇▄▂▂▁▂  cbcdf + ▋ ▆▂ ◥ ◤  特別感謝 + ▍ ▆▂▉ ◣  *s +  Skyjade◣ ◤  (本站的最佳主角喔) diff --git a/pttbbs/sample/etc/Makefile b/pttbbs/sample/etc/Makefile new file mode 100644 index 00000000..8881af2a --- /dev/null +++ b/pttbbs/sample/etc/Makefile @@ -0,0 +1,18 @@ +SUBDIR=chickens +BBSHOME?=$(HOME) +TARGET=$(BBSHOME)/etc/ +FILES= Welcome Welcome_login goodbye register registered ve.hlp Logout\ + Welcome_birth domain_name_query feast today_boring + +all: + +install_sub: + @for i in $(SUBDIR); do\ + cd $$i;\ + make BBSHOME=$(BBSHOME) OSTYPE=$(OSTYPE) install;\ + cd ..;\ + done + +install: install_sub + install -d $(TARGET) + install -c -m 644 $(FILES) $(TARGET) diff --git a/pttbbs/sample/etc/Welcome b/pttbbs/sample/etc/Welcome new file mode 100644 index 00000000..c8abb5a0 --- /dev/null +++ b/pttbbs/sample/etc/Welcome @@ -0,0 +1,18 @@ + +Welcome to ... + + + + + + ____ _ _ ____ ____ ____ +| _ \| |_| |_ | __ )| __ ) ___| +| |_) | __| __| | _ \| _ \___ \ +| __/| |_| |_ | |_) | |_) |__) | +|_| \__|\__| |____/|____/____/ + + + + + +歡迎蒞臨◎PttBBS◎目前站上有[*u]人 diff --git a/pttbbs/sample/etc/Welcome_birth b/pttbbs/sample/etc/Welcome_birth new file mode 100644 index 00000000..c0496fed --- /dev/null +++ b/pttbbs/sample/etc/Welcome_birth @@ -0,0 +1,23 @@ + 嗨*s 忙嗎? 不要忘記自己的生日喔!! 記得發表感言.... + +  ╭╮╭╮╭──╮╭──╮╭──╮╭╮╭╮ +  │╰╯││ ☆ ││ ☆ ││ ☆ ││╰╯│ +  │╭╮││╭╮││╭─╯│╭─╯╰╮╭╯ +  ╰╯╰╯╰╯╰╯╰╯ ╰╯ ╰╯ +  ╭╮ + ╭╮ ☆ ╭──╮╭╯╰╮╭╮ ╭╮╭──╮╭╮╭╮ + │╰─╮╭╮│╭─╯╰╮╭╯│╰─╮╭─╯││ ☆ ││╰╯│ + │ ☆ │││││ │╰╮│╭╮││ ☆ ││╭╮│╰╮╭╯ + ╰──╯╰╯╰╯ ╰─╯╰╯╰╯╰──╯╰╯╰╯ ╰╯ + +贈詩一首送佳人,  ☉ ☉ ☉ ☉ 批踢踢實業坊全體員工 +予時霜雪臘月天;  ╭╮╭╮╭╮╭╮ +祝音輕吟繞東海, ╭┴┴┴┴┴┴┴┴╮ 誠心的祝福! +汝影蹤跡現南山; │☆★☆★☆★☆★│ 一個人生的另一個階段就此開始 +生機蓬勃冬不斷, ╭┴────────┴╮ 望能一帆風順. +日轉星移待明春; 澺 +快意暢活人間行, ││ +樂音環身樂自添. ┌┴──────────┴┐ + └────────────┘ + ★★祝你生日快樂★祝你生日快樂★祝你生日快樂★祝你生日快樂★祝你生日快樂★ + ▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁ diff --git a/pttbbs/sample/etc/Welcome_login b/pttbbs/sample/etc/Welcome_login new file mode 100644 index 00000000..e5560602 --- /dev/null +++ b/pttbbs/sample/etc/Welcome_login @@ -0,0 +1,12 @@ + + + + + + + + + 歡迎使用 PttBBS ! + + + 有任何問題請到 ptt2.csie.ntu.edu.tw 的 PttSrc 板討論唷! diff --git a/pttbbs/sample/etc/chickens/Makefile b/pttbbs/sample/etc/chickens/Makefile new file mode 100644 index 00000000..37d46a1b --- /dev/null +++ b/pttbbs/sample/etc/chickens/Makefile @@ -0,0 +1,23 @@ +BBSHOME?=$(HOME) +TARGET=$(BBSHOME)/etc/chickens/ +FILES= buymedicine buyoo clean deadth eat food hit kiss\ + medicine nofood nohp nosatis oo read sell toofat tootired\ + a0 a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 a12 a13 a14 a15 a16\ + b0 b1 b2 b3 b4 b5 b6 b7 b8 b9 b10 b11 b12 b13 b14 b15 b16\ + c0 c1 c2 c3 c4 c5 c6 c7 c8 c9 c10 c11 c12 c13 c14 c15 c16\ + d0 d1 d2 d3 d4 d5 d6 d7 d8 d9 d10 d11 d12 d13 d14 d15 d16\ + e0 e1 e2 e3 e4 e5 e6 e7 e8 e9 e10 e11 e12 e13 e14 e15 e16\ + f0 f1 f2 f3 f4 f5 f6 f7 f8 f9 f10 f11 f12 f13 f14 f15 f16\ + g0 g1 g2 g3 g4 g5 g6 g7 g8 g9 g10 g11 g12 g13 g14 g15 g16\ + h0 h1 h2 h3 h4 h5 h6 h7 h8 h9 h10 h11 h12 h13 h14 h15 h16\ + i0 i1 i2 i3 i4 i5 i6 i7 i8 i9 i10 i11 i12 i13 i14 i15 i16\ + j0 j1 j2 j3 j4 j5 j6 j7 j8 j9 j10 j11 j12 j13 j14 j15 j16\ + k0 k1 k2 k3 k4 k5 k6 k7 k8 k9 k10 k11 k12 k13 k14 k15 k16\ + l0 l1 l2 l3 l4 l5 l6 l7 l8 l9 l10 l11 l12 l13 l14 l15 l16\ + m0 m1 m2 m3 m4 m5 m6 m7 m8 m9 m10 m11 m12 m13 m14 m15 m16 + +all: + +install: + install -d $(TARGET) + install -c -m 644 $(FILES) $(TARGET) diff --git a/pttbbs/sample/etc/chickens/a0 b/pttbbs/sample/etc/chickens/a0 new file mode 100644 index 00000000..db81a6e2 --- /dev/null +++ b/pttbbs/sample/etc/chickens/a0 @@ -0,0 +1,11 @@ + + +  /// +  ☆  +  ●●  +  ●●●  +  ●●  +   + + + diff --git a/pttbbs/sample/etc/chickens/a1 b/pttbbs/sample/etc/chickens/a1 new file mode 100644 index 00000000..e0517a99 --- /dev/null +++ b/pttbbs/sample/etc/chickens/a1 @@ -0,0 +1,11 @@ + + + + ?? + ▂██▂ ★!! + ● ● ╱// + ● ● |/ + /●●/| + /|\ + + diff --git a/pttbbs/sample/etc/chickens/a10 b/pttbbs/sample/etc/chickens/a10 new file mode 100644 index 00000000..f57b0c1d --- /dev/null +++ b/pttbbs/sample/etc/chickens/a10 @@ -0,0 +1,15 @@ +  ◢◢ +  ◤ ● +  ● ●● ●  ◎● +  ● ● ● ● ●  ◣ +  ●  ● ● ● ●●● ● ● +  ● ●  ● ● ● +  ● ●  ● ● ● +  ●  ● ● ● ● +  ●  ● ● ● + ●●●╲●● ●● ●● +  ╱ ╲ ●●● ●●● +  /\╲ /\╲ ●● ●● + + + diff --git a/pttbbs/sample/etc/chickens/a11 b/pttbbs/sample/etc/chickens/a11 new file mode 100644 index 00000000..34c70f42 --- /dev/null +++ b/pttbbs/sample/etc/chickens/a11 @@ -0,0 +1,15 @@ +  ◢◢ +  ◤ ● +  ● ●● ●  ◎● +  ● ● ● ● ●  ◣ +  ●  ● ● ● ●●● ● ●  ●● ●● +  ● ●  ● ● ● ● ☉● ● ☉● +  ● ●  ● ● ● ● ◣ ●  ◣ +  ●  ● ● ● ● ● ● ● ● +  ●  ● ● ● ● ● ● ● + ●●●╲●● ●●● ●●● +  ╱ ╲  / \ / \ +  /\╲ /\╲ /|\ /|\ /|\ /|\ + + + diff --git a/pttbbs/sample/etc/chickens/a12 b/pttbbs/sample/etc/chickens/a12 new file mode 100644 index 00000000..1f5a40e6 --- /dev/null +++ b/pttbbs/sample/etc/chickens/a12 @@ -0,0 +1,13 @@ +  ◢◢ + ●●  ◤ ● + ● ● ●● ●  ◎● + ● ● ●  ● ● ●  ◣ + ● ●  ● ● ● ● ●● ● ● + ● ● ●  ● ●  ● ●● +  ● ●  ● ●  ● ● ● +  ●  ● ● ●  ● ● ● +  ●  ● ●  ●● ● + ●●●╲●● +  ╱ ╲ +  /\╲ /\╲ + diff --git a/pttbbs/sample/etc/chickens/a13 b/pttbbs/sample/etc/chickens/a13 new file mode 100644 index 00000000..2304849a --- /dev/null +++ b/pttbbs/sample/etc/chickens/a13 @@ -0,0 +1,14 @@ + +  ◢◢ +  ◤ ● +  ** ● ●● ●  ◎● +  *  ● ●  ● ● ●  ◣ +  *  ●  ● ● ● ● ●● ● ● + *  ● ● ● ●  ● ●● + * * ● ●  ● ●  ● ● ● +  * *  ●  ● ● ●  ● ● ● + *  *  *  ● ●  ●● ● +  * * ●●●╲●● +  ╱ ╲ +  /\╲ /\╲ + diff --git a/pttbbs/sample/etc/chickens/a14 b/pttbbs/sample/etc/chickens/a14 new file mode 100644 index 00000000..c8fc7efa --- /dev/null +++ b/pttbbs/sample/etc/chickens/a14 @@ -0,0 +1,17 @@ +  ◢◢ +  ◤ ● +  *● ●● ●  ●● +  *  ● ●  ● ● ●  ◣ 殺氣!! +  *  ●  ● ● ● ● ●● ● ● + * ● ● ● ●  ● ●● 鬥氣!! + * * ● ●  ● ●  ● ● ●  ◥ +  * *  ●  ● ● ●  ● ● ● ◣●- + *  *  *  ● ●  ●● ● |●- +  * * ●●●╲●● |●/ / / +  ╱ ╲ | ●●●< +  /\╲ /\╲ \ \ \ + + + + + diff --git a/pttbbs/sample/etc/chickens/a15 b/pttbbs/sample/etc/chickens/a15 new file mode 100644 index 00000000..79457982 --- /dev/null +++ b/pttbbs/sample/etc/chickens/a15 @@ -0,0 +1,15 @@ + + 嘿嘿!I CATCH YOU!! ◢◢ / + ◤ ● | ●< +  * ● ●● ● ∩● |●\ \ +  *  ● ●  ● ● ● ◣●\ +  *  ●  ● ● ● ● ●● ● ● /●\ + *  ● ● ● ●  ● ●● /●\ + * * ● ●  ● ●  ● ● ● ●◥ +  * *  ●  ● ● ●  ● ● ● ◣ ﹏help... + *  *  *  ● ●  ●● ● +  * * ●●●●╲● + ╱ ╲ +  /\╲ /\╲ + + diff --git a/pttbbs/sample/etc/chickens/a16 b/pttbbs/sample/etc/chickens/a16 new file mode 100644 index 00000000..79457982 --- /dev/null +++ b/pttbbs/sample/etc/chickens/a16 @@ -0,0 +1,15 @@ + + 嘿嘿!I CATCH YOU!! ◢◢ / + ◤ ● | ●< +  * ● ●● ● ∩● |●\ \ +  *  ● ●  ● ● ● ◣●\ +  *  ●  ● ● ● ● ●● ● ● /●\ + *  ● ● ● ●  ● ●● /●\ + * * ● ●  ● ●  ● ● ● ●◥ +  * *  ●  ● ● ●  ● ● ● ◣ ﹏help... + *  *  *  ● ●  ●● ● +  * * ●●●●╲● + ╱ ╲ +  /\╲ /\╲ + + diff --git a/pttbbs/sample/etc/chickens/a2 b/pttbbs/sample/etc/chickens/a2 new file mode 100644 index 00000000..6308e505 --- /dev/null +++ b/pttbbs/sample/etc/chickens/a2 @@ -0,0 +1,14 @@ +  !!!  ╲\\ +  ﹌  ▎ + ●●  █︴ + ● ● █ + ☆ ● ▎ + ∣\╲ ● + + ● ● + /● ●\ + /|\ /|\  ╲∣/ \∣/ +  ﹌﹌ ﹌  + + + diff --git a/pttbbs/sample/etc/chickens/a3 b/pttbbs/sample/etc/chickens/a3 new file mode 100644 index 00000000..d076a956 --- /dev/null +++ b/pttbbs/sample/etc/chickens/a3 @@ -0,0 +1,13 @@ +  ●● +  ● ● +  ● >● +  ●  ◣ +  ● ● +  ● ●  //╱ +  ● ●  ☆ +  ●●●●╲|/ ● + ╱  | ● ●● + /|\  ● ● ● ● +  ●● ● ●  + ﹌﹌ + diff --git a/pttbbs/sample/etc/chickens/a4 b/pttbbs/sample/etc/chickens/a4 new file mode 100644 index 00000000..ea9d6535 --- /dev/null +++ b/pttbbs/sample/etc/chickens/a4 @@ -0,0 +1,13 @@ +  ●●● +  ● ●  ???  +  ● ☉● +  ● ◣ +  ● ●  ?? +  ● ● ●  ●  ∪  ● +  ● ● ●  ●▕  ● +  ●●● ●  ●● +  ●●●●●  ▍ + / \  * ▍ * + /|\ /|\  * ▍* +  **  + diff --git a/pttbbs/sample/etc/chickens/a5 b/pttbbs/sample/etc/chickens/a5 new file mode 100644 index 00000000..9a014666 --- /dev/null +++ b/pttbbs/sample/etc/chickens/a5 @@ -0,0 +1,15 @@ +  My Brother?? +  ●●● +  ● ●  ▋ +  ● ●  ●● +  ●  ☉ ☉  ●  ● ● +  ● ●  ● ● +  ●  ◥◤  ●  ● ● +  ● ●  ● ● +  ● ●  ●  酒  ● + /  ●●●●● \  ● ● +  /|\ /|\  ●●●●● + + + + diff --git a/pttbbs/sample/etc/chickens/a6 b/pttbbs/sample/etc/chickens/a6 new file mode 100644 index 00000000..e85fba5a --- /dev/null +++ b/pttbbs/sample/etc/chickens/a6 @@ -0,0 +1,13 @@ +  ●●● +  ●  ● ●  ● +  ● ● ● ● ● ● +  ●  ●  ∩ ∩  ●  ●  !!!!  +  ●  ● ●  ● +  ● ●  ◥◤  ● ●  \/ +  ● ●  ◎◎ . +  ● ●  ●● . . +  ● ● . . +  ╱ ●●●●● ╲  . . . +  / | \ / | \ . . . . . + + diff --git a/pttbbs/sample/etc/chickens/a7 b/pttbbs/sample/etc/chickens/a7 new file mode 100644 index 00000000..6b245d46 --- /dev/null +++ b/pttbbs/sample/etc/chickens/a7 @@ -0,0 +1,16 @@ +  ◢◢  +  ◤ ●  I see you!! + ●  ◎● + ●  ↘◣  + ●●● ● ●↘ + ● ●●● ● ● ↘ + ● ● ↘ + ● ● ↘ + ● ● ↘ + ●●●╲●●  .. !!!! +  ╱ ╲   ∩ +  /\╲ /\╲  ∟﹏ + + + + diff --git a/pttbbs/sample/etc/chickens/a8 b/pttbbs/sample/etc/chickens/a8 new file mode 100644 index 00000000..9482ca62 --- /dev/null +++ b/pttbbs/sample/etc/chickens/a8 @@ -0,0 +1,13 @@ +  ◢◢ +  ◤ ● +  ● ●● ●  ◎● +  ● ● ● ● ●  ◣ +  ●  ● ● ● ●●● ● ● +  ● ●  ● ● ● +  ● ●  ● ● ● +  ●  ● ● ● ● +  ●  ● ● ● + ●●●╲●● +  ╱ ╲ +  /\╲ /\╲ + diff --git a/pttbbs/sample/etc/chickens/a9 b/pttbbs/sample/etc/chickens/a9 new file mode 100644 index 00000000..e2010a91 --- /dev/null +++ b/pttbbs/sample/etc/chickens/a9 @@ -0,0 +1,14 @@ +  ◢◢  ◣◣ +  ◤ ● ●  ◥ +  ● ●● ●  ◎● ●◎ ● +  ● ● ● ● ●  ◣ ◢ ● +  ●  ● ● ● ●●● ● ● ● ● ●●● +  ● ●  ● ● ● ● ● ●● ● +  ● ●  ● ● ● ● ● +  ●  ● ● ● ● ● ● +  ●  ● ● ● ● ● + ●●●╲●● ●●╱●● +  ╱ ╲  ╱ ╲  +  /\╲ /\╲  ╱/\ ╱/\ + + diff --git a/pttbbs/sample/etc/chickens/b0 b/pttbbs/sample/etc/chickens/b0 new file mode 100644 index 00000000..5df42752 --- /dev/null +++ b/pttbbs/sample/etc/chickens/b0 @@ -0,0 +1,9 @@ + + + + +   +  ◤ ◥  +   美   +  ◥ ◤  +   diff --git a/pttbbs/sample/etc/chickens/b1 b/pttbbs/sample/etc/chickens/b1 new file mode 100644 index 00000000..0f6bb405 --- /dev/null +++ b/pttbbs/sample/etc/chickens/b1 @@ -0,0 +1,9 @@ + + +   +  ◤ ▂◥  +   ▃ ▃   +   ◥O◤   +   ● ●   +  ◥ ◤  +   diff --git a/pttbbs/sample/etc/chickens/b10 b/pttbbs/sample/etc/chickens/b10 new file mode 100644 index 00000000..920fd9a9 --- /dev/null +++ b/pttbbs/sample/etc/chickens/b10 @@ -0,0 +1,14 @@ + +   +  ◤▂▂ ◥  +   ︵ ︵   +   ● ︽  —☆  +   ◥ ▼◤  +  ◤▼◥  +   口口   +       +  ◤/II\◥  +     +     +   ▄   +   diff --git a/pttbbs/sample/etc/chickens/b11 b/pttbbs/sample/etc/chickens/b11 new file mode 100644 index 00000000..920fd9a9 --- /dev/null +++ b/pttbbs/sample/etc/chickens/b11 @@ -0,0 +1,14 @@ + +   +  ◤▂▂ ◥  +   ︵ ︵   +   ● ︽  —☆  +   ◥ ▼◤  +  ◤▼◥  +   口口   +       +  ◤/II\◥  +     +     +   ▄   +   diff --git a/pttbbs/sample/etc/chickens/b12 b/pttbbs/sample/etc/chickens/b12 new file mode 100644 index 00000000..0519b4ed --- /dev/null +++ b/pttbbs/sample/etc/chickens/b12 @@ -0,0 +1,15 @@ + +  ◤▂▂◥  +   ︵︵   +   ●●   +   ◥▼◤   +   ◤▼◥   +    ◥◤    +         +   IIII   +  I●●I  +  IIIIIIII  +  IIIIIIII  +  IIIIIIII  +     +   ▄   diff --git a/pttbbs/sample/etc/chickens/b13 b/pttbbs/sample/etc/chickens/b13 new file mode 100644 index 00000000..84f408bf --- /dev/null +++ b/pttbbs/sample/etc/chickens/b13 @@ -0,0 +1,17 @@ +   +  ◤▂▂◥ e  +   ︵︵   +   ︽︽   +  ◥◥◤◤  +  ◤▼◥  +   ▼   +   :   +   :   +   :   +   ∥∥   +  ∥∥  +  ∥∥  +  ∥∥  +  |  +   ▄   +   diff --git a/pttbbs/sample/etc/chickens/b14 b/pttbbs/sample/etc/chickens/b14 new file mode 100644 index 00000000..1c7cd389 --- /dev/null +++ b/pttbbs/sample/etc/chickens/b14 @@ -0,0 +1,16 @@ + +  ●▅▅●  +  ◤  ︵︵  ◥  +     ●●     +  ◥ ◥▼◤ ◤  +  ◤▼◥  +   ]   +  ▄     ▄  +  ▄▄IIII▄▄  +  IIIIII  +  IIIIIIII  +  IIIIIIII  +  IIIIIIII  +  |  +   ▄   +   diff --git a/pttbbs/sample/etc/chickens/b15 b/pttbbs/sample/etc/chickens/b15 new file mode 100644 index 00000000..0e325c1c --- /dev/null +++ b/pttbbs/sample/etc/chickens/b15 @@ -0,0 +1,17 @@ + +  ◤ ◥  +   ︵   +   ◤●   +   ◥◤ ▌  +  ▌◤▼◥▌  +  ▌ p ▌  +  ▌   ▌  +    IIII   +   IIIIII   +  IIIIIIII  +  IIIIIIII  +  IIIIIIII  +  IIIIIIII  +     +   ▄   +   diff --git a/pttbbs/sample/etc/chickens/b16 b/pttbbs/sample/etc/chickens/b16 new file mode 100644 index 00000000..b25212a0 --- /dev/null +++ b/pttbbs/sample/etc/chickens/b16 @@ -0,0 +1,18 @@ +   +  ◤ ◥  +   ︵   +   ◤︽   +   ◥◤ ▌  +  ▌◤▼◥▌  +  ▌ W ▌  +  ▌  |  ▌  +  ▌ ◤◥ ▌  +  ▌ IIII█  +  ▌ IIII█  +  IIII  +  IIII  +  IIII  +  |  +   ▄   +   + diff --git a/pttbbs/sample/etc/chickens/b2 b/pttbbs/sample/etc/chickens/b2 new file mode 100644 index 00000000..ffbe656a --- /dev/null +++ b/pttbbs/sample/etc/chickens/b2 @@ -0,0 +1,11 @@ + + +   +  ◤ ◥  +   . .  呀  +  ◥O◤  +  ● ●  +  ◤ ◥  +  _ _  +   + diff --git a/pttbbs/sample/etc/chickens/b3 b/pttbbs/sample/etc/chickens/b3 new file mode 100644 index 00000000..68a81361 --- /dev/null +++ b/pttbbs/sample/etc/chickens/b3 @@ -0,0 +1,10 @@ + + +   +  ◤▂▂◥  +   ︵︵   +   ◥▼◤   +  ● ●  +  ◤ ◥  +  ▃  +   diff --git a/pttbbs/sample/etc/chickens/b4 b/pttbbs/sample/etc/chickens/b4 new file mode 100644 index 00000000..fde65f4c --- /dev/null +++ b/pttbbs/sample/etc/chickens/b4 @@ -0,0 +1,11 @@ + + +   +  ◤▂▂◥  +   ︵︵   +   ◥▼◤   +  ● ●  +  ◤ ◥  +     +  ▃  +   diff --git a/pttbbs/sample/etc/chickens/b5 b/pttbbs/sample/etc/chickens/b5 new file mode 100644 index 00000000..b74b0bfb --- /dev/null +++ b/pttbbs/sample/etc/chickens/b5 @@ -0,0 +1,12 @@ + + +   +  ◤▂▂◥  +   ︵︵   +   ◥▼◤   +   ◥◤   +       +  ◤ ◥  +     +  ▃  +   diff --git a/pttbbs/sample/etc/chickens/b6 b/pttbbs/sample/etc/chickens/b6 new file mode 100644 index 00000000..279b0c2a --- /dev/null +++ b/pttbbs/sample/etc/chickens/b6 @@ -0,0 +1,12 @@ + + +   +  ◤▂▂◥  +   ︵︵   +   ◥▼◤   +   ◥◤   +    :    +  ◤ ◥  +     +  ▃  +   diff --git a/pttbbs/sample/etc/chickens/b7 b/pttbbs/sample/etc/chickens/b7 new file mode 100644 index 00000000..279b0c2a --- /dev/null +++ b/pttbbs/sample/etc/chickens/b7 @@ -0,0 +1,12 @@ + + +   +  ◤▂▂◥  +   ︵︵   +   ◥▼◤   +   ◥◤   +    :    +  ◤ ◥  +     +  ▃  +   diff --git a/pttbbs/sample/etc/chickens/b8 b/pttbbs/sample/etc/chickens/b8 new file mode 100644 index 00000000..0b429152 --- /dev/null +++ b/pttbbs/sample/etc/chickens/b8 @@ -0,0 +1,13 @@ + + +   +  ◤▂▂ ◥  +   ︵ ︵   +   ● ︽  —☆  +   ◥ ▼◤  +  ◤▼◥  +   口口   +  ◤/II\◥  +     +   ▄   +   diff --git a/pttbbs/sample/etc/chickens/b9 b/pttbbs/sample/etc/chickens/b9 new file mode 100644 index 00000000..0b429152 --- /dev/null +++ b/pttbbs/sample/etc/chickens/b9 @@ -0,0 +1,13 @@ + + +   +  ◤▂▂ ◥  +   ︵ ︵   +   ● ︽  —☆  +   ◥ ▼◤  +  ◤▼◥  +   口口   +  ◤/II\◥  +     +   ▄   +   diff --git a/pttbbs/sample/etc/chickens/buymedicine b/pttbbs/sample/etc/chickens/buymedicine new file mode 100644 index 00000000..5fe11de7 --- /dev/null +++ b/pttbbs/sample/etc/chickens/buymedicine @@ -0,0 +1,14 @@ + + + + + + +  W R I G L E Y'S ◥ +  ψ《DOUBLEMINT》  ▔▔▔▔▔▍ +  CHEWING GUM  INT》 ▍ + ◥ ◥ ▍ + ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔ + + + 買口香糖當感冒藥... diff --git a/pttbbs/sample/etc/chickens/buyoo b/pttbbs/sample/etc/chickens/buyoo new file mode 100644 index 00000000..21d5f32a --- /dev/null +++ b/pttbbs/sample/etc/chickens/buyoo @@ -0,0 +1,14 @@ + + │ │ +  ▲____________________▲ + Ⅲ ◢◣ ┼ ◢◣ Ⅲ + ≡ 田田 田田 ≡ + ▲ █====田田====田田====█ ▲ + █ΨΨΨΨ█ΠΠΠΠΠΠΠΠΠΠ█ΨΨΨΨ█ + ▕▔▔▔◥◎◤▔▔▔▔▔▔▔▔◥◎◤▔▔▔▏ + ▕ 田田 █ 田田 田田 田田 █ 田田 ▏ +  ▕ 田田 █ 田田§▉▉§田田 █ 田田 ▏ +  ▕※※※※※█※※※※▉▉※※※※█※※※※※▏ + ■══════════◢灨岷丐丐丐丐丐丐丐丐丐丑 + + 到教堂求得神奇大補丸一顆 diff --git a/pttbbs/sample/etc/chickens/c0 b/pttbbs/sample/etc/chickens/c0 new file mode 100644 index 00000000..388926ab --- /dev/null +++ b/pttbbs/sample/etc/chickens/c0 @@ -0,0 +1,8 @@ + + + ◢█◣ +  \█/  哇∼哇∼ + ◥O◤ + /╱█ + ╱██ + ◥█◤ diff --git a/pttbbs/sample/etc/chickens/c1 b/pttbbs/sample/etc/chickens/c1 new file mode 100644 index 00000000..8311a4af --- /dev/null +++ b/pttbbs/sample/etc/chickens/c1 @@ -0,0 +1,9 @@ + + ◢ + ████ 什麼是勇士啊? + █◤︵◥◣ + ◥██i█ + ◥██◤ + ◢ ▼ ◣ + █ ◎ █ + diff --git a/pttbbs/sample/etc/chickens/c10 b/pttbbs/sample/etc/chickens/c10 new file mode 100644 index 00000000..bfafeffc --- /dev/null +++ b/pttbbs/sample/etc/chickens/c10 @@ -0,0 +1,11 @@ + ◣ + ████ 朝真暮偽誰能辨 + ██◤◥█ + █◤▌██◤ 智愚永是兩公平 + ◤◥██◤ + ◥█◎◤▼◥◎█◤ + ◥█ ╳ █◤ + █◥ 癡 ◤█ + ◥█◣ █◢ █ + ███●▄▄▄▄▄▄▄▄▄▄▄▄◤ + ▋◥ diff --git a/pttbbs/sample/etc/chickens/c11 b/pttbbs/sample/etc/chickens/c11 new file mode 100644 index 00000000..0170493b --- /dev/null +++ b/pttbbs/sample/etc/chickens/c11 @@ -0,0 +1,10 @@ + + ◥█◣ ◢ + ████ 人稱一流刀一流 + ◥◣▍ █◤◥██ +◢████████████●██ ◥██▌◥█ 刀稱一流人一流 + ◢◤█ ◥██◤◥ + ██◣ ◥ ▼ ◤ ◢████▅ + █◣ ◥◤ ◢█ + ██◣ ◢██ + ██ 武 ██ diff --git a/pttbbs/sample/etc/chickens/c12 b/pttbbs/sample/etc/chickens/c12 new file mode 100644 index 00000000..020ae4ca --- /dev/null +++ b/pttbbs/sample/etc/chickens/c12 @@ -0,0 +1,12 @@ + + ◣ ◢█◤ + ████ 東風吹醒英雄夢 + ██◤◥█ + █◤▌██◤ 笑對千山萬重天 + ◤◥██◤ + ◣◥█◎◤▼◥◎█◤◢ + ◣◥█ ╳ █◤◢ +◢█◣ █◥ 殺 ◤█ +◤ ◥█◣ █◢◤ █ + ███●▄▄▄▄▄▄▄▄▄▄▄▄▄◤ + ▋◥◣ diff --git a/pttbbs/sample/etc/chickens/c13 b/pttbbs/sample/etc/chickens/c13 new file mode 100644 index 00000000..f842255c --- /dev/null +++ b/pttbbs/sample/etc/chickens/c13 @@ -0,0 +1,11 @@ + ◥█◣ ◢ + ████ 寒劍默聽君子意 + █◤◥██ + ◥██▌◥█ 傲視人間笑紅塵 + ◥██◤◥ + ◥◥ ▽ ◤◤▼◥◥ ▽ ◤◤ + ◥◥◤◤ ∣ ◥◥◤◤ +  ◥◤█ 天 █◥◤  +  ◥◣ █◢◤  +  ◥███●▄▄▄▄▄▄▄▄▄▄▄▄▄◤ +   ▋◥◣  diff --git a/pttbbs/sample/etc/chickens/c14 b/pttbbs/sample/etc/chickens/c14 new file mode 100644 index 00000000..35636ed9 --- /dev/null +++ b/pttbbs/sample/etc/chickens/c14 @@ -0,0 +1,12 @@ + ◥█◣ ◢ + ████ 一簫一劍平生意 + █◤◥██ ▍ + ◥██▌◥█ █ 負盡狂名十五年 + ◥██◤◥ █ + ◣◥◥◤◤▼◥◥◤◤◢█ + ◣◥█□╳□█◤◢ + ◢█◣  █◥◣╳ ◤◢  + ◤ ◥█◣  █◢◤悟   + ███●▄▄▄▄▄▄▄▄▄▄▄▄▄▄◤ +  ▋◥◣∣   +  ◤∣   diff --git a/pttbbs/sample/etc/chickens/c15 b/pttbbs/sample/etc/chickens/c15 new file mode 100644 index 00000000..89822c4f --- /dev/null +++ b/pttbbs/sample/etc/chickens/c15 @@ -0,0 +1,12 @@ +  ◣ ◣ ◢ + ◥ ◥ ◤ ◢ 簫中弦音藏柔情 + ◣◥█◣ ◢ ◤ 劍下腥血記恨仇 + ◥◣ ◥ ████ ◢ ◢◤ ◢◤ 來何洶湧需揮劍 + ◥◣ ◣  █◤◥██ ◤ ◢◤ ◢◤ 去向纏綿可復簫 + ◥  ◥██▌◥█ ◣ + ◥◣ ◣◥ ◥██◤◥ ◤◢ ◢◤ + ◣◥██◤▼◥██◤◢████●▄▄▄▄▄▄▄▄▄▄▄▄▄▄◤ + ◢◣◥×□╳□×◤◢◣ ▆◥◣ + ◢ ◣◥ ╳ ◤◢ ◣ ◤ + ◢ █◣ 怒 ◢ ◣ + ◢ █ ███ ◣ diff --git a/pttbbs/sample/etc/chickens/c16 b/pttbbs/sample/etc/chickens/c16 new file mode 100644 index 00000000..93b54373 --- /dev/null +++ b/pttbbs/sample/etc/chickens/c16 @@ -0,0 +1,11 @@ + + 愛落紅塵心已死 ◢ + ◢████ + 持刀抱劍了一生 ██◤◥██ + ◢ ██ ▌◥█ + ◥◣ ◣◥ ◢████◤◥ ◤◢ +◥▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄●████◣◥██◤▼◥██◤◢ + ◢◤▆ ◣◥█ ╳ █◤◢◣ + ◥ █◣◥ ╳ ◤◢ █◣ + ∼刀狂劍痴∼ ██◣ 隱 ◢█ ██◣ + ██████ █ ███◣ diff --git a/pttbbs/sample/etc/chickens/c2 b/pttbbs/sample/etc/chickens/c2 new file mode 100644 index 00000000..19901098 --- /dev/null +++ b/pttbbs/sample/etc/chickens/c2 @@ -0,0 +1,9 @@ + + ◣ + ████ + ◢◤︵◥█ + █i██◤ + ◥██◤ + ◢ ▼ ◣ + ◢◤ ◎ ◥◣ + █ █ diff --git a/pttbbs/sample/etc/chickens/c3 b/pttbbs/sample/etc/chickens/c3 new file mode 100644 index 00000000..362d06f0 --- /dev/null +++ b/pttbbs/sample/etc/chickens/c3 @@ -0,0 +1,8 @@ + + ◣ + ████ + ◢◤︵◥█ + █i██◤ + ◥██◤ + ███◥ ▼ ◤███ +  ◥◤  diff --git a/pttbbs/sample/etc/chickens/c4 b/pttbbs/sample/etc/chickens/c4 new file mode 100644 index 00000000..88095521 --- /dev/null +++ b/pttbbs/sample/etc/chickens/c4 @@ -0,0 +1,11 @@ + +  + i + i ◢ 你!敢接受我的挑戰嗎? + i ████ + i █◤︵◥█ + i ◥██i█◥ + ◥●◤ ◥██◤ + ███◥█▼█◤███▅ + █ ◢ ███ ◣ + ◢ █勇█ ◣ diff --git a/pttbbs/sample/etc/chickens/c5 b/pttbbs/sample/etc/chickens/c5 new file mode 100644 index 00000000..ad2311ba --- /dev/null +++ b/pttbbs/sample/etc/chickens/c5 @@ -0,0 +1,12 @@ + + +  + i + i ◢ 你!敢接受我的挑戰嗎? + i ████ + i █◤︵◥█ + i ◥██i█◥ + ◥●◤ ◥██◤ + ███◥█▼█◤███▅ + █ ◢ ███ ◣ + ◢ █勇█ ◣ diff --git a/pttbbs/sample/etc/chickens/c6 b/pttbbs/sample/etc/chickens/c6 new file mode 100644 index 00000000..ee018e38 --- /dev/null +++ b/pttbbs/sample/etc/chickens/c6 @@ -0,0 +1,10 @@ + +  ◣ + i ████ 放馬過來! + i █◤︵██ + i ◤█i◥█◤ + i ◥██◤ + i ◢█◤▼◥█◣ +  ◥●◤ ◢◤█╳██◣ + ▆███◤█ 忍 █ ◣ + █ █ █ █ diff --git a/pttbbs/sample/etc/chickens/c7 b/pttbbs/sample/etc/chickens/c7 new file mode 100644 index 00000000..0db89687 --- /dev/null +++ b/pttbbs/sample/etc/chickens/c7 @@ -0,0 +1,12 @@ + +  + i 別 人 的 失 敗 就 是 我 的 快 樂 啦 ! + i ◣ + i ████ + i █◤︵◥█ + i ◤█i██◤ + i ◥██◤ + i ◥█◣▼◢█◤ + ◥●◤ ◢◤◥█◤█◣ + ███◤█ █ ◣ + █ █ 命 █ █ diff --git a/pttbbs/sample/etc/chickens/c8 b/pttbbs/sample/etc/chickens/c8 new file mode 100644 index 00000000..22be6bab --- /dev/null +++ b/pttbbs/sample/etc/chickens/c8 @@ -0,0 +1,12 @@ + ◢ + ████ 雙腳踢翻塵世浪 + █◤◥██ + ◥██▌◥█ 一肩擔盡古今愁 + ◥██◤◥ + █∞◤▼◥∞█ + █◤ ◥█ + ◤█ 狂 █◥ + ◥◣ █◢ + ◥███●▄▄▄▄▄▄▄▄▄▄▄▄▄◤ + ◢ ▋◥ + ◤ diff --git a/pttbbs/sample/etc/chickens/c9 b/pttbbs/sample/etc/chickens/c9 new file mode 100644 index 00000000..676a0da9 --- /dev/null +++ b/pttbbs/sample/etc/chickens/c9 @@ -0,0 +1,11 @@ + ◣ + ◥◣ + ◥◣ ◣ + ◥◣ ████ 征衣紅塵化雲煙 + ◥◣ ██◤◥█ + ◥◣ █◤▌██◤ 江湖落拓不知年 + ◥◣ ◤◥██◤ + ◥◣ ◢██◣ ▼ ◢██◣ + ◥◣ ◢◤◥◣◢◤◥◣ + ◥█◣◢◤ ◣◥◤◢ █ + ▆█◤ ◥ 劍 ◤ █ diff --git a/pttbbs/sample/etc/chickens/clean b/pttbbs/sample/etc/chickens/clean new file mode 100644 index 00000000..9d9118a3 --- /dev/null +++ b/pttbbs/sample/etc/chickens/clean @@ -0,0 +1,14 @@ +  朅_____________________▕▔▔▏_______▕\___ +  矙朅______________ /▏ ● ●_________●▕___ +  矙矙鱌_____________▕ ● _________▕ )____●___ +  朅______________●_____________●____________ +  + 『████ + ████ + ▁▁▁▁▁▁▁▁◎████ + ▆▆▆▆▆▆▆▆▉████ + ◥  + ◥█████ + ◢ +  ▔▔▔▔▔▔ + 洗洗澡..清除便便.. diff --git a/pttbbs/sample/etc/chickens/d0 b/pttbbs/sample/etc/chickens/d0 new file mode 100644 index 00000000..ea818c4d --- /dev/null +++ b/pttbbs/sample/etc/chickens/d0 @@ -0,0 +1,10 @@ + + |/╱ + ☆ +   +  ●●  +  ●蛛●  +  ●●  +   + + diff --git a/pttbbs/sample/etc/chickens/d1 b/pttbbs/sample/etc/chickens/d1 new file mode 100644 index 00000000..91e04a2f --- /dev/null +++ b/pttbbs/sample/etc/chickens/d1 @@ -0,0 +1,9 @@ + + 生命?? + ﹏ + ╲\| ●● + ★ ●︴ ★ + !! ● ◢▎ + ● ● ◣ + ●● \|/ ▎\|/ \|/ +  ﹌  diff --git a/pttbbs/sample/etc/chickens/d10 b/pttbbs/sample/etc/chickens/d10 new file mode 100644 index 00000000..714254ea --- /dev/null +++ b/pttbbs/sample/etc/chickens/d10 @@ -0,0 +1,11 @@ + + ●● ● !!!! + ● ● ∩\ + ● ☆ ● ●●\\ !!!! ||∣ + ● ★ ● ☉ ||∣ + ●● ● ● ● ◣ ☉___________ + ●/_●﹍● ●\_ ︼︾ ☉---︶︶︶︶ . . . . . . + ●\ ●\ ●/ ●/ ||∣ + ◥ ◥ ▼ ◤ ∪/ + + diff --git a/pttbbs/sample/etc/chickens/d11 b/pttbbs/sample/etc/chickens/d11 new file mode 100644 index 00000000..b7e86634 --- /dev/null +++ b/pttbbs/sample/etc/chickens/d11 @@ -0,0 +1,15 @@ + + 等等我!! ◢◣◢◣ + ████ + ◥██◤ + ●● ● ◥◤ + ● ☆ ● + ● ★ ● ●●\\ ●● + ● ☆ ● ∩ ● ● ●●\ + ● ● ● ●● ◣ ● ● ∩ + ●▅●▅●▅--●▃︼︾ ▅●▅●▅ ●▃ ◣ + ●/ ●/ ●/ \● // // // \\ + ◥\ ◥\ ◥\ |◤ [1;35m\| \| \| |/ +   + + diff --git a/pttbbs/sample/etc/chickens/d12 b/pttbbs/sample/etc/chickens/d12 new file mode 100644 index 00000000..ab421653 --- /dev/null +++ b/pttbbs/sample/etc/chickens/d12 @@ -0,0 +1,13 @@ + ▂◢▂ ▂◢▂ ▂▎ + ◥ . ◥ ▎ + . ▎ + ●● ● . ▎ + ● ☆ ● >●●∠ ▎ + ● ★ ● ●●\\ —●●- ▎ + ● ☆ ● ∩ / OO \ ▎ + ● ● ● ●● ◣ ▎ + ●▅●▅●▅--●▃︼︾ ▎ + ●/ ●/ ●/ ●/ ▎ + ◥\ ◥\ ◥\ ◤ +   + diff --git a/pttbbs/sample/etc/chickens/d13 b/pttbbs/sample/etc/chickens/d13 new file mode 100644 index 00000000..48cef654 --- /dev/null +++ b/pttbbs/sample/etc/chickens/d13 @@ -0,0 +1,13 @@ + 小魔星?? + ● ● ● + ● * ● + ● * ● ●●\\ + ● * ●● ︵● + ● * ∩ ● + ● ●* ● *●●● ◣ + ● ●/ |●╱ ●\ ● ●●︼ + ●/—●/—●\ ●\ + ●\ ●\ ●\ ●\ + ◤ ◥ ◥ ◥ \|/ \|/ +   + diff --git a/pttbbs/sample/etc/chickens/d14 b/pttbbs/sample/etc/chickens/d14 new file mode 100644 index 00000000..02f91a47 --- /dev/null +++ b/pttbbs/sample/etc/chickens/d14 @@ -0,0 +1,13 @@ + ︵ ︵ + 鬥!! ╲╱ / |╱ | ︴ + ● ● ● ◎◎/ ╱ / ︴ + ● * ● ▼●╱ // + ●* * * * ● ●●\\ / / 》_╱ ╱ + ● * * ●● ︵● / /○ _╱ + ● * * * * ● ● // ● ﹏ + ●*● *● ●● ◣ ● ● + ● ●/ /● ●\ ╲●︾︼ ●● + ●/—●/—\●﹉ ●\ ╱ + \● \● \● \● ☆ + ◥ ◥ ◥ ◥ + diff --git a/pttbbs/sample/etc/chickens/d15 b/pttbbs/sample/etc/chickens/d15 new file mode 100644 index 00000000..2c305cb5 --- /dev/null +++ b/pttbbs/sample/etc/chickens/d15 @@ -0,0 +1,11 @@ + ● ● ●●\\ + ● * ●● ︽● + ● * ▼ ● + ● * ●| ● ◣ + ● * ●|╱ ●●︼/ + ● ●* ● ● //●\ _______ \/ + ●/ ●/ ●/_/ ●\ < ﹍/﹍/╲\>< + ●/--●/--●\ ◥●\_\_ ╱○●▼/ + ●\ ●\ ●\ ●●●Ω Ω Ω + ◥ ◥ ◥ ╱ + diff --git a/pttbbs/sample/etc/chickens/d16 b/pttbbs/sample/etc/chickens/d16 new file mode 100644 index 00000000..2c305cb5 --- /dev/null +++ b/pttbbs/sample/etc/chickens/d16 @@ -0,0 +1,11 @@ + ● ● ●●\\ + ● * ●● ︽● + ● * ▼ ● + ● * ●| ● ◣ + ● * ●|╱ ●●︼/ + ● ●* ● ● //●\ _______ \/ + ●/ ●/ ●/_/ ●\ < ﹍/﹍/╲\>< + ●/--●/--●\ ◥●\_\_ ╱○●▼/ + ●\ ●\ ●\ ●●●Ω Ω Ω + ◥ ◥ ◥ ╱ + diff --git a/pttbbs/sample/etc/chickens/d2 b/pttbbs/sample/etc/chickens/d2 new file mode 100644 index 00000000..b256f5e5 --- /dev/null +++ b/pttbbs/sample/etc/chickens/d2 @@ -0,0 +1,11 @@ + ▆▆▆▆▆▆▆ + . + . + . + . + >●●∠ \★/ \★/ + —●●- 喔? ◢▎ ◢▎ + / OO \ ◣ ◣ + \|/ ▎\|/ ▎ \|/ +   + diff --git a/pttbbs/sample/etc/chickens/d3 b/pttbbs/sample/etc/chickens/d3 new file mode 100644 index 00000000..c0dacb46 --- /dev/null +++ b/pttbbs/sample/etc/chickens/d3 @@ -0,0 +1,16 @@ + ▆▆▆▆▆▆▆▆ + . + . + . + . 嘿嘿!dinner? + >●●< + —●●— + /☉☉\ + \/ ?? + + >♁﹏﹏ \|/ \|/ +   + + + + diff --git a/pttbbs/sample/etc/chickens/d4 b/pttbbs/sample/etc/chickens/d4 new file mode 100644 index 00000000..a11683f0 --- /dev/null +++ b/pttbbs/sample/etc/chickens/d4 @@ -0,0 +1,12 @@ + ▆▆▆▆▆▆▆▆ + . + . + . + . 嘿嘿!BIG DINNER!! + —●●— + > ● < + /∩∩\ ??? + () + >●O● ﹏﹏ +  ^ ^ ^  + diff --git a/pttbbs/sample/etc/chickens/d5 b/pttbbs/sample/etc/chickens/d5 new file mode 100644 index 00000000..30ca6a2c --- /dev/null +++ b/pttbbs/sample/etc/chickens/d5 @@ -0,0 +1,14 @@ + ▆▆▆▆▆▆▆▆ + . + . + . + \ . / ☆ + ╲◢◣╱ ★ + \—██—/ + ☆ /—██—\ 倒吊太久會不會腦充血啊?? + ╱**╲ + / () \ ☆ + ★ + + + diff --git a/pttbbs/sample/etc/chickens/d6 b/pttbbs/sample/etc/chickens/d6 new file mode 100644 index 00000000..7e30c6b6 --- /dev/null +++ b/pttbbs/sample/etc/chickens/d6 @@ -0,0 +1,12 @@ + + ●● 可怕嗎?? + \ ● ● / + ╲_● ●_╱ 快閃!!! + _● ●_ + \╱ _● ●_ ╲/ ◎●/ + ╱ ● ● ╲ . . ●◎\ + ╱‾●︵︵●‾╲ . . + / ◥◎◎◤ \ . . + ( ) . . + . . . + diff --git a/pttbbs/sample/etc/chickens/d7 b/pttbbs/sample/etc/chickens/d7 new file mode 100644 index 00000000..535e5503 --- /dev/null +++ b/pttbbs/sample/etc/chickens/d7 @@ -0,0 +1,16 @@ + . + . 陷阱??? + ●● + \ ● ● / + ╲_● ●_╱ ▃▃◢▃▃▃◢▃ + _● ●_ XXXXX◥XXXX + \╱ _● ●_ ╲/XXXXX \/ XX help﹏ + ╱ ● ● ╲ XXXX ◎●︴XX▎ + ╱‾●︵︵●‾╲ ◥XX ●◎ XX◤ + / ◥∩∩◤ \ ◥XX﹌ XX ▎ + ( ) ◥XXXXX◥ + ◥XXX ▎╲∣/ \|╱ + + + + diff --git a/pttbbs/sample/etc/chickens/d8 b/pttbbs/sample/etc/chickens/d8 new file mode 100644 index 00000000..ed46f5e9 --- /dev/null +++ b/pttbbs/sample/etc/chickens/d8 @@ -0,0 +1,14 @@ + + //╱ 流星!! + ☆ + ● ● + ● ● ●●\\ + ● ● ∩ 許個願吧! + ● ● ◣ 快快長大!! + ▅●▅●▅ ●▃︾ + // // // \\ + \| \| \| |/ \|/ \|╱ \|/ +   + + + diff --git a/pttbbs/sample/etc/chickens/d9 b/pttbbs/sample/etc/chickens/d9 new file mode 100644 index 00000000..409ae520 --- /dev/null +++ b/pttbbs/sample/etc/chickens/d9 @@ -0,0 +1,13 @@ + + // ╱ + ●● ● //╱ 隕石?? + ● Χ ● ★ + ● Χ ● ●●\\ + ● Χ ● > + ● ● ● ● ◣ 許願的代價? + ●/▅●▅●/▅● ︼︾ + ●\ ●\ ●\ ●\ + ◥ ◥ ◥ ◥ \|/ \|/ \|/ +   + + diff --git a/pttbbs/sample/etc/chickens/deadth b/pttbbs/sample/etc/chickens/deadth new file mode 100644 index 00000000..ff9b3687 --- /dev/null +++ b/pttbbs/sample/etc/chickens/deadth @@ -0,0 +1,15 @@ + + + + ╭╮﹏﹏{{ + ◥███◤ + @`@`〝 +  "_  + ▄▄ + ぬ███  + █  +   +   +  ╭┘ │  + └─-┘ + 嗚 死翹翹了 下次再來吧~~~~ diff --git a/pttbbs/sample/etc/chickens/e0 b/pttbbs/sample/etc/chickens/e0 new file mode 100644 index 00000000..b66f2972 --- /dev/null +++ b/pttbbs/sample/etc/chickens/e0 @@ -0,0 +1,6 @@ + + + ●● + ●●● + ●● + diff --git a/pttbbs/sample/etc/chickens/e1 b/pttbbs/sample/etc/chickens/e1 new file mode 100644 index 00000000..b66f2972 --- /dev/null +++ b/pttbbs/sample/etc/chickens/e1 @@ -0,0 +1,6 @@ + + + ●● + ●●● + ●● + diff --git a/pttbbs/sample/etc/chickens/e10 b/pttbbs/sample/etc/chickens/e10 new file mode 100644 index 00000000..72d37fd8 --- /dev/null +++ b/pttbbs/sample/etc/chickens/e10 @@ -0,0 +1,12 @@ + + ◣◣◢◢ + ◣◣◣◣◣◢ + ●●●●●●●● +  ●●●╳●●╳●●● +  ●●▼▼▼▼▼▼▼●● +  ●● ●●  ◤ + ●●▲▲▲▲▲●● ●◤◤◤ + ● ●●●●●●●●●● ◤●● ◤ + ●●●●●●●●●●●●●●● ◤◤ + ● ●●●●●●●●●●◤◤● +  ●●●●●●●●●●●●● diff --git a/pttbbs/sample/etc/chickens/e11 b/pttbbs/sample/etc/chickens/e11 new file mode 100644 index 00000000..1579e557 --- /dev/null +++ b/pttbbs/sample/etc/chickens/e11 @@ -0,0 +1,14 @@ + + ◢◢◢ + ◢◢◢◢◢◢ +  ●●●●●●◢◢◢  ◢ +  ●●◢◣●●●◢◢ ◎◎ +  ●●●●●●●●◢◢◎◎◎ +  ▼▼▼▼▼▼●●◢◎◎◎◎ +   ●●●◎◎ +  ● ▲▲▲▲▲▲●●●◢◢◢ +  ●●●●●●●●●●●●●◢◢ ◢ + ●●●●●●●●●●◢◢ ◢◢ + ●●●●●●●●●●●●●◣◣◣◢◢◢ + ● ●●●●●●●●●●●●◣◣◢ + diff --git a/pttbbs/sample/etc/chickens/e12 b/pttbbs/sample/etc/chickens/e12 new file mode 100644 index 00000000..0a05bc8a --- /dev/null +++ b/pttbbs/sample/etc/chickens/e12 @@ -0,0 +1,15 @@ + +  ◎ ◎  ◣◣  ◎ +  ◣◣◣◣ + ◣ ◣◣●●●●●  ◎ ◢◢ + ◎◎  ◣●●●●●● ◢◢◢◢ + ◎◎◎◣◣●●●●● ●●●●◢ + ◎◎◎◎◣●●●●●●●● ◎ ●●●◢◢  ◢ +  ◎  ◎◎◣◣●●●●●◥◥◥◥ ●●●●●●◢  ◎◎ + ◎◣◣◣●●●●● ◤◤●●●●◢◢◎◎  ◎ + ◣◣◣●●●●●● ●●●●◢◢◎ + ◣ ◣◣◣●●●●●●●◢ ◣●●●●●●◢◢ + ◣◣ ◢◢◢●●●●●●●●●● ●●●●●●●●◢◢ ◢ + ◣◣◢◢◢●●●●●●●●●● ●●●●●●●●◣◣◢◢ + + diff --git a/pttbbs/sample/etc/chickens/e13 b/pttbbs/sample/etc/chickens/e13 new file mode 100644 index 00000000..7fcee5e0 --- /dev/null +++ b/pttbbs/sample/etc/chickens/e13 @@ -0,0 +1,14 @@ + + ◢◢◢  ◢ + ◢◢◢◢◢◢  ◎◎◎ +  ●●●●●●◢◢◢ ◎◎◎◎ +   ●●╳●●●●◢◢  ◎◎◎◎◎ +   ●●●●●●●●◢◢◎◎◎◎◎ +  ▼▼▼▼▼▼●●◢◎◎◎◎◎◎ +  ●●● ●●●◎◎◎◎◎ +  ●  ●● ●●●◢◢◎◎ +  ●●● ▲▲▲▲▲▲▲●●●◢◢ + ●●●●●●●●●●●◢◢ ◢◢ + ●●●●●●●●●●●●●◣◣◣◢◢◢ + ● ●●●●●●●●●●●●◣◣◢ + diff --git a/pttbbs/sample/etc/chickens/e14 b/pttbbs/sample/etc/chickens/e14 new file mode 100644 index 00000000..5685534b --- /dev/null +++ b/pttbbs/sample/etc/chickens/e14 @@ -0,0 +1,13 @@ + + ◢◢◢ ◢ +  ◢◢◢◢◢  ◎◎ + ●●●●●●◢◢  ◎◎◎ + ●●●●●●●◢ ◎◎◎◎ + ●●●●●●◢◢  ◎◎◎◎◎ + ●●●●●●●●●◢◢ ◎◎◎◎◎ + ◤◤◤◤◤◤●●●●◢◢◎◎◎◎ + ●●●  ●●●●◢◢◎◎◎ +  ●● ● ●●  ●●●●◢◢◎◎ + ●●● ●● ● ◣◣●●●●●●●●◢◢◢ ◢ + ●● ●●● ●●●●●●●●●●●●●●●◣◣ ◢◢ + ●● ●●●●●●●●●●●◣◢◢◢ diff --git a/pttbbs/sample/etc/chickens/e15 b/pttbbs/sample/etc/chickens/e15 new file mode 100644 index 00000000..b1c406be --- /dev/null +++ b/pttbbs/sample/etc/chickens/e15 @@ -0,0 +1,13 @@ + + ◣ ◣◣◣  +  ◎◎  ◣◣◣◣◣  +  ◎◎◎◎  ◣◣●●●●●●  +  ◎◎◎◎◎  ◣●●●●●●●●  +  ◎◎◎◎◎ ◣◣●●●●●●╳●●  + ◎◎◎◎  ◣●●●●◥◥◥◥◥◥ ● +  ◎◎ ◣◣●●●●● ●●●●● + ◎◎◣◣◣●●●● ●●  +  ◣  ◎◣◣◣●●●●●◢◢◢◢◢  ●  + ◣◣ ◣◣◣●●●●●●●●●● ●  + ◣◣ ◢◢◢●●●●●●●●●●●●●● +  ◣◣◢◢◢●●●●●●●●●●  diff --git a/pttbbs/sample/etc/chickens/e16 b/pttbbs/sample/etc/chickens/e16 new file mode 100644 index 00000000..c607a360 --- /dev/null +++ b/pttbbs/sample/etc/chickens/e16 @@ -0,0 +1,14 @@ + + ◢◢◢ ◢ +  ◢◢◢◢◢ ●●◢  ◢ + ●●●●●●◢◢●︽●◢ ◎◎ + ●●●●●●●◢ ●●◢  ◎◎◎ + ●●●●●●◢◢ ●◣  ◎◎◎◎ + ●●●●●●●●●◢◢ ●◢ ◎◎◎◎ +  ◣ ◤◤◤●●●●●●●◢◢  ◎◎◎ +  ◣●● ● ●●●●●●◢◢  ◎◎◎◎ +  ◣●●● ◣ ● ●●●●●●◢◢◎◎◎ +◢◢●●●● ◣●● ● ● ◣●●●●●●●●●◢◢◢ + ◣●︽● ●●●●●●●●●●●●●●●◣◣ ◢ + ◢◢●●●● ● ●●●●●●●●●●●●◣◢◢ + diff --git a/pttbbs/sample/etc/chickens/e2 b/pttbbs/sample/etc/chickens/e2 new file mode 100644 index 00000000..d975147c --- /dev/null +++ b/pttbbs/sample/etc/chickens/e2 @@ -0,0 +1,6 @@ + + + ●●◢ + ●●●◢ + ●●●●◣◣ + diff --git a/pttbbs/sample/etc/chickens/e3 b/pttbbs/sample/etc/chickens/e3 new file mode 100644 index 00000000..244f71d2 --- /dev/null +++ b/pttbbs/sample/etc/chickens/e3 @@ -0,0 +1,6 @@ + ◢◢ + ●●●◢ + ●︽︽●◢ + ●●●●◢◢ + ●●●●●◣◣◢ + diff --git a/pttbbs/sample/etc/chickens/e4 b/pttbbs/sample/etc/chickens/e4 new file mode 100644 index 00000000..d6b05b44 --- /dev/null +++ b/pttbbs/sample/etc/chickens/e4 @@ -0,0 +1,8 @@ + + ◢◢◢ + ●●●●◢ + ●●●●●◢ + ●●▼▼●◢◢ + ●●▲●●●◢◢ ◢ + ●●●●●●●◣◣◢ + diff --git a/pttbbs/sample/etc/chickens/e5 b/pttbbs/sample/etc/chickens/e5 new file mode 100644 index 00000000..a78b2df8 --- /dev/null +++ b/pttbbs/sample/etc/chickens/e5 @@ -0,0 +1,9 @@ + + ◢◢◢ + ●●●●◢ + ●◣●◢●◢◢ + ●●●●●●◢ + ●●▼▼▼●●◢◢ + ●●▲▲●●●●◢◢ ◢ + ●●●●●●●●◣◣◢◢◢ + diff --git a/pttbbs/sample/etc/chickens/e6 b/pttbbs/sample/etc/chickens/e6 new file mode 100644 index 00000000..66af6938 --- /dev/null +++ b/pttbbs/sample/etc/chickens/e6 @@ -0,0 +1,9 @@ + +  ◢◢◢◢ + ●●●●◢◢ + ●︽●︽●●◢◢ + ●●●●●●●◢ + ●▼▼▼▼●●◢◢◢ + ●●▲▲●●●●◢ ◢ + ●●●●●●●●◣◣ ◢◢ + ●●●●●●●●●◣◢◢ diff --git a/pttbbs/sample/etc/chickens/e7 b/pttbbs/sample/etc/chickens/e7 new file mode 100644 index 00000000..fc0b8270 --- /dev/null +++ b/pttbbs/sample/etc/chickens/e7 @@ -0,0 +1,11 @@ + + ◣◣◣◣ + ◣◣●●●●●  + ◣◣●●●●●  + ◣◣●●●●●●●  + ◣◣◣●●●●●●◥◥  ◎ + ◣◣●●●●●  ◎ + ◣◣●●●●●●●●◢ + ◣ ◣◣●●●●●●●●● ◎ + ◣◣◢◢●●●●●●●●● + diff --git a/pttbbs/sample/etc/chickens/e8 b/pttbbs/sample/etc/chickens/e8 new file mode 100644 index 00000000..6841430c --- /dev/null +++ b/pttbbs/sample/etc/chickens/e8 @@ -0,0 +1,11 @@ + + ◣◣ + ◣◣◣◣ + ◣◣●●●●● + ◣●◣●●◢● + ◣◣●●●●●●● + ◣◣●▼▼▼▼▼● + ◣◣◣●●▲▲▲▲● + ◣ ◣◣●●歈●●歈 + ◣◣◢◢●●●●●●●●● + ◣◢◢●●●●●●●●● diff --git a/pttbbs/sample/etc/chickens/e9 b/pttbbs/sample/etc/chickens/e9 new file mode 100644 index 00000000..1c475487 --- /dev/null +++ b/pttbbs/sample/etc/chickens/e9 @@ -0,0 +1,12 @@ + + ◣◣ + ◣◣◣◣◣ + ◣●●●●● + ◣●●●◥◤●● + ◣◣●●▼▼▼◥◥◥  + ◣◣●●  + ◣ ◣◣●●●●▲▲▲▲▲▲  + ◣ ◣◣●●●●●●●翦 + ◣◣◣◢◢●●●●●●●●●● + ◣◣◢●●●●●●●●●●● + diff --git a/pttbbs/sample/etc/chickens/eat b/pttbbs/sample/etc/chickens/eat new file mode 100644 index 00000000..03f3a578 --- /dev/null +++ b/pttbbs/sample/etc/chickens/eat @@ -0,0 +1,14 @@ + + + + + _._ / +  ╮  ▁   ╮ ▼   ╭ +  () [≡ ###/  │ () +  ∥  ▕ ▔ ▔ ▏ ∥ + │  ▕︽︽︽︽︽︽︽︽︽︽▏   │ + ╰踛  矱    踛灨 + ∥ ≡   ∥ +  ╭┴╮ ╭┴╮   ╭┴╮ +  ▔ ▔ ▔ ▔ ▔ ▔ + 吃飯囉~~~~~~~~ diff --git a/pttbbs/sample/etc/chickens/f0 b/pttbbs/sample/etc/chickens/f0 new file mode 100644 index 00000000..36f55c21 --- /dev/null +++ b/pttbbs/sample/etc/chickens/f0 @@ -0,0 +1,9 @@ + + + ●●● + ● ●● ● + ●●●●●● + ●●●●●● + ●● ●● + ●● ●● + ●●●● diff --git a/pttbbs/sample/etc/chickens/f1 b/pttbbs/sample/etc/chickens/f1 new file mode 100644 index 00000000..36f55c21 --- /dev/null +++ b/pttbbs/sample/etc/chickens/f1 @@ -0,0 +1,9 @@ + + + ●●● + ● ●● ● + ●●●●●● + ●●●●●● + ●● ●● + ●● ●● + ●●●● diff --git a/pttbbs/sample/etc/chickens/f10 b/pttbbs/sample/etc/chickens/f10 new file mode 100644 index 00000000..b5c8367f --- /dev/null +++ b/pttbbs/sample/etc/chickens/f10 @@ -0,0 +1,15 @@ + ●● ●● + ●●●● ●●●● + ●●●●●●●●●●● + ● ● + ● ● ● ● + ● ● + ● ●●● ● + ● ● + ● ● ● ● + ●● ●●● + ● ● + ● ● + ● ●●● ● + ● ● ● + ● diff --git a/pttbbs/sample/etc/chickens/f11 b/pttbbs/sample/etc/chickens/f11 new file mode 100644 index 00000000..8646bce2 --- /dev/null +++ b/pttbbs/sample/etc/chickens/f11 @@ -0,0 +1,14 @@ + ●●●●●● + ● ● ●● + ● ● ● ●● + ●● ●●● + ● ● ●● + ●●●●●●●● ●● + ● ●● + ● ● ● ● + ● ● ● ● + ● ● ● + ● ● + ● ●●● ● + ● ● ● ● + ● ● diff --git a/pttbbs/sample/etc/chickens/f12 b/pttbbs/sample/etc/chickens/f12 new file mode 100644 index 00000000..8646bce2 --- /dev/null +++ b/pttbbs/sample/etc/chickens/f12 @@ -0,0 +1,14 @@ + ●●●●●● + ● ● ●● + ● ● ● ●● + ●● ●●● + ● ● ●● + ●●●●●●●● ●● + ● ●● + ● ● ● ● + ● ● ● ● + ● ● ● + ● ● + ● ●●● ● + ● ● ● ● + ● ● diff --git a/pttbbs/sample/etc/chickens/f13 b/pttbbs/sample/etc/chickens/f13 new file mode 100644 index 00000000..ba9d1d34 --- /dev/null +++ b/pttbbs/sample/etc/chickens/f13 @@ -0,0 +1,14 @@ + ●●●● + ●●●●●●●● + ●●●●●●●●●● + ●●●●●●●●●●●● + ● ●●●●●●●●● + ●● ● ●● + ●●●● ● + ● ● + ●● ●● + ● ●●●●●● ● + ● ● + ● ● + ● ● + ●●● ●● diff --git a/pttbbs/sample/etc/chickens/f14 b/pttbbs/sample/etc/chickens/f14 new file mode 100644 index 00000000..ba9d1d34 --- /dev/null +++ b/pttbbs/sample/etc/chickens/f14 @@ -0,0 +1,14 @@ + ●●●● + ●●●●●●●● + ●●●●●●●●●● + ●●●●●●●●●●●● + ● ●●●●●●●●● + ●● ● ●● + ●●●● ● + ● ● + ●● ●● + ● ●●●●●● ● + ● ● + ● ● + ● ● + ●●● ●● diff --git a/pttbbs/sample/etc/chickens/f15 b/pttbbs/sample/etc/chickens/f15 new file mode 100644 index 00000000..df160353 --- /dev/null +++ b/pttbbs/sample/etc/chickens/f15 @@ -0,0 +1,15 @@ + ●●●●●● + ● ● ● + ● ●● ● + ● ● ● + ●●● ● + ● ● + ● ●● ● + ● ● ● + ● ● ● ● + ● ● ● + ● ● + ● ● + ● ●● ●●● + ● ●● ● + ● ● diff --git a/pttbbs/sample/etc/chickens/f16 b/pttbbs/sample/etc/chickens/f16 new file mode 100644 index 00000000..100d4260 --- /dev/null +++ b/pttbbs/sample/etc/chickens/f16 @@ -0,0 +1,15 @@ + ●●●●●●● + ● ●●● + ● ● ● ●●● + ●●●●●●● ●● + ● ● ● + ●●●●●●● ● + ● ● ● + ●●●●●● ● + ● ● + ● ● + ● ● + ●● ● ● + ● ●●●●●● ●● + ● ● + ●●● ●● diff --git a/pttbbs/sample/etc/chickens/f2 b/pttbbs/sample/etc/chickens/f2 new file mode 100644 index 00000000..6714c9d2 --- /dev/null +++ b/pttbbs/sample/etc/chickens/f2 @@ -0,0 +1,12 @@ + + + + ●●●●●● + ● ● + ● ● ● ● + ● ● + ● ●● ● + ● ● + ● ● + ● ● + ●●●●●● diff --git a/pttbbs/sample/etc/chickens/f3 b/pttbbs/sample/etc/chickens/f3 new file mode 100644 index 00000000..6714c9d2 --- /dev/null +++ b/pttbbs/sample/etc/chickens/f3 @@ -0,0 +1,12 @@ + + + + ●●●●●● + ● ● + ● ● ● ● + ● ● + ● ●● ● + ● ● + ● ● + ● ● + ●●●●●● diff --git a/pttbbs/sample/etc/chickens/f4 b/pttbbs/sample/etc/chickens/f4 new file mode 100644 index 00000000..723291ae --- /dev/null +++ b/pttbbs/sample/etc/chickens/f4 @@ -0,0 +1,13 @@ + + + + ●●●●●● + ● ● + ● ● ● ● + ● ● + ● ●● ● + ●●● ●● ●● + ● ● + ● ●●●● ● + ● ● ● + ● diff --git a/pttbbs/sample/etc/chickens/f5 b/pttbbs/sample/etc/chickens/f5 new file mode 100644 index 00000000..723291ae --- /dev/null +++ b/pttbbs/sample/etc/chickens/f5 @@ -0,0 +1,13 @@ + + + + ●●●●●● + ● ● + ● ● ● ● + ● ● + ● ●● ● + ●●● ●● ●● + ● ● + ● ●●●● ● + ● ● ● + ● diff --git a/pttbbs/sample/etc/chickens/f6 b/pttbbs/sample/etc/chickens/f6 new file mode 100644 index 00000000..d3edcf12 --- /dev/null +++ b/pttbbs/sample/etc/chickens/f6 @@ -0,0 +1,14 @@ + + + + ●●●●●● + ● ● ● + ● ●● ● + ● ● ● + ●●● ● + ● ● + ● ●● ● + ● ● ● + ● ● + ● ● + ●●●●●● diff --git a/pttbbs/sample/etc/chickens/f7 b/pttbbs/sample/etc/chickens/f7 new file mode 100644 index 00000000..d3edcf12 --- /dev/null +++ b/pttbbs/sample/etc/chickens/f7 @@ -0,0 +1,14 @@ + + + + ●●●●●● + ● ● ● + ● ●● ● + ● ● ● + ●●● ● + ● ● + ● ●● ● + ● ● ● + ● ● + ● ● + ●●●●●● diff --git a/pttbbs/sample/etc/chickens/f8 b/pttbbs/sample/etc/chickens/f8 new file mode 100644 index 00000000..b5c8367f --- /dev/null +++ b/pttbbs/sample/etc/chickens/f8 @@ -0,0 +1,15 @@ + ●● ●● + ●●●● ●●●● + ●●●●●●●●●●● + ● ● + ● ● ● ● + ● ● + ● ●●● ● + ● ● + ● ● ● ● + ●● ●●● + ● ● + ● ● + ● ●●● ● + ● ● ● + ● diff --git a/pttbbs/sample/etc/chickens/f9 b/pttbbs/sample/etc/chickens/f9 new file mode 100644 index 00000000..b5c8367f --- /dev/null +++ b/pttbbs/sample/etc/chickens/f9 @@ -0,0 +1,15 @@ + ●● ●● + ●●●● ●●●● + ●●●●●●●●●●● + ● ● + ● ● ● ● + ● ● + ● ●●● ● + ● ● + ● ● ● ● + ●● ●●● + ● ● + ● ● + ● ●●● ● + ● ● ● + ● diff --git a/pttbbs/sample/etc/chickens/food b/pttbbs/sample/etc/chickens/food new file mode 100644 index 00000000..bb686d2f --- /dev/null +++ b/pttbbs/sample/etc/chickens/food @@ -0,0 +1,14 @@ + +   +   ▄▄▄   +   ◤◤   +   ELEVEN   +   █   + █▃▃▃▃█ + ////// +      +  ((((((  ●●- > Marshakt +  ▄▄▄ˍ ╰▼ ╯  妙天小廚師  + \-. >> + :  + 來買食物啦.... diff --git a/pttbbs/sample/etc/chickens/g0 b/pttbbs/sample/etc/chickens/g0 new file mode 100644 index 00000000..1ed07519 --- /dev/null +++ b/pttbbs/sample/etc/chickens/g0 @@ -0,0 +1,5 @@ + + ●● + ●●● + ●●╯ + diff --git a/pttbbs/sample/etc/chickens/g1 b/pttbbs/sample/etc/chickens/g1 new file mode 100644 index 00000000..1ed07519 --- /dev/null +++ b/pttbbs/sample/etc/chickens/g1 @@ -0,0 +1,5 @@ + + ●● + ●●● + ●●╯ + diff --git a/pttbbs/sample/etc/chickens/g10 b/pttbbs/sample/etc/chickens/g10 new file mode 100644 index 00000000..cf4c0f14 --- /dev/null +++ b/pttbbs/sample/etc/chickens/g10 @@ -0,0 +1,13 @@ + + ◣ ◢  ◣ ◢  ◣ ◢ + ●●●●●  ●●●●●  ●●●●● + ☉*♁☆ ● ●  ● ●  ● ● + ☆*☉** ● ╳ ╳ ●  ● ︽ ︽ ●  ● 〥 〥 ● + *♁*☉*  ● ●  ● ●  ● ● + *♁*☆   ● ●  ● ●  ● ● + 稙  ● ●  ● ● ● ● +  ● ●  ● ●  ● ● +  ● ●  ● ● ● ● +  嘵 ●●●●●●  ●●●●●  ●●●● + + diff --git a/pttbbs/sample/etc/chickens/g11 b/pttbbs/sample/etc/chickens/g11 new file mode 100644 index 00000000..0c6390f8 --- /dev/null +++ b/pttbbs/sample/etc/chickens/g11 @@ -0,0 +1,15 @@ + +  ◣ ◢ + ●●●●●● + ● ●  +  ●  ﹏ ﹏ ● + ● ═ ● ═ ● + ● ﹌  ● + ● ● + ● ● + ● ● + ● ● + ● ● +  ●●●●●●●  + + diff --git a/pttbbs/sample/etc/chickens/g12 b/pttbbs/sample/etc/chickens/g12 new file mode 100644 index 00000000..326c650d --- /dev/null +++ b/pttbbs/sample/etc/chickens/g12 @@ -0,0 +1,15 @@ + +  ◣ ◢  ●●●●●●● + ●●●●●●●●●●●●●● + ● ●  ●●●●●●● + ● 〥 〥 ●  ●●●●●● + ● ═ ● ═ ●  ● ●●●● + ●  ∼  ● ● +  ● ●  ● +  ● ●  ● + ●●●●●●●●  + ●●●●●●●● +  ●  ╳  ● + ●●●●●●● + + diff --git a/pttbbs/sample/etc/chickens/g13 b/pttbbs/sample/etc/chickens/g13 new file mode 100644 index 00000000..0b6e8b53 --- /dev/null +++ b/pttbbs/sample/etc/chickens/g13 @@ -0,0 +1,14 @@ + ● ● + ●●●●●●   ◣ ◣ +  ● ●  ●●●●● + ●  ︽ ︽ ● ● ● +  ● >●< ●  ● ︽ ︽ ● +  ● ●  ●>●<● +  ●●■●●  ●●●● +  ●  ■  ●  ● ● +   ●  ■ ●  ● ●  +  ●  ▼  ●  ● ● +  ● ●  ● ● +  ●●●●●●●  ●●●●●● + + diff --git a/pttbbs/sample/etc/chickens/g14 b/pttbbs/sample/etc/chickens/g14 new file mode 100644 index 00000000..12c177ea --- /dev/null +++ b/pttbbs/sample/etc/chickens/g14 @@ -0,0 +1,14 @@ + + ● ● + ●●●●●●  ◣ ◢ + ● ●  ●●●●● + ● ● ● ● ● ● + ● > ● < ● ●●● 〥 〥 ● + ● ∼  ● ●● ●═◆═● + ◣ ◢  ═●●═  ●●  ●●● +  ●●●●  ● ● ●● ● ● + ● ●  ● ●●●● ● ◣◢ + ● ☉☉ ●  ● ●●● ●●◤◥ + ● ●  ● ●●● ● ☉☉● + ●●●●●  ●●●●●●●●  ●●●●●●●●●● + diff --git a/pttbbs/sample/etc/chickens/g15 b/pttbbs/sample/etc/chickens/g15 new file mode 100644 index 00000000..05757960 --- /dev/null +++ b/pttbbs/sample/etc/chickens/g15 @@ -0,0 +1,14 @@ + + + ● ● + ●●●●●●● +  ● ●●●●●  雙下巴都跑出來了呢! + ● # #  ● + ● ═●═  ● + ● ︵  ● + ● ● + ●  ︾  ● + ● ●● +  ●●●●●●●●●●●●● ●●●●●●● + + diff --git a/pttbbs/sample/etc/chickens/g16 b/pttbbs/sample/etc/chickens/g16 new file mode 100644 index 00000000..03e4ebaa --- /dev/null +++ b/pttbbs/sample/etc/chickens/g16 @@ -0,0 +1,14 @@ + + ●● + ╮ ● ● ●● + ●●● ╰╮● ●  ● ● + ●●●● ● ╰╮  ●● ●●● ● + ●●  (  ∥ ◤ ╰──╮ ● ● ● + ●  ●  ●●  ╰╮ ● ●  ● + ●●●  (  ∥ ◣ ● ● ╰╮● ●  ●  ●●●● + ●●  ● ●  ╰╮ ●  ●  ●●●●● + ●  │  ●  ●  ●●●●●● + ●  ╰╮● ●●  ●●●●● + ●●●●●●●●●●●● ╰─────────●●●● + + diff --git a/pttbbs/sample/etc/chickens/g2 b/pttbbs/sample/etc/chickens/g2 new file mode 100644 index 00000000..032a3e61 --- /dev/null +++ b/pttbbs/sample/etc/chickens/g2 @@ -0,0 +1,5 @@ + + ●●● + ●OO● + ●●● + diff --git a/pttbbs/sample/etc/chickens/g3 b/pttbbs/sample/etc/chickens/g3 new file mode 100644 index 00000000..5e65b34d --- /dev/null +++ b/pttbbs/sample/etc/chickens/g3 @@ -0,0 +1,6 @@ + + ◣ ◢ + ●●● + ●OO● + ●●●● + diff --git a/pttbbs/sample/etc/chickens/g4 b/pttbbs/sample/etc/chickens/g4 new file mode 100644 index 00000000..5e8a7520 --- /dev/null +++ b/pttbbs/sample/etc/chickens/g4 @@ -0,0 +1,6 @@ + + ◣ ◢ + ●●●● + ●Ο Ο● + ●≡◆≡● + ●●●●  diff --git a/pttbbs/sample/etc/chickens/g5 b/pttbbs/sample/etc/chickens/g5 new file mode 100644 index 00000000..7bd2bea7 --- /dev/null +++ b/pttbbs/sample/etc/chickens/g5 @@ -0,0 +1,8 @@ + + ◣ ◢ + ●●●●●  + ● Ω Ω ● + ● ≧◆≦ ● + ●●●●●  + ● ● + diff --git a/pttbbs/sample/etc/chickens/g6 b/pttbbs/sample/etc/chickens/g6 new file mode 100644 index 00000000..87477217 --- /dev/null +++ b/pttbbs/sample/etc/chickens/g6 @@ -0,0 +1,10 @@ + + ◣ ◢ + ●●●●●●  + ● 〥 〥 ●  矙 + ● > ● < ●  + ●  ﹀ ●  + ●●●●●●●● + ●●●●●●● + + diff --git a/pttbbs/sample/etc/chickens/g7 b/pttbbs/sample/etc/chickens/g7 new file mode 100644 index 00000000..08e1a435 --- /dev/null +++ b/pttbbs/sample/etc/chickens/g7 @@ -0,0 +1,11 @@ + + ● ● + ●●●●●● + ● ●●● + ● 〥 〥  ●  ● + ● >●<  ●  ●● ● + ●  ∪  ● ● ●● + ● ● ● + ●●●●●●●●● + ●● ●●●●● + diff --git a/pttbbs/sample/etc/chickens/g8 b/pttbbs/sample/etc/chickens/g8 new file mode 100644 index 00000000..3de22b49 --- /dev/null +++ b/pttbbs/sample/etc/chickens/g8 @@ -0,0 +1,14 @@ + + ● + ● + ◣ ◣ ●●● ● + ●●●●●●● ● ● + ● ●● + ● ◣ ◢ ●● + ● >●<  ●● + ● ◤ ◥ ●● + ● ◣ ◢ ●●◤◤ + ●●●●●●●◤◤ + ◤◤ ◤◤ + + diff --git a/pttbbs/sample/etc/chickens/g9 b/pttbbs/sample/etc/chickens/g9 new file mode 100644 index 00000000..c0274032 --- /dev/null +++ b/pttbbs/sample/etc/chickens/g9 @@ -0,0 +1,14 @@ + ◢ ◢ + ●●●● ● + ● ●  ● + ● ●  ● ● + ●═  ● ● + ●●● ●  ● + ●● ●● ● ● ● + ● ◢ ●  ● ●● + ● ◢■◢ ● ● ● + ● ◥■◥ ●  ● ● + ● ◥ ●  ●  ● + ●●●●●●●● ●●● + + diff --git a/pttbbs/sample/etc/chickens/h0 b/pttbbs/sample/etc/chickens/h0 new file mode 100644 index 00000000..36f55c21 --- /dev/null +++ b/pttbbs/sample/etc/chickens/h0 @@ -0,0 +1,9 @@ + + + ●●● + ● ●● ● + ●●●●●● + ●●●●●● + ●● ●● + ●● ●● + ●●●● diff --git a/pttbbs/sample/etc/chickens/h1 b/pttbbs/sample/etc/chickens/h1 new file mode 100644 index 00000000..36f55c21 --- /dev/null +++ b/pttbbs/sample/etc/chickens/h1 @@ -0,0 +1,9 @@ + + + ●●● + ● ●● ● + ●●●●●● + ●●●●●● + ●● ●● + ●● ●● + ●●●● diff --git a/pttbbs/sample/etc/chickens/h10 b/pttbbs/sample/etc/chickens/h10 new file mode 100644 index 00000000..b5c8367f --- /dev/null +++ b/pttbbs/sample/etc/chickens/h10 @@ -0,0 +1,15 @@ + ●● ●● + ●●●● ●●●● + ●●●●●●●●●●● + ● ● + ● ● ● ● + ● ● + ● ●●● ● + ● ● + ● ● ● ● + ●● ●●● + ● ● + ● ● + ● ●●● ● + ● ● ● + ● diff --git a/pttbbs/sample/etc/chickens/h11 b/pttbbs/sample/etc/chickens/h11 new file mode 100644 index 00000000..8646bce2 --- /dev/null +++ b/pttbbs/sample/etc/chickens/h11 @@ -0,0 +1,14 @@ + ●●●●●● + ● ● ●● + ● ● ● ●● + ●● ●●● + ● ● ●● + ●●●●●●●● ●● + ● ●● + ● ● ● ● + ● ● ● ● + ● ● ● + ● ● + ● ●●● ● + ● ● ● ● + ● ● diff --git a/pttbbs/sample/etc/chickens/h12 b/pttbbs/sample/etc/chickens/h12 new file mode 100644 index 00000000..8646bce2 --- /dev/null +++ b/pttbbs/sample/etc/chickens/h12 @@ -0,0 +1,14 @@ + ●●●●●● + ● ● ●● + ● ● ● ●● + ●● ●●● + ● ● ●● + ●●●●●●●● ●● + ● ●● + ● ● ● ● + ● ● ● ● + ● ● ● + ● ● + ● ●●● ● + ● ● ● ● + ● ● diff --git a/pttbbs/sample/etc/chickens/h13 b/pttbbs/sample/etc/chickens/h13 new file mode 100644 index 00000000..ba9d1d34 --- /dev/null +++ b/pttbbs/sample/etc/chickens/h13 @@ -0,0 +1,14 @@ + ●●●● + ●●●●●●●● + ●●●●●●●●●● + ●●●●●●●●●●●● + ● ●●●●●●●●● + ●● ● ●● + ●●●● ● + ● ● + ●● ●● + ● ●●●●●● ● + ● ● + ● ● + ● ● + ●●● ●● diff --git a/pttbbs/sample/etc/chickens/h14 b/pttbbs/sample/etc/chickens/h14 new file mode 100644 index 00000000..ba9d1d34 --- /dev/null +++ b/pttbbs/sample/etc/chickens/h14 @@ -0,0 +1,14 @@ + ●●●● + ●●●●●●●● + ●●●●●●●●●● + ●●●●●●●●●●●● + ● ●●●●●●●●● + ●● ● ●● + ●●●● ● + ● ● + ●● ●● + ● ●●●●●● ● + ● ● + ● ● + ● ● + ●●● ●● diff --git a/pttbbs/sample/etc/chickens/h15 b/pttbbs/sample/etc/chickens/h15 new file mode 100644 index 00000000..df160353 --- /dev/null +++ b/pttbbs/sample/etc/chickens/h15 @@ -0,0 +1,15 @@ + ●●●●●● + ● ● ● + ● ●● ● + ● ● ● + ●●● ● + ● ● + ● ●● ● + ● ● ● + ● ● ● ● + ● ● ● + ● ● + ● ● + ● ●● ●●● + ● ●● ● + ● ● diff --git a/pttbbs/sample/etc/chickens/h16 b/pttbbs/sample/etc/chickens/h16 new file mode 100644 index 00000000..100d4260 --- /dev/null +++ b/pttbbs/sample/etc/chickens/h16 @@ -0,0 +1,15 @@ + ●●●●●●● + ● ●●● + ● ● ● ●●● + ●●●●●●● ●● + ● ● ● + ●●●●●●● ● + ● ● ● + ●●●●●● ● + ● ● + ● ● + ● ● + ●● ● ● + ● ●●●●●● ●● + ● ● + ●●● ●● diff --git a/pttbbs/sample/etc/chickens/h2 b/pttbbs/sample/etc/chickens/h2 new file mode 100644 index 00000000..6714c9d2 --- /dev/null +++ b/pttbbs/sample/etc/chickens/h2 @@ -0,0 +1,12 @@ + + + + ●●●●●● + ● ● + ● ● ● ● + ● ● + ● ●● ● + ● ● + ● ● + ● ● + ●●●●●● diff --git a/pttbbs/sample/etc/chickens/h3 b/pttbbs/sample/etc/chickens/h3 new file mode 100644 index 00000000..6714c9d2 --- /dev/null +++ b/pttbbs/sample/etc/chickens/h3 @@ -0,0 +1,12 @@ + + + + ●●●●●● + ● ● + ● ● ● ● + ● ● + ● ●● ● + ● ● + ● ● + ● ● + ●●●●●● diff --git a/pttbbs/sample/etc/chickens/h4 b/pttbbs/sample/etc/chickens/h4 new file mode 100644 index 00000000..723291ae --- /dev/null +++ b/pttbbs/sample/etc/chickens/h4 @@ -0,0 +1,13 @@ + + + + ●●●●●● + ● ● + ● ● ● ● + ● ● + ● ●● ● + ●●● ●● ●● + ● ● + ● ●●●● ● + ● ● ● + ● diff --git a/pttbbs/sample/etc/chickens/h5 b/pttbbs/sample/etc/chickens/h5 new file mode 100644 index 00000000..723291ae --- /dev/null +++ b/pttbbs/sample/etc/chickens/h5 @@ -0,0 +1,13 @@ + + + + ●●●●●● + ● ● + ● ● ● ● + ● ● + ● ●● ● + ●●● ●● ●● + ● ● + ● ●●●● ● + ● ● ● + ● diff --git a/pttbbs/sample/etc/chickens/h6 b/pttbbs/sample/etc/chickens/h6 new file mode 100644 index 00000000..d3edcf12 --- /dev/null +++ b/pttbbs/sample/etc/chickens/h6 @@ -0,0 +1,14 @@ + + + + ●●●●●● + ● ● ● + ● ●● ● + ● ● ● + ●●● ● + ● ● + ● ●● ● + ● ● ● + ● ● + ● ● + ●●●●●● diff --git a/pttbbs/sample/etc/chickens/h7 b/pttbbs/sample/etc/chickens/h7 new file mode 100644 index 00000000..d3edcf12 --- /dev/null +++ b/pttbbs/sample/etc/chickens/h7 @@ -0,0 +1,14 @@ + + + + ●●●●●● + ● ● ● + ● ●● ● + ● ● ● + ●●● ● + ● ● + ● ●● ● + ● ● ● + ● ● + ● ● + ●●●●●● diff --git a/pttbbs/sample/etc/chickens/h8 b/pttbbs/sample/etc/chickens/h8 new file mode 100644 index 00000000..b5c8367f --- /dev/null +++ b/pttbbs/sample/etc/chickens/h8 @@ -0,0 +1,15 @@ + ●● ●● + ●●●● ●●●● + ●●●●●●●●●●● + ● ● + ● ● ● ● + ● ● + ● ●●● ● + ● ● + ● ● ● ● + ●● ●●● + ● ● + ● ● + ● ●●● ● + ● ● ● + ● diff --git a/pttbbs/sample/etc/chickens/h9 b/pttbbs/sample/etc/chickens/h9 new file mode 100644 index 00000000..b5c8367f --- /dev/null +++ b/pttbbs/sample/etc/chickens/h9 @@ -0,0 +1,15 @@ + ●● ●● + ●●●● ●●●● + ●●●●●●●●●●● + ● ● + ● ● ● ● + ● ● + ● ●●● ● + ● ● + ● ● ● ● + ●● ●●● + ● ● + ● ● + ● ●●● ● + ● ● ● + ● diff --git a/pttbbs/sample/etc/chickens/hit b/pttbbs/sample/etc/chickens/hit new file mode 100644 index 00000000..2fe4b736 --- /dev/null +++ b/pttbbs/sample/etc/chickens/hit @@ -0,0 +1,14 @@ + + + + + + ◤ "  ><  +  d▃  █  ﹌  +  ███ █ █ ff █ +  `` ▊ ●." █ █ ▊ █ +  ◢▇◥◣  ◢ ▇◣ + .o  .o o, o, + + + 嘿 打架練身體.. diff --git a/pttbbs/sample/etc/chickens/i0 b/pttbbs/sample/etc/chickens/i0 new file mode 100644 index 00000000..36f55c21 --- /dev/null +++ b/pttbbs/sample/etc/chickens/i0 @@ -0,0 +1,9 @@ + + + ●●● + ● ●● ● + ●●●●●● + ●●●●●● + ●● ●● + ●● ●● + ●●●● diff --git a/pttbbs/sample/etc/chickens/i1 b/pttbbs/sample/etc/chickens/i1 new file mode 100644 index 00000000..36f55c21 --- /dev/null +++ b/pttbbs/sample/etc/chickens/i1 @@ -0,0 +1,9 @@ + + + ●●● + ● ●● ● + ●●●●●● + ●●●●●● + ●● ●● + ●● ●● + ●●●● diff --git a/pttbbs/sample/etc/chickens/i10 b/pttbbs/sample/etc/chickens/i10 new file mode 100644 index 00000000..b5c8367f --- /dev/null +++ b/pttbbs/sample/etc/chickens/i10 @@ -0,0 +1,15 @@ + ●● ●● + ●●●● ●●●● + ●●●●●●●●●●● + ● ● + ● ● ● ● + ● ● + ● ●●● ● + ● ● + ● ● ● ● + ●● ●●● + ● ● + ● ● + ● ●●● ● + ● ● ● + ● diff --git a/pttbbs/sample/etc/chickens/i11 b/pttbbs/sample/etc/chickens/i11 new file mode 100644 index 00000000..8646bce2 --- /dev/null +++ b/pttbbs/sample/etc/chickens/i11 @@ -0,0 +1,14 @@ + ●●●●●● + ● ● ●● + ● ● ● ●● + ●● ●●● + ● ● ●● + ●●●●●●●● ●● + ● ●● + ● ● ● ● + ● ● ● ● + ● ● ● + ● ● + ● ●●● ● + ● ● ● ● + ● ● diff --git a/pttbbs/sample/etc/chickens/i12 b/pttbbs/sample/etc/chickens/i12 new file mode 100644 index 00000000..8646bce2 --- /dev/null +++ b/pttbbs/sample/etc/chickens/i12 @@ -0,0 +1,14 @@ + ●●●●●● + ● ● ●● + ● ● ● ●● + ●● ●●● + ● ● ●● + ●●●●●●●● ●● + ● ●● + ● ● ● ● + ● ● ● ● + ● ● ● + ● ● + ● ●●● ● + ● ● ● ● + ● ● diff --git a/pttbbs/sample/etc/chickens/i13 b/pttbbs/sample/etc/chickens/i13 new file mode 100644 index 00000000..ba9d1d34 --- /dev/null +++ b/pttbbs/sample/etc/chickens/i13 @@ -0,0 +1,14 @@ + ●●●● + ●●●●●●●● + ●●●●●●●●●● + ●●●●●●●●●●●● + ● ●●●●●●●●● + ●● ● ●● + ●●●● ● + ● ● + ●● ●● + ● ●●●●●● ● + ● ● + ● ● + ● ● + ●●● ●● diff --git a/pttbbs/sample/etc/chickens/i14 b/pttbbs/sample/etc/chickens/i14 new file mode 100644 index 00000000..ba9d1d34 --- /dev/null +++ b/pttbbs/sample/etc/chickens/i14 @@ -0,0 +1,14 @@ + ●●●● + ●●●●●●●● + ●●●●●●●●●● + ●●●●●●●●●●●● + ● ●●●●●●●●● + ●● ● ●● + ●●●● ● + ● ● + ●● ●● + ● ●●●●●● ● + ● ● + ● ● + ● ● + ●●● ●● diff --git a/pttbbs/sample/etc/chickens/i15 b/pttbbs/sample/etc/chickens/i15 new file mode 100644 index 00000000..df160353 --- /dev/null +++ b/pttbbs/sample/etc/chickens/i15 @@ -0,0 +1,15 @@ + ●●●●●● + ● ● ● + ● ●● ● + ● ● ● + ●●● ● + ● ● + ● ●● ● + ● ● ● + ● ● ● ● + ● ● ● + ● ● + ● ● + ● ●● ●●● + ● ●● ● + ● ● diff --git a/pttbbs/sample/etc/chickens/i16 b/pttbbs/sample/etc/chickens/i16 new file mode 100644 index 00000000..100d4260 --- /dev/null +++ b/pttbbs/sample/etc/chickens/i16 @@ -0,0 +1,15 @@ + ●●●●●●● + ● ●●● + ● ● ● ●●● + ●●●●●●● ●● + ● ● ● + ●●●●●●● ● + ● ● ● + ●●●●●● ● + ● ● + ● ● + ● ● + ●● ● ● + ● ●●●●●● ●● + ● ● + ●●● ●● diff --git a/pttbbs/sample/etc/chickens/i2 b/pttbbs/sample/etc/chickens/i2 new file mode 100644 index 00000000..6714c9d2 --- /dev/null +++ b/pttbbs/sample/etc/chickens/i2 @@ -0,0 +1,12 @@ + + + + ●●●●●● + ● ● + ● ● ● ● + ● ● + ● ●● ● + ● ● + ● ● + ● ● + ●●●●●● diff --git a/pttbbs/sample/etc/chickens/i3 b/pttbbs/sample/etc/chickens/i3 new file mode 100644 index 00000000..6714c9d2 --- /dev/null +++ b/pttbbs/sample/etc/chickens/i3 @@ -0,0 +1,12 @@ + + + + ●●●●●● + ● ● + ● ● ● ● + ● ● + ● ●● ● + ● ● + ● ● + ● ● + ●●●●●● diff --git a/pttbbs/sample/etc/chickens/i4 b/pttbbs/sample/etc/chickens/i4 new file mode 100644 index 00000000..723291ae --- /dev/null +++ b/pttbbs/sample/etc/chickens/i4 @@ -0,0 +1,13 @@ + + + + ●●●●●● + ● ● + ● ● ● ● + ● ● + ● ●● ● + ●●● ●● ●● + ● ● + ● ●●●● ● + ● ● ● + ● diff --git a/pttbbs/sample/etc/chickens/i5 b/pttbbs/sample/etc/chickens/i5 new file mode 100644 index 00000000..723291ae --- /dev/null +++ b/pttbbs/sample/etc/chickens/i5 @@ -0,0 +1,13 @@ + + + + ●●●●●● + ● ● + ● ● ● ● + ● ● + ● ●● ● + ●●● ●● ●● + ● ● + ● ●●●● ● + ● ● ● + ● diff --git a/pttbbs/sample/etc/chickens/i6 b/pttbbs/sample/etc/chickens/i6 new file mode 100644 index 00000000..d3edcf12 --- /dev/null +++ b/pttbbs/sample/etc/chickens/i6 @@ -0,0 +1,14 @@ + + + + ●●●●●● + ● ● ● + ● ●● ● + ● ● ● + ●●● ● + ● ● + ● ●● ● + ● ● ● + ● ● + ● ● + ●●●●●● diff --git a/pttbbs/sample/etc/chickens/i7 b/pttbbs/sample/etc/chickens/i7 new file mode 100644 index 00000000..d3edcf12 --- /dev/null +++ b/pttbbs/sample/etc/chickens/i7 @@ -0,0 +1,14 @@ + + + + ●●●●●● + ● ● ● + ● ●● ● + ● ● ● + ●●● ● + ● ● + ● ●● ● + ● ● ● + ● ● + ● ● + ●●●●●● diff --git a/pttbbs/sample/etc/chickens/i8 b/pttbbs/sample/etc/chickens/i8 new file mode 100644 index 00000000..b5c8367f --- /dev/null +++ b/pttbbs/sample/etc/chickens/i8 @@ -0,0 +1,15 @@ + ●● ●● + ●●●● ●●●● + ●●●●●●●●●●● + ● ● + ● ● ● ● + ● ● + ● ●●● ● + ● ● + ● ● ● ● + ●● ●●● + ● ● + ● ● + ● ●●● ● + ● ● ● + ● diff --git a/pttbbs/sample/etc/chickens/i9 b/pttbbs/sample/etc/chickens/i9 new file mode 100644 index 00000000..b5c8367f --- /dev/null +++ b/pttbbs/sample/etc/chickens/i9 @@ -0,0 +1,15 @@ + ●● ●● + ●●●● ●●●● + ●●●●●●●●●●● + ● ● + ● ● ● ● + ● ● + ● ●●● ● + ● ● + ● ● ● ● + ●● ●●● + ● ● + ● ● + ● ●●● ● + ● ● ● + ● diff --git a/pttbbs/sample/etc/chickens/j0 b/pttbbs/sample/etc/chickens/j0 new file mode 100644 index 00000000..0aeb9433 --- /dev/null +++ b/pttbbs/sample/etc/chickens/j0 @@ -0,0 +1,8 @@ + + + + ●● + ●●● ▲ + ●● ●●● + + 有尾巴的惡魔卵 diff --git a/pttbbs/sample/etc/chickens/j1 b/pttbbs/sample/etc/chickens/j1 new file mode 100644 index 00000000..2f5324a9 --- /dev/null +++ b/pttbbs/sample/etc/chickens/j1 @@ -0,0 +1,9 @@ + + + + ▲ + ▼●●● + ▲ ●●●● + ●● ●●● + ●●● + diff --git a/pttbbs/sample/etc/chickens/j10 b/pttbbs/sample/etc/chickens/j10 new file mode 100644 index 00000000..ca0238c3 --- /dev/null +++ b/pttbbs/sample/etc/chickens/j10 @@ -0,0 +1,12 @@ + ▲ + ●● + ●●●●●●▼ + ●●◢●●●● + ●●●●●●●● ▲ + ▼ ●●●●● ●● + ●●●● ●●● + ▲ ●●●● ● + ●●●●●●●● ● + ●●●●●● ●●● + ● ● + ●●● ●●● diff --git a/pttbbs/sample/etc/chickens/j11 b/pttbbs/sample/etc/chickens/j11 new file mode 100644 index 00000000..67acda5c --- /dev/null +++ b/pttbbs/sample/etc/chickens/j11 @@ -0,0 +1,12 @@ + + 我有手了!嚇死你! + ▲ ▲ + ● ●● ●● ● + ● ●●●●●●● ● + ● ●●●●●●●● ● ▲ + ●●◣●●●◢●● ●● + ●●●●●●●● ●●● + ●▼▼▼▼▼● ● ● + ● ●●●●●● ●●● + ● ● + ●●● ●●● diff --git a/pttbbs/sample/etc/chickens/j12 b/pttbbs/sample/etc/chickens/j12 new file mode 100644 index 00000000..f5368760 --- /dev/null +++ b/pttbbs/sample/etc/chickens/j12 @@ -0,0 +1,11 @@ + + ▲ ▲ + ● ●● ●● ● + ● ●●●●●●● ● + ● ●●●●●●●● ● ▲ + ●●◣●●●◢●● ●● + ●●●●●●●● ●●● + ●▼▼▼▼▼● ● ● + ● ●●●●●● ●●● + ● ● + ●●● ●●● diff --git a/pttbbs/sample/etc/chickens/j13 b/pttbbs/sample/etc/chickens/j13 new file mode 100644 index 00000000..22721b27 --- /dev/null +++ b/pttbbs/sample/etc/chickens/j13 @@ -0,0 +1,12 @@ + ● ● ▲ ▲ + ●● ●● ●● + ● ●●●●●●●●● + ● ●●●●●●●●●● + ● ●●◣●●●●●◢●● + ● ●●●●●●●●●●●● + ● ●●▼▼▼▼▼▼▼▼▼●● + ●●●● ● ● ● +▲●● ● ●▲▲▲▲▲▲▲▲▲● ● + ●●● ●●●●●●●●●● ●● + ●● ●● ● ● + ●●●● ●●●● diff --git a/pttbbs/sample/etc/chickens/j14 b/pttbbs/sample/etc/chickens/j14 new file mode 100644 index 00000000..774d0ce2 --- /dev/null +++ b/pttbbs/sample/etc/chickens/j14 @@ -0,0 +1,13 @@ + + ▲ ▲ + ●●● ●● ●● ●●● + ●● ● ●●●●●●●●● ● ●● + ▼▼ ●●●●●●●●●● ▼▼ + ●●◣●●●●●◢●● + ●●●● ●●●●●●●●●●●● ●●●● + ● ●●▼▼▼▼▼▼▼▼▼●● + ●●●● ● ● + ▲●● ● ●▲▲▲▲▲▲▲▲▲● + ●●● ●●●●●●●●●● + ●● ●● + ●●●● ●●●● diff --git a/pttbbs/sample/etc/chickens/j15 b/pttbbs/sample/etc/chickens/j15 new file mode 100644 index 00000000..774d0ce2 --- /dev/null +++ b/pttbbs/sample/etc/chickens/j15 @@ -0,0 +1,13 @@ + + ▲ ▲ + ●●● ●● ●● ●●● + ●● ● ●●●●●●●●● ● ●● + ▼▼ ●●●●●●●●●● ▼▼ + ●●◣●●●●●◢●● + ●●●● ●●●●●●●●●●●● ●●●● + ● ●●▼▼▼▼▼▼▼▼▼●● + ●●●● ● ● + ▲●● ● ●▲▲▲▲▲▲▲▲▲● + ●●● ●●●●●●●●●● + ●● ●● + ●●●● ●●●● diff --git a/pttbbs/sample/etc/chickens/j16 b/pttbbs/sample/etc/chickens/j16 new file mode 100644 index 00000000..788ee97b --- /dev/null +++ b/pttbbs/sample/etc/chickens/j16 @@ -0,0 +1,13 @@ + 吼!!!我是大魔王!!! + ▲ ▲ + ●●●● ●● ●● ●●●● + ●●● ● ●●●●●●●●●●●●●● ● ●●● + ●●● ● ●●●●●●●●●●●●●●● ● ●●● + ▼▼▼ ●●◣●●●●●●●●●●◢●● ▼▼▼ + ●●●●●●●●●●●●●●●●● + ●●▼▼▼▼▼▼▼▼▼▼▼▼▼▼●● ●● + ● ● ● ● ●●● + ● ● ●▲▲▲▲▲▲▲▲▲▲▲▲▲▲● ●● + ●●●● ●●●●●●●●●●●●●●● ●● ●●▼ + ●● ●● ●●●●●●●● + ●●●●● ●●●●● ● diff --git a/pttbbs/sample/etc/chickens/j2 b/pttbbs/sample/etc/chickens/j2 new file mode 100644 index 00000000..03ef58fc --- /dev/null +++ b/pttbbs/sample/etc/chickens/j2 @@ -0,0 +1,7 @@ + + + ▲ ▲ + ●●●● + ●●●●● + ● ●●●● + ▲●●● diff --git a/pttbbs/sample/etc/chickens/j3 b/pttbbs/sample/etc/chickens/j3 new file mode 100644 index 00000000..593a726b --- /dev/null +++ b/pttbbs/sample/etc/chickens/j3 @@ -0,0 +1,10 @@ + + ▲▲ + ●●● + ●●●● ▲ + ●◢●◣● ●● + ●●●●● ●●● + ●●●●● ● + ●●●● ● ● + ●● + diff --git a/pttbbs/sample/etc/chickens/j4 b/pttbbs/sample/etc/chickens/j4 new file mode 100644 index 00000000..e2e31934 --- /dev/null +++ b/pttbbs/sample/etc/chickens/j4 @@ -0,0 +1,9 @@ + + + ▲ ▲ + ●●●●● ▲ + ●●●●●● ●● + ●●●●●●● ●●● + ●●●●●● ● + ●●●●● ● + ●●●● diff --git a/pttbbs/sample/etc/chickens/j5 b/pttbbs/sample/etc/chickens/j5 new file mode 100644 index 00000000..2554d000 --- /dev/null +++ b/pttbbs/sample/etc/chickens/j5 @@ -0,0 +1,12 @@ + ▲ ▲ + ●●●●● + ●●●●●● + ●●︽●︽●● + ●●●●●● + ●●●●● + ● + ● + ● + ●●● + ●● + ▼ diff --git a/pttbbs/sample/etc/chickens/j6 b/pttbbs/sample/etc/chickens/j6 new file mode 100644 index 00000000..79484d50 --- /dev/null +++ b/pttbbs/sample/etc/chickens/j6 @@ -0,0 +1,9 @@ + + + ▲ ▲ + ▲ ●●●●● + ●● ●●●●●● + ●●● ●●◣●◢●● + ● ●●●●●● + ● ●●●●● + ●●●● diff --git a/pttbbs/sample/etc/chickens/j7 b/pttbbs/sample/etc/chickens/j7 new file mode 100644 index 00000000..93ffcac6 --- /dev/null +++ b/pttbbs/sample/etc/chickens/j7 @@ -0,0 +1,10 @@ + + + ▲ ▲ ▲ + ●●●●● ●● + ●●●●●● ●●● + ●●◣●◢●● ● + ●●●●●● ● + ●●●●● ●●● + ● ● + ●●● ●●● diff --git a/pttbbs/sample/etc/chickens/j8 b/pttbbs/sample/etc/chickens/j8 new file mode 100644 index 00000000..c86b6f4a --- /dev/null +++ b/pttbbs/sample/etc/chickens/j8 @@ -0,0 +1,10 @@ + + + ▲ ▲ + ●●●●●▼ ●● + ●●●●●● ●●● + ●●◣●◢●● ● + ● ●●●●●● ● + ●● ●●●●● ●●● + ● ● + ●●● diff --git a/pttbbs/sample/etc/chickens/j9 b/pttbbs/sample/etc/chickens/j9 new file mode 100644 index 00000000..a902e57c --- /dev/null +++ b/pttbbs/sample/etc/chickens/j9 @@ -0,0 +1,11 @@ + + ▲ ▲ + ●● ●● + ●●●●●●● + ●●●●●●●● + ▲ ●●◣●●●◢●● + ●● ●●●●●●●● + ●●● ●▼▼▼▼▼● + ● ● ●●●●●● + ●●● ● ● + ●●● ●●● diff --git a/pttbbs/sample/etc/chickens/k0 b/pttbbs/sample/etc/chickens/k0 new file mode 100644 index 00000000..2c1f12a0 --- /dev/null +++ b/pttbbs/sample/etc/chickens/k0 @@ -0,0 +1,13 @@ + +(1)我要成為忍者! + ◢ + ◢◢██◣ + ◤◥◤◥█ +  ▌ ▌ ◥ + ◣ ◢ + ◣ ◥◤ ◢ + █ ██ █ + █ ██ █ + ██ + ◢◤◥◣ + diff --git a/pttbbs/sample/etc/chickens/k1 b/pttbbs/sample/etc/chickens/k1 new file mode 100644 index 00000000..836976bd --- /dev/null +++ b/pttbbs/sample/etc/chickens/k1 @@ -0,0 +1,11 @@ +大師!請收我為徒吧! + ◢ + ◢◢██◣ + ◤◥◤◥█ +  ▌ ▌ ◥ + ◣ ◢ + ◣ ◥◤ ◢ + █████ + ██ + ██ + ◢◤◥◣ diff --git a/pttbbs/sample/etc/chickens/k10 b/pttbbs/sample/etc/chickens/k10 new file mode 100644 index 00000000..6bf8c59e --- /dev/null +++ b/pttbbs/sample/etc/chickens/k10 @@ -0,0 +1,13 @@ +忍者五術-心 + ◢ + ◢◢██◣ + ◤◥◤◥█ +  ◣ ◢ ◤ + ◥██◤ + ◣ ◥◤ ◢ + █◣ ◢█ + ████ + ████ + + ◢██◣ + ◥██◤ diff --git a/pttbbs/sample/etc/chickens/k11 b/pttbbs/sample/etc/chickens/k11 new file mode 100644 index 00000000..bc2a19cc --- /dev/null +++ b/pttbbs/sample/etc/chickens/k11 @@ -0,0 +1,13 @@ +水土風水心...合體!! + ◢ ◣ + ◢◢██◣ ◢██◣◣ + ◤◥◤◥█ █◤◥◤◥ +  ◣ ◢ ◥ ◤ ◣ ◢  + ◥██◤ ◥██◤ + ██ ◤ ◢██ ██◣ ◥ ██ + ◣ ◢ ◣ ◢ + ██ ██ + ███ ███ + █▌ █▌ + ◢ ◥ ◤ ◣ + ◢ ◣ diff --git a/pttbbs/sample/etc/chickens/k12 b/pttbbs/sample/etc/chickens/k12 new file mode 100644 index 00000000..4cf65887 --- /dev/null +++ b/pttbbs/sample/etc/chickens/k12 @@ -0,0 +1,12 @@ +合體後成為高級忍者,氣勢駭人! + ◢█◤ + ◥◢███◣ + ◤◥◤◥█◣ +  ◣ ◢ ◥█ + ◥██◤ ◤ + ◣ ◥ ◥◤ ◤ ◢ + ◥ █◣ ◢█ ◤ + ◥ █ ██ █ ◤ + ◥◥ █ ███ █ ◤◤ + ◥◥ ███ ◤◤ + ◥◥◥ ██ ◤◤◤ diff --git a/pttbbs/sample/etc/chickens/k13 b/pttbbs/sample/etc/chickens/k13 new file mode 100644 index 00000000..faa26334 --- /dev/null +++ b/pttbbs/sample/etc/chickens/k13 @@ -0,0 +1,12 @@ +速度超快,你看得到嗎? + ◢█◤ + ◥◢██████◤ ◤ + ◤◥◤◥██◤ ◤ +  ◣ ◢ ◤ + ◥██◤ + ███◥◥◤ ◤███ █ + ◣ ◢ + ██ + ██ █ █ + ██ █ █ + ██ █ █ diff --git a/pttbbs/sample/etc/chickens/k14 b/pttbbs/sample/etc/chickens/k14 new file mode 100644 index 00000000..4d875ce4 --- /dev/null +++ b/pttbbs/sample/etc/chickens/k14 @@ -0,0 +1,12 @@ +這是我自創的武器-十字刀! + ◢█◤ + ◥◢███◣ + ◤◥◤◥█◣ + ◢  ◣ ◢ ◥█ ◣ + █ ◥██◤ ◤ █ + ◥███◣◥ ◥ ◤ ◤◢███◤ + ███ ◣ ◥◤ ◢ ███ + ◤ ██ ◥ + ███ + ███ + ██ diff --git a/pttbbs/sample/etc/chickens/k15 b/pttbbs/sample/etc/chickens/k15 new file mode 100644 index 00000000..d2b7f59b --- /dev/null +++ b/pttbbs/sample/etc/chickens/k15 @@ -0,0 +1,14 @@ +成為終極之-白忍! + ◢███◤ + ◣ ████◣ ◢ + ◢ ◢◤◥◤◥█◣ ◣ + ◣  ◣ ◢ ██ ◢ + ◣◢ ◥██◤█◤ ◣◢ + ◥ ◥ ◤ ◤◤ + █ ████ ◣ ◥◤ ◢ ████ █ + █ ███ █ + █ ███ █ + █ ████ █ + ████ +創 世 奇 俠 敗 腳 下 寰 宇 武 典 握 手 中 + 天 下 無 敵 第 一 人 哈! diff --git a/pttbbs/sample/etc/chickens/k16 b/pttbbs/sample/etc/chickens/k16 new file mode 100644 index 00000000..d2b7f59b --- /dev/null +++ b/pttbbs/sample/etc/chickens/k16 @@ -0,0 +1,14 @@ +成為終極之-白忍! + ◢███◤ + ◣ ████◣ ◢ + ◢ ◢◤◥◤◥█◣ ◣ + ◣  ◣ ◢ ██ ◢ + ◣◢ ◥██◤█◤ ◣◢ + ◥ ◥ ◤ ◤◤ + █ ████ ◣ ◥◤ ◢ ████ █ + █ ███ █ + █ ███ █ + █ ████ █ + ████ +創 世 奇 俠 敗 腳 下 寰 宇 武 典 握 手 中 + 天 下 無 敵 第 一 人 哈! diff --git a/pttbbs/sample/etc/chickens/k2 b/pttbbs/sample/etc/chickens/k2 new file mode 100644 index 00000000..5ed4647f --- /dev/null +++ b/pttbbs/sample/etc/chickens/k2 @@ -0,0 +1,10 @@ +皇帝召見,成為正式忍者! + ◢ + ◢◢██◣ + ◤◥◤◥█ +  ▌ ▌ ◥ + ◣ ◢ + ◣ ◥◤ ◢ + █ █ ██ + █ █ █ + ◤█ ◥◣ diff --git a/pttbbs/sample/etc/chickens/k3 b/pttbbs/sample/etc/chickens/k3 new file mode 100644 index 00000000..aa8a6519 --- /dev/null +++ b/pttbbs/sample/etc/chickens/k3 @@ -0,0 +1,11 @@ +什麼?只要蒙面就可以了? + ◢ + ◢◢██◣ + ◤◥◤◥█ +  ▌ ▌ ◥ + ◥██◤ + ◣ ◥◤ ◢ + ██ ██ ██ + ██ + ██ + ◢◤◥◣ diff --git a/pttbbs/sample/etc/chickens/k4 b/pttbbs/sample/etc/chickens/k4 new file mode 100644 index 00000000..b7e0c1c8 --- /dev/null +++ b/pttbbs/sample/etc/chickens/k4 @@ -0,0 +1,12 @@ +哈!變成中級忍者了,好神氣! + ◢ + ◢◢██◣ + ◤◥◤◥█ +  ◣ ◢ ◥ + █ ◥██◤ █ + █◣ ◥◤ ◢█ + ◣ ◢ + ◢██◣ + █◤◥█ + █ █ + ◢ ◣ diff --git a/pttbbs/sample/etc/chickens/k5 b/pttbbs/sample/etc/chickens/k5 new file mode 100644 index 00000000..120b52ac --- /dev/null +++ b/pttbbs/sample/etc/chickens/k5 @@ -0,0 +1,12 @@ +最簡單的-隱身術... +  ◢ + ◢◢██◣ + ◤◥◤◥█ +  ◣ ◢ ◥ + ◥██◤ +  █ █  +  ◢◤  +  █ █◤  +  █ █◤  +  █ ● █◤ ◢█◤  +  █ ████◤  diff --git a/pttbbs/sample/etc/chickens/k6 b/pttbbs/sample/etc/chickens/k6 new file mode 100644 index 00000000..0d869ccc --- /dev/null +++ b/pttbbs/sample/etc/chickens/k6 @@ -0,0 +1,13 @@ +忍者五術-火 + ◢ + ◢◢██◣ + ◤◥◤◥█ +  ◣ ◢ ◥ + ◣ ◥██◤ ◢ + ██◣ ◥◤ ◢██ + ◣ ◢ + ██ + ◣ ███ ◢ + ◣ ██ ◢ + ◣ ◣◣ ◥◤ ◢◢ ◢ + ◣◣◣◢◣◢◢◢ diff --git a/pttbbs/sample/etc/chickens/k7 b/pttbbs/sample/etc/chickens/k7 new file mode 100644 index 00000000..fb24da23 --- /dev/null +++ b/pttbbs/sample/etc/chickens/k7 @@ -0,0 +1,14 @@ +忍者五術-土 + ◢ + ◢◢██◣ + ◣ ◤◥◤◥█◢ + ◣ ◣ ◢ ◥ + █◥██◤█ + ◣ ◥◤ ◢ + ◣ ◢ + ██ + ███ + ██ + ◣ ◥◤ ◢ + ◣◥◤◢ + ◣◢ diff --git a/pttbbs/sample/etc/chickens/k8 b/pttbbs/sample/etc/chickens/k8 new file mode 100644 index 00000000..4e73a12c --- /dev/null +++ b/pttbbs/sample/etc/chickens/k8 @@ -0,0 +1,10 @@ +忍者五術-風 + ◢ + ◢◢██◣ + ◢◣ ◤◥◤◥█ ◢◣ + ◢██◣  ◣ ◢ ◥ ◢██◣ + ◢████◣ ◥██◤ ◢████◣ + ◥█◣ ◥◤ ◢█◤ + █ ◣ ◢ █ + █ ██ █ + ◤ ◥ diff --git a/pttbbs/sample/etc/chickens/k9 b/pttbbs/sample/etc/chickens/k9 new file mode 100644 index 00000000..cda73fd8 --- /dev/null +++ b/pttbbs/sample/etc/chickens/k9 @@ -0,0 +1,11 @@ +忍者五術-水 +  ● ◢ ────  +  ● ◢◢██◣ ──  +  ● ◤◥◤◥█◤ ──  +  ● ◣ ◢  ───  +  ◥██◤██ ──  +  ██◣◥◤ ◢◤ ────  +  ◣ ◢█ ◢█◥ ─── +  █████ ───  +  ███ ─────  +  ◥ ───  diff --git a/pttbbs/sample/etc/chickens/kiss b/pttbbs/sample/etc/chickens/kiss new file mode 100644 index 00000000..fdf155ee --- /dev/null +++ b/pttbbs/sample/etc/chickens/kiss @@ -0,0 +1,14 @@ + + +  oo$$$$oooo ooo$$$$$$oo +  o$$$$$$$$$$$$$$$$$$$$$$$$$$o +  o$$$$$$$$$$$$$$$$$$$$$$$$$$$$o +  $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ +  $$$$$$$$$$$$$$$$$$$$$$$$$$$$$" +  "$$$$$$$$$$$$$$$$$$$$$$$$$$$" +  "$$$$$$$$$$$$$$$$$$$$$$$$$" +  "$$$$$$$$$$$$$$$$$$$$$" +  ""$$$$$$$$$$$$$$$$" +  ""$$$$$$$$$"" +  ""$""  + 來...親一個!! diff --git a/pttbbs/sample/etc/chickens/l0 b/pttbbs/sample/etc/chickens/l0 new file mode 100644 index 00000000..36f55c21 --- /dev/null +++ b/pttbbs/sample/etc/chickens/l0 @@ -0,0 +1,9 @@ + + + ●●● + ● ●● ● + ●●●●●● + ●●●●●● + ●● ●● + ●● ●● + ●●●● diff --git a/pttbbs/sample/etc/chickens/l1 b/pttbbs/sample/etc/chickens/l1 new file mode 100644 index 00000000..36f55c21 --- /dev/null +++ b/pttbbs/sample/etc/chickens/l1 @@ -0,0 +1,9 @@ + + + ●●● + ● ●● ● + ●●●●●● + ●●●●●● + ●● ●● + ●● ●● + ●●●● diff --git a/pttbbs/sample/etc/chickens/l10 b/pttbbs/sample/etc/chickens/l10 new file mode 100644 index 00000000..b5c8367f --- /dev/null +++ b/pttbbs/sample/etc/chickens/l10 @@ -0,0 +1,15 @@ + ●● ●● + ●●●● ●●●● + ●●●●●●●●●●● + ● ● + ● ● ● ● + ● ● + ● ●●● ● + ● ● + ● ● ● ● + ●● ●●● + ● ● + ● ● + ● ●●● ● + ● ● ● + ● diff --git a/pttbbs/sample/etc/chickens/l11 b/pttbbs/sample/etc/chickens/l11 new file mode 100644 index 00000000..8646bce2 --- /dev/null +++ b/pttbbs/sample/etc/chickens/l11 @@ -0,0 +1,14 @@ + ●●●●●● + ● ● ●● + ● ● ● ●● + ●● ●●● + ● ● ●● + ●●●●●●●● ●● + ● ●● + ● ● ● ● + ● ● ● ● + ● ● ● + ● ● + ● ●●● ● + ● ● ● ● + ● ● diff --git a/pttbbs/sample/etc/chickens/l12 b/pttbbs/sample/etc/chickens/l12 new file mode 100644 index 00000000..8646bce2 --- /dev/null +++ b/pttbbs/sample/etc/chickens/l12 @@ -0,0 +1,14 @@ + ●●●●●● + ● ● ●● + ● ● ● ●● + ●● ●●● + ● ● ●● + ●●●●●●●● ●● + ● ●● + ● ● ● ● + ● ● ● ● + ● ● ● + ● ● + ● ●●● ● + ● ● ● ● + ● ● diff --git a/pttbbs/sample/etc/chickens/l13 b/pttbbs/sample/etc/chickens/l13 new file mode 100644 index 00000000..ba9d1d34 --- /dev/null +++ b/pttbbs/sample/etc/chickens/l13 @@ -0,0 +1,14 @@ + ●●●● + ●●●●●●●● + ●●●●●●●●●● + ●●●●●●●●●●●● + ● ●●●●●●●●● + ●● ● ●● + ●●●● ● + ● ● + ●● ●● + ● ●●●●●● ● + ● ● + ● ● + ● ● + ●●● ●● diff --git a/pttbbs/sample/etc/chickens/l14 b/pttbbs/sample/etc/chickens/l14 new file mode 100644 index 00000000..ba9d1d34 --- /dev/null +++ b/pttbbs/sample/etc/chickens/l14 @@ -0,0 +1,14 @@ + ●●●● + ●●●●●●●● + ●●●●●●●●●● + ●●●●●●●●●●●● + ● ●●●●●●●●● + ●● ● ●● + ●●●● ● + ● ● + ●● ●● + ● ●●●●●● ● + ● ● + ● ● + ● ● + ●●● ●● diff --git a/pttbbs/sample/etc/chickens/l15 b/pttbbs/sample/etc/chickens/l15 new file mode 100644 index 00000000..df160353 --- /dev/null +++ b/pttbbs/sample/etc/chickens/l15 @@ -0,0 +1,15 @@ + ●●●●●● + ● ● ● + ● ●● ● + ● ● ● + ●●● ● + ● ● + ● ●● ● + ● ● ● + ● ● ● ● + ● ● ● + ● ● + ● ● + ● ●● ●●● + ● ●● ● + ● ● diff --git a/pttbbs/sample/etc/chickens/l16 b/pttbbs/sample/etc/chickens/l16 new file mode 100644 index 00000000..100d4260 --- /dev/null +++ b/pttbbs/sample/etc/chickens/l16 @@ -0,0 +1,15 @@ + ●●●●●●● + ● ●●● + ● ● ● ●●● + ●●●●●●● ●● + ● ● ● + ●●●●●●● ● + ● ● ● + ●●●●●● ● + ● ● + ● ● + ● ● + ●● ● ● + ● ●●●●●● ●● + ● ● + ●●● ●● diff --git a/pttbbs/sample/etc/chickens/l2 b/pttbbs/sample/etc/chickens/l2 new file mode 100644 index 00000000..6714c9d2 --- /dev/null +++ b/pttbbs/sample/etc/chickens/l2 @@ -0,0 +1,12 @@ + + + + ●●●●●● + ● ● + ● ● ● ● + ● ● + ● ●● ● + ● ● + ● ● + ● ● + ●●●●●● diff --git a/pttbbs/sample/etc/chickens/l3 b/pttbbs/sample/etc/chickens/l3 new file mode 100644 index 00000000..6714c9d2 --- /dev/null +++ b/pttbbs/sample/etc/chickens/l3 @@ -0,0 +1,12 @@ + + + + ●●●●●● + ● ● + ● ● ● ● + ● ● + ● ●● ● + ● ● + ● ● + ● ● + ●●●●●● diff --git a/pttbbs/sample/etc/chickens/l4 b/pttbbs/sample/etc/chickens/l4 new file mode 100644 index 00000000..723291ae --- /dev/null +++ b/pttbbs/sample/etc/chickens/l4 @@ -0,0 +1,13 @@ + + + + ●●●●●● + ● ● + ● ● ● ● + ● ● + ● ●● ● + ●●● ●● ●● + ● ● + ● ●●●● ● + ● ● ● + ● diff --git a/pttbbs/sample/etc/chickens/l5 b/pttbbs/sample/etc/chickens/l5 new file mode 100644 index 00000000..723291ae --- /dev/null +++ b/pttbbs/sample/etc/chickens/l5 @@ -0,0 +1,13 @@ + + + + ●●●●●● + ● ● + ● ● ● ● + ● ● + ● ●● ● + ●●● ●● ●● + ● ● + ● ●●●● ● + ● ● ● + ● diff --git a/pttbbs/sample/etc/chickens/l6 b/pttbbs/sample/etc/chickens/l6 new file mode 100644 index 00000000..d3edcf12 --- /dev/null +++ b/pttbbs/sample/etc/chickens/l6 @@ -0,0 +1,14 @@ + + + + ●●●●●● + ● ● ● + ● ●● ● + ● ● ● + ●●● ● + ● ● + ● ●● ● + ● ● ● + ● ● + ● ● + ●●●●●● diff --git a/pttbbs/sample/etc/chickens/l7 b/pttbbs/sample/etc/chickens/l7 new file mode 100644 index 00000000..d3edcf12 --- /dev/null +++ b/pttbbs/sample/etc/chickens/l7 @@ -0,0 +1,14 @@ + + + + ●●●●●● + ● ● ● + ● ●● ● + ● ● ● + ●●● ● + ● ● + ● ●● ● + ● ● ● + ● ● + ● ● + ●●●●●● diff --git a/pttbbs/sample/etc/chickens/l8 b/pttbbs/sample/etc/chickens/l8 new file mode 100644 index 00000000..b5c8367f --- /dev/null +++ b/pttbbs/sample/etc/chickens/l8 @@ -0,0 +1,15 @@ + ●● ●● + ●●●● ●●●● + ●●●●●●●●●●● + ● ● + ● ● ● ● + ● ● + ● ●●● ● + ● ● + ● ● ● ● + ●● ●●● + ● ● + ● ● + ● ●●● ● + ● ● ● + ● diff --git a/pttbbs/sample/etc/chickens/l9 b/pttbbs/sample/etc/chickens/l9 new file mode 100644 index 00000000..b5c8367f --- /dev/null +++ b/pttbbs/sample/etc/chickens/l9 @@ -0,0 +1,15 @@ + ●● ●● + ●●●● ●●●● + ●●●●●●●●●●● + ● ● + ● ● ● ● + ● ● + ● ●●● ● + ● ● + ● ● ● ● + ●● ●●● + ● ● + ● ● + ● ●●● ● + ● ● ● + ● diff --git a/pttbbs/sample/etc/chickens/m0 b/pttbbs/sample/etc/chickens/m0 new file mode 100644 index 00000000..36f55c21 --- /dev/null +++ b/pttbbs/sample/etc/chickens/m0 @@ -0,0 +1,9 @@ + + + ●●● + ● ●● ● + ●●●●●● + ●●●●●● + ●● ●● + ●● ●● + ●●●● diff --git a/pttbbs/sample/etc/chickens/m1 b/pttbbs/sample/etc/chickens/m1 new file mode 100644 index 00000000..36f55c21 --- /dev/null +++ b/pttbbs/sample/etc/chickens/m1 @@ -0,0 +1,9 @@ + + + ●●● + ● ●● ● + ●●●●●● + ●●●●●● + ●● ●● + ●● ●● + ●●●● diff --git a/pttbbs/sample/etc/chickens/m10 b/pttbbs/sample/etc/chickens/m10 new file mode 100644 index 00000000..b5c8367f --- /dev/null +++ b/pttbbs/sample/etc/chickens/m10 @@ -0,0 +1,15 @@ + ●● ●● + ●●●● ●●●● + ●●●●●●●●●●● + ● ● + ● ● ● ● + ● ● + ● ●●● ● + ● ● + ● ● ● ● + ●● ●●● + ● ● + ● ● + ● ●●● ● + ● ● ● + ● diff --git a/pttbbs/sample/etc/chickens/m11 b/pttbbs/sample/etc/chickens/m11 new file mode 100644 index 00000000..8646bce2 --- /dev/null +++ b/pttbbs/sample/etc/chickens/m11 @@ -0,0 +1,14 @@ + ●●●●●● + ● ● ●● + ● ● ● ●● + ●● ●●● + ● ● ●● + ●●●●●●●● ●● + ● ●● + ● ● ● ● + ● ● ● ● + ● ● ● + ● ● + ● ●●● ● + ● ● ● ● + ● ● diff --git a/pttbbs/sample/etc/chickens/m12 b/pttbbs/sample/etc/chickens/m12 new file mode 100644 index 00000000..8646bce2 --- /dev/null +++ b/pttbbs/sample/etc/chickens/m12 @@ -0,0 +1,14 @@ + ●●●●●● + ● ● ●● + ● ● ● ●● + ●● ●●● + ● ● ●● + ●●●●●●●● ●● + ● ●● + ● ● ● ● + ● ● ● ● + ● ● ● + ● ● + ● ●●● ● + ● ● ● ● + ● ● diff --git a/pttbbs/sample/etc/chickens/m13 b/pttbbs/sample/etc/chickens/m13 new file mode 100644 index 00000000..ba9d1d34 --- /dev/null +++ b/pttbbs/sample/etc/chickens/m13 @@ -0,0 +1,14 @@ + ●●●● + ●●●●●●●● + ●●●●●●●●●● + ●●●●●●●●●●●● + ● ●●●●●●●●● + ●● ● ●● + ●●●● ● + ● ● + ●● ●● + ● ●●●●●● ● + ● ● + ● ● + ● ● + ●●● ●● diff --git a/pttbbs/sample/etc/chickens/m14 b/pttbbs/sample/etc/chickens/m14 new file mode 100644 index 00000000..ba9d1d34 --- /dev/null +++ b/pttbbs/sample/etc/chickens/m14 @@ -0,0 +1,14 @@ + ●●●● + ●●●●●●●● + ●●●●●●●●●● + ●●●●●●●●●●●● + ● ●●●●●●●●● + ●● ● ●● + ●●●● ● + ● ● + ●● ●● + ● ●●●●●● ● + ● ● + ● ● + ● ● + ●●● ●● diff --git a/pttbbs/sample/etc/chickens/m15 b/pttbbs/sample/etc/chickens/m15 new file mode 100644 index 00000000..df160353 --- /dev/null +++ b/pttbbs/sample/etc/chickens/m15 @@ -0,0 +1,15 @@ + ●●●●●● + ● ● ● + ● ●● ● + ● ● ● + ●●● ● + ● ● + ● ●● ● + ● ● ● + ● ● ● ● + ● ● ● + ● ● + ● ● + ● ●● ●●● + ● ●● ● + ● ● diff --git a/pttbbs/sample/etc/chickens/m16 b/pttbbs/sample/etc/chickens/m16 new file mode 100644 index 00000000..100d4260 --- /dev/null +++ b/pttbbs/sample/etc/chickens/m16 @@ -0,0 +1,15 @@ + ●●●●●●● + ● ●●● + ● ● ● ●●● + ●●●●●●● ●● + ● ● ● + ●●●●●●● ● + ● ● ● + ●●●●●● ● + ● ● + ● ● + ● ● + ●● ● ● + ● ●●●●●● ●● + ● ● + ●●● ●● diff --git a/pttbbs/sample/etc/chickens/m2 b/pttbbs/sample/etc/chickens/m2 new file mode 100644 index 00000000..6714c9d2 --- /dev/null +++ b/pttbbs/sample/etc/chickens/m2 @@ -0,0 +1,12 @@ + + + + ●●●●●● + ● ● + ● ● ● ● + ● ● + ● ●● ● + ● ● + ● ● + ● ● + ●●●●●● diff --git a/pttbbs/sample/etc/chickens/m3 b/pttbbs/sample/etc/chickens/m3 new file mode 100644 index 00000000..6714c9d2 --- /dev/null +++ b/pttbbs/sample/etc/chickens/m3 @@ -0,0 +1,12 @@ + + + + ●●●●●● + ● ● + ● ● ● ● + ● ● + ● ●● ● + ● ● + ● ● + ● ● + ●●●●●● diff --git a/pttbbs/sample/etc/chickens/m4 b/pttbbs/sample/etc/chickens/m4 new file mode 100644 index 00000000..723291ae --- /dev/null +++ b/pttbbs/sample/etc/chickens/m4 @@ -0,0 +1,13 @@ + + + + ●●●●●● + ● ● + ● ● ● ● + ● ● + ● ●● ● + ●●● ●● ●● + ● ● + ● ●●●● ● + ● ● ● + ● diff --git a/pttbbs/sample/etc/chickens/m5 b/pttbbs/sample/etc/chickens/m5 new file mode 100644 index 00000000..723291ae --- /dev/null +++ b/pttbbs/sample/etc/chickens/m5 @@ -0,0 +1,13 @@ + + + + ●●●●●● + ● ● + ● ● ● ● + ● ● + ● ●● ● + ●●● ●● ●● + ● ● + ● ●●●● ● + ● ● ● + ● diff --git a/pttbbs/sample/etc/chickens/m6 b/pttbbs/sample/etc/chickens/m6 new file mode 100644 index 00000000..d3edcf12 --- /dev/null +++ b/pttbbs/sample/etc/chickens/m6 @@ -0,0 +1,14 @@ + + + + ●●●●●● + ● ● ● + ● ●● ● + ● ● ● + ●●● ● + ● ● + ● ●● ● + ● ● ● + ● ● + ● ● + ●●●●●● diff --git a/pttbbs/sample/etc/chickens/m7 b/pttbbs/sample/etc/chickens/m7 new file mode 100644 index 00000000..d3edcf12 --- /dev/null +++ b/pttbbs/sample/etc/chickens/m7 @@ -0,0 +1,14 @@ + + + + ●●●●●● + ● ● ● + ● ●● ● + ● ● ● + ●●● ● + ● ● + ● ●● ● + ● ● ● + ● ● + ● ● + ●●●●●● diff --git a/pttbbs/sample/etc/chickens/m8 b/pttbbs/sample/etc/chickens/m8 new file mode 100644 index 00000000..b5c8367f --- /dev/null +++ b/pttbbs/sample/etc/chickens/m8 @@ -0,0 +1,15 @@ + ●● ●● + ●●●● ●●●● + ●●●●●●●●●●● + ● ● + ● ● ● ● + ● ● + ● ●●● ● + ● ● + ● ● ● ● + ●● ●●● + ● ● + ● ● + ● ●●● ● + ● ● ● + ● diff --git a/pttbbs/sample/etc/chickens/m9 b/pttbbs/sample/etc/chickens/m9 new file mode 100644 index 00000000..b5c8367f --- /dev/null +++ b/pttbbs/sample/etc/chickens/m9 @@ -0,0 +1,15 @@ + ●● ●● + ●●●● ●●●● + ●●●●●●●●●●● + ● ● + ● ● ● ● + ● ● + ● ●●● ● + ● ● + ● ● ● ● + ●● ●●● + ● ● + ● ● + ● ●●● ● + ● ● ● + ● diff --git a/pttbbs/sample/etc/chickens/medicine b/pttbbs/sample/etc/chickens/medicine new file mode 100644 index 00000000..2bde35ed --- /dev/null +++ b/pttbbs/sample/etc/chickens/medicine @@ -0,0 +1,14 @@ + + + +[1;36  +  +  ▁▁▁▃  ▁▁▁▃ + ══☉ ══◎ + ◤ ◥ ◤ ◥ +  ╭─────鞷w────╮ +  │ pepper   salt │ + │◥◤  ◥◤│ + \薋嘵/ + + 吃藥囉~~~ diff --git a/pttbbs/sample/etc/chickens/nofood b/pttbbs/sample/etc/chickens/nofood new file mode 100644 index 00000000..d784c9e0 --- /dev/null +++ b/pttbbs/sample/etc/chickens/nofood @@ -0,0 +1,18 @@ + + \ / ◤ /◥ ●●● + — ● —  ◤◥  ●●●● + / \ ●-●─  ●●●● +  ﹉█ ●●● + █ ii◤  █ + █ ◤◥ˍ/█◥ + ████ iii █  + ◥ ◥█◤ + ◥ ◤◥  ███ +  ◥◥█●███ + ☉ ☉ ◥◥◤◥ ◤ +  ◥    ◥ ▁▂▃▄ +     ▃     +   ◤     +  ◤█   +  ████ ████ ,,..... + 餓過頭了 離家出走... diff --git a/pttbbs/sample/etc/chickens/nohp b/pttbbs/sample/etc/chickens/nohp new file mode 100644 index 00000000..474f9c63 --- /dev/null +++ b/pttbbs/sample/etc/chickens/nohp @@ -0,0 +1,16 @@ + + ▆███████▆ + i██████████ + i███████████ + ▍ i██ ██ ███ + ▍▍▍ ii█ █ i█i +▍▍▍▍▍ i█ i i█ +▍▍▍▍▍ i▁ ° i ° ▁█ +████i f █▅██▅█ f +████i ii█▂█▂█i█ + ███i i n▌▋▋▌▊ █ + ██i i █ + o▌ █ █ + o▌ d mm▌▌▌▌█ ▂ + o▌ d▃▃ ██████ ▃▃▃ + 體力(HP)耗盡 死掉了 :~~ diff --git a/pttbbs/sample/etc/chickens/nosatis b/pttbbs/sample/etc/chickens/nosatis new file mode 100644 index 00000000..c8495275 --- /dev/null +++ b/pttbbs/sample/etc/chickens/nosatis @@ -0,0 +1,6 @@ + +哼 + +我不滿意你這個爛保母 + +Byebye diff --git a/pttbbs/sample/etc/chickens/oo b/pttbbs/sample/etc/chickens/oo new file mode 100644 index 00000000..e316b055 --- /dev/null +++ b/pttbbs/sample/etc/chickens/oo @@ -0,0 +1,14 @@ + + + + + + + +  λ +  ●● + ●●● + ●● + ●  + + 吃大補丸解除疲勞吧 diff --git a/pttbbs/sample/etc/chickens/read b/pttbbs/sample/etc/chickens/read new file mode 100644 index 00000000..e4060357 --- /dev/null +++ b/pttbbs/sample/etc/chickens/read @@ -0,0 +1,14 @@ + + + + + + ▃▃▃▃ +   |/ __ +  ▁▆▂ ▇ ▕::::▏ +  歈稙 +  │ = │ = │ +  ├──────┼───┤ +  │ │ = │ + │      ├───┤ + 用功時間囉..... diff --git a/pttbbs/sample/etc/chickens/sell b/pttbbs/sample/etc/chickens/sell new file mode 100644 index 00000000..e253e3d0 --- /dev/null +++ b/pttbbs/sample/etc/chickens/sell @@ -0,0 +1,23 @@ + +  *  ︱  * +  \ ︱ /   + |   \ | /  *  +  \|/  \ │  /   +  --も--   ◢█████◣  +  /|\  █◤\│/◥█  +  |  - - -----◥-─*─-█----- - -  +  /│\ █  *  + *  / | ◢◤  +  /{㎜★㎜}\  +  /  (▄▄)  \  +  *  /  ▆▆  \  +  ██  +  │  ██  *    |  +  \ │ /  ██ \|/  +  /|\  ██  -----┼-----  +  ……(※)……  ██ /|\  + \|/  ██  |  + / │ \  ██  +  *  │  ()  *  + ▔▔ 終於解脫了 ^_^.... + diff --git a/pttbbs/sample/etc/chickens/toofat b/pttbbs/sample/etc/chickens/toofat new file mode 100644 index 00000000..b20a502e --- /dev/null +++ b/pttbbs/sample/etc/chickens/toofat @@ -0,0 +1,17 @@ + + + + + .-., ,.-. + '-. /:::\\ //:::\ .-' + '-.\|':':' `"` ':':'|/.-' + `-./`. .-=-. .-=-. .`\.-` + /=- / | \ -=\ + ; | | | ; + |=-.|______|______|.-=| + |== \ 0 /_\ 0 / ==| + |= /'---( )---'\ =| + \ \: .'. :/ / + `\= '--` `--' =/' + `-=._ _.=-' + `"""`  肥胖過度..撐死了.. diff --git a/pttbbs/sample/etc/chickens/tootired b/pttbbs/sample/etc/chickens/tootired new file mode 100644 index 00000000..a1f0429f --- /dev/null +++ b/pttbbs/sample/etc/chickens/tootired @@ -0,0 +1,15 @@ + + + ┼┼┼┼┼┼┼┼┼ ▁▂▃ ┼┼┼┼┼ + ┼┼┼┼┼▄█▄ ◆◆▕ ◤ ◥◥┼ + ┼┼┼┼/  ☉☉  ◥◤  oo  \┼ + ▃__◤ ∼◥▆▂▌◤ o▏  ◥◤ ┼ +  ▔◥ ∼◤◥◥◥█▕O▎▌ ▃▃┼ + -------◥◥◥◥◥◥█o◤ █● ◤█ +  ◥____◥▆▆◥◥ ≡≡≡≡▌▌▌▌▌▌ + ◢ ◥█歈◤ ▆▆▊▃  + ▄▄ ◥◥ ◥ ▆█ ▊█ █ ▊  + ▌ ◥◥ ◥ █  ▊ ▌█ ▊█  + ▌ ◢◤ ◥◣◤ ▊ ▌█ ◥  + + 操勞過度.....累倒了...... diff --git a/pttbbs/sample/etc/domain_name_query b/pttbbs/sample/etc/domain_name_query new file mode 100644 index 00000000..cc3a05f2 --- /dev/null +++ b/pttbbs/sample/etc/domain_name_query @@ -0,0 +1,256 @@ +# '#'自之後可以加註解 +# +# 下面這'@'行不可拿掉 +# 查無佌住址 +@@@@@@@@@@@@@@ ---------- + +# 255.255.255.255 各人專屬請放這邊 + +# 學校 或 團體 +# 群組請由小到大排列 + +pclab&csie bc的pclab +.ee.ntu. 台大電機學院 +jan.csie.ntu 台大資訊地下一月 +feb.csie.ntu 台大資訊地下二月 +mar.csie.ntu 台大資訊地下三月 +apr.csie.ntu 台大資訊地下四月 +may.csie.ntu 台大資訊地下五月 +jun.csie.ntu 台大資訊地下六月 +sep.csie.ntu 台大資訊地下九月 +snoopy.csie 史奴比工作站 +csie.ntu 台大資訊系 +140.112.28. 台大資訊系 +140.112.29. 台大資訊系 +140.112.30. 台大資訊系 +140.112.31. 台大資訊系 +#140.112.4 台大資訊系 +phys.ntu 台大物理系 +scorpio.im.ntu 台大資管scorpio +im.ntu 台大管院 +ccnet1.ntu 台大宿舍DNS +cc.ntu. 台大計算雞中心 +140.112.3. 台大計算雞中心 + +140.112.10. 台大土木系 +140.112.11. 台大土木系 +140.112.12. 台大土木系 +140.112.13. 台大土木系 +ce.ntu 台大土木系 + +140.112.15. 台大志鴻館 + +140.112.16. 台大新工學院大樓 +140.112.17. 台大電機學院 +140.112.18. 台大電機學院 +140.112.19. 台大電機學院 +140.112.20. 台大電機學院 +140.112.21. 台大電機學院 + +140.112.22. 台大化工系 +140.112.23. 台大化工系 +140.112.26. 台大造船系 + +140.112.169. 台大研二小套房 +140.112.174. 台大女九紗棉坊 +140.112.216. 台大女三甜蜜窩 +140.112.220. 台大女一大閨房 +140.112.221. 台大女一大閨房 +140.112.224. 台大女七成衣場 +140.112.225. 台大女五針織室 +140.112.239. 台大男一窩 +140.112.240. 台大男一窩 +140.112.241. 台大男一窩 +140.112.242. 台大男一窩 +140.112.243. 台大男三屋 +140.112.244. 台大男三屋 +140.112.245. 台大男五房 +140.112.246. 台大男五房 +140.112.247. 台大男六眷 +140.112.248. 台大男六眷 +140.112.249. 台大男七窯 +140.112.250. 台大男七窯 +140.112.251. 台大男八別墅 +140.112.252. 台大男八別墅 +140.112.253. 台大男八別墅 + +.m1.ntu 台大男一窩 +.m2.ntu 台大男二館 +.m3.ntu 台大男三屋 +.m4.ntu 台大男四所 +.m5.ntu 台大男五房 +.m6.ntu 台大男六眷 +.m7.ntu 台大男七窯 +.m8.ntu 台大男八莊 +.g2.ntu 台大研二小套房 +.f1.ntu 台大女一大閨房 +.f2.ntu 台大女二蜜月屋 +.f3.ntu 台大女三甜蜜窩 +.f4.ntu 台大女四高崗屋 +.f5.ntu 台大女五針織室 +.f6.ntu 台大女六婚紗廊 +.f7.ntu 台大女七成衣場 +.f8.ntu 台大女八染衣塘 +.f9.ntu 台大女九紗棉坊 + +green.ev.ntu. 台大環工所 +.ie.ntu.edu.tw 台大工工所 +140.112.36. 台大工工所(新工樓) +140.112.38. 台大應力所 +140.112.39. 台大城鄉所 +140.112.40. 台大水工所(新工樓) +140.112.42. 台大電機舊館 +140.112.43. 台大機械系 +140.112.44. 台大機械系 +140.112.46. 台大機械系 +math.ntu 台大數學系 +140.112.50. 台大數學館 +140.112.52. 台大物理系 +140.112.54. 台大化學系 +140.112.56. 台大地質系 +140.112.58. 台大動物系 +140.112.60. 台大植物系 +140.112.61. 台大植研大樓 +psy.ntu 台大心理系 +140.112.62. 台大心理系 +140.112.64. 台大地理系 +140.112.65. 台大全球變遷/凝態中心 +140.112.66. 台大大氣系 +140.112.67. 台大大氣系 +140.112.68. 台大海洋所 +140.112.69. 台大海洋所 +140.112.70. 台大漁科所 +140.112.72. 台大生化所 +140.112.74. 台大農藝系 +140.112.75. 台大生統教室 +140.112.76. 台大農工系 +140.112.78. 台大農化系 +140.112.80. 台大植病系 +140.112.81. 台大昆蟲館 +140.112.82. 台大森林系 +140.112.84. 台大畜產系 +140.112.86. 台大農經系 +140.112.88. 台大園藝系 +140.112.89. 台大工廠 +140.112.92. 台大農推系 +140.112.94. 台大農機系 +140.112.96. 台大獸醫系 +140.112.99. 台大衛生組 +140.112.111. 台大活動中心 +140.112.120. 台大活動中心 +140.112.100. 台大植病系養蟲館 +140.112.106. 台大資管系 +140.112.108. 台大管院計中 +140.112.110. 台大管院計中 +140.112.120. 台大醫學校區 +140.112.136. 台大公衛系 +140.112.141. 台大中文系/外文系 +140.112.142. 台大歷史系/藝術史所 +140.112.143. 台大哲學系/農業陳列廣 +140.112.145. 台大闈場及普通教室 +140.112.146. 台大日文系/戲刻所/語言所 +140.112.150. 台大舊法學院,法圖 +140.112.153. 台大新聞所 +140.112.155. 台大三研所 +140.112.156. 台大社會系 +140.112.157. 台大社會系 +140.112.160. 台大行政大樓 +140.112.178. 台大學生住宿服務組 +140.112.181. 台大管理學院 +140.112.182. 台大新工樓 +140.112.183. 台大農業自動化教室 +lib.ntu. 台大總圖 + +.admin.yzu 元智網推 +.dorm.ccu.e 中正大旅社 +.mayju.com 梅竹山莊 +as.ntu. 台大大氣系 +csie.nctu. 交大資工 +www.nia. 國立藝術學院www +nia.edu.tw 國立藝術學院 +163.18. 高雄甘蔗園 +203.64.3. 國立藝術學院 +140.119. 政治大學 +cc.ntnu. 師大計中 +140.122. 師範大學 +k2.dorm.nc 成大光二8舍 +cc.nctu. 交大計中 +php&cc.nctu. 交大計中 +nchu 中興大學 +linux.na.ntu. 台大造船中心 +140.112.8. 台大計算雞中心 +140.112.7. 台大計中PC室 +cc.ncku. 成大計中 +stmail.fju. 輔大計中 +IP&dialup.ntu. 計中撥接系統 +im.ntu.edu. 台大資管 +med.mc.ntu. 台大醫院網路部 +mc.ntu. 台大醫院網路部 +139.175. SeedNet +.seed.net.tw SeedNet +210.64. HiNet +168.95. Hinet +.ts.hin HiNet +.hinet. HiNet +cc.chpi. 中華工學院 +.nctu. 交通大學 +.cc.nccu.edu.tw 政大計中 +.nccu.edu.tw 政治大學 +.AB. 清大宿舍 +.ncku. 成大 +.seeder. 阿波羅資訊網 +iis. 中研院資訊所 +sinica. 中央研究院 +ntust. 台科大 +scu. 東吳大學 +fju. 輔仁大學 +nthu. 清華大學 +thu. 東海大學 +ntu.edu 台灣大學 +ntut.edu 台北科技大學 +140.112 台灣大學 +cgu. 長庚大學 +ntou. 海洋大學 +NTOU. 海洋大學 +NCTU. 交通宿舍 +140.125 雲林科技大學 +tpml.edu.tw 台北市立圖書館 +ntnu. 師範大學 +ficnet.net 大眾網路 +tku. 淡江大學 +shu. 世新大學 +ncue. 彰化師範大學 +ncu. 中央大學 +ntnu. 師範大學 +140.115 中央大學 +ndhu. 東華大學 +iii 資策會 +nsysu. 中山大學 +ethome 東森寬頻 +tmc.edu.tw 台北醫學院 +ym.edu.tw 陽明大學 +chu.edu.tw 中華大學 +140.138 元智大學 +140.128 東海大學 +140.120 中興大學 +ntpu. 台北大學 +yzu.edu.tw 元智大學 +cyut.edu.tw 朝陽科技大學 +fg.tp. 北一女 +nhltc. 花蓮師範學院 +tceb. 台中市府教育局 +ntcic. 台中技術學院 +jhnc.tp. 北市誠正國中 +dyu. 大葉大學 +ilc.edu. 宜蘭縣教育資訊網 +ks.edu. 高雄縣教育網 +cma. 陸軍官校 +ssvs.tp. 松山家商 +csmc. 中山醫學院 +ttu. 大同大學 +cmc. 中國醫藥學院 +kmu. 高雄醫學大學 +tmtc. 北市師範學院 +140.117. 中山大學 +210.208. SayHiNet無限撥接 +ck.tp.edu.tw 建國中學 diff --git a/pttbbs/sample/etc/feast b/pttbbs/sample/etc/feast new file mode 100644 index 00000000..29473341 --- /dev/null +++ b/pttbbs/sample/etc/feast @@ -0,0 +1,47 @@ +01 01 元旦放假 +01 02 元旦又放假 +01 11 司法節 +01 23 自由日 +02 14 情人節 +02 28 二二八紀念 +03 01 兵役節 +03 05 童軍節 +03 12 植樹節 +03 14 白色情人節 +03 17 國醫節 +03 21 氣象節 +03 29 青年節 +04 01 愚人節 +04 04 婦幼節 +04 04 兒童節 +04 05 清明節 +05 01 勞動節 +05 04 文藝節 +06 03 禁煙節 +06 09 鐵路節 +06 06 工程師節 +06 15 警察節 +07 01 公路節 +07 03 合作節 +07 04 美國獨立紀念日 +07 11 航海節 +07 14 法國國慶 +08 08 八八父親節 +08 14 空軍節 +09 01 記者節 +09 03 軍人節 +09 09 狗狗節 +09 18 九一八事變 +09 28 教師節 +10 10 國慶日 +10 21 華僑節 +10 25 台灣光復節 +10 31 蔣公誕辰 +11 11 工業節 +11 12 國父誕辰 +11 15 台灣大學校慶 +12 01 世界愛滋日 +12 10 世界人權節 +12 13 三商週年慶 +12 24 X'masEve +12 25 聖誕節 diff --git a/pttbbs/sample/etc/goodbye b/pttbbs/sample/etc/goodbye new file mode 100644 index 00000000..38f8aac9 --- /dev/null +++ b/pttbbs/sample/etc/goodbye @@ -0,0 +1,19 @@ +再見再見再見再見再見再見再見再見再見再見再見再見再見再見再再再見再見再見再見再 +再見再見再見再見再見再見再見再見再見再見再見再見再見再見再見再見再見再見再見再 +再見再見再見再見再見再見再見再見再見再見再見再見再見再見再再再見再見再見再見再 +再見再見再見再見再見再見再見再見再見再見再見再見再見再見再再再見再見再見再見再 +再見再見再見再見再見再見再見再見再見再見再見再見再見再見再再再見再見再見再見再 +再見再見再見再見再見再見再見再見再見再見再見再見再見再見再再再見再見再見再見再 +再見再見再見再見再見再見再見再見再見再見再見再見再見再見再再再見再見再見再見再 +再見再見再見再見再見┌─────────────┐再見再見再再見再見再見再見再 +再見再見再見再見再見│ 請仔細回憶您的密碼,  │─┐再見再再見再見再見再見再 +再見再見再見再見再見│ 如果真的忘記密碼了,  │ │再見再再見再見再見再見再 +再見再見再見再見再見│ 請用[new]重新註冊吧! │ │再見再再見再見再見再見再 +再見再見再見再見再見│ 亂踹密碼會留下記錄喔。 │ │再見再再見再見再見再見再 +再見再見再見再見再見└─────────────┘ │再見再再見再見再見再見再 +再見再見再見再見再見再見└─────────────┘再見再再見再見再見再見再 +再見再見再見再見再見再見再見再見再見再見再見再見再見再見再再再見再見再見再見再 +再見再見再見再見再見再見再見再見再見再見再見再見再見再見再再再見再見再見再見再 +如果您發現您的ID不見了, 而且不是因為太久沒來被砍者 +請通知站務管理員, 切勿重新new 原來的ID, 否則所有記 +錄和金錢將會歸零 diff --git a/pttbbs/sample/etc/register b/pttbbs/sample/etc/register new file mode 100644 index 00000000..53b5e2d6 --- /dev/null +++ b/pttbbs/sample/etc/register @@ -0,0 +1,17 @@ +┌─────────────────────────────────────┐ +│ 請參考下列的範例填寫您的註冊資料: │ +├───────────────────┬─────────────────┤ +│請輸入代號: piggy │ 輸入您想用的英文代號 │ +│請設定密碼: I'mPig │ 請設定密碼,不過螢幕上應該看不見 │ +│請檢查密碼: I'mPig │ 請再次輸入密碼,以示確定 │ +│ │ Kermit 使用者請打 vt320 │ +│您的暱稱: 豬年生的美眉 │ 您發表文章用的筆名或綽號 │ +│真實姓名: 朱曉媚 │ 您的真實姓名 │ +│目前住址: 新竹縣子虛鄉烏有村543號 │ 您目前的聯絡地址(詳細填寫) │ +│網路郵件地址: whoami@cs.ntnu.edu.tw │ 您的 E-Mail address │ +└───────────────────┴─────────────────┘ + ※ 在本站註冊者,代表願意尊從本站制度與站規,否則請離開。 + ※ 代號 [ID] 至少要兩個字,不宜採用數字。 + ※ 密碼 至少要四個字,不可與 [ID] 雷同,不宜全部小寫。 + ※ 請確實按照規定詳細填寫,否則不予通過! + ※ 以上資料缺一不可A敬請合作! diff --git a/pttbbs/sample/etc/registered b/pttbbs/sample/etc/registered new file mode 100644 index 00000000..1b52a301 --- /dev/null +++ b/pttbbs/sample/etc/registered @@ -0,0 +1,21 @@ + 歈歈 + 僓僓 審核通過  +◇── 裺裺────────────────────────◇ + + 嗨嗨,*s你好: + + 我親自幫你審核通過囉 ^o^ + + 若還不能Post請重新login一次 ^_^ (要換身份囉) + + + + 祝 使用愉快 + + 記得常常來玩喔.... ^_^ + + + + + 站長~~ +◇────────────────────────────────────◇ diff --git a/pttbbs/sample/etc/today_boring b/pttbbs/sample/etc/today_boring new file mode 100644 index 00000000..12e39ce2 --- /dev/null +++ b/pttbbs/sample/etc/today_boring @@ -0,0 +1,22 @@ + [ 牡羊時 ] + [ 牡羊時 ] + [ 金牛時 ] + [ 金牛時 ] + [ 雙子時 ] + [ 雙子時 ] + [ 巨蟹時 ] + [ 巨蟹時 ] + [ 獅子時 ] + [ 獅子時 ] + [ 處女時 ] + [ 處女時 ] + [ 天秤時 ] + [ 天秤時 ] + [ 雙魚時 ] + [ 雙魚時 ] + [ 射手時 ] + [ 射手時 ] + [ 魔羯時 ] + [ 魔羯時 ] + [ 水瓶時 ] + [ 水瓶時 ] diff --git a/pttbbs/sample/etc/ve.hlp b/pttbbs/sample/etc/ve.hlp new file mode 100644 index 00000000..c1688bf2 --- /dev/null +++ b/pttbbs/sample/etc/ve.hlp @@ -0,0 +1,127 @@ + 【一般指令】 + ^X 檔案處理 ^L 重新顯示畫面 + ^V 切換ANSI色彩 ^Z 顯示本求助畫面 + ^Q 不存檔離開  ^G 插入圖片文字庫 + 【游標移動指令】 + ← 往後移動一格 ^A,Home 移到此行開頭 + → 往前移動一格 ^E,End 移到此行結尾 + ↑,^P 往上移動一行 (ESC-,) 移到檔案開頭 + ↓ 往下移動一行 (ESC-.),^T 移到檔案結尾 + ^B,PgUp 往上移動一頁 ^F,PgDn 往下移動一頁 + ^S 尋找字串 (ESC-L) 跳至指定行 + (ESC-n) 再往後找 (ESC-p) 再往前找 + (ESC-]) 尋找對稱括弧 (ESC-x) 回到前一位置 + (ESC-f) 往前一字 (ESC-b) 後退一字 + 【刪除插入指令】 + ^D,Del 刪除目前的字元 ^H,BS 刪除前一個字元 + ^K 刪除游標之後至行尾 ^Y 刪除目前這行 + ^O,Ins 切換 插入/覆蓋 + (ESC-d) 刪除一字 (ESC-0~9) 貼上暫存檔 0-9 + + 【ANSI│黑紅綠黃藍紫靛白】 + + 前景│3031323334353637 + 背景│4041424344454647 + Ctrl-V: 切換 ANSI-color 模式,「所見即所得」,可立即編修 + Ctrl-C: 「直覺式」插入彩色碼,可輕易為文字「著色」 (in ANSI-color mode) + 支援 ANSI color 編輯模式... 不只是預覽而已 + 同時, ctrl-C 在 ANSI mode 下可以輸入顏色... + 有三種模式.... + w 代表 白字 + wb 代表白字黑底 + 1wb 代表高亮白字黑底.. + 支援 overwrite & insert , 可輕易編輯類似 Welcome 畫面 + 因某種原因, 取消在 ansi editing 下的 backspace功能:P + 【區塊處理命令】 + (ESC-l), (ESC-SPACE) 設定標記區 + ^W Cut, 把標記區剪至暫存檔 0 + (ESC-c) Copy, 把標記區拷貝至暫存檔 0 + 或者再按一次(ESC-SPACE)確定標記區範圍,確定範圍後: + 0: Cut, 把標記區剪至暫存檔 0 + 5: Copy, 把標記區拷貝至暫存檔 5 + 6-9: Cut or Copy + q: 取消 + 當需要刪「很多」行時,試試 ESC-SPC 吧 :> + 若需要把文章堛滿u部分」取出時,ESC-SPC 也適用。 + (ESC-0/5) Paste, 直接貼上暫存檔 0/5 + (ESC-6-9) 貼上暫存檔 6-9 ,貼上前先預覽 + (ESC-j) 將標記區往左移 + (ESC-k) 將標記區往右移 + (ESC-u) 取消標記區 + 【特殊指令】 + ^U 輸入 ESC 碼(以 * 表示) ^C 還原/設定 ANSI 色彩 + (ESC-y) 救回誤刪行 ^_(Ctrl-/),(ESC--) 復原目前行 + (ESC-A) 切換ANSI彩色模式 (ESC-I) 切換縮排(indent)模式 + (ESC-P) 切換注音直接打模式 (ESC-R) 切換 modem ASCII 上傳模式 + ^R 顯示上次扣應訊息 (ESC-U) 使用者列表 + (ESC-i) 進入發呆模式 + + +> -------------------------------------------------------------------------- < + + ASCⅡ上色基礎教學 + + <<<<<<<<<<<<<<<<<<<<<<<< $ 教 學 開 始 $ >>>>>>>>>>>>>>>>>>>>>>>>>>>> +  首先,告訴你一件最重要的事,在往後的教學中所有的 * 號都是按 Esc 鍵 +  兩次產生的,以其他方式,如:直接按 * 號,所產生的都無法執行。 +  對了, * 號產生的方式在聯工是按 Esc 兩次,但在其他地方可就不一定了 +  ,可能是 Ctrl + U 產生的,總之,若不清楚,按 Ctrl + Z 線上輔助說明看看 +  就知道了,反正,現在的你,應該是只有在聯工上玩吧!所以,就以聯工的方式 +  教你,以後有到別站時,再教你吧! +  先告訴你一些基本的色彩控制參數:(記住!m 一定是小寫!!) + 參 數 色彩 舉 例 說 明 + --------- ------ ---------------------------------------------- +  ############ 以下為暗色系列的前景色彩 ############ + *[0;30m  黑色  *[0;30;47m測試一下 ==> 測試一下 + *[0;31m  紅色  *[0;31m測試一下 ==> 測試一下 + *[0;32m  綠色  *[0;32m測試一下 ==> 測試一下 + *[0;33m  土棕色 *[0;33m測試一下 ==> 測試一下 + *[0;34m  深藍  *[0;34m測試一下 ==> 測試一下 + *[0;35m  紫色  *[0;35m測試一下 ==> 測試一下 + *[0;36m  淺藍  *[0;36m測試一下 ==> 測試一下 + *[0;37m  白色  *[0;37m測試一下 ==> 測試一下 +  ############ 以下為亮色系列的前景色彩 ############ + *[1;30m  深灰色 *[1;30m測試一下 ==> 測試一下 + *[1;31m  亮紅色 *[1;31m測試一下 ==> 測試一下 + *[1;32m  亮綠色 *[1;32m測試一下 ==> 測試一下 + *[1;33m  黃色  *[1;33m測試一下 ==> 測試一下 + *[1;34m  亮深藍 *[1;34m測試一下 ==> 測試一下 + *[1;35m  亮紫色 *[1;35m測試一下 ==> 測試一下 + *[1;36m  亮淺藍 *[1;36m測試一下 ==> 測試一下 + *[1;37m  亮白色 *[1;37m測試一下 ==> 測試一下 +  ############## 以 下 為 背 景 色 彩 ############## +  ############# 所有文字顏色皆以黃色顯示 ########### + *[1;33;40m 黑色  *[1;33;40m測試一下 ==> 測試一下 + *[1;33;41m 紅色  *[1;33;41m測試一下 ==> 測試一下 + *[1;33;42m 綠色  *[1;33;42m測試一下 ==> 測試一下 + *[1;33;43m 棕色  *[1;33;43m測試一下 ==> 測試一下 + *[1;33;44m 深藍  *[1;33;44m測試一下 ==> 測試一下 + *[1;33;45m 紫色  *[1;33;45m測試一下 ==> 測試一下 + *[1;33;46m 淺藍  *[1;33;46m測試一下 ==> 測試一下 + *[1;33;47m 白色  *[1;33;47m測試一下 ==> 測試一下 +  以上的所有舉例皆是修飾過後的結果,若真照舉例寫,不但沒達到原先預期 +  效果,反而可能會導致天下大亂。前景(即文字部份)和背景(即底色)的修飾方式 +  不一樣,先說前景的修飾方式。 +  再舉個例吧!將 "測試一下" 上色,之後的都不上色,若 *[1;33m測試一下 +  這種寫法,其後面所有的文字都會變成黃色: +  + *[1;33m測試一下xxxx ==> 測試一下xxxx +  會產生如上結果,若要將 xxxx 變回原色,則可: +  + *[1;33m測試一下*[mxxxx ==> 測試一下xxxx +  加個 *[m 或 *[0m 就可以解決,但若想把 xxxx 變成其他顏色,則: +  + *[1;33m測試一下*[0;36mxxxx ==> 測試一下xxxx +  總之,在想改變色彩的部份加上想改變的色彩參數;在想停止上色的地方加 +  上 *[m 或 *[0m 即可! +  以上,為前景色的修飾方式,接著,說說背景色的修飾方式,說完就下課了 +  唷! +  背景色的寫法很奇怪,以下舉例說明一下: +  + *[1;33;43m測試一下*[m ==> 測試一下 + *[1;33;43m 測試一下*[m ==>  測試一下 + *[1;33;43m 測試一下 *[m ==>  測試一下  +  它會因為你參數的位置不同,而產生不同的結果,以此特性,將背景色多加活 +  用,你也能做出出色的簽名檔、計畫檔....等。 +  好啦!下課囉!開始做些試驗吧!看看有哪裡還不懂的,再告訴我!^_^ + <<<<<<<<<<<<<<<<<<<<<<<<<<<<< $ E N D $ >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> diff --git a/pttbbs/sample/innd/Makefile b/pttbbs/sample/innd/Makefile new file mode 100644 index 00000000..853ba0db --- /dev/null +++ b/pttbbs/sample/innd/Makefile @@ -0,0 +1,9 @@ +BBSHOME?=$(HOME) +TARGET=$(BBSHOME)/innd/ +FILES=bbsname.bbs newsfeeds.bbs nodelist.bbs ntu.active + +all: + +install: + install -d $(TARGET) + install -c -m 644 $(FILES) $(TARGET) diff --git a/pttbbs/sample/innd/bbsname.bbs b/pttbbs/sample/innd/bbsname.bbs new file mode 100644 index 00000000..72db534d --- /dev/null +++ b/pttbbs/sample/innd/bbsname.bbs @@ -0,0 +1 @@ +ptt2 diff --git a/pttbbs/sample/innd/newsfeeds.bbs b/pttbbs/sample/innd/newsfeeds.bbs new file mode 100644 index 00000000..c32b8042 --- /dev/null +++ b/pttbbs/sample/innd/newsfeeds.bbs @@ -0,0 +1,3 @@ +# newsgroups board news server +#------------------------------------- -------------- ----------- +#tw.bbs.test test ntu diff --git a/pttbbs/sample/innd/nodelist.bbs b/pttbbs/sample/innd/nodelist.bbs new file mode 100644 index 00000000..d5784970 --- /dev/null +++ b/pttbbs/sample/innd/nodelist.bbs @@ -0,0 +1,4 @@ +# name hostname & domainname full name +#------- ---------------------------------- ------------ +#ptt2 ptt2.csie.ntu.edu.tw IHAVE(7777) Ptt2 +#ntu news.ntu.edu.tw POST(119) NTU News Server diff --git a/pttbbs/sample/innd/ntu.active b/pttbbs/sample/innd/ntu.active new file mode 100644 index 00000000..3825d9ea --- /dev/null +++ b/pttbbs/sample/innd/ntu.active @@ -0,0 +1 @@ +tw.bbs.chat 0000000000 0000000000 y diff --git a/pttbbs/sample/pttbbs.conf b/pttbbs/sample/pttbbs.conf new file mode 100644 index 00000000..343c0299 --- /dev/null +++ b/pttbbs/sample/pttbbs.conf @@ -0,0 +1,10 @@ +/* 定義 BBS 站名位址 */ + +#define BBSNAME "新批踢踢" /* 中文站名 */ +#define MYHOSTNAME "ptt2.twbbs.org.tw" /* 網路位址 */ +#define MYIP "140.112.8.192" /* IP位址 */ +#define BBSUSER "bbs" +#define BBSUID 9999 +#define BBSGID 99 + +#define MAX_USERS 10000 diff --git a/pttbbs/sample/rc.local b/pttbbs/sample/rc.local new file mode 100644 index 00000000..8fd6c714 --- /dev/null +++ b/pttbbs/sample/rc.local @@ -0,0 +1,4 @@ +#!/bin/sh +/usr/bin/su bbsadm -c /home/bbs/bin/uhash_loader +/usr/bin/su bbsadm -c /home/bbs/bin/outmail& +/usr/bin/su bbsadm -c /home/bbs/innd/innbbsd 7777 diff --git a/pttbbs/util/.cvsignore b/pttbbs/util/.cvsignore new file mode 100644 index 00000000..e7408563 --- /dev/null +++ b/pttbbs/util/.cvsignore @@ -0,0 +1,42 @@ +bbsmail +BM_money +post +account +birth +deluserfile +expire +mandex +horoscope +openvice +parse_news +openticket +bmda +uhash_loader +poststat +showboard +topusr +yearsold +cutpasswd +inndBM +antispam +countalldice +webgrep +bbsrf +initbbs +outmail +xchatd +userlist +tunepasswd +buildir +reaper +shmsweep +merge_passwd +merge_board +cpdeadbrd +rmuid +buildAnnounce +toplazyBBM +toplazyBM +jungo +bbsctl +daymandex diff --git a/pttbbs/util/BM_money.c b/pttbbs/util/BM_money.c new file mode 100644 index 00000000..51e24c38 --- /dev/null +++ b/pttbbs/util/BM_money.c @@ -0,0 +1,117 @@ +/* $Id: BM_money.c,v 1.1 2002/03/07 15:13:45 in2 Exp $ */ + +/* 給版主錢的程式 */ + +#include +#include +#include +#include +#include +#include "config.h" +#include "pttstruct.h" +#include "util.h" +#include "common.h" + +#define FUNCTION (2100 - c*5) + +extern int numboards; +extern boardheader_t *bcache; +extern struct UCACHE *uidshm; + +int c, n; +extern userec_t xuser; + + + +int Link(char *src, char *dst) { + char cmd[200]; + + if (link(src, dst) == 0) + return 0; + + sprintf(cmd, "/bin/cp -R %s %s", src, dst); + return system(cmd); +} + + +int main() { + FILE *fp = fopen(BBSHOME "/etc/topboardman", "r"); + char buf[201], bname[20], BM[90], *ch; + boardheader_t *bptr = NULL; + int nBM; + + resolve_boards(); + if(passwd_mmap()) + exit(1); + if (!fp) + return 0; + + c = 0; + fgets(buf, 200, fp); /* 第一行拿掉 */ + + printf( + " \033[1;44m 獎勵優良版主 每週花薪 依精華區排名分配 \033[m\n\n" + "\033[33m (排名太後面或幾乎沒有精華區者不列入)\033[m\n" + " ─────────────────────────────────────\n" + "\n\n"); + + while (fgets(buf, 200, fp) != NULL) + { + buf[24] = 0; + sscanf(&buf[9], "%s", bname); + for (n = 0; n < numboards; n++) + { + bptr = &bcache[n]; + if (!strcmp(bptr->brdname, bname)) + break; + } + if (n == numboards) + continue; + strcpy(BM, bptr->BM); + printf(" (%d) %-15.15s %s \n", c + 1, bptr->brdname, bptr->title); + + if (BM[0] == 0 || BM[0] == ' ') + continue; + + ch = BM; + for (nBM = 1; (ch = strchr(ch, '/')) != NULL; nBM++) + { + ch++; + }; + ch = BM; + + if (FUNCTION <= 0) + break; + + printf(" 獎金 \033[32m%6d \033[m 分給 \033[33m%s\033[m \n", + FUNCTION, bptr->BM); + + for (n = 0; n < nBM; n++) + { + fileheader_t mymail; + char *ch1,uid ; + if((ch1 = strchr(ch, '/'))) + *ch1 = 0; + if ((uid=getuser(ch))!=0) + { + + char genbuf[200]; + deumoney(uid,FUNCTION / nBM); + sprintf(genbuf, BBSHOME "/home/%c/%s", ch[0], ch); + stampfile(genbuf, &mymail); + + strcpy(mymail.owner, "[薪水袋]"); + sprintf(mymail.title, + "\033[32m %s \033[m版的薪水 $\033[33m%d\033![m", bptr->brdname, FUNCTION / nBM); + mymail.savemode = 0; + unlink(genbuf); + Link(BBSHOME "/etc/BM_money", genbuf); + sprintf(genbuf, BBSHOME "/home/%c/%s/.DIR", ch[0], ch); + append_record(genbuf, &mymail, sizeof(mymail)); + } + ch = ch1 + 1; + } + c++; + } + return 0; +} diff --git a/pttbbs/util/BM_money.sh b/pttbbs/util/BM_money.sh new file mode 100644 index 00000000..8bef4fc9 --- /dev/null +++ b/pttbbs/util/BM_money.sh @@ -0,0 +1,5 @@ +#!/bin/sh +# $Id: BM_money.sh,v 1.1 2002/03/07 15:13:45 in2 Exp $ + +bin/BM_money > etc/BM_money +bin/post Record 星期五' '版主發薪日 [財金消息] etc/BM_money diff --git a/pttbbs/util/BOARDS.bid b/pttbbs/util/BOARDS.bid new file mode 100644 index 00000000..8d0312e5 Binary files /dev/null and b/pttbbs/util/BOARDS.bid differ diff --git a/pttbbs/util/DEADJOE b/pttbbs/util/DEADJOE new file mode 100644 index 00000000..a0793f05 --- /dev/null +++ b/pttbbs/util/DEADJOE @@ -0,0 +1,9 @@ + +*** Modified files in JOE when it aborted on Thu Nov 22 19:30:21 2001 +*** JOE was aborted by signal 1 + +*** Modified files in JOE when it aborted on Mon Nov 26 09:50:15 2001 +*** JOE was aborted because the terminal closed + +*** File '(Unnamed)' +BBSNAME diff --git a/pttbbs/util/LocalVars.pm.sample b/pttbbs/util/LocalVars.pm.sample new file mode 100644 index 00000000..67157009 --- /dev/null +++ b/pttbbs/util/LocalVars.pm.sample @@ -0,0 +1,22 @@ +#!/usr/bin/perl +package LocalVars; +require Exporter; +@ISA = qw/Exporter/; +@EXPORT = qw/ + $hostname $FQDN $SMTPSERVER + $BBSHOME $JOBSPOOL $TMP + $TAR/; + +# host +$hostname = 'ptt'; +$FQDN = 'ptt.csie.ntu.edu.tw'; +$SMTPSERVER = 'ptt2.csie.ntu.edu.tw'; + +# dir +$BBSHOME = '/home/bbs'; +$JOBSPOOL = "$BBSHOME/jobspool"; +$TMP = '/tmp'; + +# program +$TAR = '/bin/tar'; + diff --git a/pttbbs/util/Makefile b/pttbbs/util/Makefile new file mode 100644 index 00000000..eeacad38 --- /dev/null +++ b/pttbbs/util/Makefile @@ -0,0 +1,167 @@ +# $Id: Makefile,v 1.1 2002/03/07 15:13:45 in2 Exp $ + +BBSHOME?=$(HOME) +OSTYPE=linux + +# FreeBSD +CC_FreeBSD= gcc +CFLAGS_FreeBSD= -pipe -Wall -g -O3 -DHAVE_SETPROCTITLE -DBBSHOME='"$(BBSHOME)"' -I../include +LIBS_FreeBSD= +LIBMAIL_FreeBSD=-lutil +LIBCHAT_FreeBSD= + +# Linux +CC_linux= gcc +CFLAGS_linux= -pipe -Wall -g -O3 -DHAVE_DES_CRYPT -DBBSHOME='"$(BBSHOME)"' -I../include +LIBS_linux= -lresolv +LIBMAIL_linux= +LIBCHAT_linux= -lcrypt + +CC= $(CC_$(OSTYPE)) +CFLAGS= $(CFLAGS_$(OSTYPE)) +LDFLAGS=$(LDFLAGS_$(OSTYPE)) +LIBMAIL=$(LIBMAIL_$(OSTYPE)) +LIBCHAT=$(LIBCHAT_$(OSTYPE)) + +OBJS= util_cache.o util_record.o util_passwd.o + +CPROGS= bbsmail BM_money post account birth deluserfile expire mandex\ + horoscope openvice parse_news openticket topusr yearsold uhash_loader\ + poststat showboard antispam countalldice webgrep bbsrf\ + initbbs outmail xchatd userlist tunepasswd buildir reaper shmsweep\ + merge_passwd merge_board inndBM buildAnnounce rmuid cpdeadbrd \ + toplazyBM jungo toplazyBBM daymandex + +PROGS= $(CPROGS) BM_money.sh backpasswd.sh mailog.sh opendice.sh\ + openticket.sh stock.sh topsong.sh weather.sh stock.perl weather.perl\ + toplazyBM.sh toplazyBBM.sh dailybackup.pl tarqueue.pl waterball.pl + +all: $(PROGS) + +bbsmail: bbsmail.c $(OBJS) + $(CC) $(CFLAGS) -o $@ $@.c $(OBJS) + +BM_money: BM_money.c $(OBJS) + $(CC) $(CFLAGS) -o $@ $@.c $(OBJS) + +post: post.c $(OBJS) + $(CC) $(CFLAGS) -o $@ $@.c $(OBJS) + +jungo: jungo.c $(OBJS) + $(CC) $(CFLAGS) -o $@ $@.c $(OBJS) + +account: account.c $(OBJS) + $(CC) $(CFLAGS) -o $@ $@.c $(OBJS) + +birth: birth.c $(OBJS) + $(CC) $(CFLAGS) -o $@ $@.c $(OBJS) + +deluserfile: deluserfile.c $(OBJS) + $(CC) $(CFLAGS) -o $@ $@.c $(OBJS) + +expire: expire.c $(OBJS) + $(CC) $(CFLAGS) -o $@ $@.c $(OBJS) + +mandex: mandex.c $(OBJS) + $(CC) $(CFLAGS) -o $@ $@.c $(OBJS) + +daymandex: daymandex.c $(OBJS) + $(CC) $(CFLAGS) -o $@ $@.c $(OBJS) + +rmuid: rmuid.c $(OBJS) + $(CC) $(CFLAGS) -o $@ $@.c $(OBJS) + +cpdeadbrd: cpdeadbrd.c $(OBJS) + $(CC) $(CFLAGS) -o $@ $@.c $(OBJS) + +horoscope: horoscope.c $(OBJS) + $(CC) $(CFLAGS) -o $@ $@.c $(OBJS) + +openvice: openvice.c $(OBJS) + $(CC) $(CFLAGS) -o $@ $@.c $(OBJS) + +parse_news: parse_news.c $(OBJS) + $(CC) $(CFLAGS) -o $@ $@.c $(OBJS) + +openticket: openticket.c $(OBJS) + $(CC) $(CFLAGS) -o $@ $@.c $(OBJS) + +topusr: topusr.c $(OBJS) + $(CC) $(CFLAGS) -o $@ $@.c $(OBJS) + +yearsold: yearsold.c $(OBJS) + $(CC) $(CFLAGS) -o $@ $@.c $(OBJS) + +xchatd: xchatd.c $(OBJS) descrypt.c + $(CC) $(CFLAGS) -o $@ $@.c $(OBJS) descrypt.c $(LIBCHAT) + +toplazyBM: toplazyBM.c $(OBJS) + $(CC) $(CFLAGS) -o $@ $@.c $(OBJS) + +toplazyBBM: toplazyBBM.c $(OBJS) + $(CC) $(CFLAGS) -o $@ $@.c $(OBJS) + +smtest: smtest.c $(OBJS) + $(CC) $(CFLAGS) -o $@ $@.c $(OBJS) + +reaper: reaper.c $(OBJS) + $(CC) $(CFLAGS) -o $@ $@.c $(OBJS) + +buildAnnounce: buildAnnounce.c $(OBJS) + $(CC) $(CFLAGS) -o $@ $@.c $(OBJS) + +inndBM: inndBM.c $(OBJS) + $(CC) $(CFLAGS) -o $@ $@.c $(OBJS) + +shmsweep: shmsweep.c + $(CC) $(CFLAGS) -o $@ $@.c + +uhash_loader: uhash_loader.c + $(CC) $(CFLAGS) -o $@ $@.c + +showboard: showboard.c + $(CC) $(CFLAGS) -o $@ $@.c + +antispam: antispam.c + $(CC) $(CFLAGS) -o $@ $@.c + +countalldice: countalldice.c + $(CC) $(CFLAGS) -o $@ $@.c + +webgrep: webgrep.c + $(CC) $(CFLAGS) -o $@ $@.c + +bbsrf: bbsrf.c + $(CC) $(CFLAGS) -o $@ $@.c + +initbbs: initbbs.c + $(CC) $(CFLAGS) -o $@ $@.c + +outmail: outmail.c + $(CC) $(CFLAGS) -o $@ $@.c $(LIBMAIL) + +userlist: userlist.c + $(CC) $(CFLAGS) -o $@ $@.c + +tunepasswd: tunepasswd.c + $(CC) $(CFLAGS) -o $@ $@.c + +buildir: buildir.c + $(CC) $(CFLAGS) -o $@ $@.c + +merge_passwd: merge_passwd.c + $(CC) $(CFLAGS) -o $@ $@.c + +merge_board : merge_board.c + $(CC) $(CFLAGS) -o $@ $@.c + +bbsctl: bbsctl.c + $(CC) $(CFLAGS) -o $@ $@.c + +install: $(PROGS) + install -d $(BBSHOME)/bin/ + install -c -m 755 $(PROGS) $(BBSHOME)/bin/ + chmod 4755 $(BBSHOME)/bin/post + +clean: + rm -f *.o $(CPROGS) diff --git a/pttbbs/util/Makefile.save b/pttbbs/util/Makefile.save new file mode 100644 index 00000000..2d0651b1 --- /dev/null +++ b/pttbbs/util/Makefile.save @@ -0,0 +1,152 @@ +# $Id: Makefile.save,v 1.1 2002/03/07 15:13:45 in2 Exp $ + +BBSHOME?=$(HOME) +OSTYPE=linux + +# FreeBSD +CC_FreeBSD= gcc +CFLAGS_FreeBSD= -pipe -Wall -g -O3 -DHAVE_SETPROCTITLE -DBBSHOME='"$(BBSHOME)"' -I../include +LIBS_FreeBSD= +LIBMAIL_FreeBSD=-lutil +LIBCHAT_FreeBSD= + +# Linux +CC_linux= gcc +CFLAGS_linux= -pipe -Wall -g -O3 -DHAVE_DES_CRYPT -DBBSHOME='"$(BBSHOME)"' -I../include +LIBS_linux= -lresolv +LIBMAIL_linux= +LIBCHAT_linux= -lcrypt + +CC= $(CC_$(OSTYPE)) +CFLAGS= $(CFLAGS_$(OSTYPE)) +LDFLAGS=$(LDFLAGS_$(OSTYPE)) +LIBMAIL=$(LIBMAIL_$(OSTYPE)) +LIBCHAT=$(LIBCHAT_$(OSTYPE)) + +CPROGS= bbsmail BM_money post account birth deluserfile expire mandex\ + horoscope openvice parse_news openticket topusr yearsold uhash_loader\ + poststat showboard antispam countalldice webgrep bbsrf\ + initbbs outmail xchatd userlist tunepasswd buildir reaper shmsweep\ + merge_passwd merge_board inndBM buildAnnounce cpdeadbrd toplazyBM\ + jungo +PROGS= $(CPROGS) BM_money.sh backpasswd.sh mailog.sh opendice.sh\ + openticket.sh stock.sh topsong.sh weather.sh stock.perl weather.perl\ + cvslog.sh toplazyBM.sh + +all: $(PROGS) + +bbsmail: bbsmail.c util_cache.c util_record.c util_passwd.c + $(CC) $(CFLAGS) -o $@ $@.c util_cache.c util_record.c util_passwd.c + +BM_money: BM_money.c util_cache.c util_record.c util_passwd.c + $(CC) $(CFLAGS) -o $@ $@.c util_cache.c util_record.c util_passwd.c + +post: post.c util_cache.c util_record.c util_passwd.c + $(CC) $(CFLAGS) -o $@ $@.c util_cache.c util_record.c util_passwd.c + +account: account.c util_cache.c util_record.c util_passwd.c + $(CC) $(CFLAGS) -o $@ $@.c util_cache.c util_record.c util_passwd.c + +birth: birth.c util_cache.c util_record.c util_passwd.c + $(CC) $(CFLAGS) -o $@ $@.c util_cache.c util_record.c util_passwd.c + +deluserfile: deluserfile.c util_cache.c util_record.c util_passwd.c + $(CC) $(CFLAGS) -o $@ $@.c util_cache.c util_record.c util_passwd.c + +expire: expire.c util_cache.c util_record.c util_passwd.c + $(CC) $(CFLAGS) -o $@ $@.c util_cache.c util_record.c util_passwd.c + +mandex: mandex.c util_cache.c util_record.c util_passwd.c + $(CC) $(CFLAGS) -o $@ $@.c util_cache.c util_record.c util_passwd.c + +cpdeadbrd: cpdeadbrd.c util_cache.c util_record.c util_passwd.c + $(CC) $(CFLAGS) -o $@ $@.c util_cache.c util_record.c util_passwd.c + +horoscope: horoscope.c util_cache.c util_record.c util_passwd.c + $(CC) $(CFLAGS) -o $@ $@.c util_cache.c util_record.c util_passwd.c + +openvice: openvice.c util_cache.c util_record.c util_passwd.c + $(CC) $(CFLAGS) -o $@ $@.c util_cache.c util_record.c util_passwd.c + +parse_news: parse_news.c util_cache.c util_record.c util_passwd.c + $(CC) $(CFLAGS) -o $@ $@.c util_cache.c util_record.c util_passwd.c + +openticket: openticket.c util_cache.c util_record.c util_passwd.c + $(CC) $(CFLAGS) -o $@ $@.c util_cache.c util_record.c util_passwd.c + +topusr: topusr.c util_cache.c util_record.c util_passwd.c + $(CC) $(CFLAGS) -o $@ $@.c util_cache.c util_record.c util_passwd.c + +yearsold: yearsold.c util_cache.c util_record.c util_passwd.c + $(CC) $(CFLAGS) -o $@ $@.c util_cache.c util_record.c util_passwd.c + +xchatd: xchatd.c util_cache.c util_record.c util_passwd.c descrypt.c + $(CC) $(CFLAGS) -o $@ $@.c util_cache.c util_record.c util_passwd.c descrypt.c $(LIBCHAT) + +toplazyBM: toplazyBM.c util_cache.c util_record.c util_passwd.c + $(CC) $(CFLAGS) -o $@ $@.c util_cache.c util_record.c util_passwd.c + +jungo: jungo.c util_cache.c util_record.c util_passwd.c + $(CC) $(CFLAGS) -o $@ $@.c util_cache.c util_record.c util_passwd.c + +smtest: smtest.c util_cache.c util_record.c util_passwd.c + $(CC) $(CFLAGS) -o $@ $@.c util_cache.c util_record.c util_passwd.c + +reaper: reaper.c util_passwd.c + $(CC) $(CFLAGS) -o $@ $@.c util_passwd.c util_cache.c util_passwd.c + +buildAnnounce: buildAnnounce.c + $(CC) $(CFLAGS) -o $@ $@.c util_record.c util_cache.c util_passwd.c + +inndBM: inndBM.c + $(CC) $(CFLAGS) -o $@ $@.c util_record.c util_cache.c util_passwd.c + +shmsweep: shmsweep.c + $(CC) $(CFLAGS) -o $@ $@.c + +uhash_loader: uhash_loader.c + $(CC) $(CFLAGS) -o $@ $@.c + +showboard: showboard.c + $(CC) $(CFLAGS) -o $@ $@.c + +antispam: antispam.c + $(CC) $(CFLAGS) -o $@ $@.c + +countalldice: countalldice.c + $(CC) $(CFLAGS) -o $@ $@.c + +webgrep: webgrep.c + $(CC) $(CFLAGS) -o $@ $@.c + +bbsrf: bbsrf.c + $(CC) $(CFLAGS) -o $@ $@.c + +initbbs: initbbs.c + $(CC) $(CFLAGS) -o $@ $@.c + +outmail: outmail.c + $(CC) $(CFLAGS) -o $@ $@.c $(LIBMAIL) + +userlist: userlist.c + $(CC) $(CFLAGS) -o $@ $@.c + +tunepasswd: tunepasswd.c + $(CC) $(CFLAGS) -o $@ $@.c + +buildir: buildir.c + $(CC) $(CFLAGS) -o $@ $@.c + +merge_passwd: merge_passwd.c + $(CC) $(CFLAGS) -o $@ $@.c + +merge_board : merge_board.c + $(CC) $(CFLAGS) -o $@ $@.c + +install: $(PROGS) + install -d $(BBSHOME)/bin/ + install -c -m 755 $(PROGS) $(BBSHOME)/bin/ + chmod 4755 $(BBSHOME)/bin/post + +clean: + rm -f $(CPROGS) diff --git a/pttbbs/util/a.out b/pttbbs/util/a.out new file mode 100644 index 00000000..f4032dc4 Binary files /dev/null and b/pttbbs/util/a.out differ diff --git a/pttbbs/util/account.c b/pttbbs/util/account.c new file mode 100644 index 00000000..e4166092 --- /dev/null +++ b/pttbbs/util/account.c @@ -0,0 +1,414 @@ +/* $Id: account.c,v 1.1 2002/03/07 15:13:45 in2 Exp $ */ +#include +#include +#include +#include +#include +#include +#include "config.h" +#include "pttstruct.h" +#include "util.h" + +#define MAX_LINE 16 +#define ADJUST_M 6 /* adjust back 5 minutes */ + +extern struct pttcache_t *ptt; + +void + reset_garbage() +{ + if (ptt == NULL) + { + ptt = attach_shm(PTTSHM_KEY, sizeof(*ptt)); + if (ptt->touchtime == 0) + ptt->touchtime = 1; + } + +/* 不整個reload? + for(n=0;n<=ptt->max_film;n++) + printf("\n**%d**\n %s \n",n,ptt->notes[n]); + */ + ptt->uptime = 0; + reload_pttcache(); + + printf("\n動態看板數[%d]\n", ptt->max_film); +/* + for(n=0; n 起點:%d 下次要換的:%d\n ",n,ptt->n_notes[n], + ptt->next_refresh[n]); + printf("\n"); +*/ +} + +void +keeplog(fpath, board, title) + char *fpath; + char *board; + char *title; +{ + fileheader_t fhdr; + int bid; + char genbuf[256], buf[256]; + + if (!board) + board = "Record"; + + + sprintf(genbuf, "boards/%s", board); + stampfile(genbuf, &fhdr); + sprintf(buf, "mv %s %s", fpath, genbuf); + system(buf); +/* + printf("keep record:[%s][%s][%s][%s]\n",fpath, board, title,genbuf); +*/ + strcpy(fhdr.title, title); + strcpy(fhdr.owner, "[歷史老師]"); + sprintf(genbuf, "boards/%s/.DIR", board); + append_record(genbuf, &fhdr, sizeof(fhdr)); + if((bid = getbnum(board)) > 0)touchbtotal(bid); + +} + + +static void +my_outs(fp, buf, mode) + FILE *fp; + char buf[], mode; +{ + static char state = '0'; + + if (state != mode) + fprintf(fp, "[3%cm", state = mode); + if (buf[0]) + { + fprintf(fp, buf); + buf[0] = 0; + } +} + + +void gzip(source, target, stamp) + char *source, *target, *stamp; +{ + char buf[128]; + sprintf(buf, "gzip -f9n adm/%s%s", target, stamp); + rename(source, &buf[14]); + system(buf); +} + +extern struct fromcache_t *fcache; +extern uhash_t *uhash; + +int main() { + int hour, max, item, total, i, j, mo, da, max_user = 0, max_login = 0, + max_reg = 0, mahour = 0, k; + char *act_file = ".act"; + char *log_file = "usies"; + char buf[256], buf1[256], *p; + FILE *fp, *fp1; + int act[27]; /* 次數/累計時間/pointer */ + time_t now; + struct tm *ptime; + + now = time(NULL) - ADJUST_M * 60; /* back to ancent */ + ptime = localtime(&now); + + memset(act, 0, sizeof(act)); + printf("次數/累計時間\n"); + if ((ptime->tm_hour != 0) && (fp = fopen(act_file, "r"))) + { + fread(act, sizeof(act), 1, fp); + fclose(fp); + } + if ((fp = fopen(log_file, "r")) == NULL) + { + printf("cann't open usies\n"); + return 1; + } + if (act[26]) + fseek(fp, act[26], 0); + while (fgets(buf, 256, fp)) + { + buf[11+2]=0; + hour = atoi(buf + 11); + if (hour < 0 || hour > 23) + { + continue; + } +//"09/06/1999 17:44:58 Mon " +// 012345678901234567890123 + if (strstr(buf + 20, "ENTER")) + { + act[hour]++; + continue; + } + if ((p = (char *) strstr(buf + 40, "Stay:"))) + { + if((hour = atoi(p + 5))) { + act[24] += hour; + act[25]++; + } + continue; + } + } + act[26] = ftell(fp); + fclose(fp); + for (i = max = total = 0; i < 24; i++) + { + total += act[i]; + if (act[i] > max) + { + max_user = max = act[i]; + mahour = i; + } + } + item = max / MAX_LINE + 1; + + if (!ptime->tm_hour) + { + keeplog("etc/today", "Record", "上站人次統計"); + keeplog("etc/money", "Security", "本日金錢往來記錄"); + keeplog("etc/illegal_money", "Security", "本日違法賺錢記錄"); + keeplog("etc/chicken", "Record", "雞場報告"); + } + + printf("上站人次統計\n"); + if ((fp = fopen("etc/today", "w")) == NULL) + { + printf("cann't open etc/today\n"); + return 1; + } + fprintf(fp, "\t\t\t 每小時上站人次統計 [%02d/%02d/%02d] \n\n", ptime->tm_year % 100, ptime->tm_mon + 1, ptime->tm_mday); + for (i = MAX_LINE + 1; i > 0; i--) + { + strcpy(buf, " "); + for (j = 0; j < 24; j++) + { + max = item * i; + hour = act[j]; + if (hour && (max > hour) && (max - item <= hour)) + { + my_outs(fp, buf, '3'); + fprintf(fp, "%-3d", hour / 10); + } + else if (max <= hour) + { + my_outs(fp, buf, '4'); + fprintf(fp, "█ "); + } + else + strcat(buf, " "); + } + fprintf(fp, "\n"); + } + fprintf(fp, " " + "0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23\n\n" + "\t 單位: 10 人"); + fprintf(fp, " 總共上站人次:%-7d平均使用人數:%d\n", total, total / 24); + fclose(fp); + + if((fp = fopen(act_file, "w"))) { + fwrite(act, sizeof(act), 1, fp); + fclose(fp); + } + +/* -------------------------------------------------------------- */ + + sprintf(buf, "-%02d%02d%02d", + ptime->tm_year % 100, ptime->tm_mon + 1, ptime->tm_mday); + + now += ADJUST_M * 60; /* back to future */ + + + printf("歷史事件處理\n"); +/* Ptt 歷史事件處理 */ + if((fp = fopen("etc/history.data", "r"))) { /*最多同時上線 */ + if (fscanf(fp, "%d %d %d %d", &max_login, &max, &max_reg, &k)) + { + int a; + resolve_fcache(); + printf("此時段最多同時上線:%d 過去:%d\n", a = fcache->max_user, k); + fclose(fp); + if (a > k) + { + ptime = localtime(&fcache->max_time); + if((fp1 = fopen("etc/history", "a"))) + { + fprintf(fp1, + "◎ 【%02d/%02d/%02d %02d:%02d】" + "同時在坊內人數首次達到 %d 人次\n", + ptime->tm_mon + 1, ptime->tm_mday, ptime->tm_year % 100, + ptime->tm_hour, ptime->tm_min, a); + fclose(fp1); + } + if((fp = fopen("etc/history.data", "w"))) + { + fprintf(fp, "%d %d %d %d", max_login, max, max_reg, a); + fclose(fp); + } + } + } + else + fclose(fp); + } + ptime = localtime(&now); + + if (ptime->tm_hour) + { + /* rotate one line in today_is */ + puts("多個節日處理"); + if((fp1 = fopen("etc/today_is", "r"))) { + char tod[100][20]; + + i = 0; + while(i < 100 && fgets(tod[i], sizeof(tod[0]), fp1)) + i++; + fclose(fp1); + + fp1 = fopen("etc/today_is", "w"); + for(j = 0; j < i; j++) + fputs(tod[j + 1 < i ? j + 1 : 0], fp1); + fclose(fp1); + } + } + + + if (!ptime->tm_hour) + { + keeplog(".note", "Record", "心情留言版"); + system("/bin/cp etc/today etc/yesterday"); +/* system("rm -f note.dat"); */ +/* Ptt */ + sprintf(buf1, "[公安報告] 使用者上線監控 [%02d/%02d:%02d]" + ,ptime->tm_mon + 1, ptime->tm_mday, ptime->tm_hour); + keeplog("usies", "Security", buf1); + printf("[公安報告] 使用者上線監控\n"); + gzip(log_file, "usies", buf); + printf("壓縮使用者上線監控\n"); +/* Ptt 歷史事件處理 */ + now = time(NULL) - ADJUST_M * 60; /* back to ancent */ + ptime = localtime(&now); + + attach_uhash(); + if((fp = fopen("etc/history.data", "r"))) + { /* 單日最多次人次,同時上線,註冊 */ + if (fscanf(fp, "%d %d %d %d", &max_login, &max, &max_reg, &k)) + { + fp1 = fopen("etc/history", "r+"); + fseek(fp1, 0, 2); + if (max_user > max) + { + fprintf(fp1, "◇ 【%02d/%02d/%02d %02d】 " + "單一小時上線人次首次達到 %d 人次 \n" + ,ptime->tm_mon + 1, ptime->tm_mday, ptime->tm_year % 100, mahour, max_user); + max = max_user; + } + if (total > max_login) + { + fprintf(fp1, "◆ 【%02d/%02d/%02d】 " + "單日上線人次首次達到 %d 人次 \n" + ,ptime->tm_mon + 1, ptime->tm_mday, ptime->tm_year % 100, total); + max_login = total; + } + + if (uhash->number > max_reg + max_reg / 10) + { + fprintf(fp1, "★ 【%02d/%02d/%02d】 " + "總註冊人數提升到 %d 人 \n" + ,ptime->tm_mon + 1, ptime->tm_mday, ptime->tm_year % 100, uhash->number); + max_reg = uhash->number; + } + + fclose(fp1); + } + fclose(fp); + fp = fopen("etc/history.data", "w"); + fprintf(fp, "%d %d %d %d", max_login, max, max_reg, k); + fclose(fp); + } + now += ADJUST_M * 60; /* back to future */ + ptime = localtime(&now); + + /* Ptt 節日處理 */ + printf("節日處理\n"); + if((fp1 = fopen("etc/today_is", "w"))) { + i = 0; + if((fp = fopen("etc/feast", "r"))) { + while(fgets(buf1, sizeof(buf1), fp)) { + if(buf[0] != '#' && + sscanf(buf1, "%d %d ", &mo, &da) == 2) { + if(ptime->tm_mday == da && ptime->tm_mon + 1 == mo) { + i = 1; + fprintf(fp1, "%-14.14s", &buf1[6]); + } + } + } + fclose(fp); + } + printf("節日處理1\n"); + if(i == 0) { + if((fp = fopen("etc/today_boring", "r"))) { + while(fgets(buf1, sizeof(buf1), fp)) + if(strlen(buf) > 3) + fprintf(fp1, "%s", buf1); + fclose(fp); + } else + fprintf(fp1, "本日節日徵求中"); + } + fclose(fp1); + } + + /* Ptt 歡迎畫面處理 */ + printf("歡迎畫面處理\n"); + + if((fp = fopen("etc/Welcome.date", "r"))) + { + char temp[50]; + while (fscanf(fp, "%d %d %s\n", &mo, &da, buf1) != EOF) + { + if (ptime->tm_mday == da && ptime->tm_mon + 1 == mo) + { + strcpy(temp, buf1); + sprintf(buf1, "cp -f etc/Welcomes/%s etc/Welcome", temp); + system(buf1); + break; + } + } + fclose(fp); + } + printf("歡迎畫面處理\n"); + if (ptime->tm_wday == 0) + { + keeplog("etc/week", "Record", "本週熱門話題"); + + gzip("bbslog", "bntplink", buf); + gzip("innd/bbslog", "innbbsd", buf); + gzip("etc/mailog", "mailog", buf); + } + + if (ptime->tm_mday == 1) + keeplog("etc/month", "Record", "本月熱門話題"); + + if (ptime->tm_yday == 1) + keeplog("etc/year", "Record", "年度熱門話題"); + } + else if (ptime->tm_hour == 3 && ptime->tm_wday == 6) + { + char *fn1 = "tmp"; + char *fn2 = "suicide"; + rename(fn1, fn2); + mkdir(fn1, 0755); + sprintf(buf, "tar cfz adm/%s-%02d%02d%02d.tgz %s", + fn2, ptime->tm_year % 100, ptime->tm_mon + 1, ptime->tm_mday, fn2); + system(buf); + sprintf(buf, "/bin/rm -fr %s", fn2); + system(buf); + } +/* Ptt reset Ptt's share memory */ + printf("重設Pttcache 與fcache\n"); + + fcache->uptime = 0; + resolve_fcache(); + reset_garbage(); + return 0; +} diff --git a/pttbbs/util/antispam.c b/pttbbs/util/antispam.c new file mode 100644 index 00000000..f7b77569 --- /dev/null +++ b/pttbbs/util/antispam.c @@ -0,0 +1,122 @@ +/* $Id: antispam.c,v 1.1 2002/03/07 15:13:45 in2 Exp $ */ +/* 抓廣告信的程式 */ +#include +#include +#include +#include +#include "config.h" + +#define WINDOW 100 /* 一次window多少個server */ +#define LEVEL 21 /* 若幾次重復就算廣告信 */ + +#define mailog BBSHOME "/etc/mailog" +#define spamlog BBSHOME "/etc/spam" + +typedef struct sendinfo +{ + char time[18]; + char from[50]; + char userid[20]; + int count; +} +sendinfo; + +int + main() +{ + char buf[200], *from, *userid; + int num = -1, numb = -1, n, nb; + FILE *fp = fopen(mailog, "r"), *fo; + sendinfo data[WINDOW]; + sendinfo bad[WINDOW]; + + unlink(spamlog); + fo = fopen(spamlog, "a"); + memset(data, 0, sizeof(data)); + memset(bad, 0, sizeof(bad)); + + if (!fp || !fo) + return 0; + + while (fgets(buf, 200, fp)) + { + strtok(buf, "\r\n"); + from = strchr(buf, '>') + 2; + userid = strstr(buf, " =>"); + + if (!from || !userid) + continue; + + *userid = 0; + userid += 4; + + if (strstr(from, "MAILER-DAEMON") + || strstr(from, userid)) + continue; /* 退信通知不管 */ + /* 是否已是badhost */ + + for (nb = 0; nb < WINDOW && bad[nb].from[0]; nb++) + if (!strcmp(bad[nb].from, from)) + break; + + if (nb < WINDOW && bad[nb].from[0]) + { + bad[nb].count++; + continue; + } + + /* 簡查過去記錄 */ + + for (n = 0; n < WINDOW && data[n].from[0]; n++) + if (!strcmp(data[n].from, from)) + break; + + if (n < WINDOW && data[n].from[0]) + { + if (!strncmp(data[n].userid, userid, 20)) + continue; + /* 轉給同一個人就不管 */ + strncpy(data[n].userid, userid, 20); + if (++data[n].count >= LEVEL) + { + /* 變成bad 移data到bad 空缺由後一筆資料補上 */ + if (nb >= WINDOW) + { + numb = (numb + 1) % WINDOW; + nb = numb; + fprintf(fo, "%s %s 重覆寄 %d 次\n", + bad[nb].time, bad[nb].from, bad[nb].count); +/* printf(" %s send %d times\n", + bad[nb].from, bad[nb].count); */ + } + memcpy(&bad[nb], &data[n], sizeof(sendinfo)); + memcpy(&data[n], &data[n + 1], sizeof(sendinfo) * (WINDOW - n - 1)); + if (num > n) + num--; + } + } + else + { + if (n >= WINDOW) + { + num = (num + 1) % WINDOW; + n = num; + } +/* printf("[%s] to [%s]\n", from, userid); */ + buf[17] = 0; + strncpy(data[n].time, buf, 17); + strncpy(data[n].from, from, 50); + strncpy(data[n].userid, userid, 20); + } + } + + for (nb = 0; nb < WINDOW && bad[nb].from[0]; nb++) + { + fprintf(fo, "%s %s 重覆寄 %d 次\n", bad[nb].time, + bad[nb].from, bad[nb].count); +/* printf(" %s send %d times\n", bad[nb].from, bad[nb].count); */ + } + fclose(fp); + fclose(fo); + return 0; +} diff --git a/pttbbs/util/backpasswd.sh b/pttbbs/util/backpasswd.sh new file mode 100644 index 00000000..5ec11abd --- /dev/null +++ b/pttbbs/util/backpasswd.sh @@ -0,0 +1,11 @@ +#!/bin/sh +# $Id: backpasswd.sh,v 1.1 2002/03/07 15:13:45 in2 Exp $ + +mv PASSWDS.NEW5 PASSWDS.NEW6 +mv PASSWDS.NEW4 PASSWDS.NEW5 +mv PASSWDS.NEW3 PASSWDS.NEW4 +mv PASSWDS.NEW2 PASSWDS.NEW3 +mv PASSWDS.NEW1 PASSWDS.NEW2 +mv PASSWDS.NEW PASSWDS.NEW1 +cp .PASSWDS PASSWDS.NEW + diff --git a/pttbbs/util/bbsctl.c b/pttbbs/util/bbsctl.c new file mode 100644 index 00000000..bf66df35 --- /dev/null +++ b/pttbbs/util/bbsctl.c @@ -0,0 +1,63 @@ +#include +#include +#include +#include +#include +#include +void usage(void) +{ + printf("usage: bbsctl [start|stop|restart]\n"); + exit(0); +} + +void startbbs(void) +{ + if( setuid(0) < 0 ){ + perror("setuid(0)"); + exit(1); + } + puts("starting mbbsd: 23"); system("/home/bbs/bin/mbbsd 23"); + puts("starting mbbsd:3000"); system("/home/bbs/bin/mbbsd 3000"); + puts("starting mbbsd:3001"); system("/home/bbs/bin/mbbsd 3001"); + puts("starting mbbsd:3002"); system("/home/bbs/bin/mbbsd 3002"); + puts("starting mbbsd:3003"); system("/home/bbs/bin/mbbsd 3003"); + puts("starting mbbsd:3004"); system("/home/bbs/bin/mbbsd 3004"); + puts("starting mbbsd:3005"); system("/home/bbs/bin/mbbsd 3005"); + puts("starting mbbsd:3006"); system("/home/bbs/bin/mbbsd 3006"); + puts("starting mbbsd:3007"); system("/home/bbs/bin/mbbsd 3007"); + puts("starting mbbsd:3008"); system("/home/bbs/bin/mbbsd 3008"); + puts("starting mbbsd:3009"); system("/home/bbs/bin/mbbsd 3009"); + puts("starting mbbsd:3010"); system("/home/bbs/bin/mbbsd 3010"); +} + +void stopbbs(void) +{ + char buf[1024]; + int pid; + FILE *fp = popen("/bin/ps -ax | /usr/bin/grep mbbsd | " + "/usr/bin/grep listen", "r"); + while( fgets(buf, sizeof(buf), fp) != NULL ){ + sscanf(buf, "%d", &pid); + printf("stopping %d\n", pid); + kill(pid, 1); + } +} + +void restartbbs(void) +{ + stopbbs(); + startbbs(); +} + +int main(int argc, char **argv) +{ + if( argc == 1 ) + usage(); + if( strcmp(argv[1], "start") == 0 ) + startbbs(); + else if( strcmp(argv[1], "stop") == 0 ) + stopbbs(); + else if( strcmp(argv[1], "restart") == 0 ) + restartbbs(); + return 0; +} diff --git a/pttbbs/util/bbsmail.c b/pttbbs/util/bbsmail.c new file mode 100644 index 00000000..48f74c63 --- /dev/null +++ b/pttbbs/util/bbsmail.c @@ -0,0 +1,239 @@ +/* $Id: bbsmail.c,v 1.1 2002/03/07 15:13:45 in2 Exp $ */ + +#define _BBS_UTIL_C_ +#include +#include +#include +#include +#include +#include +#include +#include "config.h" +#include "pttstruct.h" +#include "util.h" +#include "perm.h" +#include "common.h" + +#define LOG_FILE (BBSHOME "/etc/mailog") + +#ifdef HMM_USE_ANTI_SPAM +extern char *notitle[], *nofrom[], *nocont[]; +#endif + +extern userec_t xuser; + +int mailalertuid(int tuid) +{ + userinfo_t *uentp=NULL; + if(tuid>0 && (uentp = (userinfo_t *)search_ulist(tuid)) ) + uentp->mailalert=1; + return 0; +} + +void +mailog(msg) + char *msg; +{ + FILE *fp; + + if ((fp = fopen(LOG_FILE, "a"))) + { + time_t now; + struct tm *p; + + time(&now); + p = localtime(&now); + fprintf(fp, "%02d/%02d/%02d %02d:%02d:%02d %s\n", + p->tm_year % 100, p->tm_mon + 1, p->tm_mday, p->tm_hour, p->tm_min, p->tm_sec, + msg); + fclose(fp); + } +} + + +int +mail2bbs(userid) + char *userid; +{ + int uid; + fileheader_t mymail; + char genbuf[256], title[80], sender[80], filename[80], *ip, *ptr; + time_t tmp_time; + struct stat st; + FILE *fout; +/* check if the userid is in our bbs now */ + if (!(uid=getuser(userid)) ) + { + sprintf(genbuf, "BBS user <%s> not existed", userid); + puts(genbuf); + mailog(genbuf); + return -1;//EX_NOUSER; + } + + if(xuser.userlevel&PERM_NOOUTMAIL) + return -1; + + sprintf(filename, BBSHOME "/home/%c/%s", userid[0], userid); + + if (stat(filename, &st) == -1) + { + if (mkdir(filename, 0755) == -1) + { + printf("mail box create error %s \n", filename); + return -1; + } + } + else if (!(st.st_mode & S_IFDIR)) + { + printf("mail box error\n"); + return -1; + } + + // printf("dir: %s\n", filename); + +/* allocate a file for the new mail */ + + stampfile(filename, &mymail); + // printf("file: %s\n", filename); + +/* copy the stdin to the specified file */ + +/* parse header */ + + while (fgets(genbuf, 255, stdin)) + { + if (!strncmp(genbuf, "From", 4)) + { + if ((ip = strchr(genbuf, '<')) && (ptr = strrchr(ip, '>'))) + { + *ptr = '\0'; + if (ip[-1] == ' ') + ip[-1] = '\0'; + ptr = (char *) strchr(genbuf, ' '); + while (*ptr == ' ') ptr++; + sprintf(sender, "%s (%s)", ip + 1, ptr); + } + else + { + strtok(genbuf, " \t\n\r"); + ptr= strtok(NULL, " \t\n\r"); + if(ptr) + strcpy(sender, ptr); + } + continue; + } + if (!strncmp(genbuf, "Subject: ", 9)) + { + strcpy(title, genbuf + 9); + continue; + } + if (genbuf[0] == '\n') + break; + } + + if ((ptr = strchr(sender, '\n'))) + *ptr = '\0'; + + if ((ptr = strchr(title, '\n'))) + *ptr = '\0'; + + if (strchr(sender, '@') == NULL) /* 由 local host 寄信 */ + { + strcat(sender, "@" MYHOSTNAME); + } + + time(&tmp_time); + +#ifdef HMM_USE_ANTI_SPAM + for (n = 0; notitle[n]; n++) + if (strstr(title, notitle[n])) + { + sprintf(genbuf, "Title <%s> not accepted", title); + puts(genbuf); + mailog(genbuf); + return -1; + } + for (n = 0; nofrom[n]; n++) + if (strstr(sender, nofrom[n])) + { + sprintf(genbuf, "From <%s> not accepted", sender); + puts(genbuf); + mailog(genbuf); + return -1; + } +#endif + + if ((fout = fopen(filename, "w")) == NULL) + { + printf("Cannot open %s\n", filename); + return -1; + } + + if (!title[0]) + sprintf(title, "來自 %.64s", sender); + title[TTLEN] = 0; + fprintf(fout, "作者: %s\n標題: %s\n時間: %s\n", + sender, title, ctime(&tmp_time)); + + while (fgets(genbuf, 255, stdin)) + { +#ifdef HMM_USE_ANTI_SPAM + for (n = 0; nocont[n]; n++) + if (strstr(genbuf, nocont[n])) + { + fclose(fout); + unlink(filename); + sprintf(genbuf, "Content <%s> not accepted", nocont[n]); + puts(genbuf); + mailog(genbuf); + return -1; + } +#endif + fputs(genbuf, fout); + } + fclose(fout); + + sprintf(genbuf, "%s => %s", sender, userid); + mailog(genbuf); + +/* append the record to the MAIL control file */ + + strcpy(mymail.title, title); + + if (strtok(sender, " .@\t\n\r")) + strcat(sender, "."); + sender[IDLEN + 1] = '\0'; + strcpy(mymail.owner, sender); + + sprintf(genbuf, BBSHOME "/home/%c/%s/.DIR", userid[0], userid); + mailalertuid(uid); + return append_record(genbuf, &mymail, sizeof(mymail)); +} + + +int +main(int argc, char* argv[]) +{ + char receiver[256]; + +/* argv[1] is userid in bbs */ + + if (argc < 2) + { + printf("Usage:\t%s \n", argv[0]); + exit(-1); + } + (void) setgid(BBSGID); + (void) setuid(BBSUID); + + if(passwd_mmap()) exit(-1); + strcpy(receiver, argv[1]); + + strtok(receiver,"."); + if (mail2bbs(receiver)) + { + /* eat mail queue */ + while (fgets(receiver, sizeof(receiver), stdin)) ; + } + return 0; +} diff --git a/pttbbs/util/bbsrf.c b/pttbbs/util/bbsrf.c new file mode 100644 index 00000000..66f6cee0 --- /dev/null +++ b/pttbbs/util/bbsrf.c @@ -0,0 +1,148 @@ +/* $Id: bbsrf.c,v 1.1 2002/03/07 15:13:45 in2 Exp $ */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "config.h" + +/* fill the hid with from hostname */ +void gethid(char *hid, char *tty) +{ + int fd; + char *tp; + struct utmp data; + + gethostname(hid, MAXHOSTNAMELEN); + hid[MAXHOSTNAMELEN] = '\0'; + tp = strrchr(tty, '/') + 1; + if (tp && strlen(tp) == 5) + { + fd = open(_PATH_UTMP, O_RDONLY); + if (fd < 0) + syslog(LOG_ERR, "%s: %m", _PATH_UTMP); + else + { + while (read(fd, &data, sizeof(data)) == sizeof(data)) + if (strcmp(data.ut_line, tp) == 0) + { + if (data.ut_host[0]) { +#if MAXHOSTNAMELEN < UT_HOSTSIZE + strncpy(hid, data.ut_host, MAXHOSTNAMELEN); + hid[MAXHOSTNAMELEN] = '\0'; +#else + strncpy(hid, data.ut_host, UT_HOSTSIZE); + hid[UT_HOSTSIZE] = '\0'; +#endif + } + break; + } + close(fd); + } + } +} + +/* + get system load averages + return 0 if success; otherwise, return -1. + */ +int getload(double load[3]) +{ + int rtv = -1; +#if defined(linux) + FILE *fp; + + fp = fopen(LOAD_FILE, "r"); + if (fp) + { + if (fscanf(fp, "%lf %lf %lf", &load[0], &load[1], &load[2]) == 3) + rtv = 0; + fclose(fp); + } +#elif defined(__FreeBSD__) + if (getloadavg(load, 3) == 3) + rtv = 0; +#endif + return rtv; +} + +/* + show ban file + if filename exist, print it out, sleep 1 second, and return 0; + otherwise, return -1. + */ +int showbanfile(char *filename) +{ + FILE *fp; + char buf[256]; + + fp = fopen(filename, "r"); + if (fp) + { + while (fgets(buf, sizeof(buf), fp)) + fputs(buf, stdout); + printf("\n=============================" + "=============================\n"); + fclose(fp); + sleep(1); + } + return fp ? 0 : -1; +} + +int main(void) +{ + int uid, rtv = 0; + char *tty, ttybuf[32], hid[MAXHOSTNAMELEN + 1]; + + openlog("bbsrf", LOG_PID | LOG_PERROR, LOG_USER); + chdir(BBSHOME); + uid = getuid(); + + while (1) + { + if (!showbanfile(BAN_FILE)) + { + rtv = 1; + break; + } + else if (uid != BBSUID) + { + syslog(LOG_ERR, "UID DOES NOT MATCH"); + rtv = -1; + break; + } + else if (!getpwuid(uid)) + { + syslog(LOG_ERR, "YOU DONT EXIST"); + rtv = -1; + break; + } + else + { + tty = ttyname(0); + if (tty) + { + strcpy(ttybuf, tty); + gethid(hid, ttybuf); + } + else + { + strcpy(ttybuf, "notty"); + strcpy(hid, "unknown"); + } + execl(BBSPROG, "mbbsd", hid, ttybuf, NULL); + syslog(LOG_ERR, "execl(): %m"); + rtv = -1; + } + break; + } + return rtv; +} diff --git a/pttbbs/util/birth.c b/pttbbs/util/birth.c new file mode 100644 index 00000000..899bf9ee --- /dev/null +++ b/pttbbs/util/birth.c @@ -0,0 +1,99 @@ +/* 壽星程式 96 10/11 */ + +#include +#include +#include +#include +#include +#include +#include "config.h" +#include "pttstruct.h" +#include "util.h" +#include "common.h" + +#define OUTFILE BBSHOME "/etc/birth.today" + +struct userec_t cuser; + +int bad_user_id() { + register char ch; + int j; + if (strlen(cuser.userid) < 2 || !isalpha(cuser.userid[0])) + return 1; + if (cuser.numlogins == 0 || cuser.numlogins > 15000) + return 1; + if (cuser.numposts > 15000) + return 1; + for (j = 1; (ch = cuser.userid[j]); j++) + { + if (!isalnum(ch)) + return 1; + } + return 0; +} + +int Link(char *src, char *dst) { + char cmd[200]; + + if (link(src, dst) == 0) + return 0; + + sprintf(cmd, "/bin/cp -R %s %s", src, dst); + return system(cmd); +} + +int main(argc, argv) + int argc; + char **argv; +{ + FILE *fp1; + fileheader_t mymail; + int i, day = 0; + time_t now; + struct tm *ptime; + int j; + + now = time(NULL); /* back to ancent */ + ptime = localtime(&now); + + if(passwd_mmap()) + exit(1); + + printf("*製表\n"); + fp1 = fopen(OUTFILE, "w"); + + fprintf(fp1, "\n " + "★★★★★★ 壽星大觀 " + "★★★★★★ \n\n"); + fprintf(fp1, "【本日壽星】 \n"); + for(j = 1; j <= MAX_USERS; j++) { + passwd_query(j, &cuser); + if (bad_user_id()) + continue; + if (cuser.month == ptime->tm_mon + 1) + { + if (cuser.day == ptime->tm_mday) + { + char genbuf[200]; + sprintf(genbuf, BBSHOME "/home/%c/%s", cuser.userid[0], cuser.userid); + stampfile(genbuf, &mymail); + strcpy(mymail.owner, BBSNAME); + strcpy(mymail.title, "!! 生日快樂 !!"); + mymail.savemode = 0; + unlink(genbuf); + Link(BBSHOME "/etc/Welcome_birth", genbuf); + sprintf(genbuf, BBSHOME "/home/%c/%s/.DIR", cuser.userid[0], cuser.userid); + append_record(genbuf, &mymail, sizeof(mymail)); + if ((cuser.numlogins + cuser.numposts) < 20) + continue; + + fprintf(fp1, + " [%2d/%-2d] %-14s %-24s login:%-5d post:%-5d\n", + ptime->tm_mon + 1, ptime->tm_mday, cuser.userid, + cuser.username, cuser.numlogins, cuser.numposts); + } + } + } + fclose(fp1); + return 0; +} diff --git a/pttbbs/util/buildAnnounce.c b/pttbbs/util/buildAnnounce.c new file mode 100644 index 00000000..0e754f22 --- /dev/null +++ b/pttbbs/util/buildAnnounce.c @@ -0,0 +1,69 @@ +/* 建立所有看板精華區的連結 */ + +#include +#include +#include +#include +#include +#include "config.h" +#include "pttstruct.h" +#define GROUPROOT BBSHOME"/man/group" + +extern bcache_t *brdshm; +extern boardheader_t *bcache; +extern void resolve_boards(); + +void buildchilds(int level,char *path,boardheader_t *bptr) +{ + char newpath[512]; + boardheader_t *ptr; + fileheader_t item; + + if(bptr->firstchild[1]==(boardheader_t*)~0 || bptr->firstchild[1]==NULL) + return; + for(ptr =(void*) bptr->firstchild[1]; + ptr!=(boardheader_t*)~0 ;ptr=ptr->next[1]) + { + + if( + (ptr->brdattr&(BRD_BAD | BRD_GROUPBOARD | BRD_NOCOUNT | BRD_HIDE))!=0 + || + (ptr->level && !(ptr->brdattr & BRD_POSTMASK))) continue; + printf("%*.*s+-%-14s %-s \n",level*2,level*2,"| | | | | | | | |", + ptr->brdname, ptr->title); + if(ptr->brdattr & BRD_GROUPBOARD) + { + sprintf(newpath,"%s/%s",path,ptr->brdname); + mkdir(newpath,0766); + buildchilds(level+1,newpath,ptr); + } + else + { + printf("%s4\n",ptr->brdname); + sprintf(newpath,"/bin/ln -s "BBSHOME"/man/boards/%s %s/%s", + ptr->brdname,path,ptr->brdname); + system(newpath); + } + printf("%s5\n",ptr->brdname); + sprintf(newpath,"%s/.DIR",path); + strcpy(item.owner,ptr->BM); + strtok(item.owner,"/"); + strcpy(item.title,ptr->title+7); + item.savemode = 'D'; + sprintf(item.filename,ptr->brdname); + append_record(newpath, &item, sizeof(item)); + } +} + + +int main() +{ + char path[512]; + setsid(); + strcpy(path,GROUPROOT); + system("rm -rf "GROUPROOT); + mkdir(GROUPROOT,0766); + resolve_boards(); + buildchilds(0,path,&bcache[0]); + return 0; +} diff --git a/pttbbs/util/buildAnnounce.sh b/pttbbs/util/buildAnnounce.sh new file mode 100644 index 00000000..d43f420b --- /dev/null +++ b/pttbbs/util/buildAnnounce.sh @@ -0,0 +1,5 @@ +#!/bin/sh +# $Id: buildAnnounce.sh,v 1.1 2002/03/07 15:13:45 in2 Exp $ +# +bin/buildAnnounce > etc/ALLBRDLIST +bin/post Record 全站看板列表 [自動站長] etc/ALLBRDLIST diff --git a/pttbbs/util/buildir.c b/pttbbs/util/buildir.c new file mode 100644 index 00000000..381a657d --- /dev/null +++ b/pttbbs/util/buildir.c @@ -0,0 +1,124 @@ +/* $Id: buildir.c,v 1.1 2002/03/07 15:13:45 in2 Exp $ */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "config.h" +#include "pttstruct.h" + +int dirselect(struct dirent *dir) { + return strchr("MDSGH", dir->d_name[0]) && dir->d_name[1] == '.'; +} + +int mysort(const struct dirent **a,const struct dirent **b) +{ + return atoi(((*a)->d_name+2))-atoi(((*b)->d_name+2)); +} + +int main(int argc, char **argv) { + int k; + + if(argc < 2) { + fprintf(stderr, "Usage: %s [ ...]\n", argv[0]); + return 1; + } + + for(k = 1; k < argc; k++) { + int fdir, count, total; + char *ptr, path[MAXPATHLEN]; + struct dirent **dirlist; + + sprintf(path, "%s/.DIR", argv[k]); + if((fdir = open(path, O_WRONLY | O_CREAT | O_TRUNC, 0644)) == -1) { + perror(path); + continue; + } + + if((total = scandir(argv[k], &dirlist, dirselect, mysort)) == -1) { + fprintf(stderr, "scandir failed!\n"); + close(fdir); + continue; + } + + ptr = strrchr(path, '.'); + for(count = 0; count < total; count++) { + FILE *fp; + struct stat st; + + strcpy(ptr, dirlist[count]->d_name); + if(stat(path, &st) == 0 && st.st_size > 0 && + (fp = fopen(path, "r")) != NULL) { + char buf[512]; + time_t filetime; + fileheader_t fhdr; + + memset(&fhdr, 0, sizeof(fhdr)); + /* set file name */ + strcpy(fhdr.filename, dirlist[count]->d_name); + + /* set file time */ + filetime = atoi(dirlist[count]->d_name + 2); + if(filetime > 740000000) { + struct tm *ptime = localtime(&filetime); + sprintf(fhdr.date, "%2d/%02d", ptime->tm_mon + 1, + ptime->tm_mday); + } else + strcpy(fhdr.date, " "); + + /* set file mode */ + fhdr.filemode = FILE_READ; + + /* set article owner */ + fgets(buf, sizeof(buf), fp); + if(strncmp(buf, "作者: ", 6) == 0 || + strncmp(buf, "發信人: ", 8) == 0) { + int i, j; + + for(i = 5; buf[i] != ' '; i++); + for(; buf[i] == ' '; i++); + for(j = i + 1; buf[j] != ' '; j++); + j -= i; + if(j > IDLEN + 1) + j = IDLEN + 1; + strncpy(fhdr.owner, buf + i, j); + fhdr.owner[IDLEN + 1] = '\0'; + strtok(fhdr.owner, " .@\t\n\r"); + if(strtok(NULL, " .@\t\n\r")) + strcat(fhdr.owner, "."); + + /* set article title */ + while(fgets(buf, sizeof(buf), fp)) + if(strncmp(buf, "標題: ", 6) == 0 || + strncmp(buf, "標 題: ", 8) == 0) { + for(i = 5; buf[i] != ' '; i++); + for(; buf[i] == ' '; i++); + strtok(buf + i-1, "\n"); + strncpy(fhdr.title, buf + i, TTLEN); + fhdr.title[TTLEN] = '\0'; + break; + } + } else if(strncmp(buf, "☉ 歡迎光臨", 11) == 0) { + strcpy(fhdr.title, "會議記錄"); + } else if(strncmp(buf, "\33[1;33;46m★", 12) == 0|| + strncmp(buf, "To", 2) == 0) { + strcpy(fhdr.title, "熱線記錄"); + } +// if(!fhdr.title[0]) +// strcpy(fhdr.title, dirlist[count]->d_name); + fclose(fp); + write(fdir, &fhdr, sizeof(fhdr)); + } + } + close(fdir); + for(total--; total >= 0; total--) + free(dirlist[total]); + free(dirlist); + } + return 0; +} diff --git a/pttbbs/util/countalldice.c b/pttbbs/util/countalldice.c new file mode 100644 index 00000000..badd4bad --- /dev/null +++ b/pttbbs/util/countalldice.c @@ -0,0 +1,95 @@ +/* $Id: countalldice.c,v 1.1 2002/03/07 15:13:45 in2 Exp $ */ + +/**********************************************/ +/*這個程式是用來計算賭骰子賺得錢跟賠的錢的程式 */ +/*用法就是直接打 countalldice 就可以針對所有人 */ +/*來計算他總共賺了多少 賠了多少............... */ +/*作者:Heat 於1997/10/2 */ +/**********************************************/ + +#include +#include +#include +#include +#include "config.h" + +#define DICE_WIN BBSHOME "/etc/windice.log" +#define DICE_LOST BBSHOME "/etc/lostdice.log" + +int total = 0; + +typedef struct dice +{ + char id[14]; + int win; + int lost; +} +dice; + +dice table[1024]; + +int find(char *name) +{ + int i = 0; + if (total == 0) + { + total++; + return 0; + } + for (i = 0; i < total; i++) + if (!strcmp(name, table[i].id)) + return i; + memset(&table[total++], 0, sizeof(dice)); + return total - 1; +} + +int main() { + int index, win = 0, lost = 0; + FILE *fpwin, *fplost; + char buf[256], *ptr, buf0[256], *name = (char *) malloc(15), *mon = (char *) malloc(5); + + fpwin = fopen(DICE_WIN, "r"); + fplost = fopen(DICE_LOST, "r"); + + if (!fpwin || !fplost) + perror("error open file"); + + while (fgets(buf, 255, fpwin)) + { + strcpy(buf0, buf); + name = strtok(buf, " "); + mon = strstr(buf0, "淨賺:"); + if ((ptr = strchr(mon, '\n'))) + *ptr = 0; + index = find(name); + strcpy(table[index].id, name); + table[index].win += atoi(mon + 5); + } + fclose(fpwin); + + while (fgets(buf, 255, fplost)) + { + strcpy(buf0, buf); + name = strtok(buf, " "); + mon = strstr(buf0, "輸了 "); + if ((ptr = strchr(mon, '\n'))) + *ptr = 0; + if ((index = find(name)) == total - 1) + strcpy(table[index].id, name); + table[index].lost += atoi(mon + 5); + } + + for (index = 0; index < total; index++) + { + printf("%-15s 贏了 %-8d 塊錢, 輸掉 %-8d 塊錢\n", table[index].id + ,table[index].win, table[index].lost); + win += table[index].win; + lost += table[index].lost; + } + index = win + lost; + printf("\n人數: %d\n總贏錢=%d 總輸錢=%d 總金額:%d\n", total, win, lost, index); + printf("贏的比例:%f 輸的比例:%f\n", (float) win / index, (float) lost / index); + printf("\n備註:輸贏是以使用者的觀點來看\n"); + fclose(fplost); + return 0; +} diff --git a/pttbbs/util/cpdeadbrd.c b/pttbbs/util/cpdeadbrd.c new file mode 100644 index 00000000..12c5827e --- /dev/null +++ b/pttbbs/util/cpdeadbrd.c @@ -0,0 +1,41 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include "config.h" +#include "pttstruct.h" +#include "util.h" + +extern int numboards; +extern boardheader_t *bcache; +int main(int argc, char* argv[]){ +struct stat st; +boardheader_t *bptr; + int n; + char pathname[1024]; + + resolve_boards(); + for (n=numboards-1;n>0;n--) + { + + bptr = &bcache[n]; + if(!strcmp(bptr->brdname,"ck53rd316"))continue; + sprintf(pathname,"/home/bbs/boards/%s/.DIR",bptr->brdname); + if(stat(pathname, &st) == -1) + { + printf("%s is dead\n",pathname); + sprintf (pathname,"cp -R /mnt/bbs/boards/%s /home/bbs/boards/%s",bptr->brdname,bptr->brdname); + } + } +} + + + + + + + diff --git a/pttbbs/util/dailybackup.pl b/pttbbs/util/dailybackup.pl new file mode 100644 index 00000000..76943887 --- /dev/null +++ b/pttbbs/util/dailybackup.pl @@ -0,0 +1,48 @@ +#!/usr/bin/perl +use lib '/home/bbs/bin/'; +use LocalVars; +use strict; +use vars qw/$BACKHOME $MANROOT $HOMEROOT $BOARDROOT/; + +$BACKHOME = "$BBSHOME/backup"; +$MANROOT = "man/boards"; +$HOMEROOT = "home"; +$BOARDROOT= "boards"; + +chdir $BBSHOME; +my @baktable = (['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H'], + ['I', 'J', 'K', 'L', 'M', 'N', 'O', 'P'], + ['Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X'], + ['Y', 'Z', 'a', 'b', 'c', 'd', 'e'], + ['f', 'g', 'h', 'i', 'j', 'k', 'l'], + ['m', 'n', 'o', 'p', 'q', 'r', 's'], + ['t', 'u', 'v', 'w', 'x', 'y', 'z']); +my (undef,undef,undef,undef,undef,undef,$wday) = localtime(time); +my $week = defined($ARGV[0]) ? $ARGV[0] : $wday; + +no strict 'subs'; +setpriority(PRIO_PROCESS, $$, 20); +use strict subs; + +my($orig, $to); +foreach $orig ( <$BACKHOME/*new*> ){ + $to = $orig; + $to =~ s/\.new//g; + docmd("mv $orig $to"); +} + +foreach( @{$baktable[$week]} ){ + docmd("$TAR zcf $BACKHOME/man.$_.new.tgz $MANROOT/$_*"); + docmd("$TAR zcf $BACKHOME/home.$_.new.tgz $HOMEROOT/$_/*"); + docmd("$TAR zcf $BACKHOME/board.$_.new.tgz $BOARDROOT/$_*"); +} + +if( $week == 0 ){ + docmd("$TAR zcf $BACKHOME/general.new.tgz .act .crontab .note .polling .post bin cron etc innd note.ans note.dat out out.going pttbbs pttbbs.conf upgrade.sh usies ussong"); +} + +sub docmd +{ + print "@_\n"; + `@_`; +} diff --git a/pttbbs/util/daymandex.c b/pttbbs/util/daymandex.c new file mode 100644 index 00000000..d2921d07 --- /dev/null +++ b/pttbbs/util/daymandex.c @@ -0,0 +1,269 @@ +/* $Id: daymandex.c,v 1.1 2002/03/07 15:13:46 in2 Exp $ */ + +/* + target : 精華區索引程式 (man index) + + syntax : mandex [board] + [board] 有值 ==> 只跑該 board + 空的 ==> 所有的 boards 都跑 +*/ + + +#include +#include +#include +#include +#include +#include +#include +#include "config.h" +#include "pttstruct.h" +#include "util.h" + +#ifndef MAXPATHLEN +#define MAXPATHLEN 1024 +#endif + +extern int numboards; +extern boardheader_t *bcache; + +char color[4][10] = +{"", "", "", ""}; +char fn_index[] = ".index"; +char fn_new[] = ".index.new"; +char index_title[] = "◎ 精華區目錄索引"; +FILE *fndx; +int ndir; +int nfile; +int index_pos; +char topdir[128], pgem[512], pndx[512]; + +int nb = 0; /* board 數 */ + +struct boardinfo +{ + char bname[40]; + int ndir; + int nfile; + int k; +}; +typedef struct boardinfo boardinfo; + +boardinfo +board[MAX_BOARD]; + +int k_cmp(b, a) + boardinfo *b, *a; +{ + return ((a->k / 100 + a->ndir + a->nfile) - (b->k / 100 + b->ndir + b->nfile)); +} + +int dashd(fname) + char *fname; +{ + struct stat st; + + return (stat(fname, &st) == 0 && S_ISDIR(st.st_mode)); +} + + +/* visit the hierarchy recursively */ + +void +mandex(level, num_header, fpath) + int level; + char *fpath, *num_header; +{ + FILE *fgem; + char *fname, buf[256]; + struct stat st; + int count; + fileheader_t fhdr; + + fgem = fopen(fpath, "r+"); + if (fgem == NULL) + return; + + fname = strrchr(fpath, '.'); + if (!level) + { + + printf("%s\r\n",fpath); + strcpy(pgem, fpath); + + strcpy(fname, fn_new); + fndx = fopen(fpath, "w"); + if (fndx == NULL) + { + fclose(fgem); + return; + } + fprintf(fndx, "序號\t\t\t精華區主題\n" + "──────────────────────────────────────\n"); + strcpy(pndx, fpath); + ndir = nfile = 0; + index_pos = -1; + } + + count = 0; + while (fread(&fhdr, sizeof(fhdr), 1, fgem) == 1) + { + strcpy(fname, fhdr.filename); + if (!fname[0]) continue; + if (!level && !strncmp(fhdr.title, index_title, strlen(index_title)) + && index_pos < 0) + { + index_pos = count; + unlink(fpath); + } + st.st_size = 0; + stat(fpath, &st); + + sprintf(buf, "%.*s%s%3d. %s \n", + + 11 * level, num_header, color[level % 4], ++count, fhdr.title); /* Ptt */ + fputs(buf, fndx); + if (dashd(fpath)) + { + ++ndir; + if (*fhdr.title != '#' && level < 10) + { + strcat(fpath, "/.DIR"); + mandex(level + 1, buf, fpath); + } + } + else + ++nfile; + } + + if (!level) + { + char lpath[MAXPATHLEN]; + + fclose(fndx); + strcpy(fname, fn_index); + rename(pndx, fpath); + strcpy(pndx, fpath); + + sprintf(buf, "%s.new", pgem); + if (index_pos >= 0 || (fndx = fopen(buf, "w"))) + { + fname[-1] = 0; + stamplink(fpath, &fhdr); + unlink(fpath); + strcpy(fhdr.owner, "每天自動更新"); + sprintf(lpath, "%s/%s", topdir, pndx); + st.st_size = 0; + stat(lpath, &st); + sprintf(fhdr.title, "%s (%.1fk)", index_title, st.st_size / 1024.); + board[nb].k = st.st_size; /* Ptt */ + printf("(%d)[%dK]", nb, board[nb].k); + symlink(lpath, fpath); + if (index_pos < 0) + { + fwrite(&fhdr, sizeof(fhdr), 1, fndx); + rewind(fgem); + while (fread(&fhdr, sizeof(fhdr), 1, fgem) == 1) + fwrite(&fhdr, sizeof(fhdr), 1, fndx); + fclose(fndx); + fclose(fgem); + rename(buf, pgem); + } + else + { + fseek(fgem, index_pos * sizeof(fhdr), 0); + fwrite(&fhdr, sizeof(fhdr), 1, fgem); + fclose(fgem); + } + return; + } + } + fclose(fgem); +} + + +int main(int argc, char* argv[]){ + boardheader_t *bptr; + DIR *dirp; + struct dirent *de; + int ch, n; + int place = 0; + char *fname, fpath[MAXPATHLEN]; + + resolve_boards(); + nb = 0; + if(argc == 1){ + puts("Creating the whole index..."); + chdir(strcpy(topdir, BBSHOME)); + strcpy(fpath, "man/.DIR"); + mandex(0, "", fpath); + } + + + chdir(strcpy(topdir, BBSHOME "/man/boards")); + + if(argc > 1) { + sprintf(fpath, "%s/.DIR", argv[1]); + mandex(0, "", fpath); + exit(0); + } + + /* process all boards */ + + if(!(dirp = opendir(topdir))) { + printf("## unable to enter [man/boards]\n"); + exit(-1); + } + + while((de = readdir(dirp))){ + fname = de->d_name; + ch = fname[0]; + if (ch != '.'){ + board[nb].k = 0; + strcpy(board[nb].bname, fname); + sprintf(fpath, "%s/.rebuild", fname); + if( access(fpath, 0) >= 0 ){ + unlink(fpath); + + sprintf(fpath, "%s/.DIR", fname); + mandex(0, "", fpath); + printf("%-14sd: %d\tf: %d\n", fname, ndir, nfile); + /* report */ + board[nb].ndir = ndir; + board[nb].nfile = nfile; + if (board[nb].k) + nb++; + } + } + } + closedir(dirp); + + qsort(board, nb, sizeof(boardinfo), k_cmp); + + if (!(fndx = fopen(BBSHOME "/etc/topboardman", "w"))) + exit(0); + + fprintf(fndx, "排名 看 版 目錄數 檔案數" + " byte數  總 分 版 主 \n"); + + for (ch = 0; ch < nb; ch++){ + for (n = 0; n < numboards; n++){ + bptr = &bcache[n]; + if (!strcmp(bptr->brdname, board[ch].bname)) + break; + } + if (n >= numboards || + (bptr->brdattr & (BRD_BAD | BRD_NOCOUNT | BRD_HIDE))) + continue; + if (board[ch].ndir + board[ch].nfile < 5) + break; + fprintf(fndx, "%3d.%15s %5d %7d %10d %6d %-24.24s\n", + ++place, + board[ch].bname, + board[ch].ndir, board[ch].nfile, board[ch].k + ,board[ch].k / 100 + board[ch].nfile + board[ch].ndir + ,bptr->BM); + } + fclose(fndx); + exit(0); +} diff --git a/pttbbs/util/deluserfile.c b/pttbbs/util/deluserfile.c new file mode 100644 index 00000000..63cfefba --- /dev/null +++ b/pttbbs/util/deluserfile.c @@ -0,0 +1,147 @@ +/* $Id: deluserfile.c,v 1.1 2002/03/07 15:13:45 in2 Exp $ */ +/* 自動砍user目錄檔案程式 */ + +#include +#include +#include +#include +#include +#include +#include +#include "config.h" +#include "pttstruct.h" +#include "util.h" + +#define HOLDWRITELOG +#define DELZEROFILE +#define USERHOME BBSHOME "/home" + +int bad_user_id(char *userid) +{ + register char ch; + + if (strlen(userid) < 2) + return 1; + + if (!isalpha(*userid)) + return 1; + + if (!strcasecmp(userid, "new")) + return 1; + + while ((ch = *(++userid))) + if (!isalnum(ch)) + return 1; + return 0; +} + +void del_file(char *userid) +{ + char buf[200], buf1[200]; + struct dirent *de; + DIR *dirp; + char *ptr; + + sprintf(buf, BBSHOME "/home/%c/%s", userid[0], userid); + + if (chdir(buf) == -1) + return; + + if (!(dirp = opendir(buf))) + return; + + while ((de = readdir(dirp))) + { + ptr = de->d_name; + if (ptr[0] > ' ' && ptr[0] != '.') + { + if (strstr(ptr, "writelog")) +#ifdef HOLDWRITELOG + { + fileheader_t mymail; + + stampfile(buf, &mymail); + mymail.savemode = 'H'; /* hold-mail flag */ + mymail.filemode = FILE_READ; + strcpy(mymail.owner, userid); + strcpy(mymail.title, "熱線記錄"); + sprintf(buf1, BBSHOME "/home/%c/%s/writelog", + userid[0], userid); + rename(buf1, buf); + sprintf(buf1, BBSHOME "/home/%c/%s/.DIR", userid[0], userid); + append_record(buf1, &mymail, sizeof(mymail)); + } +#else + unlink(ptr); +#endif + else if (strstr(ptr, "chat_")) + unlink(ptr); + else if (strstr(ptr, "ve_")) + unlink(ptr); + else if (strstr(ptr, "SR.")) + unlink(ptr); + else if (strstr(ptr, ".old")) + unlink(ptr); + else if (strstr(ptr, "talk_")) + unlink(ptr); + } + } + closedir(dirp); +} + +void mv_user_home(char *ptr) +{ + char buf[200]; + + printf("move user %s to tmp\n", ptr); + sprintf(buf, "cp -R " BBSHOME "/home/%c/%s " BBSHOME "/tmp", ptr[0], ptr); +// sprintf(buf,"rm -rf " BBSHOME "/home/%c/%s",ptr[0],ptr); + if (!system(buf)) + { //Copy success + + sprintf(buf, "rm -rf " BBSHOME "/home/%c/%s", ptr[0], ptr); + system(buf); + } +} + +int main(int argc, char **argv) +{ + struct dirent *de; + DIR *dirp; + char *ptr, buf[200], ch; + int count = 0; +/* visit all users */ + + printf("new version, deleting\n"); + + for (ch = 'A'; ch <= 'z'; ch++) + { + if(ch > 'Z' && ch < 'a') + continue; + printf("Cleaning %c\n", ch); + sprintf(buf, USERHOME "/%c", ch); + if (!(dirp = opendir(buf))) + { + printf("unable to open %s\n", buf); + continue; + } + + while ((de = readdir(dirp))) + { + ptr = de->d_name; + + /* 預防錯誤 */ + if (!bad_user_id(ptr)) + { + if (!(count++ % 300)) + printf(".\n"); + if (!searchuser(ptr)) + mv_user_home(ptr); + else + del_file(ptr); + } + } + closedir(dirp); + } + return 0; +} diff --git a/pttbbs/util/descrypt.c b/pttbbs/util/descrypt.c new file mode 100644 index 00000000..97475c1a --- /dev/null +++ b/pttbbs/util/descrypt.c @@ -0,0 +1,616 @@ +/* $Id: descrypt.c,v 1.1 2002/03/07 15:13:45 in2 Exp $ */ + +/* + * FreeSec: libcrypt for NetBSD + * + * Copyright (c) 1994 David Burren + * All rights reserved. + * + * Adapted for FreeBSD-2.0 by Geoffrey M. Rehmet + * crypt.c should now *only* export crypt(), in order to make + * binaries of libcrypt exportable from the USA + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 4. Neither the name of the author nor the names of other contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD: src/secure/lib/libcrypt/crypt.c,v 1.11 1999/08/28 01:30:24 peter Exp $ + * + * This is an original implementation of the DES and the crypt(3) interfaces + * by David Burren . + * + * An excellent reference on the underlying algorithm (and related + * algorithms) is: + * + * B. Schneier, Applied Cryptography: protocols, algorithms, + * and source code in C, John Wiley & Sons, 1994. + * + * Note that in that book's description of DES the lookups for the initial, + * pbox, and final permutations are inverted (this has been brought to the + * attention of the author). A list of errata for this book has been + * posted to the sci.crypt newsgroup by the author and is available for FTP. + * + * ARCHITECTURE ASSUMPTIONS: + * This code assumes that u_longs are 32 bits. It will probably not + * operate on 64-bit machines without modifications. + * It is assumed that the 8-byte arrays passed by reference can be + * addressed as arrays of u_longs (ie. the CPU is not picky about + * alignment). + */ + +#ifndef HAVE_DES_CRYPT + +#include +#include +#include +#include + +static unsigned char IP[64] = { + 58, 50, 42, 34, 26, 18, 10, 2, 60, 52, 44, 36, 28, 20, 12, 4, + 62, 54, 46, 38, 30, 22, 14, 6, 64, 56, 48, 40, 32, 24, 16, 8, + 57, 49, 41, 33, 25, 17, 9, 1, 59, 51, 43, 35, 27, 19, 11, 3, + 61, 53, 45, 37, 29, 21, 13, 5, 63, 55, 47, 39, 31, 23, 15, 7 +}; + +static unsigned char inv_key_perm[64]; +static unsigned char u_key_perm[56]; +static unsigned char key_perm[56] = { + 57, 49, 41, 33, 25, 17, 9, 1, 58, 50, 42, 34, 26, 18, + 10, 2, 59, 51, 43, 35, 27, 19, 11, 3, 60, 52, 44, 36, + 63, 55, 47, 39, 31, 23, 15, 7, 62, 54, 46, 38, 30, 22, + 14, 6, 61, 53, 45, 37, 29, 21, 13, 5, 28, 20, 12, 4 +}; + +static unsigned char key_shifts[16] = { + 1, 1, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 1 +}; + +static unsigned char inv_comp_perm[56]; +static unsigned char comp_perm[48] = { + 14, 17, 11, 24, 1, 5, 3, 28, 15, 6, 21, 10, + 23, 19, 12, 4, 26, 8, 16, 7, 27, 20, 13, 2, + 41, 52, 31, 37, 47, 55, 30, 40, 51, 45, 33, 48, + 44, 49, 39, 56, 34, 53, 46, 42, 50, 36, 29, 32 +}; + +/* + * No E box is used, as it's replaced by some ANDs, shifts, and ORs. + */ + +static unsigned char u_sbox[8][64]; +static unsigned char sbox[8][64] = { + { + 14, 4, 13, 1, 2, 15, 11, 8, 3, 10, 6, 12, 5, 9, 0, 7, + 0, 15, 7, 4, 14, 2, 13, 1, 10, 6, 12, 11, 9, 5, 3, 8, + 4, 1, 14, 8, 13, 6, 2, 11, 15, 12, 9, 7, 3, 10, 5, 0, + 15, 12, 8, 2, 4, 9, 1, 7, 5, 11, 3, 14, 10, 0, 6, 13 + }, + { + 15, 1, 8, 14, 6, 11, 3, 4, 9, 7, 2, 13, 12, 0, 5, 10, + 3, 13, 4, 7, 15, 2, 8, 14, 12, 0, 1, 10, 6, 9, 11, 5, + 0, 14, 7, 11, 10, 4, 13, 1, 5, 8, 12, 6, 9, 3, 2, 15, + 13, 8, 10, 1, 3, 15, 4, 2, 11, 6, 7, 12, 0, 5, 14, 9 + }, + { + 10, 0, 9, 14, 6, 3, 15, 5, 1, 13, 12, 7, 11, 4, 2, 8, + 13, 7, 0, 9, 3, 4, 6, 10, 2, 8, 5, 14, 12, 11, 15, 1, + 13, 6, 4, 9, 8, 15, 3, 0, 11, 1, 2, 12, 5, 10, 14, 7, + 1, 10, 13, 0, 6, 9, 8, 7, 4, 15, 14, 3, 11, 5, 2, 12 + }, + { + 7, 13, 14, 3, 0, 6, 9, 10, 1, 2, 8, 5, 11, 12, 4, 15, + 13, 8, 11, 5, 6, 15, 0, 3, 4, 7, 2, 12, 1, 10, 14, 9, + 10, 6, 9, 0, 12, 11, 7, 13, 15, 1, 3, 14, 5, 2, 8, 4, + 3, 15, 0, 6, 10, 1, 13, 8, 9, 4, 5, 11, 12, 7, 2, 14 + }, + { + 2, 12, 4, 1, 7, 10, 11, 6, 8, 5, 3, 15, 13, 0, 14, 9, + 14, 11, 2, 12, 4, 7, 13, 1, 5, 0, 15, 10, 3, 9, 8, 6, + 4, 2, 1, 11, 10, 13, 7, 8, 15, 9, 12, 5, 6, 3, 0, 14, + 11, 8, 12, 7, 1, 14, 2, 13, 6, 15, 0, 9, 10, 4, 5, 3 + }, + { + 12, 1, 10, 15, 9, 2, 6, 8, 0, 13, 3, 4, 14, 7, 5, 11, + 10, 15, 4, 2, 7, 12, 9, 5, 6, 1, 13, 14, 0, 11, 3, 8, + 9, 14, 15, 5, 2, 8, 12, 3, 7, 0, 4, 10, 1, 13, 11, 6, + 4, 3, 2, 12, 9, 5, 15, 10, 11, 14, 1, 7, 6, 0, 8, 13 + }, + { + 4, 11, 2, 14, 15, 0, 8, 13, 3, 12, 9, 7, 5, 10, 6, 1, + 13, 0, 11, 7, 4, 9, 1, 10, 14, 3, 5, 12, 2, 15, 8, 6, + 1, 4, 11, 13, 12, 3, 7, 14, 10, 15, 6, 8, 0, 5, 9, 2, + 6, 11, 13, 8, 1, 4, 10, 7, 9, 5, 0, 15, 14, 2, 3, 12 + }, + { + 13, 2, 8, 4, 6, 15, 11, 1, 10, 9, 3, 14, 5, 0, 12, 7, + 1, 15, 13, 8, 10, 3, 7, 4, 12, 5, 6, 11, 0, 14, 9, 2, + 7, 11, 4, 1, 9, 12, 14, 2, 0, 6, 10, 13, 15, 3, 5, 8, + 2, 1, 14, 7, 4, 10, 8, 13, 15, 12, 9, 0, 3, 5, 6, 11 + } +}; + +static unsigned char un_pbox[32]; +static unsigned char pbox[32] = { + 16, 7, 20, 21, 29, 12, 28, 17, 1, 15, 23, 26, 5, 18, 31, 10, + 2, 8, 24, 14, 32, 27, 3, 9, 19, 13, 30, 6, 22, 11, 4, 25 +}; + +static unsigned long bits32[32] = { + 0x80000000, 0x40000000, 0x20000000, 0x10000000, + 0x08000000, 0x04000000, 0x02000000, 0x01000000, + 0x00800000, 0x00400000, 0x00200000, 0x00100000, + 0x00080000, 0x00040000, 0x00020000, 0x00010000, + 0x00008000, 0x00004000, 0x00002000, 0x00001000, + 0x00000800, 0x00000400, 0x00000200, 0x00000100, + 0x00000080, 0x00000040, 0x00000020, 0x00000010, + 0x00000008, 0x00000004, 0x00000002, 0x00000001 +}; + +static unsigned char bits8[8] = { 0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01 }; + +static unsigned long saltbits; +static long old_salt; +static unsigned long *bits28, *bits24; +static unsigned char init_perm[64], final_perm[64]; +static unsigned long en_keysl[16], en_keysr[16]; +static unsigned long de_keysl[16], de_keysr[16]; +static int des_initialised = 0; +static unsigned char m_sbox[4][4096]; +static unsigned long psbox[4][256]; +static unsigned long ip_maskl[8][256], ip_maskr[8][256]; +static unsigned long fp_maskl[8][256], fp_maskr[8][256]; +static unsigned long key_perm_maskl[8][128], key_perm_maskr[8][128]; +static unsigned long comp_maskl[8][128], comp_maskr[8][128]; +static unsigned long old_rawkey0, old_rawkey1; + +static unsigned char ascii64[] = +"./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; +/* 0000000000111111111122222222223333333333444444444455555555556666 */ +/* 0123456789012345678901234567890123456789012345678901234567890123 */ + +static int ascii_to_bin(char ch) { + if(ch > 'z') + return 0; + if(ch >= 'a') + return ch - 'a' + 38; + if(ch > 'Z') + return 0; + if(ch >= 'A') + return ch - 'A' + 12; + if(ch > '9') + return 0; + if(ch >= '.') + return ch - '.'; + return 0; +} + +static void des_init() { + int i, j, b, k, inbit, obit; + unsigned long *p, *il, *ir, *fl, *fr; + + old_rawkey0 = old_rawkey1 = 0L; + saltbits = 0L; + old_salt = 0L; + bits24 = (bits28 = bits32 + 4) + 4; + + /* + * Invert the S-boxes, reordering the input bits. + */ + for(i = 0; i < 8; i++) + for(j = 0; j < 64; j++) { + b = (j & 0x20) | ((j & 1) << 4) | ((j >> 1) & 0xf); + u_sbox[i][j] = sbox[i][b]; + } + + /* + * Convert the inverted S-boxes into 4 arrays of 8 bits. + * Each will handle 12 bits of the S-box input. + */ + for(b = 0; b < 4; b++) + for(i = 0; i < 64; i++) + for(j = 0; j < 64; j++) + m_sbox[b][(i << 6) | j] = + (u_sbox[(b << 1)][i] << 4) | + u_sbox[(b << 1) + 1][j]; + + /* + * Set up the initial & final permutations into a useful form, and + * initialise the inverted key permutation. + */ + for(i = 0; i < 64; i++) { + init_perm[final_perm[i] = IP[i] - 1] = i; + inv_key_perm[i] = 255; + } + + /* + * Invert the key permutation and initialise the inverted key + * compression permutation. + */ + for(i = 0; i < 56; i++) { + u_key_perm[i] = key_perm[i] - 1; + inv_key_perm[key_perm[i] - 1] = i; + inv_comp_perm[i] = 255; + } + + /* + * Invert the key compression permutation. + */ + for(i = 0; i < 48; i++) { + inv_comp_perm[comp_perm[i] - 1] = i; + } + + /* + * Set up the OR-mask arrays for the initial and final permutations, + * and for the key initial and compression permutations. + */ + for(k = 0; k < 8; k++) { + for(i = 0; i < 256; i++) { + *(il = &ip_maskl[k][i]) = 0L; + *(ir = &ip_maskr[k][i]) = 0L; + *(fl = &fp_maskl[k][i]) = 0L; + *(fr = &fp_maskr[k][i]) = 0L; + for(j = 0; j < 8; j++) { + inbit = 8 * k + j; + if(i & bits8[j]) { + if((obit = init_perm[inbit]) < 32) + *il |= bits32[obit]; + else + *ir |= bits32[obit-32]; + if ((obit = final_perm[inbit]) < 32) + *fl |= bits32[obit]; + else + *fr |= bits32[obit - 32]; + } + } + } + for(i = 0; i < 128; i++) { + *(il = &key_perm_maskl[k][i]) = 0L; + *(ir = &key_perm_maskr[k][i]) = 0L; + for(j = 0; j < 7; j++) { + inbit = 8 * k + j; + if(i & bits8[j + 1]) { + if((obit = inv_key_perm[inbit]) == 255) + continue; + if(obit < 28) + *il |= bits28[obit]; + else + *ir |= bits28[obit - 28]; + } + } + *(il = &comp_maskl[k][i]) = 0L; + *(ir = &comp_maskr[k][i]) = 0L; + for(j = 0; j < 7; j++) { + inbit = 7 * k + j; + if(i & bits8[j + 1]) { + if((obit=inv_comp_perm[inbit]) == 255) + continue; + if(obit < 24) + *il |= bits24[obit]; + else + *ir |= bits24[obit - 24]; + } + } + } + } + + /* + * Invert the P-box permutation, and convert into OR-masks for + * handling the output of the S-box arrays setup above. + */ + for(i = 0; i < 32; i++) + un_pbox[pbox[i] - 1] = i; + + for(b = 0; b < 4; b++) + for(i = 0; i < 256; i++) { + *(p = &psbox[b][i]) = 0L; + for (j = 0; j < 8; j++) { + if (i & bits8[j]) + *p |= bits32[un_pbox[8 * b + j]]; + } + } + + des_initialised = 1; +} + +static void setup_salt(long salt) { + unsigned long obit, saltbit; + int i; + + if (salt == old_salt) + return; + old_salt = salt; + + saltbits = 0L; + saltbit = 1; + obit = 0x800000; + for (i = 0; i < 24; i++) { + if (salt & saltbit) + saltbits |= obit; + saltbit <<= 1; + obit >>= 1; + } +} + +static int des_setkey(const char *key) { + unsigned long k0, k1, rawkey0, rawkey1; + int shifts, round; + + if(!des_initialised) + des_init(); + + rawkey0 = ntohl(*(unsigned long *) key); + rawkey1 = ntohl(*(unsigned long *) (key + 4)); + + if((rawkey0 | rawkey1) + && rawkey0 == old_rawkey0 + && rawkey1 == old_rawkey1) { + /* + * Already setup for this key. + * This optimisation fails on a zero key (which is weak and + * has bad parity anyway) in order to simplify the starting + * conditions. + */ + return 0; + } + old_rawkey0 = rawkey0; + old_rawkey1 = rawkey1; + + /* + * Do key permutation and split into two 28-bit subkeys. + */ + k0 = key_perm_maskl[0][rawkey0 >> 25] + | key_perm_maskl[1][(rawkey0 >> 17) & 0x7f] + | key_perm_maskl[2][(rawkey0 >> 9) & 0x7f] + | key_perm_maskl[3][(rawkey0 >> 1) & 0x7f] + | key_perm_maskl[4][rawkey1 >> 25] + | key_perm_maskl[5][(rawkey1 >> 17) & 0x7f] + | key_perm_maskl[6][(rawkey1 >> 9) & 0x7f] + | key_perm_maskl[7][(rawkey1 >> 1) & 0x7f]; + k1 = key_perm_maskr[0][rawkey0 >> 25] + | key_perm_maskr[1][(rawkey0 >> 17) & 0x7f] + | key_perm_maskr[2][(rawkey0 >> 9) & 0x7f] + | key_perm_maskr[3][(rawkey0 >> 1) & 0x7f] + | key_perm_maskr[4][rawkey1 >> 25] + | key_perm_maskr[5][(rawkey1 >> 17) & 0x7f] + | key_perm_maskr[6][(rawkey1 >> 9) & 0x7f] + | key_perm_maskr[7][(rawkey1 >> 1) & 0x7f]; + /* + * Rotate subkeys and do compression permutation. + */ + shifts = 0; + for(round = 0; round < 16; round++) { + unsigned long t0, t1; + + shifts += key_shifts[round]; + + t0 = (k0 << shifts) | (k0 >> (28 - shifts)); + t1 = (k1 << shifts) | (k1 >> (28 - shifts)); + + de_keysl[15 - round] = + en_keysl[round] = comp_maskl[0][(t0 >> 21) & 0x7f] + | comp_maskl[1][(t0 >> 14) & 0x7f] + | comp_maskl[2][(t0 >> 7) & 0x7f] + | comp_maskl[3][t0 & 0x7f] + | comp_maskl[4][(t1 >> 21) & 0x7f] + | comp_maskl[5][(t1 >> 14) & 0x7f] + | comp_maskl[6][(t1 >> 7) & 0x7f] + | comp_maskl[7][t1 & 0x7f]; + + de_keysr[15 - round] = en_keysr[round] = + comp_maskr[0][(t0 >> 21) & 0x7f] + | comp_maskr[1][(t0 >> 14) & 0x7f] + | comp_maskr[2][(t0 >> 7) & 0x7f] + | comp_maskr[3][t0 & 0x7f] + | comp_maskr[4][(t1 >> 21) & 0x7f] + | comp_maskr[5][(t1 >> 14) & 0x7f] + | comp_maskr[6][(t1 >> 7) & 0x7f] + | comp_maskr[7][t1 & 0x7f]; + } + return 0; +} + +static int do_des(unsigned long l_in, unsigned long r_in, unsigned long *l_out, + unsigned long *r_out, int count) { + /* + * l_in, r_in, l_out, and r_out are in pseudo-"big-endian" format. + */ + unsigned long l, r, *kl, *kr, *kl1, *kr1; + unsigned long f, r48l, r48r; + int round; + + if(count == 0) { + return 1; + } else if(count > 0) { + /* + * Encrypting + */ + kl1 = en_keysl; + kr1 = en_keysr; + } else { + /* + * Decrypting + */ + count = -count; + kl1 = de_keysl; + kr1 = de_keysr; + } + + /* + * Do initial permutation (IP). + */ + l = ip_maskl[0][l_in >> 24] + | ip_maskl[1][(l_in >> 16) & 0xff] + | ip_maskl[2][(l_in >> 8) & 0xff] + | ip_maskl[3][l_in & 0xff] + | ip_maskl[4][r_in >> 24] + | ip_maskl[5][(r_in >> 16) & 0xff] + | ip_maskl[6][(r_in >> 8) & 0xff] + | ip_maskl[7][r_in & 0xff]; + r = ip_maskr[0][l_in >> 24] + | ip_maskr[1][(l_in >> 16) & 0xff] + | ip_maskr[2][(l_in >> 8) & 0xff] + | ip_maskr[3][l_in & 0xff] + | ip_maskr[4][r_in >> 24] + | ip_maskr[5][(r_in >> 16) & 0xff] + | ip_maskr[6][(r_in >> 8) & 0xff] + | ip_maskr[7][r_in & 0xff]; + + while(count--) { + /* + * Do each round. + */ + kl = kl1; + kr = kr1; + round = 16; + while(round--) { + /* + * Expand R to 48 bits (simulate the E-box). + */ + r48l = ((r & 0x00000001) << 23) + | ((r & 0xf8000000) >> 9) + | ((r & 0x1f800000) >> 11) + | ((r & 0x01f80000) >> 13) + | ((r & 0x001f8000) >> 15); + + r48r = ((r & 0x0001f800) << 7) + | ((r & 0x00001f80) << 5) + | ((r & 0x000001f8) << 3) + | ((r & 0x0000001f) << 1) + | ((r & 0x80000000) >> 31); + /* + * Do salting for crypt() and friends, and + * XOR with the permuted key. + */ + f = (r48l ^ r48r) & saltbits; + r48l ^= f ^ *kl++; + r48r ^= f ^ *kr++; + /* + * Do sbox lookups (which shrink it back to 32 bits) + * and do the pbox permutation at the same time. + */ + f = psbox[0][m_sbox[0][r48l >> 12]] + | psbox[1][m_sbox[1][r48l & 0xfff]] + | psbox[2][m_sbox[2][r48r >> 12]] + | psbox[3][m_sbox[3][r48r & 0xfff]]; + /* + * Now that we've permuted things, complete f(). + */ + f ^= l; + l = r; + r = f; + } + r = l; + l = f; + } + /* + * Do final permutation (inverse of IP). + */ + *l_out = fp_maskl[0][l >> 24] + | fp_maskl[1][(l >> 16) & 0xff] + | fp_maskl[2][(l >> 8) & 0xff] + | fp_maskl[3][l & 0xff] + | fp_maskl[4][r >> 24] + | fp_maskl[5][(r >> 16) & 0xff] + | fp_maskl[6][(r >> 8) & 0xff] + | fp_maskl[7][r & 0xff]; + *r_out = fp_maskr[0][l >> 24] + | fp_maskr[1][(l >> 16) & 0xff] + | fp_maskr[2][(l >> 8) & 0xff] + | fp_maskr[3][l & 0xff] + | fp_maskr[4][r >> 24] + | fp_maskr[5][(r >> 16) & 0xff] + | fp_maskr[6][(r >> 8) & 0xff] + | fp_maskr[7][r & 0xff]; + return 0; +} + +char *crypt(char *key, char *setting) { + unsigned long count, salt, l, r0, r1, keybuf[2]; + unsigned char *p, *q; + static unsigned char output[21]; + + if(!des_initialised) + des_init(); + /* + * Copy the key, shifting each character up by one bit + * and padding with zeros. + */ + q = (unsigned char *)keybuf; + while(q - (unsigned char *)keybuf - 8) { + if((*q++ = *key << 1)) + key++; + } + if(des_setkey((unsigned char *)keybuf)) + return NULL; + + /* + * "old"-style: + * setting - 2 bytes of salt + * key - up to 8 characters + */ + count = 25; + + salt = (ascii_to_bin(setting[1]) << 6) + | ascii_to_bin(setting[0]); + + output[0] = setting[0]; + /* + * If the encrypted password that the salt was extracted from + * is only 1 character long, the salt will be corrupted. We + * need to ensure that the output string doesn't have an extra + * NUL in it! + */ + output[1] = setting[1] ? setting[1] : output[0]; + + p = output + 2; + + setup_salt(salt); + /* + * Do it. + */ + if(do_des(0L, 0L, &r0, &r1, count)) + return NULL; + /* + * Now encode the result... + */ + l = (r0 >> 8); + *p++ = ascii64[(l >> 18) & 0x3f]; + *p++ = ascii64[(l >> 12) & 0x3f]; + *p++ = ascii64[(l >> 6) & 0x3f]; + *p++ = ascii64[l & 0x3f]; + + l = (r0 << 16) | ((r1 >> 16) & 0xffff); + *p++ = ascii64[(l >> 18) & 0x3f]; + *p++ = ascii64[(l >> 12) & 0x3f]; + *p++ = ascii64[(l >> 6) & 0x3f]; + *p++ = ascii64[l & 0x3f]; + + l = r1 << 2; + *p++ = ascii64[(l >> 12) & 0x3f]; + *p++ = ascii64[(l >> 6) & 0x3f]; + *p++ = ascii64[l & 0x3f]; + *p = 0; + + return output; +} +#endif diff --git a/pttbbs/util/expire.c b/pttbbs/util/expire.c new file mode 100644 index 00000000..d6f3e2b9 --- /dev/null +++ b/pttbbs/util/expire.c @@ -0,0 +1,226 @@ +/* $Id: expire.c,v 1.1 2002/03/07 15:13:46 in2 Exp $ */ +/* 自動砍信工具程式 */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "config.h" +#include "pttstruct.h" +#include "util.h" + +#define QCAST int (*)(const void *, const void *) + +#define DEF_DAYS 50 +#define DEF_MAXP 2000 +#define DEF_MINP 300 + +#define EXPIRE_CONF BBSHOME "/etc/expire.conf" +extern boardheader_t *bcache; +char *bpath = BBSHOME "/boards"; + +struct life +{ + char bname[16]; /* board ID */ + int days; /* expired days */ + int maxp; /* max post */ + int minp; /* min post */ +}; +typedef struct life life; + + +void + expire(brd) +life *brd; +{ + fileheader_t head; + struct stat state; + char lockfile[128], tmpfile[128], bakfile[128]; + char fpath[128], index[128], *fname; + int total, bid; + int fd, fdr, fdw, done, keep; + int duetime, ftime; + + printf("%s\n", brd->bname); + if((bid = getbnum(brd->bname)) == 0 || + strcmp(brd->bname, bcache[bid-1].brdname)) + { + printf("no such board?: %s\n", brd->bname); + return; + } +#ifdef VERBOSE + if (brd->days < 1) + { + printf(":Err: expire time must more than 1 day.\n"); + return; + } + else if (brd->maxp < 100) + { + printf(":Err: maxmum posts number must more than 100.\n"); + return; + } +#endif + + sprintf(index, "%s/%s/.DIR", bpath, brd->bname); + sprintf(lockfile, "%s.lock", index); + if ((fd = open(lockfile, O_RDWR | O_CREAT | O_APPEND, 0644)) == -1) + return; + flock(fd, LOCK_EX); + + strcpy(fpath, index); + fname = (char *) strrchr(fpath, '.'); + + duetime = time(NULL) - brd->days * 24 * 60 * 60; + done = 0; + if ((fdr = open(index, O_RDONLY, 0)) > 0) + { + fstat(fdr, &state); + total = state.st_size / sizeof(head); + sprintf(tmpfile, "%s.new", index); + unlink(tmpfile); + if ((fdw = open(tmpfile, O_WRONLY | O_CREAT | O_EXCL, 0644)) > 0) + { + while (read(fdr, &head, sizeof head) == sizeof head) + { + done = 1; + ftime = atoi(head.filename + 2); + if (head.owner[0] == '-') + keep = 0; + else if (head.filemode & FILE_MARKED || total <= brd->minp) + keep = 1; + else if (ftime < duetime || total > brd->maxp) + keep = 0; + else + keep = 1; + + if (keep) + { + if (write(fdw, (char *)&head, sizeof head) == -1) + { + done = 0; + break; + } + } + else + { + strcpy(fname, head.filename); + unlink(fpath); + printf("\t%s\n", fname); + total--; + } + } + close(fdw); + } + close(fdr); + } + + if (done) + { + sprintf(bakfile, "%s.old", index); + if (rename(index, bakfile) != -1) + { + rename(tmpfile, index); + touchbtotal(bid); + } + } + flock(fd, LOCK_UN); + close(fd); +} + + +int main(argc, argv) +char *argv[]; +{ + FILE *fin; + int number, count; + life db, table[MAX_BOARD], *key; + struct dirent *de; + DIR *dirp; + char *ptr, *bname, buf[256]; + + resolve_boards(); + db.days = ((argc > 1) && (number = atoi(argv[1])) > 0) ? number : DEF_DAYS; + db.maxp = ((argc > 2) && (number = atoi(argv[2])) > 0) ? number : DEF_MAXP; + db.minp = ((argc > 3) && (number = atoi(argv[3])) > 0) ? number : DEF_MINP; + +/* --------------- */ +/* load expire.ctl */ +/* --------------- */ + + count = 0; + if((fin = fopen(EXPIRE_CONF, "r"))) + { + while (fgets(buf, 256, fin)) + { + if (buf[0] == '#') + continue; + + bname = (char *) strtok(buf, " \t\r\n"); + if (bname && *bname) + { + ptr = (char *) strtok(NULL, " \t\r\n"); + if (ptr && (number = atoi(ptr)) > 0) + { + key = &(table[count++]); + strcpy(key->bname, bname); + key->days = number; + key->maxp = db.maxp; + key->minp = db.minp; + + ptr = (char *) strtok(NULL, " \t\r\n"); + if (ptr && (number = atoi(ptr)) > 0) + { + key->maxp = number; + + ptr = (char *) strtok(NULL, " \t\r\n"); + if (ptr && (number = atoi(ptr)) > 0) + { + key->minp = number; + } + } + } + } + } + fclose(fin); + } + + if (count > 1) + { + qsort(table, count, sizeof(life), (QCAST)strcasecmp); + } + +/* ---------------- */ +/* visit all boards */ +/* ---------------- */ + + if (!(dirp = opendir(bpath))) + { + printf(":Err: unable to open %s\n", bpath); + return -1; + } + + while((de = readdir(dirp))) + { + ptr = de->d_name; + if (ptr[0] > ' ' && ptr[0] != '.') + { + if (count) + key = (life *) bsearch(ptr, table, count, sizeof(life), (QCAST)strcasecmp); + else + key = NULL; + if (!key) + key = &db; + strcpy(key->bname, ptr); + expire(key); + } + } + closedir(dirp); + return 0; +} diff --git a/pttbbs/util/horoscope.c b/pttbbs/util/horoscope.c new file mode 100644 index 00000000..c91db7cd --- /dev/null +++ b/pttbbs/util/horoscope.c @@ -0,0 +1,157 @@ +/* $Id: horoscope.c,v 1.1 2002/03/07 15:13:46 in2 Exp $ */ +#include +#include +#include "config.h" +#include "pttstruct.h" +#include "util.h" +#include "common.h" + +struct userec_t cuser; + +int main() { + int i, j, k; + FILE *fp; + int max, item, maxhoroscope; + + int act[12]; + + char *name[13] = + {"牡羊", + "金牛", + "雙子", + "巨蟹", + "獅子", + "處女", + "天秤", + "天蠍", + "射手", + "摩羯", + "水瓶", + "雙魚", + "" + }; + char *blk[10] = + { + " ", "▏", "▎", "▍", "▌", + "▋", "▊", "▉", "█", "█", + }; + + memset(act, 0, sizeof(act)); + if(passwd_mmap()) + exit(1); + for(k = 1; k <= MAX_USERS; k++) { + passwd_query(k, &cuser); + if(!cuser.userid[0]) + continue; + switch (cuser.month) + { + case 1: + if (cuser.day <= 19) + act[9]++; + else + act[10]++; + break; + case 2: + if (cuser.day <= 18) + act[10]++; + else + act[11]++; + break; + case 3: + if (cuser.day <= 20) + act[11]++; + else + act[0]++; + break; + case 4: + if (cuser.day <= 19) + act[0]++; + else + act[1]++; + break; + case 5: + if (cuser.day <= 20) + act[1]++; + else + act[2]++; + break; + case 6: + if (cuser.day <= 21) + act[2]++; + else + act[3]++; + break; + case 7: + if (cuser.day <= 22) + act[3]++; + else + act[4]++; + break; + case 8: + if (cuser.day <= 22) + act[4]++; + else + act[5]++; + break; + case 9: + if (cuser.day <= 22) + act[5]++; + else + act[6]++; + break; + case 10: + if (cuser.day <= 23) + act[6]++; + else + act[7]++; + break; + case 11: + if (cuser.day <= 22) + act[7]++; + else + act[8]++; + break; + case 12: + if (cuser.day <= 21) + act[8]++; + else + act[9]++; + break; + } + } + + for (i = max = maxhoroscope = 0; i < 12; i++) + { + if (act[i] > max) + { + max = act[i]; + maxhoroscope = i; + } + } + + item = max / 30 + 1; + + if ((fp = fopen(BBSHOME"/etc/horoscope", "w")) == NULL) + { + printf("cann't open etc/horoscope\n"); + return 1; + } + + for (i = 0; i < 12; i++) + { + fprintf(fp, " %s座 ", name[i]); + for (j = 0; j < act[i] / item; j++) + { + fprintf(fp, "%2s", blk[9]); + } + /* 為了剛好一頁 */ + if (i != 11) + fprintf(fp, "%2s %d\n\n", blk[(act[i] % item) * 10 / item], + act[i]); + else + fprintf(fp, "%2s %d\n", blk[(act[i] % item) * 10 / item], + act[i]); + } + fclose(fp); + return 0; +} diff --git a/pttbbs/util/in2outmail b/pttbbs/util/in2outmail new file mode 100644 index 00000000..686944c1 Binary files /dev/null and b/pttbbs/util/in2outmail differ diff --git a/pttbbs/util/in2outmail.c b/pttbbs/util/in2outmail.c new file mode 100644 index 00000000..fce9cc59 --- /dev/null +++ b/pttbbs/util/in2outmail.c @@ -0,0 +1,288 @@ +/* $Id: in2outmail.c,v 1.1 2002/03/07 15:13:46 in2 Exp $ */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "config.h" +#include "pttstruct.h" + + +#ifdef HAVE_SETPROCTITLE + +#include +#include + +void initsetproctitle(int argc, char **argv, char **envp) { +} + +#else + +#include +#include +#include +#include + +char **Argv = NULL; /* pointer to argument vector */ +char *LastArgv = NULL; /* end of argv */ +extern char **environ; + +void initsetproctitle(int argc, char **argv, char **envp) { + register int i; + + /* Move the environment so setproctitle can use the space at + the top of memory. */ + for(i = 0; envp[i]; i++); + environ = malloc(sizeof(char *) * (i + 1)); + for(i = 0; envp[i]; i++) + environ[i] = strdup(envp[i]); + environ[i] = NULL; + + /* Save start and extent of argv for setproctitle. */ + Argv = argv; + if(i > 0) + LastArgv = envp[i - 1] + strlen(envp[i - 1]); + else + LastArgv = argv[argc - 1] + strlen(argv[argc - 1]); +} + +static void do_setproctitle(const char *cmdline) { + char buf[256], *p; + int i; + + strncpy(buf, cmdline, 256); + buf[255] = '\0'; + i = strlen(buf); + if(i > LastArgv - Argv[0] - 2) { + i = LastArgv - Argv[0] - 2; + } + strcpy(Argv[0], buf); + p = &Argv[0][i]; + while(p < LastArgv) + *p++='\0'; + Argv[1] = NULL; +} + +void setproctitle(const char* format, ...) { + char buf[256]; + + va_list args; + va_start(args, format); + vsprintf(buf, format,args); + do_setproctitle(buf); + va_end(args); +} +#endif + + + + + +#define SPOOL BBSHOME "/out" +#define INDEX SPOOL "/.DIR" +#define NEWINDEX SPOOL "/.DIR.sending" +#define FROM ".bbs@" MYHOSTNAME +#define SMTPPORT 25 + +int waitReply(int sock) { + char buf[256]; + + if(read(sock, buf, sizeof(buf)) <= 0) + return -1; + else + return buf[0] - '0'; +} + +int sendRequest(int sock, char *request) { + return write(sock, request, strlen(request)) < 0 ? -1 : 0; +} + +int connectMailServer(char *host) { + int sock; + struct sockaddr_in addr; + + if((sock = socket(PF_INET, SOCK_STREAM, 0)) < 0) { + perror("socket"); + return -1; + } + + memset(&addr, 0, sizeof(addr)); +#ifdef FreeBSD + addr.sin_len = sizeof(addr); +#endif + addr.sin_family = AF_INET; + addr.sin_port = htons(SMTPPORT); + addr.sin_addr.s_addr = inet_addr(host); + + if(connect(sock, (struct sockaddr *)&addr, sizeof(addr)) < 0) { + perror(RELAY_SERVER_IP); + close(sock); + return -1; + } + + if(waitReply(sock) != 2) { + close(sock); + return -1; + } + + if(sendRequest(sock, "helo " MYHOSTNAME "\n") || waitReply(sock) != 2) { + close(sock); + return -1; + } else + return sock; +} + +void disconnectMailServer(int sock) { + sendRequest(sock, "quit\n"); + /* drop the reply :p */ + close(sock); +} + +void doSendBody(int sock, FILE *fp, char *from, char *to, char *subject) { + int n; + char buf[2048]; + + n = snprintf(buf, sizeof(buf), "From: %s\nTo: %s\nSubject: %s\n\n", + from, to, subject); + write(sock, buf, n); + + while(fgets(buf, sizeof(buf), fp)) { + if(buf[0] == '.' && buf[1] == '\n') + strcpy(buf, "..\n"); + write(sock, buf, strlen(buf)); + } +} + +void doSendMail(int sock, FILE *fp, char *from, char *to, char *subject) { + char buf[256]; + + snprintf(buf, sizeof(buf), "mail from: %s\n", from); + if(sendRequest(sock, buf) || waitReply(sock) != 2) + return; + + snprintf(buf, sizeof(buf), "rcpt to: %s\n", to); + if(sendRequest(sock, buf) || waitReply(sock) != 2) + return; + + if(sendRequest(sock, "data\n") || waitReply(sock) != 3) + return; + + doSendBody(sock, fp, from, to, subject); + + if(sendRequest(sock, "\n.\n") || waitReply(sock) != 2) + return; +} + +void sendMail() { + int fd, sockPTT2, sockHinet; + MailQueue mq; + + if(access(NEWINDEX, R_OK | W_OK)) { + if(link(INDEX, NEWINDEX) || unlink(INDEX)) + /* nothing to do */ + return; + } + + if( (sockPTT2 = connectMailServer("140.112.30.143")) < 0 ){ + fprintf(stderr, "connect server failed...\n"); + return; + } + sockHinet = connectMailServer("61.218.59.183"); + + fd = open(NEWINDEX, O_RDONLY); + flock(fd, LOCK_EX); + while(read(fd, &mq, sizeof(mq)) > 0) { + FILE *fp; + char buf[256]; + + snprintf(buf, sizeof(buf), "%s%s", mq.sender, FROM); + if((fp = fopen(mq.filepath, "r"))) { + setproctitle("outmail: sending %s", mq.filepath); + if( strstr(mq.rcpt, ".edu.tw") || + strstr(mq.rcpt, ".twbbs.org") || + strstr(mq.rcpt, "ptt.cc") || + strstr(mq.rcpt, "ptt2.cc") ){ + printf("relay server: ptt2, to %s\n", mq.rcpt); + doSendMail(sockPTT2, fp, buf, mq.rcpt, mq.subject); + } + else{ + printf("relay server: ezmain, to %s\n", mq.rcpt); + doSendMail( (sockHinet > 0) ? sockHinet : sockPTT2, + fp, buf, mq.rcpt, mq.subject); + } + fclose(fp); + unlink(mq.filepath); + } else { + perror(mq.filepath); + } + } + flock(fd, LOCK_UN); + close(fd); + unlink(NEWINDEX); + + if( sockHinet > 0 ) + disconnectMailServer(sockHinet); + disconnectMailServer(sockPTT2); +} + +void listQueue() { + int fd; + + if((fd = open(INDEX, O_RDONLY)) >= 0) { + int counter = 0; + MailQueue mq; + + flock(fd, LOCK_EX); + while(read(fd, &mq, sizeof(mq)) > 0) { + printf("%s:%s -> %s:%s\n", mq.filepath, mq.username, mq.rcpt, + mq.subject); + counter++; + } + flock(fd, LOCK_UN); + close(fd); + printf("\nTotal: %d mails in queue\n", counter); + } else { + perror(INDEX); + } +} + +void usage() { + fprintf(stderr, "usage: outmail [-qh]\n"); +} + +void wakeup(int s) { +} + +int main(int argc, char **argv, char **envp) { + int ch; + + signal(SIGHUP, wakeup); + initsetproctitle(argc, argv, envp); + + if(chdir(BBSHOME)) + return 1; + while((ch = getopt(argc, argv, "qh")) != -1) { + switch(ch) { + case 'q': + listQueue(); + return 0; + default: + usage(); + return 0; + } + } + for(;;) { + sendMail(); + setproctitle("outmail: sleeping"); + sleep(60 * 3); /* send mail every 3 minute */ + } + return 0; +} diff --git a/pttbbs/util/initbbs.c b/pttbbs/util/initbbs.c new file mode 100644 index 00000000..ce6c4361 --- /dev/null +++ b/pttbbs/util/initbbs.c @@ -0,0 +1,223 @@ +/* $Id: initbbs.c,v 1.1 2002/03/07 15:13:46 in2 Exp $ */ +#include +#include +#include +#include +#include +#include +#include +#include "config.h" +#include "pttstruct.h" +#include "perm.h" + +static void initDir() { + mkdir("adm", 0755); + mkdir("boards", 0755); + mkdir("etc", 0755); + mkdir("man", 0755); + mkdir("man/boards", 0755); + mkdir("out", 0755); + mkdir("tmp", 0755); +} + +static void initHome() { + int i; + char buf[256]; + + mkdir("home", 0755); + strcpy(buf, "home/?"); + for(i = 0; i < 26; i++) { + buf[5] = 'A' + i; + mkdir(buf, 0755); + buf[5] = 'a' + i; + mkdir(buf, 0755); + } +} + +static void initPasswds() { + int i; + userec_t u; + FILE *fp = fopen(".PASSWDS", "w"); + + memset(&u, 0, sizeof(u)); + if(fp) { + for(i = 0; i < MAX_USERS; i++) + fwrite(&u, sizeof(u), 1, fp); + fclose(fp); + } +} + +static void newboard(FILE *fp, boardheader_t *b) { + char buf[256]; + + fwrite(b, sizeof(boardheader_t), 1, fp); + sprintf(buf, "boards/%s", b->brdname); + mkdir(buf, 0755); + sprintf(buf, "man/boards/%s", b->brdname); + mkdir(buf, 0755); +} + +static void initBoards() { + FILE *fp = fopen(".BOARDS", "w"); + boardheader_t b; + + if(fp) { + memset(&b, 0, sizeof(b)); + + strcpy(b.brdname, "SYSOP"); + strcpy(b.title, "嘰哩 ◎站長好!"); + b.brdattr = BRD_POSTMASK | BRD_NOTRAN | BRD_NOZAP; + b.level = 0; + b.gid = 2; + + newboard(fp, &b); + strcpy(b.brdname, "1..........."); + strcpy(b.title, ".... Σ中央政府 《高壓危險,非人可敵》"); + b.brdattr = BRD_GROUPBOARD; + b.level = PERM_SYSOP; + b.gid = 1; + newboard(fp, &b); + + strcpy(b.brdname, "junk"); + strcpy(b.title, "發電 ◎雜七雜八的垃圾"); + b.brdattr = BRD_NOTRAN; + b.level = PERM_SYSOP; + b.gid = 2; + newboard(fp, &b); + + strcpy(b.brdname, "Security"); + strcpy(b.title, "發電 ◎站內系統安全"); + b.brdattr = BRD_NOTRAN; + b.level = PERM_SYSOP; + b.gid = 2; + newboard(fp, &b); + + strcpy(b.brdname, "2..........."); + strcpy(b.title, ".... Σ市民廣場 報告 站長 ㄜ!"); + b.brdattr = BRD_GROUPBOARD; + b.level = 0; + b.gid = 1; + newboard(fp, &b); + + strcpy(b.brdname, "ALLPOST"); + strcpy(b.title, "嘰哩 ◎跨板式LOCAL新文章"); + b.brdattr = BRD_POSTMASK | BRD_NOTRAN; + b.level = PERM_SYSOP; + b.gid = 5; + newboard(fp, &b); + + strcpy(b.brdname, "deleted"); + strcpy(b.title, "嘰哩 ◎資源回收筒"); + b.brdattr = BRD_NOTRAN; + b.level = PERM_BM; + b.gid = 5; + newboard(fp, &b); + + strcpy(b.brdname, "Note"); + strcpy(b.title, "嘰哩 ◎動態看板及歌曲投稿"); + b.brdattr = BRD_NOTRAN; + b.level = 0; + b.gid = 5; + newboard(fp, &b); + + strcpy(b.brdname, "Record"); + strcpy(b.title, "嘰哩 ◎我們的成果"); + b.brdattr = BRD_NOTRAN | BRD_POSTMASK; + b.level = 0; + b.gid = 5; + newboard(fp, &b); + + + strcpy(b.brdname, "WhoAmI"); + strcpy(b.title, "嘰哩 ◎呵呵,猜猜我是誰!"); + b.brdattr = BRD_NOTRAN; + b.level = 0; + b.gid = 5; + newboard(fp, &b); + + strcpy(b.brdname, "EditExp"); + strcpy(b.title, "嘰哩 ◎範本精靈投稿區"); + b.brdattr = BRD_NOTRAN; + b.level = 0; + b.gid = 5; + newboard(fp, &b); + + fclose(fp); + } +} + +static void initMan() { + FILE *fp; + fileheader_t f; + time_t t = time(NULL); + struct tm *tm = localtime(&t); + + memset(&f, 0, sizeof(f)); + f.savemode = 0; + strcpy(f.owner, "SYSOP"); + sprintf(f.date, "%2d/%02d", tm->tm_mon + 1, tm->tm_mday); + f.money = 0; + f.filemode = 0; + + if((fp = fopen("man/boards/Note/.DIR", "w"))) { + strcpy(f.filename, "SONGBOOK"); + strcpy(f.title, "◆ 【點 歌 歌 本】"); + fwrite(&f, sizeof(f), 1, fp); + mkdir("man/boards/Note/SONGBOOK", 0755); + + strcpy(f.filename, "SONGO"); + strcpy(f.title, "◆ <點歌> 動態看板"); + fwrite(&f, sizeof(f), 1, fp); + mkdir("man/boards/Note/SONGO", 0755); + + strcpy(f.filename, "SYS"); + strcpy(f.title, "◆ <系統> 動態看板"); + fwrite(&f, sizeof(f), 1, fp); + mkdir("man/boards/Note/SYS", 0755); + + strcpy(f.filename, "AD"); + strcpy(f.title, "◆ <廣告> 動態看板"); + fwrite(&f, sizeof(f), 1, fp); + mkdir("man/boards/Note/AD", 0755); + + strcpy(f.filename, "NEWS"); + strcpy(f.title, "◆ <新聞> 動態看板"); + fwrite(&f, sizeof(f), 1, fp); + mkdir("man/boards/Note/NEWS", 0755); + + fclose(fp); + } + +} + +static void initSymLink() { + symlink(BBSHOME "/man/boards/Note/SONGBOOK", BBSHOME "/etc/SONGBOOK"); + symlink(BBSHOME "/man/boards/Note/SONGO", BBSHOME "/etc/SONGO"); + symlink(BBSHOME "/man/boards/EditExp", BBSHOME "/etc/editexp"); +} + +static void initHistory() { + FILE *fp = fopen("etc/history.data", "w"); + + if(fp) { + fprintf(fp, "0 0 0 0"); + fclose(fp); + } +} + +int main() { + if(chdir(BBSHOME)) { + perror(BBSHOME); + exit(1); + } + + initDir(); + initHome(); + initPasswds(); + initBoards(); + initMan(); + initSymLink(); + initHistory(); + + return 0; +} diff --git a/pttbbs/util/inndBM.c b/pttbbs/util/inndBM.c new file mode 100644 index 00000000..426fa6f5 --- /dev/null +++ b/pttbbs/util/inndBM.c @@ -0,0 +1,194 @@ +/* 依據 .BOARD檔 & newsfeeds.bbs 列出參與轉信的所有板資料 */ + +#include +#include +#include +#include +#include +#include "config.h" +#include "pttstruct.h" +#define INNDHOME BBSHOME"/innd" + +#define INND_NEWSFEED INNDHOME "/newsfeeds.bbs" +#define INND_NODELIST INNDHOME "/nodelist.bbs" +#define INND_SCRIPT INNDHOME "/bbsnnrpall.auto.sh" + +extern bcache_t *brdshm; +extern boardheader_t *bcache; +extern int numboards; +int istran[MAX_BOARD]; + +typedef +struct newssvr_t +{ + char name[30]; + char address[256]; + char type[10]; +}newssvr_t; + +typedef +struct newsfeed_t +{ + char group[128]; + char board[15]; + char server[30]; +}newsfeed_t; + +newssvr_t server[128]; +newsfeed_t feedline[MAX_BOARD]; +int servercount; +int feedcount; + +int newsfeed_cmp(newsfeed_t *a,newsfeed_t *b) +{ + int i; + i=strcasecmp(a->server,b->server); + if(i) return i; + return strcasecmp(a->board,b->board); +} + +int get_server(char *name) +{ + int i; + for(i=0;i>" + INNDHOME"/log/inndBM.log 2>>" + INNDHOME"/log/inndBM.log.err &\r\n", + server[serverid].address, + serverstr); + system(buf); + if(fpscript) + fprintf(fpscript,INNDHOME"/bbsnnrp %s " + INNDHOME"/active/%s.auto.active >>" + INNDHOME"/log/inndBM.log 2>>" + INNDHOME"/log/inndBM.log.err &\r\n", + server[serverid].address,serverstr); + return 0; +} +int main() +{ + int i,serverid=0; + FILE *fp=NULL,*fpscript=fopen(INND_SCRIPT,"w"); + char buf[256],serverstr[30]=""; + resolve_boards(); + memset(istran,0,sizeof(int)*MAX_BOARD); + load_server(); + load_newsfeeds(); + + for(i=0;ibusystate) {safe_sleep(1);} + brdshm->busystate = 1; + bcache[i].brdattr = bcache[i].brdattr & ~BRD_NOTRAN; + strncpy(bcache[i].title + 5, "●", 2); + brdshm->busystate = 0; + + substitute_record(BBSHOME"/.BOARDS", &bcache[i],sizeof(boardheader_t),i+1); + } + else if(!(bcache[i].brdattr & BRD_NOTRAN) && !istran[i]) + { + while(brdshm->busystate) {safe_sleep(1);} + brdshm->busystate = 1; + bcache[i].brdattr = bcache[i].brdattr | BRD_NOTRAN; + strncpy(bcache[i].title + 5, "◎", 2); + brdshm->busystate = 0; + substitute_record(BBSHOME"/.BOARDS", &bcache[i],sizeof(boardheader_t),i+1); + } + + } + return 0; +} diff --git a/pttbbs/util/jungo.c b/pttbbs/util/jungo.c new file mode 100644 index 00000000..15096b30 --- /dev/null +++ b/pttbbs/util/jungo.c @@ -0,0 +1,202 @@ +#include +#include +#include +#include +#include +#include +#include +#include "config.h" +#include "pttstruct.h" +#include "util.h" +#include "perm.h" +#include "common.h" + +#define OUTFILE BBSHOME "/etc/toplazyBBM" +#define FIREFILE BBSHOME "/etc/topfireBBM" + +extern boardheader_t *bcache; +extern int numboards; + +boardheader_t allbrd[MAX_BOARD]; +extern userec_t xuser; +typedef struct lostbm { + char *bmname; + char *title; + char *ctitle; + int lostdays; +} lostbm; +lostbm lostbms[MAX_BOARD]; + +typedef struct BMarray{ + char *bmname; + int flag; +} BMArray; +BMArray bms[3]; + +int bmlostdays_cmp(const void *va, const void *vb) +{ + lostbm *a=(lostbm *)va, *b=(lostbm *)vb; + if (a->lostdays > b->lostdays) return -1; + else if (a->lostdays == b->lostdays) return 0; + else return 1; +} + +int LINK(char* src, char* dst){ + char cmd[200]; + if(symlink(src,dst) == -1) + { + sprintf(cmd, "/bin/cp -R %s %s", src, dst); + return system(cmd); + } + return 0; +} + +int main(int argc, char *argv[]) +{ + int bmid, i, j=0; + FILE *inf, *firef; + + resolve_boards(); + + if(passwd_mmap()) + exit(1); + + memcpy(allbrd,bcache,numboards*sizeof(boardheader_t)); + + /* write out the target file */ + + inf = fopen(OUTFILE, "w+"); + if(inf == NULL){ + printf("open file error : %s\n", OUTFILE); + exit(1); + } + firef = fopen(FIREFILE, "w+"); + if(firef == NULL){ + printf("open file error : %s\n", FIREFILE); + fclose(inf); + exit(1); + } + + fprintf(inf, "警告: 小組長若於一個月未上站,將予於免職\n"); + fprintf(inf, + "看板名稱 " + " 小組長 幾天沒來啦\n" + "---------------------------------------------------" + "-------------------\n"); + + fprintf(firef, "免職小組長\n"); + fprintf(firef, + "看板名稱 " + " 小組長 幾天沒來啦\n" + "---------------------------------------------------" + "-------------------\n"); + + + j = 0 ; + for (i = 0; i < numboards; i++) { + char *p, bmbuf[IDLEN * 3 + 3]; + int index = 0, flag = 0, k, n; + p=strtok(allbrd[i].BM,"/ "); + if(p) + do + { + if(allbrd[i].brdname[0] == '\0' || (allbrd[i].brdattr & BRD_GROUPBOARD) ==0 ) continue; + if (*p == '[' ){p[strlen(p)-1]='\0'; p++;} + bmid=getuser(p); + bms[index].bmname = p; + bms[index].flag = 0; + if (((((int)time(NULL)-(int)xuser.lastlogin)/(60*60*24))>=7) + //&& isalpha(allbrd[i].brdname[0]) + && isalpha(allbrd[i].BM[0]) + && !(xuser.userlevel & PERM_SYSOP)) + { + lostbms[j].bmname = p; + lostbms[j].title = allbrd[i].brdname; + lostbms[j].ctitle = allbrd[i].title; + lostbms[j].lostdays = + ((int)time(NULL)-(int)xuser.lastlogin)/(60*60*24); + + printf("%s\n", lostbms[j].title); + //超過六十天 免職 + if(lostbms[j].lostdays > 30){ + xuser.userlevel &= ~PERM_BM; + bms[index].flag = 1; + flag = 1; + } + j++; + } + index++; + } while((p=strtok(NULL,"/ "))!=NULL); + + //從版主名單拿掉名字 + + if(flag == 1){ + bmbuf[0] = '\0'; + for(k = 0 , n = 0; k < index; k++){ + if(!bms[k].flag){ + if( n++ != 0) strcat(bmbuf, "/"); + strcat(bmbuf, bms[k].bmname); + } + } + strcpy(bcache[i].BM, bmbuf); + } + + } + qsort(lostbms, j, sizeof(lostbm), bmlostdays_cmp); + + //write to the etc/toplazyBBM + for ( i=0; i 7){ + fprintf(firef, "%-*.*s%-*.*s%-*.*s%3d天沒上站\n", IDLEN, IDLEN, lostbms[i].title, + BTLEN-10, BTLEN-10, lostbms[i].ctitle, IDLEN,IDLEN, + lostbms[i].bmname,lostbms[i].lostdays); + }else{ + fprintf(inf, "%-*.*s%-*.*s%-*.*s%3d天沒上站\n", IDLEN, IDLEN, lostbms[i].title, + BTLEN-10, BTLEN-10, lostbms[i].ctitle, IDLEN,IDLEN, + lostbms[i].bmname,lostbms[i].lostdays); + } + } + fclose(inf); + fclose(firef); + + //printf("Total %d boards.\n", count); + + //mail to the users + for( i=0; i + + +void main() +{ + FILE * fin, * fout; + char line[255], line2[255]; + int i; + char genbuf[255], tok[20]; + fin = fopen("M.1006277896.A","r"); + while(!feof(fin)) + { + fgets(line,255,fin); + line[12] = '\0'; + + sprintf(genbuf, "cd ~/boards/%s;grep " + "超過一個月無廣告以外的本站文章發表。" + " *.A > ~/pttbbs/util/kenken.txt",line); + system(genbuf); + + fout = fopen("kenken.txt","r"); + while(!feof(fout)) + { + line2[0] = '\0'; + fgets(line2,255,fout); + if(strlen(line2) <= 10) break; + sscanf(line2,"%s:",tok); + for(i = 0; i < 20;i++) + { + if(tok[i] == ':') + { + tok[i] = '\0'; + break; + } + } + sprintf(genbuf, "cd ~/boards/%s;rm %s",line, tok); +// printf("%s \n", genbuf); + system(genbuf); + } + } + + fclose(fin); + +} diff --git a/pttbbs/util/mailog.sh b/pttbbs/util/mailog.sh new file mode 100644 index 00000000..da89ae3d --- /dev/null +++ b/pttbbs/util/mailog.sh @@ -0,0 +1,9 @@ +#!/bin/sh +# $Id: mailog.sh,v 1.1 2002/03/07 15:13:46 in2 Exp $ +# +# 整理出廣告信名單 + +bin/antispam +bin/post Record 今日違法廣告信名單 [Ptt警察局] etc/spam +bin/post Security 站外來信紀錄mailog [系統安全局] etc/mailog +rm etc/mailog diff --git a/pttbbs/util/mandex.c b/pttbbs/util/mandex.c new file mode 100644 index 00000000..9373f814 --- /dev/null +++ b/pttbbs/util/mandex.c @@ -0,0 +1,263 @@ +/* $Id: mandex.c,v 1.1 2002/03/07 15:13:46 in2 Exp $ */ + +/* + target : 精華區索引程式 (man index) + + syntax : mandex [board] + [board] 有值 ==> 只跑該 board + 空的 ==> 所有的 boards 都跑 +*/ + + +#include +#include +#include +#include +#include +#include +#include +#include "config.h" +#include "pttstruct.h" +#include "util.h" + +#ifndef MAXPATHLEN +#define MAXPATHLEN 1024 +#endif + +extern int numboards; +extern boardheader_t *bcache; + +char color[4][10] = +{"", "", "", ""}; +char fn_index[] = ".index"; +char fn_new[] = ".index.new"; +char index_title[] = "◎ 精華區目錄索引"; +FILE *fndx; +int ndir; +int nfile; +int index_pos; +char topdir[128], pgem[512], pndx[512]; + +int nb = 0; /* board 數 */ + +struct boardinfo +{ + char bname[40]; + int ndir; + int nfile; + int k; +}; +typedef struct boardinfo boardinfo; + +boardinfo +board[MAX_BOARD]; + +int k_cmp(b, a) + boardinfo *b, *a; +{ + return ((a->k / 100 + a->ndir + a->nfile) - (b->k / 100 + b->ndir + b->nfile)); +} + +int dashd(fname) + char *fname; +{ + struct stat st; + + return (stat(fname, &st) == 0 && S_ISDIR(st.st_mode)); +} + + +/* visit the hierarchy recursively */ + +void +mandex(level, num_header, fpath) + int level; + char *fpath, *num_header; +{ + FILE *fgem; + char *fname, buf[256]; + struct stat st; + int count; + fileheader_t fhdr; + + fgem = fopen(fpath, "r+"); + if (fgem == NULL) + return; + + fname = strrchr(fpath, '.'); + if (!level) + { + + printf("%s\r\n",fpath); + strcpy(pgem, fpath); + + strcpy(fname, fn_new); + fndx = fopen(fpath, "w"); + if (fndx == NULL) + { + fclose(fgem); + return; + } + fprintf(fndx, "序號\t\t\t精華區主題\n" + "──────────────────────────────────────\n"); + strcpy(pndx, fpath); + ndir = nfile = 0; + index_pos = -1; + } + + count = 0; + while (fread(&fhdr, sizeof(fhdr), 1, fgem) == 1) + { + strcpy(fname, fhdr.filename); + if (!fname[0]) continue; + if (!level && !strncmp(fhdr.title, index_title, strlen(index_title)) + && index_pos < 0) + { + index_pos = count; + unlink(fpath); + } + st.st_size = 0; + stat(fpath, &st); + + sprintf(buf, "%.*s%s%3d. %s \n", + + 11 * level, num_header, color[level % 4], ++count, fhdr.title); /* Ptt */ + fputs(buf, fndx); + if (dashd(fpath)) + { + ++ndir; + if (*fhdr.title != '#' && level < 10) + { + strcat(fpath, "/.DIR"); + mandex(level + 1, buf, fpath); + } + } + else + ++nfile; + } + + if (!level) + { + char lpath[MAXPATHLEN]; + + fclose(fndx); + strcpy(fname, fn_index); + rename(pndx, fpath); + strcpy(pndx, fpath); + + sprintf(buf, "%s.new", pgem); + if (index_pos >= 0 || (fndx = fopen(buf, "w"))) + { + fname[-1] = 0; + stamplink(fpath, &fhdr); + unlink(fpath); + strcpy(fhdr.owner, "每天自動更新"); + sprintf(lpath, "%s/%s", topdir, pndx); + st.st_size = 0; + stat(lpath, &st); + sprintf(fhdr.title, "%s (%.1fk)", index_title, st.st_size / 1024.); + board[nb].k = st.st_size; /* Ptt */ + printf("(%d)[%dK]", nb, board[nb].k); + symlink(lpath, fpath); + if (index_pos < 0) + { + fwrite(&fhdr, sizeof(fhdr), 1, fndx); + rewind(fgem); + while (fread(&fhdr, sizeof(fhdr), 1, fgem) == 1) + fwrite(&fhdr, sizeof(fhdr), 1, fndx); + fclose(fndx); + fclose(fgem); + rename(buf, pgem); + } + else + { + fseek(fgem, index_pos * sizeof(fhdr), 0); + fwrite(&fhdr, sizeof(fhdr), 1, fgem); + fclose(fgem); + } + return; + } + } + fclose(fgem); +} + + +int main(int argc, char* argv[]){ + boardheader_t *bptr; + DIR *dirp; + struct dirent *de; + int ch, n; + int place = 0; + char *fname, fpath[MAXPATHLEN]; + + resolve_boards(); + nb = 0; + if(argc == 1){ + puts("Creating the whole index..."); + chdir(strcpy(topdir, BBSHOME)); + strcpy(fpath, "man/.DIR"); + mandex(0, "", fpath); + } + + + chdir(strcpy(topdir, BBSHOME "/man/boards")); + + if(argc > 1) { + sprintf(fpath, "%s/.DIR", argv[1]); + mandex(0, "", fpath); + exit(0); + } + + /* process all boards */ + + if(!(dirp = opendir(topdir))) { + printf("## unable to enter [man/boards]\n"); + exit(-1); + } + + while((de = readdir(dirp))){ + fname = de->d_name; + ch = fname[0]; + if (ch != '.'){ + board[nb].k = 0; + strcpy(board[nb].bname, fname); + sprintf(fpath, "%s/.DIR", fname); + mandex(0, "", fpath); + printf("%-14sd: %d\tf: %d\n", fname, ndir, nfile); /* report */ + board[nb].ndir = ndir; + board[nb].nfile = nfile; + if (board[nb].k) + nb++; + } + } + closedir(dirp); + + qsort(board, nb, sizeof(boardinfo), k_cmp); + + if (!(fndx = fopen(BBSHOME "/etc/topboardman", "w"))) + exit(0); + + fprintf(fndx, "排名 看 版 目錄數 檔案數" + " byte數  總 分 版 主 \n"); + + for (ch = 0; ch < nb; ch++){ + for (n = 0; n < numboards; n++){ + bptr = &bcache[n]; + if (!strcmp(bptr->brdname, board[ch].bname)) + break; + } + if (n >= numboards || + (bptr->brdattr & (BRD_BAD | BRD_NOCOUNT | BRD_HIDE))) + continue; + if (board[ch].ndir + board[ch].nfile < 5) + break; + fprintf(fndx, "%3d.%15s %5d %7d %10d %6d %-24.24s\n", + ++place, + board[ch].bname, + board[ch].ndir, board[ch].nfile, board[ch].k + ,board[ch].k / 100 + board[ch].nfile + board[ch].ndir + ,bptr->BM); + } + fclose(fndx); + exit(0); +} diff --git a/pttbbs/util/merge_board.c b/pttbbs/util/merge_board.c new file mode 100644 index 00000000..743ffc14 --- /dev/null +++ b/pttbbs/util/merge_board.c @@ -0,0 +1,106 @@ +/* $Id: merge_board.c,v 1.1 2002/03/07 15:13:46 in2 Exp $ */ +#include +#include +#include +#include +#include +#include "config.h" +#include "pttstruct.h" + +typedef struct hash_t { + char *brdname; + struct hash_t *next; +} hash_t; + +FILE *fout; +hash_t *hash_tbl[65536]; +int counter; + +void usage() { + fprintf(stderr, "Usage:\n\n" + "merge_board [input file1] [input file2] ...\n"); +} + +unsigned int string_hash(unsigned char *s) { + unsigned int v=0; + + while(*s) { + v = (v << 8) | (v >> 24); + v ^= toupper(*s++); /* note this is case insensitive */ + } + return (v * 2654435769UL) >> (32 - 16); +} + +int is_exist(char *brdname) { + int i; + hash_t *n; + + i = string_hash(brdname); + for(n = hash_tbl[i]; n != NULL; n = n->next) + if(strcasecmp(brdname, n->brdname) == 0) + return 1; + return 0; +} + +void add_hash(char *brdname) { + int i; + hash_t *n; + + i = string_hash(brdname); + + n = malloc(sizeof(*n)); + n->brdname = strdup(brdname); + n->next = hash_tbl[i]; + hash_tbl[i] = n; +} + +void merge_board(boardheader_t *b) { + if(!is_exist(b->brdname)) { + fwrite(b, sizeof(*b), 1, fout); + add_hash(b->brdname); + ++counter; + } +} + +void merge_file(char *fname) { + FILE *fin; + boardheader_t b; + + if((fin = fopen(fname, "r")) == NULL) { + perror(fname); + return; + } + + counter = 0; + while(fread(&b, sizeof(b), 1, fin) == 1) + if(b.brdname[0]) + merge_board(&b); + + printf("merge from %s: %d boards\n", fname, counter); + + fclose(fin); +} + +int main(int argc, char **argv) { + int i; + + if(argc < 2) { + usage(); + return 1; + } + + bzero(hash_tbl, sizeof(hash_tbl)); + + if((fout = fopen(argv[1], "w")) == NULL) { + perror(argv[1]); + return 2; + } + + for(i = 2; i < argc; ++i) + merge_file(argv[i]); + + fclose(fout); + printf("Done\n"); + + return 0; +} diff --git a/pttbbs/util/merge_passwd.c b/pttbbs/util/merge_passwd.c new file mode 100644 index 00000000..d27c473b --- /dev/null +++ b/pttbbs/util/merge_passwd.c @@ -0,0 +1,106 @@ +/* $Id: merge_passwd.c,v 1.1 2002/03/07 15:13:46 in2 Exp $ */ +#include +#include +#include +#include +#include +#include "config.h" +#include "pttstruct.h" + +typedef struct hash_t { + char *userid; + struct hash_t *next; +} hash_t; + +FILE *fout; +hash_t *hash_tbl[65536]; +int counter; + +void usage() { + fprintf(stderr, "Usage:\n\n" + "merge_passwd [input file1] [input file2] ...\n"); +} + +unsigned int string_hash(unsigned char *s) { + unsigned int v=0; + + while(*s) { + v = (v << 8) | (v >> 24); + v ^= toupper(*s++); /* note this is case insensitive */ + } + return (v * 2654435769UL) >> (32 - 16); +} + +int is_exist(char *userid) { + int i; + hash_t *n; + + i = string_hash(userid); + for(n = hash_tbl[i]; n != NULL; n = n->next) + if(strcasecmp(userid, n->userid) == 0) + return 1; + return 0; +} + +void add_hash(char *userid) { + int i; + hash_t *n; + + i = string_hash(userid); + + n = malloc(sizeof(*n)); + n->userid = strdup(userid); + n->next = hash_tbl[i]; + hash_tbl[i] = n; +} + +void merge_user(userec_t *u) { + if(!is_exist(u->userid)) { + fwrite(u, sizeof(*u), 1, fout); + add_hash(u->userid); + ++counter; + } +} + +void merge_file(char *fname) { + FILE *fin; + userec_t u; + + if((fin = fopen(fname, "r")) == NULL) { + perror(fname); + return; + } + + counter = 0; + while(fread(&u, sizeof(u), 1, fin) == 1) + if(u.userid[0]) + merge_user(&u); + + printf("merge from %s: %d users\n", fname, counter); + + fclose(fin); +} + +int main(int argc, char **argv) { + int i; + + if(argc < 2) { + usage(); + return 1; + } + + bzero(hash_tbl, sizeof(hash_tbl)); + + if((fout = fopen(argv[1], "w")) == NULL) { + perror(argv[1]); + return 2; + } + + for(i = 2; i < argc; ++i) + merge_file(argv[i]); + + fclose(fout); + printf("Done\n"); + + return 0; +} diff --git a/pttbbs/util/opendice.sh b/pttbbs/util/opendice.sh new file mode 100644 index 00000000..767e213a --- /dev/null +++ b/pttbbs/util/opendice.sh @@ -0,0 +1,10 @@ +#!/bin/sh +# $Id: opendice.sh,v 1.1 2002/03/07 15:13:46 in2 Exp $ + +bin/countalldice > etc/dice.dis +bin/post Record "骰子中獎名單" "[骰子報告]" etc/windice.log +bin/post Security "骰子失敗名單" "[骰子報告]" etc/lostdice.log +bin/post Security "骰子期望值" "[骰子報告]" etc/dice.dis +rm -f etc/windice.log +rm -f etc/lostdice.log +rm -f etc/dice.dis diff --git a/pttbbs/util/openticket.c b/pttbbs/util/openticket.c new file mode 100644 index 00000000..69b9ab2a --- /dev/null +++ b/pttbbs/util/openticket.c @@ -0,0 +1,198 @@ +/* $Id: openticket.c,v 1.1 2002/03/07 15:13:46 in2 Exp $ */ +/* 開獎的 utility */ +#include +#include +#include +#include +#include +#include "config.h" +#include "pttstruct.h" +#include "common.h" +#include "util.h" + + +static char *betname[8] = {"Ptt", "Jaky", "Action", "Heat", + "DUNK", "Jungo", "waiting", "wofe"}; + +#define MAX_DES 7 /* 最大保留獎數 */ + +extern userec_t xuser; + +int Link(char *src, char *dst) +{ + char cmd[200]; + + if (link(src, dst) == 0) + return 0; + + sprintf(cmd, "/bin/cp -R %s %s", src, dst); + return system(cmd); +} + +char * + Cdatelite(clock) +time_t *clock; +{ + static char foo[18]; + struct tm *mytm = localtime(clock); + + strftime(foo, 18, "%D %T", mytm); + return (foo); +} + + +int main() +{ + int money, bet, n, total = 0, ticket[8] = + {0, 0, 0, 0, 0, 0, 0, 0}; + FILE *fp; + time_t now = time(NULL); + char des[MAX_DES][200] = + {"", "", "", ""}; + extern struct utmpfile_t *utmpshm; + + if(passwd_mmap()) + exit(1); + + rename(BBSHOME "/etc/" FN_TICKET_RECORD, + BBSHOME "/etc/" FN_TICKET_RECORD ".tmp"); + rename(BBSHOME "/etc/" FN_TICKET_USER, + BBSHOME "/etc/" FN_TICKET_USER ".tmp"); + + if (!(fp = fopen(BBSHOME "/etc/"FN_TICKET_RECORD ".tmp", "r"))) + return 0; + fscanf(fp, "%9d %9d %9d %9d %9d %9d %9d %9d\n", + &ticket[0], &ticket[1], &ticket[2], &ticket[3], + &ticket[4], &ticket[5], &ticket[6], &ticket[7]); + for (n = 0; n < 8; n++) + total += ticket[n]; + fclose(fp); + + if (!total) + return 0; + + if((fp = fopen(BBSHOME "/etc/" FN_TICKET , "r"))) + { + for (n = 0; n < MAX_DES && fgets(des[n], 200, fp); n++) ; + fclose(fp); + } + +/* + *srandom(33); // 固定一個 seed 但盡量要避免跟別人的seed同 + * + *for( n = (now / (60*60*3)) - 62820; n >0; n--) random(); + */ + +/* + * 正確的random number generator的用法 + * 是用同一個 seed後取 第一個 第二個 地三個.... 數 + * srand() 設完seed後 + * 每呼叫一次rand()就取下一個數 + * + * 但因為我們沒有記錄上次取到第幾個 + * 所以用每增四小時()就多取一次 => now / (60*60*4) (每五小時開一次獎) + * (減 61820 是減少 loop 數) + * + * 本來是用srand(time(0)) 不是正確的用法 + * 因為開獎時間有規率 所以會被找出規律 + * + * ~Ptt + */ +/* + *bet=random() % 8; + */ + + resolve_utmp(); + bet = utmpshm->number % 8; + +/* + + * 在C中 srand 跟 srandom 一樣 rand 跟 random 一樣 + * 不同的是 rand 是傳回一個 double 給非整數的亂數用 + * random 是傳回一個 int 給整數的亂數用 + * + * 若要以rand inplement 整數的亂數 要注意以下 (man page中有) + * + * In Numerical Recipes in C: The Art of Scientific Computing + * (William H. Press, Brian P. Flannery, Saul A. Teukolsky, + * William T. Vetterling; New York: Cambridge University + * Press, 1990 (1st ed, p. 207)), the following comments are + * made: + * "If you want to generate a random integer between 1 + * and 10, you should always do it by + * + * j=1+(int) (10.0*rand()/(RAND_MAX+1.0)); + * + * and never by anything resembling + * + * j=1+((int) (1000000.0*rand()) % 10); + * + * (which uses lower-order bits)." + * + * Random-number generation is a complex topic. The Numeri- + * cal Recipes in C book (see reference above) provides an + * excellent discussion of practical random-number generation + * issues in Chapter 7 (Random Numbers). + * ~ Ptt + */ + + + money = ticket[bet] ? total * 95 / ticket[bet] : 9999999; + + if((fp = fopen(BBSHOME "/etc/" FN_TICKET, "w"))) + { + if (des[MAX_DES - 1][0]) + n = 1; + else + n = 0; + + for (; n < MAX_DES && des[n][0] != 0; n++) + { + fprintf(fp, des[n]); + } + + printf("\n\n開獎時間: %s \n\n" + "開獎結果: %s \n\n" + "下注總金額: %d00 元 \n" + "中獎比例: %d張/%d張 (%f)\n" + "每張中獎彩票可得 %d 枚P幣 \n\n", + Cdatelite(&now), betname[bet], total, ticket[bet], total, + (float) ticket[bet] / total, money); + + fprintf(fp, "%s 賭盤開出:%s 總金額:%d00 元 獎金/張:%d 元 機率:%1.2f\n", + Cdatelite(&now), betname[bet], total, money, + (float) ticket[bet] / total); + fclose(fp); + + } + + if (ticket[bet] && (fp = fopen(BBSHOME "/etc/" FN_TICKET_USER ".tmp", "r"))) + { + int mybet, num, uid; + char userid[20], genbuf[200]; + fileheader_t mymail; + + while (fscanf(fp, "%s %d %d\n", userid, &mybet, &num) != EOF) + { + if (mybet == bet) + { + printf("恭喜 %-15s買了%9d 張 %s, 獲得 %d 枚P幣\n" + ,userid, num, betname[mybet], money * num); + if((uid=getuser(userid))==0) continue; + deumoney(uid, money * num); + sprintf(genbuf, BBSHOME "/home/%c/%s", userid[0], userid); + stampfile(genbuf, &mymail); + strcpy(mymail.owner, BBSNAME); + sprintf(mymail.title, "[%s] 中獎囉! $ %d", Cdatelite(&now), money * num); + mymail.savemode = 0; + unlink(genbuf); + Link(BBSHOME "/etc/ticket", genbuf); + sprintf(genbuf, BBSHOME "/home/%c/%s/.DIR", userid[0], userid); + append_record(genbuf, &mymail, sizeof(mymail)); + } + } + } + unlink(BBSHOME "/etc/" FN_TICKET_RECORD ".tmp"); + unlink(BBSHOME "/etc/" FN_TICKET_USER ".tmp"); + return 0; +} diff --git a/pttbbs/util/openticket.sh b/pttbbs/util/openticket.sh new file mode 100644 index 00000000..8274e5c3 --- /dev/null +++ b/pttbbs/util/openticket.sh @@ -0,0 +1,10 @@ +#!/bin/sh +# $Id: openticket.sh,v 1.1 2002/03/07 15:13:46 in2 Exp $ + +bin/openticket > etc/jackpot +bin/post Record "彩券中獎名單" "[賭場報告]" etc/jackpot +bin/post Record "猜數字中獎名單" "[猜數字報告]" etc/winguess.log +bin/post Record "黑白棋對戰記錄" "[猜數字報告]" etc/othello.log +rm -f etc/winguess.log +rm -f etc/loseguess.log +rm -f etc/othello.log diff --git a/pttbbs/util/openvice.c b/pttbbs/util/openvice.c new file mode 100644 index 00000000..9b5e438f --- /dev/null +++ b/pttbbs/util/openvice.c @@ -0,0 +1,54 @@ +/* $Id: openvice.c,v 1.1 2002/03/07 15:13:46 in2 Exp $ */ +/* 發票開獎小程式 */ + +#include +#include +#include +#include +#include +#include "config.h" +#include "pttstruct.h" +#include "util.h" + +#define VICE_SHOW BBSHOME "/etc/vice.show1" +#define VICE_BINGO BBSHOME "/etc/vice.bingo" +#define VICE_NEW "vice.new" +#define VICE_DATA "vice.data" +#define MAX_BINGO 99999999 + +int main() +{ + char TABLE[5][3] = + {"一", "二", "三", "四", "五"}; + + int i = 0, bingo, base = 0; + + + FILE *fp = fopen(VICE_SHOW, "w"), *fb = fopen(VICE_BINGO, "w"); + + extern struct utmpfile_t *utmpshm; + resolve_utmp(); + + srand(utmpshm->number); + + if (!fp || !fb ) + perror("error open file"); + + + bingo = rand() % MAX_BINGO; + fprintf(fp, "%1c統一發票中獎號碼\n", ' '); + fprintf(fp, "%1c================\n", ' '); + fprintf(fp, "%1c特別獎: %08d\n\n", ' ', bingo); + fprintf(fb, "%d\n", bingo); + + while (i < 5) + { + bingo = (base + rand()) % MAX_BINGO; + fprintf(fp, "%1c第%s獎: %08d\n", ' ', TABLE[i], bingo); + fprintf(fb, "%08d\n", bingo); + i++; + } + fclose(fp); + fclose(fb); + return 0; +} diff --git a/pttbbs/util/outmail.c b/pttbbs/util/outmail.c new file mode 100644 index 00000000..d6b19bb4 --- /dev/null +++ b/pttbbs/util/outmail.c @@ -0,0 +1,274 @@ +/* $Id: outmail.c,v 1.1 2002/03/07 15:13:46 in2 Exp $ */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "config.h" +#include "pttstruct.h" + + +#ifdef HAVE_SETPROCTITLE + +#include +#include + +void initsetproctitle(int argc, char **argv, char **envp) { +} + +#else + +#include +#include +#include +#include + +char **Argv = NULL; /* pointer to argument vector */ +char *LastArgv = NULL; /* end of argv */ +extern char **environ; + +void initsetproctitle(int argc, char **argv, char **envp) { + register int i; + + /* Move the environment so setproctitle can use the space at + the top of memory. */ + for(i = 0; envp[i]; i++); + environ = malloc(sizeof(char *) * (i + 1)); + for(i = 0; envp[i]; i++) + environ[i] = strdup(envp[i]); + environ[i] = NULL; + + /* Save start and extent of argv for setproctitle. */ + Argv = argv; + if(i > 0) + LastArgv = envp[i - 1] + strlen(envp[i - 1]); + else + LastArgv = argv[argc - 1] + strlen(argv[argc - 1]); +} + +static void do_setproctitle(const char *cmdline) { + char buf[256], *p; + int i; + + strncpy(buf, cmdline, 256); + buf[255] = '\0'; + i = strlen(buf); + if(i > LastArgv - Argv[0] - 2) { + i = LastArgv - Argv[0] - 2; + } + strcpy(Argv[0], buf); + p = &Argv[0][i]; + while(p < LastArgv) + *p++='\0'; + Argv[1] = NULL; +} + +void setproctitle(const char* format, ...) { + char buf[256]; + + va_list args; + va_start(args, format); + vsprintf(buf, format,args); + do_setproctitle(buf); + va_end(args); +} +#endif + + + + + +#define SPOOL BBSHOME "/out" +#define INDEX SPOOL "/.DIR" +#define NEWINDEX SPOOL "/.DIR.sending" +#define FROM ".bbs@" MYHOSTNAME +#define SMTPPORT 25 + +int waitReply(int sock) { + char buf[256]; + + if(read(sock, buf, sizeof(buf)) <= 0) + return -1; + else + return buf[0] - '0'; +} + +int sendRequest(int sock, char *request) { + return write(sock, request, strlen(request)) < 0 ? -1 : 0; +} + +int connectMailServer() { + int sock; + struct sockaddr_in addr; + + if((sock = socket(PF_INET, SOCK_STREAM, 0)) < 0) { + perror("socket"); + return -1; + } + + memset(&addr, 0, sizeof(addr)); +#ifdef FreeBSD + addr.sin_len = sizeof(addr); +#endif + addr.sin_family = AF_INET; + addr.sin_port = htons(SMTPPORT); + addr.sin_addr.s_addr = inet_addr(RELAY_SERVER_IP); + + if(connect(sock, (struct sockaddr *)&addr, sizeof(addr)) < 0) { + perror(RELAY_SERVER_IP); + close(sock); + return -1; + } + + if(waitReply(sock) != 2) { + close(sock); + return -1; + } + + if(sendRequest(sock, "helo " MYHOSTNAME "\n") || waitReply(sock) != 2) { + close(sock); + return -1; + } else + return sock; +} + +void disconnectMailServer(int sock) { + sendRequest(sock, "quit\n"); + /* drop the reply :p */ + close(sock); +} + +void doSendBody(int sock, FILE *fp, char *from, char *to, char *subject) { + int n; + char buf[2048]; + + n = snprintf(buf, sizeof(buf), "From: %s\nTo: %s\nSubject: %s\n\n", + from, to, subject); + write(sock, buf, n); + + while(fgets(buf, sizeof(buf), fp)) { + if(buf[0] == '.' && buf[1] == '\n') + strcpy(buf, "..\n"); + write(sock, buf, strlen(buf)); + } +} + +void doSendMail(int sock, FILE *fp, char *from, char *to, char *subject) { + char buf[256]; + + snprintf(buf, sizeof(buf), "mail from: %s\n", from); + if(sendRequest(sock, buf) || waitReply(sock) != 2) + return; + + snprintf(buf, sizeof(buf), "rcpt to: %s\n", to); + if(sendRequest(sock, buf) || waitReply(sock) != 2) + return; + + if(sendRequest(sock, "data\n") || waitReply(sock) != 3) + return; + + doSendBody(sock, fp, from, to, subject); + + if(sendRequest(sock, "\n.\n") || waitReply(sock) != 2) + return; +} + +void sendMail() { + int fd, sock; + MailQueue mq; + + if(access(NEWINDEX, R_OK | W_OK)) { + if(link(INDEX, NEWINDEX) || unlink(INDEX)) + /* nothing to do */ + return; + } + + if((sock = connectMailServer()) < 0) { + fprintf(stderr, "connect server failed...\n"); + return; + } + + fd = open(NEWINDEX, O_RDONLY); + flock(fd, LOCK_EX); + while(read(fd, &mq, sizeof(mq)) > 0) { + FILE *fp; + char buf[256]; + + snprintf(buf, sizeof(buf), "%s%s", mq.sender, FROM); + if((fp = fopen(mq.filepath, "r"))) { + setproctitle("outmail: sending %s", mq.filepath); + doSendMail(sock, fp, buf, mq.rcpt, mq.subject); + fclose(fp); + unlink(mq.filepath); + } else { + perror(mq.filepath); + } + } + flock(fd, LOCK_UN); + close(fd); + unlink(NEWINDEX); + + disconnectMailServer(sock); +} + +void listQueue() { + int fd; + + if((fd = open(INDEX, O_RDONLY)) >= 0) { + int counter = 0; + MailQueue mq; + + flock(fd, LOCK_EX); + while(read(fd, &mq, sizeof(mq)) > 0) { + printf("%s:%s -> %s:%s\n", mq.filepath, mq.username, mq.rcpt, + mq.subject); + counter++; + } + flock(fd, LOCK_UN); + close(fd); + printf("\nTotal: %d mails in queue\n", counter); + } else { + perror(INDEX); + } +} + +void usage() { + fprintf(stderr, "usage: outmail [-qh]\n"); +} + +void wakeup(int s) { +} + +int main(int argc, char **argv, char **envp) { + int ch; + + signal(SIGHUP, wakeup); + initsetproctitle(argc, argv, envp); + + if(chdir(BBSHOME)) + return 1; + while((ch = getopt(argc, argv, "qh")) != -1) { + switch(ch) { + case 'q': + listQueue(); + return 0; + default: + usage(); + return 0; + } + } + for(;;) { + sendMail(); + setproctitle("outmail: sleeping"); + sleep(60 * 3); /* send mail every 3 minute */ + } + return 0; +} diff --git a/pttbbs/util/parse_news.c b/pttbbs/util/parse_news.c new file mode 100644 index 00000000..bebed3f4 --- /dev/null +++ b/pttbbs/util/parse_news.c @@ -0,0 +1,78 @@ +/* $Id: parse_news.c,v 1.1 2002/03/07 15:13:46 in2 Exp $ */ +#include +#include +#include +#include +#include +#include +#include +#include "config.h" +#include "pttstruct.h" +#include "util.h" + +#define NEWSDIRECT BBSHOME "/boards/newspaper" +#define MOVIEDIRECT BBSHOME "/etc/NEWS" + +int main() { + int fd; + fileheader_t fh, news; + struct stat st; + register int numfiles, n; + FILE *fp = NULL; + char buf[200]; + + if (stat(NEWSDIRECT "/.DIR", &st) < 0) + return 0; + + system("rm -f " MOVIEDIRECT "/*"); + system("rm -f " MOVIEDIRECT "/.DIR"); + + numfiles = st.st_size / sizeof(fileheader_t); + n = 0; + if ((fd = open(NEWSDIRECT "/.DIR", O_RDONLY)) > 0) + { + lseek(fd, st.st_size - sizeof(fileheader_t), SEEK_SET); + while (numfiles-- && n < 100) + { + read(fd, &fh, sizeof(fileheader_t)); + if (!strcmp(fh.owner, "CNA-News.")) + { + if (!strstr(fh.title, "活動預告") && !strstr(fh.title, "中央氣象局") + && !strstr(fh.title, "歷史上的今天") && !strstr(fh.title, "頭條新聞標題") + && !strstr(fh.title, "Summary") && !strstr(fh.title, "全球氣象一覽") + && !strstr(fh.title, "校正公電")) + { + if (!(n % 10)) + { + if (n) + { + fclose(fp); + append_record(MOVIEDIRECT "/.DIR", &news, sizeof(news)); + } + strcpy(buf, MOVIEDIRECT); + stampfile(buf, &news); + sprintf(news.title, "中央社即時新聞 %s", fh.date); + strcpy(news.owner, "CNA-News."); + news.savemode = 0; + if (!(fp = fopen(buf, "w"))) + return (0); + fprintf(fp, " ───────── 中央社即時新聞 (%s)──────────\n", + fh.date); + } + fprintf(fp, " ─────◇ [1;3%dm%s %.*s\n", + (n % 6 + 4) % 7 + 1, fh.title, + (int)(46 - strlen(fh.title)), + "───────────────────"); + n++; + printf("[%d]\n", n); + + } + } + lseek(fd, -(off_t) 2 * sizeof(fileheader_t), SEEK_CUR); + } + close(fd); + fclose(fp); + append_record(MOVIEDIRECT "/.DIR", &news, sizeof(news)); + } + return 0; +} diff --git a/pttbbs/util/post.c b/pttbbs/util/post.c new file mode 100644 index 00000000..efec797f --- /dev/null +++ b/pttbbs/util/post.c @@ -0,0 +1,61 @@ +/* $Id: post.c,v 1.1 2002/03/07 15:13:46 in2 Exp $ */ +#include +#include +#include +#include +#include "config.h" +#include "pttstruct.h" +#include "util.h" + +void keeplog(FILE *fin, char *fpath, char *board, char *title, char *owner) { + fileheader_t fhdr; + char genbuf[256], buf[512]; + FILE *fout; + int bid; + + sprintf(genbuf, BBSHOME "/boards/%s", board); + stampfile(genbuf, &fhdr); + + if(!(fout = fopen(genbuf, "w"))) { + perror(genbuf); + return; + } + + while(fgets(buf, 512, fin)) + fputs(buf, fout); + + fclose(fin); + fclose(fout); + + strncpy(fhdr.title, title, sizeof(fhdr.title) - 1); + fhdr.title[sizeof(fhdr.title) - 1] = '\0'; + + strcpy(fhdr.owner, owner); + sprintf(genbuf, BBSHOME "/boards/%s/.DIR", board); + append_record(genbuf, &fhdr, sizeof(fhdr)); + if((bid = getbnum(board)) > 0) + touchbtotal(bid); + +} + +int main(int argc, char **argv) { + FILE *fp; + + resolve_boards(); + if(argc != 5) { + printf("usage: %s <owner> <file>\n", argv[0]); + return 0; + } + + if(strcmp(argv[4], "-") == 0) + fp = stdin; + else { + fp = fopen(argv[4], "r"); + if(!fp) { + perror(argv[4]); + return 1; + } + } + keeplog(fp, argv[4], argv[1], argv[2], argv[3]); + return 0; +} diff --git a/pttbbs/util/poststat.c b/pttbbs/util/poststat.c new file mode 100644 index 00000000..3aa3cc94 --- /dev/null +++ b/pttbbs/util/poststat.c @@ -0,0 +1,497 @@ +/* $Id: poststat.c,v 1.1 2002/03/07 15:13:46 in2 Exp $ */ +/* 統計今日、週、月、年熱門話題 */ + +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <fcntl.h> +#include <time.h> +#include <sys/types.h> +#include <sys/ipc.h> +#include <sys/shm.h> + +#ifdef __FreeBSD__ +#include <machine/param.h> +#endif + +#include "config.h" +#include "pttstruct.h" + +char *myfile[] = +{"day", "week", "month", "year"}; +int mycount[4] = +{7, 4, 12}; +int mytop[] = +{10, 50, 100, 100}; +char *mytitle[] = +{"日十", "週五十", "月百", "年度百"}; + + +#define HASHSIZE 1024 +#define TOPCOUNT 200 + + +struct postrec +{ + char author[13]; /* author name */ + char board[13]; /* board name */ + char title[66]; /* title name */ + time_t date; /* last post's date */ + int number; /* post number */ + struct postrec *next; /* next rec */ +} +*bucket[HASHSIZE]; + + +/* 100 bytes */ +struct posttop +{ + char author[13]; /* author name */ + char board[13]; /* board name */ + char title[66]; /* title name */ + time_t date; /* last post's date */ + int number; /* post number */ +} +top[TOPCOUNT], *tp; + + + +/* + woju + Cross-fs rename() + */ + +int Rename(char *src, char *dst) +{ + + if (rename(src, dst) == 0) + return 0; +/* + sprintf(cmd, "/bin/mv %s %s", src, dst); + return system(cmd); +*/ + return 0; +} + + + +/*-------------------------------------------------------*/ +/* .BOARDS cache */ +/*-------------------------------------------------------*/ + +struct bcache_t *brdshm; +boardheader_t *bcache; +int numboards = -1; + + +static void +attach_err(shmkey, name) + int shmkey; + char *name; +{ + fprintf(stderr, "[%s error] key = %x\n", name, shmkey); + exit(1); +} + + +static void * +attach_shm(shmkey, shmsize) + int shmkey, shmsize; +{ + void *shmptr; + int shmid; + + shmid = shmget(shmkey, shmsize, 0); + if (shmid < 0) + { + shmid = shmget(shmkey, shmsize, IPC_CREAT | 0600); + if (shmid < 0) + attach_err(shmkey, "shmget"); + shmptr = (void *) shmat(shmid, NULL, 0); + if (shmptr == (void *) -1) + attach_err(shmkey, "shmat"); + memset(shmptr, 0, shmsize); + } + else + { + shmptr = (void *) shmat(shmid, NULL, 0); + if (shmptr == (void *) -1) + attach_err(shmkey, "shmat"); + } + return shmptr; +} + + + +void +resolve_boards() +{ + if (brdshm == NULL) + { + brdshm = attach_shm(BRDSHM_KEY, sizeof(*brdshm)); + if (brdshm->touchtime == 0) + brdshm->touchtime = 1; + bcache = brdshm->bcache; + } + + while (brdshm->uptime < brdshm->touchtime) + { + if (brdshm->busystate) + { + sleep(1); + } + else + { + int fd; + + brdshm->busystate = 1; + + if ((fd = open(".BOARDS", O_RDONLY)) > 0) + { + brdshm->number = read(fd, bcache, MAX_BOARD * sizeof(boardheader_t)) + / sizeof(boardheader_t); + close(fd); + } + + /* 等所有 boards 資料更新後再設定 uptime */ + + brdshm->uptime = brdshm->touchtime; + brdshm->busystate = 0; + } + } + numboards = brdshm->number; +} + + +int +ci_strcmp(s1, s2) + register char *s1, *s2; +{ + register int c1, c2, diff; + + do + { + c1 = *s1++; + c2 = *s2++; + if (c1 >= 'A' && c1 <= 'Z') + c1 |= 32; + if (c2 >= 'A' && c2 <= 'Z') + c2 |= 32; + if((diff = c1 - c2)) + return (diff); + } + while (c1); + return 0; +} + +int +get_record(fpath, rptr, size, id) + char *fpath; + char *rptr; + int size, id; +{ + int fd; + + if ((fd = open(fpath, O_RDONLY, 0)) != -1) + { + if (lseek(fd, size * (id - 1), SEEK_SET) != -1) + { + if (read(fd, rptr, size) == size) + { + close(fd); + return 0; + } + } + close(fd); + } + return -1; +} + + +int +getbnum(bname) + char *bname; +{ + register int i; + register boardheader_t *bhdr; + + resolve_boards(); + for (i = 0, bhdr = bcache; i++ < numboards; bhdr++) + /* if (Ben_Perm(bhdr)) */ + if (!ci_strcmp(bname, bhdr->brdname)) + return i; + return 0; +} + + +int +hash(key) + char *key; +{ + int i, value = 0; + + for (i = 0; key[i] && i < 80; i++) + value += key[i] < 0 ? -key[i] : key[i]; + + value = value % HASHSIZE; + return value; +} + + +/* ---------------------------------- */ +/* hash structure : array + link list */ +/* ---------------------------------- */ + + +void +search(t) + struct posttop *t; +{ + struct postrec *p, *q, *s; + int i, found = 0; + + i = hash(t->title); + q = NULL; + p = bucket[i]; + while (p && (!found)) + { + if (!strcmp(p->title, t->title) && !strcmp(p->board, t->board)) + found = 1; + else + { + q = p; + p = p->next; + } + } + if (found) + { + p->number += t->number; + if (p->date < t->date) /* 取較近日期 */ + p->date = t->date; + } + else + { + s = (struct postrec *) malloc(sizeof(struct postrec)); + memcpy(s, t, sizeof(struct posttop)); + s->next = NULL; + if (q == NULL) + bucket[i] = s; + else + q->next = s; + } +} + + +int +sort(pp, count) + struct postrec *pp; +{ + int i, j; + + for (i = 0; i <= count; i++) + { + if (pp->number > top[i].number) + { + if (count < TOPCOUNT - 1) + count++; + for (j = count - 1; j >= i; j--) + memcpy(&top[j + 1], &top[j], sizeof(struct posttop)); + + memcpy(&top[i], pp, sizeof(struct posttop)); + break; + } + } + return count; +} + + +void +load_stat(fname) + char *fname; +{ + FILE *fp; + + if((fp = fopen(fname, "r"))) + { + int count = fread(top, sizeof(struct posttop), TOPCOUNT, fp); + fclose(fp); + while (count) + search(&top[--count]); + } +} + + +int +filter(board) + char *board; +{ + boardheader_t bh; + int bid; + + bid = getbnum(board); + if (get_record(".BOARDS", &bh, sizeof(bh), bid) == -1) + return 1; + if (bh.brdattr & BRD_NOCOUNT) + return 1; +/* + if (bh.brdattr & BRD_POSTMASK) + return 0; + return (bh.brdattr & ~BRD_POSTMASK) || + >= 32; +*/ + return 0; +} + + +void +poststat(mytype) + int mytype; +{ + static char *logfile = ".post"; + static char *oldfile = ".post.old"; + + FILE *fp; + char buf[40], curfile[40] = "etc/day.0", *p; + struct postrec *pp; + int i, j; + + if (mytype < 0) + { + /* --------------------------------------- */ + /* load .post and statictic processing */ + /* --------------------------------------- */ + + remove(oldfile); + Rename(logfile, oldfile); + if ((fp = fopen(oldfile, "r")) == NULL) + return; + mytype = 0; + load_stat(curfile); + + while (fread(top, sizeof(struct posttop), 1, fp)) + search(top); + fclose(fp); + } + else + { + /* ---------------------------------------------- */ + /* load previous results and statictic processing */ + /* ---------------------------------------------- */ + + i = mycount[mytype]; + p = myfile[mytype]; + while (i) + { + sprintf(buf, "etc/%s.%d", p, i); + sprintf(curfile, "etc/%s.%d", p, --i); + load_stat(curfile); + Rename(curfile, buf); + } + mytype++; + } + +/* ---------------------------------------------- */ +/* sort top 100 issue and save results */ +/* ---------------------------------------------- */ + + memset(top, 0, sizeof(top)); + for (i = j = 0; i < HASHSIZE; i++) + { + for (pp = bucket[i]; pp; pp = pp->next) + { +#ifdef DEBUG + printf("Title : %s, Board: %s\nPostNo : %d, Author: %s\n" + ,pp->title + ,pp->board + ,pp->number + ,pp->author); +#endif + + j = sort(pp, j); + } + } + + p = myfile[mytype]; + sprintf(curfile, "etc/%s.0", p); + if((fp = fopen(curfile, "w"))) + { + fwrite(top, sizeof(struct posttop), j, fp); + fclose(fp); + } + + sprintf(curfile, "etc/%s", p); + if((fp = fopen(curfile, "w"))) + { + int max, cnt; + + fprintf(fp, "\t\t-----===== 本%s大熱門話題 =====-----\n\n", mytitle[mytype]); + + max = mytop[mytype]; + p = buf + 4; + for (i = cnt = 0; (cnt < max) && (i < j); i++) + { + tp = &top[i]; + if (filter(tp->board)) + continue; + + strcpy(buf, ctime(&(tp->date))); + buf[20] = 0; + fprintf(fp, + "%3d. 看板 : %-16s《 %s》%4d 篇%16s\n" + " 標題 : %-60.60s\n" + ,++cnt, tp->board, p, tp->number, tp->author, tp->title); + } + fclose(fp); + } + +/* free statistics */ + + for (i = 0; i < HASHSIZE; i++) + { + struct postrec *pp0; + + pp = bucket[i]; + while (pp) + { + pp0 = pp; + pp = pp->next; + free(pp0); + } + + bucket[i] = NULL; + } +} + + +int main(argc, argv) + char *argv[]; +{ + time_t now; + struct tm *ptime; + + if (argc < 2) + { + printf("Usage:\t%s bbshome [day]\n", argv[0]); + return (-1); + } + chdir(argv[1]); + + if (argc == 3) + { + poststat(atoi(argv[2])); + return (0); + } + time(&now); + ptime = localtime(&now); + if (ptime->tm_hour == 0) + { + if (ptime->tm_mday == 1) + poststat(2); + + if (ptime->tm_wday == 0) + poststat(1); + poststat(0); + } + poststat(-1); + return 0; +} diff --git a/pttbbs/util/reaper.c b/pttbbs/util/reaper.c new file mode 100644 index 00000000..925ea11b --- /dev/null +++ b/pttbbs/util/reaper.c @@ -0,0 +1,69 @@ +#include <stdio.h> +#include <stdlib.h> +#include <stdarg.h> +#include <string.h> +#include <time.h> +#include <syslog.h> +#include <unistd.h> +#include <ctype.h> +#include <sys/types.h> +#include "config.h" +#include "pttstruct.h" +#include "perm.h" +#include "util.h" + +time_t now; + +int invalid(char *userid) { + int i; + + if(!isalpha(userid[0])) + return 1; + + for(i = 1; i < IDLEN && userid[i]; i++) + if(!isalpha(userid[i]) && !isdigit(userid[i])) + return 1; + return 0; +} + +int check(int n, userec_t *u) { + time_t d; + char buf[256]; + + if(u->userid[0] != '\0') { + if(invalid(u->userid)) { + syslog(LOG_ERR, "bad userid(%d): %s", n, u->userid); + u->userid[0] = '\0'; + } else { + d = now - u->lastlogin; + if((d > MAX_GUEST_LIFE && (u->userlevel & PERM_LOGINOK) == 0) || + (d > MAX_LIFE && (u->userlevel & PERM_XEMPT) == 0)) { + /* expired */ + int unum; + + unum = searchuser(u->userid); + strcpy(buf, ctime(&u->lastlogin)); + strtok(buf, "\n"); + syslog(LOG_NOTICE, "kill user(%d): %s %s", unum, u->userid, buf); + sprintf(buf, "mv home/%c/%s tmp/", u->userid[0], u->userid); + if(system(buf)) + syslog(LOG_ERR, "can't move user home: %s", u->userid); + u->userid[0] = '\0'; + setuserid(unum, u->userid); + } + } + } + return 0; +} + +int main() { + now = time(NULL); + openlog("reaper", LOG_PID | LOG_PERROR, SYSLOG_FACILITY); + chdir(BBSHOME); + + if(passwd_mmap()) + exit(1); + passwd_apply2(check); + + return 0; +} diff --git a/pttbbs/util/rmuid.c b/pttbbs/util/rmuid.c new file mode 100644 index 00000000..cc6e12cb --- /dev/null +++ b/pttbbs/util/rmuid.c @@ -0,0 +1,50 @@ +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <dirent.h> +#include <unistd.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <unistd.h> +#include "config.h" +#include "pttstruct.h" +#include "util.h" + +extern int numboards; +extern boardheader_t *bcache; + +int getbidofuid(int uid) +{ + register int n; boardheader_t *bh; + if(!uid) return 1; + for (n=0;n<numboards;n++) + { + bh = &bcache[n]; + if(bh->unused == uid) + return n+1; + } + return 1; +} + +int main(int argc, char* argv[]){ +struct stat st; + int n; + boardheader_t bh; + char pathname[1024]; + + resolve_boards(); + for (n=0;n<numboards;n++) + { + memcpy( &bh, &bcache[n], sizeof(bh)); + bh.gid=getbidofuid(bh.gid); + //printf("%14.14s%14.14s \r\n",bh.brdname, bh.title); + substitute_record("BOARDS.bid", &bh, sizeof(bh), n+1); + } +} + + + + + + + diff --git a/pttbbs/util/shmsweep.c b/pttbbs/util/shmsweep.c new file mode 100644 index 00000000..01acb26b --- /dev/null +++ b/pttbbs/util/shmsweep.c @@ -0,0 +1,43 @@ +#include <stdio.h> +#include <stdlib.h> +#include <sys/types.h> +#include <sys/ipc.h> +#include <sys/shm.h> +#include <sys/stat.h> +#include "config.h" +#include "pttstruct.h" + +int main() { + int i, shm, counter; + struct utmpfile_t *utmpshm; + + + shm = shmget(UTMPSHM_KEY, USHM_SIZE, SHM_R | SHM_W); + if(shm == -1) { + perror("shmget"); + exit(0); + } + + utmpshm = shmat(shm, NULL, 0); + if(utmpshm == (struct utmpfile_t *)-1) { + perror("shmat"); + exit(0); + } + + for(i = counter = 0; i < USHM_SIZE; i++) + if(utmpshm->uinfo[i].pid) { + char buf[256]; + userinfo_t *f; + struct stat sb; + + f = &utmpshm->uinfo[i]; + sprintf(buf, "/proc/%d", f->pid); + if(stat(buf, &sb)) { + f->pid = 0; + utmpshm->number--; + counter++; + } + } + printf("clear %d slots\n", counter); + return 0; +} diff --git a/pttbbs/util/showboard.c b/pttbbs/util/showboard.c new file mode 100644 index 00000000..3801dbb1 --- /dev/null +++ b/pttbbs/util/showboard.c @@ -0,0 +1,70 @@ +/* $Id: showboard.c,v 1.1 2002/03/07 15:13:46 in2 Exp $ */ +/* 看板一覽表(sorted) */ + +#include <stdio.h> +#include <string.h> +#include <unistd.h> +#include <stdlib.h> +#include <sys/stat.h> +#include <fcntl.h> +#include "config.h" +#include "pttstruct.h" + +boardheader_t allbrd[MAX_BOARD]; + +int +board_cmp(a, b) + boardheader_t *a, *b; +{ + return (strcasecmp(a->brdname, b->brdname)); +} + + +int main(argc, argv) + int argc; + char *argv[]; +{ + int inf, i, count; + + if (argc < 2) + { + printf("Usage:\t%s .BOARDS [MAXUSERS]\n", argv[0]); + exit(1); + } + + + inf = open(argv[1], O_RDONLY); + if (inf == -1) + { + printf("error open file\n"); + exit(1); + } + +/* read in all boards */ + + i = 0; + memset(allbrd, 0, MAX_BOARD * sizeof(boardheader_t)); + while (read(inf, &allbrd[i], sizeof(boardheader_t)) == sizeof(boardheader_t)) + { + if (allbrd[i].brdname[0] ) + { + i++; + } + } + close(inf); + +/* sort them by name */ + count = i; + qsort(allbrd, count, sizeof(boardheader_t), board_cmp); + +/* write out the target file */ + + printf( + "看板名稱 板主 類別 中文敘述\n" + "----------------------------------------------------------------------\n"); + for (i = 0; i < count; i++) + { + printf("%-13s%-25.25s%s\n", allbrd[i].brdname, allbrd[i].BM, allbrd[i].title); + } + return 0; +} diff --git a/pttbbs/util/smtest.c b/pttbbs/util/smtest.c new file mode 100644 index 00000000..16a2360d --- /dev/null +++ b/pttbbs/util/smtest.c @@ -0,0 +1,296 @@ +#include <stdio.h> +#include <sys/types.h> +#include <unistd.h> +#include <string.h> +#include <stdlib.h> +#include <time.h> +#include <ctype.h> +#include "config.h" +#include "pttstruct.h" +#include "util.h" +#include "perm.h" +#include "common.h" +#include "proto.h" + +#define WARNFILE BBSHOME "/etc/DeleteBoard.warn" +#define EXECFILE BBSHOME"/etc/DeleteBoard.exec" +#define WARNLIST BBSHOME"/etc/DeleteBoardList.warn" +#define EXECLIST BBSHOME"/etc/DeleteBoardList.exec" + +extern boardheader_t *bcache; +extern int numboards; + +boardheader_t allbrd[MAX_BOARD]; +extern userec_t xuser; + + +int LINK(char* src, char* dst){ + char cmd[200]; + + if( link(src, dst) == 0){ + return 0; + } + + sprintf(cmd, "/bin/cp -R %s %s", src, dst); + return system(cmd); +} + +int outofdate(char *hdrdate, char thedate[], int *zf) +{ + int k = 0; + char *dd; + char latestdate[6]; + int date1[2], date2[2],datetemp; + *zf = 0; + + strcpy(latestdate, thedate); + + dd = strtok(hdrdate,"/"); + if(dd == NULL) return 2; + if(dd) + k = 0; + do{ + if (*dd == '[' ){dd[strlen(dd)-1]='\0'; dd++;} + date1[k] = atoi(dd); + k++; + } while((dd=strtok(NULL,"/ "))!=NULL); + + dd = strtok(latestdate,"/"); + if(dd) + k = 0; + do{ + if (*dd == '[' ){dd[strlen(dd)-1]='\0'; dd++;} + date2[k] = atoi(dd); + k++; + } while((dd=strtok(NULL,"/ "))!=NULL); + + if(date2[0] == date1[0] && date2[1] >= date1[1]) + return 0; + + datetemp = date2[0]; + + for(k = 1;k <= 5;k++) + { + datetemp -= 1; + if((datetemp) <= 0){ + datetemp = 12; + } + if(k < 3 && datetemp == date1[0]) return 0; + if(k == 3 && datetemp == date1[0] && date2[1] <= date1[1]) return 0; + if(k == 3 && datetemp == date1[0] && date2[1] > date1[1]) return 1; + if(k == 4 && datetemp == date1[0] && date2[1] > date1[1]) return 1; + } + *zf = 1; + return 1; +} + +void mailtouser(char *bmname, char *bname, int zf) +{ + fileheader_t mymail; + char genbuf[200]; + + sprintf(genbuf, BBSHOME "/home/%c/%s", bmname[0], bmname); + stampfile(genbuf, &mymail); + strcpy(mymail.owner, "[PTT警察局]"); + + if(zf == 0){ + sprintf(mymail.title,"\033[32m [廢版警告通知]" + "\033[m %s版(BM:%s)",bname, bmname); + }else{ + sprintf(mymail.title,"\033[32m [廢版通知] " + "\033[m %s版(BM:%s)",bname, bmname); + } + mymail.savemode = 0 ; + unlink(genbuf); + if(zf == 0){ + LINK(WARNFILE, genbuf); + }else{ + LINK(EXECFILE, genbuf); + } + + sprintf(genbuf, BBSHOME "/home/%c/%s/.DIR", bmname[0], bmname); + append_record(genbuf, &mymail, sizeof(mymail)); +} + +int main() +{ + int bmid, i, j, k, rd, ood, flag, zapflag = 0,warncount = 0,execcount = 0; + char *p, *bmsname[3], fname[256], hdrdatetemp[6],thedate[6]; + char bname[32],genbuf[200]; + fileheader_t hdr; + FILE *inf, *def; + + ///// set date ////// + time_t t = time(NULL); + struct tm *tm = localtime(&t); + sprintf(thedate, "%2d/%02d", tm->tm_mon + 1, tm->tm_mday); + + ////// board ////// + + resolve_boards(); + if(passwd_mmap()) + exit(1); + memcpy(allbrd,bcache,numboards*sizeof(boardheader_t)); + + ////// write out the target file ////// + inf = fopen(WARNLIST, "w+"); + if(inf == NULL){ + printf("open file error : %s\n", WARNLIST); + exit(1); + } + + def = fopen(EXECLIST, "w+"); + if(def == NULL) + { + printf("open file error : %s\n", EXECLIST); + exit(1); + } + + ////// fprint table title ///// + fprintf(inf,"\n[廢版警告]即日起一個月內若看板" + "使用率仍然過低,則予以廢除。\n\n" + "英文版名 類別 中文版名 日期 " + " 版主名單\n\n"); + + fprintf(def,"\n[廢版公告]下列看板因使用率仍然過低,故予以廢除。\n\n" + "英文版名 類別 中文版名 日期 " + " 版主名單\n\n"); + + ////// start process ///// + j = 0 ; + for (i = 0; i < numboards; i++) { + rd = 0; + if(allbrd[i].brdname[0] == '\0') continue; + if((allbrd[i].brdattr & BRD_NOZAP) || + (allbrd[i].brdattr & BRD_GROUPBOARD) || + (allbrd[i].brdattr & BRD_WARNDEL) || + (allbrd[i].brdattr & BRD_HIDE) || + (allbrd[i].brdattr & BRD_POSTMASK) || + (allbrd[i].brdattr & BRD_VOTEBOARD) || + (allbrd[i].brdattr & BRD_BAD) || + (allbrd[i].level != 0)) continue; + + sprintf(fname, BBSHOME "/boards/%s/.DIR",allbrd[i].brdname); + + /* get date to choose junk board */ + /* exception when ood == 2 */ + flag = 30; + rd = get_num_records(fname, sizeof(fileheader_t)); + if(rd <= 30) + { + get_record(fname, &hdr, sizeof (hdr), 1); + strcpy(hdrdatetemp, hdr.date); + ood = outofdate(hdrdatetemp,thedate, &zapflag); + } + else + { + do{ + if(rd == 0) + { + ood = 0; + break; + } + get_record(fname, &hdr, sizeof (hdr), rd - flag); + strcpy(hdrdatetemp, hdr.date); + ood = outofdate(hdrdatetemp,thedate, &zapflag); + flag += 5; + }while(ood == 2 && flag < 60); + } + if(ood == 0) continue; + + warncount++; + /* print to file */ + fprintf(inf,"%-*.*s%-*.*s %-*.*s%-*.*s\n", IDLEN, IDLEN, + allbrd[i].brdname, BTLEN-26, BTLEN-26, allbrd[i].title, + IDLEN - 5, IDLEN-5,hdr.date, IDLEN * 3, IDLEN * 3, allbrd[i].BM); + + /* post warn file to each board */ + sprintf(genbuf,"~/bin/post %s [廢版警告通知]" + " [PTT警察局] %s",allbrd[i].brdname,WARNFILE); + system(genbuf); + + /* user extract to mail */ + p=strtok(allbrd[i].BM,"/ "); + if(p){ + k = 0; + do + { + if (*p == '[' ){p[strlen(p)-1]='\0'; p++;} + bmid=getuser(p); + bmsname[k] = p; + if(isalpha(allbrd[i].BM[0])&& !(xuser.userlevel &PERM_SYSOP)) + { + mailtouser(bmsname[k],allbrd[i].title, zapflag); + } + k++; + } while((p=strtok(NULL,"/ "))!=NULL); + } + /* set attribute of DeleteBoardWarn Flag */ + bcache[i].brdattr = allbrd[i].brdattr | BRD_WARNDEL; + + /* zap boards */ + if (zapflag == 1) + { + execcount++; + /* print to file */ + fprintf(def,"%-*.*s%-*.*s %-*.*s%-*.*s\n", IDLEN, IDLEN, + allbrd[i].brdname, BTLEN-26, BTLEN-26, allbrd[i].title, + IDLEN - 5, IDLEN-5,hdr.date, IDLEN * 3, IDLEN * 3, allbrd[i].BM); + +// strcpy(bname, allbrd[i].brdname); +// sprintf(genbuf, +// "/bin/tar zcvf ~/tmp/board_%s.tgz boards/%s man/%s>/dev/null 2>&1;" +// "/bin/rm -fr ~/boards/%s man/%s",bname, bname, bname, bname,bname); +// system(genbuf); + +// memset(&allbrd[i], 0, sizeof(allbrd[i])); +// sprintf(allbrd[i].title, "[%s] deleted by System", bname); +// substitute_record(fn_board, &bh, sizeof(allbrd[i]), bid); +// reset_board(bid); + } + + } + + /* post to Record, ViolateLaw */ + if(warncount > 0){ + sprintf(genbuf,"~/bin/post Record [廢版警告通知]" + " [PTT警察局] %s",WARNLIST); + system(genbuf); + sprintf(genbuf,"~/bin/post ViolateLaw [廢版警告通知]" + " [PTT警察局] %s",WARNLIST); + system(genbuf); + } + if(execcount > 0){ + sprintf(genbuf,"~/bin/post Record [廢版公告]" + " [PTT警察局] %s",EXECLIST); + system(genbuf); + sprintf(genbuf,"~/bin/post ViolateLaw [廢版公告]" + " [PTT警察局] %s",EXECLIST); + system(genbuf); + } + + +/* Below is for test only */ +/* + mailtouser("Smile","test", 1); + mailtouser("Smile","test", 0); + + strcpy(bname, "Test"); + sprintf(genbuf,"~/bin/post %s test Smile ~/etc/test.fileaaa",bname); + system(genbuf); + + + bid = getbnum(bname); + strcpy(bname,"jourslamdunk"); + sprintf(genbuf, + "/bin/tar zcvf ~/tmp/board_%s.tgz boards/%s man/%s>/dev/null 2>&1;" + "/bin/rm -fr ~/boards/%s man/%s",bname, bname, bname,bname,bname); + system(genbuf); + + memset(&bh, 0, sizeof(bh)); + sprintf(bh.title, "[%s] deleted by %s", bname,cuser.userid); + substitute_record(fn_board, &bh, sizeof(bh), bid); + reset_board(bid); +*/ + return 0; +} diff --git a/pttbbs/util/smtest.c.save b/pttbbs/util/smtest.c.save new file mode 100644 index 00000000..7e678881 --- /dev/null +++ b/pttbbs/util/smtest.c.save @@ -0,0 +1,172 @@ +#include <stdio.h> +#include <sys/types.h> +#include <unistd.h> +#include <string.h> +#include <stdlib.h> +#include <time.h> +#include <ctype.h> +#include "config.h" +#include "pttstruct.h" +#include "util.h" +#include "perm.h" +#include "common.h" +#include "proto.h" + +#define OUTFILE BBSHOME "/pttbbs/util/smtest.result1" +#define FIREFILE BBSHOME "/pttbbs/util/smtest.result2" + +extern boardheader_t *bcache; +extern int numboards; + +boardheader_t allbrd[MAX_BOARD]; +struct userec_t xuser; + +int getuser(char *userid) { + int uid; + if((uid = searchuser(userid))) + passwd_query(uid, &xuser); + return uid; +} + +int LINK(char* src, char* dst){ + char cmd[200]; + + if( link(src, dst) == 0){ + return 0; + } + + sprintf(cmd, "/bin/cp -R %s %s", src, dst); + return system(cmd); +} + +int main() +{ + int bmid, i, j, k, rd; + char *p, *bmsname[3], bmbuf[IDLEN * 3 + 3], fname[256]; + fileheader_t hdr; + FILE *inf; + + resolve_boards(); + if(passwd_mmap()) + exit(1); + memcpy(allbrd,bcache,numboards*sizeof(boardheader_t)); + + /* write out the target file */ + inf = fopen(OUTFILE, "w+"); + if(inf == NULL){ + printf("open file error : %s\n", OUTFILE); + exit(1); + } + + /*the ouput table title*/ + fprintf(inf,"英文版名 類別 中文版名 版主名單" + " 日期 備註 \n"); + + j = 0 ; + for (i = 0; i < 30; i++) { + rd = 0; + if(allbrd[i].brdname[0] == '\0') continue; + + sprintf(fname, BBSHOME "/boards/%s/.DIR",allbrd[i].brdname); + + rd = get_num_records(fname, sizeof(fileheader_t)); + get_record(fname, &hdr, sizeof (hdr), rd - 30); +// printf(" %s %s\n",hdr.title,hdr.date); + + printf("%-*.*s%-*s%s", IDLEN, IDLEN, allbrd[i].brdname, BTLEN, + allbrd[i].title,allbrd[i].BM); + + p=strtok(allbrd[i].BM,"/ "); + if(p){ + int k = 0; + do + { + if (*p == '[' ){p[strlen(p)-1]='\0'; p++;} + bmid=getuser(p); + bmsname[k] = p; + if(isalpha(allbrd[i].BM[0])&& !(xuser.userlevel &PERM_SYSOP)) + { + // printf("%s", bmsname[k]); + } + k++; + } while((p=strtok(NULL,"/ "))!=NULL); + } + + printf("\n"); + +} + + +/* + + + + if(flag == 1){ + bmbuf[0] = '\0'; + for(k = 0 , n = 0; k < index; k++){ + if(!bms[k].flag){ + if( n++ != 0) strcat(bmbuf, "/"); + strcat(bmbuf, bms[k].bmname); + } + } + strcpy(bcache[i].BM, bmbuf); + } + } + qsort(lostbms, j, sizeof(lostbm), bmlostdays_cmp); + + //write to the etc/toplazyBM + for ( i=0; i<j; i++) + { + if( lostbms[i].lostdays > 60){ + fprintf(firef, "%-*.*s%-*.*s%-*.*s%3d天沒上站\n", IDLEN, IDLEN, + lostbms[i].title, BTLEN-10, BTLEN-10, lostbms[i].ctitle, IDLEN,IDLEN, + lostbms[i].bmname,lostbms[i].lostdays); + }else{ + fprintf(inf, "%-*.*s%-*.*s%-*.*s%3d天沒上站\n", IDLEN, IDLEN, lostbms[i].title, + BTLEN-10, BTLEN-10, lostbms[i].ctitle, IDLEN,IDLEN, + lostbms[i].bmname,lostbms[i].lostdays); + } + } + fclose(inf); + fclose(firef); + + //printf("Total %d boards.\n", count); + + //mail to the users + for( i=0; i<j; i++) + { + fileheader_t mymail; + char genbuf[200]; + int lostdays; + + lostdays = lostbms[i].lostdays; + + if( (lostdays != 30) && (lostdays != 45) && (lostdays <= 60)) + continue; + + sprintf(genbuf, BBSHOME "/home/%c/%s", lostbms[i].bmname[0], lostbms[i].bmname); + stampfile(genbuf, &mymail); + + strcpy(mymail.owner, "[PTT警察局]"); + + if(lostdays <= 60){ + sprintf(mymail.title, + "\033[32m [版主免職警告通知] \033[m %s BM %s", lostbms[i].title, lostbms[i].bmname); + }else{ + sprintf(mymail.title, + "\033[32m [版主免職通知] \033[m %s BM %s", lostbms[i].title, lostbms[i].bmname); + } + mymail.savemode = 0 ; + unlink(genbuf); + if(lostdays <= 60){ + LINK(OUTFILE, genbuf); + }else{ + LINK(FIREFILE, genbuf); + } + + sprintf(genbuf, BBSHOME "/home/%c/%s/.DIR", lostbms[i].bmname[0], lostbms[i].bmname); + append_record(genbuf, &mymail, sizeof(mymail)); + } +*/ + return 0; +} diff --git a/pttbbs/util/smtest.result1 b/pttbbs/util/smtest.result1 new file mode 100644 index 00000000..6dee45ff --- /dev/null +++ b/pttbbs/util/smtest.result1 @@ -0,0 +1,191 @@ +英文版名 類別 中文版名 日期 版主名單 +ck48th301 建中 ◎大槍幫之快樂天 3/21 ching/carl/Prosecuted +Bowling 運動 ●走過2000,邁向30 7/18 Genson/chiche +NTUCH-89 化學 ◎畢業啦!! 7/10 badora/furtwangler +SetupBBS BBS ◎TEST://140.112. 8/08 Libra +Fei-cat 圖文 ◎23:56 微酸味 8/07 tears +CKAWE 建中 ●建中校友管樂團 7/04 ckb/papl/trumpet +jourslamdunk待廢 ◎政大新聞系籃球 7/04 徵求中 +ck48th308 建中 ◎又要畢業了! 7/15 honest +CS84Her 中山 ◎各奔東西 也要和 7/20 +VM 星馬 ●疼光良品冠的責 7/20 zoo +E-Diagrams 校園 ◎一起八卦五千年. 6/29 Benjamin +ck48th313 建中 ●版主不管了,來灌 6/08 fantastic +ck48th324 建中 ◎哈哈哈... 7/10 +B853023XX 政治 ◎公行新世紀 8/15 FireKing +ck48th303 建中 ◎兵的世界 6/05 Roses999/henrry/flyingdog +CS85ee 中山 ◎大家義起幸福 8/08 admin/MVPgirl +CS85simple 中山 ◎簡班人-不簡單 3/29 bbeellaa +TFG95TRUE 北一 ◎真班果菜園 3/29 deceanna +ck46th318 建中 ◎ 祝 福 大 3/16 FengX/barkjor +PTGS50th301 中女 ◎天下第一班--中 8/09 cocoduck/youki +CS85ming 中山 ◎"明"心小園 8/08 shan/lovehook/JWR +ck47th333 建中 ◎這樣會不會廢版? 7/17 diezoo/Express +TFG97SHOT 北一 ◎米那桑 噢甘起 8/07 chili/atlantis +Taichung 服務 ◎最最清新可愛健 8/09 Jahon +southdoor 南門 ◎南門六甲的童言 8/09 happyjoy +ck47th301 建中 ◎還剩誰啊?? 5/22 huskie/flutii +hsntu 附中 ●台大附友會 來 11/29 koku/Crony +JH23th301 國中 ◎你還活著嗎? 7/25 momi/mvpman +money 學術 ●Show me the 5/02 kagh +HSNU_807 附中 ◎捌佰零柒班 7/16 yijean/joj +ntubbsops 發電 ●台大連線站務板 3/23 Ptt +ntuACCT90 會計 ●這是永遠的台大 7/19 blackman/aathena +geography90 地理 ◎ 5/23 cog/uray +TFG97Juang 北一 ◎我們會不會直到 8/09 seabreeze/notorious/Ving +JHArt10th 國中 ◎黑色的放浪軍 8/14 sadness/noyes +ChanAn26-303長安 ◎叫我第一名 8/07 HunterX +FashionClub 逸趣 ●超勁爆之--台大 1/17 demure/Woodywang/wiki +TFG97KIND 北一 ◎這裡可是仁間天 1/17 Channy +AADIA 台灣 ◎燒滾滾的最佳男 8/13 CATHYSHU/dyw +Sunrise12 團體 ◎朝陽同學會十二 8/14 waiting/doggy +cksh75th09 成功 ◎友誼歷"九"一樣 8/08 chiahei/WeThree/berserk +Evangelion 日本 ●誠徵版主:) 6/15 徵求中 +NTUba87 工管 ◎工管一出 誰與 8/09 ukj/littlewin +ck49th109 建中 ◎版主要上山拜師 3/24 edvi +CS86Honest 中山 ◎這裡是誠班!誠 5/24 Nakai/vicke +YP86-307 延平 ◎亞洲第一啦! 8/08 DRAGONS/longman +jackstudio 音樂 ◎杰克搖滾音樂學 8/13 gigimusic +CS85MadWiser中山 ◎楓狂智慧人 12/06 NED +LiZin 補習 ◎立人補習班 6/10 success/adket/foster +HP_86_310 和平 ◎和平高中第一屆 11/26 beautyegg/oops/kyte +Terry 台灣 ◎林志炫「擦聲而 8/10 jane +Julia 台灣 ◎ 一生最愛的彭佳 8/07 esa +PTGS50th305 中女 ◎有夢有朋友---中 8/07 gm +ck49th111 建中 ●打擊巫婆特攻隊 3/15 ERWILSON/firebat +ck49th131 建中 ◎我們又畢業了... 12/26 lanzi/Cliche +Wallace 香港 ◎小太陽鍾漢良-- 8/07 karencc +KJ25MC 光仁 ◎光仁勁爆美女版 7/09 pm +ADS 其他 ●廣告特區 7/09 chwang/sourit/elixirs +TFSHS57th310一中 ●我們一家都是人 7/09 difficult/lpp/juwu +B84305XXX 社會 ◎84級社會人 7/12 ridley +Jeff 台灣 ◎十二月初--情歌 7/24 MisaTanaca/gambol +EricMoo 星馬 ◎巫啟賢的感動 11/27 piercec +NTUIB-PHD 國企 ◎台大國企所博士 5/22 yi03 +cksh75th19 成功 ◎今天的你,過得好 8/17 shiii/eegg +MINGDAO 明道 ◎迎接新世紀的到 3/10 apache/kaening +NTUMBA-87 商研 ◎企業家的窩 8/13 jonah +ck49th324 建中 ●一季夏夜的心動 4/03 jase/uuuuuu/brita +TFG96Chung 北一 ◎現在結婚很不划 8/12 astroboy +Kinmen 浯友 ◎台大浯友會 4/26 spurs +BANYAN 北門 ◎北門高中46TH 30 7/09 lusa/wangstar +BADTWINS 中友 ◎大德國中 7/16 Chilong/ggn/xlight +TFG96WILL 北一 ◎毅國風情 8/17 because/Galong +HSNU_924 附中 ●瘋狂惡勢力 7/16 Dukedream +Cyndi 台灣 ◎沒有"擁華",就 1/11 Melinda +test2 +CS86Smile 中山 ●笑傲中山 12/20 HsinYu/sunspring +JI3thN3-3 正義 ◎正義高中普三三 7/13 screamer/stingypig +CS87KUNG 中山 ◎公之風雲 8/12 hayashi/yjiou +NTUBA-837011企管 ◎版豬是隻大懶豬 3/10 eemil +TW-explorer 影集 ◎小心被霸王龍咬 8/06 honu +NTUIMA 武術 ◎內家拳社 陳氏太 8/16 shadowpen/fu6xjp6 +NthuPhi 哲學 ◎挾莊周以遨遊 8/07 cerberus +FreeNight 台灣 ◎TROUBLE 張震嶽 5/24 gonna/holybell +GlobalECON 待廢 ◎政經八百(財經問 12/12 ali8/martinboy +cvslog 發電 ◎cvs commit mess 4/16 +Momentum 待廢 ◎動量功場工作室 12/03 adnova/chestnut +chess 娛樂 ◎也對 都是連將 2/01 miserable +ChthoniC 台灣 ●閃靈樂團版 8/07 Iverigma +shisong304 西松 ◎西松304 5/15 JawTing/JSmoltz +NCCU97_MAT 會研 ◎來吧.....同學會 5/15 kemling/A1997 +ck49th331 建中 ◎狂沙野望。 7/12 MDP/den +HCGH-306 竹女 ◎有八卦!!! 4/19 jennywen/molly +Foolshome 團體 ◎耶耶耶~~~千禧年 1/06 truth/citizen/nathon +MARIAH 美國 ◎ ★★DON'T STOP 8/11 woowa +KHCHS-87-306新莊 ◎都跑到哪裡去了 6/10 +Delphi 程設 ◎Delphi狂想曲 2/13 cying +ciacia_Her 台灣 ◎ciacia用文字挑 7/26 sherbet +KS86-323 雄中 ●我們是永遠的阿 7/05 fayemimi/hanawa +test2 +KS86-322 雄中 ◎大家回來灌水吧 8/10 Vygotsky/SpermTiger +35WHOteam 團體 ◎醫療外交營三五 5/12 winonamars +test2 +ck49th306 建中 ◎ernesto: 306 7/18 pongo/dearyou +WuLing40-301待廢 ◎有夢有朋友 10/ 8/11 quert +NTUACCT88 會計 ◎天 道 酬 勤 6/12 Abbado/yenjui +NTUDRC 研究 ◎或許妳是對的 8/10 Kymco/plockock/Jimmyplus +NTUWRC 陸上 ◎台大摔角研究社 8/07 BigRed +TFSHS59th318一中 ●過了一天又一天 8/07 prodigy/kinoo/frisk +86literarts 文學 ◎86師大文藝營 8/07 stupidbear/bengthek +NTPU-SOC87 社會 ◎哇咧...新版成立 8/12 nettaigyo +NTU94FLLD 外文 ◎B83102's Wonder 3/27 poppet +ToriAmos 美國 ◎SLG熱賣中 8/14 CornflakeBoy +Bjork 美國 ◎文章都不見了 8/09 lunaticlace/sjon +SCU-BM-87C 觀察 ◎ 友誼歷久一樣濃 4/17 joeyoung/linging/YADY +CC-304 中正 ◎中正超棒 304 8/14 betty0804/daystar +Robin-Willia待廢 ◎永遠不老的羅賓 8/09 徵求中 +NTUEEice 團體 ◎凍 -- 結 8/10 hiei81/shouhou +tu-tuoz 團體 ◎吐槽國民小學 8/10 galilei/seethesky +WesleyS3H-32衛理 ◎最後一個暑假啦 8/15 esm +Romi 台灣 ◎利綺∼∼體貼 8/16 flyawayhome/holina +EEacademic 電機 ●要期中考囉!! 5/11 ccchen +ck-newboard 申請 ◎建中組專用連署 2/09 Pets +NTUspecial 無礙 ◎☆台灣大學無障 4/28 t6768 +chienchen 作家 ◎文字精靈——簡 8/09 curioussoul/ECOSEED +test2 +test2 +test2 +NTUmed-SC 醫學 ◎☆午間音樂會等 8/13 Evan/boo24 +Visual_Basic程設 ◎哇哇..你不能自 8/14 glans +test2 +test2 +AngelicaLee 星馬 ◎超可愛李心潔 *^ 8/11 CaptainL +Jackie_Lui 香港 ●俠骨仁心--呂頌 8/14 pipo/YCJ +HSNU_888 附中 ●888狡兔第二窟 8/10 Viggeran/cidi +ClassicMusic音樂 ●我們ㄉ國樂 8/13 kuger/mml +CM34th03 景美 ◎:) 8/13 Snorkel +CS88Jang 中山 ◎我們都是正點美 8/08 YANIYANI/cfchien +TFG99JUANG 北一 ◎然後又是秋天啦. 8/11 yumeko +SrcDiscuss 站長 ◎PTT 未來程式發 5/13 CharlieL/DavidYu +WL-AFFAIRS 事務 ◎請各板主注意群 6/09 PaiBingTran +SMGJS-80-302曉明 ◎永遠的初三乙 8/09 chifang +ck51st332 建中 ◎悼 離我們而去的 8/13 JeffreyS/jimmycat/Kampuchea/JIROO +HORT-90 園藝 ●畢業了... 8/16 sorng +NCHUPPSB 系壘 ◎哀哀哀 後繼無人 4/14 LCUTE/AMDKX +TAE 泰國 ◎再見,加州海灘 4/14 TulipChiu +LePoete 台灣 ◎田園詩人陳明章( 4/14 doomcat +NTUPOD 研究 ◎ 8/16 Galong +ck53rd211 建中 ◎換個名字吧.. 8/07 shanvic/BBD +NCHU-SES 土環 ◎大家來迎新喔~~ 4/18 yenjan +Tin-Tin 台灣 ●婷婷愛的勝利 8/09 shinoo +PTGS48th318 中女 ◎綠色蟑螂窩 8/15 yungfang +KF302 光復 ◎塞車中 8/15 ingela/cadillac +HuangLei 大陸 ◎黃磊文學音樂大 8/09 ssr +NCCU99_EDU 待廢 ◎~教育寶寶的茁壯 8/14 徵求中 +NCHU_zoo 動物 ●不良牛人比較多 4/24 sengir/GENETICS/velella +Bull 職棒 ●二十一世紀最勇 4/24 Nicky41/georgey +KS88-309 雄中 ●偶告訴你...我作 4/24 daviy +cksh77th20 成功 ◎你我都是煙火中 8/06 bergee +TFG99Dance 北一 ◎無限盃Jazz冠軍 8/07 Tinabear/hee +TFG99Love 北一 ◎ 其 實 8/07 kelala/SpiceB +Nedio 媒體 ◎快上http://nedi 8/08 SpiceB/Sophia33 +TYHS88-306 左營 ●三天三夜到三更 8/09 niniway/Jey +BCT-88 科技 ◎一群在生物技術 8/15 physik/avkao +CARNEGIE0917團體 ◎***迎接閃亮的21 8/07 blackmail/mistletoe/tsg +NCCU_PT 社團 ◎沒有活動的屏友 8/11 mib345/randying +NCHU-SKATING溜冰 ◎來去...來去... 3/18 kaoasaki/littlehome +Tun-Hua-Elem敦化 ◎TunHua_第32屆_6 8/07 pup +CS88jing 中山 ◎快畢業了耶 想 8/08 yianne +LeneMarlin 美國 ◎音樂精靈--琳恩 8/08 janetwang +KS88-304 雄中 ◎大家來灌水喔~ 8/12 ahwa/oldya/BabyHam +Summer 台灣 ◎把影子留下,在 8/08 powerpeople/FINNCHE +Slayers 日本 ◎秀逗魔導士 莉 8/07 Zelgandes/marcal/Naga +NTU-SwimCamp水上 ◎台大游泳營 6/22 sunnyl +red-sun 社團 ◎落石來囉 8/09 renaissance +1995-JH-325 金華 ◎金華國中三年二 8/13 ThisWayIn/Raistlin/ifq +X-game 運動 ◎極限運動 8/08 rbaggio +88leadercamp團體 ● 終於開版的88社 8/12 elbert/aaati +Curse 台灣 ◎詛咒樂團(十八才 8/07 anticrist +Joi 星馬 ◎淳淨佳音 8/08 leon19/crazykiller +SHENA-RINGO 日本 ◎椎名林檎 勝訴的 8/08 MayMV +CCJH-FS-27th中正 ◎ㄞ 冷清清..... 8/12 Ariyari/YehMay +PH-Service 公衛 ◎永續經營的公衛 8/07 piayyc/yuskay +1995-JH-309 待廢 ◎金華309國中同學 2/11 徵求中 +Peter 台灣 ◎每次想到"何潤東 3/05 Haas +IPIS 菲國 ◎蟑螂-忘了我是誰 5/30 +cksh76th22 成功 ◎地球很危險的!妳 8/15 lunasoul +Stella 星馬 ◎音樂甜心-黃湘怡 7/12 gutai309/crazykiller +Law-Skate 法律 ◎法苑直排輪社 溜 6/12 Rainsalt/gwenlin +cksh78th08 成功 ◎六字頭 308 3/17 smilefacer +ntucomga 管會 ◎管院研究生學生 5/08 handsome diff --git a/pttbbs/util/smtest.result2 b/pttbbs/util/smtest.result2 new file mode 100644 index 00000000..b84133c2 --- /dev/null +++ b/pttbbs/util/smtest.result2 @@ -0,0 +1,3 @@ +免職版主 +看板名稱 板主 幾天沒來啦 +---------------------------------------------------------------------- diff --git a/pttbbs/util/smtest.temp b/pttbbs/util/smtest.temp new file mode 100644 index 00000000..7daa12ce --- /dev/null +++ b/pttbbs/util/smtest.temp @@ -0,0 +1,231 @@ +#include <stdio.h> +#include <sys/types.h> +#include <unistd.h> +#include <string.h> +#include <stdlib.h> +#include <time.h> +#include <ctype.h> +#include "config.h" +#include "pttstruct.h" +#include "util.h" +#include "perm.h" +#include "common.h" +#include "proto.h" + +#define OUTFILE BBSHOME "/pttbbs/util/smtest.result1" +#define FIREFILE BBSHOME "/pttbbs/util/smtest.result2" + +extern boardheader_t *bcache; +extern int numboards; + +boardheader_t allbrd[MAX_BOARD]; +struct userec_t xuser; + +int getuser(char *userid) { + int uid; + if((uid = searchuser(userid))) + passwd_query(uid, &xuser); + return uid; +} + +int LINK(char* src, char* dst){ + char cmd[200]; + + if( link(src, dst) == 0){ + return 0; + } + + sprintf(cmd, "/bin/cp -R %s %s", src, dst); + return system(cmd); +} + +int outofdate(char *hdrdate, char latestdate[]) +{ + int k,rr; + char *dd; + + dd = strtok(hdrdate,"/"); + + if(dd){ + k = 0; + do + { + if (*dd == '[' ){dd[strlen(dd)-1]='\0'; dd++;} + rr = atoi(dd); + printf("%d/", rr); + } while((dd = strtok(NULL,"/")) != NULL); + } + + printf("\n"); + + if(1) + return 1; + else + return 0; +} + +int main() +{ + int bmid, i, j, k, rd,rr; + char *p, *bmsname[3], fname[256], *dd; + fileheader_t hdr; + FILE *inf; + + /* set date */ + char thedate[5]; + time_t t = time(NULL); + struct tm *tm = localtime(&t); + + sprintf(thedate, "%2d/%02d", tm->tm_mon + 1, tm->tm_mday); + + resolve_boards(); + if(passwd_mmap()) + exit(1); + memcpy(allbrd,bcache,numboards*sizeof(boardheader_t)); + /* write out the target file */ + inf = fopen(OUTFILE, "w+"); + if(inf == NULL){ + printf("open file error : %s\n", OUTFILE); + exit(1); + } + + /*the ouput table title*/ + fprintf(inf,"英文版名 類別 中文版名 版主名單" + " 日期 備註 \n"); + + j = 0 ; + for (i = 0; i < 30; i++) { + rd = 0; + if(allbrd[i].brdname[0] == '\0') continue; + if((allbrd[i].brdattr & BRD_NOZAP) == 1) continue; + + sprintf(fname, BBSHOME "/boards/%s/.DIR",allbrd[i].brdname); + + /* get date to choose junk board */ + + rd = get_num_records(fname, sizeof(fileheader_t)); + get_record(fname, &hdr, sizeof (hdr), rd - 30); + + + if(outofdate(hdr.date,thedate)) printf("yest\n"); + +/* + dd = strtok(hdr.date,"/"); + + if(dd){ + k = 0; + do + { + if (*dd == '[' ){dd[strlen(dd)-1]='\0'; dd++;} + rr = atoi(dd); + printf("%d/", rr); + + } while((dd = strtok(NULL,"/")) != NULL); + } + printf("\n"); +*/ + /* print to file */ + printf("%-*.*s%-*.*s%-*.*s%-*.*s", IDLEN, IDLEN, allbrd[i].brdname, + BTLEN-24, BTLEN-26, allbrd[i].title, IDLEN - 5, IDLEN-5,hdr.date, + IDLEN * 3, IDLEN * 3, allbrd[i].BM); + + /* post to board */ + + + + /* user extract to mail */ + + p=strtok(allbrd[i].BM,"/ "); + if(p){ + k = 0; + do + { + if (*p == '[' ){p[strlen(p)-1]='\0'; p++;} + bmid=getuser(p); + bmsname[k] = p; + if(isalpha(allbrd[i].BM[0])&& !(xuser.userlevel &PERM_SYSOP)) + { + // printf("%s", bmsname[k]); + } + k++; + } while((p=strtok(NULL,"/ "))!=NULL); + } + + printf("\n"); + +} + + +/* + + + + if(flag == 1){ + bmbuf[0] = '\0'; + for(k = 0 , n = 0; k < index; k++){ + if(!bms[k].flag){ + if( n++ != 0) strcat(bmbuf, "/"); + strcat(bmbuf, bms[k].bmname); + } + } + strcpy(bcache[i].BM, bmbuf); + } + } + qsort(lostbms, j, sizeof(lostbm), bmlostdays_cmp); + + //write to the etc/toplazyBM + for ( i=0; i<j; i++) + { + if( lostbms[i].lostdays > 60){ + fprintf(firef, "%-*.*s%-*.*s%-*.*s%3d天沒上站\n", IDLEN, IDLEN, lostbms[i].title, + BTLEN-10, BTLEN-10, lostbms[i].ctitle, IDLEN,IDLEN, + lostbms[i].bmname,lostbms[i].lostdays); + }else{ + fprintf(inf, "%-*.*s%-*.*s%-*.*s%3d天沒上站\n", IDLEN, IDLEN, lostbms[i].title, + BTLEN-10, BTLEN-10, lostbms[i].ctitle, IDLEN,IDLEN, + lostbms[i].bmname,lostbms[i].lostdays); + } + } + fclose(inf); + fclose(firef); + + //printf("Total %d boards.\n", count); + + //mail to the users + for( i=0; i<j; i++) + { + fileheader_t mymail; + char genbuf[200]; + int lostdays; + + lostdays = lostbms[i].lostdays; + + if( (lostdays != 30) && (lostdays != 45) && (lostdays <= 60)) + continue; + + sprintf(genbuf, BBSHOME "/home/%c/%s", lostbms[i].bmname[0], lostbms[i].bmname); + stampfile(genbuf, &mymail); + + strcpy(mymail.owner, "[PTT警察局]"); + + if(lostdays <= 60){ + sprintf(mymail.title, + "\033[32m [版主免職警告通知] \033[m %s BM %s", lostbms[i].title, lostbms[i].bmname); + }else{ + sprintf(mymail.title, + "\033[32m [版主免職通知] \033[m %s BM %s", lostbms[i].title, lostbms[i].bmname); + } + mymail.savemode = 0 ; + unlink(genbuf); + if(lostdays <= 60){ + LINK(OUTFILE, genbuf); + }else{ + LINK(FIREFILE, genbuf); + } + + sprintf(genbuf, BBSHOME "/home/%c/%s/.DIR", lostbms[i].bmname[0], lostbms[i].bmname); + append_record(genbuf, &mymail, sizeof(mymail)); + } +*/ + return 0; +} diff --git a/pttbbs/util/stock.perl b/pttbbs/util/stock.perl new file mode 100644 index 00000000..568c2d86 --- /dev/null +++ b/pttbbs/util/stock.perl @@ -0,0 +1,31 @@ +#!/usr/bin/perl +# $Id: stock.perl,v 1.1 2002/03/07 15:13:46 in2 Exp $ +# +# 不能跑的話,看看 bbspost 的路徑是否正確。 +# 如果發出的 post 沒有氣象報告而是說 URL 找不到,則確定一下能不能看到 +# 中央氣象局的 WWW 及 URL 是否正確。 +# 理論上適用所有 Eagle BBS 系列。 +# -- Beagle Apr 13 1997 +open(BBSPOST, "| bin/webgrep >etc/stock.tmp"); +# 日期 +open(DATE, "date +'%a %b %d %T %Y' |"); +$date = <DATE>; +chop $date; +close DATE; + +# Header +# 內容 +#open(WEATHER, "/usr/local/bin/lynx -dump http://www.dashin.com.tw/bulletin_board/today_stock_price.htm |"); while (<WEATHER>) { +open(WEATHER, "/usr/bin/lynx -dump http://quotecenter.jpc.com.tw/today_stock_price.htm |"); while(<WEATHER>) { + print BBSPOST if ($_ ne "\n"); +} +close WEATHER; + +# 簽名檔 +print BBSPOST "\n--\n"; +print BBSPOST "我是beagle所有可愛的小餅乾...跨海為Ptt服務\n"; +print BBSPOST "--\n"; +print BBSPOST "☆ [Origin: ◎果醬小站◎] [From: [藍莓鬆餅屋] ] "; + +close BBSPOST; + diff --git a/pttbbs/util/stock.sh b/pttbbs/util/stock.sh new file mode 100644 index 00000000..907ddb73 --- /dev/null +++ b/pttbbs/util/stock.sh @@ -0,0 +1,5 @@ +#!/bin/sh +# $Id: stock.sh,v 1.1 2002/03/07 15:13:46 in2 Exp $ +# +bin/stock.perl +bin/post Record 今日股票收盤價 [股市小姐] etc/stock.tmp diff --git a/pttbbs/util/tarqueue.pl b/pttbbs/util/tarqueue.pl new file mode 100644 index 00000000..20bda9f1 --- /dev/null +++ b/pttbbs/util/tarqueue.pl @@ -0,0 +1,75 @@ +#!/usr/bin/perl +use lib '/home/bbs/bin/'; +use LocalVars; +use strict; +use Mail::Sender; +use POSIX; + +no strict 'subs'; +setpriority(PRIO_PROCESS, $$, 20); +use strict subs; +chdir $BBSHOME; +open LOG, ">> log/tarqueue.log"; + +foreach my $board ( <$JOBSPOOL/tarqueue.*> ){ + $board =~ s/.*tarqueue\.//; + ProcessBoard($board); + unlink "$JOBSPOOL/tarqueue.$board"; +} +close DIR; +close LOG; + +sub ProcessBoard +{ + my($board)= @_; + my($cmd, $owner, $email, $bakboard, $bakman, $now); + + $now = substr(POSIX::ctime(time()), 0, -1); + open FH, "< $JOBSPOOL/tarqueue.$board"; + chomp($owner = <FH>); + chomp($email = <FH>); + chomp(($bakboard, $bakman) = split(/,/, <FH>)); + close FH; + + print LOG sprintf("%-28s %-12s %-12s %d %d %s\n", + $now, $owner, $board, $bakboard, $bakman, $email); + + MakeMail({tartarget => "$TMP/$board.tgz", + tarsource => "boards/$board/* boards/$board/.DIR", + mailto => "$board的版主$owner <$email>", + subject => "$board的看版備份", + body => + "\n\n\t $owner 您好,收到這封信,表示您已經收到看板備份。\n\n". + "\t謝謝您的耐心等待,以及使用 $hostname的看板備份系統,\n\n". + "\t如有任何疑問,歡迎寄信給站長,我們會很樂於給予協助。\n\n\n". + "\t最後,祝 $owner 平安快樂! ^_^\n\n\n". + "\t $hostname站長群. \n\t$now" + }) if( $bakboard ); + + MakeMail({tartarget => "$TMP/man.$board.tgz", + tarsource => "man/boards/$board/* man/boards/$board/.DIR", + mailto => "$board的版主$owner <$email>", + subject => "$board的精華區備份", + body => + "\n\n\t $owner 您好,收到這封信,表示您已經收到精華區備份。\n\n". + "\t謝謝您的耐心等待,以及使用 $hostname的看板備份系統,\n\n". + "\t如有任何疑問,歡迎寄信給站長,我們會很樂於給予協助。\n\n\n". + "\t最後,祝 $owner 平安快樂! ^_^\n\n\n". + "\t $hostname站長群. \n\t$now" + }) if( $bakman ); + +} + +sub MakeMail +{ + my($arg) = @_; + my $sender; + `$TAR zcf $arg->{tartarget} $arg->{tarsource}`; + $sender = new Mail::Sender{smtp => $SMTPSERVER, + from => 'pttadmin <in2@ptt2.csie.ntu.edu.tw>'}; + $sender->MailFile({to => $arg->{mailto}, + subject => $arg->{subject}, + msg => $arg->{body}, + file => $arg->{tartarget}}); + unlink $arg->{tartarget}; +} diff --git a/pttbbs/util/testkenben.txt b/pttbbs/util/testkenben.txt new file mode 100644 index 00000000..df3893d3 --- /dev/null +++ b/pttbbs/util/testkenben.txt @@ -0,0 +1,11 @@ +HCGH-306 竹女 ◎有八卦!!! 7/24 jennywen/molly +Foolshome 團體 ◎耶耶耶~~~千禧年 1/14 truth/citizen/nathon +KHCHS-87-306新莊 ◎都跑到哪裡去了 6/12 +TGHS8714 南女 ◎理性天氣;感性 8/07 grassflying/EPOCH +PttDoc 嘰哩 ◎Ptt Document Pr 8/07 +Delphi 程設 ◎Delphi狂想曲 3/09 cying +ciacia_Her 台灣 ◎ciacia用文字挑 8/16 sherbet +CS87Love 中山 ◎愛呢! 8/08 sylna/fancydream +Wanfang 台灣 ◎就值得了愛萬芳 8/07 zkkk +KS87-308 雄中 ●雄中八掛班《一 8/07 SBT/shouhou + diff --git a/pttbbs/util/toplazyBBM.c b/pttbbs/util/toplazyBBM.c new file mode 100644 index 00000000..08c07448 --- /dev/null +++ b/pttbbs/util/toplazyBBM.c @@ -0,0 +1,203 @@ +#include <stdio.h> +#include <sys/types.h> +#include <unistd.h> +#include <string.h> +#include <stdlib.h> +#include <time.h> +#include <ctype.h> +#include "config.h" +#include "pttstruct.h" +#include "util.h" +#include "perm.h" +#include "common.h" + +#define OUTFILE BBSHOME "/etc/toplazyBBM" +#define FIREFILE BBSHOME "/etc/topfireBBM" + +extern boardheader_t *bcache; +extern int numboards; + +boardheader_t allbrd[MAX_BOARD]; +extern userec_t xuser; +typedef struct lostbm { + char *bmname; + char *title; + char *ctitle; + int lostdays; +} lostbm; +lostbm lostbms[MAX_BOARD]; + +typedef struct BMarray{ + char *bmname; + int flag; +} BMArray; +BMArray bms[3]; + +int bmlostdays_cmp(const void *va, const void *vb) +{ + lostbm *a=(lostbm *)va, *b=(lostbm *)vb; + if (a->lostdays > b->lostdays) return -1; + else if (a->lostdays == b->lostdays) return 0; + else return 1; +} + + +int LINK(char* src, char* dst){ + char cmd[200]; + if(symlink(src,dst) == -1) + { + sprintf(cmd, "/bin/cp -R %s %s", src, dst); + return system(cmd); + } + return 0; +} + +int main(int argc, char *argv[]) +{ + int bmid, i, j=0; + FILE *inf, *firef; + + resolve_boards(); + + if(passwd_mmap()) + exit(1); + + memcpy(allbrd,bcache,numboards*sizeof(boardheader_t)); + + /* write out the target file */ + printf("Starting Checking\n"); + inf = fopen(OUTFILE, "w+"); + if(inf == NULL){ + printf("open file error : %s\n", OUTFILE); + exit(1); + } + firef = fopen(FIREFILE, "w+"); + if(firef == NULL){ + printf("open file error : %s\n", FIREFILE); + exit(1); + } + + fprintf(inf, "警告: 版主若於兩個月未上站,將予於免職\n"); + fprintf(inf, + "看板名稱 " + " 板主 幾天沒來啦\n" + "---------------------------------------------------" + "-------------------\n"); + + fprintf(firef, "免職版主\n"); + fprintf(firef, + "看板名稱 " + " 板主 幾天沒來啦\n" + "---------------------------------------------------" + "-------------------\n"); + + + j = 0 ; + for (i = 0; i < numboards; i++) { + char *p, bmbuf[IDLEN * 3 + 3]; + int index = 0, flag = 0, k, n; + p=strtok(allbrd[i].BM,"/ "); + if(p) + do + { + if(allbrd[i].brdname[0] == '\0' || (allbrd[i].brdattr & BRD_GROUPBOARD) ==0 ) continue; + if (*p == '[' ){p[strlen(p)-1]='\0'; p++;} + bmid=getuser(p); + bms[index].bmname = p; + bms[index].flag = 0; + if (((((int)time(NULL)-(int)xuser.lastlogin)/(60*60*24))>=7) + //&& isalpha(allbrd[i].brdname[0]) + //&& isalpha(allbrd[i].BM[0]) + && !(xuser.userlevel & PERM_SYSOP)) + { + lostbms[j].bmname = p; + lostbms[j].title = allbrd[i].brdname; + lostbms[j].ctitle = allbrd[i].title; + lostbms[j].lostdays = + ((int)time(NULL)-(int)xuser.lastlogin)/(60*60*24); + + printf("%s\n", lostbms[j].title); + //超過六十天 免職 + if(lostbms[j].lostdays > 30){ + xuser.userlevel &= ~PERM_BM; + bms[index].flag = 1; + flag = 1; + } + j++; + } + index++; + } while((p=strtok(NULL,"/ "))!=NULL); + + //從版主名單拿掉名字 + + if(flag == 1){ + bmbuf[0] = '\0'; + for(k = 0 , n = 0; k < index; k++){ + if(!bms[k].flag){ + if( n++ != 0) strcat(bmbuf, "/"); + strcat(bmbuf, bms[k].bmname); + } + } + strcpy(allbrd[i].BM, bmbuf); + } + + } + qsort(lostbms, j, sizeof(lostbm), bmlostdays_cmp); + + printf("Starting to mail\n"); + //write to the etc/toplazyBBM + for ( i=0; i<j; i++) + { + if( lostbms[i].lostdays > 30){ + fprintf(firef, "%-*.*s%-*.*s%-*.*s%3d天沒上站\n", IDLEN, IDLEN, lostbms[i].title, + BTLEN-10, BTLEN-10, lostbms[i].ctitle, IDLEN,IDLEN, + lostbms[i].bmname,lostbms[i].lostdays); + }else{ + fprintf(inf, "%-*.*s%-*.*s%-*.*s%3d天沒上站\n", IDLEN, IDLEN, lostbms[i].title, + BTLEN-10, BTLEN-10, lostbms[i].ctitle, IDLEN,IDLEN, + lostbms[i].bmname,lostbms[i].lostdays); + } + } + fclose(inf); + fclose(firef); + + printf("Total %d boards.\n", j); + + //mail to the users + for( i=0; i<j; i++) + { + fileheader_t mymail; + char genbuf[200]; + int lostdays; + + lostdays = lostbms[i].lostdays; + + if( (lostdays != 14) || (lostdays != 21) ) // 14 21 天不發信 + continue; + + sprintf(genbuf, BBSHOME "/home/%c/%s", lostbms[i].bmname[0], lostbms[i].bmname); + stampfile(genbuf, &mymail); + + strcpy(mymail.owner, "[PTT警察局]"); + + if(lostdays <= 30){ + sprintf(mymail.title, + "\033[32m [小組長免職警告通知] \033[m %s BM %s", lostbms[i].title, lostbms[i].bmname); + }else{ + sprintf(mymail.title, + "\033[32m [小組長免職通知] \033[m %s BM %s", lostbms[i].title, lostbms[i].bmname); + } + mymail.savemode = 0 ; + unlink(genbuf); + if(lostdays <= 30){ + LINK(OUTFILE, genbuf); + }else{ + LINK(FIREFILE, genbuf); + } + + sprintf(genbuf, BBSHOME "/home/%c/%s/.DIR", lostbms[i].bmname[0], lostbms[i].bmname); + append_record(genbuf, &mymail, sizeof(mymail)); + } + + return 0; +} diff --git a/pttbbs/util/toplazyBBM.sh b/pttbbs/util/toplazyBBM.sh new file mode 100644 index 00000000..d1d94229 --- /dev/null +++ b/pttbbs/util/toplazyBBM.sh @@ -0,0 +1,3 @@ +bin/toplazyBBM +bin/post Record 懶惰小組長排行榜 [Ptt警察局] etc/toplazyBBM +bin/post ViolateLaw 今日免職小組長 [Ptt法院] etc/firelazyBBM diff --git a/pttbbs/util/toplazyBM.c b/pttbbs/util/toplazyBM.c new file mode 100644 index 00000000..ec9319c2 --- /dev/null +++ b/pttbbs/util/toplazyBM.c @@ -0,0 +1,211 @@ +#include <stdio.h> +#include <sys/types.h> +#include <unistd.h> +#include <string.h> +#include <stdlib.h> +#include <time.h> +#include <ctype.h> +#include "config.h" +#include "pttstruct.h" +#include "util.h" +#include "perm.h" +#include "common.h" +#include "proto.h" +#include "modes.h" + + +#define OUTFILE BBSHOME "/etc/toplazyBM" +#define FIREFILE BBSHOME "/etc/firelazyBM" + +extern boardheader_t *bcache; +extern int numboards; + +boardheader_t allbrd[MAX_BOARD]; +extern userec_t xuser; +typedef struct lostbm { + char *bmname; + char *title; + char *ctitle; + int lostdays; +} lostbm; +lostbm lostbms[MAX_BOARD]; + +typedef struct BMarray{ + char *bmname; + int flag; +} BMArray; +BMArray bms[3]; + + +int bmlostdays_cmp(const void *va, const void *vb) +{ + lostbm *a=(lostbm *)va, *b=(lostbm *)vb; + if (a->lostdays > b->lostdays) return -1; + else if (a->lostdays == b->lostdays) return 0; + else return 1; +} + +int LINK(char* src, char* dst){ + char cmd[200]; + if(symlink(src,dst) == -1) + { + sprintf(cmd, "/bin/cp -R %s %s", src, dst); + return system(cmd); + } + return 0; +} + +int main(int argc, char *argv[]) +{ + int bmid, i, j=0; + FILE *inf, *firef; + + resolve_boards(); + + if(passwd_mmap()) + exit(1); + + memcpy(allbrd,bcache,numboards*sizeof(boardheader_t)); + + /* write out the target file */ + inf = fopen(OUTFILE, "w+"); + if(inf == NULL){ + printf("open file error : %s\n", OUTFILE); + exit(1); + } + + firef = fopen(FIREFILE, "w+"); + if(firef == NULL){ + printf("open file error : %s\n", FIREFILE); + exit(1); + } + + fprintf(inf, "警告: 版主若於兩個月未上站,將予於免職\n"); + fprintf(inf, + "看板名稱 " + " 板主 幾天沒來啦\n" + "---------------------------------------------------" + "-------------------\n"); + + fprintf(firef, "免職版主\n"); + fprintf(firef, + "看板名稱 " + " 板主 幾天沒來啦\n" + "---------------------------------------------------" + "-------------------\n"); + + + j = 0 ; + for (i = 0; i < numboards; i++) { + char *p, bmbuf[IDLEN * 3 + 3]; + int index = 0, flag = 0, k, n; + p=strtok(allbrd[i].BM,"/ "); + if(p) + do + { + if(allbrd[i].brdname[0] == '\0') continue; + if (*p == '[' ){p[strlen(p)-1]='\0'; p++;} + bmid=getuser(p); + bms[index].bmname = p; + bms[index].flag = 0; + if (((((int)time(NULL)-(int)xuser.lastlogin)/(60*60*24))>=31) + && isalpha(allbrd[i].brdname[0]) + && isalpha(allbrd[i].BM[0]) + && !(xuser.userlevel & PERM_SYSOP)) + { + lostbms[j].bmname = p; + lostbms[j].title = allbrd[i].brdname; + lostbms[j].ctitle = allbrd[i].title; + lostbms[j].lostdays = + ((int)time(NULL)-(int)xuser.lastlogin)/(60*60*24); + + + //超過六十天 免職 + if(lostbms[j].lostdays > 60){ + xuser.userlevel &= ~PERM_BM; + bms[index].flag = 1; + flag = 1; + passwd_update(bmid, &xuser); + } + j++; + } + index++; + } while((p=strtok(NULL,"/ "))!=NULL); + + if(flag == 1){ + boardheader_t *fhp = 0; + printf("%s %s\n", lostbms[j-1].title, lostbms[j-1].bmname); + bmbuf[0] = '\0'; + for(k = 0 , n = 0; k < index; k++){ + if(!bms[k].flag){ + if( n++ != 0) strcat(bmbuf, "/"); + strcat(bmbuf, bms[k].bmname); + } + } + + strcpy(allbrd[i].BM, bmbuf); + if( substitute_record(FN_BOARD, &allbrd[i], sizeof(boardheader_t), i) == -1){ + printf("Update Board Faile : %s\n", allbrd[i].brdname); + } + reset_board(i); + } + } + + qsort(lostbms, j, sizeof(lostbm), bmlostdays_cmp); + + //write to the etc/toplazyBM + for ( i=0; i<j; i++) + { + if( lostbms[i].lostdays > 60){ + fprintf(firef, "%-*.*s%-*.*s%-*.*s%3d天沒上站\n", IDLEN, IDLEN, lostbms[i].title, + BTLEN-10, BTLEN-10, lostbms[i].ctitle, IDLEN,IDLEN, + lostbms[i].bmname,lostbms[i].lostdays); + }else{ + fprintf(inf, "%-*.*s%-*.*s%-*.*s%3d天沒上站\n", IDLEN, IDLEN, lostbms[i].title, + BTLEN-10, BTLEN-10, lostbms[i].ctitle, IDLEN,IDLEN, + lostbms[i].bmname,lostbms[i].lostdays); + } + } + fclose(inf); + fclose(firef); + + //printf("Total %d boards.\n", count); + + //mail to the users + for( i=0; i<j; i++) + { + fileheader_t mymail; + char genbuf[200]; + int lostdays; + + lostdays = lostbms[i].lostdays; + + if( (lostdays != 30) && (lostdays != 45) && (lostdays <= 60)) + continue; + + sprintf(genbuf, BBSHOME "/home/%c/%s", lostbms[i].bmname[0], lostbms[i].bmname); + stampfile(genbuf, &mymail); + + strcpy(mymail.owner, "[PTT警察局]"); + + if(lostdays <= 60){ + sprintf(mymail.title, + "\033[32m [版主免職警告通知] \033[m %s BM %s", lostbms[i].title, lostbms[i].bmname); + }else{ + sprintf(mymail.title, + "\033[32m [版主免職通知] \033[m %s BM %s", lostbms[i].title, lostbms[i].bmname); + } + mymail.savemode = 0 ; + unlink(genbuf); + if(lostdays <= 60){ + LINK(OUTFILE, genbuf); + }else{ + LINK(FIREFILE, genbuf); + } + + sprintf(genbuf, BBSHOME "/home/%c/%s/.DIR", lostbms[i].bmname[0], lostbms[i].bmname); + append_record(genbuf, &mymail, sizeof(mymail)); + } + + return 0; +} diff --git a/pttbbs/util/toplazyBM.sh b/pttbbs/util/toplazyBM.sh new file mode 100644 index 00000000..033e545f --- /dev/null +++ b/pttbbs/util/toplazyBM.sh @@ -0,0 +1,3 @@ +bin/toplazyBM +bin/post Record 懶惰版主排行榜 [Ptt警察局] etc/toplazyBM +bin/post ViolateLaw 今日免職版主 [Ptt法'|'] etc/firelazyBM diff --git a/pttbbs/util/topsong.sh b/pttbbs/util/topsong.sh new file mode 100644 index 00000000..19e9663a --- /dev/null +++ b/pttbbs/util/topsong.sh @@ -0,0 +1,5 @@ +#!/bin/sh +# $Id: topsong.sh,v 1.1 2002/03/07 15:13:46 in2 Exp $ +# +bin/post Record "上半個月點歌排行榜" "[Ptt流行網]" etc/topsong +mv ussong tmp diff --git a/pttbbs/util/topusr.c b/pttbbs/util/topusr.c new file mode 100644 index 00000000..22b95e94 --- /dev/null +++ b/pttbbs/util/topusr.c @@ -0,0 +1,205 @@ +/* $Id: topusr.c,v 1.1 2002/03/07 15:13:46 in2 Exp $ */ +/* 使用者 上站記錄/文章篇數 排行榜 */ + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <sys/types.h> +#include "config.h" +#include "pttstruct.h" +#include "perm.h" +#include "common.h" +#include "util.h" + +#define REAL_INFO +struct manrec +{ + char userid[IDLEN + 1]; + char username[23]; + int values[3]; +}; +typedef struct manrec manrec; +struct manrec *allman[3]; + +userec_t aman; +manrec theman; +int num; +FILE *fp; + +#define TYPE_POST 0 +#define TYPE_LOGIN 1 +#define TYPE_MONEY 2 + + +void + top(type) +{ + static char *str_type[3] = + {"發表次數", "進站次數", " 大富翁 "}; + int i, j, rows = (num + 1) / 2; + char buf1[80], buf2[80]; + + if (type != 2) + fprintf(fp, "\n\n"); + + fprintf(fp, "\ + ╭─────╮ [%dm %8.8s排行榜  ╭─────╮\n\ + 名次─代號───暱稱──────數目──名次─代號───暱稱──────數目\ +", type + 44, str_type[type]); + for (i = 0; i < rows; i++) + { + char ch=' '; + int value; + + if(allman[type][i].values[type] > 1000000000) + { value=allman[type][i].values[type]/1000000; ch='M';} + else if(allman[type][i].values[type] > 1000000) + { value=allman[type][i].values[type]/1000; ch='K';} + else {value=allman[type][i].values[type]; ch=' ';} + sprintf(buf1, "[%2d] %-11.11s%-16.16s%5d%c", + i + 1, allman[type][i].userid, allman[type][i].username, + value, ch); + j = i + rows; + if(allman[type][j].values[type] > 1000000000) + { value=allman[type][j].values[type]/1000000; ch='M';} + else if(allman[type][j].values[type] > 1000000) + { value=allman[type][j].values[type]/1000; ch='K';} + else {value=allman[type][j].values[type]; ch=' ';} + + sprintf(buf2, "[%2d] %-11.11s%-16.16s%4d%c", + j + 1, allman[type][j].userid, allman[type][j].username, + value, ch); + if (i < 3) + fprintf(fp, "\n [1;%dm%-40s%s", 31 + i, buf1, buf2); + else + fprintf(fp, "\n %-40s%s", buf1, buf2); + } +} + + +#ifdef HAVE_TIN +int + post_in_tin(char *name) +{ + char buf[256]; + FILE *fh; + int counter = 0; + + sprintf(buf, "%s/home/%c/%s/.tin/posted", home_path, name[0], name); + fh = fopen(buf, "r"); + if (fh == NULL) + return 0; + else + { + while (fgets(buf, 255, fh) != NULL) + counter++; + fclose(fh); + return counter; + } +} +#endif /* HAVE_TIN */ +int + not_alpha(ch) +register char ch; +{ + return (ch < 'A' || (ch > 'Z' && ch < 'a') || ch > 'z'); +} + +int + not_alnum(ch) +register char ch; +{ + return (ch < '0' || (ch > '9' && ch < 'A') || + (ch > 'Z' && ch < 'a') || ch > 'z'); +} + +int + bad_user_id(userid) +char *userid; +{ + register char ch; + if (strlen(userid) < 2) + return 1; + if (not_alpha(*userid)) + return 1; + while((ch = *(++userid))) + { + if (not_alnum(ch)) + return 1; + } + return 0; +} + +int main(argc, argv) +int argc; +char **argv; +{ + int i, j; + + if (argc < 3) + { + printf("Usage: %s <num_top> <out-file>\n", argv[0]); + exit(1); + } + + num = atoi(argv[1]); + if (num == 0) + num = 30; + + if(passwd_mmap()) + { + printf("Sorry, the data is not ready.\n"); + exit(0); + } + for(i=0; i<3; i++) + { + allman[i]=malloc(sizeof(manrec) * num); + memset(allman[i],0,sizeof(manrec) * num); + } + for(j = 1; j <= MAX_USERS; j++) { + passwd_query(j, &aman); + aman.userid[IDLEN]=0; + aman.username[22]=0; + if((aman.userlevel & PERM_NOTOP) || !aman.userid[0] || + bad_user_id(aman.userid) || + strchr(aman.userid, '.')) + { + continue; + } + else { + strcpy(theman.userid, aman.userid); + strcpy(theman.username, aman.username); + theman.values[TYPE_LOGIN] = aman.numlogins; + theman.values[TYPE_POST] = aman.numposts; + theman.values[TYPE_MONEY] = aman.money; + for(i=0; i<3; i++) + { + int k,l; + for(k=num-1; k>=0 && allman[i][k].values[i]<theman.values[i]; + k--); + k++; + if(k<num) + { + for(l=num-1; l>k; l--) + memcpy(&allman[i][l], &allman[i][l-1], + sizeof(manrec)); + memcpy(&allman[i][k], &theman, sizeof(manrec)); + } + } + } + } + + + if ((fp = fopen(argv[2], "w")) == NULL) + { + printf("cann't open topusr\n"); + return 0; + } + + top(TYPE_MONEY); + top(TYPE_POST); + top(TYPE_LOGIN); + + fclose(fp); + return 0; +} diff --git a/pttbbs/util/tunepasswd.c b/pttbbs/util/tunepasswd.c new file mode 100644 index 00000000..15a3fe1f --- /dev/null +++ b/pttbbs/util/tunepasswd.c @@ -0,0 +1,77 @@ +/* $Id: tunepasswd.c,v 1.1 2002/03/07 15:13:46 in2 Exp $ */ +#include <stdio.h> +#include <string.h> +#include <unistd.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <sys/file.h> +#include "config.h" +#include "pttstruct.h" +#include "common.h" + +int tune(int num) { + int i, j, fin, fout; + userec_t u; + + if((fin = open(FN_PASSWD, O_RDONLY)) == -1) { + perror(FN_PASSWD); + return 1; + } + if(flock(fin, LOCK_EX)) { + printf("Lock failed!\n"); + return 1; + } + if((fout = open(FN_PASSWD ".tune" , O_WRONLY | O_CREAT, 0600)) == -1) { + perror(FN_PASSWD ".tune"); + flock(fin, LOCK_UN); + close(fin); + return 1; + } + + for(i = j = 0; i < num; i++) { + read(fin, &u, sizeof(u)); + if(u.userid[0]) { + if(j == MAX_USERS) { + printf("MAX_USERS is too small!\n"); + close(fout); + unlink(FN_PASSWD ".tune"); + flock(fin, LOCK_UN); + close(fin); + return 1; + } + write(fout, &u, sizeof(u)); + j++; + } + } + for(memset(&u, 0, sizeof(u)); j < MAX_USERS; j++) { + write(fout, &u, sizeof(u)); + } + close(fout); + + /* backup */ + unlink(FN_PASSWD "~"); + link(FN_PASSWD, FN_PASSWD "~"); + unlink(FN_PASSWD); + link(FN_PASSWD ".tune", FN_PASSWD); + unlink(FN_PASSWD ".tune"); + + flock(fin, LOCK_UN); + close(fin); + return 0; +} + +int main() { + struct stat sb; + + if(stat(FN_PASSWD, &sb)) { + perror("stat"); + return 1; + } + if(sb.st_size != sizeof(userec_t) * MAX_USERS) { + printf("size and MAX_USERS do not match!\n"); + if(tune(sb.st_size / sizeof(userec_t)) == 0) + printf(FN_PASSWD " has been tuned successfully!\n"); + } else + printf("Nothing to do.\n"); + return 0; +} diff --git a/pttbbs/util/uhash_loader.c b/pttbbs/util/uhash_loader.c new file mode 100644 index 00000000..2d88dd06 --- /dev/null +++ b/pttbbs/util/uhash_loader.c @@ -0,0 +1,129 @@ +/* $Id: uhash_loader.c,v 1.1 2002/03/07 15:13:47 in2 Exp $ */ +/* standalone uhash loader -- jochang */ +#include <stdio.h> +#include <unistd.h> +#include <fcntl.h> +#include <ctype.h> +#include <sys/mman.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <sys/types.h> +#include <sys/ipc.h> +#include <sys/shm.h> + +#ifdef __FreeBSD__ +#include <machine/param.h> +#endif + +#include "config.h" +#include "pttstruct.h" +#include "common.h" + +unsigned string_hash(unsigned char *s); +void add_to_uhash(int n, userec_t *id); +void fill_uhash(void); +void load_uhash(void); + +uhash_t *uhash; + +int main() { + setgid(BBSGID); + setuid(BBSUID); + chdir(BBSHOME); + load_uhash(); + return 0; +} + +void load_uhash(void) { + int shmid; + shmid = shmget(UHASH_KEY, sizeof(uhash_t), IPC_CREAT | 0600); +/* note we didn't use IPC_EXCL here. + so if the loading fails, + (like .PASSWD doesn't exist) + we may try again later. +*/ + if (shmid < 0) + { + perror("shmget"); + exit(1); + } + + uhash = (void *) shmat(shmid, NULL, 0); + if (uhash == (void *) -1) + { + perror("shmat"); + exit(1); + } + +/* in case it's not assumed zero, this becomes a race... */ + uhash->loaded = 0; + + fill_uhash(); + +/* ok... */ + uhash->loaded = 1; +} + +void fill_uhash(void) +{ + int fd, usernumber; + usernumber = 0; + + for (fd = 0; fd < (1 << HASH_BITS); fd++) + uhash->hash_head[fd] = -1; + + if ((fd = open(FN_PASSWD, O_RDONLY)) > 0) + { + struct stat stbuf; + caddr_t fimage, mimage; + + fstat(fd, &stbuf); + fimage = mmap(NULL, stbuf.st_size, PROT_READ, MAP_SHARED, fd, 0); + if (fimage == (char *) -1) + { + perror("mmap"); + exit(1); + } + close(fd); + fd = stbuf.st_size / sizeof(userec_t); + if (fd > MAX_USERS) + fd = MAX_USERS; + + for (mimage = fimage; usernumber < fd; mimage += sizeof(userec_t)) + { + add_to_uhash(usernumber, mimage); + usernumber++; + } + munmap(fimage, stbuf.st_size); + } + else + { + perror("open"); + exit(1); + } + uhash->number = usernumber; + printf("total %d names loaded.\n", usernumber); +} +unsigned string_hash(unsigned char *s) +{ + unsigned int v = 0; + while (*s) + { + v = (v << 8) | (v >> 24); + v ^= toupper(*s++); /* note this is case insensitive */ + } + return (v * 2654435769UL) >> (32 - HASH_BITS); +} + +void add_to_uhash(int n, userec_t *user) +{ + int *p, h = string_hash(user->userid); + strcpy(uhash->userid[n], user->userid); + uhash->money[n] = user->money; + p = &(uhash->hash_head[h]); + + while (*p != -1) + p = &(uhash->next_in_hash[*p]); + + uhash->next_in_hash[*p = n] = -1; +} diff --git a/pttbbs/util/userlist.c b/pttbbs/util/userlist.c new file mode 100644 index 00000000..9a142926 --- /dev/null +++ b/pttbbs/util/userlist.c @@ -0,0 +1,48 @@ +/* $id:$ */ +#include <stdio.h> +#include <stdlib.h> +#include <sys/types.h> +#include <sys/ipc.h> +#include <sys/shm.h> +#include "config.h" +#include "pttstruct.h" + +struct utmpfile_t *u; + +int main(int argc, char **argv) { + int i, shm, counter; + + shm = shmget(UTMPSHM_KEY, USHM_SIZE, SHM_R | SHM_W); + if(shm == -1) { + perror("shmget"); + exit(0); + } + + u = shmat(shm, NULL, 0); + if(u == (struct utmpfile_t *)-1) { + perror("shmat"); + exit(0); + } + + if(argc > 1) { + for(i = 1; i < argc; i++) + u->uinfo[atoi(argv[i])].pid = 0; + } else { + for(i = counter = 0; i < USHM_SIZE; i++) + if(u->uinfo[i].pid) { + userinfo_t *f; + + f = &u->uinfo[i]; + printf( + "%4d(%d) p[%d] i[%d] u[%s] n[%s] f[%s] m[%d] d[%d] t[%ld]\n", + ++counter, i, f->pager, f->invisible, f->userid, + f->username, f->from, f->mode, f->mind, f->lastact); + } + printf("\nTotal: %d(%d)\n", counter, u->number); + if(counter != u->number) { + u->number = counter; + printf("adjust user number!\n"); + } + } + return 0; +} diff --git a/pttbbs/util/util.h b/pttbbs/util/util.h new file mode 100644 index 00000000..9128e575 --- /dev/null +++ b/pttbbs/util/util.h @@ -0,0 +1,31 @@ +/* $Id: util.h,v 1.1 2002/03/07 15:13:46 in2 Exp $ */ +#ifndef INCLUDE_UTIL_H +#define INCLUDE_UTIL_H + +int searchuser(char *userid); +int stampfile(char *fpath, fileheader_t *fh); +int append_record(char *fpath, fileheader_t *record, int size); +int get_record(char *fpath, void *rptr, int size, int id); +int substitute_record(char *fpath, void *rptr, int size, int id); +void resolve_boards(); +int getbnum(char *bname); +void inbtotal(int bid, int add); +void *attach_shm(int shmkey, int shmsize); +void reload_pttcache(); +void resolve_fcache(); +void attach_uhash(); +void stamplink(char *fpath, fileheader_t *fh); +void resolve_utmp(); +void remove_from_uhash(int n); +void setuserid(int num, char *userid); + +int passwd_mmap(); +int passwd_update(int num, userec_t *buf); +int passwd_query(int num, userec_t *buf); +int passwd_apply(int (*fptr)(userec_t *)); +int passwd_apply2(int (*fptr)(int, userec_t *)); +void passwd_lock(); +void passwd_unlock(); + +#endif + diff --git a/pttbbs/util/util_cache.c b/pttbbs/util/util_cache.c new file mode 100644 index 00000000..12a01994 --- /dev/null +++ b/pttbbs/util/util_cache.c @@ -0,0 +1,518 @@ +/* $Id: util_cache.c,v 1.1 2002/03/07 15:13:46 in2 Exp $ */ +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <signal.h> +#include <unistd.h> +#include <fcntl.h> +#include <ctype.h> +#include <errno.h> +#include <time.h> +#include <sys/types.h> +#include <sys/types.h> +#include <sys/mman.h> +#include <sys/ipc.h> +#include <sys/shm.h> +#include <sys/sem.h> + +#ifdef __FreeBSD__ +#include <machine/param.h> +#endif + +#include "config.h" +#include "pttstruct.h" +#include "common.h" +#include "perm.h" +#include "modes.h" +#include "proto.h" + +int fcache_semid; + +/* the reason for "safe_sleep" is that we may call sleep during + SIGALRM handler routine, while SIGALRM is blocked. + if we use the original sleep, we'll never wake up. */ +unsigned int safe_sleep(unsigned int seconds) { + /* jochang sleep有問題時用*/ + sigset_t set,oldset; + + sigemptyset(&set); + sigprocmask(SIG_BLOCK, &set, &oldset); + if(sigismember(&oldset, SIGALRM)) { + unsigned long retv; + sigemptyset(&set); + sigaddset(&set,SIGALRM); + sigprocmask(SIG_UNBLOCK,&set,NULL); + retv=sleep(seconds); + sigprocmask(SIG_BLOCK,&set,NULL); + return retv; + } + return sleep(seconds); +} + +void setapath(char *buf, char *boardname) { + sprintf(buf, "man/boards/%s", boardname); +} + +static char *str_dotdir = ".DIR"; + +void setadir(char *buf, char *path) { + sprintf(buf, "%s/%s", path, str_dotdir); +} + +static void attach_err(int shmkey, char *name) { + fprintf(stderr, "[%s error] key = %x\n", name, shmkey); + fprintf(stderr, "errno = %d: %s\n", errno, strerror(errno)); + exit(1); +} + +void *attach_shm(int shmkey, int shmsize) { + void *shmptr; + int shmid; + + char *empty_addr; + /* set up one page in-accessible -- jochang */ + { + int fd = open("/dev/zero",O_RDONLY); + int size = ((shmsize + 4095) / 4096) * 4096; + + munmap( + (empty_addr=mmap(0,4096+size,PROT_NONE,MAP_PRIVATE,fd,0))+4096 + ,size); + + close(fd); + } + + shmid = shmget(shmkey, shmsize, 0); + if(shmid < 0) { + shmid = shmget(shmkey, shmsize, IPC_CREAT | 0600); + if(shmid < 0) + attach_err(shmkey, "shmget"); + shmptr = (void *)shmat(shmid, NULL, 0); + if(shmptr == (void *)-1) + attach_err(shmkey, "shmat"); + } else { + shmptr = (void *)shmat(shmid, NULL, 0); + if(shmptr == (void *)-1) + attach_err(shmkey, "shmat"); + } + + /* unmap the page -- jochang */ + { + munmap(empty_addr,4096); + } + return shmptr; +} + +#ifndef __FreeBSD__ +/* according to X/OPEN we have to define it ourselves */ +union semun { + int val; /* value for SETVAL */ + struct semid_ds *buf; /* buffer for IPC_STAT, IPC_SET */ + unsigned short int *array; /* array for GETALL, SETALL */ + struct seminfo *__buf; /* buffer for IPC_INFO */ +}; +#endif + +#define SEM_FLG 0600 /* semaphore mode */ + +/* ----------------------------------------------------- */ +/* semaphore : for critical section */ +/* ----------------------------------------------------- */ +void sem_init(int semkey,int *semid) { + union semun s; + + s.val=1; + *semid = semget(semkey, 1, 0); + if(*semid == -1) { + *semid = semget(semkey, 1, IPC_CREAT | SEM_FLG); + if(*semid == -1) + attach_err(semkey, "semget"); + semctl(*semid, 0, SETVAL, s); + } +} + +void sem_lock(int op,int semid) { + struct sembuf sops; + + sops.sem_num = 0; + sops.sem_flg = SEM_UNDO; + sops.sem_op = op; + semop(semid, &sops, 1); +} + +/* uhash *******************************************/ +/* the design is this: + we use another stand-alone program to create and load data into the hash. + (that program could be run in rc-scripts or something like that) + after loading completes, the stand-alone program sets loaded to 1 and exits. + + the bbs exits if it can't attach to the shared memory or + the hash is not loaded yet. +*/ +uhash_t *uhash; + +int setumoney(int uid, int money) { + uhash->money[uid-1]=money; + passwd_update_money(uid); + return uhash->money[uid-1]; +} + +int deumoney(int uid, int money) { + if(money<0 && uhash->money[uid-1]<-money) + return setumoney(uid,0); + else + return setumoney(uid,uhash->money[uid-1]+money); +} +int moneyof(int uid){ /* ptt 改進金錢處理效率 */ + return uhash->money[uid-1]; +} +/* attach_uhash should be called before using uhash */ +void attach_uhash() { + uhash = attach_shm(UHASH_KEY, sizeof(*uhash)); + if(!uhash->loaded) /* assume fresh shared memory is zeroed */ + exit(1); +} + + +static unsigned string_hash(unsigned char *s) { + unsigned int v=0; + while(*s) { + v = (v << 8) | (v >> 24); + v ^= toupper(*s++); /* note this is case insensitive */ + } + return (v * 2654435769UL) >> (32 - HASH_BITS); +} + +void add_to_uhash(int n, char *id) { + int *p, h = string_hash(id); + strcpy(uhash->userid[n], id); + + p = &(uhash->hash_head[h]); + + while(*p != -1) + p = &(uhash->next_in_hash[*p]); + + uhash->next_in_hash[*p = n] = -1; +} + +/* note: after remove_from_uhash(), you should add_to_uhash() + (likely with a different name) */ +void remove_from_uhash(int n) { + int h = string_hash(uhash->userid[n]); + int *p = &(uhash->hash_head[h]); + + while(*p != -1 && *p != n) + p = &(uhash->next_in_hash[*p]); + if(*p == n) + *p = uhash->next_in_hash[n]; +} + +int searchuser(char *userid) { + int h,p; + + if(uhash == NULL) + attach_uhash(); /* for sloopy util programs */ + + h = string_hash(userid); + p = uhash->hash_head[h]; + + while(p != -1) { + if(strcasecmp(uhash->userid[p],userid) == 0) { + strcpy(userid,uhash->userid[p]); + return p + 1; + } + p = uhash->next_in_hash[p]; + } + return 0; +} +userec_t xuser; + +int getuser(char *userid) { + int uid; + if((uid = searchuser(userid))) + passwd_query(uid, &xuser); + return uid; +} +void setuserid(int num, char *userid) { + if(num > 0 && num <= MAX_USERS) { + if(num > uhash->number) + uhash->number = num; + else + remove_from_uhash(num-1); + add_to_uhash(num-1,userid); + } +} + +/*-------------------------------------------------------*/ +/* .UTMP cache */ +/*-------------------------------------------------------*/ +struct utmpfile_t *utmpshm=NULL; + +void resolve_utmp() { + if(utmpshm == NULL) { + utmpshm = attach_shm(UTMPSHM_KEY, sizeof(*utmpshm)); + if(utmpshm->uptime == 0) + utmpshm->uptime = utmpshm->number = 1; + } +} + +userinfo_t *currutmp = NULL; + +void getnewutmpent(userinfo_t *up) { + extern int errno; + register int i; + register userinfo_t *uentp; + + resolve_utmp(); + + for(i = 0; i < USHM_SIZE; i++) { + uentp = &(utmpshm->uinfo[i]); + if(!(uentp->pid)) { + memcpy(uentp, up, sizeof(userinfo_t)); + currutmp = uentp; + utmpshm->number++; + return; + } + } + exit(1); +} + +int apply_ulist(int (*fptr)(userinfo_t *)) { + register userinfo_t *uentp; + register int i, state; + + resolve_utmp(); + for(i = 0; i < USHM_SIZE; i++) { + uentp = &(utmpshm->uinfo[i]); + if(uentp->pid && (PERM_HIDE(currutmp) || !PERM_HIDE(uentp))) + if((state = (*fptr) (uentp))) + return state; + } + return 0; +} + +userinfo_t *search_ulist(int uid) { + register int i; + register userinfo_t *uentp; + + resolve_utmp(); + for(i = 0; i < USHM_SIZE; i++) { + uentp = &(utmpshm->uinfo[i]); + if(uid==uentp->uid) + return uentp; + } + return 0; +} + +/*-------------------------------------------------------*/ +/* .BOARDS cache */ +/*-------------------------------------------------------*/ +char *fn_board=FN_BOARD; +bcache_t *brdshm; +boardheader_t *bcache; + +static void reload_bcache() { + if(brdshm->busystate) { + safe_sleep(1); + } +} + +int numboards = -1; + +void resolve_boards() { + if(brdshm == NULL) { + brdshm = attach_shm(BRDSHM_KEY, sizeof(*brdshm)); + if(brdshm->touchtime == 0) + brdshm->touchtime = 1; + bcache = brdshm->bcache; + } + + while(brdshm->uptime < brdshm->touchtime) + reload_bcache(); + numboards = brdshm->number; +} + +void touch_boards() { + time(&(brdshm->touchtime)); + numboards = -1; + resolve_boards(); +} +void reset_board(int bid) +{ + int fd; + if(--bid<0)return; + if(brdshm->busystate==0) + { + brdshm->busystate = 1; + if((fd = open(fn_board, O_RDONLY)) > 0) { + lseek(fd, (off_t)(bid * sizeof(boardheader_t)), SEEK_SET); + read(fd, &bcache[bid], sizeof(boardheader_t)); + close(fd); + } + brdshm->busystate = 0; + } +} +boardheader_t *getbcache(int bid) { /* Ptt改寫 */ + return bcache + bid - 1; +} + +void touchbtotal(int bid) { + brdshm->total[bid - 1] = 0; + brdshm->lastposttime[bid - 1] = 0; +} + + +int getbnum(char *bname) { + register int i; + register boardheader_t *bhdr; + + for(i = 0, bhdr = bcache; i++ < numboards; bhdr++) + if( + !strcasecmp(bname, bhdr->brdname)) + return i; + return 0; +} + +/*-------------------------------------------------------*/ +/* PTT cache */ +/*-------------------------------------------------------*/ +/* cachefor 動態看版 */ +struct pttcache_t *ptt; + +void reload_pttcache() { + if(ptt->busystate) + safe_sleep(1); + else { /* jochang: temporary workaround */ + fileheader_t item, subitem; + char pbuf[256], buf[256], *chr; + FILE *fp, *fp1, *fp2; + int id, section = 0; + + ptt->busystate = 1; + ptt->max_film = 0; + bzero(ptt->notes, sizeof ptt->notes); + setapath(pbuf, "Note"); + setadir(buf, pbuf); + id = 0; + if((fp = fopen(buf, "r"))) { + while(fread(&item, sizeof(item), 1, fp)) { + if(item.title[3]=='<' && item.title[8]=='>') { + sprintf(buf,"%s/%s", pbuf, item.filename); + setadir(buf, buf); + if(!(fp1 = fopen(buf, "r"))) + continue; + ptt->next_refresh[section] = ptt->n_notes[section] = id; + section ++; + while(fread(&subitem, sizeof(subitem), 1, fp1)) { + sprintf(buf,"%s/%s/%s", pbuf, item.filename , + subitem.filename); + if(!(fp2=fopen(buf,"r"))) + continue; + fread(ptt->notes[id],sizeof(char), 200*11, fp2); + ptt->notes[id][200*11 - 1]=0; + id++; + fclose(fp2); + if(id >= MAX_MOVIE) + break; + } + fclose(fp1); + if(id >= MAX_MOVIE || section >= MAX_MOVIE_SECTION) + break; + } + } + fclose(fp); + } + ptt->next_refresh[section] = -1; + ptt->n_notes[section] = ptt->max_film = id-1; + ptt->max_history = ptt->max_film - 2; + if(ptt->max_history > MAX_HISTORY - 1) + ptt->max_history = MAX_HISTORY - 1; + if(ptt->max_history <0) ptt->max_history=0; + + fp = fopen("etc/today_is","r"); + if(fp) { + fgets(ptt->today_is,15,fp); + if((chr = strchr(ptt->today_is,'\n'))) + *chr = 0; + ptt->today_is[15] = 0; + fclose(fp); + } + + /* 等所有資料更新後再設定 uptime */ + + ptt->uptime = ptt->touchtime ; + ptt->busystate = 0; + } +} + +void resolve_garbage() { + int count=0; + + if(ptt == NULL) { + ptt = attach_shm(PTTSHM_KEY, sizeof(*ptt)); + if(ptt->touchtime == 0) + ptt->touchtime = 1; + } + while(ptt->uptime < ptt->touchtime) { /* 不用while等 */ + reload_pttcache(); + if(count ++ > 10 && ptt->busystate) { +/* Ptt: 這邊會有問題 load超過10 秒會所有進loop的process都讓 busystate = 0 + 這樣會所有prcosee都會在load 動態看板 會造成load大增 + 但沒有用這個function的話 萬一load passwd檔的process死了 又沒有人把他 + 解開 同樣的問題發生在reload passwd +*/ + ptt->busystate = 0; + } + } +} + +/*-------------------------------------------------------*/ +/* PTT's cache */ +/*-------------------------------------------------------*/ +/* cachefor from host 與最多上線人數 */ +struct fromcache_t *fcache; + +static void reload_fcache() { + if(fcache->busystate) + safe_sleep(1); + else { + FILE *fp; + + fcache->busystate = 1; + bzero(fcache->domain, sizeof fcache->domain); + if((fp = fopen("etc/domain_name_query","r"))) { + char buf[101],*po; + + fcache->top=0; + while(fgets(buf,100,fp)) { + if(buf[0] && buf[0] != '#' && buf[0] != ' ' && + buf[0] != '\n') { + sscanf(buf,"%s",fcache->domain[fcache->top]); + po = buf + strlen(fcache->domain[fcache->top]); + while(*po == ' ') + po++; + strncpy(fcache->replace[fcache->top],po,49); + fcache->replace[fcache->top] + [strlen(fcache->replace[fcache->top])-1] = 0; + (fcache->top)++; + } + } + } + + fcache->max_user=0; + + /* 等所有資料更新後再設定 uptime */ + fcache->uptime = fcache->touchtime; + fcache->busystate = 0; + } +} + +void resolve_fcache() { + if(fcache == NULL) { + fcache = attach_shm(FROMSHM_KEY, sizeof(*fcache)); + if(fcache->touchtime == 0) + fcache->touchtime = 1; + } + while(fcache->uptime < fcache->touchtime) + reload_fcache(); +} diff --git a/pttbbs/util/util_passwd.c b/pttbbs/util/util_passwd.c new file mode 100644 index 00000000..07a79351 --- /dev/null +++ b/pttbbs/util/util_passwd.c @@ -0,0 +1,139 @@ +/* $Id: util_passwd.c,v 1.1 2002/03/07 15:13:46 in2 Exp $ */ +#include <stdio.h> +#include <string.h> +#include <fcntl.h> +#include <errno.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <sys/mman.h> +#include <sys/ipc.h> +#include <sys/sem.h> +#include "config.h" +#include "pttstruct.h" +#include "modes.h" +#include "common.h" + +#ifndef SEM_R +#define SEM_R 0400 +#endif + +#ifndef SEM_A +#define SEM_A 0200 +#endif + +#ifndef __FreeBSD__ +union semun { + int val; /* value for SETVAL */ + struct semid_ds *buf; /* buffer for IPC_STAT & IPC_SET */ + u_short *array; /* array for GETALL & SETALL */ + struct seminfo *__buf; /* buffer for IPC_INFO */ +}; +#endif + +static userec_t *passwd_image = NULL; +static int passwd_image_size; +static int semid = -1; + +int passwd_mmap() { + int fd; + + if(passwd_image!=NULL) return 0; + fd = open(FN_PASSWD, O_RDWR); + if(fd > 0) { + struct stat st; + + fstat(fd, &st); + passwd_image_size = st.st_size; + passwd_image = mmap(NULL, passwd_image_size, + PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); + if(passwd_image == (userec_t *)-1) { + perror("mmap"); + return -1; + } + close(fd); + semid = semget(PASSWDSEM_KEY, 1, SEM_R | SEM_A | IPC_CREAT | IPC_EXCL); + if(semid == -1) { + if(errno == EEXIST) { + semid = semget(PASSWDSEM_KEY, 1, SEM_R | SEM_A); + if(semid == -1) { + perror("semget"); + exit(1); + } + } else { + perror("semget"); + exit(1); + } + } else { + union semun s; + + s.val = 1; + if(semctl(semid, 0, SETVAL, s) == -1) { + perror("semctl"); + exit(1); + } + } + } else { + perror(FN_PASSWD); + return -1; + } + return 0; +} +int passwd_update_money(int num) { + int money; + if(num < 1 || num > MAX_USERS) + return -1; + money = moneyof(num); + memcpy(&passwd_image[num - 1].money, &money, sizeof(int)); + return 0; +} + +int passwd_update(int num, userec_t *buf) { + if(num < 1 || num > MAX_USERS) + return -1; + buf->money = moneyof(num); + memcpy(&passwd_image[num - 1], buf, sizeof(userec_t)); + return 0; +} + +int passwd_query(int num, userec_t *buf) { + if(num < 1 || num > MAX_USERS) + return -1; + memcpy(buf, &passwd_image[num - 1], sizeof(userec_t)); + return 0; +} + +int passwd_apply(int (*fptr)(userec_t *)) { + int i; + + for(i = 0; i < MAX_USERS; i++) + if((*fptr)(&passwd_image[i]) == QUIT) + return QUIT; + return 0; +} + +int passwd_apply2(int (*fptr)(int, userec_t *)) { + int i; + + for(i = 0; i < MAX_USERS; i++) + if((*fptr)(i, &passwd_image[i]) == QUIT) + return QUIT; + return 0; +} + +void passwd_lock() { + struct sembuf buf = { 0, -1, SEM_UNDO }; + + if(semop(semid, &buf, 1)) { + perror("semop"); + exit(1); + } +} + +void passwd_unlock() { + struct sembuf buf = { 0, 1, SEM_UNDO }; + + if(semop(semid, &buf, 1)) { + perror("semop"); + exit(1); + } +} diff --git a/pttbbs/util/util_record.c b/pttbbs/util/util_record.c new file mode 100644 index 00000000..ad129638 --- /dev/null +++ b/pttbbs/util/util_record.c @@ -0,0 +1,245 @@ +/* $Id: util_record.c,v 1.1 2002/03/07 15:13:46 in2 Exp $ */ +#include <stdio.h> +#include <errno.h> +#include <string.h> +#include <unistd.h> +#include <time.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <sys/file.h> +#include "config.h" +#include "pttstruct.h" +#include "modes.h" +#include "proto.h" + +#undef HAVE_MMAP +#define BUFSIZE 512 + +extern char *str_reply; + +static void PttLock(int fd, int size, int mode) { + static struct flock lock_it; + int ret; + + lock_it.l_whence = SEEK_CUR; /* from current point */ + lock_it.l_start = 0; /* -"- */ + lock_it.l_len = size; /* length of data */ + lock_it.l_type = mode; /* set exclusive/write lock */ + lock_it.l_pid = 0; /* pid not actually interesting */ + while((ret = fcntl(fd, F_SETLKW, &lock_it)) < 0 && errno == EINTR); +} + +#define safewrite write + +int get_num_records(char *fpath, int size) { + struct stat st; + if(stat(fpath, &st) == -1) + return 0; + return st.st_size / size; +} + +int get_sum_records(char* fpath, int size) { + struct stat st; + long ans = 0; + FILE* fp; + fileheader_t fhdr; + char buf[200], *p; + + if(!(fp = fopen(fpath, "r"))) + return -1; + + strcpy(buf, fpath); + p = strrchr(buf, '/') + 1; + + while(fread(&fhdr, size, 1, fp) == 1) { + strcpy(p, fhdr.filename); + if(stat(buf, &st) == 0 && S_ISREG(st.st_mode) && st.st_nlink == 1) + ans += st.st_size; + } + fclose(fp); + return ans / 1024; +} + +int get_record(char *fpath, void *rptr, int size, int id) { + int fd = -1; + + if(id < 1 || (fd = open(fpath, O_RDONLY, 0)) != -1) { + if(lseek(fd, (off_t)(size * (id - 1)), SEEK_SET) != -1) { + if(read(fd, rptr, size) == size) { + close(fd); + return 0; + } + } + close(fd); + } + return -1; +} + +int get_records(char *fpath, void *rptr, int size, int id, int number) { + int fd; + + if(id < 1 || (fd = open(fpath, O_RDONLY, 0)) == -1) + return -1; + + if(lseek(fd, (off_t)(size * (id - 1)), SEEK_SET) == -1) { + close(fd); + return 0; + } + if((id = read(fd, rptr, size * number)) == -1) { + close(fd); + return -1; + } + close(fd); + return id / size; +} + +int substitute_record(char *fpath, void *rptr, int size, int id) { + int fd; + +#ifdef POSTBUG + if(size == sizeof(fileheader) && (id > 1) && ((id - 1) % 4 == 0)) + saverecords(fpath, size, id); +#endif + + if(id < 1 || (fd = open(fpath, O_WRONLY | O_CREAT, 0644)) == -1) + return -1; + +#ifdef HAVE_REPORT + if(lseek(fd, (off_t)(size * (id - 1)), SEEK_SET) == -1) + report("substitute_record failed!!! (lseek)"); + PttLock(fd, size, F_WRLCK); + if(safewrite(fd, rptr, size) != size) + report("substitute_record failed!!! (safewrite)"); + PttLock(fd, size, F_UNLCK); +#else + lseek(fd, (off_t) (size * (id - 1)), SEEK_SET); + PttLock(fd, size, F_WRLCK); + safewrite(fd, rptr, size); + PttLock(fd, size, F_UNLCK); +#endif + close(fd); + +#ifdef POSTBUG + if(size == sizeof(fileheader) && (id > 1) && ((id - 1) % 4 == 0)) + restorerecords(fpath, size, id); +#endif + + return 0; +} + +int apply_record(char *fpath, int (*fptr)(), int size) { + char abuf[BUFSIZE]; + FILE* fp; + + if(!(fp = fopen(fpath, "r"))) + return -1; + + while(fread(abuf, 1, size, fp) == size) + if((*fptr) (abuf) == QUIT) { + fclose(fp); + return QUIT; + } + fclose(fp); + return 0; +} + +/* mail / post 時,依據時間建立檔案,加上郵戳 */ +int stampfile(char *fpath, fileheader_t *fh) { + register char *ip = fpath; + time_t dtime; + struct tm *ptime; + int fp = 0; + + if(access(fpath, X_OK | R_OK | W_OK)) + mkdir(fpath, 0755); + + time(&dtime); + while (*(++ip)); + *ip++ = '/'; + do { + sprintf(ip, "M.%ld.A", ++dtime ); + if(fp == -1 && errno != EEXIST) + return -1; + } while((fp = open(fpath, O_CREAT | O_EXCL | O_WRONLY, 0644)) == -1); + close(fp); + memset(fh, 0, sizeof(fileheader_t)); + strcpy(fh->filename, ip); + ptime = localtime(&dtime); + sprintf(fh->date, "%2d/%02d", ptime->tm_mon + 1, ptime->tm_mday); + return 0; +} + +void stampdir(char *fpath, fileheader_t *fh) { + register char *ip = fpath; + time_t dtime; + struct tm *ptime; + + if(access(fpath, X_OK | R_OK | W_OK)) + mkdir(fpath, 0755); + + time(&dtime); + while(*(++ip)); + *ip++ = '/'; + do { + sprintf(ip, "D%lX", ++dtime & 07777); + } while(mkdir(fpath, 0755) == -1); + memset(fh, 0, sizeof(fileheader_t)); + strcpy(fh->filename, ip); + ptime = localtime(&dtime); + sprintf(fh->date, "%2d/%02d", ptime->tm_mon + 1, ptime->tm_mday); +} + +void stamplink(char *fpath, fileheader_t *fh) { + register char *ip = fpath; + time_t dtime; + struct tm *ptime; + + if(access(fpath, X_OK | R_OK | W_OK)) + mkdir(fpath, 0755); + + time(&dtime); + while(*(++ip)); + *ip++ = '/'; + do { + sprintf(ip, "S%lX", ++dtime ); + } while(symlink("temp", fpath) == -1); + memset(fh, 0, sizeof(fileheader_t)); + strcpy(fh->filename, ip); + ptime = localtime(&dtime); + sprintf(fh->date, "%2d/%02d", ptime->tm_mon + 1, ptime->tm_mday); +} + +int do_append(char *fpath, fileheader_t *record, int size) { + int fd; + + if((fd = open(fpath, O_WRONLY | O_CREAT, 0644)) == -1) { + perror("open"); + return -1; + } + flock(fd, LOCK_EX); + lseek(fd, 0, SEEK_END); + + safewrite(fd, record, size); + + flock(fd, LOCK_UN); + close(fd); + return 0; +} + +int append_record(char *fpath, fileheader_t *record, int size) { +#ifdef POSTBUG + int numrecs = (int)get_num_records(fpath, size); + + bug_possible = 1; + if(size == sizeof(fileheader) && numrecs && (numrecs % 4 == 0)) + saverecords(fpath, size, numrecs + 1); +#endif + do_append(fpath,record,size); + +#ifdef POSTBUG + if(size == sizeof(fileheader) && numrecs && (numrecs % 4 == 0)) + restorerecords(fpath, size, numrecs + 1); + bug_possible = 0; +#endif + return 0; +} diff --git a/pttbbs/util/waterball.pl b/pttbbs/util/waterball.pl new file mode 100644 index 00000000..7f49d3c5 --- /dev/null +++ b/pttbbs/util/waterball.pl @@ -0,0 +1,149 @@ +#!/usr/bin/perl +use lib '/home/bbs/bin/'; +use LocalVars; +use Time::Local; +use POSIX; +use FileHandle; +use strict; +use Mail::Sender; + +my($fndes, $fnsrc, $userid, $mailto, $outmode); +foreach $fndes ( <$JOBSPOOL/water.des.*> ){ #des: userid, mailto, outmode + (open FH, "< $fndes") or next; + chomp($userid = <FH>); + chomp($mailto = <FH>); + chomp($outmode= <FH>); + close FH; + next if( !$userid ); + print "$userid, $mailto, $outmode\n"; + `rm -Rf $TMP/water`; + `mkdir $TMP/water`; + + $fnsrc = $fndes; + $fnsrc =~ s/\.des\./\.src\./; + eval{ + process($fnsrc, "$TMP/water/", $outmode, $userid); + }; + if( $@ ){ + print "$@\n"; + } + else{ + chdir "$TMP/water"; + if( $mailto eq '.' || $mailto =~ /\.bbs/ ){ + $mailto = "$userid.bbs\@$hostname" if( $mailto eq '.' ); + foreach my $fn ( <$TMP/water/*> ){ + my $who = substr($fn, rindex($fn, '/') + 1); + my $content = ''; + open FH, "< $fn";while( <FH> ){chomp;$content .= "$_\n";} + if( !MakeMail({mailto => $mailto, + subject => "和 $who 的水球記錄", + body => $content, + }) ){ print "fault\n"; } + } + unlink $fnsrc; + unlink $fndes; + } + else{ + if( MakeMail({tartarget => "$TMP/$userid.waterball.tgz", + tarsource => "*", + mailto => "$userid <$mailto>", + subject => "水球紀錄", + body => + "\n ptt2 站長群 ". POSIX::ctime(time())} + ) ){ + unlink $fnsrc; + unlink $fndes; + } + } + } +} + +sub process +{ + my($fn, $outdir, $outmode, $me) = @_; + my($cmode, $who, $time, $say, $orig, %FH, %LAST, $len); + open DIN, "< $fn"; + while( <DIN> ){ + chomp; + next if( !(($cmode, $who, $time, $say, $orig) = parse($_)) ); + next if( !$who ); + + if( ! $FH{$who} ){ + $FH{$who} = new FileHandle "> $outdir/$who"; + } + if( $outmode == 0 ){ + next if( $say =~ /<<下站通知>> -- 我走囉!/ || + $say =~ /<<上站通知>> -- 我來啦!/ ); + if( $time - $LAST{$who} > 1800 ){ + if( $LAST{$who} != 0 ){ + ($FH{$who})->print( POSIX::ctime($LAST{$who}) , "\n"); + } + ($FH{$who})->print( POSIX::ctime($time) ); + $LAST{$who} = $time; + } + $len = (length($who) > length($me) ? length($who) : length($me))+1; + ($FH{$who})->printf("%-${len}s %s\n", ($cmode?$who:$me).':', $say); + } + elsif( $outmode == 1 ){ + ($FH{$who})->print("$orig\n"); + } + } + if( $outmode == 0 ){ + foreach( keys %FH ){ + ($FH{$_})->print( POSIX::ctime($LAST{$_}) ); + } + } + foreach( keys %FH ){ + ($FH{$_})->close(); + } + close DIN; +} + +sub parse +{ + my $dat = $_[0]; + my($cmode, $who, $year, $month, $day, $hour, $min, $sec, $say); + if( $dat =~ /^To/ ){ + $cmode = 0; + ($who, $say, $month, $day, $year, $hour, $min, $sec) = + $dat =~ m|^To (\w+):\s*(.*)\[(\d+)/(\d+)/(\d+) (\d+):(\d+):(\d+)\]|; + } + else{ + $cmode = 1; + ($who, $say, $month, $day, $year, $hour, $min, $sec) = + $dat =~ m|★(\w+?)\[37;45m\s*(.*)\[m \[0m\[(\w+)/(\w+)/(\w+) (\w+):(\w+):(\w+)\]|; + + } +# $time = timelocal($sec,$min,$hours,$mday,$mon,$year); + + return undef if( $month == 0 ); + return ($cmode, $who, timelocal($sec, $min, $hour, $day, $month - 1, $year), $say, $_[0]); +} + +sub MakeMail +{ + my($arg) = @_; + my $sender; + `$TAR zcf $arg->{tartarget} $arg->{tarsource}` + if( $arg->{tarsource} ); + $sender = new Mail::Sender{smtp => $SMTPSERVER, + from => "$hostname水球整理程式 <in2\@ptt2.csie.ntu.edu.tw>"}; + foreach( 0..3 ){ + if( (!$arg->{tartarget} && + $sender->MailMsg({to => $arg->{mailto}, + subject => $arg->{subject}, + msg => $arg->{body} + }) ) || + ($arg->{tartarget} && + $sender->MailFile({to => $arg->{mailto}, + subject => $arg->{subject}, + msg => $arg->{body}, + file => $arg->{tartarget}})) ){ + unlink $arg->{tartarget} if( $arg->{tartarget} ); + return 1; + } + } + print "fault\n"; + unlink $arg->{tartarget} if( $arg->{tartarget} ); + return 0; +} diff --git a/pttbbs/util/weather.perl b/pttbbs/util/weather.perl new file mode 100644 index 00000000..c9a35406 --- /dev/null +++ b/pttbbs/util/weather.perl @@ -0,0 +1,31 @@ +#!/usr/bin/perl +# $Id: weather.perl,v 1.1 2002/03/07 15:13:46 in2 Exp $ +# +# 不能跑的話,看看 bbspost 的路徑是否正確。 +# 如果發出的 post 沒有氣象報告而是說 URL 找不到,則確定一下能不能看到 +# 中央氣象局的 WWW 及 URL 是否正確。 +# 理論上適用所有 Eagle BBS 系列。 +# -- Beagle Apr 13 1997 +open(BBSPOST, "| bin/webgrep>etc/weather.tmp"); +# 日期 +open(DATE, "date +'%a %b %d %T %Y' |"); +$date = <DATE>; +chop $date; +close DATE; + +# Header +# 內容 +open(WEATHER, "/usr/bin/lynx -dump http://www.cwb.gov.tw/V3.0/weather/text/Data/W03.txt |"); +while (<WEATHER>) { + print BBSPOST if ($_ ne "\n"); +} +close WEATHER; + +# 簽名檔 +print BBSPOST "\n--\n"; +print BBSPOST "我是beagle所有可愛的小餅乾...跨海為Ptt服務\n"; +print BBSPOST "--\n"; +print BBSPOST "☆ [Origin: ◎果醬小站◎] [From: [藍莓鬆餅屋] ] "; + +close BBSPOST; + diff --git a/pttbbs/util/weather.sh b/pttbbs/util/weather.sh new file mode 100644 index 00000000..315b0ec3 --- /dev/null +++ b/pttbbs/util/weather.sh @@ -0,0 +1,5 @@ +#!/bin/sh +# $Id: weather.sh,v 1.1 2002/03/07 15:13:46 in2 Exp $ +# +bin/weather.perl +bin/post Record 全省各地天氣預報 [氣象小姐] etc/weather.tmp diff --git a/pttbbs/util/webgrep.c b/pttbbs/util/webgrep.c new file mode 100644 index 00000000..07089bb6 --- /dev/null +++ b/pttbbs/util/webgrep.c @@ -0,0 +1,46 @@ +/* $Id: webgrep.c,v 1.1 2002/03/07 15:13:46 in2 Exp $ */ +#include <stdio.h> +#include <string.h> +#include <stdlib.h> + +int main() +{ + char genbuf[256], *str, *buf; + while (fgets(genbuf, 255, stdin)) + { + register int ansi; + if (!strncmp(genbuf, "References", 10)) + break; + str = genbuf; + buf = genbuf; + if (!strncmp(genbuf, "lynx: Can't access", 18)) + { + printf("氣象報導小姐休假中,請到Record版翻過去資料."); + break; + } + for (ansi = 0; *str; str++) + { + if (*str == '[' && strchr("0123456789", *(str + 1))) + { + ansi = 1; + } + else if (ansi) + { + if (!strchr("0123456789]", *str)) + { + ansi = 0; + if (str) + *buf++ = *str; + } + } + else + { + if (str) + *buf++ = *str; + } + } + *buf = 0; + printf(genbuf); + } + return 0; +} diff --git a/pttbbs/util/xchatd.c b/pttbbs/util/xchatd.c new file mode 100644 index 00000000..46fba147 --- /dev/null +++ b/pttbbs/util/xchatd.c @@ -0,0 +1,3504 @@ +/* $Id: xchatd.c,v 1.1 2002/03/07 15:13:46 in2 Exp $ */ +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> +#include <netdb.h> +#include <fcntl.h> +#include <signal.h> +#include <errno.h> +#include <sys/types.h> +#include <sys/wait.h> +#include <sys/ioctl.h> +#include <sys/socket.h> +#include <time.h> +#include <sys/resource.h> +#include <netinet/in.h> +#include <arpa/inet.h> +#include "config.h" +#include "pttstruct.h" +#include "util.h" +#include "perm.h" +#include "common.h" +#include "xchatd.h" + +#define SERVER_USAGE +#define WATCH_DOG +#undef MONITOR /* 監督 chatroom 活動以解決糾紛 */ +#undef DEBUG /* 程式除錯之用 */ + +#ifdef DEBUG +#define MONITOR +#endif + +static int gline; + +#ifdef WATCH_DOG +#define MYDOG gline = __LINE__ +#else +#define MYDOG /* NOOP */ +#endif + + + +#define CHAT_PIDFILE "log/chat.pid" +#define CHAT_LOGFILE "log/chat.log" +#define CHAT_INTERVAL (60 * 30) +#define SOCK_QLEN 1 + + +/* name of the main room (always exists) */ + + +#define MAIN_NAME "main" +#define MAIN_TOPIC "烹茶可貢西天佛" + + +#define ROOM_LOCKED 1 +#define ROOM_SECRET 2 +#define ROOM_OPENTOPIC 4 +#define ROOM_HANDUP 8 +#define ROOM_ALL (NULL) + + +#define LOCKED(room) (room->rflag & ROOM_LOCKED) +#define SECRET(room) (room->rflag & ROOM_SECRET) +#define OPENTOPIC(room) (room->rflag & ROOM_OPENTOPIC) +#define RHANDUP(room) (room->rflag & ROOM_HANDUP) + +#define RESTRICTED(usr) (usr->uflag == 0) /* guest */ +#define CHATSYSOP(usr) (usr->uflag & ( PERM_SYSOP | PERM_CHATROOM)) +/* Thor: SYSOP 與 CHATROOM都是 chat總管 */ +#define PERM_ROOMOP PERM_CHAT /* Thor: 借 PERM_CHAT為 PERM_ROOMOP */ +#define PERM_HANDUP PERM_BM /* 借 PERM_BM 為有沒有舉手過 */ +#define PERM_SAY PERM_NOTOP /* 借 PERM_NOTOP 為有沒有發表權 */ + +/* 進入時需清空 */ +/* Thor: ROOMOP為房間管理員 */ +#define ROOMOP(usr) (usr->uflag & ( PERM_ROOMOP | PERM_SYSOP | PERM_CHATROOM)) +#define CLOAK(usr) (usr->uflag & PERM_CLOAK) +#define HANDUP(usr) (usr->uflag & PERM_HANDUP) +#define SAY(usr) (usr->uflag & PERM_SAY) +/* Thor: 聊天室隱身術 */ + + +/* ----------------------------------------------------- */ +/* ChatRoom data structure */ +/* ----------------------------------------------------- */ + +typedef struct ChatRoom ChatRoom; +typedef struct ChatUser ChatUser; +typedef struct UserList UserList; +typedef struct ChatCmd ChatCmd; +typedef struct ChatAction ChatAction; + +struct ChatUser +{ + struct ChatUser *unext; + int sock; /* user socket */ + int talksock; /* talk socket */ + ChatRoom *room; + UserList *ignore; + int userno; + int uflag; + int clitype; /* Xshadow: client type. 1 for common client, + * 0 for bbs only client */ + time_t uptime; /* Thor: unused */ + char userid[IDLEN + 1]; /* real userid */ + char chatid[9]; /* chat id */ + char lasthost[30]; /* host address */ + char ibuf[80]; /* buffer for non-blocking receiving */ + int isize; /* current size of ibuf */ +}; + + +struct ChatRoom +{ + struct ChatRoom *next, *prev; + char name[IDLEN]; + char topic[48]; /* Let the room op to define room topic */ + int rflag; /* ROOM_LOCKED, ROOM_SECRET, ROOM_OPENTOPIC */ + int occupants; /* number of users in room */ + UserList *invite; +}; + + +struct UserList +{ + struct UserList *next; + int userno; + char userid[IDLEN + 1]; +}; + + +struct ChatCmd +{ + char *cmdstr; + void (*cmdfunc) (); + int exact; +}; + + +static ChatRoom mainroom; +static ChatUser *mainuser; +static fd_set mainfds; +static int maxfds; /* number of sockets to select on */ +static int totaluser; /* current number of connections */ +static struct timeval zerotv; /* timeval for selecting */ +static char chatbuf[256]; /* general purpose buffer */ +static int common_client_command; + +static char msg_not_op[] = "◆ 您不是這間聊天室的 Op"; +static char msg_no_such_id[] = "◆ 目前沒有人使用 [%s] 這個聊天代號"; +static char msg_not_here[] = "◆ [%s] 不在這間聊天室"; + + +#define FUZZY_USER ((ChatUser *) -1) + + +typedef struct userec_t ACCT; + +/* ----------------------------------------------------- */ +/* acct_load for check acct */ +/* ----------------------------------------------------- */ + +int +acct_load(acct, userid) + ACCT *acct; + char *userid; +{ + int id; + if((id=searchuser(userid))<0) + { + return -1; + } + else + { + return get_record(FN_PASSWD, acct, sizeof(ACCT), id); + } +} + + +/* ----------------------------------------------------- */ +/* str_lower for check acct */ +/* ----------------------------------------------------- */ +void +str_lower(dst, src) + char *dst, *src; +{ + register int ch; + + do + { + ch = *src++; + if (ch >= 'A' && ch <= 'Z') + ch |= 0x20; + *dst++ = ch; + } while (ch); +} + +/* + * str_ncpy() - similar to strncpy(3) but terminates string always with '\0' + * if n != 0, and doesn't do padding + */ + +void +str_ncpy(dst, src, n) + char *dst; + char *src; + int n; +{ + char *end; + + end = dst + n; + + do + { + n = (dst == end) ? 0 : *src++; + *dst++ = n; + } while (n); +} + + +/* ----------------------------------------------------- */ +/* usr_fpath for check acct */ +/* ----------------------------------------------------- */ +char *str_home_file = "home/%c/%s/%s"; + +void +usr_fpath(buf, userid, fname) + char *buf, *userid, *fname; +{ + sprintf(buf, str_home_file, userid[0], userid, fname); +} + +/* ----------------------------------------------------- */ +/* chkpasswd for check passwd */ +/* ----------------------------------------------------- */ +char *crypt(); +static char pwbuf[PASSLEN]; + +int +chkpasswd(passwd, test) + char *passwd, *test; +{ + char *pw; + + str_ncpy(pwbuf, test, PASSLEN); + pw = crypt(pwbuf, passwd); + return (!strncmp(pw, passwd, PASSLEN)); +} + +/* ----------------------------------------------------- */ +/* operation log and debug information */ +/* ----------------------------------------------------- */ + + +static int flog; /* log file descriptor */ + + +static void +logit(key, msg) + char *key; + char *msg; +{ + time_t now; + struct tm *p; + char buf[512]; + + time(&now); + p = localtime(&now); + sprintf(buf, "%02d/%02d %02d:%02d:%02d %-13s%s\n", + p->tm_mon + 1, p->tm_mday, + p->tm_hour, p->tm_min, p->tm_sec, key, msg); + write(flog, buf, strlen(buf)); +} + + +static void +log_init() +{ + flog = open(CHAT_LOGFILE, O_WRONLY | O_CREAT | O_APPEND, 0644); + logit("START", "chat daemon"); +} + + +static void +log_close() +{ + close(flog); +} + + +#ifdef DEBUG +static void +debug_user() +{ + register ChatUser *user; + int i; + char buf[80]; + + i = 0; + for (user = mainuser; user; user = user->unext) + { + sprintf(buf, "%d) %s %s", ++i, user->userid, user->chatid); + logit("DEBUG_U", buf); + } +} + + +static void +debug_room() +{ + register ChatRoom *room; + int i; + char buf[80]; + + i = 0; + room = &mainroom; + + do + { + sprintf(buf, "%d) %s %d", ++i, room->name, room->occupants); + logit("DEBUG_R", buf); + } while (room = room->next); +} +#endif /* DEBUG */ + + +/* ----------------------------------------------------- */ +/* string routines */ +/* ----------------------------------------------------- */ + + +static int valid_chatid(register char *id) { + register int ch, len; + + for(len = 0; (ch = *id); id++) { + /* Thor: check for endless */ + MYDOG; + + if(ch == '/' || ch == '*' || ch == ':') + return 0; + if(++len > 8) + return 0; + } + return len; +} + +/* Case Independent strcmp : 1 ==> euqal */ + + +static int +str_equal(s1, s2) + register unsigned char *s1, *s2; /* Thor: 加上 unsigned, + * 避免中文的問題 */ +{ + register int c1, c2; + + for (;;) + { /* Thor: check for endless */ + MYDOG; + + c1 = *s1; + if (c1 >= 'A' && c1 <= 'Z') + c1 |= 32; + + c2 = *s2; + if (c2 >= 'A' && c2 <= 'Z') + c2 |= 32; + + if (c1 != c2) + return 0; + + if (!c1) + return 1; + + s1++; + s2++; + } +} + + +/* ----------------------------------------------------- */ +/* match strings' similarity case-insensitively */ +/* ----------------------------------------------------- */ +/* str_match(keyword, string) */ +/* ----------------------------------------------------- */ +/* 0 : equal ("foo", "foo") */ +/* -1 : mismatch ("abc", "xyz") */ +/* ow : similar ("goo", "good") */ +/* ----------------------------------------------------- */ + + +static int +str_match(s1, s2) + register unsigned char *s1, *s2; /* Thor: 加上 unsigned, + * 避免中文的問題 */ +{ + register int c1, c2; + + for (;;) + { /* Thor: check for endless */ + MYDOG; + + c2 = *s2; + c1 = *s1; + if (!c1) + { + return c2; + } + + if (c1 >= 'A' && c1 <= 'Z') + c1 |= 32; + + if (c2 >= 'A' && c2 <= 'Z') + c2 |= 32; + + if (c1 != c2) + return -1; + + s1++; + s2++; + } +} + + +/* ----------------------------------------------------- */ +/* search user/room by its ID */ +/* ----------------------------------------------------- */ + + +static ChatUser * +cuser_by_userid(userid) + char *userid; +{ + register ChatUser *cu; + + for (cu = mainuser; cu; cu = cu->unext) + { + MYDOG; + + if (str_equal(userid, cu->userid)) + break; + } + return cu; +} + + +static ChatUser * +cuser_by_chatid(chatid) + char *chatid; +{ + register ChatUser *cu; + + for (cu = mainuser; cu; cu = cu->unext) + { + MYDOG; + + if (str_equal(chatid, cu->chatid)) + break; + } + return cu; +} + + +static ChatUser * +fuzzy_cuser_by_chatid(chatid) + char *chatid; +{ + register ChatUser *cu, *xuser; + int mode; + + xuser = NULL; + + for (cu = mainuser; cu; cu = cu->unext) + { + MYDOG; + + mode = str_match(chatid, cu->chatid); + if (mode == 0) + return cu; + + if (mode > 0) + { + if (xuser == NULL) + xuser = cu; + else + return FUZZY_USER; /* 符合者大於 2 人 */ + } + } + return xuser; +} + + +static ChatRoom *croom_by_roomid(char *roomid) { + register ChatRoom *room; + + room = &mainroom; + do { + MYDOG; + + if(str_equal(roomid, room->name)) + break; + } while((room = room->next)); + return room; +} + + +/* ----------------------------------------------------- */ +/* UserList routines */ +/* ----------------------------------------------------- */ + + +static void +list_free(list) + UserList *list; +{ + UserList *tmp; + + while (list) + { + MYDOG; + + tmp = list->next; + + free(list); + MYDOG; + list = tmp; + } +} + + +static void +list_add(list, user) + UserList **list; + ChatUser *user; +{ + UserList *node; + + MYDOG; + + if((node = (UserList *) malloc(sizeof(UserList)))) { + /* Thor: 防止空間不夠 */ + strcpy(node->userid, user->userid); + node->userno = user->userno; + node->next = *list; + *list = node; + } + MYDOG; +} + + +static int +list_delete(list, userid) + UserList **list; + char *userid; +{ + UserList *node; + + while((node = *list)) { + MYDOG; + + if (str_equal(node->userid, userid)) + { + *list = node->next; + MYDOG; + free(node); + MYDOG; + return 1; + } + list = &node->next; /* Thor: list要跟著前進 */ + } + + return 0; +} + + +static int +list_belong(list, userno) + UserList *list; + int userno; +{ + while (list) + { + MYDOG; + + if (userno == list->userno) + return 1; + list = list->next; + } + return 0; +} + + +/* ------------------------------------------------------ */ +/* non-blocking socket routines : send message to users */ +/* ------------------------------------------------------ */ + + +static void +do_send(nfds, wset, msg, number) + int nfds; + fd_set *wset; + char *msg; + int number; +{ + int sr; + + /* Thor: for future reservation bug */ + + zerotv.tv_sec = 0; + zerotv.tv_usec = 16384; /* Ptt: 改成16384 避免不按時for loop吃cpu time + 16384 約每秒64次 */ + + MYDOG; + + sr = select(nfds + 1, NULL, wset, NULL, &zerotv); + + MYDOG; + + if (sr > 0) + { + register int len; + + len = strlen(msg) + 1; + while (nfds >= 0) + { + MYDOG; + + if (FD_ISSET(nfds, wset)) + { + MYDOG; + send(nfds, msg, len, 0);/* Thor: 如果buffer滿了, 仍會 block */ + MYDOG; + if (--sr <= 0) + return; + } + nfds--; + } + } +} + + +static void +send_to_room(room, msg, userno, number) + ChatRoom *room; + char *msg; + int userno; + int number; +{ + ChatUser *cu; + fd_set wset, *wptr; + int sock, max; + static char sendbuf[256]; + int clitype; /* 分為 bbs client 及 common client 兩次處理 */ + + for (clitype = (number == MSG_MESSAGE || !number) ? 0 : 1; clitype < 2; clitype++) + { + + FD_ZERO(wptr = &wset); + max = -1; + + for (cu = mainuser; cu; cu = cu->unext) + { + MYDOG; + + if (room == cu->room || room == ROOM_ALL) + { + if (cu->clitype == clitype && (!userno || !list_belong(cu->ignore, userno))) + { + sock = cu->sock; + FD_SET(sock, wptr); + if (max < sock) + max = sock; + } + } + } + + if (max < 0) + continue; + + if (clitype) + { + if (strlen(msg)) + sprintf(sendbuf, "%3d %s", number, msg); + else + sprintf(sendbuf, "%3d", number); + + do_send(max, wptr, sendbuf); + } + else + do_send(max, wptr, msg); + } +} + + +static void +send_to_user(user, msg, userno, number) + ChatUser *user; + char *msg; + int userno; + int number; +{ + if (!user->clitype && number && number != MSG_MESSAGE) + return; + + if (!userno || !list_belong(user->ignore, userno)) + { + fd_set wset, *wptr; + int sock; + static char sendbuf[256]; + + sock = user->sock; + FD_ZERO(wptr = &wset); + FD_SET(sock, wptr); + + if (user->clitype) + { + if (strlen(msg)) + sprintf(sendbuf, "%3d %s", number, msg); + else + sprintf(sendbuf, "%3d", number); + do_send(sock, wptr, sendbuf); + } + else + do_send(sock, wptr, msg); + } +} + +#if 0 +static void +send_to_sock(sock, msg) /* Thor: unused */ + int sock; + char *msg; +{ + fd_set wset, *wptr; + + FD_ZERO(wptr = &wset); + FD_SET(sock, wptr); + do_send(sock, wptr, msg); +} +#endif + +/* ----------------------------------------------------- */ + +static void +room_changed(room) + ChatRoom *room; +{ + if (!room) + return; + + sprintf(chatbuf, "= %s %d %d %s", room->name, room->occupants, room->rflag, room->topic); + send_to_room(ROOM_ALL, chatbuf, 0, MSG_ROOMNOTIFY); +} + +static void +user_changed(cu) + ChatUser *cu; +{ + if (!cu) + return; + + sprintf(chatbuf, "= %s %s %s %s", cu->userid, cu->chatid, cu->room->name, cu->lasthost); + if (ROOMOP(cu)) + strcat(chatbuf, " Op"); + send_to_room(cu->room, chatbuf, 0, MSG_USERNOTIFY); +} + +static void +exit_room(user, mode, msg) + ChatUser *user; + int mode; + char *msg; +{ + ChatRoom *room; + + if((room = user->room)) { + user->room = NULL; + user->uflag &= ~PERM_ROOMOP; + + if (--room->occupants > 0) + { + char *chatid; + + chatid = user->chatid; + switch (mode) + { + case EXIT_LOGOUT: + + sprintf(chatbuf, "◆ %s 離開了 ...", chatid); + if (msg && *msg) + { + strcat(chatbuf, ": "); + msg[79] = 0; /* Thor:防止太長 */ + strncat(chatbuf, msg, 80); + } + break; + + case EXIT_LOSTCONN: + + sprintf(chatbuf, "◆ %s 成了斷線的風箏囉", chatid); + break; + + case EXIT_KICK: + + sprintf(chatbuf, "◆ 哈哈!%s 被踢出去了", chatid); + break; + } + if (!CLOAK(user)) /* Thor: 聊天室隱身術 */ + send_to_room(room, chatbuf, 0, MSG_MESSAGE); + + sprintf(chatbuf, "- %s", user->userid); + send_to_room(room, chatbuf, 0, MSG_USERNOTIFY); + room_changed(room); + + return; + } + + else if (room != &mainroom) + { /* Thor: 人數為0時,不是mainroom才free */ + register ChatRoom *next; + +#ifdef DEBUG + debug_room(); +#endif + + sprintf(chatbuf, "- %s", room->name); + send_to_room(ROOM_ALL, chatbuf, 0, MSG_ROOMNOTIFY); + + room->prev->next = room->next; + if((next = room->next)) + next->prev = room->prev; + list_free(room->invite); + + MYDOG; + free(room); + MYDOG; + +#ifdef DEBUG + debug_room(); +#endif + } + } +} + + +/* ----------------------------------------------------- */ +/* chat commands */ +/* ----------------------------------------------------- */ + +/* ----------------------------------------------------- */ +/* (.ACCT) 使用者帳號 (account) subroutines */ +/* ----------------------------------------------------- */ + +static char datemsg[32]; + +char * +Ctime(clock) + time_t *clock; +{ + struct tm *t = localtime(clock); + static char week[] = "日一二三四五六"; + + sprintf(datemsg, "%d年%2d月%2d日%3d:%02d:%02d 星期%.2s", + t->tm_year - 11, t->tm_mon + 1, t->tm_mday, + t->tm_hour, t->tm_min, t->tm_sec, &week[t->tm_wday << 1]); + return (datemsg); +} + +static void +chat_query(cu, msg) + ChatUser *cu; + char *msg; +{ + char str[256]; + int i; + ACCT xuser; + FILE *fp; + + if (acct_load(&xuser, msg) >= 0) + { + sprintf(chatbuf, "%s(%s) 共上站 %d 次,文章 %d 篇", + xuser.userid, xuser.username, xuser.numlogins, xuser.numposts); + send_to_user(cu, chatbuf, 0, MSG_MESSAGE); + + sprintf(chatbuf, "最近(%s)從(%s)上站", Ctime(&xuser.lastlogin), + (xuser.lasthost[0] ? xuser.lasthost : "外太空")); + send_to_user(cu, chatbuf, 0, MSG_MESSAGE); + + usr_fpath(chatbuf, xuser.userid, "plans"); + fp = fopen(chatbuf, "rt"); + i = 0; + while (fp && fgets(str, 256, fp)) + { + if (!strlen(str)) + continue; + + str[strlen(str) - 1] = 0; + send_to_user(cu, str, 0, MSG_MESSAGE); + if (++i >= MAX_QUERYLINES) + break; + } + fclose(fp); + } + else + { + sprintf(chatbuf, msg_no_such_id, msg); + send_to_user(cu, chatbuf, 0, MSG_MESSAGE); + } +} + +static void +chat_clear(cu, msg) + ChatUser *cu; + char *msg; +{ + if (cu->clitype) + send_to_user(cu, "", 0, MSG_CLRSCR); + else + send_to_user(cu, "/c", 0, MSG_MESSAGE); +} + +static void +chat_date(cu, msg) + ChatUser *cu; + char *msg; +{ + time_t thetime; + + time(&thetime); + sprintf(chatbuf, "◆ 標準時間: %s", Ctime(&thetime)); + send_to_user(cu, chatbuf, 0, MSG_MESSAGE); +} + + +static void +chat_topic(cu, msg) + ChatUser *cu; + char *msg; +{ + ChatRoom *room; + char *topic; + + if (!ROOMOP(cu) && !OPENTOPIC(cu->room)) + { + send_to_user(cu, msg_not_op, 0, MSG_MESSAGE); + return; + } + + if (*msg == '\0') + { + send_to_user(cu, "※ 請指定話題", 0, MSG_MESSAGE); + return; + } + + room = cu->room; + topic = room->topic; /* Thor: room 有可能 NULL嗎?? */ + strncpy(topic, msg, 47); + topic[47] = '\0'; + + if (cu->clitype) + send_to_room(room, topic, 0, MSG_TOPIC); + else + { + sprintf(chatbuf, "/t%s", topic); + send_to_room(room, chatbuf, 0, 0); + } + + room_changed(room); + + sprintf(chatbuf, "◆ %s 將話題改為 %s", cu->chatid, topic); + if (!CLOAK(cu)) /* Thor: 聊天室隱身術 */ + send_to_room(room, chatbuf, 0, MSG_MESSAGE); +} + + +static void +chat_version(cu, msg) + ChatUser *cu; + char *msg; +{ + sprintf(chatbuf, "%d %d", XCHAT_VERSION_MAJOR, XCHAT_VERSION_MINOR); + send_to_user(cu, chatbuf, 0, MSG_VERSION); +} + +static void +chat_nick(cu, msg) + ChatUser *cu; + char *msg; +{ + char *chatid, *str; + ChatUser *xuser; + + chatid = nextword(&msg); + chatid[8] = '\0'; + if (!valid_chatid(chatid)) + { + send_to_user(cu, "※ 這個聊天代號是不正確的", 0, MSG_MESSAGE); + return; + } + + xuser = cuser_by_chatid(chatid); + if (xuser != NULL && xuser != cu) + { + send_to_user(cu, "※ 已經有人捷足先登囉", 0, MSG_MESSAGE); + return; + } + + str = cu->chatid; + + sprintf(chatbuf, "※ %s 將聊天代號改為 %s", str, chatid); + if (!CLOAK(cu)) /* Thor: 聊天室隱身術 */ + send_to_room(cu->room, chatbuf, cu->userno, MSG_MESSAGE); + + strcpy(str, chatid); + + user_changed(cu); + + if (cu->clitype) + send_to_user(cu, chatid, 0, MSG_NICK); + else + { + sprintf(chatbuf, "/n%s", chatid); + send_to_user(cu, chatbuf, 0, 0); + } +} + +static void +chat_list_rooms(cuser, msg) + ChatUser *cuser; + char *msg; +{ + ChatRoom *cr, *room; + + if (RESTRICTED(cuser)) + { + send_to_user(cuser, "※ 您沒有權限列出現有的聊天室", 0, MSG_MESSAGE); + return; + } + + if (common_client_command) + send_to_user(cuser, "", 0, MSG_ROOMLISTSTART); + else + send_to_user(cuser, " 談天室名稱 │人數│話題 ", 0, MSG_MESSAGE); + + room = cuser->room; + cr = &mainroom; + do + { + MYDOG; + + + if (!SECRET(cr) || CHATSYSOP(cuser) || (cr == room && ROOMOP(cuser))) + { + if (common_client_command) + { + sprintf(chatbuf, "%s %d %d %s", cr->name, cr->occupants, cr->rflag, cr->topic); + send_to_user(cuser, chatbuf, 0, MSG_ROOMLIST); + } + else + { + sprintf(chatbuf, " %-12s│%4d│%s", cr->name, cr->occupants, cr->topic); + if (LOCKED(cr)) + strcat(chatbuf, " [鎖住]"); + if (SECRET(cr)) + strcat(chatbuf, " [秘密]"); + if (OPENTOPIC(cr)) + strcat(chatbuf, " [話題]"); + send_to_user(cuser, chatbuf, 0, MSG_MESSAGE); + } + + } + } while((cr = cr->next)); + + if (common_client_command) + send_to_user(cuser, "", 0, MSG_ROOMLISTEND); +} + + +static void +chat_do_user_list(cu, msg, theroom) + ChatUser *cu; + char *msg; + ChatRoom *theroom; +{ + ChatRoom *myroom, *room; + ChatUser *user; + + int start, stop, curr = 0; + start = atoi(nextword(&msg)); + stop = atoi(nextword(&msg)); + + myroom = cu->room; + +#ifdef DEBUG + logit(cu->chatid, "do user list"); +#endif + + if (common_client_command) + send_to_user(cu, "", 0, MSG_USERLISTSTART); + else + send_to_user(cu, " 聊天代號│使用者代號 │聊天室 ", 0, MSG_MESSAGE); + + for (user = mainuser; user; user = user->unext) + { + MYDOG; + + + room = user->room; + if ((theroom != ROOM_ALL) && (theroom != room)) + continue; + + if (myroom != room) + { + if (RESTRICTED(cu) || + (room && SECRET(room) && !CHATSYSOP(cu))) + continue; + } + + if (CLOAK(user)) /* Thor: 隱身術 */ + continue; + + + curr++; + if (start && curr < start) + continue; + else if (stop && (curr > stop)) + break; + + if (common_client_command) + { + if (!room) + continue; /* Xshadow: 還沒進入任何房間的就不列出 */ + + sprintf(chatbuf, "%s %s %s %s", user->chatid, user->userid, room->name, user->lasthost); + if (ROOMOP(user)) + strcat(chatbuf, " Op"); + } + else + { + sprintf(chatbuf, " %-8s│%-12s│%s", user->chatid, user->userid, room ? room->name : "[在門口徘徊]"); + if (ROOMOP(user)) + strcat(chatbuf, " [Op]"); + } + +#ifdef DEBUG + logit("list_U", chatbuf); +#endif + + send_to_user(cu, chatbuf, 0, common_client_command ? MSG_USERLIST : MSG_MESSAGE); + } + if (common_client_command) + send_to_user(cu, "", 0, MSG_USERLISTEND); +} + +static void +chat_list_by_room(cu, msg) + ChatUser *cu; + char *msg; +{ + ChatRoom *whichroom; + char *roomstr; + + roomstr = nextword(&msg); + if (*roomstr == '\0') + whichroom = cu->room; + else + { + if ((whichroom = croom_by_roomid(roomstr)) == NULL) + { + sprintf(chatbuf, "※ 沒有 [%s] 這個聊天室", roomstr); + send_to_user(cu, chatbuf, 0, MSG_MESSAGE); + return; + } + + if (whichroom != cu->room && SECRET(whichroom) && !CHATSYSOP(cu)) + { /* Thor: 要不要測同一room雖SECRET但可以列? + * Xshadow: 我改成同一 room 就可以列 */ + send_to_user(cu, "※ 無法列出在秘密聊天室的使用者", 0, MSG_MESSAGE); + return; + } + } + chat_do_user_list(cu, msg, whichroom); +} + + +static void +chat_list_users(cu, msg) + ChatUser *cu; + char *msg; +{ + chat_do_user_list(cu, msg, ROOM_ALL); +} + +static void +chat_chatroom(cu, msg) + ChatUser *cu; + char *msg; +{ + if (common_client_command) + send_to_user(cu, "批踢踢茶藝館 4 21", 0, MSG_CHATROOM); +} + +static void +chat_map_chatids(cu, whichroom) + ChatUser *cu; /* Thor: 還沒有作不同間的 */ + ChatRoom *whichroom; +{ + int c; + ChatRoom *myroom, *room; + ChatUser *user; + + /* myroom = cu->room; */ + myroom = whichroom; + send_to_user(cu, + " 聊天代號 使用者代號 │ 聊天代號 使用者代號 │ 聊天代號 使用者代號 ", 0, MSG_MESSAGE); + + c = 0; + + for (user = mainuser; user; user = user->unext) + { + MYDOG; + + room = user->room; + MYDOG; + if (whichroom != ROOM_ALL && whichroom != room) + continue; + MYDOG; + if (myroom != room) + { + if (RESTRICTED(cu) || /* Thor: 要先check room 是不是空的 */ + (room && SECRET(room) && !CHATSYSOP(cu))) + continue; + } + MYDOG; + if (CLOAK(user)) /* Thor:隱身術 */ + continue; + sprintf(chatbuf + (c * 24), " %-8s%c%-12s%s", + user->chatid, ROOMOP(user) ? '*' : ' ', + user->userid, (c < 2 ? "│" : " ")); + MYDOG; + if (++c == 3) + { + send_to_user(cu, chatbuf, 0, MSG_MESSAGE); + c = 0; + } + MYDOG; + } + if (c > 0) + send_to_user(cu, chatbuf, 0, MSG_MESSAGE); +} + + +static void +chat_map_chatids_thisroom(cu, msg) + ChatUser *cu; + char *msg; +{ + chat_map_chatids(cu, cu->room); +} + + +static void +chat_setroom(cu, msg) + ChatUser *cu; + char *msg; +{ + char *modestr; + ChatRoom *room; + char *chatid; + int sign; + int flag; + char *fstr = NULL; + + if (!ROOMOP(cu)) + { + send_to_user(cu, msg_not_op, 0, MSG_MESSAGE); + return; + } + + modestr = nextword(&msg); + sign = 1; + if (*modestr == '+') + modestr++; + else if (*modestr == '-') + { + modestr++; + sign = 0; + } + if (*modestr == '\0') + { + send_to_user(cu, + "※ 請指定狀態: {[+(設定)][-(取消)]}{[l(鎖住)][s(秘密)][t(開放話題)}", 0, MSG_MESSAGE); + return; + } + + room = cu->room; + chatid = cu->chatid; + + while (*modestr) + { + flag = 0; + switch (*modestr) + { + case 'l': + case 'L': + flag = ROOM_LOCKED; + fstr = "鎖住"; + break; + + case 's': + case 'S': + flag = ROOM_SECRET; + fstr = "秘密"; + break; + + case 't': + case 'T': + flag = ROOM_OPENTOPIC; + fstr = "開放話題"; + break; + case 'h': + case 'H': + flag = ROOM_OPENTOPIC; + fstr = "舉手發言"; + break; + + default: + sprintf(chatbuf, "※ 狀態錯誤:[%c]", *modestr); + send_to_user(cu, chatbuf, 0, MSG_MESSAGE); + } + + /* Thor: check room 是不是空的, 應該不是空的 */ + if (flag && (room->rflag & flag) != sign * flag) + { + room->rflag ^= flag; + sprintf(chatbuf, "※ 本聊天室被 %s %s [%s] 狀態", + chatid, sign ? "設定為" : "取消", fstr); + if (!CLOAK(cu)) /* Thor: 聊天室隱身術 */ + send_to_room(room, chatbuf, 0, MSG_MESSAGE); + } + modestr++; + } + room_changed(room); +} + +static char *chat_msg[] = +{ + "[//]help", "MUD-like 社交動詞", + "[/h]elp op", "談天室管理員專用指令", + "[/a]ct <msg>", "做一個動作", + "[/b]ye [msg]", "道別", + "[/c]lear [/d]ate", "清除螢幕 目前時間", + /* "[/d]ate", "目前時間", *//* Thor: 指令太多 */ + +#if 0 + "[/f]ire <user> <msg>", "發送熱訊", /* Thor.0727: 和 flag 衝key */ +#endif + + "[/i]gnore [user]", "忽略使用者", + "[/j]oin <room>", "建立或加入談天室", + "[/l]ist [start [stop]]", "列出談天室使用者", + "[/m]sg <id|user> <msg>", "跟 <id> 說悄悄話", + "[/n]ick <id>", "將談天代號換成 <id>", + "[/p]ager", "切換呼叫器", + "[/q]uery <user>", "查詢網友", + "[/r]oom", "列出一般談天室", + "[/t]ape", "開關錄音機", + "[/u]nignore <user>", "取消忽略", + +#if 0 + "[/u]sers", "列出站上使用者", +#endif + + "[/w]ho", "列出本談天室使用者", + "[/w]hoin <room>", "列出談天室<room> 的使用者", + NULL +}; + + +static char *room_msg[] = +{ + "[/f]lag [+-][lsth]", "設定鎖定、秘密、開放話題、舉手發言", + "[/i]nvite <id>", "邀請 <id> 加入談天室", + "[/kick] <id>", "將 <id> 踢出談天室", + "[/o]p <id>", "將 Op 的權力轉移給 <id>", + "[/topic] <text>", "換個話題", + "[/w]all", "廣播 (站長專用)", + NULL +}; + + +static void +chat_help(cu, msg) + ChatUser *cu; + char *msg; +{ + char **table, *str; + + if (str_equal(nextword(&msg), "op")) + { + send_to_user(cu, "談天室管理員專用指令", 0, MSG_MESSAGE); + table = room_msg; + } + else + { + table = chat_msg; + } + + while((str = *table++)) { + sprintf(chatbuf, " %-20s- %s", str, *table++); + send_to_user(cu, chatbuf, 0, MSG_MESSAGE); + } +} + + +static void +chat_private(cu, msg) + ChatUser *cu; + char *msg; +{ + char *recipient; + ChatUser *xuser; + int userno; + + userno = 0; + recipient = nextword(&msg); + xuser = (ChatUser *) fuzzy_cuser_by_chatid(recipient); + if (xuser == NULL) + { /* Thor.0724: 用 userid也可傳悄悄話 */ + xuser = cuser_by_userid(recipient); + } + if (xuser == NULL) + { + sprintf(chatbuf, msg_no_such_id, recipient); + } + else if (xuser == FUZZY_USER) + { /* ambiguous */ + strcpy(chatbuf, "※ 請指明聊天代號"); + } + else if (*msg) + { + userno = cu->userno; + sprintf(chatbuf, "*%s* ", cu->chatid); + msg[79] = 0; /* Thor:防止太長 */ + strncat(chatbuf, msg, 80); + send_to_user(xuser, chatbuf, userno, MSG_MESSAGE); + + if (xuser->clitype) + { /* Xshadow: 如果對方是用 client 上來的 */ + sprintf(chatbuf, "%s %s ", cu->userid, cu->chatid); + msg[79] = 0; + strncat(chatbuf, msg, 80); + send_to_user(xuser, chatbuf, userno, MSG_PRIVMSG); + } + if (cu->clitype) + { + sprintf(chatbuf, "%s %s ", xuser->userid, xuser->chatid); + msg[79] = 0; + strncat(chatbuf, msg, 80); + send_to_user(cu, chatbuf, 0, MSG_MYPRIVMSG); + } + + sprintf(chatbuf, "%s> ", xuser->chatid); + strncat(chatbuf, msg, 80); + } + else + { + sprintf(chatbuf, "※ 您想對 %s 說什麼話呢?", xuser->chatid); + } + send_to_user(cu, chatbuf, userno, MSG_MESSAGE); /* Thor: userno 要改成 0 + * 嗎? */ +} + + +static void +chat_cloak(cu, msg) + ChatUser *cu; + char *msg; +{ + if (CHATSYSOP(cu)) + { + cu->uflag ^= PERM_CLOAK; + sprintf(chatbuf, "◆ %s", CLOAK(cu) ? MSG_CLOAKED : MSG_UNCLOAK); + send_to_user(cu, chatbuf, 0, MSG_MESSAGE); + } +} + + + +/* ----------------------------------------------------- */ + + +static void +arrive_room(cuser, room) + ChatUser *cuser; + ChatRoom *room; +{ + char *rname; + + /* Xshadow: 不必送給自己, 反正換房間就會重新 build user list */ + sprintf(chatbuf, "+ %s %s %s %s", cuser->userid, cuser->chatid, room->name, cuser->lasthost); + if (ROOMOP(cuser)) + strcat(chatbuf, " Op"); + send_to_room(room, chatbuf, 0, MSG_USERNOTIFY); + + cuser->room = room; + room->occupants++; + rname = room->name; + + room_changed(room); + + if (cuser->clitype) + { + send_to_user(cuser, rname, 0, MSG_ROOM); + send_to_user(cuser, room->topic, 0, MSG_TOPIC); + } + else + { + sprintf(chatbuf, "/r%s", rname); + send_to_user(cuser, chatbuf, 0, 0); + sprintf(chatbuf, "/t%s", room->topic); + send_to_user(cuser, chatbuf, 0, 0); + } + + sprintf(chatbuf, "※ %s 進入 [%s] 包廂", + cuser->chatid, rname); + if (!CLOAK(cuser)) /* Thor: 聊天室隱身術 */ + send_to_room(room, chatbuf, cuser->userno, MSG_MESSAGE); +} + + +static int +enter_room(cuser, rname, msg) + ChatUser *cuser; + char *rname; + char *msg; +{ + ChatRoom *room; + int create; + + create = 0; + room = croom_by_roomid(rname); + if (room == NULL) + { + /* new room */ + +#ifdef MONITOR + logit(cuser->userid, "create new room"); +#endif + + MYDOG; + + room = (ChatRoom *) malloc(sizeof(ChatRoom)); + MYDOG; + if (room == NULL) + { + send_to_user(cuser, "※ 無法再新闢包廂了", 0, MSG_MESSAGE); + return 0; + } + + memset(room, 0, sizeof(ChatRoom)); + memcpy(room->name, rname, IDLEN - 1); + strcpy(room->topic, "這是一個新天地"); + + sprintf(chatbuf, "+ %s 1 0 %s", room->name, room->topic); + send_to_room(ROOM_ALL, chatbuf, 0, MSG_ROOMNOTIFY); + + if (mainroom.next != NULL) + mainroom.next->prev = room; + room->next = mainroom.next; + mainroom.next = room; + room->prev = &mainroom; + + create = 1; + } + else + { + if (cuser->room == room) + { + sprintf(chatbuf, "※ 您本來就在 [%s] 聊天室囉 :)", rname); + send_to_user(cuser, chatbuf, 0, MSG_MESSAGE); + return 0; + } + + if (!CHATSYSOP(cuser) && LOCKED(room) && !list_belong(room->invite, cuser->userno)) + { + send_to_user(cuser, "※ 內有惡犬,非請莫入", 0, MSG_MESSAGE); + return 0; + } + } + + exit_room(cuser, EXIT_LOGOUT, msg); + arrive_room(cuser, room); + + if (create) + cuser->uflag |= PERM_ROOMOP; + + return 0; +} + + +static void +logout_user(cuser) + ChatUser *cuser; +{ + int sock; + ChatUser *xuser, *prev; + +#ifdef DEBUG + logit("before", "logout"); + debug_user(); +#endif + + sock = cuser->sock; + shutdown(sock, 2); + close(sock); + + MYDOG; + + FD_CLR(sock, &mainfds); + +#if 0 /* Thor: 也許不差這一個 */ + if (sock >= maxfds) + maxfds = sock - 1; +#endif + + list_free(cuser->ignore); + +#ifdef DEBUG + debug_user(); +#endif + + xuser = mainuser; + if (xuser == cuser) + { + mainuser = cuser->unext; + } + else + { + do + { + prev = xuser; + xuser = xuser->unext; + if (xuser == cuser) + { + prev->unext = cuser->unext; + break; + } + } while (xuser); + } + + MYDOG; + +#ifdef DEBUG + sprintf(chatbuf, "%p", cuser); + logit("free cuser", chatbuf); +#endif + + free(cuser); + +#ifdef DEBUG + logit("after", "logout"); + debug_user(); +#endif + +#if 0 + next = cuser->next; + prev = cuser->prev; + prev->next = next; + if (next) + next->prev = prev; + + if (cuser) + free(cuser); + MYDOG; + +#endif + + totaluser--; +} + + +static void +print_user_counts(cuser) + ChatUser *cuser; +{ + ChatRoom *room; + int num, userc, suserc, roomc, number; + + userc = suserc = roomc = 0; + + room = &mainroom; + do + { + MYDOG; + + num = room->occupants; + if (SECRET(room)) + { + suserc += num; + if (CHATSYSOP(cuser)) + roomc++; + } + else + { + userc += num; + roomc++; + } + } while((room = room->next)); + + number = (cuser->clitype) ? MSG_MOTD : MSG_MESSAGE; + + sprintf(chatbuf, + "☉ 歡迎光臨【批踢踢茶藝館】,目前開了 %d 間包廂", roomc); + send_to_user(cuser, chatbuf, 0, number); + + sprintf(chatbuf, "☉ 共有 %d 人來擺\龍門陣", userc); + if (suserc) + sprintf(chatbuf + strlen(chatbuf), " [%d 人在秘密聊天室]", suserc); + send_to_user(cuser, chatbuf, 0, number); +} + + +static int +login_user(cu, msg) + ChatUser *cu; + char *msg; +{ + int utent; + + char *level; + char *userid; + char *chatid; + struct sockaddr_in from; + int fromlen; + struct hostent *hp; + + + ACCT acct; + char buf[20]; + + /* + * Thor.0819: SECURED_CHATROOM : /! userid chatid passwd , userno + * el 在check完passwd後取得 + */ + /* Xshadow.0915: common client support : /-! userid chatid password */ + + /* 傳參數:userlevel, userid, chatid */ + + /* client/server 版本依據 userid 抓 .PASSWDS 判斷 userlevel */ + + userid = nextword(&msg); + chatid = nextword(&msg); + + +#ifdef DEBUG + logit("ENTER", userid); +#endif + /* Thor.0730: parse space before passwd */ + level = msg; + + /* Thor.0813: 跳過一空格即可, 因為反正如果chatid有空格, 密碼也不對 */ + /* 就算密碼對, 也不會怎麼樣:p */ + /* 可是如果密碼第一個字是空格, 那跳太多空格會進不來... */ + if (*level == ' ') + level++; + + /* Thor.0729: load acct */ + if (!*userid || (acct_load(&acct, userid) < 0)) + { + +#ifdef DEBUG + logit("noexist", chatid); +#endif + + if (cu->clitype) + send_to_user(cu, "錯誤的使用者代號", 0, ERR_LOGIN_NOSUCHUSER); + else + send_to_user(cu, CHAT_LOGIN_INVALID, 0, 0); + + return -1; + } + else if(strncmp(level, acct.passwd, PASSLEN) && + !chkpasswd(acct.passwd, level)) + { + +#ifdef DEBUG + logit("fake", chatid); +#endif + + if (cu->clitype) + send_to_user(cu, "密碼錯誤", 0, ERR_LOGIN_PASSERROR); + else + send_to_user(cu, CHAT_LOGIN_INVALID, 0, 0); + return -1; + } + else + { + /* Thor.0729: if ok, read level. */ + sprintf(buf, "%d", acct.userlevel); + level = buf; + /* Thor.0819: read userno for client/server bbs */ + utent = searchuser(acct.userid); + } + + /* Thor.0819: for client/server bbs */ +/* + for (xuser = mainuser; xuser; xuser = xuser->unext) + { + MYDOG; + + if (xuser->userno == utent) + { + + #ifdef DEBUG + logit("enter", "bogus"); + #endif + if (cu->clitype) + send_to_user(cu, "請勿派遣分身進入聊天室 !!", 0, ERR_LOGIN_USERONLINE); + else + send_to_user(cu, CHAT_LOGIN_BOGUS, 0, 0); + return -1; + } + } +*/ + if (!valid_chatid(chatid)) + { + +#ifdef DEBUG + logit("enter", chatid); +#endif + + if (cu->clitype) + send_to_user(cu, "不合法的聊天室代號 !!", 0, ERR_LOGIN_NICKERROR); + else + send_to_user(cu, CHAT_LOGIN_INVALID, 0, 0); + return 0; + } + +#ifdef DEBUG + debug_user(); +#endif + + if (cuser_by_chatid(chatid) != NULL) + { + /* chatid in use */ + +#ifdef DEBUG + logit("enter", "duplicate"); +#endif + + if (cu->clitype) + send_to_user(cu, "這個代號已經有人使用", 0, ERR_LOGIN_NICKINUSE); + else + send_to_user(cu, CHAT_LOGIN_EXISTS, 0, 0); + return 0; + } + + cu->userno = utent; + cu->uflag = atoi(level) & ~(PERM_ROOMOP | PERM_CLOAK | PERM_HANDUP | PERM_SAY); + /* Thor: 進來先清空ROOMOP(同PERM_CHAT), CLOAK */ + strcpy(cu->userid, userid); + memcpy(cu->chatid, chatid, 8); + cu->chatid[8] = '\0'; + + /* Xshadow: 取得 client 的來源 */ + fromlen = sizeof(from); + if (!getpeername(cu->sock, (struct sockaddr *) & from, &fromlen)) + { + if ((hp = gethostbyaddr((char *) &from.sin_addr, sizeof(struct in_addr), from.sin_family))) + { + strcpy(cu->lasthost, hp->h_name); + } + else + strcpy(cu->lasthost, (char *) inet_ntoa(from.sin_addr)); + + } + else + { + strcpy(cu->lasthost, "[外太空]"); + } + + if (cu->clitype) + send_to_user(cu, "順利", 0, MSG_LOGINOK); + else + send_to_user(cu, CHAT_LOGIN_OK, 0, 0); + + arrive_room(cu, &mainroom); + + send_to_user(cu, "", 0, MSG_MOTDSTART); + print_user_counts(cu); + send_to_user(cu, "", 0, MSG_MOTDEND); + +#ifdef DEBUG + logit("enter", "OK"); +#endif + + return 0; +} + + +static void +chat_act(cu, msg) + ChatUser *cu; + char *msg; +{ + if (*msg && (!RHANDUP(cu->room) || SAY(cu) || ROOMOP(cu))) + { + sprintf(chatbuf, "%s %s", cu->chatid, msg); + send_to_room(cu->room, chatbuf, cu->userno, MSG_MESSAGE); + } +} + + +static void +chat_ignore(cu, msg) + ChatUser *cu; + char *msg; +{ + + if (RESTRICTED(cu)) + { + strcpy(chatbuf, "※ 您沒有 ignore 別人的權利"); + } + else + { + char *ignoree; + + ignoree = nextword(&msg); + if (*ignoree) + { + ChatUser *xuser; + + xuser = cuser_by_userid(ignoree); + + if (xuser == NULL) + { + + sprintf(chatbuf, msg_no_such_id, ignoree); + +#if 0 + sprintf(chatbuf, "◆ 談天室現在沒有 [%s] 這號人物", ignoree); +#endif + } + else if (xuser == cu || CHATSYSOP(xuser) || + (ROOMOP(xuser) && (xuser->room == cu->room))) + { + sprintf(chatbuf, "◆ 不可以 ignore [%s]", ignoree); + } + else + { + + if (list_belong(cu->ignore, xuser->userno)) + { + sprintf(chatbuf, "※ %s 已經被凍結了", xuser->chatid); + } + else + { + list_add(&(cu->ignore), xuser); + sprintf(chatbuf, "◆ 將 [%s] 打入冷宮了 :p", xuser->chatid); + } + } + } + else + { + UserList *list; + + if((list = cu->ignore)) + { + int len; + char buf[16]; + + send_to_user(cu, "◆ 這些人被打入冷宮了:", 0, MSG_MESSAGE); + len = 0; + do + { + sprintf(buf, "%-13s", list->userid); + strcpy(chatbuf + len, buf); + len += 13; + if (len >= 78) + { + send_to_user(cu, chatbuf, 0, MSG_MESSAGE); + len = 0; + } + } while((list = list->next)); + + if (len == 0) + return; + } + else + { + strcpy(chatbuf, "◆ 您目前並沒有 ignore 任何人"); + } + } + } + + send_to_user(cu, chatbuf, 0, MSG_MESSAGE); +} + + +static void +chat_unignore(cu, msg) + ChatUser *cu; + char *msg; +{ + char *ignoree; + + ignoree = nextword(&msg); + + if (*ignoree) + { + sprintf(chatbuf, (list_delete(&(cu->ignore), ignoree)) ? + "◆ [%s] 不再被你冷落了" : + "◆ 您並未 ignore [%s] 這號人物", ignoree); + } + else + { + strcpy(chatbuf, "◆ 請指明 user ID"); + } + send_to_user(cu, chatbuf, 0, MSG_MESSAGE); +} + + +static void +chat_join(cu, msg) + ChatUser *cu; + char *msg; +{ + if (RESTRICTED(cu)) + { + send_to_user(cu, "※ 您沒有加入其他聊天室的權限", 0, MSG_MESSAGE); + } + else + { + char *roomid = nextword(&msg); + + if (*roomid) + enter_room(cu, roomid, msg); + else + send_to_user(cu, "※ 請指定聊天室的名字", 0, MSG_MESSAGE); + } +} + + +static void +chat_kick(cu, msg) + ChatUser *cu; + char *msg; +{ + char *twit; + ChatUser *xuser; + ChatRoom *room; + + if (!ROOMOP(cu)) + { + send_to_user(cu, msg_not_op, 0, MSG_MESSAGE); + return; + } + + twit = nextword(&msg); + xuser = cuser_by_chatid(twit); + + if (xuser == NULL) + { + sprintf(chatbuf, msg_no_such_id, twit); + send_to_user(cu, chatbuf, 0, MSG_MESSAGE); + return; + } + + room = cu->room; + if (room != xuser->room || CLOAK(xuser)) + { /* Thor: 聊天室隱身術 */ + sprintf(chatbuf, msg_not_here, twit); + send_to_user(cu, chatbuf, 0, MSG_MESSAGE); + return; + } + + if (CHATSYSOP(xuser)) + { /* Thor: 踢不走 CHATSYSOP */ + sprintf(chatbuf, "◆ 不可以 kick [%s]", twit); + send_to_user(cu, chatbuf, 0, MSG_MESSAGE); + return; + } + + exit_room(xuser, EXIT_KICK, (char *) NULL); + + if (room == &mainroom) + logout_user(xuser); + else + enter_room(xuser, MAIN_NAME, (char *) NULL); +} + + +static void +chat_makeop(cu, msg) + ChatUser *cu; + char *msg; +{ + char *newop; + ChatUser *xuser; + ChatRoom *room; + + if (!ROOMOP(cu)) + { + send_to_user(cu, msg_not_op, 0, MSG_MESSAGE); + return; + } + + newop = nextword(&msg); + xuser = cuser_by_chatid(newop); + + if (xuser == NULL) + { + sprintf(chatbuf, msg_no_such_id, newop); + send_to_user(cu, chatbuf, 0, MSG_MESSAGE); + return; + } + + if (cu == xuser) + { + sprintf(chatbuf, "※ 您早就已經是 Op 了啊"); + send_to_user(cu, chatbuf, 0, MSG_MESSAGE); + return; + } + + room = cu->room; + + if (room != xuser->room || CLOAK(xuser)) + { /* Thor: 聊天室隱身術 */ + sprintf(chatbuf, msg_not_here, xuser->chatid); + send_to_user(cu, chatbuf, 0, MSG_MESSAGE); + return; + } + + cu->uflag &= ~PERM_ROOMOP; + xuser->uflag |= PERM_ROOMOP; + + user_changed(cu); + user_changed(xuser); + + sprintf(chatbuf, "※ %s 將 Op 權力轉移給 %s", + cu->chatid, xuser->chatid); + if (!CLOAK(cu)) /* Thor: 聊天室隱身術 */ + send_to_room(room, chatbuf, 0, MSG_MESSAGE, MSG_MESSAGE); +} + + + +static void +chat_invite(cu, msg) + ChatUser *cu; + char *msg; +{ + char *invitee; + ChatUser *xuser; + ChatRoom *room; + UserList **list; + + if (!ROOMOP(cu)) + { + send_to_user(cu, msg_not_op, 0, MSG_MESSAGE); + return; + } + + invitee = nextword(&msg); + xuser = cuser_by_chatid(invitee); + if (xuser == NULL) + { + sprintf(chatbuf, msg_no_such_id, invitee); + send_to_user(cu, chatbuf, 0, MSG_MESSAGE); + return; + } + + room = cu->room; /* Thor: 是否要 check room 是否 NULL ? */ + list = &(room->invite); + + if (list_belong(*list, xuser->userno)) + { + sprintf(chatbuf, "※ %s 已經接受過邀請了", xuser->chatid); + send_to_user(cu, chatbuf, 0, MSG_MESSAGE); + return; + } + list_add(list, xuser); + + sprintf(chatbuf, "※ %s 邀請您到 [%s] 聊天室", + cu->chatid, room->name); + send_to_user(xuser, chatbuf, 0, MSG_MESSAGE); /* Thor: 要不要可以 ignore? */ + sprintf(chatbuf, "※ %s 收到您的邀請了", xuser->chatid); + send_to_user(cu, chatbuf, 0, MSG_MESSAGE); +} + + +static void +chat_broadcast(cu, msg) + ChatUser *cu; + char *msg; +{ + if (!CHATSYSOP(cu)) + { + send_to_user(cu, "※ 您沒有在聊天室廣播的權力!", 0, MSG_MESSAGE); + return; + } + if (*msg == '\0') + { + send_to_user(cu, "※ 請指定廣播內容", 0, MSG_MESSAGE); + return; + } + sprintf(chatbuf, "※ " BBSNAME "談天室廣播中 [%s].....", + cu->chatid); + send_to_room(ROOM_ALL, chatbuf, 0, MSG_MESSAGE); + sprintf(chatbuf, "◆ %s", msg); + send_to_room(ROOM_ALL, chatbuf, 0, MSG_MESSAGE); +} + + +static void +chat_goodbye(cu, msg) + ChatUser *cu; + char *msg; +{ + exit_room(cu, EXIT_LOGOUT, msg); + /* Thor: 要不要加 logout_user(cu) ? */ +} + + +/* --------------------------------------------- */ +/* MUD-like social commands : action */ +/* --------------------------------------------- */ + +struct ChatAction +{ + char *verb; /* 動詞 */ + char *chinese; /* 中文翻譯 */ + char *part1_msg; /* 介詞 */ + char *part2_msg; /* 動作 */ +}; + + +static ChatAction party_data[] = +{ + {"aluba", "阿魯巴", "把", "架上柱子阿魯巴!!"}, + {"aodre", "景仰", "對", "的景仰有如滔滔江水,連綿不絕……"}, + {"bearhug", "熱擁", "熱情的擁抱", ""}, + {"blade", "一刀", "一刀啟程把", "送上西天"}, + {"bless", "祝福", "祝福", "心想事成"}, + {"board", "主機板", "把", "抓去跪主機板"}, + {"bokan", "氣功\", "雙掌微合,蓄勢待發……突然間,電光乍現,對", "使出了Bo--Kan!"}, + {"bow", "鞠躬", "畢躬畢敬的向", "鞠躬"}, + {"box", "幕之內", "開始輪擺\式移位,對", "作肝臟攻擊"}, + {"boy", "平底鍋", "從背後拿出了平底鍋,把", "敲昏了"}, + {"bye", "掰掰", "向", "說掰掰!!"}, + {"call", "呼喚", "大聲的呼喚,啊~~", "啊~~~你在哪裡啊啊啊啊~~~~"}, + {"caress", "輕撫", "輕輕的撫摸著", ""}, + {"clap", "鼓掌", "向", "熱烈鼓掌"}, + {"claw", "抓抓", "從貓咪樂園借了隻貓爪,把", "抓得死去活來"}, + {"comfort", "安慰", "溫言安慰", ""}, + {"cong", "恭喜", "從背後拿出了拉炮,呯!呯!恭喜", ""}, + {"cpr", "口對口", "對著", "做口對口人工呼吸"}, + {"cringe", "乞憐", "向", "卑躬屈膝,搖尾乞憐"}, + {"cry", "大哭", "向", "嚎啕大哭"}, + {"dance", "跳舞", "拉了", "的手翩翩起舞" }, + {"destroy", "毀滅", "祭起了『極大毀滅咒文』,轟向", ""}, + {"dogleg", "狗腿", "對", "狗腿"}, + {"drivel", "流口水", "對著", "流口水"}, + {"envy", "羨慕", "向", "流露出羨慕的眼光"}, + {"eye", "送秋波", "對", "頻送秋波"}, + {"fire", "銬問", "拿著火紅的鐵棒走向", ""}, + {"forgive", "原諒", "接受道歉,原諒了", ""}, + {"french", "法式吻", "把舌頭伸到", "喉嚨裡∼∼∼哇!一個浪漫的法國氏深吻"}, + {"giggle", "傻笑", "對著", "傻傻的呆笑"}, + {"glue", "補心", "用三秒膠,把", "的心黏了起來"}, + {"goodbye", "告別", "淚\眼汪汪的向", "告別"}, + {"grin", "奸笑", "對", "露出邪惡的笑容"}, + {"growl", "咆哮", "對", "咆哮不已"}, + {"hand", "握手", "跟", "握手"}, + {"hide", "躲", "躲在", "背後"}, + {"hospitl", "送醫院", "把", "送進醫院"}, + {"hug", "擁抱", "輕輕地擁抱", ""}, + {"hrk", "昇龍拳", "沉穩了身形,匯聚了內勁,對", "使出了一記Ho--Ryu--Kan!!!"}, + {"jab", "戳人", "溫柔的戳著", ""}, + {"judo", "過肩摔", "抓住了", "的衣襟,轉身……啊,是一記過肩摔!"}, + {"kickout", "踢", "用大腳把", "踢到山下去了"}, + {"kick", "踢人", "把", "踢的死去活來"}, + {"kiss", "輕吻", "輕吻", "的臉頰"}, + {"laugh", "嘲笑", "大聲嘲笑", ""}, + {"levis", "給我", "說:給我", "!其餘免談!"}, + {"lick", "舔", "狂舔", ""}, + {"lobster", "壓制", "施展逆蝦形固定,把", "壓制在地板上"}, + {"love", "表白", "對", "深情的表白"}, + {"marry", "求婚", "捧著九百九十九朵玫瑰向", "求婚"}, + {"no", "不要啊", "拼命對著", "搖頭~~~~不要啊~~~~"}, + {"nod", "點頭", "向", "點頭稱是"}, + {"nudge", "頂肚子", "用手肘頂", "的肥肚子"}, + {"pad", "拍肩膀", "輕拍", "的肩膀"}, + {"pettish", "撒嬌", "跟", "嗲聲嗲氣地撒嬌"}, + {"pili", "霹靂", "使出 君子風 天地根 般若懺 三式合一打向", "~~~~~~"}, + {"pinch", "擰人", "用力的把", "擰的黑青"}, + {"roll", "打滾", "放出多爾袞的音樂,", "在地上滾來滾去"}, + {"protect", "保護", "保護著", ""}, + {"pull", "拉", "死命地拉住", "不放"}, + {"punch", "揍人", "狠狠揍了", "一頓"}, + {"rascal", "耍賴", "跟", "耍賴"}, + {"recline", "入懷", "鑽到", "的懷裡睡著了……"}, + {"respond", "負責", "安慰", "說:『不要哭,我會負責的……』"}, + {"shrug", "聳肩", "無奈地向", "聳了聳肩膀"}, + {"sigh", "歎氣", "對", "歎了一口氣"}, + {"slap", "打耳光", "啪啪的巴了", "一頓耳光"}, + {"smooch", "擁吻", "擁吻著", ""}, + {"snicker", "竊笑", "嘿嘿嘿..的對", "竊笑"}, + {"sniff", "不屑", "對", "嗤之以鼻"}, + {"spank", "打屁屁", "用巴掌打", "的臀部"}, + {"squeeze", "緊擁", "緊緊地擁抱著", ""}, + {"sysop", "召喚", "叫出了批踢踢,把", "踩扁了!"}, + {"thank", "感謝", "向", "感謝得五體投地"}, + {"tickle", "搔癢", "咕嘰!咕嘰!搔", "的癢"}, + {"wake", "搖醒", "輕輕地把", "搖醒"}, + {"wave", "揮手", "對著", "拼命的搖手"}, + {"welcome", "歡迎", "歡迎", "進來八卦一下"}, + {"what", "什麼", "說:『", "哩公瞎密哇隴聽某???﹖?』"}, + {"whip", "鞭子", "手上拿著蠟燭,用鞭子痛打", ""}, + {"wink", "眨眼", "對", "神秘的眨眨眼睛"}, + {"zap", "猛攻", "對", "瘋狂的攻擊"}, + {NULL, NULL, NULL, NULL} +}; + +static int +chicken_action(cu, cmd, party) + ChatUser *cu; + char *cmd; + char *party; +{ +return 0; +} +static int +party_action(cu, cmd, party) + ChatUser *cu; + char *cmd; + char *party; +{ + ChatAction *cap; + char *verb; + + for (cap = party_data; (verb = cap->verb); cap++) + { + MYDOG; + + if (str_equal(cmd, verb)) + { + if (*party == '\0') + { + party = "大家"; + } + else + { + ChatUser *xuser; + + xuser = fuzzy_cuser_by_chatid(party); + if (xuser == NULL) + { /* Thor.0724: 用 userid也嘛通 */ + xuser = cuser_by_userid(party); + } + + if (xuser == NULL) + { + sprintf(chatbuf, msg_no_such_id, party); + send_to_user(cu, chatbuf, 0, MSG_MESSAGE); + return 0; + } + else if (xuser == FUZZY_USER) + { + sprintf(chatbuf, "※ 請指明聊天代號"); + send_to_user(cu, chatbuf, 0, MSG_MESSAGE); + return 0; + } + else if (cu->room != xuser->room || CLOAK(xuser)) + { + sprintf(chatbuf, msg_not_here, party); + send_to_user(cu, chatbuf, 0, MSG_MESSAGE); + return 0; + } + else + { + party = xuser->chatid; + } + } + sprintf(chatbuf, "%s %s %s %s", + cu->chatid, cap->part1_msg, party, cap->part2_msg); + send_to_room(cu->room, chatbuf, cu->userno, MSG_MESSAGE); + return 0; /* Thor: cu->room 是否為 NULL? */ + } + } + return 1; +} + + +/* --------------------------------------------- */ +/* MUD-like social commands : speak */ +/* --------------------------------------------- */ + + +static ChatAction speak_data[] = +{ + + { + "ask", "詢問", "問", NULL + }, + { + "chant", "歌頌", "高聲歌頌", NULL + }, + { + "cheer", "喝采", "喝采", NULL + }, + { + "chuckle", "輕笑", "輕笑", NULL + }, + { + "curse", "暗幹", "暗幹", NULL + }, + /* {"curse", "咒罵", NULL}, */ + { + "demand", "要求", "要求", NULL + }, + { + "frown", "皺眉頭", "蹙眉", NULL + }, + { + "groan", "呻吟", "呻吟", NULL + }, + { + "grumble", "發牢騷", "發牢騷", NULL + }, + { + "guitar", "彈唱", "邊彈著吉他,邊唱著", NULL + }, + /* {"helpme", "呼救","大聲呼救",NULL}, */ + { + "hum", "喃喃", "喃喃自語", NULL + }, + { + "moan", "怨嘆", "怨嘆", NULL + }, + { + "notice", "強調", "強調", NULL + }, + { + "order", "命令", "命令", NULL + }, + { + "ponder", "沈思", "沈思", NULL + }, + { + "pout", "噘嘴", "噘著嘴說", NULL + }, + { + "pray", "祈禱", "祈禱", NULL + }, + { + "request", "懇求", "懇求", NULL + }, + { + "shout", "大罵", "大罵", NULL + }, + { + "sing", "唱歌", "唱歌", NULL + }, + { + "smile", "微笑", "微笑", NULL + }, + { + "smirk", "假笑", "假笑", NULL + }, + { + "swear", "發誓", "發誓", NULL + }, + { + "tease", "嘲笑", "嘲笑", NULL + }, + { + "whimper", "嗚咽", "嗚咽的說", NULL + }, + { + "yawn", "哈欠", "邊打哈欠邊說", NULL + }, + { + "yell", "大喊", "大喊", NULL + }, + { + NULL, NULL, NULL, NULL + } +}; + + +static int +speak_action(cu, cmd, msg) + ChatUser *cu; + char *cmd; + char *msg; +{ + ChatAction *cap; + char *verb; + + for (cap = speak_data; (verb = cap->verb); cap++) + { + MYDOG; + + if (str_equal(cmd, verb)) + { + sprintf(chatbuf, "%s %s: %s", + cu->chatid, cap->part1_msg, msg); + send_to_room(cu->room, chatbuf, cu->userno, MSG_MESSAGE); + return 0; /* Thor: cu->room 是否為 NULL? */ + } + } + return 1; +} + + +/* -------------------------------------------- */ +/* MUD-like social commands : condition */ +/* -------------------------------------------- */ + + +static ChatAction condition_data[] = +{ + { + "applaud", "拍手", "啪啪啪啪啪啪啪....", NULL + }, + { + "ayo", "唉呦喂", "唉呦喂~~~", NULL + }, + { + "back", "坐回來", "回來坐正繼續奮戰", NULL + }, + { + "blood", "在血中", "倒在血泊之中", NULL + }, + { + "blush", "臉紅", "臉都紅了", NULL + }, + { + "broke", "心碎", "的心破碎成一片一片的", NULL + }, /* Thor.0731:應觀眾要求 */ + /* {"bokan", "Bo Kan! Bo Kan!", NULL}, */ + { + "careles", "沒人理", "嗚∼∼都沒有人理我 :~~~~", NULL + }, + { + "chew", "嗑瓜子", "很悠閒的嗑起瓜子來了", NULL + }, + { + "climb", "爬山", "自己慢慢爬上山來……", NULL + }, + { + "cold", "感冒了", "感冒了,媽媽不讓我出去玩 :~~~(", NULL + }, + { + "cough", "咳嗽", "咳了幾聲", NULL + }, + { + "die", "暴斃", "當場暴斃", NULL + }, + { + "faint", "昏倒", "當場昏倒", NULL + }, + { + "flop", "香蕉皮", "踩到香蕉皮... 滑倒!", NULL + }, + { + "fly", "飄飄然", "飄飄然", NULL + }, + { + "frown", "蹙眉", "蹙眉", NULL + }, + { + "gold", "拿金牌", "唱著:『金ㄍㄠˊ金ㄍㄠˊ 出國比賽! 得冠軍,拿金牌,光榮倒鄧來!』", NULL + }, + { + "gulu", "肚子餓", "的肚子發出咕嚕~~~咕嚕~~~的聲音", NULL + }, + { + "haha", "哇哈哈", "哇哈哈哈.....^o^", NULL + }, + /* {"haha", "大笑","哇哈哈哈哈哈哈哈哈~~~~!!!!!", NULL}, */ + { + "helpme", "求救", "大喊~~~救命啊~~~~", NULL + }, + { + "hoho", "呵呵笑", "呵呵呵笑個不停", NULL + }, + { + "happy", "高興", "高興得在地上打滾", NULL + }, + /* {"happy", "高興", "YA! *^_^*", NULL}, */ + /* {"happy", "", "r-o-O-m....聽了真爽!", NULL}, */ + /* {"hurricane", "Ho---Ryu--Kan!!!", NULL}, */ + { + "idle", "呆住了", "呆住了", NULL + }, + { + "jacky", "晃晃", "痞子般的晃來晃去", NULL + }, + +#if 0 + /* Thor.0729: 不知其意 */ + { + "lag", "網路慢", "lllllllaaaaaaaaaaaagggggggggggggg.................", NULL + }, +#endif + + { + "luck", "幸運", "哇!福氣啦!", NULL + }, + { + "macarn", "一種舞", "開始跳起了MaCaReNa∼∼∼∼", NULL + }, + { + "miou", "喵喵", "喵喵口苗口苗∼∼∼∼∼", NULL + }, + { + "mouth", "扁嘴", "扁嘴中!!", NULL + }, + { + "nani", "怎麼會", ":奈ㄝ啊捏??", NULL + }, + { + "nose", "流鼻血", "流鼻血", NULL + }, + { + "puke", "嘔吐", "嘔吐中", NULL + }, + /* {"puke", "真噁心,我聽了都想吐", NULL}, */ + { + "rest", "休息", "休息中,請勿打擾", NULL + }, + { + "reverse", "翻肚", "翻肚", NULL + }, + { + "room", "開房間", "r-o-O-m-r-O-O-Mmm-rRR........", NULL + }, + { + "shake", "搖頭", "搖了搖頭", NULL + }, + { + "sleep", "睡著", "趴在鍵盤上睡著了,口水流進鍵盤,造成當機!", NULL + }, + /* {"sleep", "Zzzzzzzzzz,真無聊,都快睡著了", NULL}, */ + { + "so", "就醬子", "就醬子!!", NULL + }, + { + "sorry", "道歉", "嗚啊!!我對不起大家,我對不起國家社會~~~~~~嗚啊~~~~~", NULL + }, + { + "story", "講古", "開始講古了", NULL + }, + { + "strut", "搖擺\走", "大搖大擺\地走", NULL + }, + { + "suicide", "自殺", "自殺", NULL + }, + { + "tea", "泡茶", "泡了壺好茶", NULL + }, + { + "think", "思考", "歪著頭想了一下", NULL + }, + { + "tongue", "吐舌", "吐了吐舌頭", NULL + }, + { + "wall", "撞牆", "跑去撞牆", NULL + }, + { + "wawa", "哇哇", "哇哇哇~~~~~!!!!! ~~~>_<~~~", NULL + }, + /* {"wawa","哇哇哇......>_<",NULL}, */ + { + "www", "汪汪", "汪汪汪!!!", NULL + }, + { + "zzz", "打呼", "呼嚕~~~~ZZzZzzZZZzzZzzzZZ...", NULL + }, + + { + NULL, NULL, NULL, NULL + } +}; + + +static int +condition_action(cu, cmd) + ChatUser *cu; + char *cmd; +{ + ChatAction *cap; + char *verb; + + for (cap = condition_data; (verb = cap->verb); cap++) + { + MYDOG; + + if (str_equal(cmd, verb)) + { + sprintf(chatbuf, "%s %s", + cu->chatid, cap->part1_msg); + send_to_room(cu->room, chatbuf, cu->userno, MSG_MESSAGE); + return 1; /* Thor: cu->room 是否為 NULL? */ + } + } + return 0; +} + + +/* --------------------------------------------- */ +/* MUD-like social commands : help */ +/* --------------------------------------------- */ + + +static char *dscrb[] = +{ + "【 Verb + Nick: 動詞 + 對方名字 】 例://kick piggy", + "【 Verb + Message:動詞 + 要說的話 】 例://sing 天天天藍", + "【 Verb:動詞 】 ↑↓:舊話重提", NULL +}; +ChatAction *catbl[] = +{ + party_data, speak_data, condition_data, NULL +}; + +static void +chat_partyinfo(cu, msg) + ChatUser *cu; + char *msg; +{ + if (!common_client_command) + return; /* only allow common client to retrieve it */ + + sprintf(chatbuf, "3 動作 交談 狀態"); + send_to_user(cu, chatbuf, 0, MSG_PARTYINFO); +} + +static void +chat_party(cu, msg) + ChatUser *cu; + char *msg; +{ + int kind, i; + ChatAction *cap; + + if (!common_client_command) + return; + + kind = atoi(nextword(&msg)); + if (kind < 0 || kind > 2) + return; + + sprintf(chatbuf, "%d %s", kind, kind == 2 ? "I" : ""); + + /* Xshadow: 只有 condition 才是 immediate mode */ + send_to_user(cu, chatbuf, 0, MSG_PARTYLISTSTART); + + cap = catbl[kind]; + for (i = 0; cap[i].verb; i++) + { + sprintf(chatbuf, "%-10s %-20s", cap[i].verb, cap[i].chinese); + /* for (j=0;j<1000000;j++); */ + send_to_user(cu, chatbuf, 0, MSG_PARTYLIST); + } + + sprintf(chatbuf, "%d", kind); + send_to_user(cu, chatbuf, 0, MSG_PARTYLISTEND); +} + + +#define SCREEN_WIDTH 80 +#define MAX_VERB_LEN 8 +#define VERB_NO 10 + +static void +view_action_verb(cu, cmd) /* Thor.0726: 新加動詞分類顯示 */ + register ChatUser *cu; + char cmd; +{ + register int i; + register char *p, *q, *data, *expn; + register ChatAction *cap; + + send_to_user(cu, "/c", 0, MSG_CLRSCR); + + data = chatbuf; + + if (cmd < '1' || cmd > '3') + { /* Thor.0726: 寫得不好, 想辦法改進... */ + for (i = 0; (p = dscrb[i]); i++) + { + sprintf(data, " [//]help %d - MUD-like 社交動詞 第 %d 類", i + 1, i + 1); + MYDOG; + send_to_user(cu, data, 0, MSG_MESSAGE); + send_to_user(cu, p, 0, MSG_MESSAGE); + send_to_user(cu, " ", 0, MSG_MESSAGE); /* Thor.0726: 換行, 需要 " " + * 嗎? */ + } + } + else + { + i = cmd - '1'; + + send_to_user(cu, dscrb[i], 0, MSG_MESSAGE); + + expn = chatbuf + 100; /* Thor.0726: 應該不會overlap吧? */ + + *data = '\0'; + *expn = '\0'; + + cap = catbl[i]; + + for (i = 0; (p = cap[i].verb); i++) + { + MYDOG; + q = cap[i].chinese; + + strcat(data, p); + strcat(expn, q); + + if (((i + 1) % VERB_NO) == 0) + { + send_to_user(cu, data, 0, MSG_MESSAGE); + send_to_user(cu, expn, 0, MSG_MESSAGE); /* Thor.0726: 顯示中文註解 */ + *data = '\0'; + *expn = '\0'; + } + else + { + strncat(data, " ", MAX_VERB_LEN - strlen(p)); + strncat(expn, " ", MAX_VERB_LEN - strlen(q)); + } + } + if (i % VERB_NO) + { + send_to_user(cu, data, 0, MSG_MESSAGE); + send_to_user(cu, expn, 0, MSG_MESSAGE); /* Thor.0726: 顯示中文註解 */ + } + } + /* send_to_user(cu, " ",0); *//* Thor.0726: 換行, 需要 " " 嗎? */ +} + +void view_chicken_help(cu) /* Ptt: 鬥雞程式 的help */ + register ChatUser *cu; +{ + +} + +/* ----------------------------------------------------- */ +/* chat user service routines */ +/* ----------------------------------------------------- */ + + +static ChatCmd chatcmdlist[] = +{ + {"act", chat_act, 0}, + {"bye", chat_goodbye, 0}, + {"chatroom", chat_chatroom, 1}, /* Xshadow: for common client */ + {"clear", chat_clear, 0}, + {"cloak", chat_cloak, 2}, + {"date", chat_date, 0}, + {"flags", chat_setroom, 0}, + {"help", chat_help, 0}, + {"ignore", chat_ignore, 1}, + {"invite", chat_invite, 0}, + {"join", chat_join, 0}, + {"kick", chat_kick, 1}, + {"msg", chat_private, 0}, + {"nick", chat_nick, 0}, + {"operator", chat_makeop, 0}, + {"party", chat_party, 1}, /* Xshadow: party data for common client */ + {"partyinfo", chat_partyinfo, 1}, /* Xshadow: party info for common + * client */ + + {"query", chat_query, 0}, + + {"room", chat_list_rooms, 0}, + {"unignore", chat_unignore, 1}, + {"whoin", chat_list_by_room, 1}, + {"wall", chat_broadcast, 2}, + + {"who", chat_map_chatids_thisroom, 0}, + {"list", chat_list_users, 0}, + {"topic", chat_topic, 1}, + {"version", chat_version, 1}, + + {NULL, NULL, 0} +}; + +/* Thor: 0 不用 exact, 1 要 exactly equal, 2 秘密指令 */ + + +static int +command_execute(cu) + ChatUser *cu; +{ + char *cmd, *msg; + ChatCmd *cmdrec; + int match, ch; + + msg = cu->ibuf; + match = *msg; + + /* Validation routine */ + + if (cu->room == NULL) + { + /* MUST give special /! or /-! command if not in the room yet */ + + if (match == '/' && ((ch = msg[1]) == '!' || (ch == '-' && msg[2] == '!'))) + { + cu->clitype = (ch == '-') ? 1 : 0; + return (login_user(cu, msg + 2 + cu->clitype)); + } + else + return -1; + } + + /* If not a /-command, it goes to the room. */ + + if (match != '/') + { + if (match) + { + char buf[16]; + + sprintf(buf, "%s:", cu->chatid); + sprintf(chatbuf, "%-10s%s", buf, msg); + if (!CLOAK(cu)) /* Thor: 聊天室隱身術 */ + send_to_room(cu->room, chatbuf, cu->userno, MSG_MESSAGE); + /* Thor: 要 check cu->room NULL嗎? */ + + } + return 0; + } + + msg++; + cmd = nextword(&msg); + match = 0; + + if (*cmd == '/') + { + cmd++; + if (!*cmd || str_equal(cmd, "help")) + { + /* Thor.0726: 動詞分類 */ + cmd = nextword(&msg); + view_action_verb(cu, *cmd); + match = 1; + } + else if (party_action(cu, cmd, msg) == 0) + match = 1; + else if (speak_action(cu, cmd, msg) == 0) + match = 1; + else + match = condition_action(cu, cmd); + } + else if(*cmd == '.') + { + cmd++; + if (!*cmd || str_equal(cmd, "help")) + { + view_chicken_help(cu); + match = 1; + } + else match = chicken_action(cu, cmd, msg); + } + else + { + char *str; + + common_client_command = 0; + if((*cmd == '-')) { + if(cu->clitype) { + cmd++; /* Xshadow: 指令從下一個字元才開始 */ + common_client_command = 1; + } + } + for(cmdrec = chatcmdlist; (str = cmdrec->cmdstr); cmdrec++) + { + MYDOG; + + switch (cmdrec->exact) + { + case 1: /* exactly equal */ + match = str_equal(cmd, str); + break; + case 2: /* Thor: secret command */ + if (CHATSYSOP(cu)) + match = str_equal(cmd, str); + break; + default: /* not necessary equal */ + match = str_match(cmd, str) >= 0; + break; + } + + if (match) + { + cmdrec->cmdfunc(cu, msg); + break; + } + } + } + + if (!match) + { + sprintf(chatbuf, "◆ 指令錯誤:/%s", cmd); + send_to_user(cu, chatbuf, 0, MSG_MESSAGE); + } + return 0; +} + + +/* ----------------------------------------------------- */ +/* serve chat_user's connection */ +/* ----------------------------------------------------- */ + + +static int +cuser_serve(cu) + ChatUser *cu; +{ + register int ch, len, isize; + register char *str, *cmd; + static char buf[80]; + + str = buf; + len = recv(cu->sock, str, sizeof(buf) - 1, 0); + if (len <= 0) + { + /* disconnected */ + + exit_room(cu, EXIT_LOSTCONN, (char *) NULL); + return -1; + } + +#if 0 + /* Xshadow: 將送達的資料忠實紀錄下來 */ + memcpy(logbuf, buf, sizeof(buf)); + for (ch = 0; ch < sizeof(buf); ch++) + if (!logbuf[ch]) + logbuf[ch] = '$'; + + logbuf[len + 1] = '\0'; + logit("recv: ", logbuf); +#endif + +#if 0 + logit(cu->userid, str); +#endif + + isize = cu->isize; + cmd = cu->ibuf + isize; + while (len--) + { + MYDOG; + + ch = *str++; + + if (ch == '\r' || !ch) + continue; + if (ch == '\n') + { + *cmd = '\0'; + + isize = 0; + cmd = cu->ibuf; + + if (command_execute(cu) < 0) + return -1; + + continue; + } + if (isize < 79) + { + *cmd++ = ch; + isize++; + } + } + cu->isize = isize; + return 0; +} + + +/* ----------------------------------------------------- */ +/* chatroom server core routines */ +/* ----------------------------------------------------- */ + +static int +start_daemon() +{ + int fd, value; + char buf[80]; + struct sockaddr_in fsin; + struct linger ld; + struct rlimit limit; + time_t dummy; + struct tm *dummy_time; + + /* + * More idiot speed-hacking --- the first time conversion makes the C + * library open the files containing the locale definition and time zone. + * If this hasn't happened in the parent process, it happens in the + * children, once per connection --- and it does add up. + */ + + time(&dummy); + dummy_time = gmtime(&dummy); + dummy_time = localtime(&dummy); + strftime(buf, 80, "%d/%b/%Y:%H:%M:%S", dummy_time); + + /* --------------------------------------------------- */ + /* speed-hacking DNS resolve */ + /* --------------------------------------------------- */ + + gethostname(buf, sizeof(buf)); + + /* Thor: 萬一server尚未接受connection, 就回去的話, client 第一次會進入失敗 */ + /* 所以移至 listen 後 */ + + /* --------------------------------------------------- */ + /* detach daemon process */ + /* --------------------------------------------------- */ + + close(0); + close(1); + close(2); + + if (fork()) + exit(0); + + chdir(BBSHOME); + + setsid(); + + /* --------------------------------------------------- */ + /* adjust the resource limit */ + /* --------------------------------------------------- */ + + getrlimit(RLIMIT_NOFILE, &limit); + limit.rlim_cur = limit.rlim_max; + setrlimit(RLIMIT_NOFILE, &limit); + +#if 0 + while (fd) + { + close(--fd); + } + + value = getpid(); + setpgrp(0, value); + + if ((fd = open("/dev/tty", O_RDWR)) >= 0) + { + ioctl(fd, TIOCNOTTY, 0); /* Thor : 為什麼還要用 tty? */ + close(fd); + } +#endif + + fd = open(CHAT_PIDFILE, O_WRONLY | O_CREAT | O_TRUNC, 0600); + if (fd >= 0) + { + /* sprintf(buf, "%5d\n", value); */ + sprintf(buf, "%5d\n", getpid()); + write(fd, buf, 6); + close(fd); + } + +#if 0 + /* ------------------------------ */ + /* trap signals */ + /* ------------------------------ */ + + for (fd = 1; fd < NSIG; fd++) + { + + signal(fd, SIG_IGN); + } +#endif + + fd = socket(PF_INET, SOCK_STREAM, 0); + +#if 0 + value = fcntl(fd, F_GETFL, 0); + fcntl(fd, F_SETFL, value | O_NDELAY); +#endif + + value = 1; + setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (char *) &value, sizeof(value)); + +#if 0 + setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, (char *) &value, sizeof(value)); + + value = 81920; + setsockopt(fd, SOL_SOCKET, SO_RCVBUF, (char *) &value, sizeof(value)); +#endif + + ld.l_onoff = ld.l_linger = 0; + setsockopt(fd, SOL_SOCKET, SO_LINGER, (char *) &ld, sizeof(ld)); + + memset((char *) &fsin, 0, sizeof(fsin)); + fsin.sin_family = AF_INET; + fsin.sin_port = htons(NEW_CHATPORT); + fsin.sin_addr.s_addr = htonl(INADDR_ANY); + + if (bind(fd, (struct sockaddr *) & fsin, sizeof(fsin)) < 0) + exit(1); + + listen(fd, SOCK_QLEN); + + return fd; +} + + +static void +free_resource(fd) + int fd; +{ + static int loop = 0; + register ChatUser *user; + register int sock, num; + + num = 0; + for (user = mainuser; user; user = user->unext) + { + MYDOG; + + num++; + sock = user->sock; + if (fd < sock) + fd = sock; + } + + sprintf(chatbuf, "%d, %d user (%d -> %d)", ++loop, num, maxfds, fd); + logit("LOOP", chatbuf); + + maxfds = fd + 1; +} + + +#ifdef SERVER_USAGE +static void +server_usage() +{ + struct rusage ru; + char buf[2048]; + + if (getrusage(RUSAGE_SELF, &ru)) + return; + + sprintf(buf, "\n[Server Usage]\n\n" + "user time: %.6f\n" + "system time: %.6f\n" + "maximum resident set size: %lu P\n" + "integral resident set size: %lu\n" + "page faults not requiring physical I/O: %ld\n" + "page faults requiring physical I/O: %ld\n" + "swaps: %ld\n" + "block input operations: %ld\n" + "block output operations: %ld\n" + "messages sent: %ld\n" + "messages received: %ld\n" + "signals received: %ld\n" + "voluntary context switches: %ld\n" + "involuntary context switches: %ld\n" + "gline: %d\n\n", + + (double) ru.ru_utime.tv_sec + (double) ru.ru_utime.tv_usec / 1000000.0, + (double) ru.ru_stime.tv_sec + (double) ru.ru_stime.tv_usec / 1000000.0, + ru.ru_maxrss, + ru.ru_idrss, + ru.ru_minflt, + ru.ru_majflt, + ru.ru_nswap, + ru.ru_inblock, + ru.ru_oublock, + ru.ru_msgsnd, + ru.ru_msgrcv, + ru.ru_nsignals, + ru.ru_nvcsw, + ru.ru_nivcsw, + gline); + + write(flog, buf, strlen(buf)); +} +#endif + + +static void +abort_server() +{ + log_close(); + exit(1); +} + + +static void +reaper() +{ + int state; + + while (waitpid(-1, &state, WNOHANG | WUNTRACED) > 0) + { + MYDOG; + } +} + + +int +main() +{ + register int msock, csock, nfds; + register ChatUser *cu; + register fd_set *rptr, *xptr; + fd_set rset, xset; + struct timeval tv; + time_t uptime, tmaintain; + + msock = start_daemon(); + + setgid(BBSGID); + setuid(BBSUID); + + log_init(); + + signal(SIGBUS, SIG_IGN); + signal(SIGSEGV, SIG_IGN); + signal(SIGPIPE, SIG_IGN); + signal(SIGURG, SIG_IGN); + + signal(SIGCHLD, reaper); + signal(SIGTERM, abort_server); + +#ifdef SERVER_USAGE + signal(SIGPROF, server_usage); +#endif + + /* ----------------------------- */ + /* init variable : rooms & users */ + /* ----------------------------- */ + + mainuser = NULL; + memset(&mainroom, 0, sizeof(mainroom)); + strcpy(mainroom.name, MAIN_NAME); + strcpy(mainroom.topic, MAIN_TOPIC); + + /* ----------------------------------- */ + /* main loop */ + /* ----------------------------------- */ + +#if 0 + /* Thor: 在listen 後才回client, 每次進來就會成功 */ + if (fork()) + exit(0); +#endif + + FD_ZERO(&mainfds); + FD_SET(msock, &mainfds); + rptr = &rset; + xptr = &xset; + maxfds = msock + 1; + + tmaintain = time(0) + CHAT_INTERVAL; + + for (;;) + { + uptime = time(0); + if (tmaintain < uptime) + { + tmaintain = uptime + CHAT_INTERVAL; + + /* client/server 版本利用 ping-pong 方法判斷 user 是不是還活著 */ + /* 如果 client 已經結束了,就釋放其 resource */ + + free_resource(msock); + } + + MYDOG; + + memcpy(rptr, &mainfds, sizeof(fd_set)); + memcpy(xptr, &mainfds, sizeof(fd_set)); + + /* Thor: for future reservation bug */ + + tv.tv_sec = CHAT_INTERVAL; + tv.tv_usec = 0; + + MYDOG; + + nfds = select(maxfds, rptr, NULL, xptr, &tv); + + MYDOG; + /* free idle user & chatroom's resource when no traffic */ + + if (nfds == 0) + { + continue; + } + + /* check error condition */ + + if (nfds < 0) + { + csock = errno; + continue; + } + + /* accept new connection */ + + if (FD_ISSET(msock, rptr)) + { + for (;;) + { + MYDOG; /* Thor: check for endless */ + csock = accept(msock, NULL, NULL); + + if (csock >= 0) + { + MYDOG; + if((cu = (ChatUser *) malloc(sizeof(ChatUser)))) + { + memset(cu, 0, sizeof(ChatUser)); + cu->sock = csock; + + cu->unext = mainuser; + mainuser = cu; + +#if 0 + if (mainuser.next) + mainuser.next->prev = cu; + cu->next = mainuser.next; + mainuser.next = cu; + cu->prev = &mainuser; +#endif + + totaluser++; + FD_SET(csock, &mainfds); + if (csock >= maxfds) + maxfds = csock + 1; + +#ifdef DEBUG + logit("accept", "OK"); +#endif + } + else + { + close(csock); + logit("accept", "malloc fail"); + } + MYDOG; + + break; + } + + csock = errno; + if (csock != EINTR) + { + break; + } + } + + FD_CLR(msock, rptr); + + if (--nfds <= 0) + continue; + } + + for (cu = mainuser; cu; cu = cu->unext) + { + MYDOG; + + csock = cu->sock; + + if (FD_ISSET(csock, xptr)) + { + logout_user(cu); + FD_CLR(csock, xptr); + } + else if (FD_ISSET(csock, rptr)) + { + if (cuser_serve(cu) < 0) + logout_user(cu); + } + else + { + continue; + } + + FD_CLR(csock, rptr); + if (--nfds <= 0) + break; + } + + /* end of main loop */ + } +} diff --git a/pttbbs/util/xchatd.h b/pttbbs/util/xchatd.h new file mode 100644 index 00000000..d0a6e1e4 --- /dev/null +++ b/pttbbs/util/xchatd.h @@ -0,0 +1,111 @@ +/* $Id: xchatd.h,v 1.1 2002/03/07 15:13:46 in2 Exp $ */ + +#ifndef _XCHAT_H_ +#define _XCHAT_H_ + +#define XCHAT_VERSION_MAJOR 3 +#define XCHAT_VERSION_MINOR 0 + +/* ----------------------------------------------------- */ +/* XCHAT response code : RFI 3-digit */ +/* ----------------------------------------------------- */ +/* Response : */ +/* 1xx Informative message */ +/* 2xx Command ok */ +/* 3xx Command ok so far, send the rest of it */ +/* 4xx Command correct, but NG for some reason */ +/* 5xx Command unimplemented, incorrect, or serious */ +/* program error occurred */ +/* Function : */ +/* x0x Connection, setup, and miscellaneous messages */ +/* x1x Newsgroup selection */ +/* x2x Article selection */ +/* x3x Distribution functions */ +/* x4x Posting */ +/* x8x Nonstandard extensions (AUTHINFO, XGTITLE) */ +/* x9x Debugging output */ +/* Information : */ +/* No defined semantics */ +/* ----------------------------------------------------- */ + +/* 供新版 client 使用 */ + +#define MSG_LOGINOK 100 +#define MSG_VERSION 103 +#define MSG_MESSAGE 106 + +#define MSG_CHATROOM 110 +#define MSG_TOPIC 113 +#define MSG_ROOM 116 +#define MSG_NICK 118 +#define MSG_CLRSCR 120 + +#define MSG_MOTDSTART 130 +#define MSG_MOTD 330 +#define MSG_MOTDEND 230 + +#define MSG_ROOMLISTSTART 133 +#define MSG_ROOMLIST 333 +#define MSG_ROOMLISTEND 233 +#define MSG_ROOMNOTIFY 134 + +#define MSG_USERLISTSTART 136 +#define MSG_USERLIST 336 +#define MSG_USERLISTEND 236 +#define MSG_USERNOTIFY 137 + +#define MSG_PARTYINFO 140 +#define MSG_PARTYLISTSTART 340 +#define MSG_PARTYLIST 240 +#define MSG_PARTYLISTEND 141 + +#define MSG_PRIVMSG 145 +#define MSG_MYPRIVMSG 146 + +#define ERR_LOGIN_NICKINUSE 501 +#define ERR_LOGIN_NICKERROR 502 +#define ERR_LOGIN_USERONLINE 503 +#define ERR_LOGIN_NOSUCHUSER 504 +#define ERR_LOGIN_PASSERROR 505 + +static int +Isspace (ch) + int ch; +{ + return (ch == ' ' || ch == '\t' || ch == 10 || ch == 13); +} + +static char * +nextword (str) + char **str; +{ + char *head, *tail; + int ch; + + head = *str; + for (;;) { + + ch = *head; + if (!ch) { + *str = head; + return head; + } + if (!Isspace (ch)) + break; + head++; + } + + tail = head + 1; + while((ch = *tail)) { + if(Isspace (ch)) { + *tail++ = '\0'; + break; + } + tail++; + } + *str = tail; + + return head; +} + +#endif /* _XCHAT_H_ */ diff --git a/pttbbs/util/yearsold.c b/pttbbs/util/yearsold.c new file mode 100644 index 00000000..74e711ee --- /dev/null +++ b/pttbbs/util/yearsold.c @@ -0,0 +1,112 @@ +/* $Id: yearsold.c,v 1.1 2002/03/07 15:13:46 in2 Exp $ */ +/* 站上年齡統計 */ + +#include <stdio.h> +#include <string.h> +#include <time.h> +#include <sys/types.h> +#include "config.h" +#include "pttstruct.h" +#include "common.h" +#include "util.h" + +#define MAX_LINE 16 + +struct userec_t cuser; + +void + outs(fp, buf, mode) +FILE *fp; +char buf[], mode; +{ + static char state = '0'; + + if (state != mode) + fprintf(fp, "[3%cm", state = mode); + if (buf[0]) + { + fprintf(fp, buf); + buf[0] = 0; + } +} + +int main() +{ + int i, j, k; + char buf[256]; + FILE *fp; + int year, max, item, maxyear; + long totalyear; + int act[25]; + time_t now; + struct tm *ptime; + + now = time(NULL); + ptime = localtime(&now); + + if(passwd_mmap()) + exit(1); + + memset(act, 0, sizeof(act)); + for(k = 1; k <= MAX_USERS; k++) { + passwd_query(k, &cuser); + if (((ptime->tm_year - cuser.year) < 10) || ((ptime->tm_year - cuser.year) > + 33)) + continue; + + act[ptime->tm_year - cuser.year - 10]++; + act[24]++; + } + + for (i = max = totalyear = maxyear = 0; i < 24; i++) + { + totalyear += act[i] * (i + 10); + if (act[i] > max) + { + max = act[i]; + maxyear = i; + } + } + + item = max / MAX_LINE + 1; + + if ((fp = fopen(BBSHOME"/etc/yearsold", "w")) == NULL) + { + printf("cann't open etc/yearsold\n"); + return 1; + } + + fprintf(fp, "\t\t\t  " BBSNAME + " 年齡統計 [%02d/%02d/%02d] \n\n", + ptime->tm_year % 100, ptime->tm_mon, ptime->tm_mday); + for (i = MAX_LINE + 1; i > 0; i--) + { + strcpy(buf, " "); + for (j = 0; j < 24; j++) + { + max = item * i; + year = act[j]; + if (year && (max > year) && (max - item <= year)) + { + outs(fp, buf, '7'); + fprintf(fp, "%-3d", year); + } + else if (max <= year) + { + outs(fp, buf, '4'); + fprintf(fp, "█ "); + } + else + strcat(buf, " "); + } + fprintf(fp, "\n"); + } + + + fprintf(fp, " " + "10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33\n\n" + "\t\t 有效統計人次:%-9d平均年齡:%d\n" + ,act[24], (int)totalyear / act[24]); + fclose(fp); + return 0; +} -- cgit v1.2.3 From 038aff7e95c5c7cf44b68148242c9bc42d9c8d29 Mon Sep 17 00:00:00 2001 From: bbs <bbs@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Thu, 7 Mar 2002 15:24:32 +0000 Subject: test :) git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@2 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/Makefile | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/pttbbs/mbbsd/Makefile b/pttbbs/mbbsd/Makefile index 886944f3..61690e6c 100644 --- a/pttbbs/mbbsd/Makefile +++ b/pttbbs/mbbsd/Makefile @@ -1,4 +1,4 @@ -# $Id: Makefile,v 1.1 2002/03/07 15:13:48 in2 Exp $ +# $Id: Makefile,v 1.2 2002/03/07 15:24:32 bbs Exp $ BBSHOME?=$(HOME) OSTYPE=FreeBSD @@ -37,6 +37,12 @@ all: $(PROG) $(PROG): $(OBJS) $(CC) $(LDFLAGS) -o $(PROG) $(OBJS) $(LIBS) +test: $(PROG) + killall -9 testmbbsd || true + cp mbbsd testmbbsd + ./testmbbsd 9000 + rm -f testmbbsd + install: $(PROG) install -d $(BBSHOME)/bin/ install -c -m 755 $(PROG) $(BBSHOME)/bin/ -- cgit v1.2.3 From ec83fcdcd2773cc3bbb77a89b86e9b37c6877cbf Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Thu, 7 Mar 2002 16:44:18 +0000 Subject: register default to skip git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@3 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/admin.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/pttbbs/mbbsd/admin.c b/pttbbs/mbbsd/admin.c index 14bc9721..54fb017f 100644 --- a/pttbbs/mbbsd/admin.c +++ b/pttbbs/mbbsd/admin.c @@ -1,4 +1,4 @@ -/* $Id: admin.c,v 1.1 2002/03/07 15:13:48 in2 Exp $ */ +/* $Id: admin.c,v 1.2 2002/03/07 16:44:18 in2 Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -812,8 +812,12 @@ int scan_register_form(char *regfile, int automode, int neednum) { ans[0] = 'd'; } else { getdata(b_lines - 1, 0, - "是否接受此資料(Y/N/Q/Del/Skip)?[Y] ", + "是否接受此資料(Y/N/Q/Del/Skip)?[S] ", ans, 3, LCECHO); + if( ans[0] != 'y' && ans[0] != 'n' && + ans[0] != 'q' && ans[0] != 'd' ) + ans[0] = 's'; + ans[1] = 0; } nSelf++; } else -- cgit v1.2.3 From 5b46a67c4aa673494036ad09fd5411a7e92e971c Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Thu, 7 Mar 2002 18:01:40 +0000 Subject: deleted git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@4 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/Makefile.save | 152 ---------------------------------------------- pttbbs/util/a.out | Bin 14661 -> 0 bytes 2 files changed, 152 deletions(-) delete mode 100644 pttbbs/util/Makefile.save delete mode 100644 pttbbs/util/a.out diff --git a/pttbbs/util/Makefile.save b/pttbbs/util/Makefile.save deleted file mode 100644 index 2d0651b1..00000000 --- a/pttbbs/util/Makefile.save +++ /dev/null @@ -1,152 +0,0 @@ -# $Id: Makefile.save,v 1.1 2002/03/07 15:13:45 in2 Exp $ - -BBSHOME?=$(HOME) -OSTYPE=linux - -# FreeBSD -CC_FreeBSD= gcc -CFLAGS_FreeBSD= -pipe -Wall -g -O3 -DHAVE_SETPROCTITLE -DBBSHOME='"$(BBSHOME)"' -I../include -LIBS_FreeBSD= -LIBMAIL_FreeBSD=-lutil -LIBCHAT_FreeBSD= - -# Linux -CC_linux= gcc -CFLAGS_linux= -pipe -Wall -g -O3 -DHAVE_DES_CRYPT -DBBSHOME='"$(BBSHOME)"' -I../include -LIBS_linux= -lresolv -LIBMAIL_linux= -LIBCHAT_linux= -lcrypt - -CC= $(CC_$(OSTYPE)) -CFLAGS= $(CFLAGS_$(OSTYPE)) -LDFLAGS=$(LDFLAGS_$(OSTYPE)) -LIBMAIL=$(LIBMAIL_$(OSTYPE)) -LIBCHAT=$(LIBCHAT_$(OSTYPE)) - -CPROGS= bbsmail BM_money post account birth deluserfile expire mandex\ - horoscope openvice parse_news openticket topusr yearsold uhash_loader\ - poststat showboard antispam countalldice webgrep bbsrf\ - initbbs outmail xchatd userlist tunepasswd buildir reaper shmsweep\ - merge_passwd merge_board inndBM buildAnnounce cpdeadbrd toplazyBM\ - jungo -PROGS= $(CPROGS) BM_money.sh backpasswd.sh mailog.sh opendice.sh\ - openticket.sh stock.sh topsong.sh weather.sh stock.perl weather.perl\ - cvslog.sh toplazyBM.sh - -all: $(PROGS) - -bbsmail: bbsmail.c util_cache.c util_record.c util_passwd.c - $(CC) $(CFLAGS) -o $@ $@.c util_cache.c util_record.c util_passwd.c - -BM_money: BM_money.c util_cache.c util_record.c util_passwd.c - $(CC) $(CFLAGS) -o $@ $@.c util_cache.c util_record.c util_passwd.c - -post: post.c util_cache.c util_record.c util_passwd.c - $(CC) $(CFLAGS) -o $@ $@.c util_cache.c util_record.c util_passwd.c - -account: account.c util_cache.c util_record.c util_passwd.c - $(CC) $(CFLAGS) -o $@ $@.c util_cache.c util_record.c util_passwd.c - -birth: birth.c util_cache.c util_record.c util_passwd.c - $(CC) $(CFLAGS) -o $@ $@.c util_cache.c util_record.c util_passwd.c - -deluserfile: deluserfile.c util_cache.c util_record.c util_passwd.c - $(CC) $(CFLAGS) -o $@ $@.c util_cache.c util_record.c util_passwd.c - -expire: expire.c util_cache.c util_record.c util_passwd.c - $(CC) $(CFLAGS) -o $@ $@.c util_cache.c util_record.c util_passwd.c - -mandex: mandex.c util_cache.c util_record.c util_passwd.c - $(CC) $(CFLAGS) -o $@ $@.c util_cache.c util_record.c util_passwd.c - -cpdeadbrd: cpdeadbrd.c util_cache.c util_record.c util_passwd.c - $(CC) $(CFLAGS) -o $@ $@.c util_cache.c util_record.c util_passwd.c - -horoscope: horoscope.c util_cache.c util_record.c util_passwd.c - $(CC) $(CFLAGS) -o $@ $@.c util_cache.c util_record.c util_passwd.c - -openvice: openvice.c util_cache.c util_record.c util_passwd.c - $(CC) $(CFLAGS) -o $@ $@.c util_cache.c util_record.c util_passwd.c - -parse_news: parse_news.c util_cache.c util_record.c util_passwd.c - $(CC) $(CFLAGS) -o $@ $@.c util_cache.c util_record.c util_passwd.c - -openticket: openticket.c util_cache.c util_record.c util_passwd.c - $(CC) $(CFLAGS) -o $@ $@.c util_cache.c util_record.c util_passwd.c - -topusr: topusr.c util_cache.c util_record.c util_passwd.c - $(CC) $(CFLAGS) -o $@ $@.c util_cache.c util_record.c util_passwd.c - -yearsold: yearsold.c util_cache.c util_record.c util_passwd.c - $(CC) $(CFLAGS) -o $@ $@.c util_cache.c util_record.c util_passwd.c - -xchatd: xchatd.c util_cache.c util_record.c util_passwd.c descrypt.c - $(CC) $(CFLAGS) -o $@ $@.c util_cache.c util_record.c util_passwd.c descrypt.c $(LIBCHAT) - -toplazyBM: toplazyBM.c util_cache.c util_record.c util_passwd.c - $(CC) $(CFLAGS) -o $@ $@.c util_cache.c util_record.c util_passwd.c - -jungo: jungo.c util_cache.c util_record.c util_passwd.c - $(CC) $(CFLAGS) -o $@ $@.c util_cache.c util_record.c util_passwd.c - -smtest: smtest.c util_cache.c util_record.c util_passwd.c - $(CC) $(CFLAGS) -o $@ $@.c util_cache.c util_record.c util_passwd.c - -reaper: reaper.c util_passwd.c - $(CC) $(CFLAGS) -o $@ $@.c util_passwd.c util_cache.c util_passwd.c - -buildAnnounce: buildAnnounce.c - $(CC) $(CFLAGS) -o $@ $@.c util_record.c util_cache.c util_passwd.c - -inndBM: inndBM.c - $(CC) $(CFLAGS) -o $@ $@.c util_record.c util_cache.c util_passwd.c - -shmsweep: shmsweep.c - $(CC) $(CFLAGS) -o $@ $@.c - -uhash_loader: uhash_loader.c - $(CC) $(CFLAGS) -o $@ $@.c - -showboard: showboard.c - $(CC) $(CFLAGS) -o $@ $@.c - -antispam: antispam.c - $(CC) $(CFLAGS) -o $@ $@.c - -countalldice: countalldice.c - $(CC) $(CFLAGS) -o $@ $@.c - -webgrep: webgrep.c - $(CC) $(CFLAGS) -o $@ $@.c - -bbsrf: bbsrf.c - $(CC) $(CFLAGS) -o $@ $@.c - -initbbs: initbbs.c - $(CC) $(CFLAGS) -o $@ $@.c - -outmail: outmail.c - $(CC) $(CFLAGS) -o $@ $@.c $(LIBMAIL) - -userlist: userlist.c - $(CC) $(CFLAGS) -o $@ $@.c - -tunepasswd: tunepasswd.c - $(CC) $(CFLAGS) -o $@ $@.c - -buildir: buildir.c - $(CC) $(CFLAGS) -o $@ $@.c - -merge_passwd: merge_passwd.c - $(CC) $(CFLAGS) -o $@ $@.c - -merge_board : merge_board.c - $(CC) $(CFLAGS) -o $@ $@.c - -install: $(PROGS) - install -d $(BBSHOME)/bin/ - install -c -m 755 $(PROGS) $(BBSHOME)/bin/ - chmod 4755 $(BBSHOME)/bin/post - -clean: - rm -f $(CPROGS) diff --git a/pttbbs/util/a.out b/pttbbs/util/a.out deleted file mode 100644 index f4032dc4..00000000 Binary files a/pttbbs/util/a.out and /dev/null differ -- cgit v1.2.3 From cc16ddeb09ed2aa780ef1da5559e287f6d659958 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Thu, 7 Mar 2002 18:01:57 +0000 Subject: append flags for FreeBSD/Linux git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@5 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/Makefile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pttbbs/util/Makefile b/pttbbs/util/Makefile index eeacad38..9ef46a2f 100644 --- a/pttbbs/util/Makefile +++ b/pttbbs/util/Makefile @@ -1,18 +1,18 @@ -# $Id: Makefile,v 1.1 2002/03/07 15:13:45 in2 Exp $ +# $Id: Makefile,v 1.2 2002/03/07 18:01:57 in2 Exp $ BBSHOME?=$(HOME) OSTYPE=linux # FreeBSD CC_FreeBSD= gcc -CFLAGS_FreeBSD= -pipe -Wall -g -O3 -DHAVE_SETPROCTITLE -DBBSHOME='"$(BBSHOME)"' -I../include +CFLAGS_FreeBSD= -DFreeBSD -pipe -Wall -g -O3 -DHAVE_SETPROCTITLE -DBBSHOME='"$(BBSHOME)"' -I../include LIBS_FreeBSD= LIBMAIL_FreeBSD=-lutil LIBCHAT_FreeBSD= # Linux CC_linux= gcc -CFLAGS_linux= -pipe -Wall -g -O3 -DHAVE_DES_CRYPT -DBBSHOME='"$(BBSHOME)"' -I../include +CFLAGS_linux= -DLinux -pipe -Wall -g -O3 -DHAVE_DES_CRYPT -DBBSHOME='"$(BBSHOME)"' -I../include LIBS_linux= -lresolv LIBMAIL_linux= LIBCHAT_linux= -lcrypt -- cgit v1.2.3 From 343925115b63d3101f1f2942f038c33d6cbedd22 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Thu, 7 Mar 2002 18:02:07 +0000 Subject: bbsctl bbsadm git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@6 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/bbsctl.c | 73 +++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 64 insertions(+), 9 deletions(-) diff --git a/pttbbs/util/bbsctl.c b/pttbbs/util/bbsctl.c index bf66df35..62d00300 100644 --- a/pttbbs/util/bbsctl.c +++ b/pttbbs/util/bbsctl.c @@ -4,9 +4,23 @@ #include <string.h> #include <signal.h> #include <sys/types.h> +#include <grp.h> +#ifdef FreeBSD + #include <sys/syslimits.h> + #define PS "/bin/ps" + #define GREP "/usr/bin/grep" + #define SU "/usr/bin/su" +#endif +#ifdef Linux + #include <linux/limits.h> + #define PS "/bin/ps" + #define GREP "/bin/grep" + #define SU "/bin/su" +#endif + void usage(void) { - printf("usage: bbsctl [start|stop|restart]\n"); + printf("usage: bbsctl [start|stop|restart|bbsadm]\n"); exit(0); } @@ -34,8 +48,8 @@ void stopbbs(void) { char buf[1024]; int pid; - FILE *fp = popen("/bin/ps -ax | /usr/bin/grep mbbsd | " - "/usr/bin/grep listen", "r"); + FILE *fp = popen(PS " -ax | " GREP " mbbsd | " + GREP " listen", "r"); while( fgets(buf, sizeof(buf), fp) != NULL ){ sscanf(buf, "%d", &pid); printf("stopping %d\n", pid); @@ -49,15 +63,56 @@ void restartbbs(void) startbbs(); } +void bbsadm(void) +{ + gid_t gids[NGROUPS_MAX]; + int i, ngids; + struct group *gr; + ngids = getgroups(NGROUPS_MAX, gids); + if( (gr = getgrnam("bbsadm")) == NULL ){ + puts("group bbsadm not found"); + return; + } + + for( i = 0 ; i < ngids ; ++i ) + if( gr->gr_gid == gids[i] ) + break; + + if( i == ngids ){ + puts("permission denied"); + return; + } + + if( setuid(0) < 0 ){ + perror("setuid(0)"); + return; + } + puts("permission granted"); + execl(SU, "su", "bbsadm", NULL); +} + +struct { + char *cmd; + void (*func)(); +}cmds[] = { {"start", startbbs}, + {"stop", stopbbs}, + {"restart", restartbbs}, + {"bbsadm", bbsadm}, + {NULL, NULL} }; + int main(int argc, char **argv) { + int i; if( argc == 1 ) usage(); - if( strcmp(argv[1], "start") == 0 ) - startbbs(); - else if( strcmp(argv[1], "stop") == 0 ) - stopbbs(); - else if( strcmp(argv[1], "restart") == 0 ) - restartbbs(); + for( i = 0 ; cmds[i].cmd != NULL ; ++i ) + if( strcmp(cmds[i].cmd, argv[1]) == 0 ){ + cmds[i].func(); + break; + } + if( cmds[i].cmd == NULL ){ + printf("command %s not found\n", argv[1]); + usage(); + } return 0; } -- cgit v1.2.3 From 2859ecd7c4bd6bd228fc10309fad932dce0b7c38 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Fri, 8 Mar 2002 09:21:00 +0000 Subject: no need git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@7 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/daymandex.c | 269 ------------------------------------------------ 1 file changed, 269 deletions(-) delete mode 100644 pttbbs/util/daymandex.c diff --git a/pttbbs/util/daymandex.c b/pttbbs/util/daymandex.c deleted file mode 100644 index d2921d07..00000000 --- a/pttbbs/util/daymandex.c +++ /dev/null @@ -1,269 +0,0 @@ -/* $Id: daymandex.c,v 1.1 2002/03/07 15:13:46 in2 Exp $ */ - -/* - target : 精華區索引程式 (man index) - - syntax : mandex [board] - [board] 有值 ==> 只跑該 board - 空的 ==> 所有的 boards 都跑 -*/ - - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <dirent.h> -#include <unistd.h> -#include <sys/types.h> -#include <sys/stat.h> -#include "config.h" -#include "pttstruct.h" -#include "util.h" - -#ifndef MAXPATHLEN -#define MAXPATHLEN 1024 -#endif - -extern int numboards; -extern boardheader_t *bcache; - -char color[4][10] = -{"", "", "", ""}; -char fn_index[] = ".index"; -char fn_new[] = ".index.new"; -char index_title[] = "◎ 精華區目錄索引"; -FILE *fndx; -int ndir; -int nfile; -int index_pos; -char topdir[128], pgem[512], pndx[512]; - -int nb = 0; /* board 數 */ - -struct boardinfo -{ - char bname[40]; - int ndir; - int nfile; - int k; -}; -typedef struct boardinfo boardinfo; - -boardinfo -board[MAX_BOARD]; - -int k_cmp(b, a) - boardinfo *b, *a; -{ - return ((a->k / 100 + a->ndir + a->nfile) - (b->k / 100 + b->ndir + b->nfile)); -} - -int dashd(fname) - char *fname; -{ - struct stat st; - - return (stat(fname, &st) == 0 && S_ISDIR(st.st_mode)); -} - - -/* visit the hierarchy recursively */ - -void -mandex(level, num_header, fpath) - int level; - char *fpath, *num_header; -{ - FILE *fgem; - char *fname, buf[256]; - struct stat st; - int count; - fileheader_t fhdr; - - fgem = fopen(fpath, "r+"); - if (fgem == NULL) - return; - - fname = strrchr(fpath, '.'); - if (!level) - { - - printf("%s\r\n",fpath); - strcpy(pgem, fpath); - - strcpy(fname, fn_new); - fndx = fopen(fpath, "w"); - if (fndx == NULL) - { - fclose(fgem); - return; - } - fprintf(fndx, "序號\t\t\t精華區主題\n" - "──────────────────────────────────────\n"); - strcpy(pndx, fpath); - ndir = nfile = 0; - index_pos = -1; - } - - count = 0; - while (fread(&fhdr, sizeof(fhdr), 1, fgem) == 1) - { - strcpy(fname, fhdr.filename); - if (!fname[0]) continue; - if (!level && !strncmp(fhdr.title, index_title, strlen(index_title)) - && index_pos < 0) - { - index_pos = count; - unlink(fpath); - } - st.st_size = 0; - stat(fpath, &st); - - sprintf(buf, "%.*s%s%3d. %s \n", - - 11 * level, num_header, color[level % 4], ++count, fhdr.title); /* Ptt */ - fputs(buf, fndx); - if (dashd(fpath)) - { - ++ndir; - if (*fhdr.title != '#' && level < 10) - { - strcat(fpath, "/.DIR"); - mandex(level + 1, buf, fpath); - } - } - else - ++nfile; - } - - if (!level) - { - char lpath[MAXPATHLEN]; - - fclose(fndx); - strcpy(fname, fn_index); - rename(pndx, fpath); - strcpy(pndx, fpath); - - sprintf(buf, "%s.new", pgem); - if (index_pos >= 0 || (fndx = fopen(buf, "w"))) - { - fname[-1] = 0; - stamplink(fpath, &fhdr); - unlink(fpath); - strcpy(fhdr.owner, "每天自動更新"); - sprintf(lpath, "%s/%s", topdir, pndx); - st.st_size = 0; - stat(lpath, &st); - sprintf(fhdr.title, "%s (%.1fk)", index_title, st.st_size / 1024.); - board[nb].k = st.st_size; /* Ptt */ - printf("(%d)[%dK]", nb, board[nb].k); - symlink(lpath, fpath); - if (index_pos < 0) - { - fwrite(&fhdr, sizeof(fhdr), 1, fndx); - rewind(fgem); - while (fread(&fhdr, sizeof(fhdr), 1, fgem) == 1) - fwrite(&fhdr, sizeof(fhdr), 1, fndx); - fclose(fndx); - fclose(fgem); - rename(buf, pgem); - } - else - { - fseek(fgem, index_pos * sizeof(fhdr), 0); - fwrite(&fhdr, sizeof(fhdr), 1, fgem); - fclose(fgem); - } - return; - } - } - fclose(fgem); -} - - -int main(int argc, char* argv[]){ - boardheader_t *bptr; - DIR *dirp; - struct dirent *de; - int ch, n; - int place = 0; - char *fname, fpath[MAXPATHLEN]; - - resolve_boards(); - nb = 0; - if(argc == 1){ - puts("Creating the whole index..."); - chdir(strcpy(topdir, BBSHOME)); - strcpy(fpath, "man/.DIR"); - mandex(0, "", fpath); - } - - - chdir(strcpy(topdir, BBSHOME "/man/boards")); - - if(argc > 1) { - sprintf(fpath, "%s/.DIR", argv[1]); - mandex(0, "", fpath); - exit(0); - } - - /* process all boards */ - - if(!(dirp = opendir(topdir))) { - printf("## unable to enter [man/boards]\n"); - exit(-1); - } - - while((de = readdir(dirp))){ - fname = de->d_name; - ch = fname[0]; - if (ch != '.'){ - board[nb].k = 0; - strcpy(board[nb].bname, fname); - sprintf(fpath, "%s/.rebuild", fname); - if( access(fpath, 0) >= 0 ){ - unlink(fpath); - - sprintf(fpath, "%s/.DIR", fname); - mandex(0, "", fpath); - printf("%-14sd: %d\tf: %d\n", fname, ndir, nfile); - /* report */ - board[nb].ndir = ndir; - board[nb].nfile = nfile; - if (board[nb].k) - nb++; - } - } - } - closedir(dirp); - - qsort(board, nb, sizeof(boardinfo), k_cmp); - - if (!(fndx = fopen(BBSHOME "/etc/topboardman", "w"))) - exit(0); - - fprintf(fndx, "排名 看 版 目錄數 檔案數" - " byte數  總 分 版 主 \n"); - - for (ch = 0; ch < nb; ch++){ - for (n = 0; n < numboards; n++){ - bptr = &bcache[n]; - if (!strcmp(bptr->brdname, board[ch].bname)) - break; - } - if (n >= numboards || - (bptr->brdattr & (BRD_BAD | BRD_NOCOUNT | BRD_HIDE))) - continue; - if (board[ch].ndir + board[ch].nfile < 5) - break; - fprintf(fndx, "%3d.%15s %5d %7d %10d %6d %-24.24s\n", - ++place, - board[ch].bname, - board[ch].ndir, board[ch].nfile, board[ch].k - ,board[ch].k / 100 + board[ch].nfile + board[ch].ndir - ,bptr->BM); - } - fclose(fndx); - exit(0); -} -- cgit v1.2.3 From a708888f83d3a89b38928461f729ea976ec871f3 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Fri, 8 Mar 2002 09:21:15 +0000 Subject: new mandex :) git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@8 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/mandex.c | 232 +++++++++++++++++++++++++++++---------------------- 1 file changed, 132 insertions(+), 100 deletions(-) diff --git a/pttbbs/util/mandex.c b/pttbbs/util/mandex.c index 9373f814..9f5a0e55 100644 --- a/pttbbs/util/mandex.c +++ b/pttbbs/util/mandex.c @@ -1,19 +1,13 @@ -/* $Id: mandex.c,v 1.1 2002/03/07 15:13:46 in2 Exp $ */ - -/* - target : 精華區索引程式 (man index) - - syntax : mandex [board] - [board] 有值 ==> 只跑該 board - 空的 ==> 所有的 boards 都跑 -*/ +/* $Id: mandex.c,v 1.2 2002/03/08 09:21:15 in2 Exp $ */ +/* 'mandex -h' to help */ #include <stdio.h> #include <stdlib.h> #include <string.h> #include <dirent.h> #include <unistd.h> +#include <fcntl.h> #include <sys/types.h> #include <sys/stat.h> #include "config.h" @@ -24,33 +18,28 @@ #define MAXPATHLEN 1024 #endif -extern int numboards; -extern boardheader_t *bcache; - -char color[4][10] = -{"", "", "", ""}; -char fn_index[] = ".index"; -char fn_new[] = ".index.new"; -char index_title[] = "◎ 精華區目錄索引"; -FILE *fndx; -int ndir; -int nfile; -int index_pos; -char topdir[128], pgem[512], pndx[512]; - -int nb = 0; /* board 數 */ - -struct boardinfo +typedef struct { char bname[40]; - int ndir; - int nfile; - int k; -}; -typedef struct boardinfo boardinfo; + int ndir, nfile, k; +} boardinfo; -boardinfo -board[MAX_BOARD]; +extern int numboards; +extern boardheader_t *bcache; +boardinfo board[MAX_BOARD], *biptr; +char color[4][10] = {"", "", "", ""}; +char fn_index[] = ".index"; +char fn_new[] = ".index.new"; +char index_title[] = "◎ 精華區目錄索引"; +char topdir[128], pgem[512], pndx[512]; +FILE *fndx; +int ndir, nfile, index_pos, k; +int nSorted, nb; + +int sortbyname(const void *a, const void *b) +{ + return strcmp(((boardinfo*)b)->bname, ((boardinfo*)a)->bname); +} int k_cmp(b, a) boardinfo *b, *a; @@ -85,34 +74,30 @@ mandex(level, num_header, fpath) return; fname = strrchr(fpath, '.'); - if (!level) - { - + if (!level){ printf("%s\r\n",fpath); strcpy(pgem, fpath); strcpy(fname, fn_new); fndx = fopen(fpath, "w"); - if (fndx == NULL) - { + if (fndx == NULL){ fclose(fgem); return; } fprintf(fndx, "序號\t\t\t精華區主題\n" - "──────────────────────────────────────\n"); + "───────────────────" + "───────────────────\n"); strcpy(pndx, fpath); ndir = nfile = 0; index_pos = -1; } count = 0; - while (fread(&fhdr, sizeof(fhdr), 1, fgem) == 1) - { + while (fread(&fhdr, sizeof(fhdr), 1, fgem) == 1){ strcpy(fname, fhdr.filename); if (!fname[0]) continue; if (!level && !strncmp(fhdr.title, index_title, strlen(index_title)) - && index_pos < 0) - { + && index_pos < 0){ index_pos = count; unlink(fpath); } @@ -120,14 +105,12 @@ mandex(level, num_header, fpath) stat(fpath, &st); sprintf(buf, "%.*s%s%3d. %s \n", - - 11 * level, num_header, color[level % 4], ++count, fhdr.title); /* Ptt */ + 11 * level, num_header, color[level % 4], ++count, fhdr.title); + /* Ptt */ fputs(buf, fndx); - if (dashd(fpath)) - { + if (dashd(fpath)){ ++ndir; - if (*fhdr.title != '#' && level < 10) - { + if (*fhdr.title != '#' && level < 10){ strcat(fpath, "/.DIR"); mandex(level + 1, buf, fpath); } @@ -136,8 +119,7 @@ mandex(level, num_header, fpath) ++nfile; } - if (!level) - { + if (!level){ char lpath[MAXPATHLEN]; fclose(fndx); @@ -146,8 +128,7 @@ mandex(level, num_header, fpath) strcpy(pndx, fpath); sprintf(buf, "%s.new", pgem); - if (index_pos >= 0 || (fndx = fopen(buf, "w"))) - { + if (index_pos >= 0 || (fndx = fopen(buf, "w"))){ fname[-1] = 0; stamplink(fpath, &fhdr); unlink(fpath); @@ -156,11 +137,10 @@ mandex(level, num_header, fpath) st.st_size = 0; stat(lpath, &st); sprintf(fhdr.title, "%s (%.1fk)", index_title, st.st_size / 1024.); - board[nb].k = st.st_size; /* Ptt */ - printf("(%d)[%dK]", nb, board[nb].k); + k = st.st_size; /* Ptt */ + printf("(%s)[%dK]", fpath, k); symlink(lpath, fpath); - if (index_pos < 0) - { + if (index_pos < 0){ fwrite(&fhdr, sizeof(fhdr), 1, fndx); rewind(fgem); while (fread(&fhdr, sizeof(fhdr), 1, fgem) == 1) @@ -169,8 +149,7 @@ mandex(level, num_header, fpath) fclose(fgem); rename(buf, pgem); } - else - { + else{ fseek(fgem, index_pos * sizeof(fhdr), 0); fwrite(&fhdr, sizeof(fhdr), 1, fgem); fclose(fgem); @@ -182,58 +161,111 @@ mandex(level, num_header, fpath) } -int main(int argc, char* argv[]){ +int main(int argc, char* argv[]) +{ boardheader_t *bptr; - DIR *dirp; - struct dirent *de; - int ch, n; - int place = 0; - char *fname, fpath[MAXPATHLEN]; - + DIR *dirp; + struct dirent *de; + int ch, n, place = 0, fd; + char checkrebuild = 0, *fname, fpath[MAXPATHLEN]; + + while( (ch = getopt(argc, argv, "x")) != -1 ){ + switch( ch ){ + case 'x': + checkrebuild = 1; + break; + case 'h': + printf("NAME \n" + " mandex - 精華區索引程式 (man index)\n\n" + "SYNOPSIS \n" + " mandex [-x] [board] \n\n" + "DESCRIPTION \n" + "精華區索引 (man index) \n\n" + "-x 只有含有 .rebuild的目錄才重製 \n" + "board 全部的板 (default to all) \n\n"); + return 0; + } + } + + argc -= optind; + argv += optind; + resolve_boards(); - nb = 0; - if(argc == 1){ + + if( argc == 0 ){ puts("Creating the whole index..."); - chdir(strcpy(topdir, BBSHOME)); - strcpy(fpath, "man/.DIR"); - mandex(0, "", fpath); + chdir(strcpy(topdir, BBSHOME)); + strcpy(fpath, "man/.DIR"); + mandex(0, "", fpath); } - - + chdir(strcpy(topdir, BBSHOME "/man/boards")); - if(argc > 1) { - sprintf(fpath, "%s/.DIR", argv[1]); - mandex(0, "", fpath); - exit(0); + if( argc == 1 ){ + sprintf(fpath, "%s/.DIR", argv[0]); + mandex(0, "", fpath); + return 0; } /* process all boards */ - - if(!(dirp = opendir(topdir))) { - printf("## unable to enter [man/boards]\n"); - exit(-1); - } - - while((de = readdir(dirp))){ - fname = de->d_name; - ch = fname[0]; - if (ch != '.'){ - board[nb].k = 0; - strcpy(board[nb].bname, fname); - sprintf(fpath, "%s/.DIR", fname); - mandex(0, "", fpath); - printf("%-14sd: %d\tf: %d\n", fname, ndir, nfile); /* report */ - board[nb].ndir = ndir; - board[nb].nfile = nfile; - if (board[nb].k) - nb++; + if( checkrebuild && + (fd = open(BBSHOME "/man/.rank.cache", O_RDONLY)) >= 0 ){ + read(fd, board, sizeof(board)); + close(fd); + qsort(board, MAX_BOARD, sizeof(boardinfo), sortbyname); + for( nb = 0 ; board[nb].bname[0] != 0 ; ++nb ) + ; + nSorted = nb; + } + else{ + memset(board, 0, sizeof(board)); + checkrebuild = 0; + nSorted = nb = 0; + } + + if(!(dirp = opendir(topdir))) { + printf("## unable to enter [man/boards]\n"); + exit(-1); + } + + while((de = readdir(dirp))){ + fname = de->d_name; + ch = fname[0]; + if (ch != '.'){ + k = 0; + if( checkrebuild ){ + sprintf(fpath, "%s/.rebuild", fname); + if( access(fpath, 0) < 0 ){ + printf("skip no modify board %s\n", fname); + continue; + } + unlink(fpath); + } + sprintf(fpath, "%s/.DIR", fname); + mandex(0, "", fpath); + printf("%-14sd: %d\tf: %d\n", fname, ndir, nfile); /* report */ + if( k ){ + if( !(biptr = bsearch(fname, board, nSorted, + sizeof(boardinfo), sortbyname))){ + biptr = &board[nb]; + ++nb; + } + strcpy(biptr->bname, fname); + biptr->ndir = ndir; + biptr->nfile = nfile; + biptr->k = k; } } - closedir(dirp); - - qsort(board, nb, sizeof(boardinfo), k_cmp); + } + closedir(dirp); + qsort(board, nb, sizeof(boardinfo), k_cmp); + unlink(BBSHOME "/man/.rank.cache"); + if( (fd = open(BBSHOME "/man/.rank.cache", + O_WRONLY | O_CREAT | O_TRUNC | O_APPEND, 0660)) >= 0 ){ + write(fd, board, sizeof(board)); + close(fd); + } if (!(fndx = fopen(BBSHOME "/etc/topboardman", "w"))) exit(0); @@ -259,5 +291,5 @@ int main(int argc, char* argv[]){ ,bptr->BM); } fclose(fndx); - exit(0); + return 0; } -- cgit v1.2.3 From 395dc96ca26ab460a1c5d934d299e98d29cd0e5b Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Fri, 8 Mar 2002 09:22:02 +0000 Subject: no need daymandex git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@9 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/Makefile | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/pttbbs/util/Makefile b/pttbbs/util/Makefile index 9ef46a2f..41f7326f 100644 --- a/pttbbs/util/Makefile +++ b/pttbbs/util/Makefile @@ -1,4 +1,4 @@ -# $Id: Makefile,v 1.2 2002/03/07 18:01:57 in2 Exp $ +# $Id: Makefile,v 1.3 2002/03/08 09:22:02 in2 Exp $ BBSHOME?=$(HOME) OSTYPE=linux @@ -30,7 +30,7 @@ CPROGS= bbsmail BM_money post account birth deluserfile expire mandex\ poststat showboard antispam countalldice webgrep bbsrf\ initbbs outmail xchatd userlist tunepasswd buildir reaper shmsweep\ merge_passwd merge_board inndBM buildAnnounce rmuid cpdeadbrd \ - toplazyBM jungo toplazyBBM daymandex + toplazyBM jungo toplazyBBM PROGS= $(CPROGS) BM_money.sh backpasswd.sh mailog.sh opendice.sh\ openticket.sh stock.sh topsong.sh weather.sh stock.perl weather.perl\ @@ -65,9 +65,6 @@ expire: expire.c $(OBJS) mandex: mandex.c $(OBJS) $(CC) $(CFLAGS) -o $@ $@.c $(OBJS) -daymandex: daymandex.c $(OBJS) - $(CC) $(CFLAGS) -o $@ $@.c $(OBJS) - rmuid: rmuid.c $(OBJS) $(CC) $(CFLAGS) -o $@ $@.c $(OBJS) -- cgit v1.2.3 From b8fc748bae24ddcf1e75fff241fbd3ec7cef0e37 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sat, 9 Mar 2002 02:12:21 +0000 Subject: :) git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@10 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/in2outmail | Bin 39392 -> 0 bytes pttbbs/util/in2outmail.c | 288 ----------------------------------------------- 2 files changed, 288 deletions(-) delete mode 100644 pttbbs/util/in2outmail delete mode 100644 pttbbs/util/in2outmail.c diff --git a/pttbbs/util/in2outmail b/pttbbs/util/in2outmail deleted file mode 100644 index 686944c1..00000000 Binary files a/pttbbs/util/in2outmail and /dev/null differ diff --git a/pttbbs/util/in2outmail.c b/pttbbs/util/in2outmail.c deleted file mode 100644 index fce9cc59..00000000 --- a/pttbbs/util/in2outmail.c +++ /dev/null @@ -1,288 +0,0 @@ -/* $Id: in2outmail.c,v 1.1 2002/03/07 15:13:46 in2 Exp $ */ -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <unistd.h> -#include <fcntl.h> -#include <signal.h> -#include <sys/types.h> -#include <sys/socket.h> -#include <sys/types.h> -#include <sys/param.h> -#include <sys/file.h> -#include <netinet/in.h> -#include <arpa/inet.h> -#include "config.h" -#include "pttstruct.h" - - -#ifdef HAVE_SETPROCTITLE - -#include <sys/types.h> -#include <libutil.h> - -void initsetproctitle(int argc, char **argv, char **envp) { -} - -#else - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <stdarg.h> - -char **Argv = NULL; /* pointer to argument vector */ -char *LastArgv = NULL; /* end of argv */ -extern char **environ; - -void initsetproctitle(int argc, char **argv, char **envp) { - register int i; - - /* Move the environment so setproctitle can use the space at - the top of memory. */ - for(i = 0; envp[i]; i++); - environ = malloc(sizeof(char *) * (i + 1)); - for(i = 0; envp[i]; i++) - environ[i] = strdup(envp[i]); - environ[i] = NULL; - - /* Save start and extent of argv for setproctitle. */ - Argv = argv; - if(i > 0) - LastArgv = envp[i - 1] + strlen(envp[i - 1]); - else - LastArgv = argv[argc - 1] + strlen(argv[argc - 1]); -} - -static void do_setproctitle(const char *cmdline) { - char buf[256], *p; - int i; - - strncpy(buf, cmdline, 256); - buf[255] = '\0'; - i = strlen(buf); - if(i > LastArgv - Argv[0] - 2) { - i = LastArgv - Argv[0] - 2; - } - strcpy(Argv[0], buf); - p = &Argv[0][i]; - while(p < LastArgv) - *p++='\0'; - Argv[1] = NULL; -} - -void setproctitle(const char* format, ...) { - char buf[256]; - - va_list args; - va_start(args, format); - vsprintf(buf, format,args); - do_setproctitle(buf); - va_end(args); -} -#endif - - - - - -#define SPOOL BBSHOME "/out" -#define INDEX SPOOL "/.DIR" -#define NEWINDEX SPOOL "/.DIR.sending" -#define FROM ".bbs@" MYHOSTNAME -#define SMTPPORT 25 - -int waitReply(int sock) { - char buf[256]; - - if(read(sock, buf, sizeof(buf)) <= 0) - return -1; - else - return buf[0] - '0'; -} - -int sendRequest(int sock, char *request) { - return write(sock, request, strlen(request)) < 0 ? -1 : 0; -} - -int connectMailServer(char *host) { - int sock; - struct sockaddr_in addr; - - if((sock = socket(PF_INET, SOCK_STREAM, 0)) < 0) { - perror("socket"); - return -1; - } - - memset(&addr, 0, sizeof(addr)); -#ifdef FreeBSD - addr.sin_len = sizeof(addr); -#endif - addr.sin_family = AF_INET; - addr.sin_port = htons(SMTPPORT); - addr.sin_addr.s_addr = inet_addr(host); - - if(connect(sock, (struct sockaddr *)&addr, sizeof(addr)) < 0) { - perror(RELAY_SERVER_IP); - close(sock); - return -1; - } - - if(waitReply(sock) != 2) { - close(sock); - return -1; - } - - if(sendRequest(sock, "helo " MYHOSTNAME "\n") || waitReply(sock) != 2) { - close(sock); - return -1; - } else - return sock; -} - -void disconnectMailServer(int sock) { - sendRequest(sock, "quit\n"); - /* drop the reply :p */ - close(sock); -} - -void doSendBody(int sock, FILE *fp, char *from, char *to, char *subject) { - int n; - char buf[2048]; - - n = snprintf(buf, sizeof(buf), "From: %s\nTo: %s\nSubject: %s\n\n", - from, to, subject); - write(sock, buf, n); - - while(fgets(buf, sizeof(buf), fp)) { - if(buf[0] == '.' && buf[1] == '\n') - strcpy(buf, "..\n"); - write(sock, buf, strlen(buf)); - } -} - -void doSendMail(int sock, FILE *fp, char *from, char *to, char *subject) { - char buf[256]; - - snprintf(buf, sizeof(buf), "mail from: %s\n", from); - if(sendRequest(sock, buf) || waitReply(sock) != 2) - return; - - snprintf(buf, sizeof(buf), "rcpt to: %s\n", to); - if(sendRequest(sock, buf) || waitReply(sock) != 2) - return; - - if(sendRequest(sock, "data\n") || waitReply(sock) != 3) - return; - - doSendBody(sock, fp, from, to, subject); - - if(sendRequest(sock, "\n.\n") || waitReply(sock) != 2) - return; -} - -void sendMail() { - int fd, sockPTT2, sockHinet; - MailQueue mq; - - if(access(NEWINDEX, R_OK | W_OK)) { - if(link(INDEX, NEWINDEX) || unlink(INDEX)) - /* nothing to do */ - return; - } - - if( (sockPTT2 = connectMailServer("140.112.30.143")) < 0 ){ - fprintf(stderr, "connect server failed...\n"); - return; - } - sockHinet = connectMailServer("61.218.59.183"); - - fd = open(NEWINDEX, O_RDONLY); - flock(fd, LOCK_EX); - while(read(fd, &mq, sizeof(mq)) > 0) { - FILE *fp; - char buf[256]; - - snprintf(buf, sizeof(buf), "%s%s", mq.sender, FROM); - if((fp = fopen(mq.filepath, "r"))) { - setproctitle("outmail: sending %s", mq.filepath); - if( strstr(mq.rcpt, ".edu.tw") || - strstr(mq.rcpt, ".twbbs.org") || - strstr(mq.rcpt, "ptt.cc") || - strstr(mq.rcpt, "ptt2.cc") ){ - printf("relay server: ptt2, to %s\n", mq.rcpt); - doSendMail(sockPTT2, fp, buf, mq.rcpt, mq.subject); - } - else{ - printf("relay server: ezmain, to %s\n", mq.rcpt); - doSendMail( (sockHinet > 0) ? sockHinet : sockPTT2, - fp, buf, mq.rcpt, mq.subject); - } - fclose(fp); - unlink(mq.filepath); - } else { - perror(mq.filepath); - } - } - flock(fd, LOCK_UN); - close(fd); - unlink(NEWINDEX); - - if( sockHinet > 0 ) - disconnectMailServer(sockHinet); - disconnectMailServer(sockPTT2); -} - -void listQueue() { - int fd; - - if((fd = open(INDEX, O_RDONLY)) >= 0) { - int counter = 0; - MailQueue mq; - - flock(fd, LOCK_EX); - while(read(fd, &mq, sizeof(mq)) > 0) { - printf("%s:%s -> %s:%s\n", mq.filepath, mq.username, mq.rcpt, - mq.subject); - counter++; - } - flock(fd, LOCK_UN); - close(fd); - printf("\nTotal: %d mails in queue\n", counter); - } else { - perror(INDEX); - } -} - -void usage() { - fprintf(stderr, "usage: outmail [-qh]\n"); -} - -void wakeup(int s) { -} - -int main(int argc, char **argv, char **envp) { - int ch; - - signal(SIGHUP, wakeup); - initsetproctitle(argc, argv, envp); - - if(chdir(BBSHOME)) - return 1; - while((ch = getopt(argc, argv, "qh")) != -1) { - switch(ch) { - case 'q': - listQueue(); - return 0; - default: - usage(); - return 0; - } - } - for(;;) { - sendMail(); - setproctitle("outmail: sleeping"); - sleep(60 * 3); /* send mail every 3 minute */ - } - return 0; -} -- cgit v1.2.3 From 3bb7a517709800895c6563d815accfd08e61f3fe Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sat, 9 Mar 2002 10:34:58 +0000 Subject: ofo's water show 'x' for dead users my_write() input uin if already got it git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@11 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/include/proto.h | 4 +-- pttbbs/include/pttstruct.h | 25 ++++++++--------- pttbbs/mbbsd/friend.c | 4 +-- pttbbs/mbbsd/io.c | 4 +-- pttbbs/mbbsd/mbbsd.c | 67 ++++++++++++++++++++++++++-------------------- pttbbs/mbbsd/talk.c | 28 ++++++++++++------- 6 files changed, 76 insertions(+), 56 deletions(-) diff --git a/pttbbs/include/proto.h b/pttbbs/include/proto.h index 8122f5d5..5247ac7f 100644 --- a/pttbbs/include/proto.h +++ b/pttbbs/include/proto.h @@ -1,4 +1,4 @@ -/* $Id: proto.h,v 1.1 2002/03/07 15:13:48 in2 Exp $ */ +/* $Id: proto.h,v 1.2 2002/03/09 10:34:56 in2 Exp $ */ #ifndef INCLUDE_PROTO_H #define INCLUDE_PROTO_H @@ -416,7 +416,7 @@ char *modestring(userinfo_t * uentp, int simple); int isvisible(userinfo_t * me, userinfo_t * uentp); int t_users(); int cmpuids(int uid, userinfo_t * urec); -int my_write(pid_t pid, char *hint, char *id, int flag); +int my_write(pid_t pid, char *hint, char *id, int flag, userinfo_t *); void t_display_new(); void talkreply(); int t_monitor(); diff --git a/pttbbs/include/pttstruct.h b/pttbbs/include/pttstruct.h index 76a196a9..ea1e7d78 100644 --- a/pttbbs/include/pttstruct.h +++ b/pttbbs/include/pttstruct.h @@ -1,4 +1,4 @@ -/* $Id: pttstruct.h,v 1.1 2002/03/07 15:13:48 in2 Exp $ */ +/* $Id: pttstruct.h,v 1.2 2002/03/09 10:34:56 in2 Exp $ */ #ifndef INCLUDE_STRUCT_H #define INCLUDE_STRUCT_H @@ -191,23 +191,16 @@ typedef struct { int num, page, now, level; } gmenu_t; +#define FAVMAX 74 /* Max boards of Myfavorite */ +#define FAVGMAX 16 /* Max groups of Myfavorite */ +#define FAVGSLEN 8 /* Max Length of Description String */ + typedef struct msgque_t { pid_t pid; char userid[IDLEN + 1]; char last_call_in[80]; } msgque_t; -typedef struct water_t { - pid_t pid; - char userid[IDLEN + 1]; - msgque_t msg[MAX_REVIEW]; - int top, count; -} water_t; - -#define FAVMAX 74 /* Max boards of Myfavorite */ -#define FAVGMAX 16 /* Max groups of Myfavorite */ -#define FAVGSLEN 8 /* Max Length of Description String */ - typedef struct userinfo_t { int uid; /* Used to find user name in passwd file */ pid_t pid; /* kill() to notify user of talk request */ @@ -258,6 +251,14 @@ typedef struct userinfo_t { int mind; } userinfo_t; +typedef struct water_t { + pid_t pid; + char userid[IDLEN + 1], alive; + int top, count; + msgque_t msg[MAX_REVIEW]; + userinfo_t *uin; +} water_t; + typedef struct { fileheader_t *header; char mtitle[STRLEN]; diff --git a/pttbbs/mbbsd/friend.c b/pttbbs/mbbsd/friend.c index 3d2167ae..a51d3000 100644 --- a/pttbbs/mbbsd/friend.c +++ b/pttbbs/mbbsd/friend.c @@ -1,4 +1,4 @@ -/* $Id: friend.c,v 1.1 2002/03/07 15:13:48 in2 Exp $ */ +/* $Id: friend.c,v 1.2 2002/03/09 10:34:58 in2 Exp $ */ #include <stdio.h> #include <string.h> #include <stdlib.h> @@ -330,7 +330,7 @@ static void friend_water(char *message, int type) { /* if((tuid = searchuser(userid)) && tuid != usernum && (uentp = (userinfo_t *) search_ulist(tuid)) && isvisible_uid(tuid)) - my_write(uentp->pid, message, uentp->userid, 1); + my_write(uentp->pid, message, uentp->userid, 1, NULL); } fclose(fp); } diff --git a/pttbbs/mbbsd/io.c b/pttbbs/mbbsd/io.c index e3d03b9b..1f13ffeb 100644 --- a/pttbbs/mbbsd/io.c +++ b/pttbbs/mbbsd/io.c @@ -1,4 +1,4 @@ -/* $Id: io.c,v 1.1 2002/03/07 15:13:48 in2 Exp $ */ +/* $Id: io.c,v 1.2 2002/03/09 10:34:58 in2 Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -259,7 +259,7 @@ int igetch() { show_last_call_in(0); watermode = 0; my_write(currutmp->msgs[0].pid, "水球丟過去 : ", - currutmp->msgs[0].userid, 0); + currutmp->msgs[0].userid, 0, NULL); i_newfd = my_newfd; /* 還原螢幕 */ diff --git a/pttbbs/mbbsd/mbbsd.c b/pttbbs/mbbsd/mbbsd.c index c4849da5..85f29642 100644 --- a/pttbbs/mbbsd/mbbsd.c +++ b/pttbbs/mbbsd/mbbsd.c @@ -1,4 +1,4 @@ -/* $Id: mbbsd.c,v 1.1 2002/03/07 15:13:48 in2 Exp $ */ +/* $Id: mbbsd.c,v 1.2 2002/03/09 10:34:58 in2 Exp $ */ #include <stdio.h> #include <string.h> #include <stdlib.h> @@ -349,9 +349,15 @@ extern unsigned int currstat; water_t water[6], *swater[6], *water_which=&water[0]; char water_usies=0; extern int watermode; -static int add_history_water(water_t *w, msgque_t *msg) +static int add_history_water(water_t *w, msgque_t *msg, char mode) { - memcpy(&w->msg[w->top], msg, sizeof(msgque_t)); + // mode: 1: all data(including userid, pid); + // 0: only last_call_in + if( mode ) + memcpy(&w->msg[w->top], msg, sizeof(msgque_t)); + else + memcpy(&w->msg[w->top].last_call_in, msg->last_call_in, + sizeof(msg->last_call_in)); w->top++; w->top %= WATERMODE(WATER_OFO) ? 5 : MAX_REVIEW; @@ -364,34 +370,37 @@ static int add_history_water(water_t *w, msgque_t *msg) static int add_history(msgque_t *msg) { - int i,j; + int i = 0, j; water_t *tmp; - add_history_water(&water[0], msg); - for(i = 0 ; i < 5 && swater[i] ; i++ ) - if( swater[i]->pid == msg->pid ) - break; - if( i != 5 ){ - if( !swater[i] ){ - water_usies = i + 1; - swater[i] = &water[i + 1]; - strcpy(swater[i]->userid, msg->userid); - swater[i]->pid = msg->pid; + if( WATERMODE(WATER_ORIG) || WATERMODE(WATER_NEW) ) + add_history_water(&water[0], msg, 1); + if( WATERMODE(WATER_NEW) || WATERMODE(WATER_OFO) ){ + for(i = 0 ; i < 5 && swater[i] ; i++ ) + if( swater[i]->pid == msg->pid ) + break; + if( i != 5 ){ + if( !swater[i] ){ + water_usies = i + 1; + swater[i] = &water[i + 1]; + strcpy(swater[i]->userid, msg->userid); + swater[i]->pid = msg->pid; + } + tmp = swater[i]; } - tmp = swater[i]; - } - else{ - tmp = swater[4]; - memset(swater[4], 0, sizeof (water_t)); - strcpy(swater[4]->userid, msg->userid); - swater[4]->pid = msg->pid; - i = 4; + else{ + tmp = swater[4]; + memset(swater[4], 0, sizeof (water_t)); + strcpy(swater[4]->userid, msg->userid); + swater[4]->pid = msg->pid; + i = 4; + } + + for( j = i ; j > 0 ; j-- ) + swater[j] = swater[j - 1]; + swater[0] = tmp; + add_history_water(swater[0], msg, 0); } - - for( j = i ; j > 0 ; j-- ) - swater[j] = swater[j - 1]; - swater[0] = tmp; - add_history_water(swater[0], msg); - + if(WATERMODE(WATER_ORIG) || WATERMODE(WATER_NEW) ){ if( watermode > 0 && (water_which == swater[0] || water_which == &water[0]) ){ @@ -1015,7 +1024,7 @@ do_aloha (char *hello) if ((tuid = searchuser (userid)) && tuid != usernum && (uentp = (userinfo_t *) search_ulist (tuid)) && isvisible(uentp, currutmp)){ - my_write (uentp->pid, genbuf, uentp->userid, 2); + my_write (uentp->pid, genbuf, uentp->userid, 2, NULL); } } fclose (fp); diff --git a/pttbbs/mbbsd/talk.c b/pttbbs/mbbsd/talk.c index 3012b2d2..b5c99aad 100644 --- a/pttbbs/mbbsd/talk.c +++ b/pttbbs/mbbsd/talk.c @@ -1,4 +1,4 @@ -/* $Id: talk.c,v 1.1 2002/03/07 15:13:48 in2 Exp $ */ +/* $Id: talk.c,v 1.2 2002/03/09 10:34:58 in2 Exp $ */ #include <stdio.h> #include <string.h> #include <errno.h> @@ -466,7 +466,9 @@ void water_scr(water_t **currwater, int which, char type) int colors[] = {33, 37, 33, 37, 33}; move(8 + which, 28);prints(" "); move(8 + which, 28); - prints("\033[1;37;45m %-14s \033[0m", currwater[which]->userid); + prints("\033[1;37;45m %c %-14s \033[0m", + currwater[which]->alive ? ' ' : 'x', + currwater[which]->userid); for( i = 0 ; i < 5 ; ++i ){ move(16 + i, 4); prints(" "); @@ -489,7 +491,9 @@ void water_scr(water_t **currwater, int which, char type) prints("123456789012345678901234567890"); // refresh(); move(8 + which, 28); - prints("\033[1;37;44m %-13s \033[0m", currwater[which]->userid); + prints("\033[1;37;44m %c %-13s \033[0m", + currwater[which]->alive ? ' ' : 'x', + currwater[which]->userid); // refresh(); } } @@ -517,8 +521,14 @@ void my_write2(void) for( i = 0 ; i < 5 ; ++i ) if( currwater[i] == NULL || currwater[i]->pid == 0 ) break; - else + else{ + if( currwater[i]->uin == NULL ) + currwater[i]->uin = + (userinfo_t *)search_ulist_pid(currwater[i]->pid); + currwater[i]->alive = (strcmp(currwater[i]->userid, + currwater[i]->uin->userid) == 0); water_scr(currwater, i, 0); + } move(15, 4); prints("\033[0m \033[1;35m◇\033[1;36m────────────────" "─────────────────\033[1;35m◇\033[0m "); @@ -575,7 +585,7 @@ void my_write2(void) 80-strlen(tw->userid)-6, DOECHO) ) break; - my_write(tw->pid, msg, tw->userid, 4); + my_write(tw->pid, msg, tw->userid, 4, tw->uin); break; } } while( !done ); @@ -595,7 +605,7 @@ void my_write2(void) 5. 丟水球 flag = 0 6. my_write2 flag = 4 (pre-edit) but confirm */ -int my_write(pid_t pid, char *prompt, char *id, int flag) { +int my_write(pid_t pid, char *prompt, char *id, int flag, userinfo_t *puin) { int len, currstat0 = currstat, fri_stat; char msg[80], destid[IDLEN + 1]; char genbuf[200], buf[200], c0 = currutmp->chatid[0]; @@ -603,7 +613,7 @@ int my_write(pid_t pid, char *prompt, char *id, int flag) { time_t now; struct tm *ptime; userinfo_t *uin; - uin = (userinfo_t *)search_ulist_pid(pid); + uin = (puin != NULL) ? puin : (userinfo_t *)search_ulist_pid(pid); strcpy(destid, id); if(!uin && !(flag == 0 && water_which->count> 0)) { @@ -2107,7 +2117,7 @@ static void pickup_user() { (HAS_PERM(PERM_SYSOP) || (uentp->pager != 3 && (uentp->pager != 4 || fri_stat & HFM)))) - my_write(uentp->pid, genbuf, uentp->userid, HAS_PERM(PERM_SYSOP) ? 3 : 1); + my_write(uentp->pid, genbuf, uentp->userid, HAS_PERM(PERM_SYSOP) ? 3 : 1, NULL); } } break; @@ -2206,7 +2216,7 @@ static void pickup_user() { { cursor_show(num + 3 - head, 0); sprintf(genbuf, "Call-In %s :", uentp->userid); - my_write(uentp->pid, genbuf, uentp->userid, 0); + my_write(uentp->pid, genbuf, uentp->userid, 0, NULL); } } else if (ch == 'l') -- cgit v1.2.3 From 407a780bab80efd6379cecb8b0b6cea9a95796c6 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sat, 9 Mar 2002 11:48:32 +0000 Subject: add help for W git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@12 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/talk.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pttbbs/mbbsd/talk.c b/pttbbs/mbbsd/talk.c index b5c99aad..32292a75 100644 --- a/pttbbs/mbbsd/talk.c +++ b/pttbbs/mbbsd/talk.c @@ -1,4 +1,4 @@ -/* $Id: talk.c,v 1.2 2002/03/09 10:34:58 in2 Exp $ */ +/* $Id: talk.c,v 1.3 2002/03/09 11:48:32 in2 Exp $ */ #include <stdio.h> #include <string.h> #include <errno.h> @@ -1527,6 +1527,7 @@ static void t_showhelp() { outs("\n\n\033[36m【 交談專用鍵 】\033[m\n\n" "(→)(t)(Enter) 跟他/她聊天\n" "(w) 熱線 Call in\n" + "(W)切換水球方式 一般 / 進階 / 未來\n" "(b) 對好友廣播 (一定要在好友列表中)\n" "(^R) 即時回應 (有人 Call in 你時)"); } -- cgit v1.2.3 From a5e2f45168c77fbdf6fbbdeb918ba0f9f4ccc07a Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sat, 9 Mar 2002 16:54:32 +0000 Subject: fix bug git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@13 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/talk.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pttbbs/mbbsd/talk.c b/pttbbs/mbbsd/talk.c index 32292a75..b59330a9 100644 --- a/pttbbs/mbbsd/talk.c +++ b/pttbbs/mbbsd/talk.c @@ -1,4 +1,4 @@ -/* $Id: talk.c,v 1.3 2002/03/09 11:48:32 in2 Exp $ */ +/* $Id: talk.c,v 1.4 2002/03/09 16:54:32 in2 Exp $ */ #include <stdio.h> #include <string.h> #include <errno.h> @@ -657,7 +657,6 @@ int my_write(pid_t pid, char *prompt, char *id, int flag, userinfo_t *puin) { len = strlen(msg); } - watermode = -1; strip_ansi(msg, msg, 0); if(uin && *uin->userid && (flag == 0 || flag == 4)) { sprintf(buf, "丟給 %s : %s [Y/n]?", uin->userid, msg); @@ -674,6 +673,7 @@ int my_write(pid_t pid, char *prompt, char *id, int flag, userinfo_t *puin) { } } + watermode = -1; if(!uin || !*uin->userid || strcasecmp(destid, uin->userid)) { outmsg("\033[1;33;41m糟糕! 對方已落跑了(不在站上)! \033[37m~>_<~\033[m"); clrtoeol(); -- cgit v1.2.3 From 47961d5b9d45d0166ca956eb214d1d0ea843ffc5 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sat, 9 Mar 2002 17:19:16 +0000 Subject: -.-" git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@14 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/cpdeadbrd.c | 41 ----------------------------------------- 1 file changed, 41 deletions(-) delete mode 100644 pttbbs/util/cpdeadbrd.c diff --git a/pttbbs/util/cpdeadbrd.c b/pttbbs/util/cpdeadbrd.c deleted file mode 100644 index 12c5827e..00000000 --- a/pttbbs/util/cpdeadbrd.c +++ /dev/null @@ -1,41 +0,0 @@ -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <dirent.h> -#include <unistd.h> -#include <sys/types.h> -#include <sys/stat.h> -#include <unistd.h> -#include "config.h" -#include "pttstruct.h" -#include "util.h" - -extern int numboards; -extern boardheader_t *bcache; -int main(int argc, char* argv[]){ -struct stat st; -boardheader_t *bptr; - int n; - char pathname[1024]; - - resolve_boards(); - for (n=numboards-1;n>0;n--) - { - - bptr = &bcache[n]; - if(!strcmp(bptr->brdname,"ck53rd316"))continue; - sprintf(pathname,"/home/bbs/boards/%s/.DIR",bptr->brdname); - if(stat(pathname, &st) == -1) - { - printf("%s is dead\n",pathname); - sprintf (pathname,"cp -R /mnt/bbs/boards/%s /home/bbs/boards/%s",bptr->brdname,bptr->brdname); - } - } -} - - - - - - - -- cgit v1.2.3 From feb2a8348cc3752f356157d97420f7d1d2e7322a Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sat, 9 Mar 2002 17:29:36 +0000 Subject: boards/<hash>/<brdname> git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@15 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/innbbsd/bbslink.c | 20 +++++------ pttbbs/innbbsd/bbslink2.c | 22 ++++++------ pttbbs/innbbsd/receive_article.c | 32 +++++++++--------- pttbbs/mbbsd/admin.c | 13 +++---- pttbbs/mbbsd/announce.c | 10 +++--- pttbbs/mbbsd/cache.c | 6 ++-- pttbbs/mbbsd/gamble.c | 4 +-- pttbbs/mbbsd/record.c | 6 ++-- pttbbs/mbbsd/stuff.c | 12 +++---- pttbbs/mbbsd/syspost.c | 14 ++++---- pttbbs/mbbsd/user.c | 6 ++-- pttbbs/mbbsd/vote.c | 6 ++-- pttbbs/util/account.c | 6 ++-- pttbbs/util/buildAnnounce.c | 73 ++++++++++++++++++++-------------------- pttbbs/util/initbbs.c | 24 ++++++------- pttbbs/util/kenben.c | 8 ++--- pttbbs/util/parse_news.c | 4 +-- pttbbs/util/post.c | 6 ++-- pttbbs/util/smtest.c | 11 ++++-- pttbbs/util/util_cache.c | 4 +-- 20 files changed, 146 insertions(+), 141 deletions(-) diff --git a/pttbbs/innbbsd/bbslink.c b/pttbbs/innbbsd/bbslink.c index 2b0b6f37..fa5716ac 100644 --- a/pttbbs/innbbsd/bbslink.c +++ b/pttbbs/innbbsd/bbslink.c @@ -460,7 +460,7 @@ save_article(board, filename, sover) if (Verbose) printf("<save_article> %s %s\n", board, filename); - FN = fopen(fileglue("%s/boards/%s/%s", BBSHOME, board, filename), "w"); + FN = fopen(fileglue("%s/boards/%c/%s/%s", BBSHOME, board[0], board, filename), "w"); if (FN == NULL) { bbslog("<save_article> err: %s %s\n", board, filename); @@ -484,7 +484,7 @@ save_article(board, filename, sover) times.actime = sover->mtime; times.modtime = sover->mtime; - utime(fileglue("%s/boards/%s/%s", BBSHOME, board, filename), ×); + utime(fileglue("%s/boards/%c/%s/%s", BBSHOME, board[0], board, filename), ×); utime(fileglue("%s/.bcache/%s", BBSHOME, board), NULL); } #endif @@ -508,7 +508,7 @@ process_article(board, filename, userid, nickname, subject) { subject = "無題"; } - filepath = fileglue("%s/boards/%s/%s", BBSHOME, board, filename); + filepath = fileglue("%s/boards/%c/%s/%s", BBSHOME, board[0], board, filename); if (isfile(filepath)) { linkoverview_t lover; @@ -682,17 +682,17 @@ read_outgoing(sover) #endif } BODY = ""; - FD = open(fileglue("%s/boards/%s/%s", BBSHOME, board, filename), O_RDONLY); + FD = open(fileglue("%s/boards/%c/%s/%s", BBSHOME, board[0], board, filename), O_RDONLY); if (FD < 0) { if (Verbose) - printf(" !! can't open %s/boards/%s/%s\n", BBSHOME, board, filename); + printf(" !! can't open %s/boards/%c/%s/%s\n", BBSHOME, board[0], board, filename); else - fprintf(stderr, "can't open %s/boards/%s/%s\n", BBSHOME, board, filename); + fprintf(stderr, "can't open %s/boards/%c/%s/%s\n", BBSHOME, board[0], board, filename); return -1; } - FD_SIZE = filesize(fileglue("%s/boards/%s/%s", BBSHOME, board, filename)); + FD_SIZE = filesize(fileglue("%s/boards/%c/%s/%s", BBSHOME, board[0], board, filename)); if (FD_BUF == NULL) { FD_BUF = (char *) mymalloc(FD_SIZE + 1 + strlen(COMMENT)); @@ -709,7 +709,7 @@ read_outgoing(sover) FD_END += strlen(COMMENT); if (Verbose) { - printf("<read in> %s/boards/%s/%s\n", BBSHOME, board, filename); + printf("<read in> %s/boards/%c/%s/%s\n", BBSHOME, board[0], board, filename); } *ORGANIZATION = '\0'; @@ -1301,7 +1301,7 @@ cancel_outgoing(board, filename, from, subject) bbslog("<cancel_outgoing> Try to move moderated post from %s to deleted\n", board); if (Verbose) printf("Try to move moderated post from %s to deleted\n", board); - FN = popen(fileglue("%s/bbspost post %s/boards/deleted > %s", + FN = popen(fileglue("%s/bbspost post %s/boards/d/deleted > %s", INNDHOME, BBSHOME, TMPFILE), "w"); if (FN == NULL) { @@ -1323,7 +1323,7 @@ cancel_outgoing(board, filename, from, subject) if (strncmp(result, "post to ", 8) == 0) { /* try to remove it */ - strncpy(filepath, fileglue("%s/boards/%s/%s", BBSHOME, board, filename), sizeof filepath); + strncpy(filepath, fileglue("%s/boards/%c/%s/%s", BBSHOME, board[0], board, filename), sizeof filepath); if (isfile(filepath)) { Rename(filepath, fileglue("%s.cancel", filepath)); diff --git a/pttbbs/innbbsd/bbslink2.c b/pttbbs/innbbsd/bbslink2.c index d79c23a9..70d39766 100644 --- a/pttbbs/innbbsd/bbslink2.c +++ b/pttbbs/innbbsd/bbslink2.c @@ -427,7 +427,7 @@ save_article(board, filename, sover) if (Verbose) printf("<save_article> %s %s\n", board, filename); - FN = fopen(fileglue("%s/boards/%s/%s", BBSHOME, board, filename), "w"); + FN = fopen(fileglue("%s/boards/%c/%s/%s", BBSHOME, board[0], board, filename), "w"); if (FN == NULL) { bbslog("<save_article> err: %s %s\n", board, filename); @@ -451,7 +451,7 @@ save_article(board, filename, sover) times.actime = sover->mtime; times.modtime = sover->mtime; - utime(fileglue("%s/boards/%s/%s", BBSHOME, board, filename), ×); + utime(fileglue("%s/boards/%c/%s/%s", BBSHOME, board[0], board, filename), ×); utime(fileglue("%s/.bcache/%s", BBSHOME, board), NULL); } #endif @@ -475,7 +475,7 @@ process_article(board, filename, userid, nickname, subject) { subject = "無題"; } - filepath = fileglue("%s/boards/%s/%s", BBSHOME, board, filename); + filepath = fileglue("%s/boards/%c/%s/%s", BBSHOME, board[0], board, filename); if (isfile(filepath)) { linkoverview_t lover; @@ -649,17 +649,17 @@ read_outgoing(sover) #endif } BODY = ""; - FD = open(fileglue("%s/boards/%s/%s", BBSHOME, board, filename), O_RDONLY); + FD = open(fileglue("%s/boards/%c/%s/%s", BBSHOME, board[0], board, filename), O_RDONLY); if (FD < 0) { if (Verbose) - printf(" !! can't open %s/boards/%s/%s\n", BBSHOME, board, filename); + printf(" !! can't open %s/boards/%c/%s/%s\n", BBSHOME, board[0], board, filename); else - fprintf(stderr, "can't open %s/boards/%s/%s\n", BBSHOME, board, filename); + fprintf(stderr, "can't open %s/boards/%c/%s/%s\n", BBSHOME, board[0], board, filename); return -1; } - FD_SIZE = filesize(fileglue("%s/boards/%s/%s", BBSHOME, board, filename)); + FD_SIZE = filesize(fileglue("%s/boards/%c/%s/%s", BBSHOME, board[0], board, filename)); if (FD_BUF == NULL) { FD_BUF = (char *) mymalloc(FD_SIZE + 1 + strlen(COMMENT)); @@ -676,7 +676,7 @@ read_outgoing(sover) FD_END += strlen(COMMENT); if (Verbose) { - printf("<read in> %s/boards/%s/%s\n", BBSHOME, board, filename); + printf("<read in> %s/boards/%c/%s/%s\n", BBSHOME, board[0], board, filename); } *ORGANIZATION = '\0'; @@ -1248,7 +1248,7 @@ cancel_outgoing(board, filename, from, subject) bbslog("<cancel_outgoing> Try to move moderated post from %s to deleted\n", board); if (Verbose) printf("Try to move moderated post from %s to deleted\n", board); - FN = popen(fileglue("%s/bbspost post %s/boards/deleted > %s", + FN = popen(fileglue("%s/bbspost post %s/boards/d/deleted > %s", INNDHOME, BBSHOME, TMPFILE), "w"); if (FN == NULL) { @@ -1270,7 +1270,7 @@ cancel_outgoing(board, filename, from, subject) if (strncmp(result, "post to ", 8) == 0) { /* try to remove it */ - strncpy(filepath, fileglue("%s/boards/%s/%s", BBSHOME, board, filename), sizeof filepath); + strncpy(filepath, fileglue("%s/boards/%c/%s/%s", BBSHOME, board[0], board, filename), sizeof filepath); if (isfile(filepath)) { Rename(filepath, fileglue("%s.cancel", filepath)); @@ -1691,7 +1691,7 @@ woju /* woju */ - sprintf(OUTING, "%s/boards/%s/", BBSHOME, argv[1]); + sprintf(OUTING, "%s/boards/%c/%s/", BBSHOME, argv[1][0], argv[1]); fname = OUTING + strlen(OUTING); if (initial_bbs("link") == 0) diff --git a/pttbbs/innbbsd/receive_article.c b/pttbbs/innbbsd/receive_article.c index 40f2609c..d036fe41 100644 --- a/pttbbs/innbbsd/receive_article.c +++ b/pttbbs/innbbsd/receive_article.c @@ -466,7 +466,7 @@ receive_article() { goto boardcont; } - boardhome = (char *) fileglue("%s/boards/%s", BBSHOME, boardptr); + boardhome = (char *) fileglue("%s/boards/%c/%s", BBSHOME, boardptr[0], boardptr); if (!isdir(boardhome)) { bbslog(":Err: unable to write %s\n", boardhome); @@ -485,8 +485,8 @@ receive_article() fname = (char *) fileglue("%s/%s", boardptr, fname); if (firstpath[0] == '\0') { - sprintf(firstpath, "%s/boards/%s", BBSHOME, fname); - firstpathbase = firstpath + strlen(BBSHOME) + strlen("/boards/"); + sprintf(firstpath, "%s/boards/%c, %s", BBSHOME, fname[0], fname); + firstpathbase = firstpath + strlen(BBSHOME) + strlen("/boards/x/"); } if (strlen(fname) + strlen(hispaths) + 1 < sizeof(hispaths)) { @@ -540,7 +540,7 @@ receive_control() newsfeeds_t *nf; bbslog("control post %s\n", HEADER[CONTROL_H]); - boardhome = (char *) fileglue("%s/boards/control", BBSHOME); + boardhome = (char *) fileglue("%s/boards/c/control", BBSHOME); testandmkdir(boardhome); *firstpath = '\0'; if (isdir(boardhome)) @@ -549,12 +549,12 @@ receive_control() if (fname != NULL) { if (firstpath[0] == '\0') - sprintf(firstpath, "%s/boards/control/%s", BBSHOME, fname); + sprintf(firstpath, "%s/boards/c/control/%s", BBSHOME, fname); if (storeDB(HEADER[MID_H], (char *) fileglue("control/%s", fname)) < 0) { } bbsfeedslog(fileglue("control/%s", fname), 'C'); - firstpathbase = firstpath + strlen(BBSHOME) + strlen("/boards/"); + firstpathbase = firstpath + strlen(BBSHOME) + strlen("/boards/x/"); splitptr = (char **) BNGsplit(GROUPS); for (ngptr = *splitptr; ngptr != NULL; ngptr = *(++splitptr)) { @@ -611,7 +611,7 @@ cancel_article_front(msgid) { *ptr++ = '\0'; } - sprintf(filename, "%s/boards/%s", BBSHOME, file); + sprintf(filename, "%s/boards/%c/%s", BBSHOME, file[0], file); bbslog("cancel post %s\n", filename); if (isfile(filename)) { @@ -653,7 +653,7 @@ cancel_article_front(msgid) #ifdef KEEP_NETWORK_CANCEL bbslog("cancel post %s\n", filename); - boardhome = (char *) fileglue("%s/boards/deleted", BBSHOME); + boardhome = (char *) fileglue("%s/boards/d/deleted", BBSHOME); testandmkdir(boardhome); if (isdir(boardhome)) { @@ -685,8 +685,8 @@ cancel_article_front(msgid) { if (firstpath[0] == '\0') { - sprintf(firstpath, "%s/boards/deleted/%s", BBSHOME, fname); - firstpathbase = firstpath + strlen(BBSHOME) + strlen("/boards/"); + sprintf(firstpath, "%s/boards/d/deleted/%s", BBSHOME, fname); + firstpathbase = firstpath + strlen(BBSHOME) + strlen("/boards/x/"); } if (storeDB(HEADER[MID_H], (char *) fileglue("deleted/%s", fname)) < 0) { @@ -700,7 +700,7 @@ cancel_article_front(msgid) { char board[256]; newsfeeds_t *nf; - char *filebase = filename + strlen(BBSHOME) + strlen("/boards/"); + char *filebase = filename + strlen(BBSHOME) + strlen("/boards/x/"); char *filetail = strrchr(filename, '/'); if (filetail != NULL) { @@ -900,10 +900,10 @@ cancelpost(fileheader_t *fhdr, char* boardname) int fd; char fpath[MAXPATHLEN]; - sprintf(fpath, BBSHOME "/boards/%s/%s", boardname, fhdr->filename); + sprintf(fpath, BBSHOME "/boards/%c/%s/%s", boardname[0], boardname, fhdr->filename); if ((fd = open(fpath, O_RDONLY)) >= 0) { fileheader_t postfile; - char fn2[MAXPATHLEN] = BBSHOME "/boards/deleted", *junkdir; + char fn2[MAXPATHLEN] = BBSHOME "/boards/d/deleted", *junkdir; stampfile(fn2, &postfile); memcpy(postfile.owner, fhdr->owner, IDLEN + TTLEN + 10); @@ -1039,7 +1039,7 @@ cancel_article(homepath, board, file) return 0; } size = sizeof(header); - sprintf(dirname, "%s/boards/%s/.DIR", homepath, board); + sprintf(dirname, "%s/boards/%c/%s/.DIR", homepath, board[0], board); if ((fd = open(dirname, O_RDONLY)) == -1) { bbslog("cancel_article: open `%s` error\n", dirname); return 0; @@ -1173,11 +1173,11 @@ cancel_article(homepath, board, file) PATH bdir; struct stat stbuf; - sprintf(bdir, "%s/boards/%s", homepath, board); + sprintf(bdir, "%s/boards/%c/%s", homepath, board[0], board); stat(bdir, &stbuf); #endif - sprintf(fname, "%s/boards/%s/%s", homepath, board, file); + sprintf(fname, "%s/boards/%c/%s/%s", homepath, board[0], board, file); unlink(fname); /* kill it now! the function is far small then original.. :) */ /* because it won't make system load heavy like before */ diff --git a/pttbbs/mbbsd/admin.c b/pttbbs/mbbsd/admin.c index 54fb017f..04804809 100644 --- a/pttbbs/mbbsd/admin.c +++ b/pttbbs/mbbsd/admin.c @@ -1,4 +1,4 @@ -/* $Id: admin.c,v 1.2 2002/03/07 16:44:18 in2 Exp $ */ +/* $Id: admin.c,v 1.3 2002/03/09 17:27:57 in2 Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -241,8 +241,8 @@ int m_mod_board(char *bname) { if(HAS_PERM(PERM_SYSOP) ) { char actionbuf[512]; - sprintf(actionbuf, BBSHOME "/bin/buildir boards/%s &", - bh.brdname); + sprintf(actionbuf, BBSHOME "/bin/buildir boards/%c/%s &", + bh.brdname[0], bh.brdname); system(actionbuf); } break; @@ -284,9 +284,10 @@ int m_mod_board(char *bname) { else { strcpy(bname, bh.brdname); sprintf(genbuf, - "/bin/tar zcvf tmp/board_%s.tgz boards/%s man/%s >/dev/null 2>&1;" - "/bin/rm -fr boards/%s man/%s", - bname, bname, bname, bname, bname); + "/bin/tar zcvf tmp/board_%s.tgz boards/%c/%s man/boards/%c/%s >/dev/null 2>&1;" + "/bin/rm -fr boards/%c/%s man/boards/%c/%s", + bname, bname[0], bname, bname[0], + bname, bname[0], bname, bname[0], bname); system(genbuf); memset(&bh, 0, sizeof(bh)); sprintf(bh.title, "%s 看板 %s 刪除", bname, cuser.userid); diff --git a/pttbbs/mbbsd/announce.c b/pttbbs/mbbsd/announce.c index 960a45aa..0cbce01e 100644 --- a/pttbbs/mbbsd/announce.c +++ b/pttbbs/mbbsd/announce.c @@ -1,4 +1,4 @@ -/* $Id: announce.c,v 1.1 2002/03/07 15:13:48 in2 Exp $ */ +/* $Id: announce.c,v 1.2 2002/03/09 17:27:57 in2 Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -805,12 +805,12 @@ static void a_newitem(menu_t *pm, int mode) { for(d = 0; d <= 3; d++) { switch(d) { case 0: - sprintf(lpath, "%s%s%s/%s", - BBSHOME, "/man/boards/",currboard , buf); + sprintf(lpath, BBSHOME "/man/boards/%c/%s/%s", + currboard[0], currboard, buf); break; case 1: - sprintf(lpath, "%s%s%s", - BBSHOME, "/man/boards/" , buf); + sprintf(lpath, "%s%s/%c/%s", + BBSHOME, "/man/boards/" , buf[0], buf); break; case 2: sprintf(lpath, "%s%s%s", diff --git a/pttbbs/mbbsd/cache.c b/pttbbs/mbbsd/cache.c index 73f8ac5b..57ed0d3f 100644 --- a/pttbbs/mbbsd/cache.c +++ b/pttbbs/mbbsd/cache.c @@ -1,4 +1,4 @@ -/* $Id: cache.c,v 1.1 2002/03/07 15:13:48 in2 Exp $ */ +/* $Id: cache.c,v 1.2 2002/03/09 17:27:57 in2 Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -63,7 +63,7 @@ unsigned int safe_sleep(unsigned int seconds) { #if defined(_BBS_UTIL_C_) static void setapath(char *buf, char *boardname) { - sprintf(buf, "man/boards/%s", boardname); + sprintf(buf, "man/boards/%c/%s", boardname[0], boardname); } static char *str_dotdir = ".DIR"; @@ -758,7 +758,7 @@ void setbtotal(int bid) { char genbuf[256]; int num,fd; - sprintf(genbuf, "boards/%s/.DIR", bh->brdname); + sprintf(genbuf, "boards/%c/%s/.DIR", bh->brdname[0], bh->brdname); if((fd = open(genbuf, O_RDWR)) < 0) return; /* .DIR掛了 */ diff --git a/pttbbs/mbbsd/gamble.c b/pttbbs/mbbsd/gamble.c index 23867450..a2fc3c37 100644 --- a/pttbbs/mbbsd/gamble.c +++ b/pttbbs/mbbsd/gamble.c @@ -1,4 +1,4 @@ -/* $Id: gamble.c,v 1.1 2002/03/07 15:13:48 in2 Exp $ */ +/* $Id: gamble.c,v 1.2 2002/03/09 17:27:57 in2 Exp $ */ #include <stdio.h> #include <time.h> #include <string.h> @@ -32,7 +32,7 @@ int post_msg(char* bname, char* title, char *msg, char* author) char genbuf[256]; /* 在 bname 版發表新文章 */ - sprintf(genbuf, "boards/%s", bname); + sprintf(genbuf, "boards/%c/%s", bname[0], bname); stampfile(genbuf, &fhdr); fp = fopen(genbuf,"w"); diff --git a/pttbbs/mbbsd/record.c b/pttbbs/mbbsd/record.c index 59bc6a75..321132f3 100644 --- a/pttbbs/mbbsd/record.c +++ b/pttbbs/mbbsd/record.c @@ -1,4 +1,4 @@ -/* $Id: record.c,v 1.1 2002/03/07 15:13:48 in2 Exp $ */ +/* $Id: record.c,v 1.2 2002/03/09 17:27:57 in2 Exp $ */ #include <stdio.h> #include <stdlib.h> #include <errno.h> @@ -301,9 +301,9 @@ int delete_files(char* dirname, int (*filecheck)(), int record) { char genbuf[256]; char deleted[256]; fileheader_t delfh; - char deletedDIR[] = "boards/deleted/.DIR"; + char deletedDIR[] = "boards/d/deleted/.DIR"; - strcpy(deleted, "boards/deleted"); + strcpy(deleted, "boards/d/deleted"); if(!(fp = fopen(dirname, "r"))) return ans; diff --git a/pttbbs/mbbsd/stuff.c b/pttbbs/mbbsd/stuff.c index 9218b7f0..cede4a9d 100644 --- a/pttbbs/mbbsd/stuff.c +++ b/pttbbs/mbbsd/stuff.c @@ -1,4 +1,4 @@ -/* $Id: stuff.c,v 1.1 2002/03/07 15:13:48 in2 Exp $ */ +/* $Id: stuff.c,v 1.2 2002/03/09 17:27:57 in2 Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -26,7 +26,7 @@ extern userec_t cuser; /* set file path for boards/user home */ /* ----------------------------------------------------- */ static char *str_home_file = "home/%c/%s/%s"; -static char *str_board_file = "boards/%s/%s"; +static char *str_board_file = "boards/%c/%s/%s"; #define STR_DOTDIR ".DIR" static char *str_dotdir = STR_DOTDIR; @@ -56,7 +56,7 @@ void setuserfile(char *buf, char *fname) { } void setapath(char *buf, char *boardname) { - sprintf(buf, "man/boards/%s", boardname); + sprintf(buf, "man/boards/%c/%s", boardname[0], boardname); } void setadir(char *buf, char *path) { @@ -64,17 +64,17 @@ void setadir(char *buf, char *path) { } void setbpath(char *buf, char *boardname) { - sprintf(buf, "boards/%s", boardname); + sprintf(buf, "boards/%c/%s", boardname[0], boardname); } void setbdir(char *buf, char *boardname) { - sprintf(buf, str_board_file, boardname, + sprintf(buf, str_board_file, boardname[0], boardname, currmode & MODE_ETC ? ".ETC" : (currmode & MODE_DIGEST ? fn_mandex : str_dotdir)); } void setbfile(char *buf, char *boardname, char *fname) { - sprintf(buf, str_board_file, boardname, fname); + sprintf(buf, str_board_file, boardname[0], boardname, fname); } void setdirpath(char *buf, char *direct, char *fname) { diff --git a/pttbbs/mbbsd/syspost.c b/pttbbs/mbbsd/syspost.c index b7aefe10..67edc632 100644 --- a/pttbbs/mbbsd/syspost.c +++ b/pttbbs/mbbsd/syspost.c @@ -1,4 +1,4 @@ -/* $Id: syspost.c,v 1.1 2002/03/07 15:13:48 in2 Exp $ */ +/* $Id: syspost.c,v 1.2 2002/03/09 17:27:57 in2 Exp $ */ #include <stdio.h> #include <string.h> #include <time.h> @@ -19,7 +19,7 @@ void post_change_perm(int oldperm, int newperm, char *sysopid, char *userid) { char genbuf[200], reason[30]; int i, flag=0; - strcpy(genbuf, "boards/Security"); + strcpy(genbuf, "boards/S/Security"); stampfile(genbuf, &fhdr); if(!(fp = fopen(genbuf,"w"))) return; @@ -49,7 +49,7 @@ void post_change_perm(int oldperm, int newperm, char *sysopid, char *userid) { sprintf(fhdr.title, "[公安報告] 站長%s修改%s權限報告", cuser.userid, userid); strcpy(fhdr.owner, "[系統安全局]"); - append_record("boards/Security/.DIR", &fhdr, sizeof(fhdr)); + append_record("boards/S/Security/.DIR", &fhdr, sizeof(fhdr)); } } @@ -58,7 +58,7 @@ void post_violatelaw(char* crime, char* police, char* reason, char* result){ fileheader_t fhdr; time_t now; FILE *fp; - strcpy(genbuf, "boards/Security"); + strcpy(genbuf, "boards/S/Security"); stampfile(genbuf, &fhdr); if(!(fp = fopen(genbuf,"w"))) return; @@ -72,9 +72,9 @@ void post_violatelaw(char* crime, char* police, char* reason, char* result){ fclose(fp); sprintf(fhdr.title, "[報告] %-20s 違法判決報告", crime); strcpy(fhdr.owner, "[Ptt法院]"); - append_record("boards/Security/.DIR", &fhdr, sizeof(fhdr)); + append_record("boards/S/Security/.DIR", &fhdr, sizeof(fhdr)); - strcpy(genbuf, "boards/ViolateLaw"); + strcpy(genbuf, "boards/V/ViolateLaw"); stampfile(genbuf, &fhdr); if(!(fp = fopen(genbuf,"w"))) return; @@ -89,7 +89,7 @@ void post_violatelaw(char* crime, char* police, char* reason, char* result){ sprintf(fhdr.title, "[報告] %-20s 違法判決報告", crime); strcpy(fhdr.owner, "[Ptt法院]"); - append_record("boards/ViolateLaw/.DIR", &fhdr, sizeof(fhdr)); + append_record("boards/V/ViolateLaw/.DIR", &fhdr, sizeof(fhdr)); } diff --git a/pttbbs/mbbsd/user.c b/pttbbs/mbbsd/user.c index 41aacfa9..72850ad7 100644 --- a/pttbbs/mbbsd/user.c +++ b/pttbbs/mbbsd/user.c @@ -1,4 +1,4 @@ -/* $Id: user.c,v 1.1 2002/03/07 15:13:48 in2 Exp $ */ +/* $Id: user.c,v 1.2 2002/03/09 17:27:57 in2 Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -519,7 +519,7 @@ void uinfo_query(userec_t *u, int real, int unum) { passwd_update(unum, &x); now = time(0); if(money_change) { - strcpy(genbuf, "boards/Security"); + strcpy(genbuf, "boards/S/Security"); stampfile(genbuf, &fhdr); if(!(fp = fopen(genbuf,"w"))) return; @@ -542,7 +542,7 @@ void uinfo_query(userec_t *u, int real, int unum) { sprintf(fhdr.title, "[公安報告] 站長%s修改%s錢報告", cuser.userid, x.userid); strcpy(fhdr.owner, "[系統安全局]"); - append_record("boards/Security/.DIR", &fhdr, sizeof(fhdr)); + append_record("boards/S/Security/.DIR", &fhdr, sizeof(fhdr)); } } } diff --git a/pttbbs/mbbsd/vote.c b/pttbbs/mbbsd/vote.c index 62916c99..b16857ce 100644 --- a/pttbbs/mbbsd/vote.c +++ b/pttbbs/mbbsd/vote.c @@ -1,4 +1,4 @@ -/* $Id: vote.c,v 1.1 2002/03/07 15:13:48 in2 Exp $ */ +/* $Id: vote.c,v 1.2 2002/03/09 17:27:57 in2 Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -281,10 +281,10 @@ static void b_result_one(boardheader_t *fh, int ind) { b_suckinfile(frp, b_newresults); fclose(frp); } - sprintf(inbuf, "boards/%s", bname); + sprintf(inbuf, "boards/%c/%s", bname[0], bname); vote_report(bname, b_report, inbuf); if(!(fh->brdattr &BRD_NOCOUNT)) { - sprintf(inbuf, "boards/%s", "Record"); + sprintf(inbuf, "boards/%c/%s", 'R', "Record"); vote_report(bname, b_report, inbuf); } unlink(b_report); diff --git a/pttbbs/util/account.c b/pttbbs/util/account.c index e4166092..1be06f59 100644 --- a/pttbbs/util/account.c +++ b/pttbbs/util/account.c @@ -1,4 +1,4 @@ -/* $Id: account.c,v 1.1 2002/03/07 15:13:45 in2 Exp $ */ +/* $Id: account.c,v 1.2 2002/03/09 17:29:20 in2 Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -54,7 +54,7 @@ keeplog(fpath, board, title) board = "Record"; - sprintf(genbuf, "boards/%s", board); + sprintf(genbuf, "boards/%c/%s", board[0], board); stampfile(genbuf, &fhdr); sprintf(buf, "mv %s %s", fpath, genbuf); system(buf); @@ -63,7 +63,7 @@ keeplog(fpath, board, title) */ strcpy(fhdr.title, title); strcpy(fhdr.owner, "[歷史老師]"); - sprintf(genbuf, "boards/%s/.DIR", board); + sprintf(genbuf, "boards/%c/%s/.DIR", board[0], board); append_record(genbuf, &fhdr, sizeof(fhdr)); if((bid = getbnum(board)) > 0)touchbtotal(bid); diff --git a/pttbbs/util/buildAnnounce.c b/pttbbs/util/buildAnnounce.c index 0e754f22..3fa8a6a7 100644 --- a/pttbbs/util/buildAnnounce.c +++ b/pttbbs/util/buildAnnounce.c @@ -15,36 +15,35 @@ extern void resolve_boards(); void buildchilds(int level,char *path,boardheader_t *bptr) { - char newpath[512]; - boardheader_t *ptr; - fileheader_t item; - - if(bptr->firstchild[1]==(boardheader_t*)~0 || bptr->firstchild[1]==NULL) - return; - for(ptr =(void*) bptr->firstchild[1]; - ptr!=(boardheader_t*)~0 ;ptr=ptr->next[1]) - { - + char newpath[512]; + boardheader_t *ptr; + fileheader_t item; + + if(bptr->firstchild[1]==(boardheader_t*)~0 || bptr->firstchild[1]==NULL) + return; + for(ptr =(void*) bptr->firstchild[1]; + ptr!=(boardheader_t*)~0 ;ptr=ptr->next[1]){ + if( - (ptr->brdattr&(BRD_BAD | BRD_GROUPBOARD | BRD_NOCOUNT | BRD_HIDE))!=0 - || - (ptr->level && !(ptr->brdattr & BRD_POSTMASK))) continue; + (ptr->brdattr&(BRD_BAD | BRD_GROUPBOARD | BRD_NOCOUNT | BRD_HIDE))!=0 + || + (ptr->level && !(ptr->brdattr & BRD_POSTMASK))) + continue; printf("%*.*s+-%-14s %-s \n",level*2,level*2,"| | | | | | | | |", - ptr->brdname, ptr->title); - if(ptr->brdattr & BRD_GROUPBOARD) - { - sprintf(newpath,"%s/%s",path,ptr->brdname); - mkdir(newpath,0766); - buildchilds(level+1,newpath,ptr); - } - else - { - printf("%s4\n",ptr->brdname); - sprintf(newpath,"/bin/ln -s "BBSHOME"/man/boards/%s %s/%s", - ptr->brdname,path,ptr->brdname); - system(newpath); - } - printf("%s5\n",ptr->brdname); + ptr->brdname, ptr->title); + if(ptr->brdattr & BRD_GROUPBOARD){ + sprintf(newpath,"%s/%s",path,ptr->brdname); + mkdir(newpath,0766); + buildchilds(level+1,newpath,ptr); + } + else{ + printf("%s4\n",ptr->brdname); + sprintf(newpath,"/bin/ln -s "BBSHOME"/man/boards/%c/%s %s/%s", + /* maybe something wrong with this ^^^^^ */ + ptr->brdname[0], ptr->brdname,path,ptr->brdname); + system(newpath); + } + printf("%s5\n",ptr->brdname); sprintf(newpath,"%s/.DIR",path); strcpy(item.owner,ptr->BM); strtok(item.owner,"/"); @@ -52,18 +51,18 @@ void buildchilds(int level,char *path,boardheader_t *bptr) item.savemode = 'D'; sprintf(item.filename,ptr->brdname); append_record(newpath, &item, sizeof(item)); - } + } } int main() { - char path[512]; - setsid(); - strcpy(path,GROUPROOT); - system("rm -rf "GROUPROOT); - mkdir(GROUPROOT,0766); - resolve_boards(); - buildchilds(0,path,&bcache[0]); - return 0; + char path[512]; + setsid(); + strcpy(path,GROUPROOT); + system("rm -rf "GROUPROOT); + mkdir(GROUPROOT,0766); + resolve_boards(); + buildchilds(0,path,&bcache[0]); + return 0; } diff --git a/pttbbs/util/initbbs.c b/pttbbs/util/initbbs.c index ce6c4361..c70ab826 100644 --- a/pttbbs/util/initbbs.c +++ b/pttbbs/util/initbbs.c @@ -1,4 +1,4 @@ -/* $Id: initbbs.c,v 1.1 2002/03/07 15:13:46 in2 Exp $ */ +/* $Id: initbbs.c,v 1.2 2002/03/09 17:29:20 in2 Exp $ */ #include <stdio.h> #include <string.h> #include <stdlib.h> @@ -51,9 +51,9 @@ static void newboard(FILE *fp, boardheader_t *b) { char buf[256]; fwrite(b, sizeof(boardheader_t), 1, fp); - sprintf(buf, "boards/%s", b->brdname); + sprintf(buf, "boards/%c/%s", b->brdname[0], b->brdname); mkdir(buf, 0755); - sprintf(buf, "man/boards/%s", b->brdname); + sprintf(buf, "man/boards/%c/%s", b->brdname[0], b->brdname); mkdir(buf, 0755); } @@ -159,31 +159,31 @@ static void initMan() { f.money = 0; f.filemode = 0; - if((fp = fopen("man/boards/Note/.DIR", "w"))) { + if((fp = fopen("man/boards/N/Note/.DIR", "w"))) { strcpy(f.filename, "SONGBOOK"); strcpy(f.title, "◆ 【點 歌 歌 本】"); fwrite(&f, sizeof(f), 1, fp); - mkdir("man/boards/Note/SONGBOOK", 0755); + mkdir("man/boards/N/Note/SONGBOOK", 0755); strcpy(f.filename, "SONGO"); strcpy(f.title, "◆ <點歌> 動態看板"); fwrite(&f, sizeof(f), 1, fp); - mkdir("man/boards/Note/SONGO", 0755); + mkdir("man/boards/N/Note/SONGO", 0755); strcpy(f.filename, "SYS"); strcpy(f.title, "◆ <系統> 動態看板"); fwrite(&f, sizeof(f), 1, fp); - mkdir("man/boards/Note/SYS", 0755); + mkdir("man/boards/N/Note/SYS", 0755); strcpy(f.filename, "AD"); strcpy(f.title, "◆ <廣告> 動態看板"); fwrite(&f, sizeof(f), 1, fp); - mkdir("man/boards/Note/AD", 0755); + mkdir("man/boards/N/Note/AD", 0755); strcpy(f.filename, "NEWS"); strcpy(f.title, "◆ <新聞> 動態看板"); fwrite(&f, sizeof(f), 1, fp); - mkdir("man/boards/Note/NEWS", 0755); + mkdir("man/boards/N/Note/NEWS", 0755); fclose(fp); } @@ -191,9 +191,9 @@ static void initMan() { } static void initSymLink() { - symlink(BBSHOME "/man/boards/Note/SONGBOOK", BBSHOME "/etc/SONGBOOK"); - symlink(BBSHOME "/man/boards/Note/SONGO", BBSHOME "/etc/SONGO"); - symlink(BBSHOME "/man/boards/EditExp", BBSHOME "/etc/editexp"); + symlink(BBSHOME "/man/boards/N/Note/SONGBOOK", BBSHOME "/etc/SONGBOOK"); + symlink(BBSHOME "/man/boards/N/Note/SONGO", BBSHOME "/etc/SONGO"); + symlink(BBSHOME "/man/boards/E/EditExp", BBSHOME "/etc/editexp"); } static void initHistory() { diff --git a/pttbbs/util/kenben.c b/pttbbs/util/kenben.c index 5733f4da..e5d52385 100644 --- a/pttbbs/util/kenben.c +++ b/pttbbs/util/kenben.c @@ -13,9 +13,9 @@ void main() fgets(line,255,fin); line[12] = '\0'; - sprintf(genbuf, "cd ~/boards/%s;grep " - "超過一個月無廣告以外的本站文章發表。" - " *.A > ~/pttbbs/util/kenken.txt",line); + sprintf(genbuf, "cd ~/boards/%c/%s;grep " + "超過一個月無廣告以外的本站文章發表。" + " *.A > ~/pttbbs/util/kenken.txt", line[0], line); system(genbuf); fout = fopen("kenken.txt","r"); @@ -33,7 +33,7 @@ void main() break; } } - sprintf(genbuf, "cd ~/boards/%s;rm %s",line, tok); + sprintf(genbuf, "cd ~/boards/%c/%s;rm %s", line[0], line, tok); // printf("%s \n", genbuf); system(genbuf); } diff --git a/pttbbs/util/parse_news.c b/pttbbs/util/parse_news.c index bebed3f4..fc24a2d6 100644 --- a/pttbbs/util/parse_news.c +++ b/pttbbs/util/parse_news.c @@ -1,4 +1,4 @@ -/* $Id: parse_news.c,v 1.1 2002/03/07 15:13:46 in2 Exp $ */ +/* $Id: parse_news.c,v 1.2 2002/03/09 17:29:20 in2 Exp $ */ #include <stdio.h> #include <string.h> #include <stdlib.h> @@ -10,7 +10,7 @@ #include "pttstruct.h" #include "util.h" -#define NEWSDIRECT BBSHOME "/boards/newspaper" +#define NEWSDIRECT BBSHOME "/boards/n/newspaper" #define MOVIEDIRECT BBSHOME "/etc/NEWS" int main() { diff --git a/pttbbs/util/post.c b/pttbbs/util/post.c index efec797f..d4907096 100644 --- a/pttbbs/util/post.c +++ b/pttbbs/util/post.c @@ -1,4 +1,4 @@ -/* $Id: post.c,v 1.1 2002/03/07 15:13:46 in2 Exp $ */ +/* $Id: post.c,v 1.2 2002/03/09 17:29:20 in2 Exp $ */ #include <stdio.h> #include <string.h> #include <sys/types.h> @@ -13,7 +13,7 @@ void keeplog(FILE *fin, char *fpath, char *board, char *title, char *owner) { FILE *fout; int bid; - sprintf(genbuf, BBSHOME "/boards/%s", board); + sprintf(genbuf, BBSHOME "/boards/%c/%s", board[0], board); stampfile(genbuf, &fhdr); if(!(fout = fopen(genbuf, "w"))) { @@ -31,7 +31,7 @@ void keeplog(FILE *fin, char *fpath, char *board, char *title, char *owner) { fhdr.title[sizeof(fhdr.title) - 1] = '\0'; strcpy(fhdr.owner, owner); - sprintf(genbuf, BBSHOME "/boards/%s/.DIR", board); + sprintf(genbuf, BBSHOME "/boards/%c/%s/.DIR", board[0], board); append_record(genbuf, &fhdr, sizeof(fhdr)); if((bid = getbnum(board)) > 0) touchbtotal(bid); diff --git a/pttbbs/util/smtest.c b/pttbbs/util/smtest.c index 16a2360d..7657762f 100644 --- a/pttbbs/util/smtest.c +++ b/pttbbs/util/smtest.c @@ -170,7 +170,7 @@ int main() (allbrd[i].brdattr & BRD_BAD) || (allbrd[i].level != 0)) continue; - sprintf(fname, BBSHOME "/boards/%s/.DIR",allbrd[i].brdname); + sprintf(fname, BBSHOME "/boards/%c/%s/.DIR", allbrd[i].brdname[0], allbrd[i].brdname); /* get date to choose junk board */ /* exception when ood == 2 */ @@ -237,6 +237,10 @@ int main() allbrd[i].brdname, BTLEN-26, BTLEN-26, allbrd[i].title, IDLEN - 5, IDLEN-5,hdr.date, IDLEN * 3, IDLEN * 3, allbrd[i].BM); + /* if you want to unmark these code, + make sure board, man path have changed to [man/]boards/<First char of brdname>/brdname + */ + // strcpy(bname, allbrd[i].brdname); // sprintf(genbuf, // "/bin/tar zcvf ~/tmp/board_%s.tgz boards/%s man/%s>/dev/null 2>&1;" @@ -283,8 +287,9 @@ int main() bid = getbnum(bname); strcpy(bname,"jourslamdunk"); sprintf(genbuf, - "/bin/tar zcvf ~/tmp/board_%s.tgz boards/%s man/%s>/dev/null 2>&1;" - "/bin/rm -fr ~/boards/%s man/%s",bname, bname, bname,bname,bname); + "/bin/tar zcvf ~/tmp/board_%s.tgz boards/%c/%s man/%c/%s>/dev/null 2>&1;" + "/bin/rm -fr ~/boards/%c/%s man/%c/%s", + bname, bname[0], bname, bname[0], bname, bname[0], bname, bname[0], bname); system(genbuf); memset(&bh, 0, sizeof(bh)); diff --git a/pttbbs/util/util_cache.c b/pttbbs/util/util_cache.c index 12a01994..0e1ab5a1 100644 --- a/pttbbs/util/util_cache.c +++ b/pttbbs/util/util_cache.c @@ -1,4 +1,4 @@ -/* $Id: util_cache.c,v 1.1 2002/03/07 15:13:46 in2 Exp $ */ +/* $Id: util_cache.c,v 1.2 2002/03/09 17:29:20 in2 Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -50,7 +50,7 @@ unsigned int safe_sleep(unsigned int seconds) { } void setapath(char *buf, char *boardname) { - sprintf(buf, "man/boards/%s", boardname); + sprintf(buf, "man/boards/%c/%s", boardname[0], boardname); } static char *str_dotdir = ".DIR"; -- cgit v1.2.3 From f55f8446b7eb343ec84df4fb90a51d7fe2a7b5a0 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sat, 9 Mar 2002 17:44:39 +0000 Subject: no warning git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@16 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/include/proto.h | 4 +++- pttbbs/util/BM_money.c | 3 ++- pttbbs/util/Makefile | 7 ++----- pttbbs/util/account.c | 3 ++- pttbbs/util/bbsmail.c | 3 ++- pttbbs/util/birth.c | 2 +- pttbbs/util/buildAnnounce.c | 4 ++++ pttbbs/util/buildir.c | 7 ++++--- pttbbs/util/expire.c | 3 ++- pttbbs/util/inndBM.c | 10 +++++++--- pttbbs/util/jungo.c | 1 + pttbbs/util/openticket.c | 4 ++-- pttbbs/util/post.c | 3 ++- pttbbs/util/rmuid.c | 19 ++++++++++--------- pttbbs/util/toplazyBBM.c | 1 + pttbbs/util/toplazyBM.c | 2 +- pttbbs/util/uhash_loader.c | 4 ++-- pttbbs/util/util_passwd.c | 4 +++- 18 files changed, 51 insertions(+), 33 deletions(-) diff --git a/pttbbs/include/proto.h b/pttbbs/include/proto.h index 5247ac7f..ca62fed5 100644 --- a/pttbbs/include/proto.h +++ b/pttbbs/include/proto.h @@ -1,4 +1,4 @@ -/* $Id: proto.h,v 1.2 2002/03/09 10:34:56 in2 Exp $ */ +/* $Id: proto.h,v 1.3 2002/03/09 17:44:39 in2 Exp $ */ #ifndef INCLUDE_PROTO_H #define INCLUDE_PROTO_H @@ -519,4 +519,6 @@ int passwd_update_money(int num); /* calendar */ int calendar(); +/* util */ +void touchbtotal(int bid); #endif diff --git a/pttbbs/util/BM_money.c b/pttbbs/util/BM_money.c index 51e24c38..c275b1eb 100644 --- a/pttbbs/util/BM_money.c +++ b/pttbbs/util/BM_money.c @@ -1,4 +1,4 @@ -/* $Id: BM_money.c,v 1.1 2002/03/07 15:13:45 in2 Exp $ */ +/* $Id: BM_money.c,v 1.2 2002/03/09 17:44:30 in2 Exp $ */ /* 給版主錢的程式 */ @@ -11,6 +11,7 @@ #include "pttstruct.h" #include "util.h" #include "common.h" +#include "proto.h" #define FUNCTION (2100 - c*5) diff --git a/pttbbs/util/Makefile b/pttbbs/util/Makefile index 41f7326f..6f204648 100644 --- a/pttbbs/util/Makefile +++ b/pttbbs/util/Makefile @@ -1,4 +1,4 @@ -# $Id: Makefile,v 1.3 2002/03/08 09:22:02 in2 Exp $ +# $Id: Makefile,v 1.4 2002/03/09 17:44:30 in2 Exp $ BBSHOME?=$(HOME) OSTYPE=linux @@ -29,7 +29,7 @@ CPROGS= bbsmail BM_money post account birth deluserfile expire mandex\ horoscope openvice parse_news openticket topusr yearsold uhash_loader\ poststat showboard antispam countalldice webgrep bbsrf\ initbbs outmail xchatd userlist tunepasswd buildir reaper shmsweep\ - merge_passwd merge_board inndBM buildAnnounce rmuid cpdeadbrd \ + merge_passwd merge_board inndBM buildAnnounce rmuid \ toplazyBM jungo toplazyBBM PROGS= $(CPROGS) BM_money.sh backpasswd.sh mailog.sh opendice.sh\ @@ -68,9 +68,6 @@ mandex: mandex.c $(OBJS) rmuid: rmuid.c $(OBJS) $(CC) $(CFLAGS) -o $@ $@.c $(OBJS) -cpdeadbrd: cpdeadbrd.c $(OBJS) - $(CC) $(CFLAGS) -o $@ $@.c $(OBJS) - horoscope: horoscope.c $(OBJS) $(CC) $(CFLAGS) -o $@ $@.c $(OBJS) diff --git a/pttbbs/util/account.c b/pttbbs/util/account.c index 1be06f59..4b221df4 100644 --- a/pttbbs/util/account.c +++ b/pttbbs/util/account.c @@ -1,4 +1,4 @@ -/* $Id: account.c,v 1.2 2002/03/09 17:29:20 in2 Exp $ */ +/* $Id: account.c,v 1.3 2002/03/09 17:44:30 in2 Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -8,6 +8,7 @@ #include "config.h" #include "pttstruct.h" #include "util.h" +#include "proto.h" #define MAX_LINE 16 #define ADJUST_M 6 /* adjust back 5 minutes */ diff --git a/pttbbs/util/bbsmail.c b/pttbbs/util/bbsmail.c index 48f74c63..0afcdf7e 100644 --- a/pttbbs/util/bbsmail.c +++ b/pttbbs/util/bbsmail.c @@ -1,4 +1,4 @@ -/* $Id: bbsmail.c,v 1.1 2002/03/07 15:13:45 in2 Exp $ */ +/* $Id: bbsmail.c,v 1.2 2002/03/09 17:44:30 in2 Exp $ */ #define _BBS_UTIL_C_ #include <stdio.h> @@ -13,6 +13,7 @@ #include "util.h" #include "perm.h" #include "common.h" +#include "proto.h" #define LOG_FILE (BBSHOME "/etc/mailog") diff --git a/pttbbs/util/birth.c b/pttbbs/util/birth.c index 899bf9ee..43840386 100644 --- a/pttbbs/util/birth.c +++ b/pttbbs/util/birth.c @@ -48,7 +48,7 @@ int main(argc, argv) { FILE *fp1; fileheader_t mymail; - int i, day = 0; + //int i, day = 0; time_t now; struct tm *ptime; int j; diff --git a/pttbbs/util/buildAnnounce.c b/pttbbs/util/buildAnnounce.c index 3fa8a6a7..f3f75661 100644 --- a/pttbbs/util/buildAnnounce.c +++ b/pttbbs/util/buildAnnounce.c @@ -1,12 +1,16 @@ /* 建立所有看板精華區的連結 */ #include <stdio.h> +#include <stdlib.h> +#include <unistd.h> #include <string.h> #include <sys/types.h> #include <sys/ipc.h> #include <sys/shm.h> +#include <sys/stat.h> #include "config.h" #include "pttstruct.h" +#include "proto.h" #define GROUPROOT BBSHOME"/man/group" extern bcache_t *brdshm; diff --git a/pttbbs/util/buildir.c b/pttbbs/util/buildir.c index 381a657d..38573e7f 100644 --- a/pttbbs/util/buildir.c +++ b/pttbbs/util/buildir.c @@ -1,4 +1,4 @@ -/* $Id: buildir.c,v 1.1 2002/03/07 15:13:45 in2 Exp $ */ +/* $Id: buildir.c,v 1.2 2002/03/09 17:44:30 in2 Exp $ */ #include <stdio.h> #include <stdlib.h> #include <dirent.h> @@ -11,14 +11,15 @@ #include <sys/stat.h> #include "config.h" #include "pttstruct.h" +#include "proto.h" int dirselect(struct dirent *dir) { return strchr("MDSGH", dir->d_name[0]) && dir->d_name[1] == '.'; } -int mysort(const struct dirent **a,const struct dirent **b) +int mysort(const void *a, const void *b) { - return atoi(((*a)->d_name+2))-atoi(((*b)->d_name+2)); + return atoi(((*((struct dirent **)a))->d_name+2))-atoi(((*((struct dirent **)b))->d_name+2)); } int main(int argc, char **argv) { diff --git a/pttbbs/util/expire.c b/pttbbs/util/expire.c index d6f3e2b9..c0ebdd09 100644 --- a/pttbbs/util/expire.c +++ b/pttbbs/util/expire.c @@ -1,4 +1,4 @@ -/* $Id: expire.c,v 1.1 2002/03/07 15:13:46 in2 Exp $ */ +/* $Id: expire.c,v 1.2 2002/03/09 17:44:30 in2 Exp $ */ /* 自動砍信工具程式 */ #include <stdio.h> @@ -15,6 +15,7 @@ #include "config.h" #include "pttstruct.h" #include "util.h" +#include "proto.h" #define QCAST int (*)(const void *, const void *) diff --git a/pttbbs/util/inndBM.c b/pttbbs/util/inndBM.c index 426fa6f5..4f85bfd4 100644 --- a/pttbbs/util/inndBM.c +++ b/pttbbs/util/inndBM.c @@ -1,12 +1,16 @@ /* 依據 .BOARD檔 & newsfeeds.bbs 列出參與轉信的所有板資料 */ #include <stdio.h> +#include <stdlib.h> #include <string.h> #include <sys/types.h> #include <sys/ipc.h> #include <sys/shm.h> +#include <sys/stat.h> #include "config.h" #include "pttstruct.h" +#include "proto.h" + #define INNDHOME BBSHOME"/innd" #define INND_NEWSFEED INNDHOME "/newsfeeds.bbs" @@ -39,12 +43,12 @@ newsfeed_t feedline[MAX_BOARD]; int servercount; int feedcount; -int newsfeed_cmp(newsfeed_t *a,newsfeed_t *b) +int newsfeed_cmp(const void *a, const void *b) { int i; - i=strcasecmp(a->server,b->server); + i=strcasecmp(((newsfeed_t*)a)->server,((newsfeed_t*)b)->server); if(i) return i; - return strcasecmp(a->board,b->board); + return strcasecmp(((newsfeed_t*)a)->board,((newsfeed_t*)b)->board); } int get_server(char *name) diff --git a/pttbbs/util/jungo.c b/pttbbs/util/jungo.c index 15096b30..8bc4b3a2 100644 --- a/pttbbs/util/jungo.c +++ b/pttbbs/util/jungo.c @@ -10,6 +10,7 @@ #include "util.h" #include "perm.h" #include "common.h" +#include "proto.h" #define OUTFILE BBSHOME "/etc/toplazyBBM" #define FIREFILE BBSHOME "/etc/topfireBBM" diff --git a/pttbbs/util/openticket.c b/pttbbs/util/openticket.c index 69b9ab2a..8a5798b1 100644 --- a/pttbbs/util/openticket.c +++ b/pttbbs/util/openticket.c @@ -1,4 +1,4 @@ -/* $Id: openticket.c,v 1.1 2002/03/07 15:13:46 in2 Exp $ */ +/* $Id: openticket.c,v 1.2 2002/03/09 17:44:30 in2 Exp $ */ /* 開獎的 utility */ #include <stdio.h> #include <stdlib.h> @@ -9,7 +9,7 @@ #include "pttstruct.h" #include "common.h" #include "util.h" - +#include "proto.h" static char *betname[8] = {"Ptt", "Jaky", "Action", "Heat", "DUNK", "Jungo", "waiting", "wofe"}; diff --git a/pttbbs/util/post.c b/pttbbs/util/post.c index d4907096..e14a0814 100644 --- a/pttbbs/util/post.c +++ b/pttbbs/util/post.c @@ -1,4 +1,4 @@ -/* $Id: post.c,v 1.2 2002/03/09 17:29:20 in2 Exp $ */ +/* $Id: post.c,v 1.3 2002/03/09 17:44:30 in2 Exp $ */ #include <stdio.h> #include <string.h> #include <sys/types.h> @@ -6,6 +6,7 @@ #include "config.h" #include "pttstruct.h" #include "util.h" +#include "proto.h" void keeplog(FILE *fin, char *fpath, char *board, char *title, char *owner) { fileheader_t fhdr; diff --git a/pttbbs/util/rmuid.c b/pttbbs/util/rmuid.c index cc6e12cb..c936d160 100644 --- a/pttbbs/util/rmuid.c +++ b/pttbbs/util/rmuid.c @@ -26,20 +26,21 @@ int getbidofuid(int uid) return 1; } -int main(int argc, char* argv[]){ -struct stat st; - int n; - boardheader_t bh; - char pathname[1024]; - - resolve_boards(); - for (n=0;n<numboards;n++) - { +int main(int argc, char* argv[]) +{ + //struct stat st; + int n; + boardheader_t bh; + //char pathname[1024]; + + resolve_boards(); + for (n=0;n<numboards;n++){ memcpy( &bh, &bcache[n], sizeof(bh)); bh.gid=getbidofuid(bh.gid); //printf("%14.14s%14.14s \r\n",bh.brdname, bh.title); substitute_record("BOARDS.bid", &bh, sizeof(bh), n+1); } + return 0; } diff --git a/pttbbs/util/toplazyBBM.c b/pttbbs/util/toplazyBBM.c index 08c07448..5b2f18f3 100644 --- a/pttbbs/util/toplazyBBM.c +++ b/pttbbs/util/toplazyBBM.c @@ -10,6 +10,7 @@ #include "util.h" #include "perm.h" #include "common.h" +#include "proto.h" #define OUTFILE BBSHOME "/etc/toplazyBBM" #define FIREFILE BBSHOME "/etc/topfireBBM" diff --git a/pttbbs/util/toplazyBM.c b/pttbbs/util/toplazyBM.c index ec9319c2..e5e8637b 100644 --- a/pttbbs/util/toplazyBM.c +++ b/pttbbs/util/toplazyBM.c @@ -133,7 +133,7 @@ int main(int argc, char *argv[]) } while((p=strtok(NULL,"/ "))!=NULL); if(flag == 1){ - boardheader_t *fhp = 0; + //boardheader_t *fhp = 0; printf("%s %s\n", lostbms[j-1].title, lostbms[j-1].bmname); bmbuf[0] = '\0'; for(k = 0 , n = 0; k < index; k++){ diff --git a/pttbbs/util/uhash_loader.c b/pttbbs/util/uhash_loader.c index 2d88dd06..1a963829 100644 --- a/pttbbs/util/uhash_loader.c +++ b/pttbbs/util/uhash_loader.c @@ -1,4 +1,4 @@ -/* $Id: uhash_loader.c,v 1.1 2002/03/07 15:13:47 in2 Exp $ */ +/* $Id: uhash_loader.c,v 1.2 2002/03/09 17:44:30 in2 Exp $ */ /* standalone uhash loader -- jochang */ #include <stdio.h> #include <unistd.h> @@ -91,7 +91,7 @@ void fill_uhash(void) for (mimage = fimage; usernumber < fd; mimage += sizeof(userec_t)) { - add_to_uhash(usernumber, mimage); + add_to_uhash(usernumber, (userec_t *)mimage); usernumber++; } munmap(fimage, stbuf.st_size); diff --git a/pttbbs/util/util_passwd.c b/pttbbs/util/util_passwd.c index 07a79351..c9fe4eac 100644 --- a/pttbbs/util/util_passwd.c +++ b/pttbbs/util/util_passwd.c @@ -1,8 +1,9 @@ -/* $Id: util_passwd.c,v 1.1 2002/03/07 15:13:46 in2 Exp $ */ +/* $Id: util_passwd.c,v 1.2 2002/03/09 17:44:30 in2 Exp $ */ #include <stdio.h> #include <string.h> #include <fcntl.h> #include <errno.h> +#include <unistd.h> #include <sys/types.h> #include <sys/stat.h> #include <sys/mman.h> @@ -12,6 +13,7 @@ #include "pttstruct.h" #include "modes.h" #include "common.h" +#include "proto.h" #ifndef SEM_R #define SEM_R 0400 -- cgit v1.2.3 From f325d9a9ad0432bf9d6a67e8b448473e995a4755 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Mon, 11 Mar 2002 11:12:05 +0000 Subject: bad memory check for favbuf git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@17 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/board.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/pttbbs/mbbsd/board.c b/pttbbs/mbbsd/board.c index 44b4b842..c8ba647f 100644 --- a/pttbbs/mbbsd/board.c +++ b/pttbbs/mbbsd/board.c @@ -1,4 +1,4 @@ -/* $Id: board.c,v 1.1 2002/03/07 15:13:48 in2 Exp $ */ +/* $Id: board.c,v 1.2 2002/03/11 11:12:05 in2 Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -242,7 +242,10 @@ void init_brdbuf() { n = numboards + 4; size = n * sizeof(int); zapbuf = (int *) malloc(size); - favbuf = (int *) malloc(size); + favbuf = (int *) malloc(size + sizeof(int)); + + favbuf[0] = 0x5c4d3e; /* for check memory */ + ++favbuf; memset(favbuf,0,size); @@ -275,6 +278,14 @@ void save_brdbuf() { write(fd, zapbuf, size); close(fd); } + if( favbuf[-1] != 0x5c4d3e ){ + time_t now; + FILE *fp = fopen(BBSHOME "/log/memorybad", "a"); + time(&now); + fprintf(fp, "%s %s %d\n", cuser.userid, Cdatelite(&now), favbuf[-1]); + fclose(fp); + return; + } setuserfile(fname, STR_FAV); if((fd = open(fname, O_WRONLY | O_CREAT, 0600)) != -1) { size = numboards * sizeof(int); -- cgit v1.2.3 From 44a5fccab35b13e5ccb521ceea32e27c566b110a Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Mon, 11 Mar 2002 11:15:00 +0000 Subject: fix bug git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@18 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/mbbsd.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pttbbs/mbbsd/mbbsd.c b/pttbbs/mbbsd/mbbsd.c index 85f29642..73e37d75 100644 --- a/pttbbs/mbbsd/mbbsd.c +++ b/pttbbs/mbbsd/mbbsd.c @@ -1,4 +1,4 @@ -/* $Id: mbbsd.c,v 1.2 2002/03/09 10:34:58 in2 Exp $ */ +/* $Id: mbbsd.c,v 1.3 2002/03/11 11:15:00 in2 Exp $ */ #include <stdio.h> #include <string.h> #include <stdlib.h> @@ -421,7 +421,9 @@ write_request (int sig) time (&now); ptime = localtime (&now); - if (currutmp->pager != 0 && + if (!WATERMODE(WATER_OFO) && + currutmp->mode != 0 && + currutmp->pager != 0 && cuser.userlevel != 0 && currutmp->msgcount != 0 && currutmp->mode != TALK && -- cgit v1.2.3 From 75d796285bd54d0c3eb43e317cc86ed92bcfd4d6 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Mon, 11 Mar 2002 11:15:47 +0000 Subject: fix ofo's alive bug git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@19 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/talk.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/pttbbs/mbbsd/talk.c b/pttbbs/mbbsd/talk.c index b59330a9..328e4453 100644 --- a/pttbbs/mbbsd/talk.c +++ b/pttbbs/mbbsd/talk.c @@ -1,4 +1,4 @@ -/* $Id: talk.c,v 1.4 2002/03/09 16:54:32 in2 Exp $ */ +/* $Id: talk.c,v 1.5 2002/03/11 11:15:47 in2 Exp $ */ #include <stdio.h> #include <string.h> #include <errno.h> @@ -522,11 +522,10 @@ void my_write2(void) if( currwater[i] == NULL || currwater[i]->pid == 0 ) break; else{ - if( currwater[i]->uin == NULL ) - currwater[i]->uin = - (userinfo_t *)search_ulist_pid(currwater[i]->pid); - currwater[i]->alive = (strcmp(currwater[i]->userid, - currwater[i]->uin->userid) == 0); + if( currwater[i]->alive && + (currwater[i]->pid != currwater[i]->uin->pid || + strcmp(currwater[i]->userid, currwater[i]->uin->userid)) ) + currwater[i]->alive = 0; water_scr(currwater, i, 0); } move(15, 4); @@ -573,6 +572,9 @@ void my_write2(void) watermode = 1; tw = currwater[(int)which]; + if( !tw->alive ) + break; + if( ch != '\r' && ch != '\n' ){ msg[0] = ch, msg[1] = 0; } -- cgit v1.2.3 From 9e767306ebc7eeceaded9936873b4cd3fd485b12 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Mon, 11 Mar 2002 11:18:19 +0000 Subject: boards/<hash>/<brdname> git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@20 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/mandex.c | 79 ++++++++++++++++++++++++++++++---------------------- 1 file changed, 45 insertions(+), 34 deletions(-) diff --git a/pttbbs/util/mandex.c b/pttbbs/util/mandex.c index 9f5a0e55..fd005924 100644 --- a/pttbbs/util/mandex.c +++ b/pttbbs/util/mandex.c @@ -1,4 +1,4 @@ -/* $Id: mandex.c,v 1.2 2002/03/08 09:21:15 in2 Exp $ */ +/* $Id: mandex.c,v 1.3 2002/03/11 11:18:19 in2 Exp $ */ /* 'mandex -h' to help */ @@ -166,10 +166,17 @@ int main(int argc, char* argv[]) boardheader_t *bptr; DIR *dirp; struct dirent *de; - int ch, n, place = 0, fd; + int ch, n, place = 0, fd, i; char checkrebuild = 0, *fname, fpath[MAXPATHLEN]; + char dirs[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', + 'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', + 'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', + 'z', 'x', 'c', 'v', 'b', 'n', 'm', + 'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', + 'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', + 'Z', 'X', 'C', 'V', 'B', 'N', 'M', NULL}; - while( (ch = getopt(argc, argv, "x")) != -1 ){ + while( (ch = getopt(argc, argv, "xh")) != -1 ){ switch( ch ){ case 'x': checkrebuild = 1; @@ -202,7 +209,7 @@ int main(int argc, char* argv[]) chdir(strcpy(topdir, BBSHOME "/man/boards")); if( argc == 1 ){ - sprintf(fpath, "%s/.DIR", argv[0]); + sprintf(fpath, "%c/%s/.DIR", argv[0][0], argv[0]); mandex(0, "", fpath); return 0; } @@ -222,42 +229,46 @@ int main(int argc, char* argv[]) checkrebuild = 0; nSorted = nb = 0; } + + for( i = 0 ; dirs[i] != NULL ; ++i ){ + sprintf(topdir, BBSHOME "/man/boards/%c", dirs[i]); + chdir(topdir); + if(!(dirp = opendir(topdir))) { + printf("## unable to enter [man/boards]\n"); + exit(-1); + } - if(!(dirp = opendir(topdir))) { - printf("## unable to enter [man/boards]\n"); - exit(-1); - } - - while((de = readdir(dirp))){ - fname = de->d_name; - ch = fname[0]; - if (ch != '.'){ - k = 0; - if( checkrebuild ){ - sprintf(fpath, "%s/.rebuild", fname); - if( access(fpath, 0) < 0 ){ - printf("skip no modify board %s\n", fname); - continue; + while((de = readdir(dirp))){ + fname = de->d_name; + ch = fname[0]; + if (ch != '.'){ + k = 0; + if( checkrebuild ){ + sprintf(fpath, "%s/.rebuild", fname); + if( access(fpath, 0) < 0 ){ + printf("skip no modify board %s\n", fname); + continue; + } + unlink(fpath); } - unlink(fpath); - } - sprintf(fpath, "%s/.DIR", fname); - mandex(0, "", fpath); - printf("%-14sd: %d\tf: %d\n", fname, ndir, nfile); /* report */ - if( k ){ - if( !(biptr = bsearch(fname, board, nSorted, - sizeof(boardinfo), sortbyname))){ - biptr = &board[nb]; - ++nb; + sprintf(fpath, "%s/.DIR", fname); + mandex(0, "", fpath); + printf("%-14sd: %d\tf: %d\n", fname, ndir, nfile); /* report */ + if( k ){ + if( !(biptr = bsearch(fname, board, nSorted, + sizeof(boardinfo), sortbyname))){ + biptr = &board[nb]; + ++nb; + } + strcpy(biptr->bname, fname); + biptr->ndir = ndir; + biptr->nfile = nfile; + biptr->k = k; } - strcpy(biptr->bname, fname); - biptr->ndir = ndir; - biptr->nfile = nfile; - biptr->k = k; } } + closedir(dirp); } - closedir(dirp); qsort(board, nb, sizeof(boardinfo), k_cmp); unlink(BBSHOME "/man/.rank.cache"); -- cgit v1.2.3 From ee048f31f50a1f7d4d97389ed5dd36a981bc99b3 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Mon, 11 Mar 2002 20:27:39 +0000 Subject: fix bug git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@21 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/mbbsd.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pttbbs/mbbsd/mbbsd.c b/pttbbs/mbbsd/mbbsd.c index 73e37d75..5323b376 100644 --- a/pttbbs/mbbsd/mbbsd.c +++ b/pttbbs/mbbsd/mbbsd.c @@ -1,4 +1,4 @@ -/* $Id: mbbsd.c,v 1.3 2002/03/11 11:15:00 in2 Exp $ */ +/* $Id: mbbsd.c,v 1.4 2002/03/11 20:27:39 in2 Exp $ */ #include <stdio.h> #include <string.h> #include <stdlib.h> @@ -409,6 +409,11 @@ add_history(msgque_t *msg) t_display_new(); } } + + if( WATERMODE(WATER_OFO) ){ + swater[0]->uin = (userinfo_t *)search_ulist_pid(swater[0]->pid); + swater[0]->alive = (swater[0]->uin != NULL); + } return i; } -- cgit v1.2.3 From 7049055f768900c3bc9106254c50407ec2c2ba6a Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Tue, 12 Mar 2002 16:54:36 +0000 Subject: re-formatting git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@22 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/mbbsd.c | 125 ++++---- pttbbs/mbbsd/talk.c | 800 ++++++++++++++++++++------------------------------- 2 files changed, 366 insertions(+), 559 deletions(-) diff --git a/pttbbs/mbbsd/mbbsd.c b/pttbbs/mbbsd/mbbsd.c index 5323b376..b0f0dd55 100644 --- a/pttbbs/mbbsd/mbbsd.c +++ b/pttbbs/mbbsd/mbbsd.c @@ -1,4 +1,4 @@ -/* $Id: mbbsd.c,v 1.4 2002/03/11 20:27:39 in2 Exp $ */ +/* $Id: mbbsd.c,v 1.5 2002/03/12 16:54:36 in2 Exp $ */ #include <stdio.h> #include <string.h> #include <stdlib.h> @@ -202,7 +202,7 @@ u_exit (char *mode) { //userec_t xuser; int diff = (time (0) - login_start_time) / 60; - + reload_money(); auto_backup (); save_brdbuf(); @@ -217,12 +217,11 @@ u_exit (char *mode) do_aloha ("<<下站通知>> -- 我走囉!"); purge_utmp (currutmp); - if ((cuser.uflag != enter_uflag) || (currmode & MODE_DIRTY) || diff) - { - if (!diff && cuser.numlogins) - cuser.numlogins = --cuser.numlogins; - /* Leeym 上站停留時間限制式 */ - } + if ((cuser.uflag != enter_uflag) || (currmode & MODE_DIRTY) || diff){ + if (!diff && cuser.numlogins) + cuser.numlogins = --cuser.numlogins; + /* Leeym 上站停留時間限制式 */ + } passwd_update (usernum, &cuser); log_usies (mode, NULL); } @@ -420,62 +419,58 @@ add_history(msgque_t *msg) static void write_request (int sig) { - struct tm *ptime; - time_t now; - - time (&now); - ptime = localtime (&now); - - if (!WATERMODE(WATER_OFO) && - currutmp->mode != 0 && - currutmp->pager != 0 && - cuser.userlevel != 0 && - currutmp->msgcount != 0 && - currutmp->mode != TALK && - currutmp->mode != EDITING && - currutmp->mode != CHATING && - currutmp->mode != PAGE && - currutmp->mode != IDLE && - currutmp->mode != MAILALL && currutmp->mode != MONITOR) - { - int i; - char c0 = currutmp->chatid[0]; - int currstat0 = currstat; - unsigned char mode0 = currutmp->mode; - - currutmp->mode = 0; - currutmp->chatid[0] = 2; - currstat = XMODE; + struct tm *ptime; + time_t now; + + time (&now); + ptime = localtime (&now); - do - { - bell (); - show_last_call_in (1); - igetch (); - currutmp->msgcount--; - if (currutmp->msgcount >= MAX_MSGS) - { - /* this causes chaos... jochang */ - raise (SIGFPE); + if (!WATERMODE(WATER_OFO) && + currutmp->mode != 0 && + currutmp->pager != 0 && + cuser.userlevel != 0 && + currutmp->msgcount != 0 && + currutmp->mode != TALK && + currutmp->mode != EDITING && + currutmp->mode != CHATING && + currutmp->mode != PAGE && + currutmp->mode != IDLE && + currutmp->mode != MAILALL && currutmp->mode != MONITOR){ + int i; + char c0 = currutmp->chatid[0]; + int currstat0 = currstat; + unsigned char mode0 = currutmp->mode; + + currutmp->mode = 0; + currutmp->chatid[0] = 2; + currstat = XMODE; + + do{ + bell (); + show_last_call_in (1); + igetch (); + currutmp->msgcount--; + if (currutmp->msgcount >= MAX_MSGS){ + /* this causes chaos... jochang */ + raise (SIGFPE); } - - add_history(&currutmp->msgs[0]); - for (i = 0; i < currutmp->msgcount; i++) - currutmp->msgs[i] = currutmp->msgs[i + 1]; + + add_history(&currutmp->msgs[0]); + for (i = 0; i < currutmp->msgcount; i++) + currutmp->msgs[i] = currutmp->msgs[i + 1]; } - while (currutmp->msgcount); - currutmp->chatid[0] = c0; - currutmp->mode = mode0; - currstat = currstat0; + while (currutmp->msgcount); + currutmp->chatid[0] = c0; + currutmp->mode = mode0; + currstat = currstat0; } - else - { - bell (); - show_last_call_in (1); - add_history(&currutmp->msgs[0]); - - refresh (); - currutmp->msgcount = 0; + else{ + bell (); + show_last_call_in (1); + add_history(&currutmp->msgs[0]); + + refresh (); + currutmp->msgcount = 0; } } @@ -940,11 +935,11 @@ user_login () more (buf, NA); } #else - more ("etc/Welcome_login", NA); + more ("etc/Welcome_login", NA); #endif -// pressanykey(); -// more("etc/CSIE_Week", NA); - currutmp->birth = 0; + //pressanykey(); + //more("etc/CSIE_Week", NA); + currutmp->birth = 0; } if (cuser.userlevel){/* not guest */ @@ -1010,8 +1005,6 @@ user_login () for (i = 0; i < NUMVIEWFILE; i++) if ((cuser.loginview >> i) & 1) more (loginview_file[(int) i][0], YEA); - - } static void diff --git a/pttbbs/mbbsd/talk.c b/pttbbs/mbbsd/talk.c index 328e4453..5499d18f 100644 --- a/pttbbs/mbbsd/talk.c +++ b/pttbbs/mbbsd/talk.c @@ -1,4 +1,4 @@ -/* $Id: talk.c,v 1.5 2002/03/11 11:15:47 in2 Exp $ */ +/* $Id: talk.c,v 1.6 2002/03/12 16:54:36 in2 Exp $ */ #include <stdio.h> #include <string.h> #include <errno.h> @@ -96,7 +96,8 @@ static char description[30]; static FILE *flog; -char *modestring(userinfo_t * uentp, int simple) { +char *modestring(userinfo_t * uentp, int simple) +{ static char modestr[40]; static char *notonline = "不在站上"; register int mode = uentp->mode; @@ -104,41 +105,34 @@ char *modestring(userinfo_t * uentp, int simple) { int fri_stat; /* for debugging */ - if (mode >= MAX_MODES) - { + if (mode >= MAX_MODES){ syslog(LOG_WARNING, "what!? mode = %d", mode); word = ModeTypeTable[mode % MAX_MODES]; } else word = ModeTypeTable[mode]; fri_stat = friend_stat(currutmp, uentp); - if (!(HAS_PERM(PERM_SYSOP) || HAS_PERM(PERM_SEECLOAK)) && - ( - (uentp->invisible || (fri_stat & HRM)) && - !((fri_stat & HFM) && (fri_stat & HRM)) - ) - ) + if( !(HAS_PERM(PERM_SYSOP) || HAS_PERM(PERM_SEECLOAK)) && + ((uentp->invisible || (fri_stat & HRM)) && + !((fri_stat & HFM) && (fri_stat & HRM))) ) return notonline; - else if (mode == EDITING) - { + else if (mode == EDITING){ sprintf(modestr, "E:%s", ModeTypeTable[uentp->destuid < EDITING ? uentp->destuid : - EDITING]); + EDITING]); word = modestr; } - else if (!mode && *uentp->chatid == 1) - { + else if (!mode && *uentp->chatid == 1){ if (!simple) sprintf(modestr, "回應 %s", getuserid(uentp->destuid)); else sprintf(modestr, "回應呼叫"); } else if (!mode && *uentp->chatid == 2) - if (uentp->msgcount < 10) - { + if (uentp->msgcount < 10){ char *cnum[10] = - {"", "一", "兩", "三", "四", "五", "六", "七", - "八", "九"}; + {"", "一", "兩", "三", "四", "五", "六", "七", + "八", "九"}; sprintf(modestr, "中%s顆水球", cnum[uentp->msgcount]); } else @@ -147,28 +141,25 @@ char *modestring(userinfo_t * uentp, int simple) { sprintf(modestr, "水球準備中"); else if (!mode) return (uentp->destuid == 6) ? uentp->chatid : - IdleTypeTable[(0 <= uentp->destuid && uentp->destuid < 6) ? - uentp->destuid : 0]; + IdleTypeTable[(0 <= uentp->destuid && uentp->destuid < 6) ? + uentp->destuid : 0]; else if (simple) return word; else if (uentp->in_chat && mode == CHATING) sprintf(modestr, "%s (%s)", word, uentp->chatid); - else if (mode == TALK) - { + else if (mode == TALK){ if (!isvisible_uid(uentp->destuid))/* Leeym 對方(紫色)隱形 */ sprintf(modestr, "%s", "交談 空氣");/* Leeym 大家自己發揮吧! */ else sprintf(modestr, "%s %s", word, getuserid(uentp->destuid)); } - else if (mode == M_FIVE) - { + else if (mode == M_FIVE){ if (!isvisible_uid(uentp->destuid)) sprintf(modestr, "%s", "五子棋 空氣"); else sprintf(modestr, "%s %s", word, getuserid(uentp->destuid)); } - else if (mode == CHC) - { + else if (mode == CHC){ if (isvisible_uid(uentp->destuid)) sprintf(modestr, "%s", "下象棋"); else @@ -185,37 +176,31 @@ char *modestring(userinfo_t * uentp, int simple) { int set_friend_bit(userinfo_t * me, userinfo_t * ui) { int unum, *myfriends, hit=0, n; -/* 判斷對方是否為我的朋友 ? */ + /* 判斷對方是否為我的朋友 ? */ unum = ui->uid; myfriends = me->friend; - while ((n = *myfriends++)) - { - if (unum == n) - { + while ((n = *myfriends++)){ + if (unum == n){ hit = IFH; break; } } - -/* 判斷我是否為對方的朋友 ? */ + + /* 判斷我是否為對方的朋友 ? */ myfriends = ui->friend; - while ((unum = *myfriends++)) - { - if (unum == me->uid) - { + while ((unum = *myfriends++)){ + if (unum == me->uid){ hit |= HFM; break; } } - + /* 判斷對方是否為我的仇人 ? */ unum = ui->uid; myfriends = me->reject; - while ((n = *myfriends++)) - { - if (unum == n) - { + while ((n = *myfriends++)){ + if (unum == n){ hit |= IRH; break; } @@ -223,16 +208,15 @@ int set_friend_bit(userinfo_t * me, userinfo_t * ui) { /* 判斷我是否為對方的仇人 ? */ myfriends = ui->reject; - while ((unum = *myfriends++)) - { - if (unum == me->uid) - { + while ((unum = *myfriends++)){ + if (unum == me->uid){ hit |= HRM; break; } } return hit; } + int reverse_friend_stat(int stat) { int stat1=0; @@ -249,54 +233,50 @@ int reverse_friend_stat(int stat) return stat1; } -int login_friend_online(){ - userinfo_t *uentp; - int i, stat, stat1; - int offset=(int) (currutmp - &utmpshm->uinfo[0]); - for (i=0;i<utmpshm->number && currutmp->friendtotal<MAX_FRIEND; i++) - { - uentp = (utmpshm->sorted[utmpshm->currsorted][0][i]); - if(uentp && uentp->uid && (stat=set_friend_bit(currutmp,uentp))) - { - stat1=reverse_friend_stat(stat); - stat <<= 24; - stat |= (int) (uentp - &utmpshm->uinfo[0]); - currutmp->friend_online[currutmp->friendtotal++]=stat; - if(uentp!=currutmp && uentp->friendtotal<MAX_FRIEND) - { - stat1 <<= 24; - stat1 |= offset; - uentp->friend_online[uentp->friendtotal++]=stat1; - } - } - } - return 0; +int login_friend_online(void) +{ + userinfo_t *uentp; + int i, stat, stat1; + int offset=(int) (currutmp - &utmpshm->uinfo[0]); + for (i=0;i<utmpshm->number && currutmp->friendtotal<MAX_FRIEND; i++){ + uentp = (utmpshm->sorted[utmpshm->currsorted][0][i]); + if(uentp && uentp->uid && (stat=set_friend_bit(currutmp,uentp))){ + stat1=reverse_friend_stat(stat); + stat <<= 24; + stat |= (int) (uentp - &utmpshm->uinfo[0]); + currutmp->friend_online[currutmp->friendtotal++]=stat; + if(uentp!=currutmp && uentp->friendtotal<MAX_FRIEND){ + stat1 <<= 24; + stat1 |= offset; + uentp->friend_online[uentp->friendtotal++]=stat1; + } + } + } + return 0; } -int logout_friend_online(){ +int logout_friend_online(void) +{ int i, j, k; int offset=(int) (currutmp - &utmpshm->uinfo[0]); userinfo_t *ui; - while(currutmp->friendtotal) - { - i = currutmp->friendtotal-1; - j = (currutmp->friend_online[i] & 0xFFFFFF); - currutmp->friend_online[i]=0; - ui = &utmpshm->uinfo[j]; - if(ui->pid && ui!=currutmp) - { + while(currutmp->friendtotal){ + i = currutmp->friendtotal-1; + j = (currutmp->friend_online[i] & 0xFFFFFF); + currutmp->friend_online[i]=0; + ui = &utmpshm->uinfo[j]; + if(ui->pid && ui!=currutmp){ for(k=0; k<ui->friendtotal && - (int)(ui->friend_online[k] & 0xFFFFFF) !=offset; k++); - if(k<ui->friendtotal) - { - ui->friendtotal--; - ui->friend_online[k]=ui->friend_online[ui->friendtotal]; - ui->friend_online[ui->friendtotal]=0; - } - } - currutmp->friendtotal--; - currutmp->friend_online[currutmp->friendtotal]=0; + (int)(ui->friend_online[k] & 0xFFFFFF) !=offset; k++); + if(k<ui->friendtotal){ + ui->friendtotal--; + ui->friend_online[k]=ui->friend_online[ui->friendtotal]; + ui->friend_online[ui->friendtotal]=0; + } } + currutmp->friendtotal--; + currutmp->friend_online[currutmp->friendtotal]=0; + } return 0; } @@ -304,45 +284,45 @@ int logout_friend_online(){ int friend_stat(userinfo_t *me, userinfo_t * ui) { int i, j, hit=0; -/* 看板好友 */ - if (me->brc_id && ui->brc_id == me->brc_id) - { + /* 看板好友 */ + if (me->brc_id && ui->brc_id == me->brc_id){ hit = IBH; - } - for(i=0;me->friend_online[i];i++) - { - j = (me->friend_online[i] & 0xFFFFFF); - if(ui == &utmpshm->uinfo[j]) - { - hit |= me->friend_online[i] >>24; - break; - } - } + } + for(i=0;me->friend_online[i];i++){ + j = (me->friend_online[i] & 0xFFFFFF); + if(ui == &utmpshm->uinfo[j]){ + hit |= me->friend_online[i] >>24; + break; + } + } if (PERM_HIDE(ui)) - return hit & ST_FRIEND; + return hit & ST_FRIEND; return hit; } -int isvisible_stat(userinfo_t * me, userinfo_t * uentp, int fri_stat) { +int isvisible_stat(userinfo_t * me, userinfo_t * uentp, int fri_stat) +{ if (uentp->userid[0] == 0) return 0; - + if (PERM_HIDE(uentp) && !(PERM_HIDE(me)))/* 對方紫色隱形而你沒有 */ return 0; else if ((me->userlevel & PERM_SYSOP) || ((fri_stat & HRM) && (fri_stat & HFM))) /* 站長看的見任何人 */ return 1; - + if (uentp->invisible && !(me->userlevel & PERM_SEECLOAK)) return 0; return (fri_stat & HRM) ? 0 : 1; } -int isvisible(userinfo_t * me, userinfo_t * uentp) { +int isvisible(userinfo_t * me, userinfo_t * uentp) +{ return isvisible_stat(currutmp, uentp, friend_stat(me, uentp)); } -int isvisible_uid(int tuid){ +int isvisible_uid(int tuid) +{ userinfo_t *uentp; if(!tuid || !(uentp = search_ulist(tuid))) @@ -351,13 +331,13 @@ int isvisible_uid(int tuid){ } /* 真實動作 */ -static void my_kick(userinfo_t * uentp) { +static void my_kick(userinfo_t * uentp) +{ char genbuf[200]; getdata(1, 0, msg_sure_ny, genbuf, 4, LCECHO); clrtoeol(); - if (genbuf[0] == 'y') - { + if (genbuf[0] == 'y'){ sprintf(genbuf, "%s (%s)", uentp->userid, uentp->username); log_usies("KICK ", genbuf); if((uentp->pid <= 0 || kill(uentp->pid, SIGHUP) == -1) && (errno == ESRCH)) @@ -369,23 +349,20 @@ static void my_kick(userinfo_t * uentp) { pressanykey(); } -static void chicken_query(char *userid) { +static void chicken_query(char *userid) +{ char buf[100]; - if (getuser(userid)) - { - if (xuser.mychicken.name[0]) - { + if (getuser(userid)){ + if (xuser.mychicken.name[0]){ time_diff(&(xuser.mychicken)); - if (!isdeadth(&(xuser.mychicken))) - { + if (!isdeadth(&(xuser.mychicken))){ show_chicken_data(&(xuser.mychicken), NULL); sprintf(buf, "\n\n以上是 %s 的寵物資料..", userid); outs(buf); } } - else - { + else{ move(1, 0); clrtobot(); sprintf(buf, "\n\n%s 並沒有養寵物..", userid); @@ -395,29 +372,28 @@ static void chicken_query(char *userid) { } } -int my_query(char *uident) { +int my_query(char *uident) +{ userec_t muser; int tuid, i, fri_stat=0; unsigned long int j; userinfo_t *uentp; static const char *money[10] = - {"債台高築", "赤貧", "清寒", "普通", "小康", - "小富", "中富", "大富翁", "富可敵國", "比爾蓋\天"}, - *sex[8] = - {MSG_BIG_BOY, MSG_BIG_GIRL, - MSG_LITTLE_BOY, MSG_LITTLE_GIRL, - MSG_MAN, MSG_WOMAN, MSG_PLANT, MSG_MIME}; - - - if ((tuid = getuser(uident))) - { + {"債台高築", "赤貧", "清寒", "普通", "小康", + "小富", "中富", "大富翁", "富可敵國", "比爾蓋\天"}; + static const char *sex[8] = + {MSG_BIG_BOY, MSG_BIG_GIRL, + MSG_LITTLE_BOY, MSG_LITTLE_GIRL, + MSG_MAN, MSG_WOMAN, MSG_PLANT, MSG_MIME}; + + if ((tuid = getuser(uident))){ memcpy(&muser, &xuser, sizeof(muser)); move(1, 0); clrtobot(); move(1, 0); setutmpmode(TQUERY); currutmp->destuid = tuid; - + j = muser.money; for (i = 0; i < 10 && j > 10; i++) j /= 10; @@ -429,23 +405,23 @@ int my_query(char *uident) { prints("《上站次數》%d次", muser.numlogins); move(2, 40); prints("《文章篇數》%d篇\n", muser.numposts); - + if((uentp = (userinfo_t *) search_ulist(tuid))) - fri_stat=friend_stat(currutmp, uentp); + fri_stat=friend_stat(currutmp, uentp); prints("\033[1;33m《目前動態》%-28.28s\033[m", - (uentp && isvisible_stat(currutmp, uentp, fri_stat)) ? + (uentp && isvisible_stat(currutmp, uentp, fri_stat)) ? modestring(uentp, 0) : "不在站上"); - + outs(((uentp && uentp->mailalert) || load_mailalert(muser.userid)) - ? "《私人信箱》有新進信件還沒看\n" : - "《私人信箱》所有信件都看過了\n"); + ? "《私人信箱》有新進信件還沒看\n" : + "《私人信箱》所有信件都看過了\n"); prints("《上次上站》%-28.28s《上次故鄉》%s\n", Cdate(&muser.lastlogin), (muser.lasthost[0] ? muser.lasthost : "(不詳)")); if ((uentp && fri_stat&HFM) || HAS_PERM(PERM_SYSOP)) - prints("《 性 別 》%-28.28s《私有財產》%ld 銀兩\n", - sex[muser.sex % 8], - muser.money); + prints("《 性 別 》%-28.28s《私有財產》%ld 銀兩\n", + sex[muser.sex % 8], + muser.money); prints("《五子棋戰績》%3d 勝 %3d 敗 %3d 和 " "《象棋戰績》%3d 勝 %3d 敗 %3d 和", muser.five_win, muser.five_lose, muser.five_tie, @@ -607,7 +583,8 @@ void my_write2(void) 5. 丟水球 flag = 0 6. my_write2 flag = 4 (pre-edit) but confirm */ -int my_write(pid_t pid, char *prompt, char *id, int flag, userinfo_t *puin) { +int my_write(pid_t pid, char *prompt, char *id, int flag, userinfo_t *puin) +{ int len, currstat0 = currstat, fri_stat; char msg[80], destid[IDLEN + 1]; char genbuf[200], buf[200], c0 = currutmp->chatid[0]; @@ -690,15 +667,14 @@ int my_write(pid_t pid, char *prompt, char *id, int flag, userinfo_t *puin) { time(&now); if(flag != 2) { /* aloha 的水球不用存下來 */ /* 存到自己的水球檔 */ - if(!fp_writelog) - { - sethomefile(genbuf, cuser.userid, fn_writelog); - fp_writelog = fopen(genbuf, "a"); + if(!fp_writelog){ + sethomefile(genbuf, cuser.userid, fn_writelog); + fp_writelog = fopen(genbuf, "a"); } if(fp_writelog) { fprintf(fp_writelog, "To %s: %s [%s]\n", uin->userid, msg, Cdatelite(&now)); - snprintf(t_last_write, 66, "To %s: %s", uin->userid, msg); + snprintf(t_last_write, 66, "To %s: %s", uin->userid, msg); } } @@ -742,7 +718,9 @@ int my_write(pid_t pid, char *prompt, char *id, int flag, userinfo_t *puin) { currstat = currstat0; return 1; } -void t_display_new() { + +void t_display_new(void) +{ static int t_display_new_flag=0; int i, off=2; if (t_display_new_flag) @@ -816,83 +794,19 @@ void t_display_new() { t_display_new_flag = 0; } -#if 0 -void t_display_new() { - int i, which=water_which; - char buf[200]; - if (t_display_new_flag) - return; - else - t_display_new_flag = 1; - - if (oldmsg_count && watermode > 0) - { - move(1, 0); - outs( - "───────水─球─回─顧─────────" - "用[Ctrl-R Ctrl-T]鍵切換─────"); - move(2, 0); - prints(" |"); - for (i = 0; i<5 && water[i].pid != 0; i++) - prints(" %s%13.13s \033[m|",which==i?"\033[1;33m":"", - water[i].userid); - - for( i = 0 ; i < 5 && - water[which].msg[ (water[which].msgtop-i+4) % 5 ][0] != 0; ++i ){ - move(3 + i, 0); - if (watermode - 1 != i) - sprintf(buf, "\033[1;33;46m %s \033[37;45m %s \033[m", - water[which].userid, - water[which].msg[ (water[which].msgtop-i+4) % 5 ]); - else - sprintf(buf, "\033[1;44m>\033[1;33;47m%s \033[37;45m %s \033[m", - water[which].userid, - water[which].msg[ (water[which].msgtop-i+4) % 5 ]); - } - /* - for (i = 0; i < oldmsg_count; i++) - { - int a = (water[water_which].top - i - 1 + MAX_REVIEW) % MAX_REVIEW; - - move(i + 3, 0); - clrtoeol(); - if (watermode - 1 != i) - sprintf(buf, "\033[1;33;46m %s \033[37;45m %s \033[m", - oldmsg[a].userid, oldmsg[a].last_call_in); - else - sprintf(buf, "\033[1;44m>\033[1;33;47m%s " - "\033[37;45m %s \033[m", - oldmsg[a].userid, oldmsg[a].last_call_in); - outs(buf); - } -*/ - if (t_last_write[0]) - { - move(i + 3, 0); - clrtoeol(); - outs(t_last_write); - i++; - } - move(i + 3, 0); - outs("───────────────────────" - "─────────────────"); - } - t_display_new_flag = 0; -} -#endif - -int t_display() { +int t_display(void) +{ char genbuf[200], ans[4]; - if(fp_writelog) - { fclose(fp_writelog); fp_writelog=NULL;} + if(fp_writelog){ + fclose(fp_writelog); + fp_writelog=NULL; + } setuserfile(genbuf, fn_writelog); - if (more(genbuf, YEA) != -1) - { + if (more(genbuf, YEA) != -1){ getdata(b_lines - 1, 0, "清除(C) 移至備忘錄(M) 保留(R) (C/M/R)?[R]", ans, 3, LCECHO); - if (*ans == 'm') - { + if (*ans == 'm'){ fileheader_t mymail; char title[128], buf[80]; @@ -914,7 +828,8 @@ int t_display() { return DONOTHING; } -static void do_talk_nextline(talkwin_t * twin) { +static void do_talk_nextline(talkwin_t * twin) +{ twin->curcol = 0; if (twin->curln < twin->eline) ++(twin->curln); @@ -923,14 +838,14 @@ static void do_talk_nextline(talkwin_t * twin) { move(twin->curln, twin->curcol); } -static void do_talk_char(talkwin_t * twin, int ch) { +static void do_talk_char(talkwin_t * twin, int ch) +{ extern screenline_t *big_picture; screenline_t *line; int i; char ch0, buf[81]; - if (isprint2(ch)) - { + if (isprint2(ch)){ ch0 = big_picture[twin->curln].data[twin->curcol]; if (big_picture[twin->curln].len < 79) move(twin->curln, twin->curcol); @@ -939,8 +854,7 @@ static void do_talk_char(talkwin_t * twin, int ch) { outc(ch); ++(twin->curcol); line = big_picture + twin->curln; - if (twin->curcol < line->len) - { /* insert */ + if (twin->curcol < line->len){ /* insert */ ++(line->len); memcpy(buf, line->data + twin->curcol, 80); save_cursor(); @@ -953,17 +867,15 @@ static void do_talk_char(talkwin_t * twin, int ch) { line->data[line->len] = 0; return; } - - switch (ch) - { + + switch (ch){ case Ctrl('H'): case '\177': if (twin->curcol == 0) return; line = big_picture + twin->curln; --(twin->curcol); - if (twin->curcol < line->len) - { + if (twin->curcol < line->len){ --(line->len); save_cursor(); do_move(twin->curcol, twin->curln); @@ -977,8 +889,7 @@ static void do_talk_char(talkwin_t * twin, int ch) { return; case Ctrl('D'): line = big_picture + twin->curln; - if (twin->curcol < line->len) - { + if (twin->curcol < line->len){ --(line->len); save_cursor(); do_move(twin->curcol, twin->curln); @@ -993,15 +904,13 @@ static void do_talk_char(talkwin_t * twin, int ch) { bell(); return; case Ctrl('B'): - if (twin->curcol > 0) - { + if (twin->curcol > 0){ --(twin->curcol); move(twin->curln, twin->curcol); } return; case Ctrl('F'): - if (twin->curcol < 79) - { + if (twin->curcol < 79){ ++(twin->curcol); move(twin->curln, twin->curcol); } @@ -1039,8 +948,7 @@ static void do_talk_char(talkwin_t * twin, int ch) { line = big_picture + twin->curln; strncpy(buf, line->data, line->len); buf[line->len] = 0; - if (twin->curln > twin->sline) - { + if (twin->curln > twin->sline){ --(twin->curln); move(twin->curln, twin->curcol); } @@ -1049,8 +957,7 @@ static void do_talk_char(talkwin_t * twin, int ch) { line = big_picture + twin->curln; strncpy(buf, line->data, line->len); buf[line->len] = 0; - if (twin->curln < twin->eline) - { + if (twin->curln < twin->eline){ ++(twin->curln); move(twin->curln, twin->curcol); } @@ -1065,7 +972,8 @@ static void do_talk_char(talkwin_t * twin, int ch) { (ch == Ctrl('P')) ? "\033[37;45m(Up)\033[m" : "\033[m"); } -static void do_talk(int fd) { +static void do_talk(int fd) +{ struct talkwin_t mywin, itswin; char mid_line[128], data[200]; int i, datac, ch; @@ -1095,8 +1003,7 @@ static void do_talk(int fd) { i = ch - strlen(genbuf); if (i >= 0) i = (i >> 1) + 1; - else - { + else{ genbuf[ch] = '\0'; i = 1; } @@ -1121,21 +1028,17 @@ static void do_talk(int fd) { add_io(fd, 0); - while (1) - { + while (1){ ch = igetkey(); - if (ch == I_OTHERDATA) - { + if (ch == I_OTHERDATA){ datac = recv(fd, data, sizeof(data), 0); if (datac <= 0) break; for (i = 0; i < datac; i++) do_talk_char(&itswin, data[i]); } - else - { - if (ch == Ctrl('C')) - { + else{ + if (ch == Ctrl('C')){ if (im_leaving) break; move(b_lines, 0); @@ -1144,14 +1047,12 @@ static void do_talk(int fd) { im_leaving = 1; continue; } - if (im_leaving) - { + if (im_leaving){ move(b_lines, 0); clrtoeol(); im_leaving = 0; } - switch (ch) - { + switch (ch){ case KEY_LEFT: /* 把2byte的鍵改為一byte */ ch = Ctrl('B'); break; @@ -1179,8 +1080,7 @@ static void do_talk(int fd) { add_io(0, 0); close(fd); - if (flog) - { + if (flog){ char ans[4]; extern screenline_t *big_picture; extern unsigned char scr_lns; @@ -1195,8 +1095,7 @@ static void do_talk(int fd) { more(fpath, NA); getdata(b_lines - 1, 0, "清除(C) 移至備忘錄(M). (C/M)?[C]", ans, 4, LCECHO); - if (*ans == 'm') - { + if (*ans == 'm'){ fileheader_t mymail; char title[128]; @@ -1235,45 +1134,31 @@ static void my_talk(userinfo_t * uin, int fri_stat) { if (ch == EDITING || ch == TALK || ch == CHATING || ch == PAGE || ch == MAILALL || ch == MONITOR || ch == M_FIVE || ch == CHC || (!ch && (uin->chatid[0] == 1 || uin->chatid[0] == 3)) || - uin->lockmode == M_FIVE || uin->lockmode == CHC) - { + uin->lockmode == M_FIVE || uin->lockmode == CHC){ outs("人家在忙啦"); } else if (!HAS_PERM(PERM_SYSOP) && - ( - ((fri_stat& HRM) && !(fri_stat& HFM)) || - ((!uin->pager) && !(fri_stat & HFM)) - ) - ) - { + (((fri_stat& HRM) && !(fri_stat& HFM)) || + ((!uin->pager) && !(fri_stat & HFM)) ) ){ outs("對方關掉呼叫器了"); } else if (!HAS_PERM(PERM_SYSOP) && - ( - ((fri_stat & HRM) && !(fri_stat& HFM)) || - uin->pager == 2 - ) - ) - { + (((fri_stat & HRM) && !(fri_stat& HFM)) || uin->pager == 2 )) { outs("對方拔掉呼叫器了"); } else if (!HAS_PERM(PERM_SYSOP) && - !(fri_stat & HFM) && uin->pager == 4) - { + !(fri_stat & HFM) && uin->pager == 4){ outs("對方只接受好友的呼叫"); } - else if (!(pid = uin->pid) /*|| (kill(pid, 0) == -1) */ ) - { -// resetutmpent(); + else if (!(pid = uin->pid) /*|| (kill(pid, 0) == -1) */ ){ + //resetutmpent(); outs(msg_usr_left); } - else - { + else{ showplans(uin->userid); getdata(2, 0, "要和他(她) (T)談天(F)下五子棋(P)鬥寵物" "(C)下象棋(D)下暗棋(N)沒事找錯人了?[N] ", genbuf, 4, LCECHO); - switch (*genbuf) - { + switch (*genbuf){ case 'y': case 't': uin->sig = SIG_TALK; @@ -1296,8 +1181,7 @@ static void my_talk(userinfo_t * uin, int fri_stat) { error = 1; if (!cuser.mychicken.name[0] || !xuser.mychicken.name[0]) error = 2; - if (error) - { + if (error){ outmsg(error == 2 ? "並非兩人都養寵物" : "有一方的寵物正在使用中"); bell(); @@ -1317,8 +1201,7 @@ static void my_talk(userinfo_t * uin, int fri_stat) { strcpy(currutmp->mateid, uin->userid); sock = socket(AF_INET, SOCK_STREAM, 0); - if (sock < 0) - { + if (sock < 0){ perror("sock err"); unlockutmpmode(); return; @@ -1326,16 +1209,14 @@ static void my_talk(userinfo_t * uin, int fri_stat) { server.sin_family = PF_INET; server.sin_addr.s_addr = INADDR_ANY; server.sin_port = 0; - if (bind(sock, (struct sockaddr *) &server, sizeof(server)) < 0) - { + if (bind(sock, (struct sockaddr *) &server, sizeof(server)) < 0){ close(sock); perror("bind err"); unlockutmpmode(); return; } length = sizeof(server); - if (getsockname(sock, (struct sockaddr *) &server, &length) < 0) - { + if (getsockname(sock, (struct sockaddr *) &server, &length) < 0){ close(sock); perror("sock name err"); unlockutmpmode(); @@ -1352,15 +1233,12 @@ static void my_talk(userinfo_t * uin, int fri_stat) { listen(sock, 1); add_io(sock, 5); - while (1) - { + while (1){ ch = igetch(); - if (ch == I_TIMEOUT) - { + if (ch == I_TIMEOUT){ ch = uin->mode; if (!ch && uin->chatid[0] == 1 && - uin->destuip == currutmp - &utmpshm->uinfo[0]) - { + uin->destuip == currutmp - &utmpshm->uinfo[0]){ bell(); outmsg("對方回應中..."); refresh(); @@ -1369,8 +1247,7 @@ static void my_talk(userinfo_t * uin, int fri_stat) { ch == PAGE || ch == MAILALL || ch == MONITOR || ch == M_FIVE || ch == CHC || (!ch && (uin->chatid[0] == 1 || - uin->chatid[0] == 3))) - { + uin->chatid[0] == 3))){ add_io(0, 0); close(sock); currutmp->sockactive = currutmp->destuid = 0; @@ -1379,8 +1256,7 @@ static void my_talk(userinfo_t * uin, int fri_stat) { unlockutmpmode(); return; } - else - { + else{ #ifdef linux add_io(sock, 20); /* added for linux... achen */ #endif @@ -1389,8 +1265,7 @@ static void my_talk(userinfo_t * uin, int fri_stat) { bell(); uin->destuip = currutmp - &utmpshm->uinfo[0]; - if(pid <= 0 || kill(pid, SIGUSR1) == -1) - { + if(pid <= 0 || kill(pid, SIGUSR1) == -1){ #ifdef linux add_io(sock, 20); /* added 4 linux... achen */ #endif @@ -1403,12 +1278,11 @@ static void my_talk(userinfo_t * uin, int fri_stat) { continue; } } - + if (ch == I_OTHERDATA) break; - if (ch == '\004') - { + if (ch == '\004'){ add_io(0, 0); close(sock); currutmp->sockactive = currutmp->destuid = 0; @@ -1418,8 +1292,7 @@ static void my_talk(userinfo_t * uin, int fri_stat) { } msgsock = accept(sock, (struct sockaddr *) 0, (int *) 0); - if (msgsock == -1) - { + if (msgsock == -1){ perror("accept"); unlockutmpmode(); return; @@ -1429,13 +1302,11 @@ static void my_talk(userinfo_t * uin, int fri_stat) { currutmp->sockactive = NA; read(msgsock, &c, sizeof c); - if (c == 'y') - { + if (c == 'y'){ sprintf(save_page_requestor, "%s (%s)", uin->userid, uin->username); /* gomo */ - switch (uin->sig) - { + switch (uin->sig){ case SIG_DARK: main_dark(msgsock, uin); break; @@ -1453,12 +1324,10 @@ static void my_talk(userinfo_t * uin, int fri_stat) { do_talk(msgsock); } } - else - { + else{ move(9, 9); outs("【回音】 "); - switch (c) - { + switch (c){ case 'a': outs("我現在很忙,請等一會兒再 call 我,好嗎?"); break; @@ -1475,15 +1344,15 @@ static void my_talk(userinfo_t * uin, int fri_stat) { outs("找我有事嗎?請先來信唷...."); break; case 'f': - { - char msgbuf[60]; - - read(msgsock, msgbuf, 60); - prints("對不起,我現在不能跟你 %s,因為\n", sig_des[uin->sig]); - move(10, 18); - outs(msgbuf); - } - break; + { + char msgbuf[60]; + + read(msgsock, msgbuf, 60); + prints("對不起,我現在不能跟你 %s,因為\n", sig_des[uin->sig]); + move(10, 18); + outs(msgbuf); + } + break; case '1': prints("%s?先拿100銀兩來..", sig_des[uin->sig]); break; @@ -1524,8 +1393,7 @@ static void t_showhelp() { "(p) 切換呼叫器 (g/i) 給錢/切換心情\n" "(a/d/o) 好友 增加/刪除/修改 (/)(s) 網友ID/暱稱搜尋"); - if (HAS_PERM(PERM_PAGE)) - { + if (HAS_PERM(PERM_PAGE)){ outs("\n\n\033[36m【 交談專用鍵 】\033[m\n\n" "(→)(t)(Enter) 跟他/她聊天\n" "(w) 熱線 Call in\n" @@ -1534,8 +1402,7 @@ static void t_showhelp() { "(^R) 即時回應 (有人 Call in 你時)"); } - if (HAS_PERM(PERM_SYSOP)) - { + if (HAS_PERM(PERM_SYSOP)){ outs("\n\n\033[36m【 站長專用鍵 】\033[m\n\n"); if (HAS_PERM(PERM_SYSOP)) outs("(u)/(H) 設定使用者資料/切換隱形模式\n"); @@ -1544,28 +1411,29 @@ static void t_showhelp() { pressanykey(); } -static int listcuent(userinfo_t * uentp) { +static int listcuent(userinfo_t * uentp) +{ if((!uentp->invisible || HAS_PERM(PERM_SYSOP) || HAS_PERM(PERM_SEECLOAK))) AddNameList(uentp->userid); return 0; } -static void creat_list() { +static void creat_list() +{ CreateNameList(); apply_ulist(listcuent); } -static int search_pickup(int num, int actor, pickup_t pklist[]) { +static int search_pickup(int num, int actor, pickup_t pklist[]) +{ char genbuf[IDLEN + 2]; move(1, 0); creat_list(); namecomplete(msg_uid, genbuf); - if (genbuf[0]) - { + if (genbuf[0]){ int n = (num + 1) % actor; - while (n != num) - { + while (n != num){ if (!strcasecmp(pklist[n].ui->userid, genbuf)) return n; if (++n >= actor) @@ -1586,16 +1454,13 @@ static char *friend_descript(char *uident) { setuserfile(fpath, friend_file[0]); - if ((fp = fopen(fpath, "r"))) - { + if ((fp = fopen(fpath, "r"))){ sprintf(name, "%s ", uident); len = strlen(name); desc = genbuf + 13; - while ((flag = (int) fgets(genbuf, STRLEN, fp))) - { - if (!memcmp(genbuf, name, len)) - { + while ((flag = (int) fgets(genbuf, STRLEN, fp))){ + if (!memcmp(genbuf, name, len)){ if ((ptr = strchr(desc, '\n'))) ptr[0] = '\0'; if (desc) @@ -1615,9 +1480,9 @@ static char *friend_descript(char *uident) { } static char *descript(int show_mode, userinfo_t * uentp, time_t diff, - fromcache_t * fcache) { - switch (show_mode) - { + fromcache_t * fcache) +{ + switch (show_mode){ case 1: return friend_descript(uentp->userid); case 0: @@ -1648,8 +1513,7 @@ static int pickup_user_cmp(time_t now, int sortedway, int cmp_fri, { int i, fri_stat, is_friend, count=0, diff; userinfo_t *uentp; - for (i=0;i<utmpshm->number;i++) - { + for (i=0;i<utmpshm->number;i++){ uentp = (utmpshm->sorted[utmpshm->currsorted][sortedway][i]); if (!uentp || !uentp->pid) continue; fri_stat = friend_stat(currutmp, uentp); @@ -1671,13 +1535,12 @@ static int pickup_user_cmp(time_t now, int sortedway, int cmp_fri, #ifdef DOTIMEOUT /* prevent fault /dev mount from kicking out users */ if ((diff > curr_idle_timeout + 10) && - (diff < 60 * 60 * 24 * 5)) - { - if ((uentp->pid <= 0 || kill(uentp->pid, SIGHUP) == -1) && - (errno == ESRCH)) - purge_utmp(uentp); - continue; - } + (diff < 60 * 60 * 24 * 5)){ + if ((uentp->pid <= 0 || kill(uentp->pid, SIGHUP) == -1) && + (errno == ESRCH)) + purge_utmp(uentp); + continue; + } #endif pklist[count].idle = diff; #endif @@ -1698,7 +1561,8 @@ static int cmputmpfriend(const void *i, const void *j) (((pickup_t*)i)->friend&ST_FRIEND); } -static void pickup_user() { +static void pickup_user(void) +{ static int real_name = 0; static int show_mode = 0; static int show_uid = 0; @@ -1750,11 +1614,9 @@ static void pickup_user() { ":D ", ":p ", ";) ", ":> ", ";> ", ":< ", ":)~", ":D~", ">< ", "^^;", "^^|", "哭;", NULL}; - while (1) - { + while (1) { if (utmpshm->uptime > freshtime || state == US_PICKUP || - state ==US_RESORT) - { + state ==US_RESORT){ state = US_PICKUP; time(&freshtime); ifh_number=hfm_number=irh_number=bfriends_number = actor = ch = 0; @@ -1764,49 +1626,43 @@ static void pickup_user() { sortedway=pickup_way-1; //qsort(pklist,actor,sizeof(pickup_t),cmputmpfriend); - if(pickup_way==0 || (cuser.uflag & FRIEND_FLAG)) - { + if(pickup_way==0 || (cuser.uflag & FRIEND_FLAG)){ actor=pickup_user_cmp(freshtime, sortedway, 1, - pklist, &bfriends_number, &ifh_number, &hfm_number, - NULL,keyword); + pklist, &bfriends_number, &ifh_number, + &hfm_number, NULL, keyword); if(sortedway==0) - qsort(pklist,actor,sizeof(pickup_t),cmputmpfriend); + qsort(pklist,actor,sizeof(pickup_t),cmputmpfriend); if(!(cuser.uflag & FRIEND_FLAG)) - actor=pickup_user_cmp(freshtime, sortedway, -1, - pklist+actor, NULL, NULL, NULL, &irh_number, - keyword); - } - else - { + actor=pickup_user_cmp(freshtime, sortedway, -1, + pklist+actor, NULL, NULL, NULL, + &irh_number, keyword); + } + else{ actor=pickup_user_cmp(freshtime, sortedway, 0, - pklist, &bfriends_number, &ifh_number, &hfm_number, - &irh_number, keyword); - } + pklist, &bfriends_number, &ifh_number, + &hfm_number, &irh_number, keyword); + } - if (!actor) - { - if(keyword[0]) - { - mprints(b_lines-1,0, - "搜尋不到任何人 !!"); - keyword[0]=0; - pressanykey(); - continue; + if (!actor){ + if(keyword[0]){ + mprints(b_lines-1,0, + "搜尋不到任何人 !!"); + keyword[0]=0; + pressanykey(); + continue; } getdata(b_lines - 1, 0, "你的朋友還沒上站,要看看一般網友嗎(Y/N)?[Y]", genbuf, 4, LCECHO); - if (genbuf[0] != 'n') - { + if (genbuf[0] != 'n'){ cuser.uflag &= ~FRIEND_FLAG; continue; } return; } } - if (state >= US_ACTION) - { + if (state >= US_ACTION){ showtitle((cuser.uflag & FRIEND_FLAG) ? "好友列表" : "休閒聊天", BBSName); prints(" 排序:[%s] 上站人數:%-4d\033[1;32m我的朋友:%-3d" @@ -1823,18 +1679,15 @@ static void pickup_user() { show_pid ? " PID" : "備註 發呆" ); } - else - { + else{ move(3, 0); clrtobot(); } if (pid0) - for (ch = 0; ch < actor; ch++) - { + for (ch = 0; ch < actor; ch++){ if (pid0 == (pklist[ch].ui)->pid && id0 == 256 * pklist[ch].ui->userid[0] + - pklist[ch].ui->userid[1]) - { + pklist[ch].ui->userid[1]){ num = ch; } } @@ -1846,12 +1699,10 @@ static void pickup_user() { foot = head + p_lines; if (foot > actor) foot = actor; - for (ch = head; ch < foot; ch++) - { + for (ch = head; ch < foot; ch++){ uentp = pklist[ch].ui; - if (!uentp->pid) - { + if (!uentp->pid){ prints("%5d < 離站中..>\n",ch); continue; } @@ -1923,14 +1774,12 @@ static void pickup_user() { "\033[31m(w)\033[30m水球 \033[31m(m)\033[30m寄信 \033[31m(h)" "\033[30m線上輔助 \033[m"); state = 0; - while (!state) - { + while (!state){ ch = cursor_key(num + 3 - head, 0); if (ch == KEY_RIGHT || ch == '\n' || ch == '\r') ch = 't'; - switch (ch) - { + switch (ch){ case KEY_LEFT: case 'e': case 'E': @@ -1948,8 +1797,7 @@ static void pickup_user() { case KEY_DOWN: case 'n': case 'j': - if (++num < actor) - { + if (++num < actor){ if (num >= foot) state = US_REDRAW; break; @@ -1961,15 +1809,13 @@ static void pickup_user() { state = US_REDRAW; break; case 'H': - if (HAS_PERM(PERM_SYSOP)) - { + if (HAS_PERM(PERM_SYSOP)){ currutmp->userlevel ^= PERM_DENYPOST; state = US_REDRAW; } break; case 'D': - if (HAS_PERM(PERM_SYSOP)) - { + if (HAS_PERM(PERM_SYSOP)){ char buf[100]; sprintf(buf, "代號 [%s]:", currutmp->userid); @@ -1980,8 +1826,7 @@ static void pickup_user() { } break; case 'F': - if (HAS_PERM(PERM_SYSOP)) - { + if (HAS_PERM(PERM_SYSOP)){ char buf[100]; sprintf(buf, "故鄉 [%s]:", currutmp->from); @@ -2002,8 +1847,7 @@ static void pickup_user() { case ' ': case KEY_PGDN: case Ctrl('F'): - if (foot < actor) - { + if (foot < actor){ num += p_lines; state = US_REDRAW; break; @@ -2014,10 +1858,8 @@ static void pickup_user() { break; case KEY_UP: case 'k': - if (--num < head) - { - if (num < 0) - { + if (--num < head){ + if (num < 0){ num = actor - 1; if (actor == foot) break; @@ -2028,8 +1870,7 @@ static void pickup_user() { case KEY_PGUP: case Ctrl('B'): case 'P': - if (head) - { + if (head){ num -= p_lines; state = US_REDRAW; break; @@ -2099,8 +1940,7 @@ static void pickup_user() { #endif case 'b': /* broadcast */ - if (cuser.uflag & FRIEND_FLAG || HAS_PERM(PERM_SYSOP)) - { + if (cuser.uflag & FRIEND_FLAG || HAS_PERM(PERM_SYSOP)){ int actor_pos = actor; char ans[4]; @@ -2110,8 +1950,7 @@ static void pickup_user() { if (getdata(0, 0, "確定廣播? [Y]", ans, 4, LCECHO) && *ans == 'n') break; - while (actor_pos) - { + while (actor_pos){ uentp = pklist[--actor_pos].ui; fri_stat = pklist[actor_pos].friend; if (uentp->pid && @@ -2174,8 +2013,7 @@ static void pickup_user() { state = US_ACTION; break; case 'p': - if (HAS_PERM(PERM_BASIC)) - { + if (HAS_PERM(PERM_BASIC)){ t_pager(); state = US_REDRAW; } @@ -2198,8 +2036,7 @@ static void pickup_user() { } } - if (state != US_ACTION) - { + if (state != US_ACTION){ pid0 = 0; continue; } @@ -2210,46 +2047,38 @@ static void pickup_user() { pid0 = uentp->pid; id0 = 256 * uentp->userid[0] + uentp->userid[1]; - if (ch == 'w') - { + if (ch == 'w'){ if ((uentp->pid != currpid) && (HAS_PERM(PERM_SYSOP) || (uentp->pager != 3 && - (fri_stat & HFM || uentp->pager != 4)))) - { + (fri_stat & HFM || uentp->pager != 4)))){ cursor_show(num + 3 - head, 0); sprintf(genbuf, "Call-In %s :", uentp->userid); my_write(uentp->pid, genbuf, uentp->userid, 0, NULL); } } - else if (ch == 'l') - { /* Thor: 看 Last call in */ + else if (ch == 'l'){ /* Thor: 看 Last call in */ t_display(); } - else - { - switch (ch) - { + else{ + switch (ch){ case 'r': m_read(); break; case 'g': /* give money */ move(b_lines - 2, 0); - if (strcmp(uentp->userid, cuser.userid)) - { + if (strcmp(uentp->userid, cuser.userid)){ sprintf(genbuf, "要給 %s 多少錢呢? ", uentp->userid); outs(genbuf); if (getdata(b_lines - 1, 0, "[銀行轉帳]:", genbuf, 7, - LCECHO)) - { + LCECHO)){ clrtoeol(); if ((ch = atoi(genbuf)) <= 0) break; reload_money(); if (ch > cuser.money) outs("\033[41m 現金不足~~\033[m"); - else - { + else{ deumoney(uentp->uid, ch); sprintf(genbuf, "\033[44m 嗯..還剩下 %d 錢.." "\033[m", demoney(-1*ch)); @@ -2261,8 +2090,7 @@ static void pickup_user() { mail_redenvelop(cuser.userid, uentp->userid, ch, 'Y'); } } - else - { + else{ clrtoeol(); outs("\033[41m 交易取消! \033[m"); } @@ -2276,8 +2104,7 @@ static void pickup_user() { case 'i': move(3,0); clrtobot(); - for (i = 1; Mind[i]!=NULL; i++) - { + for (i = 1; Mind[i]!=NULL; i++){ move(5+(i-1)/7,((i-1)%7)*10); prints("%2d: %s",i,Mind[i]); } @@ -2303,8 +2130,7 @@ static void pickup_user() { state = US_PICKUP; break; case 'K': - if (uentp->pid > 0 && kill(uentp->pid, 0) != -1) - { + if (uentp->pid > 0 && kill(uentp->pid, 0) != -1){ move(1, 0); clrtobot(); move(2, 0); @@ -2324,16 +2150,14 @@ static void pickup_user() { case 'c': chicken_query(uentp->userid); break; - case 'u': /* Thor: 可線上查看及修改使用者 */ - { + case 'u':{ /* Thor: 可線上查看及修改使用者 */ int id; userec_t muser; - + strcpy(currauthor, uentp->userid); stand_title("使用者設定"); move(1, 0); - if ((id = getuser(uentp->userid))) - { + if ((id = getuser(uentp->userid))){ memcpy(&muser, &xuser, sizeof(muser)); user_display(&muser, 1); uinfo_query(&muser, 1, id); @@ -2347,8 +2171,7 @@ static void pickup_user() { case 't': if (uentp->pid != currpid && - (strcmp(uentp->userid, cuser.userid))) - { + (strcmp(uentp->userid, cuser.userid))){ move(1, 0); clrtobot(); move(3, 0); @@ -2362,7 +2185,8 @@ static void pickup_user() { } } -int t_users() { +int t_users(void) +{ int destuid0 = currutmp->destuid; int mode0 = currutmp->mode; int stat0 = currstat; @@ -2375,12 +2199,14 @@ int t_users() { return 0; } -int t_pager() { +int t_pager(void) +{ currutmp->pager = (currutmp->pager + 1) % 5; return 0; } -int t_idle() { +int t_idle(void) +{ int destuid0 = currutmp->destuid; int mode0 = currutmp->mode; int stat0 = currstat; @@ -2390,8 +2216,7 @@ int t_idle() { setutmpmode(IDLE); getdata(b_lines - 1, 0, "理由:[0]發呆 (1)接電話 (2)覓食 (3)打瞌睡 " "(4)裝死 (5)羅丹 (6)其他 (Q)沒事?", genbuf, 3, DOECHO); - if (genbuf[0] == 'q' || genbuf[0] == 'Q') - { + if (genbuf[0] == 'q' || genbuf[0] == 'Q'){ currutmp->mode = mode0; currstat = stat0; return 0; @@ -2406,8 +2231,7 @@ int t_idle() { !getdata(b_lines - 1, 0, "發呆的理由:", currutmp->chatid, 11, DOECHO)) currutmp->destuid = 0; - do - { + do{ move(b_lines - 2, 0); clrtoeol(); sprintf(buf, "(鎖定螢幕)發呆原因: %s", (currutmp->destuid != 6) ? @@ -2427,7 +2251,8 @@ int t_idle() { return 0; } -int t_qchicken() { +int t_qchicken(void) +{ char uident[STRLEN]; stand_title("查詢寵物"); @@ -2437,7 +2262,8 @@ int t_qchicken() { return 0; } -int t_query() { +int t_query(void) +{ char uident[STRLEN]; stand_title("查詢網友"); @@ -2453,8 +2279,7 @@ int t_talk() { userinfo_t *uentp; char genbuf[4]; /* - if (count_ulist() <= 1) - { + if (count_ulist() <= 1){ outs("目前線上只有您一人,快邀請朋友來光臨【" BBSNAME "】吧!"); return XEASY; } @@ -2466,8 +2291,7 @@ int t_talk() { return 0; move(3, 0); - if (!(tuid = searchuser(uident)) || tuid == usernum) - { + if (!(tuid = searchuser(uident)) || tuid == usernum){ outs(err_uid); pressanykey(); return 0; @@ -2475,8 +2299,7 @@ int t_talk() { /* multi-login check */ unum = 1; - while ((ucount = count_logins(tuid, 0)) > 1) - { + while ((ucount = count_logins(tuid, 0)) > 1){ outs("(0) 不想 talk 了...\n"); count_logins(tuid, 1); getdata(1, 33, "請選擇一個聊天對象 [0]:", genbuf, 4, DOECHO); @@ -2497,7 +2320,8 @@ int t_talk() { /* 有人來串門子了,回應呼叫器 */ static userinfo_t *uip; -void talkreply() { +void talkreply(void) +{ struct hostent *h; char buf[4]; struct sockaddr_in sin; @@ -2538,8 +2362,7 @@ void talkreply() { page_requestor, sig_des[sig]); getdata(0, 0, genbuf, buf, 4, LCECHO); - if (uip->mode != PAGE) - { + if (uip->mode != PAGE){ sprintf(genbuf, "%s已停止呼叫,按Enter繼續...", page_requestor); getdata(0, 0, genbuf, buf, 4, LCECHO); return; @@ -2547,8 +2370,7 @@ void talkreply() { currutmp->msgcount = 0; strcpy(save_page_requestor, page_requestor); memset(page_requestor, 0, sizeof(page_requestor)); - if (!(h = gethostbyname("localhost"))) - { + if (!(h = gethostbyname("localhost"))){ perror("gethostbyname"); return; } @@ -2557,24 +2379,21 @@ void talkreply() { memcpy(&sin.sin_addr, h->h_addr, h->h_length); sin.sin_port = uip->sockaddr; a = socket(sin.sin_family, SOCK_STREAM, 0); - if ((connect(a, (struct sockaddr *) &sin, sizeof(sin)))) - { + if ((connect(a, (struct sockaddr *) &sin, sizeof(sin)))){ perror("connect err"); return; } if (!buf[0] || !strchr("yabcdef12", buf[0])) buf[0] = 'n'; write(a, buf, 1); - if (buf[0] == 'f' || buf[0] == 'F') - { + if (buf[0] == 'f' || buf[0] == 'F'){ if (!getdata(b_lines, 0, "不能的原因:", genbuf, 60, DOECHO)) strcpy(genbuf, "不告訴你咧 !! ^o^"); write(a, genbuf, 60); } uip->destuip = currutmp - &utmpshm->uinfo[0]; if (buf[0] == 'y') - switch (sig) - { + switch (sig){ case SIG_DARK: main_dark(a, uip); break; @@ -2598,14 +2417,14 @@ void talkreply() { /* 網友動態簡表 */ /* not used -static int shortulist(userinfo_t * uentp) { +static int shortulist(userinfo_t * uentp) +{ static int lineno, fullactive, linecnt; static int moreactive, page, num; char uentry[50]; int state; - if (!lineno) - { + if (!lineno){ lineno = 3; page = moreactive ? (page + p_lines * 3) : 0; linecnt = num = moreactive = 0; @@ -2614,8 +2433,7 @@ static int shortulist(userinfo_t * uentp) { move(lineno, 0); } - if (uentp == NULL) - { + if (uentp == NULL){ int finaltally; clrtoeol(); @@ -2625,12 +2443,12 @@ static int shortulist(userinfo_t * uentp) { lineno = fullactive = 0; return finaltally; } + if ((!HAS_PERM(PERM_SYSOP) && !HAS_PERM(PERM_SEECLOAK) && uentp->invisible) || ((friend_stat(currutmp, uentp) & HRM) && - !HAS_PERM(PERM_SYSOP))) - { + !HAS_PERM(PERM_SYSOP))){ if (lineno >= b_lines) return 0; if (num++ < page) @@ -2638,11 +2456,9 @@ static int shortulist(userinfo_t * uentp) { memset(uentry, ' ', 25); uentry[25] = '\0'; } - else - { + else{ fullactive++; - if (lineno >= b_lines) - { + if (lineno >= b_lines){ moreactive = 1; return 0; } @@ -2659,13 +2475,11 @@ static int shortulist(userinfo_t * uentp) { uentp->userid, uentp->invisible ? '#' : ' ', modestring(uentp, 1), state ? "\033[0m" : ""); } - if (++linecnt < 3) - { + if (++linecnt < 3){ strcat(uentry, "│"); outs(uentry); } - else - { + else{ outs(uentry); linecnt = 0; clrtoeol(); -- cgit v1.2.3 From 52cc23ff64283c5ca0aaf1829f859d8477e5d7ba Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Thu, 14 Mar 2002 08:17:45 +0000 Subject: ofo_water update git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@23 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/include/proto.h | 6 ++- pttbbs/mbbsd/io.c | 22 ++++++--- pttbbs/mbbsd/mbbsd.c | 121 +++++++++++++++++++++++++++++-------------------- pttbbs/mbbsd/talk.c | 65 +++++++++++++------------- 4 files changed, 125 insertions(+), 89 deletions(-) diff --git a/pttbbs/include/proto.h b/pttbbs/include/proto.h index ca62fed5..8604aab5 100644 --- a/pttbbs/include/proto.h +++ b/pttbbs/include/proto.h @@ -1,4 +1,4 @@ -/* $Id: proto.h,v 1.3 2002/03/09 17:44:39 in2 Exp $ */ +/* $Id: proto.h,v 1.4 2002/03/14 08:17:43 in2 Exp $ */ #ifndef INCLUDE_PROTO_H #define INCLUDE_PROTO_H @@ -261,6 +261,8 @@ int do_send(char *userid, char *title); void my_send(char *uident); /* mbbsd */ +void show_call_in(int save, int which); +void write_request (int sig); void log_usies(char *mode, char *mesg); void log_user(char *msg); void abort_bbs(int sig); @@ -409,7 +411,7 @@ void post_change_perm(int oldperm, int newperm, char *sysopid, char *userid); /* talk */ int cmpwatermtime(const void *a, const void *b); -void water_scr(water_t **currwater, int which, char type); +//void water_scr(water_t *tw, int which, char type); void my_write2(void); int t_idle(); char *modestring(userinfo_t * uentp, int simple); diff --git a/pttbbs/mbbsd/io.c b/pttbbs/mbbsd/io.c index 1f13ffeb..c0e796df 100644 --- a/pttbbs/mbbsd/io.c +++ b/pttbbs/mbbsd/io.c @@ -1,4 +1,4 @@ -/* $Id: io.c,v 1.2 2002/03/09 10:34:58 in2 Exp $ */ +/* $Id: io.c,v 1.3 2002/03/14 08:17:45 in2 Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -124,10 +124,20 @@ int num_in_buf() { } int watermode = -1; -/* Ptt 水球回顧用的參數 */ -/* watermode = -1 沒在回水球 - = 0 在回上一顆水球 (Ctrl-R) - > 0 在回前 n 顆水球 (Ctrl-R Ctrl-R) */ +/* + WATERMODE(WATER_ORIG) | WATERMODE(WATER_NEW): + Ptt 水球回顧用的參數 + watermode = -1 沒在回水球 + = 0 在回上一顆水球 (Ctrl-R) + > 0 在回前 n 顆水球 (Ctrl-R Ctrl-R) + + WATERMODE(WATER_OFO) by in2 + watermode = -1 沒在回水球 + = 0 正在回水球 + = 1 回水球間又接到水球 + watermode >=0 時收到水球將只顯示, 不會到water[]裡, + 待回完水球的時候一次寫入. +*/ /* dogetch() is not reentrant-safe. SIGUSR[12] might happen at any time, @@ -256,7 +266,7 @@ int igetch() { /* 如果正在talk的話先不處理對方送過來的封包 (不去select) */ my_newfd = i_newfd; i_newfd = 0; - show_last_call_in(0); + show_call_in(0, 0); watermode = 0; my_write(currutmp->msgs[0].pid, "水球丟過去 : ", currutmp->msgs[0].userid, 0, NULL); diff --git a/pttbbs/mbbsd/mbbsd.c b/pttbbs/mbbsd/mbbsd.c index b0f0dd55..3a38aabb 100644 --- a/pttbbs/mbbsd/mbbsd.c +++ b/pttbbs/mbbsd/mbbsd.c @@ -1,4 +1,4 @@ -/* $Id: mbbsd.c,v 1.5 2002/03/12 16:54:36 in2 Exp $ */ +/* $Id: mbbsd.c,v 1.6 2002/03/14 08:17:45 in2 Exp $ */ #include <stdio.h> #include <string.h> #include <stdlib.h> @@ -320,11 +320,11 @@ extern char *fn_writelog; FILE *fp_writelog = NULL; void -show_last_call_in (int save) +show_call_in(int save, int which) { char buf[200]; sprintf (buf, "\033[1;33;46m★%s\033[37;45m %s \033[m", - currutmp->msgs[0].userid, currutmp->msgs[0].last_call_in); + currutmp->msgs[which].userid, currutmp->msgs[which].last_call_in); move (b_lines, 0); clrtoeol (); refresh (); @@ -416,66 +416,91 @@ add_history(msgque_t *msg) return i; } -static void +void write_request (int sig) { + int i; + /* struct tm *ptime; time_t now; time (&now); ptime = localtime (&now); - - if (!WATERMODE(WATER_OFO) && - currutmp->mode != 0 && - currutmp->pager != 0 && - cuser.userlevel != 0 && - currutmp->msgcount != 0 && - currutmp->mode != TALK && - currutmp->mode != EDITING && - currutmp->mode != CHATING && - currutmp->mode != PAGE && - currutmp->mode != IDLE && - currutmp->mode != MAILALL && currutmp->mode != MONITOR){ - int i; - char c0 = currutmp->chatid[0]; - int currstat0 = currstat; - unsigned char mode0 = currutmp->mode; - - currutmp->mode = 0; - currutmp->chatid[0] = 2; - currstat = XMODE; - - do{ + */ + if( WATERMODE(WATER_OFO) ){ + /* sig = SIGUSR2 waterball come in + 0 flush to water[] (by my_write2()) + */ + if( sig != 0 ){ + if( watermode == 0 ) /* 正在回水球 */ + watermode = 1; bell (); - show_last_call_in (1); - igetch (); - currutmp->msgcount--; - if (currutmp->msgcount >= MAX_MSGS){ - /* this causes chaos... jochang */ - raise (SIGFPE); + show_call_in(1, currutmp->msgcount - 1); + refresh (); + } + + if( sig == 0 || /* 回水球的時候又有水球進來, 回完後一次寫回去 */ + watermode == -1 ){ /* 不在回水球模式 */ + do{ + add_history(&currutmp->msgs[0]); + for (i = 0; i < currutmp->msgcount; i++) + currutmp->msgs[i] = currutmp->msgs[i + 1]; } - - add_history(&currutmp->msgs[0]); - for (i = 0; i < currutmp->msgcount; i++) - currutmp->msgs[i] = currutmp->msgs[i + 1]; + while (currutmp->msgcount); + currutmp->msgcount = 0; } - while (currutmp->msgcount); - currutmp->chatid[0] = c0; - currutmp->mode = mode0; - currstat = currstat0; } else{ - bell (); - show_last_call_in (1); - add_history(&currutmp->msgs[0]); - - refresh (); - currutmp->msgcount = 0; + if (currutmp->mode != 0 && + currutmp->pager != 0 && + cuser.userlevel != 0 && + currutmp->msgcount != 0 && + currutmp->mode != TALK && + currutmp->mode != EDITING && + currutmp->mode != CHATING && + currutmp->mode != PAGE && + currutmp->mode != IDLE && + currutmp->mode != MAILALL && currutmp->mode != MONITOR){ + char c0 = currutmp->chatid[0]; + int currstat0 = currstat; + unsigned char mode0 = currutmp->mode; + + currutmp->mode = 0; + currutmp->chatid[0] = 2; + currstat = XMODE; + + do{ + bell (); + show_call_in(1, 0); + igetch (); + currutmp->msgcount--; + if (currutmp->msgcount >= MAX_MSGS){ + /* this causes chaos... jochang */ + raise (SIGFPE); + } + + add_history(&currutmp->msgs[0]); + for (i = 0; i < currutmp->msgcount; i++) + currutmp->msgs[i] = currutmp->msgs[i + 1]; + } + while (currutmp->msgcount); + currutmp->chatid[0] = c0; + currutmp->mode = mode0; + currstat = currstat0; + } + else{ + bell (); + show_call_in(1, 0); + add_history(&currutmp->msgs[0]); + + refresh (); + currutmp->msgcount = 0; + } } } #if 0 -static void +void write_request (int sig) { int i, mtimemin, wu; @@ -512,7 +537,7 @@ write_request (int sig) water[wu].msgtop %= 5; bell (); - show_last_call_in (1); + show_call_in(1, 0); refresh(); if( watermode == 0 ){ /* in waterball selection mode diff --git a/pttbbs/mbbsd/talk.c b/pttbbs/mbbsd/talk.c index 5499d18f..5edf29a0 100644 --- a/pttbbs/mbbsd/talk.c +++ b/pttbbs/mbbsd/talk.c @@ -1,4 +1,4 @@ -/* $Id: talk.c,v 1.6 2002/03/12 16:54:36 in2 Exp $ */ +/* $Id: talk.c,v 1.7 2002/03/14 08:17:45 in2 Exp $ */ #include <stdio.h> #include <string.h> #include <errno.h> @@ -435,7 +435,7 @@ int my_query(char *uident) static char t_last_write[200] = ""; -void water_scr(water_t **currwater, int which, char type) +void water_scr(water_t *tw, int which, char type) { if( type == 1 ){ int i; @@ -443,24 +443,24 @@ void water_scr(water_t **currwater, int which, char type) move(8 + which, 28);prints(" "); move(8 + which, 28); prints("\033[1;37;45m %c %-14s \033[0m", - currwater[which]->alive ? ' ' : 'x', - currwater[which]->userid); + tw->alive ? ' ' : 'x', + tw->userid); for( i = 0 ; i < 5 ; ++i ){ move(16 + i, 4); prints(" "); move(16 + i, 4); - if( currwater[which]->msg[ (currwater[which]->top-i+4) % 5 ].last_call_in[0] != 0 ) + if( tw->msg[ (tw->top - i + 4) % 5 ].last_call_in[0] != 0 ) prints("\033[0m \033[1;%d;44m★%-64s\033[0m \n", colors[i], - currwater[which]->msg[ (currwater[which]->top-i+4) % 5 ].last_call_in); + tw->msg[ (tw->top - i + 4) % 5 ].last_call_in); else prints("\033[0m \n"); } move(0, 0);prints(" "); move(0, 0); - prints("\033[0m反擊 %s:", currwater[which]->userid); + prints("\033[0m反擊 %s:", tw->userid); clrtoeol(); - move(0, strlen(currwater[which]->userid) + 6); + move(0, strlen(tw->userid) + 6); } else{ move(8 + which, 28); @@ -468,17 +468,17 @@ void water_scr(water_t **currwater, int which, char type) // refresh(); move(8 + which, 28); prints("\033[1;37;44m %c %-13s \033[0m", - currwater[which]->alive ? ' ' : 'x', - currwater[which]->userid); + tw->alive ? ' ' : 'x', + tw->userid); // refresh(); } } void my_write2(void) { - int i, ch, currstat0, currwater_usies; + int i, ch, currstat0; char genbuf[256], msg[80], done = 0, c0, which; - water_t *tw, *currwater[5]; + water_t *tw; unsigned char mode0; watermode = 0; @@ -490,19 +490,17 @@ void my_write2(void) currstat = XMODE; // init screen - memcpy(currwater, swater, sizeof(water_t*) * 5); - currwater_usies = water_usies; move(7, 28); prints("\033[1;33;46m ↑ 水球反擊對象 ↓\033[0m"); for( i = 0 ; i < 5 ; ++i ) - if( currwater[i] == NULL || currwater[i]->pid == 0 ) + if( swater[i] == NULL || swater[i]->pid == 0 ) break; else{ - if( currwater[i]->alive && - (currwater[i]->pid != currwater[i]->uin->pid || - strcmp(currwater[i]->userid, currwater[i]->uin->userid)) ) - currwater[i]->alive = 0; - water_scr(currwater, i, 0); + if( swater[i]->alive && + (swater[i]->pid != swater[i]->uin->pid || + strcmp(swater[i]->userid, swater[i]->uin->userid)) ) + swater[i]->alive = 0; + water_scr(swater[i], i, 0); } move(15, 4); prints("\033[0m \033[1;35m◇\033[1;36m────────────────" @@ -513,7 +511,7 @@ void my_write2(void) move(21, 4);prints(" "); move(21, 4); prints("\033[0m \033[1;37;46m%-66s\033[0m \n", t_last_write); - water_scr(currwater, 0, 1); + water_scr(swater[0], 0, 1); refresh(); which = 0; @@ -521,20 +519,20 @@ void my_write2(void) switch( (ch = igetkey()) ){ case Ctrl('T'): case KEY_UP: - if( currwater_usies != 1 ){ - water_scr(currwater, which, 0); - which = (which - 1 + currwater_usies) % currwater_usies; - water_scr(currwater, which, 1); + if( water_usies != 1 ){ + water_scr(swater[(int)which], which, 0); + which = (which - 1 + water_usies) % water_usies; + water_scr(swater[(int)which], which, 1); refresh(); } break; case KEY_DOWN: case Ctrl('R'): - if( currwater_usies != 1 ){ - water_scr(currwater, which, 0); - which = (which + 1 + currwater_usies) % currwater_usies; - water_scr(currwater, which, 1); + if( water_usies != 1 ){ + water_scr(swater[(int)which], which, 0); + which = (which + 1 + water_usies) % water_usies; + water_scr(swater[(int)which], which, 1); refresh(); } break; @@ -545,8 +543,7 @@ void my_write2(void) default: done = 1; - watermode = 1; - tw = currwater[(int)which]; + tw = swater[(int)which]; if( !tw->alive ) break; @@ -568,10 +565,12 @@ void my_write2(void) } } while( !done ); - watermode = -1; currstat = currstat0; currutmp->chatid[0] = c0; currutmp->mode = mode0; + if( watermode == 1 ) + write_request(0); + watermode = -1; } /* @@ -2356,7 +2355,7 @@ void talkreply(void) prints("對方來自 [%s],共上站 %d 次,文章 %d 篇\n", uip->from, xuser.numlogins, xuser.numposts); showplans(uip->userid); - show_last_call_in(0); + show_call_in(0, 0); sprintf(genbuf, "你想跟 %s %s啊?請選擇(Y/N/A/B/C/D/E/F/1/2)[N] ", page_requestor, sig_des[sig]); -- cgit v1.2.3 From 58979cf46f83acf7c36bc744bbbaffcd08c757c3 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Thu, 14 Mar 2002 08:44:48 +0000 Subject: use /proc and check permission git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@24 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/bbsctl.c | 82 +++++++++++++++++++++++++++++++++------------------- 1 file changed, 52 insertions(+), 30 deletions(-) diff --git a/pttbbs/util/bbsctl.c b/pttbbs/util/bbsctl.c index 62d00300..db158c77 100644 --- a/pttbbs/util/bbsctl.c +++ b/pttbbs/util/bbsctl.c @@ -5,16 +5,14 @@ #include <signal.h> #include <sys/types.h> #include <grp.h> +#include <dirent.h> + #ifdef FreeBSD #include <sys/syslimits.h> - #define PS "/bin/ps" - #define GREP "/usr/bin/grep" #define SU "/usr/bin/su" #endif #ifdef Linux #include <linux/limits.h> - #define PS "/bin/ps" - #define GREP "/bin/grep" #define SU "/bin/su" #endif @@ -24,6 +22,29 @@ void usage(void) exit(0); } +int HaveBBSADM(void) +{ + gid_t gids[NGROUPS_MAX]; + int i, ngids; + struct group *gr; + ngids = getgroups(NGROUPS_MAX, gids); + if( (gr = getgrnam("bbsadm")) == NULL ){ + puts("group bbsadm not found"); + return 0; + } + + for( i = 0 ; i < ngids ; ++i ) + if( gr->gr_gid == gids[i] ) + break; + + if( i == ngids ){ + puts("permission denied"); + return 0; + } + + return 1; +} + void startbbs(void) { if( setuid(0) < 0 ){ @@ -46,43 +67,42 @@ void startbbs(void) void stopbbs(void) { - char buf[1024]; - int pid; - FILE *fp = popen(PS " -ax | " GREP " mbbsd | " - GREP " listen", "r"); - while( fgets(buf, sizeof(buf), fp) != NULL ){ - sscanf(buf, "%d", &pid); - printf("stopping %d\n", pid); - kill(pid, 1); + DIR *dirp; + struct dirent *de; + FILE *fp; + char buf[512]; + if( !(dirp = opendir("/proc")) ){ + perror("open /proc"); + exit(0); + } + + while( (de = readdir(dirp)) ){ + if( de->d_type & DT_DIR ){ + sprintf(buf, "/proc/%s/cmdline", de->d_name); + if( (fp = fopen(buf, "r")) ){ + if( fgets(buf, sizeof(buf), fp) != NULL ){ + if( strstr(buf, "mbbsd") && strstr(buf, "listening") ){ + kill(atoi(de->d_name), 1); + printf("stopping mbbsd at pid %5d\n", atoi(de->d_name)); + } + } + fclose(fp); + } + } } + + closedir(dirp); } void restartbbs(void) { stopbbs(); + sleep(1); startbbs(); } void bbsadm(void) { - gid_t gids[NGROUPS_MAX]; - int i, ngids; - struct group *gr; - ngids = getgroups(NGROUPS_MAX, gids); - if( (gr = getgrnam("bbsadm")) == NULL ){ - puts("group bbsadm not found"); - return; - } - - for( i = 0 ; i < ngids ; ++i ) - if( gr->gr_gid == gids[i] ) - break; - - if( i == ngids ){ - puts("permission denied"); - return; - } - if( setuid(0) < 0 ){ perror("setuid(0)"); return; @@ -105,6 +125,8 @@ int main(int argc, char **argv) int i; if( argc == 1 ) usage(); + if( !HaveBBSADM() ) + return 1; for( i = 0 ; cmds[i].cmd != NULL ; ++i ) if( strcmp(cmds[i].cmd, argv[1]) == 0 ){ cmds[i].func(); -- cgit v1.2.3 From 1817f1e7c32a9dfece9f82ac1b9ae7f9d8a0c6a8 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Thu, 14 Mar 2002 10:14:55 +0000 Subject: fix bugs git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@25 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/mbbsd.c | 7 ++++--- pttbbs/mbbsd/talk.c | 19 ++++++++++++++----- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/pttbbs/mbbsd/mbbsd.c b/pttbbs/mbbsd/mbbsd.c index 3a38aabb..975e2b3c 100644 --- a/pttbbs/mbbsd/mbbsd.c +++ b/pttbbs/mbbsd/mbbsd.c @@ -1,4 +1,4 @@ -/* $Id: mbbsd.c,v 1.6 2002/03/14 08:17:45 in2 Exp $ */ +/* $Id: mbbsd.c,v 1.7 2002/03/14 10:14:55 in2 Exp $ */ #include <stdio.h> #include <string.h> #include <stdlib.h> @@ -443,8 +443,9 @@ write_request (int sig) watermode == -1 ){ /* 不在回水球模式 */ do{ add_history(&currutmp->msgs[0]); - for (i = 0; i < currutmp->msgcount; i++) - currutmp->msgs[i] = currutmp->msgs[i + 1]; + if( currutmp->msgcount-- ) + for (i = 0; i < currutmp->msgcount; i++) + currutmp->msgs[i] = currutmp->msgs[i + 1]; } while (currutmp->msgcount); currutmp->msgcount = 0; diff --git a/pttbbs/mbbsd/talk.c b/pttbbs/mbbsd/talk.c index 5edf29a0..8bf45197 100644 --- a/pttbbs/mbbsd/talk.c +++ b/pttbbs/mbbsd/talk.c @@ -1,4 +1,4 @@ -/* $Id: talk.c,v 1.7 2002/03/14 08:17:45 in2 Exp $ */ +/* $Id: talk.c,v 1.8 2002/03/14 10:14:55 in2 Exp $ */ #include <stdio.h> #include <string.h> #include <errno.h> @@ -456,9 +456,14 @@ void water_scr(water_t *tw, int which, char type) else prints("\033[0m \n"); } + + move(21, 4);prints(" "); + move(21, 4); + prints("\033[0m \033[1;37;46m%-66s\033[0m \n", + tw->msg[5].last_call_in); + move(0, 0);prints(" "); - move(0, 0); - prints("\033[0m反擊 %s:", tw->userid); + move(0, 0);prints("\033[0m反擊 %s:", tw->userid); clrtoeol(); move(0, strlen(tw->userid) + 6); } @@ -508,9 +513,11 @@ void my_write2(void) move(22, 4); prints(" \033[1;35m◇\033[1;36m────────────────" "─────────────────\033[1;35m◇\033[0m "); + /* move(21, 4);prints(" "); move(21, 4); prints("\033[0m \033[1;37;46m%-66s\033[0m \n", t_last_write); + */ water_scr(swater[0], 0, 1); refresh(); @@ -560,7 +567,9 @@ void my_write2(void) 80-strlen(tw->userid)-6, DOECHO) ) break; - my_write(tw->pid, msg, tw->userid, 4, tw->uin); + if( my_write(tw->pid, msg, tw->userid, 4, tw->uin) ) + strncpy(tw->msg[5].last_call_in, t_last_write, + sizeof(tw->msg[5].last_call_in)); break; } } while( !done ); @@ -701,7 +710,7 @@ int my_write(pid_t pid, char *prompt, char *id, int flag, userinfo_t *puin) } else if (flag != 2) outmsg("\033[1;33;41m糟糕! 對方不行了! (收到太多水球) \033[37m@_@\033[m"); - if(uin->msgcount == 1 && (uin->pid <= 0 || kill(uin->pid, SIGUSR2) == -1) && flag != 2) + if(uin->msgcount >= 1 && (uin->pid <= 0 || kill(uin->pid, SIGUSR2) == -1) && flag != 2) outmsg("\033[1;33;41m糟糕! 沒打中! \033[37m~>_<~\033[m"); else if(uin->msgcount == 1 && flag != 2) outmsg("\033[1;33;44m水球砸過去了! \033[37m*^o^*\033[m"); -- cgit v1.2.3 From 281a6fa96763c865e6dc6b1e3b88c750a47c5d29 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Thu, 14 Mar 2002 20:49:38 +0000 Subject: fix bug of ofo's waterball git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@26 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/io.c | 24 +++++++++++++----------- pttbbs/mbbsd/talk.c | 13 ++++++++----- 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/pttbbs/mbbsd/io.c b/pttbbs/mbbsd/io.c index c0e796df..bbc3baa5 100644 --- a/pttbbs/mbbsd/io.c +++ b/pttbbs/mbbsd/io.c @@ -1,4 +1,4 @@ -/* $Id: io.c,v 1.3 2002/03/14 08:17:45 in2 Exp $ */ +/* $Id: io.c,v 1.4 2002/03/14 20:49:38 in2 Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -336,18 +336,20 @@ int igetch() { return ch; case Ctrl('W'): - if(watermode >0) - { - water_which_flag=(water_which_flag+water_usies)%(water_usies+1); - if(water_which_flag==0) + if( WATERMODE(WATER_NEW) ){ + if( watermode > 0 ){ + water_which_flag=(water_which_flag+water_usies)%(water_usies+1); + if(water_which_flag==0) water_which = &water[0]; - else + else water_which = swater[water_which_flag-1]; - watermode = 1; - t_display_new(); - continue; - } - else return ch; + watermode = 1; + t_display_new(); + continue; + } + } + return ch; + default: return ch; } diff --git a/pttbbs/mbbsd/talk.c b/pttbbs/mbbsd/talk.c index 8bf45197..c87277d6 100644 --- a/pttbbs/mbbsd/talk.c +++ b/pttbbs/mbbsd/talk.c @@ -1,4 +1,4 @@ -/* $Id: talk.c,v 1.8 2002/03/14 10:14:55 in2 Exp $ */ +/* $Id: talk.c,v 1.9 2002/03/14 20:49:38 in2 Exp $ */ #include <stdio.h> #include <string.h> #include <errno.h> @@ -607,7 +607,8 @@ int my_write(pid_t pid, char *prompt, char *id, int flag, userinfo_t *puin) outmsg("\033[1;33;41m糟糕! 對方已落跑了(不在站上)! \033[37m~>_<~\033[m"); clrtoeol(); refresh(); - watermode = -1; + if( !WATERMODE(WATER_OFO) ) + watermode = -1; return 0; } currutmp->mode = 0; @@ -655,12 +656,14 @@ int my_write(pid_t pid, char *prompt, char *id, int flag, userinfo_t *puin) currutmp->chatid[0] = c0; currutmp->mode = mode0; currstat = currstat0; - watermode = -1; + if( !WATERMODE(WATER_OFO) ) + watermode = -1; return 0; } } - watermode = -1; + if( !WATERMODE(WATER_OFO) ) + watermode = -1; if(!uin || !*uin->userid || strcasecmp(destid, uin->userid)) { outmsg("\033[1;33;41m糟糕! 對方已落跑了(不在站上)! \033[37m~>_<~\033[m"); clrtoeol(); @@ -793,7 +796,7 @@ void t_display_new(void) move(i + off, 0); outs("──────────────────────" "─────────────────"); - if( WATERMODE(WATER_NEW)) + if( WATERMODE(WATER_NEW) ) while( i++ <= water[0].count ) { move(i + off, 0); clrtoeol(); -- cgit v1.2.3 From 692352b148d21ed4e9b9ef0fe477a1182d645e91 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Fri, 15 Mar 2002 14:39:25 +0000 Subject: fix bug git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@27 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/io.c | 12 ++++---- pttbbs/mbbsd/mbbsd.c | 82 +++++----------------------------------------------- pttbbs/mbbsd/talk.c | 19 +++++------- 3 files changed, 21 insertions(+), 92 deletions(-) diff --git a/pttbbs/mbbsd/io.c b/pttbbs/mbbsd/io.c index bbc3baa5..a5690bb4 100644 --- a/pttbbs/mbbsd/io.c +++ b/pttbbs/mbbsd/io.c @@ -1,4 +1,4 @@ -/* $Id: io.c,v 1.4 2002/03/14 20:49:38 in2 Exp $ */ +/* $Id: io.c,v 1.5 2002/03/15 14:39:25 in2 Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -123,7 +123,7 @@ int num_in_buf() { return icurrchar - ibufsize; } -int watermode = -1; +int watermode = -1, wmofo = -1; /* WATERMODE(WATER_ORIG) | WATERMODE(WATER_NEW): Ptt 水球回顧用的參數 @@ -132,10 +132,10 @@ int watermode = -1; > 0 在回前 n 顆水球 (Ctrl-R Ctrl-R) WATERMODE(WATER_OFO) by in2 - watermode = -1 沒在回水球 + wmofo = -1 沒在回水球 = 0 正在回水球 = 1 回水球間又接到水球 - watermode >=0 時收到水球將只顯示, 不會到water[]裡, + wmofo >=0 時收到水球將只顯示, 不會到water[]裡, 待回完水球的時候一次寫入. */ @@ -284,7 +284,7 @@ int igetch() { } if( currutmp->msgs[0].pid && - WATERMODE(WATER_OFO) && watermode == -1 ){ + WATERMODE(WATER_OFO) && wmofo == -1 ){ int y, x, my_newfd; screenline_t *screen0 = calloc(t_lines, sizeof(screenline_t)); memcpy(screen0, big_picture, t_lines * sizeof(screenline_t)); @@ -317,7 +317,7 @@ int igetch() { return (ch); case Ctrl('E'): - if( WATERMODE(WATER_ORIG) || WATERMODE(WATER_NEW) ){ + if( WATERMODE(WATER_NEW) ){ if(watermode >0){ if( water_which_flag == (int)water_usies ) water_which_flag = 0; diff --git a/pttbbs/mbbsd/mbbsd.c b/pttbbs/mbbsd/mbbsd.c index 975e2b3c..5ed7dcdf 100644 --- a/pttbbs/mbbsd/mbbsd.c +++ b/pttbbs/mbbsd/mbbsd.c @@ -1,4 +1,4 @@ -/* $Id: mbbsd.c,v 1.7 2002/03/14 10:14:55 in2 Exp $ */ +/* $Id: mbbsd.c,v 1.8 2002/03/15 14:39:25 in2 Exp $ */ #include <stdio.h> #include <string.h> #include <stdlib.h> @@ -347,7 +347,7 @@ show_call_in(int save, int which) extern unsigned int currstat; water_t water[6], *swater[6], *water_which=&water[0]; char water_usies=0; -extern int watermode; +extern int watermode, wmofo; static int add_history_water(water_t *w, msgque_t *msg, char mode) { // mode: 1: all data(including userid, pid); @@ -420,27 +420,21 @@ void write_request (int sig) { int i; - /* - struct tm *ptime; - time_t now; - - time (&now); - ptime = localtime (&now); - */ + if( WATERMODE(WATER_OFO) ){ /* sig = SIGUSR2 waterball come in 0 flush to water[] (by my_write2()) */ if( sig != 0 ){ - if( watermode == 0 ) /* 正在回水球 */ - watermode = 1; + if( wmofo == 0 ) /* 正在回水球 */ + wmofo = 1; bell (); show_call_in(1, currutmp->msgcount - 1); refresh (); } - if( sig == 0 || /* 回水球的時候又有水球進來, 回完後一次寫回去 */ - watermode == -1 ){ /* 不在回水球模式 */ + if( sig == 0 || /* 回水球的時候又有水球進來, 回完後一次寫回去 */ + wmofo == -1 ){ /* 不在回水球模式 */ do{ add_history(&currutmp->msgs[0]); if( currutmp->msgcount-- ) @@ -500,68 +494,6 @@ write_request (int sig) } } -#if 0 -void -write_request (int sig) -{ - int i, mtimemin, wu; - static char inlock = 0; - if( inlock ) /* 如果已經進來了 (表示上個水球還沒有處理完, - 新的水球又進來) 則不做任何事直接 return */ - return; - inlock = 1; - do{ - for( wu = 0 ; wu < 5 ; ++wu ) - if( water[wu].pid == currutmp->msgs[0].pid ) - break; - if( wu == 5 ){ - for( i = 0, mtimemin = INT_MAX ; i < 5 ; ++i ) - if( water[i].pid == 0 ){ - ++water_usies; - wu = i; - break; - } - else if( water[i].mtime < mtimemin ){ - mtimemin = water[i].mtime; - wu = i; - } - water[wu].pid = currutmp->msgs[0].pid; - strcpy(water[wu].userid, currutmp->msgs[0].userid); - water[wu].msgtop = 0; - for( i = 0 ; i < 5 ; ++i ) - water[wu].msg[i][0] = 0; - } - water[wu].mtime = time(NULL); - strncpy(water[wu].msg[ (int)water[wu].msgtop ], - currutmp->msgs[0].last_call_in, 64); - ++water[wu].msgtop; - water[wu].msgtop %= 5; - - bell (); - show_call_in(1, 0); - refresh(); - - if( watermode == 0 ){ /* in waterball selection mode - if( wu != 0 ){ - water_scr(water_which, 0); - qsort(water, 5, sizeof(water_t), cmpwatermtime); - for( i = 0 ; i < 5 ; ++i ) - if( water[i].pid == 0 ) - break; - else - water_scr(i, 0); - water_scr(water_which = 0, 1); - refresh(); - } */ - } - --currutmp->msgcount; - for( i = 0 ; i < currutmp->msgcount - 1 ; ++i ) - currutmp->msgs[i] = currutmp->msgs[i + 1]; - } while( currutmp->msgcount > 0 ); - inlock = 0; -} -#endif - static void multi_user_check () { diff --git a/pttbbs/mbbsd/talk.c b/pttbbs/mbbsd/talk.c index c87277d6..7af93287 100644 --- a/pttbbs/mbbsd/talk.c +++ b/pttbbs/mbbsd/talk.c @@ -1,4 +1,4 @@ -/* $Id: talk.c,v 1.9 2002/03/14 20:49:38 in2 Exp $ */ +/* $Id: talk.c,v 1.10 2002/03/15 14:39:25 in2 Exp $ */ #include <stdio.h> #include <string.h> #include <errno.h> @@ -76,7 +76,7 @@ typedef struct pickup_t { extern int bind( /* int,struct sockaddr *, int */ ); extern char *getuserid(); extern struct utmpfile_t *utmpshm; -extern int watermode; +extern int watermode, wmofo; extern water_t water[6], *swater[5], *water_which; extern char *friend_file[8], water_usies; @@ -486,7 +486,7 @@ void my_write2(void) water_t *tw; unsigned char mode0; - watermode = 0; + wmofo = 0; currstat0 = currstat; c0 = currutmp->chatid[0]; mode0 = currutmp->mode; @@ -577,9 +577,9 @@ void my_write2(void) currstat = currstat0; currutmp->chatid[0] = c0; currutmp->mode = mode0; - if( watermode == 1 ) + if( wmofo == 1 ) write_request(0); - watermode = -1; + wmofo = -1; } /* @@ -607,8 +607,7 @@ int my_write(pid_t pid, char *prompt, char *id, int flag, userinfo_t *puin) outmsg("\033[1;33;41m糟糕! 對方已落跑了(不在站上)! \033[37m~>_<~\033[m"); clrtoeol(); refresh(); - if( !WATERMODE(WATER_OFO) ) - watermode = -1; + watermode = -1; return 0; } currutmp->mode = 0; @@ -656,14 +655,12 @@ int my_write(pid_t pid, char *prompt, char *id, int flag, userinfo_t *puin) currutmp->chatid[0] = c0; currutmp->mode = mode0; currstat = currstat0; - if( !WATERMODE(WATER_OFO) ) - watermode = -1; + watermode = -1; return 0; } } - if( !WATERMODE(WATER_OFO) ) - watermode = -1; + watermode = -1; if(!uin || !*uin->userid || strcasecmp(destid, uin->userid)) { outmsg("\033[1;33;41m糟糕! 對方已落跑了(不在站上)! \033[37m~>_<~\033[m"); clrtoeol(); -- cgit v1.2.3 From 4280bdf1d3a5efccae6aafbac851412be5c803ba Mon Sep 17 00:00:00 2001 From: ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sat, 16 Mar 2002 13:19:46 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@28 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/include/pttstruct.h | 6 +++--- pttbbs/mbbsd/Makefile | 4 ++-- pttbbs/mbbsd/io.c | 6 +++--- pttbbs/mbbsd/mbbsd.c | 24 ++++++++---------------- pttbbs/mbbsd/talk.c | 25 +++++++++++-------------- 5 files changed, 27 insertions(+), 38 deletions(-) diff --git a/pttbbs/include/pttstruct.h b/pttbbs/include/pttstruct.h index ea1e7d78..1fb3fc24 100644 --- a/pttbbs/include/pttstruct.h +++ b/pttbbs/include/pttstruct.h @@ -1,4 +1,4 @@ -/* $Id: pttstruct.h,v 1.2 2002/03/09 10:34:56 in2 Exp $ */ +/* $Id: pttstruct.h,v 1.3 2002/03/16 13:18:53 ptt Exp $ */ #ifndef INCLUDE_STRUCT_H #define INCLUDE_STRUCT_H @@ -253,10 +253,10 @@ typedef struct userinfo_t { typedef struct water_t { pid_t pid; - char userid[IDLEN + 1], alive; + char userid[IDLEN + 1]; int top, count; msgque_t msg[MAX_REVIEW]; - userinfo_t *uin; + userinfo_t *uin; // Ptt:這可以取代alive } water_t; typedef struct { diff --git a/pttbbs/mbbsd/Makefile b/pttbbs/mbbsd/Makefile index 61690e6c..6281e2fe 100644 --- a/pttbbs/mbbsd/Makefile +++ b/pttbbs/mbbsd/Makefile @@ -1,7 +1,7 @@ -# $Id: Makefile,v 1.2 2002/03/07 15:24:32 bbs Exp $ +# $Id: Makefile,v 1.3 2002/03/16 13:19:46 ptt Exp $ BBSHOME?=$(HOME) -OSTYPE=FreeBSD +OSTYPE=linux # FreeBSD CFLAGS_FreeBSD= -pipe -Wall -g -O3 -DHAVE_SETPROCTITLE -DBBSHOME='"$(BBSHOME)"' -DFreeBSD -I../include diff --git a/pttbbs/mbbsd/io.c b/pttbbs/mbbsd/io.c index a5690bb4..82c5d93c 100644 --- a/pttbbs/mbbsd/io.c +++ b/pttbbs/mbbsd/io.c @@ -1,4 +1,4 @@ -/* $Id: io.c,v 1.5 2002/03/15 14:39:25 in2 Exp $ */ +/* $Id: io.c,v 1.6 2002/03/16 13:18:59 ptt Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -316,7 +316,7 @@ int igetch() { } return (ch); - case Ctrl('E'): + case Ctrl('F'): if( WATERMODE(WATER_NEW) ){ if(watermode >0){ if( water_which_flag == (int)water_usies ) @@ -335,7 +335,7 @@ int igetch() { } return ch; - case Ctrl('W'): + case Ctrl('G'): if( WATERMODE(WATER_NEW) ){ if( watermode > 0 ){ water_which_flag=(water_which_flag+water_usies)%(water_usies+1); diff --git a/pttbbs/mbbsd/mbbsd.c b/pttbbs/mbbsd/mbbsd.c index 5ed7dcdf..b55cbe23 100644 --- a/pttbbs/mbbsd/mbbsd.c +++ b/pttbbs/mbbsd/mbbsd.c @@ -1,4 +1,4 @@ -/* $Id: mbbsd.c,v 1.8 2002/03/15 14:39:25 in2 Exp $ */ +/* $Id: mbbsd.c,v 1.9 2002/03/16 13:18:59 ptt Exp $ */ #include <stdio.h> #include <string.h> #include <stdlib.h> @@ -348,15 +348,11 @@ extern unsigned int currstat; water_t water[6], *swater[6], *water_which=&water[0]; char water_usies=0; extern int watermode, wmofo; -static int add_history_water(water_t *w, msgque_t *msg, char mode) +static int add_history_water(water_t *w, msgque_t *msg) { // mode: 1: all data(including userid, pid); - // 0: only last_call_in - if( mode ) - memcpy(&w->msg[w->top], msg, sizeof(msgque_t)); - else - memcpy(&w->msg[w->top].last_call_in, msg->last_call_in, - sizeof(msg->last_call_in)); + // 0: only last_call_in Ptt:先改回來 省不多 進階會有問題 + memcpy(&w->msg[w->top], msg, sizeof(msgque_t)); w->top++; w->top %= WATERMODE(WATER_OFO) ? 5 : MAX_REVIEW; @@ -372,7 +368,7 @@ add_history(msgque_t *msg) int i = 0, j; water_t *tmp; if( WATERMODE(WATER_ORIG) || WATERMODE(WATER_NEW) ) - add_history_water(&water[0], msg, 1); + add_history_water(&water[0], msg); if( WATERMODE(WATER_NEW) || WATERMODE(WATER_OFO) ){ for(i = 0 ; i < 5 && swater[i] ; i++ ) if( swater[i]->pid == msg->pid ) @@ -397,7 +393,7 @@ add_history(msgque_t *msg) for( j = i ; j > 0 ; j-- ) swater[j] = swater[j - 1]; swater[0] = tmp; - add_history_water(swater[0], msg, 0); + add_history_water(swater[0], msg); } if(WATERMODE(WATER_ORIG) || WATERMODE(WATER_NEW) ){ @@ -407,12 +403,8 @@ add_history(msgque_t *msg) watermode++; t_display_new(); } - } - - if( WATERMODE(WATER_OFO) ){ - swater[0]->uin = (userinfo_t *)search_ulist_pid(swater[0]->pid); - swater[0]->alive = (swater[0]->uin != NULL); - } + }else + swater[0]->uin = (userinfo_t *)search_ulist_pid(swater[0]->pid); return i; } diff --git a/pttbbs/mbbsd/talk.c b/pttbbs/mbbsd/talk.c index 7af93287..a00b49ef 100644 --- a/pttbbs/mbbsd/talk.c +++ b/pttbbs/mbbsd/talk.c @@ -1,4 +1,4 @@ -/* $Id: talk.c,v 1.10 2002/03/15 14:39:25 in2 Exp $ */ +/* $Id: talk.c,v 1.11 2002/03/16 13:18:59 ptt Exp $ */ #include <stdio.h> #include <string.h> #include <errno.h> @@ -443,7 +443,7 @@ void water_scr(water_t *tw, int which, char type) move(8 + which, 28);prints(" "); move(8 + which, 28); prints("\033[1;37;45m %c %-14s \033[0m", - tw->alive ? ' ' : 'x', + tw->uin ? ' ' : 'x', tw->userid); for( i = 0 ; i < 5 ; ++i ){ move(16 + i, 4); @@ -473,7 +473,7 @@ void water_scr(water_t *tw, int which, char type) // refresh(); move(8 + which, 28); prints("\033[1;37;44m %c %-13s \033[0m", - tw->alive ? ' ' : 'x', + tw->uin ? ' ' : 'x', tw->userid); // refresh(); } @@ -501,10 +501,10 @@ void my_write2(void) if( swater[i] == NULL || swater[i]->pid == 0 ) break; else{ - if( swater[i]->alive && + if( swater[i]->uin && (swater[i]->pid != swater[i]->uin->pid || strcmp(swater[i]->userid, swater[i]->uin->userid)) ) - swater[i]->alive = 0; + swater[i]->uin = NULL; water_scr(swater[i], i, 0); } move(15, 4); @@ -513,11 +513,6 @@ void my_write2(void) move(22, 4); prints(" \033[1;35m◇\033[1;36m────────────────" "─────────────────\033[1;35m◇\033[0m "); - /* - move(21, 4);prints(" "); - move(21, 4); - prints("\033[0m \033[1;37;46m%-66s\033[0m \n", t_last_write); - */ water_scr(swater[0], 0, 1); refresh(); @@ -552,7 +547,7 @@ void my_write2(void) done = 1; tw = swater[(int)which]; - if( !tw->alive ) + if( !tw->uin ) break; if( ch != '\r' && ch != '\n' ){ @@ -753,13 +748,15 @@ void t_display_new(void) for (i = 0; i<6 ; i++){ if(i>0) prints("%s%-13.13s\033[m", + !swater[i-1]->uin?"\033[1;33;45mX": swater[i-1]==water_which?"\033[1;33;47m ": - " ", + "", swater[i-1] ? swater[i-1]->userid:""); else prints("%s 全部 \033[m", - water_which==&water[0]?"\033[1;33;45m ": - " "); + water_which==&water[0]?"\033[1;33;47m ": + " " + ); } } -- cgit v1.2.3 From 6d0ea245ad8aefbdedf0f5932cb448e9509823a1 Mon Sep 17 00:00:00 2001 From: ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sat, 16 Mar 2002 13:38:36 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@29 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/talk.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/pttbbs/mbbsd/talk.c b/pttbbs/mbbsd/talk.c index a00b49ef..8516a5a9 100644 --- a/pttbbs/mbbsd/talk.c +++ b/pttbbs/mbbsd/talk.c @@ -1,4 +1,4 @@ -/* $Id: talk.c,v 1.11 2002/03/16 13:18:59 ptt Exp $ */ +/* $Id: talk.c,v 1.12 2002/03/16 13:38:36 ptt Exp $ */ #include <stdio.h> #include <string.h> #include <errno.h> @@ -747,11 +747,13 @@ void t_display_new(void) clrtoeol(); for (i = 0; i<6 ; i++){ if(i>0) + if(swater[i-1]) prints("%s%-13.13s\033[m", - !swater[i-1]->uin?"\033[1;33;45mX": + !swater[i-1]->uin?"\033[1;33;45mX": swater[i-1]==water_which?"\033[1;33;47m ": - "", - swater[i-1] ? swater[i-1]->userid:""); + " ",swater[i-1]->userid); + else + prints(" "); else prints("%s 全部 \033[m", water_which==&water[0]?"\033[1;33;47m ": -- cgit v1.2.3 From a590c39a8108697749c44ab8020a89eaf8ad6297 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sat, 16 Mar 2002 13:47:12 +0000 Subject: add test git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@30 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/bbsctl.c | 36 +++++++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/pttbbs/util/bbsctl.c b/pttbbs/util/bbsctl.c index db158c77..1020f7d2 100644 --- a/pttbbs/util/bbsctl.c +++ b/pttbbs/util/bbsctl.c @@ -9,16 +9,25 @@ #ifdef FreeBSD #include <sys/syslimits.h> - #define SU "/usr/bin/su" + #define SU "/usr/bin/su" + #define CP "/bin/cp" + #define KILLALL "/usr/bin/killall" #endif #ifdef Linux #include <linux/limits.h> - #define SU "/bin/su" + #define SU "/bin/su" + #define CP "/bin/cp" + #define KILLALL "/usr/bin/killall" #endif void usage(void) { - printf("usage: bbsctl [start|stop|restart|bbsadm]\n"); + printf("usage: bbsctl [start|stop|restart|bbsadm|test]\n" + " bbsctl start start mbbsd at 23,3000-3010\n" + " bbsctl stop killall listening mbbsd\n" + " bbsctl restart stop + start\n" + " bbsctl bbsadm su to bbsadm\n" + " bbsctl test use bbsadm permission to exec ./mbbsd 9000\n"); exit(0); } @@ -111,6 +120,26 @@ void bbsadm(void) execl(SU, "su", "bbsadm", NULL); } +void bbstest(void) +{ + if( access("mbbsd", 0) < 0 ){ + perror("./mbbsd"); + return; + } + system(CP " -f mbbsd testmbbsd"); + if( setuid(0) < 0 ){ + perror("setuid(0)"); + return; + } + if( setuid(9999) < 0 ){ + perror("setuid(9999)"); + return; + } + system(KILLALL " testmbbsd"); + execl("./testmbbsd", "testmbbsd", "9000", NULL); + perror("execl()"); +} + struct { char *cmd; void (*func)(); @@ -118,6 +147,7 @@ struct { {"stop", stopbbs}, {"restart", restartbbs}, {"bbsadm", bbsadm}, + {"test", bbstest}, {NULL, NULL} }; int main(int argc, char **argv) -- cgit v1.2.3 From f8f2c485554dfbb68b0abbb951785873e1e99d40 Mon Sep 17 00:00:00 2001 From: ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sat, 16 Mar 2002 15:11:10 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@31 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/io.c | 46 ++++++++++++++++++++++------------------------ pttbbs/mbbsd/mbbsd.c | 9 +++++---- pttbbs/mbbsd/talk.c | 19 +++++++++++++------ 3 files changed, 40 insertions(+), 34 deletions(-) diff --git a/pttbbs/mbbsd/io.c b/pttbbs/mbbsd/io.c index 82c5d93c..b0331074 100644 --- a/pttbbs/mbbsd/io.c +++ b/pttbbs/mbbsd/io.c @@ -1,4 +1,4 @@ -/* $Id: io.c,v 1.6 2002/03/16 13:18:59 ptt Exp $ */ +/* $Id: io.c,v 1.7 2002/03/16 15:11:09 ptt Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -240,7 +240,25 @@ int igetch() { case Ctrl('R'): if(currutmp == NULL) return (ch); - if( WATERMODE(WATER_ORIG) || WATERMODE(WATER_NEW) ){ + + if( currutmp->msgs[0].pid && + WATERMODE(WATER_OFO) && wmofo == -1 ){ + int y, x, my_newfd; + screenline_t *screen0 = calloc(t_lines, sizeof(screenline_t)); + memcpy(screen0, big_picture, t_lines * sizeof(screenline_t)); + getyx(&y, &x); + my_newfd = i_newfd; + i_newfd = 0; + my_write2(); + memcpy(big_picture, screen0, t_lines * sizeof(screenline_t)); + i_newfd = my_newfd; + move(y, x); + free(screen0); + redoscr(); + continue; + } + else if(!WATERMODE(WATER_OFO)) + { if( watermode > 0 ){ watermode = (watermode + water_which->count) % water_which->count + 1; @@ -255,7 +273,7 @@ int igetch() { t_display_new(); continue; } - else if(currutmp->msgs[0].pid) { + else if(watermode==-1 && currutmp->msgs[0].pid) { /* 第一次按 Ctrl-R (必須先被丟過水球) */ screenline_t *screen0; int y, x, my_newfd; @@ -279,27 +297,7 @@ int igetch() { redoscr(); continue; } - else - return ch; - } - - if( currutmp->msgs[0].pid && - WATERMODE(WATER_OFO) && wmofo == -1 ){ - int y, x, my_newfd; - screenline_t *screen0 = calloc(t_lines, sizeof(screenline_t)); - memcpy(screen0, big_picture, t_lines * sizeof(screenline_t)); - getyx(&y, &x); - my_newfd = i_newfd; - i_newfd = 0; - my_write2(); - memcpy(big_picture, screen0, t_lines * sizeof(screenline_t)); - i_newfd = my_newfd; - move(y, x); - free(screen0); - redoscr(); - continue; - } - + } return ch; case '\n': /* Ptt把 \n拿掉 */ continue; diff --git a/pttbbs/mbbsd/mbbsd.c b/pttbbs/mbbsd/mbbsd.c index b55cbe23..265a4d74 100644 --- a/pttbbs/mbbsd/mbbsd.c +++ b/pttbbs/mbbsd/mbbsd.c @@ -1,4 +1,4 @@ -/* $Id: mbbsd.c,v 1.9 2002/03/16 13:18:59 ptt Exp $ */ +/* $Id: mbbsd.c,v 1.10 2002/03/16 15:11:10 ptt Exp $ */ #include <stdio.h> #include <string.h> #include <stdlib.h> @@ -379,6 +379,7 @@ add_history(msgque_t *msg) swater[i] = &water[i + 1]; strcpy(swater[i]->userid, msg->userid); swater[i]->pid = msg->pid; + swater[i]->uin = (userinfo_t *)search_ulist_pid(msg->pid); } tmp = swater[i]; } @@ -387,6 +388,7 @@ add_history(msgque_t *msg) memset(swater[4], 0, sizeof (water_t)); strcpy(swater[4]->userid, msg->userid); swater[4]->pid = msg->pid; + swater[4]->uin = (userinfo_t *)search_ulist_pid(msg->pid); i = 4; } @@ -403,8 +405,7 @@ add_history(msgque_t *msg) watermode++; t_display_new(); } - }else - swater[0]->uin = (userinfo_t *)search_ulist_pid(swater[0]->pid); + } return i; } @@ -894,7 +895,7 @@ user_login () if (cuser.userlevel){/* not guest */ move (t_lines - 4, 0); - prints (" 歡迎您第 \033[1;33m%d\033[0;37m 度拜訪本站," + prints ("\033[m 歡迎您第 \033[1;33m%d\033[0;37m 度拜訪本站," "上次您是從 \033[1;33m%s\033[0;37m 連往本站,\n" " 我記得那天是 \033[1;33m%s\033[0;37m。\n", ++cuser.numlogins, cuser.lasthost, Cdate (&cuser.lastlogin)); diff --git a/pttbbs/mbbsd/talk.c b/pttbbs/mbbsd/talk.c index 8516a5a9..0f0b66fe 100644 --- a/pttbbs/mbbsd/talk.c +++ b/pttbbs/mbbsd/talk.c @@ -1,4 +1,4 @@ -/* $Id: talk.c,v 1.12 2002/03/16 13:38:36 ptt Exp $ */ +/* $Id: talk.c,v 1.13 2002/03/16 15:11:10 ptt Exp $ */ #include <stdio.h> #include <string.h> #include <errno.h> @@ -741,17 +741,24 @@ void t_display_new(void) outs("───────水─球─回─顧───"); outs(WATERMODE(WATER_ORIG) ? "──────用[Ctrl-R Ctrl-T]鍵切換─────" : - "用[Ctrl-R Ctrl-T Ctrl-E Ctrl-W ]鍵切換────"); + "用[Ctrl-R Ctrl-T Ctrl-F Ctrl-G ]鍵切換────"); if( WATERMODE(WATER_NEW) ){ move(2, 0); clrtoeol(); for (i = 0; i<6 ; i++){ if(i>0) if(swater[i-1]) - prints("%s%-13.13s\033[m", - !swater[i-1]->uin?"\033[1;33;45mX": - swater[i-1]==water_which?"\033[1;33;47m ": - " ",swater[i-1]->userid); + { + if(swater[i-1]->uin && + swater[i-1]->uin->pid!=swater[i-1]->pid) + swater[i-1]->uin=NULL; + prints("%s%c%-13.13s\033[m", + swater[i-1]!=water_which? "" : + swater[i-1]->uin?"\033[1;33;47m": + "\033[1;33;45m", + !swater[i-1]->uin?'#':' ', + swater[i-1]->userid); + } else prints(" "); else -- cgit v1.2.3 From 6ef504aab77df606febe48ece53dc74cfa0fb961 Mon Sep 17 00:00:00 2001 From: ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sat, 16 Mar 2002 15:37:22 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@32 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/board.c | 6 +++--- pttbbs/mbbsd/mbbsd.c | 3 ++- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/pttbbs/mbbsd/board.c b/pttbbs/mbbsd/board.c index c8ba647f..f28721da 100644 --- a/pttbbs/mbbsd/board.c +++ b/pttbbs/mbbsd/board.c @@ -1,4 +1,4 @@ -/* $Id: board.c,v 1.2 2002/03/11 11:12:05 in2 Exp $ */ +/* $Id: board.c,v 1.3 2002/03/16 15:37:22 ptt Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -238,8 +238,8 @@ void init_brdbuf() { register int n, size; char fname[60]; - /* MAXBOARDS ==> 至多看得見 4 個新板 */ - n = numboards + 4; + /* MAXBOARDS ==> 至多看得見 32 個新板 */ + n = numboards + 32; size = n * sizeof(int); zapbuf = (int *) malloc(size); favbuf = (int *) malloc(size + sizeof(int)); diff --git a/pttbbs/mbbsd/mbbsd.c b/pttbbs/mbbsd/mbbsd.c index 265a4d74..56d91691 100644 --- a/pttbbs/mbbsd/mbbsd.c +++ b/pttbbs/mbbsd/mbbsd.c @@ -1,4 +1,4 @@ -/* $Id: mbbsd.c,v 1.10 2002/03/16 15:11:10 ptt Exp $ */ +/* $Id: mbbsd.c,v 1.11 2002/03/16 15:37:22 ptt Exp $ */ #include <stdio.h> #include <string.h> #include <stdlib.h> @@ -414,6 +414,7 @@ write_request (int sig) { int i; + signal_restart (SIGUSR2, write_request); if( WATERMODE(WATER_OFO) ){ /* sig = SIGUSR2 waterball come in 0 flush to water[] (by my_write2()) -- cgit v1.2.3 From 1142a96490ef315a30653f7e42941c2c917ba28a Mon Sep 17 00:00:00 2001 From: ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sat, 16 Mar 2002 15:44:01 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@33 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/mbbsd.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pttbbs/mbbsd/mbbsd.c b/pttbbs/mbbsd/mbbsd.c index 56d91691..6e4f7e90 100644 --- a/pttbbs/mbbsd/mbbsd.c +++ b/pttbbs/mbbsd/mbbsd.c @@ -1,4 +1,4 @@ -/* $Id: mbbsd.c,v 1.11 2002/03/16 15:37:22 ptt Exp $ */ +/* $Id: mbbsd.c,v 1.12 2002/03/16 15:44:01 ptt Exp $ */ #include <stdio.h> #include <string.h> #include <stdlib.h> @@ -414,7 +414,6 @@ write_request (int sig) { int i; - signal_restart (SIGUSR2, write_request); if( WATERMODE(WATER_OFO) ){ /* sig = SIGUSR2 waterball come in 0 flush to water[] (by my_write2()) -- cgit v1.2.3 From d9176ab52fa06056f2850bc07717fa80802e5861 Mon Sep 17 00:00:00 2001 From: ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sat, 16 Mar 2002 16:56:32 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@34 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/buildAnnounce.c | 41 ++++++++++++++++++++++++++--------------- 1 file changed, 26 insertions(+), 15 deletions(-) diff --git a/pttbbs/util/buildAnnounce.c b/pttbbs/util/buildAnnounce.c index f3f75661..30c5e9fa 100644 --- a/pttbbs/util/buildAnnounce.c +++ b/pttbbs/util/buildAnnounce.c @@ -16,46 +16,57 @@ extern bcache_t *brdshm; extern boardheader_t *bcache; extern void resolve_boards(); +extern int numboards; -void buildchilds(int level,char *path,boardheader_t *bptr) +int cmpboardclass(boardheader_t **brd, boardheader_t **tmp) { + return (strncmp((*brd)->title, (*tmp)->title, 4)<<8)+ + strcasecmp((*brd)->brdname, (*tmp)->brdname); +} +void buildchilds(int level,char *path,int gid) { char newpath[512]; - boardheader_t *ptr; + int i,count=0; + boardheader_t *ptr, *selected[512]; fileheader_t item; - if(bptr->firstchild[1]==(boardheader_t*)~0 || bptr->firstchild[1]==NULL) - return; - for(ptr =(void*) bptr->firstchild[1]; - ptr!=(boardheader_t*)~0 ;ptr=ptr->next[1]){ - + for(i=0; i<numboards; i++) + { + ptr =&brdshm->bcache[i]; if( - (ptr->brdattr&(BRD_BAD | BRD_GROUPBOARD | BRD_NOCOUNT | BRD_HIDE))!=0 + ptr->gid != gid || + (ptr->brdattr&(BRD_BAD | BRD_HIDE))!=0 || (ptr->level && !(ptr->brdattr & BRD_POSTMASK))) continue; + selected[count++]=ptr; + } + qsort(&selected, count, sizeof(boardheader_t *), + cmpboardclass); + for(i=0;i<count;i++) + { + ptr=selected[i]; printf("%*.*s+-%-14s %-s \n",level*2,level*2,"| | | | | | | | |", ptr->brdname, ptr->title); + if(ptr->brdattr & BRD_GROUPBOARD){ sprintf(newpath,"%s/%s",path,ptr->brdname); mkdir(newpath,0766); - buildchilds(level+1,newpath,ptr); + buildchilds(level+1,newpath,ptr-bcache+1); } else{ - printf("%s4\n",ptr->brdname); sprintf(newpath,"/bin/ln -s "BBSHOME"/man/boards/%c/%s %s/%s", /* maybe something wrong with this ^^^^^ */ ptr->brdname[0], ptr->brdname,path,ptr->brdname); system(newpath); } - printf("%s5\n",ptr->brdname); - sprintf(newpath,"%s/.DIR",path); strcpy(item.owner,ptr->BM); strtok(item.owner,"/"); - strcpy(item.title,ptr->title+7); + sprintf(item.title,"%-13.13s %s", level?ptr->brdname:"", ptr->title+7); item.savemode = 'D'; sprintf(item.filename,ptr->brdname); + sprintf(newpath,"%s/.DIR",path); append_record(newpath, &item, sizeof(item)); - } + } } @@ -67,6 +78,6 @@ int main() system("rm -rf "GROUPROOT); mkdir(GROUPROOT,0766); resolve_boards(); - buildchilds(0,path,&bcache[0]); + buildchilds(0,path,1); return 0; } -- cgit v1.2.3 From 149f15dc00a5c1b8cc415d52fb168007da92d8e5 Mon Sep 17 00:00:00 2001 From: ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sat, 16 Mar 2002 17:09:41 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@35 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/buildAnnounce.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pttbbs/util/buildAnnounce.c b/pttbbs/util/buildAnnounce.c index 30c5e9fa..7de62615 100644 --- a/pttbbs/util/buildAnnounce.c +++ b/pttbbs/util/buildAnnounce.c @@ -61,8 +61,9 @@ void buildchilds(int level,char *path,int gid) } strcpy(item.owner,ptr->BM); strtok(item.owner,"/"); - sprintf(item.title,"%-13.13s %s", level?ptr->brdname:"", ptr->title+7); + sprintf(item.title,"%-13.13s %-32.32s", level?ptr->brdname:"", ptr->title+7); item.savemode = 'D'; + item.filemode = 0 ; sprintf(item.filename,ptr->brdname); sprintf(newpath,"%s/.DIR",path); append_record(newpath, &item, sizeof(item)); -- cgit v1.2.3 From 5848ec021d65420aa1448dc375b8d694473da3e9 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sun, 17 Mar 2002 06:06:26 +0000 Subject: register by EMail code git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@36 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/menu.c | 7 +- pttbbs/mbbsd/register.c | 6 +- pttbbs/mbbsd/user.c | 181 ++++++++++++++++++++++++++++++++++++++++-------- 3 files changed, 161 insertions(+), 33 deletions(-) diff --git a/pttbbs/mbbsd/menu.c b/pttbbs/mbbsd/menu.c index d48670b3..d10b754f 100644 --- a/pttbbs/mbbsd/menu.c +++ b/pttbbs/mbbsd/menu.c @@ -1,4 +1,4 @@ -/* $Id: menu.c,v 1.1 2002/03/07 15:13:48 in2 Exp $ */ +/* $Id: menu.c,v 1.2 2002/03/17 06:06:26 in2 Exp $ */ #include <stdio.h> #include <stdlib.h> #include <time.h> @@ -58,9 +58,8 @@ void showtitle(char *title, char *mid) { else if(currutmp->mailalert) { mid = "\033[41;5m 郵差來按鈴囉 " TITLE_COLOR; spc = 22; - } else if(HAS_PERM(PERM_SYSOP) && (nreg = dashs(fn_register)/163) > 10) { - /* 超過十個人未審核 */ - sprintf(numreg, "\033[41;5m 有%03d/%03d未審核 " TITLE_COLOR, + } else if(HAS_PERM(PERM_SYSOP) && (nreg = dashs(fn_register)/163)) { + sprintf(numreg, "\033[41;5m 有%03d/%03d未審核 " TITLE_COLOR, nreg, (int)dashs("register.new.tmp") / 163); mid = numreg; diff --git a/pttbbs/mbbsd/register.c b/pttbbs/mbbsd/register.c index e9c25be5..1ef56e9e 100644 --- a/pttbbs/mbbsd/register.c +++ b/pttbbs/mbbsd/register.c @@ -1,4 +1,4 @@ -/* $Id: register.c,v 1.1 2002/03/07 15:13:48 in2 Exp $ */ +/* $Id: register.c,v 1.2 2002/03/17 06:04:18 in2 Exp $ */ #define _XOPEN_SOURCE #include <stdio.h> @@ -303,7 +303,8 @@ void check_register() { while(strlen(cuser.address) < 8) getdata(6, 0, "聯絡地址:", cuser.address, 50, DOECHO); - + + /* if(!strchr(cuser.email, '@')) { bell(); move(t_lines - 4, 0); @@ -320,6 +321,7 @@ void check_register() { } while(!strchr(cuser.email, '@')); } + */ if(!HAS_PERM(PERM_SYSOP) && !HAS_PERM(PERM_LOGINOK)) { /* 回覆過身份認證信函,或曾經 E-mail post 過 */ clear(); diff --git a/pttbbs/mbbsd/user.c b/pttbbs/mbbsd/user.c index 72850ad7..46aaf7ed 100644 --- a/pttbbs/mbbsd/user.c +++ b/pttbbs/mbbsd/user.c @@ -1,4 +1,4 @@ -/* $Id: user.c,v 1.2 2002/03/09 17:27:57 in2 Exp $ */ +/* $Id: user.c,v 1.3 2002/03/17 06:04:18 in2 Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -740,13 +740,121 @@ static int removespace(char* s){ return index; } -int u_register() { +static int ispersonalid(char *inid) +{ + char *lst="ABCDEFGHJKLMNPQRSTUVWXYZIO", id[20]; + int i, j, cksum; + + strcpy(id, inid); + i = cksum = 0; + if( !isalpha(id[0]) && (strlen(id)!=10) ) + return 0; + id[0] = toupper(id[0]); + /* A->10, B->11, ..H->17,I->34, J->18... */ + while( lst[i] != id[0] ) + i++; + i += 10; + id[0] = i % 10 + '0'; + if( !isdigit(id[9]) ) + return 0; + cksum += (id[9] - '0') + (i / 10); + + for( j = 0 ; j < 9 ; ++j ){ + if( !isdigit(id[j]) ) + return 0; + cksum += (id[j] - '0') * (9 - j); + } + return (cksum % 10) == 0; +} + +static char *getregcode(char *buf) +{ + sprintf(buf, "%s%s%s", + crypt(cuser.email, "PT"), + crypt(cuser.address, "2x"), + crypt(cuser.realname, "02")); + return buf; +} + +static int isvaildemail(char *email) +{ + if( strstr(email, ".bbs@") || + strstr(email, "url.com.tw") || + strstr(email, "yahoo.com") || + strstr(email, "hotmail.com")|| + !strstr(email, "@") ) + return 0; + return 1; +} + +static void toregister(char *email, char *genbuf, char *phone, char *career, + char *ident, char *rname, char *addr, char *mobile) +{ + FILE *fn; + time_t now; + char buf[80]; + clear(); + stand_title("認證設定"); + move(2, 0); + outs("您好, 本站採兩種方式認證:\n" + " 1.您若有 E-Mail , 可以透過 E-Mail 進行認證\n" + " 請輸入您的 E-Mail , 您會收到我們寄出含有認證碼的信件\n" + " 之後請到 (U)ser => (R)egister 輸入, 即可通過認證\n" + "\n" + " 2.您若沒有 E-Mail , 請輸入 0 ,\n" + " 我們會由站長親自審核您的註冊資料\n"); + while( 1 ){ + email[0] = 0; + getfield(10, "身分認證用", "E-Mail Address", email, 50); + if( email[0] == 0 || email[0] == '0' || isvaildemail(email) ) + break; + else{ + move(17, 0); + prints("指定的 E-Mail 不合法, 若您無 E-Mail 請輸入 0"); + } + } + if( email[0] == 0 ) /* 下次再來 */ + return; + else if( email[0] == '0' ){ /* 手動認證 */ + if ((fn = fopen(fn_register, "a"))) { + now = time(NULL); + fprintf(fn, "num: %d, %s", usernum, ctime(&now)); + fprintf(fn, "uid: %s\n", cuser.userid); + fprintf(fn, "ident: %s\n", ident); + fprintf(fn, "name: %s\n", rname); + fprintf(fn, "career: %s\n", career); + fprintf(fn, "addr: %s\n", addr); + fprintf(fn, "phone: %s\n", phone); + fprintf(fn, "mobile: %s\n", mobile); + fprintf(fn, "email: %s\n", email); + fprintf(fn, "----\n"); + fclose(fn); + } + } + else{ + if( phone != NULL ){ + sprintf(genbuf, "%s:%s:<Email>", phone, career); + strncpy(cuser.justify, genbuf, REGLEN); + sethomefile(buf, cuser.userid, "justify"); + } + sprintf(buf, "您在 "BBSNAME" 的認證碼: %s", getregcode(genbuf)); + bsmtp("etc/registermail", buf, email, 0); + outs("我們即將寄出認證信 (可能要麻煩您等兩三分鐘)\n" + "收到後您可以跟據認證信標題的認證碼\n" + "輸入到 (U)ser -> (R)egister 後就可以完成註冊"); + pressanykey(); + return; + } +} + +int u_register(void) +{ char rname[20], addr[50], ident[11], mobile[20]; char phone[20], career[40], email[50],birthday[9],sex_is[2],year,mon,day; + char inregcode[50], regcode[50]; char ans[3], *ptr; - FILE *fn; - time_t now; char genbuf[200]; + FILE *fn; if(cuser.userlevel & PERM_LOGINOK) { outs("您的身份確認已經完成,不需填寫申請表"); @@ -765,7 +873,37 @@ int u_register() { } fclose(fn); } - + + memset(phone, 0, sizeof(phone)); + if( cuser.year != 0 ){ /* 已經第一次填過了~ ^^" */ + clear(); + move(1, 0); + prints("%s(%s) 您好,請輸入您的認證碼或輸入 0重填 E-Mail ", + cuser.userid, cuser.username); + inregcode[0] = 0; + getdata(10, 0, "您的認證碼: ", inregcode, 45, DOECHO); + if( strcmp(inregcode, getregcode(regcode)) == 0 ){ + int unum; + if( (unum = getuser(cuser.userid)) == 0 ){ + outs("系統錯誤,查無此人\n\n"); + u_exit("getuser error"); + } + mail_muser(cuser, "[註冊成功\囉]", "etc/registeredmail"); + cuser.userlevel |= (PERM_LOGINOK | PERM_POST); + prints("\n註冊成功\, 重新上站後將取得完整權限\n" + "請按下任一鍵跳離後重新上站~ :)"); + pressanykey(); + u_exit("registed"); + exit(0); + return QUIT; + } else if( strcmp(inregcode, "0") != 0 ){ + outs("認證碼錯誤\n"); + pressanykey(); + } + toregister(email, genbuf, NULL, NULL, NULL, NULL, NULL, NULL); + return FULLUPDATE; + } + getdata(b_lines - 1, 0, "您確定要填寫註冊單嗎(Y/N)?[N] ", ans, 3, LCECHO); if(ans[0] != 'y') return FULLUPDATE; @@ -788,7 +926,9 @@ int u_register() { cuser.userid, cuser.username); do{ getfield(3, "D120908396", "身分證號", ident, 11); - }while(removespace(ident)<10 || !isalpha(ident[0])); + if( 'a' <= ident[0] && ident[0] <= 'z' ) + ident[0] -= 32; + }while( !ispersonalid(ident) ); do{ getfield(5, "請用中文", "真實姓名", rname, 20); }while(!removespace(rname) || isalpha(rname[0])); @@ -800,7 +940,7 @@ int u_register() { }while(!(addr[0])); do{ getfield(11, "包括長途撥號區域碼", "連絡電話", phone, 20); - }while(!removespace(phone)); + }while( !removespace(phone) || phone[0] != '0' || strlen(phone) < 8 ); getfield(13, "只輸入數字 如:0912345678", "手機號碼", mobile, 20); while(1) { int len; @@ -825,9 +965,7 @@ int u_register() { break; } getfield(17, "1.葛格 2.姐接 ", "性別", sex_is, 2); - getfield(19, "身分認證用", "E-Mail Address", email, 50); - - getdata(b_lines - 1, 0, "以上資料是否正確(Y/N)?(Q)取消註冊 [N] ", + getdata(18, 0, "以上資料是否正確(Y/N)?(Q)取消註冊 [N] ", ans, 3, LCECHO); if(ans[0] == 'q') return 0; @@ -843,23 +981,12 @@ int u_register() { cuser.month = mon; cuser.day = day; cuser.year = year; - if((fn = fopen(fn_register, "a"))) { - now = time(NULL); - trim(career); - trim(addr); - trim(phone); - fprintf(fn, "num: %d, %s", usernum, ctime(&now)); - fprintf(fn, "uid: %s\n", cuser.userid); - fprintf(fn, "ident: %s\n", ident); - fprintf(fn, "name: %s\n", rname); - fprintf(fn, "career: %s\n", career); - fprintf(fn, "addr: %s\n", addr); - fprintf(fn, "phone: %s\n", phone); - fprintf(fn, "mobile: %s\n", mobile); - fprintf(fn, "email: %s\n", email); - fprintf(fn, "----\n"); - fclose(fn); - } + trim(career); + trim(addr); + trim(phone); + + toregister(email, genbuf, phone, career, ident, rname, addr, mobile); + clear(); move(9,3); prints("最後Post一篇\033[32m自我介紹文章\033[m給大家吧," -- cgit v1.2.3 From 57e16b0aa2d73c211d608dbc6dac2a2bcc8a5c0f Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sun, 17 Mar 2002 06:15:04 +0000 Subject: :) git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@37 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/user.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pttbbs/mbbsd/user.c b/pttbbs/mbbsd/user.c index 46aaf7ed..c7982753 100644 --- a/pttbbs/mbbsd/user.c +++ b/pttbbs/mbbsd/user.c @@ -1,4 +1,4 @@ -/* $Id: user.c,v 1.3 2002/03/17 06:04:18 in2 Exp $ */ +/* $Id: user.c,v 1.4 2002/03/17 06:15:04 in2 Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -839,7 +839,7 @@ static void toregister(char *email, char *genbuf, char *phone, char *career, } sprintf(buf, "您在 "BBSNAME" 的認證碼: %s", getregcode(genbuf)); bsmtp("etc/registermail", buf, email, 0); - outs("我們即將寄出認證信 (可能要麻煩您等兩三分鐘)\n" + outs("\n\n\n我們即將寄出認證信 (可能要麻煩您等兩三分鐘)\n" "收到後您可以跟據認證信標題的認證碼\n" "輸入到 (U)ser -> (R)egister 後就可以完成註冊"); pressanykey(); @@ -934,10 +934,10 @@ int u_register(void) }while(!removespace(rname) || isalpha(rname[0])); do{ getfield(7, "學校系級或單位職稱", "服務單位", career, 40); - }while(!removespace(career)); + }while( !removespace(career) || career[0] < 0 || strlen(career) < 4 ); do{ getfield(9, "包括寢室或門牌號碼", "目前住址", addr, 50); - }while(!(addr[0])); + }while( !(addr[0]) || addr[0] < 0 || strlen(addr) < 15 ); do{ getfield(11, "包括長途撥號區域碼", "連絡電話", phone, 20); }while( !removespace(phone) || phone[0] != '0' || strlen(phone) < 8 ); -- cgit v1.2.3 From 04e6026fabc023d00768f72a582c5c9153a3650b Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sun, 17 Mar 2002 07:30:04 +0000 Subject: fix bug git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@38 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/user.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pttbbs/mbbsd/user.c b/pttbbs/mbbsd/user.c index c7982753..084fed95 100644 --- a/pttbbs/mbbsd/user.c +++ b/pttbbs/mbbsd/user.c @@ -1,4 +1,4 @@ -/* $Id: user.c,v 1.4 2002/03/17 06:15:04 in2 Exp $ */ +/* $Id: user.c,v 1.5 2002/03/17 07:30:04 in2 Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -931,13 +931,13 @@ int u_register(void) }while( !ispersonalid(ident) ); do{ getfield(5, "請用中文", "真實姓名", rname, 20); - }while(!removespace(rname) || isalpha(rname[0])); + }while(!removespace(rname) || rname[0] > 0); do{ getfield(7, "學校系級或單位職稱", "服務單位", career, 40); - }while( !removespace(career) || career[0] < 0 || strlen(career) < 4 ); + }while( !removespace(career) || career[0] > 0 || strlen(career) < 4 ); do{ getfield(9, "包括寢室或門牌號碼", "目前住址", addr, 50); - }while( !(addr[0]) || addr[0] < 0 || strlen(addr) < 15 ); + }while( !(addr[0]) || addr[0] > 0 || strlen(addr) < 15 ); do{ getfield(11, "包括長途撥號區域碼", "連絡電話", phone, 20); }while( !removespace(phone) || phone[0] != '0' || strlen(phone) < 8 ); -- cgit v1.2.3 From 298c0a15e064f335df85682ad1e70f9d032d5abd Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sun, 17 Mar 2002 08:11:34 +0000 Subject: fix bug git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@39 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/user.c | 55 ++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 44 insertions(+), 11 deletions(-) diff --git a/pttbbs/mbbsd/user.c b/pttbbs/mbbsd/user.c index 084fed95..30fdc4de 100644 --- a/pttbbs/mbbsd/user.c +++ b/pttbbs/mbbsd/user.c @@ -1,4 +1,4 @@ -/* $Id: user.c,v 1.5 2002/03/17 07:30:04 in2 Exp $ */ +/* $Id: user.c,v 1.6 2002/03/17 08:11:34 in2 Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -778,12 +778,26 @@ static char *getregcode(char *buf) static int isvaildemail(char *email) { - if( strstr(email, ".bbs@") || - strstr(email, "url.com.tw") || - strstr(email, "yahoo.com") || - strstr(email, "hotmail.com")|| - !strstr(email, "@") ) + FILE *fp; + char buf[128], *c; + if( !strstr(email, "@") ) return 0; + for( c = strstr(email, "@") ; *c != 0 ; ++c ) + if( 'A' <= *c && *c <= 'Z' ) + *c += 32; + + if( (fp = fopen("etc/banemail", "r")) ){ + while( fgets(buf, sizeof(buf), fp) ){ + if( buf[0] == '#' ) + continue; + buf[ strlen(buf) - 1 ] = 0; + if( buf[0] == 'A' && strcmp(&buf[1], email) == 0 ) + return 0; + if( buf[0] == 'S' && strstr(&buf[1], email) ) + return 0; + } + fclose(fp); + } return 1; } @@ -792,7 +806,25 @@ static void toregister(char *email, char *genbuf, char *phone, char *career, { FILE *fn; time_t now; - char buf[80]; + char buf[128]; + + sethomefile(buf, cuser.userid, "justify.wait"); + if( phone[0] == 0 ){ + fn = fopen(buf, "r"); + fgets(phone, 21, fn); phone[ strlen(phone) - 1] = 0; + fgets(career,41, fn); career[strlen(career)- 1] = 0; + fgets(ident, 12, fn); ident[ strlen(ident) - 1] = 0; + fgets(rname, 21, fn); rname[ strlen(rname) - 1] = 0; + fgets(addr, 51, fn); addr [ strlen(addr) - 1] = 0; + fgets(mobile,21, fn); mobile[strlen(mobile)- 1] = 0; + fclose(fn); + } + else{ + fn = fopen(buf, "w"); + fprintf(fn, "%s\n%s\n%s\n%s\n%s\n%s\n", + phone, career, ident, rname, addr, mobile); + fclose(fn); + } clear(); stand_title("認證設定"); move(2, 0); @@ -849,8 +881,8 @@ static void toregister(char *email, char *genbuf, char *phone, char *career, int u_register(void) { - char rname[20], addr[50], ident[11], mobile[20]; - char phone[20], career[40], email[50],birthday[9],sex_is[2],year,mon,day; + char rname[21], addr[51], ident[12], mobile[21]; + char phone[21], career[41], email[51],birthday[9],sex_is[2],year,mon,day; char inregcode[50], regcode[50]; char ans[3], *ptr; char genbuf[200]; @@ -900,7 +932,8 @@ int u_register(void) outs("認證碼錯誤\n"); pressanykey(); } - toregister(email, genbuf, NULL, NULL, NULL, NULL, NULL, NULL); + phone[0] = 0; + toregister(email, genbuf, phone, career, ident, rname, addr, mobile); return FULLUPDATE; } @@ -977,7 +1010,7 @@ int u_register(void) strcpy(cuser.address, addr); strcpy(cuser.email, email); cuser.mobile = atoi(mobile); - cuser.sex= (sex_is[0] - '1') % 8; + cuser.sex = (sex_is[0] - '1') % 8; cuser.month = mon; cuser.day = day; cuser.year = year; -- cgit v1.2.3 From a2b587784d967005cf0c3c9a1c91cee2cab2d7a9 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sun, 17 Mar 2002 08:23:48 +0000 Subject: fix bug git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@40 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/user.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/pttbbs/mbbsd/user.c b/pttbbs/mbbsd/user.c index 30fdc4de..5088fd27 100644 --- a/pttbbs/mbbsd/user.c +++ b/pttbbs/mbbsd/user.c @@ -1,4 +1,4 @@ -/* $Id: user.c,v 1.6 2002/03/17 08:11:34 in2 Exp $ */ +/* $Id: user.c,v 1.7 2002/03/17 08:23:48 in2 Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -793,7 +793,9 @@ static int isvaildemail(char *email) buf[ strlen(buf) - 1 ] = 0; if( buf[0] == 'A' && strcmp(&buf[1], email) == 0 ) return 0; - if( buf[0] == 'S' && strstr(&buf[1], email) ) + if( buf[0] == 'P' && strstr(email, &buf[1]) ) + return 0; + if( buf[0] == 'S' && strcmp(strstr(email, "@") + 1, &buf[1]) == 0 ) return 0; } fclose(fp); @@ -864,13 +866,17 @@ static void toregister(char *email, char *genbuf, char *phone, char *career, } } else{ + char tmp[IDLEN + 1]; if( phone != NULL ){ sprintf(genbuf, "%s:%s:<Email>", phone, career); strncpy(cuser.justify, genbuf, REGLEN); sethomefile(buf, cuser.userid, "justify"); } + strcpy(tmp, cuser.userid); + strcpy(cuser.userid, "SYSOP"); sprintf(buf, "您在 "BBSNAME" 的認證碼: %s", getregcode(genbuf)); bsmtp("etc/registermail", buf, email, 0); + strcpy(cuser.userid, tmp); outs("\n\n\n我們即將寄出認證信 (可能要麻煩您等兩三分鐘)\n" "收到後您可以跟據認證信標題的認證碼\n" "輸入到 (U)ser -> (R)egister 後就可以完成註冊"); @@ -909,7 +915,8 @@ int u_register(void) memset(phone, 0, sizeof(phone)); if( cuser.year != 0 ){ /* 已經第一次填過了~ ^^" */ clear(); - move(1, 0); + stand_title("EMail認證"); + move(2, 0); prints("%s(%s) 您好,請輸入您的認證碼或輸入 0重填 E-Mail ", cuser.userid, cuser.username); inregcode[0] = 0; -- cgit v1.2.3 From 3830a4b4eecb426851a46ea30c4ffa09355d020c Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sun, 17 Mar 2002 08:33:48 +0000 Subject: one key to confirm register delete justify.wait git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@41 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/admin.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/pttbbs/mbbsd/admin.c b/pttbbs/mbbsd/admin.c index 04804809..b0ef5f3e 100644 --- a/pttbbs/mbbsd/admin.c +++ b/pttbbs/mbbsd/admin.c @@ -1,4 +1,4 @@ -/* $Id: admin.c,v 1.3 2002/03/09 17:27:57 in2 Exp $ */ +/* $Id: admin.c,v 1.4 2002/03/17 08:33:48 in2 Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -815,6 +815,9 @@ int scan_register_form(char *regfile, int automode, int neednum) { getdata(b_lines - 1, 0, "是否接受此資料(Y/N/Q/Del/Skip)?[S] ", ans, 3, LCECHO); + ans[0] = igetch(); + if( 'A' <= ans[0] && ans[0] <= 'Z' ) + ans[0] += 32; if( ans[0] != 'y' && ans[0] != 'n' && ans[0] != 'q' && ans[0] != 'd' ) ans[0] = 's'; @@ -926,6 +929,9 @@ int scan_register_form(char *regfile, int automode, int neednum) { fprintf(fout, "----\n"); fclose(fout); } + + sethomefile(genbuf, muser.userid, "justify.wait"); + unlink(genbuf); break; } } -- cgit v1.2.3 From 3cea248e27ddcf421cf1290e42d70824beda9734 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sun, 17 Mar 2002 08:37:15 +0000 Subject: delete justify.wait git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@42 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/user.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pttbbs/mbbsd/user.c b/pttbbs/mbbsd/user.c index 5088fd27..a5763506 100644 --- a/pttbbs/mbbsd/user.c +++ b/pttbbs/mbbsd/user.c @@ -1,4 +1,4 @@ -/* $Id: user.c,v 1.7 2002/03/17 08:23:48 in2 Exp $ */ +/* $Id: user.c,v 1.8 2002/03/17 08:37:15 in2 Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -931,6 +931,8 @@ int u_register(void) cuser.userlevel |= (PERM_LOGINOK | PERM_POST); prints("\n註冊成功\, 重新上站後將取得完整權限\n" "請按下任一鍵跳離後重新上站~ :)"); + sethomefile(genbuf, cuser.userid, "justify.wait"); + unlink(genbuf); pressanykey(); u_exit("registed"); exit(0); -- cgit v1.2.3 From 39854d363d5e7b8ea460b80bbf846919834c100e Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sun, 17 Mar 2002 09:18:23 +0000 Subject: 10 git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@43 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/menu.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pttbbs/mbbsd/menu.c b/pttbbs/mbbsd/menu.c index d10b754f..19378b15 100644 --- a/pttbbs/mbbsd/menu.c +++ b/pttbbs/mbbsd/menu.c @@ -1,4 +1,4 @@ -/* $Id: menu.c,v 1.2 2002/03/17 06:06:26 in2 Exp $ */ +/* $Id: menu.c,v 1.3 2002/03/17 09:18:23 in2 Exp $ */ #include <stdio.h> #include <stdlib.h> #include <time.h> @@ -58,7 +58,7 @@ void showtitle(char *title, char *mid) { else if(currutmp->mailalert) { mid = "\033[41;5m 郵差來按鈴囉 " TITLE_COLOR; spc = 22; - } else if(HAS_PERM(PERM_SYSOP) && (nreg = dashs(fn_register)/163)) { + } else if(HAS_PERM(PERM_SYSOP) && (nreg = dashs(fn_register)/163) > 10) { sprintf(numreg, "\033[41;5m 有%03d/%03d未審核 " TITLE_COLOR, nreg, (int)dashs("register.new.tmp") / 163); -- cgit v1.2.3 From c22491d077900ccf4afb11bde4890b0a9b5f9334 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sun, 17 Mar 2002 16:39:19 +0000 Subject: fix bug git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@44 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/admin.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pttbbs/mbbsd/admin.c b/pttbbs/mbbsd/admin.c index b0ef5f3e..7ca5e466 100644 --- a/pttbbs/mbbsd/admin.c +++ b/pttbbs/mbbsd/admin.c @@ -1,4 +1,4 @@ -/* $Id: admin.c,v 1.4 2002/03/17 08:33:48 in2 Exp $ */ +/* $Id: admin.c,v 1.5 2002/03/17 16:39:19 in2 Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -818,8 +818,8 @@ int scan_register_form(char *regfile, int automode, int neednum) { ans[0] = igetch(); if( 'A' <= ans[0] && ans[0] <= 'Z' ) ans[0] += 32; - if( ans[0] != 'y' && ans[0] != 'n' && - ans[0] != 'q' && ans[0] != 'd' ) + if( ans[0] != 'y' && ans[0] != 'n' && ans[0] != 'q' && + ans[0] != 'd' && !('0' <= ans[0] && ans[0] <= '4') ) ans[0] = 's'; ans[1] = 0; } -- cgit v1.2.3 From c449c90e7245a704016766f3840c263314392514 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sun, 17 Mar 2002 17:06:54 +0000 Subject: fix bug git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@45 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/admin.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/pttbbs/mbbsd/admin.c b/pttbbs/mbbsd/admin.c index 7ca5e466..61509ba6 100644 --- a/pttbbs/mbbsd/admin.c +++ b/pttbbs/mbbsd/admin.c @@ -1,4 +1,4 @@ -/* $Id: admin.c,v 1.5 2002/03/17 16:39:19 in2 Exp $ */ +/* $Id: admin.c,v 1.6 2002/03/17 17:06:54 in2 Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -812,9 +812,8 @@ int scan_register_form(char *regfile, int automode, int neednum) { if(ans[0] != 'y' && ans[0] != 's') ans[0] = 'd'; } else { - getdata(b_lines - 1, 0, - "是否接受此資料(Y/N/Q/Del/Skip)?[S] ", - ans, 3, LCECHO); + move(b_lines - 1, 0); + prints("是否接受此資料(Y/N/Q/Del/Skip)?[S] "); ans[0] = igetch(); if( 'A' <= ans[0] && ans[0] <= 'Z' ) ans[0] += 32; -- cgit v1.2.3 From 18f6a4bfd976b48746dc906415b1fb8645ddb037 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Mon, 18 Mar 2002 05:34:45 +0000 Subject: boards/<first>/<boardname> git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@46 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/expire.c | 53 +++++++++++++++++++++++++++++----------------------- 1 file changed, 30 insertions(+), 23 deletions(-) diff --git a/pttbbs/util/expire.c b/pttbbs/util/expire.c index c0ebdd09..c74ac6bf 100644 --- a/pttbbs/util/expire.c +++ b/pttbbs/util/expire.c @@ -1,4 +1,4 @@ -/* $Id: expire.c,v 1.2 2002/03/09 17:44:30 in2 Exp $ */ +/* $Id: expire.c,v 1.3 2002/03/18 05:34:45 in2 Exp $ */ /* 自動砍信工具程式 */ #include <stdio.h> @@ -25,7 +25,7 @@ #define EXPIRE_CONF BBSHOME "/etc/expire.conf" extern boardheader_t *bcache; -char *bpath = BBSHOME "/boards"; +char bpath[256]; struct life { @@ -144,7 +144,15 @@ char *argv[]; life db, table[MAX_BOARD], *key; struct dirent *de; DIR *dirp; - char *ptr, *bname, buf[256]; + int i; + char *ptr, *bname, buf[256]; + char dirs[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', + 'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', + 'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', + 'z', 'x', 'c', 'v', 'b', 'n', 'm', + 'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', + 'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', + 'Z', 'X', 'C', 'V', 'B', 'N', 'M', NULL}; resolve_boards(); db.days = ((argc > 1) && (number = atoi(argv[1])) > 0) ? number : DEF_DAYS; @@ -201,27 +209,26 @@ char *argv[]; /* visit all boards */ /* ---------------- */ - if (!(dirp = opendir(bpath))) - { - printf(":Err: unable to open %s\n", bpath); - return -1; - } - - while((de = readdir(dirp))) - { - ptr = de->d_name; - if (ptr[0] > ' ' && ptr[0] != '.') - { - if (count) - key = (life *) bsearch(ptr, table, count, sizeof(life), (QCAST)strcasecmp); - else - key = NULL; - if (!key) - key = &db; - strcpy(key->bname, ptr); - expire(key); + for( i = 0 ; dirs[i] != NULL ; ++i ){ + sprintf(bpath, BBSHOME "/boards/%c", dirs[i]); + if (!(dirp = opendir(bpath))){ + printf(":Err: unable to open %s\n", bpath); + //return -1; + } + while((de = readdir(dirp))){ + ptr = de->d_name; + if (ptr[0] > ' ' && ptr[0] != '.'){ + if (count) + key = (life *) bsearch(ptr, table, count, sizeof(life), (QCAST)strcasecmp); + else + key = NULL; + if (!key) + key = &db; + strcpy(key->bname, ptr); + expire(key); + } } + closedir(dirp); } - closedir(dirp); return 0; } -- cgit v1.2.3 From 3ad2f238baa26ee424c2e4f10224695cba2ee748 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Mon, 18 Mar 2002 06:02:03 +0000 Subject: register use X, not 0 git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@47 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/user.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/pttbbs/mbbsd/user.c b/pttbbs/mbbsd/user.c index a5763506..a15cfe8d 100644 --- a/pttbbs/mbbsd/user.c +++ b/pttbbs/mbbsd/user.c @@ -1,4 +1,4 @@ -/* $Id: user.c,v 1.8 2002/03/17 08:37:15 in2 Exp $ */ +/* $Id: user.c,v 1.9 2002/03/18 06:02:03 in2 Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -835,12 +835,13 @@ static void toregister(char *email, char *genbuf, char *phone, char *career, " 請輸入您的 E-Mail , 您會收到我們寄出含有認證碼的信件\n" " 之後請到 (U)ser => (R)egister 輸入, 即可通過認證\n" "\n" - " 2.您若沒有 E-Mail , 請輸入 0 ,\n" + " 2.您若沒有 E-Mail , 請輸入 x ,\n" " 我們會由站長親自審核您的註冊資料\n"); while( 1 ){ email[0] = 0; getfield(10, "身分認證用", "E-Mail Address", email, 50); - if( email[0] == 0 || email[0] == '0' || isvaildemail(email) ) + if( email[0] == 0 || strcmp(email, "x") == 0 || + strcmp(email, "X") == 0 || isvaildemail(email) ) break; else{ move(17, 0); @@ -849,7 +850,7 @@ static void toregister(char *email, char *genbuf, char *phone, char *career, } if( email[0] == 0 ) /* 下次再來 */ return; - else if( email[0] == '0' ){ /* 手動認證 */ + else if( email[0] == 'x' || email[0] == 'X' ){ /* 手動認證 */ if ((fn = fopen(fn_register, "a"))) { now = time(NULL); fprintf(fn, "num: %d, %s", usernum, ctime(&now)); @@ -917,7 +918,7 @@ int u_register(void) clear(); stand_title("EMail認證"); move(2, 0); - prints("%s(%s) 您好,請輸入您的認證碼或輸入 0重填 E-Mail ", + prints("%s(%s) 您好,請輸入您的認證碼或輸入 x重填 E-Mail ", cuser.userid, cuser.username); inregcode[0] = 0; getdata(10, 0, "您的認證碼: ", inregcode, 45, DOECHO); @@ -925,7 +926,9 @@ int u_register(void) int unum; if( (unum = getuser(cuser.userid)) == 0 ){ outs("系統錯誤,查無此人\n\n"); + pressanykey(); u_exit("getuser error"); + exit(0); } mail_muser(cuser, "[註冊成功\囉]", "etc/registeredmail"); cuser.userlevel |= (PERM_LOGINOK | PERM_POST); @@ -937,7 +940,7 @@ int u_register(void) u_exit("registed"); exit(0); return QUIT; - } else if( strcmp(inregcode, "0") != 0 ){ + } else if( strcmp(inregcode, "x")!=0 && strcmp(inregcode, "X")!=0 ){ outs("認證碼錯誤\n"); pressanykey(); } -- cgit v1.2.3 From 37ec2993e8caad3abcc67ea7e35c0d0b385038ac Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Mon, 18 Mar 2002 16:52:52 +0000 Subject: if justify.wait no exists ^^" git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@48 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/user.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/pttbbs/mbbsd/user.c b/pttbbs/mbbsd/user.c index a15cfe8d..7f814b28 100644 --- a/pttbbs/mbbsd/user.c +++ b/pttbbs/mbbsd/user.c @@ -1,4 +1,4 @@ -/* $Id: user.c,v 1.9 2002/03/18 06:02:03 in2 Exp $ */ +/* $Id: user.c,v 1.10 2002/03/18 16:52:52 in2 Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -812,14 +812,15 @@ static void toregister(char *email, char *genbuf, char *phone, char *career, sethomefile(buf, cuser.userid, "justify.wait"); if( phone[0] == 0 ){ - fn = fopen(buf, "r"); - fgets(phone, 21, fn); phone[ strlen(phone) - 1] = 0; - fgets(career,41, fn); career[strlen(career)- 1] = 0; - fgets(ident, 12, fn); ident[ strlen(ident) - 1] = 0; - fgets(rname, 21, fn); rname[ strlen(rname) - 1] = 0; - fgets(addr, 51, fn); addr [ strlen(addr) - 1] = 0; - fgets(mobile,21, fn); mobile[strlen(mobile)- 1] = 0; - fclose(fn); + if( (fn = fopen(buf, "r")) ){ + fgets(phone, 21, fn); phone[ strlen(phone) - 1] = 0; + fgets(career,41, fn); career[strlen(career)- 1] = 0; + fgets(ident, 12, fn); ident[ strlen(ident) - 1] = 0; + fgets(rname, 21, fn); rname[ strlen(rname) - 1] = 0; + fgets(addr, 51, fn); addr [ strlen(addr) - 1] = 0; + fgets(mobile,21, fn); mobile[strlen(mobile)- 1] = 0; + fclose(fn); + } } else{ fn = fopen(buf, "w"); -- cgit v1.2.3 From 8e90696f5a09c5744ea1d4959cdfcf53b24b353c Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Mon, 18 Mar 2002 20:24:29 +0000 Subject: fix bug(register) git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@49 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/user.c | 63 +++++++++++++++++++++++++++-------------------------- 1 file changed, 32 insertions(+), 31 deletions(-) diff --git a/pttbbs/mbbsd/user.c b/pttbbs/mbbsd/user.c index 7f814b28..2069e084 100644 --- a/pttbbs/mbbsd/user.c +++ b/pttbbs/mbbsd/user.c @@ -1,4 +1,4 @@ -/* $Id: user.c,v 1.10 2002/03/18 16:52:52 in2 Exp $ */ +/* $Id: user.c,v 1.11 2002/03/18 20:24:29 in2 Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -811,23 +811,13 @@ static void toregister(char *email, char *genbuf, char *phone, char *career, char buf[128]; sethomefile(buf, cuser.userid, "justify.wait"); - if( phone[0] == 0 ){ - if( (fn = fopen(buf, "r")) ){ - fgets(phone, 21, fn); phone[ strlen(phone) - 1] = 0; - fgets(career,41, fn); career[strlen(career)- 1] = 0; - fgets(ident, 12, fn); ident[ strlen(ident) - 1] = 0; - fgets(rname, 21, fn); rname[ strlen(rname) - 1] = 0; - fgets(addr, 51, fn); addr [ strlen(addr) - 1] = 0; - fgets(mobile,21, fn); mobile[strlen(mobile)- 1] = 0; - fclose(fn); - } - } - else{ + if( phone[0] != 0 ){ fn = fopen(buf, "w"); fprintf(fn, "%s\n%s\n%s\n%s\n%s\n%s\n", phone, career, ident, rname, addr, mobile); fclose(fn); } + clear(); stand_title("認證設定"); move(2, 0); @@ -841,17 +831,17 @@ static void toregister(char *email, char *genbuf, char *phone, char *career, while( 1 ){ email[0] = 0; getfield(10, "身分認證用", "E-Mail Address", email, 50); - if( email[0] == 0 || strcmp(email, "x") == 0 || - strcmp(email, "X") == 0 || isvaildemail(email) ) + if( strcmp(email, "x") == 0 || strcmp(email, "X") == 0 || + isvaildemail(email) ) break; else{ move(17, 0); - prints("指定的 E-Mail 不合法, 若您無 E-Mail 請輸入 0"); + prints("指定的 E-Mail 不合法," + "若您無 E-Mail 請輸入 x由站長手動認證"); } } - if( email[0] == 0 ) /* 下次再來 */ - return; - else if( email[0] == 'x' || email[0] == 'X' ){ /* 手動認證 */ + strncpy(cuser.email, email, sizeof(cuser.email)); + if( email[0] == 'x' || email[0] == 'X' ){ /* 手動認證 */ if ((fn = fopen(fn_register, "a"))) { now = time(NULL); fprintf(fn, "num: %d, %s", usernum, ctime(&now)); @@ -913,9 +903,29 @@ int u_register(void) } fclose(fn); } - - memset(phone, 0, sizeof(phone)); - if( cuser.year != 0 ){ /* 已經第一次填過了~ ^^" */ + + strcpy(ident, cuser.ident); + strcpy(rname, cuser.realname); + strcpy(addr, cuser.address); + strcpy(email, cuser.email); + sprintf(mobile,"0%09d",cuser.mobile); + sprintf(birthday, "%02i/%02i/%02i", + cuser.month, cuser.day, cuser.year % 100); + sex_is[0]=(cuser.sex % 8)+'1';sex_is[1]=0; + career[0] = phone[0] = '\0'; + sethomefile(genbuf, cuser.userid, "justify.wait"); + if( (fn = fopen(genbuf, "r")) ){ + fgets(phone, 21, fn); phone[ strlen(phone) - 1] = 0; + fgets(career,41, fn); career[strlen(career)- 1] = 0; + fgets(ident, 12, fn); ident[ strlen(ident) - 1] = 0; + fgets(rname, 21, fn); rname[ strlen(rname) - 1] = 0; + fgets(addr, 51, fn); addr [ strlen(addr) - 1] = 0; + fgets(mobile,21, fn); mobile[strlen(mobile)- 1] = 0; + fclose(fn); + } + if( cuser.year != 0 && /* 已經第一次填過了~ ^^" */ + strcmp(cuser.email, "x") != 0 && /* 上次手動認證失敗 */ + strcmp(cuser.email, "X") != 0 ) { clear(); stand_title("EMail認證"); move(2, 0); @@ -956,15 +966,6 @@ int u_register(void) move(2, 0); clrtobot(); - strcpy(ident, cuser.ident); - strcpy(rname, cuser.realname); - strcpy(addr, cuser.address); - strcpy(email, cuser.email); - sprintf(mobile,"0%09d",cuser.mobile); - sprintf(birthday, "%02i/%02i/%02i", - cuser.month, cuser.day, cuser.year % 100); - sex_is[0]=(cuser.sex % 8)+'1';sex_is[1]=0; - career[0] = phone[0] = '\0'; while(1) { clear(); move(1, 0); -- cgit v1.2.3 From 21c6f358970127063203aa8010dcb1eefd7b6903 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Tue, 19 Mar 2002 04:47:34 +0000 Subject: if bbs abort, close all file descriptors(including network connection) first git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@50 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/mbbsd.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pttbbs/mbbsd/mbbsd.c b/pttbbs/mbbsd/mbbsd.c index 6e4f7e90..59cc974f 100644 --- a/pttbbs/mbbsd/mbbsd.c +++ b/pttbbs/mbbsd/mbbsd.c @@ -1,4 +1,4 @@ -/* $Id: mbbsd.c,v 1.12 2002/03/16 15:44:01 ptt Exp $ */ +/* $Id: mbbsd.c,v 1.13 2002/03/19 04:47:34 in2 Exp $ */ #include <stdio.h> #include <string.h> #include <stdlib.h> @@ -252,6 +252,10 @@ abort_bbs_debug (int sig) static int reentrant = 0; if (!reentrant){ + int i; + /* close all file descriptors (including the network connection) */ + for( i = 0 ; i < 256 ; ++i ) + close(i); reentrant = 1; if (currmode) u_exit ("AXXED"); -- cgit v1.2.3 From d1b7c701fc8946837aad84f5553b9a888e0578b5 Mon Sep 17 00:00:00 2001 From: ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Tue, 19 Mar 2002 14:29:51 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@51 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/talk.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pttbbs/mbbsd/talk.c b/pttbbs/mbbsd/talk.c index 0f0b66fe..026814fd 100644 --- a/pttbbs/mbbsd/talk.c +++ b/pttbbs/mbbsd/talk.c @@ -1,4 +1,4 @@ -/* $Id: talk.c,v 1.13 2002/03/16 15:11:10 ptt Exp $ */ +/* $Id: talk.c,v 1.14 2002/03/19 14:29:51 ptt Exp $ */ #include <stdio.h> #include <string.h> #include <errno.h> @@ -1402,7 +1402,7 @@ static void t_showhelp() { "來源/好友描述/戰績 切換\n" "(m) 寄信 (q/c) " "查詢網友/寵物\n" - "(r) 閱\讀信件 (l) 看上次熱訊\n" + "(r) 閱\讀信件 (l/C) 看上次熱訊/切換影身\n" "(f) 全部/好友列表 (數字) 跳至該使用者\n" "(p) 切換呼叫器 (g/i) 給錢/切換心情\n" "(a/d/o) 好友 增加/刪除/修改 (/)(s) 網友ID/暱稱搜尋"); -- cgit v1.2.3 From 79593a654c702d5860ff46e238334caf76425be3 Mon Sep 17 00:00:00 2001 From: ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Tue, 19 Mar 2002 14:34:41 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@52 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/talk.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pttbbs/mbbsd/talk.c b/pttbbs/mbbsd/talk.c index 026814fd..eb4ff2f0 100644 --- a/pttbbs/mbbsd/talk.c +++ b/pttbbs/mbbsd/talk.c @@ -1,4 +1,4 @@ -/* $Id: talk.c,v 1.14 2002/03/19 14:29:51 ptt Exp $ */ +/* $Id: talk.c,v 1.15 2002/03/19 14:34:41 ptt Exp $ */ #include <stdio.h> #include <string.h> #include <errno.h> @@ -1402,7 +1402,7 @@ static void t_showhelp() { "來源/好友描述/戰績 切換\n" "(m) 寄信 (q/c) " "查詢網友/寵物\n" - "(r) 閱\讀信件 (l/C) 看上次熱訊/切換影身\n" + "(r) 閱\讀信件 (l/C) 看上次熱訊/切換影身\n" "(f) 全部/好友列表 (數字) 跳至該使用者\n" "(p) 切換呼叫器 (g/i) 給錢/切換心情\n" "(a/d/o) 好友 增加/刪除/修改 (/)(s) 網友ID/暱稱搜尋"); -- cgit v1.2.3 From 821878c6d728d412042e946d87d545daf8ef2616 Mon Sep 17 00:00:00 2001 From: ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Tue, 19 Mar 2002 16:03:23 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@53 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/include/pttstruct.h | 4 ++-- pttbbs/mbbsd/cache.c | 3 +-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/pttbbs/include/pttstruct.h b/pttbbs/include/pttstruct.h index 1fb3fc24..d2d5f59e 100644 --- a/pttbbs/include/pttstruct.h +++ b/pttbbs/include/pttstruct.h @@ -1,4 +1,4 @@ -/* $Id: pttstruct.h,v 1.3 2002/03/16 13:18:53 ptt Exp $ */ +/* $Id: pttstruct.h,v 1.4 2002/03/19 16:03:23 ptt Exp $ */ #ifndef INCLUDE_STRUCT_H #define INCLUDE_STRUCT_H @@ -291,7 +291,7 @@ typedef struct bcache_t { boardheader_t bcache[MAX_BOARD]; boardheader_t *sorted[2][MAX_BOARD]; /* 0: by name 1: by class */ fileheader_t dircache[MAX_BOARD][DIRCACHESIZE]; - int cachetotal[MAX_BOARD]; + int busystate_b[MAX_BOARD]; int total[MAX_BOARD]; time_t lastposttime[MAX_BOARD]; time_t uptime; diff --git a/pttbbs/mbbsd/cache.c b/pttbbs/mbbsd/cache.c index 57ed0d3f..a0407437 100644 --- a/pttbbs/mbbsd/cache.c +++ b/pttbbs/mbbsd/cache.c @@ -1,4 +1,4 @@ -/* $Id: cache.c,v 1.2 2002/03/09 17:27:57 in2 Exp $ */ +/* $Id: cache.c,v 1.3 2002/03/19 16:02:23 ptt Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -601,7 +601,6 @@ void load_fileheader_cache(int bid, char *direct) brdshm->busystate = 1; get_records(direct, brdshm->dircache[bid - 1] , sizeof(fileheader_t),n<1?1:n, DIRCACHESIZE); - brdshm->cachetotal[bid-1]=num; // cachetotal先設 以後再改不用全部load brdshm->busystate = 0; } else -- cgit v1.2.3 From dfbf7f0c9d0d86145e390494b989ee6a7367f19d Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Wed, 20 Mar 2002 05:23:19 +0000 Subject: waterball git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@54 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/mbbsd.c | 37 +++++++++++++++++++------------------ pttbbs/mbbsd/talk.c | 10 ++++------ 2 files changed, 23 insertions(+), 24 deletions(-) diff --git a/pttbbs/mbbsd/mbbsd.c b/pttbbs/mbbsd/mbbsd.c index 59cc974f..9b223c23 100644 --- a/pttbbs/mbbsd/mbbsd.c +++ b/pttbbs/mbbsd/mbbsd.c @@ -1,4 +1,4 @@ -/* $Id: mbbsd.c,v 1.13 2002/03/19 04:47:34 in2 Exp $ */ +/* $Id: mbbsd.c,v 1.14 2002/03/20 05:23:19 in2 Exp $ */ #include <stdio.h> #include <string.h> #include <stdlib.h> @@ -369,7 +369,7 @@ static int add_history_water(water_t *w, msgque_t *msg) static int add_history(msgque_t *msg) { - int i = 0, j; + int i = 0, j, waterinit = 0; water_t *tmp; if( WATERMODE(WATER_ORIG) || WATERMODE(WATER_NEW) ) add_history_water(&water[0], msg); @@ -377,24 +377,25 @@ add_history(msgque_t *msg) for(i = 0 ; i < 5 && swater[i] ; i++ ) if( swater[i]->pid == msg->pid ) break; - if( i != 5 ){ - if( !swater[i] ){ - water_usies = i + 1; - swater[i] = &water[i + 1]; - strcpy(swater[i]->userid, msg->userid); - swater[i]->pid = msg->pid; - swater[i]->uin = (userinfo_t *)search_ulist_pid(msg->pid); - } - tmp = swater[i]; - } - else{ - tmp = swater[4]; - memset(swater[4], 0, sizeof (water_t)); - strcpy(swater[4]->userid, msg->userid); - swater[4]->pid = msg->pid; - swater[4]->uin = (userinfo_t *)search_ulist_pid(msg->pid); + if( i == 5 ){ + waterinit = 1; i = 4; + memset(swater[4], 0, sizeof(water_t)); + } + else if( !swater[i] ){ + water_usies = i + 1; + swater[i] = &water[i + 1]; + waterinit = 1; } + tmp = swater[i]; + + if( waterinit ){ + memcpy(swater[i]->userid, msg->userid, sizeof(swater[i]->userid)); + swater[i]->pid = msg->pid; + } + + if( !swater[i]->uin ) + swater[i]->uin = currutmp; for( j = i ; j > 0 ; j-- ) swater[j] = swater[j - 1]; diff --git a/pttbbs/mbbsd/talk.c b/pttbbs/mbbsd/talk.c index eb4ff2f0..6f1648f9 100644 --- a/pttbbs/mbbsd/talk.c +++ b/pttbbs/mbbsd/talk.c @@ -1,4 +1,4 @@ -/* $Id: talk.c,v 1.15 2002/03/19 14:34:41 ptt Exp $ */ +/* $Id: talk.c,v 1.16 2002/03/20 05:23:19 in2 Exp $ */ #include <stdio.h> #include <string.h> #include <errno.h> @@ -308,7 +308,8 @@ int isvisible_stat(userinfo_t * me, userinfo_t * uentp, int fri_stat) if (PERM_HIDE(uentp) && !(PERM_HIDE(me)))/* 對方紫色隱形而你沒有 */ return 0; else if ((me->userlevel & PERM_SYSOP) || - ((fri_stat & HRM) && (fri_stat & HFM))) /* 站長看的見任何人 */ + ((fri_stat & HRM) && (fri_stat & HFM))) + /* 站長看的見任何人 */ return 1; if (uentp->invisible && !(me->userlevel & PERM_SEECLOAK)) return 0; @@ -470,12 +471,10 @@ void water_scr(water_t *tw, int which, char type) else{ move(8 + which, 28); prints("123456789012345678901234567890"); - // refresh(); move(8 + which, 28); prints("\033[1;37;44m %c %-13s \033[0m", tw->uin ? ' ' : 'x', tw->userid); - // refresh(); } } @@ -504,7 +503,7 @@ void my_write2(void) if( swater[i]->uin && (swater[i]->pid != swater[i]->uin->pid || strcmp(swater[i]->userid, swater[i]->uin->userid)) ) - swater[i]->uin = NULL; + swater[i]->uin = (userinfo_t*)search_ulist_pid(swater[i]->pid); water_scr(swater[i], i, 0); } move(15, 4); @@ -556,7 +555,6 @@ void my_write2(void) else msg[0] = 0; move(0, 0);prints("\033[m"); clrtoeol(); - refresh(); sprintf(genbuf, "攻擊 %s:", tw->userid); if( !oldgetdata(0, 0, genbuf, msg, 80-strlen(tw->userid)-6, DOECHO) ) -- cgit v1.2.3 From 0809be9f1679f3cc651b47a984f4f9865439025d Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Wed, 20 Mar 2002 05:31:54 +0000 Subject: fix bug (register) git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@55 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/user.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pttbbs/mbbsd/user.c b/pttbbs/mbbsd/user.c index 2069e084..814ffc4e 100644 --- a/pttbbs/mbbsd/user.c +++ b/pttbbs/mbbsd/user.c @@ -1,4 +1,4 @@ -/* $Id: user.c,v 1.11 2002/03/18 20:24:29 in2 Exp $ */ +/* $Id: user.c,v 1.12 2002/03/20 05:31:54 in2 Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -955,7 +955,6 @@ int u_register(void) outs("認證碼錯誤\n"); pressanykey(); } - phone[0] = 0; toregister(email, genbuf, phone, career, ident, rname, addr, mobile); return FULLUPDATE; } -- cgit v1.2.3 From ef833f5215c5968970730fc711f2b9b20d008fd8 Mon Sep 17 00:00:00 2001 From: ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Wed, 20 Mar 2002 13:48:56 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@56 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/talk.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/pttbbs/mbbsd/talk.c b/pttbbs/mbbsd/talk.c index 6f1648f9..40ad9347 100644 --- a/pttbbs/mbbsd/talk.c +++ b/pttbbs/mbbsd/talk.c @@ -1,4 +1,4 @@ -/* $Id: talk.c,v 1.16 2002/03/20 05:23:19 in2 Exp $ */ +/* $Id: talk.c,v 1.17 2002/03/20 13:48:56 ptt Exp $ */ #include <stdio.h> #include <string.h> #include <errno.h> @@ -502,7 +502,7 @@ void my_write2(void) else{ if( swater[i]->uin && (swater[i]->pid != swater[i]->uin->pid || - strcmp(swater[i]->userid, swater[i]->uin->userid)) ) + swater[i]->userid[0]!=swater[i]->uin->userid[0]) ) swater[i]->uin = (userinfo_t*)search_ulist_pid(swater[i]->pid); water_scr(swater[i], i, 0); } @@ -747,9 +747,11 @@ void t_display_new(void) if(i>0) if(swater[i-1]) { - if(swater[i-1]->uin && - swater[i-1]->uin->pid!=swater[i-1]->pid) - swater[i-1]->uin=NULL; + + if( swater[i-1]->uin && + (swater[i-1]->pid != swater[i-1]->uin->pid || + swater[i-1]->userid[0]!=swater[i-1]->uin->userid[0]) ) + swater[i-1]->uin = (userinfo_t*)search_ulist_pid(swater[i-1]->pid); prints("%s%c%-13.13s\033[m", swater[i-1]!=water_which? "" : swater[i-1]->uin?"\033[1;33;47m": -- cgit v1.2.3 From dea0c8d2e90095ed4bf577b308203820ab522262 Mon Sep 17 00:00:00 2001 From: ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Wed, 20 Mar 2002 13:49:45 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@57 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/talk.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pttbbs/mbbsd/talk.c b/pttbbs/mbbsd/talk.c index 40ad9347..c9b108c8 100644 --- a/pttbbs/mbbsd/talk.c +++ b/pttbbs/mbbsd/talk.c @@ -1,4 +1,4 @@ -/* $Id: talk.c,v 1.17 2002/03/20 13:48:56 ptt Exp $ */ +/* $Id: talk.c,v 1.18 2002/03/20 13:49:45 ptt Exp $ */ #include <stdio.h> #include <string.h> #include <errno.h> @@ -1402,7 +1402,7 @@ static void t_showhelp() { "來源/好友描述/戰績 切換\n" "(m) 寄信 (q/c) " "查詢網友/寵物\n" - "(r) 閱\讀信件 (l/C) 看上次熱訊/切換影身\n" + "(r) 閱\讀信件 (l/C) 看上次熱訊/切換隱身\n" "(f) 全部/好友列表 (數字) 跳至該使用者\n" "(p) 切換呼叫器 (g/i) 給錢/切換心情\n" "(a/d/o) 好友 增加/刪除/修改 (/)(s) 網友ID/暱稱搜尋"); -- cgit v1.2.3 From 65cd28bac80ce61edbcaf836604cbf3f240d6121 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sat, 23 Mar 2002 09:04:54 +0000 Subject: add CPULIMIT git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@58 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/mbbsd.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/pttbbs/mbbsd/mbbsd.c b/pttbbs/mbbsd/mbbsd.c index 9b223c23..2e910180 100644 --- a/pttbbs/mbbsd/mbbsd.c +++ b/pttbbs/mbbsd/mbbsd.c @@ -1,4 +1,4 @@ -/* $Id: mbbsd.c,v 1.14 2002/03/20 05:23:19 in2 Exp $ */ +/* $Id: mbbsd.c,v 1.15 2002/03/23 09:04:54 in2 Exp $ */ #include <stdio.h> #include <string.h> #include <stdlib.h> @@ -15,6 +15,7 @@ #include <sys/wait.h> #include <sys/socket.h> #include <sys/time.h> +#include <sys/resource.h> #include <netinet/in.h> #include <arpa/inet.h> #include <arpa/telnet.h> @@ -1004,6 +1005,12 @@ start_client () #if FORCE_PROCESS_REGISTER_FORM int nreg; #endif +#ifdef CPULIMIT + struct rlimit rml; + rml.rlim_cur = CPULIMIT * 60; + rml.rlim_max = CPULIMIT * 60; + setrlimit(RLIMIT_CPU, &rml); +#endif /* system init */ nice (2); /* Ptt: lower priority */ -- cgit v1.2.3 From b3311d8bc9c386b99a2ef8e4788f05887f3d7a08 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sat, 23 Mar 2002 13:19:40 +0000 Subject: add shmctl git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@59 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/Makefile | 7 +++-- pttbbs/util/shmctl.c | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 80 insertions(+), 2 deletions(-) create mode 100644 pttbbs/util/shmctl.c diff --git a/pttbbs/util/Makefile b/pttbbs/util/Makefile index 6f204648..2b7aa690 100644 --- a/pttbbs/util/Makefile +++ b/pttbbs/util/Makefile @@ -1,4 +1,4 @@ -# $Id: Makefile,v 1.4 2002/03/09 17:44:30 in2 Exp $ +# $Id: Makefile,v 1.5 2002/03/23 13:19:40 in2 Exp $ BBSHOME?=$(HOME) OSTYPE=linux @@ -30,7 +30,7 @@ CPROGS= bbsmail BM_money post account birth deluserfile expire mandex\ poststat showboard antispam countalldice webgrep bbsrf\ initbbs outmail xchatd userlist tunepasswd buildir reaper shmsweep\ merge_passwd merge_board inndBM buildAnnounce rmuid \ - toplazyBM jungo toplazyBBM + toplazyBM jungo toplazyBBM shmctl PROGS= $(CPROGS) BM_money.sh backpasswd.sh mailog.sh opendice.sh\ openticket.sh stock.sh topsong.sh weather.sh stock.perl weather.perl\ @@ -152,6 +152,9 @@ merge_board : merge_board.c bbsctl: bbsctl.c $(CC) $(CFLAGS) -o $@ $@.c +shmctl: shmctl.c + $(CC) $(CFLAGS) -o $@ $@.c $(OBJS) + install: $(PROGS) install -d $(BBSHOME)/bin/ install -c -m 755 $(PROGS) $(BBSHOME)/bin/ diff --git a/pttbbs/util/shmctl.c b/pttbbs/util/shmctl.c new file mode 100644 index 00000000..77b9c99b --- /dev/null +++ b/pttbbs/util/shmctl.c @@ -0,0 +1,75 @@ +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <ctype.h> +#include <signal.h> +#include <sys/types.h> +#include <sys/stat.h> +#include "config.h" +#include "pttstruct.h" +#include "util.h" + +extern struct utmpfile_t *utmpshm; + +int fixutmp(int argc, char **argv) +{ + int i; + char buf[1024], *clean; + struct stat st; + if( utmpshm->busystate ){ + puts("utmpshm is busy"); + return 0; + } + utmpshm->busystate = 1; + for( i = 0 ; i < USHM_SIZE ; ++i ) + if( utmpshm->uinfo[i].pid ){ + clean = NULL; + if( !isalpha(utmpshm->uinfo[i].userid[0]) ) + clean = "userid error"; + else{ + sprintf(buf, "/proc/%d", utmpshm->uinfo[i].pid); + if( stat(buf, &st) < 0 ) + clean = "process not exist"; + } + + if( clean ){ + printf("clean %06d(%s), userid: %s\n", + i, clean, utmpshm->uinfo[i].userid); + memset(&utmpshm->uinfo[i], 0, sizeof(userinfo_t)); + } + } + utmpshm->busystate = 0; + return 0; +} + +struct { + int (*func)(int, char **); + char *cmd, *descript; +} cmd[] = + { {fixutmp, "fixutmp", "clear dead userlist entry"}, + {NULL, NULL, NULL} }; + +int main(int argc, char **argv) +{ + int i = 0; + + if( argc >= 2 ){ + resolve_utmp(); + resolve_boards(); + //resolve_garbage(); + resolve_fcache(); + for( i = 0 ; cmd[i].func != NULL ; ++i ) + if( strcmp(cmd[i].cmd, argv[1]) == 0 ){ + cmd[i].func(argc - 2, &argv[2]); + break; + } + } + if( argc == 1 || cmd[i].func == NULL ){ + /* usage */ + printf("usage: bbsctl [command] [options]\n"); + printf("commands:\n"); + for( i = 0 ; cmd[i].func != NULL ; ++i ) + printf("\t%-15s%s\n", cmd[i].cmd, cmd[i].descript); + } + return 0; +} -- cgit v1.2.3 From 0bd2558144a0379c433e79267ac8ca4740d9a916 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sun, 24 Mar 2002 14:54:12 +0000 Subject: utmpsort git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@60 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/shmctl.c | 89 +++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 88 insertions(+), 1 deletion(-) diff --git a/pttbbs/util/shmctl.c b/pttbbs/util/shmctl.c index 77b9c99b..9d6846e9 100644 --- a/pttbbs/util/shmctl.c +++ b/pttbbs/util/shmctl.c @@ -1,5 +1,6 @@ #include <stdio.h> #include <stdlib.h> +#include <string.h> #include <unistd.h> #include <ctype.h> #include <signal.h> @@ -42,11 +43,97 @@ int fixutmp(int argc, char **argv) return 0; } +/* ulistsort */ +static int cmputmpuserid(const void *i, const void *j){ + return strcasecmp((*((userinfo_t**)i))->userid, (*((userinfo_t**)j))->userid); +} + +static int cmputmpmode(const void *i, const void *j){ + return (*((userinfo_t**)i))->mode-(*((userinfo_t**)j))->mode; +} + +static int cmputmpidle(const void *i, const void *j){ + return (*((userinfo_t**)i))->lastact-(*((userinfo_t**)j))->lastact; +} + +static int cmputmpfrom(const void *i, const void *j){ + return strcasecmp((*((userinfo_t**)i))->from, (*((userinfo_t**)j))->from); +} + +static int cmputmpfive(const void *i, const void *j){ + int type; + if((type=(*((userinfo_t**)j))->five_win - (*((userinfo_t**)i))->five_win)) + return type; + if((type=(*((userinfo_t**)i))->five_lose - (*((userinfo_t**)j))->five_lose)) + return type; + return (*((userinfo_t**)i))->five_tie-(*((userinfo_t**)j))->five_tie; +} + +static int cmputmpsex(const void *i, const void *j){ + static int ladyfirst[]={1,0,1,0,1,0,3,3}; + return ladyfirst[(*((userinfo_t**)i))->sex]-ladyfirst[(*((userinfo_t**)j))->sex]; +} +static int cmputmppid(const void *i, const void *j){ + return (*((userinfo_t**)i))->pid-(*((userinfo_t**)j))->pid; +} +static int cmputmpuid(const void *i, const void *j){ + return (*((userinfo_t**)i))->uid-(*((userinfo_t**)j))->uid; +} + +int ulistsort(int argc, char **argv) +{ + time_t now=time(NULL); + int count, i, ns; + userinfo_t *uentp; + + if(now-utmpshm->uptime<60 && (now==utmpshm->uptime || utmpshm->busystate)){ + puts("lazy sort"); + //return; /* lazy sort */ + } + utmpshm->busystate=1; + utmpshm->uptime = now; + ns=(utmpshm->currsorted?0:1); + + for(uentp = &utmpshm->uinfo[0], count=0, i=0; + i< USHM_SIZE; i++,uentp = &utmpshm->uinfo[i]) + if(uentp->pid){ + utmpshm->sorted[ns][0][count++]= uentp; + } + utmpshm->number = count; + qsort(utmpshm->sorted[ns][0],count,sizeof(userinfo_t*),cmputmpuserid); + memcpy(utmpshm->sorted[ns][1],utmpshm->sorted[ns][0], + sizeof(userinfo_t *)*count); + memcpy(utmpshm->sorted[ns][2],utmpshm->sorted[ns][0], + sizeof(userinfo_t *)*count); + memcpy(utmpshm->sorted[ns][3],utmpshm->sorted[ns][0], + sizeof(userinfo_t *)*count); + memcpy(utmpshm->sorted[ns][4],utmpshm->sorted[ns][0], + sizeof(userinfo_t *)*count); + memcpy(utmpshm->sorted[ns][5],utmpshm->sorted[ns][0], + sizeof(userinfo_t *)*count); + memcpy(utmpshm->sorted[ns][6],utmpshm->sorted[ns][0], + sizeof(userinfo_t *)*count); + memcpy(utmpshm->sorted[ns][7],utmpshm->sorted[ns][0], + sizeof(userinfo_t *)*count); + qsort(utmpshm->sorted[ns][1], count, sizeof(userinfo_t *), cmputmpmode ); + qsort(utmpshm->sorted[ns][2], count, sizeof(userinfo_t *), cmputmpidle ); + qsort(utmpshm->sorted[ns][3], count, sizeof(userinfo_t *), cmputmpfrom ); + qsort(utmpshm->sorted[ns][4], count, sizeof(userinfo_t *), cmputmpfive ); + qsort(utmpshm->sorted[ns][5], count, sizeof(userinfo_t *), cmputmpsex ); + qsort(utmpshm->sorted[ns][6], count, sizeof(userinfo_t *), cmputmpuid ); + qsort(utmpshm->sorted[ns][7], count, sizeof(userinfo_t *), cmputmppid ); + utmpshm->currsorted=ns; + utmpshm->busystate=0; + return 0; +} + +/* end of ulistsort */ struct { int (*func)(int, char **); char *cmd, *descript; } cmd[] = - { {fixutmp, "fixutmp", "clear dead userlist entry"}, + { {fixutmp, "fixutmp", "clear dead userlist entry"}, + {ulistsort, "ulistsort", "sort ulist"}, {NULL, NULL, NULL} }; int main(int argc, char **argv) -- cgit v1.2.3 From d2a67fec66195cafa0318f04ba368adb26b17869 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sun, 24 Mar 2002 15:13:55 +0000 Subject: add utmpstate, utmp git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@61 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/shmctl.c | 66 ++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 46 insertions(+), 20 deletions(-) diff --git a/pttbbs/util/shmctl.c b/pttbbs/util/shmctl.c index 9d6846e9..e28a971c 100644 --- a/pttbbs/util/shmctl.c +++ b/pttbbs/util/shmctl.c @@ -43,49 +43,70 @@ int fixutmp(int argc, char **argv) return 0; } +int utmpstate(int argc, char **argv) +{ + printf("currsorted: %d\n", utmpshm->currsorted); + printf("uptime: %s", ctime(&utmpshm->uptime)); + printf("number: %d\n", utmpshm->number); + printf("busystate: %d\n", utmpshm->busystate); + return 0; +} + +int utmpreset(int argc, char **argv) +{ + utmpshm->busystate=0; + utmpstate(0, NULL); + return 0; +} + /* ulistsort */ static int cmputmpuserid(const void *i, const void *j){ - return strcasecmp((*((userinfo_t**)i))->userid, (*((userinfo_t**)j))->userid); + return strcasecmp((*((userinfo_t**)i))->userid, + (*((userinfo_t**)j))->userid); } static int cmputmpmode(const void *i, const void *j){ - return (*((userinfo_t**)i))->mode-(*((userinfo_t**)j))->mode; + return (*((userinfo_t**)i))->mode- + (*((userinfo_t**)j))->mode; } static int cmputmpidle(const void *i, const void *j){ - return (*((userinfo_t**)i))->lastact-(*((userinfo_t**)j))->lastact; + return (*((userinfo_t**)i))->lastact- + (*((userinfo_t**)j))->lastact; } static int cmputmpfrom(const void *i, const void *j){ - return strcasecmp((*((userinfo_t**)i))->from, (*((userinfo_t**)j))->from); + return strcasecmp((*((userinfo_t**)i))->from, + (*((userinfo_t**)j))->from); } static int cmputmpfive(const void *i, const void *j){ - int type; - if((type=(*((userinfo_t**)j))->five_win - (*((userinfo_t**)i))->five_win)) - return type; - if((type=(*((userinfo_t**)i))->five_lose - (*((userinfo_t**)j))->five_lose)) - return type; - return (*((userinfo_t**)i))->five_tie-(*((userinfo_t**)j))->five_tie; + int type; + if((type=(*((userinfo_t**)j))->five_win - (*((userinfo_t**)i))->five_win)) + return type; + if((type=(*((userinfo_t**)i))->five_lose-(*((userinfo_t**)j))->five_lose)) + return type; + return (*((userinfo_t**)i))->five_tie-(*((userinfo_t**)j))->five_tie; } static int cmputmpsex(const void *i, const void *j){ - static int ladyfirst[]={1,0,1,0,1,0,3,3}; - return ladyfirst[(*((userinfo_t**)i))->sex]-ladyfirst[(*((userinfo_t**)j))->sex]; + static int ladyfirst[]={1,0,1,0,1,0,3,3}; + return ladyfirst[(*((userinfo_t**)i))->sex]- + ladyfirst[(*((userinfo_t**)j))->sex]; } static int cmputmppid(const void *i, const void *j){ - return (*((userinfo_t**)i))->pid-(*((userinfo_t**)j))->pid; + return (*((userinfo_t**)i))->pid-(*((userinfo_t**)j))->pid; } static int cmputmpuid(const void *i, const void *j){ - return (*((userinfo_t**)i))->uid-(*((userinfo_t**)j))->uid; + return (*((userinfo_t**)i))->uid-(*((userinfo_t**)j))->uid; } -int ulistsort(int argc, char **argv) +int utmpsort(int argc, char **argv) { - time_t now=time(NULL); + time_t now=time(NULL); int count, i, ns; userinfo_t *uentp; - + if(now-utmpshm->uptime<60 && (now==utmpshm->uptime || utmpshm->busystate)){ puts("lazy sort"); //return; /* lazy sort */ @@ -119,21 +140,26 @@ int ulistsort(int argc, char **argv) qsort(utmpshm->sorted[ns][2], count, sizeof(userinfo_t *), cmputmpidle ); qsort(utmpshm->sorted[ns][3], count, sizeof(userinfo_t *), cmputmpfrom ); qsort(utmpshm->sorted[ns][4], count, sizeof(userinfo_t *), cmputmpfive ); - qsort(utmpshm->sorted[ns][5], count, sizeof(userinfo_t *), cmputmpsex ); + //qsort(utmpshm->sorted[ns][5], count, sizeof(userinfo_t *), cmputmpsex ); qsort(utmpshm->sorted[ns][6], count, sizeof(userinfo_t *), cmputmpuid ); qsort(utmpshm->sorted[ns][7], count, sizeof(userinfo_t *), cmputmppid ); utmpshm->currsorted=ns; utmpshm->busystate=0; + + puts("new utmpstate"); + utmpstate(0, NULL); return 0; } - /* end of ulistsort */ + struct { int (*func)(int, char **); char *cmd, *descript; } cmd[] = { {fixutmp, "fixutmp", "clear dead userlist entry"}, - {ulistsort, "ulistsort", "sort ulist"}, + {utmpstate, "utmpstate", "list utmpstate"}, + {utmpreset, "resetutmp", "utmpshm->busystate=0"}, + {utmpsort, "ulistsort", "sort ulist"}, {NULL, NULL, NULL} }; int main(int argc, char **argv) -- cgit v1.2.3 From 3053a202e78361f33aab7bc6456c4a5adff55130 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sun, 24 Mar 2002 16:19:19 +0000 Subject: shmctl git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@62 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/.cvsignore | 3 ++- pttbbs/util/shmctl.c | 23 ++++++++++++++++++----- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/pttbbs/util/.cvsignore b/pttbbs/util/.cvsignore index e7408563..73de8aac 100644 --- a/pttbbs/util/.cvsignore +++ b/pttbbs/util/.cvsignore @@ -39,4 +39,5 @@ toplazyBBM toplazyBM jungo bbsctl -daymandex +mandex +shmctl \ No newline at end of file diff --git a/pttbbs/util/shmctl.c b/pttbbs/util/shmctl.c index e28a971c..f8698398 100644 --- a/pttbbs/util/shmctl.c +++ b/pttbbs/util/shmctl.c @@ -12,7 +12,7 @@ extern struct utmpfile_t *utmpshm; -int fixutmp(int argc, char **argv) +int utmpfix(int argc, char **argv) { int i; char buf[1024], *clean; @@ -43,10 +43,23 @@ int fixutmp(int argc, char **argv) return 0; } +char *CTIME(char *buf, time_t t) +{ + strcpy(buf, ctime(&t)); + buf[strlen(buf) - 1] = 0; + return buf; +} + int utmpstate(int argc, char **argv) { + time_t now; + char upbuf[64], nowbuf[64]; + now = time(NULL); + CTIME(upbuf, utmpshm->uptime); + CTIME(nowbuf, time(NULL)); + printf("now: %s\n", nowbuf); printf("currsorted: %d\n", utmpshm->currsorted); - printf("uptime: %s", ctime(&utmpshm->uptime)); + printf("uptime: %s\n", upbuf); printf("number: %d\n", utmpshm->number); printf("busystate: %d\n", utmpshm->busystate); return 0; @@ -156,10 +169,10 @@ struct { int (*func)(int, char **); char *cmd, *descript; } cmd[] = - { {fixutmp, "fixutmp", "clear dead userlist entry"}, + { {utmpfix, "utmpfix", "clear dead userlist entry"}, {utmpstate, "utmpstate", "list utmpstate"}, - {utmpreset, "resetutmp", "utmpshm->busystate=0"}, - {utmpsort, "ulistsort", "sort ulist"}, + {utmpreset, "utmpreset", "utmpshm->busystate=0"}, + {utmpsort, "utmpsort", "sort ulist"}, {NULL, NULL, NULL} }; int main(int argc, char **argv) -- cgit v1.2.3 From 0c065520c399d4a66c89ebcf9692bcce01805ec2 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sun, 24 Mar 2002 16:27:09 +0000 Subject: :) git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@63 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/Makefile | 9 ++++++--- pttbbs/util/filtermail.pl | 43 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 3 deletions(-) create mode 100644 pttbbs/util/filtermail.pl diff --git a/pttbbs/util/Makefile b/pttbbs/util/Makefile index 2b7aa690..c1cbf06c 100644 --- a/pttbbs/util/Makefile +++ b/pttbbs/util/Makefile @@ -1,7 +1,7 @@ -# $Id: Makefile,v 1.5 2002/03/23 13:19:40 in2 Exp $ +# $Id: Makefile,v 1.6 2002/03/24 16:27:09 in2 Exp $ BBSHOME?=$(HOME) -OSTYPE=linux +OSTYPE?=linux # FreeBSD CC_FreeBSD= gcc @@ -34,7 +34,8 @@ CPROGS= bbsmail BM_money post account birth deluserfile expire mandex\ PROGS= $(CPROGS) BM_money.sh backpasswd.sh mailog.sh opendice.sh\ openticket.sh stock.sh topsong.sh weather.sh stock.perl weather.perl\ - toplazyBM.sh toplazyBBM.sh dailybackup.pl tarqueue.pl waterball.pl + toplazyBM.sh toplazyBBM.sh dailybackup.pl tarqueue.pl waterball.pl \ + filtermail.pl all: $(PROGS) @@ -159,6 +160,8 @@ install: $(PROGS) install -d $(BBSHOME)/bin/ install -c -m 755 $(PROGS) $(BBSHOME)/bin/ chmod 4755 $(BBSHOME)/bin/post + mv $(BBSHOME)/bin/bbsmail $(BBSHOME)/bin/realbbsmail + ln -s $(BBSHOME)/bin/filtermail.pl $(BBSHOME)/bin/bbsmail clean: rm -f *.o $(CPROGS) diff --git a/pttbbs/util/filtermail.pl b/pttbbs/util/filtermail.pl new file mode 100644 index 00000000..45c13c86 --- /dev/null +++ b/pttbbs/util/filtermail.pl @@ -0,0 +1,43 @@ +#!/usr/bin/perl +if( -e '/usr/bin/mktemp' ){ + $fn = `/usr/bin/mktemp -q /tmp/filtermail.XXXXXXXX`; +} +else{ + $fn = `/bin/mktemp -q /tmp/filtermail.XXXXXXXX`; +} +chomp $fn; + +$bbsuid = $ARGV[0]; +undef @ARGV; + +open FH, ">$fn"; +$norelay = 0; +while( <> ){ + print FH $_; +# if( ($bbsuid) = $_ =~ /for \<(\w+)\.bbs\@ptt/ ){ +# } + if( /^Content-Type:/i ){ + $norelay = 1 if( (/multipart/i && !/report/i) || /html/ ); + last; + } +} +while( <> ){ + print FH $_; +} +close FH; + +if( !$norelay ){ + open FH, "<$fn"; + open OUT, "|/home/bbs/bin/realbbsmail $bbsuid"; + while( <FH> ){ + print OUT $_; + } + close FH; + close OUT; + unlink $fn; +} +else{ + $to = substr($fn, rindex($fn, '/') + 1); + `/bin/mv $fn /tmp/norelay/$to`; +} + -- cgit v1.2.3 From ec3c8c6501c352d90784d065907e061e74b54b14 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sun, 24 Mar 2002 18:25:48 +0000 Subject: =?UTF-8?q?use=20mutt=20to=20(Z)ip=20UserHome=20=20=EF=BF=BD?= =?UTF-8?q?=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BDp?= =?UTF-8?q?=EF=BF=BDH=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD?= =?UTF-8?q?=EF=BF=BD=EF=BF=BD]=EF=BF=BD^=EF=BF=BDh?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@64 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/mail.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/pttbbs/mbbsd/mail.c b/pttbbs/mbbsd/mail.c index e480abb2..4a9395fa 100644 --- a/pttbbs/mbbsd/mail.c +++ b/pttbbs/mbbsd/mail.c @@ -1,4 +1,4 @@ -/* $Id: mail.c,v 1.1 2002/03/07 15:13:48 in2 Exp $ */ +/* $Id: mail.c,v 1.2 2002/03/24 18:25:48 in2 Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -1563,6 +1563,13 @@ int doforward(char *direct, fileheader_t *fh, int mode) { } if(mode == 'Z') { + sprintf(fname, TAR_PATH " cfz /tmp/home.%s.tgz home/%c/%s; " + MUTT_PATH" -a /tmp/home.%s.tgz -s 'home.%s.tgz' %s </dev/null;" + "rm /tmp/home.%s.tgz", + cuser.userid, cuser.userid[0], cuser.userid, + cuser.userid, cuser.userid, address, cuser.userid); + system(fname); + return 0; sprintf(fname, TAR_PATH " cfz - home/%c/%s | " "/usr/bin/uuencode %s.tgz > %s", cuser.userid[0], cuser.userid, cuser.userid, direct); -- cgit v1.2.3 From 30f72dcf9398e14bc3df4f0282312a5bf781bc49 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sun, 24 Mar 2002 18:32:52 +0000 Subject: mutt git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@65 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/include/config.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pttbbs/include/config.h b/pttbbs/include/config.h index 3eb6e64a..eb1ea28f 100644 --- a/pttbbs/include/config.h +++ b/pttbbs/include/config.h @@ -1,4 +1,4 @@ -/* $Id: config.h,v 1.1 2002/03/07 15:13:48 in2 Exp $ */ +/* $Id: config.h,v 1.2 2002/03/24 18:32:52 in2 Exp $ */ #ifndef INCLUDE_CONFIG_H #define INCLUDE_CONFIG_H @@ -69,6 +69,10 @@ #define TAR_PATH "tar" #endif +#ifndef MUTT_PATH +#define MUTT_PATH "mutt" +#endif + #ifndef HBFLexpire #define HBFLexpire (432000) /* 5 days */ #endif -- cgit v1.2.3 From 7119f39097f6efcbd173d854fe53590b2819ba48 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Mon, 25 Mar 2002 04:01:37 +0000 Subject: delete filtered mail git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@66 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/filtermail.pl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pttbbs/util/filtermail.pl b/pttbbs/util/filtermail.pl index 45c13c86..c7a728f7 100644 --- a/pttbbs/util/filtermail.pl +++ b/pttbbs/util/filtermail.pl @@ -38,6 +38,7 @@ if( !$norelay ){ } else{ $to = substr($fn, rindex($fn, '/') + 1); - `/bin/mv $fn /tmp/norelay/$to`; + #`/bin/mv $fn /tmp/norelay/$to`; + unlink $fn; } -- cgit v1.2.3 From f519a5859eb8f3a0df4acea0d5cd187a9d7cac28 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Mon, 25 Mar 2002 16:20:20 +0000 Subject: add utmpwatch git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@67 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/shmctl.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/pttbbs/util/shmctl.c b/pttbbs/util/shmctl.c index f8698398..5932fdf3 100644 --- a/pttbbs/util/shmctl.c +++ b/pttbbs/util/shmctl.c @@ -165,6 +165,24 @@ int utmpsort(int argc, char **argv) } /* end of ulistsort */ +int utmpwatch(int argc, char **argv) +{ + int i; + while( 1 ){ + for( i = 0 ; i < 4 ; ++i ){ + usleep(300); + if( !utmpshm->busystate ) + break; + puts("busying..."); + } + if( i == 4 ){ + puts("reset!"); + utmpshm->busystate = 0; + } + } + return 0; +} + struct { int (*func)(int, char **); char *cmd, *descript; @@ -173,6 +191,7 @@ struct { {utmpstate, "utmpstate", "list utmpstate"}, {utmpreset, "utmpreset", "utmpshm->busystate=0"}, {utmpsort, "utmpsort", "sort ulist"}, + {utmpwatch, "utmpwatch", "to see if busystate is always 1 then fix it"}, {NULL, NULL, NULL} }; int main(int argc, char **argv) -- cgit v1.2.3 From 8154b0ee73cc1567394699a3bef6bf841148c320 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Thu, 28 Mar 2002 03:56:23 +0000 Subject: boards/<HASH> git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@68 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/tarqueue.pl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pttbbs/util/tarqueue.pl b/pttbbs/util/tarqueue.pl index 20bda9f1..f3463f30 100644 --- a/pttbbs/util/tarqueue.pl +++ b/pttbbs/util/tarqueue.pl @@ -35,7 +35,7 @@ sub ProcessBoard $now, $owner, $board, $bakboard, $bakman, $email); MakeMail({tartarget => "$TMP/$board.tgz", - tarsource => "boards/$board/* boards/$board/.DIR", + tarsource => "boards/". substr($board, 0, 1). "/$board", mailto => "$board的版主$owner <$email>", subject => "$board的看版備份", body => @@ -47,7 +47,7 @@ sub ProcessBoard }) if( $bakboard ); MakeMail({tartarget => "$TMP/man.$board.tgz", - tarsource => "man/boards/$board/* man/boards/$board/.DIR", + tarsource => "man/boards/". substr($board, 0, 1). "/$board", mailto => "$board的版主$owner <$email>", subject => "$board的精華區備份", body => -- cgit v1.2.3 From 628021e73dcb53c62fd015dafe6e8e491633f13a Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Thu, 28 Mar 2002 04:03:55 +0000 Subject: chdir BBSHOME first git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@69 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/account.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pttbbs/util/account.c b/pttbbs/util/account.c index 4b221df4..9d8f6a05 100644 --- a/pttbbs/util/account.c +++ b/pttbbs/util/account.c @@ -1,10 +1,11 @@ -/* $Id: account.c,v 1.3 2002/03/09 17:44:30 in2 Exp $ */ +/* $Id: account.c,v 1.4 2002/03/28 04:03:55 in2 Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> #include <time.h> #include <sys/types.h> #include <sys/stat.h> +#include <unistd.h> #include "config.h" #include "pttstruct.h" #include "util.h" @@ -111,6 +112,7 @@ int main() { time_t now; struct tm *ptime; + chdir(BBSHOME); now = time(NULL) - ADJUST_M * 60; /* back to ancent */ ptime = localtime(&now); -- cgit v1.2.3 From 4f4ecb2b76b427261a6f97930d8bd19a0bbe058e Mon Sep 17 00:00:00 2001 From: ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Fri, 29 Mar 2002 13:45:28 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@70 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/Makefile | 4 ++-- pttbbs/mbbsd/mbbsd.c | 20 +------------------- pttbbs/mbbsd/vote.c | 14 +++++++------- 3 files changed, 10 insertions(+), 28 deletions(-) diff --git a/pttbbs/mbbsd/Makefile b/pttbbs/mbbsd/Makefile index 6281e2fe..5919b885 100644 --- a/pttbbs/mbbsd/Makefile +++ b/pttbbs/mbbsd/Makefile @@ -1,7 +1,7 @@ -# $Id: Makefile,v 1.3 2002/03/16 13:19:46 ptt Exp $ +# $Id: Makefile,v 1.4 2002/03/29 13:45:28 ptt Exp $ BBSHOME?=$(HOME) -OSTYPE=linux +OSTYPE=FreeBSD # FreeBSD CFLAGS_FreeBSD= -pipe -Wall -g -O3 -DHAVE_SETPROCTITLE -DBBSHOME='"$(BBSHOME)"' -DFreeBSD -I../include diff --git a/pttbbs/mbbsd/mbbsd.c b/pttbbs/mbbsd/mbbsd.c index 2e910180..c793b6bc 100644 --- a/pttbbs/mbbsd/mbbsd.c +++ b/pttbbs/mbbsd/mbbsd.c @@ -1,4 +1,4 @@ -/* $Id: mbbsd.c,v 1.15 2002/03/23 09:04:54 in2 Exp $ */ +/* $Id: mbbsd.c,v 1.16 2002/03/29 13:45:28 ptt Exp $ */ #include <stdio.h> #include <string.h> #include <stdlib.h> @@ -1002,9 +1002,6 @@ static void start_client () { extern struct commands_t cmdlist[]; -#if FORCE_PROCESS_REGISTER_FORM - int nreg; -#endif #ifdef CPULIMIT struct rlimit rml; rml.rlim_cur = CPULIMIT * 60; @@ -1041,26 +1038,11 @@ start_client () user_login (); m_init (); -#if FORCE_PROCESS_REGISTER_FORM - if (HAS_PERM (PERM_SYSOP) && (nreg = dashs (fn_register) / 163) > 100){ - char cpu_load[30]; - if (cpuload (cpu_load) > MAX_CPULOAD * 2 / 3) - /* DickG: 根據目前的 load 來決定要審核的數目 */ - scan_register_form (fn_register, 1, nreg / 20); - else - scan_register_form (fn_register, 1, nreg / 10); - } -#endif if (HAVE_PERM (PERM_SYSOP | PERM_BM)) b_closepolls (); if (!(cuser.uflag & COLOR_FLAG)) showansi = 0; -#ifdef DOTIMEOUT - /* init_alarm(); */// cause strange logout with saving post. signal (SIGALRM, SIG_IGN); -#else - signal (SIGALRM, SIG_IGN); -#endif if (chkmailbox ()) m_read (); diff --git a/pttbbs/mbbsd/vote.c b/pttbbs/mbbsd/vote.c index b16857ce..8835a483 100644 --- a/pttbbs/mbbsd/vote.c +++ b/pttbbs/mbbsd/vote.c @@ -1,4 +1,4 @@ -/* $Id: vote.c,v 1.2 2002/03/09 17:27:57 in2 Exp $ */ +/* $Id: vote.c,v 1.3 2002/03/29 13:45:28 ptt Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -304,7 +304,7 @@ static void b_result(boardheader_t *fh) { char temp[STRLEN]; now = time(NULL); - for(i = 0; i < 9; i++) { + for(i = 0; i < 20; i++) { if(i) sprintf(STR_new_control, "%s%d", STR_bv_control, i); else @@ -511,7 +511,7 @@ static int vote_view_all(char *bname) { fclose(xfp); } - for(i = 1; i < 9; i++) { + for(i = 1; i < 20; i++) { sprintf(STR_new_control, "%s%d", STR_bv_control, i); sprintf(STR_new_title, "%s%d", STR_bv_title, i); setbfile(buf, bname, STR_new_control); @@ -593,7 +593,7 @@ static int vote_maintain(char *bname) { setbfile(buf, bname, STR_bv_title); unlink(buf); - for(i = 1; i < 9; i++) { + for(i = 1; i < 20; i++) { sprintf(STR_new_ballots, "%s%d", STR_bv_ballots, i); sprintf(STR_new_control, "%s%d", STR_bv_control, i); sprintf(STR_new_desc, "%s%d", STR_bv_desc, i); @@ -626,7 +626,7 @@ static int vote_maintain(char *bname) { strcpy(STR_new_control, STR_bv_control); setbfile(buf,bname, STR_new_control); x = 0; - while(x < 9 && (fp = fopen(buf,"r")) != NULL) { + while(x < 20 && (fp = fopen(buf,"r")) != NULL) { fclose(fp); x++; sprintf(STR_new_control, "%s%d", STR_bv_control, x); @@ -634,7 +634,7 @@ static int vote_maintain(char *bname) { } if(fp) fclose(fp); - if(x >=9) + if(x >=20) return FULLUPDATE; if(x) { sprintf(STR_new_ballots, "%s%d", STR_bv_ballots,x); @@ -1002,7 +1002,7 @@ static int user_vote(char *bname) { fclose(xfp); } - for(i = 1; i < 9; i++) { + for(i = 1; i < 20; i++) { sprintf(STR_new_control, "%s%d", STR_bv_control, i); sprintf(STR_new_title, "%s%d", STR_bv_title, i); setbfile(buf, bname, STR_new_control); -- cgit v1.2.3 From 91699ff58cf124850359c8440bf989b9a2506707 Mon Sep 17 00:00:00 2001 From: ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Fri, 29 Mar 2002 14:33:07 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@71 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/vote.c | 37 +++++++++++++++++-------------------- 1 file changed, 17 insertions(+), 20 deletions(-) diff --git a/pttbbs/mbbsd/vote.c b/pttbbs/mbbsd/vote.c index 8835a483..4e2df984 100644 --- a/pttbbs/mbbsd/vote.c +++ b/pttbbs/mbbsd/vote.c @@ -1,4 +1,4 @@ -/* $Id: vote.c,v 1.3 2002/03/29 13:45:28 ptt Exp $ */ +/* $Id: vote.c,v 1.4 2002/03/29 14:33:07 ptt Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -39,13 +39,13 @@ static char STR_bv_title[] = "vtitle"; static char STR_bv_results[] = "results"; -static char STR_new_control[] = "control0"; /* 投票日期 選項 */ -static char STR_new_desc[] = "desc0"; /* 投票目的 */ -static char STR_new_ballots[] = "ballots0"; -static char STR_new_flags[] = "flags0"; -static char STR_new_comments[] = "comments0"; /* 投票者的建意 */ -static char STR_new_limited[] = "limited0"; /* 私人投票 */ -static char STR_new_title[] = "vtitle0"; +static char STR_new_control[] = "control0\0"; /* 投票日期 選項 */ +static char STR_new_desc[] = "desc0\0"; /* 投票目的 */ +static char STR_new_ballots[] = "ballots0\0"; +static char STR_new_flags[] = "flags0\0"; +static char STR_new_comments[] = "comments0\0"; /* 投票者的建意 */ +static char STR_new_limited[] = "limited0\0"; /* 私人投票 */ +static char STR_new_title[] = "vtitle0\0"; int strip_ansi(char *buf, char *str, int mode) { register int ansi, count = 0; @@ -145,9 +145,6 @@ static void vote_report(char *bname, char *fname, char *fpath) { } close(fd); - log_usies("TESTfn", fname); - log_usies("TESTfp", fpath); - unlink(fpath); link(fname, fpath); @@ -536,11 +533,11 @@ static int vote_view_all(char *bname) { getdata(b_lines - 1, 0, buf, genbuf, 4, LCECHO); - if(genbuf[0] < '0' || genbuf[0] > '8') - genbuf[0] = '0'+x; + if(atoi(genbuf) < 0 || atoi(genbuf) > 20) + sprintf(genbuf,"%d",x); if(genbuf[0] != '0') - sprintf(STR_new_control, "%s%c", STR_bv_control, genbuf[0]); + sprintf(STR_new_control, "%s%d", STR_bv_control, atoi(genbuf)); else strcpy(STR_new_control, STR_bv_control); @@ -548,7 +545,7 @@ static int vote_view_all(char *bname) { if((fp=fopen(buf,"r"))) { fclose(fp); - return vote_view(bname, genbuf[0] - '0'); + return vote_view(bname, atoi(genbuf)); } else return FULLUPDATE; @@ -619,7 +616,7 @@ static int vote_maintain(char *bname) { outs(err_board_update); return FULLUPDATE; - } else if(genbuf[0] != 'm' || fhp->bvote > 10) + } else if(genbuf[0] != 'm' || fhp->bvote >= 20) return FULLUPDATE; } @@ -1028,11 +1025,11 @@ static int user_vote(char *bname) { getdata(b_lines - 1, 0, buf, genbuf, 4, LCECHO); - if(genbuf[0] < '0' || genbuf[0] > '8') - genbuf[0] = x + '0'; + if(atoi(genbuf) < 0 || atoi(genbuf) > 20) + sprintf(genbuf,"%d",x); if(genbuf[0] != '0') - sprintf(STR_new_control, "%s%c", STR_bv_control, genbuf[0]); + sprintf(STR_new_control, "%s%d", STR_bv_control, atoi(genbuf)); else strcpy(STR_new_control, STR_bv_control); @@ -1041,7 +1038,7 @@ static int user_vote(char *bname) { if((fp = fopen(buf, "r"))){ fclose(fp); - return user_vote_one(bname, genbuf[0] - '0'); + return user_vote_one(bname, atoi(genbuf)); } else return FULLUPDATE; } -- cgit v1.2.3 From 5a0d2d17990cf195c732a5a59dcfa625ee8abb85 Mon Sep 17 00:00:00 2001 From: ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Fri, 29 Mar 2002 16:22:53 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@72 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/cache.c | 49 +++++++++---------------------------------------- pttbbs/mbbsd/io.c | 13 +++++++------ pttbbs/mbbsd/mbbsd.c | 2 +- pttbbs/mbbsd/vote.c | 2 +- 4 files changed, 18 insertions(+), 48 deletions(-) diff --git a/pttbbs/mbbsd/cache.c b/pttbbs/mbbsd/cache.c index a0407437..64b6bffe 100644 --- a/pttbbs/mbbsd/cache.c +++ b/pttbbs/mbbsd/cache.c @@ -1,4 +1,4 @@ -/* $Id: cache.c,v 1.3 2002/03/19 16:02:23 ptt Exp $ */ +/* $Id: cache.c,v 1.4 2002/03/29 16:22:52 ptt Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -329,42 +329,6 @@ void setutmpmode(int mode) { } } #endif -/* -static int cmputmpuserid(userinfo_t ** i, userinfo_t ** j) { - return strcasecmp((*i)->userid, (*j)->userid); -} - -static int cmputmpmode(userinfo_t ** i, userinfo_t ** j) { - return (*i)->mode-(*j)->mode; -} - -static int cmputmpidle(userinfo_t ** i, userinfo_t ** j) { - return (*i)->lastact-(*j)->lastact; -} - -static int cmputmpfrom(userinfo_t ** i, userinfo_t ** j) { - return strcasecmp((*i)->from, (*j)->from); -} - -static int cmputmpfive(userinfo_t ** i, userinfo_t ** j) { - int type; - if((type=(*j)->five_win - (*i)->five_win)) - return type; - if((type=(*i)->five_lose - (*j)->five_lose)) - return type; - return (*i)->five_tie-(*j)->five_tie; -} -static int cmputmpsex(userinfo_t ** i, userinfo_t ** j) { - static int ladyfirst[]={1,0,1,0,1,0,3,3}; - return ladyfirst[(*i)->sex]-ladyfirst[(*j)->sex]; -} -static int cmputmppid(userinfo_t ** i, userinfo_t ** j) { - return (*i)->pid-(*j)->pid; -} -static int cmputmpuid(userinfo_t ** i, userinfo_t ** j) { - return (*i)->uid-(*j)->uid; -} -*/ static int cmputmpuserid(const void *i, const void *j){ return strcasecmp((*((userinfo_t**)i))->userid, (*((userinfo_t**)j))->userid); } @@ -390,9 +354,9 @@ static int cmputmpfive(const void *i, const void *j){ return (*((userinfo_t**)i))->five_tie-(*((userinfo_t**)j))->five_tie; } -static int cmputmpsex(const void *i, const void *j){ +static int cmputmpsex(userinfo_t ** i, userinfo_t ** j){ static int ladyfirst[]={1,0,1,0,1,0,3,3}; - return ladyfirst[(*((userinfo_t**)i))->sex]-ladyfirst[(*((userinfo_t**)j))->sex]; + return ladyfirst[(*i)->sex&07]-ladyfirst[(*j)->sex&07]; } static int cmputmppid(const void *i, const void *j){ return (*((userinfo_t**)i))->pid-(*((userinfo_t**)j))->pid; @@ -414,10 +378,15 @@ void sort_utmp() for(uentp = &utmpshm->uinfo[0], count=0, i=0; i< USHM_SIZE; i++,uentp = &utmpshm->uinfo[i]) + { if(uentp->pid) { - utmpshm->sorted[ns][0][count++]= uentp; + if(uentp->sex<0 || uentp->sex>7) + memset(uentp, 0, sizeof(userinfo_t)); + else + utmpshm->sorted[ns][0][count++]= uentp; } + } utmpshm->number = count; qsort(utmpshm->sorted[ns][0],count,sizeof(userinfo_t*),cmputmpuserid); memcpy(utmpshm->sorted[ns][1],utmpshm->sorted[ns][0], diff --git a/pttbbs/mbbsd/io.c b/pttbbs/mbbsd/io.c index b0331074..4bfd80cc 100644 --- a/pttbbs/mbbsd/io.c +++ b/pttbbs/mbbsd/io.c @@ -1,4 +1,4 @@ -/* $Id: io.c,v 1.7 2002/03/16 15:11:09 ptt Exp $ */ +/* $Id: io.c,v 1.8 2002/03/29 16:22:53 ptt Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -184,11 +184,12 @@ static int dogetch() { return I_OTHERDATA; } - while((len = read(0, inbuf, IBUFSIZE)) <= 0) { - if(len == 0 || errno != EINTR) - abort_bbs(0); - /* raise(SIGHUP); */ - } + + while((len = read(0, inbuf, IBUFSIZE)) <= 0) { + if(len == 0 || errno != EINTR) + abort_bbs(0); + /* raise(SIGHUP); */ + } ibufsize = len; icurrchar = 0; } diff --git a/pttbbs/mbbsd/mbbsd.c b/pttbbs/mbbsd/mbbsd.c index c793b6bc..97c9dd0e 100644 --- a/pttbbs/mbbsd/mbbsd.c +++ b/pttbbs/mbbsd/mbbsd.c @@ -1,4 +1,4 @@ -/* $Id: mbbsd.c,v 1.16 2002/03/29 13:45:28 ptt Exp $ */ +/* $Id: mbbsd.c,v 1.17 2002/03/29 16:22:53 ptt Exp $ */ #include <stdio.h> #include <string.h> #include <stdlib.h> diff --git a/pttbbs/mbbsd/vote.c b/pttbbs/mbbsd/vote.c index 4e2df984..79176f7a 100644 --- a/pttbbs/mbbsd/vote.c +++ b/pttbbs/mbbsd/vote.c @@ -1,4 +1,4 @@ -/* $Id: vote.c,v 1.4 2002/03/29 14:33:07 ptt Exp $ */ +/* $Id: vote.c,v 1.5 2002/03/29 16:22:53 ptt Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> -- cgit v1.2.3 From 2f6a471e3963a8bd0d429210c2fc756db5eeb343 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Fri, 29 Mar 2002 17:50:23 +0000 Subject: :) git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@73 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/shmctl.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/pttbbs/util/shmctl.c b/pttbbs/util/shmctl.c index 5932fdf3..b8f4c5a6 100644 --- a/pttbbs/util/shmctl.c +++ b/pttbbs/util/shmctl.c @@ -31,6 +31,13 @@ int utmpfix(int argc, char **argv) sprintf(buf, "/proc/%d", utmpshm->uinfo[i].pid); if( stat(buf, &st) < 0 ) clean = "process not exist"; + else{ + sprintf(buf, "home/%c/%s", + utmpshm->uinfo[i].userid[0], + utmpshm->uinfo[i].userid); + if( stat(buf, &st) < 0 ) + clean = "user not exist"; + } } if( clean ){ @@ -38,6 +45,11 @@ int utmpfix(int argc, char **argv) i, clean, utmpshm->uinfo[i].userid); memset(&utmpshm->uinfo[i], 0, sizeof(userinfo_t)); } + else if ( utmpshm->uinfo[i].mind > 40 ){ + printf("mind fix: %06d, userid: %s, mind: %d\n", + i, utmpshm->uinfo[i].userid, utmpshm->uinfo[i].mind); + utmpshm->uinfo[i].mind %= 40; + } } utmpshm->busystate = 0; return 0; @@ -165,17 +177,18 @@ int utmpsort(int argc, char **argv) } /* end of ulistsort */ +#define TIMES 10 int utmpwatch(int argc, char **argv) { int i; while( 1 ){ - for( i = 0 ; i < 4 ; ++i ){ + for( i = 0 ; i < TIMES ; ++i ){ usleep(300); if( !utmpshm->busystate ) break; puts("busying..."); } - if( i == 4 ){ + if( i == TIMES ){ puts("reset!"); utmpshm->busystate = 0; } @@ -199,6 +212,7 @@ int main(int argc, char **argv) int i = 0; if( argc >= 2 ){ + chdir(BBSHOME); resolve_utmp(); resolve_boards(); //resolve_garbage(); -- cgit v1.2.3 From 56abb30ae5ebf763b86cf949fb063c9013aaba20 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Wed, 3 Apr 2002 17:41:12 +0000 Subject: hbfl move to brdshm git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@74 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/include/pttstruct.h | 6 ++++-- pttbbs/mbbsd/cache.c | 10 +++++----- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/pttbbs/include/pttstruct.h b/pttbbs/include/pttstruct.h index d2d5f59e..ea896dfd 100644 --- a/pttbbs/include/pttstruct.h +++ b/pttbbs/include/pttstruct.h @@ -1,4 +1,4 @@ -/* $Id: pttstruct.h,v 1.4 2002/03/19 16:03:23 ptt Exp $ */ +/* $Id: pttstruct.h,v 1.5 2002/04/03 17:41:10 in2 Exp $ */ #ifndef INCLUDE_STRUCT_H #define INCLUDE_STRUCT_H @@ -163,7 +163,6 @@ typedef struct uhash_t { int hash_head[1 << HASH_BITS]; int number; /* # of users total */ int loaded; /* .PASSWD has been loaded? */ - int hbfl[MAX_BOARD][MAX_FRIEND + 1]; } uhash_t; union xitem_t { @@ -240,11 +239,13 @@ typedef struct userinfo_t { unsigned short int five_win; unsigned short int five_lose; unsigned short int five_tie; + /* int myfavorite[FAVMAX]; char gfavorite[FAVGMAX][FAVGSLEN+1]; int ninGroup[FAVGMAX]; int nGroup; int ninRoot; + */ int mailalert; int sex; char color; @@ -293,6 +294,7 @@ typedef struct bcache_t { fileheader_t dircache[MAX_BOARD][DIRCACHESIZE]; int busystate_b[MAX_BOARD]; int total[MAX_BOARD]; + int hbfl[MAX_BOARD][MAX_FRIEND + 1]; time_t lastposttime[MAX_BOARD]; time_t uptime; time_t touchtime; diff --git a/pttbbs/mbbsd/cache.c b/pttbbs/mbbsd/cache.c index 64b6bffe..bd380f19 100644 --- a/pttbbs/mbbsd/cache.c +++ b/pttbbs/mbbsd/cache.c @@ -1,4 +1,4 @@ -/* $Id: cache.c,v 1.4 2002/03/29 16:22:52 ptt Exp $ */ +/* $Id: cache.c,v 1.5 2002/04/03 17:41:12 in2 Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -1004,17 +1004,17 @@ void hbflreload(int bid) fclose(fp); } hbfl[0] = time(NULL); - memcpy(uhash->hbfl[bid], hbfl, sizeof(hbfl)); + memcpy(brdshm->hbfl[bid], hbfl, sizeof(hbfl)); } int hbflcheck(int bid, int uid) { int i; - if( uhash->hbfl[bid][0] < login_start_time - HBFLexpire ) + if( brdshm->hbfl[bid][0] < login_start_time - HBFLexpire ) hbflreload(bid); - for( i = 1 ; uhash->hbfl[bid][i] != 0 && i <= MAX_FRIEND ; ++i ){ - if( uhash->hbfl[bid][i] == uid ) + for( i = 1 ; brdshm->hbfl[bid][i] != 0 && i <= MAX_FRIEND ; ++i ){ + if( brdshm->hbfl[bid][i] == uid ) return 0; } return 1; -- cgit v1.2.3 From a78396269c377d8c23ccf5499de8cfdd1239bd6a Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Wed, 3 Apr 2002 17:41:43 +0000 Subject: reformat, ipcrm git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@75 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/bbsctl.c | 111 +++++++++++++++++++++++++++++++-------------------- 1 file changed, 68 insertions(+), 43 deletions(-) diff --git a/pttbbs/util/bbsctl.c b/pttbbs/util/bbsctl.c index 1020f7d2..b6a6388f 100644 --- a/pttbbs/util/bbsctl.c +++ b/pttbbs/util/bbsctl.c @@ -12,6 +12,9 @@ #define SU "/usr/bin/su" #define CP "/bin/cp" #define KILLALL "/usr/bin/killall" + #define IPCS "/usr/bin/ipcs" + #define IPCRM "/usr/bin/ipcrm" + #define AWK "/usr/bin/awk" #endif #ifdef Linux #include <linux/limits.h> @@ -20,17 +23,6 @@ #define KILLALL "/usr/bin/killall" #endif -void usage(void) -{ - printf("usage: bbsctl [start|stop|restart|bbsadm|test]\n" - " bbsctl start start mbbsd at 23,3000-3010\n" - " bbsctl stop killall listening mbbsd\n" - " bbsctl restart stop + start\n" - " bbsctl bbsadm su to bbsadm\n" - " bbsctl test use bbsadm permission to exec ./mbbsd 9000\n"); - exit(0); -} - int HaveBBSADM(void) { gid_t gids[NGROUPS_MAX]; @@ -54,7 +46,7 @@ int HaveBBSADM(void) return 1; } -void startbbs(void) +int startbbs(int argc, char **argv) { if( setuid(0) < 0 ){ perror("setuid(0)"); @@ -72,9 +64,10 @@ void startbbs(void) puts("starting mbbsd:3008"); system("/home/bbs/bin/mbbsd 3008"); puts("starting mbbsd:3009"); system("/home/bbs/bin/mbbsd 3009"); puts("starting mbbsd:3010"); system("/home/bbs/bin/mbbsd 3010"); + return 0; } -void stopbbs(void) +int stopbbs(int argc, char **argv) { DIR *dirp; struct dirent *de; @@ -91,8 +84,9 @@ void stopbbs(void) if( (fp = fopen(buf, "r")) ){ if( fgets(buf, sizeof(buf), fp) != NULL ){ if( strstr(buf, "mbbsd") && strstr(buf, "listening") ){ - kill(atoi(de->d_name), 1); - printf("stopping mbbsd at pid %5d\n", atoi(de->d_name)); + kill(atoi(de->d_name), 9); + printf("stopping mbbsd at pid %5d\n", + atoi(de->d_name)); } } fclose(fp); @@ -101,70 +95,101 @@ void stopbbs(void) } closedir(dirp); + return 0; } -void restartbbs(void) +int restartbbs(int argc, char **argv) { - stopbbs(); + stopbbs(argc, argv); sleep(1); - startbbs(); + startbbs(argc, argv); + return 0; } -void bbsadm(void) +int bbsadm(int argc, char **argv) { if( setuid(0) < 0 ){ perror("setuid(0)"); - return; + return 1; } puts("permission granted"); execl(SU, "su", "bbsadm", NULL); + return 0; } -void bbstest(void) +int bbstest(int argc, char **argv) { if( access("mbbsd", 0) < 0 ){ perror("./mbbsd"); - return; + return 1; } system(CP " -f mbbsd testmbbsd"); if( setuid(0) < 0 ){ perror("setuid(0)"); - return; + return 1; } if( setuid(9999) < 0 ){ perror("setuid(9999)"); - return; + return 1; } system(KILLALL " testmbbsd"); execl("./testmbbsd", "testmbbsd", "9000", NULL); perror("execl()"); + return 0; +} + +int Xipcrm(int argc, char **argv) +{ + char buf[256], cmd[256]; + FILE *fp; + sprintf(buf, IPCS " | " AWK " '{print $1 $2}'"); + if( !(fp = popen(buf, "r")) ){ + perror(buf); + return 1; + } + while( fgets(buf, sizeof(buf), fp) != NULL ){ + if( buf[0] == 't' || buf[0] == 'm' || buf[0] == 's' ){ + buf[strlen(buf) - 1] = 0; + sprintf(cmd, IPCRM " -%c %s\n", buf[0], &buf[1]); + system(cmd); + } + } + pclose(fp); + system(IPCS); + return 0; } struct { - char *cmd; - void (*func)(); -}cmds[] = { {"start", startbbs}, - {"stop", stopbbs}, - {"restart", restartbbs}, - {"bbsadm", bbsadm}, - {"test", bbstest}, - {NULL, NULL} }; + int (*func)(int, char **); + char *cmd, *descript; +} cmds[] = + { {startbbs, "start", "start mbbsd at port 23, 3000~3010"}, + {stopbbs, "stop", "killall listening mbbsd"}, + {restartbbs, "restart", "stop and then start"}, + {bbsadm, "bbsadm", "switch to user: bbsadm"}, + {bbstest, "test", "run ./mbbsd as bbsadm"}, + {Xipcrm, "ipcrm", "ipcrm all msg, shm, sem"}, + {NULL, NULL, NULL} }; int main(int argc, char **argv) { - int i; - if( argc == 1 ) - usage(); + int i = 0; if( !HaveBBSADM() ) return 1; - for( i = 0 ; cmds[i].cmd != NULL ; ++i ) - if( strcmp(cmds[i].cmd, argv[1]) == 0 ){ - cmds[i].func(); - break; - } - if( cmds[i].cmd == NULL ){ - printf("command %s not found\n", argv[1]); - usage(); + if( argc >= 2 ){ + chdir(BBSHOME); + for( i = 0 ; cmds[i].func != NULL ; ++i ) + if( strcmp(cmds[i].cmd, argv[1]) == 0 ){ + cmds[i].func(argc - 2, &argv[2]); + break; + } + } + if( argc == 1 || cmds[i].func == NULL ){ + /* usage */ + printf("usage: bbsctl [command] [options]\n"); + printf("commands:\n"); + for( i = 0 ; cmds[i].func != NULL ; ++i ) + printf("\t%-15s%s\n", cmds[i].cmd, cmds[i].descript); } return 0; } -- cgit v1.2.3 From fc9c8500c392bf956b57a8793de0e46409252043 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Wed, 3 Apr 2002 18:35:47 +0000 Subject: add installbbsctl git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@76 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/Makefile | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/pttbbs/util/Makefile b/pttbbs/util/Makefile index c1cbf06c..fb606b99 100644 --- a/pttbbs/util/Makefile +++ b/pttbbs/util/Makefile @@ -1,4 +1,4 @@ -# $Id: Makefile,v 1.6 2002/03/24 16:27:09 in2 Exp $ +# $Id: Makefile,v 1.7 2002/04/03 18:35:47 in2 Exp $ BBSHOME?=$(HOME) OSTYPE?=linux @@ -163,5 +163,11 @@ install: $(PROGS) mv $(BBSHOME)/bin/bbsmail $(BBSHOME)/bin/realbbsmail ln -s $(BBSHOME)/bin/filtermail.pl $(BBSHOME)/bin/bbsmail +installbbsctl: bbsctl + rm -f /home/bbs/bin/bbsctl + cp /home/bbs/pttbbs/util/bbsctl /home/bbs/bin/bbsctl + chown root /home/bbs/bin/bbsctl + chmod 4755 /home/bbs/bin/bbsctl + clean: rm -f *.o $(CPROGS) -- cgit v1.2.3 From 316f33c3fafa1e880ae61d95ca4ace2b524e67e4 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Thu, 4 Apr 2002 13:10:27 +0000 Subject: getbackup.pl git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@77 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/Makefile | 4 ++-- pttbbs/util/getbackup.pl | 31 +++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 2 deletions(-) create mode 100644 pttbbs/util/getbackup.pl diff --git a/pttbbs/util/Makefile b/pttbbs/util/Makefile index fb606b99..a3dd02ac 100644 --- a/pttbbs/util/Makefile +++ b/pttbbs/util/Makefile @@ -1,4 +1,4 @@ -# $Id: Makefile,v 1.7 2002/04/03 18:35:47 in2 Exp $ +# $Id: Makefile,v 1.8 2002/04/04 13:10:27 in2 Exp $ BBSHOME?=$(HOME) OSTYPE?=linux @@ -35,7 +35,7 @@ CPROGS= bbsmail BM_money post account birth deluserfile expire mandex\ PROGS= $(CPROGS) BM_money.sh backpasswd.sh mailog.sh opendice.sh\ openticket.sh stock.sh topsong.sh weather.sh stock.perl weather.perl\ toplazyBM.sh toplazyBBM.sh dailybackup.pl tarqueue.pl waterball.pl \ - filtermail.pl + filtermail.pl getbackup.pl all: $(PROGS) diff --git a/pttbbs/util/getbackup.pl b/pttbbs/util/getbackup.pl new file mode 100644 index 00000000..5e566066 --- /dev/null +++ b/pttbbs/util/getbackup.pl @@ -0,0 +1,31 @@ +#!/usr/bin/perl +if( !@ARGV ){ + print "usage:\tgetbackup.pl\tbrd BRDNAME\n"; + print "\t\t\tman BRDNAME\n"; + print "\t\t\tusr USERID [all|fav|frlist]\n"; +} + +chdir "/home/bbs/backup/"; + +$prefix = substr($ARGV[1], 0, 1); +if( $ARGV[0] eq 'usr' ){ + `rm -Rf home`; + `tar zxvf home.$prefix.tgz home/$prefix/$ARGV[1]`; + if( $ARGV[2] ne 'all' && $ARGV[2] ne 'fav' && $ARGV[2] ne 'frlist' ){ + print "usr command '$ARGV[2]' unknown\n"; + exit; + } + if( $ARGV[2] eq 'all' ){ + `rm -Rf /home/bbs/home/$prefix/$ARGV[1]`; + `mv home/$prefix/$ARGV[1] /home/bbs/home/$prefix/$ARGV[1]`; + } + elsif( $ARGV[2] eq 'fav' ){ + `mv home/$prefix/$ARGV[1]/.fav /home/bbs/home/$prefix/$ARGV[1]/.fav`; + } + elsif( $ARGV[2] eq 'frlist' ){ + `mv home/$prefix/$ARGV[1]/overrides /home/bbs/home/$prefix/$ARGV[1]/overrides`; + } +} +elsif( $ARGV[0] eq 'man' ){ +} + -- cgit v1.2.3 From 0560d0c6480bb0cbdf21ebf2a87019880c1edcff Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Thu, 4 Apr 2002 13:11:52 +0000 Subject: backup .BRD, too git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@78 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/backpasswd.sh | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/pttbbs/util/backpasswd.sh b/pttbbs/util/backpasswd.sh index 5ec11abd..1cc11337 100644 --- a/pttbbs/util/backpasswd.sh +++ b/pttbbs/util/backpasswd.sh @@ -1,5 +1,5 @@ #!/bin/sh -# $Id: backpasswd.sh,v 1.1 2002/03/07 15:13:45 in2 Exp $ +# $Id: backpasswd.sh,v 1.2 2002/04/04 13:11:52 in2 Exp $ mv PASSWDS.NEW5 PASSWDS.NEW6 mv PASSWDS.NEW4 PASSWDS.NEW5 @@ -9,3 +9,11 @@ mv PASSWDS.NEW1 PASSWDS.NEW2 mv PASSWDS.NEW PASSWDS.NEW1 cp .PASSWDS PASSWDS.NEW +mv backup/BRD.NEW5 backup/BRD.NEW6 +mv backup/BRD.NEW4 backup/BRD.NEW5 +mv backup/BRD.NEW3 backup/BRD.NEW4 +mv backup/BRD.NEW2 backup/BRD.NEW3 +mv backup/BRD.NEW1 backup/BRD.NEW2 +mv backup/BRD.NEW backup/BRD.NEW1 +cp .BRD backup/BRD.NEW + -- cgit v1.2.3 From 6311cd1a24a47c4d59de5ed05bac72354affa80b Mon Sep 17 00:00:00 2001 From: ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Thu, 4 Apr 2002 18:02:31 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@79 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/include/pttstruct.h | 7 ++++--- pttbbs/mbbsd/cache.c | 14 +++++++------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/pttbbs/include/pttstruct.h b/pttbbs/include/pttstruct.h index ea896dfd..1b1dc44e 100644 --- a/pttbbs/include/pttstruct.h +++ b/pttbbs/include/pttstruct.h @@ -1,4 +1,4 @@ -/* $Id: pttstruct.h,v 1.5 2002/04/03 17:41:10 in2 Exp $ */ +/* $Id: pttstruct.h,v 1.6 2002/04/04 18:02:24 ptt Exp $ */ #ifndef INCLUDE_STRUCT_H #define INCLUDE_STRUCT_H @@ -226,7 +226,8 @@ typedef struct userinfo_t { int friend_online[MAX_FRIEND]; /* point到線上好友 utmpshm的位置 */ /* 好友比較的cache 前兩個bit是狀態 */ int reject[MAX_REJECT]; - int pad[3]; + int pad[2]; + int lock; int friendtotal; /* 好友比較的cache 大小 */ unsigned char msgcount; msgque_t msgs[MAX_MSGS]; @@ -292,7 +293,7 @@ typedef struct bcache_t { boardheader_t bcache[MAX_BOARD]; boardheader_t *sorted[2][MAX_BOARD]; /* 0: by name 1: by class */ fileheader_t dircache[MAX_BOARD][DIRCACHESIZE]; - int busystate_b[MAX_BOARD]; + time_t busystate_b[MAX_BOARD]; int total[MAX_BOARD]; int hbfl[MAX_BOARD][MAX_FRIEND + 1]; time_t lastposttime[MAX_BOARD]; diff --git a/pttbbs/mbbsd/cache.c b/pttbbs/mbbsd/cache.c index bd380f19..374385e3 100644 --- a/pttbbs/mbbsd/cache.c +++ b/pttbbs/mbbsd/cache.c @@ -1,4 +1,4 @@ -/* $Id: cache.c,v 1.5 2002/04/03 17:41:12 in2 Exp $ */ +/* $Id: cache.c,v 1.6 2002/04/04 18:02:31 ptt Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -565,12 +565,12 @@ void load_fileheader_cache(int bid, char *direct) { int num=getbtotal(bid); int n = num-DIRCACHESIZE+1; - if (brdshm->busystate!=1) + if (brdshm->busystate!=1 && brdshm->busystate_b[bid-1]!=1) { - brdshm->busystate = 1; + brdshm->busystate_b[bid-1] = 1; get_records(direct, brdshm->dircache[bid - 1] , sizeof(fileheader_t),n<1?1:n, DIRCACHESIZE); - brdshm->busystate = 0; + brdshm->busystate_b[bid-1] = 0; } else {safe_sleep(1);} @@ -679,10 +679,10 @@ void reset_board(int bid) { /* Ptt: if(--bid < 0) return; - if(brdshm->busystate) { + if(brdshm->busystate || brdshm->busystate_b[bid-1]) { safe_sleep(1); } else { - brdshm->busystate = 1; + brdshm->busystate_b[bid-1] = 1; bhdr = bcache; bhdr += bid; if((fd = open(fn_board, O_RDONLY)) > 0) { @@ -696,7 +696,7 @@ void reset_board(int bid) { /* Ptt: bcache[i].firstchild[0]=NULL; bcache[i].firstchild[1]=NULL; } - brdshm->busystate = 0; + brdshm->busystate_b[bid-1] = 0; } } -- cgit v1.2.3 From 57eb0c2dd56fe9e5ac0d6159e1f77390312fd613 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Fri, 5 Apr 2002 13:38:01 +0000 Subject: add utmpnum for snmpd git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@80 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/shmctl.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/pttbbs/util/shmctl.c b/pttbbs/util/shmctl.c index b8f4c5a6..9c458e7d 100644 --- a/pttbbs/util/shmctl.c +++ b/pttbbs/util/shmctl.c @@ -196,6 +196,12 @@ int utmpwatch(int argc, char **argv) return 0; } +int utmpnum(int argc, char **argv) +{ + printf("%d.0\n", utmpshm->number); + return 0; +} + struct { int (*func)(int, char **); char *cmd, *descript; @@ -205,6 +211,7 @@ struct { {utmpreset, "utmpreset", "utmpshm->busystate=0"}, {utmpsort, "utmpsort", "sort ulist"}, {utmpwatch, "utmpwatch", "to see if busystate is always 1 then fix it"}, + {utmpnum, "utmpnum", "print utmpshm->number for snmpd"}, {NULL, NULL, NULL} }; int main(int argc, char **argv) @@ -219,8 +226,7 @@ int main(int argc, char **argv) resolve_fcache(); for( i = 0 ; cmd[i].func != NULL ; ++i ) if( strcmp(cmd[i].cmd, argv[1]) == 0 ){ - cmd[i].func(argc - 2, &argv[2]); - break; + return cmd[i].func(argc - 2, &argv[2]); } } if( argc == 1 || cmd[i].func == NULL ){ -- cgit v1.2.3 From db196f0c145bf42c8e4ca37a169d500cb8f7234c Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Fri, 5 Apr 2002 13:39:05 +0000 Subject: add brd/man git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@81 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/getbackup.pl | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/pttbbs/util/getbackup.pl b/pttbbs/util/getbackup.pl index 5e566066..29e2c20a 100644 --- a/pttbbs/util/getbackup.pl +++ b/pttbbs/util/getbackup.pl @@ -26,6 +26,13 @@ if( $ARGV[0] eq 'usr' ){ `mv home/$prefix/$ARGV[1]/overrides /home/bbs/home/$prefix/$ARGV[1]/overrides`; } } +elsif( $ARGV[0] eq 'brd' ){ + chdir '/home/bbs'; + `mv boards/$prefix/$ARGV[1] boards.error/$ARGV[1]`; + `tar zxvf backup/board.$prefix.tgz boards/$prefix/$ARGV[1]`; +} elsif( $ARGV[0] eq 'man' ){ + chdir '/home/bbs'; + `mv man/boards/$prefix/$ARGV[1] boards.error/man.$ARGV[1]`; + `tar zxvf backup/man.$prefix.tgz man/boards/$prefix/$ARGV[1]`; } - -- cgit v1.2.3 From dcb7a60d987d6c386bad4de2837de53039ebd1db Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Fri, 5 Apr 2002 14:36:25 +0000 Subject: .BOARDS => .BRD git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@82 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/initbbs.c | 4 ++-- pttbbs/util/inndBM.c | 4 ++-- pttbbs/util/poststat.c | 6 +++--- pttbbs/util/showboard.c | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/pttbbs/util/initbbs.c b/pttbbs/util/initbbs.c index c70ab826..deab2c8b 100644 --- a/pttbbs/util/initbbs.c +++ b/pttbbs/util/initbbs.c @@ -1,4 +1,4 @@ -/* $Id: initbbs.c,v 1.2 2002/03/09 17:29:20 in2 Exp $ */ +/* $Id: initbbs.c,v 1.3 2002/04/05 14:36:25 in2 Exp $ */ #include <stdio.h> #include <string.h> #include <stdlib.h> @@ -58,7 +58,7 @@ static void newboard(FILE *fp, boardheader_t *b) { } static void initBoards() { - FILE *fp = fopen(".BOARDS", "w"); + FILE *fp = fopen(".BRD", "w"); boardheader_t b; if(fp) { diff --git a/pttbbs/util/inndBM.c b/pttbbs/util/inndBM.c index 4f85bfd4..87b4d007 100644 --- a/pttbbs/util/inndBM.c +++ b/pttbbs/util/inndBM.c @@ -181,7 +181,7 @@ int main() strncpy(bcache[i].title + 5, "●", 2); brdshm->busystate = 0; - substitute_record(BBSHOME"/.BOARDS", &bcache[i],sizeof(boardheader_t),i+1); + substitute_record(BBSHOME"/.BRD", &bcache[i],sizeof(boardheader_t),i+1); } else if(!(bcache[i].brdattr & BRD_NOTRAN) && !istran[i]) { @@ -190,7 +190,7 @@ int main() bcache[i].brdattr = bcache[i].brdattr | BRD_NOTRAN; strncpy(bcache[i].title + 5, "◎", 2); brdshm->busystate = 0; - substitute_record(BBSHOME"/.BOARDS", &bcache[i],sizeof(boardheader_t),i+1); + substitute_record(BBSHOME"/.BRD", &bcache[i],sizeof(boardheader_t),i+1); } } diff --git a/pttbbs/util/poststat.c b/pttbbs/util/poststat.c index 3aa3cc94..2577f770 100644 --- a/pttbbs/util/poststat.c +++ b/pttbbs/util/poststat.c @@ -1,4 +1,4 @@ -/* $Id: poststat.c,v 1.1 2002/03/07 15:13:46 in2 Exp $ */ +/* $Id: poststat.c,v 1.2 2002/04/05 14:36:25 in2 Exp $ */ /* 統計今日、週、月、年熱門話題 */ #include <stdio.h> @@ -146,7 +146,7 @@ resolve_boards() brdshm->busystate = 1; - if ((fd = open(".BOARDS", O_RDONLY)) > 0) + if ((fd = open(".BRD", O_RDONLY)) > 0) { brdshm->number = read(fd, bcache, MAX_BOARD * sizeof(boardheader_t)) / sizeof(boardheader_t); @@ -329,7 +329,7 @@ filter(board) int bid; bid = getbnum(board); - if (get_record(".BOARDS", &bh, sizeof(bh), bid) == -1) + if (get_record(".BRD", &bh, sizeof(bh), bid) == -1) return 1; if (bh.brdattr & BRD_NOCOUNT) return 1; diff --git a/pttbbs/util/showboard.c b/pttbbs/util/showboard.c index 3801dbb1..91593b12 100644 --- a/pttbbs/util/showboard.c +++ b/pttbbs/util/showboard.c @@ -1,4 +1,4 @@ -/* $Id: showboard.c,v 1.1 2002/03/07 15:13:46 in2 Exp $ */ +/* $Id: showboard.c,v 1.2 2002/04/05 14:36:25 in2 Exp $ */ /* 看板一覽表(sorted) */ #include <stdio.h> @@ -28,7 +28,7 @@ int main(argc, argv) if (argc < 2) { - printf("Usage:\t%s .BOARDS [MAXUSERS]\n", argv[0]); + printf("Usage:\t%s .BRD [MAXUSERS]\n", argv[0]); exit(1); } -- cgit v1.2.3 From e2383522cd3e59e9aa61261b55f01a5002bcd5f7 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Fri, 5 Apr 2002 14:36:44 +0000 Subject: fix shmctl's dependency git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@83 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pttbbs/util/Makefile b/pttbbs/util/Makefile index a3dd02ac..443ac6eb 100644 --- a/pttbbs/util/Makefile +++ b/pttbbs/util/Makefile @@ -1,4 +1,4 @@ -# $Id: Makefile,v 1.8 2002/04/04 13:10:27 in2 Exp $ +# $Id: Makefile,v 1.9 2002/04/05 14:36:44 in2 Exp $ BBSHOME?=$(HOME) OSTYPE?=linux @@ -153,7 +153,7 @@ merge_board : merge_board.c bbsctl: bbsctl.c $(CC) $(CFLAGS) -o $@ $@.c -shmctl: shmctl.c +shmctl: shmctl.c $(OBJS) $(CC) $(CFLAGS) -o $@ $@.c $(OBJS) install: $(PROGS) -- cgit v1.2.3 From 76feac7e050843a19f7568bb4c4a23b757435707 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Fri, 5 Apr 2002 18:49:35 +0000 Subject: SYSOP/BM could export board-friend list git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@84 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/friend.c | 41 +++++++++++++++++++++++++---------------- 1 file changed, 25 insertions(+), 16 deletions(-) diff --git a/pttbbs/mbbsd/friend.c b/pttbbs/mbbsd/friend.c index a51d3000..d87c4bc9 100644 --- a/pttbbs/mbbsd/friend.c +++ b/pttbbs/mbbsd/friend.c @@ -1,4 +1,4 @@ -/* $Id: friend.c,v 1.2 2002/03/09 10:34:58 in2 Exp $ */ +/* $Id: friend.c,v 1.3 2002/04/05 18:49:35 in2 Exp $ */ #include <stdio.h> #include <string.h> #include <stdlib.h> @@ -10,7 +10,10 @@ #include "common.h" #include "perm.h" #include "proto.h" +#include "modes.h" +extern userec_t cuser; +extern int currmode; extern char currboard[]; /* name of currently selected board */ extern char *fn_overrides; extern userinfo_t *currutmp; @@ -178,30 +181,36 @@ static void friend_append(int type, int count) { move(2, 0); clrtobot(); outs("要引入哪一個名單?\n"); - for (i = 0, j = 0; i <= 7; i++) - { - if (i == type) - continue; - j++; - if (i <= 4) - sprintf(buf, " (%d) %-s\n", j, friend_list[(int) i]); - else - sprintf(buf, " (%d) %s 版的 %s\n", j, currboard, - friend_list[(int) i]); - outs(buf); - } + for (j = i = 0; i <= 4; i++) + if( i != type ){ + ++j; + sprintf(buf, " (%d) %-s\n", i + 1, friend_list[(int) i]); + outs(buf); + } + + if( HAVE_PERM(PERM_SYSOP) || currmode & MODE_BOARD ) + for( ; i < 8 ; ++i ) + if( i != type ){ + ++j; + sprintf(buf, " (%d) %s 版的 %s\n", j, currboard, + friend_list[(int) i]); + outs(buf); + } + outs(" (S) 選擇其他看板的特別名單"); getdata(11, 0, "請選擇 或 直接[Enter] 放棄:", buf, 3, LCECHO); if (!buf[0]) return; if (buf[0] == 's') Select(); + j = buf[0] - '1'; + if (j >= type) + j++; + if( !(HAVE_PERM(PERM_SYSOP) || currmode & MODE_BOARD) && j >= 4 ) + return; } while (buf[0] < '1' || buf[0] > '9'); - j = buf[0] - '1'; - if (j >= type) - j++; if (j == FRIEND_SPECIAL) friend_special(); -- cgit v1.2.3 From bda28ae10a99878c7444101daa2c22d234e59331 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Fri, 5 Apr 2002 18:49:47 +0000 Subject: register screen git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@85 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/user.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/pttbbs/mbbsd/user.c b/pttbbs/mbbsd/user.c index 814ffc4e..2e2e3401 100644 --- a/pttbbs/mbbsd/user.c +++ b/pttbbs/mbbsd/user.c @@ -1,4 +1,4 @@ -/* $Id: user.c,v 1.12 2002/03/20 05:31:54 in2 Exp $ */ +/* $Id: user.c,v 1.13 2002/04/05 18:49:47 in2 Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -827,10 +827,15 @@ static void toregister(char *email, char *genbuf, char *phone, char *career, " 之後請到 (U)ser => (R)egister 輸入, 即可通過認證\n" "\n" " 2.您若沒有 E-Mail , 請輸入 x ,\n" - " 我們會由站長親自審核您的註冊資料\n"); + " 我們會由站長親自審核您的註冊資料\n" + "\n" + "**********************************************************\n" + "* 您應該會在完成後十分鐘內收到認證信函, 若過久未收到或認 *\n" + "* 證碼錯誤請麻煩重新填寫一次或改用手動認證 :) *\n" + "**********************************************************\n"); while( 1 ){ email[0] = 0; - getfield(10, "身分認證用", "E-Mail Address", email, 50); + getfield(15, "身分認證用", "E-Mail Address", email, 50); if( strcmp(email, "x") == 0 || strcmp(email, "X") == 0 || isvaildemail(email) ) break; @@ -985,8 +990,8 @@ int u_register(void) getfield(9, "包括寢室或門牌號碼", "目前住址", addr, 50); }while( !(addr[0]) || addr[0] > 0 || strlen(addr) < 15 ); do{ - getfield(11, "包括長途撥號區域碼", "連絡電話", phone, 20); - }while( !removespace(phone) || phone[0] != '0' || strlen(phone) < 8 ); + getfield(11, "包括長途撥號區域碼", "連絡電話", phone, 11); + }while( !removespace(phone) || phone[0] != '0' || strlen(phone) < 9 ); getfield(13, "只輸入數字 如:0912345678", "手機號碼", mobile, 20); while(1) { int len; -- cgit v1.2.3 From 680559021fe82bc7caa56de4144ba3c8dd7d1fea Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sat, 6 Apr 2002 01:39:04 +0000 Subject: shmctl shouldn't create shared memory itself git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@86 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/shmctl.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/pttbbs/util/shmctl.c b/pttbbs/util/shmctl.c index 9c458e7d..6a0ea764 100644 --- a/pttbbs/util/shmctl.c +++ b/pttbbs/util/shmctl.c @@ -6,6 +6,7 @@ #include <signal.h> #include <sys/types.h> #include <sys/stat.h> +#include <sys/shm.h> #include "config.h" #include "pttstruct.h" #include "util.h" @@ -219,6 +220,12 @@ int main(int argc, char **argv) int i = 0; if( argc >= 2 ){ + /* shmctl shouldn't create shm itself */ + int shmid = shmget(UHASH_KEY, sizeof(*utmpshm), 0); + if( shmid < 0 ){ + perror("attach utmpshm"); + return 1; + } chdir(BBSHOME); resolve_utmp(); resolve_boards(); -- cgit v1.2.3 From 2a8e47d1cef9842c13675c469b3dbd349466c8f9 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sat, 6 Apr 2002 03:50:33 +0000 Subject: fix bug git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@87 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/shmctl.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pttbbs/util/shmctl.c b/pttbbs/util/shmctl.c index 6a0ea764..13b97d14 100644 --- a/pttbbs/util/shmctl.c +++ b/pttbbs/util/shmctl.c @@ -10,6 +10,7 @@ #include "config.h" #include "pttstruct.h" #include "util.h" +#include <errno.h> extern struct utmpfile_t *utmpshm; @@ -221,8 +222,9 @@ int main(int argc, char **argv) if( argc >= 2 ){ /* shmctl shouldn't create shm itself */ - int shmid = shmget(UHASH_KEY, sizeof(*utmpshm), 0); + int shmid = shmget(UHASH_KEY, sizeof(uhash_t), 0); if( shmid < 0 ){ + printf("%d\n", errno); perror("attach utmpshm"); return 1; } -- cgit v1.2.3 From d990698b867809190f17791f6a8cb0aabf056579 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sat, 6 Apr 2002 08:23:19 +0000 Subject: fix bug git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@88 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/dailybackup.pl | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pttbbs/util/dailybackup.pl b/pttbbs/util/dailybackup.pl index 76943887..fdcbee93 100644 --- a/pttbbs/util/dailybackup.pl +++ b/pttbbs/util/dailybackup.pl @@ -32,13 +32,13 @@ foreach $orig ( <$BACKHOME/*new*> ){ } foreach( @{$baktable[$week]} ){ - docmd("$TAR zcf $BACKHOME/man.$_.new.tgz $MANROOT/$_*"); - docmd("$TAR zcf $BACKHOME/home.$_.new.tgz $HOMEROOT/$_/*"); - docmd("$TAR zcf $BACKHOME/board.$_.new.tgz $BOARDROOT/$_*"); + docmd("$TAR zcf $BACKHOME/man.$_.new.tgz $MANROOT/$_/*"); + docmd("$TAR zcfh $BACKHOME/home.$_.new.tgz $HOMEROOT/$_"); + docmd("$TAR zcf $BACKHOME/board.$_.new.tgz $BOARDROOT/$_/*"); } if( $week == 0 ){ - docmd("$TAR zcf $BACKHOME/general.new.tgz .act .crontab .note .polling .post bin cron etc innd note.ans note.dat out out.going pttbbs pttbbs.conf upgrade.sh usies ussong"); + docmd("$TAR zcf $BACKHOME/general.new.tgz .BRD .PASSWDS .act .note .polling .post .post.old adm bin cron etc innd log note.ans note.dat pttbbs register.log ussong"); } sub docmd -- cgit v1.2.3 From 0a8ef2122189a59cd71993b998c45924a613696c Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sat, 6 Apr 2002 08:32:34 +0000 Subject: backup .PASSWD to backup/ git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@89 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/backpasswd.sh | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/pttbbs/util/backpasswd.sh b/pttbbs/util/backpasswd.sh index 1cc11337..ed354d5f 100644 --- a/pttbbs/util/backpasswd.sh +++ b/pttbbs/util/backpasswd.sh @@ -1,5 +1,5 @@ #!/bin/sh -# $Id: backpasswd.sh,v 1.2 2002/04/04 13:11:52 in2 Exp $ +# $Id: backpasswd.sh,v 1.3 2002/04/06 08:32:34 in2 Exp $ mv PASSWDS.NEW5 PASSWDS.NEW6 mv PASSWDS.NEW4 PASSWDS.NEW5 @@ -9,6 +9,14 @@ mv PASSWDS.NEW1 PASSWDS.NEW2 mv PASSWDS.NEW PASSWDS.NEW1 cp .PASSWDS PASSWDS.NEW +mv backup/PASSWDS.NEW5 backup/PASSWDS.NEW6 +mv backup/PASSWDS.NEW4 backup/PASSWDS.NEW5 +mv backup/PASSWDS.NEW3 backup/PASSWDS.NEW4 +mv backup/PASSWDS.NEW2 backup/PASSWDS.NEW3 +mv backup/PASSWDS.NEW1 backup/PASSWDS.NEW2 +mv backup/PASSWDS.NEW backup/PASSWDS.NEW1 +cp .PASSWDS backup/PASSWDS.NEW + mv backup/BRD.NEW5 backup/BRD.NEW6 mv backup/BRD.NEW4 backup/BRD.NEW5 mv backup/BRD.NEW3 backup/BRD.NEW4 -- cgit v1.2.3 From a414fbce9177be1e3d233927f886c13621541dc9 Mon Sep 17 00:00:00 2001 From: ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Mon, 8 Apr 2002 14:44:45 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@90 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/mbbsd.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pttbbs/mbbsd/mbbsd.c b/pttbbs/mbbsd/mbbsd.c index 97c9dd0e..a9853781 100644 --- a/pttbbs/mbbsd/mbbsd.c +++ b/pttbbs/mbbsd/mbbsd.c @@ -1,4 +1,4 @@ -/* $Id: mbbsd.c,v 1.17 2002/03/29 16:22:53 ptt Exp $ */ +/* $Id: mbbsd.c,v 1.18 2002/04/08 14:44:45 ptt Exp $ */ #include <stdio.h> #include <string.h> #include <stdlib.h> @@ -526,7 +526,7 @@ multi_user_check () } else{ /* allow multiple guest user */ - if (search_ulistn(usernum, 100)!=NULL){ + if (search_ulistn(usernum, 300)!=NULL){ outs ("\n抱歉,目前已有太多 guest, 請稍後再試。\n"); pressanykey (); oflush (); -- cgit v1.2.3 From ae13d96558e207a417e024bc881d92f5d4e7e8d3 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Tue, 9 Apr 2002 18:58:59 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@91 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/getbackup.pl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pttbbs/util/getbackup.pl b/pttbbs/util/getbackup.pl index 29e2c20a..bfc5c08b 100644 --- a/pttbbs/util/getbackup.pl +++ b/pttbbs/util/getbackup.pl @@ -11,7 +11,7 @@ $prefix = substr($ARGV[1], 0, 1); if( $ARGV[0] eq 'usr' ){ `rm -Rf home`; `tar zxvf home.$prefix.tgz home/$prefix/$ARGV[1]`; - if( $ARGV[2] ne 'all' && $ARGV[2] ne 'fav' && $ARGV[2] ne 'frlist' ){ + if( $ARGV[2] ne 'all' && $ARGV[2] ne 'fav' && $ARGV[2] ne 'frlist' && $ARGV[2] ){ print "usr command '$ARGV[2]' unknown\n"; exit; } -- cgit v1.2.3 From d048df67a2c64223b331eef9bd7758030de2141c Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Tue, 9 Apr 2002 20:10:31 +0000 Subject: remove pickup_t:idle, clean of idle timeout to shmctl git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@92 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/talk.c | 14 +++++++++----- pttbbs/util/shmctl.c | 33 +++++++++++++++++---------------- 2 files changed, 26 insertions(+), 21 deletions(-) diff --git a/pttbbs/mbbsd/talk.c b/pttbbs/mbbsd/talk.c index c9b108c8..d2c6fb8a 100644 --- a/pttbbs/mbbsd/talk.c +++ b/pttbbs/mbbsd/talk.c @@ -1,4 +1,4 @@ -/* $Id: talk.c,v 1.18 2002/03/20 13:49:45 ptt Exp $ */ +/* $Id: talk.c,v 1.19 2002/04/09 20:10:31 in2 Exp $ */ #include <stdio.h> #include <string.h> #include <errno.h> @@ -69,7 +69,7 @@ typedef struct talkwin_t { typedef struct pickup_t { userinfo_t *ui; - time_t idle; + //time_t idle; int friend; } pickup_t; @@ -1525,7 +1525,7 @@ static int pickup_user_cmp(time_t now, int sortedway, int cmp_fri, pickup_t pklist[], int *bfriends_number, int *ifh_number, int *hfm_number,int *irh_number, char *keyword) { - int i, fri_stat, is_friend, count=0, diff; + int i, fri_stat, is_friend, count=0; userinfo_t *uentp; for (i=0;i<utmpshm->number;i++){ uentp = (utmpshm->sorted[utmpshm->currsorted][sortedway][i]); @@ -1544,10 +1544,12 @@ static int pickup_user_cmp(time_t now, int sortedway, int cmp_fri, if (ifh_number && fri_stat & IFH) (*ifh_number)++; if (hfm_number && fri_stat & HFM) (*hfm_number)++; if (irh_number && fri_stat & IRH) (*irh_number)++; +#if 0 #ifdef SHOW_IDLE_TIME diff = now - uentp->lastact; #ifdef DOTIMEOUT - /* prevent fault /dev mount from kicking out users */ + /* in2: timeout拿到 shmctl utmpfix去做, 一小時一次就夠了 */ + /* prevent fault /dev mount from kicking out users */ if ((diff > curr_idle_timeout + 10) && (diff < 60 * 60 * 24 * 5)){ if ((uentp->pid <= 0 || kill(uentp->pid, SIGHUP) == -1) && @@ -1557,6 +1559,7 @@ static int pickup_user_cmp(time_t now, int sortedway, int cmp_fri, } #endif pklist[count].idle = diff; +#endif #endif pklist[count].friend = fri_stat; pklist[count].ui = uentp; @@ -1721,7 +1724,8 @@ static void pickup_user(void) continue; } #ifdef SHOW_IDLE_TIME - diff = pklist[ch].idle; + diff = freshtime - pklist[ch].ui->lastact; + //diff = pklist[ch].idle; if (diff > 59990) diff = 59990; /* Doma: 以免一大串的發呆時間 */ if (diff > 0) sprintf(buf, "%3ld'%02ld", diff / 60, diff % 60); diff --git a/pttbbs/util/shmctl.c b/pttbbs/util/shmctl.c index 13b97d14..0d8a3589 100644 --- a/pttbbs/util/shmctl.c +++ b/pttbbs/util/shmctl.c @@ -5,7 +5,6 @@ #include <ctype.h> #include <signal.h> #include <sys/types.h> -#include <sys/stat.h> #include <sys/shm.h> #include "config.h" #include "pttstruct.h" @@ -17,29 +16,31 @@ extern struct utmpfile_t *utmpshm; int utmpfix(int argc, char **argv) { int i; + time_t now; char buf[1024], *clean; - struct stat st; - if( utmpshm->busystate ){ - puts("utmpshm is busy"); - return 0; - } + + time(&now); + for( i = 0 ; i < 5 ; ++i ) + if( !utmpshm->busystate ) + break; + else{ + puts("utmpshm is busy...."); + sleep(1); + } utmpshm->busystate = 1; for( i = 0 ; i < USHM_SIZE ; ++i ) if( utmpshm->uinfo[i].pid ){ clean = NULL; if( !isalpha(utmpshm->uinfo[i].userid[0]) ) clean = "userid error"; + else if( now - utmpshm->uinfo[i].lastact > 1800 ) + clean = "timeout"; else{ - sprintf(buf, "/proc/%d", utmpshm->uinfo[i].pid); - if( stat(buf, &st) < 0 ) - clean = "process not exist"; - else{ - sprintf(buf, "home/%c/%s", - utmpshm->uinfo[i].userid[0], - utmpshm->uinfo[i].userid); - if( stat(buf, &st) < 0 ) - clean = "user not exist"; - } + sprintf(buf, "home/%c/%s", + utmpshm->uinfo[i].userid[0], + utmpshm->uinfo[i].userid); + if( access(buf, 0) < 0 ) + clean = "user not exist"; } if( clean ){ -- cgit v1.2.3 From 2d8ce430f26c3be43238ecd7bc855621e5fe39f0 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Tue, 9 Apr 2002 20:31:50 +0000 Subject: fix logout_friend() git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@93 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/cache.c | 4 ++-- pttbbs/mbbsd/friend.c | 5 +++-- pttbbs/mbbsd/talk.c | 20 ++++++++++---------- 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/pttbbs/mbbsd/cache.c b/pttbbs/mbbsd/cache.c index 374385e3..ad71d35a 100644 --- a/pttbbs/mbbsd/cache.c +++ b/pttbbs/mbbsd/cache.c @@ -1,4 +1,4 @@ -/* $Id: cache.c,v 1.6 2002/04/04 18:02:31 ptt Exp $ */ +/* $Id: cache.c,v 1.7 2002/04/09 20:31:50 in2 Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -541,7 +541,7 @@ int count_logins(int uid, int show) { void purge_utmp(userinfo_t *uentp) { - logout_friend_online(); + logout_friend_online(uentp); memset(uentp, 0, sizeof(userinfo_t)); } diff --git a/pttbbs/mbbsd/friend.c b/pttbbs/mbbsd/friend.c index d87c4bc9..fef3fabc 100644 --- a/pttbbs/mbbsd/friend.c +++ b/pttbbs/mbbsd/friend.c @@ -1,4 +1,4 @@ -/* $Id: friend.c,v 1.3 2002/04/05 18:49:35 in2 Exp $ */ +/* $Id: friend.c,v 1.4 2002/04/09 20:31:50 in2 Exp $ */ #include <stdio.h> #include <string.h> #include <stdlib.h> @@ -319,7 +319,8 @@ void friend_load() { fclose(fp); } memcpy(currutmp->reject, myrejects, sizeof(myrejects)); - if(currutmp->friendtotal) logout_friend_online(); + if(currutmp->friendtotal) + logout_friend_online(currutmp); login_friend_online(); } diff --git a/pttbbs/mbbsd/talk.c b/pttbbs/mbbsd/talk.c index d2c6fb8a..1cd94a54 100644 --- a/pttbbs/mbbsd/talk.c +++ b/pttbbs/mbbsd/talk.c @@ -1,4 +1,4 @@ -/* $Id: talk.c,v 1.19 2002/04/09 20:10:31 in2 Exp $ */ +/* $Id: talk.c,v 1.20 2002/04/09 20:31:50 in2 Exp $ */ #include <stdio.h> #include <string.h> #include <errno.h> @@ -255,17 +255,17 @@ int login_friend_online(void) return 0; } -int logout_friend_online(void) +int logout_friend_online(userinfo_t *utmp) { int i, j, k; - int offset=(int) (currutmp - &utmpshm->uinfo[0]); + int offset=(int) (utmp - &utmpshm->uinfo[0]); userinfo_t *ui; - while(currutmp->friendtotal){ - i = currutmp->friendtotal-1; - j = (currutmp->friend_online[i] & 0xFFFFFF); - currutmp->friend_online[i]=0; + while(utmp->friendtotal){ + i = utmp->friendtotal-1; + j = (utmp->friend_online[i] & 0xFFFFFF); + utmp->friend_online[i]=0; ui = &utmpshm->uinfo[j]; - if(ui->pid && ui!=currutmp){ + if(ui->pid && ui!=utmp){ for(k=0; k<ui->friendtotal && (int)(ui->friend_online[k] & 0xFFFFFF) !=offset; k++); if(k<ui->friendtotal){ @@ -274,8 +274,8 @@ int logout_friend_online(void) ui->friend_online[ui->friendtotal]=0; } } - currutmp->friendtotal--; - currutmp->friend_online[currutmp->friendtotal]=0; + utmp->friendtotal--; + utmp->friend_online[utmp->friendtotal]=0; } return 0; } -- cgit v1.2.3 From ffea141eb01a5ca9c6cd312c5dcef371cb5bf766 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Tue, 9 Apr 2002 20:29:38 +0000 Subject: use logout_friend if timeout git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@94 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/shmctl.c | 38 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/pttbbs/util/shmctl.c b/pttbbs/util/shmctl.c index 0d8a3589..0205681f 100644 --- a/pttbbs/util/shmctl.c +++ b/pttbbs/util/shmctl.c @@ -6,13 +6,45 @@ #include <signal.h> #include <sys/types.h> #include <sys/shm.h> +#include <errno.h> #include "config.h" #include "pttstruct.h" #include "util.h" -#include <errno.h> +#include "proto.h" extern struct utmpfile_t *utmpshm; +int logout_friend_online(userinfo_t *utmp) +{ + int i, j, k; + int offset=(int) (utmp - &utmpshm->uinfo[0]); + userinfo_t *ui; + while(utmp->friendtotal){ + i = utmp->friendtotal-1; + j = (utmp->friend_online[i] & 0xFFFFFF); + utmp->friend_online[i]=0; + ui = &utmpshm->uinfo[j]; + if(ui->pid && ui!=utmp){ + for(k=0; k<ui->friendtotal && + (int)(ui->friend_online[k] & 0xFFFFFF) !=offset; k++); + if(k<ui->friendtotal){ + ui->friendtotal--; + ui->friend_online[k]=ui->friend_online[ui->friendtotal]; + ui->friend_online[ui->friendtotal]=0; + } + } + utmp->friendtotal--; + utmp->friend_online[utmp->friendtotal]=0; + } + return 0; +} + +void purge_utmp(userinfo_t *uentp) +{ + logout_friend_online(uentp); + //memset(uentp, 0, sizeof(userinfo_t)); +} + int utmpfix(int argc, char **argv) { int i; @@ -33,8 +65,10 @@ int utmpfix(int argc, char **argv) clean = NULL; if( !isalpha(utmpshm->uinfo[i].userid[0]) ) clean = "userid error"; - else if( now - utmpshm->uinfo[i].lastact > 1800 ) + else if( now - utmpshm->uinfo[i].lastact > 1800 ){ clean = "timeout"; + purge_utmp(&utmpshm->uinfo[i]); + } else{ sprintf(buf, "home/%c/%s", utmpshm->uinfo[i].userid[0], -- cgit v1.2.3 From 79258439e7afea3f2b81272485e142e0adfd9424 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Tue, 9 Apr 2002 20:33:52 +0000 Subject: no warning git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@95 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/cache.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/pttbbs/mbbsd/cache.c b/pttbbs/mbbsd/cache.c index ad71d35a..daef6628 100644 --- a/pttbbs/mbbsd/cache.c +++ b/pttbbs/mbbsd/cache.c @@ -1,4 +1,4 @@ -/* $Id: cache.c,v 1.7 2002/04/09 20:31:50 in2 Exp $ */ +/* $Id: cache.c,v 1.8 2002/04/09 20:33:52 in2 Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -354,9 +354,11 @@ static int cmputmpfive(const void *i, const void *j){ return (*((userinfo_t**)i))->five_tie-(*((userinfo_t**)j))->five_tie; } -static int cmputmpsex(userinfo_t ** i, userinfo_t ** j){ - static int ladyfirst[]={1,0,1,0,1,0,3,3}; - return ladyfirst[(*i)->sex&07]-ladyfirst[(*j)->sex&07]; +static int cmputmpsex(const void *i, const void *j) +{ + static int ladyfirst[]={1,0,1,0,1,0,3,3}; + return ladyfirst[(*(userinfo_t**)i)->sex&07]- + ladyfirst[(*(userinfo_t**)j)->sex&07]; } static int cmputmppid(const void *i, const void *j){ return (*((userinfo_t**)i))->pid-(*((userinfo_t**)j))->pid; -- cgit v1.2.3 From a1fdc6a4d94f49673ad9dc6b8b8d3887ae364412 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Wed, 10 Apr 2002 10:39:09 +0000 Subject: fix bug git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@96 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/shmctl.c | 1 + 1 file changed, 1 insertion(+) diff --git a/pttbbs/util/shmctl.c b/pttbbs/util/shmctl.c index 0205681f..1453126a 100644 --- a/pttbbs/util/shmctl.c +++ b/pttbbs/util/shmctl.c @@ -67,6 +67,7 @@ int utmpfix(int argc, char **argv) clean = "userid error"; else if( now - utmpshm->uinfo[i].lastact > 1800 ){ clean = "timeout"; + kill(utmpshm->uinfo[i].pid, SIGHUP); purge_utmp(&utmpshm->uinfo[i]); } else{ -- cgit v1.2.3 From 9a41781c4ae7e829db5899556bab2a8b125bfb55 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Wed, 10 Apr 2002 10:49:42 +0000 Subject: max idle 30'00 :P git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@97 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/talk.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pttbbs/mbbsd/talk.c b/pttbbs/mbbsd/talk.c index 1cd94a54..facab4b4 100644 --- a/pttbbs/mbbsd/talk.c +++ b/pttbbs/mbbsd/talk.c @@ -1,4 +1,4 @@ -/* $Id: talk.c,v 1.20 2002/04/09 20:31:50 in2 Exp $ */ +/* $Id: talk.c,v 1.21 2002/04/10 10:49:42 in2 Exp $ */ #include <stdio.h> #include <string.h> #include <errno.h> @@ -1726,7 +1726,8 @@ static void pickup_user(void) #ifdef SHOW_IDLE_TIME diff = freshtime - pklist[ch].ui->lastact; //diff = pklist[ch].idle; - if (diff > 59990) diff = 59990; /* Doma: 以免一大串的發呆時間 */ + if (diff > 1800) diff = 1800; /* Doma: 以免一大串的發呆時間 */ + /* in2: max 30'00 :P */ if (diff > 0) sprintf(buf, "%3ld'%02ld", diff / 60, diff % 60); else -- cgit v1.2.3 From 4e53b80c9f6a9a49993c67452af04036f9efa905 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Wed, 10 Apr 2002 10:51:24 +0000 Subject: mbbsd's serial -O only git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@98 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/Makefile | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/pttbbs/mbbsd/Makefile b/pttbbs/mbbsd/Makefile index 5919b885..4169ccb6 100644 --- a/pttbbs/mbbsd/Makefile +++ b/pttbbs/mbbsd/Makefile @@ -1,16 +1,16 @@ -# $Id: Makefile,v 1.4 2002/03/29 13:45:28 ptt Exp $ +# $Id: Makefile,v 1.5 2002/04/10 10:51:24 in2 Exp $ BBSHOME?=$(HOME) OSTYPE=FreeBSD # FreeBSD -CFLAGS_FreeBSD= -pipe -Wall -g -O3 -DHAVE_SETPROCTITLE -DBBSHOME='"$(BBSHOME)"' -DFreeBSD -I../include -LDFLAGS_FreeBSD=-pipe -Wall -g -O3 +CFLAGS_FreeBSD= -pipe -Wall -g -O -DHAVE_SETPROCTITLE -DBBSHOME='"$(BBSHOME)"' -DFreeBSD -I../include +LDFLAGS_FreeBSD=-pipe -Wall -g -O LIBS_FreeBSD= -lutil -lkvm # Linux -CFLAGS_linux= -pipe -Wall -g -O3 -DHAVE_DES_CRYPT -DBBSHOME='"$(BBSHOME)"' -DLinux -I../include -s -LDFLAGS_linux= -pipe -Wall -g -O3 +CFLAGS_linux= -pipe -Wall -g -O -DHAVE_DES_CRYPT -DBBSHOME='"$(BBSHOME)"' -DLinux -I../include -s +LDFLAGS_linux= -pipe -Wall -g -O LIBS_linux= -lcrypt CFLAGS= $(CFLAGS_$(OSTYPE)) @@ -46,6 +46,8 @@ test: $(PROG) install: $(PROG) install -d $(BBSHOME)/bin/ install -c -m 755 $(PROG) $(BBSHOME)/bin/ + mv $(BBSHOME)/bin/mbbsd $(BBSHOME)/bin/mbbsd.`date '+%m%d%H'` + ln -sv $(BBSHOME)/bin/mbbsd.`date '+%m%d%H'` $(BBSHOME)/bin/mbbsd clean: rm -f $(OBJS) $(PROG) -- cgit v1.2.3 From d4642bfded176bc794841b4c8694c322c22236ee Mon Sep 17 00:00:00 2001 From: ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Wed, 10 Apr 2002 14:06:07 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@99 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/mbbsd.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pttbbs/mbbsd/mbbsd.c b/pttbbs/mbbsd/mbbsd.c index a9853781..bc04b67c 100644 --- a/pttbbs/mbbsd/mbbsd.c +++ b/pttbbs/mbbsd/mbbsd.c @@ -1,4 +1,4 @@ -/* $Id: mbbsd.c,v 1.18 2002/04/08 14:44:45 ptt Exp $ */ +/* $Id: mbbsd.c,v 1.19 2002/04/10 14:06:07 ptt Exp $ */ #include <stdio.h> #include <string.h> #include <stdlib.h> @@ -526,8 +526,8 @@ multi_user_check () } else{ /* allow multiple guest user */ - if (search_ulistn(usernum, 300)!=NULL){ - outs ("\n抱歉,目前已有太多 guest, 請稍後再試。\n"); + if (search_ulistn(usernum, 100)!=NULL){ + outs ("\n抱歉,目前已有太多 guest 在站上, 請用new註冊。\n"); pressanykey (); oflush (); exit (1); -- cgit v1.2.3 From 2f4d16b1641d594d747c678dcba9fc8804024211 Mon Sep 17 00:00:00 2001 From: ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Fri, 12 Apr 2002 18:21:13 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@100 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/announce.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pttbbs/mbbsd/announce.c b/pttbbs/mbbsd/announce.c index 0cbce01e..314b3a41 100644 --- a/pttbbs/mbbsd/announce.c +++ b/pttbbs/mbbsd/announce.c @@ -1,4 +1,4 @@ -/* $Id: announce.c,v 1.2 2002/03/09 17:27:57 in2 Exp $ */ +/* $Id: announce.c,v 1.3 2002/04/12 18:21:13 ptt Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -1440,10 +1440,10 @@ int a_menu(char *maintitle, char *path, int lastlevel) { if(ans[0]=='y') { strcpy(trans_buffer,fname); Fexit = 1; - free(me.header); if(currstat == OSONG){ log_file(FN_USSONG,fhdr->title); } + free(me.header); return FULLUPDATE; } } -- cgit v1.2.3 From df7395cad2cb4808c47261c8eb0288f65d2204fa Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sun, 14 Apr 2002 10:16:54 +0000 Subject: + safty check + bbsrc git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@101 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/getbackup.pl | 44 +++++++++++++++++++++++++++++--------------- 1 file changed, 29 insertions(+), 15 deletions(-) diff --git a/pttbbs/util/getbackup.pl b/pttbbs/util/getbackup.pl index bfc5c08b..5714c87f 100644 --- a/pttbbs/util/getbackup.pl +++ b/pttbbs/util/getbackup.pl @@ -2,28 +2,42 @@ if( !@ARGV ){ print "usage:\tgetbackup.pl\tbrd BRDNAME\n"; print "\t\t\tman BRDNAME\n"; - print "\t\t\tusr USERID [all|fav|frlist]\n"; + print "\t\t\tusr USERID [all|fav|frlist|bbsrc]\n"; +} + +if( !-e '/home/bbs/backup/home.a.tgz' ){ + print "there's no /home/bbs/backup/home.a.tgz?\n"; + print "or no mount on /home/bbs/backup?\n"; + exit; } chdir "/home/bbs/backup/"; $prefix = substr($ARGV[1], 0, 1); if( $ARGV[0] eq 'usr' ){ + $userid = $ARGV[1]; `rm -Rf home`; - `tar zxvf home.$prefix.tgz home/$prefix/$ARGV[1]`; - if( $ARGV[2] ne 'all' && $ARGV[2] ne 'fav' && $ARGV[2] ne 'frlist' && $ARGV[2] ){ - print "usr command '$ARGV[2]' unknown\n"; - exit; - } - if( $ARGV[2] eq 'all' ){ - `rm -Rf /home/bbs/home/$prefix/$ARGV[1]`; - `mv home/$prefix/$ARGV[1] /home/bbs/home/$prefix/$ARGV[1]`; - } - elsif( $ARGV[2] eq 'fav' ){ - `mv home/$prefix/$ARGV[1]/.fav /home/bbs/home/$prefix/$ARGV[1]/.fav`; - } - elsif( $ARGV[2] eq 'frlist' ){ - `mv home/$prefix/$ARGV[1]/overrides /home/bbs/home/$prefix/$ARGV[1]/overrides`; + `tar zxvf home.$prefix.tgz home/$prefix/$userid`; + shift @ARGV; shift @ARGV; + foreach( @ARGV ){ + if( $_ ne 'all' && $_ ne 'fav' && $_ ne 'frlist' && + $_ ne 'bbsrc' && $_ ){ + print "usr command '$_' unknown\n"; + exit; + } + if( $_ eq 'all' ){ + `rm -Rf /home/bbs/home/$prefix/$userid`; + `mv home/$prefix/$userid /home/bbs/home/$prefix/$userid`; + } + elsif( $_ eq 'fav' ){ + `mv home/$prefix/$userid/.fav /home/bbs/home/$prefix/$userid/.fav`; + } + elsif( $_ eq 'frlist' ){ + `mv home/$prefix/$userid/overrides /home/bbs/home/$prefix/$userid/overrides`; + } + elsif( $_ eq 'bbsrc' ){ + `mv home/$prefix/$userid/.bbsrc /home/bbs/home/$prefix/$userid/.bbsrc`; + } } } elsif( $ARGV[0] eq 'brd' ){ -- cgit v1.2.3 From e7aac0a1e0cf0561e8a179336a76ba1c102d3546 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sun, 14 Apr 2002 14:08:56 +0000 Subject: kvm's killdeadbbs git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@102 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/Makefile | 7 ++++-- pttbbs/util/killdeadbbs.c | 56 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+), 2 deletions(-) create mode 100644 pttbbs/util/killdeadbbs.c diff --git a/pttbbs/util/Makefile b/pttbbs/util/Makefile index 443ac6eb..d1dd93e1 100644 --- a/pttbbs/util/Makefile +++ b/pttbbs/util/Makefile @@ -1,4 +1,4 @@ -# $Id: Makefile,v 1.9 2002/04/05 14:36:44 in2 Exp $ +# $Id: Makefile,v 1.10 2002/04/14 14:08:56 in2 Exp $ BBSHOME?=$(HOME) OSTYPE?=linux @@ -30,7 +30,7 @@ CPROGS= bbsmail BM_money post account birth deluserfile expire mandex\ poststat showboard antispam countalldice webgrep bbsrf\ initbbs outmail xchatd userlist tunepasswd buildir reaper shmsweep\ merge_passwd merge_board inndBM buildAnnounce rmuid \ - toplazyBM jungo toplazyBBM shmctl + toplazyBM jungo toplazyBBM shmctl killdeadbbs PROGS= $(CPROGS) BM_money.sh backpasswd.sh mailog.sh opendice.sh\ openticket.sh stock.sh topsong.sh weather.sh stock.perl weather.perl\ @@ -156,6 +156,9 @@ bbsctl: bbsctl.c shmctl: shmctl.c $(OBJS) $(CC) $(CFLAGS) -o $@ $@.c $(OBJS) +killdeadbbs: killdeadbbs.c + $(CC) $(CFLAGS) -lkvm -o $@ $@.c + install: $(PROGS) install -d $(BBSHOME)/bin/ install -c -m 755 $(PROGS) $(BBSHOME)/bin/ diff --git a/pttbbs/util/killdeadbbs.c b/pttbbs/util/killdeadbbs.c new file mode 100644 index 00000000..0c83fe29 --- /dev/null +++ b/pttbbs/util/killdeadbbs.c @@ -0,0 +1,56 @@ +#ifndef FreeBSD +int main(int argc, char **argv) +{ + puts("this program is only for FreeBSD"); +} +#else +#include <err.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> +#include <signal.h> +#include <kvm.h> +#include <fcntl.h> +#include <limits.h> +#include <sys/param.h> +#include <sys/sysctl.h> +#include <sys/user.h> +#include "config.h" // for BBSUID + +int main(int argc, char **argv) +{ + kvm_t *kd; + struct kinfo_proc *kp; + char errbuf[_POSIX2_LINE_MAX]; + int nentries, i, npids; + pid_t pids[8192]; + kd = kvm_openfiles("/dev/null", "/dev/null", NULL, O_RDONLY, errbuf); + if( kd == NULL ) + errx(1, "%s", errbuf); + + if ((kp = kvm_getprocs(kd, KERN_PROC_UID, BBSUID, &nentries)) == 0 || + nentries < 0) + errx(1, "%s", kvm_geterr(kd)); + + for( npids = 0, i = nentries ; --i >= 0 ; ++kp ){ + if( strncmp(kp->ki_comm, "mbbsd", 5) == 0 ){ + if( kp->ki_runtime > (60 * 1000000) ){ // 60 secs + kill(kp->ki_pid, 1); + pids[npids++] = kp->ki_pid; + printf("%d\n", kp->ki_pid); + } + } + } + + if( npids != 0 ){ + sleep(2); + while( --npids >= 0 ) + kill(pids[npids], 9); + } + + kvm_close(kd); + return 0; +} + +#endif -- cgit v1.2.3 From 351b3f2c656fcee2689a72c1cee25e35587952cb Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Mon, 15 Apr 2002 12:05:52 +0000 Subject: MDCACHE git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@103 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/include/proto.h | 4 +++- pttbbs/include/pttstruct.h | 5 ++++- pttbbs/mbbsd/cache.c | 46 ++++++++++++++++++++++++++++++++++++++++++++-- pttbbs/mbbsd/edit.c | 6 +++++- pttbbs/mbbsd/more.c | 21 ++++++++++++++++++--- 5 files changed, 74 insertions(+), 8 deletions(-) diff --git a/pttbbs/include/proto.h b/pttbbs/include/proto.h index 8604aab5..f5ceeb6e 100644 --- a/pttbbs/include/proto.h +++ b/pttbbs/include/proto.h @@ -1,4 +1,4 @@ -/* $Id: proto.h,v 1.4 2002/03/14 08:17:43 in2 Exp $ */ +/* $Id: proto.h,v 1.5 2002/04/15 12:05:49 in2 Exp $ */ #ifndef INCLUDE_PROTO_H #define INCLUDE_PROTO_H @@ -108,6 +108,8 @@ userinfo_t *search_ulist_pid(int pid); int moneyof(int uid); void hbflreload(int bid); int hbflcheck(int bid, int uid); +char *cachepath(const char *fpath); +int updatemdcache(const char *cpath, const char *fpath); /* cal */ int vice(int money, char* item); diff --git a/pttbbs/include/pttstruct.h b/pttbbs/include/pttstruct.h index 1b1dc44e..a88bafab 100644 --- a/pttbbs/include/pttstruct.h +++ b/pttbbs/include/pttstruct.h @@ -1,4 +1,4 @@ -/* $Id: pttstruct.h,v 1.6 2002/04/04 18:02:24 ptt Exp $ */ +/* $Id: pttstruct.h,v 1.7 2002/04/15 12:05:50 in2 Exp $ */ #ifndef INCLUDE_STRUCT_H #define INCLUDE_STRUCT_H @@ -333,6 +333,9 @@ struct pttcache_t { time_t uptime; time_t touchtime; int busystate; + + int GLOBE[10]; /* mbbsd間的 globe var + 用以做統計等資料 */ }; typedef struct fromcache_t { diff --git a/pttbbs/mbbsd/cache.c b/pttbbs/mbbsd/cache.c index daef6628..8fceef65 100644 --- a/pttbbs/mbbsd/cache.c +++ b/pttbbs/mbbsd/cache.c @@ -1,4 +1,4 @@ -/* $Id: cache.c,v 1.8 2002/04/09 20:33:52 in2 Exp $ */ +/* $Id: cache.c,v 1.9 2002/04/15 12:05:52 in2 Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -826,7 +826,8 @@ int haspostperm(char *bname) { /* cachefor 動態看版 */ struct pttcache_t *ptt; -static void reload_pttcache() { +static void reload_pttcache() +{ if(ptt->busystate) safe_sleep(1); else { /* jochang: temporary workaround */ @@ -895,11 +896,13 @@ static void reload_pttcache() { } } +int *GLOBE; void resolve_garbage() { int count=0; if(ptt == NULL) { ptt = attach_shm(PTTSHM_KEY, sizeof(*ptt)); + GLOBE = ptt->GLOBE; if(ptt->touchtime == 0) ptt->touchtime = 1; } @@ -1021,3 +1024,42 @@ int hbflcheck(int bid, int uid) } return 1; } + +#ifdef MDCACHE +char *cachepath(const char *fpath) +{ + static char cpath[128]; + char *ptr; + snprintf(cpath, sizeof(cpath), "cache/%s", fpath); + for( ptr = &cpath[6] ; *ptr != 0 ; ++ptr ) + if( *ptr == '/' ) + *ptr = '.'; + return cpath; +} + +int updatemdcache(const char *CPATH, const char *fpath) +{ + /* save file to mdcache with *cpath and *fpath, + return: -1 if error + else the fd + */ + int len, sourcefd, targetfd; + char buf[1024], *cpath; + cpath = (CPATH == NULL) ? cachepath(fpath) : CPATH; + if( (sourcefd = open(fpath, O_RDONLY)) < 0 ) + return -1; + if( (targetfd = open(cpath, O_RDWR | O_CREAT, 0600)) < 0 ) + /* md is full? */ + return -1; + while( (len = read(sourcefd, buf, sizeof(buf))) > 0 ) + if( write(targetfd, buf, len) < len ){ + /* md is full? */ + close(targetfd); + unlink(cpath); + return sourcefd; + } + close(sourcefd); + lseek(targetfd, 0, SEEK_SET); + return targetfd; +} +#endif diff --git a/pttbbs/mbbsd/edit.c b/pttbbs/mbbsd/edit.c index 19f437af..0c722105 100644 --- a/pttbbs/mbbsd/edit.c +++ b/pttbbs/mbbsd/edit.c @@ -1,4 +1,4 @@ -/* $Id: edit.c,v 1.1 2002/03/07 15:13:48 in2 Exp $ */ +/* $Id: edit.c,v 1.2 2002/04/15 12:05:52 in2 Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -1014,6 +1014,10 @@ write_file(char *fpath, int saveheader, int *islocal) { } fclose(fp); + +#ifdef MDCACHE + updatemdcache(NULL, fpath); +#endif if(local_article && (currstat == POSTING)) return 0; return 0; diff --git a/pttbbs/mbbsd/more.c b/pttbbs/mbbsd/more.c index f7755874..a65c1ee5 100644 --- a/pttbbs/mbbsd/more.c +++ b/pttbbs/mbbsd/more.c @@ -1,4 +1,4 @@ -/* $Id: more.c,v 1.1 2002/03/07 15:13:48 in2 Exp $ */ +/* $Id: more.c,v 1.2 2002/04/15 12:05:52 in2 Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -193,7 +193,7 @@ static int readln(FILE *fp, char *buf) { extern userec_t cuser; static int more_web(char *fpath, int promptend); - +extern int *GLOBE; int more(char *fpath, int promptend) { extern char* strcasestr(); static char *head[4] = {"作者", "標題", "時間" ,"轉信"}; @@ -232,8 +232,23 @@ int more(char *fpath, int promptend) { search_char0 = *search_str; *search_str = 0; - +#ifdef MDCACHE + if( strncmp(fpath, "boards/", 7) == 0 || strncmp(fpath, "etc/", 4) == 0 ){ + /* we only cache boards/ and etc/ */ + char *cpath = cachepath(fpath); + ++GLOBE[0]; + if( (fd = open(cpath, O_RDONLY)) < 0 ){ + if( (fd = updatemdcache(cpath, fpath)) < 0 ) + return -1; + } + else + ++GLOBE[1]; + } + else + fd = open (fpath, O_RDONLY, 0600); +#else fd = open (fpath, O_RDONLY, 0600); +#endif if (fd < 0) return -1; if(fstat(fd, &st) || ((fsize = st.st_size) <= 0) || S_ISDIR (st.st_mode)) -- cgit v1.2.3 From 9b66ab119c56a39c5045f1c2ae0c6a03c60e7a17 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Mon, 15 Apr 2002 13:57:20 +0000 Subject: GLOBE support git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@104 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/shmctl.c | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/pttbbs/util/shmctl.c b/pttbbs/util/shmctl.c index 1453126a..d6818344 100644 --- a/pttbbs/util/shmctl.c +++ b/pttbbs/util/shmctl.c @@ -13,6 +13,7 @@ #include "proto.h" extern struct utmpfile_t *utmpshm; +extern struct pttcache_t *ptt; int logout_friend_online(userinfo_t *utmp) { @@ -240,6 +241,29 @@ int utmpnum(int argc, char **argv) return 0; } +int showglobe(int argc, char **argv) +{ + int i; + for( i = 0 ; i < 10 ; ++i ) + printf("GLOBE[%d] = %d\n", i, ptt->GLOBE[i]); + return 0; +} + +int setglobe(int argc, char **argv) +{ + int where; + if( argc != 2 ) + return 1; + where = atoi(argv[0]); + if( !(0 <= where && where <= 9) ){ + puts("only GLOBE[0] ~ GLOBE[9]"); + return 1; + } + printf("GLOBE[%d] = %d -> ", where, ptt->GLOBE[where]); + printf("%d\n", ptt->GLOBE[where] = atoi(argv[1])); + return 0; +} + struct { int (*func)(int, char **); char *cmd, *descript; @@ -250,6 +274,8 @@ struct { {utmpsort, "utmpsort", "sort ulist"}, {utmpwatch, "utmpwatch", "to see if busystate is always 1 then fix it"}, {utmpnum, "utmpnum", "print utmpshm->number for snmpd"}, + {showglobe, "showglobe", "show GLOBE"}, + {setglobe, "setglobe", "set GLOBE"}, {NULL, NULL, NULL} }; int main(int argc, char **argv) @@ -267,7 +293,7 @@ int main(int argc, char **argv) chdir(BBSHOME); resolve_utmp(); resolve_boards(); - //resolve_garbage(); + resolve_garbage(); resolve_fcache(); for( i = 0 ; cmd[i].func != NULL ; ++i ) if( strcmp(cmd[i].cmd, argv[1]) == 0 ){ -- cgit v1.2.3 From a2b662318963316b86dd3c2602a6f70d36bcbca7 Mon Sep 17 00:00:00 2001 From: ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Mon, 15 Apr 2002 17:07:11 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@105 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/cache.c | 13 +++++++++---- pttbbs/mbbsd/more.c | 7 ++++--- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/pttbbs/mbbsd/cache.c b/pttbbs/mbbsd/cache.c index 8fceef65..054bd16b 100644 --- a/pttbbs/mbbsd/cache.c +++ b/pttbbs/mbbsd/cache.c @@ -1,4 +1,4 @@ -/* $Id: cache.c,v 1.9 2002/04/15 12:05:52 in2 Exp $ */ +/* $Id: cache.c,v 1.10 2002/04/15 17:07:11 ptt Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -1026,9 +1026,8 @@ int hbflcheck(int bid, int uid) } #ifdef MDCACHE -char *cachepath(const char *fpath) +int cachepath(char *cpath, const char *fpath) { - static char cpath[128]; char *ptr; snprintf(cpath, sizeof(cpath), "cache/%s", fpath); for( ptr = &cpath[6] ; *ptr != 0 ; ++ptr ) @@ -1045,7 +1044,13 @@ int updatemdcache(const char *CPATH, const char *fpath) */ int len, sourcefd, targetfd; char buf[1024], *cpath; - cpath = (CPATH == NULL) ? cachepath(fpath) : CPATH; + if(CPATH==NULL) + { + cpath=buf; + cachepath(buf, fpath); + } + else + cpath = CPATH; if( (sourcefd = open(fpath, O_RDONLY)) < 0 ) return -1; if( (targetfd = open(cpath, O_RDWR | O_CREAT, 0600)) < 0 ) diff --git a/pttbbs/mbbsd/more.c b/pttbbs/mbbsd/more.c index a65c1ee5..4265d75f 100644 --- a/pttbbs/mbbsd/more.c +++ b/pttbbs/mbbsd/more.c @@ -1,4 +1,4 @@ -/* $Id: more.c,v 1.2 2002/04/15 12:05:52 in2 Exp $ */ +/* $Id: more.c,v 1.3 2002/04/15 17:07:11 ptt Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -233,9 +233,10 @@ int more(char *fpath, int promptend) { *search_str = 0; #ifdef MDCACHE - if( strncmp(fpath, "boards/", 7) == 0 || strncmp(fpath, "etc/", 4) == 0 ){ + if(!promptend){ /* we only cache boards/ and etc/ */ - char *cpath = cachepath(fpath); + char cpath[256]; + cachepath(cpath,fpath); ++GLOBE[0]; if( (fd = open(cpath, O_RDONLY)) < 0 ){ if( (fd = updatemdcache(cpath, fpath)) < 0 ) -- cgit v1.2.3 From 28002d0b0377a3ee6e8e552f6a7c81bf9e06b4a6 Mon Sep 17 00:00:00 2001 From: ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Mon, 15 Apr 2002 17:11:37 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@106 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/cache.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/pttbbs/mbbsd/cache.c b/pttbbs/mbbsd/cache.c index 054bd16b..2182423f 100644 --- a/pttbbs/mbbsd/cache.c +++ b/pttbbs/mbbsd/cache.c @@ -1,4 +1,4 @@ -/* $Id: cache.c,v 1.10 2002/04/15 17:07:11 ptt Exp $ */ +/* $Id: cache.c,v 1.11 2002/04/15 17:11:37 ptt Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -1026,14 +1026,13 @@ int hbflcheck(int bid, int uid) } #ifdef MDCACHE -int cachepath(char *cpath, const char *fpath) +void cachepath(char *cpath, const char *fpath) { char *ptr; snprintf(cpath, sizeof(cpath), "cache/%s", fpath); for( ptr = &cpath[6] ; *ptr != 0 ; ++ptr ) if( *ptr == '/' ) *ptr = '.'; - return cpath; } int updatemdcache(const char *CPATH, const char *fpath) -- cgit v1.2.3 From 8f6d986482ef8ad753bc7680cd694e97da6b2b97 Mon Sep 17 00:00:00 2001 From: ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Mon, 15 Apr 2002 17:26:04 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@107 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/include/proto.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pttbbs/include/proto.h b/pttbbs/include/proto.h index f5ceeb6e..3e891624 100644 --- a/pttbbs/include/proto.h +++ b/pttbbs/include/proto.h @@ -1,4 +1,4 @@ -/* $Id: proto.h,v 1.5 2002/04/15 12:05:49 in2 Exp $ */ +/* $Id: proto.h,v 1.6 2002/04/15 17:26:04 ptt Exp $ */ #ifndef INCLUDE_PROTO_H #define INCLUDE_PROTO_H @@ -108,7 +108,7 @@ userinfo_t *search_ulist_pid(int pid); int moneyof(int uid); void hbflreload(int bid); int hbflcheck(int bid, int uid); -char *cachepath(const char *fpath); +void cachepath(char *buf, const char *fpath); int updatemdcache(const char *cpath, const char *fpath); /* cal */ -- cgit v1.2.3 From 761de959339bb6af5a2022fab127408d2b0615ab Mon Sep 17 00:00:00 2001 From: ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Mon, 15 Apr 2002 18:10:27 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@108 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/mbbsd.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pttbbs/mbbsd/mbbsd.c b/pttbbs/mbbsd/mbbsd.c index bc04b67c..3a63321a 100644 --- a/pttbbs/mbbsd/mbbsd.c +++ b/pttbbs/mbbsd/mbbsd.c @@ -1,4 +1,4 @@ -/* $Id: mbbsd.c,v 1.19 2002/04/10 14:06:07 ptt Exp $ */ +/* $Id: mbbsd.c,v 1.20 2002/04/15 18:10:27 ptt Exp $ */ #include <stdio.h> #include <string.h> #include <stdlib.h> @@ -574,6 +574,7 @@ login_query () char genbuf[200]; extern struct utmpfile_t *utmpshm; resolve_utmp (); + resolve_garbage (); attach_uhash (); attempts = utmpshm->number; show_file ("etc/Welcome", 1, -1, NO_RELOAD); @@ -845,7 +846,6 @@ user_login () log_usies ("ENTER", fromhost); setproctitle ("%s: %s", margs, cuser.userid); - resolve_garbage (); resolve_fcache (); resolve_boards (); memset( &water[0],0,sizeof(water_t) * 6); -- cgit v1.2.3 From 31008b3fc77a49d843da73d1f1f5394887861508 Mon Sep 17 00:00:00 2001 From: ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Mon, 15 Apr 2002 19:06:22 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@109 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/cache.c | 12 +++++------- pttbbs/mbbsd/more.c | 10 ++++------ 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/pttbbs/mbbsd/cache.c b/pttbbs/mbbsd/cache.c index 2182423f..4829c929 100644 --- a/pttbbs/mbbsd/cache.c +++ b/pttbbs/mbbsd/cache.c @@ -1,4 +1,4 @@ -/* $Id: cache.c,v 1.11 2002/04/15 17:11:37 ptt Exp $ */ +/* $Id: cache.c,v 1.12 2002/04/15 19:06:21 ptt Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -1058,12 +1058,10 @@ int updatemdcache(const char *CPATH, const char *fpath) while( (len = read(sourcefd, buf, sizeof(buf))) > 0 ) if( write(targetfd, buf, len) < len ){ /* md is full? */ - close(targetfd); - unlink(cpath); - return sourcefd; } - close(sourcefd); - lseek(targetfd, 0, SEEK_SET); - return targetfd; + close(targetfd); + lseek(sourcefd, 0, SEEK_SET); + + return sourcefd; } #endif diff --git a/pttbbs/mbbsd/more.c b/pttbbs/mbbsd/more.c index 4265d75f..c8abd17e 100644 --- a/pttbbs/mbbsd/more.c +++ b/pttbbs/mbbsd/more.c @@ -1,4 +1,4 @@ -/* $Id: more.c,v 1.3 2002/04/15 17:07:11 ptt Exp $ */ +/* $Id: more.c,v 1.4 2002/04/15 19:06:22 ptt Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -238,12 +238,10 @@ int more(char *fpath, int promptend) { char cpath[256]; cachepath(cpath,fpath); ++GLOBE[0]; - if( (fd = open(cpath, O_RDONLY)) < 0 ){ - if( (fd = updatemdcache(cpath, fpath)) < 0 ) + if( (fd = open(cpath, O_RDONLY)) < 0 || + (fd = updatemdcache(cpath, fpath)) < 0 ) return -1; - } - else - ++GLOBE[1]; + ++GLOBE[1]; } else fd = open (fpath, O_RDONLY, 0600); -- cgit v1.2.3 From be5e13e26a62fee160856cbc3ec10edacb881747 Mon Sep 17 00:00:00 2001 From: ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Mon, 15 Apr 2002 19:17:20 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@110 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/more.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pttbbs/mbbsd/more.c b/pttbbs/mbbsd/more.c index c8abd17e..aa706617 100644 --- a/pttbbs/mbbsd/more.c +++ b/pttbbs/mbbsd/more.c @@ -1,4 +1,4 @@ -/* $Id: more.c,v 1.4 2002/04/15 19:06:22 ptt Exp $ */ +/* $Id: more.c,v 1.5 2002/04/15 19:17:20 ptt Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -233,7 +233,7 @@ int more(char *fpath, int promptend) { *search_str = 0; #ifdef MDCACHE - if(!promptend){ + if(!promptend && strncmp(fpath,"home",4)){ /* we only cache boards/ and etc/ */ char cpath[256]; cachepath(cpath,fpath); -- cgit v1.2.3 From ed63617a3bd55867c79d27fb4ce22b0bbbee3cdd Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Mon, 15 Apr 2002 19:56:53 +0000 Subject: fix bug git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@111 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/cache.c | 13 +++++-------- pttbbs/mbbsd/more.c | 7 ++++--- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/pttbbs/mbbsd/cache.c b/pttbbs/mbbsd/cache.c index 4829c929..7f8845c9 100644 --- a/pttbbs/mbbsd/cache.c +++ b/pttbbs/mbbsd/cache.c @@ -1,4 +1,4 @@ -/* $Id: cache.c,v 1.12 2002/04/15 19:06:21 ptt Exp $ */ +/* $Id: cache.c,v 1.13 2002/04/15 19:56:53 in2 Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -1029,7 +1029,7 @@ int hbflcheck(int bid, int uid) void cachepath(char *cpath, const char *fpath) { char *ptr; - snprintf(cpath, sizeof(cpath), "cache/%s", fpath); + sprintf(cpath, "cache/%s", fpath); for( ptr = &cpath[6] ; *ptr != 0 ; ++ptr ) if( *ptr == '/' ) *ptr = '.'; @@ -1043,13 +1043,10 @@ int updatemdcache(const char *CPATH, const char *fpath) */ int len, sourcefd, targetfd; char buf[1024], *cpath; - if(CPATH==NULL) - { - cpath=buf; - cachepath(buf, fpath); - } + if( CPATH == NULL ) + cachepath(cpath = buf, fpath); else - cpath = CPATH; + cpath = CPATH; if( (sourcefd = open(fpath, O_RDONLY)) < 0 ) return -1; if( (targetfd = open(cpath, O_RDWR | O_CREAT, 0600)) < 0 ) diff --git a/pttbbs/mbbsd/more.c b/pttbbs/mbbsd/more.c index aa706617..0a6cbb59 100644 --- a/pttbbs/mbbsd/more.c +++ b/pttbbs/mbbsd/more.c @@ -1,4 +1,4 @@ -/* $Id: more.c,v 1.5 2002/04/15 19:17:20 ptt Exp $ */ +/* $Id: more.c,v 1.6 2002/04/15 19:56:53 in2 Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -233,12 +233,13 @@ int more(char *fpath, int promptend) { *search_str = 0; #ifdef MDCACHE - if(!promptend && strncmp(fpath,"home",4)){ + //if(!promptend && strncmp(fpath,"home",4)){ + if( strncmp(fpath, "boards/", 7) == 0 || strncmp(fpath, "etc/", 4) == 0 ){ /* we only cache boards/ and etc/ */ char cpath[256]; cachepath(cpath,fpath); ++GLOBE[0]; - if( (fd = open(cpath, O_RDONLY)) < 0 || + if( (fd = open(cpath, O_RDONLY)) < 0 && (fd = updatemdcache(cpath, fpath)) < 0 ) return -1; ++GLOBE[1]; -- cgit v1.2.3 From d5b42bf526ae364aa0d62cd97db5b83a6370fc42 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Mon, 15 Apr 2002 20:00:22 +0000 Subject: no warning git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@112 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/announce.c | 4 +++- pttbbs/mbbsd/board.c | 4 +++- pttbbs/mbbsd/cache.c | 4 ++-- pttbbs/mbbsd/mbbsd.c | 6 +++++- pttbbs/mbbsd/record.c | 4 +++- pttbbs/mbbsd/term.c | 5 +++-- 6 files changed, 19 insertions(+), 8 deletions(-) diff --git a/pttbbs/mbbsd/announce.c b/pttbbs/mbbsd/announce.c index 314b3a41..280306dc 100644 --- a/pttbbs/mbbsd/announce.c +++ b/pttbbs/mbbsd/announce.c @@ -1,4 +1,4 @@ -/* $Id: announce.c,v 1.3 2002/04/12 18:21:13 ptt Exp $ */ +/* $Id: announce.c,v 1.4 2002/04/15 20:00:22 in2 Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -1237,6 +1237,7 @@ static void a_showname(menu_t *pm) { pressanykey(); } +#if 0 static char *a_title; static void atitle() { @@ -1245,6 +1246,7 @@ static void atitle() { "[TAB]文摘 [h]elp\n\033[7m 編號 日 期 作 者 " "文 章 標 題\033[m"); } +#endif extern char currtitle[]; diff --git a/pttbbs/mbbsd/board.c b/pttbbs/mbbsd/board.c index f28721da..e97d6e3f 100644 --- a/pttbbs/mbbsd/board.c +++ b/pttbbs/mbbsd/board.c @@ -1,4 +1,4 @@ -/* $Id: board.c,v 1.3 2002/03/16 15:37:22 ptt Exp $ */ +/* $Id: board.c,v 1.4 2002/04/15 20:00:22 in2 Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -332,6 +332,7 @@ extern char currauthor[]; extern int b_lines; extern char currowner[]; +#if 0 static int have_author(char* brdname) { char dirname[100]; @@ -347,6 +348,7 @@ static int have_author(char* brdname) { return search_rec(dirname, cmpfowner); } +#endif static int check_newpost(boardstat_t *ptr) { /* Ptt 改 */ int tbrc_list[BRC_MAXNUM], tbrc_num; diff --git a/pttbbs/mbbsd/cache.c b/pttbbs/mbbsd/cache.c index 7f8845c9..b7f58866 100644 --- a/pttbbs/mbbsd/cache.c +++ b/pttbbs/mbbsd/cache.c @@ -1,4 +1,4 @@ -/* $Id: cache.c,v 1.13 2002/04/15 19:56:53 in2 Exp $ */ +/* $Id: cache.c,v 1.14 2002/04/15 20:00:22 in2 Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -1046,7 +1046,7 @@ int updatemdcache(const char *CPATH, const char *fpath) if( CPATH == NULL ) cachepath(cpath = buf, fpath); else - cpath = CPATH; + cpath = (char *)CPATH; if( (sourcefd = open(fpath, O_RDONLY)) < 0 ) return -1; if( (targetfd = open(cpath, O_RDWR | O_CREAT, 0600)) < 0 ) diff --git a/pttbbs/mbbsd/mbbsd.c b/pttbbs/mbbsd/mbbsd.c index 3a63321a..3f2b68e7 100644 --- a/pttbbs/mbbsd/mbbsd.c +++ b/pttbbs/mbbsd/mbbsd.c @@ -1,4 +1,4 @@ -/* $Id: mbbsd.c,v 1.20 2002/04/15 18:10:27 ptt Exp $ */ +/* $Id: mbbsd.c,v 1.21 2002/04/15 20:00:22 in2 Exp $ */ #include <stdio.h> #include <string.h> #include <stdlib.h> @@ -42,7 +42,9 @@ extern int curr_idle_timeout; static void do_aloha (char *hello); +#if 0 static jmp_buf byebye; +#endif int talkrequest = NA; @@ -1090,12 +1092,14 @@ telnet_init () #define RFC931_PORT 113 /* Semi-well-known port */ #define ANY_PORT 0 /* Any old port will do */ +#if 0 /* timeout - handle timeouts */ static void timeout (int sig) { longjmp (byebye, sig); } +#endif static void getremotename (struct sockaddr_in *from, char *rhost, char *rname) diff --git a/pttbbs/mbbsd/record.c b/pttbbs/mbbsd/record.c index 321132f3..b572b7cf 100644 --- a/pttbbs/mbbsd/record.c +++ b/pttbbs/mbbsd/record.c @@ -1,4 +1,4 @@ -/* $Id: record.c,v 1.2 2002/03/09 17:27:57 in2 Exp $ */ +/* $Id: record.c,v 1.3 2002/04/15 20:00:22 in2 Exp $ */ #include <stdio.h> #include <stdlib.h> #include <errno.h> @@ -192,6 +192,7 @@ int delete_record(char fpath[], int size, int id) { return 0; } +#if 0 static char *title_body(char *title) { if(!strncasecmp(title, str_reply, 3)) { title += 3; @@ -200,6 +201,7 @@ static char *title_body(char *title) { } return title; } +#endif int delete_range(char *fpath, int id1, int id2) { fileheader_t fhdr; diff --git a/pttbbs/mbbsd/term.c b/pttbbs/mbbsd/term.c index 61a0128d..db3e66d1 100644 --- a/pttbbs/mbbsd/term.c +++ b/pttbbs/mbbsd/term.c @@ -1,4 +1,4 @@ -/* $Id: term.c,v 1.1 2002/03/07 15:13:48 in2 Exp $ */ +/* $Id: term.c,v 1.2 2002/04/15 20:00:22 in2 Exp $ */ #include <stdio.h> #include <stdlib.h> #include <termios.h> @@ -67,10 +67,10 @@ int t_columns = 80; int automargins = 1; +#if 0 static char *outp; static int *outlp; - static int outcf(int ch) { if(*outlp < TERMCOMSIZE) { (*outlp)++; @@ -78,6 +78,7 @@ static int outcf(int ch) { } return 0; } +#endif extern screenline_t *big_picture; -- cgit v1.2.3 From d81e85349b0ac9ece8e09dd497d1104dfe11b3a7 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Mon, 15 Apr 2002 20:07:51 +0000 Subject: mdclean git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@113 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/.cvsignore | 3 +- pttbbs/util/Makefile | 8 ++--- pttbbs/util/mdclean.c | 81 ++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 87 insertions(+), 5 deletions(-) create mode 100644 pttbbs/util/mdclean.c diff --git a/pttbbs/util/.cvsignore b/pttbbs/util/.cvsignore index 73de8aac..982f6b1b 100644 --- a/pttbbs/util/.cvsignore +++ b/pttbbs/util/.cvsignore @@ -40,4 +40,5 @@ toplazyBM jungo bbsctl mandex -shmctl \ No newline at end of file +shmctl +mdclean diff --git a/pttbbs/util/Makefile b/pttbbs/util/Makefile index d1dd93e1..c0616b7b 100644 --- a/pttbbs/util/Makefile +++ b/pttbbs/util/Makefile @@ -1,4 +1,4 @@ -# $Id: Makefile,v 1.10 2002/04/14 14:08:56 in2 Exp $ +# $Id: Makefile,v 1.11 2002/04/15 20:07:08 in2 Exp $ BBSHOME?=$(HOME) OSTYPE?=linux @@ -30,7 +30,7 @@ CPROGS= bbsmail BM_money post account birth deluserfile expire mandex\ poststat showboard antispam countalldice webgrep bbsrf\ initbbs outmail xchatd userlist tunepasswd buildir reaper shmsweep\ merge_passwd merge_board inndBM buildAnnounce rmuid \ - toplazyBM jungo toplazyBBM shmctl killdeadbbs + toplazyBM jungo toplazyBBM shmctl mdclean PROGS= $(CPROGS) BM_money.sh backpasswd.sh mailog.sh opendice.sh\ openticket.sh stock.sh topsong.sh weather.sh stock.perl weather.perl\ @@ -156,8 +156,8 @@ bbsctl: bbsctl.c shmctl: shmctl.c $(OBJS) $(CC) $(CFLAGS) -o $@ $@.c $(OBJS) -killdeadbbs: killdeadbbs.c - $(CC) $(CFLAGS) -lkvm -o $@ $@.c +mdclean: mdclean.c + $(CC) $(CFLAGS) -o $@ $@.c install: $(PROGS) install -d $(BBSHOME)/bin/ diff --git a/pttbbs/util/mdclean.c b/pttbbs/util/mdclean.c new file mode 100644 index 00000000..f8f58728 --- /dev/null +++ b/pttbbs/util/mdclean.c @@ -0,0 +1,81 @@ +#include <stdio.h> +#include <stdlib.h> +#include "config.h" +#include <sys/types.h> +#include <dirent.h> +#include <unistd.h> +#include <err.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <sys/param.h> +#include <sys/mount.h> + +#define MAXDSs 1048576 +#define LEAVE 10 +#define CLEAN 10 +typedef struct { + time_t atime; + char name[60]; +} DS; + +DS ds[MAXDSs]; +int nDSs; + +int compar(const void *a, const void *b) +{ + return ((DS *)a)->atime - ((DS *)b)->atime; +} + +int main(int argc, char **argv) +{ + DIR *dirp; + struct dirent *dp; + struct stat sb; + struct statfs sf; + char *fn; + time_t now; + if( chdir(BBSHOME "/cache") < 0 ) + err(1, "chdir"); + + if( (dirp = opendir(".")) == NULL ) + err(1, "opendir"); + + statfs(".", &sf); + if( sf.f_bfree * 100 / sf.f_blocks > LEAVE ) + return 0; + + now = time(NULL); + while( (dp = readdir(dirp)) != NULL ){ + fn = dp->d_name; + if( fn[0] != 'e' && fn[0] != 'b' ) + continue; + if( stat(fn, &sb) < 0 ) + continue; + if( sb.st_atime < now - 1800 ){ + printf("atime: %s\n", fn); + unlink(fn); + } + else if( sb.st_mtime < now - 7200 ){ + printf("mtime: %s\n", fn); + unlink(fn); + } + else{ + if( nDSs != MAXDSs ){ + strcpy(ds[nDSs].name, fn); + ds[nDSs].atime = sb.st_atime; + ++nDSs; + } + } + } + + statfs(".", &sf); + if( sf.f_bfree * 100 / sf.f_blocks <= LEAVE ){ + qsort(ds, nDSs, sizeof(DS), compar); + nDSs = nDSs * CLEAN / 100; + while( nDSs-- ){ + printf("%s\n", ds[nDSs].name); + unlink(ds[nDSs].name); + } + } + return 0; +} -- cgit v1.2.3 From 44fe9459937df1a52d21432bd1760461f9b149cd Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Tue, 16 Apr 2002 10:07:19 +0000 Subject: bug fix git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@114 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/cache.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pttbbs/mbbsd/cache.c b/pttbbs/mbbsd/cache.c index b7f58866..d62652a8 100644 --- a/pttbbs/mbbsd/cache.c +++ b/pttbbs/mbbsd/cache.c @@ -1,4 +1,4 @@ -/* $Id: cache.c,v 1.14 2002/04/15 20:00:22 in2 Exp $ */ +/* $Id: cache.c,v 1.15 2002/04/16 10:07:19 in2 Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -1055,6 +1055,8 @@ int updatemdcache(const char *CPATH, const char *fpath) while( (len = read(sourcefd, buf, sizeof(buf))) > 0 ) if( write(targetfd, buf, len) < len ){ /* md is full? */ + close(targetfd); + unlink(cpath); } close(targetfd); lseek(sourcefd, 0, SEEK_SET); -- cgit v1.2.3 From 714c2b662ba787cc6287117fd3c9c4818144a7c3 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Tue, 16 Apr 2002 14:55:31 +0000 Subject: revert to 1.9 git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@115 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/cache.c | 21 ++++++++++----------- pttbbs/mbbsd/more.c | 6 +++--- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/pttbbs/mbbsd/cache.c b/pttbbs/mbbsd/cache.c index d62652a8..cbb042f2 100644 --- a/pttbbs/mbbsd/cache.c +++ b/pttbbs/mbbsd/cache.c @@ -1,4 +1,4 @@ -/* $Id: cache.c,v 1.15 2002/04/16 10:07:19 in2 Exp $ */ +/* $Id: cache.c,v 1.16 2002/04/16 14:55:31 in2 Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -1026,13 +1026,15 @@ int hbflcheck(int bid, int uid) } #ifdef MDCACHE -void cachepath(char *cpath, const char *fpath) +char *cachepath(const char *fpath) { + static char cpath[128]; char *ptr; - sprintf(cpath, "cache/%s", fpath); + snprintf(cpath, sizeof(cpath), "cache/%s", fpath); for( ptr = &cpath[6] ; *ptr != 0 ; ++ptr ) if( *ptr == '/' ) *ptr = '.'; + return cpath; } int updatemdcache(const char *CPATH, const char *fpath) @@ -1043,10 +1045,7 @@ int updatemdcache(const char *CPATH, const char *fpath) */ int len, sourcefd, targetfd; char buf[1024], *cpath; - if( CPATH == NULL ) - cachepath(cpath = buf, fpath); - else - cpath = (char *)CPATH; + cpath = (CPATH == NULL) ? cachepath(fpath) : CPATH; if( (sourcefd = open(fpath, O_RDONLY)) < 0 ) return -1; if( (targetfd = open(cpath, O_RDWR | O_CREAT, 0600)) < 0 ) @@ -1057,10 +1056,10 @@ int updatemdcache(const char *CPATH, const char *fpath) /* md is full? */ close(targetfd); unlink(cpath); + return sourcefd; } - close(targetfd); - lseek(sourcefd, 0, SEEK_SET); - - return sourcefd; + close(sourcefd); + lseek(targetfd, 0, SEEK_SET); + return targetfd; } #endif diff --git a/pttbbs/mbbsd/more.c b/pttbbs/mbbsd/more.c index 0a6cbb59..a932d585 100644 --- a/pttbbs/mbbsd/more.c +++ b/pttbbs/mbbsd/more.c @@ -1,4 +1,4 @@ -/* $Id: more.c,v 1.6 2002/04/15 19:56:53 in2 Exp $ */ +/* $Id: more.c,v 1.7 2002/04/16 14:55:31 in2 Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -236,8 +236,8 @@ int more(char *fpath, int promptend) { //if(!promptend && strncmp(fpath,"home",4)){ if( strncmp(fpath, "boards/", 7) == 0 || strncmp(fpath, "etc/", 4) == 0 ){ /* we only cache boards/ and etc/ */ - char cpath[256]; - cachepath(cpath,fpath); + char *cpath; + cpath = cachepath(fpath); ++GLOBE[0]; if( (fd = open(cpath, O_RDONLY)) < 0 && (fd = updatemdcache(cpath, fpath)) < 0 ) -- cgit v1.2.3 From caf410af0eae895643e3ff2bacdc2ee6debb4f28 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Tue, 16 Apr 2002 14:55:48 +0000 Subject: revert git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@116 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/include/proto.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pttbbs/include/proto.h b/pttbbs/include/proto.h index 3e891624..cc3703c5 100644 --- a/pttbbs/include/proto.h +++ b/pttbbs/include/proto.h @@ -1,4 +1,4 @@ -/* $Id: proto.h,v 1.6 2002/04/15 17:26:04 ptt Exp $ */ +/* $Id: proto.h,v 1.7 2002/04/16 14:55:48 in2 Exp $ */ #ifndef INCLUDE_PROTO_H #define INCLUDE_PROTO_H @@ -108,8 +108,8 @@ userinfo_t *search_ulist_pid(int pid); int moneyof(int uid); void hbflreload(int bid); int hbflcheck(int bid, int uid); -void cachepath(char *buf, const char *fpath); int updatemdcache(const char *cpath, const char *fpath); +char *cachepath(const char *fpath); /* cal */ int vice(int money, char* item); -- cgit v1.2.3 From f8e0db44934dcf16a7a61360bc3c5046be1b5ed9 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Tue, 16 Apr 2002 15:27:27 +0000 Subject: MDCACHE git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@117 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/voteboard.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pttbbs/mbbsd/voteboard.c b/pttbbs/mbbsd/voteboard.c index 1286d986..5c79fe46 100644 --- a/pttbbs/mbbsd/voteboard.c +++ b/pttbbs/mbbsd/voteboard.c @@ -1,4 +1,4 @@ -/* $Id: voteboard.c,v 1.1 2002/03/07 15:13:48 in2 Exp $ */ +/* $Id: voteboard.c,v 1.2 2002/04/16 15:27:27 in2 Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -189,6 +189,9 @@ void do_voteboardreply(fileheader_t *fhdr){ fclose(fo); unlink(oldfpath); rename(fpath, oldfpath); +#ifdef MDCACHE + close(updatemdcache(NULL, fpath)); +#endif } int do_voteboard() { -- cgit v1.2.3 From e4d4e627d313d696b14f368d26c12052d61bf8b4 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Tue, 16 Apr 2002 15:27:40 +0000 Subject: fix bug (MDCACHE) git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@118 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/edit.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pttbbs/mbbsd/edit.c b/pttbbs/mbbsd/edit.c index 0c722105..8072de6d 100644 --- a/pttbbs/mbbsd/edit.c +++ b/pttbbs/mbbsd/edit.c @@ -1,4 +1,4 @@ -/* $Id: edit.c,v 1.2 2002/04/15 12:05:52 in2 Exp $ */ +/* $Id: edit.c,v 1.3 2002/04/16 15:27:40 in2 Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -1016,7 +1016,7 @@ write_file(char *fpath, int saveheader, int *islocal) { fclose(fp); #ifdef MDCACHE - updatemdcache(NULL, fpath); + close(updatemdcache(NULL, fpath)); #endif if(local_article && (currstat == POSTING)) return 0; -- cgit v1.2.3 From dafc9f4a371f9f4f947fa91d73f5153c6a92ca4f Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Tue, 16 Apr 2002 15:27:54 +0000 Subject: fix MDCACHE git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@119 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/more.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/pttbbs/mbbsd/more.c b/pttbbs/mbbsd/more.c index a932d585..0ffc3793 100644 --- a/pttbbs/mbbsd/more.c +++ b/pttbbs/mbbsd/more.c @@ -1,4 +1,4 @@ -/* $Id: more.c,v 1.7 2002/04/16 14:55:31 in2 Exp $ */ +/* $Id: more.c,v 1.8 2002/04/16 15:27:54 in2 Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -238,11 +238,12 @@ int more(char *fpath, int promptend) { /* we only cache boards/ and etc/ */ char *cpath; cpath = cachepath(fpath); - ++GLOBE[0]; - if( (fd = open(cpath, O_RDONLY)) < 0 && - (fd = updatemdcache(cpath, fpath)) < 0 ) + ++GLOBE[8]; + if( (fd = open(cpath, O_RDONLY)) >= 0 ) + ++GLOBE[9]; + else + if( (fd = updatemdcache(cpath, fpath)) < 0 ) return -1; - ++GLOBE[1]; } else fd = open (fpath, O_RDONLY, 0600); -- cgit v1.2.3 From 5597dd220b9a7179fe20f90ea88dd3539bbabe66 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Tue, 16 Apr 2002 16:38:25 +0000 Subject: fix bug git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@120 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/cache.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pttbbs/mbbsd/cache.c b/pttbbs/mbbsd/cache.c index cbb042f2..b7a485ad 100644 --- a/pttbbs/mbbsd/cache.c +++ b/pttbbs/mbbsd/cache.c @@ -1,4 +1,4 @@ -/* $Id: cache.c,v 1.16 2002/04/16 14:55:31 in2 Exp $ */ +/* $Id: cache.c,v 1.17 2002/04/16 16:38:25 in2 Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -1056,6 +1056,7 @@ int updatemdcache(const char *CPATH, const char *fpath) /* md is full? */ close(targetfd); unlink(cpath); + lseek(sourcefd, 0, SEEK_SET); return sourcefd; } close(sourcefd); -- cgit v1.2.3 From 143f68b2d5c95d535bfc362ff25c2fa13c30618d Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Wed, 17 Apr 2002 09:23:26 +0000 Subject: fix bug(MDCACHE) git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@121 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/voteboard.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pttbbs/mbbsd/voteboard.c b/pttbbs/mbbsd/voteboard.c index 5c79fe46..53034692 100644 --- a/pttbbs/mbbsd/voteboard.c +++ b/pttbbs/mbbsd/voteboard.c @@ -1,4 +1,4 @@ -/* $Id: voteboard.c,v 1.2 2002/04/16 15:27:27 in2 Exp $ */ +/* $Id: voteboard.c,v 1.3 2002/04/17 09:23:26 in2 Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -190,7 +190,7 @@ void do_voteboardreply(fileheader_t *fhdr){ unlink(oldfpath); rename(fpath, oldfpath); #ifdef MDCACHE - close(updatemdcache(NULL, fpath)); + close(updatemdcache(NULL, oldfpath)); #endif } -- cgit v1.2.3 From f02f201a9afae52b691ed8cae367438fb72bcd8b Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Thu, 18 Apr 2002 21:27:23 +0000 Subject: patch MDCACHE git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@122 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/cache.c | 17 +++++++++++++++-- pttbbs/mbbsd/more.c | 17 ++--------------- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/pttbbs/mbbsd/cache.c b/pttbbs/mbbsd/cache.c index b7a485ad..1be9d32a 100644 --- a/pttbbs/mbbsd/cache.c +++ b/pttbbs/mbbsd/cache.c @@ -1,4 +1,4 @@ -/* $Id: cache.c,v 1.17 2002/04/16 16:38:25 in2 Exp $ */ +/* $Id: cache.c,v 1.18 2002/04/18 21:27:23 in2 Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -1045,7 +1045,7 @@ int updatemdcache(const char *CPATH, const char *fpath) */ int len, sourcefd, targetfd; char buf[1024], *cpath; - cpath = (CPATH == NULL) ? cachepath(fpath) : CPATH; + cpath = (CPATH == NULL) ? cachepath(fpath) : (char *)CPATH; if( (sourcefd = open(fpath, O_RDONLY)) < 0 ) return -1; if( (targetfd = open(cpath, O_RDWR | O_CREAT, 0600)) < 0 ) @@ -1063,4 +1063,17 @@ int updatemdcache(const char *CPATH, const char *fpath) lseek(targetfd, 0, SEEK_SET); return targetfd; } + +int mdcacheopen(char *fpath) +{ + int fd; + char *cpath; + if( strncmp(fpath, "boards/", 7) && strncmp(fpath, "etc/", 4) ) + return open(fpath, O_RDONLY); + + if( (fd = open((cpath = cachepath(fpath)), O_RDONLY)) < 0 ) + return updatemdcache(cpath, fpath); + + return fd; +} #endif diff --git a/pttbbs/mbbsd/more.c b/pttbbs/mbbsd/more.c index 0ffc3793..b0c57611 100644 --- a/pttbbs/mbbsd/more.c +++ b/pttbbs/mbbsd/more.c @@ -1,4 +1,4 @@ -/* $Id: more.c,v 1.8 2002/04/16 15:27:54 in2 Exp $ */ +/* $Id: more.c,v 1.9 2002/04/18 21:27:23 in2 Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -233,20 +233,7 @@ int more(char *fpath, int promptend) { *search_str = 0; #ifdef MDCACHE - //if(!promptend && strncmp(fpath,"home",4)){ - if( strncmp(fpath, "boards/", 7) == 0 || strncmp(fpath, "etc/", 4) == 0 ){ - /* we only cache boards/ and etc/ */ - char *cpath; - cpath = cachepath(fpath); - ++GLOBE[8]; - if( (fd = open(cpath, O_RDONLY)) >= 0 ) - ++GLOBE[9]; - else - if( (fd = updatemdcache(cpath, fpath)) < 0 ) - return -1; - } - else - fd = open (fpath, O_RDONLY, 0600); + fd = mdcacheopen(fpath); #else fd = open (fpath, O_RDONLY, 0600); #endif -- cgit v1.2.3 From 26a936e70587e4e652dd51a3b404efb3524369e0 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Thu, 18 Apr 2002 22:42:23 +0000 Subject: MDCACHE patch git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@123 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/include/proto.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pttbbs/include/proto.h b/pttbbs/include/proto.h index cc3703c5..fa30e640 100644 --- a/pttbbs/include/proto.h +++ b/pttbbs/include/proto.h @@ -1,4 +1,4 @@ -/* $Id: proto.h,v 1.7 2002/04/16 14:55:48 in2 Exp $ */ +/* $Id: proto.h,v 1.8 2002/04/18 22:42:23 in2 Exp $ */ #ifndef INCLUDE_PROTO_H #define INCLUDE_PROTO_H @@ -110,6 +110,7 @@ void hbflreload(int bid); int hbflcheck(int bid, int uid); int updatemdcache(const char *cpath, const char *fpath); char *cachepath(const char *fpath); +int mdcacheopen(char *fpath); /* cal */ int vice(int money, char* item); -- cgit v1.2.3 From ddf7641c61368940caab0e179bfdd97059c90cfb Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Fri, 19 Apr 2002 12:10:09 +0000 Subject: fix bug(MDCACHE) git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@124 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/cache.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pttbbs/mbbsd/cache.c b/pttbbs/mbbsd/cache.c index 1be9d32a..94e8edfc 100644 --- a/pttbbs/mbbsd/cache.c +++ b/pttbbs/mbbsd/cache.c @@ -1,4 +1,4 @@ -/* $Id: cache.c,v 1.18 2002/04/18 21:27:23 in2 Exp $ */ +/* $Id: cache.c,v 1.19 2002/04/19 12:10:09 in2 Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -1048,7 +1048,7 @@ int updatemdcache(const char *CPATH, const char *fpath) cpath = (CPATH == NULL) ? cachepath(fpath) : (char *)CPATH; if( (sourcefd = open(fpath, O_RDONLY)) < 0 ) return -1; - if( (targetfd = open(cpath, O_RDWR | O_CREAT, 0600)) < 0 ) + if( (targetfd = open(cpath, O_RDWR | O_CREAT | O_TRUNC, 0600)) < 0 ) /* md is full? */ return -1; while( (len = read(sourcefd, buf, sizeof(buf))) > 0 ) -- cgit v1.2.3 From f58979de864cb6b67c6459ecbc0296092a3ee76a Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sat, 20 Apr 2002 07:31:46 +0000 Subject: MDCACHEHITRATE git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@125 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/cache.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/pttbbs/mbbsd/cache.c b/pttbbs/mbbsd/cache.c index 94e8edfc..03092a2f 100644 --- a/pttbbs/mbbsd/cache.c +++ b/pttbbs/mbbsd/cache.c @@ -1,4 +1,4 @@ -/* $Id: cache.c,v 1.19 2002/04/19 12:10:09 in2 Exp $ */ +/* $Id: cache.c,v 1.20 2002/04/20 07:31:46 in2 Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -1070,9 +1070,16 @@ int mdcacheopen(char *fpath) char *cpath; if( strncmp(fpath, "boards/", 7) && strncmp(fpath, "etc/", 4) ) return open(fpath, O_RDONLY); - + +#ifdef MDCACHEHITRATE + ++GLOBE[0]; +#endif if( (fd = open((cpath = cachepath(fpath)), O_RDONLY)) < 0 ) return updatemdcache(cpath, fpath); +#ifdef MDCACHEHITRATE + else + ++GLOBE[1]; +#endif return fd; } -- cgit v1.2.3 From 9c0358f168b178171fbf1fbba7e432e9050646dd Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sat, 20 Apr 2002 08:06:27 +0000 Subject: powerful mdclean git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@126 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/mdclean.c | 91 ++++++++++++++++++++++++++++++--------------------- 1 file changed, 54 insertions(+), 37 deletions(-) diff --git a/pttbbs/util/mdclean.c b/pttbbs/util/mdclean.c index f8f58728..196fc9ee 100644 --- a/pttbbs/util/mdclean.c +++ b/pttbbs/util/mdclean.c @@ -11,8 +11,7 @@ #include <sys/mount.h> #define MAXDSs 1048576 -#define LEAVE 10 -#define CLEAN 10 + typedef struct { time_t atime; char name[60]; @@ -34,47 +33,65 @@ int main(int argc, char **argv) struct statfs sf; char *fn; time_t now; - if( chdir(BBSHOME "/cache") < 0 ) - err(1, "chdir"); - - if( (dirp = opendir(".")) == NULL ) - err(1, "opendir"); + int sleeptime, leavespace, clean; - statfs(".", &sf); - if( sf.f_bfree * 100 / sf.f_blocks > LEAVE ) + if( argc != 4 ){ + puts("usage:\tmdclean sleeptime(secs) leavespace(k) clean(%%)\n"); return 0; + } + sleeptime = (atoi(argv[1]) < 1) ? 1 : atoi(argv[1]); + leavespace= (atoi(argv[2]) <100)?100: atoi(argv[2]); + clean = (atoi(argv[3]) < 1) ? 1 : atoi(argv[3]); - now = time(NULL); - while( (dp = readdir(dirp)) != NULL ){ - fn = dp->d_name; - if( fn[0] != 'e' && fn[0] != 'b' ) - continue; - if( stat(fn, &sb) < 0 ) + if( chdir(BBSHOME "/cache") < 0 ) + err(1, "chdir"); + + while( 1 ){ + puts("sleeping..."); + sleep(sleeptime); + if( (dirp = opendir(".")) == NULL ) + err(1, "opendir"); + + statfs(".", &sf); + if( sf.f_bfree * sf.f_bsize / 1024 > leavespace ) continue; - if( sb.st_atime < now - 1800 ){ - printf("atime: %s\n", fn); - unlink(fn); - } - else if( sb.st_mtime < now - 7200 ){ - printf("mtime: %s\n", fn); - unlink(fn); - } - else{ - if( nDSs != MAXDSs ){ - strcpy(ds[nDSs].name, fn); - ds[nDSs].atime = sb.st_atime; - ++nDSs; + + nDSs = 0; + now = time(NULL); + while( (dp = readdir(dirp)) != NULL ){ + fn = dp->d_name; + if( fn[0] != 'e' && fn[0] != 'b' ){ + unlink(fn); + continue; + } + if( stat(fn, &sb) < 0 ) + continue; + if( sb.st_atime < now - 1800 ){ + printf("atime: %s\n", fn); + unlink(fn); + } + else if( sb.st_mtime < now - 10800 ){ + printf("mtime: %s\n", fn); + unlink(fn); + } + else{ + if( nDSs != MAXDSs ){ + strcpy(ds[nDSs].name, fn); + ds[nDSs].atime = sb.st_atime; + ++nDSs; + } } } - } - - statfs(".", &sf); - if( sf.f_bfree * 100 / sf.f_blocks <= LEAVE ){ - qsort(ds, nDSs, sizeof(DS), compar); - nDSs = nDSs * CLEAN / 100; - while( nDSs-- ){ - printf("%s\n", ds[nDSs].name); - unlink(ds[nDSs].name); + closedir(dirp); + + statfs(".", &sf); + if( sf.f_bfree * sf.f_bsize / 1024 <= leavespace ){ + qsort(ds, nDSs, sizeof(DS), compar); + nDSs = nDSs * clean / 100; + while( nDSs-- ){ + printf("%s\n", ds[nDSs].name); + unlink(ds[nDSs].name); + } } } return 0; -- cgit v1.2.3 From 74e118e03a98532467fb24159df6751e661c8412 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Wed, 24 Apr 2002 11:16:30 +0000 Subject: kcwu's patch git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@127 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/more.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pttbbs/mbbsd/more.c b/pttbbs/mbbsd/more.c index b0c57611..e072dac4 100644 --- a/pttbbs/mbbsd/more.c +++ b/pttbbs/mbbsd/more.c @@ -1,4 +1,4 @@ -/* $Id: more.c,v 1.9 2002/04/18 21:27:23 in2 Exp $ */ +/* $Id: more.c,v 1.10 2002/04/24 11:16:30 in2 Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -275,7 +275,7 @@ int more(char *fpath, int promptend) { prints("\033[47;34m %s \033[44;37m%-53.53s" "\033[47;34m %.4s \033[44;37m%-13s\033[m\n", head[0], word, ptr, ptr + 5); - } else if (pos < 4) + } else if (pos < line) prints("\033[47;34m %s \033[44;37m%-72.72s" "\033[m\n", head[pos], word); @@ -297,7 +297,7 @@ int more(char *fpath, int promptend) { header = 1; prints("\033[36m%s\033[m\n", msg_seperator); - line = pos = 4; + ++line; ++pos; } } lino = pos; -- cgit v1.2.3 From 6908394e32a3e4f98957e3229346d42251529437 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sat, 27 Apr 2002 15:50:20 +0000 Subject: for mbbsd.icc git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@128 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd.icc/.cvsignore | 2 ++ pttbbs/mbbsd.icc/Makefile | 51 +++++++++++++++++++++++++++++++++++++++++++++ pttbbs/mbbsd/dark.c | 40 +++++++++++++++++------------------ pttbbs/mbbsd/descrypt.c | 6 +++--- pttbbs/mbbsd/edit.c | 4 ++-- pttbbs/mbbsd/mbbsd.c | 6 +++--- pttbbs/mbbsd/more.c | 18 ++++++++-------- pttbbs/mbbsd/page.c | 34 +++++++++++++++--------------- pttbbs/mbbsd/screen.c | 10 ++++----- pttbbs/mbbsd/talk.c | 12 +++++------ pttbbs/mbbsd/user.c | 6 +++--- 11 files changed, 121 insertions(+), 68 deletions(-) create mode 100644 pttbbs/mbbsd.icc/.cvsignore create mode 100644 pttbbs/mbbsd.icc/Makefile diff --git a/pttbbs/mbbsd.icc/.cvsignore b/pttbbs/mbbsd.icc/.cvsignore new file mode 100644 index 00000000..0ffc7757 --- /dev/null +++ b/pttbbs/mbbsd.icc/.cvsignore @@ -0,0 +1,2 @@ +*.o +mbbsd.icc diff --git a/pttbbs/mbbsd.icc/Makefile b/pttbbs/mbbsd.icc/Makefile new file mode 100644 index 00000000..a87135cc --- /dev/null +++ b/pttbbs/mbbsd.icc/Makefile @@ -0,0 +1,51 @@ +.PATH: ../mbbsd + +BBSHOME=/home/bbs +PROG= mbbsd.icc +OBJS= admin.o announce.o args.o bbcall.o bbs.o board.o cache.o cal.o card.o\ + chat.o chc_draw.o chc_net.o chc_play.o chc_rule.o chicken.o dark.o\ + dice.o edit.o friend.o gamble.o gomo.o gomo1.o guess.o indict.o io.o\ + kaede.o lovepaper.o mail.o mbbsd.o menu.o more.o name.o osdep.o\ + othello.o page.o read.o record.o register.o screen.o stuff.o\ + talk.o term.o topsong.o user.o vice.o vote.o xyz.o\ + voteboard.o syspost.o var.o descrypt.o toolkit.o passwd.o\ + calendar.o + +CFLAGS= -O -DHAVE_SETPROCTITLE -DBBSHOME='"$(BBSHOME)"' -DFreeBSD -I../include -D__FreeBSD__ +LDFLAGS=-O -lutil -lkvm +GCCUSE=gcc -pipe -Wall -O -DHAVE_SETPROCTITLE -DBBSHOME='"/home/bbs"' -DFreeBSD -I../include -c + +.SUFFIXES: .c .o +.c.o: + iccbin $(CFLAGS) -c ../mbbsd/$*.c + +all: $(PROG) + +$(PROG): $(OBJS) + cc $(LDFLAGS) -o $(PROG) $(OBJS) + +install: $(PROG) + install -d $(BBSHOME)/bin/ + install -c -m 755 $(PROG) $(BBSHOME)/bin/ + rm -f $(BBSHOME)/bin/mbbsd + ln -sv $(BBSHOME)/bin/$(PROG) $(BBSHOME)/bin/mbbsd +cache.o: cache.c + $(GCCUSE) ../mbbsd/$*.c + +mail.o: mail.c + $(GCCUSE) ../mbbsd/$*.c + +menu.o: menu.c + $(GCCUSE) ../mbbsd/$*.c + +record.o: record.c + $(GCCUSE) ../mbbsd/$*.c + +topsong.o: topsong.c + $(GCCUSE) ../mbbsd/$*.c + +xyz.o: xyz.c + $(GCCUSE) ../mbbsd/$*.c + +clean: + rm -f $(OBJS) $(PROG) diff --git a/pttbbs/mbbsd/dark.c b/pttbbs/mbbsd/dark.c index 52741617..1b084407 100644 --- a/pttbbs/mbbsd/dark.c +++ b/pttbbs/mbbsd/dark.c @@ -1,4 +1,4 @@ -/* $Id: dark.c,v 1.1 2002/03/07 15:13:48 in2 Exp $ */ +/* $Id: dark.c,v 1.2 2002/04/27 15:50:17 in2 Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -113,17 +113,17 @@ static void brd_rand() { static void brd_prints() { clear(); move(1,0); - outs(" - ╭─┬─┬─┬─┬─┬─┬─┬─╮ - │●│●│●│●│●│●│●│●│ - ├─┼─┼─┼─┼─┼─┼─┼─┤ - │●│●│●│●│●│●│●│●│ - ├─┼─┼─┼─┼─┼─┼─┼─┤ - │●│●│●│●│●│●│●│●│ - ├─┼─┼─┼─┼─┼─┼─┼─┤ - │●│●│●│●│●│●│●│●│ - ╰─┴─┴─┴─┴─┴─┴─┴─╯ - "); + outs("\n" +" ╭─┬─┬─┬─┬─┬─┬─┬─╮\n" +" │●│●│●│●│●│●│●│●│\n" +" ├─┼─┼─┼─┼─┼─┼─┼─┤\n" +" │●│●│●│●│●│●│●│●│\n" +" ├─┼─┼─┼─┼─┼─┼─┼─┤\n" +" │●│●│●│●│●│●│●│●│\n" +" ├─┼─┼─┼─┼─┼─┼─┼─┤\n" +" │●│●│●│●│●│●│●│●│\n" +" ╰─┴─┴─┴─┴─┴─┴─┴─╯\n" +" "); } static void draw_line(sint y, sint f) { @@ -325,14 +325,14 @@ int main_dark(int fd,userinfo_t *uin) { } move(12,3); prints("%s[0勝0敗]vs.%s[0勝0敗]",currutmp->userid,currutmp->mateid); - outs(" - ╳╱功\能表╲╳╲╱╳╲ - ╱ ↑←↓→: 移動 - ╳ s:  選子,翻子 - ╱ enter:  吃棋,放棋 - 已經解決的:   ╳ p:  合棋 -    ╱ q:  認輸 - ╳ c:  換邊"); + outs("\n" +" ╳╱功\能表╲╳╲╱╳╲\n" +" ╱ ↑←↓→: 移動\n" +" ╳ s:  選子,翻子\n" +" ╱ enter:  吃棋,放棋\n" +" 已經解決的:   ╳ p:  合棋\n" +"    ╱ q:  認輸\n" +" ╳ c:  換邊"); if(currutmp->turn) move(cury[0],curx[0]); diff --git a/pttbbs/mbbsd/descrypt.c b/pttbbs/mbbsd/descrypt.c index 3bb0a5e5..1d246670 100644 --- a/pttbbs/mbbsd/descrypt.c +++ b/pttbbs/mbbsd/descrypt.c @@ -1,4 +1,4 @@ -/* $Id: descrypt.c,v 1.1 2002/03/07 15:13:48 in2 Exp $ */ +/* $Id: descrypt.c,v 1.2 2002/04/27 15:50:17 in2 Exp $ */ /* * FreeSec: libcrypt for NetBSD @@ -560,7 +560,7 @@ char *crypt(char *key, char *setting) { if((*q++ = *key << 1)) key++; } - if(des_setkey((unsigned char *)keybuf)) + if(des_setkey((char *)keybuf)) return NULL; /* @@ -611,6 +611,6 @@ char *crypt(char *key, char *setting) { *p++ = ascii64[l & 0x3f]; *p = 0; - return output; + return (char *)output; } #endif diff --git a/pttbbs/mbbsd/edit.c b/pttbbs/mbbsd/edit.c index 8072de6d..0b372209 100644 --- a/pttbbs/mbbsd/edit.c +++ b/pttbbs/mbbsd/edit.c @@ -1,4 +1,4 @@ -/* $Id: edit.c,v 1.3 2002/04/16 15:27:40 in2 Exp $ */ +/* $Id: edit.c,v 1.4 2002/04/27 15:50:17 in2 Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -860,7 +860,7 @@ void addsignature(FILE *fp, int ifuseanony) { fprintf(fp, "\n--\n※ 發信站: " BBSNAME "(" MYHOSTNAME ") \n◆ From: %s\n", "暱名天使的家"); else { - char temp[32]; + char temp[33]; strncpy(temp, fromhost, 31); temp[32] = '\0'; diff --git a/pttbbs/mbbsd/mbbsd.c b/pttbbs/mbbsd/mbbsd.c index 3f2b68e7..49915683 100644 --- a/pttbbs/mbbsd/mbbsd.c +++ b/pttbbs/mbbsd/mbbsd.c @@ -1,4 +1,4 @@ -/* $Id: mbbsd.c,v 1.21 2002/04/15 20:00:22 in2 Exp $ */ +/* $Id: mbbsd.c,v 1.22 2002/04/27 15:50:17 in2 Exp $ */ #include <stdio.h> #include <string.h> #include <stdlib.h> @@ -288,7 +288,7 @@ dosearchuser (char *userid) } static void -talk_request () +talk_request(int sig) { bell (); bell (); @@ -1351,7 +1351,7 @@ daemon_login (int argc, char *argv[], char *envp[]) /* main loop */ for(;;) { len_of_sock_addr = sizeof(xsin); - csock = accept(msock, (struct sockaddr *)&xsin, &len_of_sock_addr); + csock = accept(msock, (struct sockaddr *)&xsin, (socklen_t *)&len_of_sock_addr); if(csock < 0) { if(errno!=EINTR) sleep(1); diff --git a/pttbbs/mbbsd/more.c b/pttbbs/mbbsd/more.c index e072dac4..7440ecc4 100644 --- a/pttbbs/mbbsd/more.c +++ b/pttbbs/mbbsd/more.c @@ -1,4 +1,4 @@ -/* $Id: more.c,v 1.10 2002/04/24 11:16:30 in2 Exp $ */ +/* $Id: more.c,v 1.11 2002/04/27 15:50:17 in2 Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -119,9 +119,9 @@ more_readln (int fd, unsigned char *buf) } else if (ch == '\033') { - if (atoi (data + 1) > 47) + if (atoi ((char *)(data + 1)) > 47) { - if ((cc = strchr (data + 1, 'm')) != NULL) + if ((cc = (unsigned char *)strchr ((char *)(data + 1), 'm')) != NULL) { ch = cc - data + 1; @@ -251,7 +251,7 @@ int more(char *fpath, int promptend) { more_base = more_head = more_size = 0; - while((numbytes = more_readln(fd, buf)) || (line == t_lines)) { + while((numbytes = more_readln(fd, (unsigned char *)buf)) || (line == t_lines)) { if(scrollup) { rscroll(); move(0, 0); @@ -280,7 +280,7 @@ int more(char *fpath, int promptend) { "\033[m\n", head[pos], word); viewed += numbytes; - numbytes = more_readln(fd, buf); + numbytes = more_readln(fd, (unsigned char *)buf); /* 第一行太長了 */ if(!pos && viewed > 79) { @@ -288,7 +288,7 @@ int more(char *fpath, int promptend) { if(memcmp( buf, head[1], 2)) { /* 讀下一行進來處理 */ viewed += numbytes; - numbytes = more_readln(fd, buf); + numbytes = more_readln(fd, (unsigned char *)buf); } } pos++; @@ -390,7 +390,7 @@ int more(char *fpath, int promptend) { move(line = b_lines, 0); clrtoeol(); for(pos = 1; pos < b_lines; pos++) - viewed += more_readln(fd, buf); + viewed += more_readln(fd, (unsigned char *)buf); } else if(pos == b_lines) /* 捲動螢幕 */ scroll(); else @@ -693,13 +693,13 @@ int more(char *fpath, int promptend) { scrollup = lino - 1; more_goto(fd, viewed = pagebreak[pageno - 1]); while(line--) - viewed += more_readln(fd, buf); + viewed += more_readln(fd, (unsigned char *)buf); } else if(pageno > 1) { scrollup = b_lines - 1; line = (b_lines - 2) - local; more_goto(fd, viewed = pagebreak[--pageno - 1]); while(line--) - viewed += more_readln(fd, buf); + viewed += more_readln(fd, (unsigned char *)buf); } line = pos = 0; } else { diff --git a/pttbbs/mbbsd/page.c b/pttbbs/mbbsd/page.c index c77ef421..33201bfc 100644 --- a/pttbbs/mbbsd/page.c +++ b/pttbbs/mbbsd/page.c @@ -1,4 +1,4 @@ -/* $Id: page.c,v 1.1 2002/03/07 15:13:48 in2 Exp $ */ +/* $Id: page.c,v 1.2 2002/04/27 15:50:17 in2 Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -59,22 +59,22 @@ int main_railway() { move(0,25); prints("\033[1;37;45m 火車查詢系統 \033[1;44;33m作者:Heat\033[m"); move(1,0); - outs("\033[1;33m - 1.基隆 16.中壢 31.龍港 46.銅鑼 61.田中 76.林鳳營 91.高雄 - 2.八堵 17.埔心 32.白沙屯 47.三義 62.二水 77.隆田 92.鳳山 - 3.七堵 18.楊梅 33.新埔 48.勝興 63.林內 78.拔林 93.九曲堂 - 4.五堵 19.湖口 34.通霄 49.泰安 64.石榴 79.善化 94.屏東 - 5.汐止 20.新豐 35.苑裡 50.后里 65.斗六 80.新市 - 6.南港 21.竹北 36.日南 51.豐原 66.斗南 81.永康 - 7.松山 22.新竹 37.大甲 52.潭子 67.石龜 82.台南 - 8.台北 23.香山 38.臺中港 53.台中 68.大林 83.保安 - 9.萬華 24.崎頂 39.清水 54.烏日 69.民雄 84.中洲 -10.板橋 25.竹南 40.沙鹿 55.成功\ 70.嘉義 85.大湖 -11.樹林 26.造橋 41.龍井 56.彰化 71.水上 86.路竹 -12.山佳 27.豐富 42.大肚 57.花壇 72.南靖 87.岡山 -13.鶯歌 28.談文 43.追分 58.員林 73.後壁 88.橋頭 -14.桃園 29.大山 44.苗栗 59.永靖 74.新營 89.楠梓 -15.內壢 30.後龍 45.南勢 60.社頭 75.柳營 90.左營\033[m"); + outs("\033[1;33m\n" +" 1.基隆 16.中壢 31.龍港 46.銅鑼 61.田中 76.林鳳營 91.高雄\n" +" 2.八堵 17.埔心 32.白沙屯 47.三義 62.二水 77.隆田 92.鳳山\n" +" 3.七堵 18.楊梅 33.新埔 48.勝興 63.林內 78.拔林 93.九曲堂\n" +" 4.五堵 19.湖口 34.通霄 49.泰安 64.石榴 79.善化 94.屏東\n" +" 5.汐止 20.新豐 35.苑裡 50.后里 65.斗六 80.新市\n" +" 6.南港 21.竹北 36.日南 51.豐原 66.斗南 81.永康\n" +" 7.松山 22.新竹 37.大甲 52.潭子 67.石龜 82.台南\n" +" 8.台北 23.香山 38.臺中港 53.台中 68.大林 83.保安\n" +" 9.萬華 24.崎頂 39.清水 54.烏日 69.民雄 84.中洲\n" +"10.板橋 25.竹南 40.沙鹿 55.成功\ 70.嘉義 85.大湖\n" +"11.樹林 26.造橋 41.龍井 56.彰化 71.水上 86.路竹\n" +"12.山佳 27.豐富 42.大肚 57.花壇 72.南靖 87.岡山\n" +"13.鶯歌 28.談文 43.追分 58.員林 73.後壁 88.橋頭\n" +"14.桃園 29.大山 44.苗栗 59.永靖 74.新營 89.楠梓\n" +"15.內壢 30.後龍 45.南勢 60.社頭 75.柳營 90.左營\033[m"); getdata(17, 0, "\033[1;35m你確定要搜尋嗎?[y/n]:\033[m", buf, 2, LCECHO); if(buf[0] != 'y' && buf[0] != 'Y') diff --git a/pttbbs/mbbsd/screen.c b/pttbbs/mbbsd/screen.c index 46ad5b38..2c70917f 100644 --- a/pttbbs/mbbsd/screen.c +++ b/pttbbs/mbbsd/screen.c @@ -1,4 +1,4 @@ -/* $Id: screen.c,v 1.1 2002/03/07 15:13:48 in2 Exp $ */ +/* $Id: screen.c,v 1.2 2002/04/27 15:50:17 in2 Exp $ */ #include <stdio.h> #include <string.h> #include <stdlib.h> @@ -131,9 +131,9 @@ void redoscr() { if((len = bp->len)) { rel_move(tc_col, tc_line, 0, i); if(bp->mode & STANDOUT) - standoutput(bp->data, 0, len, bp->sso, bp->eso); + standoutput((char *)bp->data, 0, len, bp->sso, bp->eso); else - output(bp->data, len); + output((char *)bp->data, len); tc_col += len; if(tc_col >= t_columns) { if (automargins) @@ -195,10 +195,10 @@ void refresh() { rel_move(tc_col, tc_line, bp->smod, i); if(bp->mode & STANDOUT) - standoutput(bp->data, bp->smod, bp->emod + 1, + standoutput((char *)bp->data, bp->smod, bp->emod + 1, bp->sso, bp->eso); else - output(&bp->data[bp->smod], bp->emod - bp->smod + 1); + output((char *)&bp->data[bp->smod], bp->emod - bp->smod + 1); tc_col = bp->emod + 1; if(tc_col >= t_columns) { if(automargins) { diff --git a/pttbbs/mbbsd/talk.c b/pttbbs/mbbsd/talk.c index facab4b4..73fdbc43 100644 --- a/pttbbs/mbbsd/talk.c +++ b/pttbbs/mbbsd/talk.c @@ -1,4 +1,4 @@ -/* $Id: talk.c,v 1.21 2002/04/10 10:49:42 in2 Exp $ */ +/* $Id: talk.c,v 1.22 2002/04/27 15:50:17 in2 Exp $ */ #include <stdio.h> #include <string.h> #include <errno.h> @@ -954,13 +954,13 @@ static void do_talk_char(talkwin_t * twin, int ch) case Ctrl('M'): case Ctrl('J'): line = big_picture + twin->curln; - strncpy(buf, line->data, line->len); + strncpy(buf, (char *)line->data, line->len); buf[line->len] = 0; do_talk_nextline(twin); break; case Ctrl('P'): line = big_picture + twin->curln; - strncpy(buf, line->data, line->len); + strncpy(buf, (char *)line->data, line->len); buf[line->len] = 0; if (twin->curln > twin->sline){ --(twin->curln); @@ -969,7 +969,7 @@ static void do_talk_char(talkwin_t * twin, int ch) break; case Ctrl('N'): line = big_picture + twin->curln; - strncpy(buf, line->data, line->len); + strncpy(buf, (char *)line->data, line->len); buf[line->len] = 0; if (twin->curln < twin->eline){ ++(twin->curln); @@ -1230,7 +1230,7 @@ static void my_talk(userinfo_t * uin, int fri_stat) { return; } length = sizeof(server); - if (getsockname(sock, (struct sockaddr *) &server, &length) < 0){ + if (getsockname(sock, (struct sockaddr *) &server, (socklen_t*)&length) < 0){ close(sock); perror("sock name err"); unlockutmpmode(); @@ -1305,7 +1305,7 @@ static void my_talk(userinfo_t * uin, int fri_stat) { } } - msgsock = accept(sock, (struct sockaddr *) 0, (int *) 0); + msgsock = accept(sock, (struct sockaddr *) 0, (socklen_t *) 0); if (msgsock == -1){ perror("accept"); unlockutmpmode(); diff --git a/pttbbs/mbbsd/user.c b/pttbbs/mbbsd/user.c index 2e2e3401..55719a4a 100644 --- a/pttbbs/mbbsd/user.c +++ b/pttbbs/mbbsd/user.c @@ -1,4 +1,4 @@ -/* $Id: user.c,v 1.13 2002/04/05 18:49:47 in2 Exp $ */ +/* $Id: user.c,v 1.14 2002/04/27 15:50:17 in2 Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -319,7 +319,7 @@ void uinfo_query(userec_t *u, int real, int unum) { if(HAS_PERM(PERM_BBSADM)) { sprintf(genbuf, "%d", x.money); if(getdata_str(i++, 0,"銀行帳戶:", buf, 10, DOECHO,genbuf)) - if((l = atol(buf)) >= 0) { + if((l = atol(buf)) != 0) { if(l != x.money) { money_change = 1; money = x.money; @@ -329,7 +329,7 @@ void uinfo_query(userec_t *u, int real, int unum) { } sprintf(genbuf, "%d", x.exmailbox); if(getdata_str(i++, 0,"購買信箱數:", buf, 4, DOECHO,genbuf)) - if((l = atol(buf)) >= 0) + if((l = atol(buf)) != 0) x.exmailbox = (int)l; getdata_buf(i++, 0, "認證資料:", x.justify, 44, DOECHO); -- cgit v1.2.3 From 2b3fff19f8697669cedeb9d1b3a090a63da68335 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sun, 28 Apr 2002 14:29:26 +0000 Subject: DEBUG git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@129 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/Makefile | 26 +++++++++++++++++++------- pttbbs/mbbsd/mbbsd.c | 14 +++++++++++--- 2 files changed, 30 insertions(+), 10 deletions(-) diff --git a/pttbbs/mbbsd/Makefile b/pttbbs/mbbsd/Makefile index 4169ccb6..531488a4 100644 --- a/pttbbs/mbbsd/Makefile +++ b/pttbbs/mbbsd/Makefile @@ -1,22 +1,34 @@ -# $Id: Makefile,v 1.5 2002/04/10 10:51:24 in2 Exp $ +# $Id: Makefile,v 1.6 2002/04/28 14:29:26 in2 Exp $ BBSHOME?=$(HOME) OSTYPE=FreeBSD # FreeBSD -CFLAGS_FreeBSD= -pipe -Wall -g -O -DHAVE_SETPROCTITLE -DBBSHOME='"$(BBSHOME)"' -DFreeBSD -I../include -LDFLAGS_FreeBSD=-pipe -Wall -g -O +CFLAGS_FreeBSD= -pipe -Wall -DHAVE_SETPROCTITLE -DBBSHOME='"$(BBSHOME)"' -DFreeBSD -I../include +LDFLAGS_FreeBSD=-pipe -Wall LIBS_FreeBSD= -lutil -lkvm # Linux -CFLAGS_linux= -pipe -Wall -g -O -DHAVE_DES_CRYPT -DBBSHOME='"$(BBSHOME)"' -DLinux -I../include -s -LDFLAGS_linux= -pipe -Wall -g -O +CFLAGS_linux= -pipe -Wall -DHAVE_DES_CRYPT -DBBSHOME='"$(BBSHOME)"' -DLinux -I../include -s +LDFLAGS_linux= -pipe -Wall LIBS_linux= -lcrypt CFLAGS= $(CFLAGS_$(OSTYPE)) LDFLAGS=$(LDFLAGS_$(OSTYPE)) LIBS= $(LIBS_$(OSTYPE)) +.if defined(DEBUG) +CFLAGS+= -g -DDEBUG +LDFLAGS+= -g -DDEBUG +.else +CFLAGS+= -O +LDFLAGS+= -O +.endif + +.if defined(NO_FORK) +CFLAGS+= -DNO_FORK +.endif + CC= gcc PROG= mbbsd OBJS= admin.o announce.o args.o bbcall.o bbs.o board.o cache.o cal.o card.o\ @@ -30,12 +42,12 @@ OBJS= admin.o announce.o args.o bbcall.o bbs.o board.o cache.o cal.o card.o\ .SUFFIXES: .c .o .c.o: - $(CC) $(CFLAGS) -c $*.c + $(CC) $(ADDFLAGS) $(CFLAGS) -c $*.c all: $(PROG) $(PROG): $(OBJS) - $(CC) $(LDFLAGS) -o $(PROG) $(OBJS) $(LIBS) + $(CC) $(ADDFLAGS) $(LDFLAGS) -o $(PROG) $(OBJS) $(LIBS) test: $(PROG) killall -9 testmbbsd || true diff --git a/pttbbs/mbbsd/mbbsd.c b/pttbbs/mbbsd/mbbsd.c index 49915683..e7a2f84d 100644 --- a/pttbbs/mbbsd/mbbsd.c +++ b/pttbbs/mbbsd/mbbsd.c @@ -1,4 +1,4 @@ -/* $Id: mbbsd.c,v 1.22 2002/04/27 15:50:17 in2 Exp $ */ +/* $Id: mbbsd.c,v 1.23 2002/04/28 14:29:26 in2 Exp $ */ #include <stdio.h> #include <string.h> #include <stdlib.h> @@ -88,10 +88,12 @@ start_daemon () struct tm *dummy_time = localtime (&dummy); strftime (buf, 80, "%d/%b/%Y:%H:%M:%S", dummy_time); - + +#ifndef NO_FORK if ((n = fork ())){ exit (0); } +#endif /* rocker.011018: it's a good idea to close all unexcept fd!! */ n = getdtablesize (); @@ -103,9 +105,11 @@ start_daemon () /* rocker.011018: after new session, we should insure the process is clean daemon */ +#ifndef NO_FORK if ((n = fork ())){ exit (0); } +#endif } static void @@ -1363,11 +1367,15 @@ daemon_login (int argc, char *argv[], char *envp[]) close(csock); continue; } - + +#ifdef NO_FORK + break; +#else if(fork()==0) break; else close(csock); +#endif } /* here is only child running */ -- cgit v1.2.3 From c538e4e1e37295ef7aabfd5a4fd7de543decfb32 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sun, 28 Apr 2002 19:35:20 +0000 Subject: add UPDATING git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@130 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/UPDATING | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 pttbbs/UPDATING diff --git a/pttbbs/UPDATING b/pttbbs/UPDATING new file mode 100644 index 00000000..a5858a03 --- /dev/null +++ b/pttbbs/UPDATING @@ -0,0 +1,3 @@ +Mon Apr 29 03:33:38 CST 2002: + change getdata() constant to sizeof() + -- cgit v1.2.3 From 14be7f394cb526a9793f69db4bcffff58aff3a1f Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sun, 28 Apr 2002 19:35:29 +0000 Subject: change getdata() constant to sizeof() git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@131 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/admin.c | 33 +++++++++++++++--------------- pttbbs/mbbsd/announce.c | 30 ++++++++++++++-------------- pttbbs/mbbsd/bbcall.c | 16 +++++++-------- pttbbs/mbbsd/bbs.c | 24 ++++++++++++---------- pttbbs/mbbsd/board.c | 5 +++-- pttbbs/mbbsd/cache.c | 3 +-- pttbbs/mbbsd/cal.c | 29 ++++++++++++++------------- pttbbs/mbbsd/card.c | 6 +++--- pttbbs/mbbsd/chat.c | 4 ++-- pttbbs/mbbsd/chicken.c | 12 ++++++----- pttbbs/mbbsd/dice.c | 4 ++-- pttbbs/mbbsd/edit.c | 35 +++++++++++++++++--------------- pttbbs/mbbsd/friend.c | 9 +++++---- pttbbs/mbbsd/gomo.c | 6 +++--- pttbbs/mbbsd/guess.c | 29 ++++++++++++++------------- pttbbs/mbbsd/indict.c | 4 ++-- pttbbs/mbbsd/io.c | 6 +++--- pttbbs/mbbsd/lovepaper.c | 7 ++++--- pttbbs/mbbsd/mail.c | 20 +++++++++---------- pttbbs/mbbsd/mbbsd.c | 6 +++--- pttbbs/mbbsd/more.c | 4 ++-- pttbbs/mbbsd/othello.c | 5 +++-- pttbbs/mbbsd/page.c | 4 ++-- pttbbs/mbbsd/read.c | 4 ++-- pttbbs/mbbsd/register.c | 26 ++++++++++++++---------- pttbbs/mbbsd/syspost.c | 4 ++-- pttbbs/mbbsd/talk.c | 30 +++++++++++++++------------- pttbbs/mbbsd/user.c | 52 +++++++++++++++++++++++++++++------------------- pttbbs/mbbsd/vice.c | 5 +++-- pttbbs/mbbsd/vote.c | 12 ++++++----- pttbbs/mbbsd/voteboard.c | 7 ++++--- pttbbs/mbbsd/xyz.c | 10 ++++++---- 32 files changed, 244 insertions(+), 207 deletions(-) diff --git a/pttbbs/mbbsd/admin.c b/pttbbs/mbbsd/admin.c index 61509ba6..2d66bfe4 100644 --- a/pttbbs/mbbsd/admin.c +++ b/pttbbs/mbbsd/admin.c @@ -1,4 +1,4 @@ -/* $Id: admin.c,v 1.6 2002/03/17 17:06:54 in2 Exp $ */ +/* $Id: admin.c,v 1.7 2002/04/28 19:35:28 in2 Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -53,7 +53,7 @@ static int search_key_user(char *passwdfile, int mode) { clear(); getdata(0, 0, mode ? "請輸入使用者關鍵字[電話|地址|姓名|上站地點|" - "email|小雞id] :" : "請輸入id :", key, 21, DOECHO); + "email|小雞id] :" : "請輸入id :", key, sizeof(key), DOECHO); while((fread(&user, sizeof(user), 1, fp1)) > 0 && coun < MAX_USERS) { if(!(++coun & 15)) { move(1, 0); @@ -184,7 +184,7 @@ unsigned int setperms(unsigned int pbits, char *pstring[]) { } clrtobot(); while(getdata(b_lines - 1, 0, "請按 [A-5] 切換設定,按 [Return] 結束:", - choice, 3, LCECHO)) { + choice, sizeof(choice), LCECHO)) { i = choice[0] - 'a'; if(i < 0) i = choice[0] - '0' + 26; @@ -234,7 +234,7 @@ int m_mod_board(char *bname) { sprintf(genbuf, "看板 (E)設定 (V)違法/解除 %s (D)刪除 [Q]取消?", HAS_PERM(PERM_SYSOP) ? " (B)BVote (S)救回文章" : ""); - getdata(10, 0, genbuf, ans, 3, LCECHO); + getdata(10, 0, genbuf, ans, sizeof(ans), LCECHO); switch(*ans) { case 's': @@ -350,9 +350,9 @@ int m_mod_board(char *bname) { strncpy(newbh.title + 5, "●", 2); if(HAS_PERM(PERM_SYSOP) && !(newbh.brdattr & BRD_HIDE)) { - getdata_str(14, 0, "設定讀寫權限(Y/N)?", ans, 4, LCECHO, "N"); + getdata_str(14, 0, "設定讀寫權限(Y/N)?", ans, sizeof(ans), LCECHO, "N"); if(*ans == 'y') { - getdata_str(15, 0, "限制 [R]閱\讀 (P)發表?", ans, 4, LCECHO, + getdata_str(15, 0, "限制 [R]閱\讀 (P)發表?", ans, sizeof(ans), LCECHO, "R"); if(*ans == 'p') newbh.brdattr |= BRD_POSTMASK; @@ -419,7 +419,7 @@ int x_file() { "(X)刪除進站畫面" #endif "\n"); - getdata(b_lines - 1, 0, " (H)看板期限 (I)故鄉 (J)出站畫面 (K)生日卡 (L)節日 [Q]取消?", ans, 3, LCECHO); + getdata(b_lines - 1, 0, " (H)看板期限 (I)故鄉 (J)出站畫面 (K)生日卡 (L)節日 [Q]取消?", ans, sizeof(ans), LCECHO); switch(ans[0]) { case '1': @@ -463,7 +463,7 @@ int x_file() { break; case 'g': #ifdef MULTI_WELCOME_LOGIN - getdata(b_lines - 1, 0, "第幾個進站畫面[0-4]", ans, 3, LCECHO); + getdata(b_lines - 1, 0, "第幾個進站畫面[0-4]", ans, sizeof(ans), LCECHO); if( ans[0] == '1' ) { fpath = "etc/Welcome_login.1"; } else if( ans[0] == '2' ){ fpath = "etc/Welcome_login.2"; } else if( ans[0] == '3' ){ fpath = "etc/Welcome_login.3"; } @@ -476,7 +476,7 @@ int x_file() { #ifdef MULTI_WELCOME_LOGIN case 'x': - getdata(b_lines - 1, 0, "第幾個進站畫面[1-4]", ans, 3, LCECHO); + getdata(b_lines - 1, 0, "第幾個進站畫面[1-4]", ans, sizeof(ans), LCECHO); if( ans[0] == '1' ) { unlink("etc/Welcome_login.1"); outs("ok"); } else if( ans[0] == '2' ){ unlink("etc/Welcome_login.2"); outs("ok"); } else if( ans[0] == '3' ){ unlink("etc/Welcome_login.3"); outs("ok"); } @@ -533,7 +533,8 @@ int m_newbrd(int recover) { } do { - if(!getdata(3, 0, msg_bid, newboard.brdname, IDLEN + 1, DOECHO)) + if(!getdata(3, 0, msg_bid, newboard.brdname, + sizeof(newboard.brdname), DOECHO)) return -1; } while(invalid_brdname(newboard.brdname)); @@ -588,12 +589,12 @@ int m_newbrd(int recover) { strncpy(newboard.title + 5, "●", 2); newboard.level = 0; - getdata(11, 0, "板主名單:", newboard.BM, IDLEN * 3 + 3, DOECHO); + getdata(11, 0, "板主名單:", newboard.BM, sizeof(newboard.BM), DOECHO); if(HAS_PERM(PERM_SYSOP) && !(newboard.brdattr & BRD_HIDE)) { - getdata_str(14, 0, "設定讀寫權限(Y/N)?", ans, 3, LCECHO, "N"); + getdata_str(14, 0, "設定讀寫權限(Y/N)?", ans, sizeof(ans), LCECHO, "N"); if(*ans == 'y') { - getdata_str(15, 0, "限制 [R]閱\讀 (P)發表?", ans, 4, LCECHO, "R"); + getdata_str(15, 0, "限制 [R]閱\讀 (P)發表?", ans, sizeof(ans), LCECHO, "R"); if(*ans == 'p') newboard.brdattr |= BRD_POSTMASK; else @@ -808,7 +809,7 @@ int scan_register_form(char *regfile, int automode, int neednum) { } if(muser.userlevel & PERM_LOGINOK) { getdata(b_lines - 1, 0, "\033[1;32m此帳號已經完成註冊, " - "更新(Y/N/Skip)?\033[m[N] ", ans, 3, LCECHO); + "更新(Y/N/Skip)?\033[m[N] ", ans, sizeof(ans), LCECHO); if(ans[0] != 'y' && ans[0] != 's') ans[0] = 'd'; } else { @@ -1004,7 +1005,7 @@ int m_register() { } } fclose(fn); - getdata(b_lines - 1, 0, "開始審核嗎(Auto/Yes/No)?[N] ", ans, 3, LCECHO); + getdata(b_lines - 1, 0, "開始審核嗎(Auto/Yes/No)?[N] ", ans, sizeof(ans), LCECHO); if(ans[0] == 'a') scan_register_form(fn_register, 1, 0); else if(ans[0] == 'y') @@ -1046,7 +1047,7 @@ int give_money() { struct tm *pt = localtime(&t); int to_all = 0, money = 0; - getdata(0, 0, "指定使用者(S) 全站使用者(A) 取消(Q)?[S]", buf, 3, LCECHO); + getdata(0, 0, "指定使用者(S) 全站使用者(A) 取消(Q)?[S]", buf, sizeof(buf), LCECHO); if(buf[0] == 'q') return 1; else if( buf[0] == 'a') { diff --git a/pttbbs/mbbsd/announce.c b/pttbbs/mbbsd/announce.c index 280306dc..5920e45e 100644 --- a/pttbbs/mbbsd/announce.c +++ b/pttbbs/mbbsd/announce.c @@ -1,4 +1,4 @@ -/* $Id: announce.c,v 1.4 2002/04/15 20:00:22 in2 Exp $ */ +/* $Id: announce.c,v 1.5 2002/04/28 19:35:28 in2 Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -287,7 +287,7 @@ static int g_searchtitle(gmenu_t* pm, int rev) { static char search_str[30] = ""; int pos; - if(getdata(b_lines - 1, 1,"[搜尋]關鍵字:", search_str, 40, DOECHO)) + if(getdata(b_lines - 1, 1,"[搜尋]關鍵字:", search_str, sizeof(search_str), DOECHO)) if(!*search_str) return pm->now; @@ -438,7 +438,7 @@ static int a_searchtitle(menu_t *pm, int rev) { static char search_str[40] = ""; int pos; - getdata(b_lines - 1, 1, "[搜尋]關鍵字:", search_str, 40, DOECHO); + getdata(b_lines - 1, 1, "[搜尋]關鍵字:", search_str, sizeof(search_str), DOECHO); if(!*search_str) return pm->now; @@ -893,7 +893,7 @@ static void a_pasteitem(menu_t *pm, int mode) { } if(mode) { sprintf(buf, "確定要拷貝[%s]嗎(Y/N)?[N] ", copytitle); - getdata(b_lines - 1, 1, buf, ans, 3, LCECHO); + getdata(b_lines - 1, 1, buf, ans, sizeof(ans), LCECHO); } else ans[0]='y'; if(ans[0] == 'y') { @@ -959,7 +959,7 @@ static void a_appenditem(menu_t *pm, int isask) { if(isask) { sprintf(buf, "確定要將[%s]附加於此嗎(Y/N)?[N] ", copytitle); - getdata(b_lines - 2, 1, buf, ans, 3, LCECHO); + getdata(b_lines - 2, 1, buf, ans, sizeof(ans), LCECHO); } if(ans[0] == 'y') { if((fp = fopen(fname, "a+"))) { @@ -970,7 +970,7 @@ static void a_appenditem(menu_t *pm, int isask) { if(isask) getdata(b_lines - 1, 1, "是否收錄簽名檔部份(Y/N)?[Y] ", - ans, 3, LCECHO); + ans, sizeof(ans), LCECHO); while(fgets(buf, sizeof(buf), fin)) { if((ans[0] == 'n' ) && !strcmp(buf, "--\n")) @@ -1044,7 +1044,7 @@ static void a_moveitem(menu_t *pm) { int fail; sprintf(buf, "請輸入第 %d 選項的新次序:", pm->now + 1); - if(!getdata(b_lines - 1, 1, buf, newnum, 6, DOECHO)) + if(!getdata(b_lines - 1, 1, buf, newnum, sizeof(newnum), DOECHO)) return; num = (newnum[0] == '$') ? 9999 : atoi(newnum) - 1; if(num >= pm->num) @@ -1095,22 +1095,22 @@ static void a_delete(menu_t *pm) { if(pm->header[pm->now - pm->page].filename[0] == 'H' && pm->header[pm->now - pm->page].filename[1] == '.') { getdata(b_lines - 1, 1, "您確定要刪除此精華區連線嗎(Y/N)?[N] ", - ans, 3, LCECHO); + ans, sizeof(ans), LCECHO); if(ans[0] != 'y') return; if(delete_record(buf, FHSZ, pm->now + 1) == -1) return; } else if (dashl(fpath)) { getdata(b_lines - 1, 1, "您確定要刪除此 symbolic link 嗎(Y/N)?[N] ", - ans, 3, LCECHO); + ans, sizeof(ans), LCECHO); if(ans[0] != 'y') return; if(delete_record(buf, FHSZ, pm->now + 1) == -1) return; unlink(fpath); } else if(dashf(fpath)) { - getdata(b_lines - 1, 1, "您確定要刪除此檔案嗎(Y/N)?[N] ", ans, 3, - LCECHO); + getdata(b_lines - 1, 1, "您確定要刪除此檔案嗎(Y/N)?[N] ", ans, + sizeof(ans), LCECHO); if(ans[0] != 'y') return; if(delete_record(buf, FHSZ, pm->now + 1) == -1) @@ -1127,8 +1127,8 @@ static void a_delete(menu_t *pm) { setbdir(buf, "deleted"); append_record(buf, &backup, sizeof(backup)); } else if (dashd(fpath)) { - getdata(b_lines - 1, 1, "您確定要刪除整個目錄嗎(Y/N)?[N] ", ans, 3, - LCECHO); + getdata(b_lines - 1, 1, "您確定要刪除整個目錄嗎(Y/N)?[N] ", ans, + sizeof(ans), LCECHO); if(ans[0] != 'y') return; if(delete_record(buf, FHSZ, pm->now + 1) == -1) @@ -1147,7 +1147,7 @@ static void a_delete(menu_t *pm) { append_record(buf, &backup, sizeof(backup)); } else { /* Ptt 損毀的項目 */ getdata(b_lines - 1, 1, "您確定要刪除此損毀的項目嗎(Y/N)?[N] ", - ans, 3, LCECHO); + ans, sizeof(ans), LCECHO); if(ans[0] != 'y') return; if(delete_record(buf, FHSZ, pm->now + 1) == -1) @@ -1438,7 +1438,7 @@ int a_menu(char *maintitle, char *path, int lastlevel) { currstat == EDITEXP ? "要把範例 Plugin 到文章嗎?[y/N]": "確定要點這首歌嗎?[y/N]", - ans, 3, LCECHO); + ans, sizeof(ans), LCECHO); if(ans[0]=='y') { strcpy(trans_buffer,fname); Fexit = 1; diff --git a/pttbbs/mbbsd/bbcall.c b/pttbbs/mbbsd/bbcall.c index d7b2d33b..8fdc56d2 100644 --- a/pttbbs/mbbsd/bbcall.c +++ b/pttbbs/mbbsd/bbcall.c @@ -1,4 +1,4 @@ -/* $Id: bbcall.c,v 1.1 2002/03/07 15:13:48 in2 Exp $ */ +/* $Id: bbcall.c,v 1.2 2002/04/28 19:35:28 in2 Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -150,14 +150,14 @@ static void halpha0943(char* CoId) { int Year = 99, Month = 1, Day = 15, Hour = 13, Minute = 8; sprintf(tmpbuf, "\033[1;37m請輸入您要傳呼的號碼\033[m : %s-", CoId); - if(!getdata(7,0, tmpbuf, ID, 7, LCECHO) || + if(!getdata(7,0, tmpbuf, ID, sizeof(ID), LCECHO) || !getdata(8,0, "\033[1;37m請輸入傳呼訊息\033[m:", tmpbuf, 63, LCECHO)) { hpressanykey("放棄傳呼"); return; } pager_msg_encode(Msg,tmpbuf); getdata(9, 0, "\033[1;37m如果你要馬上送請按 '1' " - "如果要定時送請按 '2': \033[m", ans, 2, LCECHO); + "如果要定時送請按 '2': \033[m", ans, sizeof(ans), LCECHO); if(ans[0] != '1') gettime(0, &Year, &Month, &Day, &Hour, &Minute); @@ -179,14 +179,14 @@ static void hcall0941() { int year = 98, month = 12, day = 4, hour = 13, min = 8; if(!getdata(7, 0, "\033[1;37 請您輸入您要傳呼的號碼 : 0941- \033[m", - PAGER_NO, 7, LCECHO) || + PAGER_NO, sizeof(PAGER_NO), LCECHO) || !getdata(8, 0, "\033[1;37m請輸入傳呼訊息\033[m:", trn, 17, LCECHO)) { hpressanykey("放棄傳呼"); return; } pager_msg_encode(TRAN_MSG,trn); getdata(9,0, "\033[1;37m如果你要馬上送請按 '1' " - "如果要定時送請按 '2': \033[m", ans, 2, LCECHO); + "如果要定時送請按 '2': \033[m", ans, sizeof(ans), LCECHO); if(ans[0] != '1') { strcpy(TIME,"DELAY"); gettime(0, &year, &month, &day, &hour, &min); @@ -212,14 +212,14 @@ static void hcall0948() { clrtoeol(); if(!getdata(7, 0, "\033[1;37m請輸入您要傳呼的號碼\033[m:0948-", - svc_no, 7, LCECHO) || + svc_no, sizeof(svc_no), LCECHO) || !getdata(8, 0, "\033[1;37m請輸入傳呼訊息\033[m:", trn, 61, LCECHO)) { hpressanykey("放棄傳呼"); return; } pager_msg_encode(message, trn); getdata(9, 0, "\033[1;37m如果你要馬上送請按 '1' " - "如果要定時送請按 '2'\033[m: ", ans, 2, LCECHO); + "如果要定時送請按 '2'\033[m: ", ans, sizeof(ans), LCECHO); if(ans[0] != '1') { gettime(1, &year, &month, &day, &hour, &min); ya = 1; @@ -248,7 +248,7 @@ int main_bbcall() { " (4)0948 \033[m\n"); prints("\033[1;31m └────────────────────" "─────────┘\033[m\n"); - getdata(7, 8, "\033[1;37m你的選擇? [1-4]\033[m", ch, 2, LCECHO); + getdata(7, 8, "\033[1;37m你的選擇? [1-4]\033[m", ch, sizeof(ch), LCECHO); switch(ch[0]) { case '1': diff --git a/pttbbs/mbbsd/bbs.c b/pttbbs/mbbsd/bbs.c index 15db1c91..28322370 100644 --- a/pttbbs/mbbsd/bbs.c +++ b/pttbbs/mbbsd/bbs.c @@ -1,4 +1,4 @@ -/* $Id: bbs.c,v 1.1 2002/03/07 15:13:48 in2 Exp $ */ +/* $Id: bbs.c,v 1.2 2002/04/28 19:35:28 in2 Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -88,7 +88,7 @@ int save_violatelaw() { "已經造成很多人的不便\033[m\n"); prints("\033[1;37m你是否確定以後不會再犯了?\033[m\n"); - if(!getdata(10,0,"確定嗎?[y/n]:", ok, 2, LCECHO) || + if(!getdata(10,0,"確定嗎?[y/n]:", ok, sizeof(ok), LCECHO) || ok[0] == 'n' || ok[0] == 'N') { mprints(22,0,"\033[1;31m等你想通了再來吧!! " "我相信你不會知錯不改的~~~\033[m"); @@ -100,7 +100,7 @@ int save_violatelaw() { cuser.vl_count, cuser.vl_count*1000); mprints(11,0,buf); - if(!getdata(10, 0, "要付錢[y/n]:", ok, 2, LCECHO) || + if(!getdata(10, 0, "要付錢[y/n]:", ok, sizeof(ok), LCECHO) || ok[0] == 'N' || ok[0] == 'n') { mprints(22,0, "\033[1;31m 嗯 存夠錢 再來吧!!!\033[m"); @@ -1347,9 +1347,9 @@ static int tar_addqueue(int ent, fileheader_t *fhdr, char *direct) { return FULLUPDATE; } - getdata(6, 0, "要備份看版內容嗎(Y/N)?[Y]", ans, 2, LCECHO); + getdata(6, 0, "要備份看版內容嗎(Y/N)?[Y]", ans, sizeof(ans), LCECHO); bakboard = (ans[0] == 'n' || ans[0] =='N') ? 0 : 1; - getdata(7, 0, "要備份精華區內容嗎(Y/N)?[N]", ans, 2, LCECHO); + getdata(7, 0, "要備份精華區內容嗎(Y/N)?[N]", ans, sizeof(ans), LCECHO); bakman = (ans[0] == 'y' || ans[0] =='Y') ? 1 : 0; if( !bakboard && !bakman ){ move(8, 0); @@ -1513,7 +1513,7 @@ static int b_post_note() { if(currmode & MODE_BOARD) { setbfile(buf, currboard, FN_POST_NOTE ); if(more(buf,NA) == -1) more("etc/"FN_POST_NOTE , NA); - getdata(b_lines - 2, 0, "是否要用自訂post注意事項?", yn, 3, LCECHO); + getdata(b_lines - 2, 0, "是否要用自訂post注意事項?", yn, sizeof(yn), LCECHO); if(yn[0] == 'y') vedit(buf, NA, NULL); else @@ -1551,8 +1551,8 @@ static int bh_title_edit() { bp = getbcache(currbid); move(1,0); clrtoeol(); - getdata_str(1,0,"請輸入看板新中文敘述:", genbuf,BTLEN - - 16,DOECHO, bp->title + 7); + getdata_str(1,0,"請輸入看板新中文敘述:", genbuf, + BTLEN - 16, DOECHO, bp->title + 7); if(!genbuf[0]) return 0; @@ -1753,11 +1753,12 @@ static int change_hidden(int ent, fileheader_t *fhdr, char *direct) return DONOTHING; if( ((bh.brdattr & BRD_HIDE) && (bh.brdattr & BRD_POSTMASK)) ){ - getdata(1, 0, "目前板在隱形狀態, 要解隱形嘛(Y/N)?[N]", ans, 2, LCECHO); + getdata(1, 0, "目前板在隱形狀態, 要解隱形嘛(Y/N)?[N]", + ans, sizeof(ans), LCECHO); if( ans[0] != 'y' && ans[0] != 'Y' ) return FULLUPDATE; getdata(2, 0, "再確認一次, 真的要把板板公開嘛 @____@(Y/N)?[N]", - ans, 2, LCECHO); + ans, sizeof(ans), LCECHO); if( ans[0] != 'y' && ans[0] != 'Y' ) return FULLUPDATE; if( bh.brdattr & BRD_HIDE ) bh.brdattr -= BRD_HIDE; @@ -1768,7 +1769,8 @@ static int change_hidden(int ent, fileheader_t *fhdr, char *direct) hbflreload(bid); } else{ - getdata(1, 0, "目前板在現形狀態, 要隱形嘛(Y/N)?[N]", ans, 2, LCECHO); + getdata(1, 0, "目前板在現形狀態, 要隱形嘛(Y/N)?[N]", + ans, sizeof(ans), LCECHO); if( ans[0] != 'y' && ans[0] != 'Y' ) return FULLUPDATE; bh.brdattr |= BRD_HIDE; diff --git a/pttbbs/mbbsd/board.c b/pttbbs/mbbsd/board.c index e97d6e3f..923bea0a 100644 --- a/pttbbs/mbbsd/board.c +++ b/pttbbs/mbbsd/board.c @@ -1,4 +1,4 @@ -/* $Id: board.c,v 1.4 2002/04/15 20:00:22 in2 Exp $ */ +/* $Id: board.c,v 1.5 2002/04/28 19:35:28 in2 Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -837,7 +837,8 @@ static void choose_board(int newflag) { show_brdlist(head, 1, newflag); break; case '/': - getdata_buf(b_lines-1,0,"請輸入看板中文關鍵字:",keyword, 12, DOECHO); + getdata_buf(b_lines-1,0,"請輸入看板中文關鍵字:", + keyword, sizeof(keyword), DOECHO); brdnum=-1; break; case 'S': diff --git a/pttbbs/mbbsd/cache.c b/pttbbs/mbbsd/cache.c index 03092a2f..dd00d010 100644 --- a/pttbbs/mbbsd/cache.c +++ b/pttbbs/mbbsd/cache.c @@ -1,4 +1,4 @@ -/* $Id: cache.c,v 1.20 2002/04/20 07:31:46 in2 Exp $ */ +/* $Id: cache.c,v 1.21 2002/04/28 19:35:28 in2 Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -980,7 +980,6 @@ void resolve_fcache() { extern time_t login_start_time; extern char *fn_visable; -FILE *DEBUG = NULL; void hbflreload(int bid) { diff --git a/pttbbs/mbbsd/cal.c b/pttbbs/mbbsd/cal.c index 680ee9d6..6603925e 100644 --- a/pttbbs/mbbsd/cal.c +++ b/pttbbs/mbbsd/cal.c @@ -1,4 +1,4 @@ -/* $Id: cal.c,v 1.1 2002/03/07 15:13:48 in2 Exp $ */ +/* $Id: cal.c,v 1.2 2002/04/28 19:35:28 in2 Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -100,7 +100,7 @@ extern char save_title[]; static int osong(char *defaultid) { char destid[IDLEN + 1],buf[200],genbuf[200],filename[256],say[51]; - char receiver[60],ano[2]; + char receiver[45],ano[2]; FILE *fp,*fp1;// *fp2; fileheader_t mail; time_t now; @@ -136,30 +136,31 @@ static int osong(char *defaultid) { outs(buf); trans_buffer[0] = 0; if(!defaultid){ - getdata(13, 0, "要點給誰呢:[可直接按 Enter 先選歌]", destid, IDLEN + 1, DOECHO); + getdata(13, 0, "要點給誰呢:[可直接按 Enter 先選歌]", + destid, sizeof(destid), DOECHO); while (!destid[0]){ a_menu("點歌歌本", SONGBOOK,0 ); clear(); - getdata(13, 0, "要點給誰呢:[可按 Enter 重新選歌]", destid, IDLEN + 1, DOECHO); + getdata(13, 0, "要點給誰呢:[可按 Enter 重新選歌]", + destid, sizeof(destid), DOECHO); } } else strcpy(destid,defaultid); /* Heat:點歌者匿名功能 */ - getdata(14,0, "要匿名嗎?[y/n]:", ano, 2, DOECHO); + getdata(14,0, "要匿名嗎?[y/n]:", ano, sizeof(ano), DOECHO); if(!destid[0]) { unlockutmpmode(); return 0; } - getdata_str(14, 0, "想要要對他(她)說..:", say, 51, DOECHO, "我愛妳.."); + getdata_str(14, 0, "想要要對他(她)說..:", say, + sizeof(say), DOECHO, "我愛妳.."); sprintf(save_title, "%s:%s", (ano[0]=='y')?"匿名者":cuser.userid, say); - getdata_str(16, 0, "寄到誰的信箱(可用E-mail)?", receiver, 45, - LCECHO, destid); - - + getdata_str(16, 0, "寄到誰的信箱(可用E-mail)?", + receiver, sizeof(receiver), LCECHO, destid); if (!trans_buffer[0]){ outs("\n接著要選歌囉..進入歌本好好的選一首歌吧..^o^"); @@ -278,7 +279,7 @@ int p_cloak() { char buf[4]; getdata(b_lines-1, 0, currutmp->invisible ? "確定要現身?[y/N]" : "確定要隱身?[y/N]", - buf, 3, LCECHO); + buf, sizeof(buf), LCECHO); if(buf[0] != 'y') return 0; if(cuser.money >= 19) { @@ -295,14 +296,14 @@ int p_cloak() { int p_from() { char ans[4]; - getdata(b_lines-2, 0, "確定要改故鄉?[y/N]", ans, 3, LCECHO); + getdata(b_lines-2, 0, "確定要改故鄉?[y/N]", ans, sizeof(ans), LCECHO); if(ans[0] != 'y') return 0; reload_money(); if(cuser.money < 49) return 0; if(getdata_buf(b_lines-1, 0, "請輸入新故鄉:", - currutmp->from, 17, DOECHO)) { + currutmp->from, sizeof(currutmp->from), DOECHO)) { vice(49,"home"); currutmp->from_alias=0; } @@ -322,7 +323,7 @@ int p_exmail() { sprintf(buf,"您曾增購 %d 封容量,還要再買多少?", cuser.exmailbox); - getdata_str(b_lines-2, 0, buf, ans, 3, LCECHO, "10"); + getdata_str(b_lines-2, 0, buf, ans, sizeof(ans), LCECHO, "10"); n = atoi(ans); if(!ans[0] || !n) diff --git a/pttbbs/mbbsd/card.c b/pttbbs/mbbsd/card.c index cfa10b0c..66aeded8 100644 --- a/pttbbs/mbbsd/card.c +++ b/pttbbs/mbbsd/card.c @@ -1,4 +1,4 @@ -/* $Id: card.c,v 1.1 2002/03/07 15:13:48 in2 Exp $ */ +/* $Id: card.c,v 1.2 2002/04/28 19:35:28 in2 Exp $ */ #include <stdio.h> #include <stdlib.h> #include <sys/types.h> @@ -357,7 +357,7 @@ static int card_double_ask() { reload_money(); if(cuser.money < JACK) return 0; - getdata(20, 0, buf, buf2, 2, LCECHO); + getdata(20, 0, buf, buf2, sizeof(buf2), LCECHO); if(buf2[0] == 'y' || buf2[0] == 'Y') return 1; return 0; @@ -368,7 +368,7 @@ static int card_ask() { sprintf(buf, "[ %s ]您現在共有 %d P幣, 還要加牌嗎? [y/N]", cuser.userid, cuser.money); - getdata(20, 0 , buf, buf2, 2, LCECHO); + getdata(20, 0 , buf, buf2, sizeof(buf2), LCECHO); if(buf2[0] == 'y' || buf2[0] == 'Y') return 1; return 0; diff --git a/pttbbs/mbbsd/chat.c b/pttbbs/mbbsd/chat.c index f75383a8..4825379b 100644 --- a/pttbbs/mbbsd/chat.c +++ b/pttbbs/mbbsd/chat.c @@ -1,4 +1,4 @@ -/* $Id: chat.c,v 1.1 2002/03/07 15:13:48 in2 Exp $ */ +/* $Id: chat.c,v 1.2 2002/04/28 19:35:28 in2 Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -594,7 +594,7 @@ int t_chat() { fclose(flog); more(fpath, NA); getdata(b_lines - 1, 0, "清除(C) 移至備忘錄(M) (C/M)?[C]", - ans, 4, LCECHO); + ans, sizeof(ans), LCECHO); if (*ans == 'm') { fileheader_t mymail; char title[128]; diff --git a/pttbbs/mbbsd/chicken.c b/pttbbs/mbbsd/chicken.c index f789925f..f13b68dc 100644 --- a/pttbbs/mbbsd/chicken.c +++ b/pttbbs/mbbsd/chicken.c @@ -1,4 +1,4 @@ -/* $Id: chicken.c,v 1.1 2002/03/07 15:13:48 in2 Exp $ */ +/* $Id: chicken.c,v 1.2 2002/04/28 19:35:29 in2 Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -137,7 +137,8 @@ static int new_chicken() { } vice(price,"寵物蛋"); while(strlen(mychicken->name)<3) - getdata(8, 0, "幫牠取個好名字:", mychicken->name, 18, DOECHO); + getdata(8, 0, "幫牠取個好名字:", mychicken->name, + sizeof(mychicken->name), DOECHO); now = time(NULL); sprintf(buf,"\033[31m%s \033[m養了一隻叫\033[33m %s \033[m的 " @@ -367,7 +368,8 @@ void ch_buyitem(int money, char *picture, int *item) { int num = 0; char buf[5]; - getdata_str(b_lines - 1, 0, "要買多少份呢:", buf, 4, DOECHO, "1"); + getdata_str(b_lines - 1, 0, "要買多少份呢:", + buf, sizeof(buf), DOECHO, "1"); num = atoi(buf); if(num < 1) return; @@ -414,7 +416,7 @@ static void ch_kill() { sprintf(buf, "棄養這%s要被罰 100 元, 是否要棄養?(y/N)", chicken_type[(int)mychicken->type]); - getdata_str(23, 0, buf, ans, 3, DOECHO, "N"); + getdata_str(23, 0, buf, ans, sizeof(ans), DOECHO, "N"); if(ans[0] == 'y') { time_t now = time(NULL); @@ -476,7 +478,7 @@ static int ch_sell() { sprintf(buf, "這隻%d歲%s可以賣 %d 元, 是否要賣?(y/N)", age, chicken_type[(int)mychicken->type], money); - getdata_str(23, 0, buf, ans, 3, DOECHO, "N"); + getdata_str(23, 0, buf, ans, sizeof(ans), DOECHO, "N"); if(ans[0]=='y') { sprintf(buf, "\033[31m%s\033[m 把 \033[33m%s\033[m " "\033[32m%s\033[m 用 \033[36m%d\033[m 賣了 於 %s", diff --git a/pttbbs/mbbsd/dice.c b/pttbbs/mbbsd/dice.c index d64ce63c..e4aa8869 100644 --- a/pttbbs/mbbsd/dice.c +++ b/pttbbs/mbbsd/dice.c @@ -1,4 +1,4 @@ -/* $Id: dice.c,v 1.1 2002/03/07 15:13:48 in2 Exp $ */ +/* $Id: dice.c,v 1.2 2002/04/28 19:35:29 in2 Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -351,7 +351,7 @@ int dice_main(void) { if(cuser.money < 10) break; getdata(21, 0, "\033[1;32m賭多少錢呢\033[1;37m(大於10 小於500)" - "\033[m: ", input, 9, LCECHO); + "\033[m: ", input, sizeof(input), LCECHO); if(!(money = IsLegal(input))||input[0] == '0') continue; reload_money(); diff --git a/pttbbs/mbbsd/edit.c b/pttbbs/mbbsd/edit.c index 0b372209..79ecf7f6 100644 --- a/pttbbs/mbbsd/edit.c +++ b/pttbbs/mbbsd/edit.c @@ -1,4 +1,4 @@ -/* $Id: edit.c,v 1.4 2002/04/27 15:50:17 in2 Exp $ */ +/* $Id: edit.c,v 1.5 2002/04/28 19:35:29 in2 Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -502,7 +502,7 @@ static void read_tmpbuf(int n) { setuserfile(fp_tmpbuf, tmpf); if(n != 0 && n != 5 && more(fp_tmpbuf, NA) != -1) - getdata(b_lines - 1, 0, "確定讀入嗎(Y/N)?[Y]", ans, 4, LCECHO); + getdata(b_lines - 1, 0, "確定讀入嗎(Y/N)?[Y]", ans, sizeof(ans), LCECHO); if(*ans != 'n' && (fp = fopen(fp_tmpbuf, "r"))) { prevln = currln; prevpnt = currpnt; @@ -523,7 +523,7 @@ static void write_tmpbuf() { if(dashf(fp_tmpbuf)) { more(fp_tmpbuf, NA); getdata(b_lines - 1, 0, "暫存檔已有資料 (A)附加 (W)覆寫 (Q)取消?[A] ", - ans, 4, LCECHO); + ans, sizeof(ans), LCECHO); if(ans[0] == 'q') return; @@ -544,7 +544,8 @@ static void erase_tmpbuf() { setuserfile(fp_tmpbuf, ask_tmpbuf(3)); if(more(fp_tmpbuf, NA) != -1) - getdata(b_lines - 1, 0, "確定刪除嗎(Y/N)?[N]", ans, 4, LCECHO); + getdata(b_lines - 1, 0, "確定刪除嗎(Y/N)?[N]", + ans, sizeof(ans), LCECHO); if(*ans == 'y') unlink(fp_tmpbuf); } @@ -706,7 +707,8 @@ static int check_quote() { { char ans[4]; - getdata(12, 12, "(E)繼續編輯 (W)強制寫入?[E] ", ans, 4, LCECHO); + getdata(12, 12, "(E)繼續編輯 (W)強制寫入?[E] ", + ans, sizeof(ans), LCECHO); if(ans[0] == 'w') return 0; } @@ -760,10 +762,10 @@ void write_header(FILE *fp) { int defanony = (currbrdattr & BRD_DEFAULTANONYMOUS); if(defanony) getdata(3, 0, "請輸入你想用的ID,也可直接按[Enter]," - "或是按[r]用真名:", real_name, 12, DOECHO); + "或是按[r]用真名:", real_name, sizeof(real_name), DOECHO); else getdata(3, 0, "請輸入你想用的ID,也可直接按[Enter]使用原ID:", - real_name, 12, DOECHO); + real_name, sizeof(real_name), DOECHO); if(!real_name[0] && defanony) { strcpy(real_name, "Anonymous"); strcpy(postlog.author, real_name); @@ -893,7 +895,7 @@ write_file(char *fpath, int saveheader, int *islocal) { else msg = "[S]儲存 (L)站內信件 (A)放棄 (T)改標題 (E)繼續 " "(R/W/D)讀寫刪暫存檔?"; - getdata(1, 0, msg, ans, 3, LCECHO); + getdata(1, 0, msg, ans, 2, LCECHO); switch(ans[0]) { case 'a': @@ -915,7 +917,7 @@ write_file(char *fpath, int saveheader, int *islocal) { move(3, 0); prints("舊標題:%s", save_title); strcpy(ans,save_title); - if(getdata_buf(4, 0, "新標題:", ans, TTLEN, DOECHO)) + if(getdata_buf(4, 0, "新標題:", ans, sizeof(ans), DOECHO)) strcpy(save_title, ans); return KEEP_EDITING; case 's': @@ -1094,7 +1096,7 @@ static void goto_line(int lino) { char buf[10]; if(lino > 0 || - (getdata(b_lines - 1, 0, "跳至第幾行:", buf, 10, DOECHO) && + (getdata(b_lines - 1, 0, "跳至第幾行:", buf, sizeof(buf), DOECHO) && sscanf(buf, "%d", &lino) && lino > 0)) { textline_t* p; @@ -1148,16 +1150,17 @@ char *strcasestr(const char* big, const char* little) { -1: backward */ static void search_str(int mode) { - static char str[80]; + static char str[65]; typedef char* (*FPTR)(); static FPTR fptr; char ans[4] = "n"; if(!mode) { - if(getdata_buf(b_lines - 1, 0,"[搜尋]關鍵字:",str, 65, DOECHO)) + if(getdata_buf(b_lines - 1, 0,"[搜尋]關鍵字:", + str, sizeof(str), DOECHO)) if(*str) { if(getdata(b_lines - 1, 0, "區分大小寫(Y/N/Q)? [N] ", - ans, 4, LCECHO) && *ans == 'y') + ans, sizeof(ans), LCECHO) && *ans == 'y') fptr = strstr; else fptr = strcasestr; @@ -1351,7 +1354,7 @@ static void block_del(int hide) { if(tmpfname[4] != '5' && dashf(fp_tmpbuf)) { more(fp_tmpbuf, NA); getdata(b_lines - 1, 0, "暫存檔已有資料 (A)附加 (W)覆寫 " - "(Q)取消?[W] ", ans, 4, LCECHO); + "(Q)取消?[W] ", ans, 2, LCECHO); if(*ans == 'q') tmpfname[4] = 'q'; else if(*ans != 'a') @@ -1752,7 +1755,7 @@ int vedit(char *fpath, int saveheader, int *islocal) { "\033[45mP\033[46mC\033[47mW\033[m"); if(getdata(b_lines - 1, 0, "請輸入 亮度/前景/背景[正常白字黑底][0wb]:", - ans, 4, LCECHO)) { + ans, sizeof(ans), LCECHO)) { char t[] = "BRGYLPCW"; char color[15]; char *tmp, *apos = ans; @@ -2112,7 +2115,7 @@ int vedit(char *fpath, int saveheader, int *islocal) { getdata(b_lines - 1, 0, "區塊微調右移插入字元(預設為空白字元)", - ans, 4, LCECHO); + ans, sizeof(ans), LCECHO); insert_c = (*ans) ? *ans : ' '; } insert_character ^= 1; diff --git a/pttbbs/mbbsd/friend.c b/pttbbs/mbbsd/friend.c index fef3fabc..bac0674e 100644 --- a/pttbbs/mbbsd/friend.c +++ b/pttbbs/mbbsd/friend.c @@ -1,4 +1,4 @@ -/* $Id: friend.c,v 1.4 2002/04/09 20:31:50 in2 Exp $ */ +/* $Id: friend.c,v 1.5 2002/04/28 19:35:29 in2 Exp $ */ #include <stdio.h> #include <string.h> #include <stdlib.h> @@ -124,7 +124,7 @@ void friend_add(char *uident, int type) { strcpy(t_uident, uident); if (type != FRIEND_ALOHA && type != FRIEND_POST) - getdata(2, 0, friend_desc[type], buf, 40, DOECHO); + getdata(2, 0, friend_desc[type], buf, sizeof(buf), DOECHO); if ((fp = fopen(fpath, "a"))) { @@ -445,12 +445,13 @@ void friend_edit(int type) { } else if (*uident == 'w' && count) { - if (!getdata(0, 0, "群體水球:", uident, 60, DOECHO)) + char wall[60]; + if (!getdata(0, 0, "群體水球:", uident, sizeof(wall), DOECHO)) continue; if (getdata(0, 0, "確定丟出群體水球? [Y]", line, 4, LCECHO) && *line == 'n') continue; - friend_water(uident, type); + friend_water(wall, type); } else break; diff --git a/pttbbs/mbbsd/gomo.c b/pttbbs/mbbsd/gomo.c index 06062ce4..41650c77 100644 --- a/pttbbs/mbbsd/gomo.c +++ b/pttbbs/mbbsd/gomo.c @@ -1,4 +1,4 @@ -/* $Id: gomo.c,v 1.1 2002/03/07 15:13:48 in2 Exp $ */ +/* $Id: gomo.c,v 1.2 2002/04/28 19:35:29 in2 Exp $ */ #include <stdio.h> #include <stdlib.h> #include <unistd.h> @@ -131,7 +131,7 @@ static int gomo_key(int fd, int ch, Horder_t *mv) { *pbuf = ch; if(fd) add_io(0, 0); - oldgetdata(17, 0, "直接指定位置 :", pbuf, 4, DOECHO); + oldgetdata(17, 0, "直接指定位置 :", pbuf, sizeof(pbuf), DOECHO); if(fd) add_io(fd, 0); vx = pbuf[0] - 'a'; @@ -409,7 +409,7 @@ int gomoku(int fd) { if(v > pool) { char ans[4]; - getdata(19 , 0, "要保留本局成棋譜嗎?(y/N)", ans, 4, LCECHO); + getdata(19 , 0, "要保留本局成棋譜嗎?(y/N)", ans, sizeof(ans), LCECHO); if(*ans == 'y') HO_log(my->mateid); } diff --git a/pttbbs/mbbsd/guess.c b/pttbbs/mbbsd/guess.c index 27a337f7..c24b8361 100644 --- a/pttbbs/mbbsd/guess.c +++ b/pttbbs/mbbsd/guess.c @@ -1,4 +1,4 @@ -/* $Id: guess.c,v 1.1 2002/03/07 15:13:48 in2 Exp $ */ +/* $Id: guess.c,v 1.2 2002/04/28 19:35:29 in2 Exp $ */ #include <stdio.h> #include <stdlib.h> #include <sys/types.h> @@ -84,7 +84,7 @@ static int check_data(char *str) { static char *get_data(int count) { static char data[5]; while(1) { - getdata(6, 0, "輸入四位數字(不重複): ", data, 5, LCECHO); + getdata(6, 0, "輸入四位數字(不重複): ", data, sizeof(data), LCECHO); if(check_data(data) == 1) break; } @@ -209,7 +209,7 @@ int guess_main() { unsigned long int money; char computerwin = 0,youwin = 0; int count = 0,c_count = 0; - char ifcomputer; + char ifcomputer[2]; char answer[5]; int *n = NULL; char yournum[5]; @@ -239,18 +239,19 @@ int guess_main() { clrtoeol(); prints("您下注 :%d Ptt$", money); - getdata_str(4, 0, "您要和電腦比賽嗎? <y/n>[y]:", &ifcomputer, 2, - LCECHO, "y"); - if(ifcomputer == 'y') { - ifcomputer = 1; + getdata_str(4, 0, "您要和電腦比賽嗎? <y/n>[y]:", + ifcomputer, sizeof(ifcomputer), LCECHO, "y"); + if(ifcomputer[0] == 'y') { + ifcomputer[0] = 1; show_table(TABLE, 1); } else { - ifcomputer = 0; + ifcomputer[0] = 0; show_table(TABLE, 0); } - if(ifcomputer) { + if(ifcomputer[0]) { do { - getdata(5, 0, "請輸入您要讓電腦猜的數字: ", yournum, 5, LCECHO); + getdata(5, 0, "請輸入您要讓電腦猜的數字: ", + yournum, sizeof(yournum), LCECHO); } while(!legal(atoi(yournum))); move(8, 25); prints("電腦猜"); @@ -260,9 +261,9 @@ int guess_main() { } move(8, 55); prints("你猜"); - while(((!computerwin || !youwin) && count <10 && (ifcomputer)) || - (!ifcomputer && count < 10 && !youwin)) { - if(!computerwin && ifcomputer) { + while(((!computerwin || !youwin) && count <10 && (ifcomputer[0])) || + (!ifcomputer[0] && count < 10 && !youwin)) { + if(!computerwin && ifcomputer[0]) { ++c_count; if(computer(atoi(yournum), c_count, flag, n)) computerwin = 1; @@ -276,7 +277,7 @@ int guess_main() { } } move(17, 35); - if(ifcomputer) { + if(ifcomputer[0]) { free(flag); free(n); if(count > c_count) { diff --git a/pttbbs/mbbsd/indict.c b/pttbbs/mbbsd/indict.c index 407b5ae9..51e20590 100644 --- a/pttbbs/mbbsd/indict.c +++ b/pttbbs/mbbsd/indict.c @@ -1,4 +1,4 @@ -/* $Id: indict.c,v 1.1 2002/03/07 15:13:48 in2 Exp $ */ +/* $Id: indict.c,v 1.2 2002/04/28 19:35:29 in2 Exp $ */ #include <stdio.h> #include <string.h> #include <sys/types.h> @@ -29,7 +29,7 @@ static void addword(char word[]) { outs("\n請依上列範例輸入一行資料(直接enter放棄)\n"); getdata(10, 0, ":", buf, 65, DOECHO); if(buf[0]) { - getdata(13, 0, "確定新增?(Y/n)", a, 2, LCECHO); + getdata(13, 0, "確定新增?(Y/n)", a, sizeof(a), LCECHO); if(a[0] != 'n') fprintf(fp, "%-65s[%s]\n", buf, cuser.userid); } diff --git a/pttbbs/mbbsd/io.c b/pttbbs/mbbsd/io.c index 4bfd80cc..79a3874f 100644 --- a/pttbbs/mbbsd/io.c +++ b/pttbbs/mbbsd/io.c @@ -1,4 +1,4 @@ -/* $Id: io.c,v 1.8 2002/03/29 16:22:53 ptt Exp $ */ +/* $Id: io.c,v 1.9 2002/04/28 19:35:29 in2 Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -547,14 +547,14 @@ getans(char *prompt) { char ans[5]; - getdata(t_lines-1, 0, prompt, ans, 4, LCECHO); + getdata(t_lines-1, 0, prompt, ans, sizeof(ans), LCECHO); return ans[0]; } int getdata_str(int line, int col, char *prompt, char *buf, int len, int echo, char *defaultstr) { strncpy(buf, defaultstr, len); - buf[len] = 0; + buf[len - 1] = 0; return oldgetdata(line, col, prompt, buf, len, echo); } diff --git a/pttbbs/mbbsd/lovepaper.c b/pttbbs/mbbsd/lovepaper.c index 52e8cbd5..92330db7 100644 --- a/pttbbs/mbbsd/lovepaper.c +++ b/pttbbs/mbbsd/lovepaper.c @@ -1,4 +1,4 @@ -/* $Id: lovepaper.c,v 1.1 2002/03/07 15:13:48 in2 Exp $ */ +/* $Id: lovepaper.c,v 1.2 2002/04/28 19:35:29 in2 Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -36,10 +36,11 @@ int x_love() { outs("\n歡迎使用情書產生器 v0.00 版 \n"); outs("有何難以啟齒的話,交由系統幫你說吧.\n爸爸說 : 濫情不犯法.\n"); - if(!getdata(7, 0, "收信人:", receiver, 60, DOECHO)) return 0; + if(!getdata(7, 0, "收信人:", receiver, sizeof(receiver), DOECHO)) + return 0; if(receiver[0] && !(searchuser(receiver) && getdata(8, 0, "主 題:", save_title, - TTLEN, DOECHO))) { + sizeof(save_title), DOECHO))) { move(10, 0); outs("收信人或主題不正確, 情書無法傳遞. "); pressanykey(); diff --git a/pttbbs/mbbsd/mail.c b/pttbbs/mbbsd/mail.c index 4a9395fa..bc6ff7b3 100644 --- a/pttbbs/mbbsd/mail.c +++ b/pttbbs/mbbsd/mail.c @@ -1,4 +1,4 @@ -/* $Id: mail.c,v 1.2 2002/03/24 18:25:48 in2 Exp $ */ +/* $Id: mail.c,v 1.3 2002/04/28 19:35:29 in2 Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -61,9 +61,9 @@ int setforward() { fclose(fp); } getdata_buf(b_lines - 1, 0, "請輸入信箱自動轉寄的email地址:", - ip, 41, DOECHO); + ip, sizeof(ip), DOECHO); if(ip[0] && ip[0] != ' ') { - getdata(b_lines, 0, "確定開啟自動轉信功\能?(Y/n)", yn, 3, + getdata(b_lines, 0, "確定開啟自動轉信功\能?(Y/n)", yn, sizeof(yn), LCECHO); if(yn[0] != 'n' && (fp = fopen(buf, "w"))) { move(b_lines,0); @@ -149,9 +149,9 @@ int invalidaddr(char *addr) { int m_internet() { char receiver[60]; - getdata(20, 0, "收信人:", receiver, 60, DOECHO); + getdata(20, 0, "收信人:", receiver, sizeof(receiver), DOECHO); if(strchr(receiver, '@') && !invalidaddr(receiver) && - getdata(21, 0, "主 題:", save_title, TTLEN, DOECHO)) + getdata(21, 0, "主 題:", save_title, STRLEN, DOECHO)) do_send(receiver, save_title); else { move(22, 0); @@ -245,7 +245,7 @@ void hold_mail(char *fpath, char *receiver) { char buf[4]; getdata(b_lines - 1, 0, "已順利寄出,是否自存底稿(Y/N)?[N] ", - buf, 4, LCECHO); + buf, sizeof(buf), LCECHO); if(buf[0] == 'y') do_hold_mail(fpath, receiver, cuser.userid); @@ -268,7 +268,7 @@ int do_send(char *userid, char *title) { return -3; if(!title) - getdata(2, 0, "主題:", save_title, TTLEN, DOECHO); + getdata(2, 0, "主題:", save_title, STRLEN, DOECHO); curredit |= EDIT_MAIL; curredit &= ~EDIT_ITEM; } @@ -485,7 +485,7 @@ static void multi_send(char *title) { if(title) do_reply_title(2, title); else { - getdata(2, 0, "主題:", fpath, 64, DOECHO); + getdata(2, 0, "主題:", fpath, sizeof(fpath), DOECHO); sprintf(save_title, "[通告] %s", fpath); } @@ -588,7 +588,7 @@ int mail_all() { stand_title("給所有使用者的系統通告"); setutmpmode(SMAIL); - getdata(2, 0, "主題:", fpath, 64, DOECHO); + getdata(2, 0, "主題:", fpath, sizeof(fpath), DOECHO); sprintf(save_title, "[系統通告]\033[1;32m %s\033[m", fpath); setuserfile(fpath, fn_notes); @@ -1139,7 +1139,7 @@ static int mail_cross_post(int ent, fileheader_t *fhdr, char *direct) { strcpy(xtitle, fhdr->title); sprintf(genbuf, "採用原標題《%.60s》嗎?[Y] ", xtitle); - getdata(2, 0, genbuf, genbuf2, 4, LCECHO); + getdata(2, 0, genbuf, genbuf2, sizeof(genbuf2), LCECHO); if(*genbuf2 == 'n') if(getdata(2, 0, "標題:", genbuf, TTLEN, DOECHO)) strcpy(xtitle, genbuf); diff --git a/pttbbs/mbbsd/mbbsd.c b/pttbbs/mbbsd/mbbsd.c index e7a2f84d..496ea00f 100644 --- a/pttbbs/mbbsd/mbbsd.c +++ b/pttbbs/mbbsd/mbbsd.c @@ -1,4 +1,4 @@ -/* $Id: mbbsd.c,v 1.23 2002/04/28 14:29:26 in2 Exp $ */ +/* $Id: mbbsd.c,v 1.24 2002/04/28 19:35:29 in2 Exp $ */ #include <stdio.h> #include <string.h> #include <stdlib.h> @@ -601,7 +601,7 @@ login_query () exit (1); } getdata (20, 0, "請輸入代號,或以[guest]參觀,以[new]註冊:", - uid, IDLEN + 1, DOECHO); + uid, sizeof(uid), DOECHO); if (strcasecmp (uid, str_new) == 0){ #ifdef LOGINASNEW new_register (); @@ -615,7 +615,7 @@ login_query () outs (err_uid); } else if (strcmp (uid, STR_GUEST)){ - getdata (21, 0, MSG_PASSWD, passbuf, PASSLEN, NOECHO); + getdata (21, 0, MSG_PASSWD, passbuf, sizeof(passbuf), NOECHO); passbuf[8] = '\0'; if (!checkpasswd (cuser.passwd, passbuf) diff --git a/pttbbs/mbbsd/more.c b/pttbbs/mbbsd/more.c index 7440ecc4..f8d32c61 100644 --- a/pttbbs/mbbsd/more.c +++ b/pttbbs/mbbsd/more.c @@ -1,4 +1,4 @@ -/* $Id: more.c,v 1.11 2002/04/27 15:50:17 in2 Exp $ */ +/* $Id: more.c,v 1.12 2002/04/28 19:35:29 in2 Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -459,7 +459,7 @@ int more(char *fpath, int promptend) { if(*search_str) { searching = 1; if(getdata(b_lines - 1, 0, "區分大小寫(Y/N/Q)? [N] ", - ans, 4, LCECHO) && *ans == 'y') + ans, sizeof(ans), LCECHO) && *ans == 'y') fptr = strstr; else fptr = strcasestr; diff --git a/pttbbs/mbbsd/othello.c b/pttbbs/mbbsd/othello.c index 47b8cef3..888a483e 100644 --- a/pttbbs/mbbsd/othello.c +++ b/pttbbs/mbbsd/othello.c @@ -1,4 +1,4 @@ -/* $Id: othello.c,v 1.1 2002/03/07 15:13:48 in2 Exp $ */ +/* $Id: othello.c,v 1.2 2002/04/28 19:35:29 in2 Exp $ */ #include <stdio.h> #include <stdlib.h> #include <sys/types.h> @@ -485,7 +485,8 @@ static int choose() { prints("(2) 嬰兒\n"); /* 想 3 步 */ prints("(3) 小孩\n"); /* 想 4 步 */ do { - getdata(4, 0, "請選擇一個對象和您對打:(1~5)", thinkstep, 2, LCECHO); + getdata(4, 0, "請選擇一個對象和您對打:(1~5)", + thinkstep, sizeof(thinkstep), LCECHO); } while(thinkstep[0] < '1' || thinkstep[0] > '3'); clear(); switch(thinkstep[0]) { diff --git a/pttbbs/mbbsd/page.c b/pttbbs/mbbsd/page.c index 33201bfc..5be7762e 100644 --- a/pttbbs/mbbsd/page.c +++ b/pttbbs/mbbsd/page.c @@ -1,4 +1,4 @@ -/* $Id: page.c,v 1.2 2002/04/27 15:50:17 in2 Exp $ */ +/* $Id: page.c,v 1.3 2002/04/28 19:35:29 in2 Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -103,7 +103,7 @@ int main_railway() { break; while(1) if(getdata(21, 0, "\033[1;35m欲查詢 1:出發時間 2:到達時間\033[m", - tt, 2, LCECHO) && + tt, sizeof(tt), LCECHO) && (tt[0]=='1' || tt[0]=='2')) break; sethomepath(genbuf, cuser.userid); diff --git a/pttbbs/mbbsd/read.c b/pttbbs/mbbsd/read.c index b92f95e7..b2cc64a4 100644 --- a/pttbbs/mbbsd/read.c +++ b/pttbbs/mbbsd/read.c @@ -1,4 +1,4 @@ -/* $Id: read.c,v 1.1 2002/03/07 15:13:48 in2 Exp $ */ +/* $Id: read.c,v 1.2 2002/04/28 19:35:29 in2 Exp $ */ #include <stdio.h> #include <string.h> #include <ctype.h> @@ -408,7 +408,7 @@ static int thread(keeploc_t *locmem, int stype) { } sprintf(s_pmt, "%s搜尋%s [%s] ",(stype & RS_FORWARD) ? "往後":"往前", (stype & RS_TITLE) ? "標題" : "作者", query); - getdata(b_lines - 1, 0, s_pmt, ans, 30, DOECHO); + getdata(b_lines - 1, 0, s_pmt, ans, sizeof(ans), DOECHO); if(*ans) strcpy(query, ans); else if(*query == '\0') diff --git a/pttbbs/mbbsd/register.c b/pttbbs/mbbsd/register.c index 1ef56e9e..53acc82f 100644 --- a/pttbbs/mbbsd/register.c +++ b/pttbbs/mbbsd/register.c @@ -1,4 +1,4 @@ -/* $Id: register.c,v 1.2 2002/03/17 06:04:18 in2 Exp $ */ +/* $Id: register.c,v 1.3 2002/04/28 19:35:29 in2 Exp $ */ #define _XOPEN_SOURCE #include <stdio.h> @@ -217,7 +217,8 @@ void new_register() { oflush(); exit(1); } - getdata(17, 0, msg_uid, newuser.userid, IDLEN + 1, DOECHO); + getdata(17, 0, msg_uid, newuser.userid, + sizeof(newuser.userid), DOECHO); if(bad_user_id(newuser.userid)) outs("無法接受這個代號,請使用英文字母,並且不要包含空格\n"); @@ -246,13 +247,14 @@ void new_register() { oflush(); exit(1); } - if((getdata(19, 0, "請設定密碼:", passbuf, PASSLEN, NOECHO) < 3) || + if((getdata(19, 0, "請設定密碼:", passbuf, + sizeof(passbuf), NOECHO) < 3) || !strcmp(passbuf, newuser.userid)) { outs("密碼太簡單,易遭入侵,至少要 4 個字,請重新輸入\n"); continue; } strncpy(newuser.passwd, passbuf, PASSLEN); - getdata(20, 0, "請檢查密碼:", passbuf, PASSLEN, NOECHO); + getdata(20, 0, "請檢查密碼:", passbuf, sizeof(passbuf), NOECHO); if(strncmp(passbuf, newuser.passwd, PASSLEN)) { outs("密碼輸入錯誤, 請重新輸入密碼.\n"); continue; @@ -291,33 +293,37 @@ void check_register() { stand_title("請詳細填寫個人資料"); while(strlen(cuser.username) < 2) - getdata(2, 0, "綽號暱稱:", cuser.username, 24, DOECHO); + getdata(2, 0, "綽號暱稱:", cuser.username, + sizeof(cuser.username), DOECHO); for(ptr = cuser.username; *ptr; ptr++) { if (*ptr == 9) /* TAB convert */ *ptr = ' '; } while(strlen(cuser.realname) < 4) - getdata(4, 0, "真實姓名:", cuser.realname, 20, DOECHO); + getdata(4, 0, "真實姓名:", cuser.realname, + sizeof(cuser.realname), DOECHO); while(strlen(cuser.address) < 8) - getdata(6, 0, "聯絡地址:", cuser.address, 50, DOECHO); + getdata(6, 0, "聯絡地址:", cuser.address, + sizeof(cuser.address), DOECHO); /* if(!strchr(cuser.email, '@')) { bell(); move(t_lines - 4, 0); - prints("※ 為了您的權益,請填寫真實的 E-mail address, " + prints("※ 為了您的權益,請填寫真實的 E-mail address," "以資確認閣下身份,\n" "格式為 \033[44muser@domain_name\033[0m 或 \033[44muser" "@\\[ip_number\\]\033[0m。\n\n" "※ 如果您真的沒有 E-mail,請直接按 [return] 即可。"); do { - getdata(8, 0, "電子信箱:", cuser.email, 50, DOECHO); + getdata(8, 0, "電子信箱:", + cuser.email, sizeof(cuser.email), DOECHO); if(!cuser.email[0]) - sprintf(cuser.email, "%s%s", cuser.userid, str_mail_address); + sprintf(cuser.email, "%s%s", cuser.userid, str_mail_address); } while(!strchr(cuser.email, '@')); } diff --git a/pttbbs/mbbsd/syspost.c b/pttbbs/mbbsd/syspost.c index 67edc632..474e8b65 100644 --- a/pttbbs/mbbsd/syspost.c +++ b/pttbbs/mbbsd/syspost.c @@ -1,4 +1,4 @@ -/* $Id: syspost.c,v 1.2 2002/03/09 17:27:57 in2 Exp $ */ +/* $Id: syspost.c,v 1.3 2002/04/28 19:35:29 in2 Exp $ */ #include <stdio.h> #include <string.h> #include <time.h> @@ -41,7 +41,7 @@ void post_change_perm(int oldperm, int newperm, char *sysopid, char *userid) { clrtobot(); clear(); while(!getdata_str(5, 0, "請輸入理由以示負責:", - reason, 60, DOECHO, "看版版主:")); + reason, sizeof(reason), DOECHO, "看版版主:")); fprintf(fp, "\n \033[1;37m站長%s修改權限理由是:%s\033[m", cuser.userid, reason); fclose(fp); diff --git a/pttbbs/mbbsd/talk.c b/pttbbs/mbbsd/talk.c index 73fdbc43..463f1f71 100644 --- a/pttbbs/mbbsd/talk.c +++ b/pttbbs/mbbsd/talk.c @@ -1,4 +1,4 @@ -/* $Id: talk.c,v 1.22 2002/04/27 15:50:17 in2 Exp $ */ +/* $Id: talk.c,v 1.23 2002/04/28 19:35:29 in2 Exp $ */ #include <stdio.h> #include <string.h> #include <errno.h> @@ -819,7 +819,7 @@ int t_display(void) setuserfile(genbuf, fn_writelog); if (more(genbuf, YEA) != -1){ getdata(b_lines - 1, 0, "清除(C) 移至備忘錄(M) 保留(R) (C/M/R)?[R]", - ans, 3, LCECHO); + ans, sizeof(ans), LCECHO); if (*ans == 'm'){ fileheader_t mymail; char title[128], buf[80]; @@ -1108,7 +1108,7 @@ static void do_talk(int fd) fclose(flog); more(fpath, NA); getdata(b_lines - 1, 0, "清除(C) 移至備忘錄(M). (C/M)?[C]", - ans, 4, LCECHO); + ans, sizeof(ans), LCECHO); if (*ans == 'm'){ fileheader_t mymail; char title[128]; @@ -1838,8 +1838,8 @@ static void pickup_user(void) char buf[100]; sprintf(buf, "代號 [%s]:", currutmp->userid); - if (!getdata(1, 0, buf, currutmp->userid, IDLEN + 1, - DOECHO)) + if (!getdata(1, 0, buf, currutmp->userid, + sizeof(currutmp->userid), DOECHO)) strcpy(currutmp->userid, cuser.userid); state = US_REDRAW; } @@ -1849,7 +1849,8 @@ static void pickup_user(void) char buf[100]; sprintf(buf, "故鄉 [%s]:", currutmp->from); - if (!getdata(1, 0, buf, currutmp->from, 17, DOECHO)) + if (!getdata(1, 0, buf, currutmp->from, + sizeof(currutmp->from), DOECHO)) strncpy(currutmp->from, fromhost, 23); state = US_REDRAW; } @@ -1903,8 +1904,8 @@ static void pickup_user(void) break; case '/': - getdata_buf(b_lines-1,0,"請輸入暱稱關鍵字:",keyword, 12, - DOECHO); + getdata_buf(b_lines-1,0,"請輸入暱稱關鍵字:", + keyword, sizeof(keyword), DOECHO); state = US_PICKUP; break; case 's': @@ -1966,7 +1967,8 @@ static void pickup_user(void) state = US_PICKUP; if (!getdata(0, 0, "廣播訊息:", genbuf, 60, DOECHO)) break; - if (getdata(0, 0, "確定廣播? [Y]", ans, 4, LCECHO) && + if (getdata(0, 0, "確定廣播? [Y]", + ans, sizeof(ans), LCECHO) && *ans == 'n') break; while (actor_pos){ @@ -2247,8 +2249,8 @@ int t_idle(void) if (currutmp->destuid == 6) if (!cuser.userlevel || - !getdata(b_lines - 1, 0, "發呆的理由:", currutmp->chatid, 11, - DOECHO)) + !getdata(b_lines - 1, 0, "發呆的理由:", + currutmp->chatid, sizeof(currutmp->chatid), DOECHO)) currutmp->destuid = 0; do{ move(b_lines - 2, 0); @@ -2257,7 +2259,7 @@ int t_idle(void) IdleTypeTable[currutmp->destuid] : currutmp->chatid); outs(buf); refresh(); - getdata(b_lines - 1, 0, MSG_PASSWD, passbuf, PASSLEN, NOECHO); + getdata(b_lines - 1, 0, MSG_PASSWD, passbuf, sizeof(passbuf), NOECHO); passbuf[8] = '\0'; } while (!checkpasswd(cuser.passwd, passbuf) && @@ -2379,11 +2381,11 @@ void talkreply(void) sprintf(genbuf, "你想跟 %s %s啊?請選擇(Y/N/A/B/C/D/E/F/1/2)[N] ", page_requestor, sig_des[sig]); - getdata(0, 0, genbuf, buf, 4, LCECHO); + getdata(0, 0, genbuf, buf, sizeof(buf), LCECHO); if (uip->mode != PAGE){ sprintf(genbuf, "%s已停止呼叫,按Enter繼續...", page_requestor); - getdata(0, 0, genbuf, buf, 4, LCECHO); + getdata(0, 0, genbuf, buf, sizeof(buf), LCECHO); return; } currutmp->msgcount = 0; diff --git a/pttbbs/mbbsd/user.c b/pttbbs/mbbsd/user.c index 55719a4a..3cce4bc5 100644 --- a/pttbbs/mbbsd/user.c +++ b/pttbbs/mbbsd/user.c @@ -1,4 +1,4 @@ -/* $Id: user.c,v 1.14 2002/04/27 15:50:17 in2 Exp $ */ +/* $Id: user.c,v 1.15 2002/04/28 19:35:29 in2 Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -50,7 +50,7 @@ int u_loginview() { clrtobot(); while(getdata(b_lines - 1, 0, "請按 [A-N] 切換設定,按 [Return] 結束:", - choice, 3, LCECHO)) { + choice, sizeof(choice), LCECHO)) { i = choice[0] - 'a'; if(i >= NUMVIEWFILE || i < 0) bell(); @@ -175,8 +175,7 @@ static void violate_law(userec_t *u, int unum){ move(2,0); prints("(1)Cross-post (2)亂發廣告信 (3)亂發連鎖信\n"); prints("(4)騷擾站上使用者 (8)其他以罰單處置行為\n(9)砍 id 行為\n"); - getdata(5, 0, "(0)結束", - ans, 3, DOECHO); + getdata(5, 0, "(0)結束", ans, sizeof(ans), DOECHO); switch(ans[0]){ case '1': sprintf(reason, "%s", "Cross-post"); @@ -193,12 +192,12 @@ static void violate_law(userec_t *u, int unum){ break; case '8': case '9': - while(!getdata(6, 0, "請輸入理由以示負責:", reason, 50, DOECHO)); + while(!getdata(6, 0, "請輸入理由以示負責:", reason, 50, DOECHO)); break; default: return; } - getdata(7, 0, msg_sure_ny, ans2, 3, LCECHO); + getdata(7, 0, msg_sure_ny, ans2, sizeof(ans2), LCECHO); if(*ans2 != 'y') return; if (ans[0]=='9'){ @@ -243,7 +242,7 @@ void uinfo_query(userec_t *u, int real, int unum) { "(1)改資料(2)設密碼(3)設權限(4)砍帳號(5)改ID" "(6)殺/復活寵物(7)審判 [0]結束 " : "請選擇 (1)修改資料 (2)設定密碼 ==> [0]結束 ", - ans, 3, DOECHO); + ans, sizeof(ans), DOECHO); if(ans[0] > '2' && !real) ans[0] = '0'; @@ -264,11 +263,15 @@ void uinfo_query(userec_t *u, int real, int unum) { move(0, 0); outs("請逐項修改。"); - getdata_buf(i++, 0," 暱 稱 :",x.username, 24, DOECHO); + getdata_buf(i++, 0," 暱 稱 :",x.username, + sizeof(x.username), DOECHO); if(real) { - getdata_buf(i++, 0, "真實姓名:", x.realname, 20, DOECHO); - getdata_buf(i++, 0, "身分證號:", x.ident, 11, DOECHO); - getdata_buf(i++, 0, "居住地址:", x.address, 50, DOECHO); + getdata_buf(i++, 0, "真實姓名:", + x.realname, sizeof(x.realname), DOECHO); + getdata_buf(i++, 0, "身分證號:", + x.ident, sizeof(x.ident), DOECHO); + getdata_buf(i++, 0, "居住地址:", + x.address, sizeof(x.address), DOECHO); } sprintf(buf, "%010d", x.mobile); getdata_buf(i++, 0, "手機號碼:", buf, 11, LCECHO); @@ -332,11 +335,13 @@ void uinfo_query(userec_t *u, int real, int unum) { if((l = atol(buf)) != 0) x.exmailbox = (int)l; - getdata_buf(i++, 0, "認證資料:", x.justify, 44, DOECHO); - getdata_buf(i++, 0, "最近光臨機器:", x.lasthost, 16, DOECHO); + getdata_buf(i++, 0, "認證資料:", x.justify, + sizeof(x.justify), DOECHO); + getdata_buf(i++, 0, "最近光臨機器:", + x.lasthost, sizeof(x.lasthost), DOECHO); sprintf(genbuf, "%d", x.numlogins); - if(getdata_str(i++, 0,"上線次數:", buf, 10, DOECHO,genbuf)) + if(getdata_str(i++, 0,"上線次數:", buf, 10, DOECHO, genbuf)) if((fail = atoi(buf)) >= 0) x.numlogins = fail; @@ -398,7 +403,8 @@ void uinfo_query(userec_t *u, int real, int unum) { char witness[3][32]; time_t now = time(NULL); for(i=0;i<3;i++){ - if(!getdata(19+i, 0, "請輸入協助證明之使用者:", witness[i], 32, DOECHO)){ + if(!getdata(19+i, 0, "請輸入協助證明之使用者:", + witness[i], sizeof(witness[i]), DOECHO)){ outs("\n不輸入則無法更改\n"); fail++; break; @@ -534,7 +540,9 @@ void uinfo_query(userec_t *u, int real, int unum) { clrtobot (); clear(); - while(!getdata(5, 0, "請輸入理由以示負責:", reason, 60, DOECHO)); + while( !getdata(5, 0, "請輸入理由以示負責:", + reason, sizeof(reason), DOECHO) ) + ; fprintf(fp, "\n \033[1;37m站長%s修改錢理由是:%s\033[m", cuser.userid, reason); @@ -637,7 +645,8 @@ int u_editsig() { j = showsignature(genbuf); - getdata(0, 0, "簽名檔 (E)編輯 (D)刪除 (Q)取消?[Q] ", ans, 4, LCECHO); + getdata(0, 0, "簽名檔 (E)編輯 (D)刪除 (Q)取消?[Q] ", + ans, sizeof(ans), LCECHO); aborted = 0; if(ans[0] == 'd') @@ -646,7 +655,7 @@ int u_editsig() { aborted = 2; if(aborted) { - if(!getdata(1, 0, "請選擇簽名檔(1-9)?[1] ", ans, 4, DOECHO)) + if(!getdata(1, 0, "請選擇簽名檔(1-9)?[1] ", ans, sizeof(ans), DOECHO)) ans[0] = '1'; if(ans[0] >= '1' && ans[0] <= '9') { genbuf[j] = ans[0]; @@ -937,7 +946,7 @@ int u_register(void) prints("%s(%s) 您好,請輸入您的認證碼或輸入 x重填 E-Mail ", cuser.userid, cuser.username); inregcode[0] = 0; - getdata(10, 0, "您的認證碼: ", inregcode, 45, DOECHO); + getdata(10, 0, "您的認證碼: ", inregcode, sizeof(inregcode), DOECHO); if( strcmp(inregcode, getregcode(regcode)) == 0 ){ int unum; if( (unum = getuser(cuser.userid)) == 0 ){ @@ -964,7 +973,8 @@ int u_register(void) return FULLUPDATE; } - getdata(b_lines - 1, 0, "您確定要填寫註冊單嗎(Y/N)?[N] ", ans, 3, LCECHO); + getdata(b_lines - 1, 0, "您確定要填寫註冊單嗎(Y/N)?[N] ", + ans, sizeof(ans), LCECHO); if(ans[0] != 'y') return FULLUPDATE; @@ -1017,7 +1027,7 @@ int u_register(void) } getfield(17, "1.葛格 2.姐接 ", "性別", sex_is, 2); getdata(18, 0, "以上資料是否正確(Y/N)?(Q)取消註冊 [N] ", - ans, 3, LCECHO); + ans, sizeof(ans), LCECHO); if(ans[0] == 'q') return 0; if(ans[0] == 'y') diff --git a/pttbbs/mbbsd/vice.c b/pttbbs/mbbsd/vice.c index 46f695d9..a27e5b21 100644 --- a/pttbbs/mbbsd/vice.c +++ b/pttbbs/mbbsd/vice.c @@ -1,4 +1,4 @@ -/* $Id: vice.c,v 1.1 2002/03/07 15:13:48 in2 Exp $ */ +/* $Id: vice.c,v 1.2 2002/04/28 19:35:29 in2 Exp $ */ #include <stdio.h> #include <string.h> #include <stdlib.h> @@ -118,7 +118,8 @@ int vice_main() { j += 9; j %= 45; } - getdata(8, 0, "按'c'開始對獎了(或是任意鍵離開)): ", ch, 2, LCECHO); + getdata(8, 0, "按'c'開始對獎了(或是任意鍵離開)): ", + ch, sizeof(ch), LCECHO); if(ch[0] != 'c' || lockutmpmode(VICE, LOCK_MULTI)){ fclose(fd); return 0; diff --git a/pttbbs/mbbsd/vote.c b/pttbbs/mbbsd/vote.c index 79176f7a..9cc55b40 100644 --- a/pttbbs/mbbsd/vote.c +++ b/pttbbs/mbbsd/vote.c @@ -1,4 +1,4 @@ -/* $Id: vote.c,v 1.5 2002/03/29 16:22:53 ptt Exp $ */ +/* $Id: vote.c,v 1.6 2002/04/28 19:35:29 in2 Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -654,7 +654,7 @@ static int vote_maintain(char *bname) { move(0,0); prints("第 %d 號投票\n", x); setbfile(buf, bname, STR_new_title); - getdata(4, 0, "請輸入投票名稱", inbuf, 30, LCECHO); + getdata(4, 0, "請輸入投票名稱", inbuf, sizeof(inbuf), LCECHO); if(inbuf[0]=='\0') strcpy(inbuf,"不知名的"); fp = fopen(buf, "w"); @@ -706,7 +706,8 @@ static int vote_maintain(char *bname) { num = 0; while(!aborted) { sprintf(buf, "%c) ", num + 'A'); - getdata((num % 15) + 2, (num / 15) * 40, buf, inbuf, 36, DOECHO); + getdata((num % 15) + 2, (num / 15) * 40, buf, + inbuf, sizeof(inbuf), DOECHO); if(*inbuf) { fprintf(fp, "%1c) %s\n", (num+'A'), inbuf); num++; @@ -866,7 +867,7 @@ static int user_vote_one(char *bname, int ind) { vote[0] = vote[1] = '\0'; move(t_lines - 2, 0); prints("你還可以投 %2d 票", tickets - i); - getdata(t_lines - 4, 0, "輸入您的選擇: ", vote, 3, DOECHO); + getdata(t_lines - 4, 0, "輸入您的選擇: ", vote, sizeof(vote), DOECHO); *vote = toupper(*vote); if(vote[0] == '0' || (!vote[0] && !i)) { outs("記的再來投喔!!"); @@ -922,7 +923,8 @@ static int user_vote_one(char *bname, int ind) { outs("請問您對這次投票有什麼寶貴的意見?" "最多三行,按[Enter]結束"); for(i = 0; (i < 3) && - getdata(7 + i, 0, ":", mycomments[i], 74, + getdata(7 + i, 0, ":", + mycomments[i], sizeof(mycomments[i]), DOECHO); i++); getdata(b_lines-2,0, "(S)儲存 (E)重新來過 " "(Q)取消?[S]", buf, 3, LCECHO); diff --git a/pttbbs/mbbsd/voteboard.c b/pttbbs/mbbsd/voteboard.c index 53034692..dbc23412 100644 --- a/pttbbs/mbbsd/voteboard.c +++ b/pttbbs/mbbsd/voteboard.c @@ -1,4 +1,4 @@ -/* $Id: voteboard.c,v 1.3 2002/04/17 09:23:26 in2 Exp $ */ +/* $Id: voteboard.c,v 1.4 2002/04/28 19:35:29 in2 Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -24,7 +24,7 @@ extern userec_t cuser; void do_voteboardreply(fileheader_t *fhdr){ char genbuf[1024]; - char reason[60]; + char reason[50]; char fpath[80]; char oldfpath[80]; char opnion[10]; @@ -131,7 +131,8 @@ void do_voteboardreply(fileheader_t *fhdr){ } }while(opnion[0] != 'y' && opnion[0] != 'n'); - if (!getdata(20, 0, "請問您與這個議題的關係或連署理由為何:", reason, 40, DOECHO)){ + if (!getdata(20, 0, "請問您與這個議題的關係或連署理由為何:", + reason, sizeof(reason), DOECHO)){ flock(fd, LOCK_UN); close(fd); fclose(fo); diff --git a/pttbbs/mbbsd/xyz.c b/pttbbs/mbbsd/xyz.c index 786add30..9ddbbe3e 100644 --- a/pttbbs/mbbsd/xyz.c +++ b/pttbbs/mbbsd/xyz.c @@ -1,4 +1,4 @@ -/* $Id: xyz.c,v 1.1 2002/03/07 15:13:48 in2 Exp $ */ +/* $Id: xyz.c,v 1.2 2002/04/28 19:35:29 in2 Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -182,8 +182,9 @@ int note() { move(12, 0); clrtobot(); outs("\n投五銀... 嗶... 請留言 (至多三行),按[Enter]結束"); - for(i = 0; (i < 3) && getdata(16 + i, 0, ":", myitem.buf[i], 78, - DOECHO) && *myitem.buf[i]; i++); + for(i = 0; (i < 3) && getdata(16 + i, 0, ":", myitem.buf[i], + sizeof(myitem.buf[i]), DOECHO) + && *myitem.buf[i]; i++); getdata(b_lines - 1, 0, "(S)儲存 (E)重新來過 (Q)取消?[S] ", buf, 3, LCECHO); @@ -424,7 +425,8 @@ static int x_archie() { strcpy(genbuf1, buf); sprintf(buf, BBSHOME "/tmp/archie.%s", cuser.userid); if(dashf(buf)) { - getdata(0, 0, "要將結果寄回信箱嗎(Y/N)?[N]", ans, 3, DOECHO,0); + getdata(0, 0, "要將結果寄回信箱嗎(Y/N)?[N]", + ans, sizeof(ans), DOECHO, 0); if(*ans == 'y') { fileheader_t mhdr; char title[128], buf1[80]; -- cgit v1.2.3 From 452469988817678643abbbc9723b235702f30a46 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sun, 28 Apr 2002 19:36:04 +0000 Subject: add DEBUG flag git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@132 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd.icc/Makefile | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/pttbbs/mbbsd.icc/Makefile b/pttbbs/mbbsd.icc/Makefile index a87135cc..9247b770 100644 --- a/pttbbs/mbbsd.icc/Makefile +++ b/pttbbs/mbbsd.icc/Makefile @@ -11,13 +11,26 @@ OBJS= admin.o announce.o args.o bbcall.o bbs.o board.o cache.o cal.o card.o\ voteboard.o syspost.o var.o descrypt.o toolkit.o passwd.o\ calendar.o -CFLAGS= -O -DHAVE_SETPROCTITLE -DBBSHOME='"$(BBSHOME)"' -DFreeBSD -I../include -D__FreeBSD__ -LDFLAGS=-O -lutil -lkvm -GCCUSE=gcc -pipe -Wall -O -DHAVE_SETPROCTITLE -DBBSHOME='"/home/bbs"' -DFreeBSD -I../include -c +CFLAGS=-DHAVE_SETPROCTITLE -DBBSHOME='"$(BBSHOME)"' -DFreeBSD -I../include +LDFLAGS=-lutil -lkvm + +.if defined(DEBUG) +CFLAGS+= -g -DDEBUG +LDFLAGS+= -g -DDEBUG +.else +CFLAGS+= -O +LDFLAGS+= -O +.endif + +.if defined(NO_FORK) +CFLAGS+= -DNO_FORK +.endif + +GCCUSE=gcc -pipe -Wall $(CFLAGS) -c .SUFFIXES: .c .o .c.o: - iccbin $(CFLAGS) -c ../mbbsd/$*.c + iccbin -D__FreeBSD__ -D__FreeBSD $(CFLAGS) -c ../mbbsd/$*.c all: $(PROG) @@ -47,5 +60,11 @@ topsong.o: topsong.c xyz.o: xyz.c $(GCCUSE) ../mbbsd/$*.c +test: $(PROG) + killall -9 testmbbsd || true + cp $(PROG) testmbbsd + ./testmbbsd 9000 + rm -f testmbbsd + clean: rm -f $(OBJS) $(PROG) -- cgit v1.2.3 From 89bdaced1cd620ea4f20d54f72a1bdc34be08424 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Mon, 29 Apr 2002 07:05:45 +0000 Subject: fix buffer overflow git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@133 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/announce.c | 4 ++-- pttbbs/mbbsd/bbs.c | 8 ++++---- pttbbs/mbbsd/mail.c | 8 ++++---- pttbbs/mbbsd/read.c | 10 +++++----- pttbbs/mbbsd/var.c | 6 +++--- 5 files changed, 18 insertions(+), 18 deletions(-) diff --git a/pttbbs/mbbsd/announce.c b/pttbbs/mbbsd/announce.c index 5920e45e..2064ba9d 100644 --- a/pttbbs/mbbsd/announce.c +++ b/pttbbs/mbbsd/announce.c @@ -1,4 +1,4 @@ -/* $Id: announce.c,v 1.5 2002/04/28 19:35:28 in2 Exp $ */ +/* $Id: announce.c,v 1.6 2002/04/29 07:05:45 in2 Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -1248,7 +1248,7 @@ static void atitle() { } #endif -extern char currtitle[]; +extern char currtitle[TTLEN + 1]; char trans_buffer[256]; extern char quote_file[]; diff --git a/pttbbs/mbbsd/bbs.c b/pttbbs/mbbsd/bbs.c index 28322370..eb252233 100644 --- a/pttbbs/mbbsd/bbs.c +++ b/pttbbs/mbbsd/bbs.c @@ -1,4 +1,4 @@ -/* $Id: bbs.c,v 1.2 2002/04/28 19:35:28 in2 Exp $ */ +/* $Id: bbs.c,v 1.3 2002/04/29 07:05:45 in2 Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -154,7 +154,7 @@ static void readtitle() { extern int brc_num; extern int brc_list[]; -extern char currtitle[]; +extern char currtitle[TTLEN + 1]; extern int Tagger(); @@ -186,7 +186,7 @@ static void readdoent(int num, fileheader_t *ent) { if(title[47]) strcpy(title + 44, " …"); /* 把多餘的 string 砍掉 */ - if(strncmp(currtitle, title, 40)) + if(strncmp(currtitle, title, TTLEN)) prints("%6d %c %-7s%-13.12s%s %s\n", num, type, ent->date, ent->owner, mark, title); else @@ -838,7 +838,7 @@ static int read_post(int ent, fileheader_t *fhdr, char *direct) { return DONOTHING; brc_addlist(fhdr->filename); - strncpy(currtitle, subject(fhdr->title), 40); + strncpy(currtitle, subject(fhdr->title), TTLEN); strncpy(currowner, subject(fhdr->owner), IDLEN + 2); switch (more_result) { diff --git a/pttbbs/mbbsd/mail.c b/pttbbs/mbbsd/mail.c index bc6ff7b3..3fa7ae37 100644 --- a/pttbbs/mbbsd/mail.c +++ b/pttbbs/mbbsd/mail.c @@ -1,4 +1,4 @@ -/* $Id: mail.c,v 1.3 2002/04/28 19:35:29 in2 Exp $ */ +/* $Id: mail.c,v 1.4 2002/04/29 07:05:45 in2 Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -28,7 +28,7 @@ extern char *fn_notes; extern char *msg_mailer; extern char *msg_sure_ny; extern char *BBSName; -extern char currtitle[44]; +extern char currtitle[TTLEN + 1]; extern unsigned char currfmode; /* current file mode */ extern char *msg_del_ny; extern char currfile[FNLEN]; @@ -847,7 +847,7 @@ static void maildoent(int num, fileheader_t *ent) { mark = "R:"; } - if(strncmp(currtitle, title, 40)) + if(strncmp(currtitle, title, TTLEN)) prints("%5d %c %-7s%-15.14s%s %.46s\n", num, type, ent->date, ent->owner, mark, title); else @@ -896,7 +896,7 @@ static int mail_read(int ent, fileheader_t *fhdr, char *direct) { clear(); setdirpath(buf, direct, fhdr->filename); - strncpy(currtitle, subject(fhdr->title), 40); + strncpy(currtitle, subject(fhdr->title), TTLEN); done = delete_it = replied = NA; while(!done) { int more_result = more(buf, YEA); diff --git a/pttbbs/mbbsd/read.c b/pttbbs/mbbsd/read.c index b2cc64a4..5866422e 100644 --- a/pttbbs/mbbsd/read.c +++ b/pttbbs/mbbsd/read.c @@ -1,4 +1,4 @@ -/* $Id: read.c,v 1.2 2002/04/28 19:35:29 in2 Exp $ */ +/* $Id: read.c,v 1.3 2002/04/29 07:05:45 in2 Exp $ */ #include <stdio.h> #include <string.h> #include <ctype.h> @@ -19,7 +19,7 @@ extern int p_lines; /* a Page of Screen line numbers: tlines-4 */ extern int b_lines; /* Screen bottom line number: t_lines-1 */ extern char currowner[IDLEN + 2]; -extern char currtitle[44]; +extern char currtitle[TTLEN + 1]; extern char currauthor[IDLEN + 2]; extern char *str_reply; extern char *msg_fwd_ok; @@ -385,7 +385,7 @@ static int thread(keeploc_t *locmem, int stype) { tag = headers[pos - locmem->top_ln].title; if(stype & RS_CURRENT) { if(stype & RS_FIRST) { - if(!strncmp(currtitle, tag, 40)) + if(!strncmp(currtitle, tag, TTLEN)) return DONOTHING; near = 0; } @@ -468,8 +468,8 @@ static int thread(keeploc_t *locmem, int stype) { match = cursor_pos(locmem, now, 10); if((!(stype & RS_CURRENT)) && (stype & RS_RELATED) && - strncmp(currtitle, query, 40)) { - strncpy(currtitle, query, 40); + strncmp(currtitle, query, TTLEN)) { + strncpy(currtitle, query, TTLEN); match = PARTUPDATE; } break; diff --git a/pttbbs/mbbsd/var.c b/pttbbs/mbbsd/var.c index 7b07f63b..6f531c21 100644 --- a/pttbbs/mbbsd/var.c +++ b/pttbbs/mbbsd/var.c @@ -1,4 +1,4 @@ -/* $Id: var.c,v 1.1 2002/03/07 15:13:48 in2 Exp $ */ +/* $Id: var.c,v 1.2 2002/04/29 07:05:45 in2 Exp $ */ #include <stdio.h> #include <sys/types.h> #include "config.h" @@ -91,8 +91,8 @@ time_t paste_time; char paste_title[STRLEN]; char paste_path[256]; int paste_level; -char currtitle[40] = "\0"; -char vetitle[40] = "\0"; +char currtitle[TTLEN + 1] = "\0"; +char vetitle[TTLEN + 1] = "\0"; char currowner[IDLEN + 2] = "\0"; char currauthor[IDLEN + 2] = "\0"; char currfile[FNLEN]; /* current file name @ bbs.c mail.c */ -- cgit v1.2.3 From e9e1143bdb5cb62db07c322aef446ef78974996d Mon Sep 17 00:00:00 2001 From: lwms <lwms@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Tue, 30 Apr 2002 04:51:03 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@134 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/inndBM.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/pttbbs/util/inndBM.c b/pttbbs/util/inndBM.c index 87b4d007..7a1f665c 100644 --- a/pttbbs/util/inndBM.c +++ b/pttbbs/util/inndBM.c @@ -15,6 +15,7 @@ #define INND_NEWSFEED INNDHOME "/newsfeeds.bbs" #define INND_NODELIST INNDHOME "/nodelist.bbs" +#define INND_BADFEED INNDHOME "/badfeeds.bbs" #define INND_SCRIPT INNDHOME "/bbsnnrpall.auto.sh" extern bcache_t *brdshm; @@ -84,12 +85,16 @@ int load_server() int load_newsfeeds() { int bid; - FILE *fp; + FILE *fp, *fo; char str[128]; if (!(fp = fopen(INND_NEWSFEED, "r"))) { return 0; } + if (!(fo = fopen(INND_BADFEED, "w"))) + { + return 0; + } for(feedcount=0; fgets(str, 128, fp); feedcount++) { @@ -98,7 +103,11 @@ int load_newsfeeds() feedline[feedcount].group,feedline[feedcount].board, feedline[feedcount].server); bid=getbnum(feedline[feedcount].board); - if(!bid) {feedcount--;continue; /*移除沒有的看板i*/} + if(!bid) { + fprintf(fo,"%s\n", feedline[feedcount].group ); + feedcount--; + continue; /*移除沒有的看板i*/} + strcpy(feedline[feedcount].board,bcache[bid-1].brdname); /*校正大小寫 */ @@ -106,6 +115,7 @@ int load_newsfeeds() } fclose(fp); + fclose(fo); qsort(feedline, feedcount, sizeof(newsfeed_t), newsfeed_cmp); return feedcount; } -- cgit v1.2.3 From 5610a8ee2ed22f622a228ae07f12c2e1318da2fe Mon Sep 17 00:00:00 2001 From: ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Tue, 30 Apr 2002 11:15:29 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@135 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/mail.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pttbbs/mbbsd/mail.c b/pttbbs/mbbsd/mail.c index 3fa7ae37..6a635f39 100644 --- a/pttbbs/mbbsd/mail.c +++ b/pttbbs/mbbsd/mail.c @@ -1,4 +1,4 @@ -/* $Id: mail.c,v 1.4 2002/04/29 07:05:45 in2 Exp $ */ +/* $Id: mail.c,v 1.5 2002/04/30 11:15:29 ptt Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -268,7 +268,7 @@ int do_send(char *userid, char *title) { return -3; if(!title) - getdata(2, 0, "主題:", save_title, STRLEN, DOECHO); + getdata(2, 0, "主題:", save_title, STRLEN-20, DOECHO); curredit |= EDIT_MAIL; curredit &= ~EDIT_ITEM; } -- cgit v1.2.3 From a283e777002e4a7bb07623656f2d6c45c9a4289c Mon Sep 17 00:00:00 2001 From: lwms <lwms@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Tue, 30 Apr 2002 13:20:56 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@136 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/xyz.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pttbbs/mbbsd/xyz.c b/pttbbs/mbbsd/xyz.c index 9ddbbe3e..ee70c303 100644 --- a/pttbbs/mbbsd/xyz.c +++ b/pttbbs/mbbsd/xyz.c @@ -1,4 +1,4 @@ -/* $Id: xyz.c,v 1.2 2002/04/28 19:35:29 in2 Exp $ */ +/* $Id: xyz.c,v 1.3 2002/04/30 13:20:56 lwms Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -133,7 +133,7 @@ int x_yesterday() { } int x_login() { - more("etc/Welcome_login", YEA); + more("etc/Welcome_login.0", YEA); return 0; } -- cgit v1.2.3 From 10530a16bbcbdd55fe4bb628d6798ef12a1b27b7 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Wed, 1 May 2002 04:36:00 +0000 Subject: change real_name[20] to real_name[IDLEN+2] for anonymous posting git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@137 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/bbs.c | 4 ++-- pttbbs/mbbsd/edit.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pttbbs/mbbsd/bbs.c b/pttbbs/mbbsd/bbs.c index eb252233..179aa720 100644 --- a/pttbbs/mbbsd/bbs.c +++ b/pttbbs/mbbsd/bbs.c @@ -1,4 +1,4 @@ -/* $Id: bbs.c,v 1.3 2002/04/29 07:05:45 in2 Exp $ */ +/* $Id: bbs.c,v 1.4 2002/05/01 04:36:00 in2 Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -386,7 +386,7 @@ static time_t last_post_time = 0; static time_t water_counts = 0; #endif int local_article; -char real_name[20]; +char real_name[IDLEN + 2]; static int do_general() { fileheader_t postfile; diff --git a/pttbbs/mbbsd/edit.c b/pttbbs/mbbsd/edit.c index 79ecf7f6..9d471a88 100644 --- a/pttbbs/mbbsd/edit.c +++ b/pttbbs/mbbsd/edit.c @@ -1,4 +1,4 @@ -/* $Id: edit.c,v 1.5 2002/04/28 19:35:29 in2 Exp $ */ +/* $Id: edit.c,v 1.6 2002/05/01 04:36:00 in2 Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -61,7 +61,7 @@ static textline_t *top_of_win = NULL; static textline_t *deleted_lines = NULL; extern int local_article; -extern char real_name[20]; +extern char real_name[IDLEN + 2]; static char line[WRAPMARGIN + 2]; static int ifuseanony=0; static int currpnt, currln, totaln; -- cgit v1.2.3 From cc7450c8ef320f2725c7d0e986f16c078c32ae27 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Wed, 1 May 2002 04:42:16 +0000 Subject: fix last commit git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@138 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/bbs.c | 4 ++-- pttbbs/mbbsd/edit.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pttbbs/mbbsd/bbs.c b/pttbbs/mbbsd/bbs.c index 179aa720..e8a2431b 100644 --- a/pttbbs/mbbsd/bbs.c +++ b/pttbbs/mbbsd/bbs.c @@ -1,4 +1,4 @@ -/* $Id: bbs.c,v 1.4 2002/05/01 04:36:00 in2 Exp $ */ +/* $Id: bbs.c,v 1.5 2002/05/01 04:42:16 in2 Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -386,7 +386,7 @@ static time_t last_post_time = 0; static time_t water_counts = 0; #endif int local_article; -char real_name[IDLEN + 2]; +char real_name[IDLEN + 1]; static int do_general() { fileheader_t postfile; diff --git a/pttbbs/mbbsd/edit.c b/pttbbs/mbbsd/edit.c index 9d471a88..9806526d 100644 --- a/pttbbs/mbbsd/edit.c +++ b/pttbbs/mbbsd/edit.c @@ -1,4 +1,4 @@ -/* $Id: edit.c,v 1.6 2002/05/01 04:36:00 in2 Exp $ */ +/* $Id: edit.c,v 1.7 2002/05/01 04:42:16 in2 Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -61,7 +61,7 @@ static textline_t *top_of_win = NULL; static textline_t *deleted_lines = NULL; extern int local_article; -extern char real_name[IDLEN + 2]; +extern char real_name[IDLEN + 1]; static char line[WRAPMARGIN + 2]; static int ifuseanony=0; static int currpnt, currln, totaln; -- cgit v1.2.3 From 2af37504f5980ac326b0e428d83e4077946b5185 Mon Sep 17 00:00:00 2001 From: lwms <lwms@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Thu, 2 May 2002 06:20:40 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@139 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/include/proto.h | 3 ++- pttbbs/mbbsd/cal.c | 19 ++++++++++++++++--- pttbbs/mbbsd/talk.c | 5 +++-- 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/pttbbs/include/proto.h b/pttbbs/include/proto.h index fa30e640..30585329 100644 --- a/pttbbs/include/proto.h +++ b/pttbbs/include/proto.h @@ -1,4 +1,4 @@ -/* $Id: proto.h,v 1.8 2002/04/18 22:42:23 in2 Exp $ */ +/* $Id: proto.h,v 1.9 2002/05/02 06:20:31 lwms Exp $ */ #ifndef INCLUDE_PROTO_H #define INCLUDE_PROTO_H @@ -113,6 +113,7 @@ char *cachepath(const char *fpath); int mdcacheopen(char *fpath); /* cal */ +int give_tax(int money); int vice(int money, char* item); int inumoney(char *tuser, int money); int cal(); diff --git a/pttbbs/mbbsd/cal.c b/pttbbs/mbbsd/cal.c index 6603925e..a5526783 100644 --- a/pttbbs/mbbsd/cal.c +++ b/pttbbs/mbbsd/cal.c @@ -1,4 +1,4 @@ -/* $Id: cal.c,v 1.2 2002/04/28 19:35:28 in2 Exp $ */ +/* $Id: cal.c,v 1.3 2002/05/02 06:20:40 lwms Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -365,8 +365,19 @@ void mail_redenvelop(char* from, char* to, int money, char mode){ append_record(genbuf, &fhdr, sizeof(fhdr)); } +/* 計算贈與稅 */ +int give_tax(int money) +{ + int tax = 0, tax_rate; + static int tax_bound[] = { 1000000, 100000, 10000, 1000 }; + for( tax_rate = 0; tax_rate <= 3; tax_rate++ ) + if ( money >= tax_bound[tax_rate] ) break; + tax = money * ( 0.5 - tax_rate/10.0 ); + return tax; +} + int p_give() { - int money; + int money, tax; char id[IDLEN + 1], genbuf[90]; time_t now = time(0); @@ -378,7 +389,8 @@ int p_give() { money = atoi(genbuf); reload_money(); if(money > 0 && cuser.money >= money ) { - deumoney(searchuser(id), money); + tax = give_tax(money); + deumoney(searchuser(id), money - tax); demoney(-money); now = time(NULL); sprintf(genbuf,"%s\t給%s\t%d\t%s", cuser.userid, id, money, @@ -387,6 +399,7 @@ int p_give() { genbuf[0] = 'n'; getdata(3, 0, "要自行書寫紅包袋嗎?[y/N]", genbuf, 2, LCECHO); mail_redenvelop(cuser.userid, id, money, genbuf[0]); + vice(tax, "贈與稅"); } return 0; } diff --git a/pttbbs/mbbsd/talk.c b/pttbbs/mbbsd/talk.c index 463f1f71..6da4a0d2 100644 --- a/pttbbs/mbbsd/talk.c +++ b/pttbbs/mbbsd/talk.c @@ -1,4 +1,4 @@ -/* $Id: talk.c,v 1.23 2002/04/28 19:35:29 in2 Exp $ */ +/* $Id: talk.c,v 1.24 2002/05/02 06:20:40 lwms Exp $ */ #include <stdio.h> #include <string.h> #include <errno.h> @@ -2100,7 +2100,7 @@ static void pickup_user(void) if (ch > cuser.money) outs("\033[41m 現金不足~~\033[m"); else{ - deumoney(uentp->uid, ch); + deumoney(uentp->uid, ch - give_tax(ch)); sprintf(genbuf, "\033[44m 嗯..還剩下 %d 錢.." "\033[m", demoney(-1*ch)); outs(genbuf); @@ -2109,6 +2109,7 @@ static void pickup_user(void) ctime(&currutmp->lastact)); log_file(FN_MONEY, genbuf); mail_redenvelop(cuser.userid, uentp->userid, ch, 'Y'); + vice(give_tax(ch), "贈與稅"); } } else{ -- cgit v1.2.3 From 6eb7851f5f0f027df41b711a4753fcaecbd33930 Mon Sep 17 00:00:00 2001 From: lwms <lwms@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Thu, 2 May 2002 06:27:40 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@140 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/cal.c | 4 ++-- pttbbs/mbbsd/talk.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pttbbs/mbbsd/cal.c b/pttbbs/mbbsd/cal.c index a5526783..139492e9 100644 --- a/pttbbs/mbbsd/cal.c +++ b/pttbbs/mbbsd/cal.c @@ -1,4 +1,4 @@ -/* $Id: cal.c,v 1.3 2002/05/02 06:20:40 lwms Exp $ */ +/* $Id: cal.c,v 1.4 2002/05/02 06:27:40 lwms Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -398,7 +398,7 @@ int p_give() { log_file(FN_MONEY, genbuf); genbuf[0] = 'n'; getdata(3, 0, "要自行書寫紅包袋嗎?[y/N]", genbuf, 2, LCECHO); - mail_redenvelop(cuser.userid, id, money, genbuf[0]); + mail_redenvelop(cuser.userid, id, money - tax, genbuf[0]); vice(tax, "贈與稅"); } return 0; diff --git a/pttbbs/mbbsd/talk.c b/pttbbs/mbbsd/talk.c index 6da4a0d2..643a3d86 100644 --- a/pttbbs/mbbsd/talk.c +++ b/pttbbs/mbbsd/talk.c @@ -1,4 +1,4 @@ -/* $Id: talk.c,v 1.24 2002/05/02 06:20:40 lwms Exp $ */ +/* $Id: talk.c,v 1.25 2002/05/02 06:27:40 lwms Exp $ */ #include <stdio.h> #include <string.h> #include <errno.h> @@ -2108,7 +2108,7 @@ static void pickup_user(void) uentp->userid, ch, ctime(&currutmp->lastact)); log_file(FN_MONEY, genbuf); - mail_redenvelop(cuser.userid, uentp->userid, ch, 'Y'); + mail_redenvelop(cuser.userid, uentp->userid, ch - give_tax(ch), 'Y'); vice(give_tax(ch), "贈與稅"); } } -- cgit v1.2.3 From 436f5e71231ea10b9a009d00e5b0e9f62daa8caa Mon Sep 17 00:00:00 2001 From: lwms <lwms@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Thu, 2 May 2002 06:30:22 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@141 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/cal.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pttbbs/mbbsd/cal.c b/pttbbs/mbbsd/cal.c index 139492e9..6319ca50 100644 --- a/pttbbs/mbbsd/cal.c +++ b/pttbbs/mbbsd/cal.c @@ -1,4 +1,4 @@ -/* $Id: cal.c,v 1.4 2002/05/02 06:27:40 lwms Exp $ */ +/* $Id: cal.c,v 1.5 2002/05/02 06:30:22 lwms Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -373,7 +373,7 @@ int give_tax(int money) for( tax_rate = 0; tax_rate <= 3; tax_rate++ ) if ( money >= tax_bound[tax_rate] ) break; tax = money * ( 0.5 - tax_rate/10.0 ); - return tax; + return tax <= 0 ? 1 : tax; } int p_give() { -- cgit v1.2.3 From a663a5ea1d72400af51d7ac843763dc239d3891b Mon Sep 17 00:00:00 2001 From: lwms <lwms@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Thu, 2 May 2002 06:41:46 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@142 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/cal.c | 7 ++++--- pttbbs/mbbsd/talk.c | 4 ++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/pttbbs/mbbsd/cal.c b/pttbbs/mbbsd/cal.c index 6319ca50..c3d2303f 100644 --- a/pttbbs/mbbsd/cal.c +++ b/pttbbs/mbbsd/cal.c @@ -1,4 +1,4 @@ -/* $Id: cal.c,v 1.5 2002/05/02 06:30:22 lwms Exp $ */ +/* $Id: cal.c,v 1.6 2002/05/02 06:41:46 lwms Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -369,7 +369,7 @@ void mail_redenvelop(char* from, char* to, int money, char mode){ int give_tax(int money) { int tax = 0, tax_rate; - static int tax_bound[] = { 1000000, 100000, 10000, 1000 }; + static int tax_bound[] = { 1000000, 100000, 10000, 1000}; for( tax_rate = 0; tax_rate <= 3; tax_rate++ ) if ( money >= tax_bound[tax_rate] ) break; tax = money * ( 0.5 - tax_rate/10.0 ); @@ -390,10 +390,11 @@ int p_give() { reload_money(); if(money > 0 && cuser.money >= money ) { tax = give_tax(money); + if ( money - tax <= 0 ) return 0; /* 繳完稅就沒錢給了 */ deumoney(searchuser(id), money - tax); demoney(-money); now = time(NULL); - sprintf(genbuf,"%s\t給%s\t%d\t%s", cuser.userid, id, money, + sprintf(genbuf,"%s\t給%s\t%d\t%s", cuser.userid, id, money - tax, ctime(&now)); log_file(FN_MONEY, genbuf); genbuf[0] = 'n'; diff --git a/pttbbs/mbbsd/talk.c b/pttbbs/mbbsd/talk.c index 643a3d86..ddedb827 100644 --- a/pttbbs/mbbsd/talk.c +++ b/pttbbs/mbbsd/talk.c @@ -1,4 +1,4 @@ -/* $Id: talk.c,v 1.25 2002/05/02 06:27:40 lwms Exp $ */ +/* $Id: talk.c,v 1.26 2002/05/02 06:41:46 lwms Exp $ */ #include <stdio.h> #include <string.h> #include <errno.h> @@ -2094,7 +2094,7 @@ static void pickup_user(void) if (getdata(b_lines - 1, 0, "[銀行轉帳]:", genbuf, 7, LCECHO)){ clrtoeol(); - if ((ch = atoi(genbuf)) <= 0) + if ((ch = atoi(genbuf)) <= 0 || ch == give_tax(ch) ) break; reload_money(); if (ch > cuser.money) -- cgit v1.2.3 From b67bd5350c931869050b2e1a39f8dca7fcd3554c Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Thu, 2 May 2002 17:24:35 +0000 Subject: show current pid if DEBUG git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@143 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/menu.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/pttbbs/mbbsd/menu.c b/pttbbs/mbbsd/menu.c index 19378b15..a765adae 100644 --- a/pttbbs/mbbsd/menu.c +++ b/pttbbs/mbbsd/menu.c @@ -1,9 +1,10 @@ -/* $Id: menu.c,v 1.3 2002/03/17 09:18:23 in2 Exp $ */ +/* $Id: menu.c,v 1.4 2002/05/02 17:24:35 in2 Exp $ */ #include <stdio.h> #include <stdlib.h> #include <time.h> #include <sys/types.h> #include <string.h> +#include <unistd.h> #include "config.h" #include "pttstruct.h" #include "common.h" @@ -55,6 +56,14 @@ void showtitle(char *title, char *mid) { spc = strlen(mid); if(title[0] == 0) title++; +#ifdef DEBUG + else{ + sprintf(numreg, "\033[41;5m current pid: %6d " TITLE_COLOR, + getpid()); + mid = numreg; + spc = 22; + } +#else else if(currutmp->mailalert) { mid = "\033[41;5m 郵差來按鈴囉 " TITLE_COLOR; spc = 22; @@ -65,6 +74,7 @@ void showtitle(char *title, char *mid) { mid = numreg; spc = 22; } +#endif spc = 66 - strlen(title) - spc - strlen(currboard); if(spc < 0) spc = 0; -- cgit v1.2.3 From dd4767f3ae6643fe8e7da1f27b6dab17e3c2279b Mon Sep 17 00:00:00 2001 From: lwms <lwms@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Fri, 3 May 2002 01:25:11 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@144 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/cal.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/pttbbs/mbbsd/cal.c b/pttbbs/mbbsd/cal.c index c3d2303f..6853ec64 100644 --- a/pttbbs/mbbsd/cal.c +++ b/pttbbs/mbbsd/cal.c @@ -1,4 +1,4 @@ -/* $Id: cal.c,v 1.6 2002/05/02 06:41:46 lwms Exp $ */ +/* $Id: cal.c,v 1.7 2002/05/03 01:25:11 lwms Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -368,11 +368,12 @@ void mail_redenvelop(char* from, char* to, int money, char mode){ /* 計算贈與稅 */ int give_tax(int money) { - int tax = 0, tax_rate; - static int tax_bound[] = { 1000000, 100000, 10000, 1000}; - for( tax_rate = 0; tax_rate <= 3; tax_rate++ ) - if ( money >= tax_bound[tax_rate] ) break; - tax = money * ( 0.5 - tax_rate/10.0 ); + int i, tax = 0; + static int tax_bound[] = { 1000000, 100000, 10000, 1000, 0}; + static double tax_rate[] = { 0.4, 0.3, 0.2, 0.1, 0.05 }; + for( i = 0; money < tax_bound[i]; i++ ) + ; + tax = money * tax_rate[i]; return tax <= 0 ? 1 : tax; } -- cgit v1.2.3 From eec2d0b5a34dd9cc232d27fa4563e731b2bbe7c1 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sat, 4 May 2002 13:50:26 +0000 Subject: avoid infinite loop git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@145 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/cache.c | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/pttbbs/mbbsd/cache.c b/pttbbs/mbbsd/cache.c index dd00d010..fef81942 100644 --- a/pttbbs/mbbsd/cache.c +++ b/pttbbs/mbbsd/cache.c @@ -1,4 +1,4 @@ -/* $Id: cache.c,v 1.21 2002/04/28 19:35:28 in2 Exp $ */ +/* $Id: cache.c,v 1.22 2002/05/04 13:50:26 in2 Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -165,13 +165,17 @@ void attach_uhash() { void add_to_uhash(int n, char *id) { int *p, h = StringHash(id); + int times; strcpy(uhash->userid[n], id); p = &(uhash->hash_head[h]); - - while(*p != -1) + + for( times = 0 ; times < MAX_USERS && *p != -1 ; ++times ) p = &(uhash->next_in_hash[*p]); - + + if( times == MAX_USERS ) + abort_bbs(0); + uhash->next_in_hash[*p = n] = -1; } @@ -180,9 +184,14 @@ void add_to_uhash(int n, char *id) { void remove_from_uhash(int n) { int h = StringHash(uhash->userid[n]); int *p = &(uhash->hash_head[h]); - - while(*p != -1 && *p != n) + int times; + + for( times = 0 ; times < MAX_USERS && (*p != -1 && *p != n); ++times ) p = &(uhash->next_in_hash[*p]); + + if( times == MAX_USERS ) + abort_bbs(0); + if(*p == n) *p = uhash->next_in_hash[n]; } @@ -207,18 +216,18 @@ int moneyof(int uid){ /* ptt return uhash->money[uid-1]; } int searchuser(char *userid) { - int h,p; - + int h, p, times; h = StringHash(userid); p = uhash->hash_head[h]; - while(p != -1) { + for( times = 0 ; times < MAX_USERS && p != -1 ; ++times ){ if(strcasecmp(uhash->userid[p],userid) == 0) { strcpy(userid,uhash->userid[p]); return p + 1; } p = uhash->next_in_hash[p]; } + return 0; } -- cgit v1.2.3 From e75ab602c87e10400e6b2b8238c780df04254f3a Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sun, 5 May 2002 19:17:01 +0000 Subject: NO_SHOWPID git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@146 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd.icc/Makefile | 4 ++++ pttbbs/mbbsd/menu.c | 4 +++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/pttbbs/mbbsd.icc/Makefile b/pttbbs/mbbsd.icc/Makefile index 9247b770..02f34a63 100644 --- a/pttbbs/mbbsd.icc/Makefile +++ b/pttbbs/mbbsd.icc/Makefile @@ -22,6 +22,10 @@ CFLAGS+= -O LDFLAGS+= -O .endif +.if defined(NO_SHOWPID) +CFLAGS+= -DNO_SHOWPID +.endif + .if defined(NO_FORK) CFLAGS+= -DNO_FORK .endif diff --git a/pttbbs/mbbsd/menu.c b/pttbbs/mbbsd/menu.c index a765adae..a6cfdb5e 100644 --- a/pttbbs/mbbsd/menu.c +++ b/pttbbs/mbbsd/menu.c @@ -1,4 +1,4 @@ -/* $Id: menu.c,v 1.4 2002/05/02 17:24:35 in2 Exp $ */ +/* $Id: menu.c,v 1.5 2002/05/05 19:16:59 in2 Exp $ */ #include <stdio.h> #include <stdlib.h> #include <time.h> @@ -57,12 +57,14 @@ void showtitle(char *title, char *mid) { if(title[0] == 0) title++; #ifdef DEBUG +#ifndef NO_SHOWPID else{ sprintf(numreg, "\033[41;5m current pid: %6d " TITLE_COLOR, getpid()); mid = numreg; spc = 22; } +#endif #else else if(currutmp->mailalert) { mid = "\033[41;5m 郵差來按鈴囉 " TITLE_COLOR; -- cgit v1.2.3 From abe06bec10e6ef8f3ce5342b77bbc54bb15e5ba4 Mon Sep 17 00:00:00 2001 From: lwms <lwms@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Mon, 6 May 2002 09:17:02 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@147 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/cal.c | 4 ++-- pttbbs/mbbsd/talk.c | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/pttbbs/mbbsd/cal.c b/pttbbs/mbbsd/cal.c index 6853ec64..1e939641 100644 --- a/pttbbs/mbbsd/cal.c +++ b/pttbbs/mbbsd/cal.c @@ -1,4 +1,4 @@ -/* $Id: cal.c,v 1.7 2002/05/03 01:25:11 lwms Exp $ */ +/* $Id: cal.c,v 1.8 2002/05/06 09:17:02 lwms Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -393,7 +393,7 @@ int p_give() { tax = give_tax(money); if ( money - tax <= 0 ) return 0; /* 繳完稅就沒錢給了 */ deumoney(searchuser(id), money - tax); - demoney(-money); + demoney(-(money - tax )); now = time(NULL); sprintf(genbuf,"%s\t給%s\t%d\t%s", cuser.userid, id, money - tax, ctime(&now)); diff --git a/pttbbs/mbbsd/talk.c b/pttbbs/mbbsd/talk.c index ddedb827..80e66b0c 100644 --- a/pttbbs/mbbsd/talk.c +++ b/pttbbs/mbbsd/talk.c @@ -1,4 +1,4 @@ -/* $Id: talk.c,v 1.26 2002/05/02 06:41:46 lwms Exp $ */ +/* $Id: talk.c,v 1.27 2002/05/06 09:17:02 lwms Exp $ */ #include <stdio.h> #include <string.h> #include <errno.h> @@ -2094,7 +2094,7 @@ static void pickup_user(void) if (getdata(b_lines - 1, 0, "[銀行轉帳]:", genbuf, 7, LCECHO)){ clrtoeol(); - if ((ch = atoi(genbuf)) <= 0 || ch == give_tax(ch) ) + if ((ch = atoi(genbuf)) <= 0 || ch <= give_tax(ch) ) break; reload_money(); if (ch > cuser.money) @@ -2102,7 +2102,7 @@ static void pickup_user(void) else{ deumoney(uentp->uid, ch - give_tax(ch)); sprintf(genbuf, "\033[44m 嗯..還剩下 %d 錢.." - "\033[m", demoney(-1*ch)); + "\033[m", demoney(-1*(ch - give_tax(ch)))); outs(genbuf); sprintf(genbuf, "%s\t給%s\t%d\t%s", cuser.userid, uentp->userid, ch, -- cgit v1.2.3 From f3df09236f1f961ed8580c26172a1a7fd1c322e4 Mon Sep 17 00:00:00 2001 From: ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Mon, 6 May 2002 13:34:11 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@148 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/xyz.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/pttbbs/mbbsd/xyz.c b/pttbbs/mbbsd/xyz.c index ee70c303..1cac394a 100644 --- a/pttbbs/mbbsd/xyz.c +++ b/pttbbs/mbbsd/xyz.c @@ -1,4 +1,4 @@ -/* $Id: xyz.c,v 1.3 2002/04/30 13:20:56 lwms Exp $ */ +/* $Id: xyz.c,v 1.4 2002/05/06 13:34:11 ptt Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -151,7 +151,6 @@ static int x_gpl() { } #endif -/* 離開 BBS 站 */ int note() { static char *fn_note_tmp = "note.tmp"; static char *fn_note_dat = "note.dat"; @@ -183,7 +182,7 @@ int note() { clrtobot(); outs("\n投五銀... 嗶... 請留言 (至多三行),按[Enter]結束"); for(i = 0; (i < 3) && getdata(16 + i, 0, ":", myitem.buf[i], - sizeof(myitem.buf[i]), DOECHO) + sizeof(myitem.buf[i])-5, DOECHO) && *myitem.buf[i]; i++); getdata(b_lines - 1, 0, "(S)儲存 (E)重新來過 (Q)取消?[S] ", buf, 3, LCECHO); -- cgit v1.2.3 From c3b7849cae2d957c677ef31336fc7477d1ac25ae Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Mon, 6 May 2002 17:26:20 +0000 Subject: fix title git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@149 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/menu.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/pttbbs/mbbsd/menu.c b/pttbbs/mbbsd/menu.c index a6cfdb5e..59668377 100644 --- a/pttbbs/mbbsd/menu.c +++ b/pttbbs/mbbsd/menu.c @@ -1,4 +1,4 @@ -/* $Id: menu.c,v 1.5 2002/05/05 19:16:59 in2 Exp $ */ +/* $Id: menu.c,v 1.6 2002/05/06 17:26:20 in2 Exp $ */ #include <stdio.h> #include <stdlib.h> #include <time.h> @@ -56,15 +56,13 @@ void showtitle(char *title, char *mid) { spc = strlen(mid); if(title[0] == 0) title++; -#ifdef DEBUG -#ifndef NO_SHOWPID +#ifdef DEBUG && !NO_SHOWPID else{ sprintf(numreg, "\033[41;5m current pid: %6d " TITLE_COLOR, getpid()); mid = numreg; spc = 22; } -#endif #else else if(currutmp->mailalert) { mid = "\033[41;5m 郵差來按鈴囉 " TITLE_COLOR; -- cgit v1.2.3 From 6d043a88c624d10ef2dc1e4c2a21fa4dd6ad379c Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Mon, 6 May 2002 17:27:33 +0000 Subject: remove SHOWPID git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@150 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd.icc/Makefile | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/pttbbs/mbbsd.icc/Makefile b/pttbbs/mbbsd.icc/Makefile index 02f34a63..c260ac68 100644 --- a/pttbbs/mbbsd.icc/Makefile +++ b/pttbbs/mbbsd.icc/Makefile @@ -11,8 +11,8 @@ OBJS= admin.o announce.o args.o bbcall.o bbs.o board.o cache.o cal.o card.o\ voteboard.o syspost.o var.o descrypt.o toolkit.o passwd.o\ calendar.o -CFLAGS=-DHAVE_SETPROCTITLE -DBBSHOME='"$(BBSHOME)"' -DFreeBSD -I../include -LDFLAGS=-lutil -lkvm +CFLAGS= -DHAVE_SETPROCTITLE -DBBSHOME='"$(BBSHOME)"' -DFreeBSD -I../include +LDFLAGS= -lutil -lkvm .if defined(DEBUG) CFLAGS+= -g -DDEBUG @@ -22,10 +22,6 @@ CFLAGS+= -O LDFLAGS+= -O .endif -.if defined(NO_SHOWPID) -CFLAGS+= -DNO_SHOWPID -.endif - .if defined(NO_FORK) CFLAGS+= -DNO_FORK .endif -- cgit v1.2.3 From 0d92b04cee489b7ac3a7dbd21df5c1153aec94ae Mon Sep 17 00:00:00 2001 From: lwms <lwms@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Tue, 7 May 2002 08:15:16 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@151 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/talk.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pttbbs/mbbsd/talk.c b/pttbbs/mbbsd/talk.c index 80e66b0c..0c82bc2f 100644 --- a/pttbbs/mbbsd/talk.c +++ b/pttbbs/mbbsd/talk.c @@ -1,4 +1,4 @@ -/* $Id: talk.c,v 1.27 2002/05/06 09:17:02 lwms Exp $ */ +/* $Id: talk.c,v 1.28 2002/05/07 08:15:16 lwms Exp $ */ #include <stdio.h> #include <string.h> #include <errno.h> @@ -2101,6 +2101,7 @@ static void pickup_user(void) outs("\033[41m 現金不足~~\033[m"); else{ deumoney(uentp->uid, ch - give_tax(ch)); + vice(give_tax(ch), "贈與稅"); sprintf(genbuf, "\033[44m 嗯..還剩下 %d 錢.." "\033[m", demoney(-1*(ch - give_tax(ch)))); outs(genbuf); @@ -2109,7 +2110,6 @@ static void pickup_user(void) ctime(&currutmp->lastact)); log_file(FN_MONEY, genbuf); mail_redenvelop(cuser.userid, uentp->userid, ch - give_tax(ch), 'Y'); - vice(give_tax(ch), "贈與稅"); } } else{ -- cgit v1.2.3 From 694771f7da11be5dc25d5d3256fffc23ff8cc901 Mon Sep 17 00:00:00 2001 From: lwms <lwms@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Wed, 8 May 2002 12:06:06 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@152 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/include/proto.h | 3 ++- pttbbs/mbbsd/admin.c | 3 ++- pttbbs/mbbsd/syspost.c | 27 ++++++++++++++++++++++++++- 3 files changed, 30 insertions(+), 3 deletions(-) diff --git a/pttbbs/include/proto.h b/pttbbs/include/proto.h index 30585329..df355e4a 100644 --- a/pttbbs/include/proto.h +++ b/pttbbs/include/proto.h @@ -1,4 +1,4 @@ -/* $Id: proto.h,v 1.9 2002/05/02 06:20:31 lwms Exp $ */ +/* $Id: proto.h,v 1.10 2002/05/08 12:06:06 lwms Exp $ */ #ifndef INCLUDE_PROTO_H #define INCLUDE_PROTO_H @@ -412,6 +412,7 @@ int is_uBM(char *list, char *id); void post_newboard(char *bgroup, char *bname, char *bms); void post_violatelaw(char *crime, char *police, char *reason, char *result); void post_change_perm(int oldperm, int newperm, char *sysopid, char *userid); +void post_give_money(char *sysopid, char *userid, int money); /* talk */ int cmpwatermtime(const void *a, const void *b); diff --git a/pttbbs/mbbsd/admin.c b/pttbbs/mbbsd/admin.c index 2d66bfe4..df1256a4 100644 --- a/pttbbs/mbbsd/admin.c +++ b/pttbbs/mbbsd/admin.c @@ -1,4 +1,4 @@ -/* $Id: admin.c,v 1.7 2002/04/28 19:35:28 in2 Exp $ */ +/* $Id: admin.c,v 1.8 2002/05/08 12:04:49 lwms Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -1092,6 +1092,7 @@ int give_money() { continue; id = uhash->userid[i]; give_id_money(id, money, fp2, tt, t); + post_give_money(cuser.userid , id, money); } } else { if(!(fp = fopen("etc/givemoney.txt", "r+"))) { diff --git a/pttbbs/mbbsd/syspost.c b/pttbbs/mbbsd/syspost.c index 474e8b65..a2cdcea8 100644 --- a/pttbbs/mbbsd/syspost.c +++ b/pttbbs/mbbsd/syspost.c @@ -1,4 +1,4 @@ -/* $Id: syspost.c,v 1.3 2002/04/28 19:35:29 in2 Exp $ */ +/* $Id: syspost.c,v 1.4 2002/05/08 12:04:49 lwms Exp $ */ #include <stdio.h> #include <string.h> #include <time.h> @@ -100,3 +100,28 @@ void post_newboard(char* bgroup, char* bname, char* bms){ cuser.userid, bname, bgroup, bms); post_msg("Record", title, genbuf, "[系統]"); } + +void post_give_money(char *sysopid, char *userid, int money) { + FILE *fp; + fileheader_t fhdr; + time_t now = time(0); + char genbuf[200]; + + strcpy(genbuf, "boards/S/Security"); + stampfile(genbuf, &fhdr); + if(!(fp = fopen(genbuf,"w"))) + return; + + fprintf(fp, "作者: [系統安全局] 看板: Security\n" + "標題: [公安報告] 紅包機使用報告\n" + "時間: %s\n", ctime(&now)); + fprintf (fp, " 站長\033[1;32m%s給%s\033[m%d元\n", + sysopid, userid, money); + + sprintf(fhdr.title, "[公安報告] 站長%s使用紅包機報告", + cuser.userid); + strcpy(fhdr.owner, "[系統安全局]"); + append_record("boards/S/Security/.DIR", &fhdr, sizeof(fhdr)); +} + + -- cgit v1.2.3 From b9f094ed2f97af55e6d885023f6f4d91e31f4d73 Mon Sep 17 00:00:00 2001 From: lwms <lwms@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Wed, 8 May 2002 14:11:33 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@153 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/include/proto.h | 3 +-- pttbbs/mbbsd/admin.c | 3 +-- pttbbs/mbbsd/syspost.c | 26 +------------------------- 3 files changed, 3 insertions(+), 29 deletions(-) diff --git a/pttbbs/include/proto.h b/pttbbs/include/proto.h index df355e4a..70c40fe1 100644 --- a/pttbbs/include/proto.h +++ b/pttbbs/include/proto.h @@ -1,4 +1,4 @@ -/* $Id: proto.h,v 1.10 2002/05/08 12:06:06 lwms Exp $ */ +/* $Id: proto.h,v 1.11 2002/05/08 14:11:26 lwms Exp $ */ #ifndef INCLUDE_PROTO_H #define INCLUDE_PROTO_H @@ -412,7 +412,6 @@ int is_uBM(char *list, char *id); void post_newboard(char *bgroup, char *bname, char *bms); void post_violatelaw(char *crime, char *police, char *reason, char *result); void post_change_perm(int oldperm, int newperm, char *sysopid, char *userid); -void post_give_money(char *sysopid, char *userid, int money); /* talk */ int cmpwatermtime(const void *a, const void *b); diff --git a/pttbbs/mbbsd/admin.c b/pttbbs/mbbsd/admin.c index df1256a4..815bb854 100644 --- a/pttbbs/mbbsd/admin.c +++ b/pttbbs/mbbsd/admin.c @@ -1,4 +1,4 @@ -/* $Id: admin.c,v 1.8 2002/05/08 12:04:49 lwms Exp $ */ +/* $Id: admin.c,v 1.9 2002/05/08 14:11:33 lwms Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -1092,7 +1092,6 @@ int give_money() { continue; id = uhash->userid[i]; give_id_money(id, money, fp2, tt, t); - post_give_money(cuser.userid , id, money); } } else { if(!(fp = fopen("etc/givemoney.txt", "r+"))) { diff --git a/pttbbs/mbbsd/syspost.c b/pttbbs/mbbsd/syspost.c index a2cdcea8..c7bd163b 100644 --- a/pttbbs/mbbsd/syspost.c +++ b/pttbbs/mbbsd/syspost.c @@ -1,4 +1,4 @@ -/* $Id: syspost.c,v 1.4 2002/05/08 12:04:49 lwms Exp $ */ +/* $Id: syspost.c,v 1.5 2002/05/08 14:11:33 lwms Exp $ */ #include <stdio.h> #include <string.h> #include <time.h> @@ -101,27 +101,3 @@ void post_newboard(char* bgroup, char* bname, char* bms){ post_msg("Record", title, genbuf, "[系統]"); } -void post_give_money(char *sysopid, char *userid, int money) { - FILE *fp; - fileheader_t fhdr; - time_t now = time(0); - char genbuf[200]; - - strcpy(genbuf, "boards/S/Security"); - stampfile(genbuf, &fhdr); - if(!(fp = fopen(genbuf,"w"))) - return; - - fprintf(fp, "作者: [系統安全局] 看板: Security\n" - "標題: [公安報告] 紅包機使用報告\n" - "時間: %s\n", ctime(&now)); - fprintf (fp, " 站長\033[1;32m%s給%s\033[m%d元\n", - sysopid, userid, money); - - sprintf(fhdr.title, "[公安報告] 站長%s使用紅包機報告", - cuser.userid); - strcpy(fhdr.owner, "[系統安全局]"); - append_record("boards/S/Security/.DIR", &fhdr, sizeof(fhdr)); -} - - -- cgit v1.2.3 From 827ce2d5020bb4a618d81bf9cbb0c2737c764a00 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Wed, 8 May 2002 22:31:10 +0000 Subject: flag DEBUG, GDB git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@154 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd.icc/Makefile | 11 ++++++++--- pttbbs/mbbsd/Makefile | 13 +++++++++---- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/pttbbs/mbbsd.icc/Makefile b/pttbbs/mbbsd.icc/Makefile index c260ac68..d0cabb11 100644 --- a/pttbbs/mbbsd.icc/Makefile +++ b/pttbbs/mbbsd.icc/Makefile @@ -14,14 +14,19 @@ OBJS= admin.o announce.o args.o bbcall.o bbs.o board.o cache.o cal.o card.o\ CFLAGS= -DHAVE_SETPROCTITLE -DBBSHOME='"$(BBSHOME)"' -DFreeBSD -I../include LDFLAGS= -lutil -lkvm -.if defined(DEBUG) -CFLAGS+= -g -DDEBUG -LDFLAGS+= -g -DDEBUG +.if defined(GDB) || defined(DEBUG) +CFLAGS+= -g +FDFLAGS+= -g .else CFLAGS+= -O LDFLAGS+= -O .endif +.if defined(DEBUG) +CFLAGS+= -DDEBUG +LDFLAGS+= -DDEBUG +.endif + .if defined(NO_FORK) CFLAGS+= -DNO_FORK .endif diff --git a/pttbbs/mbbsd/Makefile b/pttbbs/mbbsd/Makefile index 531488a4..017f3d42 100644 --- a/pttbbs/mbbsd/Makefile +++ b/pttbbs/mbbsd/Makefile @@ -1,4 +1,4 @@ -# $Id: Makefile,v 1.6 2002/04/28 14:29:26 in2 Exp $ +# $Id: Makefile,v 1.7 2002/05/08 22:30:58 in2 Exp $ BBSHOME?=$(HOME) OSTYPE=FreeBSD @@ -17,14 +17,19 @@ CFLAGS= $(CFLAGS_$(OSTYPE)) LDFLAGS=$(LDFLAGS_$(OSTYPE)) LIBS= $(LIBS_$(OSTYPE)) -.if defined(DEBUG) -CFLAGS+= -g -DDEBUG -LDFLAGS+= -g -DDEBUG +.if defined(GDB) || defined(DEBUG) +CFLAGS+= -g +FDFLAGS+= -g .else CFLAGS+= -O LDFLAGS+= -O .endif +.if defined(DEBUG) +CFLAGS+= -DDEBUG +LDFLAGS+= -DDEBUG +.endif + .if defined(NO_FORK) CFLAGS+= -DNO_FORK .endif -- cgit v1.2.3 From d382c57ed318cf49d068b1b4aa35b0f712e84c58 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Wed, 8 May 2002 22:31:23 +0000 Subject: DEBUG to show current pid git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@155 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/menu.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pttbbs/mbbsd/menu.c b/pttbbs/mbbsd/menu.c index 59668377..f65a1e89 100644 --- a/pttbbs/mbbsd/menu.c +++ b/pttbbs/mbbsd/menu.c @@ -1,4 +1,4 @@ -/* $Id: menu.c,v 1.6 2002/05/06 17:26:20 in2 Exp $ */ +/* $Id: menu.c,v 1.7 2002/05/08 22:31:23 in2 Exp $ */ #include <stdio.h> #include <stdlib.h> #include <time.h> @@ -56,7 +56,7 @@ void showtitle(char *title, char *mid) { spc = strlen(mid); if(title[0] == 0) title++; -#ifdef DEBUG && !NO_SHOWPID +#ifdef DEBUG else{ sprintf(numreg, "\033[41;5m current pid: %6d " TITLE_COLOR, getpid()); -- cgit v1.2.3 From 96e327e20d4d90d4b738b6953332533070e7ed82 Mon Sep 17 00:00:00 2001 From: lwms <lwms@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Fri, 10 May 2002 02:11:12 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@156 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/cal.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/pttbbs/mbbsd/cal.c b/pttbbs/mbbsd/cal.c index 1e939641..69bab70e 100644 --- a/pttbbs/mbbsd/cal.c +++ b/pttbbs/mbbsd/cal.c @@ -1,4 +1,4 @@ -/* $Id: cal.c,v 1.8 2002/05/06 09:17:02 lwms Exp $ */ +/* $Id: cal.c,v 1.9 2002/05/10 02:11:12 lwms Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -370,11 +370,13 @@ int give_tax(int money) { int i, tax = 0; static int tax_bound[] = { 1000000, 100000, 10000, 1000, 0}; - static double tax_rate[] = { 0.4, 0.3, 0.2, 0.1, 0.05 }; - for( i = 0; money < tax_bound[i]; i++ ) - ; - tax = money * tax_rate[i]; - return tax <= 0 ? 1 : tax; + static double tax_rate[] = { 0.4, 0.3, 0.2, 0.1, 0.08 }; + for( i = 0; i <= 4 ; i++ ) + if ( money > tax_bound[i] ) { + tax += (money - tax_bound[i]) * tax_rate[i]; + money -= (money - tax_bound[i]); + } + return (tax <= 0) ? 1 : tax; } int p_give() { @@ -394,6 +396,7 @@ int p_give() { if ( money - tax <= 0 ) return 0; /* 繳完稅就沒錢給了 */ deumoney(searchuser(id), money - tax); demoney(-(money - tax )); + vice(tax, "贈與稅"); now = time(NULL); sprintf(genbuf,"%s\t給%s\t%d\t%s", cuser.userid, id, money - tax, ctime(&now)); @@ -401,7 +404,6 @@ int p_give() { genbuf[0] = 'n'; getdata(3, 0, "要自行書寫紅包袋嗎?[y/N]", genbuf, 2, LCECHO); mail_redenvelop(cuser.userid, id, money - tax, genbuf[0]); - vice(tax, "贈與稅"); } return 0; } -- cgit v1.2.3 From 8a78573d2d53e52e1225a0d185e17493728b55e3 Mon Sep 17 00:00:00 2001 From: lwms <lwms@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Fri, 10 May 2002 12:36:00 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@157 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/cal.c | 5 ++--- pttbbs/mbbsd/talk.c | 5 ++--- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/pttbbs/mbbsd/cal.c b/pttbbs/mbbsd/cal.c index 69bab70e..78204dc9 100644 --- a/pttbbs/mbbsd/cal.c +++ b/pttbbs/mbbsd/cal.c @@ -1,4 +1,4 @@ -/* $Id: cal.c,v 1.9 2002/05/10 02:11:12 lwms Exp $ */ +/* $Id: cal.c,v 1.10 2002/05/10 12:36:00 lwms Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -395,8 +395,7 @@ int p_give() { tax = give_tax(money); if ( money - tax <= 0 ) return 0; /* 繳完稅就沒錢給了 */ deumoney(searchuser(id), money - tax); - demoney(-(money - tax )); - vice(tax, "贈與稅"); + demoney(-money); now = time(NULL); sprintf(genbuf,"%s\t給%s\t%d\t%s", cuser.userid, id, money - tax, ctime(&now)); diff --git a/pttbbs/mbbsd/talk.c b/pttbbs/mbbsd/talk.c index 0c82bc2f..21b60a08 100644 --- a/pttbbs/mbbsd/talk.c +++ b/pttbbs/mbbsd/talk.c @@ -1,4 +1,4 @@ -/* $Id: talk.c,v 1.28 2002/05/07 08:15:16 lwms Exp $ */ +/* $Id: talk.c,v 1.29 2002/05/10 12:36:00 lwms Exp $ */ #include <stdio.h> #include <string.h> #include <errno.h> @@ -2101,9 +2101,8 @@ static void pickup_user(void) outs("\033[41m 現金不足~~\033[m"); else{ deumoney(uentp->uid, ch - give_tax(ch)); - vice(give_tax(ch), "贈與稅"); sprintf(genbuf, "\033[44m 嗯..還剩下 %d 錢.." - "\033[m", demoney(-1*(ch - give_tax(ch)))); + "\033[m", demoney(-ch)); outs(genbuf); sprintf(genbuf, "%s\t給%s\t%d\t%s", cuser.userid, uentp->userid, ch, -- cgit v1.2.3 From 49a6ee97f274776120b00575e2476f21844ad67b Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Fri, 10 May 2002 16:15:50 +0000 Subject: safe-memory all board complete git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@158 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/include/proto.h | 3 +- pttbbs/mbbsd/bbs.c | 11 +++- pttbbs/mbbsd/name.c | 170 ++++++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 180 insertions(+), 4 deletions(-) diff --git a/pttbbs/include/proto.h b/pttbbs/include/proto.h index 70c40fe1..a65293f4 100644 --- a/pttbbs/include/proto.h +++ b/pttbbs/include/proto.h @@ -1,4 +1,4 @@ -/* $Id: proto.h,v 1.11 2002/05/08 14:11:26 lwms Exp $ */ +/* $Id: proto.h,v 1.12 2002/05/10 16:15:47 in2 Exp $ */ #ifndef INCLUDE_PROTO_H #define INCLUDE_PROTO_H @@ -295,6 +295,7 @@ int InNameList(char *name); void ShowNameList(int row, int column, char *prompt); int RemoveNameList(char *name); void ToggleNameList(int *reciper, char *listfile, char *msg); +void allboardcomplete(char *prompt, char *data, int len); /* osdep */ int cpuload(char *str); diff --git a/pttbbs/mbbsd/bbs.c b/pttbbs/mbbsd/bbs.c index e8a2431b..2a340e73 100644 --- a/pttbbs/mbbsd/bbs.c +++ b/pttbbs/mbbsd/bbs.c @@ -1,4 +1,4 @@ -/* $Id: bbs.c,v 1.5 2002/05/01 04:42:16 in2 Exp $ */ +/* $Id: bbs.c,v 1.6 2002/05/10 16:15:50 in2 Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -247,8 +247,11 @@ static int do_select(int ent, fileheader_t *fhdr, char *direct) { move(0, 0); clrtoeol(); + allboardcomplete(MSG_SELECT_BOARD, bname, sizeof(bname)); + /* make_blist(); namecomplete(MSG_SELECT_BOARD, bname); + */ if(bname[0]=='\0' || !(i = getbnum(bname))) return FULLUPDATE; bh = getbcache(i); @@ -725,7 +728,6 @@ static int cross_post(int ent, fileheader_t *fhdr, char *direct) { char genbuf[200]; char genbuf2[4]; boardheader_t *bp; - make_blist(); move(2, 0); clrtoeol(); move(3, 0); @@ -734,7 +736,12 @@ static int cross_post(int ent, fileheader_t *fhdr, char *direct) { bp = getbcache(currbid); if (bp && (bp->brdattr & BRD_VOTEBOARD)) return FULLUPDATE; + allboardcomplete("轉錄本文章於看板:", xboard, sizeof(xboard)); + /* + make_blist(); + namecomplete(MSG_SELECT_BOARD, bname); namecomplete("轉錄本文章於看板:", xboard); + */ if(*xboard == '\0' || !haspostperm(xboard)) return FULLUPDATE; diff --git a/pttbbs/mbbsd/name.c b/pttbbs/mbbsd/name.c index 2f84a1fe..1e37db2b 100644 --- a/pttbbs/mbbsd/name.c +++ b/pttbbs/mbbsd/name.c @@ -1,4 +1,4 @@ -/* $Id: name.c,v 1.1 2002/03/07 15:13:48 in2 Exp $ */ +/* $Id: name.c,v 1.2 2002/05/10 16:15:50 in2 Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -10,6 +10,7 @@ #include "common.h" #include "proto.h" +extern struct bcache_t *brdshm; extern char *str_space; extern int p_lines; /* a Page of Screen line numbers: tlines-4 */ extern int b_lines; /* Screen bottom line number: t_lines-1 */ @@ -471,3 +472,170 @@ void usercomplete(char *prompt, char *data) { outc('\n'); } } + +int ab_findbound(char *str, int *START, int *END) +{ + int start, end, mid, cmp, strl; + strl = strlen(str); + start = 0, end = brdshm->number - 1; + while( start != end && ((mid = (start + end) / 2) != start) ){ + cmp = strncasecmp(brdshm->sorted[0][mid]->brdname, str, strl); + if( cmp >= 0 ) + end = mid; + else + start = mid; + } + ++start; + if( strncasecmp(brdshm->sorted[0][start]->brdname, str, strl) != 0 ){ + *START = *END = -1; + return -1; + } + *START = start; + + end = brdshm->number - 1; + while( start != end && ((mid = (start + end) / 2) != start) ){ + cmp = strncasecmp(brdshm->sorted[0][mid]->brdname, str, strl); + if( cmp <= 0 ) + start = mid; + else + end = mid; + } + *END = start; + return 0; +} + +#define ab_havepermission(where) \ + Ben_Perm(brdshm->sorted[0][where]) + +int ab_completeone(char *data, int start, int end) +{ + int i, count, at; + for( i = start, at = count = 0 ; i <= end && count < 2 ; ++i ) + if( ab_havepermission(i) ){ + at = i; + ++count; + } + if( count == 1 ){ + strcpy(data, brdshm->sorted[0][at]->brdname); + return 1; + } + return 0; +} + +void allboardcomplete(char *prompt, char *data, int len) +{ + int x, y, origx, origy, ch, i, morelist = -1, col; + int start, end, ptr; + int clearbot = NA; + + outs(prompt); + clrtoeol(); + getyx(&y, &x); + getyx(&origy, &origx); + standout(); + prints("%*s", IDLEN + 1, ""); + standend(); + move(y, x); + refresh(); + ptr = 0; + data[ptr] = 0; + + while( (ch = igetch()) != EOF ){ + if( ch == '\n' || ch == '\r' ){ + data[ptr] = 0; + outc('\n'); + if( ptr != 0 ){ + ab_findbound(data, &start, &end); + ab_completeone(data, start, end); + } + break; + } + else if( ch == ' ' ){ + if( ptr == 0 ) + continue; + + if( morelist == -1 ){ + if( ab_findbound(data, &start, &end) == -1 ) + continue; + if( ab_completeone(data, start, end) ){ + move(origy, origx); + outs(data); + ptr = strlen(data); + getyx(&y, &x); + continue; + } + + morelist = start; + } + else if( morelist > end ) + continue; + clearbot = YEA; + move(2, 0); + clrtobot(); + printdash("相關資訊一覽表"); + + col = 0; + while(len + col < 79) { + for( i = 0 ; morelist <= end && i < p_lines ; ++morelist){ + if( ab_havepermission(morelist) ){ + move(3 + i, col); + prints("%s ", brdshm->sorted[0][morelist]->brdname); + ++i; + } + } + + col += len + 2; + } + if( morelist != end + 1 ){ + move(b_lines, 0); + outs(msg_more); + } + move(y, x); + continue; + + } + else if(ch == '\177' || ch == '\010') { /* backspace */ + if( ptr == 0 ) + continue; + morelist = -1; + --ptr; --x; + data[ptr] = 0; + move(y, x); + outc(' '); + move(y, x); + continue; + } + else if( isprint(ch) && ptr <= (len - 2) ){ + morelist = -1; + data[ptr] = ch; + ++ptr; + data[ptr] = 0; + if( ab_findbound(data, &start, &end) < 0 ) + data[--ptr] = 0; + else{ + for( i = start ; i <= end ; ++i ) + if( ab_havepermission(i) ) + break; + if( i == end + 1 ) + data[--ptr] = 0; + else{ + move(y, x); + outc(ch); + x++; + } + } + } + } + + outc('\n'); + refresh(); + if(clearbot) { + move(2, 0); + clrtobot(); + } + if(*data) { + move(origy, origx); + outs(data); + outc('\n'); + } +} -- cgit v1.2.3 From 2eee07cbe9e43facc434b6fe56f74e3ce1d81351 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Fri, 10 May 2002 19:34:51 +0000 Subject: general namecomplete git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@159 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/include/proto.h | 8 +++++- pttbbs/mbbsd/admin.c | 9 ++++--- pttbbs/mbbsd/announce.c | 10 +++++--- pttbbs/mbbsd/bbs.c | 25 ++++++++++--------- pttbbs/mbbsd/mail.c | 19 +++++++++++---- pttbbs/mbbsd/name.c | 65 ++++++++++++++++++++++++++++++++----------------- 6 files changed, 90 insertions(+), 46 deletions(-) diff --git a/pttbbs/include/proto.h b/pttbbs/include/proto.h index a65293f4..52de7513 100644 --- a/pttbbs/include/proto.h +++ b/pttbbs/include/proto.h @@ -1,4 +1,4 @@ -/* $Id: proto.h,v 1.12 2002/05/10 16:15:47 in2 Exp $ */ +/* $Id: proto.h,v 1.13 2002/05/10 19:34:50 in2 Exp $ */ #ifndef INCLUDE_PROTO_H #define INCLUDE_PROTO_H @@ -296,6 +296,12 @@ void ShowNameList(int row, int column, char *prompt); int RemoveNameList(char *name); void ToggleNameList(int *reciper, char *listfile, char *msg); void allboardcomplete(char *prompt, char *data, int len); +void generalnamecomplete(char *prompt, char *data, int len, size_t nmemb, + int (*compar)(int, char *, int), + int (*permission)(int), char* (*getname)(int)); +int completeboard_compar(int where, char *str, int len); +int completeboard_permission(int where); +char *completeboard_getname(int where); /* osdep */ int cpuload(char *str); diff --git a/pttbbs/mbbsd/admin.c b/pttbbs/mbbsd/admin.c index 815bb854..66043aa4 100644 --- a/pttbbs/mbbsd/admin.c +++ b/pttbbs/mbbsd/admin.c @@ -1,4 +1,4 @@ -/* $Id: admin.c,v 1.9 2002/05/08 14:11:33 lwms Exp $ */ +/* $Id: admin.c,v 1.10 2002/05/10 19:34:51 in2 Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -14,6 +14,7 @@ #include "modes.h" #include "proto.h" +extern struct bcache_t *brdshm; extern char *msg_uid; extern userec_t xuser; extern char *err_uid; @@ -397,8 +398,10 @@ int m_board() { char bname[32]; stand_title("看板設定"); - make_blist(); - namecomplete(msg_bid, bname); + generalnamecomplete(msg_bid, bname, sizeof(bname), brdshm->number, + completeboard_compar, + completeboard_permission, + completeboard_getname); if(!*bname) return 0; m_mod_board(bname); diff --git a/pttbbs/mbbsd/announce.c b/pttbbs/mbbsd/announce.c index 2064ba9d..bc05fca6 100644 --- a/pttbbs/mbbsd/announce.c +++ b/pttbbs/mbbsd/announce.c @@ -1,4 +1,4 @@ -/* $Id: announce.c,v 1.6 2002/04/29 07:05:45 in2 Exp $ */ +/* $Id: announce.c,v 1.7 2002/05/10 19:34:51 in2 Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -20,6 +20,7 @@ #include "modes.h" #include "proto.h" +extern struct bcache_t *brdshm; extern int b_lines; extern int p_lines; extern int TagNum; @@ -506,8 +507,11 @@ static int AnnounceSelect() { move(3, 0); clrtoeol(); move(1, 0); - make_blist(); - namecomplete("選擇精華區看板:", buf); + generalnamecomplete("選擇精華區看板:", buf, sizeof(buf), + brdshm->number, + completeboard_compar, + completeboard_permission, + completeboard_getname); if(*buf) strcpy(xboard, buf); if(*xboard && (bp = getbcache(getbnum(xboard)))) { diff --git a/pttbbs/mbbsd/bbs.c b/pttbbs/mbbsd/bbs.c index 2a340e73..97796674 100644 --- a/pttbbs/mbbsd/bbs.c +++ b/pttbbs/mbbsd/bbs.c @@ -1,4 +1,4 @@ -/* $Id: bbs.c,v 1.6 2002/05/10 16:15:50 in2 Exp $ */ +/* $Id: bbs.c,v 1.7 2002/05/10 19:34:51 in2 Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -14,6 +14,7 @@ #include "common.h" #include "proto.h" +extern struct bcache_t *brdshm; static int g_board_names(boardheader_t *fhdr) { AddNameList(fhdr->brdname); return 0; @@ -238,6 +239,7 @@ int whereami(int ent, fileheader_t *fhdr, char *direct) { pressanykey(); return FULLUPDATE; } + static int do_select(int ent, fileheader_t *fhdr, char *direct) { char bname[20]; char bpath[60]; @@ -247,11 +249,11 @@ static int do_select(int ent, fileheader_t *fhdr, char *direct) { move(0, 0); clrtoeol(); - allboardcomplete(MSG_SELECT_BOARD, bname, sizeof(bname)); - /* - make_blist(); - namecomplete(MSG_SELECT_BOARD, bname); - */ + generalnamecomplete(MSG_SELECT_BOARD, bname, sizeof(bname), + brdshm->number, + completeboard_compar, + completeboard_permission, + completeboard_getname); if(bname[0]=='\0' || !(i = getbnum(bname))) return FULLUPDATE; bh = getbcache(i); @@ -736,12 +738,11 @@ static int cross_post(int ent, fileheader_t *fhdr, char *direct) { bp = getbcache(currbid); if (bp && (bp->brdattr & BRD_VOTEBOARD)) return FULLUPDATE; - allboardcomplete("轉錄本文章於看板:", xboard, sizeof(xboard)); - /* - make_blist(); - namecomplete(MSG_SELECT_BOARD, bname); - namecomplete("轉錄本文章於看板:", xboard); - */ + generalnamecomplete("轉錄本文章於看板:", xboard, sizeof(xboard), + brdshm->number, + completeboard_compar, + completeboard_permission, + completeboard_getname); if(*xboard == '\0' || !haspostperm(xboard)) return FULLUPDATE; diff --git a/pttbbs/mbbsd/mail.c b/pttbbs/mbbsd/mail.c index 6a635f39..34c629cb 100644 --- a/pttbbs/mbbsd/mail.c +++ b/pttbbs/mbbsd/mail.c @@ -1,4 +1,4 @@ -/* $Id: mail.c,v 1.5 2002/04/30 11:15:29 ptt Exp $ */ +/* $Id: mail.c,v 1.6 2002/05/10 19:34:51 in2 Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -14,6 +14,7 @@ #include "modes.h" #include "proto.h" +extern struct bcache_t *brdshm; extern int TagNum; extern int b_lines; /* Screen bottom line number: t_lines-1 */ extern char save_title[]; /* used by editor when inserting */ @@ -1111,13 +1112,16 @@ static int mail_cross_post(int ent, fileheader_t *fhdr, char *direct) { char genbuf[200]; char genbuf2[4]; - make_blist(); move(2, 0); clrtoeol(); move(3, 0); clrtoeol(); move(1, 0); - namecomplete("轉錄本文章於看板:", xboard); + generalnamecomplete("轉錄本文章於看板:", xboard, sizeof(xboard), + brdshm->number, + completeboard_compar, + completeboard_permission, + completeboard_getname); if(*xboard == '\0' || !haspostperm(xboard)) return FULLUPDATE; @@ -1231,8 +1235,13 @@ static int mail_cite(int ent, fileheader_t *fhdr, char *direct) { move(3, 0); clrtoeol(); move(1, 0); - make_blist(); - namecomplete("輸入看版名稱 (直接Enter進入私人信件夾):", buf); + + generalnamecomplete("輸入看版名稱 (直接Enter進入私人信件夾):", + buf, sizeof(buf), + brdshm->number, + completeboard_compar, + completeboard_permission, + completeboard_getname); if(*buf) strcpy(xboard, buf); if(*xboard && (bp = getbcache(getbnum(xboard)))) { diff --git a/pttbbs/mbbsd/name.c b/pttbbs/mbbsd/name.c index 1e37db2b..aafac786 100644 --- a/pttbbs/mbbsd/name.c +++ b/pttbbs/mbbsd/name.c @@ -1,4 +1,4 @@ -/* $Id: name.c,v 1.2 2002/05/10 16:15:50 in2 Exp $ */ +/* $Id: name.c,v 1.3 2002/05/10 19:34:51 in2 Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -473,28 +473,32 @@ void usercomplete(char *prompt, char *data) { } } -int ab_findbound(char *str, int *START, int *END) +int gnc_findbound(char *str, int *START, int *END, + size_t nmemb, int (*compar)(int, char *, int)) { int start, end, mid, cmp, strl; strl = strlen(str); - start = 0, end = brdshm->number - 1; + start = 0, end = nmemb - 1; while( start != end && ((mid = (start + end) / 2) != start) ){ - cmp = strncasecmp(brdshm->sorted[0][mid]->brdname, str, strl); + cmp = compar(mid, str, strl); + //cmp = strncasecmp(brdshm->sorted[0][mid]->brdname, str, strl); if( cmp >= 0 ) end = mid; else start = mid; } ++start; - if( strncasecmp(brdshm->sorted[0][start]->brdname, str, strl) != 0 ){ + //if( strncasecmp(brdshm->sorted[0][start]->brdname, str, strl) != 0 ){ + if( compar(start, str, strl) != 0 ){ *START = *END = -1; return -1; } *START = start; - end = brdshm->number - 1; + end = nmemb - 1; while( start != end && ((mid = (start + end) / 2) != start) ){ - cmp = strncasecmp(brdshm->sorted[0][mid]->brdname, str, strl); + cmp = compar(mid, str, strl); + //cmp = strncasecmp(brdshm->sorted[0][mid]->brdname, str, strl); if( cmp <= 0 ) start = mid; else @@ -504,25 +508,26 @@ int ab_findbound(char *str, int *START, int *END) return 0; } -#define ab_havepermission(where) \ - Ben_Perm(brdshm->sorted[0][where]) - -int ab_completeone(char *data, int start, int end) +int gnc_completeone(char *data, int start, int end, + int (*permission)(int), char* (*getname)(int)) { int i, count, at; for( i = start, at = count = 0 ; i <= end && count < 2 ; ++i ) - if( ab_havepermission(i) ){ + if( permission(i) ){ at = i; ++count; } if( count == 1 ){ - strcpy(data, brdshm->sorted[0][at]->brdname); + strcpy(data, getname(at)); return 1; } return 0; } -void allboardcomplete(char *prompt, char *data, int len) + +void generalnamecomplete(char *prompt, char *data, int len, size_t nmemb, + int (*compar)(int, char *, int), + int (*permission)(int), char* (*getname)(int)) { int x, y, origx, origy, ch, i, morelist = -1, col; int start, end, ptr; @@ -545,8 +550,8 @@ void allboardcomplete(char *prompt, char *data, int len) data[ptr] = 0; outc('\n'); if( ptr != 0 ){ - ab_findbound(data, &start, &end); - ab_completeone(data, start, end); + gnc_findbound(data, &start, &end, nmemb, compar); + gnc_completeone(data, start, end, permission, getname); } break; } @@ -555,9 +560,9 @@ void allboardcomplete(char *prompt, char *data, int len) continue; if( morelist == -1 ){ - if( ab_findbound(data, &start, &end) == -1 ) + if( gnc_findbound(data, &start, &end, nmemb, compar) == -1 ) continue; - if( ab_completeone(data, start, end) ){ + if( gnc_completeone(data, start, end, permission, getname) ){ move(origy, origx); outs(data); ptr = strlen(data); @@ -577,9 +582,9 @@ void allboardcomplete(char *prompt, char *data, int len) col = 0; while(len + col < 79) { for( i = 0 ; morelist <= end && i < p_lines ; ++morelist){ - if( ab_havepermission(morelist) ){ + if( permission(morelist) ){ move(3 + i, col); - prints("%s ", brdshm->sorted[0][morelist]->brdname); + prints("%s ", getname(morelist)); ++i; } } @@ -610,11 +615,11 @@ void allboardcomplete(char *prompt, char *data, int len) data[ptr] = ch; ++ptr; data[ptr] = 0; - if( ab_findbound(data, &start, &end) < 0 ) + if( gnc_findbound(data, &start, &end, nmemb, compar) < 0 ) data[--ptr] = 0; else{ for( i = start ; i <= end ; ++i ) - if( ab_havepermission(i) ) + if( permission(i) ) break; if( i == end + 1 ) data[--ptr] = 0; @@ -639,3 +644,19 @@ void allboardcomplete(char *prompt, char *data, int len) outc('\n'); } } + +int completeboard_compar(int where, char *str, int len) +{ + return strncasecmp(brdshm->sorted[0][where]->brdname, str, len); +} + +int completeboard_permission(int where) +{ + return Ben_Perm(brdshm->sorted[0][where]); +} + +char *completeboard_getname(int where) +{ + return brdshm->sorted[0][where]->brdname; +} + -- cgit v1.2.3 From b6e9600d7e689d52aa1609ae770e508917e613bb Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sat, 11 May 2002 15:30:31 +0000 Subject: avoid infinite loop git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@160 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/talk.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pttbbs/mbbsd/talk.c b/pttbbs/mbbsd/talk.c index 21b60a08..114668c0 100644 --- a/pttbbs/mbbsd/talk.c +++ b/pttbbs/mbbsd/talk.c @@ -1,4 +1,4 @@ -/* $Id: talk.c,v 1.29 2002/05/10 12:36:00 lwms Exp $ */ +/* $Id: talk.c,v 1.30 2002/05/11 15:30:31 in2 Exp $ */ #include <stdio.h> #include <string.h> #include <errno.h> @@ -266,7 +266,7 @@ int logout_friend_online(userinfo_t *utmp) utmp->friend_online[i]=0; ui = &utmpshm->uinfo[j]; if(ui->pid && ui!=utmp){ - for(k=0; k<ui->friendtotal && + for(k=0; k<ui->friendtotal && k < MAX_FRIEND && (int)(ui->friend_online[k] & 0xFFFFFF) !=offset; k++); if(k<ui->friendtotal){ ui->friendtotal--; @@ -288,7 +288,7 @@ int friend_stat(userinfo_t *me, userinfo_t * ui) if (me->brc_id && ui->brc_id == me->brc_id){ hit = IBH; } - for(i=0;me->friend_online[i];i++){ + for(i=0;me->friend_online[i] && i < MAX_FRIEND;i++){ j = (me->friend_online[i] & 0xFFFFFF); if(ui == &utmpshm->uinfo[j]){ hit |= me->friend_online[i] >>24; -- cgit v1.2.3 From 779f080318097ac54fd4bf2eee26be4b7aec7b44 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sat, 11 May 2002 16:42:45 +0000 Subject: generalnamecomplete, userlist complete git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@161 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/include/proto.h | 5 ++++- pttbbs/mbbsd/bbs.c | 4 +++- pttbbs/mbbsd/name.c | 24 +++++++++++++++++++++++- pttbbs/mbbsd/talk.c | 18 +++++++++++++----- 4 files changed, 43 insertions(+), 8 deletions(-) diff --git a/pttbbs/include/proto.h b/pttbbs/include/proto.h index 52de7513..66267a52 100644 --- a/pttbbs/include/proto.h +++ b/pttbbs/include/proto.h @@ -1,4 +1,4 @@ -/* $Id: proto.h,v 1.13 2002/05/10 19:34:50 in2 Exp $ */ +/* $Id: proto.h,v 1.14 2002/05/11 16:42:43 in2 Exp $ */ #ifndef INCLUDE_PROTO_H #define INCLUDE_PROTO_H @@ -302,6 +302,9 @@ void generalnamecomplete(char *prompt, char *data, int len, size_t nmemb, int completeboard_compar(int where, char *str, int len); int completeboard_permission(int where); char *completeboard_getname(int where); +int completeutmp_compar(int where, char *str, int len); +int completeutmp_permission(int where); +char *completeutmp_getname(int where); /* osdep */ int cpuload(char *str); diff --git a/pttbbs/mbbsd/bbs.c b/pttbbs/mbbsd/bbs.c index 97796674..bc853662 100644 --- a/pttbbs/mbbsd/bbs.c +++ b/pttbbs/mbbsd/bbs.c @@ -1,4 +1,4 @@ -/* $Id: bbs.c,v 1.7 2002/05/10 19:34:51 in2 Exp $ */ +/* $Id: bbs.c,v 1.8 2002/05/11 16:42:45 in2 Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -115,10 +115,12 @@ int save_violatelaw() { return 0; } +/* void make_blist() { CreateNameList(); apply_boards(g_board_names); } +*/ extern int currbid; extern char currBM[]; diff --git a/pttbbs/mbbsd/name.c b/pttbbs/mbbsd/name.c index aafac786..a16e89e6 100644 --- a/pttbbs/mbbsd/name.c +++ b/pttbbs/mbbsd/name.c @@ -1,4 +1,4 @@ -/* $Id: name.c,v 1.3 2002/05/10 19:34:51 in2 Exp $ */ +/* $Id: name.c,v 1.4 2002/05/11 16:42:45 in2 Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -9,8 +9,11 @@ #include "pttstruct.h" #include "common.h" #include "proto.h" +#include "perm.h" extern struct bcache_t *brdshm; +extern struct utmpfile_t *utmpshm; +extern userec_t cuser; extern char *str_space; extern int p_lines; /* a Page of Screen line numbers: tlines-4 */ extern int b_lines; /* Screen bottom line number: t_lines-1 */ @@ -645,6 +648,7 @@ void generalnamecomplete(char *prompt, char *data, int len, size_t nmemb, } } +/* general complete functions (brdshm) */ int completeboard_compar(int where, char *str, int len) { return strncasecmp(brdshm->sorted[0][where]->brdname, str, len); @@ -660,3 +664,21 @@ char *completeboard_getname(int where) return brdshm->sorted[0][where]->brdname; } +/* general complete functions (utmpshm) */ +int completeutmp_compar(int where, char *str, int len) +{ + return strncasecmp(utmpshm->sorted[utmpshm->currsorted][0][where]->userid, + str, len); +} + +int completeutmp_permission(int where) +{ + return (HAS_PERM(PERM_SYSOP) || HAS_PERM(PERM_SEECLOAK) || + !utmpshm->sorted[utmpshm->currsorted][0][where]->invisible); +} + +char *completeutmp_getname(int where) +{ + return utmpshm->sorted[utmpshm->currsorted][0][where]->userid; +} + diff --git a/pttbbs/mbbsd/talk.c b/pttbbs/mbbsd/talk.c index 114668c0..e7245351 100644 --- a/pttbbs/mbbsd/talk.c +++ b/pttbbs/mbbsd/talk.c @@ -1,4 +1,4 @@ -/* $Id: talk.c,v 1.30 2002/05/11 15:30:31 in2 Exp $ */ +/* $Id: talk.c,v 1.31 2002/05/11 16:42:45 in2 Exp $ */ #include <stdio.h> #include <string.h> #include <errno.h> @@ -1425,6 +1425,7 @@ static void t_showhelp() { pressanykey(); } +/* static int listcuent(userinfo_t * uentp) { if((!uentp->invisible || HAS_PERM(PERM_SYSOP) || HAS_PERM(PERM_SEECLOAK))) @@ -1437,14 +1438,18 @@ static void creat_list() CreateNameList(); apply_ulist(listcuent); } +*/ static int search_pickup(int num, int actor, pickup_t pklist[]) { char genbuf[IDLEN + 2]; move(1, 0); - creat_list(); - namecomplete(msg_uid, genbuf); + generalnamecomplete(msg_uid, genbuf, sizeof(genbuf), + utmpshm->number, + completeutmp_compar, + completeutmp_permission, + completeutmp_getname); if (genbuf[0]){ int n = (num + 1) % actor; while (n != num){ @@ -2306,8 +2311,11 @@ int t_talk() { } */ stand_title("打開話匣子"); - creat_list(); - namecomplete(msg_uid, uident); + generalnamecomplete(msg_uid, genbuf, sizeof(genbuf), + utmpshm->number, + completeutmp_compar, + completeutmp_permission, + completeutmp_getname); if (uident[0] == '\0') return 0; -- cgit v1.2.3 From 6c9885ee4d37caee270fdee35fdea698a252cdc6 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sat, 11 May 2002 16:53:25 +0000 Subject: fix bug(usercomplete) git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@162 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/talk.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pttbbs/mbbsd/talk.c b/pttbbs/mbbsd/talk.c index e7245351..ef96ca35 100644 --- a/pttbbs/mbbsd/talk.c +++ b/pttbbs/mbbsd/talk.c @@ -1,4 +1,4 @@ -/* $Id: talk.c,v 1.31 2002/05/11 16:42:45 in2 Exp $ */ +/* $Id: talk.c,v 1.32 2002/05/11 16:53:25 in2 Exp $ */ #include <stdio.h> #include <string.h> #include <errno.h> @@ -2311,7 +2311,7 @@ int t_talk() { } */ stand_title("打開話匣子"); - generalnamecomplete(msg_uid, genbuf, sizeof(genbuf), + generalnamecomplete(msg_uid, uident, sizeof(uident), utmpshm->number, completeutmp_compar, completeutmp_permission, -- cgit v1.2.3 From 0691b26858271516d74546ab4db4d25b1c47d0a8 Mon Sep 17 00:00:00 2001 From: ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Mon, 13 May 2002 03:20:04 +0000 Subject: replace time(NULL) by now git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@163 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/admin.c | 17 +++++++---------- pttbbs/mbbsd/announce.c | 7 ++----- pttbbs/mbbsd/bbs.c | 14 ++++++-------- pttbbs/mbbsd/board.c | 11 +++++------ pttbbs/mbbsd/cache.c | 10 ++++------ pttbbs/mbbsd/cal.c | 11 +++-------- pttbbs/mbbsd/calendar.c | 21 ++++++++++----------- pttbbs/mbbsd/chat.c | 7 +++---- pttbbs/mbbsd/chc_play.c | 14 +++++++------- pttbbs/mbbsd/chicken.c | 24 +++++++++--------------- pttbbs/mbbsd/dark.c | 5 +++-- pttbbs/mbbsd/edit.c | 5 ++--- pttbbs/mbbsd/gamble.c | 5 ++--- pttbbs/mbbsd/gomo.c | 15 ++++++++------- pttbbs/mbbsd/io.c | 41 +++++++++++++++-------------------------- pttbbs/mbbsd/kaede.c | 4 ++-- pttbbs/mbbsd/lovepaper.c | 7 +++---- pttbbs/mbbsd/mail.c | 35 +++++++++++++++-------------------- pttbbs/mbbsd/mbbsd.c | 12 +++--------- pttbbs/mbbsd/menu.c | 12 ++++++------ pttbbs/mbbsd/more.c | 6 +++--- pttbbs/mbbsd/record.c | 15 ++++++--------- pttbbs/mbbsd/register.c | 9 ++++----- pttbbs/mbbsd/syspost.c | 8 ++------ pttbbs/mbbsd/talk.c | 29 +++-------------------------- pttbbs/mbbsd/user.c | 12 +++--------- pttbbs/mbbsd/vote.c | 18 ++++++------------ pttbbs/mbbsd/voteboard.c | 6 +++--- pttbbs/mbbsd/xyz.c | 6 +++--- 29 files changed, 148 insertions(+), 238 deletions(-) diff --git a/pttbbs/mbbsd/admin.c b/pttbbs/mbbsd/admin.c index 66043aa4..f97a3603 100644 --- a/pttbbs/mbbsd/admin.c +++ b/pttbbs/mbbsd/admin.c @@ -1,4 +1,4 @@ -/* $Id: admin.c,v 1.10 2002/05/10 19:34:51 in2 Exp $ */ +/* $Id: admin.c,v 1.11 2002/05/13 03:20:04 ptt Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -19,7 +19,7 @@ extern char *msg_uid; extern userec_t xuser; extern char *err_uid; extern boardheader_t *bcache; - +extern time_t now; /* 使用者管理 */ int m_user() { userec_t muser; @@ -891,8 +891,7 @@ int scan_register_form(char *regfile, int automode, int neednum) { if((fout = fopen(logfile, "a"))) { for(n = 0; field[n]; n++) fprintf(fout, "%s: %s\n", field[n], fdata[n]); - n = time(NULL); - fprintf(fout, "Date: %s\n", Cdate((time_t *) & n)); + fprintf(fout, "Date: %s\n", Cdate(& now)); fprintf(fout, "Rejected: %s [%s]\n----\n", uid, buf); fclose(fout); @@ -926,8 +925,7 @@ int scan_register_form(char *regfile, int automode, int neednum) { if((fout = fopen(logfile, "a"))) { for(n = 0; field[n]; n++) fprintf(fout, "%s: %s\n", field[n], fdata[n]); - n = time(NULL); - fprintf(fout, "Date: %s\n", Cdate((time_t *) & n)); + fprintf(fout, "Date: %s\n", Cdate(&now)); fprintf(fout, "Approved: %s\n", uid); fprintf(fout, "----\n"); fclose(fout); @@ -1046,8 +1044,7 @@ int give_money() { FILE *fp, *fp2; char *ptr, *id, *mn; char buf[200] = {0}, tt[TTLEN + 1] = {0}; - time_t t = time(NULL); - struct tm *pt = localtime(&t); + struct tm *pt = localtime(&now); int to_all = 0, money = 0; getdata(0, 0, "指定使用者(S) 全站使用者(A) 取消(Q)?[S]", buf, sizeof(buf), LCECHO); @@ -1094,7 +1091,7 @@ int give_money() { if(bad_user_id(uhash->userid[i])) continue; id = uhash->userid[i]; - give_id_money(id, money, fp2, tt, t); + give_id_money(id, money, fp2, tt, now); } } else { if(!(fp = fopen("etc/givemoney.txt", "r+"))) { @@ -1108,7 +1105,7 @@ int give_money() { *ptr = '\0'; id = buf; mn = ptr + 1; - give_id_money(id, atoi(mn), fp2, tt, t); + give_id_money(id, atoi(mn), fp2, tt, now); } fclose(fp); } diff --git a/pttbbs/mbbsd/announce.c b/pttbbs/mbbsd/announce.c index bc05fca6..0de45055 100644 --- a/pttbbs/mbbsd/announce.c +++ b/pttbbs/mbbsd/announce.c @@ -1,4 +1,4 @@ -/* $Id: announce.c,v 1.7 2002/05/10 19:34:51 in2 Exp $ */ +/* $Id: announce.c,v 1.8 2002/05/13 03:20:04 ptt Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -25,6 +25,7 @@ extern int b_lines; extern int p_lines; extern int TagNum; extern int currbid; +extern time_t now; static void g_showmenu(gmenu_t *pm) { static char *mytype = "編 選 絲路之旅"; char *title, ch; @@ -113,7 +114,6 @@ static FILE* my_open(char* path) { FILE* ans = 0; char buf[80]; struct stat st; - time_t now = time(0); if(stat(path, &st) == 0 && st.st_mtime < now - 3600 * 24 * 7) { return fopen(path, "w"); @@ -213,9 +213,6 @@ static void go_proxy(char* fpath, item_t *node, int update) { ch = str[1]; if(ch == (char) 0xbc && !(HAS_PERM(PERM_SYSOP) && currutmp->pager > 1)) { - time_t now; - - time(&now); fprintf(fo, "作者: %s (連線精華區)\n標題: %s\n時間: %s\n", server, str + 3, ctime(&now) ); diff --git a/pttbbs/mbbsd/bbs.c b/pttbbs/mbbsd/bbs.c index bc853662..d4367447 100644 --- a/pttbbs/mbbsd/bbs.c +++ b/pttbbs/mbbsd/bbs.c @@ -1,4 +1,4 @@ -/* $Id: bbs.c,v 1.8 2002/05/11 16:42:45 in2 Exp $ */ +/* $Id: bbs.c,v 1.9 2002/05/13 03:20:04 ptt Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -23,6 +23,7 @@ static int g_board_names(boardheader_t *fhdr) { extern userec_t cuser; extern void touchdircache(int bid); extern int TagNum; +extern time_t now; static void mail_by_link(char* owner, char* title, char* path) { char genbuf[200]; @@ -44,7 +45,6 @@ extern int usernum; void anticrosspost() { char buf[200]; - time_t now = time(NULL); sprintf(buf, "\033[1;33;46m%s \033[37;45mcross post 文章 \033[37m %s\033[m", @@ -1482,11 +1482,11 @@ int b_note_edit_bname(int bid) { outs(msg_cancel); pressanykey(); } else { - aborted = (fh->bupdate - time(0)) / 86400 + 1; + aborted = (fh->bupdate - now ) / 86400 + 1; sprintf(buf,"%d", aborted > 0 ? aborted : 0); getdata_buf(3, 0, "請設定有效期限(0 - 9999)天?", buf, 5, DOECHO); aborted = atoi(buf); - fh->bupdate = aborted ? time(0) + aborted * 86400 : 0; + fh->bupdate = aborted ? now + aborted * 86400 : 0; substitute_record(fn_board, fh, sizeof(boardheader_t), bid); } return 0; @@ -1853,7 +1853,7 @@ int Read() { int stat0 = currstat, tmpbid=currutmp->brc_id; char buf[40]; #ifdef LOG_BOARD - time_t usetime = time(0); + time_t usetime = now; #endif setutmpmode(READING); @@ -1870,7 +1870,7 @@ int Read() { i_read(READING, buf, readtitle, readdoent, read_comms, currbid); #ifdef LOG_BOARD - log_board(currboard, time(0) - usetime); + log_board(currboard, now - usetime); #endif brc_update(); @@ -1895,11 +1895,9 @@ void ReadSelect() { #ifdef LOG_BOARD static void log_board(char *mode, time_t usetime) { - time_t now; char buf[ 256 ]; if(usetime > 30) { - now = time(0); sprintf(buf, "USE %-20.20s Stay: %5ld (%s) %s", mode, usetime ,cuser.userid ,ctime(&now)); log_file(FN_USEBOARD,buf); diff --git a/pttbbs/mbbsd/board.c b/pttbbs/mbbsd/board.c index 923bea0a..42addecf 100644 --- a/pttbbs/mbbsd/board.c +++ b/pttbbs/mbbsd/board.c @@ -1,4 +1,4 @@ -/* $Id: board.c,v 1.5 2002/04/28 19:35:28 in2 Exp $ */ +/* $Id: board.c,v 1.6 2002/05/13 03:20:04 ptt Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -20,6 +20,7 @@ #define BRC_MAXNUM 80 extern userinfo_t *currutmp; +extern time_t now; static char *brc_getrecord(char *ptr, char *name, int *pnum, int *list) { int num; char *tmp; @@ -279,9 +280,7 @@ void save_brdbuf() { close(fd); } if( favbuf[-1] != 0x5c4d3e ){ - time_t now; FILE *fp = fopen(BBSHOME "/log/memorybad", "a"); - time(&now); fprintf(fp, "%s %s %d\n", cuser.userid, Cdatelite(&now), favbuf[-1]); fclose(fp); return; @@ -927,7 +926,7 @@ static void choose_board(int newflag) { brc_initial(ptr->bh->brdname); if(ch == 'v') { ptr->myattr &= ~BRD_UNREAD; - zapbuf[ptr->bid-1] = time((time_t *) &brc_list[0]); + zapbuf[ptr->bid-1] = brc_list[0]=now; } else { zapbuf[ptr->bid-1] = brc_list[0] = 1; @@ -993,7 +992,7 @@ static void choose_board(int newflag) { } board_visit_time = zapbuf[ptr->bid-1]; if(!(ptr->myattr&BRD_ZAP)) - time((time_t *) &zapbuf[ptr->bid-1]); + zapbuf[ptr->bid-1]=now; Read(); check_newpost(ptr); head = -1; @@ -1018,7 +1017,7 @@ static void choose_board(int newflag) { if (!(currmode & MODE_MENU))/*如果還沒有小組長權限 */ set_menu_BM(ptr->bh->BM); - if(time(NULL) < ptr->bh->bupdate) { + if(now < ptr->bh->bupdate) { setbfile(buf, ptr->bh->brdname, fn_notes); if(more(buf, NA) != -1) pressanykey(); diff --git a/pttbbs/mbbsd/cache.c b/pttbbs/mbbsd/cache.c index fef81942..a2d1c98a 100644 --- a/pttbbs/mbbsd/cache.c +++ b/pttbbs/mbbsd/cache.c @@ -1,4 +1,4 @@ -/* $Id: cache.c,v 1.22 2002/05/04 13:50:26 in2 Exp $ */ +/* $Id: cache.c,v 1.23 2002/05/13 03:20:04 ptt Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -34,7 +34,7 @@ union semun { struct seminfo *__buf; /* buffer for IPC_INFO */ }; #endif - +extern time_t now; int fcache_semid; /* the reason for "safe_sleep" is that we may call sleep during @@ -330,7 +330,6 @@ void setutmpmode(int mode) { /* 追蹤使用者 */ if(HAS_PERM(PERM_LOGUSER)) { - time_t now = time(NULL); char msg[200]; sprintf(msg, "%s setutmpmode to %s(%d) at %s", cuser.userid, modestring(currutmp, 0), mode, Cdate(&now)); @@ -377,7 +376,6 @@ static int cmputmpuid(const void *i, const void *j){ } void sort_utmp() { - time_t now=time(NULL); int count, i, ns; userinfo_t *uentp; @@ -673,7 +671,7 @@ void resolve_boards() { } void touch_boards() { - time(&(brdshm->touchtime)); + brdshm->touchtime=now; numboards = -1; resolve_boards(); } @@ -1016,7 +1014,7 @@ void hbflreload(int bid) } fclose(fp); } - hbfl[0] = time(NULL); + hbfl[0] = now; memcpy(brdshm->hbfl[bid], hbfl, sizeof(hbfl)); } diff --git a/pttbbs/mbbsd/cal.c b/pttbbs/mbbsd/cal.c index 78204dc9..aec3320b 100644 --- a/pttbbs/mbbsd/cal.c +++ b/pttbbs/mbbsd/cal.c @@ -1,4 +1,4 @@ -/* $Id: cal.c,v 1.10 2002/05/10 12:36:00 lwms Exp $ */ +/* $Id: cal.c,v 1.11 2002/05/13 03:20:04 ptt Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -14,6 +14,7 @@ extern struct utmpfile_t *utmpshm; extern int usernum; +extern time_t now; /* 防堵 Multi play */ static int count_multiplay(int unmode) { @@ -103,10 +104,8 @@ static int osong(char *defaultid) { char receiver[45],ano[2]; FILE *fp,*fp1;// *fp2; fileheader_t mail; - time_t now; int nsongs; - now = time(NULL); strcpy(buf, Cdatedate(&now)); lockreturn0(OSONG, LOCK_MULTI); @@ -222,7 +221,7 @@ static int osong(char *defaultid) { // do_append(OSONGMAIL "/.DIR", &mail2, sizeof(mail2)); if(do_append(OSONGPATH "/.DIR", &mail, sizeof(mail)) != -1) { - cuser.lastsong = time(NULL); + cuser.lastsong = now; /* Jaky 超過 500 首歌就開始砍 */ nsongs=get_num_records(OSONGPATH "/.DIR", sizeof(mail)); if (nsongs > 500){ @@ -341,13 +340,11 @@ int p_exmail() { void mail_redenvelop(char* from, char* to, int money, char mode){ char genbuf[200]; fileheader_t fhdr; - time_t now; FILE* fp; sprintf(genbuf, "home/%c/%s", to[0], to); stampfile(genbuf, &fhdr); if (!(fp = fopen(genbuf, "w"))) return; - now = time(NULL); fprintf(fp, "作者: %s\n" "標題: 招財進寶\n" "時間: %s\n" @@ -382,7 +379,6 @@ int give_tax(int money) int p_give() { int money, tax; char id[IDLEN + 1], genbuf[90]; - time_t now = time(0); move(1,0); usercomplete("這位幸運兒的id:", id); @@ -396,7 +392,6 @@ int p_give() { if ( money - tax <= 0 ) return 0; /* 繳完稅就沒錢給了 */ deumoney(searchuser(id), money - tax); demoney(-money); - now = time(NULL); sprintf(genbuf,"%s\t給%s\t%d\t%s", cuser.userid, id, money - tax, ctime(&now)); log_file(FN_MONEY, genbuf); diff --git a/pttbbs/mbbsd/calendar.c b/pttbbs/mbbsd/calendar.c index 78ca46cf..371a8f79 100644 --- a/pttbbs/mbbsd/calendar.c +++ b/pttbbs/mbbsd/calendar.c @@ -1,4 +1,4 @@ -/* $Id: calendar.c,v 1.1 2002/03/07 15:13:48 in2 Exp $ */ +/* $Id: calendar.c,v 1.2 2002/05/13 03:20:04 ptt Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -9,6 +9,7 @@ #include "proto.h" #include "modes.h" +extern time_t now; typedef struct event_t { int year, month, day, days; int color; @@ -232,16 +233,14 @@ static int GenerateCalendar(char **buf, int y, int m, int today, event_t *e) { int calendar() { char **buf; - time_t t; - struct tm now; + struct tm snow; int i, y, m, today, lines = 0; event_t *head = NULL, *e = NULL; /* initialize date */ - time(&t); - memcpy(&now, localtime(&t), sizeof(struct tm)); - today = Days(now.tm_year + 1900, now.tm_mon + 1, now.tm_mday); - y = now.tm_year + 1900, m = now.tm_mon + 1; + memcpy(&snow, localtime(&now), sizeof(struct tm)); + today = Days(snow.tm_year + 1900, snow.tm_mon + 1, snow.tm_mday); + y = snow.tm_year + 1900, m = snow.tm_mon + 1; /* read event */ head = e = ReadEvent(today); @@ -265,10 +264,10 @@ int calendar() { outs(buf[i]); if(i == 0) { prints("\t\33[1;37m現在是 %d.%02d.%02d %2d:%02d:%02d%cm\33[m", - now.tm_year + 1900, now.tm_mon + 1, now.tm_mday, - (now.tm_hour == 0 || now.tm_hour == 12) ? - 12 : now.tm_hour % 12, now.tm_min, now.tm_sec, - now.tm_hour >= 12 ? 'p' : 'a'); + snow.tm_year + 1900, snow.tm_mon + 1, snow.tm_mday, + (snow.tm_hour == 0 || snow.tm_hour == 12) ? + 12 : snow.tm_hour % 12, snow.tm_min, snow.tm_sec, + snow.tm_hour >= 12 ? 'p' : 'a'); } else if(i >= 2 && e) { prints("\t\33[1;37m(\33[%dm%3d\33[37m)\33[m %02d/%02d %s", e->color, e->days - today, diff --git a/pttbbs/mbbsd/chat.c b/pttbbs/mbbsd/chat.c index 4825379b..e7e7846a 100644 --- a/pttbbs/mbbsd/chat.c +++ b/pttbbs/mbbsd/chat.c @@ -1,4 +1,4 @@ -/* $Id: chat.c,v 1.2 2002/04/28 19:35:28 in2 Exp $ */ +/* $Id: chat.c,v 1.3 2002/05/13 03:20:04 ptt Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -20,6 +20,7 @@ extern userinfo_t *currutmp; static int chatline; static int stop_line; /* next line of bottom of message window area */ static FILE *flog; +extern time_t now; static void printchatline(char *str) { move(chatline, 0); @@ -192,11 +193,9 @@ static void chat_help(char *arg) { } static void chat_date() { - time_t thetime; char genbuf[200]; - time(&thetime); - sprintf(genbuf, "◆ " BBSNAME "標準時間: %s", Cdate(&thetime)); + sprintf(genbuf, "◆ " BBSNAME "標準時間: %s", Cdate(&now)); printchatline(genbuf); } diff --git a/pttbbs/mbbsd/chc_play.c b/pttbbs/mbbsd/chc_play.c index 86c17fbc..8f3e432c 100644 --- a/pttbbs/mbbsd/chc_play.c +++ b/pttbbs/mbbsd/chc_play.c @@ -1,4 +1,4 @@ -/* $Id: chc_play.c,v 1.1 2002/03/07 15:13:48 in2 Exp $ */ +/* $Id: chc_play.c,v 1.2 2002/05/13 03:20:04 ptt Exp $ */ #include <stdio.h> #include <time.h> #include <unistd.h> @@ -12,7 +12,7 @@ extern userinfo_t *currutmp; extern int usernum; - +extern time_t now; typedef int (*play_func_t)(int, board_t, board_t); static int chc_ipass = 0, chc_hepass = 0; @@ -35,9 +35,9 @@ static int hisplay(int s, board_t board, board_t tmpbrd) { int start_time; int endgame = 0, endturn = 0; - start_time = time(NULL); + start_time = now; while(!endturn) { - chc_lefttime = CHC_TIMEOUT - (time(NULL) - start_time); + chc_lefttime = CHC_TIMEOUT - (now - start_time); if(chc_lefttime < 0) { chc_lefttime = 0; @@ -95,15 +95,15 @@ static int myplay(int s, board_t board, board_t tmpbrd) { int endgame = 0, endturn = 0; chc_ipass = 0, chc_selected = 0; - start_time = time(NULL); - chc_lefttime = CHC_TIMEOUT - (time(NULL) - start_time); + start_time = now; + chc_lefttime = CHC_TIMEOUT - (now - start_time); bell(); while(!endturn) { chc_drawline(board, TIME_ROW); chc_movecur(chc_cursor.r, chc_cursor.c); oflush(); ch = igetkey(); - chc_lefttime = CHC_TIMEOUT - (time(NULL) - start_time); + chc_lefttime = CHC_TIMEOUT - (now - start_time); if(chc_lefttime < 0) ch = 'q'; switch(ch) { diff --git a/pttbbs/mbbsd/chicken.c b/pttbbs/mbbsd/chicken.c index f13b68dc..c3bc1fa0 100644 --- a/pttbbs/mbbsd/chicken.c +++ b/pttbbs/mbbsd/chicken.c @@ -1,4 +1,4 @@ -/* $Id: chicken.c,v 1.2 2002/04/28 19:35:29 in2 Exp $ */ +/* $Id: chicken.c,v 1.3 2002/05/13 03:20:04 ptt Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -57,7 +57,7 @@ enum { }; extern userec_t cuser; - +extern time_t now; static chicken_t *mychicken = &cuser.mychicken; static int age; @@ -108,7 +108,6 @@ int reload_chicken() { static int new_chicken() { char buf[150]; int price; - time_t now; clear(); move(2,0); @@ -140,7 +139,6 @@ static int new_chicken() { getdata(8, 0, "幫牠取個好名字:", mychicken->name, sizeof(mychicken->name), DOECHO); - now = time(NULL); sprintf(buf,"\033[31m%s \033[m養了一隻叫\033[33m %s \033[m的 " "\033[32m%s\033[m 於 %s",cuser.userid, mychicken->name,chicken_type[(int)mychicken->type],ctime(&now)); @@ -214,9 +212,9 @@ extern char *BBSName; void show_chicken_data(chicken_t *thechicken, chicken_t *pkchicken) { char buf[1024]; - age = ((time(NULL) - thechicken->cbirth)/ (60*60*24)); + age = ((now - thechicken->cbirth)/ (60*60*24)); if(age < 0) { - thechicken->birthday = thechicken->cbirth = time(NULL)-10*(60*60*24); + thechicken->birthday = thechicken->cbirth = now-10*(60*60*24); age = 10; } /*Ptt:debug*/ @@ -418,7 +416,6 @@ static void ch_kill() { chicken_type[(int)mychicken->type]); getdata_str(23, 0, buf, ans, sizeof(ans), DOECHO, "N"); if(ans[0] == 'y') { - time_t now = time(NULL); vice(100,"棄養寵物費"); more(CHICKEN_PIC "/deadth",YEA); @@ -454,7 +451,6 @@ static int ch_sell() { time_change[(int)mychicken->type][HP_MAX]) * 3 / 2 - mychicken->sick; char buf[150],ans[4]; - time_t now = time(NULL); if(money < 0) money =0 ; @@ -514,10 +510,10 @@ static void geting_old(int *hp, int *weight, int diff, int age) { /* 依時間變動的資料 */ void time_diff(chicken_t *thechicken) { int diff; - int theage = ((time(NULL) - thechicken->cbirth)/ (60 * 60 * 24)); + int theage = ((now - thechicken->cbirth)/ (60 * 60 * 24)); thechicken->type %= NUM_KINDS ; - diff = (time(NULL)-thechicken->lastvisit)/60; + diff = (now-thechicken->lastvisit)/60; if((diff) < 1) return; @@ -525,7 +521,7 @@ void time_diff(chicken_t *thechicken) { if(theage > 13 ) /* 老死 */ geting_old(&thechicken->hp_max, &thechicken->weight, diff, age); - thechicken->lastvisit = time(NULL); + thechicken->lastvisit = now; thechicken->weight -= thechicken->hp_max * diff / 540; /* 體重 */ if(thechicken->weight < 1) { thechicken->sick -= thechicken->weight / 10; /* 餓得病氣上升 */ @@ -613,7 +609,6 @@ static void check_sick() { static int deadtype(chicken_t *thechicken) { int i; char buf[150]; - time_t now = time(NULL); if(thechicken->hp <= 0) /* hp用盡 */ i = 1; @@ -676,7 +671,6 @@ int isdeadth(chicken_t *thechicken) { static void ch_changename() { char buf[150], newname[20] = ""; - time_t now = time(NULL); getdata_str(b_lines - 1, 0, "嗯..改個好名字吧:", newname, 18, DOECHO, mychicken->name); @@ -780,7 +774,7 @@ static int recover_chicken(chicken_t *thechicken) { int price = egg_price[(int)thechicken->type], money = price + (rand() % price); - if(time(NULL) - thechicken->lastvisit > (60 * 60 * 24 * 7)) + if(now - thechicken->lastvisit > (60 * 60 * 24 * 7)) return 0; outmsg("\033[33;44m★靈界守衛\033[37;45m 別害怕 我是來幫你的 \033[m"); bell(); @@ -831,7 +825,7 @@ int chicken_main() { lockreturn0(CHICKEN, LOCK_MULTI); reload_chicken(); - age = ((time(NULL) - mychicken->cbirth)/ (60*60*24)); + age = ((now - mychicken->cbirth)/ (60*60*24)); if(!mychicken->name[0] && !recover_chicken(mychicken) && !new_chicken()) { unlockutmpmode(); return 0; diff --git a/pttbbs/mbbsd/dark.c b/pttbbs/mbbsd/dark.c index 1b084407..ee691577 100644 --- a/pttbbs/mbbsd/dark.c +++ b/pttbbs/mbbsd/dark.c @@ -1,4 +1,4 @@ -/* $Id: dark.c,v 1.2 2002/04/27 15:50:17 in2 Exp $ */ +/* $Id: dark.c,v 1.3 2002/05/13 03:20:04 ptt Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -13,6 +13,7 @@ #define RED 1 #define BLACK 0 +extern time_t now; typedef short int sint; typedef struct item { @@ -97,7 +98,7 @@ static void brd_rand() { bzero(brd, sizeof(brd)); bzero(tem, sizeof(tem)); bzero(&curr, sizeof(curr)); - srand(getpid()%2731+time(NULL)%3219); + srand(getpid()%2731+now%3219); for(y=0;y<4;y++) for(x=0;x<8;x++) while(1) { diff --git a/pttbbs/mbbsd/edit.c b/pttbbs/mbbsd/edit.c index 9806526d..9ad0566f 100644 --- a/pttbbs/mbbsd/edit.c +++ b/pttbbs/mbbsd/edit.c @@ -1,4 +1,4 @@ -/* $Id: edit.c,v 1.7 2002/05/01 04:42:16 in2 Exp $ */ +/* $Id: edit.c,v 1.8 2002/05/13 03:20:04 ptt Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -44,6 +44,7 @@ extern userinfo_t *currutmp; extern int KEY_ESC_arg; extern char reset_color[]; extern char trans_buffer[256]; +extern time_t now; #define KEEP_EDITING -2 #define BACKUP_LIMIT 100 @@ -735,7 +736,6 @@ static void read_file(char *fpath) { extern userec_t cuser; void write_header(FILE *fp) { - time_t now = time(0); if(curredit & EDIT_MAIL || curredit & EDIT_LIST) { fprintf(fp, "%s %s (%s)\n", str_author1, cuser.userid, @@ -1007,7 +1007,6 @@ write_file(char *fpath, int saveheader, int *islocal) { #endif ) { - time(&now); ptime = localtime(&now); fprintf(fp, "※ 編輯: %-15s 來自: %-20s (%02d/%02d %02d:%02d)\n", diff --git a/pttbbs/mbbsd/gamble.c b/pttbbs/mbbsd/gamble.c index a2fc3c37..64f04848 100644 --- a/pttbbs/mbbsd/gamble.c +++ b/pttbbs/mbbsd/gamble.c @@ -1,4 +1,4 @@ -/* $Id: gamble.c,v 1.2 2002/03/09 17:27:57 in2 Exp $ */ +/* $Id: gamble.c,v 1.3 2002/05/13 03:20:04 ptt Exp $ */ #include <stdio.h> #include <time.h> #include <string.h> @@ -15,6 +15,7 @@ extern int usernum; #ifndef _BBS_UTIL_C_ extern userec_t cuser; extern int b_lines; +extern time_t now; #define MAX_ITEM 8 //最大 賭項(item) 個數 #define MAX_ITEM_LEN 30 //最大 每一賭項名字長度 @@ -28,7 +29,6 @@ int post_msg(char* bname, char* title, char *msg, char* author) FILE *fp; int bid; fileheader_t fhdr; - time_t now = time(0); char genbuf[256]; /* 在 bname 版發表新文章 */ @@ -237,7 +237,6 @@ int openticket(int bid) { char path[128],buf[256],outcome[128]; int i, money=0, count, bet, price, total = 0, ticket[8]={0,0,0,0,0,0,0,0}; boardheader_t *bh=getbcache(bid); - time_t now = time(NULL); FILE *fp, *fp1; setbpath(path, bh->brdname); diff --git a/pttbbs/mbbsd/gomo.c b/pttbbs/mbbsd/gomo.c index 41650c77..190d6f71 100644 --- a/pttbbs/mbbsd/gomo.c +++ b/pttbbs/mbbsd/gomo.c @@ -1,4 +1,4 @@ -/* $Id: gomo.c,v 1.2 2002/04/28 19:35:29 in2 Exp $ */ +/* $Id: gomo.c,v 1.3 2002/05/13 03:20:04 ptt Exp $ */ #include <stdio.h> #include <stdlib.h> #include <unistd.h> @@ -15,6 +15,7 @@ extern int usernum; extern userinfo_t *currutmp; +extern time_t now; char ku[BRDSIZ][BRDSIZ]; static char *chess[] = { "●", "○" }; @@ -185,7 +186,7 @@ int gomoku(int fd) { me = !(my->turn) + 1; he = my->turn + 1; win = 1; - tick=time(0) + MAX_TIME; + tick=now + MAX_TIME; lastcount = MAX_TIME; setutmpmode(M_FIVE); clear(); @@ -224,8 +225,8 @@ int gomoku(int fd) { for(;;) { move(13, 40); outs(my->turn ? "輪到自己下了!": "等待對方下子.."); - if(lastcount != tick-time(0)) { - lastcount = tick-time(0); + if(lastcount != tick-now) { + lastcount = tick-now; move(18, 40); prints("%s時間還剩%d:%02d\n", my->turn ? "你的" : "對方", lastcount / 60, lastcount % 60); @@ -303,7 +304,7 @@ int gomoku(int fd) { if(ch == I_OTHERDATA) { ch = recv(fd, &mv, sizeof(Horder_t), 0); if(ch != sizeof(Horder_t)) { - lastcount=tick-time(0); + lastcount=tick-now; if(lastcount >=0) { win = 1; cuser.five_lose--; @@ -346,7 +347,7 @@ int gomoku(int fd) { win = chkmv(&mv, he, he == BBLACK); HO_add(&mv); hislasttick = tick; - tick = time(0) + MAX_TIME; + tick = now + MAX_TIME; ku[(int)mv.x][(int)mv.y] = he; bell(); BGOTO(mv.x, mv.y); @@ -382,7 +383,7 @@ int gomoku(int fd) { win = chkmv( &mv, me, me == BBLACK); ku[(int)mv.x][(int)mv.y] = me; mylasttick = tick; - tick = time(0) + MAX_TIME; /*倒數*/ + tick = now + MAX_TIME; /*倒數*/ lastcount = MAX_TIME; if(send(fd, &mv, sizeof(Horder_t), 0) != sizeof(Horder_t)) break; diff --git a/pttbbs/mbbsd/io.c b/pttbbs/mbbsd/io.c index 79a3874f..c969be8e 100644 --- a/pttbbs/mbbsd/io.c +++ b/pttbbs/mbbsd/io.c @@ -1,4 +1,4 @@ -/* $Id: io.c,v 1.9 2002/04/28 19:35:29 in2 Exp $ */ +/* $Id: io.c,v 1.10 2002/05/13 03:20:04 ptt Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -41,28 +41,7 @@ static char outbuf[OBUFSIZE], inbuf[IBUFSIZE]; static int obufsize = 0, ibufsize = 0; static int icurrchar = 0; -/* ----------------------------------------------------- */ -/* 定時顯示動態看板 */ -/* ----------------------------------------------------- */ -extern userec_t cuser; - -static void hit_alarm_clock() { - if(HAS_PERM(PERM_NOTIMEOUT) || PERM_HIDE(currutmp) || currstat == MAILALL) - return; -// if(time(0) - currutmp->lastact > IDLE_TIMEOUT - 2) { - if(time(0) - currutmp->lastact > curr_idle_timeout - 2) { - clear(); - if(currpid > 0) kill(currpid, SIGHUP); - } -// alarm(IDLE_TIMEOUT); - alarm(curr_idle_timeout); -} - -void init_alarm() { - signal(SIGALRM, (void (*)(int))hit_alarm_clock); -// alarm(IDLE_TIMEOUT); - alarm(curr_idle_timeout); -} +time_t now; /* ----------------------------------------------------- */ /* output routines */ @@ -148,7 +127,7 @@ int watermode = -1, wmofo = -1; static int dogetch() { int len; - + static int count=0; if(ibufsize <= icurrchar) { if(flushf) @@ -195,10 +174,20 @@ static int dogetch() { } if(currutmp) - currutmp->lastact = time(0); + { + now= time(0); + if(now-currutmp->lastact<3) + count=0; + else + { + if(++count>100) + system_abort(); + } + currutmp->lastact = now; + } return inbuf[icurrchar++]; } - +extern userec_t cuser; static int water_which_flag=0; int igetch() { register int ch; diff --git a/pttbbs/mbbsd/kaede.c b/pttbbs/mbbsd/kaede.c index c0bd5103..d3f9355b 100644 --- a/pttbbs/mbbsd/kaede.c +++ b/pttbbs/mbbsd/kaede.c @@ -1,4 +1,4 @@ -/* $Id: kaede.c,v 1.1 2002/03/07 15:13:48 in2 Exp $ */ +/* $Id: kaede.c,v 1.2 2002/05/13 03:20:04 ptt Exp $ */ #include <stdio.h> #include <string.h> #include <time.h> @@ -11,6 +11,7 @@ extern struct utmpfile_t *utmpshm; extern userec_t cuser; +extern time_t now; char *Ptt_prints(char *str, int mode) { char *po , strbuf[256]; @@ -21,7 +22,6 @@ char *Ptt_prints(char *str, int mode) { strcpy(str, strbuf); } while((po = strstr(str, "\033*t"))) { - time_t now = time(0); po[0] = 0; sprintf(strbuf, "%s%s", str, Cdate(&now)); diff --git a/pttbbs/mbbsd/lovepaper.c b/pttbbs/mbbsd/lovepaper.c index 92330db7..dffdee69 100644 --- a/pttbbs/mbbsd/lovepaper.c +++ b/pttbbs/mbbsd/lovepaper.c @@ -1,4 +1,4 @@ -/* $Id: lovepaper.c,v 1.2 2002/04/28 19:35:29 in2 Exp $ */ +/* $Id: lovepaper.c,v 1.3 2002/05/13 03:20:04 ptt Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -14,19 +14,18 @@ #define DATA "etc/lovepaper.dat" extern userec_t cuser; +extern time_t now; int x_love() { char buf1[200], save_title[TTLEN + 1]; char receiver[61], path[STRLEN] = "home/"; int x, y = 0, tline = 0, poem = 0; FILE *fp, *fpo; - time_t timenow; struct tm *gtime; fileheader_t mhdr; setutmpmode(LOVE); - time(&timenow); - gtime = localtime(&timenow); + gtime = localtime(&now); sprintf(buf1,"%c/%s/love%d%d", cuser.userid[0], cuser.userid,gtime->tm_sec,gtime->tm_min); strcat(path,buf1); diff --git a/pttbbs/mbbsd/mail.c b/pttbbs/mbbsd/mail.c index 34c629cb..35b6a000 100644 --- a/pttbbs/mbbsd/mail.c +++ b/pttbbs/mbbsd/mail.c @@ -1,4 +1,4 @@ -/* $Id: mail.c,v 1.6 2002/05/10 19:34:51 in2 Exp $ */ +/* $Id: mail.c,v 1.7 2002/05/13 03:20:04 ptt Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -44,7 +44,7 @@ extern pid_t currpid; extern int usernum; extern char *str_mail_address; extern userec_t cuser; - +extern time_t now; char currmaildir[32]; static char msg_cc[] = "\033[32m[群組名單]\033[m\n"; static char listfile[] = "list.0"; @@ -879,11 +879,10 @@ static int mail_del(int ent, fileheader_t *fhdr, char *direct) { setdirpath(genbuf, direct, fhdr->filename); unlink(genbuf); if((currmode & MODE_SELECT)) { - int now; - + int index; sethomedir(genbuf, cuser.userid); - now = getindex(genbuf, fhdr->filename, sizeof(fileheader_t)); - delete_file(genbuf, sizeof(fileheader_t), now, cmpfilename); + index = getindex(genbuf, fhdr->filename, sizeof(fileheader_t)); + delete_file(genbuf, sizeof(fileheader_t), index, cmpfilename); } return DIRCHANGED; } @@ -905,11 +904,11 @@ static int mail_read(int ent, fileheader_t *fhdr, char *direct) { if(more_result != -1) { fhdr->filemode |= FILE_READ; if((currmode & MODE_SELECT)) { - int now; + int index; - now = getindex(currmaildir, fhdr->filename, + index = getindex(currmaildir, fhdr->filename, sizeof(fileheader_t)); - substitute_record(currmaildir, fhdr, sizeof(*fhdr), now); + substitute_record(currmaildir, fhdr, sizeof(*fhdr), index); substitute_record(direct, fhdr, sizeof(*fhdr), ent); } else @@ -967,10 +966,10 @@ static int mail_read(int ent, fileheader_t *fhdr, char *direct) { bug_possible = YEA; #endif if((currmode & MODE_SELECT)) { - int now; + int index; - now = getindex(currmaildir, fhdr->filename, sizeof(fileheader_t)); - substitute_record(currmaildir, fhdr, sizeof(*fhdr), now); + index = getindex(currmaildir, fhdr->filename, sizeof(fileheader_t)); + substitute_record(currmaildir, fhdr, sizeof(*fhdr), index); substitute_record(direct, fhdr, sizeof(*fhdr), ent); } else substitute_record(currmaildir, fhdr, sizeof(*fhdr), ent); @@ -1063,10 +1062,10 @@ static int mail_mark(int ent, fileheader_t *fhdr, char *direct) { fhdr->filemode ^= FILE_MARKED; if((currmode & MODE_SELECT)) { - int now; + int index; - now = getindex(currmaildir, fhdr->filename, sizeof(fileheader_t)); - substitute_record(currmaildir, fhdr, sizeof(*fhdr), now); + index = getindex(currmaildir, fhdr->filename, sizeof(fileheader_t)); + substitute_record(currmaildir, fhdr, sizeof(*fhdr), index); substitute_record(direct, fhdr, sizeof(*fhdr), ent); } else substitute_record(currmaildir, fhdr, sizeof(*fhdr), ent); @@ -1282,7 +1281,6 @@ static int mail_waterball(int ent, fileheader_t *fhdr, char *direct) static char address[60], cmode = 1; char fname[500], genbuf[200]; FILE *fp; - int now; if(!address[0]) strcpy(address, cuser.email); @@ -1310,7 +1308,6 @@ static int mail_waterball(int ent, fileheader_t *fhdr, char *direct) getdata(b_lines - 1, 0, "使用模式(0/1)? [1]", fname, 3, LCECHO); cmode = (fname[0] != '0' && fname[0] != '1') ? 1 : fname[0] - '0'; - now = time(NULL); sprintf(fname, BBSHOME "/jobspool/water.src.%s-%d", cuser.userid, now); sprintf(genbuf, "cp " BBSHOME "/home/%c/%s/%s %s", @@ -1402,7 +1399,6 @@ static int bbs_sendmail(char *fpath, char *title, char *receiver) { /* 中途攔截 */ if((ptr = strchr(receiver, ';'))) { struct tm *ptime; - time_t now; *ptr = '\0'; } @@ -1489,7 +1485,7 @@ int bsmtp(char *fpath, char *title, char *rcpt, int method) { return send_inner_mail(fpath, title, hacker); } - chrono = time(NULL); + chrono = now; if(method != MQ_JUSTIFY) { /* 認證信 */ /* stamp the queue file */ strcpy(buf, "out/"); @@ -1563,7 +1559,6 @@ int doforward(char *direct, fileheader_t *fh, int mode) { /* 追蹤使用者 */ if(HAS_PERM(PERM_LOGUSER)) { - time_t now = time(NULL); char msg[200]; sprintf(msg, "%s mailforward to %s at %s", diff --git a/pttbbs/mbbsd/mbbsd.c b/pttbbs/mbbsd/mbbsd.c index 496ea00f..9a46738a 100644 --- a/pttbbs/mbbsd/mbbsd.c +++ b/pttbbs/mbbsd/mbbsd.c @@ -1,4 +1,4 @@ -/* $Id: mbbsd.c,v 1.24 2002/04/28 19:35:29 in2 Exp $ */ +/* $Id: mbbsd.c,v 1.25 2002/05/13 03:20:04 ptt Exp $ */ #include <stdio.h> #include <string.h> #include <stdlib.h> @@ -39,7 +39,7 @@ extern int t_lines, t_columns; /* Screen size / width */ extern int b_lines; /* Screen bottom line number: t_lines-1 */ extern userinfo_t *currutmp; extern int curr_idle_timeout; - +extern time_t now; static void do_aloha (char *hello); #if 0 @@ -175,7 +175,6 @@ void log_usies (char *mode, char *mesg) { char genbuf[200]; - time_t now = time (0); if (!mesg) sprintf (genbuf, cuser.userid[0] ? "%s %s %-12s Stay:%d (%s)" : @@ -233,7 +232,7 @@ u_exit (char *mode) log_usies (mode, NULL); } -static void +void system_abort () { if (currmode) @@ -778,11 +777,6 @@ static void setup_utmp (int mode) { userinfo_t uinfo; - /* - char buf[80]; - char remotebuf[1024]; - time_t now = time(NULL); - */ memset (&uinfo, 0, sizeof (uinfo)); uinfo.pid = currpid = getpid (); uinfo.uid = usernum; diff --git a/pttbbs/mbbsd/menu.c b/pttbbs/mbbsd/menu.c index f65a1e89..5108606e 100644 --- a/pttbbs/mbbsd/menu.c +++ b/pttbbs/mbbsd/menu.c @@ -1,4 +1,4 @@ -/* $Id: menu.c,v 1.7 2002/05/08 22:31:23 in2 Exp $ */ +/* $Id: menu.c,v 1.8 2002/05/13 03:20:04 ptt Exp $ */ #include <stdio.h> #include <stdlib.h> #include <time.h> @@ -21,7 +21,7 @@ extern char reset_color[]; extern userinfo_t *currutmp; extern char *BBSName; extern int b_lines; /* Screen bottom line number: t_lines-1 */ - +extern time_t now; /* help & menu processring */ static int refscreen = NA; extern char *boardprefix; @@ -122,8 +122,8 @@ void movie(int i) { static short history[MAX_HISTORY]; static char myweek[] = "天一二三四五六"; const char *msgs[] = {"關閉", "打開", "拔掉", "防水","好友"}; - time_t now = time(NULL); struct tm *ptime = localtime(&now); + int j; if((currstat != CLASS) && (cuser.uflag & MOVIE_FLAG) && !ptt->busystate && ptt->max_film > 0) { @@ -136,8 +136,8 @@ void movie(int i) { i = 1 + (int)(((float)ptt->max_film * rand()) / (RAND_MAX + 1.0)); - for(now = ptt->max_history; now >= 0; now--) - if(i == history[now]) { + for(j = ptt->max_history; j >= 0; j--) + if(i == history[j]) { i = 0; break; } @@ -145,7 +145,7 @@ void movie(int i) { } memcpy(history, &history[1], ptt->max_history * sizeof(short)); - history[ptt->max_history] = now = i; + history[ptt->max_history] = j = i; if(i == 999) /* Goodbye my friend */ i = 0; diff --git a/pttbbs/mbbsd/more.c b/pttbbs/mbbsd/more.c index f8d32c61..87d71fe9 100644 --- a/pttbbs/mbbsd/more.c +++ b/pttbbs/mbbsd/more.c @@ -1,4 +1,4 @@ -/* $Id: more.c,v 1.12 2002/04/28 19:35:29 in2 Exp $ */ +/* $Id: more.c,v 1.13 2002/05/13 03:20:04 ptt Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -24,7 +24,7 @@ extern char *str_post1; extern char *str_post2; extern char *msg_seperator; extern char reset_color[]; - +extern time_t now; #define MORE_BUFSIZE 4096 #define MORE_WINSIZE 4096 #define STR_ANSICODE "[0123456789;," @@ -780,7 +780,7 @@ static int more_web(char *fpath, int promptend) { #ifdef LOCAL_PROXY /* 先找 local disk 的 proxy */ - time(&dtime); + dtime=now; sprintf(userfile,"hproxy/%s%s",hostname,file); if(dashf(userfile) && (dtime - dasht(userfile)) < HPROXYDAY * 24 * 60 && more(userfile,promptend)) { diff --git a/pttbbs/mbbsd/record.c b/pttbbs/mbbsd/record.c index b572b7cf..2f82b372 100644 --- a/pttbbs/mbbsd/record.c +++ b/pttbbs/mbbsd/record.c @@ -1,4 +1,4 @@ -/* $Id: record.c,v 1.3 2002/04/15 20:00:22 in2 Exp $ */ +/* $Id: record.c,v 1.4 2002/05/13 03:20:04 ptt Exp $ */ #include <stdio.h> #include <stdlib.h> #include <errno.h> @@ -17,7 +17,7 @@ #define BUFSIZE 512 extern char *str_reply; - +extern time_t now; static void PttLock(int fd, int size, int mode) { static struct flock lock_it; int ret; @@ -116,7 +116,7 @@ force_open (char *fname) int fd; time_t expire; - expire = time(NULL) - 3600; /* lock 存在超過一個小時就是有問題! */ + expire = now - 3600; /* lock 存在超過一個小時就是有問題! */ if (dasht (fname) < expire) return -1; unlink(fname); @@ -422,14 +422,13 @@ int apply_record(char *fpath, int (*fptr)(), int size) { /* mail / post 時,依據時間建立檔案,加上郵戳 */ int stampfile(char *fpath, fileheader_t *fh) { register char *ip = fpath; - time_t dtime; + time_t dtime=now; struct tm *ptime; int fp = 0; if(access(fpath, X_OK | R_OK | W_OK)) mkdir(fpath, 0755); - time(&dtime); while (*(++ip)); *ip++ = '/'; do { @@ -447,13 +446,12 @@ int stampfile(char *fpath, fileheader_t *fh) { void stampdir(char *fpath, fileheader_t *fh) { register char *ip = fpath; - time_t dtime; + time_t dtime=now; struct tm *ptime; if(access(fpath, X_OK | R_OK | W_OK)) mkdir(fpath, 0755); - time(&dtime); while(*(++ip)); *ip++ = '/'; do { @@ -467,13 +465,12 @@ void stampdir(char *fpath, fileheader_t *fh) { void stamplink(char *fpath, fileheader_t *fh) { register char *ip = fpath; - time_t dtime; + time_t dtime=now; struct tm *ptime; if(access(fpath, X_OK | R_OK | W_OK)) mkdir(fpath, 0755); - time(&dtime); while(*(++ip)); *ip++ = '/'; do { diff --git a/pttbbs/mbbsd/register.c b/pttbbs/mbbsd/register.c index 53acc82f..36b30f46 100644 --- a/pttbbs/mbbsd/register.c +++ b/pttbbs/mbbsd/register.c @@ -1,4 +1,4 @@ -/* $Id: register.c,v 1.3 2002/04/28 19:35:29 in2 Exp $ */ +/* $Id: register.c,v 1.4 2002/05/13 03:20:04 ptt Exp $ */ #define _XOPEN_SOURCE #include <stdio.h> @@ -21,7 +21,7 @@ extern char *str_new; extern char *msg_uid; extern int t_lines, t_columns; /* Screen size / width */ extern char *str_mail_address; - +extern time_t now; /* password encryption */ static char pwbuf[14]; @@ -111,7 +111,6 @@ static int compute_user_value(userec_t *urec, time_t clock) { int check_and_expire_account(int uid,userec_t *urec) { userec_t zerorec; - time_t now=time(NULL); char genbuf[200],genbuf2[200]; int val; if((val = compute_user_value(urec, now)) < 0) { @@ -153,7 +152,7 @@ int getnewuserid() { int fd, i; memset(&zerorec, 0, sizeof(zerorec)); - clock = time(NULL); + clock = now; /* Lazy method : 先找尋已經清除的過期帳號 */ if((i = searchnewuser(0)) == 0) { @@ -265,7 +264,7 @@ void new_register() { } newuser.userlevel = PERM_DEFAULT; newuser.uflag = COLOR_FLAG | BRDSORT_FLAG | MOVIE_FLAG; - newuser.firstlogin = newuser.lastlogin = time(NULL); + newuser.firstlogin = newuser.lastlogin = now; newuser.money = 0; newuser.pager = 1; allocid = getnewuserid(); diff --git a/pttbbs/mbbsd/syspost.c b/pttbbs/mbbsd/syspost.c index c7bd163b..6145be26 100644 --- a/pttbbs/mbbsd/syspost.c +++ b/pttbbs/mbbsd/syspost.c @@ -1,4 +1,4 @@ -/* $Id: syspost.c,v 1.5 2002/05/08 14:11:33 lwms Exp $ */ +/* $Id: syspost.c,v 1.6 2002/05/13 03:20:04 ptt Exp $ */ #include <stdio.h> #include <string.h> #include <time.h> @@ -11,11 +11,10 @@ extern char *str_permid[]; extern userec_t cuser; - +extern time_t now; void post_change_perm(int oldperm, int newperm, char *sysopid, char *userid) { FILE *fp; fileheader_t fhdr; - time_t now = time(0); char genbuf[200], reason[30]; int i, flag=0; @@ -56,13 +55,11 @@ void post_change_perm(int oldperm, int newperm, char *sysopid, char *userid) { void post_violatelaw(char* crime, char* police, char* reason, char* result){ char genbuf[200]; fileheader_t fhdr; - time_t now; FILE *fp; strcpy(genbuf, "boards/S/Security"); stampfile(genbuf, &fhdr); if(!(fp = fopen(genbuf,"w"))) return; - now = time(NULL); fprintf(fp, "作者: [Ptt法院] 看板: Security\n" "標題: [報告] %-20s 違法判決報告\n" "時間: %s\n" @@ -78,7 +75,6 @@ void post_violatelaw(char* crime, char* police, char* reason, char* result){ stampfile(genbuf, &fhdr); if(!(fp = fopen(genbuf,"w"))) return; - now = time(NULL); fprintf(fp, "作者: [Ptt法院] 看板: ViolateLaw\n" "標題: [報告] %-20s 違法判決報告\n" "時間: %s\n" diff --git a/pttbbs/mbbsd/talk.c b/pttbbs/mbbsd/talk.c index ef96ca35..8937df3d 100644 --- a/pttbbs/mbbsd/talk.c +++ b/pttbbs/mbbsd/talk.c @@ -1,4 +1,4 @@ -/* $Id: talk.c,v 1.32 2002/05/11 16:53:25 in2 Exp $ */ +/* $Id: talk.c,v 1.33 2002/05/13 03:20:04 ptt Exp $ */ #include <stdio.h> #include <string.h> #include <errno.h> @@ -47,7 +47,7 @@ extern boardheader_t *bcache; extern int curr_idle_timeout; extern userec_t cuser; extern userec_t xuser; - +extern time_t now; static char *IdleTypeTable[] = { "偶在花呆啦", "情人來電", "覓食中", "拜見周公", "假死狀態", "我在思考" @@ -590,7 +590,6 @@ int my_write(pid_t pid, char *prompt, char *id, int flag, userinfo_t *puin) char msg[80], destid[IDLEN + 1]; char genbuf[200], buf[200], c0 = currutmp->chatid[0]; unsigned char mode0 = currutmp->mode; - time_t now; struct tm *ptime; userinfo_t *uin; uin = (puin != NULL) ? puin : (userinfo_t *)search_ulist_pid(pid); @@ -607,7 +606,6 @@ int my_write(pid_t pid, char *prompt, char *id, int flag, userinfo_t *puin) currutmp->chatid[0] = 3; currstat = XMODE; - time(&now); ptime = localtime(&now); if(flag == 0) { @@ -665,7 +663,6 @@ int my_write(pid_t pid, char *prompt, char *id, int flag, userinfo_t *puin) } fri_stat=friend_stat(currutmp, uin); - time(&now); if(flag != 2) { /* aloha 的水球不用存下來 */ /* 存到自己的水球檔 */ if(!fp_writelog){ @@ -994,10 +991,8 @@ static void do_talk(int fd) int im_leaving = 0; FILE *log; struct tm *ptime; - time_t now; char genbuf[200], fpath[100]; - time(&now); ptime = localtime(&now); sethomepath(fpath, cuser.userid); @@ -1100,7 +1095,6 @@ static void do_talk(int fd) extern unsigned char scr_lns; int i; - time(&now); fprintf(flog, "\n\033[33;44m離別畫面 [%s] ... \033[m\n", Cdatelite(&now)); for (i = 0; i < scr_lns; i++) @@ -1549,23 +1543,6 @@ static int pickup_user_cmp(time_t now, int sortedway, int cmp_fri, if (ifh_number && fri_stat & IFH) (*ifh_number)++; if (hfm_number && fri_stat & HFM) (*hfm_number)++; if (irh_number && fri_stat & IRH) (*irh_number)++; -#if 0 -#ifdef SHOW_IDLE_TIME - diff = now - uentp->lastact; -#ifdef DOTIMEOUT - /* in2: timeout拿到 shmctl utmpfix去做, 一小時一次就夠了 */ - /* prevent fault /dev mount from kicking out users */ - if ((diff > curr_idle_timeout + 10) && - (diff < 60 * 60 * 24 * 5)){ - if ((uentp->pid <= 0 || kill(uentp->pid, SIGHUP) == -1) && - (errno == ESRCH)) - purge_utmp(uentp); - continue; - } -#endif - pklist[count].idle = diff; -#endif -#endif pklist[count].friend = fri_stat; pklist[count].ui = uentp; count++; @@ -1640,7 +1617,7 @@ static void pickup_user(void) if (utmpshm->uptime > freshtime || state == US_PICKUP || state ==US_RESORT){ state = US_PICKUP; - time(&freshtime); + freshtime=now; ifh_number=hfm_number=irh_number=bfriends_number = actor = ch = 0; if(pickup_way==0) sortedway=0; diff --git a/pttbbs/mbbsd/user.c b/pttbbs/mbbsd/user.c index 3cce4bc5..9f5d7245 100644 --- a/pttbbs/mbbsd/user.c +++ b/pttbbs/mbbsd/user.c @@ -1,4 +1,4 @@ -/* $Id: user.c,v 1.15 2002/04/28 19:35:29 in2 Exp $ */ +/* $Id: user.c,v 1.16 2002/05/13 03:20:04 ptt Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -31,6 +31,7 @@ extern char *fn_register; extern char *msg_nobody; extern userec_t cuser; extern userec_t xuser; +extern time_t now; static char *sex[8] = { MSG_BIG_BOY, MSG_BIG_GIRL, MSG_LITTLE_BOY, MSG_LITTLE_GIRL, @@ -110,7 +111,7 @@ void user_display(userec_t *u, int real) { " user權限: %s\n", u->justify, genbuf); } else { - diff = (time(0) - login_start_time) / 60; + diff = (now - login_start_time) / 60; prints(" 停留期間: %d 小時 %2d 分\n", diff / 60, diff % 60); } @@ -146,13 +147,11 @@ void user_display(userec_t *u, int real) { void mail_violatelaw(char* crime, char* police, char* reason, char* result){ char genbuf[200]; fileheader_t fhdr; - time_t now; FILE *fp; sprintf(genbuf, "home/%c/%s", crime[0], crime); stampfile(genbuf, &fhdr); if(!(fp = fopen(genbuf,"w"))) return; - now = time(NULL); fprintf(fp, "作者: [Ptt法院]\n" "標題: [報告] 違法判決報告\n" "時間: %s\n" @@ -401,7 +400,6 @@ void uinfo_query(userec_t *u, int real, int unum) { } else{ char witness[3][32]; - time_t now = time(NULL); for(i=0;i<3;i++){ if(!getdata(19+i, 0, "請輸入協助證明之使用者:", witness[i], sizeof(witness[i]), DOECHO)){ @@ -523,14 +521,12 @@ void uinfo_query(userec_t *u, int real, int unum) { if(money_change) setumoney(unum,x.money); passwd_update(unum, &x); - now = time(0); if(money_change) { strcpy(genbuf, "boards/S/Security"); stampfile(genbuf, &fhdr); if(!(fp = fopen(genbuf,"w"))) return; - now = time(NULL); fprintf(fp, "作者: [系統安全局] 看板: Security\n" "標題: [公安報告] 站長修改金錢報告\n" "時間: %s\n" @@ -816,7 +812,6 @@ static void toregister(char *email, char *genbuf, char *phone, char *career, char *ident, char *rname, char *addr, char *mobile) { FILE *fn; - time_t now; char buf[128]; sethomefile(buf, cuser.userid, "justify.wait"); @@ -857,7 +852,6 @@ static void toregister(char *email, char *genbuf, char *phone, char *career, strncpy(cuser.email, email, sizeof(cuser.email)); if( email[0] == 'x' || email[0] == 'X' ){ /* 手動認證 */ if ((fn = fopen(fn_register, "a"))) { - now = time(NULL); fprintf(fn, "num: %d, %s", usernum, ctime(&now)); fprintf(fn, "uid: %s\n", cuser.userid); fprintf(fn, "ident: %s\n", ident); diff --git a/pttbbs/mbbsd/vote.c b/pttbbs/mbbsd/vote.c index 9cc55b40..ca288481 100644 --- a/pttbbs/mbbsd/vote.c +++ b/pttbbs/mbbsd/vote.c @@ -1,4 +1,4 @@ -/* $Id: vote.c,v 1.6 2002/04/28 19:35:29 in2 Exp $ */ +/* $Id: vote.c,v 1.7 2002/05/13 03:20:04 ptt Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -122,7 +122,7 @@ static int b_nonzeroNum(char *buf) { } return i; } - +extern time_t now; static void vote_report(char *bname, char *fname, char *fpath) { register char *ip; time_t dtime; @@ -135,7 +135,7 @@ static void vote_report(char *bname, char *fname, char *fpath) { /* get a filename by timestamp */ - dtime = time(0); + dtime = now; for(;;) { sprintf(ip, "M.%ld.A", ++dtime); fd = open(fpath, O_CREAT | O_EXCL | O_WRONLY, 0644); @@ -185,7 +185,7 @@ static void b_result_one(boardheader_t *fh, int ind) { char b_control[64]; char b_newresults[64]; char b_report[64]; - time_t closetime, now; + time_t closetime; fh->bvote--; @@ -233,7 +233,6 @@ static void b_result_one(boardheader_t *fh, int ind) { if((tfp = fopen(b_newresults, "w")) == NULL) return; - now = time(NULL); setbfile(buf, bname, STR_new_title); if((xfp=fopen(buf,"r"))) { @@ -295,12 +294,11 @@ static void b_result_one(boardheader_t *fh, int ind) { static void b_result(boardheader_t *fh) { FILE *cfp; - time_t closetime, now; + time_t closetime; int i; char buf[STRLEN]; char temp[STRLEN]; - now = time(NULL); for(i = 0; i < 20; i++) { if(i) sprintf(STR_new_control, "%s%d", STR_bv_control, i); @@ -320,8 +318,6 @@ static void b_result(boardheader_t *fh) { } static int b_close(boardheader_t *fh) { - time_t now; - now = time(NULL); if(fh->bvote == 2) { if(fh->vtime < now - 3 * 86400) { @@ -339,12 +335,10 @@ int b_closepolls() { static char *fn_vote_polling = ".polling"; boardheader_t *fhp; FILE *cfp; - time_t now; int pos, dirty; time_t last; char timebuf[100]; - now = time(NULL); /* Edited by CharlieL for can't auto poll bug */ if((cfp = fopen(fn_vote_polling,"r"))) { @@ -697,7 +691,7 @@ static int vote_maintain(char *bname) { else if(closetime >10) closetime = 10; - closetime = closetime * 86400 + time(NULL); + closetime = closetime * 86400 + now; setbfile(buf, bname, STR_new_control); fp = fopen(buf, "w"); fprintf(fp, "00\n%lu\n", closetime); diff --git a/pttbbs/mbbsd/voteboard.c b/pttbbs/mbbsd/voteboard.c index dbc23412..8b92adb7 100644 --- a/pttbbs/mbbsd/voteboard.c +++ b/pttbbs/mbbsd/voteboard.c @@ -1,4 +1,4 @@ -/* $Id: voteboard.c,v 1.4 2002/04/28 19:35:29 in2 Exp $ */ +/* $Id: voteboard.c,v 1.5 2002/05/13 03:20:04 ptt Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -21,6 +21,7 @@ extern int currbid; extern boardheader_t *bcache; extern int currmode; extern userec_t cuser; +extern time_t now; void do_voteboardreply(fileheader_t *fhdr){ char genbuf[1024]; @@ -34,7 +35,7 @@ void do_voteboardreply(fileheader_t *fhdr){ int len; int i, j; int fd; - time_t endtime, now = time(NULL); + time_t endtime; int hastime = 0; @@ -203,7 +204,6 @@ int do_voteboard() { char fpath[80]; FILE* fp; int temp, i; - time_t now = time(NULL); clear(); if(!(currmode & MODE_POST)) { diff --git a/pttbbs/mbbsd/xyz.c b/pttbbs/mbbsd/xyz.c index 1cac394a..daa0116e 100644 --- a/pttbbs/mbbsd/xyz.c +++ b/pttbbs/mbbsd/xyz.c @@ -1,4 +1,4 @@ -/* $Id: xyz.c,v 1.4 2002/05/06 13:34:11 ptt Exp $ */ +/* $Id: xyz.c,v 1.5 2002/05/13 03:20:04 ptt Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -22,7 +22,7 @@ extern char fromhost[]; extern userinfo_t *currutmp; extern int curr_idle_timeout; extern userec_t cuser; - +extern time_t now; /* 各種統計及相關資訊列表 */ /* Ptt90年度大學聯招查榜系統 */ int x_90() { @@ -194,7 +194,7 @@ int note() { strcpy(myitem.userid, cuser.userid); strncpy(myitem.username, cuser.username, 18); myitem.username[18] = '\0'; - time(&(myitem.date)); + myitem.date=now; /* begin load file */ if((foo = fopen(".note", "a")) == NULL) -- cgit v1.2.3 From a78b532edfefa159b554f68cab9511be059fe642 Mon Sep 17 00:00:00 2001 From: ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Mon, 13 May 2002 05:22:51 +0000 Subject: =?UTF-8?q?=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@164 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/cache.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pttbbs/mbbsd/cache.c b/pttbbs/mbbsd/cache.c index a2d1c98a..9d7162fc 100644 --- a/pttbbs/mbbsd/cache.c +++ b/pttbbs/mbbsd/cache.c @@ -1,4 +1,4 @@ -/* $Id: cache.c,v 1.23 2002/05/13 03:20:04 ptt Exp $ */ +/* $Id: cache.c,v 1.24 2002/05/13 05:22:51 ptt Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -377,6 +377,7 @@ static int cmputmpuid(const void *i, const void *j){ void sort_utmp() { int count, i, ns; + time_t now= time(0); userinfo_t *uentp; if(now-utmpshm->uptime<60 && (now==utmpshm->uptime || utmpshm->busystate)) -- cgit v1.2.3 From 76ebdc90d4f19ea31b36d0c5a4e62724f31c0c12 Mon Sep 17 00:00:00 2001 From: ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Mon, 13 May 2002 09:16:44 +0000 Subject: anti robot test git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@165 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/io.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/pttbbs/mbbsd/io.c b/pttbbs/mbbsd/io.c index c969be8e..d2219b64 100644 --- a/pttbbs/mbbsd/io.c +++ b/pttbbs/mbbsd/io.c @@ -1,4 +1,4 @@ -/* $Id: io.c,v 1.10 2002/05/13 03:20:04 ptt Exp $ */ +/* $Id: io.c,v 1.11 2002/05/13 09:16:44 ptt Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -127,7 +127,7 @@ int watermode = -1, wmofo = -1; static int dogetch() { int len; - static int count=0; + static time_t anti_robot=0; if(ibufsize <= icurrchar) { if(flushf) @@ -177,13 +177,15 @@ static int dogetch() { { now= time(0); if(now-currutmp->lastact<3) - count=0; + anti_robot=now; + else if(!anti_robot || now-anti_robot < IDLE_TIMEOUT) + { + currutmp->lastact = now; + } else { - if(++count>100) - system_abort(); + currutmp->lastact = now - IDLE_TIMEOUT - 10; } - currutmp->lastact = now; } return inbuf[icurrchar++]; } -- cgit v1.2.3 From 9d71429ea5b36b2504eaf36c20df08767aad2332 Mon Sep 17 00:00:00 2001 From: ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Mon, 13 May 2002 10:00:17 +0000 Subject: now's problem git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@166 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/cache.c | 5 ++--- pttbbs/mbbsd/mbbsd.c | 3 ++- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pttbbs/mbbsd/cache.c b/pttbbs/mbbsd/cache.c index 9d7162fc..ec85a4db 100644 --- a/pttbbs/mbbsd/cache.c +++ b/pttbbs/mbbsd/cache.c @@ -1,4 +1,4 @@ -/* $Id: cache.c,v 1.24 2002/05/13 05:22:51 ptt Exp $ */ +/* $Id: cache.c,v 1.25 2002/05/13 10:00:17 ptt Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -377,9 +377,8 @@ static int cmputmpuid(const void *i, const void *j){ void sort_utmp() { int count, i, ns; - time_t now= time(0); userinfo_t *uentp; - + now=time(0); if(now-utmpshm->uptime<60 && (now==utmpshm->uptime || utmpshm->busystate)) return; /* lazy sort */ utmpshm->busystate=1; diff --git a/pttbbs/mbbsd/mbbsd.c b/pttbbs/mbbsd/mbbsd.c index 9a46738a..07f1b955 100644 --- a/pttbbs/mbbsd/mbbsd.c +++ b/pttbbs/mbbsd/mbbsd.c @@ -1,4 +1,4 @@ -/* $Id: mbbsd.c,v 1.25 2002/05/13 03:20:04 ptt Exp $ */ +/* $Id: mbbsd.c,v 1.26 2002/05/13 10:00:17 ptt Exp $ */ #include <stdio.h> #include <string.h> #include <stdlib.h> @@ -581,6 +581,7 @@ login_query () resolve_utmp (); resolve_garbage (); attach_uhash (); + now= time(0); attempts = utmpshm->number; show_file ("etc/Welcome", 1, -1, NO_RELOAD); output ("1", 1); -- cgit v1.2.3 From bcca7e84845e54d90381318a5698f98a60b2da9f Mon Sep 17 00:00:00 2001 From: ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Tue, 14 May 2002 14:48:01 +0000 Subject: fix idle time git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@167 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/io.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pttbbs/mbbsd/io.c b/pttbbs/mbbsd/io.c index d2219b64..b6c67825 100644 --- a/pttbbs/mbbsd/io.c +++ b/pttbbs/mbbsd/io.c @@ -1,4 +1,4 @@ -/* $Id: io.c,v 1.11 2002/05/13 09:16:44 ptt Exp $ */ +/* $Id: io.c,v 1.12 2002/05/14 14:48:01 ptt Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -184,7 +184,7 @@ static int dogetch() { } else { - currutmp->lastact = now - IDLE_TIMEOUT - 10; + currutmp->lastact = anti_robot; } } return inbuf[icurrchar++]; -- cgit v1.2.3 From 93a5f340d03763964f099995138f879174fa577d Mon Sep 17 00:00:00 2001 From: ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Tue, 14 May 2002 15:08:48 +0000 Subject: idle timeout improvement git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@168 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/io.c | 3 +-- pttbbs/mbbsd/mbbsd.c | 7 +------ pttbbs/mbbsd/talk.c | 11 ++++++----- pttbbs/mbbsd/var.c | 3 +-- pttbbs/mbbsd/xyz.c | 3 +-- 5 files changed, 10 insertions(+), 17 deletions(-) diff --git a/pttbbs/mbbsd/io.c b/pttbbs/mbbsd/io.c index b6c67825..a52b7835 100644 --- a/pttbbs/mbbsd/io.c +++ b/pttbbs/mbbsd/io.c @@ -1,4 +1,4 @@ -/* $Id: io.c,v 1.12 2002/05/14 14:48:01 ptt Exp $ */ +/* $Id: io.c,v 1.13 2002/05/14 15:08:47 ptt Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -33,7 +33,6 @@ extern pid_t currpid; extern int errno; extern screenline_t *big_picture; extern int t_lines, t_columns; /* Screen size / width */ -extern int curr_idle_timeout; extern water_t water[6], *swater[5], *water_which; extern char water_usies; diff --git a/pttbbs/mbbsd/mbbsd.c b/pttbbs/mbbsd/mbbsd.c index 07f1b955..8ea6f8d1 100644 --- a/pttbbs/mbbsd/mbbsd.c +++ b/pttbbs/mbbsd/mbbsd.c @@ -1,4 +1,4 @@ -/* $Id: mbbsd.c,v 1.26 2002/05/13 10:00:17 ptt Exp $ */ +/* $Id: mbbsd.c,v 1.27 2002/05/14 15:08:48 ptt Exp $ */ #include <stdio.h> #include <string.h> #include <stdlib.h> @@ -38,7 +38,6 @@ extern int t_lines, t_columns; /* Screen size / width */ extern int b_lines; /* Screen bottom line number: t_lines-1 */ extern userinfo_t *currutmp; -extern int curr_idle_timeout; extern time_t now; static void do_aloha (char *hello); @@ -149,10 +148,6 @@ chkload (char *buf) #endif if (i > MAX_CPULOAD) return 1; - else if (i > MAX_CPULOAD / 2) - curr_idle_timeout = 10 * 60; - else - curr_idle_timeout = 30 * 60; return 0; } diff --git a/pttbbs/mbbsd/talk.c b/pttbbs/mbbsd/talk.c index 8937df3d..70fb4fd8 100644 --- a/pttbbs/mbbsd/talk.c +++ b/pttbbs/mbbsd/talk.c @@ -1,4 +1,4 @@ -/* $Id: talk.c,v 1.33 2002/05/13 03:20:04 ptt Exp $ */ +/* $Id: talk.c,v 1.34 2002/05/14 15:08:48 ptt Exp $ */ #include <stdio.h> #include <string.h> #include <errno.h> @@ -44,7 +44,6 @@ extern int talkrequest; extern char *msg_shortulist; extern char *msg_nobody; extern boardheader_t *bcache; -extern int curr_idle_timeout; extern userec_t cuser; extern userec_t xuser; extern time_t now; @@ -1708,9 +1707,11 @@ static void pickup_user(void) #ifdef SHOW_IDLE_TIME diff = freshtime - pklist[ch].ui->lastact; //diff = pklist[ch].idle; - if (diff > 1800) diff = 1800; /* Doma: 以免一大串的發呆時間 */ - /* in2: max 30'00 :P */ - if (diff > 0) + // if (diff > 1800) diff = 1800; /* Doma: 以免一大串的發呆時間 */ + // in2: max 30'00 :P Ptt:真實沒關係 + if (diff > 3600 ) + sprintf(buf,"%3ldH%02ld", diff / 3600, (diff/60) % 60); + else if (diff > 0) sprintf(buf, "%3ld'%02ld", diff / 60, diff % 60); else buf[0] = '\0'; diff --git a/pttbbs/mbbsd/var.c b/pttbbs/mbbsd/var.c index 6f531c21..866ce063 100644 --- a/pttbbs/mbbsd/var.c +++ b/pttbbs/mbbsd/var.c @@ -1,4 +1,4 @@ -/* $Id: var.c,v 1.2 2002/04/29 07:05:45 in2 Exp $ */ +/* $Id: var.c,v 1.3 2002/05/14 15:08:48 ptt Exp $ */ #include <stdio.h> #include <sys/types.h> #include "config.h" @@ -81,7 +81,6 @@ unsigned int currstat; int currmode = 0; int curredit = 0; int showansi = 1; -int curr_idle_timeout = IDLE_TIMEOUT; time_t login_start_time; userec_t cuser; /* current user structure */ userec_t xuser; /* lookup user structure */ diff --git a/pttbbs/mbbsd/xyz.c b/pttbbs/mbbsd/xyz.c index daa0116e..d880a178 100644 --- a/pttbbs/mbbsd/xyz.c +++ b/pttbbs/mbbsd/xyz.c @@ -1,4 +1,4 @@ -/* $Id: xyz.c,v 1.5 2002/05/13 03:20:04 ptt Exp $ */ +/* $Id: xyz.c,v 1.6 2002/05/14 15:08:48 ptt Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -20,7 +20,6 @@ extern int b_lines; /* Screen bottom line number: t_lines-1 */ extern char *BBSName; extern char fromhost[]; extern userinfo_t *currutmp; -extern int curr_idle_timeout; extern userec_t cuser; extern time_t now; /* 各種統計及相關資訊列表 */ -- cgit v1.2.3 From 048ca383eefeb9aa55cb023b24e63dd2d309c4f3 Mon Sep 17 00:00:00 2001 From: ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Tue, 14 May 2002 15:20:42 +0000 Subject: fix idle timeout git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@169 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/io.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pttbbs/mbbsd/io.c b/pttbbs/mbbsd/io.c index a52b7835..37dc2be1 100644 --- a/pttbbs/mbbsd/io.c +++ b/pttbbs/mbbsd/io.c @@ -1,4 +1,4 @@ -/* $Id: io.c,v 1.13 2002/05/14 15:08:47 ptt Exp $ */ +/* $Id: io.c,v 1.14 2002/05/14 15:20:42 ptt Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -177,7 +177,7 @@ static int dogetch() { now= time(0); if(now-currutmp->lastact<3) anti_robot=now; - else if(!anti_robot || now-anti_robot < IDLE_TIMEOUT) + else if(!anti_robot || now-anti_robot < 5*60) { currutmp->lastact = now; } -- cgit v1.2.3 From 039e068637fdeebf43964f3533260165a5e97446 Mon Sep 17 00:00:00 2001 From: ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Tue, 14 May 2002 16:04:29 +0000 Subject: fix post money git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@170 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/edit.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/pttbbs/mbbsd/edit.c b/pttbbs/mbbsd/edit.c index 9ad0566f..b062c4ec 100644 --- a/pttbbs/mbbsd/edit.c +++ b/pttbbs/mbbsd/edit.c @@ -1,4 +1,4 @@ -/* $Id: edit.c,v 1.8 2002/05/13 03:20:04 ptt Exp $ */ +/* $Id: edit.c,v 1.9 2002/05/14 16:04:29 ptt Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -879,7 +879,6 @@ void addsignature(FILE *fp, int ifuseanony) { static int write_file(char *fpath, int saveheader, int *islocal) { - time_t now; struct tm *ptime; FILE *fp = NULL; textline_t *p, *v; @@ -1555,7 +1554,7 @@ int vedit(char *fpath, int saveheader, int *islocal) { int destuid0 = currutmp->destuid; unsigned int money=0; unsigned short int interval=0; - time_t now=0,th; + time_t th; textline_t* firstline0 = firstline; textline_t* lastline0 = lastline; @@ -1607,8 +1606,8 @@ int vedit(char *fpath, int saveheader, int *islocal) { strcpy(line, currline->data); ch = igetkey(); /* jochang debug */ - if((interval = (unsigned short int)((th = currutmp->lastact) - now))) { - now = th; + if((interval = (unsigned short int)(now - th))) { + th=now; if((char)ch != last) { money++; last = (char)ch; -- cgit v1.2.3 From 50633db27b0d541e148e19ee26a7d3583ec16242 Mon Sep 17 00:00:00 2001 From: ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Tue, 14 May 2002 17:13:45 +0000 Subject: fix idle a bit git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@171 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/edit.c | 8 ++++---- pttbbs/mbbsd/io.c | 20 +++++++++----------- 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/pttbbs/mbbsd/edit.c b/pttbbs/mbbsd/edit.c index b062c4ec..f6a14766 100644 --- a/pttbbs/mbbsd/edit.c +++ b/pttbbs/mbbsd/edit.c @@ -1,4 +1,4 @@ -/* $Id: edit.c,v 1.9 2002/05/14 16:04:29 ptt Exp $ */ +/* $Id: edit.c,v 1.10 2002/05/14 17:13:45 ptt Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -1553,8 +1553,8 @@ int vedit(char *fpath, int saveheader, int *islocal) { int mode0 = currutmp->mode; int destuid0 = currutmp->destuid; unsigned int money=0; - unsigned short int interval=0; - time_t th; + int interval=0; + time_t th=now; textline_t* firstline0 = firstline; textline_t* lastline0 = lastline; @@ -1606,7 +1606,7 @@ int vedit(char *fpath, int saveheader, int *islocal) { strcpy(line, currline->data); ch = igetkey(); /* jochang debug */ - if((interval = (unsigned short int)(now - th))) { + if((interval = (now - th))) { th=now; if((char)ch != last) { money++; diff --git a/pttbbs/mbbsd/io.c b/pttbbs/mbbsd/io.c index 37dc2be1..8e7cd7ae 100644 --- a/pttbbs/mbbsd/io.c +++ b/pttbbs/mbbsd/io.c @@ -1,4 +1,4 @@ -/* $Id: io.c,v 1.14 2002/05/14 15:20:42 ptt Exp $ */ +/* $Id: io.c,v 1.15 2002/05/14 17:13:45 ptt Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -126,7 +126,7 @@ int watermode = -1, wmofo = -1; static int dogetch() { int len; - static time_t anti_robot=0; + static time_t lastact, realact=0; if(ibufsize <= icurrchar) { if(flushf) @@ -175,16 +175,14 @@ static int dogetch() { if(currutmp) { now= time(0); - if(now-currutmp->lastact<3) - anti_robot=now; - else if(!anti_robot || now-anti_robot < 5*60) - { - currutmp->lastact = now; - } + if(!realact || now-lastact < 3) + realact=now; + + if(now-realact<5*60) + currutmp->lastact=now; else - { - currutmp->lastact = anti_robot; - } + currutmp->lastact=realact; + lastact=now; } return inbuf[icurrchar++]; } -- cgit v1.2.3 From b1605266b1310329f841e41bfe3464b0d95e367f Mon Sep 17 00:00:00 2001 From: ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Wed, 15 May 2002 08:24:39 +0000 Subject: add over 24hr idle git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@172 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/talk.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/pttbbs/mbbsd/talk.c b/pttbbs/mbbsd/talk.c index 70fb4fd8..4d44182f 100644 --- a/pttbbs/mbbsd/talk.c +++ b/pttbbs/mbbsd/talk.c @@ -1,4 +1,4 @@ -/* $Id: talk.c,v 1.34 2002/05/14 15:08:48 ptt Exp $ */ +/* $Id: talk.c,v 1.35 2002/05/15 08:24:39 ptt Exp $ */ #include <stdio.h> #include <string.h> #include <errno.h> @@ -1709,8 +1709,10 @@ static void pickup_user(void) //diff = pklist[ch].idle; // if (diff > 1800) diff = 1800; /* Doma: 以免一大串的發呆時間 */ // in2: max 30'00 :P Ptt:真實沒關係 - if (diff > 3600 ) - sprintf(buf,"%3ldH%02ld", diff / 3600, (diff/60) % 60); + if (diff > 3600*24) + strcpy(buf," -----"); + else if (diff > 3600 ) + sprintf(buf,"%3ldh%02ld", diff / 3600, (diff/60) % 60); else if (diff > 0) sprintf(buf, "%3ld'%02ld", diff / 60, diff % 60); else -- cgit v1.2.3 From 1131c45537a2180082812e9d14abf8b0c5b1642f Mon Sep 17 00:00:00 2001 From: ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Wed, 15 May 2002 08:55:30 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@173 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/io.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/pttbbs/mbbsd/io.c b/pttbbs/mbbsd/io.c index 8e7cd7ae..f553db74 100644 --- a/pttbbs/mbbsd/io.c +++ b/pttbbs/mbbsd/io.c @@ -1,4 +1,4 @@ -/* $Id: io.c,v 1.15 2002/05/14 17:13:45 ptt Exp $ */ +/* $Id: io.c,v 1.16 2002/05/15 08:55:30 ptt Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -126,7 +126,7 @@ int watermode = -1, wmofo = -1; static int dogetch() { int len; - static time_t lastact, realact=0; + static time_t lastact; if(ibufsize <= icurrchar) { if(flushf) @@ -175,13 +175,8 @@ static int dogetch() { if(currutmp) { now= time(0); - if(!realact || now-lastact < 3) - realact=now; - - if(now-realact<5*60) + if(now-lastact < 3) currutmp->lastact=now; - else - currutmp->lastact=realact; lastact=now; } return inbuf[icurrchar++]; -- cgit v1.2.3 From 3a6d49d30d78dcab4a3cda32617e0c5b7cb3343c Mon Sep 17 00:00:00 2001 From: ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Wed, 15 May 2002 09:14:24 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@174 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/osdep.c | 63 ++++++++++++++++++++++++++-------------------------- 1 file changed, 32 insertions(+), 31 deletions(-) diff --git a/pttbbs/mbbsd/osdep.c b/pttbbs/mbbsd/osdep.c index 967a4db0..5f99da22 100644 --- a/pttbbs/mbbsd/osdep.c +++ b/pttbbs/mbbsd/osdep.c @@ -1,20 +1,19 @@ -/* $Id: osdep.c,v 1.1 2002/03/07 15:13:48 in2 Exp $ */ +/* $Id: osdep.c,v 1.2 2002/05/15 09:14:24 ptt Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> #include <fcntl.h> #include <unistd.h> -#if defined(linux) +#if __FreeBSD__ + +#include <kvm.h> + int cpuload(char *str) { double l[3] = {-1, -1, -1}; - FILE *fp; + if(getloadavg(l, 3) != 3) + l[0] = -1; - if((fp = fopen("/proc/loadavg", "r"))) { - if(fscanf(fp, "%lf %lf %lf", &l[0], &l[1], &l[2]) != 3) - l[0] = -1; - fclose(fp); - } if(str) { if(l[0] != -1) sprintf(str, " %.2f %.2f %.2f", l[0], l[1], l[2]); @@ -26,28 +25,34 @@ int cpuload(char *str) { double swapused(long *total, long *used) { double percent = -1; - char buf[101]; - FILE *fp; + kvm_t *kd; + struct kvm_swap swapinfo; + int pagesize; - if((fp = fopen("/proc/meminfo","r"))) { - while(fgets(buf, 100, fp) && buf[0] != 'S'); - if(sscanf(buf + 6, "%ld %ld", total, used) == 2) + kd = kvm_open(NULL, NULL, NULL, O_RDONLY, NULL); + if(kd) { + if(kvm_getswapinfo(kd, &swapinfo, 1, 0) == 0) { + pagesize = getpagesize(); + *total = swapinfo.ksw_total * pagesize; + *used = swapinfo.ksw_used * pagesize; if(*total != 0) percent = (double)*used / (double)*total; - fclose(fp); + } + kvm_close(kd); } return percent; } -#elif __FreeBSD__ >=4 - -#include <kvm.h> - +#else int cpuload(char *str) { double l[3] = {-1, -1, -1}; - if(getloadavg(l, 3) != 3) - l[0] = -1; + FILE *fp; + if((fp = fopen("/proc/loadavg", "r"))) { + if(fscanf(fp, "%lf %lf %lf", &l[0], &l[1], &l[2]) != 3) + l[0] = -1; + fclose(fp); + } if(str) { if(l[0] != -1) sprintf(str, " %.2f %.2f %.2f", l[0], l[1], l[2]); @@ -59,21 +64,17 @@ int cpuload(char *str) { double swapused(long *total, long *used) { double percent = -1; - kvm_t *kd; - struct kvm_swap swapinfo; - int pagesize; + char buf[101]; + FILE *fp; - kd = kvm_open(NULL, NULL, NULL, O_RDONLY, NULL); - if(kd) { - if(kvm_getswapinfo(kd, &swapinfo, 1, 0) == 0) { - pagesize = getpagesize(); - *total = swapinfo.ksw_total * pagesize; - *used = swapinfo.ksw_used * pagesize; + if((fp = fopen("/proc/meminfo","r"))) { + while(fgets(buf, 100, fp) && buf[0] != 'S'); + if(sscanf(buf + 6, "%ld %ld", total, used) == 2) if(*total != 0) percent = (double)*used / (double)*total; - } - kvm_close(kd); + fclose(fp); } return percent; } + #endif -- cgit v1.2.3 From 7aa929057c89ffb415ab1cff9a8bee95e554aad2 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Wed, 15 May 2002 11:16:33 +0000 Subject: idle time use searchuser to search if user exists git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@175 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/shmctl.c | 51 ++++++++++++++++++++++++++++++--------------------- 1 file changed, 30 insertions(+), 21 deletions(-) diff --git a/pttbbs/util/shmctl.c b/pttbbs/util/shmctl.c index d6818344..970919bc 100644 --- a/pttbbs/util/shmctl.c +++ b/pttbbs/util/shmctl.c @@ -23,15 +23,19 @@ int logout_friend_online(userinfo_t *utmp) while(utmp->friendtotal){ i = utmp->friendtotal-1; j = (utmp->friend_online[i] & 0xFFFFFF); - utmp->friend_online[i]=0; - ui = &utmpshm->uinfo[j]; - if(ui->pid && ui!=utmp){ - for(k=0; k<ui->friendtotal && - (int)(ui->friend_online[k] & 0xFFFFFF) !=offset; k++); - if(k<ui->friendtotal){ - ui->friendtotal--; - ui->friend_online[k]=ui->friend_online[ui->friendtotal]; - ui->friend_online[ui->friendtotal]=0; + if( !(0 <= j && j < MAX_ACTIVE) ) + printf("\tonline friend error(%d)\n", j); + else{ + utmp->friend_online[i]=0; + ui = &utmpshm->uinfo[j]; + if(ui->pid && ui!=utmp){ + for(k=0; k<ui->friendtotal && + (int)(ui->friend_online[k] & 0xFFFFFF) !=offset; k++); + if(k<ui->friendtotal){ + ui->friendtotal--; + ui->friend_online[k]=ui->friend_online[ui->friendtotal]; + ui->friend_online[ui->friendtotal]=0; + } } } utmp->friendtotal--; @@ -48,9 +52,12 @@ void purge_utmp(userinfo_t *uentp) int utmpfix(int argc, char **argv) { - int i; + int i, fast = 0; time_t now; - char buf[1024], *clean; + char *clean; + + if( argc >= 1 && strcmp(argv[0], "-n") == 0 ) + fast = 1; time(&now); for( i = 0 ; i < 5 ; ++i ) @@ -60,23 +67,25 @@ int utmpfix(int argc, char **argv) puts("utmpshm is busy...."); sleep(1); } + printf("starting scaning... %s \n", (fast ? "(fast mode)" : "")); utmpshm->busystate = 1; for( i = 0 ; i < USHM_SIZE ; ++i ) if( utmpshm->uinfo[i].pid ){ clean = NULL; if( !isalpha(utmpshm->uinfo[i].userid[0]) ) clean = "userid error"; - else if( now - utmpshm->uinfo[i].lastact > 1800 ){ - clean = "timeout"; - kill(utmpshm->uinfo[i].pid, SIGHUP); - purge_utmp(&utmpshm->uinfo[i]); - } - else{ - sprintf(buf, "home/%c/%s", - utmpshm->uinfo[i].userid[0], - utmpshm->uinfo[i].userid); - if( access(buf, 0) < 0 ) + else if( !fast ){ +#ifdef DOTIMEOUT + if( now - utmpshm->uinfo[i].lastact > IDLE_TIMEOUT ){ + clean = "timeout"; + kill(utmpshm->uinfo[i].pid, SIGHUP); + purge_utmp(&utmpshm->uinfo[i]); + } + else +#endif + if( searchuser(utmpshm->uinfo[i].userid) == 0 ){ clean = "user not exist"; + } } if( clean ){ -- cgit v1.2.3 From d69adf1504ff8d39c1b22d14b3b2a80ec507b6ba Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Wed, 15 May 2002 11:26:41 +0000 Subject: long idle timeout git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@176 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/include/config.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pttbbs/include/config.h b/pttbbs/include/config.h index eb1ea28f..b82d4f48 100644 --- a/pttbbs/include/config.h +++ b/pttbbs/include/config.h @@ -1,4 +1,4 @@ -/* $Id: config.h,v 1.2 2002/03/24 18:32:52 in2 Exp $ */ +/* $Id: config.h,v 1.3 2002/05/15 11:26:41 in2 Exp $ */ #ifndef INCLUDE_CONFIG_H #define INCLUDE_CONFIG_H @@ -157,7 +157,7 @@ #define DOTIMEOUT #ifdef DOTIMEOUT -#define IDLE_TIMEOUT (30*60) /* 一般情況之 timeout */ +#define IDLE_TIMEOUT (43200) /* 一般情況之 timeout (12hr) */ #define MONITOR_TIMEOUT (20*60) /* monitor 時之 timeout */ #define SHOW_IDLE_TIME /* 顯示閒置時間 */ #endif -- cgit v1.2.3 From 74f0a03f9470a0db760ace67cb4157a24042cb8b Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Thu, 16 May 2002 02:30:30 +0000 Subject: show timeout time git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@177 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/shmctl.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/pttbbs/util/shmctl.c b/pttbbs/util/shmctl.c index 970919bc..738926b9 100644 --- a/pttbbs/util/shmctl.c +++ b/pttbbs/util/shmctl.c @@ -54,7 +54,7 @@ int utmpfix(int argc, char **argv) { int i, fast = 0; time_t now; - char *clean; + char *clean, buf[1024]; if( argc >= 1 && strcmp(argv[0], "-n") == 0 ) fast = 1; @@ -77,7 +77,10 @@ int utmpfix(int argc, char **argv) else if( !fast ){ #ifdef DOTIMEOUT if( now - utmpshm->uinfo[i].lastact > IDLE_TIMEOUT ){ - clean = "timeout"; + sprintf(buf, "timeout(%s", + ctime(&utmpshm->uinfo[i].lastact)); + buf[strlen(buf) - 1] = 0; + strcat(buf, ")"); kill(utmpshm->uinfo[i].pid, SIGHUP); purge_utmp(&utmpshm->uinfo[i]); } -- cgit v1.2.3 From 91440ed867b2b0aa521f54d4600fc536a4f8d96c Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Thu, 16 May 2002 06:00:01 +0000 Subject: simple regcode git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@178 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/user.c | 44 ++++++++++++++++++++++++-------------------- 1 file changed, 24 insertions(+), 20 deletions(-) diff --git a/pttbbs/mbbsd/user.c b/pttbbs/mbbsd/user.c index 9f5d7245..8fea34ab 100644 --- a/pttbbs/mbbsd/user.c +++ b/pttbbs/mbbsd/user.c @@ -1,4 +1,4 @@ -/* $Id: user.c,v 1.16 2002/05/13 03:20:04 ptt Exp $ */ +/* $Id: user.c,v 1.17 2002/05/16 06:00:01 in2 Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -774,10 +774,7 @@ static int ispersonalid(char *inid) static char *getregcode(char *buf) { - sprintf(buf, "%s%s%s", - crypt(cuser.email, "PT"), - crypt(cuser.address, "2x"), - crypt(cuser.realname, "02")); + sprintf(buf, "%s", crypt(cuser.userid, "02")); return buf; } @@ -826,23 +823,29 @@ static void toregister(char *email, char *genbuf, char *phone, char *career, stand_title("認證設定"); move(2, 0); outs("您好, 本站採兩種方式認證:\n" - " 1.您若有 E-Mail , 可以透過 E-Mail 進行認證\n" - " 請輸入您的 E-Mail , 您會收到我們寄出含有認證碼的信件\n" - " 之後請到 (U)ser => (R)egister 輸入, 即可通過認證\n" + " 1.若您有 E-Mail (本站不接受 yahoo, kimo等免費的 E-Mail)\n" + " 請輸入您的 E-Mail , 我們會寄發含有認證碼的信件給您\n" + " 收到後請到 (U)ser => (R)egister 輸入認證碼, 即可通過認證\n" "\n" - " 2.您若沒有 E-Mail , 請輸入 x ,\n" + " 2.若您沒有 E-Mail , 請輸入 x ,\n" " 我們會由站長親自審核您的註冊資料\n" - "\n" - "**********************************************************\n" - "* 您應該會在完成後十分鐘內收到認證信函, 若過久未收到或認 *\n" - "* 證碼錯誤請麻煩重新填寫一次或改用手動認證 :) *\n" - "**********************************************************\n"); + "************************************************************\n" + "* 注意! *\n" + "* 您應該會在輸入完成後十分鐘內收到認證信, 若過久未收到, *\n" + "* 或輸入後發生認證碼錯誤, 麻煩重填一次 E-Mail 或改手動認證 *\n" + "************************************************************\n"); while( 1 ){ email[0] = 0; getfield(15, "身分認證用", "E-Mail Address", email, 50); - if( strcmp(email, "x") == 0 || strcmp(email, "X") == 0 || - isvaildemail(email) ) + if( strcmp(email, "x") == 0 || strcmp(email, "X") == 0 ) break; + else if( isvaildemail(email) ){ + char yn[3]; + getdata(16, 0, "請再次確認您輸入的 E-Mail 位置正確嘛? [y/N]", + yn, sizeof(yn), LCECHO); + if( yn[0] == 'Y' || yn[0] == 'y' ) + break; + } else{ move(17, 0); prints("指定的 E-Mail 不合法," @@ -872,12 +875,12 @@ static void toregister(char *email, char *genbuf, char *phone, char *career, strncpy(cuser.justify, genbuf, REGLEN); sethomefile(buf, cuser.userid, "justify"); } + sprintf(buf, "您在 "BBSNAME" 的認證碼: %s", getregcode(genbuf)); strcpy(tmp, cuser.userid); strcpy(cuser.userid, "SYSOP"); - sprintf(buf, "您在 "BBSNAME" 的認證碼: %s", getregcode(genbuf)); bsmtp("etc/registermail", buf, email, 0); strcpy(cuser.userid, tmp); - outs("\n\n\n我們即將寄出認證信 (可能要麻煩您等兩三分鐘)\n" + outs("\n\n\n我們即將寄出認證信 (您應該會在 10 分鐘內收到)\n" "收到後您可以跟據認證信標題的認證碼\n" "輸入到 (U)ser -> (R)egister 後就可以完成註冊"); pressanykey(); @@ -937,10 +940,11 @@ int u_register(void) clear(); stand_title("EMail認證"); move(2, 0); - prints("%s(%s) 您好,請輸入您的認證碼或輸入 x重填 E-Mail ", + prints("%s(%s) 您好,請輸入您的認證碼。\n" + "或您可以輸入 x來重新填寫 E-Mail 或改由站長手動認證", cuser.userid, cuser.username); inregcode[0] = 0; - getdata(10, 0, "您的認證碼: ", inregcode, sizeof(inregcode), DOECHO); + getdata(10, 0, "您的輸入: ", inregcode, sizeof(inregcode), DOECHO); if( strcmp(inregcode, getregcode(regcode)) == 0 ){ int unum; if( (unum = getuser(cuser.userid)) == 0 ){ -- cgit v1.2.3 From 3d437154f248c4ceb0f95642a8c2db6629772e6a Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Thu, 16 May 2002 21:51:23 +0000 Subject: fix regcode length git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@179 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/user.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pttbbs/mbbsd/user.c b/pttbbs/mbbsd/user.c index 8fea34ab..faa50d43 100644 --- a/pttbbs/mbbsd/user.c +++ b/pttbbs/mbbsd/user.c @@ -1,4 +1,4 @@ -/* $Id: user.c,v 1.17 2002/05/16 06:00:01 in2 Exp $ */ +/* $Id: user.c,v 1.18 2002/05/16 21:51:23 in2 Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -892,7 +892,7 @@ int u_register(void) { char rname[21], addr[51], ident[12], mobile[21]; char phone[21], career[41], email[51],birthday[9],sex_is[2],year,mon,day; - char inregcode[50], regcode[50]; + char inregcode[14], regcode[50]; char ans[3], *ptr; char genbuf[200]; FILE *fn; -- cgit v1.2.3 From 83716f167c437e0b2371b0824b57cb2a9b28a7b2 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Thu, 16 May 2002 21:54:56 +0000 Subject: no warning git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@180 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/admin.c | 4 ++-- pttbbs/mbbsd/bbs.c | 5 +++-- pttbbs/mbbsd/mail.c | 6 +++--- pttbbs/mbbsd/talk.c | 4 ++-- 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/pttbbs/mbbsd/admin.c b/pttbbs/mbbsd/admin.c index f97a3603..e7c51f3f 100644 --- a/pttbbs/mbbsd/admin.c +++ b/pttbbs/mbbsd/admin.c @@ -1,4 +1,4 @@ -/* $Id: admin.c,v 1.11 2002/05/13 03:20:04 ptt Exp $ */ +/* $Id: admin.c,v 1.12 2002/05/16 21:54:56 in2 Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -744,7 +744,7 @@ int scan_register_form(char *regfile, int automode, int neednum) { char fdata[7][STRLEN]; char fname[STRLEN], buf[STRLEN]; char ans[4], *ptr, *uid; - int n, unum; + int n = 0, unum = 0; int nSelf = 0, nAuto = 0; uid = cuser.userid; diff --git a/pttbbs/mbbsd/bbs.c b/pttbbs/mbbsd/bbs.c index d4367447..602e3bb4 100644 --- a/pttbbs/mbbsd/bbs.c +++ b/pttbbs/mbbsd/bbs.c @@ -1,4 +1,4 @@ -/* $Id: bbs.c,v 1.9 2002/05/13 03:20:04 ptt Exp $ */ +/* $Id: bbs.c,v 1.10 2002/05/16 21:54:56 in2 Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -15,11 +15,12 @@ #include "proto.h" extern struct bcache_t *brdshm; +/* static int g_board_names(boardheader_t *fhdr) { AddNameList(fhdr->brdname); return 0; } - +*/ extern userec_t cuser; extern void touchdircache(int bid); extern int TagNum; diff --git a/pttbbs/mbbsd/mail.c b/pttbbs/mbbsd/mail.c index 35b6a000..21871d5c 100644 --- a/pttbbs/mbbsd/mail.c +++ b/pttbbs/mbbsd/mail.c @@ -1,4 +1,4 @@ -/* $Id: mail.c,v 1.7 2002/05/13 03:20:04 ptt Exp $ */ +/* $Id: mail.c,v 1.8 2002/05/16 21:54:56 in2 Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -1309,13 +1309,13 @@ static int mail_waterball(int ent, fileheader_t *fhdr, char *direct) cmode = (fname[0] != '0' && fname[0] != '1') ? 1 : fname[0] - '0'; sprintf(fname, BBSHOME "/jobspool/water.src.%s-%d", - cuser.userid, now); + cuser.userid, (int)now); sprintf(genbuf, "cp " BBSHOME "/home/%c/%s/%s %s", cuser.userid[0], cuser.userid, fhdr->filename, fname); system(genbuf); /* dirty code ;x */ sprintf(fname, BBSHOME "/jobspool/water.des.%s-%d", - cuser.userid, now); + cuser.userid, (int)now); fp = fopen(fname, "wt"); fprintf(fp, "%s\n%s\n%d\n", cuser.userid, address, cmode); fclose(fp); diff --git a/pttbbs/mbbsd/talk.c b/pttbbs/mbbsd/talk.c index 4d44182f..6f63350c 100644 --- a/pttbbs/mbbsd/talk.c +++ b/pttbbs/mbbsd/talk.c @@ -1,4 +1,4 @@ -/* $Id: talk.c,v 1.35 2002/05/15 08:24:39 ptt Exp $ */ +/* $Id: talk.c,v 1.36 2002/05/16 21:54:56 in2 Exp $ */ #include <stdio.h> #include <string.h> #include <errno.h> @@ -1581,7 +1581,7 @@ static void pickup_user(void) int fri_stat, bfriends_number, ifh_number, irh_number, hfm_number; int savemode = currstat; int i, sortedway; /* 只是loop有用到 */ - time_t diff, freshtime; + time_t diff, freshtime = 0; pickup_t pklist[USHM_SIZE]; /* parameter Ptt註 */ /* num : 現在的游標位 */ /* foot: 此頁的腳腳 */ -- cgit v1.2.3 From b863e32271879333e956340a4d8855f4d8690fa2 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Fri, 17 May 2002 14:27:20 +0000 Subject: getopt() timeout git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@181 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/shmctl.c | 40 ++++++++++++++++++++++++++++------------ 1 file changed, 28 insertions(+), 12 deletions(-) diff --git a/pttbbs/util/shmctl.c b/pttbbs/util/shmctl.c index 738926b9..17b9dc42 100644 --- a/pttbbs/util/shmctl.c +++ b/pttbbs/util/shmctl.c @@ -53,11 +53,21 @@ void purge_utmp(userinfo_t *uentp) int utmpfix(int argc, char **argv) { int i, fast = 0; - time_t now; - char *clean, buf[1024]; + time_t now, timeout = -1; + char *clean, buf[1024], ch; - if( argc >= 1 && strcmp(argv[0], "-n") == 0 ) - fast = 1; + while( (ch = getopt(argc, argv, "nt:")) != -1 ) + switch( ch ){ + case 'n': + fast = 1; + break; + case 't': + timeout = atoi(optarg); + break; + default: + printf("usage:\tshmctl\tutmpfix[-n] [-t timeout]\n"); + return 1; + } time(&now); for( i = 0 ; i < 5 ; ++i ) @@ -74,21 +84,27 @@ int utmpfix(int argc, char **argv) clean = NULL; if( !isalpha(utmpshm->uinfo[i].userid[0]) ) clean = "userid error"; + else if( kill(utmpshm->uinfo[i].pid, 0) < 0 ){ + clean = "process error"; + purge_utmp(&utmpshm->uinfo[i]); + } else if( !fast ){ #ifdef DOTIMEOUT - if( now - utmpshm->uinfo[i].lastact > IDLE_TIMEOUT ){ + if( now - utmpshm->uinfo[i].lastact > + (timeout == -1 ? IDLE_TIMEOUT : timeout) ){ sprintf(buf, "timeout(%s", ctime(&utmpshm->uinfo[i].lastact)); buf[strlen(buf) - 1] = 0; strcat(buf, ")"); + clean = buf; kill(utmpshm->uinfo[i].pid, SIGHUP); purge_utmp(&utmpshm->uinfo[i]); } else #endif - if( searchuser(utmpshm->uinfo[i].userid) == 0 ){ - clean = "user not exist"; - } + if( searchuser(utmpshm->uinfo[i].userid) == 0 ){ + clean = "user not exist"; + } } if( clean ){ @@ -264,15 +280,15 @@ int showglobe(int argc, char **argv) int setglobe(int argc, char **argv) { int where; - if( argc != 2 ) + if( argc != 3 ) return 1; - where = atoi(argv[0]); + where = atoi(argv[1]); if( !(0 <= where && where <= 9) ){ puts("only GLOBE[0] ~ GLOBE[9]"); return 1; } printf("GLOBE[%d] = %d -> ", where, ptt->GLOBE[where]); - printf("%d\n", ptt->GLOBE[where] = atoi(argv[1])); + printf("%d\n", ptt->GLOBE[where] = atoi(argv[2])); return 0; } @@ -309,7 +325,7 @@ int main(int argc, char **argv) resolve_fcache(); for( i = 0 ; cmd[i].func != NULL ; ++i ) if( strcmp(cmd[i].cmd, argv[1]) == 0 ){ - return cmd[i].func(argc - 2, &argv[2]); + return cmd[i].func(argc - 1, &argv[1]); } } if( argc == 1 || cmd[i].func == NULL ){ -- cgit v1.2.3 From d21859701888367968b41aa0faf3d3115bd46445 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sat, 18 May 2002 13:23:39 +0000 Subject: random sleep when logouting git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@182 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/mbbsd.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/pttbbs/mbbsd/mbbsd.c b/pttbbs/mbbsd/mbbsd.c index 8ea6f8d1..078245f4 100644 --- a/pttbbs/mbbsd/mbbsd.c +++ b/pttbbs/mbbsd/mbbsd.c @@ -1,4 +1,4 @@ -/* $Id: mbbsd.c,v 1.27 2002/05/14 15:08:48 ptt Exp $ */ +/* $Id: mbbsd.c,v 1.28 2002/05/18 13:23:39 in2 Exp $ */ #include <stdio.h> #include <string.h> #include <stdlib.h> @@ -203,7 +203,14 @@ u_exit (char *mode) { //userec_t xuser; int diff = (time (0) - login_start_time) / 60; - + + /* close fd 0 & a to terminate network */ + close(0); + close(1); + + /* random sleep to avoid MANY users logout at the same time */ + usleep((int)((float)rand() * 10000000 / RAND_MAX)); + reload_money(); auto_backup (); save_brdbuf(); -- cgit v1.2.3 From e6b5badd28075cc650e934901b87257962031321 Mon Sep 17 00:00:00 2001 From: lwms <lwms@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Mon, 20 May 2002 15:41:37 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@183 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/include/proto.h | 3 ++- pttbbs/mbbsd/syspost.c | 27 ++++++++++++++++++++++++++- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/pttbbs/include/proto.h b/pttbbs/include/proto.h index 66267a52..743575f8 100644 --- a/pttbbs/include/proto.h +++ b/pttbbs/include/proto.h @@ -1,4 +1,4 @@ -/* $Id: proto.h,v 1.14 2002/05/11 16:42:43 in2 Exp $ */ +/* $Id: proto.h,v 1.15 2002/05/20 15:38:23 lwms Exp $ */ #ifndef INCLUDE_PROTO_H #define INCLUDE_PROTO_H @@ -422,6 +422,7 @@ int is_uBM(char *list, char *id); void post_newboard(char *bgroup, char *bname, char *bms); void post_violatelaw(char *crime, char *police, char *reason, char *result); void post_change_perm(int oldperm, int newperm, char *sysopid, char *userid); +void give_money_post(char *userid, int money); /* talk */ int cmpwatermtime(const void *a, const void *b); diff --git a/pttbbs/mbbsd/syspost.c b/pttbbs/mbbsd/syspost.c index 6145be26..654d6c35 100644 --- a/pttbbs/mbbsd/syspost.c +++ b/pttbbs/mbbsd/syspost.c @@ -1,4 +1,4 @@ -/* $Id: syspost.c,v 1.6 2002/05/13 03:20:04 ptt Exp $ */ +/* $Id: syspost.c,v 1.7 2002/05/20 15:41:37 lwms Exp $ */ #include <stdio.h> #include <string.h> #include <time.h> @@ -97,3 +97,28 @@ void post_newboard(char* bgroup, char* bname, char* bms){ post_msg("Record", title, genbuf, "[系統]"); } +void give_money_post(char *userid, int money) { + FILE *fp; + fileheader_t fhdr; + time_t now = time(0); + char genbuf[200], reason[30]; + int i, flag=0; + + strcpy(genbuf, "boards/S/Security"); + stampfile(genbuf, &fhdr); + if(!(fp = fopen(genbuf,"w"))) + return; + fprintf(fp, "作者: [系統安全局] 看板: Security\n" + "標題: [公安報告] 站長%s使用紅包機報告\n" + "時間: %s\n", cuser.userid, ctime(&now)); + clrtobot(); + clear(); + fprintf(fp, "\n 站長\033[1;32m%s\033[m給\033[1;33m%s %d 元\033[m", + cuser.userid, userid, money); + + fclose(fp); + sprintf(fhdr.title, "[公安報告] 站長%s使用紅包機報告", + cuser.userid); + strcpy(fhdr.owner, "[系統安全局]"); + append_record("boards/S/Security/.DIR", &fhdr, sizeof(fhdr)); +} -- cgit v1.2.3 From ef8c695f171a8d38e4c3558c3b04fb029cadffb6 Mon Sep 17 00:00:00 2001 From: lwms <lwms@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Tue, 21 May 2002 05:01:33 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@184 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/admin.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/pttbbs/mbbsd/admin.c b/pttbbs/mbbsd/admin.c index e7c51f3f..a076c10f 100644 --- a/pttbbs/mbbsd/admin.c +++ b/pttbbs/mbbsd/admin.c @@ -1,4 +1,4 @@ -/* $Id: admin.c,v 1.12 2002/05/16 21:54:56 in2 Exp $ */ +/* $Id: admin.c,v 1.13 2002/05/21 05:01:33 lwms Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -1093,19 +1093,21 @@ int give_money() { id = uhash->userid[i]; give_id_money(id, money, fp2, tt, now); } + give_money_post("全站使用者", atoi(mn) ); } else { if(!(fp = fopen("etc/givemoney.txt", "r+"))) { fclose(fp2); return 1; } while(fgets(buf, 255, fp)) { -// clear(); + clear(); if (!(ptr = strchr(buf, ':'))) continue; *ptr = '\0'; id = buf; mn = ptr + 1; - give_id_money(id, atoi(mn), fp2, tt, now); + give_id_money(id, atoi(mn), fp2, tt, t); + give_money_post(id, atoi(mn) ); } fclose(fp); } -- cgit v1.2.3 From 4ca009fb12c6217e2044dc7308febd02a065369e Mon Sep 17 00:00:00 2001 From: lwms <lwms@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Tue, 21 May 2002 05:08:44 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@185 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/admin.c | 4 ++-- pttbbs/mbbsd/syspost.c | 3 +-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/pttbbs/mbbsd/admin.c b/pttbbs/mbbsd/admin.c index a076c10f..8397234d 100644 --- a/pttbbs/mbbsd/admin.c +++ b/pttbbs/mbbsd/admin.c @@ -1,4 +1,4 @@ -/* $Id: admin.c,v 1.13 2002/05/21 05:01:33 lwms Exp $ */ +/* $Id: admin.c,v 1.14 2002/05/21 05:04:14 lwms Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -1106,7 +1106,7 @@ int give_money() { *ptr = '\0'; id = buf; mn = ptr + 1; - give_id_money(id, atoi(mn), fp2, tt, t); + give_id_money(id, atoi(mn), fp2, tt, now); give_money_post(id, atoi(mn) ); } fclose(fp); diff --git a/pttbbs/mbbsd/syspost.c b/pttbbs/mbbsd/syspost.c index 654d6c35..8a30abff 100644 --- a/pttbbs/mbbsd/syspost.c +++ b/pttbbs/mbbsd/syspost.c @@ -1,4 +1,4 @@ -/* $Id: syspost.c,v 1.7 2002/05/20 15:41:37 lwms Exp $ */ +/* $Id: syspost.c,v 1.8 2002/05/21 05:08:44 lwms Exp $ */ #include <stdio.h> #include <string.h> #include <time.h> @@ -102,7 +102,6 @@ void give_money_post(char *userid, int money) { fileheader_t fhdr; time_t now = time(0); char genbuf[200], reason[30]; - int i, flag=0; strcpy(genbuf, "boards/S/Security"); stampfile(genbuf, &fhdr); -- cgit v1.2.3 From cc0d81185cd84a0e7ea9345e4e66a15c7feaa1cc Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Wed, 22 May 2002 15:18:09 +0000 Subject: avoid infinite loop git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@186 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/talk.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pttbbs/mbbsd/talk.c b/pttbbs/mbbsd/talk.c index 6f63350c..31b72ff7 100644 --- a/pttbbs/mbbsd/talk.c +++ b/pttbbs/mbbsd/talk.c @@ -1,4 +1,4 @@ -/* $Id: talk.c,v 1.36 2002/05/16 21:54:56 in2 Exp $ */ +/* $Id: talk.c,v 1.37 2002/05/22 15:18:09 in2 Exp $ */ #include <stdio.h> #include <string.h> #include <errno.h> @@ -259,13 +259,13 @@ int logout_friend_online(userinfo_t *utmp) int i, j, k; int offset=(int) (utmp - &utmpshm->uinfo[0]); userinfo_t *ui; - while(utmp->friendtotal){ + while( utmp->friendtotal > 0 ){ i = utmp->friendtotal-1; j = (utmp->friend_online[i] & 0xFFFFFF); utmp->friend_online[i]=0; ui = &utmpshm->uinfo[j]; if(ui->pid && ui!=utmp){ - for(k=0; k<ui->friendtotal && k < MAX_FRIEND && + for(k=0; k<ui->friendtotal > 0 && k < MAX_FRIEND && (int)(ui->friend_online[k] & 0xFFFFFF) !=offset; k++); if(k<ui->friendtotal){ ui->friendtotal--; @@ -289,7 +289,7 @@ int friend_stat(userinfo_t *me, userinfo_t * ui) } for(i=0;me->friend_online[i] && i < MAX_FRIEND;i++){ j = (me->friend_online[i] & 0xFFFFFF); - if(ui == &utmpshm->uinfo[j]){ + if( 0 <= j && j < MAX_ACTIVE && ui == &utmpshm->uinfo[j] ){ hit |= me->friend_online[i] >>24; break; } -- cgit v1.2.3 From 85f1bc730182a26ce8ee403923067818e0d21916 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Wed, 22 May 2002 15:42:26 +0000 Subject: avoid search_ulistn from -1 when there's nobody online git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@187 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/cache.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pttbbs/mbbsd/cache.c b/pttbbs/mbbsd/cache.c index ec85a4db..9f3dab99 100644 --- a/pttbbs/mbbsd/cache.c +++ b/pttbbs/mbbsd/cache.c @@ -1,4 +1,4 @@ -/* $Id: cache.c,v 1.25 2002/05/13 10:00:17 ptt Exp $ */ +/* $Id: cache.c,v 1.26 2002/05/22 15:42:26 in2 Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -463,6 +463,8 @@ extern int usernum; userinfo_t *search_ulist_pid(int pid) { register int i=0, j, start = 0, end = utmpshm->number - 1; register userinfo_t **ulist; + if( end == -1 ) + return NULL; ulist=utmpshm->sorted[utmpshm->currsorted][7]; for(i=((start+end)/2); ;i=(start+end)/2) { -- cgit v1.2.3 From 62dc9d91aaafd6ba3416ca2bedaffafad9caec6d Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Wed, 22 May 2002 15:46:33 +0000 Subject: show pid at Welcome screen when DEBUG git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@188 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/mbbsd.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pttbbs/mbbsd/mbbsd.c b/pttbbs/mbbsd/mbbsd.c index 078245f4..11d90989 100644 --- a/pttbbs/mbbsd/mbbsd.c +++ b/pttbbs/mbbsd/mbbsd.c @@ -1,4 +1,4 @@ -/* $Id: mbbsd.c,v 1.28 2002/05/18 13:23:39 in2 Exp $ */ +/* $Id: mbbsd.c,v 1.29 2002/05/22 15:46:33 in2 Exp $ */ #include <stdio.h> #include <string.h> #include <stdlib.h> @@ -602,6 +602,10 @@ login_query () pressanykey (); exit (1); } +#ifdef DEBUG + move(19, 0); + prints("current pid: %d ", getpid()); +#endif getdata (20, 0, "請輸入代號,或以[guest]參觀,以[new]註冊:", uid, sizeof(uid), DOECHO); if (strcasecmp (uid, str_new) == 0){ -- cgit v1.2.3 From f8a169057615f83338b97b4991f3d3708b154bed Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Wed, 22 May 2002 15:59:07 +0000 Subject: avoid search_ulistn from -1 when there's nobody online git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@189 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/cache.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pttbbs/mbbsd/cache.c b/pttbbs/mbbsd/cache.c index 9f3dab99..e672ee56 100644 --- a/pttbbs/mbbsd/cache.c +++ b/pttbbs/mbbsd/cache.c @@ -1,4 +1,4 @@ -/* $Id: cache.c,v 1.26 2002/05/22 15:42:26 in2 Exp $ */ +/* $Id: cache.c,v 1.27 2002/05/22 15:59:07 in2 Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -490,6 +490,8 @@ userinfo_t *search_ulist_pid(int pid) { userinfo_t *search_ulistn(int uid, int unum) { register int i=0, j, start = 0, end = utmpshm->number - 1; register userinfo_t **ulist; + if( end == -1 ) + return NULL; ulist=utmpshm->sorted[utmpshm->currsorted][6]; for(i=((start+end)/2); ;i=(start+end)/2) { @@ -519,6 +521,8 @@ userinfo_t *search_ulistn(int uid, int unum) { int count_logins(int uid, int show) { register int i=0, j, start = 0, end = utmpshm->number - 1, count; register userinfo_t **ulist; + if( end == -1 ) + return NULL; ulist=utmpshm->sorted[utmpshm->currsorted][6]; for(i=((start+end)/2); ;i=(start+end)/2) { -- cgit v1.2.3 From 778f947483119c79804ea81f55ace48673f0b77d Mon Sep 17 00:00:00 2001 From: ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Fri, 24 May 2002 15:52:23 +0000 Subject: for board git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@190 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/include/proto.h | 3 ++- pttbbs/include/pttstruct.h | 14 +++++--------- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/pttbbs/include/proto.h b/pttbbs/include/proto.h index 743575f8..6d2c3049 100644 --- a/pttbbs/include/proto.h +++ b/pttbbs/include/proto.h @@ -1,4 +1,4 @@ -/* $Id: proto.h,v 1.15 2002/05/20 15:38:23 lwms Exp $ */ +/* $Id: proto.h,v 1.16 2002/05/24 15:52:22 ptt Exp $ */ #ifndef INCLUDE_PROTO_H #define INCLUDE_PROTO_H @@ -269,6 +269,7 @@ void show_call_in(int save, int which); void write_request (int sig); void log_usies(char *mode, char *mesg); void log_user(char *msg); +void system_abort(); void abort_bbs(int sig); void del_distinct(char *fname, char *line); void add_distinct(char *fname, char *line); diff --git a/pttbbs/include/pttstruct.h b/pttbbs/include/pttstruct.h index a88bafab..d5849798 100644 --- a/pttbbs/include/pttstruct.h +++ b/pttbbs/include/pttstruct.h @@ -1,4 +1,4 @@ -/* $Id: pttstruct.h,v 1.7 2002/04/15 12:05:50 in2 Exp $ */ +/* $Id: pttstruct.h,v 1.8 2002/05/24 15:52:23 ptt Exp $ */ #ifndef INCLUDE_STRUCT_H #define INCLUDE_STRUCT_H @@ -112,7 +112,10 @@ typedef struct boardheader_t { void *next[2]; /* 在同一個gid下一個看板 動態產生*/ void *firstchild[2]; /* 屬於這個看板的第一個子看板 */ void *parent; - char pad3[100]; + int childcount; /* 有多少個child */ + int nuser; /* 多少人在這板 */ + void *u; /* 放版友 linked list用 */ + char pad3[88]; } boardheader_t; #define BRD_NOZAP 00001 /* 不可zap */ @@ -240,13 +243,6 @@ typedef struct userinfo_t { unsigned short int five_win; unsigned short int five_lose; unsigned short int five_tie; - /* - int myfavorite[FAVMAX]; - char gfavorite[FAVGMAX][FAVGSLEN+1]; - int ninGroup[FAVGMAX]; - int nGroup; - int ninRoot; - */ int mailalert; int sex; char color; -- cgit v1.2.3 From 704871a50924857a45c2a8308825f12b48476edd Mon Sep 17 00:00:00 2001 From: ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Fri, 24 May 2002 15:52:33 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@191 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/board.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pttbbs/mbbsd/board.c b/pttbbs/mbbsd/board.c index 42addecf..ec9a44ab 100644 --- a/pttbbs/mbbsd/board.c +++ b/pttbbs/mbbsd/board.c @@ -1,4 +1,4 @@ -/* $Id: board.c,v 1.6 2002/05/13 03:20:04 ptt Exp $ */ +/* $Id: board.c,v 1.7 2002/05/24 15:52:33 ptt Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -386,7 +386,7 @@ int class_bid = 0; static int yank_flag = 1; static void load_uidofgid(const int gid, const int type){ boardheader_t *bptr,*currbptr; - int n; + int n, childcount=0; currbptr = &bcache[gid-1]; for(n=0;n<numboards;n++) { @@ -401,9 +401,11 @@ static void load_uidofgid(const int gid, const int type){ currbptr->next[type]=bptr; currbptr->parent=&bcache[gid-1]; } + childcount++; currbptr=bptr; } } + bcache[gid-1].childcount=childcount; if(currbptr == &bcache[gid-1]) currbptr->firstchild[type]=(boardheader_t *) ~0; else -- cgit v1.2.3 From 69a2543fe3bb2174245f11818bb90f852baf1eb8 Mon Sep 17 00:00:00 2001 From: ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Fri, 24 May 2002 16:21:11 +0000 Subject: dynamic allocation nbrd git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@192 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/board.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/pttbbs/mbbsd/board.c b/pttbbs/mbbsd/board.c index ec9a44ab..48180836 100644 --- a/pttbbs/mbbsd/board.c +++ b/pttbbs/mbbsd/board.c @@ -1,4 +1,4 @@ -/* $Id: board.c,v 1.7 2002/05/24 15:52:33 ptt Exp $ */ +/* $Id: board.c,v 1.8 2002/05/24 16:21:11 ptt Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -230,7 +230,7 @@ typedef struct { extern time_t login_start_time; extern int numboards; static int *zapbuf=NULL,*favbuf; -static boardstat_t *nbrd; +static boardstat_t *nbrd=NULL; #define STR_BBSRC ".bbsrc" #define STR_FAV ".fav" @@ -263,8 +263,6 @@ void init_brdbuf() { close(n); } - if(!nbrd) - nbrd = (boardstat_t *)malloc(MAX_BOARD * sizeof(boardstat_t)); brc_expire_time = login_start_time - 365 * 86400; } @@ -438,14 +436,15 @@ static void load_boards(char *key) { if(class_bid>0) { bptr = &bcache[class_bid-1]; - if(bptr->firstchild[type]==NULL) + if(bptr->firstchild[type]==NULL || bptr->childcount<=0) load_uidofgid(class_bid,type); } brdnum = 0; if(class_bid==0) + { + nbrd = (boardstat_t *)malloc(numboards * sizeof(boardstat_t)); for(i=0 ; i < numboards; i++) { - if( (bptr = brdshm->sorted[type][i]) == NULL ) continue; n = (int)( bptr - bcache); @@ -457,8 +456,11 @@ static void load_boards(char *key) { ) continue; addnewbrdstat(n, state); } + } else - for(bptr=bptr->firstchild[type]; bptr!=(boardheader_t *)~0; + { + nbrd = (boardstat_t *)malloc( bptr->childcount * sizeof(boardstat_t)); + for(bptr=bptr->firstchild[type]; bptr!=(boardheader_t *)~0; bptr=bptr->next[type]) { n = (int)( bptr - bcache); @@ -468,6 +470,7 @@ static void load_boards(char *key) { (key[0] && !strcasestr(bptr->title, key))) continue; addnewbrdstat(n, state); } + } } static int search_board() { @@ -1032,11 +1035,12 @@ static void choose_board(int newflag) { class_bid = bidtmp; currutmp->brc_id=tmp; brdnum = -1; + free(nbrd); } } } } while(ch != 'q'); - save_brdbuf(); + if(nbrd) free(nbrd); } int root_board() { -- cgit v1.2.3 From 2461eb0bfbc4a6b0846782609a6cf1a8306d6f53 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Fri, 24 May 2002 16:32:31 +0000 Subject: DEBUG show pid git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@193 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/mbbsd.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pttbbs/mbbsd/mbbsd.c b/pttbbs/mbbsd/mbbsd.c index 11d90989..62fcfa86 100644 --- a/pttbbs/mbbsd/mbbsd.c +++ b/pttbbs/mbbsd/mbbsd.c @@ -1,4 +1,4 @@ -/* $Id: mbbsd.c,v 1.29 2002/05/22 15:46:33 in2 Exp $ */ +/* $Id: mbbsd.c,v 1.30 2002/05/24 16:32:31 in2 Exp $ */ #include <stdio.h> #include <string.h> #include <stdlib.h> @@ -585,7 +585,12 @@ login_query () attach_uhash (); now= time(0); attempts = utmpshm->number; +#ifdef DEBUG + move(1, 0); + prints("debugging mode\ncurrent pid: %d\n", getpid()); +#else show_file ("etc/Welcome", 1, -1, NO_RELOAD); +#endif output ("1", 1); if (attempts >= MAX_ACTIVE){ outs ("由於人數太多,請您稍後再來。\n"); -- cgit v1.2.3 From 3e47635fac38e1c9f2410322fe906d1855fac3b2 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Fri, 24 May 2002 16:32:52 +0000 Subject: namecomplete return the position git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@194 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/name.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/pttbbs/mbbsd/name.c b/pttbbs/mbbsd/name.c index a16e89e6..a48c7d32 100644 --- a/pttbbs/mbbsd/name.c +++ b/pttbbs/mbbsd/name.c @@ -1,4 +1,4 @@ -/* $Id: name.c,v 1.4 2002/05/11 16:42:45 in2 Exp $ */ +/* $Id: name.c,v 1.5 2002/05/24 16:32:52 in2 Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -522,17 +522,17 @@ int gnc_completeone(char *data, int start, int end, } if( count == 1 ){ strcpy(data, getname(at)); - return 1; + return at; } - return 0; + return -1; } -void generalnamecomplete(char *prompt, char *data, int len, size_t nmemb, - int (*compar)(int, char *, int), - int (*permission)(int), char* (*getname)(int)) +int generalnamecomplete(char *prompt, char *data, int len, size_t nmemb, + int (*compar)(int, char *, int), + int (*permission)(int), char* (*getname)(int)) { - int x, y, origx, origy, ch, i, morelist = -1, col; + int x, y, origx, origy, ch, i, morelist = -1, col, ret; int start, end, ptr; int clearbot = NA; @@ -554,8 +554,10 @@ void generalnamecomplete(char *prompt, char *data, int len, size_t nmemb, outc('\n'); if( ptr != 0 ){ gnc_findbound(data, &start, &end, nmemb, compar); - gnc_completeone(data, start, end, permission, getname); + ret = gnc_completeone(data, start, end, permission, getname); } + else + ptr = -1; break; } else if( ch == ' ' ){ @@ -565,7 +567,8 @@ void generalnamecomplete(char *prompt, char *data, int len, size_t nmemb, if( morelist == -1 ){ if( gnc_findbound(data, &start, &end, nmemb, compar) == -1 ) continue; - if( gnc_completeone(data, start, end, permission, getname) ){ + if( gnc_completeone(data, start, end, + permission, getname) >= 0 ){ move(origy, origx); outs(data); ptr = strlen(data); @@ -646,6 +649,7 @@ void generalnamecomplete(char *prompt, char *data, int len, size_t nmemb, outs(data); outc('\n'); } + return ret; } /* general complete functions (brdshm) */ -- cgit v1.2.3 From 216a87c9fa2ec452e8e02d47fb26db49c5be51c2 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Fri, 24 May 2002 16:32:52 +0000 Subject: fast user list git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@195 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/talk.c | 1079 +++++++++++++++++++++++++++------------------------ 1 file changed, 568 insertions(+), 511 deletions(-) diff --git a/pttbbs/mbbsd/talk.c b/pttbbs/mbbsd/talk.c index 31b72ff7..09a079c1 100644 --- a/pttbbs/mbbsd/talk.c +++ b/pttbbs/mbbsd/talk.c @@ -1,4 +1,4 @@ -/* $Id: talk.c,v 1.37 2002/05/22 15:18:09 in2 Exp $ */ +/* $Id: talk.c,v 1.38 2002/05/24 16:32:52 in2 Exp $ */ #include <stdio.h> #include <string.h> #include <errno.h> @@ -68,8 +68,7 @@ typedef struct talkwin_t { typedef struct pickup_t { userinfo_t *ui; - //time_t idle; - int friend; + int friend, uoffset; } pickup_t; extern int bind( /* int,struct sockaddr *, int */ ); @@ -83,7 +82,6 @@ extern char *friend_file[8], water_usies; //#define PICKUP_WAYS 7 //關掉女士優先 #define PICKUP_WAYS 6 -static int pickup_way = 0; static char *fcolor[11] = { "", "\033[36m", "\033[32m", "\033[1;32m", "\033[33m", "\033[1;33m", "\033[1;37m", "\033[1;37m", @@ -1433,28 +1431,6 @@ static void creat_list() } */ -static int search_pickup(int num, int actor, pickup_t pklist[]) -{ - char genbuf[IDLEN + 2]; - - move(1, 0); - generalnamecomplete(msg_uid, genbuf, sizeof(genbuf), - utmpshm->number, - completeutmp_compar, - completeutmp_permission, - completeutmp_getname); - if (genbuf[0]){ - int n = (num + 1) % actor; - while (n != num){ - if (!strcasecmp(pklist[n].ui->userid, genbuf)) - return n; - if (++n >= actor) - n = 0; - } - } - return -1; -} - /* Kaede show friend description */ static char *friend_descript(char *uident) { static char *space_buf = " "; @@ -1519,267 +1495,300 @@ static char *descript(int show_mode, userinfo_t * uentp, time_t diff, } } -static int pickup_user_cmp(time_t now, int sortedway, int cmp_fri, - pickup_t pklist[], int *bfriends_number, int *ifh_number, - int *hfm_number,int *irh_number, char *keyword) +#define MAXPICKUP 20 +static int sort_cmpfriend(const void *a, const void *b) { - int i, fri_stat, is_friend, count=0; - userinfo_t *uentp; - for (i=0;i<utmpshm->number;i++){ - uentp = (utmpshm->sorted[utmpshm->currsorted][sortedway][i]); - if (!uentp || !uentp->pid) continue; - fri_stat = friend_stat(currutmp, uentp); - if(uentp->uid==currutmp->uid) - fri_stat = fri_stat|IFH|HFM; - is_friend = (fri_stat & IRH) && !(fri_stat & IFH) ? 0 : - fri_stat & ST_FRIEND; - if (!isvisible_stat(currutmp, uentp, fri_stat) || - ((cmp_fri==1 && !is_friend) || - (cmp_fri==-1 && is_friend)) || - (keyword[0] && !strcasestr(uentp->username,keyword)) - ) continue; - if (bfriends_number && fri_stat & IBH) (*bfriends_number)++; - if (ifh_number && fri_stat & IFH) (*ifh_number)++; - if (hfm_number && fri_stat & HFM) (*hfm_number)++; - if (irh_number && fri_stat & IRH) (*irh_number)++; - pklist[count].friend = fri_stat; - pklist[count].ui = uentp; - count++; - } - return count; + if( ((((pickup_t *)a)->friend)&ST_FRIEND) == + ((((pickup_t *)b)->friend)&ST_FRIEND) ) + return strcasecmp( ((pickup_t *)a)->ui->userid, + ((pickup_t *)b)->ui->userid ); + else + return (((pickup_t *)b)->friend & ST_FRIEND) - + (((pickup_t *)a)->friend & ST_FRIEND); } -static int cmputmpfriend(const void *i, const void *j) +int pickup_maxpages(int pickupway) { - if((((pickup_t*)j)->friend&ST_FRIEND)==(((pickup_t*)i)->friend&ST_FRIEND)) - return strcasecmp( ((pickup_t*)i)->ui->userid, - ((pickup_t*)j)->ui->userid); + int number; + if( cuser.uflag & FRIEND_FLAG ) + number = currutmp->friendtotal; else - return (((pickup_t*)j)->friend&ST_FRIEND) - - (((pickup_t*)i)->friend&ST_FRIEND); -} + number = utmpshm->number + + (pickupway == 0 ? currutmp->friendtotal : 0); + return number / MAXPICKUP + (number % MAXPICKUP == 0 ? 0 : 1); +} -static void pickup_user(void) +static void pickup_myfriend(pickup_t *friends, int *nGots, + int *myfriend, int *friendme) { - static int real_name = 0; - static int show_mode = 0; - static int show_uid = 0; - static int show_board = 0; - static int show_pid = 0; - static int num = 0; - char genbuf[200]; + //pickup_t friends[MAX_FRIEND + 1]; + userinfo_t *uentp; + int i, where, frstate; + + *myfriend = *friendme = 1; + for( *nGots = i = 0 ; currutmp->friend_online[i] && i < MAX_FRIEND ; ++i ){ + where = currutmp->friend_online[i] & 0xFFFFFF; + if( 0 <= where && where < MAX_ACTIVE && + (uentp = &utmpshm->uinfo[where]) && uentp->pid && + isvisible_stat(currutmp, uentp, + frstate = + currutmp->friend_online[i] >> 24) + ){ + friends[*nGots].ui = &utmpshm->uinfo[where]; + friends[*nGots].uoffset = where; + friends[(*nGots)++].friend = frstate; + if( frstate & IFH ) + ++*myfriend; + if( frstate & HFM ) + ++*friendme; + } + } + friends[*nGots].ui = currutmp; + friends[(*nGots)++].friend = 24; + qsort(friends, *nGots, sizeof(pickup_t), sort_cmpfriend); +} + +static void pickup(pickup_t *currpickup, int pickup_way, int *page, + int *myfriend, int *friendme) +{ + /* avoid race condition */ + int currsorted = utmpshm->currsorted; + int utmpnumber = utmpshm->number; + int friendtotal= currutmp->friendtotal; + + userinfo_t **utmp; + int which, got, sorted_way; + + got = 0; + + if( friendtotal == 0 ) + *myfriend = *friendme = 1; + + if( cuser.uflag & FRIEND_FLAG || + (pickup_way == 0 && *page * MAXPICKUP < friendtotal) ){ + /* [嗨! 朋友] mode. + we need to pickup ALL friends (from currutmp friend_online), + sort, and get pickup from right starting position */ + + pickup_t friends[MAX_FRIEND + 1]; + int nGots; + + pickup_myfriend(friends, &nGots, myfriend, friendme); + for( which = *page * MAXPICKUP ; + got < MAXPICKUP && which < nGots ; + ++got, ++which ) + currpickup[got] = friends[which]; + } + + if( !(cuser.uflag & FRIEND_FLAG) ){ + sorted_way = ((pickup_way == 0) ? 0 : (pickup_way - 1)); + utmp = utmpshm->sorted[currsorted][sorted_way]; + + which = *page * MAXPICKUP - currutmp->friendtotal; + for( which = (which >= 0 ? which : 0) ; + got < MAXPICKUP && which < utmpnumber ; + ++got, ++which ){ + + for( ; which < utmpnumber ; ++which ) + if( isvisible_stat(currutmp, utmp[which], 0) ) + break; + if( which == utmpnumber ) + break; + currpickup[got].ui = utmp[which]; + currpickup[got].friend = 0; + } + } + + for( ; got < MAXPICKUP ; ++got ) + currpickup[got].ui = 0; +} #ifdef WHERE - extern struct fromcache_t *fcache; +extern struct fromcache_t *fcache; #endif - register userinfo_t *uentp; - register pid_t pid0 = 0; /* Ptt 定位 */ - register int id0 = 0; /* US_PICKUP時的游標用 */ - register int state = US_PICKUP, ch; - register int actor = 0, head, foot; - int fri_stat, bfriends_number, ifh_number, irh_number, hfm_number; - int savemode = currstat; - int i, sortedway; /* 只是loop有用到 */ - time_t diff, freshtime = 0; - pickup_t pklist[USHM_SIZE]; /* parameter Ptt註 */ -/* num : 現在的游標位 */ -/* foot: 此頁的腳腳 */ - char buf[20],keyword[13]=""; /* actor:共有多少user */ - char pagerchar[5] = "* -Wf"; - char *msg_pickup_way[PICKUP_WAYS] = - { - "嗨! 朋友", - "網友代號", - "網友動態", - "發呆時間", - "來自何方", - "五子棋 ", -// "女士優先" - }; - char *MODE_STRING[MAX_SHOW_MODE] = - { - "故鄉", - "好友描述", - "五子棋戰績" +char *Mind[] = { + " ", + "^-^", "^_^", "Q_Q", "@_@", "/_\\", "=_=", "-_-", "-.-", ">_<", + "-_+", "!_!", "o_o", "z_Z", "O_O", "O.O", "$_$", "^*^", "O_<", + "喜!", "怒!", "哀!", "樂!", ":) ", ":( ", ":~ ", ":q ", ":O ", + ":D ", ":p ", ";) ", ":> ", ";> ", ":< ", ":)~", ":D~", ">< ", + "^^;", "^^|", "哭;", NULL +}; +static void draw_pickup(int drawall, pickup_t *pickup, int pickup_way, + int page, int show_mode, int show_uid, int show_board, + int show_pid, int real_name, + int myfriend, int friendme) +{ + char *msg_pickup_way[PICKUP_WAYS] = { + "嗨! 朋友", "網友代號", "網友動態", "發呆時間", "來自何方", "五子棋 " }; - char - *Mind[] = - {" ", - "^-^", "^_^", "Q_Q", "@_@", "/_\\", "=_=", "-_-", "-.-", ">_<", - "-_+", "!_!", "o_o", "z_Z", "O_O", "O.O", "$_$", "^*^", "O_<", - "喜!", "怒!", "哀!", "樂!", ":) ", ":( ", ":~ ", ":q ", ":O ", - ":D ", ":p ", ";) ", ":> ", ";> ", ":< ", ":)~", ":D~", ">< ", - "^^;", "^^|", "哭;", NULL}; - - while (1) { - if (utmpshm->uptime > freshtime || state == US_PICKUP || - state ==US_RESORT){ - state = US_PICKUP; - freshtime=now; - ifh_number=hfm_number=irh_number=bfriends_number = actor = ch = 0; - if(pickup_way==0) - sortedway=0; - else - sortedway=pickup_way-1; - - //qsort(pklist,actor,sizeof(pickup_t),cmputmpfriend); - if(pickup_way==0 || (cuser.uflag & FRIEND_FLAG)){ - actor=pickup_user_cmp(freshtime, sortedway, 1, - pklist, &bfriends_number, &ifh_number, - &hfm_number, NULL, keyword); - if(sortedway==0) - qsort(pklist,actor,sizeof(pickup_t),cmputmpfriend); - if(!(cuser.uflag & FRIEND_FLAG)) - actor=pickup_user_cmp(freshtime, sortedway, -1, - pklist+actor, NULL, NULL, NULL, - &irh_number, keyword); - } - else{ - actor=pickup_user_cmp(freshtime, sortedway, 0, - pklist, &bfriends_number, &ifh_number, - &hfm_number, &irh_number, keyword); - } + char *MODE_STRING[MAX_SHOW_MODE] = {"故鄉", "好友描述", "五子棋戰績"}; + char pagerchar[5] = "* -Wf"; + userinfo_t *uentp; + int i, ch, state, friend; +#ifdef SHOW_IDLE_TIME + char idlestr[32]; + int idletime; +#endif - if (!actor){ - if(keyword[0]){ - mprints(b_lines-1,0, - "搜尋不到任何人 !!"); - keyword[0]=0; - pressanykey(); - continue; - } - getdata(b_lines - 1, 0, - "你的朋友還沒上站,要看看一般網友嗎(Y/N)?[Y]", - genbuf, 4, LCECHO); - if (genbuf[0] != 'n'){ - cuser.uflag &= ~FRIEND_FLAG; - continue; - } - return; - } - } - if (state >= US_ACTION){ - showtitle((cuser.uflag & FRIEND_FLAG) ? "好友列表" : "休閒聊天", - BBSName); - prints(" 排序:[%s] 上站人數:%-4d\033[1;32m我的朋友:%-3d" - "\033[33m與我為友:%-3d\033[36m板友:%-4d\033[31m壞人:" - "%-2d\033[m\n" - "\033[7m %s P%c代號 %-17s%-17s%-13s%-10s\033[m\n", - msg_pickup_way[pickup_way], actor, ifh_number, - hfm_number, bfriends_number, irh_number, - show_uid ? "UID" : "No.", - (HAS_PERM(PERM_SEECLOAK) || HAS_PERM(PERM_SYSOP)) ? 'C' : ' ', - real_name ? "姓名" : "暱稱", - MODE_STRING[show_mode], - show_board ? "Board" : "動態", - show_pid ? " PID" : "備註 發呆" - ); + if( drawall ){ + showtitle((cuser.uflag & FRIEND_FLAG) ? "好友列表" : "休閒聊天", + BBSName); + prints("\n" + "\033[7m %s P%c代號 %-17s%-17s%-13s%-10s\033[m\n", + show_uid ? "UID" : "No.", + (HAS_PERM(PERM_SEECLOAK) || HAS_PERM(PERM_SYSOP)) ? 'C' : ' ', + real_name ? "姓名" : "暱稱", + MODE_STRING[show_mode], + show_board ? "Board" : "動態", + show_pid ? " PID" : "備註 發呆" + ); + move(b_lines, 0); + outs("\033[31;47m(TAB/f)\033[30m排序/好友 \033[31m(t)\033[30m聊天 " + "\033[31m(a/d/o)\033[30m交友 \033[31m(q)\033[30m查詢 " + "\033[31m(w)\033[30m水球 \033[31m(m)\033[30m寄信 \033[31m(h)" + "\033[30m線上輔助 \033[m"); + } + + move(1, 0); + prints(" 排序:[%s] 上站人數:%-4d\033[1;32m我的朋友:%-3d" + "\033[33m與我為友:%-3d\033[36m板友:%-4d\033[31m壞人:" + "%-2d\033[m\n", + msg_pickup_way[pickup_way], utmpshm->number, + //ifh_number, hfm_number, bfriends_number, irh_number, + myfriend, friendme, 0, 0); + + move(3, 0); + for( i = 0, ch = page * 20 + 1 ; i < MAXPICKUP ; ++i, ++ch ){ + uentp = pickup[i].ui; + friend = pickup[i].friend; + if( uentp == NULL ){ + prints("\n"); + continue; } - else{ - move(3, 0); - clrtobot(); + + if( !uentp->pid ){ + prints("%5d < 離站中..>\n", ch); + continue; } - if (pid0) - for (ch = 0; ch < actor; ch++){ - if (pid0 == (pklist[ch].ui)->pid && - id0 == 256 * pklist[ch].ui->userid[0] + - pklist[ch].ui->userid[1]){ - num = ch; - } - } - if (num < 0) - num = 0; - else if (num >= actor) - num = actor - 1; - head = (num / p_lines) * p_lines; - foot = head + p_lines; - if (foot > actor) - foot = actor; - for (ch = head; ch < foot; ch++){ - uentp = pklist[ch].ui; - - if (!uentp->pid){ - prints("%5d < 離站中..>\n",ch); - continue; - } + + if( PERM_HIDE(uentp) ) + state = 9; + else if( currutmp == uentp ) + state = 10; + else if( friend & IRH && !(friend & IFH) ) + state = 8; + else + state = (friend & ST_FRIEND) >> 2; + #ifdef SHOW_IDLE_TIME - diff = freshtime - pklist[ch].ui->lastact; - //diff = pklist[ch].idle; - // if (diff > 1800) diff = 1800; /* Doma: 以免一大串的發呆時間 */ - // in2: max 30'00 :P Ptt:真實沒關係 - if (diff > 3600*24) - strcpy(buf," -----"); - else if (diff > 3600 ) - sprintf(buf,"%3ldh%02ld", diff / 3600, (diff/60) % 60); - else if (diff > 0) - sprintf(buf, "%3ld'%02ld", diff / 60, diff % 60); - else - buf[0] = '\0'; -#else - buf[0] = '\0'; -#endif - i = pklist[ch].friend; -#ifdef SHOWPID - if (show_pid) - sprintf(buf, "%6d", uentp->pid); + idletime = (now - uentp->lastact); + if( idletime > 86400 ) + strcpy(idlestr, " -----"); + else if( idletime >= 3600 ) + sprintf(idlestr, "%3dh%02d", + idletime / 3600, (idletime / 60) % 60); + else if( idletime > 0 ) + sprintf(idlestr, "%3d'%02d", + idletime / 60, idletime % 60); + else + strcpy(idlestr, " "); #endif - if (PERM_HIDE(uentp)) - state = 9; - else if(currutmp == uentp) - state =10; - else if(i & IRH && !(i & IFH)) - state = 8; - else - state =(i&ST_FRIEND)>>2; - diff = uentp->pager & !(i&HRM); - prints("%5d %c%c%s%-13s%-17.16s\033[m%-17.16s%-13.13s" - "\33[33m%-4.4s\33[m%s\n", + + prints("%5d %c%c%s%-13s%-17.16s\033[m%-17.16s%-13.13s" + "\33[33m%-4.4s\33[m%s\n", + + /* list number or uid */ #ifdef SHOWUID - show_uid ? uentp->uid : + show_uid ? uentp->uid : #endif - (ch + 1), - (i & HRM) ? 'X' : - pagerchar[uentp->pager % 5], - (uentp->invisible ? ')' : ' '), - fcolor[state], - /* %s */ - uentp->userid, - - /* %-13s 暱稱 */ + ch, + + /* super friend or pager */ + (friend & HRM) ? 'X' : pagerchar[uentp->pager % 5], + + /* visibility */ + (uentp->invisible ? ')' : ' '), + + /* color of userid, userid */ + fcolor[state], uentp->userid, + + /* nickname or realname */ #ifdef REALINFO - real_name ? uentp->realname : + real_name ? uentp->realname : #endif - uentp->username, - /* %-17.16s 故鄉 */ - descript(show_mode, uentp, diff, fcache), + uentp->username, + + /* from */ + descript(show_mode, uentp, + uentp->pager & !(friend&HRM), fcache), - /* %-17.16s 看板 */ + /* board or mode */ #ifdef SHOWBOARD - show_board ? (uentp->brc_id == 0 ? "" : - bcache[uentp->brc_id - 1].brdname) : + show_board ? (uentp->brc_id == 0 ? "" : + bcache[uentp->brc_id - 1].brdname) : #endif - /* %-13.13s */ - modestring(uentp, 0), - /* %4s 備註 */ - ((uentp->userlevel & PERM_VIOLATELAW) ? "通緝" : - (uentp->birth ? "壽星" : - Mind[uentp->mind])), - /* %s 發呆 */ - buf); + /* %-13.13s */ + modestring(uentp, 0), + + /* memo */ + ((uentp->userlevel & PERM_VIOLATELAW) ? "通緝" : + (uentp->birth ? "壽星" : Mind[uentp->mind])), + + /* idle */ +#ifdef SHOW_IDLE_TIME + idlestr +#else + "" +#endif + ); + } +} + +static void pickup_user(void) +{ + + pickup_t currpickup[MAXPICKUP]; + userinfo_t *uentp; + static int show_mode = 0; + static int show_uid = 0; + static int show_board = 0; + static int show_pid = 0; + static int real_name = 0; + char genbuf[256]; + int page, offset, pickup_way, ch, leave, redraw, redrawall, fri_stat; + int myfriend, friendme, i, looptimes; + + page = offset = 0; + pickup_way = 0; + leave = 0; + redrawall = 1; + while( !leave ){ + pickup(currpickup, pickup_way, &page, &myfriend, &friendme); + draw_pickup(redrawall, currpickup, pickup_way, page, + show_mode, show_uid, show_board, show_pid, real_name, + myfriend, friendme); + + if( currpickup[offset].ui == NULL ){ + for( ; offset >= 0 ; --offset ) + if( currpickup[offset].ui != NULL ) + break; + if( offset == -1 ){ + --page; + offset = 0; + continue; + } } - if (state == US_PICKUP) - continue; - move(b_lines, 0); - outs("\033[31;47m(TAB/f)\033[30m排序/好友 \033[31m(t)\033[30m聊天 " - "\033[31m(a/d/o)\033[30m交友 \033[31m(q)\033[30m查詢 " - "\033[31m(w)\033[30m水球 \033[31m(m)\033[30m寄信 \033[31m(h)" - "\033[30m線上輔助 \033[m"); - state = 0; - while (!state){ - ch = cursor_key(num + 3 - head, 0); + redraw = redrawall = 0; + looptimes = 0; + while( !redraw ){ + ch = cursor_key(offset + 3, 0); + uentp = currpickup[offset].ui; + fri_stat = currpickup[offset].friend; + if (ch == KEY_RIGHT || ch == '\n' || ch == '\r') ch = 't'; @@ -1787,48 +1796,50 @@ static void pickup_user(void) case KEY_LEFT: case 'e': case 'E': - if(!keyword[0]) return; - keyword[0]=0; - state = US_PICKUP; + redraw = leave = 1; break; case KEY_TAB: pickup_way = (pickup_way + 1) % PICKUP_WAYS; - state = US_RESORT; - num = 0; + redraw = 1; + redrawall = 1; break; case KEY_DOWN: case 'n': case 'j': - if (++num < actor){ - if (num >= foot) - state = US_REDRAW; - break; + if( ++offset == MAXPICKUP || currpickup[offset].ui == NULL ){ + redraw = 1; + if( ++page >= pickup_maxpages(pickup_way) ) + offset = page = 0; + else + offset = 0; } + break; + case '0': case KEY_HOME: - num = 0; - if (head) - state = US_REDRAW; + page = offset = 0; break; + case 'H': if (HAS_PERM(PERM_SYSOP)){ currutmp->userlevel ^= PERM_DENYPOST; - state = US_REDRAW; + redrawall = redraw = 1; } break; + case 'D': if (HAS_PERM(PERM_SYSOP)){ char buf[100]; - sprintf(buf, "代號 [%s]:", currutmp->userid); if (!getdata(1, 0, buf, currutmp->userid, - sizeof(currutmp->userid), DOECHO)) + sizeof(buf), DOECHO)) strcpy(currutmp->userid, cuser.userid); - state = US_REDRAW; + redrawall = redraw = 1; } break; + case 'F': if (HAS_PERM(PERM_SYSOP)){ char buf[100]; @@ -1837,66 +1848,104 @@ static void pickup_user(void) if (!getdata(1, 0, buf, currutmp->from, sizeof(currutmp->from), DOECHO)) strncpy(currutmp->from, fromhost, 23); - state = US_REDRAW; + redraw = 1; } break; + case 'C': #if !HAVE_FREECLOAK if (HAS_PERM(PERM_CLOAK)) #endif - { - currutmp->invisible ^= 1; - state = US_REDRAW; - } + { + currutmp->invisible ^= 1; + redrawall = redraw = 1; + } break; + case ' ': case KEY_PGDN: - case Ctrl('F'): - if (foot < actor){ - num += p_lines; - state = US_REDRAW; - break; - } - if (head) - num = 0; - state = US_PICKUP; + case Ctrl('F'):{ + int newpage; + if( (newpage = page + 1) >= pickup_maxpages(pickup_way) ) + newpage = offset = 0; + if( newpage != page ){ + page = newpage; + redraw = 1; + } else if( ++looptimes == 10 ) + redrawall = redraw = 1; + } break; + case KEY_UP: case 'k': - if (--num < head){ - if (num < 0){ - num = actor - 1; - if (actor == foot) - break; - } - state = US_REDRAW; + if( --offset == -1 ){ + offset = MAXPICKUP - 1; + if( --page == -1 ) + page = pickup_maxpages(pickup_way); + redraw = 1; } break; + case KEY_PGUP: case Ctrl('B'): case 'P': - if (head){ - num -= p_lines; - state = US_REDRAW; - break; - } + if( --page == -1 ) + page = pickup_maxpages(pickup_way) - 1; + offset = 0; + redraw = 1; + break; case KEY_END: case '$': - num = actor - 1; - if (foot < actor) - state = US_REDRAW; + page = pickup_maxpages(pickup_way) - 1; + redraw = 1; break; case '/': + /* getdata_buf(b_lines-1,0,"請輸入暱稱關鍵字:", keyword, sizeof(keyword), DOECHO); state = US_PICKUP; + */ break; + case 's': + if( !(cuser.uflag & FRIEND_FLAG) ){ + int si; /* utmpshm->sorted[X][0][si] */ + int fi; /* allpickuplist[fi] */ + char swid[IDLEN + 1]; + move(1, 0); + si = generalnamecomplete(msg_uid, swid, + sizeof(swid), utmpshm->number, + completeutmp_compar, + completeutmp_permission, + completeutmp_getname); + if( si >= 0 ){ + pickup_t friends[MAX_FRIEND + 1]; + int nGots, i; + fi = utmpshm->sorted[utmpshm->currsorted][0][si] - + &utmpshm->uinfo[0]; + + pickup_myfriend(friends, &nGots, &myfriend, &friendme); + for( i = 0 ; i < nGots ; ++i ) + if( friends[i].uoffset == fi ) + break; + if( i != nGots ){ + page = i / 20; + offset = i % 20; + } + else{ + page = (si) / 20; + offset = (si) % 20; + } + } + redrawall = redraw = 1; + } + /* if ((i = search_pickup(num, actor, pklist)) >= 0) num = i; state = US_ACTION; + */ break; case '1': @@ -1908,286 +1957,294 @@ static void pickup_user(void) case '7': case '8': case '9': - { /* Thor: 可以打數字跳到該人 */ - int tmp; - if ((tmp = search_num(ch, actor - 1)) >= 0) - num = tmp; - state = US_REDRAW; - } - break; + { /* Thor: 可以打數字跳到該人 */ + int tmp; + if( (tmp = search_num(ch, utmpshm->number)) >= 0 ){ + if( tmp / 20 == page ){ + /* in2:目的在目前這一頁, 直接 + 更新 offset , 不用重畫畫面 */ + offset = tmp % 20; + } + else{ + page = tmp / 20; + offset = tmp % 20; + } + redrawall = redraw = 1; + } + } + break; + #ifdef REALINFO case 'R': /* 顯示真實姓名 */ - if (HAS_PERM(PERM_SYSOP)) + if (HAS_PERM(PERM_SYSOP)){ real_name ^= 1; - state = US_PICKUP; + redraw = 1; + } break; #endif #ifdef SHOWUID case 'U': - if (HAS_PERM(PERM_SYSOP)) + if (HAS_PERM(PERM_SYSOP)){ show_uid ^= 1; - state = US_PICKUP; + redraw = 1; + } break; #endif #ifdef SHOWBOARD case 'Y': - if (HAS_PERM(PERM_SYSOP)) + if (HAS_PERM(PERM_SYSOP)){ show_board ^= 1; - state = US_PICKUP; + redraw = 1; + } break; #endif #ifdef SHOWPID case '#': - if (HAS_PERM(PERM_SYSOP)) + if (HAS_PERM(PERM_SYSOP)){ show_pid ^= 1; - state = US_PICKUP; + redraw = 1; + } break; #endif case 'b': /* broadcast */ if (cuser.uflag & FRIEND_FLAG || HAS_PERM(PERM_SYSOP)){ - int actor_pos = actor; char ans[4]; - - state = US_PICKUP; + if (!getdata(0, 0, "廣播訊息:", genbuf, 60, DOECHO)) break; if (getdata(0, 0, "確定廣播? [Y]", ans, sizeof(ans), LCECHO) && *ans == 'n') break; - while (actor_pos){ - uentp = pklist[--actor_pos].ui; - fri_stat = pklist[actor_pos].friend; - if (uentp->pid && - currpid != uentp->pid && - uentp->pid > 0 && kill(uentp->pid, 0) != -1 && - (HAS_PERM(PERM_SYSOP) || - (uentp->pager != 3 && - (uentp->pager != 4 || fri_stat & HFM)))) - my_write(uentp->pid, genbuf, uentp->userid, HAS_PERM(PERM_SYSOP) ? 3 : 1, NULL); + if( HAS_PERM(PERM_SYSOP) ){ + for( i = 0 ; i < utmpshm->number ; ++i ){ + uentp = utmpshm->sorted[utmpshm->currsorted][0][i]; + if( uentp->pid && kill(uentp->pid, 0) != -1 ) + my_write(uentp->pid, genbuf, + uentp->userid, 1, NULL); + } } + else{ + userinfo_t *uentp; + int where, frstate; + for( i = 0 ; currutmp->friend_online[i] && + i < MAX_FRIEND ; ++i ){ + where = currutmp->friend_online[i] & 0xFFFFFF; + if( 0 <= where && where < MAX_ACTIVE && + (uentp = &utmpshm->uinfo[where]) && + uentp->pid && + isvisible_stat(currutmp, uentp, + frstate = + currutmp->friend_online[i]>>24) + && kill(uentp->pid, 0) != -1 && + uentp->pager != 3 && + (uentp->pager != 4 || frstate & HFM) ){ + my_write(uentp->pid, genbuf, + uentp->userid, 1, NULL); + } + } + } + redrawall = redraw = 1; } break; + case 'S': /* 顯示好友描述 */ show_mode = (++show_mode) % MAX_SHOW_MODE; - state = US_PICKUP; - break; - case 'u': /* 線上修改資料 */ - case 'K': /* 把壞蛋踢出去 */ - if (!HAS_PERM(PERM_ACCOUNTS)) - continue; - state = US_ACTION; + redrawall = redraw = 1; break; - case 'i': - state = US_ACTION; - break; - case Ctrl('S'): - state = US_ACTION; - break; - case 't': - case 'w': - if (!(cuser.userlevel & PERM_LOGINOK)) - continue; - state = US_ACTION; - break; - case 'a': - case 'd': - case 'o': - case 'f': - case 'g': - if (!HAS_PERM(PERM_LOGINOK)) - /* 註冊才有 Friend */ - break; - if (ch == 'f') - { - cuser.uflag ^= FRIEND_FLAG; - state = US_PICKUP; - break; - } - state = US_ACTION; - break; - case 'q': - case 'c': - case 'm': - case 'r': - case 'l': - /* guest 只能 query */ - if (!cuser.userlevel && ch != 'q' && ch != 'l') - break; - case 'h': - state = US_ACTION; - break; - case 'p': - if (HAS_PERM(PERM_BASIC)){ - t_pager(); - state = US_REDRAW; + + case 'u': /* 線上修改資料 */ + if( HAS_PERM(PERM_ACCOUNTS) ){ + int id; + userec_t muser; + strcpy(currauthor, uentp->userid); + stand_title("使用者設定"); + move(1, 0); + if( (id = getuser(uentp->userid)) > 0 ){ + memcpy(&muser, &xuser, sizeof(muser)); + user_display(&muser, 1); + uinfo_query(&muser, 1, id); + } + redrawall = redraw = 1; } break; - case 'W': - { - int tmp; - char *wm[3] = {"一般", "進階", "未來"}; - tmp = cuser.uflag2 & WATER_MASK; - cuser.uflag2 -= tmp; - tmp = (tmp + 1) % 3; - cuser.uflag2 |= tmp; - prints("切換到 %s 水球模式", wm[tmp]); - refresh(); - sleep(1); - state = US_REDRAW; - } - default: /* refresh screen */ - state = US_REDRAW; - } - } - - if (state != US_ACTION){ - pid0 = 0; - continue; - } - /* Ptt decide cur */ - uentp = pklist[num].ui; - fri_stat = friend_stat(currutmp, uentp); - pid0 = uentp->pid; - id0 = 256 * uentp->userid[0] + uentp->userid[1]; - - if (ch == 'w'){ - if ((uentp->pid != currpid) && - (HAS_PERM(PERM_SYSOP) || - (uentp->pager != 3 && - (fri_stat & HFM || uentp->pager != 4)))){ - cursor_show(num + 3 - head, 0); - sprintf(genbuf, "Call-In %s :", uentp->userid); - my_write(uentp->pid, genbuf, uentp->userid, 0, NULL); - } - } - else if (ch == 'l'){ /* Thor: 看 Last call in */ - t_display(); - } - else{ - switch (ch){ - case 'r': - m_read(); - break; - case 'g': /* give money */ - move(b_lines - 2, 0); - if (strcmp(uentp->userid, cuser.userid)){ - sprintf(genbuf, "要給 %s 多少錢呢? ", uentp->userid); - outs(genbuf); - if (getdata(b_lines - 1, 0, "[銀行轉帳]:", genbuf, 7, - LCECHO)){ - clrtoeol(); - if ((ch = atoi(genbuf)) <= 0 || ch <= give_tax(ch) ) - break; - reload_money(); - if (ch > cuser.money) - outs("\033[41m 現金不足~~\033[m"); - else{ - deumoney(uentp->uid, ch - give_tax(ch)); - sprintf(genbuf, "\033[44m 嗯..還剩下 %d 錢.." - "\033[m", demoney(-ch)); - outs(genbuf); - sprintf(genbuf, "%s\t給%s\t%d\t%s", cuser.userid, - uentp->userid, ch, - ctime(&currutmp->lastact)); - log_file(FN_MONEY, genbuf); - mail_redenvelop(cuser.userid, uentp->userid, ch - give_tax(ch), 'Y'); - } - } - else{ - clrtoeol(); - outs("\033[41m 交易取消! \033[m"); - } + case 'K': /* 踢人 */ + if( HAS_PERM(PERM_ACCOUNTS) ){ } - else - outs("\033[33m 自己給自己? 耍笨..\033[m"); - refresh(); - sleep(1); break; -#ifdef SHOWMIND + case 'i': move(3,0); clrtobot(); - for (i = 1; Mind[i]!=NULL; i++){ - move(5+(i-1)/7,((i-1)%7)*10); - prints("%2d: %s",i,Mind[i]); + for( i = 0 ; Mind[i] != NULL ; ++i ){ + move(5 + (i - 1) / 7, ((i - 1) % 7) * 10); + prints("%2d: %s", i, Mind[i]); } getdata(b_lines - 1, 0, "你現在的心情 0:無 q不變 [q]:", genbuf, 3, LCECHO); - if (genbuf[0] && genbuf[0] != 'q') - currutmp->mind=atoi(genbuf)%i; - state = US_REDRAW; + if( genbuf[0] && genbuf[0] != 'q' ) + currutmp->mind = atoi(genbuf) % i; break; -#endif + + case Ctrl('S'): + break; + + case 't': + if( HAS_PERM(PERM_LOGINOK) ){ + if( uentp->pid != currpid && + strcmp(uentp->userid, cuser.userid) != 0 ){ + move(1, 0); + clrtobot(); + move(3, 0); + my_talk(uentp, fri_stat); + redrawall = redraw = 1; + } + } + break; + + case 'w': + if( HAS_PERM(PERM_LOGINOK) && + uentp->pid != currpid && + strcmp(uentp->userid, cuser.userid) != 0 && + (HAS_PERM(PERM_SYSOP) || + (uentp->pager != 3 && + (fri_stat & HFM || uentp->pager != 4))) ){ + cursor_show(offset + 3, 0); + sprintf(genbuf, "Call-In %s :", uentp->userid); + my_write(uentp->pid, genbuf, uentp->userid, 0, NULL); + redrawall = redraw = 1; + } + break; + case 'a': - friend_add(uentp->userid, FRIEND_OVERRIDE); - friend_load(); - state = US_PICKUP; + if( HAS_PERM(PERM_LOGINOK) ){ + friend_add(uentp->userid, FRIEND_OVERRIDE); + friend_load(); + redrawall = redraw = 1; + } break; + case 'd': - friend_delete(uentp->userid, FRIEND_OVERRIDE); - friend_load(); - state = US_PICKUP; + if( HAS_PERM(PERM_LOGINOK) ){ + friend_delete(uentp->userid, FRIEND_OVERRIDE); + friend_load(); + redrawall = redraw = 1; + } break; + case 'o': - t_override(); - state = US_PICKUP; + if( HAS_PERM(PERM_LOGINOK) ){ + t_override(); + redrawall = redraw = 1; + } break; - case 'K': - if (uentp->pid > 0 && kill(uentp->pid, 0) != -1){ - move(1, 0); - clrtobot(); - move(2, 0); - my_kick(uentp); - state = US_PICKUP; + + case 'f': + if( HAS_PERM(PERM_LOGINOK) ){ + cuser.uflag ^= FRIEND_FLAG; + redrawall = redraw = 1; } break; + + case 'g': + if( HAS_PERM(PERM_LOGINOK) && + strcmp(uentp->userid, cuser.userid) != 0 ){ + move(b_lines - 2, 0); + sprintf(genbuf, "要給 %s 多少錢呢? ", uentp->userid); + outs(genbuf); + if( getdata(b_lines - 1, 0, "[銀行轉帳]: ", + genbuf, 7, LCECHO) ){ + clrtoeol(); + if( (ch == atoi(genbuf)) <= 0 || ch <= give_tax(ch) ) + break; + reload_money(); + + if( ch > cuser.money ) + outs("\033[41m 現金不足~~\033[m"); + else{ + deumoney(uentp->uid, ch - give_tax(ch)); + sprintf(genbuf, "\033[44m 嗯..還剩下 %d 錢.." + "\033[m", demoney(-ch)); + outs(genbuf); + sprintf(genbuf, "%s\t給%s\t%d\t%s", cuser.userid, + uentp->userid, ch, + ctime(&currutmp->lastact)); + log_file(FN_MONEY, genbuf); + mail_redenvelop(cuser.userid, uentp->userid, + ch - give_tax(ch), 'Y'); + } + } + else{ + clrtoeol(); + outs("\033[41m 交易取消! \033[m"); + } + redrawall = redraw = 1; + } + break; + case 'm': stand_title("寄 信"); prints("[寄信] 收信人:%s", uentp->userid); my_send(uentp->userid); break; + case 'q': - strcpy(currauthor, uentp->userid); - my_query(uentp->userid); + strcpy(currauthor, uentp->userid); + my_query(uentp->userid); + redrawall = redraw = 1; break; + case 'c': - chicken_query(uentp->userid); + if( HAS_PERM(PERM_LOGINOK) ){ + chicken_query(uentp->userid); + redrawall = redraw = 1; + } break; - case 'u':{ /* Thor: 可線上查看及修改使用者 */ - int id; - userec_t muser; - - strcpy(currauthor, uentp->userid); - stand_title("使用者設定"); - move(1, 0); - if ((id = getuser(uentp->userid))){ - memcpy(&muser, &xuser, sizeof(muser)); - user_display(&muser, 1); - uinfo_query(&muser, 1, id); + + case 'l': + if( HAS_PERM(PERM_LOGINOK) ){ + t_display(); + redrawall = redraw = 1; } - } - break; + break; - case 'h': /* Thor: 看 Help */ + case 'h': t_showhelp(); + redrawall = redraw = 1; break; - case 't': - if (uentp->pid != currpid && - (strcmp(uentp->userid, cuser.userid))){ - move(1, 0); - clrtobot(); - move(3, 0); - my_talk(uentp, fri_stat); - state = US_PICKUP; + case 'p': + if( HAS_PERM(PERM_BASIC) ){ + t_pager(); + redrawall = redraw = 1; + } + break; + + case 'W': + if( HAS_PERM(PERM_LOGINOK) ){ + int tmp; + char *wm[3] = {"一般", "進階", "未來"}; + tmp = cuser.uflag2 & WATER_MASK; + cuser.uflag2 -= tmp; + tmp = (tmp + 1) % 3; + cuser.uflag2 |= tmp; + move(4, 0); + prints("系統提供 一般 進階 未來 三種模式\n" + "在切換後請正常下線再重新登入, 以確保結構正確\n" + "目前切換到 %s 水球模式\n", wm[tmp]); + refresh(); + sleep(2); + redrawall = redraw = 1; } break; + + default: + if( ++looptimes == 10 ) + redrawall = redraw = 1; } } - setutmpmode(savemode); } } -- cgit v1.2.3 From b95987c5bf2b9205c44084a7408574f85be16fce Mon Sep 17 00:00:00 2001 From: ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Fri, 24 May 2002 16:34:16 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@196 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/board.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pttbbs/mbbsd/board.c b/pttbbs/mbbsd/board.c index 48180836..e5996ec5 100644 --- a/pttbbs/mbbsd/board.c +++ b/pttbbs/mbbsd/board.c @@ -1,4 +1,4 @@ -/* $Id: board.c,v 1.8 2002/05/24 16:21:11 ptt Exp $ */ +/* $Id: board.c,v 1.9 2002/05/24 16:34:16 ptt Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -1029,18 +1029,18 @@ static void choose_board(int newflag) { } tmp=currutmp->brc_id; currutmp->brc_id=ptr->bid; + free(nbrd); choose_board(0); currmode = currmodetmp; /* 離開版版後就把權限拿掉喔 */ num=tmp1; class_bid = bidtmp; currutmp->brc_id=tmp; brdnum = -1; - free(nbrd); } } } } while(ch != 'q'); - if(nbrd) free(nbrd); + free(nbrd); } int root_board() { -- cgit v1.2.3 From 261cd43dfd8c9c579c1e1485f71424694d9d214c Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Fri, 24 May 2002 16:40:30 +0000 Subject: namecomplete return the position git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@197 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/include/proto.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pttbbs/include/proto.h b/pttbbs/include/proto.h index 6d2c3049..444c58d2 100644 --- a/pttbbs/include/proto.h +++ b/pttbbs/include/proto.h @@ -1,4 +1,4 @@ -/* $Id: proto.h,v 1.16 2002/05/24 15:52:22 ptt Exp $ */ +/* $Id: proto.h,v 1.17 2002/05/24 16:40:30 in2 Exp $ */ #ifndef INCLUDE_PROTO_H #define INCLUDE_PROTO_H @@ -297,9 +297,9 @@ void ShowNameList(int row, int column, char *prompt); int RemoveNameList(char *name); void ToggleNameList(int *reciper, char *listfile, char *msg); void allboardcomplete(char *prompt, char *data, int len); -void generalnamecomplete(char *prompt, char *data, int len, size_t nmemb, - int (*compar)(int, char *, int), - int (*permission)(int), char* (*getname)(int)); +int generalnamecomplete(char *prompt, char *data, int len, size_t nmemb, + int (*compar)(int, char *, int), + int (*permission)(int), char* (*getname)(int)); int completeboard_compar(int where, char *str, int len); int completeboard_permission(int where); char *completeboard_getname(int where); -- cgit v1.2.3 From 26bc9f9f78cff26185e8d8afeeb875a69a171e96 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Fri, 24 May 2002 16:45:25 +0000 Subject: r => read_mail git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@198 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/talk.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/pttbbs/mbbsd/talk.c b/pttbbs/mbbsd/talk.c index 09a079c1..1792c772 100644 --- a/pttbbs/mbbsd/talk.c +++ b/pttbbs/mbbsd/talk.c @@ -1,4 +1,4 @@ -/* $Id: talk.c,v 1.38 2002/05/24 16:32:52 in2 Exp $ */ +/* $Id: talk.c,v 1.39 2002/05/24 16:45:25 in2 Exp $ */ #include <stdio.h> #include <string.h> #include <errno.h> @@ -2240,6 +2240,13 @@ static void pickup_user(void) } break; + case 'r': + if( HAS_PERM(PERM_LOGINOK) ){ + m_read(); + redrawall = redraw = 1; + } + break; + default: if( ++looptimes == 10 ) redrawall = redraw = 1; -- cgit v1.2.3 From 7ddd042d58d2b7e5066d7e616747199aee6de8db Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Fri, 24 May 2002 16:45:39 +0000 Subject: no warning git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@199 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/name.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pttbbs/mbbsd/name.c b/pttbbs/mbbsd/name.c index a48c7d32..192ead3d 100644 --- a/pttbbs/mbbsd/name.c +++ b/pttbbs/mbbsd/name.c @@ -1,4 +1,4 @@ -/* $Id: name.c,v 1.5 2002/05/24 16:32:52 in2 Exp $ */ +/* $Id: name.c,v 1.6 2002/05/24 16:45:39 in2 Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -532,7 +532,7 @@ int generalnamecomplete(char *prompt, char *data, int len, size_t nmemb, int (*compar)(int, char *, int), int (*permission)(int), char* (*getname)(int)) { - int x, y, origx, origy, ch, i, morelist = -1, col, ret; + int x, y, origx, origy, ch, i, morelist = -1, col, ret = -1; int start, end, ptr; int clearbot = NA; -- cgit v1.2.3 From 813249d6190f630eb41bb8f977ee46846aac5f9d Mon Sep 17 00:00:00 2001 From: ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Fri, 24 May 2002 17:44:39 +0000 Subject: boardfriend git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@200 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/bbs.c | 12 +++++------- pttbbs/mbbsd/board.c | 45 +++++++++++++++++++++++++++++++++++++++------ 2 files changed, 44 insertions(+), 13 deletions(-) diff --git a/pttbbs/mbbsd/bbs.c b/pttbbs/mbbsd/bbs.c index 602e3bb4..bd37b7d7 100644 --- a/pttbbs/mbbsd/bbs.c +++ b/pttbbs/mbbsd/bbs.c @@ -1,4 +1,4 @@ -/* $Id: bbs.c,v 1.10 2002/05/16 21:54:56 in2 Exp $ */ +/* $Id: bbs.c,v 1.11 2002/05/24 17:44:39 ptt Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -271,8 +271,7 @@ static int do_select(int ent, fileheader_t *fhdr, char *direct) { outs(err_bid); return FULLUPDATE; } - - currutmp->brc_id = currbid; + setutmpbid(currbid); brc_initial(bname); set_board(); @@ -1865,7 +1864,7 @@ int Read() { more(buf, NA); pressanykey(); } - currutmp->brc_id = currbid; + setutmpbid(currbid); setbdir(buf, currboard); curredit &= ~EDIT_MAIL; i_read(READING, buf, readtitle, readdoent, read_comms, @@ -1874,8 +1873,7 @@ int Read() { log_board(currboard, now - usetime); #endif brc_update(); - - currutmp->brc_id =tmpbid; + setutmpbid(tmpbid); currutmp->mode = mode0; currstat = stat0; return 0; @@ -1889,7 +1887,7 @@ void ReadSelect() { currstat = XMODE; if(do_select(0, 0, genbuf) == NEWDIRECT) Read(); - currutmp->brc_id=0; + setutmpbid(0); currutmp->mode = mode0; currstat = stat0; } diff --git a/pttbbs/mbbsd/board.c b/pttbbs/mbbsd/board.c index e5996ec5..af0ee171 100644 --- a/pttbbs/mbbsd/board.c +++ b/pttbbs/mbbsd/board.c @@ -1,4 +1,4 @@ -/* $Id: board.c,v 1.9 2002/05/24 16:34:16 ptt Exp $ */ +/* $Id: board.c,v 1.10 2002/05/24 17:44:39 ptt Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -564,7 +564,7 @@ static void show_brdlist(int head, int clsflag, int newflag) { showtitle("看板列表", BBSName); prints("[←]主選單 [→]閱\讀 [↑↓]選擇 [y]載入 [S]排序 [/]搜尋 " "[TAB]文摘•看板 [h]求助\n" - "\033[7m%-20s 類別 轉信%-31s投票 板 主 \033[m", + "\033[7m%-20s 類別 轉信%-31s人氣 板 主 \033[m", newflag ? "總數 未讀 看 板" : " 編號 看 板", " 中 文 敘 述"); move(b_lines, 0); @@ -607,7 +607,7 @@ static void show_brdlist(int head, int clsflag, int newflag) { } if(class_bid != 1) { prints("%s%-13s\033[m%s%5.5s\033[0;37m%2.2s\033[m" - "%-35.35s%c %.13s", + "%-34.34s%3d%.13s", (ptr->myattr & BRD_FAV)?"\033[1;36m":"", ptr->bh->brdname, color[(unsigned int) @@ -615,7 +615,7 @@ static void show_brdlist(int head, int clsflag, int newflag) { ptr->bh->title[3] + ptr->bh->title[0]) & 07], ptr->bh->title, ptr->bh->title+5, ptr->bh->title+7, (ptr->bh->brdattr & BRD_BAD) ? 'X' : - " ARBCDEFGHI"[ptr->bh->bvote], + ptr->bh->nuser, ptr->bh->BM); refresh(); } else { @@ -672,6 +672,39 @@ static void dozap(int num){ if(!(ptr->myattr & BRD_ZAP) ) check_newpost(ptr); zapbuf[ptr->bid-1] = (ptr->myattr&BRD_ZAP?0:login_start_time); } + +void setutmpbid(int bid) +{ + int id=currutmp->brc_id; + userinfo_t *u; + if(id) + { + u=bcache[id-1].u; + if (brdshm->busystate!=1 && brdshm->busystate_b[id-1]!=1) + { + brdshm->busystate_b[id-1]=1; + for(u; u && u->nextbfriend != (void*)currutmp; u=u->nextbfriend); + if(u) + { + bcache[id-1].nuser--; + u->nextbfriend = currutmp->nextbfriend; + } + brdshm->busystate_b[id-1]=0; + } + } + if(bid) + { + bcache[bid-1].nuser++; + currutmp->nextbfriend=bcache[bid-1].u; + bcache[bid-1].u=(void*)currutmp; + } + else + { + currutmp->nextbfriend=0; + } + currutmp->brc_id=bid; +} + static void choose_board(int newflag) { static int num = 0; boardstat_t *ptr; @@ -1028,13 +1061,13 @@ static void choose_board(int newflag) { pressanykey(); } tmp=currutmp->brc_id; - currutmp->brc_id=ptr->bid; + setutmpbid(ptr->bid); free(nbrd); choose_board(0); currmode = currmodetmp; /* 離開版版後就把權限拿掉喔 */ num=tmp1; class_bid = bidtmp; - currutmp->brc_id=tmp; + setutmpbid(tmp); brdnum = -1; } } -- cgit v1.2.3 From 8b6ac222136bf7c4a38ff06a04ce60f46d5d30f2 Mon Sep 17 00:00:00 2001 From: ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Fri, 24 May 2002 17:48:19 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@201 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/include/pttstruct.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pttbbs/include/pttstruct.h b/pttbbs/include/pttstruct.h index d5849798..c6e309cd 100644 --- a/pttbbs/include/pttstruct.h +++ b/pttbbs/include/pttstruct.h @@ -1,4 +1,4 @@ -/* $Id: pttstruct.h,v 1.8 2002/05/24 15:52:23 ptt Exp $ */ +/* $Id: pttstruct.h,v 1.9 2002/05/24 17:48:19 ptt Exp $ */ #ifndef INCLUDE_STRUCT_H #define INCLUDE_STRUCT_H @@ -229,7 +229,8 @@ typedef struct userinfo_t { int friend_online[MAX_FRIEND]; /* point到線上好友 utmpshm的位置 */ /* 好友比較的cache 前兩個bit是狀態 */ int reject[MAX_REJECT]; - int pad[2]; + void *nextbfriend; /* 用來做版友的linked list */ + int pad; int lock; int friendtotal; /* 好友比較的cache 大小 */ unsigned char msgcount; -- cgit v1.2.3 From 2e49ced7b1cdc4276abdb23ee081c2c7cf973010 Mon Sep 17 00:00:00 2001 From: ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Fri, 24 May 2002 18:16:05 +0000 Subject: brd git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@202 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/board.c | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/pttbbs/mbbsd/board.c b/pttbbs/mbbsd/board.c index af0ee171..4aee2307 100644 --- a/pttbbs/mbbsd/board.c +++ b/pttbbs/mbbsd/board.c @@ -1,4 +1,4 @@ -/* $Id: board.c,v 1.10 2002/05/24 17:44:39 ptt Exp $ */ +/* $Id: board.c,v 1.11 2002/05/24 18:16:05 ptt Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -607,16 +607,22 @@ static void show_brdlist(int head, int clsflag, int newflag) { } if(class_bid != 1) { prints("%s%-13s\033[m%s%5.5s\033[0;37m%2.2s\033[m" - "%-34.34s%3d%.13s", + "%-34.34s", (ptr->myattr & BRD_FAV)?"\033[1;36m":"", ptr->bh->brdname, color[(unsigned int) (ptr->bh->title[1] + ptr->bh->title[2] + ptr->bh->title[3] + ptr->bh->title[0]) & 07], - ptr->bh->title, ptr->bh->title+5, ptr->bh->title+7, - (ptr->bh->brdattr & BRD_BAD) ? 'X' : - ptr->bh->nuser, - ptr->bh->BM); + ptr->bh->title, ptr->bh->title+5, ptr->bh->title+7); + + if (ptr->bh->brdattr & BRD_BAD) + prints(" X "); + else if(ptr->bh->nuser>30) + prints("\033[31mHOT\033[m"); + else if(ptr->bh->nuser) + prints("\033[31m%2d\033[m ",ptr->bh->nuser); + else prints(" %c ", ptr->bh->bvote? " ":"V"); + prints(".13s", ptr->bh->BM); refresh(); } else { prints("%-40.40s %.13s", ptr->bh->title + 7, ptr->bh->BM); @@ -679,11 +685,14 @@ void setutmpbid(int bid) userinfo_t *u; if(id) { - u=bcache[id-1].u; if (brdshm->busystate!=1 && brdshm->busystate_b[id-1]!=1) { brdshm->busystate_b[id-1]=1; - for(u; u && u->nextbfriend != (void*)currutmp; u=u->nextbfriend); + u=bcache[id-1].u; + if(u!=(void*)currutmp) + for(;u && u->nextbfriend != (void*)currutmp; u=u->nextbfriend); + else + bcache[bid-1].u=NULL; if(u) { bcache[id-1].nuser--; -- cgit v1.2.3 From 0736fa7d49b51ef9243fb49eb36c17102a3c0d10 Mon Sep 17 00:00:00 2001 From: ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Fri, 24 May 2002 18:24:22 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@203 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/include/proto.h | 3 ++- pttbbs/mbbsd/board.c | 6 +++--- pttbbs/mbbsd/mbbsd.c | 6 ++---- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/pttbbs/include/proto.h b/pttbbs/include/proto.h index 444c58d2..d80f0adc 100644 --- a/pttbbs/include/proto.h +++ b/pttbbs/include/proto.h @@ -1,4 +1,4 @@ -/* $Id: proto.h,v 1.17 2002/05/24 16:40:30 in2 Exp $ */ +/* $Id: proto.h,v 1.18 2002/05/24 18:24:11 ptt Exp $ */ #ifndef INCLUDE_PROTO_H #define INCLUDE_PROTO_H @@ -53,6 +53,7 @@ int board_etc(); int board_digest(); /* board */ +void setutmpbid(int bid); int brc_unread(char *fname, int bnum, int *blist); int brc_initial(char *boardname); void brc_update(); diff --git a/pttbbs/mbbsd/board.c b/pttbbs/mbbsd/board.c index 4aee2307..31569639 100644 --- a/pttbbs/mbbsd/board.c +++ b/pttbbs/mbbsd/board.c @@ -1,4 +1,4 @@ -/* $Id: board.c,v 1.11 2002/05/24 18:16:05 ptt Exp $ */ +/* $Id: board.c,v 1.12 2002/05/24 18:24:22 ptt Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -621,8 +621,8 @@ static void show_brdlist(int head, int clsflag, int newflag) { prints("\033[31mHOT\033[m"); else if(ptr->bh->nuser) prints("\033[31m%2d\033[m ",ptr->bh->nuser); - else prints(" %c ", ptr->bh->bvote? " ":"V"); - prints(".13s", ptr->bh->BM); + else prints(" %c ", ptr->bh->bvote? ' ':'V'); + prints("%.13s", ptr->bh->BM); refresh(); } else { prints("%-40.40s %.13s", ptr->bh->title + 7, ptr->bh->BM); diff --git a/pttbbs/mbbsd/mbbsd.c b/pttbbs/mbbsd/mbbsd.c index 62fcfa86..e964c2c0 100644 --- a/pttbbs/mbbsd/mbbsd.c +++ b/pttbbs/mbbsd/mbbsd.c @@ -1,4 +1,4 @@ -/* $Id: mbbsd.c,v 1.30 2002/05/24 16:32:31 in2 Exp $ */ +/* $Id: mbbsd.c,v 1.31 2002/05/24 18:24:22 ptt Exp $ */ #include <stdio.h> #include <string.h> #include <stdlib.h> @@ -208,9 +208,6 @@ u_exit (char *mode) close(0); close(1); - /* random sleep to avoid MANY users logout at the same time */ - usleep((int)((float)rand() * 10000000 / RAND_MAX)); - reload_money(); auto_backup (); save_brdbuf(); @@ -220,6 +217,7 @@ u_exit (char *mode) cuser.invisible = currutmp->invisible; cuser.pager = currutmp->pager; cuser.mind = currutmp->mind; + setutmpbid(0); if (!(HAS_PERM (PERM_SYSOP) && HAS_PERM (PERM_DENYPOST)) && !currutmp->invisible ) do_aloha ("<<下站通知>> -- 我走囉!"); -- cgit v1.2.3 From bcf445233900a4807deaf8f501dc07304e112536 Mon Sep 17 00:00:00 2001 From: ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Fri, 24 May 2002 18:34:22 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@204 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/board.c | 4 ++-- pttbbs/mbbsd/cache.c | 13 +++++++++++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/pttbbs/mbbsd/board.c b/pttbbs/mbbsd/board.c index 31569639..4600c095 100644 --- a/pttbbs/mbbsd/board.c +++ b/pttbbs/mbbsd/board.c @@ -1,4 +1,4 @@ -/* $Id: board.c,v 1.12 2002/05/24 18:24:22 ptt Exp $ */ +/* $Id: board.c,v 1.13 2002/05/24 18:34:22 ptt Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -621,7 +621,7 @@ static void show_brdlist(int head, int clsflag, int newflag) { prints("\033[31mHOT\033[m"); else if(ptr->bh->nuser) prints("\033[31m%2d\033[m ",ptr->bh->nuser); - else prints(" %c ", ptr->bh->bvote? ' ':'V'); + else prints(" %c ", ptr->bh->bvote? 'V':' '); prints("%.13s", ptr->bh->BM); refresh(); } else { diff --git a/pttbbs/mbbsd/cache.c b/pttbbs/mbbsd/cache.c index e672ee56..81cc01b0 100644 --- a/pttbbs/mbbsd/cache.c +++ b/pttbbs/mbbsd/cache.c @@ -1,4 +1,4 @@ -/* $Id: cache.c,v 1.27 2002/05/22 15:59:07 in2 Exp $ */ +/* $Id: cache.c,v 1.28 2002/05/24 18:34:22 ptt Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -653,6 +653,8 @@ static void reload_bcache() { sort_bcache(); for(i=0;i<brdshm->number;i++) { + bcache[i].u=NULL; + bcache[i].nuser=0; bcache[i].firstchild[0]=NULL; bcache[i].firstchild[1]=NULL; } @@ -689,15 +691,20 @@ void addbrd_touchcache() } #if !defined(_BBS_UTIL_C_) void reset_board(int bid) { /* Ptt: 這樣就不用老是touch board了 */ - int fd,i; + int fd,i,nuser; + void *u; boardheader_t *bhdr; + if(--bid < 0) return; if(brdshm->busystate || brdshm->busystate_b[bid-1]) { safe_sleep(1); } else { brdshm->busystate_b[bid-1] = 1; + nuser = bcache[bid-1].nuser; + u = bcache[bid-1].u; + bhdr = bcache; bhdr += bid; if((fd = open(fn_board, O_RDONLY)) > 0) { @@ -711,6 +718,8 @@ void reset_board(int bid) { /* Ptt: bcache[i].firstchild[0]=NULL; bcache[i].firstchild[1]=NULL; } + nuser = bcache[bid-1].nuser; + u = bcache[bid-1].u; brdshm->busystate_b[bid-1] = 0; } } -- cgit v1.2.3 From 06d5a0834104883c90ccb5ee50b2f79b73f9d536 Mon Sep 17 00:00:00 2001 From: ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Fri, 24 May 2002 18:42:51 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@205 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/board.c | 8 ++++---- pttbbs/mbbsd/talk.c | 7 +++---- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/pttbbs/mbbsd/board.c b/pttbbs/mbbsd/board.c index 4600c095..e8718ea4 100644 --- a/pttbbs/mbbsd/board.c +++ b/pttbbs/mbbsd/board.c @@ -1,4 +1,4 @@ -/* $Id: board.c,v 1.13 2002/05/24 18:34:22 ptt Exp $ */ +/* $Id: board.c,v 1.14 2002/05/24 18:42:51 ptt Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -618,9 +618,9 @@ static void show_brdlist(int head, int clsflag, int newflag) { if (ptr->bh->brdattr & BRD_BAD) prints(" X "); else if(ptr->bh->nuser>30) - prints("\033[31mHOT\033[m"); - else if(ptr->bh->nuser) - prints("\033[31m%2d\033[m ",ptr->bh->nuser); + prints("\033[1;31mHOT\033[m"); + else if(ptr->bh->nuser>0) + prints("\033[1;31m%2d\033[m ",ptr->bh->nuser); else prints(" %c ", ptr->bh->bvote? 'V':' '); prints("%.13s", ptr->bh->BM); refresh(); diff --git a/pttbbs/mbbsd/talk.c b/pttbbs/mbbsd/talk.c index 1792c772..76069b61 100644 --- a/pttbbs/mbbsd/talk.c +++ b/pttbbs/mbbsd/talk.c @@ -1,4 +1,4 @@ -/* $Id: talk.c,v 1.39 2002/05/24 16:45:25 in2 Exp $ */ +/* $Id: talk.c,v 1.40 2002/05/24 18:42:51 ptt Exp $ */ #include <stdio.h> #include <string.h> #include <errno.h> @@ -47,7 +47,7 @@ extern boardheader_t *bcache; extern userec_t cuser; extern userec_t xuser; extern time_t now; - +extern int currbid; static char *IdleTypeTable[] = { "偶在花呆啦", "情人來電", "覓食中", "拜見周公", "假死狀態", "我在思考" }; @@ -1657,8 +1657,7 @@ static void draw_pickup(int drawall, pickup_t *pickup, int pickup_way, "\033[33m與我為友:%-3d\033[36m板友:%-4d\033[31m壞人:" "%-2d\033[m\n", msg_pickup_way[pickup_way], utmpshm->number, - //ifh_number, hfm_number, bfriends_number, irh_number, - myfriend, friendme, 0, 0); + myfriend, friendme, bcache[currbid-1].nuser, 0); move(3, 0); for( i = 0, ch = page * 20 + 1 ; i < MAXPICKUP ; ++i, ++ch ){ -- cgit v1.2.3 From 6f5027be4860b44881490e8d161dbff2ce333525 Mon Sep 17 00:00:00 2001 From: ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Fri, 24 May 2002 18:56:28 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@206 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/board.c | 4 ++-- pttbbs/mbbsd/talk.c | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/pttbbs/mbbsd/board.c b/pttbbs/mbbsd/board.c index e8718ea4..5c030b4b 100644 --- a/pttbbs/mbbsd/board.c +++ b/pttbbs/mbbsd/board.c @@ -1,4 +1,4 @@ -/* $Id: board.c,v 1.14 2002/05/24 18:42:51 ptt Exp $ */ +/* $Id: board.c,v 1.15 2002/05/24 18:56:28 ptt Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -692,7 +692,7 @@ void setutmpbid(int bid) if(u!=(void*)currutmp) for(;u && u->nextbfriend != (void*)currutmp; u=u->nextbfriend); else - bcache[bid-1].u=NULL; + bcache[id-1].u=NULL; if(u) { bcache[id-1].nuser--; diff --git a/pttbbs/mbbsd/talk.c b/pttbbs/mbbsd/talk.c index 76069b61..e84831d4 100644 --- a/pttbbs/mbbsd/talk.c +++ b/pttbbs/mbbsd/talk.c @@ -1,4 +1,4 @@ -/* $Id: talk.c,v 1.40 2002/05/24 18:42:51 ptt Exp $ */ +/* $Id: talk.c,v 1.41 2002/05/24 18:56:28 ptt Exp $ */ #include <stdio.h> #include <string.h> #include <errno.h> @@ -47,7 +47,6 @@ extern boardheader_t *bcache; extern userec_t cuser; extern userec_t xuser; extern time_t now; -extern int currbid; static char *IdleTypeTable[] = { "偶在花呆啦", "情人來電", "覓食中", "拜見周公", "假死狀態", "我在思考" }; @@ -1657,7 +1656,8 @@ static void draw_pickup(int drawall, pickup_t *pickup, int pickup_way, "\033[33m與我為友:%-3d\033[36m板友:%-4d\033[31m壞人:" "%-2d\033[m\n", msg_pickup_way[pickup_way], utmpshm->number, - myfriend, friendme, bcache[currbid-1].nuser, 0); + myfriend, friendme, + currutmp->brc_id? bcache[currutmp->brc_id-1].nuser, 0); move(3, 0); for( i = 0, ch = page * 20 + 1 ; i < MAXPICKUP ; ++i, ++ch ){ -- cgit v1.2.3 From 0b590beff9a12c1f11d1f2cecb8cf169884de072 Mon Sep 17 00:00:00 2001 From: ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Fri, 24 May 2002 18:57:37 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@207 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/talk.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pttbbs/mbbsd/talk.c b/pttbbs/mbbsd/talk.c index e84831d4..727a6449 100644 --- a/pttbbs/mbbsd/talk.c +++ b/pttbbs/mbbsd/talk.c @@ -1,4 +1,4 @@ -/* $Id: talk.c,v 1.41 2002/05/24 18:56:28 ptt Exp $ */ +/* $Id: talk.c,v 1.42 2002/05/24 18:57:37 ptt Exp $ */ #include <stdio.h> #include <string.h> #include <errno.h> @@ -1657,7 +1657,7 @@ static void draw_pickup(int drawall, pickup_t *pickup, int pickup_way, "%-2d\033[m\n", msg_pickup_way[pickup_way], utmpshm->number, myfriend, friendme, - currutmp->brc_id? bcache[currutmp->brc_id-1].nuser, 0); + currutmp->brc_id? bcache[currutmp->brc_id-1].nuser:0, 0); move(3, 0); for( i = 0, ch = page * 20 + 1 ; i < MAXPICKUP ; ++i, ++ch ){ -- cgit v1.2.3 From 955e6ff2860b22c7c36091dad118d8852b577a26 Mon Sep 17 00:00:00 2001 From: ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Fri, 24 May 2002 19:05:47 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@208 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/board.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/pttbbs/mbbsd/board.c b/pttbbs/mbbsd/board.c index 5c030b4b..58c01601 100644 --- a/pttbbs/mbbsd/board.c +++ b/pttbbs/mbbsd/board.c @@ -1,4 +1,4 @@ -/* $Id: board.c,v 1.15 2002/05/24 18:56:28 ptt Exp $ */ +/* $Id: board.c,v 1.16 2002/05/24 19:05:47 ptt Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -690,14 +690,13 @@ void setutmpbid(int bid) brdshm->busystate_b[id-1]=1; u=bcache[id-1].u; if(u!=(void*)currutmp) + { for(;u && u->nextbfriend != (void*)currutmp; u=u->nextbfriend); + if(u) u->nextbfriend = currutmp->nextbfriend; + } else - bcache[id-1].u=NULL; - if(u) - { - bcache[id-1].nuser--; - u->nextbfriend = currutmp->nextbfriend; - } + bcache[id-1].u=currutmp->nextbfriend; + bcache[id-1].nuser--; brdshm->busystate_b[id-1]=0; } } -- cgit v1.2.3 From 5761b5fb1c5af7eafc792f9c69806fc4f342e4e5 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sat, 25 May 2002 00:51:03 +0000 Subject: fix bug(fast user list) git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@209 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/talk.c | 51 ++++++++++++++++++++++++++++++++++----------------- 1 file changed, 34 insertions(+), 17 deletions(-) diff --git a/pttbbs/mbbsd/talk.c b/pttbbs/mbbsd/talk.c index 727a6449..fd75d620 100644 --- a/pttbbs/mbbsd/talk.c +++ b/pttbbs/mbbsd/talk.c @@ -1,4 +1,4 @@ -/* $Id: talk.c,v 1.42 2002/05/24 18:57:37 ptt Exp $ */ +/* $Id: talk.c,v 1.43 2002/05/25 00:51:03 in2 Exp $ */ #include <stdio.h> #include <string.h> #include <errno.h> @@ -1589,7 +1589,8 @@ static void pickup(pickup_t *currpickup, int pickup_way, int *page, ++got, ++which ){ for( ; which < utmpnumber ; ++which ) - if( isvisible_stat(currutmp, utmp[which], 0) ) + if( currutmp != utmp[which] && + isvisible_stat(currutmp, utmp[which], 0) ) break; if( which == utmpnumber ) break; @@ -1659,8 +1660,9 @@ static void draw_pickup(int drawall, pickup_t *pickup, int pickup_way, myfriend, friendme, currutmp->brc_id? bcache[currutmp->brc_id-1].nuser:0, 0); - move(3, 0); for( i = 0, ch = page * 20 + 1 ; i < MAXPICKUP ; ++i, ++ch ){ + move(i + 3, 0); prints("a"); + move(i + 3, 0); uentp = pickup[i].ui; friend = pickup[i].friend; if( uentp == NULL ){ @@ -1743,6 +1745,8 @@ static void draw_pickup(int drawall, pickup_t *pickup, int pickup_way, "" #endif ); + + refresh(); } } @@ -1758,31 +1762,42 @@ static void pickup_user(void) static int real_name = 0; char genbuf[256]; int page, offset, pickup_way, ch, leave, redraw, redrawall, fri_stat; - int myfriend, friendme, i, looptimes; + int myfriend, friendme, i; + time_t lastupdate; page = offset = 0; pickup_way = 0; leave = 0; redrawall = 1; + /* redraw : 會離開鍵盤處理 loop , 重新 pickup, draw_pickup + (只重畫中間使用者部份) + redrawall : 會重畫所有的部份 (上面的標題列, 下面的說明列等等) + leave : 返回上一選單 + */ while( !leave ){ pickup(currpickup, pickup_way, &page, &myfriend, &friendme); draw_pickup(redrawall, currpickup, pickup_way, page, show_mode, show_uid, show_board, show_pid, real_name, myfriend, friendme); - if( currpickup[offset].ui == NULL ){ - for( ; offset >= 0 ; --offset ) + /* 如果因為換頁的時候, 這一頁有的人數比較少, + (通常都是最後一頁人數不滿的時候) + 那要重新計算 offset 以免指到沒有人的地方 */ + if( offset == -1 || currpickup[offset].ui == NULL ){ + for( offset = (offset == -1 ? MAXPICKUP - 1 : offset ) ; + offset >= 0 ; --offset ) if( currpickup[offset].ui != NULL ) break; if( offset == -1 ){ - --page; + if( --page < 0 ) + page = pickup_maxpages(pickup_way) - 1; offset = 0; continue; } } redraw = redrawall = 0; - looptimes = 0; + lastupdate = now; while( !redraw ){ ch = cursor_key(offset + 3, 0); uentp = currpickup[offset].ui; @@ -1819,6 +1834,7 @@ static void pickup_user(void) case '0': case KEY_HOME: page = offset = 0; + redraw = 1; break; case 'H': @@ -1847,7 +1863,7 @@ static void pickup_user(void) if (!getdata(1, 0, buf, currutmp->from, sizeof(currutmp->from), DOECHO)) strncpy(currutmp->from, fromhost, 23); - redraw = 1; + redrawall = redraw = 1; } break; @@ -1870,7 +1886,7 @@ static void pickup_user(void) if( newpage != page ){ page = newpage; redraw = 1; - } else if( ++looptimes == 10 ) + } else if( now >= lastupdate + 2 ) redrawall = redraw = 1; } break; @@ -1880,7 +1896,7 @@ static void pickup_user(void) if( --offset == -1 ){ offset = MAXPICKUP - 1; if( --page == -1 ) - page = pickup_maxpages(pickup_way); + page = pickup_maxpages(pickup_way) - 1; redraw = 1; } break; @@ -1897,6 +1913,7 @@ static void pickup_user(void) case KEY_END: case '$': page = pickup_maxpages(pickup_way) - 1; + offset = -1; redraw = 1; break; @@ -1977,7 +1994,7 @@ static void pickup_user(void) case 'R': /* 顯示真實姓名 */ if (HAS_PERM(PERM_SYSOP)){ real_name ^= 1; - redraw = 1; + redrawall = redraw = 1; } break; #endif @@ -1985,7 +2002,7 @@ static void pickup_user(void) case 'U': if (HAS_PERM(PERM_SYSOP)){ show_uid ^= 1; - redraw = 1; + redrawall = redraw = 1; } break; #endif @@ -1993,7 +2010,7 @@ static void pickup_user(void) case 'Y': if (HAS_PERM(PERM_SYSOP)){ show_board ^= 1; - redraw = 1; + redrawall = redraw = 1; } break; #endif @@ -2001,7 +2018,7 @@ static void pickup_user(void) case '#': if (HAS_PERM(PERM_SYSOP)){ show_pid ^= 1; - redraw = 1; + redrawall = redraw = 1; } break; #endif @@ -2247,8 +2264,8 @@ static void pickup_user(void) break; default: - if( ++looptimes == 10 ) - redrawall = redraw = 1; + if( now >= lastupdate + 2 ) + redraw = 1; } } } -- cgit v1.2.3 From 4ad73e959938eb77b83cee2b6c26744012092a3f Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sat, 25 May 2002 00:58:13 +0000 Subject: fix bug - dup myself in friend section (fast user list) git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@210 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/talk.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pttbbs/mbbsd/talk.c b/pttbbs/mbbsd/talk.c index fd75d620..cbbbe3df 100644 --- a/pttbbs/mbbsd/talk.c +++ b/pttbbs/mbbsd/talk.c @@ -1,4 +1,4 @@ -/* $Id: talk.c,v 1.43 2002/05/25 00:51:03 in2 Exp $ */ +/* $Id: talk.c,v 1.44 2002/05/25 00:58:13 in2 Exp $ */ #include <stdio.h> #include <string.h> #include <errno.h> @@ -1529,6 +1529,7 @@ static void pickup_myfriend(pickup_t *friends, int *nGots, where = currutmp->friend_online[i] & 0xFFFFFF; if( 0 <= where && where < MAX_ACTIVE && (uentp = &utmpshm->uinfo[where]) && uentp->pid && + uentp != currutmp && isvisible_stat(currutmp, uentp, frstate = currutmp->friend_online[i] >> 24) -- cgit v1.2.3 From d96953d0d6de41ccc3c50a183575c831ebf599a1 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sat, 25 May 2002 01:50:11 +0000 Subject: add common git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@211 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/include/common.h | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/pttbbs/include/common.h b/pttbbs/include/common.h index 333bed8c..a7fe26a6 100644 --- a/pttbbs/include/common.h +++ b/pttbbs/include/common.h @@ -1,4 +1,4 @@ -/* $Id: common.h,v 1.1 2002/03/07 15:13:48 in2 Exp $ */ +/* $Id: common.h,v 1.2 2002/05/25 01:50:11 in2 Exp $ */ #ifndef INCLUDE_COMMON_H #define INCLUDE_COMMON_H @@ -116,12 +116,12 @@ #define YEA 1 /* Booleans (Yep, for true and false) */ #define NA 0 - -#define IRH 1 /* 好友關係 */ -#define HRM 2 -#define IBH 4 -#define IFH 8 -#define HFM 16 +/* 好友關係 */ +#define IRH 1 /* I reject him. */ +#define HRM 2 /* He reject me. */ +#define IBH 4 /* I am board friend of him. */ +#define IFH 8 /* I am friend of him. */ +#define HFM 16 /* He is friend of me. */ #define ST_FRIEND (IBH | IFH | HFM) #define ST_REJECT (IRH | HRM) -- cgit v1.2.3 From a10adab593a04c809e2158c1677df9c4e6cbc16e Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sat, 25 May 2002 03:33:43 +0000 Subject: fix bug - pickup who I reject (fast user list) git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@212 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/talk.c | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/pttbbs/mbbsd/talk.c b/pttbbs/mbbsd/talk.c index cbbbe3df..73637afc 100644 --- a/pttbbs/mbbsd/talk.c +++ b/pttbbs/mbbsd/talk.c @@ -1,4 +1,4 @@ -/* $Id: talk.c,v 1.44 2002/05/25 00:58:13 in2 Exp $ */ +/* $Id: talk.c,v 1.45 2002/05/25 03:33:43 in2 Exp $ */ #include <stdio.h> #include <string.h> #include <errno.h> @@ -1527,12 +1527,13 @@ static void pickup_myfriend(pickup_t *friends, int *nGots, *myfriend = *friendme = 1; for( *nGots = i = 0 ; currutmp->friend_online[i] && i < MAX_FRIEND ; ++i ){ where = currutmp->friend_online[i] & 0xFFFFFF; - if( 0 <= where && where < MAX_ACTIVE && - (uentp = &utmpshm->uinfo[where]) && uentp->pid && - uentp != currutmp && + if( 0 <= where && where < MAX_ACTIVE && + (uentp = &utmpshm->uinfo[where]) && uentp->pid && + uentp != currutmp && isvisible_stat(currutmp, uentp, frstate = - currutmp->friend_online[i] >> 24) + currutmp->friend_online[i] >> 24) && + ( !(frstate & IRH) || ((frstate & IRH) && (frstate & IFH)) ) ){ friends[*nGots].ui = &utmpshm->uinfo[where]; friends[*nGots].uoffset = where; @@ -1751,9 +1752,15 @@ static void draw_pickup(int drawall, pickup_t *pickup, int pickup_way, } } -static void pickup_user(void) +static void userlist(void) { - + /* 使用者名單: + userlist() : main loop + draw_pickup() : show out screen + pickup() : generate THIS PAGE pickup list + pickup_maxpages : return max pages number of all list + pickup_myfriend : pickup friend (from friend_online) and sort + */ pickup_t currpickup[MAXPICKUP]; userinfo_t *uentp; static int show_mode = 0; @@ -2279,7 +2286,7 @@ int t_users(void) int stat0 = currstat; setutmpmode(LUSERS); - pickup_user(); + userlist(); currutmp->mode = mode0; currutmp->destuid = destuid0; currstat = stat0; -- cgit v1.2.3 From d3e3e95f9567e48a8e7c2974843c3f5d6c539039 Mon Sep 17 00:00:00 2001 From: ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sat, 25 May 2002 06:12:12 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@213 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/include/pttstruct.h | 3 ++- pttbbs/mbbsd/board.c | 25 +++++++++++++++++++------ pttbbs/mbbsd/var.c | 4 ++-- 3 files changed, 23 insertions(+), 9 deletions(-) diff --git a/pttbbs/include/pttstruct.h b/pttbbs/include/pttstruct.h index c6e309cd..143a9f60 100644 --- a/pttbbs/include/pttstruct.h +++ b/pttbbs/include/pttstruct.h @@ -1,4 +1,4 @@ -/* $Id: pttstruct.h,v 1.9 2002/05/24 17:48:19 ptt Exp $ */ +/* $Id: pttstruct.h,v 1.10 2002/05/25 06:12:12 ptt Exp $ */ #ifndef INCLUDE_STRUCT_H #define INCLUDE_STRUCT_H @@ -129,6 +129,7 @@ typedef struct boardheader_t { #define BRD_BAD 00400 /* 違法改進中看板 */ #define BRD_VOTEBOARD 01000 /* 連署機看板 */ #define BRD_WARNDEL 02000 /* 已警告要廢除的看板 */ +#define BRD_TOP 04000 /* 熱門看板的群組 設群組板才有用*/ #define TTLEN 64 /* Length of title */ #define FNLEN 33 /* Length of filename */ diff --git a/pttbbs/mbbsd/board.c b/pttbbs/mbbsd/board.c index 58c01601..56ca1f01 100644 --- a/pttbbs/mbbsd/board.c +++ b/pttbbs/mbbsd/board.c @@ -1,4 +1,4 @@ -/* $Id: board.c,v 1.16 2002/05/24 19:05:47 ptt Exp $ */ +/* $Id: board.c,v 1.17 2002/05/25 06:11:38 ptt Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -427,6 +427,10 @@ static boardstat_t * addnewbrdstat(int n, int state) return ptr; } +static int cmpboardname(boardstat_t *brd, boardstat_t *tmp) { + return brd->bh->nuser- tmp->bh->nuser; +} + static void load_boards(char *key) { boardheader_t *bptr = NULL; int type=cuser.uflag & BRDSORT_FLAG?1:0; @@ -440,7 +444,7 @@ static void load_boards(char *key) { load_uidofgid(class_bid,type); } brdnum = 0; - if(class_bid==0) + if(class_bid<=0) { nbrd = (boardstat_t *)malloc(numboards * sizeof(boardstat_t)); for(i=0 ; i < numboards; i++) @@ -452,9 +456,12 @@ static void load_boards(char *key) { !((state = Ben_Perm(bptr)) || (currmode & MODE_MENU)) || (yank_flag == 0 && !(favbuf[n]&BRD_FAV)) || (yank_flag == 1 && !zapbuf[n]) || - (key[0] && !strcasestr(bptr->title, key)) + (key[0] && !strcasestr(bptr->title, key)) || + (class_bid=-1 && !bptr->nuser) ) continue; addnewbrdstat(n, state); + if(class_bid=-1) + qsort(nbrd, brdnum, sizeof(boardstat_t), cmpboardname); } } else @@ -617,10 +624,12 @@ static void show_brdlist(int head, int clsflag, int newflag) { if (ptr->bh->brdattr & BRD_BAD) prints(" X "); - else if(ptr->bh->nuser>30) + else if(ptr->bh->nuser>=100) prints("\033[1;31mHOT\033[m"); - else if(ptr->bh->nuser>0) + else if(ptr->bh->nuser>50) prints("\033[1;31m%2d\033[m ",ptr->bh->nuser); + else if(ptr->bh->nuser>0) + prints("\033[1;33m%2d\033[m ",ptr->bh->nuser); else prints(" %c ", ptr->bh->bvote? 'V':' '); prints("%.13s", ptr->bh->BM); refresh(); @@ -1059,7 +1068,11 @@ static void choose_board(int newflag) { currmodetmp =currmode; tmp1=num; num=0; - class_bid = ptr->bid; + if(!(ptr->bh->brdattr & BRD_TOP)) + class_bid = ptr->bid; + else + class_bid = -1; /* 熱門群組用 */ + if (!(currmode & MODE_MENU))/*如果還沒有小組長權限 */ set_menu_BM(ptr->bh->BM); diff --git a/pttbbs/mbbsd/var.c b/pttbbs/mbbsd/var.c index 866ce063..ff2febf0 100644 --- a/pttbbs/mbbsd/var.c +++ b/pttbbs/mbbsd/var.c @@ -1,4 +1,4 @@ -/* $Id: var.c,v 1.3 2002/05/14 15:08:48 ptt Exp $ */ +/* $Id: var.c,v 1.4 2002/05/25 06:11:38 ptt Exp $ */ #include <stdio.h> #include <sys/types.h> #include "config.h" @@ -51,7 +51,7 @@ char *str_permboard[] = { "預設匿名版", /* BRD_DEFAULTANONYMOUS */ "違法改進中看版", /* BRD_BAD */ "連署專用看版", /* BRD_VOTEBOARD */ - "沒想到", + "熱門看板群組", /* BRD_TOP */ "沒想到", "沒想到", "沒想到", -- cgit v1.2.3 From bda7cd6313067905e36da0469b1328f93d4c3565 Mon Sep 17 00:00:00 2001 From: ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sat, 25 May 2002 06:16:34 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@214 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/board.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pttbbs/mbbsd/board.c b/pttbbs/mbbsd/board.c index 56ca1f01..4eafe913 100644 --- a/pttbbs/mbbsd/board.c +++ b/pttbbs/mbbsd/board.c @@ -1,4 +1,4 @@ -/* $Id: board.c,v 1.17 2002/05/25 06:11:38 ptt Exp $ */ +/* $Id: board.c,v 1.18 2002/05/25 06:16:34 ptt Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -457,7 +457,7 @@ static void load_boards(char *key) { (yank_flag == 0 && !(favbuf[n]&BRD_FAV)) || (yank_flag == 1 && !zapbuf[n]) || (key[0] && !strcasestr(bptr->title, key)) || - (class_bid=-1 && !bptr->nuser) + (class_bid==-1 && bptr->nuser<5) ) continue; addnewbrdstat(n, state); if(class_bid=-1) -- cgit v1.2.3 From cb779cd43d68b4f55ab9d29d8c8d3d3c6ba67fd7 Mon Sep 17 00:00:00 2001 From: ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sat, 25 May 2002 06:18:09 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@215 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/board.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pttbbs/mbbsd/board.c b/pttbbs/mbbsd/board.c index 4eafe913..44014b93 100644 --- a/pttbbs/mbbsd/board.c +++ b/pttbbs/mbbsd/board.c @@ -1,4 +1,4 @@ -/* $Id: board.c,v 1.18 2002/05/25 06:16:34 ptt Exp $ */ +/* $Id: board.c,v 1.19 2002/05/25 06:18:09 ptt Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -460,7 +460,7 @@ static void load_boards(char *key) { (class_bid==-1 && bptr->nuser<5) ) continue; addnewbrdstat(n, state); - if(class_bid=-1) + if(class_bid==-1) qsort(nbrd, brdnum, sizeof(boardstat_t), cmpboardname); } } -- cgit v1.2.3 From d4326fa47e769714096c5d7048c38c31e2be8616 Mon Sep 17 00:00:00 2001 From: ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sat, 25 May 2002 06:28:21 +0000 Subject: hot board complete git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@216 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/board.c | 4 ++-- pttbbs/mbbsd/var.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pttbbs/mbbsd/board.c b/pttbbs/mbbsd/board.c index 44014b93..2d774033 100644 --- a/pttbbs/mbbsd/board.c +++ b/pttbbs/mbbsd/board.c @@ -1,4 +1,4 @@ -/* $Id: board.c,v 1.19 2002/05/25 06:18:09 ptt Exp $ */ +/* $Id: board.c,v 1.20 2002/05/25 06:28:21 ptt Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -428,7 +428,7 @@ static boardstat_t * addnewbrdstat(int n, int state) } static int cmpboardname(boardstat_t *brd, boardstat_t *tmp) { - return brd->bh->nuser- tmp->bh->nuser; + return tmp->bh->nuser - brd->bh->nuser; } static void load_boards(char *key) { diff --git a/pttbbs/mbbsd/var.c b/pttbbs/mbbsd/var.c index ff2febf0..e7fbb118 100644 --- a/pttbbs/mbbsd/var.c +++ b/pttbbs/mbbsd/var.c @@ -1,4 +1,4 @@ -/* $Id: var.c,v 1.4 2002/05/25 06:11:38 ptt Exp $ */ +/* $Id: var.c,v 1.5 2002/05/25 06:28:21 ptt Exp $ */ #include <stdio.h> #include <sys/types.h> #include "config.h" @@ -51,8 +51,8 @@ char *str_permboard[] = { "預設匿名版", /* BRD_DEFAULTANONYMOUS */ "違法改進中看版", /* BRD_BAD */ "連署專用看版", /* BRD_VOTEBOARD */ + "已警告要廢除", /* BRD_WARNEL */ "熱門看板群組", /* BRD_TOP */ - "沒想到", "沒想到", "沒想到", "沒想到", -- cgit v1.2.3 From 95269029c3db4502977c48cb12660852bf902a44 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sat, 25 May 2002 06:59:50 +0000 Subject: fix bug - return from my_query (fast user list) git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@217 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/talk.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pttbbs/mbbsd/talk.c b/pttbbs/mbbsd/talk.c index 73637afc..5d070193 100644 --- a/pttbbs/mbbsd/talk.c +++ b/pttbbs/mbbsd/talk.c @@ -1,4 +1,4 @@ -/* $Id: talk.c,v 1.45 2002/05/25 03:33:43 in2 Exp $ */ +/* $Id: talk.c,v 1.46 2002/05/25 06:59:50 in2 Exp $ */ #include <stdio.h> #include <string.h> #include <errno.h> @@ -2217,6 +2217,7 @@ static void userlist(void) case 'q': strcpy(currauthor, uentp->userid); my_query(uentp->userid); + setutmpmode(LUSERS); redrawall = redraw = 1; break; -- cgit v1.2.3 From bec708212e580f8908ca23edd65efd5248fe5ac6 Mon Sep 17 00:00:00 2001 From: ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sat, 25 May 2002 09:33:22 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@218 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/board.c | 4 ++-- pttbbs/mbbsd/vote.c | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/pttbbs/mbbsd/board.c b/pttbbs/mbbsd/board.c index 2d774033..910322d8 100644 --- a/pttbbs/mbbsd/board.c +++ b/pttbbs/mbbsd/board.c @@ -1,4 +1,4 @@ -/* $Id: board.c,v 1.20 2002/05/25 06:28:21 ptt Exp $ */ +/* $Id: board.c,v 1.21 2002/05/25 09:33:22 ptt Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -705,7 +705,7 @@ void setutmpbid(int bid) } else bcache[id-1].u=currutmp->nextbfriend; - bcache[id-1].nuser--; + if(bcache[id-1].nuser>0) bcache[id-1].nuser--; brdshm->busystate_b[id-1]=0; } } diff --git a/pttbbs/mbbsd/vote.c b/pttbbs/mbbsd/vote.c index ca288481..f25a6a2b 100644 --- a/pttbbs/mbbsd/vote.c +++ b/pttbbs/mbbsd/vote.c @@ -1,4 +1,4 @@ -/* $Id: vote.c,v 1.7 2002/05/13 03:20:04 ptt Exp $ */ +/* $Id: vote.c,v 1.8 2002/05/25 09:33:22 ptt Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -648,7 +648,7 @@ static int vote_maintain(char *bname) { move(0,0); prints("第 %d 號投票\n", x); setbfile(buf, bname, STR_new_title); - getdata(4, 0, "請輸入投票名稱", inbuf, sizeof(inbuf), LCECHO); + getdata(4, 0, "請輸入投票名稱:", inbuf, 50, LCECHO); if(inbuf[0]=='\0') strcpy(inbuf,"不知名的"); fp = fopen(buf, "w"); @@ -701,7 +701,7 @@ static int vote_maintain(char *bname) { while(!aborted) { sprintf(buf, "%c) ", num + 'A'); getdata((num % 15) + 2, (num / 15) * 40, buf, - inbuf, sizeof(inbuf), DOECHO); + inbuf, 50, DOECHO); if(*inbuf) { fprintf(fp, "%1c) %s\n", (num+'A'), inbuf); num++; -- cgit v1.2.3 From e38a6062b55373420f13461d30135ccbfc904257 Mon Sep 17 00:00:00 2001 From: ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sat, 25 May 2002 11:17:55 +0000 Subject: remode savemode git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@219 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/BM_money.c | 3 +-- pttbbs/util/birth.c | 1 - pttbbs/util/buildAnnounce.c | 1 - pttbbs/util/deluserfile.c | 5 ++--- pttbbs/util/initbbs.c | 3 +-- pttbbs/util/jungo.c | 1 - pttbbs/util/openticket.c | 3 +-- pttbbs/util/parse_news.c | 3 +-- pttbbs/util/smtest.c | 1 - pttbbs/util/toplazyBBM.c | 1 - pttbbs/util/toplazyBM.c | 1 - 11 files changed, 6 insertions(+), 17 deletions(-) diff --git a/pttbbs/util/BM_money.c b/pttbbs/util/BM_money.c index c275b1eb..a20dc5e3 100644 --- a/pttbbs/util/BM_money.c +++ b/pttbbs/util/BM_money.c @@ -1,4 +1,4 @@ -/* $Id: BM_money.c,v 1.2 2002/03/09 17:44:30 in2 Exp $ */ +/* $Id: BM_money.c,v 1.3 2002/05/25 11:17:55 ptt Exp $ */ /* 給版主錢的程式 */ @@ -104,7 +104,6 @@ int main() { strcpy(mymail.owner, "[薪水袋]"); sprintf(mymail.title, "\033[32m %s \033[m版的薪水 $\033[33m%d\033![m", bptr->brdname, FUNCTION / nBM); - mymail.savemode = 0; unlink(genbuf); Link(BBSHOME "/etc/BM_money", genbuf); sprintf(genbuf, BBSHOME "/home/%c/%s/.DIR", ch[0], ch); diff --git a/pttbbs/util/birth.c b/pttbbs/util/birth.c index 43840386..89033830 100644 --- a/pttbbs/util/birth.c +++ b/pttbbs/util/birth.c @@ -79,7 +79,6 @@ int main(argc, argv) stampfile(genbuf, &mymail); strcpy(mymail.owner, BBSNAME); strcpy(mymail.title, "!! 生日快樂 !!"); - mymail.savemode = 0; unlink(genbuf); Link(BBSHOME "/etc/Welcome_birth", genbuf); sprintf(genbuf, BBSHOME "/home/%c/%s/.DIR", cuser.userid[0], cuser.userid); diff --git a/pttbbs/util/buildAnnounce.c b/pttbbs/util/buildAnnounce.c index 7de62615..cd4b9877 100644 --- a/pttbbs/util/buildAnnounce.c +++ b/pttbbs/util/buildAnnounce.c @@ -62,7 +62,6 @@ void buildchilds(int level,char *path,int gid) strcpy(item.owner,ptr->BM); strtok(item.owner,"/"); sprintf(item.title,"%-13.13s %-32.32s", level?ptr->brdname:"", ptr->title+7); - item.savemode = 'D'; item.filemode = 0 ; sprintf(item.filename,ptr->brdname); sprintf(newpath,"%s/.DIR",path); diff --git a/pttbbs/util/deluserfile.c b/pttbbs/util/deluserfile.c index 63cfefba..3cf226bb 100644 --- a/pttbbs/util/deluserfile.c +++ b/pttbbs/util/deluserfile.c @@ -1,4 +1,4 @@ -/* $Id: deluserfile.c,v 1.1 2002/03/07 15:13:45 in2 Exp $ */ +/* $Id: deluserfile.c,v 1.2 2002/05/25 11:17:55 ptt Exp $ */ /* 自動砍user目錄檔案程式 */ #include <stdio.h> @@ -61,8 +61,7 @@ void del_file(char *userid) fileheader_t mymail; stampfile(buf, &mymail); - mymail.savemode = 'H'; /* hold-mail flag */ - mymail.filemode = FILE_READ; + mymail.filemode = FILE_READ|FILE_HOLD; strcpy(mymail.owner, userid); strcpy(mymail.title, "熱線記錄"); sprintf(buf1, BBSHOME "/home/%c/%s/writelog", diff --git a/pttbbs/util/initbbs.c b/pttbbs/util/initbbs.c index deab2c8b..f88daf92 100644 --- a/pttbbs/util/initbbs.c +++ b/pttbbs/util/initbbs.c @@ -1,4 +1,4 @@ -/* $Id: initbbs.c,v 1.3 2002/04/05 14:36:25 in2 Exp $ */ +/* $Id: initbbs.c,v 1.4 2002/05/25 11:17:55 ptt Exp $ */ #include <stdio.h> #include <string.h> #include <stdlib.h> @@ -153,7 +153,6 @@ static void initMan() { struct tm *tm = localtime(&t); memset(&f, 0, sizeof(f)); - f.savemode = 0; strcpy(f.owner, "SYSOP"); sprintf(f.date, "%2d/%02d", tm->tm_mon + 1, tm->tm_mday); f.money = 0; diff --git a/pttbbs/util/jungo.c b/pttbbs/util/jungo.c index 8bc4b3a2..8a46f22a 100644 --- a/pttbbs/util/jungo.c +++ b/pttbbs/util/jungo.c @@ -187,7 +187,6 @@ int main(int argc, char *argv[]) sprintf(mymail.title, "\033[32m [小組長免職通知] \033[m %s BM %s", lostbms[i].title, lostbms[i].bmname); } - mymail.savemode = 0 ; unlink(genbuf); if(lostdays <= 60){ LINK(OUTFILE, genbuf); diff --git a/pttbbs/util/openticket.c b/pttbbs/util/openticket.c index 8a5798b1..250d2238 100644 --- a/pttbbs/util/openticket.c +++ b/pttbbs/util/openticket.c @@ -1,4 +1,4 @@ -/* $Id: openticket.c,v 1.2 2002/03/09 17:44:30 in2 Exp $ */ +/* $Id: openticket.c,v 1.3 2002/05/25 11:17:55 ptt Exp $ */ /* 開獎的 utility */ #include <stdio.h> #include <stdlib.h> @@ -184,7 +184,6 @@ int main() stampfile(genbuf, &mymail); strcpy(mymail.owner, BBSNAME); sprintf(mymail.title, "[%s] 中獎囉! $ %d", Cdatelite(&now), money * num); - mymail.savemode = 0; unlink(genbuf); Link(BBSHOME "/etc/ticket", genbuf); sprintf(genbuf, BBSHOME "/home/%c/%s/.DIR", userid[0], userid); diff --git a/pttbbs/util/parse_news.c b/pttbbs/util/parse_news.c index fc24a2d6..18fcd654 100644 --- a/pttbbs/util/parse_news.c +++ b/pttbbs/util/parse_news.c @@ -1,4 +1,4 @@ -/* $Id: parse_news.c,v 1.2 2002/03/09 17:29:20 in2 Exp $ */ +/* $Id: parse_news.c,v 1.3 2002/05/25 11:17:55 ptt Exp $ */ #include <stdio.h> #include <string.h> #include <stdlib.h> @@ -53,7 +53,6 @@ int main() { stampfile(buf, &news); sprintf(news.title, "中央社即時新聞 %s", fh.date); strcpy(news.owner, "CNA-News."); - news.savemode = 0; if (!(fp = fopen(buf, "w"))) return (0); fprintf(fp, " ───────── 中央社即時新聞 (%s)──────────\n", diff --git a/pttbbs/util/smtest.c b/pttbbs/util/smtest.c index 7657762f..9059c419 100644 --- a/pttbbs/util/smtest.c +++ b/pttbbs/util/smtest.c @@ -100,7 +100,6 @@ void mailtouser(char *bmname, char *bname, int zf) sprintf(mymail.title,"\033[32m [廢版通知] " "\033[m %s版(BM:%s)",bname, bmname); } - mymail.savemode = 0 ; unlink(genbuf); if(zf == 0){ LINK(WARNFILE, genbuf); diff --git a/pttbbs/util/toplazyBBM.c b/pttbbs/util/toplazyBBM.c index 5b2f18f3..1341c17a 100644 --- a/pttbbs/util/toplazyBBM.c +++ b/pttbbs/util/toplazyBBM.c @@ -188,7 +188,6 @@ int main(int argc, char *argv[]) sprintf(mymail.title, "\033[32m [小組長免職通知] \033[m %s BM %s", lostbms[i].title, lostbms[i].bmname); } - mymail.savemode = 0 ; unlink(genbuf); if(lostdays <= 30){ LINK(OUTFILE, genbuf); diff --git a/pttbbs/util/toplazyBM.c b/pttbbs/util/toplazyBM.c index e5e8637b..0aba0560 100644 --- a/pttbbs/util/toplazyBM.c +++ b/pttbbs/util/toplazyBM.c @@ -195,7 +195,6 @@ int main(int argc, char *argv[]) sprintf(mymail.title, "\033[32m [版主免職通知] \033[m %s BM %s", lostbms[i].title, lostbms[i].bmname); } - mymail.savemode = 0 ; unlink(genbuf); if(lostdays <= 60){ LINK(OUTFILE, genbuf); -- cgit v1.2.3 From 70d44f7a08201e4addbf2d104e9f4b33b4b6bf41 Mon Sep 17 00:00:00 2001 From: ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sat, 25 May 2002 11:18:11 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@220 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/innbbsd/receive_article.c | 3 +-- pttbbs/mbbsd/admin.c | 4 +--- pttbbs/mbbsd/announce.c | 3 +-- pttbbs/mbbsd/bbs.c | 23 ++++++----------------- pttbbs/mbbsd/cal.c | 3 +-- pttbbs/mbbsd/chat.c | 5 ++--- pttbbs/mbbsd/gomo.c | 5 ++--- pttbbs/mbbsd/lovepaper.c | 3 +-- pttbbs/mbbsd/mail.c | 18 +++++------------- pttbbs/mbbsd/page.c | 3 +-- pttbbs/mbbsd/talk.c | 8 +++----- pttbbs/mbbsd/voteboard.c | 3 +-- pttbbs/mbbsd/xyz.c | 3 +-- 13 files changed, 26 insertions(+), 58 deletions(-) diff --git a/pttbbs/innbbsd/receive_article.c b/pttbbs/innbbsd/receive_article.c index d036fe41..0c2827da 100644 --- a/pttbbs/innbbsd/receive_article.c +++ b/pttbbs/innbbsd/receive_article.c @@ -862,7 +862,7 @@ char *pathname, *firstpath; strcpy(&userid[IDLEN], "."); strcpy(header.owner, userid); strncpy(header.title, subject, TTLEN); - header.savemode = 'M'; + header.filemode |= FILE_MULTI; { struct tm *ptime; ptime = localtime(&datevalue); @@ -907,7 +907,6 @@ cancelpost(fileheader_t *fhdr, char* boardname) stampfile(fn2, &postfile); memcpy(postfile.owner, fhdr->owner, IDLEN + TTLEN + 10); - postfile.savemode = 'D'; close(fd); Rename(fpath, fn2); strcpy(strrchr(fn2, '/') + 1, ".DIR"); diff --git a/pttbbs/mbbsd/admin.c b/pttbbs/mbbsd/admin.c index 8397234d..1712d7e4 100644 --- a/pttbbs/mbbsd/admin.c +++ b/pttbbs/mbbsd/admin.c @@ -1,4 +1,4 @@ -/* $Id: admin.c,v 1.14 2002/05/21 05:04:14 lwms Exp $ */ +/* $Id: admin.c,v 1.15 2002/05/25 11:18:11 ptt Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -880,7 +880,6 @@ int scan_register_form(char *regfile, int automode, int neednum) { stampfile(buf1, &mhdr); strcpy(mhdr.owner, cuser.userid); strncpy(mhdr.title, "[註冊失敗]", TTLEN); - mhdr.savemode = 0; mhdr.filemode = 0; sethomedir(title, muser.userid); if(append_record(title, &mhdr, sizeof(mhdr)) != -1) { @@ -955,7 +954,6 @@ int scan_register_form(char *regfile, int automode, int neednum) { stampfile(xfpath, &xfile); strcpy(xfile.owner, "系統"); strcpy(xfile.title, "[報告] 審核記錄"); - xfile.savemode = 'S'; xptr = fopen(xfpath, "w"); fprintf(xptr, "\n時間:%s %s 審了 %d 份註冊單\n diff --git a/pttbbs/mbbsd/announce.c b/pttbbs/mbbsd/announce.c index 0de45055..a31dc6c2 100644 --- a/pttbbs/mbbsd/announce.c +++ b/pttbbs/mbbsd/announce.c @@ -1,4 +1,4 @@ -/* $Id: announce.c,v 1.8 2002/05/13 03:20:04 ptt Exp $ */ +/* $Id: announce.c,v 1.9 2002/05/25 11:18:11 ptt Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -1121,7 +1121,6 @@ static void a_delete(menu_t *pm) { stampfile(buf, &backup); strcpy(backup.owner, cuser.userid); strcpy(backup.title,pm->header[pm->now - pm->page].title + 2); - backup.savemode = 'D'; sprintf(cmd, "mv -f %s %s", fpath,buf); system(cmd); diff --git a/pttbbs/mbbsd/bbs.c b/pttbbs/mbbsd/bbs.c index bd37b7d7..5e4ebff4 100644 --- a/pttbbs/mbbsd/bbs.c +++ b/pttbbs/mbbsd/bbs.c @@ -1,4 +1,4 @@ -/* $Id: bbs.c,v 1.11 2002/05/24 17:44:39 ptt Exp $ */ +/* $Id: bbs.c,v 1.12 2002/05/25 11:18:11 ptt Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -34,7 +34,6 @@ static void mail_by_link(char* owner, char* title, char* path) { stampfile(genbuf, &mymail); strcpy(mymail.owner, owner); sprintf(mymail.title, title); - mymail.savemode = 0; unlink(genbuf); Link(path, genbuf); sprintf(genbuf,BBSHOME"/home/%c/%s/.DIR",cuser.userid[0],cuser.userid); @@ -312,9 +311,7 @@ static void cancelpost(fileheader_t *fh, int by_BM) { setbpath(fn2, brd); stampfile(fn2, &postfile); memcpy(postfile.owner, fh->owner, IDLEN + TTLEN + 10); - postfile.savemode = 'D'; - if(fh->savemode == 'S') { nick[0] = '\0'; while(fgets(genbuf, sizeof(genbuf), fin)) { if (!strncmp(genbuf, str_author1, LEN_AUTHOR1) || @@ -332,7 +329,6 @@ static void cancelpost(fileheader_t *fh, int by_BM) { cuser.userid, nick, fh->title); fclose(fout); } - } fclose(fin); Rename(fn1, fn2); @@ -374,7 +370,6 @@ static void do_unanonymous_post(char* fpath) { Link(fpath, genbuf); strcpy(mhdr.owner, cuser.userid); strcpy(mhdr.title, save_title); - mhdr.savemode = 0; mhdr.filemode = 0; setbdir(title, "UnAnonymous"); append_record(title, &mhdr, sizeof(mhdr)); @@ -490,11 +485,8 @@ static int do_general() { postfile.money = aborted; strcpy(postfile.owner, owner); strcpy(postfile.title, save_title); - if(islocal) { /* local save */ - postfile.savemode = 'L'; + if(islocal) /* local save */ postfile.filemode = FILE_LOCAL; - } else - postfile.savemode = 'S'; setbdir(buf, currboard); if(append_record(buf, &postfile, sizeof(postfile)) != -1) { @@ -524,7 +516,7 @@ static int do_general() { } strcpy(postfile.owner, owner); strcpy(postfile.title, save_title); - postfile.savemode = 'L'; + postfile.filemode = FILE_LOCAL; setbdir(genbuf, ALLPOST); if(append_record(genbuf, &postfile, sizeof(postfile)) != -1) { setbtotal(getbnum(ALLPOST)); @@ -566,7 +558,7 @@ static int do_general() { strcpy(postfile.owner, cuser.userid); strcpy(postfile.title, save_title); - postfile.savemode = 'B';/* both-reply flag */ + postfile.filemode = FILE_BOTH;/* both-reply flag */ sethomedir(genbuf, quote_user); if(append_record(genbuf, &postfile, sizeof(postfile)) == -1) msg = err_uid; @@ -611,7 +603,6 @@ static void do_generalboardreply(fileheader_t *fhdr){ default: strcpy(currtitle, fhdr->title); strcpy(quote_user, fhdr->owner); - quote_file[79] = fhdr->savemode; do_post(); } *quote_file = 0; @@ -794,10 +785,8 @@ static int cross_post(int ent, fileheader_t *fhdr, char *direct) { strcpy(xfile.owner, cuser.userid); strcpy(xfile.title, xtitle); if(genbuf[0] == 'l') { - xfile.savemode = 'L'; xfile.filemode = FILE_LOCAL; - } else - xfile.savemode = 'S'; + } setbfile(fname, currboard, fhdr->filename); // if(ent) { @@ -1662,7 +1651,7 @@ static int good_post(int ent, fileheader_t *fhdr, char *direct) { if(dashf(genbuf)) unlink (genbuf); - digest.savemode = digest.filemode = 0; + digest.filemode = 0; sprintf(genbuf2, "%s%s", buf, fhdr->filename); Link(genbuf2, genbuf); strcpy(ptr, fn_mandex); diff --git a/pttbbs/mbbsd/cal.c b/pttbbs/mbbsd/cal.c index aec3320b..5d80bc47 100644 --- a/pttbbs/mbbsd/cal.c +++ b/pttbbs/mbbsd/cal.c @@ -1,4 +1,4 @@ -/* $Id: cal.c,v 1.11 2002/05/13 03:20:04 ptt Exp $ */ +/* $Id: cal.c,v 1.12 2002/05/25 11:18:11 ptt Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -186,7 +186,6 @@ static int osong(char *defaultid) { strcpy(mail.owner, "點歌機"); sprintf(mail.title, "◇ %s 點給 %s ", (ano[0]=='y')?"匿名者":cuser.userid, destid); - mail.savemode = 0; while(fgets(buf, 200, fp)) { char *po; diff --git a/pttbbs/mbbsd/chat.c b/pttbbs/mbbsd/chat.c index e7e7846a..284403a8 100644 --- a/pttbbs/mbbsd/chat.c +++ b/pttbbs/mbbsd/chat.c @@ -1,4 +1,4 @@ -/* $Id: chat.c,v 1.3 2002/05/13 03:20:04 ptt Exp $ */ +/* $Id: chat.c,v 1.4 2002/05/25 11:18:11 ptt Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -600,8 +600,7 @@ int t_chat() { sethomepath(genbuf, cuser.userid); stampfile(genbuf, &mymail); - mymail.savemode = 'H'; /* hold-mail flag */ - mymail.filemode = FILE_READ; + mymail.filemode = FILE_READ|FILE_HOLD; strcpy(mymail.owner, "[備.忘.錄]"); strcpy(mymail.title, "會議\033[1;33m記錄\033[m"); sethomedir(title, cuser.userid); diff --git a/pttbbs/mbbsd/gomo.c b/pttbbs/mbbsd/gomo.c index 190d6f71..a8174d7f 100644 --- a/pttbbs/mbbsd/gomo.c +++ b/pttbbs/mbbsd/gomo.c @@ -1,4 +1,4 @@ -/* $Id: gomo.c,v 1.3 2002/05/13 03:20:04 ptt Exp $ */ +/* $Id: gomo.c,v 1.4 2002/05/25 11:18:11 ptt Exp $ */ #include <stdio.h> #include <stdlib.h> #include <unistd.h> @@ -85,8 +85,7 @@ static void HO_log(char *user) { sethomepath(buf1, cuser.userid); stampfile(buf1, &mymail); - mymail.savemode = 'H'; /* hold-mail flag */ - mymail.filemode = FILE_READ; + mymail.filemode = FILE_READ|FILE_HOLD; strcpy(mymail.owner, "[備.忘.錄]"); sprintf(mymail.title, "\033[37;41m棋譜\033[m %s VS %s", cuser.userid, user); diff --git a/pttbbs/mbbsd/lovepaper.c b/pttbbs/mbbsd/lovepaper.c index dffdee69..f4b8b56c 100644 --- a/pttbbs/mbbsd/lovepaper.c +++ b/pttbbs/mbbsd/lovepaper.c @@ -1,4 +1,4 @@ -/* $Id: lovepaper.c,v 1.3 2002/05/13 03:20:04 ptt Exp $ */ +/* $Id: lovepaper.c,v 1.4 2002/05/25 11:18:11 ptt Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -109,7 +109,6 @@ int x_love() { Rename(path, buf1); strncpy(mhdr.title, save_title, TTLEN); strcpy(mhdr.owner, cuser.userid); - mhdr.savemode = '\0'; sethomedir(path, receiver ); if(append_record(path, &mhdr, sizeof(mhdr)) == -1) return -1; diff --git a/pttbbs/mbbsd/mail.c b/pttbbs/mbbsd/mail.c index 21871d5c..a67f4002 100644 --- a/pttbbs/mbbsd/mail.c +++ b/pttbbs/mbbsd/mail.c @@ -1,4 +1,4 @@ -/* $Id: mail.c,v 1.8 2002/05/16 21:54:56 in2 Exp $ */ +/* $Id: mail.c,v 1.9 2002/05/25 11:18:11 ptt Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -127,7 +127,6 @@ int mail_id(char* id, char *title, char *filename, char *owner) { return 0; strcpy(mhdr.owner, owner); strncpy(mhdr.title, title, TTLEN); - mhdr.savemode = 0; mhdr.filemode = 0; Link(filename, genbuf); sethomedir(genbuf,id); @@ -223,8 +222,7 @@ static void do_hold_mail(char *fpath, char *receiver, char *holder) { sethomepath(buf, holder); stampfile(buf, &mymail); - mymail.savemode = 'H'; /* hold-mail flag */ - mymail.filemode = FILE_READ; + mymail.filemode = FILE_READ|FILE_HOLD; strcpy(mymail.owner, "[備.忘.錄]"); if(receiver) { sprintf(title, "(%s) %s", receiver, save_title); @@ -314,7 +312,6 @@ int do_send(char *userid, char *title) { stampfile(genbuf, &mhdr); strcpy(mhdr.owner, cuser.userid); strncpy(mhdr.title, save_title, TTLEN); - mhdr.savemode = '\0'; if(vedit(genbuf, YEA, NULL) == -1) { unlink(genbuf); clear(); @@ -547,7 +544,7 @@ static void multi_send(char *title) { strcpy(mymail.owner, cuser.userid); strcpy(mymail.title, save_title); - mymail.savemode = 'M'; /* multi-send flag */ + mymail.filemode |= FILE_MULTI; /* multi-send flag */ sethomedir(genbuf, p->word); if(append_record(genbuf, &mymail, sizeof(mymail)) == -1) outs(err_uid); @@ -562,7 +559,7 @@ static void multi_send(char *title) { } static int multi_reply(int ent, fileheader_t *fhdr, char *direct) { - if(fhdr->savemode != 'M') + if(!(fhdr->filemode&FILE_MULTI) ) return mail_reply(ent, fhdr, direct); stand_title("群組回信"); @@ -626,7 +623,6 @@ int mail_all() { strcpy(mymail.owner, cuser.userid); /*站長 ID*/ strcpy(mymail.title, save_title); - mymail.savemode = 0; sethomedir(genbuf, cuser.userid); if(append_record(genbuf, &mymail, sizeof(mymail)) == -1) @@ -646,7 +642,6 @@ int mail_all() { strcpy(mymail.owner, cuser.userid); strcpy(mymail.title, save_title); - mymail.savemode = 0; /* mymail.filemode |= FILE_MARKED; Ptt 公告改成不會mark */ sethomedir(genbuf, userid); if(append_record(genbuf, &mymail, sizeof(mymail)) == -1) @@ -1160,10 +1155,8 @@ static int mail_cross_post(int ent, fileheader_t *fhdr, char *direct) { strcpy(xfile.owner, cuser.userid); strcpy(xfile.title, xtitle); if(genbuf[0] == 'l') { - xfile.savemode = 'L'; xfile.filemode = FILE_LOCAL; - } else - xfile.savemode = 'S'; + } setuserfile(fname, fhdr->filename); if(ent) { @@ -1648,7 +1641,6 @@ static void mail_justify(userec_t muser) { unlink(buf1); strcpy(mhdr.owner, cuser.userid); strncpy(mhdr.title, "[審核通過]", TTLEN); - mhdr.savemode = 0; mhdr.filemode = 0; if(valid_ident(muser.email) && !invalidaddr(muser.email)) { diff --git a/pttbbs/mbbsd/page.c b/pttbbs/mbbsd/page.c index 5be7762e..05b2f744 100644 --- a/pttbbs/mbbsd/page.c +++ b/pttbbs/mbbsd/page.c @@ -1,4 +1,4 @@ -/* $Id: page.c,v 1.3 2002/04/28 19:35:29 in2 Exp $ */ +/* $Id: page.c,v 1.4 2002/05/25 11:18:11 ptt Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -110,7 +110,6 @@ int main_railway() { stampfile(genbuf, &mhdr); strcpy(mhdr.owner, "Ptt搜尋器"); strncpy(mhdr.title, "火車時刻搜尋結果", TTLEN); - mhdr.savemode = '\0'; sprintf(command,"echo \"from-station=%s&to-station=%s" "&from-time=%02d00&to-time=%02d00&tt=%s&type=%s\" | " diff --git a/pttbbs/mbbsd/talk.c b/pttbbs/mbbsd/talk.c index 5d070193..82ffb0ef 100644 --- a/pttbbs/mbbsd/talk.c +++ b/pttbbs/mbbsd/talk.c @@ -1,4 +1,4 @@ -/* $Id: talk.c,v 1.46 2002/05/25 06:59:50 in2 Exp $ */ +/* $Id: talk.c,v 1.47 2002/05/25 11:18:11 ptt Exp $ */ #include <stdio.h> #include <string.h> #include <errno.h> @@ -820,8 +820,7 @@ int t_display(void) sethomepath(buf, cuser.userid); stampfile(buf, &mymail); - mymail.savemode = 'H'; /* hold-mail flag */ - mymail.filemode = FILE_READ; + mymail.filemode = FILE_READ | FILE_HOLD; strcpy(mymail.owner, "[備.忘.錄]"); strcpy(mymail.title, "熱線\033[37;41m記錄\033[m"); sethomedir(title, cuser.userid); @@ -1105,8 +1104,7 @@ static void do_talk(int fd) sethomepath(genbuf, cuser.userid); stampfile(genbuf, &mymail); - mymail.savemode = 'H'; /* hold-mail flag */ - mymail.filemode = FILE_READ; + mymail.filemode = FILE_READ|FILE_HOLD; strcpy(mymail.owner, "[備.忘.錄]"); sprintf(mymail.title, "對話記錄 \033[1;36m(%s)\033[m", getuserid(currutmp->destuid)); diff --git a/pttbbs/mbbsd/voteboard.c b/pttbbs/mbbsd/voteboard.c index 8b92adb7..f8be3d27 100644 --- a/pttbbs/mbbsd/voteboard.c +++ b/pttbbs/mbbsd/voteboard.c @@ -1,4 +1,4 @@ -/* $Id: voteboard.c,v 1.5 2002/05/13 03:20:04 ptt Exp $ */ +/* $Id: voteboard.c,v 1.6 2002/05/25 11:18:11 ptt Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -442,7 +442,6 @@ int do_voteboard() { fclose(fp); strcpy(votefile.owner, cuser.userid); strcpy(votefile.title, title); - votefile.savemode = 'S'; setbdir(genbuf, currboard); if(append_record(genbuf, &votefile, sizeof(votefile)) != -1) setbtotal(currbid); diff --git a/pttbbs/mbbsd/xyz.c b/pttbbs/mbbsd/xyz.c index d880a178..3754582e 100644 --- a/pttbbs/mbbsd/xyz.c +++ b/pttbbs/mbbsd/xyz.c @@ -1,4 +1,4 @@ -/* $Id: xyz.c,v 1.6 2002/05/14 15:08:48 ptt Exp $ */ +/* $Id: xyz.c,v 1.7 2002/05/25 11:18:11 ptt Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -435,7 +435,6 @@ static int x_archie() { strcpy(mhdr.owner, cuser.userid); sprintf(genbuf2, "Archie 搜尋檔案: %s 結果", genbuf1); strcpy(mhdr.title, genbuf2); - mhdr.savemode = 0; mhdr.filemode = 0; sethomedir(title, cuser.userid); append_record(title, &mhdr, sizeof(mhdr)); -- cgit v1.2.3 From a9de13811dff718dd62fce6e85bdb3b1785ed0ea Mon Sep 17 00:00:00 2001 From: ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sat, 25 May 2002 12:14:32 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@221 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/include/pttstruct.h | 10 ++-- pttbbs/mbbsd/bbs.c | 111 ++++++++++++++++++++------------------------- 2 files changed, 57 insertions(+), 64 deletions(-) diff --git a/pttbbs/include/pttstruct.h b/pttbbs/include/pttstruct.h index 143a9f60..0bc88b42 100644 --- a/pttbbs/include/pttstruct.h +++ b/pttbbs/include/pttstruct.h @@ -1,4 +1,4 @@ -/* $Id: pttstruct.h,v 1.10 2002/05/25 06:12:12 ptt Exp $ */ +/* $Id: pttstruct.h,v 1.11 2002/05/25 12:14:32 ptt Exp $ */ #ifndef INCLUDE_STRUCT_H #define INCLUDE_STRUCT_H @@ -75,7 +75,8 @@ typedef struct userec_t { int mind; char ident[11]; unsigned int uflag2; - char pad[72]; + time_t recommend; + char pad[68]; } userec_t; /* these are flags in userec_t.uflag */ #define SIG_FLAG 0x3 /* signature number, 2 bits */ @@ -138,7 +139,7 @@ typedef struct boardheader_t { typedef struct fileheader_t { char filename[FNLEN]; /* M.9876543210.A */ - char savemode; /* file save mode */ + char recommend; /* important level */ char owner[IDLEN + 2]; /* uid[.] */ char date[6]; /* [02/02] or space(5) */ char title[TTLEN + 1]; @@ -150,9 +151,12 @@ typedef struct fileheader_t { #define FILE_READ 0x1 /* already read : mail only */ #define FILE_MARKED 0x2 /* opus: 0x8 */ #define FILE_DIGEST 0x4 /* digest */ +#define FILE_HOLD 0x8 /* holdmail for mail */ #define FILE_SOLVED 0x10 /* problem solved, sysop only */ #define FILE_HIDE 0x20 /* hild */ #define FILE_BM 0x40 /* BM only */ +#define FILE_BOTH 0x80 /* both replay for mail and board */ +#define FILE_MULTI 0x100 /* multi send for mail */ #define STRLEN 80 /* Length of most string data */ diff --git a/pttbbs/mbbsd/bbs.c b/pttbbs/mbbsd/bbs.c index 5e4ebff4..c087ed4c 100644 --- a/pttbbs/mbbsd/bbs.c +++ b/pttbbs/mbbsd/bbs.c @@ -1,4 +1,4 @@ -/* $Id: bbs.c,v 1.12 2002/05/25 11:18:11 ptt Exp $ */ +/* $Id: bbs.c,v 1.13 2002/05/25 12:13:55 ptt Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -242,6 +242,27 @@ int whereami(int ent, fileheader_t *fhdr, char *direct) { return FULLUPDATE; } +static int substitute_check(fileheader_t *fhdr) +{ + fileheader_t hdr; + char genbuf[100]; + int num=0; + + /* rocker.011018: 串接模式用reference增進效率 */ + if ((currmode & MODE_SELECT) && (fhdr->money & FHR_REFERENCE)) + { + num = fhdr->money & ~FHR_REFERENCE; + setbdir(genbuf, currboard); + get_record(genbuf, &hdr, sizeof (hdr), num); + + /* 再這裡要check一下原來的dir裡面是不是有被人動過... */ + if (strcmp (hdr.filename, fhdr->filename)) + num = getindex(genbuf, fhdr->filename, sizeof(fileheader_t)); + + substitute_record(genbuf, fhdr, sizeof(*fhdr), num); + } + return num; +} static int do_select(int ent, fileheader_t *fhdr, char *direct) { char bname[20]; char bpath[60]; @@ -1076,31 +1097,7 @@ int edit_title(int ent, fileheader_t *fhdr, char *direct) { *fhdr = tmpfhdr; substitute_record(direct, fhdr, sizeof(*fhdr), ent); /* rocker.011018: 這裡應該改成用reference的方式取得原來的檔案 */ -#if 0 - if((currmode & MODE_SELECT)) { - int now; - - setbdir(genbuf, currboard); - now = getindex(genbuf, fhdr->filename, sizeof(fileheader_t)); - substitute_record(genbuf, fhdr, sizeof(*fhdr), now); - } -#else - if ((currmode & MODE_SELECT) && (fhdr->money & FHR_REFERENCE)) - { - fileheader_t hdr; - int num; - - num = fhdr->money & ~FHR_REFERENCE; - setbdir(genbuf, currboard); - get_record(genbuf, &hdr, sizeof (hdr), num); - - /* 再這裡要check一下原來的dir裡面是不是有被人動過... */ - if (strcmp (hdr.filename, fhdr->filename)) - num = getindex(genbuf, fhdr->filename, sizeof(fileheader_t)); - - substitute_record(genbuf, fhdr, sizeof(*fhdr), num); - } -#endif + substitute_check(fhdr); touchdircache(currbid); } return FULLUPDATE; @@ -1120,30 +1117,38 @@ static int solve_post(int ent, fileheader_t * fhdr, char *direct){ return DONOTHING; } +static recommend(int ent, fileheader_t *fhdr, char *direct) { + extern userec_t xuser; + char yn[5]; + if(!HAS_PERM(PERM_LOGINOK) || fhdr->recommend==9 ) return DONOTHING; + if(fhdr->recommend>9 || fhdr->recommend<0 )// 暫時性的code 原來舊有值取消 + fhdr->recommend=0; + + if (getuser(cuser.userid) && + now - xuser.recommend < 60*10 ) + { + outmsg("離上次推薦時間太近囉, 請多花點時間仔細閱讀文章!"); + sleep(1); + return DONOTHING; + } + + getdata(b_lines-1, 0, "確定要推薦(Y/N)?[n] ", yn, 5, DOECHO); + fhdr->recommend++; + cuser.recommend=now; + passwd_update(usernum, &cuser); + substitute_record(direct, fhdr, sizeof(*fhdr), ent); + substitute_check(fhdr); + touchdircache(currbid); + return PART_REDRAW; +} + static int mark_post(int ent, fileheader_t *fhdr, char *direct) { if(!(currmode & MODE_BOARD)) return DONOTHING; fhdr->filemode ^= FILE_MARKED; substitute_record(direct, fhdr, sizeof(*fhdr), ent); - - /* rocker.011018: 串接模式用reference增進效率 */ - if ((currmode & MODE_SELECT) && (fhdr->money & FHR_REFERENCE)) - { - fileheader_t hdr; - char genbuf[100]; - int num; - - num = fhdr->money & ~FHR_REFERENCE; - setbdir(genbuf, currboard); - get_record(genbuf, &hdr, sizeof (hdr), num); - - /* 再這裡要check一下原來的dir裡面是不是有被人動過... */ - if (strcmp (hdr.filename, fhdr->filename)) - num = getindex(genbuf, fhdr->filename, sizeof(fileheader_t)); - - substitute_record(genbuf, fhdr, sizeof(*fhdr), num); - } + substitute_check(fhdr); touchdircache(currbid); return PART_REDRAW; } @@ -1271,13 +1276,6 @@ static int del_post(int ent, fileheader_t *fhdr, char *direct) { delete_file (genbuf, sizeof(fileheader_t), num, cmpfilename); } -#if 0 - { - setbdir(genbuf,currboard); - now=getindex(genbuf,fhdr->filename,sizeof(fileheader_t)); - delete_file (genbuf, sizeof(fileheader_t),now,cmpfilename); - } -#endif cancelpost(fhdr, not_owned); setbtotal(currbid); @@ -1688,16 +1686,6 @@ static int good_post(int ent, fileheader_t *fhdr, char *direct) { substitute_record(genbuf, fhdr, sizeof(*fhdr), num); } -#if 0 - if(currmode & MODE_SELECT) { - int now; - char genbuf[100]; - - setbdir(genbuf, currboard); - now=getindex(genbuf, fhdr->filename, sizeof(fileheader_t)); - substitute_record(genbuf, fhdr, sizeof(*fhdr), now); - } -#endif return PART_REDRAW; } @@ -1813,6 +1801,7 @@ struct onekey_t read_comms[] = { {'i', b_application}, {'o', can_vote_edit}, {'x', cross_post}, + {'X', recommend}, {'h', b_help}, #ifndef NO_GAMBLE {'f', join_gamble}, -- cgit v1.2.3 From 9ddd56100ecec3a737aa9387c7dbaa4c91efad82 Mon Sep 17 00:00:00 2001 From: ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sat, 25 May 2002 12:15:52 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@222 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/bbs.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pttbbs/mbbsd/bbs.c b/pttbbs/mbbsd/bbs.c index c087ed4c..bdb8d06f 100644 --- a/pttbbs/mbbsd/bbs.c +++ b/pttbbs/mbbsd/bbs.c @@ -1,4 +1,4 @@ -/* $Id: bbs.c,v 1.13 2002/05/25 12:13:55 ptt Exp $ */ +/* $Id: bbs.c,v 1.14 2002/05/25 12:15:52 ptt Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -1127,7 +1127,7 @@ static recommend(int ent, fileheader_t *fhdr, char *direct) { if (getuser(cuser.userid) && now - xuser.recommend < 60*10 ) { - outmsg("離上次推薦時間太近囉, 請多花點時間仔細閱讀文章!"); + outmsg("離上次推薦時間太近囉, 請多花點時間仔細閱\讀文章!"); sleep(1); return DONOTHING; } -- cgit v1.2.3 From fab03cee353ac70c9c037427474b45a0c1ccdd02 Mon Sep 17 00:00:00 2001 From: ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sat, 25 May 2002 12:39:37 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@223 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/bbs.c | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/pttbbs/mbbsd/bbs.c b/pttbbs/mbbsd/bbs.c index bdb8d06f..5a67c36f 100644 --- a/pttbbs/mbbsd/bbs.c +++ b/pttbbs/mbbsd/bbs.c @@ -1,4 +1,4 @@ -/* $Id: bbs.c,v 1.14 2002/05/25 12:15:52 ptt Exp $ */ +/* $Id: bbs.c,v 1.15 2002/05/25 12:39:37 ptt Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -190,10 +190,12 @@ static void readdoent(int num, fileheader_t *ent) { strcpy(title + 44, " …"); /* 把多餘的 string 砍掉 */ if(strncmp(currtitle, title, TTLEN)) - prints("%6d %c %-7s%-13.12s%s %s\n", num, type, - ent->date, ent->owner, mark, title); + prints("%6d \033[1;34m%c\033[32m%c\033[m %-6s%-13.12s%s %s\n", num, type, + ent->recommend?ent->recommend+'0':' ', + ent->date, ent->owner, mark, title); else - prints("%6d %c %-7s%-13.12s\033[1;3%cm%s %s\033[m\n", num, type, + prints("%6d \033[1;34m%c\033[32m%c\033[m %-6s%-13.12s\033[1;3%cm%s %s\033[m\n", num, type, + ent->recommend?ent->recommend+'0':' ', ent->date, ent->owner, color, mark, title); } @@ -1117,31 +1119,44 @@ static int solve_post(int ent, fileheader_t * fhdr, char *direct){ return DONOTHING; } -static recommend(int ent, fileheader_t *fhdr, char *direct) { +static int recommend_cancel(int ent, fileheader_t *fhdr, char *direct) { + char yn[5]; + if (!(currmode & MODE_BOARD)) return DONOTHING; + getdata(b_lines-1, 0, "確定要推薦歸零(Y/N)?[n] ", yn, 5, LCECHO); + if(yn[0]!='y') return PART_REDRAW; + fhdr->recommend=0; + + substitute_record(direct, fhdr, sizeof(*fhdr), ent); + substitute_check(fhdr); + touchdircache(currbid); + return PART_REDRAW; +} +static int recommend(int ent, fileheader_t *fhdr, char *direct) { extern userec_t xuser; char yn[5]; if(!HAS_PERM(PERM_LOGINOK) || fhdr->recommend==9 ) return DONOTHING; if(fhdr->recommend>9 || fhdr->recommend<0 )// 暫時性的code 原來舊有值取消 fhdr->recommend=0; - if (getuser(cuser.userid) && + if (!(currmode & MODE_BOARD) && getuser(cuser.userid) && now - xuser.recommend < 60*10 ) { outmsg("離上次推薦時間太近囉, 請多花點時間仔細閱\讀文章!"); sleep(1); - return DONOTHING; + return PART_REDRAW; } - getdata(b_lines-1, 0, "確定要推薦(Y/N)?[n] ", yn, 5, DOECHO); + getdata(b_lines-1, 0, "確定要推薦, 請仔細考慮(Y/N)?[n] ", yn, 5, LCECHO); + if(yn[0]!='y') return PART_REDRAW; fhdr->recommend++; cuser.recommend=now; passwd_update(usernum, &cuser); + substitute_record(direct, fhdr, sizeof(*fhdr), ent); substitute_check(fhdr); touchdircache(currbid); return PART_REDRAW; } - static int mark_post(int ent, fileheader_t *fhdr, char *direct) { if(!(currmode & MODE_BOARD)) return DONOTHING; @@ -1802,6 +1817,7 @@ struct onekey_t read_comms[] = { {'o', can_vote_edit}, {'x', cross_post}, {'X', recommend}, + {'R', recommend_cancel}, {'h', b_help}, #ifndef NO_GAMBLE {'f', join_gamble}, -- cgit v1.2.3 From 0466c36c5d34b9168a0dabd089411a6f9ffc801b Mon Sep 17 00:00:00 2001 From: ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sat, 25 May 2002 12:42:30 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@224 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/bbs.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pttbbs/mbbsd/bbs.c b/pttbbs/mbbsd/bbs.c index 5a67c36f..915daebf 100644 --- a/pttbbs/mbbsd/bbs.c +++ b/pttbbs/mbbsd/bbs.c @@ -1,4 +1,4 @@ -/* $Id: bbs.c,v 1.15 2002/05/25 12:39:37 ptt Exp $ */ +/* $Id: bbs.c,v 1.16 2002/05/25 12:42:30 ptt Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -164,7 +164,7 @@ extern int Tagger(); static void readdoent(int num, fileheader_t *ent) { int type; char *mark, *title, color; - + if(ent->recommend>9 || ent->recommend <0 ) ent->recommend=0; //Ptt:暫時 type = brc_unread(ent->filename,brc_num,brc_list) ? '+' : ' '; if((currmode & MODE_BOARD) && (ent->filemode & FILE_DIGEST)) @@ -190,11 +190,11 @@ static void readdoent(int num, fileheader_t *ent) { strcpy(title + 44, " …"); /* 把多餘的 string 砍掉 */ if(strncmp(currtitle, title, TTLEN)) - prints("%6d \033[1;34m%c\033[32m%c\033[m %-6s%-13.12s%s %s\n", num, type, + prints("%6d %c\033[1;32m%c\033[m %-6s%-13.12s%s %s\n", num, type, ent->recommend?ent->recommend+'0':' ', ent->date, ent->owner, mark, title); else - prints("%6d \033[1;34m%c\033[32m%c\033[m %-6s%-13.12s\033[1;3%cm%s %s\033[m\n", num, type, + prints("%6d %c\033[1;32m%c\033[m %-6s%-13.12s\033[1;3%cm%s %s\033[m\n", num, type, ent->recommend?ent->recommend+'0':' ', ent->date, ent->owner, color, mark, title); } -- cgit v1.2.3 From d338970b007770784f9cf708db1f4987d11ce421 Mon Sep 17 00:00:00 2001 From: ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sat, 25 May 2002 12:48:47 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@225 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/bbs.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/pttbbs/mbbsd/bbs.c b/pttbbs/mbbsd/bbs.c index 915daebf..44f1f7f4 100644 --- a/pttbbs/mbbsd/bbs.c +++ b/pttbbs/mbbsd/bbs.c @@ -1,4 +1,4 @@ -/* $Id: bbs.c,v 1.16 2002/05/25 12:42:30 ptt Exp $ */ +/* $Id: bbs.c,v 1.17 2002/05/25 12:48:47 ptt Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -190,11 +190,11 @@ static void readdoent(int num, fileheader_t *ent) { strcpy(title + 44, " …"); /* 把多餘的 string 砍掉 */ if(strncmp(currtitle, title, TTLEN)) - prints("%6d %c\033[1;32m%c\033[m %-6s%-13.12s%s %s\n", num, type, + prints("%6d %c\033[1;32m%c\033[m%-6s%-13.12s%s %s\n", num, type, ent->recommend?ent->recommend+'0':' ', ent->date, ent->owner, mark, title); else - prints("%6d %c\033[1;32m%c\033[m %-6s%-13.12s\033[1;3%cm%s %s\033[m\n", num, type, + prints("%6d %c\033[1;32m%c\033[m%-6s%-13.12s\033[1;3%cm%s %s\033[m\n", num, type, ent->recommend?ent->recommend+'0':' ', ent->date, ent->owner, color, mark, title); } @@ -1716,7 +1716,7 @@ static char *board_help[] = { "\01進階命令", "(tab)/z 文摘模式/精華區 (a)(A) 找尋作者", "(b/f) 展讀備忘錄/參與賭盤 (?)(/) 找尋標題", - "(V/R) 投票/查詢投票結果 (^W) 我在哪裡可看到看板的分類", + "(V/R) 投票/查詢投票結果 (^W)(X) 我在哪裡/推薦文章", "(x) 轉錄文章到其他看板 (=)/([]<>-+) 找尋首篇文章/主題式閱\讀", #ifdef INTERNET_EMAIL "(F) 文章寄回Internet郵箱 (U) 將文章 uuencode 後寄回郵箱", @@ -1727,7 +1727,7 @@ static char *board_help[] = { "(M/o) 舉行投票/編私投票名單 (m/c/g) 保留文章/選錄精華/文摘", "(D) 刪除一段範圍的文章 (T/B) 重編文章標題/重編看版標題", "(i) 編輯申請入會表格 (t/^D) 標記文章/砍除標記的文章", - "(O) 編輯Post注意事項 (H) 看板隱藏/現身", + "(O) 編輯Post注意事項 (H)/(Y) 看板隱藏/現身 取消推薦文章", NULL }; @@ -1817,7 +1817,7 @@ struct onekey_t read_comms[] = { {'o', can_vote_edit}, {'x', cross_post}, {'X', recommend}, - {'R', recommend_cancel}, + {'Y', recommend_cancel}, {'h', b_help}, #ifndef NO_GAMBLE {'f', join_gamble}, -- cgit v1.2.3 From f2ab0ab88fa95d7daf39140e34417304c37c38e7 Mon Sep 17 00:00:00 2001 From: ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sat, 25 May 2002 14:08:53 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@226 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/bbs.c | 40 ++++++++++++++++++++++++++-------------- 1 file changed, 26 insertions(+), 14 deletions(-) diff --git a/pttbbs/mbbsd/bbs.c b/pttbbs/mbbsd/bbs.c index 44f1f7f4..2d9707d7 100644 --- a/pttbbs/mbbsd/bbs.c +++ b/pttbbs/mbbsd/bbs.c @@ -1,4 +1,4 @@ -/* $Id: bbs.c,v 1.17 2002/05/25 12:48:47 ptt Exp $ */ +/* $Id: bbs.c,v 1.18 2002/05/25 14:08:53 ptt Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -25,6 +25,8 @@ extern userec_t cuser; extern void touchdircache(int bid); extern int TagNum; extern time_t now; +extern char fromhost[]; + static void mail_by_link(char* owner, char* title, char* path) { char genbuf[200]; @@ -437,7 +439,7 @@ static int do_general() { if(currutmp->lastact - last_post_time < 60 * 3) { if(water_counts >= 5) { move(5, 10); - outs("對不起,您的文章太水囉,多思考一下,待會再post吧!"); + outs("對不起,您的文章太水囉,待會再post吧!小秘訣:可用'X'推薦文章"); pressanykey(); return FULLUPDATE; } @@ -1132,9 +1134,10 @@ static int recommend_cancel(int ent, fileheader_t *fhdr, char *direct) { return PART_REDRAW; } static int recommend(int ent, fileheader_t *fhdr, char *direct) { + struct tm *ptime=localtime(&now); extern userec_t xuser; - char yn[5]; - if(!HAS_PERM(PERM_LOGINOK) || fhdr->recommend==9 ) return DONOTHING; + char buf[200],path[200], yn[5]; + if(!HAS_PERM(PERM_LOGINOK)) return DONOTHING; if(fhdr->recommend>9 || fhdr->recommend<0 )// 暫時性的code 原來舊有值取消 fhdr->recommend=0; @@ -1145,16 +1148,25 @@ static int recommend(int ent, fileheader_t *fhdr, char *direct) { sleep(1); return PART_REDRAW; } - - getdata(b_lines-1, 0, "確定要推薦, 請仔細考慮(Y/N)?[n] ", yn, 5, LCECHO); - if(yn[0]!='y') return PART_REDRAW; - fhdr->recommend++; - cuser.recommend=now; - passwd_update(usernum, &cuser); - - substitute_record(direct, fhdr, sizeof(*fhdr), ent); - substitute_check(fhdr); - touchdircache(currbid); + + if(!getdata(b_lines-2, 0, "推薦語:",path,40,DOECHO) || + !getdata(b_lines-1, 0, "確定要推薦, 請仔細考慮(Y/N)?[n] ", yn, 5,LCECHO) + || yn[0]!='y') return PART_REDRAW; + + sprintf(buf,"□ %-15s推薦:%-40.40s 來自: %-20s (%02d/%02d %02d:%02d)\n", + cuser.userid, path, fromhost, + ptime->tm_mon+1,ptime->tm_mday,ptime->tm_hour,ptime->tm_min) ; + setdirpath(path, direct, fhdr->filename); + log_file(path, buf); + if(fhdr->recommend<9) + { + fhdr->recommend++; + cuser.recommend=now; + passwd_update(usernum, &cuser); + substitute_record(direct, fhdr, sizeof(*fhdr), ent); + substitute_check(fhdr); + touchdircache(currbid); + } return PART_REDRAW; } static int mark_post(int ent, fileheader_t *fhdr, char *direct) { -- cgit v1.2.3 From efbbda3ed54430923dcc9561cb87cf403be7e364 Mon Sep 17 00:00:00 2001 From: ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sat, 25 May 2002 14:16:36 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@227 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/bbs.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/pttbbs/mbbsd/bbs.c b/pttbbs/mbbsd/bbs.c index 2d9707d7..f46a5316 100644 --- a/pttbbs/mbbsd/bbs.c +++ b/pttbbs/mbbsd/bbs.c @@ -1,4 +1,4 @@ -/* $Id: bbs.c,v 1.18 2002/05/25 14:08:53 ptt Exp $ */ +/* $Id: bbs.c,v 1.19 2002/05/25 14:16:36 ptt Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -1125,13 +1125,13 @@ static int recommend_cancel(int ent, fileheader_t *fhdr, char *direct) { char yn[5]; if (!(currmode & MODE_BOARD)) return DONOTHING; getdata(b_lines-1, 0, "確定要推薦歸零(Y/N)?[n] ", yn, 5, LCECHO); - if(yn[0]!='y') return PART_REDRAW; + if(yn[0]!='y') return FULLUPDATE; fhdr->recommend=0; substitute_record(direct, fhdr, sizeof(*fhdr), ent); substitute_check(fhdr); touchdircache(currbid); - return PART_REDRAW; + return FULLUPDATE; } static int recommend(int ent, fileheader_t *fhdr, char *direct) { struct tm *ptime=localtime(&now); @@ -1142,18 +1142,18 @@ static int recommend(int ent, fileheader_t *fhdr, char *direct) { fhdr->recommend=0; if (!(currmode & MODE_BOARD) && getuser(cuser.userid) && - now - xuser.recommend < 60*10 ) + now - xuser.recommend < 60 ) { outmsg("離上次推薦時間太近囉, 請多花點時間仔細閱\讀文章!"); sleep(1); - return PART_REDRAW; + return return FULLUPDATE; } if(!getdata(b_lines-2, 0, "推薦語:",path,40,DOECHO) || !getdata(b_lines-1, 0, "確定要推薦, 請仔細考慮(Y/N)?[n] ", yn, 5,LCECHO) || yn[0]!='y') return PART_REDRAW; - sprintf(buf,"□ %-15s推薦:%-40.40s 來自: %-20s (%02d/%02d %02d:%02d)\n", + sprintf(buf,"□ %s推薦:%s 來自: %-20s (%02d/%02d %02d:%02d)\n", cuser.userid, path, fromhost, ptime->tm_mon+1,ptime->tm_mday,ptime->tm_hour,ptime->tm_min) ; setdirpath(path, direct, fhdr->filename); @@ -1167,7 +1167,7 @@ static int recommend(int ent, fileheader_t *fhdr, char *direct) { substitute_check(fhdr); touchdircache(currbid); } - return PART_REDRAW; + return FULLUPDATE; } static int mark_post(int ent, fileheader_t *fhdr, char *direct) { -- cgit v1.2.3 From d9c8fa0a97893f113c0181baf704467c2bff6b40 Mon Sep 17 00:00:00 2001 From: ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sat, 25 May 2002 14:18:23 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@228 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/bbs.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pttbbs/mbbsd/bbs.c b/pttbbs/mbbsd/bbs.c index f46a5316..43deaacf 100644 --- a/pttbbs/mbbsd/bbs.c +++ b/pttbbs/mbbsd/bbs.c @@ -1,4 +1,4 @@ -/* $Id: bbs.c,v 1.19 2002/05/25 14:16:36 ptt Exp $ */ +/* $Id: bbs.c,v 1.20 2002/05/25 14:18:23 ptt Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -1146,7 +1146,7 @@ static int recommend(int ent, fileheader_t *fhdr, char *direct) { { outmsg("離上次推薦時間太近囉, 請多花點時間仔細閱\讀文章!"); sleep(1); - return return FULLUPDATE; + return FULLUPDATE; } if(!getdata(b_lines-2, 0, "推薦語:",path,40,DOECHO) || -- cgit v1.2.3 From 8c02f8304b1f21090b46cb794f05a7853309a220 Mon Sep 17 00:00:00 2001 From: ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sat, 25 May 2002 14:21:26 +0000 Subject: recommend fix git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@229 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/bbs.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/pttbbs/mbbsd/bbs.c b/pttbbs/mbbsd/bbs.c index 43deaacf..5d821315 100644 --- a/pttbbs/mbbsd/bbs.c +++ b/pttbbs/mbbsd/bbs.c @@ -1,4 +1,4 @@ -/* $Id: bbs.c,v 1.20 2002/05/25 14:18:23 ptt Exp $ */ +/* $Id: bbs.c,v 1.21 2002/05/25 14:21:26 ptt Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -1151,9 +1151,10 @@ static int recommend(int ent, fileheader_t *fhdr, char *direct) { if(!getdata(b_lines-2, 0, "推薦語:",path,40,DOECHO) || !getdata(b_lines-1, 0, "確定要推薦, 請仔細考慮(Y/N)?[n] ", yn, 5,LCECHO) - || yn[0]!='y') return PART_REDRAW; + || yn[0]!='y') return FULLUPDATE; - sprintf(buf,"□ %s推薦:%s 來自: %-20s (%02d/%02d %02d:%02d)\n", + sprintf(buf, + "\033[1;33m□ %s推薦:%s\033[m 來自: %-20s (%02d/%02d %02d:%02d)\n", cuser.userid, path, fromhost, ptime->tm_mon+1,ptime->tm_mday,ptime->tm_hour,ptime->tm_min) ; setdirpath(path, direct, fhdr->filename); -- cgit v1.2.3 From a8375eb402aa3845bcdd50e2d3d9b4930adce6bf Mon Sep 17 00:00:00 2001 From: ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sat, 25 May 2002 14:24:25 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@230 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/bbs.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pttbbs/mbbsd/bbs.c b/pttbbs/mbbsd/bbs.c index 5d821315..78d3d4de 100644 --- a/pttbbs/mbbsd/bbs.c +++ b/pttbbs/mbbsd/bbs.c @@ -1,4 +1,4 @@ -/* $Id: bbs.c,v 1.21 2002/05/25 14:21:26 ptt Exp $ */ +/* $Id: bbs.c,v 1.22 2002/05/25 14:24:25 ptt Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -1154,7 +1154,7 @@ static int recommend(int ent, fileheader_t *fhdr, char *direct) { || yn[0]!='y') return FULLUPDATE; sprintf(buf, - "\033[1;33m□ %s推薦:%s\033[m 來自: %-20s (%02d/%02d %02d:%02d)\n", + "\033[1;31m→\033[33m %s推薦:%s\033[m 來自: %s (%02d/%02d %02d:%02d)\n", cuser.userid, path, fromhost, ptime->tm_mon+1,ptime->tm_mday,ptime->tm_hour,ptime->tm_min) ; setdirpath(path, direct, fhdr->filename); -- cgit v1.2.3 From 6220bb59006e506ebe2f96990306c222d6a700db Mon Sep 17 00:00:00 2001 From: ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sat, 25 May 2002 16:34:35 +0000 Subject: ofix dead lock git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@231 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/board.c | 6 +++--- pttbbs/mbbsd/cache.c | 10 +++++----- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/pttbbs/mbbsd/board.c b/pttbbs/mbbsd/board.c index 910322d8..5288fedb 100644 --- a/pttbbs/mbbsd/board.c +++ b/pttbbs/mbbsd/board.c @@ -1,4 +1,4 @@ -/* $Id: board.c,v 1.21 2002/05/25 09:33:22 ptt Exp $ */ +/* $Id: board.c,v 1.22 2002/05/25 16:34:35 ptt Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -694,9 +694,9 @@ void setutmpbid(int bid) userinfo_t *u; if(id) { - if (brdshm->busystate!=1 && brdshm->busystate_b[id-1]!=1) + if (brdshm->busystate!=1 && now-brdshm->busystate_b[id-1]>=10) { - brdshm->busystate_b[id-1]=1; + brdshm->busystate_b[id-1]=now; u=bcache[id-1].u; if(u!=(void*)currutmp) { diff --git a/pttbbs/mbbsd/cache.c b/pttbbs/mbbsd/cache.c index 81cc01b0..4dcb271d 100644 --- a/pttbbs/mbbsd/cache.c +++ b/pttbbs/mbbsd/cache.c @@ -1,4 +1,4 @@ -/* $Id: cache.c,v 1.28 2002/05/24 18:34:22 ptt Exp $ */ +/* $Id: cache.c,v 1.29 2002/05/25 16:34:35 ptt Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -580,9 +580,9 @@ void load_fileheader_cache(int bid, char *direct) { int num=getbtotal(bid); int n = num-DIRCACHESIZE+1; - if (brdshm->busystate!=1 && brdshm->busystate_b[bid-1]!=1) + if (brdshm->busystate!=1 && now-brdshm->busystate_b[bid-1]>=10 ) { - brdshm->busystate_b[bid-1] = 1; + brdshm->busystate_b[bid-1] = now; get_records(direct, brdshm->dircache[bid - 1] , sizeof(fileheader_t),n<1?1:n, DIRCACHESIZE); brdshm->busystate_b[bid-1] = 0; @@ -698,10 +698,10 @@ void reset_board(int bid) { /* Ptt: if(--bid < 0) return; - if(brdshm->busystate || brdshm->busystate_b[bid-1]) { + if(brdshm->busystate || now-brdshm->busystate_b[bid-1]<10 ) { safe_sleep(1); } else { - brdshm->busystate_b[bid-1] = 1; + brdshm->busystate_b[bid-1] = now; nuser = bcache[bid-1].nuser; u = bcache[bid-1].u; -- cgit v1.2.3 From 9a0d367b6ce36dbefaefa6fb646efb1b0ab07871 Mon Sep 17 00:00:00 2001 From: ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sat, 25 May 2002 16:56:33 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@232 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/bbs.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/pttbbs/mbbsd/bbs.c b/pttbbs/mbbsd/bbs.c index 78d3d4de..7c757496 100644 --- a/pttbbs/mbbsd/bbs.c +++ b/pttbbs/mbbsd/bbs.c @@ -1,4 +1,4 @@ -/* $Id: bbs.c,v 1.22 2002/05/25 14:24:25 ptt Exp $ */ +/* $Id: bbs.c,v 1.23 2002/05/25 16:56:33 ptt Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -1144,8 +1144,9 @@ static int recommend(int ent, fileheader_t *fhdr, char *direct) { if (!(currmode & MODE_BOARD) && getuser(cuser.userid) && now - xuser.recommend < 60 ) { - outmsg("離上次推薦時間太近囉, 請多花點時間仔細閱\讀文章!"); - sleep(1); + move(b_lines-1,0); + prints("離上次推薦時間太近囉, 請多花點時間仔細閱\讀文章!"); + pressanykey(); return FULLUPDATE; } -- cgit v1.2.3 From f94c21851c8bef9627b2f1b341b244dc6d3d1157 Mon Sep 17 00:00:00 2001 From: ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sat, 25 May 2002 17:49:48 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@233 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/bbs.c | 19 +++++++++++++------ pttbbs/mbbsd/mail.c | 4 ++-- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/pttbbs/mbbsd/bbs.c b/pttbbs/mbbsd/bbs.c index 7c757496..069751df 100644 --- a/pttbbs/mbbsd/bbs.c +++ b/pttbbs/mbbsd/bbs.c @@ -1,4 +1,4 @@ -/* $Id: bbs.c,v 1.23 2002/05/25 16:56:33 ptt Exp $ */ +/* $Id: bbs.c,v 1.24 2002/05/25 17:49:48 ptt Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -165,7 +165,8 @@ extern int Tagger(); static void readdoent(int num, fileheader_t *ent) { int type; - char *mark, *title, color; + char *mark, *title, color, + special=0; if(ent->recommend>9 || ent->recommend <0 ) ent->recommend=0; //Ptt:暫時 type = brc_unread(ent->filename,brc_num,brc_list) ? '+' : ' '; @@ -191,14 +192,20 @@ static void readdoent(int num, fileheader_t *ent) { if(title[47]) strcpy(title + 44, " …"); /* 把多餘的 string 砍掉 */ + if(title[0]=='[' && title[3]==']' ) special=1; + if(strncmp(currtitle, title, TTLEN)) - prints("%6d %c\033[1;32m%c\033[m%-6s%-13.12s%s %s\n", num, type, + prints("%6d %c\033[1;32m%c\033[m%-6s%-13.12s%s " + "\033[1m%.*s\033[m%s\n", num, type, ent->recommend?ent->recommend+'0':' ', - ent->date, ent->owner, mark, title); + ent->date, ent->owner, mark, + special?6:0, title, special?title+6:title); else - prints("%6d %c\033[1;32m%c\033[m%-6s%-13.12s\033[1;3%cm%s %s\033[m\n", num, type, + prints("%6d %c\033[1;32m%c\033[m%-6s%-13.12s\033[1;3%cm%s " + "%s\033[m\n", num, type, ent->recommend?ent->recommend+'0':' ', - ent->date, ent->owner, color, mark, title); + ent->date, ent->owner, color, mark, + title); } extern char currfile[]; diff --git a/pttbbs/mbbsd/mail.c b/pttbbs/mbbsd/mail.c index a67f4002..9f7da59a 100644 --- a/pttbbs/mbbsd/mail.c +++ b/pttbbs/mbbsd/mail.c @@ -1,4 +1,4 @@ -/* $Id: mail.c,v 1.9 2002/05/25 11:18:11 ptt Exp $ */ +/* $Id: mail.c,v 1.10 2002/05/25 17:49:48 ptt Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -829,7 +829,7 @@ static void mailtitle() { } static void maildoent(int num, fileheader_t *ent) { - char *title, *mark, color, type = "+ Mm"[ent->filemode]; + char *title, *mark, color, type = "+ Mm"[(ent->filemode&3)]; if (TagNum && !Tagger(atoi(ent->filename + 2), 0, TAG_NIN)) type = 'D'; -- cgit v1.2.3 From 8e51f4e8290fffbd185c13054ba7023f9bd641e6 Mon Sep 17 00:00:00 2001 From: ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sat, 25 May 2002 17:52:35 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@234 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/bbs.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pttbbs/mbbsd/bbs.c b/pttbbs/mbbsd/bbs.c index 069751df..afaa7da1 100644 --- a/pttbbs/mbbsd/bbs.c +++ b/pttbbs/mbbsd/bbs.c @@ -1,4 +1,4 @@ -/* $Id: bbs.c,v 1.24 2002/05/25 17:49:48 ptt Exp $ */ +/* $Id: bbs.c,v 1.25 2002/05/25 17:52:35 ptt Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -192,7 +192,7 @@ static void readdoent(int num, fileheader_t *ent) { if(title[47]) strcpy(title + 44, " …"); /* 把多餘的 string 砍掉 */ - if(title[0]=='[' && title[3]==']' ) special=1; + if(title[0]=='[' && title[5]==']' ) special=1; if(strncmp(currtitle, title, TTLEN)) prints("%6d %c\033[1;32m%c\033[m%-6s%-13.12s%s " -- cgit v1.2.3 From 698ef131eb316f125939835a9b88d38b2d39db78 Mon Sep 17 00:00:00 2001 From: ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sat, 25 May 2002 18:13:36 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@235 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/bbs.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/pttbbs/mbbsd/bbs.c b/pttbbs/mbbsd/bbs.c index afaa7da1..318cd08a 100644 --- a/pttbbs/mbbsd/bbs.c +++ b/pttbbs/mbbsd/bbs.c @@ -1,4 +1,4 @@ -/* $Id: bbs.c,v 1.25 2002/05/25 17:52:35 ptt Exp $ */ +/* $Id: bbs.c,v 1.26 2002/05/25 18:13:36 ptt Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -426,7 +426,8 @@ static int do_general() { fileheader_t postfile; char fpath[80], buf[80]; int aborted, defanony, ifuseanony; - char genbuf[200],*owner; + char genbuf[200],*owner, + *ctype[]={"問題","建議","討論","心得","閒聊","公告","情報"}; boardheader_t *bp; int islocal; @@ -468,7 +469,15 @@ static int do_general() { if(quote_file[0]) do_reply_title(20, currtitle); else { - getdata(21, 0, "標題:", save_title, TTLEN, DOECHO); + getdata(21, 0, + "種類:1.問題 2.建議 3.討論 4.心得 5.閒聊 6.公告 7.情報 (1-7或不選)", + save_title,3,LCECHO); + local_article = save_title[0]-'1'; + if(local_article>=0 && local_article<=7) + sprintf(save_title,"[%s]",ctype[local_article]); + else + save_title[0]='\0'; + getdata_buf(22, 0, "標題:", save_title, TTLEN, DOECHO); strip_ansi(save_title,save_title,0); } if(save_title[0] == '\0') -- cgit v1.2.3 From 54010e612cbbbb99fd44d33a1ac29fda4f73c8fc Mon Sep 17 00:00:00 2001 From: ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sat, 25 May 2002 18:16:40 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@236 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/bbs.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pttbbs/mbbsd/bbs.c b/pttbbs/mbbsd/bbs.c index 318cd08a..7e441841 100644 --- a/pttbbs/mbbsd/bbs.c +++ b/pttbbs/mbbsd/bbs.c @@ -1,4 +1,4 @@ -/* $Id: bbs.c,v 1.26 2002/05/25 18:13:36 ptt Exp $ */ +/* $Id: bbs.c,v 1.27 2002/05/25 18:16:40 ptt Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -474,7 +474,7 @@ static int do_general() { save_title,3,LCECHO); local_article = save_title[0]-'1'; if(local_article>=0 && local_article<=7) - sprintf(save_title,"[%s]",ctype[local_article]); + sprintf(save_title,"[%s] ",ctype[local_article]); else save_title[0]='\0'; getdata_buf(22, 0, "標題:", save_title, TTLEN, DOECHO); -- cgit v1.2.3 From 7662e20b1f0d30180c873529f10b23a1fc267b54 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sat, 25 May 2002 20:49:35 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@237 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/UPDATING | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pttbbs/UPDATING b/pttbbs/UPDATING index a5858a03..75812ec4 100644 --- a/pttbbs/UPDATING +++ b/pttbbs/UPDATING @@ -1,3 +1,6 @@ +Sun May 26 04:49:03 CST 2002 + new userlist. + Mon Apr 29 03:33:38 CST 2002: change getdata() constant to sizeof() -- cgit v1.2.3 From c1c7b83782303a8b084f99fe2f7d27b5075bb1d3 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sat, 25 May 2002 21:13:06 +0000 Subject: stop, STOP git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@238 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/bbsctl.c | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/pttbbs/util/bbsctl.c b/pttbbs/util/bbsctl.c index b6a6388f..03a68689 100644 --- a/pttbbs/util/bbsctl.c +++ b/pttbbs/util/bbsctl.c @@ -68,6 +68,35 @@ int startbbs(int argc, char **argv) } int stopbbs(int argc, char **argv) +{ + DIR *dirp; + struct dirent *de; + FILE *fp; + char buf[512], fn[512]; + if( !(dirp = opendir("run")) ){ + perror("open " BBSHOME "/run"); + exit(0); + } + + while( (de = readdir(dirp)) ){ + if( strstr(de->d_name, "mbbsd") && strstr(de->d_name, "pid")){ + sprintf(fn, BBSHOME "/run/%s", de->d_name); + if( (fp = fopen(fn, "r")) != NULL ){ + if( fgets(buf, sizeof(buf), fp) != NULL ){ + printf("stopping listening-mbbsd at pid %5d\n", atoi(buf)); + kill(atoi(buf), 9); + } + fclose(fp); + unlink(fn); + } + } + } + + closedir(dirp); + return 0; +} + +int STOP(int argc, char **argv) { DIR *dirp; struct dirent *de; @@ -83,8 +112,8 @@ int stopbbs(int argc, char **argv) sprintf(buf, "/proc/%s/cmdline", de->d_name); if( (fp = fopen(buf, "r")) ){ if( fgets(buf, sizeof(buf), fp) != NULL ){ - if( strstr(buf, "mbbsd") && strstr(buf, "listening") ){ - kill(atoi(de->d_name), 9); + if( strstr(buf, "mbbsd") ){ + kill(atoi(de->d_name), 1); printf("stopping mbbsd at pid %5d\n", atoi(de->d_name)); } @@ -169,6 +198,7 @@ struct { {bbsadm, "bbsadm", "switch to user: bbsadm"}, {bbstest, "test", "run ./mbbsd as bbsadm"}, {Xipcrm, "ipcrm", "ipcrm all msg, shm, sem"}, + {STOP, "STOP", "killall ALL mbbsd"}, {NULL, NULL, NULL} }; int main(int argc, char **argv) -- cgit v1.2.3 From 4b14963cb7370845b8d3ed7e22613177b6c0e4f0 Mon Sep 17 00:00:00 2001 From: ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sun, 26 May 2002 01:45:06 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@239 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/bbs.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pttbbs/mbbsd/bbs.c b/pttbbs/mbbsd/bbs.c index 7e441841..cea57c3e 100644 --- a/pttbbs/mbbsd/bbs.c +++ b/pttbbs/mbbsd/bbs.c @@ -1,4 +1,4 @@ -/* $Id: bbs.c,v 1.27 2002/05/25 18:16:40 ptt Exp $ */ +/* $Id: bbs.c,v 1.28 2002/05/26 01:45:06 ptt Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -1153,7 +1153,7 @@ static int recommend(int ent, fileheader_t *fhdr, char *direct) { struct tm *ptime=localtime(&now); extern userec_t xuser; char buf[200],path[200], yn[5]; - if(!HAS_PERM(PERM_LOGINOK)) return DONOTHING; + if(!(currmode & MODE_POST)) return DONOTHING; if(fhdr->recommend>9 || fhdr->recommend<0 )// 暫時性的code 原來舊有值取消 fhdr->recommend=0; -- cgit v1.2.3 From 0299e037e2338c711373c4fc63eada6b16becd13 Mon Sep 17 00:00:00 2001 From: ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sun, 26 May 2002 02:08:43 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@240 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/board.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/pttbbs/mbbsd/board.c b/pttbbs/mbbsd/board.c index 5288fedb..f26e21b4 100644 --- a/pttbbs/mbbsd/board.c +++ b/pttbbs/mbbsd/board.c @@ -1,4 +1,4 @@ -/* $Id: board.c,v 1.22 2002/05/25 16:34:35 ptt Exp $ */ +/* $Id: board.c,v 1.23 2002/05/26 02:08:43 ptt Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -625,11 +625,13 @@ static void show_brdlist(int head, int clsflag, int newflag) { if (ptr->bh->brdattr & BRD_BAD) prints(" X "); else if(ptr->bh->nuser>=100) - prints("\033[1;31mHOT\033[m"); + prints("\033[1mHOT\033[m"); else if(ptr->bh->nuser>50) prints("\033[1;31m%2d\033[m ",ptr->bh->nuser); - else if(ptr->bh->nuser>0) + else if(ptr->bh->nuser>10) prints("\033[1;33m%2d\033[m ",ptr->bh->nuser); + else if(ptr->bh->nuser>0) + prints("%2d ",ptr->bh->nuser); else prints(" %c ", ptr->bh->bvote? 'V':' '); prints("%.13s", ptr->bh->BM); refresh(); -- cgit v1.2.3 From e3b2727a52b780afff1fe308822919b333d9a507 Mon Sep 17 00:00:00 2001 From: ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sun, 26 May 2002 02:39:11 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@241 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/bbs.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pttbbs/mbbsd/bbs.c b/pttbbs/mbbsd/bbs.c index cea57c3e..e37f96da 100644 --- a/pttbbs/mbbsd/bbs.c +++ b/pttbbs/mbbsd/bbs.c @@ -1,4 +1,4 @@ -/* $Id: bbs.c,v 1.28 2002/05/26 01:45:06 ptt Exp $ */ +/* $Id: bbs.c,v 1.29 2002/05/26 02:39:11 ptt Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -473,7 +473,7 @@ static int do_general() { "種類:1.問題 2.建議 3.討論 4.心得 5.閒聊 6.公告 7.情報 (1-7或不選)", save_title,3,LCECHO); local_article = save_title[0]-'1'; - if(local_article>=0 && local_article<=7) + if(local_article>=0 && local_article<=6) sprintf(save_title,"[%s] ",ctype[local_article]); else save_title[0]='\0'; -- cgit v1.2.3 From 9eb8709bb7476f61b2dfce71d4051adaf288f522 Mon Sep 17 00:00:00 2001 From: ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sun, 26 May 2002 04:53:19 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@242 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/bbs.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/pttbbs/mbbsd/bbs.c b/pttbbs/mbbsd/bbs.c index e37f96da..31cde584 100644 --- a/pttbbs/mbbsd/bbs.c +++ b/pttbbs/mbbsd/bbs.c @@ -1,4 +1,4 @@ -/* $Id: bbs.c,v 1.29 2002/05/26 02:39:11 ptt Exp $ */ +/* $Id: bbs.c,v 1.30 2002/05/26 04:53:19 ptt Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -1153,7 +1153,8 @@ static int recommend(int ent, fileheader_t *fhdr, char *direct) { struct tm *ptime=localtime(&now); extern userec_t xuser; char buf[200],path[200], yn[5]; - if(!(currmode & MODE_POST)) return DONOTHING; + if(!(currmode & MODE_POST) || !strcmp(fhdr->owner,cuser.userid)) + return DONOTHING; if(fhdr->recommend>9 || fhdr->recommend<0 )// 暫時性的code 原來舊有值取消 fhdr->recommend=0; @@ -1171,7 +1172,7 @@ static int recommend(int ent, fileheader_t *fhdr, char *direct) { || yn[0]!='y') return FULLUPDATE; sprintf(buf, - "\033[1;31m→\033[33m %s推薦:%s\033[m 來自: %s (%02d/%02d %02d:%02d)\n", + "\033[1;31m→\033[33m %s推薦:%s\033[m 來自: %s (%02d/%02d %02d:%02d)\n", cuser.userid, path, fromhost, ptime->tm_mon+1,ptime->tm_mday,ptime->tm_hour,ptime->tm_min) ; setdirpath(path, direct, fhdr->filename); -- cgit v1.2.3 From 0b5ba05a02d070963f3a0a335f6d9322b6aa625a Mon Sep 17 00:00:00 2001 From: ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sun, 26 May 2002 05:14:44 +0000 Subject: recommend fix git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@243 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/bbs.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/pttbbs/mbbsd/bbs.c b/pttbbs/mbbsd/bbs.c index 31cde584..a700654c 100644 --- a/pttbbs/mbbsd/bbs.c +++ b/pttbbs/mbbsd/bbs.c @@ -1,4 +1,4 @@ -/* $Id: bbs.c,v 1.30 2002/05/26 04:53:19 ptt Exp $ */ +/* $Id: bbs.c,v 1.31 2002/05/26 05:14:44 ptt Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -15,12 +15,6 @@ #include "proto.h" extern struct bcache_t *brdshm; -/* -static int g_board_names(boardheader_t *fhdr) { - AddNameList(fhdr->brdname); - return 0; -} -*/ extern userec_t cuser; extern void touchdircache(int bid); extern int TagNum; @@ -1172,9 +1166,10 @@ static int recommend(int ent, fileheader_t *fhdr, char *direct) { || yn[0]!='y') return FULLUPDATE; sprintf(buf, - "\033[1;31m→\033[33m %s推薦:%s\033[m 來自: %s (%02d/%02d %02d:%02d)\n", - cuser.userid, path, fromhost, - ptime->tm_mon+1,ptime->tm_mday,ptime->tm_hour,ptime->tm_min) ; + "\033[1;31m→\033[33m %s推薦:%s\033[m %*s 來自: %s %02d/%02d\n", + cuser.userid, path, + 55-strlen(cuser.userid)-strlen(path), " ",fromhost, + ptime->tm_mon+1,ptime->tm_mday) ; setdirpath(path, direct, fhdr->filename); log_file(path, buf); if(fhdr->recommend<9) -- cgit v1.2.3 From 450c0d75e371de6e06b091f58eaccfba67e7fc25 Mon Sep 17 00:00:00 2001 From: ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sun, 26 May 2002 05:19:20 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@244 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/bbs.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pttbbs/mbbsd/bbs.c b/pttbbs/mbbsd/bbs.c index a700654c..6fb27878 100644 --- a/pttbbs/mbbsd/bbs.c +++ b/pttbbs/mbbsd/bbs.c @@ -1,4 +1,4 @@ -/* $Id: bbs.c,v 1.31 2002/05/26 05:14:44 ptt Exp $ */ +/* $Id: bbs.c,v 1.32 2002/05/26 05:19:20 ptt Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -1166,9 +1166,9 @@ static int recommend(int ent, fileheader_t *fhdr, char *direct) { || yn[0]!='y') return FULLUPDATE; sprintf(buf, - "\033[1;31m→\033[33m %s推薦:%s\033[m %*s 來自: %s %02d/%02d\n", + "\033[1;31m→\033[33m%s\033[m\033[33m:%s\033[m%*s來自: %s %02d/%02d\n", cuser.userid, path, - 55-strlen(cuser.userid)-strlen(path), " ",fromhost, + 45-strlen(cuser.userid)-strlen(path), " ",fromhost, ptime->tm_mon+1,ptime->tm_mday) ; setdirpath(path, direct, fhdr->filename); log_file(path, buf); -- cgit v1.2.3 From 092466af9ec864d8fe161d491db8eb9479363ac3 Mon Sep 17 00:00:00 2001 From: ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sun, 26 May 2002 05:22:46 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@245 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/bbs.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pttbbs/mbbsd/bbs.c b/pttbbs/mbbsd/bbs.c index 6fb27878..fad06d3f 100644 --- a/pttbbs/mbbsd/bbs.c +++ b/pttbbs/mbbsd/bbs.c @@ -1,4 +1,4 @@ -/* $Id: bbs.c,v 1.32 2002/05/26 05:19:20 ptt Exp $ */ +/* $Id: bbs.c,v 1.33 2002/05/26 05:22:46 ptt Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -1166,7 +1166,7 @@ static int recommend(int ent, fileheader_t *fhdr, char *direct) { || yn[0]!='y') return FULLUPDATE; sprintf(buf, - "\033[1;31m→\033[33m%s\033[m\033[33m:%s\033[m%*s來自: %s %02d/%02d\n", + "\033[1;31m→ \033[33m%s\033[m\033[33m:%s\033[m%*s推薦自:%s %02d/%02d\n", cuser.userid, path, 45-strlen(cuser.userid)-strlen(path), " ",fromhost, ptime->tm_mon+1,ptime->tm_mday) ; -- cgit v1.2.3 From dadfa540c8913fc510f4a2bd193a7521ac673ef3 Mon Sep 17 00:00:00 2001 From: ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sun, 26 May 2002 05:31:26 +0000 Subject: recommend fix for junchoon git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@246 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/bbs.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/pttbbs/mbbsd/bbs.c b/pttbbs/mbbsd/bbs.c index fad06d3f..5ad1789d 100644 --- a/pttbbs/mbbsd/bbs.c +++ b/pttbbs/mbbsd/bbs.c @@ -1,4 +1,4 @@ -/* $Id: bbs.c,v 1.33 2002/05/26 05:22:46 ptt Exp $ */ +/* $Id: bbs.c,v 1.34 2002/05/26 05:31:26 ptt Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -1147,8 +1147,17 @@ static int recommend(int ent, fileheader_t *fhdr, char *direct) { struct tm *ptime=localtime(&now); extern userec_t xuser; char buf[200],path[200], yn[5]; - if(!(currmode & MODE_POST) || !strcmp(fhdr->owner,cuser.userid)) - return DONOTHING; + boardheader_t *bp; + bp = getbcache(currbid); + + if(!(currmode & MODE_POST) || !strcmp(fhdr->owner,cuser.userid) || + bp->brdattr & BRD_VOTEBOARD) + { + move(b_lines-1,0); + prints("您因權限不足無法推薦 或 不能推薦自己的文章!"); + pressanykey(); + return FULLUPDATE; + } if(fhdr->recommend>9 || fhdr->recommend<0 )// 暫時性的code 原來舊有值取消 fhdr->recommend=0; -- cgit v1.2.3 From ea6fae093ac0c920592b03d0e9f5cb101b588db3 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Thu, 30 May 2002 10:21:35 +0000 Subject: some hints git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@247 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/user.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/pttbbs/mbbsd/user.c b/pttbbs/mbbsd/user.c index faa50d43..54aa5dee 100644 --- a/pttbbs/mbbsd/user.c +++ b/pttbbs/mbbsd/user.c @@ -1,4 +1,4 @@ -/* $Id: user.c,v 1.18 2002/05/16 21:51:23 in2 Exp $ */ +/* $Id: user.c,v 1.19 2002/05/30 10:21:35 in2 Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -992,7 +992,8 @@ int u_register(void) getfield(5, "請用中文", "真實姓名", rname, 20); }while(!removespace(rname) || rname[0] > 0); do{ - getfield(7, "學校系級或單位職稱", "服務單位", career, 40); + getfield(7, "學校(含\033[1;33m系所\033[m)或單位職稱", + "服務單位", career, 40); }while( !removespace(career) || career[0] > 0 || strlen(career) < 4 ); do{ getfield(9, "包括寢室或門牌號碼", "目前住址", addr, 50); @@ -1000,7 +1001,8 @@ int u_register(void) do{ getfield(11, "包括長途撥號區域碼", "連絡電話", phone, 11); }while( !removespace(phone) || phone[0] != '0' || strlen(phone) < 9 ); - getfield(13, "只輸入數字 如:0912345678", "手機號碼", mobile, 20); + getfield(13, "只輸入數字 如:0912345678 (可不填)", + "手機號碼", mobile, 20); while(1) { int len; -- cgit v1.2.3 From 6291d616d165ad4f014ce02d4121d5f6adb3bb12 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Thu, 30 May 2002 10:58:45 +0000 Subject: register user if he isn't online git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@248 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/admin.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pttbbs/mbbsd/admin.c b/pttbbs/mbbsd/admin.c index 1712d7e4..ec8da78a 100644 --- a/pttbbs/mbbsd/admin.c +++ b/pttbbs/mbbsd/admin.c @@ -1,4 +1,4 @@ -/* $Id: admin.c,v 1.15 2002/05/25 11:18:11 ptt Exp $ */ +/* $Id: admin.c,v 1.16 2002/05/30 10:58:45 in2 Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -795,7 +795,8 @@ int scan_register_form(char *regfile, int automode, int neednum) { if(automode) uid = autoid; - if(!automode || !auto_scan(fdata, ans)) { + if( (!automode || !auto_scan(fdata, ans)) && + search_ulist(unum) == NULL ) { uid = cuser.userid; move(1, 0); -- cgit v1.2.3 From bff9c8b5237593a66626cb50e9ac2b162bf5984f Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Thu, 30 May 2002 12:11:09 +0000 Subject: fix last commit bug git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@249 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/admin.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/pttbbs/mbbsd/admin.c b/pttbbs/mbbsd/admin.c index ec8da78a..96c91b9c 100644 --- a/pttbbs/mbbsd/admin.c +++ b/pttbbs/mbbsd/admin.c @@ -1,4 +1,4 @@ -/* $Id: admin.c,v 1.16 2002/05/30 10:58:45 in2 Exp $ */ +/* $Id: admin.c,v 1.17 2002/05/30 12:11:09 in2 Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -795,8 +795,7 @@ int scan_register_form(char *regfile, int automode, int neednum) { if(automode) uid = autoid; - if( (!automode || !auto_scan(fdata, ans)) && - search_ulist(unum) == NULL ) { + if( (!automode || !auto_scan(fdata, ans)) ) { uid = cuser.userid; move(1, 0); @@ -819,7 +818,10 @@ int scan_register_form(char *regfile, int automode, int neednum) { } else { move(b_lines - 1, 0); prints("是否接受此資料(Y/N/Q/Del/Skip)?[S] "); - ans[0] = igetch(); + if( search_ulist(unum) == NULL ) + ans[0] = igetch(); + else + ans[0] = 's'; if( 'A' <= ans[0] && ans[0] <= 'Z' ) ans[0] += 32; if( ans[0] != 'y' && ans[0] != 'n' && ans[0] != 'q' && -- cgit v1.2.3 From ff6872446fb1133ad905953c2b356e54437de569 Mon Sep 17 00:00:00 2001 From: lwms <lwms@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Thu, 30 May 2002 15:49:11 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@250 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/talk.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pttbbs/mbbsd/talk.c b/pttbbs/mbbsd/talk.c index 82ffb0ef..d31299ec 100644 --- a/pttbbs/mbbsd/talk.c +++ b/pttbbs/mbbsd/talk.c @@ -1,4 +1,4 @@ -/* $Id: talk.c,v 1.47 2002/05/25 11:18:11 ptt Exp $ */ +/* $Id: talk.c,v 1.48 2002/05/30 15:49:11 lwms Exp $ */ #include <stdio.h> #include <string.h> #include <errno.h> @@ -2106,7 +2106,7 @@ static void userlist(void) } getdata(b_lines - 1, 0, "你現在的心情 0:無 q不變 [q]:", genbuf, 3, LCECHO); - if( genbuf[0] && genbuf[0] != 'q' ) + if( genbuf[0] && genbuf[0] != 'q' && atoi(genbuf) > 0) currutmp->mind = atoi(genbuf) % i; break; -- cgit v1.2.3 From bdfcae6e4cda6d130330a425e028b9e0ec9ac9fb Mon Sep 17 00:00:00 2001 From: lwms <lwms@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Thu, 30 May 2002 15:53:28 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@251 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/talk.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pttbbs/mbbsd/talk.c b/pttbbs/mbbsd/talk.c index d31299ec..2ba53be4 100644 --- a/pttbbs/mbbsd/talk.c +++ b/pttbbs/mbbsd/talk.c @@ -1,4 +1,4 @@ -/* $Id: talk.c,v 1.48 2002/05/30 15:49:11 lwms Exp $ */ +/* $Id: talk.c,v 1.49 2002/05/30 15:53:28 lwms Exp $ */ #include <stdio.h> #include <string.h> #include <errno.h> @@ -2106,7 +2106,7 @@ static void userlist(void) } getdata(b_lines - 1, 0, "你現在的心情 0:無 q不變 [q]:", genbuf, 3, LCECHO); - if( genbuf[0] && genbuf[0] != 'q' && atoi(genbuf) > 0) + if( genbuf[0] && genbuf[0] != 'q' && atoi(genbuf) >= 0) currutmp->mind = atoi(genbuf) % i; break; -- cgit v1.2.3 From 94e429ac164a4a06d077a7f6206e29d4cbdf5237 Mon Sep 17 00:00:00 2001 From: ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Thu, 30 May 2002 16:50:50 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@252 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/bbs.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/pttbbs/mbbsd/bbs.c b/pttbbs/mbbsd/bbs.c index 5ad1789d..116f78e9 100644 --- a/pttbbs/mbbsd/bbs.c +++ b/pttbbs/mbbsd/bbs.c @@ -1,4 +1,4 @@ -/* $Id: bbs.c,v 1.34 2002/05/26 05:31:26 ptt Exp $ */ +/* $Id: bbs.c,v 1.35 2002/05/30 16:50:50 ptt Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -186,19 +186,23 @@ static void readdoent(int num, fileheader_t *ent) { if(title[47]) strcpy(title + 44, " …"); /* 把多餘的 string 砍掉 */ - if(title[0]=='[' && title[5]==']' ) special=1; + if(!strncmp(title,"[公告]",6)) special=1; if(strncmp(currtitle, title, TTLEN)) - prints("%6d %c\033[1;32m%c\033[m%-6s%-13.12s%s " + prints("%6d %c\033[1;32m%c\033[m%-6s\033[%d;0m%-13.12s%s\033[m " "\033[1m%.*s\033[m%s\n", num, type, ent->recommend?ent->recommend+'0':' ', - ent->date, ent->owner, mark, + ent->date, + search_ulist (searchuser(ent->owner))? 1:0, + ent->owner, mark, special?6:0, title, special?title+6:title); else - prints("%6d %c\033[1;32m%c\033[m%-6s%-13.12s\033[1;3%cm%s " + prints("%6d %c\033[1;32m%c\033[m%-6s\033[%d;0m%-13.12s\033[1;3%cm%s " "%s\033[m\n", num, type, ent->recommend?ent->recommend+'0':' ', - ent->date, ent->owner, color, mark, + ent->date, + search_ulist (searchuser(ent->owner))? 1:0, + ent->owner, color, mark, title); } -- cgit v1.2.3 From cb1431049dc6d70f42379066dabd12f7f7990ab6 Mon Sep 17 00:00:00 2001 From: ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Thu, 30 May 2002 16:52:14 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@253 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/bbs.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pttbbs/mbbsd/bbs.c b/pttbbs/mbbsd/bbs.c index 116f78e9..d9e8178d 100644 --- a/pttbbs/mbbsd/bbs.c +++ b/pttbbs/mbbsd/bbs.c @@ -1,4 +1,4 @@ -/* $Id: bbs.c,v 1.35 2002/05/30 16:50:50 ptt Exp $ */ +/* $Id: bbs.c,v 1.36 2002/05/30 16:52:14 ptt Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -189,7 +189,7 @@ static void readdoent(int num, fileheader_t *ent) { if(!strncmp(title,"[公告]",6)) special=1; if(strncmp(currtitle, title, TTLEN)) - prints("%6d %c\033[1;32m%c\033[m%-6s\033[%d;0m%-13.12s%s\033[m " + prints("%6d %c\033[1;32m%c\033[m%-6s\033[%dm%-13.12s%s\033[m " "\033[1m%.*s\033[m%s\n", num, type, ent->recommend?ent->recommend+'0':' ', ent->date, @@ -197,7 +197,7 @@ static void readdoent(int num, fileheader_t *ent) { ent->owner, mark, special?6:0, title, special?title+6:title); else - prints("%6d %c\033[1;32m%c\033[m%-6s\033[%d;0m%-13.12s\033[1;3%cm%s " + prints("%6d %c\033[1;32m%c\033[m%-6s\033[%dm%-13.12s\033[1;3%cm%s " "%s\033[m\n", num, type, ent->recommend?ent->recommend+'0':' ', ent->date, -- cgit v1.2.3 From 4b1d6588a37b8b6837bfb5634b2853aebbd346ea Mon Sep 17 00:00:00 2001 From: ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Thu, 30 May 2002 17:00:12 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@254 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/bbs.c | 4 ++-- pttbbs/mbbsd/board.c | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/pttbbs/mbbsd/bbs.c b/pttbbs/mbbsd/bbs.c index d9e8178d..b0fc7db9 100644 --- a/pttbbs/mbbsd/bbs.c +++ b/pttbbs/mbbsd/bbs.c @@ -1,4 +1,4 @@ -/* $Id: bbs.c,v 1.36 2002/05/30 16:52:14 ptt Exp $ */ +/* $Id: bbs.c,v 1.37 2002/05/30 17:00:12 ptt Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -189,7 +189,7 @@ static void readdoent(int num, fileheader_t *ent) { if(!strncmp(title,"[公告]",6)) special=1; if(strncmp(currtitle, title, TTLEN)) - prints("%6d %c\033[1;32m%c\033[m%-6s\033[%dm%-13.12s%s\033[m " + prints("%6d %c\033[1;32m%c\033[m%-6s\033[%dm%-13.12s\033[m%s " "\033[1m%.*s\033[m%s\n", num, type, ent->recommend?ent->recommend+'0':' ', ent->date, diff --git a/pttbbs/mbbsd/board.c b/pttbbs/mbbsd/board.c index f26e21b4..f65faf53 100644 --- a/pttbbs/mbbsd/board.c +++ b/pttbbs/mbbsd/board.c @@ -1,4 +1,4 @@ -/* $Id: board.c,v 1.23 2002/05/26 02:08:43 ptt Exp $ */ +/* $Id: board.c,v 1.24 2002/05/30 17:00:12 ptt Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -1021,9 +1021,9 @@ static void choose_board(int newflag) { } break; case 'W': - if(class_bid > 0 && + if(currutmp->brc_id > 0 && (HAS_PERM(PERM_SYSOP) || (currmode & MODE_MENU))) { - b_note_edit_bname(class_bid); + b_note_edit_bname(currutmp->brc_id); brdnum = -1; } break; -- cgit v1.2.3 From bd829734dfce0d4d327e31e4a39713530793d86b Mon Sep 17 00:00:00 2001 From: ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Thu, 30 May 2002 17:04:59 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@255 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/bbs.c | 7 +++++-- pttbbs/mbbsd/board.c | 6 +++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/pttbbs/mbbsd/bbs.c b/pttbbs/mbbsd/bbs.c index b0fc7db9..ed68b9c1 100644 --- a/pttbbs/mbbsd/bbs.c +++ b/pttbbs/mbbsd/bbs.c @@ -1,4 +1,4 @@ -/* $Id: bbs.c,v 1.37 2002/05/30 17:00:12 ptt Exp $ */ +/* $Id: bbs.c,v 1.38 2002/05/30 17:04:59 ptt Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -1515,7 +1515,10 @@ int b_note_edit_bname(int bid) { char buf[64]; int aborted; boardheader_t *fh=getbcache(bid); - + pressanykey(); +move(10,10); +prints("[[[%d]]]", bid); +pressanykey(); setbfile(buf, fh->brdname, fn_notes); aborted = vedit(buf, NA, NULL); if(aborted == -1) { diff --git a/pttbbs/mbbsd/board.c b/pttbbs/mbbsd/board.c index f65faf53..99c015ec 100644 --- a/pttbbs/mbbsd/board.c +++ b/pttbbs/mbbsd/board.c @@ -1,4 +1,4 @@ -/* $Id: board.c,v 1.24 2002/05/30 17:00:12 ptt Exp $ */ +/* $Id: board.c,v 1.25 2002/05/30 17:04:59 ptt Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -1021,9 +1021,9 @@ static void choose_board(int newflag) { } break; case 'W': - if(currutmp->brc_id > 0 && + if(class_bid > 0 && (HAS_PERM(PERM_SYSOP) || (currmode & MODE_MENU))) { - b_note_edit_bname(currutmp->brc_id); + b_note_edit_bname(class_bid); brdnum = -1; } break; -- cgit v1.2.3 From 77486922c0eedd00c80bdf918ed239b3cccc8a8b Mon Sep 17 00:00:00 2001 From: ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Thu, 30 May 2002 17:37:06 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@256 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/bbs.c | 17 ++++++++++++----- pttbbs/mbbsd/talk.c | 33 +++++++++++++++++++-------------- 2 files changed, 31 insertions(+), 19 deletions(-) diff --git a/pttbbs/mbbsd/bbs.c b/pttbbs/mbbsd/bbs.c index ed68b9c1..f4690469 100644 --- a/pttbbs/mbbsd/bbs.c +++ b/pttbbs/mbbsd/bbs.c @@ -1,4 +1,4 @@ -/* $Id: bbs.c,v 1.38 2002/05/30 17:04:59 ptt Exp $ */ +/* $Id: bbs.c,v 1.39 2002/05/30 17:37:06 ptt Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -676,7 +676,13 @@ int invalid_brdname(char *brd) { } return 0; } - +static int b_call_in(int ent, fileheader_t *fhdr, char *direct) { + userinfo_t *u=search_ulist (searchuser(fhdr->owner)); + if(u && + call_in(u,friend_stat(currutmp, u))) + return FULLUPDATE; + return DONOTHING; +} static void do_reply(fileheader_t *fhdr) { boardheader_t *bp; bp = getbcache(currbid); @@ -1756,10 +1762,10 @@ static char *board_help[] = { "(N)(PgDn) 下移一頁 (##) 跳到 ## 號文章", "(r)(→) 閱\讀此篇文章 ($) 跳到最後一篇文章", "\01進階命令", - "(tab)/z 文摘模式/精華區 (a)(A) 找尋作者", + "(tab)/z 文摘模式/精華區 (a/A)(^Q)找尋作者/作者資料", "(b/f) 展讀備忘錄/參與賭盤 (?)(/) 找尋標題", "(V/R) 投票/查詢投票結果 (^W)(X) 我在哪裡/推薦文章", - "(x) 轉錄文章到其他看板 (=)/([]<>-+) 找尋首篇文章/主題式閱\讀", + "(x)(w) 轉錄文章/丟水球 (=)/([]<>-+) 找尋首篇文章/主題式閱\讀", #ifdef INTERNET_EMAIL "(F) 文章寄回Internet郵箱 (U) 將文章 uuencode 後寄回郵箱", #endif @@ -1853,7 +1859,8 @@ struct onekey_t read_comms[] = { {'B', bh_title_edit}, {'W', b_notes_edit}, {'O', b_post_note}, - {'w', b_water_edit}, + {'K', b_water_edit}, + {'w', b_call_in}, {'v', visable_list_edit}, {'i', b_application}, {'o', can_vote_edit}, diff --git a/pttbbs/mbbsd/talk.c b/pttbbs/mbbsd/talk.c index 2ba53be4..e0cbefea 100644 --- a/pttbbs/mbbsd/talk.c +++ b/pttbbs/mbbsd/talk.c @@ -1,4 +1,4 @@ -/* $Id: talk.c,v 1.49 2002/05/30 15:53:28 lwms Exp $ */ +/* $Id: talk.c,v 1.50 2002/05/30 17:37:06 ptt Exp $ */ #include <stdio.h> #include <string.h> #include <errno.h> @@ -1750,6 +1750,21 @@ static void draw_pickup(int drawall, pickup_t *pickup, int pickup_way, } } +int call_in(userinfo_t *uentp, int fri_stat) +{ + char genbuf[60]; + if( HAS_PERM(PERM_LOGINOK) && + uentp->pid != currpid && + strcmp(uentp->userid, cuser.userid) != 0 && + (HAS_PERM(PERM_SYSOP) || + (uentp->pager != 3 && + (fri_stat & HFM || uentp->pager != 4))) ){ + sprintf(genbuf, "Call-In %s :", uentp->userid); + my_write(uentp->pid, genbuf, uentp->userid, 0, NULL); + return 1; + } + return 0; +} static void userlist(void) { /* 使用者名單: @@ -2040,7 +2055,7 @@ static void userlist(void) *ans == 'n') break; if( HAS_PERM(PERM_SYSOP) ){ - for( i = 0 ; i < utmpshm->number ; ++i ){ + for( i = 0 ; i < utmpshm->number && i<1000 ; ++i ){ uentp = utmpshm->sorted[utmpshm->currsorted][0][i]; if( uentp->pid && kill(uentp->pid, 0) != -1 ) my_write(uentp->pid, genbuf, @@ -2127,19 +2142,9 @@ static void userlist(void) break; case 'w': - if( HAS_PERM(PERM_LOGINOK) && - uentp->pid != currpid && - strcmp(uentp->userid, cuser.userid) != 0 && - (HAS_PERM(PERM_SYSOP) || - (uentp->pager != 3 && - (fri_stat & HFM || uentp->pager != 4))) ){ - cursor_show(offset + 3, 0); - sprintf(genbuf, "Call-In %s :", uentp->userid); - my_write(uentp->pid, genbuf, uentp->userid, 0, NULL); - redrawall = redraw = 1; - } + if(call_in(uentp,fri_stat)) + redrawall = redraw = 1; break; - case 'a': if( HAS_PERM(PERM_LOGINOK) ){ friend_add(uentp->userid, FRIEND_OVERRIDE); -- cgit v1.2.3 From 886918e30e629cd678e479eccd96063335cb839f Mon Sep 17 00:00:00 2001 From: ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Thu, 30 May 2002 17:49:15 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@257 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/bbs.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/pttbbs/mbbsd/bbs.c b/pttbbs/mbbsd/bbs.c index f4690469..75da7945 100644 --- a/pttbbs/mbbsd/bbs.c +++ b/pttbbs/mbbsd/bbs.c @@ -1,4 +1,4 @@ -/* $Id: bbs.c,v 1.39 2002/05/30 17:37:06 ptt Exp $ */ +/* $Id: bbs.c,v 1.40 2002/05/30 17:49:15 ptt Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -1521,10 +1521,6 @@ int b_note_edit_bname(int bid) { char buf[64]; int aborted; boardheader_t *fh=getbcache(bid); - pressanykey(); -move(10,10); -prints("[[[%d]]]", bid); -pressanykey(); setbfile(buf, fh->brdname, fn_notes); aborted = vedit(buf, NA, NULL); if(aborted == -1) { @@ -1771,7 +1767,7 @@ static char *board_help[] = { #endif "(E) 重編文章 (^H) 列出所有的 New Post(s)", "\01板主命令", - "(G) 舉辦賭盤/停止下注/開獎(W/w/v) 編輯備忘錄/水桶名單/可看見名單", + "(G) 舉辦賭盤/停止下注/開獎(W/K/v) 編輯備忘錄/水桶名單/可看見名單", "(M/o) 舉行投票/編私投票名單 (m/c/g) 保留文章/選錄精華/文摘", "(D) 刪除一段範圍的文章 (T/B) 重編文章標題/重編看版標題", "(i) 編輯申請入會表格 (t/^D) 標記文章/砍除標記的文章", -- cgit v1.2.3 From ed50113cc3b2a185e865dbedf34ed0f5aaa5c9eb Mon Sep 17 00:00:00 2001 From: ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Thu, 30 May 2002 17:59:41 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@258 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/board.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pttbbs/mbbsd/board.c b/pttbbs/mbbsd/board.c index 99c015ec..88376c7e 100644 --- a/pttbbs/mbbsd/board.c +++ b/pttbbs/mbbsd/board.c @@ -1,4 +1,4 @@ -/* $Id: board.c,v 1.25 2002/05/30 17:04:59 ptt Exp $ */ +/* $Id: board.c,v 1.26 2002/05/30 17:59:41 ptt Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -1023,6 +1023,9 @@ static void choose_board(int newflag) { case 'W': if(class_bid > 0 && (HAS_PERM(PERM_SYSOP) || (currmode & MODE_MENU))) { + char buf[128]; + setbpath(buf, bcache[class_bid-1].brdname); + mkdir(buf, 0755) ; //Ptt:開群組目錄 b_note_edit_bname(class_bid); brdnum = -1; } -- cgit v1.2.3 From eea6f3367ca3160615e5db41084e557a2b800b8a Mon Sep 17 00:00:00 2001 From: ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Thu, 30 May 2002 18:13:58 +0000 Subject: invisible fix git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@259 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/bbs.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/pttbbs/mbbsd/bbs.c b/pttbbs/mbbsd/bbs.c index 75da7945..0baea631 100644 --- a/pttbbs/mbbsd/bbs.c +++ b/pttbbs/mbbsd/bbs.c @@ -1,4 +1,4 @@ -/* $Id: bbs.c,v 1.40 2002/05/30 17:49:15 ptt Exp $ */ +/* $Id: bbs.c,v 1.41 2002/05/30 18:13:58 ptt Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -159,6 +159,7 @@ extern int Tagger(); static void readdoent(int num, fileheader_t *ent) { int type; + userinfo_t *u; char *mark, *title, color, special=0; if(ent->recommend>9 || ent->recommend <0 ) ent->recommend=0; //Ptt:暫時 @@ -193,7 +194,7 @@ static void readdoent(int num, fileheader_t *ent) { "\033[1m%.*s\033[m%s\n", num, type, ent->recommend?ent->recommend+'0':' ', ent->date, - search_ulist (searchuser(ent->owner))? 1:0, + (u=search_ulist (searchuser(ent->owner)))&&!u->invisible? 1:0, ent->owner, mark, special?6:0, title, special?title+6:title); else @@ -201,7 +202,7 @@ static void readdoent(int num, fileheader_t *ent) { "%s\033[m\n", num, type, ent->recommend?ent->recommend+'0':' ', ent->date, - search_ulist (searchuser(ent->owner))? 1:0, + (u=search_ulist (searchuser(ent->owner)))&&!u->invisible? 1:0, ent->owner, color, mark, title); } -- cgit v1.2.3 From 1f3cb1bf5765b73586916b3d6d13ee7da46d8bec Mon Sep 17 00:00:00 2001 From: ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Thu, 30 May 2002 18:21:04 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@260 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/bbs.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/pttbbs/mbbsd/bbs.c b/pttbbs/mbbsd/bbs.c index 0baea631..047578e1 100644 --- a/pttbbs/mbbsd/bbs.c +++ b/pttbbs/mbbsd/bbs.c @@ -1,4 +1,4 @@ -/* $Id: bbs.c,v 1.41 2002/05/30 18:13:58 ptt Exp $ */ +/* $Id: bbs.c,v 1.42 2002/05/30 18:21:04 ptt Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -161,7 +161,7 @@ static void readdoent(int num, fileheader_t *ent) { int type; userinfo_t *u; char *mark, *title, color, - special=0; + special=0, isonline=0; if(ent->recommend>9 || ent->recommend <0 ) ent->recommend=0; //Ptt:暫時 type = brc_unread(ent->filename,brc_num,brc_list) ? '+' : ' '; @@ -188,13 +188,16 @@ static void readdoent(int num, fileheader_t *ent) { strcpy(title + 44, " …"); /* 把多餘的 string 砍掉 */ if(!strncmp(title,"[公告]",6)) special=1; + if((u=search_ulist (searchuser(ent->owner)))&& + !u->invisible && !PERM_HIDE(u)) + isonline=1; if(strncmp(currtitle, title, TTLEN)) prints("%6d %c\033[1;32m%c\033[m%-6s\033[%dm%-13.12s\033[m%s " "\033[1m%.*s\033[m%s\n", num, type, ent->recommend?ent->recommend+'0':' ', ent->date, - (u=search_ulist (searchuser(ent->owner)))&&!u->invisible? 1:0, + isonline, ent->owner, mark, special?6:0, title, special?title+6:title); else @@ -202,7 +205,7 @@ static void readdoent(int num, fileheader_t *ent) { "%s\033[m\n", num, type, ent->recommend?ent->recommend+'0':' ', ent->date, - (u=search_ulist (searchuser(ent->owner)))&&!u->invisible? 1:0, + isonline, ent->owner, color, mark, title); } -- cgit v1.2.3 From 809c8fafa6f875541f1d8a6a11b998f198bcfc99 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Fri, 31 May 2002 03:11:17 +0000 Subject: everyone can't write to whom is invisiable (from article list) git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@261 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/bbs.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/pttbbs/mbbsd/bbs.c b/pttbbs/mbbsd/bbs.c index 047578e1..d2d616b2 100644 --- a/pttbbs/mbbsd/bbs.c +++ b/pttbbs/mbbsd/bbs.c @@ -1,4 +1,4 @@ -/* $Id: bbs.c,v 1.42 2002/05/30 18:21:04 ptt Exp $ */ +/* $Id: bbs.c,v 1.43 2002/05/31 03:11:17 in2 Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -680,12 +680,12 @@ int invalid_brdname(char *brd) { } return 0; } -static int b_call_in(int ent, fileheader_t *fhdr, char *direct) { - userinfo_t *u=search_ulist (searchuser(fhdr->owner)); - if(u && - call_in(u,friend_stat(currutmp, u))) - return FULLUPDATE; - return DONOTHING; +static int b_call_in(int ent, fileheader_t *fhdr, char *direct) +{ + userinfo_t *u=search_ulist (searchuser(fhdr->owner)); + if(u && !u->invisible && call_in(u,friend_stat(currutmp, u)) ) + return FULLUPDATE; + return DONOTHING; } static void do_reply(fileheader_t *fhdr) { boardheader_t *bp; -- cgit v1.2.3 From 838d29ef2b7784a552417e015c4b49e3e982259c Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Fri, 31 May 2002 03:22:31 +0000 Subject: permission check when writing from article list git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@262 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/bbs.c | 4 ++-- pttbbs/mbbsd/talk.c | 28 +++++++++++++++------------- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/pttbbs/mbbsd/bbs.c b/pttbbs/mbbsd/bbs.c index d2d616b2..3393baaf 100644 --- a/pttbbs/mbbsd/bbs.c +++ b/pttbbs/mbbsd/bbs.c @@ -1,4 +1,4 @@ -/* $Id: bbs.c,v 1.43 2002/05/31 03:11:17 in2 Exp $ */ +/* $Id: bbs.c,v 1.44 2002/05/31 03:22:31 in2 Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -683,7 +683,7 @@ int invalid_brdname(char *brd) { static int b_call_in(int ent, fileheader_t *fhdr, char *direct) { userinfo_t *u=search_ulist (searchuser(fhdr->owner)); - if(u && !u->invisible && call_in(u,friend_stat(currutmp, u)) ) + if(u && call_in(u,friend_stat(currutmp, u)) ) return FULLUPDATE; return DONOTHING; } diff --git a/pttbbs/mbbsd/talk.c b/pttbbs/mbbsd/talk.c index e0cbefea..113f4c16 100644 --- a/pttbbs/mbbsd/talk.c +++ b/pttbbs/mbbsd/talk.c @@ -1,4 +1,4 @@ -/* $Id: talk.c,v 1.50 2002/05/30 17:37:06 ptt Exp $ */ +/* $Id: talk.c,v 1.51 2002/05/31 03:22:31 in2 Exp $ */ #include <stdio.h> #include <string.h> #include <errno.h> @@ -1752,18 +1752,20 @@ static void draw_pickup(int drawall, pickup_t *pickup, int pickup_way, int call_in(userinfo_t *uentp, int fri_stat) { - char genbuf[60]; - if( HAS_PERM(PERM_LOGINOK) && - uentp->pid != currpid && - strcmp(uentp->userid, cuser.userid) != 0 && - (HAS_PERM(PERM_SYSOP) || - (uentp->pager != 3 && - (fri_stat & HFM || uentp->pager != 4))) ){ - sprintf(genbuf, "Call-In %s :", uentp->userid); - my_write(uentp->pid, genbuf, uentp->userid, 0, NULL); - return 1; - } - return 0; + char genbuf[60]; + if( HAS_PERM(PERM_LOGINOK) && + uentp->pid != currpid && + strcmp(uentp->userid, cuser.userid) != 0 && + (HAS_PERM(PERM_SYSOP) || + (!uentp->invisible && + !(fri_stat & HRM) && + uentp->pager != 3 && + (fri_stat & HFM || uentp->pager != 4))) ){ + sprintf(genbuf, "Call-In %s :", uentp->userid); + my_write(uentp->pid, genbuf, uentp->userid, 0, NULL); + return 1; + } + return 0; } static void userlist(void) { -- cgit v1.2.3 From 402dbb2d8dc3c563a276071394eb1a3a0c0fe8e3 Mon Sep 17 00:00:00 2001 From: lwms <lwms@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Fri, 31 May 2002 07:17:42 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@263 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/talk.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pttbbs/mbbsd/talk.c b/pttbbs/mbbsd/talk.c index 113f4c16..c56c5d2a 100644 --- a/pttbbs/mbbsd/talk.c +++ b/pttbbs/mbbsd/talk.c @@ -1,4 +1,4 @@ -/* $Id: talk.c,v 1.51 2002/05/31 03:22:31 in2 Exp $ */ +/* $Id: talk.c,v 1.52 2002/05/31 07:17:42 lwms Exp $ */ #include <stdio.h> #include <string.h> #include <errno.h> @@ -415,7 +415,7 @@ int my_query(char *uident) prints("《上次上站》%-28.28s《上次故鄉》%s\n", Cdate(&muser.lastlogin), (muser.lasthost[0] ? muser.lasthost : "(不詳)")); - if ((uentp && fri_stat&HFM) || HAS_PERM(PERM_SYSOP)) + if ((uentp && fri_stat&HFM && !uentp->invisible) || HAS_PERM(PERM_SYSOP)) prints("《 性 別 》%-28.28s《私有財產》%ld 銀兩\n", sex[muser.sex % 8], muser.money); -- cgit v1.2.3 From febb20fba063a20bbbd62f19f469b30a64546818 Mon Sep 17 00:00:00 2001 From: lwms <lwms@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Fri, 31 May 2002 07:45:41 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@264 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/talk.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pttbbs/mbbsd/talk.c b/pttbbs/mbbsd/talk.c index c56c5d2a..a6eeba5b 100644 --- a/pttbbs/mbbsd/talk.c +++ b/pttbbs/mbbsd/talk.c @@ -1,4 +1,4 @@ -/* $Id: talk.c,v 1.52 2002/05/31 07:17:42 lwms Exp $ */ +/* $Id: talk.c,v 1.53 2002/05/31 07:45:41 lwms Exp $ */ #include <stdio.h> #include <string.h> #include <errno.h> @@ -1974,8 +1974,8 @@ static void userlist(void) offset = i % 20; } else{ - page = (si) / 20; - offset = (si) % 20; + page = (si + nGots) / 20; + offset = (si + nGots) % 20; } } redrawall = redraw = 1; -- cgit v1.2.3 From 25675b0d15d859a9e1e355efb3ccb23364fdb598 Mon Sep 17 00:00:00 2001 From: ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sat, 1 Jun 2002 00:34:49 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@265 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/bbs.c | 21 +++++++++++++-------- pttbbs/mbbsd/talk.c | 9 +++------ 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/pttbbs/mbbsd/bbs.c b/pttbbs/mbbsd/bbs.c index 3393baaf..aec95937 100644 --- a/pttbbs/mbbsd/bbs.c +++ b/pttbbs/mbbsd/bbs.c @@ -1,4 +1,4 @@ -/* $Id: bbs.c,v 1.44 2002/05/31 03:22:31 in2 Exp $ */ +/* $Id: bbs.c,v 1.45 2002/06/01 00:34:49 ptt Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -158,8 +158,7 @@ extern char currtitle[TTLEN + 1]; extern int Tagger(); static void readdoent(int num, fileheader_t *ent) { - int type; - userinfo_t *u; + int type,uid; char *mark, *title, color, special=0, isonline=0; if(ent->recommend>9 || ent->recommend <0 ) ent->recommend=0; //Ptt:暫時 @@ -188,9 +187,9 @@ static void readdoent(int num, fileheader_t *ent) { strcpy(title + 44, " …"); /* 把多餘的 string 砍掉 */ if(!strncmp(title,"[公告]",6)) special=1; - if((u=search_ulist (searchuser(ent->owner)))&& - !u->invisible && !PERM_HIDE(u)) - isonline=1; + if(!strchr(ent->owner, '.') && (uid=searchuser(ent->owner)) && + isvisible_uid(uid)) + isonline=1; if(strncmp(currtitle, title, TTLEN)) prints("%6d %c\033[1;32m%c\033[m%-6s\033[%dm%-13.12s\033[m%s " @@ -683,8 +682,14 @@ int invalid_brdname(char *brd) { static int b_call_in(int ent, fileheader_t *fhdr, char *direct) { userinfo_t *u=search_ulist (searchuser(fhdr->owner)); - if(u && call_in(u,friend_stat(currutmp, u)) ) - return FULLUPDATE; + int fri_stat; + if(u ) + { + fri_stat= friend_stat(currutmp, u); + if(isvisible_stat(currutmp, u, fri_stat) && + call_in(u, fri_stat)) + return FULLUPDATE; + } return DONOTHING; } static void do_reply(fileheader_t *fhdr) { diff --git a/pttbbs/mbbsd/talk.c b/pttbbs/mbbsd/talk.c index a6eeba5b..2097417f 100644 --- a/pttbbs/mbbsd/talk.c +++ b/pttbbs/mbbsd/talk.c @@ -1,4 +1,4 @@ -/* $Id: talk.c,v 1.53 2002/05/31 07:45:41 lwms Exp $ */ +/* $Id: talk.c,v 1.54 2002/06/01 00:34:49 ptt Exp $ */ #include <stdio.h> #include <string.h> #include <errno.h> @@ -1755,12 +1755,9 @@ int call_in(userinfo_t *uentp, int fri_stat) char genbuf[60]; if( HAS_PERM(PERM_LOGINOK) && uentp->pid != currpid && - strcmp(uentp->userid, cuser.userid) != 0 && (HAS_PERM(PERM_SYSOP) || - (!uentp->invisible && - !(fri_stat & HRM) && - uentp->pager != 3 && - (fri_stat & HFM || uentp->pager != 4))) ){ + (uentp->pager != 3 && + (fri_stat & HFM || uentp->pager != 4))) ){ sprintf(genbuf, "Call-In %s :", uentp->userid); my_write(uentp->pid, genbuf, uentp->userid, 0, NULL); return 1; -- cgit v1.2.3 From 0e37f30cdf9e0515fc1262ab090e455da23d3c6c Mon Sep 17 00:00:00 2001 From: ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sat, 1 Jun 2002 00:40:28 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@266 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/bbs.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pttbbs/mbbsd/bbs.c b/pttbbs/mbbsd/bbs.c index aec95937..0191bada 100644 --- a/pttbbs/mbbsd/bbs.c +++ b/pttbbs/mbbsd/bbs.c @@ -1,4 +1,4 @@ -/* $Id: bbs.c,v 1.45 2002/06/01 00:34:49 ptt Exp $ */ +/* $Id: bbs.c,v 1.46 2002/06/01 00:40:28 ptt Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -188,6 +188,7 @@ static void readdoent(int num, fileheader_t *ent) { if(!strncmp(title,"[公告]",6)) special=1; if(!strchr(ent->owner, '.') && (uid=searchuser(ent->owner)) && + search_ulist(uid) && isvisible_uid(uid)) isonline=1; -- cgit v1.2.3 From 56c2d9e320c63f13b8e20f92a67400c63eb08926 Mon Sep 17 00:00:00 2001 From: ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sat, 1 Jun 2002 03:51:36 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@267 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/cache.c | 4 +++- pttbbs/mbbsd/talk.c | 15 ++++++++------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/pttbbs/mbbsd/cache.c b/pttbbs/mbbsd/cache.c index 4dcb271d..5d7bef6a 100644 --- a/pttbbs/mbbsd/cache.c +++ b/pttbbs/mbbsd/cache.c @@ -1,4 +1,4 @@ -/* $Id: cache.c,v 1.29 2002/05/25 16:34:35 ptt Exp $ */ +/* $Id: cache.c,v 1.30 2002/06/01 03:51:36 ptt Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -398,6 +398,8 @@ void sort_utmp() } utmpshm->number = count; qsort(utmpshm->sorted[ns][0],count,sizeof(userinfo_t*),cmputmpuserid); + for(i=0; i<count; i++) + ((userinfo_t*)utmpshm->sorted[ns][0][i])->idoffset=i; memcpy(utmpshm->sorted[ns][1],utmpshm->sorted[ns][0], sizeof(userinfo_t *)*count); memcpy(utmpshm->sorted[ns][2],utmpshm->sorted[ns][0], diff --git a/pttbbs/mbbsd/talk.c b/pttbbs/mbbsd/talk.c index 2097417f..6f96a52f 100644 --- a/pttbbs/mbbsd/talk.c +++ b/pttbbs/mbbsd/talk.c @@ -1,4 +1,4 @@ -/* $Id: talk.c,v 1.54 2002/06/01 00:34:49 ptt Exp $ */ +/* $Id: talk.c,v 1.55 2002/06/01 03:51:36 ptt Exp $ */ #include <stdio.h> #include <string.h> #include <errno.h> @@ -2106,11 +2106,6 @@ static void userlist(void) } break; - case 'K': /* 踢人 */ - if( HAS_PERM(PERM_ACCOUNTS) ){ - } - break; - case 'i': move(3,0); clrtobot(); @@ -2139,7 +2134,13 @@ static void userlist(void) } } break; - + case 'K': + if(HAS_PERM(PERM_ACCOUNTS)) + { + my_kick(uentp); + redrawall = redraw = 1; + } + break; case 'w': if(call_in(uentp,fri_stat)) redrawall = redraw = 1; -- cgit v1.2.3 From be69e57f551f3fa15d48167bdf7497d3f5a90274 Mon Sep 17 00:00:00 2001 From: ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sat, 1 Jun 2002 22:04:24 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@268 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/include/pttstruct.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pttbbs/include/pttstruct.h b/pttbbs/include/pttstruct.h index 0bc88b42..7f2724fd 100644 --- a/pttbbs/include/pttstruct.h +++ b/pttbbs/include/pttstruct.h @@ -1,4 +1,4 @@ -/* $Id: pttstruct.h,v 1.11 2002/05/25 12:14:32 ptt Exp $ */ +/* $Id: pttstruct.h,v 1.12 2002/06/01 22:04:24 ptt Exp $ */ #ifndef INCLUDE_STRUCT_H #define INCLUDE_STRUCT_H @@ -235,7 +235,7 @@ typedef struct userinfo_t { /* 好友比較的cache 前兩個bit是狀態 */ int reject[MAX_REJECT]; void *nextbfriend; /* 用來做版友的linked list */ - int pad; + int idoffset; /* shm id上的 offset */ int lock; int friendtotal; /* 好友比較的cache 大小 */ unsigned char msgcount; -- cgit v1.2.3 From 187e23ae70b6c0cd8ad6310063912a27a79cc76c Mon Sep 17 00:00:00 2001 From: ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sat, 1 Jun 2002 22:08:53 +0000 Subject: 't' unset git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@269 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/board.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pttbbs/mbbsd/board.c b/pttbbs/mbbsd/board.c index 88376c7e..54237fa5 100644 --- a/pttbbs/mbbsd/board.c +++ b/pttbbs/mbbsd/board.c @@ -1,4 +1,4 @@ -/* $Id: board.c,v 1.26 2002/05/30 17:59:41 ptt Exp $ */ +/* $Id: board.c,v 1.27 2002/06/01 22:08:53 ptt Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -262,6 +262,9 @@ void init_brdbuf() { read(n, favbuf, size); close(n); } + + for(n = 0; n < size; n++) + favbuf[n] &= ~BRD_TAG; brc_expire_time = login_start_time - 365 * 86400; } -- cgit v1.2.3 From 3407e1b8efa80d901bcf2bda0fd0a1124f73ce0b Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sun, 2 Jun 2002 01:55:21 +0000 Subject: iswritable_stat, isvisible_stat git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@270 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/include/proto.h | 11 +++++++-- pttbbs/mbbsd/bbs.c | 35 ++++++++++++++-------------- pttbbs/mbbsd/board.c | 15 ++++++------ pttbbs/mbbsd/syspost.c | 4 ++-- pttbbs/mbbsd/talk.c | 63 +++++++++++++++++++++++++++----------------------- 5 files changed, 71 insertions(+), 57 deletions(-) diff --git a/pttbbs/include/proto.h b/pttbbs/include/proto.h index d80f0adc..97e8b970 100644 --- a/pttbbs/include/proto.h +++ b/pttbbs/include/proto.h @@ -1,4 +1,4 @@ -/* $Id: proto.h,v 1.18 2002/05/24 18:24:11 ptt Exp $ */ +/* $Id: proto.h,v 1.19 2002/06/02 01:55:19 in2 Exp $ */ #ifndef INCLUDE_PROTO_H #define INCLUDE_PROTO_H @@ -427,12 +427,18 @@ void post_change_perm(int oldperm, int newperm, char *sysopid, char *userid); void give_money_post(char *userid, int money); /* talk */ +#define iswritable(uentp) \ + (iswritable_stat(uentp, friend_stat(currutmp, uentp))) +#define isvisible(me, uentp) \ + (isvisible_stat(currutmp, uentp, friend_stat(me, uentp))) + +int iswritable_stat(userinfo_t *uentp, int fri_stat); +int isvisible_stat(userinfo_t * me, userinfo_t * uentp, int fri_stat); int cmpwatermtime(const void *a, const void *b); //void water_scr(water_t *tw, int which, char type); void my_write2(void); int t_idle(); char *modestring(userinfo_t * uentp, int simple); -int isvisible(userinfo_t * me, userinfo_t * uentp); int t_users(); int cmpuids(int uid, userinfo_t * urec); int my_write(pid_t pid, char *hint, char *id, int flag, userinfo_t *); @@ -449,6 +455,7 @@ int logout_friend_online(); int login_friend_online(); int isvisible_uid(int tuid); int friend_stat(userinfo_t *me, userinfo_t * ui); +int call_in(userinfo_t *uentp, int fri_stat); /* tmpjack */ int reg_barbq(); diff --git a/pttbbs/mbbsd/bbs.c b/pttbbs/mbbsd/bbs.c index 0191bada..9c5d864b 100644 --- a/pttbbs/mbbsd/bbs.c +++ b/pttbbs/mbbsd/bbs.c @@ -1,4 +1,4 @@ -/* $Id: bbs.c,v 1.46 2002/06/01 00:40:28 ptt Exp $ */ +/* $Id: bbs.c,v 1.47 2002/06/02 01:55:21 in2 Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -15,6 +15,7 @@ #include "proto.h" extern struct bcache_t *brdshm; +extern userinfo_t *currutmp; extern userec_t cuser; extern void touchdircache(int bid); extern int TagNum; @@ -157,10 +158,11 @@ extern char currtitle[TTLEN + 1]; extern int Tagger(); -static void readdoent(int num, fileheader_t *ent) { - int type,uid; - char *mark, *title, color, - special=0, isonline=0; +static void readdoent(int num, fileheader_t *ent) +{ + int type,uid; + char *mark, *title, color, special=0, isonline=0; + userinfo_t *uentp; if(ent->recommend>9 || ent->recommend <0 ) ent->recommend=0; //Ptt:暫時 type = brc_unread(ent->filename,brc_num,brc_list) ? '+' : ' '; @@ -188,8 +190,7 @@ static void readdoent(int num, fileheader_t *ent) { if(!strncmp(title,"[公告]",6)) special=1; if(!strchr(ent->owner, '.') && (uid=searchuser(ent->owner)) && - search_ulist(uid) && - isvisible_uid(uid)) + (uentp = search_ulist(uid)) && isvisible(currutmp, uentp) ) isonline=1; if(strncmp(currtitle, title, TTLEN)) @@ -679,20 +680,20 @@ int invalid_brdname(char *brd) { return 1; } return 0; -} +} + static int b_call_in(int ent, fileheader_t *fhdr, char *direct) { - userinfo_t *u=search_ulist (searchuser(fhdr->owner)); - int fri_stat; - if(u ) - { - fri_stat= friend_stat(currutmp, u); - if(isvisible_stat(currutmp, u, fri_stat) && - call_in(u, fri_stat)) - return FULLUPDATE; - } + userinfo_t *u = search_ulist(searchuser(fhdr->owner)); + if( u ){ + int fri_stat; + fri_stat = friend_stat(currutmp, u); + if( isvisible_stat(currutmp, u, fri_stat) && call_in(u, fri_stat) ) + return FULLUPDATE; + } return DONOTHING; } + static void do_reply(fileheader_t *fhdr) { boardheader_t *bp; bp = getbcache(currbid); diff --git a/pttbbs/mbbsd/board.c b/pttbbs/mbbsd/board.c index 54237fa5..c0fed91c 100644 --- a/pttbbs/mbbsd/board.c +++ b/pttbbs/mbbsd/board.c @@ -1,4 +1,4 @@ -/* $Id: board.c,v 1.27 2002/06/01 22:08:53 ptt Exp $ */ +/* $Id: board.c,v 1.28 2002/06/02 01:55:21 in2 Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -263,8 +263,8 @@ void init_brdbuf() { close(n); } - for(n = 0; n < size; n++) - favbuf[n] &= ~BRD_TAG; + for(n = 0; n < numboards; n++) + favbuf[n] &= ~BRD_TAG; brc_expire_time = login_start_time - 365 * 86400; } @@ -430,9 +430,10 @@ static boardstat_t * addnewbrdstat(int n, int state) return ptr; } -static int cmpboardname(boardstat_t *brd, boardstat_t *tmp) { - return tmp->bh->nuser - brd->bh->nuser; -} +static int cmpboardname(const void *brd, const void *tmp) +{ + return ((boardstat_t *)tmp)->bh->nuser - ((boardstat_t *)brd)->bh->nuser; +} static void load_boards(char *key) { boardheader_t *bptr = NULL; @@ -464,7 +465,7 @@ static void load_boards(char *key) { ) continue; addnewbrdstat(n, state); if(class_bid==-1) - qsort(nbrd, brdnum, sizeof(boardstat_t), cmpboardname); + qsort(nbrd, brdnum, sizeof(boardstat_t), cmpboardname); } } else diff --git a/pttbbs/mbbsd/syspost.c b/pttbbs/mbbsd/syspost.c index 8a30abff..f1a2e70e 100644 --- a/pttbbs/mbbsd/syspost.c +++ b/pttbbs/mbbsd/syspost.c @@ -1,4 +1,4 @@ -/* $Id: syspost.c,v 1.8 2002/05/21 05:08:44 lwms Exp $ */ +/* $Id: syspost.c,v 1.9 2002/06/02 01:55:21 in2 Exp $ */ #include <stdio.h> #include <string.h> #include <time.h> @@ -101,7 +101,7 @@ void give_money_post(char *userid, int money) { FILE *fp; fileheader_t fhdr; time_t now = time(0); - char genbuf[200], reason[30]; + char genbuf[200]; strcpy(genbuf, "boards/S/Security"); stampfile(genbuf, &fhdr); diff --git a/pttbbs/mbbsd/talk.c b/pttbbs/mbbsd/talk.c index 6f96a52f..77b8edf5 100644 --- a/pttbbs/mbbsd/talk.c +++ b/pttbbs/mbbsd/talk.c @@ -1,4 +1,4 @@ -/* $Id: talk.c,v 1.55 2002/06/01 03:51:36 ptt Exp $ */ +/* $Id: talk.c,v 1.56 2002/06/02 01:55:21 in2 Exp $ */ #include <stdio.h> #include <string.h> #include <errno.h> @@ -91,6 +91,36 @@ static char page_requestor[40]; static char description[30]; static FILE *flog; +int iswritable_stat(userinfo_t *uentp, int fri_stat) +{ + if( uentp == currutmp ) + return 0; + + if( HAS_PERM(PERM_SYSOP) ) + return 1; + + if( !HAS_PERM(PERM_LOGINOK) ) + return 0; + + return (uentp->pager != 3 && (fri_stat & HFM || uentp->pager != 4)); +} + +int isvisible_stat(userinfo_t * me, userinfo_t * uentp, int fri_stat) +{ + if (uentp->userid[0] == 0) + return 0; + + if (PERM_HIDE(uentp) && !(PERM_HIDE(me)))/* 對方紫色隱形而你沒有 */ + return 0; + else if ((me->userlevel & PERM_SYSOP) || + ((fri_stat & HRM) && (fri_stat & HFM))) + /* 站長看的見任何人 */ + return 1; + + if (uentp->invisible && !(me->userlevel & PERM_SEECLOAK)) return 0; + + return !(fri_stat & HRM); +} char *modestring(userinfo_t * uentp, int simple) { @@ -296,28 +326,6 @@ int friend_stat(userinfo_t *me, userinfo_t * ui) return hit; } -int isvisible_stat(userinfo_t * me, userinfo_t * uentp, int fri_stat) -{ - if (uentp->userid[0] == 0) - return 0; - - if (PERM_HIDE(uentp) && !(PERM_HIDE(me)))/* 對方紫色隱形而你沒有 */ - return 0; - else if ((me->userlevel & PERM_SYSOP) || - ((fri_stat & HRM) && (fri_stat & HFM))) - /* 站長看的見任何人 */ - return 1; - - if (uentp->invisible && !(me->userlevel & PERM_SEECLOAK)) return 0; - - return (fri_stat & HRM) ? 0 : 1; -} - -int isvisible(userinfo_t * me, userinfo_t * uentp) -{ - return isvisible_stat(currutmp, uentp, friend_stat(me, uentp)); -} - int isvisible_uid(int tuid) { userinfo_t *uentp; @@ -1752,18 +1760,15 @@ static void draw_pickup(int drawall, pickup_t *pickup, int pickup_way, int call_in(userinfo_t *uentp, int fri_stat) { - char genbuf[60]; - if( HAS_PERM(PERM_LOGINOK) && - uentp->pid != currpid && - (HAS_PERM(PERM_SYSOP) || - (uentp->pager != 3 && - (fri_stat & HFM || uentp->pager != 4))) ){ + if( iswritable_stat(uentp, fri_stat) ){ + char genbuf[60]; sprintf(genbuf, "Call-In %s :", uentp->userid); my_write(uentp->pid, genbuf, uentp->userid, 0, NULL); return 1; } return 0; } + static void userlist(void) { /* 使用者名單: -- cgit v1.2.3 From fa4d9f646fc07cfd228a56f722fee7cd84877d83 Mon Sep 17 00:00:00 2001 From: lwms <lwms@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sun, 2 Jun 2002 02:53:31 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@271 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/admin.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pttbbs/mbbsd/admin.c b/pttbbs/mbbsd/admin.c index 96c91b9c..dc5a0c12 100644 --- a/pttbbs/mbbsd/admin.c +++ b/pttbbs/mbbsd/admin.c @@ -1,4 +1,4 @@ -/* $Id: admin.c,v 1.17 2002/05/30 12:11:09 in2 Exp $ */ +/* $Id: admin.c,v 1.18 2002/06/02 02:53:31 lwms Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -1094,7 +1094,7 @@ int give_money() { id = uhash->userid[i]; give_id_money(id, money, fp2, tt, now); } - give_money_post("全站使用者", atoi(mn) ); + give_money_post("全站使用者", atoi(money) ); } else { if(!(fp = fopen("etc/givemoney.txt", "r+"))) { fclose(fp2); -- cgit v1.2.3 From 035d049210d8354663c423a221a8be152da797e4 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sun, 2 Jun 2002 06:44:28 +0000 Subject: register reject reason git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@272 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/admin.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/pttbbs/mbbsd/admin.c b/pttbbs/mbbsd/admin.c index dc5a0c12..ba690f8a 100644 --- a/pttbbs/mbbsd/admin.c +++ b/pttbbs/mbbsd/admin.c @@ -1,4 +1,4 @@ -/* $Id: admin.c,v 1.18 2002/06/02 02:53:31 lwms Exp $ */ +/* $Id: admin.c,v 1.19 2002/06/02 06:44:28 in2 Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -735,8 +735,10 @@ int scan_register_form(char *regfile, int automode, int neednum) { "連絡電話", "電子郵件信箱", NULL }; static char *reason[] = { - "輸入真實姓名", "詳填學校科系與年級", "填寫完整的住址資料", - "詳填連絡電話", "確實填寫註冊申請表", "用中文填寫申請單", NULL + "輸入真實姓名", "詳細填寫您的「學校以及『科系』」或「服務的單位」" + "填寫完整的住址資料 (含縣市名稱, 台北市請含行政區域) ", + "詳填連絡電話 (含區域碼)", "確實填寫註冊申請表", + "用中文填寫申請單", NULL }; static char *autoid = "AutoScan"; userec_t muser; -- cgit v1.2.3 From 00c44556bdd3074a9ce2f7c75fc9f7ef812a5a31 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sun, 2 Jun 2002 06:44:44 +0000 Subject: fix register bug git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@273 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/user.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pttbbs/mbbsd/user.c b/pttbbs/mbbsd/user.c index 54aa5dee..89ebef5f 100644 --- a/pttbbs/mbbsd/user.c +++ b/pttbbs/mbbsd/user.c @@ -1,4 +1,4 @@ -/* $Id: user.c,v 1.19 2002/05/30 10:21:35 in2 Exp $ */ +/* $Id: user.c,v 1.20 2002/06/02 06:44:44 in2 Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -853,7 +853,7 @@ static void toregister(char *email, char *genbuf, char *phone, char *career, } } strncpy(cuser.email, email, sizeof(cuser.email)); - if( email[0] == 'x' || email[0] == 'X' ){ /* 手動認證 */ + if( strcasecmp(email, "x") == 0 ){ /* 手動認證 */ if ((fn = fopen(fn_register, "a"))) { fprintf(fn, "num: %d, %s", usernum, ctime(&now)); fprintf(fn, "uid: %s\n", cuser.userid); -- cgit v1.2.3 From 0d4d914fc0ec0ca9d3ce437b0f311b966d728ac2 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sun, 2 Jun 2002 07:10:49 +0000 Subject: fixbfriend git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@274 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/shmctl.c | 38 ++++++++++++++++++++++++++++++-------- 1 file changed, 30 insertions(+), 8 deletions(-) diff --git a/pttbbs/util/shmctl.c b/pttbbs/util/shmctl.c index 17b9dc42..f2ed2973 100644 --- a/pttbbs/util/shmctl.c +++ b/pttbbs/util/shmctl.c @@ -14,6 +14,7 @@ extern struct utmpfile_t *utmpshm; extern struct pttcache_t *ptt; +extern bcache_t *brdshm; int logout_friend_online(userinfo_t *utmp) { @@ -292,18 +293,39 @@ int setglobe(int argc, char **argv) return 0; } +int fixbfriend(int argc, char **argv) +{ + userinfo_t *ptr; + int count, i; + + for( i = 0 ; i < MAX_BOARD ; ++i ){ + if( isdigit(brdshm->bcache[i].brdname[0]) || + isalpha(brdshm->bcache[i].brdname[0]) ){ + for( count = 0, ptr = brdshm->bcache[i].u ; + ptr != NULL && count < 256 ; + ++count, ptr = ptr->nextbfriend ) + ; + printf("counting %s\n", brdshm->bcache[i].brdname); + brdshm->bcache[i].nuser = ((count == 256) ? 0 : count); + } + } + + return 0; +} + struct { int (*func)(int, char **); char *cmd, *descript; } cmd[] = - { {utmpfix, "utmpfix", "clear dead userlist entry"}, - {utmpstate, "utmpstate", "list utmpstate"}, - {utmpreset, "utmpreset", "utmpshm->busystate=0"}, - {utmpsort, "utmpsort", "sort ulist"}, - {utmpwatch, "utmpwatch", "to see if busystate is always 1 then fix it"}, - {utmpnum, "utmpnum", "print utmpshm->number for snmpd"}, - {showglobe, "showglobe", "show GLOBE"}, - {setglobe, "setglobe", "set GLOBE"}, + { {utmpfix, "utmpfix", "clear dead userlist entry"}, + {utmpstate, "utmpstate", "list utmpstate"}, + {utmpreset, "utmpreset", "utmpshm->busystate=0"}, + {utmpsort, "utmpsort", "sort ulist"}, + {utmpwatch, "utmpwatch", "to see if busystate is always 1 then fix it"}, + {utmpnum, "utmpnum", "print utmpshm->number for snmpd"}, + {showglobe, "showglobe", "show GLOBE"}, + {setglobe, "setglobe", "set GLOBE"}, + {fixbfriend, "fixbfriend", "recount numbers of board friends"}, {NULL, NULL, NULL} }; int main(int argc, char **argv) -- cgit v1.2.3 From 77de748b7fe7b71c9d2136a455b65261bfca8820 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sun, 2 Jun 2002 07:13:34 +0000 Subject: board friend git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@275 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/talk.c | 37 +++++++++++++++++++++++++++++++------ 1 file changed, 31 insertions(+), 6 deletions(-) diff --git a/pttbbs/mbbsd/talk.c b/pttbbs/mbbsd/talk.c index 77b8edf5..32988a87 100644 --- a/pttbbs/mbbsd/talk.c +++ b/pttbbs/mbbsd/talk.c @@ -1,4 +1,4 @@ -/* $Id: talk.c,v 1.56 2002/06/02 01:55:21 in2 Exp $ */ +/* $Id: talk.c,v 1.57 2002/06/02 07:13:34 in2 Exp $ */ #include <stdio.h> #include <string.h> #include <errno.h> @@ -1555,6 +1555,20 @@ static void pickup_myfriend(pickup_t *friends, int *nGots, qsort(friends, *nGots, sizeof(pickup_t), sort_cmpfriend); } +static void pickup_bfriend(pickup_t *friends, int *nGots) +{ + userinfo_t *ptr; + for( ptr = bcache[currutmp->brc_id - 1].u, *nGots = 0 ; + ptr != NULL && *nGots < MAX_FRIEND ; + ptr = ptr->nextbfriend ){ + if( currutmp != ptr && isvisible(currutmp, ptr) ){ + friends[*nGots].ui = ptr; + friends[(*nGots)++].friend = IBH; + } + } + qsort(friends, *nGots, sizeof(pickup_t), sort_cmpfriend); +} + static void pickup(pickup_t *currpickup, int pickup_way, int *page, int *myfriend, int *friendme) { @@ -1564,6 +1578,7 @@ static void pickup(pickup_t *currpickup, int pickup_way, int *page, int friendtotal= currutmp->friendtotal; userinfo_t **utmp; + static int nFriends, nBoardFriends; int which, got, sorted_way; got = 0; @@ -1572,26 +1587,36 @@ static void pickup(pickup_t *currpickup, int pickup_way, int *page, *myfriend = *friendme = 1; if( cuser.uflag & FRIEND_FLAG || - (pickup_way == 0 && *page * MAXPICKUP < friendtotal) ){ + (pickup_way == 0 && *page * MAXPICKUP < (friendtotal + 1)) ){ /* [嗨! 朋友] mode. we need to pickup ALL friends (from currutmp friend_online), sort, and get pickup from right starting position */ pickup_t friends[MAX_FRIEND + 1]; - int nGots; - pickup_myfriend(friends, &nGots, myfriend, friendme); + pickup_myfriend(friends, &nFriends, myfriend, friendme); for( which = *page * MAXPICKUP ; - got < MAXPICKUP && which < nGots ; + got < MAXPICKUP && which < nFriends ; ++got, ++which ) currpickup[got] = friends[which]; } if( !(cuser.uflag & FRIEND_FLAG) ){ + if( pickup_way == 0 ){ + /* now pickup board friends */ + pickup_t friends[MAX_FRIEND + 1]; + pickup_bfriend(friends, &nBoardFriends); + which = *page * MAXPICKUP - nFriends; + for( which = (which >= 0 ? which : 0) ; + got < MAXPICKUP && which < nBoardFriends ; + ++got, ++which ) + currpickup[got] = friends[which]; + } + sorted_way = ((pickup_way == 0) ? 0 : (pickup_way - 1)); utmp = utmpshm->sorted[currsorted][sorted_way]; - which = *page * MAXPICKUP - currutmp->friendtotal; + which = *page * MAXPICKUP - nFriends - nBoardFriends; for( which = (which >= 0 ? which : 0) ; got < MAXPICKUP && which < utmpnumber ; ++got, ++which ){ -- cgit v1.2.3 From 84c80e6c9f9650a4966aec217ff7c23dedf2b607 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sun, 2 Jun 2002 07:58:15 +0000 Subject: show number of board friends by counting git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@276 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/talk.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/pttbbs/mbbsd/talk.c b/pttbbs/mbbsd/talk.c index 32988a87..1fff43f5 100644 --- a/pttbbs/mbbsd/talk.c +++ b/pttbbs/mbbsd/talk.c @@ -1,4 +1,4 @@ -/* $Id: talk.c,v 1.57 2002/06/02 07:13:34 in2 Exp $ */ +/* $Id: talk.c,v 1.58 2002/06/02 07:58:15 in2 Exp $ */ #include <stdio.h> #include <string.h> #include <errno.h> @@ -1570,7 +1570,7 @@ static void pickup_bfriend(pickup_t *friends, int *nGots) } static void pickup(pickup_t *currpickup, int pickup_way, int *page, - int *myfriend, int *friendme) + int *myfriend, int *friendme, int *bfriend) { /* avoid race condition */ int currsorted = utmpshm->currsorted; @@ -1605,10 +1605,10 @@ static void pickup(pickup_t *currpickup, int pickup_way, int *page, if( pickup_way == 0 ){ /* now pickup board friends */ pickup_t friends[MAX_FRIEND + 1]; - pickup_bfriend(friends, &nBoardFriends); + pickup_bfriend(friends, bfriend); which = *page * MAXPICKUP - nFriends; for( which = (which >= 0 ? which : 0) ; - got < MAXPICKUP && which < nBoardFriends ; + got < MAXPICKUP && which < *bfriend ; ++got, ++which ) currpickup[got] = friends[which]; } @@ -1651,7 +1651,7 @@ char *Mind[] = { static void draw_pickup(int drawall, pickup_t *pickup, int pickup_way, int page, int show_mode, int show_uid, int show_board, int show_pid, int real_name, - int myfriend, int friendme) + int myfriend, int friendme, int bfriend) { char *msg_pickup_way[PICKUP_WAYS] = { "嗨! 朋友", "網友代號", "網友動態", "發呆時間", "來自何方", "五子棋 " @@ -1690,8 +1690,7 @@ static void draw_pickup(int drawall, pickup_t *pickup, int pickup_way, "\033[33m與我為友:%-3d\033[36m板友:%-4d\033[31m壞人:" "%-2d\033[m\n", msg_pickup_way[pickup_way], utmpshm->number, - myfriend, friendme, - currutmp->brc_id? bcache[currutmp->brc_id-1].nuser:0, 0); + myfriend, friendme, currutmp->brc_id ? (bfriend + 1) : 0, 0); for( i = 0, ch = page * 20 + 1 ; i < MAXPICKUP ; ++i, ++ch ){ move(i + 3, 0); prints("a"); @@ -1812,7 +1811,7 @@ static void userlist(void) static int real_name = 0; char genbuf[256]; int page, offset, pickup_way, ch, leave, redraw, redrawall, fri_stat; - int myfriend, friendme, i; + int myfriend, friendme, bfriend, i; time_t lastupdate; page = offset = 0; @@ -1825,10 +1824,10 @@ static void userlist(void) leave : 返回上一選單 */ while( !leave ){ - pickup(currpickup, pickup_way, &page, &myfriend, &friendme); + pickup(currpickup, pickup_way, &page, &myfriend, &friendme, &bfriend); draw_pickup(redrawall, currpickup, pickup_way, page, show_mode, show_uid, show_board, show_pid, real_name, - myfriend, friendme); + myfriend, friendme, bfriend); /* 如果因為換頁的時候, 這一頁有的人數比較少, (通常都是最後一頁人數不滿的時候) -- cgit v1.2.3 From b80254155c7b4207935ed8d1cdd79d52575ef679 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sun, 2 Jun 2002 08:36:56 +0000 Subject: show board friends when only friends fix maxpages bug git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@277 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/talk.c | 59 ++++++++++++++++++++++++++++------------------------- 1 file changed, 31 insertions(+), 28 deletions(-) diff --git a/pttbbs/mbbsd/talk.c b/pttbbs/mbbsd/talk.c index 1fff43f5..2324204c 100644 --- a/pttbbs/mbbsd/talk.c +++ b/pttbbs/mbbsd/talk.c @@ -1,4 +1,4 @@ -/* $Id: talk.c,v 1.58 2002/06/02 07:58:15 in2 Exp $ */ +/* $Id: talk.c,v 1.59 2002/06/02 08:36:56 in2 Exp $ */ #include <stdio.h> #include <string.h> #include <errno.h> @@ -1512,14 +1512,14 @@ static int sort_cmpfriend(const void *a, const void *b) (((pickup_t *)a)->friend & ST_FRIEND); } -int pickup_maxpages(int pickupway) +int pickup_maxpages(int pickupway, int nfriend, int bfriend) { int number; if( cuser.uflag & FRIEND_FLAG ) - number = currutmp->friendtotal; + number = nfriend + bfriend; else number = utmpshm->number + - (pickupway == 0 ? currutmp->friendtotal : 0); + (pickupway == 0 ? nfriend + bfriend : 0); return number / MAXPICKUP + (number % MAXPICKUP == 0 ? 0 : 1); } @@ -1570,7 +1570,7 @@ static void pickup_bfriend(pickup_t *friends, int *nGots) } static void pickup(pickup_t *currpickup, int pickup_way, int *page, - int *myfriend, int *friendme, int *bfriend) + int *nfriend, int *myfriend, int *friendme, int *bfriend) { /* avoid race condition */ int currsorted = utmpshm->currsorted; @@ -1578,7 +1578,6 @@ static void pickup(pickup_t *currpickup, int pickup_way, int *page, int friendtotal= currutmp->friendtotal; userinfo_t **utmp; - static int nFriends, nBoardFriends; int which, got, sorted_way; got = 0; @@ -1594,29 +1593,29 @@ static void pickup(pickup_t *currpickup, int pickup_way, int *page, pickup_t friends[MAX_FRIEND + 1]; - pickup_myfriend(friends, &nFriends, myfriend, friendme); + pickup_myfriend(friends, nfriend, myfriend, friendme); for( which = *page * MAXPICKUP ; - got < MAXPICKUP && which < nFriends ; + got < MAXPICKUP && which < *nfriend ; ++got, ++which ) currpickup[got] = friends[which]; } - if( !(cuser.uflag & FRIEND_FLAG) ){ - if( pickup_way == 0 ){ - /* now pickup board friends */ - pickup_t friends[MAX_FRIEND + 1]; - pickup_bfriend(friends, bfriend); - which = *page * MAXPICKUP - nFriends; - for( which = (which >= 0 ? which : 0) ; - got < MAXPICKUP && which < *bfriend ; - ++got, ++which ) - currpickup[got] = friends[which]; - } + if( pickup_way == 0 ){ + /* now pickup board friends */ + pickup_t friends[MAX_FRIEND + 1]; + pickup_bfriend(friends, bfriend); + which = *page * MAXPICKUP - *nfriend; + for( which = (which >= 0 ? which : 0) ; + got < MAXPICKUP && which < *bfriend ; + ++got, ++which ) + currpickup[got] = friends[which]; + } + if( !(cuser.uflag & FRIEND_FLAG) ){ sorted_way = ((pickup_way == 0) ? 0 : (pickup_way - 1)); utmp = utmpshm->sorted[currsorted][sorted_way]; - which = *page * MAXPICKUP - nFriends - nBoardFriends; + which = *page * MAXPICKUP - *nfriend - *bfriend; for( which = (which >= 0 ? which : 0) ; got < MAXPICKUP && which < utmpnumber ; ++got, ++which ){ @@ -1811,7 +1810,7 @@ static void userlist(void) static int real_name = 0; char genbuf[256]; int page, offset, pickup_way, ch, leave, redraw, redrawall, fri_stat; - int myfriend, friendme, bfriend, i; + int nfriend, myfriend, friendme, bfriend, i; time_t lastupdate; page = offset = 0; @@ -1824,7 +1823,8 @@ static void userlist(void) leave : 返回上一選單 */ while( !leave ){ - pickup(currpickup, pickup_way, &page, &myfriend, &friendme, &bfriend); + pickup(currpickup, pickup_way, &page, + &nfriend, &myfriend, &friendme, &bfriend); draw_pickup(redrawall, currpickup, pickup_way, page, show_mode, show_uid, show_board, show_pid, real_name, myfriend, friendme, bfriend); @@ -1839,7 +1839,7 @@ static void userlist(void) break; if( offset == -1 ){ if( --page < 0 ) - page = pickup_maxpages(pickup_way) - 1; + page = pickup_maxpages(pickup_way, nfriend, bfriend) - 1; offset = 0; continue; } @@ -1873,7 +1873,8 @@ static void userlist(void) case 'j': if( ++offset == MAXPICKUP || currpickup[offset].ui == NULL ){ redraw = 1; - if( ++page >= pickup_maxpages(pickup_way) ) + if( ++page >= pickup_maxpages(pickup_way, + nfriend, bfriend) ) offset = page = 0; else offset = 0; @@ -1930,7 +1931,8 @@ static void userlist(void) case KEY_PGDN: case Ctrl('F'):{ int newpage; - if( (newpage = page + 1) >= pickup_maxpages(pickup_way) ) + if( (newpage = page + 1) >= pickup_maxpages(pickup_way, + nfriend, bfriend) ) newpage = offset = 0; if( newpage != page ){ page = newpage; @@ -1945,7 +1947,8 @@ static void userlist(void) if( --offset == -1 ){ offset = MAXPICKUP - 1; if( --page == -1 ) - page = pickup_maxpages(pickup_way) - 1; + page = pickup_maxpages(pickup_way, nfriend, bfriend) + - 1; redraw = 1; } break; @@ -1954,14 +1957,14 @@ static void userlist(void) case Ctrl('B'): case 'P': if( --page == -1 ) - page = pickup_maxpages(pickup_way) - 1; + page = pickup_maxpages(pickup_way, nfriend, bfriend) - 1; offset = 0; redraw = 1; break; case KEY_END: case '$': - page = pickup_maxpages(pickup_way) - 1; + page = pickup_maxpages(pickup_way, nfriend, bfriend) - 1; offset = -1; redraw = 1; break; -- cgit v1.2.3 From 8bd958375054bdefb6d60f882a3ae31d8216346e Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Mon, 3 Jun 2002 09:59:32 +0000 Subject: permission report git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@278 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/bbsctl.c | 54 ++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 46 insertions(+), 8 deletions(-) diff --git a/pttbbs/util/bbsctl.c b/pttbbs/util/bbsctl.c index 03a68689..64e54e61 100644 --- a/pttbbs/util/bbsctl.c +++ b/pttbbs/util/bbsctl.c @@ -1,11 +1,16 @@ +#include <grp.h> #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <string.h> #include <signal.h> #include <sys/types.h> -#include <grp.h> #include <dirent.h> +#include <fcntl.h> +#include <ctype.h> +#include "config.h" +#include "pttstruct.h" +#include "perm.h" #ifdef FreeBSD #include <sys/syslimits.h> @@ -188,17 +193,50 @@ int Xipcrm(int argc, char **argv) return 0; } +int permreport(int argc, char **argv) +{ + int fd, i, count; + userec_t usr; + struct { + int perm; + char *desc; + } check[] = {{PERM_ACCOUNTS, "PERM_ACCOUNTS"}, + {PERM_SYSOP, "PERM_SYSOP"}, + {PERM_SYSSUBOP, "PERM_SYSSUBOP"}, + {PERM_MANAGER, "PERM_MANAGER"}, + {0, NULL}}; + + if( (fd = open(".PASSWDS", O_RDONLY)) < 0 ){ + perror(".PASSWDS"); + return 1; + } + for( count = i = 0 ; check[i].perm != 0 ; ++i ){ + lseek(fd, 0, SEEK_SET); + printf("%s\n", check[i].desc); + while( read(fd, &usr, sizeof(usr)) > 0 ){ + if( usr.userid[0] != 0 && isalpha(usr.userid[0]) && + usr.userlevel & check[i].perm ){ + ++count; + printf("%-20s%-10s\n", usr.userid, usr.realname); + } + } + printf("total %d users\n\n", count); + } + return 0; +} + struct { int (*func)(int, char **); char *cmd, *descript; } cmds[] = - { {startbbs, "start", "start mbbsd at port 23, 3000~3010"}, - {stopbbs, "stop", "killall listening mbbsd"}, - {restartbbs, "restart", "stop and then start"}, - {bbsadm, "bbsadm", "switch to user: bbsadm"}, - {bbstest, "test", "run ./mbbsd as bbsadm"}, - {Xipcrm, "ipcrm", "ipcrm all msg, shm, sem"}, - {STOP, "STOP", "killall ALL mbbsd"}, + { {startbbs, "start", "start mbbsd at port 23, 3000~3010"}, + {stopbbs, "stop", "killall listening mbbsd"}, + {restartbbs, "restart", "stop and then start"}, + {bbsadm, "bbsadm", "switch to user: bbsadm"}, + {bbstest, "test", "run ./mbbsd as bbsadm"}, + {Xipcrm, "ipcrm", "ipcrm all msg, shm, sem"}, + {STOP, "STOP", "killall ALL mbbsd"}, + {permreport, "permreport", "permission report"}, {NULL, NULL, NULL} }; int main(int argc, char **argv) -- cgit v1.2.3 From ecfc2a3a0f5f3104021eb7dfb24f852679b49a23 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Mon, 3 Jun 2002 10:30:40 +0000 Subject: only port 23 using root permission git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@279 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/bbsctl.c | 40 +++++++++++++++++++++++++--------------- 1 file changed, 25 insertions(+), 15 deletions(-) diff --git a/pttbbs/util/bbsctl.c b/pttbbs/util/bbsctl.c index 64e54e61..9618f5de 100644 --- a/pttbbs/util/bbsctl.c +++ b/pttbbs/util/bbsctl.c @@ -1,4 +1,3 @@ -#include <grp.h> #include <stdio.h> #include <stdlib.h> #include <unistd.h> @@ -6,6 +5,7 @@ #include <signal.h> #include <sys/types.h> #include <dirent.h> +#include <grp.h> #include <fcntl.h> #include <ctype.h> #include "config.h" @@ -53,23 +53,32 @@ int HaveBBSADM(void) int startbbs(int argc, char **argv) { + int i; + char *port[] = {"3000", "3001", "3002", "3003", "3004", "3005", + "3006", "3007", "3008", "3009", "3010", NULL}; + pid_t pid; + + for( i = 0 ; port[i] != NULL ; ++i ){ + if( (pid = fork()) < 0 ){ + perror("fork()"); + return 1; + } + else if( pid == 0 ){ + printf("starting mbbsd at port %s\n", port[i]); + execl("/home/bbs/bin/mbbsd", "mbbsd", port[i], NULL); + printf("start port[%s] failed\n", port[i]); + return 1; + } + } + if( setuid(0) < 0 ){ perror("setuid(0)"); exit(1); } - puts("starting mbbsd: 23"); system("/home/bbs/bin/mbbsd 23"); - puts("starting mbbsd:3000"); system("/home/bbs/bin/mbbsd 3000"); - puts("starting mbbsd:3001"); system("/home/bbs/bin/mbbsd 3001"); - puts("starting mbbsd:3002"); system("/home/bbs/bin/mbbsd 3002"); - puts("starting mbbsd:3003"); system("/home/bbs/bin/mbbsd 3003"); - puts("starting mbbsd:3004"); system("/home/bbs/bin/mbbsd 3004"); - puts("starting mbbsd:3005"); system("/home/bbs/bin/mbbsd 3005"); - puts("starting mbbsd:3006"); system("/home/bbs/bin/mbbsd 3006"); - puts("starting mbbsd:3007"); system("/home/bbs/bin/mbbsd 3007"); - puts("starting mbbsd:3008"); system("/home/bbs/bin/mbbsd 3008"); - puts("starting mbbsd:3009"); system("/home/bbs/bin/mbbsd 3009"); - puts("starting mbbsd:3010"); system("/home/bbs/bin/mbbsd 3010"); - return 0; + printf("starting mbbsd at port %s\n", "23"); + execl("/home/bbs/bin/mbbsd", "mbbsd", "23", NULL); + printf("start port[%s] failed\n", "23"); + return 1; } int stopbbs(int argc, char **argv) @@ -200,8 +209,9 @@ int permreport(int argc, char **argv) struct { int perm; char *desc; - } check[] = {{PERM_ACCOUNTS, "PERM_ACCOUNTS"}, + } check[] = {{PERM_BBSADM, "PERM_BBSADM"}, {PERM_SYSOP, "PERM_SYSOP"}, + {PERM_ACCOUNTS, "PERM_ACCOUNTS"}, {PERM_SYSSUBOP, "PERM_SYSSUBOP"}, {PERM_MANAGER, "PERM_MANAGER"}, {0, NULL}}; -- cgit v1.2.3 From 56abe8db6a78683c5cc454061717e79f64589800 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Tue, 4 Jun 2002 13:08:35 +0000 Subject: global variable move to var.c git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@280 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/include/.cvsignore | 1 + pttbbs/include/bbs.h | 53 ++++++ pttbbs/include/config.h | 10 +- pttbbs/include/gomo.h | 193 +------------------ pttbbs/include/proto.h | 18 +- pttbbs/include/pttstruct.h | 12 +- pttbbs/mbbsd/Makefile | 7 +- pttbbs/mbbsd/admin.c | 44 +---- pttbbs/mbbsd/announce.c | 55 +----- pttbbs/mbbsd/args.c | 7 +- pttbbs/mbbsd/bbcall.c | 15 +- pttbbs/mbbsd/bbs.c | 82 +------- pttbbs/mbbsd/board.c | 46 +---- pttbbs/mbbsd/cache.c | 61 +----- pttbbs/mbbsd/cal.c | 30 +-- pttbbs/mbbsd/calendar.c | 15 +- pttbbs/mbbsd/card.c | 16 +- pttbbs/mbbsd/chat.c | 47 +---- pttbbs/mbbsd/chc_draw.c | 17 +- pttbbs/mbbsd/chc_net.c | 11 +- pttbbs/mbbsd/chc_play.c | 26 +-- pttbbs/mbbsd/chc_rule.c | 13 +- pttbbs/mbbsd/chicken.c | 26 +-- pttbbs/mbbsd/dark.c | 16 +- pttbbs/mbbsd/dice.c | 15 +- pttbbs/mbbsd/edit.c | 49 +---- pttbbs/mbbsd/friend.c | 38 +--- pttbbs/mbbsd/gamble.c | 19 +- pttbbs/mbbsd/gomo.c | 28 +-- pttbbs/mbbsd/gomo1.c | 23 +-- pttbbs/mbbsd/guess.c | 17 +- pttbbs/mbbsd/indict.c | 18 +- pttbbs/mbbsd/io.c | 54 +----- pttbbs/mbbsd/kaede.c | 16 +- pttbbs/mbbsd/lovepaper.c | 18 +- pttbbs/mbbsd/mail.c | 61 +----- pttbbs/mbbsd/mbbsd.c | 82 +------- pttbbs/mbbsd/menu.c | 62 ++---- pttbbs/mbbsd/more.c | 33 +--- pttbbs/mbbsd/name.c | 24 +-- pttbbs/mbbsd/osdep.c | 8 +- pttbbs/mbbsd/othello.c | 16 +- pttbbs/mbbsd/page.c | 15 +- pttbbs/mbbsd/passwd.c | 21 +- pttbbs/mbbsd/read.c | 63 +----- pttbbs/mbbsd/record.c | 19 +- pttbbs/mbbsd/register.c | 27 +-- pttbbs/mbbsd/screen.c | 35 +--- pttbbs/mbbsd/stuff.c | 28 +-- pttbbs/mbbsd/syspost.c | 15 +- pttbbs/mbbsd/talk.c | 63 +----- pttbbs/mbbsd/term.c | 39 +--- pttbbs/mbbsd/toolkit.c | 7 +- pttbbs/mbbsd/topsong.c | 11 +- pttbbs/mbbsd/user.c | 38 +--- pttbbs/mbbsd/var.c | 463 +++++++++++++++++++++++++++++++++++++-------- pttbbs/mbbsd/vice.c | 17 +- pttbbs/mbbsd/vote.c | 32 +--- pttbbs/mbbsd/voteboard.c | 24 +-- pttbbs/mbbsd/xyz.c | 36 +--- pttbbs/util/parsevar.pl | 23 +++ pttbbs/util/shmctl.c | 16 +- 62 files changed, 652 insertions(+), 1742 deletions(-) create mode 100755 pttbbs/include/.cvsignore create mode 100644 pttbbs/include/bbs.h create mode 100644 pttbbs/util/parsevar.pl diff --git a/pttbbs/include/.cvsignore b/pttbbs/include/.cvsignore new file mode 100755 index 00000000..38c67d55 --- /dev/null +++ b/pttbbs/include/.cvsignore @@ -0,0 +1 @@ +var.h diff --git a/pttbbs/include/bbs.h b/pttbbs/include/bbs.h new file mode 100644 index 00000000..5d1469f9 --- /dev/null +++ b/pttbbs/include/bbs.h @@ -0,0 +1,53 @@ +/* $id$ */ +#ifndef INCLUDE_BBS_H +#define INCLUDE_BBS_H + +#include <stdio.h> +#include <string.h> +#include <stdlib.h> +#include <stdarg.h> +#include <setjmp.h> +#include <signal.h> +#include <unistd.h> +#include <fcntl.h> +#include <syslog.h> +#include <errno.h> +#include <netdb.h> +#include <time.h> +#include <ctype.h> +#include <termios.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <sys/wait.h> +#include <sys/socket.h> +#include <sys/time.h> +#include <sys/resource.h> +#include <netinet/in.h> +#include <arpa/inet.h> +#include <arpa/telnet.h> +#include <sys/types.h> +#include <sys/mman.h> +#include <machine/param.h> +#include <sys/types.h> +#include <sys/ipc.h> +#include <sys/shm.h> +#include <sys/sem.h> + +#include "config.h" +#include "pttstruct.h" +#include "common.h" +#include "perm.h" +#include "modes.h" +#include "proto.h" +#include "gomo.h" + +#ifndef INCLUDE_VAR_H + #include "var.h" +#endif +#ifdef FreeBSD + #include <machine/limits.h> +#else + #include <limits.h> +#endif + +#endif /* INCLUDE_BBS_H */ diff --git a/pttbbs/include/config.h b/pttbbs/include/config.h index b82d4f48..edec26dd 100644 --- a/pttbbs/include/config.h +++ b/pttbbs/include/config.h @@ -1,4 +1,4 @@ -/* $Id: config.h,v 1.3 2002/05/15 11:26:41 in2 Exp $ */ +/* $Id: config.h,v 1.4 2002/06/04 13:07:12 in2 Exp $ */ #ifndef INCLUDE_CONFIG_H #define INCLUDE_CONFIG_H @@ -198,4 +198,12 @@ #define ALLPOST "ALLPOST" +#define MAXTAGS 256 +#define BRC_STRLEN 15 /* Length of board name */ +#define BRC_MAXSIZE 24576 +#define BRC_ITEMSIZE (BRC_STRLEN + 1 + BRC_MAXNUM * sizeof( int )) +#define BRC_MAXNUM 80 + +#define WRAPMARGIN (511) + #endif diff --git a/pttbbs/include/gomo.h b/pttbbs/include/gomo.h index c51bb283..e2a5a5ca 100644 --- a/pttbbs/include/gomo.h +++ b/pttbbs/include/gomo.h @@ -1,3 +1,7 @@ +/* $Id: gomo.h,v 1.2 2002/06/04 13:07:12 in2 Exp $ */ + +#ifndef _INCLUDE_GOMO_H +#define _INCLUDE_GOMO_H #define BBLANK (0) /* 空白 */ #define BBLACK (1) /* 黑子, 先手 */ @@ -1966,191 +1970,4 @@ 1952 61 61 = OOOO_@_OOOO : len=11 : NO 00 X4 */ -unsigned char *pat_gomoku /* [1954] */ = -/* 0 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" -/* 16 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x44\x55\xcc\x00\x00\x00\x00" -/* 32 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x33\x00\x44\x00\x33\x00\x00\x00" -/* 48 */ "\x00\x22\x00\x55\x00\x22\x00\x00\x00\x44\x33\x66\x55\xcc\x33\x66" -/* 64 */ "\x55\xcc\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x03\x00\x00\x00" -/* 80 */ "\x55\x00\x55\x00\x05\x00\x55\x02\x46\x00\xaa\x00\x00\x55\x00\x55" -/* 96 */ "\x00\x05\x00\x55\x00\x05\x00\x55\x00\x00\x44\xcc\x44\xcc\x05\xbb" -/* 112 */ "\x44\xcc\x05\xbb\x44\xcc\x05\xbb\x00\x00\x00\x00\x00\x00\x00\x00" -/* 128 */ "\x00\x00\x33\x00\x00\x00\x44\x00\x00\x00\x00\x00\x33\x00\x44\x00" -/* 144 */ "\x33\x22\x66\x00\x55\x55\xcc\x00\x33\x00\x00\x00\x00\x22\x00\x55" -/* 160 */ "\x00\x22\x00\x55\x00\x02\x00\x05\x00\x22\x00\x00\x33\x44\x33\x66" -/* 176 */ "\x55\xcc\x33\x66\x55\xcc\x33\x46\x05\xbb\x33\x66\x55\xcc\x00\x00" -/* 192 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x03\x00\x00\x00\x44\x00\x00\x00" -/* 208 */ "\x33\x00\x00\x22\x55\x22\x55\x02\x05\x22\x55\x02\x46\x22\xaa\x55" -/* 224 */ "\xcc\x22\x55\x02\x46\x22\xaa\x00\x22\x55\x22\x55\x02\x05\x22\x55" -/* 240 */ "\x02\x05\x22\x55\x02\x05\x22\x55\x02\x05\x22\x55\x02\x44\x66\xcc" -/* 256 */ "\x66\xcc\x46\xbb\x66\xcc\x46\xbb\x66\xcc\x46\xbb\x66\xcc\x46\xbb" -/* 272 */ "\x66\xcc\x46\xbb\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x33\x00" -/* 288 */ "\x00\x00\x44\x00\x00\x00\x33\x00\x22\x22\x66\x00\x00\x00\x00\x00" -/* 304 */ "\x03\x00\x44\x00\x33\x22\x66\x00\x55\x55\xcc\x00\x33\x22\x66\x00" -/* 320 */ "\x55\x55\xcc\x00\x03\x00\x00\x00\x00\x02\x00\x55\x00\x02\x00\x55" -/* 336 */ "\x00\x02\x00\x05\x00\x02\x00\x55\x00\x02\x02\x46\x00\x02\x00\x55" -/* 352 */ "\x55\x05\x55\x46\xaa\xcc\x55\x46\xaa\xcc\x55\x06\x5a\xbb\x55\x46" -/* 368 */ "\xaa\xcc\x55\x06\x5a\xbb\x55\x46\xaa\xcc\x00\x00\x00\x00\x00\x00" -/* 384 */ "\x00\x00\x00\x00\x03\x00\x00\x00\x44\x00\x00\x00\x33\x00\x22\x22" -/* 400 */ "\x66\x00\x00\x00\x55\x00\x55\x55\x05\x55\x05\x55\x05\x55\x05\x55" -/* 416 */ "\x46\x55\x5a\xaa\xcc\x55\x05\x55\x46\x55\x5a\xaa\xcc\x55\x05\x55" -/* 432 */ "\x06\x55\x0a\x55\x55\x05\x55\x05\x55\x05\x55\x05\x55\x05\x55\x05" -/* 448 */ "\x55\x05\x55\x05\x55\x05\x55\x05\x55\x46\x55\x05\x55\x5a\x55\x5a" -/* 464 */ "\xaa\xcc\xcc\xbb\xcc\xbb\xcc\xbb\xcc\xbb\xcc\xbb\xcc\xbb\xcc\xbb" -/* 480 */ "\xcc\xbb\xcc\xbb\xcc\xbb\xcc\xbb\xcc\xbb\xcc\xbb\xcc\xbb\xcc\xbb" -/* 496 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x33\x00\x00\x00\x44\x00" -/* 512 */ "\x00\x00\x33\x00\x22\x22\x66\x00\x00\x00\x55\x00\x55\x55\xcc\x00" -/* 528 */ "\x00\x00\x00\x00\x33\x00\x44\x00\x33\x22\x66\x00\x55\x55\xcc\x00" -/* 544 */ "\x33\x22\x66\x00\x55\x55\xcc\x00\x33\x02\x46\x00\x05\x05\xbb\x00" -/* 560 */ "\x33\x00\x00\x00\x00\x22\x00\x55\x00\x22\x00\x55\x00\x02\x00\x05" -/* 576 */ "\x00\x22\x00\x55\x00\x02\x02\x46\x00\x22\x00\xaa\x00\x55\x55\xcc" -/* 592 */ "\x00\x22\x00\x00\x33\x44\x33\x66\x55\xcc\x33\x66\x55\xcc\x33\x46" -/* 608 */ "\x05\xbb\x33\x66\x55\xcc\x33\x46\x05\xbb\x33\x66\x55\xcc\x33\x46" -/* 624 */ "\x05\xbb\x33\x66\x55\xcc\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" -/* 640 */ "\x03\x00\x00\x00\x44\x00\x00\x00\x33\x00\x22\x22\x66\x00\x00\x00" -/* 656 */ "\x55\x00\x55\x55\xcc\x00\x00\x00\x33\x00\x00\x22\x55\x22\x55\x02" -/* 672 */ "\x05\x22\x55\x02\x46\x22\xaa\x55\xcc\x22\x55\x02\x46\x22\xaa\x55" -/* 688 */ "\xcc\x22\x55\x02\x06\x22\x5a\x05\xbb\x22\x55\x02\x46\x22\xaa\x00" -/* 704 */ "\x22\x55\x22\x55\x02\x05\x22\x55\x02\x05\x22\x55\x02\x05\x22\x55" -/* 720 */ "\x02\x05\x22\x55\x02\x46\x22\x55\x02\x5a\x22\xaa\x55\xcc\x22\x55" -/* 736 */ "\x02\x05\x22\x55\x02\x44\x66\xcc\x66\xcc\x46\xbb\x66\xcc\x46\xbb" -/* 752 */ "\x66\xcc\x46\xbb\x66\xcc\x46\xbb\x66\xcc\x46\xbb\x66\xcc\x46\xbb" -/* 768 */ "\x66\xcc\x46\xbb\x66\xcc\x46\xbb\x66\xcc\x46\xbb\x00\x00\x00\x00" -/* 784 */ "\x00\x00\x00\x00\x00\x00\x33\x00\x00\x00\x44\x00\x00\x00\x33\x00" -/* 800 */ "\x22\x22\x66\x00\x00\x00\x55\x00\x55\x55\xcc\x00\x00\x00\x33\x00" -/* 816 */ "\x22\x22\x66\x00\x00\x00\x00\x00\x03\x00\x44\x00\x33\x22\x66\x00" -/* 832 */ "\x55\x55\xcc\x00\x33\x22\x66\x00\x55\x55\xcc\x00\x03\x02\x46\x00" -/* 848 */ "\x05\x05\xbb\x00\x33\x22\x66\x00\x55\x55\xcc\x00\x03\x00\x00\x00" -/* 864 */ "\x00\x02\x00\x55\x00\x02\x00\x55\x00\x02\x00\x05\x00\x02\x00\x55" -/* 880 */ "\x00\x02\x02\x46\x00\x02\x00\xaa\x00\x55\x55\xcc\x00\x02\x00\x55" -/* 896 */ "\x00\x02\x02\x46\x00\x02\x00\x55\x55\x05\x55\x46\xaa\xcc\x55\x46" -/* 912 */ "\xaa\xcc\x55\x06\x5a\xbb\x55\x46\xaa\xcc\x55\x06\x5a\xbb\x55\x46" -/* 928 */ "\xaa\xcc\x55\x06\x5a\xbb\x55\x46\xaa\xcc\x55\x06\x5a\xbb\x55\x46" -/* 944 */ "\xaa\xcc\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x03\x00\x00\x00" -/* 960 */ "\x44\x00\x00\x00\x33\x00\x22\x22\x66\x00\x00\x00\x55\x00\x55\x55" -/* 976 */ "\xcc\x00\x00\x00\x33\x00\x22\x22\x66\x00\x00\x00\x55\x00\x55\x55" -/* 992 */ "\x05\x55\x05\x55\x05\x55\x05\x55\x46\x55\x5a\xaa\xcc\x55\x05\x55" -/* 1008 */ "\x46\x55\x5a\xaa\xcc\x55\x05\x55\x06\x55\x0a\x5a\xbb\x55\x05\x55" -/* 1024 */ "\x46\x55\x5a\xaa\xcc\x55\x05\x55\x06\x55\x0a\x55\x55\x05\x55\x05" -/* 1040 */ "\x55\x05\x55\x05\x55\x05\x55\x05\x55\x05\x55\x05\x55\x05\x55\x05" -/* 1056 */ "\x55\x46\x55\x05\x55\x5a\x55\x5a\xaa\xcc\x55\x05\x55\x05\x55\x05" -/* 1072 */ "\x55\x46\x55\x05\x55\x5a\x55\x5a\xaa\xcc\xcc\xbb\xcc\xbb\xcc\xbb" -/* 1088 */ "\xcc\xbb\xcc\xbb\xcc\xbb\xcc\xbb\xcc\xbb\xcc\xbb\xcc\xbb\xcc\xbb" -/* 1104 */ "\xcc\xbb\xcc\xbb\xcc\xbb\xcc\xbb\xcc\xbb\xcc\xbb\xcc\xbb\xcc\xbb" -/* 1120 */ "\xcc\xbb\xcc\xbb\xcc\xbb\xcc\xbb\x00\x00\x00\x00\x00\x00\x00\x00" -/* 1136 */ "\x00\x00\x33\x00\x00\x00\x44\x00\x00\x00\x33\x00\x22\x22\x66\x00" -/* 1152 */ "\x00\x00\x55\x00\x55\x55\xcc\x00\x00\x00\x33\x00\x22\x22\x66\x00" -/* 1168 */ "\x00\x00\x55\x00\x55\x55\xcc\x00\x00\x00\x00\x00\x33\x00\x44\x00" -/* 1184 */ "\x33\x22\x66\x00\x55\x55\xcc\x00\x33\x22\x66\x00\x55\x55\xcc\x00" -/* 1200 */ "\x33\x02\x46\x00\x05\x05\xbb\x00\x33\x22\x66\x00\x55\x55\xcc\x00" -/* 1216 */ "\x33\x02\x46\x00\x05\x05\xbb\x00\x33\x00\x00\x00\x00\x22\x00\x55" -/* 1232 */ "\x00\x22\x00\x55\x00\x02\x00\x05\x00\x22\x00\x55\x00\x02\x02\x46" -/* 1248 */ "\x00\x22\x00\xaa\x00\x55\x55\xcc\x00\x22\x00\x55\x00\x02\x02\x46" -/* 1264 */ "\x00\x22\x00\xaa\x00\x55\x55\xcc\x00\x22\x00\x00\x03\x44\x33\x66" -/* 1280 */ "\x55\xcc\x33\x66\x55\xcc\x03\x46\x05\xbb\x33\x66\x55\xcc\x03\x46" -/* 1296 */ "\x05\xbb\x33\x66\x55\xcc\x03\x46\x05\xbb\x33\x66\x55\xcc\x03\x46" -/* 1312 */ "\x05\xbb\x33\x66\x55\xcc\x03\x46\x05\xbb\x33\x66\x55\xcc\x00\x00" -/* 1328 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x03\x00\x00\x00\x44\x00\x00\x00" -/* 1344 */ "\x33\x00\x22\x22\x66\x00\x00\x00\x55\x00\x55\x55\xcc\x00\x00\x00" -/* 1360 */ "\x33\x00\x22\x22\x66\x00\x00\x00\x55\x00\x55\x55\xcc\x00\x00\x00" -/* 1376 */ "\x03\x00\x00\x02\x55\x02\x55\x02\x05\x02\x55\x02\x46\x02\xaa\x55" -/* 1392 */ "\xcc\x02\x55\x02\x46\x02\xaa\x55\xcc\x02\x55\x02\x06\x02\x5a\x05" -/* 1408 */ "\xbb\x02\x55\x02\x46\x02\xaa\x55\xcc\x02\x55\x02\x06\x02\x5a\x05" -/* 1424 */ "\xbb\x02\x55\x02\x46\x02\xaa\x00\x02\x55\x02\x55\x02\x05\x02\x55" -/* 1440 */ "\x02\x05\x02\x55\x02\x05\x02\x55\x02\x05\x02\x55\x02\x46\x02\x55" -/* 1456 */ "\x02\x5a\x02\xaa\x55\xcc\x02\x55\x02\x05\x02\x55\x02\x46\x02\x55" -/* 1472 */ "\x02\x5a\x02\xaa\x55\xcc\x02\x55\x02\x05\x02\x55\x02\x05\x46\xcc" -/* 1488 */ "\x46\xcc\x06\xbb\x46\xcc\x06\xbb\x46\xcc\x06\xbb\x46\xcc\x06\xbb" -/* 1504 */ "\x46\xcc\x06\xbb\x46\xcc\x06\xbb\x46\xcc\x06\xbb\x46\xcc\x06\xbb" -/* 1520 */ "\x46\xcc\x06\xbb\x46\xcc\x06\xbb\x46\xcc\x06\xbb\x46\xcc\x06\xbb" -/* 1536 */ "\x46\xcc\x06\xbb\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x33\x00" -/* 1552 */ "\x00\x00\x44\x00\x00\x00\x33\x00\x22\x22\x66\x00\x00\x00\x55\x00" -/* 1568 */ "\x55\x55\xcc\x00\x00\x00\x33\x00\x22\x22\x66\x00\x00\x00\x55\x00" -/* 1584 */ "\x55\x55\xcc\x00\x00\x00\x33\x00\x02\x02\x46\x00\x00\x00\x00\x00" -/* 1600 */ "\x03\x00\x44\x00\x33\x22\x66\x00\x55\x55\xcc\x00\x33\x22\x66\x00" -/* 1616 */ "\x55\x55\xcc\x00\x03\x02\x46\x00\x05\x05\xbb\x00\x33\x22\x66\x00" -/* 1632 */ "\x55\x55\xcc\x00\x03\x02\x46\x00\x05\x05\xbb\x00\x33\x22\x66\x00" -/* 1648 */ "\x55\x55\xcc\x00\x03\x00\x00\x00\x00\x02\x00\x55\x00\x02\x00\x55" -/* 1664 */ "\x00\x02\x00\x05\x00\x02\x00\x55\x00\x02\x02\x46\x00\x02\x00\xaa" -/* 1680 */ "\x00\x55\x55\xcc\x00\x02\x00\x55\x00\x02\x02\x46\x00\x02\x00\xaa" -/* 1696 */ "\x00\x55\x55\xcc\x00\x02\x00\x55\x00\x02\x02\x06\x00\x02\x00\x05" -/* 1712 */ "\x05\x05\x05\x46\x5a\xcc\x05\x46\x5a\xcc\x05\x06\x0a\xbb\x05\x46" -/* 1728 */ "\x5a\xcc\x05\x06\x0a\xbb\x05\x46\x5a\xcc\x05\x06\x0a\xbb\x05\x46" -/* 1744 */ "\x5a\xcc\x05\x06\x0a\xbb\x05\x46\x5a\xcc\x05\x06\x0a\xbb\x05\x46" -/* 1760 */ "\x5a\xcc\x05\x06\x0a\xbb\x05\x46\x5a\xcc\x00\x00\x00\x00\x00\x00" -/* 1776 */ "\x00\x00\x00\x00\x03\x00\x00\x00\x44\x00\x00\x00\x33\x00\x22\x22" -/* 1792 */ "\x66\x00\x00\x00\x55\x00\x55\x55\xcc\x00\x00\x00\x33\x00\x22\x22" -/* 1808 */ "\x66\x00\x00\x00\x55\x00\x55\x55\xcc\x00\x00\x00\x03\x00\x02\x02" -/* 1824 */ "\x46\x00\x00\x00\x05\x00\x05\x05\x05\x05\x05\x05\x05\x05\x05\x05" -/* 1840 */ "\x46\x05\x5a\x5a\xcc\x05\x05\x05\x46\x05\x5a\x5a\xcc\x05\x05\x05" -/* 1856 */ "\x06\x05\x0a\x0a\xbb\x05\x05\x05\x46\x05\x5a\x5a\xcc\x05\x05\x05" -/* 1872 */ "\x06\x05\x0a\x0a\xbb\x05\x05\x05\x46\x05\x5a\x5a\xcc\x05\x05\x05" -/* 1888 */ "\x06\x05\x0a\x05\x05\x05\x05\x05\x05\x05\x05\x05\x05\x05\x05\x05" -/* 1904 */ "\x05\x05\x05\x05\x05\x05\x05\x05\x05\x46\x05\x05\x05\x5a\x05\x5a" -/* 1920 */ "\x5a\xcc\x05\x05\x05\x05\x05\x05\x05\x46\x05\x05\x05\x5a\x05\x5a" -/* 1936 */ "\x5a\xcc\x05\x05\x05\x05\x05\x05\x05\x06\x05\x05\x05\x0a\x05\x0a" -/* 1952 */ "\x0a"; - -unsigned char *adv_gomoku /* [978] */ = -/* 0 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" -/* 16 */ "\x00\x00\x00\x00\xa0\x00\xa0\x00\x04\x00\x04\x00\x00\xd0\x00\xd0" -/* 32 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" -/* 48 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" -/* 64 */ "\x00\x70\x00\x00\x00\x00\xa0\x00\xa1\x00\x00\x00\xa0\x00\x04\x00" -/* 80 */ "\x04\x00\x00\x00\x04\x00\xd0\xd0\x00\xd0\x00\xd0\x00\xd0\x00\x00" -/* 96 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x70\x08\x08\x00\x08\x00\x08\x00" -/* 112 */ "\x08\x00\x08\x00\x40\x40\x00\x40\x00\x40\x00\x40\x00\x40\x00\x00" -/* 128 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x70" -/* 144 */ "\x00\x00\x00\x70\x21\x00\x00\x00\x00\x00\xa1\x00\x00\x00\xa1\x00" -/* 160 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" -/* 176 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" -/* 192 */ "\x00\x00\x00\x00\x00\x00\x70\x21\x00\x00\x00\x00\x00\x00\x00\x00" -/* 208 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" -/* 224 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" -/* 240 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x70\x00\x00" -/* 256 */ "\x00\x70\x21\x00\x00\x00\x00\x00\x00\x00\xa0\x00\xa1\x00\x00\x00" -/* 272 */ "\xa1\x00\x00\x00\xa0\x00\x00\x00\xa0\x00\x04\x00\x04\x00\x00\x00" -/* 288 */ "\x04\x00\x00\x00\x04\x00\x00\x00\x04\x00\xd0\xd0\x00\xd0\x00\xd0" -/* 304 */ "\x00\xd0\x00\xd0\x00\xd0\x00\xd0\x00\xd0\x00\x00\x00\x00\x00\x00" -/* 320 */ "\x00\x00\x00\x00\x70\x21\x00\x00\x00\x00\x00\x00\x70\x08\x08\x00" -/* 336 */ "\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00" -/* 352 */ "\x40\x40\x00\x40\x00\x40\x00\x40\x00\x40\x00\x40\x00\x40\x00\x40" -/* 368 */ "\x00\x40\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" -/* 384 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x70\x00\x00\x00\x70" -/* 400 */ "\x21\x00\x00\x00\x00\x00\x00\x70\x21\x00\x00\x00\x00\x00\xa1\x00" -/* 416 */ "\x00\x00\xa1\x00\x00\x00\x00\x00\x00\x00\xa1\x00\x00\x00\x00\x00" -/* 432 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" -/* 448 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" -/* 464 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" -/* 480 */ "\x00\x00\x70\x21\x00\x00\x00\x00\x00\x00\x70\x21\x00\x00\x00\x00" -/* 496 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" -/* 512 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" -/* 528 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" -/* 544 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" -/* 560 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x70\x00\x00\x00\x70\x21\x00" -/* 576 */ "\x00\x00\x00\x00\x00\x70\x21\x00\x00\x00\x00\x00\x00\x00\xa0\x00" -/* 592 */ "\xa1\x00\x00\x00\xa1\x00\x00\x00\xa0\x00\x00\x00\xa1\x00\x00\x00" -/* 608 */ "\xa0\x00\x00\x00\xa0\x00\x04\x00\x04\x00\x00\x00\x04\x00\x00\x00" -/* 624 */ "\x04\x00\x00\x00\x04\x00\x00\x00\x04\x00\x00\x00\x04\x00\x00\xd0" -/* 640 */ "\x00\xd0\x00\x00\x00\xd0\x00\x00\x00\xd0\x00\x00\x00\xd0\x00\x00" -/* 656 */ "\x00\xd0\x00\x00\x00\xd0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" -/* 672 */ "\x70\x21\x00\x00\x00\x00\x00\x00\x70\x21\x00\x00\x00\x00\x00\x00" -/* 688 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" -/* 704 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" -/* 720 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" -/* 736 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" -/* 752 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" -/* 768 */ "\x00\x00\x00\x00\x00\x00\x00\x70\x00\x00\x00\x70\x21\x00\x00\x00" -/* 784 */ "\x00\x00\x00\x70\x21\x00\x00\x00\x00\x00\x00\x70\x00\x00\x00\x00" -/* 800 */ "\x00\x00\xa1\x00\x00\x00\xa1\x00\x00\x00\x00\x00\x00\x00\xa1\x00" -/* 816 */ "\x00\x00\x00\x00\x00\x00\xa1\x00\x00\x00\x00\x00\x00\x00\x00\x00" -/* 832 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" -/* 848 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" -/* 864 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" -/* 880 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x70\x21" -/* 896 */ "\x00\x00\x00\x00\x00\x00\x70\x21\x00\x00\x00\x00\x00\x00\x00\x00" -/* 912 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" -/* 928 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" -/* 944 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" -/* 960 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" -/* 976 */ "\x00"; +#endif diff --git a/pttbbs/include/proto.h b/pttbbs/include/proto.h index 97e8b970..7d8d886f 100644 --- a/pttbbs/include/proto.h +++ b/pttbbs/include/proto.h @@ -1,4 +1,4 @@ -/* $Id: proto.h,v 1.19 2002/06/02 01:55:19 in2 Exp $ */ +/* $Id: proto.h,v 1.20 2002/06/04 13:07:12 in2 Exp $ */ #ifndef INCLUDE_PROTO_H #define INCLUDE_PROTO_H @@ -112,7 +112,9 @@ int hbflcheck(int bid, int uid); int updatemdcache(const char *cpath, const char *fpath); char *cachepath(const char *fpath); int mdcacheopen(char *fpath); - +void touchdircache(int bid); +int get_fileheader_cache(int bid, char *direct, fileheader_t *headers, + int recbase, int nlines); /* cal */ int give_tax(int money); int vice(int money, char* item); @@ -230,6 +232,8 @@ void output(char *s, int len); void init_alarm(); int num_in_buf(); int ochar(int c); +int rget(int x,char *prompt); +char getans(char *prompt); /* kaede */ int Rename(char* src, char* dst); @@ -283,6 +287,13 @@ void showtitle(char *title, char *mid); int egetch(); void movie(int i); void domenu(int cmdmode, char *cmdtitle, int cmd, commands_t cmdtable[]); +int admin(void); +int Mail(void); +int Talk(void); +int User(void); +int Xyz(void); +int Play_Play(void); +int Name_Menu(void); /* more */ int more(char *fpath, int promptend); @@ -324,7 +335,8 @@ void i_read(int cmdmode, char *direct, void (*dotitle)(), void (*doentry)(), one void fixkeep(char *s, int first); keeploc_t *getkeep(char *s, int def_topline, int def_cursline); int Tagger(time_t chrono, int recno, int mode); - +void EnumTagFhdr(fileheader_t *fhdr, char *direct, int locus); +void UnTagger (int locus); /* record */ int substitute_record(char *fpath, void *rptr, int size, int id); int get_record(char *fpath, void *rptr, int size, int id); diff --git a/pttbbs/include/pttstruct.h b/pttbbs/include/pttstruct.h index 7f2724fd..91a0d036 100644 --- a/pttbbs/include/pttstruct.h +++ b/pttbbs/include/pttstruct.h @@ -1,4 +1,4 @@ -/* $Id: pttstruct.h,v 1.12 2002/06/01 22:04:24 ptt Exp $ */ +/* $Id: pttstruct.h,v 1.13 2002/06/04 13:07:12 in2 Exp $ */ #ifndef INCLUDE_STRUCT_H #define INCLUDE_STRUCT_H @@ -336,8 +336,8 @@ struct pttcache_t { time_t touchtime; int busystate; - int GLOBE[10]; /* mbbsd間的 globe var - 用以做統計等資料 */ + int GLOBALVAR[10]; /* mbbsd間的 global variable + 用以做統計等資料 (非常態) */ }; typedef struct fromcache_t { @@ -396,4 +396,10 @@ typedef struct MailQueue { enum {MQ_TEXT, MQ_UUENCODE, MQ_JUSTIFY}; +typedef struct +{ + time_t chrono; + int recno; +} TagItem; + #endif diff --git a/pttbbs/mbbsd/Makefile b/pttbbs/mbbsd/Makefile index 017f3d42..47ae7819 100644 --- a/pttbbs/mbbsd/Makefile +++ b/pttbbs/mbbsd/Makefile @@ -1,4 +1,4 @@ -# $Id: Makefile,v 1.7 2002/05/08 22:30:58 in2 Exp $ +# $Id: Makefile,v 1.8 2002/06/04 13:08:33 in2 Exp $ BBSHOME?=$(HOME) OSTYPE=FreeBSD @@ -46,7 +46,7 @@ OBJS= admin.o announce.o args.o bbcall.o bbs.o board.o cache.o cal.o card.o\ calendar.o .SUFFIXES: .c .o -.c.o: +.c.o: ../include/var.h $(CC) $(ADDFLAGS) $(CFLAGS) -c $*.c all: $(PROG) @@ -54,6 +54,9 @@ all: $(PROG) $(PROG): $(OBJS) $(CC) $(ADDFLAGS) $(LDFLAGS) -o $(PROG) $(OBJS) $(LIBS) +../include/var.h: var.c + perl ../util/parsevar.pl < var.c > ../include/var.h + test: $(PROG) killall -9 testmbbsd || true cp mbbsd testmbbsd diff --git a/pttbbs/mbbsd/admin.c b/pttbbs/mbbsd/admin.c index ba690f8a..9d795f90 100644 --- a/pttbbs/mbbsd/admin.c +++ b/pttbbs/mbbsd/admin.c @@ -1,25 +1,6 @@ -/* $Id: admin.c,v 1.19 2002/06/02 06:44:28 in2 Exp $ */ -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <unistd.h> -#include <ctype.h> -#include <time.h> -#include <sys/types.h> -#include <sys/stat.h> -#include "config.h" -#include "pttstruct.h" -#include "common.h" -#include "perm.h" -#include "modes.h" -#include "proto.h" +/* $Id: admin.c,v 1.20 2002/06/04 13:08:33 in2 Exp $ */ +#include "bbs.h" -extern struct bcache_t *brdshm; -extern char *msg_uid; -extern userec_t xuser; -extern char *err_uid; -extern boardheader_t *bcache; -extern time_t now; /* 使用者管理 */ int m_user() { userec_t muser; @@ -43,8 +24,6 @@ int m_user() { return 0; } -extern int b_lines; - static int search_key_user(char *passwdfile, int mode) { userec_t user; int ch; @@ -168,8 +147,6 @@ static void bperm_msg(boardheader_t *board) { board->brdattr & BRD_POSTMASK ? "發表" : "閱\讀"); } -extern char* str_permboard[]; - unsigned int setperms(unsigned int pbits, char *pstring[]) { register int i; char choice[4]; @@ -208,11 +185,6 @@ void setup_man(boardheader_t * board) { mkdir(genbuf, 0755); } -extern char *fn_board; -extern char *err_bid; -extern userec_t cuser; -extern char *msg_sure_ny; -extern char* str_permid[]; int m_mod_board(char *bname) { boardheader_t bh, newbh; @@ -391,8 +363,6 @@ int m_mod_board(char *bname) { return 0; } -extern char *msg_bid; - /* 設定看版 */ int m_board() { char bname[32]; @@ -515,9 +485,6 @@ int x_file() { return FULLUPDATE; } -extern int numboards; -extern int class_bid; - int m_newbrd(int recover) { boardheader_t newboard; char ans[4]; @@ -977,9 +944,6 @@ int scan_register_form(char *regfile, int automode, int neednum) { return (0); } -extern char* fn_register; -extern int t_lines; - int m_register() { FILE *fn; int x, y, wid, len; @@ -1088,7 +1052,6 @@ int give_money() { stand_title("發錢中..."); if(to_all) { - extern struct uhash_t *uhash; int i, unum; for(unum = uhash->number, i=0; i<unum; i++) { if(bad_user_id(uhash->userid[i])) @@ -1096,7 +1059,8 @@ int give_money() { id = uhash->userid[i]; give_id_money(id, money, fp2, tt, now); } - give_money_post("全站使用者", atoi(money) ); + // something wrong @_@ + //give_money_post("全站使用者", atoi(money) ); } else { if(!(fp = fopen("etc/givemoney.txt", "r+"))) { fclose(fp2); diff --git a/pttbbs/mbbsd/announce.c b/pttbbs/mbbsd/announce.c index a31dc6c2..3afdbac2 100644 --- a/pttbbs/mbbsd/announce.c +++ b/pttbbs/mbbsd/announce.c @@ -1,31 +1,6 @@ -/* $Id: announce.c,v 1.9 2002/05/25 11:18:11 ptt Exp $ */ -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <syslog.h> -#include <netdb.h> -#include <unistd.h> -#include <setjmp.h> -#include <signal.h> -#include <time.h> -#include <sys/types.h> -#include <sys/stat.h> -#include <sys/socket.h> -#include <netinet/in.h> -#include <arpa/inet.h> -#include "config.h" -#include "pttstruct.h" -#include "perm.h" -#include "common.h" -#include "modes.h" -#include "proto.h" - -extern struct bcache_t *brdshm; -extern int b_lines; -extern int p_lines; -extern int TagNum; -extern int currbid; -extern time_t now; +/* $Id: announce.c,v 1.10 2002/06/04 13:08:33 in2 Exp $ */ +#include "bbs.h" + static void g_showmenu(gmenu_t *pm) { static char *mytype = "編 選 絲路之旅"; char *title, ch; @@ -108,8 +83,6 @@ static char *nextfield(char *data, char *field) { return data; } -extern char *str_author1; - static FILE* my_open(char* path) { FILE* ans = 0; char buf[80]; @@ -145,8 +118,6 @@ static void isig(int sig) { } #define PROXY_HOME "proxy/" -extern userec_t cuser; -extern userinfo_t *currutmp; static void go_proxy(char* fpath, item_t *node, int update) { char *ptr, *str, *server; @@ -326,10 +297,6 @@ static void g_showhelp() { #define PATHLEN 256 static char paste_fname[200]; -extern time_t paste_time; -extern char paste_path[]; -extern char paste_title[]; -extern int paste_level; static void load_paste() { struct stat st; @@ -521,8 +488,6 @@ static int AnnounceSelect() { return FULLUPDATE; } -extern char vetitle[]; - void gem(char* maintitle, item_t* path, int update) { gmenu_t me; int ch; @@ -715,10 +680,6 @@ void gem(char* maintitle, item_t* path, int update) { free(me.item[ch]); } -extern char *msg_fwd_ok; -extern char *msg_fwd_err1; -extern char *msg_fwd_err2; - static void a_forward(char *path, fileheader_t *pitem, int mode) { fileheader_t fhdr; @@ -758,7 +719,6 @@ static void a_additem(menu_t *pm, fileheader_t *myheader) { #define ADDGROUP 1 #define ADDGOPHER 2 #define ADDLINK 3 -extern char currboard[]; static void a_newitem(menu_t *pm, int mode) { static char *mesg[4] = { @@ -999,9 +959,6 @@ static void a_appenditem(menu_t *pm, int isask) { } static int a_pastetagpost(menu_t *pm, int mode) { - extern int TagNum; - extern void EnumTagFhdr(); - extern void UnTagger(int locus); fileheader_t fhdr; int ans = 0, ent=0, tagnum; char title[TTLEN + 1]= "◇ "; @@ -1248,12 +1205,6 @@ static void atitle() { } #endif -extern char currtitle[TTLEN + 1]; - -char trans_buffer[256]; -extern char quote_file[]; -extern unsigned int currstat; - static int isvisible_man(menu_t *me) { fileheader_t *fhdr = &me->header[me->now-me->page]; diff --git a/pttbbs/mbbsd/args.c b/pttbbs/mbbsd/args.c index 4d1d6ceb..9f937723 100644 --- a/pttbbs/mbbsd/args.c +++ b/pttbbs/mbbsd/args.c @@ -1,4 +1,5 @@ -/* $Id: args.c,v 1.1 2002/03/07 15:13:48 in2 Exp $ */ +/* $Id: args.c,v 1.2 2002/06/04 13:08:33 in2 Exp $ */ +#include "bbs.h" #ifdef HAVE_SETPROCTITLE void initsetproctitle(int argc, char **argv, char **envp) { @@ -6,10 +7,6 @@ void initsetproctitle(int argc, char **argv, char **envp) { #else -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <stdarg.h> char **Argv = NULL; /* pointer to argument vector */ char *LastArgv = NULL; /* end of argv */ diff --git a/pttbbs/mbbsd/bbcall.c b/pttbbs/mbbsd/bbcall.c index 8fdc56d2..7e511686 100644 --- a/pttbbs/mbbsd/bbcall.c +++ b/pttbbs/mbbsd/bbcall.c @@ -1,16 +1,5 @@ -/* $Id: bbcall.c,v 1.2 2002/04/28 19:35:28 in2 Exp $ */ -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <netdb.h> -#include <unistd.h> -#include <sys/types.h> -#include <sys/socket.h> -#include <netinet/in.h> -#include "config.h" -#include "pttstruct.h" -#include "common.h" -#include "proto.h" +/* $Id: bbcall.c,v 1.3 2002/06/04 13:08:33 in2 Exp $ */ +#include "bbs.h" #define SERVER_0941 "www.chips.com.tw" #define SERVER_0943 "www.pager.com.tw" diff --git a/pttbbs/mbbsd/bbs.c b/pttbbs/mbbsd/bbs.c index 9c5d864b..4b401280 100644 --- a/pttbbs/mbbsd/bbs.c +++ b/pttbbs/mbbsd/bbs.c @@ -1,27 +1,5 @@ -/* $Id: bbs.c,v 1.47 2002/06/02 01:55:21 in2 Exp $ */ -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <unistd.h> -#include <time.h> -#include <fcntl.h> -#include <sys/types.h> -#include <sys/stat.h> -#include "config.h" -#include "pttstruct.h" -#include "perm.h" -#include "modes.h" -#include "common.h" -#include "proto.h" - -extern struct bcache_t *brdshm; -extern userinfo_t *currutmp; -extern userec_t cuser; -extern void touchdircache(int bid); -extern int TagNum; -extern time_t now; -extern char fromhost[]; - +/* $Id: bbs.c,v 1.48 2002/06/04 13:08:33 in2 Exp $ */ +#include "bbs.h" static void mail_by_link(char* owner, char* title, char* path) { char genbuf[200]; @@ -38,7 +16,6 @@ static void mail_by_link(char* owner, char* title, char* path) { append_record(genbuf, &mymail, sizeof(mymail)); } -extern int usernum; void anticrosspost() { char buf[200]; @@ -119,10 +96,6 @@ void make_blist() { } */ -extern int currbid; -extern char currBM[]; -extern int currmode; -extern char currboard[]; static time_t board_note_time; static char *brd_title; @@ -152,12 +125,6 @@ static void readtitle() { " \033[m"); } -extern int brc_num; -extern int brc_list[]; -extern char currtitle[TTLEN + 1]; - -extern int Tagger(); - static void readdoent(int num, fileheader_t *ent) { int type,uid; @@ -211,27 +178,18 @@ static void readdoent(int num, fileheader_t *ent) title); } -extern char currfile[]; - int cmpfilename(fileheader_t *fhdr) { return (!strcmp(fhdr->filename, currfile)); } -extern unsigned char currfmode; - int cmpfmode(fileheader_t *fhdr) { return (fhdr->filemode & currfmode); } -extern char currowner[]; - int cmpfowner(fileheader_t *fhdr) { return !strcasecmp(fhdr->owner, currowner); } -extern char *err_bid; -extern userinfo_t *currutmp; - int whereami(int ent, fileheader_t *fhdr, char *direct) { boardheader_t *bh, *p[32], *root; int i,j; @@ -329,9 +287,6 @@ void outgo_post(fileheader_t *fh, char *board) { } } -extern char *str_author1; -extern char *str_author2; - static void cancelpost(fileheader_t *fh, int by_BM) { FILE *fin, *fout; char *ptr, *brd; @@ -372,9 +327,6 @@ static void cancelpost(fileheader_t *fh, int by_BM) { } } -extern char *str_reply; -extern char save_title[]; - /* ----------------------------------------------------- */ /* 發表、回應、編輯、轉錄文章 */ /* ----------------------------------------------------- */ @@ -411,19 +363,10 @@ static void do_unanonymous_post(char* fpath) { } } -extern char quote_file[]; -extern char quote_user[]; -extern int curredit; -extern unsigned int currbrdattr; -extern char currdirect[]; -extern char *err_uid; - #ifdef NO_WATER_POST static time_t last_post_time = 0; static time_t water_counts = 0; #endif -int local_article; -char real_name[IDLEN + 1]; static int do_general() { fileheader_t postfile; @@ -628,9 +571,6 @@ int do_post() { return 0; } -extern int b_lines; -extern int curredit; - static void do_generalboardreply(fileheader_t *fhdr){ char genbuf[200]; getdata(b_lines - 1, 0, @@ -768,7 +708,6 @@ static int edit_post(int ent, fileheader_t *fhdr, char *direct) { return FULLUPDATE; } -extern crosspost_t postrecord; #define UPDATE_USEREC (currmode |= MODE_DIRTY) static int cross_post(int ent, fileheader_t *fhdr, char *direct) { @@ -1140,8 +1079,6 @@ int edit_title(int ent, fileheader_t *fhdr, char *direct) { return DONOTHING; } -extern unsigned int currstat; - static int solve_post(int ent, fileheader_t * fhdr, char *direct){ if (HAS_PERM(PERM_SYSOP)) { fhdr->filemode ^= FILE_SOLVED; @@ -1166,7 +1103,6 @@ static int recommend_cancel(int ent, fileheader_t *fhdr, char *direct) { } static int recommend(int ent, fileheader_t *fhdr, char *direct) { struct tm *ptime=localtime(&now); - extern userec_t xuser; char buf[200],path[200], yn[5]; boardheader_t *bp; bp = getbcache(currbid); @@ -1224,8 +1160,6 @@ static int mark_post(int ent, fileheader_t *fhdr, char *direct) { return PART_REDRAW; } -extern char *msg_sure_ny; - int del_range(int ent, fileheader_t *fhdr, char *direct) { char num1[8], num2[8]; int inum1, inum2; @@ -1298,9 +1232,6 @@ int del_range(int ent, fileheader_t *fhdr, char *direct) { return DONOTHING; } -extern char *msg_del_ny; -extern char *msg_del_ok; - static int del_post(int ent, fileheader_t *fhdr, char *direct) { char genbuf[100]; int not_owned; @@ -1521,10 +1452,6 @@ static int sequential_read(int ent, fileheader_t *fhdr, char *direct) { return FULLUPDATE; } -extern char *fn_notes; -extern char *msg_cancel; -extern char *fn_board; - /* ----------------------------------------------------- */ /* 看板備忘錄、文摘、精華區 */ /* ----------------------------------------------------- */ @@ -1686,8 +1613,6 @@ int board_etc() { return NEWDIRECT; } -extern char *fn_mandex; - static int good_post(int ent, fileheader_t *fhdr, char *direct) { char genbuf[200]; char genbuf2[200]; @@ -1796,7 +1721,6 @@ static int b_help() { /* ----------------------------------------------------- */ char board_hidden_status; #ifdef BMCHS -extern char *fn_board; static int change_hidden(int ent, fileheader_t *fhdr, char *direct) { boardheader_t bh; @@ -1896,8 +1820,6 @@ struct onekey_t read_comms[] = { {'\0', NULL} }; -time_t board_visit_time; - int Read() { int mode0 = currutmp->mode; int stat0 = currstat, tmpbid=currutmp->brc_id; diff --git a/pttbbs/mbbsd/board.c b/pttbbs/mbbsd/board.c index c0fed91c..af997121 100644 --- a/pttbbs/mbbsd/board.c +++ b/pttbbs/mbbsd/board.c @@ -1,26 +1,10 @@ -/* $Id: board.c,v 1.28 2002/06/02 01:55:21 in2 Exp $ */ -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <time.h> -#include <fcntl.h> -#include <unistd.h> -#include <sys/types.h> -#include <sys/stat.h> -#include "config.h" -#include "pttstruct.h" -#include "perm.h" -#include "modes.h" -#include "common.h" -#include "proto.h" - +/* $Id: board.c,v 1.29 2002/06/04 13:08:33 in2 Exp $ */ +#include "bbs.h" #define BRC_STRLEN 15 /* Length of board name */ #define BRC_MAXSIZE 24576 #define BRC_ITEMSIZE (BRC_STRLEN + 1 + BRC_MAXNUM * sizeof( int )) #define BRC_MAXNUM 80 -extern userinfo_t *currutmp; -extern time_t now; static char *brc_getrecord(char *ptr, char *name, int *pnum, int *list) { int num; char *tmp; @@ -55,13 +39,9 @@ static char *brc_putrecord(char *ptr, char *name, int num, int *list) { return ptr; } -extern userec_t cuser; -extern char currboard[]; /* name of currently selected board */ static int brc_changed = 0; static char brc_buf[BRC_MAXSIZE]; -int brc_num; static char brc_name[BRC_STRLEN]; -int brc_list[BRC_MAXNUM]; static char *fn_boardrc = ".boardrc"; static int brc_size; @@ -117,10 +97,6 @@ static void read_brc_buf() { } } -extern int currbid; -extern unsigned int currbrdattr; -extern boardheader_t *bcache; - int brc_initial(char *boardname) { char *ptr; if(strcmp(currboard, boardname) == 0) { @@ -227,8 +203,6 @@ typedef struct { unsigned int myattr; } boardstat_t; -extern time_t login_start_time; -extern int numboards; static int *zapbuf=NULL,*favbuf; static boardstat_t *nbrd=NULL; @@ -294,8 +268,6 @@ void save_brdbuf() { } } -extern char *fn_visable; - int Ben_Perm(boardheader_t *bptr) { register int level,brdattr; register char *ptr; @@ -328,10 +300,6 @@ int Ben_Perm(boardheader_t *bptr) { return 1; } -extern char currauthor[]; -extern int b_lines; -extern char currowner[]; - #if 0 static int have_author(char* brdname) { char dirname[100]; @@ -380,10 +348,7 @@ static int check_newpost(boardstat_t *ptr) { /* Ptt return 1; } -extern int currmode; -extern struct bcache_t *brdshm; static int brdnum; -int class_bid = 0; static int yank_flag = 1; static void load_uidofgid(const int gid, const int type){ boardheader_t *bptr,*currbptr; @@ -546,9 +511,6 @@ static void brdlist_foot() { yank_flag==0 ? "最愛" : yank_flag==1 ? "部份" : "全部"); } -extern unsigned int currstat; -extern char *BBSName; - static void show_brdlist(int head, int clsflag, int newflag) { int myrow = 2; if(class_bid == 1) { @@ -680,9 +642,6 @@ static void set_menu_BM(char *BM) { } } -extern int p_lines; /* a Page of Screen line numbers: tlines-4 */ -extern int t_lines; -extern char *fn_notes; static char *privateboard = "\n\n\n\n 對不起 此板目前只准看板好友進入 請先向板主申請入境許\可"; static void dozap(int num){ @@ -736,7 +695,6 @@ static void choose_board(int newflag) { #if HAVE_SEARCH_ALL char genbuf[200]; #endif - extern time_t board_visit_time; setutmpmode(newflag ? READNEW : READBRD); brdnum = 0; diff --git a/pttbbs/mbbsd/cache.c b/pttbbs/mbbsd/cache.c index 5d7bef6a..ab87c3a0 100644 --- a/pttbbs/mbbsd/cache.c +++ b/pttbbs/mbbsd/cache.c @@ -1,30 +1,5 @@ -/* $Id: cache.c,v 1.30 2002/06/01 03:51:36 ptt Exp $ */ -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <signal.h> -#include <unistd.h> -#include <fcntl.h> -#include <ctype.h> -#include <errno.h> -#include <time.h> -#include <sys/types.h> -#include <sys/mman.h> -#include <sys/stat.h> -#include <sys/ipc.h> -#include <sys/shm.h> -#include <sys/sem.h> - -#ifdef __FreeBSD__ -#include <machine/param.h> -#endif - -#include "config.h" -#include "pttstruct.h" -#include "common.h" -#include "perm.h" -#include "modes.h" -#include "proto.h" +/* $Id: cache.c,v 1.31 2002/06/04 13:08:33 in2 Exp $ */ +#include "bbs.h" #ifndef __FreeBSD__ union semun { @@ -34,7 +9,6 @@ union semun { struct seminfo *__buf; /* buffer for IPC_INFO */ }; #endif -extern time_t now; int fcache_semid; /* the reason for "safe_sleep" is that we may call sleep during @@ -154,7 +128,6 @@ void sem_lock(int op,int semid) { the bbs exits if it can't attach to the shared memory or the hash is not loaded yet. */ -uhash_t *uhash; /* attach_uhash should be called before using uhash */ void attach_uhash() { @@ -209,7 +182,6 @@ int deumoney(int uid, int money) { return setumoney(uid,uhash->money[uid-1]+money); } int demoney(int money) { - extern int usernum; return deumoney(usernum,money); } int moneyof(int uid){ /* ptt 改進金錢處理效率 */ @@ -232,7 +204,6 @@ int searchuser(char *userid) { } #if !defined(_BBS_UTIL_C_) -extern userec_t xuser; int getuser(char *userid) { int uid; @@ -310,20 +281,13 @@ char *u_namearray(char buf[][IDLEN + 1], int *pnum, char *tag) { /*-------------------------------------------------------*/ /* .UTMP cache */ /*-------------------------------------------------------*/ -struct utmpfile_t *utmpshm=NULL; - void resolve_utmp() { if(utmpshm == NULL) { utmpshm = attach_shm(UTMPSHM_KEY, sizeof(*utmpshm)); } } -userinfo_t *currutmp = NULL; - #if !defined(_BBS_UTIL_C_) -extern unsigned int currstat; -extern userec_t cuser; - void setutmpmode(int mode) { if(currstat != mode) currutmp->mode = currstat = mode; @@ -426,7 +390,6 @@ void sort_utmp() } // Ptt:這邊加入hash觀念 找空的utmp void getnewutmpent(userinfo_t *up) { - extern int errno; register int i, p ; register userinfo_t *uentp; for(i = 0, p=StringHash(up->userid)%USHM_SIZE; i < USHM_SIZE; i++, p++) { @@ -460,8 +423,6 @@ userinfo_t *search_ulist(int uid) { } #if !defined(_BBS_UTIL_C_) -extern int usernum; - userinfo_t *search_ulist_pid(int pid) { register int i=0, j, start = 0, end = utmpshm->number - 1; register userinfo_t **ulist; @@ -567,11 +528,6 @@ void purge_utmp(userinfo_t *uentp) { /*-------------------------------------------------------*/ /* .BOARDS cache */ /*-------------------------------------------------------*/ -extern char *fn_board; -extern int currbid; -bcache_t *brdshm; -boardheader_t *bcache; - void touchdircache(int bid) { int *i= (int *)&brdshm->dircache[bid - 1][0].filename[0]; @@ -665,8 +621,6 @@ static void reload_bcache() { #endif } -int numboards = -1; - void resolve_boards() { if(brdshm == NULL) { brdshm = attach_shm(BRDSHM_KEY, sizeof(*brdshm)); @@ -806,9 +760,6 @@ int getbnum(char *bname) { } #if !defined(_BBS_UTIL_C_) -extern char *fn_water; -extern char *str_sysop; - int haspostperm(char *bname) { register int i; char buf[200]; @@ -920,13 +871,12 @@ static void reload_pttcache() } } -int *GLOBE; void resolve_garbage() { int count=0; if(ptt == NULL) { ptt = attach_shm(PTTSHM_KEY, sizeof(*ptt)); - GLOBE = ptt->GLOBE; + GLOBALVAR = ptt->GLOBALVAR; if(ptt->touchtime == 0) ptt->touchtime = 1; } @@ -950,8 +900,6 @@ void resolve_garbage() { /* PTT's cache */ /*-------------------------------------------------------*/ /* cachefor from host 與最多上線人數 */ -struct fromcache_t *fcache; - static void reload_fcache() { if(fcache->busystate) safe_sleep(1); @@ -1002,9 +950,6 @@ void resolve_fcache() { reload_fcache(); } -extern time_t login_start_time; -extern char *fn_visable; - void hbflreload(int bid) { int hbfl[MAX_FRIEND + 1], i, num, uid; diff --git a/pttbbs/mbbsd/cal.c b/pttbbs/mbbsd/cal.c index 5d80bc47..3b41d279 100644 --- a/pttbbs/mbbsd/cal.c +++ b/pttbbs/mbbsd/cal.c @@ -1,26 +1,10 @@ -/* $Id: cal.c,v 1.12 2002/05/25 11:18:11 ptt Exp $ */ -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <unistd.h> -#include <time.h> -#include <sys/types.h> -#include "config.h" -#include "pttstruct.h" -#include "common.h" -#include "modes.h" -#include "perm.h" -#include "proto.h" - -extern struct utmpfile_t *utmpshm; -extern int usernum; -extern time_t now; +/* $Id: cal.c,v 1.13 2002/06/04 13:08:33 in2 Exp $ */ +#include "bbs.h" /* 防堵 Multi play */ static int count_multiplay(int unmode) { register int i, j; register userinfo_t *uentp; - extern struct utmpfile_t *utmpshm; for(i = j = 0; i < USHM_SIZE; i++) { uentp = &(utmpshm->uinfo[i]); @@ -31,9 +15,6 @@ static int count_multiplay(int unmode) { return j; } -extern userinfo_t *currutmp; -extern char *ModeTypeTable[]; - int lockutmpmode(int unmode, int state) { int errorno = 0; @@ -66,9 +47,6 @@ int unlockutmpmode() { return 0; } -extern userec_t cuser; -extern userec_t xuser; - /* 使用錢的函數 */ #define VICE_NEW "vice.new" @@ -96,8 +74,6 @@ int vice(int money, char* item) { #define lockbreak(unmode, state) if(lockutmpmode(unmode, state)) break #define SONGBOOK "etc/SONGBOOK" #define OSONGPATH "etc/SONGO" -extern char trans_buffer[]; -extern char save_title[]; static int osong(char *defaultid) { char destid[IDLEN + 1],buf[200],genbuf[200],filename[256],say[51]; @@ -269,8 +245,6 @@ static int inmailbox(int m) { } -extern int b_lines; - #if !HAVE_FREECLOAK /* 花錢選單 */ int p_cloak() { diff --git a/pttbbs/mbbsd/calendar.c b/pttbbs/mbbsd/calendar.c index 371a8f79..f807c8a9 100644 --- a/pttbbs/mbbsd/calendar.c +++ b/pttbbs/mbbsd/calendar.c @@ -1,15 +1,6 @@ -/* $Id: calendar.c,v 1.2 2002/05/13 03:20:04 ptt Exp $ */ -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <time.h> -#include <sys/types.h> -#include "config.h" -#include "pttstruct.h" -#include "proto.h" -#include "modes.h" +/* $Id: calendar.c,v 1.3 2002/06/04 13:08:33 in2 Exp $ */ +#include "bbs.h" -extern time_t now; typedef struct event_t { int year, month, day, days; int color; @@ -100,8 +91,6 @@ static void FreeEvent(event_t *e) { } } -extern userec_t cuser; - static event_t *ReadEvent(int today) { FILE *fp; char buf[256]; diff --git a/pttbbs/mbbsd/card.c b/pttbbs/mbbsd/card.c index 66aeded8..e5ac18e7 100644 --- a/pttbbs/mbbsd/card.c +++ b/pttbbs/mbbsd/card.c @@ -1,13 +1,5 @@ -/* $Id: card.c,v 1.2 2002/04/28 19:35:28 in2 Exp $ */ -#include <stdio.h> -#include <stdlib.h> -#include <sys/types.h> -#include "config.h" -#include "pttstruct.h" -#include "common.h" -#include "modes.h" -#include "proto.h" -extern int usernum; +/* $Id: card.c,v 1.3 2002/06/04 13:08:33 in2 Exp $ */ +#include "bbs.h" static int card_remain(int cards[]) { int i, temp = 0; @@ -322,8 +314,6 @@ int card_99() { #define JACK (10) /*黑傑克的Ticket*/ #define NINE99 (99) /*99 的Ticket*/ -extern userec_t cuser; - static int game_log(int type, int money) { FILE *fp; @@ -394,8 +384,6 @@ static int card_alls_upper(int all[]) { return count; } -extern int b_lines; - static int card_jack(int *db) { int i, j; int cpu[5], c[5], me[5], m[5]; diff --git a/pttbbs/mbbsd/chat.c b/pttbbs/mbbsd/chat.c index 284403a8..17e004b0 100644 --- a/pttbbs/mbbsd/chat.c +++ b/pttbbs/mbbsd/chat.c @@ -1,27 +1,8 @@ -/* $Id: chat.c,v 1.4 2002/05/25 11:18:11 ptt Exp $ */ -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <time.h> -#include <ctype.h> -#include <netdb.h> -#include <unistd.h> -#include <sys/types.h> -#include <sys/socket.h> -#include <netinet/in.h> -#include "config.h" -#include "pttstruct.h" -#include "perm.h" -#include "common.h" -#include "modes.h" -#include "proto.h" - -extern userinfo_t *currutmp; -static int chatline; -static int stop_line; /* next line of bottom of message window area */ -static FILE *flog; -extern time_t now; +/* $Id: chat.c,v 1.5 2002/06/04 13:08:33 in2 Exp $ */ +#include "bbs.h" +static int chatline, stop_line; +static FILE *flog; static void printchatline(char *str) { move(chatline, 0); if(*str == '>' && !PERM_HIDE(currutmp)) @@ -40,8 +21,6 @@ static void printchatline(char *str) { fprintf(flog, "%s\n", str); } -extern int b_lines; /* Screen bottom line number: t_lines-1 */ - static void chat_clear() { for(chatline = 2; chatline < stop_line; chatline++) { move(chatline, 0); @@ -125,8 +104,6 @@ static int chat_recv(int fd, char *chatid) { return 0; } -extern userec_t cuser; - static int printuserent(userinfo_t *uentp) { static char uline[80]; static int cnt; @@ -208,11 +185,6 @@ static void chat_pager() { printchatline(genbuf); } -extern char *str_space; -extern userec_t xuser; -extern char *fn_plans; -extern char *err_uid; - static void chat_query(char *arg) { char *uid; int tuid; @@ -245,8 +217,6 @@ static void chat_query(char *arg) { printchatline(err_uid); } -extern char *msg_shortulist; - static void chat_users() { printchatline(""); printchatline("【 " BBSNAME "的遊客列表 】"); @@ -294,8 +264,6 @@ static int chat_cmd(char *buf, int fd) { return 0; } -extern char trans_buffer[256]; /* 一般傳遞變數 add by Ptt */ - #if 0 static char *select_address() { int c; @@ -330,9 +298,6 @@ static char *select_address() { } #endif -extern int usernum; -extern int t_lines; -extern char *msg_seperator; #define MAXLASTCMD 6 static int chatid_len = 10; @@ -563,7 +528,6 @@ int t_chat() { continue; } if(ch == Ctrl('I')) { - extern screenline_t *big_picture; screenline_t *screen0 = calloc(t_lines, sizeof(screenline_t)); memcpy(screen0, big_picture, t_lines * sizeof(screenline_t)); @@ -615,7 +579,4 @@ int t_chat() { /* -------------------------------------------------- */ #if 0 -extern char page_requestor[]; -extern userinfo_t *currutmp; - #endif diff --git a/pttbbs/mbbsd/chc_draw.c b/pttbbs/mbbsd/chc_draw.c index b3bd216f..bb9a15a9 100644 --- a/pttbbs/mbbsd/chc_draw.c +++ b/pttbbs/mbbsd/chc_draw.c @@ -1,10 +1,5 @@ -/* $Id: chc_draw.c,v 1.1 2002/03/07 15:13:48 in2 Exp $ */ -#include <stdio.h> -#include <sys/types.h> -#include "config.h" -#include "pttstruct.h" -#include "common.h" -#include "proto.h" +/* $Id: chc_draw.c,v 1.2 2002/06/04 13:08:33 in2 Exp $ */ +#include "bbs.h" #define SIDE_ROW 10 #define TURN_ROW 11 @@ -14,12 +9,6 @@ #define MYWIN_ROW 17 #define HISWIN_ROW 18 -extern char chc_warnmsg[64], *chc_mateid; -extern rc_t chc_from, chc_to, chc_select; -extern int chc_selected, chc_my, chc_turn, chc_firststep; -extern int chc_lefttime; -extern int chc_hiswin, chc_hislose, chc_histie; - static char *turn_str[2] = {"黑的", "紅的"}; static char *num_str[10] = { @@ -104,8 +93,6 @@ static void showstep(board_t board) { prints("\033[m"); } -extern userec_t cuser; - void chc_drawline(board_t board, int line) { int i, j; diff --git a/pttbbs/mbbsd/chc_net.c b/pttbbs/mbbsd/chc_net.c index d094d5f2..b9f63d8f 100644 --- a/pttbbs/mbbsd/chc_net.c +++ b/pttbbs/mbbsd/chc_net.c @@ -1,12 +1,5 @@ -/* $Id: chc_net.c,v 1.1 2002/03/07 15:13:48 in2 Exp $ */ -#include <stdio.h> -#include <sys/types.h> -#include <unistd.h> -#include "config.h" -#include "pttstruct.h" - -extern rc_t chc_from, chc_to; - +/* $Id: chc_net.c,v 1.2 2002/06/04 13:08:33 in2 Exp $ */ +#include "bbs.h" typedef struct drc_t { rc_t from, to; } drc_t; diff --git a/pttbbs/mbbsd/chc_play.c b/pttbbs/mbbsd/chc_play.c index 8f3e432c..cffe3959 100644 --- a/pttbbs/mbbsd/chc_play.c +++ b/pttbbs/mbbsd/chc_play.c @@ -1,26 +1,8 @@ -/* $Id: chc_play.c,v 1.2 2002/05/13 03:20:04 ptt Exp $ */ -#include <stdio.h> -#include <time.h> -#include <unistd.h> -#include <sys/types.h> -#include <string.h> -#include "config.h" -#include "pttstruct.h" -#include "common.h" -#include "modes.h" -#include "proto.h" - -extern userinfo_t *currutmp; -extern int usernum; -extern time_t now; +/* $Id: chc_play.c,v 1.3 2002/06/04 13:08:33 in2 Exp $ */ +#include "bbs.h" typedef int (*play_func_t)(int, board_t, board_t); static int chc_ipass = 0, chc_hepass = 0; -int chc_lefttime; -int chc_my, chc_turn, chc_selected, chc_firststep; -char chc_warnmsg[64], *chc_mateid; -rc_t chc_from, chc_to, chc_select, chc_cursor; -int chc_hiswin, chc_hislose, chc_histie; #define CHC_TIMEOUT 300 #define SIDE_ROW 10 @@ -191,8 +173,6 @@ static int myplay(int s, board_t board, board_t tmpbrd) { return endgame; } -extern userec_t cuser; - static void mainloop(int s, board_t board) { int endgame; board_t tmpbrd; @@ -229,8 +209,6 @@ static void mainloop(int s, board_t board) { oflush(); } -extern userec_t xuser; - static void chc_init(int s, board_t board) { userinfo_t *my = currutmp; diff --git a/pttbbs/mbbsd/chc_rule.c b/pttbbs/mbbsd/chc_rule.c index 35d8fe6a..e5a92c32 100644 --- a/pttbbs/mbbsd/chc_rule.c +++ b/pttbbs/mbbsd/chc_rule.c @@ -1,14 +1,5 @@ -/* $Id: chc_rule.c,v 1.1 2002/03/07 15:13:48 in2 Exp $ */ -#include <stdio.h> -#include <sys/types.h> -#include <string.h> -#include "config.h" -#include "pttstruct.h" -#include "common.h" -#include "proto.h" - -extern rc_t chc_from, chc_to; -extern int chc_my; +/* $Id: chc_rule.c,v 1.2 2002/06/04 13:08:33 in2 Exp $ */ +#include "bbs.h" #define CENTER(a, b) (((a) + (b)) >> 1) diff --git a/pttbbs/mbbsd/chicken.c b/pttbbs/mbbsd/chicken.c index c3bc1fa0..9c30deec 100644 --- a/pttbbs/mbbsd/chicken.c +++ b/pttbbs/mbbsd/chicken.c @@ -1,16 +1,5 @@ -/* $Id: chicken.c,v 1.3 2002/05/13 03:20:04 ptt Exp $ */ -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <time.h> -#include <unistd.h> -#include <sys/types.h> -#include <sys/socket.h> -#include "config.h" -#include "pttstruct.h" -#include "common.h" -#include "modes.h" -#include "proto.h" +/* $Id: chicken.c,v 1.4 2002/06/04 13:08:33 in2 Exp $ */ +#include "bbs.h" #define NUM_KINDS 13 /* 有多少種動物 */ @@ -56,8 +45,6 @@ enum { TEMPERAMENT, TIREDSTRONG, SICK, HP_MAX, MM_MAX }; -extern userec_t cuser; -extern time_t now; static chicken_t *mychicken = &cuser.mychicken; static int age; @@ -92,9 +79,6 @@ static const int time_change[NUM_KINDS][14] = { 1, 1, 147, 2, 10, 10, 85, 20, 4, 25, 25, 5, 145, 95} }; -extern userec_t xuser; -extern int usernum; - int reload_chicken() { passwd_query(usernum, &xuser); memcpy(mychicken, &xuser.mychicken, sizeof(chicken_t)); @@ -208,7 +192,6 @@ static void show_chicken_stat(chicken_t *thechicken) { } #define CHICKEN_PIC "etc/chickens" -extern char *BBSName; void show_chicken_data(chicken_t *thechicken, chicken_t *pkchicken) { char buf[1024]; @@ -360,8 +343,6 @@ static void ch_hit() { pressanykey(); } -extern int b_lines; /* Screen bottom line number: t_lines-1 */ - void ch_buyitem(int money, char *picture, int *item) { int num = 0; char buf[5]; @@ -843,9 +824,6 @@ int chicken_main() { return 0; } -extern userinfo_t *currutmp; -extern struct utmpfile_t *utmpshm; - int chickenpk(int fd) { char mateid[IDLEN + 1], data[200], buf[200]; int ch = 0; diff --git a/pttbbs/mbbsd/dark.c b/pttbbs/mbbsd/dark.c index ee691577..9cf99aab 100644 --- a/pttbbs/mbbsd/dark.c +++ b/pttbbs/mbbsd/dark.c @@ -1,19 +1,8 @@ -/* $Id: dark.c,v 1.3 2002/05/13 03:20:04 ptt Exp $ */ -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <unistd.h> -#include <time.h> -#include <sys/types.h> -#include <sys/socket.h> -#include "config.h" -#include "pttstruct.h" -#include "common.h" -#include "proto.h" +/* $Id: dark.c,v 1.4 2002/06/04 13:08:33 in2 Exp $ */ +#include "bbs.h" #define RED 1 #define BLACK 0 -extern time_t now; typedef short int sint; typedef struct item { @@ -26,7 +15,6 @@ typedef struct cur{ static item brd[4][8]; static cur curr; /* 6 個 bytes */ -extern userinfo_t *currutmp; static char *rname[]={"兵","炮","傌","車","相","仕","帥"}; static char *bname[]={"卒","包","馬","車","象","士","將"}; diff --git a/pttbbs/mbbsd/dice.c b/pttbbs/mbbsd/dice.c index e4aa8869..32ef7f5b 100644 --- a/pttbbs/mbbsd/dice.c +++ b/pttbbs/mbbsd/dice.c @@ -1,13 +1,5 @@ -/* $Id: dice.c,v 1.2 2002/04/28 19:35:29 in2 Exp $ */ -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <sys/types.h> -#include "config.h" -#include "pttstruct.h" -#include "common.h" -#include "modes.h" -#include "proto.h" +/* $Id: dice.c,v 1.3 2002/06/04 13:08:33 in2 Exp $ */ +#include "bbs.h" #define DICE_TXT BBSHOME "/etc/dice.txt" #define DICE_DATA BBSHOME "/etc/dice.data" @@ -20,7 +12,6 @@ #define B_TIMES 5 #define B_THIRD 3 -extern int usernum; static int flag[100], value[100]; typedef struct dicedata_t { @@ -173,8 +164,6 @@ static int check_index(int index) { return 0; } -extern userec_t cuser; - static int del(int total, dicedata_t *table) { int index, money; char data[10]; diff --git a/pttbbs/mbbsd/edit.c b/pttbbs/mbbsd/edit.c index f6a14766..b9dc41ba 100644 --- a/pttbbs/mbbsd/edit.c +++ b/pttbbs/mbbsd/edit.c @@ -1,21 +1,5 @@ -/* $Id: edit.c,v 1.10 2002/05/14 17:13:45 ptt Exp $ */ -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <ctype.h> -#include <unistd.h> -#include <time.h> -#include <sys/types.h> -#include "config.h" -#include "pttstruct.h" -#include "config.h" -#include "common.h" -#include "modes.h" -#include "perm.h" -#include "proto.h" - -#define WRAPMARGIN (511) - +/* $Id: edit.c,v 1.11 2002/06/04 13:08:33 in2 Exp $ */ +#include "bbs.h" typedef struct textline_t { struct textline_t *prev; struct textline_t *next; @@ -23,29 +7,6 @@ typedef struct textline_t { char data[WRAPMARGIN + 1]; } textline_t; -extern int current_font_type; -extern char *str_author1; -extern char *str_author2; -extern int t_lines, t_columns; /* Screen size / width */ -extern int b_lines; /* Screen bottom line number: t_lines-1 */ -extern char quote_file[80]; -extern char quote_user[80]; -extern int curredit; -extern unsigned int currbrdattr; -extern char currboard[]; /* name of currently selected board */ -extern char *str_reply; -extern char *str_post1; -extern char *str_post2; -extern char *BBSName; -extern char fromhost[]; -extern unsigned int currstat; -extern crosspost_t postrecord; -extern userinfo_t *currutmp; -extern int KEY_ESC_arg; -extern char reset_color[]; -extern char trans_buffer[256]; -extern time_t now; - #define KEEP_EDITING -2 #define BACKUP_LIMIT 100 #define SCR_WIDTH 80 @@ -61,8 +22,6 @@ static textline_t *blockline = NULL; static textline_t *top_of_win = NULL; static textline_t *deleted_lines = NULL; -extern int local_article; -extern char real_name[IDLEN + 1]; static char line[WRAPMARGIN + 2]; static int ifuseanony=0; static int currpnt, currln, totaln; @@ -82,8 +41,6 @@ static int insert_c = ' '; static char fp_bak[] = "bak"; -char save_title[STRLEN]; - /* 記憶體管理與編輯處理 */ static void indigestion(i) { fprintf(stderr, "嚴重內傷 %d\n", i); @@ -733,8 +690,6 @@ static void read_file(char *fpath) { load_file(fp); } -extern userec_t cuser; - void write_header(FILE *fp) { if(curredit & EDIT_MAIL || curredit & EDIT_LIST) { diff --git a/pttbbs/mbbsd/friend.c b/pttbbs/mbbsd/friend.c index bac0674e..d772ad8c 100644 --- a/pttbbs/mbbsd/friend.c +++ b/pttbbs/mbbsd/friend.c @@ -1,26 +1,5 @@ -/* $Id: friend.c,v 1.5 2002/04/28 19:35:29 in2 Exp $ */ -#include <stdio.h> -#include <string.h> -#include <stdlib.h> -#include <unistd.h> -#include <sys/types.h> -#include <sys/file.h> -#include "config.h" -#include "pttstruct.h" -#include "common.h" -#include "perm.h" -#include "proto.h" -#include "modes.h" - -extern userec_t cuser; -extern int currmode; -extern char currboard[]; /* name of currently selected board */ -extern char *fn_overrides; -extern userinfo_t *currutmp; -extern char *fn_reject; -extern int usernum; -extern char *str_space; -extern char *msg_uid; +/* $Id: friend.c,v 1.6 2002/06/04 13:08:33 in2 Exp $ */ +#include "bbs.h" /* ------------------------------------- */ /* 特別名單 */ @@ -43,17 +22,6 @@ static unsigned int friend_max[8] = { }; /* 雖然好友跟壞人名單都是 * 2 但是一次最多load到shm只能有128 */ -/* Ptt 各種特別名單的檔名 */ -char *friend_file[8] = { - FN_OVERRIDES, - FN_REJECT, - "alohaed", - "postlist", - "", - FN_CANVOTE, - FN_WATER, - FN_VISABLE -}; /* Ptt 各種特別名單的補述 */ static char *friend_desc[8] = { @@ -324,8 +292,6 @@ void friend_load() { login_friend_online(); } -extern userec_t cuser; - static void friend_water(char *message, int type) { /* 群體水球 added by Ptt */ char fpath[80], line[80], userid[IDLEN + 1]; FILE *fp; diff --git a/pttbbs/mbbsd/gamble.c b/pttbbs/mbbsd/gamble.c index 64f04848..541dd451 100644 --- a/pttbbs/mbbsd/gamble.c +++ b/pttbbs/mbbsd/gamble.c @@ -1,22 +1,7 @@ -/* $Id: gamble.c,v 1.3 2002/05/13 03:20:04 ptt Exp $ */ -#include <stdio.h> -#include <time.h> -#include <string.h> -#include <sys/types.h> -#include <stdlib.h> -#include <unistd.h> -#include "config.h" -#include "pttstruct.h" -#include "common.h" -#include "modes.h" -#include "proto.h" -extern int usernum; +/* $Id: gamble.c,v 1.4 2002/06/04 13:08:33 in2 Exp $ */ +#include "bbs.h" #ifndef _BBS_UTIL_C_ -extern userec_t cuser; -extern int b_lines; -extern time_t now; - #define MAX_ITEM 8 //最大 賭項(item) 個數 #define MAX_ITEM_LEN 30 //最大 每一賭項名字長度 #define MAX_SUBJECT_LEN 650 //8*81 = 648 最大 主題長度 diff --git a/pttbbs/mbbsd/gomo.c b/pttbbs/mbbsd/gomo.c index a8174d7f..6969df7a 100644 --- a/pttbbs/mbbsd/gomo.c +++ b/pttbbs/mbbsd/gomo.c @@ -1,28 +1,9 @@ -/* $Id: gomo.c,v 1.4 2002/05/25 11:18:11 ptt Exp $ */ -#include <stdio.h> -#include <stdlib.h> -#include <unistd.h> -#include <time.h> -#include <sys/types.h> -#include <sys/socket.h> -#include <string.h> -#include "config.h" -#include "pttstruct.h" -#include "gomo.h" -#include "common.h" -#include "modes.h" -#include "proto.h" +/* $Id: gomo.c,v 1.5 2002/06/04 13:08:33 in2 Exp $ */ +#include "bbs.h" -extern int usernum; -extern userinfo_t *currutmp; -extern time_t now; - -char ku[BRDSIZ][BRDSIZ]; static char *chess[] = { "●", "○" }; static int tick, lastcount, mylasttick, hislasttick; -unsigned char *pat, *adv; - typedef struct { char x; char y; @@ -55,8 +36,6 @@ static void HO_undo(Horder_t *mv) { prints("%.2s", str + loc); } -extern userec_t cuser; - static void HO_log(char *user) { int i; FILE *log; @@ -64,7 +43,6 @@ static void HO_log(char *user) { char buf1[80]; char title[80]; Horder_t *ptr = pool; - extern screenline_t *big_picture; fileheader_t mymail; sprintf(buf, "home/%c/%s/F.%d", cuser.userid[0], cuser.userid, @@ -165,8 +143,6 @@ static int gomo_key(int fd, int ch, Horder_t *mv) { return 0; } -extern userec_t xuser; - static int reload_gomo() { passwd_query(usernum, &xuser); cuser.five_win = xuser.five_win; diff --git a/pttbbs/mbbsd/gomo1.c b/pttbbs/mbbsd/gomo1.c index 953bad2d..c741f538 100644 --- a/pttbbs/mbbsd/gomo1.c +++ b/pttbbs/mbbsd/gomo1.c @@ -1,24 +1,9 @@ -/* $Id: gomo1.c,v 1.1 2002/03/07 15:13:48 in2 Exp $ */ -#include <stdio.h> -#include <stdlib.h> -#include <sys/types.h> -#include "config.h" -#include "pttstruct.h" -#include "proto.h" +/* $Id: gomo1.c,v 1.2 2002/06/04 13:08:33 in2 Exp $ */ +#include "bbs.h" #define QCAST int (*)(const void *, const void *) -#define BBLANK (0) /* 空白 */ -#define BBLACK (1) /* 黑子, 先手 */ -#define BWHITE (2) /* 白子, 後手 */ -#ifndef BRDSIZ -#define BRDSIZ (15) /* 棋盤單邊大小 */ -#endif - -extern char ku[BRDSIZ][BRDSIZ]; - /* pattern and advance map */ -extern unsigned char *pat, *adv; static int intrevcmp(const void *a, const void *b) { return (*(int *)b - *(int *)a); @@ -62,7 +47,7 @@ int chkwin(int style, int limit) { /* x,y: 0..BRDSIZ-1 ; color: CBLACK,CWHITE ; limit:1,0 ; dx,dy: 0,1 */ static int dirchk(int x, int y, int color, int limit, int dx, int dy) { - int le, ri, loc, style; + int le, ri, loc, style = 0; le = gomo_getindex(x, y, color, -dx, -dy); ri = gomo_getindex(x, y, color, dx, dy); @@ -78,7 +63,7 @@ static int dirchk(int x, int y, int color, int limit, int dx, int dy) { style >>= 4; if((style == 3) || (style == 2)) { - int i, n, tmp, nx, ny; + int i, n = 0, tmp, nx, ny; n = adv[loc >> 1]; diff --git a/pttbbs/mbbsd/guess.c b/pttbbs/mbbsd/guess.c index c24b8361..2a7e6fdb 100644 --- a/pttbbs/mbbsd/guess.c +++ b/pttbbs/mbbsd/guess.c @@ -1,16 +1,5 @@ -/* $Id: guess.c,v 1.2 2002/04/28 19:35:29 in2 Exp $ */ -#include <stdio.h> -#include <stdlib.h> -#include <sys/types.h> -#include <string.h> -#include "config.h" -#include "pttstruct.h" -#include "common.h" -#include "modes.h" -#include "proto.h" - -extern char *BBSName; -extern int usernum; +/* $Id: guess.c,v 1.3 2002/06/04 13:08:33 in2 Exp $ */ +#include "bbs.h" #define LOGPASS BBSHOME "/etc/winguess.log" static void show_table(char TABLE[], char ifcomputer) { @@ -31,8 +20,6 @@ static void show_table(char TABLE[], char ifcomputer) { prints("\033[33m=================\033[m"); } -extern userec_t cuser; - static unsigned long int get_money(void) { int money, i; char data[20]; diff --git a/pttbbs/mbbsd/indict.c b/pttbbs/mbbsd/indict.c index 51e20590..8861b320 100644 --- a/pttbbs/mbbsd/indict.c +++ b/pttbbs/mbbsd/indict.c @@ -1,20 +1,10 @@ -/* $Id: indict.c,v 1.2 2002/04/28 19:35:29 in2 Exp $ */ -#include <stdio.h> -#include <string.h> -#include <sys/types.h> -#include "config.h" -#include "pttstruct.h" -#include "perm.h" -#include "common.h" -#include "modes.h" -#include "proto.h" +/* $Id: indict.c,v 1.3 2002/06/04 13:08:33 in2 Exp $ */ +#include "bbs.h" #define REFER "etc/dicts" -extern userec_t cuser; -char dict[41],database[41]; - -static void addword(char word[]) { +static void addword(char word[]) +{ char buf[150],temp[150],a[3]; FILE *fp = fopen(database,"r+"); diff --git a/pttbbs/mbbsd/io.c b/pttbbs/mbbsd/io.c index f553db74..12459063 100644 --- a/pttbbs/mbbsd/io.c +++ b/pttbbs/mbbsd/io.c @@ -1,21 +1,5 @@ -/* $Id: io.c,v 1.16 2002/05/15 08:55:30 ptt Exp $ */ -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <ctype.h> -#include <time.h> -#include <unistd.h> -#include <errno.h> -#include <sys/types.h> -#include <sys/time.h> -#include <sys/ioctl.h> -#include <signal.h> -#include "config.h" -#include "pttstruct.h" -#include "perm.h" -#include "modes.h" -#include "common.h" -#include "proto.h" +/* $Id: io.c,v 1.17 2002/06/04 13:08:33 in2 Exp $ */ +#include "bbs.h" #if defined(linux) #define OBUFSIZE 2048 @@ -25,23 +9,10 @@ #define IBUFSIZE 256 #endif -extern int current_font_type; -extern char *fn_proverb; -extern userinfo_t *currutmp; -extern unsigned int currstat; -extern pid_t currpid; -extern int errno; -extern screenline_t *big_picture; -extern int t_lines, t_columns; /* Screen size / width */ -extern water_t water[6], *swater[5], *water_which; -extern char water_usies; - static char outbuf[OBUFSIZE], inbuf[IBUFSIZE]; static int obufsize = 0, ibufsize = 0; static int icurrchar = 0; -time_t now; - /* ----------------------------------------------------- */ /* output routines */ /* ----------------------------------------------------- */ @@ -101,22 +72,6 @@ int num_in_buf() { return icurrchar - ibufsize; } -int watermode = -1, wmofo = -1; -/* - WATERMODE(WATER_ORIG) | WATERMODE(WATER_NEW): - Ptt 水球回顧用的參數 - watermode = -1 沒在回水球 - = 0 在回上一顆水球 (Ctrl-R) - > 0 在回前 n 顆水球 (Ctrl-R Ctrl-R) - - WATERMODE(WATER_OFO) by in2 - wmofo = -1 沒在回水球 - = 0 正在回水球 - = 1 回水球間又接到水球 - wmofo >=0 時收到水球將只顯示, 不會到water[]裡, - 待回完水球的時候一次寫入. -*/ - /* dogetch() is not reentrant-safe. SIGUSR[12] might happen at any time, and dogetch() might be called again, and then ibufsize/icurrchar/inbuf @@ -181,7 +136,7 @@ static int dogetch() { } return inbuf[icurrchar++]; } -extern userec_t cuser; + static int water_which_flag=0; int igetch() { register int ch; @@ -343,7 +298,6 @@ int oldgetdata(int line, int col, char *prompt, char *buf, int len, int echo) { register int ch, i; int clen; int x = col, y = line; - extern unsigned char scr_cols; #define MAXLASTCMD 12 static char lastcmd[MAXLASTCMD][80]; @@ -563,8 +517,6 @@ rget(int x,char *prompt) } -int KEY_ESC_arg; - int igetkey() { int mode; int ch, last; diff --git a/pttbbs/mbbsd/kaede.c b/pttbbs/mbbsd/kaede.c index d3f9355b..d9c33589 100644 --- a/pttbbs/mbbsd/kaede.c +++ b/pttbbs/mbbsd/kaede.c @@ -1,17 +1,5 @@ -/* $Id: kaede.c,v 1.2 2002/05/13 03:20:04 ptt Exp $ */ -#include <stdio.h> -#include <string.h> -#include <time.h> -#include <unistd.h> -#include <stdlib.h> -#include <sys/types.h> -#include "config.h" -#include "pttstruct.h" -#include "proto.h" - -extern struct utmpfile_t *utmpshm; -extern userec_t cuser; -extern time_t now; +/* $Id: kaede.c,v 1.3 2002/06/04 13:08:33 in2 Exp $ */ +#include "bbs.h" char *Ptt_prints(char *str, int mode) { char *po , strbuf[256]; diff --git a/pttbbs/mbbsd/lovepaper.c b/pttbbs/mbbsd/lovepaper.c index f4b8b56c..4c96f461 100644 --- a/pttbbs/mbbsd/lovepaper.c +++ b/pttbbs/mbbsd/lovepaper.c @@ -1,21 +1,7 @@ -/* $Id: lovepaper.c,v 1.4 2002/05/25 11:18:11 ptt Exp $ */ -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <time.h> -#include <unistd.h> -#include <sys/types.h> -#include "config.h" -#include "pttstruct.h" -#include "modes.h" -#include "common.h" -#include "proto.h" - +/* $Id: lovepaper.c,v 1.5 2002/06/04 13:08:33 in2 Exp $ */ +#include "bbs.h" #define DATA "etc/lovepaper.dat" -extern userec_t cuser; -extern time_t now; - int x_love() { char buf1[200], save_title[TTLEN + 1]; char receiver[61], path[STRLEN] = "home/"; diff --git a/pttbbs/mbbsd/mail.c b/pttbbs/mbbsd/mail.c index 9f7da59a..14325216 100644 --- a/pttbbs/mbbsd/mail.c +++ b/pttbbs/mbbsd/mail.c @@ -1,50 +1,5 @@ -/* $Id: mail.c,v 1.10 2002/05/25 17:49:48 ptt Exp $ */ -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <unistd.h> -#include <fcntl.h> -#include <sys/types.h> -#include <sys/stat.h> -#include <string.h> -#include "config.h" -#include "pttstruct.h" -#include "common.h" -#include "perm.h" -#include "modes.h" -#include "proto.h" - -extern struct bcache_t *brdshm; -extern int TagNum; -extern int b_lines; /* Screen bottom line number: t_lines-1 */ -extern char save_title[]; /* used by editor when inserting */ -extern int curredit; -extern char *err_uid; -extern char *msg_cancel; -extern char *msg_uid; -extern char *fn_overrides; -extern char quote_file[80]; -extern char quote_user[80]; -extern char *fn_notes; -extern char *msg_mailer; -extern char *msg_sure_ny; -extern char *BBSName; -extern char currtitle[TTLEN + 1]; -extern unsigned char currfmode; /* current file mode */ -extern char *msg_del_ny; -extern char currfile[FNLEN]; -extern int currmode; -extern char currboard[]; /* name of currently selected board */ -extern char *str_space; -extern char *str_author1; -extern char *str_author2; -extern userinfo_t *currutmp; -extern unsigned int currstat; -extern pid_t currpid; -extern int usernum; -extern char *str_mail_address; -extern userec_t cuser; -extern time_t now; +/* $Id: mail.c,v 1.11 2002/06/04 13:08:33 in2 Exp $ */ +#include "bbs.h" char currmaildir[32]; static char msg_cc[] = "\033[32m[群組名單]\033[m\n"; static char listfile[] = "list.0"; @@ -238,8 +193,6 @@ static void do_hold_mail(char *fpath, char *receiver, char *holder) { do_append(title, &mymail, sizeof(mymail)); } -extern userec_t xuser; - void hold_mail(char *fpath, char *receiver) { char buf[4]; @@ -361,8 +314,6 @@ int m_send() { } /* 群組寄信、回信 : multi_send, multi_reply */ -extern struct word_t *toplev; - static void multi_list(int *reciper) { char uid[16]; char genbuf[200]; @@ -441,7 +392,7 @@ static void multi_list(int *reciper) { static void multi_send(char *title) { FILE *fp; - struct word_t *p; + struct word_t *p = NULL; fileheader_t mymail; char fpath[TTLEN], *ptr; int reciper, listing; @@ -580,7 +531,6 @@ int mail_all() { fileheader_t mymail; char fpath[TTLEN]; char genbuf[200]; - extern struct uhash_t *uhash; int i, unum; char *userid; @@ -851,11 +801,6 @@ static void maildoent(int num, fileheader_t *ent) { ent->date, ent->owner, color, mark, title); } -#ifdef POSTBUG -extern int bug_possible; -#endif - - static int m_idle(int ent, fileheader_t *fhdr, char *direct) { t_idle(); return FULLUPDATE; diff --git a/pttbbs/mbbsd/mbbsd.c b/pttbbs/mbbsd/mbbsd.c index e964c2c0..036976f6 100644 --- a/pttbbs/mbbsd/mbbsd.c +++ b/pttbbs/mbbsd/mbbsd.c @@ -1,63 +1,21 @@ -/* $Id: mbbsd.c,v 1.31 2002/05/24 18:24:22 ptt Exp $ */ -#include <stdio.h> -#include <string.h> -#include <stdlib.h> -#include <setjmp.h> -#include <signal.h> -#include <unistd.h> -#include <fcntl.h> -#include <syslog.h> -#include <errno.h> -#include <netdb.h> -#include <time.h> -#include <sys/types.h> -#include <sys/stat.h> -#include <sys/wait.h> -#include <sys/socket.h> -#include <sys/time.h> -#include <sys/resource.h> -#include <netinet/in.h> -#include <arpa/inet.h> -#include <arpa/telnet.h> -#include "config.h" -#include "pttstruct.h" -#include "common.h" -#include "perm.h" -#include "modes.h" -#include "proto.h" -#ifdef FreeBSD - #include <machine/limits.h> -#else - #include <limits.h> -#endif +/* $Id: mbbsd.c,v 1.32 2002/06/04 13:08:33 in2 Exp $ */ +#include "bbs.h" #define SOCKET_QLEN 4 #define TH_LOW 100 #define TH_HIGH 120 -extern int t_lines, t_columns; /* Screen size / width */ -extern int b_lines; /* Screen bottom line number: t_lines-1 */ -extern userinfo_t *currutmp; -extern time_t now; static void do_aloha (char *hello); #if 0 static jmp_buf byebye; #endif -int talkrequest = NA; - static char remoteusername[40] = "?"; -extern struct fromcache_t *fcache; -extern struct utmpfile_t *utmpshm; -extern int fcache_semid; - static unsigned char enter_uflag; static int use_shell_login_mode = 0; -char fromhost[STRLEN] = "\0"; - static struct sockaddr_in xsin; /* set signal handler, which won't be reset once signal comes */ @@ -152,8 +110,6 @@ chkload (char *buf) return 0; } -extern userec_t cuser; - void log_user (char *msg) { @@ -164,7 +120,6 @@ log_user (char *msg) log_file (filename, msg); } -extern time_t login_start_time; void log_usies (char *mode, char *mesg) @@ -195,9 +150,6 @@ setflags (int mask, int value) cuser.uflag &= ~mask; } -extern int usernum; -extern int currmode; - void u_exit (char *mode) { @@ -278,8 +230,6 @@ mysrand () srand (time (NULL) + currutmp->pid); /* 時間跟 pid 當 rand 的 seed */ } -extern userec_t xuser; - int dosearchuser (char *userid) { @@ -312,7 +262,6 @@ talk_request(int sig) unsigned char mode0 = currutmp->mode; char c0 = currutmp->chatid[0]; screenline_t *screen0 = calloc (t_lines, sizeof (screenline_t)); - extern screenline_t *big_picture; currutmp->mode = 0; currutmp->chatid[0] = 1; @@ -326,9 +275,6 @@ talk_request(int sig) } } -extern char *fn_writelog; -FILE *fp_writelog = NULL; - void show_call_in(int save, int which) { @@ -354,10 +300,6 @@ show_call_in(int save, int which) } } -extern unsigned int currstat; -water_t water[6], *swater[6], *water_which=&water[0]; -char water_usies=0; -extern int watermode, wmofo; static int add_history_water(water_t *w, msgque_t *msg) { // mode: 1: all data(including userid, pid); @@ -568,16 +510,12 @@ logattempt (char *uid, char type) } } -extern char *str_new; -extern char *err_uid; - static void login_query () { char uid[IDLEN + 1], passbuf[PASSLEN]; int attempts; char genbuf[200]; - extern struct utmpfile_t *utmpshm; resolve_utmp (); resolve_garbage (); attach_uhash (); @@ -772,17 +710,12 @@ check_BM () { int i; boardheader_t *bhdr; - extern boardheader_t *bcache; - extern int numboards; cuser.userlevel &= ~PERM_BM; for (i = 0, bhdr = bcache; i < numboards && !is_BM (bhdr->BM); i++, bhdr++) ; } -extern pid_t currpid; -extern crosspost_t postrecord; - static void setup_utmp (int mode) { @@ -836,10 +769,6 @@ setup_utmp (int mode) #endif } -extern char margs[]; -extern char *str_sysop; -extern char *loginview_file[NUMVIEWFILE][2]; - static void user_login () { @@ -1005,13 +934,9 @@ do_term_init () initscr (); } -extern char *fn_register; -extern int showansi; - static void start_client () { - extern struct commands_t cmdlist[]; #ifdef CPULIMIT struct rlimit rml; rml.rlim_cur = CPULIMIT * 60; @@ -1248,9 +1173,6 @@ bind_port (int port) static void shell_login (int argc, char *argv[], char *envp[]); static void daemon_login (int argc, char *argv[], char *envp[]); static int check_ban_and_load (int fd); -#ifdef SUPPORT_GB -extern int current_font_type; -#endif int main (int argc, char *argv[], char *envp[]) diff --git a/pttbbs/mbbsd/menu.c b/pttbbs/mbbsd/menu.c index 5108606e..cbdb0871 100644 --- a/pttbbs/mbbsd/menu.c +++ b/pttbbs/mbbsd/menu.c @@ -1,27 +1,6 @@ -/* $Id: menu.c,v 1.8 2002/05/13 03:20:04 ptt Exp $ */ -#include <stdio.h> -#include <stdlib.h> -#include <time.h> -#include <sys/types.h> -#include <string.h> -#include <unistd.h> -#include "config.h" -#include "pttstruct.h" -#include "common.h" -#include "perm.h" -#include "modes.h" -#include "proto.h" -extern int usernum; -extern int talkrequest; -extern char *fn_register; -extern char currboard[]; /* name of currently selected board */ -extern int currmode; -extern unsigned int currstat; -extern char reset_color[]; -extern userinfo_t *currutmp; -extern char *BBSName; -extern int b_lines; /* Screen bottom line number: t_lines-1 */ -extern time_t now; +/* $Id: menu.c,v 1.9 2002/06/04 13:08:33 in2 Exp $ */ +#include "bbs.h" + /* help & menu processring */ static int refscreen = NA; extern char *boardprefix; @@ -554,52 +533,45 @@ static int forsearch() { /* main menu */ -static int admin() { +int admin() +{ domenu(ADMIN, "系統維護", 'X', adminlist); return 0; } -static int Mail() { +int Mail() +{ domenu(MAIL, "電子郵件", 'R', maillist); return 0; } -static int Talk() { +int Talk() +{ domenu(TMENU, "聊天說話", 'U', talklist); return 0; } -static int User() { +int User() +{ domenu(UMENU, "個人設定", 'A', userlist); return 0; } -static int Xyz() { +int Xyz() +{ domenu(XMENU, "工具程式", 'M', xyzlist); return 0; } -static int Play_Play() { +int Play_Play() +{ domenu(PMENU, "網路遊樂場", 'A', playlist); return 0; } -static int Name_Menu() { +int Name_Menu() +{ domenu(NMENU, "白色恐怖", 'O', namelist); return 0; } -commands_t cmdlist[] = { - {admin,PERM_SYSOP|PERM_VIEWSYSOP, "00Admin 【 系統維護區 】"}, - {Announce, 0, "AAnnounce 【 精華公佈欄 】"}, - {Boards, 0, "FFavorite 【 我 的 最愛 】"}, - {root_board, 0, "CClass 【 分組討論區 】"}, - {Mail, PERM_BASIC, "MMail 【 私人信件區 】"}, - {Talk, 0, "TTalk 【 休閒聊天區 】"}, - {User, 0, "UUser 【 個人設定區 】"}, - {Xyz, 0, "XXyz 【 系統工具區 】"}, - {Play_Play,0, "PPlay 【 遊樂場/大學查榜】"}, - {Name_Menu,PERM_LOGINOK, "NNamelist 【 編特別名單 】"}, - {Goodbye, 0, "GGoodbye 離開,再見……"}, - {NULL, 0, NULL} -}; diff --git a/pttbbs/mbbsd/more.c b/pttbbs/mbbsd/more.c index 87d71fe9..1d6b173a 100644 --- a/pttbbs/mbbsd/more.c +++ b/pttbbs/mbbsd/more.c @@ -1,30 +1,5 @@ -/* $Id: more.c,v 1.13 2002/05/13 03:20:04 ptt Exp $ */ -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <unistd.h> -#include <fcntl.h> -#include <time.h> -#include <sys/types.h> -#include <sys/stat.h> - -#include "config.h" -#include "pttstruct.h" -#include "common.h" -#include "modes.h" -#include "perm.h" -#include "proto.h" - -extern int showansi; -extern int t_lines, t_columns; /* Screen size / width */ -extern int b_lines; /* Screen bottom line number: t_lines-1 */ -extern char *str_author1; -extern char *str_author2; -extern char *str_post1; -extern char *str_post2; -extern char *msg_seperator; -extern char reset_color[]; -extern time_t now; +/* $Id: more.c,v 1.14 2002/06/04 13:08:34 in2 Exp $ */ +#include "bbs.h" #define MORE_BUFSIZE 4096 #define MORE_WINSIZE 4096 #define STR_ANSICODE "[0123456789;," @@ -190,12 +165,8 @@ static int readln(FILE *fp, char *buf) { } */ -extern userec_t cuser; - static int more_web(char *fpath, int promptend); -extern int *GLOBE; int more(char *fpath, int promptend) { - extern char* strcasestr(); static char *head[4] = {"作者", "標題", "時間" ,"轉信"}; char *ptr, *word = NULL, buf[ANSILINELEN + 1], *ch1; struct stat st; diff --git a/pttbbs/mbbsd/name.c b/pttbbs/mbbsd/name.c index 192ead3d..b78b54d1 100644 --- a/pttbbs/mbbsd/name.c +++ b/pttbbs/mbbsd/name.c @@ -1,24 +1,6 @@ -/* $Id: name.c,v 1.6 2002/05/24 16:45:39 in2 Exp $ */ -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <ctype.h> -#include <signal.h> -#include <sys/types.h> -#include "config.h" -#include "pttstruct.h" -#include "common.h" -#include "proto.h" -#include "perm.h" - -extern struct bcache_t *brdshm; -extern struct utmpfile_t *utmpshm; -extern userec_t cuser; -extern char *str_space; -extern int p_lines; /* a Page of Screen line numbers: tlines-4 */ -extern int b_lines; /* Screen bottom line number: t_lines-1 */ - -word_t *toplev = NULL; +/* $Id: name.c,v 1.7 2002/06/04 13:08:34 in2 Exp $ */ +#include "bbs.h" + static word_t *current = NULL; static char *msg_more = "\033[7m-- More --\033[m"; diff --git a/pttbbs/mbbsd/osdep.c b/pttbbs/mbbsd/osdep.c index 5f99da22..315cdb51 100644 --- a/pttbbs/mbbsd/osdep.c +++ b/pttbbs/mbbsd/osdep.c @@ -1,9 +1,5 @@ -/* $Id: osdep.c,v 1.2 2002/05/15 09:14:24 ptt Exp $ */ -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <fcntl.h> -#include <unistd.h> +/* $Id: osdep.c,v 1.3 2002/06/04 13:08:34 in2 Exp $ */ +#include "bbs.h" #if __FreeBSD__ diff --git a/pttbbs/mbbsd/othello.c b/pttbbs/mbbsd/othello.c index 888a483e..4a146f77 100644 --- a/pttbbs/mbbsd/othello.c +++ b/pttbbs/mbbsd/othello.c @@ -1,15 +1,5 @@ -/* $Id: othello.c,v 1.2 2002/04/28 19:35:29 in2 Exp $ */ -#include <stdio.h> -#include <stdlib.h> -#include <sys/types.h> -#include <string.h> -#include "config.h" -#include "pttstruct.h" -#include "common.h" -#include "modes.h" -#include "proto.h" - -extern char *BBSName; +/* $Id: othello.c,v 1.3 2002/06/04 13:08:34 in2 Exp $ */ +#include "bbs.h" #define LOGFILE "etc/othello.log" #define SECRET "etc/othello.secret" @@ -81,8 +71,6 @@ static void print_chess(int x, int y, char chess) { refresh(); } -extern userec_t cuser; - static void printboard() { int i; diff --git a/pttbbs/mbbsd/page.c b/pttbbs/mbbsd/page.c index 05b2f744..b39f7d7e 100644 --- a/pttbbs/mbbsd/page.c +++ b/pttbbs/mbbsd/page.c @@ -1,14 +1,5 @@ -/* $Id: page.c,v 1.4 2002/05/25 11:18:11 ptt Exp $ */ -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <unistd.h> -#include <sys/types.h> -#include "config.h" -#include "pttstruct.h" -#include "modes.h" -#include "common.h" -#include "proto.h" +/* $Id: page.c,v 1.5 2002/06/04 13:08:34 in2 Exp $ */ +#include "bbs.h" #define hpressanykey(a) {move(22, 0); prints(a); pressanykey();} static void filt_railway(char* fpath) { @@ -31,8 +22,6 @@ static void filt_railway(char* fpath) { unlink(tmppath); } -extern userec_t cuser; - int main_railway() { fileheader_t mhdr; char genbuf[200]; diff --git a/pttbbs/mbbsd/passwd.c b/pttbbs/mbbsd/passwd.c index 28a31119..cfc7361a 100644 --- a/pttbbs/mbbsd/passwd.c +++ b/pttbbs/mbbsd/passwd.c @@ -1,21 +1,5 @@ -/* $Id: passwd.c,v 1.1 2002/03/07 15:13:48 in2 Exp $ */ -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <fcntl.h> -#include <unistd.h> -#include <errno.h> -#include <sys/types.h> -#include <sys/stat.h> -#include <sys/mman.h> -#include <sys/ipc.h> -#include <sys/sem.h> -#include "config.h" -#include "pttstruct.h" -#include "modes.h" -#include "proto.h" - -extern char *fn_passwd; +/* $Id: passwd.c,v 1.2 2002/06/04 13:08:34 in2 Exp $ */ +#include "bbs.h" static userec_t *passwd_image = NULL; static int passwd_image_size; @@ -85,7 +69,6 @@ int passwd_mmap() { return 0; } -extern int usernum; int passwd_update_money(int num) { int money; if(num < 1 || num > MAX_USERS) diff --git a/pttbbs/mbbsd/read.c b/pttbbs/mbbsd/read.c index 5866422e..7e598f53 100644 --- a/pttbbs/mbbsd/read.c +++ b/pttbbs/mbbsd/read.c @@ -1,72 +1,17 @@ -/* $Id: read.c,v 1.3 2002/04/29 07:05:45 in2 Exp $ */ -#include <stdio.h> -#include <string.h> -#include <ctype.h> -#include <unistd.h> -#include <stdlib.h> -#include <fcntl.h> -#include <sys/types.h> -#include <sys/stat.h> -#include "config.h" -#include "pttstruct.h" -#include "modes.h" -#include "common.h" -#include "perm.h" -#include "proto.h" +/* $Id: read.c,v 1.4 2002/06/04 13:08:34 in2 Exp $ */ +#include "bbs.h" #define MAXPATHLEN 256 -extern int p_lines; /* a Page of Screen line numbers: tlines-4 */ -extern int b_lines; /* Screen bottom line number: t_lines-1 */ -extern char currowner[IDLEN + 2]; -extern char currtitle[TTLEN + 1]; -extern char currauthor[IDLEN + 2]; -extern char *str_reply; -extern char *msg_fwd_ok; -extern char *msg_fwd_err1; -extern char *msg_fwd_err2; -extern int currmode; -extern unsigned int currstat; -extern char currboard[]; /* name of currently selected board */ -extern int KEY_ESC_arg; -extern int curredit; -extern char *msg_mailer; -extern int currbid; -extern bcache_t *brdshm; - -char currdirect[64]; static fileheader_t *headers = NULL; static int last_line; static int hit_thread; -/* rocker.011018: add new tag */ - -extern int rget(); -extern char getans(); -extern void touchdircache(); -extern int get_fileheader_cache(); - -/* rocker.011018: 新的tag方式 */ - -#define MAXTAGS 256 - #include <sys/mman.h> -typedef struct -{ - time_t chrono; - int recno; -} TagItem; - - /* ----------------------------------------------------- */ /* Tag List 標籤 */ /* ----------------------------------------------------- */ - - -int TagNum; /* tag's number */ -TagItem TagList[MAXTAGS]; /* ascending list */ - void UnTagger (int locus) { @@ -507,8 +452,6 @@ static void mail_forward(fileheader_t *fhdr, char *direct, int mode) { } #endif -extern userec_t cuser; - static int select_read(keeploc_t *locmem, int sr_mode) { register char *tag,*query,*temp; fileheader_t fh; @@ -606,8 +549,6 @@ static int select_read(keeploc_t *locmem, int sr_mode) { return st.st_size; } -extern userec_t xuser; - static int i_read_key(onekey_t *rcmdlist, keeploc_t *locmem, int ch, int bid) { int i, mode = DONOTHING; diff --git a/pttbbs/mbbsd/record.c b/pttbbs/mbbsd/record.c index 2f82b372..a29988b7 100644 --- a/pttbbs/mbbsd/record.c +++ b/pttbbs/mbbsd/record.c @@ -1,23 +1,9 @@ -/* $Id: record.c,v 1.4 2002/05/13 03:20:04 ptt Exp $ */ -#include <stdio.h> -#include <stdlib.h> -#include <errno.h> -#include <string.h> -#include <unistd.h> -#include <time.h> -#include <sys/types.h> -#include <sys/stat.h> -#include <sys/file.h> -#include "config.h" -#include "pttstruct.h" -#include "modes.h" -#include "proto.h" +/* $Id: record.c,v 1.5 2002/06/04 13:08:34 in2 Exp $ */ +#include "bbs.h" #undef HAVE_MMAP #define BUFSIZE 512 -extern char *str_reply; -extern time_t now; static void PttLock(int fd, int size, int mode) { static struct flock lock_it; int ret; @@ -209,7 +195,6 @@ int delete_range(char *fpath, int id1, int id2) { char fullpath[STRLEN], *t; int fdr, fdw, fd; int count; - extern int Tagger(); nolfilename(&my, fpath); diff --git a/pttbbs/mbbsd/register.c b/pttbbs/mbbsd/register.c index 36b30f46..a3fa13ef 100644 --- a/pttbbs/mbbsd/register.c +++ b/pttbbs/mbbsd/register.c @@ -1,27 +1,7 @@ -/* $Id: register.c,v 1.4 2002/05/13 03:20:04 ptt Exp $ */ +/* $Id: register.c,v 1.5 2002/06/04 13:08:34 in2 Exp $ */ #define _XOPEN_SOURCE -#include <stdio.h> -#include <strings.h> -#include <string.h> -#include <unistd.h> -#include <time.h> -#include <fcntl.h> -#include <stdlib.h> -#include <unistd.h> -#include <sys/types.h> -#include <sys/stat.h> -#include "config.h" -#include "pttstruct.h" -#include "perm.h" -#include "common.h" -#include "proto.h" - -extern char *str_new; -extern char *msg_uid; -extern int t_lines, t_columns; /* Screen size / width */ -extern char *str_mail_address; -extern time_t now; +#include "bbs.h" /* password encryption */ static char pwbuf[14]; @@ -141,7 +121,6 @@ int check_and_expire_account(int uid,userec_t *urec) return val; } -extern char *fn_passwd; int getnewuserid() { char genbuf[50]; @@ -199,7 +178,6 @@ int getnewuserid() { } void new_register() { - extern userec_t xuser; userec_t newuser; char passbuf[STRLEN]; int allocid, try, id; @@ -284,7 +262,6 @@ void new_register() { } } -extern userec_t cuser; void check_register() { char *ptr = NULL; diff --git a/pttbbs/mbbsd/screen.c b/pttbbs/mbbsd/screen.c index 2c70917f..5bd9dbdb 100644 --- a/pttbbs/mbbsd/screen.c +++ b/pttbbs/mbbsd/screen.c @@ -1,30 +1,6 @@ -/* $Id: screen.c,v 1.2 2002/04/27 15:50:17 in2 Exp $ */ -#include <stdio.h> -#include <string.h> -#include <stdlib.h> -#include <stdarg.h> -#include <sys/types.h> -#include "config.h" -#include "pttstruct.h" -#include "common.h" -#include "proto.h" - -extern int t_lines, t_columns; /* Screen size / width */ -extern int b_lines; /* Screen bottom line number: t_lines-1 */ -extern int p_lines; /* a Page of Screen line numbers: tlines-4 */ -extern int showansi; - -extern char *clearbuf; -extern char *cleolbuf; -extern char *scrollrev; -extern char *strtstandout; -extern char *endstandout; -extern int clearbuflen; -extern int cleolbuflen; -extern int scrollrevlen; -extern int strtstandoutlen; -extern int endstandoutlen; -extern int automargins; +/* $Id: screen.c,v 1.3 2002/06/04 13:08:34 in2 Exp $ */ +#include "bbs.h" + #ifdef SUPPORT_GB static int current_font_type=TYPE_BIG5; static int gbinited=0; @@ -36,15 +12,12 @@ static int gbinited=0; #define o_standup() output(strtstandout,strtstandoutlen) #define o_standdown() output(endstandout,endstandoutlen) -unsigned char scr_lns, scr_cols; static unsigned char cur_ln = 0, cur_col = 0; static unsigned char docls, downfrom = 0; static unsigned char standing = NA; static char roll = 0; static int scrollcnt, tc_col, tc_line; -screenline_t *big_picture = NULL; - #define MODIFIED (1) /* if line has been modifed, screen output */ #define STANDOUT (2) /* if this line has a standout region */ @@ -157,8 +130,6 @@ void redoscr() { void refresh() { register screenline_t *bp = big_picture; register int i, j, len; - extern int automargins; - extern int scrollrevlen; if(num_in_buf()) return; diff --git a/pttbbs/mbbsd/stuff.c b/pttbbs/mbbsd/stuff.c index cede4a9d..2fa278e9 100644 --- a/pttbbs/mbbsd/stuff.c +++ b/pttbbs/mbbsd/stuff.c @@ -1,26 +1,5 @@ -/* $Id: stuff.c,v 1.2 2002/03/09 17:27:57 in2 Exp $ */ -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <stdarg.h> -#include <ctype.h> -#include <unistd.h> -#include <time.h> -#include <sys/types.h> -#include <sys/stat.h> -#include "config.h" -#include "pttstruct.h" -#include "modes.h" -#include "common.h" -#include "perm.h" -#include "proto.h" - -extern int currmode; -extern char *fn_mandex; -extern char *str_reply; -extern char *str_space; -extern int b_lines; /* Screen bottom line number: t_lines-1 */ -extern userec_t cuser; +/* $Id: stuff.c,v 1.3 2002/06/04 13:08:34 in2 Exp $ */ +#include "bbs.h" /* ----------------------------------------------------- */ /* set file path for boards/user home */ @@ -316,8 +295,6 @@ char *Cdatedate(time_t *clock){ static void capture_screen() { char fname[200]; FILE* fp; - extern screenline_t *big_picture; - extern unsigned char scr_lns; int i; getdata(b_lines - 2, 0, "把這個畫面收入到暫存檔?[y/N] ", @@ -397,7 +374,6 @@ void bell() { int search_num(int ch, int max) { int clen = 1; int x, y; - extern unsigned char scr_cols; char genbuf[10]; outmsg("\033[7m 跳至第幾項:\033[m"); diff --git a/pttbbs/mbbsd/syspost.c b/pttbbs/mbbsd/syspost.c index f1a2e70e..bbd07381 100644 --- a/pttbbs/mbbsd/syspost.c +++ b/pttbbs/mbbsd/syspost.c @@ -1,17 +1,6 @@ -/* $Id: syspost.c,v 1.9 2002/06/02 01:55:21 in2 Exp $ */ -#include <stdio.h> -#include <string.h> -#include <time.h> -#include <sys/types.h> -#include "config.h" -#include "pttstruct.h" -#include "perm.h" -#include "common.h" -#include "proto.h" +/* $Id: syspost.c,v 1.10 2002/06/04 13:08:34 in2 Exp $ */ +#include "bbs.h" -extern char *str_permid[]; -extern userec_t cuser; -extern time_t now; void post_change_perm(int oldperm, int newperm, char *sysopid, char *userid) { FILE *fp; fileheader_t fhdr; diff --git a/pttbbs/mbbsd/talk.c b/pttbbs/mbbsd/talk.c index 2324204c..3cb14c57 100644 --- a/pttbbs/mbbsd/talk.c +++ b/pttbbs/mbbsd/talk.c @@ -1,52 +1,8 @@ -/* $Id: talk.c,v 1.59 2002/06/02 08:36:56 in2 Exp $ */ -#include <stdio.h> -#include <string.h> -#include <errno.h> -#include <syslog.h> -#include <unistd.h> -#include <stdlib.h> -#include <signal.h> -#include <netdb.h> -#include <time.h> -#include <sys/types.h> -#include <sys/socket.h> -#include <netinet/in.h> -#include "config.h" -#include "pttstruct.h" -#include "common.h" -#include "perm.h" -#include "modes.h" -#include "proto.h" +/* $Id: talk.c,v 1.60 2002/06/04 13:08:34 in2 Exp $ */ +#include "bbs.h" #define QCAST int (*)(const void *, const void *) -extern userinfo_t *currutmp; -extern char *ModeTypeTable[MAX_MODES]; -extern char *fn_overrides; -extern int usernum; -extern char *msg_sure_ny; -extern char *msg_cancel; -extern unsigned int currstat; -extern char *fn_writelog; -extern FILE *fp_writelog; -extern pid_t currpid; -extern int b_lines; /* Screen bottom line number: t_lines-1 */ -extern int t_lines, t_columns; /* Screen size / width */ -extern char *fn_talklog; -extern char currauthor[IDLEN + 2]; -extern char *msg_usr_left; -extern char *msg_uid; -extern char *BBSName; -extern int p_lines; /* a Page of Screen line numbers: tlines-4 */ -extern char fromhost[]; -extern char *err_uid; -extern int talkrequest; -extern char *msg_shortulist; -extern char *msg_nobody; -extern boardheader_t *bcache; -extern userec_t cuser; -extern userec_t xuser; -extern time_t now; static char *IdleTypeTable[] = { "偶在花呆啦", "情人來電", "覓食中", "拜見周公", "假死狀態", "我在思考" }; @@ -70,12 +26,8 @@ typedef struct pickup_t { int friend, uoffset; } pickup_t; -extern int bind( /* int,struct sockaddr *, int */ ); -extern char *getuserid(); -extern struct utmpfile_t *utmpshm; -extern int watermode, wmofo; -extern water_t water[6], *swater[5], *water_which; -extern char *friend_file[8], water_usies; +//extern int bind( /* int,struct sockaddr *, int */ ); +//extern char *getuserid(); /* 記錄 friend 的 user number */ //#define PICKUP_WAYS 7 //關掉女士優先 @@ -854,7 +806,6 @@ static void do_talk_nextline(talkwin_t * twin) static void do_talk_char(talkwin_t * twin, int ch) { - extern screenline_t *big_picture; screenline_t *line; int i; char ch0, buf[81]; @@ -1094,8 +1045,6 @@ static void do_talk(int fd) if (flog){ char ans[4]; - extern screenline_t *big_picture; - extern unsigned char scr_lns; int i; fprintf(flog, "\n\033[33;44m離別畫面 [%s] ... \033[m\n", @@ -1635,10 +1584,6 @@ static void pickup(pickup_t *currpickup, int pickup_way, int *page, currpickup[got].ui = 0; } -#ifdef WHERE -extern struct fromcache_t *fcache; -#endif - char *Mind[] = { " ", "^-^", "^_^", "Q_Q", "@_@", "/_\\", "=_=", "-_-", "-.-", ">_<", diff --git a/pttbbs/mbbsd/term.c b/pttbbs/mbbsd/term.c index db3e66d1..4cab3e2c 100644 --- a/pttbbs/mbbsd/term.c +++ b/pttbbs/mbbsd/term.c @@ -1,16 +1,5 @@ -/* $Id: term.c,v 1.2 2002/04/15 20:00:22 in2 Exp $ */ -#include <stdio.h> -#include <stdlib.h> -#include <termios.h> -#include <string.h> -#include <syslog.h> -#include <signal.h> -#include <sys/types.h> -#include <sys/ioctl.h> -#include "config.h" -#include "pttstruct.h" -#include "common.h" -#include "proto.h" +/* $Id: term.c,v 1.3 2002/06/04 13:08:34 in2 Exp $ */ +#include "bbs.h" int tgetent(const char *bp, char *name); char *tgetstr(const char *id, char **area); @@ -45,28 +34,6 @@ void init_tty() { #define TERMCOMSIZE (40) -char *clearbuf = "\33[H\33[J"; -int clearbuflen = 6; - -char *cleolbuf = "\33[K"; -int cleolbuflen = 3; - -char *scrollrev = "\33M"; -int scrollrevlen = 2; - -char *strtstandout = "\33[7m"; -int strtstandoutlen = 4; - -char *endstandout = "\33[m"; -int endstandoutlen = 3; - -int t_lines = 24; -int b_lines = 23; -int p_lines = 20; -int t_columns = 80; - -int automargins = 1; - #if 0 static char *outp; static int *outlp; @@ -80,8 +47,6 @@ static int outcf(int ch) { } #endif -extern screenline_t *big_picture; - static void term_resize(int sig) { struct winsize newsize; screenline_t *new_picture; diff --git a/pttbbs/mbbsd/toolkit.c b/pttbbs/mbbsd/toolkit.c index 81a0d6f0..2955f040 100644 --- a/pttbbs/mbbsd/toolkit.c +++ b/pttbbs/mbbsd/toolkit.c @@ -1,8 +1,5 @@ -/* $Id: toolkit.c,v 1.1 2002/03/07 15:13:48 in2 Exp $ */ -#include <ctype.h> -#include <sys/types.h> -#include "config.h" -#include "pttstruct.h" +/* $Id: toolkit.c,v 1.2 2002/06/04 13:08:34 in2 Exp $ */ +#include "bbs.h" unsigned StringHash(unsigned char *s) { unsigned int v=0; diff --git a/pttbbs/mbbsd/topsong.c b/pttbbs/mbbsd/topsong.c index d3a65447..169feb8d 100644 --- a/pttbbs/mbbsd/topsong.c +++ b/pttbbs/mbbsd/topsong.c @@ -1,12 +1,5 @@ -/* $Id: topsong.c,v 1.1 2002/03/07 15:13:48 in2 Exp $ */ -#include <stdio.h> -#include <string.h> -#include <stdlib.h> -#include <sys/types.h> -#include "config.h" -#include "pttstruct.h" -#include "common.h" -#include "proto.h" +/* $Id: topsong.c,v 1.2 2002/06/04 13:08:34 in2 Exp $ */ +#include "bbs.h" #define MAX_SONGS 300 #define QCAST int (*)(const void *, const void *) diff --git a/pttbbs/mbbsd/user.c b/pttbbs/mbbsd/user.c index 89ebef5f..54a3a515 100644 --- a/pttbbs/mbbsd/user.c +++ b/pttbbs/mbbsd/user.c @@ -1,37 +1,5 @@ -/* $Id: user.c,v 1.20 2002/06/02 06:44:44 in2 Exp $ */ -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <time.h> -#include <unistd.h> -#include <ctype.h> -#include <sys/types.h> -#include "config.h" -#include "pttstruct.h" -#include "common.h" -#include "perm.h" -#include "modes.h" -#include "proto.h" - -extern int numboards; -extern boardheader_t *bcache; -extern char *loginview_file[NUMVIEWFILE][2]; -extern int b_lines; /* Screen bottom line number: t_lines-1 */ -extern time_t login_start_time; -extern char *msg_uid; -extern int usernum; -extern char *msg_sure_ny; -extern userinfo_t *currutmp; -extern int showansi; -extern char reset_color[]; -extern char *fn_proverb; -extern char *fn_plans; -extern char *msg_del_ok; -extern char *fn_register; -extern char *msg_nobody; -extern userec_t cuser; -extern userec_t xuser; -extern time_t now; +/* $Id: user.c,v 1.21 2002/06/04 13:08:34 in2 Exp $ */ +#include "bbs.h" static char *sex[8] = { MSG_BIG_BOY, MSG_BIG_GIRL, MSG_LITTLE_BOY, MSG_LITTLE_GIRL, @@ -220,7 +188,6 @@ static void violate_law(userec_t *u, int unum){ pressanykey(); } -extern char* str_permid[]; void uinfo_query(userec_t *u, int real, int unum) { userec_t x; @@ -1062,7 +1029,6 @@ int u_register(void) } /* 列出所有註冊使用者 */ -extern struct uhash_t *uhash; static int usercounter, totalusers, showrealname; static ushort u_list_special; diff --git a/pttbbs/mbbsd/var.c b/pttbbs/mbbsd/var.c index e7fbb118..43dab291 100644 --- a/pttbbs/mbbsd/var.c +++ b/pttbbs/mbbsd/var.c @@ -1,9 +1,6 @@ -/* $Id: var.c,v 1.5 2002/05/25 06:28:21 ptt Exp $ */ -#include <stdio.h> -#include <sys/types.h> -#include "config.h" -#include "pttstruct.h" -#include "common.h" +/* $Id: var.c,v 1.6 2002/06/04 13:08:34 in2 Exp $ */ +#define INCLUDE_VAR_H +#include "bbs.h" char *str_permid[] = { "基本權力", /* PERM_BASIC */ @@ -46,7 +43,7 @@ char *str_permboard[] = { "不轉信", /* BRD_NOTRAN */ "群組版", /* BRD_GROUP */ "隱藏版", /* BRD_HIDE */ - "限制(不需設定)", /* BRD_POSTMASK */ + "限制(不需設定)", /* BRD_POSTMASK */ "匿名版", /* BRD_ANONYMOUS */ "預設匿名版", /* BRD_DEFAULTANONYMOUS */ "違法改進中看版", /* BRD_BAD */ @@ -75,53 +72,53 @@ char *str_permboard[] = { "沒想到", }; -int usernum; -pid_t currpid; /* current process ID */ -unsigned int currstat; -int currmode = 0; -int curredit = 0; -int showansi = 1; -time_t login_start_time; -userec_t cuser; /* current user structure */ -userec_t xuser; /* lookup user structure */ -char quote_file[80] = "\0"; -char quote_user[80] = "\0"; -time_t paste_time; -char paste_title[STRLEN]; -char paste_path[256]; -int paste_level; -char currtitle[TTLEN + 1] = "\0"; -char vetitle[TTLEN + 1] = "\0"; -char currowner[IDLEN + 2] = "\0"; -char currauthor[IDLEN + 2] = "\0"; -char currfile[FNLEN]; /* current file name @ bbs.c mail.c */ -unsigned char currfmode; /* current file mode */ -char currboard[IDLEN + 2]; -int currbid; -unsigned int currbrdattr; -char currBM[IDLEN * 3 + 10]; -char reset_color[4] = "\033[m"; -char margs[64] = "\0"; /* main argv list*/ -crosspost_t postrecord; /* anti cross post */ +int usernum; +int currmode = 0; +int curredit = 0; +int showansi = 1; +int paste_level; +int currbid; +char quote_file[80] = "\0"; +char quote_user[80] = "\0"; +char paste_title[STRLEN]; +char paste_path[256]; +char currtitle[TTLEN + 1] = "\0"; +char vetitle[TTLEN + 1] = "\0"; +char currowner[IDLEN + 2] = "\0"; +char currauthor[IDLEN + 2] = "\0"; +char currfile[FNLEN]; /* current file name @ bbs.c mail.c */ +char currboard[IDLEN + 2]; +char currBM[IDLEN * 3 + 10]; +char reset_color[4] = "\033[m"; +char margs[64] = "\0"; /* main argv list*/ +pid_t currpid; /* current process ID */ +time_t login_start_time; +time_t paste_time; +userec_t cuser; /* current user structure */ +userec_t xuser; /* lookup user structure */ +crosspost_t postrecord; /* anti cross post */ +unsigned int currbrdattr; +unsigned int currstat; +unsigned char currfmode; /* current file mode */ /* global string variables */ /* filename */ -char *fn_passwd = FN_PASSWD; -char *fn_board = FN_BOARD; -char *fn_note_ans = FN_NOTE_ANS; -char *fn_register = "register.new"; -char *fn_plans = "plans"; -char *fn_writelog = "writelog"; -char *fn_talklog = "talklog"; +char *fn_passwd = FN_PASSWD; +char *fn_board = FN_BOARD; +char *fn_note_ans = FN_NOTE_ANS; +char *fn_register = "register.new"; +char *fn_plans = "plans"; +char *fn_writelog = "writelog"; +char *fn_talklog = "talklog"; char *fn_overrides = FN_OVERRIDES; -char *fn_reject = FN_REJECT; -char *fn_canvote = FN_CANVOTE; -char *fn_notes = "notes"; -char *fn_water = FN_WATER; -char *fn_visable = FN_VISABLE; -char *fn_mandex = "/.Names"; -char *fn_proverb = "proverb"; +char *fn_reject = FN_REJECT; +char *fn_canvote = FN_CANVOTE; +char *fn_notes = "notes"; +char *fn_water = FN_WATER; +char *fn_visable = FN_VISABLE; +char *fn_mandex = "/.Names"; +char *fn_proverb = "proverb"; /* are descript in userec.loginview */ @@ -143,42 +140,42 @@ char *loginview_file[NUMVIEWFILE][2] = { }; /* message */ -char *msg_seperator = MSG_SEPERATOR; -char *msg_mailer = MSG_MAILER; +char *msg_seperator = MSG_SEPERATOR; +char *msg_mailer = MSG_MAILER; char *msg_shortulist = MSG_SHORTULIST; -char *msg_cancel = MSG_CANCEL; -char *msg_usr_left = MSG_USR_LEFT; -char *msg_nobody = MSG_NOBODY; +char *msg_cancel = MSG_CANCEL; +char *msg_usr_left = MSG_USR_LEFT; +char *msg_nobody = MSG_NOBODY; -char *msg_sure_ny = MSG_SURE_NY; -char *msg_sure_yn = MSG_SURE_YN; +char *msg_sure_ny = MSG_SURE_NY; +char *msg_sure_yn = MSG_SURE_YN; -char *msg_bid = MSG_BID; -char *msg_uid = MSG_UID; +char *msg_bid = MSG_BID; +char *msg_uid = MSG_UID; -char *msg_del_ok = MSG_DEL_OK; -char *msg_del_ny = MSG_DEL_NY; +char *msg_del_ok = MSG_DEL_OK; +char *msg_del_ny = MSG_DEL_NY; -char *msg_fwd_ok = MSG_FWD_OK; -char *msg_fwd_err1 = MSG_FWD_ERR1; -char *msg_fwd_err2 = MSG_FWD_ERR2; +char *msg_fwd_ok = MSG_FWD_OK; +char *msg_fwd_err1 = MSG_FWD_ERR1; +char *msg_fwd_err2 = MSG_FWD_ERR2; char *err_board_update = ERR_BOARD_UPDATE; -char *err_bid = ERR_BID; -char *err_uid = ERR_UID; -char *err_filename = ERR_FILENAME; +char *err_bid = ERR_BID; +char *err_uid = ERR_UID; +char *err_filename = ERR_FILENAME; char *str_mail_address = "." BBSUSER "@" MYHOSTNAME; -char *str_new = "new"; -char *str_reply = "Re: "; -char *str_space = " \t\n\r"; -char *str_sysop = "SYSOP"; -char *str_author1 = STR_AUTHOR1; -char *str_author2 = STR_AUTHOR2; -char *str_post1 = STR_POST1; -char *str_post2 = STR_POST2; -char *BBSName = BBSNAME; +char *str_new = "new"; +char *str_reply = "Re: "; +char *str_space = " \t\n\r"; +char *str_sysop = "SYSOP"; +char *str_author1 = STR_AUTHOR1; +char *str_author2 = STR_AUTHOR2; +char *str_post1 = STR_POST1; +char *str_post2 = STR_POST2; +char *BBSName = BBSNAME; /* #define MAX_MODES 78 */ /* MAX_MODES is defined in common.h */ @@ -262,6 +259,320 @@ char *ModeTypeTable[MAX_MODES] = { "下象棋", /* CHC */ "下暗琪", /* DARK */ "NBA大猜測" /* TMPJACK */ - "Ptt查榜系統", /* JCEE */ + "Ptt查榜系統", /* JCEE */ "重編文章" /* REEDIT */ }; + +/* indict.c */ +char dict[41], database[41]; + +/* term.c */ +int b_lines = 23; +int t_lines = 24; +int p_lines = 20; +int t_columns = 80; +char *strtstandout = "\33[7m"; +int strtstandoutlen = 4; +char *endstandout = "\33[m"; +int endstandoutlen = 3; +char *clearbuf = "\33[H\33[J"; +int clearbuflen = 6; +char *cleolbuf = "\33[K"; +int cleolbuflen = 3; +char *scrollrev = "\33M"; +int scrollrevlen = 2; +int automargins = 1; + +/* io.c */ +time_t now; +int KEY_ESC_arg; +int watermode = -1; +int wmofo = -1; +/* + WATERMODE(WATER_ORIG) | WATERMODE(WATER_NEW): + Ptt 水球回顧用的參數 + watermode = -1 沒在回水球 + = 0 在回上一顆水球 (Ctrl-R) + > 0 在回前 n 顆水球 (Ctrl-R Ctrl-R) + + WATERMODE(WATER_OFO) by in2 + wmofo = -1 沒在回水球 + = 0 正在回水球 + = 1 回水球間又接到水球 + wmofo >=0 時收到水球將只顯示, 不會到water[]裡, + 待回完水球的時候一次寫入. +*/ + + +/* cache.c */ +int numboards = -1; +int *GLOBALVAR; +uhash_t *uhash; +bcache_t *brdshm; +userinfo_t *currutmp; +boardheader_t *bcache; +struct utmpfile_t *utmpshm; +struct fromcache_t *fcache; + +/* board.c */ +int class_bid = 0; +int brc_num; +int brc_list[BRC_MAXNUM]; + +/* read.c */ +int TagNum; /* tag's number */ +TagItem TagList[MAXTAGS]; /* ascending list */ +char currdirect[64]; + +/* edit.c */ +char save_title[STRLEN]; + +/* bbs.c */ +time_t board_visit_time; +char real_name[IDLEN + 1]; +int local_article; + +/* mbbsd.c */ +int talkrequest = NA; +char fromhost[STRLEN] = "\0"; +char water_usies = 0; +FILE *fp_writelog = NULL; +water_t water[6], *swater[6], *water_which = &water[0]; + +/* announce.c */ +char trans_buffer[256]; + +/* chc_play.c */ +rc_t chc_from, chc_to, chc_select, chc_cursor; +int chc_lefttime; +int chc_my, chc_turn, chc_selected, chc_firststep; +char chc_warnmsg[64], *chc_mateid; +int chc_hiswin, chc_hislose, chc_histie; + +/* screen.c */ +screenline_t *big_picture = NULL; +unsigned char scr_lns, scr_cols; + +/* gomo.c */ +char ku[BRDSIZ][BRDSIZ]; +unsigned char *pat, *adv; +unsigned char *pat_gomoku /* [1954] */ = +/* 0 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" +/* 16 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x44\x55\xcc\x00\x00\x00\x00" +/* 32 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x33\x00\x44\x00\x33\x00\x00\x00" +/* 48 */ "\x00\x22\x00\x55\x00\x22\x00\x00\x00\x44\x33\x66\x55\xcc\x33\x66" +/* 64 */ "\x55\xcc\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x03\x00\x00\x00" +/* 80 */ "\x55\x00\x55\x00\x05\x00\x55\x02\x46\x00\xaa\x00\x00\x55\x00\x55" +/* 96 */ "\x00\x05\x00\x55\x00\x05\x00\x55\x00\x00\x44\xcc\x44\xcc\x05\xbb" +/* 112 */ "\x44\xcc\x05\xbb\x44\xcc\x05\xbb\x00\x00\x00\x00\x00\x00\x00\x00" +/* 128 */ "\x00\x00\x33\x00\x00\x00\x44\x00\x00\x00\x00\x00\x33\x00\x44\x00" +/* 144 */ "\x33\x22\x66\x00\x55\x55\xcc\x00\x33\x00\x00\x00\x00\x22\x00\x55" +/* 160 */ "\x00\x22\x00\x55\x00\x02\x00\x05\x00\x22\x00\x00\x33\x44\x33\x66" +/* 176 */ "\x55\xcc\x33\x66\x55\xcc\x33\x46\x05\xbb\x33\x66\x55\xcc\x00\x00" +/* 192 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x03\x00\x00\x00\x44\x00\x00\x00" +/* 208 */ "\x33\x00\x00\x22\x55\x22\x55\x02\x05\x22\x55\x02\x46\x22\xaa\x55" +/* 224 */ "\xcc\x22\x55\x02\x46\x22\xaa\x00\x22\x55\x22\x55\x02\x05\x22\x55" +/* 240 */ "\x02\x05\x22\x55\x02\x05\x22\x55\x02\x05\x22\x55\x02\x44\x66\xcc" +/* 256 */ "\x66\xcc\x46\xbb\x66\xcc\x46\xbb\x66\xcc\x46\xbb\x66\xcc\x46\xbb" +/* 272 */ "\x66\xcc\x46\xbb\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x33\x00" +/* 288 */ "\x00\x00\x44\x00\x00\x00\x33\x00\x22\x22\x66\x00\x00\x00\x00\x00" +/* 304 */ "\x03\x00\x44\x00\x33\x22\x66\x00\x55\x55\xcc\x00\x33\x22\x66\x00" +/* 320 */ "\x55\x55\xcc\x00\x03\x00\x00\x00\x00\x02\x00\x55\x00\x02\x00\x55" +/* 336 */ "\x00\x02\x00\x05\x00\x02\x00\x55\x00\x02\x02\x46\x00\x02\x00\x55" +/* 352 */ "\x55\x05\x55\x46\xaa\xcc\x55\x46\xaa\xcc\x55\x06\x5a\xbb\x55\x46" +/* 368 */ "\xaa\xcc\x55\x06\x5a\xbb\x55\x46\xaa\xcc\x00\x00\x00\x00\x00\x00" +/* 384 */ "\x00\x00\x00\x00\x03\x00\x00\x00\x44\x00\x00\x00\x33\x00\x22\x22" +/* 400 */ "\x66\x00\x00\x00\x55\x00\x55\x55\x05\x55\x05\x55\x05\x55\x05\x55" +/* 416 */ "\x46\x55\x5a\xaa\xcc\x55\x05\x55\x46\x55\x5a\xaa\xcc\x55\x05\x55" +/* 432 */ "\x06\x55\x0a\x55\x55\x05\x55\x05\x55\x05\x55\x05\x55\x05\x55\x05" +/* 448 */ "\x55\x05\x55\x05\x55\x05\x55\x05\x55\x46\x55\x05\x55\x5a\x55\x5a" +/* 464 */ "\xaa\xcc\xcc\xbb\xcc\xbb\xcc\xbb\xcc\xbb\xcc\xbb\xcc\xbb\xcc\xbb" +/* 480 */ "\xcc\xbb\xcc\xbb\xcc\xbb\xcc\xbb\xcc\xbb\xcc\xbb\xcc\xbb\xcc\xbb" +/* 496 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x33\x00\x00\x00\x44\x00" +/* 512 */ "\x00\x00\x33\x00\x22\x22\x66\x00\x00\x00\x55\x00\x55\x55\xcc\x00" +/* 528 */ "\x00\x00\x00\x00\x33\x00\x44\x00\x33\x22\x66\x00\x55\x55\xcc\x00" +/* 544 */ "\x33\x22\x66\x00\x55\x55\xcc\x00\x33\x02\x46\x00\x05\x05\xbb\x00" +/* 560 */ "\x33\x00\x00\x00\x00\x22\x00\x55\x00\x22\x00\x55\x00\x02\x00\x05" +/* 576 */ "\x00\x22\x00\x55\x00\x02\x02\x46\x00\x22\x00\xaa\x00\x55\x55\xcc" +/* 592 */ "\x00\x22\x00\x00\x33\x44\x33\x66\x55\xcc\x33\x66\x55\xcc\x33\x46" +/* 608 */ "\x05\xbb\x33\x66\x55\xcc\x33\x46\x05\xbb\x33\x66\x55\xcc\x33\x46" +/* 624 */ "\x05\xbb\x33\x66\x55\xcc\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" +/* 640 */ "\x03\x00\x00\x00\x44\x00\x00\x00\x33\x00\x22\x22\x66\x00\x00\x00" +/* 656 */ "\x55\x00\x55\x55\xcc\x00\x00\x00\x33\x00\x00\x22\x55\x22\x55\x02" +/* 672 */ "\x05\x22\x55\x02\x46\x22\xaa\x55\xcc\x22\x55\x02\x46\x22\xaa\x55" +/* 688 */ "\xcc\x22\x55\x02\x06\x22\x5a\x05\xbb\x22\x55\x02\x46\x22\xaa\x00" +/* 704 */ "\x22\x55\x22\x55\x02\x05\x22\x55\x02\x05\x22\x55\x02\x05\x22\x55" +/* 720 */ "\x02\x05\x22\x55\x02\x46\x22\x55\x02\x5a\x22\xaa\x55\xcc\x22\x55" +/* 736 */ "\x02\x05\x22\x55\x02\x44\x66\xcc\x66\xcc\x46\xbb\x66\xcc\x46\xbb" +/* 752 */ "\x66\xcc\x46\xbb\x66\xcc\x46\xbb\x66\xcc\x46\xbb\x66\xcc\x46\xbb" +/* 768 */ "\x66\xcc\x46\xbb\x66\xcc\x46\xbb\x66\xcc\x46\xbb\x00\x00\x00\x00" +/* 784 */ "\x00\x00\x00\x00\x00\x00\x33\x00\x00\x00\x44\x00\x00\x00\x33\x00" +/* 800 */ "\x22\x22\x66\x00\x00\x00\x55\x00\x55\x55\xcc\x00\x00\x00\x33\x00" +/* 816 */ "\x22\x22\x66\x00\x00\x00\x00\x00\x03\x00\x44\x00\x33\x22\x66\x00" +/* 832 */ "\x55\x55\xcc\x00\x33\x22\x66\x00\x55\x55\xcc\x00\x03\x02\x46\x00" +/* 848 */ "\x05\x05\xbb\x00\x33\x22\x66\x00\x55\x55\xcc\x00\x03\x00\x00\x00" +/* 864 */ "\x00\x02\x00\x55\x00\x02\x00\x55\x00\x02\x00\x05\x00\x02\x00\x55" +/* 880 */ "\x00\x02\x02\x46\x00\x02\x00\xaa\x00\x55\x55\xcc\x00\x02\x00\x55" +/* 896 */ "\x00\x02\x02\x46\x00\x02\x00\x55\x55\x05\x55\x46\xaa\xcc\x55\x46" +/* 912 */ "\xaa\xcc\x55\x06\x5a\xbb\x55\x46\xaa\xcc\x55\x06\x5a\xbb\x55\x46" +/* 928 */ "\xaa\xcc\x55\x06\x5a\xbb\x55\x46\xaa\xcc\x55\x06\x5a\xbb\x55\x46" +/* 944 */ "\xaa\xcc\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x03\x00\x00\x00" +/* 960 */ "\x44\x00\x00\x00\x33\x00\x22\x22\x66\x00\x00\x00\x55\x00\x55\x55" +/* 976 */ "\xcc\x00\x00\x00\x33\x00\x22\x22\x66\x00\x00\x00\x55\x00\x55\x55" +/* 992 */ "\x05\x55\x05\x55\x05\x55\x05\x55\x46\x55\x5a\xaa\xcc\x55\x05\x55" +/* 1008 */ "\x46\x55\x5a\xaa\xcc\x55\x05\x55\x06\x55\x0a\x5a\xbb\x55\x05\x55" +/* 1024 */ "\x46\x55\x5a\xaa\xcc\x55\x05\x55\x06\x55\x0a\x55\x55\x05\x55\x05" +/* 1040 */ "\x55\x05\x55\x05\x55\x05\x55\x05\x55\x05\x55\x05\x55\x05\x55\x05" +/* 1056 */ "\x55\x46\x55\x05\x55\x5a\x55\x5a\xaa\xcc\x55\x05\x55\x05\x55\x05" +/* 1072 */ "\x55\x46\x55\x05\x55\x5a\x55\x5a\xaa\xcc\xcc\xbb\xcc\xbb\xcc\xbb" +/* 1088 */ "\xcc\xbb\xcc\xbb\xcc\xbb\xcc\xbb\xcc\xbb\xcc\xbb\xcc\xbb\xcc\xbb" +/* 1104 */ "\xcc\xbb\xcc\xbb\xcc\xbb\xcc\xbb\xcc\xbb\xcc\xbb\xcc\xbb\xcc\xbb" +/* 1120 */ "\xcc\xbb\xcc\xbb\xcc\xbb\xcc\xbb\x00\x00\x00\x00\x00\x00\x00\x00" +/* 1136 */ "\x00\x00\x33\x00\x00\x00\x44\x00\x00\x00\x33\x00\x22\x22\x66\x00" +/* 1152 */ "\x00\x00\x55\x00\x55\x55\xcc\x00\x00\x00\x33\x00\x22\x22\x66\x00" +/* 1168 */ "\x00\x00\x55\x00\x55\x55\xcc\x00\x00\x00\x00\x00\x33\x00\x44\x00" +/* 1184 */ "\x33\x22\x66\x00\x55\x55\xcc\x00\x33\x22\x66\x00\x55\x55\xcc\x00" +/* 1200 */ "\x33\x02\x46\x00\x05\x05\xbb\x00\x33\x22\x66\x00\x55\x55\xcc\x00" +/* 1216 */ "\x33\x02\x46\x00\x05\x05\xbb\x00\x33\x00\x00\x00\x00\x22\x00\x55" +/* 1232 */ "\x00\x22\x00\x55\x00\x02\x00\x05\x00\x22\x00\x55\x00\x02\x02\x46" +/* 1248 */ "\x00\x22\x00\xaa\x00\x55\x55\xcc\x00\x22\x00\x55\x00\x02\x02\x46" +/* 1264 */ "\x00\x22\x00\xaa\x00\x55\x55\xcc\x00\x22\x00\x00\x03\x44\x33\x66" +/* 1280 */ "\x55\xcc\x33\x66\x55\xcc\x03\x46\x05\xbb\x33\x66\x55\xcc\x03\x46" +/* 1296 */ "\x05\xbb\x33\x66\x55\xcc\x03\x46\x05\xbb\x33\x66\x55\xcc\x03\x46" +/* 1312 */ "\x05\xbb\x33\x66\x55\xcc\x03\x46\x05\xbb\x33\x66\x55\xcc\x00\x00" +/* 1328 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x03\x00\x00\x00\x44\x00\x00\x00" +/* 1344 */ "\x33\x00\x22\x22\x66\x00\x00\x00\x55\x00\x55\x55\xcc\x00\x00\x00" +/* 1360 */ "\x33\x00\x22\x22\x66\x00\x00\x00\x55\x00\x55\x55\xcc\x00\x00\x00" +/* 1376 */ "\x03\x00\x00\x02\x55\x02\x55\x02\x05\x02\x55\x02\x46\x02\xaa\x55" +/* 1392 */ "\xcc\x02\x55\x02\x46\x02\xaa\x55\xcc\x02\x55\x02\x06\x02\x5a\x05" +/* 1408 */ "\xbb\x02\x55\x02\x46\x02\xaa\x55\xcc\x02\x55\x02\x06\x02\x5a\x05" +/* 1424 */ "\xbb\x02\x55\x02\x46\x02\xaa\x00\x02\x55\x02\x55\x02\x05\x02\x55" +/* 1440 */ "\x02\x05\x02\x55\x02\x05\x02\x55\x02\x05\x02\x55\x02\x46\x02\x55" +/* 1456 */ "\x02\x5a\x02\xaa\x55\xcc\x02\x55\x02\x05\x02\x55\x02\x46\x02\x55" +/* 1472 */ "\x02\x5a\x02\xaa\x55\xcc\x02\x55\x02\x05\x02\x55\x02\x05\x46\xcc" +/* 1488 */ "\x46\xcc\x06\xbb\x46\xcc\x06\xbb\x46\xcc\x06\xbb\x46\xcc\x06\xbb" +/* 1504 */ "\x46\xcc\x06\xbb\x46\xcc\x06\xbb\x46\xcc\x06\xbb\x46\xcc\x06\xbb" +/* 1520 */ "\x46\xcc\x06\xbb\x46\xcc\x06\xbb\x46\xcc\x06\xbb\x46\xcc\x06\xbb" +/* 1536 */ "\x46\xcc\x06\xbb\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x33\x00" +/* 1552 */ "\x00\x00\x44\x00\x00\x00\x33\x00\x22\x22\x66\x00\x00\x00\x55\x00" +/* 1568 */ "\x55\x55\xcc\x00\x00\x00\x33\x00\x22\x22\x66\x00\x00\x00\x55\x00" +/* 1584 */ "\x55\x55\xcc\x00\x00\x00\x33\x00\x02\x02\x46\x00\x00\x00\x00\x00" +/* 1600 */ "\x03\x00\x44\x00\x33\x22\x66\x00\x55\x55\xcc\x00\x33\x22\x66\x00" +/* 1616 */ "\x55\x55\xcc\x00\x03\x02\x46\x00\x05\x05\xbb\x00\x33\x22\x66\x00" +/* 1632 */ "\x55\x55\xcc\x00\x03\x02\x46\x00\x05\x05\xbb\x00\x33\x22\x66\x00" +/* 1648 */ "\x55\x55\xcc\x00\x03\x00\x00\x00\x00\x02\x00\x55\x00\x02\x00\x55" +/* 1664 */ "\x00\x02\x00\x05\x00\x02\x00\x55\x00\x02\x02\x46\x00\x02\x00\xaa" +/* 1680 */ "\x00\x55\x55\xcc\x00\x02\x00\x55\x00\x02\x02\x46\x00\x02\x00\xaa" +/* 1696 */ "\x00\x55\x55\xcc\x00\x02\x00\x55\x00\x02\x02\x06\x00\x02\x00\x05" +/* 1712 */ "\x05\x05\x05\x46\x5a\xcc\x05\x46\x5a\xcc\x05\x06\x0a\xbb\x05\x46" +/* 1728 */ "\x5a\xcc\x05\x06\x0a\xbb\x05\x46\x5a\xcc\x05\x06\x0a\xbb\x05\x46" +/* 1744 */ "\x5a\xcc\x05\x06\x0a\xbb\x05\x46\x5a\xcc\x05\x06\x0a\xbb\x05\x46" +/* 1760 */ "\x5a\xcc\x05\x06\x0a\xbb\x05\x46\x5a\xcc\x00\x00\x00\x00\x00\x00" +/* 1776 */ "\x00\x00\x00\x00\x03\x00\x00\x00\x44\x00\x00\x00\x33\x00\x22\x22" +/* 1792 */ "\x66\x00\x00\x00\x55\x00\x55\x55\xcc\x00\x00\x00\x33\x00\x22\x22" +/* 1808 */ "\x66\x00\x00\x00\x55\x00\x55\x55\xcc\x00\x00\x00\x03\x00\x02\x02" +/* 1824 */ "\x46\x00\x00\x00\x05\x00\x05\x05\x05\x05\x05\x05\x05\x05\x05\x05" +/* 1840 */ "\x46\x05\x5a\x5a\xcc\x05\x05\x05\x46\x05\x5a\x5a\xcc\x05\x05\x05" +/* 1856 */ "\x06\x05\x0a\x0a\xbb\x05\x05\x05\x46\x05\x5a\x5a\xcc\x05\x05\x05" +/* 1872 */ "\x06\x05\x0a\x0a\xbb\x05\x05\x05\x46\x05\x5a\x5a\xcc\x05\x05\x05" +/* 1888 */ "\x06\x05\x0a\x05\x05\x05\x05\x05\x05\x05\x05\x05\x05\x05\x05\x05" +/* 1904 */ "\x05\x05\x05\x05\x05\x05\x05\x05\x05\x46\x05\x05\x05\x5a\x05\x5a" +/* 1920 */ "\x5a\xcc\x05\x05\x05\x05\x05\x05\x05\x46\x05\x05\x05\x5a\x05\x5a" +/* 1936 */ "\x5a\xcc\x05\x05\x05\x05\x05\x05\x05\x06\x05\x05\x05\x0a\x05\x0a" +/* 1952 */ "\x0a"; + +unsigned char *adv_gomoku /* [978] */ = +/* 0 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" +/* 16 */ "\x00\x00\x00\x00\xa0\x00\xa0\x00\x04\x00\x04\x00\x00\xd0\x00\xd0" +/* 32 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" +/* 48 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" +/* 64 */ "\x00\x70\x00\x00\x00\x00\xa0\x00\xa1\x00\x00\x00\xa0\x00\x04\x00" +/* 80 */ "\x04\x00\x00\x00\x04\x00\xd0\xd0\x00\xd0\x00\xd0\x00\xd0\x00\x00" +/* 96 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x70\x08\x08\x00\x08\x00\x08\x00" +/* 112 */ "\x08\x00\x08\x00\x40\x40\x00\x40\x00\x40\x00\x40\x00\x40\x00\x00" +/* 128 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x70" +/* 144 */ "\x00\x00\x00\x70\x21\x00\x00\x00\x00\x00\xa1\x00\x00\x00\xa1\x00" +/* 160 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" +/* 176 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" +/* 192 */ "\x00\x00\x00\x00\x00\x00\x70\x21\x00\x00\x00\x00\x00\x00\x00\x00" +/* 208 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" +/* 224 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" +/* 240 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x70\x00\x00" +/* 256 */ "\x00\x70\x21\x00\x00\x00\x00\x00\x00\x00\xa0\x00\xa1\x00\x00\x00" +/* 272 */ "\xa1\x00\x00\x00\xa0\x00\x00\x00\xa0\x00\x04\x00\x04\x00\x00\x00" +/* 288 */ "\x04\x00\x00\x00\x04\x00\x00\x00\x04\x00\xd0\xd0\x00\xd0\x00\xd0" +/* 304 */ "\x00\xd0\x00\xd0\x00\xd0\x00\xd0\x00\xd0\x00\x00\x00\x00\x00\x00" +/* 320 */ "\x00\x00\x00\x00\x70\x21\x00\x00\x00\x00\x00\x00\x70\x08\x08\x00" +/* 336 */ "\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00" +/* 352 */ "\x40\x40\x00\x40\x00\x40\x00\x40\x00\x40\x00\x40\x00\x40\x00\x40" +/* 368 */ "\x00\x40\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" +/* 384 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x70\x00\x00\x00\x70" +/* 400 */ "\x21\x00\x00\x00\x00\x00\x00\x70\x21\x00\x00\x00\x00\x00\xa1\x00" +/* 416 */ "\x00\x00\xa1\x00\x00\x00\x00\x00\x00\x00\xa1\x00\x00\x00\x00\x00" +/* 432 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" +/* 448 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" +/* 464 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" +/* 480 */ "\x00\x00\x70\x21\x00\x00\x00\x00\x00\x00\x70\x21\x00\x00\x00\x00" +/* 496 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" +/* 512 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" +/* 528 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" +/* 544 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" +/* 560 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x70\x00\x00\x00\x70\x21\x00" +/* 576 */ "\x00\x00\x00\x00\x00\x70\x21\x00\x00\x00\x00\x00\x00\x00\xa0\x00" +/* 592 */ "\xa1\x00\x00\x00\xa1\x00\x00\x00\xa0\x00\x00\x00\xa1\x00\x00\x00" +/* 608 */ "\xa0\x00\x00\x00\xa0\x00\x04\x00\x04\x00\x00\x00\x04\x00\x00\x00" +/* 624 */ "\x04\x00\x00\x00\x04\x00\x00\x00\x04\x00\x00\x00\x04\x00\x00\xd0" +/* 640 */ "\x00\xd0\x00\x00\x00\xd0\x00\x00\x00\xd0\x00\x00\x00\xd0\x00\x00" +/* 656 */ "\x00\xd0\x00\x00\x00\xd0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" +/* 672 */ "\x70\x21\x00\x00\x00\x00\x00\x00\x70\x21\x00\x00\x00\x00\x00\x00" +/* 688 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" +/* 704 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" +/* 720 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" +/* 736 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" +/* 752 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" +/* 768 */ "\x00\x00\x00\x00\x00\x00\x00\x70\x00\x00\x00\x70\x21\x00\x00\x00" +/* 784 */ "\x00\x00\x00\x70\x21\x00\x00\x00\x00\x00\x00\x70\x00\x00\x00\x00" +/* 800 */ "\x00\x00\xa1\x00\x00\x00\xa1\x00\x00\x00\x00\x00\x00\x00\xa1\x00" +/* 816 */ "\x00\x00\x00\x00\x00\x00\xa1\x00\x00\x00\x00\x00\x00\x00\x00\x00" +/* 832 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" +/* 848 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" +/* 864 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" +/* 880 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x70\x21" +/* 896 */ "\x00\x00\x00\x00\x00\x00\x70\x21\x00\x00\x00\x00\x00\x00\x00\x00" +/* 912 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" +/* 928 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" +/* 944 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" +/* 960 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" +/* 976 */ "\x00"; + +/* name.c */ +word_t *toplev; + +/* menu.c */ +commands_t cmdlist[] = { + {admin,PERM_SYSOP|PERM_VIEWSYSOP, "00Admin 【 系統維護區 】"}, + {Announce, 0, "AAnnounce 【 精華公佈欄 】"}, + {Boards, 0, "FFavorite 【 我 的 最愛 】"}, + {root_board, 0, "CClass 【 分組討論區 】"}, + {Mail, PERM_BASIC, "MMail 【 私人信件區 】"}, + {Talk, 0, "TTalk 【 休閒聊天區 】"}, + {User, 0, "UUser 【 個人設定區 】"}, + {Xyz, 0, "XXyz 【 系統工具區 】"}, + {Play_Play,0, "PPlay 【 遊樂場/大學查榜】"}, + {Name_Menu,PERM_LOGINOK, "NNamelist 【 編特別名單 】"}, + {Goodbye, 0, "GGoodbye 離開,再見……"}, + {NULL, 0, NULL} +}; + +/* friend.c */ +/* Ptt 各種特別名單的檔名 */ +char *friend_file[8] = { + FN_OVERRIDES, + FN_REJECT, + "alohaed", + "postlist", + "", + FN_CANVOTE, + FN_WATER, + FN_VISABLE +}; diff --git a/pttbbs/mbbsd/vice.c b/pttbbs/mbbsd/vice.c index a27e5b21..8b8abe0f 100644 --- a/pttbbs/mbbsd/vice.c +++ b/pttbbs/mbbsd/vice.c @@ -1,15 +1,5 @@ -/* $Id: vice.c,v 1.2 2002/04/28 19:35:29 in2 Exp $ */ -#include <stdio.h> -#include <string.h> -#include <stdlib.h> -#include <unistd.h> -#include <sys/types.h> -#include "config.h" -#include "pttstruct.h" -#include "common.h" -#include "modes.h" -#include "proto.h" -extern int usernum; +/* $Id: vice.c,v 1.3 2002/06/04 13:08:34 in2 Exp $ */ +#include "bbs.h" #define VICE_PLAY BBSHOME "/etc/vice/vice.play" #define VICE_DATA "vice.new" @@ -24,8 +14,6 @@ extern int usernum; #define MAX_LOST_PICTURE 3 #define MAX_END_PICTURE 5 - - static int vice_load(char tbingo[6][15]) { FILE *fb = fopen(VICE_BINGO, "r"); char buf[16], *ptr; @@ -81,7 +69,6 @@ static int ran_showmfile(char *filename, int maxnum) { return more(buf, YEA); } -extern userec_t cuser; int vice_main() { FILE *fd; diff --git a/pttbbs/mbbsd/vote.c b/pttbbs/mbbsd/vote.c index f25a6a2b..914ac24a 100644 --- a/pttbbs/mbbsd/vote.c +++ b/pttbbs/mbbsd/vote.c @@ -1,33 +1,7 @@ -/* $Id: vote.c,v 1.8 2002/05/25 09:33:22 ptt Exp $ */ -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <fcntl.h> -#include <time.h> -#include <unistd.h> -#include <ctype.h> -#include <sys/file.h> -#include <sys/types.h> -#include <sys/stat.h> -#include "config.h" -#include "pttstruct.h" -#include "modes.h" -#include "common.h" -#include "perm.h" -#include "proto.h" +/* $Id: vote.c,v 1.9 2002/06/04 13:08:34 in2 Exp $ */ +#include "bbs.h" static int total; -extern int numboards; -extern boardheader_t *bcache; /* Thor: for speed up */ -extern char *err_board_update; -extern char *fn_board; -extern char *msg_seperator; -extern int t_lines, t_columns; /* Screen size / width */ -extern int b_lines; /* Screen bottom line number: t_lines-1 */ -extern int currmode; -extern int usernum; -extern char currboard[]; /* name of currently selected board */ -extern userec_t cuser; static char STR_bv_control[] = "control"; /* 投票日期 選項 */ static char STR_bv_desc[] = "desc"; /* 投票目的 */ @@ -122,7 +96,7 @@ static int b_nonzeroNum(char *buf) { } return i; } -extern time_t now; + static void vote_report(char *bname, char *fname, char *fpath) { register char *ip; time_t dtime; diff --git a/pttbbs/mbbsd/voteboard.c b/pttbbs/mbbsd/voteboard.c index f8be3d27..2f71fef2 100644 --- a/pttbbs/mbbsd/voteboard.c +++ b/pttbbs/mbbsd/voteboard.c @@ -1,28 +1,8 @@ -/* $Id: voteboard.c,v 1.6 2002/05/25 11:18:11 ptt Exp $ */ -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <time.h> -#include <fcntl.h> -#include <unistd.h> -#include <sys/types.h> -#include <sys/file.h> -#include "config.h" -#include "pttstruct.h" -#include "modes.h" -#include "common.h" -#include "perm.h" -#include "proto.h" +/* $Id: voteboard.c,v 1.7 2002/06/04 13:08:34 in2 Exp $ */ +#include "bbs.h" #define VOTEBOARD "NewBoard" -extern char currboard[]; -extern int currbid; -extern boardheader_t *bcache; -extern int currmode; -extern userec_t cuser; -extern time_t now; - void do_voteboardreply(fileheader_t *fhdr){ char genbuf[1024]; char reason[50]; diff --git a/pttbbs/mbbsd/xyz.c b/pttbbs/mbbsd/xyz.c index 3754582e..59a265b3 100644 --- a/pttbbs/mbbsd/xyz.c +++ b/pttbbs/mbbsd/xyz.c @@ -1,31 +1,9 @@ -/* $Id: xyz.c,v 1.7 2002/05/25 11:18:11 ptt Exp $ */ -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <fcntl.h> -#include <unistd.h> -#include <signal.h> -#include <time.h> -#include <sys/types.h> -#include <sys/stat.h> -#include <sys/wait.h> -#include "config.h" -#include "pttstruct.h" -#include "common.h" -#include "modes.h" -#include "proto.h" - -extern char *fn_note_ans; -extern int b_lines; /* Screen bottom line number: t_lines-1 */ -extern char *BBSName; -extern char fromhost[]; -extern userinfo_t *currutmp; -extern userec_t cuser; -extern time_t now; +/* $Id: xyz.c,v 1.8 2002/06/04 13:08:34 in2 Exp $ */ +#include "bbs.h" + /* 各種統計及相關資訊列表 */ /* Ptt90年度大學聯招查榜系統 */ int x_90() { - extern char dict[21], database[41]; strcpy(dict, "(90)准考證號/姓名/學校/科系/類組"); strcpy(database, "etc/90"); use_dict(); @@ -34,7 +12,6 @@ int x_90() { /* Ptt89年度大學聯招查榜系統 */ int x_89() { - extern char dict[21], database[41]; strcpy(dict, "(89)准考證號/姓名/學校/科系/類組"); strcpy(database, "etc/89"); use_dict(); @@ -42,8 +19,6 @@ int x_89() { } /* Ptt88年度大學聯招查榜系統 */ int x_88() { - extern char dict[21], database[41]; - strcpy(dict, "(88)准考證號/姓名/學校/科系/類組"); strcpy(database, "etc/88"); use_dict(); @@ -51,8 +26,6 @@ int x_88() { } /* Ptt87年度大學聯招查榜系統 */ int x_87() { - extern char dict[21], database[41]; - strcpy(dict, "(87)准考證號/姓名/學校/科系"); strcpy(database, "etc/87"); use_dict(); @@ -61,8 +34,6 @@ int x_87() { /* Ptt86年度大學聯招查榜系統 */ int x_86() { - extern char dict[21], database[41]; - strcpy(dict, "(86)准考證號/姓名/學校/科系"); strcpy(database, "etc/86"); use_dict(); @@ -319,7 +290,6 @@ int m_sysop() { } int Goodbye() { - extern void movie(); char genbuf[100]; getdata(b_lines - 1, 0, "您確定要離開【 " BBSNAME " 】嗎(Y/N)?[N] ", diff --git a/pttbbs/util/parsevar.pl b/pttbbs/util/parsevar.pl new file mode 100644 index 00000000..60063608 --- /dev/null +++ b/pttbbs/util/parsevar.pl @@ -0,0 +1,23 @@ +#!/usr/bin/perl +print << '.'; +/* + * This header file is auto-generated from pttbbs/mbbsd/var.c . + * Please do NOT edit this file directly. + */ + +#ifndef INCLUDE_VAR_H +#define INCLUDE_VAR_H +#include "bbs.h" +. +while( <> ){ + if( /^\w/ ){ + chomp; + $_ = substr($_, 0, index($_, '=') - 1) if( index($_, '=') != -1 ); + $_ .= ';' if( index($_, ';') == -1 ); + print "extern $_\n"; + } elsif( /^\#/ && !/include/ ){ + print; + } +} +print "#endif /* INCLUDE_VAR_H */\n"; + diff --git a/pttbbs/util/shmctl.c b/pttbbs/util/shmctl.c index f2ed2973..7f2aae98 100644 --- a/pttbbs/util/shmctl.c +++ b/pttbbs/util/shmctl.c @@ -270,26 +270,26 @@ int utmpnum(int argc, char **argv) return 0; } -int showglobe(int argc, char **argv) +int showglobal(int argc, char **argv) { int i; for( i = 0 ; i < 10 ; ++i ) - printf("GLOBE[%d] = %d\n", i, ptt->GLOBE[i]); + printf("GLOBALVAR[%d] = %d\n", i, ptt->GLOBALVAR[i]); return 0; } -int setglobe(int argc, char **argv) +int setglobal(int argc, char **argv) { int where; if( argc != 3 ) return 1; where = atoi(argv[1]); if( !(0 <= where && where <= 9) ){ - puts("only GLOBE[0] ~ GLOBE[9]"); + puts("only GLOBALVAR[0] ~ GLOBALVAR[9]"); return 1; } - printf("GLOBE[%d] = %d -> ", where, ptt->GLOBE[where]); - printf("%d\n", ptt->GLOBE[where] = atoi(argv[2])); + printf("GLOBALVAR[%d] = %d -> ", where, ptt->GLOBALVAR[where]); + printf("%d\n", ptt->GLOBALVAR[where] = atoi(argv[2])); return 0; } @@ -323,8 +323,8 @@ struct { {utmpsort, "utmpsort", "sort ulist"}, {utmpwatch, "utmpwatch", "to see if busystate is always 1 then fix it"}, {utmpnum, "utmpnum", "print utmpshm->number for snmpd"}, - {showglobe, "showglobe", "show GLOBE"}, - {setglobe, "setglobe", "set GLOBE"}, + {showglobal, "showglobal", "show GLOBALVAR[]"}, + {setglobal, "setglobal", "set GLOBALVAR[]"}, {fixbfriend, "fixbfriend", "recount numbers of board friends"}, {NULL, NULL, NULL} }; -- cgit v1.2.3 From adad483d479f96193e509a094a53b8b91ccfd78a Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Tue, 4 Jun 2002 13:12:03 +0000 Subject: use libcrypt git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@281 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd.icc/Makefile | 4 ++-- pttbbs/mbbsd/Makefile | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/pttbbs/mbbsd.icc/Makefile b/pttbbs/mbbsd.icc/Makefile index d0cabb11..ceacb632 100644 --- a/pttbbs/mbbsd.icc/Makefile +++ b/pttbbs/mbbsd.icc/Makefile @@ -8,11 +8,11 @@ OBJS= admin.o announce.o args.o bbcall.o bbs.o board.o cache.o cal.o card.o\ kaede.o lovepaper.o mail.o mbbsd.o menu.o more.o name.o osdep.o\ othello.o page.o read.o record.o register.o screen.o stuff.o\ talk.o term.o topsong.o user.o vice.o vote.o xyz.o\ - voteboard.o syspost.o var.o descrypt.o toolkit.o passwd.o\ + voteboard.o syspost.o var.o toolkit.o passwd.o\ calendar.o CFLAGS= -DHAVE_SETPROCTITLE -DBBSHOME='"$(BBSHOME)"' -DFreeBSD -I../include -LDFLAGS= -lutil -lkvm +LDFLAGS= -lutil -lkvm -lcrypt .if defined(GDB) || defined(DEBUG) CFLAGS+= -g diff --git a/pttbbs/mbbsd/Makefile b/pttbbs/mbbsd/Makefile index 47ae7819..03bdc07f 100644 --- a/pttbbs/mbbsd/Makefile +++ b/pttbbs/mbbsd/Makefile @@ -1,4 +1,4 @@ -# $Id: Makefile,v 1.8 2002/06/04 13:08:33 in2 Exp $ +# $Id: Makefile,v 1.9 2002/06/04 13:11:38 in2 Exp $ BBSHOME?=$(HOME) OSTYPE=FreeBSD @@ -6,7 +6,7 @@ OSTYPE=FreeBSD # FreeBSD CFLAGS_FreeBSD= -pipe -Wall -DHAVE_SETPROCTITLE -DBBSHOME='"$(BBSHOME)"' -DFreeBSD -I../include LDFLAGS_FreeBSD=-pipe -Wall -LIBS_FreeBSD= -lutil -lkvm +LIBS_FreeBSD= -lutil -lkvm -lcrypt # Linux CFLAGS_linux= -pipe -Wall -DHAVE_DES_CRYPT -DBBSHOME='"$(BBSHOME)"' -DLinux -I../include -s @@ -42,7 +42,7 @@ OBJS= admin.o announce.o args.o bbcall.o bbs.o board.o cache.o cal.o card.o\ kaede.o lovepaper.o mail.o mbbsd.o menu.o more.o name.o osdep.o\ othello.o page.o read.o record.o register.o screen.o stuff.o\ talk.o term.o topsong.o user.o vice.o vote.o xyz.o\ - voteboard.o syspost.o var.o descrypt.o toolkit.o passwd.o\ + voteboard.o syspost.o var.o toolkit.o passwd.o\ calendar.o .SUFFIXES: .c .o -- cgit v1.2.3 From a631e47761756f6caa38b3afe36cd8babd24541d Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Tue, 4 Jun 2002 13:13:10 +0000 Subject: global var git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@282 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd.icc/Makefile | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pttbbs/mbbsd.icc/Makefile b/pttbbs/mbbsd.icc/Makefile index ceacb632..20c7a115 100644 --- a/pttbbs/mbbsd.icc/Makefile +++ b/pttbbs/mbbsd.icc/Makefile @@ -34,7 +34,7 @@ CFLAGS+= -DNO_FORK GCCUSE=gcc -pipe -Wall $(CFLAGS) -c .SUFFIXES: .c .o -.c.o: +.c.o: ../include/var.h iccbin -D__FreeBSD__ -D__FreeBSD $(CFLAGS) -c ../mbbsd/$*.c all: $(PROG) @@ -42,6 +42,9 @@ all: $(PROG) $(PROG): $(OBJS) cc $(LDFLAGS) -o $(PROG) $(OBJS) +../include/var.h: var.c + perl ../util/parsevar.pl < var.c > ../include/var.h + install: $(PROG) install -d $(BBSHOME)/bin/ install -c -m 755 $(PROG) $(BBSHOME)/bin/ -- cgit v1.2.3 From f6a4849974a4a8eed33c761845e468cca04ec026 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Tue, 4 Jun 2002 13:17:58 +0000 Subject: fix last commit bug git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@283 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd.icc/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pttbbs/mbbsd.icc/Makefile b/pttbbs/mbbsd.icc/Makefile index 20c7a115..169b6f29 100644 --- a/pttbbs/mbbsd.icc/Makefile +++ b/pttbbs/mbbsd.icc/Makefile @@ -43,7 +43,7 @@ $(PROG): $(OBJS) cc $(LDFLAGS) -o $(PROG) $(OBJS) ../include/var.h: var.c - perl ../util/parsevar.pl < var.c > ../include/var.h + perl ../util/parsevar.pl < ../mbbsd/var.c > ../include/var.h install: $(PROG) install -d $(BBSHOME)/bin/ -- cgit v1.2.3 From b04563ea8073a817ab68fbb808f0ef4f1c5c4c93 Mon Sep 17 00:00:00 2001 From: ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Tue, 4 Jun 2002 18:08:59 +0000 Subject: optimize talk.c git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@284 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/talk.c | 103 ++++++++++++++++++++++++++++++---------------------- 1 file changed, 59 insertions(+), 44 deletions(-) diff --git a/pttbbs/mbbsd/talk.c b/pttbbs/mbbsd/talk.c index 3cb14c57..cbdb9344 100644 --- a/pttbbs/mbbsd/talk.c +++ b/pttbbs/mbbsd/talk.c @@ -1,4 +1,4 @@ -/* $Id: talk.c,v 1.60 2002/06/04 13:08:34 in2 Exp $ */ +/* $Id: talk.c,v 1.61 2002/06/04 18:08:59 ptt Exp $ */ #include "bbs.h" #define QCAST int (*)(const void *, const void *) @@ -1472,15 +1472,15 @@ int pickup_maxpages(int pickupway, int nfriend, int bfriend) return number / MAXPICKUP + (number % MAXPICKUP == 0 ? 0 : 1); } -static void pickup_myfriend(pickup_t *friends, int *nGots, +static int pickup_myfriend(pickup_t *friends, int *myfriend, int *friendme) { //pickup_t friends[MAX_FRIEND + 1]; userinfo_t *uentp; - int i, where, frstate; + int i, where, frstate, ngets=0; *myfriend = *friendme = 1; - for( *nGots = i = 0 ; currutmp->friend_online[i] && i < MAX_FRIEND ; ++i ){ + for( i = 0 ; currutmp->friend_online[i] && i < MAX_FRIEND ; ++i ){ where = currutmp->friend_online[i] & 0xFFFFFF; if( 0 <= where && where < MAX_ACTIVE && (uentp = &utmpshm->uinfo[where]) && uentp->pid && @@ -1490,32 +1490,36 @@ static void pickup_myfriend(pickup_t *friends, int *nGots, currutmp->friend_online[i] >> 24) && ( !(frstate & IRH) || ((frstate & IRH) && (frstate & IFH)) ) ){ - friends[*nGots].ui = &utmpshm->uinfo[where]; - friends[*nGots].uoffset = where; - friends[(*nGots)++].friend = frstate; + friends[ngets].ui = uentp; + friends[ngets].uoffset = where; + if(uentp->brc_id==currutmp->brc_id) frstate |= IBH; + friends[ngets++].friend = frstate; if( frstate & IFH ) ++*myfriend; if( frstate & HFM ) ++*friendme; } } - friends[*nGots].ui = currutmp; - friends[(*nGots)++].friend = 24; - qsort(friends, *nGots, sizeof(pickup_t), sort_cmpfriend); + friends[ngets].ui = currutmp; + friends[ngets++].friend = 24; + return ngets; } -static void pickup_bfriend(pickup_t *friends, int *nGots) +static int pickup_bfriend(pickup_t *friends, int base) { userinfo_t *ptr; - for( ptr = bcache[currutmp->brc_id - 1].u, *nGots = 0 ; - ptr != NULL && *nGots < MAX_FRIEND ; + int ngets=0; + friends = friends + base; + for( ptr = bcache[currutmp->brc_id - 1].u; + ptr != NULL && ngets < MAX_FRIEND-base ; ptr = ptr->nextbfriend ){ - if( currutmp != ptr && isvisible(currutmp, ptr) ){ - friends[*nGots].ui = ptr; - friends[(*nGots)++].friend = IBH; + if( currutmp != ptr && isvisible(currutmp, ptr) && + !(friend_stat(currutmp,ptr)&ST_FRIEND) ){ + friends[ngets].ui = ptr; + friends[ngets++].friend = IBH; } } - qsort(friends, *nGots, sizeof(pickup_t), sort_cmpfriend); + return ngets; } static void pickup(pickup_t *currpickup, int pickup_way, int *page, @@ -1527,44 +1531,55 @@ static void pickup(pickup_t *currpickup, int pickup_way, int *page, int friendtotal= currutmp->friendtotal; userinfo_t **utmp; - int which, got, sorted_way; - - got = 0; + int which, all=0, sorted_way, size=0; if( friendtotal == 0 ) *myfriend = *friendme = 1; if( cuser.uflag & FRIEND_FLAG || - (pickup_way == 0 && *page * MAXPICKUP < (friendtotal + 1)) ){ + (pickup_way == 0 && *page * MAXPICKUP < MAX_FRIEND ) ) + { /* [嗨! 朋友] mode. we need to pickup ALL friends (from currutmp friend_online), sort, and get pickup from right starting position */ + pickup_t friends[MAX_FRIEND]; - pickup_t friends[MAX_FRIEND + 1]; + *nfriend = pickup_myfriend(friends, myfriend, friendme); - pickup_myfriend(friends, nfriend, myfriend, friendme); - for( which = *page * MAXPICKUP ; - got < MAXPICKUP && which < *nfriend ; - ++got, ++which ) - currpickup[got] = friends[which]; - } + if( pickup_way == 0 ) + *bfriend=pickup_bfriend(friends,*nfriend); + else + *bfriend=0; - if( pickup_way == 0 ){ - /* now pickup board friends */ - pickup_t friends[MAX_FRIEND + 1]; - pickup_bfriend(friends, bfriend); - which = *page * MAXPICKUP - *nfriend; - for( which = (which >= 0 ? which : 0) ; - got < MAXPICKUP && which < *bfriend ; - ++got, ++which ) - currpickup[got] = friends[which]; + all = *bfriend+ *nfriend ; + which = *page * MAXPICKUP; + if(all>which) // Ptt: 只有在要秀出才有必要 sort + { + qsort(friends, all, sizeof(pickup_t), sort_cmpfriend); + size=all-which; + if(size>MAXPICKUP) size= MAXPICKUP; + memcpy(currpickup, friends+which, sizeof(pickup_t)*size); + } } - if( !(cuser.uflag & FRIEND_FLAG) ){ + if( !(cuser.uflag & FRIEND_FLAG) && size < MAXPICKUP ) + { sorted_way = ((pickup_way == 0) ? 0 : (pickup_way - 1)); utmp = utmpshm->sorted[currsorted][sorted_way]; - - which = *page * MAXPICKUP - *nfriend - *bfriend; + which = *page * MAXPICKUP-all; + if(which<0) which=0; + for(;which < utmpnumber && size < MAXPICKUP;which++) + { + if(currutmp != utmp[which] && + !(friend_stat(currutmp,utmp[which])&ST_FRIEND) && + isvisible_stat(currutmp, utmp[which], 0)) + { + currpickup[size].ui = utmp[which]; + currpickup[size++].friend = 0; + } + } + } +/* for( which = (which >= 0 ? which : 0) ; got < MAXPICKUP && which < utmpnumber ; ++got, ++which ){ @@ -1578,10 +1593,10 @@ static void pickup(pickup_t *currpickup, int pickup_way, int *page, currpickup[got].ui = utmp[which]; currpickup[got].friend = 0; } - } +*/ - for( ; got < MAXPICKUP ; ++got ) - currpickup[got].ui = 0; + for( ; size < MAXPICKUP ; ++size ) + currpickup[size].ui = 0; } char *Mind[] = { @@ -1939,7 +1954,7 @@ static void userlist(void) fi = utmpshm->sorted[utmpshm->currsorted][0][si] - &utmpshm->uinfo[0]; - pickup_myfriend(friends, &nGots, &myfriend, &friendme); + nGots= pickup_myfriend(friends, &myfriend, &friendme); for( i = 0 ; i < nGots ; ++i ) if( friends[i].uoffset == fi ) break; -- cgit v1.2.3 From a747bbed1b2082f31339d58ab0e3029d7f6ae456 Mon Sep 17 00:00:00 2001 From: ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Tue, 4 Jun 2002 18:31:59 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@285 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/talk.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pttbbs/mbbsd/talk.c b/pttbbs/mbbsd/talk.c index cbdb9344..36adbd72 100644 --- a/pttbbs/mbbsd/talk.c +++ b/pttbbs/mbbsd/talk.c @@ -1,4 +1,4 @@ -/* $Id: talk.c,v 1.61 2002/06/04 18:08:59 ptt Exp $ */ +/* $Id: talk.c,v 1.62 2002/06/04 18:31:59 ptt Exp $ */ #include "bbs.h" #define QCAST int (*)(const void *, const void *) @@ -1514,7 +1514,7 @@ static int pickup_bfriend(pickup_t *friends, int base) ptr != NULL && ngets < MAX_FRIEND-base ; ptr = ptr->nextbfriend ){ if( currutmp != ptr && isvisible(currutmp, ptr) && - !(friend_stat(currutmp,ptr)&ST_FRIEND) ){ + !(friend_stat(currutmp,ptr)&(IFH|HFM)) ){ friends[ngets].ui = ptr; friends[ngets++].friend = IBH; } -- cgit v1.2.3 From d615d763e52de1f4492db6ad0954d22efcd277c6 Mon Sep 17 00:00:00 2001 From: ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Tue, 4 Jun 2002 18:54:41 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@286 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/talk.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pttbbs/mbbsd/talk.c b/pttbbs/mbbsd/talk.c index 36adbd72..4f54254d 100644 --- a/pttbbs/mbbsd/talk.c +++ b/pttbbs/mbbsd/talk.c @@ -1,4 +1,4 @@ -/* $Id: talk.c,v 1.62 2002/06/04 18:31:59 ptt Exp $ */ +/* $Id: talk.c,v 1.63 2002/06/04 18:54:41 ptt Exp $ */ #include "bbs.h" #define QCAST int (*)(const void *, const void *) @@ -1467,9 +1467,9 @@ int pickup_maxpages(int pickupway, int nfriend, int bfriend) if( cuser.uflag & FRIEND_FLAG ) number = nfriend + bfriend; else - number = utmpshm->number + - (pickupway == 0 ? nfriend + bfriend : 0); - return number / MAXPICKUP + (number % MAXPICKUP == 0 ? 0 : 1); + number = utmpshm->number; + // (pickupway == 0 ? nfriend + bfriend : 0); + return (number-1) / MAXPICKUP; } static int pickup_myfriend(pickup_t *friends, -- cgit v1.2.3 From 7411f0c63ef3dc814f19ef311573b421278765d5 Mon Sep 17 00:00:00 2001 From: ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Wed, 5 Jun 2002 01:50:40 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@287 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/talk.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/pttbbs/mbbsd/talk.c b/pttbbs/mbbsd/talk.c index 4f54254d..64a85d34 100644 --- a/pttbbs/mbbsd/talk.c +++ b/pttbbs/mbbsd/talk.c @@ -1,4 +1,4 @@ -/* $Id: talk.c,v 1.63 2002/06/04 18:54:41 ptt Exp $ */ +/* $Id: talk.c,v 1.64 2002/06/05 01:50:40 ptt Exp $ */ #include "bbs.h" #define QCAST int (*)(const void *, const void *) @@ -1492,7 +1492,6 @@ static int pickup_myfriend(pickup_t *friends, ){ friends[ngets].ui = uentp; friends[ngets].uoffset = where; - if(uentp->brc_id==currutmp->brc_id) frstate |= IBH; friends[ngets++].friend = frstate; if( frstate & IFH ) ++*myfriend; @@ -1514,7 +1513,7 @@ static int pickup_bfriend(pickup_t *friends, int base) ptr != NULL && ngets < MAX_FRIEND-base ; ptr = ptr->nextbfriend ){ if( currutmp != ptr && isvisible(currutmp, ptr) && - !(friend_stat(currutmp,ptr)&(IFH|HFM)) ){ + (base || !(friend_stat(currutmp,ptr)&(IFH|HFM))) ){ friends[ngets].ui = ptr; friends[ngets++].friend = IBH; } @@ -1571,7 +1570,7 @@ static void pickup(pickup_t *currpickup, int pickup_way, int *page, for(;which < utmpnumber && size < MAXPICKUP;which++) { if(currutmp != utmp[which] && - !(friend_stat(currutmp,utmp[which])&ST_FRIEND) && + (pickup_way||!(friend_stat(currutmp,utmp[which])&ST_FRIEND)) && isvisible_stat(currutmp, utmp[which], 0)) { currpickup[size].ui = utmp[which]; -- cgit v1.2.3 From 5238e9301a6cc39a0b8e169b72c40894880abc2c Mon Sep 17 00:00:00 2001 From: ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Wed, 5 Jun 2002 01:53:20 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@288 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/talk.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/pttbbs/mbbsd/talk.c b/pttbbs/mbbsd/talk.c index 64a85d34..445665dd 100644 --- a/pttbbs/mbbsd/talk.c +++ b/pttbbs/mbbsd/talk.c @@ -1,4 +1,4 @@ -/* $Id: talk.c,v 1.64 2002/06/05 01:50:40 ptt Exp $ */ +/* $Id: talk.c,v 1.65 2002/06/05 01:53:20 ptt Exp $ */ #include "bbs.h" #define QCAST int (*)(const void *, const void *) @@ -1468,14 +1468,13 @@ int pickup_maxpages(int pickupway, int nfriend, int bfriend) number = nfriend + bfriend; else number = utmpshm->number; - // (pickupway == 0 ? nfriend + bfriend : 0); + (pickupway == 0 ? nfriend + bfriend : 0); return (number-1) / MAXPICKUP; } static int pickup_myfriend(pickup_t *friends, int *myfriend, int *friendme) { - //pickup_t friends[MAX_FRIEND + 1]; userinfo_t *uentp; int i, where, frstate, ngets=0; -- cgit v1.2.3 From 41048328e61aab44f84455c93791f90f2d6b2d90 Mon Sep 17 00:00:00 2001 From: ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Wed, 5 Jun 2002 02:24:25 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@289 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/talk.c | 41 +++++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/pttbbs/mbbsd/talk.c b/pttbbs/mbbsd/talk.c index 445665dd..8b1ee687 100644 --- a/pttbbs/mbbsd/talk.c +++ b/pttbbs/mbbsd/talk.c @@ -1,4 +1,4 @@ -/* $Id: talk.c,v 1.65 2002/06/05 01:53:20 ptt Exp $ */ +/* $Id: talk.c,v 1.66 2002/06/05 02:24:25 ptt Exp $ */ #include "bbs.h" #define QCAST int (*)(const void *, const void *) @@ -1461,14 +1461,14 @@ static int sort_cmpfriend(const void *a, const void *b) (((pickup_t *)a)->friend & ST_FRIEND); } -int pickup_maxpages(int pickupway, int nfriend, int bfriend) +int pickup_maxpages(int pickupway, int nfriends) { int number; if( cuser.uflag & FRIEND_FLAG ) - number = nfriend + bfriend; + number = nfriends; else - number = utmpshm->number; - (pickupway == 0 ? nfriend + bfriend : 0); + number = utmpshm->number+ + (pickupway == 0 ? nfriends : 0); return (number-1) / MAXPICKUP; } @@ -1529,7 +1529,7 @@ static void pickup(pickup_t *currpickup, int pickup_way, int *page, int friendtotal= currutmp->friendtotal; userinfo_t **utmp; - int which, all=0, sorted_way, size=0; + int which, sorted_way, size=0; if( friendtotal == 0 ) *myfriend = *friendme = 1; @@ -1548,28 +1548,29 @@ static void pickup(pickup_t *currpickup, int pickup_way, int *page, *bfriend=pickup_bfriend(friends,*nfriend); else *bfriend=0; - - all = *bfriend+ *nfriend ; + *nfriend += *bfriend; which = *page * MAXPICKUP; - if(all>which) // Ptt: 只有在要秀出才有必要 sort + if(*nfriend>which) // Ptt: 只有在要秀出才有必要 sort { - qsort(friends, all, sizeof(pickup_t), sort_cmpfriend); - size=all-which; + qsort(friends, *nfriend, sizeof(pickup_t), sort_cmpfriend); + size=*nfriend-which; if(size>MAXPICKUP) size= MAXPICKUP; memcpy(currpickup, friends+which, sizeof(pickup_t)*size); } } + else + *nfriend=0; if( !(cuser.uflag & FRIEND_FLAG) && size < MAXPICKUP ) { sorted_way = ((pickup_way == 0) ? 0 : (pickup_way - 1)); utmp = utmpshm->sorted[currsorted][sorted_way]; - which = *page * MAXPICKUP-all; + which = *page * MAXPICKUP-*nfriend; if(which<0) which=0; for(;which < utmpnumber && size < MAXPICKUP;which++) { - if(currutmp != utmp[which] && - (pickup_way||!(friend_stat(currutmp,utmp[which])&ST_FRIEND)) && + if((pickup_way||(currutmp != utmp[which] && + !(friend_stat(currutmp,utmp[which])&ST_FRIEND))) && isvisible_stat(currutmp, utmp[which], 0)) { currpickup[size].ui = utmp[which]; @@ -1797,7 +1798,7 @@ static void userlist(void) break; if( offset == -1 ){ if( --page < 0 ) - page = pickup_maxpages(pickup_way, nfriend, bfriend) - 1; + page = pickup_maxpages(pickup_way, nfriend) - 1; offset = 0; continue; } @@ -1832,7 +1833,7 @@ static void userlist(void) if( ++offset == MAXPICKUP || currpickup[offset].ui == NULL ){ redraw = 1; if( ++page >= pickup_maxpages(pickup_way, - nfriend, bfriend) ) + nfriend) ) offset = page = 0; else offset = 0; @@ -1890,7 +1891,7 @@ static void userlist(void) case Ctrl('F'):{ int newpage; if( (newpage = page + 1) >= pickup_maxpages(pickup_way, - nfriend, bfriend) ) + nfriend) ) newpage = offset = 0; if( newpage != page ){ page = newpage; @@ -1905,7 +1906,7 @@ static void userlist(void) if( --offset == -1 ){ offset = MAXPICKUP - 1; if( --page == -1 ) - page = pickup_maxpages(pickup_way, nfriend, bfriend) + page = pickup_maxpages(pickup_way, nfriend) - 1; redraw = 1; } @@ -1915,14 +1916,14 @@ static void userlist(void) case Ctrl('B'): case 'P': if( --page == -1 ) - page = pickup_maxpages(pickup_way, nfriend, bfriend) - 1; + page = pickup_maxpages(pickup_way, nfriend) - 1; offset = 0; redraw = 1; break; case KEY_END: case '$': - page = pickup_maxpages(pickup_way, nfriend, bfriend) - 1; + page = pickup_maxpages(pickup_way, nfriend) - 1; offset = -1; redraw = 1; break; -- cgit v1.2.3 From b52e681d6487fbb31f18aeaf02a4cefd3d106f82 Mon Sep 17 00:00:00 2001 From: ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Wed, 5 Jun 2002 02:42:29 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@290 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/board.c | 32 ++++++++++++++++++-------------- pttbbs/mbbsd/mbbsd.c | 11 +---------- pttbbs/mbbsd/talk.c | 4 ++-- 3 files changed, 21 insertions(+), 26 deletions(-) diff --git a/pttbbs/mbbsd/board.c b/pttbbs/mbbsd/board.c index af997121..75503b23 100644 --- a/pttbbs/mbbsd/board.c +++ b/pttbbs/mbbsd/board.c @@ -1,4 +1,4 @@ -/* $Id: board.c,v 1.29 2002/06/04 13:08:33 in2 Exp $ */ +/* $Id: board.c,v 1.30 2002/06/05 02:42:29 ptt Exp $ */ #include "bbs.h" #define BRC_STRLEN 15 /* Length of board name */ #define BRC_MAXSIZE 24576 @@ -653,26 +653,30 @@ static void dozap(int num){ zapbuf[ptr->bid-1] = (ptr->myattr&BRD_ZAP?0:login_start_time); } -void setutmpbid(int bid) +void delutmpbid(int bid, userinfo_t *utmp) { - int id=currutmp->brc_id; userinfo_t *u; - if(id) - { - if (brdshm->busystate!=1 && now-brdshm->busystate_b[id-1]>=10) + if (brdshm->busystate!=1 && now-brdshm->busystate_b[bid-1]>=10) { - brdshm->busystate_b[id-1]=now; - u=bcache[id-1].u; - if(u!=(void*)currutmp) + brdshm->busystate_b[bid-1]=now; + u=bcache[bid-1].u; + if(u!=(void*)utmp) { - for(;u && u->nextbfriend != (void*)currutmp; u=u->nextbfriend); - if(u) u->nextbfriend = currutmp->nextbfriend; + for(;u && u->nextbfriend != (void*)utmp; u=u->nextbfriend); + if(u) u->nextbfriend = utmp->nextbfriend; } else - bcache[id-1].u=currutmp->nextbfriend; - if(bcache[id-1].nuser>0) bcache[id-1].nuser--; - brdshm->busystate_b[id-1]=0; + bcache[bid-1].u=utmp->nextbfriend; + if(bcache[bid-1].nuser>0) bcache[bid-1].nuser--; + brdshm->busystate_b[bid-1]=0; } +} + +void setutmpbid(int bid) +{ + if(currutmp->brc_id) + { + delutmpbid(currutmp->brc_id, currutmp); } if(bid) { diff --git a/pttbbs/mbbsd/mbbsd.c b/pttbbs/mbbsd/mbbsd.c index 036976f6..a933b6f3 100644 --- a/pttbbs/mbbsd/mbbsd.c +++ b/pttbbs/mbbsd/mbbsd.c @@ -1,4 +1,4 @@ -/* $Id: mbbsd.c,v 1.32 2002/06/04 13:08:33 in2 Exp $ */ +/* $Id: mbbsd.c,v 1.33 2002/06/05 02:42:29 ptt Exp $ */ #include "bbs.h" #define SOCKET_QLEN 4 @@ -724,7 +724,6 @@ setup_utmp (int mode) uinfo.pid = currpid = getpid (); uinfo.uid = usernum; uinfo.mode = currstat = mode; - uinfo.msgcount = 0; uinfo.mailalert = load_mailalert (cuser.userid); if (!(cuser.numlogins % 20) && cuser.userlevel & PERM_BM) check_BM (); /* Ptt 自動取下離職板主權力 */ @@ -732,26 +731,18 @@ setup_utmp (int mode) uinfo.userlevel = cuser.userlevel; uinfo.sex = cuser.sex % 8; uinfo.lastact = time (NULL); - - postrecord.times = 0; /* 計算crosspost數 */ - strcpy (uinfo.userid, cuser.userid); strcpy (uinfo.realname, cuser.realname); strcpy (uinfo.username, cuser.username); strncpy (uinfo.from, fromhost, 23); - uinfo.five_win = cuser.five_win; uinfo.five_lose = cuser.five_lose; uinfo.five_tie = cuser.five_tie; - uinfo.invisible = cuser.invisible % 2; uinfo.pager = cuser.pager%5; uinfo.mind = cuser.mind; - uinfo.brc_id = 0; #ifdef WHERE uinfo.from_alias = where (fromhost); -#else - uinfo.from_alias = 0; #endif #ifndef FAST_LOGIN setuserfile (buf, "remoteuser"); diff --git a/pttbbs/mbbsd/talk.c b/pttbbs/mbbsd/talk.c index 8b1ee687..3e078ef4 100644 --- a/pttbbs/mbbsd/talk.c +++ b/pttbbs/mbbsd/talk.c @@ -1,4 +1,4 @@ -/* $Id: talk.c,v 1.66 2002/06/05 02:24:25 ptt Exp $ */ +/* $Id: talk.c,v 1.67 2002/06/05 02:42:29 ptt Exp $ */ #include "bbs.h" #define QCAST int (*)(const void *, const void *) @@ -1469,7 +1469,7 @@ int pickup_maxpages(int pickupway, int nfriends) else number = utmpshm->number+ (pickupway == 0 ? nfriends : 0); - return (number-1) / MAXPICKUP; + return (number-1) / MAXPICKUP +1; } static int pickup_myfriend(pickup_t *friends, -- cgit v1.2.3 From b624b76ac6b282bf4427e965e44493d74a27b3b9 Mon Sep 17 00:00:00 2001 From: ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Wed, 5 Jun 2002 02:51:48 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@291 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/board.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pttbbs/mbbsd/board.c b/pttbbs/mbbsd/board.c index 75503b23..92a6c6e9 100644 --- a/pttbbs/mbbsd/board.c +++ b/pttbbs/mbbsd/board.c @@ -1,4 +1,4 @@ -/* $Id: board.c,v 1.30 2002/06/05 02:42:29 ptt Exp $ */ +/* $Id: board.c,v 1.31 2002/06/05 02:51:48 ptt Exp $ */ #include "bbs.h" #define BRC_STRLEN 15 /* Length of board name */ #define BRC_MAXSIZE 24576 @@ -656,7 +656,8 @@ static void dozap(int num){ void delutmpbid(int bid, userinfo_t *utmp) { userinfo_t *u; - if (brdshm->busystate!=1 && now-brdshm->busystate_b[bid-1]>=10) + //if (brdshm->busystate!=1 && now-brdshm->busystate_b[bid-1]>=10) + // Ptt:有問題都是這邊沒有執行到就爛掉了 { brdshm->busystate_b[bid-1]=now; u=bcache[bid-1].u; -- cgit v1.2.3 From 53029565a916c4a14cdf724e8b52b04a27c7520e Mon Sep 17 00:00:00 2001 From: ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Wed, 5 Jun 2002 03:06:11 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@292 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/board.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/pttbbs/mbbsd/board.c b/pttbbs/mbbsd/board.c index 92a6c6e9..7da01d72 100644 --- a/pttbbs/mbbsd/board.c +++ b/pttbbs/mbbsd/board.c @@ -1,4 +1,4 @@ -/* $Id: board.c,v 1.31 2002/06/05 02:51:48 ptt Exp $ */ +/* $Id: board.c,v 1.32 2002/06/05 03:06:11 ptt Exp $ */ #include "bbs.h" #define BRC_STRLEN 15 /* Length of board name */ #define BRC_MAXSIZE 24576 @@ -656,21 +656,20 @@ static void dozap(int num){ void delutmpbid(int bid, userinfo_t *utmp) { userinfo_t *u; - //if (brdshm->busystate!=1 && now-brdshm->busystate_b[bid-1]>=10) + while (brdshm->busystate!=1 && now-brdshm->busystate_b[bid-1]>=10) + sleep(1); // Ptt:有問題都是這邊沒有執行到就爛掉了 - { - brdshm->busystate_b[bid-1]=now; - u=bcache[bid-1].u; - if(u!=(void*)utmp) + brdshm->busystate_b[bid-1]=now; + u=bcache[bid-1].u; + if(u!=(void*)utmp) { for(;u && u->nextbfriend != (void*)utmp; u=u->nextbfriend); if(u) u->nextbfriend = utmp->nextbfriend; } - else + else bcache[bid-1].u=utmp->nextbfriend; - if(bcache[bid-1].nuser>0) bcache[bid-1].nuser--; - brdshm->busystate_b[bid-1]=0; - } + if(bcache[bid-1].nuser>0) bcache[bid-1].nuser--; + brdshm->busystate_b[bid-1]=0; } void setutmpbid(int bid) -- cgit v1.2.3 From 45d870b08d4137c3e4fc1851efdb1a829801752a Mon Sep 17 00:00:00 2001 From: ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Wed, 5 Jun 2002 03:08:56 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@293 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/board.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pttbbs/mbbsd/board.c b/pttbbs/mbbsd/board.c index 7da01d72..b9caf3cf 100644 --- a/pttbbs/mbbsd/board.c +++ b/pttbbs/mbbsd/board.c @@ -1,4 +1,4 @@ -/* $Id: board.c,v 1.32 2002/06/05 03:06:11 ptt Exp $ */ +/* $Id: board.c,v 1.33 2002/06/05 03:08:56 ptt Exp $ */ #include "bbs.h" #define BRC_STRLEN 15 /* Length of board name */ #define BRC_MAXSIZE 24576 @@ -659,6 +659,7 @@ void delutmpbid(int bid, userinfo_t *utmp) while (brdshm->busystate!=1 && now-brdshm->busystate_b[bid-1]>=10) sleep(1); // Ptt:有問題都是這邊沒有執行到就爛掉了 + brdshm->busystate_b[bid-1]=now; u=bcache[bid-1].u; if(u!=(void*)utmp) -- cgit v1.2.3 From ebcb92077456656ee77ad98fe0195e160bac1a3b Mon Sep 17 00:00:00 2001 From: ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Wed, 5 Jun 2002 03:10:43 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@294 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/board.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pttbbs/mbbsd/board.c b/pttbbs/mbbsd/board.c index b9caf3cf..15cdee5b 100644 --- a/pttbbs/mbbsd/board.c +++ b/pttbbs/mbbsd/board.c @@ -1,4 +1,4 @@ -/* $Id: board.c,v 1.33 2002/06/05 03:08:56 ptt Exp $ */ +/* $Id: board.c,v 1.34 2002/06/05 03:10:43 ptt Exp $ */ #include "bbs.h" #define BRC_STRLEN 15 /* Length of board name */ #define BRC_MAXSIZE 24576 @@ -656,7 +656,7 @@ static void dozap(int num){ void delutmpbid(int bid, userinfo_t *utmp) { userinfo_t *u; - while (brdshm->busystate!=1 && now-brdshm->busystate_b[bid-1]>=10) + while (brdshm->busystate || now-brdshm->busystate_b[bid-1]<5) sleep(1); // Ptt:有問題都是這邊沒有執行到就爛掉了 -- cgit v1.2.3 From 61bf1a715517ecbdb210eff5b606720539040780 Mon Sep 17 00:00:00 2001 From: ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Wed, 5 Jun 2002 03:22:43 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@295 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/talk.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/pttbbs/mbbsd/talk.c b/pttbbs/mbbsd/talk.c index 3e078ef4..e1feac1f 100644 --- a/pttbbs/mbbsd/talk.c +++ b/pttbbs/mbbsd/talk.c @@ -1,4 +1,4 @@ -/* $Id: talk.c,v 1.67 2002/06/05 02:42:29 ptt Exp $ */ +/* $Id: talk.c,v 1.68 2002/06/05 03:22:43 ptt Exp $ */ #include "bbs.h" #define QCAST int (*)(const void *, const void *) @@ -1529,7 +1529,7 @@ static void pickup(pickup_t *currpickup, int pickup_way, int *page, int friendtotal= currutmp->friendtotal; userinfo_t **utmp; - int which, sorted_way, size=0; + int which, sorted_way, size=0, friend; if( friendtotal == 0 ) *myfriend = *friendme = 1; @@ -1569,12 +1569,13 @@ static void pickup(pickup_t *currpickup, int pickup_way, int *page, if(which<0) which=0; for(;which < utmpnumber && size < MAXPICKUP;which++) { + friend = friend_stat(currutmp,utmp[which]); if((pickup_way||(currutmp != utmp[which] && - !(friend_stat(currutmp,utmp[which])&ST_FRIEND))) && + !(friend&ST_FRIEND))) && isvisible_stat(currutmp, utmp[which], 0)) { currpickup[size].ui = utmp[which]; - currpickup[size++].friend = 0; + currpickup[size++].friend = friend; } } } -- cgit v1.2.3 From 6ab3d6e3e90a67e21d550ef22abc5eb9c4d6ece6 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Thu, 6 Jun 2002 21:35:23 +0000 Subject: only one shared memory git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@296 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/include/bbs.h | 2 +- pttbbs/include/config.h | 5 +- pttbbs/include/proto.h | 8 +- pttbbs/include/pttstruct.h | 117 +++++++------- pttbbs/mbbsd/admin.c | 10 +- pttbbs/mbbsd/announce.c | 4 +- pttbbs/mbbsd/bbs.c | 6 +- pttbbs/mbbsd/board.c | 70 ++++---- pttbbs/mbbsd/cache.c | 379 +++++++++++++++++++++----------------------- pttbbs/mbbsd/cal.c | 4 +- pttbbs/mbbsd/chicken.c | 4 +- pttbbs/mbbsd/kaede.c | 4 +- pttbbs/mbbsd/mail.c | 12 +- pttbbs/mbbsd/mbbsd.c | 19 ++- pttbbs/mbbsd/menu.c | 19 ++- pttbbs/mbbsd/name.c | 14 +- pttbbs/mbbsd/talk.c | 63 ++++---- pttbbs/mbbsd/user.c | 4 +- pttbbs/mbbsd/var.c | 9 +- pttbbs/util/BM_money.c | 13 +- pttbbs/util/Makefile | 12 +- pttbbs/util/account.c | 52 +++--- pttbbs/util/bbsmail.c | 16 +- pttbbs/util/birth.c | 15 +- pttbbs/util/buildAnnounce.c | 26 ++- pttbbs/util/deluserfile.c | 13 +- pttbbs/util/expire.c | 18 +-- pttbbs/util/horoscope.c | 9 +- pttbbs/util/inndBM.c | 24 +-- pttbbs/util/jungo.c | 15 +- pttbbs/util/mandex.c | 15 +- pttbbs/util/openticket.c | 16 +- pttbbs/util/openvice.c | 14 +- pttbbs/util/parse_news.c | 13 +- pttbbs/util/post.c | 11 +- pttbbs/util/poststat.c | 148 +---------------- pttbbs/util/reaper.c | 15 +- pttbbs/util/rmuid.c | 13 +- pttbbs/util/shmctl.c | 149 ++++++++--------- pttbbs/util/shmsweep.c | 4 +- pttbbs/util/smtest.c | 15 +- pttbbs/util/toplazyBBM.c | 15 +- pttbbs/util/toplazyBM.c | 16 +- pttbbs/util/topusr.c | 12 +- pttbbs/util/uhash_loader.c | 28 ++-- pttbbs/util/userlist.c | 19 ++- pttbbs/util/util_cache.c | 224 +++++++++++++------------- pttbbs/util/xchatd.c | 36 +---- pttbbs/util/yearsold.c | 17 +- 49 files changed, 676 insertions(+), 1070 deletions(-) diff --git a/pttbbs/include/bbs.h b/pttbbs/include/bbs.h index 5d1469f9..7d2ef8d1 100644 --- a/pttbbs/include/bbs.h +++ b/pttbbs/include/bbs.h @@ -26,9 +26,9 @@ #include <arpa/inet.h> #include <arpa/telnet.h> #include <sys/types.h> +#include <dirent.h> #include <sys/mman.h> #include <machine/param.h> -#include <sys/types.h> #include <sys/ipc.h> #include <sys/shm.h> #include <sys/sem.h> diff --git a/pttbbs/include/config.h b/pttbbs/include/config.h index edec26dd..971c84be 100644 --- a/pttbbs/include/config.h +++ b/pttbbs/include/config.h @@ -1,4 +1,4 @@ -/* $Id: config.h,v 1.4 2002/06/04 13:07:12 in2 Exp $ */ +/* $Id: config.h,v 1.5 2002/06/06 21:34:09 in2 Exp $ */ #ifndef INCLUDE_CONFIG_H #define INCLUDE_CONFIG_H @@ -168,11 +168,14 @@ #define MAGIC_KEY 1234 /* 身分認證信函編碼 */ +#define SHM_KEY 1228 +#if 0 #define BRDSHM_KEY 1208 #define UHASH_KEY 1218 /* userid->uid hash */ #define UTMPSHM_KEY 2221 #define PTTSHM_KEY 1220 /* 動態看版 , 節日 */ #define FROMSHM_KEY 1223 /* whereis, 最多使用者 */ +#endif #define BRDSEM_KEY 2005 /* semaphore key */ #define PTTSEM_KEY 2000 /* semaphore key */ diff --git a/pttbbs/include/proto.h b/pttbbs/include/proto.h index 7d8d886f..ee32cd2d 100644 --- a/pttbbs/include/proto.h +++ b/pttbbs/include/proto.h @@ -1,4 +1,4 @@ -/* $Id: proto.h,v 1.20 2002/06/04 13:07:12 in2 Exp $ */ +/* $Id: proto.h,v 1.21 2002/06/06 21:34:09 in2 Exp $ */ #ifndef INCLUDE_PROTO_H #define INCLUDE_PROTO_H @@ -115,6 +115,9 @@ int mdcacheopen(char *fpath); void touchdircache(int bid); int get_fileheader_cache(int bid, char *direct, fileheader_t *headers, int recbase, int nlines); +void *attach_shm(int shmkey, int shmsize); +void attach_SHM(void); + /* cal */ int give_tax(int money); int vice(int money, char* item); @@ -559,4 +562,7 @@ int calendar(); /* util */ void touchbtotal(int bid); + +/* util_cache.c */ +void reload_pttcache(void); #endif diff --git a/pttbbs/include/pttstruct.h b/pttbbs/include/pttstruct.h index 91a0d036..a9c4db57 100644 --- a/pttbbs/include/pttstruct.h +++ b/pttbbs/include/pttstruct.h @@ -1,4 +1,4 @@ -/* $Id: pttstruct.h,v 1.13 2002/06/04 13:07:12 in2 Exp $ */ +/* $Id: pttstruct.h,v 1.14 2002/06/06 21:34:09 in2 Exp $ */ #ifndef INCLUDE_STRUCT_H #define INCLUDE_STRUCT_H @@ -165,12 +165,6 @@ typedef struct fileheader_t { #define HASH_BITS 16 typedef struct uhash_t { - char userid[MAX_USERS][IDLEN + 1]; - int next_in_hash[MAX_USERS]; - int money[MAX_USERS]; - int hash_head[1 << HASH_BITS]; - int number; /* # of users total */ - int loaded; /* .PASSWD has been loaded? */ } uhash_t; union xitem_t { @@ -291,20 +285,6 @@ typedef struct crosspost_t { #define SORT_BY_FIVE 4 #define SORT_BY_SEX 5 -typedef struct bcache_t { - boardheader_t bcache[MAX_BOARD]; - boardheader_t *sorted[2][MAX_BOARD]; /* 0: by name 1: by class */ - fileheader_t dircache[MAX_BOARD][DIRCACHESIZE]; - time_t busystate_b[MAX_BOARD]; - int total[MAX_BOARD]; - int hbfl[MAX_BOARD][MAX_FRIEND + 1]; - time_t lastposttime[MAX_BOARD]; - time_t uptime; - time_t touchtime; - int number; - int busystate; -} bcache_t; - typedef struct keeploc_t { char *key; int top_ln; @@ -314,42 +294,65 @@ typedef struct keeploc_t { #define USHM_SIZE (MAX_ACTIVE + 4) /* why+4? */ -struct utmpfile_t { - userinfo_t uinfo[USHM_SIZE]; - userinfo_t *sorted[2][8][USHM_SIZE]; - /* 第一維double buffer 由currsorted指向目前使用的 - 第二維sort type */ - int currsorted; - time_t uptime; - int number; - int busystate; -}; - -struct pttcache_t { - char notes[MAX_MOVIE][200*11]; - char today_is[20]; - int n_notes[MAX_MOVIE_SECTION]; /* 一節中有幾個 看板 */ - int next_refresh[MAX_MOVIE_SECTION]; /* 下一次要refresh的 看板 */ - int max_film; - int max_history; - time_t uptime; - time_t touchtime; - int busystate; - - int GLOBALVAR[10]; /* mbbsd間的 global variable - 用以做統計等資料 (非常態) */ -}; - -typedef struct fromcache_t { - char domain[MAX_FROM][50]; - char replace[MAX_FROM][50]; - int top; - int max_user; - time_t max_time; - time_t uptime; - time_t touchtime; - int busystate; -} fromcache_t; +typedef struct { + /* uhash */ + char userid[MAX_USERS][IDLEN + 1]; + int next_in_hash[MAX_USERS]; + int money[MAX_USERS]; + int hash_head[1 << HASH_BITS]; + int number; /* # of users total */ + int loaded; /* .PASSWD has been loaded? */ + + /* utmpshm */ + userinfo_t uinfo[USHM_SIZE]; + userinfo_t *sorted[2][8][USHM_SIZE]; + /* 第一維double buffer 由currsorted指向目前使用的 + 第二維sort type */ + int currsorted; + time_t UTMPuptime; + int UTMPnumber; + int UTMPbusystate; + + char gap[1024]; /* avoid some memory error / buffer overflow */ + /* brdshm */ + boardheader_t bcache[MAX_BOARD]; + boardheader_t *bsorted[2][MAX_BOARD]; /* 0: by name 1: by class */ + fileheader_t dircache[MAX_BOARD][DIRCACHESIZE]; + time_t busystate_b[MAX_BOARD]; + int total[MAX_BOARD]; + int hbfl[MAX_BOARD][MAX_FRIEND + 1]; + time_t lastposttime[MAX_BOARD]; + time_t Buptime; + time_t Btouchtime; + int Bnumber; + int Bbusystate; + + char gap2[1024]; /* avoid some memory error / buffer overflow */ + /* pttcache */ + char notes[MAX_MOVIE][200*11]; + char today_is[20]; + int n_notes[MAX_MOVIE_SECTION]; /* 一節中有幾個 看板 */ + int next_refresh[MAX_MOVIE_SECTION]; /* 下一次要refresh的 看板 */ + int max_film; + int max_history; + time_t Puptime; + time_t Ptouchtime; + int Pbusystate; + + int GLOBALVAR[10]; /* mbbsd間的 global variable + 用以做統計等資料 (非常態) */ + + char gap3[1024]; /* avoid some memory error / buffer overflow */ + /* fromcache */ + char domain[MAX_FROM][50]; + char replace[MAX_FROM][50]; + int top; + int max_user; + time_t max_time; + time_t Fuptime; + time_t Ftouchtime; + int Fbusystate; +} SHM_t; typedef struct { unsigned char oldlen; /* previous line length */ diff --git a/pttbbs/mbbsd/admin.c b/pttbbs/mbbsd/admin.c index 9d795f90..48e21777 100644 --- a/pttbbs/mbbsd/admin.c +++ b/pttbbs/mbbsd/admin.c @@ -1,4 +1,4 @@ -/* $Id: admin.c,v 1.20 2002/06/04 13:08:33 in2 Exp $ */ +/* $Id: admin.c,v 1.21 2002/06/06 21:34:11 in2 Exp $ */ #include "bbs.h" /* 使用者管理 */ @@ -368,7 +368,7 @@ int m_board() { char bname[32]; stand_title("看板設定"); - generalnamecomplete(msg_bid, bname, sizeof(bname), brdshm->number, + generalnamecomplete(msg_bid, bname, sizeof(bname), SHM->Bnumber, completeboard_compar, completeboard_permission, completeboard_getname); @@ -1053,10 +1053,10 @@ int give_money() { stand_title("發錢中..."); if(to_all) { int i, unum; - for(unum = uhash->number, i=0; i<unum; i++) { - if(bad_user_id(uhash->userid[i])) + for(unum = SHM->number, i=0; i<unum; i++) { + if(bad_user_id(SHM->userid[i])) continue; - id = uhash->userid[i]; + id = SHM->userid[i]; give_id_money(id, money, fp2, tt, now); } // something wrong @_@ diff --git a/pttbbs/mbbsd/announce.c b/pttbbs/mbbsd/announce.c index 3afdbac2..d7fe9cde 100644 --- a/pttbbs/mbbsd/announce.c +++ b/pttbbs/mbbsd/announce.c @@ -1,4 +1,4 @@ -/* $Id: announce.c,v 1.10 2002/06/04 13:08:33 in2 Exp $ */ +/* $Id: announce.c,v 1.11 2002/06/06 21:34:11 in2 Exp $ */ #include "bbs.h" static void g_showmenu(gmenu_t *pm) { @@ -472,7 +472,7 @@ static int AnnounceSelect() { clrtoeol(); move(1, 0); generalnamecomplete("選擇精華區看板:", buf, sizeof(buf), - brdshm->number, + SHM->Bnumber, completeboard_compar, completeboard_permission, completeboard_getname); diff --git a/pttbbs/mbbsd/bbs.c b/pttbbs/mbbsd/bbs.c index 4b401280..6b08d1db 100644 --- a/pttbbs/mbbsd/bbs.c +++ b/pttbbs/mbbsd/bbs.c @@ -1,4 +1,4 @@ -/* $Id: bbs.c,v 1.48 2002/06/04 13:08:33 in2 Exp $ */ +/* $Id: bbs.c,v 1.49 2002/06/06 21:34:11 in2 Exp $ */ #include "bbs.h" static void mail_by_link(char* owner, char* title, char* path) { @@ -245,7 +245,7 @@ static int do_select(int ent, fileheader_t *fhdr, char *direct) { move(0, 0); clrtoeol(); generalnamecomplete(MSG_SELECT_BOARD, bname, sizeof(bname), - brdshm->number, + SHM->Bnumber, completeboard_compar, completeboard_permission, completeboard_getname); @@ -727,7 +727,7 @@ static int cross_post(int ent, fileheader_t *fhdr, char *direct) { if (bp && (bp->brdattr & BRD_VOTEBOARD)) return FULLUPDATE; generalnamecomplete("轉錄本文章於看板:", xboard, sizeof(xboard), - brdshm->number, + SHM->Bnumber, completeboard_compar, completeboard_permission, completeboard_getname); diff --git a/pttbbs/mbbsd/board.c b/pttbbs/mbbsd/board.c index 15cdee5b..ad19d881 100644 --- a/pttbbs/mbbsd/board.c +++ b/pttbbs/mbbsd/board.c @@ -1,4 +1,4 @@ -/* $Id: board.c,v 1.34 2002/06/05 03:10:43 ptt Exp $ */ +/* $Id: board.c,v 1.35 2002/06/06 21:34:11 in2 Exp $ */ #include "bbs.h" #define BRC_STRLEN 15 /* Length of board name */ #define BRC_MAXSIZE 24576 @@ -354,23 +354,21 @@ static void load_uidofgid(const int gid, const int type){ boardheader_t *bptr,*currbptr; int n, childcount=0; currbptr = &bcache[gid-1]; - for(n=0;n<numboards;n++) - { - bptr = brdshm->sorted[type][n]; - if(bptr->brdname[0]=='\0') continue; - if(bptr->gid == gid) - { - if(currbptr == &bcache[gid-1]) - currbptr->firstchild[type]=bptr; - else - { - currbptr->next[type]=bptr; - currbptr->parent=&bcache[gid-1]; + for( n = 0 ; n < numboards ; ++n ){ + bptr = SHM->bsorted[type][n]; + if( bptr->brdname[0] == '\0' ) + continue; + if( bptr->gid == gid ){ + if(currbptr == &bcache[gid-1]) + currbptr->firstchild[type]=bptr; + else{ + currbptr->next[type]=bptr; + currbptr->parent=&bcache[gid-1]; } - childcount++; - currbptr=bptr; - } - } + childcount++; + currbptr=bptr; + } + } bcache[gid-1].childcount=childcount; if(currbptr == &bcache[gid-1]) currbptr->firstchild[type]=(boardheader_t *) ~0; @@ -381,8 +379,8 @@ static boardstat_t * addnewbrdstat(int n, int state) { boardstat_t *ptr=&nbrd[brdnum++]; boardheader_t *bptr = &bcache[n]; - ptr->total = &(brdshm->total[n]); - ptr->lastposttime = &(brdshm->lastposttime[n]); + ptr->total = &(SHM->total[n]); + ptr->lastposttime = &(SHM->lastposttime[n]); ptr->bid = n+1; ptr->myattr=0; ptr->myattr=(favbuf[n]&~BRD_ZAP); @@ -418,7 +416,7 @@ static void load_boards(char *key) { nbrd = (boardstat_t *)malloc(numboards * sizeof(boardstat_t)); for(i=0 ; i < numboards; i++) { - if( (bptr = brdshm->sorted[type][i]) == NULL ) + if( (bptr = SHM->bsorted[type][i]) == NULL ) continue; n = (int)( bptr - bcache); if(!bptr->brdname[0] || bptr->brdattr & BRD_GROUPBOARD || @@ -656,21 +654,23 @@ static void dozap(int num){ void delutmpbid(int bid, userinfo_t *utmp) { userinfo_t *u; - while (brdshm->busystate || now-brdshm->busystate_b[bid-1]<5) - sleep(1); - // Ptt:有問題都是這邊沒有執行到就爛掉了 - - brdshm->busystate_b[bid-1]=now; - u=bcache[bid-1].u; - if(u!=(void*)utmp) - { - for(;u && u->nextbfriend != (void*)utmp; u=u->nextbfriend); - if(u) u->nextbfriend = utmp->nextbfriend; - } - else - bcache[bid-1].u=utmp->nextbfriend; - if(bcache[bid-1].nuser>0) bcache[bid-1].nuser--; - brdshm->busystate_b[bid-1]=0; + while( SHM->Bbusystate || now - SHM->busystate_b[bid - 1] < 5 ) + sleep(1); + // Ptt:有問題都是這邊沒有執行到就爛掉了 + + SHM->busystate_b[bid-1] = now; + u = bcache[bid - 1].u; + if( u != (void *)utmp ){ + for( ; u && u->nextbfriend != (void*)utmp; u = u->nextbfriend ) + ; + if( u ) + u->nextbfriend = utmp->nextbfriend; + } + else + bcache[bid - 1].u = utmp->nextbfriend; + if( bcache[bid - 1].nuser > 0 ) + bcache[bid - 1].nuser--; + SHM->busystate_b[bid - 1] = 0; } void setutmpbid(int bid) diff --git a/pttbbs/mbbsd/cache.c b/pttbbs/mbbsd/cache.c index ab87c3a0..d2c47fe7 100644 --- a/pttbbs/mbbsd/cache.c +++ b/pttbbs/mbbsd/cache.c @@ -1,4 +1,4 @@ -/* $Id: cache.c,v 1.31 2002/06/04 13:08:33 in2 Exp $ */ +/* $Id: cache.c,v 1.32 2002/06/06 21:34:11 in2 Exp $ */ #include "bbs.h" #ifndef __FreeBSD__ @@ -9,7 +9,6 @@ union semun { struct seminfo *__buf; /* buffer for IPC_INFO */ }; #endif -int fcache_semid; /* the reason for "safe_sleep" is that we may call sleep during SIGALRM handler routine, while SIGALRM is blocked. @@ -53,7 +52,7 @@ static void attach_err(int shmkey, char *name) { exit(1); } -static void *attach_shm(int shmkey, int shmsize) { +void *attach_shm(int shmkey, int shmsize) { void *shmptr; int shmid; @@ -130,74 +129,86 @@ void sem_lock(int op,int semid) { */ /* attach_uhash should be called before using uhash */ -void attach_uhash() { - uhash = attach_shm(UHASH_KEY, sizeof(*uhash)); - if(!uhash->loaded) /* assume fresh shared memory is zeroed */ + +void attach_SHM(void) +{ + SHM = attach_shm(SHM_KEY, sizeof(SHM_t)); + if( !SHM->loaded ) /* (uhash) assume fresh shared memory is zeroed */ exit(1); + if( SHM->Btouchtime == 0 ) + SHM->Btouchtime = 1; + bcache = SHM->bcache; + + GLOBALVAR = SHM->GLOBALVAR; + if( SHM->Ptouchtime == 0 ) + SHM->Ptouchtime = 1; + + if( SHM->Ftouchtime == 0 ) + SHM->Ftouchtime = 1; } void add_to_uhash(int n, char *id) { int *p, h = StringHash(id); int times; - strcpy(uhash->userid[n], id); + strcpy(SHM->userid[n], id); - p = &(uhash->hash_head[h]); + p = &(SHM->hash_head[h]); for( times = 0 ; times < MAX_USERS && *p != -1 ; ++times ) - p = &(uhash->next_in_hash[*p]); + p = &(SHM->next_in_hash[*p]); if( times == MAX_USERS ) abort_bbs(0); - uhash->next_in_hash[*p = n] = -1; + SHM->next_in_hash[*p = n] = -1; } /* note: after remove_from_uhash(), you should add_to_uhash() (likely with a different name) */ void remove_from_uhash(int n) { - int h = StringHash(uhash->userid[n]); - int *p = &(uhash->hash_head[h]); + int h = StringHash(SHM->userid[n]); + int *p = &(SHM->hash_head[h]); int times; for( times = 0 ; times < MAX_USERS && (*p != -1 && *p != n); ++times ) - p = &(uhash->next_in_hash[*p]); + p = &(SHM->next_in_hash[*p]); if( times == MAX_USERS ) abort_bbs(0); if(*p == n) - *p = uhash->next_in_hash[n]; + *p = SHM->next_in_hash[n]; } int setumoney(int uid, int money) { - uhash->money[uid-1]=money; + SHM->money[uid-1]=money; passwd_update_money(uid); - return uhash->money[uid-1]; + return SHM->money[uid-1]; } int deumoney(int uid, int money) { - if(money<0 && uhash->money[uid-1]<-money) + if(money<0 && SHM->money[uid-1]<-money) return setumoney(uid,0); else - return setumoney(uid,uhash->money[uid-1]+money); + return setumoney(uid,SHM->money[uid-1]+money); } int demoney(int money) { return deumoney(usernum,money); } int moneyof(int uid){ /* ptt 改進金錢處理效率 */ - return uhash->money[uid-1]; + return SHM->money[uid-1]; } int searchuser(char *userid) { int h, p, times; h = StringHash(userid); - p = uhash->hash_head[h]; + p = SHM->hash_head[h]; for( times = 0 ; times < MAX_USERS && p != -1 ; ++times ){ - if(strcasecmp(uhash->userid[p],userid) == 0) { - strcpy(userid,uhash->userid[p]); + if(strcasecmp(SHM->userid[p],userid) == 0) { + strcpy(userid,SHM->userid[p]); return p + 1; } - p = uhash->next_in_hash[p]; + p = SHM->next_in_hash[p]; } return 0; @@ -215,14 +226,14 @@ int getuser(char *userid) { char *getuserid(int num) { if(--num >= 0 && num < MAX_USERS) - return ((char *) uhash->userid[num]); + return ((char *) SHM->userid[num]); return NULL; } void setuserid(int num, char *userid) { if(num > 0 && num <= MAX_USERS) { - if(num > uhash->number) - uhash->number = num; + if(num > SHM->number) + SHM->number = num; else remove_from_uhash(num-1); add_to_uhash(num-1,userid); @@ -235,12 +246,12 @@ void setuserid(int num, char *userid) { int searchnewuser(int mode) { register int i, num; - num = uhash->number; + num = SHM->number; i = 0; /* 為什麼這邊不用 hash table 去找而要用 linear search? */ while(i < num) { - if(!uhash->userid[i++][0]) + if(!SHM->userid[i++][0]) return i; } if(mode && (num < MAX_USERS)) @@ -249,24 +260,23 @@ int searchnewuser(int mode) { } char *u_namearray(char buf[][IDLEN + 1], int *pnum, char *tag) { - register struct uhash_t *reg_ushm = uhash; register char *ptr, tmp; register int n, total; char tagbuf[STRLEN]; int ch, ch2, num; if(*tag == '\0') { - *pnum = reg_ushm->number; - return reg_ushm->userid[0]; + *pnum = SHM->number; + return SHM->userid[0]; } for(n = 0; tag[n]; n++) tagbuf[n] = chartoupper(tag[n]); tagbuf[n] = '\0'; ch = tagbuf[0]; ch2 = ch - 'A' + 'a'; - total = reg_ushm->number; + total = SHM->number; for(n = num = 0; n < total; n++) { - ptr = reg_ushm->userid[n]; + ptr = SHM->userid[n]; tmp = *ptr; if(tmp == ch || tmp == ch2) { if(chkstr(tag, tagbuf, ptr)) @@ -281,12 +291,6 @@ char *u_namearray(char buf[][IDLEN + 1], int *pnum, char *tag) { /*-------------------------------------------------------*/ /* .UTMP cache */ /*-------------------------------------------------------*/ -void resolve_utmp() { - if(utmpshm == NULL) { - utmpshm = attach_shm(UTMPSHM_KEY, sizeof(*utmpshm)); - } -} - #if !defined(_BBS_UTIL_C_) void setutmpmode(int mode) { if(currstat != mode) @@ -343,50 +347,50 @@ void sort_utmp() int count, i, ns; userinfo_t *uentp; now=time(0); - if(now-utmpshm->uptime<60 && (now==utmpshm->uptime || utmpshm->busystate)) - return; /* lazy sort */ - utmpshm->busystate=1; - utmpshm->uptime = now; - ns=(utmpshm->currsorted?0:1); - - for(uentp = &utmpshm->uinfo[0], count=0, i=0; - i< USHM_SIZE; i++,uentp = &utmpshm->uinfo[i]) - { - if(uentp->pid) - { - if(uentp->sex<0 || uentp->sex>7) - memset(uentp, 0, sizeof(userinfo_t)); - else - utmpshm->sorted[ns][0][count++]= uentp; + if( now - SHM->UTMPuptime < 60 && + (now == SHM->UTMPuptime || SHM->UTMPbusystate) ) + return; /* lazy sort */ + SHM->UTMPbusystate=1; + SHM->UTMPuptime = now; + ns = (SHM->currsorted ? 0 : 1); + + for( uentp = &SHM->uinfo[0], count = i = 0 ; + i < USHM_SIZE ; + ++i, uentp = &SHM->uinfo[i] ){ + if(uentp->pid) { + if(uentp->sex<0 || uentp->sex>7) + memset(uentp, 0, sizeof(userinfo_t)); + else + SHM->sorted[ns][0][count++]= uentp; } - } - utmpshm->number = count; - qsort(utmpshm->sorted[ns][0],count,sizeof(userinfo_t*),cmputmpuserid); + } + SHM->UTMPnumber = count; + qsort(SHM->sorted[ns][0],count,sizeof(userinfo_t*),cmputmpuserid); for(i=0; i<count; i++) - ((userinfo_t*)utmpshm->sorted[ns][0][i])->idoffset=i; - memcpy(utmpshm->sorted[ns][1],utmpshm->sorted[ns][0], + ((userinfo_t*)SHM->sorted[ns][0][i])->idoffset=i; + memcpy(SHM->sorted[ns][1],SHM->sorted[ns][0], sizeof(userinfo_t *)*count); - memcpy(utmpshm->sorted[ns][2],utmpshm->sorted[ns][0], + memcpy(SHM->sorted[ns][2],SHM->sorted[ns][0], sizeof(userinfo_t *)*count); - memcpy(utmpshm->sorted[ns][3],utmpshm->sorted[ns][0], + memcpy(SHM->sorted[ns][3],SHM->sorted[ns][0], sizeof(userinfo_t *)*count); - memcpy(utmpshm->sorted[ns][4],utmpshm->sorted[ns][0], + memcpy(SHM->sorted[ns][4],SHM->sorted[ns][0], sizeof(userinfo_t *)*count); - memcpy(utmpshm->sorted[ns][5],utmpshm->sorted[ns][0], + memcpy(SHM->sorted[ns][5],SHM->sorted[ns][0], sizeof(userinfo_t *)*count); - memcpy(utmpshm->sorted[ns][6],utmpshm->sorted[ns][0], + memcpy(SHM->sorted[ns][6],SHM->sorted[ns][0], sizeof(userinfo_t *)*count); - memcpy(utmpshm->sorted[ns][7],utmpshm->sorted[ns][0], + memcpy(SHM->sorted[ns][7],SHM->sorted[ns][0], sizeof(userinfo_t *)*count); - qsort(utmpshm->sorted[ns][1], count, sizeof(userinfo_t *), cmputmpmode ); - qsort(utmpshm->sorted[ns][2], count, sizeof(userinfo_t *), cmputmpidle ); - qsort(utmpshm->sorted[ns][3], count, sizeof(userinfo_t *), cmputmpfrom ); - qsort(utmpshm->sorted[ns][4], count, sizeof(userinfo_t *), cmputmpfive ); - qsort(utmpshm->sorted[ns][5], count, sizeof(userinfo_t *), cmputmpsex ); - qsort(utmpshm->sorted[ns][6], count, sizeof(userinfo_t *), cmputmpuid ); - qsort(utmpshm->sorted[ns][7], count, sizeof(userinfo_t *), cmputmppid ); - utmpshm->currsorted=ns; - utmpshm->busystate=0; + qsort(SHM->sorted[ns][1], count, sizeof(userinfo_t *), cmputmpmode ); + qsort(SHM->sorted[ns][2], count, sizeof(userinfo_t *), cmputmpidle ); + qsort(SHM->sorted[ns][3], count, sizeof(userinfo_t *), cmputmpfrom ); + qsort(SHM->sorted[ns][4], count, sizeof(userinfo_t *), cmputmpfive ); + qsort(SHM->sorted[ns][5], count, sizeof(userinfo_t *), cmputmpsex ); + qsort(SHM->sorted[ns][6], count, sizeof(userinfo_t *), cmputmpuid ); + qsort(SHM->sorted[ns][7], count, sizeof(userinfo_t *), cmputmppid ); + SHM->currsorted=ns; + SHM->UTMPbusystate=0; } // Ptt:這邊加入hash觀念 找空的utmp void getnewutmpent(userinfo_t *up) { @@ -394,7 +398,7 @@ void getnewutmpent(userinfo_t *up) { register userinfo_t *uentp; for(i = 0, p=StringHash(up->userid)%USHM_SIZE; i < USHM_SIZE; i++, p++) { if(p==USHM_SIZE) p=0; - uentp = &(utmpshm->uinfo[p]); + uentp = &(SHM->uinfo[p]); if(!(uentp->pid)) { memcpy(uentp, up, sizeof(userinfo_t)); currutmp = uentp; @@ -410,7 +414,7 @@ int apply_ulist(int (*fptr)(userinfo_t *)) { register int i, state; for(i = 0; i < USHM_SIZE; i++) { - uentp = &(utmpshm->uinfo[i]); + uentp = &(SHM->uinfo[i]); if(uentp->pid && (PERM_HIDE(currutmp) || !PERM_HIDE(uentp))) if((state = (*fptr) (uentp))) return state; @@ -424,11 +428,11 @@ userinfo_t *search_ulist(int uid) { #if !defined(_BBS_UTIL_C_) userinfo_t *search_ulist_pid(int pid) { - register int i=0, j, start = 0, end = utmpshm->number - 1; + register int i=0, j, start = 0, end = SHM->UTMPnumber - 1; register userinfo_t **ulist; if( end == -1 ) return NULL; - ulist=utmpshm->sorted[utmpshm->currsorted][7]; + ulist=SHM->sorted[SHM->currsorted][7]; for(i=((start+end)/2); ;i=(start+end)/2) { j=pid-ulist[i]->pid; @@ -451,11 +455,11 @@ userinfo_t *search_ulist_pid(int pid) { return 0; } userinfo_t *search_ulistn(int uid, int unum) { - register int i=0, j, start = 0, end = utmpshm->number - 1; + register int i=0, j, start = 0, end = SHM->UTMPnumber - 1; register userinfo_t **ulist; if( end == -1 ) return NULL; - ulist=utmpshm->sorted[utmpshm->currsorted][6]; + ulist=SHM->sorted[SHM->currsorted][6]; for(i=((start+end)/2); ;i=(start+end)/2) { j= uid - ulist[i]->uid; @@ -482,11 +486,11 @@ userinfo_t *search_ulistn(int uid, int unum) { } int count_logins(int uid, int show) { - register int i=0, j, start = 0, end = utmpshm->number - 1, count; + register int i=0, j, start = 0, end = SHM->UTMPnumber - 1, count; register userinfo_t **ulist; if( end == -1 ) return NULL; - ulist=utmpshm->sorted[utmpshm->currsorted][6]; + ulist=SHM->sorted[SHM->currsorted][6]; for(i=((start+end)/2); ;i=(start+end)/2) { j = uid-ulist[i]->uid; @@ -530,7 +534,7 @@ void purge_utmp(userinfo_t *uentp) { /*-------------------------------------------------------*/ void touchdircache(int bid) { - int *i= (int *)&brdshm->dircache[bid - 1][0].filename[0]; + int *i= (int *)&SHM->dircache[bid - 1][0].filename[0]; *i=0; } @@ -538,15 +542,15 @@ void load_fileheader_cache(int bid, char *direct) { int num=getbtotal(bid); int n = num-DIRCACHESIZE+1; - if (brdshm->busystate!=1 && now-brdshm->busystate_b[bid-1]>=10 ) - { - brdshm->busystate_b[bid-1] = now; - get_records(direct, brdshm->dircache[bid - 1] , - sizeof(fileheader_t),n<1?1:n, DIRCACHESIZE); - brdshm->busystate_b[bid-1] = 0; - } - else - {safe_sleep(1);} + if( SHM->Bbusystate != 1 && now - SHM->busystate_b[bid - 1] >= 10 ){ + SHM->busystate_b[bid-1] = now; + get_records(direct, SHM->dircache[bid - 1] , + sizeof(fileheader_t),n<1?1:n, DIRCACHESIZE); + SHM->busystate_b[bid-1] = 0; + } + else{ + safe_sleep(1); + } } int get_fileheader_cache(int bid, char *direct, fileheader_t *headers, @@ -560,7 +564,7 @@ int get_fileheader_cache(int bid, char *direct, fileheader_t *headers, n = (num - DIRCACHESIZE+1); - if(brdshm->dircache[bid - 1][0].filename[0]=='\0') + if(SHM->dircache[bid - 1][0].filename[0]=='\0') load_fileheader_cache(bid, direct); if (n<1) n=recbase-1; @@ -568,7 +572,7 @@ int get_fileheader_cache(int bid, char *direct, fileheader_t *headers, n=recbase-n; if(n<0) n=0; if (ret>nlines) ret=nlines; - memcpy(headers, &(brdshm->dircache[bid - 1][n]),sizeof(fileheader_t)*ret); + memcpy(headers, &(SHM->dircache[bid - 1][n]),sizeof(fileheader_t)*ret); return ret; } static int cmpboardname(boardheader_t **brd, boardheader_t **tmp) { @@ -578,72 +582,66 @@ static int cmpboardclass(boardheader_t **brd, boardheader_t **tmp) { return (strncmp((*brd)->title, (*tmp)->title, 4)<<8)+ strcasecmp((*brd)->brdname, (*tmp)->brdname); } -static void sort_bcache(){ - int i;/*critical section 不能單獨呼叫 呼叫reload_bcache or reset_board */ - for(i=0;i<brdshm->number;i++) - { - brdshm->sorted[1][i]=brdshm->sorted[0][i]=&bcache[i]; - } - qsort(brdshm->sorted[0], brdshm->number, sizeof(boardheader_t *), +static void sort_bcache() +{ + int i; + /*critical section 不能單獨呼叫 呼叫reload_bcache or reset_board */ + for(i=0;i<SHM->Bnumber;i++){ + SHM->bsorted[1][i]=SHM->bsorted[0][i]=&bcache[i]; + } + qsort(SHM->bsorted[0], SHM->Bnumber, sizeof(boardheader_t *), (QCAST)cmpboardname); - qsort(brdshm->sorted[1], brdshm->number, sizeof(boardheader_t *), + qsort(SHM->bsorted[1], SHM->Bnumber, sizeof(boardheader_t *), (QCAST)cmpboardclass); } static void reload_bcache() { - if(brdshm->busystate) { + if( SHM->Bbusystate ){ safe_sleep(1); } #if !defined(_BBS_UTIL_C_) else { int fd,i; - brdshm->busystate = 1; + SHM->Bbusystate = 1; if((fd = open(fn_board, O_RDONLY)) > 0) { - brdshm->number = + SHM->Bnumber = read(fd, bcache, MAX_BOARD * sizeof(boardheader_t)) / sizeof(boardheader_t); close(fd); } - memset(brdshm->lastposttime, 0, MAX_BOARD * sizeof(time_t)); + memset(SHM->lastposttime, 0, MAX_BOARD * sizeof(time_t)); /* 等所有 boards 資料更新後再設定 uptime */ - brdshm->uptime = brdshm->touchtime; + SHM->Buptime = SHM->Btouchtime; log_usies("CACHE", "reload bcache"); sort_bcache(); - for(i=0;i<brdshm->number;i++) - { - bcache[i].u=NULL; - bcache[i].nuser=0; - bcache[i].firstchild[0]=NULL; - bcache[i].firstchild[1]=NULL; - } - brdshm->busystate = 0; + for( i = 0 ; i < SHM->Bnumber ; ++i ){ + bcache[i].u=NULL; + bcache[i].nuser=0; + bcache[i].firstchild[0]=NULL; + bcache[i].firstchild[1]=NULL; + } + SHM->Bbusystate = 0; } #endif } void resolve_boards() { - if(brdshm == NULL) { - brdshm = attach_shm(BRDSHM_KEY, sizeof(*brdshm)); - if(brdshm->touchtime == 0) - brdshm->touchtime = 1; - bcache = brdshm->bcache; + while( SHM->Buptime < SHM->Btouchtime ){ + reload_bcache(); } - - while(brdshm->uptime < brdshm->touchtime) - {reload_bcache();} - numboards = brdshm->number; + numboards = SHM->Bnumber; } void touch_boards() { - brdshm->touchtime=now; + SHM->Btouchtime=now; numboards = -1; resolve_boards(); } void addbrd_touchcache() { - brdshm->number++; - numboards=brdshm->number; - reset_board(numboards); + SHM->Bnumber++; + numboards=SHM->Bnumber; + reset_board(numboards); } #if !defined(_BBS_UTIL_C_) void reset_board(int bid) { /* Ptt: 這樣就不用老是touch board了 */ @@ -654,10 +652,10 @@ void reset_board(int bid) { /* Ptt: if(--bid < 0) return; - if(brdshm->busystate || now-brdshm->busystate_b[bid-1]<10 ) { + if( SHM->Bbusystate || now - SHM->busystate_b[bid - 1] < 10 ){ safe_sleep(1); } else { - brdshm->busystate_b[bid-1] = now; + SHM->busystate_b[bid-1] = now; nuser = bcache[bid-1].nuser; u = bcache[bid-1].u; @@ -669,14 +667,14 @@ void reset_board(int bid) { /* Ptt: close(fd); } sort_bcache(); - for(i=0;i<brdshm->number;i++) + for(i=0;i<SHM->Bnumber;i++) { bcache[i].firstchild[0]=NULL; bcache[i].firstchild[1]=NULL; } nuser = bcache[bid-1].nuser; u = bcache[bid-1].u; - brdshm->busystate_b[bid-1] = 0; + SHM->busystate_b[bid-1] = 0; } } @@ -698,7 +696,7 @@ boardheader_t *getbcache(int bid) { /* Ptt } int getbtotal(int bid) { - return brdshm->total[bid - 1]; + return SHM->total[bid - 1]; } void setbtotal(int bid) { boardheader_t *bh = getbcache(bid); @@ -712,34 +710,35 @@ void setbtotal(int bid) { return; /* .DIR掛了 */ fstat(fd, &st); num = st.st_size / sizeof(fileheader_t); - brdshm->total[bid - 1] = num; + SHM->total[bid - 1] = num; if(num>0) { lseek(fd, (off_t) (num - 1) * sizeof(fileheader_t), SEEK_SET); if(read(fd, genbuf, FNLEN)>=0) { - brdshm->lastposttime[bid - 1]=(time_t) atoi(&genbuf[2]); + SHM->lastposttime[bid - 1]=(time_t) atoi(&genbuf[2]); } } else - brdshm->lastposttime[bid - 1] = 0; + SHM->lastposttime[bid - 1] = 0; close(fd); if(num) touchdircache(bid); } -void -touchbpostnum(int bid, int delta) { - int *total = &brdshm->total[bid - 1]; - if (*total) *total += delta; +void touchbpostnum(int bid, int delta) +{ + int *total = &SHM->total[bid - 1]; + if (*total) + *total += delta; } int getbnum(char *bname) { - register int i=0, j, start = 0, end = brdshm->number - 1; + register int i=0, j, start = 0, end = SHM->Bnumber - 1; register boardheader_t **bhdr; - bhdr=brdshm->sorted[0]; + bhdr=SHM->bsorted[0]; for(i=((start+end)/2); ;i=(start+end)/2) { if(! (j=strcasecmp(bname,bhdr[i]->brdname))) @@ -799,11 +798,9 @@ int haspostperm(char *bname) { /* PTT cache */ /*-------------------------------------------------------*/ /* cachefor 動態看版 */ -struct pttcache_t *ptt; - static void reload_pttcache() { - if(ptt->busystate) + if( SHM->Pbusystate ) safe_sleep(1); else { /* jochang: temporary workaround */ fileheader_t item, subitem; @@ -811,9 +808,9 @@ static void reload_pttcache() FILE *fp, *fp1, *fp2; int id, section = 0; - ptt->busystate = 1; - ptt->max_film = 0; - bzero(ptt->notes, sizeof ptt->notes); + SHM->Pbusystate = 1; + SHM->max_film = 0; + bzero(SHM->notes, sizeof(SHM->notes)); setapath(pbuf, "Note"); setadir(buf, pbuf); id = 0; @@ -824,15 +821,15 @@ static void reload_pttcache() setadir(buf, buf); if(!(fp1 = fopen(buf, "r"))) continue; - ptt->next_refresh[section] = ptt->n_notes[section] = id; + SHM->next_refresh[section] = SHM->n_notes[section] = id; section ++; while(fread(&subitem, sizeof(subitem), 1, fp1)) { sprintf(buf,"%s/%s/%s", pbuf, item.filename , subitem.filename); if(!(fp2=fopen(buf,"r"))) continue; - fread(ptt->notes[id],sizeof(char), 200*11, fp2); - ptt->notes[id][200*11 - 1]=0; + fread(SHM->notes[id],sizeof(char), 200*11, fp2); + SHM->notes[id][200*11 - 1]=0; id++; fclose(fp2); if(id >= MAX_MOVIE) @@ -845,50 +842,44 @@ static void reload_pttcache() } fclose(fp); } - ptt->next_refresh[section] = -1; - ptt->n_notes[section] = ptt->max_film = id-1; - ptt->max_history = ptt->max_film - 2; - if(ptt->max_history > MAX_HISTORY - 1) - ptt->max_history = MAX_HISTORY - 1; - if(ptt->max_history <0) ptt->max_history=0; + SHM->next_refresh[section] = -1; + SHM->n_notes[section] = SHM->max_film = id-1; + SHM->max_history = SHM->max_film - 2; + if(SHM->max_history > MAX_HISTORY - 1) + SHM->max_history = MAX_HISTORY - 1; + if(SHM->max_history <0) SHM->max_history=0; fp = fopen("etc/today_is","r"); if(fp) { - fgets(ptt->today_is,15,fp); - if((chr = strchr(ptt->today_is,'\n'))) + fgets(SHM->today_is,15,fp); + if((chr = strchr(SHM->today_is,'\n'))) *chr = 0; - ptt->today_is[15] = 0; + SHM->today_is[15] = 0; fclose(fp); } /* 等所有資料更新後再設定 uptime */ - ptt->uptime = ptt->touchtime ; + SHM->Puptime = SHM->Ptouchtime ; #if !defined(_BBS_UTIL_C_) log_usies("CACHE", "reload pttcache"); #endif - ptt->busystate = 0; + SHM->Pbusystate = 0; } } void resolve_garbage() { int count=0; - if(ptt == NULL) { - ptt = attach_shm(PTTSHM_KEY, sizeof(*ptt)); - GLOBALVAR = ptt->GLOBALVAR; - if(ptt->touchtime == 0) - ptt->touchtime = 1; - } - while(ptt->uptime < ptt->touchtime) { /* 不用while等 */ + while(SHM->Puptime < SHM->Ptouchtime) { /* 不用while等 */ reload_pttcache(); - if(count ++ > 10 && ptt->busystate) { + if(count ++ > 10 && SHM->Pbusystate) { /* Ptt: 這邊會有問題 load超過10 秒會所有進loop的process都讓 busystate = 0 這樣會所有prcosee都會在load 動態看板 會造成load大增 但沒有用這個function的話 萬一load passwd檔的process死了 又沒有人把他 解開 同樣的問題發生在reload passwd */ - ptt->busystate = 0; + SHM->Pbusystate = 0; #ifndef _BBS_UTIL_C_ log_usies("CACHE", "refork Ptt dead lock"); #endif @@ -901,52 +892,48 @@ void resolve_garbage() { /*-------------------------------------------------------*/ /* cachefor from host 與最多上線人數 */ static void reload_fcache() { - if(fcache->busystate) + if( SHM->Fbusystate ) safe_sleep(1); else { FILE *fp; - fcache->busystate = 1; - bzero(fcache->domain, sizeof fcache->domain); + SHM->Fbusystate = 1; + bzero(SHM->domain, sizeof(SHM->domain)); if((fp = fopen("etc/domain_name_query","r"))) { char buf[256],*po; - fcache->top=0; + SHM->top=0; while(fgets(buf, sizeof(buf),fp)) { if(buf[0] && buf[0] != '#' && buf[0] != ' ' && buf[0] != '\n') { - sscanf(buf,"%s",fcache->domain[fcache->top]); - po = buf + strlen(fcache->domain[fcache->top]); + sscanf(buf,"%s",SHM->domain[SHM->top]); + po = buf + strlen(SHM->domain[SHM->top]); while(*po == ' ') po++; - strncpy(fcache->replace[fcache->top],po,49); - fcache->replace[fcache->top] - [strlen(fcache->replace[fcache->top])-1] = 0; - (fcache->top)++; - if(fcache->top == MAX_FROM) + strncpy(SHM->replace[SHM->top],po,49); + SHM->replace[SHM->top] + [strlen(SHM->replace[SHM->top])-1] = 0; + (SHM->top)++; + if(SHM->top == MAX_FROM) break; } } } - fcache->max_user=0; + SHM->max_user=0; /* 等所有資料更新後再設定 uptime */ - fcache->uptime = fcache->touchtime; + SHM->Fuptime = SHM->Ftouchtime; #if !defined(_BBS_UTIL_C_) log_usies("CACHE", "reload fcache"); #endif - fcache->busystate = 0; + SHM->Fbusystate = 0; } } -void resolve_fcache() { - if(fcache == NULL) { - fcache = attach_shm(FROMSHM_KEY, sizeof(*fcache)); - if(fcache->touchtime == 0) - fcache->touchtime = 1; - } - while(fcache->uptime < fcache->touchtime) +void resolve_fcache() +{ + while( SHM->Fuptime < SHM->Ftouchtime ) reload_fcache(); } @@ -977,17 +964,17 @@ void hbflreload(int bid) fclose(fp); } hbfl[0] = now; - memcpy(brdshm->hbfl[bid], hbfl, sizeof(hbfl)); + memcpy(SHM->hbfl[bid], hbfl, sizeof(hbfl)); } int hbflcheck(int bid, int uid) { int i; - if( brdshm->hbfl[bid][0] < login_start_time - HBFLexpire ) + if( SHM->hbfl[bid][0] < login_start_time - HBFLexpire ) hbflreload(bid); - for( i = 1 ; brdshm->hbfl[bid][i] != 0 && i <= MAX_FRIEND ; ++i ){ - if( brdshm->hbfl[bid][i] == uid ) + for( i = 1 ; SHM->hbfl[bid][i] != 0 && i <= MAX_FRIEND ; ++i ){ + if( SHM->hbfl[bid][i] == uid ) return 0; } return 1; diff --git a/pttbbs/mbbsd/cal.c b/pttbbs/mbbsd/cal.c index 3b41d279..dbb90c71 100644 --- a/pttbbs/mbbsd/cal.c +++ b/pttbbs/mbbsd/cal.c @@ -1,4 +1,4 @@ -/* $Id: cal.c,v 1.13 2002/06/04 13:08:33 in2 Exp $ */ +/* $Id: cal.c,v 1.14 2002/06/06 21:34:11 in2 Exp $ */ #include "bbs.h" /* 防堵 Multi play */ @@ -7,7 +7,7 @@ static int count_multiplay(int unmode) { register userinfo_t *uentp; for(i = j = 0; i < USHM_SIZE; i++) { - uentp = &(utmpshm->uinfo[i]); + uentp = &(SHM->uinfo[i]); if(uentp->uid == usernum) if(uentp->lockmode == unmode) j++; diff --git a/pttbbs/mbbsd/chicken.c b/pttbbs/mbbsd/chicken.c index 9c30deec..0b1c9320 100644 --- a/pttbbs/mbbsd/chicken.c +++ b/pttbbs/mbbsd/chicken.c @@ -1,4 +1,4 @@ -/* $Id: chicken.c,v 1.4 2002/06/04 13:08:33 in2 Exp $ */ +/* $Id: chicken.c,v 1.5 2002/06/06 21:34:11 in2 Exp $ */ #include "bbs.h" #define NUM_KINDS 13 /* 有多少種動物 */ @@ -828,7 +828,7 @@ int chickenpk(int fd) { char mateid[IDLEN + 1], data[200], buf[200]; int ch = 0; - userinfo_t *uin = &utmpshm->uinfo[currutmp->destuip]; + userinfo_t *uin = &SHM->uinfo[currutmp->destuip]; userec_t ouser; chicken_t *ochicken = &ouser.mychicken; int r, attmax, i, datac, duid = currutmp->destuid, catched=0, count=0; diff --git a/pttbbs/mbbsd/kaede.c b/pttbbs/mbbsd/kaede.c index d9c33589..a3005ad3 100644 --- a/pttbbs/mbbsd/kaede.c +++ b/pttbbs/mbbsd/kaede.c @@ -1,4 +1,4 @@ -/* $Id: kaede.c,v 1.3 2002/06/04 13:08:33 in2 Exp $ */ +/* $Id: kaede.c,v 1.4 2002/06/06 21:34:11 in2 Exp $ */ #include "bbs.h" char *Ptt_prints(char *str, int mode) { @@ -20,7 +20,7 @@ char *Ptt_prints(char *str, int mode) { while((po = strstr(str, "\033*u"))) { int attempts; - attempts = utmpshm->number; + attempts = SHM->UTMPnumber; po[0] = 0; sprintf(strbuf, "%s%d%s", str, attempts, po + 3); strcpy(str, strbuf); diff --git a/pttbbs/mbbsd/mail.c b/pttbbs/mbbsd/mail.c index 14325216..8610e5c5 100644 --- a/pttbbs/mbbsd/mail.c +++ b/pttbbs/mbbsd/mail.c @@ -1,4 +1,4 @@ -/* $Id: mail.c,v 1.11 2002/06/04 13:08:33 in2 Exp $ */ +/* $Id: mail.c,v 1.12 2002/06/06 21:34:11 in2 Exp $ */ #include "bbs.h" char currmaildir[32]; static char msg_cc[] = "\033[32m[群組名單]\033[m\n"; @@ -578,11 +578,11 @@ int mail_all() { if(append_record(genbuf, &mymail, sizeof(mymail)) == -1) outs(err_uid); - for(unum = uhash->number, i = 0; i < unum; i++) { - if(bad_user_id(uhash->userid[i])) + for(unum = SHM->number, i = 0; i < unum; i++) { + if(bad_user_id(SHM->userid[i])) continue; /* Ptt */ - userid = uhash->userid[i]; + userid = SHM->userid[i]; if(strcmp(userid,STR_GUEST) && strcmp(userid, "new") && strcmp(userid, cuser.userid)) { sethomepath(genbuf, userid); @@ -1057,7 +1057,7 @@ static int mail_cross_post(int ent, fileheader_t *fhdr, char *direct) { clrtoeol(); move(1, 0); generalnamecomplete("轉錄本文章於看板:", xboard, sizeof(xboard), - brdshm->number, + SHM->Bnumber, completeboard_compar, completeboard_permission, completeboard_getname); @@ -1175,7 +1175,7 @@ static int mail_cite(int ent, fileheader_t *fhdr, char *direct) { generalnamecomplete("輸入看版名稱 (直接Enter進入私人信件夾):", buf, sizeof(buf), - brdshm->number, + SHM->Bnumber, completeboard_compar, completeboard_permission, completeboard_getname); diff --git a/pttbbs/mbbsd/mbbsd.c b/pttbbs/mbbsd/mbbsd.c index a933b6f3..64ab1557 100644 --- a/pttbbs/mbbsd/mbbsd.c +++ b/pttbbs/mbbsd/mbbsd.c @@ -1,4 +1,4 @@ -/* $Id: mbbsd.c,v 1.33 2002/06/05 02:42:29 ptt Exp $ */ +/* $Id: mbbsd.c,v 1.34 2002/06/06 21:34:11 in2 Exp $ */ #include "bbs.h" #define SOCKET_QLEN 4 @@ -250,7 +250,7 @@ talk_request(int sig) time_t now = time (0); sprintf (buf, "\033[33;41m★%s\033[34;47m [%s] %s \033[0m", - utmpshm->uinfo[currutmp->destuip].userid, my_ctime (&now), + SHM->uinfo[currutmp->destuip].userid, my_ctime (&now), (currutmp->sig == 2)? "重要消息廣播!(請Ctrl-U,l查看熱訊記錄)" : "呼叫、呼叫,聽到請回答"); move (0, 0); @@ -516,11 +516,10 @@ login_query () char uid[IDLEN + 1], passbuf[PASSLEN]; int attempts; char genbuf[200]; - resolve_utmp (); + attach_SHM(); resolve_garbage (); - attach_uhash (); now= time(0); - attempts = utmpshm->number; + attempts = SHM->UTMPnumber; #ifdef DEBUG move(1, 0); prints("debugging mode\ncurrent pid: %d\n", getpid()); @@ -685,8 +684,8 @@ where (char *from) { register int i = 0, count = 0, j; - for (j = 0; j < fcache->top; j++){ - char *token = strtok (fcache->domain[j], "&"); + for (j = 0; j < SHM->top; j++){ + char *token = strtok (SHM->domain[j], "&"); i = 0; count = 0; @@ -790,9 +789,9 @@ user_login () time (&now); ptime = localtime (&now); tmp = localtime (&cuser.lastlogin); - if ((a = utmpshm->number) > fcache->max_user){ - fcache->max_user = a; - fcache->max_time = now; + if ((a = SHM->UTMPnumber) > SHM->max_user){ + SHM->max_user = a; + SHM->max_time = now; } init_brdbuf(); brc_initial (DEFAULT_BOARD); diff --git a/pttbbs/mbbsd/menu.c b/pttbbs/mbbsd/menu.c index cbdb0871..61bf8bda 100644 --- a/pttbbs/mbbsd/menu.c +++ b/pttbbs/mbbsd/menu.c @@ -1,4 +1,4 @@ -/* $Id: menu.c,v 1.9 2002/06/04 13:08:33 in2 Exp $ */ +/* $Id: menu.c,v 1.10 2002/06/06 21:34:11 in2 Exp $ */ #include "bbs.h" /* help & menu processring */ @@ -97,7 +97,6 @@ static int u_movie() { } void movie(int i) { - extern struct pttcache_t *ptt; static short history[MAX_HISTORY]; static char myweek[] = "天一二三四五六"; const char *msgs[] = {"關閉", "打開", "拔掉", "防水","好友"}; @@ -105,17 +104,17 @@ void movie(int i) { int j; if((currstat != CLASS) && (cuser.uflag & MOVIE_FLAG) && - !ptt->busystate && ptt->max_film > 0) { + !SHM->Pbusystate && SHM->max_film > 0) { if(currstat == PSALE) { i = PSALE; reload_money(); } else { do { if(!i) - i = 1 + (int)(((float)ptt->max_film * + i = 1 + (int)(((float)SHM->max_film * rand()) / (RAND_MAX + 1.0)); - for(j = ptt->max_history; j >= 0; j--) + for(j = SHM->max_history; j >= 0; j--) if(i == history[j]) { i = 0; break; @@ -123,15 +122,15 @@ void movie(int i) { } while(i == 0); } - memcpy(history, &history[1], ptt->max_history * sizeof(short)); - history[ptt->max_history] = j = i; + memcpy(history, &history[1], SHM->max_history * sizeof(short)); + history[SHM->max_history] = j = i; if(i == 999) /* Goodbye my friend */ i = 0; move(1, 0); clrtoline(1 + FILMROW); /* 清掉上次的 */ - Jaky_outs(ptt->notes[i], 11); /* 只印11行就好 */ + Jaky_outs(SHM->notes[i], 11); /* 只印11行就好 */ outs(reset_color); } i = ptime->tm_wday << 1; @@ -140,8 +139,8 @@ void movie(int i) { "\033[30m[扣機]\033[31m%s\033[0m", ptime->tm_mon + 1, ptime->tm_mday, myweek[i], myweek[i + 1], ptime->tm_hour, ptime->tm_min, currutmp->birth ? - "生日要請客唷" : ptt->today_is, - utmpshm->number, cuser.userid, msgs[currutmp->pager]); + "生日要請客唷" : SHM->today_is, + SHM->UTMPnumber, cuser.userid, msgs[currutmp->pager]); outmsg(mystatus); refresh(); } diff --git a/pttbbs/mbbsd/name.c b/pttbbs/mbbsd/name.c index b78b54d1..f2a0f704 100644 --- a/pttbbs/mbbsd/name.c +++ b/pttbbs/mbbsd/name.c @@ -1,4 +1,4 @@ -/* $Id: name.c,v 1.7 2002/06/04 13:08:34 in2 Exp $ */ +/* $Id: name.c,v 1.8 2002/06/06 21:34:11 in2 Exp $ */ #include "bbs.h" static word_t *current = NULL; @@ -637,34 +637,34 @@ int generalnamecomplete(char *prompt, char *data, int len, size_t nmemb, /* general complete functions (brdshm) */ int completeboard_compar(int where, char *str, int len) { - return strncasecmp(brdshm->sorted[0][where]->brdname, str, len); + return strncasecmp(SHM->bsorted[0][where]->brdname, str, len); } int completeboard_permission(int where) { - return Ben_Perm(brdshm->sorted[0][where]); + return Ben_Perm(SHM->bsorted[0][where]); } char *completeboard_getname(int where) { - return brdshm->sorted[0][where]->brdname; + return SHM->bsorted[0][where]->brdname; } /* general complete functions (utmpshm) */ int completeutmp_compar(int where, char *str, int len) { - return strncasecmp(utmpshm->sorted[utmpshm->currsorted][0][where]->userid, + return strncasecmp(SHM->sorted[SHM->currsorted][0][where]->userid, str, len); } int completeutmp_permission(int where) { return (HAS_PERM(PERM_SYSOP) || HAS_PERM(PERM_SEECLOAK) || - !utmpshm->sorted[utmpshm->currsorted][0][where]->invisible); + !SHM->sorted[SHM->currsorted][0][where]->invisible); } char *completeutmp_getname(int where) { - return utmpshm->sorted[utmpshm->currsorted][0][where]->userid; + return SHM->sorted[SHM->currsorted][0][where]->userid; } diff --git a/pttbbs/mbbsd/talk.c b/pttbbs/mbbsd/talk.c index e1feac1f..90b39eab 100644 --- a/pttbbs/mbbsd/talk.c +++ b/pttbbs/mbbsd/talk.c @@ -1,4 +1,4 @@ -/* $Id: talk.c,v 1.68 2002/06/05 03:22:43 ptt Exp $ */ +/* $Id: talk.c,v 1.69 2002/06/06 21:34:11 in2 Exp $ */ #include "bbs.h" #define QCAST int (*)(const void *, const void *) @@ -215,13 +215,13 @@ int login_friend_online(void) { userinfo_t *uentp; int i, stat, stat1; - int offset=(int) (currutmp - &utmpshm->uinfo[0]); - for (i=0;i<utmpshm->number && currutmp->friendtotal<MAX_FRIEND; i++){ - uentp = (utmpshm->sorted[utmpshm->currsorted][0][i]); + int offset=(int) (currutmp - &SHM->uinfo[0]); + for (i=0;i<SHM->UTMPnumber && currutmp->friendtotal<MAX_FRIEND; i++){ + uentp = (SHM->sorted[SHM->currsorted][0][i]); if(uentp && uentp->uid && (stat=set_friend_bit(currutmp,uentp))){ stat1=reverse_friend_stat(stat); stat <<= 24; - stat |= (int) (uentp - &utmpshm->uinfo[0]); + stat |= (int) (uentp - &SHM->uinfo[0]); currutmp->friend_online[currutmp->friendtotal++]=stat; if(uentp!=currutmp && uentp->friendtotal<MAX_FRIEND){ stat1 <<= 24; @@ -236,13 +236,13 @@ int login_friend_online(void) int logout_friend_online(userinfo_t *utmp) { int i, j, k; - int offset=(int) (utmp - &utmpshm->uinfo[0]); + int offset=(int) (utmp - &SHM->uinfo[0]); userinfo_t *ui; while( utmp->friendtotal > 0 ){ i = utmp->friendtotal-1; j = (utmp->friend_online[i] & 0xFFFFFF); utmp->friend_online[i]=0; - ui = &utmpshm->uinfo[j]; + ui = &SHM->uinfo[j]; if(ui->pid && ui!=utmp){ for(k=0; k<ui->friendtotal > 0 && k < MAX_FRIEND && (int)(ui->friend_online[k] & 0xFFFFFF) !=offset; k++); @@ -268,7 +268,7 @@ int friend_stat(userinfo_t *me, userinfo_t * ui) } for(i=0;me->friend_online[i] && i < MAX_FRIEND;i++){ j = (me->friend_online[i] & 0xFFFFFF); - if( 0 <= j && j < MAX_ACTIVE && ui == &utmpshm->uinfo[j] ){ + if( 0 <= j && j < MAX_ACTIVE && ui == &SHM->uinfo[j] ){ hit |= me->friend_online[i] >>24; break; } @@ -634,7 +634,7 @@ int my_write(pid_t pid, char *prompt, char *id, int flag, userinfo_t *puin) if(flag == 3 && uin->msgcount) { /* 不懂 */ - uin->destuip = currutmp - &utmpshm->uinfo[0]; + uin->destuip = currutmp - &SHM->uinfo[0]; uin->sig = 2; if(uin->pid > 0) kill(uin->pid, SIGUSR1); } else if(flag != 2 && @@ -1185,7 +1185,7 @@ static void my_talk(userinfo_t * uin, int fri_stat) { currutmp->sockaddr = server.sin_port; currutmp->destuid = uin->uid; setutmpmode(PAGE); - uin->destuip = currutmp - &utmpshm->uinfo[0]; + uin->destuip = currutmp - &SHM->uinfo[0]; if(pid > 0) kill(pid, SIGUSR1); clear(); prints("正呼叫 %s.....\n鍵入 Ctrl-D 中止....", uin->userid); @@ -1197,7 +1197,7 @@ static void my_talk(userinfo_t * uin, int fri_stat) { if (ch == I_TIMEOUT){ ch = uin->mode; if (!ch && uin->chatid[0] == 1 && - uin->destuip == currutmp - &utmpshm->uinfo[0]){ + uin->destuip == currutmp - &SHM->uinfo[0]){ bell(); outmsg("對方回應中..."); refresh(); @@ -1223,7 +1223,7 @@ static void my_talk(userinfo_t * uin, int fri_stat) { outs("再"); bell(); - uin->destuip = currutmp - &utmpshm->uinfo[0]; + uin->destuip = currutmp - &SHM->uinfo[0]; if(pid <= 0 || kill(pid, SIGUSR1) == -1){ #ifdef linux add_io(sock, 20); /* added 4 linux... achen */ @@ -1421,8 +1421,7 @@ static char *friend_descript(char *uident) { return space_buf; } -static char *descript(int show_mode, userinfo_t * uentp, time_t diff, - fromcache_t * fcache) +static char *descript(int show_mode, userinfo_t * uentp, time_t diff) { switch (show_mode){ case 1: @@ -1431,7 +1430,7 @@ static char *descript(int show_mode, userinfo_t * uentp, time_t diff, return (((uentp->pager != 2 && uentp->pager != 3 && diff) || HAS_PERM(PERM_SYSOP)) ? #ifdef WHERE - uentp->from_alias ? fcache->replace[uentp->from_alias] : + uentp->from_alias ? SHM->replace[uentp->from_alias] : uentp->from #else uentp->from @@ -1467,7 +1466,7 @@ int pickup_maxpages(int pickupway, int nfriends) if( cuser.uflag & FRIEND_FLAG ) number = nfriends; else - number = utmpshm->number+ + number = SHM->UTMPnumber+ (pickupway == 0 ? nfriends : 0); return (number-1) / MAXPICKUP +1; } @@ -1482,7 +1481,7 @@ static int pickup_myfriend(pickup_t *friends, for( i = 0 ; currutmp->friend_online[i] && i < MAX_FRIEND ; ++i ){ where = currutmp->friend_online[i] & 0xFFFFFF; if( 0 <= where && where < MAX_ACTIVE && - (uentp = &utmpshm->uinfo[where]) && uentp->pid && + (uentp = &SHM->uinfo[where]) && uentp->pid && uentp != currutmp && isvisible_stat(currutmp, uentp, frstate = @@ -1524,8 +1523,8 @@ static void pickup(pickup_t *currpickup, int pickup_way, int *page, int *nfriend, int *myfriend, int *friendme, int *bfriend) { /* avoid race condition */ - int currsorted = utmpshm->currsorted; - int utmpnumber = utmpshm->number; + int currsorted = SHM->currsorted; + int utmpnumber = SHM->UTMPnumber; int friendtotal= currutmp->friendtotal; userinfo_t **utmp; @@ -1564,7 +1563,7 @@ static void pickup(pickup_t *currpickup, int pickup_way, int *page, if( !(cuser.uflag & FRIEND_FLAG) && size < MAXPICKUP ) { sorted_way = ((pickup_way == 0) ? 0 : (pickup_way - 1)); - utmp = utmpshm->sorted[currsorted][sorted_way]; + utmp = SHM->sorted[currsorted][sorted_way]; which = *page * MAXPICKUP-*nfriend; if(which<0) which=0; for(;which < utmpnumber && size < MAXPICKUP;which++) @@ -1648,7 +1647,7 @@ static void draw_pickup(int drawall, pickup_t *pickup, int pickup_way, prints(" 排序:[%s] 上站人數:%-4d\033[1;32m我的朋友:%-3d" "\033[33m與我為友:%-3d\033[36m板友:%-4d\033[31m壞人:" "%-2d\033[m\n", - msg_pickup_way[pickup_way], utmpshm->number, + msg_pickup_way[pickup_way], SHM->UTMPnumber, myfriend, friendme, currutmp->brc_id ? (bfriend + 1) : 0, 0); for( i = 0, ch = page * 20 + 1 ; i < MAXPICKUP ; ++i, ++ch ){ @@ -1715,7 +1714,7 @@ static void draw_pickup(int drawall, pickup_t *pickup, int pickup_way, /* from */ descript(show_mode, uentp, - uentp->pager & !(friend&HRM), fcache), + uentp->pager & !(friend&HRM)), /* board or mode */ #ifdef SHOWBOARD @@ -1944,15 +1943,15 @@ static void userlist(void) char swid[IDLEN + 1]; move(1, 0); si = generalnamecomplete(msg_uid, swid, - sizeof(swid), utmpshm->number, + sizeof(swid), SHM->UTMPnumber, completeutmp_compar, completeutmp_permission, completeutmp_getname); if( si >= 0 ){ pickup_t friends[MAX_FRIEND + 1]; int nGots, i; - fi = utmpshm->sorted[utmpshm->currsorted][0][si] - - &utmpshm->uinfo[0]; + fi = SHM->sorted[SHM->currsorted][0][si] - + &SHM->uinfo[0]; nGots= pickup_myfriend(friends, &myfriend, &friendme); for( i = 0 ; i < nGots ; ++i ) @@ -1987,7 +1986,7 @@ static void userlist(void) case '9': { /* Thor: 可以打數字跳到該人 */ int tmp; - if( (tmp = search_num(ch, utmpshm->number)) >= 0 ){ + if( (tmp = search_num(ch, SHM->UTMPnumber)) >= 0 ){ if( tmp / 20 == page ){ /* in2:目的在目前這一頁, 直接 更新 offset , 不用重畫畫面 */ @@ -2046,8 +2045,8 @@ static void userlist(void) *ans == 'n') break; if( HAS_PERM(PERM_SYSOP) ){ - for( i = 0 ; i < utmpshm->number && i<1000 ; ++i ){ - uentp = utmpshm->sorted[utmpshm->currsorted][0][i]; + for( i = 0 ; i < SHM->UTMPnumber && i<1000 ; ++i ){ + uentp = SHM->sorted[SHM->currsorted][0][i]; if( uentp->pid && kill(uentp->pid, 0) != -1 ) my_write(uentp->pid, genbuf, uentp->userid, 1, NULL); @@ -2060,7 +2059,7 @@ static void userlist(void) i < MAX_FRIEND ; ++i ){ where = currutmp->friend_online[i] & 0xFFFFFF; if( 0 <= where && where < MAX_ACTIVE && - (uentp = &utmpshm->uinfo[where]) && + (uentp = &SHM->uinfo[where]) && uentp->pid && isvisible_stat(currutmp, uentp, frstate = @@ -2376,7 +2375,7 @@ int t_talk() { */ stand_title("打開話匣子"); generalnamecomplete(msg_uid, uident, sizeof(uident), - utmpshm->number, + SHM->UTMPnumber, completeutmp_compar, completeutmp_permission, completeutmp_getname); @@ -2422,7 +2421,7 @@ void talkreply(void) int a, sig = currutmp->sig; talkrequest = NA; - uip = &utmpshm->uinfo[currutmp->destuip]; + uip = &SHM->uinfo[currutmp->destuip]; sprintf(page_requestor, "%s (%s)", uip->userid, uip->username); currutmp->destuid = uip->uid; currstat = XMODE; /* 避免出現動畫 */ @@ -2484,7 +2483,7 @@ void talkreply(void) strcpy(genbuf, "不告訴你咧 !! ^o^"); write(a, genbuf, 60); } - uip->destuip = currutmp - &utmpshm->uinfo[0]; + uip->destuip = currutmp - &SHM->uinfo[0]; if (buf[0] == 'y') switch (sig){ case SIG_DARK: diff --git a/pttbbs/mbbsd/user.c b/pttbbs/mbbsd/user.c index 54a3a515..c7a5e455 100644 --- a/pttbbs/mbbsd/user.c +++ b/pttbbs/mbbsd/user.c @@ -1,4 +1,4 @@ -/* $Id: user.c,v 1.21 2002/06/04 13:08:34 in2 Exp $ */ +/* $Id: user.c,v 1.22 2002/06/06 21:34:11 in2 Exp $ */ #include "bbs.h" static char *sex[8] = { @@ -1107,7 +1107,7 @@ int u_list() { setutmpmode(LAUSERS); showrealname = u_list_special = usercounter = 0; - totalusers = uhash->number; + totalusers = SHM->number; if(HAS_PERM(PERM_SEEULEVELS)) { getdata(b_lines - 1, 0, "觀看 [1]特殊等級 (2)全部?", genbuf, 3, DOECHO); diff --git a/pttbbs/mbbsd/var.c b/pttbbs/mbbsd/var.c index 43dab291..123f7245 100644 --- a/pttbbs/mbbsd/var.c +++ b/pttbbs/mbbsd/var.c @@ -1,4 +1,4 @@ -/* $Id: var.c,v 1.6 2002/06/04 13:08:34 in2 Exp $ */ +/* $Id: var.c,v 1.7 2002/06/06 21:34:11 in2 Exp $ */ #define INCLUDE_VAR_H #include "bbs.h" @@ -307,12 +307,9 @@ int wmofo = -1; /* cache.c */ int numboards = -1; int *GLOBALVAR; -uhash_t *uhash; -bcache_t *brdshm; -userinfo_t *currutmp; +SHM_t *SHM; boardheader_t *bcache; -struct utmpfile_t *utmpshm; -struct fromcache_t *fcache; +userinfo_t *currutmp; /* board.c */ int class_bid = 0; diff --git a/pttbbs/util/BM_money.c b/pttbbs/util/BM_money.c index a20dc5e3..0c1b029f 100644 --- a/pttbbs/util/BM_money.c +++ b/pttbbs/util/BM_money.c @@ -1,17 +1,8 @@ -/* $Id: BM_money.c,v 1.3 2002/05/25 11:17:55 ptt Exp $ */ +/* $Id: BM_money.c,v 1.4 2002/06/06 21:34:14 in2 Exp $ */ /* 給版主錢的程式 */ -#include <stdio.h> -#include <string.h> -#include <unistd.h> -#include <stdlib.h> -#include <sys/types.h> -#include "config.h" -#include "pttstruct.h" -#include "util.h" -#include "common.h" -#include "proto.h" +#include "bbs.h" #define FUNCTION (2100 - c*5) diff --git a/pttbbs/util/Makefile b/pttbbs/util/Makefile index c0616b7b..0fc23f70 100644 --- a/pttbbs/util/Makefile +++ b/pttbbs/util/Makefile @@ -1,4 +1,4 @@ -# $Id: Makefile,v 1.11 2002/04/15 20:07:08 in2 Exp $ +# $Id: Makefile,v 1.12 2002/06/06 21:35:23 in2 Exp $ BBSHOME?=$(HOME) OSTYPE?=linux @@ -23,14 +23,14 @@ LDFLAGS=$(LDFLAGS_$(OSTYPE)) LIBMAIL=$(LIBMAIL_$(OSTYPE)) LIBCHAT=$(LIBCHAT_$(OSTYPE)) -OBJS= util_cache.o util_record.o util_passwd.o +OBJS= util_cache.o util_record.o util_passwd.o CPROGS= bbsmail BM_money post account birth deluserfile expire mandex\ horoscope openvice parse_news openticket topusr yearsold uhash_loader\ poststat showboard antispam countalldice webgrep bbsrf\ initbbs outmail xchatd userlist tunepasswd buildir reaper shmsweep\ merge_passwd merge_board inndBM buildAnnounce rmuid \ - toplazyBM jungo toplazyBBM shmctl mdclean + toplazyBM jungo toplazyBBM shmctl mdclean splitpasswd PROGS= $(CPROGS) BM_money.sh backpasswd.sh mailog.sh opendice.sh\ openticket.sh stock.sh topsong.sh weather.sh stock.perl weather.perl\ @@ -48,6 +48,9 @@ BM_money: BM_money.c $(OBJS) post: post.c $(OBJS) $(CC) $(CFLAGS) -o $@ $@.c $(OBJS) +poststat: poststat.c $(OBJS) + $(CC) $(CFLAGS) -o $@ $@.c $(OBJS) + jungo: jungo.c $(OBJS) $(CC) $(CFLAGS) -o $@ $@.c $(OBJS) @@ -159,6 +162,9 @@ shmctl: shmctl.c $(OBJS) mdclean: mdclean.c $(CC) $(CFLAGS) -o $@ $@.c +splitpasswd: splitpasswd.c + $(CC) $(CFLAGS) -o $@ $@.c + install: $(PROGS) install -d $(BBSHOME)/bin/ install -c -m 755 $(PROGS) $(BBSHOME)/bin/ diff --git a/pttbbs/util/account.c b/pttbbs/util/account.c index 9d8f6a05..cfc9f911 100644 --- a/pttbbs/util/account.c +++ b/pttbbs/util/account.c @@ -1,43 +1,31 @@ -/* $Id: account.c,v 1.4 2002/03/28 04:03:55 in2 Exp $ */ -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <time.h> -#include <sys/types.h> -#include <sys/stat.h> -#include <unistd.h> -#include "config.h" -#include "pttstruct.h" -#include "util.h" -#include "proto.h" +/* $Id: account.c,v 1.5 2002/06/06 21:34:14 in2 Exp $ */ +#include "bbs.h" #define MAX_LINE 16 #define ADJUST_M 6 /* adjust back 5 minutes */ -extern struct pttcache_t *ptt; - void - reset_garbage() +reset_garbage() { - if (ptt == NULL) + if (SHM == NULL) { - ptt = attach_shm(PTTSHM_KEY, sizeof(*ptt)); - if (ptt->touchtime == 0) - ptt->touchtime = 1; + attach_SHM(); + if (SHM->Ptouchtime == 0) + SHM->Ptouchtime = 1; } /* 不整個reload? - for(n=0;n<=ptt->max_film;n++) - printf("\n**%d**\n %s \n",n,ptt->notes[n]); + for(n=0;n<=SHM->max_film;n++) + printf("\n**%d**\n %s \n",n,SHM->notes[n]); */ - ptt->uptime = 0; + SHM->Puptime = 0; reload_pttcache(); - printf("\n動態看板數[%d]\n", ptt->max_film); + printf("\n動態看板數[%d]\n", SHM->max_film); /* for(n=0; n<MAX_MOVIE_SECTION; n++) - printf("sec%d=> 起點:%d 下次要換的:%d\n ",n,ptt->n_notes[n], - ptt->next_refresh[n]); + printf("sec%d=> 起點:%d 下次要換的:%d\n ",n,SHM->n_notes[n], + SHM->next_refresh[n]); printf("\n"); */ } @@ -230,11 +218,11 @@ int main() { { int a; resolve_fcache(); - printf("此時段最多同時上線:%d 過去:%d\n", a = fcache->max_user, k); + printf("此時段最多同時上線:%d 過去:%d\n", a = SHM->max_user, k); fclose(fp); if (a > k) { - ptime = localtime(&fcache->max_time); + ptime = localtime(&SHM->max_time); if((fp1 = fopen("etc/history", "a"))) { fprintf(fp1, @@ -292,7 +280,7 @@ int main() { now = time(NULL) - ADJUST_M * 60; /* back to ancent */ ptime = localtime(&now); - attach_uhash(); + attach_SHM(); if((fp = fopen("etc/history.data", "r"))) { /* 單日最多次人次,同時上線,註冊 */ if (fscanf(fp, "%d %d %d %d", &max_login, &max, &max_reg, &k)) @@ -314,12 +302,12 @@ int main() { max_login = total; } - if (uhash->number > max_reg + max_reg / 10) + if (SHM->number > max_reg + max_reg / 10) { fprintf(fp1, "★ 【%02d/%02d/%02d】 " "總註冊人數提升到 %d 人 \n" - ,ptime->tm_mon + 1, ptime->tm_mday, ptime->tm_year % 100, uhash->number); - max_reg = uhash->number; + ,ptime->tm_mon + 1, ptime->tm_mday, ptime->tm_year % 100, SHM->number); + max_reg = SHM->number; } fclose(fp1); @@ -410,7 +398,7 @@ int main() { /* Ptt reset Ptt's share memory */ printf("重設Pttcache 與fcache\n"); - fcache->uptime = 0; + SHM->Puptime = 0; resolve_fcache(); reset_garbage(); return 0; diff --git a/pttbbs/util/bbsmail.c b/pttbbs/util/bbsmail.c index 0afcdf7e..634b2991 100644 --- a/pttbbs/util/bbsmail.c +++ b/pttbbs/util/bbsmail.c @@ -1,19 +1,7 @@ -/* $Id: bbsmail.c,v 1.2 2002/03/09 17:44:30 in2 Exp $ */ +/* $Id: bbsmail.c,v 1.3 2002/06/06 21:34:14 in2 Exp $ */ #define _BBS_UTIL_C_ -#include <stdio.h> -#include <string.h> -#include <ctype.h> -#include <time.h> -#include <sys/types.h> -#include <sys/stat.h> -#include <unistd.h> -#include "config.h" -#include "pttstruct.h" -#include "util.h" -#include "perm.h" -#include "common.h" -#include "proto.h" +#include "bbs.h" #define LOG_FILE (BBSHOME "/etc/mailog") diff --git a/pttbbs/util/birth.c b/pttbbs/util/birth.c index 89033830..5c13c54f 100644 --- a/pttbbs/util/birth.c +++ b/pttbbs/util/birth.c @@ -1,21 +1,12 @@ /* 壽星程式 96 10/11 */ -#include <stdio.h> -#include <sys/types.h> -#include <ctype.h> -#include <unistd.h> -#include <stdlib.h> -#include <time.h> -#include "config.h" -#include "pttstruct.h" -#include "util.h" -#include "common.h" +#include "bbs.h" #define OUTFILE BBSHOME "/etc/birth.today" struct userec_t cuser; -int bad_user_id() { +int bad_user_id(char *userid) { register char ch; int j; if (strlen(cuser.userid) < 2 || !isalpha(cuser.userid[0])) @@ -68,7 +59,7 @@ int main(argc, argv) fprintf(fp1, "【本日壽星】 \n"); for(j = 1; j <= MAX_USERS; j++) { passwd_query(j, &cuser); - if (bad_user_id()) + if (bad_user_id(NULL)) continue; if (cuser.month == ptime->tm_mon + 1) { diff --git a/pttbbs/util/buildAnnounce.c b/pttbbs/util/buildAnnounce.c index cd4b9877..1db151f9 100644 --- a/pttbbs/util/buildAnnounce.c +++ b/pttbbs/util/buildAnnounce.c @@ -1,26 +1,18 @@ /* 建立所有看板精華區的連結 */ -#include <stdio.h> -#include <stdlib.h> -#include <unistd.h> -#include <string.h> -#include <sys/types.h> -#include <sys/ipc.h> -#include <sys/shm.h> -#include <sys/stat.h> -#include "config.h" -#include "pttstruct.h" -#include "proto.h" +#include "bbs.h" #define GROUPROOT BBSHOME"/man/group" -extern bcache_t *brdshm; extern boardheader_t *bcache; extern void resolve_boards(); extern int numboards; -int cmpboardclass(boardheader_t **brd, boardheader_t **tmp) { - return (strncmp((*brd)->title, (*tmp)->title, 4)<<8)+ - strcasecmp((*brd)->brdname, (*tmp)->brdname); +int cmpboardclass(const void *a, const void *b) +{ + boardheader_t **brd = (boardheader_t **)a; + boardheader_t **tmp = (boardheader_t **)b; + return (strncmp((*brd)->title, (*tmp)->title, 4)<<8)+ + strcasecmp((*brd)->brdname, (*tmp)->brdname); } void buildchilds(int level,char *path,int gid) { @@ -31,7 +23,7 @@ void buildchilds(int level,char *path,int gid) for(i=0; i<numboards; i++) { - ptr =&brdshm->bcache[i]; + ptr =&SHM->bcache[i]; if( ptr->gid != gid || (ptr->brdattr&(BRD_BAD | BRD_HIDE))!=0 @@ -41,7 +33,7 @@ void buildchilds(int level,char *path,int gid) selected[count++]=ptr; } qsort(&selected, count, sizeof(boardheader_t *), - cmpboardclass); + cmpboardclass); for(i=0;i<count;i++) { ptr=selected[i]; diff --git a/pttbbs/util/deluserfile.c b/pttbbs/util/deluserfile.c index 3cf226bb..543048d0 100644 --- a/pttbbs/util/deluserfile.c +++ b/pttbbs/util/deluserfile.c @@ -1,16 +1,7 @@ -/* $Id: deluserfile.c,v 1.2 2002/05/25 11:17:55 ptt Exp $ */ +/* $Id: deluserfile.c,v 1.3 2002/06/06 21:34:14 in2 Exp $ */ /* 自動砍user目錄檔案程式 */ -#include <stdio.h> -#include <string.h> -#include <ctype.h> -#include <dirent.h> -#include <unistd.h> -#include <stdlib.h> -#include <sys/types.h> -#include "config.h" -#include "pttstruct.h" -#include "util.h" +#include "bbs.h" #define HOLDWRITELOG #define DELZEROFILE diff --git a/pttbbs/util/expire.c b/pttbbs/util/expire.c index c74ac6bf..dc75a03a 100644 --- a/pttbbs/util/expire.c +++ b/pttbbs/util/expire.c @@ -1,21 +1,7 @@ -/* $Id: expire.c,v 1.3 2002/03/18 05:34:45 in2 Exp $ */ +/* $Id: expire.c,v 1.4 2002/06/06 21:34:14 in2 Exp $ */ /* 自動砍信工具程式 */ -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <strings.h> -#include <dirent.h> -#include <fcntl.h> -#include <unistd.h> -#include <time.h> -#include <sys/types.h> -#include <sys/stat.h> -#include <sys/file.h> -#include "config.h" -#include "pttstruct.h" -#include "util.h" -#include "proto.h" +#include "bbs.h" #define QCAST int (*)(const void *, const void *) diff --git a/pttbbs/util/horoscope.c b/pttbbs/util/horoscope.c index c91db7cd..f1183591 100644 --- a/pttbbs/util/horoscope.c +++ b/pttbbs/util/horoscope.c @@ -1,10 +1,5 @@ -/* $Id: horoscope.c,v 1.1 2002/03/07 15:13:46 in2 Exp $ */ -#include <stdio.h> -#include <sys/types.h> -#include "config.h" -#include "pttstruct.h" -#include "util.h" -#include "common.h" +/* $Id: horoscope.c,v 1.2 2002/06/06 21:34:14 in2 Exp $ */ +#include "bbs.h" struct userec_t cuser; diff --git a/pttbbs/util/inndBM.c b/pttbbs/util/inndBM.c index 7a1f665c..17b6ce87 100644 --- a/pttbbs/util/inndBM.c +++ b/pttbbs/util/inndBM.c @@ -1,15 +1,6 @@ /* 依據 .BOARD檔 & newsfeeds.bbs 列出參與轉信的所有板資料 */ -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <sys/types.h> -#include <sys/ipc.h> -#include <sys/shm.h> -#include <sys/stat.h> -#include "config.h" -#include "pttstruct.h" -#include "proto.h" +#include "bbs.h" #define INNDHOME BBSHOME"/innd" @@ -18,7 +9,6 @@ #define INND_BADFEED INNDHOME "/badfeeds.bbs" #define INND_SCRIPT INNDHOME "/bbsnnrpall.auto.sh" -extern bcache_t *brdshm; extern boardheader_t *bcache; extern int numboards; int istran[MAX_BOARD]; @@ -185,21 +175,21 @@ int main() (bcache[i].brdattr & BRD_GROUPBOARD) ) continue; if((bcache[i].brdattr & BRD_NOTRAN )&& istran[i]) { - while(brdshm->busystate) {safe_sleep(1);} - brdshm->busystate = 1; + while(SHM->Bbusystate) {safe_sleep(1);} + SHM->Bbusystate = 1; bcache[i].brdattr = bcache[i].brdattr & ~BRD_NOTRAN; strncpy(bcache[i].title + 5, "●", 2); - brdshm->busystate = 0; + SHM->Bbusystate = 0; substitute_record(BBSHOME"/.BRD", &bcache[i],sizeof(boardheader_t),i+1); } else if(!(bcache[i].brdattr & BRD_NOTRAN) && !istran[i]) { - while(brdshm->busystate) {safe_sleep(1);} - brdshm->busystate = 1; + while(SHM->Bbusystate) {safe_sleep(1);} + SHM->Bbusystate = 1; bcache[i].brdattr = bcache[i].brdattr | BRD_NOTRAN; strncpy(bcache[i].title + 5, "◎", 2); - brdshm->busystate = 0; + SHM->Bbusystate = 0; substitute_record(BBSHOME"/.BRD", &bcache[i],sizeof(boardheader_t),i+1); } diff --git a/pttbbs/util/jungo.c b/pttbbs/util/jungo.c index 8a46f22a..17a01a10 100644 --- a/pttbbs/util/jungo.c +++ b/pttbbs/util/jungo.c @@ -1,16 +1,5 @@ -#include <stdio.h> -#include <sys/types.h> -#include <unistd.h> -#include <string.h> -#include <stdlib.h> -#include <time.h> -#include <ctype.h> -#include "config.h" -#include "pttstruct.h" -#include "util.h" -#include "perm.h" -#include "common.h" -#include "proto.h" +/* $Id: jungo.c,v 1.4 2002/06/06 21:34:14 in2 Exp $ */ +#include "bbs.h" #define OUTFILE BBSHOME "/etc/toplazyBBM" #define FIREFILE BBSHOME "/etc/topfireBBM" diff --git a/pttbbs/util/mandex.c b/pttbbs/util/mandex.c index fd005924..8b073ea2 100644 --- a/pttbbs/util/mandex.c +++ b/pttbbs/util/mandex.c @@ -1,19 +1,8 @@ -/* $Id: mandex.c,v 1.3 2002/03/11 11:18:19 in2 Exp $ */ +/* $Id: mandex.c,v 1.4 2002/06/06 21:34:14 in2 Exp $ */ /* 'mandex -h' to help */ -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <dirent.h> -#include <unistd.h> -#include <fcntl.h> -#include <sys/types.h> -#include <sys/stat.h> -#include "config.h" -#include "pttstruct.h" -#include "util.h" - +#include "bbs.h" #ifndef MAXPATHLEN #define MAXPATHLEN 1024 #endif diff --git a/pttbbs/util/openticket.c b/pttbbs/util/openticket.c index 250d2238..33a8a54f 100644 --- a/pttbbs/util/openticket.c +++ b/pttbbs/util/openticket.c @@ -1,15 +1,6 @@ -/* $Id: openticket.c,v 1.3 2002/05/25 11:17:55 ptt Exp $ */ +/* $Id: openticket.c,v 1.4 2002/06/06 21:34:14 in2 Exp $ */ /* 開獎的 utility */ -#include <stdio.h> -#include <stdlib.h> -#include <unistd.h> -#include <time.h> -#include <sys/types.h> -#include "config.h" -#include "pttstruct.h" -#include "common.h" -#include "util.h" -#include "proto.h" +#include "bbs.h" static char *betname[8] = {"Ptt", "Jaky", "Action", "Heat", "DUNK", "Jungo", "waiting", "wofe"}; @@ -49,7 +40,6 @@ int main() time_t now = time(NULL); char des[MAX_DES][200] = {"", "", "", ""}; - extern struct utmpfile_t *utmpshm; if(passwd_mmap()) exit(1); @@ -103,7 +93,7 @@ int main() */ resolve_utmp(); - bet = utmpshm->number % 8; + bet = SHM->number % 8; /* diff --git a/pttbbs/util/openvice.c b/pttbbs/util/openvice.c index 9b5e438f..b622eb55 100644 --- a/pttbbs/util/openvice.c +++ b/pttbbs/util/openvice.c @@ -1,14 +1,7 @@ -/* $Id: openvice.c,v 1.1 2002/03/07 15:13:46 in2 Exp $ */ +/* $Id: openvice.c,v 1.2 2002/06/06 21:34:14 in2 Exp $ */ /* 發票開獎小程式 */ -#include <stdio.h> -#include <string.h> -#include <stdlib.h> -#include <unistd.h> -#include <sys/types.h> -#include "config.h" -#include "pttstruct.h" -#include "util.h" +#include "bbs.h" #define VICE_SHOW BBSHOME "/etc/vice.show1" #define VICE_BINGO BBSHOME "/etc/vice.bingo" @@ -26,10 +19,9 @@ int main() FILE *fp = fopen(VICE_SHOW, "w"), *fb = fopen(VICE_BINGO, "w"); - extern struct utmpfile_t *utmpshm; resolve_utmp(); - srand(utmpshm->number); + srand(SHM->number); if (!fp || !fb ) perror("error open file"); diff --git a/pttbbs/util/parse_news.c b/pttbbs/util/parse_news.c index 18fcd654..042cf107 100644 --- a/pttbbs/util/parse_news.c +++ b/pttbbs/util/parse_news.c @@ -1,14 +1,5 @@ -/* $Id: parse_news.c,v 1.3 2002/05/25 11:17:55 ptt Exp $ */ -#include <stdio.h> -#include <string.h> -#include <stdlib.h> -#include <fcntl.h> -#include <unistd.h> -#include <sys/types.h> -#include <sys/stat.h> -#include "config.h" -#include "pttstruct.h" -#include "util.h" +/* $Id: parse_news.c,v 1.4 2002/06/06 21:34:14 in2 Exp $ */ +#include "bbs.h" #define NEWSDIRECT BBSHOME "/boards/n/newspaper" #define MOVIEDIRECT BBSHOME "/etc/NEWS" diff --git a/pttbbs/util/post.c b/pttbbs/util/post.c index e14a0814..0d93e0a0 100644 --- a/pttbbs/util/post.c +++ b/pttbbs/util/post.c @@ -1,12 +1,5 @@ -/* $Id: post.c,v 1.3 2002/03/09 17:44:30 in2 Exp $ */ -#include <stdio.h> -#include <string.h> -#include <sys/types.h> -#include <time.h> -#include "config.h" -#include "pttstruct.h" -#include "util.h" -#include "proto.h" +/* $Id: post.c,v 1.4 2002/06/06 21:34:14 in2 Exp $ */ +#include "bbs.h" void keeplog(FILE *fin, char *fpath, char *board, char *title, char *owner) { fileheader_t fhdr; diff --git a/pttbbs/util/poststat.c b/pttbbs/util/poststat.c index 2577f770..9ae3b477 100644 --- a/pttbbs/util/poststat.c +++ b/pttbbs/util/poststat.c @@ -1,21 +1,7 @@ -/* $Id: poststat.c,v 1.2 2002/04/05 14:36:25 in2 Exp $ */ +/* $Id: poststat.c,v 1.3 2002/06/06 21:34:14 in2 Exp $ */ /* 統計今日、週、月、年熱門話題 */ -#include <stdio.h> -#include <stdlib.h> -#include <unistd.h> -#include <fcntl.h> -#include <time.h> -#include <sys/types.h> -#include <sys/ipc.h> -#include <sys/shm.h> - -#ifdef __FreeBSD__ -#include <machine/param.h> -#endif - -#include "config.h" -#include "pttstruct.h" +#include "bbs.h" char *myfile[] = {"day", "week", "month", "year"}; @@ -73,96 +59,6 @@ int Rename(char *src, char *dst) return 0; } - - -/*-------------------------------------------------------*/ -/* .BOARDS cache */ -/*-------------------------------------------------------*/ - -struct bcache_t *brdshm; -boardheader_t *bcache; -int numboards = -1; - - -static void -attach_err(shmkey, name) - int shmkey; - char *name; -{ - fprintf(stderr, "[%s error] key = %x\n", name, shmkey); - exit(1); -} - - -static void * -attach_shm(shmkey, shmsize) - int shmkey, shmsize; -{ - void *shmptr; - int shmid; - - shmid = shmget(shmkey, shmsize, 0); - if (shmid < 0) - { - shmid = shmget(shmkey, shmsize, IPC_CREAT | 0600); - if (shmid < 0) - attach_err(shmkey, "shmget"); - shmptr = (void *) shmat(shmid, NULL, 0); - if (shmptr == (void *) -1) - attach_err(shmkey, "shmat"); - memset(shmptr, 0, shmsize); - } - else - { - shmptr = (void *) shmat(shmid, NULL, 0); - if (shmptr == (void *) -1) - attach_err(shmkey, "shmat"); - } - return shmptr; -} - - - -void -resolve_boards() -{ - if (brdshm == NULL) - { - brdshm = attach_shm(BRDSHM_KEY, sizeof(*brdshm)); - if (brdshm->touchtime == 0) - brdshm->touchtime = 1; - bcache = brdshm->bcache; - } - - while (brdshm->uptime < brdshm->touchtime) - { - if (brdshm->busystate) - { - sleep(1); - } - else - { - int fd; - - brdshm->busystate = 1; - - if ((fd = open(".BRD", O_RDONLY)) > 0) - { - brdshm->number = read(fd, bcache, MAX_BOARD * sizeof(boardheader_t)) - / sizeof(boardheader_t); - close(fd); - } - - /* 等所有 boards 資料更新後再設定 uptime */ - - brdshm->uptime = brdshm->touchtime; - brdshm->busystate = 0; - } - } - numboards = brdshm->number; -} - - int ci_strcmp(s1, s2) register char *s1, *s2; @@ -184,46 +80,6 @@ ci_strcmp(s1, s2) return 0; } -int -get_record(fpath, rptr, size, id) - char *fpath; - char *rptr; - int size, id; -{ - int fd; - - if ((fd = open(fpath, O_RDONLY, 0)) != -1) - { - if (lseek(fd, size * (id - 1), SEEK_SET) != -1) - { - if (read(fd, rptr, size) == size) - { - close(fd); - return 0; - } - } - close(fd); - } - return -1; -} - - -int -getbnum(bname) - char *bname; -{ - register int i; - register boardheader_t *bhdr; - - resolve_boards(); - for (i = 0, bhdr = bcache; i++ < numboards; bhdr++) - /* if (Ben_Perm(bhdr)) */ - if (!ci_strcmp(bname, bhdr->brdname)) - return i; - return 0; -} - - int hash(key) char *key; diff --git a/pttbbs/util/reaper.c b/pttbbs/util/reaper.c index 925ea11b..d605bb70 100644 --- a/pttbbs/util/reaper.c +++ b/pttbbs/util/reaper.c @@ -1,16 +1,5 @@ -#include <stdio.h> -#include <stdlib.h> -#include <stdarg.h> -#include <string.h> -#include <time.h> -#include <syslog.h> -#include <unistd.h> -#include <ctype.h> -#include <sys/types.h> -#include "config.h" -#include "pttstruct.h" -#include "perm.h" -#include "util.h" +/* $Id: reaper.c,v 1.2 2002/06/06 21:34:14 in2 Exp $ */ +#include "bbs.h" time_t now; diff --git a/pttbbs/util/rmuid.c b/pttbbs/util/rmuid.c index c936d160..901a31c8 100644 --- a/pttbbs/util/rmuid.c +++ b/pttbbs/util/rmuid.c @@ -1,14 +1,5 @@ -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <dirent.h> -#include <unistd.h> -#include <sys/types.h> -#include <sys/stat.h> -#include <unistd.h> -#include "config.h" -#include "pttstruct.h" -#include "util.h" +/* $Id: rmuid.c,v 1.3 2002/06/06 21:34:14 in2 Exp $ */ +#include "bbs.h" extern int numboards; extern boardheader_t *bcache; diff --git a/pttbbs/util/shmctl.c b/pttbbs/util/shmctl.c index 7f2aae98..e264eb48 100644 --- a/pttbbs/util/shmctl.c +++ b/pttbbs/util/shmctl.c @@ -1,25 +1,12 @@ -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <unistd.h> -#include <ctype.h> -#include <signal.h> -#include <sys/types.h> -#include <sys/shm.h> -#include <errno.h> -#include "config.h" -#include "pttstruct.h" -#include "util.h" -#include "proto.h" +/* $Id: shmctl.c,v 1.19 2002/06/06 21:34:14 in2 Exp $ */ +#include "bbs.h" -extern struct utmpfile_t *utmpshm; -extern struct pttcache_t *ptt; -extern bcache_t *brdshm; +extern SHM_t *SHM; int logout_friend_online(userinfo_t *utmp) { int i, j, k; - int offset=(int) (utmp - &utmpshm->uinfo[0]); + int offset=(int) (utmp - &SHM->uinfo[0]); userinfo_t *ui; while(utmp->friendtotal){ i = utmp->friendtotal-1; @@ -28,7 +15,7 @@ int logout_friend_online(userinfo_t *utmp) printf("\tonline friend error(%d)\n", j); else{ utmp->friend_online[i]=0; - ui = &utmpshm->uinfo[j]; + ui = &SHM->uinfo[j]; if(ui->pid && ui!=utmp){ for(k=0; k<ui->friendtotal && (int)(ui->friend_online[k] & 0xFFFFFF) !=offset; k++); @@ -72,58 +59,58 @@ int utmpfix(int argc, char **argv) time(&now); for( i = 0 ; i < 5 ; ++i ) - if( !utmpshm->busystate ) + if( !SHM->UTMPbusystate ) break; else{ puts("utmpshm is busy...."); sleep(1); } printf("starting scaning... %s \n", (fast ? "(fast mode)" : "")); - utmpshm->busystate = 1; + SHM->UTMPbusystate = 1; for( i = 0 ; i < USHM_SIZE ; ++i ) - if( utmpshm->uinfo[i].pid ){ + if( SHM->uinfo[i].pid ){ clean = NULL; - if( !isalpha(utmpshm->uinfo[i].userid[0]) ) + if( !isalpha(SHM->uinfo[i].userid[0]) ) clean = "userid error"; - else if( kill(utmpshm->uinfo[i].pid, 0) < 0 ){ + else if( kill(SHM->uinfo[i].pid, 0) < 0 ){ clean = "process error"; - purge_utmp(&utmpshm->uinfo[i]); + purge_utmp(&SHM->uinfo[i]); } else if( !fast ){ #ifdef DOTIMEOUT - if( now - utmpshm->uinfo[i].lastact > + if( now - SHM->uinfo[i].lastact > (timeout == -1 ? IDLE_TIMEOUT : timeout) ){ sprintf(buf, "timeout(%s", - ctime(&utmpshm->uinfo[i].lastact)); + ctime(&SHM->uinfo[i].lastact)); buf[strlen(buf) - 1] = 0; strcat(buf, ")"); clean = buf; - kill(utmpshm->uinfo[i].pid, SIGHUP); - purge_utmp(&utmpshm->uinfo[i]); + kill(SHM->uinfo[i].pid, SIGHUP); + purge_utmp(&SHM->uinfo[i]); } else #endif - if( searchuser(utmpshm->uinfo[i].userid) == 0 ){ + if( searchuser(SHM->uinfo[i].userid) == 0 ){ clean = "user not exist"; } } if( clean ){ printf("clean %06d(%s), userid: %s\n", - i, clean, utmpshm->uinfo[i].userid); - memset(&utmpshm->uinfo[i], 0, sizeof(userinfo_t)); + i, clean, SHM->uinfo[i].userid); + memset(&SHM->uinfo[i], 0, sizeof(userinfo_t)); } - else if ( utmpshm->uinfo[i].mind > 40 ){ + else if ( SHM->uinfo[i].mind > 40 ){ printf("mind fix: %06d, userid: %s, mind: %d\n", - i, utmpshm->uinfo[i].userid, utmpshm->uinfo[i].mind); - utmpshm->uinfo[i].mind %= 40; + i, SHM->uinfo[i].userid, SHM->uinfo[i].mind); + SHM->uinfo[i].mind %= 40; } } - utmpshm->busystate = 0; + SHM->UTMPbusystate = 0; return 0; } -char *CTIME(char *buf, time_t t) +char *CTIMEx(char *buf, time_t t) { strcpy(buf, ctime(&t)); buf[strlen(buf) - 1] = 0; @@ -135,19 +122,19 @@ int utmpstate(int argc, char **argv) time_t now; char upbuf[64], nowbuf[64]; now = time(NULL); - CTIME(upbuf, utmpshm->uptime); - CTIME(nowbuf, time(NULL)); + CTIMEx(upbuf, SHM->UTMPuptime); + CTIMEx(nowbuf, time(NULL)); printf("now: %s\n", nowbuf); - printf("currsorted: %d\n", utmpshm->currsorted); + printf("currsorted: %d\n", SHM->currsorted); printf("uptime: %s\n", upbuf); - printf("number: %d\n", utmpshm->number); - printf("busystate: %d\n", utmpshm->busystate); + printf("number: %d\n", SHM->number); + printf("busystate: %d\n", SHM->UTMPbusystate); return 0; } int utmpreset(int argc, char **argv) { - utmpshm->busystate=0; + SHM->UTMPbusystate=0; utmpstate(0, NULL); return 0; } @@ -200,44 +187,44 @@ int utmpsort(int argc, char **argv) int count, i, ns; userinfo_t *uentp; - if(now-utmpshm->uptime<60 && (now==utmpshm->uptime || utmpshm->busystate)){ + if(now-SHM->UTMPuptime<60 && (now==SHM->UTMPuptime || SHM->UTMPbusystate)){ puts("lazy sort"); //return; /* lazy sort */ } - utmpshm->busystate=1; - utmpshm->uptime = now; - ns=(utmpshm->currsorted?0:1); + SHM->UTMPbusystate=1; + SHM->UTMPuptime = now; + ns=(SHM->currsorted?0:1); - for(uentp = &utmpshm->uinfo[0], count=0, i=0; - i< USHM_SIZE; i++,uentp = &utmpshm->uinfo[i]) + for(uentp = &SHM->uinfo[0], count=0, i=0; + i< USHM_SIZE; i++,uentp = &SHM->uinfo[i]) if(uentp->pid){ - utmpshm->sorted[ns][0][count++]= uentp; + SHM->sorted[ns][0][count++]= uentp; } - utmpshm->number = count; - qsort(utmpshm->sorted[ns][0],count,sizeof(userinfo_t*),cmputmpuserid); - memcpy(utmpshm->sorted[ns][1],utmpshm->sorted[ns][0], + SHM->number = count; + qsort(SHM->sorted[ns][0],count,sizeof(userinfo_t*),cmputmpuserid); + memcpy(SHM->sorted[ns][1],SHM->sorted[ns][0], sizeof(userinfo_t *)*count); - memcpy(utmpshm->sorted[ns][2],utmpshm->sorted[ns][0], + memcpy(SHM->sorted[ns][2],SHM->sorted[ns][0], sizeof(userinfo_t *)*count); - memcpy(utmpshm->sorted[ns][3],utmpshm->sorted[ns][0], + memcpy(SHM->sorted[ns][3],SHM->sorted[ns][0], sizeof(userinfo_t *)*count); - memcpy(utmpshm->sorted[ns][4],utmpshm->sorted[ns][0], + memcpy(SHM->sorted[ns][4],SHM->sorted[ns][0], sizeof(userinfo_t *)*count); - memcpy(utmpshm->sorted[ns][5],utmpshm->sorted[ns][0], + memcpy(SHM->sorted[ns][5],SHM->sorted[ns][0], sizeof(userinfo_t *)*count); - memcpy(utmpshm->sorted[ns][6],utmpshm->sorted[ns][0], + memcpy(SHM->sorted[ns][6],SHM->sorted[ns][0], sizeof(userinfo_t *)*count); - memcpy(utmpshm->sorted[ns][7],utmpshm->sorted[ns][0], + memcpy(SHM->sorted[ns][7],SHM->sorted[ns][0], sizeof(userinfo_t *)*count); - qsort(utmpshm->sorted[ns][1], count, sizeof(userinfo_t *), cmputmpmode ); - qsort(utmpshm->sorted[ns][2], count, sizeof(userinfo_t *), cmputmpidle ); - qsort(utmpshm->sorted[ns][3], count, sizeof(userinfo_t *), cmputmpfrom ); - qsort(utmpshm->sorted[ns][4], count, sizeof(userinfo_t *), cmputmpfive ); - //qsort(utmpshm->sorted[ns][5], count, sizeof(userinfo_t *), cmputmpsex ); - qsort(utmpshm->sorted[ns][6], count, sizeof(userinfo_t *), cmputmpuid ); - qsort(utmpshm->sorted[ns][7], count, sizeof(userinfo_t *), cmputmppid ); - utmpshm->currsorted=ns; - utmpshm->busystate=0; + qsort(SHM->sorted[ns][1], count, sizeof(userinfo_t *), cmputmpmode ); + qsort(SHM->sorted[ns][2], count, sizeof(userinfo_t *), cmputmpidle ); + qsort(SHM->sorted[ns][3], count, sizeof(userinfo_t *), cmputmpfrom ); + qsort(SHM->sorted[ns][4], count, sizeof(userinfo_t *), cmputmpfive ); + //qsort(SHM->sorted[ns][5], count, sizeof(userinfo_t *), cmputmpsex ); + qsort(SHM->sorted[ns][6], count, sizeof(userinfo_t *), cmputmpuid ); + qsort(SHM->sorted[ns][7], count, sizeof(userinfo_t *), cmputmppid ); + SHM->currsorted=ns; + SHM->UTMPbusystate=0; puts("new utmpstate"); utmpstate(0, NULL); @@ -252,13 +239,13 @@ int utmpwatch(int argc, char **argv) while( 1 ){ for( i = 0 ; i < TIMES ; ++i ){ usleep(300); - if( !utmpshm->busystate ) + if( !SHM->UTMPbusystate ) break; puts("busying..."); } if( i == TIMES ){ puts("reset!"); - utmpshm->busystate = 0; + SHM->UTMPbusystate = 0; } } return 0; @@ -266,7 +253,7 @@ int utmpwatch(int argc, char **argv) int utmpnum(int argc, char **argv) { - printf("%d.0\n", utmpshm->number); + printf("%d.0\n", SHM->number); return 0; } @@ -274,7 +261,7 @@ int showglobal(int argc, char **argv) { int i; for( i = 0 ; i < 10 ; ++i ) - printf("GLOBALVAR[%d] = %d\n", i, ptt->GLOBALVAR[i]); + printf("GLOBALVAR[%d] = %d\n", i, SHM->GLOBALVAR[i]); return 0; } @@ -288,8 +275,8 @@ int setglobal(int argc, char **argv) puts("only GLOBALVAR[0] ~ GLOBALVAR[9]"); return 1; } - printf("GLOBALVAR[%d] = %d -> ", where, ptt->GLOBALVAR[where]); - printf("%d\n", ptt->GLOBALVAR[where] = atoi(argv[2])); + printf("GLOBALVAR[%d] = %d -> ", where, SHM->GLOBALVAR[where]); + printf("%d\n", SHM->GLOBALVAR[where] = atoi(argv[2])); return 0; } @@ -299,14 +286,14 @@ int fixbfriend(int argc, char **argv) int count, i; for( i = 0 ; i < MAX_BOARD ; ++i ){ - if( isdigit(brdshm->bcache[i].brdname[0]) || - isalpha(brdshm->bcache[i].brdname[0]) ){ - for( count = 0, ptr = brdshm->bcache[i].u ; + if( isdigit(SHM->bcache[i].brdname[0]) || + isalpha(SHM->bcache[i].brdname[0]) ){ + for( count = 0, ptr = SHM->bcache[i].u ; ptr != NULL && count < 256 ; ++count, ptr = ptr->nextbfriend ) ; - printf("counting %s\n", brdshm->bcache[i].brdname); - brdshm->bcache[i].nuser = ((count == 256) ? 0 : count); + printf("counting %s\n", SHM->bcache[i].brdname); + SHM->bcache[i].nuser = ((count == 256) ? 0 : count); } } @@ -319,10 +306,10 @@ struct { } cmd[] = { {utmpfix, "utmpfix", "clear dead userlist entry"}, {utmpstate, "utmpstate", "list utmpstate"}, - {utmpreset, "utmpreset", "utmpshm->busystate=0"}, + {utmpreset, "utmpreset", "SHM->busystate=0"}, {utmpsort, "utmpsort", "sort ulist"}, {utmpwatch, "utmpwatch", "to see if busystate is always 1 then fix it"}, - {utmpnum, "utmpnum", "print utmpshm->number for snmpd"}, + {utmpnum, "utmpnum", "print SHM->number for snmpd"}, {showglobal, "showglobal", "show GLOBALVAR[]"}, {setglobal, "setglobal", "set GLOBALVAR[]"}, {fixbfriend, "fixbfriend", "recount numbers of board friends"}, @@ -334,7 +321,7 @@ int main(int argc, char **argv) if( argc >= 2 ){ /* shmctl shouldn't create shm itself */ - int shmid = shmget(UHASH_KEY, sizeof(uhash_t), 0); + int shmid = shmget(SHM_KEY, sizeof(SHM_t), 0); if( shmid < 0 ){ printf("%d\n", errno); perror("attach utmpshm"); diff --git a/pttbbs/util/shmsweep.c b/pttbbs/util/shmsweep.c index 01acb26b..94d5291a 100644 --- a/pttbbs/util/shmsweep.c +++ b/pttbbs/util/shmsweep.c @@ -8,6 +8,7 @@ #include "pttstruct.h" int main() { +#if 0 int i, shm, counter; struct utmpfile_t *utmpshm; @@ -25,7 +26,7 @@ int main() { } for(i = counter = 0; i < USHM_SIZE; i++) - if(utmpshm->uinfo[i].pid) { + if(SHM->uinfo[i].pid) { char buf[256]; userinfo_t *f; struct stat sb; @@ -39,5 +40,6 @@ int main() { } } printf("clear %d slots\n", counter); +#endif return 0; } diff --git a/pttbbs/util/smtest.c b/pttbbs/util/smtest.c index 9059c419..f211cb3a 100644 --- a/pttbbs/util/smtest.c +++ b/pttbbs/util/smtest.c @@ -1,16 +1,5 @@ -#include <stdio.h> -#include <sys/types.h> -#include <unistd.h> -#include <string.h> -#include <stdlib.h> -#include <time.h> -#include <ctype.h> -#include "config.h" -#include "pttstruct.h" -#include "util.h" -#include "perm.h" -#include "common.h" -#include "proto.h" +/* $Id: smtest.c,v 1.4 2002/06/06 21:34:14 in2 Exp $ */ +#include "bbs.h" #define WARNFILE BBSHOME "/etc/DeleteBoard.warn" #define EXECFILE BBSHOME"/etc/DeleteBoard.exec" diff --git a/pttbbs/util/toplazyBBM.c b/pttbbs/util/toplazyBBM.c index 1341c17a..90f6ee2c 100644 --- a/pttbbs/util/toplazyBBM.c +++ b/pttbbs/util/toplazyBBM.c @@ -1,16 +1,5 @@ -#include <stdio.h> -#include <sys/types.h> -#include <unistd.h> -#include <string.h> -#include <stdlib.h> -#include <time.h> -#include <ctype.h> -#include "config.h" -#include "pttstruct.h" -#include "util.h" -#include "perm.h" -#include "common.h" -#include "proto.h" +/* $Id: toplazyBBM.c,v 1.4 2002/06/06 21:34:14 in2 Exp $ */ +#include "bbs.h" #define OUTFILE BBSHOME "/etc/toplazyBBM" #define FIREFILE BBSHOME "/etc/topfireBBM" diff --git a/pttbbs/util/toplazyBM.c b/pttbbs/util/toplazyBM.c index 0aba0560..3494eb07 100644 --- a/pttbbs/util/toplazyBM.c +++ b/pttbbs/util/toplazyBM.c @@ -1,17 +1,5 @@ -#include <stdio.h> -#include <sys/types.h> -#include <unistd.h> -#include <string.h> -#include <stdlib.h> -#include <time.h> -#include <ctype.h> -#include "config.h" -#include "pttstruct.h" -#include "util.h" -#include "perm.h" -#include "common.h" -#include "proto.h" -#include "modes.h" +/* $Id: toplazyBM.c,v 1.4 2002/06/06 21:34:14 in2 Exp $ */ +#include "bbs.h" #define OUTFILE BBSHOME "/etc/toplazyBM" diff --git a/pttbbs/util/topusr.c b/pttbbs/util/topusr.c index 22b95e94..0f64777d 100644 --- a/pttbbs/util/topusr.c +++ b/pttbbs/util/topusr.c @@ -1,15 +1,7 @@ -/* $Id: topusr.c,v 1.1 2002/03/07 15:13:46 in2 Exp $ */ +/* $Id: topusr.c,v 1.2 2002/06/06 21:34:14 in2 Exp $ */ /* 使用者 上站記錄/文章篇數 排行榜 */ -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <sys/types.h> -#include "config.h" -#include "pttstruct.h" -#include "perm.h" -#include "common.h" -#include "util.h" +#include "bbs.h" #define REAL_INFO struct manrec diff --git a/pttbbs/util/uhash_loader.c b/pttbbs/util/uhash_loader.c index 1a963829..5fadd48e 100644 --- a/pttbbs/util/uhash_loader.c +++ b/pttbbs/util/uhash_loader.c @@ -1,4 +1,4 @@ -/* $Id: uhash_loader.c,v 1.2 2002/03/09 17:44:30 in2 Exp $ */ +/* $Id: uhash_loader.c,v 1.3 2002/06/06 21:34:14 in2 Exp $ */ /* standalone uhash loader -- jochang */ #include <stdio.h> #include <unistd.h> @@ -24,7 +24,7 @@ void add_to_uhash(int n, userec_t *id); void fill_uhash(void); void load_uhash(void); -uhash_t *uhash; +SHM_t *SHM; int main() { setgid(BBSGID); @@ -36,7 +36,7 @@ int main() { void load_uhash(void) { int shmid; - shmid = shmget(UHASH_KEY, sizeof(uhash_t), IPC_CREAT | 0600); + shmid = shmget(SHM_KEY, sizeof(SHM_t), IPC_CREAT | 0600); /* note we didn't use IPC_EXCL here. so if the loading fails, (like .PASSWD doesn't exist) @@ -48,20 +48,20 @@ void load_uhash(void) { exit(1); } - uhash = (void *) shmat(shmid, NULL, 0); - if (uhash == (void *) -1) + SHM = (void *) shmat(shmid, NULL, 0); + if (SHM == (void *) -1) { perror("shmat"); exit(1); } /* in case it's not assumed zero, this becomes a race... */ - uhash->loaded = 0; + SHM->loaded = 0; fill_uhash(); /* ok... */ - uhash->loaded = 1; + SHM->loaded = 1; } void fill_uhash(void) @@ -70,7 +70,7 @@ void fill_uhash(void) usernumber = 0; for (fd = 0; fd < (1 << HASH_BITS); fd++) - uhash->hash_head[fd] = -1; + SHM->hash_head[fd] = -1; if ((fd = open(FN_PASSWD, O_RDONLY)) > 0) { @@ -101,7 +101,7 @@ void fill_uhash(void) perror("open"); exit(1); } - uhash->number = usernumber; + SHM->number = usernumber; printf("total %d names loaded.\n", usernumber); } unsigned string_hash(unsigned char *s) @@ -118,12 +118,12 @@ unsigned string_hash(unsigned char *s) void add_to_uhash(int n, userec_t *user) { int *p, h = string_hash(user->userid); - strcpy(uhash->userid[n], user->userid); - uhash->money[n] = user->money; - p = &(uhash->hash_head[h]); + strcpy(SHM->userid[n], user->userid); + SHM->money[n] = user->money; + p = &(SHM->hash_head[h]); while (*p != -1) - p = &(uhash->next_in_hash[*p]); + p = &(SHM->next_in_hash[*p]); - uhash->next_in_hash[*p = n] = -1; + SHM->next_in_hash[*p = n] = -1; } diff --git a/pttbbs/util/userlist.c b/pttbbs/util/userlist.c index 9a142926..c8d53389 100644 --- a/pttbbs/util/userlist.c +++ b/pttbbs/util/userlist.c @@ -7,40 +7,39 @@ #include "config.h" #include "pttstruct.h" -struct utmpfile_t *u; +SHM_t *SHM; int main(int argc, char **argv) { int i, shm, counter; - shm = shmget(UTMPSHM_KEY, USHM_SIZE, SHM_R | SHM_W); + shm = shmget(SHM_KEY, USHM_SIZE, SHM_R | SHM_W); if(shm == -1) { perror("shmget"); exit(0); } - u = shmat(shm, NULL, 0); - if(u == (struct utmpfile_t *)-1) { + if( (SHM = shmat(shm, NULL, 0)) < 0 ){ perror("shmat"); exit(0); } if(argc > 1) { for(i = 1; i < argc; i++) - u->uinfo[atoi(argv[i])].pid = 0; + SHM->uinfo[atoi(argv[i])].pid = 0; } else { for(i = counter = 0; i < USHM_SIZE; i++) - if(u->uinfo[i].pid) { + if(SHM->uinfo[i].pid) { userinfo_t *f; - f = &u->uinfo[i]; + f = &SHM->uinfo[i]; printf( "%4d(%d) p[%d] i[%d] u[%s] n[%s] f[%s] m[%d] d[%d] t[%ld]\n", ++counter, i, f->pager, f->invisible, f->userid, f->username, f->from, f->mode, f->mind, f->lastact); } - printf("\nTotal: %d(%d)\n", counter, u->number); - if(counter != u->number) { - u->number = counter; + printf("\nTotal: %d(%d)\n", counter, SHM->number); + if(counter != SHM->number) { + SHM->number = counter; printf("adjust user number!\n"); } } diff --git a/pttbbs/util/util_cache.c b/pttbbs/util/util_cache.c index 0e1ab5a1..7f4b0897 100644 --- a/pttbbs/util/util_cache.c +++ b/pttbbs/util/util_cache.c @@ -1,4 +1,4 @@ -/* $Id: util_cache.c,v 1.2 2002/03/09 17:29:20 in2 Exp $ */ +/* $Id: util_cache.c,v 1.3 2002/06/06 21:34:15 in2 Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -26,8 +26,6 @@ #include "modes.h" #include "proto.h" -int fcache_semid; - /* the reason for "safe_sleep" is that we may call sleep during SIGALRM handler routine, while SIGALRM is blocked. if we use the original sleep, we'll never wake up. */ @@ -140,40 +138,43 @@ void sem_lock(int op,int semid) { semop(semid, &sops, 1); } -/* uhash *******************************************/ -/* the design is this: - we use another stand-alone program to create and load data into the hash. - (that program could be run in rc-scripts or something like that) - after loading completes, the stand-alone program sets loaded to 1 and exits. - - the bbs exits if it can't attach to the shared memory or - the hash is not loaded yet. -*/ -uhash_t *uhash; +SHM_t *SHM; +int *GLOBALVAR; +boardheader_t *bcache; + +void attach_SHM(void) +{ + SHM = attach_shm(SHM_KEY, sizeof(SHM_t)); + if( !SHM->loaded ) /* (uhash) assume fresh shared memory is zeroed */ + exit(1); + if( SHM->Btouchtime == 0 ) + SHM->Btouchtime = 1; + bcache = SHM->bcache; + + GLOBALVAR = SHM->GLOBALVAR; + if( SHM->Ptouchtime == 0 ) + SHM->Ptouchtime = 1; + + if( SHM->Ftouchtime == 0 ) + SHM->Ftouchtime = 1; +} int setumoney(int uid, int money) { - uhash->money[uid-1]=money; + SHM->money[uid-1]=money; passwd_update_money(uid); - return uhash->money[uid-1]; + return SHM->money[uid-1]; } int deumoney(int uid, int money) { - if(money<0 && uhash->money[uid-1]<-money) + if(money<0 && SHM->money[uid-1]<-money) return setumoney(uid,0); else - return setumoney(uid,uhash->money[uid-1]+money); + return setumoney(uid,SHM->money[uid-1]+money); } int moneyof(int uid){ /* ptt 改進金錢處理效率 */ - return uhash->money[uid-1]; -} -/* attach_uhash should be called before using uhash */ -void attach_uhash() { - uhash = attach_shm(UHASH_KEY, sizeof(*uhash)); - if(!uhash->loaded) /* assume fresh shared memory is zeroed */ - exit(1); + return SHM->money[uid-1]; } - static unsigned string_hash(unsigned char *s) { unsigned int v=0; while(*s) { @@ -185,43 +186,43 @@ static unsigned string_hash(unsigned char *s) { void add_to_uhash(int n, char *id) { int *p, h = string_hash(id); - strcpy(uhash->userid[n], id); + strcpy(SHM->userid[n], id); - p = &(uhash->hash_head[h]); + p = &(SHM->hash_head[h]); while(*p != -1) - p = &(uhash->next_in_hash[*p]); + p = &(SHM->next_in_hash[*p]); - uhash->next_in_hash[*p = n] = -1; + SHM->next_in_hash[*p = n] = -1; } /* note: after remove_from_uhash(), you should add_to_uhash() (likely with a different name) */ void remove_from_uhash(int n) { - int h = string_hash(uhash->userid[n]); - int *p = &(uhash->hash_head[h]); + int h = string_hash(SHM->userid[n]); + int *p = &(SHM->hash_head[h]); while(*p != -1 && *p != n) - p = &(uhash->next_in_hash[*p]); + p = &(SHM->next_in_hash[*p]); if(*p == n) - *p = uhash->next_in_hash[n]; + *p = SHM->next_in_hash[n]; } int searchuser(char *userid) { int h,p; - if(uhash == NULL) - attach_uhash(); /* for sloopy util programs */ + if(SHM == NULL) + attach_SHM(); /* for sloopy util programs */ h = string_hash(userid); - p = uhash->hash_head[h]; + p = SHM->hash_head[h]; while(p != -1) { - if(strcasecmp(uhash->userid[p],userid) == 0) { - strcpy(userid,uhash->userid[p]); + if(strcasecmp(SHM->userid[p],userid) == 0) { + strcpy(userid,SHM->userid[p]); return p + 1; } - p = uhash->next_in_hash[p]; + p = SHM->next_in_hash[p]; } return 0; } @@ -233,10 +234,11 @@ int getuser(char *userid) { passwd_query(uid, &xuser); return uid; } + void setuserid(int num, char *userid) { if(num > 0 && num <= MAX_USERS) { - if(num > uhash->number) - uhash->number = num; + if(num > SHM->number) + SHM->number = num; else remove_from_uhash(num-1); add_to_uhash(num-1,userid); @@ -246,13 +248,11 @@ void setuserid(int num, char *userid) { /*-------------------------------------------------------*/ /* .UTMP cache */ /*-------------------------------------------------------*/ -struct utmpfile_t *utmpshm=NULL; - void resolve_utmp() { - if(utmpshm == NULL) { - utmpshm = attach_shm(UTMPSHM_KEY, sizeof(*utmpshm)); - if(utmpshm->uptime == 0) - utmpshm->uptime = utmpshm->number = 1; + if(SHM == NULL) { + attach_SHM(); + if(SHM->UTMPuptime == 0) + SHM->UTMPuptime = SHM->UTMPnumber = 1; } } @@ -266,11 +266,11 @@ void getnewutmpent(userinfo_t *up) { resolve_utmp(); for(i = 0; i < USHM_SIZE; i++) { - uentp = &(utmpshm->uinfo[i]); + uentp = &(SHM->uinfo[i]); if(!(uentp->pid)) { memcpy(uentp, up, sizeof(userinfo_t)); currutmp = uentp; - utmpshm->number++; + SHM->number++; return; } } @@ -283,7 +283,7 @@ int apply_ulist(int (*fptr)(userinfo_t *)) { resolve_utmp(); for(i = 0; i < USHM_SIZE; i++) { - uentp = &(utmpshm->uinfo[i]); + uentp = &(SHM->uinfo[i]); if(uentp->pid && (PERM_HIDE(currutmp) || !PERM_HIDE(uentp))) if((state = (*fptr) (uentp))) return state; @@ -297,7 +297,7 @@ userinfo_t *search_ulist(int uid) { resolve_utmp(); for(i = 0; i < USHM_SIZE; i++) { - uentp = &(utmpshm->uinfo[i]); + uentp = &(SHM->uinfo[i]); if(uid==uentp->uid) return uentp; } @@ -308,11 +308,10 @@ userinfo_t *search_ulist(int uid) { /* .BOARDS cache */ /*-------------------------------------------------------*/ char *fn_board=FN_BOARD; -bcache_t *brdshm; boardheader_t *bcache; static void reload_bcache() { - if(brdshm->busystate) { + if(SHM->Bbusystate) { safe_sleep(1); } } @@ -320,20 +319,20 @@ static void reload_bcache() { int numboards = -1; void resolve_boards() { - if(brdshm == NULL) { - brdshm = attach_shm(BRDSHM_KEY, sizeof(*brdshm)); - if(brdshm->touchtime == 0) - brdshm->touchtime = 1; - bcache = brdshm->bcache; + if(SHM == NULL) { + attach_SHM(); + if(SHM->Btouchtime == 0) + SHM->Btouchtime = 1; + bcache = SHM->bcache; } - while(brdshm->uptime < brdshm->touchtime) + while(SHM->Buptime < SHM->Btouchtime) reload_bcache(); - numboards = brdshm->number; + numboards = SHM->number; } void touch_boards() { - time(&(brdshm->touchtime)); + time(&(SHM->Btouchtime)); numboards = -1; resolve_boards(); } @@ -341,15 +340,15 @@ void reset_board(int bid) { int fd; if(--bid<0)return; - if(brdshm->busystate==0) + if(SHM->Bbusystate==0) { - brdshm->busystate = 1; + SHM->Bbusystate = 1; if((fd = open(fn_board, O_RDONLY)) > 0) { lseek(fd, (off_t)(bid * sizeof(boardheader_t)), SEEK_SET); read(fd, &bcache[bid], sizeof(boardheader_t)); close(fd); } - brdshm->busystate = 0; + SHM->Bbusystate = 0; } } boardheader_t *getbcache(int bid) { /* Ptt改寫 */ @@ -357,8 +356,8 @@ boardheader_t *getbcache(int bid) { /* Ptt } void touchbtotal(int bid) { - brdshm->total[bid - 1] = 0; - brdshm->lastposttime[bid - 1] = 0; + SHM->total[bid - 1] = 0; + SHM->lastposttime[bid - 1] = 0; } @@ -377,10 +376,9 @@ int getbnum(char *bname) { /* PTT cache */ /*-------------------------------------------------------*/ /* cachefor 動態看版 */ -struct pttcache_t *ptt; - -void reload_pttcache() { - if(ptt->busystate) +void reload_pttcache(void) +{ + if(SHM->Pbusystate) safe_sleep(1); else { /* jochang: temporary workaround */ fileheader_t item, subitem; @@ -388,9 +386,9 @@ void reload_pttcache() { FILE *fp, *fp1, *fp2; int id, section = 0; - ptt->busystate = 1; - ptt->max_film = 0; - bzero(ptt->notes, sizeof ptt->notes); + SHM->Pbusystate = 1; + SHM->max_film = 0; + bzero(SHM->notes, sizeof SHM->notes); setapath(pbuf, "Note"); setadir(buf, pbuf); id = 0; @@ -401,15 +399,15 @@ void reload_pttcache() { setadir(buf, buf); if(!(fp1 = fopen(buf, "r"))) continue; - ptt->next_refresh[section] = ptt->n_notes[section] = id; + SHM->next_refresh[section] = SHM->n_notes[section] = id; section ++; while(fread(&subitem, sizeof(subitem), 1, fp1)) { sprintf(buf,"%s/%s/%s", pbuf, item.filename , subitem.filename); if(!(fp2=fopen(buf,"r"))) continue; - fread(ptt->notes[id],sizeof(char), 200*11, fp2); - ptt->notes[id][200*11 - 1]=0; + fread(SHM->notes[id],sizeof(char), 200*11, fp2); + SHM->notes[id][200*11 - 1]=0; id++; fclose(fp2); if(id >= MAX_MOVIE) @@ -422,46 +420,46 @@ void reload_pttcache() { } fclose(fp); } - ptt->next_refresh[section] = -1; - ptt->n_notes[section] = ptt->max_film = id-1; - ptt->max_history = ptt->max_film - 2; - if(ptt->max_history > MAX_HISTORY - 1) - ptt->max_history = MAX_HISTORY - 1; - if(ptt->max_history <0) ptt->max_history=0; + SHM->next_refresh[section] = -1; + SHM->n_notes[section] = SHM->max_film = id-1; + SHM->max_history = SHM->max_film - 2; + if(SHM->max_history > MAX_HISTORY - 1) + SHM->max_history = MAX_HISTORY - 1; + if(SHM->max_history <0) SHM->max_history=0; fp = fopen("etc/today_is","r"); if(fp) { - fgets(ptt->today_is,15,fp); - if((chr = strchr(ptt->today_is,'\n'))) + fgets(SHM->today_is,15,fp); + if((chr = strchr(SHM->today_is,'\n'))) *chr = 0; - ptt->today_is[15] = 0; + SHM->today_is[15] = 0; fclose(fp); } /* 等所有資料更新後再設定 uptime */ - ptt->uptime = ptt->touchtime ; - ptt->busystate = 0; + SHM->Puptime = SHM->Ptouchtime ; + SHM->Pbusystate = 0; } } void resolve_garbage() { int count=0; - if(ptt == NULL) { - ptt = attach_shm(PTTSHM_KEY, sizeof(*ptt)); - if(ptt->touchtime == 0) - ptt->touchtime = 1; + if(SHM == NULL) { + attach_SHM(); + if(SHM->Ptouchtime == 0) + SHM->Ptouchtime = 1; } - while(ptt->uptime < ptt->touchtime) { /* 不用while等 */ + while(SHM->Puptime < SHM->Ptouchtime) { /* 不用while等 */ reload_pttcache(); - if(count ++ > 10 && ptt->busystate) { + if(count ++ > 10 && SHM->Pbusystate) { /* Ptt: 這邊會有問題 load超過10 秒會所有進loop的process都讓 busystate = 0 這樣會所有prcosee都會在load 動態看板 會造成load大增 但沒有用這個function的話 萬一load passwd檔的process死了 又沒有人把他 解開 同樣的問題發生在reload passwd */ - ptt->busystate = 0; + SHM->Pbusystate = 0; } } } @@ -470,49 +468,47 @@ void resolve_garbage() { /* PTT's cache */ /*-------------------------------------------------------*/ /* cachefor from host 與最多上線人數 */ -struct fromcache_t *fcache; - static void reload_fcache() { - if(fcache->busystate) + if(SHM->Fbusystate) safe_sleep(1); else { FILE *fp; - fcache->busystate = 1; - bzero(fcache->domain, sizeof fcache->domain); + SHM->Fbusystate = 1; + bzero(SHM->domain, sizeof SHM->domain); if((fp = fopen("etc/domain_name_query","r"))) { char buf[101],*po; - fcache->top=0; + SHM->top=0; while(fgets(buf,100,fp)) { if(buf[0] && buf[0] != '#' && buf[0] != ' ' && buf[0] != '\n') { - sscanf(buf,"%s",fcache->domain[fcache->top]); - po = buf + strlen(fcache->domain[fcache->top]); + sscanf(buf,"%s",SHM->domain[SHM->top]); + po = buf + strlen(SHM->domain[SHM->top]); while(*po == ' ') po++; - strncpy(fcache->replace[fcache->top],po,49); - fcache->replace[fcache->top] - [strlen(fcache->replace[fcache->top])-1] = 0; - (fcache->top)++; + strncpy(SHM->replace[SHM->top],po,49); + SHM->replace[SHM->top] + [strlen(SHM->replace[SHM->top])-1] = 0; + (SHM->top)++; } } } - fcache->max_user=0; + SHM->max_user=0; /* 等所有資料更新後再設定 uptime */ - fcache->uptime = fcache->touchtime; - fcache->busystate = 0; + SHM->Fuptime = SHM->Ftouchtime; + SHM->Fbusystate = 0; } } void resolve_fcache() { - if(fcache == NULL) { - fcache = attach_shm(FROMSHM_KEY, sizeof(*fcache)); - if(fcache->touchtime == 0) - fcache->touchtime = 1; + if(SHM == NULL) { + attach_SHM(); + if(SHM->Ftouchtime == 0) + SHM->Ftouchtime = 1; } - while(fcache->uptime < fcache->touchtime) + while(SHM->Fuptime < SHM->Ftouchtime) reload_fcache(); } diff --git a/pttbbs/util/xchatd.c b/pttbbs/util/xchatd.c index 46fba147..97cb33fe 100644 --- a/pttbbs/util/xchatd.c +++ b/pttbbs/util/xchatd.c @@ -1,25 +1,5 @@ -/* $Id: xchatd.c,v 1.1 2002/03/07 15:13:46 in2 Exp $ */ -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <unistd.h> -#include <netdb.h> -#include <fcntl.h> -#include <signal.h> -#include <errno.h> -#include <sys/types.h> -#include <sys/wait.h> -#include <sys/ioctl.h> -#include <sys/socket.h> -#include <time.h> -#include <sys/resource.h> -#include <netinet/in.h> -#include <arpa/inet.h> -#include "config.h" -#include "pttstruct.h" -#include "util.h" -#include "perm.h" -#include "common.h" +/* $Id: xchatd.c,v 1.2 2002/06/06 21:34:15 in2 Exp $ */ +#include "bbs.h" #include "xchatd.h" #define SERVER_USAGE @@ -598,7 +578,7 @@ list_belong(list, userno) static void -do_send(nfds, wset, msg, number) +Xdo_send(nfds, wset, msg, number) int nfds; fd_set *wset; char *msg; @@ -686,10 +666,10 @@ send_to_room(room, msg, userno, number) else sprintf(sendbuf, "%3d", number); - do_send(max, wptr, sendbuf); + Xdo_send(max, wptr, sendbuf); } else - do_send(max, wptr, msg); + Xdo_send(max, wptr, msg); } } @@ -720,10 +700,10 @@ send_to_user(user, msg, userno, number) sprintf(sendbuf, "%3d %s", number, msg); else sprintf(sendbuf, "%3d", number); - do_send(sock, wptr, sendbuf); + Xdo_send(sock, wptr, sendbuf); } else - do_send(sock, wptr, msg); + Xdo_send(sock, wptr, msg); } } @@ -737,7 +717,7 @@ send_to_sock(sock, msg) /* Thor: unused */ FD_ZERO(wptr = &wset); FD_SET(sock, wptr); - do_send(sock, wptr, msg); + Xdo_send(sock, wptr, msg); } #endif diff --git a/pttbbs/util/yearsold.c b/pttbbs/util/yearsold.c index 74e711ee..3124d778 100644 --- a/pttbbs/util/yearsold.c +++ b/pttbbs/util/yearsold.c @@ -1,21 +1,14 @@ -/* $Id: yearsold.c,v 1.1 2002/03/07 15:13:46 in2 Exp $ */ +/* $Id: yearsold.c,v 1.2 2002/06/06 21:34:15 in2 Exp $ */ /* 站上年齡統計 */ -#include <stdio.h> -#include <string.h> -#include <time.h> -#include <sys/types.h> -#include "config.h" -#include "pttstruct.h" -#include "common.h" -#include "util.h" +#include "bbs.h" #define MAX_LINE 16 struct userec_t cuser; void - outs(fp, buf, mode) +fouts(fp, buf, mode) FILE *fp; char buf[], mode; { @@ -88,12 +81,12 @@ int main() year = act[j]; if (year && (max > year) && (max - item <= year)) { - outs(fp, buf, '7'); + fouts(fp, buf, '7'); fprintf(fp, "%-3d", year); } else if (max <= year) { - outs(fp, buf, '4'); + fouts(fp, buf, '4'); fprintf(fp, "█ "); } else -- cgit v1.2.3 From e0c3ddb9c54cb57f794106d92778f8455128d4ae Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Thu, 6 Jun 2002 21:42:40 +0000 Subject: first commit git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@297 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/splitpasswd.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 pttbbs/util/splitpasswd.c diff --git a/pttbbs/util/splitpasswd.c b/pttbbs/util/splitpasswd.c new file mode 100644 index 00000000..1a800f6c --- /dev/null +++ b/pttbbs/util/splitpasswd.c @@ -0,0 +1,32 @@ +#include "bbs.h" +#include <err.h> + +int main(int argc, char **argv) +{ + userec_t xuser; + int fd, ufd; + char path[80], fn[80]; + + chdir(BBSHOME); + if( (fd = open(".PASSWDS", O_RDONLY)) < 0 ) + err(1, ".PASSWDS"); + + while( read(fd, &xuser, sizeof(xuser)) > 0 ){ + if( strcmp(xuser.userid, "in2") != 0 ) + continue; + sprintf(path, "home/%c/%s", xuser.userid[0], xuser.userid); + if( access(path, 0) < 0 ){ + printf("user home error (%s) (%s)\n", xuser.userid, path); + continue; + } + sprintf(fn, "%s/.passwd", path); + if( (ufd = open(fn, O_WRONLY | O_CREAT, 0600)) < 0 ){ + perror(path); + continue; + } + write(ufd, &xuser, sizeof(xuser)); + close(ufd); + } + + return 0; +} -- cgit v1.2.3 From d3be05c56346462572843525cf4deb305fb9701f Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Thu, 6 Jun 2002 21:42:47 +0000 Subject: fix bug git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@298 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/account.c | 5 +---- pttbbs/util/shmctl.c | 4 ++-- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/pttbbs/util/account.c b/pttbbs/util/account.c index cfc9f911..4512747f 100644 --- a/pttbbs/util/account.c +++ b/pttbbs/util/account.c @@ -1,4 +1,4 @@ -/* $Id: account.c,v 1.5 2002/06/06 21:34:14 in2 Exp $ */ +/* $Id: account.c,v 1.6 2002/06/06 21:42:47 in2 Exp $ */ #include "bbs.h" #define MAX_LINE 16 @@ -86,9 +86,6 @@ void gzip(source, target, stamp) system(buf); } -extern struct fromcache_t *fcache; -extern uhash_t *uhash; - int main() { int hour, max, item, total, i, j, mo, da, max_user = 0, max_login = 0, max_reg = 0, mahour = 0, k; diff --git a/pttbbs/util/shmctl.c b/pttbbs/util/shmctl.c index e264eb48..791926e7 100644 --- a/pttbbs/util/shmctl.c +++ b/pttbbs/util/shmctl.c @@ -1,4 +1,4 @@ -/* $Id: shmctl.c,v 1.19 2002/06/06 21:34:14 in2 Exp $ */ +/* $Id: shmctl.c,v 1.20 2002/06/06 21:42:47 in2 Exp $ */ #include "bbs.h" extern SHM_t *SHM; @@ -253,7 +253,7 @@ int utmpwatch(int argc, char **argv) int utmpnum(int argc, char **argv) { - printf("%d.0\n", SHM->number); + printf("%d.0\n", SHM->UTMPnumber); return 0; } -- cgit v1.2.3 From 1fe316169f4285a2dfe94ab02b8f1db1e93625a4 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Thu, 6 Jun 2002 21:45:16 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@299 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/UPDATING | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pttbbs/UPDATING b/pttbbs/UPDATING index 75812ec4..8b22e3b8 100644 --- a/pttbbs/UPDATING +++ b/pttbbs/UPDATING @@ -1,3 +1,9 @@ +Fri Jun 7 05:44:54 CST 2002 + only one shared memory + +Tue Jun 4 13:07:12 UTC 2002 + global variable move to var.c + Sun May 26 04:49:03 CST 2002 new userlist. -- cgit v1.2.3 From 37dd1b6926af6e8b339fbb8db1208ad9544f9f7f Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Fri, 7 Jun 2002 00:08:47 +0000 Subject: fix bugs for guest not logining when there're too few online users git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@300 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/cache.c | 50 +++++++++++++++++++++++++------------------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/pttbbs/mbbsd/cache.c b/pttbbs/mbbsd/cache.c index d2c47fe7..9ee6286b 100644 --- a/pttbbs/mbbsd/cache.c +++ b/pttbbs/mbbsd/cache.c @@ -1,4 +1,4 @@ -/* $Id: cache.c,v 1.32 2002/06/06 21:34:11 in2 Exp $ */ +/* $Id: cache.c,v 1.33 2002/06/07 00:08:47 in2 Exp $ */ #include "bbs.h" #ifndef __FreeBSD__ @@ -454,34 +454,34 @@ userinfo_t *search_ulist_pid(int pid) { } return 0; } -userinfo_t *search_ulistn(int uid, int unum) { - register int i=0, j, start = 0, end = SHM->UTMPnumber - 1; +userinfo_t *search_ulistn(int uid, int unum) +{ + register int i = 0, j, start = 0, end = SHM->UTMPnumber - 1; register userinfo_t **ulist; if( end == -1 ) return NULL; ulist=SHM->sorted[SHM->currsorted][6]; - for(i=((start+end)/2); ;i=(start+end)/2) - { - j= uid - ulist[i]->uid; - if(!j) - { - for(;i>0 && uid==ulist[i-1]->uid;i--);/* 指到第一筆 */ - if(uid==ulist[i+unum-1]->uid) - return (userinfo_t *) (ulist[i+unum-1]); - break; /* 超過範圍 */ - } - if(end==start) - { - break; - } - else if(i==start) - { - i=end; - start=end; - } - else if(j>0) start = i; - else end = i; - } + for( i = ((start + end) / 2) ; ; i = (start + end) / 2 ){ + j = uid - ulist[i]->uid; + if( j != 0 ){ + for( ; i > 0 && uid == ulist[i - 1]->uid ; --i ) + ; /* 指到第一筆 */ + if( ulist[i + unum - 1] 1= NULL && uid == ulist[i + num - 1]->uid ) + return (userinfo_t *)(ulist[i + unum - 1]); + break; /* 超過範圍 */ + } + if(end==start){ + break; + } + else if(i == start){ + i = end; + start = end; + } + else if( j > 0 ) + start = i; + else + end = i; + } return 0; } -- cgit v1.2.3 From dfb5acc3376ae597156cef2b4b7ff9e89a783382 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Fri, 7 Jun 2002 00:10:47 +0000 Subject: fix last commit bug git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@301 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/cache.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pttbbs/mbbsd/cache.c b/pttbbs/mbbsd/cache.c index 9ee6286b..1c22b0e3 100644 --- a/pttbbs/mbbsd/cache.c +++ b/pttbbs/mbbsd/cache.c @@ -1,4 +1,4 @@ -/* $Id: cache.c,v 1.33 2002/06/07 00:08:47 in2 Exp $ */ +/* $Id: cache.c,v 1.34 2002/06/07 00:10:47 in2 Exp $ */ #include "bbs.h" #ifndef __FreeBSD__ @@ -466,7 +466,7 @@ userinfo_t *search_ulistn(int uid, int unum) if( j != 0 ){ for( ; i > 0 && uid == ulist[i - 1]->uid ; --i ) ; /* 指到第一筆 */ - if( ulist[i + unum - 1] 1= NULL && uid == ulist[i + num - 1]->uid ) + if( ulist[i + unum - 1]!=NULL && uid==ulist[i + unum - 1]->uid ) return (userinfo_t *)(ulist[i + unum - 1]); break; /* 超過範圍 */ } @@ -798,7 +798,7 @@ int haspostperm(char *bname) { /* PTT cache */ /*-------------------------------------------------------*/ /* cachefor 動態看版 */ -static void reload_pttcache() +void reload_pttcache() { if( SHM->Pbusystate ) safe_sleep(1); -- cgit v1.2.3 From ea1d66481a47fc0eddd6d5becdbd66e8aed7312b Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Fri, 7 Jun 2002 04:10:02 +0000 Subject: fix last commit bug git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@302 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/cache.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pttbbs/mbbsd/cache.c b/pttbbs/mbbsd/cache.c index 1c22b0e3..309c8152 100644 --- a/pttbbs/mbbsd/cache.c +++ b/pttbbs/mbbsd/cache.c @@ -1,4 +1,4 @@ -/* $Id: cache.c,v 1.34 2002/06/07 00:10:47 in2 Exp $ */ +/* $Id: cache.c,v 1.35 2002/06/07 04:10:02 in2 Exp $ */ #include "bbs.h" #ifndef __FreeBSD__ @@ -463,7 +463,7 @@ userinfo_t *search_ulistn(int uid, int unum) ulist=SHM->sorted[SHM->currsorted][6]; for( i = ((start + end) / 2) ; ; i = (start + end) / 2 ){ j = uid - ulist[i]->uid; - if( j != 0 ){ + if( j == 0 ){ for( ; i > 0 && uid == ulist[i - 1]->uid ; --i ) ; /* 指到第一筆 */ if( ulist[i + unum - 1]!=NULL && uid==ulist[i + unum - 1]->uid ) -- cgit v1.2.3 From f0f2ea5c958a49f280a93abe3e7e5962a13fef26 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Fri, 7 Jun 2002 11:01:03 +0000 Subject: remove uhash_t git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@303 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/include/pttstruct.h | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/pttbbs/include/pttstruct.h b/pttbbs/include/pttstruct.h index a9c4db57..0f7e6d9c 100644 --- a/pttbbs/include/pttstruct.h +++ b/pttbbs/include/pttstruct.h @@ -1,4 +1,4 @@ -/* $Id: pttstruct.h,v 1.14 2002/06/06 21:34:09 in2 Exp $ */ +/* $Id: pttstruct.h,v 1.15 2002/06/07 11:01:03 in2 Exp $ */ #ifndef INCLUDE_STRUCT_H #define INCLUDE_STRUCT_H @@ -164,8 +164,6 @@ typedef struct fileheader_t { /* uhash is a userid->uid hash table -- jochang */ #define HASH_BITS 16 -typedef struct uhash_t { -} uhash_t; union xitem_t { struct { /* bbs_item */ -- cgit v1.2.3 From 8db2c94ea0318f8fc2a0696a3a9fd962121903a2 Mon Sep 17 00:00:00 2001 From: ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Fri, 7 Jun 2002 17:19:47 +0000 Subject: gamle and talk bug fix git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@304 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/gamble.c | 7 ++++--- pttbbs/mbbsd/talk.c | 6 +++--- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/pttbbs/mbbsd/gamble.c b/pttbbs/mbbsd/gamble.c index 541dd451..5409330d 100644 --- a/pttbbs/mbbsd/gamble.c +++ b/pttbbs/mbbsd/gamble.c @@ -1,4 +1,4 @@ -/* $Id: gamble.c,v 1.4 2002/06/04 13:08:33 in2 Exp $ */ +/* $Id: gamble.c,v 1.5 2002/06/07 17:19:47 ptt Exp $ */ #include "bbs.h" #ifndef _BBS_UTIL_C_ @@ -298,14 +298,14 @@ int openticket(int bid) { setbfile(buf, bh->brdname, FN_TICKET_END); unlink(buf); -/* if(fork()) { more(outcome,YEA); unlockutmpmode(); return 0; } -*/ + close(0); + close(1); sprintf(buf, "[公告] %s 賭盤開獎", bh->brdname); post_file(bh->brdname, buf, outcome, "[賭神]"); post_file("Record", buf+7, outcome, "[馬路探子]"); @@ -335,6 +335,7 @@ int openticket(int bid) { unlink(buf); setbfile(buf, bh->brdname, FN_TICKET_USER); unlink(buf); + exit(1); return 0; } diff --git a/pttbbs/mbbsd/talk.c b/pttbbs/mbbsd/talk.c index 90b39eab..51b318e5 100644 --- a/pttbbs/mbbsd/talk.c +++ b/pttbbs/mbbsd/talk.c @@ -1,4 +1,4 @@ -/* $Id: talk.c,v 1.69 2002/06/06 21:34:11 in2 Exp $ */ +/* $Id: talk.c,v 1.70 2002/06/07 17:19:47 ptt Exp $ */ #include "bbs.h" #define QCAST int (*)(const void *, const void *) @@ -2044,12 +2044,12 @@ static void userlist(void) ans, sizeof(ans), LCECHO) && *ans == 'n') break; - if( HAS_PERM(PERM_SYSOP) ){ + if( !(cuser.uflag & FRIEND_FLAG) && HAS_PERM(PERM_SYSOP) ){ for( i = 0 ; i < SHM->UTMPnumber && i<1000 ; ++i ){ uentp = SHM->sorted[SHM->currsorted][0][i]; if( uentp->pid && kill(uentp->pid, 0) != -1 ) my_write(uentp->pid, genbuf, - uentp->userid, 1, NULL); + uentp->userid, 1, NULL); } } else{ -- cgit v1.2.3 From 3beb6879f528c6cb904bc8afb03fb7b8a371b877 Mon Sep 17 00:00:00 2001 From: ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Fri, 7 Jun 2002 17:38:31 +0000 Subject: add log git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@305 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/gamble.c | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/pttbbs/mbbsd/gamble.c b/pttbbs/mbbsd/gamble.c index 5409330d..4b7b25a4 100644 --- a/pttbbs/mbbsd/gamble.c +++ b/pttbbs/mbbsd/gamble.c @@ -1,4 +1,4 @@ -/* $Id: gamble.c,v 1.5 2002/06/07 17:19:47 ptt Exp $ */ +/* $Id: gamble.c,v 1.6 2002/06/07 17:38:31 ptt Exp $ */ #include "bbs.h" #ifndef _BBS_UTIL_C_ @@ -292,37 +292,36 @@ int openticket(int bid) { Cdatelite(&now), betname[bet], total*price, money, total? (float)ticket[bet] / total:0); - fclose(fp); } fclose(fp1); setbfile(buf, bh->brdname, FN_TICKET_END); unlink(buf); if(fork()) - { + { // Ptt 用fork防止不正常斷線洗錢 + fclose(fp); more(outcome,YEA); + move(22,0); + prints("系統將於稍後自動把中獎結果公佈於看板 若參加者多會需要幾分鐘時間.."); unlockutmpmode(); return 0; } close(0); close(1); - sprintf(buf, "[公告] %s 賭盤開獎", bh->brdname); - post_file(bh->brdname, buf, outcome, "[賭神]"); - post_file("Record", buf+7, outcome, "[馬路探子]"); /* 以下是給錢動作 */ setbfile(buf, bh->brdname, FN_TICKET_USER); - if (ticket[bet] && (fp = fopen(buf, "r"))) + if (ticket[bet] && (fp1 = fopen(buf, "r"))) { int mybet, uid; char userid[IDLEN]; - while (fscanf(fp, "%s %d %d\n", userid, &mybet, &i) != EOF) + while (fscanf(fp1, "%s %d %d\n", userid, &mybet, &i) != EOF) { if (mybet == bet) { - printf("恭喜 %-15s買了%9d 張 %s, 獲得 %d 枚P幣\n" + fprintf(fp,"恭喜 %-15s買了%9d 張 %s, 獲得 %d 枚P幣\n" ,userid, i, betname[mybet], money * i); if((uid=getuser(userid))==0) continue; deumoney(uid, money * i); @@ -330,7 +329,14 @@ int openticket(int bid) { mail_id(userid, buf, outcome, "Ptt賭場"); } } + fclose(fp1); } + fclose(fp); + + sprintf(buf, "[公告] %s 賭盤開獎", bh->brdname); + post_file(bh->brdname, buf, outcome, "[賭神]"); + post_file("Record", buf+7, outcome, "[馬路探子]"); + setbfile(buf, bh->brdname, FN_TICKET_RECORD); unlink(buf); setbfile(buf, bh->brdname, FN_TICKET_USER); -- cgit v1.2.3 From f940a2f640f0806fc71698a4ca866fc66b402d39 Mon Sep 17 00:00:00 2001 From: ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Fri, 7 Jun 2002 17:45:38 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@306 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/gamble.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pttbbs/mbbsd/gamble.c b/pttbbs/mbbsd/gamble.c index 4b7b25a4..360f8a81 100644 --- a/pttbbs/mbbsd/gamble.c +++ b/pttbbs/mbbsd/gamble.c @@ -1,4 +1,4 @@ -/* $Id: gamble.c,v 1.6 2002/06/07 17:38:31 ptt Exp $ */ +/* $Id: gamble.c,v 1.7 2002/06/07 17:45:38 ptt Exp $ */ #include "bbs.h" #ifndef _BBS_UTIL_C_ @@ -299,10 +299,10 @@ int openticket(int bid) { unlink(buf); if(fork()) { // Ptt 用fork防止不正常斷線洗錢 - fclose(fp); - more(outcome,YEA); + //fclose(fp); move(22,0); - prints("系統將於稍後自動把中獎結果公佈於看板 若參加者多會需要幾分鐘時間.."); + prints("系統將於稍後自動把中獎結果公佈於看板 若參加者多會需要幾分鐘時間.."); + pressanykey(); unlockutmpmode(); return 0; } -- cgit v1.2.3 From 4c6d875265d53376f0d363ad4b60ef73b9ae3211 Mon Sep 17 00:00:00 2001 From: ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Fri, 7 Jun 2002 17:54:17 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@307 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/gamble.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/pttbbs/mbbsd/gamble.c b/pttbbs/mbbsd/gamble.c index 360f8a81..9337d569 100644 --- a/pttbbs/mbbsd/gamble.c +++ b/pttbbs/mbbsd/gamble.c @@ -1,4 +1,4 @@ -/* $Id: gamble.c,v 1.7 2002/06/07 17:45:38 ptt Exp $ */ +/* $Id: gamble.c,v 1.8 2002/06/07 17:54:17 ptt Exp $ */ #include "bbs.h" #ifndef _BBS_UTIL_C_ @@ -299,7 +299,6 @@ int openticket(int bid) { unlink(buf); if(fork()) { // Ptt 用fork防止不正常斷線洗錢 - //fclose(fp); move(22,0); prints("系統將於稍後自動把中獎結果公佈於看板 若參加者多會需要幾分鐘時間.."); pressanykey(); @@ -326,7 +325,7 @@ int openticket(int bid) { if((uid=getuser(userid))==0) continue; deumoney(uid, money * i); sprintf(buf, "%s 中獎咧! $ %d", bh->brdname, money * i); - mail_id(userid, buf, outcome, "Ptt賭場"); + mail_id(userid, buf, "etc/ticket.win", "Ptt賭場"); } } fclose(fp1); -- cgit v1.2.3 From 0efa4ed32b3f95c551e274900dbbc36900722149 Mon Sep 17 00:00:00 2001 From: ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Fri, 7 Jun 2002 18:42:52 +0000 Subject: add revoke gamble git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@308 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/gamble.c | 63 +++++++++++++++++++++++++++++++++++---------------- 1 file changed, 43 insertions(+), 20 deletions(-) diff --git a/pttbbs/mbbsd/gamble.c b/pttbbs/mbbsd/gamble.c index 9337d569..c3229bfe 100644 --- a/pttbbs/mbbsd/gamble.c +++ b/pttbbs/mbbsd/gamble.c @@ -1,4 +1,4 @@ -/* $Id: gamble.c,v 1.8 2002/06/07 17:54:17 ptt Exp $ */ +/* $Id: gamble.c,v 1.9 2002/06/07 18:42:52 ptt Exp $ */ #include "bbs.h" #ifndef _BBS_UTIL_C_ @@ -237,14 +237,15 @@ int openticket(int bid) { { do { - getdata(20, 0, "\033[1m選擇中獎的號碼(0:取消)\033[m:", buf, 3, LCECHO); + getdata(20, 0, + "\033[1m選擇中獎的號碼(0:不開獎 99:取消退錢)\033[m:", buf, 3, LCECHO); bet=atoi(buf); move(0,0); clrtoeol(); - } while(bet<0 || bet>count); + } while( (bet<0 || bet>count) && bet!=99); if(bet==0) {unlockutmpmode(); return 0;} - getdata(21, 0, "\033[1m再次確認中獎的號碼\033[m:", buf, 3, LCECHO); + getdata(21, 0, "\033[1m再次確認輸入號碼\033[m:", buf, 3, LCECHO); }while(bet!=atoi(buf)); bet -= 1; //轉成矩陣的index @@ -257,10 +258,18 @@ int openticket(int bid) { return 0; } // 還沒開完獎不能賭博 只要mv一項就好 - money=total*price; - demoney(money*0.02); - mail_redenvelop("[賭場抽頭]", cuser.userid, money*0.02, 'n'); - money = ticket[bet] ? money*0.95/ticket[bet]:9999999; + if(bet!=98) + { + money=total*price; + demoney(money*0.02); + mail_redenvelop("[賭場抽頭]", cuser.userid, money*0.02, 'n'); + money = ticket[bet] ? money*0.95/ticket[bet]:9999999; + } + else + { + vice(price*10, "賭盤退錢手續費"); + money=price; + } setbfile(outcome,bh->brdname,FN_TICKET_OUTCOME); if((fp = fopen(outcome, "w"))) { @@ -279,8 +288,10 @@ int openticket(int bid) { if(i==3) fprintf(fp,"\n"); } fprintf(fp, "\033[m\n"); - - fprintf(fp, "\n\n開獎時間: %s \n\n" + + if(bet!=98) + { + fprintf(fp, "\n\n開獎時間: %s \n\n" "開獎結果: %s \n\n" "所有金額: %d 元 \n" "中獎比例: %d張/%d張 (%f)\n" @@ -288,9 +299,12 @@ int openticket(int bid) { Cdatelite(&now), betname[bet], total*price, ticket[bet], total, (float) ticket[bet] / total, money); - fprintf(fp, "%s 賭盤開出:%s 所有金額:%d 元 獎金/張:%d 元 機率:%1.2f\n", + fprintf(fp, "%s 賭盤開出:%s 所有金額:%d 元 獎金/張:%d 元 機率:%1.2f\n", Cdatelite(&now), betname[bet], total*price, money, total? (float)ticket[bet] / total:0); + } + else + fprintf(fp, "\n\n賭盤取消退錢: %s \n\n"); } fclose(fp1); @@ -311,28 +325,37 @@ int openticket(int bid) { 以下是給錢動作 */ setbfile(buf, bh->brdname, FN_TICKET_USER); - if (ticket[bet] && (fp1 = fopen(buf, "r"))) + if ((bet==98 || ticket[bet]) && (fp1 = fopen(buf, "r"))) { int mybet, uid; char userid[IDLEN]; while (fscanf(fp1, "%s %d %d\n", userid, &mybet, &i) != EOF) { - if (mybet == bet) + if (bet==98 ) + { + fprintf(fp,"%s 買了 %d 張 %s, 退回 %d 枚P幣\n" + ,userid, i, betname[mybet], money); + sprintf(buf, "%s 賭場退錢! $ %d", bh->brdname, money * i); + } + else if (mybet == bet) { - fprintf(fp,"恭喜 %-15s買了%9d 張 %s, 獲得 %d 枚P幣\n" - ,userid, i, betname[mybet], money * i); - if((uid=getuser(userid))==0) continue; - deumoney(uid, money * i); + fprintf(fp,"恭喜 %s 買了%d 張 %s, 獲得 %d 枚P幣\n" + ,userid, i, betname[mybet], money); sprintf(buf, "%s 中獎咧! $ %d", bh->brdname, money * i); - mail_id(userid, buf, "etc/ticket.win", "Ptt賭場"); - } + } + if((uid=getuser(userid))==0) continue; + deumoney(uid, money * i); + mail_id(userid, buf, "etc/ticket.win", "Ptt賭場"); } fclose(fp1); } fclose(fp); - sprintf(buf, "[公告] %s 賭盤開獎", bh->brdname); + if(bet!=98) + sprintf(buf, "[公告] %s 賭盤開獎", bh->brdname); + else + sprintf(buf, "[公告] %s 賭盤取消", bh->brdname); post_file(bh->brdname, buf, outcome, "[賭神]"); post_file("Record", buf+7, outcome, "[馬路探子]"); -- cgit v1.2.3 From c29a79e533fd9b37c62d4be9e601d2e927e65751 Mon Sep 17 00:00:00 2001 From: ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Fri, 7 Jun 2002 18:47:40 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@309 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/gamble.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pttbbs/mbbsd/gamble.c b/pttbbs/mbbsd/gamble.c index c3229bfe..253c6682 100644 --- a/pttbbs/mbbsd/gamble.c +++ b/pttbbs/mbbsd/gamble.c @@ -1,4 +1,4 @@ -/* $Id: gamble.c,v 1.9 2002/06/07 18:42:52 ptt Exp $ */ +/* $Id: gamble.c,v 1.10 2002/06/07 18:47:40 ptt Exp $ */ #include "bbs.h" #ifndef _BBS_UTIL_C_ @@ -304,7 +304,7 @@ int openticket(int bid) { total? (float)ticket[bet] / total:0); } else - fprintf(fp, "\n\n賭盤取消退錢: %s \n\n"); + fprintf(fp, "\n\n賭盤取消退錢: %s \n\n", Cdatelite(&now)); } fclose(fp1); -- cgit v1.2.3 From 7d0c4a3548159588c9f4cca28bceea40dbfea76f Mon Sep 17 00:00:00 2001 From: ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Fri, 7 Jun 2002 18:54:52 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@310 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/bbs.c | 4 ++-- pttbbs/mbbsd/gamble.c | 29 ++++++++++++++--------------- 2 files changed, 16 insertions(+), 17 deletions(-) diff --git a/pttbbs/mbbsd/bbs.c b/pttbbs/mbbsd/bbs.c index 6b08d1db..f6877570 100644 --- a/pttbbs/mbbsd/bbs.c +++ b/pttbbs/mbbsd/bbs.c @@ -1,4 +1,4 @@ -/* $Id: bbs.c,v 1.49 2002/06/06 21:34:11 in2 Exp $ */ +/* $Id: bbs.c,v 1.50 2002/06/07 18:54:52 ptt Exp $ */ #include "bbs.h" static void mail_by_link(char* owner, char* title, char* path) { @@ -974,7 +974,7 @@ static int hold_gamble(int ent, fileheader_t *fhdr, char *direct) { if(dashf(fn_ticket_end)) { getdata(b_lines - 1, 0, "已經有舉辦賭盤, " - "是否要 [開獎]?(N/y):", yn, 3, LCECHO); + "是否要 [開獎/取消]?(N/y):", yn, 3, LCECHO); if(yn[0]!='y') return FULLUPDATE; openticket(currbid); return FULLUPDATE; diff --git a/pttbbs/mbbsd/gamble.c b/pttbbs/mbbsd/gamble.c index 253c6682..a73460f9 100644 --- a/pttbbs/mbbsd/gamble.c +++ b/pttbbs/mbbsd/gamble.c @@ -1,4 +1,4 @@ -/* $Id: gamble.c,v 1.10 2002/06/07 18:47:40 ptt Exp $ */ +/* $Id: gamble.c,v 1.11 2002/06/07 18:54:52 ptt Exp $ */ #include "bbs.h" #ifndef _BBS_UTIL_C_ @@ -248,15 +248,24 @@ int openticket(int bid) { getdata(21, 0, "\033[1m再次確認輸入號碼\033[m:", buf, 3, LCECHO); }while(bet!=atoi(buf)); + if(fork()) + { // Ptt 用fork防止不正常斷線洗錢 + move(22,0); + prints("系統將於稍後自動把中獎結果公佈於看板 若參加者多會需要幾分鐘時間.."); + pressanykey(); + unlockutmpmode(); + return 0; + } + close(0); + close(1); + bet -= 1; //轉成矩陣的index total=load_ticket_record(path, ticket); setbfile(buf,bh->brdname,FN_TICKET_END); if(!(fp1 = fopen(buf,"r"))) - { - unlockutmpmode(); - return 0; - } + exit(1); + // 還沒開完獎不能賭博 只要mv一項就好 if(bet!=98) { @@ -311,16 +320,6 @@ int openticket(int bid) { setbfile(buf, bh->brdname, FN_TICKET_END); unlink(buf); - if(fork()) - { // Ptt 用fork防止不正常斷線洗錢 - move(22,0); - prints("系統將於稍後自動把中獎結果公佈於看板 若參加者多會需要幾分鐘時間.."); - pressanykey(); - unlockutmpmode(); - return 0; - } - close(0); - close(1); /* 以下是給錢動作 */ -- cgit v1.2.3 From d3776f2bd3beeedaa25ce824bf1adf6598b0e2d9 Mon Sep 17 00:00:00 2001 From: ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Fri, 7 Jun 2002 19:03:25 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@311 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/gamble.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pttbbs/mbbsd/gamble.c b/pttbbs/mbbsd/gamble.c index a73460f9..065b05b4 100644 --- a/pttbbs/mbbsd/gamble.c +++ b/pttbbs/mbbsd/gamble.c @@ -1,4 +1,4 @@ -/* $Id: gamble.c,v 1.11 2002/06/07 18:54:52 ptt Exp $ */ +/* $Id: gamble.c,v 1.12 2002/06/07 19:03:25 ptt Exp $ */ #include "bbs.h" #ifndef _BBS_UTIL_C_ @@ -347,9 +347,10 @@ int openticket(int bid) { deumoney(uid, money * i); mail_id(userid, buf, "etc/ticket.win", "Ptt賭場"); } - fclose(fp1); } + fclose(fp); + fclose(fp1); if(bet!=98) sprintf(buf, "[公告] %s 賭盤開獎", bh->brdname); -- cgit v1.2.3 From 6bd8aa4474c4291eed6490ec8ba13b0d16a8fe01 Mon Sep 17 00:00:00 2001 From: ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Fri, 7 Jun 2002 19:10:10 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@312 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/gamble.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/pttbbs/mbbsd/gamble.c b/pttbbs/mbbsd/gamble.c index 065b05b4..69127e1e 100644 --- a/pttbbs/mbbsd/gamble.c +++ b/pttbbs/mbbsd/gamble.c @@ -1,4 +1,4 @@ -/* $Id: gamble.c,v 1.12 2002/06/07 19:03:25 ptt Exp $ */ +/* $Id: gamble.c,v 1.13 2002/06/07 19:10:10 ptt Exp $ */ #include "bbs.h" #ifndef _BBS_UTIL_C_ @@ -49,8 +49,9 @@ int post_file(char* bname, char* title, char *filename, char* author) if(size<=0) return -1; if(!(fp=fopen(filename,"r")) ) return -1; - msg= (char *)malloc(size); - fread(msg,1,size,fp); + msg= (char *)malloc(size+1); + size = fread(msg,1,size,fp); + msg[size]=0; size= post_msg(bname, title, msg, author); fclose(fp); free(msg); -- cgit v1.2.3 From acb38e72d8f4cb39f7cb81edce8b5e270528b383 Mon Sep 17 00:00:00 2001 From: ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Fri, 7 Jun 2002 19:12:11 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@313 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/gamble.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pttbbs/mbbsd/gamble.c b/pttbbs/mbbsd/gamble.c index 69127e1e..ce33e40d 100644 --- a/pttbbs/mbbsd/gamble.c +++ b/pttbbs/mbbsd/gamble.c @@ -1,4 +1,4 @@ -/* $Id: gamble.c,v 1.13 2002/06/07 19:10:10 ptt Exp $ */ +/* $Id: gamble.c,v 1.14 2002/06/07 19:12:11 ptt Exp $ */ #include "bbs.h" #ifndef _BBS_UTIL_C_ @@ -309,7 +309,7 @@ int openticket(int bid) { Cdatelite(&now), betname[bet], total*price, ticket[bet], total, (float) ticket[bet] / total, money); - fprintf(fp, "%s 賭盤開出:%s 所有金額:%d 元 獎金/張:%d 元 機率:%1.2f\n", + fprintf(fp, "%s 賭盤開出:%s 所有金額:%d 元 獎金/張:%d 元 機率:%1.2f\n\n", Cdatelite(&now), betname[bet], total*price, money, total? (float)ticket[bet] / total:0); } -- cgit v1.2.3 From 0f75e66bab4c1d39e5bb649efea489d8444ae8c2 Mon Sep 17 00:00:00 2001 From: lwms <lwms@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sun, 9 Jun 2002 04:28:10 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@314 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/bbs.c | 13 ++++++++++--- pttbbs/mbbsd/read.c | 6 +++++- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/pttbbs/mbbsd/bbs.c b/pttbbs/mbbsd/bbs.c index f6877570..dd100900 100644 --- a/pttbbs/mbbsd/bbs.c +++ b/pttbbs/mbbsd/bbs.c @@ -1,4 +1,4 @@ -/* $Id: bbs.c,v 1.50 2002/06/07 18:54:52 ptt Exp $ */ +/* $Id: bbs.c,v 1.51 2002/06/09 04:27:50 lwms Exp $ */ #include "bbs.h" static void mail_by_link(char* owner, char* title, char* path) { @@ -659,6 +659,9 @@ static int edit_post(int ent, fileheader_t *fhdr, char *direct) { fileheader_t postfile; boardheader_t *bp; bp = getbcache(currbid); + if ( strcmp(bp->brdname, "Security" ) == 0 ) + return DONOTHING; + if (!HAS_PERM(PERM_SYSOP) && (bp->brdattr & BRD_VOTEBOARD)) return DONOTHING; @@ -1163,6 +1166,8 @@ static int mark_post(int ent, fileheader_t *fhdr, char *direct) { int del_range(int ent, fileheader_t *fhdr, char *direct) { char num1[8], num2[8]; int inum1, inum2; + boardheader_t *bp; + bp = getbcache(currbid); /* rocker.011018: 串接模式下還是不允許刪除比較好 */ if(currmode & MODE_SELECT) { @@ -1171,7 +1176,8 @@ int del_range(int ent, fileheader_t *fhdr, char *direct) { /*safe_sleep(1);*/ return FULLUPDATE; } - + if ( strcmp( bp->brdname, "Security") == 0 ) + return DONOTHING; if((currstat != READING) || (currmode & MODE_BOARD)) { getdata(1, 0, "[設定刪除範圍] 起點:", num1, 5, DOECHO); inum1 = atoi(num1); @@ -1238,7 +1244,8 @@ static int del_post(int ent, fileheader_t *fhdr, char *direct) { boardheader_t *bp; bp = getbcache(currbid); - + if ( strcmp(bp->brdname, "Security") == 0 ) + return DONOTHING; if((fhdr->filemode & FILE_MARKED) || (fhdr->filemode & FILE_DIGEST) || (fhdr->owner[0] == '-')) return DONOTHING; diff --git a/pttbbs/mbbsd/read.c b/pttbbs/mbbsd/read.c index 7e598f53..57671882 100644 --- a/pttbbs/mbbsd/read.c +++ b/pttbbs/mbbsd/read.c @@ -1,4 +1,4 @@ -/* $Id: read.c,v 1.4 2002/06/04 13:08:34 in2 Exp $ */ +/* $Id: read.c,v 1.5 2002/06/09 04:28:10 lwms Exp $ */ #include "bbs.h" #define MAXPATHLEN 256 @@ -180,6 +180,10 @@ TagThread(char *direct) int TagPruner(int bid) { + boardheader_t *bp; + bp = getbcache(bid); + if ( strcmp(bp->brdname, "Security" ) == 0 ) + return DONOTHING; if (TagNum && ((currstat != READING) || (currmode & MODE_BOARD))) { if(getans("刪除所有標記[N]?") != 'y') -- cgit v1.2.3 From a8d5fdbb1fac903a92f0ceb4de0d0fad0334e2f7 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sun, 9 Jun 2002 12:51:07 +0000 Subject: fix bug git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@315 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/util_cache.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pttbbs/util/util_cache.c b/pttbbs/util/util_cache.c index 7f4b0897..4a53cd2c 100644 --- a/pttbbs/util/util_cache.c +++ b/pttbbs/util/util_cache.c @@ -1,4 +1,4 @@ -/* $Id: util_cache.c,v 1.3 2002/06/06 21:34:15 in2 Exp $ */ +/* $Id: util_cache.c,v 1.4 2002/06/09 12:51:07 in2 Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -328,7 +328,7 @@ void resolve_boards() { while(SHM->Buptime < SHM->Btouchtime) reload_bcache(); - numboards = SHM->number; + numboards = SHM->Bnumber; } void touch_boards() { -- cgit v1.2.3 From bb40965c4ab0f000e2360737186aeb1a90921200 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sun, 9 Jun 2002 12:51:26 +0000 Subject: fix redirect bug git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@316 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/inndBM.c | 35 +++++++++++++++-------------------- 1 file changed, 15 insertions(+), 20 deletions(-) diff --git a/pttbbs/util/inndBM.c b/pttbbs/util/inndBM.c index 17b6ce87..52092434 100644 --- a/pttbbs/util/inndBM.c +++ b/pttbbs/util/inndBM.c @@ -9,8 +9,6 @@ #define INND_BADFEED INNDHOME "/badfeeds.bbs" #define INND_SCRIPT INNDHOME "/bbsnnrpall.auto.sh" -extern boardheader_t *bcache; -extern int numboards; int istran[MAX_BOARD]; typedef @@ -109,32 +107,29 @@ int load_newsfeeds() qsort(feedline, feedcount, sizeof(newsfeed_t), newsfeed_cmp); return feedcount; } + int dobbsnnrp(char *serverstr, int serverid,FILE *fpscript) { - char buf[256]; - printf("set %s\r\n",serverstr); - strtok(serverstr,";\r\n"); - strtok(server[serverid].address,";\r\n"); //防hack - sprintf(buf,INNDHOME"/bbsnnrp -c %s " - INNDHOME"/active/%s.auto.active >>" - INNDHOME"/log/inndBM.log 2>>" - INNDHOME"/log/inndBM.log.err &\r\n", - server[serverid].address, - serverstr); - system(buf); - if(fpscript) - fprintf(fpscript,INNDHOME"/bbsnnrp %s " - INNDHOME"/active/%s.auto.active >>" - INNDHOME"/log/inndBM.log 2>>" - INNDHOME"/log/inndBM.log.err &\r\n", - server[serverid].address,serverstr); - return 0; + char buf[256]; + printf("set %s\r\n",serverstr); + strtok(serverstr,";\r\n"); + strtok(server[serverid].address,";\r\n"); //防hack + sprintf(buf, INNDHOME"/bbsnnrp -c %s " + INNDHOME "/active/%s.auto.active " + " >> " INNDHOME"/log/inndBM.log &", + server[serverid].address, + serverstr); + system(buf); + if(fpscript) + fprintf(fpscript, buf); + return 0; } int main() { int i,serverid=0; FILE *fp=NULL,*fpscript=fopen(INND_SCRIPT,"w"); char buf[256],serverstr[30]=""; + chdir(BBSHOME "/innd"); resolve_boards(); memset(istran,0,sizeof(int)*MAX_BOARD); load_server(); -- cgit v1.2.3 From 851e1083e1b595ed0f8c3578a18c41041dc7b9f0 Mon Sep 17 00:00:00 2001 From: lwms <lwms@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Mon, 10 Jun 2002 13:12:08 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@317 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/openticket.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/pttbbs/util/openticket.c b/pttbbs/util/openticket.c index 33a8a54f..2b2fc884 100644 --- a/pttbbs/util/openticket.c +++ b/pttbbs/util/openticket.c @@ -1,4 +1,4 @@ -/* $Id: openticket.c,v 1.4 2002/06/06 21:34:14 in2 Exp $ */ +/* $Id: openticket.c,v 1.5 2002/06/10 13:12:08 lwms Exp $ */ /* 開獎的 utility */ #include "bbs.h" @@ -67,11 +67,10 @@ int main() fclose(fp); } -/* - *srandom(33); // 固定一個 seed 但盡量要避免跟別人的seed同 - * - *for( n = (now / (60*60*3)) - 62820; n >0; n--) random(); - */ + srandom(33); // 固定一個 seed 但盡量要避免跟別人的seed同 + + for( n = (now / (60*60*3)) - 62820; n >0; n--) random(); + /* * 正確的random number generator的用法 -- cgit v1.2.3 From 81a7137d1186690d381470c507425d9eb814d92e Mon Sep 17 00:00:00 2001 From: lwms <lwms@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Tue, 11 Jun 2002 04:09:31 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@318 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/openticket.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pttbbs/util/openticket.c b/pttbbs/util/openticket.c index 2b2fc884..7c31f531 100644 --- a/pttbbs/util/openticket.c +++ b/pttbbs/util/openticket.c @@ -1,4 +1,4 @@ -/* $Id: openticket.c,v 1.5 2002/06/10 13:12:08 lwms Exp $ */ +/* $Id: openticket.c,v 1.6 2002/06/11 04:09:31 lwms Exp $ */ /* 開獎的 utility */ #include "bbs.h" @@ -87,9 +87,9 @@ int main() * * ~Ptt */ -/* - *bet=random() % 8; - */ + + bet=random() % 8; + resolve_utmp(); bet = SHM->number % 8; -- cgit v1.2.3 From 441cef73089db2cad6b92f71cedf02ecbd4dff08 Mon Sep 17 00:00:00 2001 From: ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Wed, 12 Jun 2002 11:33:46 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@319 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/gamble.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/pttbbs/mbbsd/gamble.c b/pttbbs/mbbsd/gamble.c index ce33e40d..fbd06ab0 100644 --- a/pttbbs/mbbsd/gamble.c +++ b/pttbbs/mbbsd/gamble.c @@ -1,4 +1,4 @@ -/* $Id: gamble.c,v 1.14 2002/06/07 19:12:11 ptt Exp $ */ +/* $Id: gamble.c,v 1.15 2002/06/12 11:33:46 ptt Exp $ */ #include "bbs.h" #ifndef _BBS_UTIL_C_ @@ -309,11 +309,11 @@ int openticket(int bid) { Cdatelite(&now), betname[bet], total*price, ticket[bet], total, (float) ticket[bet] / total, money); - fprintf(fp, "%s 賭盤開出:%s 所有金額:%d 元 獎金/張:%d 元 機率:%1.2f\n\n", + fprintf(fp, "%s 賭盤開出:%s 所有金額:%d 元 獎金/張:%d 元 機率:%1.2f\n\n", Cdatelite(&now), betname[bet], total*price, money, total? (float)ticket[bet] / total:0); } - else + else fprintf(fp, "\n\n賭盤取消退錢: %s \n\n", Cdatelite(&now)); } @@ -344,6 +344,8 @@ int openticket(int bid) { ,userid, i, betname[mybet], money); sprintf(buf, "%s 中獎咧! $ %d", bh->brdname, money * i); } + else + continue; if((uid=getuser(userid))==0) continue; deumoney(uid, money * i); mail_id(userid, buf, "etc/ticket.win", "Ptt賭場"); -- cgit v1.2.3 From 5971bd7da24deff8e6b4658a3ab1e43619c374dc Mon Sep 17 00:00:00 2001 From: ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Wed, 12 Jun 2002 11:44:41 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@320 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/bbs.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pttbbs/mbbsd/bbs.c b/pttbbs/mbbsd/bbs.c index dd100900..0656c19d 100644 --- a/pttbbs/mbbsd/bbs.c +++ b/pttbbs/mbbsd/bbs.c @@ -1,4 +1,4 @@ -/* $Id: bbs.c,v 1.51 2002/06/09 04:27:50 lwms Exp $ */ +/* $Id: bbs.c,v 1.52 2002/06/12 11:44:41 ptt Exp $ */ #include "bbs.h" static void mail_by_link(char* owner, char* title, char* path) { @@ -953,6 +953,7 @@ static int b_man() { #ifndef NO_GAMBLE static int join_gamble(int ent, fileheader_t *fhdr, char *direct) { + if(!HAS_PERM(PERM_LOGINOK)) return DONOTHING; ticket(currbid); return FULLUPDATE; } -- cgit v1.2.3 From e25c9af1638ebb3efae3dbe208a37d6d65dd1b61 Mon Sep 17 00:00:00 2001 From: lwms <lwms@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Wed, 12 Jun 2002 12:27:04 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@321 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/inndBM.c | 2 +- pttbbs/util/openticket.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pttbbs/util/inndBM.c b/pttbbs/util/inndBM.c index 52092434..110d1ab2 100644 --- a/pttbbs/util/inndBM.c +++ b/pttbbs/util/inndBM.c @@ -116,7 +116,7 @@ int dobbsnnrp(char *serverstr, int serverid,FILE *fpscript) strtok(server[serverid].address,";\r\n"); //防hack sprintf(buf, INNDHOME"/bbsnnrp -c %s " INNDHOME "/active/%s.auto.active " - " >> " INNDHOME"/log/inndBM.log &", + " >> " INNDHOME"/log/inndBM.log &\n", server[serverid].address, serverstr); system(buf); diff --git a/pttbbs/util/openticket.c b/pttbbs/util/openticket.c index 7c31f531..4d1af5b4 100644 --- a/pttbbs/util/openticket.c +++ b/pttbbs/util/openticket.c @@ -1,4 +1,4 @@ -/* $Id: openticket.c,v 1.6 2002/06/11 04:09:31 lwms Exp $ */ +/* $Id: openticket.c,v 1.7 2002/06/12 12:27:04 lwms Exp $ */ /* 開獎的 utility */ #include "bbs.h" @@ -92,7 +92,7 @@ int main() resolve_utmp(); - bet = SHM->number % 8; + bet = SHM->UTMPnumber % 8; /* -- cgit v1.2.3 From a73f6da4bd876114160461b15aa63a15ea42806e Mon Sep 17 00:00:00 2001 From: ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Wed, 12 Jun 2002 12:44:09 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@322 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/inndBM.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pttbbs/util/inndBM.c b/pttbbs/util/inndBM.c index 110d1ab2..2e300a20 100644 --- a/pttbbs/util/inndBM.c +++ b/pttbbs/util/inndBM.c @@ -116,10 +116,15 @@ int dobbsnnrp(char *serverstr, int serverid,FILE *fpscript) strtok(server[serverid].address,";\r\n"); //防hack sprintf(buf, INNDHOME"/bbsnnrp -c %s " INNDHOME "/active/%s.auto.active " - " >> " INNDHOME"/log/inndBM.log &\n", + " >> " INNDHOME"/log/inndBM.log &\r\n", server[serverid].address, serverstr); system(buf); + sprintf(buf, INNDHOME"/bbsnnrp %s " + INNDHOME "/active/%s.auto.active " + " >> " INNDHOME"/log/inndBM.log &\r\n", + server[serverid].address, + serverstr); if(fpscript) fprintf(fpscript, buf); return 0; -- cgit v1.2.3 From b3a2405e063a320d8ef08ade53a62946a393c1f2 Mon Sep 17 00:00:00 2001 From: lwms <lwms@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Thu, 13 Jun 2002 03:24:09 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@323 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/inndBM.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pttbbs/util/inndBM.c b/pttbbs/util/inndBM.c index 2e300a20..1e0fa6ad 100644 --- a/pttbbs/util/inndBM.c +++ b/pttbbs/util/inndBM.c @@ -114,7 +114,7 @@ int dobbsnnrp(char *serverstr, int serverid,FILE *fpscript) printf("set %s\r\n",serverstr); strtok(serverstr,";\r\n"); strtok(server[serverid].address,";\r\n"); //防hack - sprintf(buf, INNDHOME"/bbsnnrp -c %s " + sprintf(buf, INNDHOME"/bbsnnrp %s " INNDHOME "/active/%s.auto.active " " >> " INNDHOME"/log/inndBM.log &\r\n", server[serverid].address, -- cgit v1.2.3 From d72103b1c615b6d5dbeadf33b023377c80c50a9d Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Thu, 13 Jun 2002 15:10:50 +0000 Subject: fix bug (UTMPnumber) git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@324 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/shmctl.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pttbbs/util/shmctl.c b/pttbbs/util/shmctl.c index 791926e7..adf08640 100644 --- a/pttbbs/util/shmctl.c +++ b/pttbbs/util/shmctl.c @@ -1,4 +1,4 @@ -/* $Id: shmctl.c,v 1.20 2002/06/06 21:42:47 in2 Exp $ */ +/* $Id: shmctl.c,v 1.21 2002/06/13 15:10:50 in2 Exp $ */ #include "bbs.h" extern SHM_t *SHM; @@ -127,7 +127,7 @@ int utmpstate(int argc, char **argv) printf("now: %s\n", nowbuf); printf("currsorted: %d\n", SHM->currsorted); printf("uptime: %s\n", upbuf); - printf("number: %d\n", SHM->number); + printf("number: %d\n", SHM->UTMPnumber); printf("busystate: %d\n", SHM->UTMPbusystate); return 0; } -- cgit v1.2.3 From 8f6ad44ce0957da09faf730a208ba5883cd21c6b Mon Sep 17 00:00:00 2001 From: ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sun, 16 Jun 2002 22:03:05 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@325 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/mandex.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pttbbs/util/mandex.c b/pttbbs/util/mandex.c index 8b073ea2..f9e1198c 100644 --- a/pttbbs/util/mandex.c +++ b/pttbbs/util/mandex.c @@ -1,4 +1,4 @@ -/* $Id: mandex.c,v 1.4 2002/06/06 21:34:14 in2 Exp $ */ +/* $Id: mandex.c,v 1.5 2002/06/16 22:03:05 ptt Exp $ */ /* 'mandex -h' to help */ @@ -187,14 +187,14 @@ int main(int argc, char* argv[]) argv += optind; resolve_boards(); - +/* if( argc == 0 ){ puts("Creating the whole index..."); chdir(strcpy(topdir, BBSHOME)); strcpy(fpath, "man/.DIR"); mandex(0, "", fpath); } - +*/ chdir(strcpy(topdir, BBSHOME "/man/boards")); if( argc == 1 ){ -- cgit v1.2.3 From c5ea640275c8d0566ff943301b036c87062a3499 Mon Sep 17 00:00:00 2001 From: ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sun, 16 Jun 2002 22:21:12 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@326 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/account.c | 3 ++- pttbbs/util/mandex.c | 3 ++- pttbbs/util/openticket.c | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/pttbbs/util/account.c b/pttbbs/util/account.c index 4512747f..5220f713 100644 --- a/pttbbs/util/account.c +++ b/pttbbs/util/account.c @@ -1,4 +1,4 @@ -/* $Id: account.c,v 1.6 2002/06/06 21:42:47 in2 Exp $ */ +/* $Id: account.c,v 1.7 2002/06/16 22:21:12 ptt Exp $ */ #include "bbs.h" #define MAX_LINE 16 @@ -97,6 +97,7 @@ int main() { time_t now; struct tm *ptime; + nice(10); chdir(BBSHOME); now = time(NULL) - ADJUST_M * 60; /* back to ancent */ ptime = localtime(&now); diff --git a/pttbbs/util/mandex.c b/pttbbs/util/mandex.c index f9e1198c..3eb6c05a 100644 --- a/pttbbs/util/mandex.c +++ b/pttbbs/util/mandex.c @@ -1,4 +1,4 @@ -/* $Id: mandex.c,v 1.5 2002/06/16 22:03:05 ptt Exp $ */ +/* $Id: mandex.c,v 1.6 2002/06/16 22:21:12 ptt Exp $ */ /* 'mandex -h' to help */ @@ -165,6 +165,7 @@ int main(int argc, char* argv[]) 'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', 'Z', 'X', 'C', 'V', 'B', 'N', 'M', NULL}; + nice(10); while( (ch = getopt(argc, argv, "xh")) != -1 ){ switch( ch ){ case 'x': diff --git a/pttbbs/util/openticket.c b/pttbbs/util/openticket.c index 4d1af5b4..643c55fb 100644 --- a/pttbbs/util/openticket.c +++ b/pttbbs/util/openticket.c @@ -1,4 +1,4 @@ -/* $Id: openticket.c,v 1.7 2002/06/12 12:27:04 lwms Exp $ */ +/* $Id: openticket.c,v 1.8 2002/06/16 22:21:12 ptt Exp $ */ /* 開獎的 utility */ #include "bbs.h" @@ -41,6 +41,7 @@ int main() char des[MAX_DES][200] = {"", "", "", ""}; + nice(10); if(passwd_mmap()) exit(1); -- cgit v1.2.3 From 4a6f166842c5983104a37a1153450046e6abc7e8 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Mon, 17 Jun 2002 09:14:42 +0000 Subject: fix register bug git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@327 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/admin.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/pttbbs/mbbsd/admin.c b/pttbbs/mbbsd/admin.c index 48e21777..a8008a6c 100644 --- a/pttbbs/mbbsd/admin.c +++ b/pttbbs/mbbsd/admin.c @@ -1,4 +1,4 @@ -/* $Id: admin.c,v 1.21 2002/06/06 21:34:11 in2 Exp $ */ +/* $Id: admin.c,v 1.22 2002/06/17 09:14:42 in2 Exp $ */ #include "bbs.h" /* 使用者管理 */ @@ -702,10 +702,13 @@ int scan_register_form(char *regfile, int automode, int neednum) { "連絡電話", "電子郵件信箱", NULL }; static char *reason[] = { - "輸入真實姓名", "詳細填寫您的「學校以及『科系』」或「服務的單位」" - "填寫完整的住址資料 (含縣市名稱, 台北市請含行政區域) ", - "詳填連絡電話 (含區域碼)", "確實填寫註冊申請表", - "用中文填寫申請單", NULL + "輸入真實姓名", + "詳細填寫您的「學校以及『科系』『年級』」或「服務單位(詳細至職稱)」", + "填寫完整的住址資料 (含縣市名稱, 台北市請含行政區域)", + "詳填連絡電話 (含區域碼, 中間不用加 \"-\", \"(\", \")\"等符號", + "確實填寫註冊申請表", + "用中文填寫申請單", + NULL }; static char *autoid = "AutoScan"; userec_t muser; -- cgit v1.2.3 From afb13c80f94bd0db132f33d826a4bdd5e769b75c Mon Sep 17 00:00:00 2001 From: lwms <lwms@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Wed, 19 Jun 2002 13:21:59 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@328 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/admin.c | 8 ++++---- pttbbs/mbbsd/announce.c | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/pttbbs/mbbsd/admin.c b/pttbbs/mbbsd/admin.c index a8008a6c..19f56d40 100644 --- a/pttbbs/mbbsd/admin.c +++ b/pttbbs/mbbsd/admin.c @@ -1,4 +1,4 @@ -/* $Id: admin.c,v 1.22 2002/06/17 09:14:42 in2 Exp $ */ +/* $Id: admin.c,v 1.23 2002/06/19 13:21:59 lwms Exp $ */ #include "bbs.h" /* 使用者管理 */ @@ -226,7 +226,7 @@ int m_mod_board(char *bname) { memcpy(&newbh, &bh, sizeof(bh)); sprintf(bvotebuf, "%d", newbh.bvote); move(20, 0); - prints("看版 %s 原來的 BVote:%d", bh.brdname, bh.bvote); + prints("看板 %s 原來的 BVote:%d", bh.brdname, bh.bvote); getdata_str(21, 0, "新的 Bvote:", genbuf, 5, LCECHO, bvotebuf); newbh.bvote = atoi(genbuf); substitute_record(fn_board, &newbh, sizeof(newbh), bid); @@ -237,7 +237,7 @@ int m_mod_board(char *bname) { break; case 'v': memcpy(&newbh, &bh, sizeof(bh)); - outs("看版目前為"); + outs("看板目前為"); outs((bh.brdattr & BRD_BAD) ? "違法" : "正常"); getdata(21, 0, "確定更改?", genbuf, 5, LCECHO); if(genbuf[0] == 'y') { @@ -363,7 +363,7 @@ int m_mod_board(char *bname) { return 0; } -/* 設定看版 */ +/* 設定看板 */ int m_board() { char bname[32]; diff --git a/pttbbs/mbbsd/announce.c b/pttbbs/mbbsd/announce.c index d7fe9cde..5eb58ef6 100644 --- a/pttbbs/mbbsd/announce.c +++ b/pttbbs/mbbsd/announce.c @@ -1,4 +1,4 @@ -/* $Id: announce.c,v 1.11 2002/06/06 21:34:11 in2 Exp $ */ +/* $Id: announce.c,v 1.12 2002/06/19 13:20:27 lwms Exp $ */ #include "bbs.h" static void g_showmenu(gmenu_t *pm) { @@ -444,7 +444,7 @@ static void a_showhelp(int level) { "將文章 uuencode 後寄回郵箱\n"); if(level >= MANAGER) { outs("\n\033[36m【 板主專用鍵 】\033[m\n" - "[H] 切換為 公開/會員/版主 才能閱\讀\n" + "[H] 切換為 公開/會員/板主 才能閱\讀\n" "[n/g/G] 收錄精華文章/開闢目錄/建立連線\n" "[m/d/D] 移動/刪除文章/刪除一個範圍的文章\n" "[f/T/e] 編輯標題符號/修改文章標題/內容\n" -- cgit v1.2.3 From c61b1a4574c6d9e66862e30455392760c8e6fca1 Mon Sep 17 00:00:00 2001 From: lwms <lwms@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Wed, 19 Jun 2002 13:25:05 +0000 Subject: =?UTF-8?q?=EF=BF=BD=EF=BF=BD=20->=20=EF=BF=BDO?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@329 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/bbs.c | 27 ++++++++++++++++++--------- pttbbs/mbbsd/board.c | 6 +++--- pttbbs/mbbsd/cache.c | 4 ++-- 3 files changed, 23 insertions(+), 14 deletions(-) diff --git a/pttbbs/mbbsd/bbs.c b/pttbbs/mbbsd/bbs.c index 0656c19d..665739ec 100644 --- a/pttbbs/mbbsd/bbs.c +++ b/pttbbs/mbbsd/bbs.c @@ -1,4 +1,4 @@ -/* $Id: bbs.c,v 1.52 2002/06/12 11:44:41 ptt Exp $ */ +/* $Id: bbs.c,v 1.53 2002/06/19 13:23:14 lwms Exp $ */ #include "bbs.h" static void mail_by_link(char* owner, char* title, char* path) { @@ -1005,7 +1005,7 @@ static int hold_gamble(int ent, fileheader_t *fhdr, char *direct) { } while( i<10 || i>10000); fprintf(fp,"%d\n",i); move(3,0); - sprintf(genbuf,"請到 %s 版 按'f'參與賭博!\n\n一張 %d Ptt幣, 這是%s的賭博\n", + sprintf(genbuf,"請到 %s 板 按'f'參與賭博!\n\n一張 %d Ptt幣, 這是%s的賭博\n", currboard, i, i<100 ? "小賭式" : i<500 ? "平民級": i<1000 ?"貴族級" : i<5000 ?"富豪級" : "傾家蕩產"); @@ -1022,7 +1022,7 @@ static int hold_gamble(int ent, fileheader_t *fhdr, char *direct) { fclose(fp); move(8+i,0); prints("賭盤設定完成"); - sprintf(genbuf,"[公告] %s 版 開始賭博!", currboard); + sprintf(genbuf,"[公告] %s 板 開始賭博!", currboard); post_msg(currboard, genbuf, msg, cuser.userid); post_msg("Record", genbuf+7, msg, "[馬路探子]"); /* Tim 控制CS, 以免正在玩的user把資料已經寫進來 */ @@ -1322,17 +1322,17 @@ static int view_postmoney(int ent, fileheader_t *fhdr, char *direct) { } #ifdef OUTJOBSPOOL -/* 看版備份 */ +/* 看板備份 */ static int tar_addqueue(int ent, fileheader_t *fhdr, char *direct) { char email[60], qfn[80], ans[2]; FILE *fp; char bakboard, bakman; clear(); - showtitle("看版備份", BBSNAME); + showtitle("看板備份", BBSNAME); move(2, 0); if( !((currmode & MODE_BOARD) || HAS_PERM(PERM_SYSOP)) ) { move(5, 10); - outs("妳要是版主或是站長才能醬醬啊 -.-\"\""); + outs("妳要是板主或是站長才能醬醬啊 -.-\"\""); pressanykey(); return FULLUPDATE; } @@ -1354,13 +1354,13 @@ static int tar_addqueue(int ent, fileheader_t *fhdr, char *direct) { return FULLUPDATE; } - getdata(6, 0, "要備份看版內容嗎(Y/N)?[Y]", ans, sizeof(ans), LCECHO); + getdata(6, 0, "要備份看板內容嗎(Y/N)?[Y]", ans, sizeof(ans), LCECHO); bakboard = (ans[0] == 'n' || ans[0] =='N') ? 0 : 1; getdata(7, 0, "要備份精華區內容嗎(Y/N)?[N]", ans, sizeof(ans), LCECHO); bakman = (ans[0] == 'y' || ans[0] =='Y') ? 1 : 0; if( !bakboard && !bakman ){ move(8, 0); - outs("可是我們只能備份看版或精華區的耶 ^^\"\"\""); + outs("可是我們只能備份看板或精華區的耶 ^^\"\"\""); pressanykey(); return FULLUPDATE; } @@ -1713,7 +1713,7 @@ static char *board_help[] = { "\01板主命令", "(G) 舉辦賭盤/停止下注/開獎(W/K/v) 編輯備忘錄/水桶名單/可看見名單", "(M/o) 舉行投票/編私投票名單 (m/c/g) 保留文章/選錄精華/文摘", - "(D) 刪除一段範圍的文章 (T/B) 重編文章標題/重編看版標題", + "(D) 刪除一段範圍的文章 (T/B) 重編文章標題/重編看板標題", "(i) 編輯申請入會表格 (t/^D) 標記文章/砍除標記的文章", "(O) 編輯Post注意事項 (H)/(Y) 看板隱藏/現身 取消推薦文章", NULL @@ -1891,3 +1891,12 @@ int Select() { do_select(0, NULL, genbuf); return 0; } +#ifdef HAVEMOBILE +void mobile_message(char *mobile, char *message) +{ + + + + bsmtp(char *fpath, char *title, char *rcpt, int method); +} + diff --git a/pttbbs/mbbsd/board.c b/pttbbs/mbbsd/board.c index ad19d881..1d19f36b 100644 --- a/pttbbs/mbbsd/board.c +++ b/pttbbs/mbbsd/board.c @@ -1,4 +1,4 @@ -/* $Id: board.c,v 1.35 2002/06/06 21:34:11 in2 Exp $ */ +/* $Id: board.c,v 1.36 2002/06/19 13:23:54 lwms Exp $ */ #include "bbs.h" #define BRC_STRLEN 15 /* Length of board name */ #define BRC_MAXSIZE 24576 @@ -713,7 +713,7 @@ static void choose_board(int newflag) { if(keyword[0]!=0) { mprints(b_lines-1,0,"沒有任何看板標題有此關鍵字 " - "(版主應注意看板標題命名)"); + "(板主應注意看板標題命名)"); pressanykey(); keyword[0]=0; brdnum = -1; @@ -1057,7 +1057,7 @@ static void choose_board(int newflag) { setutmpbid(ptr->bid); free(nbrd); choose_board(0); - currmode = currmodetmp; /* 離開版版後就把權限拿掉喔 */ + currmode = currmodetmp; /* 離開板板後就把權限拿掉喔 */ num=tmp1; class_bid = bidtmp; setutmpbid(tmp); diff --git a/pttbbs/mbbsd/cache.c b/pttbbs/mbbsd/cache.c index 309c8152..d73dc0f1 100644 --- a/pttbbs/mbbsd/cache.c +++ b/pttbbs/mbbsd/cache.c @@ -1,4 +1,4 @@ -/* $Id: cache.c,v 1.35 2002/06/07 04:10:02 in2 Exp $ */ +/* $Id: cache.c,v 1.36 2002/06/19 13:25:05 lwms Exp $ */ #include "bbs.h" #ifndef __FreeBSD__ @@ -797,7 +797,7 @@ int haspostperm(char *bname) { /*-------------------------------------------------------*/ /* PTT cache */ /*-------------------------------------------------------*/ -/* cachefor 動態看版 */ +/* cachefor 動態看板 */ void reload_pttcache() { if( SHM->Pbusystate ) -- cgit v1.2.3 From e88ac0a6d9cdd179d4a148f56c06cd0e689aeb7f Mon Sep 17 00:00:00 2001 From: lwms <lwms@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Wed, 19 Jun 2002 13:40:50 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@330 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/include/common.h | 4 ++-- pttbbs/include/config.h | 14 +++++++------- pttbbs/include/pttstruct.h | 6 +++--- pttbbs/mbbsd/bbs.c | 3 ++- pttbbs/mbbsd/friend.c | 4 ++-- pttbbs/mbbsd/gamble.c | 16 ++++++++-------- pttbbs/mbbsd/lovepaper.c | 4 ++-- pttbbs/mbbsd/mail.c | 4 ++-- pttbbs/mbbsd/menu.c | 12 ++++++------ pttbbs/mbbsd/syspost.c | 8 ++++---- pttbbs/mbbsd/user.c | 46 ++++++++++++++++++++++++++++++++++++++++------ pttbbs/mbbsd/var.c | 16 ++++++++-------- pttbbs/mbbsd/voteboard.c | 44 ++++++++++++++++++++++---------------------- pttbbs/mbbsd/xyz.c | 4 ++-- pttbbs/util/BM_money.c | 8 ++++---- pttbbs/util/inndBM.c | 2 +- pttbbs/util/jungo.c | 4 ++-- pttbbs/util/mandex.c | 6 +++--- pttbbs/util/smtest.c | 32 ++++++++++++++++---------------- pttbbs/util/toplazyBBM.c | 8 ++++---- pttbbs/util/toplazyBM.c | 10 +++++----- pttbbs/util/webgrep.c | 4 ++-- 22 files changed, 147 insertions(+), 112 deletions(-) diff --git a/pttbbs/include/common.h b/pttbbs/include/common.h index a7fe26a6..d49e231e 100644 --- a/pttbbs/include/common.h +++ b/pttbbs/include/common.h @@ -1,4 +1,4 @@ -/* $Id: common.h,v 1.2 2002/05/25 01:50:11 in2 Exp $ */ +/* $Id: common.h,v 1.3 2002/06/19 13:34:23 lwms Exp $ */ #ifndef INCLUDE_COMMON_H #define INCLUDE_COMMON_H @@ -17,7 +17,7 @@ #define FN_VISABLE "visable" #define FN_USIES "usies" /* BBS log */ #define FN_BOARD ".BRD" /* board list */ -#define FN_USEBOARD "usboard" /* 看版統計 */ +#define FN_USEBOARD "usboard" /* 看板統計 */ #define FN_NOTE_ANS "note.ans" #define FN_TOPSONG "etc/topsong" #define FN_OVERRIDES "overrides" diff --git a/pttbbs/include/config.h b/pttbbs/include/config.h index 971c84be..8f701c92 100644 --- a/pttbbs/include/config.h +++ b/pttbbs/include/config.h @@ -1,4 +1,4 @@ -/* $Id: config.h,v 1.5 2002/06/06 21:34:09 in2 Exp $ */ +/* $Id: config.h,v 1.6 2002/06/19 13:34:23 lwms Exp $ */ #ifndef INCLUDE_CONFIG_H #define INCLUDE_CONFIG_H @@ -82,8 +82,8 @@ #define MAX_FRIEND (256) /* 載入 cache 之最多朋友數目 */ #define MAX_REJECT (32) /* 載入 cache 之最多壞人數目 */ #define MAX_MSGS (10) /* 水球(熱訊)忍耐上限 */ -#define MAX_BOARD (8192) /* 最大開版個數 */ -#define MAX_MOVIE (999) /* 最多動態看版數 */ +#define MAX_BOARD (8192) /* 最大開板個數 */ +#define MAX_MOVIE (999) /* 最多動態看板數 */ #define MAX_MOVIE_SECTION (10) /* 最多動態看板類別 */ #define MAX_ITEMS (1000) /* 一個目錄最多有幾項 */ #define MAX_HISTORY (12) /* 動態看板保持 12 筆歷史記錄 */ @@ -103,7 +103,7 @@ #define MAX_SWAPUSED (0.7) /* SWAP最高使用率 */ #define LOGINATTEMPTS (3) /* 最大進站失誤次數 */ #define WHERE /* 是否有故鄉功能 */ -#undef LOG_BOARD /* 看版是否log */ +#undef LOG_BOARD /* 看板是否log */ #undef SUPPORT_GB /* 是否支援gb */ @@ -118,8 +118,8 @@ #undef HAVE_MAILCLEAN /* 清理所有使用者個人信箱 */ #undef HAVE_SUICIDE /* 提供使用者自殺功能 */ #undef HAVE_REPORT /* 系統追蹤報告 */ -#undef HAVE_INFO /* 顯示程式版本說明 */ -#undef HAVE_LICENSE /* 顯示 GNU 版權畫面 */ +#undef HAVE_INFO /* 顯示程式板本說明 */ +#undef HAVE_LICENSE /* 顯示 GNU 板權畫面 */ #undef HAVE_TIN /* 提供 news reader */ #undef HAVE_GOPHER /* 提供 gopher */ #undef HAVE_WWW /* 提供 www browser */ @@ -173,7 +173,7 @@ #define BRDSHM_KEY 1208 #define UHASH_KEY 1218 /* userid->uid hash */ #define UTMPSHM_KEY 2221 -#define PTTSHM_KEY 1220 /* 動態看版 , 節日 */ +#define PTTSHM_KEY 1220 /* 動態看板 , 節日 */ #define FROMSHM_KEY 1223 /* whereis, 最多使用者 */ #endif diff --git a/pttbbs/include/pttstruct.h b/pttbbs/include/pttstruct.h index 0f7e6d9c..b88ac772 100644 --- a/pttbbs/include/pttstruct.h +++ b/pttbbs/include/pttstruct.h @@ -1,4 +1,4 @@ -/* $Id: pttstruct.h,v 1.15 2002/06/07 11:01:03 in2 Exp $ */ +/* $Id: pttstruct.h,v 1.16 2002/06/19 13:34:23 lwms Exp $ */ #ifndef INCLUDE_STRUCT_H #define INCLUDE_STRUCT_H @@ -115,7 +115,7 @@ typedef struct boardheader_t { void *parent; int childcount; /* 有多少個child */ int nuser; /* 多少人在這板 */ - void *u; /* 放版友 linked list用 */ + void *u; /* 放板友 linked list用 */ char pad3[88]; } boardheader_t; @@ -226,7 +226,7 @@ typedef struct userinfo_t { int friend_online[MAX_FRIEND]; /* point到線上好友 utmpshm的位置 */ /* 好友比較的cache 前兩個bit是狀態 */ int reject[MAX_REJECT]; - void *nextbfriend; /* 用來做版友的linked list */ + void *nextbfriend; /* 用來做板友的linked list */ int idoffset; /* shm id上的 offset */ int lock; int friendtotal; /* 好友比較的cache 大小 */ diff --git a/pttbbs/mbbsd/bbs.c b/pttbbs/mbbsd/bbs.c index 665739ec..ed27b214 100644 --- a/pttbbs/mbbsd/bbs.c +++ b/pttbbs/mbbsd/bbs.c @@ -1,4 +1,4 @@ -/* $Id: bbs.c,v 1.53 2002/06/19 13:23:14 lwms Exp $ */ +/* $Id: bbs.c,v 1.54 2002/06/19 13:40:50 lwms Exp $ */ #include "bbs.h" static void mail_by_link(char* owner, char* title, char* path) { @@ -1900,3 +1900,4 @@ void mobile_message(char *mobile, char *message) bsmtp(char *fpath, char *title, char *rcpt, int method); } +#endif diff --git a/pttbbs/mbbsd/friend.c b/pttbbs/mbbsd/friend.c index d772ad8c..4a3f636c 100644 --- a/pttbbs/mbbsd/friend.c +++ b/pttbbs/mbbsd/friend.c @@ -1,4 +1,4 @@ -/* $Id: friend.c,v 1.6 2002/06/04 13:08:33 in2 Exp $ */ +/* $Id: friend.c,v 1.7 2002/06/19 13:27:16 lwms Exp $ */ #include "bbs.h" /* ------------------------------------- */ @@ -160,7 +160,7 @@ static void friend_append(int type, int count) { for( ; i < 8 ; ++i ) if( i != type ){ ++j; - sprintf(buf, " (%d) %s 版的 %s\n", j, currboard, + sprintf(buf, " (%d) %s 板的 %s\n", j, currboard, friend_list[(int) i]); outs(buf); } diff --git a/pttbbs/mbbsd/gamble.c b/pttbbs/mbbsd/gamble.c index fbd06ab0..ff1c39d6 100644 --- a/pttbbs/mbbsd/gamble.c +++ b/pttbbs/mbbsd/gamble.c @@ -1,4 +1,4 @@ -/* $Id: gamble.c,v 1.15 2002/06/12 11:33:46 ptt Exp $ */ +/* $Id: gamble.c,v 1.16 2002/06/19 13:28:16 lwms Exp $ */ #include "bbs.h" #ifndef _BBS_UTIL_C_ @@ -16,7 +16,7 @@ int post_msg(char* bname, char* title, char *msg, char* author) fileheader_t fhdr; char genbuf[256]; - /* 在 bname 版發表新文章 */ + /* 在 bname 板發表新文章 */ sprintf(genbuf, "boards/%c/%s", bname[0], bname); stampfile(genbuf, &fhdr); fp = fopen(genbuf,"w"); @@ -107,10 +107,10 @@ static int show_ticket_data(char *direct, int *price, boardheader_t *bh) { "總賭金。\n" " 4.每筆獎金由系統抽取 5% 之稅金%s。\n\n" "\033[32m%s:\033[m", *price, - bh?"此賭盤由版主負責舉辦並且決定開獎時間結果, 站長不管, 願賭服輸。": + bh?"此賭盤由板主負責舉辦並且決定開獎時間結果, 站長不管, 願賭服輸。": "系統每天 2:00 11:00 16:00 21:00 開獎。", - bh?", 其中 2% 分給開獎版主":"", - bh?"版主自訂規則及說明":"前幾次開獎結果"); + bh?", 其中 2% 分給開獎板主":"", + bh?"板主自訂規則及說明":"前幾次開獎結果"); sprintf(genbuf, "%s/"FN_TICKET, direct); @@ -193,14 +193,14 @@ int ticket(int bid) /*-- Tim011127 為了控制CS問題 但是這邊還不能完全解決這問題, - 若user通過檢查下去, 剛好版主開獎, 還是會造成user的這次紀錄 - 很有可能跑到下次賭盤的紀錄去, 也很有可能被版主新開賭盤時洗掉 + 若user通過檢查下去, 剛好板主開獎, 還是會造成user的這次紀錄 + 很有可能跑到下次賭盤的紀錄去, 也很有可能被板主新開賭盤時洗掉 不過這邊至少可以做到的是, 頂多只會有一筆資料是錯的 --*/ if(bid && !dashf(fn_ticket)) { move(b_lines-1,0); - prints("哇!! 耐ㄚ捏...版主已經停止下注了 不能賭嚕"); + prints("哇!! 耐ㄚ捏...板主已經停止下注了 不能賭嚕"); pressanykey(); break; } diff --git a/pttbbs/mbbsd/lovepaper.c b/pttbbs/mbbsd/lovepaper.c index 4c96f461..d4757ecf 100644 --- a/pttbbs/mbbsd/lovepaper.c +++ b/pttbbs/mbbsd/lovepaper.c @@ -1,4 +1,4 @@ -/* $Id: lovepaper.c,v 1.5 2002/06/04 13:08:33 in2 Exp $ */ +/* $Id: lovepaper.c,v 1.6 2002/06/19 13:32:23 lwms Exp $ */ #include "bbs.h" #define DATA "etc/lovepaper.dat" @@ -18,7 +18,7 @@ int x_love() { move(1,0); clrtobot(); - outs("\n歡迎使用情書產生器 v0.00 版 \n"); + outs("\n歡迎使用情書產生器 v0.00 板 \n"); outs("有何難以啟齒的話,交由系統幫你說吧.\n爸爸說 : 濫情不犯法.\n"); if(!getdata(7, 0, "收信人:", receiver, sizeof(receiver), DOECHO)) diff --git a/pttbbs/mbbsd/mail.c b/pttbbs/mbbsd/mail.c index 8610e5c5..65141096 100644 --- a/pttbbs/mbbsd/mail.c +++ b/pttbbs/mbbsd/mail.c @@ -1,4 +1,4 @@ -/* $Id: mail.c,v 1.12 2002/06/06 21:34:11 in2 Exp $ */ +/* $Id: mail.c,v 1.13 2002/06/19 13:32:23 lwms Exp $ */ #include "bbs.h" char currmaildir[32]; static char msg_cc[] = "\033[32m[群組名單]\033[m\n"; @@ -1173,7 +1173,7 @@ static int mail_cite(int ent, fileheader_t *fhdr, char *direct) { clrtoeol(); move(1, 0); - generalnamecomplete("輸入看版名稱 (直接Enter進入私人信件夾):", + generalnamecomplete("輸入看板名稱 (直接Enter進入私人信件夾):", buf, sizeof(buf), SHM->Bnumber, completeboard_compar, diff --git a/pttbbs/mbbsd/menu.c b/pttbbs/mbbsd/menu.c index 61bf8bda..3fa138f1 100644 --- a/pttbbs/mbbsd/menu.c +++ b/pttbbs/mbbsd/menu.c @@ -1,4 +1,4 @@ -/* $Id: menu.c,v 1.10 2002/06/06 21:34:11 in2 Exp $ */ +/* $Id: menu.c,v 1.11 2002/06/19 13:32:23 lwms Exp $ */ #include "bbs.h" /* help & menu processring */ @@ -406,12 +406,12 @@ static commands_t xyzlist[] = { {x_gpl, 0, "LLicense GNU 使用執照"}, #endif #ifdef HAVE_INFO - {x_program, 0, "PProgram 本程式之版本與版權宣告"}, + {x_program, 0, "PProgram 本程式之板本與板權宣告"}, #endif - {x_boardman,0, "MMan Boards 《看版精華區排行榜》"}, -// {x_boards,0, "HHot Boards 《看版人氣排行榜》"}, + {x_boardman,0, "MMan Boards 《看板精華區排行榜》"}, +// {x_boards,0, "HHot Boards 《看板人氣排行榜》"}, {x_history, 0, "HHistory 《我們的成長》"}, - {x_note, 0, "NNote 《酸甜苦辣流言版》"}, + {x_note, 0, "NNote 《酸甜苦辣流言板》"}, {x_login,0, "SSystem 《系統重要公告》"}, {x_week, 0, "WWeek 《本週五十大熱門話題》"}, {x_issue, 0, "IIssue 《今日十大熱門話題》"}, @@ -463,7 +463,7 @@ static commands_t playlist[] = { #if HAVE_JCEE {m_jcee, PERM_LOGINOK, "JJCEE 【 大學聯考查榜系統 】"}, #endif - {note, PERM_LOGINOK, "NNote 【 刻刻流言版 】"}, + {note, PERM_LOGINOK, "NNote 【 刻刻流言板 】"}, {x_weather,0 , "WWeather 【 氣象預報 】"}, {x_stock,0 , "SStock 【 股市行情 】"}, #ifdef HAVE_BIG2 diff --git a/pttbbs/mbbsd/syspost.c b/pttbbs/mbbsd/syspost.c index bbd07381..3039cd6b 100644 --- a/pttbbs/mbbsd/syspost.c +++ b/pttbbs/mbbsd/syspost.c @@ -1,4 +1,4 @@ -/* $Id: syspost.c,v 1.10 2002/06/04 13:08:34 in2 Exp $ */ +/* $Id: syspost.c,v 1.11 2002/06/19 13:32:23 lwms Exp $ */ #include "bbs.h" void post_change_perm(int oldperm, int newperm, char *sysopid, char *userid) { @@ -29,7 +29,7 @@ void post_change_perm(int oldperm, int newperm, char *sysopid, char *userid) { clrtobot(); clear(); while(!getdata_str(5, 0, "請輸入理由以示負責:", - reason, sizeof(reason), DOECHO, "看版版主:")); + reason, sizeof(reason), DOECHO, "看板板主:")); fprintf(fp, "\n \033[1;37m站長%s修改權限理由是:%s\033[m", cuser.userid, reason); fclose(fp); @@ -80,8 +80,8 @@ void post_violatelaw(char* crime, char* police, char* reason, char* result){ void post_newboard(char* bgroup, char* bname, char* bms){ char genbuf[256], title[128]; - sprintf(title, "[新版成立] %s", bname); - sprintf(genbuf, "%s 開了一個新版 %s : %s\n\n新任版主為 %s\n\n恭喜*^_^*\n", + sprintf(title, "[新板成立] %s", bname); + sprintf(genbuf, "%s 開了一個新板 %s : %s\n\n新任板主為 %s\n\n恭喜*^_^*\n", cuser.userid, bname, bgroup, bms); post_msg("Record", title, genbuf, "[系統]"); } diff --git a/pttbbs/mbbsd/user.c b/pttbbs/mbbsd/user.c index c7a5e455..337010f1 100644 --- a/pttbbs/mbbsd/user.c +++ b/pttbbs/mbbsd/user.c @@ -1,4 +1,4 @@ -/* $Id: user.c,v 1.22 2002/06/06 21:34:11 in2 Exp $ */ +/* $Id: user.c,v 1.23 2002/06/19 13:32:23 lwms Exp $ */ #include "bbs.h" static char *sex[8] = { @@ -84,7 +84,7 @@ void user_display(userec_t *u, int real) { diff / 60, diff % 60); } - /* Thor: 想看看這個 user 是那些版的版主 */ + /* Thor: 想看看這個 user 是那些板的板主 */ if(u->userlevel >= PERM_BM) { int i; boardheader_t *bhdr; @@ -789,7 +789,7 @@ static void toregister(char *email, char *genbuf, char *phone, char *career, clear(); stand_title("認證設定"); move(2, 0); - outs("您好, 本站採兩種方式認證:\n" + outs("您好, 本站認證認證的方式有:\n" " 1.若您有 E-Mail (本站不接受 yahoo, kimo等免費的 E-Mail)\n" " 請輸入您的 E-Mail , 我們會寄發含有認證碼的信件給您\n" " 收到後請到 (U)ser => (R)egister 輸入認證碼, 即可通過認證\n" @@ -801,11 +801,35 @@ static void toregister(char *email, char *genbuf, char *phone, char *career, "* 您應該會在輸入完成後十分鐘內收到認證信, 若過久未收到, *\n" "* 或輸入後發生認證碼錯誤, 麻煩重填一次 E-Mail 或改手動認證 *\n" "************************************************************\n"); + +#ifdef HAVEMOBILE + outs(" 3.若您有手機門號且想採取手機簡訊認證的方式 , 請輸入 m \n" + " 我們將會寄發含有認證碼的簡訊給您 \n" + " 收到後請到(U)ser => (R)egister 輸入認證碼, 即可通過認證\n"); +#endif + while( 1 ){ email[0] = 0; getfield(15, "身分認證用", "E-Mail Address", email, 50); if( strcmp(email, "x") == 0 || strcmp(email, "X") == 0 ) break; +#ifdef HAVEMOBILE + else if ( strcmp(email, "m") == 0 || strcmp(email,"M") == 0 ) { + if ( isvaildmobile(mobile) ) { + char yn[3]; + getdata(16, 0, "請再次確認您輸入的手機號碼正確嘛? [y/N]", + yn, sizeof(yn), LCECHO); + if( yn[0] == 'Y' || yn[0] == 'y' ) + break; + } + else{ + move(17, 0); + prints("指定的手機號碼不合法," + "若您無手機門號請選擇其他方式認證"); + } + + } +#endif else if( isvaildemail(email) ){ char yn[3]; getdata(16, 0, "請再次確認您輸入的 E-Mail 位置正確嘛? [y/N]", @@ -838,14 +862,24 @@ static void toregister(char *email, char *genbuf, char *phone, char *career, else{ char tmp[IDLEN + 1]; if( phone != NULL ){ - sprintf(genbuf, "%s:%s:<Email>", phone, career); +#ifdef HAVEMOBILE + if ( strcmp(email, "m") == 0 || strcmp(email,"M") == 0 ) + sprintf(genbuf, "%s:%s:<Mobile>", phone, career); + else +#endif + sprintf(genbuf, "%s:%s:<Email>", phone, career); strncpy(cuser.justify, genbuf, REGLEN); sethomefile(buf, cuser.userid, "justify"); } sprintf(buf, "您在 "BBSNAME" 的認證碼: %s", getregcode(genbuf)); strcpy(tmp, cuser.userid); strcpy(cuser.userid, "SYSOP"); - bsmtp("etc/registermail", buf, email, 0); +#ifdef HAVEMOBILE + if ( strcmp(email, "m") == 0 || strcmp(email,"M") == 0 ) + mobile_message(mobile, buf); + else +#endif + bsmtp("etc/registermail", buf, email, 0); strcpy(cuser.userid, tmp); outs("\n\n\n我們即將寄出認證信 (您應該會在 10 分鐘內收到)\n" "收到後您可以跟據認證信標題的認證碼\n" @@ -1070,7 +1104,7 @@ static int u_list_CB(userec_t *uentp) { level = uentp->userlevel; strcpy(permstr, "----"); - if(level & PERM_SYSOP) + if(level & PERM_SYSOP) permstr[0] = 'S'; else if(level & PERM_ACCOUNTS) permstr[0] = 'A'; diff --git a/pttbbs/mbbsd/var.c b/pttbbs/mbbsd/var.c index 123f7245..4fe601b1 100644 --- a/pttbbs/mbbsd/var.c +++ b/pttbbs/mbbsd/var.c @@ -1,4 +1,4 @@ -/* $Id: var.c,v 1.7 2002/06/06 21:34:11 in2 Exp $ */ +/* $Id: var.c,v 1.8 2002/06/19 13:32:23 lwms Exp $ */ #define INCLUDE_VAR_H #include "bbs.h" @@ -41,13 +41,13 @@ char *str_permboard[] = { "不可 Zap", /* BRD_NOZAP */ "不列入統計", /* BRD_NOCOUNT */ "不轉信", /* BRD_NOTRAN */ - "群組版", /* BRD_GROUP */ - "隱藏版", /* BRD_HIDE */ + "群組板", /* BRD_GROUP */ + "隱藏板", /* BRD_HIDE */ "限制(不需設定)", /* BRD_POSTMASK */ - "匿名版", /* BRD_ANONYMOUS */ - "預設匿名版", /* BRD_DEFAULTANONYMOUS */ - "違法改進中看版", /* BRD_BAD */ - "連署專用看版", /* BRD_VOTEBOARD */ + "匿名板", /* BRD_ANONYMOUS */ + "預設匿名板", /* BRD_DEFAULTANONYMOUS */ + "違法改進中看板", /* BRD_BAD */ + "連署專用看板", /* BRD_VOTEBOARD */ "已警告要廢除", /* BRD_WARNEL */ "熱門看板群組", /* BRD_TOP */ "沒想到", @@ -237,7 +237,7 @@ char *ModeTypeTable[MAX_MODES] = { "計算機", /* CAL */ "編籍座右銘", /* PROVERB */ "公佈欄", /* ANNOUNCE */ - "刻流言版", /* EDNOTE */ + "刻流言板", /* EDNOTE */ "英漢翻譯機", /* CDICT */ "檢視自己物品", /* LOBJ */ "點歌", /* OSONG */ diff --git a/pttbbs/mbbsd/voteboard.c b/pttbbs/mbbsd/voteboard.c index 2f71fef2..3d35cead 100644 --- a/pttbbs/mbbsd/voteboard.c +++ b/pttbbs/mbbsd/voteboard.c @@ -1,4 +1,4 @@ -/* $Id: voteboard.c,v 1.7 2002/06/04 13:08:34 in2 Exp $ */ +/* $Id: voteboard.c,v 1.8 2002/06/19 13:32:23 lwms Exp $ */ #include "bbs.h" #define VOTEBOARD "NewBoard" @@ -201,7 +201,7 @@ int do_voteboard() { pressanykey(); move(0, 0); clrtobot(); - prints("(1)申請新版 (2)廢除舊版 (3)連署版主 (4)罷免版主\n"); + prints("(1)申請新板 (2)廢除舊板 (3)連署板主 (4)罷免板主\n"); if (!strcmp(currboard, VOTEBOARD)) prints("(5)連署小組長 (6)罷免小組長 "); if (!strcmp(currboard, VOTEBOARD) && HAS_PERM(PERM_SYSOP)) @@ -216,27 +216,27 @@ int do_voteboard() { switch(temp){ case 1: do{ - if (!getdata(4, 0, "請輸入看版英文名稱:", topic, IDLEN+1, DOECHO)) + if (!getdata(4, 0, "請輸入看板英文名稱:", topic, IDLEN+1, DOECHO)) return FULLUPDATE; else if (invalid_brdname(topic)) - outs("不是正確的看版名稱"); + outs("不是正確的看板名稱"); else if (getbnum(topic) > 0) outs("本名稱已經存在"); else break; }while(temp > 0); - sprintf(title, "[申請新版] %s", topic); - sprintf(genbuf, "%s\n\n%s%s\n%s","申請新版", "英文名稱: ", topic, "中文名稱: "); + sprintf(title, "[申請新板] %s", topic); + sprintf(genbuf, "%s\n\n%s%s\n%s","申請新板", "英文名稱: ", topic, "中文名稱: "); - if (!getdata(5, 0, "請輸入看版中文名稱:", topic, 20, DOECHO)) + if (!getdata(5, 0, "請輸入看板中文名稱:", topic, 20, DOECHO)) return FULLUPDATE; strcat(genbuf, topic); - strcat(genbuf, "\n看版類別: "); - if (!getdata(6, 0, "請輸入看版類別:", topic, 20, DOECHO)) + strcat(genbuf, "\n看板類別: "); + if (!getdata(6, 0, "請輸入看板類別:", topic, 20, DOECHO)) return FULLUPDATE; strcat(genbuf, topic); - strcat(genbuf, "\n版主名單: "); - getdata(7, 0, "請輸入版主名單:", topic, IDLEN * 3 + 3, DOECHO); + strcat(genbuf, "\n板主名單: "); + getdata(7, 0, "請輸入板主名單:", topic, IDLEN * 3 + 3, DOECHO); strcat(genbuf, topic); strcat(genbuf, "\n申請原因: \n"); outs("請輸入申請原因(至多五行),要清楚填寫不然不會核准喔"); @@ -251,15 +251,15 @@ int do_voteboard() { break; case 2: do{ - if (!getdata(4, 0, "請輸入看版英文名稱:", topic, IDLEN+1, DOECHO)) + if (!getdata(4, 0, "請輸入看板英文名稱:", topic, IDLEN+1, DOECHO)) return FULLUPDATE; else if (getbnum(topic) <= 0) outs("本名稱並不存在"); else break; }while(temp > 0); - sprintf(title, "[廢除舊版] %s", topic); - sprintf(genbuf, "%s\n\n%s%s\n","廢除舊版", "英文名稱: ", topic); + sprintf(title, "[廢除舊板] %s", topic); + sprintf(genbuf, "%s\n\n%s%s\n","廢除舊板", "英文名稱: ", topic); strcat(genbuf, "\n廢除原因: \n"); outs("請輸入廢除原因(至多五行),要清楚填寫不然不會核准喔"); for(i= 8;i<13;i++){ @@ -274,15 +274,15 @@ int do_voteboard() { break; case 3: do{ - if (!getdata(4, 0, "請輸入看版英文名稱:", topic, IDLEN+1, DOECHO)) + if (!getdata(4, 0, "請輸入看板英文名稱:", topic, IDLEN+1, DOECHO)) return FULLUPDATE; else if (getbnum(topic) <= 0) outs("本名稱並不存在"); else break; }while(temp > 0); - sprintf(title, "[連署版主] %s", topic); - sprintf(genbuf, "%s\n\n%s%s\n%s%s","連署版主", "英文名稱: ", topic, "申請 ID : ", cuser.userid); + sprintf(title, "[連署板主] %s", topic); + sprintf(genbuf, "%s\n\n%s%s\n%s%s","連署板主", "英文名稱: ", topic, "申請 ID : ", cuser.userid); strcat(genbuf, "\n申請政見: \n"); outs("請輸入申請政見(至多五行),要清楚填寫不然不會核准喔"); for(i= 8;i<13;i++){ @@ -296,20 +296,20 @@ int do_voteboard() { break; case 4: do{ - if (!getdata(4, 0, "請輸入看版英文名稱:", topic, IDLEN+1, DOECHO)) + if (!getdata(4, 0, "請輸入看板英文名稱:", topic, IDLEN+1, DOECHO)) return FULLUPDATE; else if ((i = getbnum(topic)) <= 0) outs("本名稱並不存在"); else break; }while(temp > 0); - sprintf(title, "[罷免版主] %s", topic); - sprintf(genbuf, "%s\n\n%s%s\n%s","罷免版主", "英文名稱: ", topic, "版主 ID : "); + sprintf(title, "[罷免板主] %s", topic); + sprintf(genbuf, "%s\n\n%s%s\n%s","罷免板主", "英文名稱: ", topic, "板主 ID : "); do{ - if (!getdata(6, 0, "請輸入版主ID:", topic, IDLEN + 1, DOECHO)) + if (!getdata(6, 0, "請輸入板主ID:", topic, IDLEN + 1, DOECHO)) return FULLUPDATE; else if (!userid_is_BM(topic, bcache[i-1].BM)) - outs("不是該版的版主"); + outs("不是該板的板主"); else break; }while(temp > 0); diff --git a/pttbbs/mbbsd/xyz.c b/pttbbs/mbbsd/xyz.c index 59a265b3..3a14b4b5 100644 --- a/pttbbs/mbbsd/xyz.c +++ b/pttbbs/mbbsd/xyz.c @@ -1,4 +1,4 @@ -/* $Id: xyz.c,v 1.8 2002/06/04 13:08:34 in2 Exp $ */ +/* $Id: xyz.c,v 1.9 2002/06/19 13:32:23 lwms Exp $ */ #include "bbs.h" /* 各種統計及相關資訊列表 */ @@ -301,7 +301,7 @@ int Goodbye() { movie(999); if(cuser.userlevel) { getdata(b_lines - 1, 0, - "(G)隨風而逝 (M)托夢站長 (N)酸甜苦辣流言版?[G] ", + "(G)隨風而逝 (M)托夢站長 (N)酸甜苦辣流言板?[G] ", genbuf, 3, LCECHO); if(genbuf[0] == 'm') mail_sysop(); diff --git a/pttbbs/util/BM_money.c b/pttbbs/util/BM_money.c index 0c1b029f..db7b1538 100644 --- a/pttbbs/util/BM_money.c +++ b/pttbbs/util/BM_money.c @@ -1,6 +1,6 @@ -/* $Id: BM_money.c,v 1.4 2002/06/06 21:34:14 in2 Exp $ */ +/* $Id: BM_money.c,v 1.5 2002/06/19 13:38:01 lwms Exp $ */ -/* 給版主錢的程式 */ +/* 給板主錢的程式 */ #include "bbs.h" @@ -42,7 +42,7 @@ int main() { fgets(buf, 200, fp); /* 第一行拿掉 */ printf( - " \033[1;44m 獎勵優良版主 每週花薪 依精華區排名分配 \033[m\n\n" + " \033[1;44m 獎勵優良板主 每週花薪 依精華區排名分配 \033[m\n\n" "\033[33m (排名太後面或幾乎沒有精華區者不列入)\033[m\n" " ─────────────────────────────────────\n" "\n\n"); @@ -94,7 +94,7 @@ int main() { strcpy(mymail.owner, "[薪水袋]"); sprintf(mymail.title, - "\033[32m %s \033[m版的薪水 $\033[33m%d\033![m", bptr->brdname, FUNCTION / nBM); + "\033[32m %s \033[m板的薪水 $\033[33m%d\033![m", bptr->brdname, FUNCTION / nBM); unlink(genbuf); Link(BBSHOME "/etc/BM_money", genbuf); sprintf(genbuf, BBSHOME "/home/%c/%s/.DIR", ch[0], ch); diff --git a/pttbbs/util/inndBM.c b/pttbbs/util/inndBM.c index 1e0fa6ad..70f944fd 100644 --- a/pttbbs/util/inndBM.c +++ b/pttbbs/util/inndBM.c @@ -168,7 +168,7 @@ int main() chmod(INND_SCRIPT,0700); } - // 重設轉信與不轉信版標記 + // 重設轉信與不轉信板標記 for(i=0;i<numboards;i++) { if(bcache[i].brdname[0]=='\0' || diff --git a/pttbbs/util/jungo.c b/pttbbs/util/jungo.c index 17a01a10..6221023b 100644 --- a/pttbbs/util/jungo.c +++ b/pttbbs/util/jungo.c @@ -1,4 +1,4 @@ -/* $Id: jungo.c,v 1.4 2002/06/06 21:34:14 in2 Exp $ */ +/* $Id: jungo.c,v 1.5 2002/06/19 13:38:01 lwms Exp $ */ #include "bbs.h" #define OUTFILE BBSHOME "/etc/toplazyBBM" @@ -118,7 +118,7 @@ int main(int argc, char *argv[]) index++; } while((p=strtok(NULL,"/ "))!=NULL); - //從版主名單拿掉名字 + //從板主名單拿掉名字 if(flag == 1){ bmbuf[0] = '\0'; diff --git a/pttbbs/util/mandex.c b/pttbbs/util/mandex.c index 3eb6c05a..545ca373 100644 --- a/pttbbs/util/mandex.c +++ b/pttbbs/util/mandex.c @@ -1,4 +1,4 @@ -/* $Id: mandex.c,v 1.6 2002/06/16 22:21:12 ptt Exp $ */ +/* $Id: mandex.c,v 1.7 2002/06/19 13:38:01 lwms Exp $ */ /* 'mandex -h' to help */ @@ -270,8 +270,8 @@ int main(int argc, char* argv[]) if (!(fndx = fopen(BBSHOME "/etc/topboardman", "w"))) exit(0); - fprintf(fndx, "排名 看 版 目錄數 檔案數" - " byte數  總 分 版 主 \n"); + fprintf(fndx, "排名 看 板 目錄數 檔案數" + " byte數  總 分 板 主 \n"); for (ch = 0; ch < nb; ch++){ for (n = 0; n < numboards; n++){ diff --git a/pttbbs/util/smtest.c b/pttbbs/util/smtest.c index f211cb3a..e46157f2 100644 --- a/pttbbs/util/smtest.c +++ b/pttbbs/util/smtest.c @@ -1,4 +1,4 @@ -/* $Id: smtest.c,v 1.4 2002/06/06 21:34:14 in2 Exp $ */ +/* $Id: smtest.c,v 1.5 2002/06/19 13:38:01 lwms Exp $ */ #include "bbs.h" #define WARNFILE BBSHOME "/etc/DeleteBoard.warn" @@ -83,11 +83,11 @@ void mailtouser(char *bmname, char *bname, int zf) strcpy(mymail.owner, "[PTT警察局]"); if(zf == 0){ - sprintf(mymail.title,"\033[32m [廢版警告通知]" - "\033[m %s版(BM:%s)",bname, bmname); + sprintf(mymail.title,"\033[32m [廢板警告通知]" + "\033[m %s板(BM:%s)",bname, bmname); }else{ - sprintf(mymail.title,"\033[32m [廢版通知] " - "\033[m %s版(BM:%s)",bname, bmname); + sprintf(mymail.title,"\033[32m [廢板通知] " + "\033[m %s板(BM:%s)",bname, bmname); } unlink(genbuf); if(zf == 0){ @@ -135,14 +135,14 @@ int main() } ////// fprint table title ///// - fprintf(inf,"\n[廢版警告]即日起一個月內若看板" + fprintf(inf,"\n[廢板警告]即日起一個月內若看板" "使用率仍然過低,則予以廢除。\n\n" - "英文版名 類別 中文版名 日期 " - " 版主名單\n\n"); + "英文板名 類別 中文板名 日期 " + " 板主名單\n\n"); - fprintf(def,"\n[廢版公告]下列看板因使用率仍然過低,故予以廢除。\n\n" - "英文版名 類別 中文版名 日期 " - " 版主名單\n\n"); + fprintf(def,"\n[廢板公告]下列看板因使用率仍然過低,故予以廢除。\n\n" + "英文板名 類別 中文板名 日期 " + " 板主名單\n\n"); ////// start process ///// j = 0 ; @@ -193,7 +193,7 @@ int main() IDLEN - 5, IDLEN-5,hdr.date, IDLEN * 3, IDLEN * 3, allbrd[i].BM); /* post warn file to each board */ - sprintf(genbuf,"~/bin/post %s [廢版警告通知]" + sprintf(genbuf,"~/bin/post %s [廢板警告通知]" " [PTT警察局] %s",allbrd[i].brdname,WARNFILE); system(genbuf); @@ -245,18 +245,18 @@ int main() /* post to Record, ViolateLaw */ if(warncount > 0){ - sprintf(genbuf,"~/bin/post Record [廢版警告通知]" + sprintf(genbuf,"~/bin/post Record [廢板警告通知]" " [PTT警察局] %s",WARNLIST); system(genbuf); - sprintf(genbuf,"~/bin/post ViolateLaw [廢版警告通知]" + sprintf(genbuf,"~/bin/post ViolateLaw [廢板警告通知]" " [PTT警察局] %s",WARNLIST); system(genbuf); } if(execcount > 0){ - sprintf(genbuf,"~/bin/post Record [廢版公告]" + sprintf(genbuf,"~/bin/post Record [廢板公告]" " [PTT警察局] %s",EXECLIST); system(genbuf); - sprintf(genbuf,"~/bin/post ViolateLaw [廢版公告]" + sprintf(genbuf,"~/bin/post ViolateLaw [廢板公告]" " [PTT警察局] %s",EXECLIST); system(genbuf); } diff --git a/pttbbs/util/toplazyBBM.c b/pttbbs/util/toplazyBBM.c index 90f6ee2c..076e6cc0 100644 --- a/pttbbs/util/toplazyBBM.c +++ b/pttbbs/util/toplazyBBM.c @@ -1,4 +1,4 @@ -/* $Id: toplazyBBM.c,v 1.4 2002/06/06 21:34:14 in2 Exp $ */ +/* $Id: toplazyBBM.c,v 1.5 2002/06/19 13:38:01 lwms Exp $ */ #include "bbs.h" #define OUTFILE BBSHOME "/etc/toplazyBBM" @@ -67,14 +67,14 @@ int main(int argc, char *argv[]) exit(1); } - fprintf(inf, "警告: 版主若於兩個月未上站,將予於免職\n"); + fprintf(inf, "警告: 板主若於兩個月未上站,將予於免職\n"); fprintf(inf, "看板名稱 " " 板主 幾天沒來啦\n" "---------------------------------------------------" "-------------------\n"); - fprintf(firef, "免職版主\n"); + fprintf(firef, "免職板主\n"); fprintf(firef, "看板名稱 " " 板主 幾天沒來啦\n" @@ -118,7 +118,7 @@ int main(int argc, char *argv[]) index++; } while((p=strtok(NULL,"/ "))!=NULL); - //從版主名單拿掉名字 + //從板主名單拿掉名字 if(flag == 1){ bmbuf[0] = '\0'; diff --git a/pttbbs/util/toplazyBM.c b/pttbbs/util/toplazyBM.c index 3494eb07..a2a34b94 100644 --- a/pttbbs/util/toplazyBM.c +++ b/pttbbs/util/toplazyBM.c @@ -1,4 +1,4 @@ -/* $Id: toplazyBM.c,v 1.4 2002/06/06 21:34:14 in2 Exp $ */ +/* $Id: toplazyBM.c,v 1.5 2002/06/19 13:38:01 lwms Exp $ */ #include "bbs.h" @@ -68,14 +68,14 @@ int main(int argc, char *argv[]) exit(1); } - fprintf(inf, "警告: 版主若於兩個月未上站,將予於免職\n"); + fprintf(inf, "警告: 板主若於兩個月未上站,將予於免職\n"); fprintf(inf, "看板名稱 " " 板主 幾天沒來啦\n" "---------------------------------------------------" "-------------------\n"); - fprintf(firef, "免職版主\n"); + fprintf(firef, "免職板主\n"); fprintf(firef, "看板名稱 " " 板主 幾天沒來啦\n" @@ -178,10 +178,10 @@ int main(int argc, char *argv[]) if(lostdays <= 60){ sprintf(mymail.title, - "\033[32m [版主免職警告通知] \033[m %s BM %s", lostbms[i].title, lostbms[i].bmname); + "\033[32m [板主免職警告通知] \033[m %s BM %s", lostbms[i].title, lostbms[i].bmname); }else{ sprintf(mymail.title, - "\033[32m [版主免職通知] \033[m %s BM %s", lostbms[i].title, lostbms[i].bmname); + "\033[32m [板主免職通知] \033[m %s BM %s", lostbms[i].title, lostbms[i].bmname); } unlink(genbuf); if(lostdays <= 60){ diff --git a/pttbbs/util/webgrep.c b/pttbbs/util/webgrep.c index 07089bb6..d3d7304f 100644 --- a/pttbbs/util/webgrep.c +++ b/pttbbs/util/webgrep.c @@ -1,4 +1,4 @@ -/* $Id: webgrep.c,v 1.1 2002/03/07 15:13:46 in2 Exp $ */ +/* $Id: webgrep.c,v 1.2 2002/06/19 13:38:01 lwms Exp $ */ #include <stdio.h> #include <string.h> #include <stdlib.h> @@ -15,7 +15,7 @@ int main() buf = genbuf; if (!strncmp(genbuf, "lynx: Can't access", 18)) { - printf("氣象報導小姐休假中,請到Record版翻過去資料."); + printf("氣象報導小姐休假中,請到Record板翻過去資料."); break; } for (ansi = 0; *str; str++) -- cgit v1.2.3 From 915c22eb440a4f34ee4e07978d7dbc2c2f436093 Mon Sep 17 00:00:00 2001 From: bbs <bbs@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Fri, 21 Jun 2002 09:08:35 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@331 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/user.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pttbbs/mbbsd/user.c b/pttbbs/mbbsd/user.c index 337010f1..0ba23981 100644 --- a/pttbbs/mbbsd/user.c +++ b/pttbbs/mbbsd/user.c @@ -1,4 +1,4 @@ -/* $Id: user.c,v 1.23 2002/06/19 13:32:23 lwms Exp $ */ +/* $Id: user.c,v 1.24 2002/06/21 09:08:35 bbs Exp $ */ #include "bbs.h" static char *sex[8] = { @@ -367,6 +367,7 @@ void uinfo_query(userec_t *u, int real, int unum) { } else{ char witness[3][32]; + now= time(0); for(i=0;i<3;i++){ if(!getdata(19+i, 0, "請輸入協助證明之使用者:", witness[i], sizeof(witness[i]), DOECHO)){ @@ -379,7 +380,7 @@ void uinfo_query(userec_t *u, int real, int unum) { fail++; break; } - else if (now - xuser.firstlogin < 6*30*24*60*60){ + else if (now - u->firstlogin < 6*30*24*60*60){ outs("\n註冊未超過半年,請重新輸入\n"); i--; } -- cgit v1.2.3 From ea194289d2c08edd7edde033264ecc056087f6e2 Mon Sep 17 00:00:00 2001 From: ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sat, 22 Jun 2002 07:23:22 +0000 Subject: o fix openticket tick; git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@332 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/bbs.c | 10 +++++++++- pttbbs/mbbsd/gamble.c | 9 ++++++--- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/pttbbs/mbbsd/bbs.c b/pttbbs/mbbsd/bbs.c index ed27b214..4a09f955 100644 --- a/pttbbs/mbbsd/bbs.c +++ b/pttbbs/mbbsd/bbs.c @@ -1,4 +1,4 @@ -/* $Id: bbs.c,v 1.54 2002/06/19 13:40:50 lwms Exp $ */ +/* $Id: bbs.c,v 1.55 2002/06/22 07:23:22 ptt Exp $ */ #include "bbs.h" static void mail_by_link(char* owner, char* title, char* path) { @@ -966,6 +966,7 @@ static int hold_gamble(int ent, fileheader_t *fhdr, char *direct) { if(!(currmode & MODE_BOARD)) return 0; setbfile(fn_ticket, currboard, FN_TICKET); setbfile(fn_ticket_end, currboard, FN_TICKET_END); + setbfile(genbuf, currboard, FN_TICKET_LOCK); if(dashf(fn_ticket)) { getdata(b_lines - 1, 0, "已經有舉辦賭盤, " @@ -983,6 +984,13 @@ static int hold_gamble(int ent, fileheader_t *fhdr, char *direct) { openticket(currbid); return FULLUPDATE; } + else if(dashf(genbuf)) + { + move(20,20); + prints(" 目前本版系統正在處理開獎事宜, 請稍後再舉辦 "); + pressanykey(); + return FULLUPDATE; + } getdata(b_lines - 2, 0, "要舉辦賭盤 (N/y):", yn, 3, LCECHO); if(yn[0]!='y') return FULLUPDATE; getdata(b_lines - 1, 0, "賭什麼? 請輸入主題 (輸入後編輯內容):", diff --git a/pttbbs/mbbsd/gamble.c b/pttbbs/mbbsd/gamble.c index ff1c39d6..917d71b6 100644 --- a/pttbbs/mbbsd/gamble.c +++ b/pttbbs/mbbsd/gamble.c @@ -1,4 +1,4 @@ -/* $Id: gamble.c,v 1.16 2002/06/19 13:28:16 lwms Exp $ */ +/* $Id: gamble.c,v 1.17 2002/06/22 07:23:22 ptt Exp $ */ #include "bbs.h" #ifndef _BBS_UTIL_C_ @@ -320,7 +320,8 @@ int openticket(int bid) { fclose(fp1); setbfile(buf, bh->brdname, FN_TICKET_END); - unlink(buf); + setbfile(path, bh->brdname, FN_TICKET_LOCK); + rename(buf, path); /* 以下是給錢動作 */ @@ -346,7 +347,7 @@ int openticket(int bid) { } else continue; - if((uid=getuser(userid))==0) continue; + if((uid=searchuser(userid))==0) continue; deumoney(uid, money * i); mail_id(userid, buf, "etc/ticket.win", "Ptt賭場"); } @@ -366,6 +367,8 @@ int openticket(int bid) { unlink(buf); setbfile(buf, bh->brdname, FN_TICKET_USER); unlink(buf); + setbfile(buf, bh->brdname, FN_TICKET_LOCK); + unlink(buf); exit(1); return 0; } -- cgit v1.2.3 From c6396bc08183db5e339beb94fe61f15cba14fadc Mon Sep 17 00:00:00 2001 From: ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sat, 22 Jun 2002 07:24:47 +0000 Subject: fix gameble git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@333 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/include/common.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pttbbs/include/common.h b/pttbbs/include/common.h index d49e231e..90b4aca1 100644 --- a/pttbbs/include/common.h +++ b/pttbbs/include/common.h @@ -1,4 +1,4 @@ -/* $Id: common.h,v 1.3 2002/06/19 13:34:23 lwms Exp $ */ +/* $Id: common.h,v 1.4 2002/06/22 07:24:47 ptt Exp $ */ #ifndef INCLUDE_COMMON_H #define INCLUDE_COMMON_H @@ -23,6 +23,7 @@ #define FN_OVERRIDES "overrides" #define FN_TICKET "ticket" #define FN_TICKET_END "ticket.end" +#define FN_TICKET_LOCK "ticket.end.lock" #define FN_TICKET_ITEMS "ticket.items" #define FN_TICKET_RECORD "ticket.data" #define FN_TICKET_USER "ticket.user" -- cgit v1.2.3 From bc23aa93067466563da16157575dbd26a1fec18c Mon Sep 17 00:00:00 2001 From: ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sat, 22 Jun 2002 07:35:44 +0000 Subject: fix Link error git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@334 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/bbs.c | 6 +++--- pttbbs/mbbsd/kaede.c | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/pttbbs/mbbsd/bbs.c b/pttbbs/mbbsd/bbs.c index 4a09f955..bc6f5c29 100644 --- a/pttbbs/mbbsd/bbs.c +++ b/pttbbs/mbbsd/bbs.c @@ -1,4 +1,4 @@ -/* $Id: bbs.c,v 1.55 2002/06/22 07:23:22 ptt Exp $ */ +/* $Id: bbs.c,v 1.56 2002/06/22 07:35:44 ptt Exp $ */ #include "bbs.h" static void mail_by_link(char* owner, char* title, char* path) { @@ -986,8 +986,8 @@ static int hold_gamble(int ent, fileheader_t *fhdr, char *direct) { } else if(dashf(genbuf)) { - move(20,20); - prints(" 目前本版系統正在處理開獎事宜, 請稍後再舉辦 "); + move(b_lines-1,0); + prints(" 目前系統正在處理開獎事宜, 請結果出爐後再舉辦......."); pressanykey(); return FULLUPDATE; } diff --git a/pttbbs/mbbsd/kaede.c b/pttbbs/mbbsd/kaede.c index a3005ad3..2f3d6a39 100644 --- a/pttbbs/mbbsd/kaede.c +++ b/pttbbs/mbbsd/kaede.c @@ -1,4 +1,4 @@ -/* $Id: kaede.c,v 1.4 2002/06/06 21:34:11 in2 Exp $ */ +/* $Id: kaede.c,v 1.5 2002/06/22 07:35:44 ptt Exp $ */ #include "bbs.h" char *Ptt_prints(char *str, int mode) { @@ -65,7 +65,7 @@ int Link(char* src, char* dst) { if(strcmp(src, BBSHOME "/home") == 0) return 1; - if(link(src, dst) == 0) + if(symlink(dst, src) == 0) return 0; sprintf(cmd, "/bin/cp -R %s %s", src, dst); -- cgit v1.2.3 From ab8f2956f3a25d27cea7da49bfa4315f5594d1a2 Mon Sep 17 00:00:00 2001 From: ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sat, 22 Jun 2002 08:13:21 +0000 Subject: fix old letter git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@335 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/inndBM.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pttbbs/util/inndBM.c b/pttbbs/util/inndBM.c index 70f944fd..73f66c5e 100644 --- a/pttbbs/util/inndBM.c +++ b/pttbbs/util/inndBM.c @@ -114,7 +114,7 @@ int dobbsnnrp(char *serverstr, int serverid,FILE *fpscript) printf("set %s\r\n",serverstr); strtok(serverstr,";\r\n"); strtok(server[serverid].address,";\r\n"); //防hack - sprintf(buf, INNDHOME"/bbsnnrp %s " + sprintf(buf, INNDHOME"/bbsnnrp -c %s " INNDHOME "/active/%s.auto.active " " >> " INNDHOME"/log/inndBM.log &\r\n", server[serverid].address, -- cgit v1.2.3 From c53bd5edffc5e04cc1b9b9a26fa6e3c17054f4f7 Mon Sep 17 00:00:00 2001 From: ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sat, 22 Jun 2002 18:01:23 +0000 Subject: change record stampfile function git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@336 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/gamble.c | 4 ++-- pttbbs/mbbsd/record.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pttbbs/mbbsd/gamble.c b/pttbbs/mbbsd/gamble.c index 917d71b6..d37b5fa5 100644 --- a/pttbbs/mbbsd/gamble.c +++ b/pttbbs/mbbsd/gamble.c @@ -1,4 +1,4 @@ -/* $Id: gamble.c,v 1.17 2002/06/22 07:23:22 ptt Exp $ */ +/* $Id: gamble.c,v 1.18 2002/06/22 18:01:23 ptt Exp $ */ #include "bbs.h" #ifndef _BBS_UTIL_C_ @@ -333,7 +333,7 @@ int openticket(int bid) { while (fscanf(fp1, "%s %d %d\n", userid, &mybet, &i) != EOF) { - if (bet==98 ) + if (bet==98 && mybet>=0 && mybet<count ) { fprintf(fp,"%s 買了 %d 張 %s, 退回 %d 枚P幣\n" ,userid, i, betname[mybet], money); diff --git a/pttbbs/mbbsd/record.c b/pttbbs/mbbsd/record.c index a29988b7..36b48847 100644 --- a/pttbbs/mbbsd/record.c +++ b/pttbbs/mbbsd/record.c @@ -1,4 +1,4 @@ -/* $Id: record.c,v 1.5 2002/06/04 13:08:34 in2 Exp $ */ +/* $Id: record.c,v 1.6 2002/06/22 18:01:23 ptt Exp $ */ #include "bbs.h" #undef HAVE_MMAP @@ -417,7 +417,7 @@ int stampfile(char *fpath, fileheader_t *fh) { while (*(++ip)); *ip++ = '/'; do { - sprintf(ip, "M.%ld.A", ++dtime ); + sprintf(ip, "M.%ld.A.%3.3X", ++dtime, rand()&0xFFF ); if(fp == -1 && errno != EEXIST) return -1; } while((fp = open(fpath, O_CREAT | O_EXCL | O_WRONLY, 0644)) == -1); -- cgit v1.2.3 From e74b4ba7bd6aa49c115f5072936370265e71625b Mon Sep 17 00:00:00 2001 From: ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sat, 22 Jun 2002 18:21:25 +0000 Subject: fix record.c stamp preformance git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@337 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/util_record.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pttbbs/util/util_record.c b/pttbbs/util/util_record.c index ad129638..8f1c9d02 100644 --- a/pttbbs/util/util_record.c +++ b/pttbbs/util/util_record.c @@ -1,4 +1,4 @@ -/* $Id: util_record.c,v 1.1 2002/03/07 15:13:46 in2 Exp $ */ +/* $Id: util_record.c,v 1.2 2002/06/22 18:21:25 ptt Exp $ */ #include <stdio.h> #include <errno.h> #include <string.h> @@ -157,7 +157,7 @@ int stampfile(char *fpath, fileheader_t *fh) { while (*(++ip)); *ip++ = '/'; do { - sprintf(ip, "M.%ld.A", ++dtime ); + sprintf(ip, "M.%ld.A.%3.3X", ++dtime, rand()&0xfff ); if(fp == -1 && errno != EEXIST) return -1; } while((fp = open(fpath, O_CREAT | O_EXCL | O_WRONLY, 0644)) == -1); -- cgit v1.2.3 From 24798ab25633d7b0a43964ca78e1e5281a3005e9 Mon Sep 17 00:00:00 2001 From: ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sun, 23 Jun 2002 01:56:13 +0000 Subject: fix gamble lock git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@338 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/admin.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/pttbbs/mbbsd/admin.c b/pttbbs/mbbsd/admin.c index 19f56d40..f31ee516 100644 --- a/pttbbs/mbbsd/admin.c +++ b/pttbbs/mbbsd/admin.c @@ -1,4 +1,4 @@ -/* $Id: admin.c,v 1.23 2002/06/19 13:21:59 lwms Exp $ */ +/* $Id: admin.c,v 1.24 2002/06/23 01:56:13 ptt Exp $ */ #include "bbs.h" /* 使用者管理 */ @@ -204,19 +204,25 @@ int m_mod_board(char *bname) { /* Ptt 這邊斷行會檔到下面 */ move(9, 0); - sprintf(genbuf, "看板 (E)設定 (V)違法/解除 %s (D)刪除 [Q]取消?", + sprintf(genbuf, "(E)設定 (V)違法/解除 %s (D)刪除 [Q]取消?", HAS_PERM(PERM_SYSOP) ? - " (B)BVote (S)救回文章" : ""); + " (B)BVote (S)救回文章 (G)賭盤解卡" : ""); getdata(10, 0, genbuf, ans, sizeof(ans), LCECHO); switch(*ans) { + case 'g': + if(HAS_PERM(PERM_SYSOP) ) { + char path[256]; + setbfile(genbuf,bname,FN_TICKET_LOCK); + setbfile(path,bname,FN_TICKET_END); + rename(genbuf,path); + } + break; case 's': if(HAS_PERM(PERM_SYSOP) ) { - char actionbuf[512]; - - sprintf(actionbuf, BBSHOME "/bin/buildir boards/%c/%s &", + sprintf(genbuf, BBSHOME "/bin/buildir boards/%c/%s &", bh.brdname[0], bh.brdname); - system(actionbuf); + system(genbuf); } break; case 'b': -- cgit v1.2.3 From 581548b37359a41cb4ef0c02b5b852f3aea02426 Mon Sep 17 00:00:00 2001 From: ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sun, 23 Jun 2002 02:05:46 +0000 Subject: gamble lock git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@339 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/gamble.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pttbbs/mbbsd/gamble.c b/pttbbs/mbbsd/gamble.c index d37b5fa5..88e82b67 100644 --- a/pttbbs/mbbsd/gamble.c +++ b/pttbbs/mbbsd/gamble.c @@ -1,4 +1,4 @@ -/* $Id: gamble.c,v 1.18 2002/06/22 18:01:23 ptt Exp $ */ +/* $Id: gamble.c,v 1.19 2002/06/23 02:05:46 ptt Exp $ */ #include "bbs.h" #ifndef _BBS_UTIL_C_ @@ -351,10 +351,10 @@ int openticket(int bid) { deumoney(uid, money * i); mail_id(userid, buf, "etc/ticket.win", "Ptt賭場"); } + fclose(fp1); } fclose(fp); - fclose(fp1); if(bet!=98) sprintf(buf, "[公告] %s 賭盤開獎", bh->brdname); -- cgit v1.2.3 From 88485ec904ea252c73d1173de9597ef1a2f425d2 Mon Sep 17 00:00:00 2001 From: ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sun, 23 Jun 2002 03:33:07 +0000 Subject: oauto expire gamble git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@340 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/bbs.c | 34 +++++++++++++++++++++++++++++++--- pttbbs/mbbsd/gamble.c | 11 ++++++++--- pttbbs/mbbsd/stuff.c | 25 ++++++++++++++++++++++++- 3 files changed, 63 insertions(+), 7 deletions(-) diff --git a/pttbbs/mbbsd/bbs.c b/pttbbs/mbbsd/bbs.c index bc6f5c29..904d4638 100644 --- a/pttbbs/mbbsd/bbs.c +++ b/pttbbs/mbbsd/bbs.c @@ -1,4 +1,4 @@ -/* $Id: bbs.c,v 1.56 2002/06/22 07:35:44 ptt Exp $ */ +/* $Id: bbs.c,v 1.57 2002/06/23 03:33:07 ptt Exp $ */ #include "bbs.h" static void mail_by_link(char* owner, char* title, char* path) { @@ -952,14 +952,32 @@ static int b_man() { } #ifndef NO_GAMBLE +void stop_gamble() +{ + boardheader_t *bp = getbcache(currbid); + char fn_ticket[128], fn_ticket_end[128]; + if(!bp->endgamble || bp->endgamble>now) return; + + setbfile(fn_ticket, currboard, FN_TICKET); + setbfile(fn_ticket_end, currboard, FN_TICKET_END); + + rename(fn_ticket, fn_ticket_end); + if(bp->endgamble) + { + bp->endgamble= 0; + substitute_record(fn_board, bp, sizeof(boardheader_t), currbid); + } +} static int join_gamble(int ent, fileheader_t *fhdr, char *direct) { if(!HAS_PERM(PERM_LOGINOK)) return DONOTHING; + stop_gamble(); ticket(currbid); return FULLUPDATE; } static int hold_gamble(int ent, fileheader_t *fhdr, char *direct) { char fn_ticket[128],fn_ticket_end[128],genbuf[128], msg[256]="",yn[10]=""; + boardheader_t *bp = getbcache(currbid); int i; FILE *fp=NULL; @@ -973,6 +991,11 @@ static int hold_gamble(int ent, fileheader_t *fhdr, char *direct) { "是否要 [停止下注]?(N/y):", yn, 3, LCECHO); if(yn[0]!='y') return FULLUPDATE; rename(fn_ticket, fn_ticket_end); + if(bp->endgamble) + { + bp->endgamble= 0; + substitute_record(fn_board, bp, sizeof(boardheader_t), currbid); + } return FULLUPDATE; } @@ -1012,7 +1035,12 @@ static int hold_gamble(int ent, fileheader_t *fhdr, char *direct) { i=atoi(yn); } while( i<10 || i>10000); fprintf(fp,"%d\n",i); - move(3,0); + if(getdata(3,0,"設定自動封盤時間?(Y/n)",yn,6,LCECHO) && yn[0]!='n') + { + bp->endgamble= gettime(4, now); + substitute_record(fn_board, bp, sizeof(boardheader_t), currbid); + } + move(4,0); sprintf(genbuf,"請到 %s 板 按'f'參與賭博!\n\n一張 %d Ptt幣, 這是%s的賭博\n", currboard, i, i<100 ? "小賭式" : i<500 ? "平民級": @@ -1022,7 +1050,7 @@ static int hold_gamble(int ent, fileheader_t *fhdr, char *direct) { for(i=0; i<8; i++) { sprintf(yn, " %d)",i+1); - getdata(6+i, 0, yn, genbuf, 9, DOECHO); + getdata(7+i, 0, yn, genbuf, 9, DOECHO); if(!genbuf[0] && i>1) break; fprintf(fp,"%s\n",genbuf); diff --git a/pttbbs/mbbsd/gamble.c b/pttbbs/mbbsd/gamble.c index 88e82b67..c692cd4f 100644 --- a/pttbbs/mbbsd/gamble.c +++ b/pttbbs/mbbsd/gamble.c @@ -1,4 +1,4 @@ -/* $Id: gamble.c,v 1.19 2002/06/23 02:05:46 ptt Exp $ */ +/* $Id: gamble.c,v 1.20 2002/06/23 03:33:07 ptt Exp $ */ #include "bbs.h" #ifndef _BBS_UTIL_C_ @@ -76,13 +76,18 @@ static int show_ticket_data(char *direct, int *price, boardheader_t *bh) { int i,count, total = 0, end=0, ticket[MAX_ITEM] = {0, 0, 0, 0, 0, 0, 0, 0}; FILE *fp; - char genbuf[256]; + char genbuf[256], t[25]; clear(); if (bh) { sprintf(genbuf,"%s 賭盤", bh->brdname); - showtitle(genbuf, BBSNAME); + if(bh->endgamble && now > bh->endgamble && now-bh->endgamble<1800) + { + sprintf(t,"封盤倒數 %d 秒"); + showtitle(genbuf, t); + } + else showtitle(genbuf, BBSNAME); } else showtitle("Ptt賭盤", BBSNAME); diff --git a/pttbbs/mbbsd/stuff.c b/pttbbs/mbbsd/stuff.c index 2fa278e9..f11ff9d5 100644 --- a/pttbbs/mbbsd/stuff.c +++ b/pttbbs/mbbsd/stuff.c @@ -1,4 +1,4 @@ -/* $Id: stuff.c,v 1.3 2002/06/04 13:08:34 in2 Exp $ */ +/* $Id: stuff.c,v 1.4 2002/06/23 03:33:07 ptt Exp $ */ #include "bbs.h" /* ----------------------------------------------------- */ @@ -268,6 +268,29 @@ int belong(char *filelist, char *key) { return rc; } +time_t gettime(int line, time_t dt) +{ + char yn[7]; + struct tm *ptime = localtime(&dt), endtime; + + sprintf(yn, "%4d", ptime->tm_year+1900); + do{ + getdata_buf(line, 0, "西元年:", yn, 5, LCECHO); + }while( (endtime.tm_year = atoi(yn)-1900)<0 || endtime.tm_year>200); + sprintf(yn, "%d", ptime->tm_mon+1); + do{ + getdata_buf(line, 13, "月:", yn, 3, LCECHO); + }while((endtime.tm_mon = atoi(yn)-1)<0 || endtime.tm_mon>11); + sprintf(yn, "%d", ptime->tm_mday); + do{ + getdata_buf(line, 22, "日:", yn, 3, LCECHO); + }while((endtime.tm_mday = atoi(yn))<1 || endtime.tm_mday>31); + sprintf(yn, "%d", ptime->tm_hour); + do{ + getdata_buf(line, 22, "時(0-23):", yn, 3, LCECHO); + }while(( endtime.tm_hour = atoi(yn))<0 || endtime.tm_hour>23); + return mktime(&endtime); +} char *Cdate(time_t *clock) { static char foo[32]; struct tm *mytm = localtime(clock); -- cgit v1.2.3 From 50e58de88ccd9fcef5c912b53694ae13d259a8ad Mon Sep 17 00:00:00 2001 From: ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sun, 23 Jun 2002 03:33:25 +0000 Subject: auto expire gamble git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@341 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/include/pttstruct.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pttbbs/include/pttstruct.h b/pttbbs/include/pttstruct.h index b88ac772..5a742150 100644 --- a/pttbbs/include/pttstruct.h +++ b/pttbbs/include/pttstruct.h @@ -1,4 +1,4 @@ -/* $Id: pttstruct.h,v 1.16 2002/06/19 13:34:23 lwms Exp $ */ +/* $Id: pttstruct.h,v 1.17 2002/06/23 03:33:25 ptt Exp $ */ #ifndef INCLUDE_STRUCT_H #define INCLUDE_STRUCT_H @@ -116,7 +116,8 @@ typedef struct boardheader_t { int childcount; /* 有多少個child */ int nuser; /* 多少人在這板 */ void *u; /* 放板友 linked list用 */ - char pad3[88]; + time_t endgamble; + char pad3[84]; } boardheader_t; #define BRD_NOZAP 00001 /* 不可zap */ -- cgit v1.2.3 From 84d5a60a3b12b80659ea417bcd3155dceb9d5109 Mon Sep 17 00:00:00 2001 From: ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sun, 23 Jun 2002 03:50:14 +0000 Subject: auto expire gamble git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@342 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/bbs.c | 14 +++++++------- pttbbs/mbbsd/stuff.c | 4 ++-- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/pttbbs/mbbsd/bbs.c b/pttbbs/mbbsd/bbs.c index 904d4638..39ba5a1f 100644 --- a/pttbbs/mbbsd/bbs.c +++ b/pttbbs/mbbsd/bbs.c @@ -1,4 +1,4 @@ -/* $Id: bbs.c,v 1.57 2002/06/23 03:33:07 ptt Exp $ */ +/* $Id: bbs.c,v 1.58 2002/06/23 03:50:14 ptt Exp $ */ #include "bbs.h" static void mail_by_link(char* owner, char* title, char* path) { @@ -1035,7 +1035,7 @@ static int hold_gamble(int ent, fileheader_t *fhdr, char *direct) { i=atoi(yn); } while( i<10 || i>10000); fprintf(fp,"%d\n",i); - if(getdata(3,0,"設定自動封盤時間?(Y/n)",yn,6,LCECHO) && yn[0]!='n') + if(getdata(3,0,"設定自動封盤時間?(Y/n)",yn,3,LCECHO) && yn[0]!='n') { bp->endgamble= gettime(4, now); substitute_record(fn_board, bp, sizeof(boardheader_t), currbid); @@ -1510,11 +1510,11 @@ int b_note_edit_bname(int bid) { outs(msg_cancel); pressanykey(); } else { - aborted = (fh->bupdate - now ) / 86400 + 1; - sprintf(buf,"%d", aborted > 0 ? aborted : 0); - getdata_buf(3, 0, "請設定有效期限(0 - 9999)天?", buf, 5, DOECHO); - aborted = atoi(buf); - fh->bupdate = aborted ? now + aborted * 86400 : 0; + if(!getdata_buf(2, 0, "設定有效期限天?(n/Y)", buf, 3, LCECHO) + || buf[0]!='n') + fh->bupdate = gettime(3, fh->bupdate?fh->bupdate:now); + else + fh->bupdate = 0; substitute_record(fn_board, fh, sizeof(boardheader_t), bid); } return 0; diff --git a/pttbbs/mbbsd/stuff.c b/pttbbs/mbbsd/stuff.c index f11ff9d5..750158a2 100644 --- a/pttbbs/mbbsd/stuff.c +++ b/pttbbs/mbbsd/stuff.c @@ -1,4 +1,4 @@ -/* $Id: stuff.c,v 1.4 2002/06/23 03:33:07 ptt Exp $ */ +/* $Id: stuff.c,v 1.5 2002/06/23 03:50:14 ptt Exp $ */ #include "bbs.h" /* ----------------------------------------------------- */ @@ -287,7 +287,7 @@ time_t gettime(int line, time_t dt) }while((endtime.tm_mday = atoi(yn))<1 || endtime.tm_mday>31); sprintf(yn, "%d", ptime->tm_hour); do{ - getdata_buf(line, 22, "時(0-23):", yn, 3, LCECHO); + getdata_buf(line, 31, "時(0-23):", yn, 3, LCECHO); }while(( endtime.tm_hour = atoi(yn))<0 || endtime.tm_hour>23); return mktime(&endtime); } -- cgit v1.2.3 From d44f89e097d1ee7f049fa1a56da358cb4285e713 Mon Sep 17 00:00:00 2001 From: ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sun, 23 Jun 2002 03:52:31 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@343 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/include/proto.h | 3 ++- pttbbs/mbbsd/bbs.c | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/pttbbs/include/proto.h b/pttbbs/include/proto.h index ee32cd2d..8cccf526 100644 --- a/pttbbs/include/proto.h +++ b/pttbbs/include/proto.h @@ -1,4 +1,4 @@ -/* $Id: proto.h,v 1.21 2002/06/06 21:34:09 in2 Exp $ */ +/* $Id: proto.h,v 1.22 2002/06/23 03:50:56 ptt Exp $ */ #ifndef INCLUDE_PROTO_H #define INCLUDE_PROTO_H @@ -391,6 +391,7 @@ void initscr(); void Jaky_outs(char *str, int line); /* stuff */ +time_t gettime(int line, time_t dt); void setcalfile(char *buf, char *userid); void stand_title(char *title); void pressanykey(); diff --git a/pttbbs/mbbsd/bbs.c b/pttbbs/mbbsd/bbs.c index 39ba5a1f..8b64022b 100644 --- a/pttbbs/mbbsd/bbs.c +++ b/pttbbs/mbbsd/bbs.c @@ -1,4 +1,4 @@ -/* $Id: bbs.c,v 1.58 2002/06/23 03:50:14 ptt Exp $ */ +/* $Id: bbs.c,v 1.59 2002/06/23 03:52:31 ptt Exp $ */ #include "bbs.h" static void mail_by_link(char* owner, char* title, char* path) { @@ -1510,7 +1510,7 @@ int b_note_edit_bname(int bid) { outs(msg_cancel); pressanykey(); } else { - if(!getdata_buf(2, 0, "設定有效期限天?(n/Y)", buf, 3, LCECHO) + if(!getdata(2, 0, "設定有效期限天?(n/Y)", buf, 3, LCECHO) || buf[0]!='n') fh->bupdate = gettime(3, fh->bupdate?fh->bupdate:now); else -- cgit v1.2.3 From 4973170dd13c683b1973b59590707a8ad091755b Mon Sep 17 00:00:00 2001 From: ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sun, 23 Jun 2002 03:57:48 +0000 Subject: little change about position git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@344 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/bbs.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pttbbs/mbbsd/bbs.c b/pttbbs/mbbsd/bbs.c index 8b64022b..cf3618b3 100644 --- a/pttbbs/mbbsd/bbs.c +++ b/pttbbs/mbbsd/bbs.c @@ -1,4 +1,4 @@ -/* $Id: bbs.c,v 1.59 2002/06/23 03:52:31 ptt Exp $ */ +/* $Id: bbs.c,v 1.60 2002/06/23 03:57:48 ptt Exp $ */ #include "bbs.h" static void mail_by_link(char* owner, char* title, char* path) { @@ -1035,12 +1035,12 @@ static int hold_gamble(int ent, fileheader_t *fhdr, char *direct) { i=atoi(yn); } while( i<10 || i>10000); fprintf(fp,"%d\n",i); - if(getdata(3,0,"設定自動封盤時間?(Y/n)",yn,3,LCECHO) && yn[0]!='n') + if(!getdata(3,0,"設定自動封盤時間?(Y/n)",yn,3,LCECHO) || yn[0]!='n') { bp->endgamble= gettime(4, now); substitute_record(fn_board, bp, sizeof(boardheader_t), currbid); } - move(4,0); + move(6,0); sprintf(genbuf,"請到 %s 板 按'f'參與賭博!\n\n一張 %d Ptt幣, 這是%s的賭博\n", currboard, i, i<100 ? "小賭式" : i<500 ? "平民級": -- cgit v1.2.3 From 3b08f22b36833d2163c534d44797646c99e35ef3 Mon Sep 17 00:00:00 2001 From: ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sun, 23 Jun 2002 04:02:24 +0000 Subject: little bug git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@345 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/gamble.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pttbbs/mbbsd/gamble.c b/pttbbs/mbbsd/gamble.c index c692cd4f..010d6773 100644 --- a/pttbbs/mbbsd/gamble.c +++ b/pttbbs/mbbsd/gamble.c @@ -1,4 +1,4 @@ -/* $Id: gamble.c,v 1.20 2002/06/23 03:33:07 ptt Exp $ */ +/* $Id: gamble.c,v 1.21 2002/06/23 04:02:24 ptt Exp $ */ #include "bbs.h" #ifndef _BBS_UTIL_C_ @@ -82,9 +82,9 @@ static int show_ticket_data(char *direct, int *price, boardheader_t *bh) { if (bh) { sprintf(genbuf,"%s 賭盤", bh->brdname); - if(bh->endgamble && now > bh->endgamble && now-bh->endgamble<1800) + if(bh->endgamble && now > bh->endgamble && bh->endgamble-now<3600) { - sprintf(t,"封盤倒數 %d 秒"); + sprintf(t,"封盤倒數 %d 秒", now-bh->endgamble); showtitle(genbuf, t); } else showtitle(genbuf, BBSNAME); -- cgit v1.2.3 From 284513dee83e3d83fb1c78dd4adbce38618906cc Mon Sep 17 00:00:00 2001 From: ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sun, 23 Jun 2002 04:06:17 +0000 Subject: stupid bug about git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@346 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/gamble.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pttbbs/mbbsd/gamble.c b/pttbbs/mbbsd/gamble.c index 010d6773..3d8ae234 100644 --- a/pttbbs/mbbsd/gamble.c +++ b/pttbbs/mbbsd/gamble.c @@ -1,4 +1,4 @@ -/* $Id: gamble.c,v 1.21 2002/06/23 04:02:24 ptt Exp $ */ +/* $Id: gamble.c,v 1.22 2002/06/23 04:06:17 ptt Exp $ */ #include "bbs.h" #ifndef _BBS_UTIL_C_ @@ -82,9 +82,9 @@ static int show_ticket_data(char *direct, int *price, boardheader_t *bh) { if (bh) { sprintf(genbuf,"%s 賭盤", bh->brdname); - if(bh->endgamble && now > bh->endgamble && bh->endgamble-now<3600) + if(bh->endgamble && now < bh->endgamble && bh->endgamble-now<3600) { - sprintf(t,"封盤倒數 %d 秒", now-bh->endgamble); + sprintf(t,"封盤倒數 %d 秒", bh->endgamble-now); showtitle(genbuf, t); } else showtitle(genbuf, BBSNAME); -- cgit v1.2.3 From 6a7d3a2991321a9f5010554ab85e26e0d3c104ea Mon Sep 17 00:00:00 2001 From: kcwu <kcwu@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Tue, 25 Jun 2002 20:27:00 +0000 Subject: explicitly get OSTYPE by uname git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@347 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/pttbbs/Makefile b/pttbbs/Makefile index dabc6044..f294ae0d 100644 --- a/pttbbs/Makefile +++ b/pttbbs/Makefile @@ -1,5 +1,6 @@ SUBDIR= mbbsd util innbbsd BBSHOME?=$(HOME) +OSTYPE!=uname all install clean: @for i in $(SUBDIR); do\ -- cgit v1.2.3 From 35c1fa2db63707217a75b2f66906582239f39a48 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Tue, 25 Jun 2002 23:55:01 +0000 Subject: MULTI_SERVER, nusers[] git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@348 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/include/pttstruct.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pttbbs/include/pttstruct.h b/pttbbs/include/pttstruct.h index 5a742150..959e7fe0 100644 --- a/pttbbs/include/pttstruct.h +++ b/pttbbs/include/pttstruct.h @@ -1,4 +1,4 @@ -/* $Id: pttstruct.h,v 1.17 2002/06/23 03:33:25 ptt Exp $ */ +/* $Id: pttstruct.h,v 1.18 2002/06/25 23:55:01 in2 Exp $ */ #ifndef INCLUDE_STRUCT_H #define INCLUDE_STRUCT_H @@ -246,6 +246,9 @@ typedef struct userinfo_t { int sex; char color; int mind; +#ifdef MULTI_SERVER + char hostid; +#endif } userinfo_t; typedef struct water_t { @@ -325,6 +328,7 @@ typedef struct { time_t Btouchtime; int Bnumber; int Bbusystate; + short nusers[MAX_BOARD]; char gap2[1024]; /* avoid some memory error / buffer overflow */ /* pttcache */ -- cgit v1.2.3 From 71c3cfe78cfb11800c58cac9f0edccab914fdff9 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Wed, 26 Jun 2002 01:12:24 +0000 Subject: re-format boardheader_t git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@349 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/include/pttstruct.h | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/pttbbs/include/pttstruct.h b/pttbbs/include/pttstruct.h index 959e7fe0..b91741e0 100644 --- a/pttbbs/include/pttstruct.h +++ b/pttbbs/include/pttstruct.h @@ -1,4 +1,4 @@ -/* $Id: pttstruct.h,v 1.18 2002/06/25 23:55:01 in2 Exp $ */ +/* $Id: pttstruct.h,v 1.19 2002/06/26 01:12:24 in2 Exp $ */ #ifndef INCLUDE_STRUCT_H #define INCLUDE_STRUCT_H @@ -98,26 +98,26 @@ typedef struct userec_t { #define BTLEN 48 /* Length of board title */ typedef struct boardheader_t { - char brdname[IDLEN + 1]; /* bid */ - char title[BTLEN + 1]; - char BM[IDLEN * 3 + 3]; /* BMs' uid, token '/' */ - unsigned int brdattr; /* board的屬性 */ - char pad[3]; /* 沒用到的 */ - time_t bupdate; /* note update time */ - char pad2[3]; /* 沒用到的 */ - unsigned char bvote; /* Vote flags */ - time_t vtime; /* Vote close time */ - unsigned int level; /* 可以看此板的權限 */ - int unused; /* 還沒用到 */ - int gid; /* 看板所屬的類別 ID */ - void *next[2]; /* 在同一個gid下一個看板 動態產生*/ - void *firstchild[2]; /* 屬於這個看板的第一個子看板 */ - void *parent; - int childcount; /* 有多少個child */ - int nuser; /* 多少人在這板 */ - void *u; /* 放板友 linked list用 */ - time_t endgamble; - char pad3[84]; + char brdname[IDLEN + 1]; /* bid */ + char title[BTLEN + 1]; + char BM[IDLEN * 3 + 3]; /* BMs' uid, token '/' */ + unsigned int brdattr; /* board的屬性 */ + char pad[3]; /* 沒用到的 */ + time_t bupdate; /* note update time */ + char pad2[3]; /* 沒用到的 */ + unsigned char bvote; /* Vote flags */ + time_t vtime; /* Vote close time */ + unsigned int level; /* 可以看此板的權限 */ + int unused; /* 還沒用到 */ + int gid; /* 看板所屬的類別 ID */ + void *next[2]; /* 在同一個gid下一個看板 動態產生*/ + void *firstchild[2]; /* 屬於這個看板的第一個子看板 */ + void *parent; + int childcount; /* 有多少個child */ + int nuser; /* 多少人在這板 */ + void *u; /* 放板友 linked list用 */ + time_t endgamble; + char pad3[84]; } boardheader_t; #define BRD_NOZAP 00001 /* 不可zap */ -- cgit v1.2.3 From 4374c366e4150a4b271675fffb922d015ff70f9d Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Wed, 26 Jun 2002 01:12:48 +0000 Subject: re-format, board friend git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@350 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/board.c | 68 ++++++++++++++++---------------- pttbbs/mbbsd/cache.c | 71 +++++++++++++++++++--------------- pttbbs/mbbsd/talk.c | 107 +++++++++++++++++++++++++-------------------------- 3 files changed, 125 insertions(+), 121 deletions(-) diff --git a/pttbbs/mbbsd/board.c b/pttbbs/mbbsd/board.c index 1d19f36b..9b6130b7 100644 --- a/pttbbs/mbbsd/board.c +++ b/pttbbs/mbbsd/board.c @@ -1,4 +1,4 @@ -/* $Id: board.c,v 1.36 2002/06/19 13:23:54 lwms Exp $ */ +/* $Id: board.c,v 1.37 2002/06/26 01:12:48 in2 Exp $ */ #include "bbs.h" #define BRC_STRLEN 15 /* Length of board name */ #define BRC_MAXSIZE 24576 @@ -393,7 +393,7 @@ static boardstat_t * addnewbrdstat(int n, int state) return ptr; } -static int cmpboardname(const void *brd, const void *tmp) +static int cmpboardfriends(const void *brd, const void *tmp) { return ((boardstat_t *)tmp)->bh->nuser - ((boardstat_t *)brd)->bh->nuser; } @@ -411,40 +411,38 @@ static void load_boards(char *key) { load_uidofgid(class_bid,type); } brdnum = 0; - if(class_bid<=0) - { - nbrd = (boardstat_t *)malloc(numboards * sizeof(boardstat_t)); - for(i=0 ; i < numboards; i++) - { - if( (bptr = SHM->bsorted[type][i]) == NULL ) - continue; - n = (int)( bptr - bcache); - if(!bptr->brdname[0] || bptr->brdattr & BRD_GROUPBOARD || - !((state = Ben_Perm(bptr)) || (currmode & MODE_MENU)) || - (yank_flag == 0 && !(favbuf[n]&BRD_FAV)) || - (yank_flag == 1 && !zapbuf[n]) || - (key[0] && !strcasestr(bptr->title, key)) || - (class_bid==-1 && bptr->nuser<5) - ) continue; - addnewbrdstat(n, state); - if(class_bid==-1) - qsort(nbrd, brdnum, sizeof(boardstat_t), cmpboardname); + if(class_bid<=0){ + nbrd = (boardstat_t *)malloc(numboards * sizeof(boardstat_t)); + for(i=0 ; i < numboards; i++){ + if( (bptr = SHM->bsorted[type][i]) == NULL ) + continue; + n = (int)(bptr - bcache); + if( !bptr->brdname[0] || bptr->brdattr & BRD_GROUPBOARD || + !((state = Ben_Perm(bptr)) || (currmode & MODE_MENU)) || + (yank_flag == 0 && !(favbuf[n] & BRD_FAV)) || + (yank_flag == 1 && !zapbuf[n]) || + (key[0] && !strcasestr(bptr->title, key)) || + (class_bid == -1 && bptr->nuser < 5) ) + continue; + addnewbrdstat(n, state); + + if( class_bid == -1 ) + qsort(nbrd, brdnum, sizeof(boardstat_t), cmpboardfriends); } - } - else - { - nbrd = (boardstat_t *)malloc( bptr->childcount * sizeof(boardstat_t)); - for(bptr=bptr->firstchild[type]; bptr!=(boardheader_t *)~0; - bptr=bptr->next[type]) - { - n = (int)( bptr - bcache); - if(!((state = Ben_Perm(bptr)) || (currmode & MODE_MENU)) - ||(yank_flag == 0 && !(favbuf[n]&BRD_FAV)) - ||(yank_flag == 1 && !zapbuf[n]) || - (key[0] && !strcasestr(bptr->title, key))) continue; - addnewbrdstat(n, state); - } - } + } + else{ + nbrd = (boardstat_t *)malloc(bptr->childcount * sizeof(boardstat_t)); + for(bptr=bptr->firstchild[type]; bptr!=(boardheader_t *)~0; + bptr=bptr->next[type]) { + n = (int)( bptr - bcache); + if(!((state = Ben_Perm(bptr)) || (currmode & MODE_MENU)) + ||(yank_flag == 0 && !(favbuf[n] & BRD_FAV)) + ||(yank_flag == 1 && !zapbuf[n]) || + (key[0] && !strcasestr(bptr->title, key))) + continue; + addnewbrdstat(n, state); + } + } } static int search_board() { diff --git a/pttbbs/mbbsd/cache.c b/pttbbs/mbbsd/cache.c index d73dc0f1..1f67f7e0 100644 --- a/pttbbs/mbbsd/cache.c +++ b/pttbbs/mbbsd/cache.c @@ -1,4 +1,4 @@ -/* $Id: cache.c,v 1.36 2002/06/19 13:25:05 lwms Exp $ */ +/* $Id: cache.c,v 1.37 2002/06/26 01:12:48 in2 Exp $ */ #include "bbs.h" #ifndef __FreeBSD__ @@ -330,12 +330,14 @@ static int cmputmpfive(const void *i, const void *j){ return (*((userinfo_t**)i))->five_tie-(*((userinfo_t**)j))->five_tie; } +#if 0 static int cmputmpsex(const void *i, const void *j) { static int ladyfirst[]={1,0,1,0,1,0,3,3}; return ladyfirst[(*(userinfo_t**)i)->sex&07]- ladyfirst[(*(userinfo_t**)j)->sex&07]; } +#endif static int cmputmppid(const void *i, const void *j){ return (*((userinfo_t**)i))->pid-(*((userinfo_t**)j))->pid; } @@ -344,9 +346,10 @@ static int cmputmpuid(const void *i, const void *j){ } void sort_utmp() { - int count, i, ns; - userinfo_t *uentp; - now=time(0); + userinfo_t *uentp; + int count, i, ns; + short nusers[MAX_BOARD]; + now = time(0); if( now - SHM->UTMPuptime < 60 && (now == SHM->UTMPuptime || SHM->UTMPbusystate) ) return; /* lazy sort */ @@ -357,41 +360,45 @@ void sort_utmp() for( uentp = &SHM->uinfo[0], count = i = 0 ; i < USHM_SIZE ; ++i, uentp = &SHM->uinfo[i] ){ - if(uentp->pid) { - if(uentp->sex<0 || uentp->sex>7) - memset(uentp, 0, sizeof(userinfo_t)); + if( uentp->pid ){ + if( uentp->sex < 0 || uentp->sex > 7 ) + purge_utmp(uentp); else - SHM->sorted[ns][0][count++]= uentp; + SHM->sorted[ns][0][count++] = uentp; } } SHM->UTMPnumber = count; - qsort(SHM->sorted[ns][0],count,sizeof(userinfo_t*),cmputmpuserid); - for(i=0; i<count; i++) - ((userinfo_t*)SHM->sorted[ns][0][i])->idoffset=i; - memcpy(SHM->sorted[ns][1],SHM->sorted[ns][0], - sizeof(userinfo_t *)*count); - memcpy(SHM->sorted[ns][2],SHM->sorted[ns][0], - sizeof(userinfo_t *)*count); - memcpy(SHM->sorted[ns][3],SHM->sorted[ns][0], - sizeof(userinfo_t *)*count); - memcpy(SHM->sorted[ns][4],SHM->sorted[ns][0], - sizeof(userinfo_t *)*count); - memcpy(SHM->sorted[ns][5],SHM->sorted[ns][0], - sizeof(userinfo_t *)*count); - memcpy(SHM->sorted[ns][6],SHM->sorted[ns][0], - sizeof(userinfo_t *)*count); - memcpy(SHM->sorted[ns][7],SHM->sorted[ns][0], - sizeof(userinfo_t *)*count); - qsort(SHM->sorted[ns][1], count, sizeof(userinfo_t *), cmputmpmode ); - qsort(SHM->sorted[ns][2], count, sizeof(userinfo_t *), cmputmpidle ); - qsort(SHM->sorted[ns][3], count, sizeof(userinfo_t *), cmputmpfrom ); - qsort(SHM->sorted[ns][4], count, sizeof(userinfo_t *), cmputmpfive ); - qsort(SHM->sorted[ns][5], count, sizeof(userinfo_t *), cmputmpsex ); - qsort(SHM->sorted[ns][6], count, sizeof(userinfo_t *), cmputmpuid ); - qsort(SHM->sorted[ns][7], count, sizeof(userinfo_t *), cmputmppid ); + qsort(SHM->sorted[ns][0], count, sizeof(userinfo_t*), cmputmpuserid); + for( i = 0 ; i < count ; ++i ) + ((userinfo_t*)SHM->sorted[ns][0][i])->idoffset = i; + memcpy(SHM->sorted[ns][1],SHM->sorted[ns][0], sizeof(userinfo_t*) * count); + memcpy(SHM->sorted[ns][2],SHM->sorted[ns][0], sizeof(userinfo_t*) * count); + memcpy(SHM->sorted[ns][3],SHM->sorted[ns][0], sizeof(userinfo_t*) * count); + memcpy(SHM->sorted[ns][4],SHM->sorted[ns][0], sizeof(userinfo_t*) * count); + memcpy(SHM->sorted[ns][5],SHM->sorted[ns][0], sizeof(userinfo_t*) * count); + memcpy(SHM->sorted[ns][6],SHM->sorted[ns][0], sizeof(userinfo_t*) * count); + memcpy(SHM->sorted[ns][7],SHM->sorted[ns][0], sizeof(userinfo_t*) * count); + qsort(SHM->sorted[ns][1], count, sizeof(userinfo_t *), cmputmpmode); + qsort(SHM->sorted[ns][2], count, sizeof(userinfo_t *), cmputmpidle); + qsort(SHM->sorted[ns][3], count, sizeof(userinfo_t *), cmputmpfrom); + qsort(SHM->sorted[ns][4], count, sizeof(userinfo_t *), cmputmpfive); + //qsort(SHM->sorted[ns][5], count, sizeof(userinfo_t *), cmputmpsex); + qsort(SHM->sorted[ns][6], count, sizeof(userinfo_t *), cmputmpuid); + qsort(SHM->sorted[ns][7], count, sizeof(userinfo_t *), cmputmppid); SHM->currsorted=ns; SHM->UTMPbusystate=0; + + memset(nusers, 0, sizeof(nusers)); + for( i = 0 ; i < count ; ++i ){ + uentp = SHM->sorted[ns][0][i]; + if( uentp && uentp->pid && + 0 <= uentp->brc_id && uentp->brc_id < MAX_BOARD ) + ++nusers[ uentp->brc_id - 1 ]; + } + for( i = 0 ; i < MAX_BOARD ; ++i ) + SHM->bcache[i].nuser = nusers[i]; } + // Ptt:這邊加入hash觀念 找空的utmp void getnewutmpent(userinfo_t *up) { register int i, p ; diff --git a/pttbbs/mbbsd/talk.c b/pttbbs/mbbsd/talk.c index 51b318e5..7ff04cb4 100644 --- a/pttbbs/mbbsd/talk.c +++ b/pttbbs/mbbsd/talk.c @@ -1,4 +1,4 @@ -/* $Id: talk.c,v 1.70 2002/06/07 17:19:47 ptt Exp $ */ +/* $Id: talk.c,v 1.71 2002/06/26 01:12:48 in2 Exp $ */ #include "bbs.h" #define QCAST int (*)(const void *, const void *) @@ -1504,15 +1504,17 @@ static int pickup_myfriend(pickup_t *friends, static int pickup_bfriend(pickup_t *friends, int base) { - userinfo_t *ptr; - int ngets=0; + userinfo_t *uentp; + int i, ngets = 0; + int currsorted = SHM->currsorted, + number = SHM->UTMPnumber; friends = friends + base; - for( ptr = bcache[currutmp->brc_id - 1].u; - ptr != NULL && ngets < MAX_FRIEND-base ; - ptr = ptr->nextbfriend ){ - if( currutmp != ptr && isvisible(currutmp, ptr) && - (base || !(friend_stat(currutmp,ptr)&(IFH|HFM))) ){ - friends[ngets].ui = ptr; + for( i = 0 ; i < number && ngets < MAX_FRIEND - base ; ++i ){ + uentp = SHM->sorted[currsorted][0][i]; + if( uentp && uentp->pid && uentp->brc_id == currutmp->brc_id && + currutmp != uentp && isvisible(currutmp, uentp) && + (base || !(friend_stat(currutmp, uentp) & (IFH | HFM))) ){ + friends[ngets].ui = uentp; friends[ngets++].friend = IBH; } } @@ -1534,66 +1536,63 @@ static void pickup(pickup_t *currpickup, int pickup_way, int *page, *myfriend = *friendme = 1; if( cuser.uflag & FRIEND_FLAG || - (pickup_way == 0 && *page * MAXPICKUP < MAX_FRIEND ) ) - { + (pickup_way == 0 && *page * MAXPICKUP < MAX_FRIEND ) ){ /* [嗨! 朋友] mode. we need to pickup ALL friends (from currutmp friend_online), sort, and get pickup from right starting position */ pickup_t friends[MAX_FRIEND]; - + *nfriend = pickup_myfriend(friends, myfriend, friendme); - if( pickup_way == 0 ) - *bfriend=pickup_bfriend(friends,*nfriend); + if( pickup_way == 0 && currutmp->brc_id != 0 ) + *bfriend = pickup_bfriend(friends,*nfriend); else - *bfriend=0; + *bfriend=0; *nfriend += *bfriend; - which = *page * MAXPICKUP; - if(*nfriend>which) // Ptt: 只有在要秀出才有必要 sort - { - qsort(friends, *nfriend, sizeof(pickup_t), sort_cmpfriend); - size=*nfriend-which; - if(size>MAXPICKUP) size= MAXPICKUP; - memcpy(currpickup, friends+which, sizeof(pickup_t)*size); - } + which = *page * MAXPICKUP; + if( *nfriend > which ){ // Ptt: 只有在要秀出才有必要 sort + qsort(friends, *nfriend, sizeof(pickup_t), sort_cmpfriend); + size = *nfriend - which; + if( size > MAXPICKUP ) + size = MAXPICKUP; + memcpy(currpickup, friends + which, sizeof(pickup_t) * size); + } } else - *nfriend=0; + *nfriend=0; - if( !(cuser.uflag & FRIEND_FLAG) && size < MAXPICKUP ) - { + if( !(cuser.uflag & FRIEND_FLAG) && size < MAXPICKUP ){ sorted_way = ((pickup_way == 0) ? 0 : (pickup_way - 1)); utmp = SHM->sorted[currsorted][sorted_way]; which = *page * MAXPICKUP-*nfriend; - if(which<0) which=0; - for(;which < utmpnumber && size < MAXPICKUP;which++) - { - friend = friend_stat(currutmp,utmp[which]); - if((pickup_way||(currutmp != utmp[which] && - !(friend&ST_FRIEND))) && - isvisible_stat(currutmp, utmp[which], 0)) - { - currpickup[size].ui = utmp[which]; - currpickup[size++].friend = friend; - } - } - } -/* - for( which = (which >= 0 ? which : 0) ; - got < MAXPICKUP && which < utmpnumber ; - ++got, ++which ){ - - for( ; which < utmpnumber ; ++which ) - if( currutmp != utmp[which] && - isvisible_stat(currutmp, utmp[which], 0) ) - break; - if( which == utmpnumber ) - break; - currpickup[got].ui = utmp[which]; - currpickup[got].friend = 0; + if( which < 0 ) + which = 0; + for( ; which < utmpnumber && size < MAXPICKUP ; which++ ){ + friend = friend_stat(currutmp, utmp[which]); + if( ( pickup_way || + (currutmp != utmp[which] && !(friend & ST_FRIEND))) && + isvisible_stat(currutmp, utmp[which], 0)){ + currpickup[size].ui = utmp[which]; + currpickup[size++].friend = friend; + } } -*/ - + } + /* + for( which = (which >= 0 ? which : 0) ; + got < MAXPICKUP && which < utmpnumber ; + ++got, ++which ){ + + for( ; which < utmpnumber ; ++which ) + if( currutmp != utmp[which] && + isvisible_stat(currutmp, utmp[which], 0) ) + break; + if( which == utmpnumber ) + break; + currpickup[got].ui = utmp[which]; + currpickup[got].friend = 0; + } + */ + for( ; size < MAXPICKUP ; ++size ) currpickup[size].ui = 0; } -- cgit v1.2.3 From 713efb763fac8b3239890a1670af58a8c70a7452 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Wed, 26 Jun 2002 01:43:01 +0000 Subject: avoid some memory error (for last commiting board friends) git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@351 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/cache.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/pttbbs/mbbsd/cache.c b/pttbbs/mbbsd/cache.c index 1f67f7e0..9f62424b 100644 --- a/pttbbs/mbbsd/cache.c +++ b/pttbbs/mbbsd/cache.c @@ -1,4 +1,4 @@ -/* $Id: cache.c,v 1.37 2002/06/26 01:12:48 in2 Exp $ */ +/* $Id: cache.c,v 1.38 2002/06/26 01:43:01 in2 Exp $ */ #include "bbs.h" #ifndef __FreeBSD__ @@ -392,11 +392,12 @@ void sort_utmp() for( i = 0 ; i < count ; ++i ){ uentp = SHM->sorted[ns][0][i]; if( uentp && uentp->pid && - 0 <= uentp->brc_id && uentp->brc_id < MAX_BOARD ) + 0 < uentp->brc_id && uentp->brc_id < MAX_BOARD ) ++nusers[ uentp->brc_id - 1 ]; } - for( i = 0 ; i < MAX_BOARD ; ++i ) - SHM->bcache[i].nuser = nusers[i]; + for( i = 0 ; i < SHM->Bnumber ; ++i ) + if( SHM->bcache[i].brdname[0] != 0 ) + SHM->bcache[i].nuser = nusers[i]; } // Ptt:這邊加入hash觀念 找空的utmp -- cgit v1.2.3 From 0242f2dcd46bbe0ae30426c70cacde0e4a4bbe2f Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Wed, 26 Jun 2002 01:54:39 +0000 Subject: remove old board friend structure git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@352 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/include/pttstruct.h | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/pttbbs/include/pttstruct.h b/pttbbs/include/pttstruct.h index b91741e0..7b93c515 100644 --- a/pttbbs/include/pttstruct.h +++ b/pttbbs/include/pttstruct.h @@ -1,4 +1,4 @@ -/* $Id: pttstruct.h,v 1.19 2002/06/26 01:12:24 in2 Exp $ */ +/* $Id: pttstruct.h,v 1.20 2002/06/26 01:54:39 in2 Exp $ */ #ifndef INCLUDE_STRUCT_H #define INCLUDE_STRUCT_H @@ -115,7 +115,7 @@ typedef struct boardheader_t { void *parent; int childcount; /* 有多少個child */ int nuser; /* 多少人在這板 */ - void *u; /* 放板友 linked list用 */ + char pad5[4]; /* original void *u */ time_t endgamble; char pad3[84]; } boardheader_t; @@ -224,13 +224,13 @@ typedef struct userinfo_t { char birth; /* 是否是生日 Ptt*/ char tty[11]; /* tty port */ int friend[MAX_FRIEND]; - int friend_online[MAX_FRIEND]; /* point到線上好友 utmpshm的位置 */ - /* 好友比較的cache 前兩個bit是狀態 */ + int friend_online[MAX_FRIEND];/* point到線上好友 utmpshm的位置 */ + /* 好友比較的cache 前兩個bit是狀態 */ int reject[MAX_REJECT]; - void *nextbfriend; /* 用來做板友的linked list */ - int idoffset; /* shm id上的 offset */ + char pad[4]; /* original void *nextbfriend; */ + int idoffset; /* shm id上的 offset */ int lock; - int friendtotal; /* 好友比較的cache 大小 */ + int friendtotal; /* 好友比較的cache 大小 */ unsigned char msgcount; msgque_t msgs[MAX_MSGS]; time_t uptime; -- cgit v1.2.3 From 695a650c296da410c777b7f2f465c11db1aa092e Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Wed, 26 Jun 2002 01:55:30 +0000 Subject: remove old board friend structure, avoid some memory problem of new board friend git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@353 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/board.c | 40 ++-------------------------------------- pttbbs/mbbsd/cache.c | 7 +------ 2 files changed, 3 insertions(+), 44 deletions(-) diff --git a/pttbbs/mbbsd/board.c b/pttbbs/mbbsd/board.c index 9b6130b7..5578064d 100644 --- a/pttbbs/mbbsd/board.c +++ b/pttbbs/mbbsd/board.c @@ -1,4 +1,4 @@ -/* $Id: board.c,v 1.37 2002/06/26 01:12:48 in2 Exp $ */ +/* $Id: board.c,v 1.38 2002/06/26 01:55:30 in2 Exp $ */ #include "bbs.h" #define BRC_STRLEN 15 /* Length of board name */ #define BRC_MAXSIZE 24576 @@ -649,45 +649,9 @@ static void dozap(int num){ zapbuf[ptr->bid-1] = (ptr->myattr&BRD_ZAP?0:login_start_time); } -void delutmpbid(int bid, userinfo_t *utmp) -{ - userinfo_t *u; - while( SHM->Bbusystate || now - SHM->busystate_b[bid - 1] < 5 ) - sleep(1); - // Ptt:有問題都是這邊沒有執行到就爛掉了 - - SHM->busystate_b[bid-1] = now; - u = bcache[bid - 1].u; - if( u != (void *)utmp ){ - for( ; u && u->nextbfriend != (void*)utmp; u = u->nextbfriend ) - ; - if( u ) - u->nextbfriend = utmp->nextbfriend; - } - else - bcache[bid - 1].u = utmp->nextbfriend; - if( bcache[bid - 1].nuser > 0 ) - bcache[bid - 1].nuser--; - SHM->busystate_b[bid - 1] = 0; -} - void setutmpbid(int bid) { - if(currutmp->brc_id) - { - delutmpbid(currutmp->brc_id, currutmp); - } - if(bid) - { - bcache[bid-1].nuser++; - currutmp->nextbfriend=bcache[bid-1].u; - bcache[bid-1].u=(void*)currutmp; - } - else - { - currutmp->nextbfriend=0; - } - currutmp->brc_id=bid; + currutmp->brc_id=bid; } static void choose_board(int newflag) { diff --git a/pttbbs/mbbsd/cache.c b/pttbbs/mbbsd/cache.c index 9f62424b..9b14eb8a 100644 --- a/pttbbs/mbbsd/cache.c +++ b/pttbbs/mbbsd/cache.c @@ -1,4 +1,4 @@ -/* $Id: cache.c,v 1.38 2002/06/26 01:43:01 in2 Exp $ */ +/* $Id: cache.c,v 1.39 2002/06/26 01:55:30 in2 Exp $ */ #include "bbs.h" #ifndef __FreeBSD__ @@ -623,8 +623,6 @@ static void reload_bcache() { log_usies("CACHE", "reload bcache"); sort_bcache(); for( i = 0 ; i < SHM->Bnumber ; ++i ){ - bcache[i].u=NULL; - bcache[i].nuser=0; bcache[i].firstchild[0]=NULL; bcache[i].firstchild[1]=NULL; } @@ -654,7 +652,6 @@ void addbrd_touchcache() #if !defined(_BBS_UTIL_C_) void reset_board(int bid) { /* Ptt: 這樣就不用老是touch board了 */ int fd,i,nuser; - void *u; boardheader_t *bhdr; @@ -665,7 +662,6 @@ void reset_board(int bid) { /* Ptt: } else { SHM->busystate_b[bid-1] = now; nuser = bcache[bid-1].nuser; - u = bcache[bid-1].u; bhdr = bcache; bhdr += bid; @@ -681,7 +677,6 @@ void reset_board(int bid) { /* Ptt: bcache[i].firstchild[1]=NULL; } nuser = bcache[bid-1].nuser; - u = bcache[bid-1].u; SHM->busystate_b[bid-1] = 0; } } -- cgit v1.2.3 From f7ee60f71c658c483bc9f7ae2703abb829feaa8a Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Wed, 26 Jun 2002 01:57:49 +0000 Subject: remove fixbfriend git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@354 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/shmctl.c | 26 ++++---------------------- 1 file changed, 4 insertions(+), 22 deletions(-) diff --git a/pttbbs/util/shmctl.c b/pttbbs/util/shmctl.c index adf08640..2ce7982b 100644 --- a/pttbbs/util/shmctl.c +++ b/pttbbs/util/shmctl.c @@ -1,4 +1,4 @@ -/* $Id: shmctl.c,v 1.21 2002/06/13 15:10:50 in2 Exp $ */ +/* $Id: shmctl.c,v 1.22 2002/06/26 01:57:49 in2 Exp $ */ #include "bbs.h" extern SHM_t *SHM; @@ -169,11 +169,14 @@ static int cmputmpfive(const void *i, const void *j){ return (*((userinfo_t**)i))->five_tie-(*((userinfo_t**)j))->five_tie; } +#if 0 static int cmputmpsex(const void *i, const void *j){ static int ladyfirst[]={1,0,1,0,1,0,3,3}; return ladyfirst[(*((userinfo_t**)i))->sex]- ladyfirst[(*((userinfo_t**)j))->sex]; } +#endif + static int cmputmppid(const void *i, const void *j){ return (*((userinfo_t**)i))->pid-(*((userinfo_t**)j))->pid; } @@ -280,26 +283,6 @@ int setglobal(int argc, char **argv) return 0; } -int fixbfriend(int argc, char **argv) -{ - userinfo_t *ptr; - int count, i; - - for( i = 0 ; i < MAX_BOARD ; ++i ){ - if( isdigit(SHM->bcache[i].brdname[0]) || - isalpha(SHM->bcache[i].brdname[0]) ){ - for( count = 0, ptr = SHM->bcache[i].u ; - ptr != NULL && count < 256 ; - ++count, ptr = ptr->nextbfriend ) - ; - printf("counting %s\n", SHM->bcache[i].brdname); - SHM->bcache[i].nuser = ((count == 256) ? 0 : count); - } - } - - return 0; -} - struct { int (*func)(int, char **); char *cmd, *descript; @@ -312,7 +295,6 @@ struct { {utmpnum, "utmpnum", "print SHM->number for snmpd"}, {showglobal, "showglobal", "show GLOBALVAR[]"}, {setglobal, "setglobal", "set GLOBALVAR[]"}, - {fixbfriend, "fixbfriend", "recount numbers of board friends"}, {NULL, NULL, NULL} }; int main(int argc, char **argv) -- cgit v1.2.3 From 4bd12721b47205248416f5120be02d89268c6e08 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Wed, 26 Jun 2002 02:09:06 +0000 Subject: fix bug( Admin -> SetUserPasswd ) git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@355 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/user.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/pttbbs/mbbsd/user.c b/pttbbs/mbbsd/user.c index 0ba23981..786de5de 100644 --- a/pttbbs/mbbsd/user.c +++ b/pttbbs/mbbsd/user.c @@ -1,4 +1,4 @@ -/* $Id: user.c,v 1.24 2002/06/21 09:08:35 bbs Exp $ */ +/* $Id: user.c,v 1.25 2002/06/26 02:09:06 in2 Exp $ */ #include "bbs.h" static char *sex[8] = { @@ -192,12 +192,12 @@ static void violate_law(userec_t *u, int unum){ void uinfo_query(userec_t *u, int real, int unum) { userec_t x; register int i = 0, fail, mail_changed; + int uid; char ans[4], buf[STRLEN], *p; char genbuf[200], reason[50]; unsigned long int money = 0; fileheader_t fhdr; int flag = 0, temp = 0, money_change = 0; - time_t now; FILE *fp; @@ -367,7 +367,6 @@ void uinfo_query(userec_t *u, int real, int unum) { } else{ char witness[3][32]; - now= time(0); for(i=0;i<3;i++){ if(!getdata(19+i, 0, "請輸入協助證明之使用者:", witness[i], sizeof(witness[i]), DOECHO)){ @@ -375,14 +374,18 @@ void uinfo_query(userec_t *u, int real, int unum) { fail++; break; } - else if (!getuser(witness[i])){ + else if( !(uid = getuser(witness[i])) ){ outs("\n查無此使用者\n"); fail++; break; } - else if (now - u->firstlogin < 6*30*24*60*60){ - outs("\n註冊未超過半年,請重新輸入\n"); - i--; + else { + userec_t atuser; + passwd_query(uid, &atuser); + if (now - atuser.firstlogin < 6*30*24*60*60){ + outs("\n註冊未超過半年,請重新輸入\n"); + i--; + } } } if (i < 3) -- cgit v1.2.3 From b2865fc0fd368f7fe13294ced816406d860476c8 Mon Sep 17 00:00:00 2001 From: ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Wed, 26 Jun 2002 07:48:47 +0000 Subject: setproctitle("open ticket"); git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@356 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/gamble.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pttbbs/mbbsd/gamble.c b/pttbbs/mbbsd/gamble.c index 3d8ae234..839dbfa5 100644 --- a/pttbbs/mbbsd/gamble.c +++ b/pttbbs/mbbsd/gamble.c @@ -1,4 +1,4 @@ -/* $Id: gamble.c,v 1.22 2002/06/23 04:06:17 ptt Exp $ */ +/* $Id: gamble.c,v 1.23 2002/06/26 07:48:47 ptt Exp $ */ #include "bbs.h" #ifndef _BBS_UTIL_C_ @@ -264,6 +264,8 @@ int openticket(int bid) { } close(0); close(1); + setproctitle("open ticket"); + bet -= 1; //轉成矩陣的index -- cgit v1.2.3 From 0d721c0fb8ced41293e1cce17443a8876dd6b314 Mon Sep 17 00:00:00 2001 From: ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Wed, 26 Jun 2002 08:37:23 +0000 Subject: fix deleted board : git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@357 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/kaede.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/pttbbs/mbbsd/kaede.c b/pttbbs/mbbsd/kaede.c index 2f3d6a39..26d3ac54 100644 --- a/pttbbs/mbbsd/kaede.c +++ b/pttbbs/mbbsd/kaede.c @@ -1,4 +1,4 @@ -/* $Id: kaede.c,v 1.5 2002/06/22 07:35:44 ptt Exp $ */ +/* $Id: kaede.c,v 1.6 2002/06/26 08:37:23 ptt Exp $ */ #include "bbs.h" char *Ptt_prints(char *str, int mode) { @@ -55,8 +55,14 @@ char *Ptt_prints(char *str, int mode) { } int Rename(char* src, char* dst) { + char buf[256]; if(rename(src, dst) == 0) return 0; + if(!strchr(src,";") && !strchr(dst,";")) // Ptt 防不正常指令 + { + sprintf(buf,"/bin/mv %s %s",src,dst); + system(buf); + } return -1; } -- cgit v1.2.3 From 94c3d406a0b316cee9f46c5ff0c98648d2f214c0 Mon Sep 17 00:00:00 2001 From: ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Wed, 26 Jun 2002 08:39:07 +0000 Subject: I am idoit git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@358 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/kaede.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pttbbs/mbbsd/kaede.c b/pttbbs/mbbsd/kaede.c index 26d3ac54..e529aa3d 100644 --- a/pttbbs/mbbsd/kaede.c +++ b/pttbbs/mbbsd/kaede.c @@ -1,4 +1,4 @@ -/* $Id: kaede.c,v 1.6 2002/06/26 08:37:23 ptt Exp $ */ +/* $Id: kaede.c,v 1.7 2002/06/26 08:39:07 ptt Exp $ */ #include "bbs.h" char *Ptt_prints(char *str, int mode) { @@ -58,7 +58,7 @@ int Rename(char* src, char* dst) { char buf[256]; if(rename(src, dst) == 0) return 0; - if(!strchr(src,";") && !strchr(dst,";")) // Ptt 防不正常指令 + if(!strchr(src,';') && !strchr(dst,';')) // Ptt 防不正常指令 { sprintf(buf,"/bin/mv %s %s",src,dst); system(buf); -- cgit v1.2.3 From ee75ea5077c0981be92d20089ef1d2229767298a Mon Sep 17 00:00:00 2001 From: ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Wed, 26 Jun 2002 08:47:51 +0000 Subject: fix deleted brd git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@359 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/bbs.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pttbbs/mbbsd/bbs.c b/pttbbs/mbbsd/bbs.c index cf3618b3..44442a45 100644 --- a/pttbbs/mbbsd/bbs.c +++ b/pttbbs/mbbsd/bbs.c @@ -1,4 +1,4 @@ -/* $Id: bbs.c,v 1.60 2002/06/23 03:57:48 ptt Exp $ */ +/* $Id: bbs.c,v 1.61 2002/06/26 08:47:51 ptt Exp $ */ #include "bbs.h" static void mail_by_link(char* owner, char* title, char* path) { @@ -323,6 +323,7 @@ static void cancelpost(fileheader_t *fh, int by_BM) { fclose(fin); Rename(fn1, fn2); setbdir(genbuf, brd); + setbtotal(getbnum(brd)); append_record(genbuf, &postfile, sizeof(postfile)); } } -- cgit v1.2.3 From a8c9e25dbe6e256004374f01270ecb9c80788dbb Mon Sep 17 00:00:00 2001 From: ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Wed, 26 Jun 2002 09:49:37 +0000 Subject: remove bbcall.c should add SMS now ont bbcall git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@360 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/Makefile | 4 ++-- pttbbs/mbbsd/board.c | 6 +----- pttbbs/mbbsd/menu.c | 3 +-- 3 files changed, 4 insertions(+), 9 deletions(-) diff --git a/pttbbs/mbbsd/Makefile b/pttbbs/mbbsd/Makefile index 03bdc07f..af2d3a7a 100644 --- a/pttbbs/mbbsd/Makefile +++ b/pttbbs/mbbsd/Makefile @@ -1,4 +1,4 @@ -# $Id: Makefile,v 1.9 2002/06/04 13:11:38 in2 Exp $ +# $Id: Makefile,v 1.10 2002/06/26 09:49:37 ptt Exp $ BBSHOME?=$(HOME) OSTYPE=FreeBSD @@ -36,7 +36,7 @@ CFLAGS+= -DNO_FORK CC= gcc PROG= mbbsd -OBJS= admin.o announce.o args.o bbcall.o bbs.o board.o cache.o cal.o card.o\ +OBJS= admin.o announce.o args.o bbs.o board.o cache.o cal.o card.o\ chat.o chc_draw.o chc_net.o chc_play.o chc_rule.o chicken.o dark.o\ dice.o edit.o friend.o gamble.o gomo.o gomo1.o guess.o indict.o io.o\ kaede.o lovepaper.o mail.o mbbsd.o menu.o more.o name.o osdep.o\ diff --git a/pttbbs/mbbsd/board.c b/pttbbs/mbbsd/board.c index 5578064d..d85a45ae 100644 --- a/pttbbs/mbbsd/board.c +++ b/pttbbs/mbbsd/board.c @@ -1,4 +1,4 @@ -/* $Id: board.c,v 1.38 2002/06/26 01:55:30 in2 Exp $ */ +/* $Id: board.c,v 1.39 2002/06/26 09:49:37 ptt Exp $ */ #include "bbs.h" #define BRC_STRLEN 15 /* Length of board name */ #define BRC_MAXSIZE 24576 @@ -649,10 +649,6 @@ static void dozap(int num){ zapbuf[ptr->bid-1] = (ptr->myattr&BRD_ZAP?0:login_start_time); } -void setutmpbid(int bid) -{ - currutmp->brc_id=bid; -} static void choose_board(int newflag) { static int num = 0; diff --git a/pttbbs/mbbsd/menu.c b/pttbbs/mbbsd/menu.c index 3fa138f1..d06481b0 100644 --- a/pttbbs/mbbsd/menu.c +++ b/pttbbs/mbbsd/menu.c @@ -1,4 +1,4 @@ -/* $Id: menu.c,v 1.11 2002/06/19 13:32:23 lwms Exp $ */ +/* $Id: menu.c,v 1.12 2002/06/26 09:49:37 ptt Exp $ */ #include "bbs.h" /* help & menu processring */ @@ -326,7 +326,6 @@ static commands_t maillist[] = { {m_new, PERM_READMAIL, "RNew 閱\讀新進郵件"}, {m_read, PERM_READMAIL, "RRead 多功\能讀信選單"}, {m_send, PERM_BASIC, "RSend 站內寄信"}, - {main_bbcall, PERM_LOGINOK, "BBBcall \033[1;31m電話秘書\033[m"}, {x_love, PERM_LOGINOK, "PPaper \033[1;32m情書產生器\033[m "}, {mail_list, PERM_BASIC, "RMail List 群組寄信"}, {setforward, PERM_LOGINOK,"FForward \033[32m設定信箱自動轉寄\033[m"}, -- cgit v1.2.3 From 73df647f53be0329d484c593d600aaba01428ceb Mon Sep 17 00:00:00 2001 From: ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Wed, 26 Jun 2002 09:51:33 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@361 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/include/proto.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pttbbs/include/proto.h b/pttbbs/include/proto.h index 8cccf526..2f916219 100644 --- a/pttbbs/include/proto.h +++ b/pttbbs/include/proto.h @@ -1,4 +1,4 @@ -/* $Id: proto.h,v 1.22 2002/06/23 03:50:56 ptt Exp $ */ +/* $Id: proto.h,v 1.23 2002/06/26 09:51:33 ptt Exp $ */ #ifndef INCLUDE_PROTO_H #define INCLUDE_PROTO_H @@ -53,7 +53,7 @@ int board_etc(); int board_digest(); /* board */ -void setutmpbid(int bid); +#define setutmpbid(bid) currutmp->brc_id=bid; int brc_unread(char *fname, int bnum, int *blist); int brc_initial(char *boardname); void brc_update(); -- cgit v1.2.3 From a976d079af330afea7fea17b41124509475afa58 Mon Sep 17 00:00:00 2001 From: ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Wed, 26 Jun 2002 09:52:56 +0000 Subject: remove bbcall.o git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@362 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd.icc/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pttbbs/mbbsd.icc/Makefile b/pttbbs/mbbsd.icc/Makefile index 169b6f29..6d7e5f53 100644 --- a/pttbbs/mbbsd.icc/Makefile +++ b/pttbbs/mbbsd.icc/Makefile @@ -2,7 +2,7 @@ BBSHOME=/home/bbs PROG= mbbsd.icc -OBJS= admin.o announce.o args.o bbcall.o bbs.o board.o cache.o cal.o card.o\ +OBJS= admin.o announce.o args.o bbs.o board.o cache.o cal.o card.o\ chat.o chc_draw.o chc_net.o chc_play.o chc_rule.o chicken.o dark.o\ dice.o edit.o friend.o gamble.o gomo.o gomo1.o guess.o indict.o io.o\ kaede.o lovepaper.o mail.o mbbsd.o menu.o more.o name.o osdep.o\ -- cgit v1.2.3 From 4673ae2814ec3524d2ab37b48d4e697dcf0386eb Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Wed, 26 Jun 2002 14:36:07 +0000 Subject: remove nuser from SHM git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@363 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/include/pttstruct.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pttbbs/include/pttstruct.h b/pttbbs/include/pttstruct.h index 7b93c515..d570bc57 100644 --- a/pttbbs/include/pttstruct.h +++ b/pttbbs/include/pttstruct.h @@ -1,4 +1,4 @@ -/* $Id: pttstruct.h,v 1.20 2002/06/26 01:54:39 in2 Exp $ */ +/* $Id: pttstruct.h,v 1.21 2002/06/26 14:36:07 in2 Exp $ */ #ifndef INCLUDE_STRUCT_H #define INCLUDE_STRUCT_H @@ -328,7 +328,6 @@ typedef struct { time_t Btouchtime; int Bnumber; int Bbusystate; - short nusers[MAX_BOARD]; char gap2[1024]; /* avoid some memory error / buffer overflow */ /* pttcache */ -- cgit v1.2.3 From f92d45bb864ec0987fee8a04737553beeac09510 Mon Sep 17 00:00:00 2001 From: kcwu <kcwu@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Wed, 26 Jun 2002 17:07:41 +0000 Subject: bad file git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@364 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/DEADJOE | 9 --------- 1 file changed, 9 deletions(-) delete mode 100644 pttbbs/util/DEADJOE diff --git a/pttbbs/util/DEADJOE b/pttbbs/util/DEADJOE deleted file mode 100644 index a0793f05..00000000 --- a/pttbbs/util/DEADJOE +++ /dev/null @@ -1,9 +0,0 @@ - -*** Modified files in JOE when it aborted on Thu Nov 22 19:30:21 2001 -*** JOE was aborted by signal 1 - -*** Modified files in JOE when it aborted on Mon Nov 26 09:50:15 2001 -*** JOE was aborted because the terminal closed - -*** File '(Unnamed)' -BBSNAME -- cgit v1.2.3 From 9becd3e9fbd1e5d34fcf5bddbb5d56aba98fd2a9 Mon Sep 17 00:00:00 2001 From: kcwu <kcwu@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Wed, 26 Jun 2002 17:34:22 +0000 Subject: ignore executable 'splitpasswd' git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@365 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/.cvsignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pttbbs/util/.cvsignore b/pttbbs/util/.cvsignore index 982f6b1b..5b0fde27 100644 --- a/pttbbs/util/.cvsignore +++ b/pttbbs/util/.cvsignore @@ -42,3 +42,5 @@ bbsctl mandex shmctl mdclean +splitpasswd + -- cgit v1.2.3 From ba32015cbcfad3e1291445e3e5637f76d58fbc5a Mon Sep 17 00:00:00 2001 From: kcwu <kcwu@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Wed, 26 Jun 2002 18:05:49 +0000 Subject: build broken due to: function name 'gettime' conflits with the other in stuff.c git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@366 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/bbcall.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pttbbs/mbbsd/bbcall.c b/pttbbs/mbbsd/bbcall.c index 7e511686..29b39abc 100644 --- a/pttbbs/mbbsd/bbcall.c +++ b/pttbbs/mbbsd/bbcall.c @@ -1,4 +1,4 @@ -/* $Id: bbcall.c,v 1.3 2002/06/04 13:08:33 in2 Exp $ */ +/* $Id: bbcall.c,v 1.4 2002/06/26 18:05:49 kcwu Exp $ */ #include "bbs.h" #define SERVER_0941 "www.chips.com.tw" @@ -39,7 +39,7 @@ static void pager_msg_encode(char *field, char *buf) { *cc = 0; } -static void gettime(int flag, int *Year, int *Month, int *Day, int *Hour, +static void Gettime(int flag, int *Year, int *Month, int *Day, int *Hour, int *Minute) { char ans[5]; @@ -149,7 +149,7 @@ static void halpha0943(char* CoId) { "如果要定時送請按 '2': \033[m", ans, sizeof(ans), LCECHO); if(ans[0] != '1') - gettime(0, &Year, &Month, &Day, &Hour, &Minute); + Gettime(0, &Year, &Month, &Day, &Hour, &Minute); sprintf(atrn, "CoId=%s&ID=%s&Year=19%02d&Month=%02d&Day=%02d" "&Hour=%02d&Minute=%02d&Msg=%s", @@ -178,7 +178,7 @@ static void hcall0941() { "如果要定時送請按 '2': \033[m", ans, sizeof(ans), LCECHO); if(ans[0] != '1') { strcpy(TIME,"DELAY"); - gettime(0, &year, &month, &day, &hour, &min); + Gettime(0, &year, &month, &day, &hour, &min); } else strcpy(TIME,"NOW"); sprintf(trn,"PAGER_NO=%s&TRAN_MSG=%s&MSG_TYPE=NUMERIC&%s=1" @@ -210,7 +210,7 @@ static void hcall0948() { getdata(9, 0, "\033[1;37m如果你要馬上送請按 '1' " "如果要定時送請按 '2'\033[m: ", ans, sizeof(ans), LCECHO); if(ans[0] != '1') { - gettime(1, &year, &month, &day, &hour, &min); + Gettime(1, &year, &month, &day, &hour, &min); ya = 1; } -- cgit v1.2.3 From 3456b3026ef137e03eaedaca2e29a326a296ba45 Mon Sep 17 00:00:00 2001 From: kcwu <kcwu@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Wed, 26 Jun 2002 19:38:16 +0000 Subject: it seems no one need 'libutil' git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@367 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pttbbs/mbbsd/Makefile b/pttbbs/mbbsd/Makefile index af2d3a7a..54882a35 100644 --- a/pttbbs/mbbsd/Makefile +++ b/pttbbs/mbbsd/Makefile @@ -1,4 +1,4 @@ -# $Id: Makefile,v 1.10 2002/06/26 09:49:37 ptt Exp $ +# $Id: Makefile,v 1.11 2002/06/26 19:38:16 kcwu Exp $ BBSHOME?=$(HOME) OSTYPE=FreeBSD @@ -6,7 +6,7 @@ OSTYPE=FreeBSD # FreeBSD CFLAGS_FreeBSD= -pipe -Wall -DHAVE_SETPROCTITLE -DBBSHOME='"$(BBSHOME)"' -DFreeBSD -I../include LDFLAGS_FreeBSD=-pipe -Wall -LIBS_FreeBSD= -lutil -lkvm -lcrypt +LIBS_FreeBSD= -lkvm -lcrypt # Linux CFLAGS_linux= -pipe -Wall -DHAVE_DES_CRYPT -DBBSHOME='"$(BBSHOME)"' -DLinux -I../include -s -- cgit v1.2.3 From 938911bb14262a570aaad5d6c98352d9e76f5de0 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Thu, 27 Jun 2002 12:44:22 +0000 Subject: new crontab git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@368 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/sample/crontab | 129 ++++++++++++++++++++++++++++++++-------------- pttbbs/sample/crontab.old | 56 ++++++++++++++++++++ 2 files changed, 146 insertions(+), 39 deletions(-) create mode 100644 pttbbs/sample/crontab.old diff --git a/pttbbs/sample/crontab b/pttbbs/sample/crontab index 5acc8403..06769ac9 100644 --- a/pttbbs/sample/crontab +++ b/pttbbs/sample/crontab @@ -1,56 +1,107 @@ -20 7 * * * bin/mailog.sh > /dev/null -20 6 * * * rm -f out/*; rm -f out/.DIR +# 信件紀錄 +20 7 * * * bin/mailog.sh -# 每天 12:00 17:00 20:00 00:00 開獎。 -0 2,11,16,21 * * * bin/openticket.sh > /dev/null +# 每天 2:00, 11:00, 16:00, 21:00 開獎 +0 2,11,16,21 * * * bin/openticket.sh # 每天早上清除過期使用者 -10 7 * * * bin/reaper > /dev/null 2> /dev/null +#10 7 * * * bin/reaper -# 每個小時 1 分執行上站人次統計 -1 * * * * bin/account > /dev/null 2> /dev/null +# 每個小時 1分執行上站人次統計 +1 * * * * bin/account # 每個小時 10 分執行熱門話題統計 -50 * * * * bin/parse_news -10 * * * * bin/poststat /home/bbs > /dev/null +#50 * * * * bin/parse_news +10 * * * * bin/poststat -# 每天5:30執行使用者排行榜更新 -30 5 * * * bin/topusr 10 etc/topusr > /dev/null -30 3 * * * bin/topusr 100 etc/topusr100 > /dev/null -30 5 * * * bin/yearsold > /dev/null -30 5 * * * bin/horoscope +# 每天 5:30 執行使用者排行榜更新 +30 5 * * * bin/topusr 10 etc/topusr +30 5 * * * bin/topusr 100 etc/topusr100 +30 5 * * * bin/yearsold +30 5 * * * bin/horoscope -# 每個月一, 十五號點歌排行榜 -20 6 1,15 * * bin/topsong.sh +# 每個月初一, 十五點歌排行榜 +20 6 1,15 * * bin/topsong.sh -# 每週三,六統計轉信所有板 -35 6 * * 6 bin/showboard ~/.BOARDS > ~/etc/BOARD.rec +# 每週三, 六統計轉信所有板 +35 6 * * 6 bin/showboard ~/.BOARDS -# 每週一早上把user home清一清 -20 3 * * * (/bin/rm -f logins.bad; bin/expire ) > /dev/null -1 7 * * 1 bin/deluserfile > /dev/null +# 每天清 logins.bad +20 3 * * * /bin/rm -f logins.bad -# 每週二早上 4:30 , 將 BBS boards 中超過七天的 SR. 系列的檔案砍掉 -30 4 * * 2 /usr/bin/find /home/bbs/boards/ -mtime +7 -name SR\* -exec rm -f {} ';' -30 4 * * 2 /bin/rm -f ~/tmp/* +# 清版 (視情況用每天或每週) +20 3 * * 1 bin/expire -# 每天執行一次生日程 -1 2 * * * bin/birth > /dev/null +# 清使用者目錄 +1 7 * * 1 bin/deluserfile -# 每天精華區index一次 index前砍掉deleted的精華區 -15 6 * * * rm -rf man/boards/deleted -20 6 * * * bin/mandex > /dev/null -30 6 * * * bin/openvice > /dev/null +# 每週二早上 4:30 , 將 BBS boards 中超過七天的 SR. 系列及 ~/tmp/的檔案砍掉, +30 4 * * 2 /usr/bin/find /home/bbs/boards/ -mtime +7 -name SR\* -exec rm -f {} ';' +30 4 * * 2 /bin/rm -f ~/tmp/* -# 每天砍掉點歌超過5天檔案 -40 6 * * * ( find /home/bbs/etc/SONGO/M* -mtime +5 -exec rm -f {} ';' ) +# 每天執行一次生日程式 +1 2 * * * bin/birth -#天氣股票 -0 5,11,17,23 * * * bin/weather.sh > /dev/null -20 12 * * * bin/stock.sh > /dev/null +# 除每月一號整個重新計算精華區, 其他都只在星期二, 四, 六算有更動過的 +# 計算前先砍掉 deleted的精華區 +20 6 * * * /bin/rm -rf man/boards/d/deleted; mkdir man/boards/d/deleted +30 6 1 * * bin/mandex +30 6 2-31 * 2,4,6 bin/mandex -x -# 每個月一號早上 3:50 , 將 BBS 系統中長度為零的檔案砍掉 -50 3 1 * * ( /usr/bin/find /home1/bbs -size 0 -exec rm -f {} ';' ) +# 每天發票開獎 +40 6 * * * bin/openvice -#每天早上 6:30 把bbs中的home和passwords備份 -30 6 * * * bin/backpasswd.sh > /dev/null +# 每天砍掉點歌超過 5天檔案 +0 7 * * * /usr/bin/find /home/bbs/etc/SONGO/M* -mtime +5 -exec rm -f {} ';' + +# 天氣, 股票 +0 5,11,17,23 * * * bin/weather.sh +20 12 * * * bin/stock.sh + +# 每個月十號早上 3:50 , 將 BBS 系統中長度為零的檔案砍掉 +50 3 10 * * /usr/bin/find /home/bbs/boards/*/ -size 0 -exec rm -f {} ';' ; /usr/bin/find /home/bbs/home/*/ -size 0 -exec rm -f {} ';' + +# 每天早上 6:50 備份 .PASSWDS, .BRD +50 6 * * * bin/backpasswd.sh + + +# mrtg每五分鐘計算一次 +*/5 * * * * bin/shmctl utmpnum > /tmp/utmpnum +*/5 * * * * bin/lookhdd.pl > /tmp/hdd +*/5 * * * * /usr/local/bin/getuptime -x > /tmp/uptime +*/5 * * * * /bin/ps -ax | /usr/bin/wc -l > /tmp/nps + +# ??? +10 7 * * * bin/buildAnnounce +#10 7 * * * bin/toplazyBM.sh +#10 7 * * * bin/toplazyBBM.sh +#*/5 * * * * bin/shmsweep +#*/10 * * * * bin/userlist + +# 轉信 +*/30 * * * * (kill -0 `cat /tmp/innbbsd-7777.pid` || innd/innbbsd 7777) +0,30 2-21 * * * innd/bbslink /home/bbs +0 3 * * * bin/inndBM +10 3 * * * innd/ctlinnbbsd reload +17,47 2,4-21 * * * innd/bbsnnrpall.auto.sh +40 3 * * * /bin/mv innd/bbslog innd/bbslog.old +40 2 * * * /bin/mv innd/log/inndBM.log innd/log/inndBM.log.old +40 2 * * * /bin/mv innd/log/inndBM.log.err innd/log/inndBM.log.err.old + +# jobspool +10 3-20 * * * bin/waterball.pl +30 3 * * * bin/tarqueue.pl + +# 每日備份 +30 3 * * * bin/dailybackup.pl + +# 每日砍除 ALLPOST +30 5 * * * /bin/rm boards/A/ALLPOST; mkdir bords/A/ALLPOST + +# utmpfix +0 2-20 * * * bin/shmctl utmpfix -n +0 21 * * * bin/shmctl utmpfix -t 10800 +10 21 * * * bin/shmctl utmpfix -t 7200 +20 21 * * * bin/shmctl utmpfix -t 3600 +30,40,50 21 * * * bin/shmctl utmpfix -t 1800 +*/20 22,23,0,1 * * * bin/shmctl utmpfix -t 1200 diff --git a/pttbbs/sample/crontab.old b/pttbbs/sample/crontab.old new file mode 100644 index 00000000..5acc8403 --- /dev/null +++ b/pttbbs/sample/crontab.old @@ -0,0 +1,56 @@ +20 7 * * * bin/mailog.sh > /dev/null +20 6 * * * rm -f out/*; rm -f out/.DIR + +# 每天 12:00 17:00 20:00 00:00 開獎。 +0 2,11,16,21 * * * bin/openticket.sh > /dev/null + +# 每天早上清除過期使用者 +10 7 * * * bin/reaper > /dev/null 2> /dev/null + +# 每個小時 1 分執行上站人次統計 +1 * * * * bin/account > /dev/null 2> /dev/null + +# 每個小時 10 分執行熱門話題統計 +50 * * * * bin/parse_news +10 * * * * bin/poststat /home/bbs > /dev/null + +# 每天5:30執行使用者排行榜更新 +30 5 * * * bin/topusr 10 etc/topusr > /dev/null +30 3 * * * bin/topusr 100 etc/topusr100 > /dev/null +30 5 * * * bin/yearsold > /dev/null +30 5 * * * bin/horoscope + +# 每個月一, 十五號點歌排行榜 +20 6 1,15 * * bin/topsong.sh + +# 每週三,六統計轉信所有板 +35 6 * * 6 bin/showboard ~/.BOARDS > ~/etc/BOARD.rec + +# 每週一早上把user home清一清 +20 3 * * * (/bin/rm -f logins.bad; bin/expire ) > /dev/null +1 7 * * 1 bin/deluserfile > /dev/null + +# 每週二早上 4:30 , 將 BBS boards 中超過七天的 SR. 系列的檔案砍掉 +30 4 * * 2 /usr/bin/find /home/bbs/boards/ -mtime +7 -name SR\* -exec rm -f {} ';' +30 4 * * 2 /bin/rm -f ~/tmp/* + +# 每天執行一次生日程 +1 2 * * * bin/birth > /dev/null + +# 每天精華區index一次 index前砍掉deleted的精華區 +15 6 * * * rm -rf man/boards/deleted +20 6 * * * bin/mandex > /dev/null +30 6 * * * bin/openvice > /dev/null + +# 每天砍掉點歌超過5天檔案 +40 6 * * * ( find /home/bbs/etc/SONGO/M* -mtime +5 -exec rm -f {} ';' ) + +#天氣股票 +0 5,11,17,23 * * * bin/weather.sh > /dev/null +20 12 * * * bin/stock.sh > /dev/null + +# 每個月一號早上 3:50 , 將 BBS 系統中長度為零的檔案砍掉 +50 3 1 * * ( /usr/bin/find /home1/bbs -size 0 -exec rm -f {} ';' ) + +#每天早上 6:30 把bbs中的home和passwords備份 +30 6 * * * bin/backpasswd.sh > /dev/null -- cgit v1.2.3 From 6e8f20903e8fd0d150cdec716acd063cc2fb8125 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Thu, 27 Jun 2002 16:33:20 +0000 Subject: fix bug git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@369 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/sample/crontab | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pttbbs/sample/crontab b/pttbbs/sample/crontab index 06769ac9..eddf5f48 100644 --- a/pttbbs/sample/crontab +++ b/pttbbs/sample/crontab @@ -24,7 +24,7 @@ 20 6 1,15 * * bin/topsong.sh # 每週三, 六統計轉信所有板 -35 6 * * 6 bin/showboard ~/.BOARDS +35 6 * * 6 bin/showboard .BOARDS > etc/BOARD.rec # 每天清 logins.bad 20 3 * * * /bin/rm -f logins.bad -- cgit v1.2.3 From d62612b42e386737261ac940cea3396b38024ca3 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Thu, 27 Jun 2002 19:41:46 +0000 Subject: this shouldn't exist git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@370 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/uptime | 23 ----------------------- 1 file changed, 23 deletions(-) delete mode 100644 pttbbs/mbbsd/uptime diff --git a/pttbbs/mbbsd/uptime b/pttbbs/mbbsd/uptime deleted file mode 100644 index 4f8281fb..00000000 --- a/pttbbs/mbbsd/uptime +++ /dev/null @@ -1,23 +0,0 @@ -cache.c: if(fcache->busystate) -cache.c: fcache->busystate = 1; -cache.c: bzero(fcache->domain, sizeof fcache->domain); -cache.c: fcache->top=0; -cache.c: sscanf(buf,"%s",fcache->domain[fcache->top]); -cache.c: po = buf + strlen(fcache->domain[fcache->top]); -cache.c: strncpy(fcache->replace[fcache->top],po,49); -cache.c: fcache->replace[fcache->top] -cache.c: [strlen(fcache->replace[fcache->top])-1] = 0; -cache.c: (fcache->top)++; -cache.c: if(fcache->top == MAX_FROM) -cache.c: fcache->max_user=0; -cache.c: fcache->uptime = fcache->touchtime; -cache.c: fcache->busystate = 0; -cache.c: if(fcache->touchtime == 0) -cache.c: fcache->touchtime = 1; -cache.c: while(fcache->uptime < fcache->touchtime) -mbbsd.c: for (j = 0; j < fcache->top; j++){ -mbbsd.c: char *token = strtok (fcache->domain[j], "&"); -mbbsd.c: if ((a = utmpshm->number) > fcache->max_user){ -mbbsd.c: fcache->max_user = a; -mbbsd.c: fcache->max_time = now; -talk.c: uentp->from_alias ? fcache->replace[uentp->from_alias] : -- cgit v1.2.3 From 6555b3ae981547ba980a778cf6abd07fbee00730 Mon Sep 17 00:00:00 2001 From: kcwu <kcwu@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Thu, 27 Jun 2002 19:49:48 +0000 Subject: change the valid email address char set from "[].%!@:-_;" to "[].@-_" quote the placeholder %s of address git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@371 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/mail.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pttbbs/mbbsd/mail.c b/pttbbs/mbbsd/mail.c index 65141096..f4ba6d64 100644 --- a/pttbbs/mbbsd/mail.c +++ b/pttbbs/mbbsd/mail.c @@ -1,4 +1,4 @@ -/* $Id: mail.c,v 1.13 2002/06/19 13:32:23 lwms Exp $ */ +/* $Id: mail.c,v 1.14 2002/06/27 19:49:48 kcwu Exp $ */ #include "bbs.h" char currmaildir[32]; static char msg_cc[] = "\033[32m[群組名單]\033[m\n"; @@ -94,7 +94,7 @@ int invalidaddr(char *addr) { if(*addr == '\0') return 1; /* blank */ while(*addr) { - if(not_alnum(*addr) && !strchr("[].%!@:-_;", *addr)) + if(not_alnum(*addr) && !strchr("[].@-_", *addr)) return 1; addr++; } @@ -1506,7 +1506,7 @@ int doforward(char *direct, fileheader_t *fh, int mode) { if(mode == 'Z') { sprintf(fname, TAR_PATH " cfz /tmp/home.%s.tgz home/%c/%s; " - MUTT_PATH" -a /tmp/home.%s.tgz -s 'home.%s.tgz' %s </dev/null;" + MUTT_PATH" -a /tmp/home.%s.tgz -s 'home.%s.tgz' '%s' </dev/null;" "rm /tmp/home.%s.tgz", cuser.userid, cuser.userid[0], cuser.userid, cuser.userid, cuser.userid, address, cuser.userid); -- cgit v1.2.3 From cebefff6f9f8eb63c17d0c90136733a77ece44f2 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Fri, 28 Jun 2002 14:17:22 +0000 Subject: two mail relay servers git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@372 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/outmail.c | 92 ++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 76 insertions(+), 16 deletions(-) diff --git a/pttbbs/util/outmail.c b/pttbbs/util/outmail.c index d6b19bb4..c66929cb 100644 --- a/pttbbs/util/outmail.c +++ b/pttbbs/util/outmail.c @@ -1,4 +1,4 @@ -/* $Id: outmail.c,v 1.1 2002/03/07 15:13:46 in2 Exp $ */ +/* $Id: outmail.c,v 1.2 2002/06/28 14:17:22 in2 Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -91,6 +91,9 @@ void setproctitle(const char* format, ...) { #define NEWINDEX SPOOL "/.DIR.sending" #define FROM ".bbs@" MYHOSTNAME #define SMTPPORT 25 +char *smtpname, *hiname; +int smtpport, hiport; + int waitReply(int sock) { char buf[256]; @@ -105,7 +108,8 @@ int sendRequest(int sock, char *request) { return write(sock, request, strlen(request)) < 0 ? -1 : 0; } -int connectMailServer() { +int connectMailServer(char *servername, int serverport) +{ int sock; struct sockaddr_in addr; @@ -119,11 +123,13 @@ int connectMailServer() { addr.sin_len = sizeof(addr); #endif addr.sin_family = AF_INET; - addr.sin_port = htons(SMTPPORT); - addr.sin_addr.s_addr = inet_addr(RELAY_SERVER_IP); + addr.sin_port = htons(serverport); + addr.sin_addr.s_addr = inet_addr(servername); if(connect(sock, (struct sockaddr *)&addr, sizeof(addr)) < 0) { - perror(RELAY_SERVER_IP); + printf("servername: %s\n", servername); + perror(servername); + exit(0); close(sock); return -1; } @@ -182,7 +188,7 @@ void doSendMail(int sock, FILE *fp, char *from, char *to, char *subject) { } void sendMail() { - int fd, sock; + int fd, smtpsock, hisock; MailQueue mq; if(access(NEWINDEX, R_OK | W_OK)) { @@ -190,9 +196,16 @@ void sendMail() { /* nothing to do */ return; } - - if((sock = connectMailServer()) < 0) { - fprintf(stderr, "connect server failed...\n"); + + smtpsock = connectMailServer(smtpname, smtpport); + hisock = (hiname != NULL) ? connectMailServer(hiname, hiport) : -1; + + if( smtpsock < 0 && hisock >= 0 ){ + smtpsock = hisock; + hisock = -1; + } + if( smtpsock < 0 && hisock < 0 ){ + fprintf(stderr, "connecting to relay server failure...\n"); return; } @@ -205,7 +218,20 @@ void sendMail() { snprintf(buf, sizeof(buf), "%s%s", mq.sender, FROM); if((fp = fopen(mq.filepath, "r"))) { setproctitle("outmail: sending %s", mq.filepath); - doSendMail(sock, fp, buf, mq.rcpt, mq.subject); + if( hisock >= 0 && + !strstr(mq.rcpt, ".edu.tw") && + !strstr(mq.rcpt, ".twbbs.org") && + !strstr(mq.rcpt, "ptt.cc") && + !strstr(mq.rcpt, "ptt2.cc") ){ + printf("mailto: %s, relay server: %s:%d\n", + mq.rcpt, hiname, hiport); + doSendMail(hisock, fp, buf, mq.rcpt, mq.subject); + } + else{ + printf("mailto: %s, relay server: %s:%d\n", + mq.rcpt, smtpname, smtpport); + doSendMail(smtpsock, fp, buf, mq.rcpt, mq.subject); + } fclose(fp); unlink(mq.filepath); } else { @@ -216,7 +242,9 @@ void sendMail() { close(fd); unlink(NEWINDEX); - disconnectMailServer(sock); + disconnectMailServer(smtpsock); + if( hisock >= 0 ) + disconnectMailServer(hisock); } void listQueue() { @@ -240,11 +268,23 @@ void listQueue() { } } -void usage() { - fprintf(stderr, "usage: outmail [-qh]\n"); +void wakeup(int s) { } -void wakeup(int s) { +void parseserver(char *sx, char **name, int *port) +{ + char *save = strdup(sx); + char *ptr; + if( (ptr = strstr(save, ":")) == NULL ){ + *name = strdup(save); + *port = 25; + } + else{ + *ptr = 0; + *name = strdup(save); + *port = atoi(ptr + 1); + } + free(save); } int main(int argc, char **argv, char **envp) { @@ -255,16 +295,36 @@ int main(int argc, char **argv, char **envp) { if(chdir(BBSHOME)) return 1; - while((ch = getopt(argc, argv, "qh")) != -1) { + while((ch = getopt(argc, argv, "qhs:o:")) != -1) { switch(ch) { + case 's': + parseserver(optarg, &smtpname, &smtpport); + break; + case 'o': + parseserver(optarg, &hiname, &hiport); + break; case 'q': listQueue(); return 0; default: - usage(); + printf("usage:\toutmail [-qh] -s host[:port] [-o host[:port]]\n" + "\t-q\tlistqueue\n" + "\t-h\thelp\n" + "\t-s\tset default smtp server to host[:port]\n" + "\t-o\tset non-Tanet smtp server to host[:port]\n"); return 0; } } + + if( smtpname == NULL ){ +#ifdef RELAY_SERVER_IP + smtpname = RELAY_SERVER_IP; +#else + smtpname = "127.0.0.1"; +#endif + smtpport = 25; + } + for(;;) { sendMail(); setproctitle("outmail: sleeping"); -- cgit v1.2.3 From f97bbecf0a91aa2524832fc50d122d6ab8f26c39 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Fri, 28 Jun 2002 14:20:12 +0000 Subject: fix bug(last commit) git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@373 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/outmail.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pttbbs/util/outmail.c b/pttbbs/util/outmail.c index c66929cb..1c282d61 100644 --- a/pttbbs/util/outmail.c +++ b/pttbbs/util/outmail.c @@ -1,4 +1,4 @@ -/* $Id: outmail.c,v 1.2 2002/06/28 14:17:22 in2 Exp $ */ +/* $Id: outmail.c,v 1.3 2002/06/28 14:20:12 in2 Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -129,7 +129,6 @@ int connectMailServer(char *servername, int serverport) if(connect(sock, (struct sockaddr *)&addr, sizeof(addr)) < 0) { printf("servername: %s\n", servername); perror(servername); - exit(0); close(sock); return -1; } -- cgit v1.2.3 From 8753a65b613be90f1e6c0ce1353a583ccfcbb324 Mon Sep 17 00:00:00 2001 From: ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sat, 29 Jun 2002 13:16:50 +0000 Subject: setcpulimit for gamble git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@374 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/gamble.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/pttbbs/mbbsd/gamble.c b/pttbbs/mbbsd/gamble.c index 839dbfa5..d7a96a53 100644 --- a/pttbbs/mbbsd/gamble.c +++ b/pttbbs/mbbsd/gamble.c @@ -1,4 +1,4 @@ -/* $Id: gamble.c,v 1.23 2002/06/26 07:48:47 ptt Exp $ */ +/* $Id: gamble.c,v 1.24 2002/06/29 13:16:50 ptt Exp $ */ #include "bbs.h" #ifndef _BBS_UTIL_C_ @@ -265,6 +265,14 @@ int openticket(int bid) { close(0); close(1); setproctitle("open ticket"); +#ifdef CPULIMIT + { + struct rlimit rml; + rml.rlim_cur = RLIM_INFINITY; + rml.rlim_max = RLIM_INFINITY; + setrlimit(RLIMIT_CPU, &rml); + } +#endif bet -= 1; //轉成矩陣的index -- cgit v1.2.3 From 15ddfbb13d858adabfe42a2df0a953d98270e66c Mon Sep 17 00:00:00 2001 From: ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sat, 29 Jun 2002 13:50:46 +0000 Subject: try toplazyBM git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@375 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/toplazyBM.c | 6 +++--- pttbbs/util/util_cache.c | 7 +++++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/pttbbs/util/toplazyBM.c b/pttbbs/util/toplazyBM.c index a2a34b94..b55d6a26 100644 --- a/pttbbs/util/toplazyBM.c +++ b/pttbbs/util/toplazyBM.c @@ -1,4 +1,4 @@ -/* $Id: toplazyBM.c,v 1.5 2002/06/19 13:38:01 lwms Exp $ */ +/* $Id: toplazyBM.c,v 1.6 2002/06/29 13:50:46 ptt Exp $ */ #include "bbs.h" @@ -22,7 +22,7 @@ typedef struct BMarray{ char *bmname; int flag; } BMArray; -BMArray bms[3]; +BMArray bms[5]; int bmlostdays_cmp(const void *va, const void *vb) @@ -118,7 +118,7 @@ int main(int argc, char *argv[]) j++; } index++; - } while((p=strtok(NULL,"/ "))!=NULL); + } while((p=strtok(NULL,"/ "))!=NULL && index<5); if(flag == 1){ //boardheader_t *fhp = 0; diff --git a/pttbbs/util/util_cache.c b/pttbbs/util/util_cache.c index 4a53cd2c..4cf0ff1f 100644 --- a/pttbbs/util/util_cache.c +++ b/pttbbs/util/util_cache.c @@ -1,4 +1,4 @@ -/* $Id: util_cache.c,v 1.4 2002/06/09 12:51:07 in2 Exp $ */ +/* $Id: util_cache.c,v 1.5 2002/06/29 13:50:46 ptt Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -339,14 +339,17 @@ void touch_boards() { void reset_board(int bid) { int fd; + boardheader_t bh; if(--bid<0)return; if(SHM->Bbusystate==0) { SHM->Bbusystate = 1; if((fd = open(fn_board, O_RDONLY)) > 0) { lseek(fd, (off_t)(bid * sizeof(boardheader_t)), SEEK_SET); - read(fd, &bcache[bid], sizeof(boardheader_t)); + read(fd, &bh , sizeof(boardheader_t)); close(fd); + if(bh.brdname[0] && !strcmp(bh.brdname,bcache[bid].brdname)) + memcpy(&bcache[bid],&bh, sizeof(boardheader_t)); } SHM->Bbusystate = 0; } -- cgit v1.2.3 From 08047fb94f216a2de90da9b91f79707bf6317d11 Mon Sep 17 00:00:00 2001 From: ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sat, 29 Jun 2002 13:52:31 +0000 Subject: add close vote once a day git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@376 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/include/pttstruct.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pttbbs/include/pttstruct.h b/pttbbs/include/pttstruct.h index d570bc57..8570aa22 100644 --- a/pttbbs/include/pttstruct.h +++ b/pttbbs/include/pttstruct.h @@ -1,4 +1,4 @@ -/* $Id: pttstruct.h,v 1.21 2002/06/26 14:36:07 in2 Exp $ */ +/* $Id: pttstruct.h,v 1.22 2002/06/29 13:52:31 ptt Exp $ */ #ifndef INCLUDE_STRUCT_H #define INCLUDE_STRUCT_H @@ -328,8 +328,9 @@ typedef struct { time_t Btouchtime; int Bnumber; int Bbusystate; + time_t close_vote_time; - char gap2[1024]; /* avoid some memory error / buffer overflow */ + char gap2[1020]; /* avoid some memory error / buffer overflow */ /* pttcache */ char notes[MAX_MOVIE][200*11]; char today_is[20]; -- cgit v1.2.3 From c3bbd09de6dac185a05b5d40c33b8cf86eb960dc Mon Sep 17 00:00:00 2001 From: ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sat, 29 Jun 2002 13:52:52 +0000 Subject: add close vote once a day git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@377 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/mbbsd.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/pttbbs/mbbsd/mbbsd.c b/pttbbs/mbbsd/mbbsd.c index 64ab1557..8f7605f7 100644 --- a/pttbbs/mbbsd/mbbsd.c +++ b/pttbbs/mbbsd/mbbsd.c @@ -1,4 +1,4 @@ -/* $Id: mbbsd.c,v 1.34 2002/06/06 21:34:11 in2 Exp $ */ +/* $Id: mbbsd.c,v 1.35 2002/06/29 13:52:52 ptt Exp $ */ #include "bbs.h" #define SOCKET_QLEN 4 @@ -963,8 +963,11 @@ start_client () user_login (); m_init (); - if (HAVE_PERM (PERM_SYSOP | PERM_BM)) + if (now - SHM->close_vote_time > 86400) // 改為一天一次 + { b_closepolls (); + SHM->close_vote_time = now; + } if (!(cuser.uflag & COLOR_FLAG)) showansi = 0; signal (SIGALRM, SIG_IGN); -- cgit v1.2.3 From 0fcd4fcb944584b5969670decf6ee35afa39220b Mon Sep 17 00:00:00 2001 From: ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sat, 29 Jun 2002 14:36:24 +0000 Subject: important error git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@378 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/toplazyBM.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pttbbs/util/toplazyBM.c b/pttbbs/util/toplazyBM.c index b55d6a26..25252870 100644 --- a/pttbbs/util/toplazyBM.c +++ b/pttbbs/util/toplazyBM.c @@ -1,4 +1,4 @@ -/* $Id: toplazyBM.c,v 1.6 2002/06/29 13:50:46 ptt Exp $ */ +/* $Id: toplazyBM.c,v 1.7 2002/06/29 14:36:24 ptt Exp $ */ #include "bbs.h" @@ -132,7 +132,7 @@ int main(int argc, char *argv[]) } strcpy(allbrd[i].BM, bmbuf); - if( substitute_record(FN_BOARD, &allbrd[i], sizeof(boardheader_t), i) == -1){ + if( substitute_record(FN_BOARD, &allbrd[i], sizeof(boardheader_t), i+1) == -1){ printf("Update Board Faile : %s\n", allbrd[i].brdname); } reset_board(i); -- cgit v1.2.3 From b59ba6485773de249e99d90913c8cc9451607c39 Mon Sep 17 00:00:00 2001 From: ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sat, 29 Jun 2002 14:39:09 +0000 Subject: again git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@379 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/toplazyBM.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pttbbs/util/toplazyBM.c b/pttbbs/util/toplazyBM.c index 25252870..5a23abcb 100644 --- a/pttbbs/util/toplazyBM.c +++ b/pttbbs/util/toplazyBM.c @@ -1,4 +1,4 @@ -/* $Id: toplazyBM.c,v 1.7 2002/06/29 14:36:24 ptt Exp $ */ +/* $Id: toplazyBM.c,v 1.8 2002/06/29 14:39:09 ptt Exp $ */ #include "bbs.h" @@ -135,7 +135,7 @@ int main(int argc, char *argv[]) if( substitute_record(FN_BOARD, &allbrd[i], sizeof(boardheader_t), i+1) == -1){ printf("Update Board Faile : %s\n", allbrd[i].brdname); } - reset_board(i); + reset_board(i+1); } } -- cgit v1.2.3 From 2a0357c145cbafc4d5c85d866e78c1c0d75f5e23 Mon Sep 17 00:00:00 2001 From: ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sat, 29 Jun 2002 14:42:14 +0000 Subject: bid errpr git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@380 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/toplazyBM.c | 4 ++-- pttbbs/util/util_cache.c | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/pttbbs/util/toplazyBM.c b/pttbbs/util/toplazyBM.c index 5a23abcb..cf277ef8 100644 --- a/pttbbs/util/toplazyBM.c +++ b/pttbbs/util/toplazyBM.c @@ -1,4 +1,4 @@ -/* $Id: toplazyBM.c,v 1.8 2002/06/29 14:39:09 ptt Exp $ */ +/* $Id: toplazyBM.c,v 1.9 2002/06/29 14:42:14 ptt Exp $ */ #include "bbs.h" @@ -88,7 +88,7 @@ int main(int argc, char *argv[]) char *p, bmbuf[IDLEN * 3 + 3]; int index = 0, flag = 0, k, n; p=strtok(allbrd[i].BM,"/ "); - if(p) + if(p && p[0]) do { if(allbrd[i].brdname[0] == '\0') continue; diff --git a/pttbbs/util/util_cache.c b/pttbbs/util/util_cache.c index 4cf0ff1f..3adb5e61 100644 --- a/pttbbs/util/util_cache.c +++ b/pttbbs/util/util_cache.c @@ -1,4 +1,4 @@ -/* $Id: util_cache.c,v 1.5 2002/06/29 13:50:46 ptt Exp $ */ +/* $Id: util_cache.c,v 1.6 2002/06/29 14:42:14 ptt Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -348,8 +348,8 @@ void reset_board(int bid) lseek(fd, (off_t)(bid * sizeof(boardheader_t)), SEEK_SET); read(fd, &bh , sizeof(boardheader_t)); close(fd); - if(bh.brdname[0] && !strcmp(bh.brdname,bcache[bid].brdname)) - memcpy(&bcache[bid],&bh, sizeof(boardheader_t)); + if(bh.brdname[0] && !strcmp(bh.brdname,bcache[bid-1].brdname)) + memcpy(&bcache[bid-1],&bh, sizeof(boardheader_t)); } SHM->Bbusystate = 0; } -- cgit v1.2.3 From fc54bc37b026e6d0fe5b037a14a6c70c28b67bbc Mon Sep 17 00:00:00 2001 From: ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sat, 29 Jun 2002 14:55:34 +0000 Subject: gamble git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@381 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/bbs.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/pttbbs/mbbsd/bbs.c b/pttbbs/mbbsd/bbs.c index 44442a45..cc5fd86a 100644 --- a/pttbbs/mbbsd/bbs.c +++ b/pttbbs/mbbsd/bbs.c @@ -1,4 +1,4 @@ -/* $Id: bbs.c,v 1.61 2002/06/26 08:47:51 ptt Exp $ */ +/* $Id: bbs.c,v 1.62 2002/06/29 14:55:34 ptt Exp $ */ #include "bbs.h" static void mail_by_link(char* owner, char* title, char* path) { @@ -996,6 +996,7 @@ static int hold_gamble(int ent, fileheader_t *fhdr, char *direct) { { bp->endgamble= 0; substitute_record(fn_board, bp, sizeof(boardheader_t), currbid); + } return FULLUPDATE; } @@ -1042,10 +1043,13 @@ static int hold_gamble(int ent, fileheader_t *fhdr, char *direct) { substitute_record(fn_board, bp, sizeof(boardheader_t), currbid); } move(6,0); - sprintf(genbuf,"請到 %s 板 按'f'參與賭博!\n\n一張 %d Ptt幣, 這是%s的賭博\n", +sprintf(genbuf,"請到 %s 板 按'f'參與賭博!\n\n一張 %d Ptt幣, 這是%s的賭博\n%s%s", currboard, i, i<100 ? "小賭式" : i<500 ? "平民級": - i<1000 ?"貴族級" : i<5000 ?"富豪級" : "傾家蕩產"); + i<1000 ?"貴族級" : i<5000 ?"富豪級" : "傾家蕩產", + bp->endgamble?"賭盤結束時間: ":"", + bp->endgamble?Cdate(&bp->endgamble):"" + ); strcat(msg, genbuf); prints("請依次輸入彩票名稱, 需提供2~8項. (未滿八項, 輸入直接按enter)\n"); for(i=0; i<8; i++) -- cgit v1.2.3 From 2c29c607308f2329451f12862cbf2d3b40e8eaa9 Mon Sep 17 00:00:00 2001 From: ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sat, 29 Jun 2002 15:10:01 +0000 Subject: bug of gettime: git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@382 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/stuff.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pttbbs/mbbsd/stuff.c b/pttbbs/mbbsd/stuff.c index 750158a2..c563fc29 100644 --- a/pttbbs/mbbsd/stuff.c +++ b/pttbbs/mbbsd/stuff.c @@ -1,4 +1,4 @@ -/* $Id: stuff.c,v 1.5 2002/06/23 03:50:14 ptt Exp $ */ +/* $Id: stuff.c,v 1.6 2002/06/29 15:10:01 ptt Exp $ */ #include "bbs.h" /* ----------------------------------------------------- */ @@ -273,6 +273,7 @@ time_t gettime(int line, time_t dt) char yn[7]; struct tm *ptime = localtime(&dt), endtime; + memcpy(&endtime, ptime, sizeof(struct tm )); sprintf(yn, "%4d", ptime->tm_year+1900); do{ getdata_buf(line, 0, "西元年:", yn, 5, LCECHO); -- cgit v1.2.3 From 6867c125c6c8fd31d32beecdd23e91d213223dba Mon Sep 17 00:00:00 2001 From: ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sun, 30 Jun 2002 01:46:24 +0000 Subject: testbug git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@383 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/toplazyBM.c | 37 ++++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/pttbbs/util/toplazyBM.c b/pttbbs/util/toplazyBM.c index cf277ef8..7237f170 100644 --- a/pttbbs/util/toplazyBM.c +++ b/pttbbs/util/toplazyBM.c @@ -1,4 +1,4 @@ -/* $Id: toplazyBM.c,v 1.9 2002/06/29 14:42:14 ptt Exp $ */ +/* $Id: toplazyBM.c,v 1.10 2002/06/30 01:46:24 ptt Exp $ */ #include "bbs.h" @@ -47,7 +47,7 @@ int main(int argc, char *argv[]) { int bmid, i, j=0; FILE *inf, *firef; - + time_t now=time(NULL); resolve_boards(); if(passwd_mmap()) @@ -87,27 +87,27 @@ int main(int argc, char *argv[]) for (i = 0; i < numboards; i++) { char *p, bmbuf[IDLEN * 3 + 3]; int index = 0, flag = 0, k, n; - p=strtok(allbrd[i].BM,"/ "); - if(p && p[0]) - do + p = allbrd[i].BM; + if(*p=='[') p++; + if(allbrd[i].brdname[0] == '\0' || + !isalpha(allbrd[i].brdname[0]) + ) continue; + + p=strtok(allbrd[i].BM,"/ ]"); + for(index=0; p && index<5; index++) { - if(allbrd[i].brdname[0] == '\0') continue; - if (*p == '[' ){p[strlen(p)-1]='\0'; p++;} + if(!p[0]) {index--; continue;} bmid=getuser(p); bms[index].bmname = p; bms[index].flag = 0; - if (((((int)time(NULL)-(int)xuser.lastlogin)/(60*60*24))>=31) - && isalpha(allbrd[i].brdname[0]) - && isalpha(allbrd[i].BM[0]) - && !(xuser.userlevel & PERM_SYSOP)) + if ((now-xuser.lastlogin)>30*86400 + && !(xuser.userlevel & PERM_SYSOP)) { lostbms[j].bmname = p; lostbms[j].title = allbrd[i].brdname; lostbms[j].ctitle = allbrd[i].title; lostbms[j].lostdays = ((int)time(NULL)-(int)xuser.lastlogin)/(60*60*24); - - //超過六十天 免職 if(lostbms[j].lostdays > 60){ xuser.userlevel &= ~PERM_BM; @@ -117,8 +117,8 @@ int main(int argc, char *argv[]) } j++; } - index++; - } while((p=strtok(NULL,"/ "))!=NULL && index<5); + p=strtok(NULL,"/ ]"); + } if(flag == 1){ //boardheader_t *fhp = 0; @@ -130,15 +130,17 @@ int main(int argc, char *argv[]) strcat(bmbuf, bms[k].bmname); } } - +printf("%d) %s:%s ",i,allbrd[i].brdname,bmbuf); + /* strcpy(allbrd[i].BM, bmbuf); if( substitute_record(FN_BOARD, &allbrd[i], sizeof(boardheader_t), i+1) == -1){ printf("Update Board Faile : %s\n", allbrd[i].brdname); } reset_board(i+1); +*/ } } - + /* qsort(lostbms, j, sizeof(lostbm), bmlostdays_cmp); //write to the etc/toplazyBM @@ -194,5 +196,6 @@ int main(int argc, char *argv[]) append_record(genbuf, &mymail, sizeof(mymail)); } +*/ return 0; } -- cgit v1.2.3 From fe61677779e8894ac1fac720db83134d5906dea9 Mon Sep 17 00:00:00 2001 From: ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sun, 30 Jun 2002 02:11:48 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@384 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/toplazyBM.c | 40 ++++++++++++++++++---------------------- 1 file changed, 18 insertions(+), 22 deletions(-) diff --git a/pttbbs/util/toplazyBM.c b/pttbbs/util/toplazyBM.c index 7237f170..d0157117 100644 --- a/pttbbs/util/toplazyBM.c +++ b/pttbbs/util/toplazyBM.c @@ -1,10 +1,7 @@ -/* $Id: toplazyBM.c,v 1.10 2002/06/30 01:46:24 ptt Exp $ */ +/* $Id: toplazyBM.c,v 1.11 2002/06/30 02:11:48 ptt Exp $ */ #include "bbs.h" - - #define OUTFILE BBSHOME "/etc/toplazyBM" #define FIREFILE BBSHOME "/etc/firelazyBM" - extern boardheader_t *bcache; extern int numboards; @@ -96,7 +93,9 @@ int main(int argc, char *argv[]) p=strtok(allbrd[i].BM,"/ ]"); for(index=0; p && index<5; index++) { - if(!p[0]) {index--; continue;} + if(!p[0]) {index--; + p=strtok(NULL,"/ ]"); + continue;} bmid=getuser(p); bms[index].bmname = p; bms[index].flag = 0; @@ -107,7 +106,7 @@ int main(int argc, char *argv[]) lostbms[j].title = allbrd[i].brdname; lostbms[j].ctitle = allbrd[i].title; lostbms[j].lostdays = - ((int)time(NULL)-(int)xuser.lastlogin)/(60*60*24); + (now-xuser.lastlogin)/86400; //超過六十天 免職 if(lostbms[j].lostdays > 60){ xuser.userlevel &= ~PERM_BM; @@ -121,8 +120,6 @@ int main(int argc, char *argv[]) } if(flag == 1){ - //boardheader_t *fhp = 0; - printf("%s %s\n", lostbms[j-1].title, lostbms[j-1].bmname); bmbuf[0] = '\0'; for(k = 0 , n = 0; k < index; k++){ if(!bms[k].flag){ @@ -130,17 +127,15 @@ int main(int argc, char *argv[]) strcat(bmbuf, bms[k].bmname); } } -printf("%d) %s:%s ",i,allbrd[i].brdname,bmbuf); - /* + printf("%d) %s:%s ",i,allbrd[i].brdname,bmbuf); strcpy(allbrd[i].BM, bmbuf); - if( substitute_record(FN_BOARD, &allbrd[i], sizeof(boardheader_t), i+1) == -1){ - printf("Update Board Faile : %s\n", allbrd[i].brdname); - } + if( substitute_record(FN_BOARD, &allbrd[i], + sizeof(boardheader_t), i+1) == -1){ + printf("Update Board Faile : %s\n", allbrd[i].brdname); + } reset_board(i+1); -*/ } } - /* qsort(lostbms, j, sizeof(lostbm), bmlostdays_cmp); //write to the etc/toplazyBM @@ -173,17 +168,19 @@ printf("%d) %s:%s ",i,allbrd[i].brdname,bmbuf); if( (lostdays != 30) && (lostdays != 45) && (lostdays <= 60)) continue; - sprintf(genbuf, BBSHOME "/home/%c/%s", lostbms[i].bmname[0], lostbms[i].bmname); + sprintf(genbuf, BBSHOME "/home/%c/%s", + lostbms[i].bmname[0], lostbms[i].bmname); stampfile(genbuf, &mymail); strcpy(mymail.owner, "[PTT警察局]"); - if(lostdays <= 60){ sprintf(mymail.title, - "\033[32m [板主免職警告通知] \033[m %s BM %s", lostbms[i].title, lostbms[i].bmname); + "\033[32m版主通知\033[m %s版版主%s", lostbms[i].title, + lostbms[i].bmname); }else{ sprintf(mymail.title, - "\033[32m [板主免職通知] \033[m %s BM %s", lostbms[i].title, lostbms[i].bmname); + "\033[32m版主自動免職通知\033[m %s BM %s", lostbms[i].title, + lostbms[i].bmname); } unlink(genbuf); if(lostdays <= 60){ @@ -192,10 +189,9 @@ printf("%d) %s:%s ",i,allbrd[i].brdname,bmbuf); LINK(FIREFILE, genbuf); } - sprintf(genbuf, BBSHOME "/home/%c/%s/.DIR", lostbms[i].bmname[0], lostbms[i].bmname); + sprintf(genbuf, BBSHOME "/home/%c/%s/.DIR", + lostbms[i].bmname[0], lostbms[i].bmname); append_record(genbuf, &mymail, sizeof(mymail)); } - -*/ return 0; } -- cgit v1.2.3 From 3f602dda86ad0d4b70dbe33e6f257641062ef31d Mon Sep 17 00:00:00 2001 From: ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sun, 30 Jun 2002 02:33:19 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@385 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/toplazyBM.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pttbbs/util/toplazyBM.c b/pttbbs/util/toplazyBM.c index d0157117..d2f1a031 100644 --- a/pttbbs/util/toplazyBM.c +++ b/pttbbs/util/toplazyBM.c @@ -1,4 +1,4 @@ -/* $Id: toplazyBM.c,v 1.11 2002/06/30 02:11:48 ptt Exp $ */ +/* $Id: toplazyBM.c,v 1.12 2002/06/30 02:33:19 ptt Exp $ */ #include "bbs.h" #define OUTFILE BBSHOME "/etc/toplazyBM" #define FIREFILE BBSHOME "/etc/firelazyBM" @@ -127,7 +127,6 @@ int main(int argc, char *argv[]) strcat(bmbuf, bms[k].bmname); } } - printf("%d) %s:%s ",i,allbrd[i].brdname,bmbuf); strcpy(allbrd[i].BM, bmbuf); if( substitute_record(FN_BOARD, &allbrd[i], sizeof(boardheader_t), i+1) == -1){ -- cgit v1.2.3 From 44df2e1653e24f41adb03c603be418524b59a795 Mon Sep 17 00:00:00 2001 From: ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sun, 30 Jun 2002 03:43:55 +0000 Subject: fix bug git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@386 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/util_cache.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pttbbs/util/util_cache.c b/pttbbs/util/util_cache.c index 3adb5e61..e99f52ea 100644 --- a/pttbbs/util/util_cache.c +++ b/pttbbs/util/util_cache.c @@ -1,4 +1,4 @@ -/* $Id: util_cache.c,v 1.6 2002/06/29 14:42:14 ptt Exp $ */ +/* $Id: util_cache.c,v 1.7 2002/06/30 03:43:55 ptt Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -307,7 +307,7 @@ userinfo_t *search_ulist(int uid) { /*-------------------------------------------------------*/ /* .BOARDS cache */ /*-------------------------------------------------------*/ -char *fn_board=FN_BOARD; +char *fn_board=BBSHOME"/"FN_BOARD; boardheader_t *bcache; static void reload_bcache() { @@ -348,8 +348,8 @@ void reset_board(int bid) lseek(fd, (off_t)(bid * sizeof(boardheader_t)), SEEK_SET); read(fd, &bh , sizeof(boardheader_t)); close(fd); - if(bh.brdname[0] && !strcmp(bh.brdname,bcache[bid-1].brdname)) - memcpy(&bcache[bid-1],&bh, sizeof(boardheader_t)); + if(bh.brdname[0] && !strcmp(bh.brdname,bcache[bid].brdname)) + memcpy(&bcache[bid],&bh, sizeof(boardheader_t)); } SHM->Bbusystate = 0; } -- cgit v1.2.3 From e09e0973cc26ecdaafc3797807afceaa36f40e33 Mon Sep 17 00:00:00 2001 From: ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sun, 30 Jun 2002 03:47:35 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@387 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/toplazyBM.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pttbbs/util/toplazyBM.c b/pttbbs/util/toplazyBM.c index d2f1a031..68fd0349 100644 --- a/pttbbs/util/toplazyBM.c +++ b/pttbbs/util/toplazyBM.c @@ -1,4 +1,4 @@ -/* $Id: toplazyBM.c,v 1.12 2002/06/30 02:33:19 ptt Exp $ */ +/* $Id: toplazyBM.c,v 1.13 2002/06/30 03:47:35 ptt Exp $ */ #include "bbs.h" #define OUTFILE BBSHOME "/etc/toplazyBM" #define FIREFILE BBSHOME "/etc/firelazyBM" @@ -128,7 +128,7 @@ int main(int argc, char *argv[]) } } strcpy(allbrd[i].BM, bmbuf); - if( substitute_record(FN_BOARD, &allbrd[i], + if( substitute_record(BBSHOME"/"FN_BOARD, &allbrd[i], sizeof(boardheader_t), i+1) == -1){ printf("Update Board Faile : %s\n", allbrd[i].brdname); } -- cgit v1.2.3 From 9d83b55bbee6003a913415d0c9a743a26112d8c1 Mon Sep 17 00:00:00 2001 From: ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sun, 30 Jun 2002 04:04:35 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@388 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/toplazyBM.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/pttbbs/util/toplazyBM.c b/pttbbs/util/toplazyBM.c index 68fd0349..736379f4 100644 --- a/pttbbs/util/toplazyBM.c +++ b/pttbbs/util/toplazyBM.c @@ -1,4 +1,4 @@ -/* $Id: toplazyBM.c,v 1.13 2002/06/30 03:47:35 ptt Exp $ */ +/* $Id: toplazyBM.c,v 1.14 2002/06/30 04:04:35 ptt Exp $ */ #include "bbs.h" #define OUTFILE BBSHOME "/etc/toplazyBM" #define FIREFILE BBSHOME "/etc/firelazyBM" @@ -99,7 +99,7 @@ int main(int argc, char *argv[]) bmid=getuser(p); bms[index].bmname = p; bms[index].flag = 0; - if ((now-xuser.lastlogin)>30*86400 + if ((now-xuser.lastlogin)>=45*86400 && !(xuser.userlevel & PERM_SYSOP)) { lostbms[j].bmname = p; @@ -107,8 +107,8 @@ int main(int argc, char *argv[]) lostbms[j].ctitle = allbrd[i].title; lostbms[j].lostdays = (now-xuser.lastlogin)/86400; - //超過六十天 免職 - if(lostbms[j].lostdays > 60){ + //超過90天 免職 + if(lostbms[j].lostdays > 90){ xuser.userlevel &= ~PERM_BM; bms[index].flag = 1; flag = 1; @@ -140,7 +140,7 @@ int main(int argc, char *argv[]) //write to the etc/toplazyBM for ( i=0; i<j; i++) { - if( lostbms[i].lostdays > 60){ + if( lostbms[i].lostdays > 90){ fprintf(firef, "%-*.*s%-*.*s%-*.*s%3d天沒上站\n", IDLEN, IDLEN, lostbms[i].title, BTLEN-10, BTLEN-10, lostbms[i].ctitle, IDLEN,IDLEN, lostbms[i].bmname,lostbms[i].lostdays); @@ -164,7 +164,7 @@ int main(int argc, char *argv[]) lostdays = lostbms[i].lostdays; - if( (lostdays != 30) && (lostdays != 45) && (lostdays <= 60)) + if( (lostdays != 45) && (lostdays <= 60)) continue; sprintf(genbuf, BBSHOME "/home/%c/%s", -- cgit v1.2.3 From e7bb6c87c7a854b3e48f1b30b96c0a5795355cf1 Mon Sep 17 00:00:00 2001 From: ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sun, 30 Jun 2002 04:11:47 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@389 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/toplazyBM.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pttbbs/util/toplazyBM.c b/pttbbs/util/toplazyBM.c index 736379f4..3d139d5b 100644 --- a/pttbbs/util/toplazyBM.c +++ b/pttbbs/util/toplazyBM.c @@ -1,4 +1,4 @@ -/* $Id: toplazyBM.c,v 1.14 2002/06/30 04:04:35 ptt Exp $ */ +/* $Id: toplazyBM.c,v 1.15 2002/06/30 04:11:47 ptt Exp $ */ #include "bbs.h" #define OUTFILE BBSHOME "/etc/toplazyBM" #define FIREFILE BBSHOME "/etc/firelazyBM" @@ -164,7 +164,7 @@ int main(int argc, char *argv[]) lostdays = lostbms[i].lostdays; - if( (lostdays != 45) && (lostdays <= 60)) + if( lostdays != 45 && lostdays != 60 && lostdays!=75 &&(lostdays <= 90)) continue; sprintf(genbuf, BBSHOME "/home/%c/%s", @@ -178,11 +178,11 @@ int main(int argc, char *argv[]) lostbms[i].bmname); }else{ sprintf(mymail.title, - "\033[32m版主自動免職通知\033[m %s BM %s", lostbms[i].title, + "\033[32m版主自動免職通知\033[m %s 版主 %s",lostbms[i].title, lostbms[i].bmname); } unlink(genbuf); - if(lostdays <= 60){ + if(lostdays <= 90){ LINK(OUTFILE, genbuf); }else{ LINK(FIREFILE, genbuf); -- cgit v1.2.3 From cee9acd858e4c74f64b97be1985f065d76efc2b1 Mon Sep 17 00:00:00 2001 From: ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sun, 30 Jun 2002 04:14:46 +0000 Subject: last one git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@390 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/toplazyBM.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pttbbs/util/toplazyBM.c b/pttbbs/util/toplazyBM.c index 3d139d5b..f54d7770 100644 --- a/pttbbs/util/toplazyBM.c +++ b/pttbbs/util/toplazyBM.c @@ -1,4 +1,4 @@ -/* $Id: toplazyBM.c,v 1.15 2002/06/30 04:11:47 ptt Exp $ */ +/* $Id: toplazyBM.c,v 1.16 2002/06/30 04:14:46 ptt Exp $ */ #include "bbs.h" #define OUTFILE BBSHOME "/etc/toplazyBM" #define FIREFILE BBSHOME "/etc/firelazyBM" @@ -172,7 +172,7 @@ int main(int argc, char *argv[]) stampfile(genbuf, &mymail); strcpy(mymail.owner, "[PTT警察局]"); - if(lostdays <= 60){ + if(lostdays <= 90){ sprintf(mymail.title, "\033[32m版主通知\033[m %s版版主%s", lostbms[i].title, lostbms[i].bmname); -- cgit v1.2.3 From ce97472e748854f8b8c082de3cbd6abe71522d9f Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sun, 30 Jun 2002 09:20:21 +0000 Subject: redraw git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@391 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/talk.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pttbbs/mbbsd/talk.c b/pttbbs/mbbsd/talk.c index 7ff04cb4..f63778c9 100644 --- a/pttbbs/mbbsd/talk.c +++ b/pttbbs/mbbsd/talk.c @@ -1,4 +1,4 @@ -/* $Id: talk.c,v 1.71 2002/06/26 01:12:48 in2 Exp $ */ +/* $Id: talk.c,v 1.72 2002/06/30 09:20:21 in2 Exp $ */ #include "bbs.h" #define QCAST int (*)(const void *, const void *) @@ -2107,6 +2107,7 @@ static void userlist(void) genbuf, 3, LCECHO); if( genbuf[0] && genbuf[0] != 'q' && atoi(genbuf) >= 0) currutmp->mind = atoi(genbuf) % i; + redrawall = redraw = 1; break; case Ctrl('S'): @@ -2205,6 +2206,7 @@ static void userlist(void) stand_title("寄 信"); prints("[寄信] 收信人:%s", uentp->userid); my_send(uentp->userid); + redrawall = redraw = 1; break; case 'q': -- cgit v1.2.3 From a4e87f398898ed5a281d4e8ffcf015921d1e43d7 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sun, 30 Jun 2002 14:33:14 +0000 Subject: not using mmap for .PASSWD git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@392 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/mbbsd.c | 16 ++++------- pttbbs/mbbsd/passwd.c | 79 +++++++++++++++++++++------------------------------ 2 files changed, 38 insertions(+), 57 deletions(-) diff --git a/pttbbs/mbbsd/mbbsd.c b/pttbbs/mbbsd/mbbsd.c index 8f7605f7..2b33fc2c 100644 --- a/pttbbs/mbbsd/mbbsd.c +++ b/pttbbs/mbbsd/mbbsd.c @@ -1,4 +1,4 @@ -/* $Id: mbbsd.c,v 1.35 2002/06/29 13:52:52 ptt Exp $ */ +/* $Id: mbbsd.c,v 1.36 2002/06/30 14:33:14 in2 Exp $ */ #include "bbs.h" #define SOCKET_QLEN 4 @@ -955,6 +955,10 @@ start_client () signal_restart (SIGUSR2, write_request); dup2 (0, 1); + + /* mmap passwd file */ + if (passwd_mmap ()) + exit (1); do_term_init (); signal (SIGALRM, abort_bbs); @@ -998,7 +1002,7 @@ telnet_init () to.tv_sec = 3; to.tv_usec = 0; rset=1; - if (select (1, (fd_set *) & rset, NULL, NULL, &to) > 0) + if (select(1, (fd_set *) & rset, NULL, NULL, &to) > 0) recv(0, buf, sizeof (buf),0); } } @@ -1195,9 +1199,6 @@ shell_login (int argc, char *argv[], char *envp[]) setuid (BBSUID); chdir (BBSHOME); - /* mmap passwd file */ - if (passwd_mmap ()) - exit (1); use_shell_login_mode = 1; initsetproctitle (argc, argv, envp); @@ -1260,11 +1261,6 @@ daemon_login (int argc, char *argv[], char *envp[]) setuid(BBSUID); chdir(BBSHOME); - /* mmap passwd file */ - if(passwd_mmap()) - { - exit(1); - } sprintf(buf, "run/mbbsd.%d.pid", listen_port); if((fp = fopen(buf, "w"))) { fprintf(fp, "%d\n", getpid()); diff --git a/pttbbs/mbbsd/passwd.c b/pttbbs/mbbsd/passwd.c index cfc7361a..46ea1529 100644 --- a/pttbbs/mbbsd/passwd.c +++ b/pttbbs/mbbsd/passwd.c @@ -1,8 +1,6 @@ -/* $Id: passwd.c,v 1.2 2002/06/04 13:08:34 in2 Exp $ */ +/* $Id: passwd.c,v 1.3 2002/06/30 14:33:14 in2 Exp $ */ #include "bbs.h" -static userec_t *passwd_image = NULL; -static int passwd_image_size; static int semid = -1; #ifndef SEM_R @@ -22,59 +20,42 @@ union semun { }; #endif +int PASSWDfd; int passwd_mmap() { - int fd; - - fd = open(fn_passwd, O_RDWR); - if(fd > 0) - { - struct stat st; - - fstat(fd, &st); - passwd_image_size = st.st_size; - passwd_image = mmap(NULL, passwd_image_size, - PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); - if(passwd_image == (userec_t *)-1) { - perror("mmap"); - return -1; - } -/* rocker 011018: after success get mmap, close file descript */ - close (fd); - - semid = semget(PASSWDSEM_KEY, 1, SEM_R | SEM_A | IPC_CREAT | IPC_EXCL); - if(semid == -1) { - if(errno == EEXIST) { - semid = semget(PASSWDSEM_KEY, 1, SEM_R | SEM_A); - if(semid == -1) { - perror("semget"); - exit(1); - } - } else { + if( (PASSWDfd = open(fn_passwd, O_RDWR)) < 0 || PASSWDfd <= 1 ) + return -1; + semid = semget(PASSWDSEM_KEY, 1, SEM_R | SEM_A | IPC_CREAT | IPC_EXCL); + if(semid == -1) { + if(errno == EEXIST) { + semid = semget(PASSWDSEM_KEY, 1, SEM_R | SEM_A); + if(semid == -1) { perror("semget"); exit(1); } } else { - union semun s; - - s.val = 1; - if(semctl(semid, 0, SETVAL, s) == -1) { - perror("semctl"); - exit(1); - } + perror("semget"); + exit(1); } } else { - perror(fn_passwd); - return -1; + union semun s; + + s.val = 1; + if(semctl(semid, 0, SETVAL, s) == -1) { + perror("semctl"); + exit(1); + } } + return 0; } int passwd_update_money(int num) { - int money; + userec_t user; if(num < 1 || num > MAX_USERS) return -1; - money = moneyof(num); - memcpy(&passwd_image[num - 1].money, &money, sizeof(int)); + passwd_query(num, &user); + user.money = moneyof(num); + passwd_update(num, &user); return 0; } @@ -82,23 +63,27 @@ int passwd_update(int num, userec_t *buf) { if(num < 1 || num > MAX_USERS) return -1; buf->money = moneyof(num); - memcpy(&passwd_image[num - 1], buf, sizeof(userec_t)); + lseek(PASSWDfd, sizeof(userec_t) * (num - 1), SEEK_SET); + write(PASSWDfd, buf, sizeof(userec_t)); return 0; } int passwd_query(int num, userec_t *buf) { if(num < 1 || num > MAX_USERS) return -1; - memcpy(buf, &passwd_image[num - 1], sizeof(userec_t)); + lseek(PASSWDfd, sizeof(userec_t) * (num - 1), SEEK_SET); + read(PASSWDfd, buf, sizeof(userec_t)); return 0; } int passwd_apply(int (*fptr)(userec_t *)) { int i; - - for(i = 0; i < MAX_USERS; i++) - if((*fptr)(&passwd_image[i]) == QUIT) + userec_t user; + for(i = 0; i < MAX_USERS; i++){ + passwd_query(i + 1, &user); + if((*fptr)(&user) == QUIT) return QUIT; + } return 0; } -- cgit v1.2.3 From 67ef63c61841dd5813c43e880e14564aaea5772f Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sun, 30 Jun 2002 14:34:11 +0000 Subject: hit for register git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@393 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/user.c | 54 +++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 40 insertions(+), 14 deletions(-) diff --git a/pttbbs/mbbsd/user.c b/pttbbs/mbbsd/user.c index 786de5de..95c3032f 100644 --- a/pttbbs/mbbsd/user.c +++ b/pttbbs/mbbsd/user.c @@ -1,4 +1,4 @@ -/* $Id: user.c,v 1.25 2002/06/26 02:09:06 in2 Exp $ */ +/* $Id: user.c,v 1.26 2002/06/30 14:34:11 in2 Exp $ */ #include "bbs.h" static char *sex[8] = { @@ -925,8 +925,11 @@ int u_register(void) strcpy(addr, cuser.address); strcpy(email, cuser.email); sprintf(mobile,"0%09d",cuser.mobile); - sprintf(birthday, "%02i/%02i/%02i", - cuser.month, cuser.day, cuser.year % 100); + if( cuser.month == 0 && cuser.day && cuser.year == 0 ) + birthday[0] = 0; + else + sprintf(birthday, "%02i/%02i/%02i", + cuser.month, cuser.day, cuser.year % 100); sex_is[0]=(cuser.sex % 8)+'1';sex_is[1]=0; career[0] = phone[0] = '\0'; sethomefile(genbuf, cuser.userid, "justify.wait"); @@ -993,19 +996,42 @@ int u_register(void) if( 'a' <= ident[0] && ident[0] <= 'z' ) ident[0] -= 32; }while( !ispersonalid(ident) ); - do{ + while( 1 ){ getfield(5, "請用中文", "真實姓名", rname, 20); - }while(!removespace(rname) || rname[0] > 0); - do{ - getfield(7, "學校(含\033[1;33m系所\033[m)或單位職稱", + if( removespace(rname) && rname[0] < 0 && + !strstr(rname, "阿") && !strstr(rname, "小") ) + break; + move(20, 0);prints("您的輸入不正確"); + pressanykey(); + move(20, 0);prints(" "); + } + + while( 1 ){ + getfield(7, "學校(含\033[1;33m系所年級\033[m)或單位職稱", "服務單位", career, 40); - }while( !removespace(career) || career[0] > 0 || strlen(career) < 4 ); - do{ - getfield(9, "包括寢室或門牌號碼", "目前住址", addr, 50); - }while( !(addr[0]) || addr[0] > 0 || strlen(addr) < 15 ); - do{ - getfield(11, "包括長途撥號區域碼", "連絡電話", phone, 11); - }while( !removespace(phone) || phone[0] != '0' || strlen(phone) < 9 ); + if( removespace(career) && career[0] < 0 && strlen(career) >= 4 ) + break; + move(20, 0);prints("您的輸入不正確"); + pressanykey(); + move(20, 0);prints(" "); + } + while( 1 ){ + getfield(9, "含縣市及門寢號碼(台北請加\033[1;33m行政區\033[m)", + "目前住址", addr, 50); + if( removespace(addr) && addr[0] < 0 && strlen(addr) >= 15 ) + break; + move(20, 0);prints("您的輸入不正確"); + pressanykey(); + move(20, 0);prints(" "); + } + while( 1 ){ + getfield(11, "不加-(), 包括長途區號", "連絡電話", phone, 11); + if( removespace(phone) && phone[0] == '0' && strlen(phone) >= 9 ) + break; + move(20, 0);prints("您的輸入不正確"); + pressanykey(); + move(20, 0);prints(" "); + } getfield(13, "只輸入數字 如:0912345678 (可不填)", "手機號碼", mobile, 20); while(1) { -- cgit v1.2.3 From a1b0594ff34b404f92b86658be3de15185a7718b Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sun, 30 Jun 2002 16:06:19 +0000 Subject: =?UTF-8?q?fix=20=EF=BF=BDQ=EF=BF=BDj/=EF=BF=BD=EF=BF=BD=EF=BF=BDQ?= =?UTF-8?q?=EF=BF=BDj?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@394 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/poststat.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pttbbs/util/poststat.c b/pttbbs/util/poststat.c index 9ae3b477..acd4aed4 100644 --- a/pttbbs/util/poststat.c +++ b/pttbbs/util/poststat.c @@ -1,4 +1,4 @@ -/* $Id: poststat.c,v 1.3 2002/06/06 21:34:14 in2 Exp $ */ +/* $Id: poststat.c,v 1.4 2002/06/30 16:06:19 in2 Exp $ */ /* 統計今日、週、月、年熱門話題 */ #include "bbs.h" @@ -325,6 +325,7 @@ int main(argc, argv) time_t now; struct tm *ptime; + attach_SHM(); if (argc < 2) { printf("Usage:\t%s bbshome [day]\n", argv[0]); -- cgit v1.2.3 From d9d69b2ee87bb6dfeb8fd140a4f9690565221ee3 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sun, 30 Jun 2002 16:06:43 +0000 Subject: board cache problem git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@395 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/util_cache.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/pttbbs/util/util_cache.c b/pttbbs/util/util_cache.c index e99f52ea..2426044c 100644 --- a/pttbbs/util/util_cache.c +++ b/pttbbs/util/util_cache.c @@ -1,4 +1,4 @@ -/* $Id: util_cache.c,v 1.7 2002/06/30 03:43:55 ptt Exp $ */ +/* $Id: util_cache.c,v 1.8 2002/06/30 16:06:43 in2 Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -141,6 +141,7 @@ void sem_lock(int op,int semid) { SHM_t *SHM; int *GLOBALVAR; boardheader_t *bcache; +int numboards = -1; void attach_SHM(void) { @@ -157,6 +158,9 @@ void attach_SHM(void) if( SHM->Ftouchtime == 0 ) SHM->Ftouchtime = 1; + + bcache = SHM->bcache; + numboards = SHM->Bnumber; } int setumoney(int uid, int money) { @@ -308,22 +312,17 @@ userinfo_t *search_ulist(int uid) { /* .BOARDS cache */ /*-------------------------------------------------------*/ char *fn_board=BBSHOME"/"FN_BOARD; -boardheader_t *bcache; - static void reload_bcache() { if(SHM->Bbusystate) { safe_sleep(1); } } -int numboards = -1; - void resolve_boards() { if(SHM == NULL) { attach_SHM(); if(SHM->Btouchtime == 0) SHM->Btouchtime = 1; - bcache = SHM->bcache; } while(SHM->Buptime < SHM->Btouchtime) -- cgit v1.2.3 From b58ea328268306ae79026d97c9c63930d0bae6ce Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sun, 30 Jun 2002 16:07:12 +0000 Subject: fix bug (poststat) git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@396 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/sample/crontab | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pttbbs/sample/crontab b/pttbbs/sample/crontab index eddf5f48..4be44b03 100644 --- a/pttbbs/sample/crontab +++ b/pttbbs/sample/crontab @@ -12,7 +12,7 @@ # 每個小時 10 分執行熱門話題統計 #50 * * * * bin/parse_news -10 * * * * bin/poststat +10 * * * * bin/poststat /home/bbs # 每天 5:30 執行使用者排行榜更新 30 5 * * * bin/topusr 10 etc/topusr -- cgit v1.2.3 From 460851d46c3093a1790a0612e16b0820bc7bee1f Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sun, 30 Jun 2002 18:16:33 +0000 Subject: avoid utmp->friendtotal error git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@397 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/shmctl.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pttbbs/util/shmctl.c b/pttbbs/util/shmctl.c index 2ce7982b..348b6024 100644 --- a/pttbbs/util/shmctl.c +++ b/pttbbs/util/shmctl.c @@ -1,4 +1,4 @@ -/* $Id: shmctl.c,v 1.22 2002/06/26 01:57:49 in2 Exp $ */ +/* $Id: shmctl.c,v 1.23 2002/06/30 18:16:33 in2 Exp $ */ #include "bbs.h" extern SHM_t *SHM; @@ -9,6 +9,8 @@ int logout_friend_online(userinfo_t *utmp) int offset=(int) (utmp - &SHM->uinfo[0]); userinfo_t *ui; while(utmp->friendtotal){ + if( !(0 <= utmp->friendtotal && utmp->friendtotal < MAX_FRIEND) ) + return 1; i = utmp->friendtotal-1; j = (utmp->friend_online[i] & 0xFFFFFF); if( !(0 <= j && j < MAX_ACTIVE) ) -- cgit v1.2.3 From 6cfd452d48ca7ed955056416cfdcf6e8fcbf6d76 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Mon, 1 Jul 2002 08:03:55 +0000 Subject: chdir(BBSHOME) git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@398 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/bbsmail.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pttbbs/util/bbsmail.c b/pttbbs/util/bbsmail.c index 634b2991..54e4dc47 100644 --- a/pttbbs/util/bbsmail.c +++ b/pttbbs/util/bbsmail.c @@ -1,4 +1,4 @@ -/* $Id: bbsmail.c,v 1.3 2002/06/06 21:34:14 in2 Exp $ */ +/* $Id: bbsmail.c,v 1.4 2002/07/01 08:03:55 in2 Exp $ */ #define _BBS_UTIL_C_ #include "bbs.h" @@ -205,6 +205,7 @@ main(int argc, char* argv[]) { char receiver[256]; + chdir(BBSHOME); /* argv[1] is userid in bbs */ if (argc < 2) -- cgit v1.2.3 From 1a34d8d438063b9988cb942a59b4410350ff7465 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Tue, 2 Jul 2002 02:12:56 +0000 Subject: hit to water program git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@399 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/mail.c | 19 ++++++++++++++++--- pttbbs/mbbsd/talk.c | 6 +++++- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/pttbbs/mbbsd/mail.c b/pttbbs/mbbsd/mail.c index f4ba6d64..a4d47df7 100644 --- a/pttbbs/mbbsd/mail.c +++ b/pttbbs/mbbsd/mail.c @@ -1,4 +1,4 @@ -/* $Id: mail.c,v 1.14 2002/06/27 19:49:48 kcwu Exp $ */ +/* $Id: mail.c,v 1.15 2002/07/02 02:12:56 in2 Exp $ */ #include "bbs.h" char currmaildir[32]; static char msg_cc[] = "\033[32m[群組名單]\033[m\n"; @@ -1220,8 +1220,16 @@ static int mail_waterball(int ent, fileheader_t *fhdr, char *direct) char fname[500], genbuf[200]; FILE *fp; + if( !strstr(fhdr->title, "熱線記錄") ){ + vmsg("必須是 熱線記錄 才能使用水球整理的唷!"); + return 1; + } if(!address[0]) strcpy(address, cuser.email); + move(b_lines - 5, 0); + outs("水球整理程式:\n" + "系統將會按照和不同人丟的水球各獨自獨立\n" + "於整點的時候 (尖鋒時段除外) 將資料整理好寄送給您\n\n\n"); if(address[0]) { sprintf(genbuf, "寄給 [%s] 嗎(Y/N/Q)?[Y] ", address); getdata(b_lines - 2, 0, genbuf, fname, 3, LCECHO); @@ -1235,7 +1243,7 @@ static int mail_waterball(int ent, fileheader_t *fhdr, char *direct) if(fname[0] && strchr(fname, '.')) { strcpy(address, fname); } else { - outmsg("取消處理"); + vmsg("取消處理"); return 1; } } @@ -1243,7 +1251,11 @@ static int mail_waterball(int ent, fileheader_t *fhdr, char *direct) return -2; // sprintf(fname, "%d\n", cmode); - getdata(b_lines - 1, 0, "使用模式(0/1)? [1]", fname, 3, LCECHO); + getdata(b_lines - 1, 0, "使用模式(0/1/Q)? [1]", fname, 3, LCECHO); + if( fname[0] == 'Q' || fname[0] == 'q' ){ + outmsg("取消處理"); + return 1; + } cmode = (fname[0] != '0' && fname[0] != '1') ? 1 : fname[0] - '0'; sprintf(fname, BBSHOME "/jobspool/water.src.%s-%d", @@ -1257,6 +1269,7 @@ static int mail_waterball(int ent, fileheader_t *fhdr, char *direct) fp = fopen(fname, "wt"); fprintf(fp, "%s\n%s\n%d\n", cuser.userid, address, cmode); fclose(fp); + vmsg("設定完成, 系統將在下一個整點(尖鋒時段除外)將資料寄給您"); return FULLUPDATE; } #endif diff --git a/pttbbs/mbbsd/talk.c b/pttbbs/mbbsd/talk.c index f63778c9..e0c5fa92 100644 --- a/pttbbs/mbbsd/talk.c +++ b/pttbbs/mbbsd/talk.c @@ -1,4 +1,4 @@ -/* $Id: talk.c,v 1.72 2002/06/30 09:20:21 in2 Exp $ */ +/* $Id: talk.c,v 1.73 2002/07/02 02:12:56 in2 Exp $ */ #include "bbs.h" #define QCAST int (*)(const void *, const void *) @@ -771,6 +771,10 @@ int t_display(void) } setuserfile(genbuf, fn_writelog); if (more(genbuf, YEA) != -1){ + move(b_lines - 4, 0); + outs("\033[1;33;45m★現在 Ptt提供創新的水球整理程式★\033[m\n" + "您將水球存至信箱後, 在【郵件選單】該信件前按 u,\n" + "系統即會將您的水球紀錄重新整理後寄送給您唷! \n"); getdata(b_lines - 1, 0, "清除(C) 移至備忘錄(M) 保留(R) (C/M/R)?[R]", ans, sizeof(ans), LCECHO); if (*ans == 'm'){ -- cgit v1.2.3 From 5f38de2d82c01b1dec5fbb3984f9ec1fe91ff3e6 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Tue, 2 Jul 2002 13:01:43 +0000 Subject: fix memory bug git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@400 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/friend.c | 30 ++++++++++++++---------------- pttbbs/mbbsd/indict.c | 6 +++++- pttbbs/mbbsd/name.c | 4 +++- pttbbs/mbbsd/talk.c | 4 +++- 4 files changed, 25 insertions(+), 19 deletions(-) diff --git a/pttbbs/mbbsd/friend.c b/pttbbs/mbbsd/friend.c index 4a3f636c..c24f6240 100644 --- a/pttbbs/mbbsd/friend.c +++ b/pttbbs/mbbsd/friend.c @@ -1,4 +1,4 @@ -/* $Id: friend.c,v 1.7 2002/06/19 13:27:16 lwms Exp $ */ +/* $Id: friend.c,v 1.8 2002/07/02 13:01:43 in2 Exp $ */ #include "bbs.h" /* ------------------------------------- */ @@ -184,24 +184,22 @@ static void friend_append(int type, int count) { setfriendfile(sfile, j); - fp = fopen(sfile, "r"); - while (fgets(buf, 80, fp) && count <= friend_max[type]) - { - char the_id[15]; - - sscanf(buf, "%s", the_id); - if (!belong(fpath, the_id)) - { - if ((fp1 = fopen(fpath, "a"))) - { - flock(fileno(fp1), LOCK_EX); - fputs(buf, fp1); - flock(fileno(fp1), LOCK_UN); - fclose(fp1); + if( (fp = fopen(sfile, "r")) != NULL ){ + while (fgets(buf, 80, fp) && count <= friend_max[type]){ + char the_id[15]; + + sscanf(buf, "%s", the_id); + if (!belong(fpath, the_id)){ + if ((fp1 = fopen(fpath, "a"))){ + flock(fileno(fp1), LOCK_EX); + fputs(buf, fp1); + flock(fileno(fp1), LOCK_UN); + fclose(fp1); + } } } + fclose(fp); } - fclose(fp); } void friend_delete(char *uident, int type) { diff --git a/pttbbs/mbbsd/indict.c b/pttbbs/mbbsd/indict.c index 8861b320..ca44033a 100644 --- a/pttbbs/mbbsd/indict.c +++ b/pttbbs/mbbsd/indict.c @@ -1,4 +1,4 @@ -/* $Id: indict.c,v 1.3 2002/06/04 13:08:33 in2 Exp $ */ +/* $Id: indict.c,v 1.4 2002/07/02 13:01:43 in2 Exp $ */ #include "bbs.h" #define REFER "etc/dicts" @@ -8,6 +8,10 @@ static void addword(char word[]) char buf[150],temp[150],a[3]; FILE *fp = fopen(database,"r+"); + if( fp == NULL ){ + vmsg("database error"); + return ; + } fgets(buf,130,fp); fseek(fp,0,2); if(HAVE_PERM(PERM_LOGINOK)) { diff --git a/pttbbs/mbbsd/name.c b/pttbbs/mbbsd/name.c index f2a0f704..af32daa5 100644 --- a/pttbbs/mbbsd/name.c +++ b/pttbbs/mbbsd/name.c @@ -1,4 +1,4 @@ -/* $Id: name.c,v 1.8 2002/06/06 21:34:11 in2 Exp $ */ +/* $Id: name.c,v 1.9 2002/07/02 13:01:43 in2 Exp $ */ #include "bbs.h" static word_t *current = NULL; @@ -497,6 +497,8 @@ int gnc_completeone(char *data, int start, int end, int (*permission)(int), char* (*getname)(int)) { int i, count, at; + if( start < 0 || end < 0 ) + return -1; for( i = start, at = count = 0 ; i <= end && count < 2 ; ++i ) if( permission(i) ){ at = i; diff --git a/pttbbs/mbbsd/talk.c b/pttbbs/mbbsd/talk.c index e0c5fa92..780c0244 100644 --- a/pttbbs/mbbsd/talk.c +++ b/pttbbs/mbbsd/talk.c @@ -1,4 +1,4 @@ -/* $Id: talk.c,v 1.73 2002/07/02 02:12:56 in2 Exp $ */ +/* $Id: talk.c,v 1.74 2002/07/02 13:01:43 in2 Exp $ */ #include "bbs.h" #define QCAST int (*)(const void *, const void *) @@ -441,6 +441,8 @@ void my_write2(void) water_t *tw; unsigned char mode0; + if( swater[0] == NULL ) + return; wmofo = 0; currstat0 = currstat; c0 = currutmp->chatid[0]; -- cgit v1.2.3 From a8f68d10d03c506dac406775608765fb4e1d9675 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Tue, 2 Jul 2002 14:56:22 +0000 Subject: use vmsg() git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@401 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/user.c | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/pttbbs/mbbsd/user.c b/pttbbs/mbbsd/user.c index 95c3032f..a0895c3e 100644 --- a/pttbbs/mbbsd/user.c +++ b/pttbbs/mbbsd/user.c @@ -1,4 +1,4 @@ -/* $Id: user.c,v 1.26 2002/06/30 14:34:11 in2 Exp $ */ +/* $Id: user.c,v 1.27 2002/07/02 14:56:22 in2 Exp $ */ #include "bbs.h" static char *sex[8] = { @@ -1001,9 +1001,7 @@ int u_register(void) if( removespace(rname) && rname[0] < 0 && !strstr(rname, "阿") && !strstr(rname, "小") ) break; - move(20, 0);prints("您的輸入不正確"); - pressanykey(); - move(20, 0);prints(" "); + vmsg("您的輸入不正確"); } while( 1 ){ @@ -1011,26 +1009,20 @@ int u_register(void) "服務單位", career, 40); if( removespace(career) && career[0] < 0 && strlen(career) >= 4 ) break; - move(20, 0);prints("您的輸入不正確"); - pressanykey(); - move(20, 0);prints(" "); + vmsg("您的輸入不正確"); } while( 1 ){ getfield(9, "含縣市及門寢號碼(台北請加\033[1;33m行政區\033[m)", "目前住址", addr, 50); if( removespace(addr) && addr[0] < 0 && strlen(addr) >= 15 ) break; - move(20, 0);prints("您的輸入不正確"); - pressanykey(); - move(20, 0);prints(" "); + vmsg("這個地址並不合法"); } while( 1 ){ getfield(11, "不加-(), 包括長途區號", "連絡電話", phone, 11); if( removespace(phone) && phone[0] == '0' && strlen(phone) >= 9 ) break; - move(20, 0);prints("您的輸入不正確"); - pressanykey(); - move(20, 0);prints(" "); + vmsg("這個電話號碼並不合法"); } getfield(13, "只輸入數字 如:0912345678 (可不填)", "手機號碼", mobile, 20); -- cgit v1.2.3 From c322dc313959c83df5033e469b13ef9656eff096 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Tue, 2 Jul 2002 15:07:20 +0000 Subject: =?UTF-8?q?title=20"=EF=BF=BD=EF=BF=BD=EF=BF=BDu=EF=BF=BDO?= =?UTF-8?q?=EF=BF=BD=EF=BF=BD"=20format?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@402 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/talk.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pttbbs/mbbsd/talk.c b/pttbbs/mbbsd/talk.c index 780c0244..add07deb 100644 --- a/pttbbs/mbbsd/talk.c +++ b/pttbbs/mbbsd/talk.c @@ -1,4 +1,4 @@ -/* $Id: talk.c,v 1.74 2002/07/02 13:01:43 in2 Exp $ */ +/* $Id: talk.c,v 1.75 2002/07/02 15:07:20 in2 Exp $ */ #include "bbs.h" #define QCAST int (*)(const void *, const void *) @@ -788,7 +788,7 @@ int t_display(void) mymail.filemode = FILE_READ | FILE_HOLD; strcpy(mymail.owner, "[備.忘.錄]"); - strcpy(mymail.title, "熱線\033[37;41m記錄\033[m"); + strcpy(mymail.title, "熱線記錄"); sethomedir(title, cuser.userid); Rename(genbuf, buf); append_record(title, &mymail, sizeof(mymail)); -- cgit v1.2.3 From 9b53a258db477c1eabbdf24c8f368895e6c133c0 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Tue, 2 Jul 2002 15:08:52 +0000 Subject: max search-forware 300 articles git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@403 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/read.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pttbbs/mbbsd/read.c b/pttbbs/mbbsd/read.c index 57671882..8fbbf9a9 100644 --- a/pttbbs/mbbsd/read.c +++ b/pttbbs/mbbsd/read.c @@ -1,4 +1,4 @@ -/* $Id: read.c,v 1.5 2002/06/09 04:28:10 lwms Exp $ */ +/* $Id: read.c,v 1.6 2002/07/02 15:08:52 in2 Exp $ */ #include "bbs.h" #define MAXPATHLEN 256 @@ -372,7 +372,7 @@ static int thread(keeploc_t *locmem, int stype) { if(++now > last_line) return DONOTHING; } else { - if(--now <= 0) { + if(--now <= 0 || now < pos - 300) { if((stype & RS_FIRST) && (near)) { hit_thread = 1; return cursor_pos(locmem, near, 10); -- cgit v1.2.3 From 97c6cc24030daf8fe09ff861d10d2ac723ac72e1 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Tue, 2 Jul 2002 16:13:37 +0000 Subject: fix buffer overflow, search use last value git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@404 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/read.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/pttbbs/mbbsd/read.c b/pttbbs/mbbsd/read.c index 8fbbf9a9..fe8c871d 100644 --- a/pttbbs/mbbsd/read.c +++ b/pttbbs/mbbsd/read.c @@ -1,4 +1,4 @@ -/* $Id: read.c,v 1.6 2002/07/02 15:08:52 in2 Exp $ */ +/* $Id: read.c,v 1.7 2002/07/02 16:13:37 in2 Exp $ */ #include "bbs.h" #define MAXPATHLEN 256 @@ -461,7 +461,7 @@ static int select_read(keeploc_t *locmem, int sr_mode) { fileheader_t fh; char fpath[80], genbuf[MAXPATHLEN], buf3[5]; char static t_ans[TTLEN+1]=""; - char static a_ans[IDLEN+1]=""; + char static a_ans[TTLEN+1]=""; int fd, fr, size = sizeof(fileheader_t); struct stat st; /* rocker.011018: make a reference number for process article */ @@ -479,11 +479,14 @@ static int select_read(keeploc_t *locmem, int sr_mode) { else { char buff[80]; + char newdata[35]; query = (sr_mode == RS_RELATED) ? t_ans : a_ans; sprintf(buff, "搜尋%s [%s] ", (sr_mode == RS_RELATED) ? "標題" : "作者", query); - getdata(b_lines, 0,buff, query, 30, DOECHO); + getdata(b_lines, 0, buff, newdata, sizeof(newdata), DOECHO); + if( newdata[0] ) + strcpy(query, newdata); if(!(*query)) return DONOTHING; } -- cgit v1.2.3 From 7f55953786fb554ae09961d62e07a466975a6967 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Tue, 2 Jul 2002 16:22:00 +0000 Subject: fix broadcast bug git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@405 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/talk.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/pttbbs/mbbsd/talk.c b/pttbbs/mbbsd/talk.c index add07deb..f02d3c14 100644 --- a/pttbbs/mbbsd/talk.c +++ b/pttbbs/mbbsd/talk.c @@ -1,4 +1,4 @@ -/* $Id: talk.c,v 1.75 2002/07/02 15:07:20 in2 Exp $ */ +/* $Id: talk.c,v 1.76 2002/07/02 16:22:00 in2 Exp $ */ #include "bbs.h" #define QCAST int (*)(const void *, const void *) @@ -2050,11 +2050,13 @@ static void userlist(void) *ans == 'n') break; if( !(cuser.uflag & FRIEND_FLAG) && HAS_PERM(PERM_SYSOP) ){ - for( i = 0 ; i < SHM->UTMPnumber && i<1000 ; ++i ){ + for( i = 0 ; i < SHM->UTMPnumber ; ++i ){ uentp = SHM->sorted[SHM->currsorted][0][i]; if( uentp->pid && kill(uentp->pid, 0) != -1 ) my_write(uentp->pid, genbuf, uentp->userid, 1, NULL); + if( i % 100 == 0 ) + sleep(1); } } else{ @@ -2071,7 +2073,8 @@ static void userlist(void) currutmp->friend_online[i]>>24) && kill(uentp->pid, 0) != -1 && uentp->pager != 3 && - (uentp->pager != 4 || frstate & HFM) ){ + (uentp->pager != 4 || frstate & HFM) && + !(frstate & IRH) ){ my_write(uentp->pid, genbuf, uentp->userid, 1, NULL); } -- cgit v1.2.3 From 0fc1088b726b2f0e5bb5ee0799f58002e7aec9f3 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Tue, 2 Jul 2002 18:54:28 +0000 Subject: secure .PASSWD git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@406 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/passwd.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/pttbbs/mbbsd/passwd.c b/pttbbs/mbbsd/passwd.c index 46ea1529..7e877ac4 100644 --- a/pttbbs/mbbsd/passwd.c +++ b/pttbbs/mbbsd/passwd.c @@ -1,4 +1,4 @@ -/* $Id: passwd.c,v 1.3 2002/06/30 14:33:14 in2 Exp $ */ +/* $Id: passwd.c,v 1.4 2002/07/02 18:54:28 in2 Exp $ */ #include "bbs.h" static int semid = -1; @@ -20,10 +20,7 @@ union semun { }; #endif -int PASSWDfd; int passwd_mmap() { - if( (PASSWDfd = open(fn_passwd, O_RDWR)) < 0 || PASSWDfd <= 1 ) - return -1; semid = semget(PASSWDSEM_KEY, 1, SEM_R | SEM_A | IPC_CREAT | IPC_EXCL); if(semid == -1) { if(errno == EEXIST) { @@ -60,19 +57,27 @@ int passwd_update_money(int num) { } int passwd_update(int num, userec_t *buf) { + int pwdfd; if(num < 1 || num > MAX_USERS) return -1; buf->money = moneyof(num); - lseek(PASSWDfd, sizeof(userec_t) * (num - 1), SEEK_SET); - write(PASSWDfd, buf, sizeof(userec_t)); + if( (pwdfd = open(fn_passwd, O_RDWR)) < 0 ) + exit(1); + lseek(pwdfd, sizeof(userec_t) * (num - 1), SEEK_SET); + write(pwdfd, buf, sizeof(userec_t)); + close(pwdfd); return 0; } int passwd_query(int num, userec_t *buf) { + int pwdfd; if(num < 1 || num > MAX_USERS) return -1; - lseek(PASSWDfd, sizeof(userec_t) * (num - 1), SEEK_SET); - read(PASSWDfd, buf, sizeof(userec_t)); + if( (pwdfd = open(fn_passwd, O_RDONLY)) < 0 ) + exit(1); + lseek(pwdfd, sizeof(userec_t) * (num - 1), SEEK_SET); + read(pwdfd, buf, sizeof(userec_t)); + close(pwdfd); return 0; } -- cgit v1.2.3 From 32633f53d27446544fcf296c16c5b1c2bfe6625a Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Tue, 2 Jul 2002 19:17:31 +0000 Subject: do NOT reload memory if shared-memoy fails git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@407 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/passwd.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pttbbs/mbbsd/passwd.c b/pttbbs/mbbsd/passwd.c index 7e877ac4..4291fa3e 100644 --- a/pttbbs/mbbsd/passwd.c +++ b/pttbbs/mbbsd/passwd.c @@ -1,4 +1,4 @@ -/* $Id: passwd.c,v 1.4 2002/07/02 18:54:28 in2 Exp $ */ +/* $Id: passwd.c,v 1.5 2002/07/02 19:17:31 in2 Exp $ */ #include "bbs.h" static int semid = -1; @@ -51,7 +51,8 @@ int passwd_update_money(int num) { if(num < 1 || num > MAX_USERS) return -1; passwd_query(num, &user); - user.money = moneyof(num); + if( SHM->loaded ) + user.money = moneyof(num); passwd_update(num, &user); return 0; } -- cgit v1.2.3 From dbf19de33a1d05dd2322a57dc84ccb672f6323ad Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Wed, 3 Jul 2002 09:08:14 +0000 Subject: =?UTF-8?q?=20=20=20=20if(=20!(strstr(fhdr->title,=20"=EF=BF=BD?= =?UTF-8?q?=EF=BF=BD=EF=BF=BDu")=20&&=20strstr(fhdr->title,=20"=EF=BF=BDO?= =?UTF-8?q?=EF=BF=BD=EF=BF=BD"))=20){?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@408 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/mail.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pttbbs/mbbsd/mail.c b/pttbbs/mbbsd/mail.c index a4d47df7..35fced7e 100644 --- a/pttbbs/mbbsd/mail.c +++ b/pttbbs/mbbsd/mail.c @@ -1,4 +1,4 @@ -/* $Id: mail.c,v 1.15 2002/07/02 02:12:56 in2 Exp $ */ +/* $Id: mail.c,v 1.16 2002/07/03 09:08:14 in2 Exp $ */ #include "bbs.h" char currmaildir[32]; static char msg_cc[] = "\033[32m[群組名單]\033[m\n"; @@ -1220,7 +1220,7 @@ static int mail_waterball(int ent, fileheader_t *fhdr, char *direct) char fname[500], genbuf[200]; FILE *fp; - if( !strstr(fhdr->title, "熱線記錄") ){ + if( !(strstr(fhdr->title, "熱線") && strstr(fhdr->title, "記錄")) ){ vmsg("必須是 熱線記錄 才能使用水球整理的唷!"); return 1; } -- cgit v1.2.3 From 6ab3fd7a3daa3a483f57e2d764df81daef5a7233 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Wed, 3 Jul 2002 09:14:57 +0000 Subject: fix wrong word git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@409 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/mail.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pttbbs/mbbsd/mail.c b/pttbbs/mbbsd/mail.c index 35fced7e..bc7d25a5 100644 --- a/pttbbs/mbbsd/mail.c +++ b/pttbbs/mbbsd/mail.c @@ -1,4 +1,4 @@ -/* $Id: mail.c,v 1.16 2002/07/03 09:08:14 in2 Exp $ */ +/* $Id: mail.c,v 1.17 2002/07/03 09:14:57 in2 Exp $ */ #include "bbs.h" char currmaildir[32]; static char msg_cc[] = "\033[32m[群組名單]\033[m\n"; @@ -1228,7 +1228,7 @@ static int mail_waterball(int ent, fileheader_t *fhdr, char *direct) strcpy(address, cuser.email); move(b_lines - 5, 0); outs("水球整理程式:\n" - "系統將會按照和不同人丟的水球各獨自獨立\n" + "系統將會按照和不同人丟的水球各自獨立\n" "於整點的時候 (尖鋒時段除外) 將資料整理好寄送給您\n\n\n"); if(address[0]) { sprintf(genbuf, "寄給 [%s] 嗎(Y/N/Q)?[Y] ", address); -- cgit v1.2.3 From 11d6ed75c8a8ccdef78727e8c3748fabe7ee7015 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Thu, 4 Jul 2002 09:33:10 +0000 Subject: weather url changed git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@410 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/weather.perl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pttbbs/util/weather.perl b/pttbbs/util/weather.perl index c9a35406..276ba8a5 100644 --- a/pttbbs/util/weather.perl +++ b/pttbbs/util/weather.perl @@ -1,5 +1,5 @@ #!/usr/bin/perl -# $Id: weather.perl,v 1.1 2002/03/07 15:13:46 in2 Exp $ +# $Id: weather.perl,v 1.2 2002/07/04 09:33:10 in2 Exp $ # # 不能跑的話,看看 bbspost 的路徑是否正確。 # 如果發出的 post 沒有氣象報告而是說 URL 找不到,則確定一下能不能看到 @@ -15,7 +15,7 @@ close DATE; # Header # 內容 -open(WEATHER, "/usr/bin/lynx -dump http://www.cwb.gov.tw/V3.0/weather/text/Data/W03.txt |"); +open(WEATHER, "/usr/bin/lynx -dump http://www.cwb.gov.tw/V3.0/weather/text/W03.htm |"); while (<WEATHER>) { print BBSPOST if ($_ ne "\n"); } -- cgit v1.2.3 From 72199b0c7909510d40b68afdc538ff535dff4939 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Thu, 4 Jul 2002 19:46:16 +0000 Subject: remove mmap git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@411 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/include/proto.h | 4 ++-- pttbbs/mbbsd/cache.c | 19 +------------------ pttbbs/mbbsd/mbbsd.c | 6 +++--- pttbbs/mbbsd/passwd.c | 4 ++-- 4 files changed, 8 insertions(+), 25 deletions(-) diff --git a/pttbbs/include/proto.h b/pttbbs/include/proto.h index 2f916219..5e3d8f91 100644 --- a/pttbbs/include/proto.h +++ b/pttbbs/include/proto.h @@ -1,4 +1,4 @@ -/* $Id: proto.h,v 1.23 2002/06/26 09:51:33 ptt Exp $ */ +/* $Id: proto.h,v 1.24 2002/07/04 19:46:14 in2 Exp $ */ #ifndef INCLUDE_PROTO_H #define INCLUDE_PROTO_H @@ -550,7 +550,7 @@ int Goodbye(); unsigned StringHash(unsigned char *s); /* passwd */ -int passwd_mmap(); +int passwd_init(); int passwd_update(int num, userec_t *buf); int passwd_query(int num, userec_t *buf); int passwd_apply(int (*fptr)(userec_t *)); diff --git a/pttbbs/mbbsd/cache.c b/pttbbs/mbbsd/cache.c index 9b14eb8a..206b39e3 100644 --- a/pttbbs/mbbsd/cache.c +++ b/pttbbs/mbbsd/cache.c @@ -1,4 +1,4 @@ -/* $Id: cache.c,v 1.39 2002/06/26 01:55:30 in2 Exp $ */ +/* $Id: cache.c,v 1.40 2002/07/04 19:46:16 in2 Exp $ */ #include "bbs.h" #ifndef __FreeBSD__ @@ -56,19 +56,6 @@ void *attach_shm(int shmkey, int shmsize) { void *shmptr; int shmid; - char *empty_addr; - /* set up one page in-accessible -- jochang */ - { - int fd = open("/dev/zero",O_RDONLY); - int size = ((shmsize + 4095) / 4096) * 4096; - - munmap( - (empty_addr=mmap(0,4096+size,PROT_NONE,MAP_PRIVATE,fd,0))+4096 - ,size); - - close(fd); - } - shmid = shmget(shmkey, shmsize, 0); if(shmid < 0) { shmid = shmget(shmkey, shmsize, IPC_CREAT | 0600); @@ -83,10 +70,6 @@ void *attach_shm(int shmkey, int shmsize) { attach_err(shmkey, "shmat"); } - /* unmap the page -- jochang */ - { - munmap(empty_addr,4096); - } return shmptr; } diff --git a/pttbbs/mbbsd/mbbsd.c b/pttbbs/mbbsd/mbbsd.c index 2b33fc2c..ae560338 100644 --- a/pttbbs/mbbsd/mbbsd.c +++ b/pttbbs/mbbsd/mbbsd.c @@ -1,4 +1,4 @@ -/* $Id: mbbsd.c,v 1.36 2002/06/30 14:33:14 in2 Exp $ */ +/* $Id: mbbsd.c,v 1.37 2002/07/04 19:46:16 in2 Exp $ */ #include "bbs.h" #define SOCKET_QLEN 4 @@ -956,8 +956,8 @@ start_client () dup2 (0, 1); - /* mmap passwd file */ - if (passwd_mmap ()) + /* initialize passwd semaphores */ + if( passwd_init() ) exit (1); do_term_init (); diff --git a/pttbbs/mbbsd/passwd.c b/pttbbs/mbbsd/passwd.c index 4291fa3e..06a26d32 100644 --- a/pttbbs/mbbsd/passwd.c +++ b/pttbbs/mbbsd/passwd.c @@ -1,4 +1,4 @@ -/* $Id: passwd.c,v 1.5 2002/07/02 19:17:31 in2 Exp $ */ +/* $Id: passwd.c,v 1.6 2002/07/04 19:46:16 in2 Exp $ */ #include "bbs.h" static int semid = -1; @@ -20,7 +20,7 @@ union semun { }; #endif -int passwd_mmap() { +int passwd_init() { semid = semget(PASSWDSEM_KEY, 1, SEM_R | SEM_A | IPC_CREAT | IPC_EXCL); if(semid == -1) { if(errno == EEXIST) { -- cgit v1.2.3 From 9e5d6c45157f1c016389bbf39b2facf407a3f756 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Thu, 4 Jul 2002 20:08:11 +0000 Subject: mind git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@412 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/include/pttstruct.h | 6 +++--- pttbbs/mbbsd/mbbsd.c | 6 +++--- pttbbs/mbbsd/talk.c | 43 +++++++++++++++++++++---------------------- 3 files changed, 27 insertions(+), 28 deletions(-) diff --git a/pttbbs/include/pttstruct.h b/pttbbs/include/pttstruct.h index 8570aa22..f7690f43 100644 --- a/pttbbs/include/pttstruct.h +++ b/pttbbs/include/pttstruct.h @@ -1,4 +1,4 @@ -/* $Id: pttstruct.h,v 1.22 2002/06/29 13:52:31 ptt Exp $ */ +/* $Id: pttstruct.h,v 1.23 2002/07/04 20:08:09 in2 Exp $ */ #ifndef INCLUDE_STRUCT_H #define INCLUDE_STRUCT_H @@ -72,7 +72,7 @@ typedef struct userec_t { unsigned short chc_lose; unsigned short chc_tie; int mobile; - int mind; + char mind[4]; char ident[11]; unsigned int uflag2; time_t recommend; @@ -245,7 +245,7 @@ typedef struct userinfo_t { int mailalert; int sex; char color; - int mind; + char mind[4]; #ifdef MULTI_SERVER char hostid; #endif diff --git a/pttbbs/mbbsd/mbbsd.c b/pttbbs/mbbsd/mbbsd.c index ae560338..9309668d 100644 --- a/pttbbs/mbbsd/mbbsd.c +++ b/pttbbs/mbbsd/mbbsd.c @@ -1,4 +1,4 @@ -/* $Id: mbbsd.c,v 1.37 2002/07/04 19:46:16 in2 Exp $ */ +/* $Id: mbbsd.c,v 1.38 2002/07/04 20:08:11 in2 Exp $ */ #include "bbs.h" #define SOCKET_QLEN 4 @@ -168,7 +168,7 @@ u_exit (char *mode) cuser.invisible = currutmp->invisible; cuser.pager = currutmp->pager; - cuser.mind = currutmp->mind; + memcpy(cuser.mind, currutmp->mind, 4); setutmpbid(0); if (!(HAS_PERM (PERM_SYSOP) && HAS_PERM (PERM_DENYPOST)) && !currutmp->invisible ) @@ -739,7 +739,7 @@ setup_utmp (int mode) uinfo.five_tie = cuser.five_tie; uinfo.invisible = cuser.invisible % 2; uinfo.pager = cuser.pager%5; - uinfo.mind = cuser.mind; + memcpy(uinfo.mind, cuser.mind, 4); #ifdef WHERE uinfo.from_alias = where (fromhost); #endif diff --git a/pttbbs/mbbsd/talk.c b/pttbbs/mbbsd/talk.c index f02d3c14..9c8dba8d 100644 --- a/pttbbs/mbbsd/talk.c +++ b/pttbbs/mbbsd/talk.c @@ -1,4 +1,4 @@ -/* $Id: talk.c,v 1.76 2002/07/02 16:22:00 in2 Exp $ */ +/* $Id: talk.c,v 1.77 2002/07/04 20:08:11 in2 Exp $ */ #include "bbs.h" #define QCAST int (*)(const void *, const void *) @@ -1603,14 +1603,6 @@ static void pickup(pickup_t *currpickup, int pickup_way, int *page, currpickup[size].ui = 0; } -char *Mind[] = { - " ", - "^-^", "^_^", "Q_Q", "@_@", "/_\\", "=_=", "-_-", "-.-", ">_<", - "-_+", "!_!", "o_o", "z_Z", "O_O", "O.O", "$_$", "^*^", "O_<", - "喜!", "怒!", "哀!", "樂!", ":) ", ":( ", ":~ ", ":q ", ":O ", - ":D ", ":p ", ";) ", ":> ", ";> ", ":< ", ":)~", ":D~", ">< ", - "^^;", "^^|", "哭;", NULL -}; static void draw_pickup(int drawall, pickup_t *pickup, int pickup_way, int page, int show_mode, int show_uid, int show_board, int show_pid, int real_name, @@ -1624,6 +1616,7 @@ static void draw_pickup(int drawall, pickup_t *pickup, int pickup_way, userinfo_t *uentp; int i, ch, state, friend; + char mind[5]; #ifdef SHOW_IDLE_TIME char idlestr[32]; int idletime; @@ -1693,6 +1686,13 @@ static void draw_pickup(int drawall, pickup_t *pickup, int pickup_way, strcpy(idlestr, " "); #endif + if( (uentp->userlevel & PERM_VIOLATELAW) ) + memcpy(mind, "通緝", 4); + else if( uentp->birth ) + memcpy(mind, "壽星", 4); + else + memcpy(mind, uentp->mind, 4); + mind[4] = 0; prints("%5d %c%c%s%-13s%-17.16s\033[m%-17.16s%-13.13s" "\33[33m%-4.4s\33[m%s\n", @@ -1730,8 +1730,7 @@ static void draw_pickup(int drawall, pickup_t *pickup, int pickup_way, modestring(uentp, 0), /* memo */ - ((uentp->userlevel & PERM_VIOLATELAW) ? "通緝" : - (uentp->birth ? "壽星" : Mind[uentp->mind])), + mind, /* idle */ #ifdef SHOW_IDLE_TIME @@ -2105,17 +2104,17 @@ static void userlist(void) } break; - case 'i': - move(3,0); - clrtobot(); - for( i = 0 ; Mind[i] != NULL ; ++i ){ - move(5 + (i - 1) / 7, ((i - 1) % 7) * 10); - prints("%2d: %s", i, Mind[i]); - } - getdata(b_lines - 1, 0, "你現在的心情 0:無 q不變 [q]:", - genbuf, 3, LCECHO); - if( genbuf[0] && genbuf[0] != 'q' && atoi(genbuf) >= 0) - currutmp->mind = atoi(genbuf) % i; + case 'i':{ + char mindbuf[5]; + getdata(b_lines - 1, 0, "現在的心情? ", + mindbuf, sizeof(mindbuf), LCECHO); + if( strcmp(mindbuf, "通緝") == 0 ) + vmsg("不可以把自己設通緝啦!"); + else if( strcmp(mindbuf, "壽星") == 0 ) + vmsg("你不是今天生日欸!"); + else + memcpy(currutmp->mind, mindbuf, 4); + } redrawall = redraw = 1; break; -- cgit v1.2.3 From 182b16dde08e2ab6c1ef7d5a21f6baae71360a92 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Fri, 5 Jul 2002 10:59:29 +0000 Subject: remove mind fix git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@413 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/shmctl.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/pttbbs/util/shmctl.c b/pttbbs/util/shmctl.c index 348b6024..bdefc8e2 100644 --- a/pttbbs/util/shmctl.c +++ b/pttbbs/util/shmctl.c @@ -1,4 +1,4 @@ -/* $Id: shmctl.c,v 1.23 2002/06/30 18:16:33 in2 Exp $ */ +/* $Id: shmctl.c,v 1.24 2002/07/05 10:59:29 in2 Exp $ */ #include "bbs.h" extern SHM_t *SHM; @@ -102,11 +102,6 @@ int utmpfix(int argc, char **argv) i, clean, SHM->uinfo[i].userid); memset(&SHM->uinfo[i], 0, sizeof(userinfo_t)); } - else if ( SHM->uinfo[i].mind > 40 ){ - printf("mind fix: %06d, userid: %s, mind: %d\n", - i, SHM->uinfo[i].userid, SHM->uinfo[i].mind); - SHM->uinfo[i].mind %= 40; - } } SHM->UTMPbusystate = 0; return 0; -- cgit v1.2.3 From 5252dc3780ae4136b13ce300c9c217ac82374bc6 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Fri, 5 Jul 2002 13:18:29 +0000 Subject: sysinfo git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@414 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd.icc/Makefile | 1 + pttbbs/mbbsd/Makefile | 4 +++- pttbbs/mbbsd/cal.c | 33 ++++++++++++++++++--------------- pttbbs/mbbsd/mbbsd.c | 4 +++- pttbbs/mbbsd/var.c | 3 ++- 5 files changed, 27 insertions(+), 18 deletions(-) diff --git a/pttbbs/mbbsd.icc/Makefile b/pttbbs/mbbsd.icc/Makefile index 6d7e5f53..c78d8f86 100644 --- a/pttbbs/mbbsd.icc/Makefile +++ b/pttbbs/mbbsd.icc/Makefile @@ -31,6 +31,7 @@ LDFLAGS+= -DDEBUG CFLAGS+= -DNO_FORK .endif +CFLAGS+= "-DCOMPILE_TIME=\"`date`\"" GCCUSE=gcc -pipe -Wall $(CFLAGS) -c .SUFFIXES: .c .o diff --git a/pttbbs/mbbsd/Makefile b/pttbbs/mbbsd/Makefile index 54882a35..5d9d4f2b 100644 --- a/pttbbs/mbbsd/Makefile +++ b/pttbbs/mbbsd/Makefile @@ -1,4 +1,4 @@ -# $Id: Makefile,v 1.11 2002/06/26 19:38:16 kcwu Exp $ +# $Id: Makefile,v 1.12 2002/07/05 13:18:27 in2 Exp $ BBSHOME?=$(HOME) OSTYPE=FreeBSD @@ -34,6 +34,8 @@ LDFLAGS+= -DDEBUG CFLAGS+= -DNO_FORK .endif +CFLAGS+= "-DCOMPILE_TIME=\"`date`\"" + CC= gcc PROG= mbbsd OBJS= admin.o announce.o args.o bbs.o board.o cache.o cal.o card.o\ diff --git a/pttbbs/mbbsd/cal.c b/pttbbs/mbbsd/cal.c index dbb90c71..995f4c55 100644 --- a/pttbbs/mbbsd/cal.c +++ b/pttbbs/mbbsd/cal.c @@ -1,4 +1,4 @@ -/* $Id: cal.c,v 1.14 2002/06/06 21:34:11 in2 Exp $ */ +/* $Id: cal.c,v 1.15 2002/07/05 13:14:14 in2 Exp $ */ #include "bbs.h" /* 防堵 Multi play */ @@ -375,21 +375,24 @@ int p_give() { return 0; } -int p_sysinfo() { - char buf[100]; - long int total,used; - float p; - - move(b_lines-1,0); - clrtoeol(); - cpuload(buf); - outs("CPU 負荷 : "); - outs(buf); +int p_sysinfo(void) +{ + char buf[128], *cpuloadstr; + int load; + + load = cpuload(buf); + cpuloadstr = (load < 5 ? "良好" : (load < 20 ? "尚可" : "過重")); - p = swapused(&total,&used); - sprintf(buf, " 虛擬記憶體: %.1f%%(全部:%ldMB 用掉:%ldMB)\n", - p*100, total >> 20, used >> 20); - outs(buf); + clear(); + showtitle("系統資訊", BBSNAME); + move(2, 0); + prints("您現在位於 " TITLE_COLOR BBSNAME "\033[m (" MYIP ")\n" + "系統負載情況: %s\n" + "線上服務人數: %d/%d\n" + "編譯時間: %s\n" + "起始時間: %s\n", + cpuloadstr, SHM->UTMPnumber, + MAX_ACTIVE, COMPILE_TIME, ctime(&start_time)); pressanykey(); return 0; } diff --git a/pttbbs/mbbsd/mbbsd.c b/pttbbs/mbbsd/mbbsd.c index 9309668d..5109474d 100644 --- a/pttbbs/mbbsd/mbbsd.c +++ b/pttbbs/mbbsd/mbbsd.c @@ -1,4 +1,4 @@ -/* $Id: mbbsd.c,v 1.38 2002/07/04 20:08:11 in2 Exp $ */ +/* $Id: mbbsd.c,v 1.39 2002/07/05 13:14:14 in2 Exp $ */ #include "bbs.h" #define SOCKET_QLEN 4 @@ -1174,6 +1174,8 @@ static int check_ban_and_load (int fd); int main (int argc, char *argv[], char *envp[]) { + start_time = time(NULL); + /* avoid SIGPIPE */ signal (SIGPIPE, SIG_IGN); diff --git a/pttbbs/mbbsd/var.c b/pttbbs/mbbsd/var.c index 4fe601b1..fe778782 100644 --- a/pttbbs/mbbsd/var.c +++ b/pttbbs/mbbsd/var.c @@ -1,4 +1,4 @@ -/* $Id: var.c,v 1.8 2002/06/19 13:32:23 lwms Exp $ */ +/* $Id: var.c,v 1.9 2002/07/05 13:14:14 in2 Exp $ */ #define INCLUDE_VAR_H #include "bbs.h" @@ -93,6 +93,7 @@ char reset_color[4] = "\033[m"; char margs[64] = "\0"; /* main argv list*/ pid_t currpid; /* current process ID */ time_t login_start_time; +time_t start_time; time_t paste_time; userec_t cuser; /* current user structure */ userec_t xuser; /* lookup user structure */ -- cgit v1.2.3 From 7cdc62557c8063bd66b5f4ef74a29dd1fed5c514 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Fri, 5 Jul 2002 17:10:28 +0000 Subject: indent git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@415 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/include/pttstruct.h | 322 +++--- pttbbs/mbbsd/admin.c | 782 +++++++------ pttbbs/mbbsd/announce.c | 1122 +++++++++--------- pttbbs/mbbsd/args.c | 60 +- pttbbs/mbbsd/bbcall.c | 131 ++- pttbbs/mbbsd/bbs.c | 2736 ++++++++++++++++++++++---------------------- pttbbs/mbbsd/board.c | 1078 ++++++++--------- pttbbs/mbbsd/cache.c | 1114 ++++++++++-------- pttbbs/mbbsd/cal.c | 456 ++++---- pttbbs/mbbsd/calendar.c | 260 +++-- pttbbs/mbbsd/card.c | 964 ++++++++-------- pttbbs/mbbsd/chat.c | 369 +++--- pttbbs/mbbsd/chc_draw.c | 119 +- pttbbs/mbbsd/chc_net.c | 22 +- pttbbs/mbbsd/chc_play.c | 133 ++- pttbbs/mbbsd/chc_rule.c | 212 ++-- pttbbs/mbbsd/chicken.c | 848 +++++++------- pttbbs/mbbsd/dark.c | 725 +++++++----- pttbbs/mbbsd/descrypt.c | 451 ++++---- pttbbs/mbbsd/dice.c | 445 +++---- pttbbs/mbbsd/edit.c | 1722 ++++++++++++++-------------- pttbbs/mbbsd/friend.c | 311 +++-- pttbbs/mbbsd/gamble.c | 586 +++++----- pttbbs/mbbsd/gomo.c | 303 ++--- pttbbs/mbbsd/gomo1.c | 108 +- pttbbs/mbbsd/guess.c | 308 ++--- pttbbs/mbbsd/indict.c | 150 +-- pttbbs/mbbsd/io.c | 478 ++++---- pttbbs/mbbsd/kaede.c | 77 +- pttbbs/mbbsd/lovepaper.c | 81 +- pttbbs/mbbsd/mail.c | 1119 +++++++++--------- pttbbs/mbbsd/mbbsd.c | 1504 ++++++++++++------------ pttbbs/mbbsd/menu.c | 446 ++++---- pttbbs/mbbsd/more.c | 782 ++++++------- pttbbs/mbbsd/name.c | 671 +++++------ pttbbs/mbbsd/osdep.c | 74 +- pttbbs/mbbsd/othello.c | 427 +++---- pttbbs/mbbsd/page.c | 128 ++- pttbbs/mbbsd/passwd.c | 94 +- pttbbs/mbbsd/read.c | 810 +++++++------ pttbbs/mbbsd/record.c | 467 ++++---- pttbbs/mbbsd/register.c | 296 ++--- pttbbs/mbbsd/screen.c | 410 ++++--- pttbbs/mbbsd/stuff.c | 549 +++++---- pttbbs/mbbsd/syspost.c | 118 +- pttbbs/mbbsd/talk.c | 1741 ++++++++++++++-------------- pttbbs/mbbsd/term.c | 98 +- pttbbs/mbbsd/toolkit.c | 10 +- pttbbs/mbbsd/topsong.c | 72 +- pttbbs/mbbsd/user.c | 896 ++++++++------- pttbbs/mbbsd/var.c | 971 ++++++++-------- pttbbs/mbbsd/vice.c | 155 +-- pttbbs/mbbsd/vote.c | 810 ++++++------- pttbbs/mbbsd/voteboard.c | 302 ++--- pttbbs/mbbsd/xyz.c | 301 +++-- 55 files changed, 15416 insertions(+), 14308 deletions(-) diff --git a/pttbbs/include/pttstruct.h b/pttbbs/include/pttstruct.h index f7690f43..a6e71118 100644 --- a/pttbbs/include/pttstruct.h +++ b/pttbbs/include/pttstruct.h @@ -1,33 +1,33 @@ -/* $Id: pttstruct.h,v 1.23 2002/07/04 20:08:09 in2 Exp $ */ +/* $Id: pttstruct.h,v 1.24 2002/07/05 17:10:23 in2 Exp $ */ #ifndef INCLUDE_STRUCT_H #define INCLUDE_STRUCT_H /* 小雞的資料 */ typedef struct chicken_t { - char name[20]; - char type; /* 物種 */ - unsigned char tech[16]; /* 技能 */ - time_t birthday; /* 生日 */ - time_t lastvisit; /* 上次照顧時間 */ - int oo; /* 補品 */ - int food; /* 食物 */ - int medicine; /* 藥品 */ - int weight; /* 體重 */ - int clean; /* 乾淨 */ - int run; /* 敏捷度 */ - int attack; /* 攻擊力 */ - int book; /* 知識 */ - int happy; /* 快樂 */ - int satis; /* 滿意度 */ - int temperament; /* 氣質 */ - int tiredstrong; /* 疲勞度 */ - int sick; /* 病氣指數 */ - int hp; /* 血量 */ - int hp_max; /* 滿血量 */ - int mm; /* 法力 */ - int mm_max; /* 滿法力 */ - time_t cbirth; /* 實際計算用的生日 */ - int pad[2]; /* 留著以後用 */ + char name[20]; + char type; /* 物種 */ + unsigned char tech[16]; /* 技能 */ + time_t birthday; /* 生日 */ + time_t lastvisit; /* 上次照顧時間 */ + int oo; /* 補品 */ + int food; /* 食物 */ + int medicine; /* 藥品 */ + int weight; /* 體重 */ + int clean; /* 乾淨 */ + int run; /* 敏捷度 */ + int attack; /* 攻擊力 */ + int book; /* 知識 */ + int happy; /* 快樂 */ + int satis; /* 滿意度 */ + int temperament; /* 氣質 */ + int tiredstrong; /* 疲勞度 */ + int sick; /* 病氣指數 */ + int hp; /* 血量 */ + int hp_max; /* 滿血量 */ + int mm; /* 法力 */ + int mm_max; /* 滿法力 */ + time_t cbirth; /* 實際計算用的生日 */ + int pad[2]; /* 留著以後用 */ } chicken_t; #define IDLEN 12 /* Length of bid/uid */ @@ -35,48 +35,48 @@ typedef struct chicken_t { #define REGLEN 38 /* Length of registration data */ typedef struct userec_t { - char userid[IDLEN + 1]; - char realname[20]; - char username[24]; - char passwd[PASSLEN]; - unsigned char uflag; - unsigned int userlevel; - unsigned short numlogins; - unsigned short numposts; - time_t firstlogin; - time_t lastlogin; - char lasthost[16]; - int money; - char remoteuser[3]; /* 保留 目前沒用到的 */ - char proverb; - char email[50]; - char address[50]; - char justify[REGLEN + 1]; - unsigned char month; - unsigned char day; - unsigned char year; - unsigned char sex; - unsigned char state; - unsigned char pager; - unsigned char invisible; - unsigned int exmailbox; - chicken_t mychicken; - time_t lastsong; - unsigned int loginview; - unsigned char channel; /* 動態看板 */ - unsigned short vl_count; /* ViolateLaw counter */ - unsigned short five_win; - unsigned short five_lose; - unsigned short five_tie; - unsigned short chc_win; - unsigned short chc_lose; - unsigned short chc_tie; - int mobile; - char mind[4]; - char ident[11]; - unsigned int uflag2; - time_t recommend; - char pad[68]; + char userid[IDLEN + 1]; + char realname[20]; + char username[24]; + char passwd[PASSLEN]; + unsigned char uflag; + unsigned int userlevel; + unsigned short numlogins; + unsigned short numposts; + time_t firstlogin; + time_t lastlogin; + char lasthost[16]; + int money; + char remoteuser[3]; /* 保留 目前沒用到的 */ + char proverb; + char email[50]; + char address[50]; + char justify[REGLEN + 1]; + unsigned char month; + unsigned char day; + unsigned char year; + unsigned char sex; + unsigned char state; + unsigned char pager; + unsigned char invisible; + unsigned int exmailbox; + chicken_t mychicken; + time_t lastsong; + unsigned int loginview; + unsigned char channel; /* 動態看板 */ + unsigned short vl_count; /* ViolateLaw counter */ + unsigned short five_win; + unsigned short five_lose; + unsigned short five_tie; + unsigned short chc_win; + unsigned short chc_lose; + unsigned short chc_tie; + int mobile; + char mind[4]; + char ident[11]; + unsigned int uflag2; + time_t recommend; + char pad[68]; } userec_t; /* these are flags in userec_t.uflag */ #define SIG_FLAG 0x3 /* signature number, 2 bits */ @@ -139,13 +139,13 @@ typedef struct boardheader_t { #define FHR_REFERENCE (1<<31) typedef struct fileheader_t { - char filename[FNLEN]; /* M.9876543210.A */ - char recommend; /* important level */ - char owner[IDLEN + 2]; /* uid[.] */ - char date[6]; /* [02/02] or space(5) */ - char title[TTLEN + 1]; - int money; /* rocker: if bit32 on ==> reference */ - unsigned char filemode; /* must be last field @ boards.c */ + char filename[FNLEN]; /* M.9876543210.A */ + char recommend; /* important level */ + char owner[IDLEN + 2]; /* uid[.] */ + char date[6]; /* [02/02] or space(5) */ + char title[TTLEN + 1]; + int money; /* rocker: if bit32 on ==> reference */ + unsigned char filemode; /* must be last field @ boards.c */ } fileheader_t; #define FILE_LOCAL 0x1 /* local saved */ @@ -168,27 +168,27 @@ typedef struct fileheader_t { union xitem_t { struct { /* bbs_item */ - char fdate[9]; /* [mm/dd/yy] */ - char editor[13]; /* user ID */ - char fname[31]; + char fdate[9]; /* [mm/dd/yy] */ + char editor[13]; /* user ID */ + char fname[31]; } B; struct { /* gopher_item */ - char path[81]; - char server[48]; - int port; + char path[81]; + char server[48]; + int port; } G; }; typedef struct { - char title[63]; - union xitem_t X; + char title[63]; + union xitem_t X; } item_t; typedef struct { - item_t *item[MAX_ITEMS]; - char mtitle[STRLEN]; - char *path; - int num, page, now, level; + item_t *item[MAX_ITEMS]; + char mtitle[STRLEN]; + char *path; + int num, page, now, level; } gmenu_t; #define FAVMAX 74 /* Max boards of Myfavorite */ @@ -196,56 +196,56 @@ typedef struct { #define FAVGSLEN 8 /* Max Length of Description String */ typedef struct msgque_t { - pid_t pid; - char userid[IDLEN + 1]; - char last_call_in[80]; + pid_t pid; + char userid[IDLEN + 1]; + char last_call_in[80]; } msgque_t; typedef struct userinfo_t { - int uid; /* Used to find user name in passwd file */ - pid_t pid; /* kill() to notify user of talk request */ - int sockaddr; /* ... */ - int destuid; /* talk uses this to identify who called */ - int destuip; /* dest index in utmpshm->uinfo[] */ - unsigned char active; /* When allocated this field is true */ - unsigned char invisible; /* Used by cloaking function in Xyz menu */ - unsigned char sockactive; /* Used to coordinate talk requests */ - unsigned int userlevel; - unsigned char mode; /* UL/DL, Talk Mode, Chat Mode, ... */ - unsigned char pager; /* pager toggle, YEA, or NA */ - unsigned char in_chat; /* for in_chat commands */ - unsigned char sig; /* signal type */ - char userid[IDLEN + 1]; - char chatid[11]; /* chat id, if in chat mode */ - char realname[20]; - char username[24]; - char from[27]; /* machine name the user called in from */ - int from_alias; - char birth; /* 是否是生日 Ptt*/ - char tty[11]; /* tty port */ - int friend[MAX_FRIEND]; - int friend_online[MAX_FRIEND];/* point到線上好友 utmpshm的位置 */ + int uid; /* Used to find user name in passwd file */ + pid_t pid; /* kill() to notify user of talk request */ + int sockaddr; /* ... */ + int destuid; /* talk uses this to identify who called */ + int destuip; /* dest index in utmpshm->uinfo[] */ + unsigned char active; /* When allocated this field is true */ + unsigned char invisible; /* Used by cloaking function in Xyz menu */ + unsigned char sockactive; /* Used to coordinate talk requests */ + unsigned int userlevel; + unsigned char mode; /* UL/DL, Talk Mode, Chat Mode, ... */ + unsigned char pager; /* pager toggle, YEA, or NA */ + unsigned char in_chat; /* for in_chat commands */ + unsigned char sig; /* signal type */ + char userid[IDLEN + 1]; + char chatid[11]; /* chat id, if in chat mode */ + char realname[20]; + char username[24]; + char from[27]; /* machine name the user called in from */ + int from_alias; + char birth; /* 是否是生日 Ptt*/ + char tty[11]; /* tty port */ + int friend[MAX_FRIEND]; + int friend_online[MAX_FRIEND];/* point到線上好友 utmpshm的位置 */ /* 好友比較的cache 前兩個bit是狀態 */ - int reject[MAX_REJECT]; - char pad[4]; /* original void *nextbfriend; */ - int idoffset; /* shm id上的 offset */ - int lock; - int friendtotal; /* 好友比較的cache 大小 */ - unsigned char msgcount; - msgque_t msgs[MAX_MSGS]; - time_t uptime; - time_t lastact; /* 上次使用者動的時間 */ - unsigned int brc_id; - unsigned char lockmode; /* 不准 multi_login 玩的東西 */ - char turn; /* for gomo */ - char mateid[IDLEN + 1]; /* for gomo */ - unsigned short int five_win; - unsigned short int five_lose; - unsigned short int five_tie; - int mailalert; - int sex; - char color; - char mind[4]; + int reject[MAX_REJECT]; + char pad[4]; /* original void *nextbfriend; */ + int idoffset; /* shm id上的 offset */ + int lock; + int friendtotal; /* 好友比較的cache 大小 */ + unsigned char msgcount; + msgque_t msgs[MAX_MSGS]; + time_t uptime; + time_t lastact; /* 上次使用者動的時間 */ + unsigned int brc_id; + unsigned char lockmode; /* 不准 multi_login 玩的東西 */ + char turn; /* for gomo */ + char mateid[IDLEN + 1]; /* for gomo */ + unsigned short int five_win; + unsigned short int five_lose; + unsigned short int five_tie; + int mailalert; + int sex; + char color; + char mind[4]; #ifdef MULTI_SERVER char hostid; #endif @@ -255,28 +255,28 @@ typedef struct water_t { pid_t pid; char userid[IDLEN + 1]; int top, count; - msgque_t msg[MAX_REVIEW]; - userinfo_t *uin; // Ptt:這可以取代alive + msgque_t msg[MAX_REVIEW]; + userinfo_t *uin; // Ptt:這可以取代alive } water_t; typedef struct { - fileheader_t *header; - char mtitle[STRLEN]; - char *path; - int num, page, now, level; + fileheader_t *header; + char mtitle[STRLEN]; + char *path; + int num, page, now, level; } menu_t; typedef struct onekey_t { /* Used to pass commands to the readmenu */ - int key; - int (*fptr)(); + int key; + int (*fptr)(); } onekey_t; #define ANSILINELEN (511) /* Maximum Screen width in chars */ /* anti_crosspost */ typedef struct crosspost_t { - int checksum[4]; /* 0 -> 'X' cross post 1-3 -> 簡查文章行 */ - int times; /* 第幾次 */ + int checksum[4]; /* 0 -> 'X' cross post 1-3 -> 簡查文章行 */ + int times; /* 第幾次 */ } crosspost_t; #define SORT_BY_ID 0 @@ -288,10 +288,10 @@ typedef struct crosspost_t { #define SORT_BY_SEX 5 typedef struct keeploc_t { - char *key; - int top_ln; - int crs_ln; - struct keeploc_t *next; + char *key; + int top_ln; + int crs_ln; + struct keeploc_t *next; } keeploc_t; #define USHM_SIZE (MAX_ACTIVE + 4) /* why+4? */ @@ -379,33 +379,33 @@ typedef int board_t[BRD_ROW][BRD_COL]; /* name.c 中運用的資料結構 */ typedef struct word_t { - char *word; - struct word_t *next; + char *word; + struct word_t *next; } word_t; typedef struct commands_t { - int (*cmdfunc)(); - int level; - char *desc; /* next/key/description */ + int (*cmdfunc)(); + int level; + char *desc; /* next/key/description */ } commands_t; typedef struct MailQueue { - char filepath[FNLEN]; - char subject[STRLEN]; - time_t mailtime; - char sender[IDLEN + 1]; - char username[24]; - char rcpt[50]; - int method; - char * niamod; + char filepath[FNLEN]; + char subject[STRLEN]; + time_t mailtime; + char sender[IDLEN + 1]; + char username[24]; + char rcpt[50]; + int method; + char *niamod; } MailQueue; enum {MQ_TEXT, MQ_UUENCODE, MQ_JUSTIFY}; typedef struct { - time_t chrono; - int recno; + time_t chrono; + int recno; } TagItem; #endif diff --git a/pttbbs/mbbsd/admin.c b/pttbbs/mbbsd/admin.c index f31ee516..ffe594dc 100644 --- a/pttbbs/mbbsd/admin.c +++ b/pttbbs/mbbsd/admin.c @@ -1,17 +1,19 @@ -/* $Id: admin.c,v 1.24 2002/06/23 01:56:13 ptt Exp $ */ +/* $Id: admin.c,v 1.25 2002/07/05 17:10:26 in2 Exp $ */ #include "bbs.h" /* 使用者管理 */ -int m_user() { - userec_t muser; - int id; - char genbuf[200]; - +int +m_user() +{ + userec_t muser; + int id; + char genbuf[200]; + stand_title("使用者設定"); usercomplete(msg_uid, genbuf); - if(*genbuf) { + if (*genbuf) { move(2, 0); - if((id = getuser(genbuf))) { + if ((id = getuser(genbuf))) { memcpy(&muser, &xuser, sizeof(muser)); user_display(&muser, 1); uinfo_query(&muser, 1, id); @@ -24,49 +26,51 @@ int m_user() { return 0; } -static int search_key_user(char *passwdfile, int mode) { - userec_t user; - int ch; - int coun = 0; - FILE *fp1 = fopen(passwdfile, "r"); - char buf[128], key[22], genbuf[8]; - +static int +search_key_user(char *passwdfile, int mode) +{ + userec_t user; + int ch; + int coun = 0; + FILE *fp1 = fopen(passwdfile, "r"); + char buf[128], key[22], genbuf[8]; + clear(); getdata(0, 0, mode ? "請輸入使用者關鍵字[電話|地址|姓名|上站地點|" "email|小雞id] :" : "請輸入id :", key, sizeof(key), DOECHO); - while((fread(&user, sizeof(user), 1, fp1)) > 0 && coun < MAX_USERS) { - if(!(++coun & 15)) { + while ((fread(&user, sizeof(user), 1, fp1)) > 0 && coun < MAX_USERS) { + if (!(++coun & 15)) { move(1, 0); sprintf(buf, "第 [%d] 筆資料\n", coun); outs(buf); refresh(); } - if(!strcasecmp(user.userid, key) || - (mode && ( - strstr(user.realname, key) || strstr(user.username, key) || - strstr(user.lasthost, key) || strstr(user.email, key) || - strstr(user.address, key) || strstr(user.justify, key) || - strstr(user.mychicken.name, key)))) { + if (!strcasecmp(user.userid, key) || + (mode && ( + strstr(user.realname, key) || strstr(user.username, key) || + strstr(user.lasthost, key) || strstr(user.email, key) || + strstr(user.address, key) || strstr(user.justify, key) || + strstr(user.mychicken.name, key)))) { move(1, 0); sprintf(buf, "第 [%d] 筆資料\n", coun); outs(buf); refresh(); - + user_display(&user, 1); uinfo_query(&user, 1, coun); outs("\033[44m 空白鍵\033[37m:搜尋下一個" " \033[33m Q\033[37m: 離開"); outs(mode ? " \033[m " : " S: 取用備份資料 \033[m "); - while(1) { - while((ch = igetch()) == 0); - if(ch == ' ') - break; - if(ch == 'q' || ch == 'Q') + while (1) { + while ((ch = igetch()) == 0); + if (ch == ' ') + break; + if (ch == 'q' || ch == 'Q') return 0; - if(ch == 's' && !mode) { - if((ch = searchuser(user.userid))) { - setumoney(ch,user.money); + if (ch == 's' && !mode) { + if ((ch = searchuser(user.userid))) { + setumoney(ch, user.money); passwd_update(ch, &user); return 0; } else { @@ -75,23 +79,22 @@ static int search_key_user(char *passwdfile, int mode) { getdata(0, 0, "目前的 PASSWD 檔沒有此 ID,新增嗎?[y/N]", genbuf, 3, LCECHO); - if(genbuf[0] == 'n') { + if (genbuf[0] == 'n') { outs("目前的PASSWDS檔沒有此id " "請先new一個這個id的帳號"); } else { - int allocid = getnewuserid(); - - if(allocid > MAX_USERS || allocid <= 0) { + int allocid = getnewuserid(); + + if (allocid > MAX_USERS || allocid <= 0) { fprintf(stderr, "本站人口已達飽和!\n"); exit(1); } - - if(passwd_update(allocid, &user) == -1) { + if (passwd_update(allocid, &user) == -1) { fprintf(stderr, "客滿了,再見!\n"); exit(1); } setuserid(allocid, user.userid); - if(!searchuser(user.userid)) { + if (!searchuser(user.userid)) { fprintf(stderr, "無法建立帳號\n"); exit(1); } @@ -102,26 +105,30 @@ static int search_key_user(char *passwdfile, int mode) { } } } - + fclose(fp1); return 0; } /* 以任意 key 尋找使用者 */ -int search_user_bypwd() { +int +search_user_bypwd() +{ search_key_user(FN_PASSWD, 1); return 0; } /* 尋找備份的使用者資料 */ -int search_user_bybakpwd() { - char *choice[] = { +int +search_user_bybakpwd() +{ + char *choice[] = { "PASSWDS.NEW1", "PASSWDS.NEW2", "PASSWDS.NEW3", "PASSWDS.NEW4", "PASSWDS.NEW5", "PASSWDS.NEW6", "PASSWDS.BAK" }; - int ch; - + int ch; + clear(); move(1, 1); outs("請輸入你要用來尋找備份的檔案 或按 'q' 離開\n"); @@ -134,7 +141,7 @@ int search_user_bybakpwd() { move(5, 1); outs("選擇 => "); ch = igetch(); - if(ch == 'q' || ch == 'Q') + if (ch == 'q' || ch == 'Q') return 0; } while (ch < '1' || ch > '8'); ch -= '1'; @@ -142,17 +149,21 @@ int search_user_bybakpwd() { return 0; } -static void bperm_msg(boardheader_t *board) { +static void +bperm_msg(boardheader_t * board) +{ prints("\n設定 [%s] 看板之(%s)權限:", board->brdname, board->brdattr & BRD_POSTMASK ? "發表" : "閱\讀"); } -unsigned int setperms(unsigned int pbits, char *pstring[]) { - register int i; - char choice[4]; - +unsigned int +setperms(unsigned int pbits, char *pstring[]) +{ + register int i; + char choice[4]; + move(4, 0); - for(i = 0; i < NUMPERMS / 2; i++) { + for (i = 0; i < NUMPERMS / 2; i++) { prints("%c. %-20s %-15s %c. %-20s %s\n", 'A' + i, pstring[i], ((pbits >> i) & 1 ? "ˇ" : "X"), @@ -161,12 +172,12 @@ unsigned int setperms(unsigned int pbits, char *pstring[]) { ((pbits >> (i + 16)) & 1 ? "ˇ" : "X")); } clrtobot(); - while(getdata(b_lines - 1, 0, "請按 [A-5] 切換設定,按 [Return] 結束:", - choice, sizeof(choice), LCECHO)) { + while (getdata(b_lines - 1, 0, "請按 [A-5] 切換設定,按 [Return] 結束:", + choice, sizeof(choice), LCECHO)) { i = choice[0] - 'a'; - if(i < 0) + if (i < 0) i = choice[0] - '0' + 26; - if(i >= NUMPERMS) + if (i >= NUMPERMS) bell(); else { pbits ^= (1 << i); @@ -178,57 +189,60 @@ unsigned int setperms(unsigned int pbits, char *pstring[]) { } /* 自動設立精華區 */ -void setup_man(boardheader_t * board) { - char genbuf[200]; - +void +setup_man(boardheader_t * board) +{ + char genbuf[200]; + setapath(genbuf, board->brdname); mkdir(genbuf, 0755); } -int m_mod_board(char *bname) { - boardheader_t bh, newbh; - int bid; - char genbuf[256], ans[4]; - +int +m_mod_board(char *bname) +{ + boardheader_t bh, newbh; + int bid; + char genbuf[256], ans[4]; + bid = getbnum(bname); - if(!bid || !bname[0] || get_record(fn_board, &bh, sizeof(bh), bid) == -1) { + if (!bid || !bname[0] || get_record(fn_board, &bh, sizeof(bh), bid) == -1) { outs(err_bid); pressanykey(); return -1; } - prints("看板名稱:%s\n看板說明:%s\n看板bid:%d\n看板GID:%d\n" "板主名單:%s", bh.brdname, bh.title, bid, bh.gid, bh.BM); bperm_msg(&bh); - + /* Ptt 這邊斷行會檔到下面 */ move(9, 0); sprintf(genbuf, "(E)設定 (V)違法/解除 %s (D)刪除 [Q]取消?", HAS_PERM(PERM_SYSOP) ? " (B)BVote (S)救回文章 (G)賭盤解卡" : ""); getdata(10, 0, genbuf, ans, sizeof(ans), LCECHO); - - switch(*ans) { + + switch (*ans) { case 'g': - if(HAS_PERM(PERM_SYSOP) ) { - char path[256]; - setbfile(genbuf,bname,FN_TICKET_LOCK); - setbfile(path,bname,FN_TICKET_END); - rename(genbuf,path); - } - break; + if (HAS_PERM(PERM_SYSOP)) { + char path[256]; + setbfile(genbuf, bname, FN_TICKET_LOCK); + setbfile(path, bname, FN_TICKET_END); + rename(genbuf, path); + } + break; case 's': - if(HAS_PERM(PERM_SYSOP) ) { + if (HAS_PERM(PERM_SYSOP)) { sprintf(genbuf, BBSHOME "/bin/buildir boards/%c/%s &", bh.brdname[0], bh.brdname); system(genbuf); } break; case 'b': - if(HAS_PERM(PERM_SYSOP)) { - char bvotebuf[10]; - + if (HAS_PERM(PERM_SYSOP)) { + char bvotebuf[10]; + memcpy(&newbh, &bh, sizeof(bh)); sprintf(bvotebuf, "%d", newbh.bvote); move(20, 0); @@ -246,8 +260,8 @@ int m_mod_board(char *bname) { outs("看板目前為"); outs((bh.brdattr & BRD_BAD) ? "違法" : "正常"); getdata(21, 0, "確定更改?", genbuf, 5, LCECHO); - if(genbuf[0] == 'y') { - if(newbh.brdattr & BRD_BAD) + if (genbuf[0] == 'y') { + if (newbh.brdattr & BRD_BAD) newbh.brdattr = newbh.brdattr & (!BRD_BAD); else newbh.brdattr = newbh.brdattr | BRD_BAD; @@ -257,87 +271,85 @@ int m_mod_board(char *bname) { } break; case 'd': - getdata_str(9, 0, msg_sure_ny, genbuf, 3, LCECHO, "N"); - if(genbuf[0] != 'y' || !bname[0]) - outs(MSG_DEL_CANCEL); - else { - strcpy(bname, bh.brdname); - sprintf(genbuf, - "/bin/tar zcvf tmp/board_%s.tgz boards/%c/%s man/boards/%c/%s >/dev/null 2>&1;" - "/bin/rm -fr boards/%c/%s man/boards/%c/%s", - bname, bname[0], bname, bname[0], - bname, bname[0], bname, bname[0], bname); - system(genbuf); - memset(&bh, 0, sizeof(bh)); - sprintf(bh.title, "%s 看板 %s 刪除", bname, cuser.userid); - post_msg("Security", bh.title,"請注意刪除的合法性","[系統安全局]"); - substitute_record(fn_board, &bh, sizeof(bh), bid); - reset_board(bid); - log_usies("DelBoard", bh.title); - outs("刪板完畢"); - } + getdata_str(9, 0, msg_sure_ny, genbuf, 3, LCECHO, "N"); + if (genbuf[0] != 'y' || !bname[0]) + outs(MSG_DEL_CANCEL); + else { + strcpy(bname, bh.brdname); + sprintf(genbuf, + "/bin/tar zcvf tmp/board_%s.tgz boards/%c/%s man/boards/%c/%s >/dev/null 2>&1;" + "/bin/rm -fr boards/%c/%s man/boards/%c/%s", + bname, bname[0], bname, bname[0], + bname, bname[0], bname, bname[0], bname); + system(genbuf); + memset(&bh, 0, sizeof(bh)); + sprintf(bh.title, "%s 看板 %s 刪除", bname, cuser.userid); + post_msg("Security", bh.title, "請注意刪除的合法性", "[系統安全局]"); + substitute_record(fn_board, &bh, sizeof(bh), bid); + reset_board(bid); + log_usies("DelBoard", bh.title); + outs("刪板完畢"); + } break; case 'e': move(8, 0); outs("直接按 [Return] 不修改該項設定"); memcpy(&newbh, &bh, sizeof(bh)); - while(getdata(9, 0, "新看板名稱:", genbuf, IDLEN + 1, DOECHO)) { - if(getbnum(genbuf)) { + while (getdata(9, 0, "新看板名稱:", genbuf, IDLEN + 1, DOECHO)) { + if (getbnum(genbuf)) { move(3, 0); outs("錯誤! 板名雷同"); - } else if(!invalid_brdname(genbuf)) { + } else if (!invalid_brdname(genbuf)) { strcpy(newbh.brdname, genbuf); break; } } - + do { getdata_str(12, 0, "看板類別:", genbuf, 5, DOECHO, bh.title); - if(strlen(genbuf) == 4) + if (strlen(genbuf) == 4) break; } while (1); - if(strlen(genbuf) >= 4) + if (strlen(genbuf) >= 4) strncpy(newbh.title, genbuf, 4); - + newbh.title[4] = ' '; - getdata_str(14, 0, "看板主題:", genbuf, BTLEN + 1, DOECHO, + getdata_str(14, 0, "看板主題:", genbuf, BTLEN + 1, DOECHO, bh.title + 7); - if(genbuf[0]) + if (genbuf[0]) strcpy(newbh.title + 7, genbuf); - if(getdata_str(15, 0, "新板主名單:", genbuf, IDLEN * 3 + 3, DOECHO, - bh.BM)) { + if (getdata_str(15, 0, "新板主名單:", genbuf, IDLEN * 3 + 3, DOECHO, + bh.BM)) { trim(genbuf); strcpy(newbh.BM, genbuf); } - - if(HAS_PERM(PERM_SYSOP)) { + if (HAS_PERM(PERM_SYSOP)) { move(1, 0); clrtobot(); newbh.brdattr = setperms(newbh.brdattr, str_permboard); move(1, 0); clrtobot(); } - - if(newbh.brdattr & BRD_GROUPBOARD) + if (newbh.brdattr & BRD_GROUPBOARD) strncpy(newbh.title + 5, "Σ", 2); - else if(newbh.brdattr & BRD_NOTRAN) + else if (newbh.brdattr & BRD_NOTRAN) strncpy(newbh.title + 5, "◎", 2); else strncpy(newbh.title + 5, "●", 2); - - if(HAS_PERM(PERM_SYSOP) && !(newbh.brdattr & BRD_HIDE)) { + + if (HAS_PERM(PERM_SYSOP) && !(newbh.brdattr & BRD_HIDE)) { getdata_str(14, 0, "設定讀寫權限(Y/N)?", ans, sizeof(ans), LCECHO, "N"); - if(*ans == 'y') { + if (*ans == 'y') { getdata_str(15, 0, "限制 [R]閱\讀 (P)發表?", ans, sizeof(ans), LCECHO, "R"); - if(*ans == 'p') + if (*ans == 'p') newbh.brdattr |= BRD_POSTMASK; else newbh.brdattr &= ~BRD_POSTMASK; - + move(1, 0); clrtobot(); bperm_msg(&newbh); @@ -345,17 +357,16 @@ int m_mod_board(char *bname) { clear(); } } - getdata_str(b_lines - 1, 0, msg_sure_ny, genbuf, 4, LCECHO, "Y"); - if((*genbuf == 'y') && memcmp(&newbh, &bh, sizeof(bh))) { - if(strcmp(bh.brdname, newbh.brdname)) { - char src[60], tar[60]; - + if ((*genbuf == 'y') && memcmp(&newbh, &bh, sizeof(bh))) { + if (strcmp(bh.brdname, newbh.brdname)) { + char src[60], tar[60]; + setbpath(src, bh.brdname); setbpath(tar, newbh.brdname); Rename(src, tar); - + setapath(src, bh.brdname); setapath(tar, newbh.brdname); Rename(src, tar); @@ -370,37 +381,41 @@ int m_mod_board(char *bname) { } /* 設定看板 */ -int m_board() { - char bname[32]; - +int +m_board() +{ + char bname[32]; + stand_title("看板設定"); generalnamecomplete(msg_bid, bname, sizeof(bname), SHM->Bnumber, completeboard_compar, completeboard_permission, completeboard_getname); - if(!*bname) + if (!*bname) return 0; m_mod_board(bname); return 0; } /* 設定系統檔案 */ -int x_file() { - int aborted; - char ans[4], *fpath; - +int +x_file() +{ + int aborted; + char ans[4], *fpath; + move(b_lines - 4, 0); /* Ptt */ outs("設定 (1)身份確認信 (4)post注意事項 (5)錯誤登入訊息 (6)註冊範例 (7)通過確認通知\n"); outs(" (8)email post通知 (9)系統功\能精靈 (A)茶樓 (B)站長名單 (C)email通過確認\n"); outs(" (D)新使用者需知 (E)身份確認方法 (F)歡迎畫面 (G)進站畫面 " #ifdef MULTI_WELCOME_LOGIN -"(X)刪除進站畫面" + "(X)刪除進站畫面" #endif -"\n"); + "\n"); getdata(b_lines - 1, 0, " (H)看板期限 (I)故鄉 (J)出站畫面 (K)生日卡 (L)節日 [Q]取消?", ans, sizeof(ans), LCECHO); - - switch(ans[0]) { + + switch (ans[0]) { case '1': fpath = "etc/confirm"; break; @@ -443,11 +458,17 @@ int x_file() { case 'g': #ifdef MULTI_WELCOME_LOGIN getdata(b_lines - 1, 0, "第幾個進站畫面[0-4]", ans, sizeof(ans), LCECHO); - if( ans[0] == '1' ) { fpath = "etc/Welcome_login.1"; } - else if( ans[0] == '2' ){ fpath = "etc/Welcome_login.2"; } - else if( ans[0] == '3' ){ fpath = "etc/Welcome_login.3"; } - else if( ans[0] == '4' ){ fpath = "etc/Welcome_login.4"; } - else { fpath = "etc/Welcome_login.0"; } + if (ans[0] == '1') { + fpath = "etc/Welcome_login.1"; + } else if (ans[0] == '2') { + fpath = "etc/Welcome_login.2"; + } else if (ans[0] == '3') { + fpath = "etc/Welcome_login.3"; + } else if (ans[0] == '4') { + fpath = "etc/Welcome_login.4"; + } else { + fpath = "etc/Welcome_login.0"; + } #else fpath = "etc/Welcome_login"; #endif @@ -456,11 +477,21 @@ int x_file() { #ifdef MULTI_WELCOME_LOGIN case 'x': getdata(b_lines - 1, 0, "第幾個進站畫面[1-4]", ans, sizeof(ans), LCECHO); - if( ans[0] == '1' ) { unlink("etc/Welcome_login.1"); outs("ok"); } - else if( ans[0] == '2' ){ unlink("etc/Welcome_login.2"); outs("ok"); } - else if( ans[0] == '3' ){ unlink("etc/Welcome_login.3"); outs("ok"); } - else if( ans[0] == '4' ){ unlink("etc/Welcome_login.4"); outs("ok"); } - else {outs("所指定的進站畫面無法刪除"); } + if (ans[0] == '1') { + unlink("etc/Welcome_login.1"); + outs("ok"); + } else if (ans[0] == '2') { + unlink("etc/Welcome_login.2"); + outs("ok"); + } else if (ans[0] == '3') { + unlink("etc/Welcome_login.3"); + outs("ok"); + } else if (ans[0] == '4') { + unlink("etc/Welcome_login.4"); + outs("ok"); + } else { + outs("所指定的進站畫面無法刪除"); + } pressanykey(); return FULLUPDATE; @@ -491,15 +522,17 @@ int x_file() { return FULLUPDATE; } -int m_newbrd(int recover) { - boardheader_t newboard; - char ans[4]; - int bid; - char genbuf[200]; +int +m_newbrd(int recover) +{ + boardheader_t newboard; + char ans[4]; + int bid; + char genbuf[200]; stand_title("建立新板"); memset(&newboard, 0, sizeof(newboard)); - + newboard.gid = class_bid; if (newboard.gid == 0) { move(6, 0); @@ -507,46 +540,44 @@ int m_newbrd(int recover) { pressanykey(); return -1; } - do { - if(!getdata(3, 0, msg_bid, newboard.brdname, - sizeof(newboard.brdname), DOECHO)) + if (!getdata(3, 0, msg_bid, newboard.brdname, + sizeof(newboard.brdname), DOECHO)) return -1; - } while(invalid_brdname(newboard.brdname)); + } while (invalid_brdname(newboard.brdname)); do { getdata(6, 0, "看板類別:", genbuf, 5, DOECHO); - if(strlen(genbuf) == 4) + if (strlen(genbuf) == 4) break; } while (1); - - if(strlen(genbuf) >= 4) + + if (strlen(genbuf) >= 4) strncpy(newboard.title, genbuf, 4); - + newboard.title[4] = ' '; - + getdata(8, 0, "看板主題:", genbuf, BTLEN + 1, DOECHO); - if(genbuf[0]) + if (genbuf[0]) strcpy(newboard.title + 7, genbuf); setbpath(genbuf, newboard.brdname); - - if(recover) { - struct stat sb; - - if(stat(genbuf, &sb) == -1 || !(sb.st_mode & S_IFDIR)) { + + if (recover) { + struct stat sb; + + if (stat(genbuf, &sb) == -1 || !(sb.st_mode & S_IFDIR)) { outs("此看板已經存在! 請取不同英文板名"); pressanykey(); return -1; } - } else if(getbnum(newboard.brdname) > 0 || mkdir(genbuf, 0755) == -1) { + } else if (getbnum(newboard.brdname) > 0 || mkdir(genbuf, 0755) == -1) { outs("此看板已經存在! 請取不同英文板名"); pressanykey(); return -1; } - newboard.brdattr = BRD_NOTRAN; - - if(HAS_PERM(PERM_SYSOP)) { + + if (HAS_PERM(PERM_SYSOP)) { move(1, 0); clrtobot(); newboard.brdattr = setperms(newboard.brdattr, str_permboard); @@ -554,28 +585,28 @@ int m_newbrd(int recover) { clrtobot(); } getdata(9, 0, "是看板? (N:目錄) (Y/n):", genbuf, 3, LCECHO); - if(genbuf[0]=='n') + if (genbuf[0] == 'n') newboard.brdattr |= BRD_GROUPBOARD; - if(newboard.brdattr & BRD_GROUPBOARD) + if (newboard.brdattr & BRD_GROUPBOARD) strncpy(newboard.title + 5, "Σ", 2); - else if(newboard.brdattr & BRD_NOTRAN) + else if (newboard.brdattr & BRD_NOTRAN) strncpy(newboard.title + 5, "◎", 2); else strncpy(newboard.title + 5, "●", 2); - + newboard.level = 0; getdata(11, 0, "板主名單:", newboard.BM, sizeof(newboard.BM), DOECHO); - if(HAS_PERM(PERM_SYSOP) && !(newboard.brdattr & BRD_HIDE)) { + if (HAS_PERM(PERM_SYSOP) && !(newboard.brdattr & BRD_HIDE)) { getdata_str(14, 0, "設定讀寫權限(Y/N)?", ans, sizeof(ans), LCECHO, "N"); - if(*ans == 'y') { + if (*ans == 'y') { getdata_str(15, 0, "限制 [R]閱\讀 (P)發表?", ans, sizeof(ans), LCECHO, "R"); - if(*ans == 'p') + if (*ans == 'p') newboard.brdattr |= BRD_POSTMASK; else newboard.brdattr &= (~BRD_POSTMASK); - + move(1, 0); clrtobot(); bperm_msg(&newboard); @@ -583,20 +614,15 @@ int m_newbrd(int recover) { clear(); } } - - if((bid = getbnum("")) > 0) - { + if ((bid = getbnum("")) > 0) { substitute_record(fn_board, &newboard, sizeof(newboard), bid); - reset_board(bid); - } - else if(append_record(fn_board, (fileheader_t *) & newboard, - sizeof(newboard)) == -1) { + reset_board(bid); + } else if (append_record(fn_board, (fileheader_t *) & newboard, + sizeof(newboard)) == -1) { pressanykey(); return -1; - } - else - { - addbrd_touchcache(); + } else { + addbrd_touchcache(); } setup_man(&newboard); @@ -607,54 +633,51 @@ int m_newbrd(int recover) { return 0; } -static int auto_scan(char fdata[][STRLEN], char ans[]) { - int good = 0; - int count = 0; - int i; - char temp[10]; - - if(!strncmp(fdata[2], "小", 2) || strstr(fdata[2], "丫") +static int +auto_scan(char fdata[][STRLEN], char ans[]) +{ + int good = 0; + int count = 0; + int i; + char temp[10]; + + if (!strncmp(fdata[2], "小", 2) || strstr(fdata[2], "丫") || strstr(fdata[2], "誰") || strstr(fdata[2], "不")) { ans[0] = '0'; return 1; } - strncpy(temp, fdata[2], 2); temp[2] = '\0'; - + /* 疊字 */ - if(!strncmp(temp, &(fdata[2][2]), 2)) { + if (!strncmp(temp, &(fdata[2][2]), 2)) { ans[0] = '0'; return 1; } - - if(strlen(fdata[2]) >= 6) { - if(strstr(fdata[2], "陳水扁")) { + if (strlen(fdata[2]) >= 6) { + if (strstr(fdata[2], "陳水扁")) { ans[0] = '0'; return 1; } - - if(strstr("趙錢孫李周吳鄭王", temp)) + if (strstr("趙錢孫李周吳鄭王", temp)) good++; - else if(strstr("杜顏黃林陳官余辛劉", temp)) + else if (strstr("杜顏黃林陳官余辛劉", temp)) good++; - else if(strstr("蘇方吳呂李邵張廖應蘇", temp)) + else if (strstr("蘇方吳呂李邵張廖應蘇", temp)) good++; - else if(strstr("徐謝石盧施戴翁唐", temp)) + else if (strstr("徐謝石盧施戴翁唐", temp)) good++; } - - if(!good) + if (!good) return 0; - if(!strcmp(fdata[3], fdata[4]) || - !strcmp(fdata[3], fdata[5]) || - !strcmp(fdata[4], fdata[5])) { + if (!strcmp(fdata[3], fdata[4]) || + !strcmp(fdata[3], fdata[5]) || + !strcmp(fdata[4], fdata[5])) { ans[0] = '4'; return 5; } - - if(strstr(fdata[3], "大")) { + if (strstr(fdata[3], "大")) { if (strstr(fdata[3], "台") || strstr(fdata[3], "淡") || strstr(fdata[3], "交") || strstr(fdata[3], "政") || strstr(fdata[3], "清") || strstr(fdata[3], "警") || @@ -662,34 +685,32 @@ static int auto_scan(char fdata[][STRLEN], char ans[]) { strstr(fdata[3], "中央") || strstr(fdata[3], "成") || strstr(fdata[3], "輔") || strstr(fdata[3], "東吳")) good++; - } else if(strstr(fdata[3], "女中")) + } else if (strstr(fdata[3], "女中")) good++; - - if(strstr(fdata[4], "地球") || strstr(fdata[4], "宇宙") || - strstr(fdata[4], "信箱")) { + + if (strstr(fdata[4], "地球") || strstr(fdata[4], "宇宙") || + strstr(fdata[4], "信箱")) { ans[0] = '2'; return 3; } - - if(strstr(fdata[4], "市") || strstr(fdata[4], "縣")) { - if(strstr(fdata[4], "路") || strstr(fdata[4], "街")) { - if(strstr(fdata[4], "號")) + if (strstr(fdata[4], "市") || strstr(fdata[4], "縣")) { + if (strstr(fdata[4], "路") || strstr(fdata[4], "街")) { + if (strstr(fdata[4], "號")) good++; } } - - for(i = 0; fdata[5][i]; i++) { - if(isdigit(fdata[5][i])) + for (i = 0; fdata[5][i]; i++) { + if (isdigit(fdata[5][i])) count++; } - - if(count <= 4) { + + if (count <= 4) { ans[0] = '3'; return 4; - } else if(count >= 7) + } else if (count >= 7) good++; - if(good >= 3) { + if (good >= 3) { ans[0] = 'y'; return -1; } else @@ -697,17 +718,19 @@ static int auto_scan(char fdata[][STRLEN], char ans[]) { } /* 處理 Register Form */ -int scan_register_form(char *regfile, int automode, int neednum) { - char genbuf[200]; - static char *logfile = "register.log"; - static char *field[] = { +int +scan_register_form(char *regfile, int automode, int neednum) +{ + char genbuf[200]; + static char *logfile = "register.log"; + static char *field[] = { "uid", "ident", "name", "career", "addr", "phone", "email", NULL }; - static char *finfo[] = { + static char *finfo[] = { "帳號", "身分證號", "真實姓名", "服務單位", "目前住址", "連絡電話", "電子郵件信箱", NULL }; - static char *reason[] = { + static char *reason[] = { "輸入真實姓名", "詳細填寫您的「學校以及『科系』『年級』」或「服務單位(詳細至職稱)」", "填寫完整的住址資料 (含縣市名稱, 台北市請含行政區域)", @@ -716,32 +739,32 @@ int scan_register_form(char *regfile, int automode, int neednum) { "用中文填寫申請單", NULL }; - static char *autoid = "AutoScan"; - userec_t muser; - FILE *fn, *fout, *freg; - char fdata[7][STRLEN]; - char fname[STRLEN], buf[STRLEN]; - char ans[4], *ptr, *uid; - int n = 0, unum = 0; - int nSelf = 0, nAuto = 0; - + static char *autoid = "AutoScan"; + userec_t muser; + FILE *fn, *fout, *freg; + char fdata[7][STRLEN]; + char fname[STRLEN], buf[STRLEN]; + char ans[4], *ptr, *uid; + int n = 0, unum = 0; + int nSelf = 0, nAuto = 0; + uid = cuser.userid; sprintf(fname, "%s.tmp", regfile); move(2, 0); - if(dashf(fname)) { - if(neednum == 0) { /* 自己進 Admin 來審的 */ + if (dashf(fname)) { + if (neednum == 0) { /* 自己進 Admin 來審的 */ outs("其他 SYSOP 也在審核註冊申請單"); pressanykey(); } return -1; } Rename(regfile, fname); - if((fn = fopen(fname, "r")) == NULL) { + if ((fn = fopen(fname, "r")) == NULL) { prints("系統錯誤,無法讀取註冊資料檔: %s", fname); pressanykey(); return -1; } - if(neednum) { /* 被強迫審的 */ + if (neednum) { /* 被強迫審的 */ move(1, 0); clrtobot(); prints("各位具有站長權限的人,註冊單累積超過一百份了,麻煩您幫忙審 %d 份\n", neednum); @@ -749,13 +772,13 @@ int scan_register_form(char *regfile, int automode, int neednum) { pressanykey(); } memset(fdata, 0, sizeof(fdata)); - while(fgets(genbuf, STRLEN, fn)) { - if ((ptr = (char *) strstr(genbuf, ": "))) { + while (fgets(genbuf, STRLEN, fn)) { + if ((ptr = (char *)strstr(genbuf, ": "))) { *ptr = '\0'; - for(n = 0; field[n]; n++) { - if(strcmp(genbuf, field[n]) == 0) { + for (n = 0; field[n]; n++) { + if (strcmp(genbuf, field[n]) == 0) { strcpy(fdata[n], ptr + 2); - if((ptr = (char *) strchr(fdata[n], '\n'))) + if ((ptr = (char *)strchr(fdata[n], '\n'))) *ptr = '\0'; } } @@ -770,61 +793,60 @@ int scan_register_form(char *regfile, int automode, int neednum) { } else { neednum--; memcpy(&muser, &xuser, sizeof(muser)); - if(automode) + if (automode) uid = autoid; - - if( (!automode || !auto_scan(fdata, ans)) ) { + + if ((!automode || !auto_scan(fdata, ans))) { uid = cuser.userid; - + move(1, 0); prints("帳號位置 :%d\n", unum); user_display(&muser, 1); move(14, 0); prints("\033[1;32m------------- 請站長嚴格審核使用者資料,您還有 %d 份---------------\033[m\n", neednum); - for(n = 0; field[n]; n++) { - if(n >= 2 && n <= 5) + for (n = 0; field[n]; n++) { + if (n >= 2 && n <= 5) prints("%d.", n - 2); else prints(" "); prints("%-12s:%s\n", finfo[n], fdata[n]); } - if(muser.userlevel & PERM_LOGINOK) { + if (muser.userlevel & PERM_LOGINOK) { getdata(b_lines - 1, 0, "\033[1;32m此帳號已經完成註冊, " - "更新(Y/N/Skip)?\033[m[N] ", ans, sizeof(ans), LCECHO); - if(ans[0] != 'y' && ans[0] != 's') + "更新(Y/N/Skip)?\033[m[N] ", ans, sizeof(ans), LCECHO); + if (ans[0] != 'y' && ans[0] != 's') ans[0] = 'd'; } else { move(b_lines - 1, 0); prints("是否接受此資料(Y/N/Q/Del/Skip)?[S] "); - if( search_ulist(unum) == NULL ) + if (search_ulist(unum) == NULL) ans[0] = igetch(); else ans[0] = 's'; - if( 'A' <= ans[0] && ans[0] <= 'Z' ) + if ('A' <= ans[0] && ans[0] <= 'Z') ans[0] += 32; - if( ans[0] != 'y' && ans[0] != 'n' && ans[0] != 'q' && - ans[0] != 'd' && !('0' <= ans[0] && ans[0] <= '4') ) + if (ans[0] != 'y' && ans[0] != 'n' && ans[0] != 'q' && + ans[0] != 'd' && !('0' <= ans[0] && ans[0] <= '4')) ans[0] = 's'; ans[1] = 0; } nSelf++; } else nAuto++; - if(neednum > 0 && ans[0] == 'q') { + if (neednum > 0 && ans[0] == 'q') { move(2, 0); clrtobot(); prints("沒審完不能退出"); pressanykey(); ans[0] = 's'; } - - switch(ans[0]) { + switch (ans[0]) { case 'q': - if((freg = fopen(regfile, "a"))) { - for(n = 0; field[n]; n++) + if ((freg = fopen(regfile, "a"))) { + for (n = 0; field[n]; n++) fprintf(freg, "%s: %s\n", field[n], fdata[n]); fprintf(freg, "----\n"); - while(fgets(genbuf, STRLEN, fn)) + while (fgets(genbuf, STRLEN, fn)) fputs(genbuf, freg); fclose(freg); } @@ -836,8 +858,8 @@ int scan_register_form(char *regfile, int automode, int neednum) { case '3': case '4': case 'n': - if(ans[0] == 'n') { - for(n = 0; field[n]; n++) + if (ans[0] == 'n') { + for (n = 0; field[n]; n++) prints("%s: %s\n", finfo[n], fdata[n]); move(9, 0); prints("請提出退回申請表原因,按 <enter> 取消\n"); @@ -845,33 +867,33 @@ int scan_register_form(char *regfile, int automode, int neednum) { prints("%d) 請%s\n", n, reason[n]); } else buf[0] = ans[0]; - if(ans[0] != 'n' || + if (ans[0] != 'n' || getdata(10 + n, 0, "退回原因:", buf, 60, DOECHO)) - if((buf[0] - '0') >= 0 && (buf[0] - '0') < n) { - int i; - fileheader_t mhdr; - char title[128], buf1[80]; - FILE *fp; - + if ((buf[0] - '0') >= 0 && (buf[0] - '0') < n) { + int i; + fileheader_t mhdr; + char title[128], buf1[80]; + FILE *fp; + i = buf[0] - '0'; strcpy(buf, reason[i]); sprintf(genbuf, "[退回原因] 請%s", buf); - + sethomepath(buf1, muser.userid); stampfile(buf1, &mhdr); strcpy(mhdr.owner, cuser.userid); strncpy(mhdr.title, "[註冊失敗]", TTLEN); mhdr.filemode = 0; sethomedir(title, muser.userid); - if(append_record(title, &mhdr, sizeof(mhdr)) != -1) { + if (append_record(title, &mhdr, sizeof(mhdr)) != -1) { fp = fopen(buf1, "w"); fprintf(fp, "%s\n", genbuf); fclose(fp); } - if((fout = fopen(logfile, "a"))) { - for(n = 0; field[n]; n++) + if ((fout = fopen(logfile, "a"))) { + for (n = 0; field[n]; n++) fprintf(fout, "%s: %s\n", field[n], fdata[n]); - fprintf(fout, "Date: %s\n", Cdate(& now)); + fprintf(fout, "Date: %s\n", Cdate(&now)); fprintf(fout, "Rejected: %s [%s]\n----\n", uid, buf); fclose(fout); @@ -882,8 +904,8 @@ int scan_register_form(char *regfile, int automode, int neednum) { clrtobot(); prints("取消退回此註冊申請表"); case 's': - if((freg = fopen(regfile, "a"))) { - for(n = 0; field[n]; n++) + if ((freg = fopen(regfile, "a"))) { + for (n = 0; field[n]; n++) fprintf(freg, "%s: %s\n", field[n], fdata[n]); fprintf(freg, "----\n"); fclose(freg); @@ -901,16 +923,15 @@ int scan_register_form(char *regfile, int automode, int neednum) { sethomefile(buf, muser.userid, "justify"); log_file(buf, genbuf); passwd_update(unum, &muser); - - if((fout = fopen(logfile, "a"))) { - for(n = 0; field[n]; n++) + + if ((fout = fopen(logfile, "a"))) { + for (n = 0; field[n]; n++) fprintf(fout, "%s: %s\n", field[n], fdata[n]); fprintf(fout, "Date: %s\n", Cdate(&now)); fprintf(fout, "Approved: %s\n", uid); fprintf(fout, "----\n"); fclose(fout); } - sethomefile(genbuf, muser.userid, "justify.wait"); unlink(genbuf); break; @@ -926,56 +947,49 @@ int scan_register_form(char *regfile, int automode, int neednum) { move(5, 0); prints("您審了 %d 份註冊單,AutoScan 審了 %d 份", nSelf, nAuto); -/** DickG: 將審了幾份的相關資料 post 到 Security 板上 ***********/ -/* DickG: 因應新的站長上站需審核方案,是故沒有必要留下 record 而關掉 - strftime(buf, 200, "%Y/%m/%d/%H:%M", pt); - - strcpy(xboard, "Security"); - setbpath(xfpath, xboard); - stampfile(xfpath, &xfile); - strcpy(xfile.owner, "系統"); - strcpy(xfile.title, "[報告] 審核記錄"); - xptr = fopen(xfpath, "w"); - fprintf(xptr, "\n時間:%s - %s 審了 %d 份註冊單\n - AutoScan 審了 %d 份註冊單\n - 共計 %d 份。", - buf, cuser.userid, nSelf, nAuto, nSelf+nAuto); - fclose(xptr); - setbdir(fname, xboard); - append_record(fname, &xfile, sizeof(xfile)); - outgo_post(&xfile, xboard); - touchbtotal(getbnum(xboard)); - cuser.numposts++; -*/ -/*********************************************/ + /** DickG: 將審了幾份的相關資料 post 到 Security 板上 ***********/ + /* + * DickG: 因應新的站長上站需審核方案,是故沒有必要留下 record + * ime(buf, 200, "%Y/%m/%d/%H:%M", pt); + * + * strcpy(xboard, "Security"); setbpath(xfpath, xboard); stampfile(xfpath, + * &xfile); strcpy(xfile.owner, "系統"); strcpy(xfile.title, "[報告] + * 審核記錄"); xptr = fopen(xfpath, "w"); fprintf(xptr, "\n時間:%s %s + * 審了 %d 份註冊單\n AutoScan 審了 %d 份註冊單\n 共計 %d 份。", buf, + * cuser.userid, nSelf, nAuto, nSelf+nAuto); fclose(xptr); setbdir(fname, + * xboard); append_record(fname, &xfile, sizeof(xfile)); + * outgo_post(&xfile, xboard); touchbtotal(getbnum(xboard)); + * cuser.numposts++; + */ + /*********************************************/ pressanykey(); return (0); } -int m_register() { - FILE *fn; - int x, y, wid, len; - char ans[4]; - char genbuf[200]; - - if((fn = fopen(fn_register, "r")) == NULL) { +int +m_register() +{ + FILE *fn; + int x, y, wid, len; + char ans[4]; + char genbuf[200]; + + if ((fn = fopen(fn_register, "r")) == NULL) { outs("目前並無新註冊資料"); return XEASY; } - stand_title("審核使用者註冊資料"); y = 2; x = wid = 0; - - while(fgets(genbuf, STRLEN, fn) && x < 65) { - if(strncmp(genbuf, "uid: ", 5) == 0) { + + while (fgets(genbuf, STRLEN, fn) && x < 65) { + if (strncmp(genbuf, "uid: ", 5) == 0) { move(y++, x); outs(genbuf + 5); len = strlen(genbuf + 5); - if(len > wid) + if (len > wid) wid = len; - if(y >= t_lines - 3) { + if (y >= t_lines - 3) { y = 2; x += wid + 2; } @@ -983,17 +997,19 @@ int m_register() { } fclose(fn); getdata(b_lines - 1, 0, "開始審核嗎(Auto/Yes/No)?[N] ", ans, sizeof(ans), LCECHO); - if(ans[0] == 'a') + if (ans[0] == 'a') scan_register_form(fn_register, 1, 0); - else if(ans[0] == 'y') + else if (ans[0] == 'y') scan_register_form(fn_register, 0, 0); - + return 0; } -int cat_register() { - if(system("cat register.new.tmp >> register.new") == 0 && - system("rm -f register.new.tmp") == 0) +int +cat_register() +{ + if (system("cat register.new.tmp >> register.new") == 0 && + system("rm -f register.new.tmp") == 0) mprints(22, 0, "OK 嚕~~ 繼續去奮鬥吧!! "); else mprints(22, 0, "沒辦法CAT過去呢 去檢查一下系統吧!! "); @@ -1001,93 +1017,97 @@ int cat_register() { return 0; } -static void give_id_money(char *user_id, int money, FILE *log_fp, char *mail_title, time_t t) { - char tt[TTLEN + 1] = {0}; - - if(deumoney(searchuser(user_id), money) < 0) { - move(12, 0); - clrtoeol(); - prints("id:%s money:%d 不對吧!!", user_id, money); - pressanykey(); +static void +give_id_money(char *user_id, int money, FILE * log_fp, char *mail_title, time_t t) +{ + char tt[TTLEN + 1] = {0}; + + if (deumoney(searchuser(user_id), money) < 0) { + move(12, 0); + clrtoeol(); + prints("id:%s money:%d 不對吧!!", user_id, money); + pressanykey(); } else { - fprintf(log_fp, "%ld %s %d", t, user_id, money); - sprintf(tt, "%s : %d ptt 幣", mail_title, money); - mail_id(user_id, tt, "~bbs/etc/givemoney.why", "[PTT 銀行]"); + fprintf(log_fp, "%ld %s %d", t, user_id, money); + sprintf(tt, "%s : %d ptt 幣", mail_title, money); + mail_id(user_id, tt, "~bbs/etc/givemoney.why", "[PTT 銀行]"); } -} - -int give_money() { - FILE *fp, *fp2; - char *ptr, *id, *mn; - char buf[200] = {0}, tt[TTLEN + 1] = {0}; - struct tm *pt = localtime(&now); - int to_all = 0, money = 0; - +} + +int +give_money() +{ + FILE *fp, *fp2; + char *ptr, *id, *mn; + char buf[200] = {0}, tt[TTLEN + 1] = {0}; + struct tm *pt = localtime(&now); + int to_all = 0, money = 0; + getdata(0, 0, "指定使用者(S) 全站使用者(A) 取消(Q)?[S]", buf, sizeof(buf), LCECHO); - if(buf[0] == 'q') + if (buf[0] == 'q') return 1; - else if( buf[0] == 'a') { + else if (buf[0] == 'a') { to_all = 1; getdata(1, 0, "發多少錢呢?", buf, 20, DOECHO); money = atoi(buf); - if(money <= 0) { + if (money <= 0) { move(2, 0); prints("輸入錯誤!!"); pressanykey(); return 1; } } else { - if(vedit("etc/givemoney.txt", NA, NULL) < 0) + if (vedit("etc/givemoney.txt", NA, NULL) < 0) return 1; } - + clear(); getdata(0, 0, "要發錢了嗎(Y/N)[N]", buf, 3, LCECHO); - if(buf[0] != 'y') + if (buf[0] != 'y') return 1; - if(!(fp2 = fopen("etc/givemoney.log", "a"))) + if (!(fp2 = fopen("etc/givemoney.log", "a"))) return 1; strftime(buf, 200, "%Y/%m/%d/%H:%M", pt); fprintf(fp2, "%s\n", buf); - + getdata(1, 0, "紅包袋標題 :", tt, TTLEN, DOECHO); move(2, 0); - + prints("編紅包袋內容"); pressanykey(); - if(vedit("etc/givemoney.why", NA, NULL) < 0) + if (vedit("etc/givemoney.why", NA, NULL) < 0) return 1; - + stand_title("發錢中..."); - if(to_all) { - int i, unum; - for(unum = SHM->number, i=0; i<unum; i++) { - if(bad_user_id(SHM->userid[i])) + if (to_all) { + int i, unum; + for (unum = SHM->number, i = 0; i < unum; i++) { + if (bad_user_id(SHM->userid[i])) continue; id = SHM->userid[i]; give_id_money(id, money, fp2, tt, now); } - // something wrong @_@ - //give_money_post("全站使用者", atoi(money) ); + //something wrong @ _ @ + //give_money_post("全站使用者", atoi(money)); } else { - if(!(fp = fopen("etc/givemoney.txt", "r+"))) { + if (!(fp = fopen("etc/givemoney.txt", "r+"))) { fclose(fp2); return 1; } - while(fgets(buf, 255, fp)) { - clear(); + while (fgets(buf, 255, fp)) { + clear(); if (!(ptr = strchr(buf, ':'))) continue; *ptr = '\0'; id = buf; mn = ptr + 1; give_id_money(id, atoi(mn), fp2, tt, now); - give_money_post(id, atoi(mn) ); + give_money_post(id, atoi(mn)); } fclose(fp); } - + fclose(fp2); pressanykey(); return FULLUPDATE; diff --git a/pttbbs/mbbsd/announce.c b/pttbbs/mbbsd/announce.c index 5eb58ef6..3e8700bf 100644 --- a/pttbbs/mbbsd/announce.c +++ b/pttbbs/mbbsd/announce.c @@ -1,21 +1,23 @@ -/* $Id: announce.c,v 1.12 2002/06/19 13:20:27 lwms Exp $ */ +/* $Id: announce.c,v 1.13 2002/07/05 17:10:26 in2 Exp $ */ #include "bbs.h" -static void g_showmenu(gmenu_t *pm) { - static char *mytype = "編 選 絲路之旅"; - char *title, ch; - int n, max; - item_t *item; +static void +g_showmenu(gmenu_t * pm) +{ + static char *mytype = "編 選 絲路之旅"; + char *title, ch; + int n, max; + item_t *item; showtitle("精華文章", pm->mtitle); prints(" \033[1;36m編號 標 題%56s\033[m", mytype); - - if(pm->num) { + + if (pm->num) { n = pm->page; max = n + p_lines; - if(max > pm->num) + if (max > pm->num) max = pm->num; - while(n < max) { + while (n < max) { item = pm->item[n++]; title = item->title; ch = title[1]; @@ -34,35 +36,37 @@ static void g_showmenu(gmenu_t *pm) { "\033[31m(enter/→)\033[30m讀取資料 \033[m"); } -static FILE *go_cmd(item_t *node, int *sock) { +static FILE * +go_cmd(item_t * node, int *sock) +{ struct sockaddr_in sin; struct hostent *host; - char *site; - FILE *fp; - + char *site; + FILE *fp; + *sock = socket(AF_INET, SOCK_STREAM, 0); - - if(*sock < 0) { + + if (*sock < 0) { syslog(LOG_ERR, "socket(): %m"); return NULL; } memset((char *)&sin, 0, sizeof(sin)); sin.sin_family = AF_INET; sin.sin_port = htons(node->X.G.port); - + host = gethostbyname(site = node->X.G.server); - if(host == NULL) + if (host == NULL) sin.sin_addr.s_addr = inet_addr(site); else memcpy(&sin.sin_addr.s_addr, host->h_addr, host->h_length); - - if(connect(*sock, (struct sockaddr *)&sin, sizeof(sin)) < 0) { + + if (connect(*sock, (struct sockaddr *) & sin, sizeof(sin)) < 0) { syslog(LOG_ERR, "connect(): %m"); return NULL; } fp = fdopen(*sock, "r+"); - if(fp != NULL) { - setbuf(fp, (char *) 0); + if (fp != NULL) { + setbuf(fp, (char *)0); fprintf(fp, "%s\r\n", node->X.G.path); fflush(fp); } else @@ -70,12 +74,14 @@ static FILE *go_cmd(item_t *node, int *sock) { return fp; } -static char *nextfield(char *data, char *field) { - register int ch; - - while((ch = *data)) { +static char * +nextfield(char *data, char *field) +{ + register int ch; + + while ((ch = *data)) { data++; - if((ch == '\t') || (ch == '\r' && *data == '\n')) + if ((ch == '\t') || (ch == '\r' && *data == '\n')) break; *field++ = ch; } @@ -83,90 +89,94 @@ static char *nextfield(char *data, char *field) { return data; } -static FILE* my_open(char* path) { - FILE* ans = 0; - char buf[80]; - struct stat st; +static FILE * +my_open(char *path) +{ + FILE *ans = 0; + char buf[80]; + struct stat st; - if(stat(path, &st) == 0 && st.st_mtime < now - 3600 * 24 * 7) { + if (stat(path, &st) == 0 && st.st_mtime < now - 3600 * 24 * 7) { return fopen(path, "w"); } - - if((ans = fopen(path, "r+"))) { + if ((ans = fopen(path, "r+"))) { fclose(ans); return 0; /* - return directly due to currutmp->pager > 1 mode (real copy) - */ + * return directly due to currutmp->pager > 1 mode (real copy) + */ fgets(buf, 80, ans); - if(!strncmp(buf, str_author1, strlen(str_author1)) || - *buf == '0' || *buf == '1') { + if (!strncmp(buf, str_author1, strlen(str_author1)) || + *buf == '0' || *buf == '1') { fclose(ans); return 0; } - rewind(ans); } else ans = fopen(path, "w"); return ans; } -static jmp_buf jbuf; +static jmp_buf jbuf; -static void isig(int sig) { +static void +isig(int sig) +{ longjmp(jbuf, 1); } #define PROXY_HOME "proxy/" -static void go_proxy(char* fpath, item_t *node, int update) { - char *ptr, *str, *server; - int ch; - static FILE *fo; - +static void +go_proxy(char *fpath, item_t * node, int update) +{ + char *ptr, *str, *server; + int ch; + static FILE *fo; + strcpy(fpath, PROXY_HOME); ptr = fpath + sizeof(PROXY_HOME) - 1; str = server = node->X.G.server; - while((ch = *str)) { + while ((ch = *str)) { str++; - if(ch == '.') { - if(!strcmp(str, "edu.tw")) + if (ch == '.') { + if (!strcmp(str, "edu.tw")) break; - } else if(ch >= 'A' && ch <= 'Z') { + } else if (ch >= 'A' && ch <= 'Z') { ch |= 0x20; } *ptr++ = ch; } *ptr = '\0'; mkdir(fpath, 0755); - + *ptr++ = '/'; str = node->X.G.path; - while((ch = *str)) { + while ((ch = *str)) { str++; - if(ch == '/') { + if (ch == '/') { ch = '.'; } *ptr++ = ch; } *ptr = '\0'; - + /* expire proxy data */ - - if((fo = update ? fopen(fpath, "w") : my_open(fpath))) { - FILE *fp; - char buf[512]; - int sock; - - if(fo == NULL) + + if ((fo = update ? fopen(fpath, "w") : my_open(fpath))) { + FILE *fp; + char buf[512]; + int sock; + + if (fo == NULL) return; - + outmsg("★ 建立 proxy 資料連線中 ... "); refresh(); - + sock = -1; - if(setjmp(jbuf)) { - if(sock != -1) + if (setjmp(jbuf)) { + if (sock != -1) close(sock); fseek(fo, 0, SEEK_SET); fwrite("", 0, 0, fo); @@ -174,7 +184,6 @@ static void go_proxy(char* fpath, item_t *node, int update) { alarm(0); return; } - signal(SIGALRM, isig); alarm(5); fp = go_cmd(node, &sock); @@ -182,17 +191,16 @@ static void go_proxy(char* fpath, item_t *node, int update) { str = node->title; ch = str[1]; - if(ch == (char) 0xbc && - !(HAS_PERM(PERM_SYSOP) && currutmp->pager > 1)) { + if (ch == (char)0xbc && + !(HAS_PERM(PERM_SYSOP) && currutmp->pager > 1)) { fprintf(fo, "作者: %s (連線精華區)\n標題: %s\n時間: %s\n", server, str + 3, ctime(&now) ); } - - while(fgets(buf, 511, fp)) { - if(!strcmp(buf, ".\r\n")) + while (fgets(buf, 511, fp)) { + if (!strcmp(buf, ".\r\n")) break; - if((ptr = strstr(buf, "\r\n"))) + if ((ptr = strstr(buf, "\r\n"))) strcpy(ptr, "\n"); fputs(buf, fo); } @@ -201,46 +209,50 @@ static void go_proxy(char* fpath, item_t *node, int update) { } } -static void g_additem(gmenu_t *pm, item_t *myitem) { - if(pm->num < MAX_ITEMS) { - item_t *newitem = (item_t *)malloc(sizeof(item_t)); - +static void +g_additem(gmenu_t * pm, item_t * myitem) +{ + if (pm->num < MAX_ITEMS) { + item_t *newitem = (item_t *) malloc(sizeof(item_t)); + memcpy(newitem, myitem, sizeof(item_t)); pm->item[(pm->num)++] = newitem; } } -static void go_menu(gmenu_t *pm, item_t *node, int update) { - FILE *fp; - char buf[512], *ptr, *title; - item_t item; - int ch; - +static void +go_menu(gmenu_t * pm, item_t * node, int update) +{ + FILE *fp; + char buf[512], *ptr, *title; + item_t item; + int ch; + go_proxy(buf, node, update); pm->num = 0; - if((fp = fopen(buf, "r"))) { + if ((fp = fopen(buf, "r"))) { title = item.title; - while(fgets(buf, 511, fp)) { + while (fgets(buf, 511, fp)) { ptr = buf; ch = *ptr++; - if(ch != '0' && ch != '1') + if (ch != '0' && ch != '1') continue; - + strcpy(title, "□ "); - if(ch == '1') - title[1] = (char) 0xbd; + if (ch == '1') + title[1] = (char)0xbd; ptr = nextfield(ptr, title + 3); - if(!*ptr) + if (!*ptr) continue; title[sizeof(item.title) - 1] = '\0'; ptr = nextfield(ptr, item.X.G.path); - if(!*ptr) + if (!*ptr) continue; ptr = nextfield(ptr, item.X.G.server); - if(!*ptr) + if (!*ptr) continue; nextfield(ptr, buf); @@ -252,12 +264,14 @@ static void go_menu(gmenu_t *pm, item_t *node, int update) { } } -static int g_searchtitle(gmenu_t* pm, int rev) { - static char search_str[30] = ""; - int pos; - - if(getdata(b_lines - 1, 1,"[搜尋]關鍵字:", search_str, sizeof(search_str), DOECHO)) - if(!*search_str) +static int +g_searchtitle(gmenu_t * pm, int rev) +{ + static char search_str[30] = ""; + int pos; + + if (getdata(b_lines - 1, 1, "[搜尋]關鍵字:", search_str, sizeof(search_str), DOECHO)) + if (!*search_str) return pm->now; str_lower(search_str, search_str); @@ -266,17 +280,19 @@ static int g_searchtitle(gmenu_t* pm, int rev) { pos = pm->now; do { pos += rev; - if(pos == pm->num) + if (pos == pm->num) pos = 0; - else if(pos < 0) + else if (pos < 0) pos = pm->num - 1; - if(strstr_lower(pm->item[pos]->title, search_str)) + if (strstr_lower(pm->item[pos]->title, search_str)) return pos; - } while(pos != pm->now); + } while (pos != pm->now); return pm->now; } -static void g_showhelp() { +static void +g_showhelp() +{ clear(); outs("\033[36m【 " BBSNAME "連線精華區使用說明 】\033[m\n\n" "[←][q] 離開到上一層目錄\n" @@ -296,24 +312,26 @@ static void g_showhelp() { #define PATHLEN 256 -static char paste_fname[200]; +static char paste_fname[200]; -static void load_paste() { - struct stat st; - FILE *fp; - - if(!*paste_fname) +static void +load_paste() +{ + struct stat st; + FILE *fp; + + if (!*paste_fname) setuserfile(paste_fname, "paste_path"); - if(stat(paste_fname, &st) == 0 && st.st_mtime > paste_time && - (fp = fopen(paste_fname, "r"))) { - int i; + if (stat(paste_fname, &st) == 0 && st.st_mtime > paste_time && + (fp = fopen(paste_fname, "r"))) { + int i; fgets(paste_path, PATHLEN, fp); i = strlen(paste_path) - 1; - if(paste_path[i] == '\n') + if (paste_path[i] == '\n') paste_path[i] = 0; fgets(paste_title, STRLEN, fp); i = strlen(paste_title) - 1; - if(paste_title[i] == '\n') + if (paste_title[i] == '\n') paste_title[i] = 0; fscanf(fp, "%d", &paste_level); paste_time = st.st_mtime; @@ -321,18 +339,20 @@ static void load_paste() { } } -static char copyfile[PATHLEN]; -static char copytitle[TTLEN+1]; -static char copyowner[IDLEN + 2]; +static char copyfile[PATHLEN]; +static char copytitle[TTLEN + 1]; +static char copyowner[IDLEN + 2]; -void a_copyitem(char* fpath, char* title, char* owner, int mode) { +void +a_copyitem(char *fpath, char *title, char *owner, int mode) +{ strcpy(copyfile, fpath); strcpy(copytitle, title); - if(owner) + if (owner) strcpy(copyowner, owner); else *copyowner = 0; - if(mode) { + if (mode) { outmsg("檔案標記完成。[注意] 拷貝後才能刪除原文!"); igetch(); } @@ -340,50 +360,56 @@ void a_copyitem(char* fpath, char* title, char* owner, int mode) { #define FHSZ sizeof(fileheader_t) -static void a_loadname(menu_t *pm) { - char buf[PATHLEN]; - int len; - +static void +a_loadname(menu_t * pm) +{ + char buf[PATHLEN]; + int len; + setadir(buf, pm->path); - len = get_records(buf, pm->header, FHSZ, pm->page+1, p_lines); - if(len < p_lines) - bzero(&pm->header[len], FHSZ*(p_lines-len)); + len = get_records(buf, pm->header, FHSZ, pm->page + 1, p_lines); + if (len < p_lines) + bzero(&pm->header[len], FHSZ * (p_lines - len)); } -static void a_timestamp(char *buf, time_t *time) { - struct tm *pt = localtime(time); - +static void +a_timestamp(char *buf, time_t * time) +{ + struct tm *pt = localtime(time); + sprintf(buf, "%02d/%02d/%02d", pt->tm_mon + 1, pt->tm_mday, (pt->tm_year + 1900) % 100); } -static void a_showmenu(menu_t *pm) { - char *title, *editor; - int n; - fileheader_t *item; - char buf[PATHLEN]; - time_t dtime; +static void +a_showmenu(menu_t * pm) +{ + char *title, *editor; + int n; + fileheader_t *item; + char buf[PATHLEN]; + time_t dtime; showtitle("精華文章", pm->mtitle); prints(" \033[1;36m編號 標 題%56s\033[0m", "編 選 日 期"); - if(pm->num) { + if (pm->num) { setadir(buf, pm->path); a_loadname(pm); - for(n = 0; n < p_lines && pm->page + n < pm->num; n++) { + for (n = 0; n < p_lines && pm->page + n < pm->num; n++) { item = &pm->header[n]; title = item->title; editor = item->owner; - /* Ptt 把時間改為取檔案時間 - dtime = atoi(&item->filename[2]); - */ - sprintf(buf,"%s/%s",pm->path,item->filename); + /* + * Ptt 把時間改為取檔案時間 dtime = atoi(&item->filename[2]); + */ + sprintf(buf, "%s/%s", pm->path, item->filename); dtime = dasht(buf); a_timestamp(buf, &dtime); - prints("\n%6d%c %-47.46s%-13s[%s]", pm->page+n+1, - (item->filemode & FILE_BM) ?'X': - (item->filemode & FILE_HIDE) ?')':'.', - title, editor, + prints("\n%6d%c %-47.46s%-13s[%s]", pm->page + n + 1, + (item->filemode & FILE_BM) ? 'X' : + (item->filemode & FILE_HIDE) ? ')' : '.', + title, editor, buf); } } else @@ -399,38 +425,44 @@ static void a_showmenu(menu_t *pm) { "\033[31m(enter/→)\033[30m讀取資料 \033[m"); } -static int a_searchtitle(menu_t *pm, int rev) { - static char search_str[40] = ""; - int pos; - +static int +a_searchtitle(menu_t * pm, int rev) +{ + static char search_str[40] = ""; + int pos; + getdata(b_lines - 1, 1, "[搜尋]關鍵字:", search_str, sizeof(search_str), DOECHO); - - if(!*search_str) + + if (!*search_str) return pm->now; - + str_lower(search_str, search_str); - + rev = rev ? -1 : 1; pos = pm->now; do { pos += rev; - if(pos == pm->num) + if (pos == pm->num) pos = 0; - else if(pos < 0) + else if (pos < 0) pos = pm->num - 1; - if(pos < pm->page || pos >= pm->page + p_lines) { + if (pos < pm->page || pos >= pm->page + p_lines) { pm->page = pos - pos % p_lines; a_loadname(pm); } - if(strstr_lower(pm->header[pos - pm->page].title, search_str)) + if (strstr_lower(pm->header[pos - pm->page].title, search_str)) return pos; - } while(pos != pm->now); + } while (pos != pm->now); return pm->now; } -enum {NOBODY, MANAGER, SYSOP}; +enum { + NOBODY, MANAGER, SYSOP +}; -static void a_showhelp(int level) { +static void +a_showhelp(int level) +{ clear(); outs("\033[36m【 " BBSNAME "公佈欄使用說明 】\033[m\n\n" "[←][q] 離開到上一層目錄\n" @@ -442,17 +474,16 @@ static void a_showhelp(int level) { "[##] 移到該選項\n" "[F][U] 將文章寄回 Internet 郵箱/" "將文章 uuencode 後寄回郵箱\n"); - if(level >= MANAGER) { + if (level >= MANAGER) { outs("\n\033[36m【 板主專用鍵 】\033[m\n" - "[H] 切換為 公開/會員/板主 才能閱\讀\n" + "[H] 切換為 公開/會員/板主 才能閱\讀\n" "[n/g/G] 收錄精華文章/開闢目錄/建立連線\n" "[m/d/D] 移動/刪除文章/刪除一個範圍的文章\n" "[f/T/e] 編輯標題符號/修改文章標題/內容\n" "[c/p/a] 拷貝/粘貼/附加文章\n" "[^P/^A] 粘貼/附加已用't'標記文章\n"); } - - if(level >= SYSOP) { + if (level >= SYSOP) { outs("\n\033[36m【 站長專用鍵 】\033[m\n" "[l] 建 symbolic link\n" "[N] 查詢檔名\n"); @@ -460,11 +491,13 @@ static void a_showhelp(int level) { pressanykey(); } -static int AnnounceSelect() { - static char xboard[20]; - char buf[20]; - char fpath[256]; - boardheader_t *bp; +static int +AnnounceSelect() +{ + static char xboard[20]; + char buf[20]; + char fpath[256]; + boardheader_t *bp; move(2, 0); clrtoeol(); @@ -476,9 +509,9 @@ static int AnnounceSelect() { completeboard_compar, completeboard_permission, completeboard_getname); - if(*buf) + if (*buf) strcpy(xboard, buf); - if(*xboard && (bp = getbcache(getbnum(xboard)))) { + if (*xboard && (bp = getbcache(getbnum(xboard)))) { setapath(fpath, xboard); setutmpmode(ANNOUNCE); a_menu(xboard, fpath, @@ -488,57 +521,58 @@ static int AnnounceSelect() { return FULLUPDATE; } -void gem(char* maintitle, item_t* path, int update) { - gmenu_t me; - int ch; - char fname[PATHLEN]; - +void +gem(char *maintitle, item_t * path, int update) +{ + gmenu_t me; + int ch; + char fname[PATHLEN]; + strncpy(me.mtitle, maintitle, 40); me.mtitle[40] = 0; go_menu(&me, path, update); - + /* 精華區-tree 中部份結構屬於 cuser ==> BM */ - + me.level = 0; me.page = 9999; me.now = 0; - for(;;) { - if(me.now >= me.num && me.num > 0) + for (;;) { + if (me.now >= me.num && me.num > 0) me.now = me.num - 1; - else if(me.now < 0) + else if (me.now < 0) me.now = 0; - - if(me.now < me.page || me.now >= me.page + p_lines) { + + if (me.now < me.page || me.now >= me.page + p_lines) { me.page = me.now - (me.now % p_lines); g_showmenu(&me); } ch = cursor_key(2 + me.now - me.page, 0); - if(ch == 'q' || ch == 'Q' || ch == KEY_LEFT) + if (ch == 'q' || ch == 'Q' || ch == KEY_LEFT) break; - - if(ch >= '0' && ch <= '9') { - if((ch = search_num(ch, me.num)) != -1) + + if (ch >= '0' && ch <= '9') { + if ((ch = search_num(ch, me.num)) != -1) me.now = ch; me.page = 9999; continue; } - - switch(ch) { + switch (ch) { case KEY_UP: case 'k': - if(--me.now < 0) + if (--me.now < 0) me.now = me.num - 1; break; case KEY_DOWN: case 'j': - if(++me.now >= me.num) + if (++me.now >= me.num) me.now = 0; break; case KEY_PGUP: case 'b': - if(me.now >= p_lines) + if (me.now >= p_lines) me.now -= p_lines; - else if(me.now > 0) + else if (me.now > 0) me.now = 0; else me.now = me.num - 1; @@ -546,9 +580,9 @@ void gem(char* maintitle, item_t* path, int update) { case ' ': case KEY_PGDN: case Ctrl('F'): - if(me.now < me.num - p_lines) + if (me.now < me.num - p_lines) me.now += p_lines; - else if(me.now < me.num - 1) + else if (me.now < me.num - 1) me.now = me.num - 1; else me.now = 0; @@ -563,7 +597,7 @@ void gem(char* maintitle, item_t* path, int update) { me.page = 9999; break; case 'N': - if(HAS_PERM(PERM_SYSOP)) { + if (HAS_PERM(PERM_SYSOP)) { go_proxy(fname, me.item[me.now], 0); move(b_lines - 1, 0); outs(fname); @@ -574,21 +608,21 @@ void gem(char* maintitle, item_t* path, int update) { case 'c': case 'C': case Ctrl('C'): - if(me.now < me.num) { - item_t *node = me.item[me.now]; - char *title = node->title; - int mode = title[1]; + if (me.now < me.num) { + item_t *node = me.item[me.now]; + char *title = node->title; + int mode = title[1]; load_paste(); - if(mode == (char) 0xbc || ch == Ctrl('C')) { - if(mode == (char) 0xbc) + if (mode == (char)0xbc || ch == Ctrl('C')) { + if (mode == (char)0xbc) go_proxy(fname, node, 0); - if(ch == Ctrl('C') && *paste_path && paste_level) { - char newpath[PATHLEN]; - fileheader_t item; + if (ch == Ctrl('C') && *paste_path && paste_level) { + char newpath[PATHLEN]; + fileheader_t item; strcpy(newpath, paste_path); - if(mode == (char) 0xbc) { + if (mode == (char)0xbc) { stampfile(newpath, &item); unlink(newpath); Link(fname, newpath); @@ -597,19 +631,19 @@ void gem(char* maintitle, item_t* path, int update) { strcpy(item.owner, cuser.userid); sprintf(item.title, "%s%.72s", (currutmp->pager > 1) ? "" : - (mode == (char) 0xbc) ? "◇ " : "◆ ", + (mode == (char)0xbc) ? "◇ " : "◆ ", title + 3); strcpy(strrchr(newpath, '/') + 1, ".DIR"); append_record(newpath, &item, FHSZ); - if(++me.now >= me.num) + if (++me.now >= me.num) me.now = 0; break; } - if(mode == (char) 0xbc) { + if (mode == (char)0xbc) { a_copyitem(fname, title + ((currutmp->pager > 1) ? 3 : 0), 0, 1); - if(ch == 'C' && *paste_path) { + if (ch == 'C' && *paste_path) { setutmpmode(ANNOUNCE); a_menu(paste_title, paste_path, paste_level); } @@ -636,39 +670,39 @@ void gem(char* maintitle, item_t* path, int update) { case KEY_RIGHT: case 'r': case 'R': - if(me.now < me.num) { - item_t *node = me.item[me.now]; - char *title = node->title; - int mode = title[1]; - int update = (ch == 'R') ? 1 : 0; + if (me.now < me.num) { + item_t *node = me.item[me.now]; + char *title = node->title; + int mode = title[1]; + int update = (ch == 'R') ? 1 : 0; title += 3; - if(mode == (char) 0xbc) { - int more_result; + if (mode == (char)0xbc) { + int more_result; go_proxy(fname, node, update); strcpy(vetitle, title); - while((more_result = more(fname, YEA))) { - if(more_result == 1) { - if(--me.now < 0) { + while ((more_result = more(fname, YEA))) { + if (more_result == 1) { + if (--me.now < 0) { me.now = 0; break; } - } else if(more_result == 3) { - if(++me.now >= me.num) { + } else if (more_result == 3) { + if (++me.now >= me.num) { me.now = me.num - 1; break; } } else break; node = me.item[me.now]; - if(node->title[1] != (char) 0xbc) + if (node->title[1] != (char)0xbc) break; go_proxy(fname, node, update); strcpy(vetitle, title); } - } else if(mode == (char) 0xbd) { + } else if (mode == (char)0xbd) { gem(title, node, update); } me.page = 9999; @@ -676,16 +710,18 @@ void gem(char* maintitle, item_t* path, int update) { break; } } - for(ch = 0; ch < me.num; ch++) + for (ch = 0; ch < me.num; ch++) free(me.item[ch]); } -static void a_forward(char *path, fileheader_t *pitem, int mode) { - fileheader_t fhdr; - +static void +a_forward(char *path, fileheader_t * pitem, int mode) +{ + fileheader_t fhdr; + strcpy(fhdr.filename, pitem->filename); strcpy(fhdr.title, pitem->title); - switch(doforward(path, &fhdr, mode)) { + switch (doforward(path, &fhdr, mode)) { case 0: outmsg(msg_fwd_ok); break; @@ -698,20 +734,21 @@ static void a_forward(char *path, fileheader_t *pitem, int mode) { } } -static void a_additem(menu_t *pm, fileheader_t *myheader) { - char buf[PATHLEN]; - +static void +a_additem(menu_t * pm, fileheader_t * myheader) +{ + char buf[PATHLEN]; + setadir(buf, pm->path); - if(append_record(buf, myheader, FHSZ) == -1) + if (append_record(buf, myheader, FHSZ) == -1) return; pm->now = pm->num++; - - if(pm->now >= pm->page + p_lines) { + + if (pm->now >= pm->page + p_lines) { pm->page = pm->now - ((pm->page == 10000 && pm->now > p_lines / 2) ? (p_lines / 2) : (pm->now % p_lines)); - } - - /*Ptt*/ + } + /* Ptt */ strcpy(pm->header[pm->now - pm->page].filename, myheader->filename); } @@ -720,80 +757,81 @@ static void a_additem(menu_t *pm, fileheader_t *myheader) { #define ADDGOPHER 2 #define ADDLINK 3 -static void a_newitem(menu_t *pm, int mode) { - static char *mesg[4] = { - "[新增文章] 請輸入標題:", /* ADDITEM */ - "[新增目錄] 請輸入標題:", /* ADDGROUP */ - "[新增連線] 請輸入標題:", /* ADDGOPHER */ - "請輸入標題:" /* ADDLINK */ +static void +a_newitem(menu_t * pm, int mode) +{ + static char *mesg[4] = { + "[新增文章] 請輸入標題:", /* ADDITEM */ + "[新增目錄] 請輸入標題:", /* ADDGROUP */ + "[新增連線] 請輸入標題:", /* ADDGOPHER */ + "請輸入標題:" /* ADDLINK */ }; - char fpath[PATHLEN], buf[PATHLEN], lpath[PATHLEN]; - fileheader_t item; - int d; + char fpath[PATHLEN], buf[PATHLEN], lpath[PATHLEN]; + fileheader_t item; + int d; strcpy(fpath, pm->path); - switch(mode) { + switch (mode) { case ADDITEM: stampfile(fpath, &item); - strcpy(item.title, "◇ "); /* A1BA */ + strcpy(item.title, "◇ "); /* A1BA */ break; - + case ADDGROUP: stampdir(fpath, &item); - strcpy(item.title, "◆ "); /* A1BB */ + strcpy(item.title, "◆ "); /* A1BB */ break; case ADDGOPHER: bzero(&item, sizeof(item)); - strcpy(item.title, "☉ "); /* A1BB */ - if(!getdata(b_lines - 2, 1, "輸入URL位址:", - item.filename+2,61, DOECHO)) + strcpy(item.title, "☉ "); /* A1BB */ + if (!getdata(b_lines - 2, 1, "輸入URL位址:", + item.filename + 2, 61, DOECHO)) return; break; case ADDLINK: stamplink(fpath, &item); if (!getdata(b_lines - 2, 1, "新增連線:", buf, 61, DOECHO)) return; - if(invalid_pname(buf)) { + if (invalid_pname(buf)) { unlink(fpath); outs("目的地路徑不合法!"); igetch(); return; } - item.title[0] = 0; - for(d = 0; d <= 3; d++) { - switch(d) { + for (d = 0; d <= 3; d++) { + switch (d) { case 0: sprintf(lpath, BBSHOME "/man/boards/%c/%s/%s", currboard[0], currboard, buf); break; case 1: sprintf(lpath, "%s%s/%c/%s", - BBSHOME, "/man/boards/" , buf[0], buf); + BBSHOME, "/man/boards/", buf[0], buf); break; case 2: sprintf(lpath, "%s%s%s", - BBSHOME, "/" , buf); + BBSHOME, "/", buf); break; case 3: sprintf(lpath, "%s%s%s", - BBSHOME, "/etc/" , buf); + BBSHOME, "/etc/", buf); break; } - if(dashf(lpath)) { - strcpy(item.title, "☆ "); /* A1B3 */ + if (dashf(lpath)) { + strcpy(item.title, "☆ "); /* A1B3 */ break; } else if (dashd(lpath)) { - strcpy(item.title, "★ "); /* A1B4 */ + strcpy(item.title, "★ "); /* A1B4 */ break; } - if(!HAS_PERM(PERM_BBSADM) && d==1) + if (!HAS_PERM(PERM_BBSADM) && d == 1) break; } - - if(!item.title[0]) { + + if (!item.title[0]) { unlink(fpath); outs("目的地路徑不合法!"); igetch(); @@ -801,17 +839,16 @@ static void a_newitem(menu_t *pm, int mode) { } } - if(!getdata(b_lines - 1, 1, mesg[mode], &item.title[3], 55, DOECHO)) { - if(mode == ADDGROUP) + if (!getdata(b_lines - 1, 1, mesg[mode], &item.title[3], 55, DOECHO)) { + if (mode == ADDGROUP) rmdir(fpath); - else if(mode != ADDGOPHER) + else if (mode != ADDGOPHER) unlink(fpath); return; } - - switch(mode) { + switch (mode) { case ADDITEM: - if(vedit(fpath, 0, NULL) == -1) { + if (vedit(fpath, 0, NULL) == -1) { unlink(fpath); pressanykey(); return; @@ -819,7 +856,7 @@ static void a_newitem(menu_t *pm, int mode) { break; case ADDLINK: unlink(fpath); - if(symlink(lpath, fpath) == -1) { + if (symlink(lpath, fpath) == -1) { outs("無法建立 symbolic link"); igetch(); return; @@ -827,7 +864,7 @@ static void a_newitem(menu_t *pm, int mode) { break; case ADDGOPHER: strcpy(item.date, "70"); - strncpy(item.filename, "H.",2); + strncpy(item.filename, "H.", 2); break; } @@ -835,54 +872,56 @@ static void a_newitem(menu_t *pm, int mode) { a_additem(pm, &item); } -static void a_pasteitem(menu_t *pm, int mode) { - char newpath[PATHLEN]; - char buf[PATHLEN]; - char ans[2]; - int i; - fileheader_t item; +static void +a_pasteitem(menu_t * pm, int mode) +{ + char newpath[PATHLEN]; + char buf[PATHLEN]; + char ans[2]; + int i; + fileheader_t item; move(b_lines - 1, 1); - if(copyfile[0]) { - if(dashd(copyfile)) { - for(i = 0; copyfile[i] && copyfile[i] == pm->path[i]; i++); - if(!copyfile[i]) { + if (copyfile[0]) { + if (dashd(copyfile)) { + for (i = 0; copyfile[i] && copyfile[i] == pm->path[i]; i++); + if (!copyfile[i]) { outs("將目錄拷進自己的子目錄中,會造成無窮迴圈!"); igetch(); return; } } - if(mode) { + if (mode) { sprintf(buf, "確定要拷貝[%s]嗎(Y/N)?[N] ", copytitle); getdata(b_lines - 1, 1, buf, ans, sizeof(ans), LCECHO); } else - ans[0]='y'; - if(ans[0] == 'y') { + ans[0] = 'y'; + if (ans[0] == 'y') { strcpy(newpath, pm->path); - if(*copyowner) { - char* fname = strrchr(copyfile, '/'); + if (*copyowner) { + char *fname = strrchr(copyfile, '/'); - if(fname) + if (fname) strcat(newpath, fname); else return; - if(access(pm->path, X_OK | R_OK | W_OK)) + if (access(pm->path, X_OK | R_OK | W_OK)) mkdir(pm->path, 0755); memset(&item, 0, sizeof(fileheader_t)); strcpy(item.filename, fname + 1); memcpy(copytitle, "◎", 2); - if(HAS_PERM(PERM_BBSADM)) + if (HAS_PERM(PERM_BBSADM)) Link(copyfile, newpath); else { sprintf(buf, "/bin/cp %s %s", copyfile, newpath); system(buf); } - } else if(dashf(copyfile)) { + } else if (dashf(copyfile)) { stampfile(newpath, &item); memcpy(copytitle, "◇", 2); sprintf(buf, "/bin/cp %s %s", copyfile, newpath); - } else if(dashd(copyfile)) { + } else if (dashd(copyfile)) { stampdir(newpath, &item); memcpy(copytitle, "◆", 2); sprintf(buf, "/bin/cp -r %s/* %s/.D* %s", copyfile, copyfile, @@ -894,7 +933,7 @@ static void a_pasteitem(menu_t *pm, int mode) { } strcpy(item.owner, *copyowner ? copyowner : cuser.userid); strcpy(item.title, copytitle); - if(!*copyowner) + if (!*copyowner) system(buf); a_additem(pm, &item); copyfile[0] = '\0'; @@ -905,36 +944,38 @@ static void a_pasteitem(menu_t *pm, int mode) { } } -static void a_appenditem(menu_t *pm, int isask) { - char fname[PATHLEN]; - char buf[ANSILINELEN]; - char ans[2] = "y"; - FILE *fp, *fin; +static void +a_appenditem(menu_t * pm, int isask) +{ + char fname[PATHLEN]; + char buf[ANSILINELEN]; + char ans[2] = "y"; + FILE *fp, *fin; move(b_lines - 1, 1); - if(copyfile[0]) { - if(dashf(copyfile)) { + if (copyfile[0]) { + if (dashf(copyfile)) { sprintf(fname, "%s/%s", pm->path, - pm->header[pm->now-pm->page].filename); - if(dashf(fname)) { - if(isask) { + pm->header[pm->now - pm->page].filename); + if (dashf(fname)) { + if (isask) { sprintf(buf, "確定要將[%s]附加於此嗎(Y/N)?[N] ", copytitle); getdata(b_lines - 2, 1, buf, ans, sizeof(ans), LCECHO); } - if(ans[0] == 'y') { - if((fp = fopen(fname, "a+"))) { - if((fin = fopen(copyfile, "r"))) { + if (ans[0] == 'y') { + if ((fp = fopen(fname, "a+"))) { + if ((fin = fopen(copyfile, "r"))) { memset(buf, '-', 74); buf[74] = '\0'; fprintf(fp, "\n> %s <\n\n", buf); - if(isask) + if (isask) getdata(b_lines - 1, 1, "是否收錄簽名檔部份(Y/N)?[Y] ", ans, sizeof(ans), LCECHO); - while(fgets(buf, sizeof(buf), fin)) { - if((ans[0] == 'n' ) && - !strcmp(buf, "--\n")) + while (fgets(buf, sizeof(buf), fin)) { + if ((ans[0] == 'n') && + !strcmp(buf, "--\n")) break; fputs(buf, fp); } @@ -958,56 +999,57 @@ static void a_appenditem(menu_t *pm, int isask) { } } -static int a_pastetagpost(menu_t *pm, int mode) { - fileheader_t fhdr; - int ans = 0, ent=0, tagnum; - char title[TTLEN + 1]= "◇ "; - char dirname[200],buf[200]; +static int +a_pastetagpost(menu_t * pm, int mode) +{ + fileheader_t fhdr; + int ans = 0, ent = 0, tagnum; + char title[TTLEN + 1] = "◇ "; + char dirname[200], buf[200]; setbdir(dirname, currboard); tagnum = TagNum; - if (!tagnum) return ans; - - while (tagnum--) - { - EnumTagFhdr (&fhdr, dirname, ent++); - setbfile (buf, currboard, fhdr.filename); - - if (dashf (buf)) - { - strncpy(title+3, fhdr.title, TTLEN-3); - title[TTLEN] = '\0'; - a_copyitem(buf, title, 0, 0); - if(mode) - { - mode--; - a_pasteitem(pm,0); - } - else a_appenditem(pm, 0); - ++ans; - UnTagger (tagnum); - } + if (!tagnum) + return ans; + while (tagnum--) { + EnumTagFhdr(&fhdr, dirname, ent++); + setbfile(buf, currboard, fhdr.filename); + + if (dashf(buf)) { + strncpy(title + 3, fhdr.title, TTLEN - 3); + title[TTLEN] = '\0'; + a_copyitem(buf, title, 0, 0); + if (mode) { + mode--; + a_pasteitem(pm, 0); + } else + a_appenditem(pm, 0); + ++ans; + UnTagger(tagnum); + } }; return ans; -} +} -static void a_moveitem(menu_t *pm) { - fileheader_t *tmp; - char newnum[4]; - int num, max, min; - char buf[PATHLEN]; - int fail; +static void +a_moveitem(menu_t * pm) +{ + fileheader_t *tmp; + char newnum[4]; + int num, max, min; + char buf[PATHLEN]; + int fail; sprintf(buf, "請輸入第 %d 選項的新次序:", pm->now + 1); - if(!getdata(b_lines - 1, 1, buf, newnum, sizeof(newnum), DOECHO)) + if (!getdata(b_lines - 1, 1, buf, newnum, sizeof(newnum), DOECHO)) return; num = (newnum[0] == '$') ? 9999 : atoi(newnum) - 1; - if(num >= pm->num) + if (num >= pm->num) num = pm->num - 1; - else if(num < 0) + else if (num < 0) num = 0; setadir(buf, pm->path); min = num < pm->now ? num : pm->now; @@ -1015,137 +1057,146 @@ static void a_moveitem(menu_t *pm) { tmp = (fileheader_t *) calloc(max + 1, FHSZ); fail = 0; - if(get_records(buf, tmp, FHSZ, 1, min) != min) + if (get_records(buf, tmp, FHSZ, 1, min) != min) fail = 1; - if(num > pm->now) { - if(get_records(buf, &tmp[min], FHSZ, pm->now+2, max-min) != max-min) + if (num > pm->now) { + if (get_records(buf, &tmp[min], FHSZ, pm->now + 2, max - min) != max - min) fail = 1; - if(get_records(buf, &tmp[max], FHSZ, pm->now+1, 1) != 1) + if (get_records(buf, &tmp[max], FHSZ, pm->now + 1, 1) != 1) fail = 1; } else { - if(get_records(buf, &tmp[min], FHSZ, pm->now+1, 1) != 1) + if (get_records(buf, &tmp[min], FHSZ, pm->now + 1, 1) != 1) fail = 1; - if(get_records(buf, &tmp[min+1], FHSZ, num+1, max-min) != max-min) + if (get_records(buf, &tmp[min + 1], FHSZ, num + 1, max - min) != max - min) fail = 1; } - if(!fail) + if (!fail) substitute_record(buf, tmp, FHSZ * (max + 1), 1); pm->now = num; free(tmp); } -static void a_delrange(menu_t *pm) { - char fname[256]; +static void +a_delrange(menu_t * pm) +{ + char fname[256]; - sprintf(fname,"%s/.DIR",pm->path); + sprintf(fname, "%s/.DIR", pm->path); del_range(0, NULL, fname); pm->num = get_num_records(fname, FHSZ); } -static void a_delete(menu_t *pm) { - char fpath[PATHLEN], buf[PATHLEN], cmd[PATHLEN]; - char ans[4]; - fileheader_t backup; +static void +a_delete(menu_t * pm) +{ + char fpath[PATHLEN], buf[PATHLEN], cmd[PATHLEN]; + char ans[4]; + fileheader_t backup; sprintf(fpath, "%s/%s", pm->path, pm->header[pm->now - pm->page].filename); setadir(buf, pm->path); - - if(pm->header[pm->now - pm->page].filename[0] == 'H' && - pm->header[pm->now - pm->page].filename[1] == '.') { + + if (pm->header[pm->now - pm->page].filename[0] == 'H' && + pm->header[pm->now - pm->page].filename[1] == '.') { getdata(b_lines - 1, 1, "您確定要刪除此精華區連線嗎(Y/N)?[N] ", ans, sizeof(ans), LCECHO); - if(ans[0] != 'y') + if (ans[0] != 'y') return; - if(delete_record(buf, FHSZ, pm->now + 1) == -1) + if (delete_record(buf, FHSZ, pm->now + 1) == -1) return; } else if (dashl(fpath)) { getdata(b_lines - 1, 1, "您確定要刪除此 symbolic link 嗎(Y/N)?[N] ", ans, sizeof(ans), LCECHO); - if(ans[0] != 'y') + if (ans[0] != 'y') return; - if(delete_record(buf, FHSZ, pm->now + 1) == -1) + if (delete_record(buf, FHSZ, pm->now + 1) == -1) return; unlink(fpath); - } else if(dashf(fpath)) { + } else if (dashf(fpath)) { getdata(b_lines - 1, 1, "您確定要刪除此檔案嗎(Y/N)?[N] ", ans, sizeof(ans), LCECHO); - if(ans[0] != 'y') + if (ans[0] != 'y') + return; + if (delete_record(buf, FHSZ, pm->now + 1) == -1) return; - if(delete_record(buf, FHSZ, pm->now + 1) == -1) - return; setbpath(buf, "deleted"); stampfile(buf, &backup); strcpy(backup.owner, cuser.userid); - strcpy(backup.title,pm->header[pm->now - pm->page].title + 2); + strcpy(backup.title, pm->header[pm->now - pm->page].title + 2); - sprintf(cmd, "mv -f %s %s", fpath,buf); + sprintf(cmd, "mv -f %s %s", fpath, buf); system(cmd); - setbdir(buf, "deleted"); - append_record(buf, &backup, sizeof(backup)); + setbdir(buf, "deleted"); + append_record(buf, &backup, sizeof(backup)); } else if (dashd(fpath)) { - getdata(b_lines - 1, 1, "您確定要刪除整個目錄嗎(Y/N)?[N] ", ans, + getdata(b_lines - 1, 1, "您確定要刪除整個目錄嗎(Y/N)?[N] ", ans, sizeof(ans), LCECHO); - if(ans[0] != 'y') + if (ans[0] != 'y') return; - if(delete_record(buf, FHSZ, pm->now + 1) == -1) + if (delete_record(buf, FHSZ, pm->now + 1) == -1) return; - setapath(buf, "deleted"); - stampdir(buf, &backup); + setapath(buf, "deleted"); + stampdir(buf, &backup); - sprintf(cmd, "rm -rf %s;/bin/mv -f %s %s",buf,fpath,buf); - system(cmd); + sprintf(cmd, "rm -rf %s;/bin/mv -f %s %s", buf, fpath, buf); + system(cmd); - strcpy(backup.owner, cuser.userid); - strcpy(backup.title,pm->header[pm->now - pm->page].title +2); - setapath(buf, "deleted"); - setadir(buf,buf); - append_record(buf, &backup, sizeof(backup)); - } else { /* Ptt 損毀的項目 */ + strcpy(backup.owner, cuser.userid); + strcpy(backup.title, pm->header[pm->now - pm->page].title + 2); + setapath(buf, "deleted"); + setadir(buf, buf); + append_record(buf, &backup, sizeof(backup)); + } else { /* Ptt 損毀的項目 */ getdata(b_lines - 1, 1, "您確定要刪除此損毀的項目嗎(Y/N)?[N] ", ans, sizeof(ans), LCECHO); - if(ans[0] != 'y') + if (ans[0] != 'y') return; - if(delete_record(buf, FHSZ, pm->now + 1) == -1) + if (delete_record(buf, FHSZ, pm->now + 1) == -1) return; } pm->num--; } -static void a_newtitle(menu_t *pm) { - char buf[PATHLEN]; - fileheader_t item; +static void +a_newtitle(menu_t * pm) +{ + char buf[PATHLEN]; + fileheader_t item; memcpy(&item, &pm->header[pm->now - pm->page], FHSZ); - strcpy(buf,item.title + 3); - if(getdata_buf(b_lines - 1, 1, "新標題:", buf, 60, DOECHO)) { + strcpy(buf, item.title + 3); + if (getdata_buf(b_lines - 1, 1, "新標題:", buf, 60, DOECHO)) { strcpy(item.title + 3, buf); setadir(buf, pm->path); substitute_record(buf, &item, FHSZ, pm->now + 1); } } -static void a_hideitem(menu_t *pm) { - fileheader_t *item=&pm->header[pm->now - pm->page]; - char buf[PATHLEN]; - if(item->filemode&FILE_BM) - { - item->filemode &= ~FILE_BM; - item->filemode &= ~FILE_HIDE; - } - else if(item->filemode&FILE_HIDE) - item->filemode |= FILE_BM; - else item->filemode |= FILE_HIDE; +static void +a_hideitem(menu_t * pm) +{ + fileheader_t *item = &pm->header[pm->now - pm->page]; + char buf[PATHLEN]; + if (item->filemode & FILE_BM) { + item->filemode &= ~FILE_BM; + item->filemode &= ~FILE_HIDE; + } else if (item->filemode & FILE_HIDE) + item->filemode |= FILE_BM; + else + item->filemode |= FILE_HIDE; setadir(buf, pm->path); substitute_record(buf, item, FHSZ, pm->now + 1); } -static void a_editsign(menu_t *pm) { - char buf[PATHLEN]; - fileheader_t item; +static void +a_editsign(menu_t * pm) +{ + char buf[PATHLEN]; + fileheader_t item; memcpy(&item, &pm->header[pm->now - pm->page], FHSZ); sprintf(buf, "%c%c", item.title[0], item.title[1]); - if(getdata_buf(b_lines - 1, 1, "符號", buf, 5, DOECHO)) { + if (getdata_buf(b_lines - 1, 1, "符號", buf, 5, DOECHO)) { item.title[0] = buf[0] ? buf[0] : ' '; item.title[1] = buf[1] ? buf[1] : ' '; item.title[2] = buf[2] ? buf[2] : ' '; @@ -1154,40 +1205,42 @@ static void a_editsign(menu_t *pm) { } } -static void a_showname(menu_t *pm) { - char buf[PATHLEN]; - int len; - int i; - int sym; +static void +a_showname(menu_t * pm) +{ + char buf[PATHLEN]; + int len; + int i; + int sym; move(b_lines - 1, 1); sprintf(buf, "%s/%s", pm->path, pm->header[pm->now - pm->page].filename); - if(dashl(buf)) { + if (dashl(buf)) { prints("此 symbolic link 名稱為 %s\n", pm->header[pm->now - pm->page].filename); - if((len = readlink(buf, buf, PATHLEN-1)) >= 0) { + if ((len = readlink(buf, buf, PATHLEN - 1)) >= 0) { buf[len] = '\0'; - for(i = 0; BBSHOME[i] && buf[i] == BBSHOME[i]; i++); - if(!BBSHOME[i] && buf[i] == '/') { - if(HAS_PERM(PERM_BBSADM)) + for (i = 0; BBSHOME[i] && buf[i] == BBSHOME[i]; i++); + if (!BBSHOME[i] && buf[i] == '/') { + if (HAS_PERM(PERM_BBSADM)) sym = 1; else { sym = 0; - for(i++; BBSHOME "/man"[i] && buf[i] == BBSHOME "/man"[i]; - i++); - if(!BBSHOME "/man"[i] && buf[i] == '/') + for (i++; BBSHOME "/man"[i] && buf[i] == BBSHOME "/man"[i]; + i++); + if (!BBSHOME "/man"[i] && buf[i] == '/') sym = 1; } - if(sym) { + if (sym) { pressanykey(); move(b_lines - 1, 1); - prints("此 symbolic link 指向 %s\n", &buf[i+1]); + prints("此 symbolic link 指向 %s\n", &buf[i + 1]); } } } - } else if(dashf(buf)) + } else if (dashf(buf)) prints("此文章名稱為 %s", pm->header[pm->now - pm->page].filename); - else if(dashd(buf)) + else if (dashd(buf)) prints("此目錄名稱為 %s", pm->header[pm->now - pm->page].filename); else outs("此項目已損毀, 建議將其刪除!"); @@ -1195,9 +1248,11 @@ static void a_showname(menu_t *pm) { } #if 0 -static char *a_title; +static char *a_title; -static void atitle() { +static void +atitle() +{ showtitle("精華文章", a_title); outs("[←]離開 [→]閱\讀 [^P]發表文章 [b]備忘錄 [d]刪除 [q]精華區 " "[TAB]文摘 [h]elp\n\033[7m 編號 日 期 作 者 " @@ -1205,81 +1260,81 @@ static void atitle() { } #endif -static int isvisible_man(menu_t *me) +static int +isvisible_man(menu_t * me) { - fileheader_t *fhdr = &me->header[me->now-me->page]; - if( me->level<MANAGER && ((fhdr->filemode & FILE_BM) || - ((fhdr->filemode & FILE_HIDE) && - hbflcheck(currbid, currutmp->uid)))) - return 0; - return 1; + fileheader_t *fhdr = &me->header[me->now - me->page]; + if (me->level < MANAGER && ((fhdr->filemode & FILE_BM) || + ((fhdr->filemode & FILE_HIDE) && + hbflcheck(currbid, currutmp->uid)))) + return 0; + return 1; } -int a_menu(char *maintitle, char *path, int lastlevel) { - static char Fexit; - menu_t me; - char fname[PATHLEN]; - int ch, returnvalue = FULLUPDATE; - +int +a_menu(char *maintitle, char *path, int lastlevel) +{ + static char Fexit; + menu_t me; + char fname[PATHLEN]; + int ch, returnvalue = FULLUPDATE; + trans_buffer[0] = 0; - + Fexit = 0; - me.header = (fileheader_t *)calloc(p_lines, FHSZ); + me.header = (fileheader_t *) calloc(p_lines, FHSZ); me.path = path; strcpy(me.mtitle, maintitle); setadir(fname, me.path); me.num = get_num_records(fname, FHSZ); - + /* 精華區-tree 中部份結構屬於 cuser ==> BM */ - - if(!(me.level = lastlevel)) { - char *ptr; - - if((ptr = strrchr(me.mtitle, '['))) + + if (!(me.level = lastlevel)) { + char *ptr; + + if ((ptr = strrchr(me.mtitle, '['))) me.level = is_BM(ptr + 1); } - me.page = 9999; me.now = 0; - for(;;) { - if(me.now >= me.num) + for (;;) { + if (me.now >= me.num) me.now = me.num - 1; - if(me.now < 0) + if (me.now < 0) me.now = 0; - if(me.now < me.page || me.now >= me.page + p_lines) { + if (me.now < me.page || me.now >= me.page + p_lines) { me.page = me.now - ((me.page == 10000 && me.now > p_lines / 2) ? (p_lines / 2) : (me.now % p_lines)); a_showmenu(&me); } - ch = cursor_key(2 + me.now - me.page, 0); - - if(ch == 'q' || ch == 'Q' || ch == KEY_LEFT) + + if (ch == 'q' || ch == 'Q' || ch == KEY_LEFT) break; - - if(ch >= '1' && ch <= '9') { - if((ch = search_num(ch, me.num)) != -1) + + if (ch >= '1' && ch <= '9') { + if ((ch = search_num(ch, me.num)) != -1) me.now = ch; me.page = 10000; continue; } - - switch(ch) { + switch (ch) { case KEY_UP: case 'k': - if(--me.now < 0) + if (--me.now < 0) me.now = me.num - 1; break; - + case KEY_DOWN: case 'j': - if(++me.now >= me.num) + if (++me.now >= me.num) me.now = 0; break; case KEY_PGUP: case Ctrl('B'): - if(me.now >= p_lines) + if (me.now >= p_lines) me.now -= p_lines; else if (me.now > 0) me.now = 0; @@ -1290,9 +1345,9 @@ int a_menu(char *maintitle, char *path, int lastlevel) { case ' ': case KEY_PGDN: case Ctrl('F'): - if(me.now < me.num - p_lines) + if (me.now < me.num - p_lines) me.now += p_lines; - else if(me.now < me.num - 1) + else if (me.now < me.num - 1) me.now = me.num - 1; else me.now = 0; @@ -1307,7 +1362,7 @@ int a_menu(char *maintitle, char *path, int lastlevel) { me.page = 9999; break; case '$': - me.now = me.num -1; + me.now = me.num - 1; break; case 'h': a_showhelp(me.level); @@ -1330,98 +1385,100 @@ int a_menu(char *maintitle, char *path, int lastlevel) { case 'e': case 'E': - sprintf(fname, "%s/%s", path, me.header[me.now-me.page].filename); - if(dashf(fname) && me.level >= MANAGER) { + sprintf(fname, "%s/%s", path, me.header[me.now - me.page].filename); + if (dashf(fname) && me.level >= MANAGER) { *quote_file = 0; - if(vedit(fname, NA, NULL) != -1) { - char fpath[200]; - fileheader_t fhdr; + if (vedit(fname, NA, NULL) != -1) { + char fpath[200]; + fileheader_t fhdr; strcpy(fpath, path); stampfile(fpath, &fhdr); unlink(fpath); Rename(fname, fpath); - strcpy(me.header[me.now-me.page].filename, fhdr.filename); - strcpy(me.header[me.now-me.page].owner, cuser.userid); + strcpy(me.header[me.now - me.page].filename, fhdr.filename); + strcpy(me.header[me.now - me.page].owner, cuser.userid); setadir(fpath, path); - substitute_record(fpath, me.header+me.now-me.page, - sizeof(fhdr), me.now + 1); + substitute_record(fpath, me.header + me.now - me.page, + sizeof(fhdr), me.now + 1); } me.page = 9999; } break; case 'c': - if(me.now < me.num) { - if(!isvisible_man(&me)) break; + if (me.now < me.num) { + if (!isvisible_man(&me)) + break; sprintf(fname, "%s/%s", path, - me.header[me.now-me.page].filename); - a_copyitem(fname, me.header[me.now-me.page].title, 0, 1); + me.header[me.now - me.page].filename); + a_copyitem(fname, me.header[me.now - me.page].title, 0, 1); me.page = 9999; break; } - case '\n': case '\r': case KEY_RIGHT: case 'r': - if(me.now < me.num) { - fileheader_t *fhdr = &me.header[me.now-me.page]; - if(!isvisible_man(&me)) break; + if (me.now < me.num) { + fileheader_t *fhdr = &me.header[me.now - me.page]; + if (!isvisible_man(&me)) + break; sprintf(fname, "%s/%s", path, fhdr->filename); - if(*fhdr->filename == 'H' && fhdr->filename[1] == '.') { - item_t item; + if (*fhdr->filename == 'H' && fhdr->filename[1] == '.') { + item_t item; strcpy(item.X.G.server, fhdr->filename + 2); strcpy(item.X.G.path, "1/"); item.X.G.port = 70; gem(fhdr->title, &item, (ch == 'R') ? 1 : 0); } else if (dashf(fname)) { - int more_result; + int more_result; - while((more_result = more(fname, YEA))) { + while ((more_result = more(fname, YEA))) { /* Ptt 範本精靈 plugin */ - if(currstat == EDITEXP || currstat == OSONG) { - char ans[4]; + if (currstat == EDITEXP || currstat == OSONG) { + char ans[4]; move(22, 0); clrtoeol(); - getdata(22, 1, - currstat == EDITEXP ? - "要把範例 Plugin 到文章嗎?[y/N]": + getdata(22, 1, + currstat == EDITEXP ? + "要把範例 Plugin 到文章嗎?[y/N]" : "確定要點這首歌嗎?[y/N]", ans, sizeof(ans), LCECHO); - if(ans[0]=='y') { - strcpy(trans_buffer,fname); + if (ans[0] == 'y') { + strcpy(trans_buffer, fname); Fexit = 1; - if(currstat == OSONG){ - log_file(FN_USSONG,fhdr->title); + if (currstat == OSONG) { + log_file(FN_USSONG, fhdr->title); } free(me.header); return FULLUPDATE; } } - if(more_result == 1) { - if(--me.now < 0) { + if (more_result == 1) { + if (--me.now < 0) { me.now = 0; break; } - } else if(more_result == 3) { - if(++me.now >= me.num) { + } else if (more_result == 3) { + if (++me.now >= me.num) { me.now = me.num - 1; break; } } else break; - if(!isvisible_man(&me)) break; + if (!isvisible_man(&me)) + break; sprintf(fname, "%s/%s", path, - me.header[me.now-me.page].filename); - if(!dashf(fname)) + me.header[me.now - me.page].filename); + if (!dashf(fname)) break; } - } else if(dashd(fname)) { - a_menu(me.header[me.now-me.page].title, fname, me.level); + } else if (dashd(fname)) { + a_menu(me.header[me.now - me.page].title, fname, me.level); /* Ptt 強力跳出recursive */ - if(Fexit) { + if (Fexit) { free(me.header); return FULLUPDATE; } @@ -1432,10 +1489,10 @@ int a_menu(char *maintitle, char *path, int lastlevel) { case 'F': case 'U': - sprintf(fname, "%s/%s", path, me.header[me.now-me.page].filename); - if(me.now < me.num && HAS_PERM(PERM_BASIC) && dashf(fname)) { - a_forward(path, &me.header[me.now-me.page], ch /*== 'U'*/); - /*By CharlieL*/ + sprintf(fname, "%s/%s", path, me.header[me.now - me.page].filename); + if (me.now < me.num && HAS_PERM(PERM_BASIC) && dashf(fname)) { + a_forward(path, &me.header[me.now - me.page], ch /* == 'U' */ ); + /* By CharlieL */ } else outmsg("無法轉寄此項目"); @@ -1445,10 +1502,10 @@ int a_menu(char *maintitle, char *path, int lastlevel) { break; } - if(me.level >= MANAGER) { - int page0 = me.page; + if (me.level >= MANAGER) { + int page0 = me.page; - switch(ch) { + switch (ch) { case 'n': a_newitem(&me, ADDITEM); me.page = 9999; @@ -1462,7 +1519,7 @@ int a_menu(char *maintitle, char *path, int lastlevel) { me.page = 9999; break; case 'p': - a_pasteitem(&me,1); + a_pasteitem(&me, 1); me.page = 9999; break; case 'f': @@ -1471,7 +1528,7 @@ int a_menu(char *maintitle, char *path, int lastlevel) { break; case Ctrl('P'): a_pastetagpost(&me, -1); - returnvalue = DIRCHANGED; + returnvalue = DIRCHANGED; me.page = 9999; break; case Ctrl('A'): @@ -1487,16 +1544,16 @@ int a_menu(char *maintitle, char *path, int lastlevel) { me.page = page0; break; } - - if(me.num) - switch(ch) { + + if (me.num) + switch (ch) { case 'm': a_moveitem(&me); me.page = 9999; break; case 'D': - /* Ptt me.page = -1;*/ + /* Ptt me.page = -1; */ a_delrange(&me); me.page = 9999; break; @@ -1504,7 +1561,7 @@ int a_menu(char *maintitle, char *path, int lastlevel) { a_delete(&me); me.page = 9999; break; - case 'H': + case 'H': a_hideitem(&me); me.page = 9999; break; @@ -1514,9 +1571,8 @@ int a_menu(char *maintitle, char *path, int lastlevel) { break; } } - - if(me.level == SYSOP) { - switch(ch) { + if (me.level == SYSOP) { + switch (ch) { case 'l': a_newitem(&me, ADDLINK); me.page = 9999; @@ -1532,9 +1588,11 @@ int a_menu(char *maintitle, char *path, int lastlevel) { return returnvalue; } -static char *mytitle = BBSNAME "佈告欄"; +static char *mytitle = BBSNAME "佈告欄"; -int Announce() { +int +Announce() +{ setutmpmode(ANNOUNCE); a_menu(mytitle, "man", ((HAS_PERM(PERM_SYSOP) || HAS_PERM(PERM_ANNOUNCE)) ? SYSOP : diff --git a/pttbbs/mbbsd/args.c b/pttbbs/mbbsd/args.c index 9f937723..60e1de32 100644 --- a/pttbbs/mbbsd/args.c +++ b/pttbbs/mbbsd/args.c @@ -1,58 +1,68 @@ -/* $Id: args.c,v 1.2 2002/06/04 13:08:33 in2 Exp $ */ +/* $Id: args.c,v 1.3 2002/07/05 17:10:26 in2 Exp $ */ #include "bbs.h" #ifdef HAVE_SETPROCTITLE -void initsetproctitle(int argc, char **argv, char **envp) { +void +initsetproctitle(int argc, char **argv, char **envp) +{ } #else -char **Argv = NULL; /* pointer to argument vector */ -char *LastArgv = NULL; /* end of argv */ -extern char **environ; +char **Argv = NULL; /* pointer to argument vector */ +char *LastArgv = NULL;/* end of argv */ +extern char **environ; -void initsetproctitle(int argc, char **argv, char **envp) { - register int i; - - /* Move the environment so setproctitle can use the space at - the top of memory. */ - for(i = 0; envp[i]; i++); +void +initsetproctitle(int argc, char **argv, char **envp) +{ + register int i; + + /* + * Move the environment so setproctitle can use the space at the top of + * memory. + */ + for (i = 0; envp[i]; i++); environ = malloc(sizeof(char *) * (i + 1)); - for(i = 0; envp[i]; i++) + for (i = 0; envp[i]; i++) environ[i] = strdup(envp[i]); environ[i] = NULL; - + /* Save start and extent of argv for setproctitle. */ Argv = argv; - if(i > 0) + if (i > 0) LastArgv = envp[i - 1] + strlen(envp[i - 1]); else LastArgv = argv[argc - 1] + strlen(argv[argc - 1]); } -static void do_setproctitle(const char *cmdline) { - char buf[256], *p; - int i; - +static void +do_setproctitle(const char *cmdline) +{ + char buf[256], *p; + int i; + strncpy(buf, cmdline, 256); buf[255] = '\0'; i = strlen(buf); - if(i > LastArgv - Argv[0] - 2) { + if (i > LastArgv - Argv[0] - 2) { i = LastArgv - Argv[0] - 2; } strcpy(Argv[0], buf); p = &Argv[0][i]; - while(p < LastArgv) - *p++='\0'; + while (p < LastArgv) + *p++ = '\0'; Argv[1] = NULL; } -void setproctitle(const char* format, ...) { - char buf[256]; - va_list args; +void +setproctitle(const char *format,...) +{ + char buf[256]; + va_list args; va_start(args, format); - vsprintf(buf, format,args); + vsprintf(buf, format, args); do_setproctitle(buf); va_end(args); } diff --git a/pttbbs/mbbsd/bbcall.c b/pttbbs/mbbsd/bbcall.c index 29b39abc..2c369be4 100644 --- a/pttbbs/mbbsd/bbcall.c +++ b/pttbbs/mbbsd/bbcall.c @@ -1,4 +1,4 @@ -/* $Id: bbcall.c,v 1.4 2002/06/26 18:05:49 kcwu Exp $ */ +/* $Id: bbcall.c,v 1.5 2002/07/05 17:10:26 in2 Exp $ */ #include "bbs.h" #define SERVER_0941 "www.chips.com.tw" @@ -21,100 +21,106 @@ #define REFER_0947 "http://web1.hoyard.com.tw/freeway/freewayi.html" #define REFER_0945 "http://203.73.181.254/call.HTM" -static void pager_msg_encode(char *field, char *buf) { - char *cc = field; - unsigned char *p; - - for(p = (unsigned char *)buf; *p; p++) { - if((*p >= '0' && *p <= '9') || - (*p >= 'A' && *p <= 'Z') || - (*p >= 'a' && *p <= 'z') || - *p == ' ') - *cc++ = *p == ' ' ? '+' : (char)*p; - else { - sprintf(cc, "%%%02X", (int)*p); - cc += 3; - } +static void +pager_msg_encode(char *field, char *buf) +{ + char *cc = field; + unsigned char *p; + + for (p = (unsigned char *)buf; *p; p++) { + if ((*p >= '0' && *p <= '9') || + (*p >= 'A' && *p <= 'Z') || + (*p >= 'a' && *p <= 'z') || + *p == ' ') + *cc++ = *p == ' ' ? '+' : (char)*p; + else { + sprintf(cc, "%%%02X", (int)*p); + cc += 3; + } } *cc = 0; } -static void Gettime(int flag, int *Year, int *Month, int *Day, int *Hour, - int *Minute) { - char ans[5]; +static void +Gettime(int flag, int *Year, int *Month, int *Day, int *Hour, + int *Minute) +{ + char ans[5]; do { - getdata(10, 0, "年[20-]:", ans, 3, LCECHO); - *Year = atoi(ans); - } while(*Year < 00 || *Year > 02); + getdata(10, 0, "年[20-]:", ans, 3, LCECHO); + *Year = atoi(ans); + } while (*Year < 00 || *Year > 02); do { - getdata(10, 15, "月[1-12]:", ans, 3, LCECHO); - } while(!IsSNum(ans) || (*Month = atoi(ans)) > 12 || *Month < 1); + getdata(10, 15, "月[1-12]:", ans, 3, LCECHO); + } while (!IsSNum(ans) || (*Month = atoi(ans)) > 12 || *Month < 1); do { - getdata(10,30, "日[1-31]:", ans, 3, LCECHO); - } while(!IsSNum(ans) || (*Day = atoi(ans)) > 31 || *Day < 1); + getdata(10, 30, "日[1-31]:", ans, 3, LCECHO); + } while (!IsSNum(ans) || (*Day = atoi(ans)) > 31 || *Day < 1); do { - getdata(10,45, "時[0-23]:", ans, 3, LCECHO); - } while(!IsSNum(ans) || (*Hour = atoi(ans)) > 23 || *Hour < 0); + getdata(10, 45, "時[0-23]:", ans, 3, LCECHO); + } while (!IsSNum(ans) || (*Hour = atoi(ans)) > 23 || *Hour < 0); do { - getdata(10,60, "分[0-59]:", ans, 3, LCECHO); - } while(!IsSNum(ans) || (*Minute=atoi(ans))>59 || *Minute<0); - if(flag == 1) - *Year-=11; + getdata(10, 60, "分[0-59]:", ans, 3, LCECHO); + } while (!IsSNum(ans) || (*Minute = atoi(ans)) > 59 || *Minute < 0); + if (flag == 1) + *Year -= 11; } #define hpressanykey(a) {move(22, 0); prints(a); pressanykey();} -static int Connect(char *s, char *server) { - FILE *fp = fopen(BBSHOME "/log/bbcall.log", "a"); - int sockfd; - char result[2048]; +static int +Connect(char *s, char *server) +{ + FILE *fp = fopen(BBSHOME "/log/bbcall.log", "a"); + int sockfd; + char result[2048]; struct sockaddr_in serv_addr; struct hostent *hp; sockfd = socket(AF_INET, SOCK_STREAM, 0); - if(sockfd < 0) - return 0; + if (sockfd < 0) + return 0; memset((char *)&serv_addr, 0, sizeof(serv_addr)); serv_addr.sin_family = AF_INET; - if((hp = gethostbyname(server)) == NULL) - return 0; + if ((hp = gethostbyname(server)) == NULL) + return 0; memcpy(&serv_addr.sin_addr, hp->h_addr, hp->h_length); - if(!strcmp(server, SERVER_0941)) - serv_addr.sin_port = htons(9100); + if (!strcmp(server, SERVER_0941)) + serv_addr.sin_port = htons(9100); else - serv_addr.sin_port = htons(80); + serv_addr.sin_port = htons(80); - if(connect(sockfd, (struct sockaddr *) &serv_addr, sizeof serv_addr)) { - hpressanykey("無法與伺服器取得連結,傳呼失敗"); - return 0; + if (connect(sockfd, (struct sockaddr *) & serv_addr, sizeof serv_addr)) { + hpressanykey("無法與伺服器取得連結,傳呼失敗"); + return 0; } else { - mprints(20, 0, "\033[1;33m伺服器已經連接上,請稍後" - ".....................\033[m"); - refresh(); + mprints(20, 0, "\033[1;33m伺服器已經連接上,請稍後" + ".....................\033[m"); + refresh(); } write(sockfd, s, strlen(s)); shutdown(sockfd, 1); - while(read(sockfd, result, sizeof(result)) > 0) { - fprintf(fp, "%s\n", result); - fflush(fp); - if(strstr(result, "正確") || - strstr(result,"等待") || - strstr(result,"再度") || - strstr(result,"完 成 回 應") || - strstr(result, "預約中") || - strstr(result,"傳送中")) { - close(sockfd); - hpressanykey("順利送出傳呼"); - return 0; - } - memset(result, 0, sizeof(result)); + while (read(sockfd, result, sizeof(result)) > 0) { + fprintf(fp, "%s\n", result); + fflush(fp); + if (strstr(result, "正確") || + strstr(result, "等待") || + strstr(result, "再度") || + strstr(result, "完 成 回 應") || + strstr(result, "預約中") || + strstr(result, "傳送中")) { + close(sockfd); + hpressanykey("順利送出傳呼"); + return 0; + } + memset(result, 0, sizeof(result)); } fclose(fp); close(sockfd); @@ -255,3 +261,4 @@ int main_bbcall() { } return 0; } + diff --git a/pttbbs/mbbsd/bbs.c b/pttbbs/mbbsd/bbs.c index cc5fd86a..f3eaf143 100644 --- a/pttbbs/mbbsd/bbs.c +++ b/pttbbs/mbbsd/bbs.c @@ -1,246 +1,263 @@ -/* $Id: bbs.c,v 1.62 2002/06/29 14:55:34 ptt Exp $ */ +/* $Id: bbs.c,v 1.63 2002/07/05 17:10:26 in2 Exp $ */ #include "bbs.h" -static void mail_by_link(char* owner, char* title, char* path) { - char genbuf[200]; - fileheader_t mymail; - - sprintf(genbuf,BBSHOME"/home/%c/%s", cuser.userid[0], cuser.userid); +static void +mail_by_link(char *owner, char *title, char *path) +{ + char genbuf[200]; + fileheader_t mymail; + + sprintf(genbuf, BBSHOME "/home/%c/%s", cuser.userid[0], cuser.userid); stampfile(genbuf, &mymail); strcpy(mymail.owner, owner); - sprintf(mymail.title, title); + sprintf(mymail.title, title); unlink(genbuf); Link(path, genbuf); - sprintf(genbuf,BBSHOME"/home/%c/%s/.DIR",cuser.userid[0],cuser.userid); - - append_record(genbuf, &mymail, sizeof(mymail)); + sprintf(genbuf, BBSHOME "/home/%c/%s/.DIR", cuser.userid[0], cuser.userid); + + append_record(genbuf, &mymail, sizeof(mymail)); } -void anticrosspost() { - char buf[200]; - +void +anticrosspost() +{ + char buf[200]; + sprintf(buf, "\033[1;33;46m%s \033[37;45mcross post 文章 \033[37m %s\033[m", cuser.userid, ctime(&now)); log_file("etc/illegal_money", buf); - - post_violatelaw(cuser.userid, "Ptt系統警察", "Cross-post", "罰單處份"); + + post_violatelaw(cuser.userid, "Ptt系統警察", "Cross-post", "罰單處份"); cuser.userlevel |= PERM_VIOLATELAW; - cuser.vl_count ++; + cuser.vl_count++; mail_by_link("Ptt警察部隊", "Cross-Post罰單", BBSHOME "/etc/crosspost.txt"); passwd_update(usernum, &cuser); exit(0); } -/* Heat CharlieL*/ -int save_violatelaw() { - char buf[128], ok[3]; - - setutmpmode(VIOLATELAW); +/* Heat CharlieL */ +int +save_violatelaw() +{ + char buf[128], ok[3]; + + setutmpmode(VIOLATELAW); clear(); stand_title("繳罰單中心"); - if(!(cuser.userlevel & PERM_VIOLATELAW)) { + if (!(cuser.userlevel & PERM_VIOLATELAW)) { mprints(22, 0, "\033[1;31m你無聊啊? 你又沒有被開罰單~~\033[m"); pressanykey(); return 0; } - reload_money(); - if(cuser.money < (int)cuser.vl_count*1000) { + if (cuser.money < (int)cuser.vl_count * 1000) { sprintf(buf, "\033[1;31m這是你第 %d 次違反本站法規" "必須繳出 %d $Ptt ,你只有 %d 元, 錢不夠啦!!\033[m", - (int)cuser.vl_count, (int)cuser.vl_count * 1000, cuser.money); + (int)cuser.vl_count, (int)cuser.vl_count * 1000, cuser.money); mprints(22, 0, buf); pressanykey(); return 0; } - - move(5,0); + move(5, 0); prints("\033[1;37m你知道嗎? 因為你的違法 " "已經造成很多人的不便\033[m\n"); prints("\033[1;37m你是否確定以後不會再犯了?\033[m\n"); - - if(!getdata(10,0,"確定嗎?[y/n]:", ok, sizeof(ok), LCECHO) || - ok[0] == 'n' || ok[0] == 'N') { - mprints(22,0,"\033[1;31m等你想通了再來吧!! " + + if (!getdata(10, 0, "確定嗎?[y/n]:", ok, sizeof(ok), LCECHO) || + ok[0] == 'n' || ok[0] == 'N') { + mprints(22, 0, "\033[1;31m等你想通了再來吧!! " "我相信你不會知錯不改的~~~\033[m"); pressanykey(); return 0; } - sprintf(buf, "這是你第 %d 次違法 必須繳出 %d $Ptt", - cuser.vl_count, cuser.vl_count*1000); - mprints(11,0,buf); + cuser.vl_count, cuser.vl_count * 1000); + mprints(11, 0, buf); - if(!getdata(10, 0, "要付錢[y/n]:", ok, sizeof(ok), LCECHO) || - ok[0] == 'N' || ok[0] == 'n') { + if (!getdata(10, 0, "要付錢[y/n]:", ok, sizeof(ok), LCECHO) || + ok[0] == 'N' || ok[0] == 'n') { - mprints(22,0, "\033[1;31m 嗯 存夠錢 再來吧!!!\033[m"); + mprints(22, 0, "\033[1;31m 嗯 存夠錢 再來吧!!!\033[m"); pressanykey(); return 0; } - - demoney(-1000*cuser.vl_count); + demoney(-1000 * cuser.vl_count); cuser.userlevel &= (~PERM_VIOLATELAW); passwd_update(usernum, &cuser); return 0; } /* -void make_blist() { - CreateNameList(); - apply_boards(g_board_names); -} -*/ + * void make_blist() { CreateNameList(); apply_boards(g_board_names); } + */ -static time_t board_note_time; -static char *brd_title; +static time_t board_note_time; +static char *brd_title; -void set_board() { - boardheader_t *bp; +void +set_board() +{ + boardheader_t *bp; bp = getbcache(currbid); board_note_time = bp->bupdate; brd_title = bp->BM; - if(brd_title[0] <= ' ') + if (brd_title[0] <= ' ') brd_title = "徵求中"; sprintf(currBM, "板主:%s", brd_title); brd_title = ((bp->bvote != 2 && bp->bvote) ? "本看板進行投票中" : bp->title + 7); - currmode = (currmode & (MODE_DIRTY | MODE_MENU)) | MODE_STARTED ; - + currmode = (currmode & (MODE_DIRTY | MODE_MENU)) | MODE_STARTED; + if (HAS_PERM(PERM_ALLBOARD) || is_BM(bp->BM)) currmode = currmode | MODE_BOARD | MODE_POST; - else if(haspostperm(currboard)) - currmode |= MODE_POST; + else if (haspostperm(currboard)) + currmode |= MODE_POST; } -static void readtitle() { +static void +readtitle() +{ showtitle(currBM, brd_title); outs("[←]離開 [→]閱\讀 [^P]發表文章 [b]備忘錄 [d]刪除 [z]精華區 " - "[TAB]文摘 [h]elp\n\033[7m 編號 日 期 作 者 文 章 標 題" + "[TAB]文摘 [h]elp\n\033[7m 編號 日 期 作 者 文 章 標 題" " \033[m"); } -static void readdoent(int num, fileheader_t *ent) +static void +readdoent(int num, fileheader_t * ent) { - int type,uid; - char *mark, *title, color, special=0, isonline=0; - userinfo_t *uentp; - if(ent->recommend>9 || ent->recommend <0 ) ent->recommend=0; //Ptt:暫時 - type = brc_unread(ent->filename,brc_num,brc_list) ? '+' : ' '; - - if((currmode & MODE_BOARD) && (ent->filemode & FILE_DIGEST)) + int type, uid; + char *mark, *title, color, special = 0, isonline = 0; + userinfo_t *uentp; + if (ent->recommend > 9 || ent->recommend < 0) + ent->recommend = 0; +//Ptt:暫時 + type = brc_unread(ent->filename, brc_num, brc_list) ? '+' : ' '; + + if ((currmode & MODE_BOARD) && (ent->filemode & FILE_DIGEST)) type = (type == ' ') ? '*' : '#'; - else if(currmode & MODE_BOARD || HAS_PERM(PERM_LOGINOK)) { - if(ent->filemode & FILE_MARKED) + else if (currmode & MODE_BOARD || HAS_PERM(PERM_LOGINOK)) { + if (ent->filemode & FILE_MARKED) type = (type == ' ') ? 'm' : 'M'; - else if (TagNum && !Tagger(atoi(ent->filename + 2), 0, TAG_NIN)) - type = 'D'; + else if (TagNum && !Tagger(atoi(ent->filename + 2), 0, TAG_NIN)) + type = 'D'; else if (ent->filemode & FILE_SOLVED) type = 's'; } - title = subject(mark = ent->title); - if(title == mark) + if (title == mark) color = '1', mark = "□"; else color = '3', mark = "R:"; - - if(title[47]) - strcpy(title + 44, " …"); /* 把多餘的 string 砍掉 */ - - if(!strncmp(title,"[公告]",6)) special=1; - if(!strchr(ent->owner, '.') && (uid=searchuser(ent->owner)) && - (uentp = search_ulist(uid)) && isvisible(currutmp, uentp) ) - isonline=1; - - if(strncmp(currtitle, title, TTLEN)) - prints("%6d %c\033[1;32m%c\033[m%-6s\033[%dm%-13.12s\033[m%s " - "\033[1m%.*s\033[m%s\n", num, type, - ent->recommend?ent->recommend+'0':' ', - ent->date, - isonline, - ent->owner, mark, - special?6:0, title, special?title+6:title); + + if (title[47]) + strcpy(title + 44, " …"); /* 把多餘的 string 砍掉 */ + + if (!strncmp(title, "[公告]", 6)) + special = 1; + if (!strchr(ent->owner, '.') && (uid = searchuser(ent->owner)) && + (uentp = search_ulist(uid)) && isvisible(currutmp, uentp)) + isonline = 1; + + if (strncmp(currtitle, title, TTLEN)) + prints("%6d %c\033[1;32m%c\033[m%-6s\033[%dm%-13.12s\033[m%s " + "\033[1m%.*s\033[m%s\n", num, type, + ent->recommend ? ent->recommend + '0' : ' ', + ent->date, + isonline, + ent->owner, mark, + special ? 6 : 0, title, special ? title + 6 : title); else - prints("%6d %c\033[1;32m%c\033[m%-6s\033[%dm%-13.12s\033[1;3%cm%s " - "%s\033[m\n", num, type, - ent->recommend?ent->recommend+'0':' ', + prints("%6d %c\033[1;32m%c\033[m%-6s\033[%dm%-13.12s\033[1;3%cm%s " + "%s\033[m\n", num, type, + ent->recommend ? ent->recommend + '0' : ' ', ent->date, - isonline, - ent->owner, color, mark, - title); + isonline, + ent->owner, color, mark, + title); } -int cmpfilename(fileheader_t *fhdr) { +int +cmpfilename(fileheader_t * fhdr) +{ return (!strcmp(fhdr->filename, currfile)); } -int cmpfmode(fileheader_t *fhdr) { +int +cmpfmode(fileheader_t * fhdr) +{ return (fhdr->filemode & currfmode); } -int cmpfowner(fileheader_t *fhdr) { +int +cmpfowner(fileheader_t * fhdr) +{ return !strcasecmp(fhdr->owner, currowner); } -int whereami(int ent, fileheader_t *fhdr, char *direct) { - boardheader_t *bh, *p[32], *root; - int i,j; +int +whereami(int ent, fileheader_t * fhdr, char *direct) +{ + boardheader_t *bh, *p[32], *root; + int i, j; - if(!currutmp->brc_id) return 0; + if (!currutmp->brc_id) + return 0; - move(1,0); + move(1, 0); clrtobot(); - bh=getbcache(currutmp->brc_id); - root=getbcache(1); - p[0]=bh; - for(i=0;i<31 && p[i]->parent!=root && p[i]->parent;i++) - p[i+1]=p[i]->parent; - j=i; - prints("我在哪?\n%-40.40s %.13s\n", p[j]->title+7, p[j]->BM); - for(j--;j>=0;j--) - prints("%*s %-13.13s %-37.37s %.13s\n", (i-j)*2, "", - p[j]->brdname, p[j]->title, - p[j]->BM); + bh = getbcache(currutmp->brc_id); + root = getbcache(1); + p[0] = bh; + for (i = 0; i < 31 && p[i]->parent != root && p[i]->parent; i++) + p[i + 1] = p[i]->parent; + j = i; + prints("我在哪?\n%-40.40s %.13s\n", p[j]->title + 7, p[j]->BM); + for (j--; j >= 0; j--) + prints("%*s %-13.13s %-37.37s %.13s\n", (i - j) * 2, "", + p[j]->brdname, p[j]->title, + p[j]->BM); pressanykey(); return FULLUPDATE; } -static int substitute_check(fileheader_t *fhdr) +static int +substitute_check(fileheader_t * fhdr) { - fileheader_t hdr; - char genbuf[100]; - int num=0; + fileheader_t hdr; + char genbuf[100]; + int num = 0; /* rocker.011018: 串接模式用reference增進效率 */ - if ((currmode & MODE_SELECT) && (fhdr->money & FHR_REFERENCE)) - { - num = fhdr->money & ~FHR_REFERENCE; - setbdir(genbuf, currboard); - get_record(genbuf, &hdr, sizeof (hdr), num); + if ((currmode & MODE_SELECT) && (fhdr->money & FHR_REFERENCE)) { + num = fhdr->money & ~FHR_REFERENCE; + setbdir(genbuf, currboard); + get_record(genbuf, &hdr, sizeof(hdr), num); - /* 再這裡要check一下原來的dir裡面是不是有被人動過... */ - if (strcmp (hdr.filename, fhdr->filename)) - num = getindex(genbuf, fhdr->filename, sizeof(fileheader_t)); + /* 再這裡要check一下原來的dir裡面是不是有被人動過... */ + if (strcmp(hdr.filename, fhdr->filename)) + num = getindex(genbuf, fhdr->filename, sizeof(fileheader_t)); - substitute_record(genbuf, fhdr, sizeof(*fhdr), num); + substitute_record(genbuf, fhdr, sizeof(*fhdr), num); } return num; } -static int do_select(int ent, fileheader_t *fhdr, char *direct) { - char bname[20]; - char bpath[60]; - boardheader_t *bh; - struct stat st; - int i; +static int +do_select(int ent, fileheader_t * fhdr, char *direct) +{ + char bname[20]; + char bpath[60]; + boardheader_t *bh; + struct stat st; + int i; move(0, 0); clrtoeol(); @@ -249,21 +266,22 @@ static int do_select(int ent, fileheader_t *fhdr, char *direct) { completeboard_compar, completeboard_permission, completeboard_getname); - if(bname[0]=='\0' || !(i = getbnum(bname))) - return FULLUPDATE; + if (bname[0] == '\0' || !(i = getbnum(bname))) + return FULLUPDATE; bh = getbcache(i); - if(!Ben_Perm(bh)) return FULLUPDATE; + if (!Ben_Perm(bh)) + return FULLUPDATE; strcpy(bname, bh->brdname); - currbid=i; - + currbid = i; + setbpath(bpath, bname); - if((*bname == '\0') || (stat(bpath, &st) == -1)) { + if ((*bname == '\0') || (stat(bpath, &st) == -1)) { move(2, 0); clrtoeol(); outs(err_bid); return FULLUPDATE; } - setutmpbid(currbid); + setutmpbid(currbid); brc_initial(bname); set_board(); @@ -277,53 +295,56 @@ static int do_select(int ent, fileheader_t *fhdr, char *direct) { /* ----------------------------------------------------- */ /* 改良 innbbsd 轉出信件、連線砍信之處理程序 */ /* ----------------------------------------------------- */ -void outgo_post(fileheader_t *fh, char *board) { - FILE *foo; - - if((foo = fopen("innd/out.bntp", "a"))) { +void +outgo_post(fileheader_t * fh, char *board) +{ + FILE *foo; + + if ((foo = fopen("innd/out.bntp", "a"))) { fprintf(foo, "%s\t%s\t%s\t%s\t%s\n", board, fh->filename, cuser.userid, cuser.username, fh->title); fclose(foo); } } -static void cancelpost(fileheader_t *fh, int by_BM) { - FILE *fin, *fout; - char *ptr, *brd; - fileheader_t postfile; - char genbuf[200]; - char nick[STRLEN], fn1[STRLEN], fn2[STRLEN]; - +static void +cancelpost(fileheader_t * fh, int by_BM) +{ + FILE *fin, *fout; + char *ptr, *brd; + fileheader_t postfile; + char genbuf[200]; + char nick[STRLEN], fn1[STRLEN], fn2[STRLEN]; + setbfile(fn1, currboard, fh->filename); - if((fin = fopen(fn1, "r"))) { + if ((fin = fopen(fn1, "r"))) { brd = by_BM ? "deleted" : "junk"; setbpath(fn2, brd); stampfile(fn2, &postfile); memcpy(postfile.owner, fh->owner, IDLEN + TTLEN + 10); - nick[0] = '\0'; - while(fgets(genbuf, sizeof(genbuf), fin)) { - if (!strncmp(genbuf, str_author1, LEN_AUTHOR1) || - !strncmp(genbuf, str_author2, LEN_AUTHOR2)) { - if((ptr = strrchr(genbuf, ')'))) - *ptr = '\0'; - if((ptr = (char *)strchr(genbuf, '('))) - strcpy(nick, ptr + 1); - break; - } + nick[0] = '\0'; + while (fgets(genbuf, sizeof(genbuf), fin)) { + if (!strncmp(genbuf, str_author1, LEN_AUTHOR1) || + !strncmp(genbuf, str_author2, LEN_AUTHOR2)) { + if ((ptr = strrchr(genbuf, ')'))) + *ptr = '\0'; + if ((ptr = (char *)strchr(genbuf, '('))) + strcpy(nick, ptr + 1); + break; } + } - if((fout = fopen("innd/cancel.bntp", "a"))) { - fprintf(fout, "%s\t%s\t%s\t%s\t%s\n", currboard, fh->filename, - cuser.userid, nick, fh->title); - fclose(fout); - } - + if ((fout = fopen("innd/cancel.bntp", "a"))) { + fprintf(fout, "%s\t%s\t%s\t%s\t%s\n", currboard, fh->filename, + cuser.userid, nick, fh->title); + fclose(fout); + } fclose(fin); Rename(fn1, fn2); setbdir(genbuf, brd); - setbtotal(getbnum(brd)); + setbtotal(getbnum(brd)); append_record(genbuf, &postfile, sizeof(postfile)); } } @@ -331,28 +352,32 @@ static void cancelpost(fileheader_t *fh, int by_BM) { /* ----------------------------------------------------- */ /* 發表、回應、編輯、轉錄文章 */ /* ----------------------------------------------------- */ -void do_reply_title(int row, char *title) { - char genbuf[200]; - char genbuf2[4]; +void +do_reply_title(int row, char *title) +{ + char genbuf[200]; + char genbuf2[4]; - if(strncasecmp(title, str_reply, 4)) + if (strncasecmp(title, str_reply, 4)) sprintf(save_title, "Re: %s", title); else strcpy(save_title, title); save_title[TTLEN - 1] = '\0'; sprintf(genbuf, "採用原標題《%.60s》嗎?[Y] ", save_title); getdata(row, 0, genbuf, genbuf2, 4, LCECHO); - if(genbuf2[0] == 'n' || genbuf2[0] == 'N') + if (genbuf2[0] == 'n' || genbuf2[0] == 'N') getdata(++row, 0, "標題:", save_title, TTLEN, DOECHO); } -static void do_unanonymous_post(char* fpath) { - fileheader_t mhdr; - char title[128]; - char genbuf[200]; +static void +do_unanonymous_post(char *fpath) +{ + fileheader_t mhdr; + char title[128]; + char genbuf[200]; setbpath(genbuf, "UnAnonymous"); - if(dashd(genbuf)) { + if (dashd(genbuf)) { stampfile(genbuf, &mhdr); unlink(genbuf); Link(fpath, genbuf); @@ -365,77 +390,77 @@ static void do_unanonymous_post(char* fpath) { } #ifdef NO_WATER_POST -static time_t last_post_time = 0; -static time_t water_counts = 0; +static time_t last_post_time = 0; +static time_t water_counts = 0; #endif -static int do_general() { - fileheader_t postfile; - char fpath[80], buf[80]; - int aborted, defanony, ifuseanony; - char genbuf[200],*owner, - *ctype[]={"問題","建議","討論","心得","閒聊","公告","情報"}; - boardheader_t *bp; - int islocal; - +static int +do_general() +{ + fileheader_t postfile; + char fpath[80], buf[80]; + int aborted, defanony, ifuseanony; + char genbuf[200], *owner, *ctype[] = {"問題", "建議", "討論", "心得", "閒聊", "公告", "情報"}; + boardheader_t *bp; + int islocal; + ifuseanony = 0; bp = getbcache(currbid); - + clear(); - if(!(currmode & MODE_POST)) { + if (!(currmode & MODE_POST)) { move(5, 10); outs("對不起,您目前無法在此發表文章!"); pressanykey(); return FULLUPDATE; } - #ifdef NO_WATER_POST /* 三分鐘內最多發表五篇文章 */ - if(currutmp->lastact - last_post_time < 60 * 3) { - if(water_counts >= 5) { + if (currutmp->lastact - last_post_time < 60 * 3) { + if (water_counts >= 5) { move(5, 10); - outs("對不起,您的文章太水囉,待會再post吧!小秘訣:可用'X'推薦文章"); + outs("對不起,您的文章太水囉,待會再post吧!小秘訣:可用'X'推薦文章"); pressanykey(); return FULLUPDATE; - } + } } else { last_post_time = currutmp->lastact; water_counts = 0; } #endif - - setbfile(genbuf, currboard, FN_POST_NOTE ); - - if(more(genbuf,NA) == -1) - more("etc/"FN_POST_NOTE , NA); - - move(19,0); + + setbfile(genbuf, currboard, FN_POST_NOTE); + + if (more(genbuf, NA) == -1) + more("etc/" FN_POST_NOTE, NA); + + move(19, 0); prints("發表文章於【\033[33m %s\033[m 】 \033[32m%s\033[m 看板\n\n", currboard, bp->title + 7); - - if(quote_file[0]) + + if (quote_file[0]) do_reply_title(20, currtitle); else { - getdata(21, 0, - "種類:1.問題 2.建議 3.討論 4.心得 5.閒聊 6.公告 7.情報 (1-7或不選)", - save_title,3,LCECHO); - local_article = save_title[0]-'1'; - if(local_article>=0 && local_article<=6) - sprintf(save_title,"[%s] ",ctype[local_article]); - else - save_title[0]='\0'; + getdata(21, 0, + "種類:1.問題 2.建議 3.討論 4.心得 5.閒聊 6.公告 7.情報 (1-7或不選)", + save_title, 3, LCECHO); + local_article = save_title[0] - '1'; + if (local_article >= 0 && local_article <= 6) + sprintf(save_title, "[%s] ", ctype[local_article]); + else + save_title[0] = '\0'; getdata_buf(22, 0, "標題:", save_title, TTLEN, DOECHO); - strip_ansi(save_title,save_title,0); + strip_ansi(save_title, save_title, 0); } - if(save_title[0] == '\0') + if (save_title[0] == '\0') return FULLUPDATE; - + curredit &= ~EDIT_MAIL; curredit &= ~EDIT_ITEM; setutmpmode(POSTING); - + /* 未具備 Internet 權限者,只能在站內發表文章 */ - if(HAS_PERM(PERM_INTERNET)) + if (HAS_PERM(PERM_INTERNET)) local_article = 0; else local_article = 1; @@ -443,26 +468,26 @@ static int do_general() { /* build filename */ setbpath(fpath, currboard); stampfile(fpath, &postfile); - + aborted = vedit(fpath, YEA, &islocal); - if(aborted == -1) { + if (aborted == -1) { unlink(fpath); pressanykey(); return FULLUPDATE; } - water_counts++; /* po成功 */ + water_counts++; /* po成功 */ /* set owner to Anonymous , for Anonymous board */ #ifdef HAVE_ANONYMOUS /* Ptt and Jaky */ - defanony=currbrdattr & BRD_DEFAULTANONYMOUS; - if((currbrdattr & BRD_ANONYMOUS) && - ((strcmp(real_name,"r") && defanony) || (real_name[0] && !defanony)) + defanony = currbrdattr & BRD_DEFAULTANONYMOUS; + if ((currbrdattr & BRD_ANONYMOUS) && + ((strcmp(real_name, "r") && defanony) || (real_name[0] && !defanony)) ) { - strcat(real_name,"."); + strcat(real_name, "."); owner = real_name; - ifuseanony=1; + ifuseanony = 1; } else owner = cuser.userid; #else @@ -473,68 +498,68 @@ static int do_general() { postfile.money = aborted; strcpy(postfile.owner, owner); strcpy(postfile.title, save_title); - if(islocal) /* local save */ + if (islocal) /* local save */ postfile.filemode = FILE_LOCAL; - + setbdir(buf, currboard); - if(append_record(buf, &postfile, sizeof(postfile)) != -1) { + if (append_record(buf, &postfile, sizeof(postfile)) != -1) { setbtotal(currbid); - if(currmode & MODE_SELECT) - append_record(currdirect,&postfile,sizeof(postfile)); - if(!islocal && !(bp->brdattr & BRD_NOTRAN)) + if (currmode & MODE_SELECT) + append_record(currdirect, &postfile, sizeof(postfile)); + if (!islocal && !(bp->brdattr & BRD_NOTRAN)) outgo_post(&postfile, currboard); brc_addlist(postfile.filename); - if(!(currbrdattr & BRD_HIDE) && - (!bp->level || (currbrdattr & BRD_POSTMASK))) { + if (!(currbrdattr & BRD_HIDE) && + (!bp->level || (currbrdattr & BRD_POSTMASK))) { setbpath(genbuf, ALLPOST); stampfile(genbuf, &postfile); unlink(genbuf); /* jochang: boards may spread across many disk */ - /* link doesn't work across device, - Link doesn't work if we have same-time-across-device posts, - we try symlink now */ + /* + * link doesn't work across device, Link doesn't work if we have + * same-time-across-device posts, we try symlink now + */ { - /* we need absolute path for symlink */ - char abspath[256]=BBSHOME"/"; - strcat(abspath,fpath); - symlink(abspath,genbuf); + /* we need absolute path for symlink */ + char abspath[256] = BBSHOME "/"; + strcat(abspath, fpath); + symlink(abspath, genbuf); } strcpy(postfile.owner, owner); strcpy(postfile.title, save_title); postfile.filemode = FILE_LOCAL; setbdir(genbuf, ALLPOST); - if(append_record(genbuf, &postfile, sizeof(postfile)) != -1) { + if (append_record(genbuf, &postfile, sizeof(postfile)) != -1) { setbtotal(getbnum(ALLPOST)); } } - outs("順利貼出佈告,"); - + #ifdef MAX_POST_MONEY aborted = (aborted > MAX_POST_MONEY) ? MAX_POST_MONEY : aborted; #endif - if(strcmp(currboard, "Test") && !ifuseanony) { + if (strcmp(currboard, "Test") && !ifuseanony) { prints("這是您的第 %d 篇文章。 稿酬 %d 銀。", - ++cuser.numposts, aborted ); + ++cuser.numposts, aborted); demoney(aborted); - passwd_update(usernum, &cuser); /* post 數 */ + passwd_update(usernum, &cuser); /* post 數 */ } else outs("測試信件不列入紀錄,敬請包涵。"); - + /* 回應到原作者信箱 */ - - if(curredit & EDIT_BOTH) { - char *str, *msg = "回應至作者信箱"; - if((str = strchr(quote_user, '.'))) { - if( + if (curredit & EDIT_BOTH) { + char *str, *msg = "回應至作者信箱"; + + if ((str = strchr(quote_user, '.'))) { + if ( #ifndef USE_BSMTP bbs_sendmail(fpath, save_title, str + 1) #else - bsmtp(fpath, save_title, str + 1 ,0) + bsmtp(fpath, save_title, str + 1, 0) #endif < 0) msg = "作者無法收信"; @@ -546,38 +571,42 @@ static int do_general() { strcpy(postfile.owner, cuser.userid); strcpy(postfile.title, save_title); - postfile.filemode = FILE_BOTH;/* both-reply flag */ + postfile.filemode = FILE_BOTH; /* both-reply flag */ sethomedir(genbuf, quote_user); - if(append_record(genbuf, &postfile, sizeof(postfile)) == -1) + if (append_record(genbuf, &postfile, sizeof(postfile)) == -1) msg = err_uid; } outs(msg); curredit ^= EDIT_BOTH; } - if(currbrdattr & BRD_ANONYMOUS) + if (currbrdattr & BRD_ANONYMOUS) do_unanonymous_post(fpath); } pressanykey(); return FULLUPDATE; } -int do_post() { - boardheader_t *bp; +int +do_post() +{ + boardheader_t *bp; bp = getbcache(currbid); - if(bp->brdattr & BRD_VOTEBOARD) - return do_voteboard(); - else if(!(bp->brdattr & BRD_GROUPBOARD)) - return do_general(); + if (bp->brdattr & BRD_VOTEBOARD) + return do_voteboard(); + else if (!(bp->brdattr & BRD_GROUPBOARD)) + return do_general(); touchdircache(currbid); return 0; } -static void do_generalboardreply(fileheader_t *fhdr){ - char genbuf[200]; +static void +do_generalboardreply(fileheader_t * fhdr) +{ + char genbuf[200]; getdata(b_lines - 1, 0, "▲ 回應至 (F)看板 (M)作者信箱 (B)二者皆是 (Q)取消?[F] ", genbuf, 3, LCECHO); - switch(genbuf[0]) { + switch (genbuf[0]) { case 'm': mail_reply(0, fhdr, 0); case 'q': @@ -593,14 +622,16 @@ static void do_generalboardreply(fileheader_t *fhdr){ *quote_file = 0; } -int getindex(char *fpath, char *fname, int size) { - int fd, now=0; - fileheader_t fhdr; - - if((fd = open(fpath, O_RDONLY, 0)) != -1) { - while((read(fd, &fhdr, size) == size)) { +int +getindex(char *fpath, char *fname, int size) +{ + int fd, now = 0; + fileheader_t fhdr; + + if ((fd = open(fpath, O_RDONLY, 0)) != -1) { + while ((read(fd, &fhdr, size) == size)) { now++; - if(!strcmp(fhdr.filename,fname)) { + if (!strcmp(fhdr.filename, fname)) { close(fd); return now; } @@ -610,42 +641,49 @@ int getindex(char *fpath, char *fname, int size) { return 0; } -int invalid_brdname(char *brd) { - register char ch; - +int +invalid_brdname(char *brd) +{ + register char ch; + ch = *brd++; - if(not_alnum(ch)) + if (not_alnum(ch)) return 1; - while((ch = *brd++)) { - if(not_alnum(ch) && ch != '_' && ch != '-' && ch != '.') + while ((ch = *brd++)) { + if (not_alnum(ch) && ch != '_' && ch != '-' && ch != '.') return 1; } return 0; } -static int b_call_in(int ent, fileheader_t *fhdr, char *direct) +static int +b_call_in(int ent, fileheader_t * fhdr, char *direct) { - userinfo_t *u = search_ulist(searchuser(fhdr->owner)); - if( u ){ - int fri_stat; + userinfo_t *u = search_ulist(searchuser(fhdr->owner)); + if (u) { + int fri_stat; fri_stat = friend_stat(currutmp, u); - if( isvisible_stat(currutmp, u, fri_stat) && call_in(u, fri_stat) ) - return FULLUPDATE; + if (isvisible_stat(currutmp, u, fri_stat) && call_in(u, fri_stat)) + return FULLUPDATE; } return DONOTHING; } -static void do_reply(fileheader_t *fhdr) { - boardheader_t *bp; +static void +do_reply(fileheader_t * fhdr) +{ + boardheader_t *bp; bp = getbcache(currbid); if (bp->brdattr & BRD_VOTEBOARD) - do_voteboardreply(fhdr); + do_voteboardreply(fhdr); else - do_generalboardreply(fhdr); + do_generalboardreply(fhdr); } -static int reply_post(int ent, fileheader_t *fhdr, char *direct) { - if(!(currmode & MODE_POST)) +static int +reply_post(int ent, fileheader_t * fhdr, char *direct) +{ + if (!(currmode & MODE_POST)) return DONOTHING; setdirpath(quote_file, direct, fhdr->filename); @@ -654,28 +692,30 @@ static int reply_post(int ent, fileheader_t *fhdr, char *direct) { return FULLUPDATE; } -static int edit_post(int ent, fileheader_t *fhdr, char *direct) { - char fpath[80], fpath0[80]; - char genbuf[200]; - fileheader_t postfile; - boardheader_t *bp; +static int +edit_post(int ent, fileheader_t * fhdr, char *direct) +{ + char fpath[80], fpath0[80]; + char genbuf[200]; + fileheader_t postfile; + boardheader_t *bp; bp = getbcache(currbid); - if ( strcmp(bp->brdname, "Security" ) == 0 ) + if (strcmp(bp->brdname, "Security") == 0) return DONOTHING; if (!HAS_PERM(PERM_SYSOP) && (bp->brdattr & BRD_VOTEBOARD)) return DONOTHING; - if ((!HAS_PERM(PERM_SYSOP)) && - strcmp(fhdr->owner, cuser.userid)) + if ((!HAS_PERM(PERM_SYSOP)) && + strcmp(fhdr->owner, cuser.userid)) return DONOTHING; - setutmpmode(REEDIT); + setutmpmode(REEDIT); setdirpath(genbuf, direct, fhdr->filename); local_article = fhdr->filemode & FILE_LOCAL; strcpy(save_title, fhdr->title); -/* rocker.011018: 這裡是不是該檢查一下修改文章後的money和原有的比較? */ - if(vedit(genbuf, 0, NULL) != -1) { + /* rocker.011018: 這裡是不是該檢查一下修改文章後的money和原有的比較? */ + if (vedit(genbuf, 0, NULL) != -1) { setbpath(fpath, currboard); stampfile(fpath, &postfile); unlink(fpath); @@ -683,45 +723,44 @@ static int edit_post(int ent, fileheader_t *fhdr, char *direct) { Rename(fpath0, fpath); -/* rocker.011018: fix 串接模式改文章後文章就不見的bug */ - if ((currmode & MODE_SELECT) && (fhdr->money & FHR_REFERENCE)) - { - fileheader_t hdr; - int num; - - num = fhdr->money & ~FHR_REFERENCE; - setbdir(fpath0, currboard); - get_record(fpath0, &hdr, sizeof (hdr), num); - - /* 再這裡要check一下原來的dir裡面是不是有被人動過... */ - if (!strcmp (hdr.filename, fhdr->filename)) - { - strcpy(hdr.filename, postfile.filename); - strcpy(hdr.title, save_title); - substitute_record(fpath0, &hdr, sizeof(hdr), num); - } - } + /* rocker.011018: fix 串接模式改文章後文章就不見的bug */ + if ((currmode & MODE_SELECT) && (fhdr->money & FHR_REFERENCE)) { + fileheader_t hdr; + int num; + + num = fhdr->money & ~FHR_REFERENCE; + setbdir(fpath0, currboard); + get_record(fpath0, &hdr, sizeof(hdr), num); + /* 再這裡要check一下原來的dir裡面是不是有被人動過... */ + if (!strcmp(hdr.filename, fhdr->filename)) { + strcpy(hdr.filename, postfile.filename); + strcpy(hdr.title, save_title); + substitute_record(fpath0, &hdr, sizeof(hdr), num); + } + } strcpy(fhdr->filename, postfile.filename); strcpy(fhdr->title, save_title); brc_addlist(postfile.filename); substitute_record(direct, fhdr, sizeof(*fhdr), ent); -/* rocker.011018: 順便更新一下cache */ - touchdircache(currbid); + /* rocker.011018: 順便更新一下cache */ + touchdircache(currbid); } return FULLUPDATE; } #define UPDATE_USEREC (currmode |= MODE_DIRTY) -static int cross_post(int ent, fileheader_t *fhdr, char *direct) { - char xboard[20], fname[80], xfpath[80], xtitle[80], inputbuf[10]; - fileheader_t xfile; - FILE *xptr; - int author = 0; - char genbuf[200]; - char genbuf2[4]; - boardheader_t *bp; +static int +cross_post(int ent, fileheader_t * fhdr, char *direct) +{ + char xboard[20], fname[80], xfpath[80], xtitle[80], inputbuf[10]; + fileheader_t xfile; + FILE *xptr; + int author = 0; + char genbuf[200]; + char genbuf2[4]; + boardheader_t *bp; move(2, 0); clrtoeol(); move(3, 0); @@ -735,13 +774,13 @@ static int cross_post(int ent, fileheader_t *fhdr, char *direct) { completeboard_compar, completeboard_permission, completeboard_getname); - if(*xboard == '\0' || !haspostperm(xboard)) + if (*xboard == '\0' || !haspostperm(xboard)) return FULLUPDATE; - - if((ent = str_checksum(fhdr->title)) != 0 && - ent == postrecord.checksum[0]) { + + if ((ent = str_checksum(fhdr->title)) != 0 && + ent == postrecord.checksum[0]) { /* 檢查 cross post 次數 */ - if(postrecord.times++ > MAX_CROSSNUM) + if (postrecord.times++ > MAX_CROSSNUM) anticrosspost(); } else { postrecord.times = 0; @@ -749,1196 +788,1177 @@ static int cross_post(int ent, fileheader_t *fhdr, char *direct) { } ent = 1; - if(HAS_PERM(PERM_SYSOP) || !strcmp(fhdr->owner, cuser.userid)) { + if (HAS_PERM(PERM_SYSOP) || !strcmp(fhdr->owner, cuser.userid)) { getdata(2, 0, "(1)原文轉載 (2)舊轉錄格式?[1] ", genbuf, 3, DOECHO); - if(genbuf[0] != '2') { + if (genbuf[0] != '2') { ent = 0; getdata(2, 0, "保留原作者名稱嗎?[Y] ", inputbuf, 3, DOECHO); - if (inputbuf[0] != 'n' && inputbuf[0] != 'N') author = 1; + if (inputbuf[0] != 'n' && inputbuf[0] != 'N') + author = 1; } } - - if(ent) + if (ent) sprintf(xtitle, "[轉錄]%.66s", fhdr->title); else strcpy(xtitle, fhdr->title); sprintf(genbuf, "採用原標題《%.60s》嗎?[Y] ", xtitle); getdata(2, 0, genbuf, genbuf2, 4, LCECHO); - if(genbuf2[0] == 'n' || genbuf2[0] == 'N') { - if(getdata_str(2, 0, "標題:", genbuf, TTLEN, DOECHO,xtitle)) + if (genbuf2[0] == 'n' || genbuf2[0] == 'N') { + if (getdata_str(2, 0, "標題:", genbuf, TTLEN, DOECHO, xtitle)) strcpy(xtitle, genbuf); } - getdata(2, 0, "(S)存檔 (L)站內 (Q)取消?[Q] ", genbuf, 3, LCECHO); - if(genbuf[0] == 'l' || genbuf[0] == 's') { - int currmode0 = currmode; + if (genbuf[0] == 'l' || genbuf[0] == 's') { + int currmode0 = currmode; currmode = 0; setbpath(xfpath, xboard); stampfile(xfpath, &xfile); - if(author) + if (author) strcpy(xfile.owner, fhdr->owner); else strcpy(xfile.owner, cuser.userid); strcpy(xfile.title, xtitle); - if(genbuf[0] == 'l') { + if (genbuf[0] == 'l') { xfile.filemode = FILE_LOCAL; - } - + } setbfile(fname, currboard, fhdr->filename); -// if(ent) { - xptr = fopen(xfpath, "w"); - - strcpy(save_title, xfile.title); - strcpy(xfpath, currboard); - strcpy(currboard, xboard); - write_header(xptr); - strcpy(currboard, xfpath); - - fprintf(xptr, "※ [本文轉錄自 %s 看板]\n\n", currboard); - - b_suckinfile(xptr, fname); - addsignature(xptr,0); - fclose(xptr); -/* Cross fs有問題 - } else { - unlink(xfpath); - link(fname, xfpath); - } -*/ - setbdir(fname, xboard); - append_record(fname, &xfile, sizeof(xfile)); - bp = getbcache(getbnum(xboard)); - if(!xfile.filemode && !(bp->brdattr && BRD_NOTRAN)) - outgo_post(&xfile, xboard); - setbtotal(getbnum(xboard)); - cuser.numposts++; - UPDATE_USEREC; - outs("文章轉錄完成"); - pressanykey(); - currmode = currmode0; - } - return FULLUPDATE; -} - -static int read_post(int ent, fileheader_t *fhdr, char *direct) { - char genbuf[200]; - int more_result; - - if(fhdr->owner[0] == '-') - return DONOTHING; - - setdirpath(genbuf, direct, fhdr->filename); - - if((more_result = more(genbuf, YEA)) == -1) - return DONOTHING; - - brc_addlist(fhdr->filename); - strncpy(currtitle, subject(fhdr->title), TTLEN); - strncpy(currowner, subject(fhdr->owner), IDLEN + 2); - - switch (more_result) { - case 1: - return READ_PREV; - case 2: - return RELATE_PREV; - case 3: - return READ_NEXT; - case 4: - return RELATE_NEXT; - case 5: - return RELATE_FIRST; - case 6: - return FULLUPDATE; - case 7: - case 8: - if((currmode & MODE_POST)) { - strcpy(quote_file, genbuf); - do_reply(fhdr); - *quote_file = 0; + //if (ent) { + xptr = fopen(xfpath, "w"); + + strcpy(save_title, xfile.title); + strcpy(xfpath, currboard); + strcpy(currboard, xboard); + write_header(xptr); + strcpy(currboard, xfpath); + + fprintf(xptr, "※ [本文轉錄自 %s 看板]\n\n", currboard); + + b_suckinfile(xptr, fname); + addsignature(xptr, 0); + fclose(xptr); + /* + * Cross fs有問題 } else { unlink(xfpath); link(fname, xfpath); } + */ + setbdir(fname, xboard); + append_record(fname, &xfile, sizeof(xfile)); + bp = getbcache(getbnum(xboard)); + if (!xfile.filemode && !(bp->brdattr && BRD_NOTRAN)) + outgo_post(&xfile, xboard); + setbtotal(getbnum(xboard)); + cuser.numposts++; + UPDATE_USEREC; + outs("文章轉錄完成"); + pressanykey(); + currmode = currmode0; } return FULLUPDATE; - case 9: - return 'A'; - case 10: - return 'a'; - case 11: - return '/'; - case 12: - return '?'; } + static int read_post(int ent, fileheader_t * fhdr, char *direct){ + char genbuf[200]; + int more_result; + + if (fhdr->owner[0] == '-') + return DONOTHING; + + setdirpath(genbuf, direct, fhdr->filename); + + if ((more_result = more(genbuf, YEA)) == -1) + return DONOTHING; + + brc_addlist(fhdr->filename); + strncpy(currtitle, subject(fhdr->title), TTLEN); + strncpy(currowner, subject(fhdr->owner), IDLEN + 2); + + switch (more_result) { + case 1: + return READ_PREV; + case 2: + return RELATE_PREV; + case 3: + return READ_NEXT; + case 4: + return RELATE_NEXT; + case 5: + return RELATE_FIRST; + case 6: + return FULLUPDATE; + case 7: + case 8: + if ((currmode & MODE_POST)) { + strcpy(quote_file, genbuf); + do_reply(fhdr); + *quote_file = 0; + } + return FULLUPDATE; + case 9: + return 'A'; + case 10: + return 'a'; + case 11: + return '/'; + case 12: + return '?'; + } - outmsg("\033[34;46m 閱\讀文章 \033[31;47m (R/Y)\033[30m回信 \033[31m" - "(=[]<>)\033[30m相關主題 \033[31m(↑↓)\033[30m上下封 \033[31m(←)" - "\033[30m離開 \033[m"); + outmsg("\033[34;46m 閱\讀文章 \033[31;47m (R/Y)\033[30m回信 \033[31m" + "(=[]<>)\033[30m相關主題 \033[31m(↑↓)\033[30m上下封 \033[31m(←)" + "\033[30m離開 \033[m"); - switch(egetch()) { - case 'q': - case 'Q': - case KEY_LEFT: - break; + switch (egetch()) { + case 'q': + case 'Q': + case KEY_LEFT: + break; - case ' ': - case KEY_RIGHT: - case KEY_DOWN: - case KEY_PGDN: - case 'n': - case Ctrl('N'): - return READ_NEXT; + case ' ': + case KEY_RIGHT: + case KEY_DOWN: + case KEY_PGDN: + case 'n': + case Ctrl('N'): + return READ_NEXT; - case KEY_UP: - case 'p': - case Ctrl('P'): - case KEY_PGUP: - return READ_PREV; + case KEY_UP: + case 'p': + case Ctrl('P'): + case KEY_PGUP: + return READ_PREV; - case '=': - return RELATE_FIRST; + case '=': + return RELATE_FIRST; - case ']': - case 't': - return RELATE_NEXT; + case ']': + case 't': + return RELATE_NEXT; - case '[': - return RELATE_PREV; + case '[': + return RELATE_PREV; - case '.': - case '>': - return THREAD_NEXT; + case '.': + case '>': + return THREAD_NEXT; - case ',': - case '<': - return THREAD_PREV; + case ',': + case '<': + return THREAD_PREV; - case Ctrl('C'): - cal(); - return FULLUPDATE; - break; + case Ctrl('C'): + cal(); + return FULLUPDATE; + break; - case Ctrl('I'): - t_idle(); - return FULLUPDATE; - case 'y': - case 'r': - case 'R': - case 'Y': - if((currmode & MODE_POST)) { - strcpy(quote_file, genbuf); - do_reply(fhdr); - *quote_file = 0; + case Ctrl('I'): + t_idle(); + return FULLUPDATE; + case 'y': + case 'r': + case 'R': + case 'Y': + if ((currmode & MODE_POST)) { + strcpy(quote_file, genbuf); + do_reply(fhdr); + *quote_file = 0; + } } + return FULLUPDATE; } - return FULLUPDATE; -} -/* ----------------------------------------------------- */ -/* 採集精華區 */ -/* ----------------------------------------------------- */ -static int b_man() { - char buf[64]; - - setapath(buf, currboard); - if( (currmode & MODE_BOARD) || HAS_PERM(PERM_SYSOP) ){ - char genbuf[128]; - int fd; - sprintf(genbuf, "%s/.rebuild", buf); - if( (fd = open(genbuf, O_CREAT, 0640)) > 0 ) - close(fd); + /* ----------------------------------------------------- */ + /* 採集精華區 */ + /* ----------------------------------------------------- */ + static int b_man() { + char buf[64]; + + setapath(buf, currboard); + if ((currmode & MODE_BOARD) || HAS_PERM(PERM_SYSOP)) { + char genbuf[128]; + int fd; + sprintf(genbuf, "%s/.rebuild", buf); + if ((fd = open(genbuf, O_CREAT, 0640)) > 0) + close(fd); + } + return a_menu(currboard, buf, HAS_PERM(PERM_ALLBOARD) ? 2 : + (currmode & MODE_BOARD ? 1 : 0)); } - return a_menu(currboard, buf, HAS_PERM(PERM_ALLBOARD) ? 2 : - (currmode & MODE_BOARD ? 1 : 0)); -} #ifndef NO_GAMBLE -void stop_gamble() -{ - boardheader_t *bp = getbcache(currbid); - char fn_ticket[128], fn_ticket_end[128]; - if(!bp->endgamble || bp->endgamble>now) return; - - setbfile(fn_ticket, currboard, FN_TICKET); - setbfile(fn_ticket_end, currboard, FN_TICKET_END); - - rename(fn_ticket, fn_ticket_end); - if(bp->endgamble) - { - bp->endgamble= 0; - substitute_record(fn_board, bp, sizeof(boardheader_t), currbid); - } -} -static int join_gamble(int ent, fileheader_t *fhdr, char *direct) { - if(!HAS_PERM(PERM_LOGINOK)) return DONOTHING; - stop_gamble(); - ticket(currbid); - return FULLUPDATE; -} -static int hold_gamble(int ent, fileheader_t *fhdr, char *direct) { - char fn_ticket[128],fn_ticket_end[128],genbuf[128], - msg[256]="",yn[10]=""; - boardheader_t *bp = getbcache(currbid); - int i; - FILE *fp=NULL; - - if(!(currmode & MODE_BOARD)) return 0; - setbfile(fn_ticket, currboard, FN_TICKET); - setbfile(fn_ticket_end, currboard, FN_TICKET_END); - setbfile(genbuf, currboard, FN_TICKET_LOCK); - if(dashf(fn_ticket)) - { - getdata(b_lines - 1, 0, "已經有舉辦賭盤, " - "是否要 [停止下注]?(N/y):", yn, 3, LCECHO); - if(yn[0]!='y') return FULLUPDATE; - rename(fn_ticket, fn_ticket_end); - if(bp->endgamble) - { - bp->endgamble= 0; - substitute_record(fn_board, bp, sizeof(boardheader_t), currbid); - - } - return FULLUPDATE; - } - - if(dashf(fn_ticket_end)) - { - getdata(b_lines - 1, 0, "已經有舉辦賭盤, " - "是否要 [開獎/取消]?(N/y):", yn, 3, LCECHO); - if(yn[0]!='y') return FULLUPDATE; - openticket(currbid); - return FULLUPDATE; + void stop_gamble() { + boardheader_t *bp = getbcache(currbid); + char fn_ticket[128], fn_ticket_end[128]; + if (!bp->endgamble || bp->endgamble > now) + return; + + setbfile(fn_ticket, currboard, FN_TICKET); + setbfile(fn_ticket_end, currboard, FN_TICKET_END); + + rename(fn_ticket, fn_ticket_end); + if (bp->endgamble) { + bp->endgamble = 0; + substitute_record(fn_board, bp, sizeof(boardheader_t), currbid); + } } - else if(dashf(genbuf)) - { - move(b_lines-1,0); - prints(" 目前系統正在處理開獎事宜, 請結果出爐後再舉辦......."); - pressanykey(); - return FULLUPDATE; + static int join_gamble(int ent, fileheader_t * fhdr, char *direct){ + if (!HAS_PERM(PERM_LOGINOK)) + return DONOTHING; + stop_gamble(); + ticket(currbid); + return FULLUPDATE; } - getdata(b_lines - 2, 0, "要舉辦賭盤 (N/y):", yn, 3, LCECHO); - if(yn[0]!='y') return FULLUPDATE; - getdata(b_lines - 1, 0, "賭什麼? 請輸入主題 (輸入後編輯內容):", - msg, 20, DOECHO); - if(msg[0]==0 || - vedit(fn_ticket_end, NA, NULL)<0) - return FULLUPDATE; - - clear(); - showtitle("舉辦賭盤",BBSNAME); - setbfile(genbuf, currboard, FN_TICKET_ITEMS); - -// sprintf(genbuf, "%s/"FN_TICKET_ITEMS, direct); - - if(!(fp=fopen(genbuf,"w"))) return FULLUPDATE; - do - { - getdata(2, 0, "輸入彩票價格 (價格:10-10000):",yn,6, LCECHO); - i=atoi(yn); - } while( i<10 || i>10000); - fprintf(fp,"%d\n",i); - if(!getdata(3,0,"設定自動封盤時間?(Y/n)",yn,3,LCECHO) || yn[0]!='n') - { - bp->endgamble= gettime(4, now); - substitute_record(fn_board, bp, sizeof(boardheader_t), currbid); + static int hold_gamble(int ent, fileheader_t * fhdr, char *direct){ + char fn_ticket[128], fn_ticket_end[128], genbuf[128], msg[256] = "", + yn[10] = ""; + boardheader_t *bp = getbcache(currbid); + int i; + FILE *fp = NULL; + + if (!(currmode & MODE_BOARD)) + return 0; + setbfile(fn_ticket, currboard, FN_TICKET); + setbfile(fn_ticket_end, currboard, FN_TICKET_END); + setbfile(genbuf, currboard, FN_TICKET_LOCK); + if (dashf(fn_ticket)) { + getdata(b_lines - 1, 0, "已經有舉辦賭盤, " + "是否要 [停止下注]?(N/y):", yn, 3, LCECHO); + if (yn[0] != 'y') + return FULLUPDATE; + rename(fn_ticket, fn_ticket_end); + if (bp->endgamble) { + bp->endgamble = 0; + substitute_record(fn_board, bp, sizeof(boardheader_t), currbid); + + } + return FULLUPDATE; + } + if (dashf(fn_ticket_end)) { + getdata(b_lines - 1, 0, "已經有舉辦賭盤, " + "是否要 [開獎/取消]?(N/y):", yn, 3, LCECHO); + if (yn[0] != 'y') + return FULLUPDATE; + openticket(currbid); + return FULLUPDATE; + } else if (dashf(genbuf)) { + move(b_lines - 1, 0); + prints(" 目前系統正在處理開獎事宜, 請結果出爐後再舉辦......."); + pressanykey(); + return FULLUPDATE; + } + getdata(b_lines - 2, 0, "要舉辦賭盤 (N/y):", yn, 3, LCECHO); + if (yn[0] != 'y') + return FULLUPDATE; + getdata(b_lines - 1, 0, "賭什麼? 請輸入主題 (輸入後編輯內容):", + msg, 20, DOECHO); + if (msg[0] == 0 || + vedit(fn_ticket_end, NA, NULL) < 0) + return FULLUPDATE; + + clear(); + showtitle("舉辦賭盤", BBSNAME); + setbfile(genbuf, currboard, FN_TICKET_ITEMS); + + //sprintf(genbuf, "%s/" FN_TICKET_ITEMS, direct); + + if (!(fp = fopen(genbuf, "w"))) + return FULLUPDATE; + do { + getdata(2, 0, "輸入彩票價格 (價格:10-10000):", yn, 6, LCECHO); + i = atoi(yn); + } while (i < 10 || i > 10000); + fprintf(fp, "%d\n", i); + if (!getdata(3, 0, "設定自動封盤時間?(Y/n)", yn, 3, LCECHO) || yn[0] != 'n') { + bp->endgamble = gettime(4, now); + substitute_record(fn_board, bp, sizeof(boardheader_t), currbid); + } + move(6, 0); + sprintf(genbuf, "請到 %s 板 按'f'參與賭博!\n\n一張 %d Ptt幣, 這是%s的賭博\n%s%s", + currboard, + i, i < 100 ? "小賭式" : i < 500 ? "平民級" : + i < 1000 ? "貴族級" : i < 5000 ? "富豪級" : "傾家蕩產", + bp->endgamble ? "賭盤結束時間: " : "", + bp->endgamble ? Cdate(&bp->endgamble) : "" + ); + strcat(msg, genbuf); + prints("請依次輸入彩票名稱, 需提供2~8項. (未滿八項, 輸入直接按enter)\n"); + for (i = 0; i < 8; i++) { + sprintf(yn, " %d)", i + 1); + getdata(7 + i, 0, yn, genbuf, 9, DOECHO); + if (!genbuf[0] && i > 1) + break; + fprintf(fp, "%s\n", genbuf); + } + fclose(fp); + move(8 + i, 0); + prints("賭盤設定完成"); + sprintf(genbuf, "[公告] %s 板 開始賭博!", currboard); + post_msg(currboard, genbuf, msg, cuser.userid); + post_msg("Record", genbuf + 7, msg, "[馬路探子]"); + /* Tim 控制CS, 以免正在玩的user把資料已經寫進來 */ + rename(fn_ticket_end, fn_ticket); + //設 w 馱~把檔名 儮L + + return FULLUPDATE; } - move(6,0); -sprintf(genbuf,"請到 %s 板 按'f'參與賭博!\n\n一張 %d Ptt幣, 這是%s的賭博\n%s%s", - currboard, - i, i<100 ? "小賭式" : i<500 ? "平民級": - i<1000 ?"貴族級" : i<5000 ?"富豪級" : "傾家蕩產", - bp->endgamble?"賭盤結束時間: ":"", - bp->endgamble?Cdate(&bp->endgamble):"" - ); - strcat(msg, genbuf); - prints("請依次輸入彩票名稱, 需提供2~8項. (未滿八項, 輸入直接按enter)\n"); - for(i=0; i<8; i++) - { - sprintf(yn, " %d)",i+1); - getdata(7+i, 0, yn, genbuf, 9, DOECHO); - if(!genbuf[0] && i>1) - break; - fprintf(fp,"%s\n",genbuf); - } - fclose(fp); - move(8+i,0); - prints("賭盤設定完成"); - sprintf(genbuf,"[公告] %s 板 開始賭博!", currboard); - post_msg(currboard, genbuf, msg, cuser.userid); - post_msg("Record", genbuf+7, msg, "[馬路探子]"); - /* Tim 控制CS, 以免正在玩的user把資料已經寫進來 */ - rename(fn_ticket_end, fn_ticket); // 設定完才把檔名改過來 - - return FULLUPDATE; -} #endif -static int cite_post(int ent, fileheader_t *fhdr, char *direct) { - char fpath[256]; - char title[TTLEN + 1]; - - setbfile(fpath, currboard, fhdr->filename); - strcpy(title, "◇ "); - strncpy(title+3, fhdr->title, TTLEN-3); - title[TTLEN] = '\0'; - a_copyitem(fpath, title, 0, 1); - b_man(); - return FULLUPDATE; -} + static int cite_post(int ent, fileheader_t * fhdr, char *direct){ + char fpath[256]; + char title[TTLEN + 1]; + + setbfile(fpath, currboard, fhdr->filename); + strcpy(title, "◇ "); + strncpy(title + 3, fhdr->title, TTLEN - 3); + title[TTLEN] = '\0'; + a_copyitem(fpath, title, 0, 1); + b_man(); + return FULLUPDATE; + } + + int edit_title(int ent, fileheader_t * fhdr, char *direct){ + char genbuf[200]; + fileheader_t tmpfhdr = *fhdr; + int dirty = 0; -int edit_title(int ent, fileheader_t *fhdr, char *direct) { - char genbuf[200]; - fileheader_t tmpfhdr = *fhdr; - int dirty = 0; + if (currmode & MODE_BOARD || !strcmp(cuser.userid, fhdr->owner)) { + if (getdata(b_lines - 1, 0, "標題:", genbuf, TTLEN, DOECHO)) { + strcpy(tmpfhdr.title, genbuf); + dirty++; + } + } + if (HAS_PERM(PERM_SYSOP)) { + if (getdata(b_lines - 1, 0, "作者:", genbuf, IDLEN + 2, DOECHO)) { + strcpy(tmpfhdr.owner, genbuf); + dirty++; + } + if (getdata(b_lines - 1, 0, "日期:", genbuf, 6, DOECHO)) { + sprintf(tmpfhdr.date, "%.5s", genbuf); + dirty++; + } + } + if (currmode & MODE_BOARD || !strcmp(cuser.userid, fhdr->owner)) { + getdata(b_lines - 1, 0, "確定(Y/N)?[n] ", genbuf, 3, DOECHO); + if ((genbuf[0] == 'y' || genbuf[0] == 'Y') && dirty) { + *fhdr = tmpfhdr; + substitute_record(direct, fhdr, sizeof(*fhdr), ent); + /* rocker.011018: 這裡應該改成用reference的方式取得原來的檔案 */ + substitute_check(fhdr); + touchdircache(currbid); + } + return FULLUPDATE; + } + return DONOTHING; + } - if(currmode & MODE_BOARD || !strcmp(cuser.userid,fhdr->owner)) { - if(getdata(b_lines - 1, 0, "標題:", genbuf, TTLEN, DOECHO)) { - strcpy(tmpfhdr.title, genbuf); - dirty++; - } + static int solve_post(int ent, fileheader_t * fhdr, char *direct){ + if (HAS_PERM(PERM_SYSOP)) { + fhdr->filemode ^= FILE_SOLVED; + substitute_record(direct, fhdr, sizeof(*fhdr), ent); + touchdircache(currbid); + return PART_REDRAW; + } + return DONOTHING; } - if(HAS_PERM(PERM_SYSOP)) { - if(getdata(b_lines - 1, 0, "作者:", genbuf, IDLEN + 2, DOECHO)) { - strcpy(tmpfhdr.owner, genbuf); - dirty++; - } - - if(getdata(b_lines - 1, 0, "日期:", genbuf, 6, DOECHO)) { - sprintf(tmpfhdr.date, "%.5s", genbuf); - dirty++; - } + static int recommend_cancel(int ent, fileheader_t * fhdr, char *direct){ + char yn[5]; + if (!(currmode & MODE_BOARD)) + return DONOTHING; + getdata(b_lines - 1, 0, "確定要推薦歸零(Y/N)?[n] ", yn, 5, LCECHO); + if (yn[0] != 'y') + return FULLUPDATE; + fhdr->recommend = 0; + + substitute_record(direct, fhdr, sizeof(*fhdr), ent); + substitute_check(fhdr); + touchdircache(currbid); + return FULLUPDATE; } + static int recommend(int ent, fileheader_t * fhdr, char *direct){ + struct tm *ptime = localtime(&now); + char buf[200], path[200], yn[5]; + boardheader_t *bp; + bp = getbcache(currbid); + + if (!(currmode & MODE_POST) || !strcmp(fhdr->owner, cuser.userid) || + bp->brdattr & BRD_VOTEBOARD) { + move(b_lines - 1, 0); + prints("您因權限不足無法推薦 或 不能推薦自己的文章!"); + pressanykey(); + return FULLUPDATE; + } + if (fhdr->recommend > 9 || fhdr->recommend < 0) + //暫時性的code 鴩蚋礎陪取消 + fhdr->recommend = 0; + + if (!(currmode & MODE_BOARD) && getuser(cuser.userid) && + now - xuser.recommend < 60) { + move(b_lines - 1, 0); + prints("離上次推薦時間太近囉, 請多花點時間仔細閱\讀文章!"); + pressanykey(); + return FULLUPDATE; + } + if (!getdata(b_lines - 2, 0, "推薦語:", path, 40, DOECHO) || + !getdata(b_lines - 1, 0, "確定要推薦, 請仔細考慮(Y/N)?[n] ", yn, 5, LCECHO) + || yn[0] != 'y') + return FULLUPDATE; - if(currmode & MODE_BOARD || !strcmp(cuser.userid,fhdr->owner)) { - getdata(b_lines-1, 0, "確定(Y/N)?[n] ", genbuf, 3, DOECHO); - if((genbuf[0] == 'y' || genbuf[0] == 'Y') && dirty) { - *fhdr = tmpfhdr; + sprintf(buf, + "\033[1;31m→ \033[33m%s\033[m\033[33m:%s\033[m%*s推薦自:%s %02d/%02d\n", + cuser.userid, path, + 45 - strlen(cuser.userid) - strlen(path), " ", fromhost, + ptime->tm_mon + 1, ptime->tm_mday); + setdirpath(path, direct, fhdr->filename); + log_file(path, buf); + if (fhdr->recommend < 9) { + fhdr->recommend++; + cuser.recommend = now; + passwd_update(usernum, &cuser); substitute_record(direct, fhdr, sizeof(*fhdr), ent); -/* rocker.011018: 這裡應該改成用reference的方式取得原來的檔案 */ - substitute_check(fhdr); - touchdircache(currbid); + substitute_check(fhdr); + touchdircache(currbid); } return FULLUPDATE; } - return DONOTHING; -} + static int mark_post(int ent, fileheader_t * fhdr, char *direct){ + + if (!(currmode & MODE_BOARD)) + return DONOTHING; -static int solve_post(int ent, fileheader_t * fhdr, char *direct){ - if (HAS_PERM(PERM_SYSOP)) { - fhdr->filemode ^= FILE_SOLVED; + fhdr->filemode ^= FILE_MARKED; substitute_record(direct, fhdr, sizeof(*fhdr), ent); - touchdircache(currbid); + substitute_check(fhdr); + touchdircache(currbid); return PART_REDRAW; } - return DONOTHING; -} - -static int recommend_cancel(int ent, fileheader_t *fhdr, char *direct) { - char yn[5]; - if (!(currmode & MODE_BOARD)) return DONOTHING; - getdata(b_lines-1, 0, "確定要推薦歸零(Y/N)?[n] ", yn, 5, LCECHO); - if(yn[0]!='y') return FULLUPDATE; - fhdr->recommend=0; - - substitute_record(direct, fhdr, sizeof(*fhdr), ent); - substitute_check(fhdr); - touchdircache(currbid); - return FULLUPDATE; -} -static int recommend(int ent, fileheader_t *fhdr, char *direct) { - struct tm *ptime=localtime(&now); - char buf[200],path[200], yn[5]; - boardheader_t *bp; - bp = getbcache(currbid); - - if(!(currmode & MODE_POST) || !strcmp(fhdr->owner,cuser.userid) || - bp->brdattr & BRD_VOTEBOARD) - { - move(b_lines-1,0); - prints("您因權限不足無法推薦 或 不能推薦自己的文章!"); - pressanykey(); - return FULLUPDATE; - } - if(fhdr->recommend>9 || fhdr->recommend<0 )// 暫時性的code 原來舊有值取消 - fhdr->recommend=0; - - if (!(currmode & MODE_BOARD) && getuser(cuser.userid) && - now - xuser.recommend < 60 ) - { - move(b_lines-1,0); - prints("離上次推薦時間太近囉, 請多花點時間仔細閱\讀文章!"); - pressanykey(); - return FULLUPDATE; - } - - if(!getdata(b_lines-2, 0, "推薦語:",path,40,DOECHO) || - !getdata(b_lines-1, 0, "確定要推薦, 請仔細考慮(Y/N)?[n] ", yn, 5,LCECHO) - || yn[0]!='y') return FULLUPDATE; - - sprintf(buf, - "\033[1;31m→ \033[33m%s\033[m\033[33m:%s\033[m%*s推薦自:%s %02d/%02d\n", - cuser.userid, path, - 45-strlen(cuser.userid)-strlen(path), " ",fromhost, - ptime->tm_mon+1,ptime->tm_mday) ; - setdirpath(path, direct, fhdr->filename); - log_file(path, buf); - if(fhdr->recommend<9) - { - fhdr->recommend++; - cuser.recommend=now; - passwd_update(usernum, &cuser); - substitute_record(direct, fhdr, sizeof(*fhdr), ent); - substitute_check(fhdr); - touchdircache(currbid); - } - return FULLUPDATE; -} -static int mark_post(int ent, fileheader_t *fhdr, char *direct) { - if(!(currmode & MODE_BOARD)) return DONOTHING; + int del_range(int ent, fileheader_t * fhdr, char *direct){ + char num1[8], num2[8]; + int inum1, inum2; + boardheader_t *bp; + bp = getbcache(currbid); - fhdr->filemode ^= FILE_MARKED; - substitute_record(direct, fhdr, sizeof(*fhdr), ent); - substitute_check(fhdr); - touchdircache(currbid); - return PART_REDRAW; -} - -int del_range(int ent, fileheader_t *fhdr, char *direct) { - char num1[8], num2[8]; - int inum1, inum2; - boardheader_t *bp; - bp = getbcache(currbid); - -/* rocker.011018: 串接模式下還是不允許刪除比較好 */ - if(currmode & MODE_SELECT) { + /* rocker.011018: 串接模式下還是不允許刪除比較好 */ + if (currmode & MODE_SELECT) { outmsg("請先回到正常模式後再進行刪除..."); refresh(); - /*safe_sleep(1);*/ - return FULLUPDATE; - } - if ( strcmp( bp->brdname, "Security") == 0 ) - return DONOTHING; - if((currstat != READING) || (currmode & MODE_BOARD)) { - getdata(1, 0, "[設定刪除範圍] 起點:", num1, 5, DOECHO); - inum1 = atoi(num1); - if(inum1 <= 0) { - outmsg("起點有誤"); - refresh(); - /*safe_sleep(1);*/ - return FULLUPDATE; - } - getdata(1, 28, "終點:", num2, 5, DOECHO); - inum2 = atoi(num2); - if(inum2 < inum1) { - outmsg("終點有誤"); - refresh(); - /*safe_sleep(1);*/ + /* safe_sleep(1); */ return FULLUPDATE; } - getdata(1, 48, msg_sure_ny, num1, 3, LCECHO); - if(*num1 == 'y') { - outmsg("處理中,請稍後..."); - refresh(); - if(currmode & MODE_SELECT) { - int fd,size = sizeof(fileheader_t); - char genbuf[100]; - fileheader_t rsfh; - int i = inum1,now; - if(currstat == RMAIL) - sethomedir(genbuf, cuser.userid); - else - setbdir(genbuf,currboard); - if((fd = (open(direct, O_RDONLY, 0))) != -1) { - if(lseek(fd, (off_t)(size * (inum1 - 1)), SEEK_SET) != - -1) { - while(read(fd,&rsfh,size) == size) { - if(i > inum2) - break; - now = getindex(genbuf, rsfh.filename, size); - strcpy(currfile, rsfh.filename); - delete_file(genbuf, sizeof(fileheader_t), now, - cmpfilename); - i++; + if (strcmp(bp->brdname, "Security") == 0) + return DONOTHING; + if ((currstat != READING) || (currmode & MODE_BOARD)) { + getdata(1, 0, "[設定刪除範圍] 起點:", num1, 5, DOECHO); + inum1 = atoi(num1); + if (inum1 <= 0) { + outmsg("起點有誤"); + refresh(); + /* safe_sleep(1); */ + return FULLUPDATE; + } + getdata(1, 28, "終點:", num2, 5, DOECHO); + inum2 = atoi(num2); + if (inum2 < inum1) { + outmsg("終點有誤"); + refresh(); + /* safe_sleep(1); */ + return FULLUPDATE; + } + getdata(1, 48, msg_sure_ny, num1, 3, LCECHO); + if (*num1 == 'y') { + outmsg("處理中,請稍後..."); + refresh(); + if (currmode & MODE_SELECT) { + int fd, size = sizeof(fileheader_t); + char genbuf[100]; + fileheader_t rsfh; + int i = inum1, now; + if (currstat == RMAIL) + sethomedir(genbuf, cuser.userid); + else + setbdir(genbuf, currboard); + if ((fd = (open(direct, O_RDONLY, 0))) != -1) { + if (lseek(fd, (off_t) (size * (inum1 - 1)), SEEK_SET) != + -1) { + while (read(fd, &rsfh, size) == size) { + if (i > inum2) + break; + now = getindex(genbuf, rsfh.filename, size); + strcpy(currfile, rsfh.filename); + delete_file(genbuf, sizeof(fileheader_t), now, + cmpfilename); + i++; + } } + close(fd); } - close(fd); } - } - - delete_range(direct, inum1, inum2); - fixkeep(direct, inum1); - - if(currmode & MODE_BOARD) - setbtotal(currbid); - - return DIRCHANGED; - } - return FULLUPDATE; - } - return DONOTHING; -} + delete_range(direct, inum1, inum2); + fixkeep(direct, inum1); -static int del_post(int ent, fileheader_t *fhdr, char *direct) { - char genbuf[100]; - int not_owned; - boardheader_t *bp; - - bp = getbcache(currbid); - if ( strcmp(bp->brdname, "Security") == 0 ) - return DONOTHING; - if((fhdr->filemode & FILE_MARKED) || (fhdr->filemode & FILE_DIGEST) || - (fhdr->owner[0] == '-')) - return DONOTHING; + if (currmode & MODE_BOARD) + setbtotal(currbid); - not_owned = strcmp(fhdr->owner, cuser.userid); - if((!(currmode & MODE_BOARD) && not_owned) || - ((bp->brdattr & BRD_VOTEBOARD) && !HAS_PERM(PERM_SYSOP)) || - !strcmp(cuser.userid, STR_GUEST)) + return DIRCHANGED; + } + return FULLUPDATE; + } return DONOTHING; + } - getdata(1, 0, msg_del_ny, genbuf, 3, LCECHO); - if(genbuf[0] == 'y' || genbuf[0] == 'Y') { - strcpy(currfile, fhdr->filename); - - setbfile(genbuf,currboard,fhdr->filename); - if(!delete_file (direct, sizeof(fileheader_t), ent, cmpfilename)) { - - if(currmode & MODE_SELECT) - { - /* rocker.011018: 利用reference減低loading */ - fileheader_t hdr; - int num; - - num = fhdr->money & ~FHR_REFERENCE; - setbdir(genbuf, currboard); - get_record(genbuf, &hdr, sizeof (hdr), num); - - /* 再這裡要check一下原來的dir裡面是不是有被人動過... */ - if (strcmp (hdr.filename, fhdr->filename)) - { - num=getindex(genbuf,fhdr->filename,sizeof(fileheader_t)); - get_record(genbuf, &hdr, sizeof (hdr), num); + static int del_post(int ent, fileheader_t * fhdr, char *direct){ + char genbuf[100]; + int not_owned; + boardheader_t *bp; + + bp = getbcache(currbid); + if (strcmp(bp->brdname, "Security") == 0) + return DONOTHING; + if ((fhdr->filemode & FILE_MARKED) || (fhdr->filemode & FILE_DIGEST) || + (fhdr->owner[0] == '-')) + return DONOTHING; + + not_owned = strcmp(fhdr->owner, cuser.userid); + if ((!(currmode & MODE_BOARD) && not_owned) || + ((bp->brdattr & BRD_VOTEBOARD) && !HAS_PERM(PERM_SYSOP)) || + !strcmp(cuser.userid, STR_GUEST)) + return DONOTHING; + + getdata(1, 0, msg_del_ny, genbuf, 3, LCECHO); + if (genbuf[0] == 'y' || genbuf[0] == 'Y') { + strcpy(currfile, fhdr->filename); + + setbfile(genbuf, currboard, fhdr->filename); + if (!delete_file(direct, sizeof(fileheader_t), ent, cmpfilename)) { + + if (currmode & MODE_SELECT) { + /* rocker.011018: 利用reference減低loading */ + fileheader_t hdr; + int num; + + num = fhdr->money & ~FHR_REFERENCE; + setbdir(genbuf, currboard); + get_record(genbuf, &hdr, sizeof(hdr), num); + + /* 再這裡要check一下原來的dir裡面是不是有被人動過... */ + if (strcmp(hdr.filename, fhdr->filename)) { + num = getindex(genbuf, fhdr->filename, sizeof(fileheader_t)); + get_record(genbuf, &hdr, sizeof(hdr), num); + } + /* rocker.011018: 這裡要還原被破壞的money */ + fhdr->money = hdr.money; + delete_file(genbuf, sizeof(fileheader_t), num, cmpfilename); } + cancelpost(fhdr, not_owned); - /* rocker.011018: 這裡要還原被破壞的money */ - fhdr->money = hdr.money; - delete_file (genbuf, sizeof(fileheader_t), num, cmpfilename); - } - - cancelpost(fhdr, not_owned); - - setbtotal(currbid); - if (fhdr->money < 0) - fhdr->money = 0; - if (not_owned && strcmp(currboard, "Test")){ - deumoney(searchuser(fhdr->owner), -fhdr->money); - } - if(!not_owned && strcmp(currboard, "Test")) { - if(cuser.numposts) - cuser.numposts--; - move(b_lines - 1, 0); - clrtoeol(); - demoney(-fhdr->money); - passwd_update(usernum, &cuser); /* post 數 */ - prints("%s,您的文章減為 %d 篇,支付清潔費 %d 銀", msg_del_ok, - cuser.numposts,fhdr->money); - refresh(); - pressanykey(); + setbtotal(currbid); + if (fhdr->money < 0) + fhdr->money = 0; + if (not_owned && strcmp(currboard, "Test")) { + deumoney(searchuser(fhdr->owner), -fhdr->money); + } + if (!not_owned && strcmp(currboard, "Test")) { + if (cuser.numposts) + cuser.numposts--; + move(b_lines - 1, 0); + clrtoeol(); + demoney(-fhdr->money); + passwd_update(usernum, &cuser); /* post 數 */ + prints("%s,您的文章減為 %d 篇,支付清潔費 %d 銀", msg_del_ok, + cuser.numposts, fhdr->money); + refresh(); + pressanykey(); + } + return DIRCHANGED; } - return DIRCHANGED; } + return FULLUPDATE; } - return FULLUPDATE; -} - -static int view_postmoney(int ent, fileheader_t *fhdr, char *direct) { - move(b_lines - 1, 0); - clrtoeol(); - prints("這一篇文章值 %d 銀", fhdr->money); - refresh(); - pressanykey(); - return FULLUPDATE; -} -#ifdef OUTJOBSPOOL -/* 看板備份 */ -static int tar_addqueue(int ent, fileheader_t *fhdr, char *direct) { - char email[60], qfn[80], ans[2]; - FILE *fp; - char bakboard, bakman; - clear(); - showtitle("看板備份", BBSNAME); - move(2, 0); - if( !((currmode & MODE_BOARD) || HAS_PERM(PERM_SYSOP)) ) { - move(5, 10); - outs("妳要是板主或是站長才能醬醬啊 -.-\"\""); - pressanykey(); - return FULLUPDATE; + static int view_postmoney(int ent, fileheader_t * fhdr, char *direct){ + move(b_lines - 1, 0); + clrtoeol(); + prints("這一篇文章值 %d 銀", fhdr->money); + refresh(); + pressanykey(); + return FULLUPDATE; } - sprintf(qfn, BBSHOME "/jobspool/tarqueue.%s", currboard); - if( access(qfn, 0) == 0 ){ - outs("已經排定行程, 稍後會進行備份"); - pressanykey(); - return FULLUPDATE; - } - if( !getdata(4, 0, "請輸入目的信箱:", email, sizeof(email), DOECHO) ) - return FULLUPDATE; - - /* check email -.-"" */ - if( strstr(email, "@") == NULL || strstr(email, ".bbs@") != NULL ){ - move(6, 0); - outs("您指定的信箱不正確! "); - pressanykey(); - return FULLUPDATE; - } +#ifdef OUTJOBSPOOL + /* 看板備份 */ + static int tar_addqueue(int ent, fileheader_t * fhdr, char *direct){ + char email[60], qfn[80], ans[2]; + FILE *fp; + char bakboard, bakman; + clear(); + showtitle("看板備份", BBSNAME); + move(2, 0); + if (!((currmode & MODE_BOARD) || HAS_PERM(PERM_SYSOP))) { + move(5, 10); + outs("妳要是板主或是站長才能醬醬啊 -.-\"\""); + pressanykey(); + return FULLUPDATE; + } + sprintf(qfn, BBSHOME "/jobspool/tarqueue.%s", currboard); + if (access(qfn, 0) == 0) { + outs("已經排定行程, 稍後會進行備份"); + pressanykey(); + return FULLUPDATE; + } + if (!getdata(4, 0, "請輸入目的信箱:", email, sizeof(email), DOECHO)) + return FULLUPDATE; - getdata(6, 0, "要備份看板內容嗎(Y/N)?[Y]", ans, sizeof(ans), LCECHO); - bakboard = (ans[0] == 'n' || ans[0] =='N') ? 0 : 1; - getdata(7, 0, "要備份精華區內容嗎(Y/N)?[N]", ans, sizeof(ans), LCECHO); - bakman = (ans[0] == 'y' || ans[0] =='Y') ? 1 : 0; - if( !bakboard && !bakman ){ - move(8, 0); - outs("可是我們只能備份看板或精華區的耶 ^^\"\"\""); - pressanykey(); - return FULLUPDATE; + /* check email -.-"" */ + if (strstr(email, "@") == NULL || strstr(email, ".bbs@") != NULL) { + move(6, 0); + outs("您指定的信箱不正確! "); + pressanykey(); + return FULLUPDATE; + } + getdata(6, 0, "要備份看板內容嗎(Y/N)?[Y]", ans, sizeof(ans), LCECHO); + bakboard = (ans[0] == 'n' || ans[0] == 'N') ? 0 : 1; + getdata(7, 0, "要備份精華區內容嗎(Y/N)?[N]", ans, sizeof(ans), LCECHO); + bakman = (ans[0] == 'y' || ans[0] == 'Y') ? 1 : 0; + if (!bakboard && !bakman) { + move(8, 0); + outs("可是我們只能備份看板或精華區的耶 ^^\"\"\""); + pressanykey(); + return FULLUPDATE; + } + fp = fopen(qfn, "w"); + fprintf(fp, "%s\n", cuser.userid); + fprintf(fp, "%s\n", email); + fprintf(fp, "%d,%d\n", bakboard, bakman); + fclose(fp); + + move(10, 0); + outs("系統已經將您的備份排入行程, \n"); + outs("稍後將會在系統負荷較低的時候將資料寄給您~ :) "); + pressanykey(); + return FULLUPDATE; } +#endif - fp = fopen(qfn, "w"); - fprintf(fp, "%s\n", cuser.userid); - fprintf(fp, "%s\n", email); - fprintf(fp, "%d,%d\n", bakboard, bakman); - fclose(fp); + static int sequent_ent; + static int continue_flag; - move(10, 0); - outs("系統已經將您的備份排入行程, \n"); - outs("稍後將會在系統負荷較低的時候將資料寄給您~ :) "); - pressanykey(); - return FULLUPDATE; -} -#endif + /* ----------------------------------------------------- */ + /* 依序讀新文章 */ + /* ----------------------------------------------------- */ + static int sequent_messages(fileheader_t * fptr) { + static int idc; + char genbuf[200]; -static int sequent_ent; -static int continue_flag; + if (fptr == NULL) + return (idc = 0); -/* ----------------------------------------------------- */ -/* 依序讀新文章 */ -/* ----------------------------------------------------- */ -static int sequent_messages(fileheader_t *fptr) { - static int idc; - char genbuf[200]; + if (++idc < sequent_ent) + return 0; - if(fptr == NULL) - return (idc = 0); + if (!brc_unread(fptr->filename, brc_num, brc_list)) + return 0; - if(++idc < sequent_ent) - return 0; + if (continue_flag) + genbuf[0] = 'y'; + else { + prints("讀取文章於:[%s] 作者:[%s]\n標題:[%s]", + currboard, fptr->owner, fptr->title); + getdata(3, 0, "(Y/N/Quit) [Y]: ", genbuf, 3, LCECHO); + } - if(!brc_unread(fptr->filename,brc_num,brc_list)) - return 0; + if (genbuf[0] != 'y' && genbuf[0]) { + clear(); + return (genbuf[0] == 'q' ? QUIT : 0); + } + setbfile(genbuf, currboard, fptr->filename); + brc_addlist(fptr->filename); + + if (more(genbuf, YEA) == 0) + outmsg("\033[31;47m \033[31m(R)\033[30m回信 \033[31m(↓,n)" + "\033[30m下一封 \033[31m(←,q)\033[30m離開 \033[m"); + continue_flag = 0; + + switch (egetch()) { + case KEY_LEFT: + case 'e': + case 'q': + case 'Q': + break; + + case 'y': + case 'r': + case 'Y': + case 'R': + if (currmode & MODE_POST) { + strcpy(quote_file, genbuf); + do_reply(fptr); + *quote_file = 0; + } + break; - if(continue_flag) - genbuf[0] = 'y'; - else { - prints("讀取文章於:[%s] 作者:[%s]\n標題:[%s]", - currboard, fptr->owner, fptr->title); - getdata(3, 0, "(Y/N/Quit) [Y]: ", genbuf, 3, LCECHO); - } + case ' ': + case KEY_DOWN: + case '\n': + case 'n': + continue_flag = 1; + } - if(genbuf[0] != 'y' && genbuf[0]) { clear(); - return (genbuf[0] == 'q' ? QUIT : 0); + return 0; } - setbfile(genbuf, currboard, fptr->filename); - brc_addlist(fptr->filename); + static int sequential_read(int ent, fileheader_t * fhdr, char *direct){ + char buf[40]; - if(more(genbuf, YEA) == 0) - outmsg("\033[31;47m \033[31m(R)\033[30m回信 \033[31m(↓,n)" - "\033[30m下一封 \033[31m(←,q)\033[30m離開 \033[m"); - continue_flag = 0; + clear(); + sequent_messages((fileheader_t *) NULL); + sequent_ent = ent; + continue_flag = 0; + setbdir(buf, currboard); + apply_record(buf, sequent_messages, sizeof(fileheader_t)); + return FULLUPDATE; + } - switch(egetch()) { - case KEY_LEFT: - case 'e': - case 'q': - case 'Q': - break; - - case 'y': - case 'r': - case 'Y': - case 'R': - if(currmode & MODE_POST) { - strcpy(quote_file, genbuf); - do_reply(fptr); - *quote_file = 0; + /* ----------------------------------------------------- */ + /* 看板備忘錄、文摘、精華區 */ + /* ----------------------------------------------------- */ + int b_note_edit_bname(int bid){ + char buf[64]; + int aborted; + boardheader_t *fh = getbcache(bid); + setbfile(buf, fh->brdname, fn_notes); + aborted = vedit(buf, NA, NULL); + if (aborted == -1) { + clear(); + outs(msg_cancel); + pressanykey(); + } else { + if (!getdata(2, 0, "設定有效期限天?(n/Y)", buf, 3, LCECHO) + || buf[0] != 'n') + fh->bupdate = gettime(3, fh->bupdate ? fh->bupdate : now); + else + fh->bupdate = 0; + substitute_record(fn_board, fh, sizeof(boardheader_t), bid); } - break; - - case ' ': - case KEY_DOWN: - case '\n': - case 'n': - continue_flag = 1; + return 0; } - clear(); - return 0; -} - -static int sequential_read(int ent, fileheader_t *fhdr, char *direct) { - char buf[40]; - - clear(); - sequent_messages((fileheader_t *) NULL); - sequent_ent = ent; - continue_flag = 0; - setbdir(buf, currboard); - apply_record(buf, sequent_messages, sizeof(fileheader_t)); - return FULLUPDATE; -} - -/* ----------------------------------------------------- */ -/* 看板備忘錄、文摘、精華區 */ -/* ----------------------------------------------------- */ -int b_note_edit_bname(int bid) { - char buf[64]; - int aborted; - boardheader_t *fh=getbcache(bid); - setbfile(buf, fh->brdname, fn_notes); - aborted = vedit(buf, NA, NULL); - if(aborted == -1) { - clear(); - outs(msg_cancel); - pressanykey(); - } else { - if(!getdata(2, 0, "設定有效期限天?(n/Y)", buf, 3, LCECHO) - || buf[0]!='n') - fh->bupdate = gettime(3, fh->bupdate?fh->bupdate:now); - else - fh->bupdate = 0; - substitute_record(fn_board, fh, sizeof(boardheader_t), bid); + static int b_notes_edit() { + if (currmode & MODE_BOARD) { + b_note_edit_bname(currbid); + return FULLUPDATE; + } + return 0; } - return 0; -} -static int b_notes_edit() { - if(currmode & MODE_BOARD) { - b_note_edit_bname(currbid); - return FULLUPDATE; + static int b_water_edit() { + if (currmode & MODE_BOARD) { + friend_edit(BOARD_WATER); + return FULLUPDATE; + } + return 0; } - return 0; -} -static int b_water_edit() { - if(currmode & MODE_BOARD) { - friend_edit(BOARD_WATER); - return FULLUPDATE; + static int visable_list_edit() { + if (currmode & MODE_BOARD) { + friend_edit(BOARD_VISABLE); + hbflreload(currbid); + return FULLUPDATE; + } + return 0; } - return 0; -} -static int visable_list_edit() { - if(currmode & MODE_BOARD) { - friend_edit(BOARD_VISABLE); - hbflreload(currbid); - return FULLUPDATE; - } - return 0; -} + static int b_post_note() { + char buf[200], yn[3]; -static int b_post_note() { - char buf[200], yn[3]; - - if(currmode & MODE_BOARD) { - setbfile(buf, currboard, FN_POST_NOTE ); - if(more(buf,NA) == -1) more("etc/"FN_POST_NOTE , NA); - getdata(b_lines - 2, 0, "是否要用自訂post注意事項?", yn, sizeof(yn), LCECHO); - if(yn[0] == 'y') - vedit(buf, NA, NULL); - else - unlink(buf); - return FULLUPDATE; + if (currmode & MODE_BOARD) { + setbfile(buf, currboard, FN_POST_NOTE); + if (more(buf, NA) == -1) + more("etc/" FN_POST_NOTE, NA); + getdata(b_lines - 2, 0, "是否要用自訂post注意事項?", yn, sizeof(yn), LCECHO); + if (yn[0] == 'y') + vedit(buf, NA, NULL); + else + unlink(buf); + return FULLUPDATE; + } + return 0; } - return 0; -} -static int b_application() { - char buf[200]; + static int b_application() { + char buf[200]; - if(currmode & MODE_BOARD) { - setbfile(buf, currboard, FN_APPLICATION); - vedit(buf, NA, NULL); - return FULLUPDATE; + if (currmode & MODE_BOARD) { + setbfile(buf, currboard, FN_APPLICATION); + vedit(buf, NA, NULL); + return FULLUPDATE; + } + return 0; } - return 0; -} -static int can_vote_edit() { - if(currmode & MODE_BOARD) { - friend_edit(FRIEND_CANVOTE); - return FULLUPDATE; + static int can_vote_edit() { + if (currmode & MODE_BOARD) { + friend_edit(FRIEND_CANVOTE); + return FULLUPDATE; + } + return 0; } - return 0; -} -static int bh_title_edit() { - boardheader_t *bp; + static int bh_title_edit() { + boardheader_t *bp; + + if (currmode & MODE_BOARD) { + char genbuf[BTLEN]; + + bp = getbcache(currbid); + move(1, 0); + clrtoeol(); + getdata_str(1, 0, "請輸入看板新中文敘述:", genbuf, + BTLEN - 16, DOECHO, bp->title + 7); + + if (!genbuf[0]) + return 0; + strip_ansi(genbuf, genbuf, 0); + strcpy(bp->title + 7, genbuf); + substitute_record(fn_board, bp, sizeof(boardheader_t), currbid); + log_usies("SetBoard", currboard); + return FULLUPDATE; + } + return 0; + } - if(currmode & MODE_BOARD) { - char genbuf[BTLEN]; + static int b_notes() { + char buf[64]; - bp = getbcache(currbid); - move(1,0); - clrtoeol(); - getdata_str(1,0,"請輸入看板新中文敘述:", genbuf, - BTLEN - 16, DOECHO, bp->title + 7); - - if(!genbuf[0]) - return 0; - strip_ansi( genbuf,genbuf,0); - strcpy(bp->title + 7,genbuf); - substitute_record(fn_board, bp, sizeof(boardheader_t), currbid); - log_usies("SetBoard", currboard); + setbfile(buf, currboard, fn_notes); + if (more(buf, NA) == -1) { + clear(); + move(4, 20); + outs("本看板尚無「備忘錄」。"); + } + pressanykey(); return FULLUPDATE; } - return 0; -} -static int b_notes() { - char buf[64]; - - setbfile(buf, currboard, fn_notes); - if(more(buf, NA) == -1) { - clear(); - move(4, 20); - outs("本看板尚無「備忘錄」。"); + int board_select() { + char fpath[80]; + char genbuf[100]; + + currmode &= ~MODE_SELECT; + sprintf(fpath, "SR.%s", cuser.userid); + setbfile(genbuf, currboard, fpath); + unlink(genbuf); + if (currstat == RMAIL) + sethomedir(currdirect, cuser.userid); + else + setbdir(currdirect, currboard); + return NEWDIRECT; } - pressanykey(); - return FULLUPDATE; -} -int board_select() { - char fpath[80]; - char genbuf[100]; + int board_digest() { + if (currmode & MODE_SELECT) + board_select(); + currmode ^= MODE_DIGEST; + if (currmode & MODE_DIGEST) + currmode &= ~MODE_POST; + else if (haspostperm(currboard)) + currmode |= MODE_POST; - currmode &= ~MODE_SELECT; - sprintf(fpath, "SR.%s", cuser.userid); - setbfile(genbuf, currboard, fpath); - unlink(genbuf); - if(currstat == RMAIL) - sethomedir(currdirect, cuser.userid); - else setbdir(currdirect, currboard); - return NEWDIRECT; -} - -int board_digest() { - if(currmode & MODE_SELECT) - board_select(); - currmode ^= MODE_DIGEST; - if(currmode & MODE_DIGEST) - currmode &= ~MODE_POST; - else if (haspostperm(currboard)) - currmode |= MODE_POST; - - setbdir(currdirect, currboard); - return NEWDIRECT; -} + return NEWDIRECT; + } -int board_etc() { - if(!HAS_PERM(PERM_SYSOP)) - return DONOTHING; - currmode ^= MODE_ETC; - if(currmode & MODE_ETC) - currmode &= ~MODE_POST; - else if(haspostperm(currboard)) - currmode |= MODE_POST; - - setbdir(currdirect, currboard); - return NEWDIRECT; -} + int board_etc() { + if (!HAS_PERM(PERM_SYSOP)) + return DONOTHING; + currmode ^= MODE_ETC; + if (currmode & MODE_ETC) + currmode &= ~MODE_POST; + else if (haspostperm(currboard)) + currmode |= MODE_POST; -static int good_post(int ent, fileheader_t *fhdr, char *direct) { - char genbuf[200]; - char genbuf2[200]; - int delta = 0; + setbdir(currdirect, currboard); + return NEWDIRECT; + } - if((currmode & MODE_DIGEST) || !(currmode & MODE_BOARD)) - return DONOTHING; + static int good_post(int ent, fileheader_t * fhdr, char *direct){ + char genbuf[200]; + char genbuf2[200]; + int delta = 0; + + if ((currmode & MODE_DIGEST) || !(currmode & MODE_BOARD)) + return DONOTHING; + + if (fhdr->filemode & FILE_DIGEST) { + fhdr->filemode = (fhdr->filemode & ~FILE_DIGEST); + if (!strcmp(currboard, "Note") || !strcmp(currboard, "PttBug") || + !strcmp(currboard, "Artdsn") || !strcmp(currboard, "PttLaw")) { + deumoney(searchuser(fhdr->owner), -1000); + if (!(currmode & MODE_SELECT)) + fhdr->money -= 1000; + else + delta = -1000; + } + } else { + fileheader_t digest; + char *ptr, buf[64]; + + memcpy(&digest, fhdr, sizeof(digest)); + digest.filename[0] = 'G'; + strcpy(buf, direct); + ptr = strrchr(buf, '/') + 1; + ptr[0] = '\0'; + sprintf(genbuf, "%s%s", buf, digest.filename); + + if (dashf(genbuf)) + unlink(genbuf); - if(fhdr->filemode & FILE_DIGEST) { - fhdr->filemode = (fhdr->filemode & ~FILE_DIGEST); - if(!strcmp(currboard,"Note") || !strcmp(currboard,"PttBug") || - !strcmp(currboard,"Artdsn") || !strcmp(currboard, "PttLaw")) { - deumoney(searchuser(fhdr->owner),-1000); - if(!(currmode & MODE_SELECT)) - fhdr->money -= 1000; - else - delta = -1000; + digest.filemode = 0; + sprintf(genbuf2, "%s%s", buf, fhdr->filename); + Link(genbuf2, genbuf); + strcpy(ptr, fn_mandex); + append_record(buf, &digest, sizeof(digest)); + + fhdr->filemode = (fhdr->filemode & ~FILE_MARKED) | FILE_DIGEST; + if (!strcmp(currboard, "Note") || !strcmp(currboard, "PttBug") || + !strcmp(currboard, "Artdsn") || !strcmp(currboard, "PttLaw")) { + deumoney(searchuser(fhdr->owner), 1000); + if (!(currmode & MODE_SELECT)) + fhdr->money += 1000; + else + delta = 1000; + } } - } else { - fileheader_t digest; - char *ptr, buf[64]; - - memcpy(&digest, fhdr, sizeof(digest)); - digest.filename[0] = 'G'; - strcpy(buf, direct); - ptr = strrchr(buf, '/') + 1; - ptr[0] = '\0'; - sprintf(genbuf, "%s%s", buf, digest.filename); - - if(dashf(genbuf)) unlink (genbuf); - - digest.filemode = 0; - sprintf(genbuf2, "%s%s", buf, fhdr->filename); - Link(genbuf2, genbuf); - strcpy(ptr, fn_mandex); - append_record(buf, &digest, sizeof(digest)); - - fhdr->filemode = (fhdr->filemode & ~FILE_MARKED) | FILE_DIGEST; - if(!strcmp(currboard, "Note") || !strcmp(currboard, "PttBug") || - !strcmp(currboard,"Artdsn") || !strcmp(currboard, "PttLaw")) { - deumoney(searchuser(fhdr->owner), 1000); - if(!(currmode & MODE_SELECT)) fhdr->money += 1000; - else delta = 1000; + substitute_record(direct, fhdr, sizeof(*fhdr), ent); + touchdircache(currbid); + /* rocker.011018: 串接模式用reference增進效率 */ + if ((currmode & MODE_SELECT) && (fhdr->money & FHR_REFERENCE)) { + fileheader_t hdr; + char genbuf[100]; + int num; + + num = fhdr->money & ~FHR_REFERENCE; + setbdir(genbuf, currboard); + get_record(genbuf, &hdr, sizeof(hdr), num); + + /* 再這裡要check一下原來的dir裡面是不是有被人動過... */ + if (strcmp(hdr.filename, fhdr->filename)) { + num = getindex(genbuf, fhdr->filename, sizeof(fileheader_t)); + get_record(genbuf, &hdr, sizeof(hdr), num); + } + fhdr->money = hdr.money + delta; + + substitute_record(genbuf, fhdr, sizeof(*fhdr), num); } + return PART_REDRAW; } - substitute_record(direct, fhdr, sizeof(*fhdr), ent); - touchdircache(currbid); -/* rocker.011018: 串接模式用reference增進效率 */ - if ((currmode & MODE_SELECT) && (fhdr->money & FHR_REFERENCE)) - { - fileheader_t hdr; - char genbuf[100]; - int num; - - num = fhdr->money & ~FHR_REFERENCE; - setbdir(genbuf, currboard); - get_record(genbuf, &hdr, sizeof (hdr), num); - - /* 再這裡要check一下原來的dir裡面是不是有被人動過... */ - if (strcmp (hdr.filename, fhdr->filename)) - { - num = getindex(genbuf, fhdr->filename, sizeof(fileheader_t)); - get_record(genbuf, &hdr, sizeof (hdr), num); - } - fhdr->money = hdr.money + delta; - - substitute_record(genbuf, fhdr, sizeof(*fhdr), num); - } - return PART_REDRAW; -} -/* help for board reading */ -static char *board_help[] = { - "\0全功\能看板操作說明", - "\01基本命令", - "(p)(↑) 上移一篇文章 (^P) 發表文章", - "(n)(↓) 下移一篇文章 (d) 刪除文章", - "(P)(PgUp) 上移一頁 (S) 串連相關文章", - "(N)(PgDn) 下移一頁 (##) 跳到 ## 號文章", - "(r)(→) 閱\讀此篇文章 ($) 跳到最後一篇文章", - "\01進階命令", - "(tab)/z 文摘模式/精華區 (a/A)(^Q)找尋作者/作者資料", - "(b/f) 展讀備忘錄/參與賭盤 (?)(/) 找尋標題", - "(V/R) 投票/查詢投票結果 (^W)(X) 我在哪裡/推薦文章", - "(x)(w) 轉錄文章/丟水球 (=)/([]<>-+) 找尋首篇文章/主題式閱\讀", + /* help for board reading */ + static char *board_help[] = { + "\0全功\能看板操作說明", + "\01基本命令", + "(p)(↑) 上移一篇文章 (^P) 發表文章", + "(n)(↓) 下移一篇文章 (d) 刪除文章", + "(P)(PgUp) 上移一頁 (S) 串連相關文章", + "(N)(PgDn) 下移一頁 (##) 跳到 ## 號文章", + "(r)(→) 閱\讀此篇文章 ($) 跳到最後一篇文章", + "\01進階命令", + "(tab)/z 文摘模式/精華區 (a/A)(^Q)找尋作者/作者資料", + "(b/f) 展讀備忘錄/參與賭盤 (?)(/) 找尋標題", + "(V/R) 投票/查詢投票結果 (^W)(X) 我在哪裡/推薦文章", + "(x)(w) 轉錄文章/丟水球 (=)/([]<>-+) 找尋首篇文章/主題式閱\讀", #ifdef INTERNET_EMAIL - "(F) 文章寄回Internet郵箱 (U) 將文章 uuencode 後寄回郵箱", + "(F) 文章寄回Internet郵箱 (U) 將文章 uuencode 後寄回郵箱", #endif - "(E) 重編文章 (^H) 列出所有的 New Post(s)", - "\01板主命令", - "(G) 舉辦賭盤/停止下注/開獎(W/K/v) 編輯備忘錄/水桶名單/可看見名單", - "(M/o) 舉行投票/編私投票名單 (m/c/g) 保留文章/選錄精華/文摘", - "(D) 刪除一段範圍的文章 (T/B) 重編文章標題/重編看板標題", - "(i) 編輯申請入會表格 (t/^D) 標記文章/砍除標記的文章", - "(O) 編輯Post注意事項 (H)/(Y) 看板隱藏/現身 取消推薦文章", - NULL -}; - -static int b_help() { - show_help(board_help); - return FULLUPDATE; -} + "(E) 重編文章 (^H) 列出所有的 New Post(s)", + "\01板主命令", + "(G) 舉辦賭盤/停止下注/開獎(W/K/v) 編輯備忘錄/水桶名單/可看見名單", + "(M/o) 舉行投票/編私投票名單 (m/c/g) 保留文章/選錄精華/文摘", + "(D) 刪除一段範圍的文章 (T/B) 重編文章標題/重編看板標題", + "(i) 編輯申請入會表格 (t/^D) 標記文章/砍除標記的文章", + "(O) 編輯Post注意事項 (H)/(Y) 看板隱藏/現身 取消推薦文章", + NULL + }; + + static int b_help() { + show_help(board_help); + return FULLUPDATE; + } -/* ----------------------------------------------------- */ -/* 板主設定隱形/ 解隱形 */ -/* ----------------------------------------------------- */ -char board_hidden_status; + /* ----------------------------------------------------- */ + /* 板主設定隱形/ 解隱形 */ + /* ----------------------------------------------------- */ + char board_hidden_status; #ifdef BMCHS -static int change_hidden(int ent, fileheader_t *fhdr, char *direct) -{ - boardheader_t bh; - int bid; - char ans[4]; - - if( !((currmode & MODE_BOARD) || HAS_PERM(PERM_SYSOP)) || - currboard[0] == 0 || - (bid = getbnum(currboard)) < 0 || - get_record(fn_board, &bh, sizeof(bh), bid) == -1 ) - return DONOTHING; - - if( ((bh.brdattr & BRD_HIDE) && (bh.brdattr & BRD_POSTMASK)) ){ - getdata(1, 0, "目前板在隱形狀態, 要解隱形嘛(Y/N)?[N]", - ans, sizeof(ans), LCECHO); - if( ans[0] != 'y' && ans[0] != 'Y' ) - return FULLUPDATE; - getdata(2, 0, "再確認一次, 真的要把板板公開嘛 @____@(Y/N)?[N]", - ans, sizeof(ans), LCECHO); - if( ans[0] != 'y' && ans[0] != 'Y' ) - return FULLUPDATE; - if( bh.brdattr & BRD_HIDE ) bh.brdattr -= BRD_HIDE; - if( bh.brdattr & BRD_POSTMASK ) bh.brdattr -= BRD_POSTMASK; - log_usies("OpenBoard", bh.brdname); - outs("君心今傳眾人,無處不聞弦歌。\n"); - board_hidden_status = 0; - hbflreload(bid); - } - else{ - getdata(1, 0, "目前板在現形狀態, 要隱形嘛(Y/N)?[N]", - ans, sizeof(ans), LCECHO); - if( ans[0] != 'y' && ans[0] != 'Y' ) - return FULLUPDATE; - bh.brdattr |= BRD_HIDE; - bh.brdattr |= BRD_POSTMASK; - log_usies("CloseBoard", bh.brdname); - outs("君心今已掩抑,惟盼善自珍重。\n"); - board_hidden_status = 1; + static int change_hidden(int ent, fileheader_t * fhdr, char *direct){ + boardheader_t bh; + int bid; + char ans[4]; + + if (!((currmode & MODE_BOARD) || HAS_PERM(PERM_SYSOP)) || + currboard[0] == 0 || + (bid = getbnum(currboard)) < 0 || + get_record(fn_board, &bh, sizeof(bh), bid) == -1) + return DONOTHING; + + if (((bh.brdattr & BRD_HIDE) && (bh.brdattr & BRD_POSTMASK))) { + getdata(1, 0, "目前板在隱形狀態, 要解隱形嘛(Y/N)?[N]", + ans, sizeof(ans), LCECHO); + if (ans[0] != 'y' && ans[0] != 'Y') + return FULLUPDATE; + getdata(2, 0, "再確認一次, 真的要把板板公開嘛 @____@(Y/N)?[N]", + ans, sizeof(ans), LCECHO); + if (ans[0] != 'y' && ans[0] != 'Y') + return FULLUPDATE; + if (bh.brdattr & BRD_HIDE) + bh.brdattr -= BRD_HIDE; + if (bh.brdattr & BRD_POSTMASK) + bh.brdattr -= BRD_POSTMASK; + log_usies("OpenBoard", bh.brdname); + outs("君心今傳眾人,無處不聞弦歌。\n"); + board_hidden_status = 0; + hbflreload(bid); + } else { + getdata(1, 0, "目前板在現形狀態, 要隱形嘛(Y/N)?[N]", + ans, sizeof(ans), LCECHO); + if (ans[0] != 'y' && ans[0] != 'Y') + return FULLUPDATE; + bh.brdattr |= BRD_HIDE; + bh.brdattr |= BRD_POSTMASK; + log_usies("CloseBoard", bh.brdname); + outs("君心今已掩抑,惟盼善自珍重。\n"); + board_hidden_status = 1; + } + setup_man(&bh); + substitute_record(fn_board, &bh, sizeof(bh), bid); + reset_board(bid); + log_usies("SetBoard", bh.brdname); + pressanykey(); + return FULLUPDATE; } - setup_man(&bh); - substitute_record(fn_board, &bh, sizeof(bh), bid); - reset_board(bid); - log_usies("SetBoard", bh.brdname); - pressanykey(); - return FULLUPDATE; -} #endif -/* ----------------------------------------------------- */ -/* 看板功能表 */ -/* ----------------------------------------------------- */ -struct onekey_t read_comms[] = { - {KEY_TAB, board_digest}, - {'C', board_etc}, - {'b', b_notes}, - {'c', cite_post}, - {'r', read_post}, - {'z', b_man}, - {'D', del_range}, - {'S', sequential_read}, - {'E', edit_post}, - {'T', edit_title}, - {'s', do_select}, - {'R', b_results}, - {'V', b_vote}, - {'M', b_vote_maintain}, - {'B', bh_title_edit}, - {'W', b_notes_edit}, - {'O', b_post_note}, - {'K', b_water_edit}, - {'w', b_call_in}, - {'v', visable_list_edit}, - {'i', b_application}, - {'o', can_vote_edit}, - {'x', cross_post}, - {'X', recommend}, - {'Y', recommend_cancel}, - {'h', b_help}, + /* ----------------------------------------------------- */ + /* 看板功能表 */ + /* ----------------------------------------------------- */ + struct onekey_t read_comms[] = { + {KEY_TAB, board_digest}, + {'C', board_etc}, + {'b', b_notes}, + {'c', cite_post}, + {'r', read_post}, + {'z', b_man}, + {'D', del_range}, + {'S', sequential_read}, + {'E', edit_post}, + {'T', edit_title}, + {'s', do_select}, + {'R', b_results}, + {'V', b_vote}, + {'M', b_vote_maintain}, + {'B', bh_title_edit}, + {'W', b_notes_edit}, + {'O', b_post_note}, + {'K', b_water_edit}, + {'w', b_call_in}, + {'v', visable_list_edit}, + {'i', b_application}, + {'o', can_vote_edit}, + {'x', cross_post}, + {'X', recommend}, + {'Y', recommend_cancel}, + {'h', b_help}, #ifndef NO_GAMBLE - {'f', join_gamble}, - {'G', hold_gamble}, + {'f', join_gamble}, + {'G', hold_gamble}, #endif - {'g', good_post}, - {'y', reply_post}, - {'d', del_post}, - {'m', mark_post}, - {'L', solve_post}, - {Ctrl('P'), do_post}, - {Ctrl('W'), whereami}, - {'Q', view_postmoney}, + {'g', good_post}, + {'y', reply_post}, + {'d', del_post}, + {'m', mark_post}, + {'L', solve_post}, + {Ctrl('P'), do_post}, + {Ctrl('W'), whereami}, + {'Q', view_postmoney}, #ifdef OUTJOBSPOOL - {'u', tar_addqueue}, + {'u', tar_addqueue}, #endif #ifdef BMCHS - {'H', change_hidden}, + {'H', change_hidden}, #endif - {'\0', NULL} -}; + {'\0', NULL} + }; -int Read() { - int mode0 = currutmp->mode; - int stat0 = currstat, tmpbid=currutmp->brc_id; - char buf[40]; + int Read() { + int mode0 = currutmp->mode; + int stat0 = currstat, tmpbid = currutmp->brc_id; + char buf[40]; #ifdef LOG_BOARD - time_t usetime = now; -#endif + time_t usetime = now; +#endif - setutmpmode(READING); - set_board(); + setutmpmode(READING); + set_board(); - if(board_visit_time < board_note_time) { - setbfile(buf, currboard, fn_notes); - more(buf, NA); - pressanykey(); - } - setutmpbid(currbid); - setbdir(buf, currboard); - curredit &= ~EDIT_MAIL; - i_read(READING, buf, readtitle, readdoent, read_comms, - currbid); + if (board_visit_time < board_note_time) { + setbfile(buf, currboard, fn_notes); + more(buf, NA); + pressanykey(); + } + setutmpbid(currbid); + setbdir(buf, currboard); + curredit &= ~EDIT_MAIL; + i_read(READING, buf, readtitle, readdoent, read_comms, + currbid); #ifdef LOG_BOARD - log_board(currboard, now - usetime); + log_board(currboard, now - usetime); #endif - brc_update(); - setutmpbid(tmpbid); - currutmp->mode = mode0; - currstat = stat0; - return 0; -} + brc_update(); + setutmpbid(tmpbid); + currutmp->mode = mode0; + currstat = stat0; + return 0; + } -void ReadSelect() { - int mode0 = currutmp->mode; - int stat0 = currstat; - char genbuf[200]; - - currstat = XMODE; - if(do_select(0, 0, genbuf) == NEWDIRECT) - Read(); - setutmpbid(0); - currutmp->mode = mode0; - currstat = stat0; -} + void ReadSelect() { + int mode0 = currutmp->mode; + int stat0 = currstat; + char genbuf[200]; + + currstat = XMODE; + if (do_select(0, 0, genbuf) == NEWDIRECT) + Read(); + setutmpbid(0); + currutmp->mode = mode0; + currstat = stat0; + } -#ifdef LOG_BOARD -static void log_board(char *mode, time_t usetime) { - char buf[ 256 ]; +#ifdef LOG_BOARD + static void log_board(char *mode, time_t usetime){ + char buf[256]; - if(usetime > 30) { - sprintf(buf, "USE %-20.20s Stay: %5ld (%s) %s", - mode, usetime ,cuser.userid ,ctime(&now)); - log_file(FN_USEBOARD,buf); + if (usetime > 30) { + sprintf(buf, "USE %-20.20s Stay: %5ld (%s) %s", + mode, usetime, cuser.userid, ctime(&now)); + log_file(FN_USEBOARD, buf); + } } -} #endif -int Select() { - char genbuf[200]; + int Select() { + char genbuf[200]; - setutmpmode(SELECT); - do_select(0, NULL, genbuf); - return 0; -} + setutmpmode(SELECT); + do_select(0, NULL, genbuf); + return 0; + } #ifdef HAVEMOBILE -void mobile_message(char *mobile, char *message) -{ + void mobile_message(char *mobile, char *message){ - bsmtp(char *fpath, char *title, char *rcpt, int method); -} + bsmtp(char *fpath, char *title, char *rcpt, int method); + } #endif diff --git a/pttbbs/mbbsd/board.c b/pttbbs/mbbsd/board.c index d85a45ae..4626adb5 100644 --- a/pttbbs/mbbsd/board.c +++ b/pttbbs/mbbsd/board.c @@ -1,13 +1,15 @@ -/* $Id: board.c,v 1.39 2002/06/26 09:49:37 ptt Exp $ */ +/* $Id: board.c,v 1.40 2002/07/05 17:10:26 in2 Exp $ */ #include "bbs.h" -#define BRC_STRLEN 15 /* Length of board name */ +#define BRC_STRLEN 15 /* Length of board name */ #define BRC_MAXSIZE 24576 #define BRC_ITEMSIZE (BRC_STRLEN + 1 + BRC_MAXNUM * sizeof( int )) #define BRC_MAXNUM 80 -static char *brc_getrecord(char *ptr, char *name, int *pnum, int *list) { - int num; - char *tmp; +static char * +brc_getrecord(char *ptr, char *name, int *pnum, int *list) +{ + int num; + char *tmp; strncpy(name, ptr, BRC_STRLEN); ptr += BRC_STRLEN; @@ -20,14 +22,16 @@ static char *brc_getrecord(char *ptr, char *name, int *pnum, int *list) { return tmp; } -static time_t brc_expire_time; +static time_t brc_expire_time; -static char *brc_putrecord(char *ptr, char *name, int num, int *list) { - if(num > 0 && list[0] > brc_expire_time) { +static char * +brc_putrecord(char *ptr, char *name, int num, int *list) +{ + if (num > 0 && list[0] > brc_expire_time) { if (num > BRC_MAXNUM) num = BRC_MAXNUM; - while(num > 1 && list[num - 1] < brc_expire_time) + while (num > 1 && list[num - 1] < brc_expire_time) num--; strncpy(ptr, name, BRC_STRLEN); @@ -39,26 +43,28 @@ static char *brc_putrecord(char *ptr, char *name, int num, int *list) { return ptr; } -static int brc_changed = 0; -static char brc_buf[BRC_MAXSIZE]; -static char brc_name[BRC_STRLEN]; -static char *fn_boardrc = ".boardrc"; -static int brc_size; +static int brc_changed = 0; +static char brc_buf[BRC_MAXSIZE]; +static char brc_name[BRC_STRLEN]; +static char *fn_boardrc = ".boardrc"; +static int brc_size; -void brc_update() { - if(brc_changed && cuser.userlevel) { - char dirfile[STRLEN], *ptr; - char tmp_buf[BRC_MAXSIZE - BRC_ITEMSIZE], *tmp; - char tmp_name[BRC_STRLEN]; - int tmp_list[BRC_MAXNUM], tmp_num; - int fd, tmp_size; +void +brc_update() +{ + if (brc_changed && cuser.userlevel) { + char dirfile[STRLEN], *ptr; + char tmp_buf[BRC_MAXSIZE - BRC_ITEMSIZE], *tmp; + char tmp_name[BRC_STRLEN]; + int tmp_list[BRC_MAXNUM], tmp_num; + int fd, tmp_size; ptr = brc_buf; - if(brc_num > 0) + if (brc_num > 0) ptr = brc_putrecord(ptr, brc_name, brc_num, brc_list); setuserfile(dirfile, fn_boardrc); - if((fd = open(dirfile, O_RDONLY)) != -1) { + if ((fd = open(dirfile, O_RDONLY)) != -1) { tmp_size = read(fd, tmp_buf, sizeof(tmp_buf)); close(fd); } else { @@ -66,14 +72,14 @@ void brc_update() { } tmp = tmp_buf; - while(tmp < &tmp_buf[tmp_size] && (*tmp >= ' ' && *tmp <= 'z')) { + while (tmp < &tmp_buf[tmp_size] && (*tmp >= ' ' && *tmp <= 'z')) { tmp = brc_getrecord(tmp, tmp_name, &tmp_num, tmp_list); - if(strncmp(tmp_name, currboard, BRC_STRLEN)) + if (strncmp(tmp_name, currboard, BRC_STRLEN)) ptr = brc_putrecord(ptr, tmp_name, tmp_num, tmp_list); } brc_size = (int)(ptr - brc_buf); - if((fd = open(dirfile, O_WRONLY | O_CREAT, 0644)) != -1) { + if ((fd = open(dirfile, O_WRONLY | O_CREAT, 0644)) != -1) { ftruncate(fd, 0); write(fd, brc_buf, brc_size); close(fd); @@ -82,13 +88,15 @@ void brc_update() { } } -static void read_brc_buf() { - char dirfile[STRLEN]; - int fd; +static void +read_brc_buf() +{ + char dirfile[STRLEN]; + int fd; - if(brc_buf[0] == '\0') { + if (brc_buf[0] == '\0') { setuserfile(dirfile, fn_boardrc); - if((fd = open(dirfile, O_RDONLY)) != -1) { + if ((fd = open(dirfile, O_RDONLY)) != -1) { brc_size = read(fd, brc_buf, sizeof(brc_buf)); close(fd); } else { @@ -97,9 +105,11 @@ static void read_brc_buf() { } } -int brc_initial(char *boardname) { - char *ptr; - if(strcmp(currboard, boardname) == 0) { +int +brc_initial(char *boardname) +{ + char *ptr; + if (strcmp(currboard, boardname) == 0) { return brc_num; } brc_update(); @@ -109,7 +119,7 @@ int brc_initial(char *boardname) { read_brc_buf(); ptr = brc_buf; - while(ptr < &brc_buf[brc_size] && (*ptr >= ' ' && *ptr <= 'z')) { + while (ptr < &brc_buf[brc_size] && (*ptr >= ' ' && *ptr <= 'z')) { ptr = brc_getrecord(ptr, brc_name, &brc_num, brc_list); if (strncmp(brc_name, currboard, BRC_STRLEN) == 0) return brc_num; @@ -119,73 +129,79 @@ int brc_initial(char *boardname) { return 0; } -void brc_addlist(char *fname) { - int ftime, n, i; +void +brc_addlist(char *fname) +{ + int ftime, n, i; - if(!cuser.userlevel) + if (!cuser.userlevel) return; ftime = atoi(&fname[2]); - if(ftime <= brc_expire_time - /* || fname[0] != 'M' || fname[1] != '.' */ ) { + if (ftime <= brc_expire_time + /* || fname[0] != 'M' || fname[1] != '.' */ ) { return; } - if(brc_num <= 0) { + if (brc_num <= 0) { brc_list[brc_num++] = ftime; brc_changed = 1; return; } - if((brc_num == 1) && (ftime < brc_list[0])) + if ((brc_num == 1) && (ftime < brc_list[0])) return; - for(n = 0; n < brc_num; n++) { - if(ftime == brc_list[n]) { + for (n = 0; n < brc_num; n++) { + if (ftime == brc_list[n]) { return; - } else if(ftime > brc_list[n]) { - if(brc_num < BRC_MAXNUM) + } else if (ftime > brc_list[n]) { + if (brc_num < BRC_MAXNUM) brc_num++; - for(i = brc_num - 1; --i >= n; brc_list[i + 1] = brc_list[i]); + for (i = brc_num - 1; --i >= n; brc_list[i + 1] = brc_list[i]); brc_list[n] = ftime; brc_changed = 1; return; } } - if(brc_num < BRC_MAXNUM) { + if (brc_num < BRC_MAXNUM) { brc_list[brc_num++] = ftime; brc_changed = 1; } } -static int brc_unread_time(time_t ftime, int bnum, int *blist) { - int n; +static int +brc_unread_time(time_t ftime, int bnum, int *blist) +{ + int n; - if(ftime <= brc_expire_time ) + if (ftime <= brc_expire_time) return 0; - if(brc_num <= 0) + if (brc_num <= 0) return 1; - for(n = 0; n < bnum; n++) { - if(ftime > blist[n]) + for (n = 0; n < bnum; n++) { + if (ftime > blist[n]) return 1; - else if(ftime == blist[n]) + else if (ftime == blist[n]) return 0; } return 0; } -int brc_unread(char *fname, int bnum, int *blist) { - int ftime, n; +int +brc_unread(char *fname, int bnum, int *blist) +{ + int ftime, n; ftime = atoi(&fname[2]); - if(ftime <= brc_expire_time ) + if (ftime <= brc_expire_time) return 0; - if(brc_num <= 0) + if (brc_num <= 0) return 1; - for(n = 0; n < bnum; n++) { - if(ftime > blist[n]) + for (n = 0; n < bnum; n++) { + if (ftime > blist[n]) return 1; - else if(ftime == blist[n]) + else if (ftime == blist[n]) return 0; } return 0; @@ -197,96 +213,102 @@ int brc_unread(char *fname, int bnum, int *blist) { #define BRD_TAG 8 typedef struct { - int bid, *total; - time_t *lastposttime; - boardheader_t *bh; - unsigned int myattr; -} boardstat_t; + int bid, *total; + time_t *lastposttime; + boardheader_t *bh; + unsigned int myattr; +} boardstat_t; -static int *zapbuf=NULL,*favbuf; -static boardstat_t *nbrd=NULL; +static int *zapbuf = NULL, *favbuf; +static boardstat_t *nbrd = NULL; #define STR_BBSRC ".bbsrc" #define STR_FAV ".fav" -void init_brdbuf() { - register int n, size; - char fname[60]; +void +init_brdbuf() +{ + register int n, size; + char fname[60]; /* MAXBOARDS ==> 至多看得見 32 個新板 */ n = numboards + 32; size = n * sizeof(int); - zapbuf = (int *) malloc(size); - favbuf = (int *) malloc(size + sizeof(int)); + zapbuf = (int *)malloc(size); + favbuf = (int *)malloc(size + sizeof(int)); - favbuf[0] = 0x5c4d3e; /* for check memory */ + favbuf[0] = 0x5c4d3e; /* for check memory */ ++favbuf; - memset(favbuf,0,size); + memset(favbuf, 0, size); - while(n) + while (n) zapbuf[--n] = login_start_time; setuserfile(fname, STR_BBSRC); - if((n = open(fname, O_RDONLY, 0600)) != -1) { + if ((n = open(fname, O_RDONLY, 0600)) != -1) { read(n, zapbuf, size); close(n); } setuserfile(fname, STR_FAV); - if((n = open(fname, O_RDONLY, 0600)) != -1) { + if ((n = open(fname, O_RDONLY, 0600)) != -1) { read(n, favbuf, size); close(n); } + for (n = 0; n < numboards; n++) + favbuf[n] &= ~BRD_TAG; - for(n = 0; n < numboards; n++) - favbuf[n] &= ~BRD_TAG; - brc_expire_time = login_start_time - 365 * 86400; } -void save_brdbuf() { - int fd, size; - char fname[60]; +void +save_brdbuf() +{ + int fd, size; + char fname[60]; - if(!zapbuf) return; + if (!zapbuf) + return; setuserfile(fname, STR_BBSRC); - if((fd = open(fname, O_WRONLY | O_CREAT, 0600)) != -1) { + if ((fd = open(fname, O_WRONLY | O_CREAT, 0600)) != -1) { size = numboards * sizeof(int); write(fd, zapbuf, size); close(fd); } - if( favbuf[-1] != 0x5c4d3e ){ - FILE *fp = fopen(BBSHOME "/log/memorybad", "a"); + if (favbuf[-1] != 0x5c4d3e) { + FILE *fp = fopen(BBSHOME "/log/memorybad", "a"); fprintf(fp, "%s %s %d\n", cuser.userid, Cdatelite(&now), favbuf[-1]); fclose(fp); return; } setuserfile(fname, STR_FAV); - if((fd = open(fname, O_WRONLY | O_CREAT, 0600)) != -1) { + if ((fd = open(fname, O_WRONLY | O_CREAT, 0600)) != -1) { size = numboards * sizeof(int); write(fd, favbuf, size); close(fd); } } -int Ben_Perm(boardheader_t *bptr) { - register int level,brdattr; - register char *ptr; +int +Ben_Perm(boardheader_t * bptr) +{ + register int level, brdattr; + register char *ptr; level = bptr->level; brdattr = bptr->brdattr; - if(HAS_PERM(PERM_SYSOP)) + if (HAS_PERM(PERM_SYSOP)) return 1; ptr = bptr->BM; - if(is_BM(ptr)) + if (is_BM(ptr)) return 1; /* 祕密看板:核對首席板主的好友名單 */ - if(brdattr & BRD_HIDE) { /* 隱藏 */ - if( hbflcheck((int)(bptr-bcache) + 1, currutmp->uid) ){ - if(brdattr & BRD_POSTMASK) + if (brdattr & BRD_HIDE) { /* 隱藏 */ + if (hbflcheck((int)(bptr - bcache) + 1, currutmp->uid)) { + if (brdattr & BRD_POSTMASK) return 0; else return 2; @@ -294,18 +316,20 @@ int Ben_Perm(boardheader_t *bptr) { return 1; } /* 限制閱讀權限 */ - if(level && !(brdattr & BRD_POSTMASK) && !HAS_PERM(level)) + if (level && !(brdattr & BRD_POSTMASK) && !HAS_PERM(level)) return 0; return 1; } #if 0 -static int have_author(char* brdname) { - char dirname[100]; +static int +have_author(char *brdname) +{ + char dirname[100]; sprintf(dirname, "正在搜尋作者%s 看板:%s.....", - currauthor,brdname); + currauthor, brdname); move(b_lines, 0); clrtoeol(); outs(dirname); @@ -318,28 +342,31 @@ static int have_author(char* brdname) { } #endif -static int check_newpost(boardstat_t *ptr) { /* Ptt 改 */ - int tbrc_list[BRC_MAXNUM], tbrc_num; - char bname[BRC_STRLEN]; - char *po; - time_t ftime; +static int +check_newpost(boardstat_t * ptr) +{ /* Ptt 改 */ + int tbrc_list[BRC_MAXNUM], tbrc_num; + char bname[BRC_STRLEN]; + char *po; + time_t ftime; ptr->myattr &= ~BRD_UNREAD; - if(ptr->bh->brdattr & BRD_GROUPBOARD) + if (ptr->bh->brdattr & BRD_GROUPBOARD) return 0; - if(*(ptr->total) == 0) - setbtotal(ptr->bid); - if(*(ptr->total) == 0) return 0; + if (*(ptr->total) == 0) + setbtotal(ptr->bid); + if (*(ptr->total) == 0) + return 0; ftime = *(ptr->lastposttime); read_brc_buf(); po = brc_buf; - while(po < &brc_buf[brc_size] && (*po >= ' ' && *po <= 'z')) { + while (po < &brc_buf[brc_size] && (*po >= ' ' && *po <= 'z')) { po = brc_getrecord(po, bname, &tbrc_num, tbrc_list); - if(strncmp(bname, ptr->bh->brdname, BRC_STRLEN) == 0) { - if(brc_unread_time(ftime,tbrc_num,tbrc_list)) { + if (strncmp(bname, ptr->bh->brdname, BRC_STRLEN) == 0) { + if (brc_unread_time(ftime, tbrc_num, tbrc_list)) { ptr->myattr |= BRD_UNREAD; - } + } return 1; } } @@ -348,168 +375,180 @@ static int check_newpost(boardstat_t *ptr) { /* Ptt return 1; } -static int brdnum; -static int yank_flag = 1; -static void load_uidofgid(const int gid, const int type){ - boardheader_t *bptr,*currbptr; - int n, childcount=0; - currbptr = &bcache[gid-1]; - for( n = 0 ; n < numboards ; ++n ){ - bptr = SHM->bsorted[type][n]; - if( bptr->brdname[0] == '\0' ) - continue; - if( bptr->gid == gid ){ - if(currbptr == &bcache[gid-1]) - currbptr->firstchild[type]=bptr; - else{ - currbptr->next[type]=bptr; - currbptr->parent=&bcache[gid-1]; - } - childcount++; - currbptr=bptr; - } - } - bcache[gid-1].childcount=childcount; - if(currbptr == &bcache[gid-1]) - currbptr->firstchild[type]=(boardheader_t *) ~0; - else - currbptr->next[type]=(boardheader_t *) ~0; +static int brdnum; +static int yank_flag = 1; +static void +load_uidofgid(const int gid, const int type) +{ + boardheader_t *bptr, *currbptr; + int n, childcount = 0; + currbptr = &bcache[gid - 1]; + for (n = 0; n < numboards; ++n) { + bptr = SHM->bsorted[type][n]; + if (bptr->brdname[0] == '\0') + continue; + if (bptr->gid == gid) { + if (currbptr == &bcache[gid - 1]) + currbptr->firstchild[type] = bptr; + else { + currbptr->next[type] = bptr; + currbptr->parent = &bcache[gid - 1]; + } + childcount++; + currbptr = bptr; + } + } + bcache[gid - 1].childcount = childcount; + if (currbptr == &bcache[gid - 1]) + currbptr->firstchild[type] = (boardheader_t *) ~ 0; + else + currbptr->next[type] = (boardheader_t *) ~ 0; } -static boardstat_t * addnewbrdstat(int n, int state) +static boardstat_t * +addnewbrdstat(int n, int state) { - boardstat_t *ptr=&nbrd[brdnum++]; - boardheader_t *bptr = &bcache[n]; - ptr->total = &(SHM->total[n]); - ptr->lastposttime = &(SHM->lastposttime[n]); - ptr->bid = n+1; - ptr->myattr=0; - ptr->myattr=(favbuf[n]&~BRD_ZAP); - if(zapbuf[n] == 0) - ptr->myattr|=BRD_ZAP; - ptr->bh = bptr; - if((bptr->brdattr & BRD_HIDE) && state == 1) - bptr->brdattr |= BRD_POSTMASK; - check_newpost(ptr); - return ptr; + boardstat_t *ptr = &nbrd[brdnum++]; + boardheader_t *bptr = &bcache[n]; + ptr->total = &(SHM->total[n]); + ptr->lastposttime = &(SHM->lastposttime[n]); + ptr->bid = n + 1; + ptr->myattr = 0; + ptr->myattr = (favbuf[n] & ~BRD_ZAP); + if (zapbuf[n] == 0) + ptr->myattr |= BRD_ZAP; + ptr->bh = bptr; + if ((bptr->brdattr & BRD_HIDE) && state == 1) + bptr->brdattr |= BRD_POSTMASK; + check_newpost(ptr); + return ptr; } -static int cmpboardfriends(const void *brd, const void *tmp) +static int +cmpboardfriends(const void *brd, const void *tmp) { - return ((boardstat_t *)tmp)->bh->nuser - ((boardstat_t *)brd)->bh->nuser; + return ((boardstat_t *) tmp)->bh->nuser - ((boardstat_t *) brd)->bh->nuser; } -static void load_boards(char *key) { - boardheader_t *bptr = NULL; - int type=cuser.uflag & BRDSORT_FLAG?1:0; - register int i,n; - register int state ; - - if(class_bid>0) - { - bptr = &bcache[class_bid-1]; - if(bptr->firstchild[type]==NULL || bptr->childcount<=0) - load_uidofgid(class_bid,type); - } +static void +load_boards(char *key) +{ + boardheader_t *bptr = NULL; + int type = cuser.uflag & BRDSORT_FLAG ? 1 : 0; + register int i, n; + register int state; + + if (class_bid > 0) { + bptr = &bcache[class_bid - 1]; + if (bptr->firstchild[type] == NULL || bptr->childcount <= 0) + load_uidofgid(class_bid, type); + } brdnum = 0; - if(class_bid<=0){ - nbrd = (boardstat_t *)malloc(numboards * sizeof(boardstat_t)); - for(i=0 ; i < numboards; i++){ - if( (bptr = SHM->bsorted[type][i]) == NULL ) + if (class_bid <= 0) { + nbrd = (boardstat_t *) malloc(numboards * sizeof(boardstat_t)); + for (i = 0; i < numboards; i++) { + if ((bptr = SHM->bsorted[type][i]) == NULL) continue; n = (int)(bptr - bcache); - if( !bptr->brdname[0] || bptr->brdattr & BRD_GROUPBOARD || + if (!bptr->brdname[0] || bptr->brdattr & BRD_GROUPBOARD || !((state = Ben_Perm(bptr)) || (currmode & MODE_MENU)) || (yank_flag == 0 && !(favbuf[n] & BRD_FAV)) || (yank_flag == 1 && !zapbuf[n]) || (key[0] && !strcasestr(bptr->title, key)) || - (class_bid == -1 && bptr->nuser < 5) ) + (class_bid == -1 && bptr->nuser < 5)) continue; addnewbrdstat(n, state); - if( class_bid == -1 ) + if (class_bid == -1) qsort(nbrd, brdnum, sizeof(boardstat_t), cmpboardfriends); } - } - else{ - nbrd = (boardstat_t *)malloc(bptr->childcount * sizeof(boardstat_t)); - for(bptr=bptr->firstchild[type]; bptr!=(boardheader_t *)~0; - bptr=bptr->next[type]) { - n = (int)( bptr - bcache); - if(!((state = Ben_Perm(bptr)) || (currmode & MODE_MENU)) - ||(yank_flag == 0 && !(favbuf[n] & BRD_FAV)) - ||(yank_flag == 1 && !zapbuf[n]) || - (key[0] && !strcasestr(bptr->title, key))) + } else { + nbrd = (boardstat_t *) malloc(bptr->childcount * sizeof(boardstat_t)); + for (bptr = bptr->firstchild[type]; bptr != (boardheader_t *) ~ 0; + bptr = bptr->next[type]) { + n = (int)(bptr - bcache); + if (!((state = Ben_Perm(bptr)) || (currmode & MODE_MENU)) + || (yank_flag == 0 && !(favbuf[n] & BRD_FAV)) + || (yank_flag == 1 && !zapbuf[n]) || + (key[0] && !strcasestr(bptr->title, key))) continue; addnewbrdstat(n, state); } } } -static int search_board() { - int num; - char genbuf[IDLEN + 2]; +static int +search_board() +{ + int num; + char genbuf[IDLEN + 2]; move(0, 0); clrtoeol(); CreateNameList(); - for(num = 0; num < brdnum; num++) + for (num = 0; num < brdnum; num++) AddNameList(nbrd[num].bh->brdname); namecomplete(MSG_SELECT_BOARD, genbuf); for (num = 0; num < brdnum; num++) - if (!strcasecmp(nbrd[num].bh->brdname, genbuf)) - return num; - return -1; + if (!strcasecmp(nbrd[num].bh->brdname, genbuf)) + return num; + return -1; } -static int unread_position(char *dirfile, boardstat_t *ptr) { - fileheader_t fh; - char fname[FNLEN]; - register int num, fd, step, total; +static int +unread_position(char *dirfile, boardstat_t * ptr) +{ + fileheader_t fh; + char fname[FNLEN]; + register int num, fd, step, total; total = *(ptr->total); num = total + 1; - if((ptr->myattr&BRD_UNREAD) &&(fd = open(dirfile, O_RDWR)) > 0) { - if(!brc_initial(ptr->bh->brdname)) { + if ((ptr->myattr & BRD_UNREAD) && (fd = open(dirfile, O_RDWR)) > 0) { + if (!brc_initial(ptr->bh->brdname)) { num = 1; } else { num = total - 1; step = 4; - while(num > 0) { - lseek(fd, (off_t)(num * sizeof(fh)), SEEK_SET); - if(read(fd, fname, FNLEN) <= 0 || - !brc_unread(fname,brc_num,brc_list)) + while (num > 0) { + lseek(fd, (off_t) (num * sizeof(fh)), SEEK_SET); + if (read(fd, fname, FNLEN) <= 0 || + !brc_unread(fname, brc_num, brc_list)) break; num -= step; - if(step < 32) + if (step < 32) step += step >> 1; } - if(num < 0) + if (num < 0) num = 0; - while(num < total) { - lseek(fd, (off_t)(num * sizeof(fh)), SEEK_SET); - if(read(fd, fname, FNLEN) <= 0 || - brc_unread(fname,brc_num,brc_list)) + while (num < total) { + lseek(fd, (off_t) (num * sizeof(fh)), SEEK_SET); + if (read(fd, fname, FNLEN) <= 0 || + brc_unread(fname, brc_num, brc_list)) break; num++; } } close(fd); } - if(num < 0) + if (num < 0) num = 0; return num; } -static void brdlist_foot() { +static void +brdlist_foot() +{ prints("\033[34;46m 選擇看板 \033[31;47m (c)\033[30m新文章模式 " "\033[31m(v/V)\033[30m標記已讀/未讀 \033[31m(y)\033[30m篩選%s" " \033[31m(z)\033[30m切換選擇 \033[m", - yank_flag==0 ? "最愛" : yank_flag==1 ? "部份" : "全部"); + yank_flag == 0 ? "最愛" : yank_flag == 1 ? "部份" : "全部"); } -static void show_brdlist(int head, int clsflag, int newflag) { - int myrow = 2; - if(class_bid == 1) { +static void +show_brdlist(int head, int clsflag, int newflag) +{ + int myrow = 2; + if (class_bid == 1) { currstat = CLASS; myrow = 6; showtitle("分類看板", BBSName); @@ -517,18 +556,18 @@ static void show_brdlist(int head, int clsflag, int newflag) { move(1, 0); prints( " " - "◣ ╭—\033[33m●\n" - " 寣X \033[m " - "◢█\033[47m☉\033[40m██◣蔌n"); + "◣ ╭—\033[33m●\n" + " 寣X \033[m " + "◢█\033[47m☉\033[40m██◣蔌n"); prints( - " \033[44m ︿︿︿︿︿︿︿︿ " - "\033[33m鱋033[m\033[44m ◣◢███▼▼▼ \033[m\n" - " \033[44m " - "\033[33m \033[m\033[44m ◤◥███▲▲▲ 鱋033[m\n" + " \033[44m ︿︿︿︿︿︿︿︿ " + "\033[33m鱋033[m\033[44m ◣◢███▼▼▼ \033[m\n" + " \033[44m " + "\033[33m \033[m\033[44m ◤◥███▲▲▲ 鱋033[m\n" " ︿︿︿︿︿︿︿︿ \033[33m" - "│\033[m ◥████◤ 鱋n" - " \033[33m" - "——\033[m ◤ —+\033[m"); + "│\033[m ◥████◤ 鱋n" + " \033[33m" + "——\033[m ◤ —+\033[m"); } else if (clsflag) { showtitle("看板列表", BBSName); prints("[←]主選單 [→]閱\讀 [↑↓]選擇 [y]載入 [S]排序 [/]搜尋 " @@ -539,63 +578,63 @@ static void show_brdlist(int head, int clsflag, int newflag) { move(b_lines, 0); brdlist_foot(); } - - if(brdnum > 0) { - boardstat_t *ptr; - static char *color[8]={"","\033[32m", - "\033[33m","\033[36m","\033[34m","\033[1m", - "\033[1;32m","\033[1;33m"}; - static char *unread[2]={"\33[37m \033[m","\033[1;31mˇ\033[m"}; - - while(++myrow < b_lines) { + if (brdnum > 0) { + boardstat_t *ptr; + static char *color[8] = {"", "\033[32m", + "\033[33m", "\033[36m", "\033[34m", "\033[1m", + "\033[1;32m", "\033[1;33m"}; + static char *unread[2] = {"\33[37m \033[m", "\033[1;31mˇ\033[m"}; + + while (++myrow < b_lines) { move(myrow, 0); clrtoeol(); - if(head < brdnum) { + if (head < brdnum) { ptr = &nbrd[head++]; - if(class_bid == 1) + if (class_bid == 1) prints(" "); - if(!newflag) { + if (!newflag) { prints("%5d%c%s", head, - !(ptr->bh->brdattr & BRD_HIDE) ? ' ': + !(ptr->bh->brdattr & BRD_HIDE) ? ' ' : (ptr->bh->brdattr & BRD_POSTMASK) ? ')' : '-', (ptr->myattr & BRD_TAG) ? "D " : (ptr->myattr & BRD_ZAP) ? "- " : (ptr->bh->brdattr & BRD_GROUPBOARD) ? " " : - unread[ptr->myattr&BRD_UNREAD]); - } else if(ptr->myattr&BRD_ZAP) { + unread[ptr->myattr & BRD_UNREAD]); + } else if (ptr->myattr & BRD_ZAP) { ptr->myattr &= ~BRD_UNREAD; prints(" ﹣ ﹣"); } else { - if(newflag) { - if((ptr->bh->brdattr & BRD_GROUPBOARD)) - prints(" "); - else + if (newflag) { + if ((ptr->bh->brdattr & BRD_GROUPBOARD)) + prints(" "); + else prints("%6d%s", (int)(*(ptr->total)), - unread[ptr->myattr&BRD_UNREAD]); + unread[ptr->myattr & BRD_UNREAD]); } } - if(class_bid != 1) { - prints("%s%-13s\033[m%s%5.5s\033[0;37m%2.2s\033[m" - "%-34.34s", - (ptr->myattr & BRD_FAV)?"\033[1;36m":"", + if (class_bid != 1) { + prints("%s%-13s\033[m%s%5.5s\033[0;37m%2.2s\033[m" + "%-34.34s", + (ptr->myattr & BRD_FAV) ? "\033[1;36m" : "", ptr->bh->brdname, color[(unsigned int) - (ptr->bh->title[1] + ptr->bh->title[2] + - ptr->bh->title[3] + ptr->bh->title[0]) & 07], - ptr->bh->title, ptr->bh->title+5, ptr->bh->title+7); - - if (ptr->bh->brdattr & BRD_BAD) - prints(" X "); - else if(ptr->bh->nuser>=100) - prints("\033[1mHOT\033[m"); - else if(ptr->bh->nuser>50) - prints("\033[1;31m%2d\033[m ",ptr->bh->nuser); - else if(ptr->bh->nuser>10) - prints("\033[1;33m%2d\033[m ",ptr->bh->nuser); - else if(ptr->bh->nuser>0) - prints("%2d ",ptr->bh->nuser); - else prints(" %c ", ptr->bh->bvote? 'V':' '); - prints("%.13s", ptr->bh->BM); + (ptr->bh->title[1] + ptr->bh->title[2] + + ptr->bh->title[3] + ptr->bh->title[0]) & 07], + ptr->bh->title, ptr->bh->title + 5, ptr->bh->title + 7); + + if (ptr->bh->brdattr & BRD_BAD) + prints(" X "); + else if (ptr->bh->nuser >= 100) + prints("\033[1mHOT\033[m"); + else if (ptr->bh->nuser > 50) + prints("\033[1;31m%2d\033[m ", ptr->bh->nuser); + else if (ptr->bh->nuser > 10) + prints("\033[1;33m%2d\033[m ", ptr->bh->nuser); + else if (ptr->bh->nuser > 0) + prints("%2d ", ptr->bh->nuser); + else + prints(" %c ", ptr->bh->bvote ? 'V' : ' '); + prints("%.13s", ptr->bh->BM); refresh(); } else { prints("%-40.40s %.13s", ptr->bh->title + 7, ptr->bh->BM); @@ -606,7 +645,7 @@ static void show_brdlist(int head, int clsflag, int newflag) { } } -static char *choosebrdhelp[] = { +static char *choosebrdhelp[] = { "\0看板選單輔助說明", "\01基本指令", "(p)(↑)/(n)(↓)上一個看板 / 下一個看板", @@ -631,60 +670,66 @@ static char *choosebrdhelp[] = { }; -static void set_menu_BM(char *BM) { - if(HAS_PERM(PERM_ALLBOARD) || is_BM(BM)) { +static void +set_menu_BM(char *BM) +{ + if (HAS_PERM(PERM_ALLBOARD) || is_BM(BM)) { currmode |= MODE_MENU; cuser.userlevel |= PERM_SYSSUBOP; } } -static char *privateboard = +static char *privateboard = "\n\n\n\n 對不起 此板目前只准看板好友進入 請先向板主申請入境許\可"; -static void dozap(int num){ - boardstat_t *ptr; - ptr = &nbrd[num]; - ptr->myattr ^= BRD_ZAP; - if(ptr->bh->brdattr & BRD_NOZAP) ptr->myattr &= ~BRD_ZAP; - if(!(ptr->myattr & BRD_ZAP) ) check_newpost(ptr); - zapbuf[ptr->bid-1] = (ptr->myattr&BRD_ZAP?0:login_start_time); +static void +dozap(int num) +{ + boardstat_t *ptr; + ptr = &nbrd[num]; + ptr->myattr ^= BRD_ZAP; + if (ptr->bh->brdattr & BRD_NOZAP) + ptr->myattr &= ~BRD_ZAP; + if (!(ptr->myattr & BRD_ZAP)) + check_newpost(ptr); + zapbuf[ptr->bid - 1] = (ptr->myattr & BRD_ZAP ? 0 : login_start_time); } -static void choose_board(int newflag) { - static int num = 0; - boardstat_t *ptr; - int head = -1, ch = 0, currmodetmp, tmp,tmp1, bidtmp; - char keyword[13]=""; +static void +choose_board(int newflag) +{ + static int num = 0; + boardstat_t *ptr; + int head = -1, ch = 0, currmodetmp, tmp, tmp1, bidtmp; + char keyword[13] = ""; #if HAVE_SEARCH_ALL - char genbuf[200]; + char genbuf[200]; #endif - + setutmpmode(newflag ? READNEW : READBRD); brdnum = 0; - if(!cuser.userlevel) /* guest yank all boards */ + if (!cuser.userlevel) /* guest yank all boards */ yank_flag = 2; - + do { - if(brdnum <= 0) { + if (brdnum <= 0) { load_boards(keyword); - if(brdnum <= 0) { - if(keyword[0]!=0) - { - mprints(b_lines-1,0,"沒有任何看板標題有此關鍵字 " - "(板主應注意看板標題命名)"); - pressanykey(); - keyword[0]=0; - brdnum = -1; - continue; - } - if(yank_flag<2) - { - brdnum = -1; - yank_flag++; - continue; - } - if(HAS_PERM(PERM_SYSOP) || (currmode & MODE_MENU)) { - if(m_newbrd(0) == -1) + if (brdnum <= 0) { + if (keyword[0] != 0) { + mprints(b_lines - 1, 0, "沒有任何看板標題有此關鍵字 " + "(板主應注意看板標題命名)"); + pressanykey(); + keyword[0] = 0; + brdnum = -1; + continue; + } + if (yank_flag < 2) { + brdnum = -1; + yank_flag++; + continue; + } + if (HAS_PERM(PERM_SYSOP) || (currmode & MODE_MENU)) { + if (m_newbrd(0) == -1) break; brdnum = -1; continue; @@ -693,51 +738,49 @@ static void choose_board(int newflag) { } head = -1; } - - if(num < 0) + if (num < 0) num = 0; - else if(num >= brdnum) + else if (num >= brdnum) num = brdnum - 1; - - if(head < 0) { - if(newflag) { + + if (head < 0) { + if (newflag) { tmp = num; - while(num < brdnum) { + while (num < brdnum) { ptr = &nbrd[num]; - if(ptr->myattr&BRD_UNREAD) + if (ptr->myattr & BRD_UNREAD) break; num++; } - if(num >= brdnum) + if (num >= brdnum) num = tmp; } head = (num / p_lines) * p_lines; show_brdlist(head, 1, newflag); - } else if(num < head || num >= head + p_lines) { + } else if (num < head || num >= head + p_lines) { head = (num / p_lines) * p_lines; show_brdlist(head, 0, newflag); } - if(class_bid == 1) + if (class_bid == 1) ch = cursor_key(7 + num - head, 10); else ch = cursor_key(3 + num - head, 0); - - switch(ch) { + + switch (ch) { case Ctrl('W'): - whereami(0,NULL,NULL); - head=-1; + whereami(0, NULL, NULL); + head = -1; break; case 'e': case KEY_LEFT: case EOF: ch = 'q'; case 'q': - if(keyword[0]) - { - keyword[0]=0; - brdnum=-1; - ch=' '; - } + if (keyword[0]) { + keyword[0] = 0; + brdnum = -1; + ch = ' '; + } break; case 'c': show_brdlist(head, 1, newflag ^= 1); @@ -746,7 +789,7 @@ static void choose_board(int newflag) { case 'P': case 'b': case Ctrl('B'): - if(num) { + if (num) { num -= p_lines; break; } @@ -758,7 +801,7 @@ static void choose_board(int newflag) { case KEY_PGDN: case 'N': case Ctrl('F'): - if(num == brdnum - 1) + if (num == brdnum - 1) num = 0; else num += p_lines; @@ -778,10 +821,10 @@ static void choose_board(int newflag) { num = brdnum - 1; break; case 't': - ptr = &nbrd[num]; - ptr->myattr ^= BRD_TAG; - favbuf[ptr->bid-1]=ptr->myattr; - head = 9999; + ptr = &nbrd[num]; + ptr->myattr ^= BRD_TAG; + favbuf[ptr->bid - 1] = ptr->myattr; + head = 9999; case KEY_DOWN: case 'n': case 'j': @@ -800,104 +843,98 @@ static void choose_board(int newflag) { case '7': case '8': case '9': - if((tmp = search_num(ch, brdnum)) >= 0) + if ((tmp = search_num(ch, brdnum)) >= 0) num = tmp; brdlist_foot(); break; - case 'F': - case 'f': - if(class_bid && HAS_PERM(PERM_SYSOP)) - { - bcache[class_bid-1].firstchild[cuser.uflag&BRDSORT_FLAG?1:0] - =NULL; - brdnum = -1; - } + case 'F': + case 'f': + if (class_bid && HAS_PERM(PERM_SYSOP)) { + bcache[class_bid - 1].firstchild[cuser.uflag & BRDSORT_FLAG ? 1 : 0] + = NULL; + brdnum = -1; + } break; case 'h': show_help(choosebrdhelp); show_brdlist(head, 1, newflag); break; case '/': - getdata_buf(b_lines-1,0,"請輸入看板中文關鍵字:", + getdata_buf(b_lines - 1, 0, "請輸入看板中文關鍵字:", keyword, sizeof(keyword), DOECHO); - brdnum=-1; + brdnum = -1; break; case 'S': cuser.uflag ^= BRDSORT_FLAG; brdnum = -1; break; case 'y': - if(class_bid==0) - yank_flag = (yank_flag+1)%3; - else - yank_flag = yank_flag%2+1; + if (class_bid == 0) + yank_flag = (yank_flag + 1) % 3; + else + yank_flag = yank_flag % 2 + 1; brdnum = -1; break; case Ctrl('D'): - for(tmp = 0; tmp < numboards; tmp++) - { - if(favbuf[tmp] & BRD_TAG) - { - favbuf[tmp] &= ~BRD_FAV; - favbuf[tmp] &= ~BRD_TAG; - } - } - brdnum = -1; - break; + for (tmp = 0; tmp < numboards; tmp++) { + if (favbuf[tmp] & BRD_TAG) { + favbuf[tmp] &= ~BRD_FAV; + favbuf[tmp] &= ~BRD_TAG; + } + } + brdnum = -1; + break; case Ctrl('A'): - for(tmp = 0; tmp < numboards; tmp++) - { - if(favbuf[tmp] & BRD_TAG) - { - favbuf[tmp] |= BRD_FAV; - favbuf[tmp] &= ~BRD_TAG; - } - } - brdnum = -1; - break; + for (tmp = 0; tmp < numboards; tmp++) { + if (favbuf[tmp] & BRD_TAG) { + favbuf[tmp] |= BRD_FAV; + favbuf[tmp] &= ~BRD_TAG; + } + } + brdnum = -1; + break; case Ctrl('T'): - for(tmp = 0; tmp < numboards; tmp++) - favbuf[tmp] &= ~BRD_TAG; - brdnum = -1; - break; - case Ctrl('P'): - if(class_bid!=0 && - (HAS_PERM(PERM_SYSOP) || (currmode & MODE_MENU))) { - for(tmp = 0; tmp < numboards; tmp++) { - boardheader_t *bh=&bcache[tmp]; - if(!(favbuf[tmp]&BRD_TAG) || bh->gid==class_bid) - continue; - favbuf[tmp] &= ~BRD_TAG; - if(bh->gid != class_bid) - { - bh->gid = class_bid; - substitute_record(FN_BOARD, bh, - sizeof(boardheader_t), tmp+1); - reset_board(tmp+1); - log_usies("SetBoardGID", bh->brdname); - } - } - brdnum = -1; - } - break; + for (tmp = 0; tmp < numboards; tmp++) + favbuf[tmp] &= ~BRD_TAG; + brdnum = -1; + break; + case Ctrl('P'): + if (class_bid != 0 && + (HAS_PERM(PERM_SYSOP) || (currmode & MODE_MENU))) { + for (tmp = 0; tmp < numboards; tmp++) { + boardheader_t *bh = &bcache[tmp]; + if (!(favbuf[tmp] & BRD_TAG) || bh->gid == class_bid) + continue; + favbuf[tmp] &= ~BRD_TAG; + if (bh->gid != class_bid) { + bh->gid = class_bid; + substitute_record(FN_BOARD, bh, + sizeof(boardheader_t), tmp + 1); + reset_board(tmp + 1); + log_usies("SetBoardGID", bh->brdname); + } + } + brdnum = -1; + } + break; case 'm': - if(HAS_PERM(PERM_BASIC)) { + if (HAS_PERM(PERM_BASIC)) { ptr = &nbrd[num]; - ptr->myattr ^= BRD_FAV; - favbuf[ptr->bid-1]=ptr->myattr; + ptr->myattr ^= BRD_FAV; + favbuf[ptr->bid - 1] = ptr->myattr; head = 9999; } break; case 'z': - if(HAS_PERM(PERM_BASIC)) { - dozap(num); + if (HAS_PERM(PERM_BASIC)) { + dozap(num); head = 9999; } break; - case 'Z': /* Ptt */ - if(HAS_PERM(PERM_BASIC)) { - for(tmp = 0; tmp < brdnum; tmp++) { - dozap(tmp); + case 'Z': /* Ptt */ + if (HAS_PERM(PERM_BASIC)) { + for (tmp = 0; tmp < brdnum; tmp++) { + dozap(tmp); } head = 9999; } @@ -906,51 +943,50 @@ static void choose_board(int newflag) { case 'V': ptr = &nbrd[num]; brc_initial(ptr->bh->brdname); - if(ch == 'v') { + if (ch == 'v') { ptr->myattr &= ~BRD_UNREAD; - zapbuf[ptr->bid-1] = brc_list[0]=now; - } else - { - zapbuf[ptr->bid-1] = brc_list[0] = 1; - ptr->myattr |= BRD_UNREAD; - } + zapbuf[ptr->bid - 1] = brc_list[0] = now; + } else { + zapbuf[ptr->bid - 1] = brc_list[0] = 1; + ptr->myattr |= BRD_UNREAD; + } brc_num = brc_changed = 1; brc_update(); show_brdlist(head, 0, newflag); break; case 's': - if((tmp = search_board()) == -1) { + if ((tmp = search_board()) == -1) { show_brdlist(head, 1, newflag); break; } num = tmp; case 'E': - if(HAS_PERM(PERM_SYSOP) || (currmode & MODE_MENU)) { + if (HAS_PERM(PERM_SYSOP) || (currmode & MODE_MENU)) { ptr = &nbrd[num]; - move(1,1); + move(1, 1); clrtobot(); m_mod_board(ptr->bh->brdname); brdnum = -1; } break; case 'R': - if(HAS_PERM(PERM_SYSOP) || (currmode & MODE_MENU)) { + if (HAS_PERM(PERM_SYSOP) || (currmode & MODE_MENU)) { m_newbrd(1); brdnum = -1; } break; case 'B': - if(HAS_PERM(PERM_SYSOP) || (currmode & MODE_MENU)) { + if (HAS_PERM(PERM_SYSOP) || (currmode & MODE_MENU)) { m_newbrd(0); brdnum = -1; } break; case 'W': - if(class_bid > 0 && - (HAS_PERM(PERM_SYSOP) || (currmode & MODE_MENU))) { - char buf[128]; - setbpath(buf, bcache[class_bid-1].brdname); - mkdir(buf, 0755) ; //Ptt:開群組目錄 + if (class_bid > 0 && + (HAS_PERM(PERM_SYSOP) || (currmode & MODE_MENU))) { + char buf[128]; + setbpath(buf, bcache[class_bid - 1].brdname); + mkdir(buf, 0755); /* Ptt:開群組目錄 */ b_note_edit_bname(class_bid); brdnum = -1; } @@ -959,92 +995,98 @@ static void choose_board(int newflag) { case '\n': case '\r': case 'r': - { - char buf[STRLEN]; - - ptr = &nbrd[num]; - - if(!(ptr->bh->brdattr & BRD_GROUPBOARD)) { /* 非sub class */ - if(!(ptr->bh->brdattr & BRD_HIDE) || - (ptr->bh->brdattr & BRD_POSTMASK)) { - brc_initial(ptr->bh->brdname); - - if(newflag) { - setbdir(buf, currboard); - tmp = unread_position(buf, ptr); - head = tmp - t_lines / 2; - getkeep(buf, head > 1 ? head : 1, tmp + 1); + { + char buf[STRLEN]; + + ptr = &nbrd[num]; + + if (!(ptr->bh->brdattr & BRD_GROUPBOARD)) { /* 非sub class */ + if (!(ptr->bh->brdattr & BRD_HIDE) || + (ptr->bh->brdattr & BRD_POSTMASK)) { + brc_initial(ptr->bh->brdname); + + if (newflag) { + setbdir(buf, currboard); + tmp = unread_position(buf, ptr); + head = tmp - t_lines / 2; + getkeep(buf, head > 1 ? head : 1, tmp + 1); + } + board_visit_time = zapbuf[ptr->bid - 1]; + if (!(ptr->myattr & BRD_ZAP)) + zapbuf[ptr->bid - 1] = now; + Read(); + check_newpost(ptr); + head = -1; + setutmpmode(newflag ? READNEW : READBRD); + } else { + setbfile(buf, ptr->bh->brdname, FN_APPLICATION); + if (more(buf, YEA) == -1) { + move(1, 0); + clrtobot(); + outs(privateboard); + pressanykey(); + } + head = -1; } - board_visit_time = zapbuf[ptr->bid-1]; - if(!(ptr->myattr&BRD_ZAP)) - zapbuf[ptr->bid-1]=now; - Read(); - check_newpost(ptr); - head = -1; - setutmpmode(newflag ? READNEW : READBRD); - } else { - setbfile(buf, ptr->bh->brdname, FN_APPLICATION); - if(more(buf,YEA)==-1) { - move(1,0); - clrtobot(); - outs(privateboard); - pressanykey(); + } else { /* sub class */ + move(12, 1); + bidtmp = class_bid; + currmodetmp = currmode; + tmp1 = num; + num = 0; + if (!(ptr->bh->brdattr & BRD_TOP)) + class_bid = ptr->bid; + else + class_bid = -1; /* 熱門群組用 */ + + if (!(currmode & MODE_MENU)) /* 如果還沒有小組長權限 */ + set_menu_BM(ptr->bh->BM); + + if (now < ptr->bh->bupdate) { + setbfile(buf, ptr->bh->brdname, fn_notes); + if (more(buf, NA) != -1) + pressanykey(); } - head = -1; + tmp = currutmp->brc_id; + setutmpbid(ptr->bid); + free(nbrd); + choose_board(0); + currmode = currmodetmp; /* 離開板板後就把權限拿掉喔 */ + num = tmp1; + class_bid = bidtmp; + setutmpbid(tmp); + brdnum = -1; } - } else { /* sub class */ - move(12,1); - bidtmp = class_bid; - currmodetmp =currmode; - tmp1=num; - num=0; - if(!(ptr->bh->brdattr & BRD_TOP)) - class_bid = ptr->bid; - else - class_bid = -1; /* 熱門群組用 */ - - if (!(currmode & MODE_MENU))/*如果還沒有小組長權限 */ - set_menu_BM(ptr->bh->BM); - - if(now < ptr->bh->bupdate) { - setbfile(buf, ptr->bh->brdname, fn_notes); - if(more(buf, NA) != -1) - pressanykey(); - } - tmp=currutmp->brc_id; - setutmpbid(ptr->bid); - free(nbrd); - choose_board(0); - currmode = currmodetmp; /* 離開板板後就把權限拿掉喔 */ - num=tmp1; - class_bid = bidtmp; - setutmpbid(tmp); - brdnum = -1; } } - } - } while(ch != 'q'); + } while (ch != 'q'); free(nbrd); } -int root_board() { +int +root_board() +{ class_bid = 1; yank_flag = 1; choose_board(0); return 0; } -int Boards() { +int +Boards() +{ class_bid = 0; - yank_flag = 0; + yank_flag = 0; choose_board(0); return 0; } -int New() { - int mode0 = currutmp->mode; - int stat0 = currstat; +int +New() +{ + int mode0 = currutmp->mode; + int stat0 = currstat; class_bid = 0; choose_board(1); @@ -1054,48 +1096,28 @@ int New() { } /* -int v_favorite(){ - char fname[256]; - char inbuf[2048]; - FILE* fp; - int nGroup; - char* strtmp; - - setuserfile(fname,str_favorite); - - if (!(fp=fopen(fname,"r"))) - return -1; - move(0,0); - clrtobot(); - fgets(inbuf,sizeof(inbuf),fp); - nGroup=atoi(inbuf); - - currutmp->nGroup=0; - currutmp->ninRoot=0; - - while(nGroup!=currutmp->nGroup+1){ - fgets(inbuf,sizeof(inbuf),fp); - prints("%s\n",strtmp=strtok(inbuf," \n")); - strcpy(currutmp->gfavorite[currutmp->nGroup++],strtmp); - while((strtmp=strtok(NULL, " \n"))){ - prints(" %s %d\n",strtmp,getbnum(strtmp)); - } - currutmp->nGroup++; - } - prints("+++%d+++\n",currutmp->nGroup); - - fgets(inbuf,sizeof(inbuf),fp); - - for(strtmp=strtok(inbuf, " \n");strtmp;strtmp=strtok(NULL, " \n")){ - if (strtmp[0]!='#') - prints("*** %s %d\n",strtmp, getbnum(strtmp)); - else - prints("*** %s %d\n",strtmp+1, -1); - currutmp->ninRoot++; - } - - fclose(fp); - pressanykey(); - return 0; -} -*/ + * int v_favorite(){ char fname[256]; char inbuf[2048]; FILE* fp; int nGroup; + * char* strtmp; + * + * setuserfile(fname,str_favorite); + * + * if (!(fp=fopen(fname,"r"))) return -1; move(0,0); clrtobot(); + * fgets(inbuf,sizeof(inbuf),fp); nGroup=atoi(inbuf); + * + * currutmp->nGroup=0; currutmp->ninRoot=0; + * + * while(nGroup!=currutmp->nGroup+1){ fgets(inbuf,sizeof(inbuf),fp); + * prints("%s\n",strtmp=strtok(inbuf," \n")); + * strcpy(currutmp->gfavorite[currutmp->nGroup++],strtmp); + * while((strtmp=strtok(NULL, " \n"))){ prints(" %s + * %d\n",strtmp,getbnum(strtmp)); } currutmp->nGroup++; } + * prints("+++%d+++\n",currutmp->nGroup); + * + * fgets(inbuf,sizeof(inbuf),fp); + * + * for(strtmp=strtok(inbuf, " \n");strtmp;strtmp=strtok(NULL, " \n")){ if + * (strtmp[0]!='#') prints("*** %s %d\n",strtmp, getbnum(strtmp)); else + * prints("*** %s %d\n",strtmp+1, -1); currutmp->ninRoot++; } + * + * fclose(fp); pressanykey(); return 0; } + */ diff --git a/pttbbs/mbbsd/cache.c b/pttbbs/mbbsd/cache.c index 206b39e3..5f97c503 100644 --- a/pttbbs/mbbsd/cache.c +++ b/pttbbs/mbbsd/cache.c @@ -1,99 +1,115 @@ -/* $Id: cache.c,v 1.40 2002/07/04 19:46:16 in2 Exp $ */ +/* $Id: cache.c,v 1.41 2002/07/05 17:10:26 in2 Exp $ */ #include "bbs.h" #ifndef __FreeBSD__ union semun { - int val; /* value for SETVAL */ - struct semid_ds *buf; /* buffer for IPC_STAT, IPC_SET */ - unsigned short int *array; /* array for GETALL, SETALL */ - struct seminfo *__buf; /* buffer for IPC_INFO */ + int val; /* value for SETVAL */ + struct semid_ds *buf; /* buffer for IPC_STAT, IPC_SET */ + unsigned short int *array; /* array for GETALL, SETALL */ + struct seminfo *__buf; /* buffer for IPC_INFO */ }; #endif -/* the reason for "safe_sleep" is that we may call sleep during - SIGALRM handler routine, while SIGALRM is blocked. - if we use the original sleep, we'll never wake up. */ -unsigned int safe_sleep(unsigned int seconds) { - /* jochang sleep有問題時用*/ - sigset_t set,oldset; - +/* + * the reason for "safe_sleep" is that we may call sleep during SIGALRM + * handler routine, while SIGALRM is blocked. if we use the original sleep, + * we'll never wake up. + */ +unsigned int +safe_sleep(unsigned int seconds) +{ + /* jochang sleep有問題時用 */ + sigset_t set, oldset; + sigemptyset(&set); sigprocmask(SIG_BLOCK, &set, &oldset); - if(sigismember(&oldset, SIGALRM)) { - unsigned long retv; + if (sigismember(&oldset, SIGALRM)) { + unsigned long retv; #if !defined(_BBS_UTIL_C_) log_usies("SAFE_SLEEP ", "avoid hang"); #endif sigemptyset(&set); - sigaddset(&set,SIGALRM); - sigprocmask(SIG_UNBLOCK,&set,NULL); - retv=sleep(seconds); - sigprocmask(SIG_BLOCK,&set,NULL); + sigaddset(&set, SIGALRM); + sigprocmask(SIG_UNBLOCK, &set, NULL); + retv = sleep(seconds); + sigprocmask(SIG_BLOCK, &set, NULL); return retv; } return sleep(seconds); } #if defined(_BBS_UTIL_C_) -static void setapath(char *buf, char *boardname) { +static void +setapath(char *buf, char *boardname) +{ sprintf(buf, "man/boards/%c/%s", boardname[0], boardname); } -static char *str_dotdir = ".DIR"; +static char *str_dotdir = ".DIR"; -static void setadir(char *buf, char *path) { +static void +setadir(char *buf, char *path) +{ sprintf(buf, "%s/%s", path, str_dotdir); } #endif -static void attach_err(int shmkey, char *name) { +static void +attach_err(int shmkey, char *name) +{ fprintf(stderr, "[%s error] key = %x\n", name, shmkey); fprintf(stderr, "errno = %d: %s\n", errno, strerror(errno)); exit(1); } -void *attach_shm(int shmkey, int shmsize) { - void *shmptr; - int shmid; +void * +attach_shm(int shmkey, int shmsize) +{ + void *shmptr; + int shmid; shmid = shmget(shmkey, shmsize, 0); - if(shmid < 0) { + if (shmid < 0) { shmid = shmget(shmkey, shmsize, IPC_CREAT | 0600); - if(shmid < 0) + if (shmid < 0) attach_err(shmkey, "shmget"); shmptr = (void *)shmat(shmid, NULL, 0); - if(shmptr == (void *)-1) + if (shmptr == (void *)-1) attach_err(shmkey, "shmat"); } else { shmptr = (void *)shmat(shmid, NULL, 0); - if(shmptr == (void *)-1) + if (shmptr == (void *)-1) attach_err(shmkey, "shmat"); } - + return shmptr; } -#define SEM_FLG 0600 /* semaphore mode */ +#define SEM_FLG 0600 /* semaphore mode */ /* ----------------------------------------------------- */ /* semaphore : for critical section */ /* ----------------------------------------------------- */ -void sem_init(int semkey,int *semid) { - union semun s; +void +sem_init(int semkey, int *semid) +{ + union semun s; - s.val=1; + s.val = 1; *semid = semget(semkey, 1, 0); - if(*semid == -1) { + if (*semid == -1) { *semid = semget(semkey, 1, IPC_CREAT | SEM_FLG); - if(*semid == -1) + if (*semid == -1) attach_err(semkey, "semget"); semctl(*semid, 0, SETVAL, s); } } -void sem_lock(int op,int semid) { - struct sembuf sops; +void +sem_lock(int op, int semid) +{ + struct sembuf sops; sops.sem_num = 0; sops.sem_flg = SEM_UNDO; @@ -101,94 +117,113 @@ void sem_lock(int op,int semid) { semop(semid, &sops, 1); } -/* uhash *******************************************/ -/* the design is this: - we use another stand-alone program to create and load data into the hash. - (that program could be run in rc-scripts or something like that) - after loading completes, the stand-alone program sets loaded to 1 and exits. - - the bbs exits if it can't attach to the shared memory or - the hash is not loaded yet. -*/ +/* uhash ****************************************** */ +/* + * the design is this: we use another stand-alone program to create and load + * data into the hash. (that program could be run in rc-scripts or something + * like that) after loading completes, the stand-alone program sets loaded to + * 1 and exits. + * + * the bbs exits if it can't attach to the shared memory or the hash is not + * loaded yet. + */ /* attach_uhash should be called before using uhash */ -void attach_SHM(void) +void +attach_SHM(void) { SHM = attach_shm(SHM_KEY, sizeof(SHM_t)); - if( !SHM->loaded ) /* (uhash) assume fresh shared memory is zeroed */ + if (!SHM->loaded) /* (uhash) assume fresh shared memory is + * zeroed */ exit(1); - if( SHM->Btouchtime == 0 ) + if (SHM->Btouchtime == 0) SHM->Btouchtime = 1; bcache = SHM->bcache; - + GLOBALVAR = SHM->GLOBALVAR; - if( SHM->Ptouchtime == 0 ) + if (SHM->Ptouchtime == 0) SHM->Ptouchtime = 1; - if( SHM->Ftouchtime == 0 ) + if (SHM->Ftouchtime == 0) SHM->Ftouchtime = 1; } -void add_to_uhash(int n, char *id) { - int *p, h = StringHash(id); - int times; +void +add_to_uhash(int n, char *id) +{ + int *p, h = StringHash(id); + int times; strcpy(SHM->userid[n], id); - + p = &(SHM->hash_head[h]); - - for( times = 0 ; times < MAX_USERS && *p != -1 ; ++times ) + + for (times = 0; times < MAX_USERS && *p != -1; ++times) p = &(SHM->next_in_hash[*p]); - if( times == MAX_USERS ) + if (times == MAX_USERS) abort_bbs(0); SHM->next_in_hash[*p = n] = -1; } -/* note: after remove_from_uhash(), you should add_to_uhash() - (likely with a different name) */ -void remove_from_uhash(int n) { - int h = StringHash(SHM->userid[n]); - int *p = &(SHM->hash_head[h]); - int times; +/* + * note: after remove_from_uhash(), you should add_to_uhash() (likely with a + * different name) + */ +void +remove_from_uhash(int n) +{ + int h = StringHash(SHM->userid[n]); + int *p = &(SHM->hash_head[h]); + int times; - for( times = 0 ; times < MAX_USERS && (*p != -1 && *p != n); ++times ) + for (times = 0; times < MAX_USERS && (*p != -1 && *p != n); ++times) p = &(SHM->next_in_hash[*p]); - if( times == MAX_USERS ) + if (times == MAX_USERS) abort_bbs(0); - if(*p == n) + if (*p == n) *p = SHM->next_in_hash[n]; } -int setumoney(int uid, int money) { - SHM->money[uid-1]=money; - passwd_update_money(uid); - return SHM->money[uid-1]; +int +setumoney(int uid, int money) +{ + SHM->money[uid - 1] = money; + passwd_update_money(uid); + return SHM->money[uid - 1]; } -int deumoney(int uid, int money) { - if(money<0 && SHM->money[uid-1]<-money) - return setumoney(uid,0); - else - return setumoney(uid,SHM->money[uid-1]+money); +int +deumoney(int uid, int money) +{ + if (money < 0 && SHM->money[uid - 1] < -money) + return setumoney(uid, 0); + else + return setumoney(uid, SHM->money[uid - 1] + money); } -int demoney(int money) { - return deumoney(usernum,money); -} -int moneyof(int uid){ /* ptt 改進金錢處理效率 */ - return SHM->money[uid-1]; +int +demoney(int money) +{ + return deumoney(usernum, money); } -int searchuser(char *userid) { - int h, p, times; +int +moneyof(int uid) +{ /* ptt 改進金錢處理效率 */ + return SHM->money[uid - 1]; +} +int +searchuser(char *userid) +{ + int h, p, times; h = StringHash(userid); p = SHM->hash_head[h]; - - for( times = 0 ; times < MAX_USERS && p != -1 ; ++times ){ - if(strcasecmp(SHM->userid[p],userid) == 0) { - strcpy(userid,SHM->userid[p]); + + for (times = 0; times < MAX_USERS && p != -1; ++times) { + if (strcasecmp(SHM->userid[p], userid) == 0) { + strcpy(userid, SHM->userid[p]); return p + 1; } p = SHM->next_in_hash[p]; @@ -199,70 +234,80 @@ int searchuser(char *userid) { #if !defined(_BBS_UTIL_C_) -int getuser(char *userid) { - int uid; - - if((uid = searchuser(userid))) +int +getuser(char *userid) +{ + int uid; + + if ((uid = searchuser(userid))) passwd_query(uid, &xuser); return uid; } -char *getuserid(int num) { - if(--num >= 0 && num < MAX_USERS) - return ((char *) SHM->userid[num]); +char * +getuserid(int num) +{ + if (--num >= 0 && num < MAX_USERS) + return ((char *)SHM->userid[num]); return NULL; } -void setuserid(int num, char *userid) { - if(num > 0 && num <= MAX_USERS) { - if(num > SHM->number) +void +setuserid(int num, char *userid) +{ + if (num > 0 && num <= MAX_USERS) { + if (num > SHM->number) SHM->number = num; else - remove_from_uhash(num-1); - add_to_uhash(num-1,userid); + remove_from_uhash(num - 1); + add_to_uhash(num - 1, userid); } } /* 0 ==> 找過期帳號 */ /* 1 ==> 建立新帳號 */ /* should do it by searching "" in the hash */ -int searchnewuser(int mode) { - register int i, num; +int +searchnewuser(int mode) +{ + register int i, num; num = SHM->number; i = 0; /* 為什麼這邊不用 hash table 去找而要用 linear search? */ - while(i < num) { - if(!SHM->userid[i++][0]) + while (i < num) { + if (!SHM->userid[i++][0]) return i; } - if(mode && (num < MAX_USERS)) + if (mode && (num < MAX_USERS)) return num + 1; return 0; } -char *u_namearray(char buf[][IDLEN + 1], int *pnum, char *tag) { - register char *ptr, tmp; - register int n, total; - char tagbuf[STRLEN]; - int ch, ch2, num; +char * +u_namearray(char buf[][IDLEN + 1], int *pnum, char *tag) +{ + register char *ptr, tmp; + register int n, total; + char tagbuf[STRLEN]; + int ch, ch2, num; - if(*tag == '\0') { + if (*tag == '\0') { *pnum = SHM->number; return SHM->userid[0]; } - for(n = 0; tag[n]; n++) + for (n = 0; tag[n]; n++) tagbuf[n] = chartoupper(tag[n]); tagbuf[n] = '\0'; ch = tagbuf[0]; ch2 = ch - 'A' + 'a'; total = SHM->number; - for(n = num = 0; n < total; n++) { + for (n = num = 0; n < total; n++) { ptr = SHM->userid[n]; tmp = *ptr; - if(tmp == ch || tmp == ch2) { - if(chkstr(tag, tagbuf, ptr)) + if (tmp == ch || tmp == ch2) { + if (chkstr(tag, tagbuf, ptr)) strcpy(buf[num++], ptr); } } @@ -275,92 +320,110 @@ char *u_namearray(char buf[][IDLEN + 1], int *pnum, char *tag) { /* .UTMP cache */ /*-------------------------------------------------------*/ #if !defined(_BBS_UTIL_C_) -void setutmpmode(int mode) { - if(currstat != mode) +void +setutmpmode(int mode) +{ + if (currstat != mode) currutmp->mode = currstat = mode; - + /* 追蹤使用者 */ - if(HAS_PERM(PERM_LOGUSER)) { - char msg[200]; + if (HAS_PERM(PERM_LOGUSER)) { + char msg[200]; sprintf(msg, "%s setutmpmode to %s(%d) at %s", cuser.userid, modestring(currutmp, 0), mode, Cdate(&now)); log_user(msg); } } #endif -static int cmputmpuserid(const void *i, const void *j){ - return strcasecmp((*((userinfo_t**)i))->userid, (*((userinfo_t**)j))->userid); +static int +cmputmpuserid(const void *i, const void *j) +{ + return strcasecmp((*((userinfo_t **) i))->userid, (*((userinfo_t **) j))->userid); } -static int cmputmpmode(const void *i, const void *j){ - return (*((userinfo_t**)i))->mode-(*((userinfo_t**)j))->mode; -} +static int +cmputmpmode(const void *i, const void *j) +{ + return (*((userinfo_t **) i))->mode - (*((userinfo_t **) j))->mode; +} -static int cmputmpidle(const void *i, const void *j){ - return (*((userinfo_t**)i))->lastact-(*((userinfo_t**)j))->lastact; -} +static int +cmputmpidle(const void *i, const void *j) +{ + return (*((userinfo_t **) i))->lastact - (*((userinfo_t **) j))->lastact; +} -static int cmputmpfrom(const void *i, const void *j){ - return strcasecmp((*((userinfo_t**)i))->from, (*((userinfo_t**)j))->from); -} +static int +cmputmpfrom(const void *i, const void *j) +{ + return strcasecmp((*((userinfo_t **) i))->from, (*((userinfo_t **) j))->from); +} -static int cmputmpfive(const void *i, const void *j){ - int type; - if((type=(*((userinfo_t**)j))->five_win - (*((userinfo_t**)i))->five_win)) - return type; - if((type=(*((userinfo_t**)i))->five_lose - (*((userinfo_t**)j))->five_lose)) - return type; - return (*((userinfo_t**)i))->five_tie-(*((userinfo_t**)j))->five_tie; -} +static int +cmputmpfive(const void *i, const void *j) +{ + int type; + if ((type = (*((userinfo_t **) j))->five_win - (*((userinfo_t **) i))->five_win)) + return type; + if ((type = (*((userinfo_t **) i))->five_lose - (*((userinfo_t **) j))->five_lose)) + return type; + return (*((userinfo_t **) i))->five_tie - (*((userinfo_t **) j))->five_tie; +} #if 0 -static int cmputmpsex(const void *i, const void *j) +static int +cmputmpsex(const void *i, const void *j) { - static int ladyfirst[]={1,0,1,0,1,0,3,3}; - return ladyfirst[(*(userinfo_t**)i)->sex&07]- - ladyfirst[(*(userinfo_t**)j)->sex&07]; + static int ladyfirst[] = {1, 0, 1, 0, 1, 0, 3, 3}; + return ladyfirst[(*(userinfo_t **) i)->sex & 07] - + ladyfirst[(*(userinfo_t **) j)->sex & 07]; } #endif -static int cmputmppid(const void *i, const void *j){ - return (*((userinfo_t**)i))->pid-(*((userinfo_t**)j))->pid; +static int +cmputmppid(const void *i, const void *j) +{ + return (*((userinfo_t **) i))->pid - (*((userinfo_t **) j))->pid; } -static int cmputmpuid(const void *i, const void *j){ - return (*((userinfo_t**)i))->uid-(*((userinfo_t**)j))->uid; +static int +cmputmpuid(const void *i, const void *j) +{ + return (*((userinfo_t **) i))->uid - (*((userinfo_t **) j))->uid; } -void sort_utmp() +void +sort_utmp() { - userinfo_t *uentp; - int count, i, ns; - short nusers[MAX_BOARD]; + userinfo_t *uentp; + int count, i, ns; + short nusers[MAX_BOARD]; now = time(0); - if( now - SHM->UTMPuptime < 60 && - (now == SHM->UTMPuptime || SHM->UTMPbusystate) ) - return; /* lazy sort */ - SHM->UTMPbusystate=1; + if (now - SHM->UTMPuptime < 60 && + (now == SHM->UTMPuptime || SHM->UTMPbusystate)) + return; /* lazy sort */ + SHM->UTMPbusystate = 1; SHM->UTMPuptime = now; ns = (SHM->currsorted ? 0 : 1); - - for( uentp = &SHM->uinfo[0], count = i = 0 ; - i < USHM_SIZE ; - ++i, uentp = &SHM->uinfo[i] ){ - if( uentp->pid ){ - if( uentp->sex < 0 || uentp->sex > 7 ) + + for (uentp = &SHM->uinfo[0], count = i = 0; + i < USHM_SIZE; + ++i, uentp = &SHM->uinfo[i]) { + if (uentp->pid) { + if (uentp->sex < 0 || uentp->sex > 7) purge_utmp(uentp); else SHM->sorted[ns][0][count++] = uentp; - } + } } SHM->UTMPnumber = count; - qsort(SHM->sorted[ns][0], count, sizeof(userinfo_t*), cmputmpuserid); - for( i = 0 ; i < count ; ++i ) - ((userinfo_t*)SHM->sorted[ns][0][i])->idoffset = i; - memcpy(SHM->sorted[ns][1],SHM->sorted[ns][0], sizeof(userinfo_t*) * count); - memcpy(SHM->sorted[ns][2],SHM->sorted[ns][0], sizeof(userinfo_t*) * count); - memcpy(SHM->sorted[ns][3],SHM->sorted[ns][0], sizeof(userinfo_t*) * count); - memcpy(SHM->sorted[ns][4],SHM->sorted[ns][0], sizeof(userinfo_t*) * count); - memcpy(SHM->sorted[ns][5],SHM->sorted[ns][0], sizeof(userinfo_t*) * count); - memcpy(SHM->sorted[ns][6],SHM->sorted[ns][0], sizeof(userinfo_t*) * count); - memcpy(SHM->sorted[ns][7],SHM->sorted[ns][0], sizeof(userinfo_t*) * count); + qsort(SHM->sorted[ns][0], count, sizeof(userinfo_t *), cmputmpuserid); + for (i = 0; i < count; ++i) + ((userinfo_t *) SHM->sorted[ns][0][i])->idoffset = i; + memcpy(SHM->sorted[ns][1], SHM->sorted[ns][0], sizeof(userinfo_t *) * count); + memcpy(SHM->sorted[ns][2], SHM->sorted[ns][0], sizeof(userinfo_t *) * count); + memcpy(SHM->sorted[ns][3], SHM->sorted[ns][0], sizeof(userinfo_t *) * count); + memcpy(SHM->sorted[ns][4], SHM->sorted[ns][0], sizeof(userinfo_t *) * count); + memcpy(SHM->sorted[ns][5], SHM->sorted[ns][0], sizeof(userinfo_t *) * count); + memcpy(SHM->sorted[ns][6], SHM->sorted[ns][0], sizeof(userinfo_t *) * count); + memcpy(SHM->sorted[ns][7], SHM->sorted[ns][0], sizeof(userinfo_t *) * count); qsort(SHM->sorted[ns][1], count, sizeof(userinfo_t *), cmputmpmode); qsort(SHM->sorted[ns][2], count, sizeof(userinfo_t *), cmputmpidle); qsort(SHM->sorted[ns][3], count, sizeof(userinfo_t *), cmputmpfrom); @@ -368,29 +431,31 @@ void sort_utmp() //qsort(SHM->sorted[ns][5], count, sizeof(userinfo_t *), cmputmpsex); qsort(SHM->sorted[ns][6], count, sizeof(userinfo_t *), cmputmpuid); qsort(SHM->sorted[ns][7], count, sizeof(userinfo_t *), cmputmppid); - SHM->currsorted=ns; - SHM->UTMPbusystate=0; + SHM->currsorted = ns; + SHM->UTMPbusystate = 0; memset(nusers, 0, sizeof(nusers)); - for( i = 0 ; i < count ; ++i ){ + for (i = 0; i < count; ++i) { uentp = SHM->sorted[ns][0][i]; - if( uentp && uentp->pid && - 0 < uentp->brc_id && uentp->brc_id < MAX_BOARD ) - ++nusers[ uentp->brc_id - 1 ]; + if (uentp && uentp->pid && + 0 < uentp->brc_id && uentp->brc_id < MAX_BOARD) + ++nusers[uentp->brc_id - 1]; } - for( i = 0 ; i < SHM->Bnumber ; ++i ) - if( SHM->bcache[i].brdname[0] != 0 ) + for (i = 0; i < SHM->Bnumber; ++i) + if (SHM->bcache[i].brdname[0] != 0) SHM->bcache[i].nuser = nusers[i]; } -// Ptt:這邊加入hash觀念 找空的utmp -void getnewutmpent(userinfo_t *up) { - register int i, p ; +//Ptt:這 銗[入hash 觀念找空的utmp + void getnewutmpent(userinfo_t * up) + { + register int i, p; register userinfo_t *uentp; - for(i = 0, p=StringHash(up->userid)%USHM_SIZE; i < USHM_SIZE; i++, p++) { - if(p==USHM_SIZE) p=0; + for (i = 0, p = StringHash(up->userid) % USHM_SIZE; i < USHM_SIZE; i++, p++) { + if (p == USHM_SIZE) + p = 0; uentp = &(SHM->uinfo[p]); - if(!(uentp->pid)) { + if (!(uentp->pid)) { memcpy(uentp, up, sizeof(userinfo_t)); currutmp = uentp; sort_utmp(); @@ -400,75 +465,75 @@ void getnewutmpent(userinfo_t *up) { exit(1); } -int apply_ulist(int (*fptr)(userinfo_t *)) { +int +apply_ulist(int (*fptr) (userinfo_t *)) +{ register userinfo_t *uentp; - register int i, state; + register int i, state; - for(i = 0; i < USHM_SIZE; i++) { + for (i = 0; i < USHM_SIZE; i++) { uentp = &(SHM->uinfo[i]); - if(uentp->pid && (PERM_HIDE(currutmp) || !PERM_HIDE(uentp))) - if((state = (*fptr) (uentp))) + if (uentp->pid && (PERM_HIDE(currutmp) || !PERM_HIDE(uentp))) + if ((state = (*fptr) (uentp))) return state; } return 0; } -userinfo_t *search_ulist(int uid) { - return search_ulistn(uid,1); +userinfo_t * +search_ulist(int uid) +{ + return search_ulistn(uid, 1); } -#if !defined(_BBS_UTIL_C_) -userinfo_t *search_ulist_pid(int pid) { - register int i=0, j, start = 0, end = SHM->UTMPnumber - 1; +#if !defined(_BBS_UTIL_C_) +userinfo_t * +search_ulist_pid(int pid) +{ + register int i = 0, j, start = 0, end = SHM->UTMPnumber - 1; register userinfo_t **ulist; - if( end == -1 ) + if (end == -1) return NULL; - ulist=SHM->sorted[SHM->currsorted][7]; - for(i=((start+end)/2); ;i=(start+end)/2) - { - j=pid-ulist[i]->pid; - if(!j) - { - return (userinfo_t *) (ulist[i]); - } - if(end==start) - { - break; - } - else if(i==start) - { - i=end; - start=end; - } - else if(j>0) start = i; - else end = i; - } + ulist = SHM->sorted[SHM->currsorted][7]; + for (i = ((start + end) / 2);; i = (start + end) / 2) { + j = pid - ulist[i]->pid; + if (!j) { + return (userinfo_t *) (ulist[i]); + } + if (end == start) { + break; + } else if (i == start) { + i = end; + start = end; + } else if (j > 0) + start = i; + else + end = i; + } return 0; } -userinfo_t *search_ulistn(int uid, int unum) +userinfo_t * +search_ulistn(int uid, int unum) { - register int i = 0, j, start = 0, end = SHM->UTMPnumber - 1; + register int i = 0, j, start = 0, end = SHM->UTMPnumber - 1; register userinfo_t **ulist; - if( end == -1 ) + if (end == -1) return NULL; - ulist=SHM->sorted[SHM->currsorted][6]; - for( i = ((start + end) / 2) ; ; i = (start + end) / 2 ){ + ulist = SHM->sorted[SHM->currsorted][6]; + for (i = ((start + end) / 2);; i = (start + end) / 2) { j = uid - ulist[i]->uid; - if( j == 0 ){ - for( ; i > 0 && uid == ulist[i - 1]->uid ; --i ) - ; /* 指到第一筆 */ - if( ulist[i + unum - 1]!=NULL && uid==ulist[i + unum - 1]->uid ) - return (userinfo_t *)(ulist[i + unum - 1]); - break; /* 超過範圍 */ + if (j == 0) { + for (; i > 0 && uid == ulist[i - 1]->uid; --i); /* 指到第一筆 */ + if (ulist[i + unum - 1] != NULL && uid == ulist[i + unum - 1]->uid) + return (userinfo_t *) (ulist[i + unum - 1]); + break; /* 超過範圍 */ } - if(end==start){ + if (end == start) { break; - } - else if(i == start){ + } else if (i == start) { i = end; start = end; - } - else if( j > 0 ) + } else if (j > 0) start = i; else end = i; @@ -476,44 +541,43 @@ userinfo_t *search_ulistn(int uid, int unum) return 0; } -int count_logins(int uid, int show) { - register int i=0, j, start = 0, end = SHM->UTMPnumber - 1, count; +int +count_logins(int uid, int show) +{ + register int i = 0, j, start = 0, end = SHM->UTMPnumber - 1, count; register userinfo_t **ulist; - if( end == -1 ) + if (end == -1) return NULL; - ulist=SHM->sorted[SHM->currsorted][6]; - for(i=((start+end)/2); ;i=(start+end)/2) - { - j = uid-ulist[i]->uid; - if(!j) - { - for(;i>0 && uid==ulist[i-1]->uid;i--);/* 指到第一筆 */ - for(count=0;uid==ulist[i+count]->uid;count++) - { - if(show) - prints("(%d) 目前狀態為: %-17.16s(來自 %s)\n", - count+1, modestring(ulist[i+count], 0), - ulist[i+count]->from); - } - return count; - } - if(end==start) - { - break; - } - else if(i==start) - { - i=end; - start=end; - } - else if(j>0) start = i; - else end = i; - } + ulist = SHM->sorted[SHM->currsorted][6]; + for (i = ((start + end) / 2);; i = (start + end) / 2) { + j = uid - ulist[i]->uid; + if (!j) { + for (; i > 0 && uid == ulist[i - 1]->uid; i--); /* 指到第一筆 */ + for (count = 0; uid == ulist[i + count]->uid; count++) { + if (show) + prints("(%d) 目前狀態為: %-17.16s(來自 %s)\n", + count + 1, modestring(ulist[i + count], 0), + ulist[i + count]->from); + } + return count; + } + if (end == start) { + break; + } else if (i == start) { + i = end; + start = end; + } else if (j > 0) + start = i; + else + end = i; + } return 0; } -void purge_utmp(userinfo_t *uentp) { +void +purge_utmp(userinfo_t * uentp) +{ logout_friend_online(uentp); memset(uentp, 0, sizeof(userinfo_t)); } @@ -523,78 +587,89 @@ void purge_utmp(userinfo_t *uentp) { /*-------------------------------------------------------*/ /* .BOARDS cache */ /*-------------------------------------------------------*/ -void touchdircache(int bid) +void +touchdircache(int bid) { - int *i= (int *)&SHM->dircache[bid - 1][0].filename[0]; - *i=0; -} - -void load_fileheader_cache(int bid, char *direct) + int *i = (int *)&SHM->dircache[bid - 1][0].filename[0]; + *i = 0; +} + +void +load_fileheader_cache(int bid, char *direct) { - int num=getbtotal(bid); - int n = num-DIRCACHESIZE+1; - if( SHM->Bbusystate != 1 && now - SHM->busystate_b[bid - 1] >= 10 ){ - SHM->busystate_b[bid-1] = now; - get_records(direct, SHM->dircache[bid - 1] , - sizeof(fileheader_t),n<1?1:n, DIRCACHESIZE); - SHM->busystate_b[bid-1] = 0; - } - else{ + int num = getbtotal(bid); + int n = num - DIRCACHESIZE + 1; + if (SHM->Bbusystate != 1 && now - SHM->busystate_b[bid - 1] >= 10) { + SHM->busystate_b[bid - 1] = now; + get_records(direct, SHM->dircache[bid - 1], + sizeof(fileheader_t), n < 1 ? 1 : n, DIRCACHESIZE); + SHM->busystate_b[bid - 1] = 0; + } else { safe_sleep(1); } } -int get_fileheader_cache(int bid, char *direct, fileheader_t *headers, - int recbase, int nlines) +int +get_fileheader_cache(int bid, char *direct, fileheader_t * headers, + int recbase, int nlines) { - int ret, n,num; + int ret, n, num; - num=getbtotal(bid); + num = getbtotal(bid); - ret = num-recbase+1, - n = (num - DIRCACHESIZE+1); + ret = num - recbase + 1, + n = (num - DIRCACHESIZE + 1); - if(SHM->dircache[bid - 1][0].filename[0]=='\0') - load_fileheader_cache(bid, direct); - if (n<1) - n=recbase-1; + if (SHM->dircache[bid - 1][0].filename[0] == '\0') + load_fileheader_cache(bid, direct); + if (n < 1) + n = recbase - 1; else - n=recbase-n; - if(n<0) n=0; - if (ret>nlines) ret=nlines; - memcpy(headers, &(SHM->dircache[bid - 1][n]),sizeof(fileheader_t)*ret); + n = recbase - n; + if (n < 0) + n = 0; + if (ret > nlines) + ret = nlines; + memcpy(headers, &(SHM->dircache[bid - 1][n]), sizeof(fileheader_t) * ret); return ret; } -static int cmpboardname(boardheader_t **brd, boardheader_t **tmp) { +static int +cmpboardname(boardheader_t ** brd, boardheader_t ** tmp) +{ return strcasecmp((*brd)->brdname, (*tmp)->brdname); -} -static int cmpboardclass(boardheader_t **brd, boardheader_t **tmp) { - return (strncmp((*brd)->title, (*tmp)->title, 4)<<8)+ - strcasecmp((*brd)->brdname, (*tmp)->brdname); } -static void sort_bcache() +static int +cmpboardclass(boardheader_t ** brd, boardheader_t ** tmp) +{ + return (strncmp((*brd)->title, (*tmp)->title, 4) << 8) + + strcasecmp((*brd)->brdname, (*tmp)->brdname); +} +static void +sort_bcache() { - int i; - /*critical section 不能單獨呼叫 呼叫reload_bcache or reset_board */ - for(i=0;i<SHM->Bnumber;i++){ - SHM->bsorted[1][i]=SHM->bsorted[0][i]=&bcache[i]; - } - qsort(SHM->bsorted[0], SHM->Bnumber, sizeof(boardheader_t *), - (QCAST)cmpboardname); - qsort(SHM->bsorted[1], SHM->Bnumber, sizeof(boardheader_t *), - (QCAST)cmpboardclass); -} -static void reload_bcache() { - if( SHM->Bbusystate ){ + int i; + /* critical section 不能單獨呼叫 呼叫reload_bcache or reset_board */ + for (i = 0; i < SHM->Bnumber; i++) { + SHM->bsorted[1][i] = SHM->bsorted[0][i] = &bcache[i]; + } + qsort(SHM->bsorted[0], SHM->Bnumber, sizeof(boardheader_t *), + (QCAST) cmpboardname); + qsort(SHM->bsorted[1], SHM->Bnumber, sizeof(boardheader_t *), + (QCAST) cmpboardclass); +} +static void +reload_bcache() +{ + if (SHM->Bbusystate) { safe_sleep(1); } #if !defined(_BBS_UTIL_C_) else { - int fd,i; + int fd, i; SHM->Bbusystate = 1; - if((fd = open(fn_board, O_RDONLY)) > 0) { + if ((fd = open(fn_board, O_RDONLY)) > 0) { SHM->Bnumber = read(fd, bcache, MAX_BOARD * sizeof(boardheader_t)) / sizeof(boardheader_t); @@ -604,177 +679,189 @@ static void reload_bcache() { /* 等所有 boards 資料更新後再設定 uptime */ SHM->Buptime = SHM->Btouchtime; log_usies("CACHE", "reload bcache"); - sort_bcache(); - for( i = 0 ; i < SHM->Bnumber ; ++i ){ - bcache[i].firstchild[0]=NULL; - bcache[i].firstchild[1]=NULL; + sort_bcache(); + for (i = 0; i < SHM->Bnumber; ++i) { + bcache[i].firstchild[0] = NULL; + bcache[i].firstchild[1] = NULL; } SHM->Bbusystate = 0; } #endif } -void resolve_boards() { - while( SHM->Buptime < SHM->Btouchtime ){ +void +resolve_boards() +{ + while (SHM->Buptime < SHM->Btouchtime) { reload_bcache(); } numboards = SHM->Bnumber; } -void touch_boards() { - SHM->Btouchtime=now; +void +touch_boards() +{ + SHM->Btouchtime = now; numboards = -1; - resolve_boards(); + resolve_boards(); } -void addbrd_touchcache() +void +addbrd_touchcache() { SHM->Bnumber++; - numboards=SHM->Bnumber; - reset_board(numboards); + numboards = SHM->Bnumber; + reset_board(numboards); } #if !defined(_BBS_UTIL_C_) -void reset_board(int bid) { /* Ptt: 這樣就不用老是touch board了 */ - int fd,i,nuser; - boardheader_t *bhdr; - +void +reset_board(int bid) +{ /* Ptt: 這樣就不用老是touch board了 */ + int fd, i, nuser; + boardheader_t *bhdr; - if(--bid < 0) + + if (--bid < 0) return; - if( SHM->Bbusystate || now - SHM->busystate_b[bid - 1] < 10 ){ + if (SHM->Bbusystate || now - SHM->busystate_b[bid - 1] < 10) { safe_sleep(1); } else { - SHM->busystate_b[bid-1] = now; - nuser = bcache[bid-1].nuser; + SHM->busystate_b[bid - 1] = now; + nuser = bcache[bid - 1].nuser; bhdr = bcache; - bhdr += bid; - if((fd = open(fn_board, O_RDONLY)) > 0) { - lseek(fd, (off_t)(bid * sizeof(boardheader_t)), SEEK_SET); + bhdr += bid; + if ((fd = open(fn_board, O_RDONLY)) > 0) { + lseek(fd, (off_t) (bid * sizeof(boardheader_t)), SEEK_SET); read(fd, bhdr, sizeof(boardheader_t)); close(fd); } - sort_bcache(); - for(i=0;i<SHM->Bnumber;i++) - { - bcache[i].firstchild[0]=NULL; - bcache[i].firstchild[1]=NULL; - } - nuser = bcache[bid-1].nuser; - SHM->busystate_b[bid-1] = 0; + sort_bcache(); + for (i = 0; i < SHM->Bnumber; i++) { + bcache[i].firstchild[0] = NULL; + bcache[i].firstchild[1] = NULL; + } + nuser = bcache[bid - 1].nuser; + SHM->busystate_b[bid - 1] = 0; } -} +} -int apply_boards(int (*func)(boardheader_t *)) { - register int i; +int +apply_boards(int (*func) (boardheader_t *)) +{ + register int i; register boardheader_t *bhdr; - - for(i = 0, bhdr = bcache; i < numboards; i++, bhdr++) { - if(!(bhdr->brdattr & BRD_GROUPBOARD) && Ben_Perm(bhdr) && - (*func)(bhdr) == QUIT) + + for (i = 0, bhdr = bcache; i < numboards; i++, bhdr++) { + if (!(bhdr->brdattr & BRD_GROUPBOARD) && Ben_Perm(bhdr) && + (*func) (bhdr) == QUIT) return QUIT; } return 0; } #endif -boardheader_t *getbcache(int bid) { /* Ptt改寫 */ +boardheader_t * +getbcache(int bid) +{ /* Ptt改寫 */ return bcache + bid - 1; } -int getbtotal(int bid) +int +getbtotal(int bid) { return SHM->total[bid - 1]; } -void setbtotal(int bid) { - boardheader_t *bh = getbcache(bid); - struct stat st; - char genbuf[256]; - int num,fd; +void +setbtotal(int bid) +{ + boardheader_t *bh = getbcache(bid); + struct stat st; + char genbuf[256]; + int num, fd; sprintf(genbuf, "boards/%c/%s/.DIR", bh->brdname[0], bh->brdname); - if((fd = open(genbuf, O_RDWR)) < 0) - return; /* .DIR掛了 */ - fstat(fd, &st); - num = st.st_size / sizeof(fileheader_t); + if ((fd = open(genbuf, O_RDWR)) < 0) + return; /* .DIR掛了 */ + fstat(fd, &st); + num = st.st_size / sizeof(fileheader_t); SHM->total[bid - 1] = num; - if(num>0) - { - lseek(fd, (off_t) (num - 1) * sizeof(fileheader_t), SEEK_SET); - if(read(fd, genbuf, FNLEN)>=0) - { - SHM->lastposttime[bid - 1]=(time_t) atoi(&genbuf[2]); + if (num > 0) { + lseek(fd, (off_t) (num - 1) * sizeof(fileheader_t), SEEK_SET); + if (read(fd, genbuf, FNLEN) >= 0) { + SHM->lastposttime[bid - 1] = (time_t) atoi(&genbuf[2]); } - } - else - SHM->lastposttime[bid - 1] = 0; + } else + SHM->lastposttime[bid - 1] = 0; close(fd); - if(num) - touchdircache(bid); + if (num) + touchdircache(bid); } -void touchbpostnum(int bid, int delta) +void +touchbpostnum(int bid, int delta) { - int *total = &SHM->total[bid - 1]; + int *total = &SHM->total[bid - 1]; if (*total) *total += delta; } -int getbnum(char *bname) { - register int i=0, j, start = 0, end = SHM->Bnumber - 1; +int +getbnum(char *bname) +{ + register int i = 0, j, start = 0, end = SHM->Bnumber - 1; register boardheader_t **bhdr; - bhdr=SHM->bsorted[0]; - for(i=((start+end)/2); ;i=(start+end)/2) - { - if(! (j=strcasecmp(bname,bhdr[i]->brdname))) - return (int) (bhdr[i] - bcache +1); - if(end==start) - { - break; - } - else if(i==start) - { - i=end; - start=end; - } - else if(j>0) start = i; - else end = i; - } + bhdr = SHM->bsorted[0]; + for (i = ((start + end) / 2);; i = (start + end) / 2) { + if (!(j = strcasecmp(bname, bhdr[i]->brdname))) + return (int)(bhdr[i] - bcache + 1); + if (end == start) { + break; + } else if (i == start) { + i = end; + start = end; + } else if (j > 0) + start = i; + else + end = i; + } return 0; } #if !defined(_BBS_UTIL_C_) -int haspostperm(char *bname) { - register int i; - char buf[200]; +int +haspostperm(char *bname) +{ + register int i; + char buf[200]; setbfile(buf, bname, fn_water); - if(belong(buf, cuser.userid)) + if (belong(buf, cuser.userid)) return 0; - if(!strcasecmp(bname, DEFAULT_BOARD)) + if (!strcasecmp(bname, DEFAULT_BOARD)) return 1; if (!strcasecmp(bname, "PttLaw")) - return 1; + return 1; - if(!HAS_PERM(PERM_POST)) + if (!HAS_PERM(PERM_POST)) return 0; - - if(!(i = getbnum(bname))) + + if (!(i = getbnum(bname))) return 0; /* 秘密看板特別處理 */ - if(bcache[i - 1].brdattr & BRD_HIDE) + if (bcache[i - 1].brdattr & BRD_HIDE) return 1; i = bcache[i - 1].level; if (HAS_PERM(PERM_VIOLATELAW) && (i & PERM_VIOLATELAW)) - return 1; + return 1; else if (HAS_PERM(PERM_VIOLATELAW)) - return 0; + return 0; return HAS_PERM(i & ~PERM_POST); } @@ -784,15 +871,16 @@ int haspostperm(char *bname) { /* PTT cache */ /*-------------------------------------------------------*/ /* cachefor 動態看板 */ -void reload_pttcache() +void +reload_pttcache() { - if( SHM->Pbusystate ) + if (SHM->Pbusystate) safe_sleep(1); - else { /* jochang: temporary workaround */ - fileheader_t item, subitem; - char pbuf[256], buf[256], *chr; - FILE *fp, *fp1, *fp2; - int id, section = 0; + else { /* jochang: temporary workaround */ + fileheader_t item, subitem; + char pbuf[256], buf[256], *chr; + FILE *fp, *fp1, *fp2; + int id, section = 0; SHM->Pbusystate = 1; SHM->max_film = 0; @@ -800,53 +888,53 @@ void reload_pttcache() setapath(pbuf, "Note"); setadir(buf, pbuf); id = 0; - if((fp = fopen(buf, "r"))) { - while(fread(&item, sizeof(item), 1, fp)) { - if(item.title[3]=='<' && item.title[8]=='>') { - sprintf(buf,"%s/%s", pbuf, item.filename); + if ((fp = fopen(buf, "r"))) { + while (fread(&item, sizeof(item), 1, fp)) { + if (item.title[3] == '<' && item.title[8] == '>') { + sprintf(buf, "%s/%s", pbuf, item.filename); setadir(buf, buf); - if(!(fp1 = fopen(buf, "r"))) + if (!(fp1 = fopen(buf, "r"))) continue; SHM->next_refresh[section] = SHM->n_notes[section] = id; - section ++; - while(fread(&subitem, sizeof(subitem), 1, fp1)) { - sprintf(buf,"%s/%s/%s", pbuf, item.filename , + section++; + while (fread(&subitem, sizeof(subitem), 1, fp1)) { + sprintf(buf, "%s/%s/%s", pbuf, item.filename, subitem.filename); - if(!(fp2=fopen(buf,"r"))) + if (!(fp2 = fopen(buf, "r"))) continue; - fread(SHM->notes[id],sizeof(char), 200*11, fp2); - SHM->notes[id][200*11 - 1]=0; + fread(SHM->notes[id], sizeof(char), 200 * 11, fp2); + SHM->notes[id][200 * 11 - 1] = 0; id++; fclose(fp2); - if(id >= MAX_MOVIE) - break; + if (id >= MAX_MOVIE) + break; } - fclose(fp1); - if(id >= MAX_MOVIE || section >= MAX_MOVIE_SECTION) - break; + fclose(fp1); + if (id >= MAX_MOVIE || section >= MAX_MOVIE_SECTION) + break; } } fclose(fp); } SHM->next_refresh[section] = -1; - SHM->n_notes[section] = SHM->max_film = id-1; + SHM->n_notes[section] = SHM->max_film = id - 1; SHM->max_history = SHM->max_film - 2; - if(SHM->max_history > MAX_HISTORY - 1) + if (SHM->max_history > MAX_HISTORY - 1) SHM->max_history = MAX_HISTORY - 1; - if(SHM->max_history <0) SHM->max_history=0; + if (SHM->max_history < 0) + SHM->max_history = 0; - fp = fopen("etc/today_is","r"); - if(fp) { - fgets(SHM->today_is,15,fp); - if((chr = strchr(SHM->today_is,'\n'))) + fp = fopen("etc/today_is", "r"); + if (fp) { + fgets(SHM->today_is, 15, fp); + if ((chr = strchr(SHM->today_is, '\n'))) *chr = 0; SHM->today_is[15] = 0; fclose(fp); } - /* 等所有資料更新後再設定 uptime */ - SHM->Puptime = SHM->Ptouchtime ; + SHM->Puptime = SHM->Ptouchtime; #if !defined(_BBS_UTIL_C_) log_usies("CACHE", "reload pttcache"); #endif @@ -854,17 +942,20 @@ void reload_pttcache() } } -void resolve_garbage() { - int count=0; - - while(SHM->Puptime < SHM->Ptouchtime) { /* 不用while等 */ +void +resolve_garbage() +{ + int count = 0; + + while (SHM->Puptime < SHM->Ptouchtime) { /* 不用while等 */ reload_pttcache(); - if(count ++ > 10 && SHM->Pbusystate) { -/* Ptt: 這邊會有問題 load超過10 秒會所有進loop的process都讓 busystate = 0 - 這樣會所有prcosee都會在load 動態看板 會造成load大增 - 但沒有用這個function的話 萬一load passwd檔的process死了 又沒有人把他 - 解開 同樣的問題發生在reload passwd -*/ + if (count++ > 10 && SHM->Pbusystate) { + /* + * Ptt: 這邊會有問題 load超過10 秒會所有進loop的process + * tate = 0 這樣會所有prcosee都會在load 動態看板 會造成load大增 + * 但沒有用這個function的話 萬一load passwd檔的process死了 + * 又沒有人把他 解開 同樣的問題發生在reload passwd + */ SHM->Pbusystate = 0; #ifndef _BBS_UTIL_C_ log_usies("CACHE", "refork Ptt dead lock"); @@ -877,36 +968,37 @@ void resolve_garbage() { /* PTT's cache */ /*-------------------------------------------------------*/ /* cachefor from host 與最多上線人數 */ -static void reload_fcache() { - if( SHM->Fbusystate ) +static void +reload_fcache() +{ + if (SHM->Fbusystate) safe_sleep(1); else { - FILE *fp; + FILE *fp; SHM->Fbusystate = 1; bzero(SHM->domain, sizeof(SHM->domain)); - if((fp = fopen("etc/domain_name_query","r"))) { - char buf[256],*po; - - SHM->top=0; - while(fgets(buf, sizeof(buf),fp)) { - if(buf[0] && buf[0] != '#' && buf[0] != ' ' && - buf[0] != '\n') { - sscanf(buf,"%s",SHM->domain[SHM->top]); + if ((fp = fopen("etc/domain_name_query", "r"))) { + char buf[256], *po; + + SHM->top = 0; + while (fgets(buf, sizeof(buf), fp)) { + if (buf[0] && buf[0] != '#' && buf[0] != ' ' && + buf[0] != '\n') { + sscanf(buf, "%s", SHM->domain[SHM->top]); po = buf + strlen(SHM->domain[SHM->top]); - while(*po == ' ') + while (*po == ' ') po++; - strncpy(SHM->replace[SHM->top],po,49); + strncpy(SHM->replace[SHM->top], po, 49); SHM->replace[SHM->top] - [strlen(SHM->replace[SHM->top])-1] = 0; + [strlen(SHM->replace[SHM->top]) - 1] = 0; (SHM->top)++; - if(SHM->top == MAX_FROM) + if (SHM->top == MAX_FROM) break; - } + } } } - - SHM->max_user=0; + SHM->max_user = 0; /* 等所有資料更新後再設定 uptime */ SHM->Fuptime = SHM->Ftouchtime; @@ -917,31 +1009,33 @@ static void reload_fcache() { } } -void resolve_fcache() +void +resolve_fcache() { - while( SHM->Fuptime < SHM->Ftouchtime ) + while (SHM->Fuptime < SHM->Ftouchtime) reload_fcache(); } -void hbflreload(int bid) +void +hbflreload(int bid) { - int hbfl[MAX_FRIEND + 1], i, num, uid; - char buf[128]; - FILE *fp; + int hbfl[MAX_FRIEND + 1], i, num, uid; + char buf[128]; + FILE *fp; memset(hbfl, 0, sizeof(hbfl)); - setbfile(buf, bcache[bid-1].brdname, fn_visable); - if( (fp = fopen(buf, "r")) != NULL ){ - for( num = 1 ; num <= MAX_FRIEND ; ++num ){ - if( fgets(buf, sizeof(buf), fp) == NULL ) + setbfile(buf, bcache[bid - 1].brdname, fn_visable); + if ((fp = fopen(buf, "r")) != NULL) { + for (num = 1; num <= MAX_FRIEND; ++num) { + if (fgets(buf, sizeof(buf), fp) == NULL) break; - for( i = 0 ; buf[i] != 0 ; ++i ) - if( buf[i] == ' ' ){ + for (i = 0; buf[i] != 0; ++i) + if (buf[i] == ' ') { buf[i] = 0; break; } - if( strcasecmp("guest", buf) == 0 || - (uid = searchuser(buf)) == 0 ) { + if (strcasecmp("guest", buf) == 0 || + (uid = searchuser(buf)) == 0) { --num; continue; } @@ -953,47 +1047,50 @@ void hbflreload(int bid) memcpy(SHM->hbfl[bid], hbfl, sizeof(hbfl)); } -int hbflcheck(int bid, int uid) +int +hbflcheck(int bid, int uid) { - int i; + int i; - if( SHM->hbfl[bid][0] < login_start_time - HBFLexpire ) + if (SHM->hbfl[bid][0] < login_start_time - HBFLexpire) hbflreload(bid); - for( i = 1 ; SHM->hbfl[bid][i] != 0 && i <= MAX_FRIEND ; ++i ){ - if( SHM->hbfl[bid][i] == uid ) + for (i = 1; SHM->hbfl[bid][i] != 0 && i <= MAX_FRIEND; ++i) { + if (SHM->hbfl[bid][i] == uid) return 0; } return 1; } #ifdef MDCACHE -char *cachepath(const char *fpath) +char * +cachepath(const char *fpath) { - static char cpath[128]; - char *ptr; + static char cpath[128]; + char *ptr; snprintf(cpath, sizeof(cpath), "cache/%s", fpath); - for( ptr = &cpath[6] ; *ptr != 0 ; ++ptr ) - if( *ptr == '/' ) + for (ptr = &cpath[6]; *ptr != 0; ++ptr) + if (*ptr == '/') *ptr = '.'; return cpath; } -int updatemdcache(const char *CPATH, const char *fpath) +int +updatemdcache(const char *CPATH, const char *fpath) { - /* save file to mdcache with *cpath and *fpath, - return: -1 if error - else the fd - */ - int len, sourcefd, targetfd; - char buf[1024], *cpath; + /* + * save file to mdcache with *cpath and *fpath, return: -1 if error + * else the fd + */ + int len, sourcefd, targetfd; + char buf[1024], *cpath; cpath = (CPATH == NULL) ? cachepath(fpath) : (char *)CPATH; - if( (sourcefd = open(fpath, O_RDONLY)) < 0 ) + if ((sourcefd = open(fpath, O_RDONLY)) < 0) return -1; - if( (targetfd = open(cpath, O_RDWR | O_CREAT | O_TRUNC, 0600)) < 0 ) + if ((targetfd = open(cpath, O_RDWR | O_CREAT | O_TRUNC, 0600)) < 0) /* md is full? */ return -1; - while( (len = read(sourcefd, buf, sizeof(buf))) > 0 ) - if( write(targetfd, buf, len) < len ){ + while ((len = read(sourcefd, buf, sizeof(buf))) > 0) + if (write(targetfd, buf, len) < len) { /* md is full? */ close(targetfd); unlink(cpath); @@ -1005,17 +1102,18 @@ int updatemdcache(const char *CPATH, const char *fpath) return targetfd; } -int mdcacheopen(char *fpath) +int +mdcacheopen(char *fpath) { - int fd; - char *cpath; - if( strncmp(fpath, "boards/", 7) && strncmp(fpath, "etc/", 4) ) + int fd; + char *cpath; + if (strncmp(fpath, "boards/", 7) && strncmp(fpath, "etc/", 4)) return open(fpath, O_RDONLY); #ifdef MDCACHEHITRATE ++GLOBE[0]; #endif - if( (fd = open((cpath = cachepath(fpath)), O_RDONLY)) < 0 ) + if ((fd = open((cpath = cachepath(fpath)), O_RDONLY)) < 0) return updatemdcache(cpath, fpath); #ifdef MDCACHEHITRATE else diff --git a/pttbbs/mbbsd/cal.c b/pttbbs/mbbsd/cal.c index 995f4c55..cd2c0d48 100644 --- a/pttbbs/mbbsd/cal.c +++ b/pttbbs/mbbsd/cal.c @@ -1,48 +1,53 @@ -/* $Id: cal.c,v 1.15 2002/07/05 13:14:14 in2 Exp $ */ +/* $Id: cal.c,v 1.16 2002/07/05 17:10:26 in2 Exp $ */ #include "bbs.h" /* 防堵 Multi play */ -static int count_multiplay(int unmode) { - register int i, j; +static int +count_multiplay(int unmode) +{ + register int i, j; register userinfo_t *uentp; - for(i = j = 0; i < USHM_SIZE; i++) { + for (i = j = 0; i < USHM_SIZE; i++) { uentp = &(SHM->uinfo[i]); - if(uentp->uid == usernum) - if(uentp->lockmode == unmode) + if (uentp->uid == usernum) + if (uentp->lockmode == unmode) j++; } return j; } -int lockutmpmode(int unmode, int state) { - int errorno = 0; - - if(currutmp->lockmode) +int +lockutmpmode(int unmode, int state) +{ + int errorno = 0; + + if (currutmp->lockmode) errorno = 1; - else if(count_multiplay(unmode)) + else if (count_multiplay(unmode)) errorno = 2; - - if(errorno && !(state == LOCK_THIS && errorno == LOCK_MULTI)) { + + if (errorno && !(state == LOCK_THIS && errorno == LOCK_MULTI)) { clear(); - move(10,20); - if(errorno == 1) + move(10, 20); + if (errorno == 1) prints("請先離開 %s 才能再 %s ", ModeTypeTable[currutmp->lockmode], ModeTypeTable[unmode]); - else + else prints("抱歉! 您已有其他線相同的ID正在%s", ModeTypeTable[unmode]); pressanykey(); return errorno; } - setutmpmode(unmode); currutmp->lockmode = unmode; return 0; } -int unlockutmpmode() { +int +unlockutmpmode() +{ currutmp->lockmode = 0; return 0; } @@ -51,44 +56,50 @@ int unlockutmpmode() { #define VICE_NEW "vice.new" /* Heat:發票 */ -int vice(int money, char* item) { - char buf[128]; - unsigned int viceserial=(currutmp->lastact%1000000)*100+rand()%100; - FILE *fp; +int +vice(int money, char *item) +{ + char buf[128]; + unsigned int viceserial = (currutmp->lastact % 1000000) * 100 + rand() % 100; + FILE *fp; demoney(-money); - sprintf(buf, BBSHOME"/home/%c/%s/%s", + sprintf(buf, BBSHOME "/home/%c/%s/%s", cuser.userid[0], cuser.userid, VICE_NEW); fp = fopen(buf, "a"); - if(!fp ) - {return 0;} - + if (!fp) { + return 0; + } fprintf(fp, "%08d\n", viceserial); fclose(fp); - sprintf(buf, "%s 花了%d$ 編號[%08d]",item, money, viceserial); - mail_id(cuser.userid, buf, "etc/vice.txt", "Ptt經濟部"); + sprintf(buf, "%s 花了%d$ 編號[%08d]", item, money, viceserial); + mail_id(cuser.userid, buf, "etc/vice.txt", "Ptt經濟部"); return 0; } -#define lockreturn(unmode, state) if(lockutmpmode(unmode, state)) return +#define lockreturn(unmode, state) if(lockutmpmode(unmode, state)) return #define lockreturn0(unmode, state) if(lockutmpmode(unmode, state)) return 0 #define lockbreak(unmode, state) if(lockutmpmode(unmode, state)) break #define SONGBOOK "etc/SONGBOOK" #define OSONGPATH "etc/SONGO" -static int osong(char *defaultid) { - char destid[IDLEN + 1],buf[200],genbuf[200],filename[256],say[51]; - char receiver[45],ano[2]; - FILE *fp,*fp1;// *fp2; - fileheader_t mail; - int nsongs; - +static int +osong(char *defaultid) +{ + char destid[IDLEN + 1], buf[200], genbuf[200], filename[256], + say[51]; + char receiver[45], ano[2]; + FILE *fp, *fp1; + //*fp2; + fileheader_t mail; + int nsongs; + strcpy(buf, Cdatedate(&now)); - + lockreturn0(OSONG, LOCK_MULTI); - + /* Jaky 一人一天點一首 */ - if(!strcmp(buf, Cdatedate(&cuser.lastsong)) && !HAS_PERM(PERM_SYSOP)) { - move(22,0); + if (!strcmp(buf, Cdatedate(&cuser.lastsong)) && !HAS_PERM(PERM_SYSOP)) { + move(22, 0); outs("你今天已經點過囉,明天再點吧...."); refresh(); pressanykey(); @@ -96,8 +107,7 @@ static int osong(char *defaultid) { unlockutmpmode(); return 0; } - - if(cuser.money < 200) { + if (cuser.money < 200) { move(22, 0); outs("點歌要200銀唷!...."); refresh(); @@ -110,120 +120,117 @@ static int osong(char *defaultid) { sprintf(buf, "親愛的 %s 歡迎來到歐桑自動點歌系統\n", cuser.userid); outs(buf); trans_buffer[0] = 0; - if(!defaultid){ - getdata(13, 0, "要點給誰呢:[可直接按 Enter 先選歌]", - destid, sizeof(destid), DOECHO); - while (!destid[0]){ - a_menu("點歌歌本", SONGBOOK,0 ); - clear(); - getdata(13, 0, "要點給誰呢:[可按 Enter 重新選歌]", - destid, sizeof(destid), DOECHO); - } + if (!defaultid) { + getdata(13, 0, "要點給誰呢:[可直接按 Enter 先選歌]", + destid, sizeof(destid), DOECHO); + while (!destid[0]) { + a_menu("點歌歌本", SONGBOOK, 0); + clear(); + getdata(13, 0, "要點給誰呢:[可按 Enter 重新選歌]", + destid, sizeof(destid), DOECHO); } - else - strcpy(destid,defaultid); + } else + strcpy(destid, defaultid); - /* Heat:點歌者匿名功能 */ - getdata(14,0, "要匿名嗎?[y/n]:", ano, sizeof(ano), DOECHO); - - if(!destid[0]) { + /* Heat:點歌者匿名功能 */ + getdata(14, 0, "要匿名嗎?[y/n]:", ano, sizeof(ano), DOECHO); + + if (!destid[0]) { unlockutmpmode(); return 0; } - getdata_str(14, 0, "想要要對他(她)說..:", say, sizeof(say), DOECHO, "我愛妳.."); - sprintf(save_title, "%s:%s", (ano[0]=='y')?"匿名者":cuser.userid, say); + sprintf(save_title, "%s:%s", (ano[0] == 'y') ? "匿名者" : cuser.userid, say); getdata_str(16, 0, "寄到誰的信箱(可用E-mail)?", receiver, sizeof(receiver), LCECHO, destid); - - if (!trans_buffer[0]){ - outs("\n接著要選歌囉..進入歌本好好的選一首歌吧..^o^"); - pressanykey(); - a_menu("點歌歌本", SONGBOOK,0 ); + + if (!trans_buffer[0]) { + outs("\n接著要選歌囉..進入歌本好好的選一首歌吧..^o^"); + pressanykey(); + a_menu("點歌歌本", SONGBOOK, 0); } - if(!trans_buffer[0] || strstr(trans_buffer, "home") || - strstr(trans_buffer, "boards") || !(fp = fopen(trans_buffer, "r"))) { + if (!trans_buffer[0] || strstr(trans_buffer, "home") || + strstr(trans_buffer, "boards") || !(fp = fopen(trans_buffer, "r"))) { unlockutmpmode(); return 0; } - strcpy(filename, OSONGPATH); - + stampfile(filename, &mail); - + unlink(filename); - - if(!(fp1 = fopen(filename, "w"))) { + + if (!(fp1 = fopen(filename, "w"))) { fclose(fp); unlockutmpmode(); return 0; } - strcpy(mail.owner, "點歌機"); - sprintf(mail.title, "◇ %s 點給 %s ", (ano[0]=='y')?"匿名者":cuser.userid, destid); - - while(fgets(buf, 200, fp)) { - char *po; - if(!strncmp(buf, "標題: ", 6)) { + sprintf(mail.title, "◇ %s 點給 %s ", (ano[0] == 'y') ? "匿名者" : cuser.userid, destid); + + while (fgets(buf, 200, fp)) { + char *po; + if (!strncmp(buf, "標題: ", 6)) { clear(); - move(10,10);prints("%s", buf); + move(10, 10); + prints("%s", buf); pressanykey(); fclose(fp); unlockutmpmode(); return 0; } - while((po = strstr(buf, "<~Src~>"))) { + while ((po = strstr(buf, "<~Src~>"))) { po[0] = 0; - sprintf(genbuf,"%s%s%s",buf,(ano[0]=='y')?"匿名者":cuser.userid,po+7); - strcpy(buf,genbuf); - } - while((po = strstr(buf, "<~Des~>"))) { + sprintf(genbuf, "%s%s%s", buf, (ano[0] == 'y') ? "匿名者" : cuser.userid, po + 7); + strcpy(buf, genbuf); + } + while ((po = strstr(buf, "<~Des~>"))) { po[0] = 0; - sprintf(genbuf,"%s%s%s",buf,destid,po+7); - strcpy(buf,genbuf); - } - while((po = strstr(buf, "<~Say~>"))) { + sprintf(genbuf, "%s%s%s", buf, destid, po + 7); + strcpy(buf, genbuf); + } + while ((po = strstr(buf, "<~Say~>"))) { po[0] = 0; - sprintf(genbuf,"%s%s%s",buf,say,po+7); - strcpy(buf,genbuf); - } - fputs(buf,fp1); + sprintf(genbuf, "%s%s%s", buf, say, po + 7); + strcpy(buf, genbuf); + } + fputs(buf, fp1); } fclose(fp1); fclose(fp); -// do_append(OSONGMAIL "/.DIR", &mail2, sizeof(mail2)); - - if(do_append(OSONGPATH "/.DIR", &mail, sizeof(mail)) != -1) { - cuser.lastsong = now; + //do_append(OSONGMAIL "/.DIR", &mail2, sizeof(mail2)); + + if (do_append(OSONGPATH "/.DIR", &mail, sizeof(mail)) != -1) { + cuser.lastsong = now; /* Jaky 超過 500 首歌就開始砍 */ - nsongs=get_num_records(OSONGPATH "/.DIR", sizeof(mail)); - if (nsongs > 500){ - delete_range(OSONGPATH "/.DIR", 1, nsongs-500); - } + nsongs = get_num_records(OSONGPATH "/.DIR", sizeof(mail)); + if (nsongs > 500) { + delete_range(OSONGPATH "/.DIR", 1, nsongs - 500); + } /* 把第一首拿掉 */ - vice(200, "點歌"); + vice(200, "點歌"); } - sprintf(save_title, "%s:%s", (ano[0]=='y')?"匿名者":cuser.userid, say); + sprintf(save_title, "%s:%s", (ano[0] == 'y') ? "匿名者" : cuser.userid, say); hold_mail(filename, destid); - if(receiver[0]) { + if (receiver[0]) { #ifndef USE_BSMTP bbs_sendmail(filename, save_title, receiver); #else - bsmtp(filename, save_title, receiver,0); + bsmtp(filename, save_title, receiver, 0); #endif } clear(); outs( - "\n\n 恭喜您點歌完成囉..\n" - " 一小時內動態看板會自動重新更新\n" - " 大家就可以看到您點的歌囉\n\n" - " 點歌有任何問題可以到Note板的精華區找答案\n" - " 也可在Note板精華區看到自己的點歌記錄\n" - " 有任何保貴的意見也歡迎到Note板留話\n" - " 讓親切的板主為您服務\n"); + "\n\n 恭喜您點歌完成囉..\n" + " 一小時內動態看板會自動重新更新\n" + " 大家就可以看到您點的歌囉\n\n" + " 點歌有任何問題可以到Note板的精華區找答案\n" + " 也可在Note板精華區看到自己的點歌記錄\n" + " 有任何保貴的意見也歡迎到Note板留話\n" + " 讓親切的板主為您服務\n"); pressanykey(); sortsong(); topsong(); @@ -232,12 +239,16 @@ static int osong(char *defaultid) { return 1; } -int ordersong() { +int +ordersong() +{ osong(NULL); return 0; } -static int inmailbox(int m) { +static int +inmailbox(int m) +{ passwd_query(usernum, &xuser); cuser.exmailbox = xuser.exmailbox + m; passwd_update(usernum, &cuser); @@ -247,14 +258,16 @@ static int inmailbox(int m) { #if !HAVE_FREECLOAK /* 花錢選單 */ -int p_cloak() { - char buf[4]; - getdata(b_lines-1, 0, +int +p_cloak() +{ + char buf[4]; + getdata(b_lines - 1, 0, currutmp->invisible ? "確定要現身?[y/N]" : "確定要隱身?[y/N]", buf, sizeof(buf), LCECHO); - if(buf[0] != 'y') + if (buf[0] != 'y') return 0; - if(cuser.money >= 19) { + if (cuser.money >= 19) { vice(19, "cloak"); currutmp->invisible %= 2; outs((currutmp->invisible ^= 1) ? MSG_CLOAKED : MSG_UNCLOAK); @@ -265,107 +278,117 @@ int p_cloak() { } #endif -int p_from() { - char ans[4]; +int +p_from() +{ + char ans[4]; - getdata(b_lines-2, 0, "確定要改故鄉?[y/N]", ans, sizeof(ans), LCECHO); - if(ans[0] != 'y') + getdata(b_lines - 2, 0, "確定要改故鄉?[y/N]", ans, sizeof(ans), LCECHO); + if (ans[0] != 'y') return 0; reload_money(); - if(cuser.money < 49) + if (cuser.money < 49) return 0; - if(getdata_buf(b_lines-1, 0, "請輸入新故鄉:", - currutmp->from, sizeof(currutmp->from), DOECHO)) { - vice(49,"home"); - currutmp->from_alias=0; + if (getdata_buf(b_lines - 1, 0, "請輸入新故鄉:", + currutmp->from, sizeof(currutmp->from), DOECHO)) { + vice(49, "home"); + currutmp->from_alias = 0; } return 0; } -int p_exmail() { - char ans[4],buf[200]; - int n; +int +p_exmail() +{ + char ans[4], buf[200]; + int n; - if(cuser.exmailbox >= MAX_EXKEEPMAIL) { - sprintf(buf,"容量最多增加 %d 封,不能再買了。", MAX_EXKEEPMAIL); + if (cuser.exmailbox >= MAX_EXKEEPMAIL) { + sprintf(buf, "容量最多增加 %d 封,不能再買了。", MAX_EXKEEPMAIL); outs(buf); refresh(); return 0; } - sprintf(buf,"您曾增購 %d 封容量,還要再買多少?", + sprintf(buf, "您曾增購 %d 封容量,還要再買多少?", cuser.exmailbox); - - getdata_str(b_lines-2, 0, buf, ans, sizeof(ans), LCECHO, "10"); - + + getdata_str(b_lines - 2, 0, buf, ans, sizeof(ans), LCECHO, "10"); + n = atoi(ans); - if(!ans[0] || !n) + if (!ans[0] || !n) return 0; - if(n + cuser.exmailbox > MAX_EXKEEPMAIL) + if (n + cuser.exmailbox > MAX_EXKEEPMAIL) n = MAX_EXKEEPMAIL - cuser.exmailbox; reload_money(); - if(cuser.money < n * 1000) + if (cuser.money < n * 1000) return 0; vice(n * 1000, "mail"); inmailbox(n); return 0; } -void mail_redenvelop(char* from, char* to, int money, char mode){ - char genbuf[200]; - fileheader_t fhdr; - FILE* fp; +void +mail_redenvelop(char *from, char *to, int money, char mode) +{ + char genbuf[200]; + fileheader_t fhdr; + FILE *fp; sprintf(genbuf, "home/%c/%s", to[0], to); stampfile(genbuf, &fhdr); if (!(fp = fopen(genbuf, "w"))) - return; + return; fprintf(fp, "作者: %s\n" - "標題: 招財進寶\n" - "時間: %s\n" - "\033[1;33m親愛的 %s :\n\n\033[m" - "\033[1;31m 我包給你一個 %d 元的大紅包喔 ^_^\n\n" - " 禮輕情意重,請笑納...... ^_^\033[m\n" - , from, ctime(&now), to, money); + "標題: 招財進寶\n" + "時間: %s\n" + "\033[1;33m親愛的 %s :\n\n\033[m" + "\033[1;31m 我包給你一個 %d 元的大紅包喔 ^_^\n\n" + " 禮輕情意重,請笑納...... ^_^\033[m\n" + ,from, ctime(&now), to, money); fclose(fp); sprintf(fhdr.title, "招財進寶"); strcpy(fhdr.owner, from); if (mode == 'y') - vedit(genbuf, NA, NULL); - sprintf(genbuf, "home/%c/%s/.DIR", to[0], to); + vedit(genbuf, NA, NULL); + sprintf(genbuf, "home/%c/%s/.DIR", to[0], to); append_record(genbuf, &fhdr, sizeof(fhdr)); } /* 計算贈與稅 */ -int give_tax(int money) +int +give_tax(int money) { - int i, tax = 0; - static int tax_bound[] = { 1000000, 100000, 10000, 1000, 0}; - static double tax_rate[] = { 0.4, 0.3, 0.2, 0.1, 0.08 }; - for( i = 0; i <= 4 ; i++ ) - if ( money > tax_bound[i] ) { - tax += (money - tax_bound[i]) * tax_rate[i]; - money -= (money - tax_bound[i]); - } - return (tax <= 0) ? 1 : tax; + int i, tax = 0; + static int tax_bound[] = {1000000, 100000, 10000, 1000, 0}; + static double tax_rate[] = {0.4, 0.3, 0.2, 0.1, 0.08}; + for (i = 0; i <= 4; i++) + if (money > tax_bound[i]) { + tax += (money - tax_bound[i]) * tax_rate[i]; + money -= (money - tax_bound[i]); + } + return (tax <= 0) ? 1 : tax; } -int p_give() { - int money, tax; - char id[IDLEN + 1], genbuf[90]; - - move(1,0); +int +p_give() +{ + int money, tax; + char id[IDLEN + 1], genbuf[90]; + + move(1, 0); usercomplete("這位幸運兒的id:", id); - if(!id[0] || !strcmp(cuser.userid,id) || - !getdata(2, 0, "要給多少錢:", genbuf, 7, LCECHO)) + if (!id[0] || !strcmp(cuser.userid, id) || + !getdata(2, 0, "要給多少錢:", genbuf, 7, LCECHO)) return 0; money = atoi(genbuf); reload_money(); - if(money > 0 && cuser.money >= money ) { + if (money > 0 && cuser.money >= money) { tax = give_tax(money); - if ( money - tax <= 0 ) return 0; /* 繳完稅就沒錢給了 */ - deumoney(searchuser(id), money - tax); + if (money - tax <= 0) + return 0; /* 繳完稅就沒錢給了 */ + deumoney(searchuser(id), money - tax); demoney(-money); - sprintf(genbuf,"%s\t給%s\t%d\t%s", cuser.userid, id, money - tax, + sprintf(genbuf, "%s\t給%s\t%d\t%s", cuser.userid, id, money - tax, ctime(&now)); log_file(FN_MONEY, genbuf); genbuf[0] = 'n'; @@ -375,14 +398,15 @@ int p_give() { return 0; } -int p_sysinfo(void) +int +p_sysinfo(void) { - char buf[128], *cpuloadstr; - int load; + char buf[128], *cpuloadstr; + int load; load = cpuload(buf); cpuloadstr = (load < 5 ? "良好" : (load < 20 ? "尚可" : "過重")); - + clear(); showtitle("系統資訊", BBSNAME); move(2, 0); @@ -398,31 +422,35 @@ int p_sysinfo(void) } /* 小計算機 */ -static void ccount(float *a, float b, int cmode) { - switch(cmode) { - case 0: - case 1: - case 2: - *a += b; - break; +static void +ccount(float *a, float b, int cmode) +{ + switch (cmode) { + case 0: + case 1: + case 2: + *a += b; + break; case 3: - *a -= b; - break; + *a -= b; + break; case 4: - *a *= b; - break; + *a *= b; + break; case 5: - *a /= b; - break; + *a /= b; + break; } } -int cal() { - float a = 0; - char flo = 0, ch = 0; - char mode[6] = {' ','=','+','-','*','/'} , cmode = 0; - char buf[100] = "[ 0] [ ] ", b[20] = "0"; - +int +cal() +{ + float a = 0; + char flo = 0, ch = 0; + char mode[6] = {' ', '=', '+', '-', '*', '/'}, cmode = 0; + char buf[100] = "[ 0] [ ] ", b[20] = "0"; + move(b_lines - 1, 0); clrtoeol(); outs(buf); @@ -431,28 +459,28 @@ int cal() { outs("\033[44m 小計算機 \033[31;47m (0123456789+-*/=) " "\033[30m輸入 \033[31m " "(Q)\033[30m 離開 \033[m"); - while(1) { + while (1) { ch = igetch(); - switch(ch) { + switch (ch) { case '\r': - ch = '='; + ch = '='; case '=': case '+': case '-': case '*': case '/': - ccount(&a, atof(b), cmode); - flo = 0; - b[0] = '0'; - b[1] = 0; - move(b_lines - 1, 0); - sprintf(buf, "[%13.2f] [%c] ", a, ch); - outs(buf); - break; + ccount(&a, atof(b), cmode); + flo = 0; + b[0] = '0'; + b[1] = 0; + move(b_lines - 1, 0); + sprintf(buf, "[%13.2f] [%c] ", a, ch); + outs(buf); + break; case '.': - if(!flo) + if (!flo) flo = 1; - else + else break; case '1': case '2': @@ -464,12 +492,12 @@ int cal() { case '8': case '9': case '0': - if(strlen(b) > 13) + if (strlen(b) > 13) break; - if(flo || b[0] != '0') - sprintf(b,"%s%c",b,ch); + if (flo || b[0] != '0') + sprintf(b, "%s%c", b, ch); else - b[0]=ch; + b[0] = ch; move(b_lines - 1, 0); sprintf(buf, "[%13s] [%c]", b, mode[(int)cmode]); outs(buf); @@ -477,8 +505,8 @@ int cal() { case 'q': return 0; } - - switch(ch) { + + switch (ch) { case '=': a = 0; cmode = 0; diff --git a/pttbbs/mbbsd/calendar.c b/pttbbs/mbbsd/calendar.c index f807c8a9..a3d7943c 100644 --- a/pttbbs/mbbsd/calendar.c +++ b/pttbbs/mbbsd/calendar.c @@ -1,145 +1,181 @@ -/* $Id: calendar.c,v 1.3 2002/06/04 13:08:33 in2 Exp $ */ +/* $Id: calendar.c,v 1.4 2002/07/05 17:10:26 in2 Exp $ */ #include "bbs.h" typedef struct event_t { - int year, month, day, days; - int color; - char *content; + int year, month, day, days; + int color; + char *content; struct event_t *next; -} event_t; +} event_t; + +static int +MonthDay(int m, int leap) +{ + static int day[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; -static int MonthDay(int m, int leap) { - static int day[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; - return leap && m == 2 ? 29 : day[m - 1]; } -static int IsLeap(int y) { - if(y % 400 == 0 || (y % 4 == 0 && y % 100 != 0)) +static int +IsLeap(int y) +{ + if (y % 400 == 0 || (y % 4 == 0 && y % 100 != 0)) return 1; else return 0; } -static int Days(int y, int m, int d) { - int i, w; - +static int +Days(int y, int m, int d) +{ + int i, w; + w = 1 + 365 * (y - 1) + ((y - 1) / 4) - ((y - 1) / 100) + ((y - 1) / 400) + d - 1; - for(i = 1; i < m; i++) + for (i = 1; i < m; i++) w += MonthDay(i, IsLeap(y)); return w; } -static int ParseDate(char *date, event_t *t) { - char *y, *m, *d; - +static int +ParseDate(char *date, event_t * t) +{ + char *y, *m, *d; + y = strtok(date, "/"); m = strtok(NULL, "/"); d = strtok(NULL, ""); - if(!y || !m || !d) + if (!y || !m || !d) return 1; - + t->year = atoi(y); t->month = atoi(m); t->day = atoi(d); - if(t->year < 1 || t->month < 1 || t->month > 12 || - t->day < 1 || t->day > 31) + if (t->year < 1 || t->month < 1 || t->month > 12 || + t->day < 1 || t->day > 31) return 1; t->days = Days(t->year, t->month, t->day); return 0; } -static int ParseColor(char *color) { +static int +ParseColor(char *color) +{ struct { - char *str; - int val; - } c[] = { - {"black", 0}, - {"red", 1}, - {"green", 2}, - {"yellow", 3}, - {"blue", 4}, - {"magenta", 5}, - {"cyan", 6}, - {"white", 7} + char *str; + int val; + } c[] = { + { + "black", 0 + }, + { + "red", 1 + }, + { + "green", 2 + }, + { + "yellow", 3 + }, + { + "blue", 4 + }, + { + "magenta", 5 + }, + { + "cyan", 6 + }, + { + "white", 7 + } }; - int i; - - for(i = 0; i < sizeof(c) / sizeof(c[0]); i++) - if(strcasecmp(color, c[i].str) == 0) + int i; + + for (i = 0; i < sizeof(c) / sizeof(c[0]); i++) + if (strcasecmp(color, c[i].str) == 0) return c[i].val; return 7; } -static void InsertEvent(event_t *head, event_t *t) { - event_t *p; - - for(p = head; p->next && p->next->days < t->days; p = p->next); +static void +InsertEvent(event_t * head, event_t * t) +{ + event_t *p; + + for (p = head; p->next && p->next->days < t->days; p = p->next); t->next = p->next; p->next = t; } -static void FreeEvent(event_t *e) { - event_t *n; - - while(e) { +static void +FreeEvent(event_t * e) +{ + event_t *n; + + while (e) { n = e->next; free(e); e = n; } } -static event_t *ReadEvent(int today) { - FILE *fp; - char buf[256]; - static event_t head; - +static event_t * +ReadEvent(int today) +{ + FILE *fp; + char buf[256]; + static event_t head; + head.next = NULL; setcalfile(buf, cuser.userid); fp = fopen(buf, "r"); - if(fp) { - while(fgets(buf, sizeof(buf), fp)) { - char *date, *color, *content; - event_t *t; - - if(buf[0] == '#') + if (fp) { + while (fgets(buf, sizeof(buf), fp)) { + char *date, *color, *content; + event_t *t; + + if (buf[0] == '#') continue; - + date = strtok(buf, " \t\n"); color = strtok(NULL, " \t\n"); content = strtok(NULL, "\n"); - if(!date || !color || !content) + if (!date || !color || !content) continue; - + t = malloc(sizeof(event_t)); - if(ParseDate(date, t) || t->days < today) { + if (ParseDate(date, t) || t->days < today) { free(t); continue; } t->color = ParseColor(color) + 30; - for(; *content == ' ' || *content == '\t'; content++); + for (; *content == ' ' || *content == '\t'; content++); t->content = strdup(content); InsertEvent(&head, t); } fclose(fp); - } + } return head.next; } -static char **AllocCalBuffer(int line, int len) { - int i; - char **p; - +static char ** +AllocCalBuffer(int line, int len) +{ + int i; + char **p; + p = malloc(sizeof(char *) * line); p[0] = malloc(sizeof(char) * line * len); - for(i = 1; i < line; i++) + for (i = 1; i < line; i++) p[i] = p[i - 1] + len; return p; } -static void FreeCalBuffer(char **buf) { +static void +FreeCalBuffer(char **buf) +{ free(buf[0]); free(buf); } @@ -149,115 +185,119 @@ static void FreeCalBuffer(char **buf) { #define HEADER_SUNDAY_COLOR "\33[31m" #define HEADER_DAY_COLOR "\33[33m" -static int GenerateCalendar(char **buf, int y, int m, int today, event_t *e) { - static char *week_str[7] = {"日", "一", "二", "三", "四", "五", "六"}; - static char *month_color[12] = { +static int +GenerateCalendar(char **buf, int y, int m, int today, event_t * e) +{ + static char *week_str[7] = {"日", "一", "二", "三", "四", "五", "六"}; + static char *month_color[12] = { "\33[1;32m", "\33[1;33m", "\33[1;35m", "\33[1;36m", "\33[1;32m", "\33[1;33m", "\33[1;35m", "\33[1;36m", "\33[1;32m", "\33[1;33m", "\33[1;35m", "\33[1;36m" }; - static char *month_str[12] = { + static char *month_str[12] = { "一月 ", "二月 ", "三月 ", "四月 ", "五月 ", "六月 ", "七月 ", "八月 ", "九月 ", "十月 ", "十一月", "十二月" }; - - char *p, attr1[16], *attr2; - int i, d, w, line = 0, first_day = Days(y, m, 1); - + char *p, attr1[16], *attr2; + int i, d, w, line = 0, first_day = Days(y, m, 1); + + /* week day banner */ p = buf[line]; p += sprintf(p, " %s%s%s%s", HEADER_COLOR, HEADER_SUNDAY_COLOR, week_str[0], HEADER_DAY_COLOR); - for(i = 1; i < 7; i++) + for (i = 1; i < 7; i++) p += sprintf(p, " %s", week_str[i]); p += sprintf(p, "\33[m"); - + /* indent for first line */ p = buf[++line]; p += sprintf(p, " %s", CALENDAR_COLOR); - for(i = 0, w = first_day % 7; i < w; i++) + for (i = 0, w = first_day % 7; i < w; i++) p += sprintf(p, " "); - + /* initial event */ - for(; e && e->days < first_day; e = e->next); - + for (; e && e->days < first_day; e = e->next); + d = MonthDay(m, IsLeap(y)); - for(i = 1; i <= d; i++, w = (w + 1) % 7) { - attr1[0] = 0; - attr2 = ""; - while(e && e->days == first_day + i - 1) { + for (i = 1; i <= d; i++, w = (w + 1) % 7) { + attr1[0] = 0; + attr2 = ""; + while (e && e->days == first_day + i - 1) { sprintf(attr1, "\33[1;%dm", e->color); attr2 = CALENDAR_COLOR; e = e->next; } - if(today == first_day + i - 1) { + if (today == first_day + i - 1) { strcpy(attr1, "\33[1;37;42m"); attr2 = CALENDAR_COLOR; } p += sprintf(p, "%s%2d%s", attr1, i, attr2); - - if(w == 6) { + + if (w == 6) { p += sprintf(p, "\33[m"); p = buf[++line]; /* show month */ - if(line >= 2 && line <= 4) + if (line >= 2 && line <= 4) p += sprintf(p, "%s%2.2s\33[m %s", month_color[m - 1], month_str[m - 1] + (line - 2) * 2, CALENDAR_COLOR); - else if(i < d) + else if (i < d) p += sprintf(p, " %s", CALENDAR_COLOR); } else *p++ = ' '; } - + /* fill up the last line */ - if(w) { - for(w = 7 - w; w; w--) + if (w) { + for (w = 7 - w; w; w--) p += sprintf(p, w == 1 ? " " : " "); p += sprintf(p, "\33[m"); } return line + 1; } -int calendar() { - char **buf; - struct tm snow; - int i, y, m, today, lines = 0; - event_t *head = NULL, *e = NULL; - +int +calendar() +{ + char **buf; + struct tm snow; + int i, y, m, today, lines = 0; + event_t *head = NULL, *e = NULL; + /* initialize date */ memcpy(&snow, localtime(&now), sizeof(struct tm)); today = Days(snow.tm_year + 1900, snow.tm_mon + 1, snow.tm_mday); y = snow.tm_year + 1900, m = snow.tm_mon + 1; - + /* read event */ head = e = ReadEvent(today); - + /* generate calendar */ buf = AllocCalBuffer(22, 256); - for(i = 0; i < 22; i++) + for (i = 0; i < 22; i++) sprintf(buf[i], "%24s", ""); - for(i = 0; i < 3; i++) { + for (i = 0; i < 3; i++) { lines += GenerateCalendar(buf + lines, y, m, today, e) + 1; - if(m == 12) + if (m == 12) y++, m = 1; else m++; } - + /* output */ clear(); outc('\n'); - for(i = 0; i < 22; i++) { + for (i = 0; i < 22; i++) { outs(buf[i]); - if(i == 0) { + if (i == 0) { prints("\t\33[1;37m現在是 %d.%02d.%02d %2d:%02d:%02d%cm\33[m", snow.tm_year + 1900, snow.tm_mon + 1, snow.tm_mday, - (snow.tm_hour == 0 || snow.tm_hour == 12) ? + (snow.tm_hour == 0 || snow.tm_hour == 12) ? 12 : snow.tm_hour % 12, snow.tm_min, snow.tm_sec, snow.tm_hour >= 12 ? 'p' : 'a'); - } else if(i >= 2 && e) { + } else if (i >= 2 && e) { prints("\t\33[1;37m(\33[%dm%3d\33[37m)\33[m %02d/%02d %s", e->color, e->days - today, e->month, e->day, e->content); diff --git a/pttbbs/mbbsd/card.c b/pttbbs/mbbsd/card.c index e5ac18e7..2b09d9c2 100644 --- a/pttbbs/mbbsd/card.c +++ b/pttbbs/mbbsd/card.c @@ -1,255 +1,281 @@ -/* $Id: card.c,v 1.3 2002/06/04 13:08:33 in2 Exp $ */ +/* $Id: card.c,v 1.4 2002/07/05 17:10:27 in2 Exp $ */ #include "bbs.h" -static int card_remain(int cards[]) { - int i, temp = 0; - - for(i = 0; i < 52; i++) - temp += cards[i]; - if(temp == 52) - return 1; +static int +card_remain(int cards[]) +{ + int i, temp = 0; + + for (i = 0; i < 52; i++) + temp += cards[i]; + if (temp == 52) + return 1; return 0; } /* 0 Spare , 1 heart , ...3 dimon */ -static int card_flower(int card) { +static int +card_flower(int card) +{ return (card / 13); } /* 1...13 */ -static int card_number(int card) { +static int +card_number(int card) +{ return (card % 13 + 1); } -static int card_select(int *now) { - char *cc[2] = {"\033[44m \033[m", - "\033[1;33;41m △ \033[m"}; - - while(1) { - move(20, 0); - clrtoeol(); - prints("%s%s%s%s%s", (*now == 0) ? cc[1] : cc[0], - (*now == 1) ? cc[1] : cc[0], - (*now == 2) ? cc[1] : cc[0], - (*now == 3) ? cc[1] : cc[0], - (*now == 4) ? cc[1] : cc[0]); - switch(egetch()) { - case 'Q': - case 'q': - return 0; - case '+': - case ',': - return 1; - case '\r': - return -1; - case KEY_LEFT: - *now = (*now + 4) % 5; - break; - case KEY_RIGHT: - *now = (*now + 1) % 5; - break; - case '1': - *now = 0; - break; - case '2': - *now = 1; - break; - case '3': - *now = 2; - break; - case '4': - *now = 3; - break; - case '5': - *now = 4; - break; - } +static int +card_select(int *now) +{ + char *cc[2] = {"\033[44m \033[m", + "\033[1;33;41m △ \033[m"}; + + while (1) { + move(20, 0); + clrtoeol(); + prints("%s%s%s%s%s", (*now == 0) ? cc[1] : cc[0], + (*now == 1) ? cc[1] : cc[0], + (*now == 2) ? cc[1] : cc[0], + (*now == 3) ? cc[1] : cc[0], + (*now == 4) ? cc[1] : cc[0]); + switch (egetch()) { + case 'Q': + case 'q': + return 0; + case '+': + case ',': + return 1; + case '\r': + return -1; + case KEY_LEFT: + *now = (*now + 4) % 5; + break; + case KEY_RIGHT: + *now = (*now + 1) % 5; + break; + case '1': + *now = 0; + break; + case '2': + *now = 1; + break; + case '3': + *now = 2; + break; + case '4': + *now = 3; + break; + case '5': + *now = 4; + break; + } } } -static void card_display(int cline, int number, int flower, int show) { - int color = 31; - char *cn[13] = {"A", "2", "3", "4", "5", "6", - "7", "8", "9", "10", "J", "Q", "K"}; - if(flower == 0 || flower == 3) - color = 36; - if((show < 0) && (cline > 1 && cline < 8)) - prints("│\033[1;33;42m※※※※\033[m│"); +static void +card_display(int cline, int number, int flower, int show) +{ + int color = 31; + char *cn[13] = {"A", "2", "3", "4", "5", "6", + "7", "8", "9", "10", "J", "Q", "K"}; + if (flower == 0 || flower == 3) + color = 36; + if ((show < 0) && (cline > 1 && cline < 8)) + prints("│\033[1;33;42m※※※※\033[m│"); else - switch(cline) { - case 1: - prints("╭────╮"); - break; - case 2: - prints("│\033[1;%dm%s\033[m │", color, cn[number - 1]); - break; - case 3: - if(flower == 1) - prints("│\033[1;%dm◢◣◢◣\033[m│", color); - else - prints("│\033[1;%dm ◢◣ \033[m│", color); - break; - case 4: - if(flower == 1) - prints("│\033[1;%dm████\033[m│", color); - else if (flower == 3) - prints("│\033[1;%dm◣██◢\033[m│", color); - else - prints("│\033[1;%dm◢██◣\033[m│", color); - break; - case 5: - if(flower == 0) - prints("│\033[1;%dm████\033[m│", color); - else if (flower == 3) - prints("│\033[1;%dm█◥◤█\033[m│", color); - else - prints("│\033[1;%dm◥██◤\033[m│", color); - break; - case 6: - if(flower == 0) - prints("│\033[1;%dm ◢◣ \033[m│", color); - else if (flower == 3) - prints("│\033[1;%dm◥◢◣◤\033[m│", color); - else - prints("│\033[1;%dm ◥◤ \033[m│", color); - break; - case 7: - prints("│ \033[1;%dm%s\033[m│", color, cn[number - 1]); - break; - case 8: - prints("╰────╯"); - break; - } + switch (cline) { + case 1: + prints("╭────╮"); + break; + case 2: + prints("│\033[1;%dm%s\033[m │", color, cn[number - 1]); + break; + case 3: + if (flower == 1) + prints("│\033[1;%dm◢◣◢◣\033[m│", color); + else + prints("│\033[1;%dm ◢◣ \033[m│", color); + break; + case 4: + if (flower == 1) + prints("│\033[1;%dm████\033[m│", color); + else if (flower == 3) + prints("│\033[1;%dm◣██◢\033[m│", color); + else + prints("│\033[1;%dm◢██◣\033[m│", color); + break; + case 5: + if (flower == 0) + prints("│\033[1;%dm████\033[m│", color); + else if (flower == 3) + prints("│\033[1;%dm█◥◤█\033[m│", color); + else + prints("│\033[1;%dm◥██◤\033[m│", color); + break; + case 6: + if (flower == 0) + prints("│\033[1;%dm ◢◣ \033[m│", color); + else if (flower == 3) + prints("│\033[1;%dm◥◢◣◤\033[m│", color); + else + prints("│\033[1;%dm ◥◤ \033[m│", color); + break; + case 7: + prints("│ \033[1;%dm%s\033[m│", color, cn[number - 1]); + break; + case 8: + prints("╰────╯"); + break; + } } -static void card_show(int cpu[], int c[], int me[], int m[]) { - int i, j; - - for(j = 0; j < 8; j++) { - move(2 + j, 0); - clrtoeol(); - for(i = 0; i < 5 && cpu[i] >= 0; i++) - card_display(j + 1, card_number(cpu[i]), - card_flower(cpu[i]), c[i]); +static void +card_show(int cpu[], int c[], int me[], int m[]) +{ + int i, j; + + for (j = 0; j < 8; j++) { + move(2 + j, 0); + clrtoeol(); + for (i = 0; i < 5 && cpu[i] >= 0; i++) + card_display(j + 1, card_number(cpu[i]), + card_flower(cpu[i]), c[i]); } - for(j = 0; j < 8; j++) { - move(11 + j, 0); - clrtoeol(); - for(i = 0; i < 5 && me[i] >= 0; i++) - card_display(j + 1, card_number(me[i]), card_flower(me[i]), m[i]); + for (j = 0; j < 8; j++) { + move(11 + j, 0); + clrtoeol(); + for (i = 0; i < 5 && me[i] >= 0; i++) + card_display(j + 1, card_number(me[i]), card_flower(me[i]), m[i]); } } -static void card_new(int cards[]) { - memset(cards, 0, sizeof(int)*52); -} - -static int card_give(int cards[]) { - int i, error; - for(error=0, i=rand()%52; cards[i] == 1 && error<52; error++, i=rand()%52); - if(error==52) card_new(cards); // Ptt:這邊有dead lock問題 - cards[i] = 1; +static void +card_new(int cards[]) +{ + memset(cards, 0, sizeof(int) * 52); +} + +static int +card_give(int cards[]) +{ + int i, error; + for (error = 0, i = rand() % 52; cards[i] == 1 && error < 52; error++, i = rand() % 52); + if (error == 52) + card_new(cards); +//Ptt:這 鉿責ead lock 暋D + cards[i] = 1; return i; } -static void card_start(char name[]) { +static void +card_start(char name[]) +{ clear(); stand_title(name); move(1, 0); prints(" \033[1;33;41m 電 腦 \033[m"); move(10, 0); prints("\033[1;34;44m◆∼◆∼◆∼◆∼◆∼◆∼◆∼◆∼◆∼◆∼◆∼◆∼" - "◆∼◆∼◆∼◆∼◆∼◆∼◆∼◆\033[m"); + "◆∼◆∼◆∼◆∼◆∼◆∼◆∼◆\033[m"); move(19, 0); prints(" \033[1;37;42m 自 己 \033[m"); } -static int card_99_add(int i, int aom, int count) { +static int +card_99_add(int i, int aom, int count) +{ if (i == 4 || i == 5 || i == 11) - return count; - else if(i == 12) - return count + 20 * aom; - else if(i == 10) - return count + 10 * aom; - else if(i == 13) - return 99; + return count; + else if (i == 12) + return count + 20 * aom; + else if (i == 10) + return count + 10 * aom; + else if (i == 13) + return 99; else - return count + i; + return count + i; } -static int card_99_cpu(int cpu[], int *count) { - int stop = -1; - int twenty = -1; - int ten = -1; - int kill = -1; - int temp, num[10]; - int other = -1; - int think = 99-(*count); - int i, j; - - for(i = 0; i < 10; i++) - num[i] = -1; - for(i = 0; i < 5; i++) { - temp = card_number(cpu[i]); - if(temp == 4 || temp == 5 || temp == 11) - stop = i; - else if(temp == 12) - twenty = i; - else if (temp == 10) - ten = i; - else if (temp == 13) - kill = i; - else { - other = i; - num[temp] = i; - } +static int +card_99_cpu(int cpu[], int *count) +{ + int stop = -1; + int twenty = -1; + int ten = -1; + int kill = -1; + int temp, num[10]; + int other = -1; + int think = 99 - (*count); + int i, j; + + for (i = 0; i < 10; i++) + num[i] = -1; + for (i = 0; i < 5; i++) { + temp = card_number(cpu[i]); + if (temp == 4 || temp == 5 || temp == 11) + stop = i; + else if (temp == 12) + twenty = i; + else if (temp == 10) + ten = i; + else if (temp == 13) + kill = i; + else { + other = i; + num[temp] = i; + } } - for(j = 9; j > 0; j--) - if(num[j] >= 0 && j != 4 && j != 5 && think >= j) { - (*count) += j; - return num[j]; - } - if((think >= 20) && (twenty >= 0)) { - (*count) += 20; - return twenty; - } else if((think >= 10) && (ten >= 0)) { - (*count) += 10; - return ten; - } else if(stop >= 0) - return stop; + for (j = 9; j > 0; j--) + if (num[j] >= 0 && j != 4 && j != 5 && think >= j) { + (*count) += j; + return num[j]; + } + if ((think >= 20) && (twenty >= 0)) { + (*count) += 20; + return twenty; + } else if ((think >= 10) && (ten >= 0)) { + (*count) += 10; + return ten; + } else if (stop >= 0) + return stop; else if (kill >= 0) { - (*count) = 99; - return kill; - } else if(ten >= 0) { - (*count) -= 10; - return ten; - } else if(twenty >= 0) { - (*count) -= 20; - return twenty; + (*count) = 99; + return kill; + } else if (ten >= 0) { + (*count) -= 10; + return ten; + } else if (twenty >= 0) { + (*count) -= 20; + return twenty; } else { - (*count) += card_number(cpu[0]); - return 0; + (*count) += card_number(cpu[0]); + return 0; } } -int card_99() { - int i, j, turn; - int cpu[5], c[5], me[5], m[5]; - int cards[52]; - int count = 0; - char *ff[4] = {"\033[1;36m黑桃", "\033[1;31m紅心", - "\033[1;31m方塊", "\033[1;36m黑花"}; - char *cn[13] = {"A", "2", "3", "4", "5", "6", - "7", "8", "9", "10", "J", "Q", "K"}; - for(i = 0; i < 5; i++) - cpu[i] = c[i] = me[i] = m[i] = -1; +int +card_99() +{ + int i, j, turn; + int cpu[5], c[5], me[5], m[5]; + int cards[52]; + int count = 0; + char *ff[4] = {"\033[1;36m黑桃", "\033[1;31m紅心", + "\033[1;31m方塊", "\033[1;36m黑花"}; + char *cn[13] = {"A", "2", "3", "4", "5", "6", + "7", "8", "9", "10", "J", "Q", "K"}; + for (i = 0; i < 5; i++) + cpu[i] = c[i] = me[i] = m[i] = -1; setutmpmode(CARD_99); card_start("天長地久"); card_new(cards); - for(i = 0; i < 5; i++) { - cpu[i] = card_give(cards); - me[i] = card_give(cards); - m[i] = 1; + for (i = 0; i < 5; i++) { + cpu[i] = card_give(cards); + me[i] = card_give(cards); + m[i] = 1; } card_show(cpu, c, me, m); j = 0; @@ -258,232 +284,244 @@ int card_99() { clrtoeol(); prints("[0]目前 %d , 殘 %d 點\n", count, 99 - count); prints("左右鍵移動游標, [Enter]確定, [ + ]表加二十(加十), [Q/q]放棄遊戲"); - while(1) { - i = card_select(&j); - if(i == 0) /*放棄遊戲*/ - return 0; - count = card_99_add(card_number(me[j]), i, count); - move(21 + (turn / 2) % 2, 0); - clrtoeol(); - prints("[%d]您出 %s%s\033[m 目前 \033[1;31m%d/\033[34m%d\033[m 點", - turn, ff[card_flower(me[j])], - cn[card_number(me[j]) - 1], count, 99 - count); - me[j] = card_give(cards); - turn++; - if(count < 0) - count = 0; - card_show(cpu, c, me, m); - pressanykey(); - if(count > 99) { - move(22, 0); - clrtoeol(); - prints("[%d]結果..YOU LOSS..目前 \033[1;31m%d/\033[34m%d\033[m 點", - turn, count, 99 - count); - pressanykey(); - return 0; - } - i = card_99_cpu(cpu, &count); - move(21 + (turn / 2 + 1) % 2, 40); - prints("[%d]電腦出 %s%s\033[m 目前 \033[1;31m%d/\033[34m%d\033[m 點", - turn, ff[card_flower(cpu[i])], - cn[card_number(cpu[i]) - 1], count, 99 - count); - cpu[i] = card_give(cards); - turn++; - if(count < 0) - count = 0; - if(count > 99) { - move(22, 0); - clrtoeol(); - prints("[%d]結果..YOU WIN!..目前 \033[1;31m%d/\033[34m%d\033[m 點", - turn, count, 99 - count); - pressanykey(); - return 0; - } - if(!card_remain(cards)) { - card_new(cards); - for(i = 0; i < 5; i++) { - cards[me[i]] = 1; - cards[cpu[i]] = 1; - } - } + while (1) { + i = card_select(&j); + if (i == 0) /* 放棄遊戲 */ + return 0; + count = card_99_add(card_number(me[j]), i, count); + move(21 + (turn / 2) % 2, 0); + clrtoeol(); + prints("[%d]您出 %s%s\033[m 目前 \033[1;31m%d/\033[34m%d\033[m 點", + turn, ff[card_flower(me[j])], + cn[card_number(me[j]) - 1], count, 99 - count); + me[j] = card_give(cards); + turn++; + if (count < 0) + count = 0; + card_show(cpu, c, me, m); + pressanykey(); + if (count > 99) { + move(22, 0); + clrtoeol(); + prints("[%d]結果..YOU LOSS..目前 \033[1;31m%d/\033[34m%d\033[m 點", + turn, count, 99 - count); + pressanykey(); + return 0; + } + i = card_99_cpu(cpu, &count); + move(21 + (turn / 2 + 1) % 2, 40); + prints("[%d]電腦出 %s%s\033[m 目前 \033[1;31m%d/\033[34m%d\033[m 點", + turn, ff[card_flower(cpu[i])], + cn[card_number(cpu[i]) - 1], count, 99 - count); + cpu[i] = card_give(cards); + turn++; + if (count < 0) + count = 0; + if (count > 99) { + move(22, 0); + clrtoeol(); + prints("[%d]結果..YOU WIN!..目前 \033[1;31m%d/\033[34m%d\033[m 點", + turn, count, 99 - count); + pressanykey(); + return 0; + } + if (!card_remain(cards)) { + card_new(cards); + for (i = 0; i < 5; i++) { + cards[me[i]] = 1; + cards[cpu[i]] = 1; + } + } } } #define PMONEY (10) -#define TEN_HALF (5) /*十點半的Ticket*/ -#define JACK (10) /*黑傑克的Ticket*/ -#define NINE99 (99) /*99 的Ticket*/ +#define TEN_HALF (5) /* 十點半的Ticket */ +#define JACK (10) /* 黑傑克的Ticket */ +#define NINE99 (99) /* 99 的Ticket */ -static int game_log(int type, int money) { - FILE *fp; +static int +game_log(int type, int money) +{ + FILE *fp; - if(money > 0) + if (money > 0) demoney(money); - switch(type) { + switch (type) { case JACK: - fp = fopen(BBSHOME "/etc/card/jack.log", "a"); - if(!fp) - return 0; - fprintf(fp, "%s win:%d\n", cuser.userid, money); - fclose(fp); - break; + fp = fopen(BBSHOME "/etc/card/jack.log", "a"); + if (!fp) + return 0; + fprintf(fp, "%s win:%d\n", cuser.userid, money); + fclose(fp); + break; case TEN_HALF: - fp = fopen(BBSHOME "/etc/card/tenhalf.log", "a"); - if(!fp) - return 0; - fprintf(fp, "%s win:%d\n", cuser.userid, money); - fclose(fp); - break; + fp = fopen(BBSHOME "/etc/card/tenhalf.log", "a"); + if (!fp) + return 0; + fprintf(fp, "%s win:%d\n", cuser.userid, money); + fclose(fp); + break; } return 0; } -static int card_double_ask() { - char buf[100], buf2[3]; +static int +card_double_ask() +{ + char buf[100], buf2[3]; sprintf(buf, "[ %s ]您現在共有 %d P幣, 現在要分組(加收 %d 元)嗎? [y/N]", - cuser.userid, cuser.money, JACK); + cuser.userid, cuser.money, JACK); reload_money(); - if(cuser.money < JACK) - return 0; + if (cuser.money < JACK) + return 0; getdata(20, 0, buf, buf2, sizeof(buf2), LCECHO); - if(buf2[0] == 'y' || buf2[0] == 'Y') - return 1; + if (buf2[0] == 'y' || buf2[0] == 'Y') + return 1; return 0; } -static int card_ask() { - char buf[100], buf2[3]; +static int +card_ask() +{ + char buf[100], buf2[3]; sprintf(buf, "[ %s ]您現在共有 %d P幣, 還要加牌嗎? [y/N]", - cuser.userid, cuser.money); - getdata(20, 0 , buf, buf2, sizeof(buf2), LCECHO); - if(buf2[0] == 'y' || buf2[0] == 'Y') - return 1; + cuser.userid, cuser.money); + getdata(20, 0, buf, buf2, sizeof(buf2), LCECHO); + if (buf2[0] == 'y' || buf2[0] == 'Y') + return 1; return 0; } -static int card_alls_lower(int all[]) { - int i, count = 0; +static int +card_alls_lower(int all[]) +{ + int i, count = 0; for (i = 0; i < 5 && all[i] >= 0; i++) - if(card_number(all[i]) <= 10) - count += card_number(all[i]); - else - count += 10; + if (card_number(all[i]) <= 10) + count += card_number(all[i]); + else + count += 10; return count; } -static int card_alls_upper(int all[]) { - int i, count; +static int +card_alls_upper(int all[]) +{ + int i, count; count = card_alls_lower(all); for (i = 0; i < 5 && all[i] >= 0 && count <= 11; i++) - if (card_number(all[i]) == 1) - count += 10; + if (card_number(all[i]) == 1) + count += 10; return count; } -static int card_jack(int *db) { - int i, j; - int cpu[5], c[5], me[5], m[5]; - int cards[52]; - - for(i = 0;i<5;i++) - cpu[i] = c[i] = me[i] = m[i] = -1; - - if((*db)<0) { - card_new(cards); - card_start("黑傑克"); - for(i = 0; i < 2; i++) { - cpu[i] = card_give(cards); - me[i] = card_give(cards); - } +static int +card_jack(int *db) +{ + int i, j; + int cpu[5], c[5], me[5], m[5]; + int cards[52]; + + for (i = 0; i < 5; i++) + cpu[i] = c[i] = me[i] = m[i] = -1; + + if ((*db) < 0) { + card_new(cards); + card_start("黑傑克"); + for (i = 0; i < 2; i++) { + cpu[i] = card_give(cards); + me[i] = card_give(cards); + } } else { - card_start("黑傑克DOUBLE追加局"); - cpu[0] = card_give(cards); - cpu[1] = card_give(cards); - me[0] = *db; - me[1] = card_give(cards); + card_start("黑傑克DOUBLE追加局"); + cpu[0] = card_give(cards); + cpu[1] = card_give(cards); + me[0] = *db; + me[1] = card_give(cards); } c[1] = m[0] = m[1] = 1; card_show(cpu, c, me, m); - if((card_number(me[0]) == 0 && card_number(me[1]) == 12) || - (card_number(me[1]) == 0 && card_number(me[0]) == 12)) { - if(card_flower(me[0]) == 0 && card_flower(me[1]) == 0) { - move(b_lines - 1, 0); - prints("非常不錯唷! (超級黑傑克!! 加 %d 元)", JACK * 10); - game_log(JACK, JACK * 10); - pressanykey(); - return 0; - } else { - move(b_lines - 1, 0); - prints("很不錯唷! (黑傑克!! 加 %d 元)", JACK * 5); - game_log(JACK, JACK * 5); - pressanykey(); - return 0; - } + if ((card_number(me[0]) == 0 && card_number(me[1]) == 12) || + (card_number(me[1]) == 0 && card_number(me[0]) == 12)) { + if (card_flower(me[0]) == 0 && card_flower(me[1]) == 0) { + move(b_lines - 1, 0); + prints("非常不錯唷! (超級黑傑克!! 加 %d 元)", JACK * 10); + game_log(JACK, JACK * 10); + pressanykey(); + return 0; + } else { + move(b_lines - 1, 0); + prints("很不錯唷! (黑傑克!! 加 %d 元)", JACK * 5); + game_log(JACK, JACK * 5); + pressanykey(); + return 0; + } } - if((card_number(cpu[0]) == 0 && card_number(cpu[1]) == 12) || - (card_number(cpu[1]) == 0 && card_number(cpu[0]) == 12)) { - c[0] = 1; - card_show(cpu, c, me, m); - move(b_lines - 1, 0); - prints("嘿嘿...不好意思....黑傑克!!"); - game_log(JACK, 0); - pressanykey(); - return 0; + if ((card_number(cpu[0]) == 0 && card_number(cpu[1]) == 12) || + (card_number(cpu[1]) == 0 && card_number(cpu[0]) == 12)) { + c[0] = 1; + card_show(cpu, c, me, m); + move(b_lines - 1, 0); + prints("嘿嘿...不好意思....黑傑克!!"); + game_log(JACK, 0); + pressanykey(); + return 0; } - if((*db < 0)&& (card_number(me[0]) == card_number(me[1])) && - (card_double_ask())) { - *db = me[1]; - me[1] = card_give(cards); - card_show(cpu, c, me, m); + if ((*db < 0) && (card_number(me[0]) == card_number(me[1])) && + (card_double_ask())) { + *db = me[1]; + me[1] = card_give(cards); + card_show(cpu, c, me, m); } i = 2; - while(i < 5 && card_ask()) { - me[i] = card_give(cards); - m[i] = 1; - card_show(cpu, c, me, m); - if(card_alls_lower(me) > 21) { - move(b_lines - 1, 0); - prints("嗚嗚...爆掉了!"); - game_log(JACK, 0); - pressanykey(); - return 0; - } - i++; - if((i == 3) && (card_number(me[0]) == 7) && - (card_number(me[1]) == 7) && (card_number(me[2]) == 7)) { - move(b_lines - 1, 0); - prints("很不錯唷! (幸運七號!! 加 %d 元)", JACK * 7); - game_log(JACK, JACK * 7); - pressanykey(); - return 0; - } + while (i < 5 && card_ask()) { + me[i] = card_give(cards); + m[i] = 1; + card_show(cpu, c, me, m); + if (card_alls_lower(me) > 21) { + move(b_lines - 1, 0); + prints("嗚嗚...爆掉了!"); + game_log(JACK, 0); + pressanykey(); + return 0; + } + i++; + if ((i == 3) && (card_number(me[0]) == 7) && + (card_number(me[1]) == 7) && (card_number(me[2]) == 7)) { + move(b_lines - 1, 0); + prints("很不錯唷! (幸運七號!! 加 %d 元)", JACK * 7); + game_log(JACK, JACK * 7); + pressanykey(); + return 0; + } } - if(i == 5) {/*過五關*/ - move(b_lines - 1, 0); - prints("好厲害唷! 過五關嘍! 加P幣 %d 元!", 5 * JACK); - game_log(JACK, JACK * 5); - pressanykey(); - return 0; + if (i == 5) { /* 過五關 */ + move(b_lines - 1, 0); + prints("好厲害唷! 過五關嘍! 加P幣 %d 元!", 5 * JACK); + game_log(JACK, JACK * 5); + pressanykey(); + return 0; } j = 2; c[0] = 1; - while((card_alls_upper(cpu) < card_alls_upper(me))|| - ((card_alls_upper(cpu) == card_alls_upper(me) && j < i ) && j < 5)) { - cpu[j] = card_give(cards); - c[j] = 1; - if(card_alls_lower(cpu) > 21) { - card_show(cpu, c, me, m); - move(b_lines - 1, 0); - prints("呵呵...電腦爆掉了! 你贏了! 可得P幣 %d 元", JACK * 2); - game_log(JACK, JACK * 2); - pressanykey(); - return 0; - } - j++; + while ((card_alls_upper(cpu) < card_alls_upper(me)) || + ((card_alls_upper(cpu) == card_alls_upper(me) && j < i) && j < 5)) { + cpu[j] = card_give(cards); + c[j] = 1; + if (card_alls_lower(cpu) > 21) { + card_show(cpu, c, me, m); + move(b_lines - 1, 0); + prints("呵呵...電腦爆掉了! 你贏了! 可得P幣 %d 元", JACK * 2); + game_log(JACK, JACK * 2); + pressanykey(); + return 0; + } + j++; } card_show(cpu, c, me, m); move(b_lines - 1, 0); @@ -493,93 +531,99 @@ static int card_jack(int *db) { return 0; } -int g_card_jack() { - int db; - char buf[3]; +int +g_card_jack() +{ + int db; + char buf[3]; setutmpmode(JACK_CARD); - while(1) { - reload_money(); - if(cuser.money < JACK) { - outs("您的錢不夠唷!去多發表些有意義的文章再來~~~"); - return 0; - } - getdata(b_lines - 1, 0, "確定要玩黑傑克嗎 一次十元唷?(Y/N)?[N]", - buf, 3, LCECHO); - if((*buf != 'y') && (*buf != 'Y')) - break; - else { - db = -1; + while (1) { + reload_money(); + if (cuser.money < JACK) { + outs("您的錢不夠唷!去多發表些有意義的文章再來~~~"); + return 0; + } + getdata(b_lines - 1, 0, "確定要玩黑傑克嗎 一次十元唷?(Y/N)?[N]", + buf, 3, LCECHO); + if ((*buf != 'y') && (*buf != 'Y')) + break; + else { + db = -1; vice(PMONEY, "黑傑克"); - card_jack(&db); - if(db >= 0) - card_jack(&db); - } + card_jack(&db); + if (db >= 0) + card_jack(&db); + } } return 0; } -static int card_all(int all[]) { - int i, count = 0; +static int +card_all(int all[]) +{ + int i, count = 0; for (i = 0; i < 5 && all[i] >= 0; i++) - if(card_number(all[i]) <= 10) - count += 2 * card_number(all[i]); - else - count += 1; + if (card_number(all[i]) <= 10) + count += 2 * card_number(all[i]); + else + count += 1; return count; } -static int ten_helf() { - int i, j; - int cpu[5], c[5], me[5], m[5]; - int cards[52]; +static int +ten_helf() +{ + int i, j; + int cpu[5], c[5], me[5], m[5]; + int cards[52]; card_start("十點半"); card_new(cards); for (i = 0; i < 5; i++) - cpu[i] = c[i] = me[i] = m[i] = -1; + cpu[i] = c[i] = me[i] = m[i] = -1; cpu[0] = card_give(cards); me[0] = card_give(cards); m[0] = 1; card_show(cpu, c, me, m); i = 1; - while(i < 5 && card_ask()) { - me[i] = card_give(cards); - m[i] = 1; - card_show(cpu, c, me, m); - if(card_all(me) > 21) { - move(b_lines - 1, 0); - prints("嗚嗚...爆掉了!"); - game_log(TEN_HALF, 0); - pressanykey(); - return 0; - } - i++; + while (i < 5 && card_ask()) { + me[i] = card_give(cards); + m[i] = 1; + card_show(cpu, c, me, m); + if (card_all(me) > 21) { + move(b_lines - 1, 0); + prints("嗚嗚...爆掉了!"); + game_log(TEN_HALF, 0); + pressanykey(); + return 0; + } + i++; } - if(i == 5) {/*過五關*/ - move(b_lines - 1, 0); - prints("好厲害唷! 過五關嘍! 加P幣 %d 元!", 5 * PMONEY); - game_log(TEN_HALF, PMONEY * 5); - pressanykey(); - return 0; + if (i == 5) { /* 過五關 */ + move(b_lines - 1, 0); + prints("好厲害唷! 過五關嘍! 加P幣 %d 元!", 5 * PMONEY); + game_log(TEN_HALF, PMONEY * 5); + pressanykey(); + return 0; } j = 1; c[0] = 1; - while( j<5 && ((card_all(cpu) < card_all(me)) || - (card_all(cpu) == card_all(me) && j < i))) { - cpu[j] = card_give(cards); - c[j] = 1; - if(card_all(cpu) > 21) { - card_show(cpu, c, me, m); - move(b_lines - 1, 0); - prints("呵呵...電腦爆掉了! 你贏了! 可得P幣 %d 元", PMONEY * 2); - game_log(TEN_HALF, PMONEY * 2); - pressanykey(); - return 0; - } - j++; + while (j < 5 && ((card_all(cpu) < card_all(me)) || + (card_all(cpu) == card_all(me) && j < i))) { + cpu[j] = card_give(cards); + c[j] = 1; + if (card_all(cpu) > 21) { + card_show(cpu, c, me, m); + move(b_lines - 1, 0); + prints("呵呵...電腦爆掉了! 你贏了! 可得P幣 %d 元", PMONEY * 2); + game_log(TEN_HALF, PMONEY * 2); + pressanykey(); + return 0; + } + j++; } card_show(cpu, c, me, m); move(b_lines - 1, 0); @@ -589,25 +633,27 @@ static int ten_helf() { return 0; } -int g_ten_helf() { - char buf[3]; +int +g_ten_helf() +{ + char buf[3]; setutmpmode(TENHALF); - while(1) { - reload_money(); - if(cuser.money < TEN_HALF) { - outs("您的錢不夠唷!去多發表些有意義的文章再來~~~"); - return 0; - } - getdata(b_lines - 1, 0, - "\033[1;37m確定要玩十點半嗎 一次十元唷?(Y/N)?[N]\033[m", - buf, 3, LCECHO); - if(buf[0] != 'y' && buf[0] != 'Y') - return 0; - else { - vice(PMONEY, "十點半"); - ten_helf(); - } + while (1) { + reload_money(); + if (cuser.money < TEN_HALF) { + outs("您的錢不夠唷!去多發表些有意義的文章再來~~~"); + return 0; + } + getdata(b_lines - 1, 0, + "\033[1;37m確定要玩十點半嗎 一次十元唷?(Y/N)?[N]\033[m", + buf, 3, LCECHO); + if (buf[0] != 'y' && buf[0] != 'Y') + return 0; + else { + vice(PMONEY, "十點半"); + ten_helf(); + } } return 0; } diff --git a/pttbbs/mbbsd/chat.c b/pttbbs/mbbsd/chat.c index 17e004b0..5dd2d768 100644 --- a/pttbbs/mbbsd/chat.c +++ b/pttbbs/mbbsd/chat.c @@ -1,13 +1,15 @@ -/* $Id: chat.c,v 1.5 2002/06/04 13:08:33 in2 Exp $ */ +/* $Id: chat.c,v 1.6 2002/07/05 17:10:27 in2 Exp $ */ #include "bbs.h" -static int chatline, stop_line; -static FILE *flog; -static void printchatline(char *str) { +static int chatline, stop_line; +static FILE *flog; +static void +printchatline(char *str) +{ move(chatline, 0); - if(*str == '>' && !PERM_HIDE(currutmp)) + if (*str == '>' && !PERM_HIDE(currutmp)) return; - else if(chatline < stop_line - 1) + else if (chatline < stop_line - 1) chatline++; else { region_scroll_up(2, stop_line - 2); @@ -16,13 +18,15 @@ static void printchatline(char *str) { outs(str); outc('\n'); outs("→"); - - if(flog) + + if (flog) fprintf(flog, "%s\n", str); } -static void chat_clear() { - for(chatline = 2; chatline < stop_line; chatline++) { +static void +chat_clear() +{ + for (chatline = 2; chatline < stop_line; chatline++) { move(chatline, 0); clrtoeol(); } @@ -32,44 +36,50 @@ static void chat_clear() { outs("→"); } -static void print_chatid(char *chatid) { +static void +print_chatid(char *chatid) +{ move(b_lines - 1, 0); clrtoeol(); outs(chatid); outc(':'); } -static int chat_send(int fd, char *buf) { - int len; - char genbuf[200]; +static int +chat_send(int fd, char *buf) +{ + int len; + char genbuf[200]; sprintf(genbuf, "%s\n", buf); len = strlen(genbuf); return (send(fd, genbuf, len, 0) == len); } -static char chatroom[IDLEN]; /* Chat-Room Name */ +static char chatroom[IDLEN];/* Chat-Room Name */ -static int chat_recv(int fd, char *chatid) { - static char buf[512]; - static int bufstart = 0; - char genbuf[200]; - int c, len; - char *bptr; +static int +chat_recv(int fd, char *chatid) +{ + static char buf[512]; + static int bufstart = 0; + char genbuf[200]; + int c, len; + char *bptr; len = sizeof(buf) - bufstart - 1; - if((c = recv(fd, buf + bufstart, len, 0)) <= 0) + if ((c = recv(fd, buf + bufstart, len, 0)) <= 0) return -1; c += bufstart; bptr = buf; - while(c > 0) { + while (c > 0) { len = strlen(bptr) + 1; - if(len > c && len < (sizeof buf / 2)) + if (len > c && len < (sizeof buf / 2)) break; - if(*bptr == '/') { - switch(bptr[1]) { + if (*bptr == '/') { + switch (bptr[1]) { case 'c': chat_clear(); break; @@ -95,7 +105,7 @@ static int chat_recv(int fd, char *chatid) { bptr += len; } - if(c > 0) { + if (c > 0) { strcpy(genbuf, bptr); strcpy(buf, genbuf); bufstart = len - 1; @@ -104,28 +114,30 @@ static int chat_recv(int fd, char *chatid) { return 0; } -static int printuserent(userinfo_t *uentp) { - static char uline[80]; - static int cnt; - char pline[30]; +static int +printuserent(userinfo_t * uentp) +{ + static char uline[80]; + static int cnt; + char pline[30]; - if(!uentp) { - if(cnt) + if (!uentp) { + if (cnt) printchatline(uline); bzero(uline, 80); cnt = 0; return 0; } - if(!HAS_PERM(PERM_SYSOP) && !HAS_PERM(PERM_SEECLOAK) && uentp->invisible) + if (!HAS_PERM(PERM_SYSOP) && !HAS_PERM(PERM_SEECLOAK) && uentp->invisible) return 0; sprintf(pline, "%-13s%c%-10s ", uentp->userid, uentp->invisible ? '#' : ' ', modestring(uentp, 1)); - if(cnt < 2) + if (cnt < 2) strcat(pline, "│"); strcat(uline, pline); - if(++cnt == 3) { + if (++cnt == 3) { printchatline(uline); memset(uline, 0, 80); cnt = 0; @@ -133,15 +145,19 @@ static int printuserent(userinfo_t *uentp) { return 0; } -static void chathelp(char *cmd, char *desc) { - char buf[STRLEN]; - +static void +chathelp(char *cmd, char *desc) +{ + char buf[STRLEN]; + sprintf(buf, " %-20s- %s", cmd, desc); printchatline(buf); } -static void chat_help(char *arg) { - if(strstr(arg, " op")) { +static void +chat_help(char *arg) +{ + if (strstr(arg, " op")) { printchatline("談天室管理員專用指令"); chathelp("[/f]lag [+-][ls]", "設定鎖定、秘密狀態"); chathelp("[/i]nvite <id>", "邀請 <id> 加入談天室"); @@ -169,45 +185,51 @@ static void chat_help(char *arg) { } } -static void chat_date() { - char genbuf[200]; +static void +chat_date() +{ + char genbuf[200]; sprintf(genbuf, "◆ " BBSNAME "標準時間: %s", Cdate(&now)); printchatline(genbuf); } -static void chat_pager() { - char genbuf[200]; +static void +chat_pager() +{ + char genbuf[200]; - char *msgs[] = {"關閉", "打開", "拔掉", "防水","好友"}; + char *msgs[] = {"關閉", "打開", "拔掉", "防水", "好友"}; sprintf(genbuf, "◆ 您的呼叫器:[%s]", - msgs[currutmp->pager = (currutmp->pager+1)%5]); + msgs[currutmp->pager = (currutmp->pager + 1) % 5]); printchatline(genbuf); } -static void chat_query(char *arg) { - char *uid; - int tuid; - +static void +chat_query(char *arg) +{ + char *uid; + int tuid; + printchatline(""); strtok(arg, str_space); - if((uid = strtok(NULL, str_space)) && (tuid = getuser(uid))) { - char buf[128], *ptr; - FILE *fp; - + if ((uid = strtok(NULL, str_space)) && (tuid = getuser(uid))) { + char buf[128], *ptr; + FILE *fp; + sprintf(buf, "%s(%s) 共上站 %d 次,發表過 %d 篇文章", - xuser.userid, xuser.username, xuser.numlogins, xuser.numposts); + xuser.userid, xuser.username, xuser.numlogins, xuser.numposts); printchatline(buf); - + sprintf(buf, "最近(%s)從[%s]上站", Cdate(&xuser.lastlogin), (xuser.lasthost[0] ? xuser.lasthost : "(不詳)")); printchatline(buf); - + sethomefile(buf, xuser.userid, fn_plans); - if((fp = fopen(buf, "r"))) { + if ((fp = fopen(buf, "r"))) { tuid = 0; - while(tuid++ < MAX_QUERYLINES && fgets(buf, 128, fp)) { - if((ptr = strchr(buf, '\n'))) + while (tuid++ < MAX_QUERYLINES && fgets(buf, 128, fp)) { + if ((ptr = strchr(buf, '\n'))) ptr[0] = '\0'; printchatline(buf); } @@ -217,20 +239,22 @@ static void chat_query(char *arg) { printchatline(err_uid); } -static void chat_users() { +static void +chat_users() +{ printchatline(""); printchatline("【 " BBSNAME "的遊客列表 】"); printchatline(msg_shortulist); - if(apply_ulist(printuserent) == -1) + if (apply_ulist(printuserent) == -1) printchatline("空無一人"); printuserent(NULL); } typedef struct chat_command_t { - char *cmdname; /* Chatroom command length */ - void (*cmdfunc) (); /* Pointer to function */ -} chat_command_t; + char *cmdname; /* Chatroom command length */ + void (*cmdfunc) (); /* Pointer to function */ +} chat_command_t; static chat_command_t chat_cmdtbl[] = { {"help", chat_help}, @@ -242,21 +266,25 @@ static chat_command_t chat_cmdtbl[] = { {NULL, NULL} }; -static int chat_cmd_match(char *buf, char *str) { - while(*str && *buf && !isspace(*buf)) - if(tolower(*buf++) != *str++) +static int +chat_cmd_match(char *buf, char *str) +{ + while (*str && *buf && !isspace(*buf)) + if (tolower(*buf++) != *str++) return 0; return 1; } -static int chat_cmd(char *buf, int fd) { - int i; +static int +chat_cmd(char *buf, int fd) +{ + int i; - if(*buf++ != '/') + if (*buf++ != '/') return 0; - for(i = 0; chat_cmdtbl[i].cmdname; i++) { - if(chat_cmd_match(buf, chat_cmdtbl[i].cmdname)) { + for (i = 0; chat_cmdtbl[i].cmdname; i++) { + if (chat_cmd_match(buf, chat_cmdtbl[i].cmdname)) { chat_cmdtbl[i].cmdfunc(buf); return 1; } @@ -265,31 +293,33 @@ static int chat_cmd(char *buf, int fd) { } #if 0 -static char *select_address() { - int c; - FILE *fp; - char nametab[25][90]; - char iptab[25][18], buf[80]; +static char * +select_address() +{ + int c; + FILE *fp; + char nametab[25][90]; + char iptab[25][18], buf[80]; move(1, 0); clrtobot(); outs("\n \033[36m【找個地方抬抬槓吧!】\033[m " "◎ 【以下為本站登記有案的茶樓】 \n"); - trans_buffer[0]=0; - if((fp = fopen("etc/teashop", "r"))) { - for(c = 0; fscanf(fp, "%s%s", iptab[c], nametab[c]) != EOF; c++) { - sprintf(buf,"\n (\033[36m%d\033[0m) %-30s [%s]", + trans_buffer[0] = 0; + if ((fp = fopen("etc/teashop", "r"))) { + for (c = 0; fscanf(fp, "%s%s", iptab[c], nametab[c]) != EOF; c++) { + sprintf(buf, "\n (\033[36m%d\033[0m) %-30s [%s]", c + 1, nametab[c], iptab[c]); - outs(buf); + outs(buf); } - getdata(20, 10, "★\033[32m 請選擇,[0]離開:\033[0m", buf, 3, + getdata(20, 10, "★\033[32m 請選擇,[0]離開:\033[0m", buf, 3, LCECHO); - if(buf[1]) + if (buf[1]) buf[0] = (buf[0] + 1) * 10 + (buf[1] - '1'); else buf[0] -= '1'; - if(buf[0] >= 0 && buf[0] < c) - strcpy(trans_buffer,iptab[(int)buf[0]]); + if (buf[0] >= 0 && buf[0] < c) + strcpy(trans_buffer, iptab[(int)buf[0]]); } else { outs("本站沒有登記任何合格茶樓"); pressanykey(); @@ -299,25 +329,27 @@ static char *select_address() { #endif #define MAXLASTCMD 6 -static int chatid_len = 10; +static int chatid_len = 10; -int t_chat() { - char inbuf[80], chatid[20], lastcmd[MAXLASTCMD][80], *ptr = ""; +int +t_chat() +{ + char inbuf[80], chatid[20], lastcmd[MAXLASTCMD][80], *ptr = ""; struct sockaddr_in sin; struct hostent *h; - int cfd, cmdpos, ch; - int currchar; - int newmail; - int chatting = YEA; - char fpath[80]; - char genbuf[200]; - char roomtype; - - if(inbuf[0] == 0) + int cfd, cmdpos, ch; + int currchar; + int newmail; + int chatting = YEA; + char fpath[80]; + char genbuf[200]; + char roomtype; + + if (inbuf[0] == 0) return -1; outs(" 驅車前往 請梢候........ "); - if(!(h = gethostbyname("localhost"))) { + if (!(h = gethostbyname("localhost"))) { perror("gethostbyname"); return -1; } @@ -329,69 +361,69 @@ int t_chat() { memcpy(&sin.sin_addr, h->h_addr, h->h_length); sin.sin_port = htons(NEW_CHATPORT); cfd = socket(sin.sin_family, SOCK_STREAM, 0); - if(!(connect(cfd, (struct sockaddr *) & sin, sizeof sin))) + if (!(connect(cfd, (struct sockaddr *) & sin, sizeof sin))) roomtype = 1; else { sin.sin_port = CHATPORT; cfd = socket(sin.sin_family, SOCK_STREAM, 0); - if(!(connect(cfd, (struct sockaddr *) & sin, sizeof sin))) + if (!(connect(cfd, (struct sockaddr *) & sin, sizeof sin))) roomtype = 2; else { outs("\n " "哇! 沒人在那邊耶...要有那地方的人先去開門啦!..."); - system("bin/xchatd"); + system("bin/xchatd"); pressanykey(); return -1; } } - - while(1) { + + while (1) { getdata(b_lines - 1, 0, "請輸入聊天代號:", inbuf, 9, DOECHO); sprintf(chatid, "%s", (inbuf[0] ? inbuf : cuser.userid)); chatid[8] = '\0'; -/* - 舊格式: /! 使用者編號 使用者等級 UserID ChatID - 新格式: /! UserID ChatID Password -*/ - if(roomtype == 1) + /* + * 舊格式: /! 使用者編號 使用者等級 UserID ChatID 新格式: /! + * UserID ChatID Password + */ + if (roomtype == 1) sprintf(inbuf, "/! %s %s %s", cuser.userid, chatid, cuser.passwd); else sprintf(inbuf, "/! %d %d %s %s", usernum, cuser.userlevel, cuser.userid, chatid); chat_send(cfd, inbuf); - if(recv(cfd, inbuf, 3, 0) != 3) + if (recv(cfd, inbuf, 3, 0) != 3) return 0; - if(!strcmp(inbuf, CHAT_LOGIN_OK)) + if (!strcmp(inbuf, CHAT_LOGIN_OK)) break; - else if(!strcmp(inbuf, CHAT_LOGIN_EXISTS)) + else if (!strcmp(inbuf, CHAT_LOGIN_EXISTS)) ptr = "這個代號已經有人用了"; - else if(!strcmp(inbuf, CHAT_LOGIN_INVALID)) + else if (!strcmp(inbuf, CHAT_LOGIN_INVALID)) ptr = "這個代號是錯誤的"; - else if(!strcmp(inbuf, CHAT_LOGIN_BOGUS)) + else if (!strcmp(inbuf, CHAT_LOGIN_BOGUS)) ptr = "請勿派遣分身進入聊天室 !!"; - + move(b_lines - 2, 0); outs(ptr); clrtoeol(); bell(); } - + add_io(cfd, 0); - + newmail = currchar = 0; cmdpos = -1; memset(lastcmd, 0, MAXLASTCMD * 80); - + setutmpmode(CHATING); currutmp->in_chat = YEA; strcpy(currutmp->chatid, chatid); - + clear(); chatline = 2; strcpy(inbuf, chatid); stop_line = t_lines - 3; - + move(stop_line, 0); outs(msg_seperator); move(1, 0); @@ -403,11 +435,11 @@ int t_chat() { strcpy(fpath, tempnam(fpath, "chat_")); flog = fopen(fpath, "w"); - while(chatting) { + while (chatting) { move(b_lines - 1, currchar + chatid_len); ch = igetkey(); - switch(ch) { + switch (ch) { case KEY_DOWN: cmdpos += MAXLASTCMD - 2; case KEY_UP: @@ -420,37 +452,36 @@ int t_chat() { currchar = strlen(inbuf); continue; case KEY_LEFT: - if(currchar) + if (currchar) --currchar; continue; case KEY_RIGHT: - if(inbuf[currchar]) + if (inbuf[currchar]) ++currchar; continue; } - if(!newmail && currutmp->mailalert ) { + if (!newmail && currutmp->mailalert) { newmail = 1; printchatline("◆ 噹!郵差又來了..."); } - - if(ch == I_OTHERDATA) { /* incoming */ - if(chat_recv(cfd, chatid) == -1) { + if (ch == I_OTHERDATA) {/* incoming */ + if (chat_recv(cfd, chatid) == -1) { chatting = chat_send(cfd, "/b"); break; } continue; } - if(isprint2(ch)) { - if(currchar < 68) { - if(inbuf[currchar]) { /* insert */ - int i; - - for(i = currchar; inbuf[i] && i < 68; i++); - inbuf[i + 1 ] = '\0'; - for(; i > currchar; i--) + if (isprint2(ch)) { + if (currchar < 68) { + if (inbuf[currchar]) { /* insert */ + int i; + + for (i = currchar; inbuf[i] && i < 68; i++); + inbuf[i + 1] = '\0'; + for (; i > currchar; i--) inbuf[i] = inbuf[i - 1]; - } else /* append */ + } else /* append */ inbuf[currchar + 1] = '\0'; inbuf[currchar] = ch; move(b_lines - 1, currchar + chatid_len); @@ -458,19 +489,18 @@ int t_chat() { } continue; } - - if(ch == '\n' || ch == '\r') { - if(*inbuf) { + if (ch == '\n' || ch == '\r') { + if (*inbuf) { chatting = chat_cmd(inbuf, cfd); - if(chatting == 0) + if (chatting == 0) chatting = chat_send(cfd, inbuf); - if(!strncmp(inbuf, "/b", 2)) + if (!strncmp(inbuf, "/b", 2)) break; - - for(cmdpos = MAXLASTCMD - 1; cmdpos; cmdpos--) + + for (cmdpos = MAXLASTCMD - 1; cmdpos; cmdpos--) strcpy(lastcmd[cmdpos], lastcmd[cmdpos - 1]); strcpy(lastcmd[0], inbuf); - + inbuf[0] = '\0'; currchar = 0; cmdpos = -1; @@ -479,9 +509,8 @@ int t_chat() { move(b_lines - 1, chatid_len); continue; } - - if(ch == Ctrl('H') || ch == '\177') { - if(currchar) { + if (ch == Ctrl('H') || ch == '\177') { + if (currchar) { currchar--; inbuf[69] = '\0'; memcpy(&inbuf[currchar], &inbuf[currchar + 1], 69 - currchar); @@ -491,20 +520,19 @@ int t_chat() { } continue; } - if(ch == Ctrl('Z') || ch == Ctrl('Y')) { + if (ch == Ctrl('Z') || ch == Ctrl('Y')) { inbuf[0] = '\0'; currchar = 0; print_chatid(chatid); move(b_lines - 1, chatid_len); continue; } - - if(ch == Ctrl('C')) { + if (ch == Ctrl('C')) { chat_send(cfd, "/b"); break; } - if(ch == Ctrl('D')) { - if(currchar < strlen(inbuf)) { + if (ch == Ctrl('D')) { + if (currchar < strlen(inbuf)) { inbuf[69] = '\0'; memcpy(&inbuf[currchar], &inbuf[currchar + 1], 69 - currchar); move(b_lines - 1, currchar + chatid_len); @@ -513,22 +541,22 @@ int t_chat() { } continue; } - if(ch == Ctrl('K')) { + if (ch == Ctrl('K')) { inbuf[currchar] = 0; move(b_lines - 1, currchar + chatid_len); clrtoeol(); continue; } - if(ch == Ctrl('A')) { + if (ch == Ctrl('A')) { currchar = 0; continue; } - if(ch == Ctrl('E')) { + if (ch == Ctrl('E')) { currchar = strlen(inbuf); continue; } - if(ch == Ctrl('I')) { - screenline_t *screen0 = calloc(t_lines, sizeof(screenline_t)); + if (ch == Ctrl('I')) { + screenline_t *screen0 = calloc(t_lines, sizeof(screenline_t)); memcpy(screen0, big_picture, t_lines * sizeof(screenline_t)); add_io(0, 0); @@ -539,32 +567,32 @@ int t_chat() { add_io(cfd, 0); continue; } - if(ch == Ctrl('Q')) { + if (ch == Ctrl('Q')) { print_chatid(chatid); move(b_lines - 1, chatid_len); outs(inbuf); continue; } } - + close(cfd); add_io(0, 0); currutmp->in_chat = currutmp->chatid[0] = 0; - - if(flog) { - char ans[4]; - + + if (flog) { + char ans[4]; + fclose(flog); more(fpath, NA); getdata(b_lines - 1, 0, "清除(C) 移至備忘錄(M) (C/M)?[C]", ans, sizeof(ans), LCECHO); if (*ans == 'm') { - fileheader_t mymail; - char title[128]; - + fileheader_t mymail; + char title[128]; + sethomepath(genbuf, cuser.userid); stampfile(genbuf, &mymail); - mymail.filemode = FILE_READ|FILE_HOLD; + mymail.filemode = FILE_READ | FILE_HOLD; strcpy(mymail.owner, "[備.忘.錄]"); strcpy(mymail.title, "會議\033[1;33m記錄\033[m"); sethomedir(title, cuser.userid); @@ -573,7 +601,6 @@ int t_chat() { } else unlink(fpath); } - return 0; } /* -------------------------------------------------- */ diff --git a/pttbbs/mbbsd/chc_draw.c b/pttbbs/mbbsd/chc_draw.c index bb9a15a9..9f4091b1 100644 --- a/pttbbs/mbbsd/chc_draw.c +++ b/pttbbs/mbbsd/chc_draw.c @@ -1,4 +1,4 @@ -/* $Id: chc_draw.c,v 1.2 2002/06/04 13:08:33 in2 Exp $ */ +/* $Id: chc_draw.c,v 1.3 2002/07/05 17:10:27 in2 Exp $ */ #include "bbs.h" #define SIDE_ROW 10 @@ -9,49 +9,51 @@ #define MYWIN_ROW 17 #define HISWIN_ROW 18 -static char *turn_str[2] = {"黑的", "紅的"}; +static char *turn_str[2] = {"黑的", "紅的"}; -static char *num_str[10] = { +static char *num_str[10] = { "", "一", "二", "三", "四", "五", "六", "七", "八", "九" }; -static char *chess_str[2][8] = { +static char *chess_str[2][8] = { /* 0 1 2 3 4 5 6 7 */ {" ", "將", "士", "象", "車", "馬", "包", "卒"}, {" ", "帥", "仕", "相", "車", "傌", "炮", "兵"} }; -static char *chess_brd[BRD_ROW * 2 - 1] = { - /*0 1 2 3 4 5 6 7 8*/ - "┌─┬─┬─┬─┬─┬─┬─┬─┐", /* 0 */ +static char *chess_brd[BRD_ROW * 2 - 1] = { + /* 0 1 2 3 4 5 6 7 8 */ + "┌─┬─┬─┬─┬─┬─┬─┬─┐", /* 0 */ "│ │ │ │\│/│ │ │ │", - "├─┼─┼─┼─┼─┼─┼─┼─┤", /* 1 */ + "├─┼─┼─┼─┼─┼─┼─┼─┤", /* 1 */ "│ │ │ │/│\│ │ │ │", - "├─┼─┼─┼─┼─┼─┼─┼─┤", /* 2 */ + "├─┼─┼─┼─┼─┼─┼─┼─┤", /* 2 */ "│ │ │ │ │ │ │ │ │", - "├─┼─┼─┼─┼─┼─┼─┼─┤", /* 3 */ + "├─┼─┼─┼─┼─┼─┼─┼─┤", /* 3 */ "│ │ │ │ │ │ │ │ │", - "├─┴─┴─┴─┴─┴─┴─┴─┤", /* 4 */ + "├─┴─┴─┴─┴─┴─┴─┴─┤", /* 4 */ "│ 楚 河 漢 界 │", - "├─┬─┬─┬─┬─┬─┬─┬─┤", /* 5 */ + "├─┬─┬─┬─┬─┬─┬─┬─┤", /* 5 */ "│ │ │ │ │ │ │ │ │", - "├─┼─┼─┼─┼─┼─┼─┼─┤", /* 6 */ + "├─┼─┼─┼─┼─┼─┼─┼─┤", /* 6 */ "│ │ │ │ │ │ │ │ │", - "├─┼─┼─┼─┼─┼─┼─┼─┤", /* 7 */ + "├─┼─┼─┼─┼─┼─┼─┼─┤", /* 7 */ "│ │ │ │\│/│ │ │ │", - "├─┼─┼─┼─┼─┼─┼─┼─┤", /* 8 */ + "├─┼─┼─┼─┼─┼─┼─┼─┤", /* 8 */ "│ │ │ │/│\│ │ │ │", - "└─┴─┴─┴─┴─┴─┴─┴─┘" /* 9 */ + "└─┴─┴─┴─┴─┴─┴─┴─┘" /* 9 */ }; -static char *hint_str[] = { +static char *hint_str[] = { " q 認輸離開", " p 要求和棋", "方向鍵 移動遊標", "Enter 選擇/移動" }; -void chc_movecur(int r, int c) { +void +chc_movecur(int r, int c) +{ move(r * 2 + 3, c * 4 + 4); } @@ -61,22 +63,25 @@ void chc_movecur(int r, int c) { #define RED_REVERSE "\033[1;37;41m" #define TURN_COLOR "\033[1;33m" -static void showstep(board_t board) { - int turn, fc, tc, eatten; - char *dir; - +static void +showstep(board_t board) +{ + int turn, fc, tc, eatten; + char *dir; + turn = CHE_O(board[chc_from.r][chc_from.c]); fc = (turn == (chc_my ^ 1) ? chc_from.c + 1 : 9 - chc_from.c); tc = (turn == (chc_my ^ 1) ? chc_to.c + 1 : 9 - chc_to.c); - if(chc_from.r == chc_to.r) + if (chc_from.r == chc_to.r) dir = "平"; else { - if(chc_from.c == chc_to.c) + if (chc_from.c == chc_to.c) tc = chc_from.r - chc_to.r; - if(tc < 0) tc = -tc; - - if((turn == (chc_my ^ 1) && chc_to.r > chc_from.r) || - (turn == chc_my && chc_to.r < chc_from.r)) + if (tc < 0) + tc = -tc; + + if ((turn == (chc_my ^ 1) && chc_to.r > chc_from.r) || + (turn == chc_my && chc_to.r < chc_from.r)) dir = "進"; else dir = "退"; @@ -86,28 +91,30 @@ static void showstep(board_t board) { chess_str[turn][CHE_P(board[chc_from.r][chc_from.c])], num_str[fc], dir, num_str[tc]); eatten = board[chc_to.r][chc_to.c]; - if(eatten) + if (eatten) prints(": %s%s", CHE_O(eatten) == 0 ? BLACK_COLOR : RED_COLOR, chess_str[CHE_O(eatten)][CHE_P(eatten)]); prints("\033[m"); } -void chc_drawline(board_t board, int line) { - int i, j; - +void +chc_drawline(board_t board, int line) +{ + int i, j; + move(line, 0); clrtoeol(); - if(line == 0) { + if (line == 0) { prints("\033[1;46m 象棋對戰 \033[45m%30s VS %-30s\033[m", cuser.userid, chc_mateid); - } else if(line >= 3 && line <= 21) { + } else if (line >= 3 && line <= 21) { outs(" "); - for(i = 0; i < 9; i++) { + for (i = 0; i < 9; i++) { j = board[RTL(line)][i]; - if((line & 1) == 1 && j) { - if(chc_selected && - chc_select.r == RTL(line) && chc_select.c == i) + if ((line & 1) == 1 && j) { + if (chc_selected && + chc_select.r == RTL(line) && chc_select.c == i) prints("%s%s\033[m", CHE_O(j) == 0 ? BLACK_REVERSE : RED_REVERSE, chess_str[CHE_O(j)][CHE_P(j)]); @@ -118,36 +125,36 @@ void chc_drawline(board_t board, int line) { } else prints("%c%c", chess_brd[line - 3][i * 4], chess_brd[line - 3][i * 4 + 1]); - if(i != 8) + if (i != 8) prints("%c%c", chess_brd[line - 3][i * 4 + 2], chess_brd[line - 3][i * 4 + 3]); } outs(" "); - if(line >= 3 && line < 3 + dim(hint_str)) { + if (line >= 3 && line < 3 + dim(hint_str)) { outs(hint_str[line - 3]); - } else if(line == SIDE_ROW) { + } else if (line == SIDE_ROW) { prints("\033[1m你是%s%s\033[m", chc_my == 0 ? BLACK_COLOR : RED_COLOR, turn_str[chc_my]); - } else if(line == TURN_ROW) { + } else if (line == TURN_ROW) { prints("%s%s\033[m", TURN_COLOR, chc_my == chc_turn ? "輪到你下棋了" : "等待對方下棋"); - } else if(line == STEP_ROW && !chc_firststep) { + } else if (line == STEP_ROW && !chc_firststep) { showstep(board); - } else if(line == TIME_ROW) { + } else if (line == TIME_ROW) { prints("剩餘時間 %d:%02d", chc_lefttime / 60, chc_lefttime % 60); - } else if(line == WARN_ROW) { + } else if (line == WARN_ROW) { outs(chc_warnmsg); - } else if(line == MYWIN_ROW) { + } else if (line == MYWIN_ROW) { prints("\033[1;33m%12.12s " "\033[1;31m%2d\033[37m勝 " "\033[34m%2d\033[37m敗 " "\033[36m%2d\033[37m和\033[m", cuser.userid, cuser.chc_win, cuser.chc_lose - 1, cuser.chc_tie); - } else if(line == HISWIN_ROW) { + } else if (line == HISWIN_ROW) { prints("\033[1;33m%12.12s " "\033[1;31m%2d\033[37m勝 " "\033[34m%2d\033[37m敗 " @@ -155,20 +162,22 @@ void chc_drawline(board_t board, int line) { chc_mateid, chc_hiswin, chc_hislose - 1, chc_histie); } - } else if(line == 2 || line == 22) { + } else if (line == 2 || line == 22) { outs(" "); - if(line == 2) - for(i = 1; i <= 9; i++) + if (line == 2) + for (i = 1; i <= 9; i++) prints("%s ", num_str[i]); else - for(i = 9; i >= 1; i--) + for (i = 9; i >= 1; i--) prints("%s ", num_str[i]); } } -void chc_redraw(board_t board) { - int i; - - for(i = 0; i <= 22; i++) +void +chc_redraw(board_t board) +{ + int i; + + for (i = 0; i <= 22; i++) chc_drawline(board, i); } diff --git a/pttbbs/mbbsd/chc_net.c b/pttbbs/mbbsd/chc_net.c index b9f63d8f..ba52bf26 100644 --- a/pttbbs/mbbsd/chc_net.c +++ b/pttbbs/mbbsd/chc_net.c @@ -1,21 +1,25 @@ -/* $Id: chc_net.c,v 1.2 2002/06/04 13:08:33 in2 Exp $ */ +/* $Id: chc_net.c,v 1.3 2002/07/05 17:10:27 in2 Exp $ */ #include "bbs.h" typedef struct drc_t { - rc_t from, to; -} drc_t; + rc_t from, to; +} drc_t; -int chc_recvmove(int s) { - drc_t buf; +int +chc_recvmove(int s) +{ + drc_t buf; - if(read(s, &buf, sizeof(buf)) != sizeof(buf)) + if (read(s, &buf, sizeof(buf)) != sizeof(buf)) return 1; chc_from = buf.from, chc_to = buf.to; return 0; } -void chc_sendmove(int s) { - drc_t buf; - +void +chc_sendmove(int s) +{ + drc_t buf; + buf.from = chc_from, buf.to = chc_to; write(s, &buf, sizeof(buf)); } diff --git a/pttbbs/mbbsd/chc_play.c b/pttbbs/mbbsd/chc_play.c index cffe3959..de093052 100644 --- a/pttbbs/mbbsd/chc_play.c +++ b/pttbbs/mbbsd/chc_play.c @@ -1,8 +1,8 @@ -/* $Id: chc_play.c,v 1.3 2002/06/04 13:08:33 in2 Exp $ */ +/* $Id: chc_play.c,v 1.4 2002/07/05 17:10:27 in2 Exp $ */ #include "bbs.h" -typedef int (*play_func_t)(int, board_t, board_t); +typedef int (*play_func_t) (int, board_t, board_t); -static int chc_ipass = 0, chc_hepass = 0; +static int chc_ipass = 0, chc_hepass = 0; #define CHC_TIMEOUT 300 #define SIDE_ROW 10 @@ -13,14 +13,16 @@ static int chc_ipass = 0, chc_hepass = 0; #define MYWIN_ROW 17 #define HISWIN_ROW 18 -static int hisplay(int s, board_t board, board_t tmpbrd) { - int start_time; - int endgame = 0, endturn = 0; - +static int +hisplay(int s, board_t board, board_t tmpbrd) +{ + int start_time; + int endgame = 0, endturn = 0; + start_time = now; - while(!endturn) { + while (!endturn) { chc_lefttime = CHC_TIMEOUT - (now - start_time); - if(chc_lefttime < 0) { + if (chc_lefttime < 0) { chc_lefttime = 0; /* to make him break out igetkey() */ @@ -30,13 +32,13 @@ static int hisplay(int s, board_t board, board_t tmpbrd) { chc_drawline(board, TIME_ROW); move(1, 0); oflush(); - switch(igetkey()) { + switch (igetkey()) { case 'q': endgame = 2; endturn = 1; break; case 'p': - if(chc_hepass) { + if (chc_hepass) { chc_from.r = -1; chc_sendmove(s); endgame = 3; @@ -44,11 +46,11 @@ static int hisplay(int s, board_t board, board_t tmpbrd) { } break; case I_OTHERDATA: - if(chc_recvmove(s)) { /* disconnect */ + if (chc_recvmove(s)) { /* disconnect */ endturn = 1; endgame = 1; } else { - if(chc_from.r == -1) { + if (chc_from.r == -1) { chc_hepass = 1; strcpy(chc_warnmsg, "\033[1;33m要求和局!\033[m"); chc_drawline(board, WARN_ROW); @@ -56,7 +58,7 @@ static int hisplay(int s, board_t board, board_t tmpbrd) { chc_from.r = 9 - chc_from.r, chc_from.c = 8 - chc_from.c; chc_to.r = 9 - chc_to.r, chc_to.c = 8 - chc_to.c; chc_cursor = chc_to; - if(CHE_P(board[chc_to.r][chc_to.c]) == 1) + if (CHE_P(board[chc_to.r][chc_to.c]) == 1) endgame = 2; endturn = 1; chc_hepass = 0; @@ -72,50 +74,52 @@ static int hisplay(int s, board_t board, board_t tmpbrd) { return endgame; } -static int myplay(int s, board_t board, board_t tmpbrd) { - int ch, start_time; - int endgame = 0, endturn = 0; - +static int +myplay(int s, board_t board, board_t tmpbrd) +{ + int ch, start_time; + int endgame = 0, endturn = 0; + chc_ipass = 0, chc_selected = 0; start_time = now; chc_lefttime = CHC_TIMEOUT - (now - start_time); bell(); - while(!endturn) { + while (!endturn) { chc_drawline(board, TIME_ROW); chc_movecur(chc_cursor.r, chc_cursor.c); oflush(); ch = igetkey(); - chc_lefttime = CHC_TIMEOUT - (now - start_time); - if(chc_lefttime < 0) + chc_lefttime = CHC_TIMEOUT - (now - start_time); + if (chc_lefttime < 0) ch = 'q'; - switch(ch) { + switch (ch) { case I_OTHERDATA: - if(chc_recvmove(s)) { /* disconnect */ + if (chc_recvmove(s)) { /* disconnect */ endgame = 1; endturn = 1; - } else if(chc_from.r == -1 && chc_ipass) { + } else if (chc_from.r == -1 && chc_ipass) { endgame = 3; endturn = 1; } break; case KEY_UP: chc_cursor.r--; - if(chc_cursor.r < 0) + if (chc_cursor.r < 0) chc_cursor.r = BRD_ROW - 1; break; case KEY_DOWN: chc_cursor.r++; - if(chc_cursor.r >= BRD_ROW) + if (chc_cursor.r >= BRD_ROW) chc_cursor.r = 0; break; case KEY_LEFT: chc_cursor.c--; - if(chc_cursor.c < 0) + if (chc_cursor.c < 0) chc_cursor.c = BRD_COL - 1; break; case KEY_RIGHT: chc_cursor.c++; - if(chc_cursor.c >= BRD_COL) + if (chc_cursor.c >= BRD_COL) chc_cursor.c = 0; break; case 'q': @@ -133,21 +137,21 @@ static int myplay(int s, board_t board, board_t tmpbrd) { case '\r': case '\n': case ' ': - if(chc_selected) { - if(chc_cursor.r == chc_select.r && - chc_cursor.c == chc_select.c) { + if (chc_selected) { + if (chc_cursor.r == chc_select.r && + chc_cursor.c == chc_select.c) { chc_selected = 0; chc_drawline(board, LTR(chc_cursor.r)); - } else if(chc_canmove(board, chc_select, chc_cursor)) { - if(CHE_P(board[chc_cursor.r][chc_cursor.c]) == 1) + } else if (chc_canmove(board, chc_select, chc_cursor)) { + if (CHE_P(board[chc_cursor.r][chc_cursor.c]) == 1) endgame = 1; chc_from = chc_select; chc_to = chc_cursor; - if(!endgame) { + if (!endgame) { memcpy(tmpbrd, board, sizeof(board_t)); chc_movechess(tmpbrd); } - if(endgame || !chc_iskfk(tmpbrd)) { + if (endgame || !chc_iskfk(tmpbrd)) { chc_drawline(board, STEP_ROW); chc_movechess(board); chc_sendmove(s); @@ -161,8 +165,8 @@ static int myplay(int s, board_t board, board_t tmpbrd) { chc_drawline(board, WARN_ROW); } } - } else if(board[chc_cursor.r][chc_cursor.c] && - CHE_O(board[chc_cursor.r][chc_cursor.c]) == chc_turn) { + } else if (board[chc_cursor.r][chc_cursor.c] && + CHE_O(board[chc_cursor.r][chc_cursor.c]) == chc_turn) { chc_selected = 1; chc_select = chc_cursor; chc_drawline(board, LTR(chc_cursor.r)); @@ -173,29 +177,31 @@ static int myplay(int s, board_t board, board_t tmpbrd) { return endgame; } -static void mainloop(int s, board_t board) { - int endgame; - board_t tmpbrd; - play_func_t play_func[2]; - +static void +mainloop(int s, board_t board) +{ + int endgame; + board_t tmpbrd; + play_func_t play_func[2]; + play_func[chc_my] = myplay; play_func[chc_my ^ 1] = hisplay; - for(chc_turn = 1, endgame = 0; !endgame; chc_turn ^= 1) { + for (chc_turn = 1, endgame = 0; !endgame; chc_turn ^= 1) { chc_firststep = 0; chc_drawline(board, TURN_ROW); - if(chc_ischeck(board, chc_turn)) { + if (chc_ischeck(board, chc_turn)) { strcpy(chc_warnmsg, "\033[1;31m將軍!\033[m"); bell(); } else chc_warnmsg[0] = 0; chc_drawline(board, WARN_ROW); - endgame = play_func[chc_turn](s, board, tmpbrd); + endgame = play_func[chc_turn] (s, board, tmpbrd); } - - if(endgame == 1) { + + if (endgame == 1) { strcpy(chc_warnmsg, "對方認輸了!"); cuser.chc_win++; - } else if(endgame == 2) { + } else if (endgame == 2) { strcpy(chc_warnmsg, "你認輸了!"); cuser.chc_lose++; } else { @@ -209,8 +215,10 @@ static void mainloop(int s, board_t board) { oflush(); } -static void chc_init(int s, board_t board) { - userinfo_t *my = currutmp; +static void +chc_init(int s, board_t board) +{ + userinfo_t *my = currutmp; setutmpmode(CHC); clear(); @@ -222,34 +230,37 @@ static void chc_init(int s, board_t board) { chc_redraw(board); chc_cursor.r = 9, chc_cursor.c = 0; add_io(s, 0); - - if(my->turn) chc_recvmove(s); + + if (my->turn) + chc_recvmove(s); passwd_query(usernum, &xuser); cuser.chc_win = xuser.chc_win; cuser.chc_lose = xuser.chc_lose + 1; cuser.chc_tie = xuser.chc_tie; - cuser.money = xuser.money; + cuser.money = xuser.money; passwd_update(usernum, &cuser); - + getuser(chc_mateid); chc_hiswin = xuser.chc_win; chc_hislose = xuser.chc_lose; chc_histie = xuser.chc_tie; - - if(!my->turn) { + + if (!my->turn) { chc_sendmove(s); chc_hislose++; } - chc_redraw(board); } -void chc(int s) { - board_t board; - +void +chc(int s) +{ + board_t board; + chc_init(s, board); mainloop(s, board); close(s); add_io(0, 0); - if(chc_my) pressanykey(); + if (chc_my) + pressanykey(); } diff --git a/pttbbs/mbbsd/chc_rule.c b/pttbbs/mbbsd/chc_rule.c index e5a92c32..62996764 100644 --- a/pttbbs/mbbsd/chc_rule.c +++ b/pttbbs/mbbsd/chc_rule.c @@ -1,177 +1,195 @@ -/* $Id: chc_rule.c,v 1.2 2002/06/04 13:08:33 in2 Exp $ */ +/* $Id: chc_rule.c,v 1.3 2002/07/05 17:10:27 in2 Exp $ */ #include "bbs.h" #define CENTER(a, b) (((a) + (b)) >> 1) -void chc_init_board(board_t board) { +void +chc_init_board(board_t board) +{ memset(board, 0, sizeof(board_t)); - board[0][4] = CHE(1, chc_my ^ 1); /* 將 */ - board[0][3] = board[0][5] = CHE(2, chc_my ^ 1); /* 士 */ - board[0][2] = board[0][6] = CHE(3, chc_my ^ 1); /* 象 */ - board[0][0] = board[0][8] = CHE(4, chc_my ^ 1); /* 車 */ - board[0][1] = board[0][7] = CHE(5, chc_my ^ 1); /* 馬 */ - board[2][1] = board[2][7] = CHE(6, chc_my ^ 1); /* 包 */ + board[0][4] = CHE(1, chc_my ^ 1); /* 將 */ + board[0][3] = board[0][5] = CHE(2, chc_my ^ 1); /* 士 */ + board[0][2] = board[0][6] = CHE(3, chc_my ^ 1); /* 象 */ + board[0][0] = board[0][8] = CHE(4, chc_my ^ 1); /* 車 */ + board[0][1] = board[0][7] = CHE(5, chc_my ^ 1); /* 馬 */ + board[2][1] = board[2][7] = CHE(6, chc_my ^ 1); /* 包 */ board[3][0] = board[3][2] = board[3][4] = - board[3][6] = board[3][8] = CHE(7, chc_my ^ 1); /* 卒 */ - - board[9][4] = CHE(1, chc_my); /* 帥 */ - board[9][3] = board[9][5] = CHE(2, chc_my); /* 仕 */ - board[9][2] = board[9][6] = CHE(3, chc_my); /* 相 */ - board[9][0] = board[9][8] = CHE(4, chc_my); /* 車 */ - board[9][1] = board[9][7] = CHE(5, chc_my); /* 傌 */ - board[7][1] = board[7][7] = CHE(6, chc_my); /* 炮 */ + board[3][6] = board[3][8] = CHE(7, chc_my ^ 1); /* 卒 */ + + board[9][4] = CHE(1, chc_my); /* 帥 */ + board[9][3] = board[9][5] = CHE(2, chc_my); /* 仕 */ + board[9][2] = board[9][6] = CHE(3, chc_my); /* 相 */ + board[9][0] = board[9][8] = CHE(4, chc_my); /* 車 */ + board[9][1] = board[9][7] = CHE(5, chc_my); /* 傌 */ + board[7][1] = board[7][7] = CHE(6, chc_my); /* 炮 */ board[6][0] = board[6][2] = board[6][4] = - board[6][6] = board[6][8] = CHE(7, chc_my); /* 兵 */ + board[6][6] = board[6][8] = CHE(7, chc_my); /* 兵 */ } -void chc_movechess(board_t board) { +void +chc_movechess(board_t board) +{ board[chc_to.r][chc_to.c] = board[chc_from.r][chc_from.c]; board[chc_from.r][chc_from.c] = 0; } -static int dist(rc_t from, rc_t to, int rowcol) { - int d; - +static int +dist(rc_t from, rc_t to, int rowcol) +{ + int d; + d = rowcol ? from.c - to.c : from.r - to.r; return d > 0 ? d : -d; } -static int between(board_t board, rc_t from, rc_t to, int rowcol) { - int i, rtv = 0; +static int +between(board_t board, rc_t from, rc_t to, int rowcol) +{ + int i, rtv = 0; - if(rowcol) { - if(from.c > to.c) + if (rowcol) { + if (from.c > to.c) i = from.c, from.c = to.c, to.c = i; - for(i = from.c + 1; i < to.c; i++) - if(board[to.r][i]) rtv++; + for (i = from.c + 1; i < to.c; i++) + if (board[to.r][i]) + rtv++; } else { - if(from.r > to.r) + if (from.r > to.r) i = from.r, from.r = to.r, to.r = i; - for(i = from.r + 1; i < to.r; i++) - if(board[i][to.c]) rtv++; + for (i = from.r + 1; i < to.r; i++) + if (board[i][to.c]) + rtv++; } return rtv; } -int chc_canmove(board_t board, rc_t from, rc_t to) { - int i; - int rd, cd, turn; +int +chc_canmove(board_t board, rc_t from, rc_t to) +{ + int i; + int rd, cd, turn; rd = dist(from, to, 0); cd = dist(from, to, 1); turn = CHE_O(board[from.r][from.c]); - + /* general check */ - if(board[to.r][to.c] && CHE_O(board[to.r][to.c]) == turn) + if (board[to.r][to.c] && CHE_O(board[to.r][to.c]) == turn) return 0; /* individual check */ - switch(CHE_P(board[from.r][from.c])) { - case 1: /* 將 帥 */ - if(!(rd == 1 && cd == 0) && - !(rd == 0 && cd == 1)) + switch (CHE_P(board[from.r][from.c])) { + case 1: /* 將 帥 */ + if (!(rd == 1 && cd == 0) && + !(rd == 0 && cd == 1)) return 0; - if((turn == (chc_my ^ 1) && to.r > 2) || - (turn == chc_my && to.r < 7) || + if ((turn == (chc_my ^ 1) && to.r > 2) || + (turn == chc_my && to.r < 7) || to.c < 3 || to.c > 5) - return 0; + return 0; break; - case 2: /* 士 仕 */ - if(!(rd == 1 && cd == 1)) + case 2: /* 士 仕 */ + if (!(rd == 1 && cd == 1)) return 0; - if((turn == (chc_my ^ 1) && to.r > 2) || - (turn == chc_my && to.r < 7) || + if ((turn == (chc_my ^ 1) && to.r > 2) || + (turn == chc_my && to.r < 7) || to.c < 3 || to.c > 5) - return 0; - break; - case 3: /* 象 相 */ - if(!(rd == 2 && cd == 2)) return 0; - if((turn == (chc_my ^ 1) && to.r > 4) || - (turn == chc_my && to.r < 5)) + break; + case 3: /* 象 相 */ + if (!(rd == 2 && cd == 2)) + return 0; + if ((turn == (chc_my ^ 1) && to.r > 4) || + (turn == chc_my && to.r < 5)) return 0; /* 拐象腿 */ - if(board[CENTER(from.r, to.r)][CENTER(from.c, to.c)]) + if (board[CENTER(from.r, to.r)][CENTER(from.c, to.c)]) return 0; break; - case 4: /* 車 */ - if(!(rd > 0 && cd == 0) && - !(rd == 0 && cd > 0)) + case 4: /* 車 */ + if (!(rd > 0 && cd == 0) && + !(rd == 0 && cd > 0)) return 0; - if(between(board, from, to, rd == 0)) + if (between(board, from, to, rd == 0)) return 0; break; - case 5: /* 馬 傌 */ - if(!(rd == 2 && cd == 1) && - !(rd == 1 && cd == 2)) + case 5: /* 馬 傌 */ + if (!(rd == 2 && cd == 1) && + !(rd == 1 && cd == 2)) return 0; /* 拐馬腳 */ - if(rd == 2) { - if(board[CENTER(from.r, to.r)][from.c]) + if (rd == 2) { + if (board[CENTER(from.r, to.r)][from.c]) return 0; } else { - if(board[from.r][CENTER(from.c, to.c)]) + if (board[from.r][CENTER(from.c, to.c)]) return 0; - } + } break; - case 6: /* 包 炮 */ - if(!(rd > 0 && cd == 0) && - !(rd == 0 && cd > 0)) + case 6: /* 包 炮 */ + if (!(rd > 0 && cd == 0) && + !(rd == 0 && cd > 0)) return 0; i = between(board, from, to, rd == 0); - if((i > 1) || - (i == 1 && !board[to.r][to.c]) || - (i == 0 && board[to.r][to.c])) - return 0; + if ((i > 1) || + (i == 1 && !board[to.r][to.c]) || + (i == 0 && board[to.r][to.c])) + return 0; break; - case 7: /* 卒 兵 */ - if(!(rd == 1 && cd == 0) && - !(rd == 0 && cd == 1)) + case 7: /* 卒 兵 */ + if (!(rd == 1 && cd == 0) && + !(rd == 0 && cd == 1)) return 0; - if(((turn == (chc_my ^ 1) && to.r < 5) || - (turn == chc_my && to.r > 4)) && + if (((turn == (chc_my ^ 1) && to.r < 5) || + (turn == chc_my && to.r > 4)) && cd != 0) return 0; - if((turn == (chc_my ^ 1) && to.r < from.r) || - (turn == chc_my && to.r > from.r)) + if ((turn == (chc_my ^ 1) && to.r < from.r) || + (turn == chc_my && to.r > from.r)) return 0; break; } return 1; } -static void findking(board_t board, int turn, rc_t *buf) { - int i, r, c; +static void +findking(board_t board, int turn, rc_t * buf) +{ + int i, r, c; r = (turn == (chc_my ^ 1)) ? 0 : 7; - for(i = 0; i < 3; r++, i++) - for(c = 3; c < 6; c++) - if(CHE_P(board[r][c]) == 1 && - CHE_O(board[r][c]) == turn) { + for (i = 0; i < 3; r++, i++) + for (c = 3; c < 6; c++) + if (CHE_P(board[r][c]) == 1 && + CHE_O(board[r][c]) == turn) { buf->r = r, buf->c = c; - return ; + return; } } -int chc_iskfk(board_t board) { - rc_t from, to; - +int +chc_iskfk(board_t board) +{ + rc_t from, to; + findking(board, 0, &to); findking(board, 1, &from); - if(from.c == to.c && between(board, from, to, 0) == 0) + if (from.c == to.c && between(board, from, to, 0) == 0) return 1; return 0; } -int chc_ischeck(board_t board, int turn) { - rc_t from, to; - +int +chc_ischeck(board_t board, int turn) +{ + rc_t from, to; + findking(board, turn, &to); - for(from.r = 0;from.r < BRD_ROW; from.r++) - for(from.c = 0; from.c < BRD_COL; from.c++) - if(board[from.r][from.c] && - CHE_O(board[from.r][from.c]) != turn) - if(chc_canmove(board, from, to)) + for (from.r = 0; from.r < BRD_ROW; from.r++) + for (from.c = 0; from.c < BRD_COL; from.c++) + if (board[from.r][from.c] && + CHE_O(board[from.r][from.c]) != turn) + if (chc_canmove(board, from, to)) return 1; return 0; } diff --git a/pttbbs/mbbsd/chicken.c b/pttbbs/mbbsd/chicken.c index 0b1c9320..6b43ee33 100644 --- a/pttbbs/mbbsd/chicken.c +++ b/pttbbs/mbbsd/chicken.c @@ -1,44 +1,44 @@ -/* $Id: chicken.c,v 1.5 2002/06/06 21:34:11 in2 Exp $ */ +/* $Id: chicken.c,v 1.6 2002/07/05 17:10:27 in2 Exp $ */ #include "bbs.h" -#define NUM_KINDS 13 /* 有多少種動物 */ +#define NUM_KINDS 13 /* 有多少種動物 */ -static const char *cage[17] = { +static const char *cage[17] = { "誕生", "週歲", "幼年", "少年", "青春", "青年", "青年", "活力", "壯年", "壯年", "壯年", "中年", - "中年", "老年", "老年", "老摳摳", "古希"}; -static const char *chicken_type[NUM_KINDS] = { +"中年", "老年", "老年", "老摳摳", "古希"}; +static const char *chicken_type[NUM_KINDS] = { "小雞", "美少女", "勇士", "蜘蛛", "恐龍", "老鷹", "貓", "蠟筆小新", "狗狗", "惡魔", "忍者", "ㄚ扁", - "馬英九"}; -static const char *chicken_food[NUM_KINDS] = { +"馬英九"}; +static const char *chicken_food[NUM_KINDS] = { "雞飼料", "營養厚片", "雞排便當", "死蝴蝶", "屍體", "小雞", "貓餅乾", "小熊餅乾", "寶錄", "靈氣", "飯團", "便當", - "雞腿"}; -static const int egg_price[NUM_KINDS] = { +"雞腿"}; +static const int egg_price[NUM_KINDS] = { 5, 25, 30, 40, 80, 50, 15, 35, 17, 100, 85, 200, - 200}; -static const int food_price[NUM_KINDS] = { +200}; +static const int food_price[NUM_KINDS] = { 4, 6, 8, 10, 12, 12, 5, 6, 5, 20, 15, 23, - 23}; -static const char *attack_type[NUM_KINDS] = { +23}; +static const char *attack_type[NUM_KINDS] = { "啄", "鞭打", "槌", "咬", "撞擊", "啄", "抓", "踢", - "咬","燃燒","暗擊","棍打", - "劍擊"}; + "咬", "燃燒", "暗擊", "棍打", +"劍擊"}; -static const char *damage_degree[] = { +static const char *damage_degree[] = { "蚊子似的", "騷癢似的", "小力的", "輕微的", "有點疼的", "使力的", "傷人的", "重重的", "使全力的", "惡狠狠的", "危險的", "瘋狂的", "猛烈的", "狂風暴雨似的", "驚天動地的", - "致命的", NULL}; +"致命的", NULL}; enum { OO, FOOD, WEIGHT, CLEAN, RUN, ATTACK, BOOK, HAPPY, SATIS, @@ -46,55 +46,60 @@ enum { }; static chicken_t *mychicken = &cuser.mychicken; -static int age; +static int age; -static const int time_change[NUM_KINDS][14] = -/* 補品 食物 體重 乾淨 敏捷 攻擊力 知識 快樂 滿意 氣質 疲勞 病氣 滿血 滿法*/ +static const int time_change[NUM_KINDS][14] = +/* 補品 食物 體重 乾淨 敏捷 攻擊力 知識 快樂 滿意 氣質 疲勞 病氣 滿血 滿法 */ { -/*雞*/ - { 1, 1, 30, 3, 8, 3, 3, 40, 9, 1, 7, 3, 30, 1}, -/*美少女*/ - { 1, 1, 110, 1, 4, 7, 41, 20, 9, 25, 25, 7, 110, 15}, -/*勇士*/ - { 1, 1, 200, 5, 4, 10, 33, 20, 15, 10, 27, 1, 200, 9}, -/*蜘蛛*/ - { 1, 1, 10, 5, 8, 1, 1, 5, 3, 1, 4, 1, 10, 30}, -/*恐龍*/ - { 1, 1,1000, 9, 1, 13, 4, 12, 3, 1, 200, 1, 1000, 3}, -/*老鷹*/ - { 1, 1, 90, 7, 10, 7, 4, 12, 3, 30, 20, 5, 90, 20}, -/*貓*/ - { 1, 1, 30, 5, 5, 6, 4, 8, 3, 15, 7, 4, 30, 21}, -/*蠟筆小新*/ - { 1, 1, 100, 9, 7, 7, 20, 50, 10, 8, 24, 4, 100, 9}, -/*狗*/ - { 1, 1, 45, 8, 7, 9, 3, 40, 20, 3, 9, 5, 45, 1}, -/* 惡魔 */ - { 1, 1, 45, 10, 11, 11, 5, 21, 11, 1, 9, 5, 45, 25}, -/* 忍者 */ - { 1, 1, 45, 2, 12, 10, 25, 1, 1, 10, 9, 5, 45, 26}, -/* 阿扁 */ - { 1, 1, 150, 4, 8, 13, 95, 25, 7, 10, 25, 5, 175, 85}, -/* 馬英九 */ - { 1, 1, 147, 2, 10, 10, 85, 20, 4, 25, 25, 5, 145, 95} + /* 雞 */ + {1, 1, 30, 3, 8, 3, 3, 40, 9, 1, 7, 3, 30, 1}, + /* 美少女 */ + {1, 1, 110, 1, 4, 7, 41, 20, 9, 25, 25, 7, 110, 15}, + /* 勇士 */ + {1, 1, 200, 5, 4, 10, 33, 20, 15, 10, 27, 1, 200, 9}, + /* 蜘蛛 */ + {1, 1, 10, 5, 8, 1, 1, 5, 3, 1, 4, 1, 10, 30}, + /* 恐龍 */ + {1, 1, 1000, 9, 1, 13, 4, 12, 3, 1, 200, 1, 1000, 3}, + /* 老鷹 */ + {1, 1, 90, 7, 10, 7, 4, 12, 3, 30, 20, 5, 90, 20}, + /* 貓 */ + {1, 1, 30, 5, 5, 6, 4, 8, 3, 15, 7, 4, 30, 21}, + /* 蠟筆小新 */ + {1, 1, 100, 9, 7, 7, 20, 50, 10, 8, 24, 4, 100, 9}, + /* 狗 */ + {1, 1, 45, 8, 7, 9, 3, 40, 20, 3, 9, 5, 45, 1}, + /* 惡魔 */ + {1, 1, 45, 10, 11, 11, 5, 21, 11, 1, 9, 5, 45, 25}, + /* 忍者 */ + {1, 1, 45, 2, 12, 10, 25, 1, 1, 10, 9, 5, 45, 26}, + /* 阿扁 */ + {1, 1, 150, 4, 8, 13, 95, 25, 7, 10, 25, 5, 175, 85}, + /* 馬英九 */ + {1, 1, 147, 2, 10, 10, 85, 20, 4, 25, 25, 5, 145, 95} }; -int reload_chicken() { +int +reload_chicken() +{ passwd_query(usernum, &xuser); memcpy(mychicken, &xuser.mychicken, sizeof(chicken_t)); - if(!mychicken->name[0]) + if (!mychicken->name[0]) return 0; - else return 1; + else + return 1; } #define CHICKENLOG "etc/chicken" -static int new_chicken() { - char buf[150]; - int price; - +static int +new_chicken() +{ + char buf[150]; + int price; + clear(); - move(2,0); + move(2, 0); outs("歡迎觀臨 \033[33m◎\033[37;44m Ptt寵物市場 \033[33;40m◎\033[m.. " "目前蛋價:\n" "(a)小雞 $5 (b)美少女 $25 (c)勇士 $30 (d)蜘蛛 $40 " @@ -106,65 +111,69 @@ static int new_chicken() { getdata_str(6, 0, "請選擇你要養的動物:", buf, 3, LCECHO, "0"); buf[0] -= 'a'; - if(buf[0]<0 || buf[0]>NUM_KINDS-1) + if (buf[0] < 0 || buf[0] > NUM_KINDS - 1) return 0; - + mychicken->type = buf[0]; - + reload_money(); price = egg_price[(int)mychicken->type]; - if(cuser.money < price) { + if (cuser.money < price) { prints("\n 錢不夠買蛋蛋,蛋蛋要 %d 元", price); refresh(); return 0; } - vice(price,"寵物蛋"); - while(strlen(mychicken->name)<3) + vice(price, "寵物蛋"); + while (strlen(mychicken->name) < 3) getdata(8, 0, "幫牠取個好名字:", mychicken->name, sizeof(mychicken->name), DOECHO); - sprintf(buf,"\033[31m%s \033[m養了一隻叫\033[33m %s \033[m的 " - "\033[32m%s\033[m 於 %s",cuser.userid, - mychicken->name,chicken_type[(int)mychicken->type],ctime(&now)); - log_file(CHICKENLOG,buf); + sprintf(buf, "\033[31m%s \033[m養了一隻叫\033[33m %s \033[m的 " + "\033[32m%s\033[m 於 %s", cuser.userid, + mychicken->name, chicken_type[(int)mychicken->type], ctime(&now)); + log_file(CHICKENLOG, buf); mychicken->lastvisit = mychicken->birthday = mychicken->cbirth = now; - mychicken->food = 0; - mychicken->weight = time_change[(int)mychicken->type][WEIGHT]/3; - mychicken->clean = 0; - mychicken->run = time_change[(int)mychicken->type][RUN]; + mychicken->food = 0; + mychicken->weight = time_change[(int)mychicken->type][WEIGHT] / 3; + mychicken->clean = 0; + mychicken->run = time_change[(int)mychicken->type][RUN]; mychicken->attack = time_change[(int)mychicken->type][ATTACK]; - mychicken->book = time_change[(int)mychicken->type][BOOK]; - mychicken->happy = time_change[(int)mychicken->type][HAPPY]; - mychicken->satis = time_change[(int)mychicken->type][SATIS]; + mychicken->book = time_change[(int)mychicken->type][BOOK]; + mychicken->happy = time_change[(int)mychicken->type][HAPPY]; + mychicken->satis = time_change[(int)mychicken->type][SATIS]; mychicken->temperament = time_change[(int)mychicken->type][TEMPERAMENT]; mychicken->tiredstrong = 0; - mychicken->sick = 0; - mychicken->hp = time_change[(int)mychicken->type][WEIGHT]; + mychicken->sick = 0; + mychicken->hp = time_change[(int)mychicken->type][WEIGHT]; mychicken->hp_max = time_change[(int)mychicken->type][WEIGHT]; - mychicken->mm = 0; - mychicken->mm_max = 0; + mychicken->mm = 0; + mychicken->mm_max = 0; return 1; } -int show_file(char *filename, int y, int lines, int mode) { - FILE *fp; - char buf[256]; - - if(y >= 0) - move(y,0); +int +show_file(char *filename, int y, int lines, int mode) +{ + FILE *fp; + char buf[256]; + + if (y >= 0) + move(y, 0); clrtoline(lines + y); - if((fp=fopen(filename,"r"))) { - while(fgets(buf,256,fp) && lines--) - outs(Ptt_prints(buf,mode)); + if ((fp = fopen(filename, "r"))) { + while (fgets(buf, 256, fp) && lines--) + outs(Ptt_prints(buf, mode)); fclose(fp); } else return 0; return 1; } -static void show_chicken_stat(chicken_t *thechicken) { - struct tm *ptime; - +static void +show_chicken_stat(chicken_t * thechicken) +{ + struct tm *ptime; + ptime = localtime(&thechicken->birthday); prints(" Name :\033[33m%s\033[m (\033[32m%s\033[m)%*s生日 " ":\033[31m%02d\033[m年\033[31m%2d\033[m月\033[31m%2d\033[m日 " @@ -178,92 +187,96 @@ static void show_chicken_stat(chicken_t *thechicken) { " 病氣 :\033[33m%-7d\033[m 乾淨 :\033[33m%-7d\033[m 食物 :" "\033[33m%-7d\033[m 大補丸:\033[33m%-7d\033[m 藥品 :\033[33m%-7d" "\033[m \n", - thechicken->name, chicken_type[(int)thechicken->type], + thechicken->name, chicken_type[(int)thechicken->type], 15 - strlen(thechicken->name), "", ptime->tm_year % 100, ptime->tm_mon + 1, ptime->tm_mday, - cage[age > 16 ? 16 : age], age, thechicken->hp, thechicken->hp_max, + cage[age > 16 ? 16 : age], age, thechicken->hp, thechicken->hp_max, thechicken->mm, thechicken->mm_max, thechicken->attack, thechicken->run, thechicken->book, thechicken->happy, thechicken->satis, thechicken->tiredstrong, thechicken->temperament, - ((float)(thechicken->hp_max+(thechicken->weight/50))) / 100, + ((float)(thechicken->hp_max + (thechicken->weight / 50))) / 100, thechicken->sick, thechicken->clean, thechicken->food, thechicken->oo, thechicken->medicine); } #define CHICKEN_PIC "etc/chickens" -void show_chicken_data(chicken_t *thechicken, chicken_t *pkchicken) { - char buf[1024]; - age = ((now - thechicken->cbirth)/ (60*60*24)); - if(age < 0) { - thechicken->birthday = thechicken->cbirth = now-10*(60*60*24); - age = 10; +void +show_chicken_data(chicken_t * thechicken, chicken_t * pkchicken) +{ + char buf[1024]; + age = ((now - thechicken->cbirth) / (60 * 60 * 24)); + if (age < 0) { + thechicken->birthday = thechicken->cbirth = now - 10 * (60 * 60 * 24); + age = 10; } - /*Ptt:debug*/ + /* Ptt:debug */ thechicken->type %= NUM_KINDS; clear(); showtitle(pkchicken ? "Ptt鬥雞場" : "Ptt養雞場", BBSName); - move(1,0); - + move(1, 0); + show_chicken_stat(thechicken); - + sprintf(buf, CHICKEN_PIC "/%c%d", thechicken->type + 'a', age > 16 ? 16 : age); show_file(buf, 5, 14, NO_RELOAD); - - move(18,0); - - if(thechicken->sick) + + move(18, 0); + + if (thechicken->sick) outs("生病了..."); - if(thechicken->sick > thechicken->hp / 5) + if (thechicken->sick > thechicken->hp / 5) outs("\033[5;31m擔心...病重!!\033[m"); - if(thechicken->clean > 150) + if (thechicken->clean > 150) outs("\033[31m又臭又髒的..\033[m"); - else if(thechicken->clean > 80) + else if (thechicken->clean > 80) outs("有點髒.."); - else if(thechicken->clean < 20) + else if (thechicken->clean < 20) outs("\033[32m很乾淨..\033[m"); - if(thechicken->weight > thechicken->hp_max*4) + if (thechicken->weight > thechicken->hp_max * 4) outs("\033[31m快飽死了!.\033[m"); - else if(thechicken->weight > thechicken->hp_max*3) + else if (thechicken->weight > thechicken->hp_max * 3) outs("\033[32m飽嘟嘟..\033[m"); - else if(thechicken->weight < (thechicken->hp_max / 4)) + else if (thechicken->weight < (thechicken->hp_max / 4)) outs("\033[31m快餓死了!..\033[m"); - else if(thechicken->weight < (thechicken->hp_max / 2)) + else if (thechicken->weight < (thechicken->hp_max / 2)) outs("餓了.."); - if(thechicken->tiredstrong > thechicken->hp * 1.7) + if (thechicken->tiredstrong > thechicken->hp * 1.7) outs("\033[31m累得昏迷了...\033[m"); - else if(thechicken->tiredstrong > thechicken->hp) + else if (thechicken->tiredstrong > thechicken->hp) outs("累了.."); - else if(thechicken->tiredstrong < thechicken->hp / 4) + else if (thechicken->tiredstrong < thechicken->hp / 4) outs("\033[32m精力旺盛...\033[m"); - if(thechicken->hp < thechicken->hp_max / 4) + if (thechicken->hp < thechicken->hp_max / 4) outs("\033[31m體力用盡..奄奄一息..\033[m"); - if(thechicken->happy > 500) + if (thechicken->happy > 500) outs("\033[32m很快樂..\033[m"); - else if(thechicken->happy < 100) + else if (thechicken->happy < 100) outs("不快樂.."); - if(thechicken->satis > 500) + if (thechicken->satis > 500) outs("\033[32m很滿足..\033[m"); - else if(thechicken->satis < 50) + else if (thechicken->satis < 50) outs("不滿足.."); - if(pkchicken) { + if (pkchicken) { outs("\n"); show_chicken_stat(pkchicken); outs("[任意鍵] 攻擊對方 [q] 落跑 [o] 吃大補丸"); } } -static void ch_eat() { - if(mychicken->food) { +static void +ch_eat() +{ + if (mychicken->food) { mychicken->weight += time_change[(int)mychicken->type][WEIGHT] + - mychicken->hp_max/5 ; + mychicken->hp_max / 5; mychicken->tiredstrong += time_change[(int)mychicken->type][TIREDSTRONG] / 2; mychicken->hp_max++; @@ -271,13 +284,15 @@ static void ch_eat() { mychicken->satis += 7; mychicken->food--; move(10, 10); - + show_file(CHICKEN_PIC "/eat", 5, 14, NO_RELOAD); pressanykey(); } } -static void ch_clean() { +static void +ch_clean() +{ mychicken->clean = 0; mychicken->tiredstrong += time_change[(int)mychicken->type][TIREDSTRONG] / 3; @@ -285,37 +300,43 @@ static void ch_clean() { pressanykey(); } -static void ch_guess() { - char *guess[3] = {"剪刀", "石頭", "布"}, me, ch, win; - - mychicken->happy += time_change[(int)mychicken->type][HAPPY]*1.5; +static void +ch_guess() +{ + char *guess[3] = {"剪刀", "石頭", "布"}, me, ch, win; + + mychicken->happy += time_change[(int)mychicken->type][HAPPY] * 1.5; mychicken->satis += time_change[(int)mychicken->type][SATIS]; mychicken->tiredstrong += time_change[(int)mychicken->type][TIREDSTRONG]; - mychicken->attack += time_change[(int)mychicken->type][ATTACK]/4; - move(20,0); + mychicken->attack += time_change[(int)mychicken->type][ATTACK] / 4; + move(20, 0); clrtobot(); outs("你要出[\033[32m1\033[m]\033[33m剪刀\033[m(\033[32m2\033[m)" "\033[33m石頭\033[m(\033[32m3\033[m)\033[33m布\033[m:\n"); me = igetch(); me -= '1'; - if(me > 2 || me < 0) + if (me > 2 || me < 0) me = 0; - win = (int)(3.0 * rand()/(RAND_MAX + 1.0)) - 1; - ch = (me + win + 3)%3; + win = (int)(3.0 * rand() / (RAND_MAX + 1.0)) - 1; + ch = (me + win + 3) % 3; prints("%s:%s ! %s:%s !.....%s", cuser.userid, guess[(int)me], mychicken->name, guess[(int)ch], - win==0 ? "平手" : win < 0 ? "耶..贏了 :D!!" : "嗚..我輸了 :~"); + win == 0 ? "平手" : win < 0 ? "耶..贏了 :D!!" : "嗚..我輸了 :~"); pressanykey(); } -static void ch_book() { +static void +ch_book() +{ mychicken->book += time_change[(int)mychicken->type][BOOK]; mychicken->tiredstrong += time_change[(int)mychicken->type][TIREDSTRONG]; show_file(CHICKEN_PIC "/read", 5, 14, NO_RELOAD); pressanykey(); } -static void ch_kiss() { +static void +ch_kiss() +{ mychicken->happy += time_change[(int)mychicken->type][HAPPY]; mychicken->satis += time_change[(int)mychicken->type][SATIS]; mychicken->tiredstrong += @@ -324,289 +345,307 @@ static void ch_kiss() { pressanykey(); } -static void ch_hit() { +static void +ch_hit() +{ mychicken->attack += time_change[(int)mychicken->type][ATTACK]; mychicken->run += time_change[(int)mychicken->type][RUN]; - mychicken->mm_max += time_change[(int)mychicken->type][MM_MAX]/15; - mychicken->weight -= mychicken->hp_max / 15 ; + mychicken->mm_max += time_change[(int)mychicken->type][MM_MAX] / 15; + mychicken->weight -= mychicken->hp_max / 15; mychicken->hp -= (int)((float)time_change[(int)mychicken->type][HP_MAX] * - rand()/(RAND_MAX+1.0)) / 2 + 1; - - if(mychicken->book > 2) + rand() / (RAND_MAX + 1.0)) / 2 + 1; + + if (mychicken->book > 2) mychicken->book -= 2; - if(mychicken->happy > 2) + if (mychicken->happy > 2) mychicken->happy -= 2; - if(mychicken->satis > 2) + if (mychicken->satis > 2) mychicken->satis -= 2; mychicken->tiredstrong += time_change[(int)mychicken->type][TIREDSTRONG]; show_file(CHICKEN_PIC "/hit", 5, 14, NO_RELOAD); pressanykey(); } -void ch_buyitem(int money, char *picture, int *item) { - int num = 0; - char buf[5]; - +void +ch_buyitem(int money, char *picture, int *item) +{ + int num = 0; + char buf[5]; + getdata_str(b_lines - 1, 0, "要買多少份呢:", buf, sizeof(buf), DOECHO, "1"); num = atoi(buf); - if(num < 1) + if (num < 1) return; reload_money(); - if(cuser.money > money*num) { + if (cuser.money > money * num) { *item += num; - vice(money*num,"購買寵物,賭盤項目"); + vice(money * num, "購買寵物,賭盤項目"); show_file(picture, 5, 14, NO_RELOAD); } else { - move(b_lines-1,0); + move(b_lines - 1, 0); clrtoeol(); outs("現金不夠 !!!"); } pressanykey(); } -static void ch_eatoo() { - if(mychicken->oo > 0) { +static void +ch_eatoo() +{ + if (mychicken->oo > 0) { mychicken->oo--; mychicken->tiredstrong = 0; - if(mychicken->happy > 5) + if (mychicken->happy > 5) mychicken->happy -= 5; show_file(CHICKEN_PIC "/oo", 5, 14, NO_RELOAD); pressanykey(); } } -static void ch_eatmedicine() { - if(mychicken->medicine > 0) { +static void +ch_eatmedicine() +{ + if (mychicken->medicine > 0) { mychicken->medicine--; mychicken->sick = 0; - if(mychicken->hp_max > 10) + if (mychicken->hp_max > 10) mychicken->hp_max -= 3; mychicken->hp = mychicken->hp_max; - if(mychicken->happy>10) + if (mychicken->happy > 10) mychicken->happy -= 10; show_file(CHICKEN_PIC "/medicine", 5, 14, NO_RELOAD); pressanykey(); } } -static void ch_kill() { - char buf[150],ans[4]; - +static void +ch_kill() +{ + char buf[150], ans[4]; + sprintf(buf, "棄養這%s要被罰 100 元, 是否要棄養?(y/N)", chicken_type[(int)mychicken->type]); getdata_str(23, 0, buf, ans, sizeof(ans), DOECHO, "N"); - if(ans[0] == 'y') { - - vice(100,"棄養寵物費"); - more(CHICKEN_PIC "/deadth",YEA); + if (ans[0] == 'y') { + + vice(100, "棄養寵物費"); + more(CHICKEN_PIC "/deadth", YEA); sprintf(buf, "\033[31m%s \033[m把 \033[33m%s\033[m\033[32m %s " "\033[m宰了 於 %s", cuser.userid, - mychicken->name, chicken_type[(int)mychicken->type], ctime(&now)); + mychicken->name, chicken_type[(int)mychicken->type], ctime(&now)); log_file(CHICKENLOG, buf); - mychicken->name[0]=0; + mychicken->name[0] = 0; } } -static int ch_sell() { -/* - int money = (mychicken->weight - time_change[(int)mychicken->type][WEIGHT]) - *(food_price[(int)mychicken->type])/4 + - ( - + ((mychicken->clean / time_change[(int)mychicken->type][CLEAN]) - + (mychicken->run / time_change[(int)mychicken->type][RUN]) - + (mychicken->attack / time_change[(int)mychicken->type][ATTACK]) - + (mychicken->book / time_change[(int)mychicken->type][BOOK]) - + (mychicken->happy / time_change[(int)mychicken->type][HAPPY]) - + (mychicken->satis / time_change[(int)mychicken->type][SATIS]) - + (mychicken->temperament / time_change[(int)mychicken->type][TEMPERAMENT]) - - (mychicken->tiredstrong / time_change[(int)mychicken->type][TIREDSTRONG]) - - (mychicken->sick / time_change[(int)mychicken->type][SICK]) - + (mychicken->hp / time_change[(int)mychicken->type][HP_MAX]) - + (mychicken->mm / time_change[(int)mychicken->type][MM_MAX]) - + 7 - abs(age - 7)) * 3 - ; -*/ - int money = (age * food_price[(int)mychicken->type] * 3 - + (mychicken->hp_max * 10 + mychicken->weight) / - time_change[(int)mychicken->type][HP_MAX]) * 3 / 2 - - mychicken->sick; - char buf[150],ans[4]; - - if(money < 0) - money =0 ; - else if(money > MAX_CHICKEN_MONEY) - money = MAX_CHICKEN_MONEY; //防止怪雞 - if(mychicken->type == 1 || mychicken->type == 7) { +static int +ch_sell() +{ + /* + * int money = (mychicken->weight - + * time_change[(int)mychicken->type][WEIGHT]) + * (food_price[(int)mychicken->type])/4 + ( + ((mychicken->clean / + * time_change[(int)mychicken->type][CLEAN]) + (mychicken->run / + * time_change[(int)mychicken->type][RUN]) + (mychicken->attack / + * time_change[(int)mychicken->type][ATTACK]) + (mychicken->book / + * time_change[(int)mychicken->type][BOOK]) + (mychicken->happy / + * time_change[(int)mychicken->type][HAPPY]) + (mychicken->satis / + * time_change[(int)mychicken->type][SATIS]) + (mychicken->temperament / + * time_change[(int)mychicken->type][TEMPERAMENT]) - + * (mychicken->tiredstrong / + * time_change[(int)mychicken->type][TIREDSTRONG]) - (mychicken->sick / + * time_change[(int)mychicken->type][SICK]) + (mychicken->hp / + * time_change[(int)mychicken->type][HP_MAX]) + (mychicken->mm / + * time_change[(int)mychicken->type][MM_MAX]) + 7 - abs(age - 7)) * 3 ; + */ + int money = (age * food_price[(int)mychicken->type] * 3 + + (mychicken->hp_max * 10 + mychicken->weight) / + time_change[(int)mychicken->type][HP_MAX]) * 3 / 2 - + mychicken->sick; + char buf[150], ans[4]; + + if (money < 0) + money = 0; + else if (money > MAX_CHICKEN_MONEY) + money = MAX_CHICKEN_MONEY; + //防止怪雞 + if (mychicken->type == 1 || mychicken->type == 7) { outs("\n\033[31m ㄜ..親愛的..販賣人口是會犯法的唷..\033[m"); pressanykey(); return 0; } - if(age < 5) { + if (age < 5) { outs("\n 還未成年不能賣"); pressanykey(); return 0; } - if(age > 30) { + if (age > 30) { outs("\n\033[31m 這..太老沒人要了\033[m"); pressanykey(); return 0; } - sprintf(buf, "這隻%d歲%s可以賣 %d 元, 是否要賣?(y/N)", age, chicken_type[(int)mychicken->type], money); getdata_str(23, 0, buf, ans, sizeof(ans), DOECHO, "N"); - if(ans[0]=='y') { + if (ans[0] == 'y') { sprintf(buf, "\033[31m%s\033[m 把 \033[33m%s\033[m " "\033[32m%s\033[m 用 \033[36m%d\033[m 賣了 於 %s", cuser.userid, mychicken->name, - chicken_type[(int)mychicken->type],money,ctime(&now)); + chicken_type[(int)mychicken->type], money, ctime(&now)); log_file(CHICKENLOG, buf); - mychicken->lastvisit = mychicken->name[0]=0; + mychicken->lastvisit = mychicken->name[0] = 0; passwd_update(usernum, &cuser); - more(CHICKEN_PIC "/sell",YEA); + more(CHICKEN_PIC "/sell", YEA); demoney(money); return 1; } return 0; } -static void geting_old(int *hp, int *weight, int diff, int age) { - float ex = 0.9; - - if(age > 70) +static void +geting_old(int *hp, int *weight, int diff, int age) +{ + float ex = 0.9; + + if (age > 70) ex = 0.1; - else if(age > 30) + else if (age > 30) ex = 0.5; - else if(age > 20) + else if (age > 20) ex = 0.7; - diff /= 60*6; - while(diff--) { + diff /= 60 * 6; + while (diff--) { *hp *= ex; *weight *= ex; } } /* 依時間變動的資料 */ -void time_diff(chicken_t *thechicken) { - int diff; - int theage = ((now - thechicken->cbirth)/ (60 * 60 * 24)); - - thechicken->type %= NUM_KINDS ; - diff = (now-thechicken->lastvisit)/60; - - if((diff) < 1) +void +time_diff(chicken_t * thechicken) +{ + int diff; + int theage = ((now - thechicken->cbirth) / (60 * 60 * 24)); + + thechicken->type %= NUM_KINDS; + diff = (now - thechicken->lastvisit) / 60; + + if ((diff) < 1) return; - if(theage > 13 ) /* 老死 */ + if (theage > 13) /* 老死 */ geting_old(&thechicken->hp_max, &thechicken->weight, diff, age); - + thechicken->lastvisit = now; - thechicken->weight -= thechicken->hp_max * diff / 540; /* 體重 */ - if(thechicken->weight < 1) { - thechicken->sick -= thechicken->weight / 10; /* 餓得病氣上升 */ - thechicken->weight =1; + thechicken->weight -= thechicken->hp_max * diff / 540; /* 體重 */ + if (thechicken->weight < 1) { + thechicken->sick -= thechicken->weight / 10; /* 餓得病氣上升 */ + thechicken->weight = 1; } - - /* 清潔度 */ + /* 清潔度 */ thechicken->clean += diff * time_change[(int)thechicken->type][CLEAN] / 30; - + /* 快樂度 */ thechicken->happy -= diff / 60; - if(thechicken->happy < 0) - thechicken->happy=0; + if (thechicken->happy < 0) + thechicken->happy = 0; thechicken->attack -= time_change[(int)thechicken->type][ATTACK] * diff / (60 * 32); - if(thechicken->attack < 0) + if (thechicken->attack < 0) thechicken->attack = 0; /* 攻擊力 */ thechicken->run -= time_change[(int)thechicken->type][RUN] * diff / (60 * 32); /* 敏捷 */ - if(thechicken->run < 0) + if (thechicken->run < 0) thechicken->run = 0; - thechicken->book -= time_change[(int)thechicken->type][BOOK]*diff/ (60*32); + thechicken->book -= time_change[(int)thechicken->type][BOOK] * diff / (60 * 32); /* 知識 */ - if(thechicken->book < 0) + if (thechicken->book < 0) thechicken->book = 0; /* 氣質 */ thechicken->temperament++; - + thechicken->satis -= diff / 60 / 3 * time_change[(int)thechicken->type][SATIS]; /* 滿意度 */ - if(thechicken->satis < 0) + if (thechicken->satis < 0) thechicken->satis = 0; /* 髒病的 */ - if(mychicken->clean > 1000) - mychicken->sick += (mychicken->clean - 400) / 10; + if (mychicken->clean > 1000) + mychicken->sick += (mychicken->clean - 400) / 10; - if(thechicken->weight > 1) + if (thechicken->weight > 1) thechicken->sick -= diff / 60; /* 病氣恢護 */ - if(thechicken->sick < 0) + if (thechicken->sick < 0) thechicken->sick = 0; thechicken->tiredstrong -= diff * time_change[(int)thechicken->type][TIREDSTRONG] / 4; /* 疲勞 */ - if(thechicken->tiredstrong < 0) + if (thechicken->tiredstrong < 0) thechicken->tiredstrong = 0; /* hp_max */ - if(thechicken->hp >= thechicken->hp_max/2) + if (thechicken->hp >= thechicken->hp_max / 2) thechicken->hp_max += - time_change[(int)thechicken->type][HP_MAX]*diff/ (60*12); + time_change[(int)thechicken->type][HP_MAX] * diff / (60 * 12); /* hp恢護 */ - if(!thechicken->sick) + if (!thechicken->sick) thechicken->hp += - time_change[(int)thechicken->type][HP_MAX]*diff/ (60*6); - if(thechicken->hp>thechicken->hp_max) + time_change[(int)thechicken->type][HP_MAX] * diff / (60 * 6); + if (thechicken->hp > thechicken->hp_max) thechicken->hp = thechicken->hp_max; /* mm_max */ - if(thechicken->mm >= thechicken->mm_max/2) + if (thechicken->mm >= thechicken->mm_max / 2) thechicken->mm_max += - time_change[(int)thechicken->type][MM_MAX]*diff/ (60*8); + time_change[(int)thechicken->type][MM_MAX] * diff / (60 * 8); /* mm恢護 */ - if(!thechicken->sick) + if (!thechicken->sick) thechicken->mm += diff; - if(thechicken->mm>thechicken->mm_max) + if (thechicken->mm > thechicken->mm_max) thechicken->mm = thechicken->mm_max; } -static void check_sick() { +static void +check_sick() +{ /* 髒病的 */ - if(mychicken->tiredstrong > mychicken->hp * 0.3 && mychicken->clean > 150) - mychicken->sick += (mychicken->clean - 150) / 10; + if (mychicken->tiredstrong > mychicken->hp * 0.3 && mychicken->clean > 150) + mychicken->sick += (mychicken->clean - 150) / 10; /* 累病的 */ - if(mychicken->tiredstrong > mychicken->hp*1.3) - mychicken->sick += time_change[(int)mychicken->type][SICK]; + if (mychicken->tiredstrong > mychicken->hp * 1.3) + mychicken->sick += time_change[(int)mychicken->type][SICK]; /* 病氣太重還做事減hp */ - if(mychicken->sick > mychicken->hp / 5) { - mychicken->hp -= (mychicken->sick - mychicken->hp / 5)/4; - if(mychicken->hp < 0 ) + if (mychicken->sick > mychicken->hp / 5) { + mychicken->hp -= (mychicken->sick - mychicken->hp / 5) / 4; + if (mychicken->hp < 0) mychicken->hp = 0; } } -static int deadtype(chicken_t *thechicken) { - int i; - char buf[150]; - - if(thechicken->hp <= 0) /* hp用盡 */ +static int +deadtype(chicken_t * thechicken) +{ + int i; + char buf[150]; + + if (thechicken->hp <= 0) /* hp用盡 */ i = 1; - else if(thechicken->tiredstrong > thechicken->hp * 3 ) /* 操勞過度 */ + else if (thechicken->tiredstrong > thechicken->hp * 3) /* 操勞過度 */ i = 2; - else if(thechicken->weight > thechicken->hp_max*5) /* 肥胖過度 */ + else if (thechicken->weight > thechicken->hp_max * 5) /* 肥胖過度 */ i = 3; - else if(thechicken->weight == 1 && - thechicken->sick > thechicken->hp_max / 4) - i = 4; /* 餓死了 */ - else if(thechicken->satis <= 0) /* 很不滿意 */ + else if (thechicken->weight == 1 && + thechicken->sick > thechicken->hp_max / 4) + i = 4; /* 餓死了 */ + else if (thechicken->satis <= 0) /* 很不滿意 */ i = 5; else return 0; - if(thechicken == mychicken) { - sprintf(buf,"\033[31m%s\033[m 所疼愛的\033[33m %s\033[32m %s " + if (thechicken == mychicken) { + sprintf(buf, "\033[31m%s\033[m 所疼愛的\033[33m %s\033[32m %s " "\033[m掛了 於 %s", cuser.userid, thechicken->name, chicken_type[(int)thechicken->type], @@ -614,23 +653,25 @@ static int deadtype(chicken_t *thechicken) { log_file(CHICKENLOG, buf); mychicken->name[0] = 0; passwd_update(usernum, &cuser); - } + } return i; } -int showdeadth(int type) { - switch(type) { - case 1: - more(CHICKEN_PIC "/nohp",YEA); +int +showdeadth(int type) +{ + switch (type) { + case 1: + more(CHICKEN_PIC "/nohp", YEA); break; case 2: - more(CHICKEN_PIC "/tootired",YEA); + more(CHICKEN_PIC "/tootired", YEA); break; case 3: - more(CHICKEN_PIC "/toofat",YEA); + more(CHICKEN_PIC "/toofat", YEA); break; case 4: - more(CHICKEN_PIC "/nofood",YEA); + more(CHICKEN_PIC "/nofood", YEA); break; case 5: more(CHICKEN_PIC "/nosatis", YEA); @@ -638,40 +679,46 @@ int showdeadth(int type) { default: return 0; } - more(CHICKEN_PIC "/deadth",YEA); + more(CHICKEN_PIC "/deadth", YEA); return type; } -int isdeadth(chicken_t *thechicken) { - int i; - - if(!(i = deadtype(thechicken))) +int +isdeadth(chicken_t * thechicken) +{ + int i; + + if (!(i = deadtype(thechicken))) return 0; return showdeadth(i); } -static void ch_changename() { - char buf[150], newname[20] = ""; - +static void +ch_changename() +{ + char buf[150], newname[20] = ""; + getdata_str(b_lines - 1, 0, "嗯..改個好名字吧:", newname, 18, DOECHO, - mychicken->name); - - if(strlen(newname) >= 3 && strcmp(newname,mychicken->name)) { + mychicken->name); + + if (strlen(newname) >= 3 && strcmp(newname, mychicken->name)) { sprintf(buf, "\033[31m%s\033[m 把疼愛的\033[33m %s\033[32m %s " "\033[m改名為\033[33m %s\033[m 於 %s", cuser.userid, mychicken->name, chicken_type[(int)mychicken->type], newname, ctime(&now)); strcpy(mychicken->name, newname); - log_file(CHICKENLOG,buf); + log_file(CHICKENLOG, buf); } } -static int select_menu() { - char ch; - +static int +select_menu() +{ + char ch; + reload_money(); - move(19,0); + move(19, 0); prints("\033[44;37m 錢 :\033[33m %-10d " " \033[m\n" "\033[33m(\033[37m1\033[33m)清理 (\033[37m2\033[33m)吃飯 " @@ -683,13 +730,15 @@ static int select_menu() { "(\033[37ms\033[33m)賣掉 (\033[37mn\033[33m)改名 " "(\033[37mq\033[33m)離開:\033[m", cuser.money, - /*chicken_food[(int)mychicken->type], - chicken_type[(int)mychicken->type], - chicken_type[(int)mychicken->type],*/ + /* + * chicken_food[(int)mychicken->type], + * chicken_type[(int)mychicken->type], + * chicken_type[(int)mychicken->type], + */ chicken_food[(int)mychicken->type], food_price[(int)mychicken->type]); do { - switch(ch = igetch()) { + switch (ch = igetch()) { case '1': ch_clean(); check_sick(); @@ -741,21 +790,23 @@ static int select_menu() { return 0; case 'S': case 's': - if(!ch_sell()) break; + if (!ch_sell()) + break; case 'Q': case 'q': return 0; - } - } while(ch < ' ' || ch>'z'); + } + } while (ch < ' ' || ch > 'z'); return 1; } -static int recover_chicken(chicken_t *thechicken) { - char buf[200]; - int price = egg_price[(int)thechicken->type], - money = price + (rand() % price); - - if(now - thechicken->lastvisit > (60 * 60 * 24 * 7)) +static int +recover_chicken(chicken_t * thechicken) +{ + char buf[200]; + int price = egg_price[(int)thechicken->type], money = price + (rand() % price); + + if (now - thechicken->lastvisit > (60 * 60 * 24 * 7)) return 0; outmsg("\033[33;44m★靈界守衛\033[37;45m 別害怕 我是來幫你的 \033[m"); bell(); @@ -765,31 +816,31 @@ static int recover_chicken(chicken_t *thechicken) { bell(); igetch(); sprintf(buf, "\033[33;44m★靈界守衛\033[37;45m " - "你有一個剛走不久的%s要招換回來嗎? 只要%d元唷 \033[m", - chicken_type[(int)thechicken->type], price*2); + "你有一個剛走不久的%s要招換回來嗎? 只要%d元唷 \033[m", + chicken_type[(int)thechicken->type], price * 2); outmsg(buf); bell(); getdata_str(21, 0, " 選擇:(N:坑人嘛/y:請幫幫我)", buf, 3, LCECHO, "N"); - if(buf[0] == 'y' || buf[0] == 'Y') { - reload_money(); - if(cuser.money < price*2) { + if (buf[0] == 'y' || buf[0] == 'Y') { + reload_money(); + if (cuser.money < price * 2) { outmsg("\033[33;44m★靈界守衛\033[37;45m 什麼 錢沒帶夠 " "沒錢的小鬼 快去籌錢吧 \033[m"); bell(); igetch(); return 0; - } - strcpy(thechicken->name, "[撿回來的]"); - thechicken->hp = thechicken->hp_max; - thechicken->sick = 0; - thechicken->satis = 2; - vice(money,"靈界守衛"); - sprintf(buf, "\033[33;44m★靈界守衛\033[37;45m OK了 記得餵他點東西 " + } + strcpy(thechicken->name, "[撿回來的]"); + thechicken->hp = thechicken->hp_max; + thechicken->sick = 0; + thechicken->satis = 2; + vice(money, "靈界守衛"); + sprintf(buf, "\033[33;44m★靈界守衛\033[37;45m OK了 記得餵他點東西 " "不然可能失效 念在我也有玩Ptt 拿你%d就好 \033[m", money); - outmsg(buf); - bell(); - igetch(); - return 1; + outmsg(buf); + bell(); + igetch(); + return 1; } outmsg("\033[33;44m★靈界守衛\033[37;45m 竟然說我坑人! 這年頭命真不值錢 " "除非我再來找你 你再也沒機會了 \033[m"); @@ -802,46 +853,50 @@ static int recover_chicken(chicken_t *thechicken) { #define lockreturn0(unmode, state) if(lockutmpmode(unmode, state)) return 0 -int chicken_main() { +int +chicken_main() +{ lockreturn0(CHICKEN, LOCK_MULTI); - + reload_chicken(); - age = ((now - mychicken->cbirth)/ (60*60*24)); - if(!mychicken->name[0] && !recover_chicken(mychicken) && !new_chicken()) { + age = ((now - mychicken->cbirth) / (60 * 60 * 24)); + if (!mychicken->name[0] && !recover_chicken(mychicken) && !new_chicken()) { unlockutmpmode(); return 0; } - do { time_diff(mychicken); - if(isdeadth(mychicken)) + if (isdeadth(mychicken)) break; show_chicken_data(mychicken, NULL); - } while(select_menu()); + } while (select_menu()); reload_money(); passwd_update(usernum, &cuser); unlockutmpmode(); return 0; } -int chickenpk(int fd) { - char mateid[IDLEN + 1], data[200], buf[200]; - int ch = 0; +int +chickenpk(int fd) +{ + char mateid[IDLEN + 1], data[200], buf[200]; + int ch = 0; - userinfo_t *uin = &SHM->uinfo[currutmp->destuip]; - userec_t ouser; - chicken_t *ochicken = &ouser.mychicken; - int r, attmax, i, datac, duid = currutmp->destuid, catched=0, count=0; + userinfo_t *uin = &SHM->uinfo[currutmp->destuip]; + userec_t ouser; + chicken_t *ochicken = &ouser.mychicken; + int r, attmax, i, datac, duid = currutmp->destuid, catched = 0, + count = 0; lockreturn0(CHICKEN, LOCK_MULTI); - - strcpy(mateid, currutmp->mateid); /*把對手的id用local buffer記住*/ - - getuser(mateid) ; + + strcpy(mateid, currutmp->mateid); /* 把對手的id用local buffer記住 */ + + getuser(mateid); memcpy(&ouser, &xuser, sizeof(userec_t)); reload_chicken(); - if(!ochicken->name[0] || !mychicken->name[0]) { - outmsg("有一方沒有寵物"); /* Ptt:妨止page時把寵物賣掉 */ + if (!ochicken->name[0] || !mychicken->name[0]) { + outmsg("有一方沒有寵物"); /* Ptt:妨止page時把寵物賣掉 */ bell(); refresh(); add_io(0, 0); @@ -850,114 +905,113 @@ int chickenpk(int fd) { sleep(1); return 0; } - show_chicken_data(ochicken, mychicken); - add_io(fd, 3); /* 把fd加到igetch監視 */ - while(1) { + add_io(fd, 3); /* 把fd加到igetch監視 */ + while (1) { r = rand(); ch = igetkey(); - getuser(mateid) ; + getuser(mateid); memcpy(&ouser, &xuser, sizeof(userec_t)); reload_chicken(); - show_chicken_data(ochicken, mychicken); + show_chicken_data(ochicken, mychicken); time_diff(mychicken); - - i = mychicken->attack* mychicken->hp / mychicken->hp_max; - for(attmax=2; (i = i*9/10); attmax++); - if(ch == I_OTHERDATA) { - count =0; + i = mychicken->attack * mychicken->hp / mychicken->hp_max; + for (attmax = 2; (i = i * 9 / 10); attmax++); + + if (ch == I_OTHERDATA) { + count = 0; datac = recv(fd, data, sizeof(data), 0); - if(datac <= 1) + if (datac <= 1) break; - move(17,0); - outs(data+1); - switch(data[0]) { + move(17, 0); + outs(data + 1); + switch (data[0]) { case 'c': - catched=1; - move(16,0); + catched = 1; + move(16, 0); outs("要放他走嗎?(y/N)"); break; case 'd': - move(16,0); + move(16, 0); outs("阿~倒下了!!"); break; } - if(data[0] == 'd' || data[0]=='q' || data[0]=='l') + if (data[0] == 'd' || data[0] == 'q' || data[0] == 'l') break; continue; - } else if(currutmp->turn) { + } else if (currutmp->turn) { count = 0; currutmp->turn = 0; uin->turn = 1; - mychicken->tiredstrong ++; - switch(ch) { + mychicken->tiredstrong++; + switch (ch) { case 'y': - if(catched == 1) { + if (catched == 1) { sprintf(data, "l讓 %s 落跑了\n", ochicken->name); } - break; + break; case 'n': - catched =0; + catched = 0; default: case 'k': - r = r % (attmax + 2); - if(r) { + r = r % (attmax + 2); + if (r) { sprintf(data, "M%s %s%s %s 傷了 %d 點\n", mychicken->name, - damage_degree[r/3>15 ? 15:r/3], + damage_degree[r / 3 > 15 ? 15 : r / 3], attack_type[(int)mychicken->type], ochicken->name, r); - ochicken->hp-=r; + ochicken->hp -= r; } else sprintf(data, "M%s 覺得手軟出擊無效\n", mychicken->name); - break; + break; case 'o': - if(mychicken->oo > 0) { + if (mychicken->oo > 0) { mychicken->oo--; mychicken->hp += 300; - if(mychicken->hp > mychicken->hp_max) - mychicken->hp = mychicken->hp_max; + if (mychicken->hp > mychicken->hp_max) + mychicken->hp = mychicken->hp_max; mychicken->tiredstrong = 0; sprintf(data, "M%s 吃了顆大補丸補充體力\n", mychicken->name); - } else + } else sprintf(data, "M%s 想吃大補丸, 可是沒有大補丸可吃\n", mychicken->name); - break; + break; case 'q': - if(r % (mychicken->run+1) > r % (ochicken->run+1)) + if (r % (mychicken->run + 1) > r % (ochicken->run + 1)) sprintf(data, "q%s 落跑了\n", mychicken->name); - else + else sprintf(data, "c%s 想落跑, 但被 %s 抓到了\n", mychicken->name, ochicken->name); - break; + break; } - if(deadtype(ochicken)) { - strtok(data,"\n"); + if (deadtype(ochicken)) { + strtok(data, "\n"); strcpy(buf, data); - sprintf(data, "d%s , %s 被 %s 打死了\n", - buf + 1, ochicken->name, mychicken->name); + sprintf(data, "d%s , %s 被 %s 打死了\n", + buf + 1, ochicken->name, mychicken->name); } - move(17,0); - outs(data+1); - i = strlen(data) +1; + move(17, 0); + outs(data + 1); + i = strlen(data) + 1; passwd_update(duid, &ouser); passwd_update(usernum, &cuser); - send(fd, data, i, 0); - if(data[0]=='q' || data[0]=='d') + send(fd, data, i, 0); + if (data[0] == 'q' || data[0] == 'd') break; } else { move(17, 0); - if(count++ > 30) + if (count++ > 30) break; } } - add_io(0, 0); /* 把igetch恢護回 */ + add_io(0, 0); /* 把igetch恢護回 */ pressanykey(); close(fd); - if(!showdeadth(deadtype(mychicken))); + if (!showdeadth(deadtype(mychicken))); unlockutmpmode(); return 0; } diff --git a/pttbbs/mbbsd/dark.c b/pttbbs/mbbsd/dark.c index 9cf99aab..19e17444 100644 --- a/pttbbs/mbbsd/dark.c +++ b/pttbbs/mbbsd/dark.c @@ -1,4 +1,4 @@ -/* $Id: dark.c,v 1.4 2002/06/04 13:08:33 in2 Exp $ */ +/* $Id: dark.c,v 1.5 2002/07/05 17:10:27 in2 Exp $ */ #include "bbs.h" #define RED 1 @@ -6,439 +6,550 @@ typedef short int sint; typedef struct item { - short int color,value,die,out; -} item; + short int color, value, die, out; +} item; -typedef struct cur{ - short int y,x,end; -} cur; +typedef struct cur { + short int y, x, end; +} cur; -static item brd[4][8]; -static cur curr; /* 6 個 bytes */ +static item brd[4][8]; +static cur curr; /* 6 個 bytes */ -static char *rname[]={"兵","炮","傌","車","相","仕","帥"}; -static char *bname[]={"卒","包","馬","車","象","士","將"}; +static char *rname[] = {"兵", "炮", "傌", "車", "相", "仕", "帥"}; +static char *bname[] = {"卒", "包", "馬", "車", "象", "士", "將"}; -static sint cury[]={3,5,7,9}, curx[]={5,9,13,17,21,25,29,33}; -static sint rcount,bcount,cont,fix; /* cont:是否可連吃 */ -static sint my=0,mx=0,mly=-1,mlx=-1; /* 移動的座標 跟 選子的座標 */ +static sint cury[] = {3, 5, 7, 9}, curx[] = {5, 9, 13, 17, 21, 25, 29, 33}; +static sint rcount, bcount, cont, fix; /* cont:是否可連吃 */ +static sint my = 0, mx = 0, mly = -1, mlx = -1; /* 移動的座標 + * 標 */ -static sint cur_eaty,cur_eatx; /* 吃掉對方其子的秀出座標 */ -static void brdswap(sint y,sint x,sint ly,sint lx) { - memcpy(&brd[y][x],&brd[ly][lx],sizeof(item)); - brd[ly][lx].die=1; - brd[ly][lx].color=-1; /* 沒這個color */ - brd[ly][lx].value=-1; +static sint cur_eaty, cur_eatx; /* 吃掉對方其子的秀出座標 */ +static void +brdswap(sint y, sint x, sint ly, sint lx) +{ + memcpy(&brd[y][x], &brd[ly][lx], sizeof(item)); + brd[ly][lx].die = 1; + brd[ly][lx].color = -1; /* 沒這個color */ + brd[ly][lx].value = -1; } -static void pprints(sint y,sint x,char* s) { - move(y,x); +static void +pprints(sint y, sint x, char *s) +{ + move(y, x); clrtoeol(); - prints("%s",s); + prints("%s", s); } -static sint Is_win(item att, item det, sint y, sint x, sint ly, sint lx) { - sint i,c=0,min,max; - if(att.value == 1) /* 砲 */ - { - if(y!=ly && x!=lx) return 0; - if((abs(ly-y)==1 && brd[y][x].die==0)|| - (abs(lx-x)==1 && brd[y][x].die==0)) +static sint +Is_win(item att, item det, sint y, sint x, sint ly, sint lx) +{ + sint i, c = 0, min, max; + if (att.value == 1) { /* 砲 */ + if (y != ly && x != lx) return 0; - if(y==ly){ - if(x>lx) {max=x;min=lx;} - else {max=lx;min=x;} - for(i=min+1;i<max;i++) - if(brd[y][i].die==0) c++; - }else if(x==lx){ - if(y>ly) {max=y;min=ly;} - else {max=ly;min=y;} - for(i=min+1;i<max;i++) - if(brd[i][x].die==0) c++; + if ((abs(ly - y) == 1 && brd[y][x].die == 0) || + (abs(lx - x) == 1 && brd[y][x].die == 0)) + return 0; + if (y == ly) { + if (x > lx) { + max = x; + min = lx; + } else { + max = lx; + min = x; + } + for (i = min + 1; i < max; i++) + if (brd[y][i].die == 0) + c++; + } else if (x == lx) { + if (y > ly) { + max = y; + min = ly; + } else { + max = ly; + min = y; + } + for (i = min + 1; i < max; i++) + if (brd[i][x].die == 0) + c++; } - if(c != 1) return 0; - if(det.die == 1) return 0; + if (c != 1) + return 0; + if (det.die == 1) + return 0; return 1; } /* 非砲 */ - if( ((abs(ly-y)==1&&x==lx) || (abs(lx-x)==1&&ly==y)) && brd[y][x].out==1 ) - { - if(att.value == 0 && det.value == 6) return 1; - else if(att.value == 6 && det.value == 0) return 0; - else if(att.value >= det.value) return 1; - else return 0; + if (((abs(ly - y) == 1 && x == lx) || (abs(lx - x) == 1 && ly == y)) && brd[y][x].out == 1) { + if (att.value == 0 && det.value == 6) + return 1; + else if (att.value == 6 && det.value == 0) + return 0; + else if (att.value >= det.value) + return 1; + else + return 0; } return 0; } -static sint Is_move(sint y,sint x, sint ly, sint lx) { - if(brd[y][x].die==1 && ((abs(ly-y)==1&&x==lx) || (abs(lx-x)==1&&ly==y))) +static sint +Is_move(sint y, sint x, sint ly, sint lx) +{ + if (brd[y][x].die == 1 && ((abs(ly - y) == 1 && x == lx) || (abs(lx - x) == 1 && ly == y))) return 1; return 0; } -static void brd_rand() { - sint y,x,index; - sint tem[32]; - sint value[32]={0,0,0,0,0,1,1,2,2,3,3,4,4,5,5,6, - 0,0,0,0,0,1,1,2,2,3,3,4,4,5,5,6}; +static void +brd_rand() +{ + sint y, x, index; + sint tem[32]; + sint value[32] = {0, 0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, + 0, 0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6}; bzero(brd, sizeof(brd)); bzero(tem, sizeof(tem)); bzero(&curr, sizeof(curr)); - srand(getpid()%2731+now%3219); - for(y=0;y<4;y++) - for(x=0;x<8;x++) - while(1) { - index=rand()%32; - if(tem[index]) continue; - brd[y][x].color=(index>15)?0:1; - brd[y][x].value=value[index]; - tem[index]=1; + srand(getpid() % 2731 + now % 3219); + for (y = 0; y < 4; y++) + for (x = 0; x < 8; x++) + while (1) { + index = rand() % 32; + if (tem[index]) + continue; + brd[y][x].color = (index > 15) ? 0 : 1; + brd[y][x].value = value[index]; + tem[index] = 1; break; } } -static void brd_prints() { +static void +brd_prints() +{ clear(); - move(1,0); + move(1, 0); outs("\n" -" ╭─┬─┬─┬─┬─┬─┬─┬─╮\n" -" │●│●│●│●│●│●│●│●│\n" -" ├─┼─┼─┼─┼─┼─┼─┼─┤\n" -" │●│●│●│●│●│●│●│●│\n" -" ├─┼─┼─┼─┼─┼─┼─┼─┤\n" -" │●│●│●│●│●│●│●│●│\n" -" ├─┼─┼─┼─┼─┼─┼─┼─┤\n" -" │●│●│●│●│●│●│●│●│\n" -" ╰─┴─┴─┴─┴─┴─┴─┴─╯\n" -" "); + " ╭─┬─┬─┬─┬─┬─┬─┬─╮\n" + " │●│●│●│●│●│●│●│●│\n" + " ├─┼─┼─┼─┼─┼─┼─┼─┤\n" + " │●│●│●│●│●│●│●│●│\n" + " ├─┼─┼─┼─┼─┼─┼─┼─┤\n" + " │●│●│●│●│●│●│●│●│\n" + " ├─┼─┼─┼─┼─┼─┼─┼─┤\n" + " │●│●│●│●│●│●│●│●│\n" + " ╰─┴─┴─┴─┴─┴─┴─┴─╯\n" + " "); } -static void draw_line(sint y, sint f) { - sint i; - char buf[1024],tmp[256]; +static void +draw_line(sint y, sint f) +{ + sint i; + char buf[1024], tmp[256]; *buf = 0; *tmp = 0; - strcpy(buf,"\033[43;30m"); - for(i=0; i<8; i++) - { - if(brd[y][i].die==1) - sprintf(tmp,"│ "); - else if(brd[y][i].out==0) - sprintf(tmp,"│●"); + strcpy(buf, "\033[43;30m"); + for (i = 0; i < 8; i++) { + if (brd[y][i].die == 1) + sprintf(tmp, "│ "); + else if (brd[y][i].out == 0) + sprintf(tmp, "│●"); else { sprintf(tmp, "│\033[%s1;%dm%s\033[m\033[43;30m", - (f==i)?"1;47;":"",(brd[y][i].color)?31:34, - (brd[y][i].color)?rname[brd[y][i].value]: + (f == i) ? "1;47;" : "", (brd[y][i].color) ? 31 : 34, + (brd[y][i].color) ? rname[brd[y][i].value] : bname[brd[y][i].value]); } - strcat(buf,tmp); + strcat(buf, tmp); } - strcat(buf,"│\033[m"); + strcat(buf, "│\033[m"); - move(cury[y],3); + move(cury[y], 3); clrtoeol(); - prints("%s",buf); + prints("%s", buf); } -static void redraw() { - sint i=0; - for(;i<4;i++) - draw_line(i,-1); +static void +redraw() +{ + sint i = 0; + for (; i < 4; i++) + draw_line(i, -1); } -static sint playing(sint fd, sint color,sint ch,sint *b, userinfo_t *uin) { +static sint +playing(sint fd, sint color, sint ch, sint * b, userinfo_t * uin) +{ curr.end = 0; - move(cury[my],curx[mx]); + move(cury[my], curx[mx]); - if(fix) { - if(ch=='s') { - fix=0; *b=0; return 0; + if (fix) { + if (ch == 's') { + fix = 0; + *b = 0; + return 0; } else { - draw_line(mly,-1); + draw_line(mly, -1); } } - - switch(ch) { + switch (ch) { case KEY_LEFT: - if(mx == 0) mx=7; - else mx--; - move(cury[my],curx[mx]); - *b=-1; + if (mx == 0) + mx = 7; + else + mx--; + move(cury[my], curx[mx]); + *b = -1; break; case KEY_RIGHT: - if(mx==7) mx=0; - else mx++; - move(cury[my],curx[mx]); - *b=-1; + if (mx == 7) + mx = 0; + else + mx++; + move(cury[my], curx[mx]); + *b = -1; break; case KEY_UP: - if(my==0) my=3; - else my--; - move(cury[my],curx[mx]); - *b=-1; + if (my == 0) + my = 3; + else + my--; + move(cury[my], curx[mx]); + *b = -1; break; case KEY_DOWN: - if(my==3) my=0; - else my++; - move(cury[my],curx[mx]); - *b=-1; + if (my == 3) + my = 0; + else + my++; + move(cury[my], curx[mx]); + *b = -1; break; - case 'q':case 'Q': - if(!color) bcount=0; - else rcount=0; - *b=0; + case 'q': + case 'Q': + if (!color) + bcount = 0; + else + rcount = 0; + *b = 0; return -2; - case 'p':case 'P': + case 'p': + case 'P': return -3; case 'c': return -4; case 'g': return -5; - case 's': /* 翻開棋子 或是選擇棋子 */ + case 's': /* 翻開棋子 或是選擇棋子 */ /* 選擇棋子 */ - if(brd[my][mx].out==1) - { - if(brd[my][mx].color != color) - { - *b=-1; + if (brd[my][mx].out == 1) { + if (brd[my][mx].color != color) { + *b = -1; break; } - if(mly<0) /*可以選擇*/ - { - mly=my;mlx=mx; - draw_line(my,mx); - *b=-1; + if (mly < 0) { /* 可以選擇 */ + mly = my; + mlx = mx; + draw_line(my, mx); + *b = -1; break; + } else if (mly == my && mlx == mx) { /* 不選了 */ + mly = -1; + mlx = -1; + draw_line(my, -1); + } else { + draw_line(mly, -1); + mly = my; + mlx = mx; + if (brd[mly][mlx].value == 1) + fix = 1; + draw_line(my, mx); } - else if(mly == my && mlx == mx) /*不選了*/ - { - mly=-1;mlx=-1; - draw_line(my,-1); - }else - { - draw_line(mly,-1); - mly=my;mlx=mx; - if(brd[mly][mlx].value == 1) fix=1; - draw_line(my,mx); - } - *b=-1; + *b = -1; break; } /* 翻開棋子 */ - if(mly >=0 ){ *b=-1; break;} /*本來就是翻開的*/ + if (mly >= 0) { + *b = -1; + break; + } /* 本來就是翻開的 */ /* 決定一開始的顏色 */ - if(currutmp->color=='.'){ - if(uin->color!='1' && uin->color!='0') - currutmp->color=(brd[my][mx].color)?'1':'0'; + if (currutmp->color == '.') { + if (uin->color != '1' && uin->color != '0') + currutmp->color = (brd[my][mx].color) ? '1' : '0'; else - currutmp->color=(uin->color=='0')?'1':'0';} - brd[my][mx].out=1; - draw_line(my,-1); - move(cury[my],curx[mx]); - *b=0; + currutmp->color = (uin->color == '0') ? '1' : '0'; + } + brd[my][mx].out = 1; + draw_line(my, -1); + move(cury[my], curx[mx]); + *b = 0; break; case 'u': - move(0,0);clrtoeol(); - prints("%s色%s cont=%d",(brd[my][mx].color == RED)?"紅":"黑",rname[brd[my][mx].value],cont); - *b=-1; + move(0, 0); + clrtoeol(); + prints("%s色%s cont=%d", (brd[my][mx].color == RED) ? "紅" : "黑", rname[brd[my][mx].value], cont); + *b = -1; break; - case '\r': /* 吃 or 移動 ly跟lx必須大於0*/ + case '\r': /* 吃 or 移動 ly跟lx必須大於0 */ case '\n': - if( - mly >= 0 /* 要先選子 */ + if ( + mly >= 0 /* 要先選子 */ && - brd[mly][mlx].color != brd[my][mx].color /* 同色不能移動也不能吃 */ + brd[mly][mlx].color != brd[my][mx].color /* 同色不能移動也不能吃 */ && - (Is_move(my,mx,mly,mlx) || Is_win(brd[mly][mlx],brd[my][mx],my,mx,mly,mlx)) - ) - { - if(fix && brd[my][mx].value<0) - { - *b=-1;return 0; + (Is_move(my, mx, mly, mlx) || Is_win(brd[mly][mlx], brd[my][mx], my, mx, mly, mlx)) + ) { + if (fix && brd[my][mx].value < 0) { + *b = -1; + return 0; } - if(brd[my][mx].value>=0&&brd[my][mx].die==0) - { - if(!color) bcount--; - else rcount--; - move(cur_eaty,cur_eatx); - prints("%s",(color)?bname[brd[my][mx].value]:rname[brd[my][mx].value]); - if(cur_eatx>=26) - { cur_eatx=5;cur_eaty++; } + if (brd[my][mx].value >= 0 && brd[my][mx].die == 0) { + if (!color) + bcount--; else - cur_eatx+=3; + rcount--; + move(cur_eaty, cur_eatx); + prints("%s", (color) ? bname[brd[my][mx].value] : rname[brd[my][mx].value]); + if (cur_eatx >= 26) { + cur_eatx = 5; + cur_eaty++; + } else + cur_eatx += 3; } - brdswap(my,mx,mly,mlx); - draw_line(mly,-1); - draw_line( my,-1); - if(fix==1) *b=-1; - else { mly=-1;mlx=-1;*b=0; } - } - else *b=-1; + brdswap(my, mx, mly, mlx); + draw_line(mly, -1); + draw_line(my, -1); + if (fix == 1) + *b = -1; + else { + mly = -1; + mlx = -1; + *b = 0; + } + } else + *b = -1; break; default: - *b=-1; + *b = -1; } - - if(!rcount) + + if (!rcount) return -1; - else if(!bcount) + else if (!bcount) return -1; - if(*b == -1) return 0; - curr.y = my;curr.x = mx; curr.end=(!*b)?1:0; - send(fd,&curr,sizeof(curr),0); - send(fd,&brd,sizeof(brd),0); + if (*b == -1) + return 0; + curr.y = my; + curr.x = mx; + curr.end = (!*b) ? 1 : 0; + send(fd, &curr, sizeof(curr), 0); + send(fd, &brd, sizeof(brd), 0); return 0; } -int main_dark(int fd,userinfo_t *uin) { - sint end=0,ch=1,go_on,i=0,cont=0; - char buf[16]; - *buf=0;fix=0; - currutmp->color='.'; // '.' 表示還沒決定顏色 - rcount=16;bcount=16; // initialize - cur_eaty=18,cur_eatx=5; +int +main_dark(int fd, userinfo_t * uin) +{ + sint end = 0, ch = 1, go_on, i = 0, cont = 0; + char buf[16]; + *buf = 0; + fix = 0; + currutmp->color = '.'; + //'.' 磳僋晲S M w C + rcount = 16; + bcount = 16; + //initialize + cur_eaty = 18, cur_eatx = 5; brd_prints(); - if(currutmp->turn) - { + if (currutmp->turn) { brd_rand(); - send(fd,&brd,sizeof(brd),0); - pprints(21,0," ◆你是先手"); - pprints(22,0," ◆輪到你下了"); - }else - { - recv(fd,&brd,sizeof(brd),0); - pprints(21,0," ◆你是後手"); + send(fd, &brd, sizeof(brd), 0); + pprints(21, 0, " ◆你是先手"); + pprints(22, 0, " ◆輪到你下了"); + } else { + recv(fd, &brd, sizeof(brd), 0); + pprints(21, 0, " ◆你是後手"); } - move(12,3); - prints("%s[0勝0敗]vs.%s[0勝0敗]",currutmp->userid,currutmp->mateid); + move(12, 3); + prints("%s[0勝0敗]vs.%s[0勝0敗]", currutmp->userid, currutmp->mateid); outs("\n" -" ╳╱功\能表╲╳╲╱╳╲\n" -" ╱ ↑←↓→: 移動\n" -" ╳ s:  選子,翻子\n" -" ╱ enter:  吃棋,放棋\n" -" 已經解決的:   ╳ p:  合棋\n" -"    ╱ q:  認輸\n" -" ╳ c:  換邊"); + " ╳╱功\能表╲╳╲╱╳╲\n" + " ╱ ↑←↓→: 移動\n" + " ╳ s:  選子,翻子\n" + " ╱ enter:  吃棋,放棋\n" + " 已經解決的:   ╳ p:  合棋\n" + "    ╱ q:  認輸\n" + " ╳ c:  換邊"); - if(currutmp->turn) move(cury[0],curx[0]); + if (currutmp->turn) + move(cury[0], curx[0]); add_io(fd, 0); - while(end<=0) - { - if(uin->turn=='w' || currutmp->turn=='w') { end=-1; break; } - + while (end <= 0) { + if (uin->turn == 'w' || currutmp->turn == 'w') { + end = -1; + break; + } ch = igetkey(); - if(ch == I_OTHERDATA) - { - ch=recv(fd,&curr,sizeof(curr),0); - if(ch!=sizeof(curr)) - { - if(uin->turn=='e') { end=-3;break; } - else if(uin->turn!='w') { end=-1; currutmp->turn='w'; break; } - end=-1; break; + if (ch == I_OTHERDATA) { + ch = recv(fd, &curr, sizeof(curr), 0); + if (ch != sizeof(curr)) { + if (uin->turn == 'e') { + end = -3; + break; + } else if (uin->turn != 'w') { + end = -1; + currutmp->turn = 'w'; + break; + } + end = -1; + break; } + if (curr.end == -3) + pprints(23, 30, "\033[33m要求合棋\033[m"); + else if (curr.end == -4) + pprints(23, 30, "\033[33m要求換邊\033[m"); + else if (curr.end == -5) + pprints(23, 30, "\033[33m要求連吃\033[m"); + else + pprints(23, 30, ""); - if(curr.end==-3) pprints(23,30,"\033[33m要求合棋\033[m"); - else if(curr.end==-4) pprints(23,30,"\033[33m要求換邊\033[m"); - else if(curr.end==-5) pprints(23,30,"\033[33m要求連吃\033[m"); - else pprints(23,30,""); - - recv(fd,&brd,sizeof(brd),0); - my=curr.y;mx=curr.x; + recv(fd, &brd, sizeof(brd), 0); + my = curr.y; + mx = curr.x; redraw(); - if(curr.end) - pprints(22,0," ◆輪到你下了"); - move(cury[my],curx[mx]); - }else - { - if(currutmp->turn=='p') - { - if(ch=='y') { end=-3; currutmp->turn='e'; break; } - else { pprints(23,30,""); *buf=0; currutmp->turn=(uin->turn)?0:1; } - }else if(currutmp->turn=='c') - { - if(ch=='y') { currutmp->color=(currutmp->color=='1')?'0':'1'; - uin->color=(uin->color=='1')?'0':'1'; - pprints(21,0,(currutmp->color=='1')?" \033[1;33m◆你持紅色棋\033[m":" \033[1;33m◆你持黑色棋\033[m"); + if (curr.end) + pprints(22, 0, " ◆輪到你下了"); + move(cury[my], curx[mx]); + } else { + if (currutmp->turn == 'p') { + if (ch == 'y') { + end = -3; + currutmp->turn = 'e'; + break; + } else { + pprints(23, 30, ""); + *buf = 0; + currutmp->turn = (uin->turn) ? 0 : 1; } - else { pprints(23,30,""); currutmp->turn=(uin->turn)?0:1; } - }else if(currutmp->turn=='g') - { - if(ch=='y') { - cont=1; - pprints(21,0," \033[1;33m◆你持紅色棋\033[m 可連吃"); + } else if (currutmp->turn == 'c') { + if (ch == 'y') { + currutmp->color = (currutmp->color == '1') ? '0' : '1'; + uin->color = (uin->color == '1') ? '0' : '1'; + pprints(21, 0, (currutmp->color == '1') ? " \033[1;33m◆你持紅色棋\033[m" : " \033[1;33m◆你持黑色棋\033[m"); + } else { + pprints(23, 30, ""); + currutmp->turn = (uin->turn) ? 0 : 1; + } + } else if (currutmp->turn == 'g') { + if (ch == 'y') { + cont = 1; + pprints(21, 0, " \033[1;33m◆你持紅色棋\033[m 可連吃"); + } else { + pprints(23, 30, ""); + currutmp->turn = (uin->turn) ? 0 : 1; } - else { pprints(23,30,""); currutmp->turn=(uin->turn)?0:1; } } + if (currutmp->turn == 1) { + if (uin->turn == 'g') { + cont = 1; + uin->turn = (currutmp->turn) ? 0 : 1; + pprints(21, 10, "可連吃"); + } + end = playing(fd, currutmp->color - '0', ch, &go_on, uin); - if(currutmp->turn==1) - { - if(uin->turn=='g') { cont=1;uin->turn=(currutmp->turn)?0:1; pprints(21,10,"可連吃"); } - end=playing(fd,currutmp->color-'0',ch,&go_on,uin); - - if(end == -1) { currutmp->turn='w';break; } - else if(end == -2) { uin->turn='w';break; } - else if(end == -3) { - uin->turn='p';curr.end=-3; - send(fd,&curr,sizeof(curr),0); - send(fd,&brd,sizeof(buf),0); + if (end == -1) { + currutmp->turn = 'w'; + break; + } else if (end == -2) { + uin->turn = 'w'; + break; + } else if (end == -3) { + uin->turn = 'p'; + curr.end = -3; + send(fd, &curr, sizeof(curr), 0); + send(fd, &brd, sizeof(buf), 0); continue; - } - else if(end == -4) { - if(currutmp->color!='1'&&currutmp->color!='0') + } else if (end == -4) { + if (currutmp->color != '1' && currutmp->color != '0') continue; - uin->turn='c';i=0;curr.end=-4; - send(fd,&curr,sizeof(curr),0); - send(fd,&brd,sizeof(buf),0); + uin->turn = 'c'; + i = 0; + curr.end = -4; + send(fd, &curr, sizeof(curr), 0); + send(fd, &brd, sizeof(buf), 0); continue; - } - else if(end == -5) { - uin->turn='g';curr.end=-5; - send(fd,&curr,sizeof(curr),0); - send(fd,&brd,sizeof(buf),0); + } else if (end == -5) { + uin->turn = 'g'; + curr.end = -5; + send(fd, &curr, sizeof(curr), 0); + send(fd, &brd, sizeof(buf), 0); continue; } - if(!i && currutmp->color=='1') - { pprints(21,0," \033[1;33m◆你持紅色棋\033[m");i++;move(cury[my],curx[mx]); } - if(!i && currutmp->color=='0') - { pprints(21,0," \033[1;33m◆你持黑色棋\033[m");i++;move(cury[my],curx[mx]); } - - if(uin->turn == 'e') { end=-3; break; } - if(go_on < 0) continue; + if (!i && currutmp->color == '1') { + pprints(21, 0, " \033[1;33m◆你持紅色棋\033[m"); + i++; + move(cury[my], curx[mx]); + } + if (!i && currutmp->color == '0') { + pprints(21, 0, " \033[1;33m◆你持黑色棋\033[m"); + i++; + move(cury[my], curx[mx]); + } + if (uin->turn == 'e') { + end = -3; + break; + } + if (go_on < 0) + continue; - move(22,0);clrtoeol(); - prints(" ◆輪到%s下 別怕別怕 他算啥米",currutmp->mateid); + move(22, 0); + clrtoeol(); + prints(" ◆輪到%s下 別怕別怕 他算啥米", currutmp->mateid); currutmp->turn = 0; uin->turn = 1; - }else - { - if(ch == 'q'){uin->turn='w';break;} - move(22,0);clrtoeol(); - prints(" ◆輪到%s下 別怕別怕 他算啥米",currutmp->mateid); + } else { + if (ch == 'q') { + uin->turn = 'w'; + break; + } + move(22, 0); + clrtoeol(); + prints(" ◆輪到%s下 別怕別怕 他算啥米", currutmp->mateid); } } } - switch(end) - { + switch (end) { case -1: case -2: - if(currutmp->turn=='w'){ move(22,0);clrtoeol();prints("你贏了.. 真是恭喜~~");} - else {move(22,0);clrtoeol();prints("輸掉了啦.....下次讓他好看!!");} - break; + if (currutmp->turn == 'w') { + move(22, 0); + clrtoeol(); + prints("你贏了.. 真是恭喜~~"); + } else { + move(22, 0); + clrtoeol(); + prints("輸掉了啦.....下次讓他好看!!"); + } + break; case -3: - pprints(22,0,"合棋唷!! 下次在分高下吧 ^_^"); - break; + pprints(22, 0, "合棋唷!! 下次在分高下吧 ^_^"); + break; default: - add_io(0,0); - close(fd); - pressanykey(); - return 0; + add_io(0, 0); + close(fd); + pressanykey(); + return 0; } - add_io(0,0); + add_io(0, 0); close(fd); pressanykey(); return 0; diff --git a/pttbbs/mbbsd/descrypt.c b/pttbbs/mbbsd/descrypt.c index 1d246670..ede4f9f3 100644 --- a/pttbbs/mbbsd/descrypt.c +++ b/pttbbs/mbbsd/descrypt.c @@ -1,61 +1,58 @@ -/* $Id: descrypt.c,v 1.2 2002/04/27 15:50:17 in2 Exp $ */ +/* $Id: descrypt.c,v 1.3 2002/07/05 17:10:27 in2 Exp $ */ /* * FreeSec: libcrypt for NetBSD - * - * Copyright (c) 1994 David Burren - * All rights reserved. - * - * Adapted for FreeBSD-2.0 by Geoffrey M. Rehmet - * crypt.c should now *only* export crypt(), in order to make - * binaries of libcrypt exportable from the USA - * + * + * Copyright (c) 1994 David Burren All rights reserved. + * + * Adapted for FreeBSD-2.0 by Geoffrey M. Rehmet crypt.c should now *only* + * export crypt(), in order to make binaries of libcrypt exportable from the + * USA + * * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 4. Neither the name of the author nor the names of other contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * modification, are permitted provided that the following conditions are + * met: 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. 2. + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. 4. Neither the name + * of the author nor the names of other contributors may be used to endorse + * or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. - * - * $FreeBSD: src/secure/lib/libcrypt/crypt.c,v 1.11 1999/08/28 01:30:24 peter Exp $ - * - * This is an original implementation of the DES and the crypt(3) interfaces - * by David Burren <davidb@werj.com.au>. - * - * An excellent reference on the underlying algorithm (and related - * algorithms) is: - * - * B. Schneier, Applied Cryptography: protocols, algorithms, - * and source code in C, John Wiley & Sons, 1994. - * + * + * $FreeBSD: src/secure/lib/libcrypt/crypt.c,v 1.11 1999/08/28 01:30:24 peter + * Exp $ + * + * This is an original implementation of the DES and the crypt(3) interfaces by + * David Burren <davidb@werj.com.au>. + * + * An excellent reference on the underlying algorithm (and related algorithms) + * is: + * + * B. Schneier, Applied Cryptography: protocols, algorithms, and source code in + * C, John Wiley & Sons, 1994. + * * Note that in that book's description of DES the lookups for the initial, * pbox, and final permutations are inverted (this has been brought to the - * attention of the author). A list of errata for this book has been - * posted to the sci.crypt newsgroup by the author and is available for FTP. - * - * ARCHITECTURE ASSUMPTIONS: - * This code assumes that u_longs are 32 bits. It will probably not - * operate on 64-bit machines without modifications. - * It is assumed that the 8-byte arrays passed by reference can be - * addressed as arrays of u_longs (ie. the CPU is not picky about - * alignment). + * attention of the author). A list of errata for this book has been posted + * to the sci.crypt newsgroup by the author and is available for FTP. + * + * ARCHITECTURE ASSUMPTIONS: This code assumes that u_longs are 32 bits. It + * will probably not operate on 64-bit machines without modifications. It is + * assumed that the 8-byte arrays passed by reference can be addressed as + * arrays of u_longs (ie. the CPU is not picky about alignment). */ #ifndef HAVE_DES_CRYPT @@ -66,19 +63,19 @@ #include <string.h> static unsigned char IP[64] = { - 58, 50, 42, 34, 26, 18, 10, 2, 60, 52, 44, 36, 28, 20, 12, 4, - 62, 54, 46, 38, 30, 22, 14, 6, 64, 56, 48, 40, 32, 24, 16, 8, - 57, 49, 41, 33, 25, 17, 9, 1, 59, 51, 43, 35, 27, 19, 11, 3, - 61, 53, 45, 37, 29, 21, 13, 5, 63, 55, 47, 39, 31, 23, 15, 7 + 58, 50, 42, 34, 26, 18, 10, 2, 60, 52, 44, 36, 28, 20, 12, 4, + 62, 54, 46, 38, 30, 22, 14, 6, 64, 56, 48, 40, 32, 24, 16, 8, + 57, 49, 41, 33, 25, 17, 9, 1, 59, 51, 43, 35, 27, 19, 11, 3, + 61, 53, 45, 37, 29, 21, 13, 5, 63, 55, 47, 39, 31, 23, 15, 7 }; static unsigned char inv_key_perm[64]; static unsigned char u_key_perm[56]; static unsigned char key_perm[56] = { - 57, 49, 41, 33, 25, 17, 9, 1, 58, 50, 42, 34, 26, 18, - 10, 2, 59, 51, 43, 35, 27, 19, 11, 3, 60, 52, 44, 36, - 63, 55, 47, 39, 31, 23, 15, 7, 62, 54, 46, 38, 30, 22, - 14, 6, 61, 53, 45, 37, 29, 21, 13, 5, 28, 20, 12, 4 + 57, 49, 41, 33, 25, 17, 9, 1, 58, 50, 42, 34, 26, 18, + 10, 2, 59, 51, 43, 35, 27, 19, 11, 3, 60, 52, 44, 36, + 63, 55, 47, 39, 31, 23, 15, 7, 62, 54, 46, 38, 30, 22, + 14, 6, 61, 53, 45, 37, 29, 21, 13, 5, 28, 20, 12, 4 }; static unsigned char key_shifts[16] = { @@ -87,72 +84,72 @@ static unsigned char key_shifts[16] = { static unsigned char inv_comp_perm[56]; static unsigned char comp_perm[48] = { - 14, 17, 11, 24, 1, 5, 3, 28, 15, 6, 21, 10, - 23, 19, 12, 4, 26, 8, 16, 7, 27, 20, 13, 2, + 14, 17, 11, 24, 1, 5, 3, 28, 15, 6, 21, 10, + 23, 19, 12, 4, 26, 8, 16, 7, 27, 20, 13, 2, 41, 52, 31, 37, 47, 55, 30, 40, 51, 45, 33, 48, 44, 49, 39, 56, 34, 53, 46, 42, 50, 36, 29, 32 }; /* - * No E box is used, as it's replaced by some ANDs, shifts, and ORs. + * No E box is used, as it's replaced by some ANDs, shifts, and ORs. */ static unsigned char u_sbox[8][64]; static unsigned char sbox[8][64] = { { - 14, 4, 13, 1, 2, 15, 11, 8, 3, 10, 6, 12, 5, 9, 0, 7, - 0, 15, 7, 4, 14, 2, 13, 1, 10, 6, 12, 11, 9, 5, 3, 8, - 4, 1, 14, 8, 13, 6, 2, 11, 15, 12, 9, 7, 3, 10, 5, 0, - 15, 12, 8, 2, 4, 9, 1, 7, 5, 11, 3, 14, 10, 0, 6, 13 + 14, 4, 13, 1, 2, 15, 11, 8, 3, 10, 6, 12, 5, 9, 0, 7, + 0, 15, 7, 4, 14, 2, 13, 1, 10, 6, 12, 11, 9, 5, 3, 8, + 4, 1, 14, 8, 13, 6, 2, 11, 15, 12, 9, 7, 3, 10, 5, 0, + 15, 12, 8, 2, 4, 9, 1, 7, 5, 11, 3, 14, 10, 0, 6, 13 }, { - 15, 1, 8, 14, 6, 11, 3, 4, 9, 7, 2, 13, 12, 0, 5, 10, - 3, 13, 4, 7, 15, 2, 8, 14, 12, 0, 1, 10, 6, 9, 11, 5, - 0, 14, 7, 11, 10, 4, 13, 1, 5, 8, 12, 6, 9, 3, 2, 15, - 13, 8, 10, 1, 3, 15, 4, 2, 11, 6, 7, 12, 0, 5, 14, 9 + 15, 1, 8, 14, 6, 11, 3, 4, 9, 7, 2, 13, 12, 0, 5, 10, + 3, 13, 4, 7, 15, 2, 8, 14, 12, 0, 1, 10, 6, 9, 11, 5, + 0, 14, 7, 11, 10, 4, 13, 1, 5, 8, 12, 6, 9, 3, 2, 15, + 13, 8, 10, 1, 3, 15, 4, 2, 11, 6, 7, 12, 0, 5, 14, 9 }, { - 10, 0, 9, 14, 6, 3, 15, 5, 1, 13, 12, 7, 11, 4, 2, 8, - 13, 7, 0, 9, 3, 4, 6, 10, 2, 8, 5, 14, 12, 11, 15, 1, - 13, 6, 4, 9, 8, 15, 3, 0, 11, 1, 2, 12, 5, 10, 14, 7, - 1, 10, 13, 0, 6, 9, 8, 7, 4, 15, 14, 3, 11, 5, 2, 12 + 10, 0, 9, 14, 6, 3, 15, 5, 1, 13, 12, 7, 11, 4, 2, 8, + 13, 7, 0, 9, 3, 4, 6, 10, 2, 8, 5, 14, 12, 11, 15, 1, + 13, 6, 4, 9, 8, 15, 3, 0, 11, 1, 2, 12, 5, 10, 14, 7, + 1, 10, 13, 0, 6, 9, 8, 7, 4, 15, 14, 3, 11, 5, 2, 12 }, { - 7, 13, 14, 3, 0, 6, 9, 10, 1, 2, 8, 5, 11, 12, 4, 15, - 13, 8, 11, 5, 6, 15, 0, 3, 4, 7, 2, 12, 1, 10, 14, 9, - 10, 6, 9, 0, 12, 11, 7, 13, 15, 1, 3, 14, 5, 2, 8, 4, - 3, 15, 0, 6, 10, 1, 13, 8, 9, 4, 5, 11, 12, 7, 2, 14 + 7, 13, 14, 3, 0, 6, 9, 10, 1, 2, 8, 5, 11, 12, 4, 15, + 13, 8, 11, 5, 6, 15, 0, 3, 4, 7, 2, 12, 1, 10, 14, 9, + 10, 6, 9, 0, 12, 11, 7, 13, 15, 1, 3, 14, 5, 2, 8, 4, + 3, 15, 0, 6, 10, 1, 13, 8, 9, 4, 5, 11, 12, 7, 2, 14 }, { - 2, 12, 4, 1, 7, 10, 11, 6, 8, 5, 3, 15, 13, 0, 14, 9, - 14, 11, 2, 12, 4, 7, 13, 1, 5, 0, 15, 10, 3, 9, 8, 6, - 4, 2, 1, 11, 10, 13, 7, 8, 15, 9, 12, 5, 6, 3, 0, 14, - 11, 8, 12, 7, 1, 14, 2, 13, 6, 15, 0, 9, 10, 4, 5, 3 + 2, 12, 4, 1, 7, 10, 11, 6, 8, 5, 3, 15, 13, 0, 14, 9, + 14, 11, 2, 12, 4, 7, 13, 1, 5, 0, 15, 10, 3, 9, 8, 6, + 4, 2, 1, 11, 10, 13, 7, 8, 15, 9, 12, 5, 6, 3, 0, 14, + 11, 8, 12, 7, 1, 14, 2, 13, 6, 15, 0, 9, 10, 4, 5, 3 }, { - 12, 1, 10, 15, 9, 2, 6, 8, 0, 13, 3, 4, 14, 7, 5, 11, - 10, 15, 4, 2, 7, 12, 9, 5, 6, 1, 13, 14, 0, 11, 3, 8, - 9, 14, 15, 5, 2, 8, 12, 3, 7, 0, 4, 10, 1, 13, 11, 6, - 4, 3, 2, 12, 9, 5, 15, 10, 11, 14, 1, 7, 6, 0, 8, 13 + 12, 1, 10, 15, 9, 2, 6, 8, 0, 13, 3, 4, 14, 7, 5, 11, + 10, 15, 4, 2, 7, 12, 9, 5, 6, 1, 13, 14, 0, 11, 3, 8, + 9, 14, 15, 5, 2, 8, 12, 3, 7, 0, 4, 10, 1, 13, 11, 6, + 4, 3, 2, 12, 9, 5, 15, 10, 11, 14, 1, 7, 6, 0, 8, 13 }, { - 4, 11, 2, 14, 15, 0, 8, 13, 3, 12, 9, 7, 5, 10, 6, 1, - 13, 0, 11, 7, 4, 9, 1, 10, 14, 3, 5, 12, 2, 15, 8, 6, - 1, 4, 11, 13, 12, 3, 7, 14, 10, 15, 6, 8, 0, 5, 9, 2, - 6, 11, 13, 8, 1, 4, 10, 7, 9, 5, 0, 15, 14, 2, 3, 12 + 4, 11, 2, 14, 15, 0, 8, 13, 3, 12, 9, 7, 5, 10, 6, 1, + 13, 0, 11, 7, 4, 9, 1, 10, 14, 3, 5, 12, 2, 15, 8, 6, + 1, 4, 11, 13, 12, 3, 7, 14, 10, 15, 6, 8, 0, 5, 9, 2, + 6, 11, 13, 8, 1, 4, 10, 7, 9, 5, 0, 15, 14, 2, 3, 12 }, { - 13, 2, 8, 4, 6, 15, 11, 1, 10, 9, 3, 14, 5, 0, 12, 7, - 1, 15, 13, 8, 10, 3, 7, 4, 12, 5, 6, 11, 0, 14, 9, 2, - 7, 11, 4, 1, 9, 12, 14, 2, 0, 6, 10, 13, 15, 3, 5, 8, - 2, 1, 14, 7, 4, 10, 8, 13, 15, 12, 9, 0, 3, 5, 6, 11 + 13, 2, 8, 4, 6, 15, 11, 1, 10, 9, 3, 14, 5, 0, 12, 7, + 1, 15, 13, 8, 10, 3, 7, 4, 12, 5, 6, 11, 0, 14, 9, 2, + 7, 11, 4, 1, 9, 12, 14, 2, 0, 6, 10, 13, 15, 3, 5, 8, + 2, 1, 14, 7, 4, 10, 8, 13, 15, 12, 9, 0, 3, 5, 6, 11 } }; static unsigned char un_pbox[32]; static unsigned char pbox[32] = { - 16, 7, 20, 21, 29, 12, 28, 17, 1, 15, 23, 26, 5, 18, 31, 10, - 2, 8, 24, 14, 32, 27, 3, 9, 19, 13, 30, 6, 22, 11, 4, 25 + 16, 7, 20, 21, 29, 12, 28, 17, 1, 15, 23, 26, 5, 18, 31, 10, + 2, 8, 24, 14, 32, 27, 3, 9, 19, 13, 30, 6, 22, 11, 4, 25 }; static unsigned long bits32[32] = { @@ -166,15 +163,15 @@ static unsigned long bits32[32] = { 0x00000008, 0x00000004, 0x00000002, 0x00000001 }; -static unsigned char bits8[8] = { 0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01 }; +static unsigned char bits8[8] = {0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01}; static unsigned long saltbits; -static long old_salt; +static long old_salt; static unsigned long *bits28, *bits24; static unsigned char init_perm[64], final_perm[64]; static unsigned long en_keysl[16], en_keysr[16]; static unsigned long de_keysl[16], de_keysr[16]; -static int des_initialised = 0; +static int des_initialised = 0; static unsigned char m_sbox[4][4096]; static unsigned long psbox[4][256]; static unsigned long ip_maskl[8][256], ip_maskr[8][256]; @@ -183,52 +180,56 @@ static unsigned long key_perm_maskl[8][128], key_perm_maskr[8][128]; static unsigned long comp_maskl[8][128], comp_maskr[8][128]; static unsigned long old_rawkey0, old_rawkey1; -static unsigned char ascii64[] = +static unsigned char ascii64[] = "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; -/* 0000000000111111111122222222223333333333444444444455555555556666 */ -/* 0123456789012345678901234567890123456789012345678901234567890123 */ +/* 0000000000111111111122222222223333333333444444444455555555556666 */ +/* 0123456789012345678901234567890123456789012345678901234567890123 */ -static int ascii_to_bin(char ch) { - if(ch > 'z') +static int +ascii_to_bin(char ch) +{ + if (ch > 'z') return 0; - if(ch >= 'a') + if (ch >= 'a') return ch - 'a' + 38; - if(ch > 'Z') + if (ch > 'Z') return 0; - if(ch >= 'A') + if (ch >= 'A') return ch - 'A' + 12; - if(ch > '9') + if (ch > '9') return 0; - if(ch >= '.') + if (ch >= '.') return ch - '.'; return 0; } -static void des_init() { - int i, j, b, k, inbit, obit; - unsigned long *p, *il, *ir, *fl, *fr; - +static void +des_init() +{ + int i, j, b, k, inbit, obit; + unsigned long *p, *il, *ir, *fl, *fr; + old_rawkey0 = old_rawkey1 = 0L; saltbits = 0L; old_salt = 0L; bits24 = (bits28 = bits32 + 4) + 4; - + /* * Invert the S-boxes, reordering the input bits. */ - for(i = 0; i < 8; i++) - for(j = 0; j < 64; j++) { + for (i = 0; i < 8; i++) + for (j = 0; j < 64; j++) { b = (j & 0x20) | ((j & 1) << 4) | ((j >> 1) & 0xf); u_sbox[i][j] = sbox[i][b]; } - + /* - * Convert the inverted S-boxes into 4 arrays of 8 bits. - * Each will handle 12 bits of the S-box input. + * Convert the inverted S-boxes into 4 arrays of 8 bits. Each will handle + * 12 bits of the S-box input. */ - for(b = 0; b < 4; b++) - for(i = 0; i < 64; i++) - for(j = 0; j < 64; j++) + for (b = 0; b < 4; b++) + for (i = 0; i < 64; i++) + for (j = 0; j < 64; j++) m_sbox[b][(i << 6) | j] = (u_sbox[(b << 1)][i] << 4) | u_sbox[(b << 1) + 1][j]; @@ -237,16 +238,16 @@ static void des_init() { * Set up the initial & final permutations into a useful form, and * initialise the inverted key permutation. */ - for(i = 0; i < 64; i++) { + for (i = 0; i < 64; i++) { init_perm[final_perm[i] = IP[i] - 1] = i; inv_key_perm[i] = 255; } /* - * Invert the key permutation and initialise the inverted key - * compression permutation. + * Invert the key permutation and initialise the inverted key compression + * permutation. */ - for(i = 0; i < 56; i++) { + for (i = 0; i < 56; i++) { u_key_perm[i] = key_perm[i] - 1; inv_key_perm[key_perm[i] - 1] = i; inv_comp_perm[i] = 255; @@ -255,27 +256,27 @@ static void des_init() { /* * Invert the key compression permutation. */ - for(i = 0; i < 48; i++) { + for (i = 0; i < 48; i++) { inv_comp_perm[comp_perm[i] - 1] = i; } /* - * Set up the OR-mask arrays for the initial and final permutations, - * and for the key initial and compression permutations. + * Set up the OR-mask arrays for the initial and final permutations, and + * for the key initial and compression permutations. */ - for(k = 0; k < 8; k++) { - for(i = 0; i < 256; i++) { + for (k = 0; k < 8; k++) { + for (i = 0; i < 256; i++) { *(il = &ip_maskl[k][i]) = 0L; *(ir = &ip_maskr[k][i]) = 0L; *(fl = &fp_maskl[k][i]) = 0L; *(fr = &fp_maskr[k][i]) = 0L; - for(j = 0; j < 8; j++) { + for (j = 0; j < 8; j++) { inbit = 8 * k + j; - if(i & bits8[j]) { - if((obit = init_perm[inbit]) < 32) + if (i & bits8[j]) { + if ((obit = init_perm[inbit]) < 32) *il |= bits32[obit]; else - *ir |= bits32[obit-32]; + *ir |= bits32[obit - 32]; if ((obit = final_perm[inbit]) < 32) *fl |= bits32[obit]; else @@ -283,15 +284,15 @@ static void des_init() { } } } - for(i = 0; i < 128; i++) { + for (i = 0; i < 128; i++) { *(il = &key_perm_maskl[k][i]) = 0L; *(ir = &key_perm_maskr[k][i]) = 0L; - for(j = 0; j < 7; j++) { + for (j = 0; j < 7; j++) { inbit = 8 * k + j; - if(i & bits8[j + 1]) { - if((obit = inv_key_perm[inbit]) == 255) + if (i & bits8[j + 1]) { + if ((obit = inv_key_perm[inbit]) == 255) continue; - if(obit < 28) + if (obit < 28) *il |= bits28[obit]; else *ir |= bits28[obit - 28]; @@ -299,12 +300,12 @@ static void des_init() { } *(il = &comp_maskl[k][i]) = 0L; *(ir = &comp_maskr[k][i]) = 0L; - for(j = 0; j < 7; j++) { + for (j = 0; j < 7; j++) { inbit = 7 * k + j; - if(i & bits8[j + 1]) { - if((obit=inv_comp_perm[inbit]) == 255) + if (i & bits8[j + 1]) { + if ((obit = inv_comp_perm[inbit]) == 255) continue; - if(obit < 24) + if (obit < 24) *il |= bits24[obit]; else *ir |= bits24[obit - 24]; @@ -312,34 +313,36 @@ static void des_init() { } } } - + /* - * Invert the P-box permutation, and convert into OR-masks for - * handling the output of the S-box arrays setup above. + * Invert the P-box permutation, and convert into OR-masks for handling + * the output of the S-box arrays setup above. */ - for(i = 0; i < 32; i++) + for (i = 0; i < 32; i++) un_pbox[pbox[i] - 1] = i; - for(b = 0; b < 4; b++) - for(i = 0; i < 256; i++) { + for (b = 0; b < 4; b++) + for (i = 0; i < 256; i++) { *(p = &psbox[b][i]) = 0L; for (j = 0; j < 8; j++) { if (i & bits8[j]) *p |= bits32[un_pbox[8 * b + j]]; } } - + des_initialised = 1; } -static void setup_salt(long salt) { - unsigned long obit, saltbit; - int i; - +static void +setup_salt(long salt) +{ + unsigned long obit, saltbit; + int i; + if (salt == old_salt) return; old_salt = salt; - + saltbits = 0L; saltbit = 1; obit = 0x800000; @@ -351,32 +354,33 @@ static void setup_salt(long salt) { } } -static int des_setkey(const char *key) { - unsigned long k0, k1, rawkey0, rawkey1; - int shifts, round; +static int +des_setkey(const char *key) +{ + unsigned long k0, k1, rawkey0, rawkey1; + int shifts, round; - if(!des_initialised) + if (!des_initialised) des_init(); - - rawkey0 = ntohl(*(unsigned long *) key); - rawkey1 = ntohl(*(unsigned long *) (key + 4)); - - if((rawkey0 | rawkey1) - && rawkey0 == old_rawkey0 - && rawkey1 == old_rawkey1) { + + rawkey0 = ntohl(*(unsigned long *)key); + rawkey1 = ntohl(*(unsigned long *)(key + 4)); + + if ((rawkey0 | rawkey1) + && rawkey0 == old_rawkey0 + && rawkey1 == old_rawkey1) { /* - * Already setup for this key. - * This optimisation fails on a zero key (which is weak and - * has bad parity anyway) in order to simplify the starting - * conditions. + * Already setup for this key. This optimisation fails on a zero key + * (which is weak and has bad parity anyway) in order to simplify the + * starting conditions. */ return 0; } old_rawkey0 = rawkey0; old_rawkey1 = rawkey1; - + /* - * Do key permutation and split into two 28-bit subkeys. + * Do key permutation and split into two 28-bit subkeys. */ k0 = key_perm_maskl[0][rawkey0 >> 25] | key_perm_maskl[1][(rawkey0 >> 17) & 0x7f] @@ -395,17 +399,17 @@ static int des_setkey(const char *key) { | key_perm_maskr[6][(rawkey1 >> 9) & 0x7f] | key_perm_maskr[7][(rawkey1 >> 1) & 0x7f]; /* - * Rotate subkeys and do compression permutation. + * Rotate subkeys and do compression permutation. */ shifts = 0; - for(round = 0; round < 16; round++) { - unsigned long t0, t1; - + for (round = 0; round < 16; round++) { + unsigned long t0, t1; + shifts += key_shifts[round]; - + t0 = (k0 << shifts) | (k0 >> (28 - shifts)); t1 = (k1 << shifts) | (k1 >> (28 - shifts)); - + de_keysl[15 - round] = en_keysl[round] = comp_maskl[0][(t0 >> 21) & 0x7f] | comp_maskl[1][(t0 >> 14) & 0x7f] @@ -415,7 +419,7 @@ static int des_setkey(const char *key) { | comp_maskl[5][(t1 >> 14) & 0x7f] | comp_maskl[6][(t1 >> 7) & 0x7f] | comp_maskl[7][t1 & 0x7f]; - + de_keysr[15 - round] = en_keysr[round] = comp_maskr[0][(t0 >> 21) & 0x7f] | comp_maskr[1][(t0 >> 14) & 0x7f] @@ -429,35 +433,37 @@ static int des_setkey(const char *key) { return 0; } -static int do_des(unsigned long l_in, unsigned long r_in, unsigned long *l_out, - unsigned long *r_out, int count) { +static int +do_des(unsigned long l_in, unsigned long r_in, unsigned long *l_out, + unsigned long *r_out, int count) +{ /* - * l_in, r_in, l_out, and r_out are in pseudo-"big-endian" format. - */ - unsigned long l, r, *kl, *kr, *kl1, *kr1; - unsigned long f, r48l, r48r; - int round; + * l_in, r_in, l_out, and r_out are in pseudo-"big-endian" format. + */ + unsigned long l, r, *kl, *kr, *kl1, *kr1; + unsigned long f, r48l, r48r; + int round; - if(count == 0) { + if (count == 0) { return 1; - } else if(count > 0) { + } else if (count > 0) { /* - * Encrypting - */ + * Encrypting + */ kl1 = en_keysl; kr1 = en_keysr; } else { /* - * Decrypting - */ + * Decrypting + */ count = -count; kl1 = de_keysl; kr1 = de_keysr; } - + /* - * Do initial permutation (IP). - */ + * Do initial permutation (IP). + */ l = ip_maskl[0][l_in >> 24] | ip_maskl[1][(l_in >> 16) & 0xff] | ip_maskl[2][(l_in >> 8) & 0xff] @@ -474,15 +480,15 @@ static int do_des(unsigned long l_in, unsigned long r_in, unsigned long *l_out, | ip_maskr[5][(r_in >> 16) & 0xff] | ip_maskr[6][(r_in >> 8) & 0xff] | ip_maskr[7][r_in & 0xff]; - - while(count--) { + + while (count--) { /* * Do each round. */ kl = kl1; kr = kr1; round = 16; - while(round--) { + while (round--) { /* * Expand R to 48 bits (simulate the E-box). */ @@ -498,15 +504,15 @@ static int do_des(unsigned long l_in, unsigned long r_in, unsigned long *l_out, | ((r & 0x0000001f) << 1) | ((r & 0x80000000) >> 31); /* - * Do salting for crypt() and friends, and - * XOR with the permuted key. + * Do salting for crypt() and friends, and XOR with the permuted + * key. */ f = (r48l ^ r48r) & saltbits; r48l ^= f ^ *kl++; r48r ^= f ^ *kr++; /* - * Do sbox lookups (which shrink it back to 32 bits) - * and do the pbox permutation at the same time. + * Do sbox lookups (which shrink it back to 32 bits) and do the + * pbox permutation at the same time. */ f = psbox[0][m_sbox[0][r48l >> 12]] | psbox[1][m_sbox[1][r48l & 0xfff]] @@ -523,8 +529,8 @@ static int do_des(unsigned long l_in, unsigned long r_in, unsigned long *l_out, l = f; } /* - * Do final permutation (inverse of IP). - */ + * Do final permutation (inverse of IP). + */ *l_out = fp_maskl[0][l >> 24] | fp_maskl[1][(l >> 16) & 0xff] | fp_maskl[2][(l >> 8) & 0xff] @@ -544,41 +550,40 @@ static int do_des(unsigned long l_in, unsigned long r_in, unsigned long *l_out, return 0; } -char *crypt(char *key, char *setting) { - unsigned long count, salt, l, r0, r1, keybuf[2]; - unsigned char *p, *q; +char * +crypt(char *key, char *setting) +{ + unsigned long count, salt, l, r0, r1, keybuf[2]; + unsigned char *p, *q; static unsigned char output[21]; - - if(!des_initialised) + + if (!des_initialised) des_init(); /* - * Copy the key, shifting each character up by one bit - * and padding with zeros. + * Copy the key, shifting each character up by one bit and padding with + * zeros. */ q = (unsigned char *)keybuf; - while(q - (unsigned char *)keybuf - 8) { - if((*q++ = *key << 1)) + while (q - (unsigned char *)keybuf - 8) { + if ((*q++ = *key << 1)) key++; } - if(des_setkey((char *)keybuf)) + if (des_setkey((char *)keybuf)) return NULL; - + /* - * "old"-style: - * setting - 2 bytes of salt - * key - up to 8 characters + * "old"-style: setting - 2 bytes of salt key - up to 8 characters */ count = 25; salt = (ascii_to_bin(setting[1]) << 6) - | ascii_to_bin(setting[0]); + | ascii_to_bin(setting[0]); output[0] = setting[0]; /* - * If the encrypted password that the salt was extracted from - * is only 1 character long, the salt will be corrupted. We - * need to ensure that the output string doesn't have an extra - * NUL in it! + * If the encrypted password that the salt was extracted from is only 1 + * character long, the salt will be corrupted. We need to ensure that + * the output string doesn't have an extra NUL in it! */ output[1] = setting[1] ? setting[1] : output[0]; @@ -588,7 +593,7 @@ char *crypt(char *key, char *setting) { /* * Do it. */ - if(do_des(0L, 0L, &r0, &r1, count)) + if (do_des(0L, 0L, &r0, &r1, count)) return NULL; /* * Now encode the result... diff --git a/pttbbs/mbbsd/dice.c b/pttbbs/mbbsd/dice.c index 32ef7f5b..62aeba16 100644 --- a/pttbbs/mbbsd/dice.c +++ b/pttbbs/mbbsd/dice.c @@ -1,4 +1,4 @@ -/* $Id: dice.c,v 1.3 2002/06/04 13:08:33 in2 Exp $ */ +/* $Id: dice.c,v 1.4 2002/07/05 17:10:27 in2 Exp $ */ #include "bbs.h" #define DICE_TXT BBSHOME "/etc/dice.txt" @@ -12,85 +12,94 @@ #define B_TIMES 5 #define B_THIRD 3 -static int flag[100], value[100]; +static int flag[100], value[100]; typedef struct dicedata_t { - int mybet; - int mymoney; -} dicedata_t; - -static void set_bingo(int bet[]) { - int i, j = 0, k = 0, m = 0; - - for(i = 0; i < 3; i++) - for(j = 2; j > i; j--) - if(bet[j] < bet[j - 1]) { + int mybet; + int mymoney; +} dicedata_t; + +static void +set_bingo(int bet[]) +{ + int i, j = 0, k = 0, m = 0; + + for (i = 0; i < 3; i++) + for (j = 2; j > i; j--) + if (bet[j] < bet[j - 1]) { m = bet[j]; bet[j] = bet[j - 1]; - bet[j - 1]=m; + bet[j - 1] = m; } - - for(i = 0; i < 100; i++) + for (i = 0; i < 100; i++) flag[i] = 0; - - for(i = 0; i < 3; i++) + + for (i = 0; i < 3; i++) flag[bet[i]]++; j = bet[0] + bet[1] + bet[2]; - if((abs(bet[1] - bet[0]) == 1 && abs(bet[2] - bet[0]) == 2) || - (abs(bet[2] - bet[0]) == 1 && abs(bet[1] - bet[0]) == 2)) + if ((abs(bet[1] - bet[0]) == 1 && abs(bet[2] - bet[0]) == 2) || + (abs(bet[2] - bet[0]) == 1 && abs(bet[1] - bet[0]) == 2)) flag[66] = B_TIMES; - - if(j < 10){ + + if (j < 10) { flag[7] = B_COMMON; - for(i = 0; i < 3; i++) - if(bet[i] == 4) + for (i = 0; i < 3; i++) + if (bet[i] == 4) flag[74] = B_TIMES; - } else if(j > 11) { + } else if (j > 11) { flag[8] = B_COMMON; - for(i = 0; i < 3; i++) - if(bet[i] == 3) - flag[83]=B_TIMES; + for (i = 0; i < 3; i++) + if (bet[i] == 3) + flag[83] = B_TIMES; } else flag[11] = B_THIRD; - - for(i = 0; i < 3; i++) - for(j = i; j < 3; j++) { + + for (i = 0; i < 3; i++) + for (j = i; j < 3; j++) { m = bet[i]; k = bet[j]; - if(m != k) + if (m != k) flag[m * 10 + k] = B_TIMES; } } -static int bingo(int mybet) { +static int +bingo(int mybet) +{ return flag[mybet]; } -int IsNum(char *a, int n) { - int i; +int +IsNum(char *a, int n) +{ + int i; - for(i = 0; i < n; i++) - if (a[i] > '9' || a[i] < '0' ) + for (i = 0; i < n; i++) + if (a[i] > '9' || a[i] < '0') return 0; return 1; } -int IsSNum(char *a) { - int i; - - for(i = 0; a[i]; i++) - if(a[i] > '9' || a[i] < '0') +int +IsSNum(char *a) +{ + int i; + + for (i = 0; a[i]; i++) + if (a[i] > '9' || a[i] < '0') return 0; return 1; } -static void show_data(void) { +static void +show_data(void) +{ move(0, 0); prints("\033[31m ┌───────────────────────" "──────────┐\033[m\n"); prints("\033[45;37m倍率一\033[m\033[31m │ \033[33m[1]押一點 [2]押二點 " - "[3]押三點 [4]押四點 [5]押五點 [6]押六點 \033[31m │\033[m\n"); + "[3]押三點 [4]押四點 [5]押五點 [6]押六點 \033[31m │\033[m\n"); prints("\033[31m │ \033[33m[7]押小 [8]押大 " " \033[31m │\033[m\n"); prints("\033[31m │ " @@ -113,87 +122,93 @@ static void show_data(void) { "─────────┘\033[m\n"); } -static void show_count(int index, int money) { - int i = 0, count = 2, j, k; - +static void +show_count(int index, int money) +{ + int i = 0, count = 2, j, k; + value[index] += money; - move(14,0); + move(14, 0); clrtoline(18); - for(i = 1, j = 13; i <= 8; i++, count += 12) { - if(i == 6) { + for (i = 1, j = 13; i <= 8; i++, count += 12) { + if (i == 6) { j = 14; count = 2; } - move(j,count); + move(j, count); prints("[%2d]:%d ", i, value[i]); } - + count = 2; i = 15; - for(j = 1; j <= 5; j++) - for(k = j + 1; k <= 6; k++, count += 12) { - if(j == 2 && k == 4) { + for (j = 1; j <= 5; j++) + for (k = j + 1; k <= 6; k++, count += 12) { + if (j == 2 && k == 4) { i = 16; count = 2; - } else if(j==4 && k==5) { + } else if (j == 4 && k == 5) { i = 17; count = 2; } - move(i,count); + move(i, count); prints("[%d%d]:%d ", j, k, value[j * 10 + k]); } - - move(18,2); - prints("[11]:%d",value[11]); - move(18,14); - prints("[66]:%d",value[66]); - move(18,26); - prints("[74]:%d",value[74]); - move(18,38); - prints("[83]:%d",value[83]); + + move(18, 2); + prints("[11]:%d", value[11]); + move(18, 14); + prints("[66]:%d", value[66]); + move(18, 26); + prints("[74]:%d", value[74]); + move(18, 38); + prints("[83]:%d", value[83]); } -static int check_index(int index) { - int i,tp[] = {1, 2, 3, 4, 5, 6, 7, 8, 11, 12, 13, 14, 15, 16, 23, 24, 25, - 26, 34, 35, 36, 45, 46, 56, 66, 74, 83}; - if(index < 0 || index > 100) +static int +check_index(int index) +{ + int i, tp[] = {1, 2, 3, 4, 5, 6, 7, 8, 11, 12, 13, 14, 15, 16, 23, 24, 25, + 26, 34, 35, 36, 45, 46, 56, 66, 74, 83}; + if (index < 0 || index > 100) return 0; - for(i = 0; i < 27; i++) - if(index == tp[i]) + for (i = 0; i < 27; i++) + if (index == tp[i]) return 1; return 0; } -static int del(int total, dicedata_t *table) { - int index, money; - char data[10]; - int i; - - while(1) { +static int +del(int total, dicedata_t * table) +{ + int index, money; + char data[10]; + int i; + + while (1) { do { - move(22,0); + move(22, 0); clrtoeol(); getdata(21, 0, "輸入退選的數字(打q離開): ", data, 3, LCECHO); - if(data[0] == 'q' || data[0] == 'Q') + if (data[0] == 'q' || data[0] == 'Q') return 0; - } while(!IsNum(data,strlen(data))); - + } while (!IsNum(data, strlen(data))); + index = atoi(data); - for(i = 0; i < total; i++) { - if(table[i].mybet == index){ + for (i = 0; i < total; i++) { + if (table[i].mybet == index) { do { getdata(21, 0, "多少錢: ", data, 10, LCECHO); - } while(!IsNum(data,strlen(data))); + } while (!IsNum(data, strlen(data))); money = atoi(data); - if(money>table[i].mymoney) { - move(22,0); + if (money > table[i].mymoney) { + move(22, 0); clrtoeol(); prints("不夠扣啦"); i--; continue; } demoney(money); - move(19,0); + move(19, 0); clrtoeol(); prints("你現在有 %u Ptt$歐", cuser.money); table[i].mymoney -= money; @@ -205,71 +220,105 @@ static int del(int total, dicedata_t *table) { return 0; } -static int IsLegal(char *data) { - int money = atoi(data); - if(IsNum(data,strlen(data)) && money<=B_MAX && money>=B_MIN) +static int +IsLegal(char *data) +{ + int money = atoi(data); + if (IsNum(data, strlen(data)) && money <= B_MAX && money >= B_MIN) return money; return 0; } -static void show_output(int bet[]) { - int i, j = 10; - - move(12,0); +static void +show_output(int bet[]) +{ + int i, j = 10; + + move(12, 0); clrtoline(17); /* 暫時降啦 因為那各clrtoline怪怪的 */ - for(i = 13; i <= 18; i++) { - move(i,0); + for (i = 13; i <= 18; i++) { + move(i, 0); prints(" "); } - move(12,0); + move(12, 0); prints("\033[1;31m ┌──────────────────────" "─┐\033[m\n\n\n\n\n\n"); prints("\033[1;31m └──────────────────────" "─┘\033[m"); - for(i = 0; i < 3; i++, j += 25) { - switch(bet[i]) { + for (i = 0; i < 3; i++, j += 25) { + switch (bet[i]) { case 1: - move(13, j);prints("\033[37m╭────╮\033[m"); - move(14, j);prints("\033[37m│ │\033[m"); - move(15, j);prints("\033[37m│ ● │\033[m"); - move(16, j);prints("\033[37m│ │\033[m"); - move(17, j);prints("\033[37m╰────╯\033[m"); + move(13, j); + prints("\033[37m╭────╮\033[m"); + move(14, j); + prints("\033[37m│ │\033[m"); + move(15, j); + prints("\033[37m│ ● │\033[m"); + move(16, j); + prints("\033[37m│ │\033[m"); + move(17, j); + prints("\033[37m╰────╯\033[m"); break; case 2: - move(13, j);prints("\033[37m╭────╮\033[m"); - move(14, j);prints("\033[37m│ ●│\033[m"); - move(15, j);prints("\033[37m│ │\033[m"); - move(16, j);prints("\033[37m│● │\033[m"); - move(17, j);prints("\033[37m╰────╯\033[m"); + move(13, j); + prints("\033[37m╭────╮\033[m"); + move(14, j); + prints("\033[37m│ ●│\033[m"); + move(15, j); + prints("\033[37m│ │\033[m"); + move(16, j); + prints("\033[37m│● │\033[m"); + move(17, j); + prints("\033[37m╰────╯\033[m"); break; case 3: - move(13, j);prints("\033[37m╭────╮\033[m"); - move(14, j);prints("\033[37m│ ●│\033[m"); - move(15, j);prints("\033[37m│ ● │\033[m"); - move(16, j);prints("\033[37m│● │\033[m"); - move(17, j);prints("\033[37m╰────╯\033[m"); + move(13, j); + prints("\033[37m╭────╮\033[m"); + move(14, j); + prints("\033[37m│ ●│\033[m"); + move(15, j); + prints("\033[37m│ ● │\033[m"); + move(16, j); + prints("\033[37m│● │\033[m"); + move(17, j); + prints("\033[37m╰────╯\033[m"); break; case 4: - move(13, j);prints("\033[37m╭────╮\033[m"); - move(14, j);prints("\033[37m│● ●│\033[m"); - move(15, j);prints("\033[37m│ │\033[m"); - move(16, j);prints("\033[37m│● ●│\033[m"); - move(17, j);prints("\033[37m╰────╯\033[m"); + move(13, j); + prints("\033[37m╭────╮\033[m"); + move(14, j); + prints("\033[37m│● ●│\033[m"); + move(15, j); + prints("\033[37m│ │\033[m"); + move(16, j); + prints("\033[37m│● ●│\033[m"); + move(17, j); + prints("\033[37m╰────╯\033[m"); break; case 5: - move(13, j);prints("\033[37m╭────╮\033[m"); - move(14, j);prints("\033[37m│● ●│\033[m"); - move(15, j);prints("\033[37m│ ● │\033[m"); - move(16, j);prints("\033[37m│● ●│\033[m"); - move(17, j);prints("\033[37m╰────╯\033[m"); + move(13, j); + prints("\033[37m╭────╮\033[m"); + move(14, j); + prints("\033[37m│● ●│\033[m"); + move(15, j); + prints("\033[37m│ ● │\033[m"); + move(16, j); + prints("\033[37m│● ●│\033[m"); + move(17, j); + prints("\033[37m╰────╯\033[m"); break; case 6: - move(13, j);prints("\033[37m╭────╮\033[m"); - move(14, j);prints("\033[37m│● ●│\033[m"); - move(15, j);prints("\033[37m│● ●│\033[m"); - move(16, j);prints("\033[37m│● ●│\033[m"); - move(17, j);prints("\033[37m╰────╯\033[m"); + move(13, j); + prints("\033[37m╭────╮\033[m"); + move(14, j); + prints("\033[37m│● ●│\033[m"); + move(15, j); + prints("\033[37m│● ●│\033[m"); + move(16, j); + prints("\033[37m│● ●│\033[m"); + move(17, j); + prints("\033[37m╰────╯\033[m"); break; } } @@ -277,160 +326,162 @@ static void show_output(int bet[]) { #define lockreturn0(unmode, state) if(lockutmpmode(unmode, state)) return 0 -int dice_main(void) { - char input[10],data[256], ch; - dicedata_t table[256]; - int bet[3], index, money = 0, i, ya = 0, j, total, sig = 0; - FILE *winfp/* , *lostfp */; - +int +dice_main(void) +{ + char input[10], data[256], ch; + dicedata_t table[256]; + int bet[3], index, money = 0, i, ya = 0, j, total, sig = 0; + FILE *winfp /* , *lostfp */ ; + more(DICE_TXT, NA); reload_money(); - if(cuser.money < 10){ - move(19,0); + if (cuser.money < 10) { + move(19, 0); prints("\033[1;37m超過十元再來玩吧~~\033[m"); pressanykey(); return 0; } - lockreturn0(DICE, LOCK_MULTI); - winfp = fopen(DICE_WIN,"a"); - /*lostfp = fopen(DICE_LOST,"a");*/ - if(!winfp /*|| !lostfp*/) + winfp = fopen(DICE_WIN, "a"); + /* lostfp = fopen(DICE_LOST,"a"); */ + if (!winfp /* || !lostfp */ ) return 0; do { - total = 0; i = 0; + total = 0; + i = 0; ch = 'y'; clear(); show_data(); - for(j = 0; j < 3; j++) + for (j = 0; j < 3; j++) bet[j] = rand() % 6 + 1; - - for(j = 0; j < 100; j++) + + for (j = 0; j < 100; j++) value[j] = 0; - while(1) { - move(19,0); + while (1) { + move(19, 0); prints("\033[1;32m你現在有\033[1;31m %u \033[1;32mPtt$歐\033[m", cuser.money); getdata(20, 0, "\033[1;37m數字:加選 d:退選 s:開始或離開\033[m: ", input, 5, LCECHO); reload_money(); - if(input[0] != 's' && input[0] != 'd' && cuser.money < 10) { + if (input[0] != 's' && input[0] != 'd' && cuser.money < 10) { move(21, 0); clrtoeol(); prints("\033[1;37m超過十元才能賭~\033[m"); continue; } - if(input[0] == 'd' || input[0] == 'D') { + if (input[0] == 'd' || input[0] == 'D') { del(i, table); continue; } - if(input[0] == 's' || input[0] == 'S') + if (input[0] == 's' || input[0] == 'S') break; - - if(!IsNum(input,strlen(input))) + + if (!IsNum(input, strlen(input))) continue; - - index=atoi(input); - if(check_index(index) == 0) + + index = atoi(input); + if (check_index(index) == 0) continue; -/*輸入錢的loop*/ - while(1) { - if(cuser.money < 10) + /* 輸入錢的loop */ + while (1) { + if (cuser.money < 10) break; getdata(21, 0, "\033[1;32m賭多少錢呢\033[1;37m(大於10 小於500)" "\033[m: ", input, sizeof(input), LCECHO); - if(!(money = IsLegal(input))||input[0] == '0') + if (!(money = IsLegal(input)) || input[0] == '0') continue; - reload_money(); - if(money > cuser.money) + reload_money(); + if (money > cuser.money) continue; - for(j = 0, sig = 0; j < i; j++) - if(table[j].mybet == index) { - if(table[j].mymoney == B_MAX) + for (j = 0, sig = 0; j < i; j++) + if (table[j].mybet == index) { + if (table[j].mymoney == B_MAX) sig = 2; - else if(table[j].mymoney+money>B_MAX) { + else if (table[j].mymoney + money > B_MAX) { sig = 1; break; } else { - vice(money,"骰子"); + vice(money, "骰子"); table[j].mymoney += money; j = -1; break; } } - if(sig == 2) + if (sig == 2) break; - if(sig == 1) + if (sig == 1) continue; - if(j != -1) { - bzero((char*)&table[i], sizeof(dicedata_t)); + if (j != -1) { + bzero((char *)&table[i], sizeof(dicedata_t)); table[i].mybet = index; table[i++].mymoney = money; - vice(money,"骰子"); + vice(money, "骰子"); } break; } - reload_money(); - move(19,0); + reload_money(); + move(19, 0); prints("\033[1;32m你現在有 \033[1;31m%u\033[1;32m Ptt$歐", cuser.money); - if(sig != 2) + if (sig != 2) show_count(index, money); } - - if(i == 0) { + + if (i == 0) { fclose(winfp); - /*fclose(lostfp);*/ + /* fclose(lostfp); */ unlockutmpmode(); return 0; } - show_output(bet); set_bingo(bet); - for(j = 0; j < i; j++) { - if(table[j].mymoney <= 0) + for (j = 0; j < i; j++) { + if (table[j].mymoney <= 0) continue; ya = bingo(table[j].mybet); - if(ya == 0) { - /*sprintf(data, "%-15s 輸了 %-8d $", cuser.userid, - table[j].mymoney); - fprintf(lostfp, "%s\n", data);*/ + if (ya == 0) { + /* + * sprintf(data, "%-15s 輸了 %-8d $", cuser.userid, + * table[j].mymoney); fprintf(lostfp, "%s\n", data); + */ continue; } demoney(table[j].mymoney * ya + table[j].mymoney); total += table[j].mymoney * ya; - if (table[j].mymoney * ya > 500){ /* 超過500塊錢才做log 減少io */ - sprintf(data, "%-15s 押%-2d選項%-8d塊錢 中了%d倍 淨賺:%-8d\n", - cuser.userid,table[j].mybet, - table[j].mymoney, ya, table[j].mymoney * ya); - fputs(data,winfp); + if (table[j].mymoney * ya > 500) { /* 超過500塊錢才做log 減少io */ + sprintf(data, "%-15s 押%-2d選項%-8d塊錢 中了%d倍 淨賺:%-8d\n", + cuser.userid, table[j].mybet, + table[j].mymoney, ya, table[j].mymoney * ya); + fputs(data, winfp); } ya = 0; } - if(total > 0) { - move(21,0); + if (total > 0) { + move(21, 0); prints("\033[1;32m你贏了 \033[1;31m%d\033[1;32m Ptt$ 唷~~" " \033[m", total); } else { - move(21,0); + move(21, 0); clrtoeol(); prints("\033[1;32m真可惜 下次再來碰碰運氣吧\033[m"); } - - move(19,0); + + move(19, 0); clrtoeol(); prints("\033[1;32m你現在有 \033[1;31m%u\033[1;32m Ptt$歐\033[m", cuser.money); - + getdata(23, 0, "\033[1;32m繼續奮鬥[\033[1;37my/n\033[1;32m]\033[m: ", input, 2, LCECHO); - } while(input[0] != 'n' && input[0] != 'N'); + } while (input[0] != 'n' && input[0] != 'N'); fclose(winfp); - /*fclose(lostfp);*/ + /* fclose(lostfp); */ unlockutmpmode(); return 0; } diff --git a/pttbbs/mbbsd/edit.c b/pttbbs/mbbsd/edit.c index b9dc41ba..c210ba8f 100644 --- a/pttbbs/mbbsd/edit.c +++ b/pttbbs/mbbsd/edit.c @@ -1,15 +1,15 @@ -/* $Id: edit.c,v 1.11 2002/06/04 13:08:33 in2 Exp $ */ +/* $Id: edit.c,v 1.12 2002/07/05 17:10:27 in2 Exp $ */ #include "bbs.h" typedef struct textline_t { struct textline_t *prev; struct textline_t *next; - int len; - char data[WRAPMARGIN + 1]; -} textline_t; + int len; + char data[WRAPMARGIN + 1]; +} textline_t; #define KEEP_EDITING -2 #define BACKUP_LIMIT 100 -#define SCR_WIDTH 80 +#define SCR_WIDTH 80 enum { NOBODY, MANAGER, SYSOP @@ -22,46 +22,50 @@ static textline_t *blockline = NULL; static textline_t *top_of_win = NULL; static textline_t *deleted_lines = NULL; -static char line[WRAPMARGIN + 2]; -static int ifuseanony=0; -static int currpnt, currln, totaln; -static int curr_window_line; -static int redraw_everything; -static int insert_character; -static int my_ansimode; -static int raw_mode; -static int edit_margin; -static int blockln = -1; -static int blockpnt; -static int prevln = -1; -static int prevpnt; -static int line_dirty; -static int indent_mode; -static int insert_c = ' '; - -static char fp_bak[] = "bak"; +static char line[WRAPMARGIN + 2]; +static int ifuseanony = 0; +static int currpnt, currln, totaln; +static int curr_window_line; +static int redraw_everything; +static int insert_character; +static int my_ansimode; +static int raw_mode; +static int edit_margin; +static int blockln = -1; +static int blockpnt; +static int prevln = -1; +static int prevpnt; +static int line_dirty; +static int indent_mode; +static int insert_c = ' '; + +static char fp_bak[] = "bak"; /* 記憶體管理與編輯處理 */ -static void indigestion(i) { +static void +indigestion(i) +{ fprintf(stderr, "嚴重內傷 %d\n", i); } /* Thor: ansi 座標轉換 for color 編輯模式 */ -static int ansi2n(int ansix, textline_t * line) { - register char *data, *tmp; - register char ch; - +static int +ansi2n(int ansix, textline_t * line) +{ + register char *data, *tmp; + register char ch; + data = tmp = line->data; - - while(*tmp) { - if(*tmp == KEY_ESC) { - while((ch = *tmp) && !isalpha(ch)) + + while (*tmp) { + if (*tmp == KEY_ESC) { + while ((ch = *tmp) && !isalpha(ch)) tmp++; - if(ch) + if (ch) tmp++; continue; } - if(ansix <= 0) + if (ansix <= 0) break; tmp++; ansix--; @@ -69,23 +73,25 @@ static int ansi2n(int ansix, textline_t * line) { return tmp - data; } -static int n2ansi(int nx, textline_t * line) { - register int ansix = 0; - register char *tmp,*nxp; - register char ch; - +static int +n2ansi(int nx, textline_t * line) +{ + register int ansix = 0; + register char *tmp, *nxp; + register char ch; + tmp = nxp = line->data; nxp += nx; - - while(*tmp) { - if(*tmp == KEY_ESC) { - while((ch = *tmp) && !isalpha(ch)) + + while (*tmp) { + if (*tmp == KEY_ESC) { + while ((ch = *tmp) && !isalpha(ch)) tmp++; - if(ch) + if (ch) tmp++; continue; } - if(tmp >= nxp) + if (tmp >= nxp) break; tmp++; ansix++; @@ -94,11 +100,13 @@ static int n2ansi(int nx, textline_t * line) { } /* 螢幕處理:輔助訊息、顯示編輯內容 */ -static void edit_msg() { - static char *edit_mode[2] = {"取代", "插入"}; - register int n = currpnt; - - if(my_ansimode) /* Thor: 作 ansi 編輯 */ +static void +edit_msg() +{ + static char *edit_mode[2] = {"取代", "插入"}; + register int n = currpnt; + + if (my_ansimode) /* Thor: 作 ansi 編輯 */ n = n2ansi(n, currline); n++; move(b_lines, 0); @@ -109,15 +117,17 @@ static void edit_msg() { "37;44", edit_mode[insert_character], my_ansimode ? 'A' : 'a', indent_mode ? 'I' : 'i', - 'P' , raw_mode ? 'R' : 'r', + 'P', raw_mode ? 'R' : 'r', currln + 1, n); } -static textline_t *back_line(textline_t *pos, int num) { - while(num-- > 0) { +static textline_t * +back_line(textline_t * pos, int num) +{ + while (num-- > 0) { register textline_t *item; - - if(pos && (item = pos->prev)) { + + if (pos && (item = pos->prev)) { pos = item; currln--; } @@ -125,11 +135,13 @@ static textline_t *back_line(textline_t *pos, int num) { return pos; } -static textline_t *forward_line(textline_t *pos, int num) { - while(num-- > 0) { +static textline_t * +forward_line(textline_t * pos, int num) +{ + while (num-- > 0) { register textline_t *item; - if(pos && (item = pos->next)) { + if (pos && (item = pos->next)) { pos = item; currln++; } @@ -137,41 +149,48 @@ static textline_t *forward_line(textline_t *pos, int num) { return pos; } -static int getlineno() { - int cnt = 0; - textline_t *p = currline; +static int +getlineno() +{ + int cnt = 0; + textline_t *p = currline; - while(p && (p != top_of_win)) { + while (p && (p != top_of_win)) { cnt++; p = p->prev; } return cnt; } -static char *killsp(char *s) { - while(*s == ' ') +static char * +killsp(char *s) +{ + while (*s == ' ') s++; return s; } -static textline_t *alloc_line() { +static textline_t * +alloc_line() +{ register textline_t *p; - - if((p = (textline_t *)malloc(sizeof(textline_t)))) { + + if ((p = (textline_t *) malloc(sizeof(textline_t)))) { memset(p, 0, sizeof(textline_t)); return p; } - indigestion(13); abort_bbs(0); return NULL; } /* append p after line in list. keeps up with last line */ -static void append(textline_t *p, textline_t *line) { +static void +append(textline_t * p, textline_t * line) +{ register textline_t *n; - - if((p->next = n = line->next)) + + if ((p->next = n = line->next)) n->prev = p; else lastline = p; @@ -180,23 +199,25 @@ static void append(textline_t *p, textline_t *line) { } /* - delete_line deletes 'line' from the list, - and maintains the lastline, and firstline pointers. -*/ + * delete_line deletes 'line' from the list, and maintains the lastline, and + * firstline pointers. + */ -static void delete_line(textline_t *line) { +static void +delete_line(textline_t * line) +{ register textline_t *p = line->prev; register textline_t *n = line->next; - - if(!p && !n) { + + if (!p && !n) { line->data[0] = line->len = 0; return; } - if(n) + if (n) n->prev = p; else lastline = p; - if(p) + if (p) p->next = n; else firstline = n; @@ -206,29 +227,33 @@ static void delete_line(textline_t *line) { totaln--; } -static int ask(char *prompt) { - int ch; - - move (0, 0); - clrtoeol (); - standout (); - prints ("%s", prompt); - standend (); - ch = igetkey (); - move (0, 0); - clrtoeol (); +static int +ask(char *prompt) +{ + int ch; + + move(0, 0); + clrtoeol(); + standout(); + prints("%s", prompt); + standend(); + ch = igetkey(); + move(0, 0); + clrtoeol(); return (ch); } -static int indent_spcs() { - textline_t* p; - int spcs; - - if(!indent_mode) +static int +indent_spcs() +{ + textline_t *p; + int spcs; + + if (!indent_mode) return 0; - - for(p = currline; p; p = p->prev) { - for(spcs = 0; p->data[spcs] == ' '; ++spcs); + + for (p = currline; p; p = p->prev) { + for (spcs = 0; p->data[spcs] == ' '; ++spcs); if (p->data[spcs]) return spcs; } @@ -236,25 +261,27 @@ static int indent_spcs() { } /* split 'line' right before the character pos */ -static void split(textline_t *line, int pos) { - if(pos <= line->len) { +static void +split(textline_t * line, int pos) +{ + if (pos <= line->len) { register textline_t *p = alloc_line(); - register char *ptr; - int spcs = indent_spcs(); - + register char *ptr; + int spcs = indent_spcs(); + totaln++; - + p->len = line->len - pos + spcs; line->len = pos; - + memset(p->data, ' ', spcs); p->data[spcs] = 0; strcat(p->data, (ptr = line->data + pos)); ptr[0] = '\0'; append(p, line); - if(line == currline && pos <= currpnt) { + if (line == currline && pos <= currpnt) { currline = p; - if(pos == currpnt) + if (pos == currpnt) currpnt = spcs; else currpnt -= pos; @@ -265,45 +292,47 @@ static void split(textline_t *line, int pos) { } } -static void insert_char(int ch) { +static void +insert_char(int ch) +{ register textline_t *p = currline; - register int i = p->len; - register char *s; - int wordwrap = YEA; - - if(currpnt > i) { + register int i = p->len; + register char *s; + int wordwrap = YEA; + + if (currpnt > i) { indigestion(1); return; } - if(currpnt < i && !insert_character) { + if (currpnt < i && !insert_character) { p->data[currpnt++] = ch; /* Thor: ansi 編輯, 可以overwrite, 不蓋到 ansi code */ - if(my_ansimode) - currpnt = ansi2n(n2ansi(currpnt, p),p); + if (my_ansimode) + currpnt = ansi2n(n2ansi(currpnt, p), p); } else { - while(i >= currpnt) { + while (i >= currpnt) { p->data[i + 1] = p->data[i]; i--; } p->data[currpnt++] = ch; i = ++(p->len); } - if(i < WRAPMARGIN) + if (i < WRAPMARGIN) return; s = p->data + (i - 1); - while(s != p->data && *s == ' ') + while (s != p->data && *s == ' ') s--; - while(s != p->data && *s != ' ') + while (s != p->data && *s != ' ') s--; - if(s == p->data) { + if (s == p->data) { wordwrap = NA; s = p->data + (i - 2); } split(p, (s - p->data) + 1); p = p->next; i = p->len; - if(wordwrap && i >= 1) { - if(p->data[i - 1] != ' ') { + if (wordwrap && i >= 1) { + if (p->data[i - 1] != ' ') { p->data[i] = ' '; p->data[i + 1] = '\0'; p->len++; @@ -311,39 +340,43 @@ static void insert_char(int ch) { } } -static void insert_string(char *str) { - int ch; - - while((ch = *str++)) { - if(isprint2(ch) || ch == '\033') +static void +insert_string(char *str) +{ + int ch; + + while ((ch = *str++)) { + if (isprint2(ch) || ch == '\033') insert_char(ch); - else if(ch == '\t') { + else if (ch == '\t') { do { insert_char(' '); - } while(currpnt & 0x7); - } else if(ch == '\n') + } while (currpnt & 0x7); + } else if (ch == '\n') split(currline, currpnt); } } -static int undelete_line() { - textline_t* p = deleted_lines; - textline_t* currline0 = currline; - textline_t* top_of_win0 = top_of_win; - int currpnt0 = currpnt; - int currln0 = currln; - int curr_window_line0 = curr_window_line; - int indent_mode0 = indent_mode; - - if(!deleted_lines) +static int +undelete_line() +{ + textline_t *p = deleted_lines; + textline_t *currline0 = currline; + textline_t *top_of_win0 = top_of_win; + int currpnt0 = currpnt; + int currln0 = currln; + int curr_window_line0 = curr_window_line; + int indent_mode0 = indent_mode; + + if (!deleted_lines) return 0; - + indent_mode = 0; insert_string(deleted_lines->data); indent_mode = indent_mode0; deleted_lines = deleted_lines->prev; free(p); - + currline = currline0; top_of_win = top_of_win0; currpnt = currpnt0; @@ -353,48 +386,47 @@ static int undelete_line() { } /* - 1) lines were joined and one was deleted - 2) lines could not be joined - 3) next line is empty - returns false if: - 1) Some of the joined line wrapped -*/ -static int join(textline_t *line) { + * 1) lines were joined and one was deleted 2) lines could not be joined 3) + * next line is empty returns false if: 1) Some of the joined line wrapped + */ +static int +join(textline_t * line) +{ register textline_t *n; - register int ovfl; - - if(!(n = line->next)) + register int ovfl; + + if (!(n = line->next)) return YEA; - if(!*killsp(n->data)) + if (!*killsp(n->data)) return YEA; - + ovfl = line->len + n->len - WRAPMARGIN; - if(ovfl < 0) { + if (ovfl < 0) { strcat(line->data, n->data); line->len += n->len; delete_line(n); return YEA; } else { - register char *s; - + register char *s; + s = n->data + n->len - ovfl - 1; - while(s != n->data && *s == ' ') + while (s != n->data && *s == ' ') s--; - while(s != n->data && *s != ' ') + while (s != n->data && *s != ' ') s--; - if(s == n->data) + if (s == n->data) return YEA; split(n, (s - n->data) + 1); - if(line->len + n->len >= WRAPMARGIN) { + if (line->len + n->len >= WRAPMARGIN) { indigestion(0); return YEA; } join(line); n = line->next; ovfl = n->len - 1; - if(ovfl >= 0 && ovfl < WRAPMARGIN - 2) { + if (ovfl >= 0 && ovfl < WRAPMARGIN - 2) { s = &(n->data[ovfl]); - if(*s != ' ') { + if (*s != ' ') { strcpy(s, " "); n->len++; } @@ -403,122 +435,135 @@ static int join(textline_t *line) { } } -static void delete_char() { - register int len; - - if((len = currline->len)) { - register int i; - register char *s; - - if(currpnt >= len) { +static void +delete_char() +{ + register int len; + + if ((len = currline->len)) { + register int i; + register char *s; + + if (currpnt >= len) { indigestion(1); return; } - for(i = currpnt, s = currline->data + i; i != len; i++, s++) + for (i = currpnt, s = currline->data + i; i != len; i++, s++) s[0] = s[1]; currline->len--; } } -static void load_file(FILE *fp) { - int indent_mode0 = indent_mode; +static void +load_file(FILE * fp) +{ + int indent_mode0 = indent_mode; indent_mode = 0; - while(fgets(line, WRAPMARGIN + 2, fp)) + while (fgets(line, WRAPMARGIN + 2, fp)) insert_string(line); fclose(fp); indent_mode = indent_mode0; } /* 暫存檔 */ -char *ask_tmpbuf(int y) { - static char fp_buf[10] = "buf.0"; - static char msg[] = "請選擇暫存檔 (0-9)[0]: "; - +char * +ask_tmpbuf(int y) +{ + static char fp_buf[10] = "buf.0"; + static char msg[] = "請選擇暫存檔 (0-9)[0]: "; + msg[19] = fp_buf[4]; do { - if(!getdata(y, 0, msg, fp_buf + 4, 4, DOECHO)) + if (!getdata(y, 0, msg, fp_buf + 4, 4, DOECHO)) fp_buf[4] = msg[19]; - } while(fp_buf[4] < '0' || fp_buf[4] > '9'); + } while (fp_buf[4] < '0' || fp_buf[4] > '9'); return fp_buf; } -static void read_tmpbuf(int n) { - FILE *fp; - char fp_tmpbuf[80]; - char tmpfname[] = "buf.0"; - char *tmpf; - char ans[4] = "y"; - - if(0 <= n && n <= 9) { +static void +read_tmpbuf(int n) +{ + FILE *fp; + char fp_tmpbuf[80]; + char tmpfname[] = "buf.0"; + char *tmpf; + char ans[4] = "y"; + + if (0 <= n && n <= 9) { tmpfname[4] = '0' + n; tmpf = tmpfname; } else { tmpf = ask_tmpbuf(3); n = tmpf[4] - '0'; } - + setuserfile(fp_tmpbuf, tmpf); - if(n != 0 && n != 5 && more(fp_tmpbuf, NA) != -1) + if (n != 0 && n != 5 && more(fp_tmpbuf, NA) != -1) getdata(b_lines - 1, 0, "確定讀入嗎(Y/N)?[Y]", ans, sizeof(ans), LCECHO); - if(*ans != 'n' && (fp = fopen(fp_tmpbuf, "r"))) { + if (*ans != 'n' && (fp = fopen(fp_tmpbuf, "r"))) { prevln = currln; prevpnt = currpnt; load_file(fp); - while(curr_window_line >= b_lines) { + while (curr_window_line >= b_lines) { curr_window_line--; top_of_win = top_of_win->next; } } } -static void write_tmpbuf() { - FILE *fp; - char fp_tmpbuf[80], ans[4]; - textline_t *p; +static void +write_tmpbuf() +{ + FILE *fp; + char fp_tmpbuf[80], ans[4]; + textline_t *p; setuserfile(fp_tmpbuf, ask_tmpbuf(3)); - if(dashf(fp_tmpbuf)) { + if (dashf(fp_tmpbuf)) { more(fp_tmpbuf, NA); getdata(b_lines - 1, 0, "暫存檔已有資料 (A)附加 (W)覆寫 (Q)取消?[A] ", ans, sizeof(ans), LCECHO); - - if(ans[0] == 'q') + + if (ans[0] == 'q') return; } - - if((fp = fopen(fp_tmpbuf, (ans[0] == 'w' ? "w" : "a+")))) { - for(p = firstline; p; p = p->next) { - if(p->next || p->data[0]) + if ((fp = fopen(fp_tmpbuf, (ans[0] == 'w' ? "w" : "a+")))) { + for (p = firstline; p; p = p->next) { + if (p->next || p->data[0]) fprintf(fp, "%s\n", p->data); } fclose(fp); } } -static void erase_tmpbuf() { - char fp_tmpbuf[80]; - char ans[4] = "n"; - +static void +erase_tmpbuf() +{ + char fp_tmpbuf[80]; + char ans[4] = "n"; + setuserfile(fp_tmpbuf, ask_tmpbuf(3)); - if(more(fp_tmpbuf, NA) != -1) + if (more(fp_tmpbuf, NA) != -1) getdata(b_lines - 1, 0, "確定刪除嗎(Y/N)?[N]", ans, sizeof(ans), LCECHO); - if(*ans == 'y') + if (*ans == 'y') unlink(fp_tmpbuf); } /* 編輯器自動備份 */ -void auto_backup() { - if(currline) { - FILE *fp; - textline_t *p, *v; - char bakfile[64]; - int count = 0; - +void +auto_backup() +{ + if (currline) { + FILE *fp; + textline_t *p, *v; + char bakfile[64]; + int count = 0; + setuserfile(bakfile, fp_bak); - if((fp = fopen(bakfile, "w"))) { - for(p = firstline; p != NULL && count < 512; p = v,count++) { + if ((fp = fopen(bakfile, "w"))) { + for (p = firstline; p != NULL && count < 512; p = v, count++) { v = p->next; fprintf(fp, "%s\n", p->data); free(p); @@ -529,15 +574,17 @@ void auto_backup() { } } -void restore_backup() { - char bakfile[80], buf[80]; - +void +restore_backup() +{ + char bakfile[80], buf[80]; + setuserfile(bakfile, fp_bak); - if(dashf(bakfile)) { + if (dashf(bakfile)) { stand_title("編輯器自動復原"); getdata(1, 0, "您有一篇文章尚未完成,(S)寫入暫存檔 (Q)算了?[S] ", buf, 4, LCECHO); - if(buf[0] != 'q') { + if (buf[0] != 'q') { setuserfile(buf, ask_tmpbuf(3)); Rename(bakfile, buf); } else @@ -546,87 +593,91 @@ void restore_backup() { } /* 引用文章 */ -static int garbage_line(char *str) { - int qlevel = 0; - - while(*str == ':' || *str == '>') { - if(*(++str) == ' ') +static int +garbage_line(char *str) +{ + int qlevel = 0; + + while (*str == ':' || *str == '>') { + if (*(++str) == ' ') str++; - if(qlevel++ >= 1) + if (qlevel++ >= 1) return 1; } - while(*str == ' ' || *str == '\t') + while (*str == ' ' || *str == '\t') str++; - if(qlevel >= 1) { - if(!strncmp(str, "※ ", 3) || !strncmp(str, "==>", 3) || - strstr(str, ") 提到:\n")) + if (qlevel >= 1) { + if (!strncmp(str, "※ ", 3) || !strncmp(str, "==>", 3) || + strstr(str, ") 提到:\n")) return 1; } return (*str == '\n'); } -static void do_quote() { - int op; - char buf[256]; +static void +do_quote() +{ + int op; + char buf[256]; getdata(b_lines - 1, 0, "請問要引用原文嗎(Y/N/All/Repost)?[Y] ", buf, 3, LCECHO); op = buf[0]; - - if(op != 'n') { - FILE *inf; - - if((inf = fopen(quote_file, "r"))) { - char *ptr; - int indent_mode0 = indent_mode; - + + if (op != 'n') { + FILE *inf; + + if ((inf = fopen(quote_file, "r"))) { + char *ptr; + int indent_mode0 = indent_mode; + fgets(buf, 256, inf); - if((ptr = strrchr(buf, ')'))) + if ((ptr = strrchr(buf, ')'))) ptr[1] = '\0'; - else if((ptr = strrchr(buf, '\n'))) + else if ((ptr = strrchr(buf, '\n'))) ptr[0] = '\0'; - - if((ptr = strchr(buf, ':'))) { - char *str; - - while(*(++ptr) == ' '); + + if ((ptr = strchr(buf, ':'))) { + char *str; + + while (*(++ptr) == ' '); /* 順手牽羊,取得 author's address */ - if((curredit & EDIT_BOTH) && (str = strchr(quote_user, '.'))) { + if ((curredit & EDIT_BOTH) && (str = strchr(quote_user, '.'))) { strcpy(++str, ptr); str = strchr(str, ' '); str[0] = '\0'; } } else ptr = quote_user; - + indent_mode = 0; insert_string("※ 引述《"); insert_string(ptr); insert_string("》之銘言:\n"); - - if(op != 'a') /* 去掉 header */ - while(fgets(buf, 256, inf) && buf[0] != '\n'); - if(op == 'a') - while(fgets(buf, 256, inf)) { + if (op != 'a') /* 去掉 header */ + while (fgets(buf, 256, inf) && buf[0] != '\n'); + + if (op == 'a') + while (fgets(buf, 256, inf)) { insert_char(':'); insert_char(' '); - insert_string(Ptt_prints(buf,STRIP_ALL)); + insert_string(Ptt_prints(buf, STRIP_ALL)); } - else if(op == 'r') - while(fgets(buf, 256, inf)) - insert_string(Ptt_prints(buf,NO_RELOAD)); + else if (op == 'r') + while (fgets(buf, 256, inf)) + insert_string(Ptt_prints(buf, NO_RELOAD)); else { - if(curredit & EDIT_LIST) /* 去掉 mail list 之 header */ + if (curredit & EDIT_LIST) /* 去掉 mail list 之 header */ while (fgets(buf, 256, inf) && (!strncmp(buf, "※ ", 3))); - while(fgets(buf, 256, inf)) { - if(!strcmp(buf, "--\n")) + while (fgets(buf, 256, inf)) { + if (!strcmp(buf, "--\n")) break; - if(!garbage_line(buf)) { + if (!garbage_line(buf)) { insert_char(':'); insert_char(' '); - insert_string(Ptt_prints(buf,STRIP_ALL)); + insert_string(Ptt_prints(buf, STRIP_ALL)); } } } @@ -637,37 +688,39 @@ static void do_quote() { } /* 審查 user 引言的使用 */ -static int check_quote() { +static int +check_quote() +{ register textline_t *p = firstline; - register char *str; - int post_line; - int included_line; - + register char *str; + int post_line; + int included_line; + post_line = included_line = 0; - while(p) { - if(!strcmp(str = p->data, "--")) + while (p) { + if (!strcmp(str = p->data, "--")) break; - if(str[1] == ' ' && ((str[0] == ':') || (str[0] == '>'))) + if (str[1] == ' ' && ((str[0] == ':') || (str[0] == '>'))) included_line++; else { - while(*str == ' ' || *str == '\t') + while (*str == ' ' || *str == '\t') str++; - if(*str) + if (*str) post_line++; } p = p->next; } - - if((included_line >> 2) > post_line) { + + if ((included_line >> 2) > post_line) { move(4, 0); outs("本篇文章的引言比例超過 80%,請您做些微的修正:\n\n" "\033[1;33m1) 增加一些文章 或 2) 刪除不必要之引言\033[m"); { - char ans[4]; - + char ans[4]; + getdata(12, 12, "(E)繼續編輯 (W)強制寫入?[E] ", ans, sizeof(ans), LCECHO); - if(ans[0] == 'w') + if (ans[0] == 'w') return 0; } return 1; @@ -676,11 +729,13 @@ static int check_quote() { } /* 檔案處理:讀檔、存檔、標題、簽名檔 */ -static void read_file(char *fpath) { - FILE *fp; - - if((fp = fopen(fpath, "r")) == NULL) { - if((fp = fopen(fpath, "w+"))) { +static void +read_file(char *fpath) +{ + FILE *fp; + + if ((fp = fopen(fpath, "r")) == NULL) { + if ((fp = fopen(fpath, "w+"))) { fclose(fp); return; } @@ -690,67 +745,69 @@ static void read_file(char *fpath) { load_file(fp); } -void write_header(FILE *fp) { +void +write_header(FILE * fp) +{ - if(curredit & EDIT_MAIL || curredit & EDIT_LIST) { + if (curredit & EDIT_MAIL || curredit & EDIT_LIST) { fprintf(fp, "%s %s (%s)\n", str_author1, cuser.userid, #if defined(REALINFO) && defined(MAIL_REALNAMES) cuser.realname #else cuser.username #endif - ); + ); } else { - char *ptr; + char *ptr; struct { - char author[IDLEN + 1]; - char board[IDLEN + 1]; - char title[66]; - time_t date; /* last post's date */ - int number; /* post number */ - } postlog; - + char author[IDLEN + 1]; + char board[IDLEN + 1]; + char title[66]; + time_t date; /* last post's date */ + int number; /* post number */ + } postlog; + strcpy(postlog.author, cuser.userid); - ifuseanony=0; + ifuseanony = 0; #ifdef HAVE_ANONYMOUS - if(currbrdattr& BRD_ANONYMOUS) { - int defanony = (currbrdattr & BRD_DEFAULTANONYMOUS); - if(defanony) + if (currbrdattr & BRD_ANONYMOUS) { + int defanony = (currbrdattr & BRD_DEFAULTANONYMOUS); + if (defanony) getdata(3, 0, "請輸入你想用的ID,也可直接按[Enter]," - "或是按[r]用真名:", real_name, sizeof(real_name), DOECHO); + "或是按[r]用真名:", real_name, sizeof(real_name), DOECHO); else getdata(3, 0, "請輸入你想用的ID,也可直接按[Enter]使用原ID:", real_name, sizeof(real_name), DOECHO); - if(!real_name[0] && defanony) { + if (!real_name[0] && defanony) { strcpy(real_name, "Anonymous"); strcpy(postlog.author, real_name); ifuseanony = 1; } else { - if(!strcmp("r",real_name) || (!defanony && !real_name[0])) - sprintf(postlog.author,"%s",cuser.userid); + if (!strcmp("r", real_name) || (!defanony && !real_name[0])) + sprintf(postlog.author, "%s", cuser.userid); else { - sprintf(postlog.author,"%s.",real_name); - ifuseanony=1; + sprintf(postlog.author, "%s.", real_name); + ifuseanony = 1; } } } #endif strcpy(postlog.board, currboard); ptr = save_title; - if(!strncmp(ptr, str_reply, 4)) + if (!strncmp(ptr, str_reply, 4)) ptr += 4; strncpy(postlog.title, ptr, 65); postlog.date = now; postlog.number = 1; - append_record(".post", (fileheader_t *)&postlog, sizeof(postlog)); + append_record(".post", (fileheader_t *) & postlog, sizeof(postlog)); #ifdef HAVE_ANONYMOUS - if(currbrdattr & BRD_ANONYMOUS) { - int defanony = (currbrdattr & BRD_DEFAULTANONYMOUS); - - fprintf(fp, "%s %s (%s) %s %s\n", str_author1, postlog.author , - (((!strcmp(real_name,"r") && defanony) || + if (currbrdattr & BRD_ANONYMOUS) { + int defanony = (currbrdattr & BRD_DEFAULTANONYMOUS); + + fprintf(fp, "%s %s (%s) %s %s\n", str_author1, postlog.author, + (((!strcmp(real_name, "r") && defanony) || (!real_name[0] && (!defanony))) ? cuser.username : - "猜猜我是誰 ? ^o^"), + "猜猜我是誰 ? ^o^"), local_article ? str_post2 : str_post1, currboard); } else { fprintf(fp, "%s %s (%s) %s %s\n", str_author1, cuser.userid, @@ -761,7 +818,7 @@ void write_header(FILE *fp) { #endif local_article ? str_post2 : str_post1, currboard); } -#else /* HAVE_ANONYMOUS */ +#else /* HAVE_ANONYMOUS */ fprintf(fp, "%s %s (%s) %s %s\n", str_author1, cuser.userid, #if defined(REALINFO) && defined(POSTS_REALNAMES) cuser.realname, @@ -769,43 +826,44 @@ void write_header(FILE *fp) { cuser.username, #endif local_article ? str_post2 : str_post1, currboard); -#endif /* HAVE_ANONYMOUS */ +#endif /* HAVE_ANONYMOUS */ } save_title[72] = '\0'; fprintf(fp, "標題: %s\n時間: %s\n", save_title, ctime(&now)); } -void addsignature(FILE *fp, int ifuseanony) { - FILE *fs; - int i; - char buf[WRAPMARGIN + 1]; - char fpath[STRLEN]; +void +addsignature(FILE * fp, int ifuseanony) +{ + FILE *fs; + int i; + char buf[WRAPMARGIN + 1]; + char fpath[STRLEN]; - static char msg[] = "請選擇簽名檔 (1-9, 0=不加)[0]: "; - char ch; + static char msg[] = "請選擇簽名檔 (1-9, 0=不加)[0]: "; + char ch; - if(!strcmp(cuser.userid,STR_GUEST)) { + if (!strcmp(cuser.userid, STR_GUEST)) { fprintf(fp, "\n--\n※ 發信站 :" BBSNAME "(" MYHOSTNAME ") \n◆ From: %s\n", fromhost); return; } - if(!ifuseanony) { + if (!ifuseanony) { i = showsignature(fpath); msg[27] = ch = '0' | (cuser.uflag & SIG_FLAG); getdata(0, 0, msg, buf, 4, DOECHO); - - if(ch != buf[0] && buf[0] >= '0' && buf[0] <= '9') { + + if (ch != buf[0] && buf[0] >= '0' && buf[0] <= '9') { ch = buf[0]; cuser.uflag = (cuser.uflag & ~SIG_FLAG) | (ch & SIG_FLAG); } - - if(ch != '0') { + if (ch != '0') { fpath[i] = ch; - if((fs = fopen(fpath, "r"))) { + if ((fs = fopen(fpath, "r"))) { fputs("\n--\n", fp); - for(i = 0; i < MAX_SIGLINES && - fgets(buf, sizeof(buf), fs); i++) + for (i = 0; i < MAX_SIGLINES && + fgets(buf, sizeof(buf), fs); i++) fputs(buf, fp); fclose(fs); } @@ -813,19 +871,19 @@ void addsignature(FILE *fp, int ifuseanony) { } #ifdef HAVE_ORIGIN #ifdef HAVE_ANONYMOUS - if(ifuseanony) + if (ifuseanony) fprintf(fp, "\n--\n※ 發信站: " BBSNAME "(" MYHOSTNAME ") \n◆ From: %s\n", "暱名天使的家"); else { - char temp[33]; - + char temp[33]; + strncpy(temp, fromhost, 31); temp[32] = '\0'; fprintf(fp, "\n--\n※ 發信站: " BBSNAME "(" MYHOSTNAME ") \n◆ From: %s\n", temp); } #else - strncpy (temp,fromhost,15); + strncpy(temp, fromhost, 15); fprintf(fp, "\n--\n※ 發信站: " BBSNAME "(" MYHOSTNAME ") \n◆ From: %s\n", temp); #endif @@ -833,30 +891,31 @@ void addsignature(FILE *fp, int ifuseanony) { } static int -write_file(char *fpath, int saveheader, int *islocal) { - struct tm *ptime; - FILE *fp = NULL; - textline_t *p, *v; - char ans[TTLEN], *msg; - int aborted = 0, line = 0, checksum[3], sum = 0, po = 1; +write_file(char *fpath, int saveheader, int *islocal) +{ + struct tm *ptime; + FILE *fp = NULL; + textline_t *p, *v; + char ans[TTLEN], *msg; + int aborted = 0, line = 0, checksum[3], sum = 0, po = 1; stand_title("檔案處理"); - if(currstat == SMAIL) + if (currstat == SMAIL) msg = "[S]儲存 (A)放棄 (T)改標題 (E)繼續 (R/W/D)讀寫刪暫存檔?"; - else if(local_article) + else if (local_article) msg = "[L]站內信件 (S)儲存 (A)放棄 (T)改標題 (E)繼續 " "(R/W/D)讀寫刪暫存檔?"; else msg = "[S]儲存 (L)站內信件 (A)放棄 (T)改標題 (E)繼續 " "(R/W/D)讀寫刪暫存檔?"; getdata(1, 0, msg, ans, 2, LCECHO); - - switch(ans[0]) { + + switch (ans[0]) { case 'a': outs("文章\033[1m 沒有 \033[m存入"); safe_sleep(1); aborted = -1; - break; + break; case 'r': read_tmpbuf(-1); case 'e': @@ -870,12 +929,12 @@ write_file(char *fpath, int saveheader, int *islocal) { case 't': move(3, 0); prints("舊標題:%s", save_title); - strcpy(ans,save_title); - if(getdata_buf(4, 0, "新標題:", ans, sizeof(ans), DOECHO)) + strcpy(ans, save_title); + if (getdata_buf(4, 0, "新標題:", ans, sizeof(ans), DOECHO)) strcpy(save_title, ans); return KEEP_EDITING; case 's': - if(!HAS_PERM(PERM_LOGINOK)) { + if (!HAS_PERM(PERM_LOGINOK)) { local_article = 1; move(2, 0); prints("您尚未通過身份確認,只能 Local Save。\n"); @@ -887,93 +946,87 @@ write_file(char *fpath, int saveheader, int *islocal) { local_article = 1; } - if(!aborted) { - if(saveheader && !(curredit & EDIT_MAIL) && check_quote()) + if (!aborted) { + if (saveheader && !(curredit & EDIT_MAIL) && check_quote()) return KEEP_EDITING; - - if(!*fpath) { + + if (!*fpath) { sethomepath(fpath, cuser.userid); strcpy(fpath, tempnam(fpath, "ve_")); } - - if((fp = fopen(fpath, "w")) == NULL) { + if ((fp = fopen(fpath, "w")) == NULL) { indigestion(5); abort_bbs(0); } - if(saveheader) + if (saveheader) write_header(fp); } - - for(p = firstline; p; p = v) { + for (p = firstline; p; p = v) { v = p->next; - if(!aborted) { + if (!aborted) { msg = p->data; - if(v || msg[0]) { + if (v || msg[0]) { trim(msg); - + line++; - if(currstat == POSTING && po) { + if (currstat == POSTING && po) { saveheader = str_checksum(msg); - if(saveheader) { - if(postrecord.checksum[po] == saveheader) { + if (saveheader) { + if (postrecord.checksum[po] == saveheader) { po++; - if(po > 3) { + if (po > 3) { postrecord.times++; - po =0; + po = 0; } } else po = 1; - if(currstat == POSTING && line >= totaln/2 && - sum < 3) { + if (currstat == POSTING && line >= totaln / 2 && + sum < 3) { checksum[sum++] = saveheader; } } } #ifdef SUPPORT_GB - if(current_font_type == TYPE_GB) - { - fprintf(fp, "%s\n", hc_convert_str(msg, HC_GBtoBIG, HC_DO_SINGLE)); - } - else + if (current_font_type == TYPE_GB) { + fprintf(fp, "%s\n", hc_convert_str(msg, HC_GBtoBIG, HC_DO_SINGLE)); + } else #endif - fprintf(fp, "%s\n", msg); + fprintf(fp, "%s\n", msg); } } free(p); } currline = NULL; - - if(postrecord.times > MAX_CROSSNUM - 1) + + if (postrecord.times > MAX_CROSSNUM - 1) anticrosspost(); - - if(po && sum == 3) { + + if (po && sum == 3) { memcpy(&postrecord.checksum[1], checksum, sizeof(int) * 3); - postrecord.times =0; + postrecord.times = 0; } - if(!aborted) { - if(islocal) + if (!aborted) { + if (islocal) *islocal = (local_article == 1); - if(currstat == POSTING || currstat == SMAIL) - addsignature(fp,ifuseanony); - else if(currstat == REEDIT + if (currstat == POSTING || currstat == SMAIL) + addsignature(fp, ifuseanony); + else if (currstat == REEDIT #ifndef ALL_REEDIT_LOG - && strcmp(currboard, "SYSOP") == 0 + && strcmp(currboard, "SYSOP") == 0 #endif - ) - { + ) { ptime = localtime(&now); - fprintf(fp, - "※ 編輯: %-15s 來自: %-20s (%02d/%02d %02d:%02d)\n", - cuser.userid, fromhost, - ptime->tm_mon+1,ptime->tm_mday,ptime->tm_hour,ptime->tm_min); - } - + fprintf(fp, + "※ 編輯: %-15s 來自: %-20s (%02d/%02d %02d:%02d)\n", + cuser.userid, fromhost, + ptime->tm_mon + 1, ptime->tm_mday, ptime->tm_hour, ptime->tm_min); + } fclose(fp); #ifdef MDCACHE close(updatemdcache(NULL, fpath)); #endif - if(local_article && (currstat == POSTING)) + if (local_article && (currstat == POSTING)) return 0; return 0; } @@ -981,14 +1034,16 @@ write_file(char *fpath, int saveheader, int *islocal) { } -static void display_buffer() { +static void +display_buffer() +{ register textline_t *p; - register int i; - int inblock; - char buf[WRAPMARGIN + 2]; - int min, max; - - if(currpnt > blockpnt) { + register int i; + int inblock; + char buf[WRAPMARGIN + 2]; + int min, max; + + if (currpnt > blockpnt) { min = blockpnt; max = currpnt; } else { @@ -996,21 +1051,21 @@ static void display_buffer() { max = blockpnt; } - for(p = top_of_win, i = 0; i < b_lines; i++) { + for (p = top_of_win, i = 0; i < b_lines; i++) { move(i, 0); clrtoeol(); - if(blockln >= 0 && - ((blockln <= currln && blockln <= (currln - curr_window_line + i) && - (currln - curr_window_line + i) <= currln) || - (currln <= (currln - curr_window_line + i) && - (currln - curr_window_line + i) <= blockln))) { + if (blockln >= 0 && + ((blockln <= currln && blockln <= (currln - curr_window_line + i) && + (currln - curr_window_line + i) <= currln) || + (currln <= (currln - curr_window_line + i) && + (currln - curr_window_line + i) <= blockln))) { outs("\033[7m"); inblock = 1; } else inblock = 0; - if(p) { - if(my_ansimode) - if(currln == blockln && p == currline && max > min) { + if (p) { + if (my_ansimode) + if (currln == blockln && p == currline && max > min) { outs("\033[m"); strncpy(buf, p->data, min); buf[min] = 0; @@ -1023,21 +1078,21 @@ static void display_buffer() { outs(p->data + max); } else outs(p->data); - else if(currln == blockln && p == currline && max > min) { + else if (currln == blockln && p == currline && max > min) { outs("\033[m"); - strncpy(buf, p->data, min); - buf[min] = 0; - edit_outs(buf); - outs("\033[7m"); - strncpy(buf, p->data + min, max - min); - buf[max - min] = 0; - edit_outs(buf); - outs("\033[m"); - edit_outs(p->data + max); - } else - edit_outs(&p->data[edit_margin]); + strncpy(buf, p->data, min); + buf[min] = 0; + edit_outs(buf); + outs("\033[7m"); + strncpy(buf, p->data + min, max - min); + buf[max - min] = 0; + edit_outs(buf); + outs("\033[m"); + edit_outs(p->data + max); + } else + edit_outs(&p->data[edit_margin]); p = p->next; - if(inblock) + if (inblock) outs("\033[m"); } else outch('~'); @@ -1045,51 +1100,55 @@ static void display_buffer() { edit_msg(); } -static void goto_line(int lino) { - char buf[10]; - - if(lino > 0 || - (getdata(b_lines - 1, 0, "跳至第幾行:", buf, sizeof(buf), DOECHO) && - sscanf(buf, "%d", &lino) && lino > 0)) { - textline_t* p; - +static void +goto_line(int lino) +{ + char buf[10]; + + if (lino > 0 || + (getdata(b_lines - 1, 0, "跳至第幾行:", buf, sizeof(buf), DOECHO) && + sscanf(buf, "%d", &lino) && lino > 0)) { + textline_t *p; + prevln = currln; prevpnt = currpnt; p = firstline; currln = lino - 1; - - while(--lino && p->next) + + while (--lino && p->next) p = p->next; - - if(p) + + if (p) currline = p; else { currln = totaln; currline = lastline; } currpnt = 0; - if(currln < 11) { + if (currln < 11) { top_of_win = firstline; curr_window_line = currln; } else { - int i; + int i; curr_window_line = 11; - for(i = curr_window_line; i; i--) + for (i = curr_window_line; i; i--) p = p->prev; - top_of_win = p; + top_of_win = p; } } redraw_everything = YEA; } -char *strcasestr(const char* big, const char* little) { - char* ans = (char*)big; - int len = strlen(little); - char* endptr = (char*)big + strlen(big) - len; - - while(ans <= endptr) - if(!strncasecmp(ans, little, len)) +char * +strcasestr(const char *big, const char *little) +{ + char *ans = (char *)big; + int len = strlen(little); + char *endptr = (char *)big + strlen(big) - len; + + while (ans <= endptr) + if (!strncasecmp(ans, little, len)) return ans; else ans++; @@ -1097,181 +1156,181 @@ char *strcasestr(const char* big, const char* little) { } /* - mode: - 0: prompt - 1: forward - -1: backward -*/ -static void search_str(int mode) { - static char str[65]; - typedef char* (*FPTR)(); - static FPTR fptr; - char ans[4] = "n"; - - if(!mode) { - if(getdata_buf(b_lines - 1, 0,"[搜尋]關鍵字:", - str, sizeof(str), DOECHO)) - if(*str) { - if(getdata(b_lines - 1, 0, "區分大小寫(Y/N/Q)? [N] ", - ans, sizeof(ans), LCECHO) && *ans == 'y') + * mode: 0: prompt 1: forward -1: backward + */ +static void +search_str(int mode) +{ + static char str[65]; + typedef char *(*FPTR) (); + static FPTR fptr; + char ans[4] = "n"; + + if (!mode) { + if (getdata_buf(b_lines - 1, 0, "[搜尋]關鍵字:", + str, sizeof(str), DOECHO)) + if (*str) { + if (getdata(b_lines - 1, 0, "區分大小寫(Y/N/Q)? [N] ", + ans, sizeof(ans), LCECHO) && *ans == 'y') fptr = strstr; else fptr = strcasestr; } } - - if(*str && *ans != 'q') { - textline_t* p; - char *pos = NULL; - int lino; - - if(mode >= 0) { - for(lino = currln, p = currline; p; p = p->next, lino++) - if((pos = fptr(p->data + (lino == currln ? currpnt + 1 : 0), - str)) && (lino != currln || - pos - p->data != currpnt)) + if (*str && *ans != 'q') { + textline_t *p; + char *pos = NULL; + int lino; + + if (mode >= 0) { + for (lino = currln, p = currline; p; p = p->next, lino++) + if ((pos = fptr(p->data + (lino == currln ? currpnt + 1 : 0), + str)) && (lino != currln || + pos - p->data != currpnt)) break; } else { - for(lino = currln, p = currline; p; p = p->prev, lino--) - if((pos = fptr(p->data, str)) && - (lino != currln || pos - p->data != currpnt)) + for (lino = currln, p = currline; p; p = p->prev, lino--) + if ((pos = fptr(p->data, str)) && + (lino != currln || pos - p->data != currpnt)) break; } - if(pos) { + if (pos) { prevln = currln; prevpnt = currpnt; currline = p; currln = lino; currpnt = pos - p->data; - if(lino < 11) { + if (lino < 11) { top_of_win = firstline; curr_window_line = currln; } else { - int i; + int i; curr_window_line = 11; - for(i = curr_window_line; i; i--) + for (i = curr_window_line; i; i--) p = p->prev; top_of_win = p; } redraw_everything = YEA; } } - if(!mode) + if (!mode) redraw_everything = YEA; } -static void match_paren() { - static char parens[] = "()[]{}"; - int type; - int parenum = 0; - char *ptype; - textline_t* p; - int lino; - int c, i = 0; - - if(!(ptype = strchr(parens, currline->data[currpnt]))) +static void +match_paren() +{ + static char parens[] = "()[]{}"; + int type; + int parenum = 0; + char *ptype; + textline_t *p; + int lino; + int c, i = 0; + + if (!(ptype = strchr(parens, currline->data[currpnt]))) return; - + type = (ptype - parens) / 2; parenum += ((ptype - parens) % 2) ? -1 : 1; - - if(parenum > 0) { - for(lino = currln, p = currline; p; p = p->next, lino++) { + + if (parenum > 0) { + for (lino = currln, p = currline; p; p = p->next, lino++) { lino = lino; - for(i = (lino == currln) ? currpnt + 1 : 0; - i < strlen(p->data); i++) - if(p->data[i] == '/' && p->data[++i] == '*') { + for (i = (lino == currln) ? currpnt + 1 : 0; + i < strlen(p->data); i++) + if (p->data[i] == '/' && p->data[++i] == '*') { ++i; - while(1) { - while(i < strlen(p->data) - 1 && - !(p->data[i] == '*' && p->data[i + 1] == '/')) + while (1) { + while (i < strlen(p->data) - 1 && + !(p->data[i] == '*' && p->data[i + 1] == '/')) i++; - if(i >= strlen(p->data) - 1 && p->next) { + if (i >= strlen(p->data) - 1 && p->next) { p = p->next; ++lino; i = 0; } else break; } - } else if((c = p->data[i]) == '\'' || c == '"') { - while(1) { - while(i < (int)(strlen(p->data) - 1)) - if(p->data[++i] == '\\' && i < strlen(p->data) - 2) + } else if ((c = p->data[i]) == '\'' || c == '"') { + while (1) { + while (i < (int)(strlen(p->data) - 1)) + if (p->data[++i] == '\\' && i < strlen(p->data) - 2) ++i; - else if(p->data[i] == c) + else if (p->data[i] == c) goto end_quote; - if(i >= strlen(p->data) - 1 && p->next) { + if (i >= strlen(p->data) - 1 && p->next) { p = p->next; ++lino; i = -1; } else break; } -end_quote: + end_quote: ; - } else if((ptype = strchr(parens, p->data[i])) && - (ptype - parens) / 2 == type) - if(!(parenum += ((ptype - parens) % 2) ? -1 : 1)) + } else if ((ptype = strchr(parens, p->data[i])) && + (ptype - parens) / 2 == type) + if (!(parenum += ((ptype - parens) % 2) ? -1 : 1)) goto p_outscan; } } else { - for(lino = currln, p = currline; p; p = p->prev, lino--) - for(i = (lino == currln) ? currpnt - 1 : strlen(p->data) - 1; + for (lino = currln, p = currline; p; p = p->prev, lino--) + for (i = (lino == currln) ? currpnt - 1 : strlen(p->data) - 1; i >= 0; i--) - if(p->data[i] == '/' && p->data[--i] == '*' && i > 0) { + if (p->data[i] == '/' && p->data[--i] == '*' && i > 0) { --i; - while(1) { - while(i > 0 && - !(p->data[i] == '*' && p->data[i - 1] == '/')) + while (1) { + while (i > 0 && + !(p->data[i] == '*' && p->data[i - 1] == '/')) i--; - if(i <= 0 && p->prev) { + if (i <= 0 && p->prev) { p = p->prev; --lino; i = strlen(p->data) - 1; } else break; } - } else if((c = p->data[i]) == '\'' || c == '"') { - while(1) { - while(i > 0) - if(i > 1 && p->data[i - 2] == '\\') + } else if ((c = p->data[i]) == '\'' || c == '"') { + while (1) { + while (i > 0) + if (i > 1 && p->data[i - 2] == '\\') i -= 2; - else if((p->data[--i]) == c) + else if ((p->data[--i]) == c) goto begin_quote; - if(i <= 0 && p->prev) { + if (i <= 0 && p->prev) { p = p->prev; --lino; i = strlen(p->data); } else break; } -begin_quote: + begin_quote: ; - } else if((ptype = strchr(parens, p->data[i])) && - (ptype - parens) / 2 == type) - if(!(parenum += ((ptype - parens) % 2) ? -1 : 1)) + } else if ((ptype = strchr(parens, p->data[i])) && + (ptype - parens) / 2 == type) + if (!(parenum += ((ptype - parens) % 2) ? -1 : 1)) goto p_outscan; } p_outscan: - if(!parenum) { - int top = currln - curr_window_line; - int bottom = currln - curr_window_line + b_lines - 1; - + if (!parenum) { + int top = currln - curr_window_line; + int bottom = currln - curr_window_line + b_lines - 1; + currpnt = i; currline = p; curr_window_line += lino - currln; currln = lino; - - if(lino < top || lino > bottom) { - if(lino < 11) { + + if (lino < top || lino > bottom) { + if (lino < 11) { top_of_win = firstline; curr_window_line = currln; } else { - int i; + int i; curr_window_line = 11; - for(i = curr_window_line; i; i--) + for (i = curr_window_line; i; i--) p = p->prev; top_of_win = p; } @@ -1280,58 +1339,60 @@ p_outscan: } } -static void block_del(int hide) { - if(blockln < 0) { +static void +block_del(int hide) +{ + if (blockln < 0) { blockln = currln; blockpnt = currpnt; blockline = currline; } else { - char fp_tmpbuf[80]; - FILE* fp; - textline_t *begin, *end, *p; - char tmpfname[10] = "buf.0"; - char ans[6] = "w+n"; + char fp_tmpbuf[80]; + FILE *fp; + textline_t *begin, *end, *p; + char tmpfname[10] = "buf.0"; + char ans[6] = "w+n"; move(b_lines - 1, 0); clrtoeol(); - if(hide == 1) + if (hide == 1) tmpfname[4] = 'q'; - else if(!hide && !getdata(b_lines - 1, 0, "把區塊移至暫存檔 " - "(0:Cut, 5:Copy, 6-9, q: Cancel)[0] ", - tmpfname + 4, 4, LCECHO)) + else if (!hide && !getdata(b_lines - 1, 0, "把區塊移至暫存檔 " + "(0:Cut, 5:Copy, 6-9, q: Cancel)[0] ", + tmpfname + 4, 4, LCECHO)) tmpfname[4] = '0'; - if(tmpfname[4] < '0' || tmpfname[4] > '9') + if (tmpfname[4] < '0' || tmpfname[4] > '9') tmpfname[4] = 'q'; - if('1' <= tmpfname[4] && tmpfname[4] <= '9') { + if ('1' <= tmpfname[4] && tmpfname[4] <= '9') { setuserfile(fp_tmpbuf, tmpfname); - if(tmpfname[4] != '5' && dashf(fp_tmpbuf)) { + if (tmpfname[4] != '5' && dashf(fp_tmpbuf)) { more(fp_tmpbuf, NA); getdata(b_lines - 1, 0, "暫存檔已有資料 (A)附加 (W)覆寫 " "(Q)取消?[W] ", ans, 2, LCECHO); - if(*ans == 'q') + if (*ans == 'q') tmpfname[4] = 'q'; - else if(*ans != 'a') + else if (*ans != 'a') *ans = 'w'; } - if(tmpfname[4] != '5') { + if (tmpfname[4] != '5') { getdata(b_lines - 1, 0, "刪除區塊(Y/N)?[N] ", ans + 2, 4, LCECHO); - if(ans[2] != 'y') + if (ans[2] != 'y') ans[2] = 'n'; } - } else if(hide != 3) + } else if (hide != 3) ans[2] = 'y'; - + tmpfname[5] = ans[1] = ans[3] = 0; - if(tmpfname[4] != 'q') { - if(currln >= blockln) { + if (tmpfname[4] != 'q') { + if (currln >= blockln) { begin = blockline; end = currline; - if(ans[2] == 'y' && !(begin == end && currpnt != blockpnt)) { + if (ans[2] == 'y' && !(begin == end && currpnt != blockpnt)) { curr_window_line -= (currln - blockln); - if(curr_window_line < 0) { + if (curr_window_line < 0) { curr_window_line = 0; - if(end->next) + if (end->next) (top_of_win = end->next)->prev = begin->prev; else top_of_win = (lastline = begin->prev); @@ -1342,33 +1403,32 @@ static void block_del(int hide) { begin = currline; end = blockline; } - if(ans[2] == 'y' && !(begin == end && currpnt != blockpnt)) { - if(begin->prev) + if (ans[2] == 'y' && !(begin == end && currpnt != blockpnt)) { + if (begin->prev) begin->prev->next = end->next; - else if(end->next) + else if (end->next) top_of_win = firstline = end->next; else { currline = top_of_win = firstline = lastline = alloc_line(); currln = curr_window_line = edit_margin = 0; } - - if(end->next) + + if (end->next) (currline = end->next)->prev = begin->prev; - else if(begin->prev) { + else if (begin->prev) { currline = (lastline = begin->prev); currln--; - if(curr_window_line > 0) + if (curr_window_line > 0) curr_window_line--; } } - setuserfile(fp_tmpbuf, tmpfname); - if((fp = fopen(fp_tmpbuf, ans))) { - if(begin == end && currpnt != blockpnt) { - char buf[WRAPMARGIN + 2]; - - if(currpnt > blockpnt) { + if ((fp = fopen(fp_tmpbuf, ans))) { + if (begin == end && currpnt != blockpnt) { + char buf[WRAPMARGIN + 2]; + + if (currpnt > blockpnt) { strcpy(buf, begin->data + blockpnt); buf[currpnt - blockpnt] = 0; } else { @@ -1377,18 +1437,17 @@ static void block_del(int hide) { } fputs(buf, fp); } else { - for(p = begin; p != end; p = p->next) + for (p = begin; p != end; p = p->next) fprintf(fp, "%s\n", p->data); fprintf(fp, "%s\n", end->data); } fclose(fp); } - - if(ans[2] == 'y') { - if(begin == end && currpnt != blockpnt) { - int min, max; - - if(currpnt > blockpnt) { + if (ans[2] == 'y') { + if (begin == end && currpnt != blockpnt) { + int min, max; + + if (currpnt > blockpnt) { min = blockpnt; max = currpnt; } else { @@ -1399,7 +1458,7 @@ static void block_del(int hide) { begin->len -= max - min; currpnt = min; } else { - for(p = begin; p != end; totaln--) + for (p = begin; p != end; totaln--) free((p = p->next)->prev); free(end); totaln--; @@ -1412,10 +1471,12 @@ static void block_del(int hide) { } } -static void block_shift_left() { - textline_t *begin, *end, *p; - - if(currln >= blockln) { +static void +block_shift_left() +{ + textline_t *begin, *end, *p; + + if (currln >= blockln) { begin = blockline; end = currline; } else { @@ -1423,25 +1484,27 @@ static void block_shift_left() { end = blockline; } p = begin; - while(1) { - if(p->len) { + while (1) { + if (p->len) { strcpy(p->data, p->data + 1); --p->len; } - if(p == end) + if (p == end) break; else p = p->next; } - if(currpnt > currline->len) + if (currpnt > currline->len) currpnt = currline->len; redraw_everything = YEA; } -static void block_shift_right() { - textline_t *begin, *end, *p; +static void +block_shift_right() +{ + textline_t *begin, *end, *p; - if(currln >= blockln) { + if (currln >= blockln) { begin = blockline; end = currline; } else { @@ -1449,38 +1512,42 @@ static void block_shift_right() { end = blockline; } p = begin; - while(1) { - if(p->len < WRAPMARGIN) { - int i = p->len + 1; - - while(i--) + while (1) { + if (p->len < WRAPMARGIN) { + int i = p->len + 1; + + while (i--) p->data[i + 1] = p->data[i]; p->data[0] = insert_character ? ' ' : insert_c; ++p->len; } - if(p == end) + if (p == end) break; else p = p->next; } - if(currpnt > currline->len) + if (currpnt > currline->len) currpnt = currline->len; redraw_everything = YEA; } -static void transform_to_color(char* line) { - while(line[0] && line[1]) - if(line[0] == '*' && line[1] == '[') { +static void +transform_to_color(char *line) +{ + while (line[0] && line[1]) + if (line[0] == '*' && line[1] == '[') { line[0] = KEY_ESC; line += 2; } else ++line; } -static void block_color() { - textline_t *begin, *end, *p; - - if(currln >= blockln) { +static void +block_color() +{ + textline_t *begin, *end, *p; + + if (currln >= blockln) { begin = blockline; end = currline; } else { @@ -1488,9 +1555,9 @@ static void block_color() { end = blockline; } p = begin; - while(1) { + while (1) { transform_to_color(p->data); - if(p == end) + if (p == end) break; else p = p->next; @@ -1499,96 +1566,95 @@ static void block_color() { } /* 編輯處理:主程式、鍵盤處理 */ -int vedit(char *fpath, int saveheader, int *islocal) { - FILE *fp1; - char last = 0, buf[200]; /* the last key you press */ - int ch, foo; - int lastindent = -1; - int last_margin; - int mode0 = currutmp->mode; - int destuid0 = currutmp->destuid; - unsigned int money=0; - int interval=0; - time_t th=now; - - textline_t* firstline0 = firstline; - textline_t* lastline0 = lastline; - textline_t* currline0 = currline; - textline_t* blockline0 = blockline; - textline_t* top_of_win0 = top_of_win; - int local_article0 = local_article; - int currpnt0 = currpnt; - int currln0 = currln; - int totaln0 = totaln; - int curr_window_line0 = curr_window_line; - int insert_character0 = insert_character; - int my_ansimode0 = my_ansimode; - int edit_margin0 = edit_margin; - int blockln0 = blockln, count=0, tin=0; - +int +vedit(char *fpath, int saveheader, int *islocal) +{ + FILE *fp1; + char last = 0, buf[200]; /* the last key you press */ + int ch, foo; + int lastindent = -1; + int last_margin; + int mode0 = currutmp->mode; + int destuid0 = currutmp->destuid; + unsigned int money = 0; + int interval = 0; + time_t th = now; + + textline_t *firstline0 = firstline; + textline_t *lastline0 = lastline; + textline_t *currline0 = currline; + textline_t *blockline0 = blockline; + textline_t *top_of_win0 = top_of_win; + int local_article0 = local_article; + int currpnt0 = currpnt; + int currln0 = currln; + int totaln0 = totaln; + int curr_window_line0 = curr_window_line; + int insert_character0 = insert_character; + int my_ansimode0 = my_ansimode; + int edit_margin0 = edit_margin; + int blockln0 = blockln, count = 0, tin = 0; + currutmp->mode = EDITING; currutmp->destuid = currstat; insert_character = redraw_everything = 1; prevln = blockln = -1; - + line_dirty = currpnt = totaln = my_ansimode = 0; currline = top_of_win = firstline = lastline = alloc_line(); - - if(*fpath) + + if (*fpath) read_file(fpath); - if(*quote_file) { + if (*quote_file) { do_quote(); *quote_file = '\0'; - if(quote_file[79] == 'L') + if (quote_file[79] == 'L') local_article = 1; } - currline = firstline; currpnt = currln = curr_window_line = edit_margin = last_margin = 0; - - while(1) { - if(redraw_everything || blockln >= 0) { + + while (1) { + if (redraw_everything || blockln >= 0) { display_buffer(); redraw_everything = NA; } - if(my_ansimode) + if (my_ansimode) ch = n2ansi(currpnt, currline); else ch = currpnt - edit_margin; move(curr_window_line, ch); - if(!line_dirty && strcmp(line, currline->data)) + if (!line_dirty && strcmp(line, currline->data)) strcpy(line, currline->data); ch = igetkey(); - /* jochang debug */ - if((interval = (now - th))) { - th=now; - if((char)ch != last) { + /* jochang debug */ + if ((interval = (now - th))) { + th = now; + if ((char)ch != last) { money++; last = (char)ch; } - } - if(interval && interval == tin) - count++; - else - { - count=0; - tin = interval; - } - /* 連續240個interval一樣 , 分明是在斂財 */ - if(count >= 240) { + } + if (interval && interval == tin) + count++; + else { + count = 0; + tin = interval; + } + /* 連續240個interval一樣 , 分明是在斂財 */ + if (count >= 240) { sprintf(buf, "\033[1;33;46m%s\033[37m在\033[37;45m%s" "\033[37m板違法賺錢 , %s\033[m", cuser.userid, - currboard,ctime(&now)); - log_file ("etc/illegal_money",buf); - money = 0 ; + currboard, ctime(&now)); + log_file("etc/illegal_money", buf); + money = 0; post_violatelaw(cuser.userid, "Ptt 系統警察", "違法賺錢", "扣除不法所得"); mail_violatelaw(cuser.userid, "Ptt 系統警察", "違法賺錢", "扣除不法所得"); -// demoney(10000); -// abort_bbs(0); + //demoney(10000); + //abort_bbs(0); } - - if(raw_mode) + if (raw_mode) switch (ch) { case Ctrl('S'): case Ctrl('Q'): @@ -1596,19 +1662,19 @@ int vedit(char *fpath, int saveheader, int *islocal) { continue; break; } - if(ch < 0x100 && isprint2(ch)) { + if (ch < 0x100 && isprint2(ch)) { insert_char(ch); lastindent = -1; line_dirty = 1; } else { - if(ch == Ctrl('P') || ch == KEY_UP || ch == KEY_DOWN || - ch == Ctrl('N')) { - if(lastindent == -1) + if (ch == Ctrl('P') || ch == KEY_UP || ch == KEY_DOWN || + ch == Ctrl('N')) { + if (lastindent == -1) lastindent = currpnt; } else lastindent = -1; - if(ch == KEY_ESC) - switch(KEY_ESC_arg) { + if (ch == KEY_ESC) + switch (KEY_ESC_arg) { case ',': ch = Ctrl(']'); break; @@ -1639,10 +1705,10 @@ int vedit(char *fpath, int saveheader, int *islocal) { break; } - switch(ch) { - case Ctrl('X'): /* Save and exit */ + switch (ch) { + case Ctrl('X'): /* Save and exit */ foo = write_file(fpath, saveheader, islocal); - if(foo != KEEP_EDITING) { + if (foo != KEEP_EDITING) { currutmp->mode = mode0; currutmp->destuid = destuid0; firstline = firstline0; @@ -1659,7 +1725,7 @@ int vedit(char *fpath, int saveheader, int *islocal) { my_ansimode = my_ansimode0; edit_margin = edit_margin0; blockln = blockln0; - if(!foo) + if (!foo) return money; else return foo; @@ -1668,13 +1734,13 @@ int vedit(char *fpath, int saveheader, int *islocal) { redraw_everything = YEA; break; case Ctrl('W'): - if(blockln >= 0) + if (blockln >= 0) block_del(2); line_dirty = 1; break; - case Ctrl('Q'): /* Quit without saving */ + case Ctrl('Q'): /* Quit without saving */ ch = ask("結束但不儲存 (Y/N)? [N]: "); - if(ch == 'y' || ch == 'Y') { + if (ch == 'y' || ch == 'Y') { currutmp->mode = mode0; currutmp->destuid = destuid0; firstline = firstline0; @@ -1699,36 +1765,36 @@ int vedit(char *fpath, int saveheader, int *islocal) { case Ctrl('C'): ch = insert_character; insert_character = redraw_everything = YEA; - if(!my_ansimode) + if (!my_ansimode) insert_string(reset_color); else { - char ans[4]; + char ans[4]; move(b_lines - 2, 55); outs("\033[1;33;40mB\033[41mR\033[42mG\033[43mY\033[44mL" "\033[45mP\033[46mC\033[47mW\033[m"); - if(getdata(b_lines - 1, 0, - "請輸入 亮度/前景/背景[正常白字黑底][0wb]:", - ans, sizeof(ans), LCECHO)) { - char t[] = "BRGYLPCW"; - char color[15]; - char *tmp, *apos = ans; - int fg, bg; - + if (getdata(b_lines - 1, 0, + "請輸入 亮度/前景/背景[正常白字黑底][0wb]:", + ans, sizeof(ans), LCECHO)) { + char t[] = "BRGYLPCW"; + char color[15]; + char *tmp, *apos = ans; + int fg, bg; + strcpy(color, "\033["); - if(isdigit(*apos)) { + if (isdigit(*apos)) { sprintf(color, "%s%c", color, *(apos++)); - if(*apos) + if (*apos) sprintf(color, "%s;", color); } - if(*apos) { - if((tmp = strchr(t, toupper(*(apos++))))) + if (*apos) { + if ((tmp = strchr(t, toupper(*(apos++))))) fg = tmp - t + 30; else fg = 37; sprintf(color, "%s%d", color, fg); } - if(*apos) { - if((tmp = strchr(t, toupper(*(apos++))))) + if (*apos) { + if ((tmp = strchr(t, toupper(*(apos++))))) bg = tmp - t + 40; else bg = 40; @@ -1744,7 +1810,7 @@ int vedit(char *fpath, int saveheader, int *islocal) { break; case KEY_ESC: line_dirty = 0; - switch(KEY_ESC_arg) { + switch (KEY_ESC_arg) { case 'U': t_users(); redraw_everything = YEA; @@ -1781,18 +1847,18 @@ int vedit(char *fpath, int saveheader, int *islocal) { read_tmpbuf(KEY_ESC_arg - '0'); redraw_everything = YEA; break; - case 'l': /* block delete */ + case 'l': /* block delete */ case ' ': block_del(0); line_dirty = 1; break; case 'u': - if(blockln >= 0) + if (blockln >= 0) block_del(1); line_dirty = 1; break; case 'c': - if(blockln >= 0) + if (blockln >= 0) block_del(3); line_dirty = 1; break; @@ -1808,26 +1874,26 @@ int vedit(char *fpath, int saveheader, int *islocal) { line_dirty = 1; break; case 'j': - if(blockln >= 0) + if (blockln >= 0) block_shift_left(); - else if(currline->len) { - int currpnt0 = currpnt; + else if (currline->len) { + int currpnt0 = currpnt; currpnt = 0; delete_char(); - currpnt = (currpnt0 <= currline->len) ? currpnt0 : + currpnt = (currpnt0 <= currline->len) ? currpnt0 : currpnt0 - 1; - if(my_ansimode) + if (my_ansimode) currpnt = ansi2n(n2ansi(currpnt, currline), currline); } line_dirty = 1; break; case 'k': - if(blockln >= 0) + if (blockln >= 0) block_shift_right(); else { - int currpnt0 = currpnt; - + int currpnt0 = currpnt; + currpnt = 0; insert_char(' '); currpnt = currpnt0; @@ -1835,26 +1901,26 @@ int vedit(char *fpath, int saveheader, int *islocal) { line_dirty = 1; break; case 'f': - while(currpnt < currline->len && - isalnum(currline->data[++currpnt])); - while(currpnt < currline->len && - isspace(currline->data[++currpnt])); + while (currpnt < currline->len && + isalnum(currline->data[++currpnt])); + while (currpnt < currline->len && + isspace(currline->data[++currpnt])); line_dirty = 1; break; case 'b': - while(currpnt && isalnum(currline->data[--currpnt])); - while(currpnt && isspace(currline->data[--currpnt])); + while (currpnt && isalnum(currline->data[--currpnt])); + while (currpnt && isspace(currline->data[--currpnt])); line_dirty = 1; break; case 'd': - while(currpnt < currline->len) { + while (currpnt < currline->len) { delete_char(); - if(!isalnum(currline->data[currpnt])) + if (!isalnum(currline->data[currpnt])) break; } - while(currpnt < currline->len) { + while (currpnt < currline->len) { delete_char(); - if(!isspace(currline->data[currpnt])) + if (!isspace(currline->data[currpnt])) break; } line_dirty = 1; @@ -1864,9 +1930,9 @@ int vedit(char *fpath, int saveheader, int *islocal) { } break; case Ctrl('_'): - if(strcmp(line, currline->data)) { - char buf[WRAPMARGIN]; - + if (strcmp(line, currline->data)) { + char buf[WRAPMARGIN]; + strcpy(buf, currline->data); strcpy(currline->data, line); strcpy(line, buf); @@ -1882,9 +1948,9 @@ int vedit(char *fpath, int saveheader, int *islocal) { insert_char('\033'); line_dirty = 1; break; - case Ctrl('V'): /* Toggle ANSI color */ + case Ctrl('V'): /* Toggle ANSI color */ my_ansimode ^= 1; - if(my_ansimode && blockln >= 0) + if (my_ansimode && blockln >= 0) block_color(); clear(); redraw_everything = YEA; @@ -1893,7 +1959,7 @@ int vedit(char *fpath, int saveheader, int *islocal) { case Ctrl('I'): do { insert_char(' '); - } while(currpnt & 0x7); + } while (currpnt & 0x7); line_dirty = 1; break; case '\r': @@ -1902,40 +1968,40 @@ int vedit(char *fpath, int saveheader, int *islocal) { line_dirty = 0; break; case Ctrl('G'): - { - unsigned int currstat0 = currstat; - setutmpmode(EDITEXP); - a_menu("編輯輔助器", "etc/editexp", - (HAS_PERM(PERM_SYSOP) ? SYSOP : NOBODY)); - currstat = currstat0; - } - if(trans_buffer[0]) { - if((fp1 = fopen(trans_buffer, "r"))) { - int indent_mode0 = indent_mode; - - indent_mode = 0; - prevln = currln; - prevpnt = currpnt; - while(fgets(line, WRAPMARGIN + 2, fp1)) { - if(!strncmp(line,"作者:",5) || - !strncmp(line,"標題:",5) || - !strncmp(line,"時間:",5)) - continue; - insert_string(line); - } - fclose(fp1); - indent_mode = indent_mode0; - while(curr_window_line >= b_lines) { - curr_window_line--; - top_of_win = top_of_win->next; + { + unsigned int currstat0 = currstat; + setutmpmode(EDITEXP); + a_menu("編輯輔助器", "etc/editexp", + (HAS_PERM(PERM_SYSOP) ? SYSOP : NOBODY)); + currstat = currstat0; + } + if (trans_buffer[0]) { + if ((fp1 = fopen(trans_buffer, "r"))) { + int indent_mode0 = indent_mode; + + indent_mode = 0; + prevln = currln; + prevpnt = currpnt; + while (fgets(line, WRAPMARGIN + 2, fp1)) { + if (!strncmp(line, "作者:", 5) || + !strncmp(line, "標題:", 5) || + !strncmp(line, "時間:", 5)) + continue; + insert_string(line); + } + fclose(fp1); + indent_mode = indent_mode0; + while (curr_window_line >= b_lines) { + curr_window_line--; + top_of_win = top_of_win->next; + } } } - } - redraw_everything = YEA; - line_dirty = 1; - break; - case Ctrl('Z'): /* Help */ - more("etc/ve.hlp",YEA); + redraw_everything = YEA; + line_dirty = 1; + break; + case Ctrl('Z'): /* Help */ + more("etc/ve.hlp", YEA); redraw_everything = YEA; line_dirty = 1; break; @@ -1945,14 +2011,14 @@ int vedit(char *fpath, int saveheader, int *islocal) { line_dirty = 1; break; case KEY_LEFT: - if(currpnt) { - if(my_ansimode) + if (currpnt) { + if (my_ansimode) currpnt = n2ansi(currpnt, currline); currpnt--; - if(my_ansimode) + if (my_ansimode) currpnt = ansi2n(currpnt, currline); line_dirty = 1; - } else if(currline->prev) { + } else if (currline->prev) { curr_window_line--; currln--; currline = currline->prev; @@ -1961,14 +2027,14 @@ int vedit(char *fpath, int saveheader, int *islocal) { } break; case KEY_RIGHT: - if(currline->len != currpnt) { - if(my_ansimode) + if (currline->len != currpnt) { + if (my_ansimode) currpnt = n2ansi(currpnt, currline); currpnt++; - if(my_ansimode) + if (my_ansimode) currpnt = ansi2n(currpnt, currline); line_dirty = 1; - } else if(currline->next) { + } else if (currline->next) { currpnt = 0; curr_window_line++; currln++; @@ -1978,33 +2044,33 @@ int vedit(char *fpath, int saveheader, int *islocal) { break; case KEY_UP: case Ctrl('P'): - if(currline->prev) { - if(my_ansimode) - ch = n2ansi(currpnt,currline); + if (currline->prev) { + if (my_ansimode) + ch = n2ansi(currpnt, currline); curr_window_line--; currln--; currline = currline->prev; - if(my_ansimode) - currpnt = ansi2n(ch , currline); + if (my_ansimode) + currpnt = ansi2n(ch, currline); else currpnt = (currline->len > lastindent) ? lastindent : - currline->len; + currline->len; line_dirty = 0; } break; case KEY_DOWN: case Ctrl('N'): - if(currline->next) { - if(my_ansimode) - ch = n2ansi(currpnt,currline); + if (currline->next) { + if (my_ansimode) + ch = n2ansi(currpnt, currline); currline = currline->next; curr_window_line++; currln++; - if(my_ansimode) - currpnt = ansi2n(ch , currline); + if (my_ansimode) + currpnt = ansi2n(ch, currline); else currpnt = (currline->len > lastindent) ? lastindent : - currline->len; + currline->len; line_dirty = 0; } break; @@ -2015,7 +2081,7 @@ int vedit(char *fpath, int saveheader, int *islocal) { currln = redraw_everything; currline = back_line(currline, 22); curr_window_line = getlineno(); - if(currpnt > currline->len) + if (currpnt > currline->len) currpnt = currline->len; redraw_everything = YEA; line_dirty = 0; @@ -2027,7 +2093,7 @@ int vedit(char *fpath, int saveheader, int *islocal) { currln = redraw_everything; currline = forward_line(currline, 22); curr_window_line = getlineno(); - if(currpnt > currline->len) + if (currpnt > currline->len) currpnt = currline->len; redraw_everything = YEA; line_dirty = 0; @@ -2037,7 +2103,7 @@ int vedit(char *fpath, int saveheader, int *islocal) { currpnt = currline->len; line_dirty = 1; break; - case Ctrl(']'): /* start of file */ + case Ctrl(']'): /* start of file */ prevln = currln; prevpnt = currpnt; currline = top_of_win = firstline; @@ -2045,7 +2111,7 @@ int vedit(char *fpath, int saveheader, int *islocal) { redraw_everything = YEA; line_dirty = 0; break; - case Ctrl('T'): /* tail of file */ + case Ctrl('T'): /* tail of file */ prevln = currln; prevpnt = currpnt; top_of_win = back_line(lastline, 23); @@ -2061,10 +2127,10 @@ int vedit(char *fpath, int saveheader, int *islocal) { currpnt = 0; line_dirty = 1; break; - case KEY_INS: /* Toggle insert/overwrite */ + case KEY_INS: /* Toggle insert/overwrite */ case Ctrl('O'): - if(blockln >= 0 && insert_character) { - char ans[4]; + if (blockln >= 0 && insert_character) { + char ans[4]; getdata(b_lines - 1, 0, "區塊微調右移插入字元(預設為空白字元)", @@ -2075,17 +2141,17 @@ int vedit(char *fpath, int saveheader, int *islocal) { line_dirty = 1; break; case Ctrl('H'): - case '\177': /* backspace */ + case '\177': /* backspace */ line_dirty = 1; - if(my_ansimode) { + if (my_ansimode) { my_ansimode = 0; clear(); redraw_everything = YEA; } else { - if(currpnt == 0) { - textline_t *p; + if (currpnt == 0) { + textline_t *p; - if(!currline->prev) + if (!currline->prev) break; line_dirty = 0; curr_window_line--; @@ -2093,14 +2159,14 @@ int vedit(char *fpath, int saveheader, int *islocal) { currline = currline->prev; currpnt = currline->len; redraw_everything = YEA; - if(*killsp(currline->next->data) == '\0') { + if (*killsp(currline->next->data) == '\0') { delete_line(currline->next); break; } p = currline; - while(!join(p)) { + while (!join(p)) { p = p->next; - if(p == NULL) { + if (p == NULL) { indigestion(2); abort_bbs(0); } @@ -2112,14 +2178,14 @@ int vedit(char *fpath, int saveheader, int *islocal) { } break; case Ctrl('D'): - case KEY_DEL: /* delete current character */ + case KEY_DEL: /* delete current character */ line_dirty = 1; - if(currline->len == currpnt) { - textline_t *p = currline; - - while(!join(p)) { + if (currline->len == currpnt) { + textline_t *p = currline; + + while (!join(p)) { p = p->next; - if(p == NULL) { + if (p == NULL) { indigestion(2); abort_bbs(0); } @@ -2128,25 +2194,25 @@ int vedit(char *fpath, int saveheader, int *islocal) { redraw_everything = YEA; } else { delete_char(); - if(my_ansimode) + if (my_ansimode) currpnt = ansi2n(n2ansi(currpnt, currline), currline); } break; - case Ctrl('Y'): /* delete current line */ + case Ctrl('Y'): /* delete current line */ currline->len = currpnt = 0; - case Ctrl('K'): /* delete to end of line */ - if(currline->len == 0) { - textline_t *p = currline->next; - if(!p) { + case Ctrl('K'): /* delete to end of line */ + if (currline->len == 0) { + textline_t *p = currline->next; + if (!p) { p = currline->prev; - if(!p) + if (!p) break; - if(curr_window_line > 0) { + if (curr_window_line > 0) { curr_window_line--; currln--; } } - if(currline == top_of_win) + if (currline == top_of_win) top_of_win = p; delete_line(currline); currline = p; @@ -2154,12 +2220,12 @@ int vedit(char *fpath, int saveheader, int *islocal) { line_dirty = 0; break; } - if(currline->len == currpnt) { - textline_t *p = currline; + if (currline->len == currpnt) { + textline_t *p = currline; - while(!join(p)) { + while (!join(p)) { p = p->next; - if(p == NULL) { + if (p == NULL) { indigestion(2); abort_bbs(0); } @@ -2173,20 +2239,20 @@ int vedit(char *fpath, int saveheader, int *islocal) { line_dirty = 1; break; } - if(currln < 0) + if (currln < 0) currln = 0; - if(curr_window_line < 0) { + if (curr_window_line < 0) { curr_window_line = 0; - if(!top_of_win->prev) + if (!top_of_win->prev) indigestion(6); else { top_of_win = top_of_win->prev; rscroll(); } } - if(curr_window_line == b_lines) { + if (curr_window_line == b_lines) { curr_window_line = t_lines - 2; - if(!top_of_win->next) + if (!top_of_win->next) indigestion(7); else { top_of_win = top_of_win->next; @@ -2197,15 +2263,15 @@ int vedit(char *fpath, int saveheader, int *islocal) { } } edit_margin = currpnt < SCR_WIDTH - 1 ? 0 : currpnt / 72 * 72; - - if(!redraw_everything) { - if(edit_margin != last_margin) { + + if (!redraw_everything) { + if (edit_margin != last_margin) { last_margin = edit_margin; redraw_everything = YEA; } else { move(curr_window_line, 0); clrtoeol(); - if(my_ansimode) + if (my_ansimode) outs(currline->data); else edit_outs(&currline->data[edit_margin]); diff --git a/pttbbs/mbbsd/friend.c b/pttbbs/mbbsd/friend.c index c24f6240..81abf097 100644 --- a/pttbbs/mbbsd/friend.c +++ b/pttbbs/mbbsd/friend.c @@ -1,4 +1,4 @@ -/* $Id: friend.c,v 1.8 2002/07/02 13:01:43 in2 Exp $ */ +/* $Id: friend.c,v 1.9 2002/07/05 17:10:27 in2 Exp $ */ #include "bbs.h" /* ------------------------------------- */ @@ -6,8 +6,8 @@ /* ------------------------------------- */ /* Ptt 其他特別名單的檔名 */ -static char special_list[] = "list.0"; -static char special_des[] = "ldes.0"; +static char special_list[] = "list.0"; +static char special_des[] = "ldes.0"; /* 特別名單的上限 */ static unsigned int friend_max[8] = { @@ -24,7 +24,7 @@ static unsigned int friend_max[8] = { /* Ptt 各種特別名單的補述 */ -static char *friend_desc[8] = { +static char *friend_desc[8] = { "友誼描述:", "惡形惡狀:", "", @@ -36,7 +36,7 @@ static char *friend_desc[8] = { }; /* Ptt 各種特別名單的中文敘述 */ -static char *friend_list[8] = { +static char *friend_list[8] = { "好友名單", "壞人名單", "上線通知", @@ -47,17 +47,21 @@ static char *friend_list[8] = { "看板好友名單" }; -static void setfriendfile(char *fpath, int type) { +static void +setfriendfile(char *fpath, int type) +{ if (type <= 4) /* user list Ptt */ setuserfile(fpath, friend_file[type]); else /* board list */ setbfile(fpath, currboard, friend_file[type]); } -static int friend_count(char *fname) { - FILE *fp; - int count = 0; - char buf[200]; +static int +friend_count(char *fname) +{ + FILE *fp; + int count = 0; + char buf[200]; #if 0 if ((fp = fopen(fname, "r"))) @@ -65,37 +69,36 @@ static int friend_count(char *fname) { count++; #endif -/*rocker.011018: 忘記關檔了... */ - if ((fp = fopen(fname, "r"))) - { - while (fgets(buf, 200, fp)) count++; - fclose (fp); + /* rocker.011018: 忘記關檔了... */ + if ((fp = fopen(fname, "r"))) { + while (fgets(buf, 200, fp)) + count++; + fclose(fp); } - return count; } -void friend_add(char *uident, int type) { - char fpath[80]; +void +friend_add(char *uident, int type) +{ + char fpath[80]; setfriendfile(fpath, type); if (friend_count(fpath) > friend_max[type]) return; - if ((uident[0] > ' ') && !belong(fpath, uident)) - { - FILE *fp; - char buf[40] = ""; - char t_uident[IDLEN + 1]; + if ((uident[0] > ' ') && !belong(fpath, uident)) { + FILE *fp; + char buf[40] = ""; + char t_uident[IDLEN + 1]; - /* Thor: avoid uident run away when get data */ + /* Thor: avoid uident run away when get data */ strcpy(t_uident, uident); if (type != FRIEND_ALOHA && type != FRIEND_POST) getdata(2, 0, friend_desc[type], buf, sizeof(buf), DOECHO); - if ((fp = fopen(fpath, "a"))) - { + if ((fp = fopen(fpath, "a"))) { flock(fileno(fp), LOCK_EX); fprintf(fp, "%-13s%s\n", t_uident, buf); flock(fileno(fp), LOCK_UN); @@ -104,19 +107,19 @@ void friend_add(char *uident, int type) { } } -static void friend_special() { - char genbuf[70], i, fname[70]; +static void +friend_special() +{ + char genbuf[70], i, fname[70]; friend_file[FRIEND_SPECIAL] = special_list; - for (i = 0; i <= 9; i++) - { + for (i = 0; i <= 9; i++) { sprintf(genbuf, " (\033[36m%d\033[m) .. ", i); special_des[5] = i + '0'; setuserfile(fname, special_des); - if (dashf(fname)) - { - /* no NULL check?? */ - FILE *fp = fopen(fname, "r"); + if (dashf(fname)) { + /* no NULL check?? */ + FILE *fp = fopen(fname, "r"); fgets(genbuf + 15, 40, fp); genbuf[47] = 0; @@ -126,45 +129,41 @@ static void friend_special() { outs(genbuf); } getdata(22, 0, "請選擇第幾號特別名單 (0~9)[0]?", genbuf, 3, LCECHO); - if (genbuf[0] >= '0' && genbuf[0] <= '9') - { + if (genbuf[0] >= '0' && genbuf[0] <= '9') { special_list[5] = genbuf[0]; special_des[5] = genbuf[0]; - } - else - { + } else { special_list[5] = '0'; special_des[5] = '0'; } } -static void friend_append(int type, int count) { - char fpath[80], i, j, buf[80], sfile[80]; - FILE *fp, *fp1; +static void +friend_append(int type, int count) +{ + char fpath[80], i, j, buf[80], sfile[80]; + FILE *fp, *fp1; setfriendfile(fpath, type); - do - { + do { move(2, 0); clrtobot(); outs("要引入哪一個名單?\n"); for (j = i = 0; i <= 4; i++) - if( i != type ){ + if (i != type) { ++j; - sprintf(buf, " (%d) %-s\n", i + 1, friend_list[(int) i]); + sprintf(buf, " (%d) %-s\n", i + 1, friend_list[(int)i]); outs(buf); } - - if( HAVE_PERM(PERM_SYSOP) || currmode & MODE_BOARD ) - for( ; i < 8 ; ++i ) - if( i != type ){ + if (HAVE_PERM(PERM_SYSOP) || currmode & MODE_BOARD) + for (; i < 8; ++i) + if (i != type) { ++j; sprintf(buf, " (%d) %s 板的 %s\n", j, currboard, - friend_list[(int) i]); + friend_list[(int)i]); outs(buf); } - outs(" (S) 選擇其他看板的特別名單"); getdata(11, 0, "請選擇 或 直接[Enter] 放棄:", buf, 3, LCECHO); if (!buf[0]) @@ -174,7 +173,7 @@ static void friend_append(int type, int count) { j = buf[0] - '1'; if (j >= type) j++; - if( !(HAVE_PERM(PERM_SYSOP) || currmode & MODE_BOARD) && j >= 4 ) + if (!(HAVE_PERM(PERM_SYSOP) || currmode & MODE_BOARD) && j >= 4) return; } while (buf[0] < '1' || buf[0] > '9'); @@ -184,13 +183,13 @@ static void friend_append(int type, int count) { setfriendfile(sfile, j); - if( (fp = fopen(sfile, "r")) != NULL ){ - while (fgets(buf, 80, fp) && count <= friend_max[type]){ - char the_id[15]; - + if ((fp = fopen(sfile, "r")) != NULL) { + while (fgets(buf, 80, fp) && count <= friend_max[type]) { + char the_id[15]; + sscanf(buf, "%s", the_id); - if (!belong(fpath, the_id)){ - if ((fp1 = fopen(fpath, "a"))){ + if (!belong(fpath, the_id)) { + if ((fp1 = fopen(fpath, "a"))) { flock(fileno(fp1), LOCK_EX); fputs(buf, fp1); flock(fileno(fp1), LOCK_UN); @@ -202,17 +201,18 @@ static void friend_append(int type, int count) { } } -void friend_delete(char *uident, int type) { - FILE *fp, *nfp; - char fn[80], fnnew[80]; - char genbuf[200]; +void +friend_delete(char *uident, int type) +{ + FILE *fp, *nfp; + char fn[80], fnnew[80]; + char genbuf[200]; setfriendfile(fn, type); sprintf(fnnew, "%s-", fn); - if ((fp = fopen(fn, "r")) && (nfp = fopen(fnnew, "w"))) - { - int length = strlen(uident); + if ((fp = fopen(fn, "r")) && (nfp = fopen(fnnew, "w"))) { + int length = strlen(uident); while (fgets(genbuf, STRLEN, fp)) if ((genbuf[0] > ' ') && strncmp(genbuf, uident, length)) @@ -223,22 +223,21 @@ void friend_delete(char *uident, int type) { } } -static void friend_editdesc(char *uident, int type) { - FILE *fp, *nfp; - char fnnew[200], genbuf[200], fn[200]; +static void +friend_editdesc(char *uident, int type) +{ + FILE *fp, *nfp; + char fnnew[200], genbuf[200], fn[200]; setfriendfile(fn, type); sprintf(fnnew, "%s-", fn); - if ((fp = fopen(fn, "r")) && (nfp = fopen(fnnew, "w"))) - { - int length = strlen(uident); + if ((fp = fopen(fn, "r")) && (nfp = fopen(fnnew, "w"))) { + int length = strlen(uident); - while (fgets(genbuf, STRLEN, fp)) - { + while (fgets(genbuf, STRLEN, fp)) { if ((genbuf[0] > ' ') && strncmp(genbuf, uident, length)) fputs(genbuf, nfp); - else if (!strncmp(genbuf, uident, length)) - { - char buf[50] = ""; + else if (!strncmp(genbuf, uident, length)) { + char buf[50] = ""; getdata(2, 0, "修改描述:", buf, 40, DOECHO); fprintf(nfp, "%-13s%s\n", uident, buf); } @@ -249,19 +248,20 @@ static void friend_editdesc(char *uident, int type) { } } -void friend_load() { - FILE *fp; - int myfriends[MAX_FRIEND]; - int myrejects[MAX_REJECT]; - int friendcount, rejectedcount; - char genbuf[200]; +void +friend_load() +{ + FILE *fp; + int myfriends[MAX_FRIEND]; + int myrejects[MAX_REJECT]; + int friendcount, rejectedcount; + char genbuf[200]; memset(myfriends, 0, sizeof(myfriends)); friendcount = 0; setuserfile(genbuf, fn_overrides); - if ((fp = fopen(genbuf, "r"))) - { - int unum; + if ((fp = fopen(genbuf, "r"))) { + int unum; while (fgets(genbuf, STRLEN, fp) && friendcount < MAX_FRIEND - 1) if (strtok(genbuf, str_space)) @@ -274,9 +274,8 @@ void friend_load() { memset(myrejects, 0, sizeof(myrejects)); rejectedcount = 0; setuserfile(genbuf, fn_reject); - if ((fp = fopen(genbuf, "r"))) - { - int unum; + if ((fp = fopen(genbuf, "r"))) { + int unum; while (fgets(genbuf, STRLEN, fp) && rejectedcount < MAX_REJECT - 1) if (strtok(genbuf, str_space)) @@ -285,52 +284,52 @@ void friend_load() { fclose(fp); } memcpy(currutmp->reject, myrejects, sizeof(myrejects)); - if(currutmp->friendtotal) + if (currutmp->friendtotal) logout_friend_online(currutmp); login_friend_online(); } -static void friend_water(char *message, int type) { /* 群體水球 added by Ptt */ - char fpath[80], line[80], userid[IDLEN + 1]; - FILE *fp; +static void +friend_water(char *message, int type) +{ /* 群體水球 added by Ptt */ + char fpath[80], line[80], userid[IDLEN + 1]; + FILE *fp; setfriendfile(fpath, type); if ((fp = fopen(fpath, "r"))) - while(fgets(line, 80, fp)) { - userinfo_t *uentp; - int tuid; - + while (fgets(line, 80, fp)) { + userinfo_t *uentp; + int tuid; + sscanf(line, "%s", userid); - if((tuid = searchuser(userid)) && tuid != usernum && - (uentp = (userinfo_t *) search_ulist(tuid)) && - isvisible_uid(tuid)) + if ((tuid = searchuser(userid)) && tuid != usernum && + (uentp = (userinfo_t *) search_ulist(tuid)) && + isvisible_uid(tuid)) my_write(uentp->pid, message, uentp->userid, 1, NULL); } fclose(fp); } -void friend_edit(int type) { - char fpath[80], line[80], uident[20]; - int count, column, dirty; - FILE *fp; - char genbuf[200]; +void +friend_edit(int type) +{ + char fpath[80], line[80], uident[20]; + int count, column, dirty; + FILE *fp; + char genbuf[200]; if (type == FRIEND_SPECIAL) friend_special(); setfriendfile(fpath, type); - if (type == FRIEND_ALOHA || type == FRIEND_POST) - { - if (dashf(fpath)) - { + if (type == FRIEND_ALOHA || type == FRIEND_POST) { + if (dashf(fpath)) { sprintf(genbuf, "/bin/cp %s %s.old", fpath, fpath); system(genbuf); } } - dirty = 0; - while (1) - { + while (1) { stand_title(friend_list[type]); move(0, 40); sprintf(line, "(名單上限:%d個人)", friend_max[type]); @@ -338,20 +337,17 @@ void friend_edit(int type) { count = 0; CreateNameList(); - if ((fp = fopen(fpath, "r"))) - { + if ((fp = fopen(fpath, "r"))) { move(3, 0); column = 0; - while (fgets(genbuf, STRLEN, fp)) - { + while (fgets(genbuf, STRLEN, fp)) { if (genbuf[0] <= ' ') continue; strtok(genbuf, str_space); AddNameList(genbuf); prints("%-13s", genbuf); count++; - if (++column > 5) - { + if (++column > 5) { column = 0; outc('\n'); } @@ -363,108 +359,83 @@ void friend_edit(int type) { "(K)刪除整個名單(W)丟水球(Q)結束?[Q]" : "(A)增加 (P)引入其他名單 (Q)結束?[Q]"), uident, 3, LCECHO); - if (*uident == 'a') - { + if (*uident == 'a') { move(1, 0); usercomplete(msg_uid, uident); - if (uident[0] && searchuser(uident) && !InNameList(uident)) - { + if (uident[0] && searchuser(uident) && !InNameList(uident)) { friend_add(uident, type); dirty = 1; } - } - else if (*uident == 'p') - { + } else if (*uident == 'p') { friend_append(type, count); dirty = 1; - } - else if (*uident == 'e' && count) - { + } else if (*uident == 'e' && count) { move(1, 0); namecomplete(msg_uid, uident); - if (uident[0] && InNameList(uident)) - { + if (uident[0] && InNameList(uident)) { friend_editdesc(uident, type); } - } - else if (*uident == 'd' && count) - { + } else if (*uident == 'd' && count) { move(1, 0); namecomplete(msg_uid, uident); - if (uident[0] && InNameList(uident)) - { + if (uident[0] && InNameList(uident)) { friend_delete(uident, type); dirty = 1; } - } - else if (*uident == 'l' && count) + } else if (*uident == 'l' && count) more(fpath, YEA); - else if (*uident == 'k' && count) - { + else if (*uident == 'k' && count) { getdata(2, 0, "整份名單將會被刪除,您確定嗎 (a/N)?", uident, 3, LCECHO); if (*uident == 'a') unlink(fpath); dirty = 1; - } - else if (*uident == 'w' && count) - { - char wall[60]; + } else if (*uident == 'w' && count) { + char wall[60]; if (!getdata(0, 0, "群體水球:", uident, sizeof(wall), DOECHO)) continue; if (getdata(0, 0, "確定丟出群體水球? [Y]", line, 4, LCECHO) && *line == 'n') continue; friend_water(wall, type); - } - else + } else break; } - if (dirty) - { + if (dirty) { move(2, 0); outs("更新資料中..請稍候....."); refresh(); - if (type == FRIEND_ALOHA || type == FRIEND_POST) - { + if (type == FRIEND_ALOHA || type == FRIEND_POST) { sprintf(genbuf, "%s.old", fpath); - if ((fp = fopen(genbuf, "r"))) - { - while (fgets(line, 80, fp)) - { + if ((fp = fopen(genbuf, "r"))) { + while (fgets(line, 80, fp)) { sscanf(line, "%s", uident); sethomefile(genbuf, uident, - type == FRIEND_ALOHA ? "aloha" : "postnotify"); + type == FRIEND_ALOHA ? "aloha" : "postnotify"); del_distinct(genbuf, cuser.userid); } fclose(fp); } sprintf(genbuf, "%s", fpath); - if ((fp = fopen(genbuf, "r"))) - { - while (fgets(line, 80, fp)) - { + if ((fp = fopen(genbuf, "r"))) { + while (fgets(line, 80, fp)) { sscanf(line, "%s", uident); sethomefile(genbuf, uident, - type == FRIEND_ALOHA ? "aloha" : "postnotify"); + type == FRIEND_ALOHA ? "aloha" : "postnotify"); add_distinct(genbuf, cuser.userid); } fclose(fp); } - } - else if (type == FRIEND_SPECIAL) - { + } else if (type == FRIEND_SPECIAL) { genbuf[0] = 0; setuserfile(line, special_des); - if ((fp = fopen(line, "r"))) - { + if ((fp = fopen(line, "r"))) { fgets(genbuf, 30, fp); fclose(fp); } getdata_buf(2, 0, " 請為此特別名單取一個簡短名稱:", genbuf, 30, DOECHO); - if ((fp = fopen(line, "w"))) - { + if ((fp = fopen(line, "w"))) { fprintf(fp, "%s", genbuf); fclose(fp); } @@ -473,12 +444,16 @@ void friend_edit(int type) { } } -int t_override() { +int +t_override() +{ friend_edit(FRIEND_OVERRIDE); return 0; } -int t_reject() { +int +t_reject() +{ friend_edit(FRIEND_REJECT); return 0; } diff --git a/pttbbs/mbbsd/gamble.c b/pttbbs/mbbsd/gamble.c index d7a96a53..5a93c275 100644 --- a/pttbbs/mbbsd/gamble.c +++ b/pttbbs/mbbsd/gamble.c @@ -1,394 +1,384 @@ -/* $Id: gamble.c,v 1.24 2002/06/29 13:16:50 ptt Exp $ */ +/* $Id: gamble.c,v 1.25 2002/07/05 17:10:27 in2 Exp $ */ #include "bbs.h" #ifndef _BBS_UTIL_C_ #define MAX_ITEM 8 //最大 賭項(item) 個數 #define MAX_ITEM_LEN 30 //最大 每一賭項名字長度 -#define MAX_SUBJECT_LEN 650 //8*81 = 648 最大 主題長度 +#define MAX_SUBJECT_LEN 650 //8*81 = 648 最大 主題長度 -static char betname[MAX_ITEM][MAX_ITEM_LEN]; -static int currbid; +static char betname[MAX_ITEM][MAX_ITEM_LEN]; +static int currbid; -int post_msg(char* bname, char* title, char *msg, char* author) +int +post_msg(char *bname, char *title, char *msg, char *author) { - FILE *fp; - int bid; - fileheader_t fhdr; - char genbuf[256]; - + FILE *fp; + int bid; + fileheader_t fhdr; + char genbuf[256]; + /* 在 bname 板發表新文章 */ sprintf(genbuf, "boards/%c/%s", bname[0], bname); stampfile(genbuf, &fhdr); - fp = fopen(genbuf,"w"); - - if(!fp) - return -1; - - fprintf(fp, "作者: %s 看板: %s\n標題: %s \n",author,bname,title); + fp = fopen(genbuf, "w"); + + if (!fp) + return -1; + + fprintf(fp, "作者: %s 看板: %s\n標題: %s \n", author, bname, title); fprintf(fp, "時間: %s\n", ctime(&now)); - + /* 文章的內容 */ fprintf(fp, "%s", msg); fclose(fp); - + /* 將檔案加入列表 */ strcpy(fhdr.title, title); strcpy(fhdr.owner, author); - setbdir(genbuf,bname); - if(append_record(genbuf, &fhdr, sizeof(fhdr))!=-1) - if((bid = getbnum(bname)) > 0) - setbtotal(bid); + setbdir(genbuf, bname); + if (append_record(genbuf, &fhdr, sizeof(fhdr)) != -1) + if ((bid = getbnum(bname)) > 0) + setbtotal(bid); return 0; } -int post_file(char* bname, char* title, char *filename, char* author) +int +post_file(char *bname, char *title, char *filename, char *author) { - int size=dashs(filename); - char *msg; - FILE *fp; - - if(size<=0) return -1; - if(!(fp=fopen(filename,"r")) ) return -1; - msg= (char *)malloc(size+1); - size = fread(msg,1,size,fp); - msg[size]=0; - size= post_msg(bname, title, msg, author); - fclose(fp); - free(msg); - return size; + int size = dashs(filename); + char *msg; + FILE *fp; + + if (size <= 0) + return -1; + if (!(fp = fopen(filename, "r"))) + return -1; + msg = (char *)malloc(size + 1); + size = fread(msg, 1, size, fp); + msg[size] = 0; + size = post_msg(bname, title, msg, author); + fclose(fp); + free(msg); + return size; } -static int load_ticket_record(char *direct, int ticket[]) +static int +load_ticket_record(char *direct, int ticket[]) { - char buf[256]; - int i, total=0; - FILE *fp; - sprintf(buf,"%s/"FN_TICKET_RECORD,direct); - if(!(fp=fopen(buf,"r"))) return 0; - for(i=0;i<MAX_ITEM && fscanf(fp, "%9d ",&ticket[i]); i++) - total=total+ticket[i]; - fclose(fp); - return total; + char buf[256]; + int i, total = 0; + FILE *fp; + sprintf(buf, "%s/" FN_TICKET_RECORD, direct); + if (!(fp = fopen(buf, "r"))) + return 0; + for (i = 0; i < MAX_ITEM && fscanf(fp, "%9d ", &ticket[i]); i++) + total = total + ticket[i]; + fclose(fp); + return total; } -static int show_ticket_data(char *direct, int *price, boardheader_t *bh) { - int i,count, total = 0, end=0, - ticket[MAX_ITEM] = {0, 0, 0, 0, 0, 0, 0, 0}; - FILE *fp; - char genbuf[256], t[25]; +static int +show_ticket_data(char *direct, int *price, boardheader_t * bh) +{ + int i, count, total = 0, end = 0, ticket[MAX_ITEM] = {0, 0, 0, 0, 0, 0, 0, 0}; + FILE *fp; + char genbuf[256], t[25]; clear(); - if (bh) - { - sprintf(genbuf,"%s 賭盤", bh->brdname); - if(bh->endgamble && now < bh->endgamble && bh->endgamble-now<3600) - { - sprintf(t,"封盤倒數 %d 秒", bh->endgamble-now); - showtitle(genbuf, t); - } - else showtitle(genbuf, BBSNAME); - } - else - showtitle("Ptt賭盤", BBSNAME); + if (bh) { + sprintf(genbuf, "%s 賭盤", bh->brdname); + if (bh->endgamble && now < bh->endgamble && bh->endgamble - now < 3600) { + sprintf(t, "封盤倒數 %d 秒", bh->endgamble - now); + showtitle(genbuf, t); + } else + showtitle(genbuf, BBSNAME); + } else + showtitle("Ptt賭盤", BBSNAME); move(2, 0); - sprintf(genbuf, "%s/"FN_TICKET_ITEMS, direct); - if(!(fp = fopen(genbuf,"r"))) - { - prints("\n目前並沒有舉辦賭盤\n"); - sprintf(genbuf, "%s/"FN_TICKET_OUTCOME, direct); - if(more(genbuf, NA)); - return 0; + sprintf(genbuf, "%s/" FN_TICKET_ITEMS, direct); + if (!(fp = fopen(genbuf, "r"))) { + prints("\n目前並沒有舉辦賭盤\n"); + sprintf(genbuf, "%s/" FN_TICKET_OUTCOME, direct); + if (more(genbuf, NA)); + return 0; } - fgets(genbuf,MAX_ITEM_LEN,fp); - *price=atoi(genbuf); - for(count=0; fgets(betname[count],MAX_ITEM_LEN,fp)&&count<MAX_ITEM; count++) - strtok(betname[count],"\r\n"); + fgets(genbuf, MAX_ITEM_LEN, fp); + *price = atoi(genbuf); + for (count = 0; fgets(betname[count], MAX_ITEM_LEN, fp) && count < MAX_ITEM; count++) + strtok(betname[count], "\r\n"); fclose(fp); prints("\033[32m站規:\033[m 1.可購買以下不同類型的彩票。每張要花 \033[32m%d\033[m 元。\n" - " 2.%s\n" - " 3.開獎時只有一種彩票中獎, 有購買該彩票者, 則可依購買的張數均分" - "總賭金。\n" - " 4.每筆獎金由系統抽取 5% 之稅金%s。\n\n" - "\033[32m%s:\033[m", *price, - bh?"此賭盤由板主負責舉辦並且決定開獎時間結果, 站長不管, 願賭服輸。": - "系統每天 2:00 11:00 16:00 21:00 開獎。", - bh?", 其中 2% 分給開獎板主":"", - bh?"板主自訂規則及說明":"前幾次開獎結果"); - - - sprintf(genbuf, "%s/"FN_TICKET, direct); - if(!dashf(genbuf)) - { - sprintf(genbuf, "%s/"FN_TICKET_END, direct); - end=1; - } + " 2.%s\n" + " 3.開獎時只有一種彩票中獎, 有購買該彩票者, 則可依購買的張數均分" + "總賭金。\n" + " 4.每筆獎金由系統抽取 5% 之稅金%s。\n\n" + "\033[32m%s:\033[m", *price, + bh ? "此賭盤由板主負責舉辦並且決定開獎時間結果, 站長不管, 願賭服輸。" : + "系統每天 2:00 11:00 16:00 21:00 開獎。", + bh ? ", 其中 2% 分給開獎板主" : "", + bh ? "板主自訂規則及說明" : "前幾次開獎結果"); + + + sprintf(genbuf, "%s/" FN_TICKET, direct); + if (!dashf(genbuf)) { + sprintf(genbuf, "%s/" FN_TICKET_END, direct); + end = 1; + } show_file(genbuf, 8, -1, NO_RELOAD); - move(15,0); + move(15, 0); prints("\033[1;32m目前下注狀況:\033[m\n"); - total=load_ticket_record(direct, ticket); - + total = load_ticket_record(direct, ticket); + prints("\033[33m"); - for(i = 0 ; i<count; i++) - { - prints("%d.%-8s: %-7d", i+1, betname[i], ticket[i]); - if(i==3) prints("\n"); - } - prints("\033[m\n\033[42m 下注總金額:\033[31m %d 元 \033[m",total*(*price)); - if(end) - { - prints("\n賭盤已經停止下注\n"); - return -count; - } + for (i = 0; i < count; i++) { + prints("%d.%-8s: %-7d", i + 1, betname[i], ticket[i]); + if (i == 3) + prints("\n"); + } + prints("\033[m\n\033[42m 下注總金額:\033[31m %d 元 \033[m", total * (*price)); + if (end) { + prints("\n賭盤已經停止下注\n"); + return -count; + } return count; } -static void append_ticket_record(char *direct, int ch, int n, int count) { - FILE *fp; - int ticket[8] = {0,0,0,0,0,0,0,0}, i; - char genbuf[256]; - sprintf(genbuf, "%s/"FN_TICKET_USER, direct); - - if((fp = fopen(genbuf,"a"))) { +static void +append_ticket_record(char *direct, int ch, int n, int count) +{ + FILE *fp; + int ticket[8] = {0, 0, 0, 0, 0, 0, 0, 0}, i; + char genbuf[256]; + sprintf(genbuf, "%s/" FN_TICKET_USER, direct); + + if ((fp = fopen(genbuf, "a"))) { fprintf(fp, "%s %d %d\n", cuser.userid, ch, n); fclose(fp); } load_ticket_record(direct, ticket); ticket[ch] += n; sprintf(genbuf, "%s/" FN_TICKET_RECORD, direct); - if((fp = fopen(genbuf,"w"))) { - for(i=0; i<count; i++) - fprintf(fp,"%d ", ticket[i]); + if ((fp = fopen(genbuf, "w"))) { + for (i = 0; i < count; i++) + fprintf(fp, "%d ", ticket[i]); fclose(fp); } } #define lockreturn0(unmode, state) if(lockutmpmode(unmode, state)) return 0 -int ticket(int bid) +int +ticket(int bid) { - int ch, n, price, count, end=0; - char path[128],fn_ticket[128]; - boardheader_t *bh=NULL; - - if(bid) - { - bh=getbcache(bid); - setbpath(path, bh->brdname); - setbfile(fn_ticket, bh->brdname, FN_TICKET); - currbid = bid; - } - else - strcpy(path,"etc/"); + int ch, n, price, count, end = 0; + char path[128], fn_ticket[128]; + boardheader_t *bh = NULL; + + if (bid) { + bh = getbcache(bid); + setbpath(path, bh->brdname); + setbfile(fn_ticket, bh->brdname, FN_TICKET); + currbid = bid; + } else + strcpy(path, "etc/"); lockreturn0(TICKET, LOCK_MULTI); - while(1) { - count=show_ticket_data(path, &price, bh); - if(count<=0) - { - pressanykey(); - break; - } - move(20, 0); - reload_money(); + while (1) { + count = show_ticket_data(path, &price, bh); + if (count <= 0) { + pressanykey(); + break; + } + move(20, 0); + reload_money(); prints("\033[44m錢: %-10d \033[m\n\033[1m請選擇要購買的種類(1~%d)" - "[Q:離開]\033[m:", cuser.money,count); + "[Q:離開]\033[m:", cuser.money, count); ch = igetch(); - /*-- + /*-- Tim011127 - 為了控制CS問題 但是這邊還不能完全解決這問題, + 為了控制CS問題 但是這邊還不能完全解決這問題, 若user通過檢查下去, 剛好板主開獎, 還是會造成user的這次紀錄 很有可能跑到下次賭盤的紀錄去, 也很有可能被板主新開賭盤時洗掉 不過這邊至少可以做到的是, 頂多只會有一筆資料是錯的 --*/ - if(bid && !dashf(fn_ticket)) - { - move(b_lines-1,0); - prints("哇!! 耐ㄚ捏...板主已經停止下注了 不能賭嚕"); - pressanykey(); - break; - } - - if(ch=='q' || ch == 'Q') + if (bid && !dashf(fn_ticket)) { + move(b_lines - 1, 0); + prints("哇!! 耐ㄚ捏...板主已經停止下注了 不能賭嚕"); + pressanykey(); break; - ch-='1'; - if(end || ch >= count || ch < 0) + } + if (ch == 'q' || ch == 'Q') + break; + ch -= '1'; + if (end || ch >= count || ch < 0) continue; - n=0; - ch_buyitem(price, "etc/buyticket", &n); - if(n > 0) - append_ticket_record(path,ch,n,count); - } + n = 0; + ch_buyitem(price, "etc/buyticket", &n); + if (n > 0) + append_ticket_record(path, ch, n, count); + } unlockutmpmode(); return 0; } -int openticket(int bid) { - char path[128],buf[256],outcome[128]; - int i, money=0, count, bet, price, total = 0, ticket[8]={0,0,0,0,0,0,0,0}; - boardheader_t *bh=getbcache(bid); - FILE *fp, *fp1; - - setbpath(path, bh->brdname); - count=-show_ticket_data(path, &price, bh); - if(count==0) - { - setbfile(buf,bh->brdname,FN_TICKET_END); - unlink(buf); //Ptt: 有bug - return 0; - } +int +openticket(int bid) +{ + char path[128], buf[256], outcome[128]; + int i, money = 0, count, bet, price, total = 0, ticket[8] = {0, 0, 0, 0, 0, 0, 0, 0}; + boardheader_t *bh = getbcache(bid); + FILE *fp, *fp1; + + setbpath(path, bh->brdname); + count = -show_ticket_data(path, &price, bh); + if (count == 0) { + setbfile(buf, bh->brdname, FN_TICKET_END); + unlink(buf); +//Ptt: 有bug + return 0; + } lockreturn0(TICKET, LOCK_MULTI); - do - { - do - { - getdata(20, 0, - "\033[1m選擇中獎的號碼(0:不開獎 99:取消退錢)\033[m:", buf, 3, LCECHO); - bet=atoi(buf); - move(0,0); - clrtoeol(); - } while( (bet<0 || bet>count) && bet!=99); - if(bet==0) - {unlockutmpmode(); return 0;} - getdata(21, 0, "\033[1m再次確認輸入號碼\033[m:", buf, 3, LCECHO); - }while(bet!=atoi(buf)); - - if(fork()) - { // Ptt 用fork防止不正常斷線洗錢 - move(22,0); - prints("系統將於稍後自動把中獎結果公佈於看板 若參加者多會需要幾分鐘時間.."); - pressanykey(); - unlockutmpmode(); - return 0; - } + do { + do { + getdata(20, 0, + "\033[1m選擇中獎的號碼(0:不開獎 99:取消退錢)\033[m:", buf, 3, LCECHO); + bet = atoi(buf); + move(0, 0); + clrtoeol(); + } while ((bet < 0 || bet > count) && bet != 99); + if (bet == 0) { + unlockutmpmode(); + return 0; + } + getdata(21, 0, "\033[1m再次確認輸入號碼\033[m:", buf, 3, LCECHO); + } while (bet != atoi(buf)); + + if (fork()) { + //Ptt 姱ork 黎謅ㄔ膨`斷 u ~錢 + move(22, 0); + prints("系統將於稍後自動把中獎結果公佈於看板 若參加者多會需要幾分鐘時間.."); + pressanykey(); + unlockutmpmode(); + return 0; + } close(0); close(1); setproctitle("open ticket"); #ifdef CPULIMIT - { - struct rlimit rml; - rml.rlim_cur = RLIM_INFINITY; - rml.rlim_max = RLIM_INFINITY; - setrlimit(RLIMIT_CPU, &rml); - } -#endif - - - bet -= 1; //轉成矩陣的index - - total=load_ticket_record(path, ticket); - setbfile(buf,bh->brdname,FN_TICKET_END); - if(!(fp1 = fopen(buf,"r"))) - exit(1); - - // 還沒開完獎不能賭博 只要mv一項就好 - if(bet!=98) - { - money=total*price; - demoney(money*0.02); - mail_redenvelop("[賭場抽頭]", cuser.userid, money*0.02, 'n'); - money = ticket[bet] ? money*0.95/ticket[bet]:9999999; - } - else - { - vice(price*10, "賭盤退錢手續費"); - money=price; - } - setbfile(outcome,bh->brdname,FN_TICKET_OUTCOME); - if((fp = fopen(outcome, "w"))) - { - fprintf(fp,"賭盤說明\n"); - while(fgets(buf,256,fp1)) - { - buf[255]=0; - fprintf(fp,"%s",buf); - } - fprintf(fp,"下注情況\n"); - - fprintf(fp, "\033[33m"); - for(i = 0 ; i<count; i++) - { - fprintf(fp, "%d.%-8s: %-7d",i+1,betname[i], ticket[i]); - if(i==3) fprintf(fp,"\n"); - } - fprintf(fp, "\033[m\n"); - - if(bet!=98) - { - fprintf(fp, "\n\n開獎時間: %s \n\n" - "開獎結果: %s \n\n" - "所有金額: %d 元 \n" - "中獎比例: %d張/%d張 (%f)\n" - "每張中獎彩票可得 %d 枚P幣 \n\n", - Cdatelite(&now), betname[bet], total*price, ticket[bet], total, - (float) ticket[bet] / total, money); - - fprintf(fp, "%s 賭盤開出:%s 所有金額:%d 元 獎金/張:%d 元 機率:%1.2f\n\n", - Cdatelite(&now), betname[bet], total*price, money, - total? (float)ticket[bet] / total:0); - } - else - fprintf(fp, "\n\n賭盤取消退錢: %s \n\n", Cdatelite(&now)); - + { + struct rlimit rml; + rml.rlim_cur = RLIM_INFINITY; + rml.rlim_max = RLIM_INFINITY; + setrlimit(RLIMIT_CPU, &rml); + } +#endif + + + bet -= 1; /* 轉成矩陣的index */ + + total = load_ticket_record(path, ticket); + setbfile(buf, bh->brdname, FN_TICKET_END); + if (!(fp1 = fopen(buf, "r"))) + exit(1); + + /* 還沒開完獎不能賭博 只要mv一項就好 */ + if (bet != 98) { + money = total * price; + demoney(money * 0.02); + mail_redenvelop("[賭場抽頭]", cuser.userid, money * 0.02, 'n'); + money = ticket[bet] ? money * 0.95 / ticket[bet] : 9999999; + } else { + vice(price * 10, "賭盤退錢手續費"); + money = price; + } + setbfile(outcome, bh->brdname, FN_TICKET_OUTCOME); + if ((fp = fopen(outcome, "w"))) { + fprintf(fp, "賭盤說明\n"); + while (fgets(buf, 256, fp1)) { + buf[255] = 0; + fprintf(fp, "%s", buf); + } + fprintf(fp, "下注情況\n"); + + fprintf(fp, "\033[33m"); + for (i = 0; i < count; i++) { + fprintf(fp, "%d.%-8s: %-7d", i + 1, betname[i], ticket[i]); + if (i == 3) + fprintf(fp, "\n"); + } + fprintf(fp, "\033[m\n"); + + if (bet != 98) { + fprintf(fp, "\n\n開獎時間: %s \n\n" + "開獎結果: %s \n\n" + "所有金額: %d 元 \n" + "中獎比例: %d張/%d張 (%f)\n" + "每張中獎彩票可得 %d 枚P幣 \n\n", + Cdatelite(&now), betname[bet], total * price, ticket[bet], total, + (float)ticket[bet] / total, money); + + fprintf(fp, "%s 賭盤開出:%s 所有金額:%d 元 獎金/張:%d 元 機率:%1.2f\n\n", + Cdatelite(&now), betname[bet], total * price, money, + total ? (float)ticket[bet] / total : 0); + } else + fprintf(fp, "\n\n賭盤取消退錢: %s \n\n", Cdatelite(&now)); + } - fclose(fp1); + fclose(fp1); setbfile(buf, bh->brdname, FN_TICKET_END); setbfile(path, bh->brdname, FN_TICKET_LOCK); - rename(buf, path); + rename(buf, path); /* - 以下是給錢動作 - */ + * 以下是給錢動作 + */ setbfile(buf, bh->brdname, FN_TICKET_USER); - if ((bet==98 || ticket[bet]) && (fp1 = fopen(buf, "r"))) - { - int mybet, uid; - char userid[IDLEN]; - - while (fscanf(fp1, "%s %d %d\n", userid, &mybet, &i) != EOF) - { - if (bet==98 && mybet>=0 && mybet<count ) - { - fprintf(fp,"%s 買了 %d 張 %s, 退回 %d 枚P幣\n" - ,userid, i, betname[mybet], money); - sprintf(buf, "%s 賭場退錢! $ %d", bh->brdname, money * i); - } - else if (mybet == bet) - { - fprintf(fp,"恭喜 %s 買了%d 張 %s, 獲得 %d 枚P幣\n" - ,userid, i, betname[mybet], money); - sprintf(buf, "%s 中獎咧! $ %d", bh->brdname, money * i); - } - else - continue; - if((uid=searchuser(userid))==0) continue; - deumoney(uid, money * i); - mail_id(userid, buf, "etc/ticket.win", "Ptt賭場"); - } - fclose(fp1); - } + if ((bet == 98 || ticket[bet]) && (fp1 = fopen(buf, "r"))) { + int mybet, uid; + char userid[IDLEN]; + while (fscanf(fp1, "%s %d %d\n", userid, &mybet, &i) != EOF) { + if (bet == 98 && mybet >= 0 && mybet < count) { + fprintf(fp, "%s 買了 %d 張 %s, 退回 %d 枚P幣\n" + ,userid, i, betname[mybet], money); + sprintf(buf, "%s 賭場退錢! $ %d", bh->brdname, money * i); + } else if (mybet == bet) { + fprintf(fp, "恭喜 %s 買了%d 張 %s, 獲得 %d 枚P幣\n" + ,userid, i, betname[mybet], money); + sprintf(buf, "%s 中獎咧! $ %d", bh->brdname, money * i); + } else + continue; + if ((uid = searchuser(userid)) == 0) + continue; + deumoney(uid, money * i); + mail_id(userid, buf, "etc/ticket.win", "Ptt賭場"); + } + fclose(fp1); + } fclose(fp); - if(bet!=98) - sprintf(buf, "[公告] %s 賭盤開獎", bh->brdname); + if (bet != 98) + sprintf(buf, "[公告] %s 賭盤開獎", bh->brdname); else - sprintf(buf, "[公告] %s 賭盤取消", bh->brdname); + sprintf(buf, "[公告] %s 賭盤取消", bh->brdname); post_file(bh->brdname, buf, outcome, "[賭神]"); - post_file("Record", buf+7, outcome, "[馬路探子]"); + post_file("Record", buf + 7, outcome, "[馬路探子]"); - setbfile(buf, bh->brdname, FN_TICKET_RECORD); + setbfile(buf, bh->brdname, FN_TICKET_RECORD); unlink(buf); - setbfile(buf, bh->brdname, FN_TICKET_USER); + setbfile(buf, bh->brdname, FN_TICKET_USER); unlink(buf); - setbfile(buf, bh->brdname, FN_TICKET_LOCK); + setbfile(buf, bh->brdname, FN_TICKET_LOCK); unlink(buf); exit(1); return 0; } -int ticket_main() { +int +ticket_main() +{ ticket(0); return 0; } diff --git a/pttbbs/mbbsd/gomo.c b/pttbbs/mbbsd/gomo.c index 6969df7a..1eb6ca77 100644 --- a/pttbbs/mbbsd/gomo.c +++ b/pttbbs/mbbsd/gomo.c @@ -1,17 +1,19 @@ -/* $Id: gomo.c,v 1.5 2002/06/04 13:08:33 in2 Exp $ */ +/* $Id: gomo.c,v 1.6 2002/07/05 17:10:27 in2 Exp $ */ #include "bbs.h" -static char *chess[] = { "●", "○" }; -static int tick, lastcount, mylasttick, hislasttick; +static char *chess[] = {"●", "○"}; +static int tick, lastcount, mylasttick, hislasttick; typedef struct { - char x; - char y; -} Horder_t; + char x; + char y; +} Horder_t; static Horder_t *v, pool[225]; -static void HO_init() { +static void +HO_init() +{ memset(pool, 0, sizeof(pool)); v = pool; pat = pat_gomoku; @@ -19,82 +21,92 @@ static void HO_init() { memset(ku, 0, sizeof(ku)); } -static void HO_add(Horder_t *mv) { +static void +HO_add(Horder_t * mv) +{ *v++ = *mv; } -static void HO_undo(Horder_t *mv) { - char *str = "┌┬┐├┼┤└┴┘"; - int n1, n2, loc; +static void +HO_undo(Horder_t * mv) +{ + char *str = "┌┬┐├┼┤└┴┘"; + int n1, n2, loc; *mv = *(--v); ku[(int)mv->x][(int)mv->y] = BBLANK; BGOTO(mv->x, mv->y); n1 = (mv->x == 0) ? 0 : (mv->x == 14) ? 2 : 1; - n2 = (mv->y == 14)? 0 : (mv->y == 0) ? 2 : 1; - loc= 2 * ( n2 * 3 + n1); + n2 = (mv->y == 14) ? 0 : (mv->y == 0) ? 2 : 1; + loc = 2 * (n2 * 3 + n1); prints("%.2s", str + loc); } -static void HO_log(char *user) { - int i; - FILE *log; - char buf[80]; - char buf1[80]; - char title[80]; - Horder_t *ptr = pool; - fileheader_t mymail; +static void +HO_log(char *user) +{ + int i; + FILE *log; + char buf[80]; + char buf1[80]; + char title[80]; + Horder_t *ptr = pool; + fileheader_t mymail; sprintf(buf, "home/%c/%s/F.%d", cuser.userid[0], cuser.userid, rand() & 65535); log = fopen(buf, "w"); - - for(i = 1; i < 17; i++) + + for (i = 1; i < 17; i++) fprintf(log, "%.*s\n", big_picture[i].len, big_picture[i].data); - + i = 0; do { fprintf(log, "[%2d]%s ==> %c%d%c", i + 1, chess[i % 2], - 'A' + ptr->x, ptr->y + 1, (i % 2) ? '\n' : '\t'); + 'A' + ptr->x, ptr->y + 1, (i % 2) ? '\n' : '\t'); i++; - } while( ++ptr < v); + } while (++ptr < v); fclose(log); - + sethomepath(buf1, cuser.userid); stampfile(buf1, &mymail); - - mymail.filemode = FILE_READ|FILE_HOLD; + + mymail.filemode = FILE_READ | FILE_HOLD; strcpy(mymail.owner, "[備.忘.錄]"); sprintf(mymail.title, "\033[37;41m棋譜\033[m %s VS %s", cuser.userid, user); sethomedir(title, cuser.userid); Rename(buf, buf1); - append_record(title, &mymail, sizeof(mymail)); - + append_record(title, &mymail, sizeof(mymail)); + unlink(buf); } -static int countgomo() { - Horder_t *ptr; - int i; - +static int +countgomo() +{ + Horder_t *ptr; + int i; + ptr = pool; i = 0; do { i++; - } while(++ptr < v); + } while (++ptr < v); return i; } -static int chkmv(Horder_t *mv, int color, int limit) { - char *xtype[] = {"\033[1;31m跳三\033[m", "\033[1;31m活三\033[m", - "\033[1;31m死四\033[m", "\033[1;31m跳四\033[m", - "\033[1;31m活四\033[m", "\033[1;31m四三\033[m", - "\033[1;31m雙三\033[m", "\033[1;31m雙四\033[m", - "\033[1;31m雙四\033[m", "\033[1;31m連六\033[m", - "\033[1;31m連五\033[m"}; - int rule = getstyle(mv->x, mv->y, color, limit); - if(rule > 1 && rule < 13) { +static int +chkmv(Horder_t * mv, int color, int limit) +{ + char *xtype[] = {"\033[1;31m跳三\033[m", "\033[1;31m活三\033[m", + "\033[1;31m死四\033[m", "\033[1;31m跳四\033[m", + "\033[1;31m活四\033[m", "\033[1;31m四三\033[m", + "\033[1;31m雙三\033[m", "\033[1;31m雙四\033[m", + "\033[1;31m雙四\033[m", "\033[1;31m連六\033[m", + "\033[1;31m連五\033[m"}; + int rule = getstyle(mv->x, mv->y, color, limit); + if (rule > 1 && rule < 13) { move(15, 40); outs(xtype[rule - 2]); bell(); @@ -102,70 +114,76 @@ static int chkmv(Horder_t *mv, int color, int limit) { return chkwin(rule, limit); } -static int gomo_key(int fd, int ch, Horder_t *mv) { - if( ch >= 'a' && ch <= 'o') { - char pbuf[4], vx, vy; - - *pbuf = ch; - if(fd) +static int +gomo_key(int fd, int ch, Horder_t * mv) +{ + if (ch >= 'a' && ch <= 'o') { + char pbuf[4], vx, vy; + + *pbuf = ch; + if (fd) add_io(0, 0); - oldgetdata(17, 0, "直接指定位置 :", pbuf, sizeof(pbuf), DOECHO); - if(fd) + oldgetdata(17, 0, "直接指定位置 :", pbuf, sizeof(pbuf), DOECHO); + if (fd) add_io(fd, 0); - vx = pbuf[0] - 'a'; - vy = atoi(pbuf + 1) - 1; - if(vx >= 0 && vx < 15 && vy >= 0 && vy < 15 && - ku[(int)vx][(int)vy] == BBLANK) { + vx = pbuf[0] - 'a'; + vy = atoi(pbuf + 1) - 1; + if (vx >= 0 && vx < 15 && vy >= 0 && vy < 15 && + ku[(int)vx][(int)vy] == BBLANK) { mv->x = vx; mv->y = vy; return 1; - } + } } else { - switch(ch) { + switch (ch) { case KEY_RIGHT: - mv->x = (mv->x == BRDSIZ - 1) ? mv->x : mv->x + 1; - break; + mv->x = (mv->x == BRDSIZ - 1) ? mv->x : mv->x + 1; + break; case KEY_LEFT: - mv->x = (mv->x == 0 ) ? 0 : mv->x - 1; - break; + mv->x = (mv->x == 0) ? 0 : mv->x - 1; + break; case KEY_UP: - mv->y = (mv->y == BRDSIZ - 1) ? mv->y : mv->y + 1; - break; + mv->y = (mv->y == BRDSIZ - 1) ? mv->y : mv->y + 1; + break; case KEY_DOWN: - mv->y = (mv->y == 0 ) ? 0 : mv->y - 1; - break; + mv->y = (mv->y == 0) ? 0 : mv->y - 1; + break; case ' ': case '\r': - if(ku[(int)mv->x][(int)mv->y] == BBLANK) + if (ku[(int)mv->x][(int)mv->y] == BBLANK) return 1; - } + } } return 0; } -static int reload_gomo() { +static int +reload_gomo() +{ passwd_query(usernum, &xuser); cuser.five_win = xuser.five_win; cuser.five_lose = xuser.five_lose; cuser.five_tie = xuser.five_tie; return 0; -} - -int gomoku(int fd) { - Horder_t mv; - int me, he, win, ch; - int hewantpass, iwantpass; - userinfo_t *my = currutmp; - +} + +int +gomoku(int fd) +{ + Horder_t mv; + int me, he, win, ch; + int hewantpass, iwantpass; + userinfo_t *my = currutmp; + HO_init(); me = !(my->turn) + 1; he = my->turn + 1; win = 1; - tick=now + MAX_TIME; + tick = now + MAX_TIME; lastcount = MAX_TIME; setutmpmode(M_FIVE); clear(); - + prints("\033[1;46m 五子棋對戰 \033[45m%30s VS %-30s\033[m", cuser.userid, my->mateid); show_file("etc/@five", 1, -1, ONLY_COLOR); @@ -175,44 +193,44 @@ int gomoku(int fd) { prints("\033[1;33m%s", cuser.userid); move(17, 40); prints("\033[1;33m%s", my->mateid); - + reload_gomo(); move(16, 60); prints("\033[1;31m%d\033[37m勝 \033[34m%d\033[37m敗 \033[36m%d\033[37m和" "\033[m", cuser.five_win, cuser.five_lose, cuser.five_tie); - - getuser(my->mateid); - move(17, 60); + + getuser(my->mateid); + move(17, 60); prints("\033[1;31m%d\033[37m勝 \033[34m%d\033[37m敗 \033[36m%d\033[37m" "和\033[m", xuser.five_win, xuser.five_lose, xuser.five_tie); - + cuser.five_lose++; /* 一進來先加一場敗場, 贏了後再扣回去, 避免快輸了惡意斷線 */ passwd_update(usernum, &cuser); - + add_io(fd, 0); - + hewantpass = iwantpass = 0; mv.x = mv.y = 7; move(18, 40); prints("%s時間還剩%d:%02d\n", my->turn ? "你的" : "對方", - MAX_TIME / 60, MAX_TIME % 60); - for(;;) { + MAX_TIME / 60, MAX_TIME % 60); + for (;;) { move(13, 40); - outs(my->turn ? "輪到自己下了!": "等待對方下子.."); - if(lastcount != tick-now) { - lastcount = tick-now; + outs(my->turn ? "輪到自己下了!" : "等待對方下子.."); + if (lastcount != tick - now) { + lastcount = tick - now; move(18, 40); prints("%s時間還剩%d:%02d\n", my->turn ? "你的" : "對方", lastcount / 60, lastcount % 60); - if(lastcount <= 0 && my->turn) { + if (lastcount <= 0 && my->turn) { move(19, 40); outs("時間已到, 你輸了"); my->five_lose++; send(fd, '\0', 1, 0); break; } - if(lastcount <= -5 && !my->turn) { + if (lastcount <= -5 && !my->turn) { move(19, 40); outs("對手太久沒下, 你贏了!"); win = 1; @@ -222,68 +240,67 @@ int gomoku(int fd) { passwd_update(usernum, &cuser); mv.x = mv.y = -2; send(fd, &mv, sizeof(Horder_t), 0); - mv = *(v - 1); - break; + mv = *(v - 1); + break; } } move(14, 40); - if(hewantpass) { + if (hewantpass) { outs("\033[1;32m和棋要求!\033[m"); bell(); } else clrtoeol(); BGOTOCUR(mv.x, mv.y); ch = igetkey(); - if(ch != I_OTHERDATA) + if (ch != I_OTHERDATA) iwantpass = 0; - if(ch == 'q') { - if(countgomo() < 10) { - cuser.five_lose--; + if (ch == 'q') { + if (countgomo() < 10) { + cuser.five_lose--; passwd_update(usernum, &cuser); } send(fd, '\0', 1, 0); break; - } else if(ch == 'u' && !my->turn && v > pool) { + } else if (ch == 'u' && !my->turn && v > pool) { mv.x = mv.y = -1; ch = send(fd, &mv, sizeof(Horder_t), 0); - if(ch == sizeof(Horder_t)) { - HO_undo(&mv); + if (ch == sizeof(Horder_t)) { + HO_undo(&mv); tick = mylasttick; my->turn = 1; continue; - } else + } else break; } - if(ch == 'p') { - if(my->turn ) { - if(iwantpass == 0) { + if (ch == 'p') { + if (my->turn) { + if (iwantpass == 0) { iwantpass = 1; mv.x = mv.y = -2; send(fd, &mv, sizeof(Horder_t), 0); mv = *(v - 1); } continue; - } else if(hewantpass) { + } else if (hewantpass) { win = 0; cuser.five_lose--; cuser.five_tie++; my->five_tie++; passwd_update(usernum, &cuser); - mv.x=mv.y=-2; + mv.x = mv.y = -2; send(fd, &mv, sizeof(Horder_t), 0); mv = *(v - 1); break; } } - - if(ch == I_OTHERDATA) { + if (ch == I_OTHERDATA) { ch = recv(fd, &mv, sizeof(Horder_t), 0); - if(ch != sizeof(Horder_t)) { - lastcount=tick-now; - if(lastcount >=0) { + if (ch != sizeof(Horder_t)) { + lastcount = tick - now; + if (lastcount >= 0) { win = 1; cuser.five_lose--; - if(countgomo() >=10) { + if (countgomo() >= 10) { cuser.five_win++; my->five_win++; } @@ -296,8 +313,8 @@ int gomoku(int fd) { my->five_lose++; break; } - } else if(mv.x == -2 && mv.y == -2) { - if(iwantpass == 1) { + } else if (mv.x == -2 && mv.y == -2) { + if (iwantpass == 1) { win = 0; cuser.five_lose--; cuser.five_tie++; @@ -310,15 +327,14 @@ int gomoku(int fd) { continue; } } - if(my->turn && mv.x == -1 && mv.y == -1) { + if (my->turn && mv.x == -1 && mv.y == -1) { outmsg("對方悔棋"); tick = hislasttick; HO_undo(&mv); my->turn = 0; continue; } - - if(!my->turn) { + if (!my->turn) { win = chkmv(&mv, he, he == BBLACK); HO_add(&mv); hislasttick = tick; @@ -327,16 +343,16 @@ int gomoku(int fd) { bell(); BGOTO(mv.x, mv.y); outs(chess[he - 1]); - - if(win) { + + if (win) { outmsg(win == 1 ? "對方贏了!" : "對方禁手"); - if(win != 1) { + if (win != 1) { cuser.five_lose--; cuser.five_win++; my->five_win++; passwd_update(usernum, &cuser); } else - my->five_lose++; + my->five_lose++; win = -win; break; } @@ -344,33 +360,32 @@ int gomoku(int fd) { } continue; } - - if(my->turn) { - if(gomo_key(fd, ch, &mv)) + if (my->turn) { + if (gomo_key(fd, ch, &mv)) my->turn = 0; else continue; - - if(!my->turn) { + + if (!my->turn) { HO_add(&mv); BGOTO(mv.x, mv.y); outs(chess[me - 1]); - win = chkmv( &mv, me, me == BBLACK); + win = chkmv(&mv, me, me == BBLACK); ku[(int)mv.x][(int)mv.y] = me; mylasttick = tick; - tick = now + MAX_TIME; /*倒數*/ + tick = now + MAX_TIME; /* 倒數 */ lastcount = MAX_TIME; - if(send(fd, &mv, sizeof(Horder_t), 0) != sizeof(Horder_t)) + if (send(fd, &mv, sizeof(Horder_t), 0) != sizeof(Horder_t)) break; - if(win) { - outmsg(win == 1 ? "我贏囉~~" : "禁手輸了" ); - if(win == 1) { + if (win) { + outmsg(win == 1 ? "我贏囉~~" : "禁手輸了"); + if (win == 1) { cuser.five_lose--; cuser.five_win++; my->five_win++; passwd_update(usernum, &cuser); - } else - my->five_lose++; + } else + my->five_lose++; break; } move(15, 40); @@ -380,13 +395,13 @@ int gomoku(int fd) { } add_io(0, 0); close(fd); - + igetch(); - if(v > pool) { - char ans[4]; - - getdata(19 , 0, "要保留本局成棋譜嗎?(y/N)", ans, sizeof(ans), LCECHO); - if(*ans == 'y') + if (v > pool) { + char ans[4]; + + getdata(19, 0, "要保留本局成棋譜嗎?(y/N)", ans, sizeof(ans), LCECHO); + if (*ans == 'y') HO_log(my->mateid); } return 0; diff --git a/pttbbs/mbbsd/gomo1.c b/pttbbs/mbbsd/gomo1.c index c741f538..462ceb47 100644 --- a/pttbbs/mbbsd/gomo1.c +++ b/pttbbs/mbbsd/gomo1.c @@ -1,87 +1,95 @@ -/* $Id: gomo1.c,v 1.2 2002/06/04 13:08:33 in2 Exp $ */ +/* $Id: gomo1.c,v 1.3 2002/07/05 17:10:27 in2 Exp $ */ #include "bbs.h" #define QCAST int (*)(const void *, const void *) /* pattern and advance map */ -static int intrevcmp(const void *a, const void *b) { +static int +intrevcmp(const void *a, const void *b) +{ return (*(int *)b - *(int *)a); } /* x,y: 0..BRDSIZ-1 ; color: CBLACK,CWHITE ; dx,dy: -1,0,+1 */ -static int gomo_getindex(int x, int y, int color, int dx, int dy) { - int i, k, n; - for(n = -1, i = 0, k = 1; i < 5; i++, k <<= 1) { +static int +gomo_getindex(int x, int y, int color, int dx, int dy) +{ + int i, k, n; + for (n = -1, i = 0, k = 1; i < 5; i++, k <<= 1) { x += dx; y += dy; - - if((x < 0) || (x >= BRDSIZ) || ( y < 0) || ( y >= BRDSIZ)) { + + if ((x < 0) || (x >= BRDSIZ) || (y < 0) || (y >= BRDSIZ)) { n += k; break; - } else if(ku[x][y] != BBLANK) { + } else if (ku[x][y] != BBLANK) { n += k; - if(ku[x][y] != color) + if (ku[x][y] != color) break; } } - - if(i >= 5) + + if (i >= 5) n += k; return n; } -int chkwin(int style, int limit) { - if(style == 0x0c) - return 1 /* style */; - else if(limit == 0) { - if(style == 0x0b) - return 1 /* style */; +int +chkwin(int style, int limit) +{ + if (style == 0x0c) + return 1 /* style */ ; + else if (limit == 0) { + if (style == 0x0b) + return 1 /* style */ ; return 0; } - if((style < 0x0c) && (style > 0x07)) - return -1 /* -style */; + if ((style < 0x0c) && (style > 0x07)) + return -1 /* -style */ ; return 0; } /* x,y: 0..BRDSIZ-1 ; color: CBLACK,CWHITE ; limit:1,0 ; dx,dy: 0,1 */ -static int dirchk(int x, int y, int color, int limit, int dx, int dy) { - int le, ri, loc, style = 0; +static int +dirchk(int x, int y, int color, int limit, int dx, int dy) +{ + int le, ri, loc, style = 0; le = gomo_getindex(x, y, color, -dx, -dy); - ri = gomo_getindex(x, y, color, dx, dy); + ri = gomo_getindex(x, y, color, dx, dy); loc = (le > ri) ? (((le * (le + 1)) >> 1) + ri) : (((ri * (ri + 1)) >> 1) + le); - + style = pat[loc]; - - if(limit == 0) + + if (limit == 0) return (style & 0x0f); style >>= 4; - - if((style == 3) || (style == 2)) { - int i, n = 0, tmp, nx, ny; - + + if ((style == 3) || (style == 2)) { + int i, n = 0, tmp, nx, ny; + n = adv[loc >> 1]; - + ((loc & 1) == 0) ? (n >>= 4) : (n &= 0x0f); - + ku[x][y] = color; - - for(i = 0; i < 2; i++) { - if((tmp = (i == 0) ? (-(n >> 2)):(n & 3)) != 0) { + + for (i = 0; i < 2; i++) { + if ((tmp = (i == 0) ? (-(n >> 2)) : (n & 3)) != 0) { nx = x + (le > ri ? 1 : -1) * tmp * dx; ny = y + (le > ri ? 1 : -1) * tmp * dy; - - if((dirchk(nx, ny, color, 0, dx, dy) == 0x06) && - (chkwin(getstyle(nx, ny, color, limit), limit) >= 0)) + + if ((dirchk(nx, ny, color, 0, dx, dy) == 0x06) && + (chkwin(getstyle(nx, ny, color, limit), limit) >= 0)) break; } } - if(i >= 2) + if (i >= 2) style = 0; ku[x][y] = BBLANK; } @@ -92,26 +100,28 @@ static int dirchk(int x, int y, int color, int limit, int dx, int dy) { /* 四三=7 活四=6 斷四=5 死四=4 活三=3 斷三=2 保留=1 無效=0 */ /* x,y: 0..BRDSIZ-1 ; color: CBLACK,CWHITE ; limit: 1,0 */ -int getstyle(int x, int y, int color, int limit) { - int i, j, dir[4], style; +int +getstyle(int x, int y, int color, int limit) +{ + int i, j, dir[4], style; - if((x < 0) || (x >= BRDSIZ) || ( y < 0) || (y >= BRDSIZ)) + if ((x < 0) || (x >= BRDSIZ) || (y < 0) || (y >= BRDSIZ)) return 0x0f; - if(ku[x][y] != BBLANK) + if (ku[x][y] != BBLANK) return 0x0d; - for(i = 0; i < 4; i++) - dir[i] = dirchk(x, y, color, limit, i ? (i>>1) : -1, i ? (i&1) : 1); + for (i = 0; i < 4; i++) + dir[i] = dirchk(x, y, color, limit, i ? (i >> 1) : -1, i ? (i & 1) : 1); qsort(dir, 4, sizeof(int), (QCAST)intrevcmp); - if((style = dir[0]) >= 2) { - for(i = 1, j = 6 + (limit ? 1 : 0); i < 4; i++) { - if((style > j) || (dir[i] < 2)) + if ((style = dir[0]) >= 2) { + for (i = 1, j = 6 + (limit ? 1 : 0); i < 4; i++) { + if ((style > j) || (dir[i] < 2)) break; - if(dir[i] > 3) + if (dir[i] > 3) style = 9; - else if((style < 7) && (style > 3)) + else if ((style < 7) && (style > 3)) style = 7; else style = 8; diff --git a/pttbbs/mbbsd/guess.c b/pttbbs/mbbsd/guess.c index 2a7e6fdb..1f683ce2 100644 --- a/pttbbs/mbbsd/guess.c +++ b/pttbbs/mbbsd/guess.c @@ -1,159 +1,177 @@ -/* $Id: guess.c,v 1.3 2002/06/04 13:08:33 in2 Exp $ */ +/* $Id: guess.c,v 1.4 2002/07/05 17:10:27 in2 Exp $ */ #include "bbs.h" #define LOGPASS BBSHOME "/etc/winguess.log" -static void show_table(char TABLE[], char ifcomputer) { - int i; - +static void +show_table(char TABLE[], char ifcomputer) +{ + int i; + move(0, 35); prints("\033[1;44;33m 【 猜數字 】 \033[m"); move(8, 1); prints("\033[1;44;36m目 前 倍 率\033[m\n"); prints("\033[1;33m=================\033[m\n"); - if(ifcomputer) { + if (ifcomputer) { prints("贏電腦: 2 倍\n"); prints("輸電腦: 0 倍\n"); } else { - for(i = 1; i <= 6; i++) - prints("第%d次, %02d倍\n",i,TABLE[i]); + for (i = 1; i <= 6; i++) + prints("第%d次, %02d倍\n", i, TABLE[i]); } prints("\033[33m=================\033[m"); } -static unsigned long int get_money(void) { - int money, i; - char data[20]; - +static unsigned long int +get_money(void) +{ + int money, i; + char data[20]; + move(1, 0); prints("您目前有:%d Ptt$", cuser.money); do { getdata(2, 0, "要賭多少(5-10或按q離開): ", data, 9, LCECHO); money = strlen(data); - if(data[0] == 'q' || data[0] == 'Q') { + if (data[0] == 'q' || data[0] == 'Q') { unlockutmpmode(); return 0; } - for(i = 0; i < money; i++) - if(data[i]<'0' || data[i]>'9') { + for (i = 0; i < money; i++) + if (data[i] < '0' || data[i] > '9') { money = -1; break; } - if(money != -1){ + if (money != -1) { money = atol(data); reload_money(); - if(money > cuser.money || money <= 4 || money > 10 || - money < 1) + if (money > cuser.money || money <= 4 || money > 10 || + money < 1) money = -1; - } - } while(money == -1); - move(1,0); + } + } while (money == -1); + move(1, 0); clrtoeol(); reload_money(); prints("您目前有:%d Ptt$", cuser.money - money); return money; } -static int check_data(char *str) { - int i, j; - - if(strlen(str) != 4) +static int +check_data(char *str) +{ + int i, j; + + if (strlen(str) != 4) return -1; - for(i = 0; i < 4; i++) - if(str[i] < '0' || str[i] > '9') + for (i = 0; i < 4; i++) + if (str[i] < '0' || str[i] > '9') return -1; - for(i = 0; i < 4; i++) - for(j = i + 1; j < 4; j++) - if(str[i] == str[j]) + for (i = 0; i < 4; i++) + for (j = i + 1; j < 4; j++) + if (str[i] == str[j]) return -1; return 1; } -static char *get_data(int count) { - static char data[5]; - while(1) { +static char * +get_data(int count) +{ + static char data[5]; + while (1) { getdata(6, 0, "輸入四位數字(不重複): ", data, sizeof(data), LCECHO); - if(check_data(data) == 1) + if (check_data(data) == 1) break; } return data; } -static int guess_play(char *data, char *answer, int count) { - int A_num = 0, B_num = 0; - int i, j; - - for(i = 0; i < 4; i++) { - if(data[i] == answer[i]) +static int +guess_play(char *data, char *answer, int count) +{ + int A_num = 0, B_num = 0; + int i, j; + + for (i = 0; i < 4; i++) { + if (data[i] == answer[i]) A_num++; - for(j = 0; j < 4; j++) - if(i == j) + for (j = 0; j < 4; j++) + if (i == j) continue; - else if(data[i] == answer[j]) { + else if (data[i] == answer[j]) { B_num++; break; } } - if(A_num == 4) + if (A_num == 4) return 1; - move(count + 8,55); + move(count + 8, 55); prints("%s => \033[1;32m%dA %dB\033[m", data, A_num, B_num); return 0; } -static int result(int correct, int number) { - char a = 0, b = 0, i, j; - char n1[5], n2[5]; - - sprintf(n1, "%04d",correct); - sprintf(n2, "%04d",number); - for(i = 0; i < 4; i++) - for(j = 0; j < 4; j++) - if(n1[(int)i] == n2[(int)j]) +static int +result(int correct, int number) +{ + char a = 0, b = 0, i, j; + char n1[5], n2[5]; + + sprintf(n1, "%04d", correct); + sprintf(n2, "%04d", number); + for (i = 0; i < 4; i++) + for (j = 0; j < 4; j++) + if (n1[(int)i] == n2[(int)j]) b++; - for(i = 0; i < 4; i++) - if(n1[(int)i] == n2[(int)i]) { + for (i = 0; i < 4; i++) + if (n1[(int)i] == n2[(int)i]) { b--; a++; } return 10 * a + b; } -static int legal(int number) { - char i, j; - char temp[5]; - +static int +legal(int number) +{ + char i, j; + char temp[5]; + sprintf(temp, "%04d", number); - for(i = 0; i < 4; i++) - for(j = i + 1; j < 4; j++) - if(temp[(int)i] == temp[(int)j]) + for (i = 0; i < 4; i++) + for (j = i + 1; j < 4; j++) + if (temp[(int)i] == temp[(int)j]) return 0; return 1; } -static void initcomputer(char flag[]) { - int i; - - for(i = 0; i < 10000; i++) - if(legal(i)) +static void +initcomputer(char flag[]) +{ + int i; + + for (i = 0; i < 10000; i++) + if (legal(i)) flag[i] = 1; - else + else flag[i] = 0; } -static int computer(int correct, int total, char flag[], int n[]) { - int guess; - static int j; - int k,i; - char data[5]; - - if(total == 1) { +static int +computer(int correct, int total, char flag[], int n[]) +{ + int guess; + static int j; + int k, i; + char data[5]; + + if (total == 1) { do { guess = rand() % 10000; - } while(!legal(guess)); - } else + } while (!legal(guess)); + } else guess = n[rand() % j]; k = result(correct, guess); - if(k == 40) { + if (k == 40) { move(total + 8, 25); sprintf(data, "%04d", guess); prints("%s => 猜中了!!", data); @@ -164,25 +182,27 @@ static int computer(int correct, int total, char flag[], int n[]) { prints("%s => \033[1;32m%dA %dB\033[m", data, k / 10, k % 10); } j = 0; - for(i = 0; i < 10000; i++) - if(flag[i]) { - if(result(i, guess) != k) + for (i = 0; i < 10000; i++) + if (flag[i]) { + if (result(i, guess) != k) flag[i] = 0; - else + else n[j++] = i; } return 0; } -static void Diff_Random(char *answer) { - register int i = 0, j, k; - - while(i < 4) { +static void +Diff_Random(char *answer) +{ + register int i = 0, j, k; + + while (i < 4) { k = rand() % 10 + '0'; - for(j = 0; j < i; j++) - if(k == answer[j]) + for (j = 0; j < i; j++) + if (k == answer[j]) break; - if(j == i) { + if (j == i) { answer[j] = k; i++; } @@ -192,24 +212,26 @@ static void Diff_Random(char *answer) { #define lockreturn0(unmode, state) if(lockutmpmode(unmode, state)) return 0 -int guess_main() { +int +guess_main() +{ unsigned long int money; - char computerwin = 0,youwin = 0; - int count = 0,c_count = 0; - char ifcomputer[2]; - char answer[5]; - int *n = NULL; - char yournum[5]; - char *flag = NULL; - static char TABLE[]={0,10,8,4,2,1,0,0,0,0,0}; - FILE *file; + char computerwin = 0, youwin = 0; + int count = 0, c_count = 0; + char ifcomputer[2]; + char answer[5]; + int *n = NULL; + char yournum[5]; + char *flag = NULL; + static char TABLE[] = {0, 10, 8, 4, 2, 1, 0, 0, 0, 0, 0}; + FILE *file; clear(); showtitle("猜數字", BBSName); lockreturn0(GUESSNUM, LOCK_MULTI); reload_money(); - if(cuser.money < 5) { + if (cuser.money < 5) { clear(); move(12, 35); prints("錢不夠啦 至少要 5 Ptt$"); @@ -217,29 +239,29 @@ int guess_main() { pressanykey(); return 1; } - if((money = get_money()) == 0) - return 1; - vice(money,"猜數字"); - + if ((money = get_money()) == 0) + return 1; + vice(money, "猜數字"); + Diff_Random(answer); move(2, 0); clrtoeol(); prints("您下注 :%d Ptt$", money); - + getdata_str(4, 0, "您要和電腦比賽嗎? <y/n>[y]:", - ifcomputer, sizeof(ifcomputer), LCECHO, "y"); - if(ifcomputer[0] == 'y') { + ifcomputer, sizeof(ifcomputer), LCECHO, "y"); + if (ifcomputer[0] == 'y') { ifcomputer[0] = 1; show_table(TABLE, 1); } else { ifcomputer[0] = 0; show_table(TABLE, 0); } - if(ifcomputer[0]) { + if (ifcomputer[0]) { do { getdata(5, 0, "請輸入您要讓電腦猜的數字: ", yournum, sizeof(yournum), LCECHO); - } while(!legal(atoi(yournum))); + } while (!legal(atoi(yournum))); move(8, 25); prints("電腦猜"); flag = malloc(sizeof(char) * 10000); @@ -248,46 +270,47 @@ int guess_main() { } move(8, 55); prints("你猜"); - while(((!computerwin || !youwin) && count <10 && (ifcomputer[0])) || - (!ifcomputer[0] && count < 10 && !youwin)) { - if(!computerwin && ifcomputer[0]) { + while (((!computerwin || !youwin) && count < 10 && (ifcomputer[0])) || + (!ifcomputer[0] && count < 10 && !youwin)) { + if (!computerwin && ifcomputer[0]) { ++c_count; - if(computer(atoi(yournum), c_count, flag, n)) - computerwin = 1; + if (computer(atoi(yournum), c_count, flag, n)) + computerwin = 1; } move(20, 55); prints("第 %d 次機會 ", count + 1); - if(!youwin) { + if (!youwin) { ++count; - if(guess_play(get_data(count),answer,count)) - youwin=1; + if (guess_play(get_data(count), answer, count)) + youwin = 1; } } move(17, 35); - if(ifcomputer[0]) { + if (ifcomputer[0]) { free(flag); free(n); - if(count > c_count) { + if (count > c_count) { prints("你輸給電腦了"); move(18, 35); prints("你賠了 %d ", money); - if((file = fopen(LOGPASS,"a"))) { + if ((file = fopen(LOGPASS, "a"))) { fprintf(file, "電腦第%d次猜中, ", c_count); - if(youwin) + if (youwin) fprintf(file, "%s 第%d次猜中, ", cuser.userid, count); else - fprintf(file, "%s 沒猜中, ", cuser.userid); - fprintf(file,"電腦賺走了%s %ld Ptt$\n", cuser.userid, money); + fprintf(file, "%s 沒猜中, ", cuser.userid); + fprintf(file, "電腦賺走了%s %ld Ptt$\n", cuser.userid, money); fclose(file); } unlockutmpmode(); pressanykey(); - return 1; - } else if(count < c_count) { + return 1; + } else if (count < c_count) { prints("真厲害, 讓你賺到囉"); - move(18,35);prints("你賺走了 %d ",money*2); - demoney(money*2); - if((file = fopen(LOGPASS,"a"))) { + move(18, 35); + prints("你賺走了 %d ", money * 2); + demoney(money * 2); + if ((file = fopen(LOGPASS, "a"))) { fprintf(file, "id: %s, 第%d次猜中, 電腦第%d次猜中, " "贏了電腦 %ld Ptt$\n", cuser.userid, count, c_count, money * 2); @@ -299,7 +322,7 @@ int guess_main() { } else { prints("真厲害, 和電腦打成平手了, 拿回本錢%d\n", money); demoney(money); - if((file = fopen(LOGPASS,"a"))) { + if ((file = fopen(LOGPASS, "a"))) { fprintf(file, "id: %s 和電腦打成了平手\n", cuser.userid); fclose(file); } @@ -308,29 +331,28 @@ int guess_main() { return 1; } } - if(youwin) { - demoney(TABLE[count]*money); - if(count < 5) { + if (youwin) { + demoney(TABLE[count] * money); + if (count < 5) { prints("真厲害, 錢被你賺走了"); - if((file = fopen(LOGPASS,"a"))) { + if ((file = fopen(LOGPASS, "a"))) { fprintf(file, "id: %s, 第%d次猜中, 贏了 %ld Ptt$\n", cuser.userid, count, TABLE[count] * money); fclose(file); } - } else if(count > 5) { + } else if (count > 5) { prints("唉, 太多次才猜出來了"); - if((file = fopen(LOGPASS,"a"))) { + if ((file = fopen(LOGPASS, "a"))) { fprintf(file, "id: %s, 第%d次才猜中, 賠了 %ld Ptt$\n", cuser.userid, count, money); fclose(file); } - } - else { + } else { prints("五次猜出來, 還你本錢吧"); - move(18,35); + move(18, 35); clrtoeol(); prints("你拿回了%d Ptt$\n", money); - if((file = fopen(LOGPASS,"a"))) { + if ((file = fopen(LOGPASS, "a"))) { fprintf(file, "id: %s, 第%d次猜中, 拿回了本錢 %ld Ptt$\n", cuser.userid, count, money); fclose(file); @@ -340,12 +362,12 @@ int guess_main() { pressanykey(); return 1; } - move(17,35); + move(17, 35); prints("嘿嘿 標準答案是 %s ", answer); - move(18,35); + move(18, 35); prints("下次再來吧"); - if((file = fopen(BBSHOME "/etc/loseguess.log","a"))) { - fprintf(file,"id: %s 賭了 %ld Ptt$\n",cuser.userid,money); + if ((file = fopen(BBSHOME "/etc/loseguess.log", "a"))) { + fprintf(file, "id: %s 賭了 %ld Ptt$\n", cuser.userid, money); fclose(file); } return 1; diff --git a/pttbbs/mbbsd/indict.c b/pttbbs/mbbsd/indict.c index ca44033a..5a575211 100644 --- a/pttbbs/mbbsd/indict.c +++ b/pttbbs/mbbsd/indict.c @@ -1,30 +1,31 @@ -/* $Id: indict.c,v 1.4 2002/07/02 13:01:43 in2 Exp $ */ +/* $Id: indict.c,v 1.5 2002/07/05 17:10:27 in2 Exp $ */ #include "bbs.h" #define REFER "etc/dicts" -static void addword(char word[]) +static void +addword(char word[]) { - char buf[150],temp[150],a[3]; - FILE *fp = fopen(database,"r+"); + char buf[150], temp[150], a[3]; + FILE *fp = fopen(database, "r+"); - if( fp == NULL ){ + if (fp == NULL) { vmsg("database error"); - return ; + return; } - fgets(buf,130,fp); - fseek(fp,0,2); - if(HAVE_PERM(PERM_LOGINOK)) { + fgets(buf, 130, fp); + fseek(fp, 0, 2); + if (HAVE_PERM(PERM_LOGINOK)) { clear(); - move(4,0); + move(4, 0); outs(" \033[31m警告\033[m:若蓄意填寫假資料將\033[36m砍id\033[m處份\n"); sprintf(temp, "\n輸入範利\n:\033[33m%s\033[m", buf); outs(temp); outs("\n請依上列範例輸入一行資料(直接enter放棄)\n"); getdata(10, 0, ":", buf, 65, DOECHO); - if(buf[0]) { + if (buf[0]) { getdata(13, 0, "確定新增?(Y/n)", a, sizeof(a), LCECHO); - if(a[0] != 'n') + if (a[0] != 'n') fprintf(fp, "%-65s[%s]\n", buf, cuser.userid); } } @@ -32,29 +33,31 @@ static void addword(char word[]) clear(); } -static int choose_dict(void) { - int c; - FILE *fp; - char buf[10][21], data[10][21], cho[130]; +static int +choose_dict(void) +{ + int c; + FILE *fp; + char buf[10][21], data[10][21], cho[130]; move(12, 0); clrtobot(); outs(" " "● \033[45;33m字典唷 ◇ 要查哪一本?\033[m ●"); - if((fp = fopen(REFER, "r"))) { - for(c = 0; fscanf(fp, "%s %s", buf[c], data[c]) != EOF; c++ ) { - sprintf(cho,"\n " - "(\033[36m%d\033[m) %-20s大字典",c+1,buf[c]); - outs(cho); + if ((fp = fopen(REFER, "r"))) { + for (c = 0; fscanf(fp, "%s %s", buf[c], data[c]) != EOF; c++) { + sprintf(cho, "\n " + "(\033[36m%d\033[m) %-20s大字典", c + 1, buf[c]); + outs(cho); } - + getdata(22, 14, " ★ 請選擇,[Enter]離開:", cho, 3, LCECHO); cho[0] -= '1'; - if(cho[1]) + if (cho[1]) cho[0] = (cho[0] + 1) * 10 + (cho[1] - '1'); - - if(cho[0] >= 0 && cho[0] < c) { + + if (cho[0] >= 0 && cho[0] < c) { strcpy(dict, buf[(int)cho[0]]); strcpy(database, data[(int)cho[0]]); return 1; @@ -64,33 +67,37 @@ static int choose_dict(void) { return 0; } -static char *lower(char str[]) { - int c; - static char temp[200]; +static char * +lower(char str[]) +{ + int c; + static char temp[200]; - strcpy(temp,str); - for(c = 0; temp[c] !=0; c++) - if(temp[c] >= 'A' && temp[c] <= 'Z') + strcpy(temp, str); + for (c = 0; temp[c] != 0; c++) + if (temp[c] >= 'A' && temp[c] <= 'Z') temp[c] += 'a' - 'A'; return temp; } -int use_dict() { - FILE *fp; - char lang[150], word[80] = ""; - char j, f, buf[120], sys[] = "|\033[31me\033[m:編籍字典"; - int i = 0; - +int +use_dict() +{ + FILE *fp; + char lang[150], word[80] = ""; + char j, f, buf[120], sys[] = "|\033[31me\033[m:編籍字典"; + int i = 0; + setutmpmode(DICT); - if(!HAS_PERM(PERM_SYSOP)) - sys[0]=0; - + if (!HAS_PERM(PERM_SYSOP)) + sys[0] = 0; + clear(); - - sprintf(buf,"\033[45m ●\033[1;44;33m" + + sprintf(buf, "\033[45m ●\033[1;44;33m" " %-14s\033[3;45m ● ", dict); - strcpy(&buf[100],"\033[m\n"); - for(;;) { + strcpy(&buf[100], "\033[m\n"); + for (;;) { move(0, 0); sprintf(lang, " 請輸入關鍵字串(%s) 或指令(h,t,a)\n", dict); outs(lang); @@ -99,27 +106,27 @@ int use_dict() { outs(lang); getdata(2, 0, ":", word, 18, DOECHO); outs("資料搜尋中請稍候...."); - strcpy(word,lower(word)); - if(word[0] == 0) + strcpy(word, lower(word)); + if (word[0] == 0) return 0; clear(); move(4, 0); outs(buf); - if(strlen(word) == 1) { - if(word[0] == 'a') { + if (strlen(word) == 1) { + if (word[0] == 'a') { clear(); - move(4,0); + move(4, 0); outs(buf); addword(word); continue; - } else if(word[0] == 't') + } else if (word[0] == 't') word[0] = 0; - else if(word[0] == 'h') { - more("etc/dict.hlp",YEA); + else if (word[0] == 'h') { + more("etc/dict.hlp", YEA); clear(); continue; - } else if(word[0]=='e') { - vedit(database,NA, NULL); + } else if (word[0] == 'e') { + vedit(database, NA, NULL); clear(); continue; } else { @@ -127,43 +134,42 @@ int use_dict() { continue; } } - - if((fp = fopen(database,"r"))) { + if ((fp = fopen(database, "r"))) { i = 0; - while(fgets(lang,150,fp) != NULL) { - if(lang[65] == '[') { + while (fgets(lang, 150, fp) != NULL) { + if (lang[65] == '[') { lang[65] = 0; f = 1; } else f = 0; - if(strstr(lower(lang),word)) { - if(f == 1) + if (strstr(lower(lang), word)) { + if (f == 1) lang[65] = '['; outs(lang); i++; - if(!((i+1)%17)) { + if (!((i + 1) % 17)) { move(23, 0); outs("\033[45m " - "任意鍵繼續 Q:離開 " + "任意鍵繼續 Q:離開 " "\033[m "); j = igetch(); - if(j == 'q') + if (j == 'q') break; - else { + else { clear(); - move(4,0); + move(4, 0); outs(buf); - } + } } } } } fclose(fp); - if(i == 0) { + if (i == 0) { getdata(5, 0, "沒這個資料耶,新增嗎?(y/N)", lang, 3, LCECHO); - if(lang[0] == 'y') { + if (lang[0] == 'y') { clear(); - move(4,0); + move(4, 0); outs(buf); addword(word); } @@ -171,8 +177,10 @@ int use_dict() { } } -int x_dict() { - if(choose_dict()) +int +x_dict() +{ + if (choose_dict()) use_dict(); return 0; } diff --git a/pttbbs/mbbsd/io.c b/pttbbs/mbbsd/io.c index 12459063..7d993d0f 100644 --- a/pttbbs/mbbsd/io.c +++ b/pttbbs/mbbsd/io.c @@ -1,4 +1,4 @@ -/* $Id: io.c,v 1.17 2002/06/04 13:08:33 in2 Exp $ */ +/* $Id: io.c,v 1.18 2002/07/05 17:10:27 in2 Exp $ */ #include "bbs.h" #if defined(linux) @@ -9,30 +9,35 @@ #define IBUFSIZE 256 #endif -static char outbuf[OBUFSIZE], inbuf[IBUFSIZE]; -static int obufsize = 0, ibufsize = 0; -static int icurrchar = 0; +static char outbuf[OBUFSIZE], inbuf[IBUFSIZE]; +static int obufsize = 0, ibufsize = 0; +static int icurrchar = 0; /* ----------------------------------------------------- */ /* output routines */ /* ----------------------------------------------------- */ -void oflush() { - if(obufsize) { +void +oflush() +{ + if (obufsize) { write(1, outbuf, obufsize); obufsize = 0; } } -void init_buf() +void +init_buf() { - memset(inbuf,0,IBUFSIZE); + memset(inbuf, 0, IBUFSIZE); } -void output(char *s, int len) { +void +output(char *s, int len) +{ /* Invalid if len >= OBUFSIZE */ - if(obufsize + len > OBUFSIZE) { + if (obufsize + len > OBUFSIZE) { write(1, outbuf, obufsize); obufsize = 0; } @@ -40,8 +45,10 @@ void output(char *s, int len) { obufsize += len; } -int ochar(int c) { - if(obufsize > OBUFSIZE - 1) { +int +ochar(int c) +{ + if (obufsize > OBUFSIZE - 1) { write(1, outbuf, obufsize); obufsize = 0; } @@ -53,104 +60,108 @@ int ochar(int c) { /* input routines */ /* ----------------------------------------------------- */ -static int i_newfd = 0; +static int i_newfd = 0; static struct timeval i_to, *i_top = NULL; -static int (*flushf) () = NULL; +static int (*flushf) () = NULL; -void add_io(int fd, int timeout) { +void +add_io(int fd, int timeout) +{ i_newfd = fd; - if(timeout) { + if (timeout) { i_to.tv_sec = timeout; - i_to.tv_usec = 16384; /* Ptt: 改成16384 避免不按時for loop吃cpu time - 16384 約每秒64次 */ + i_to.tv_usec = 16384; /* Ptt: 改成16384 避免不按時for loop吃cpu + * time 16384 約每秒64次 */ i_top = &i_to; } else i_top = NULL; } -int num_in_buf() { +int +num_in_buf() +{ return icurrchar - ibufsize; } /* - dogetch() is not reentrant-safe. SIGUSR[12] might happen at any time, - and dogetch() might be called again, and then ibufsize/icurrchar/inbuf - might be inconsistent. - We try to not segfault here... -*/ + * dogetch() is not reentrant-safe. SIGUSR[12] might happen at any time, and + * dogetch() might be called again, and then ibufsize/icurrchar/inbuf might + * be inconsistent. We try to not segfault here... + */ -static int dogetch() { - int len; - static time_t lastact; - if(ibufsize <= icurrchar) { +static int +dogetch() +{ + int len; + static time_t lastact; + if (ibufsize <= icurrchar) { - if(flushf) - (*flushf)(); + if (flushf) + (*flushf) (); refresh(); - if(i_newfd) { - - struct timeval timeout; - fd_set readfds; - - if(i_top) timeout=*i_top; /* copy it because select() might change it */ - + if (i_newfd) { + + struct timeval timeout; + fd_set readfds; + + if (i_top) + timeout = *i_top; /* copy it because select() might + * change it */ + FD_ZERO(&readfds); FD_SET(0, &readfds); FD_SET(i_newfd, &readfds); /* jochang: modify first argument of select from FD_SETSIZE */ /* since we are only waiting input from fd 0 and i_newfd(>0) */ - - while((len = select(i_newfd+1, &readfds, NULL, NULL, i_top?&timeout:NULL))<0) - { - if(errno != EINTR) + + while ((len = select(i_newfd + 1, &readfds, NULL, NULL, i_top ? &timeout : NULL)) < 0) { + if (errno != EINTR) abort_bbs(0); - /* raise(SIGHUP); */ + /* raise(SIGHUP); */ } - if(len == 0) + if (len == 0) return I_TIMEOUT; - if(i_newfd && FD_ISSET(i_newfd, &readfds)) + if (i_newfd && FD_ISSET(i_newfd, &readfds)) return I_OTHERDATA; } - - - while((len = read(0, inbuf, IBUFSIZE)) <= 0) { - if(len == 0 || errno != EINTR) - abort_bbs(0); - /* raise(SIGHUP); */ - } + while ((len = read(0, inbuf, IBUFSIZE)) <= 0) { + if (len == 0 || errno != EINTR) + abort_bbs(0); + /* raise(SIGHUP); */ + } ibufsize = len; icurrchar = 0; } - - if(currutmp) - { - now= time(0); - if(now-lastact < 3) - currutmp->lastact=now; - lastact=now; - } + if (currutmp) { + now = time(0); + if (now - lastact < 3) + currutmp->lastact = now; + lastact = now; + } return inbuf[icurrchar++]; } -static int water_which_flag=0; -int igetch() { - register int ch; - while((ch = dogetch())) { - switch(ch) { +static int water_which_flag = 0; +int +igetch() +{ + register int ch; + while ((ch = dogetch())) { + switch (ch) { case Ctrl('L'): redoscr(); continue; case Ctrl('U'): - if(currutmp != NULL && currutmp->mode != EDITING - && currutmp->mode != LUSERS && currutmp->mode) { + if (currutmp != NULL && currutmp->mode != EDITING + && currutmp->mode != LUSERS && currutmp->mode) { - screenline_t *screen0 = calloc(t_lines, sizeof(screenline_t)); - int y, x, my_newfd; + screenline_t *screen0 = calloc(t_lines, sizeof(screenline_t)); + int y, x, my_newfd; getyx(&y, &x); memcpy(screen0, big_picture, t_lines * sizeof(screenline_t)); @@ -165,9 +176,9 @@ int igetch() { continue; } else return (ch); - case KEY_TAB: - if( WATERMODE(WATER_ORIG) || WATERMODE(WATER_NEW) ) - if( currutmp != NULL && watermode > 0 ){ + case KEY_TAB: + if (WATERMODE(WATER_ORIG) || WATERMODE(WATER_NEW)) + if (currutmp != NULL && watermode > 0) { watermode = (watermode + water_which->count) % water_which->count + 1; t_display_new(); @@ -176,16 +187,16 @@ int igetch() { return ch; break; - case Ctrl('R'): - if(currutmp == NULL) + case Ctrl('R'): + if (currutmp == NULL) return (ch); - if( currutmp->msgs[0].pid && - WATERMODE(WATER_OFO) && wmofo == -1 ){ - int y, x, my_newfd; - screenline_t *screen0 = calloc(t_lines, sizeof(screenline_t)); + if (currutmp->msgs[0].pid && + WATERMODE(WATER_OFO) && wmofo == -1) { + int y, x, my_newfd; + screenline_t *screen0 = calloc(t_lines, sizeof(screenline_t)); memcpy(screen0, big_picture, t_lines * sizeof(screenline_t)); - getyx(&y, &x); + getyx(&y, &x); my_newfd = i_newfd; i_newfd = 0; my_write2(); @@ -195,31 +206,27 @@ int igetch() { free(screen0); redoscr(); continue; - } - else if(!WATERMODE(WATER_OFO)) - { - if( watermode > 0 ){ + } else if (!WATERMODE(WATER_OFO)) { + if (watermode > 0) { watermode = (watermode + water_which->count) % water_which->count + 1; t_display_new(); continue; - } - else if( currutmp->mode == 0 && - (currutmp->chatid[0]==2 || currutmp->chatid[0]==3) && - water_which->count != 0 && watermode == 0) { + } else if (currutmp->mode == 0 && + (currutmp->chatid[0] == 2 || currutmp->chatid[0] == 3) && + water_which->count != 0 && watermode == 0) { /* 第二次按 Ctrl-R */ watermode = 1; t_display_new(); continue; - } - else if(watermode==-1 && currutmp->msgs[0].pid) { + } else if (watermode == -1 && currutmp->msgs[0].pid) { /* 第一次按 Ctrl-R (必須先被丟過水球) */ - screenline_t *screen0; - int y, x, my_newfd; + screenline_t *screen0; + int y, x, my_newfd; screen0 = calloc(t_lines, sizeof(screenline_t)); getyx(&y, &x); - memcpy(screen0, big_picture, t_lines*sizeof(screenline_t)); - + memcpy(screen0, big_picture, t_lines * sizeof(screenline_t)); + /* 如果正在talk的話先不處理對方送過來的封包 (不去select) */ my_newfd = i_newfd; i_newfd = 0; @@ -228,43 +235,43 @@ int igetch() { my_write(currutmp->msgs[0].pid, "水球丟過去 : ", currutmp->msgs[0].userid, 0, NULL); i_newfd = my_newfd; - + /* 還原螢幕 */ - memcpy(big_picture, screen0, t_lines*sizeof(screenline_t)); + memcpy(big_picture, screen0, t_lines * sizeof(screenline_t)); move(y, x); free(screen0); redoscr(); continue; } - } + } return ch; - case '\n': /* Ptt把 \n拿掉 */ + case '\n': /* Ptt把 \n拿掉 */ continue; - case Ctrl('T'): - if( WATERMODE(WATER_ORIG) || WATERMODE(WATER_NEW) ){ - if(watermode > 0) { - if(watermode>1) + case Ctrl('T'): + if (WATERMODE(WATER_ORIG) || WATERMODE(WATER_NEW)) { + if (watermode > 0) { + if (watermode > 1) watermode--; else - watermode = water_which->count; + watermode = water_which->count; t_display_new(); continue; } } return (ch); - case Ctrl('F'): - if( WATERMODE(WATER_NEW) ){ - if(watermode >0){ - if( water_which_flag == (int)water_usies ) + case Ctrl('F'): + if (WATERMODE(WATER_NEW)) { + if (watermode > 0) { + if (water_which_flag == (int)water_usies) water_which_flag = 0; else water_which_flag = - (water_which_flag+1) % (int)(water_usies+1); - if(water_which_flag==0) + (water_which_flag + 1) % (int)(water_usies + 1); + if (water_which_flag == 0) water_which = &water[0]; else - water_which = swater[water_which_flag-1]; + water_which = swater[water_which_flag - 1]; watermode = 1; t_display_new(); continue; @@ -272,14 +279,14 @@ int igetch() { } return ch; - case Ctrl('G'): - if( WATERMODE(WATER_NEW) ){ - if( watermode > 0 ){ - water_which_flag=(water_which_flag+water_usies)%(water_usies+1); - if(water_which_flag==0) + case Ctrl('G'): + if (WATERMODE(WATER_NEW)) { + if (watermode > 0) { + water_which_flag = (water_which_flag + water_usies) % (water_usies + 1); + if (water_which_flag == 0) water_which = &water[0]; else - water_which = swater[water_which_flag-1]; + water_which = swater[water_which_flag - 1]; watermode = 1; t_display_new(); continue; @@ -287,23 +294,25 @@ int igetch() { } return ch; - default: + default: return ch; } } return 0; } -int oldgetdata(int line, int col, char *prompt, char *buf, int len, int echo) { - register int ch, i; - int clen; - int x = col, y = line; +int +oldgetdata(int line, int col, char *prompt, char *buf, int len, int echo) +{ + register int ch, i; + int clen; + int x = col, y = line; #define MAXLASTCMD 12 - static char lastcmd[MAXLASTCMD][80]; + static char lastcmd[MAXLASTCMD][80]; strip_ansi(buf, buf, STRIP_ALL); - if(prompt) { + if (prompt) { move(line, col); @@ -311,56 +320,54 @@ int oldgetdata(int line, int col, char *prompt, char *buf, int len, int echo) { outs(prompt); - x += strip_ansi(NULL,prompt,0); + x += strip_ansi(NULL, prompt, 0); } - - if(!echo) { + if (!echo) { len--; clen = 0; - while((ch = igetch()) != '\r') { - if(ch == '\177' || ch == Ctrl('H')) { - if(!clen) { + while ((ch = igetch()) != '\r') { + if (ch == '\177' || ch == Ctrl('H')) { + if (!clen) { bell(); continue; } clen--; - if(echo) { + if (echo) { ochar(Ctrl('H')); ochar(' '); ochar(Ctrl('H')); } continue; } -// Ptt + //Ptt #ifdef BIT8 - if(!isprint2(ch)) + if (!isprint2(ch)) #else - if(!isprint(ch)) + if (!isprint(ch)) #endif - { - if(echo) - bell(); - continue; - } - - if(clen >= len) { - if(echo) + { + if (echo) + bell(); + continue; + } + if (clen >= len) { + if (echo) bell(); continue; } buf[clen++] = ch; - if(echo) + if (echo) ochar(ch); } buf[clen] = '\0'; outc('\n'); oflush(); } else { - int cmdpos = -1; - int currchar = 0; + int cmdpos = -1; + int currchar = 0; standout(); - for(clen = len--; clen; clen--) + for (clen = len--; clen; clen--) outc(' '); standend(); buf[len] = 0; @@ -368,81 +375,81 @@ int oldgetdata(int line, int col, char *prompt, char *buf, int len, int echo) { edit_outs(buf); clen = currchar = strlen(buf); - while(move(y, x + currchar), (ch = igetkey()) != '\r') { - switch(ch) { + while (move(y, x + currchar), (ch = igetkey()) != '\r') { + switch (ch) { case KEY_DOWN: case Ctrl('N'): - buf[clen] = '\0'; /* Ptt */ - strncpy(lastcmd[cmdpos], buf, 79); - cmdpos += MAXLASTCMD - 2; + buf[clen] = '\0'; /* Ptt */ + strncpy(lastcmd[cmdpos], buf, 79); + cmdpos += MAXLASTCMD - 2; case Ctrl('P'): case KEY_UP: - if(ch == KEY_UP || ch == Ctrl('P')) { - buf[clen] = '\0'; /* Ptt */ + if (ch == KEY_UP || ch == Ctrl('P')) { + buf[clen] = '\0'; /* Ptt */ strncpy(lastcmd[cmdpos], buf, 79); - } - cmdpos++; - cmdpos %= MAXLASTCMD; - strncpy(buf, lastcmd[cmdpos], len); - buf[len] = 0; - - move(y, x); /* clrtoeof */ - for(i = 0; i <= clen; i++) + } + cmdpos++; + cmdpos %= MAXLASTCMD; + strncpy(buf, lastcmd[cmdpos], len); + buf[len] = 0; + + move(y, x); /* clrtoeof */ + for (i = 0; i <= clen; i++) outc(' '); - move(y, x); - edit_outs(buf); - clen = currchar = strlen(buf); - break; + move(y, x); + edit_outs(buf); + clen = currchar = strlen(buf); + break; case KEY_LEFT: - if(currchar) + if (currchar) --currchar; - break; + break; case KEY_RIGHT: - if(buf[currchar]) + if (buf[currchar]) ++currchar; - break; + break; case '\177': case Ctrl('H'): - if(currchar) { + if (currchar) { currchar--; clen--; - for(i = currchar; i <= clen; i++) + for (i = currchar; i <= clen; i++) buf[i] = buf[i + 1]; move(y, x + clen); outc(' '); move(y, x); edit_outs(buf); - } - break; + } + break; case Ctrl('Y'): - currchar = 0; + currchar = 0; case Ctrl('K'): - buf[currchar] = 0; - move(y, x + currchar); - for(i = currchar; i < clen; i++) + buf[currchar] = 0; + move(y, x + currchar); + for (i = currchar; i < clen; i++) outc(' '); - clen = currchar; - break; + clen = currchar; + break; case Ctrl('D'): - if(buf[currchar]) { + if (buf[currchar]) { clen--; - for(i = currchar; i <= clen; i++) + for (i = currchar; i <= clen; i++) buf[i] = buf[i + 1]; move(y, x + clen); outc(' '); move(y, x); edit_outs(buf); - } - break; + } + break; case Ctrl('A'): - currchar = 0; - break; + currchar = 0; + break; case Ctrl('E'): - currchar = clen; - break; + currchar = clen; + break; default: - if(isprint2(ch) && clen < len && x + clen < scr_cols) { - for(i = clen + 1; i > currchar;i--) + if (isprint2(ch) && clen < len && x + clen < scr_cols) { + for (i = clen + 1; i > currchar; i--) buf[i] = buf[i - 1]; buf[currchar] = ch; move(y, x + currchar); @@ -450,103 +457,111 @@ int oldgetdata(int line, int col, char *prompt, char *buf, int len, int echo) { currchar++; clen++; } - break; - }/* end case */ - } /* end while */ - - if(clen > 1) - for(cmdpos = MAXLASTCMD - 1; cmdpos; cmdpos--) { - strcpy(lastcmd[cmdpos], lastcmd[cmdpos - 1]); - strncpy(lastcmd[0], buf, len); + break; + } /* end case */ + } /* end while */ + + if (clen > 1) + for (cmdpos = MAXLASTCMD - 1; cmdpos; cmdpos--) { + strcpy(lastcmd[cmdpos], lastcmd[cmdpos - 1]); + strncpy(lastcmd[0], buf, len); } - if(echo) + if (echo) outc('\n'); refresh(); } - if((echo == LCECHO) && ((ch = buf[0]) >= 'A') && (ch <= 'Z')) + if ((echo == LCECHO) && ((ch = buf[0]) >= 'A') && (ch <= 'Z')) buf[0] = ch | 32; -#ifdef SUPPORT_GB - if(echo == DOECHO && current_font_type == TYPE_GB) - { - strcpy(buf,hc_convert_str(buf, HC_GBtoBIG, HC_DO_SINGLE)); +#ifdef SUPPORT_GB + if (echo == DOECHO && current_font_type == TYPE_GB) { + strcpy(buf, hc_convert_str(buf, HC_GBtoBIG, HC_DO_SINGLE)); } #endif return clen; } /* Ptt */ -int getdata_buf(int line, int col, char *prompt, char *buf, int len, int echo) { +int +getdata_buf(int line, int col, char *prompt, char *buf, int len, int echo) +{ return oldgetdata(line, col, prompt, buf, len, echo); } char getans(char *prompt) { - char ans[5]; + char ans[5]; - getdata(t_lines-1, 0, prompt, ans, sizeof(ans), LCECHO); - return ans[0]; + getdata(t_lines - 1, 0, prompt, ans, sizeof(ans), LCECHO); + return ans[0]; } -int getdata_str(int line, int col, char *prompt, char *buf, int len, int echo, char *defaultstr) { +int +getdata_str(int line, int col, char *prompt, char *buf, int len, int echo, char *defaultstr) +{ strncpy(buf, defaultstr, len); - + buf[len - 1] = 0; return oldgetdata(line, col, prompt, buf, len, echo); } -int getdata(int line, int col, char *prompt, char *buf, int len, int echo) { +int +getdata(int line, int col, char *prompt, char *buf, int len, int echo) +{ buf[0] = 0; return oldgetdata(line, col, prompt, buf, len, echo); } int -rget(int x,char *prompt) +rget(int x, char *prompt) { - register int ch; + register int ch; - move(x,0); - clrtobot(); - outs(prompt); - refresh(); + move(x, 0); + clrtobot(); + outs(prompt); + refresh(); - ch = igetch(); - if( ch >= 'A' && ch <= 'Z') ch |= 32; + ch = igetch(); + if (ch >= 'A' && ch <= 'Z') + ch |= 32; - return ch; + return ch; } -int igetkey() { - int mode; - int ch, last; +int +igetkey() +{ + int mode; + int ch, last; mode = last = 0; - while(1) { + while (1) { ch = igetch(); - if(mode == 0) { - if(ch == KEY_ESC) + if (mode == 0) { + if (ch == KEY_ESC) mode = 1; else - return ch; /* Normal Key */ - } else if (mode == 1) { /* Escape sequence */ - if(ch == '[' || ch == 'O') + return ch; /* Normal Key */ + } else if (mode == 1) { /* Escape sequence */ + if (ch == '[' || ch == 'O') mode = 2; - else if(ch == '1' || ch == '4') + else if (ch == '1' || ch == '4') mode = 3; else { KEY_ESC_arg = ch; return KEY_ESC; } - } else if(mode == 2) { /* Cursor key */ - if(ch >= 'A' && ch <= 'D') + } else if (mode == 2) { /* Cursor key */ + if (ch >= 'A' && ch <= 'D') return KEY_UP + (ch - 'A'); - else if(ch >= '1' && ch <= '6') + else if (ch >= '1' && ch <= '6') mode = 3; else return ch; - } else if (mode == 3) { /* Ins Del Home End PgUp PgDn */ - if(ch == '~') + } else if (mode == 3) { /* Ins Del Home End PgUp PgDn */ + if (ch == '~') return KEY_HOME + (last - '1'); else return ch; @@ -554,4 +569,3 @@ int igetkey() { last = ch; } } - diff --git a/pttbbs/mbbsd/kaede.c b/pttbbs/mbbsd/kaede.c index e529aa3d..e3fd1b62 100644 --- a/pttbbs/mbbsd/kaede.c +++ b/pttbbs/mbbsd/kaede.c @@ -1,89 +1,98 @@ -/* $Id: kaede.c,v 1.7 2002/06/26 08:39:07 ptt Exp $ */ +/* $Id: kaede.c,v 1.8 2002/07/05 17:10:27 in2 Exp $ */ #include "bbs.h" -char *Ptt_prints(char *str, int mode) { - char *po , strbuf[256]; +char * +Ptt_prints(char *str, int mode) +{ + char *po, strbuf[256]; - while((po = strstr(str, "\033*s"))) { + while ((po = strstr(str, "\033*s"))) { po[0] = 0; sprintf(strbuf, "%s%s%s", str, cuser.userid, po + 3); strcpy(str, strbuf); } - while((po = strstr(str, "\033*t"))) { + while ((po = strstr(str, "\033*t"))) { po[0] = 0; sprintf(strbuf, "%s%s", str, Cdate(&now)); - str[strlen(strbuf)-1] = 0; + str[strlen(strbuf) - 1] = 0; strcat(strbuf, po + 3); strcpy(str, strbuf); } - while((po = strstr(str, "\033*u"))) { - int attempts; + while ((po = strstr(str, "\033*u"))) { + int attempts; attempts = SHM->UTMPnumber; po[0] = 0; sprintf(strbuf, "%s%d%s", str, attempts, po + 3); strcpy(str, strbuf); } - while((po = strstr(str, "\033*b"))) { + while ((po = strstr(str, "\033*b"))) { po[0] = 0; sprintf(strbuf, "%s%d/%d%s", str, cuser.month, cuser.day, po + 3); strcpy(str, strbuf); } - while((po = strstr(str, "\033*l"))) { + while ((po = strstr(str, "\033*l"))) { po[0] = 0; sprintf(strbuf, "%s%d%s", str, cuser.numlogins, po + 3); strcpy(str, strbuf); } - while((po = strstr(str, "\033*p"))) { + while ((po = strstr(str, "\033*p"))) { po[0] = 0; sprintf(strbuf, "%s%d%s", str, cuser.numposts, po + 3); strcpy(str, strbuf); } - while((po = strstr(str, "\033*n"))) { + while ((po = strstr(str, "\033*n"))) { po[0] = 0; sprintf(strbuf, "%s%s%s", str, cuser.username, po + 3); strcpy(str, strbuf); } - while((po = strstr(str, "\033*m"))) { + while ((po = strstr(str, "\033*m"))) { po[0] = 0; sprintf(strbuf, "%s%d%s", str, cuser.money, po + 3); strcpy(str, strbuf); } - strip_ansi(str, str ,mode); + strip_ansi(str, str, mode); return str; } -int Rename(char* src, char* dst) { - char buf[256]; - if(rename(src, dst) == 0) - return 0; - if(!strchr(src,';') && !strchr(dst,';')) // Ptt 防不正常指令 - { - sprintf(buf,"/bin/mv %s %s",src,dst); - system(buf); - } +int +Rename(char *src, char *dst) +{ + char buf[256]; + if (rename(src, dst) == 0) + return 0; + if (!strchr(src, ';') && !strchr(dst, ';')) + //Ptt 黎ㄔ膨`指令 + { + sprintf(buf, "/bin/mv %s %s", src, dst); + system(buf); + } return -1; } -int Link(char* src, char* dst) { - char cmd[200]; - - if(strcmp(src, BBSHOME "/home") == 0) - return 1; - if(symlink(dst, src) == 0) +int +Link(char *src, char *dst) +{ + char cmd[200]; + + if (strcmp(src, BBSHOME "/home") == 0) + return 1; + if (symlink(dst, src) == 0) return 0; - + sprintf(cmd, "/bin/cp -R %s %s", src, dst); return system(cmd); } -char *my_ctime(const time_t *t) { - struct tm *tp; - static char ans[100]; +char * +my_ctime(const time_t * t) +{ + struct tm *tp; + static char ans[100]; tp = localtime(t); sprintf(ans, "%02d/%02d/%02d %02d:%02d:%02d", (tp->tm_year % 100), - tp->tm_mon + 1,tp->tm_mday, tp->tm_hour, tp->tm_min, tp->tm_sec); + tp->tm_mon + 1, tp->tm_mday, tp->tm_hour, tp->tm_min, tp->tm_sec); return ans; } diff --git a/pttbbs/mbbsd/lovepaper.c b/pttbbs/mbbsd/lovepaper.c index d4757ecf..c2f4459c 100644 --- a/pttbbs/mbbsd/lovepaper.c +++ b/pttbbs/mbbsd/lovepaper.c @@ -1,53 +1,54 @@ -/* $Id: lovepaper.c,v 1.6 2002/06/19 13:32:23 lwms Exp $ */ +/* $Id: lovepaper.c,v 1.7 2002/07/05 17:10:27 in2 Exp $ */ #include "bbs.h" #define DATA "etc/lovepaper.dat" -int x_love() { - char buf1[200], save_title[TTLEN + 1]; - char receiver[61], path[STRLEN] = "home/"; - int x, y = 0, tline = 0, poem = 0; - FILE *fp, *fpo; - struct tm *gtime; - fileheader_t mhdr; - +int +x_love() +{ + char buf1[200], save_title[TTLEN + 1]; + char receiver[61], path[STRLEN] = "home/"; + int x, y = 0, tline = 0, poem = 0; + FILE *fp, *fpo; + struct tm *gtime; + fileheader_t mhdr; + setutmpmode(LOVE); gtime = localtime(&now); - sprintf(buf1,"%c/%s/love%d%d", - cuser.userid[0], cuser.userid,gtime->tm_sec,gtime->tm_min); - strcat(path,buf1); - move(1,0); + sprintf(buf1, "%c/%s/love%d%d", + cuser.userid[0], cuser.userid, gtime->tm_sec, gtime->tm_min); + strcat(path, buf1); + move(1, 0); clrtobot(); - + outs("\n歡迎使用情書產生器 v0.00 板 \n"); outs("有何難以啟齒的話,交由系統幫你說吧.\n爸爸說 : 濫情不犯法.\n"); - - if(!getdata(7, 0, "收信人:", receiver, sizeof(receiver), DOECHO)) + + if (!getdata(7, 0, "收信人:", receiver, sizeof(receiver), DOECHO)) return 0; - if(receiver[0] && !(searchuser(receiver) && - getdata(8, 0, "主 題:", save_title, - sizeof(save_title), DOECHO))) { + if (receiver[0] && !(searchuser(receiver) && + getdata(8, 0, "主 題:", save_title, + sizeof(save_title), DOECHO))) { move(10, 0); outs("收信人或主題不正確, 情書無法傳遞. "); pressanykey(); return 0; } - fpo = fopen(path, "w"); fprintf(fpo, "\n"); - if((fp = fopen(DATA, "r"))) { - while(fgets(buf1,100, fp)) { - switch(buf1[0]) { + if ((fp = fopen(DATA, "r"))) { + while (fgets(buf1, 100, fp)) { + switch (buf1[0]) { case '#': break; case '@': - if(!strncmp(buf1, "@begin", 6) || !strncmp(buf1, "@end", 4)) - tline=3; - else if(!strncmp(buf1,"@poem",5)) { + if (!strncmp(buf1, "@begin", 6) || !strncmp(buf1, "@end", 4)) + tline = 3; + else if (!strncmp(buf1, "@poem", 5)) { poem = 1; tline = 1; fprintf(fpo, "\n\n"); } else - tline=2; + tline = 2; break; case '1': case '2': @@ -58,32 +59,32 @@ int x_love() { case '7': case '8': case '9': - sscanf(buf1,"%d",&x); - y = (rand() % (x - 1)) * tline; + sscanf(buf1, "%d", &x); + y = (rand() % (x - 1)) * tline; break; default: - if(!poem) { - if(y > 0) + if (!poem) { + if (y > 0) y = y - 1; else { - if(tline > 0) { + if (tline > 0) { fprintf(fpo, "%s", buf1); tline--; } } } else { - if(buf1[0] == '$') + if (buf1[0] == '$') y--; - else if(y == 0) - fprintf(fpo,"%s",buf1); + else if (y == 0) + fprintf(fpo, "%s", buf1); } - } + } } - + fclose(fp); fclose(fpo); - if(vedit(path, YEA, NULL) == -1) { + if (vedit(path, YEA, NULL) == -1) { unlink(path); clear(); outs("\n\n 放棄寄情書\n"); @@ -95,8 +96,8 @@ int x_love() { Rename(path, buf1); strncpy(mhdr.title, save_title, TTLEN); strcpy(mhdr.owner, cuser.userid); - sethomedir(path, receiver ); - if(append_record(path, &mhdr, sizeof(mhdr)) == -1) + sethomedir(path, receiver); + if (append_record(path, &mhdr, sizeof(mhdr)) == -1) return -1; hold_mail(buf1, receiver); return 1; diff --git a/pttbbs/mbbsd/mail.c b/pttbbs/mbbsd/mail.c index bc7d25a5..d6d4e3d9 100644 --- a/pttbbs/mbbsd/mail.c +++ b/pttbbs/mbbsd/mail.c @@ -1,37 +1,39 @@ -/* $Id: mail.c,v 1.17 2002/07/03 09:14:57 in2 Exp $ */ +/* $Id: mail.c,v 1.18 2002/07/05 17:10:27 in2 Exp $ */ #include "bbs.h" -char currmaildir[32]; -static char msg_cc[] = "\033[32m[群組名單]\033[m\n"; -static char listfile[] = "list.0"; -static int mailkeep = 0, mailsum = 0; -static int mailsumlimit = 0,mailmaxkeep = 0; - -int setforward() { - char buf[80], ip[50] = "", yn[4]; - FILE *fp; - +char currmaildir[32]; +static char msg_cc[] = "\033[32m[群組名單]\033[m\n"; +static char listfile[] = "list.0"; +static int mailkeep = 0, mailsum = 0; +static int mailsumlimit = 0, mailmaxkeep = 0; + +int +setforward() +{ + char buf[80], ip[50] = "", yn[4]; + FILE *fp; + sethomepath(buf, cuser.userid); - strcat(buf,"/.forward"); - if((fp = fopen(buf,"r"))) { - fscanf(fp,"%s",ip); + strcat(buf, "/.forward"); + if ((fp = fopen(buf, "r"))) { + fscanf(fp, "%s", ip); fclose(fp); } getdata_buf(b_lines - 1, 0, "請輸入信箱自動轉寄的email地址:", ip, sizeof(ip), DOECHO); - if(ip[0] && ip[0] != ' ') { + if (ip[0] && ip[0] != ' ') { getdata(b_lines, 0, "確定開啟自動轉信功\能?(Y/n)", yn, sizeof(yn), LCECHO); - if(yn[0] != 'n' && (fp = fopen(buf, "w"))) { - move(b_lines,0); + if (yn[0] != 'n' && (fp = fopen(buf, "w"))) { + move(b_lines, 0); clrtoeol(); - fprintf(fp,"%s",ip); + fprintf(fp, "%s", ip); fclose(fp); outs("設定完成!"); refresh(); return 0; } } - move(b_lines,0); + move(b_lines, 0); clrtoeol(); outs("取消自動轉信!"); unlink(buf); @@ -39,74 +41,88 @@ int setforward() { return 0; } -int built_mail_index() { - char genbuf[128]; - +int +built_mail_index() +{ + char genbuf[128]; + getdata(b_lines, 0, "重建信箱?(警告:請確定信箱有問題時才使用)(y/N)", genbuf, 3, - LCECHO); - if(genbuf[0] != 'y') return 0; + LCECHO); + if (genbuf[0] != 'y') + return 0; sprintf(genbuf, BBSHOME "/bin/buildir " BBSHOME "/home/%c/%s", cuser.userid[0], cuser.userid); - move(22,0); - prints("\033[1;31m已經處理完畢!! 諸多不便 敬請原諒~\033[m");pressanykey(); + move(22, 0); + prints("\033[1;31m已經處理完畢!! 諸多不便 敬請原諒~\033[m"); + pressanykey(); system(genbuf); return 0; } -int mailalert(char *userid) +int +mailalert(char *userid) { - userinfo_t *uentp=NULL; - int n,tuid,i; + userinfo_t *uentp = NULL; + int n, tuid, i; - if((tuid=searchuser(userid))==0) return -1; + if ((tuid = searchuser(userid)) == 0) + return -1; - n=count_logins(tuid, 0); - for(i=1;i<=n;i++) - if((uentp = (userinfo_t *)search_ulistn(tuid, i))) - uentp->mailalert=1; + n = count_logins(tuid, 0); + for (i = 1; i <= n; i++) + if ((uentp = (userinfo_t *) search_ulistn(tuid, i))) + uentp->mailalert = 1; return 0; } -int mail_muser(userec_t muser, char *title, char *filename) { +int +mail_muser(userec_t muser, char *title, char *filename) +{ return mail_id(muser.userid, title, filename, cuser.userid); } /* Heat: 用id來寄信,內容則link準備好的檔案 */ -int mail_id(char* id, char *title, char *filename, char *owner) { - fileheader_t mhdr; - char genbuf[128]; +int +mail_id(char *id, char *title, char *filename, char *owner) +{ + fileheader_t mhdr; + char genbuf[128]; sethomepath(genbuf, id); - if(stampfile(genbuf, &mhdr)) - return 0; + if (stampfile(genbuf, &mhdr)) + return 0; strcpy(mhdr.owner, owner); strncpy(mhdr.title, title, TTLEN); mhdr.filemode = 0; Link(filename, genbuf); - sethomedir(genbuf,id); + sethomedir(genbuf, id); append_record(genbuf, &mhdr, sizeof(mhdr)); mailalert(id); return 0; -} - -int invalidaddr(char *addr) { - if(*addr == '\0') - return 1; /* blank */ - while(*addr) { - if(not_alnum(*addr) && !strchr("[].@-_", *addr)) +} + +int +invalidaddr(char *addr) +{ + if (*addr == '\0') + return 1; /* blank */ + while (*addr) { + if (not_alnum(*addr) && !strchr("[].@-_", *addr)) return 1; addr++; } return 0; } -int m_internet() { - char receiver[60]; - +int +m_internet() +{ + char receiver[60]; + getdata(20, 0, "收信人:", receiver, sizeof(receiver), DOECHO); - if(strchr(receiver, '@') && !invalidaddr(receiver) && - getdata(21, 0, "主 題:", save_title, STRLEN, DOECHO)) + if (strchr(receiver, '@') && !invalidaddr(receiver) && + getdata(21, 0, "主 題:", save_title, STRLEN, DOECHO)) do_send(receiver, save_title); else { move(22, 0); @@ -116,33 +132,33 @@ int m_internet() { return 0; } -void m_init() { +void +m_init() +{ sethomedir(currmaildir, cuser.userid); } -int chkmailbox() { - if(!HAVE_PERM(PERM_SYSOP) && !HAVE_PERM(PERM_MAILLIMIT)) { - int max_keepmail = MAX_KEEPMAIL; - if ( HAS_PERM(PERM_SYSSUBOP) || HAS_PERM(PERM_SMG) || - HAS_PERM(PERM_PRG) || HAS_PERM(PERM_ACTION) || HAS_PERM(PERM_PAINT)) - { - mailsumlimit = 700; - max_keepmail = 500; - } - else if(HAS_PERM(PERM_BM)) - { +int +chkmailbox() +{ + if (!HAVE_PERM(PERM_SYSOP) && !HAVE_PERM(PERM_MAILLIMIT)) { + int max_keepmail = MAX_KEEPMAIL; + if (HAS_PERM(PERM_SYSSUBOP) || HAS_PERM(PERM_SMG) || + HAS_PERM(PERM_PRG) || HAS_PERM(PERM_ACTION) || HAS_PERM(PERM_PAINT)) { + mailsumlimit = 700; + max_keepmail = 500; + } else if (HAS_PERM(PERM_BM)) { mailsumlimit = 500; - max_keepmail = 300; - } - else if(HAS_PERM(PERM_LOGINOK)) + max_keepmail = 300; + } else if (HAS_PERM(PERM_LOGINOK)) mailsumlimit = 200; else mailsumlimit = 50; mailsumlimit += cuser.exmailbox * 10; mailmaxkeep = max_keepmail + cuser.exmailbox; m_init(); - if((mailkeep = get_num_records(currmaildir, sizeof(fileheader_t))) > - mailmaxkeep) { + if ((mailkeep = get_num_records(currmaildir, sizeof(fileheader_t))) > + mailmaxkeep) { move(b_lines, 0); clrtoeol(); bell(); @@ -153,8 +169,8 @@ int chkmailbox() { igetch(); return mailkeep; } - if((mailsum = get_sum_records(currmaildir, sizeof(fileheader_t))) > - mailsumlimit) { + if ((mailsum = get_sum_records(currmaildir, sizeof(fileheader_t))) > + mailsumlimit) { move(b_lines, 0); clrtoeol(); bell(); @@ -169,70 +185,76 @@ int chkmailbox() { return 0; } -static void do_hold_mail(char *fpath, char *receiver, char *holder) { - char buf[80], title[128]; - - fileheader_t mymail; - +static void +do_hold_mail(char *fpath, char *receiver, char *holder) +{ + char buf[80], title[128]; + + fileheader_t mymail; + sethomepath(buf, holder); stampfile(buf, &mymail); - - mymail.filemode = FILE_READ|FILE_HOLD; + + mymail.filemode = FILE_READ | FILE_HOLD; strcpy(mymail.owner, "[備.忘.錄]"); - if(receiver) { + if (receiver) { sprintf(title, "(%s) %s", receiver, save_title); strncpy(mymail.title, title, TTLEN); } else strcpy(mymail.title, save_title); - + sethomedir(title, holder); - + unlink(buf); Link(fpath, buf); /* Ptt: append_record->do_append */ do_append(title, &mymail, sizeof(mymail)); } -void hold_mail(char *fpath, char *receiver) { - char buf[4]; - +void +hold_mail(char *fpath, char *receiver) +{ + char buf[4]; + getdata(b_lines - 1, 0, "已順利寄出,是否自存底稿(Y/N)?[N] ", buf, sizeof(buf), LCECHO); - - if(buf[0] == 'y') + + if (buf[0] == 'y') do_hold_mail(fpath, receiver, cuser.userid); } -int do_send(char *userid, char *title) { - fileheader_t mhdr; - char fpath[STRLEN]; - char receiver[IDLEN]; - char genbuf[200]; - int internet_mail, i; - - if(strchr(userid, '@')) +int +do_send(char *userid, char *title) +{ + fileheader_t mhdr; + char fpath[STRLEN]; + char receiver[IDLEN]; + char genbuf[200]; + int internet_mail, i; + + if (strchr(userid, '@')) internet_mail = 1; else { internet_mail = 0; - if(!getuser(userid)) + if (!getuser(userid)) return -1; - if(!(xuser.userlevel & PERM_READMAIL)) + if (!(xuser.userlevel & PERM_READMAIL)) return -3; - - if(!title) - getdata(2, 0, "主題:", save_title, STRLEN-20, DOECHO); + + if (!title) + getdata(2, 0, "主題:", save_title, STRLEN - 20, DOECHO); curredit |= EDIT_MAIL; curredit &= ~EDIT_ITEM; } - + setutmpmode(SMAIL); - + fpath[0] = '\0'; - - if(internet_mail) { - int res, ch; - if(vedit(fpath, NA, NULL) == -1) { + if (internet_mail) { + int res, ch; + + if (vedit(fpath, NA, NULL) == -1) { unlink(fpath); clear(); return -2; @@ -241,7 +263,7 @@ int do_send(char *userid, char *title) { prints("信件即將寄給 %s\n標題為:%s\n確定要寄出嗎? (Y/N) [Y]", userid, title); ch = igetch(); - switch(ch) { + switch (ch) { case 'N': case 'n': outs("N\n信件已取消"); @@ -253,7 +275,7 @@ int do_send(char *userid, char *title) { #ifndef USE_BSMTP bbs_sendmail(fpath, title, userid); #else - bsmtp(fpath, title, userid,0); + bsmtp(fpath, title, userid, 0); #endif hold_mail(fpath, userid); } @@ -265,31 +287,34 @@ int do_send(char *userid, char *title) { stampfile(genbuf, &mhdr); strcpy(mhdr.owner, cuser.userid); strncpy(mhdr.title, save_title, TTLEN); - if(vedit(genbuf, YEA, NULL) == -1) { + if (vedit(genbuf, YEA, NULL) == -1) { unlink(genbuf); clear(); return -2; } clear(); sethomefile(fpath, userid, FN_OVERRIDES); - i=belong(fpath, cuser.userid); - sethomefile(fpath, userid, FN_REJECT); + i = belong(fpath, cuser.userid); + sethomefile(fpath, userid, FN_REJECT); - if(i || !belong(fpath, cuser.userid)) //Ptt:用belong有點討厭 - { + if (i || !belong(fpath, cuser.userid)) + //Ptt: 用belong 麻I Q + { sethomedir(fpath, userid); - if(append_record(fpath, &mhdr, sizeof(mhdr)) == -1) - return -1; - mailalert(userid); - } + if (append_record(fpath, &mhdr, sizeof(mhdr)) == -1) + return -1; + mailalert(userid); + } hold_mail(genbuf, userid); return 0; } } -void my_send(char *uident) { - switch(do_send(uident, NULL)) { - case -1: +void +my_send(char *uident) +{ + switch (do_send(uident, NULL)) { + case -1: outs(err_uid); break; case -2: @@ -302,44 +327,48 @@ void my_send(char *uident) { pressanykey(); } -int m_send() { - char uident[40]; +int +m_send() +{ + char uident[40]; stand_title("且聽風的話"); usercomplete(msg_uid, uident); showplans(uident); - if(uident[0]) + if (uident[0]) my_send(uident); return 0; } /* 群組寄信、回信 : multi_send, multi_reply */ -static void multi_list(int *reciper) { - char uid[16]; - char genbuf[200]; +static void +multi_list(int *reciper) +{ + char uid[16]; + char genbuf[200]; - while(1) { + while (1) { stand_title("群組寄信名單"); ShowNameList(3, 0, msg_cc); getdata(1, 0, "(I)引入好友 (O)引入上線通知 (N)引入新文章通知 " "(0-9)引入其他特別名單\n" - "(A)增加 (D)刪除 (M)確認寄信名單 (Q)取消 ?[M]", + "(A)增加 (D)刪除 (M)確認寄信名單 (Q)取消 ?[M]", genbuf, 4, LCECHO); - switch(genbuf[0]) { + switch (genbuf[0]) { case 'a': - while(1) { + while (1) { move(1, 0); usercomplete("請輸入要增加的代號(只按 ENTER 結束新增): ", uid); - if(uid[0] == '\0') + if (uid[0] == '\0') break; - + move(2, 0); clrtoeol(); - - if(!searchuser(uid)) + + if (!searchuser(uid)) outs(err_uid); - else if(!InNameList(uid)) { + else if (!InNameList(uid)) { AddNameList(uid); (*reciper)++; } @@ -347,12 +376,12 @@ static void multi_list(int *reciper) { } break; case 'd': - while(*reciper) { + while (*reciper) { move(1, 0); namecomplete("請輸入要刪除的代號(只按 ENTER 結束刪除): ", uid); - if(uid[0] == '\0') + if (uid[0] == '\0') break; - if(RemoveNameList(uid)) + if (RemoveNameList(uid)) (*reciper)--; ShowNameList(3, 0, msg_cc); } @@ -390,68 +419,69 @@ static void multi_list(int *reciper) { } } -static void multi_send(char *title) { - FILE *fp; - struct word_t *p = NULL; - fileheader_t mymail; - char fpath[TTLEN], *ptr; - int reciper, listing; - char genbuf[256]; - +static void +multi_send(char *title) +{ + FILE *fp; + struct word_t *p = NULL; + fileheader_t mymail; + char fpath[TTLEN], *ptr; + int reciper, listing; + char genbuf[256]; + CreateNameList(); listing = reciper = 0; - if(*quote_file) { + if (*quote_file) { AddNameList(quote_user); reciper = 1; fp = fopen(quote_file, "r"); - while(fgets(genbuf, 256, fp)) { - if(strncmp(genbuf, "※ ", 3)) { - if(listing) + while (fgets(genbuf, 256, fp)) { + if (strncmp(genbuf, "※ ", 3)) { + if (listing) break; } else { - if(listing) { + if (listing) { strtok(ptr = genbuf + 3, " \n\r"); do { - if(searchuser(ptr) && !InNameList(ptr) && - strcmp(cuser.userid, ptr)) { + if (searchuser(ptr) && !InNameList(ptr) && + strcmp(cuser.userid, ptr)) { AddNameList(ptr); reciper++; } - } while((ptr = (char *)strtok(NULL, " \n\r"))); - } else if(!strncmp(genbuf + 3, "[通告]", 6)) + } while ((ptr = (char *)strtok(NULL, " \n\r"))); + } else if (!strncmp(genbuf + 3, "[通告]", 6)) listing = 1; } } ShowNameList(3, 0, msg_cc); } - multi_list(&reciper); move(1, 0); clrtobot(); - - if(reciper) { + + if (reciper) { setutmpmode(SMAIL); - if(title) + if (title) do_reply_title(2, title); else { getdata(2, 0, "主題:", fpath, sizeof(fpath), DOECHO); sprintf(save_title, "[通告] %s", fpath); } - + setuserfile(fpath, fn_notes); - - if((fp = fopen(fpath, "w"))) { + + if ((fp = fopen(fpath, "w"))) { fprintf(fp, "※ [通告] 共 %d 人收件", reciper); listing = 80; - for(p = toplev; p; p = p->next) { + for (p = toplev; p; p = p->next) { reciper = strlen(p->word) + 1; - if(listing + reciper > 75) { + if (listing + reciper > 75) { listing = reciper; fprintf(fp, "\n※"); } else listing += reciper; - + fprintf(fp, " %s", p->word); } memset(genbuf, '-', 75); @@ -459,25 +489,23 @@ static void multi_send(char *title) { fprintf(fp, "\n%s\n\n", genbuf); fclose(fp); } - curredit |= EDIT_LIST; - if(vedit(fpath, YEA, NULL) == -1) { + if (vedit(fpath, YEA, NULL) == -1) { unlink(fpath); curredit = 0; outs(msg_cancel); pressanykey(); return; } - stand_title("寄信中..."); refresh(); - + listing = 80; - - for(p = toplev; p; p = p->next) { + + for (p = toplev; p; p = p->next) { reciper = strlen(p->word) + 1; - if(listing + reciper > 75) { + if (listing + reciper > 75) { listing = reciper; outc('\n'); } else { @@ -485,19 +513,19 @@ static void multi_send(char *title) { outc(' '); } outs(p->word); - if(searchuser(p->word) && strcmp(STR_GUEST, p->word) ) + if (searchuser(p->word) && strcmp(STR_GUEST, p->word)) sethomepath(genbuf, p->word); else continue; stampfile(genbuf, &mymail); unlink(genbuf); Link(fpath, genbuf); - + strcpy(mymail.owner, cuser.userid); strcpy(mymail.title, save_title); - mymail.filemode |= FILE_MULTI; /* multi-send flag */ + mymail.filemode |= FILE_MULTI; /* multi-send flag */ sethomedir(genbuf, p->word); - if(append_record(genbuf, &mymail, sizeof(mymail)) == -1) + if (append_record(genbuf, &mymail, sizeof(mymail)) == -1) outs(err_uid); mailalert(p->word); } @@ -509,8 +537,10 @@ static void multi_send(char *title) { pressanykey(); } -static int multi_reply(int ent, fileheader_t *fhdr, char *direct) { - if(!(fhdr->filemode&FILE_MULTI) ) +static int +multi_reply(int ent, fileheader_t * fhdr, char *direct) +{ + if (!(fhdr->filemode & FILE_MULTI)) return mail_reply(ent, fhdr, direct); stand_title("群組回信"); @@ -520,39 +550,42 @@ static int multi_reply(int ent, fileheader_t *fhdr, char *direct) { return 0; } -int mail_list() { +int +mail_list() +{ stand_title("群組作業"); multi_send(NULL); return 0; } -int mail_all() { - FILE *fp; - fileheader_t mymail; - char fpath[TTLEN]; - char genbuf[200]; - int i, unum; - char *userid; - +int +mail_all() +{ + FILE *fp; + fileheader_t mymail; + char fpath[TTLEN]; + char genbuf[200]; + int i, unum; + char *userid; + stand_title("給所有使用者的系統通告"); setutmpmode(SMAIL); getdata(2, 0, "主題:", fpath, sizeof(fpath), DOECHO); sprintf(save_title, "[系統通告]\033[1;32m %s\033[m", fpath); - + setuserfile(fpath, fn_notes); - - if((fp = fopen(fpath, "w"))) { + + if ((fp = fopen(fpath, "w"))) { fprintf(fp, "※ [\033[1m系統通告\033[m] 這是封給所有使用者的信\n"); fprintf(fp, "-----------------------------------------------------" "----------------------\n"); fclose(fp); } - *quote_file = 0; - + curredit |= EDIT_MAIL; curredit &= ~EDIT_ITEM; - if(vedit(fpath, YEA, NULL) == -1) { + if (vedit(fpath, YEA, NULL) == -1) { curredit = 0; unlink(fpath); outs(msg_cancel); @@ -560,41 +593,41 @@ int mail_all() { return 0; } curredit = 0; - + setutmpmode(MAILALL); stand_title("寄信中..."); - + sethomepath(genbuf, cuser.userid); stampfile(genbuf, &mymail); unlink(genbuf); Link(fpath, genbuf); unlink(fpath); strcpy(fpath, genbuf); - - strcpy(mymail.owner, cuser.userid); /*站長 ID*/ + + strcpy(mymail.owner, cuser.userid); /* 站長 ID */ strcpy(mymail.title, save_title); - + sethomedir(genbuf, cuser.userid); - if(append_record(genbuf, &mymail, sizeof(mymail)) == -1) + if (append_record(genbuf, &mymail, sizeof(mymail)) == -1) outs(err_uid); - - for(unum = SHM->number, i = 0; i < unum; i++) { - if(bad_user_id(SHM->userid[i])) - continue; /* Ptt */ - + + for (unum = SHM->number, i = 0; i < unum; i++) { + if (bad_user_id(SHM->userid[i])) + continue; /* Ptt */ + userid = SHM->userid[i]; - if(strcmp(userid,STR_GUEST) && strcmp(userid, "new") && - strcmp(userid, cuser.userid)) { + if (strcmp(userid, STR_GUEST) && strcmp(userid, "new") && + strcmp(userid, cuser.userid)) { sethomepath(genbuf, userid); stampfile(genbuf, &mymail); unlink(genbuf); Link(fpath, genbuf); - + strcpy(mymail.owner, cuser.userid); strcpy(mymail.title, save_title); /* mymail.filemode |= FILE_MARKED; Ptt 公告改成不會mark */ sethomedir(genbuf, userid); - if(append_record(genbuf, &mymail, sizeof(mymail)) == -1) + if (append_record(genbuf, &mymail, sizeof(mymail)) == -1) outs(err_uid); sprintf(genbuf, "%*s %5d / %5d", IDLEN + 1, userid, i + 1, unum); outmsg(genbuf); @@ -604,9 +637,11 @@ int mail_all() { return 0; } -int mail_mbox() { - char cmd[100]; - fileheader_t fhdr; +int +mail_mbox() +{ + char cmd[100]; + fileheader_t fhdr; sprintf(cmd, "/tmp/%s.uu", cuser.userid); sprintf(fhdr.title, "%s 私人資料", cuser.userid); @@ -614,12 +649,14 @@ int mail_mbox() { return 0; } -static int m_forward(int ent, fileheader_t *fhdr, char *direct) { - char uid[STRLEN]; +static int +m_forward(int ent, fileheader_t * fhdr, char *direct) +{ + char uid[STRLEN]; stand_title("轉達信件"); usercomplete(msg_uid, uid); - if(uid[0] == '\0') + if (uid[0] == '\0') return FULLUPDATE; strcpy(quote_user, fhdr->owner); @@ -629,7 +666,7 @@ static int m_forward(int ent, fileheader_t *fhdr, char *direct) { clrtobot(); prints("轉信給: %s\n標 題: %s\n", uid, save_title); - switch(do_send(uid, save_title)) { + switch (do_send(uid, save_title)) { case -1: outs(err_uid); break; @@ -644,44 +681,46 @@ static int m_forward(int ent, fileheader_t *fhdr, char *direct) { return FULLUPDATE; } -static int delmsgs[128]; -static int delcnt; -static int mrd; - -static int read_new_mail(fileheader_t *fptr) { - static int idc; - char done = NA, delete_it; - char fname[256]; - char genbuf[4]; - - if(fptr == NULL) { +static int delmsgs[128]; +static int delcnt; +static int mrd; + +static int +read_new_mail(fileheader_t * fptr) +{ + static int idc; + char done = NA, delete_it; + char fname[256]; + char genbuf[4]; + + if (fptr == NULL) { delcnt = 0; idc = 0; return 0; } idc++; - if(fptr->filemode) + if (fptr->filemode) return 0; clear(); move(10, 0); prints("您要讀來自[%s]的訊息(%s)嗎?", fptr->owner, fptr->title); getdata(11, 0, "請您確定(Y/N/Q)?[Y] ", genbuf, 3, DOECHO); - if(genbuf[0] == 'q') + if (genbuf[0] == 'q') return QUIT; - if(genbuf[0] == 'n') + if (genbuf[0] == 'n') return 0; - + setuserfile(fname, fptr->filename); fptr->filemode |= FILE_READ; - if(substitute_record(currmaildir, fptr, sizeof(*fptr), idc)) + if (substitute_record(currmaildir, fptr, sizeof(*fptr), idc)) return -1; - + mrd = 1; delete_it = NA; - while(!done) { - int more_result = more(fname, YEA); + while (!done) { + int more_result = more(fname, YEA); - switch(more_result) { + switch (more_result) { case 1: return READ_PREV; case 2: @@ -705,8 +744,8 @@ static int read_new_mail(fileheader_t *fptr) { clrtoeol(); outs(msg_mailer); refresh(); - - switch(egetch()) { + + switch (egetch()) { case 'r': case 'R': mail_reply(idc, fptr, currmaildir); @@ -724,11 +763,11 @@ static int read_new_mail(fileheader_t *fptr) { done = YEA; } } - if(delete_it) { + if (delete_it) { clear(); prints("刪除信件《%s》", fptr->title); getdata(1, 0, msg_sure_ny, genbuf, 2, LCECHO); - if(genbuf[0] == 'y') { + if (genbuf[0] == 'y') { unlink(fname); delmsgs[delcnt++] = idc; } @@ -737,7 +776,9 @@ static int read_new_mail(fileheader_t *fptr) { return 0; } -int m_new() { +int +m_new() +{ clear(); mrd = 0; setutmpmode(RMAIL); @@ -745,14 +786,14 @@ int m_new() { clear(); curredit |= EDIT_MAIL; curredit &= ~EDIT_ITEM; - if(apply_record(currmaildir, read_new_mail, sizeof(fileheader_t)) == -1) { + if (apply_record(currmaildir, read_new_mail, sizeof(fileheader_t)) == -1) { outs("沒有新信件了"); pressanykey(); return -1; } curredit = 0; - if(delcnt) { - while(delcnt--) + if (delcnt) { + while (delcnt--) delete_record(currmaildir, sizeof(fileheader_t), delmsgs[delcnt]); } outs(mrd ? "信已閱\畢" : "沒有新信件了"); @@ -760,32 +801,36 @@ int m_new() { return -1; } -static void mailtitle() { - char buf[256] = ""; +static void +mailtitle() +{ + char buf[256] = ""; showtitle("\0郵件選單", BBSName); - sprintf(buf,"[←]離開[↑↓]選擇[→]閱\讀信件 [R]回信 [x]轉達 " - "[y]群組回信 [O]站外信:%s [h]求助\n\033[7m" - "編號 日 期 作 者 信 件 標 題 \033[32m", - HAS_PERM(PERM_NOOUTMAIL)? "\033[31m關\033[m":"開"); + sprintf(buf, "[←]離開[↑↓]選擇[→]閱\讀信件 [R]回信 [x]轉達 " + "[y]群組回信 [O]站外信:%s [h]求助\n\033[7m" + "編號 日 期 作 者 信 件 標 題 \033[32m", + HAS_PERM(PERM_NOOUTMAIL) ? "\033[31m關\033[m" : "開"); outs(buf); - buf[0]=0; - if(mailsumlimit) { - sprintf(buf,"(容量:%d/%dk %d/%d篇)", mailsum, mailsumlimit, + buf[0] = 0; + if (mailsumlimit) { + sprintf(buf, "(容量:%d/%dk %d/%d篇)", mailsum, mailsumlimit, mailkeep, mailmaxkeep); } - sprintf(buf, "%s%*s\033[m", buf, 29 - (int) strlen(buf), ""); + sprintf(buf, "%s%*s\033[m", buf, 29 - (int)strlen(buf), ""); outs(buf); } -static void maildoent(int num, fileheader_t *ent) { - char *title, *mark, color, type = "+ Mm"[(ent->filemode&3)]; +static void +maildoent(int num, fileheader_t * ent) +{ + char *title, *mark, color, type = "+ Mm"[(ent->filemode & 3)]; if (TagNum && !Tagger(atoi(ent->filename + 2), 0, TAG_NIN)) - type = 'D'; + type = 'D'; title = subject(mark = ent->title); - if(title == mark) { + if (title == mark) { color = '1'; mark = "◇"; } else { @@ -793,7 +838,7 @@ static void maildoent(int num, fileheader_t *ent) { mark = "R:"; } - if(strncmp(currtitle, title, TTLEN)) + if (strncmp(currtitle, title, TTLEN)) prints("%5d %c %-7s%-15.14s%s %.46s\n", num, type, ent->date, ent->owner, mark, title); else @@ -801,25 +846,29 @@ static void maildoent(int num, fileheader_t *ent) { ent->date, ent->owner, color, mark, title); } -static int m_idle(int ent, fileheader_t *fhdr, char *direct) { +static int +m_idle(int ent, fileheader_t * fhdr, char *direct) +{ t_idle(); return FULLUPDATE; } -static int mail_del(int ent, fileheader_t *fhdr, char *direct) { - char genbuf[200]; +static int +mail_del(int ent, fileheader_t * fhdr, char *direct) +{ + char genbuf[200]; - if(fhdr->filemode & FILE_MARKED) + if (fhdr->filemode & FILE_MARKED) return DONOTHING; getdata(1, 0, msg_del_ny, genbuf, 3, LCECHO); - if(genbuf[0] == 'y') { + if (genbuf[0] == 'y') { strcpy(currfile, fhdr->filename); - if(!delete_file(direct, sizeof(*fhdr), ent, cmpfilename)) { + if (!delete_file(direct, sizeof(*fhdr), ent, cmpfilename)) { setdirpath(genbuf, direct, fhdr->filename); unlink(genbuf); - if((currmode & MODE_SELECT)) { - int index; + if ((currmode & MODE_SELECT)) { + int index; sethomedir(genbuf, cuser.userid); index = getindex(genbuf, fhdr->filename, sizeof(fileheader_t)); delete_file(genbuf, sizeof(fileheader_t), index, cmpfilename); @@ -830,31 +879,32 @@ static int mail_del(int ent, fileheader_t *fhdr, char *direct) { return FULLUPDATE; } -static int mail_read(int ent, fileheader_t *fhdr, char *direct) { - char buf[64]; - char done, delete_it, replied; +static int +mail_read(int ent, fileheader_t * fhdr, char *direct) +{ + char buf[64]; + char done, delete_it, replied; clear(); setdirpath(buf, direct, fhdr->filename); strncpy(currtitle, subject(fhdr->title), TTLEN); done = delete_it = replied = NA; - while(!done) { - int more_result = more(buf, YEA); - - if(more_result != -1) { + while (!done) { + int more_result = more(buf, YEA); + + if (more_result != -1) { fhdr->filemode |= FILE_READ; - if((currmode & MODE_SELECT)) { - int index; - + if ((currmode & MODE_SELECT)) { + int index; + index = getindex(currmaildir, fhdr->filename, - sizeof(fileheader_t)); + sizeof(fileheader_t)); substitute_record(currmaildir, fhdr, sizeof(*fhdr), index); substitute_record(direct, fhdr, sizeof(*fhdr), ent); - } - else + } else substitute_record(currmaildir, fhdr, sizeof(*fhdr), ent); } - switch(more_result) { + switch (more_result) { case 1: return READ_PREV; case 2: @@ -878,8 +928,8 @@ static int mail_read(int ent, fileheader_t *fhdr, char *direct) { clrtoeol(); refresh(); outs(msg_mailer); - - switch(egetch()) { + + switch (egetch()) { case 'r': case 'R': replied = YEA; @@ -897,17 +947,17 @@ static int mail_read(int ent, fileheader_t *fhdr, char *direct) { done = YEA; } } - if(delete_it) + if (delete_it) mail_del(ent, fhdr, direct); else { fhdr->filemode |= FILE_READ; #ifdef POSTBUG - if(replied) + if (replied) bug_possible = YEA; #endif - if((currmode & MODE_SELECT)) { - int index; - + if ((currmode & MODE_SELECT)) { + int index; + index = getindex(currmaildir, fhdr->filename, sizeof(fileheader_t)); substitute_record(currmaildir, fhdr, sizeof(*fhdr), index); substitute_record(direct, fhdr, sizeof(*fhdr), ent); @@ -921,31 +971,32 @@ static int mail_read(int ent, fileheader_t *fhdr, char *direct) { } /* in boards/mail 回信給原作者,轉信站亦可 */ -int mail_reply(int ent, fileheader_t *fhdr, char *direct) { - char uid[STRLEN]; - char *t; - FILE *fp; - char genbuf[512]; +int +mail_reply(int ent, fileheader_t * fhdr, char *direct) +{ + char uid[STRLEN]; + char *t; + FILE *fp; + char genbuf[512]; stand_title("回 信"); /* 判斷是 boards 或 mail */ - if(curredit & EDIT_MAIL) + if (curredit & EDIT_MAIL) setuserfile(quote_file, fhdr->filename); else setbfile(quote_file, currboard, fhdr->filename); /* find the author */ strcpy(quote_user, fhdr->owner); - if(strchr(quote_user, '.')) { + if (strchr(quote_user, '.')) { genbuf[0] = '\0'; - if((fp = fopen(quote_file, "r"))) { + if ((fp = fopen(quote_file, "r"))) { fgets(genbuf, 512, fp); fclose(fp); } - t = strtok(genbuf, str_space); - if(!strcmp(t, str_author1) || !strcmp(t, str_author2)) + if (!strcmp(t, str_author1) || !strcmp(t, str_author2)) strcpy(uid, strtok(NULL, str_space)); else { outs("錯誤: 找不到作者。"); @@ -954,14 +1005,14 @@ int mail_reply(int ent, fileheader_t *fhdr, char *direct) { } } else strcpy(uid, quote_user); - + /* make the title */ do_reply_title(3, fhdr->title); prints("\n收信人: %s\n標 題: %s\n", uid, save_title); - + /* edit, then send the mail */ ent = curredit; - switch(do_send(uid, save_title)) { + switch (do_send(uid, save_title)) { case -1: outs(err_uid); break; @@ -977,12 +1028,14 @@ int mail_reply(int ent, fileheader_t *fhdr, char *direct) { return FULLUPDATE; } -static int mail_edit(int ent, fileheader_t *fhdr, char *direct) { - char genbuf[200]; +static int +mail_edit(int ent, fileheader_t * fhdr, char *direct) +{ + char genbuf[200]; - if(!HAS_PERM(PERM_SYSOP) && - strcmp(cuser.userid, fhdr->owner) && - strcmp("[備.忘.錄]", fhdr->owner)) + if (!HAS_PERM(PERM_SYSOP) && + strcmp(cuser.userid, fhdr->owner) && + strcmp("[備.忘.錄]", fhdr->owner)) return DONOTHING; setdirpath(genbuf, direct, fhdr->filename); @@ -990,7 +1043,8 @@ static int mail_edit(int ent, fileheader_t *fhdr, char *direct) { return FULLUPDATE; } -static int mail_nooutmail(int ent, fileheader_t *fhdr, char *direct) +static int +mail_nooutmail(int ent, fileheader_t * fhdr, char *direct) { cuser.userlevel ^= PERM_NOOUTMAIL; passwd_update(usernum, &cuser); @@ -998,11 +1052,13 @@ static int mail_nooutmail(int ent, fileheader_t *fhdr, char *direct) } -static int mail_mark(int ent, fileheader_t *fhdr, char *direct) { +static int +mail_mark(int ent, fileheader_t * fhdr, char *direct) +{ fhdr->filemode ^= FILE_MARKED; - - if((currmode & MODE_SELECT)) { - int index; + + if ((currmode & MODE_SELECT)) { + int index; index = getindex(currmaildir, fhdr->filename, sizeof(fileheader_t)); substitute_record(currmaildir, fhdr, sizeof(*fhdr), index); @@ -1013,7 +1069,7 @@ static int mail_mark(int ent, fileheader_t *fhdr, char *direct) { } /* help for mail reading */ -static char *mail_help[] = { +static char *mail_help[] = { "\0電子信箱操作說明", "\01基本命令", "(p)(↑) 前一篇文章", @@ -1038,19 +1094,23 @@ static char *mail_help[] = { NULL }; -static int m_help() { +static int +m_help() +{ show_help(mail_help); return FULLUPDATE; } -static int mail_cross_post(int ent, fileheader_t *fhdr, char *direct) { - char xboard[20], fname[80], xfpath[80], xtitle[80], inputbuf[10]; - fileheader_t xfile; - FILE *xptr; - int author = 0; - char genbuf[200]; - char genbuf2[4]; - +static int +mail_cross_post(int ent, fileheader_t * fhdr, char *direct) +{ + char xboard[20], fname[80], xfpath[80], xtitle[80], inputbuf[10]; + fileheader_t xfile; + FILE *xptr; + int author = 0; + char genbuf[200]; + char genbuf2[4]; + move(2, 0); clrtoeol(); move(3, 0); @@ -1061,72 +1121,70 @@ static int mail_cross_post(int ent, fileheader_t *fhdr, char *direct) { completeboard_compar, completeboard_permission, completeboard_getname); - if(*xboard == '\0' || !haspostperm(xboard)) + if (*xboard == '\0' || !haspostperm(xboard)) return FULLUPDATE; - + ent = 1; - if(HAS_PERM(PERM_SYSOP) || !strcmp(fhdr->owner, cuser.userid)) { + if (HAS_PERM(PERM_SYSOP) || !strcmp(fhdr->owner, cuser.userid)) { getdata(2, 0, "(1)原文轉載 (2)舊轉錄格式?[1] ", genbuf, 3, DOECHO); - if(genbuf[0] != '2') { + if (genbuf[0] != '2') { ent = 0; getdata(2, 0, "保留原作者名稱嗎?[Y] ", inputbuf, 3, DOECHO); - if(inputbuf[0] != 'n' && inputbuf[0] != 'N') + if (inputbuf[0] != 'n' && inputbuf[0] != 'N') author = 1; } } - - if(ent) + if (ent) sprintf(xtitle, "[轉錄]%.66s", fhdr->title); else strcpy(xtitle, fhdr->title); - + sprintf(genbuf, "採用原標題《%.60s》嗎?[Y] ", xtitle); getdata(2, 0, genbuf, genbuf2, sizeof(genbuf2), LCECHO); - if(*genbuf2 == 'n') - if(getdata(2, 0, "標題:", genbuf, TTLEN, DOECHO)) + if (*genbuf2 == 'n') + if (getdata(2, 0, "標題:", genbuf, TTLEN, DOECHO)) strcpy(xtitle, genbuf); - + getdata(2, 0, "(S)存檔 (L)站內 (Q)取消?[Q] ", genbuf, 3, LCECHO); - if(genbuf[0] == 'l' || genbuf[0] == 's') { - int currmode0 = currmode; + if (genbuf[0] == 'l' || genbuf[0] == 's') { + int currmode0 = currmode; currmode = 0; setbpath(xfpath, xboard); stampfile(xfpath, &xfile); - if(author) + if (author) strcpy(xfile.owner, fhdr->owner); else strcpy(xfile.owner, cuser.userid); strcpy(xfile.title, xtitle); - if(genbuf[0] == 'l') { + if (genbuf[0] == 'l') { xfile.filemode = FILE_LOCAL; - } - + } setuserfile(fname, fhdr->filename); - if(ent) { + if (ent) { xptr = fopen(xfpath, "w"); - + strcpy(save_title, xfile.title); strcpy(xfpath, currboard); strcpy(currboard, xboard); write_header(xptr); strcpy(currboard, xfpath); - + fprintf(xptr, "※ [本文轉錄自 %s 信箱]\n\n", cuser.userid); - + b_suckinfile(xptr, fname); - addsignature(xptr,0); + addsignature(xptr, 0); fclose(xptr); } else { unlink(xfpath); Link(fname, xfpath); } - + setbdir(fname, xboard); append_record(fname, &xfile, sizeof(xfile)); setbtotal(getbnum(xboard)); - if(!xfile.filemode) + if (!xfile.filemode) outgo_post(&xfile, xboard); cuser.numposts++; passwd_update(usernum, &cuser); @@ -1137,12 +1195,14 @@ static int mail_cross_post(int ent, fileheader_t *fhdr, char *direct) { return FULLUPDATE; } -int mail_man() { - char buf[64],buf1[64]; +int +mail_man() +{ + char buf[64], buf1[64]; if (HAS_PERM(PERM_MAILLIMIT)) { - int mode0 = currutmp->mode; - int stat0 = currstat; - + int mode0 = currutmp->mode; + int stat0 = currstat; + sethomeman(buf, cuser.userid); sprintf(buf1, "%s 的信件夾", cuser.userid); a_menu(buf1, buf, 1); @@ -1153,20 +1213,22 @@ int mail_man() { return DONOTHING; } -static int mail_cite(int ent, fileheader_t *fhdr, char *direct) { - char fpath[256]; - char title[TTLEN + 1]; - static char xboard[20]; - char buf[20]; - boardheader_t *bp; +static int +mail_cite(int ent, fileheader_t * fhdr, char *direct) +{ + char fpath[256]; + char title[TTLEN + 1]; + static char xboard[20]; + char buf[20]; + boardheader_t *bp; setuserfile(fpath, fhdr->filename); strcpy(title, "◇ "); - strncpy(title+3, fhdr->title, TTLEN-3); + strncpy(title + 3, fhdr->title, TTLEN - 3); title[TTLEN] = '\0'; a_copyitem(fpath, title, 0, 1); - if(cuser.userlevel >= PERM_BM) { + if (cuser.userlevel >= PERM_BM) { move(2, 0); clrtoeol(); move(3, 0); @@ -1179,9 +1241,9 @@ static int mail_cite(int ent, fileheader_t *fhdr, char *direct) { completeboard_compar, completeboard_permission, completeboard_getname); - if(*buf) + if (*buf) strcpy(xboard, buf); - if(*xboard && (bp = getbcache(getbnum(xboard)))) { + if (*xboard && (bp = getbcache(getbnum(xboard)))) { setapath(fpath, xboard); setutmpmode(ANNOUNCE); a_menu(xboard, fpath, HAS_PERM(PERM_ALLBOARD) ? 2 : @@ -1192,15 +1254,17 @@ static int mail_cite(int ent, fileheader_t *fhdr, char *direct) { return FULLUPDATE; } else { mail_man(); - return FULLUPDATE; + return FULLUPDATE; } } -static int mail_save(int ent, fileheader_t *fhdr, char *direct) { - char fpath[256]; - char title[TTLEN+1]; +static int +mail_save(int ent, fileheader_t * fhdr, char *direct) +{ + char fpath[256]; + char title[TTLEN + 1]; - if(HAS_PERM(PERM_MAILLIMIT)) { + if (HAS_PERM(PERM_MAILLIMIT)) { setuserfile(fpath, fhdr->filename); strcpy(title, "◇ "); strncpy(title + 3, fhdr->title, TTLEN - 3); @@ -1214,50 +1278,53 @@ static int mail_save(int ent, fileheader_t *fhdr, char *direct) { } #ifdef OUTJOBSPOOL -static int mail_waterball(int ent, fileheader_t *fhdr, char *direct) +static int +mail_waterball(int ent, fileheader_t * fhdr, char *direct) { - static char address[60], cmode = 1; - char fname[500], genbuf[200]; - FILE *fp; + static char address[60], cmode = 1; + char fname[500], genbuf[200]; + FILE *fp; - if( !(strstr(fhdr->title, "熱線") && strstr(fhdr->title, "記錄")) ){ + if (!(strstr(fhdr->title, "熱線") && strstr(fhdr->title, "記錄"))) { vmsg("必須是 熱線記錄 才能使用水球整理的唷!"); return 1; } - if(!address[0]) + if (!address[0]) strcpy(address, cuser.email); move(b_lines - 5, 0); outs("水球整理程式:\n" "系統將會按照和不同人丟的水球各自獨立\n" "於整點的時候 (尖鋒時段除外) 將資料整理好寄送給您\n\n\n"); - if(address[0]) { + if (address[0]) { sprintf(genbuf, "寄給 [%s] 嗎(Y/N/Q)?[Y] ", address); getdata(b_lines - 2, 0, genbuf, fname, 3, LCECHO); - if(fname[0] == 'q') { outmsg("取消處理"); return 1; } - if(fname[0] == 'n') + if (fname[0] == 'q') { + outmsg("取消處理"); + return 1; + } + if (fname[0] == 'n') address[0] = '\0'; } - - if(!address[0]) { + if (!address[0]) { getdata(b_lines - 2, 0, "請輸入郵件地址:", fname, 60, DOECHO); - if(fname[0] && strchr(fname, '.')) { + if (fname[0] && strchr(fname, '.')) { strcpy(address, fname); } else { vmsg("取消處理"); return 1; } } - if(invalidaddr(address)) + if (invalidaddr(address)) return -2; - - // sprintf(fname, "%d\n", cmode); + + //sprintf(fname, "%d\n", cmode); getdata(b_lines - 1, 0, "使用模式(0/1/Q)? [1]", fname, 3, LCECHO); - if( fname[0] == 'Q' || fname[0] == 'q' ){ + if (fname[0] == 'Q' || fname[0] == 'q') { outmsg("取消處理"); return 1; } cmode = (fname[0] != '0' && fname[0] != '1') ? 1 : fname[0] - '0'; - + sprintf(fname, BBSHOME "/jobspool/water.src.%s-%d", cuser.userid, (int)now); sprintf(genbuf, "cp " BBSHOME "/home/%c/%s/%s %s", @@ -1287,7 +1354,7 @@ static struct onekey_t mail_comms[] = { {'T', edit_title}, {'x', m_forward}, {'X', mail_cross_post}, - {Ctrl('G'), built_mail_index}, /* 修信箱 */ + {Ctrl('G'), built_mail_index}, /* 修信箱 */ {'y', multi_reply}, {Ctrl('I'), m_idle}, {'h', m_help}, @@ -1297,13 +1364,15 @@ static struct onekey_t mail_comms[] = { {'\0', NULL} }; -int m_read() { - if(get_num_records(currmaildir, sizeof(fileheader_t))) { +int +m_read() +{ + if (get_num_records(currmaildir, sizeof(fileheader_t))) { curredit = EDIT_MAIL; curredit &= ~EDIT_ITEM; - i_read(RMAIL, currmaildir, mailtitle, maildoent, mail_comms, -1); + i_read(RMAIL, currmaildir, mailtitle, maildoent, mail_comms, -1); curredit = 0; - currutmp->mailalert = load_mailalert(cuser.userid); + currutmp->mailalert = load_mailalert(cuser.userid); return 0; } else { outs("您沒有來信"); @@ -1312,15 +1381,17 @@ int m_read() { } /* 寄站內信 */ -static int send_inner_mail(char *fpath, char *title, char *receiver) { - char genbuf[256]; - fileheader_t mymail; - - if(!searchuser(receiver)) +static int +send_inner_mail(char *fpath, char *title, char *receiver) +{ + char genbuf[256]; + fileheader_t mymail; + + if (!searchuser(receiver)) return -2; sethomepath(genbuf, receiver); stampfile(genbuf, &mymail); - if(!strcmp(receiver, cuser.userid)) { + if (!strcmp(receiver, cuser.userid)) { strcpy(mymail.owner, "[" BBSNAME "]"); mymail.filemode = FILE_READ; } else @@ -1329,7 +1400,7 @@ static int send_inner_mail(char *fpath, char *title, char *receiver) { unlink(genbuf); Link(fpath, genbuf); sethomedir(genbuf, receiver); - return do_append(genbuf, &mymail, sizeof(mymail)); + return do_append(genbuf, &mymail, sizeof(mymail)); } #include <netdb.h> @@ -1337,55 +1408,54 @@ static int send_inner_mail(char *fpath, char *title, char *receiver) { #include <time.h> #ifndef USE_BSMTP -static int bbs_sendmail(char *fpath, char *title, char *receiver) { - static int configured = 0; - static char myhostname[STRLEN]; - static char myusername[20]; +static int +bbs_sendmail(char *fpath, char *title, char *receiver) +{ + static int configured = 0; + static char myhostname[STRLEN]; + static char myusername[20]; struct hostent *hbuf; - struct passwd *pbuf; - char *ptr; - char genbuf[256]; - FILE *fin, *fout; + struct passwd *pbuf; + char *ptr; + char genbuf[256]; + FILE *fin, *fout; /* 中途攔截 */ - if((ptr = strchr(receiver, ';'))) { - struct tm *ptime; - + if ((ptr = strchr(receiver, ';'))) { + struct tm *ptime; + *ptr = '\0'; } - - if((ptr = strstr(receiver, str_mail_address)) || !strchr(receiver,'@')) { - char hacker[20]; - int len; - - if(strchr(receiver,'@')) { - len = ptr - receiver; - memcpy(hacker, receiver, len); - hacker[len] = '\0'; - } else - strcpy(hacker,receiver); + if ((ptr = strstr(receiver, str_mail_address)) || !strchr(receiver, '@')) { + char hacker[20]; + int len; + + if (strchr(receiver, '@')) { + len = ptr - receiver; + memcpy(hacker, receiver, len); + hacker[len] = '\0'; + } else + strcpy(hacker, receiver); return send_inner_mail(fpath, title, hacker); } - /* setup the hostname and username */ - if(!configured) { + if (!configured) { /* get host name */ hbuf = gethostbyname("localhost"); - if(hbuf) + if (hbuf) strncpy(myhostname, hbuf->h_name, STRLEN); /* get bbs uident */ pbuf = getpwuid(getuid()); - if(pbuf) + if (pbuf) strncpy(myusername, pbuf->pw_name, 20); - if(hbuf && pbuf) + if (hbuf && pbuf) configured = 1; else return -1; } - /* Running the sendmail */ - if(fpath == NULL) { + if (fpath == NULL) { sprintf(genbuf, "/usr/sbin/sendmail %s > /dev/null", receiver); fin = fopen("etc/confirm", "r"); } else { @@ -1394,18 +1464,18 @@ static int bbs_sendmail(char *fpath, char *title, char *receiver) { fin = fopen(fpath, "r"); } fout = popen(genbuf, "w"); - if(fin == NULL || fout == NULL) + if (fin == NULL || fout == NULL) return -1; - - if(fpath) + + if (fpath) fprintf(fout, "Reply-To: %s%s\nFrom: %s%s\n", cuser.userid, str_mail_address, cuser.userid, str_mail_address); fprintf(fout, "To: %s\nSubject: %s\n", receiver, title); fprintf(fout, "X-Disclaimer: " BBSNAME "對本信內容恕不負責。\n\n"); - - while(fgets(genbuf, 255, fin)) { - if(genbuf[0] == '.' && genbuf[1] == '\n') + + while (fgets(genbuf, 255, fin)) { + if (genbuf[0] == '.' && genbuf[1] == '\n') fputs(". \n", fout); else fputs(genbuf, fout); @@ -1415,82 +1485,84 @@ static int bbs_sendmail(char *fpath, char *title, char *receiver) { pclose(fout); return 0; } -#else /* USE_BSMTP */ +#else /* USE_BSMTP */ -int bsmtp(char *fpath, char *title, char *rcpt, int method) { - char buf[80], *ptr; - time_t chrono; - MailQueue mqueue; +int +bsmtp(char *fpath, char *title, char *rcpt, int method) +{ + char buf[80], *ptr; + time_t chrono; + MailQueue mqueue; /* check if the mail is a inner mail */ - if((ptr = strstr(rcpt, str_mail_address)) || !strchr(rcpt, '@')) { - char hacker[20]; - int len; - - if(strchr(rcpt,'@')) { - len = ptr - rcpt; - memcpy(hacker, rcpt, len); - hacker[len] = '\0'; - } else - strcpy(hacker, rcpt); + if ((ptr = strstr(rcpt, str_mail_address)) || !strchr(rcpt, '@')) { + char hacker[20]; + int len; + + if (strchr(rcpt, '@')) { + len = ptr - rcpt; + memcpy(hacker, rcpt, len); + hacker[len] = '\0'; + } else + strcpy(hacker, rcpt); return send_inner_mail(fpath, title, hacker); } - chrono = now; - if(method != MQ_JUSTIFY) { /* 認證信 */ + if (method != MQ_JUSTIFY) { /* 認證信 */ /* stamp the queue file */ strcpy(buf, "out/"); - for(;;) { - sprintf(buf + 4,"M.%ld.A", ++chrono); - if(!dashf(buf)) { + for (;;) { + sprintf(buf + 4, "M.%ld.A", ++chrono); + if (!dashf(buf)) { Link(fpath, buf); break; } } - + fpath = buf; strcpy(mqueue.filepath, fpath); strcpy(mqueue.subject, title); } - /* setup mail queue */ + /* setup mail queue */ mqueue.mailtime = chrono; mqueue.method = method; strcpy(mqueue.sender, cuser.userid); strcpy(mqueue.username, cuser.username); strcpy(mqueue.rcpt, rcpt); - if(do_append("out/.DIR", (fileheader_t *)&mqueue, sizeof(mqueue)) < 0) + if (do_append("out/.DIR", (fileheader_t *) & mqueue, sizeof(mqueue)) < 0) return 0; return chrono; } -#endif /* USE_BSMTP */ - -int doforward(char *direct, fileheader_t *fh, int mode) { - static char address[60]; - char fname[500]; - int return_no; - char genbuf[200]; - - if(!address[0]) +#endif /* USE_BSMTP */ + +int +doforward(char *direct, fileheader_t * fh, int mode) +{ + static char address[60]; + char fname[500]; + int return_no; + char genbuf[200]; + + if (!address[0]) strcpy(address, cuser.email); - if(address[0]) { + if (address[0]) { sprintf(genbuf, "確定轉寄給 [%s] 嗎(Y/N/Q)?[Y] ", address); getdata(b_lines - 1, 0, genbuf, fname, 3, LCECHO); - - if(fname[0] == 'q') { + + if (fname[0] == 'q') { outmsg("取消轉寄"); return 1; } - if(fname[0] == 'n') + if (fname[0] == 'n') address[0] = '\0'; } - - if(!address[0]) { - do{ + if (!address[0]) { + do { getdata(b_lines - 1, 0, "請輸入轉寄地址:", fname, 60, DOECHO); - if(fname[0]) { - if(strchr(fname, '.')) + if (fname[0]) { + if (strchr(fname, '.')) strcpy(address, fname); else sprintf(address, "%s.bbs@%s", fname, MYHOSTNAME); @@ -1498,28 +1570,27 @@ int doforward(char *direct, fileheader_t *fh, int mode) { outmsg("取消轉寄"); return 1; } - }while(mode=='Z' && strstr(address, MYHOSTNAME)); + } while (mode == 'Z' && strstr(address, MYHOSTNAME)); } - if(invalidaddr(address)) + if (invalidaddr(address)) return -2; - + sprintf(fname, "正轉寄給 %s, 請稍候...", address); outmsg(fname); move(b_lines - 1, 0); refresh(); - + /* 追蹤使用者 */ - if(HAS_PERM(PERM_LOGUSER)) { - char msg[200]; - + if (HAS_PERM(PERM_LOGUSER)) { + char msg[200]; + sprintf(msg, "%s mailforward to %s at %s", cuser.userid, address, Cdate(&now)); log_user(msg); } - - if(mode == 'Z') { + if (mode == 'Z') { sprintf(fname, TAR_PATH " cfz /tmp/home.%s.tgz home/%c/%s; " - MUTT_PATH" -a /tmp/home.%s.tgz -s 'home.%s.tgz' '%s' </dev/null;" + MUTT_PATH " -a /tmp/home.%s.tgz -s 'home.%s.tgz' '%s' </dev/null;" "rm /tmp/home.%s.tgz", cuser.userid, cuser.userid[0], cuser.userid, cuser.userid, cuser.userid, address, cuser.userid); @@ -1530,58 +1601,60 @@ int doforward(char *direct, fileheader_t *fh, int mode) { cuser.userid[0], cuser.userid, cuser.userid, direct); system(fname); strcpy(fname, direct); - } else if(mode == 'U') { - char tmp_buf[128]; + } else if (mode == 'U') { + char tmp_buf[128]; sprintf(fname, "/tmp/bbs.uu%05d", currpid); sprintf(tmp_buf, "/usr/bin/uuencode %s/%s uu.%05d > %s", direct, fh->filename, currpid, fname); system(tmp_buf); - } else if (mode == 'F'){ - char tmp_buf[128]; - + } else if (mode == 'F') { + char tmp_buf[128]; + sprintf(fname, "/tmp/bbs.f%05d", currpid); - sprintf(tmp_buf, "cp %s/%s %s",direct,fh->filename,fname); + sprintf(tmp_buf, "cp %s/%s %s", direct, fh->filename, fname); system(tmp_buf); } else return -1; - + return_no = #ifndef USE_BSMTP bbs_sendmail(fname, fh->title, address); #else - bsmtp(fname, fh->title, address,mode); + bsmtp(fname, fh->title, address, mode); #endif unlink(fname); return (return_no); } -int load_mailalert(char *userid) { - struct stat st; - char maildir[256]; - int fd; - register int numfiles; - fileheader_t my_mail; - - sethomedir(maildir, userid); - if(!HAS_PERM(PERM_BASIC)) +int +load_mailalert(char *userid) +{ + struct stat st; + char maildir[256]; + int fd; + register int numfiles; + fileheader_t my_mail; + + sethomedir(maildir, userid); + if (!HAS_PERM(PERM_BASIC)) return 0; - if(stat(maildir, &st) < 0) + if (stat(maildir, &st) < 0) return 0; numfiles = st.st_size / sizeof(fileheader_t); - if(numfiles <= 0) + if (numfiles <= 0) return 0; - - /* 看看有沒有信件還沒讀過?從檔尾回頭檢查,效率較高 */ - if((fd = open(maildir, O_RDONLY)) > 0) { + + /* 看看有沒有信件還沒讀過?從檔尾回頭檢查,效率較高 */ + if ((fd = open(maildir, O_RDONLY)) > 0) { lseek(fd, st.st_size - sizeof(fileheader_t), SEEK_SET); - while(numfiles--) { + while (numfiles--) { read(fd, &my_mail, sizeof(fileheader_t)); - if(!(my_mail.filemode & FILE_READ)) { + if (!(my_mail.filemode & FILE_READ)) { close(fd); return 1; } - lseek(fd, -(off_t)2 * sizeof(fileheader_t), SEEK_CUR); + lseek(fd, -(off_t) 2 * sizeof(fileheader_t), SEEK_CUR); } close(fd); } @@ -1589,11 +1662,13 @@ int load_mailalert(char *userid) { } #ifdef EMAIL_JUSTIFY -static void mail_justify(userec_t muser) { - fileheader_t mhdr; - char title[128], buf1[80]; - FILE* fp; - +static void +mail_justify(userec_t muser) +{ + fileheader_t mhdr; + char title[128], buf1[80]; + FILE *fp; + sethomepath(buf1, muser.userid); stampfile(buf1, &mhdr); unlink(buf1); @@ -1601,36 +1676,36 @@ static void mail_justify(userec_t muser) { strncpy(mhdr.title, "[審核通過]", TTLEN); mhdr.filemode = 0; - if(valid_ident(muser.email) && !invalidaddr(muser.email)) { - char title[80], *ptr; - unsigned short checksum; /* 16-bit is enough */ - char ch; - + if (valid_ident(muser.email) && !invalidaddr(muser.email)) { + char title[80], *ptr; + unsigned short checksum; /* 16-bit is enough */ + char ch; + checksum = searchuser(muser.userid); ptr = muser.email; - while((ch = *ptr++)) { - if(ch <= ' ') + while ((ch = *ptr++)) { + if (ch <= ' ') break; - if(ch >= 'A' && ch <= 'Z') + if (ch >= 'A' && ch <= 'Z') ch |= 0x20; checksum = (checksum << 1) ^ ch; } - + sprintf(title, "[PTT BBS]To %s(%d:%d) [User Justify]", muser.userid, getuser(muser.userid) + MAGIC_KEY, checksum); - if( + if ( #ifndef USE_BSMTP bbs_sendmail(NULL, title, muser.email) #else bsmtp(NULL, title, muser.email, MQ_JUSTIFY); #endif - < 0) + <0) Link("etc/bademail", buf1); else - Link("etc/replyemail", buf1); + Link("etc/replyemail", buf1); } else Link("etc/bademail", buf1); sethomedir(title, muser.userid); append_record(title, &mhdr, sizeof(mhdr)); } -#endif /* EMAIL_JUSTIFY */ +#endif /* EMAIL_JUSTIFY */ diff --git a/pttbbs/mbbsd/mbbsd.c b/pttbbs/mbbsd/mbbsd.c index 5109474d..c9736e1b 100644 --- a/pttbbs/mbbsd/mbbsd.c +++ b/pttbbs/mbbsd/mbbsd.c @@ -1,148 +1,150 @@ -/* $Id: mbbsd.c,v 1.39 2002/07/05 13:14:14 in2 Exp $ */ +/* $Id: mbbsd.c,v 1.40 2002/07/05 17:10:27 in2 Exp $ */ #include "bbs.h" #define SOCKET_QLEN 4 #define TH_LOW 100 #define TH_HIGH 120 -static void do_aloha (char *hello); +static void do_aloha(char *hello); #if 0 -static jmp_buf byebye; +static jmp_buf byebye; #endif -static char remoteusername[40] = "?"; +static char remoteusername[40] = "?"; static unsigned char enter_uflag; -static int use_shell_login_mode = 0; +static int use_shell_login_mode = 0; static struct sockaddr_in xsin; /* set signal handler, which won't be reset once signal comes */ static void -signal_restart (int signum, void (*handler) (int)) +signal_restart(int signum, void (*handler) (int)) { struct sigaction act; act.sa_handler = handler; - memset (&(act.sa_mask), 0, sizeof (sigset_t)); + memset(&(act.sa_mask), 0, sizeof(sigset_t)); act.sa_flags = 0; - sigaction (signum, &act, NULL); + sigaction(signum, &act, NULL); } static void -start_daemon () +start_daemon() { - int n; - char buf[80]; - + int n; + char buf[80]; + /* * More idiot speed-hacking --- the first time conversion makes the C * library open the files containing the locale definition and time zone. * If this hasn't happened in the parent process, it happens in the * children, once per connection --- and it does add up. */ - time_t dummy = time (NULL); - struct tm *dummy_time = localtime (&dummy); - - strftime (buf, 80, "%d/%b/%Y:%H:%M:%S", dummy_time); - -#ifndef NO_FORK - if ((n = fork ())){ - exit (0); + time_t dummy = time(NULL); + struct tm *dummy_time = localtime(&dummy); + + strftime(buf, 80, "%d/%b/%Y:%H:%M:%S", dummy_time); + +#ifndef NO_FORK + if ((n = fork())) { + exit(0); } #endif - + /* rocker.011018: it's a good idea to close all unexcept fd!! */ - n = getdtablesize (); + n = getdtablesize(); while (n) - close (--n); - /* rocker.011018: we don't need to remember original tty, - so request a new session id */ - setsid (); - - /* rocker.011018: after new session, - we should insure the process is clean daemon */ + close(--n); + /* + * rocker.011018: we don't need to remember original tty, so request a + * new session id + */ + setsid(); + + /* + * rocker.011018: after new session, we should insure the process is + * clean daemon + */ #ifndef NO_FORK - if ((n = fork ())){ - exit (0); + if ((n = fork())) { + exit(0); } #endif } static void -reapchild (int sig) +reapchild(int sig) { - int state, pid; - - while ((pid = waitpid (-1, &state, WNOHANG | WUNTRACED)) > 0) - ; + int state, pid; + + while ((pid = waitpid(-1, &state, WNOHANG | WUNTRACED)) > 0); } #define BANNER \ "【" BBSNAME "】◎ 台大流行網 ◎(" MYHOSTNAME ") 調幅(" MYIP ") " /* -#define BANNER \ -"【" BBSNAME "】◎ 台大流行網 ◎(" MYHOSTNAME ")\r\n"\ -" 調幅(" MYIP ") " -*/ + * #define BANNER \ "【" BBSNAME "】◎ 台大流行網 ◎(" MYHOSTNAME ")\r\n"\ " + * 調幅(" MYIP ") " + */ /* check load and print approriate banner string in buf */ static int -chkload (char *buf) +chkload(char *buf) { - char cpu_load[30]; - int i; - - i = cpuload (cpu_load); - - sprintf (buf, BANNER" 系統負荷\r\n %s %s \r\n", cpu_load, - (i > MAX_CPULOAD ? ",高負荷量,請稍後再來 " - "(請利用port 3000~3010連線)" : "")); + char cpu_load[30]; + int i; + + i = cpuload(cpu_load); + + sprintf(buf, BANNER " 系統負荷\r\n %s %s \r\n", cpu_load, + (i > MAX_CPULOAD ? ",高負荷量,請稍後再來 " + "(請利用port 3000~3010連線)" : "")); #ifdef INSCREEN strcpy(buf, (i > MAX_CPULOAD ? BANNER "高負荷量,請稍後再來(請利用port 3000~3010連線)" : "")); #else sprintf(buf, BANNER "%s\r\n", - (i > MAX_CPULOAD ? "高負荷量,請稍後再來(請利用port 3000~3010連線)":"")); + (i > MAX_CPULOAD ? "高負荷量,請稍後再來(請利用port 3000~3010連線)" : "")); #endif if (i > MAX_CPULOAD) return 1; - + return 0; } void -log_user (char *msg) +log_user(char *msg) { - char filename[200]; - - sprintf (filename, BBSHOME "/home/%c/%s/USERLOG", - cuser.userid[0], cuser.userid); - log_file (filename, msg); + char filename[200]; + + sprintf(filename, BBSHOME "/home/%c/%s/USERLOG", + cuser.userid[0], cuser.userid); + log_file(filename, msg); } void -log_usies (char *mode, char *mesg) +log_usies(char *mode, char *mesg) { - char genbuf[200]; - + char genbuf[200]; + if (!mesg) - sprintf (genbuf, cuser.userid[0] ? "%s %s %-12s Stay:%d (%s)" : - "%s %s %s Stay:%d (%s)", - Cdate (&now), mode, cuser.userid, - (int)(now - login_start_time) / 60, cuser.username); + sprintf(genbuf, cuser.userid[0] ? "%s %s %-12s Stay:%d (%s)" : + "%s %s %s Stay:%d (%s)", + Cdate(&now), mode, cuser.userid, + (int)(now - login_start_time) / 60, cuser.username); else - sprintf (genbuf, cuser.userid[0] ? "%s %s %-12s %s" : "%s %s %s%s", - Cdate (&now), mode, cuser.userid, mesg); - log_file (FN_USIES, genbuf); - + sprintf(genbuf, cuser.userid[0] ? "%s %s %-12s %s" : "%s %s %s%s", + Cdate(&now), mode, cuser.userid, mesg); + log_file(FN_USIES, genbuf); + /* 追蹤使用者 */ - if (HAS_PERM (PERM_LOGUSER)) - log_user (genbuf); + if (HAS_PERM(PERM_LOGUSER)) + log_user(genbuf); } static void -setflags (int mask, int value) +setflags(int mask, int value) { if (value) cuser.uflag |= mask; @@ -151,209 +153,206 @@ setflags (int mask, int value) } void -u_exit (char *mode) +u_exit(char *mode) { //userec_t xuser; - int diff = (time (0) - login_start_time) / 60; + int diff = (time(0) - login_start_time) / 60; /* close fd 0 & a to terminate network */ close(0); close(1); - reload_money(); - auto_backup (); + reload_money(); + auto_backup(); save_brdbuf(); - setflags (PAGER_FLAG, currutmp->pager != 1); - setflags (CLOAK_FLAG, currutmp->invisible); - + setflags(PAGER_FLAG, currutmp->pager != 1); + setflags(CLOAK_FLAG, currutmp->invisible); + cuser.invisible = currutmp->invisible; cuser.pager = currutmp->pager; memcpy(cuser.mind, currutmp->mind, 4); setutmpbid(0); - if (!(HAS_PERM (PERM_SYSOP) && HAS_PERM (PERM_DENYPOST)) && - !currutmp->invisible ) - do_aloha ("<<下站通知>> -- 我走囉!"); - - purge_utmp (currutmp); - if ((cuser.uflag != enter_uflag) || (currmode & MODE_DIRTY) || diff){ + if (!(HAS_PERM(PERM_SYSOP) && HAS_PERM(PERM_DENYPOST)) && + !currutmp->invisible) + do_aloha("<<下站通知>> -- 我走囉!"); + + purge_utmp(currutmp); + if ((cuser.uflag != enter_uflag) || (currmode & MODE_DIRTY) || diff) { if (!diff && cuser.numlogins) cuser.numlogins = --cuser.numlogins; /* Leeym 上站停留時間限制式 */ } - passwd_update (usernum, &cuser); - log_usies (mode, NULL); + passwd_update(usernum, &cuser); + log_usies(mode, NULL); } void -system_abort () +system_abort() { if (currmode) - u_exit ("ABORT"); - - clear (); - refresh (); - fprintf (stdout, "謝謝光臨, 記得常來喔 !\n"); - exit (0); + u_exit("ABORT"); + + clear(); + refresh(); + fprintf(stdout, "謝謝光臨, 記得常來喔 !\n"); + exit(0); } void -abort_bbs (int sig) +abort_bbs(int sig) { if (currmode) - u_exit ("AXXED"); - exit (0); + u_exit("AXXED"); + exit(0); } static void -abort_bbs_debug (int sig) +abort_bbs_debug(int sig) { - static int reentrant = 0; - - if (!reentrant){ - int i; + static int reentrant = 0; + + if (!reentrant) { + int i; /* close all file descriptors (including the network connection) */ - for( i = 0 ; i < 256 ; ++i ) + for (i = 0; i < 256; ++i) close(i); reentrant = 1; if (currmode) - u_exit ("AXXED"); - setproctitle("debug me!(%d)",sig); - sleep(3600); /* wait 60 mins for debug */ + u_exit("AXXED"); + setproctitle("debug me!(%d)", sig); + sleep(3600); /* wait 60 mins for debug */ } - exit (0); + exit(0); } /* 登錄 BBS 程式 */ static void -mysrand () +mysrand() { - srand (time (NULL) + currutmp->pid); /* 時間跟 pid 當 rand 的 seed */ + srand(time(NULL) + currutmp->pid); /* 時間跟 pid 當 rand 的 seed */ } int -dosearchuser (char *userid) +dosearchuser(char *userid) { - if ((usernum = getuser (userid))) - memcpy (&cuser, &xuser, sizeof (cuser)); + if ((usernum = getuser(userid))) + memcpy(&cuser, &xuser, sizeof(cuser)); else - memset (&cuser, 0, sizeof (cuser)); + memset(&cuser, 0, sizeof(cuser)); return usernum; } static void talk_request(int sig) { - bell (); - bell (); - if (currutmp->msgcount){ - char buf[200]; - time_t now = time (0); - - sprintf (buf, "\033[33;41m★%s\033[34;47m [%s] %s \033[0m", - SHM->uinfo[currutmp->destuip].userid, my_ctime (&now), - (currutmp->sig == 2)? "重要消息廣播!(請Ctrl-U,l查看熱訊記錄)" - : "呼叫、呼叫,聽到請回答"); - move (0, 0); - clrtoeol (); - outs (buf); - refresh (); - } - else{ - unsigned char mode0 = currutmp->mode; - char c0 = currutmp->chatid[0]; - screenline_t *screen0 = calloc (t_lines, sizeof (screenline_t)); - + bell(); + bell(); + if (currutmp->msgcount) { + char buf[200]; + time_t now = time(0); + + sprintf(buf, "\033[33;41m★%s\033[34;47m [%s] %s \033[0m", + SHM->uinfo[currutmp->destuip].userid, my_ctime(&now), + (currutmp->sig == 2) ? "重要消息廣播!(請Ctrl-U,l查看熱訊記錄)" + : "呼叫、呼叫,聽到請回答"); + move(0, 0); + clrtoeol(); + outs(buf); + refresh(); + } else { + unsigned char mode0 = currutmp->mode; + char c0 = currutmp->chatid[0]; + screenline_t *screen0 = calloc(t_lines, sizeof(screenline_t)); + currutmp->mode = 0; currutmp->chatid[0] = 1; - memcpy (screen0, big_picture, t_lines * sizeof (screenline_t)); - talkreply (); + memcpy(screen0, big_picture, t_lines * sizeof(screenline_t)); + talkreply(); currutmp->mode = mode0; currutmp->chatid[0] = c0; - memcpy (big_picture, screen0, t_lines * sizeof (screenline_t)); - free (screen0); - redoscr (); + memcpy(big_picture, screen0, t_lines * sizeof(screenline_t)); + free(screen0); + redoscr(); } } void show_call_in(int save, int which) { - char buf[200]; - sprintf (buf, "\033[1;33;46m★%s\033[37;45m %s \033[m", - currutmp->msgs[which].userid, currutmp->msgs[which].last_call_in); - move (b_lines, 0); - clrtoeol (); - refresh (); - outmsg (buf); - - if (save){ - char genbuf[200]; - time_t now; - if (!fp_writelog){ - sethomefile (genbuf, cuser.userid, fn_writelog); - fp_writelog = fopen (genbuf, "a"); + char buf[200]; + sprintf(buf, "\033[1;33;46m★%s\033[37;45m %s \033[m", + currutmp->msgs[which].userid, currutmp->msgs[which].last_call_in); + move(b_lines, 0); + clrtoeol(); + refresh(); + outmsg(buf); + + if (save) { + char genbuf[200]; + time_t now; + if (!fp_writelog) { + sethomefile(genbuf, cuser.userid, fn_writelog); + fp_writelog = fopen(genbuf, "a"); } - if (fp_writelog){ - time (&now); - fprintf (fp_writelog, "%s \033[0m[%s]\n", buf, Cdatelite (&now)); + if (fp_writelog) { + time(&now); + fprintf(fp_writelog, "%s \033[0m[%s]\n", buf, Cdatelite(&now)); } } } -static int add_history_water(water_t *w, msgque_t *msg) +static int +add_history_water(water_t * w, msgque_t * msg) { - // mode: 1: all data(including userid, pid); - // 0: only last_call_in Ptt:先改回來 省不多 進階會有問題 - memcpy(&w->msg[w->top], msg, sizeof(msgque_t)); + //mode:1:all data(including userid, pid); +//0: only last_call_in Ptt:先改回來省不多 i 扑|有問題 + memcpy(&w->msg[w->top], msg, sizeof(msgque_t)); w->top++; w->top %= WATERMODE(WATER_OFO) ? 5 : MAX_REVIEW; - + if (w->count < MAX_REVIEW) w->count++; - + return w->count; } static int -add_history(msgque_t *msg) +add_history(msgque_t * msg) { - int i = 0, j, waterinit = 0; - water_t *tmp; - if( WATERMODE(WATER_ORIG) || WATERMODE(WATER_NEW) ) + int i = 0, j, waterinit = 0; + water_t *tmp; + if (WATERMODE(WATER_ORIG) || WATERMODE(WATER_NEW)) add_history_water(&water[0], msg); - if( WATERMODE(WATER_NEW) || WATERMODE(WATER_OFO) ){ - for(i = 0 ; i < 5 && swater[i] ; i++ ) - if( swater[i]->pid == msg->pid ) + if (WATERMODE(WATER_NEW) || WATERMODE(WATER_OFO)) { + for (i = 0; i < 5 && swater[i]; i++) + if (swater[i]->pid == msg->pid) break; - if( i == 5 ){ + if (i == 5) { waterinit = 1; i = 4; memset(swater[4], 0, sizeof(water_t)); - } - else if( !swater[i] ){ + } else if (!swater[i]) { water_usies = i + 1; swater[i] = &water[i + 1]; waterinit = 1; } tmp = swater[i]; - if( waterinit ){ + if (waterinit) { memcpy(swater[i]->userid, msg->userid, sizeof(swater[i]->userid)); swater[i]->pid = msg->pid; } - - if( !swater[i]->uin ) + if (!swater[i]->uin) swater[i]->uin = currutmp; - - for( j = i ; j > 0 ; j-- ) + + for (j = i; j > 0; j--) swater[j] = swater[j - 1]; swater[0] = tmp; add_history_water(swater[0], msg); } - - if(WATERMODE(WATER_ORIG) || WATERMODE(WATER_NEW) ){ - if( watermode > 0 && - (water_which == swater[0] || water_which == &water[0]) ){ + if (WATERMODE(WATER_ORIG) || WATERMODE(WATER_NEW)) { + if (watermode > 0 && + (water_which == swater[0] || water_which == &water[0])) { if (watermode < water_which->count) watermode++; t_display_new(); @@ -363,35 +362,34 @@ add_history(msgque_t *msg) } void -write_request (int sig) +write_request(int sig) { - int i; - - if( WATERMODE(WATER_OFO) ){ - /* sig = SIGUSR2 waterball come in - 0 flush to water[] (by my_write2()) - */ - if( sig != 0 ){ - if( wmofo == 0 ) /* 正在回水球 */ + int i; + + if (WATERMODE(WATER_OFO)) { + /* + * sig = SIGUSR2 waterball come in 0 flush to water[] (by + * my_write2()) + */ + if (sig != 0) { + if (wmofo == 0) /* 正在回水球 */ wmofo = 1; - bell (); + bell(); show_call_in(1, currutmp->msgcount - 1); - refresh (); + refresh(); } - - if( sig == 0 || /* 回水球的時候又有水球進來, 回完後一次寫回去 */ - wmofo == -1 ){ /* 不在回水球模式 */ - do{ + if (sig == 0 || /* 回水球的時候又有水球進來, 回完後一次寫回去 */ + wmofo == -1) { /* 不在回水球模式 */ + do { add_history(&currutmp->msgs[0]); - if( currutmp->msgcount-- ) + if (currutmp->msgcount--) for (i = 0; i < currutmp->msgcount; i++) currutmp->msgs[i] = currutmp->msgs[i + 1]; } while (currutmp->msgcount); currutmp->msgcount = 0; } - } - else{ + } else { if (currutmp->mode != 0 && currutmp->pager != 0 && cuser.userlevel != 0 && @@ -401,25 +399,24 @@ write_request (int sig) currutmp->mode != CHATING && currutmp->mode != PAGE && currutmp->mode != IDLE && - currutmp->mode != MAILALL && currutmp->mode != MONITOR){ - char c0 = currutmp->chatid[0]; - int currstat0 = currstat; - unsigned char mode0 = currutmp->mode; - + currutmp->mode != MAILALL && currutmp->mode != MONITOR) { + char c0 = currutmp->chatid[0]; + int currstat0 = currstat; + unsigned char mode0 = currutmp->mode; + currutmp->mode = 0; currutmp->chatid[0] = 2; currstat = XMODE; - - do{ - bell (); + + do { + bell(); show_call_in(1, 0); - igetch (); + igetch(); currutmp->msgcount--; - if (currutmp->msgcount >= MAX_MSGS){ + if (currutmp->msgcount >= MAX_MSGS) { /* this causes chaos... jochang */ - raise (SIGFPE); + raise(SIGFPE); } - add_history(&currutmp->msgs[0]); for (i = 0; i < currutmp->msgcount; i++) currutmp->msgs[i] = currutmp->msgs[i + 1]; @@ -428,271 +425,263 @@ write_request (int sig) currutmp->chatid[0] = c0; currutmp->mode = mode0; currstat = currstat0; - } - else{ - bell (); + } else { + bell(); show_call_in(1, 0); add_history(&currutmp->msgs[0]); - - refresh (); + + refresh(); currutmp->msgcount = 0; } } } static void -multi_user_check () +multi_user_check() { register userinfo_t *ui; - register pid_t pid; - char genbuf[3]; - - if (HAS_PERM (PERM_SYSOP)) + register pid_t pid; + char genbuf[3]; + + if (HAS_PERM(PERM_SYSOP)) return; /* don't check sysops */ - - if (cuser.userlevel){ - if (!(ui = (userinfo_t *) search_ulist (usernum))) - return; /* user isn't logged in */ - + + if (cuser.userlevel) { + if (!(ui = (userinfo_t *) search_ulist(usernum))) + return; /* user isn't logged in */ + pid = ui->pid; - if (!pid /*|| (kill(pid, 0) == -1) */ ) - return; /* stale entry in utmp file */ - - getdata (b_lines - 1, 0, "您想刪除其他重複的 login (Y/N)嗎?[Y] ", - genbuf, 3, LCECHO); - - if (genbuf[0] != 'n'){ + if (!pid /* || (kill(pid, 0) == -1) */ ) + return; /* stale entry in utmp file */ + + getdata(b_lines - 1, 0, "您想刪除其他重複的 login (Y/N)嗎?[Y] ", + genbuf, 3, LCECHO); + + if (genbuf[0] != 'n') { if (pid > 0) - kill (pid, SIGHUP); - log_usies ("KICK ", cuser.username); + kill(pid, SIGHUP); + log_usies("KICK ", cuser.username); + } else { + if (search_ulistn(usernum, 3) != NULL) + system_abort(); /* Goodbye(); */ } - else{ - if (search_ulistn(usernum, 3)!=NULL) - system_abort (); /* Goodbye(); */ - } - } - else{ + } else { /* allow multiple guest user */ - if (search_ulistn(usernum, 100)!=NULL){ - outs ("\n抱歉,目前已有太多 guest 在站上, 請用new註冊。\n"); - pressanykey (); - oflush (); - exit (1); + if (search_ulistn(usernum, 100) != NULL) { + outs("\n抱歉,目前已有太多 guest 在站上, 請用new註冊。\n"); + pressanykey(); + oflush(); + exit(1); } } } /* bad login */ -static char str_badlogin[] = "logins.bad"; +static char str_badlogin[] = "logins.bad"; static void -logattempt (char *uid, char type) +logattempt(char *uid, char type) { - char fname[40]; - int fd, len; - char genbuf[200]; - - sprintf (genbuf, "%c%-12s[%s] %s@%s\n", type, uid, - Cdate (&login_start_time), remoteusername, fromhost); - len = strlen (genbuf); - if ((fd = open (str_badlogin, O_WRONLY | O_CREAT | O_APPEND, 0644)) > 0){ - write (fd, genbuf, len); - close (fd); + char fname[40]; + int fd, len; + char genbuf[200]; + + sprintf(genbuf, "%c%-12s[%s] %s@%s\n", type, uid, + Cdate(&login_start_time), remoteusername, fromhost); + len = strlen(genbuf); + if ((fd = open(str_badlogin, O_WRONLY | O_CREAT | O_APPEND, 0644)) > 0) { + write(fd, genbuf, len); + close(fd); } - if (type == '-'){ - sprintf (genbuf, "[%s] %s\n", Cdate (&login_start_time), fromhost); - len = strlen (genbuf); - sethomefile (fname, uid, str_badlogin); - if ((fd = open (fname, O_WRONLY | O_CREAT | O_APPEND, 0644)) > 0){ - write (fd, genbuf, len); - close (fd); + if (type == '-') { + sprintf(genbuf, "[%s] %s\n", Cdate(&login_start_time), fromhost); + len = strlen(genbuf); + sethomefile(fname, uid, str_badlogin); + if ((fd = open(fname, O_WRONLY | O_CREAT | O_APPEND, 0644)) > 0) { + write(fd, genbuf, len); + close(fd); } } } static void -login_query () +login_query() { - char uid[IDLEN + 1], passbuf[PASSLEN]; - int attempts; - char genbuf[200]; + char uid[IDLEN + 1], passbuf[PASSLEN]; + int attempts; + char genbuf[200]; attach_SHM(); - resolve_garbage (); - now= time(0); + resolve_garbage(); + now = time(0); attempts = SHM->UTMPnumber; #ifdef DEBUG move(1, 0); prints("debugging mode\ncurrent pid: %d\n", getpid()); #else - show_file ("etc/Welcome", 1, -1, NO_RELOAD); + show_file("etc/Welcome", 1, -1, NO_RELOAD); #endif - output ("1", 1); - if (attempts >= MAX_ACTIVE){ - outs ("由於人數太多,請您稍後再來。\n"); - refresh (); - exit (1); + output("1", 1); + if (attempts >= MAX_ACTIVE) { + outs("由於人數太多,請您稍後再來。\n"); + refresh(); + exit(1); } - - /* hint */ - - attempts = 0; - while (1){ - if (attempts++ >= LOGINATTEMPTS){ - more ("etc/goodbye", NA); - pressanykey (); - exit (1); - } + /* hint */ + + attempts = 0; + while (1) { + if (attempts++ >= LOGINATTEMPTS) { + more("etc/goodbye", NA); + pressanykey(); + exit(1); + } #ifdef DEBUG - move(19, 0); - prints("current pid: %d ", getpid()); + move(19, 0); + prints("current pid: %d ", getpid()); #endif - getdata (20, 0, "請輸入代號,或以[guest]參觀,以[new]註冊:", - uid, sizeof(uid), DOECHO); - if (strcasecmp (uid, str_new) == 0){ + getdata(20, 0, "請輸入代號,或以[guest]參觀,以[new]註冊:", + uid, sizeof(uid), DOECHO); + if (strcasecmp(uid, str_new) == 0) { #ifdef LOGINASNEW - new_register (); - break; + new_register(); + break; #else - outs ("本系統目前無法以 new 註冊, 請用 guest 進入\n"); - continue; + outs("本系統目前無法以 new 註冊, 請用 guest 進入\n"); + continue; #endif - } - else if (uid[0] == '\0' || !dosearchuser (uid)){ - outs (err_uid); - } - else if (strcmp (uid, STR_GUEST)){ - getdata (21, 0, MSG_PASSWD, passbuf, sizeof(passbuf), NOECHO); - passbuf[8] = '\0'; - - if (!checkpasswd (cuser.passwd, passbuf) - /* || (HAS_PERM(PERM_SYSOP) && !use_shell_login_mode) */ ){ - logattempt (cuser.userid, '-'); - outs (ERR_PASSWD); - } - else{ - logattempt (cuser.userid, ' '); - if (strcasecmp ("SYSOP", cuser.userid) == 0) - cuser.userlevel = PERM_BASIC | PERM_CHAT | PERM_PAGE | - PERM_POST | PERM_LOGINOK | PERM_MAILLIMIT | - PERM_CLOAK | PERM_SEECLOAK | PERM_XEMPT | - PERM_DENYPOST | PERM_BM | PERM_ACCOUNTS | - PERM_CHATROOM | PERM_BOARD | PERM_SYSOP | PERM_BBSADM; - break; - } - } - else{ /* guest */ - cuser.userlevel = 0; - cuser.uflag = COLOR_FLAG | PAGER_FLAG | BRDSORT_FLAG | MOVIE_FLAG; - break; - } - } - multi_user_check (); - sethomepath (genbuf, cuser.userid); - mkdir (genbuf, 0755); + } else if (uid[0] == '\0' || !dosearchuser(uid)) { + outs(err_uid); + } else if (strcmp(uid, STR_GUEST)) { + getdata(21, 0, MSG_PASSWD, passbuf, sizeof(passbuf), NOECHO); + passbuf[8] = '\0'; + + if (!checkpasswd(cuser.passwd, passbuf) + /* || (HAS_PERM(PERM_SYSOP) && !use_shell_login_mode) */ ) { + logattempt(cuser.userid, '-'); + outs(ERR_PASSWD); + } else { + logattempt(cuser.userid, ' '); + if (strcasecmp("SYSOP", cuser.userid) == 0) + cuser.userlevel = PERM_BASIC | PERM_CHAT | PERM_PAGE | + PERM_POST | PERM_LOGINOK | PERM_MAILLIMIT | + PERM_CLOAK | PERM_SEECLOAK | PERM_XEMPT | + PERM_DENYPOST | PERM_BM | PERM_ACCOUNTS | + PERM_CHATROOM | PERM_BOARD | PERM_SYSOP | PERM_BBSADM; + break; + } + } else { /* guest */ + cuser.userlevel = 0; + cuser.uflag = COLOR_FLAG | PAGER_FLAG | BRDSORT_FLAG | MOVIE_FLAG; + break; + } + } + multi_user_check(); + sethomepath(genbuf, cuser.userid); + mkdir(genbuf, 0755); } void -add_distinct (char *fname, char *line) +add_distinct(char *fname, char *line) { - FILE *fp; - int n = 0; - - if ((fp = fopen (fname, "a+"))){ - char buffer[80]; - char tmpname[100]; - FILE *fptmp; - - strcpy (tmpname, fname); - strcat (tmpname, "_tmp"); - if (!(fptmp = fopen (tmpname, "w"))){ - fclose (fp); + FILE *fp; + int n = 0; + + if ((fp = fopen(fname, "a+"))) { + char buffer[80]; + char tmpname[100]; + FILE *fptmp; + + strcpy(tmpname, fname); + strcat(tmpname, "_tmp"); + if (!(fptmp = fopen(tmpname, "w"))) { + fclose(fp); return; } - rewind (fp); - while (fgets (buffer, 80, fp)){ - char *p = buffer + strlen (buffer) - 1; - + rewind(fp); + while (fgets(buffer, 80, fp)) { + char *p = buffer + strlen(buffer) - 1; + if (p[-1] == '\n' || p[-1] == '\r') p[-1] = 0; - if (!strcmp (buffer, line)) + if (!strcmp(buffer, line)) break; - sscanf (buffer + strlen (buffer) + 2, "%d", &n); - fprintf (fptmp, "%s%c#%d\n", buffer, 0, n); + sscanf(buffer + strlen(buffer) + 2, "%d", &n); + fprintf(fptmp, "%s%c#%d\n", buffer, 0, n); } - - if (feof (fp)) - fprintf (fptmp, "%s%c#1\n", line, 0); - else{ - sscanf (buffer + strlen (buffer) + 2, "%d", &n); - fprintf (fptmp, "%s%c#%d\n", buffer, 0, n + 1); - while (fgets (buffer, 80, fp)){ - sscanf (buffer + strlen (buffer) + 2, "%d", &n); - fprintf (fptmp, "%s%c#%d\n", buffer, 0, n); + + if (feof(fp)) + fprintf(fptmp, "%s%c#1\n", line, 0); + else { + sscanf(buffer + strlen(buffer) + 2, "%d", &n); + fprintf(fptmp, "%s%c#%d\n", buffer, 0, n + 1); + while (fgets(buffer, 80, fp)) { + sscanf(buffer + strlen(buffer) + 2, "%d", &n); + fprintf(fptmp, "%s%c#%d\n", buffer, 0, n); } } - fclose (fp); - fclose (fptmp); - unlink (fname); - rename (tmpname, fname); + fclose(fp); + fclose(fptmp); + unlink(fname); + rename(tmpname, fname); } } void -del_distinct (char *fname, char *line) +del_distinct(char *fname, char *line) { - FILE *fp; - int n = 0; - - if ((fp = fopen (fname, "r"))){ - char buffer[80]; - char tmpname[100]; - FILE *fptmp; - - strcpy (tmpname, fname); - strcat (tmpname, "_tmp"); - if (!(fptmp = fopen (tmpname, "w"))){ - fclose (fp); + FILE *fp; + int n = 0; + + if ((fp = fopen(fname, "r"))) { + char buffer[80]; + char tmpname[100]; + FILE *fptmp; + + strcpy(tmpname, fname); + strcat(tmpname, "_tmp"); + if (!(fptmp = fopen(tmpname, "w"))) { + fclose(fp); return; } - rewind (fp); - while (fgets (buffer, 80, fp)){ - char *p = buffer + strlen (buffer) - 1; - + rewind(fp); + while (fgets(buffer, 80, fp)) { + char *p = buffer + strlen(buffer) - 1; + if (p[-1] == '\n' || p[-1] == '\r') p[-1] = 0; - if (!strcmp (buffer, line)) + if (!strcmp(buffer, line)) break; - sscanf (buffer + strlen (buffer) + 2, "%d", &n); - fprintf (fptmp, "%s%c#%d\n", buffer, 0, n); + sscanf(buffer + strlen(buffer) + 2, "%d", &n); + fprintf(fptmp, "%s%c#%d\n", buffer, 0, n); } - - if (!feof (fp)) - while (fgets (buffer, 80, fp)){ - sscanf (buffer + strlen (buffer) + 2, "%d", &n); - fprintf (fptmp, "%s%c#%d\n", buffer, 0, n); + + if (!feof(fp)) + while (fgets(buffer, 80, fp)) { + sscanf(buffer + strlen(buffer) + 2, "%d", &n); + fprintf(fptmp, "%s%c#%d\n", buffer, 0, n); } - fclose (fp); - fclose (fptmp); - unlink (fname); - rename (tmpname, fname); + fclose(fp); + fclose(fptmp); + unlink(fname); + rename(tmpname, fname); } } #ifdef WHERE static int -where (char *from) +where(char *from) { - register int i = 0, count = 0, j; - - for (j = 0; j < SHM->top; j++){ - char *token = strtok (SHM->domain[j], "&"); - + register int i = 0, count = 0, j; + + for (j = 0; j < SHM->top; j++) { + char *token = strtok(SHM->domain[j], "&"); + i = 0; count = 0; - while (token){ - if (strstr (from, token)) + while (token) { + if (strstr(from, token)) count++; - token = strtok (NULL, "&"); + token = strtok(NULL, "&"); i++; } if (i == count) @@ -705,305 +694,302 @@ where (char *from) #endif static void -check_BM () +check_BM() { - int i; - boardheader_t *bhdr; - + int i; + boardheader_t *bhdr; + cuser.userlevel &= ~PERM_BM; - for (i = 0, bhdr = bcache; i < numboards && !is_BM (bhdr->BM); i++, bhdr++) - ; + for (i = 0, bhdr = bcache; i < numboards && !is_BM(bhdr->BM); i++, bhdr++); } static void -setup_utmp (int mode) +setup_utmp(int mode) { - userinfo_t uinfo; - memset (&uinfo, 0, sizeof (uinfo)); - uinfo.pid = currpid = getpid (); + userinfo_t uinfo; + memset(&uinfo, 0, sizeof(uinfo)); + uinfo.pid = currpid = getpid(); uinfo.uid = usernum; uinfo.mode = currstat = mode; - uinfo.mailalert = load_mailalert (cuser.userid); + uinfo.mailalert = load_mailalert(cuser.userid); if (!(cuser.numlogins % 20) && cuser.userlevel & PERM_BM) - check_BM (); /* Ptt 自動取下離職板主權力 */ - + check_BM(); /* Ptt 自動取下離職板主權力 */ + uinfo.userlevel = cuser.userlevel; uinfo.sex = cuser.sex % 8; - uinfo.lastact = time (NULL); - strcpy (uinfo.userid, cuser.userid); - strcpy (uinfo.realname, cuser.realname); - strcpy (uinfo.username, cuser.username); - strncpy (uinfo.from, fromhost, 23); + uinfo.lastact = time(NULL); + strcpy(uinfo.userid, cuser.userid); + strcpy(uinfo.realname, cuser.realname); + strcpy(uinfo.username, cuser.username); + strncpy(uinfo.from, fromhost, 23); uinfo.five_win = cuser.five_win; uinfo.five_lose = cuser.five_lose; uinfo.five_tie = cuser.five_tie; uinfo.invisible = cuser.invisible % 2; - uinfo.pager = cuser.pager%5; + uinfo.pager = cuser.pager % 5; memcpy(uinfo.mind, cuser.mind, 4); #ifdef WHERE - uinfo.from_alias = where (fromhost); + uinfo.from_alias = where(fromhost); #endif #ifndef FAST_LOGIN - setuserfile (buf, "remoteuser"); - - strcpy (remotebuf, fromhost); - strcat (remotebuf, ctime (&now)); - remotebuf[strlen (remotebuf) - 1] = 0; - add_distinct (buf, remotebuf); + setuserfile(buf, "remoteuser"); + + strcpy(remotebuf, fromhost); + strcat(remotebuf, ctime(&now)); + remotebuf[strlen(remotebuf) - 1] = 0; + add_distinct(buf, remotebuf); #endif if (enter_uflag & CLOAK_FLAG) uinfo.invisible = YEA; - getnewutmpent (&uinfo); + getnewutmpent(&uinfo); #ifndef _BBS_UTIL_C_ - friend_load (); + friend_load(); #endif } static void -user_login () +user_login() { - char ans[4], i; - char genbuf[200]; - struct tm *ptime, *tmp; - time_t now; - int a; + char ans[4], i; + char genbuf[200]; + struct tm *ptime, *tmp; + time_t now; + int a; /*** Heat:廣告詞 char *ADV[] = { "7/17 @LIVE 亂彈, 何欣穗 的 入場卷要送給 ptt 的愛用者!", "欲知詳情請看 PttAct 板!!", }; ***/ - - log_usies ("ENTER", fromhost); - setproctitle ("%s: %s", margs, cuser.userid); - resolve_fcache (); - resolve_boards (); - memset( &water[0],0,sizeof(water_t) * 6); + + log_usies("ENTER", fromhost); + setproctitle("%s: %s", margs, cuser.userid); + resolve_fcache(); + resolve_boards(); + memset(&water[0], 0, sizeof(water_t) * 6); strcpy(water[0].userid, " 全部 "); /* 初始化 uinfo、flag、mode */ - setup_utmp (LOGIN); - mysrand (); /* 初始化: random number 增加user跟時間的差異 */ + setup_utmp(LOGIN); + mysrand(); /* 初始化: random number 增加user跟時間的差異 */ currmode = MODE_STARTED; enter_uflag = cuser.uflag; - + /* get local time */ - time (&now); - ptime = localtime (&now); - tmp = localtime (&cuser.lastlogin); - if ((a = SHM->UTMPnumber) > SHM->max_user){ + time(&now); + ptime = localtime(&now); + tmp = localtime(&cuser.lastlogin); + if ((a = SHM->UTMPnumber) > SHM->max_user) { SHM->max_user = a; SHM->max_time = now; } - init_brdbuf(); - brc_initial (DEFAULT_BOARD); - set_board (); + init_brdbuf(); + brc_initial(DEFAULT_BOARD); + set_board(); /* 畫面處理開始 */ - if (!(HAS_PERM (PERM_SYSOP) && HAS_PERM (PERM_DENYPOST)) && !currutmp->invisible ) - do_aloha ("<<上站通知>> -- 我來啦!"); - if (ptime->tm_mday == cuser.day && ptime->tm_mon + 1 == cuser.month){ - more ("etc/Welcome_birth", NA); + if (!(HAS_PERM(PERM_SYSOP) && HAS_PERM(PERM_DENYPOST)) && !currutmp->invisible) + do_aloha("<<上站通知>> -- 我來啦!"); + if (ptime->tm_mday == cuser.day && ptime->tm_mon + 1 == cuser.month) { + more("etc/Welcome_birth", NA); currutmp->birth = 1; - } - else{ + } else { #ifdef MULTI_WELCOME_LOGIN - char buf[80]; - int nScreens; - for( nScreens = 0 ; nScreens < 10 ; ++nScreens ){ + char buf[80]; + int nScreens; + for (nScreens = 0; nScreens < 10; ++nScreens) { sprintf(buf, "etc/Welcome_login.%d", nScreens); - if( access(buf, 0) < 0 ) + if (access(buf, 0) < 0) break; } printf("%d\n", nScreens); - if( nScreens == 0 ){ // multi screen error? - more ("etc/Welcome_login", NA); - } - else{ + if (nScreens == 0) { + //multi screen error ? + more("etc/Welcome_login", NA); + } else { sprintf(buf, "etc/Welcome_login.%d", (int)login_start_time % nScreens); - more (buf, NA); + more(buf, NA); } #else - more ("etc/Welcome_login", NA); + more("etc/Welcome_login", NA); #endif //pressanykey(); //more("etc/CSIE_Week", NA); currutmp->birth = 0; } - - if (cuser.userlevel){/* not guest */ - move (t_lines - 4, 0); - prints ("\033[m 歡迎您第 \033[1;33m%d\033[0;37m 度拜訪本站," - "上次您是從 \033[1;33m%s\033[0;37m 連往本站,\n" - " 我記得那天是 \033[1;33m%s\033[0;37m。\n", - ++cuser.numlogins, cuser.lasthost, Cdate (&cuser.lastlogin)); - pressanykey (); - - if (currutmp->birth && tmp->tm_mday != ptime->tm_mday){ - more ("etc/birth.post", YEA); - brc_initial ("WhoAmI"); - set_board (); - do_post (); + + if (cuser.userlevel) { /* not guest */ + move(t_lines - 4, 0); + prints("\033[m 歡迎您第 \033[1;33m%d\033[0;37m 度拜訪本站," + "上次您是從 \033[1;33m%s\033[0;37m 連往本站,\n" + " 我記得那天是 \033[1;33m%s\033[0;37m。\n", + ++cuser.numlogins, cuser.lasthost, Cdate(&cuser.lastlogin)); + pressanykey(); + + if (currutmp->birth && tmp->tm_mday != ptime->tm_mday) { + more("etc/birth.post", YEA); + brc_initial("WhoAmI"); + set_board(); + do_post(); } - setuserfile (genbuf, str_badlogin); - if (more (genbuf, NA) != -1){ - getdata (b_lines - 1, 0, "您要刪除以上錯誤嘗試的記錄嗎(Y/N)?[Y]", - ans, 3, LCECHO); + setuserfile(genbuf, str_badlogin); + if (more(genbuf, NA) != -1) { + getdata(b_lines - 1, 0, "您要刪除以上錯誤嘗試的記錄嗎(Y/N)?[Y]", + ans, 3, LCECHO); if (*ans != 'n') - unlink (genbuf); + unlink(genbuf); } - check_register (); - strncpy (cuser.lasthost, fromhost, 16); + check_register(); + strncpy(cuser.lasthost, fromhost, 16); cuser.lasthost[15] = '\0'; - restore_backup (); - } - else if (!strcmp (cuser.userid, STR_GUEST)){ - char *nick[13] = { + restore_backup(); + } else if (!strcmp(cuser.userid, STR_GUEST)) { + char *nick[13] = { "椰子", "貝殼", "內衣", "寶特瓶", "翻車魚", "樹葉", "浮萍", "鞋子", "潛水艇", "魔王", "鐵罐", "考卷", "大美女" }; - char *name[13] = { + char *name[13] = { "大王椰子", "鸚鵡螺", "比基尼", "可口可樂", "仰泳的魚", "憶", "高岡屋", "AIR Jordon", "紅色十月號", "批踢踢", "SASAYA椰奶", "鴨蛋", "布魯克鱈魚香絲" }; - char *addr[13] = { + char *addr[13] = { "天堂樂園", "大海", "綠島小夜曲", "美國", "綠色珊瑚礁", "遠方", "原本海", "NIKE", "蘇聯", "男八618室", "愛之味", "天上", "藍色珊瑚礁" }; i = login_start_time % 13; - sprintf (cuser.username, "海邊漂來的%s", nick[(int) i]); - sprintf (currutmp->username, cuser.username); - sprintf (cuser.realname, name[(int) i]); - sprintf (currutmp->realname, cuser.realname); - sprintf (cuser.address, addr[(int) i]); + sprintf(cuser.username, "海邊漂來的%s", nick[(int)i]); + sprintf(currutmp->username, cuser.username); + sprintf(cuser.realname, name[(int)i]); + sprintf(currutmp->realname, cuser.realname); + sprintf(cuser.address, addr[(int)i]); cuser.sex = i % 8; currutmp->pager = 2; - pressanykey (); - } - else - pressanykey (); - - if (!PERM_HIDE (currutmp)) + pressanykey(); + } else + pressanykey(); + + if (!PERM_HIDE(currutmp)) cuser.lastlogin = login_start_time; - - passwd_update (usernum, &cuser); - + + passwd_update(usernum, &cuser); + for (i = 0; i < NUMVIEWFILE; i++) if ((cuser.loginview >> i) & 1) - more (loginview_file[(int) i][0], YEA); + more(loginview_file[(int)i][0], YEA); } static void -do_aloha (char *hello) +do_aloha(char *hello) { - FILE *fp; - char userid[80]; - char genbuf[200]; - - setuserfile (genbuf, "aloha"); - if ((fp = fopen (genbuf, "r"))){ - sprintf (genbuf, hello); - while (fgets (userid, 80, fp)){ - userinfo_t *uentp; - int tuid; - - if ((tuid = searchuser (userid)) && tuid != usernum && - (uentp = (userinfo_t *) search_ulist (tuid)) && - isvisible(uentp, currutmp)){ - my_write (uentp->pid, genbuf, uentp->userid, 2, NULL); + FILE *fp; + char userid[80]; + char genbuf[200]; + + setuserfile(genbuf, "aloha"); + if ((fp = fopen(genbuf, "r"))) { + sprintf(genbuf, hello); + while (fgets(userid, 80, fp)) { + userinfo_t *uentp; + int tuid; + + if ((tuid = searchuser(userid)) && tuid != usernum && + (uentp = (userinfo_t *) search_ulist(tuid)) && + isvisible(uentp, currutmp)) { + my_write(uentp->pid, genbuf, uentp->userid, 2, NULL); } } - fclose (fp); + fclose(fp); } } static void -do_term_init () +do_term_init() { - term_init (); - initscr (); + term_init(); + initscr(); } static void -start_client () +start_client() { #ifdef CPULIMIT - struct rlimit rml; + struct rlimit rml; rml.rlim_cur = CPULIMIT * 60; rml.rlim_max = CPULIMIT * 60; setrlimit(RLIMIT_CPU, &rml); #endif - + /* system init */ - nice (2); /* Ptt: lower priority */ - login_start_time = time (0); + nice(2); /* Ptt: lower priority */ + login_start_time = time(0); currmode = 0; - - signal (SIGHUP, abort_bbs); - signal (SIGTERM, abort_bbs); - signal (SIGPIPE, abort_bbs); - - signal (SIGINT, abort_bbs_debug); - signal (SIGQUIT, abort_bbs_debug); - signal (SIGILL, abort_bbs_debug); - signal (SIGABRT, abort_bbs_debug); - signal (SIGFPE, abort_bbs_debug); - signal (SIGBUS, abort_bbs_debug); - signal (SIGSEGV, abort_bbs_debug); - - signal_restart (SIGUSR1, talk_request); - signal_restart (SIGUSR2, write_request); - - dup2 (0, 1); + + signal(SIGHUP, abort_bbs); + signal(SIGTERM, abort_bbs); + signal(SIGPIPE, abort_bbs); + + signal(SIGINT, abort_bbs_debug); + signal(SIGQUIT, abort_bbs_debug); + signal(SIGILL, abort_bbs_debug); + signal(SIGABRT, abort_bbs_debug); + signal(SIGFPE, abort_bbs_debug); + signal(SIGBUS, abort_bbs_debug); + signal(SIGSEGV, abort_bbs_debug); + + signal_restart(SIGUSR1, talk_request); + signal_restart(SIGUSR2, write_request); + + dup2(0, 1); /* initialize passwd semaphores */ - if( passwd_init() ) - exit (1); - - do_term_init (); - signal (SIGALRM, abort_bbs); - alarm (600); - login_query (); /* Ptt 加上login time out */ - user_login (); - m_init (); - - if (now - SHM->close_vote_time > 86400) // 改為一天一次 - { - b_closepolls (); - SHM->close_vote_time = now; - } + if (passwd_init()) + exit(1); + + do_term_init(); + signal(SIGALRM, abort_bbs); + alarm(600); + login_query(); /* Ptt 加上login time out */ + user_login(); + m_init(); + + if (now - SHM->close_vote_time > 86400) + //改為一天一次 + { + b_closepolls(); + SHM->close_vote_time = now; + } if (!(cuser.uflag & COLOR_FLAG)) showansi = 0; - signal (SIGALRM, SIG_IGN); - if (chkmailbox ()) - m_read (); - - domenu (MMENU, "主功\能表", (currutmp->mailalert ? 'M' : 'C'), cmdlist); + signal(SIGALRM, SIG_IGN); + if (chkmailbox()) + m_read(); + + domenu(MMENU, "主功\能表", (currutmp->mailalert ? 'M' : 'C'), cmdlist); } /* FSA (finite state automata) for telnet protocol */ static void -telnet_init () +telnet_init() { - static char svr[] = { + static char svr[] = { IAC, DO, TELOPT_TTYPE, IAC, SB, TELOPT_TTYPE, TELQUAL_SEND, IAC, SE, IAC, WILL, TELOPT_ECHO, IAC, WILL, TELOPT_SGA }; - char *cmd; - int n, len, rset; - struct timeval to; - char buf[64]; - for (n = 0, cmd = svr; n < 4; n++){ + char *cmd; + int n, len, rset; + struct timeval to; + char buf[64]; + for (n = 0, cmd = svr; n < 4; n++) { len = (n == 1 ? 6 : 3); - write (0, cmd, len); + write(0, cmd, len); cmd += len; to.tv_sec = 3; to.tv_usec = 0; - rset=1; + rset = 1; if (select(1, (fd_set *) & rset, NULL, NULL, &to) > 0) - recv(0, buf, sizeof (buf),0); + recv(0, buf, sizeof(buf), 0); } } @@ -1013,7 +999,7 @@ telnet_init () * 1413 protocols. It queries an RFC 931 etc. compatible daemon on a remote * host to look up the owner of a connection. The information should not be * used for authentication purposes. This routine intercepts alarm signals. - * + * * Author: Wietse Venema, Eindhoven University of Technology, The Netherlands. */ @@ -1025,140 +1011,141 @@ telnet_init () #if 0 /* timeout - handle timeouts */ static void -timeout (int sig) +timeout(int sig) { - longjmp (byebye, sig); + longjmp(byebye, sig); } #endif static void -getremotename (struct sockaddr_in *from, char *rhost, char *rname) +getremotename(struct sockaddr_in * from, char *rhost, char *rname) { /* get remote host name */ - + #ifdef FAST_LOGIN - strcpy (rhost, (char *) inet_ntoa (from->sin_addr)); + strcpy(rhost, (char *)inet_ntoa(from->sin_addr)); #else struct sockaddr_in our_sin; struct sockaddr_in rmt_sin; - unsigned rmt_port, rmt_pt; - unsigned our_port, our_pt; - FILE *fp; - char buffer[512], user[80], *cp; - int s; + unsigned rmt_port, rmt_pt; + unsigned our_port, our_pt; + FILE *fp; + char buffer[512], user[80], *cp; + int s; static struct hostent *hp; - - + + hp = NULL; - if (setjmp (byebye) == 0){ - signal (SIGALRM, timeout); - alarm (3); - hp = gethostbyaddr ((char *) &from->sin_addr, sizeof (struct in_addr), - from->sin_family); - alarm (0); + if (setjmp(byebye) == 0) { + signal(SIGALRM, timeout); + alarm(3); + hp = gethostbyaddr((char *)&from->sin_addr, sizeof(struct in_addr), + from->sin_family); + alarm(0); } - strcpy (rhost, hp ? hp->h_name : (char *) inet_ntoa (from->sin_addr)); - -/* - * Use one unbuffered stdio stream for writing to and for reading from the - * RFC931 etc. server. This is done because of a bug in the SunOS 4.1.x - * stdio library. The bug may live in other stdio implementations, too. - * When we use a single, buffered, bidirectional stdio stream ("r+" or "w+" - * mode) we read our own output. Such behaviour would make sense with - * resources that support random-access operations, but not with sockets. - */ + strcpy(rhost, hp ? hp->h_name : (char *)inet_ntoa(from->sin_addr)); + + /* + * Use one unbuffered stdio stream for writing to and for reading from + * the RFC931 etc. server. This is done because of a bug in the SunOS + * 4.1.x stdio library. The bug may live in other stdio implementations, + * too. When we use a single, buffered, bidirectional stdio stream ("r+" + * or "w+" mode) we read our own output. Such behaviour would make sense + * with resources that support random-access operations, but not with + * sockets. + */ - s = sizeof (our_sin); - if (getsockname (0, (struct sockaddr *) &our_sin, &s) < 0) + s = sizeof(our_sin); + if (getsockname(0, (struct sockaddr *) & our_sin, &s) < 0) return; - - if ((s = socket (AF_INET, SOCK_STREAM, 0)) < 0) + + if ((s = socket(AF_INET, SOCK_STREAM, 0)) < 0) return; - - if (!(fp = fdopen (s, "r+"))){ - close (s); + + if (!(fp = fdopen(s, "r+"))) { + close(s); return; } /* Set up a timer so we won't get stuck while waiting for the server. */ - if (setjmp (byebye) == 0){ - signal (SIGALRM, timeout); - alarm (RFC931_TIMEOUT); - -/* - * Bind the local and remote ends of the query socket to the same IP - * addresses as the connection under investigation. We go through all - * this trouble because the local or remote system might have more than - * one network address. The RFC931 etc. client sends only port numbers; - * the server takes the IP addresses from the query socket. - */ - our_pt = ntohs (our_sin.sin_port); - our_sin.sin_port = htons (ANY_PORT); - - rmt_sin = *from; - rmt_pt = ntohs (rmt_sin.sin_port); - rmt_sin.sin_port = htons (RFC931_PORT); - - setbuf (fp, (char *) 0); - s = fileno (fp); - - if (bind (s, (struct sockaddr *) &our_sin, sizeof (our_sin)) >= 0 && - connect (s, (struct sockaddr *) &rmt_sin, sizeof (rmt_sin)) >= 0){ -/* - * Send query to server. Neglect the risk that a 13-byte write would - * have to be fragmented by the local system and cause trouble with - * buggy System V stdio libraries. - */ - fprintf (fp, "%u,%u\r\n", rmt_pt, our_pt); - fflush (fp); -/* - * Read response from server. Use fgets()/sscanf() so we can work - * around System V stdio libraries that incorrectly assume EOF when a - * read from a socket returns less than requested. - */ - if (fgets (buffer, sizeof (buffer), fp) && !ferror (fp) - && !feof (fp) - && sscanf (buffer, "%u , %u : USERID :%*[^:]:%79s", &rmt_port, - &our_port, user) == 3 && rmt_pt == rmt_port - && our_pt == our_port){ + if (setjmp(byebye) == 0) { + signal(SIGALRM, timeout); + alarm(RFC931_TIMEOUT); + + /* + * Bind the local and remote ends of the query socket to the same IP + * addresses as the connection under investigation. We go through all + * this trouble because the local or remote system might have more + * than one network address. The RFC931 etc. client sends only port + * numbers; the server takes the IP addresses from the query socket. + */ + our_pt = ntohs(our_sin.sin_port); + our_sin.sin_port = htons(ANY_PORT); -/* - * Strip trailing carriage return. It is part of the protocol, not - * part of the data. - */ - if ((cp = (char *) strchr (user, '\r'))) + rmt_sin = *from; + rmt_pt = ntohs(rmt_sin.sin_port); + rmt_sin.sin_port = htons(RFC931_PORT); + + setbuf(fp, (char *)0); + s = fileno(fp); + + if (bind(s, (struct sockaddr *) & our_sin, sizeof(our_sin)) >= 0 && + connect(s, (struct sockaddr *) & rmt_sin, sizeof(rmt_sin)) >= 0) { + /* + * Send query to server. Neglect the risk that a 13-byte write + * would have to be fragmented by the local system and cause + * trouble with buggy System V stdio libraries. + */ + fprintf(fp, "%u,%u\r\n", rmt_pt, our_pt); + fflush(fp); + /* + * Read response from server. Use fgets()/sscanf() so we can work + * around System V stdio libraries that incorrectly assume EOF + * when a read from a socket returns less than requested. + */ + if (fgets(buffer, sizeof(buffer), fp) && !ferror(fp) + && !feof(fp) + && sscanf(buffer, "%u , %u : USERID :%*[^:]:%79s", &rmt_port, + &our_port, user) == 3 && rmt_pt == rmt_port + && our_pt == our_port) { + + /* + * Strip trailing carriage return. It is part of the + * protocol, not part of the data. + */ + if ((cp = (char *)strchr(user, '\r'))) *cp = 0; - strcpy (rname, user); + strcpy(rname, user); } } - alarm (0); + alarm(0); } - fclose (fp); + fclose(fp); #endif } static int -bind_port (int port) +bind_port(int port) { - int sock, on; - - sock = socket (AF_INET, SOCK_STREAM, IPPROTO_TCP); - + int sock, on; + + sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); + on = 1; - setsockopt (sock, SOL_SOCKET, SO_REUSEADDR, (char *) &on, sizeof (on)); - setsockopt (sock, SOL_SOCKET, SO_KEEPALIVE, (char *) &on, sizeof (on)); - + setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (char *)&on, sizeof(on)); + setsockopt(sock, SOL_SOCKET, SO_KEEPALIVE, (char *)&on, sizeof(on)); + on = 0; - setsockopt (sock, SOL_SOCKET, SO_LINGER, (char *) &on, sizeof (on)); - - xsin.sin_port = htons (port); - if (bind (sock, (struct sockaddr *) &xsin, sizeof xsin) < 0){ - syslog (LOG_INFO, "bbsd bind_port can't bind to %d", port); - exit (1); + setsockopt(sock, SOL_SOCKET, SO_LINGER, (char *)&on, sizeof(on)); + + xsin.sin_port = htons(port); + if (bind(sock, (struct sockaddr *) & xsin, sizeof xsin) < 0) { + syslog(LOG_INFO, "bbsd bind_port can't bind to %d", port); + exit(1); } - if (listen (sock, SOCKET_QLEN) < 0){ - syslog (LOG_INFO, "bbsd bind_port can't listen to %d", port); - exit (1); + if (listen(sock, SOCKET_QLEN) < 0) { + syslog(LOG_INFO, "bbsd bind_port can't listen to %d", port); + exit(1); } return sock; } @@ -1167,136 +1154,132 @@ bind_port (int port) /*******************************************************/ -static void shell_login (int argc, char *argv[], char *envp[]); -static void daemon_login (int argc, char *argv[], char *envp[]); -static int check_ban_and_load (int fd); +static void shell_login(int argc, char *argv[], char *envp[]); +static void daemon_login(int argc, char *argv[], char *envp[]); +static int check_ban_and_load(int fd); int -main (int argc, char *argv[], char *envp[]) +main(int argc, char *argv[], char *envp[]) { start_time = time(NULL); /* avoid SIGPIPE */ - signal (SIGPIPE, SIG_IGN); - + signal(SIGPIPE, SIG_IGN); + /* avoid erroneous signal from other mbbsd */ - signal (SIGUSR1, SIG_IGN); - signal (SIGUSR2, SIG_IGN); - + signal(SIGUSR1, SIG_IGN); + signal(SIGUSR2, SIG_IGN); + /* check if invoked as "bbs" */ if (argc == 3) - shell_login (argc, argv, envp); + shell_login(argc, argv, envp); else - daemon_login (argc, argv, envp); - + daemon_login(argc, argv, envp); + return 0; } static void -shell_login (int argc, char *argv[], char *envp[]) +shell_login(int argc, char *argv[], char *envp[]) { - + /* Give up root privileges: no way back from here */ - setgid (BBSGID); - setuid (BBSUID); - chdir (BBSHOME); - - + setgid(BBSGID); + setuid(BBSUID); + chdir(BBSHOME); + + use_shell_login_mode = 1; - initsetproctitle (argc, argv, envp); - - /* copy fromindent: Standard input:1138: Error:Unexpected end of file - the original "bbs" */ - if (argc > 1){ - strcpy (fromhost, argv[1]); + initsetproctitle(argc, argv, envp); + + /* + * copy fromindent: Standard input:1138: Error:Unexpected end of file the + * original "bbs" + */ + if (argc > 1) { + strcpy(fromhost, argv[1]); if (argc > 3) - strcpy (remoteusername, argv[3]); + strcpy(remoteusername, argv[3]); } - - close (2); + close(2); /* don't close fd 1, at least init_tty need it */ - - init_tty (); - if (check_ban_and_load (0)){ - exit (0); + + init_tty(); + if (check_ban_and_load(0)) { + exit(0); } - start_client (); + start_client(); } static void -daemon_login (int argc, char *argv[], char *envp[]) +daemon_login(int argc, char *argv[], char *envp[]) { - int msock, csock; /* socket for Master and Child */ - FILE *fp; - int listen_port = 23; - int len_of_sock_addr; - char buf[256]; - + int msock, csock; /* socket for Master and Child */ + FILE *fp; + int listen_port = 23; + int len_of_sock_addr; + char buf[256]; + /* setup standalone */ start_daemon(); - + signal_restart(SIGCHLD, reapchild); - + /* choose port */ - if(argc == 1) + if (argc == 1) listen_port = 3006; - else if(argc >= 2) + else if (argc >= 2) listen_port = atoi(argv[1]); - sprintf(margs, "%s %d ", argv[0],listen_port); + sprintf(margs, "%s %d ", argv[0], listen_port); /* port binding */ xsin.sin_family = AF_INET; msock = bind_port(listen_port); - if(msock<0) { + if (msock < 0) { syslog(LOG_INFO, "mbbsd bind_port failed.\n"); exit(1); } - - initsetproctitle(argc, argv, envp); setproctitle("%s: listening ", margs); - + /* Give up root privileges: no way back from here */ setgid(BBSGID); setuid(BBSUID); chdir(BBSHOME); - + sprintf(buf, "run/mbbsd.%d.pid", listen_port); - if((fp = fopen(buf, "w"))) { + if ((fp = fopen(buf, "w"))) { fprintf(fp, "%d\n", getpid()); fclose(fp); } - /* main loop */ - for(;;) { + for (;;) { len_of_sock_addr = sizeof(xsin); - csock = accept(msock, (struct sockaddr *)&xsin, (socklen_t *)&len_of_sock_addr); + csock = accept(msock, (struct sockaddr *) & xsin, (socklen_t *) & len_of_sock_addr); - if(csock < 0) { - if(errno!=EINTR) sleep(1); + if (csock < 0) { + if (errno != EINTR) + sleep(1); continue; } - - if(check_ban_and_load(csock)) - { + if (check_ban_and_load(csock)) { close(csock); continue; } - #ifdef NO_FORK break; #else - if(fork()==0) + if (fork() == 0) break; else close(csock); #endif - } + } /* here is only child running */ - + setproctitle("%s: ...login wait... ", margs); close(msock); dup2(csock, 0); @@ -1309,35 +1292,34 @@ daemon_login (int argc, char *argv[], char *envp[]) close(1); } -/* check if we're banning login and if the load is too high. - if login is permitted, return 0; - else return -1; - approriate message is output to fd. -*/ -static int check_ban_and_load(int fd) +/* + * check if we're banning login and if the load is too high. if login is + * permitted, return 0; else return -1; approriate message is output to fd. + */ +static int +check_ban_and_load(int fd) { - FILE *fp; - static char buf[256]; - static time_t chkload_time = 0; - static int overload = 0; /* overload or banned, update every 1 sec */ - static int banned = 0; - - if((time(0) - chkload_time) > 1) { + FILE *fp; + static char buf[256]; + static time_t chkload_time = 0; + static int overload = 0; /* overload or banned, update every 1 + * sec */ + static int banned = 0; + + if ((time(0) - chkload_time) > 1) { overload = chkload(buf); - banned = !access(BBSHOME "/BAN",R_OK) && + banned = !access(BBSHOME "/BAN", R_OK) && (strcmp(fromhost, "localhost") != 0); chkload_time = time(0); } - write(fd, buf, strlen(buf)); - if(banned && (fp = fopen(BBSHOME "/BAN", "r"))) { - while(fgets(buf, 256, fp)) + if (banned && (fp = fopen(BBSHOME "/BAN", "r"))) { + while (fgets(buf, 256, fp)) write(fd, buf, strlen(buf)); fclose(fp); } - - if(banned || overload) + if (banned || overload) return -1; #ifdef INSCREEN diff --git a/pttbbs/mbbsd/menu.c b/pttbbs/mbbsd/menu.c index d06481b0..9379c28f 100644 --- a/pttbbs/mbbsd/menu.c +++ b/pttbbs/mbbsd/menu.c @@ -1,83 +1,86 @@ -/* $Id: menu.c,v 1.12 2002/06/26 09:49:37 ptt Exp $ */ +/* $Id: menu.c,v 1.13 2002/07/05 17:10:27 in2 Exp $ */ #include "bbs.h" /* help & menu processring */ -static int refscreen = NA; -extern char *boardprefix; +static int refscreen = NA; +extern char *boardprefix; extern struct utmpfile_t *utmpshm; -int egetch() { - int rval; - - while(1) { - rval = igetkey(); - if(talkrequest) { - talkreply(); - refscreen = YEA; - return rval; - } - if(rval != Ctrl('L')) - return rval; - redoscr(); +int +egetch() +{ + int rval; + + while (1) { + rval = igetkey(); + if (talkrequest) { + talkreply(); + refscreen = YEA; + return rval; + } + if (rval != Ctrl('L')) + return rval; + redoscr(); } } extern userec_t cuser; -extern char *fn_board; -extern char board_hidden_status; +extern char *fn_board; +extern char board_hidden_status; -void showtitle(char *title, char *mid) { - char buf[40], numreg[50]; - int nreg, spc = 0, pad, bid; +void +showtitle(char *title, char *mid) +{ + char buf[40], numreg[50]; + int nreg, spc = 0, pad, bid; boardheader_t bh; - static char lastboard[16] = {0}; + static char lastboard[16] = {0}; spc = strlen(mid); - if(title[0] == 0) - title++; + if (title[0] == 0) + title++; #ifdef DEBUG - else{ + else { sprintf(numreg, "\033[41;5m current pid: %6d " TITLE_COLOR, getpid()); mid = numreg; spc = 22; } #else - else if(currutmp->mailalert) { - mid = "\033[41;5m 郵差來按鈴囉 " TITLE_COLOR; - spc = 22; - } else if(HAS_PERM(PERM_SYSOP) && (nreg = dashs(fn_register)/163) > 10) { + else if (currutmp->mailalert) { + mid = "\033[41;5m 郵差來按鈴囉 " TITLE_COLOR; + spc = 22; + } else if (HAS_PERM(PERM_SYSOP) && (nreg = dashs(fn_register) / 163) > 10) { sprintf(numreg, "\033[41;5m 有%03d/%03d未審核 " TITLE_COLOR, nreg, (int)dashs("register.new.tmp") / 163); - mid = numreg; - spc = 22; + mid = numreg; + spc = 22; } #endif spc = 66 - strlen(title) - spc - strlen(currboard); - if(spc < 0) - spc = 0; + if (spc < 0) + spc = 0; pad = 1 - (spc & 1); memset(buf, ' ', spc >>= 1); buf[spc] = '\0'; - + clear(); prints(TITLE_COLOR "【%s】%s\033[33m%s%s%s\033[3%s《", - title, buf, mid, buf, " " + pad, - currmode & MODE_SELECT ? "6m系列" : currmode & MODE_ETC ? "5m其他" : - currmode & MODE_DIGEST ? "2m文摘" : "7m看板"); + title, buf, mid, buf, " " + pad, + currmode & MODE_SELECT ? "6m系列" : currmode & MODE_ETC ? "5m其他" : + currmode & MODE_DIGEST ? "2m文摘" : "7m看板"); - if( strcmp(currboard, lastboard) ){ /* change board */ - if( currboard[0] != 0 && + if (strcmp(currboard, lastboard)) { /* change board */ + if (currboard[0] != 0 && (bid = getbnum(currboard)) > 0 && - (get_record(fn_board, &bh, sizeof(bh), bid) != -1) ){ + (get_record(fn_board, &bh, sizeof(bh), bid) != -1)) { board_hidden_status = ((bh.brdattr & BRD_HIDE) && (bh.brdattr & BRD_POSTMASK)); strncpy(lastboard, currboard, sizeof(lastboard)); } } - - if( board_hidden_status ) + if (board_hidden_status) prints("\033[32m%s", currboard); else prints("%s", currboard); @@ -89,91 +92,99 @@ void showtitle(char *title, char *mid) { #define FILMROW 11 static unsigned char menu_row = 12; static unsigned char menu_column = 20; -static char mystatus[160]; +static char mystatus[160]; -static int u_movie() { +static int +u_movie() +{ cuser.uflag ^= MOVIE_FLAG; return 0; } -void movie(int i) { - static short history[MAX_HISTORY]; - static char myweek[] = "天一二三四五六"; - const char *msgs[] = {"關閉", "打開", "拔掉", "防水","好友"}; - struct tm *ptime = localtime(&now); - int j; - - if((currstat != CLASS) && (cuser.uflag & MOVIE_FLAG) && - !SHM->Pbusystate && SHM->max_film > 0) { - if(currstat == PSALE) { - i = PSALE; - reload_money(); - } else { - do { - if(!i) - i = 1 + (int)(((float)SHM->max_film * - rand()) / (RAND_MAX + 1.0)); - - for(j = SHM->max_history; j >= 0; j--) - if(i == history[j]) { - i = 0; - break; - } - } while(i == 0); - } - - memcpy(history, &history[1], SHM->max_history * sizeof(short)); - history[SHM->max_history] = j = i; - - if(i == 999) /* Goodbye my friend */ - i = 0; - - move(1, 0); - clrtoline(1 + FILMROW); /* 清掉上次的 */ - Jaky_outs(SHM->notes[i], 11); /* 只印11行就好 */ - outs(reset_color); +void +movie(int i) +{ + static short history[MAX_HISTORY]; + static char myweek[] = "天一二三四五六"; + const char *msgs[] = {"關閉", "打開", "拔掉", "防水", "好友"}; + struct tm *ptime = localtime(&now); + int j; + + if ((currstat != CLASS) && (cuser.uflag & MOVIE_FLAG) && + !SHM->Pbusystate && SHM->max_film > 0) { + if (currstat == PSALE) { + i = PSALE; + reload_money(); + } else { + do { + if (!i) + i = 1 + (int)(((float)SHM->max_film * + rand()) / (RAND_MAX + 1.0)); + + for (j = SHM->max_history; j >= 0; j--) + if (i == history[j]) { + i = 0; + break; + } + } while (i == 0); + } + + memcpy(history, &history[1], SHM->max_history * sizeof(short)); + history[SHM->max_history] = j = i; + + if (i == 999) /* Goodbye my friend */ + i = 0; + + move(1, 0); + clrtoline(1 + FILMROW); /* 清掉上次的 */ + Jaky_outs(SHM->notes[i], 11); /* 只印11行就好 */ + outs(reset_color); } i = ptime->tm_wday << 1; sprintf(mystatus, "\033[34;46m[%d/%d 星期%c%c %d:%02d]\033[1;33;45m%-14s" - "\033[30;47m 目前坊裡有 \033[31m%d\033[30m人, 我是\033[31m%-12s" - "\033[30m[扣機]\033[31m%s\033[0m", - ptime->tm_mon + 1, ptime->tm_mday, myweek[i], myweek[i + 1], - ptime->tm_hour, ptime->tm_min, currutmp->birth ? - "生日要請客唷" : SHM->today_is, - SHM->UTMPnumber, cuser.userid, msgs[currutmp->pager]); + "\033[30;47m 目前坊裡有 \033[31m%d\033[30m人, 我是\033[31m%-12s" + "\033[30m[扣機]\033[31m%s\033[0m", + ptime->tm_mon + 1, ptime->tm_mday, myweek[i], myweek[i + 1], + ptime->tm_hour, ptime->tm_min, currutmp->birth ? + "生日要請客唷" : SHM->today_is, + SHM->UTMPnumber, cuser.userid, msgs[currutmp->pager]); outmsg(mystatus); refresh(); } -static int show_menu(commands_t *p) { - register int n = 0; - register char *s; - const char *state[4]={"用功\型", "安逸型", "自定型", "SHUTUP"}; - char buf[80]; +static int +show_menu(commands_t * p) +{ + register int n = 0; + register char *s; + const char *state[4] = {"用功\型", "安逸型", "自定型", "SHUTUP"}; + char buf[80]; movie(currstat); move(menu_row, 0); - while((s = p[n].desc)) { - if(HAS_PERM(p[n].level)) { - sprintf(buf, s + 2, state[cuser.proverb % 4]); - prints("%*s (\033[1;36m%c\033[0m)%s\n", menu_column, "", s[1], - buf); - } - n++; + while ((s = p[n].desc)) { + if (HAS_PERM(p[n].level)) { + sprintf(buf, s + 2, state[cuser.proverb % 4]); + prints("%*s (\033[1;36m%c\033[0m)%s\n", menu_column, "", s[1], + buf); + } + n++; } return n - 1; } -void domenu(int cmdmode, char *cmdtitle, int cmd, commands_t cmdtable[]) { - int lastcmdptr; - int n, pos, total, i; - int err; - int chkmailbox(); - static char cmd0[LOGIN]; +void +domenu(int cmdmode, char *cmdtitle, int cmd, commands_t cmdtable[]) +{ + int lastcmdptr; + int n, pos, total, i; + int err; + int chkmailbox(); + static char cmd0[LOGIN]; - if(cmd0[cmdmode]) - cmd = cmd0[cmdmode]; + if (cmd0[cmdmode]) + cmd = cmd0[cmdmode]; setutmpmode(cmdmode); @@ -185,118 +196,116 @@ void domenu(int cmdmode, char *cmdtitle, int cmd, commands_t cmdtable[]) { lastcmdptr = pos = 0; do { - i = -1; - switch(cmd) { - case Ctrl('C'): - cal(); - i = lastcmdptr; - refscreen = YEA; - break; - case Ctrl('I'): - t_idle(); - refscreen = YEA; - i = lastcmdptr; - break; - case Ctrl('N'): - New(); - refscreen = YEA; - i = lastcmdptr; - break; - case Ctrl('A'): - if(mail_man() == FULLUPDATE) - refscreen = YEA; - i = lastcmdptr; - break; - case KEY_DOWN: - i = lastcmdptr; - case KEY_HOME: - case KEY_PGUP: - do { - if(++i > total) - i = 0; - } while(!HAS_PERM(cmdtable[i].level)); - break; - case KEY_END: - case KEY_PGDN: - i = total; - break; - case KEY_UP: - i = lastcmdptr; - do { - if(--i < 0) - i = total; - } while(!HAS_PERM(cmdtable[i].level)); - break; - case KEY_LEFT: - case 'e': - case 'E': - if(cmdmode == MMENU) - cmd = 'G'; - else if((cmdmode == MAIL) && chkmailbox()) - cmd = 'R'; - else - return; - default: - if((cmd == 's' || cmd == 'r') && - (currstat == MMENU || currstat == TMENU || currstat == XMENU)) { - if(cmd == 's') - ReadSelect(); - else - Read(); - refscreen = YEA; - i = lastcmdptr; - break; - } - - if(cmd == '\n' || cmd == '\r' || cmd == KEY_RIGHT) { - move(b_lines, 0); - clrtoeol(); - - currstat = XMODE; - - if((err = (*cmdtable[lastcmdptr].cmdfunc) ()) == QUIT) - return; - currutmp->mode = currstat = cmdmode; - - if(err == XEASY) { - refresh(); - safe_sleep(1); - } else if(err != XEASY + 1 || err == FULLUPDATE) - refscreen = YEA; - - if(err != -1) - cmd = cmdtable[lastcmdptr].desc[0]; - else - cmd = cmdtable[lastcmdptr].desc[1]; - cmd0[cmdmode] = cmdtable[lastcmdptr].desc[0]; - } - - if(cmd >= 'a' && cmd <= 'z') - cmd &= ~0x20; - while(++i <= total) - if(cmdtable[i].desc[1] == cmd) - break; - } - - if(i > total || !HAS_PERM(cmdtable[i].level)) - continue; - - if(refscreen) { - showtitle(cmdtitle, BBSName); - - show_menu(cmdtable); - - outmsg(mystatus); - refscreen = NA; - } - cursor_clear(menu_row + pos, menu_column); - n = pos = -1; - while(++n <= (lastcmdptr = i)) - if(HAS_PERM(cmdtable[n].level)) - pos++; - - cursor_show(menu_row + pos, menu_column); - } while(((cmd = egetch()) != EOF) || refscreen); + i = -1; + switch (cmd) { + case Ctrl('C'): + cal(); + i = lastcmdptr; + refscreen = YEA; + break; + case Ctrl('I'): + t_idle(); + refscreen = YEA; + i = lastcmdptr; + break; + case Ctrl('N'): + New(); + refscreen = YEA; + i = lastcmdptr; + break; + case Ctrl('A'): + if (mail_man() == FULLUPDATE) + refscreen = YEA; + i = lastcmdptr; + break; + case KEY_DOWN: + i = lastcmdptr; + case KEY_HOME: + case KEY_PGUP: + do { + if (++i > total) + i = 0; + } while (!HAS_PERM(cmdtable[i].level)); + break; + case KEY_END: + case KEY_PGDN: + i = total; + break; + case KEY_UP: + i = lastcmdptr; + do { + if (--i < 0) + i = total; + } while (!HAS_PERM(cmdtable[i].level)); + break; + case KEY_LEFT: + case 'e': + case 'E': + if (cmdmode == MMENU) + cmd = 'G'; + else if ((cmdmode == MAIL) && chkmailbox()) + cmd = 'R'; + else + return; + default: + if ((cmd == 's' || cmd == 'r') && + (currstat == MMENU || currstat == TMENU || currstat == XMENU)) { + if (cmd == 's') + ReadSelect(); + else + Read(); + refscreen = YEA; + i = lastcmdptr; + break; + } + if (cmd == '\n' || cmd == '\r' || cmd == KEY_RIGHT) { + move(b_lines, 0); + clrtoeol(); + + currstat = XMODE; + + if ((err = (*cmdtable[lastcmdptr].cmdfunc) ()) == QUIT) + return; + currutmp->mode = currstat = cmdmode; + + if (err == XEASY) { + refresh(); + safe_sleep(1); + } else if (err != XEASY + 1 || err == FULLUPDATE) + refscreen = YEA; + + if (err != -1) + cmd = cmdtable[lastcmdptr].desc[0]; + else + cmd = cmdtable[lastcmdptr].desc[1]; + cmd0[cmdmode] = cmdtable[lastcmdptr].desc[0]; + } + if (cmd >= 'a' && cmd <= 'z') + cmd &= ~0x20; + while (++i <= total) + if (cmdtable[i].desc[1] == cmd) + break; + } + + if (i > total || !HAS_PERM(cmdtable[i].level)) + continue; + + if (refscreen) { + showtitle(cmdtitle, BBSName); + + show_menu(cmdtable); + + outmsg(mystatus); + refscreen = NA; + } + cursor_clear(menu_row + pos, menu_column); + n = pos = -1; + while (++n <= (lastcmdptr = i)) + if (HAS_PERM(cmdtable[n].level)) + pos++; + + cursor_show(menu_row + pos, menu_column); + } while (((cmd = egetch()) != EOF) || refscreen); abort_bbs(0); } @@ -573,3 +582,4 @@ int Name_Menu() return 0; } + diff --git a/pttbbs/mbbsd/more.c b/pttbbs/mbbsd/more.c index 1d6b173a..56efeb57 100644 --- a/pttbbs/mbbsd/more.c +++ b/pttbbs/mbbsd/more.c @@ -1,15 +1,15 @@ -/* $Id: more.c,v 1.14 2002/06/04 13:08:34 in2 Exp $ */ +/* $Id: more.c,v 1.15 2002/07/05 17:10:27 in2 Exp $ */ #include "bbs.h" #define MORE_BUFSIZE 4096 #define MORE_WINSIZE 4096 #define STR_ANSICODE "[0123456789;," -static int more_base, more_size, more_head; +static int more_base, more_size, more_head; static unsigned char more_pool[MORE_BUFSIZE]; #define MAXPATHLEN 256 -static char *more_help[] = { +static char *more_help[] = { "\0閱\讀文章功\能鍵使用說明", "\01游標移動功\能鍵", "(↑) 上捲一行", @@ -34,229 +34,193 @@ static char *more_help[] = { NULL }; -int beep = 0; +int beep = 0; static void -more_goto (int fd, off_t off) -{ - int base = more_base; - - if (off < base || off >= base + more_size) - { - more_base = base = off & (-MORE_WINSIZE); - lseek (fd, base, SEEK_SET); - more_size = read (fd, more_pool, MORE_BUFSIZE); - } - more_head = off - base; -} - -static int -more_readln (int fd, unsigned char *buf) +more_goto(int fd, off_t off) { - int ch; - - unsigned char *data, *tail, *cc; - int len, bytes, in_ansi; - int size, head, ansilen; - - len = bytes = in_ansi = ansilen = 0; - tail = buf + ANSILINELEN - 1; - size = more_size; - head = more_head; - data = &more_pool[head]; - - do - { - if (head >= size) - { - more_base += size; - data = more_pool; - more_size = size = read (fd, data, MORE_BUFSIZE); - if (size == 0) - break; - head = 0; - } + int base = more_base; - ch = *data++; - head++; - bytes++; - if (ch == '\n') - { - break; - } - if (ch == '\t') - { - do - { - *buf++ = ' '; - } - while ((++len & 7) && len < 80); - } - else if (ch == '\033') - { - if (atoi ((char *)(data + 1)) > 47) - { - if ((cc = (unsigned char *)strchr ((char *)(data + 1), 'm')) != NULL) - { - ch = cc - data + 1; - - data += ch; - head += ch; - bytes += ch; - } - } - else - { - if (showansi) - *buf++ = ch; - in_ansi = 1; - } - } - else if (in_ansi) - { - if (showansi) - *buf++ = ch; - if (!strchr (STR_ANSICODE, ch)) - in_ansi = 0; - } - else if (isprint2 (ch)) - { - len++; - *buf++ = ch; + if (off < base || off >= base + more_size) { + more_base = base = off & (-MORE_WINSIZE); + lseek(fd, base, SEEK_SET); + more_size = read(fd, more_pool, MORE_BUFSIZE); } - } - while (len < 80 && buf < tail); - *buf = '\0'; - more_head = head; - return bytes; + more_head = off - base; } -/* not used -static int readln(FILE *fp, char *buf) { - register int ch, i, len, bytes, in_ansi; - - len = bytes = in_ansi = i = 0; - while(len < 80 && i < ANSILINELEN && (ch = getc(fp)) != EOF) { +static int +more_readln(int fd, unsigned char *buf) +{ + int ch; + + unsigned char *data, *tail, *cc; + int len, bytes, in_ansi; + int size, head, ansilen; + + len = bytes = in_ansi = ansilen = 0; + tail = buf + ANSILINELEN - 1; + size = more_size; + head = more_head; + data = &more_pool[head]; + + do { + if (head >= size) { + more_base += size; + data = more_pool; + more_size = size = read(fd, data, MORE_BUFSIZE); + if (size == 0) + break; + head = 0; + } + ch = *data++; + head++; bytes++; - if(ch == '\n') + if (ch == '\n') { break; - else if(ch == '\t') + } + if (ch == '\t') { do { - buf[i++] = ' '; - } while((++len & 7) && len < 80); - else if(ch == '\a') - beep = 1; - else if(ch == '\033') { - if(showansi) - buf[i++] = ch; - in_ansi = 1; - } else if(in_ansi) { - if(showansi) - buf[i++] = ch; - if(!strchr("[0123456789;,", ch)) + *buf++ = ' '; + } + while ((++len & 7) && len < 80); + } else if (ch == '\033') { + if (atoi((char *)(data + 1)) > 47) { + if ((cc = (unsigned char *)strchr((char *)(data + 1), 'm')) != NULL) { + ch = cc - data + 1; + + data += ch; + head += ch; + bytes += ch; + } + } else { + if (showansi) + *buf++ = ch; + in_ansi = 1; + } + } else if (in_ansi) { + if (showansi) + *buf++ = ch; + if (!strchr(STR_ANSICODE, ch)) in_ansi = 0; - } else if(isprint2(ch)) { + } else if (isprint2(ch)) { len++; - buf[i++] = ch; + *buf++ = ch; } } - buf[i] = '\0'; + while (len < 80 && buf < tail); + *buf = '\0'; + more_head = head; return bytes; } -*/ - -static int more_web(char *fpath, int promptend); -int more(char *fpath, int promptend) { - static char *head[4] = {"作者", "標題", "時間" ,"轉信"}; - char *ptr, *word = NULL, buf[ANSILINELEN + 1], *ch1; - struct stat st; - -/* rocker */ - //FILE *fp; - int fd, fsize; - - unsigned int pagebreak[MAX_PAGES], pageno, lino = 0; - int line, ch, viewed, pos, numbytes; - int header = 0; - int local = 0; - char search_char0=0; - static char search_str[81]=""; - typedef char* (*FPTR)(); - static FPTR fptr; - int searching = 0; - int scrollup = 0; - char *printcolor[3]= {"44","33;45","0;34;46"}, color =0; - char *http[80]={NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL, - NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL, - NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL, - NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL, - NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL, - NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL, - NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL, - NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL}; + +/* + * not used static int readln(FILE *fp, char *buf) { register int ch, i, len, + * bytes, in_ansi; + * + * len = bytes = in_ansi = i = 0; while(len < 80 && i < ANSILINELEN && (ch = + * getc(fp)) != EOF) { bytes++; if(ch == '\n') break; else if(ch == '\t') do + * { buf[i++] = ' '; } while((++len & 7) && len < 80); else if(ch == '\a') + * beep = 1; else if(ch == '\033') { if(showansi) buf[i++] = ch; in_ansi = 1; + * } else if(in_ansi) { if(showansi) buf[i++] = ch; + * if(!strchr("[0123456789;,", ch)) in_ansi = 0; } else if(isprint2(ch)) { + * len++; buf[i++] = ch; } } buf[i] = '\0'; return bytes; } + */ + +static int more_web(char *fpath, int promptend); +int +more(char *fpath, int promptend) +{ + static char *head[4] = {"作者", "標題", "時間", "轉信"}; + char *ptr, *word = NULL, buf[ANSILINELEN + 1], *ch1; + struct stat st; + + /* rocker */ + //FILE * fp; + int fd, fsize; + + unsigned int pagebreak[MAX_PAGES], pageno, lino = 0; + int line, ch, viewed, pos, numbytes; + int header = 0; + int local = 0; + char search_char0 = 0; + static char search_str[81] = ""; + typedef char *(*FPTR) (); + static FPTR fptr; + int searching = 0; + int scrollup = 0; + char *printcolor[3] = {"44", "33;45", "0;34;46"}, color = 0; + char *http[80] = {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}; /* Ptt */ - char pagemode = 0; - char pagecount = 0; + char pagemode = 0; + char pagecount = 0; memset(pagebreak, 0, sizeof(pagebreak)); - if(*search_str) + if (*search_str) search_char0 = *search_str; *search_str = 0; #ifdef MDCACHE fd = mdcacheopen(fpath); -#else - fd = open (fpath, O_RDONLY, 0600); +#else + fd = open(fpath, O_RDONLY, 0600); #endif - if (fd < 0) return -1; - - if(fstat(fd, &st) || ((fsize = st.st_size) <= 0) || S_ISDIR (st.st_mode)) - { - close(fd); //Ptt + if (fd < 0) return -1; - } + + if (fstat(fd, &st) || ((fsize = st.st_size) <= 0) || S_ISDIR(st.st_mode)) { + close(fd); + //Ptt + return -1; + } pagebreak[0] = pageno = viewed = line = pos = 0; clear(); -/* rocker */ + /* rocker */ - more_base = more_head = more_size = 0; - - while((numbytes = more_readln(fd, (unsigned char *)buf)) || (line == t_lines)) { - if(scrollup) { + more_base = more_head = more_size = 0; + + while ((numbytes = more_readln(fd, (unsigned char *)buf)) || (line == t_lines)) { + if (scrollup) { rscroll(); move(0, 0); } - if(numbytes) { /* 一般資料處理 */ - if(!viewed) { /* begin of file */ - if(showansi) { /* header processing */ - if(!strncmp(buf, str_author1, LEN_AUTHOR1)) { + if (numbytes) { /* 一般資料處理 */ + if (!viewed) { /* begin of file */ + if (showansi) { /* header processing */ + if (!strncmp(buf, str_author1, LEN_AUTHOR1)) { line = 3; word = buf + LEN_AUTHOR1; local = 1; - } else if(!strncmp(buf, str_author2, LEN_AUTHOR2)) { + } else if (!strncmp(buf, str_author2, LEN_AUTHOR2)) { line = 4; word = buf + LEN_AUTHOR2; } - - while(pos < line) { - if(!pos && ((ptr = strstr(word, str_post1)) || - (ptr = strstr(word, str_post2)))) { + while (pos < line) { + if (!pos && ((ptr = strstr(word, str_post1)) || + (ptr = strstr(word, str_post2)))) { ptr[-1] = '\0'; prints("\033[47;34m %s \033[44;37m%-53.53s" - "\033[47;34m %.4s \033[44;37m%-13s\033[m\n", + "\033[47;34m %.4s \033[44;37m%-13s\033[m\n", head[0], word, ptr, ptr + 5); } else if (pos < line) prints("\033[47;34m %s \033[44;37m%-72.72s" "\033[m\n", head[pos], word); - + viewed += numbytes; numbytes = more_readln(fd, (unsigned char *)buf); - - /* 第一行太長了 */ - if(!pos && viewed > 79) { - /* 第二行不是 [標....] */ - if(memcmp( buf, head[1], 2)) { + + /* 第一行太長了 */ + if (!pos && viewed > 79) { + /* 第二行不是 [標....] */ + if (memcmp(buf, head[1], 2)) { /* 讀下一行進來處理 */ viewed += numbytes; numbytes = more_readln(fd, (unsigned char *)buf); @@ -264,91 +228,87 @@ int more(char *fpath, int promptend) { } pos++; } - if(pos) { + if (pos) { header = 1; - + prints("\033[36m%s\033[m\n", msg_seperator); - ++line; ++pos; + ++line; + ++pos; } } lino = pos; word = NULL; } - /* ※處理引用者 & 引言 */ - if((buf[1] == ' ') && (buf[0] == ':' || buf[0] == '>')) + if ((buf[1] == ' ') && (buf[0] == ':' || buf[0] == '>')) word = "\033[36m"; - else if(!strncmp(buf, "※", 2) || !strncmp(buf, "==>", 3)) + else if (!strncmp(buf, "※", 2) || !strncmp(buf, "==>", 3)) word = "\033[32m"; - + ch1 = buf; - while(1) { - int i; - char e,*ch2; - - if((ch2 = strstr(ch1, "http://"))) - ; - else if((ch2 = strstr(ch1,"gopher://"))) - ; - else if((ch2 = strstr(ch1,"mailto:"))) - ; + while (1) { + int i; + char e, *ch2; + + if ((ch2 = strstr(ch1, "http://"))); + else if ((ch2 = strstr(ch1, "gopher://"))); + else if ((ch2 = strstr(ch1, "mailto:"))); else break; - for(e = 0; ch2[(int)e] != ' ' && ch2[(int)e] != '\n' && - ch2[(int)e] != '\0' && ch2[(int)e] != '"' && - ch2[(int)e] != ';' && ch2[(int)e] != ']'; e++); - for(i = 0; http[i] && i < 80; i++) - if(!strncmp(http[i], ch2, e) && http[(int)e] == 0) + for (e = 0; ch2[(int)e] != ' ' && ch2[(int)e] != '\n' && + ch2[(int)e] != '\0' && ch2[(int)e] != '"' && + ch2[(int)e] != ';' && ch2[(int)e] != ']'; e++); + for (i = 0; http[i] && i < 80; i++) + if (!strncmp(http[i], ch2, e) && http[(int)e] == 0) break; - if(!http[i]) { + if (!http[i]) { http[i] = (char *)malloc(e + 1); strncpy(http[i], ch2, e); http[i][(int)e] = 0; pagecount++; - } + } ch1 = &ch2[7]; } - if(word) + if (word) outs(word); { - char msg[500], *pos; - - if(*search_str && (pos = fptr(buf, search_str))) { - char SearchStr[81]; - char buf1[100], *pos1; - + char msg[500], *pos; + + if (*search_str && (pos = fptr(buf, search_str))) { + char SearchStr[81]; + char buf1[100], *pos1; + strncpy(SearchStr, pos, strlen(search_str)); SearchStr[strlen(search_str)] = 0; searching = 0; sprintf(msg, "%.*s\033[7m%s\033[m", pos - buf, buf, SearchStr); - while((pos = fptr(pos1 = pos + strlen(search_str), - search_str))) { + while ((pos = fptr(pos1 = pos + strlen(search_str), + search_str))) { sprintf(buf1, "%.*s\033[7m%s\033[m", pos - pos1, pos1, SearchStr); strcat(msg, buf1); } strcat(msg, pos1); - outs(Ptt_prints(msg,NO_RELOAD)); + outs(Ptt_prints(msg, NO_RELOAD)); } else - outs(Ptt_prints(buf,NO_RELOAD)); + outs(Ptt_prints(buf, NO_RELOAD)); } - if(word) { + if (word) { outs("\033[m"); word = NULL; } outch('\n'); - - if(beep) { + + if (beep) { bell(); beep = 0; } - - if(line < b_lines) /* 一般資料讀取 */ + if (line < b_lines) /* 一般資料讀取 */ line++; - - if(line == b_lines && searching == -1) { - if(pageno > 0) + + if (line == b_lines && searching == -1) { + if (pageno > 0) more_goto(fd, viewed = pagebreak[--pageno]); else searching = 0; @@ -356,104 +316,102 @@ int more(char *fpath, int promptend) { clear(); continue; } - - if(scrollup) { + if (scrollup) { move(line = b_lines, 0); clrtoeol(); - for(pos = 1; pos < b_lines; pos++) + for (pos = 1; pos < b_lines; pos++) viewed += more_readln(fd, (unsigned char *)buf); - } else if(pos == b_lines) /* 捲動螢幕 */ + } else if (pos == b_lines) /* 捲動螢幕 */ scroll(); else pos++; - if(!scrollup && ++lino >= b_lines && pageno < MAX_PAGES - 1) { + if (!scrollup && ++lino >= b_lines && pageno < MAX_PAGES - 1) { pagebreak[++pageno] = viewed; lino = 1; } - - if(scrollup) { + if (scrollup) { lino = scrollup; scrollup = 0; } - viewed += numbytes; /* 累計讀過資料 */ + viewed += numbytes; /* 累計讀過資料 */ } else - line = b_lines; /* end of END */ - - if(promptend && - ((!searching && line == b_lines) || viewed == fsize)) { + line = b_lines; /* end of END */ + + if (promptend && + ((!searching && line == b_lines) || viewed == fsize)) { /* Kaede 剛好 100% 時不停 */ move(b_lines, 0); - if(viewed == fsize) { - if(searching == 1) + if (viewed == fsize) { + if (searching == 1) searching = 0; color = 0; - } else if(pageno == 1 && lino == 1) { - if(searching == -1) + } else if (pageno == 1 && lino == 1) { + if (searching == -1) searching = 0; color = 1; } else color = 2; prints("\033[m\033[%sm 瀏覽 P.%d(%d%%) %s %-30.30s%s", - printcolor[(int)color], - pageno, + printcolor[(int)color], + pageno, (int)((viewed * 100) / fsize), pagemode ? "\033[30;47m" : "\033[31;47m", - pagemode ? http[pagemode-1] : "(h)\033[30m求助 \033[31m→↓[PgUp][", + pagemode ? http[pagemode - 1] : "(h)\033[30m求助 \033[31m→↓[PgUp][", pagemode ? "\033[31m[TAB]\033[30m切換 \033[31m[Enter]\033[30m選定 \033[31m←\033[30m放棄\033[m" : "PgDn][Home][End]\033[30m游標移動 \033[31m←[q]\033[30m結束 \033[m"); - - - while(line == b_lines || (line > 0 && viewed == fsize)) { - switch((ch = egetch())) { + + + while (line == b_lines || (line > 0 && viewed == fsize)) { + switch ((ch = egetch())) { case ':': - { - char buf[10]; - int i = 0; - - getdata(b_lines - 1, 0, "Goto Page: ", buf, 5, DOECHO); - sscanf(buf, "%d", &i); - if(0 < i && i < MAX_PAGES && (i == 1 || pagebreak[i - 1])) - pageno = i - 1; - else if(pageno) - pageno--; - lino = line = 0; - break; - } + { + char buf[10]; + int i = 0; + + getdata(b_lines - 1, 0, "Goto Page: ", buf, 5, DOECHO); + sscanf(buf, "%d", &i); + if (0 < i && i < MAX_PAGES && (i == 1 || pagebreak[i - 1])) + pageno = i - 1; + else if (pageno) + pageno--; + lino = line = 0; + break; + } case '/': - { - char ans[4] = "n"; - - *search_str = search_char0; - getdata_buf(b_lines - 1, 0,"[搜尋]關鍵字:", search_str, - 40, DOECHO); - if(*search_str) { - searching = 1; - if(getdata(b_lines - 1, 0, "區分大小寫(Y/N/Q)? [N] ", + { + char ans[4] = "n"; + + *search_str = search_char0; + getdata_buf(b_lines - 1, 0, "[搜尋]關鍵字:", search_str, + 40, DOECHO); + if (*search_str) { + searching = 1; + if (getdata(b_lines - 1, 0, "區分大小寫(Y/N/Q)? [N] ", ans, sizeof(ans), LCECHO) && *ans == 'y') - fptr = strstr; - else - fptr = strcasestr; + fptr = strstr; + else + fptr = strcasestr; + } + if (*ans == 'q') + searching = 0; + if (pageno) + pageno--; + lino = line = 0; + break; } - if(*ans == 'q') - searching = 0; - if(pageno) - pageno--; - lino = line = 0; - break; - } case 'n': - if(*search_str) { + if (*search_str) { searching = 1; - if(pageno) + if (pageno) pageno--; lino = line = 0; } break; case 'N': - if(*search_str) { + if (*search_str) { searching = -1; - if(pageno) + if (pageno) pageno--; lino = line = 0; } @@ -479,10 +437,10 @@ int more(char *fpath, int promptend) { close(fd); return 12; case KEY_LEFT: - if(pagemode) { + if (pagemode) { pagemode = 0; *search_str = 0; - if(pageno) + if (pageno) pageno--; lino = line = 0; break; @@ -498,13 +456,13 @@ int more(char *fpath, int promptend) { case 'f': close(fd); return 3; - case ']': /* Kaede 為了主題閱讀方便 */ + case ']': /* Kaede 為了主題閱讀方便 */ close(fd); return 4; - case '[': /* Kaede 為了主題閱讀方便 */ + case '[': /* Kaede 為了主題閱讀方便 */ close(fd); return 2; - case '=': /* Kaede 為了主題閱讀方便 */ + case '=': /* Kaede 為了主題閱讀方便 */ close(fd); return 5; case Ctrl('F'): @@ -512,21 +470,21 @@ int more(char *fpath, int promptend) { line = 1; break; case 't': - if(viewed == fsize) { + if (viewed == fsize) { close(fd); return 4; } line = 1; break; case ' ': - if(viewed == fsize) { + if (viewed == fsize) { close(fd); return 3; } line = 1; break; case KEY_RIGHT: - if(viewed == fsize) { + if (viewed == fsize) { close(fd); return 0; } @@ -534,18 +492,18 @@ int more(char *fpath, int promptend) { break; case '\r': case '\n': - if(pagemode) { - more_web(http[pagemode-1],YEA); + if (pagemode) { + more_web(http[pagemode - 1], YEA); pagemode = 0; *search_str = 0; - if(pageno) + if (pageno) pageno--; lino = line = 0; break; } case KEY_DOWN: - if(viewed == fsize || - (promptend == 2 && (ch == '\r' || ch == '\n'))) { + if (viewed == fsize || + (promptend == 2 && (ch == '\r' || ch == '\n'))) { close(fd); return 3; } @@ -566,12 +524,12 @@ int more(char *fpath, int promptend) { case '?': /* Kaede Buggy ... */ show_help(more_help); - if(pageno) + if (pageno) pageno--; lino = line = 0; break; case 'E': - if(HAS_PERM(PERM_SYSOP) && strcmp(fpath, "etc/ve.hlp")) { + if (HAS_PERM(PERM_SYSOP) && strcmp(fpath, "etc/ve.hlp")) { close(fd); vedit(fpath, NA, NULL); return 0; @@ -579,7 +537,7 @@ int more(char *fpath, int promptend) { break; case Ctrl('C'): cal(); - if(pageno) + if (pageno) pageno--; lino = line = 0; break; @@ -587,26 +545,26 @@ int more(char *fpath, int promptend) { case Ctrl('T'): getdata(b_lines - 2, 0, "把這篇文章收入到暫存檔?[y/N] ", buf, 4, LCECHO); - if(buf[0] == 'y') { - char tmpbuf[128]; - + if (buf[0] == 'y') { + char tmpbuf[128]; + setuserfile(tmpbuf, ask_tmpbuf(b_lines - 1)); sprintf(buf, "cp -f %s %s", fpath, tmpbuf); system(buf); } - if(pageno) + if (pageno) pageno--; lino = line = 0; break; #if 0 case Ctrl('I'): - if(!pagecount) + if (!pagecount) break; pagemode = (pagemode % pagecount) + 1; - strncpy(search_str,http[pagemode-1],80); - search_str[80] =0; + strncpy(search_str, http[pagemode - 1], 80); + search_str[80] = 0; fptr = strstr; - if(pageno) + if (pageno) pageno--; lino = line = 0; break; @@ -616,23 +574,23 @@ int more(char *fpath, int promptend) { break; case Ctrl('B'): case KEY_PGUP: - if(pageno > 1) { - if(lino < 2) + if (pageno > 1) { + if (lino < 2) pageno -= 2; else pageno--; lino = line = 0; - } else if(pageno && lino > 1) + } else if (pageno && lino > 1) pageno = line = 0; break; case Ctrl('H'): - if(pageno > 1) { - if(lino < 2) + if (pageno > 1) { + if (lino < 2) pageno -= 2; else pageno--; lino = line = 0; - } else if(pageno && lino > 1) + } else if (pageno && lino > 1) pageno = line = 0; else { close(fd); @@ -640,50 +598,50 @@ int more(char *fpath, int promptend) { } } } - - if(line > 0) { + + if (line > 0) { move(b_lines, 0); clrtoeol(); refresh(); - } else if(line < 0) { /* Line scroll up */ - if(pageno <= 1) { - if(lino == 1 || !pageno) { + } else if (line < 0) { /* Line scroll up */ + if (pageno <= 1) { + if (lino == 1 || !pageno) { close(fd); return 1; } - if(header && lino <= 5) { + if (header && lino <= 5) { more_goto(fd, viewed = pagebreak[scrollup = lino = - pageno = 0] = 0); + pageno = 0] = 0); clear(); } } - if(pageno && lino > 1 + local) { - line = (lino - 2) - local; - if(pageno > 1 && viewed == fsize) + if (pageno && lino > 1 + local) { + line = (lino - 2) - local; + if (pageno > 1 && viewed == fsize) line += local; scrollup = lino - 1; more_goto(fd, viewed = pagebreak[pageno - 1]); - while(line--) + while (line--) viewed += more_readln(fd, (unsigned char *)buf); - } else if(pageno > 1) { + } else if (pageno > 1) { scrollup = b_lines - 1; line = (b_lines - 2) - local; more_goto(fd, viewed = pagebreak[--pageno - 1]); - while(line--) + while (line--) viewed += more_readln(fd, (unsigned char *)buf); } line = pos = 0; } else { pos = 0; - more_goto (fd, viewed = pagebreak[pageno]); - move(0,0); + more_goto(fd, viewed = pagebreak[pageno]); + move(0, 0); clear(); } } } close(fd); - if(promptend) { + if (promptend) { pressanykey(); clear(); } else @@ -691,54 +649,56 @@ int more(char *fpath, int promptend) { return 0; } -static int more_web(char *fpath, int promptend) { - char *ch, *ch1 = NULL; - char *hostname = fpath,userfile[MAXPATHLEN],file[MAXPATHLEN]="/"; - char genbuf[200]; - time_t dtime; +static int +more_web(char *fpath, int promptend) +{ + char *ch, *ch1 = NULL; + char *hostname = fpath, userfile[MAXPATHLEN], file[MAXPATHLEN] = "/"; + char genbuf[200]; + time_t dtime; #if !defined(USE_LYNX) && defined(USE_PROXY) - int a; - FILE *fp; + int a; + FILE *fp; struct hostent *h; struct sockaddr_in sin; #endif - if((ch = strstr(fpath, "mailto:"))) { - if(!HAS_PERM(PERM_LOGINOK)) { - move(b_lines - 1,0); + if ((ch = strstr(fpath, "mailto:"))) { + if (!HAS_PERM(PERM_LOGINOK)) { + move(b_lines - 1, 0); outs("\033[41m 您的權限不足無法使用internet mail... \033[m"); refresh(); return 0; } - if(!invalidaddr(&ch[7]) && - getdata(b_lines - 1, 0, "[寄信]主題:", genbuf, 40, DOECHO)) + if (!invalidaddr(&ch[7]) && + getdata(b_lines - 1, 0, "[寄信]主題:", genbuf, 40, DOECHO)) do_send(&ch[7], genbuf); else { - move(b_lines - 1,0); + move(b_lines - 1, 0); outs("\033[41m 收信人email 或 標題 有誤... \033[m"); refresh(); } - return 0; + return 0; } - if((ch = strstr(fpath, "gopher://"))) { - item_t item; + if ((ch = strstr(fpath, "gopher://"))) { + item_t item; strcpy(item.X.G.server, &ch[9]); strcpy(item.X.G.path, "1/"); item.X.G.port = 70; - gem(fpath , &item, 0); - return 0; + gem(fpath, &item, 0); + return 0; } - if((ch = strstr(fpath, "http://"))) - hostname=&ch[7]; - if((ch = strchr(hostname, '/'))) { - *ch = 0; - if(&ch1[1]) - strcat(file,&ch[1]); + if ((ch = strstr(fpath, "http://"))) + hostname = &ch[7]; + if ((ch = strchr(hostname, '/'))) { + *ch = 0; + if (&ch1[1]) + strcat(file, &ch[1]); } - if(file[strlen(file) - 1] == '/') - strcat(file,"index.html"); - move(b_lines-1,0); + if (file[strlen(file) - 1] == '/') + strcat(file, "index.html"); + move(b_lines - 1, 0); clrtoeol(); #ifdef USE_PROXY sprintf(genbuf, "\033[33;44m 正在連往%s.(proxy:%s).....請稍候....\033[m", @@ -750,65 +710,65 @@ static int more_web(char *fpath, int promptend) { refresh(); #ifdef LOCAL_PROXY -/* 先找 local disk 的 proxy */ - dtime=now; - sprintf(userfile,"hproxy/%s%s",hostname,file); - if(dashf(userfile) && (dtime - dasht(userfile)) < HPROXYDAY * 24 * 60 - && more(userfile,promptend)) { - return 1; + /* 先找 local disk 的 proxy */ + dtime = now; + sprintf(userfile, "hproxy/%s%s", hostname, file); + if (dashf(userfile) && (dtime - dasht(userfile)) < HPROXYDAY * 24 * 60 + && more(userfile, promptend)) { + return 1; } - ch=userfile - 1; - while((ch1 = strchr(ch + 1,'/'))) { - *ch1 = 0; - if(!dashd(ch)) - mkdir(ch+1,0755); - chdir(ch+1); - *ch1 = '/'; - ch = ch1; + ch = userfile - 1; + while ((ch1 = strchr(ch + 1, '/'))) { + *ch1 = 0; + if (!dashd(ch)) + mkdir(ch + 1, 0755); + chdir(ch + 1); + *ch1 = '/'; + ch = ch1; } chdir(BBSHOME); #endif #ifndef USE_LYNX #ifdef USE_PROXY - if(!(h = gethostbyname(PROXYSERVER))) { + if (!(h = gethostbyname(PROXYSERVER))) { outs("\033[33;44m 找不到這個proxy server!..\033[m"); refresh(); return; } - ()memset((char *)&sin, 0, sizeof(sin)); + () memset((char *)&sin, 0, sizeof(sin)); sin.sin_family = AF_INET; - if(h == NULL) + if (h == NULL) sin.sin_addr.s_addr = inet_addr(PROXYSERVER); else - ()memcpy(&sin.sin_addr.s_addr, h->h_addr, h->h_length); + () memcpy(&sin.sin_addr.s_addr, h->h_addr, h->h_length); - sin.sin_port = htons((ushort)PROXYPORT); /* HTTP port */ + sin.sin_port = htons((ushort) PROXYPORT); /* HTTP port */ a = socket(AF_INET, SOCK_STREAM, 0); - if((connect(a, (struct sockaddr *) & sin, sizeof sin)) < 0) { + if ((connect(a, (struct sockaddr *) & sin, sizeof sin)) < 0) { outs("\033[1;44m 連接到proxy受到拒絕 ! \033[m"); refresh(); return; } - sprintf(genbuf,"GET http://%s/%s HTTP/1.1\n",hostname,file); + sprintf(genbuf, "GET http://%s/%s HTTP/1.1\n", hostname, file); #else - if(!(h = gethostbyname(hostname))) { + if (!(h = gethostbyname(hostname))) { outs("\033[33;44m 找不到這個server!..\033[m"); refresh(); return; } - ()memset((char *) &sin, 0, sizeof(sin)); + () memset((char *)&sin, 0, sizeof(sin)); sin.sin_family = AF_INET; - - if(h == NULL) + + if (h == NULL) sin.sin_addr.s_addr = inet_addr(hostname); else - ()memcpy(&sin.sin_addr.s_addr, h->h_addr, h->h_length); - - sin.sin_port = htons((ushort)80); + () memcpy(&sin.sin_addr.s_addr, h->h_addr, h->h_length); + + sin.sin_port = htons((ushort) 80); a = socket(AF_INET, SOCK_STREAM, 0); - if((connect(a, (struct sockaddr *) & sin, sizeof sin)) < 0) { + if ((connect(a, (struct sockaddr *) & sin, sizeof sin)) < 0) { outs("\033[1;44m 連接受到拒絕 ! \033[m"); refresh(); return; @@ -816,7 +776,7 @@ static int more_web(char *fpath, int promptend) { sprintf(genbuf, "GET %s\n", file); #endif - for(i = strlen(file); file[i - 1] != '/' && i > 0 ; i--); + for (i = strlen(file); file[i - 1] != '/' && i > 0; i--); file[i] = 0; i = strlen(genbuf); @@ -826,70 +786,70 @@ static int more_web(char *fpath, int promptend) { #define ISPRINT 002 #define PRE 004 #define CENTER 010 - if((fp = fopen(userfile,"w"))) { - int flag = 2, c; - char path[MAXPATHLEN]; - unsigned char j, k; + if ((fp = fopen(userfile, "w"))) { + int flag = 2, c; + char path[MAXPATHLEN]; + unsigned char j, k; - while((i = read(a,genbuf,200))) { - if(i < 0) + while ((i = read(a, genbuf, 200))) { + if (i < 0) return; - genbuf[i]=0; - - for(j = 0, k = 0; genbuf[j] && j < i; j++) { - if((flag & ISPRINT) && genbuf[j] == '<') + genbuf[i] = 0; + + for (j = 0, k = 0; genbuf[j] && j < i; j++) { + if ((flag & ISPRINT) && genbuf[j] == '<') flag |= BLANK; - else if((flag & ISPRINT) && genbuf[j] == '>') + else if ((flag & ISPRINT) && genbuf[j] == '>') flag &= ~BLANK; else { - if(!(flag & BLANK)) { - if(j != k && (genbuf[j] != '\n' || flag & PRE)) + if (!(flag & BLANK)) { + if (j != k && (genbuf[j] != '\n' || flag & PRE)) genbuf[k++] = genbuf[j]; } else { - switch(char_lower(genbuf[j])) { + switch (char_lower(genbuf[j])) { case 'a': break; case 'b': - if(genbuf[j + 1] == 'r' && genbuf[j + 2] == '>') + if (genbuf[j + 1] == 'r' && genbuf[j + 2] == '>') genbuf[k++] = '\n'; break; case 'h': - if(genbuf[j + 1] == 'r' && - (genbuf[j + 2] == '>' || - genbuf[j + 2] == 's')) { + if (genbuf[j + 1] == 'r' && + (genbuf[j + 2] == '>' || + genbuf[j + 2] == 's')) { strncpy(&genbuf[k], "\n--\n", 4); k += 4; } break; case 'l': - if(genbuf[j + 1] == 'i' && genbuf[j + 2]=='>') { + if (genbuf[j + 1] == 'i' && genbuf[j + 2] == '>') { strncpy(&genbuf[k], "\n◎ ", 4); k += 4; } break; case 'p': - if(genbuf[j + 1]=='>') { + if (genbuf[j + 1] == '>') { genbuf[k++] = '\n'; genbuf[k++] = '\n'; - } else if(genbuf[j + 1] == 'r' && - genbuf[j + 2] == 'e') + } else if (genbuf[j + 1] == 'r' && + genbuf[j + 2] == 'e') flag ^= PRE; break; case 't': - if(genbuf[j + 1] == 'd' && genbuf[j + 2]=='>') { + if (genbuf[j + 1] == 'd' && genbuf[j + 2] == '>') { strncpy(&genbuf[k], "\n-\n", 3); k += 3; } break; } } - if((genbuf[j] & 0x80) && (flag & ISPRINT)) + if ((genbuf[j] & 0x80) && (flag & ISPRINT)) flag &= ~ISPRINT; else flag |= ISPRINT; - } + } } - genbuf[k]=0; + genbuf[k] = 0; fputs(genbuf, fp); } fclose(fp); @@ -897,7 +857,7 @@ static int more_web(char *fpath, int promptend) { return more(userfile, promptend); } return 0; -#else /* use lynx dump */ +#else /* use lynx dump */ sprintf(genbuf, "lynx -dump http://%s%s > %s", hostname, file, userfile); system(genbuf); return more(userfile, promptend); diff --git a/pttbbs/mbbsd/name.c b/pttbbs/mbbsd/name.c index af32daa5..d87d8175 100644 --- a/pttbbs/mbbsd/name.c +++ b/pttbbs/mbbsd/name.c @@ -1,17 +1,19 @@ -/* $Id: name.c,v 1.9 2002/07/02 13:01:43 in2 Exp $ */ +/* $Id: name.c,v 1.10 2002/07/05 17:10:27 in2 Exp $ */ #include "bbs.h" -static word_t *current = NULL; -static char *msg_more = "\033[7m-- More --\033[m"; +static word_t *current = NULL; +static char *msg_more = "\033[7m-- More --\033[m"; -typedef char (*arrptr)[]; +typedef char (*arrptr)[]; /* name complete for user ID */ -static int UserMaxLen(char cwlist[][IDLEN + 1], int cwnum, int morenum, - int count) { - int len, max = 0; - - while(count-- > 0 && morenum < cwnum) { +static int +UserMaxLen(char cwlist[][IDLEN + 1], int cwnum, int morenum, + int count) +{ + int len, max = 0; + + while (count-- > 0 && morenum < cwnum) { len = strlen(cwlist[morenum++]); if (len > max) max = len; @@ -19,66 +21,76 @@ static int UserMaxLen(char cwlist[][IDLEN + 1], int cwnum, int morenum, return max; } -static int UserSubArray(char cwbuf[][IDLEN + 1], char cwlist[][IDLEN + 1], - int cwnum, int key, int pos) { - int key2, num = 0; - int n, ch; +static int +UserSubArray(char cwbuf[][IDLEN + 1], char cwlist[][IDLEN + 1], + int cwnum, int key, int pos) +{ + int key2, num = 0; + int n, ch; key = chartoupper(key); - if(key >= 'A' && key <= 'Z') + if (key >= 'A' && key <= 'Z') key2 = key | 0x20; else - key2 = key ; + key2 = key; - for(n = 0; n < cwnum; n++) { + for (n = 0; n < cwnum; n++) { ch = cwlist[n][pos]; - if(ch == key || ch == key2) + if (ch == key || ch == key2) strcpy(cwbuf[num++], cwlist[n]); } return num; } -static void FreeNameList() { - word_t *p, *temp; - - for(p = toplev; p; p = temp) { +static void +FreeNameList() +{ + word_t *p, *temp; + + for (p = toplev; p; p = temp) { temp = p->next; free(p->word); free(p); } } -void CreateNameList() { - if(toplev) +void +CreateNameList() +{ + if (toplev) FreeNameList(); toplev = current = NULL; } -void AddNameList(char *name) { - word_t *node; - - node = (word_t *)malloc(sizeof(word_t)); +void +AddNameList(char *name) +{ + word_t *node; + + node = (word_t *) malloc(sizeof(word_t)); node->next = NULL; node->word = (char *)malloc(strlen(name) + 1); strcpy(node->word, name); - if(toplev) + if (toplev) current = current->next = node; else current = toplev = node; } -int RemoveNameList(char *name) { - word_t *curr, *prev = NULL; +int +RemoveNameList(char *name) +{ + word_t *curr, *prev = NULL; - for(curr = toplev; curr; curr = curr->next) { - if(!strcmp(curr->word, name)) { - if(prev == NULL) + for (curr = toplev; curr; curr = curr->next) { + if (!strcmp(curr->word, name)) { + if (prev == NULL) toplev = curr->next; else prev->next = curr->next; - if(curr == current) + if (curr == current) current = prev; free(curr->word); free(curr); @@ -89,26 +101,30 @@ int RemoveNameList(char *name) { return 0; } -int InNameList(char *name) { - word_t *p; +int +InNameList(char *name) +{ + word_t *p; - for(p = toplev; p; p = p->next) - if(!strcmp(p->word, name)) + for (p = toplev; p; p = p->next) + if (!strcmp(p->word, name)) return 1; return 0; } -void ShowNameList(int row, int column, char *prompt) { - word_t *p; - +void +ShowNameList(int row, int column, char *prompt) +{ + word_t *p; + move(row, column); clrtobot(); outs(prompt); column = 80; - for(p = toplev; p; p = p->next) { + for (p = toplev; p; p = p->next) { row = strlen(p->word) + 1; - if(column + row > 76) { + if (column + row > 76) { column = row; outc('\n'); } else { @@ -119,14 +135,16 @@ void ShowNameList(int row, int column, char *prompt) { } } -void ToggleNameList(int *reciper, char *listfile, char *msg) { - FILE *fp; - char genbuf[200]; +void +ToggleNameList(int *reciper, char *listfile, char *msg) +{ + FILE *fp; + char genbuf[200]; - if((fp = fopen(listfile, "r"))) { - while(fgets(genbuf, STRLEN, fp)) { + if ((fp = fopen(listfile, "r"))) { + while (fgets(genbuf, STRLEN, fp)) { strtok(genbuf, str_space); - if(!InNameList(genbuf)) { + if (!InNameList(genbuf)) { AddNameList(genbuf); (*reciper)++; } else { @@ -139,46 +157,52 @@ void ToggleNameList(int *reciper, char *listfile, char *msg) { } } -static int NumInList(word_t *list) { - register int i; +static int +NumInList(word_t * list) +{ + register int i; - for(i = 0; list; i++) + for (i = 0; list; i++) list = list->next; return i; } -int chkstr(char *otag, char *tag, char *name) { - char ch, *oname = name; +int +chkstr(char *otag, char *tag, char *name) +{ + char ch, *oname = name; - while(*tag) { + while (*tag) { ch = *name++; - if(*tag != chartoupper(ch)) + if (*tag != chartoupper(ch)) return 0; tag++; } - if(*tag && *name == '\0') + if (*tag && *name == '\0') strcpy(otag, oname); return 1; } -static word_t *GetSubList(char *tag, word_t *list) { - word_t *wlist, *wcurr; - char tagbuf[STRLEN]; - int n; +static word_t * +GetSubList(char *tag, word_t * list) +{ + word_t *wlist, *wcurr; + char tagbuf[STRLEN]; + int n; wlist = wcurr = NULL; - for(n = 0; tag[n]; n++) + for (n = 0; tag[n]; n++) tagbuf[n] = chartoupper(tag[n]); tagbuf[n] = '\0'; - while(list) { - if(chkstr(tag, tagbuf, list->word)) { + while (list) { + if (chkstr(tag, tagbuf, list->word)) { register word_t *node; - node = (word_t *)malloc(sizeof(word_t)); + node = (word_t *) malloc(sizeof(word_t)); node->word = list->word; node->next = NULL; - if(wlist) + if (wlist) wcurr->next = node; else wlist = node; @@ -189,22 +213,26 @@ static word_t *GetSubList(char *tag, word_t *list) { return wlist; } -static void ClearSubList(word_t *list) { - struct word_t *tmp_list; +static void +ClearSubList(word_t * list) +{ + struct word_t *tmp_list; - while(list) { + while (list) { tmp_list = list->next; free(list); list = tmp_list; } } -static int MaxLen(word_t *list, int count) { - int len = strlen(list->word); - int t; +static int +MaxLen(word_t * list, int count) +{ + int len = strlen(list->word); + int t; - while(list && count) { - if((t = strlen(list->word)) > len) + while (list && count) { + if ((t = strlen(list->word)) > len) len = t; list = list->next; count--; @@ -212,20 +240,22 @@ static int MaxLen(word_t *list, int count) { return len; } -void namecomplete(char *prompt, char *data) { - char *temp; - word_t *cwlist, *morelist; - int x, y, origx, origy; - int ch; - int count = 0; - int clearbot = NA; - - if(toplev == NULL) +void +namecomplete(char *prompt, char *data) +{ + char *temp; + word_t *cwlist, *morelist; + int x, y, origx, origy; + int ch; + int count = 0; + int clearbot = NA; + + if (toplev == NULL) AddNameList(""); cwlist = GetSubList("", toplev); morelist = NULL; temp = data; - + outs(prompt); clrtoeol(); getyx(&y, &x); @@ -235,20 +265,20 @@ void namecomplete(char *prompt, char *data) { standend(); move(y, x); refresh(); - - while((ch = igetch()) != EOF) { - if(ch == '\n' || ch == '\r') { + + while ((ch = igetch()) != EOF) { + if (ch == '\n' || ch == '\r') { *temp = '\0'; outc('\n'); - if(NumInList(cwlist) == 1) + if (NumInList(cwlist) == 1) strcpy(data, cwlist->word); ClearSubList(cwlist); break; } - if(ch == ' ') { - int col, len; - - if(NumInList(cwlist) == 1) { + if (ch == ' ') { + int col, len; + + if (NumInList(cwlist) == 1) { strcpy(data, cwlist->word); move(y, x); outs(data + count); @@ -259,34 +289,34 @@ void namecomplete(char *prompt, char *data) { } clearbot = YEA; col = 0; - if(!morelist) + if (!morelist) morelist = cwlist; len = MaxLen(morelist, p_lines); move(2, 0); clrtobot(); printdash("相關資訊一覽表"); - while(len + col < 80) { - int i; - - for(i = p_lines; (morelist) && (i > 0); i--) { + while (len + col < 80) { + int i; + + for (i = p_lines; (morelist) && (i > 0); i--) { move(3 + (p_lines - i), col); outs(morelist->word); morelist = morelist->next; } col += len + 2; - if(!morelist) + if (!morelist) break; len = MaxLen(morelist, p_lines); } - if(morelist) { + if (morelist) { move(b_lines, 0); outs(msg_more); } move(y, x); continue; } - if(ch == '\177' || ch == '\010') { - if(temp == data) + if (ch == '\177' || ch == '\010') { + if (temp == data) continue; temp--; count--; @@ -300,15 +330,14 @@ void namecomplete(char *prompt, char *data) { move(y, x); continue; } - - if(count < STRLEN && isprint(ch)) { - word_t *node; + if (count < STRLEN && isprint(ch)) { + word_t *node; *temp++ = ch; count++; *temp = '\0'; node = GetSubList(data, cwlist); - if(node == NULL) { + if (node == NULL) { temp--; *temp = '\0'; count--; @@ -322,33 +351,36 @@ void namecomplete(char *prompt, char *data) { x++; } } - if(ch == EOF) + if (ch == EOF) /* longjmp(byebye, -1); */ - raise(SIGHUP); /* jochang: don't know if this is necessary... */ + raise(SIGHUP); /* jochang: don't know if this is + * necessary... */ outc('\n'); refresh(); - if(clearbot) { + if (clearbot) { move(2, 0); clrtobot(); } - if(*data) { + if (*data) { move(origy, origx); outs(data); outc('\n'); } } -void usercomplete(char *prompt, char *data) { - char *temp; - char *cwbuf, *cwlist; - int cwnum, x, y, origx, origy; - int clearbot = NA, count = 0, morenum = 0; - char ch; +void +usercomplete(char *prompt, char *data) +{ + char *temp; + char *cwbuf, *cwlist; + int cwnum, x, y, origx, origy; + int clearbot = NA, count = 0, morenum = 0; + char ch; cwbuf = malloc(MAX_USERS * (IDLEN + 1)); - cwlist = u_namearray((arrptr)cwbuf, &cwnum, ""); + cwlist = u_namearray((arrptr) cwbuf, &cwnum, ""); temp = data; - + outs(prompt); clrtoeol(); getyx(&y, &x); @@ -357,24 +389,24 @@ void usercomplete(char *prompt, char *data) { prints("%*s", IDLEN + 1, ""); standend(); move(y, x); - while((ch = igetch()) != EOF) { - if(ch == '\n' || ch == '\r') { - int i; - char *ptr; - + while ((ch = igetch()) != EOF) { + if (ch == '\n' || ch == '\r') { + int i; + char *ptr; + *temp = '\0'; outc('\n'); ptr = (char *)cwlist; - for(i = 0; i < cwnum; i++) { - if(strncasecmp(data, ptr, IDLEN + 1) == 0) + for (i = 0; i < cwnum; i++) { + if (strncasecmp(data, ptr, IDLEN + 1) == 0) strcpy(data, ptr); ptr += IDLEN + 1; } break; - } else if(ch == ' ') { - int col, len; - - if(cwnum == 1) { + } else if (ch == ' ') { + int col, len; + + if (cwnum == 1) { strcpy(data, (char *)cwlist); move(y, x); outs(data + count); @@ -385,49 +417,49 @@ void usercomplete(char *prompt, char *data) { } clearbot = YEA; col = 0; - len = UserMaxLen((arrptr)cwlist, cwnum, morenum, p_lines); + len = UserMaxLen((arrptr) cwlist, cwnum, morenum, p_lines); move(2, 0); clrtobot(); printdash("使用者代號一覽表"); - while(len + col < 79) { - int i; - - for(i = 0; morenum < cwnum && i < p_lines; i++) { + while (len + col < 79) { + int i; + + for (i = 0; morenum < cwnum && i < p_lines; i++) { move(3 + i, col); prints("%s ", cwlist + (IDLEN + 1) * morenum++); } col += len + 2; - if(morenum >= cwnum) + if (morenum >= cwnum) break; - len = UserMaxLen((arrptr)cwlist, cwnum, morenum, p_lines); + len = UserMaxLen((arrptr) cwlist, cwnum, morenum, p_lines); } - if(morenum < cwnum) { + if (morenum < cwnum) { move(b_lines, 0); outs(msg_more); } else morenum = 0; move(y, x); continue; - } else if(ch == '\177' || ch == '\010') { - if(temp == data) + } else if (ch == '\177' || ch == '\010') { + if (temp == data) continue; temp--; count--; *temp = '\0'; - cwlist = u_namearray((arrptr)cwbuf, &cwnum, data); + cwlist = u_namearray((arrptr) cwbuf, &cwnum, data); morenum = 0; x--; move(y, x); outc(' '); move(y, x); continue; - } else if(count < STRLEN && isprint(ch)) { - int n; - + } else if (count < STRLEN && isprint(ch)) { + int n; + *temp++ = ch; *temp = '\0'; - n = UserSubArray((arrptr)cwbuf, (arrptr)cwlist, cwnum, ch, count); - if(n == 0) { + n = UserSubArray((arrptr) cwbuf, (arrptr) cwlist, cwnum, ch, count); + if (n == 0) { temp--; *temp = '\0'; continue; @@ -442,231 +474,218 @@ void usercomplete(char *prompt, char *data) { } } free(cwbuf); - if(ch == EOF) + if (ch == EOF) /* longjmp(byebye, -1); */ - raise(SIGHUP); /* jochang: don't know if this is necessary */ + raise(SIGHUP); /* jochang: don't know if this is necessary */ outc('\n'); refresh(); - if(clearbot) { + if (clearbot) { move(2, 0); clrtobot(); } - if(*data) { + if (*data) { move(origy, origx); outs(data); outc('\n'); } } -int gnc_findbound(char *str, int *START, int *END, - size_t nmemb, int (*compar)(int, char *, int)) +int +gnc_findbound(char *str, int *START, int *END, + size_t nmemb, int (*compar) (int, char *, int)) { - int start, end, mid, cmp, strl; + int start, end, mid, cmp, strl; strl = strlen(str); start = 0, end = nmemb - 1; - while( start != end && ((mid = (start + end) / 2) != start) ){ + while (start != end && ((mid = (start + end) / 2) != start)) { cmp = compar(mid, str, strl); //cmp = strncasecmp(brdshm->sorted[0][mid]->brdname, str, strl); - if( cmp >= 0 ) + if (cmp >= 0) end = mid; else start = mid; } ++start; - //if( strncasecmp(brdshm->sorted[0][start]->brdname, str, strl) != 0 ){ - if( compar(start, str, strl) != 0 ){ - *START = *END = -1; - return -1; - } - *START = start; - - end = nmemb - 1; - while( start != end && ((mid = (start + end) / 2) != start) ){ - cmp = compar(mid, str, strl); - //cmp = strncasecmp(brdshm->sorted[0][mid]->brdname, str, strl); - if( cmp <= 0 ) - start = mid; - else - end = mid; - } - *END = start; - return 0; -} - -int gnc_completeone(char *data, int start, int end, - int (*permission)(int), char* (*getname)(int)) -{ - int i, count, at; - if( start < 0 || end < 0 ) - return -1; - for( i = start, at = count = 0 ; i <= end && count < 2 ; ++i ) - if( permission(i) ){ - at = i; - ++count; + //if (strncasecmp(brdshm->sorted[0][start]->brdname, str, strl) != 0) { + if (compar(start, str, strl) != 0) { + *START = *END = -1; + return -1; } - if( count == 1 ){ - strcpy(data, getname(at)); - return at; + *START = start; + + end = nmemb - 1; + while (start != end && ((mid = (start + end) / 2) != start)) { + cmp = compar(mid, str, strl); + //cmp = strncasecmp(brdshm->sorted[0][mid]->brdname, str, strl); + if (cmp <= 0) + start = mid; + else + end = mid; + } + *END = start; + return 0; } - return -1; -} - - -int generalnamecomplete(char *prompt, char *data, int len, size_t nmemb, - int (*compar)(int, char *, int), - int (*permission)(int), char* (*getname)(int)) -{ - int x, y, origx, origy, ch, i, morelist = -1, col, ret = -1; - int start, end, ptr; - int clearbot = NA; - - outs(prompt); - clrtoeol(); - getyx(&y, &x); - getyx(&origy, &origx); - standout(); - prints("%*s", IDLEN + 1, ""); - standend(); - move(y, x); - refresh(); - ptr = 0; - data[ptr] = 0; - - while( (ch = igetch()) != EOF ){ - if( ch == '\n' || ch == '\r' ){ - data[ptr] = 0; - outc('\n'); - if( ptr != 0 ){ - gnc_findbound(data, &start, &end, nmemb, compar); - ret = gnc_completeone(data, start, end, permission, getname); + int gnc_completeone(char *data, int start, int end, + int (*permission) (int), char *(*getname) (int)){ + int i, count, at; + if (start < 0 || end < 0) + return -1; + for (i = start, at = count = 0; i <= end && count < 2; ++i) + if (permission(i)) { + at = i; + ++count; } - else - ptr = -1; - break; + if (count == 1) { + strcpy(data, getname(at)); + return at; } - else if( ch == ' ' ){ - if( ptr == 0 ) - continue; + return -1; + } - if( morelist == -1 ){ - if( gnc_findbound(data, &start, &end, nmemb, compar) == -1 ) - continue; - if( gnc_completeone(data, start, end, - permission, getname) >= 0 ){ - move(origy, origx); - outs(data); - ptr = strlen(data); - getyx(&y, &x); - continue; - } - morelist = start; - } - else if( morelist > end ) - continue; - clearbot = YEA; - move(2, 0); - clrtobot(); - printdash("相關資訊一覽表"); + int generalnamecomplete(char *prompt, char *data, int len, size_t nmemb, + int (*compar) (int, char *, int), + int (*permission) (int), char *(*getname) (int)){ + int x, y, origx, origy, ch, i, morelist = -1, col, + ret = -1; + int start, end, ptr; + int clearbot = NA; + + outs(prompt); + clrtoeol(); + getyx(&y, &x); + getyx(&origy, &origx); + standout(); + prints("%*s", IDLEN + 1, ""); + standend(); + move(y, x); + refresh(); + ptr = 0; + data[ptr] = 0; + + while ((ch = igetch()) != EOF) { + if (ch == '\n' || ch == '\r') { + data[ptr] = 0; + outc('\n'); + if (ptr != 0) { + gnc_findbound(data, &start, &end, nmemb, compar); + ret = gnc_completeone(data, start, end, permission, getname); + } else + ptr = -1; + break; + } else if (ch == ' ') { + if (ptr == 0) + continue; - col = 0; - while(len + col < 79) { - for( i = 0 ; morelist <= end && i < p_lines ; ++morelist){ - if( permission(morelist) ){ - move(3 + i, col); - prints("%s ", getname(morelist)); - ++i; + if (morelist == -1) { + if (gnc_findbound(data, &start, &end, nmemb, compar) == -1) + continue; + if (gnc_completeone(data, start, end, + permission, getname) >= 0) { + move(origy, origx); + outs(data); + ptr = strlen(data); + getyx(&y, &x); + continue; + } + morelist = start; + } else if (morelist > end) + continue; + clearbot = YEA; + move(2, 0); + clrtobot(); + printdash("相關資訊一覽表"); + + col = 0; + while (len + col < 79) { + for (i = 0; morelist <= end && i < p_lines; ++morelist) { + if (permission(morelist)) { + move(3 + i, col); + prints("%s ", getname(morelist)); + ++i; + } } - } - col += len + 2; - } - if( morelist != end + 1 ){ - move(b_lines, 0); - outs(msg_more); - } - move(y, x); - continue; + col += len + 2; + } + if (morelist != end + 1) { + move(b_lines, 0); + outs(msg_more); + } + move(y, x); + continue; - } - else if(ch == '\177' || ch == '\010') { /* backspace */ - if( ptr == 0 ) + } else if (ch == '\177' || ch == '\010') { /* backspace */ + if (ptr == 0) + continue; + morelist = -1; + --ptr; + --x; + data[ptr] = 0; + move(y, x); + outc(' '); + move(y, x); continue; - morelist = -1; - --ptr; --x; - data[ptr] = 0; - move(y, x); - outc(' '); - move(y, x); - continue; - } - else if( isprint(ch) && ptr <= (len - 2) ){ - morelist = -1; - data[ptr] = ch; - ++ptr; - data[ptr] = 0; - if( gnc_findbound(data, &start, &end, nmemb, compar) < 0 ) - data[--ptr] = 0; - else{ - for( i = start ; i <= end ; ++i ) - if( permission(i) ) - break; - if( i == end + 1 ) + } else if (isprint(ch) && ptr <= (len - 2)) { + morelist = -1; + data[ptr] = ch; + ++ptr; + data[ptr] = 0; + if (gnc_findbound(data, &start, &end, nmemb, compar) < 0) data[--ptr] = 0; - else{ - move(y, x); - outc(ch); - x++; + else { + for (i = start; i <= end; ++i) + if (permission(i)) + break; + if (i == end + 1) + data[--ptr] = 0; + else { + move(y, x); + outc(ch); + x++; + } } } } - } - outc('\n'); - refresh(); - if(clearbot) { - move(2, 0); - clrtobot(); - } - if(*data) { - move(origy, origx); - outs(data); outc('\n'); + refresh(); + if (clearbot) { + move(2, 0); + clrtobot(); + } + if (*data) { + move(origy, origx); + outs(data); + outc('\n'); + } + return ret; } - return ret; -} - -/* general complete functions (brdshm) */ -int completeboard_compar(int where, char *str, int len) -{ - return strncasecmp(SHM->bsorted[0][where]->brdname, str, len); -} -int completeboard_permission(int where) -{ - return Ben_Perm(SHM->bsorted[0][where]); -} + /* general complete functions (brdshm) */ + int completeboard_compar(int where, char *str, int len){ + return strncasecmp(SHM->bsorted[0][where]->brdname, str, len); + } -char *completeboard_getname(int where) -{ - return SHM->bsorted[0][where]->brdname; -} + int completeboard_permission(int where){ + return Ben_Perm(SHM->bsorted[0][where]); + } -/* general complete functions (utmpshm) */ -int completeutmp_compar(int where, char *str, int len) -{ - return strncasecmp(SHM->sorted[SHM->currsorted][0][where]->userid, - str, len); -} + char *completeboard_getname(int where){ + return SHM->bsorted[0][where]->brdname; + } -int completeutmp_permission(int where) -{ - return (HAS_PERM(PERM_SYSOP) || HAS_PERM(PERM_SEECLOAK) || - !SHM->sorted[SHM->currsorted][0][where]->invisible); -} + /* general complete functions (utmpshm) */ + int completeutmp_compar(int where, char *str, int len){ + return strncasecmp(SHM->sorted[SHM->currsorted][0][where]->userid, + str, len); + } -char *completeutmp_getname(int where) -{ - return SHM->sorted[SHM->currsorted][0][where]->userid; -} + int completeutmp_permission(int where){ + return (HAS_PERM(PERM_SYSOP) || HAS_PERM(PERM_SEECLOAK) || + !SHM->sorted[SHM->currsorted][0][where]->invisible); + } + char *completeutmp_getname(int where){ + return SHM->sorted[SHM->currsorted][0][where]->userid; + } diff --git a/pttbbs/mbbsd/osdep.c b/pttbbs/mbbsd/osdep.c index 315cdb51..d99395c7 100644 --- a/pttbbs/mbbsd/osdep.c +++ b/pttbbs/mbbsd/osdep.c @@ -1,17 +1,19 @@ -/* $Id: osdep.c,v 1.3 2002/06/04 13:08:34 in2 Exp $ */ +/* $Id: osdep.c,v 1.4 2002/07/05 17:10:27 in2 Exp $ */ #include "bbs.h" -#if __FreeBSD__ +#if __FreeBSD__ #include <kvm.h> -int cpuload(char *str) { - double l[3] = {-1, -1, -1}; - if(getloadavg(l, 3) != 3) +int +cpuload(char *str) +{ + double l[3] = {-1, -1, -1}; + if (getloadavg(l, 3) != 3) l[0] = -1; - - if(str) { - if(l[0] != -1) + + if (str) { + if (l[0] != -1) sprintf(str, " %.2f %.2f %.2f", l[0], l[1], l[2]); else strcpy(str, " (unknown) "); @@ -19,19 +21,21 @@ int cpuload(char *str) { return (int)l[0]; } -double swapused(long *total, long *used) { - double percent = -1; - kvm_t *kd; +double +swapused(long *total, long *used) +{ + double percent = -1; + kvm_t *kd; struct kvm_swap swapinfo; - int pagesize; - + int pagesize; + kd = kvm_open(NULL, NULL, NULL, O_RDONLY, NULL); - if(kd) { - if(kvm_getswapinfo(kd, &swapinfo, 1, 0) == 0) { + if (kd) { + if (kvm_getswapinfo(kd, &swapinfo, 1, 0) == 0) { pagesize = getpagesize(); *total = swapinfo.ksw_total * pagesize; *used = swapinfo.ksw_used * pagesize; - if(*total != 0) + if (*total != 0) percent = (double)*used / (double)*total; } kvm_close(kd); @@ -40,17 +44,19 @@ double swapused(long *total, long *used) { } #else -int cpuload(char *str) { - double l[3] = {-1, -1, -1}; - FILE *fp; - - if((fp = fopen("/proc/loadavg", "r"))) { - if(fscanf(fp, "%lf %lf %lf", &l[0], &l[1], &l[2]) != 3) +int +cpuload(char *str) +{ + double l[3] = {-1, -1, -1}; + FILE *fp; + + if ((fp = fopen("/proc/loadavg", "r"))) { + if (fscanf(fp, "%lf %lf %lf", &l[0], &l[1], &l[2]) != 3) l[0] = -1; fclose(fp); } - if(str) { - if(l[0] != -1) + if (str) { + if (l[0] != -1) sprintf(str, " %.2f %.2f %.2f", l[0], l[1], l[2]); else strcpy(str, " (unknown) "); @@ -58,15 +64,17 @@ int cpuload(char *str) { return (int)l[0]; } -double swapused(long *total, long *used) { - double percent = -1; - char buf[101]; - FILE *fp; - - if((fp = fopen("/proc/meminfo","r"))) { - while(fgets(buf, 100, fp) && buf[0] != 'S'); - if(sscanf(buf + 6, "%ld %ld", total, used) == 2) - if(*total != 0) +double +swapused(long *total, long *used) +{ + double percent = -1; + char buf[101]; + FILE *fp; + + if ((fp = fopen("/proc/meminfo", "r"))) { + while (fgets(buf, 100, fp) && buf[0] != 'S'); + if (sscanf(buf + 6, "%ld %ld", total, used) == 2) + if (*total != 0) percent = (double)*used / (double)*total; fclose(fp); } diff --git a/pttbbs/mbbsd/othello.c b/pttbbs/mbbsd/othello.c index 4a146f77..76cd2f8c 100644 --- a/pttbbs/mbbsd/othello.c +++ b/pttbbs/mbbsd/othello.c @@ -1,4 +1,4 @@ -/* $Id: othello.c,v 1.3 2002/06/04 13:08:34 in2 Exp $ */ +/* $Id: othello.c,v 1.4 2002/07/05 17:10:27 in2 Exp $ */ #include "bbs.h" #define LOGFILE "etc/othello.log" @@ -20,67 +20,71 @@ #define INVERT(COLOR) (((COLOR))==WHITE?BLACK:WHITE) -static char nowx = 3, nowy = 3; -static char *CHESS_TYPE[] = {NONE_CHESS, HINT_CHESS, BLACK_CHESS, WHITE_CHESS}; -static char DIRX[] = {-1,-1,-1, 0, 1, 1, 1, 0}; -static char DIRY[] = {-1, 0, 1, 1, 1, 0,-1,-1}; -static char number[2]; - -static char pass = 0; -static char if_hint = 0; -static int think, which_table; - -static char nowboard[10][10]= -{{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, - {-1, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, -1}, - {-1, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, -1}, - {-1, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, -1}, - {-1, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, -1}, - {-1, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, -1}, - {-1, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, -1}, - {-1, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, -1}, - {-1, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, -1}, - {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1}}; -static char init_table[NR_TABLE+1][5][5] = { - {{ 0, 0, 0, 0, 0}, - { 0,30,-3, 2, 2}, - { 0,-3,-3,-1,-1}, - { 0, 2,-1, 1, 1}, - { 0, 2,-1, 1, 0}}, - - {{ 0, 0, 0, 0, 0}, - { 0,70, 5,20,30}, - { 0, 5,-5, 3, 3}, - { 0,20, 3, 5, 5}, - { 0,30, 3, 5, 5}}, - - {{ 0, 0, 0, 0, 0}, - { 0, 5, 2, 2, 2}, - { 0, 2, 1, 1, 1}, - { 0, 2, 1, 1, 1}, - { 0, 2, 1, 1, 1}} +static char nowx = 3, nowy = 3; +static char *CHESS_TYPE[] = {NONE_CHESS, HINT_CHESS, BLACK_CHESS, WHITE_CHESS}; +static char DIRX[] = {-1, -1, -1, 0, 1, 1, 1, 0}; +static char DIRY[] = {-1, 0, 1, 1, 1, 0, -1, -1}; +static char number[2]; + +static char pass = 0; +static char if_hint = 0; +static int think, which_table; + +static char nowboard[10][10] = +{{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, +{-1, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, -1}, +{-1, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, -1}, +{-1, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, -1}, +{-1, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, -1}, +{-1, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, -1}, +{-1, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, -1}, +{-1, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, -1}, +{-1, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, -1}, +{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1}}; +static char init_table[NR_TABLE + 1][5][5] = { + {{0, 0, 0, 0, 0}, + {0, 30, -3, 2, 2}, + {0, -3, -3, -1, -1}, + {0, 2, -1, 1, 1}, + {0, 2, -1, 1, 0}}, + + {{0, 0, 0, 0, 0}, + {0, 70, 5, 20, 30}, + {0, 5, -5, 3, 3}, + {0, 20, 3, 5, 5}, + {0, 30, 3, 5, 5}}, + + {{0, 0, 0, 0, 0}, + {0, 5, 2, 2, 2}, + {0, 2, 1, 1, 1}, + {0, 2, 1, 1, 1}, + {0, 2, 1, 1, 1}} }; -static char table[NR_TABLE + 1][10][10]; -static void print_chess(int x, int y, char chess) { +static char table[NR_TABLE + 1][10][10]; +static void +print_chess(int x, int y, char chess) +{ move(STARTX - 1 + x * 2, STARTY - 2 + y * 4); - if(chess != HINT || if_hint == 1) + if (chess != HINT || if_hint == 1) prints(CHESS_TYPE[(int)chess]); else prints(CHESS_TYPE[NONE]); refresh(); } -static void printboard() { - int i; - +static void +printboard() +{ + int i; + move(STARTX, STARTY); prints("┌─┬─┬─┬─┬─┬─┬─┬─┐"); - for(i = 0; i < 7; i++) { + for (i = 0; i < 7; i++) { move(STARTX + 1 + i * 2, STARTY); - prints ("│ │ │ │ │ │ │ │ │"); + prints("│ │ │ │ │ │ │ │ │"); move(STARTX + 2 + i * 2, STARTY); - prints ("├─┼─┼─┼─┼─┼─┼─┼─┤"); + prints("├─┼─┼─┼─┼─┼─┼─┼─┤"); } move(STARTX + 1 + i * 2, STARTY); prints("│ │ │ │ │ │ │ │ │"); @@ -91,7 +95,7 @@ static void printboard() { print_chess(4, 5, BLACK); print_chess(5, 4, BLACK); move(3, 56); - prints("(黑)%s",cuser.userid); + prints("(黑)%s", cuser.userid); move(3, 72); prints(": 02"); move(4, 56); @@ -102,7 +106,7 @@ static void printboard() { prints("[q] 退出"); move(8, 56); prints("[h] 開啟/關閉 提示"); - move(9,56); + move(9, 56); prints("[Enter][Space] 下棋"); move(10, 56); prints("上:↑, i"); @@ -114,39 +118,43 @@ static void printboard() { prints("右:→, l"); } -static int get_key(char nowx, char nowy) { - int ch; - +static int +get_key(char nowx, char nowy) +{ + int ch; + move(STARTX - 1 + nowx * 2, STARTY - 1 + nowy * 4); ch = igetkey(); move(STARTX - 1 + nowx * 2, STARTY - 2 + nowy * 4); - if(nowboard[(int)nowx][(int)nowy] != HINT || if_hint==1) + if (nowboard[(int)nowx][(int)nowy] != HINT || if_hint == 1) outs(CHESS_TYPE[(int)nowboard[(int)nowx][(int)nowy]]); else outs(CHESS_TYPE[NONE]); return ch; } -static int eatline(int i, int j, char color, int dir, char chessboard[][10]) { - int tmpx,tmpy; - char tmpchess; - +static int +eatline(int i, int j, char color, int dir, char chessboard[][10]) +{ + int tmpx, tmpy; + char tmpchess; + tmpx = i + DIRX[dir]; tmpy = j + DIRY[dir]; tmpchess = chessboard[tmpx][tmpy]; - if(tmpchess == -1) + if (tmpchess == -1) return false; - if(tmpchess != INVERT(color)) + if (tmpchess != INVERT(color)) return false; - + tmpx += DIRX[dir]; tmpy += DIRY[dir]; tmpchess = chessboard[tmpx][tmpy]; - while(tmpchess != -1) { - if(tmpchess < BLACK) + while (tmpchess != -1) { + if (tmpchess < BLACK) return false; - if(tmpchess == color) { - while(i != tmpx || j != tmpy) { + if (tmpchess == color) { + while (i != tmpx || j != tmpy) { chessboard[i][j] = color; i += DIRX[dir]; j += DIRY[dir]; @@ -160,32 +168,36 @@ static int eatline(int i, int j, char color, int dir, char chessboard[][10]) { return false; } -static int if_can_put(int x, int y, char color, char chessboard[][10]) { - int i, temp, checkx, checky; - - if(chessboard[x][y]<BLACK) - for(i = 0; i < 8; i++) { +static int +if_can_put(int x, int y, char color, char chessboard[][10]) +{ + int i, temp, checkx, checky; + + if (chessboard[x][y] < BLACK) + for (i = 0; i < 8; i++) { checkx = x + DIRX[i]; checky = y + DIRY[i]; temp = chessboard[checkx][checky]; - if(temp < BLACK) + if (temp < BLACK) continue; - if(temp != color) - while(chessboard[checkx += DIRX[i]][checky += DIRY[i]] > HINT) - if(chessboard[checkx][checky] == color) + if (temp != color) + while (chessboard[checkx += DIRX[i]][checky += DIRY[i]] > HINT) + if (chessboard[checkx][checky] == color) return true; } return false; } -static int get_hint(char color) { - int i, j, temp = 0; - - for(i = 1; i <= 8; i++) - for(j = 1; j <= 8; j++) { - if(nowboard[i][j] == HINT) +static int +get_hint(char color) +{ + int i, j, temp = 0; + + for (i = 1; i <= 8; i++) + for (j = 1; j <= 8; j++) { + if (nowboard[i][j] == HINT) nowboard[i][j] = NONE; - if(if_can_put(i, j, color, nowboard)) { + if (if_can_put(i, j, color, nowboard)) { nowboard[i][j] = HINT; temp++; } @@ -194,89 +206,96 @@ static int get_hint(char color) { return temp; } -static void eat(int x, int y, int color, char chessboard[][10]) { - int k; - - for(k = 0; k < 8; k++) +static void +eat(int x, int y, int color, char chessboard[][10]) +{ + int k; + + for (k = 0; k < 8; k++) eatline(x, y, color, k, chessboard); } -static void end_of_game(int quit) { - FILE *fp,*fp1; - char *opponent[] = {"","CD-65","","嬰兒","小孩","","大人","專家"}; - +static void +end_of_game(int quit) +{ + FILE *fp, *fp1; + char *opponent[] = {"", "CD-65", "", "嬰兒", "小孩", "", "大人", "專家"}; + move(STARTX - 1, 30); - prints (" "); + prints(" "); move(22, 35); fp = fopen(LOGFILE, "a"); - if(!quit) { + if (!quit) { fp1 = fopen(SECRET, "a"); - if(fp1) { + if (fp1) { fprintf(fp1, "%d,%d,%s,%02d,%02d\n", think, which_table, - cuser.userid, number[0], number[1]); + cuser.userid, number[0], number[1]); fclose(fp1); } } - - if(quit) { - if(number[0] == 2 && number[1] == 2) { - if(fp) + if (quit) { + if (number[0] == 2 && number[1] == 2) { + if (fp) fclose(fp); return; } fprintf(fp, "在%s級中, %s臨陣脫逃\n", opponent[think], cuser.userid); - if(fp) - fclose(fp); + if (fp) + fclose(fp); return; - } - if(number[0] > number[1]) { + } + if (number[0] > number[1]) { prints("你贏了電腦%02d子", number[0] - number[1]); - if(think == 6 && number[0] - number[1] >= 50) + if (think == 6 && number[0] - number[1] >= 50) demoney(200); - if(think == 7 && number[0] - number[1] >= 40) + if (think == 7 && number[0] - number[1] >= 40) demoney(200); - if(fp) + if (fp) fprintf(fp, "在%s級中, %s以 %02d:%02d 贏了電腦%02d子\n", opponent[think], cuser.userid, number[0], number[1], number[0] - number[1]); - } else if(number[1] > number[0]) { + } else if (number[1] > number[0]) { prints("電腦贏了你%02d子", number[1] - number[0]); - if(fp) { + if (fp) { fprintf(fp, "在%s級中, ", opponent[think]); - if(number[1] - number[0] > 20) + if (number[1] - number[0] > 20) fprintf(fp, "電腦以 %02d:%02d 慘電%s %02d子\n", number[1], number[0], cuser.userid, number[1] - number[0]); else fprintf(fp, "電腦以 %02d:%02d 贏了%s %02d子\n", number[1], number[0], cuser.userid, number[1] - number[0]); - } + } } else { prints("你和電腦打成平手!!"); - if(fp) + if (fp) fprintf(fp, "在%s級中, %s和電腦以 %02d:%02d 打成了平手\n", opponent[think], cuser.userid, number[1], number[0]); } - if(fp) + if (fp) fclose(fp); - move(1,1); + move(1, 1); igetkey(); } -static void othello_redraw() { - int i, j; - - for(i = 1; i <= 8; i++) - for(j = 1; j <= 8; j++) +static void +othello_redraw() +{ + int i, j; + + for (i = 1; i <= 8; i++) + for (j = 1; j <= 8; j++) print_chess(i, j, nowboard[i][j]); } -static int player(char color) { - int ch; - - if(get_hint(color)) { - while(true) { - ch = get_key(nowx,nowy); - switch(ch) { +static int +player(char color) +{ + int ch; + + if (get_hint(color)) { + while (true) { + ch = get_key(nowx, nowy); + switch (ch) { case 'J': case 'j': case KEY_LEFT: @@ -296,10 +315,10 @@ static int player(char color) { case 'k': case KEY_DOWN: nowx++; - break; + break; case ' ': case '\r': - if(nowboard[(int)nowx][(int)nowy] != HINT) + if (nowboard[(int)nowx][(int)nowy] != HINT) break; pass = 0; nowboard[(int)nowx][(int)nowy] = color; @@ -311,26 +330,26 @@ static int player(char color) { return false; case 'H': case 'h': - if_hint = if_hint^1; + if_hint = if_hint ^ 1; othello_redraw(); break; } - if(nowx == 9) - nowx=1; - if(nowx == 0) - nowx=8; - if(nowy == 9) - nowy=1; - if(nowy == 0) - nowy=8; + if (nowx == 9) + nowx = 1; + if (nowx == 0) + nowx = 8; + if (nowy == 9) + nowy = 1; + if (nowy == 0) + nowy = 8; } } else { pass++; - if(pass == 1) { + if (pass == 1) { move(23, 34); prints("你必需放棄這一步!!"); igetch(); - move(28,23); + move(28, 23); prints(" "); } else { end_of_game(0); @@ -340,35 +359,39 @@ static int player(char color) { return 0; } -static void init() { - int i, j, i1, j1; - +static void +init() +{ + int i, j, i1, j1; + nowx = 4; nowy = 4; number[0] = number[1] = 2; - for(i = 1; i <= 8; i++) - for(j = 1;j <= 8; j++) { + for (i = 1; i <= 8; i++) + for (j = 1; j <= 8; j++) { i1 = 4.5 - abs(4.5 - i); j1 = 4.5 - abs(4.5 - j); table[0][i][j] = init_table[0][i1][j1]; table[1][i][j] = init_table[1][i1][j1]; } - for(i = 1; i <= 8; i++) - for(j = 1; j <= 8; j++) + for (i = 1; i <= 8; i++) + for (j = 1; j <= 8; j++) nowboard[i][j] = NONE; nowboard[4][4] = nowboard[5][5] = WHITE; nowboard[4][5] = nowboard[5][4] = BLACK; } -static void report() { - int i, j; - +static void +report() +{ + int i, j; + number[0] = number[1] = 0; - for(i = 1; i <= 8; i++) - for(j = 1; j <= 8; j++) - if(nowboard[i][j] == BLACK) + for (i = 1; i <= 8; i++) + for (j = 1; j <= 8; j++) + if (nowboard[i][j] == BLACK) number[0]++; - else if(nowboard[i][j] == WHITE) + else if (nowboard[i][j] == WHITE) number[1]++; move(3, 60); prints("%s", cuser.userid); @@ -378,12 +401,14 @@ static void report() { prints("電腦 : %02d", number[1]); } -static int EVL(char chessboard[][10], int color, int table_number) { - int points = 0,a,b; - for(a = 1; a <= 8; a++) - for(b = 1; b <= 8; b++) - if(chessboard[a][b] > HINT) { - if(chessboard[a][b] == BLACK) +static int +EVL(char chessboard[][10], int color, int table_number) +{ + int points = 0, a, b; + for (a = 1; a <= 8; a++) + for (b = 1; b <= 8; b++) + if (chessboard[a][b] > HINT) { + if (chessboard[a][b] == BLACK) points += table[table_number][a][b]; else points -= table[table_number][a][b]; @@ -391,57 +416,61 @@ static int EVL(char chessboard[][10], int color, int table_number) { return ((color == BLACK) ? points : -points); } -static int alphabeta(int alpha, int beta, int level, char chessboard[][10], - int thinkstep, int color, int table) { - int i, j, k, flag = 1; - char tempboard[10][10]; - if(level == thinkstep+1) +static int +alphabeta(int alpha, int beta, int level, char chessboard[][10], + int thinkstep, int color, int table) +{ + int i, j, k, flag = 1; + char tempboard[10][10]; + if (level == thinkstep + 1) return EVL(chessboard, (level & 1 ? color : ((color - 2) ^ 1) + 2), table); - for(i = 1; i <= 8; i++) { - for(j = 1; j <= 8; j++) { - if(if_can_put(i, j, color, chessboard)) { + for (i = 1; i <= 8; i++) { + for (j = 1; j <= 8; j++) { + if (if_can_put(i, j, color, chessboard)) { flag = 0; memcpy(tempboard, chessboard, sizeof(char) * 100); eat(i, j, color, tempboard); - + k = alphabeta(alpha, beta, level + 1, tempboard, thinkstep, ((color - 2) ^ 1) + 2, table); - if(((level & 1) && k > alpha)) + if (((level & 1) && k > alpha)) alpha = k; - else if(!(level & 1) && k < beta) + else if (!(level & 1) && k < beta) beta = k; - if(alpha >= beta) + if (alpha >= beta) break; } } } - if(flag) + if (flag) return EVL(chessboard, color, table); return ((level & 1) ? alpha : beta); } -static int Computer(int thinkstep, int table) { - int i, j, maxi = 0, maxj = 0, level = 1; - char chessboard[10][10]; - int alpha = -10000, k; - if((number[0] + number[1]) > 44) +static int +Computer(int thinkstep, int table) +{ + int i, j, maxi = 0, maxj = 0, level = 1; + char chessboard[10][10]; + int alpha = -10000, k; + if ((number[0] + number[1]) > 44) table = NR_TABLE; - for(i = 1; i <= 8; i++) - for(j = 1; j <= 8; j++) { - if(if_can_put(i,j,WHITE,nowboard)) { + for (i = 1; i <= 8; i++) + for (j = 1; j <= 8; j++) { + if (if_can_put(i, j, WHITE, nowboard)) { memcpy(chessboard, nowboard, sizeof(char) * 100); eat(i, j, WHITE, chessboard); k = alphabeta(alpha, 10000, level + 1, chessboard, thinkstep, BLACK, table); - if(k > alpha) { + if (k > alpha) { alpha = k; maxi = i; maxj = j; } } } - if(alpha != -10000) { + if (alpha != -10000) { eat(maxi, maxj, WHITE, nowboard); pass = 0; nowx = maxi; @@ -450,7 +479,7 @@ static int Computer(int thinkstep, int table) { move(23, 30); prints("電腦放棄這一步棋!!"); pass++; - if(pass == 2) { + if (pass == 2) { move(23, 24); prints(" "); end_of_game(0); @@ -458,26 +487,28 @@ static int Computer(int thinkstep, int table) { } igetch(); move(23, 24); - prints(" "); + prints(" "); } return true; } -static int choose() { - char thinkstep[2]; - +static int +choose() +{ + char thinkstep[2]; + move(2, 0); prints("請選擇難度:"); move(5, 0); - prints("(1) CD-65\n"); /* 想 1 步 */ - prints("(2) 嬰兒\n"); /* 想 3 步 */ - prints("(3) 小孩\n"); /* 想 4 步 */ + prints("(1) CD-65\n"); /* 想 1 步 */ + prints("(2) 嬰兒\n"); /* 想 3 步 */ + prints("(3) 小孩\n"); /* 想 4 步 */ do { getdata(4, 0, "請選擇一個對象和您對打:(1~5)", thinkstep, sizeof(thinkstep), LCECHO); - } while(thinkstep[0] < '1' || thinkstep[0] > '3'); + } while (thinkstep[0] < '1' || thinkstep[0] > '3'); clear(); - switch(thinkstep[0]) { + switch (thinkstep[0]) { case '2': thinkstep[0] = '3'; break; @@ -493,33 +524,35 @@ static int choose() { #define lockreturn0(unmode, state) if(lockutmpmode(unmode, state)) return 0 -int othello_main() { +int +othello_main() +{ lockreturn0(OTHELLO, LOCK_MULTI); clear(); init(); think = choose(); - showtitle("黑白棋", BBSName); + showtitle("黑白棋", BBSName); printboard(); which_table = rand() % NR_TABLE; - while(true) { + while (true) { move(STARTX - 1, 30); prints("輪到你下了..."); - if(!player(BLACK)) + if (!player(BLACK)) break; report(); othello_redraw(); - if(number[0] + number[1] == 64) { + if (number[0] + number[1] == 64) { end_of_game(0); break; } move(STARTX - 1, 30); prints("電腦思考中..."); refresh(); - if(!Computer(think, which_table)) + if (!Computer(think, which_table)) break; report(); othello_redraw(); - if(number[0] + number[1] == 64) { + if (number[0] + number[1] == 64) { end_of_game(0); break; } diff --git a/pttbbs/mbbsd/page.c b/pttbbs/mbbsd/page.c index b39f7d7e..6e8489e2 100644 --- a/pttbbs/mbbsd/page.c +++ b/pttbbs/mbbsd/page.c @@ -1,19 +1,21 @@ -/* $Id: page.c,v 1.5 2002/06/04 13:08:34 in2 Exp $ */ +/* $Id: page.c,v 1.6 2002/07/05 17:10:27 in2 Exp $ */ #include "bbs.h" -#define hpressanykey(a) {move(22, 0); prints(a); pressanykey();} -static void filt_railway(char* fpath) { - char buf[256], tmppath[32]; - FILE* fp = fopen(fpath, "w"), *tp; +#define hpressanykey(a) {move(22, 0); prints(a); pressanykey();} +static void +filt_railway(char *fpath) +{ + char buf[256], tmppath[32]; + FILE *fp = fopen(fpath, "w"), *tp; sprintf(tmppath, "%s.railway", fpath); - if(!fp || !(tp = fopen(tmppath, "r"))) + if (!fp || !(tp = fopen(tmppath, "r"))) return; - while(fgets(buf, 255, tp)) { - if(strstr(buf, "INLINE")) + while (fgets(buf, 255, tp)) { + if (strstr(buf, "INLINE")) continue; - if(strstr(buf, "LINK")) + if (strstr(buf, "LINK")) break; fprintf(fp, "%s", buf); } @@ -22,13 +24,15 @@ static void filt_railway(char* fpath) { unlink(tmppath); } -int main_railway() { - fileheader_t mhdr; - char genbuf[200]; - int from, to, time_go, time_reach; - char tt[2], type[2]; - char command[256], buf[8]; - char *addr[]= { +int +main_railway() +{ + fileheader_t mhdr; + char genbuf[200]; + int from, to, time_go, time_reach; + char tt[2], type[2]; + char command[256], buf[8]; + char *addr[] = { "基隆", "八堵", "七堵", "五堵", "汐止", "南港", "松山", "台北", "萬華", "板橋", "樹林", "山佳", "鶯歌", "桃園", "內壢", "中壢", "埔心", "楊梅", "湖口", "新豐", "竹北", "新竹", "香山", "崎頂", "竹南", "造橋", "豐富", @@ -37,81 +41,81 @@ int main_railway() { "苗栗", "南勢", "銅鑼", "三義", "勝興", "泰安", "后里", "豐原", "潭子", "台中", "烏日", "成功\", "彰化", "花壇", "員林", "永靖", "社頭", "田中", "二水", "林內", "石榴", "斗六", "斗南", "石龜", "大林", - "民雄", "嘉義", "水上", "南靖", "後壁", "新營", "柳營", "林鳳營", - "隆田", "拔林", "善化", "新市", "永康", "台南", "保安", "中洲", - "大湖", "路竹", "岡山", "橋頭", "楠梓", "左營", "高雄", "鳳山", + "民雄", "嘉義", "水上", "南靖", "後壁", "新營", "柳營", "林鳳營", + "隆田", "拔林", "善化", "新市", "永康", "台南", "保安", "中洲", + "大湖", "路竹", "岡山", "橋頭", "楠梓", "左營", "高雄", "鳳山", "九曲堂", "屏東", NULL, NULL }; - + setutmpmode(RAIL_WAY); clear(); - move(0,25); + move(0, 25); prints("\033[1;37;45m 火車查詢系統 \033[1;44;33m作者:Heat\033[m"); - move(1,0); + move(1, 0); outs("\033[1;33m\n" -" 1.基隆 16.中壢 31.龍港 46.銅鑼 61.田中 76.林鳳營 91.高雄\n" -" 2.八堵 17.埔心 32.白沙屯 47.三義 62.二水 77.隆田 92.鳳山\n" -" 3.七堵 18.楊梅 33.新埔 48.勝興 63.林內 78.拔林 93.九曲堂\n" -" 4.五堵 19.湖口 34.通霄 49.泰安 64.石榴 79.善化 94.屏東\n" -" 5.汐止 20.新豐 35.苑裡 50.后里 65.斗六 80.新市\n" -" 6.南港 21.竹北 36.日南 51.豐原 66.斗南 81.永康\n" -" 7.松山 22.新竹 37.大甲 52.潭子 67.石龜 82.台南\n" -" 8.台北 23.香山 38.臺中港 53.台中 68.大林 83.保安\n" -" 9.萬華 24.崎頂 39.清水 54.烏日 69.民雄 84.中洲\n" -"10.板橋 25.竹南 40.沙鹿 55.成功\ 70.嘉義 85.大湖\n" -"11.樹林 26.造橋 41.龍井 56.彰化 71.水上 86.路竹\n" -"12.山佳 27.豐富 42.大肚 57.花壇 72.南靖 87.岡山\n" -"13.鶯歌 28.談文 43.追分 58.員林 73.後壁 88.橋頭\n" -"14.桃園 29.大山 44.苗栗 59.永靖 74.新營 89.楠梓\n" -"15.內壢 30.後龍 45.南勢 60.社頭 75.柳營 90.左營\033[m"); + " 1.基隆 16.中壢 31.龍港 46.銅鑼 61.田中 76.林鳳營 91.高雄\n" + " 2.八堵 17.埔心 32.白沙屯 47.三義 62.二水 77.隆田 92.鳳山\n" + " 3.七堵 18.楊梅 33.新埔 48.勝興 63.林內 78.拔林 93.九曲堂\n" + " 4.五堵 19.湖口 34.通霄 49.泰安 64.石榴 79.善化 94.屏東\n" + " 5.汐止 20.新豐 35.苑裡 50.后里 65.斗六 80.新市\n" + " 6.南港 21.竹北 36.日南 51.豐原 66.斗南 81.永康\n" + " 7.松山 22.新竹 37.大甲 52.潭子 67.石龜 82.台南\n" + " 8.台北 23.香山 38.臺中港 53.台中 68.大林 83.保安\n" + " 9.萬華 24.崎頂 39.清水 54.烏日 69.民雄 84.中洲\n" + "10.板橋 25.竹南 40.沙鹿 55.成功\ 70.嘉義 85.大湖\n" + "11.樹林 26.造橋 41.龍井 56.彰化 71.水上 86.路竹\n" + "12.山佳 27.豐富 42.大肚 57.花壇 72.南靖 87.岡山\n" + "13.鶯歌 28.談文 43.追分 58.員林 73.後壁 88.橋頭\n" + "14.桃園 29.大山 44.苗栗 59.永靖 74.新營 89.楠梓\n" + "15.內壢 30.後龍 45.南勢 60.社頭 75.柳營 90.左營\033[m"); getdata(17, 0, "\033[1;35m你確定要搜尋嗎?[y/n]:\033[m", buf, 2, LCECHO); - if(buf[0] != 'y' && buf[0] != 'Y') + if (buf[0] != 'y' && buf[0] != 'Y') return 0; - while(1) - if(getdata(18, 0, "\033[1;35m請輸入起站(1-94):\033[m", buf, 3, LCECHO) && - (from = atoi(buf)) >= 1 && from <= 94) + while (1) + if (getdata(18, 0, "\033[1;35m請輸入起站(1-94):\033[m", buf, 3, LCECHO) && + (from = atoi(buf)) >= 1 && from <= 94) break; - while(1) - if(getdata(18, 40, "\033[1;35m請輸入目的地(1-94):\033[m", - buf, 3, LCECHO) && - (to = atoi(buf)) >= 1 && to <= 94) + while (1) + if (getdata(18, 40, "\033[1;35m請輸入目的地(1-94):\033[m", + buf, 3, LCECHO) && + (to = atoi(buf)) >= 1 && to <= 94) break; - while(1) - if(getdata(19, 0, "\033[1;35m請輸入時間區段(0-23) 由:\033[m", - buf,3,LCECHO) && - (time_go = atoi(buf)) >= 0 && time_go <= 23) + while (1) + if (getdata(19, 0, "\033[1;35m請輸入時間區段(0-23) 由:\033[m", + buf, 3, LCECHO) && + (time_go = atoi(buf)) >= 0 && time_go <= 23) break; - while(1) - if(getdata(19, 40, "\033[1;35m到:\033[m", buf, 3, LCECHO) && - (time_reach=atoi(buf)) >= 0 && time_reach <= 23) + while (1) + if (getdata(19, 40, "\033[1;35m到:\033[m", buf, 3, LCECHO) && + (time_reach = atoi(buf)) >= 0 && time_reach <= 23) break; - while(1) - if(getdata(20, 0, "\033[1;35m想查詢 1:對號快車 2:普通平快\033[m", - type,2,LCECHO) && (type[0] == '1' || type[0] == '2')) + while (1) + if (getdata(20, 0, "\033[1;35m想查詢 1:對號快車 2:普通平快\033[m", + type, 2, LCECHO) && (type[0] == '1' || type[0] == '2')) break; - while(1) - if(getdata(21, 0, "\033[1;35m欲查詢 1:出發時間 2:到達時間\033[m", - tt, sizeof(tt), LCECHO) && - (tt[0]=='1' || tt[0]=='2')) + while (1) + if (getdata(21, 0, "\033[1;35m欲查詢 1:出發時間 2:到達時間\033[m", + tt, sizeof(tt), LCECHO) && + (tt[0] == '1' || tt[0] == '2')) break; sethomepath(genbuf, cuser.userid); stampfile(genbuf, &mhdr); strcpy(mhdr.owner, "Ptt搜尋器"); strncpy(mhdr.title, "火車時刻搜尋結果", TTLEN); - sprintf(command,"echo \"from-station=%s&to-station=%s" + sprintf(command, "echo \"from-station=%s&to-station=%s" "&from-time=%02d00&to-time=%02d00&tt=%s&type=%s\" | " "lynx -dump -post_data " "\"http://www.railway.gov.tw/cgi-bin/timetk.cgi\" > %s.railway", addr[from - 1], addr[to - 1], time_go, time_reach, (tt[0] == '1') ? "start" : "arriv", (type[0] == '1') ? "fast" : "slow", genbuf); - + system(command); filt_railway(genbuf); sethomedir(genbuf, cuser.userid); - if(append_record(genbuf, &mhdr, sizeof(mhdr)) == -1) + if (append_record(genbuf, &mhdr, sizeof(mhdr)) == -1) return -1; hpressanykey("\033[1;31m我們會把搜尋結果很快就寄給你唷 ^_^\033[m"); return 0; diff --git a/pttbbs/mbbsd/passwd.c b/pttbbs/mbbsd/passwd.c index 06a26d32..9c129dc0 100644 --- a/pttbbs/mbbsd/passwd.c +++ b/pttbbs/mbbsd/passwd.c @@ -1,7 +1,7 @@ -/* $Id: passwd.c,v 1.6 2002/07/04 19:46:16 in2 Exp $ */ +/* $Id: passwd.c,v 1.7 2002/07/05 17:10:28 in2 Exp $ */ #include "bbs.h" -static int semid = -1; +static int semid = -1; #ifndef SEM_R #define SEM_R 0400 @@ -13,19 +13,21 @@ static int semid = -1; #ifndef __FreeBSD__ union semun { - int val; /* value for SETVAL */ - struct semid_ds *buf; /* buffer for IPC_STAT & IPC_SET */ - u_short *array; /* array for GETALL & SETALL */ - struct seminfo *__buf; /* buffer for IPC_INFO */ + int val; /* value for SETVAL */ + struct semid_ds *buf; /* buffer for IPC_STAT & IPC_SET */ + u_short *array; /* array for GETALL & SETALL */ + struct seminfo *__buf; /* buffer for IPC_INFO */ }; #endif -int passwd_init() { +int +passwd_init() +{ semid = semget(PASSWDSEM_KEY, 1, SEM_R | SEM_A | IPC_CREAT | IPC_EXCL); - if(semid == -1) { - if(errno == EEXIST) { + if (semid == -1) { + if (errno == EEXIST) { semid = semget(PASSWDSEM_KEY, 1, SEM_R | SEM_A); - if(semid == -1) { + if (semid == -1) { perror("semget"); exit(1); } @@ -34,10 +36,10 @@ int passwd_init() { exit(1); } } else { - union semun s; - + union semun s; + s.val = 1; - if(semctl(semid, 0, SETVAL, s) == -1) { + if (semctl(semid, 0, SETVAL, s) == -1) { perror("semctl"); exit(1); } @@ -46,23 +48,27 @@ int passwd_init() { return 0; } -int passwd_update_money(int num) { - userec_t user; - if(num < 1 || num > MAX_USERS) - return -1; +int +passwd_update_money(int num) +{ + userec_t user; + if (num < 1 || num > MAX_USERS) + return -1; passwd_query(num, &user); - if( SHM->loaded ) + if (SHM->loaded) user.money = moneyof(num); passwd_update(num, &user); return 0; -} +} -int passwd_update(int num, userec_t *buf) { - int pwdfd; - if(num < 1 || num > MAX_USERS) +int +passwd_update(int num, userec_t * buf) +{ + int pwdfd; + if (num < 1 || num > MAX_USERS) return -1; buf->money = moneyof(num); - if( (pwdfd = open(fn_passwd, O_RDWR)) < 0 ) + if ((pwdfd = open(fn_passwd, O_RDWR)) < 0) exit(1); lseek(pwdfd, sizeof(userec_t) * (num - 1), SEEK_SET); write(pwdfd, buf, sizeof(userec_t)); @@ -70,11 +76,13 @@ int passwd_update(int num, userec_t *buf) { return 0; } -int passwd_query(int num, userec_t *buf) { - int pwdfd; - if(num < 1 || num > MAX_USERS) +int +passwd_query(int num, userec_t * buf) +{ + int pwdfd; + if (num < 1 || num > MAX_USERS) return -1; - if( (pwdfd = open(fn_passwd, O_RDONLY)) < 0 ) + if ((pwdfd = open(fn_passwd, O_RDONLY)) < 0) exit(1); lseek(pwdfd, sizeof(userec_t) * (num - 1), SEEK_SET); read(pwdfd, buf, sizeof(userec_t)); @@ -82,30 +90,36 @@ int passwd_query(int num, userec_t *buf) { return 0; } -int passwd_apply(int (*fptr)(userec_t *)) { - int i; - userec_t user; - for(i = 0; i < MAX_USERS; i++){ +int +passwd_apply(int (*fptr) (userec_t *)) +{ + int i; + userec_t user; + for (i = 0; i < MAX_USERS; i++) { passwd_query(i + 1, &user); - if((*fptr)(&user) == QUIT) + if ((*fptr) (&user) == QUIT) return QUIT; } return 0; } -void passwd_lock() { - struct sembuf buf = { 0, -1, SEM_UNDO }; - - if(semop(semid, &buf, 1)) { +void +passwd_lock() +{ + struct sembuf buf = {0, -1, SEM_UNDO}; + + if (semop(semid, &buf, 1)) { perror("semop"); exit(1); } } -void passwd_unlock() { - struct sembuf buf = { 0, 1, SEM_UNDO }; - - if(semop(semid, &buf, 1)) { +void +passwd_unlock() +{ + struct sembuf buf = {0, 1, SEM_UNDO}; + + if (semop(semid, &buf, 1)) { perror("semop"); exit(1); } diff --git a/pttbbs/mbbsd/read.c b/pttbbs/mbbsd/read.c index fe8c871d..3d661479 100644 --- a/pttbbs/mbbsd/read.c +++ b/pttbbs/mbbsd/read.c @@ -1,11 +1,11 @@ -/* $Id: read.c,v 1.7 2002/07/02 16:13:37 in2 Exp $ */ +/* $Id: read.c,v 1.8 2002/07/05 17:10:28 in2 Exp $ */ #include "bbs.h" #define MAXPATHLEN 256 static fileheader_t *headers = NULL; -static int last_line; -static int hit_thread; +static int last_line; +static int hit_thread; #include <sys/mman.h> @@ -13,88 +13,76 @@ static int hit_thread; /* Tag List 標籤 */ /* ----------------------------------------------------- */ void -UnTagger (int locus) +UnTagger(int locus) { - if (locus > TagNum) return; + if (locus > TagNum) + return; - TagNum--; + TagNum--; - if (TagNum > locus) - memcpy(&TagList[locus], &TagList[locus + 1], - (TagNum - locus) * sizeof(TagItem)); + if (TagNum > locus) + memcpy(&TagList[locus], &TagList[locus + 1], + (TagNum - locus) * sizeof(TagItem)); } int Tagger(time_t chrono, int recno, int mode) -{ - int head, tail, posi = 0, comp; - - for (head = 0, tail = TagNum - 1, comp = 1; head <= tail;) - { - posi = (head + tail) >> 1; - comp = TagList[posi].chrono - chrono; - if (!comp) - { - break; - } - else if (comp < 0) - { - head = posi + 1; - } - else - { - tail = posi - 1; - } - } - - if (mode == TAG_NIN) - { - if (!comp && recno) /* 絕對嚴謹:連 recno 一起比對 */ - comp = recno - TagList[posi].recno; - return comp; +{ + int head, tail, posi = 0, comp; - } + for (head = 0, tail = TagNum - 1, comp = 1; head <= tail;) { + posi = (head + tail) >> 1; + comp = TagList[posi].chrono - chrono; + if (!comp) { + break; + } else if (comp < 0) { + head = posi + 1; + } else { + tail = posi - 1; + } + } - if (!comp) - { - if (mode != TAG_TOGGLE) - return NA; + if (mode == TAG_NIN) { + if (!comp && recno) /* 絕對嚴謹:連 recno 一起比對 */ + comp = recno - TagList[posi].recno; + return comp; - TagNum--; - memcpy(&TagList[posi], &TagList[posi + 1], - (TagNum - posi) * sizeof(TagItem)); - } - else if (TagNum < MAXTAGS) - { - TagItem *tagp, buf[MAXTAGS]; - - tail = (TagNum - head) * sizeof(TagItem); - tagp = &TagList[head]; - memcpy(buf, tagp, tail); - tagp->chrono = chrono; - tagp->recno = recno; - memcpy(++tagp, buf, tail); - TagNum++; - } - else - { - bell(); - return 0; /* full */ - } - return YEA; + } + if (!comp) { + if (mode != TAG_TOGGLE) + return NA; + + TagNum--; + memcpy(&TagList[posi], &TagList[posi + 1], + (TagNum - posi) * sizeof(TagItem)); + } else if (TagNum < MAXTAGS) { + TagItem *tagp, buf[MAXTAGS]; + + tail = (TagNum - head) * sizeof(TagItem); + tagp = &TagList[head]; + memcpy(buf, tagp, tail); + tagp->chrono = chrono; + tagp->recno = recno; + memcpy(++tagp, buf, tail); + TagNum++; + } else { + bell(); + return 0; /* full */ + } + return YEA; } void -EnumTagName( char *fname, int locus) -{ - sprintf(fname, "M.%d.A", (int) TagList[locus].chrono); +EnumTagName(char *fname, int locus) +{ + sprintf(fname, "M.%d.A", (int)TagList[locus].chrono); } void -EnumTagFhdr(fileheader_t *fhdr, char *direct, int locus) -{ - get_record(direct, fhdr, sizeof(fileheader_t), TagList[locus].recno); +EnumTagFhdr(fileheader_t * fhdr, char *direct, int locus) +{ + get_record(direct, fhdr, sizeof(fileheader_t), TagList[locus].recno); } /* -1 : 取消 */ @@ -103,21 +91,20 @@ EnumTagFhdr(fileheader_t *fhdr, char *direct, int locus) int AskTag(char *msg) -{ - char buf[80]; - int num; - - num = TagNum; - sprintf(buf, "◆ %s A)文章 T)標記 Q)uit?", msg); - switch (rget(b_lines-1, buf)) - { - case 'q': - num = -1; - break; - case 'a': - num = 0; - } - return num; +{ + char buf[80]; + int num; + + num = TagNum; + sprintf(buf, "◆ %s A)文章 T)標記 Q)uit?", msg); + switch (rget(b_lines - 1, buf)) { + case 'q': + num = -1; + break; + case 'a': + num = 0; + } + return num; } @@ -125,98 +112,95 @@ AskTag(char *msg) #define BATCH_SIZE 65536 -char * -f_map (char *fpath, int *fsize) +char * +f_map(char *fpath, int *fsize) { - int fd, size; - struct stat st; - - if ((fd = open(fpath, O_RDONLY)) < 0) - return (char *) -1; - - if (fstat(fd, &st) || !S_ISREG(st.st_mode) || (size = st.st_size) <= 0) - { - close(fd); - return (char *) -1; - } + int fd, size; + struct stat st; + + if ((fd = open(fpath, O_RDONLY)) < 0) + return (char *)-1; - fpath = (char *) mmap(NULL, size, PROT_READ, MAP_SHARED, fd, 0); - close(fd); - *fsize = size; - return fpath; + if (fstat(fd, &st) || !S_ISREG(st.st_mode) || (size = st.st_size) <= 0) { + close(fd); + return (char *)-1; + } + fpath = (char *)mmap(NULL, size, PROT_READ, MAP_SHARED, fd, 0); + close(fd); + *fsize = size; + return fpath; } static int TagThread(char *direct) -{ - int fsize, count; - char *title, *fimage; - fileheader_t *head, *tail; +{ + int fsize, count; + char *title, *fimage; + fileheader_t *head, *tail; - fimage = f_map(direct, &fsize); - if ( fimage == (char *) -1) - return DONOTHING; + fimage = f_map(direct, &fsize); + if (fimage == (char *)-1) + return DONOTHING; - head = (fileheader_t *) fimage; - tail = (fileheader_t *) (fimage + fsize); - count = 0; - do - { - count++; - title = subject(head->title); - if (!strncmp( currtitle, title,TTLEN)) - { - if (!Tagger(atoi (head->filename + 2), count, TAG_INSERT)) - break; - } - } while (++head < tail); + head = (fileheader_t *) fimage; + tail = (fileheader_t *) (fimage + fsize); + count = 0; + do { + count++; + title = subject(head->title); + if (!strncmp(currtitle, title, TTLEN)) { + if (!Tagger(atoi(head->filename + 2), count, TAG_INSERT)) + break; + } + } while (++head < tail); - munmap(fimage, fsize); - return FULLUPDATE; + munmap(fimage, fsize); + return FULLUPDATE; } int TagPruner(int bid) -{ - boardheader_t *bp; - bp = getbcache(bid); - if ( strcmp(bp->brdname, "Security" ) == 0 ) +{ + boardheader_t *bp; + bp = getbcache(bid); + if (strcmp(bp->brdname, "Security") == 0) return DONOTHING; - if (TagNum && ((currstat != READING) || (currmode & MODE_BOARD))) - { - if(getans("刪除所有標記[N]?") != 'y') - return FULLUPDATE; - delete_range(currdirect, 0, 0); - TagNum = 0; - if(bid>0); - setbtotal(bid); - return NEWDIRECT; - } - return DONOTHING; + if (TagNum && ((currstat != READING) || (currmode & MODE_BOARD))) { + if (getans("刪除所有標記[N]?") != 'y') + return FULLUPDATE; + delete_range(currdirect, 0, 0); + TagNum = 0; + if (bid > 0); + setbtotal(bid); + return NEWDIRECT; + } + return DONOTHING; } /* ----------------------------------------------------- */ /* cursor & reading record position control */ /* ----------------------------------------------------- */ -keeploc_t *getkeep(char *s, int def_topline, int def_cursline) { +keeploc_t * +getkeep(char *s, int def_topline, int def_cursline) +{ static struct keeploc_t *keeplist = NULL; struct keeploc_t *p; - void *malloc(); + void *malloc(); - if(def_cursline >= 0) - for(p = keeplist; p; p = p->next) { - if(!strcmp(s, p->key)) { - if(p->crs_ln < 1) + if (def_cursline >= 0) + for (p = keeplist; p; p = p->next) { + if (!strcmp(s, p->key)) { + if (p->crs_ln < 1) p->crs_ln = 1; return p; } } else def_cursline = -def_cursline; - p = (keeploc_t *)malloc(sizeof(keeploc_t)); + p = (keeploc_t *) malloc(sizeof(keeploc_t)); p->key = (char *)malloc(strlen(s) + 1); strcpy(p->key, s); p->top_ln = def_topline; @@ -225,66 +209,71 @@ keeploc_t *getkeep(char *s, int def_topline, int def_cursline) { return (keeplist = p); } -void fixkeep(char *s, int first) { - keeploc_t *k; - +void +fixkeep(char *s, int first) +{ + keeploc_t *k; + k = getkeep(s, 1, 1); - if(k->crs_ln >= first) { + if (k->crs_ln >= first) { k->crs_ln = (first == 1 ? 1 : first - 1); k->top_ln = (first < 11 ? 1 : first - 10); } } /* calc cursor pos and show cursor correctly */ -static int cursor_pos(keeploc_t *locmem, int val, int from_top) { - int top; - - if(val > last_line) { +static int +cursor_pos(keeploc_t * locmem, int val, int from_top) +{ + int top; + + if (val > last_line) { bell(); val = last_line; } - if(val <= 0) { + if (val <= 0) { bell(); val = 1; } - top = locmem->top_ln; - if(val >= top && val < top + p_lines) { + if (val >= top && val < top + p_lines) { cursor_clear(3 + locmem->crs_ln - top, 0); locmem->crs_ln = val; cursor_show(3 + val - top, 0); return DONOTHING; } locmem->top_ln = val - from_top; - if(locmem->top_ln <= 0) + if (locmem->top_ln <= 0) locmem->top_ln = 1; locmem->crs_ln = val; return PARTUPDATE; } -static int move_cursor_line(keeploc_t *locmem, int mode) { - int top, crs; - int reload = 0; +static int +move_cursor_line(keeploc_t * locmem, int mode) +{ + int top, crs; + int reload = 0; top = locmem->top_ln; crs = locmem->crs_ln; - if(mode == READ_PREV) { - if(crs <= top) { + if (mode == READ_PREV) { + if (crs <= top) { top -= p_lines - 1; - if(top < 1) + if (top < 1) top = 1; reload = 1; } - if(--crs < 1) { + if (--crs < 1) { crs = 1; reload = -1; } - } else if(mode == READ_NEXT) { - if(crs >= top + p_lines - 1) { + } else if (mode == READ_NEXT) { + if (crs >= top + p_lines - 1) { top += p_lines - 1; reload = 1; } - if(++crs > last_line) { + if (++crs > last_line) { crs = last_line; reload = -1; } @@ -294,86 +283,87 @@ static int move_cursor_line(keeploc_t *locmem, int mode) { return reload; } -static int thread(keeploc_t *locmem, int stype) { - static char a_ans[32], t_ans[32]; - char ans[32], s_pmt[64]; - register char *tag, *query = NULL; - register int now, pos, match, near = 0; - fileheader_t fh; - int circulate_flag = 1; /* circulate at end or begin */ +static int +thread(keeploc_t * locmem, int stype) +{ + static char a_ans[32], t_ans[32]; + char ans[32], s_pmt[64]; + register char *tag, *query = NULL; + register int now, pos, match, near = 0; + fileheader_t fh; + int circulate_flag = 1; /* circulate at end or begin */ match = hit_thread = 0; now = pos = locmem->crs_ln; - if(stype == 'A') { - if(!*currowner) + if (stype == 'A') { + if (!*currowner) return DONOTHING; str_lower(a_ans, currowner); query = a_ans; circulate_flag = 0; stype = 0; - } else if(stype == 'a') { - if(!*currowner) + } else if (stype == 'a') { + if (!*currowner) return DONOTHING; str_lower(a_ans, currowner); query = a_ans; circulate_flag = 0; stype = RS_FORWARD; - } else if(stype == '/') { - if(!*t_ans) + } else if (stype == '/') { + if (!*t_ans) return DONOTHING; query = t_ans; circulate_flag = 0; stype = RS_TITLE | RS_FORWARD; - } else if(stype == '?') { - if(!*t_ans) + } else if (stype == '?') { + if (!*t_ans) return DONOTHING; circulate_flag = 0; query = t_ans; stype = RS_TITLE; - } else if(stype & RS_RELATED) { + } else if (stype & RS_RELATED) { tag = headers[pos - locmem->top_ln].title; - if(stype & RS_CURRENT) { - if(stype & RS_FIRST) { - if(!strncmp(currtitle, tag, TTLEN)) + if (stype & RS_CURRENT) { + if (stype & RS_FIRST) { + if (!strncmp(currtitle, tag, TTLEN)) return DONOTHING; near = 0; } query = currtitle; } else { query = subject(tag); - if(stype & RS_FIRST) { - if(query == tag) + if (stype & RS_FIRST) { + if (query == tag) return DONOTHING; near = 0; } } - } else if(!(stype & RS_THREAD)) { + } else if (!(stype & RS_THREAD)) { query = (stype & RS_TITLE) ? t_ans : a_ans; - if(!*query && query == a_ans) { - if(*currowner) + if (!*query && query == a_ans) { + if (*currowner) strcpy(a_ans, currowner); else if (*currauthor) strcpy(a_ans, currauthor); } - sprintf(s_pmt, "%s搜尋%s [%s] ",(stype & RS_FORWARD) ? "往後":"往前", + sprintf(s_pmt, "%s搜尋%s [%s] ", (stype & RS_FORWARD) ? "往後" : "往前", (stype & RS_TITLE) ? "標題" : "作者", query); getdata(b_lines - 1, 0, s_pmt, ans, sizeof(ans), DOECHO); - if(*ans) + if (*ans) strcpy(query, ans); - else if(*query == '\0') + else if (*query == '\0') return DONOTHING; } - tag = fh.owner; do { - if(!circulate_flag || stype & RS_RELATED) { - if(stype & RS_FORWARD) { - if(++now > last_line) + if (!circulate_flag || stype & RS_RELATED) { + if (stype & RS_FORWARD) { + if (++now > last_line) return DONOTHING; } else { - if(--now <= 0 || now < pos - 300) { - if((stype & RS_FIRST) && (near)) { + if (--now <= 0 || now < pos - 300) { + if ((stype & RS_FIRST) && (near)) { hit_thread = 1; return cursor_pos(locmem, near, 10); } @@ -381,64 +371,64 @@ static int thread(keeploc_t *locmem, int stype) { } } } else { - if(stype & RS_FORWARD) { - if(++now > last_line) + if (stype & RS_FORWARD) { + if (++now > last_line) now = 1; - } else if(--now <= 0) + } else if (--now <= 0) now = last_line; } - + get_record(currdirect, &fh, sizeof(fileheader_t), now); - - if(fh.owner[0] == '-') + + if (fh.owner[0] == '-') continue; - - if(stype & RS_THREAD) { - if(strncasecmp(fh.title, str_reply, 3)) { + + if (stype & RS_THREAD) { + if (strncasecmp(fh.title, str_reply, 3)) { hit_thread = 1; return cursor_pos(locmem, now, 10); } continue; } - - if(stype & RS_TITLE) + if (stype & RS_TITLE) tag = subject(fh.title); - - if(((stype & RS_RELATED) && !strncmp(tag, query, 40)) || - (!(stype & RS_RELATED) && ((query == currowner) ? - !strcmp(tag, query) : - strstr_lower(tag, query)))) { - if((stype & RS_FIRST) && tag != fh.title) { + + if (((stype & RS_RELATED) && !strncmp(tag, query, 40)) || + (!(stype & RS_RELATED) && ((query == currowner) ? + !strcmp(tag, query) : + strstr_lower(tag, query)))) { + if ((stype & RS_FIRST) && tag != fh.title) { near = now; continue; } - hit_thread = 1; match = cursor_pos(locmem, now, 10); - if((!(stype & RS_CURRENT)) && - (stype & RS_RELATED) && - strncmp(currtitle, query, TTLEN)) { + if ((!(stype & RS_CURRENT)) && + (stype & RS_RELATED) && + strncmp(currtitle, query, TTLEN)) { strncpy(currtitle, query, TTLEN); match = PARTUPDATE; } break; } - } while(now != pos); - + } while (now != pos); + return match; } #ifdef INTERNET_EMAIL -static void mail_forward(fileheader_t *fhdr, char *direct, int mode) { - int i; - char buf[STRLEN]; - char *p; - +static void +mail_forward(fileheader_t * fhdr, char *direct, int mode) +{ + int i; + char buf[STRLEN]; + char *p; + strncpy(buf, direct, sizeof(buf)); - if((p = strrchr(buf, '/'))) + if ((p = strrchr(buf, '/'))) *p = '\0'; - switch(i = doforward(buf, fhdr, mode)) { + switch (i = doforward(buf, fhdr, mode)) { case 0: outmsg(msg_fwd_ok); break; @@ -456,150 +446,144 @@ static void mail_forward(fileheader_t *fhdr, char *direct, int mode) { } #endif -static int select_read(keeploc_t *locmem, int sr_mode) { - register char *tag,*query,*temp; - fileheader_t fh; - char fpath[80], genbuf[MAXPATHLEN], buf3[5]; - char static t_ans[TTLEN+1]=""; - char static a_ans[TTLEN+1]=""; - int fd, fr, size = sizeof(fileheader_t); - struct stat st; -/* rocker.011018: make a reference number for process article */ - int reference = 0; - - if((currmode & MODE_SELECT)) +static int +select_read(keeploc_t * locmem, int sr_mode) +{ + register char *tag, *query, *temp; + fileheader_t fh; + char fpath[80], genbuf[MAXPATHLEN], buf3[5]; + char static t_ans[TTLEN + 1] = ""; + char static a_ans[TTLEN + 1] = ""; + int fd, fr, size = sizeof(fileheader_t); + struct stat st; + /* rocker.011018: make a reference number for process article */ + int reference = 0; + + if ((currmode & MODE_SELECT)) return -1; - if(sr_mode == RS_TITLE) + if (sr_mode == RS_TITLE) query = subject(headers[locmem->crs_ln - locmem->top_ln].title); - else if(sr_mode == RS_NEWPOST) - { + else if (sr_mode == RS_NEWPOST) { strcpy(buf3, "Re: "); query = buf3; - } - else - { - char buff[80]; - char newdata[35]; + } else { + char buff[80]; + char newdata[35]; query = (sr_mode == RS_RELATED) ? t_ans : a_ans; sprintf(buff, "搜尋%s [%s] ", (sr_mode == RS_RELATED) ? "標題" : "作者", query); getdata(b_lines, 0, buff, newdata, sizeof(newdata), DOECHO); - if( newdata[0] ) + if (newdata[0]) strcpy(query, newdata); - if(!(*query)) + if (!(*query)) return DONOTHING; } - if((fd = open(currdirect, O_RDONLY, 0)) != -1) { - sprintf(genbuf,"SR.%s",cuser.userid); - if(currstat==RMAIL) - sethomefile(fpath,cuser.userid,genbuf); + if ((fd = open(currdirect, O_RDONLY, 0)) != -1) { + sprintf(genbuf, "SR.%s", cuser.userid); + if (currstat == RMAIL) + sethomefile(fpath, cuser.userid, genbuf); else - setbfile(fpath,currboard,genbuf); - if(((fr = open(fpath,O_WRONLY | O_CREAT | O_TRUNC,0600)) != -1)) { - switch(sr_mode) { + setbfile(fpath, currboard, genbuf); + if (((fr = open(fpath, O_WRONLY | O_CREAT | O_TRUNC, 0600)) != -1)) { + switch (sr_mode) { case RS_TITLE: - while(read(fd,&fh,size) == size) { + while (read(fd, &fh, size) == size) { ++reference; tag = subject(fh.title); - if(!strncmp(tag, query, 40)) - { + if (!strncmp(tag, query, 40)) { fh.money = reference | FHR_REFERENCE; - write(fr,&fh,size); + write(fr, &fh, size); } } break; case RS_RELATED: - while(read(fd,&fh,size) == size) { + while (read(fd, &fh, size) == size) { ++reference; tag = fh.title; - if(strcasestr(tag,query)) - { + if (strcasestr(tag, query)) { fh.money = reference | FHR_REFERENCE; - write(fr,&fh,size); + write(fr, &fh, size); } } break; case RS_NEWPOST: - while(read(fd, &fh, size) == size) { + while (read(fd, &fh, size) == size) { ++reference; tag = fh.title; temp = strstr(tag, query); - if(temp == NULL || temp != tag) - { + if (temp == NULL || temp != tag) { write(fr, &fh, size); fh.money = reference | FHR_REFERENCE; } } case RS_AUTHOR: - while(read(fd,&fh,size) == size) { + while (read(fd, &fh, size) == size) { ++reference; tag = fh.owner; - if(strcasestr(tag,query)) - { - write(fr,&fh,size); + if (strcasestr(tag, query)) { + write(fr, &fh, size); fh.money = reference | FHR_REFERENCE; } } break; } - fstat(fr,&st); + fstat(fr, &st); close(fr); } close(fd); - if(st.st_size) { + if (st.st_size) { currmode |= MODE_SELECT; - strcpy(currdirect,fpath); + strcpy(currdirect, fpath); } } return st.st_size; } -static int i_read_key(onekey_t *rcmdlist, keeploc_t *locmem, int ch, int bid) { - int i, mode = DONOTHING; - - switch(ch) { +static int +i_read_key(onekey_t * rcmdlist, keeploc_t * locmem, int ch, int bid) +{ + int i, mode = DONOTHING; + + switch (ch) { case 'q': case 'e': case KEY_LEFT: return (currmode & MODE_SELECT) ? board_select() : (currmode & MODE_ETC) ? board_etc() : - (currmode & MODE_DIGEST) ? board_digest() : DOQUIT; + (currmode & MODE_DIGEST) ? board_digest() : DOQUIT; case Ctrl('L'): redoscr(); break; -/* - case Ctrl('C'): - cal(); - return FULLUPDATE; - break; -*/ + /* + * case Ctrl('C'): cal(); return FULLUPDATE; break; + */ case KEY_ESC: - if(KEY_ESC_arg == 'i') { + if (KEY_ESC_arg == 'i') { t_idle(); return FULLUPDATE; } break; case Ctrl('H'): - if(select_read(locmem, RS_NEWPOST)) + if (select_read(locmem, RS_NEWPOST)) return NEWDIRECT; else return READ_REDRAW; case 'a': case 'A': - if(select_read(locmem,RS_AUTHOR)) + if (select_read(locmem, RS_AUTHOR)) return NEWDIRECT; else return READ_REDRAW; case '/': case '?': - if(select_read(locmem,RS_RELATED)) + if (select_read(locmem, RS_RELATED)) return NEWDIRECT; else return READ_REDRAW; case 'S': - if(select_read(locmem,RS_TITLE)) + if (select_read(locmem, RS_TITLE)) return NEWDIRECT; else return READ_REDRAW; @@ -636,8 +620,8 @@ static int i_read_key(onekey_t *rcmdlist, keeploc_t *locmem, int ch, int bid) { case KEY_PGDN: case 'N': case Ctrl('F'): - if(last_line >= locmem->top_ln + p_lines) { - if(last_line > locmem->top_ln + p_lines) + if (last_line >= locmem->top_ln + p_lines) { + if (last_line > locmem->top_ln + p_lines) locmem->top_ln += p_lines; else locmem->top_ln += p_lines - 1; @@ -651,9 +635,9 @@ static int i_read_key(onekey_t *rcmdlist, keeploc_t *locmem, int ch, int bid) { case KEY_PGUP: case Ctrl('B'): case 'P': - if(locmem->top_ln > 1) { + if (locmem->top_ln > 1) { locmem->top_ln -= p_lines; - if(locmem->top_ln <= 0) + if (locmem->top_ln <= 0) locmem->top_ln = 1; locmem->crs_ln = locmem->top_ln; return PARTUPDATE; @@ -661,9 +645,9 @@ static int i_read_key(onekey_t *rcmdlist, keeploc_t *locmem, int ch, int bid) { break; case KEY_END: case '$': - if(last_line >= locmem->top_ln + p_lines) { + if (last_line >= locmem->top_ln + p_lines) { locmem->top_ln = last_line - p_lines + 1; - if(locmem->top_ln <= 0) + if (locmem->top_ln <= 0) locmem->top_ln = 1; locmem->crs_ln = last_line; return PARTUPDATE; @@ -674,24 +658,24 @@ static int i_read_key(onekey_t *rcmdlist, keeploc_t *locmem, int ch, int bid) { break; case 'F': case 'U': - if(HAS_PERM(PERM_FORWARD)) { + if (HAS_PERM(PERM_FORWARD)) { mail_forward(&headers[locmem->crs_ln - locmem->top_ln], - currdirect, ch /*== 'U'*/); - /*by CharlieL*/ + currdirect, ch /* == 'U' */ ); + /* by CharlieL */ return FULLUPDATE; } break; case Ctrl('Q'): return my_query(headers[locmem->crs_ln - locmem->top_ln].owner); case Ctrl('S'): - if(HAS_PERM(PERM_ACCOUNTS)) { - int id; - userec_t muser; + if (HAS_PERM(PERM_ACCOUNTS)) { + int id; + userec_t muser; strcpy(currauthor, headers[locmem->crs_ln - locmem->top_ln].owner); stand_title("使用者設定"); move(1, 0); - if((id = getuser(headers[locmem->crs_ln - locmem->top_ln].owner))){ + if ((id = getuser(headers[locmem->crs_ln - locmem->top_ln].owner))) { memcpy(&muser, &xuser, sizeof(muser)); user_display(&muser, 1); uinfo_query(&muser, 1, id); @@ -700,109 +684,108 @@ static int i_read_key(onekey_t *rcmdlist, keeploc_t *locmem, int ch, int bid) { } break; -/* rocker.011018: 採用新的tag模式 */ + /* rocker.011018: 採用新的tag模式 */ case 't': -/* rocker.011112: 解決再select mode標記文章的問題 */ - if (Tagger(atoi(headers[locmem->crs_ln - locmem->top_ln].filename + 2), - (currmode & MODE_SELECT) ? - (headers[locmem->crs_ln - locmem->top_ln].money & ~FHR_REFERENCE) : - locmem->crs_ln, TAG_TOGGLE)) - return POS_NEXT; - return DONOTHING; + /* rocker.011112: 解決再select mode標記文章的問題 */ + if (Tagger(atoi(headers[locmem->crs_ln - locmem->top_ln].filename + 2), + (currmode & MODE_SELECT) ? + (headers[locmem->crs_ln - locmem->top_ln].money & ~FHR_REFERENCE) : + locmem->crs_ln, TAG_TOGGLE)) + return POS_NEXT; + return DONOTHING; case Ctrl('C'): - if (TagNum) - { - TagNum = 0; - return FULLUPDATE; - } - return DONOTHING; + if (TagNum) { + TagNum = 0; + return FULLUPDATE; + } + return DONOTHING; case Ctrl('T'): - return TagThread(currdirect); + return TagThread(currdirect); case Ctrl('D'): - return TagPruner(bid); + return TagPruner(bid); case '\n': case '\r': case 'l': case KEY_RIGHT: ch = 'r'; default: - for(i = 0; rcmdlist[i].fptr; i++) { - if(rcmdlist[i].key == ch) { - mode = (*(rcmdlist[i].fptr))(locmem->crs_ln, - &headers[locmem->crs_ln - - locmem->top_ln], currdirect); + for (i = 0; rcmdlist[i].fptr; i++) { + if (rcmdlist[i].key == ch) { + mode = (*(rcmdlist[i].fptr)) (locmem->crs_ln, + &headers[locmem->crs_ln - + locmem->top_ln], currdirect); break; } - if(rcmdlist[i].key == 'h') - if(currmode & (MODE_ETC | MODE_DIGEST)) + if (rcmdlist[i].key == 'h') + if (currmode & (MODE_ETC | MODE_DIGEST)) return DONOTHING; } } return mode; } -void i_read(int cmdmode, char *direct, void (*dotitle)(), void (*doentry)(), onekey_t *rcmdlist, int bidcache) { - keeploc_t *locmem = NULL; - int recbase = 0, mode, ch; - int num = 0, entries = 0; - int i; - int jump = 0; - char genbuf[4]; - char currdirect0[64]; - int last_line0 = last_line; - int hit_thread0 = hit_thread; - fileheader_t *headers0 = headers; - - strcpy(currdirect0 ,currdirect); +void i_read(int cmdmode, char *direct, void (*dotitle) (), void (*doentry) (), onekey_t * rcmdlist, int bidcache){ + keeploc_t *locmem = NULL; + int recbase = 0, mode, ch; + int num = 0, entries = 0; + int i; + int jump = 0; + char genbuf[4]; + char currdirect0[64]; + int last_line0 = last_line; + int hit_thread0 = hit_thread; + fileheader_t *headers0 = headers; + + strcpy(currdirect0, currdirect); #define FHSZ sizeof(fileheader_t) -// Ptt:這邊headers 可以針對看板的最後60篇做cache - headers = (fileheader_t *)calloc(p_lines, FHSZ); +//Ptt:這 鄣eaders i H w 麍搌O 熙怮60 g 甥ache + headers = (fileheader_t *) calloc(p_lines, FHSZ); strcpy(currdirect, direct); mode = NEWDIRECT; -/* rocker.011018: 加入新的tag機制 */ + /* rocker.011018: 加入新的tag機制 */ TagNum = 0; do { /* 依據 mode 顯示 fileheader */ setutmpmode(cmdmode); - switch(mode) { - case NEWDIRECT: /* 第一次載入此目錄 */ + switch (mode) { + case NEWDIRECT: /* 第一次載入此目錄 */ case DIRCHANGED: - if(bidcache>0 && !(currmode & (MODE_SELECT| MODE_DIGEST)) ) - last_line=getbtotal(currbid); - else - last_line= get_num_records(currdirect, FHSZ); - - if(mode == NEWDIRECT) { - if(last_line == 0) { - if(curredit & EDIT_ITEM) { + if (bidcache > 0 && !(currmode & (MODE_SELECT | MODE_DIGEST))) + last_line = getbtotal(currbid); + else + last_line = get_num_records(currdirect, FHSZ); + + if (mode == NEWDIRECT) { + if (last_line == 0) { + if (curredit & EDIT_ITEM) { outs("沒有物品"); refresh(); goto return_i_read; - } else if(curredit & EDIT_MAIL) { + } else if (curredit & EDIT_MAIL) { outs("沒有來信"); refresh(); goto return_i_read; - } else if(currmode & MODE_ETC) { - board_etc(); /* Kaede */ + } else if (currmode & MODE_ETC) { + board_etc(); /* Kaede */ outmsg("尚未收錄其它文章"); refresh(); - } else if(currmode & MODE_DIGEST) { - board_digest(); /* Kaede */ + } else if (currmode & MODE_DIGEST) { + board_digest(); /* Kaede */ outmsg("尚未收錄文摘"); refresh(); - } else if(currmode & MODE_SELECT) { - board_select(); /* Leeym */ + } else if (currmode & MODE_SELECT) { + board_select(); /* Leeym */ outmsg("沒有此系列的文章"); refresh(); } else { getdata(b_lines - 1, 0, "看板新成立 (P)發表文章 (Q)離開?[Q] ", genbuf, 4, LCECHO); - if(genbuf[0] == 'p') + if (genbuf[0] == 'p') do_post(); goto return_i_read; } @@ -811,42 +794,41 @@ void i_read(int cmdmode, char *direct, void (*dotitle)(), void (*doentry)(), one locmem = getkeep(currdirect, num < 1 ? 1 : num, last_line); } recbase = -1; - + case FULLUPDATE: - (*dotitle)(); - + (*dotitle) (); + case PARTUPDATE: - if(last_line < locmem->top_ln + p_lines) { - if(bidcache>0 && !(currmode & (MODE_SELECT| MODE_DIGEST))) - num=getbtotal(currbid); - else + if (last_line < locmem->top_ln + p_lines) { + if (bidcache > 0 && !(currmode & (MODE_SELECT | MODE_DIGEST))) + num = getbtotal(currbid); + else num = get_num_records(currdirect, FHSZ); - - if(last_line != num) { + + if (last_line != num) { last_line = num; recbase = -1; } } - - if(last_line == 0) + if (last_line == 0) goto return_i_read; - else if(recbase != locmem->top_ln) { + else if (recbase != locmem->top_ln) { recbase = locmem->top_ln; - if(recbase > last_line) { + if (recbase > last_line) { recbase = (last_line - p_lines) >> 1; - if(recbase < 1) + if (recbase < 1) recbase = 1; locmem->top_ln = recbase; } - if(bidcache>0 && !(currmode & (MODE_SELECT| MODE_DIGEST)) - && (last_line - recbase) < DIRCACHESIZE ) - entries = get_fileheader_cache(currbid, currdirect, headers, - recbase, p_lines); + if (bidcache > 0 && !(currmode & (MODE_SELECT | MODE_DIGEST)) + && (last_line - recbase) < DIRCACHESIZE) + entries = get_fileheader_cache(currbid, currdirect, headers, + recbase, p_lines); else - entries = get_records(currdirect, headers, FHSZ, recbase, - p_lines); + entries = get_records(currdirect, headers, FHSZ, recbase, + p_lines); } - if(locmem->crs_ln > last_line) + if (locmem->crs_ln > last_line) locmem->crs_ln = last_line; move(3, 0); clrtobot(); @@ -856,7 +838,7 @@ void i_read(int cmdmode, char *direct, void (*dotitle)(), void (*doentry)(), one (*doentry) (locmem->top_ln + i, &headers[i]); case READ_REDRAW: outmsg(curredit & EDIT_ITEM ? - "\033[44m 私人收藏 \033[30;47m 繼續? \033[m" : + "\033[44m 私人收藏 \033[30;47m 繼續? \033[m" : curredit & EDIT_MAIL ? msg_mailer : MSG_POSTER); break; case READ_PREV: @@ -874,73 +856,73 @@ void i_read(int cmdmode, char *direct, void (*dotitle)(), void (*doentry)(), one } /* 讀取鍵盤,加以處理,設定 mode */ - if(!jump) { + if (!jump) { cursor_show(3 + locmem->crs_ln - locmem->top_ln, 0); ch = egetch(); mode = DONOTHING; } else ch = ' '; - if(mode == POS_NEXT) { + if (mode == POS_NEXT) { mode = cursor_pos(locmem, locmem->crs_ln + 1, 1); - if(mode == DONOTHING) + if (mode == DONOTHING) mode = PART_REDRAW; jump = 0; - } else if(ch >= '0' && ch <= '9') { - if((i = search_num(ch, last_line)) != -1) + } else if (ch >= '0' && ch <= '9') { + if ((i = search_num(ch, last_line)) != -1) mode = cursor_pos(locmem, i + 1, 10); } else { - if(!jump) + if (!jump) mode = i_read_key(rcmdlist, locmem, ch, currbid); - while(mode == READ_NEXT || mode == READ_PREV || - mode == RELATE_FIRST || mode == RELATE_NEXT || - mode == RELATE_PREV || mode == THREAD_NEXT || - mode == THREAD_PREV || mode == 'A' || mode == 'a' || - mode == '/' || mode == '?') { - int reload; - - if(mode == READ_NEXT || mode == READ_PREV) + while (mode == READ_NEXT || mode == READ_PREV || + mode == RELATE_FIRST || mode == RELATE_NEXT || + mode == RELATE_PREV || mode == THREAD_NEXT || + mode == THREAD_PREV || mode == 'A' || mode == 'a' || + mode == '/' || mode == '?') { + int reload; + + if (mode == READ_NEXT || mode == READ_PREV) reload = move_cursor_line(locmem, mode); else { reload = thread(locmem, mode); - if(!hit_thread) { + if (!hit_thread) { mode = FULLUPDATE; break; } } - - if(reload == -1) { + + if (reload == -1) { mode = FULLUPDATE; break; - } else if(reload) { + } else if (reload) { recbase = locmem->top_ln; - if(bidcache>0 && !(currmode &(MODE_SELECT| MODE_DIGEST)) - && last_line-recbase<DIRCACHESIZE ) - entries = get_fileheader_cache(currbid, currdirect, - headers, recbase, p_lines); - else - entries = get_records(currdirect, headers, FHSZ, recbase, - p_lines); + if (bidcache > 0 && !(currmode & (MODE_SELECT | MODE_DIGEST)) + && last_line - recbase < DIRCACHESIZE) + entries = get_fileheader_cache(currbid, currdirect, + headers, recbase, p_lines); + else + entries = get_records(currdirect, headers, FHSZ, recbase, + p_lines); - if(entries <= 0) { + if (entries <= 0) { last_line = -1; break; } } num = locmem->crs_ln - locmem->top_ln; - if(headers[num].owner[0] != '-') + if (headers[num].owner[0] != '-') mode = i_read_key(rcmdlist, locmem, ch, bidcache); } } - } while(mode != DOQUIT); + } while (mode != DOQUIT); #undef FHSZ - return_i_read: +return_i_read: free(headers); last_line = last_line0; hit_thread = hit_thread0; headers = headers0; - strcpy(currdirect ,currdirect0); + strcpy(currdirect, currdirect0); return; } diff --git a/pttbbs/mbbsd/record.c b/pttbbs/mbbsd/record.c index 36b48847..bc50cbe1 100644 --- a/pttbbs/mbbsd/record.c +++ b/pttbbs/mbbsd/record.c @@ -1,58 +1,66 @@ -/* $Id: record.c,v 1.6 2002/06/22 18:01:23 ptt Exp $ */ +/* $Id: record.c,v 1.7 2002/07/05 17:10:28 in2 Exp $ */ #include "bbs.h" #undef HAVE_MMAP #define BUFSIZE 512 -static void PttLock(int fd, int size, int mode) { +static void +PttLock(int fd, int size, int mode) +{ static struct flock lock_it; - int ret; - - lock_it.l_whence = SEEK_CUR; /* from current point */ - lock_it.l_start = 0; /* -"- */ - lock_it.l_len = size; /* length of data */ - lock_it.l_type = mode; /* set exclusive/write lock */ - lock_it.l_pid = 0; /* pid not actually interesting */ - while((ret = fcntl(fd, F_SETLKW, &lock_it)) < 0 && errno == EINTR); + int ret; + + lock_it.l_whence = SEEK_CUR;/* from current point */ + lock_it.l_start = 0; /* -"- */ + lock_it.l_len = size; /* length of data */ + lock_it.l_type = mode; /* set exclusive/write lock */ + lock_it.l_pid = 0; /* pid not actually interesting */ + while ((ret = fcntl(fd, F_SETLKW, &lock_it)) < 0 && errno == EINTR); } #define safewrite write -int get_num_records(char *fpath, int size) { - struct stat st; - if(stat(fpath, &st) == -1) +int +get_num_records(char *fpath, int size) +{ + struct stat st; + if (stat(fpath, &st) == -1) return 0; return st.st_size / size; } -int get_sum_records(char* fpath, int size) { - struct stat st; - long ans = 0; - FILE* fp; - fileheader_t fhdr; - char buf[200], *p; +int +get_sum_records(char *fpath, int size) +{ + struct stat st; + long ans = 0; + FILE *fp; + fileheader_t fhdr; + char buf[200], *p; - if(!(fp = fopen(fpath, "r"))) + if (!(fp = fopen(fpath, "r"))) return -1; - + strcpy(buf, fpath); p = strrchr(buf, '/') + 1; - - while(fread(&fhdr, size, 1, fp) == 1) { + + while (fread(&fhdr, size, 1, fp) == 1) { strcpy(p, fhdr.filename); - if(stat(buf, &st) == 0 && S_ISREG(st.st_mode) && st.st_nlink == 1) + if (stat(buf, &st) == 0 && S_ISREG(st.st_mode) && st.st_nlink == 1) ans += st.st_size; } fclose(fp); return ans / 1024; } -int get_record(char *fpath, void *rptr, int size, int id) { - int fd = -1; - - if(id < 1 || (fd = open(fpath, O_RDONLY, 0)) != -1) { - if(lseek(fd, (off_t)(size * (id - 1)), SEEK_SET) != -1) { - if(read(fd, rptr, size) == size) { +int +get_record(char *fpath, void *rptr, int size, int id) +{ + int fd = -1; + + if (id < 1 || (fd = open(fpath, O_RDONLY, 0)) != -1) { + if (lseek(fd, (off_t) (size * (id - 1)), SEEK_SET) != -1) { + if (read(fd, rptr, size) == size) { close(fd); return 0; } @@ -62,17 +70,19 @@ int get_record(char *fpath, void *rptr, int size, int id) { return -1; } -int get_records(char *fpath, void *rptr, int size, int id, int number) { - int fd; - - if(id < 1 || (fd = open(fpath, O_RDONLY, 0)) == -1) +int +get_records(char *fpath, void *rptr, int size, int id, int number) +{ + int fd; + + if (id < 1 || (fd = open(fpath, O_RDONLY, 0)) == -1) return -1; - if(lseek(fd, (off_t)(size * (id - 1)), SEEK_SET) == -1) { + if (lseek(fd, (off_t) (size * (id - 1)), SEEK_SET) == -1) { close(fd); return 0; } - if((id = read(fd, rptr, size * number)) == -1) { + if ((id = read(fd, rptr, size * number)) == -1) { close(fd); return -1; } @@ -80,84 +90,90 @@ int get_records(char *fpath, void *rptr, int size, int id, int number) { return id / size; } -int substitute_record(char *fpath, void *rptr, int size, int id) { - int fd; +int +substitute_record(char *fpath, void *rptr, int size, int id) +{ + int fd; - if(id < 1 || (fd = open(fpath, O_WRONLY | O_CREAT, 0644)) == -1) + if (id < 1 || (fd = open(fpath, O_WRONLY | O_CREAT, 0644)) == -1) return -1; - + lseek(fd, (off_t) (size * (id - 1)), SEEK_SET); PttLock(fd, size, F_WRLCK); safewrite(fd, rptr, size); PttLock(fd, size, F_UNLCK); close(fd); - + return 0; } /* rocker.011022: 避免lock檔開啟時不正常斷線,造成永久lock */ static int -force_open (char *fname) +force_open(char *fname) { - int fd; - time_t expire; + int fd; + time_t expire; + + expire = now - 3600; /* lock 存在超過一個小時就是有問題! */ - expire = now - 3600; /* lock 存在超過一個小時就是有問題! */ - - if (dasht (fname) < expire) return -1; - unlink(fname); - fd = open (fname, O_WRONLY|O_TRUNC, 0644); + if (dasht(fname) < expire) + return -1; + unlink(fname); + fd = open(fname, O_WRONLY | O_TRUNC, 0644); - return fd; + return fd; } #if !defined(_BBS_UTIL_C_) /* new/old/lock file processing */ typedef struct nol_t { - char newfn[256]; - char oldfn[256]; - char lockfn[256]; -} nol_t; + char newfn[256]; + char oldfn[256]; + char lockfn[256]; +} nol_t; -static void nolfilename(nol_t *n, char *fpath) { +static void +nolfilename(nol_t * n, char *fpath) +{ sprintf(n->newfn, "%s.new", fpath); sprintf(n->oldfn, "%s.old", fpath); sprintf(n->lockfn, "%s.lock", fpath); } -int delete_record(char fpath[], int size, int id) { - nol_t my; - char abuf[BUFSIZE]; - int fdr, fdw, fd; - int count; - +int +delete_record(char fpath[], int size, int id) +{ + nol_t my; + char abuf[BUFSIZE]; + int fdr, fdw, fd; + int count; + nolfilename(&my, fpath); - if((fd = open(my.lockfn, O_RDWR | O_CREAT | O_APPEND, 0644)) == -1) + if ((fd = open(my.lockfn, O_RDWR | O_CREAT | O_APPEND, 0644)) == -1) return -1; flock(fd, LOCK_EX); - if((fdr = open(fpath, O_RDONLY, 0)) == -1) { - move(10,10); + if ((fdr = open(fpath, O_RDONLY, 0)) == -1) { + move(10, 10); outs("delete_record failed!!! (open)"); pressanykey(); flock(fd, LOCK_UN); close(fd); return -1; } - - if( - ((fdw = open(my.newfn, O_WRONLY | O_CREAT | O_EXCL, 0644)) == -1) && - ((fdw = force_open (my.newfn)) == -1)) { + if ( + ((fdw = open(my.newfn, O_WRONLY | O_CREAT | O_EXCL, 0644)) == -1) && + ((fdw = force_open(my.newfn)) == -1)) { flock(fd, LOCK_UN); close(fd); close(fdr); return -1; } count = 1; - while(read(fdr, abuf, size) == size) { - if(id != count++ && (safewrite(fdw, abuf, size) == -1)) { + while (read(fdr, abuf, size) == size) { + if (id != count++ && (safewrite(fdw, abuf, size) == -1)) { unlink(my.newfn); close(fdr); close(fdw); @@ -168,7 +184,7 @@ int delete_record(char fpath[], int size, int id) { } close(fdr); close(fdw); - if(Rename(fpath, my.oldfn) == -1 || Rename(my.newfn, fpath) == -1) { + if (Rename(fpath, my.oldfn) == -1 || Rename(my.newfn, fpath) == -1) { flock(fd, LOCK_UN); close(fd); return -1; @@ -179,61 +195,61 @@ int delete_record(char fpath[], int size, int id) { } #if 0 -static char *title_body(char *title) { - if(!strncasecmp(title, str_reply, 3)) { +static char * +title_body(char *title) +{ + if (!strncasecmp(title, str_reply, 3)) { title += 3; - if(*title == ' ') + if (*title == ' ') title++; } return title; } #endif -int delete_range(char *fpath, int id1, int id2) { - fileheader_t fhdr; - nol_t my; - char fullpath[STRLEN], *t; - int fdr, fdw, fd; - int count; - +int +delete_range(char *fpath, int id1, int id2) +{ + fileheader_t fhdr; + nol_t my; + char fullpath[STRLEN], *t; + int fdr, fdw, fd; + int count; + nolfilename(&my, fpath); - - if((fd = open(my.lockfn, O_RDWR | O_CREAT | O_APPEND, 0644)) == -1) + + if ((fd = open(my.lockfn, O_RDWR | O_CREAT | O_APPEND, 0644)) == -1) return -1; flock(fd, LOCK_EX); - if((fdr = open(fpath, O_RDONLY, 0)) == -1) { + if ((fdr = open(fpath, O_RDONLY, 0)) == -1) { flock(fd, LOCK_UN); close(fd); return -1; } - - if( + if ( ((fdw = open(my.newfn, O_WRONLY | O_CREAT | O_EXCL, 0644)) == -1) && - ((fdw = force_open (my.newfn)) == -1)) { + ((fdw = force_open(my.newfn)) == -1)) { close(fdr); flock(fd, LOCK_UN); close(fd); return -1; } - count = 1; strcpy(fullpath, fpath); t = strrchr(fullpath, '/') + 1; - while(read(fdr, &fhdr, sizeof(fileheader_t)) == sizeof(fileheader_t)) - { + while (read(fdr, &fhdr, sizeof(fileheader_t)) == sizeof(fileheader_t)) { strcpy(t, fhdr.filename); -/* rocker.011018: add new tag delete */ - if ( - (fhdr.filemode & FILE_MARKED) || /* 標記 */ - (fhdr.filemode & FILE_DIGEST) || /* 文摘 */ - (id1 && (count < id1 || count > id2)) || /* range */ - (!id1 && Tagger(atoi (t + 2), count, TAG_NIN))) /* TagList */ - { - if((safewrite(fdw, &fhdr, sizeof(fileheader_t)) == -1)) { + /* rocker.011018: add new tag delete */ + if ( + (fhdr.filemode & FILE_MARKED) || /* 標記 */ + (fhdr.filemode & FILE_DIGEST) || /* 文摘 */ + (id1 && (count < id1 || count > id2)) || /* range */ + (!id1 && Tagger(atoi(t + 2), count, TAG_NIN))) { /* TagList */ + if ((safewrite(fdw, &fhdr, sizeof(fileheader_t)) == -1)) { close(fdr); close(fdw); unlink(my.newfn); @@ -241,17 +257,15 @@ int delete_range(char *fpath, int id1, int id2) { close(fd); return -1; } - } - else - { - //if(dashd(fullpath)) - unlink(fullpath); - } + } else { + //if (dashd(fullpath)) + unlink(fullpath); + } ++count; } close(fdr); close(fdw); - if(Rename(fpath, my.oldfn) == -1 || Rename(my.newfn, fpath) == -1) { + if (Rename(fpath, my.oldfn) == -1 || Rename(my.newfn, fpath) == -1) { flock(fd, LOCK_UN); close(fd); return -1; @@ -261,17 +275,19 @@ int delete_range(char *fpath, int id1, int id2) { return 0; } -int search_rec(char* dirname, int (*filecheck)()) { - fileheader_t fhdr; - FILE *fp; - int ans = 0; - - if(!(fp = fopen(dirname, "r"))) +int +search_rec(char *dirname, int (*filecheck) ()) +{ + fileheader_t fhdr; + FILE *fp; + int ans = 0; + + if (!(fp = fopen(dirname, "r"))) return 0; - - while(fread(&fhdr, sizeof(fhdr), 1, fp)) { + + while (fread(&fhdr, sizeof(fhdr), 1, fp)) { ans++; - if((*filecheck) (&fhdr)) { + if ((*filecheck) (&fhdr)) { fclose(fp); return ans; } @@ -280,34 +296,33 @@ int search_rec(char* dirname, int (*filecheck)()) { return 0; } -int delete_files(char* dirname, int (*filecheck)(), int record) { - fileheader_t fhdr; - FILE *fp, *fptmp; - int ans = 0; - char tmpfname[128]; - char genbuf[256]; - char deleted[256]; - fileheader_t delfh; - char deletedDIR[] = "boards/d/deleted/.DIR"; - +int delete_files(char *dirname, int (*filecheck) (), int record){ + fileheader_t fhdr; + FILE *fp, *fptmp; + int ans = 0; + char tmpfname[128]; + char genbuf[256]; + char deleted[256]; + fileheader_t delfh; + char deletedDIR[] = "boards/d/deleted/.DIR"; + strcpy(deleted, "boards/d/deleted"); - - if(!(fp = fopen(dirname, "r"))) + + if (!(fp = fopen(dirname, "r"))) return ans; - + strcpy(tmpfname, dirname); strcat(tmpfname, "_tmp"); - - if(!(fptmp = fopen(tmpfname, "w"))) { + + if (!(fptmp = fopen(tmpfname, "w"))) { fclose(fp); return ans; } - - while(fread(&fhdr, sizeof(fhdr), 1, fp)){ - if((*filecheck)(&fhdr)) { + while (fread(&fhdr, sizeof(fhdr), 1, fp)) { + if ((*filecheck) (&fhdr)) { ans++; setdirpath(genbuf, dirname, fhdr.filename); - if (record){ + if (record) { deleted[14] = '\0'; stampfile(deleted, &delfh); strcpy(delfh.owner, fhdr.owner); @@ -319,39 +334,41 @@ int delete_files(char* dirname, int (*filecheck)(), int record) { } else fwrite(&fhdr, sizeof(fhdr), 1, fptmp); } - + fclose(fp); fclose(fptmp); unlink(dirname); Rename(tmpfname, dirname); - + return ans; } -int delete_file(char *dirname, int size, int ent, int (*filecheck)()) { - char abuf[BUFSIZE]; - int fd; - struct stat st; - long numents; - - if(ent < 1 || (fd = open(dirname, O_RDWR)) == -1) +int +delete_file(char *dirname, int size, int ent, int (*filecheck) ()) +{ + char abuf[BUFSIZE]; + int fd; + struct stat st; + long numents; + + if (ent < 1 || (fd = open(dirname, O_RDWR)) == -1) return -1; flock(fd, LOCK_EX); fstat(fd, &st); - numents = ((long) st.st_size) / size; - if(((long) st.st_size) % size) + numents = ((long)st.st_size) / size; + if (((long)st.st_size) % size) fprintf(stderr, "align err\n"); - if(lseek(fd, (off_t) size * (ent - 1), SEEK_SET) != -1) { - if(read(fd, abuf, size) == size){ - if((*filecheck) (abuf)) { - int i; - - for(i = ent; i < numents; i++) { - if(lseek(fd, (off_t)((i) * size), SEEK_SET) == -1 || - read(fd, abuf, size) != size || - lseek(fd, (off_t)(i - 1) * size, SEEK_SET) == -1) + if (lseek(fd, (off_t) size * (ent - 1), SEEK_SET) != -1) { + if (read(fd, abuf, size) == size) { + if ((*filecheck) (abuf)) { + int i; + + for (i = ent; i < numents; i++) { + if (lseek(fd, (off_t) ((i) * size), SEEK_SET) == -1 || + read(fd, abuf, size) != size || + lseek(fd, (off_t) (i - 1) * size, SEEK_SET) == -1) break; - if(safewrite(fd, abuf, size) != size) + if (safewrite(fd, abuf, size) != size) break; } ftruncate(fd, (off_t) size * (numents - 1)); @@ -363,15 +380,15 @@ int delete_file(char *dirname, int size, int ent, int (*filecheck)()) { } lseek(fd, 0, SEEK_SET); ent = 1; - while(read(fd, abuf, size) == size) { - if((*filecheck)(abuf)) { - int i; - - for(i = ent; i < numents; i++) { - if(lseek(fd, (off_t) (i + 1) * size, SEEK_SET) == -1 || - read(fd, abuf, size) != size || - lseek(fd, (off_t) (i) * size, SEEK_SET) == -1 || - safewrite(fd, abuf, size) != size) + while (read(fd, abuf, size) == size) { + if ((*filecheck) (abuf)) { + int i; + + for (i = ent; i < numents; i++) { + if (lseek(fd, (off_t) (i + 1) * size, SEEK_SET) == -1 || + read(fd, abuf, size) != size || + lseek(fd, (off_t) (i) * size, SEEK_SET) == -1 || + safewrite(fd, abuf, size) != size) break; } ftruncate(fd, (off_t) size * (numents - 1)); @@ -386,17 +403,17 @@ int delete_file(char *dirname, int size, int ent, int (*filecheck)()) { return -1; } -#endif /* !defined(_BBS_UTIL_C_) */ +#endif /* !defined(_BBS_UTIL_C_) */ + +int apply_record(char *fpath, int (*fptr) (), int size){ + char abuf[BUFSIZE]; + FILE *fp; -int apply_record(char *fpath, int (*fptr)(), int size) { - char abuf[BUFSIZE]; - FILE* fp; - - if(!(fp = fopen(fpath, "r"))) + if (!(fp = fopen(fpath, "r"))) return -1; - - while(fread(abuf, 1, size, fp) == size) - if((*fptr) (abuf) == QUIT) { + + while (fread(abuf, 1, size, fp) == size) + if ((*fptr) (abuf) == QUIT) { fclose(fp); return QUIT; } @@ -405,22 +422,24 @@ int apply_record(char *fpath, int (*fptr)(), int size) { } /* mail / post 時,依據時間建立檔案,加上郵戳 */ -int stampfile(char *fpath, fileheader_t *fh) { - register char *ip = fpath; - time_t dtime=now; - struct tm *ptime; - int fp = 0; +int +stampfile(char *fpath, fileheader_t * fh) +{ + register char *ip = fpath; + time_t dtime = now; + struct tm *ptime; + int fp = 0; - if(access(fpath, X_OK | R_OK | W_OK)) + if (access(fpath, X_OK | R_OK | W_OK)) mkdir(fpath, 0755); while (*(++ip)); *ip++ = '/'; do { - sprintf(ip, "M.%ld.A.%3.3X", ++dtime, rand()&0xFFF ); - if(fp == -1 && errno != EEXIST) + sprintf(ip, "M.%ld.A.%3.3X", ++dtime, rand() & 0xFFF); + if (fp == -1 && errno != EEXIST) return -1; - } while((fp = open(fpath, O_CREAT | O_EXCL | O_WRONLY, 0644)) == -1); + } while ((fp = open(fpath, O_CREAT | O_EXCL | O_WRONLY, 0644)) == -1); close(fp); memset(fh, 0, sizeof(fileheader_t)); strcpy(fh->filename, ip); @@ -429,82 +448,90 @@ int stampfile(char *fpath, fileheader_t *fh) { return 0; } -void stampdir(char *fpath, fileheader_t *fh) { - register char *ip = fpath; - time_t dtime=now; - struct tm *ptime; - - if(access(fpath, X_OK | R_OK | W_OK)) +void +stampdir(char *fpath, fileheader_t * fh) +{ + register char *ip = fpath; + time_t dtime = now; + struct tm *ptime; + + if (access(fpath, X_OK | R_OK | W_OK)) mkdir(fpath, 0755); - - while(*(++ip)); + + while (*(++ip)); *ip++ = '/'; do { sprintf(ip, "D%lX", ++dtime & 07777); - } while(mkdir(fpath, 0755) == -1); + } while (mkdir(fpath, 0755) == -1); memset(fh, 0, sizeof(fileheader_t)); strcpy(fh->filename, ip); ptime = localtime(&dtime); sprintf(fh->date, "%2d/%02d", ptime->tm_mon + 1, ptime->tm_mday); } -void stamplink(char *fpath, fileheader_t *fh) { - register char *ip = fpath; - time_t dtime=now; - struct tm *ptime; +void +stamplink(char *fpath, fileheader_t * fh) +{ + register char *ip = fpath; + time_t dtime = now; + struct tm *ptime; - if(access(fpath, X_OK | R_OK | W_OK)) + if (access(fpath, X_OK | R_OK | W_OK)) mkdir(fpath, 0755); - while(*(++ip)); + while (*(++ip)); *ip++ = '/'; do { - sprintf(ip, "S%lX", ++dtime ); - } while(symlink("temp", fpath) == -1); + sprintf(ip, "S%lX", ++dtime); + } while (symlink("temp", fpath) == -1); memset(fh, 0, sizeof(fileheader_t)); strcpy(fh->filename, ip); ptime = localtime(&dtime); sprintf(fh->date, "%2d/%02d", ptime->tm_mon + 1, ptime->tm_mday); } -int do_append(char *fpath, fileheader_t *record, int size) { - int fd; - - if((fd = open(fpath, O_WRONLY | O_CREAT, 0644)) == -1) { +int +do_append(char *fpath, fileheader_t * record, int size) +{ + int fd; + + if ((fd = open(fpath, O_WRONLY | O_CREAT, 0644)) == -1) { perror("open"); return -1; } flock(fd, LOCK_EX); lseek(fd, 0, SEEK_END); - + safewrite(fd, record, size); - + flock(fd, LOCK_UN); close(fd); return 0; } -int append_record(char *fpath, fileheader_t *record, int size) { +int +append_record(char *fpath, fileheader_t * record, int size) +{ #if !defined(_BBS_UTIL_C_) - int m,n; - if(get_num_records(fpath, sizeof(fileheader_t)) <= MAX_KEEPMAIL * 2) { - FILE *fp; - char buf[512],address[200]; + int m, n; + if (get_num_records(fpath, sizeof(fileheader_t)) <= MAX_KEEPMAIL * 2) { + FILE *fp; + char buf[512], address[200]; - for(n = strlen(fpath) - 1 ; fpath[n] != '/' && n > 0; n--); + for (n = strlen(fpath) - 1; fpath[n] != '/' && n > 0; n--); strncpy(buf, fpath, n + 1); buf[n + 1] = 0; - for(m = strlen(buf) - 2 ; buf[m] != '/' && m > 0 ; m--); + for (m = strlen(buf) - 2; buf[m] != '/' && m > 0; m--); strcat(buf, ".forward"); - if((fp = fopen(buf,"r"))) { - fscanf(fp,"%s",address); + if ((fp = fopen(buf, "r"))) { + fscanf(fp, "%s", address); fclose(fp); - if(buf[0] != 0 && buf[0] != ' ') { + if (buf[0] != 0 && buf[0] != ' ') { buf[n + 1] = 0; strcat(buf, record->filename); - do_append(fpath,record,size); + do_append(fpath, record, size); #ifndef USE_BSMTP - bbs_sendmail(buf,record->title,address); + bbs_sendmail(buf, record->title, address); #else bsmtp(buf, record->title, address, 0); #endif @@ -512,9 +539,9 @@ int append_record(char *fpath, fileheader_t *record, int size) { } } } -#endif - - do_append(fpath,record,size); - +#endif + + do_append(fpath, record, size); + return 0; } diff --git a/pttbbs/mbbsd/register.c b/pttbbs/mbbsd/register.c index a3fa13ef..f2b50a9b 100644 --- a/pttbbs/mbbsd/register.c +++ b/pttbbs/mbbsd/register.c @@ -1,24 +1,26 @@ -/* $Id: register.c,v 1.5 2002/06/04 13:08:34 in2 Exp $ */ +/* $Id: register.c,v 1.6 2002/07/05 17:10:28 in2 Exp $ */ #define _XOPEN_SOURCE #include "bbs.h" /* password encryption */ -static char pwbuf[14]; +static char pwbuf[14]; + +char * +genpasswd(char *pw) +{ + if (pw[0]) { + char saltc[2], c; + int i; -char *genpasswd(char *pw) { - if(pw[0]) { - char saltc[2], c; - int i; - i = 9 * getpid(); saltc[0] = i & 077; saltc[1] = (i >> 6) & 077; - - for(i = 0; i < 2; i++) { + + for (i = 0; i < 2; i++) { c = saltc[i] + '.'; - if(c > '9') + if (c > '9') c += 7; - if(c > 'Z') + if (c > 'Z') c += 6; saltc[i] = c; } @@ -28,34 +30,39 @@ char *genpasswd(char *pw) { return ""; } -int checkpasswd(char *passwd, char *test) { - char *pw; - +int +checkpasswd(char *passwd, char *test) +{ + char *pw; + strncpy(pwbuf, test, 14); pw = crypt(pwbuf, passwd); return (!strncmp(pw, passwd, 14)); } /* 檢查 user 註冊情況 */ -int bad_user_id(char *userid) { - int len, i; +int +bad_user_id(char *userid) +{ + int len, i; len = strlen(userid); - if(len < 2) + if (len < 2) return 1; if (not_alpha(userid[0])) return 1; - for (i=1; i<len; i++) //DickG:修正了只比較 userid 第一個字元的 bug - if(not_alnum(userid[i])) - return 1; - - if(strcasecmp(userid, str_new) == 0) + for (i = 1; i < len; i++) +//DickG:修正了 u 騆userid 臚@個字 葵槓ug + if (not_alnum(userid[i])) + return 1; + + if (strcasecmp(userid, str_new) == 0) return 1; - - /* while((ch = *(++userid))) - if(not_alnum(ch)) - return 1;*/ + + /* + * while((ch = *(++userid))) if(not_alnum(ch)) return 1; + */ return 0; } @@ -64,23 +71,25 @@ int bad_user_id(char *userid) { /* (a) is the worst user currently */ /* (b) is the object to be compared */ /* -------------------------------- */ -static int compute_user_value(userec_t *urec, time_t clock) { - int value; - +static int +compute_user_value(userec_t * urec, time_t clock) +{ + int value; + /* if (urec) has XEMPT permission, don't kick it */ - if((urec->userid[0] == '\0') || (urec->userlevel & PERM_XEMPT) - /*|| (urec->userlevel & PERM_LOGINOK)*/ - || !strcmp(STR_GUEST,urec->userid)) + if ((urec->userid[0] == '\0') || (urec->userlevel & PERM_XEMPT) + /* || (urec->userlevel & PERM_LOGINOK) */ + || !strcmp(STR_GUEST, urec->userid)) return 999999; - value = (clock - urec->lastlogin) / 60; /* minutes */ - + value = (clock - urec->lastlogin) / 60; /* minutes */ + /* new user should register in 30 mins */ - if(strcmp(urec->userid, str_new) == 0) + if (strcmp(urec->userid, str_new) == 0) return 30 - value; -#if 0 - if (!urec->numlogins) /* 未 login 成功者,不保留 */ +#if 0 + if (!urec->numlogins) /* 未 login 成功者,不保留 */ return -1; - if (urec->numlogins <= 3) /* #login 少於三者,保留 20 天 */ + if (urec->numlogins <= 3) /* #login 少於三者,保留 20 天 */ return 20 * 24 * 60 - value; #endif /* 未完成註冊者,保留 15 天 */ @@ -88,87 +97,86 @@ static int compute_user_value(userec_t *urec, time_t clock) { return (urec->userlevel & PERM_LOGINOK ? 120 : 15) * 24 * 60 - value; } -int check_and_expire_account(int uid,userec_t *urec) +int +check_and_expire_account(int uid, userec_t * urec) { - userec_t zerorec; - char genbuf[200],genbuf2[200]; - int val; - if((val = compute_user_value(urec, now)) < 0) { - sprintf(genbuf, "#%d %-12s %15.15s %d %d %d", - uid, urec->userid, ctime(&(urec->lastlogin)) + 4, - urec->numlogins, urec->numposts, val); - if(val > -1 * 60 * 24 * 365) { + userec_t zerorec; + char genbuf[200], genbuf2[200]; + int val; + if ((val = compute_user_value(urec, now)) < 0) { + sprintf(genbuf, "#%d %-12s %15.15s %d %d %d", + uid, urec->userid, ctime(&(urec->lastlogin)) + 4, + urec->numlogins, urec->numposts, val); + if (val > -1 * 60 * 24 * 365) { memset(&zerorec, 0, sizeof(zerorec)); - log_usies("CLEAN", genbuf); - sprintf(genbuf, "home/%c/%s", urec->userid[0], - urec->userid); - sprintf(genbuf2, "tmp/%s", urec->userid); - if(dashd(genbuf) && Rename(genbuf, genbuf2)) { - sprintf(genbuf, "/bin/rm -fr home/%c/%s >/dev/null 2>&1", - urec->userid[0],urec->userid); - system(genbuf); - } + log_usies("CLEAN", genbuf); + sprintf(genbuf, "home/%c/%s", urec->userid[0], + urec->userid); + sprintf(genbuf2, "tmp/%s", urec->userid); + if (dashd(genbuf) && Rename(genbuf, genbuf2)) { + sprintf(genbuf, "/bin/rm -fr home/%c/%s >/dev/null 2>&1", + urec->userid[0], urec->userid); + system(genbuf); + } passwd_update(uid, &zerorec); remove_from_uhash(uid - 1); add_to_uhash(uid - 1, ""); - } - else - { - val=0; - log_usies("DATED", genbuf); - } + } else { + val = 0; + log_usies("DATED", genbuf); } + } return val; } -int getnewuserid() { - char genbuf[50]; - static char *fn_fresh = ".fresh"; - userec_t utmp,zerorec; - time_t clock; - struct stat st; - int fd, i; - +int +getnewuserid() +{ + char genbuf[50]; + static char *fn_fresh = ".fresh"; + userec_t utmp, zerorec; + time_t clock; + struct stat st; + int fd, i; + memset(&zerorec, 0, sizeof(zerorec)); clock = now; - + /* Lazy method : 先找尋已經清除的過期帳號 */ - if((i = searchnewuser(0)) == 0) { + if ((i = searchnewuser(0)) == 0) { /* 每 1 個小時,清理 user 帳號一次 */ - if((stat(fn_fresh, &st) == -1) || (st.st_mtime < clock - 3600)) { - if((fd = open(fn_fresh, O_RDWR | O_CREAT, 0600)) == -1) + if ((stat(fn_fresh, &st) == -1) || (st.st_mtime < clock - 3600)) { + if ((fd = open(fn_fresh, O_RDWR | O_CREAT, 0600)) == -1) return -1; write(fd, ctime(&clock), 25); close(fd); log_usies("CLEAN", "dated users"); - + fprintf(stdout, "尋找新帳號中, 請稍待片刻...\n\r"); - - if((fd = open(fn_passwd, O_RDWR | O_CREAT, 0600)) == -1) + + if ((fd = open(fn_passwd, O_RDWR | O_CREAT, 0600)) == -1) return -1; - + /* 不曉得為什麼要從 2 開始... Ptt:因為SYSOP在1 */ - for(i = 2; i <= MAX_USERS; i++) { + for (i = 2; i <= MAX_USERS; i++) { passwd_query(i, &utmp); - check_and_expire_account(i,&utmp); + check_and_expire_account(i, &utmp); } } } - passwd_lock(); i = searchnewuser(1); - if((i <= 0) || (i > MAX_USERS)) { + if ((i <= 0) || (i > MAX_USERS)) { passwd_unlock(); - if(more("etc/user_full", NA) == -1) + if (more("etc/user_full", NA) == -1) fprintf(stdout, "抱歉,使用者帳號已經滿了,無法註冊新的帳號\n\r"); safe_sleep(2); exit(1); } - sprintf(genbuf, "uid %d", i); log_usies("APPLY", genbuf); - + strcpy(zerorec.userid, str_new); zerorec.lastlogin = clock; passwd_update(i, &zerorec); @@ -177,19 +185,21 @@ int getnewuserid() { return i; } -void new_register() { - userec_t newuser; - char passbuf[STRLEN]; - int allocid, try, id; +void +new_register() +{ + userec_t newuser; + char passbuf[STRLEN]; + int allocid, try, id; memset(&newuser, 0, sizeof(newuser)); more("etc/register", NA); try = 0; - while(1) { - if(++try >= 6) { + while (1) { + if (++try >= 6) { outs("\n您嘗試錯誤的輸入太多,請下次再來吧\n"); refresh(); - + pressanykey(); oflush(); exit(1); @@ -197,42 +207,39 @@ void new_register() { getdata(17, 0, msg_uid, newuser.userid, sizeof(newuser.userid), DOECHO); - if(bad_user_id(newuser.userid)) + if (bad_user_id(newuser.userid)) outs("無法接受這個代號,請使用英文字母,並且不要包含空格\n"); - else if ((id=getuser(newuser.userid)) && - (id=check_and_expire_account(id,&xuser))>=0) - { - if(id==999999) + else if ((id = getuser(newuser.userid)) && + (id = check_and_expire_account(id, &xuser)) >= 0) { + if (id == 999999) outs("此代號已經有人使用 是不死之身"); - else - { - sprintf(passbuf,"此代號已經有人使用 還有%d天才過期 \n",id/(60*24)); - outs(passbuf); - } - } - else + else { + sprintf(passbuf, "此代號已經有人使用 還有%d天才過期 \n", id / (60 * 24)); + outs(passbuf); + } + } else break; } try = 0; - while(1) { - if(++try >= 6) { + while (1) { + if (++try >= 6) { outs("\n您嘗試錯誤的輸入太多,請下次再來吧\n"); refresh(); - + pressanykey(); oflush(); exit(1); } - if((getdata(19, 0, "請設定密碼:", passbuf, - sizeof(passbuf), NOECHO) < 3) || - !strcmp(passbuf, newuser.userid)) { + if ((getdata(19, 0, "請設定密碼:", passbuf, + sizeof(passbuf), NOECHO) < 3) || + !strcmp(passbuf, newuser.userid)) { outs("密碼太簡單,易遭入侵,至少要 4 個字,請重新輸入\n"); continue; } strncpy(newuser.passwd, passbuf, PASSLEN); getdata(20, 0, "請檢查密碼:", passbuf, sizeof(passbuf), NOECHO); - if(strncmp(passbuf, newuser.passwd, PASSLEN)) { + if (strncmp(passbuf, newuser.passwd, PASSLEN)) { outs("密碼輸入錯誤, 請重新輸入密碼.\n"); continue; } @@ -246,76 +253,69 @@ void new_register() { newuser.money = 0; newuser.pager = 1; allocid = getnewuserid(); - if(allocid > MAX_USERS || allocid <= 0) { + if (allocid > MAX_USERS || allocid <= 0) { fprintf(stderr, "本站人口已達飽和!\n"); exit(1); } - - if(passwd_update(allocid, &newuser) == -1) { + if (passwd_update(allocid, &newuser) == -1) { fprintf(stderr, "客滿了,再見!\n"); exit(1); } setuserid(allocid, newuser.userid); - if(!dosearchuser(newuser.userid)) { + if (!dosearchuser(newuser.userid)) { fprintf(stderr, "無法建立帳號\n"); exit(1); } } -void check_register() { - char *ptr = NULL; - +void +check_register() +{ + char *ptr = NULL; + stand_title("請詳細填寫個人資料"); - - while(strlen(cuser.username) < 2) + + while (strlen(cuser.username) < 2) getdata(2, 0, "綽號暱稱:", cuser.username, sizeof(cuser.username), DOECHO); - for(ptr = cuser.username; *ptr; ptr++) { - if (*ptr == 9) /* TAB convert */ + for (ptr = cuser.username; *ptr; ptr++) { + if (*ptr == 9) /* TAB convert */ *ptr = ' '; } - while(strlen(cuser.realname) < 4) + while (strlen(cuser.realname) < 4) getdata(4, 0, "真實姓名:", cuser.realname, sizeof(cuser.realname), DOECHO); - - while(strlen(cuser.address) < 8) + + while (strlen(cuser.address) < 8) getdata(6, 0, "聯絡地址:", cuser.address, sizeof(cuser.address), DOECHO); /* - if(!strchr(cuser.email, '@')) { - bell(); - move(t_lines - 4, 0); - prints("※ 為了您的權益,請填寫真實的 E-mail address," - "以資確認閣下身份,\n" - "格式為 \033[44muser@domain_name\033[0m 或 \033[44muser" - "@\\[ip_number\\]\033[0m。\n\n" - "※ 如果您真的沒有 E-mail,請直接按 [return] 即可。"); - - do { - getdata(8, 0, "電子信箱:", - cuser.email, sizeof(cuser.email), DOECHO); - if(!cuser.email[0]) - sprintf(cuser.email, "%s%s", cuser.userid, str_mail_address); - } while(!strchr(cuser.email, '@')); - - } - */ - if(!HAS_PERM(PERM_SYSOP) && !HAS_PERM(PERM_LOGINOK)) { + * if(!strchr(cuser.email, '@')) { bell(); move(t_lines - 4, 0); prints(" + * 您的權益,請填寫真實的 E-mail address," "以資確認閣下身份,\n" " + * 033[44muser@domain_name\033[0m 或 \033[44muser" + * "@\\[ip_number\\]\033[0m。\n\n" "※ 如果您真的沒有 E-mail, + * turn] 即可。"); + * + * do { getdata(8, 0, "電子信箱:", cuser.email, sizeof(cuser.email), + * DOECHO); if(!cuser.email[0]) sprintf(cuser.email, "%s%s", + * cuser.userid, str_mail_address); } while(!strchr(cuser.email, '@')); + * + * } */ + if (!HAS_PERM(PERM_SYSOP) && !HAS_PERM(PERM_LOGINOK)) { /* 回覆過身份認證信函,或曾經 E-mail post 過 */ clear(); - move(9,3); + move(9, 3); prints("請詳填寫\033[32m註冊申請單\033[m," "通告站長以獲得進階使用權力。\n\n\n\n"); u_register(); } - #ifdef NEWUSER_LIMIT - if(!(cuser.userlevel & PERM_LOGINOK) && !HAS_PERM(PERM_SYSOP)) { - if(cuser.lastlogin - cuser.firstlogin < 3 * 86400) + if (!(cuser.userlevel & PERM_LOGINOK) && !HAS_PERM(PERM_SYSOP)) { + if (cuser.lastlogin - cuser.firstlogin < 3 * 86400) cuser.userlevel &= ~PERM_POST; more("etc/newuser", YEA); } diff --git a/pttbbs/mbbsd/screen.c b/pttbbs/mbbsd/screen.c index 5bd9dbdb..12901158 100644 --- a/pttbbs/mbbsd/screen.c +++ b/pttbbs/mbbsd/screen.c @@ -1,11 +1,11 @@ -/* $Id: screen.c,v 1.3 2002/06/04 13:08:34 in2 Exp $ */ +/* $Id: screen.c,v 1.4 2002/07/05 17:10:28 in2 Exp $ */ #include "bbs.h" -#ifdef SUPPORT_GB -static int current_font_type=TYPE_BIG5; -static int gbinited=0; +#ifdef SUPPORT_GB +static int current_font_type = TYPE_BIG5; +static int gbinited = 0; #endif -#define SCR_WIDTH 80 +#define SCR_WIDTH 80 #define o_clear() output(clearbuf,clearbuflen) #define o_cleol() output(cleolbuf,cleolbuflen) #define o_scrollrev() output(scrollrev,scrollrevlen) @@ -15,16 +15,18 @@ static int gbinited=0; static unsigned char cur_ln = 0, cur_col = 0; static unsigned char docls, downfrom = 0; static unsigned char standing = NA; -static char roll = 0; -static int scrollcnt, tc_col, tc_line; +static char roll = 0; +static int scrollcnt, tc_col, tc_line; -#define MODIFIED (1) /* if line has been modifed, screen output */ -#define STANDOUT (2) /* if this line has a standout region */ +#define MODIFIED (1) /* if line has been modifed, screen output */ +#define STANDOUT (2) /* if this line has a standout region */ -int tputs(const char *str, int affcnt, int (*putc)(int)); +int tputs(const char *str, int affcnt, int (*putc) (int)); -void initscr() { - if(!big_picture) { +void +initscr() +{ + if (!big_picture) { scr_lns = t_lines; scr_cols = t_columns = ANSILINELEN; /* scr_cols = MIN(t_columns, ANSILINELEN); */ @@ -33,40 +35,45 @@ void initscr() { } } -void move(int y, int x) { +void +move(int y, int x) +{ cur_col = x; cur_ln = y; } -void getyx(int *y, int *x) { +void +getyx(int *y, int *x) +{ *y = cur_ln; *x = cur_col; } -static void rel_move(int was_col, int was_ln, int new_col, int new_ln) { - if(new_ln >= t_lines || new_col >= t_columns) +static void +rel_move(int was_col, int was_ln, int new_col, int new_ln) +{ + if (new_ln >= t_lines || new_col >= t_columns) return; tc_col = new_col; tc_line = new_ln; - if(new_col == 0) { - if(new_ln == was_ln) { - if(was_col) + if (new_col == 0) { + if (new_ln == was_ln) { + if (was_col) ochar('\r'); return; - } else if(new_ln == was_ln + 1) { + } else if (new_ln == was_ln + 1) { ochar('\n'); - if(was_col) + if (was_col) ochar('\r'); return; } } - - if(new_ln == was_ln) { - if(was_col == new_col) + if (new_ln == was_ln) { + if (was_col == new_col) return; - if(new_col == was_col - 1) { + if (new_col == was_col - 1) { ochar(Ctrl('H')); return; } @@ -74,47 +81,51 @@ static void rel_move(int was_col, int was_ln, int new_col, int new_ln) { do_move(new_col, new_ln); } -static void standoutput(char *buf, int ds, int de, int sso, int eso) { - int st_start, st_end; - - if(eso <= ds || sso >= de) { +static void +standoutput(char *buf, int ds, int de, int sso, int eso) +{ + int st_start, st_end; + + if (eso <= ds || sso >= de) { output(buf + ds, de - ds); } else { st_start = MAX(sso, ds); st_end = MIN(eso, de); - if(sso > ds) + if (sso > ds) output(buf + ds, sso - ds); o_standup(); output(buf + st_start, st_end - st_start); o_standdown(); - if(de > eso) + if (de > eso) output(buf + eso, de - eso); } } -void redoscr() { +void +redoscr() +{ register screenline_t *bp; - register int i, j, len; + register int i, j, len; o_clear(); - for(tc_col = tc_line = i = 0, j = roll; i < scr_lns; i++, j++) { - if(j >= scr_lns) + for (tc_col = tc_line = i = 0, j = roll; i < scr_lns; i++, j++) { + if (j >= scr_lns) j = 0; bp = &big_picture[j]; - if((len = bp->len)) { + if ((len = bp->len)) { rel_move(tc_col, tc_line, 0, i); - if(bp->mode & STANDOUT) + if (bp->mode & STANDOUT) standoutput((char *)bp->data, 0, len, bp->sso, bp->eso); else output((char *)bp->data, len); tc_col += len; - if(tc_col >= t_columns) { + if (tc_col >= t_columns) { if (automargins) tc_col = t_columns - 1; else { tc_col -= t_columns; tc_line++; - if(tc_line >= t_lines) + if (tc_line >= t_lines) tc_line = b_lines; } } @@ -127,61 +138,60 @@ void redoscr() { oflush(); } -void refresh() { +void +refresh() +{ register screenline_t *bp = big_picture; - register int i, j, len; - if(num_in_buf()) + register int i, j, len; + if (num_in_buf()) return; - if((docls) || (abs(scrollcnt) >= (scr_lns - 3))) { + if ((docls) || (abs(scrollcnt) >= (scr_lns - 3))) { redoscr(); return; } - - if(scrollcnt < 0) { - if(!scrollrevlen) { + if (scrollcnt < 0) { + if (!scrollrevlen) { redoscr(); return; } rel_move(tc_col, tc_line, 0, 0); do { o_scrollrev(); - } while(++scrollcnt); + } while (++scrollcnt); } else if (scrollcnt > 0) { rel_move(tc_col, tc_line, 0, b_lines); do { ochar('\n'); - } while(--scrollcnt); + } while (--scrollcnt); } - - for(i = 0, j = roll; i < scr_lns; i++, j++) { - if(j >= scr_lns) + for (i = 0, j = roll; i < scr_lns; i++, j++) { + if (j >= scr_lns) j = 0; bp = &big_picture[j]; len = bp->len; - if(bp->mode & MODIFIED && bp->smod < len) { + if (bp->mode & MODIFIED && bp->smod < len) { bp->mode &= ~(MODIFIED); - if(bp->emod >= len) + if (bp->emod >= len) bp->emod = len - 1; rel_move(tc_col, tc_line, bp->smod, i); - if(bp->mode & STANDOUT) + if (bp->mode & STANDOUT) standoutput((char *)bp->data, bp->smod, bp->emod + 1, bp->sso, bp->eso); else output((char *)&bp->data[bp->smod], bp->emod - bp->smod + 1); tc_col = bp->emod + 1; - if(tc_col >= t_columns) { - if(automargins) { + if (tc_col >= t_columns) { + if (automargins) { tc_col -= t_columns; - if(++tc_line >= t_lines) + if (++tc_line >= t_lines) tc_line = b_lines; } else tc_col = t_columns - 1; } } - - if(bp->oldlen > len) { + if (bp->oldlen > len) { rel_move(tc_col, tc_line, len, i); o_cleol(); } @@ -194,134 +204,137 @@ void refresh() { oflush(); } -void clear() { +void +clear() +{ register screenline_t *slp; - register int i; + register int i; docls = YEA; cur_col = cur_ln = roll = downfrom = i = 0; do { slp = &big_picture[i]; slp->mode = slp->len = slp->oldlen = 0; - } while(++i < scr_lns); + } while (++i < scr_lns); } -void clrtoeol() { +void +clrtoeol() +{ register screenline_t *slp; - register int ln; + register int ln; standing = NA; - if((ln = cur_ln + roll) >= scr_lns) + if ((ln = cur_ln + roll) >= scr_lns) ln -= scr_lns; slp = &big_picture[ln]; - if(cur_col <= slp->sso) + if (cur_col <= slp->sso) slp->mode &= ~STANDOUT; - if(cur_col > slp->oldlen) { - for(ln = slp->len; ln <= cur_col; ln++) + if (cur_col > slp->oldlen) { + for (ln = slp->len; ln <= cur_col; ln++) slp->data[ln] = ' '; } - - if(cur_col < slp->oldlen) { - for(ln = slp->len; ln >= cur_col; ln--) + if (cur_col < slp->oldlen) { + for (ln = slp->len; ln >= cur_col; ln--) slp->data[ln] = ' '; } - slp->len = cur_col; } -void clrtoline(int line) { +void +clrtoline(int line) +{ register screenline_t *slp; - register int i, j; + register int i, j; - for(i = cur_ln, j = i + roll; i < line; i++, j++) { - if(j >= scr_lns) + for (i = cur_ln, j = i + roll; i < line; i++, j++) { + if (j >= scr_lns) j -= scr_lns; slp = &big_picture[j]; slp->mode = slp->len = 0; - if(slp->oldlen) + if (slp->oldlen) slp->oldlen = 255; } -} +} -void clrtobot() { +void +clrtobot() +{ clrtoline(scr_lns); } -void outch(unsigned char c) { +void +outch(unsigned char c) +{ register screenline_t *slp; - register int i; + register int i; - if((i = cur_ln + roll) >= scr_lns) + if ((i = cur_ln + roll) >= scr_lns) i -= scr_lns; slp = &big_picture[i]; - - if(c == '\n' || c == '\r') { - if(standing) { + + if (c == '\n' || c == '\r') { + if (standing) { slp->eso = MAX(slp->eso, cur_col); standing = NA; } - if((i = cur_col - slp->len) > 0) + if ((i = cur_col - slp->len) > 0) memset(&slp->data[slp->len], ' ', i + 1); slp->len = cur_col; cur_col = 0; - if(cur_ln < scr_lns) + if (cur_ln < scr_lns) cur_ln++; return; } -/* - else if(c != '\033' && !isprint2(c)) - { - c = '*'; //substitute a '*' for non-printable - } -*/ - if(cur_col >= slp->len) { - for(i = slp->len; i < cur_col; i++) + /* + * else if(c != '\033' && !isprint2(c)) { c = '*'; //substitute a '*' for + * non-printable } + */ + if (cur_col >= slp->len) { + for (i = slp->len; i < cur_col; i++) slp->data[i] = ' '; slp->data[cur_col] = '\0'; slp->len = cur_col + 1; } - - if(slp->data[cur_col] != c) { + if (slp->data[cur_col] != c) { slp->data[cur_col] = c; - if((slp->mode & MODIFIED) != MODIFIED) + if ((slp->mode & MODIFIED) != MODIFIED) slp->smod = slp->emod = cur_col; slp->mode |= MODIFIED; - if(cur_col > slp->emod) + if (cur_col > slp->emod) slp->emod = cur_col; - if(cur_col < slp->smod) + if (cur_col < slp->smod) slp->smod = cur_col; } - - if (++cur_col >= scr_cols) - { - if (standing && (slp->mode & STANDOUT)) - { + if (++cur_col >= scr_cols) { + if (standing && (slp->mode & STANDOUT)) { standing = 0; slp->eso = MAX(slp->eso, cur_col); } cur_col = 0; if (cur_ln < scr_lns) cur_ln++; - } - + } } -static void parsecolor(char *buf) { - char *val; - char data[24]; - +static void +parsecolor(char *buf) +{ + char *val; + char data[24]; + data[0] = '\0'; val = (char *)strtok(buf, ";"); - while(val) { - if(atoi(val) < 30) { - if(data[0]) + while (val) { + if (atoi(val) < 30) { + if (data[0]) strcat(data, ";"); strcat(data, val); } - val = (char *) strtok(NULL, ";"); + val = (char *)strtok(NULL, ";"); } strcpy(buf, data); } @@ -330,24 +343,26 @@ static void parsecolor(char *buf) { #define ESCAPE (01) #define VTKEYS (02) -void outc(unsigned char ch) { - if(showansi) +void +outc(unsigned char ch) +{ + if (showansi) outch(ch); else { - static char buf[24]; - static int p = 0; - static int mode = NORMAL; - int i; + static char buf[24]; + static int p = 0; + static int mode = NORMAL; + int i; - switch(mode) { + switch (mode) { case NORMAL: - if(ch == '\033') + if (ch == '\033') mode = ESCAPE; else outch(ch); return; case ESCAPE: - if(ch == '[') + if (ch == '[') mode = VTKEYS; else { mode = NORMAL; @@ -356,18 +371,18 @@ void outc(unsigned char ch) { } return; case VTKEYS: - if(ch == 'm') { + if (ch == 'm') { buf[p++] = '\0'; parsecolor(buf); - } else if((p < 24) && (not_alpha(ch))) { + } else if ((p < 24) && (not_alpha(ch))) { buf[p++] = ch; return; } - if(buf[0]) { + if (buf[0]) { outch(''); outch('['); - for(i = 0; (p = buf[i]); i++) + for (i = 0; (p = buf[i]); i++) outch(p); outch(ch); } @@ -377,49 +392,55 @@ void outc(unsigned char ch) { } } -static void do_outs(char *str) { - while(*str) - { - outc(*str++); +static void +do_outs(char *str) +{ + while (*str) { + outc(*str++); } -} -#ifdef SUPPORT_GB -static void gb_init() +} +#ifdef SUPPORT_GB +static void +gb_init() { - if(current_font_type == TYPE_GB) - { - hc_readtab(BBSHOME"/etc/hc.tab"); + if (current_font_type == TYPE_GB) { + hc_readtab(BBSHOME "/etc/hc.tab"); } gbinited = 1; } -static void gb_outs(char *str) +static void +gb_outs(char *str) { do_outs(hc_convert_str(str, HC_BIGtoGB, HC_DO_SINGLE)); -} +} #endif -int edit_outs(char *text) { - register int column = 0; - register char ch; -#ifdef SUPPORT_GB - if(current_font_type == TYPE_GB) +int +edit_outs(char *text) +{ + register int column = 0; + register char ch; +#ifdef SUPPORT_GB + if (current_font_type == TYPE_GB) text = hc_convert_str(text, HC_BIGtoGB, HC_DO_SINGLE); #endif - while((ch = *text++) && (++column < SCR_WIDTH)) - outch(ch == 27 ? '*' : ch); + while ((ch = *text++) && (++column < SCR_WIDTH)) + outch(ch == 27 ? '*' : ch); return 0; -} +} -void outs(char *str) { -#ifdef SUPPORT_GB - if(current_font_type == TYPE_BIG5) +void +outs(char *str) +{ +#ifdef SUPPORT_GB + if (current_font_type == TYPE_BIG5) #endif do_outs(str); -#ifdef SUPPORT_GB - else - { - if(!gbinited) gb_init(); +#ifdef SUPPORT_GB + else { + if (!gbinited) + gb_init(); gb_outs(str); } #endif @@ -427,33 +448,39 @@ void outs(char *str) { /* Jaky */ -void Jaky_outs(char *str, int line) { -#ifdef SUPPORT_GB - if(current_font_type == TYPE_GB) - str = hc_convert_str(str, HC_BIGtoGB, HC_DO_SINGLE); +void +Jaky_outs(char *str, int line) +{ +#ifdef SUPPORT_GB + if (current_font_type == TYPE_GB) + str = hc_convert_str(str, HC_BIGtoGB, HC_DO_SINGLE); #endif - while(*str && line) { + while (*str && line) { outc(*str); - if(*str=='\n') + if (*str == '\n') line--; str++; } } -void outmsg(char *msg) { +void +outmsg(char *msg) +{ move(b_lines, 0); clrtoeol(); -#ifdef SUPPORT_GB - if(current_font_type == TYPE_GB) - msg = hc_convert_str(msg, HC_BIGtoGB, HC_DO_SINGLE); +#ifdef SUPPORT_GB + if (current_font_type == TYPE_GB) + msg = hc_convert_str(msg, HC_BIGtoGB, HC_DO_SINGLE); #endif - while(*msg) + while (*msg) outc(*msg++); } -void prints(char *fmt, ...) { - va_list args; - char buff[1024]; +void +prints(char *fmt,...) +{ + va_list args; + char buff[1024]; va_start(args, fmt); vsprintf(buff, fmt, args); @@ -461,41 +488,48 @@ void prints(char *fmt, ...) { outs(buff); } -void mprints(int y, int x, char *str) { +void +mprints(int y, int x, char *str) +{ move(y, x); clrtoeol(); prints(str); -} +} -void scroll() { +void +scroll() +{ scrollcnt++; - if(++roll >= scr_lns) + if (++roll >= scr_lns) roll = 0; move(b_lines, 0); clrtoeol(); } -void rscroll() { +void +rscroll() +{ scrollcnt--; - if(--roll < 0) + if (--roll < 0) roll = b_lines; move(0, 0); clrtoeol(); } -void region_scroll_up(int top, int bottom) { - int i; +void +region_scroll_up(int top, int bottom) +{ + int i; - if(top > bottom) { - i = top; + if (top > bottom) { + i = top; top = bottom; bottom = i; } - - if(top < 0 || bottom >= scr_lns) + if (top < 0 || bottom >= scr_lns) return; - for(i = top; i < bottom; i++) + for (i = top; i < bottom; i++) big_picture[i] = big_picture[i + 1]; memset(big_picture + i, 0, sizeof(*big_picture)); memset(big_picture[i].data, ' ', scr_cols); @@ -508,8 +542,10 @@ void region_scroll_up(int top, int bottom) { refresh(); } -void standout() { - if(!standing && strtstandoutlen) { +void +standout() +{ + if (!standing && strtstandoutlen) { register screenline_t *slp; slp = &big_picture[((cur_ln + roll) % scr_lns)]; @@ -519,8 +555,10 @@ void standout() { } } -void standend() { - if(standing && strtstandoutlen) { +void +standend() +{ + if (standing && strtstandoutlen) { register screenline_t *slp; slp = &big_picture[((cur_ln + roll) % scr_lns)]; diff --git a/pttbbs/mbbsd/stuff.c b/pttbbs/mbbsd/stuff.c index c563fc29..98c38e19 100644 --- a/pttbbs/mbbsd/stuff.c +++ b/pttbbs/mbbsd/stuff.c @@ -1,71 +1,97 @@ -/* $Id: stuff.c,v 1.6 2002/06/29 15:10:01 ptt Exp $ */ +/* $Id: stuff.c,v 1.7 2002/07/05 17:10:28 in2 Exp $ */ #include "bbs.h" /* ----------------------------------------------------- */ /* set file path for boards/user home */ /* ----------------------------------------------------- */ -static char *str_home_file = "home/%c/%s/%s"; -static char *str_board_file = "boards/%c/%s/%s"; +static char *str_home_file = "home/%c/%s/%s"; +static char *str_board_file = "boards/%c/%s/%s"; #define STR_DOTDIR ".DIR" -static char *str_dotdir = STR_DOTDIR; +static char *str_dotdir = STR_DOTDIR; -void setcalfile(char *buf, char *userid) { +void +setcalfile(char *buf, char *userid) +{ sprintf(buf, "home/%c/%s/calendar", userid[0], userid); } -void sethomepath(char *buf, char *userid) { +void +sethomepath(char *buf, char *userid) +{ sprintf(buf, "home/%c/%s", userid[0], userid); } -void sethomedir(char *buf, char *userid) { +void +sethomedir(char *buf, char *userid) +{ sprintf(buf, str_home_file, userid[0], userid, str_dotdir); } -void sethomeman(char *buf, char *userid) { +void +sethomeman(char *buf, char *userid) +{ sprintf(buf, str_home_file, userid[0], userid, "man"); } -void sethomefile(char *buf, char *userid, char *fname) { +void +sethomefile(char *buf, char *userid, char *fname) +{ sprintf(buf, str_home_file, userid[0], userid, fname); } -void setuserfile(char *buf, char *fname) { +void +setuserfile(char *buf, char *fname) +{ sprintf(buf, str_home_file, cuser.userid[0], cuser.userid, fname); } -void setapath(char *buf, char *boardname) { +void +setapath(char *buf, char *boardname) +{ sprintf(buf, "man/boards/%c/%s", boardname[0], boardname); } -void setadir(char *buf, char *path) { +void +setadir(char *buf, char *path) +{ sprintf(buf, "%s/%s", path, str_dotdir); } -void setbpath(char *buf, char *boardname) { +void +setbpath(char *buf, char *boardname) +{ sprintf(buf, "boards/%c/%s", boardname[0], boardname); } -void setbdir(char *buf, char *boardname) { +void +setbdir(char *buf, char *boardname) +{ sprintf(buf, str_board_file, boardname[0], boardname, currmode & MODE_ETC ? ".ETC" : (currmode & MODE_DIGEST ? fn_mandex : str_dotdir)); } -void setbfile(char *buf, char *boardname, char *fname) { +void +setbfile(char *buf, char *boardname, char *fname) +{ sprintf(buf, str_board_file, boardname[0], boardname, fname); } -void setdirpath(char *buf, char *direct, char *fname) { +void +setdirpath(char *buf, char *direct, char *fname) +{ strcpy(buf, direct); direct = strrchr(buf, '/'); strcpy(direct + 1, fname); } -char *subject(char *title) { - if(!strncasecmp(title, str_reply, 3)) { +char * +subject(char *title) +{ + if (!strncasecmp(title, str_reply, 3)) { title += 3; - if(*title == ' ') + if (*title == ' ') title++; } return title; @@ -74,38 +100,46 @@ char *subject(char *title) { /* ----------------------------------------------------- */ /* 字串轉換檢查函數 */ /* ----------------------------------------------------- */ -int str_checksum(char *str) { - int n = 1; - if(strlen(str) < 6) +int +str_checksum(char *str) +{ + int n = 1; + if (strlen(str) < 6) return 0; - while(*str) - n += *(str++) * (n); + while (*str) + n += *(str++) * (n); return n; } -void str_lower(char *t, char *s) { +void +str_lower(char *t, char *s) +{ register unsigned char ch; do { ch = *s++; *t++ = char_lower(ch); - } while(ch); + } while (ch); } -int strstr_lower(char *str, char *tag) { - char buf[STRLEN]; - +int +strstr_lower(char *str, char *tag) +{ + char buf[STRLEN]; + str_lower(buf, str); return (int)strstr(buf, tag); } -void trim(char *buf) { /* remove trailing space */ - char *p = buf; +void +trim(char *buf) +{ /* remove trailing space */ + char *p = buf; - while(*p) + while (*p) p++; - while(--p >= buf) { - if(*p == ' ') + while (--p >= buf) { + if (*p == ' ') *p = '\0'; else break; @@ -115,98 +149,114 @@ void trim(char *buf) { /* remove trailing space */ /* ----------------------------------------------------- */ /* 字串檢查函數:英文、數字、檔名、E-mail address */ /* ----------------------------------------------------- */ -int isprint2(char ch) { +int +isprint2(char ch) +{ return ((ch & 0x80) ? 1 : isprint(ch)); //return 1; } -int not_alpha(char ch) { +int +not_alpha(char ch) +{ return (ch < 'A' || (ch > 'Z' && ch < 'a') || ch > 'z'); } -int not_alnum(char ch) { +int +not_alnum(char ch) +{ return (ch < '0' || (ch > '9' && ch < 'A') || (ch > 'Z' && ch < 'a') || ch > 'z'); } -int invalid_pname(char *str) { - char *p1, *p2, *p3; - +int +invalid_pname(char *str) +{ + char *p1, *p2, *p3; + p1 = str; - while(*p1) { - if(!(p2 = strchr(p1, '/'))) + while (*p1) { + if (!(p2 = strchr(p1, '/'))) p2 = str + strlen(str); - if(p1 + 1 > p2 || p1 + strspn(p1, ".") == p2) + if (p1 + 1 > p2 || p1 + strspn(p1, ".") == p2) return 1; - for(p3 = p1; p3 < p2; p3++) - if(not_alnum(*p3) && !strchr("@[]-._", *p3)) + for (p3 = p1; p3 < p2; p3++) + if (not_alnum(*p3) && !strchr("@[]-._", *p3)) return 1; p1 = p2 + (*p2 ? 1 : 0); } return 0; } -int valid_ident(char *ident) { - static char *invalid[] = {"unknown@", "root@", "gopher@", "bbs@", - "@bbs", "guest@", "@ppp", "@slip", NULL}; - char buf[128]; - int i; - +int +valid_ident(char *ident) +{ + static char *invalid[] = {"unknown@", "root@", "gopher@", "bbs@", + "@bbs", "guest@", "@ppp", "@slip", NULL}; + char buf[128]; + int i; + str_lower(buf, ident); - for(i = 0; invalid[i]; i++) - if(strstr(buf, invalid[i])) + for (i = 0; invalid[i]; i++) + if (strstr(buf, invalid[i])) return 0; return 1; } -int is_uBM(char *list, char *id) { - register int len; +int +is_uBM(char *list, char *id) +{ + register int len; - if(list[0] == '[') + if (list[0] == '[') list++; - if(list[0] > ' ') { + if (list[0] > ' ') { len = strlen(id); do { - if(!strncasecmp(list, id, len)) { + if (!strncasecmp(list, id, len)) { list += len; - if((*list == 0) || (*list == '/') || - (*list == ']') || (*list == ' ')) + if ((*list == 0) || (*list == '/') || + (*list == ']') || (*list == ' ')) return 1; } - if((list = strchr(list,'/')) != NULL) + if ((list = strchr(list, '/')) != NULL) list++; else break; - } while(1); + } while (1); } return 0; } -int is_BM(char *list) { - if(is_uBM(list,cuser.userid)) { - cuser.userlevel |= PERM_BM; /* Ptt 自動加上BM的權利 */ +int +is_BM(char *list) +{ + if (is_uBM(list, cuser.userid)) { + cuser.userlevel |= PERM_BM; /* Ptt 自動加上BM的權利 */ return 1; } return 0; } -int userid_is_BM(char *userid, char *list) { - register int ch, len; - +int +userid_is_BM(char *userid, char *list) +{ + register int ch, len; + ch = list[0]; - if((ch > ' ') && (ch < 128)) { + if ((ch > ' ') && (ch < 128)) { len = strlen(userid); do { - if(!strncasecmp(list, userid, len)) { + if (!strncasecmp(list, userid, len)) { ch = list[len]; - if((ch == 0) || (ch == '/') || (ch == ']')) + if ((ch == 0) || (ch == '/') || (ch == ']')) return 1; } - while((ch = *list++)) { - if(ch == '/') + while ((ch = *list++)) { + if (ch == '/') break; } - } while(ch); + } while (ch); } return 0; } @@ -214,51 +264,63 @@ int userid_is_BM(char *userid, char *list) { /* ----------------------------------------------------- */ /* 檔案檢查函數:檔案、目錄、屬於 */ /* ----------------------------------------------------- */ -off_t dashs(char *fname) { - struct stat st; - - if(!stat(fname, &st)) - return st.st_size; +off_t +dashs(char *fname) +{ + struct stat st; + + if (!stat(fname, &st)) + return st.st_size; else - return -1; + return -1; } -long dasht(char *fname) { - struct stat st; - - if(!stat(fname, &st)) - return st.st_mtime; +long +dasht(char *fname) +{ + struct stat st; + + if (!stat(fname, &st)) + return st.st_mtime; else - return -1; + return -1; } -int dashl(char *fname) { - struct stat st; - +int +dashl(char *fname) +{ + struct stat st; + return (lstat(fname, &st) == 0 && S_ISLNK(st.st_mode)); } -int dashf(char *fname) { - struct stat st; - +int +dashf(char *fname) +{ + struct stat st; + return (stat(fname, &st) == 0 && S_ISREG(st.st_mode)); } -int dashd(char *fname) { - struct stat st; +int +dashd(char *fname) +{ + struct stat st; return (stat(fname, &st) == 0 && S_ISDIR(st.st_mode)); } -int belong(char *filelist, char *key) { - FILE *fp; - int rc = 0; - - if((fp = fopen(filelist, "r"))) { - char buf[STRLEN], *ptr; - - while(fgets(buf, STRLEN, fp)) { - if((ptr = strtok(buf, str_space)) && !strcasecmp(ptr, key)) { +int +belong(char *filelist, char *key) +{ + FILE *fp; + int rc = 0; + + if ((fp = fopen(filelist, "r"))) { + char buf[STRLEN], *ptr; + + while (fgets(buf, STRLEN, fp)) { + if ((ptr = strtok(buf, str_space)) && !strcasecmp(ptr, key)) { rc = 1; break; } @@ -268,150 +330,167 @@ int belong(char *filelist, char *key) { return rc; } -time_t gettime(int line, time_t dt) -{ - char yn[7]; - struct tm *ptime = localtime(&dt), endtime; - - memcpy(&endtime, ptime, sizeof(struct tm )); - sprintf(yn, "%4d", ptime->tm_year+1900); - do{ - getdata_buf(line, 0, "西元年:", yn, 5, LCECHO); - }while( (endtime.tm_year = atoi(yn)-1900)<0 || endtime.tm_year>200); - sprintf(yn, "%d", ptime->tm_mon+1); - do{ - getdata_buf(line, 13, "月:", yn, 3, LCECHO); - }while((endtime.tm_mon = atoi(yn)-1)<0 || endtime.tm_mon>11); - sprintf(yn, "%d", ptime->tm_mday); - do{ - getdata_buf(line, 22, "日:", yn, 3, LCECHO); - }while((endtime.tm_mday = atoi(yn))<1 || endtime.tm_mday>31); - sprintf(yn, "%d", ptime->tm_hour); - do{ - getdata_buf(line, 31, "時(0-23):", yn, 3, LCECHO); - }while(( endtime.tm_hour = atoi(yn))<0 || endtime.tm_hour>23); - return mktime(&endtime); -} -char *Cdate(time_t *clock) { - static char foo[32]; - struct tm *mytm = localtime(clock); - +time_t +gettime(int line, time_t dt) +{ + char yn[7]; + struct tm *ptime = localtime(&dt), endtime; + + memcpy(&endtime, ptime, sizeof(struct tm)); + sprintf(yn, "%4d", ptime->tm_year + 1900); + do { + getdata_buf(line, 0, "西元年:", yn, 5, LCECHO); + } while ((endtime.tm_year = atoi(yn) - 1900) < 0 || endtime.tm_year > 200); + sprintf(yn, "%d", ptime->tm_mon + 1); + do { + getdata_buf(line, 13, "月:", yn, 3, LCECHO); + } while ((endtime.tm_mon = atoi(yn) - 1) < 0 || endtime.tm_mon > 11); + sprintf(yn, "%d", ptime->tm_mday); + do { + getdata_buf(line, 22, "日:", yn, 3, LCECHO); + } while ((endtime.tm_mday = atoi(yn)) < 1 || endtime.tm_mday > 31); + sprintf(yn, "%d", ptime->tm_hour); + do { + getdata_buf(line, 31, "時(0-23):", yn, 3, LCECHO); + } while ((endtime.tm_hour = atoi(yn)) < 0 || endtime.tm_hour > 23); + return mktime(&endtime); +} +char * +Cdate(time_t * clock) +{ + static char foo[32]; + struct tm *mytm = localtime(clock); + strftime(foo, 32, "%m/%d/%Y %T %a", mytm); return foo; } -char *Cdatelite(time_t *clock) { - static char foo[32]; - struct tm *mytm = localtime(clock); - +char * +Cdatelite(time_t * clock) +{ + static char foo[32]; + struct tm *mytm = localtime(clock); + strftime(foo, 32, "%m/%d/%Y %T", mytm); return foo; } -char *Cdatedate(time_t *clock){ - static char foo[32]; - struct tm *mytm = localtime(clock); - +char * +Cdatedate(time_t * clock) +{ + static char foo[32]; + struct tm *mytm = localtime(clock); + strftime(foo, 32, "%m/%d/%Y", mytm); return foo; } -static void capture_screen() { - char fname[200]; - FILE* fp; - int i; +static void +capture_screen() +{ + char fname[200]; + FILE *fp; + int i; getdata(b_lines - 2, 0, "把這個畫面收入到暫存檔?[y/N] ", fname, 4, LCECHO); - if(fname[0] != 'y' ) return; - + if (fname[0] != 'y') + return; + setuserfile(fname, ask_tmpbuf(b_lines - 1)); - if((fp = fopen(fname, "w"))) { - for(i = 0; i < scr_lns; i++) + if ((fp = fopen(fname, "w"))) { + for (i = 0; i < scr_lns; i++) fprintf(fp, "%.*s\n", big_picture[i].len, big_picture[i].data); fclose(fp); } } -void pressanykey() { - int ch; - +void +pressanykey() +{ + int ch; + outmsg("\033[37;45;1m " "● 請按 \033[33m(Space/Return)\033[37m 繼續 ●" " \033[33m(^T)\033[37m 存暫存檔 \033[m"); do { ch = igetkey(); - - if(ch == Ctrl('T')) { + + if (ch == Ctrl('T')) { capture_screen(); break; } - } while((ch != ' ') && (ch != KEY_LEFT) && (ch != '\r') && (ch != '\n')); + } while ((ch != ' ') && (ch != KEY_LEFT) && (ch != '\r') && (ch != '\n')); move(b_lines, 0); clrtoeol(); refresh(); } -int vmsg (const char *fmt, ...) +int +vmsg(const char *fmt,...) { - va_list ap; - char msg[80] = {0}; - int ch; + va_list ap; + char msg[80] = {0}; + int ch; - va_start (ap, fmt); - vsprintf (msg, fmt, ap); - va_end (ap); + va_start(ap, fmt); + vsprintf(msg, fmt, ap); + va_end(ap); - move (b_lines, 0); - clrtoeol (); + move(b_lines, 0); + clrtoeol(); - if (*msg) - prints ("\033[1;36;44m ◆ %-55.54s \033[33;46m \033[200m\033[1431m\033[506m[請按任意鍵繼續]\033[201m \033[m", msg); - else - outs ("\033[46;1m \033[37m" - "\033[200m\033[1431m\033[506m□ 請按 \033[33m(Space/Return)\033[37m 繼續 □\033[201m" - " \033[m"); + if (*msg) + prints("\033[1;36;44m ◆ %-55.54s \033[33;46m \033[200m\033[1431m\033[506m[請按任意鍵繼續]\033[201m \033[m", msg); + else + outs("\033[46;1m \033[37m" + "\033[200m\033[1431m\033[506m□ 請按 \033[33m(Space/Return)\033[37m 繼續 □\033[201m" + " \033[m"); - do { + do { ch = igetkey(); - - if(ch == Ctrl('T')) { + + if (ch == Ctrl('T')) { capture_screen(); break; } - } while((ch != ' ') && (ch != KEY_LEFT) && (ch != '\r') && (ch != '\n')); + } while ((ch != ' ') && (ch != KEY_LEFT) && (ch != '\r') && (ch != '\n')); + - - move (b_lines, 0); - clrtoeol (); - refresh (); - return ch; + move(b_lines, 0); + clrtoeol(); + refresh(); + return ch; } -void bell() { - char c; - +void +bell() +{ + char c; + c = Ctrl('G'); write(1, &c, 1); } -int search_num(int ch, int max) { - int clen = 1; - int x, y; - char genbuf[10]; - +int +search_num(int ch, int max) +{ + int clen = 1; + int x, y; + char genbuf[10]; + outmsg("\033[7m 跳至第幾項:\033[m"); outc(ch); genbuf[0] = ch; getyx(&y, &x); x--; - while((ch = igetch()) != '\r') { - if(ch == 'q' || ch == 'e') + while ((ch = igetch()) != '\r') { + if (ch == 'q' || ch == 'e') return -1; - if(ch == '\n') + if (ch == '\n') break; - if(ch == '\177' || ch == Ctrl('H')) { - if(clen == 0) { + if (ch == '\177' || ch == Ctrl('H')) { + if (clen == 0) { bell(); continue; } @@ -421,11 +500,11 @@ int search_num(int ch, int max) { move(y, x + clen); continue; } - if(!isdigit(ch)) { + if (!isdigit(ch)) { bell(); continue; } - if(x + clen >= scr_cols || clen >= 6) { + if (x + clen >= scr_cols || clen >= 6) { bell(); continue; } @@ -435,35 +514,43 @@ int search_num(int ch, int max) { genbuf[clen] = '\0'; move(b_lines, 0); clrtoeol(); - if(genbuf[0] == '\0') + if (genbuf[0] == '\0') return -1; clen = atoi(genbuf); - if(clen == 0) + if (clen == 0) return 0; - if(clen > max) + if (clen > max) return max; return clen - 1; } -void stand_title(char *title) { +void +stand_title(char *title) +{ clear(); prints("\033[1;37;46m【 %s 】\033[m\n", title); } -void cursor_show(int row, int column) { +void +cursor_show(int row, int column) +{ move(row, column); outs(STR_CURSOR); move(row, column + 1); } -void cursor_clear(int row, int column) { +void +cursor_clear(int row, int column) +{ move(row, column); outs(STR_UNCUR); } -int cursor_key(int row, int column) { - int ch; - +int +cursor_key(int row, int column) +{ + int ch; + cursor_show(row, column); ch = egetch(); move(row, column); @@ -471,51 +558,55 @@ int cursor_key(int row, int column) { return ch; } -void printdash(char *mesg) { - int head = 0, tail; - - if(mesg) +void +printdash(char *mesg) +{ + int head = 0, tail; + + if (mesg) head = (strlen(mesg) + 1) >> 1; - + tail = head; - - while(head++ < 38) + + while (head++ < 38) outch('-'); - - if(tail) { + + if (tail) { outch(' '); outs(mesg); outch(' '); } - - while(tail++ < 38) + while (tail++ < 38) outch('-'); outch('\n'); } -int log_file(char *filename,char *buf) { - FILE *fp; +int +log_file(char *filename, char *buf) +{ + FILE *fp; - if((fp = fopen(filename, "a" )) != NULL ) { - fputs( buf, fp ); - if(!strchr(buf,'\n')) - fputc('\n',fp); - fclose( fp ); - return 0; - } - else + if ((fp = fopen(filename, "a")) != NULL) { + fputs(buf, fp); + if (!strchr(buf, '\n')) + fputc('\n', fp); + fclose(fp); + return 0; + } else return -1; } -void show_help(char *helptext[]) { - char *str; - int i; - +void +show_help(char *helptext[]) +{ + char *str; + int i; + clear(); - for(i = 0; (str = helptext[i]); i++) { - if(*str == '\0') + for (i = 0; (str = helptext[i]); i++) { + if (*str == '\0') prints("\033[1m【 %s 】\033[0m\n", str + 1); - else if(*str == '\01') + else if (*str == '\01') prints("\n\033[36m【 %s 】\033[m\n", str + 1); else prints(" %s\n", str); diff --git a/pttbbs/mbbsd/syspost.c b/pttbbs/mbbsd/syspost.c index 3039cd6b..15caf482 100644 --- a/pttbbs/mbbsd/syspost.c +++ b/pttbbs/mbbsd/syspost.c @@ -1,39 +1,41 @@ -/* $Id: syspost.c,v 1.11 2002/06/19 13:32:23 lwms Exp $ */ +/* $Id: syspost.c,v 1.12 2002/07/05 17:10:28 in2 Exp $ */ #include "bbs.h" -void post_change_perm(int oldperm, int newperm, char *sysopid, char *userid) { - FILE *fp; - fileheader_t fhdr; - char genbuf[200], reason[30]; - int i, flag=0; - +void +post_change_perm(int oldperm, int newperm, char *sysopid, char *userid) +{ + FILE *fp; + fileheader_t fhdr; + char genbuf[200], reason[30]; + int i, flag = 0; + strcpy(genbuf, "boards/S/Security"); stampfile(genbuf, &fhdr); - if(!(fp = fopen(genbuf,"w"))) + if (!(fp = fopen(genbuf, "w"))) return; - + fprintf(fp, "作者: [系統安全局] 看板: Security\n" "標題: [公安報告] 站長修改權限報告\n" "時間: %s\n", ctime(&now)); - for(i = 5; i < NUMPERMS; i++) { - if(((oldperm >> i) & 1) != ((newperm >> i) & 1)) { - fprintf (fp, " 站長\033[1;32m%s%s%s%s\033[m的權限\n", - sysopid, - (((oldperm >> i) & 1) ? "\033[1;33m關閉":"\033[1;33m開啟"), - userid, str_permid[i]); - flag++; - } + for (i = 5; i < NUMPERMS; i++) { + if (((oldperm >> i) & 1) != ((newperm >> i) & 1)) { + fprintf(fp, " 站長\033[1;32m%s%s%s%s\033[m的權限\n", + sysopid, + (((oldperm >> i) & 1) ? "\033[1;33m關閉" : "\033[1;33m開啟"), + userid, str_permid[i]); + flag++; + } } - - if(flag) { + + if (flag) { clrtobot(); clear(); - while(!getdata_str(5, 0, "請輸入理由以示負責:", - reason, sizeof(reason), DOECHO, "看板板主:")); + while (!getdata_str(5, 0, "請輸入理由以示負責:", + reason, sizeof(reason), DOECHO, "看板板主:")); fprintf(fp, "\n \033[1;37m站長%s修改權限理由是:%s\033[m", cuser.userid, reason); fclose(fp); - + sprintf(fhdr.title, "[公安報告] 站長%s修改%s權限報告", cuser.userid, userid); strcpy(fhdr.owner, "[系統安全局]"); @@ -41,14 +43,16 @@ void post_change_perm(int oldperm, int newperm, char *sysopid, char *userid) { } } -void post_violatelaw(char* crime, char* police, char* reason, char* result){ - char genbuf[200]; - fileheader_t fhdr; - FILE *fp; +void +post_violatelaw(char *crime, char *police, char *reason, char *result) +{ + char genbuf[200]; + fileheader_t fhdr; + FILE *fp; strcpy(genbuf, "boards/S/Security"); stampfile(genbuf, &fhdr); - if(!(fp = fopen(genbuf,"w"))) - return; + if (!(fp = fopen(genbuf, "w"))) + return; fprintf(fp, "作者: [Ptt法院] 看板: Security\n" "標題: [報告] %-20s 違法判決報告\n" "時間: %s\n" @@ -59,11 +63,11 @@ void post_violatelaw(char* crime, char* police, char* reason, char* result){ sprintf(fhdr.title, "[報告] %-20s 違法判決報告", crime); strcpy(fhdr.owner, "[Ptt法院]"); append_record("boards/S/Security/.DIR", &fhdr, sizeof(fhdr)); - + strcpy(genbuf, "boards/V/ViolateLaw"); stampfile(genbuf, &fhdr); - if(!(fp = fopen(genbuf,"w"))) - return; + if (!(fp = fopen(genbuf, "w"))) + return; fprintf(fp, "作者: [Ptt法院] 看板: ViolateLaw\n" "標題: [報告] %-20s 違法判決報告\n" "時間: %s\n" @@ -73,40 +77,44 @@ void post_violatelaw(char* crime, char* police, char* reason, char* result){ fclose(fp); sprintf(fhdr.title, "[報告] %-20s 違法判決報告", crime); strcpy(fhdr.owner, "[Ptt法院]"); - + append_record("boards/V/ViolateLaw/.DIR", &fhdr, sizeof(fhdr)); - + } -void post_newboard(char* bgroup, char* bname, char* bms){ - char genbuf[256], title[128]; +void +post_newboard(char *bgroup, char *bname, char *bms) +{ + char genbuf[256], title[128]; sprintf(title, "[新板成立] %s", bname); sprintf(genbuf, "%s 開了一個新板 %s : %s\n\n新任板主為 %s\n\n恭喜*^_^*\n", - cuser.userid, bname, bgroup, bms); - post_msg("Record", title, genbuf, "[系統]"); + cuser.userid, bname, bgroup, bms); + post_msg("Record", title, genbuf, "[系統]"); } -void give_money_post(char *userid, int money) { - FILE *fp; - fileheader_t fhdr; - time_t now = time(0); - char genbuf[200]; +void +give_money_post(char *userid, int money) +{ + FILE *fp; + fileheader_t fhdr; + time_t now = time(0); + char genbuf[200]; strcpy(genbuf, "boards/S/Security"); stampfile(genbuf, &fhdr); - if(!(fp = fopen(genbuf,"w"))) - return; + if (!(fp = fopen(genbuf, "w"))) + return; fprintf(fp, "作者: [系統安全局] 看板: Security\n" - "標題: [公安報告] 站長%s使用紅包機報告\n" - "時間: %s\n", cuser.userid, ctime(&now)); - clrtobot(); - clear(); - fprintf(fp, "\n 站長\033[1;32m%s\033[m給\033[1;33m%s %d 元\033[m", - cuser.userid, userid, money); + "標題: [公安報告] 站長%s使用紅包機報告\n" + "時間: %s\n", cuser.userid, ctime(&now)); + clrtobot(); + clear(); + fprintf(fp, "\n 站長\033[1;32m%s\033[m給\033[1;33m%s %d 元\033[m", + cuser.userid, userid, money); - fclose(fp); - sprintf(fhdr.title, "[公安報告] 站長%s使用紅包機報告", - cuser.userid); - strcpy(fhdr.owner, "[系統安全局]"); - append_record("boards/S/Security/.DIR", &fhdr, sizeof(fhdr)); + fclose(fp); + sprintf(fhdr.title, "[公安報告] 站長%s使用紅包機報告", + cuser.userid); + strcpy(fhdr.owner, "[系統安全局]"); + append_record("boards/S/Security/.DIR", &fhdr, sizeof(fhdr)); } diff --git a/pttbbs/mbbsd/talk.c b/pttbbs/mbbsd/talk.c index 9c8dba8d..5f62d642 100644 --- a/pttbbs/mbbsd/talk.c +++ b/pttbbs/mbbsd/talk.c @@ -1,12 +1,12 @@ -/* $Id: talk.c,v 1.77 2002/07/04 20:08:11 in2 Exp $ */ +/* $Id: talk.c,v 1.78 2002/07/05 17:10:28 in2 Exp $ */ #include "bbs.h" #define QCAST int (*)(const void *, const void *) -static char *IdleTypeTable[] = { +static char *IdleTypeTable[] = { "偶在花呆啦", "情人來電", "覓食中", "拜見周公", "假死狀態", "我在思考" }; -static char *sig_des[] = { +static char *sig_des[] = { "鬥雞", "聊天", "", "下棋", "象棋", "暗棋" }; @@ -17,103 +17,104 @@ static char *sig_des[] = { #define BOARDFRI 1 typedef struct talkwin_t { - int curcol, curln; - int sline, eline; -} talkwin_t; + int curcol, curln; + int sline, eline; +} talkwin_t; typedef struct pickup_t { - userinfo_t *ui; - int friend, uoffset; -} pickup_t; + userinfo_t *ui; + int friend, uoffset; +} pickup_t; -//extern int bind( /* int,struct sockaddr *, int */ ); -//extern char *getuserid(); +//extern int bind( /* int,struct sockaddr *, int */ ); +//extern char *getuserid(); /* 記錄 friend 的 user number */ -//#define PICKUP_WAYS 7 //關掉女士優先 +// +#define PICKUP_WAYS 7 //關掉女士優先 #define PICKUP_WAYS 6 -static char *fcolor[11] = { +static char *fcolor[11] = { "", "\033[36m", "\033[32m", "\033[1;32m", "\033[33m", "\033[1;33m", "\033[1;37m", "\033[1;37m", "\033[31m", "\033[1;35m", "\033[1;36m" }; -static char save_page_requestor[40]; -static char page_requestor[40]; -static char description[30]; -static FILE *flog; +static char save_page_requestor[40]; +static char page_requestor[40]; +static char description[30]; +static FILE *flog; -int iswritable_stat(userinfo_t *uentp, int fri_stat) +int +iswritable_stat(userinfo_t * uentp, int fri_stat) { - if( uentp == currutmp ) + if (uentp == currutmp) return 0; - if( HAS_PERM(PERM_SYSOP) ) + if (HAS_PERM(PERM_SYSOP)) return 1; - if( !HAS_PERM(PERM_LOGINOK) ) + if (!HAS_PERM(PERM_LOGINOK)) return 0; return (uentp->pager != 3 && (fri_stat & HFM || uentp->pager != 4)); } -int isvisible_stat(userinfo_t * me, userinfo_t * uentp, int fri_stat) +int +isvisible_stat(userinfo_t * me, userinfo_t * uentp, int fri_stat) { if (uentp->userid[0] == 0) return 0; - - if (PERM_HIDE(uentp) && !(PERM_HIDE(me)))/* 對方紫色隱形而你沒有 */ + + if (PERM_HIDE(uentp) && !(PERM_HIDE(me))) /* 對方紫色隱形而你沒有 */ return 0; else if ((me->userlevel & PERM_SYSOP) || - ((fri_stat & HRM) && (fri_stat & HFM))) - /* 站長看的見任何人 */ + ((fri_stat & HRM) && (fri_stat & HFM))) + /* 站長看的見任何人 */ return 1; - - if (uentp->invisible && !(me->userlevel & PERM_SEECLOAK)) return 0; + + if (uentp->invisible && !(me->userlevel & PERM_SEECLOAK)) + return 0; return !(fri_stat & HRM); } -char *modestring(userinfo_t * uentp, int simple) +char * +modestring(userinfo_t * uentp, int simple) { - static char modestr[40]; - static char *notonline = "不在站上"; - register int mode = uentp->mode; - register char *word; - int fri_stat; - -/* for debugging */ - if (mode >= MAX_MODES){ + static char modestr[40]; + static char *notonline = "不在站上"; + register int mode = uentp->mode; + register char *word; + int fri_stat; + + /* for debugging */ + if (mode >= MAX_MODES) { syslog(LOG_WARNING, "what!? mode = %d", mode); word = ModeTypeTable[mode % MAX_MODES]; - } - else + } else word = ModeTypeTable[mode]; fri_stat = friend_stat(currutmp, uentp); - if( !(HAS_PERM(PERM_SYSOP) || HAS_PERM(PERM_SEECLOAK)) && + if (!(HAS_PERM(PERM_SYSOP) || HAS_PERM(PERM_SEECLOAK)) && ((uentp->invisible || (fri_stat & HRM)) && - !((fri_stat & HFM) && (fri_stat & HRM))) ) + !((fri_stat & HFM) && (fri_stat & HRM)))) return notonline; - else if (mode == EDITING){ + else if (mode == EDITING) { sprintf(modestr, "E:%s", ModeTypeTable[uentp->destuid < EDITING ? uentp->destuid : EDITING]); word = modestr; - } - else if (!mode && *uentp->chatid == 1){ + } else if (!mode && *uentp->chatid == 1) { if (!simple) sprintf(modestr, "回應 %s", getuserid(uentp->destuid)); else sprintf(modestr, "回應呼叫"); - } - else if (!mode && *uentp->chatid == 2) - if (uentp->msgcount < 10){ - char *cnum[10] = - {"", "一", "兩", "三", "四", "五", "六", "七", - "八", "九"}; + } else if (!mode && *uentp->chatid == 2) + if (uentp->msgcount < 10) { + char *cnum[10] = + {"", "一", "兩", "三", "四", "五", "六", "七", + "八", "九"}; sprintf(modestr, "中%s顆水球", cnum[uentp->msgcount]); - } - else + } else sprintf(modestr, "不行了 @_@"); else if (!mode && *uentp->chatid == 3) sprintf(modestr, "水球準備中"); @@ -125,25 +126,23 @@ char *modestring(userinfo_t * uentp, int simple) return word; else if (uentp->in_chat && mode == CHATING) sprintf(modestr, "%s (%s)", word, uentp->chatid); - else if (mode == TALK){ - if (!isvisible_uid(uentp->destuid))/* Leeym 對方(紫色)隱形 */ - sprintf(modestr, "%s", "交談 空氣");/* Leeym 大家自己發揮吧! */ + else if (mode == TALK) { + if (!isvisible_uid(uentp->destuid)) /* Leeym 對方(紫色)隱形 */ + sprintf(modestr, "%s", "交談 空氣"); /* Leeym + * 大家自己發揮吧! */ else sprintf(modestr, "%s %s", word, getuserid(uentp->destuid)); - } - else if (mode == M_FIVE){ + } else if (mode == M_FIVE) { if (!isvisible_uid(uentp->destuid)) sprintf(modestr, "%s", "五子棋 空氣"); else sprintf(modestr, "%s %s", word, getuserid(uentp->destuid)); - } - else if (mode == CHC){ + } else if (mode == CHC) { if (isvisible_uid(uentp->destuid)) sprintf(modestr, "%s", "下象棋"); else sprintf(modestr, "下象棋 %s", getuserid(uentp->destuid)); - } - else if (mode != PAGE && mode != TQUERY) + } else if (mode != PAGE && mode != TQUERY) return word; else sprintf(modestr, "%s %s", word, getuserid(uentp->destuid)); @@ -151,43 +150,45 @@ char *modestring(userinfo_t * uentp, int simple) return (modestr); } -int set_friend_bit(userinfo_t * me, userinfo_t * ui) { - int unum, *myfriends, hit=0, n; +int +set_friend_bit(userinfo_t * me, userinfo_t * ui) +{ + int unum, *myfriends, hit = 0, n; /* 判斷對方是否為我的朋友 ? */ unum = ui->uid; myfriends = me->friend; - while ((n = *myfriends++)){ - if (unum == n){ + while ((n = *myfriends++)) { + if (unum == n) { hit = IFH; break; } } - + /* 判斷我是否為對方的朋友 ? */ myfriends = ui->friend; - while ((unum = *myfriends++)){ - if (unum == me->uid){ + while ((unum = *myfriends++)) { + if (unum == me->uid) { hit |= HFM; break; } } - -/* 判斷對方是否為我的仇人 ? */ + + /* 判斷對方是否為我的仇人 ? */ unum = ui->uid; myfriends = me->reject; - while ((n = *myfriends++)){ - if (unum == n){ + while ((n = *myfriends++)) { + if (unum == n) { hit |= IRH; break; } } -/* 判斷我是否為對方的仇人 ? */ + /* 判斷我是否為對方的仇人 ? */ myfriends = ui->reject; - while ((unum = *myfriends++)){ - if (unum == me->uid){ + while ((unum = *myfriends++)) { + if (unum == me->uid) { hit |= HRM; break; } @@ -195,131 +196,136 @@ int set_friend_bit(userinfo_t * me, userinfo_t * ui) { return hit; } -int reverse_friend_stat(int stat) +int +reverse_friend_stat(int stat) { - int stat1=0; - if(stat & IFH) - stat1 |=HFM; - if(stat & IRH) - stat1 |=HRM; - if(stat & HFM) - stat1 |=IFH; - if(stat & HRM) - stat1 |=IRH; - if(stat & IBH) - stat1 |=IBH; - return stat1; + int stat1 = 0; + if (stat & IFH) + stat1 |= HFM; + if (stat & IRH) + stat1 |= HRM; + if (stat & HFM) + stat1 |= IFH; + if (stat & HRM) + stat1 |= IRH; + if (stat & IBH) + stat1 |= IBH; + return stat1; } -int login_friend_online(void) +int +login_friend_online(void) { - userinfo_t *uentp; - int i, stat, stat1; - int offset=(int) (currutmp - &SHM->uinfo[0]); - for (i=0;i<SHM->UTMPnumber && currutmp->friendtotal<MAX_FRIEND; i++){ + userinfo_t *uentp; + int i, stat, stat1; + int offset = (int)(currutmp - &SHM->uinfo[0]); + for (i = 0; i < SHM->UTMPnumber && currutmp->friendtotal < MAX_FRIEND; i++) { uentp = (SHM->sorted[SHM->currsorted][0][i]); - if(uentp && uentp->uid && (stat=set_friend_bit(currutmp,uentp))){ - stat1=reverse_friend_stat(stat); + if (uentp && uentp->uid && (stat = set_friend_bit(currutmp, uentp))) { + stat1 = reverse_friend_stat(stat); stat <<= 24; - stat |= (int) (uentp - &SHM->uinfo[0]); - currutmp->friend_online[currutmp->friendtotal++]=stat; - if(uentp!=currutmp && uentp->friendtotal<MAX_FRIEND){ + stat |= (int)(uentp - &SHM->uinfo[0]); + currutmp->friend_online[currutmp->friendtotal++] = stat; + if (uentp != currutmp && uentp->friendtotal < MAX_FRIEND) { stat1 <<= 24; stat1 |= offset; - uentp->friend_online[uentp->friendtotal++]=stat1; + uentp->friend_online[uentp->friendtotal++] = stat1; } } - } + } return 0; } -int logout_friend_online(userinfo_t *utmp) +int +logout_friend_online(userinfo_t * utmp) { - int i, j, k; - int offset=(int) (utmp - &SHM->uinfo[0]); - userinfo_t *ui; - while( utmp->friendtotal > 0 ){ - i = utmp->friendtotal-1; + int i, j, k; + int offset = (int)(utmp - &SHM->uinfo[0]); + userinfo_t *ui; + while (utmp->friendtotal > 0) { + i = utmp->friendtotal - 1; j = (utmp->friend_online[i] & 0xFFFFFF); - utmp->friend_online[i]=0; - ui = &SHM->uinfo[j]; - if(ui->pid && ui!=utmp){ - for(k=0; k<ui->friendtotal > 0 && k < MAX_FRIEND && - (int)(ui->friend_online[k] & 0xFFFFFF) !=offset; k++); - if(k<ui->friendtotal){ + utmp->friend_online[i] = 0; + ui = &SHM->uinfo[j]; + if (ui->pid && ui != utmp) { + for (k = 0; k < ui->friendtotal > 0 && k < MAX_FRIEND && + (int)(ui->friend_online[k] & 0xFFFFFF) != offset; k++); + if (k < ui->friendtotal) { ui->friendtotal--; - ui->friend_online[k]=ui->friend_online[ui->friendtotal]; - ui->friend_online[ui->friendtotal]=0; + ui->friend_online[k] = ui->friend_online[ui->friendtotal]; + ui->friend_online[ui->friendtotal] = 0; } } utmp->friendtotal--; - utmp->friend_online[utmp->friendtotal]=0; + utmp->friend_online[utmp->friendtotal] = 0; } return 0; } -int friend_stat(userinfo_t *me, userinfo_t * ui) +int +friend_stat(userinfo_t * me, userinfo_t * ui) { - int i, j, hit=0; - /* 看板好友 */ - if (me->brc_id && ui->brc_id == me->brc_id){ - hit = IBH; - } - for(i=0;me->friend_online[i] && i < MAX_FRIEND;i++){ - j = (me->friend_online[i] & 0xFFFFFF); - if( 0 <= j && j < MAX_ACTIVE && ui == &SHM->uinfo[j] ){ - hit |= me->friend_online[i] >>24; - break; - } - } - if (PERM_HIDE(ui)) - return hit & ST_FRIEND; - return hit; + int i, j, hit = 0; + /* 看板好友 */ + if (me->brc_id && ui->brc_id == me->brc_id) { + hit = IBH; + } + for (i = 0; me->friend_online[i] && i < MAX_FRIEND; i++) { + j = (me->friend_online[i] & 0xFFFFFF); + if (0 <= j && j < MAX_ACTIVE && ui == &SHM->uinfo[j]) { + hit |= me->friend_online[i] >> 24; + break; + } + } + if (PERM_HIDE(ui)) + return hit & ST_FRIEND; + return hit; } -int isvisible_uid(int tuid) +int +isvisible_uid(int tuid) { - userinfo_t *uentp; + userinfo_t *uentp; - if(!tuid || !(uentp = search_ulist(tuid))) - return 1; + if (!tuid || !(uentp = search_ulist(tuid))) + return 1; return isvisible(currutmp, uentp); } /* 真實動作 */ -static void my_kick(userinfo_t * uentp) +static void +my_kick(userinfo_t * uentp) { - char genbuf[200]; + char genbuf[200]; getdata(1, 0, msg_sure_ny, genbuf, 4, LCECHO); clrtoeol(); - if (genbuf[0] == 'y'){ + if (genbuf[0] == 'y') { sprintf(genbuf, "%s (%s)", uentp->userid, uentp->username); log_usies("KICK ", genbuf); - if((uentp->pid <= 0 || kill(uentp->pid, SIGHUP) == -1) && (errno == ESRCH)) + if ((uentp->pid <= 0 || kill(uentp->pid, SIGHUP) == -1) && (errno == ESRCH)) purge_utmp(uentp); outs("踢出去囉"); - } - else + } else outs(msg_cancel); pressanykey(); } -static void chicken_query(char *userid) +static void +chicken_query(char *userid) { - char buf[100]; + char buf[100]; - if (getuser(userid)){ - if (xuser.mychicken.name[0]){ + if (getuser(userid)) { + if (xuser.mychicken.name[0]) { time_diff(&(xuser.mychicken)); - if (!isdeadth(&(xuser.mychicken))){ + if (!isdeadth(&(xuser.mychicken))) { show_chicken_data(&(xuser.mychicken), NULL); sprintf(buf, "\n\n以上是 %s 的寵物資料..", userid); outs(buf); } - } - else{ + } else { move(1, 0); clrtobot(); sprintf(buf, "\n\n%s 並沒有養寵物..", userid); @@ -329,28 +335,29 @@ static void chicken_query(char *userid) } } -int my_query(char *uident) +int +my_query(char *uident) { - userec_t muser; - int tuid, i, fri_stat=0; + userec_t muser; + int tuid, i, fri_stat = 0; unsigned long int j; - userinfo_t *uentp; - static const char *money[10] = - {"債台高築", "赤貧", "清寒", "普通", "小康", - "小富", "中富", "大富翁", "富可敵國", "比爾蓋\天"}; - static const char *sex[8] = - {MSG_BIG_BOY, MSG_BIG_GIRL, - MSG_LITTLE_BOY, MSG_LITTLE_GIRL, - MSG_MAN, MSG_WOMAN, MSG_PLANT, MSG_MIME}; - - if ((tuid = getuser(uident))){ + userinfo_t *uentp; + static const char *money[10] = + {"債台高築", "赤貧", "清寒", "普通", "小康", + "小富", "中富", "大富翁", "富可敵國", "比爾蓋\天"}; + static const char *sex[8] = + {MSG_BIG_BOY, MSG_BIG_GIRL, + MSG_LITTLE_BOY, MSG_LITTLE_GIRL, + MSG_MAN, MSG_WOMAN, MSG_PLANT, MSG_MIME}; + + if ((tuid = getuser(uident))) { memcpy(&muser, &xuser, sizeof(muser)); move(1, 0); clrtobot(); move(1, 0); setutmpmode(TQUERY); currutmp->destuid = tuid; - + j = muser.money; for (i = 0; i < 10 && j > 10; i++) j /= 10; @@ -362,20 +369,20 @@ int my_query(char *uident) prints("《上站次數》%d次", muser.numlogins); move(2, 40); prints("《文章篇數》%d篇\n", muser.numposts); - - if((uentp = (userinfo_t *) search_ulist(tuid))) - fri_stat=friend_stat(currutmp, uentp); + + if ((uentp = (userinfo_t *) search_ulist(tuid))) + fri_stat = friend_stat(currutmp, uentp); prints("\033[1;33m《目前動態》%-28.28s\033[m", (uentp && isvisible_stat(currutmp, uentp, fri_stat)) ? modestring(uentp, 0) : "不在站上"); - + outs(((uentp && uentp->mailalert) || load_mailalert(muser.userid)) ? "《私人信箱》有新進信件還沒看\n" : "《私人信箱》所有信件都看過了\n"); prints("《上次上站》%-28.28s《上次故鄉》%s\n", Cdate(&muser.lastlogin), (muser.lasthost[0] ? muser.lasthost : "(不詳)")); - if ((uentp && fri_stat&HFM && !uentp->invisible) || HAS_PERM(PERM_SYSOP)) + if ((uentp && fri_stat & HFM && !uentp->invisible) || HAS_PERM(PERM_SYSOP)) prints("《 性 別 》%-28.28s《私有財產》%ld 銀兩\n", sex[muser.sex % 8], muser.money); @@ -390,41 +397,45 @@ int my_query(char *uident) return DONOTHING; } -static char t_last_write[200] = ""; +static char t_last_write[200] = ""; -void water_scr(water_t *tw, int which, char type) +void +water_scr(water_t * tw, int which, char type) { - if( type == 1 ){ - int i; - int colors[] = {33, 37, 33, 37, 33}; - move(8 + which, 28);prints(" "); + if (type == 1) { + int i; + int colors[] = {33, 37, 33, 37, 33}; + move(8 + which, 28); + prints(" "); move(8 + which, 28); prints("\033[1;37;45m %c %-14s \033[0m", tw->uin ? ' ' : 'x', tw->userid); - for( i = 0 ; i < 5 ; ++i ){ + for (i = 0; i < 5; ++i) { move(16 + i, 4); prints(" "); move(16 + i, 4); - if( tw->msg[ (tw->top - i + 4) % 5 ].last_call_in[0] != 0 ) + if (tw->msg[(tw->top - i + 4) % 5].last_call_in[0] != 0) prints("\033[0m \033[1;%d;44m★%-64s\033[0m \n", colors[i], - tw->msg[ (tw->top - i + 4) % 5 ].last_call_in); + tw->msg[(tw->top - i + 4) % 5].last_call_in); else prints("\033[0m \n"); } - move(21, 4);prints(" "); + move(21, 4); + prints(" "); move(21, 4); prints("\033[0m \033[1;37;46m%-66s\033[0m \n", tw->msg[5].last_call_in); - move(0, 0);prints(" "); - move(0, 0);prints("\033[0m反擊 %s:", tw->userid); + move(0, 0); + prints(" "); + move(0, 0); + prints("\033[0m反擊 %s:", tw->userid); clrtoeol(); move(0, strlen(tw->userid) + 6); - } - else{ + } else { move(8 + which, 28); prints("123456789012345678901234567890"); move(8 + which, 28); @@ -434,15 +445,16 @@ void water_scr(water_t *tw, int which, char type) } } -void my_write2(void) +void +my_write2(void) { - int i, ch, currstat0; - char genbuf[256], msg[80], done = 0, c0, which; - water_t *tw; - unsigned char mode0; + int i, ch, currstat0; + char genbuf[256], msg[80], done = 0, c0, which; + water_t *tw; + unsigned char mode0; - if( swater[0] == NULL ) - return; + if (swater[0] == NULL) + return; wmofo = 0; currstat0 = currstat; c0 = currutmp->chatid[0]; @@ -451,17 +463,17 @@ void my_write2(void) currutmp->chatid[0] = 3; currstat = XMODE; - // init screen - move(7, 28); + //init screen + move(7, 28); prints("\033[1;33;46m ↑ 水球反擊對象 ↓\033[0m"); - for( i = 0 ; i < 5 ; ++i ) - if( swater[i] == NULL || swater[i]->pid == 0 ) + for (i = 0; i < 5; ++i) + if (swater[i] == NULL || swater[i]->pid == 0) break; - else{ - if( swater[i]->uin && + else { + if (swater[i]->uin && (swater[i]->pid != swater[i]->uin->pid || - swater[i]->userid[0]!=swater[i]->uin->userid[0]) ) - swater[i]->uin = (userinfo_t*)search_ulist_pid(swater[i]->pid); + swater[i]->userid[0] != swater[i]->uin->userid[0])) + swater[i]->uin = (userinfo_t *) search_ulist_pid(swater[i]->pid); water_scr(swater[i], i, 0); } move(15, 4); @@ -474,11 +486,11 @@ void my_write2(void) refresh(); which = 0; - do{ - switch( (ch = igetkey()) ){ + do { + switch ((ch = igetkey())) { case Ctrl('T'): case KEY_UP: - if( water_usies != 1 ){ + if (water_usies != 1) { water_scr(swater[(int)which], which, 0); which = (which - 1 + water_usies) % water_usies; water_scr(swater[(int)which], which, 1); @@ -488,7 +500,7 @@ void my_write2(void) case KEY_DOWN: case Ctrl('R'): - if( water_usies != 1 ){ + if (water_usies != 1) { water_scr(swater[(int)which], which, 0); which = (which + 1 + water_usies) % water_usies; water_scr(swater[(int)which], which, 1); @@ -504,57 +516,56 @@ void my_write2(void) done = 1; tw = swater[(int)which]; - if( !tw->uin ) + if (!tw->uin) break; - if( ch != '\r' && ch != '\n' ){ + if (ch != '\r' && ch != '\n') { msg[0] = ch, msg[1] = 0; - } - else + } else msg[0] = 0; - move(0, 0);prints("\033[m"); clrtoeol(); + move(0, 0); + prints("\033[m"); + clrtoeol(); sprintf(genbuf, "攻擊 %s:", tw->userid); - if( !oldgetdata(0, 0, genbuf, msg, - 80-strlen(tw->userid)-6, DOECHO) ) + if (!oldgetdata(0, 0, genbuf, msg, + 80 - strlen(tw->userid) - 6, DOECHO)) break; - if( my_write(tw->pid, msg, tw->userid, 4, tw->uin) ) + if (my_write(tw->pid, msg, tw->userid, 4, tw->uin)) strncpy(tw->msg[5].last_call_in, t_last_write, sizeof(tw->msg[5].last_call_in)); break; } - } while( !done ); + } while (!done); currstat = currstat0; currutmp->chatid[0] = c0; currutmp->mode = mode0; - if( wmofo == 1 ) + if (wmofo == 1) write_request(0); wmofo = -1; } -/* - 被呼叫的時機: - 1. 丟群組水球 flag = 1 (pre-edit) - 2. 回水球 flag = 0 - 3. 上站aloha flag = 2 (pre-edit) - 4. 廣播 flag = 3 if SYSOP, otherwise flag = 1 (pre-edit) - 5. 丟水球 flag = 0 - 6. my_write2 flag = 4 (pre-edit) but confirm -*/ -int my_write(pid_t pid, char *prompt, char *id, int flag, userinfo_t *puin) +/* + * 被呼叫的時機: 1. 丟群組水球 flag = 1 (pre-edit) 2. 回水球 flag = 0 3. + * 上站aloha flag = 2 (pre-edit) 4. 廣播 flag = 3 if SYSOP, otherwise + * flag = 1 (pre-edit) 5. 丟水球 flag = 0 6. my_write2 flag = 4 + * (pre-edit) but confirm + */ +int +my_write(pid_t pid, char *prompt, char *id, int flag, userinfo_t * puin) { - int len, currstat0 = currstat, fri_stat; - char msg[80], destid[IDLEN + 1]; - char genbuf[200], buf[200], c0 = currutmp->chatid[0]; - unsigned char mode0 = currutmp->mode; - struct tm *ptime; - userinfo_t *uin; - uin = (puin != NULL) ? puin : (userinfo_t *)search_ulist_pid(pid); + int len, currstat0 = currstat, fri_stat; + char msg[80], destid[IDLEN + 1]; + char genbuf[200], buf[200], c0 = currutmp->chatid[0]; + unsigned char mode0 = currutmp->mode; + struct tm *ptime; + userinfo_t *uin; + uin = (puin != NULL) ? puin : (userinfo_t *) search_ulist_pid(pid); strcpy(destid, id); - - if(!uin && !(flag == 0 && water_which->count> 0)) { - outmsg("\033[1;33;41m糟糕! 對方已落跑了(不在站上)! \033[37m~>_<~\033[m"); + + if (!uin && !(flag == 0 && water_which->count > 0)) { + outmsg("\033[1;33;41m糟糕! 對方已落跑了(不在站上)! \033[37m~>_<~\033[m"); clrtoeol(); refresh(); watermode = -1; @@ -563,13 +574,13 @@ int my_write(pid_t pid, char *prompt, char *id, int flag, userinfo_t *puin) currutmp->mode = 0; currutmp->chatid[0] = 3; currstat = XMODE; - + ptime = localtime(&now); - - if(flag == 0) { + + if (flag == 0) { /* 一般水球 */ watermode = 0; - if(!(len = getdata(0, 0, prompt, msg, 56, DOECHO))) { + if (!(len = getdata(0, 0, prompt, msg, 56, DOECHO))) { outmsg("\033[1;33;42m算了! 放你一馬...\033[m"); clrtoeol(); refresh(); @@ -579,12 +590,11 @@ int my_write(pid_t pid, char *prompt, char *id, int flag, userinfo_t *puin) watermode = -1; return 0; } - - if(watermode > 0) { - int i; - - i = (water_which->top- watermode + MAX_REVIEW) % MAX_REVIEW; - uin = (userinfo_t *)search_ulist_pid(water_which->msg[i].pid); + if (watermode > 0) { + int i; + + i = (water_which->top - watermode + MAX_REVIEW) % MAX_REVIEW; + uin = (userinfo_t *) search_ulist_pid(water_which->msg[i].pid); strcpy(destid, water_which->msg[i].userid); } } else { @@ -592,12 +602,12 @@ int my_write(pid_t pid, char *prompt, char *id, int flag, userinfo_t *puin) strcpy(msg, prompt); len = strlen(msg); } - + strip_ansi(msg, msg, 0); - if(uin && *uin->userid && (flag == 0 || flag == 4)) { + if (uin && *uin->userid && (flag == 0 || flag == 4)) { sprintf(buf, "丟給 %s : %s [Y/n]?", uin->userid, msg); getdata(0, 0, buf, genbuf, 3, LCECHO); - if(genbuf[0] == 'n') { + if (genbuf[0] == 'n') { outmsg("\033[1;33;42m算了! 放你一馬...\033[m"); clrtoeol(); refresh(); @@ -608,9 +618,8 @@ int my_write(pid_t pid, char *prompt, char *id, int flag, userinfo_t *puin) return 0; } } - watermode = -1; - if(!uin || !*uin->userid || strcasecmp(destid, uin->userid)) { + if (!uin || !*uin->userid || strcasecmp(destid, uin->userid)) { outmsg("\033[1;33;41m糟糕! 對方已落跑了(不在站上)! \033[37m~>_<~\033[m"); clrtoeol(); refresh(); @@ -619,37 +628,36 @@ int my_write(pid_t pid, char *prompt, char *id, int flag, userinfo_t *puin) currstat = currstat0; return 0; } - - fri_stat=friend_stat(currutmp, uin); - if(flag != 2) { /* aloha 的水球不用存下來 */ + fri_stat = friend_stat(currutmp, uin); + if (flag != 2) { /* aloha 的水球不用存下來 */ /* 存到自己的水球檔 */ - if(!fp_writelog){ + if (!fp_writelog) { sethomefile(genbuf, cuser.userid, fn_writelog); fp_writelog = fopen(genbuf, "a"); } - if(fp_writelog) { - fprintf(fp_writelog, "To %s: %s [%s]\n", + if (fp_writelog) { + fprintf(fp_writelog, "To %s: %s [%s]\n", uin->userid, msg, Cdatelite(&now)); snprintf(t_last_write, 66, "To %s: %s", uin->userid, msg); } } - - if(flag == 3 && uin->msgcount) { + if (flag == 3 && uin->msgcount) { /* 不懂 */ uin->destuip = currutmp - &SHM->uinfo[0]; uin->sig = 2; - if(uin->pid > 0) kill(uin->pid, SIGUSR1); - } else if(flag != 2 && - !HAS_PERM(PERM_SYSOP) && - (uin->pager == 3 || - uin->pager == 2 || - (uin->pager == 4 && - !(fri_stat & HFM)))) + if (uin->pid > 0) + kill(uin->pid, SIGUSR1); + } else if (flag != 2 && + !HAS_PERM(PERM_SYSOP) && + (uin->pager == 3 || + uin->pager == 2 || + (uin->pager == 4 && + !(fri_stat & HFM)))) outmsg("\033[1;33;41m糟糕! 對方防水了! \033[37m~>_<~\033[m"); else { - if(uin->msgcount < MAX_MSGS) { - unsigned char pager0 = uin->pager; - + if (uin->msgcount < MAX_MSGS) { + unsigned char pager0 = uin->pager; + uin->pager = 2; uin->msgs[uin->msgcount].pid = currpid; strcpy(uin->msgs[uin->msgcount].userid, cuser.userid); @@ -657,80 +665,78 @@ int my_write(pid_t pid, char *prompt, char *id, int flag, userinfo_t *puin) uin->pager = pager0; } else if (flag != 2) outmsg("\033[1;33;41m糟糕! 對方不行了! (收到太多水球) \033[37m@_@\033[m"); - - if(uin->msgcount >= 1 && (uin->pid <= 0 || kill(uin->pid, SIGUSR2) == -1) && flag != 2) + + if (uin->msgcount >= 1 && (uin->pid <= 0 || kill(uin->pid, SIGUSR2) == -1) && flag != 2) outmsg("\033[1;33;41m糟糕! 沒打中! \033[37m~>_<~\033[m"); - else if(uin->msgcount == 1 && flag != 2) + else if (uin->msgcount == 1 && flag != 2) outmsg("\033[1;33;44m水球砸過去了! \033[37m*^o^*\033[m"); - else if(uin->msgcount > 1 && uin->msgcount < MAX_MSGS && flag != 2) + else if (uin->msgcount > 1 && uin->msgcount < MAX_MSGS && flag != 2) outmsg("\033[1;33;44m再補上一粒! \033[37m*^o^*\033[m"); } - + clrtoeol(); refresh(); - + currutmp->chatid[0] = c0; currutmp->mode = mode0; currstat = currstat0; return 1; } -void t_display_new(void) +void +t_display_new(void) { - static int t_display_new_flag=0; - int i, off=2; + static int t_display_new_flag = 0; + int i, off = 2; if (t_display_new_flag) return; else t_display_new_flag = 1; - if( WATERMODE(WATER_ORIG) ) + if (WATERMODE(WATER_ORIG)) water_which = &water[0]; else - off =3; + off = 3; - if (water[0].count && watermode > 0){ + if (water[0].count && watermode > 0) { move(1, 0); outs("───────水─球─回─顧───"); - outs(WATERMODE(WATER_ORIG) ? + outs(WATERMODE(WATER_ORIG) ? "──────用[Ctrl-R Ctrl-T]鍵切換─────" : "用[Ctrl-R Ctrl-T Ctrl-F Ctrl-G ]鍵切換────"); - if( WATERMODE(WATER_NEW) ){ + if (WATERMODE(WATER_NEW)) { move(2, 0); clrtoeol(); - for (i = 0; i<6 ; i++){ - if(i>0) - if(swater[i-1]) - { - - if( swater[i-1]->uin && - (swater[i-1]->pid != swater[i-1]->uin->pid || - swater[i-1]->userid[0]!=swater[i-1]->uin->userid[0]) ) - swater[i-1]->uin = (userinfo_t*)search_ulist_pid(swater[i-1]->pid); - prints("%s%c%-13.13s\033[m", - swater[i-1]!=water_which? "" : - swater[i-1]->uin?"\033[1;33;47m": - "\033[1;33;45m", - !swater[i-1]->uin?'#':' ', - swater[i-1]->userid); - } - else - prints(" "); + for (i = 0; i < 6; i++) { + if (i > 0) + if (swater[i - 1]) { + + if (swater[i - 1]->uin && + (swater[i - 1]->pid != swater[i - 1]->uin->pid || + swater[i - 1]->userid[0] != swater[i - 1]->uin->userid[0])) + swater[i - 1]->uin = (userinfo_t *) search_ulist_pid(swater[i - 1]->pid); + prints("%s%c%-13.13s\033[m", + swater[i - 1] != water_which ? "" : + swater[i - 1]->uin ? "\033[1;33;47m" : + "\033[1;33;45m", + !swater[i - 1]->uin ? '#' : ' ', + swater[i - 1]->userid); + } else + prints(" "); else prints("%s 全部 \033[m", - water_which==&water[0]?"\033[1;33;47m ": + water_which == &water[0] ? "\033[1;33;47m " : " " - ); + ); } } - - for (i = 0; i < water_which->count; i++){ - int a = (water_which->top - i - 1 + MAX_REVIEW) % MAX_REVIEW, - len = 75-strlen(water_which->msg[a].last_call_in) - -strlen(water_which->msg[a].userid); - if(len<0) len=0; - - move(i + (WATERMODE(WATER_ORIG)?2:3), 0); + for (i = 0; i < water_which->count; i++) { + int a = (water_which->top - i - 1 + MAX_REVIEW) % MAX_REVIEW, len = 75 - strlen(water_which->msg[a].last_call_in) + - strlen(water_which->msg[a].userid); + if (len < 0) + len = 0; + + move(i + (WATERMODE(WATER_ORIG) ? 2 : 3), 0); clrtoeol(); if (watermode - 1 != i) prints("\033[1;33;46m %s \033[37;45m %s \033[m%*s", @@ -740,12 +746,12 @@ void t_display_new(void) else prints("\033[1;44m>\033[1;33;47m%s " "\033[37;45m %s \033[m%*s", - water_which->msg[a].userid, + water_which->msg[a].userid, water_which->msg[a].last_call_in, - len,""); + len, ""); } - - if (t_last_write[0]){ + + if (t_last_write[0]) { move(i + off, 0); clrtoeol(); prints(t_last_write); @@ -754,34 +760,34 @@ void t_display_new(void) move(i + off, 0); outs("──────────────────────" "─────────────────"); - if( WATERMODE(WATER_NEW) ) - while( i++ <= water[0].count ) { - move(i + off, 0); - clrtoeol(); - } + if (WATERMODE(WATER_NEW)) + while (i++ <= water[0].count) { + move(i + off, 0); + clrtoeol(); + } } - t_display_new_flag = 0; } -int t_display(void) +int +t_display(void) { - char genbuf[200], ans[4]; - if(fp_writelog){ + char genbuf[200], ans[4]; + if (fp_writelog) { fclose(fp_writelog); - fp_writelog=NULL; + fp_writelog = NULL; } setuserfile(genbuf, fn_writelog); - if (more(genbuf, YEA) != -1){ + if (more(genbuf, YEA) != -1) { move(b_lines - 4, 0); outs("\033[1;33;45m★現在 Ptt提供創新的水球整理程式★\033[m\n" "您將水球存至信箱後, 在【郵件選單】該信件前按 u,\n" "系統即會將您的水球紀錄重新整理後寄送給您唷! \n"); getdata(b_lines - 1, 0, "清除(C) 移至備忘錄(M) 保留(R) (C/M/R)?[R]", ans, sizeof(ans), LCECHO); - if (*ans == 'm'){ - fileheader_t mymail; - char title[128], buf[80]; + if (*ans == 'm') { + fileheader_t mymail; + char title[128], buf[80]; sethomepath(buf, cuser.userid); stampfile(buf, &mymail); @@ -792,15 +798,15 @@ int t_display(void) sethomedir(title, cuser.userid); Rename(genbuf, buf); append_record(title, &mymail, sizeof(mymail)); - } - else if (*ans == 'c') + } else if (*ans == 'c') unlink(genbuf); return FULLUPDATE; } return DONOTHING; } -static void do_talk_nextline(talkwin_t * twin) +static void +do_talk_nextline(talkwin_t * twin) { twin->curcol = 0; if (twin->curln < twin->eline) @@ -810,13 +816,14 @@ static void do_talk_nextline(talkwin_t * twin) move(twin->curln, twin->curcol); } -static void do_talk_char(talkwin_t * twin, int ch) +static void +do_talk_char(talkwin_t * twin, int ch) { - screenline_t *line; - int i; - char ch0, buf[81]; + screenline_t *line; + int i; + char ch0, buf[81]; - if (isprint2(ch)){ + if (isprint2(ch)) { ch0 = big_picture[twin->curln].data[twin->curcol]; if (big_picture[twin->curln].len < 79) move(twin->curln, twin->curcol); @@ -825,7 +832,7 @@ static void do_talk_char(talkwin_t * twin, int ch) outc(ch); ++(twin->curcol); line = big_picture + twin->curln; - if (twin->curcol < line->len){ /* insert */ + if (twin->curcol < line->len) { /* insert */ ++(line->len); memcpy(buf, line->data + twin->curcol, 80); save_cursor(); @@ -838,15 +845,14 @@ static void do_talk_char(talkwin_t * twin, int ch) line->data[line->len] = 0; return; } - - switch (ch){ + switch (ch) { case Ctrl('H'): case '\177': if (twin->curcol == 0) return; line = big_picture + twin->curln; --(twin->curcol); - if (twin->curcol < line->len){ + if (twin->curcol < line->len) { --(line->len); save_cursor(); do_move(twin->curcol, twin->curln); @@ -860,7 +866,7 @@ static void do_talk_char(talkwin_t * twin, int ch) return; case Ctrl('D'): line = big_picture + twin->curln; - if (twin->curcol < line->len){ + if (twin->curcol < line->len) { --(line->len); save_cursor(); do_move(twin->curcol, twin->curln); @@ -875,13 +881,13 @@ static void do_talk_char(talkwin_t * twin, int ch) bell(); return; case Ctrl('B'): - if (twin->curcol > 0){ + if (twin->curcol > 0) { --(twin->curcol); move(twin->curln, twin->curcol); } return; case Ctrl('F'): - if (twin->curcol < 79){ + if (twin->curcol < 79) { ++(twin->curcol); move(twin->curln, twin->curcol); } @@ -919,7 +925,7 @@ static void do_talk_char(talkwin_t * twin, int ch) line = big_picture + twin->curln; strncpy(buf, (char *)line->data, line->len); buf[line->len] = 0; - if (twin->curln > twin->sline){ + if (twin->curln > twin->sline) { --(twin->curln); move(twin->curln, twin->curcol); } @@ -928,7 +934,7 @@ static void do_talk_char(talkwin_t * twin, int ch) line = big_picture + twin->curln; strncpy(buf, (char *)line->data, line->len); buf[line->len] = 0; - if (twin->curln < twin->eline){ + if (twin->curln < twin->eline) { ++(twin->curln); move(twin->curln, twin->curcol); } @@ -943,15 +949,16 @@ static void do_talk_char(talkwin_t * twin, int ch) (ch == Ctrl('P')) ? "\033[37;45m(Up)\033[m" : "\033[m"); } -static void do_talk(int fd) +static void +do_talk(int fd) { struct talkwin_t mywin, itswin; - char mid_line[128], data[200]; - int i, datac, ch; - int im_leaving = 0; - FILE *log; - struct tm *ptime; - char genbuf[200], fpath[100]; + char mid_line[128], data[200]; + int i, datac, ch; + int im_leaving = 0; + FILE *log; + struct tm *ptime; + char genbuf[200], fpath[100]; ptime = localtime(&now); @@ -972,7 +979,7 @@ static void do_talk(int fd) i = ch - strlen(genbuf); if (i >= 0) i = (i >> 1) + 1; - else{ + else { genbuf[ch] = '\0'; i = 1; } @@ -997,17 +1004,16 @@ static void do_talk(int fd) add_io(fd, 0); - while (1){ + while (1) { ch = igetkey(); - if (ch == I_OTHERDATA){ + if (ch == I_OTHERDATA) { datac = recv(fd, data, sizeof(data), 0); if (datac <= 0) break; for (i = 0; i < datac; i++) do_talk_char(&itswin, data[i]); - } - else{ - if (ch == Ctrl('C')){ + } else { + if (ch == Ctrl('C')) { if (im_leaving) break; move(b_lines, 0); @@ -1016,12 +1022,12 @@ static void do_talk(int fd) im_leaving = 1; continue; } - if (im_leaving){ + if (im_leaving) { move(b_lines, 0); clrtoeol(); im_leaving = 0; } - switch (ch){ + switch (ch) { case KEY_LEFT: /* 把2byte的鍵改為一byte */ ch = Ctrl('B'); break; @@ -1035,11 +1041,11 @@ static void do_talk(int fd) ch = Ctrl('N'); break; } - data[0] = (char) ch; + data[0] = (char)ch; if (send(fd, data, 1, 0) != 1) break; if (log) - fprintf(log, "%c", (ch == Ctrl('M')) ? '\n' : (char) *data); + fprintf(log, "%c", (ch == Ctrl('M')) ? '\n' : (char)*data); do_talk_char(&mywin, *data); } } @@ -1049,9 +1055,9 @@ static void do_talk(int fd) add_io(0, 0); close(fd); - if (flog){ - char ans[4]; - int i; + if (flog) { + char ans[4]; + int i; fprintf(flog, "\n\033[33;44m離別畫面 [%s] ... \033[m\n", Cdatelite(&now)); @@ -1061,37 +1067,38 @@ static void do_talk(int fd) more(fpath, NA); getdata(b_lines - 1, 0, "清除(C) 移至備忘錄(M). (C/M)?[C]", ans, sizeof(ans), LCECHO); - if (*ans == 'm'){ - fileheader_t mymail; - char title[128]; + if (*ans == 'm') { + fileheader_t mymail; + char title[128]; sethomepath(genbuf, cuser.userid); stampfile(genbuf, &mymail); - mymail.filemode = FILE_READ|FILE_HOLD; + mymail.filemode = FILE_READ | FILE_HOLD; strcpy(mymail.owner, "[備.忘.錄]"); sprintf(mymail.title, "對話記錄 \033[1;36m(%s)\033[m", getuserid(currutmp->destuid)); sethomedir(title, cuser.userid); Rename(fpath, genbuf); append_record(title, &mymail, sizeof(mymail)); - } - else + } else unlink(fpath); flog = 0; } setutmpmode(XINFO); } -#define lockreturn(unmode, state) if(lockutmpmode(unmode, state)) return +#define lockreturn(unmode, state) if(lockutmpmode(unmode, state)) return -static void my_talk(userinfo_t * uin, int fri_stat) { - int sock, msgsock, length, ch, error = 0; +static void +my_talk(userinfo_t * uin, int fri_stat) +{ + int sock, msgsock, length, ch, error = 0; struct sockaddr_in server; - pid_t pid; - char c; - char genbuf[4]; + pid_t pid; + char c; + char genbuf[4]; - unsigned char mode0 = currutmp->mode; + unsigned char mode0 = currutmp->mode; ch = uin->mode; strcpy(currauthor, uin->userid); @@ -1099,31 +1106,26 @@ static void my_talk(userinfo_t * uin, int fri_stat) { if (ch == EDITING || ch == TALK || ch == CHATING || ch == PAGE || ch == MAILALL || ch == MONITOR || ch == M_FIVE || ch == CHC || (!ch && (uin->chatid[0] == 1 || uin->chatid[0] == 3)) || - uin->lockmode == M_FIVE || uin->lockmode == CHC){ + uin->lockmode == M_FIVE || uin->lockmode == CHC) { outs("人家在忙啦"); - } - else if (!HAS_PERM(PERM_SYSOP) && - (((fri_stat& HRM) && !(fri_stat& HFM)) || - ((!uin->pager) && !(fri_stat & HFM)) ) ){ + } else if (!HAS_PERM(PERM_SYSOP) && + (((fri_stat & HRM) && !(fri_stat & HFM)) || + ((!uin->pager) && !(fri_stat & HFM)))) { outs("對方關掉呼叫器了"); - } - else if (!HAS_PERM(PERM_SYSOP) && - (((fri_stat & HRM) && !(fri_stat& HFM)) || uin->pager == 2 )) { + } else if (!HAS_PERM(PERM_SYSOP) && + (((fri_stat & HRM) && !(fri_stat & HFM)) || uin->pager == 2)) { outs("對方拔掉呼叫器了"); - } - else if (!HAS_PERM(PERM_SYSOP) && - !(fri_stat & HFM) && uin->pager == 4){ + } else if (!HAS_PERM(PERM_SYSOP) && + !(fri_stat & HFM) && uin->pager == 4) { outs("對方只接受好友的呼叫"); - } - else if (!(pid = uin->pid) /*|| (kill(pid, 0) == -1) */ ){ + } else if (!(pid = uin->pid) /* || (kill(pid, 0) == -1) */ ) { //resetutmpent(); outs(msg_usr_left); - } - else{ + } else { showplans(uin->userid); getdata(2, 0, "要和他(她) (T)談天(F)下五子棋(P)鬥寵物" "(C)下象棋(D)下暗棋(N)沒事找錯人了?[N] ", genbuf, 4, LCECHO); - switch (*genbuf){ + switch (*genbuf) { case 'y': case 't': uin->sig = SIG_TALK; @@ -1146,7 +1148,7 @@ static void my_talk(userinfo_t * uin, int fri_stat) { error = 1; if (!cuser.mychicken.name[0] || !xuser.mychicken.name[0]) error = 2; - if (error){ + if (error) { outmsg(error == 2 ? "並非兩人都養寵物" : "有一方的寵物正在使用中"); bell(); @@ -1166,7 +1168,7 @@ static void my_talk(userinfo_t * uin, int fri_stat) { strcpy(currutmp->mateid, uin->userid); sock = socket(AF_INET, SOCK_STREAM, 0); - if (sock < 0){ + if (sock < 0) { perror("sock err"); unlockutmpmode(); return; @@ -1174,14 +1176,14 @@ static void my_talk(userinfo_t * uin, int fri_stat) { server.sin_family = PF_INET; server.sin_addr.s_addr = INADDR_ANY; server.sin_port = 0; - if (bind(sock, (struct sockaddr *) &server, sizeof(server)) < 0){ + if (bind(sock, (struct sockaddr *) & server, sizeof(server)) < 0) { close(sock); perror("bind err"); unlockutmpmode(); return; } length = sizeof(server); - if (getsockname(sock, (struct sockaddr *) &server, (socklen_t*)&length) < 0){ + if (getsockname(sock, (struct sockaddr *) & server, (socklen_t *) & length) < 0) { close(sock); perror("sock name err"); unlockutmpmode(); @@ -1192,27 +1194,27 @@ static void my_talk(userinfo_t * uin, int fri_stat) { currutmp->destuid = uin->uid; setutmpmode(PAGE); uin->destuip = currutmp - &SHM->uinfo[0]; - if(pid > 0) kill(pid, SIGUSR1); + if (pid > 0) + kill(pid, SIGUSR1); clear(); prints("正呼叫 %s.....\n鍵入 Ctrl-D 中止....", uin->userid); listen(sock, 1); add_io(sock, 5); - while (1){ + while (1) { ch = igetch(); - if (ch == I_TIMEOUT){ + if (ch == I_TIMEOUT) { ch = uin->mode; if (!ch && uin->chatid[0] == 1 && - uin->destuip == currutmp - &SHM->uinfo[0]){ + uin->destuip == currutmp - &SHM->uinfo[0]) { bell(); outmsg("對方回應中..."); refresh(); - } - else if (ch == EDITING || ch == TALK || ch == CHATING || - ch == PAGE || ch == MAILALL || ch == MONITOR || - ch == M_FIVE || ch == CHC || - (!ch && (uin->chatid[0] == 1 || - uin->chatid[0] == 3))){ + } else if (ch == EDITING || ch == TALK || ch == CHATING || + ch == PAGE || ch == MAILALL || ch == MONITOR || + ch == M_FIVE || ch == CHC || + (!ch && (uin->chatid[0] == 1 || + uin->chatid[0] == 3))) { add_io(0, 0); close(sock); currutmp->sockactive = currutmp->destuid = 0; @@ -1220,8 +1222,7 @@ static void my_talk(userinfo_t * uin, int fri_stat) { pressanykey(); unlockutmpmode(); return; - } - else{ + } else { #ifdef linux add_io(sock, 20); /* added for linux... achen */ #endif @@ -1230,7 +1231,7 @@ static void my_talk(userinfo_t * uin, int fri_stat) { bell(); uin->destuip = currutmp - &SHM->uinfo[0]; - if(pid <= 0 || kill(pid, SIGUSR1) == -1){ + if (pid <= 0 || kill(pid, SIGUSR1) == -1) { #ifdef linux add_io(sock, 20); /* added 4 linux... achen */ #endif @@ -1243,11 +1244,10 @@ static void my_talk(userinfo_t * uin, int fri_stat) { continue; } } - if (ch == I_OTHERDATA) break; - if (ch == '\004'){ + if (ch == '\004') { add_io(0, 0); close(sock); currutmp->sockactive = currutmp->destuid = 0; @@ -1257,7 +1257,7 @@ static void my_talk(userinfo_t * uin, int fri_stat) { } msgsock = accept(sock, (struct sockaddr *) 0, (socklen_t *) 0); - if (msgsock == -1){ + if (msgsock == -1) { perror("accept"); unlockutmpmode(); return; @@ -1267,11 +1267,11 @@ static void my_talk(userinfo_t * uin, int fri_stat) { currutmp->sockactive = NA; read(msgsock, &c, sizeof c); - if (c == 'y'){ + if (c == 'y') { sprintf(save_page_requestor, "%s (%s)", uin->userid, uin->username); /* gomo */ - switch (uin->sig){ + switch (uin->sig) { case SIG_DARK: main_dark(msgsock, uin); break; @@ -1288,11 +1288,10 @@ static void my_talk(userinfo_t * uin, int fri_stat) { default: do_talk(msgsock); } - } - else{ + } else { move(9, 9); outs("【回音】 "); - switch (c){ + switch (c) { case 'a': outs("我現在很忙,請等一會兒再 call 我,好嗎?"); break; @@ -1310,8 +1309,8 @@ static void my_talk(userinfo_t * uin, int fri_stat) { break; case 'f': { - char msgbuf[60]; - + char msgbuf[60]; + read(msgsock, msgbuf, 60); prints("對不起,我現在不能跟你 %s,因為\n", sig_des[uin->sig]); move(10, 18); @@ -1342,23 +1341,25 @@ static void my_talk(userinfo_t * uin, int fri_stat) { #define US_ACTION 1232 #define US_REDRAW 1231 -static void t_showhelp() { +static void +t_showhelp() +{ clear(); outs("\033[36m【 休閒聊天使用說明 】\033[m\n\n" "(←)(e) 結束離開 (h) 看使用說明\n" - "(↑)/(↓)(n) 上下移動 (TAB) 切換排序方式\n" + "(↑)/(↓)(n) 上下移動 (TAB) 切換排序方式\n" "(PgUp)(^B) 上頁選單 ( )(PgDn)(^F) 下頁選單\n" "(Hm)/($)(Ed) 首/尾 (S) " "來源/好友描述/戰績 切換\n" "(m) 寄信 (q/c) " "查詢網友/寵物\n" "(r) 閱\讀信件 (l/C) 看上次熱訊/切換隱身\n" - "(f) 全部/好友列表 (數字) 跳至該使用者\n" - "(p) 切換呼叫器 (g/i) 給錢/切換心情\n" - "(a/d/o) 好友 增加/刪除/修改 (/)(s) 網友ID/暱稱搜尋"); + "(f) 全部/好友列表 (數字) 跳至該使用者\n" + "(p) 切換呼叫器 (g/i) 給錢/切換心情\n" + "(a/d/o) 好友 增加/刪除/修改 (/)(s) 網友ID/暱稱搜尋"); - if (HAS_PERM(PERM_PAGE)){ + if (HAS_PERM(PERM_PAGE)) { outs("\n\n\033[36m【 交談專用鍵 】\033[m\n\n" "(→)(t)(Enter) 跟他/她聊天\n" "(w) 熱線 Call in\n" @@ -1366,8 +1367,7 @@ static void t_showhelp() { "(b) 對好友廣播 (一定要在好友列表中)\n" "(^R) 即時回應 (有人 Call in 你時)"); } - - if (HAS_PERM(PERM_SYSOP)){ + if (HAS_PERM(PERM_SYSOP)) { outs("\n\n\033[36m【 站長專用鍵 】\033[m\n\n"); if (HAS_PERM(PERM_SYSOP)) outs("(u)/(H) 設定使用者資料/切換隱形模式\n"); @@ -1377,38 +1377,33 @@ static void t_showhelp() { } /* -static int listcuent(userinfo_t * uentp) -{ - if((!uentp->invisible || HAS_PERM(PERM_SYSOP) || HAS_PERM(PERM_SEECLOAK))) - AddNameList(uentp->userid); - return 0; -} - -static void creat_list() -{ - CreateNameList(); - apply_ulist(listcuent); -} -*/ + * static int listcuent(userinfo_t * uentp) { if((!uentp->invisible || + * HAS_PERM(PERM_SYSOP) || HAS_PERM(PERM_SEECLOAK))) + * AddNameList(uentp->userid); return 0; } + * + * static void creat_list() { CreateNameList(); apply_ulist(listcuent); } + */ /* Kaede show friend description */ -static char *friend_descript(char *uident) { - static char *space_buf = " "; - static char desc_buf[80]; - char fpath[80], name[IDLEN + 2], *desc, *ptr; - int len, flag; - FILE *fp; - char genbuf[200]; +static char * +friend_descript(char *uident) +{ + static char *space_buf = " "; + static char desc_buf[80]; + char fpath[80], name[IDLEN + 2], *desc, *ptr; + int len, flag; + FILE *fp; + char genbuf[200]; setuserfile(fpath, friend_file[0]); - if ((fp = fopen(fpath, "r"))){ + if ((fp = fopen(fpath, "r"))) { sprintf(name, "%s ", uident); len = strlen(name); desc = genbuf + 13; - while ((flag = (int) fgets(genbuf, STRLEN, fp))){ - if (!memcmp(genbuf, name, len)){ + while ((flag = (int)fgets(genbuf, STRLEN, fp))) { + if (!memcmp(genbuf, name, len)) { if ((ptr = strchr(desc, '\n'))) ptr[0] = '\0'; if (desc) @@ -1422,15 +1417,15 @@ static char *friend_descript(char *uident) { return space_buf; return desc_buf; - } - else + } else return space_buf; } -static char *descript(int show_mode, userinfo_t * uentp, time_t diff) +static char * +descript(int show_mode, userinfo_t * uentp, time_t diff) { - switch (show_mode){ - case 1: + switch (show_mode) { + case 1: return friend_descript(uentp->userid); case 0: return (((uentp->pager != 2 && uentp->pager != 3 && diff) || @@ -1455,52 +1450,55 @@ static char *descript(int show_mode, userinfo_t * uentp, time_t diff) } #define MAXPICKUP 20 -static int sort_cmpfriend(const void *a, const void *b) +static int +sort_cmpfriend(const void *a, const void *b) { - if( ((((pickup_t *)a)->friend)&ST_FRIEND) == - ((((pickup_t *)b)->friend)&ST_FRIEND) ) - return strcasecmp( ((pickup_t *)a)->ui->userid, - ((pickup_t *)b)->ui->userid ); + if (((((pickup_t *) a)->friend) & ST_FRIEND) == + ((((pickup_t *) b)->friend) & ST_FRIEND)) + return strcasecmp(((pickup_t *) a)->ui->userid, + ((pickup_t *) b)->ui->userid); else - return (((pickup_t *)b)->friend & ST_FRIEND) - - (((pickup_t *)a)->friend & ST_FRIEND); + return (((pickup_t *) b)->friend & ST_FRIEND) - + (((pickup_t *) a)->friend & ST_FRIEND); } -int pickup_maxpages(int pickupway, int nfriends) +int +pickup_maxpages(int pickupway, int nfriends) { - int number; - if( cuser.uflag & FRIEND_FLAG ) + int number; + if (cuser.uflag & FRIEND_FLAG) number = nfriends; else - number = SHM->UTMPnumber+ - (pickupway == 0 ? nfriends : 0); - return (number-1) / MAXPICKUP +1; + number = SHM->UTMPnumber + + (pickupway == 0 ? nfriends : 0); + return (number - 1) / MAXPICKUP + 1; } -static int pickup_myfriend(pickup_t *friends, - int *myfriend, int *friendme) +static int +pickup_myfriend(pickup_t * friends, + int *myfriend, int *friendme) { - userinfo_t *uentp; - int i, where, frstate, ngets=0; - + userinfo_t *uentp; + int i, where, frstate, ngets = 0; + *myfriend = *friendme = 1; - for( i = 0 ; currutmp->friend_online[i] && i < MAX_FRIEND ; ++i ){ + for (i = 0; currutmp->friend_online[i] && i < MAX_FRIEND; ++i) { where = currutmp->friend_online[i] & 0xFFFFFF; - if( 0 <= where && where < MAX_ACTIVE && - (uentp = &SHM->uinfo[where]) && uentp->pid && - uentp != currutmp && + if (0 <= where && where < MAX_ACTIVE && + (uentp = &SHM->uinfo[where]) && uentp->pid && + uentp != currutmp && isvisible_stat(currutmp, uentp, frstate = currutmp->friend_online[i] >> 24) && - ( !(frstate & IRH) || ((frstate & IRH) && (frstate & IFH)) ) - ){ + (!(frstate & IRH) || ((frstate & IRH) && (frstate & IFH))) + ) { friends[ngets].ui = uentp; friends[ngets].uoffset = where; friends[ngets++].friend = frstate; - if( frstate & IFH ) - ++*myfriend; - if( frstate & HFM ) - ++*friendme; + if (frstate & IFH) + ++* myfriend; + if (frstate & HFM) + ++* friendme; } } friends[ngets].ui = currutmp; @@ -1508,18 +1506,18 @@ static int pickup_myfriend(pickup_t *friends, return ngets; } -static int pickup_bfriend(pickup_t *friends, int base) +static int +pickup_bfriend(pickup_t * friends, int base) { - userinfo_t *uentp; - int i, ngets = 0; - int currsorted = SHM->currsorted, - number = SHM->UTMPnumber; + userinfo_t *uentp; + int i, ngets = 0; + int currsorted = SHM->currsorted, number = SHM->UTMPnumber; friends = friends + base; - for( i = 0 ; i < number && ngets < MAX_FRIEND - base ; ++i ){ + for (i = 0; i < number && ngets < MAX_FRIEND - base; ++i) { uentp = SHM->sorted[currsorted][0][i]; - if( uentp && uentp->pid && uentp->brc_id == currutmp->brc_id && + if (uentp && uentp->pid && uentp->brc_id == currutmp->brc_id && currutmp != uentp && isvisible(currutmp, uentp) && - (base || !(friend_stat(currutmp, uentp) & (IFH | HFM))) ){ + (base || !(friend_stat(currutmp, uentp) & (IFH | HFM)))) { friends[ngets].ui = uentp; friends[ngets++].friend = IBH; } @@ -1527,120 +1525,116 @@ static int pickup_bfriend(pickup_t *friends, int base) return ngets; } -static void pickup(pickup_t *currpickup, int pickup_way, int *page, - int *nfriend, int *myfriend, int *friendme, int *bfriend) +static void +pickup(pickup_t * currpickup, int pickup_way, int *page, + int *nfriend, int *myfriend, int *friendme, int *bfriend) { /* avoid race condition */ - int currsorted = SHM->currsorted; - int utmpnumber = SHM->UTMPnumber; - int friendtotal= currutmp->friendtotal; + int currsorted = SHM->currsorted; + int utmpnumber = SHM->UTMPnumber; + int friendtotal = currutmp->friendtotal; - userinfo_t **utmp; - int which, sorted_way, size=0, friend; + userinfo_t **utmp; + int which, sorted_way, size = 0, friend; - if( friendtotal == 0 ) + if (friendtotal == 0) *myfriend = *friendme = 1; - if( cuser.uflag & FRIEND_FLAG || - (pickup_way == 0 && *page * MAXPICKUP < MAX_FRIEND ) ){ - /* [嗨! 朋友] mode. - we need to pickup ALL friends (from currutmp friend_online), - sort, and get pickup from right starting position */ + if (cuser.uflag & FRIEND_FLAG || + (pickup_way == 0 && *page * MAXPICKUP < MAX_FRIEND)) { + /* + * [嗨! 朋友] mode. we need to pickup ALL friends (from currutmp + * friend_online), sort, and get pickup from right starting position + */ pickup_t friends[MAX_FRIEND]; - + *nfriend = pickup_myfriend(friends, myfriend, friendme); - if( pickup_way == 0 && currutmp->brc_id != 0 ) - *bfriend = pickup_bfriend(friends,*nfriend); - else - *bfriend=0; - *nfriend += *bfriend; - which = *page * MAXPICKUP; - if( *nfriend > which ){ // Ptt: 只有在要秀出才有必要 sort - qsort(friends, *nfriend, sizeof(pickup_t), sort_cmpfriend); + if (pickup_way == 0 && currutmp->brc_id != 0) + *bfriend = pickup_bfriend(friends, *nfriend); + else + *bfriend = 0; + *nfriend += *bfriend; + which = *page * MAXPICKUP; + if (*nfriend > which) { + //Ptt: 只 釵b n q X ~有必要 sort + qsort(friends, *nfriend, sizeof(pickup_t), sort_cmpfriend); size = *nfriend - which; - if( size > MAXPICKUP ) + if (size > MAXPICKUP) size = MAXPICKUP; - memcpy(currpickup, friends + which, sizeof(pickup_t) * size); + memcpy(currpickup, friends + which, sizeof(pickup_t) * size); } - } - else - *nfriend=0; + } else + *nfriend = 0; - if( !(cuser.uflag & FRIEND_FLAG) && size < MAXPICKUP ){ + if (!(cuser.uflag & FRIEND_FLAG) && size < MAXPICKUP) { sorted_way = ((pickup_way == 0) ? 0 : (pickup_way - 1)); utmp = SHM->sorted[currsorted][sorted_way]; - which = *page * MAXPICKUP-*nfriend; - if( which < 0 ) + which = *page * MAXPICKUP - *nfriend; + if (which < 0) which = 0; - for( ; which < utmpnumber && size < MAXPICKUP ; which++ ){ + for (; which < utmpnumber && size < MAXPICKUP; which++) { friend = friend_stat(currutmp, utmp[which]); - if( ( pickup_way || - (currutmp != utmp[which] && !(friend & ST_FRIEND))) && - isvisible_stat(currutmp, utmp[which], 0)){ + if ((pickup_way || + (currutmp != utmp[which] && !(friend & ST_FRIEND))) && + isvisible_stat(currutmp, utmp[which], 0)) { currpickup[size].ui = utmp[which]; currpickup[size++].friend = friend; } } } /* - for( which = (which >= 0 ? which : 0) ; - got < MAXPICKUP && which < utmpnumber ; - ++got, ++which ){ - - for( ; which < utmpnumber ; ++which ) - if( currutmp != utmp[which] && - isvisible_stat(currutmp, utmp[which], 0) ) - break; - if( which == utmpnumber ) - break; - currpickup[got].ui = utmp[which]; - currpickup[got].friend = 0; - } - */ - - for( ; size < MAXPICKUP ; ++size ) + * for( which = (which >= 0 ? which : 0) ; got < MAXPICKUP && which + * < utmpnumber ; ++got, ++which ){ + * + * for( ; which < utmpnumber ; ++which ) if( currutmp != utmp[which] && + * isvisible_stat(currutmp, utmp[which], 0) ) break; if( which == + * utmpnumber ) break; currpickup[got].ui = utmp[which]; + * currpickup[got].friend = 0; } + */ + + for (; size < MAXPICKUP; ++size) currpickup[size].ui = 0; } -static void draw_pickup(int drawall, pickup_t *pickup, int pickup_way, - int page, int show_mode, int show_uid, int show_board, - int show_pid, int real_name, - int myfriend, int friendme, int bfriend) +static void +draw_pickup(int drawall, pickup_t * pickup, int pickup_way, + int page, int show_mode, int show_uid, int show_board, + int show_pid, int real_name, + int myfriend, int friendme, int bfriend) { - char *msg_pickup_way[PICKUP_WAYS] = { + char *msg_pickup_way[PICKUP_WAYS] = { "嗨! 朋友", "網友代號", "網友動態", "發呆時間", "來自何方", "五子棋 " }; - char *MODE_STRING[MAX_SHOW_MODE] = {"故鄉", "好友描述", "五子棋戰績"}; - char pagerchar[5] = "* -Wf"; + char *MODE_STRING[MAX_SHOW_MODE] = {"故鄉", "好友描述", "五子棋戰績"}; + char pagerchar[5] = "* -Wf"; - userinfo_t *uentp; - int i, ch, state, friend; - char mind[5]; + userinfo_t *uentp; + int i, ch, state, friend; + char mind[5]; #ifdef SHOW_IDLE_TIME - char idlestr[32]; - int idletime; + char idlestr[32]; + int idletime; #endif - if( drawall ){ + if (drawall) { showtitle((cuser.uflag & FRIEND_FLAG) ? "好友列表" : "休閒聊天", BBSName); prints("\n" "\033[7m %s P%c代號 %-17s%-17s%-13s%-10s\033[m\n", - show_uid ? "UID" : "No.", + show_uid ? "UID" : "No.", (HAS_PERM(PERM_SEECLOAK) || HAS_PERM(PERM_SYSOP)) ? 'C' : ' ', real_name ? "姓名" : "暱稱", MODE_STRING[show_mode], show_board ? "Board" : "動態", show_pid ? " PID" : "備註 發呆" - ); + ); move(b_lines, 0); outs("\033[31;47m(TAB/f)\033[30m排序/好友 \033[31m(t)\033[30m聊天 " "\033[31m(a/d/o)\033[30m交友 \033[31m(q)\033[30m查詢 " "\033[31m(w)\033[30m水球 \033[31m(m)\033[30m寄信 \033[31m(h)" "\033[30m線上輔助 \033[m"); } - move(1, 0); prints(" 排序:[%s] 上站人數:%-4d\033[1;32m我的朋友:%-3d" "\033[33m與我為友:%-3d\033[36m板友:%-4d\033[31m壞人:" @@ -1648,47 +1642,46 @@ static void draw_pickup(int drawall, pickup_t *pickup, int pickup_way, msg_pickup_way[pickup_way], SHM->UTMPnumber, myfriend, friendme, currutmp->brc_id ? (bfriend + 1) : 0, 0); - for( i = 0, ch = page * 20 + 1 ; i < MAXPICKUP ; ++i, ++ch ){ - move(i + 3, 0); prints("a"); + for (i = 0, ch = page * 20 + 1; i < MAXPICKUP; ++i, ++ch) { + move(i + 3, 0); + prints("a"); move(i + 3, 0); uentp = pickup[i].ui; friend = pickup[i].friend; - if( uentp == NULL ){ + if (uentp == NULL) { prints("\n"); continue; } - - if( !uentp->pid ){ + if (!uentp->pid) { prints("%5d < 離站中..>\n", ch); continue; } - - if( PERM_HIDE(uentp) ) + if (PERM_HIDE(uentp)) state = 9; - else if( currutmp == uentp ) + else if (currutmp == uentp) state = 10; - else if( friend & IRH && !(friend & IFH) ) + else if (friend & IRH && !(friend & IFH)) state = 8; else state = (friend & ST_FRIEND) >> 2; #ifdef SHOW_IDLE_TIME idletime = (now - uentp->lastact); - if( idletime > 86400 ) - strcpy(idlestr, " -----"); - else if( idletime >= 3600 ) + if (idletime > 86400) + strcpy(idlestr, " -----"); + else if (idletime >= 3600) sprintf(idlestr, "%3dh%02d", idletime / 3600, (idletime / 60) % 60); - else if( idletime > 0 ) + else if (idletime > 0) sprintf(idlestr, "%3d'%02d", idletime / 60, idletime % 60); else - strcpy(idlestr, " "); + strcpy(idlestr, " "); #endif - if( (uentp->userlevel & PERM_VIOLATELAW) ) + if ((uentp->userlevel & PERM_VIOLATELAW)) memcpy(mind, "通緝", 4); - else if( uentp->birth ) + else if (uentp->birth) memcpy(mind, "壽星", 4); else memcpy(mind, uentp->mind, 4); @@ -1696,58 +1689,59 @@ static void draw_pickup(int drawall, pickup_t *pickup, int pickup_way, prints("%5d %c%c%s%-13s%-17.16s\033[m%-17.16s%-13.13s" "\33[33m%-4.4s\33[m%s\n", - /* list number or uid */ + /* list number or uid */ #ifdef SHOWUID show_uid ? uentp->uid : #endif ch, - /* super friend or pager */ - (friend & HRM) ? 'X' : pagerchar[uentp->pager % 5], + /* super friend or pager */ + (friend & HRM) ? 'X' : pagerchar[uentp->pager % 5], - /* visibility */ + /* visibility */ (uentp->invisible ? ')' : ' '), - /* color of userid, userid */ + /* color of userid, userid */ fcolor[state], uentp->userid, - /* nickname or realname */ + /* nickname or realname */ #ifdef REALINFO real_name ? uentp->realname : #endif uentp->username, - /* from */ + /* from */ descript(show_mode, uentp, - uentp->pager & !(friend&HRM)), + uentp->pager & !(friend & HRM)), - /* board or mode */ + /* board or mode */ #ifdef SHOWBOARD show_board ? (uentp->brc_id == 0 ? "" : bcache[uentp->brc_id - 1].brdname) : #endif - /* %-13.13s */ + /* %-13.13s */ modestring(uentp, 0), - - /* memo */ + + /* memo */ mind, - /* idle */ + /* idle */ #ifdef SHOW_IDLE_TIME idlestr #else "" #endif - ); + ); refresh(); } } -int call_in(userinfo_t *uentp, int fri_stat) +int +call_in(userinfo_t * uentp, int fri_stat) { - if( iswritable_stat(uentp, fri_stat) ){ - char genbuf[60]; + if (iswritable_stat(uentp, fri_stat)) { + char genbuf[60]; sprintf(genbuf, "Call-In %s :", uentp->userid); my_write(uentp->pid, genbuf, uentp->userid, 0, NULL); return 1; @@ -1755,62 +1749,64 @@ int call_in(userinfo_t *uentp, int fri_stat) return 0; } -static void userlist(void) +static void +userlist(void) { - /* 使用者名單: - userlist() : main loop - draw_pickup() : show out screen - pickup() : generate THIS PAGE pickup list - pickup_maxpages : return max pages number of all list - pickup_myfriend : pickup friend (from friend_online) and sort - */ + /* + * 使用者名單: userlist() : main loop draw_pickup() : show out + * screen pickup() : generate THIS PAGE pickup list + * pickup_maxpages : return max pages number of all list pickup_myfriend + * : pickup friend (from friend_online) and sort + */ pickup_t currpickup[MAXPICKUP]; - userinfo_t *uentp; - static int show_mode = 0; - static int show_uid = 0; - static int show_board = 0; - static int show_pid = 0; - static int real_name = 0; - char genbuf[256]; - int page, offset, pickup_way, ch, leave, redraw, redrawall, fri_stat; - int nfriend, myfriend, friendme, bfriend, i; - time_t lastupdate; + userinfo_t *uentp; + static int show_mode = 0; + static int show_uid = 0; + static int show_board = 0; + static int show_pid = 0; + static int real_name = 0; + char genbuf[256]; + int page, offset, pickup_way, ch, leave, redraw, redrawall, + fri_stat; + int nfriend, myfriend, friendme, bfriend, i; + time_t lastupdate; page = offset = 0; pickup_way = 0; leave = 0; redrawall = 1; - /* redraw : 會離開鍵盤處理 loop , 重新 pickup, draw_pickup - (只重畫中間使用者部份) - redrawall : 會重畫所有的部份 (上面的標題列, 下面的說明列等等) - leave : 返回上一選單 - */ - while( !leave ){ + /* + * redraw : 會離開鍵盤處理 loop , 重新 pickup, draw_pickup + * (只重畫中間使用者部份) redrawall : 會重畫所有的部份 (上面的標題列, + * 下面的說明列等等) leave : 返回上一選單 + */ + while (!leave) { pickup(currpickup, pickup_way, &page, &nfriend, &myfriend, &friendme, &bfriend); draw_pickup(redrawall, currpickup, pickup_way, page, show_mode, show_uid, show_board, show_pid, real_name, myfriend, friendme, bfriend); - /* 如果因為換頁的時候, 這一頁有的人數比較少, - (通常都是最後一頁人數不滿的時候) - 那要重新計算 offset 以免指到沒有人的地方 */ - if( offset == -1 || currpickup[offset].ui == NULL ){ - for( offset = (offset == -1 ? MAXPICKUP - 1 : offset ) ; - offset >= 0 ; --offset ) - if( currpickup[offset].ui != NULL ) + /* + * 如果因為換頁的時候, 這一頁有的人數比較少, + * (通常都是最後一頁人數不滿的時候) 那要重新計算 offset + * 以免指到沒有人的地方 + */ + if (offset == -1 || currpickup[offset].ui == NULL) { + for (offset = (offset == -1 ? MAXPICKUP - 1 : offset); + offset >= 0; --offset) + if (currpickup[offset].ui != NULL) break; - if( offset == -1 ){ - if( --page < 0 ) + if (offset == -1) { + if (--page < 0) page = pickup_maxpages(pickup_way, nfriend) - 1; offset = 0; continue; } } - redraw = redrawall = 0; lastupdate = now; - while( !redraw ){ + while (!redraw) { ch = cursor_key(offset + 3, 0); uentp = currpickup[offset].ui; fri_stat = currpickup[offset].friend; @@ -1818,7 +1814,7 @@ static void userlist(void) if (ch == KEY_RIGHT || ch == '\n' || ch == '\r') ch = 't'; - switch (ch){ + switch (ch) { case KEY_LEFT: case 'e': case 'E': @@ -1834,10 +1830,10 @@ static void userlist(void) case KEY_DOWN: case 'n': case 'j': - if( ++offset == MAXPICKUP || currpickup[offset].ui == NULL ){ + if (++offset == MAXPICKUP || currpickup[offset].ui == NULL) { redraw = 1; - if( ++page >= pickup_maxpages(pickup_way, - nfriend) ) + if (++page >= pickup_maxpages(pickup_way, + nfriend)) offset = page = 0; else offset = 0; @@ -1851,15 +1847,15 @@ static void userlist(void) break; case 'H': - if (HAS_PERM(PERM_SYSOP)){ + if (HAS_PERM(PERM_SYSOP)) { currutmp->userlevel ^= PERM_DENYPOST; redrawall = redraw = 1; } break; case 'D': - if (HAS_PERM(PERM_SYSOP)){ - char buf[100]; + if (HAS_PERM(PERM_SYSOP)) { + char buf[100]; sprintf(buf, "代號 [%s]:", currutmp->userid); if (!getdata(1, 0, buf, currutmp->userid, sizeof(buf), DOECHO)) @@ -1869,8 +1865,8 @@ static void userlist(void) break; case 'F': - if (HAS_PERM(PERM_SYSOP)){ - char buf[100]; + if (HAS_PERM(PERM_SYSOP)) { + char buf[100]; sprintf(buf, "故鄉 [%s]:", currutmp->from); if (!getdata(1, 0, buf, currutmp->from, @@ -1884,34 +1880,34 @@ static void userlist(void) #if !HAVE_FREECLOAK if (HAS_PERM(PERM_CLOAK)) #endif - { - currutmp->invisible ^= 1; - redrawall = redraw = 1; - } + { + currutmp->invisible ^= 1; + redrawall = redraw = 1; + } break; case ' ': case KEY_PGDN: case Ctrl('F'):{ - int newpage; - if( (newpage = page + 1) >= pickup_maxpages(pickup_way, - nfriend) ) - newpage = offset = 0; - if( newpage != page ){ - page = newpage; - redraw = 1; - } else if( now >= lastupdate + 2 ) - redrawall = redraw = 1; - } + int newpage; + if ((newpage = page + 1) >= pickup_maxpages(pickup_way, + nfriend)) + newpage = offset = 0; + if (newpage != page) { + page = newpage; + redraw = 1; + } else if (now >= lastupdate + 2) + redrawall = redraw = 1; + } break; case KEY_UP: case 'k': - if( --offset == -1 ){ + if (--offset == -1) { offset = MAXPICKUP - 1; - if( --page == -1 ) + if (--page == -1) page = pickup_maxpages(pickup_way, nfriend) - - 1; + - 1; redraw = 1; } break; @@ -1919,7 +1915,7 @@ static void userlist(void) case KEY_PGUP: case Ctrl('B'): case 'P': - if( --page == -1 ) + if (--page == -1) page = pickup_maxpages(pickup_way, nfriend) - 1; offset = 0; redraw = 1; @@ -1934,49 +1930,46 @@ static void userlist(void) case '/': /* - getdata_buf(b_lines-1,0,"請輸入暱稱關鍵字:", - keyword, sizeof(keyword), DOECHO); - state = US_PICKUP; - */ - break; + * getdata_buf(b_lines-1,0,"請輸入暱稱關鍵字:", keyword, + * sizeof(keyword), DOECHO); state = US_PICKUP; + */ + break; case 's': - if( !(cuser.uflag & FRIEND_FLAG) ){ - int si; /* utmpshm->sorted[X][0][si] */ - int fi; /* allpickuplist[fi] */ - char swid[IDLEN + 1]; + if (!(cuser.uflag & FRIEND_FLAG)) { + int si; /* utmpshm->sorted[X][0][si] */ + int fi; /* allpickuplist[fi] */ + char swid[IDLEN + 1]; move(1, 0); si = generalnamecomplete(msg_uid, swid, sizeof(swid), SHM->UTMPnumber, completeutmp_compar, completeutmp_permission, completeutmp_getname); - if( si >= 0 ){ + if (si >= 0) { pickup_t friends[MAX_FRIEND + 1]; - int nGots, i; + int nGots, i; fi = SHM->sorted[SHM->currsorted][0][si] - - &SHM->uinfo[0]; + &SHM->uinfo[0]; - nGots= pickup_myfriend(friends, &myfriend, &friendme); - for( i = 0 ; i < nGots ; ++i ) - if( friends[i].uoffset == fi ) + nGots = pickup_myfriend(friends, &myfriend, &friendme); + for (i = 0; i < nGots; ++i) + if (friends[i].uoffset == fi) break; - if( i != nGots ){ + if (i != nGots) { page = i / 20; offset = i % 20; - } - else{ + } else { page = (si + nGots) / 20; offset = (si + nGots) % 20; - } + } } redrawall = redraw = 1; } /* - if ((i = search_pickup(num, actor, pklist)) >= 0) - num = i; - state = US_ACTION; - */ + * if ((i = search_pickup(num, actor, pklist)) >= 0) num = i; + * state = US_ACTION; + */ break; case '1': @@ -1989,14 +1982,15 @@ static void userlist(void) case '8': case '9': { /* Thor: 可以打數字跳到該人 */ - int tmp; - if( (tmp = search_num(ch, SHM->UTMPnumber)) >= 0 ){ - if( tmp / 20 == page ){ - /* in2:目的在目前這一頁, 直接 - 更新 offset , 不用重畫畫面 */ + int tmp; + if ((tmp = search_num(ch, SHM->UTMPnumber)) >= 0) { + if (tmp / 20 == page) { + /* + * in2:目的在目前這一頁, 直接 更新 offset , + * 不用重畫畫面 + */ offset = tmp % 20; - } - else{ + } else { page = tmp / 20; offset = tmp % 20; } @@ -2004,10 +1998,10 @@ static void userlist(void) } } break; - + #ifdef REALINFO case 'R': /* 顯示真實姓名 */ - if (HAS_PERM(PERM_SYSOP)){ + if (HAS_PERM(PERM_SYSOP)) { real_name ^= 1; redrawall = redraw = 1; } @@ -2015,7 +2009,7 @@ static void userlist(void) #endif #ifdef SHOWUID case 'U': - if (HAS_PERM(PERM_SYSOP)){ + if (HAS_PERM(PERM_SYSOP)) { show_uid ^= 1; redrawall = redraw = 1; } @@ -2023,7 +2017,7 @@ static void userlist(void) #endif #ifdef SHOWBOARD case 'Y': - if (HAS_PERM(PERM_SYSOP)){ + if (HAS_PERM(PERM_SYSOP)) { show_board ^= 1; redrawall = redraw = 1; } @@ -2031,7 +2025,7 @@ static void userlist(void) #endif #ifdef SHOWPID case '#': - if (HAS_PERM(PERM_SYSOP)){ + if (HAS_PERM(PERM_SYSOP)) { show_pid ^= 1; redrawall = redraw = 1; } @@ -2039,41 +2033,40 @@ static void userlist(void) #endif case 'b': /* broadcast */ - if (cuser.uflag & FRIEND_FLAG || HAS_PERM(PERM_SYSOP)){ - char ans[4]; - + if (cuser.uflag & FRIEND_FLAG || HAS_PERM(PERM_SYSOP)) { + char ans[4]; + if (!getdata(0, 0, "廣播訊息:", genbuf, 60, DOECHO)) break; if (getdata(0, 0, "確定廣播? [Y]", ans, sizeof(ans), LCECHO) && *ans == 'n') break; - if( !(cuser.uflag & FRIEND_FLAG) && HAS_PERM(PERM_SYSOP) ){ - for( i = 0 ; i < SHM->UTMPnumber ; ++i ){ + if (!(cuser.uflag & FRIEND_FLAG) && HAS_PERM(PERM_SYSOP)) { + for (i = 0; i < SHM->UTMPnumber; ++i) { uentp = SHM->sorted[SHM->currsorted][0][i]; - if( uentp->pid && kill(uentp->pid, 0) != -1 ) + if (uentp->pid && kill(uentp->pid, 0) != -1) my_write(uentp->pid, genbuf, - uentp->userid, 1, NULL); - if( i % 100 == 0 ) + uentp->userid, 1, NULL); + if (i % 100 == 0) sleep(1); } - } - else{ - userinfo_t *uentp; - int where, frstate; - for( i = 0 ; currutmp->friend_online[i] && - i < MAX_FRIEND ; ++i ){ + } else { + userinfo_t *uentp; + int where, frstate; + for (i = 0; currutmp->friend_online[i] && + i < MAX_FRIEND; ++i) { where = currutmp->friend_online[i] & 0xFFFFFF; - if( 0 <= where && where < MAX_ACTIVE && - (uentp = &SHM->uinfo[where]) && + if (0 <= where && where < MAX_ACTIVE && + (uentp = &SHM->uinfo[where]) && uentp->pid && isvisible_stat(currutmp, uentp, frstate = - currutmp->friend_online[i]>>24) + currutmp->friend_online[i] >> 24) && kill(uentp->pid, 0) != -1 && uentp->pager != 3 && (uentp->pager != 4 || frstate & HFM) && - !(frstate & IRH) ){ + !(frstate & IRH)) { my_write(uentp->pid, genbuf, uentp->userid, 1, NULL); } @@ -2088,16 +2081,16 @@ static void userlist(void) redrawall = redraw = 1; break; - case 'u': /* 線上修改資料 */ - if( HAS_PERM(PERM_ACCOUNTS) ){ - int id; - userec_t muser; + case 'u': /* 線上修改資料 */ + if (HAS_PERM(PERM_ACCOUNTS)) { + int id; + userec_t muser; strcpy(currauthor, uentp->userid); stand_title("使用者設定"); move(1, 0); - if( (id = getuser(uentp->userid)) > 0 ){ + if ((id = getuser(uentp->userid)) > 0) { memcpy(&muser, &xuser, sizeof(muser)); - user_display(&muser, 1); + user_display(&muser, 1); uinfo_query(&muser, 1, id); } redrawall = redraw = 1; @@ -2105,26 +2098,26 @@ static void userlist(void) break; case 'i':{ - char mindbuf[5]; - getdata(b_lines - 1, 0, "現在的心情? ", - mindbuf, sizeof(mindbuf), LCECHO); - if( strcmp(mindbuf, "通緝") == 0 ) - vmsg("不可以把自己設通緝啦!"); - else if( strcmp(mindbuf, "壽星") == 0 ) - vmsg("你不是今天生日欸!"); - else - memcpy(currutmp->mind, mindbuf, 4); - } + char mindbuf[5]; + getdata(b_lines - 1, 0, "現在的心情? ", + mindbuf, sizeof(mindbuf), LCECHO); + if (strcmp(mindbuf, "通緝") == 0) + vmsg("不可以把自己設通緝啦!"); + else if (strcmp(mindbuf, "壽星") == 0) + vmsg("你不是今天生日欸!"); + else + memcpy(currutmp->mind, mindbuf, 4); + } redrawall = redraw = 1; break; - + case Ctrl('S'): break; case 't': - if( HAS_PERM(PERM_LOGINOK) ){ - if( uentp->pid != currpid && - strcmp(uentp->userid, cuser.userid) != 0 ){ + if (HAS_PERM(PERM_LOGINOK)) { + if (uentp->pid != currpid && + strcmp(uentp->userid, cuser.userid) != 0) { move(1, 0); clrtobot(); move(3, 0); @@ -2133,19 +2126,18 @@ static void userlist(void) } } break; - case 'K': - if(HAS_PERM(PERM_ACCOUNTS)) - { - my_kick(uentp); - redrawall = redraw = 1; - } - break; + case 'K': + if (HAS_PERM(PERM_ACCOUNTS)) { + my_kick(uentp); + redrawall = redraw = 1; + } + break; case 'w': - if(call_in(uentp,fri_stat)) - redrawall = redraw = 1; + if (call_in(uentp, fri_stat)) + redrawall = redraw = 1; break; case 'a': - if( HAS_PERM(PERM_LOGINOK) ){ + if (HAS_PERM(PERM_LOGINOK)) { friend_add(uentp->userid, FRIEND_OVERRIDE); friend_load(); redrawall = redraw = 1; @@ -2153,7 +2145,7 @@ static void userlist(void) break; case 'd': - if( HAS_PERM(PERM_LOGINOK) ){ + if (HAS_PERM(PERM_LOGINOK)) { friend_delete(uentp->userid, FRIEND_OVERRIDE); friend_load(); redrawall = redraw = 1; @@ -2161,51 +2153,50 @@ static void userlist(void) break; case 'o': - if( HAS_PERM(PERM_LOGINOK) ){ + if (HAS_PERM(PERM_LOGINOK)) { t_override(); redrawall = redraw = 1; } break; case 'f': - if( HAS_PERM(PERM_LOGINOK) ){ + if (HAS_PERM(PERM_LOGINOK)) { cuser.uflag ^= FRIEND_FLAG; redrawall = redraw = 1; } break; - + case 'g': - if( HAS_PERM(PERM_LOGINOK) && - strcmp(uentp->userid, cuser.userid) != 0 ){ + if (HAS_PERM(PERM_LOGINOK) && + strcmp(uentp->userid, cuser.userid) != 0) { move(b_lines - 2, 0); sprintf(genbuf, "要給 %s 多少錢呢? ", uentp->userid); - outs(genbuf); - if( getdata(b_lines - 1, 0, "[銀行轉帳]: ", - genbuf, 7, LCECHO) ){ - clrtoeol(); - if( (ch == atoi(genbuf)) <= 0 || ch <= give_tax(ch) ) - break; + outs(genbuf); + if (getdata(b_lines - 1, 0, "[銀行轉帳]: ", + genbuf, 7, LCECHO)) { + clrtoeol(); + if ((ch == atoi(genbuf)) <= 0 || ch <= give_tax(ch)) + break; reload_money(); - - if( ch > cuser.money ) - outs("\033[41m 現金不足~~\033[m"); - else{ - deumoney(uentp->uid, ch - give_tax(ch)); - sprintf(genbuf, "\033[44m 嗯..還剩下 %d 錢.." - "\033[m", demoney(-ch)); - outs(genbuf); - sprintf(genbuf, "%s\t給%s\t%d\t%s", cuser.userid, - uentp->userid, ch, - ctime(&currutmp->lastact)); - log_file(FN_MONEY, genbuf); - mail_redenvelop(cuser.userid, uentp->userid, + + if (ch > cuser.money) + outs("\033[41m 現金不足~~\033[m"); + else { + deumoney(uentp->uid, ch - give_tax(ch)); + sprintf(genbuf, "\033[44m 嗯..還剩下 %d 錢.." + "\033[m", demoney(-ch)); + outs(genbuf); + sprintf(genbuf, "%s\t給%s\t%d\t%s", cuser.userid, + uentp->userid, ch, + ctime(&currutmp->lastact)); + log_file(FN_MONEY, genbuf); + mail_redenvelop(cuser.userid, uentp->userid, ch - give_tax(ch), 'Y'); - } - } - else{ - clrtoeol(); - outs("\033[41m 交易取消! \033[m"); - } + } + } else { + clrtoeol(); + outs("\033[41m 交易取消! \033[m"); + } redrawall = redraw = 1; } break; @@ -2218,21 +2209,21 @@ static void userlist(void) break; case 'q': - strcpy(currauthor, uentp->userid); - my_query(uentp->userid); + strcpy(currauthor, uentp->userid); + my_query(uentp->userid); setutmpmode(LUSERS); redrawall = redraw = 1; break; case 'c': - if( HAS_PERM(PERM_LOGINOK) ){ + if (HAS_PERM(PERM_LOGINOK)) { chicken_query(uentp->userid); redrawall = redraw = 1; } break; case 'l': - if( HAS_PERM(PERM_LOGINOK) ){ + if (HAS_PERM(PERM_LOGINOK)) { t_display(); redrawall = redraw = 1; } @@ -2244,50 +2235,51 @@ static void userlist(void) break; case 'p': - if( HAS_PERM(PERM_BASIC) ){ + if (HAS_PERM(PERM_BASIC)) { t_pager(); redrawall = redraw = 1; } break; case 'W': - if( HAS_PERM(PERM_LOGINOK) ){ - int tmp; - char *wm[3] = {"一般", "進階", "未來"}; - tmp = cuser.uflag2 & WATER_MASK; - cuser.uflag2 -= tmp; - tmp = (tmp + 1) % 3; - cuser.uflag2 |= tmp; + if (HAS_PERM(PERM_LOGINOK)) { + int tmp; + char *wm[3] = {"一般", "進階", "未來"}; + tmp = cuser.uflag2 & WATER_MASK; + cuser.uflag2 -= tmp; + tmp = (tmp + 1) % 3; + cuser.uflag2 |= tmp; move(4, 0); prints("系統提供 一般 進階 未來 三種模式\n" "在切換後請正常下線再重新登入, 以確保結構正確\n" "目前切換到 %s 水球模式\n", wm[tmp]); - refresh(); - sleep(2); + refresh(); + sleep(2); redrawall = redraw = 1; } break; case 'r': - if( HAS_PERM(PERM_LOGINOK) ){ + if (HAS_PERM(PERM_LOGINOK)) { m_read(); redrawall = redraw = 1; } break; default: - if( now >= lastupdate + 2 ) + if (now >= lastupdate + 2) redraw = 1; } } } } -int t_users(void) +int +t_users(void) { - int destuid0 = currutmp->destuid; - int mode0 = currutmp->mode; - int stat0 = currstat; + int destuid0 = currutmp->destuid; + int mode0 = currutmp->mode; + int stat0 = currstat; setutmpmode(LUSERS); userlist(); @@ -2297,29 +2289,30 @@ int t_users(void) return 0; } -int t_pager(void) +int +t_pager(void) { currutmp->pager = (currutmp->pager + 1) % 5; return 0; } -int t_idle(void) +int +t_idle(void) { - int destuid0 = currutmp->destuid; - int mode0 = currutmp->mode; - int stat0 = currstat; - char genbuf[20]; - char buf[80], passbuf[PASSLEN]; + int destuid0 = currutmp->destuid; + int mode0 = currutmp->mode; + int stat0 = currstat; + char genbuf[20]; + char buf[80], passbuf[PASSLEN]; setutmpmode(IDLE); getdata(b_lines - 1, 0, "理由:[0]發呆 (1)接電話 (2)覓食 (3)打瞌睡 " "(4)裝死 (5)羅丹 (6)其他 (Q)沒事?", genbuf, 3, DOECHO); - if (genbuf[0] == 'q' || genbuf[0] == 'Q'){ + if (genbuf[0] == 'q' || genbuf[0] == 'Q') { currutmp->mode = mode0; currstat = stat0; return 0; - } - else if (genbuf[0] >= '1' && genbuf[0] <= '6') + } else if (genbuf[0] >= '1' && genbuf[0] <= '6') currutmp->destuid = genbuf[0] - '0'; else currutmp->destuid = 0; @@ -2329,7 +2322,7 @@ int t_idle(void) !getdata(b_lines - 1, 0, "發呆的理由:", currutmp->chatid, sizeof(currutmp->chatid), DOECHO)) currutmp->destuid = 0; - do{ + do { move(b_lines - 2, 0); clrtoeol(); sprintf(buf, "(鎖定螢幕)發呆原因: %s", (currutmp->destuid != 6) ? @@ -2349,9 +2342,10 @@ int t_idle(void) return 0; } -int t_qchicken(void) +int +t_qchicken(void) { - char uident[STRLEN]; + char uident[STRLEN]; stand_title("查詢寵物"); usercomplete(msg_uid, uident); @@ -2360,9 +2354,10 @@ int t_qchicken(void) return 0; } -int t_query(void) +int +t_query(void) { - char uident[STRLEN]; + char uident[STRLEN]; stand_title("查詢網友"); usercomplete(msg_uid, uident); @@ -2371,17 +2366,17 @@ int t_query(void) return 0; } -int t_talk() { - char uident[16]; - int tuid, unum, ucount; - userinfo_t *uentp; - char genbuf[4]; -/* - if (count_ulist() <= 1){ - outs("目前線上只有您一人,快邀請朋友來光臨【" BBSNAME "】吧!"); - return XEASY; - } -*/ +int +t_talk() +{ + char uident[16]; + int tuid, unum, ucount; + userinfo_t *uentp; + char genbuf[4]; + /* + * if (count_ulist() <= 1){ outs("目前線上只有您一人,快邀請朋友來光臨【" + * BBSNAME "】吧!"); return XEASY; } + */ stand_title("打開話匣子"); generalnamecomplete(msg_uid, uident, sizeof(uident), SHM->UTMPnumber, @@ -2392,15 +2387,14 @@ int t_talk() { return 0; move(3, 0); - if (!(tuid = searchuser(uident)) || tuid == usernum){ + if (!(tuid = searchuser(uident)) || tuid == usernum) { outs(err_uid); pressanykey(); return 0; } - -/* multi-login check */ + /* multi-login check */ unum = 1; - while ((ucount = count_logins(tuid, 0)) > 1){ + while ((ucount = count_logins(tuid, 0)) > 1) { outs("(0) 不想 talk 了...\n"); count_logins(tuid, 1); getdata(1, 33, "請選擇一個聊天對象 [0]:", genbuf, 4, DOECHO); @@ -2421,13 +2415,14 @@ int t_talk() { /* 有人來串門子了,回應呼叫器 */ static userinfo_t *uip; -void talkreply(void) +void +talkreply(void) { struct hostent *h; - char buf[4]; + char buf[4]; struct sockaddr_in sin; - char genbuf[200]; - int a, sig = currutmp->sig; + char genbuf[200]; + int a, sig = currutmp->sig; talkrequest = NA; uip = &SHM->uinfo[currutmp->destuip]; @@ -2463,7 +2458,7 @@ void talkreply(void) page_requestor, sig_des[sig]); getdata(0, 0, genbuf, buf, sizeof(buf), LCECHO); - if (uip->mode != PAGE){ + if (uip->mode != PAGE) { sprintf(genbuf, "%s已停止呼叫,按Enter繼續...", page_requestor); getdata(0, 0, genbuf, buf, sizeof(buf), LCECHO); return; @@ -2471,7 +2466,7 @@ void talkreply(void) currutmp->msgcount = 0; strcpy(save_page_requestor, page_requestor); memset(page_requestor, 0, sizeof(page_requestor)); - if (!(h = gethostbyname("localhost"))){ + if (!(h = gethostbyname("localhost"))) { perror("gethostbyname"); return; } @@ -2480,21 +2475,21 @@ void talkreply(void) memcpy(&sin.sin_addr, h->h_addr, h->h_length); sin.sin_port = uip->sockaddr; a = socket(sin.sin_family, SOCK_STREAM, 0); - if ((connect(a, (struct sockaddr *) &sin, sizeof(sin)))){ + if ((connect(a, (struct sockaddr *) & sin, sizeof(sin)))) { perror("connect err"); return; } if (!buf[0] || !strchr("yabcdef12", buf[0])) buf[0] = 'n'; write(a, buf, 1); - if (buf[0] == 'f' || buf[0] == 'F'){ + if (buf[0] == 'f' || buf[0] == 'F') { if (!getdata(b_lines, 0, "不能的原因:", genbuf, 60, DOECHO)) strcpy(genbuf, "不告訴你咧 !! ^o^"); write(a, genbuf, 60); } uip->destuip = currutmp - &SHM->uinfo[0]; if (buf[0] == 'y') - switch (sig){ + switch (sig) { case SIG_DARK: main_dark(a, uip); break; @@ -2517,75 +2512,33 @@ void talkreply(void) } /* 網友動態簡表 */ -/* not used -static int shortulist(userinfo_t * uentp) -{ - static int lineno, fullactive, linecnt; - static int moreactive, page, num; - char uentry[50]; - int state; - - if (!lineno){ - lineno = 3; - page = moreactive ? (page + p_lines * 3) : 0; - linecnt = num = moreactive = 0; - move(1, 70); - prints("Page: %d", page / (p_lines) / 3 + 1); - move(lineno, 0); - } - - if (uentp == NULL){ - int finaltally; - - clrtoeol(); - move(++lineno, 0); - clrtobot(); - finaltally = fullactive; - lineno = fullactive = 0; - return finaltally; - } - - if ((!HAS_PERM(PERM_SYSOP) && - !HAS_PERM(PERM_SEECLOAK) && - uentp->invisible) || - ((friend_stat(currutmp, uentp) & HRM) && - !HAS_PERM(PERM_SYSOP))){ - if (lineno >= b_lines) - return 0; - if (num++ < page) - return 0; - memset(uentry, ' ', 25); - uentry[25] = '\0'; - } - else{ - fullactive++; - if (lineno >= b_lines){ - moreactive = 1; - return 0; - } - if (num++ < page) - return 0; - - state = (currutmp == uentp) ? 10 : - (friend_stat(currutmp,uentp)&ST_FRIEND)>>2; - - if (PERM_HIDE(uentp)) - state = 9; - - sprintf(uentry, "%s%-13s%c%-10s%s ", fcolor[state], - uentp->userid, uentp->invisible ? '#' : ' ', - modestring(uentp, 1), state ? "\033[0m" : ""); - } - if (++linecnt < 3){ - strcat(uentry, "│"); - outs(uentry); - } - else{ - outs(uentry); - linecnt = 0; - clrtoeol(); - move(++lineno, 0); - } - return 0; -} -*/ +/* + * not used static int shortulist(userinfo_t * uentp) { static int lineno, + * fullactive, linecnt; static int moreactive, page, num; char uentry[50]; + * int state; + * + * if (!lineno){ lineno = 3; page = moreactive ? (page + p_lines * 3) : 0; + * linecnt = num = moreactive = 0; move(1, 70); prints("Page: %d", page / + * (p_lines) / 3 + 1); move(lineno, 0); } + * + * if (uentp == NULL){ int finaltally; + * + * clrtoeol(); move(++lineno, 0); clrtobot(); finaltally = fullactive; lineno = + * fullactive = 0; return finaltally; } + * + * if ((!HAS_PERM(PERM_SYSOP) && !HAS_PERM(PERM_SEECLOAK) && uentp->invisible) + * || ((friend_stat(currutmp, uentp) & HRM) && !HAS_PERM(PERM_SYSOP))){ if + * (lineno >= b_lines) return 0; if (num++ < page) return 0; memset(uentry, ' + * ', 25); uentry[25] = '\0'; } else{ fullactive++; if (lineno >= b_lines){ + * moreactive = 1; return 0; } if (num++ < page) return 0; + * + * state = (currutmp == uentp) ? 10 : + * (friend_stat(currutmp,uentp)&ST_FRIEND)>>2; + * + * if (PERM_HIDE(uentp)) state = 9; + * + * sprintf(uentry, "%s%-13s%c%-10s%s ", fcolor[state], uentp->userid, + * uentp->invisible ? '#' : ' ', modestring(uentp, 1), state ? "\033[0m" : + * ""); } if (++linecnt < 3){ strcat(uentry, "│"); outs(uentry); } else{ + * outs(uentry); linecnt = 0; clrtoeol(); move(++lineno, 0); } return 0; } + */ diff --git a/pttbbs/mbbsd/term.c b/pttbbs/mbbsd/term.c index 4cab3e2c..aa310212 100644 --- a/pttbbs/mbbsd/term.c +++ b/pttbbs/mbbsd/term.c @@ -1,28 +1,31 @@ -/* $Id: term.c,v 1.3 2002/06/04 13:08:34 in2 Exp $ */ +/* $Id: term.c,v 1.4 2002/07/05 17:10:28 in2 Exp $ */ #include "bbs.h" -int tgetent(const char *bp, char *name); -char *tgetstr(const char *id, char **area); -int tgetflag(const char *id); -int tgetnum(const char *id); -int tputs(const char *str, int affcnt, int (*putc)(int)); -char *tparm(const char *str, ...); -char *tgoto(const char *cap, int col, int row); +int tgetent(const char *bp, char *name); +char *tgetstr(const char *id, char **area); +int tgetflag(const char *id); +int tgetnum(const char *id); +int tputs(const char *str, int affcnt, int (*putc) (int)); +char *tparm(const char *str,...); +char *tgoto(const char *cap, int col, int row); static struct termios tty_state, tty_new; /* ----------------------------------------------------- */ /* basic tty control */ /* ----------------------------------------------------- */ -void init_tty() { - if(tcgetattr(1, &tty_state) < 0) { +void +init_tty() +{ + if (tcgetattr(1, &tty_state) < 0) { syslog(LOG_ERR, "tcgetattr(): %m"); return; } memcpy(&tty_new, &tty_state, sizeof(tty_new)); tty_new.c_lflag &= ~(ICANON | ECHO | ISIG); -/* tty_new.c_cc[VTIME] = 0; - tty_new.c_cc[VMIN] = 1; */ + /* + * tty_new.c_cc[VTIME] = 0; tty_new.c_cc[VMIN] = 1; + */ tcsetattr(1, TCSANOW, &tty_new); system("stty raw -echo"); } @@ -35,11 +38,13 @@ void init_tty() { #define TERMCOMSIZE (40) #if 0 -static char *outp; -static int *outlp; +static char *outp; +static int *outlp; -static int outcf(int ch) { - if(*outlp < TERMCOMSIZE) { +static int +outcf(int ch) +{ + if (*outlp < TERMCOMSIZE) { (*outlp)++; *outp++ = ch; } @@ -47,64 +52,77 @@ static int outcf(int ch) { } #endif -static void term_resize(int sig) { - struct winsize newsize; - screenline_t *new_picture; +static void +term_resize(int sig) +{ + struct winsize newsize; + screenline_t *new_picture; signal(SIGWINCH, SIG_IGN); /* Don't bother me! */ ioctl(0, TIOCGWINSZ, &newsize); - if(newsize.ws_row > t_lines) { - new_picture = (screenline_t *)calloc(newsize.ws_row, - sizeof(screenline_t)); - if(new_picture == NULL) { + if (newsize.ws_row > t_lines) { + new_picture = (screenline_t *) calloc(newsize.ws_row, + sizeof(screenline_t)); + if (new_picture == NULL) { syslog(LOG_ERR, "calloc(): %m"); return; } free(big_picture); big_picture = new_picture; } - - t_lines=newsize.ws_row; - b_lines=t_lines-1; - p_lines=t_lines-4; + t_lines = newsize.ws_row; + b_lines = t_lines - 1; + p_lines = t_lines - 4; signal(SIGWINCH, term_resize); } -int term_init() { +int +term_init() +{ signal(SIGWINCH, term_resize); return YEA; } -char term_buf[32]; +char term_buf[32]; + +void +do_move(int destcol, int destline) +{ + char buf[16], *p; -void do_move(int destcol, int destline) { - char buf[16], *p; - sprintf(buf, "\33[%d;%dH", destline + 1, destcol + 1); - for(p = buf; *p; p++) + for (p = buf; *p; p++) ochar(*p); } -void save_cursor() { +void +save_cursor() +{ ochar('\33'); ochar('7'); } -void restore_cursor() { +void +restore_cursor() +{ ochar('\33'); ochar('8'); } -void change_scroll_range(int top, int bottom) { - char buf[16], *p; - +void +change_scroll_range(int top, int bottom) +{ + char buf[16], *p; + sprintf(buf, "\33[%d;%dr", top + 1, bottom + 1); - for(p = buf; *p; p++) + for (p = buf; *p; p++) ochar(*p); } -void scroll_forward() { +void +scroll_forward() +{ ochar('\33'); ochar('D'); } diff --git a/pttbbs/mbbsd/toolkit.c b/pttbbs/mbbsd/toolkit.c index 2955f040..9623c578 100644 --- a/pttbbs/mbbsd/toolkit.c +++ b/pttbbs/mbbsd/toolkit.c @@ -1,9 +1,11 @@ -/* $Id: toolkit.c,v 1.2 2002/06/04 13:08:34 in2 Exp $ */ +/* $Id: toolkit.c,v 1.3 2002/07/05 17:10:28 in2 Exp $ */ #include "bbs.h" -unsigned StringHash(unsigned char *s) { - unsigned int v=0; - while(*s) { +unsigned +StringHash(unsigned char *s) +{ + unsigned int v = 0; + while (*s) { v = (v << 8) | (v >> 24); v ^= toupper(*s++); /* note this is case insensitive */ } diff --git a/pttbbs/mbbsd/topsong.c b/pttbbs/mbbsd/topsong.c index 169feb8d..9d5fd475 100644 --- a/pttbbs/mbbsd/topsong.c +++ b/pttbbs/mbbsd/topsong.c @@ -1,71 +1,79 @@ -/* $Id: topsong.c,v 1.2 2002/06/04 13:08:34 in2 Exp $ */ +/* $Id: topsong.c,v 1.3 2002/07/05 17:10:28 in2 Exp $ */ #include "bbs.h" #define MAX_SONGS 300 #define QCAST int (*)(const void *, const void *) typedef struct songcmp_t { - char name[100]; - char cname[100]; - long int count; -} songcmp_t; + char name[100]; + char cname[100]; + long int count; +} songcmp_t; -static long int totalcount=0; +static long int totalcount = 0; -static int count_cmp(songcmp_t *b, songcmp_t *a) { +static int +count_cmp(songcmp_t * b, songcmp_t * a) +{ return (a->count - b->count); } -int topsong() { - more(FN_TOPSONG,YEA); +int +topsong() +{ + more(FN_TOPSONG, YEA); return 0; } - -static int strip_blank(char *cbuf, char *buf) { - for(; *buf; buf++) - if(*buf != ' ') - *cbuf++ = *buf; + +static int +strip_blank(char *cbuf, char *buf) +{ + for (; *buf; buf++) + if (*buf != ' ') + *cbuf++ = *buf; *cbuf = 0; return 0; } -void sortsong() { - FILE *fo, *fp = fopen(BBSHOME "/" FN_USSONG, "r"); - songcmp_t songs[MAX_SONGS + 1]; - int n; - char buf[256], cbuf[256]; +void +sortsong() +{ + FILE *fo, *fp = fopen(BBSHOME "/" FN_USSONG, "r"); + songcmp_t songs[MAX_SONGS + 1]; + int n; + char buf[256], cbuf[256]; - memset(songs , 0, sizeof(songs)); - if(!fp) return; - if(!(fo = fopen(FN_TOPSONG,"w"))) { + memset(songs, 0, sizeof(songs)); + if (!fp) + return; + if (!(fo = fopen(FN_TOPSONG, "w"))) { fclose(fp); return; } - totalcount = 0; - while(fgets(buf, 200, fp)) { + while (fgets(buf, 200, fp)) { strtok(buf, "\n\r"); strip_blank(cbuf, buf); - if(!cbuf[0] || !isprint2(cbuf[0])) + if (!cbuf[0] || !isprint2(cbuf[0])) continue; - - for(n = 0; n < MAX_SONGS && songs[n].name[0]; n++) - if(!strcmp(songs[n].cname,cbuf)) + + for (n = 0; n < MAX_SONGS && songs[n].name[0]; n++) + if (!strcmp(songs[n].cname, cbuf)) break; strcpy(songs[n].name, buf); strcpy(songs[n].cname, cbuf); songs[n].count++; totalcount++; } - qsort(songs, MAX_SONGS, sizeof(songcmp_t), (QCAST)count_cmp); + qsort(songs, MAX_SONGS, sizeof(songcmp_t), (QCAST) count_cmp); fprintf(fo, " \033[36m──\033[37m名次\033[36m──────\033[37m歌" " 名\033[36m───────────\033[37m次數\033[36m" "──\033[32m共%ld次\033[36m──\033[m\n", totalcount); - for(n = 0; n < 100 && songs[n].name[0]; n++) { - fprintf(fo, " %5d. %-38.38s %4ld \033[32m[%.2f]\033[m\n", n + 1, + for (n = 0; n < 100 && songs[n].name[0]; n++) { + fprintf(fo, " %5d. %-38.38s %4ld \033[32m[%.2f]\033[m\n", n + 1, songs[n].name, songs[n].count, - (float)songs[n].count/totalcount); + (float)songs[n].count / totalcount); } fclose(fp); fclose(fo); diff --git a/pttbbs/mbbsd/user.c b/pttbbs/mbbsd/user.c index a0895c3e..f5615a88 100644 --- a/pttbbs/mbbsd/user.c +++ b/pttbbs/mbbsd/user.c @@ -1,46 +1,50 @@ -/* $Id: user.c,v 1.27 2002/07/02 14:56:22 in2 Exp $ */ +/* $Id: user.c,v 1.28 2002/07/05 17:10:28 in2 Exp $ */ #include "bbs.h" -static char *sex[8] = { +static char *sex[8] = { MSG_BIG_BOY, MSG_BIG_GIRL, MSG_LITTLE_BOY, MSG_LITTLE_GIRL, MSG_MAN, MSG_WOMAN, MSG_PLANT, MSG_MIME }; -int u_loginview() { - int i; - unsigned int pbits = cuser.loginview; - char choice[5]; - +int +u_loginview() +{ + int i; + unsigned int pbits = cuser.loginview; + char choice[5]; + clear(); - move(4,0); - for(i = 0; i < NUMVIEWFILE ; i++) + move(4, 0); + for (i = 0; i < NUMVIEWFILE; i++) prints(" %c. %-20s %-15s \n", 'A' + i, - loginview_file[i][1],((pbits >> i) & 1 ? "ˇ" : "X")); - + loginview_file[i][1], ((pbits >> i) & 1 ? "ˇ" : "X")); + clrtobot(); - while(getdata(b_lines - 1, 0, "請按 [A-N] 切換設定,按 [Return] 結束:", - choice, sizeof(choice), LCECHO)) { + while (getdata(b_lines - 1, 0, "請按 [A-N] 切換設定,按 [Return] 結束:", + choice, sizeof(choice), LCECHO)) { i = choice[0] - 'a'; - if(i >= NUMVIEWFILE || i < 0) + if (i >= NUMVIEWFILE || i < 0) bell(); else { pbits ^= (1 << i); - move( i + 4 , 28 ); + move(i + 4, 28); prints((pbits >> i) & 1 ? "ˇ" : "X"); } } - - if(pbits != cuser.loginview) { - cuser.loginview = pbits ; + + if (pbits != cuser.loginview) { + cuser.loginview = pbits; passwd_update(usernum, &cuser); } return 0; } -void user_display(userec_t *u, int real) { - int diff = 0; - char genbuf[200]; - +void +user_display(userec_t * u, int real) +{ + int diff = 0; + char genbuf[200]; + clrtobot(); prints( " \033[30;41m┴┬┴┬┴┬\033[m \033[1;30;45m 使 用 者" @@ -54,7 +58,7 @@ void user_display(userec_t *u, int real) { " 銀行帳戶: %ld 銀兩\n", u->userid, u->username, u->realname, u->address, u->email, sex[u->sex % 8], u->money); - + sethomedir(genbuf, u->userid); prints(" 私人信箱: %d 封 (購買信箱: %d 封)\n" " 身分證號: %s\n" @@ -70,10 +74,10 @@ void user_display(userec_t *u, int real) { prints(" 上站文章: %d 次 / %d 篇\n", u->numlogins, u->numposts); - if(real) { + if (real) { strcpy(genbuf, "bTCPRp#@XWBA#VSM0123456789ABCDEF"); - for(diff = 0; diff < 32; diff++) - if(!(u->userlevel & (1 << diff))) + for (diff = 0; diff < 32; diff++) + if (!(u->userlevel & (1 << diff))) genbuf[diff] = '-'; prints(" 認證資料: %s\n" " user權限: %s\n", @@ -83,16 +87,16 @@ void user_display(userec_t *u, int real) { prints(" 停留期間: %d 小時 %2d 分\n", diff / 60, diff % 60); } - + /* Thor: 想看看這個 user 是那些板的板主 */ - if(u->userlevel >= PERM_BM) { - int i; - boardheader_t *bhdr; - + if (u->userlevel >= PERM_BM) { + int i; + boardheader_t *bhdr; + outs(" 擔任板主: "); - - for(i = 0, bhdr = bcache; i < numboards; i++, bhdr++) { - if(is_uBM(bhdr->BM,u->userid)) { + + for (i = 0, bhdr = bcache; i < numboards; i++, bhdr++) { + if (is_uBM(bhdr->BM, u->userid)) { outs(bhdr->brdname); outc(' '); } @@ -101,31 +105,33 @@ void user_display(userec_t *u, int real) { } outs(" \033[30;41m┴┬┴┬┴┬┴┬┴┬┴┬┴┬┴┬┴┬┴┬┴┬┴" "┬┴┬┴┬┴┬\033[m"); - + outs((u->userlevel & PERM_LOGINOK) ? "\n您的註冊程序已經完成,歡迎加入本站" : "\n如果要提昇權限,請參考本站公佈欄辦理註冊"); - + #ifdef NEWUSER_LIMIT - if((u->lastlogin - u->firstlogin < 3 * 86400) && !HAS_PERM(PERM_POST)) + if ((u->lastlogin - u->firstlogin < 3 * 86400) && !HAS_PERM(PERM_POST)) outs("\n新手上路,三天後開放權限"); #endif } -void mail_violatelaw(char* crime, char* police, char* reason, char* result){ - char genbuf[200]; - fileheader_t fhdr; - FILE *fp; +void +mail_violatelaw(char *crime, char *police, char *reason, char *result) +{ + char genbuf[200]; + fileheader_t fhdr; + FILE *fp; sprintf(genbuf, "home/%c/%s", crime[0], crime); stampfile(genbuf, &fhdr); - if(!(fp = fopen(genbuf,"w"))) - return; + if (!(fp = fopen(genbuf, "w"))) + return; fprintf(fp, "作者: [Ptt法院]\n" "標題: [報告] 違法判決報告\n" "時間: %s\n" "\033[1;32m%s\033[m判決:\n \033[1;32m%s\033[m" "因\033[1;35m%s\033[m行為,\n違反本站站規,處以\033[1;35m%s\033[m,特此通知" - "\n請到 PttLaw 查詢相關法規資訊,並到 Play-Pay-ViolateLaw 繳交罰單", + "\n請到 PttLaw 查詢相關法規資訊,並到 Play-Pay-ViolateLaw 繳交罰單", ctime(&now), police, crime, reason, result); fclose(fp); sprintf(fhdr.title, "[報告] 違法判決報告"); @@ -134,16 +140,18 @@ void mail_violatelaw(char* crime, char* police, char* reason, char* result){ append_record(genbuf, &fhdr, sizeof(fhdr)); } -static void violate_law(userec_t *u, int unum){ - char ans[4], ans2[4]; - char reason[128]; - move(1,0); +static void +violate_law(userec_t * u, int unum) +{ + char ans[4], ans2[4]; + char reason[128]; + move(1, 0); clrtobot(); - move(2,0); + move(2, 0); prints("(1)Cross-post (2)亂發廣告信 (3)亂發連鎖信\n"); prints("(4)騷擾站上使用者 (8)其他以罰單處置行為\n(9)砍 id 行為\n"); getdata(5, 0, "(0)結束", ans, sizeof(ans), DOECHO); - switch(ans[0]){ + switch (ans[0]) { case '1': sprintf(reason, "%s", "Cross-post"); break; @@ -154,84 +162,84 @@ static void violate_law(userec_t *u, int unum){ sprintf(reason, "%s", "亂發連鎖信"); break; case '4': - while(!getdata(7, 0, "請輸入被檢舉理由以示負責:", reason, 50, DOECHO)); - strcat(reason, "[騷擾站上使用者]"); - break; - case '8': + while (!getdata(7, 0, "請輸入被檢舉理由以示負責:", reason, 50, DOECHO)); + strcat(reason, "[騷擾站上使用者]"); + break; + case '8': case '9': - while(!getdata(6, 0, "請輸入理由以示負責:", reason, 50, DOECHO)); - break; + while (!getdata(6, 0, "請輸入理由以示負責:", reason, 50, DOECHO)); + break; default: return; } getdata(7, 0, msg_sure_ny, ans2, sizeof(ans2), LCECHO); - if(*ans2 != 'y') - return; - if (ans[0]=='9'){ - char src[STRLEN], dst[STRLEN]; + if (*ans2 != 'y') + return; + if (ans[0] == '9') { + char src[STRLEN], dst[STRLEN]; sprintf(src, "home/%c/%s", u->userid[0], u->userid); sprintf(dst, "tmp/%s", u->userid); Rename(src, dst); log_usies("KILL", u->userid); - post_violatelaw(u->userid, cuser.userid, reason, "砍除 ID"); + post_violatelaw(u->userid, cuser.userid, reason, "砍除 ID"); u->userid[0] = '\0'; setuserid(unum, u->userid); passwd_update(unum, u); - } - else{ - u->userlevel |= PERM_VIOLATELAW; - u->vl_count ++; + } else { + u->userlevel |= PERM_VIOLATELAW; + u->vl_count++; passwd_update(unum, u); - post_violatelaw(u->userid, cuser.userid, reason, "罰單處份"); - mail_violatelaw(u->userid, cuser.userid, reason, "罰單處份"); - } + post_violatelaw(u->userid, cuser.userid, reason, "罰單處份"); + mail_violatelaw(u->userid, cuser.userid, reason, "罰單處份"); + } pressanykey(); } -void uinfo_query(userec_t *u, int real, int unum) { - userec_t x; - register int i = 0, fail, mail_changed; - int uid; - char ans[4], buf[STRLEN], *p; - char genbuf[200], reason[50]; +void +uinfo_query(userec_t * u, int real, int unum) +{ + userec_t x; + register int i = 0, fail, mail_changed; + int uid; + char ans[4], buf[STRLEN], *p; + char genbuf[200], reason[50]; unsigned long int money = 0; - fileheader_t fhdr; - int flag = 0, temp = 0, money_change = 0; - - FILE *fp; - + fileheader_t fhdr; + int flag = 0, temp = 0, money_change = 0; + + FILE *fp; + fail = mail_changed = 0; - + memcpy(&x, u, sizeof(userec_t)); getdata(b_lines - 1, 0, real ? "(1)改資料(2)設密碼(3)設權限(4)砍帳號(5)改ID" "(6)殺/復活寵物(7)審判 [0]結束 " : "請選擇 (1)修改資料 (2)設定密碼 ==> [0]結束 ", ans, sizeof(ans), DOECHO); - - if(ans[0] > '2' && !real) + + if (ans[0] > '2' && !real) ans[0] = '0'; - - if(ans[0] == '1' || ans[0] == '3') { + + if (ans[0] == '1' || ans[0] == '3') { clear(); i = 2; move(i++, 0); outs(msg_uid); outs(x.userid); } - - switch(ans[0]) { + switch (ans[0]) { case '7': violate_law(&x, unum); return; case '1': move(0, 0); outs("請逐項修改。"); - - getdata_buf(i++, 0," 暱 稱 :",x.username, + + getdata_buf(i++, 0, " 暱 稱 :", x.username, sizeof(x.username), DOECHO); - if(real) { + if (real) { getdata_buf(i++, 0, "真實姓名:", x.realname, sizeof(x.realname), DOECHO); getdata_buf(i++, 0, "身分證號:", @@ -241,55 +249,54 @@ void uinfo_query(userec_t *u, int real, int unum) { } sprintf(buf, "%010d", x.mobile); getdata_buf(i++, 0, "手機號碼:", buf, 11, LCECHO); - x.mobile=atoi(buf); + x.mobile = atoi(buf); getdata_str(i++, 0, "電子信箱[變動要重新認證]:", buf, 50, DOECHO, x.email); - if(strcmp(buf,x.email) && strchr(buf, '@')) { - strcpy(x.email,buf); + if (strcmp(buf, x.email) && strchr(buf, '@')) { + strcpy(x.email, buf); mail_changed = 1 - real; } - sprintf(genbuf, "%i", (u->sex + 1) % 8); getdata_str(i++, 0, "性別 (1)葛格 (2)姐接 (3)底迪 (4)美眉 (5)薯叔 " "(6)阿姨 (7)植物 (8)礦物:", - buf, 3, DOECHO,genbuf); - if(buf[0] >= '1' && buf[0] <= '8') + buf, 3, DOECHO, genbuf); + if (buf[0] >= '1' && buf[0] <= '8') x.sex = (buf[0] - '1') % 8; else x.sex = u->sex % 8; - - while(1) { - int len; - + + while (1) { + int len; + sprintf(genbuf, "%02i/%02i/%02i", u->month, u->day, u->year % 100); len = getdata_str(i, 0, "生日 月月/日日/西元:", buf, 9, - DOECHO,genbuf); - if(len && len != 8) + DOECHO, genbuf); + if (len && len != 8) continue; - if(!len) { + if (!len) { x.month = u->month; x.day = u->day; x.year = u->year; - } else if(len == 8) { + } else if (len == 8) { x.month = (buf[0] - '0') * 10 + (buf[1] - '0'); - x.day = (buf[3] - '0') * 10 + (buf[4] - '0'); - x.year = (buf[6] - '0') * 10 + (buf[7] - '0'); + x.day = (buf[3] - '0') * 10 + (buf[4] - '0'); + x.year = (buf[6] - '0') * 10 + (buf[7] - '0'); } else continue; - if(!real && (x.month > 12 || x.month < 1 || x.day > 31 || - x.day < 1 || x.year > 90 || x.year < 40)) + if (!real && (x.month > 12 || x.month < 1 || x.day > 31 || + x.day < 1 || x.year > 90 || x.year < 40)) continue; i++; break; } - if(real) { + if (real) { unsigned long int l; - if(HAS_PERM(PERM_BBSADM)) { + if (HAS_PERM(PERM_BBSADM)) { sprintf(genbuf, "%d", x.money); - if(getdata_str(i++, 0,"銀行帳戶:", buf, 10, DOECHO,genbuf)) - if((l = atol(buf)) != 0) { - if(l != x.money) { + if (getdata_str(i++, 0, "銀行帳戶:", buf, 10, DOECHO, genbuf)) + if ((l = atol(buf)) != 0) { + if (l != x.money) { money_change = 1; money = x.money; x.money = l; @@ -297,92 +304,95 @@ void uinfo_query(userec_t *u, int real, int unum) { } } sprintf(genbuf, "%d", x.exmailbox); - if(getdata_str(i++, 0,"購買信箱數:", buf, 4, DOECHO,genbuf)) - if((l = atol(buf)) != 0) + if (getdata_str(i++, 0, "購買信箱數:", buf, 4, DOECHO, genbuf)) + if ((l = atol(buf)) != 0) x.exmailbox = (int)l; - + getdata_buf(i++, 0, "認證資料:", x.justify, sizeof(x.justify), DOECHO); getdata_buf(i++, 0, "最近光臨機器:", x.lasthost, sizeof(x.lasthost), DOECHO); - + sprintf(genbuf, "%d", x.numlogins); - if(getdata_str(i++, 0,"上線次數:", buf, 10, DOECHO, genbuf)) - if((fail = atoi(buf)) >= 0) + if (getdata_str(i++, 0, "上線次數:", buf, 10, DOECHO, genbuf)) + if ((fail = atoi(buf)) >= 0) x.numlogins = fail; - - sprintf(genbuf,"%d", u->numposts); - if(getdata_str(i++, 0, "文章數目:", buf, 10, DOECHO,genbuf)) - if((fail = atoi(buf)) >= 0) + + sprintf(genbuf, "%d", u->numposts); + if (getdata_str(i++, 0, "文章數目:", buf, 10, DOECHO, genbuf)) + if ((fail = atoi(buf)) >= 0) x.numposts = fail; sprintf(genbuf, "%d", u->vl_count); if (getdata_str(i++, 0, "違法記錄:", buf, 10, DOECHO, genbuf)) if ((fail = atoi(buf)) >= 0) x.vl_count = fail; - + sprintf(genbuf, "%d/%d/%d", u->five_win, u->five_lose, u->five_tie); - if(getdata_str(i++, 0, "五子棋戰績 勝/敗/和:", buf, 16, DOECHO, - genbuf)) - while(1) { + if (getdata_str(i++, 0, "五子棋戰績 勝/敗/和:", buf, 16, DOECHO, + genbuf)) + while (1) { p = strtok(buf, "/\r\n"); - if(!p) break; + if (!p) + break; x.five_win = atoi(p); p = strtok(NULL, "/\r\n"); - if(!p) break; + if (!p) + break; x.five_lose = atoi(p); p = strtok(NULL, "/\r\n"); - if(!p) break; + if (!p) + break; x.five_tie = atoi(p); break; } sprintf(genbuf, "%d/%d/%d", u->chc_win, u->chc_lose, u->chc_tie); - if(getdata_str(i++, 0, "象棋戰績 勝/敗/和:", buf, 16, DOECHO, - genbuf)) - while(1) { + if (getdata_str(i++, 0, "象棋戰績 勝/敗/和:", buf, 16, DOECHO, + genbuf)) + while (1) { p = strtok(buf, "/\r\n"); - if(!p) break; + if (!p) + break; x.chc_win = atoi(p); p = strtok(NULL, "/\r\n"); - if(!p) break; + if (!p) + break; x.chc_lose = atoi(p); p = strtok(NULL, "/\r\n"); - if(!p) break; + if (!p) + break; x.chc_tie = atoi(p); break; } fail = 0; } break; - + case '2': i = 19; - if(!real) { - if(!getdata(i++, 0, "請輸入原密碼:", buf, PASSLEN, NOECHO) || - !checkpasswd(u->passwd, buf)) { + if (!real) { + if (!getdata(i++, 0, "請輸入原密碼:", buf, PASSLEN, NOECHO) || + !checkpasswd(u->passwd, buf)) { outs("\n\n您輸入的密碼不正確\n"); fail++; break; } - } - else{ - char witness[3][32]; - for(i=0;i<3;i++){ - if(!getdata(19+i, 0, "請輸入協助證明之使用者:", - witness[i], sizeof(witness[i]), DOECHO)){ + } else { + char witness[3][32]; + for (i = 0; i < 3; i++) { + if (!getdata(19 + i, 0, "請輸入協助證明之使用者:", + witness[i], sizeof(witness[i]), DOECHO)) { outs("\n不輸入則無法更改\n"); fail++; break; - } - else if( !(uid = getuser(witness[i])) ){ + } else if (!(uid = getuser(witness[i]))) { outs("\n查無此使用者\n"); fail++; break; - } - else { - userec_t atuser; + } else { + userec_t atuser; passwd_query(uid, &atuser); - if (now - atuser.firstlogin < 6*30*24*60*60){ + if (now - atuser.firstlogin < 6 * 30 * 24 * 60 * 60) { outs("\n註冊未超過半年,請重新輸入\n"); i--; } @@ -392,17 +402,17 @@ void uinfo_query(userec_t *u, int real, int unum) { break; else i = 20; - } - - if(!getdata(i++, 0, "請設定新密碼:", buf, PASSLEN, NOECHO)) { + } + + if (!getdata(i++, 0, "請設定新密碼:", buf, PASSLEN, NOECHO)) { outs("\n\n密碼設定取消, 繼續使用舊密碼\n"); fail++; break; } strncpy(genbuf, buf, PASSLEN); - + getdata(i++, 0, "請檢查新密碼:", buf, PASSLEN, NOECHO); - if(strncmp(buf, genbuf, PASSLEN)) { + if (strncmp(buf, genbuf, PASSLEN)) { outs("\n\n新密碼確認失敗, 無法設定新密碼\n"); fail++; break; @@ -412,26 +422,26 @@ void uinfo_query(userec_t *u, int real, int unum) { if (real) x.userlevel &= (!PERM_LOGINOK); break; - + case '3': i = setperms(x.userlevel, str_permid); - if(i == x.userlevel) + if (i == x.userlevel) fail++; else { - flag=1; - temp=x.userlevel; + flag = 1; + temp = x.userlevel; x.userlevel = i; } break; - + case '4': i = QUIT; break; - + case '5': if (getdata_str(b_lines - 3, 0, "新的使用者代號:", genbuf, IDLEN + 1, - DOECHO,x.userid)) { - if(searchuser(genbuf)) { + DOECHO, x.userid)) { + if (searchuser(genbuf)) { outs("錯誤! 已經有同樣 ID 的使用者"); fail++; } else @@ -439,78 +449,75 @@ void uinfo_query(userec_t *u, int real, int unum) { } break; case '6': - if(x.mychicken.name[0]) + if (x.mychicken.name[0]) x.mychicken.name[0] = 0; else - strcpy(x.mychicken.name,"[死]"); + strcpy(x.mychicken.name, "[死]"); break; default: return; } - if(fail) { + if (fail) { pressanykey(); return; } - getdata(b_lines - 1, 0, msg_sure_ny, ans, 3, LCECHO); - if(*ans == 'y') { - if(flag) - post_change_perm(temp,i,cuser.userid,x.userid); - if(strcmp(u->userid, x.userid)) { - char src[STRLEN], dst[STRLEN]; - + if (*ans == 'y') { + if (flag) + post_change_perm(temp, i, cuser.userid, x.userid); + if (strcmp(u->userid, x.userid)) { + char src[STRLEN], dst[STRLEN]; + sethomepath(src, u->userid); sethomepath(dst, x.userid); Rename(src, dst); setuserid(unum, x.userid); } memcpy(u, &x, sizeof(x)); - if(mail_changed) { + if (mail_changed) { #ifdef EMAIL_JUSTIFY x.userlevel &= ~PERM_LOGINOK; mail_justify(); #endif } - - if(i == QUIT) { - char src[STRLEN], dst[STRLEN]; - + if (i == QUIT) { + char src[STRLEN], dst[STRLEN]; + sprintf(src, "home/%c/%s", x.userid[0], x.userid); sprintf(dst, "tmp/%s", x.userid); - if(Rename(src, dst)) { + if (Rename(src, dst)) { sprintf(genbuf, "/bin/rm -fr %s >/dev/null 2>&1", src); -/* do not remove - system(genbuf); -*/ - } + /* + * do not remove system(genbuf); + */ + } log_usies("KILL", x.userid); x.userid[0] = '\0'; setuserid(unum, x.userid); } else log_usies("SetUser", x.userid); - if(money_change) - setumoney(unum,x.money); + if (money_change) + setumoney(unum, x.money); passwd_update(unum, &x); - if(money_change) { + if (money_change) { strcpy(genbuf, "boards/S/Security"); - stampfile(genbuf, &fhdr); - if(!(fp = fopen(genbuf,"w"))) + stampfile(genbuf, &fhdr); + if (!(fp = fopen(genbuf, "w"))) return; - + fprintf(fp, "作者: [系統安全局] 看板: Security\n" "標題: [公安報告] 站長修改金錢報告\n" "時間: %s\n" " 站長\033[1;32m%s\033[m把\033[1;32m%s\033[m" "的錢從\033[1;35m%ld\033[m改成\033[1;35m%d\033[m", ctime(&now), cuser.userid, x.userid, money, x.money); - - clrtobot (); + + clrtobot(); clear(); - while( !getdata(5, 0, "請輸入理由以示負責:", - reason, sizeof(reason), DOECHO) ) - ; - + while (!getdata(5, 0, "請輸入理由以示負責:", + reason, sizeof(reason), DOECHO)); + fprintf(fp, "\n \033[1;37m站長%s修改錢理由是:%s\033[m", cuser.userid, reason); fclose(fp); @@ -522,7 +529,9 @@ void uinfo_query(userec_t *u, int real, int unum) { } } -int u_info() { +int +u_info() +{ move(2, 0); user_display(&cuser, 0); uinfo_query(&cuser, 0, usernum); @@ -531,108 +540,122 @@ int u_info() { return 0; } -int u_ansi() { +int +u_ansi() +{ showansi ^= 1; cuser.uflag ^= COLOR_FLAG; outs(reset_color); return 0; } -int u_cloak() { +int +u_cloak() +{ outs((currutmp->invisible ^= 1) ? MSG_CLOAKED : MSG_UNCLOAK); return XEASY; } -int u_switchproverb() { -/* char *state[4]={"用功\型","安逸型","自定型","SHUTUP"}; */ - char buf[100]; +int +u_switchproverb() +{ + /* char *state[4]={"用功\型","安逸型","自定型","SHUTUP"}; */ + char buf[100]; + + cuser.proverb = (cuser.proverb + 1) % 4; + setuserfile(buf, fn_proverb); + if (cuser.proverb == 2 && dashd(buf)) { + FILE *fp = fopen(buf, "a"); - cuser.proverb =(cuser.proverb +1) %4; - setuserfile(buf,fn_proverb); - if(cuser.proverb==2 && dashd(buf)) { - FILE *fp = fopen(buf,"a"); - - fprintf(fp,"座右銘狀態為[自定型]要記得設座右銘的內容唷!!"); + fprintf(fp, "座右銘狀態為[自定型]要記得設座右銘的內容唷!!"); fclose(fp); } passwd_update(usernum, &cuser); return 0; } -int u_editproverb() { - char buf[100]; - +int +u_editproverb() +{ + char buf[100]; + setutmpmode(PROVERB); - setuserfile(buf,fn_proverb); - move(1,0); + setuserfile(buf, fn_proverb); + move(1, 0); clrtobot(); outs("\n\n 請一行一行依序鍵入想系統提醒你的內容,\n" " 儲存後記得把狀態設為 [自定型] 才有作用\n" " 座右銘最多100條"); pressanykey(); - vedit(buf,NA, NULL); + vedit(buf, NA, NULL); return 0; } -void showplans(char *uid) { - char genbuf[200]; - +void +showplans(char *uid) +{ + char genbuf[200]; + sethomefile(genbuf, uid, fn_plans); - if(!show_file(genbuf, 7, MAX_QUERYLINES, ONLY_COLOR)) + if (!show_file(genbuf, 7, MAX_QUERYLINES, ONLY_COLOR)) prints("《個人名片》%s 目前沒有名片", uid); } -int showsignature(char *fname) { - FILE *fp; - char buf[256]; - int i, j; - char ch; +int +showsignature(char *fname) +{ + FILE *fp; + char buf[256]; + int i, j; + char ch; clear(); move(2, 0); setuserfile(fname, "sig.0"); j = strlen(fname) - 1; - for(ch = '1'; ch <= '9'; ch++) { + for (ch = '1'; ch <= '9'; ch++) { fname[j] = ch; - if((fp = fopen(fname, "r"))) { + if ((fp = fopen(fname, "r"))) { prints("\033[36m【 簽名檔.%c 】\033[m\n", ch); - for(i = 0; i++ < MAX_SIGLINES && fgets(buf, 256, fp); outs(buf)); + for (i = 0; i++ < MAX_SIGLINES && fgets(buf, 256, fp); outs(buf)); fclose(fp); } } return j; } -int u_editsig() { - int aborted; - char ans[4]; - int j; - char genbuf[200]; - +int +u_editsig() +{ + int aborted; + char ans[4]; + int j; + char genbuf[200]; + j = showsignature(genbuf); - + getdata(0, 0, "簽名檔 (E)編輯 (D)刪除 (Q)取消?[Q] ", ans, sizeof(ans), LCECHO); - + aborted = 0; - if(ans[0] == 'd') + if (ans[0] == 'd') aborted = 1; - if(ans[0] == 'e') + if (ans[0] == 'e') aborted = 2; - - if(aborted) { - if(!getdata(1, 0, "請選擇簽名檔(1-9)?[1] ", ans, sizeof(ans), DOECHO)) + + if (aborted) { + if (!getdata(1, 0, "請選擇簽名檔(1-9)?[1] ", ans, sizeof(ans), DOECHO)) ans[0] = '1'; - if(ans[0] >= '1' && ans[0] <= '9') { + if (ans[0] >= '1' && ans[0] <= '9') { genbuf[j] = ans[0]; - if(aborted == 1) { + if (aborted == 1) { unlink(genbuf); outs(msg_del_ok); } else { setutmpmode(EDITSIG); aborted = vedit(genbuf, NA, NULL); - if(aborted != -1) + if (aborted != -1) outs("簽名檔更新完畢"); } } @@ -641,23 +664,25 @@ int u_editsig() { return 0; } -int u_editplan() { - char genbuf[200]; - +int +u_editplan() +{ + char genbuf[200]; + getdata(b_lines - 1, 0, "名片 (D)刪除 (E)編輯 [Q]取消?[Q] ", genbuf, 3, LCECHO); - - if(genbuf[0] == 'e') { - int aborted; - + + if (genbuf[0] == 'e') { + int aborted; + setutmpmode(EDITPLAN); setuserfile(genbuf, fn_plans); aborted = vedit(genbuf, NA, NULL); - if(aborted != -1) + if (aborted != -1) outs("名片更新完畢"); pressanykey(); return 0; - } else if(genbuf[0] == 'd') { + } else if (genbuf[0] == 'd') { setuserfile(genbuf, fn_plans); unlink(genbuf); outmsg("名片刪除完畢"); @@ -665,23 +690,25 @@ int u_editplan() { return 0; } -int u_editcalendar() { - char genbuf[200]; - +int +u_editcalendar() +{ + char genbuf[200]; + getdata(b_lines - 1, 0, "行事曆 (D)刪除 (E)編輯 [Q]取消?[Q] ", genbuf, 3, LCECHO); - - if(genbuf[0] == 'e') { - int aborted; - + + if (genbuf[0] == 'e') { + int aborted; + setutmpmode(EDITPLAN); setcalfile(genbuf, cuser.userid); aborted = vedit(genbuf, NA, NULL); - if(aborted != -1) + if (aborted != -1) outs("行事曆更新完畢"); pressanykey(); return 0; - } else if(genbuf[0] == 'd') { + } else if (genbuf[0] == 'd') { setcalfile(genbuf, cuser.userid); unlink(genbuf); outmsg("行事曆刪除完畢"); @@ -690,25 +717,29 @@ int u_editcalendar() { } /* 使用者填寫註冊表格 */ -static void getfield(int line, char *info, char *desc, char *buf, int len) { - char prompt[STRLEN]; - char genbuf[200]; +static void +getfield(int line, char *info, char *desc, char *buf, int len) +{ + char prompt[STRLEN]; + char genbuf[200]; sprintf(genbuf, "原先設定:%-30.30s (%s)", buf, info); move(line, 2); outs(genbuf); sprintf(prompt, "%s:", desc); - if(getdata_str(line + 1, 2, prompt, genbuf, len, DOECHO, buf)) + if (getdata_str(line + 1, 2, prompt, genbuf, len, DOECHO, buf)) strcpy(buf, genbuf); move(line, 2); prints("%s:%s", desc, buf); clrtoeol(); } -static int removespace(char* s){ - int i, index; +static int +removespace(char *s) +{ + int i, index; - for(i=0, index=0;s[i];i++){ + for (i = 0, index = 0; s[i]; i++) { if (s[i] != ' ') s[index++] = s[i]; } @@ -716,59 +747,62 @@ static int removespace(char* s){ return index; } -static int ispersonalid(char *inid) +static int +ispersonalid(char *inid) { - char *lst="ABCDEFGHJKLMNPQRSTUVWXYZIO", id[20]; - int i, j, cksum; + char *lst = "ABCDEFGHJKLMNPQRSTUVWXYZIO", id[20]; + int i, j, cksum; strcpy(id, inid); i = cksum = 0; - if( !isalpha(id[0]) && (strlen(id)!=10) ) - return 0; + if (!isalpha(id[0]) && (strlen(id) != 10)) + return 0; id[0] = toupper(id[0]); /* A->10, B->11, ..H->17,I->34, J->18... */ - while( lst[i] != id[0] ) - i++; + while (lst[i] != id[0]) + i++; i += 10; id[0] = i % 10 + '0'; - if( !isdigit(id[9]) ) - return 0; + if (!isdigit(id[9])) + return 0; cksum += (id[9] - '0') + (i / 10); - for( j = 0 ; j < 9 ; ++j ){ - if( !isdigit(id[j]) ) - return 0; - cksum += (id[j] - '0') * (9 - j); + for (j = 0; j < 9; ++j) { + if (!isdigit(id[j])) + return 0; + cksum += (id[j] - '0') * (9 - j); } return (cksum % 10) == 0; } -static char *getregcode(char *buf) +static char * +getregcode(char *buf) { sprintf(buf, "%s", crypt(cuser.userid, "02")); return buf; } -static int isvaildemail(char *email) +static int +isvaildemail(char *email) { - FILE *fp; - char buf[128], *c; - if( !strstr(email, "@") ) + FILE *fp; + char buf[128], *c; + if (!strstr(email, "@")) return 0; - for( c = strstr(email, "@") ; *c != 0 ; ++c ) - if( 'A' <= *c && *c <= 'Z' ) + for (c = strstr(email, "@"); *c != 0; ++c) + if ('A' <= *c && *c <= 'Z') *c += 32; - if( (fp = fopen("etc/banemail", "r")) ){ - while( fgets(buf, sizeof(buf), fp) ){ - if( buf[0] == '#' ) + if ((fp = fopen("etc/banemail", "r"))) { + while (fgets(buf, sizeof(buf), fp)) { + if (buf[0] == '#') continue; - buf[ strlen(buf) - 1 ] = 0; - if( buf[0] == 'A' && strcmp(&buf[1], email) == 0 ) + buf[strlen(buf) - 1] = 0; + if (buf[0] == 'A' && strcmp(&buf[1], email) == 0) return 0; - if( buf[0] == 'P' && strstr(email, &buf[1]) ) + if (buf[0] == 'P' && strstr(email, &buf[1])) return 0; - if( buf[0] == 'S' && strcmp(strstr(email, "@") + 1, &buf[1]) == 0 ) + if (buf[0] == 'S' && strcmp(strstr(email, "@") + 1, &buf[1]) == 0) return 0; } fclose(fp); @@ -776,20 +810,20 @@ static int isvaildemail(char *email) return 1; } -static void toregister(char *email, char *genbuf, char *phone, char *career, - char *ident, char *rname, char *addr, char *mobile) +static void +toregister(char *email, char *genbuf, char *phone, char *career, + char *ident, char *rname, char *addr, char *mobile) { - FILE *fn; - char buf[128]; + FILE *fn; + char buf[128]; sethomefile(buf, cuser.userid, "justify.wait"); - if( phone[0] != 0 ){ + if (phone[0] != 0) { fn = fopen(buf, "w"); fprintf(fn, "%s\n%s\n%s\n%s\n%s\n%s\n", phone, career, ident, rname, addr, mobile); fclose(fn); } - clear(); stand_title("認證設定"); move(2, 0); @@ -812,43 +846,41 @@ static void toregister(char *email, char *genbuf, char *phone, char *career, " 收到後請到(U)ser => (R)egister 輸入認證碼, 即可通過認證\n"); #endif - while( 1 ){ + while (1) { email[0] = 0; getfield(15, "身分認證用", "E-Mail Address", email, 50); - if( strcmp(email, "x") == 0 || strcmp(email, "X") == 0 ) + if (strcmp(email, "x") == 0 || strcmp(email, "X") == 0) break; #ifdef HAVEMOBILE - else if ( strcmp(email, "m") == 0 || strcmp(email,"M") == 0 ) { - if ( isvaildmobile(mobile) ) { - char yn[3]; - getdata(16, 0, "請再次確認您輸入的手機號碼正確嘛? [y/N]", - yn, sizeof(yn), LCECHO); - if( yn[0] == 'Y' || yn[0] == 'y' ) - break; - } - else{ - move(17, 0); - prints("指定的手機號碼不合法," - "若您無手機門號請選擇其他方式認證"); - } + else if (strcmp(email, "m") == 0 || strcmp(email, "M") == 0) { + if (isvaildmobile(mobile)) { + char yn[3]; + getdata(16, 0, "請再次確認您輸入的手機號碼正確嘛? [y/N]", + yn, sizeof(yn), LCECHO); + if (yn[0] == 'Y' || yn[0] == 'y') + break; + } else { + move(17, 0); + prints("指定的手機號碼不合法," + "若您無手機門號請選擇其他方式認證"); + } } #endif - else if( isvaildemail(email) ){ - char yn[3]; + else if (isvaildemail(email)) { + char yn[3]; getdata(16, 0, "請再次確認您輸入的 E-Mail 位置正確嘛? [y/N]", yn, sizeof(yn), LCECHO); - if( yn[0] == 'Y' || yn[0] == 'y' ) + if (yn[0] == 'Y' || yn[0] == 'y') break; - } - else{ + } else { move(17, 0); prints("指定的 E-Mail 不合法," "若您無 E-Mail 請輸入 x由站長手動認證"); } } strncpy(cuser.email, email, sizeof(cuser.email)); - if( strcasecmp(email, "x") == 0 ){ /* 手動認證 */ + if (strcasecmp(email, "x") == 0) { /* 手動認證 */ if ((fn = fopen(fn_register, "a"))) { fprintf(fn, "num: %d, %s", usernum, ctime(&now)); fprintf(fn, "uid: %s\n", cuser.userid); @@ -862,28 +894,27 @@ static void toregister(char *email, char *genbuf, char *phone, char *career, fprintf(fn, "----\n"); fclose(fn); } - } - else{ - char tmp[IDLEN + 1]; - if( phone != NULL ){ + } else { + char tmp[IDLEN + 1]; + if (phone != NULL) { #ifdef HAVEMOBILE - if ( strcmp(email, "m") == 0 || strcmp(email,"M") == 0 ) - sprintf(genbuf, "%s:%s:<Mobile>", phone, career); - else + if (strcmp(email, "m") == 0 || strcmp(email, "M") == 0) + sprintf(genbuf, "%s:%s:<Mobile>", phone, career); + else #endif - sprintf(genbuf, "%s:%s:<Email>", phone, career); + sprintf(genbuf, "%s:%s:<Email>", phone, career); strncpy(cuser.justify, genbuf, REGLEN); sethomefile(buf, cuser.userid, "justify"); } - sprintf(buf, "您在 "BBSNAME" 的認證碼: %s", getregcode(genbuf)); + sprintf(buf, "您在 " BBSNAME " 的認證碼: %s", getregcode(genbuf)); strcpy(tmp, cuser.userid); strcpy(cuser.userid, "SYSOP"); #ifdef HAVEMOBILE - if ( strcmp(email, "m") == 0 || strcmp(email,"M") == 0 ) - mobile_message(mobile, buf); - else + if (strcmp(email, "m") == 0 || strcmp(email, "M") == 0) + mobile_message(mobile, buf); + else #endif - bsmtp("etc/registermail", buf, email, 0); + bsmtp("etc/registermail", buf, email, 0); strcpy(cuser.userid, tmp); outs("\n\n\n我們即將寄出認證信 (您應該會在 10 分鐘內收到)\n" "收到後您可以跟據認證信標題的認證碼\n" @@ -893,25 +924,27 @@ static void toregister(char *email, char *genbuf, char *phone, char *career, } } -int u_register(void) +int +u_register(void) { - char rname[21], addr[51], ident[12], mobile[21]; - char phone[21], career[41], email[51],birthday[9],sex_is[2],year,mon,day; - char inregcode[14], regcode[50]; - char ans[3], *ptr; - char genbuf[200]; - FILE *fn; - - if(cuser.userlevel & PERM_LOGINOK) { + char rname[21], addr[51], ident[12], mobile[21]; + char phone[21], career[41], email[51], birthday[9], sex_is[2], + year, mon, day; + char inregcode[14], regcode[50]; + char ans[3], *ptr; + char genbuf[200]; + FILE *fn; + + if (cuser.userlevel & PERM_LOGINOK) { outs("您的身份確認已經完成,不需填寫申請表"); return XEASY; } - if((fn = fopen(fn_register, "r"))) { - while(fgets(genbuf, STRLEN, fn)) { - if((ptr = strchr(genbuf, '\n'))) + if ((fn = fopen(fn_register, "r"))) { + while (fgets(genbuf, STRLEN, fn)) { + if ((ptr = strchr(genbuf, '\n'))) *ptr = '\0'; - if(strncmp(genbuf, "uid: ", 5) == 0 && - strcmp(genbuf + 5, cuser.userid) == 0) { + if (strncmp(genbuf, "uid: ", 5) == 0 && + strcmp(genbuf + 5, cuser.userid) == 0) { fclose(fn); outs("您的註冊申請單尚在處理中,請耐心等候"); return XEASY; @@ -919,32 +952,38 @@ int u_register(void) } fclose(fn); } - strcpy(ident, cuser.ident); strcpy(rname, cuser.realname); strcpy(addr, cuser.address); strcpy(email, cuser.email); - sprintf(mobile,"0%09d",cuser.mobile); - if( cuser.month == 0 && cuser.day && cuser.year == 0 ) + sprintf(mobile, "0%09d", cuser.mobile); + if (cuser.month == 0 && cuser.day && cuser.year == 0) birthday[0] = 0; else sprintf(birthday, "%02i/%02i/%02i", cuser.month, cuser.day, cuser.year % 100); - sex_is[0]=(cuser.sex % 8)+'1';sex_is[1]=0; + sex_is[0] = (cuser.sex % 8) + '1'; + sex_is[1] = 0; career[0] = phone[0] = '\0'; sethomefile(genbuf, cuser.userid, "justify.wait"); - if( (fn = fopen(genbuf, "r")) ){ - fgets(phone, 21, fn); phone[ strlen(phone) - 1] = 0; - fgets(career,41, fn); career[strlen(career)- 1] = 0; - fgets(ident, 12, fn); ident[ strlen(ident) - 1] = 0; - fgets(rname, 21, fn); rname[ strlen(rname) - 1] = 0; - fgets(addr, 51, fn); addr [ strlen(addr) - 1] = 0; - fgets(mobile,21, fn); mobile[strlen(mobile)- 1] = 0; + if ((fn = fopen(genbuf, "r"))) { + fgets(phone, 21, fn); + phone[strlen(phone) - 1] = 0; + fgets(career, 41, fn); + career[strlen(career) - 1] = 0; + fgets(ident, 12, fn); + ident[strlen(ident) - 1] = 0; + fgets(rname, 21, fn); + rname[strlen(rname) - 1] = 0; + fgets(addr, 51, fn); + addr[strlen(addr) - 1] = 0; + fgets(mobile, 21, fn); + mobile[strlen(mobile) - 1] = 0; fclose(fn); } - if( cuser.year != 0 && /* 已經第一次填過了~ ^^" */ - strcmp(cuser.email, "x") != 0 && /* 上次手動認證失敗 */ - strcmp(cuser.email, "X") != 0 ) { + if (cuser.year != 0 && /* 已經第一次填過了~ ^^" */ + strcmp(cuser.email, "x") != 0 && /* 上次手動認證失敗 */ + strcmp(cuser.email, "X") != 0) { clear(); stand_title("EMail認證"); move(2, 0); @@ -953,9 +992,9 @@ int u_register(void) cuser.userid, cuser.username); inregcode[0] = 0; getdata(10, 0, "您的輸入: ", inregcode, sizeof(inregcode), DOECHO); - if( strcmp(inregcode, getregcode(regcode)) == 0 ){ - int unum; - if( (unum = getuser(cuser.userid)) == 0 ){ + if (strcmp(inregcode, getregcode(regcode)) == 0) { + int unum; + if ((unum = getuser(cuser.userid)) == 0) { outs("系統錯誤,查無此人\n\n"); pressanykey(); u_exit("getuser error"); @@ -971,89 +1010,88 @@ int u_register(void) u_exit("registed"); exit(0); return QUIT; - } else if( strcmp(inregcode, "x")!=0 && strcmp(inregcode, "X")!=0 ){ + } else if (strcmp(inregcode, "x") != 0 && strcmp(inregcode, "X") != 0) { outs("認證碼錯誤\n"); pressanykey(); } toregister(email, genbuf, phone, career, ident, rname, addr, mobile); return FULLUPDATE; } - getdata(b_lines - 1, 0, "您確定要填寫註冊單嗎(Y/N)?[N] ", ans, sizeof(ans), LCECHO); - if(ans[0] != 'y') + if (ans[0] != 'y') return FULLUPDATE; - + move(2, 0); clrtobot(); - while(1) { + while (1) { clear(); move(1, 0); prints("%s(%s) 您好,請據實填寫以下的資料:", cuser.userid, cuser.username); - do{ + do { getfield(3, "D120908396", "身分證號", ident, 11); - if( 'a' <= ident[0] && ident[0] <= 'z' ) + if ('a' <= ident[0] && ident[0] <= 'z') ident[0] -= 32; - }while( !ispersonalid(ident) ); - while( 1 ){ + } while (!ispersonalid(ident)); + while (1) { getfield(5, "請用中文", "真實姓名", rname, 20); - if( removespace(rname) && rname[0] < 0 && - !strstr(rname, "阿") && !strstr(rname, "小") ) + if (removespace(rname) && rname[0] < 0 && + !strstr(rname, "阿") && !strstr(rname, "小")) break; vmsg("您的輸入不正確"); } - while( 1 ){ + while (1) { getfield(7, "學校(含\033[1;33m系所年級\033[m)或單位職稱", "服務單位", career, 40); - if( removespace(career) && career[0] < 0 && strlen(career) >= 4 ) + if (removespace(career) && career[0] < 0 && strlen(career) >= 4) break; vmsg("您的輸入不正確"); } - while( 1 ){ + while (1) { getfield(9, "含縣市及門寢號碼(台北請加\033[1;33m行政區\033[m)", "目前住址", addr, 50); - if( removespace(addr) && addr[0] < 0 && strlen(addr) >= 15 ) + if (removespace(addr) && addr[0] < 0 && strlen(addr) >= 15) break; vmsg("這個地址並不合法"); } - while( 1 ){ + while (1) { getfield(11, "不加-(), 包括長途區號", "連絡電話", phone, 11); - if( removespace(phone) && phone[0] == '0' && strlen(phone) >= 9 ) + if (removespace(phone) && phone[0] == '0' && strlen(phone) >= 9) break; vmsg("這個電話號碼並不合法"); } getfield(13, "只輸入數字 如:0912345678 (可不填)", "手機號碼", mobile, 20); - while(1) { - int len; - - getfield(15,"月月/日日/西元 如:09/27/76","生日",birthday,9); + while (1) { + int len; + + getfield(15, "月月/日日/西元 如:09/27/76", "生日", birthday, 9); len = strlen(birthday); - if(!len) { + if (!len) { sprintf(birthday, "%02i/%02i/%02i", cuser.month, cuser.day, cuser.year % 100); mon = cuser.month; day = cuser.day; year = cuser.year; - } else if(len == 8) { + } else if (len == 8) { mon = (birthday[0] - '0') * 10 + (birthday[1] - '0'); day = (birthday[3] - '0') * 10 + (birthday[4] - '0'); year = (birthday[6] - '0') * 10 + (birthday[7] - '0'); } else continue; - if(mon > 12 || mon < 1 || day > 31 || day < 1 || year > 90 || - year < 40) + if (mon > 12 || mon < 1 || day > 31 || day < 1 || year > 90 || + year < 40) continue; break; } getfield(17, "1.葛格 2.姐接 ", "性別", sex_is, 2); getdata(18, 0, "以上資料是否正確(Y/N)?(Q)取消註冊 [N] ", ans, sizeof(ans), LCECHO); - if(ans[0] == 'q') + if (ans[0] == 'q') return 0; - if(ans[0] == 'y') + if (ans[0] == 'y') break; } strcpy(cuser.ident, ident); @@ -1072,7 +1110,7 @@ int u_register(void) toregister(email, genbuf, phone, career, ident, rname, addr, mobile); clear(); - move(9,3); + move(9, 3); prints("最後Post一篇\033[32m自我介紹文章\033[m給大家吧," "告訴所有老骨頭\033[31m我來啦^$。\\n\n\n\n"); pressanykey(); @@ -1085,15 +1123,17 @@ int u_register(void) } /* 列出所有註冊使用者 */ -static int usercounter, totalusers, showrealname; -static ushort u_list_special; - -static int u_list_CB(userec_t *uentp) { - static int i; - char permstr[8], *ptr; - register int level; - - if(uentp == NULL) { +static int usercounter, totalusers, showrealname; +static ushort u_list_special; + +static int +u_list_CB(userec_t * uentp) +{ + static int i; + char permstr[8], *ptr; + register int level; + + if (uentp == NULL) { move(2, 0); clrtoeol(); prints("\033[7m 使用者代號 %-25s 上站 文章 %s " @@ -1103,49 +1143,47 @@ static int u_list_CB(userec_t *uentp) { i = 3; return 0; } - - if(bad_user_id(uentp->userid)) + if (bad_user_id(uentp->userid)) return 0; - - if((uentp->userlevel & ~(u_list_special)) == 0) + + if ((uentp->userlevel & ~(u_list_special)) == 0) return 0; - - if(i == b_lines) { + + if (i == b_lines) { prints("\033[34;46m 已顯示 %d/%d 人(%d%%) \033[31;47m " "(Space)\033[30m 看下一頁 \033[31m(Q)\033[30m 離開 \033[m", usercounter, totalusers, usercounter * 100 / totalusers); i = igetch(); - if(i == 'q' || i == 'Q') + if (i == 'q' || i == 'Q') return QUIT; i = 3; } - if(i == 3) { + if (i == 3) { move(3, 0); clrtobot(); } - level = uentp->userlevel; strcpy(permstr, "----"); - if(level & PERM_SYSOP) + if (level & PERM_SYSOP) permstr[0] = 'S'; - else if(level & PERM_ACCOUNTS) + else if (level & PERM_ACCOUNTS) permstr[0] = 'A'; - else if(level & PERM_DENYPOST) + else if (level & PERM_DENYPOST) permstr[0] = 'p'; - if(level & (PERM_BOARD)) + if (level & (PERM_BOARD)) permstr[1] = 'B'; - else if(level & (PERM_BM)) + else if (level & (PERM_BM)) permstr[1] = 'b'; - if(level & (PERM_XEMPT)) + if (level & (PERM_XEMPT)) permstr[2] = 'X'; - else if(level & (PERM_LOGINOK)) + else if (level & (PERM_LOGINOK)) permstr[2] = 'R'; - if(level & (PERM_CLOAK | PERM_SEECLOAK)) + if (level & (PERM_CLOAK | PERM_SEECLOAK)) permstr[3] = 'C'; - + ptr = (char *)Cdate(&uentp->lastlogin); ptr[18] = '\0'; prints("%-14s %-27.27s%5d %5d %s %s\n", @@ -1158,26 +1196,28 @@ static int u_list_CB(userec_t *uentp) { return 0; } -int u_list() { - char genbuf[3]; - +int +u_list() +{ + char genbuf[3]; + setutmpmode(LAUSERS); showrealname = u_list_special = usercounter = 0; totalusers = SHM->number; - if(HAS_PERM(PERM_SEEULEVELS)) { + if (HAS_PERM(PERM_SEEULEVELS)) { getdata(b_lines - 1, 0, "觀看 [1]特殊等級 (2)全部?", genbuf, 3, DOECHO); - if(genbuf[0] != '2') + if (genbuf[0] != '2') u_list_special = PERM_BASIC | PERM_CHAT | PERM_PAGE | PERM_POST | PERM_LOGINOK | PERM_BM; } - if(HAS_PERM(PERM_CHATROOM) || HAS_PERM(PERM_SYSOP)) { + if (HAS_PERM(PERM_CHATROOM) || HAS_PERM(PERM_SYSOP)) { getdata(b_lines - 1, 0, "顯示 [1]真實姓名 (2)暱稱?", genbuf, 3, DOECHO); - if(genbuf[0] != '2') + if (genbuf[0] != '2') showrealname = 1; } u_list_CB(NULL); - if(passwd_apply(u_list_CB) == -1) { + if (passwd_apply(u_list_CB) == -1) { outs(msg_nobody); return XEASY; } diff --git a/pttbbs/mbbsd/var.c b/pttbbs/mbbsd/var.c index fe778782..221c9cb4 100644 --- a/pttbbs/mbbsd/var.c +++ b/pttbbs/mbbsd/var.c @@ -1,570 +1,565 @@ -/* $Id: var.c,v 1.9 2002/07/05 13:14:14 in2 Exp $ */ +/* $Id: var.c,v 1.10 2002/07/05 17:10:28 in2 Exp $ */ #define INCLUDE_VAR_H #include "bbs.h" -char *str_permid[] = { - "基本權力", /* PERM_BASIC */ - "進入聊天室", /* PERM_CHAT */ - "找人聊天", /* PERM_PAGE */ - "發表文章", /* PERM_POST */ - "註冊程序認證", /* PERM_LOGINOK */ - "信件無上限", /* PERM_MAILLIMIT */ - "隱身術", /* PERM_CLOAK */ - "看見忍者", /* PERM_SEECLOAK */ - "永久保留帳號", /* PERM_XEMPT */ - "站長隱身術", /* PERM_DENYPOST */ - "板主", /* PERM_BM */ - "帳號總管", /* PERM_ACCOUNTS */ - "聊天室總管", /* PERM_CHATCLOAK */ - "看板總管", /* PERM_BOARD */ - "站長", /* PERM_SYSOP */ - "BBSADM", /* PERM_POSTMARK */ - "不列入排行榜", /* PERM_NOTOP */ - "違法通緝中", /* PERM_VIOLATELAW */ - "不接受站外的信", /* PERM_ */ - "沒想到", /* PERM_ */ - "視覺站長", /* PERM_VIEWSYSOP */ - "觀察使用者行蹤", /* PERM_LOGUSER */ - "精華區總整理權", /* PERM_Announce */ - "公關組", /* PERM_RELATION */ - "特務組", /* PERM_SMG */ - "程式組", /* PERM_PRG */ - "活動組", /* PERM_ACTION */ - "美工組", /* PERM_PAINT */ - "立法組", /* PERM_LAW */ - "小組長", /* PERM_SYSSUBOP */ - "一級主管", /* PERM_LSYSOP */ - "Ptt" /* PERM_PTT */ +char *str_permid[] = { + "基本權力", /* PERM_BASIC */ + "進入聊天室", /* PERM_CHAT */ + "找人聊天", /* PERM_PAGE */ + "發表文章", /* PERM_POST */ + "註冊程序認證", /* PERM_LOGINOK */ + "信件無上限", /* PERM_MAILLIMIT */ + "隱身術", /* PERM_CLOAK */ + "看見忍者", /* PERM_SEECLOAK */ + "永久保留帳號", /* PERM_XEMPT */ + "站長隱身術", /* PERM_DENYPOST */ + "板主", /* PERM_BM */ + "帳號總管", /* PERM_ACCOUNTS */ + "聊天室總管", /* PERM_CHATCLOAK */ + "看板總管", /* PERM_BOARD */ + "站長", /* PERM_SYSOP */ + "BBSADM", /* PERM_POSTMARK */ + "不列入排行榜", /* PERM_NOTOP */ + "違法通緝中", /* PERM_VIOLATELAW */ + "不接受站外的信", /* PERM_ */ + "沒想到", /* PERM_ */ + "視覺站長", /* PERM_VIEWSYSOP */ + "觀察使用者行蹤", /* PERM_LOGUSER */ + "精華區總整理權", /* PERM_Announce */ + "公關組", /* PERM_RELATION */ + "特務組", /* PERM_SMG */ + "程式組", /* PERM_PRG */ + "活動組", /* PERM_ACTION */ + "美工組", /* PERM_PAINT */ + "立法組", /* PERM_LAW */ + "小組長", /* PERM_SYSSUBOP */ + "一級主管", /* PERM_LSYSOP */ + "Ptt" /* PERM_PTT */ }; -char *str_permboard[] = { - "不可 Zap", /* BRD_NOZAP */ - "不列入統計", /* BRD_NOCOUNT */ - "不轉信", /* BRD_NOTRAN */ - "群組板", /* BRD_GROUP */ - "隱藏板", /* BRD_HIDE */ - "限制(不需設定)", /* BRD_POSTMASK */ - "匿名板", /* BRD_ANONYMOUS */ - "預設匿名板", /* BRD_DEFAULTANONYMOUS */ - "違法改進中看板", /* BRD_BAD */ - "連署專用看板", /* BRD_VOTEBOARD */ - "已警告要廢除", /* BRD_WARNEL */ - "熱門看板群組", /* BRD_TOP */ +char *str_permboard[] = { + "不可 Zap", /* BRD_NOZAP */ + "不列入統計", /* BRD_NOCOUNT */ + "不轉信", /* BRD_NOTRAN */ + "群組板", /* BRD_GROUP */ + "隱藏板", /* BRD_HIDE */ + "限制(不需設定)", /* BRD_POSTMASK */ + "匿名板", /* BRD_ANONYMOUS */ + "預設匿名板", /* BRD_DEFAULTANONYMOUS */ + "違法改進中看板", /* BRD_BAD */ + "連署專用看板", /* BRD_VOTEBOARD */ + "已警告要廢除", /* BRD_WARNEL */ + "熱門看板群組", /* BRD_TOP */ + "沒想到", + "沒想到", + "沒想到", + "沒想到", "沒想到", "沒想到", "沒想到", "沒想到", - "沒想到", "沒想到", "沒想到", "沒想到", "沒想到", - "沒想到", "沒想到", "沒想到", "沒想到", "沒想到", - "沒想到", "沒想到", "沒想到", "沒想到", "沒想到", - "沒想到", }; -int usernum; -int currmode = 0; -int curredit = 0; -int showansi = 1; -int paste_level; -int currbid; -char quote_file[80] = "\0"; -char quote_user[80] = "\0"; -char paste_title[STRLEN]; -char paste_path[256]; -char currtitle[TTLEN + 1] = "\0"; -char vetitle[TTLEN + 1] = "\0"; -char currowner[IDLEN + 2] = "\0"; -char currauthor[IDLEN + 2] = "\0"; -char currfile[FNLEN]; /* current file name @ bbs.c mail.c */ -char currboard[IDLEN + 2]; -char currBM[IDLEN * 3 + 10]; -char reset_color[4] = "\033[m"; -char margs[64] = "\0"; /* main argv list*/ -pid_t currpid; /* current process ID */ -time_t login_start_time; -time_t start_time; -time_t paste_time; -userec_t cuser; /* current user structure */ -userec_t xuser; /* lookup user structure */ -crosspost_t postrecord; /* anti cross post */ +int usernum; +int currmode = 0; +int curredit = 0; +int showansi = 1; +int paste_level; +int currbid; +char quote_file[80] = "\0"; +char quote_user[80] = "\0"; +char paste_title[STRLEN]; +char paste_path[256]; +char currtitle[TTLEN + 1] = "\0"; +char vetitle[TTLEN + 1] = "\0"; +char currowner[IDLEN + 2] = "\0"; +char currauthor[IDLEN + 2] = "\0"; +char currfile[FNLEN];/* current file name @ bbs.c mail.c */ +char currboard[IDLEN + 2]; +char currBM[IDLEN * 3 + 10]; +char reset_color[4] = "\033[m"; +char margs[64] = "\0"; /* main argv list */ +pid_t currpid; /* current process ID */ +time_t login_start_time; +time_t start_time; +time_t paste_time; +userec_t cuser; /* current user structure */ +userec_t xuser; /* lookup user structure */ +crosspost_t postrecord; /* anti cross post */ unsigned int currbrdattr; unsigned int currstat; -unsigned char currfmode; /* current file mode */ +unsigned char currfmode; /* current file mode */ /* global string variables */ /* filename */ -char *fn_passwd = FN_PASSWD; -char *fn_board = FN_BOARD; -char *fn_note_ans = FN_NOTE_ANS; -char *fn_register = "register.new"; -char *fn_plans = "plans"; -char *fn_writelog = "writelog"; -char *fn_talklog = "talklog"; -char *fn_overrides = FN_OVERRIDES; -char *fn_reject = FN_REJECT; -char *fn_canvote = FN_CANVOTE; -char *fn_notes = "notes"; -char *fn_water = FN_WATER; -char *fn_visable = FN_VISABLE; -char *fn_mandex = "/.Names"; -char *fn_proverb = "proverb"; +char *fn_passwd = FN_PASSWD; +char *fn_board = FN_BOARD; +char *fn_note_ans = FN_NOTE_ANS; +char *fn_register = "register.new"; +char *fn_plans = "plans"; +char *fn_writelog = "writelog"; +char *fn_talklog = "talklog"; +char *fn_overrides = FN_OVERRIDES; +char *fn_reject = FN_REJECT; +char *fn_canvote = FN_CANVOTE; +char *fn_notes = "notes"; +char *fn_water = FN_WATER; +char *fn_visable = FN_VISABLE; +char *fn_mandex = "/.Names"; +char *fn_proverb = "proverb"; /* are descript in userec.loginview */ -char *loginview_file[NUMVIEWFILE][2] = { - {FN_NOTE_ANS ,"酸甜苦辣流言板"}, - {FN_TOPSONG ,"點歌排行榜" }, - {"etc/topusr" ,"十大排行榜" }, - {"etc/topusr100" ,"百大排行榜" }, - {"etc/birth.today" ,"今日壽星" }, - {"etc/weather.tmp" ,"天氣快報" }, - {"etc/stock.tmp" ,"股市快報" }, - {"etc/day" ,"今日十大話題" }, - {"etc/week" ,"一週五十大話題"}, - {"etc/today" ,"今天上站人次" }, - {"etc/yesterday" ,"昨日上站人次" }, - {"etc/history" ,"歷史上的今天" }, - {"etc/topboardman" ,"精華區排行榜" }, - {"etc/topboard.tmp","看板人氣排行榜"} +char *loginview_file[NUMVIEWFILE][2] = { + {FN_NOTE_ANS, "酸甜苦辣流言板"}, + {FN_TOPSONG, "點歌排行榜"}, + {"etc/topusr", "十大排行榜"}, + {"etc/topusr100", "百大排行榜"}, + {"etc/birth.today", "今日壽星"}, + {"etc/weather.tmp", "天氣快報"}, + {"etc/stock.tmp", "股市快報"}, + {"etc/day", "今日十大話題"}, + {"etc/week", "一週五十大話題"}, + {"etc/today", "今天上站人次"}, + {"etc/yesterday", "昨日上站人次"}, + {"etc/history", "歷史上的今天"}, + {"etc/topboardman", "精華區排行榜"}, + {"etc/topboard.tmp", "看板人氣排行榜"} }; /* message */ -char *msg_seperator = MSG_SEPERATOR; -char *msg_mailer = MSG_MAILER; -char *msg_shortulist = MSG_SHORTULIST; - -char *msg_cancel = MSG_CANCEL; -char *msg_usr_left = MSG_USR_LEFT; -char *msg_nobody = MSG_NOBODY; - -char *msg_sure_ny = MSG_SURE_NY; -char *msg_sure_yn = MSG_SURE_YN; - -char *msg_bid = MSG_BID; -char *msg_uid = MSG_UID; - -char *msg_del_ok = MSG_DEL_OK; -char *msg_del_ny = MSG_DEL_NY; - -char *msg_fwd_ok = MSG_FWD_OK; -char *msg_fwd_err1 = MSG_FWD_ERR1; -char *msg_fwd_err2 = MSG_FWD_ERR2; - -char *err_board_update = ERR_BOARD_UPDATE; -char *err_bid = ERR_BID; -char *err_uid = ERR_UID; -char *err_filename = ERR_FILENAME; - -char *str_mail_address = "." BBSUSER "@" MYHOSTNAME; -char *str_new = "new"; -char *str_reply = "Re: "; -char *str_space = " \t\n\r"; -char *str_sysop = "SYSOP"; -char *str_author1 = STR_AUTHOR1; -char *str_author2 = STR_AUTHOR2; -char *str_post1 = STR_POST1; -char *str_post2 = STR_POST2; -char *BBSName = BBSNAME; +char *msg_seperator = MSG_SEPERATOR; +char *msg_mailer = MSG_MAILER; +char *msg_shortulist = MSG_SHORTULIST; + +char *msg_cancel = MSG_CANCEL; +char *msg_usr_left = MSG_USR_LEFT; +char *msg_nobody = MSG_NOBODY; + +char *msg_sure_ny = MSG_SURE_NY; +char *msg_sure_yn = MSG_SURE_YN; + +char *msg_bid = MSG_BID; +char *msg_uid = MSG_UID; + +char *msg_del_ok = MSG_DEL_OK; +char *msg_del_ny = MSG_DEL_NY; + +char *msg_fwd_ok = MSG_FWD_OK; +char *msg_fwd_err1 = MSG_FWD_ERR1; +char *msg_fwd_err2 = MSG_FWD_ERR2; + +char *err_board_update = ERR_BOARD_UPDATE; +char *err_bid = ERR_BID; +char *err_uid = ERR_UID; +char *err_filename = ERR_FILENAME; + +char *str_mail_address = "." BBSUSER "@" MYHOSTNAME; +char *str_new = "new"; +char *str_reply = "Re: "; +char *str_space = " \t\n\r"; +char *str_sysop = "SYSOP"; +char *str_author1 = STR_AUTHOR1; +char *str_author2 = STR_AUTHOR2; +char *str_post1 = STR_POST1; +char *str_post2 = STR_POST2; +char *BBSName = BBSNAME; /* #define MAX_MODES 78 */ /* MAX_MODES is defined in common.h */ -char *ModeTypeTable[MAX_MODES] = { - "發呆", /* IDLE */ - "主選單", /* MMENU */ - "系統維護", /* ADMIN */ - "郵件選單", /* MAIL */ - "交談選單", /* TMENU */ - "使用者選單", /* UMENU */ - "XYZ 選單", /* XMENU */ - "分類看板", /* CLASS */ - "Play選單", /* PMENU */ - "編特別名單", /* NMENU */ - "Ptt量販店", /* PSALE */ - "發表文章", /* POSTING */ - "看板列表", /* READBRD */ - "閱\讀文章", /* READING */ - "新文章列表", /* READNEW */ - "選擇看板", /* SELECT */ - "讀信", /* RMAIL */ - "寫信", /* SMAIL */ - "聊天室", /* CHATING */ - "其他", /* XMODE */ - "尋找好友", /* FRIEND */ - "上線使用者", /* LAUSERS */ - "使用者名單", /* LUSERS */ - "追蹤站友", /* MONITOR */ - "呼叫", /* PAGE */ - "查詢", /* TQUERY */ - "交談", /* TALK */ - "編名片檔", /* EDITPLAN */ - "編簽名檔", /* EDITSIG */ - "投票中", /* VOTING */ - "設定資料", /* XINFO */ - "寄給站長", /* MSYSOP */ - "汪汪汪", /* WWW */ - "打大老二", /* BIG2 */ - "回應", /* REPLY */ - "被水球打中", /* HIT */ - "水球準備中", /* DBACK */ - "筆記本", /* NOTE */ - "編輯文章", /* EDITING */ - "發系統通告", /* MAILALL */ - "摸兩圈", /* MJ */ - "電腦擇友", /* P_FRIEND */ - "上站途中", /* LOGIN */ - "查字典", /* DICT */ - "打橋牌", /* BRIDGE */ - "找檔案", /* ARCHIE */ - "打地鼠", /* GOPHER */ - "看News", /* NEWS */ - "情書產生器", /* LOVE */ - "編籍輔助器", /* EDITEXP */ - "申請IP位址", /* IPREG */ - "網管辦公中", /* NetAdm */ - "虛擬實業坊", /* DRINK */ - "計算機", /* CAL */ - "編籍座右銘", /* PROVERB */ - "公佈欄", /* ANNOUNCE */ - "刻流言板", /* EDNOTE */ - "英漢翻譯機", /* CDICT */ - "檢視自己物品", /* LOBJ */ - "點歌", /* OSONG */ - "正在玩小雞", /* CHICKEN */ - "玩彩券", /* TICKET */ - "猜數字", /* GUESSNUM */ - "遊樂場", /* AMUSE */ - "黑白棋", /* OTHELLO */ - "玩骰子", /* DICE*/ - "發票對獎", /* VICE */ - "逼逼摳ing", /* BBCALL */ - "繳罰單", /* CROSSPOST */ - "五子棋", /* M_FIVE */ - "21點ing", /* JACK_CARD */ - "10點半ing", /* TENHALF */ - "超級九十九", /* CARD_99 */ - "火車查詢", /* RAIL_WAY */ - "搜尋選單", /* SREG */ - "下象棋", /* CHC */ - "下暗琪", /* DARK */ - "NBA大猜測" /* TMPJACK */ - "Ptt查榜系統", /* JCEE */ - "重編文章" /* REEDIT */ +char *ModeTypeTable[MAX_MODES] = { + "發呆", /* IDLE */ + "主選單", /* MMENU */ + "系統維護", /* ADMIN */ + "郵件選單", /* MAIL */ + "交談選單", /* TMENU */ + "使用者選單", /* UMENU */ + "XYZ 選單", /* XMENU */ + "分類看板", /* CLASS */ + "Play選單", /* PMENU */ + "編特別名單", /* NMENU */ + "Ptt量販店", /* PSALE */ + "發表文章", /* POSTING */ + "看板列表", /* READBRD */ + "閱\讀文章", /* READING */ + "新文章列表", /* READNEW */ + "選擇看板", /* SELECT */ + "讀信", /* RMAIL */ + "寫信", /* SMAIL */ + "聊天室", /* CHATING */ + "其他", /* XMODE */ + "尋找好友", /* FRIEND */ + "上線使用者", /* LAUSERS */ + "使用者名單", /* LUSERS */ + "追蹤站友", /* MONITOR */ + "呼叫", /* PAGE */ + "查詢", /* TQUERY */ + "交談", /* TALK */ + "編名片檔", /* EDITPLAN */ + "編簽名檔", /* EDITSIG */ + "投票中", /* VOTING */ + "設定資料", /* XINFO */ + "寄給站長", /* MSYSOP */ + "汪汪汪", /* WWW */ + "打大老二", /* BIG2 */ + "回應", /* REPLY */ + "被水球打中", /* HIT */ + "水球準備中", /* DBACK */ + "筆記本", /* NOTE */ + "編輯文章", /* EDITING */ + "發系統通告", /* MAILALL */ + "摸兩圈", /* MJ */ + "電腦擇友", /* P_FRIEND */ + "上站途中", /* LOGIN */ + "查字典", /* DICT */ + "打橋牌", /* BRIDGE */ + "找檔案", /* ARCHIE */ + "打地鼠", /* GOPHER */ + "看News", /* NEWS */ + "情書產生器", /* LOVE */ + "編籍輔助器", /* EDITEXP */ + "申請IP位址", /* IPREG */ + "網管辦公中", /* NetAdm */ + "虛擬實業坊", /* DRINK */ + "計算機", /* CAL */ + "編籍座右銘", /* PROVERB */ + "公佈欄", /* ANNOUNCE */ + "刻流言板", /* EDNOTE */ + "英漢翻譯機", /* CDICT */ + "檢視自己物品", /* LOBJ */ + "點歌", /* OSONG */ + "正在玩小雞", /* CHICKEN */ + "玩彩券", /* TICKET */ + "猜數字", /* GUESSNUM */ + "遊樂場", /* AMUSE */ + "黑白棋", /* OTHELLO */ + "玩骰子", /* DICE */ + "發票對獎", /* VICE */ + "逼逼摳ing", /* BBCALL */ + "繳罰單", /* CROSSPOST */ + "五子棋", /* M_FIVE */ + "21點ing", /* JACK_CARD */ + "10點半ing", /* TENHALF */ + "超級九十九", /* CARD_99 */ + "火車查詢", /* RAIL_WAY */ + "搜尋選單", /* SREG */ + "下象棋", /* CHC */ + "下暗琪", /* DARK */ + "NBA大猜測" /* TMPJACK */ + "Ptt查榜系統", /* JCEE */ + "重編文章" /* REEDIT */ }; /* indict.c */ -char dict[41], database[41]; +char dict[41], database[41]; /* term.c */ -int b_lines = 23; -int t_lines = 24; -int p_lines = 20; -int t_columns = 80; -char *strtstandout = "\33[7m"; -int strtstandoutlen = 4; -char *endstandout = "\33[m"; -int endstandoutlen = 3; -char *clearbuf = "\33[H\33[J"; -int clearbuflen = 6; -char *cleolbuf = "\33[K"; -int cleolbuflen = 3; -char *scrollrev = "\33M"; -int scrollrevlen = 2; -int automargins = 1; +int b_lines = 23; +int t_lines = 24; +int p_lines = 20; +int t_columns = 80; +char *strtstandout = "\33[7m"; +int strtstandoutlen = 4; +char *endstandout = "\33[m"; +int endstandoutlen = 3; +char *clearbuf = "\33[H\33[J"; +int clearbuflen = 6; +char *cleolbuf = "\33[K"; +int cleolbuflen = 3; +char *scrollrev = "\33M"; +int scrollrevlen = 2; +int automargins = 1; /* io.c */ -time_t now; -int KEY_ESC_arg; -int watermode = -1; -int wmofo = -1; +time_t now; +int KEY_ESC_arg; +int watermode = -1; +int wmofo = -1; /* - WATERMODE(WATER_ORIG) | WATERMODE(WATER_NEW): - Ptt 水球回顧用的參數 - watermode = -1 沒在回水球 - = 0 在回上一顆水球 (Ctrl-R) - > 0 在回前 n 顆水球 (Ctrl-R Ctrl-R) - - WATERMODE(WATER_OFO) by in2 - wmofo = -1 沒在回水球 - = 0 正在回水球 - = 1 回水球間又接到水球 - wmofo >=0 時收到水球將只顯示, 不會到water[]裡, - 待回完水球的時候一次寫入. -*/ + * WATERMODE(WATER_ORIG) | WATERMODE(WATER_NEW): Ptt 水球回顧 + * e = -1 沒在回水球 = 0 在回上一顆水球 (Ctrl-R) > 0 在回前 n 顆水球 + * (Ctrl-R Ctrl-R) + * + * WATERMODE(WATER_OFO) by in2 wmofo = -1 沒在回水球 = 0 正在回水球 = 1 + * 回水球間又接到水球 wmofo >=0 時收到水球將只顯示, 不會到water[]裡, + * 待回完水球的時候一次寫入. + */ /* cache.c */ -int numboards = -1; -int *GLOBALVAR; -SHM_t *SHM; -boardheader_t *bcache; -userinfo_t *currutmp; +int numboards = -1; +int *GLOBALVAR; +SHM_t *SHM; +boardheader_t *bcache; +userinfo_t *currutmp; /* board.c */ -int class_bid = 0; -int brc_num; -int brc_list[BRC_MAXNUM]; +int class_bid = 0; +int brc_num; +int brc_list[BRC_MAXNUM]; /* read.c */ -int TagNum; /* tag's number */ -TagItem TagList[MAXTAGS]; /* ascending list */ -char currdirect[64]; +int TagNum; /* tag's number */ +TagItem TagList[MAXTAGS]; /* ascending list */ +char currdirect[64]; /* edit.c */ -char save_title[STRLEN]; +char save_title[STRLEN]; /* bbs.c */ -time_t board_visit_time; -char real_name[IDLEN + 1]; -int local_article; +time_t board_visit_time; +char real_name[IDLEN + 1]; +int local_article; /* mbbsd.c */ -int talkrequest = NA; -char fromhost[STRLEN] = "\0"; -char water_usies = 0; -FILE *fp_writelog = NULL; -water_t water[6], *swater[6], *water_which = &water[0]; +int talkrequest = NA; +char fromhost[STRLEN] = "\0"; +char water_usies = 0; +FILE *fp_writelog = NULL; +water_t water[6], *swater[6], *water_which = &water[0]; /* announce.c */ -char trans_buffer[256]; +char trans_buffer[256]; /* chc_play.c */ -rc_t chc_from, chc_to, chc_select, chc_cursor; -int chc_lefttime; -int chc_my, chc_turn, chc_selected, chc_firststep; -char chc_warnmsg[64], *chc_mateid; -int chc_hiswin, chc_hislose, chc_histie; +rc_t chc_from, chc_to, chc_select, chc_cursor; +int chc_lefttime; +int chc_my, chc_turn, chc_selected, chc_firststep; +char chc_warnmsg[64], *chc_mateid; +int chc_hiswin, chc_hislose, chc_histie; /* screen.c */ -screenline_t *big_picture = NULL; +screenline_t *big_picture = NULL; unsigned char scr_lns, scr_cols; /* gomo.c */ -char ku[BRDSIZ][BRDSIZ]; -unsigned char *pat, *adv; -unsigned char *pat_gomoku /* [1954] */ = -/* 0 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" -/* 16 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x44\x55\xcc\x00\x00\x00\x00" -/* 32 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x33\x00\x44\x00\x33\x00\x00\x00" -/* 48 */ "\x00\x22\x00\x55\x00\x22\x00\x00\x00\x44\x33\x66\x55\xcc\x33\x66" -/* 64 */ "\x55\xcc\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x03\x00\x00\x00" -/* 80 */ "\x55\x00\x55\x00\x05\x00\x55\x02\x46\x00\xaa\x00\x00\x55\x00\x55" -/* 96 */ "\x00\x05\x00\x55\x00\x05\x00\x55\x00\x00\x44\xcc\x44\xcc\x05\xbb" -/* 112 */ "\x44\xcc\x05\xbb\x44\xcc\x05\xbb\x00\x00\x00\x00\x00\x00\x00\x00" -/* 128 */ "\x00\x00\x33\x00\x00\x00\x44\x00\x00\x00\x00\x00\x33\x00\x44\x00" -/* 144 */ "\x33\x22\x66\x00\x55\x55\xcc\x00\x33\x00\x00\x00\x00\x22\x00\x55" -/* 160 */ "\x00\x22\x00\x55\x00\x02\x00\x05\x00\x22\x00\x00\x33\x44\x33\x66" -/* 176 */ "\x55\xcc\x33\x66\x55\xcc\x33\x46\x05\xbb\x33\x66\x55\xcc\x00\x00" -/* 192 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x03\x00\x00\x00\x44\x00\x00\x00" -/* 208 */ "\x33\x00\x00\x22\x55\x22\x55\x02\x05\x22\x55\x02\x46\x22\xaa\x55" -/* 224 */ "\xcc\x22\x55\x02\x46\x22\xaa\x00\x22\x55\x22\x55\x02\x05\x22\x55" -/* 240 */ "\x02\x05\x22\x55\x02\x05\x22\x55\x02\x05\x22\x55\x02\x44\x66\xcc" -/* 256 */ "\x66\xcc\x46\xbb\x66\xcc\x46\xbb\x66\xcc\x46\xbb\x66\xcc\x46\xbb" -/* 272 */ "\x66\xcc\x46\xbb\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x33\x00" -/* 288 */ "\x00\x00\x44\x00\x00\x00\x33\x00\x22\x22\x66\x00\x00\x00\x00\x00" -/* 304 */ "\x03\x00\x44\x00\x33\x22\x66\x00\x55\x55\xcc\x00\x33\x22\x66\x00" -/* 320 */ "\x55\x55\xcc\x00\x03\x00\x00\x00\x00\x02\x00\x55\x00\x02\x00\x55" -/* 336 */ "\x00\x02\x00\x05\x00\x02\x00\x55\x00\x02\x02\x46\x00\x02\x00\x55" -/* 352 */ "\x55\x05\x55\x46\xaa\xcc\x55\x46\xaa\xcc\x55\x06\x5a\xbb\x55\x46" -/* 368 */ "\xaa\xcc\x55\x06\x5a\xbb\x55\x46\xaa\xcc\x00\x00\x00\x00\x00\x00" -/* 384 */ "\x00\x00\x00\x00\x03\x00\x00\x00\x44\x00\x00\x00\x33\x00\x22\x22" -/* 400 */ "\x66\x00\x00\x00\x55\x00\x55\x55\x05\x55\x05\x55\x05\x55\x05\x55" -/* 416 */ "\x46\x55\x5a\xaa\xcc\x55\x05\x55\x46\x55\x5a\xaa\xcc\x55\x05\x55" -/* 432 */ "\x06\x55\x0a\x55\x55\x05\x55\x05\x55\x05\x55\x05\x55\x05\x55\x05" -/* 448 */ "\x55\x05\x55\x05\x55\x05\x55\x05\x55\x46\x55\x05\x55\x5a\x55\x5a" -/* 464 */ "\xaa\xcc\xcc\xbb\xcc\xbb\xcc\xbb\xcc\xbb\xcc\xbb\xcc\xbb\xcc\xbb" -/* 480 */ "\xcc\xbb\xcc\xbb\xcc\xbb\xcc\xbb\xcc\xbb\xcc\xbb\xcc\xbb\xcc\xbb" -/* 496 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x33\x00\x00\x00\x44\x00" -/* 512 */ "\x00\x00\x33\x00\x22\x22\x66\x00\x00\x00\x55\x00\x55\x55\xcc\x00" -/* 528 */ "\x00\x00\x00\x00\x33\x00\x44\x00\x33\x22\x66\x00\x55\x55\xcc\x00" -/* 544 */ "\x33\x22\x66\x00\x55\x55\xcc\x00\x33\x02\x46\x00\x05\x05\xbb\x00" -/* 560 */ "\x33\x00\x00\x00\x00\x22\x00\x55\x00\x22\x00\x55\x00\x02\x00\x05" -/* 576 */ "\x00\x22\x00\x55\x00\x02\x02\x46\x00\x22\x00\xaa\x00\x55\x55\xcc" -/* 592 */ "\x00\x22\x00\x00\x33\x44\x33\x66\x55\xcc\x33\x66\x55\xcc\x33\x46" -/* 608 */ "\x05\xbb\x33\x66\x55\xcc\x33\x46\x05\xbb\x33\x66\x55\xcc\x33\x46" -/* 624 */ "\x05\xbb\x33\x66\x55\xcc\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" -/* 640 */ "\x03\x00\x00\x00\x44\x00\x00\x00\x33\x00\x22\x22\x66\x00\x00\x00" -/* 656 */ "\x55\x00\x55\x55\xcc\x00\x00\x00\x33\x00\x00\x22\x55\x22\x55\x02" -/* 672 */ "\x05\x22\x55\x02\x46\x22\xaa\x55\xcc\x22\x55\x02\x46\x22\xaa\x55" -/* 688 */ "\xcc\x22\x55\x02\x06\x22\x5a\x05\xbb\x22\x55\x02\x46\x22\xaa\x00" -/* 704 */ "\x22\x55\x22\x55\x02\x05\x22\x55\x02\x05\x22\x55\x02\x05\x22\x55" -/* 720 */ "\x02\x05\x22\x55\x02\x46\x22\x55\x02\x5a\x22\xaa\x55\xcc\x22\x55" -/* 736 */ "\x02\x05\x22\x55\x02\x44\x66\xcc\x66\xcc\x46\xbb\x66\xcc\x46\xbb" -/* 752 */ "\x66\xcc\x46\xbb\x66\xcc\x46\xbb\x66\xcc\x46\xbb\x66\xcc\x46\xbb" -/* 768 */ "\x66\xcc\x46\xbb\x66\xcc\x46\xbb\x66\xcc\x46\xbb\x00\x00\x00\x00" -/* 784 */ "\x00\x00\x00\x00\x00\x00\x33\x00\x00\x00\x44\x00\x00\x00\x33\x00" -/* 800 */ "\x22\x22\x66\x00\x00\x00\x55\x00\x55\x55\xcc\x00\x00\x00\x33\x00" -/* 816 */ "\x22\x22\x66\x00\x00\x00\x00\x00\x03\x00\x44\x00\x33\x22\x66\x00" -/* 832 */ "\x55\x55\xcc\x00\x33\x22\x66\x00\x55\x55\xcc\x00\x03\x02\x46\x00" -/* 848 */ "\x05\x05\xbb\x00\x33\x22\x66\x00\x55\x55\xcc\x00\x03\x00\x00\x00" -/* 864 */ "\x00\x02\x00\x55\x00\x02\x00\x55\x00\x02\x00\x05\x00\x02\x00\x55" -/* 880 */ "\x00\x02\x02\x46\x00\x02\x00\xaa\x00\x55\x55\xcc\x00\x02\x00\x55" -/* 896 */ "\x00\x02\x02\x46\x00\x02\x00\x55\x55\x05\x55\x46\xaa\xcc\x55\x46" -/* 912 */ "\xaa\xcc\x55\x06\x5a\xbb\x55\x46\xaa\xcc\x55\x06\x5a\xbb\x55\x46" -/* 928 */ "\xaa\xcc\x55\x06\x5a\xbb\x55\x46\xaa\xcc\x55\x06\x5a\xbb\x55\x46" -/* 944 */ "\xaa\xcc\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x03\x00\x00\x00" -/* 960 */ "\x44\x00\x00\x00\x33\x00\x22\x22\x66\x00\x00\x00\x55\x00\x55\x55" -/* 976 */ "\xcc\x00\x00\x00\x33\x00\x22\x22\x66\x00\x00\x00\x55\x00\x55\x55" -/* 992 */ "\x05\x55\x05\x55\x05\x55\x05\x55\x46\x55\x5a\xaa\xcc\x55\x05\x55" -/* 1008 */ "\x46\x55\x5a\xaa\xcc\x55\x05\x55\x06\x55\x0a\x5a\xbb\x55\x05\x55" -/* 1024 */ "\x46\x55\x5a\xaa\xcc\x55\x05\x55\x06\x55\x0a\x55\x55\x05\x55\x05" -/* 1040 */ "\x55\x05\x55\x05\x55\x05\x55\x05\x55\x05\x55\x05\x55\x05\x55\x05" -/* 1056 */ "\x55\x46\x55\x05\x55\x5a\x55\x5a\xaa\xcc\x55\x05\x55\x05\x55\x05" -/* 1072 */ "\x55\x46\x55\x05\x55\x5a\x55\x5a\xaa\xcc\xcc\xbb\xcc\xbb\xcc\xbb" -/* 1088 */ "\xcc\xbb\xcc\xbb\xcc\xbb\xcc\xbb\xcc\xbb\xcc\xbb\xcc\xbb\xcc\xbb" -/* 1104 */ "\xcc\xbb\xcc\xbb\xcc\xbb\xcc\xbb\xcc\xbb\xcc\xbb\xcc\xbb\xcc\xbb" -/* 1120 */ "\xcc\xbb\xcc\xbb\xcc\xbb\xcc\xbb\x00\x00\x00\x00\x00\x00\x00\x00" -/* 1136 */ "\x00\x00\x33\x00\x00\x00\x44\x00\x00\x00\x33\x00\x22\x22\x66\x00" -/* 1152 */ "\x00\x00\x55\x00\x55\x55\xcc\x00\x00\x00\x33\x00\x22\x22\x66\x00" -/* 1168 */ "\x00\x00\x55\x00\x55\x55\xcc\x00\x00\x00\x00\x00\x33\x00\x44\x00" -/* 1184 */ "\x33\x22\x66\x00\x55\x55\xcc\x00\x33\x22\x66\x00\x55\x55\xcc\x00" -/* 1200 */ "\x33\x02\x46\x00\x05\x05\xbb\x00\x33\x22\x66\x00\x55\x55\xcc\x00" -/* 1216 */ "\x33\x02\x46\x00\x05\x05\xbb\x00\x33\x00\x00\x00\x00\x22\x00\x55" -/* 1232 */ "\x00\x22\x00\x55\x00\x02\x00\x05\x00\x22\x00\x55\x00\x02\x02\x46" -/* 1248 */ "\x00\x22\x00\xaa\x00\x55\x55\xcc\x00\x22\x00\x55\x00\x02\x02\x46" -/* 1264 */ "\x00\x22\x00\xaa\x00\x55\x55\xcc\x00\x22\x00\x00\x03\x44\x33\x66" -/* 1280 */ "\x55\xcc\x33\x66\x55\xcc\x03\x46\x05\xbb\x33\x66\x55\xcc\x03\x46" -/* 1296 */ "\x05\xbb\x33\x66\x55\xcc\x03\x46\x05\xbb\x33\x66\x55\xcc\x03\x46" -/* 1312 */ "\x05\xbb\x33\x66\x55\xcc\x03\x46\x05\xbb\x33\x66\x55\xcc\x00\x00" -/* 1328 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x03\x00\x00\x00\x44\x00\x00\x00" -/* 1344 */ "\x33\x00\x22\x22\x66\x00\x00\x00\x55\x00\x55\x55\xcc\x00\x00\x00" -/* 1360 */ "\x33\x00\x22\x22\x66\x00\x00\x00\x55\x00\x55\x55\xcc\x00\x00\x00" -/* 1376 */ "\x03\x00\x00\x02\x55\x02\x55\x02\x05\x02\x55\x02\x46\x02\xaa\x55" -/* 1392 */ "\xcc\x02\x55\x02\x46\x02\xaa\x55\xcc\x02\x55\x02\x06\x02\x5a\x05" -/* 1408 */ "\xbb\x02\x55\x02\x46\x02\xaa\x55\xcc\x02\x55\x02\x06\x02\x5a\x05" -/* 1424 */ "\xbb\x02\x55\x02\x46\x02\xaa\x00\x02\x55\x02\x55\x02\x05\x02\x55" -/* 1440 */ "\x02\x05\x02\x55\x02\x05\x02\x55\x02\x05\x02\x55\x02\x46\x02\x55" -/* 1456 */ "\x02\x5a\x02\xaa\x55\xcc\x02\x55\x02\x05\x02\x55\x02\x46\x02\x55" -/* 1472 */ "\x02\x5a\x02\xaa\x55\xcc\x02\x55\x02\x05\x02\x55\x02\x05\x46\xcc" -/* 1488 */ "\x46\xcc\x06\xbb\x46\xcc\x06\xbb\x46\xcc\x06\xbb\x46\xcc\x06\xbb" -/* 1504 */ "\x46\xcc\x06\xbb\x46\xcc\x06\xbb\x46\xcc\x06\xbb\x46\xcc\x06\xbb" -/* 1520 */ "\x46\xcc\x06\xbb\x46\xcc\x06\xbb\x46\xcc\x06\xbb\x46\xcc\x06\xbb" -/* 1536 */ "\x46\xcc\x06\xbb\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x33\x00" -/* 1552 */ "\x00\x00\x44\x00\x00\x00\x33\x00\x22\x22\x66\x00\x00\x00\x55\x00" -/* 1568 */ "\x55\x55\xcc\x00\x00\x00\x33\x00\x22\x22\x66\x00\x00\x00\x55\x00" -/* 1584 */ "\x55\x55\xcc\x00\x00\x00\x33\x00\x02\x02\x46\x00\x00\x00\x00\x00" -/* 1600 */ "\x03\x00\x44\x00\x33\x22\x66\x00\x55\x55\xcc\x00\x33\x22\x66\x00" -/* 1616 */ "\x55\x55\xcc\x00\x03\x02\x46\x00\x05\x05\xbb\x00\x33\x22\x66\x00" -/* 1632 */ "\x55\x55\xcc\x00\x03\x02\x46\x00\x05\x05\xbb\x00\x33\x22\x66\x00" -/* 1648 */ "\x55\x55\xcc\x00\x03\x00\x00\x00\x00\x02\x00\x55\x00\x02\x00\x55" -/* 1664 */ "\x00\x02\x00\x05\x00\x02\x00\x55\x00\x02\x02\x46\x00\x02\x00\xaa" -/* 1680 */ "\x00\x55\x55\xcc\x00\x02\x00\x55\x00\x02\x02\x46\x00\x02\x00\xaa" -/* 1696 */ "\x00\x55\x55\xcc\x00\x02\x00\x55\x00\x02\x02\x06\x00\x02\x00\x05" -/* 1712 */ "\x05\x05\x05\x46\x5a\xcc\x05\x46\x5a\xcc\x05\x06\x0a\xbb\x05\x46" -/* 1728 */ "\x5a\xcc\x05\x06\x0a\xbb\x05\x46\x5a\xcc\x05\x06\x0a\xbb\x05\x46" -/* 1744 */ "\x5a\xcc\x05\x06\x0a\xbb\x05\x46\x5a\xcc\x05\x06\x0a\xbb\x05\x46" -/* 1760 */ "\x5a\xcc\x05\x06\x0a\xbb\x05\x46\x5a\xcc\x00\x00\x00\x00\x00\x00" -/* 1776 */ "\x00\x00\x00\x00\x03\x00\x00\x00\x44\x00\x00\x00\x33\x00\x22\x22" -/* 1792 */ "\x66\x00\x00\x00\x55\x00\x55\x55\xcc\x00\x00\x00\x33\x00\x22\x22" -/* 1808 */ "\x66\x00\x00\x00\x55\x00\x55\x55\xcc\x00\x00\x00\x03\x00\x02\x02" -/* 1824 */ "\x46\x00\x00\x00\x05\x00\x05\x05\x05\x05\x05\x05\x05\x05\x05\x05" -/* 1840 */ "\x46\x05\x5a\x5a\xcc\x05\x05\x05\x46\x05\x5a\x5a\xcc\x05\x05\x05" -/* 1856 */ "\x06\x05\x0a\x0a\xbb\x05\x05\x05\x46\x05\x5a\x5a\xcc\x05\x05\x05" -/* 1872 */ "\x06\x05\x0a\x0a\xbb\x05\x05\x05\x46\x05\x5a\x5a\xcc\x05\x05\x05" -/* 1888 */ "\x06\x05\x0a\x05\x05\x05\x05\x05\x05\x05\x05\x05\x05\x05\x05\x05" -/* 1904 */ "\x05\x05\x05\x05\x05\x05\x05\x05\x05\x46\x05\x05\x05\x5a\x05\x5a" -/* 1920 */ "\x5a\xcc\x05\x05\x05\x05\x05\x05\x05\x46\x05\x05\x05\x5a\x05\x5a" -/* 1936 */ "\x5a\xcc\x05\x05\x05\x05\x05\x05\x05\x06\x05\x05\x05\x0a\x05\x0a" -/* 1952 */ "\x0a"; - -unsigned char *adv_gomoku /* [978] */ = -/* 0 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" -/* 16 */ "\x00\x00\x00\x00\xa0\x00\xa0\x00\x04\x00\x04\x00\x00\xd0\x00\xd0" -/* 32 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" -/* 48 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" -/* 64 */ "\x00\x70\x00\x00\x00\x00\xa0\x00\xa1\x00\x00\x00\xa0\x00\x04\x00" -/* 80 */ "\x04\x00\x00\x00\x04\x00\xd0\xd0\x00\xd0\x00\xd0\x00\xd0\x00\x00" -/* 96 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x70\x08\x08\x00\x08\x00\x08\x00" -/* 112 */ "\x08\x00\x08\x00\x40\x40\x00\x40\x00\x40\x00\x40\x00\x40\x00\x00" -/* 128 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x70" -/* 144 */ "\x00\x00\x00\x70\x21\x00\x00\x00\x00\x00\xa1\x00\x00\x00\xa1\x00" -/* 160 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" -/* 176 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" -/* 192 */ "\x00\x00\x00\x00\x00\x00\x70\x21\x00\x00\x00\x00\x00\x00\x00\x00" -/* 208 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" -/* 224 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" -/* 240 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x70\x00\x00" -/* 256 */ "\x00\x70\x21\x00\x00\x00\x00\x00\x00\x00\xa0\x00\xa1\x00\x00\x00" -/* 272 */ "\xa1\x00\x00\x00\xa0\x00\x00\x00\xa0\x00\x04\x00\x04\x00\x00\x00" -/* 288 */ "\x04\x00\x00\x00\x04\x00\x00\x00\x04\x00\xd0\xd0\x00\xd0\x00\xd0" -/* 304 */ "\x00\xd0\x00\xd0\x00\xd0\x00\xd0\x00\xd0\x00\x00\x00\x00\x00\x00" -/* 320 */ "\x00\x00\x00\x00\x70\x21\x00\x00\x00\x00\x00\x00\x70\x08\x08\x00" -/* 336 */ "\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00" -/* 352 */ "\x40\x40\x00\x40\x00\x40\x00\x40\x00\x40\x00\x40\x00\x40\x00\x40" -/* 368 */ "\x00\x40\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" -/* 384 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x70\x00\x00\x00\x70" -/* 400 */ "\x21\x00\x00\x00\x00\x00\x00\x70\x21\x00\x00\x00\x00\x00\xa1\x00" -/* 416 */ "\x00\x00\xa1\x00\x00\x00\x00\x00\x00\x00\xa1\x00\x00\x00\x00\x00" -/* 432 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" -/* 448 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" -/* 464 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" -/* 480 */ "\x00\x00\x70\x21\x00\x00\x00\x00\x00\x00\x70\x21\x00\x00\x00\x00" -/* 496 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" -/* 512 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" -/* 528 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" -/* 544 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" -/* 560 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x70\x00\x00\x00\x70\x21\x00" -/* 576 */ "\x00\x00\x00\x00\x00\x70\x21\x00\x00\x00\x00\x00\x00\x00\xa0\x00" -/* 592 */ "\xa1\x00\x00\x00\xa1\x00\x00\x00\xa0\x00\x00\x00\xa1\x00\x00\x00" -/* 608 */ "\xa0\x00\x00\x00\xa0\x00\x04\x00\x04\x00\x00\x00\x04\x00\x00\x00" -/* 624 */ "\x04\x00\x00\x00\x04\x00\x00\x00\x04\x00\x00\x00\x04\x00\x00\xd0" -/* 640 */ "\x00\xd0\x00\x00\x00\xd0\x00\x00\x00\xd0\x00\x00\x00\xd0\x00\x00" -/* 656 */ "\x00\xd0\x00\x00\x00\xd0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" -/* 672 */ "\x70\x21\x00\x00\x00\x00\x00\x00\x70\x21\x00\x00\x00\x00\x00\x00" -/* 688 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" -/* 704 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" -/* 720 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" -/* 736 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" -/* 752 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" -/* 768 */ "\x00\x00\x00\x00\x00\x00\x00\x70\x00\x00\x00\x70\x21\x00\x00\x00" -/* 784 */ "\x00\x00\x00\x70\x21\x00\x00\x00\x00\x00\x00\x70\x00\x00\x00\x00" -/* 800 */ "\x00\x00\xa1\x00\x00\x00\xa1\x00\x00\x00\x00\x00\x00\x00\xa1\x00" -/* 816 */ "\x00\x00\x00\x00\x00\x00\xa1\x00\x00\x00\x00\x00\x00\x00\x00\x00" -/* 832 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" -/* 848 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" -/* 864 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" -/* 880 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x70\x21" -/* 896 */ "\x00\x00\x00\x00\x00\x00\x70\x21\x00\x00\x00\x00\x00\x00\x00\x00" -/* 912 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" -/* 928 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" -/* 944 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" -/* 960 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" -/* 976 */ "\x00"; +char ku[BRDSIZ][BRDSIZ]; +unsigned char *pat, *adv; +unsigned char *pat_gomoku /* [1954] */ = + /* 0 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" + /* 16 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x44\x55\xcc\x00\x00\x00\x00" + /* 32 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x33\x00\x44\x00\x33\x00\x00\x00" + /* 48 */ "\x00\x22\x00\x55\x00\x22\x00\x00\x00\x44\x33\x66\x55\xcc\x33\x66" + /* 64 */ "\x55\xcc\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x03\x00\x00\x00" + /* 80 */ "\x55\x00\x55\x00\x05\x00\x55\x02\x46\x00\xaa\x00\x00\x55\x00\x55" + /* 96 */ "\x00\x05\x00\x55\x00\x05\x00\x55\x00\x00\x44\xcc\x44\xcc\x05\xbb" + /* 112 */ "\x44\xcc\x05\xbb\x44\xcc\x05\xbb\x00\x00\x00\x00\x00\x00\x00\x00" + /* 128 */ "\x00\x00\x33\x00\x00\x00\x44\x00\x00\x00\x00\x00\x33\x00\x44\x00" + /* 144 */ "\x33\x22\x66\x00\x55\x55\xcc\x00\x33\x00\x00\x00\x00\x22\x00\x55" + /* 160 */ "\x00\x22\x00\x55\x00\x02\x00\x05\x00\x22\x00\x00\x33\x44\x33\x66" + /* 176 */ "\x55\xcc\x33\x66\x55\xcc\x33\x46\x05\xbb\x33\x66\x55\xcc\x00\x00" + /* 192 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x03\x00\x00\x00\x44\x00\x00\x00" + /* 208 */ "\x33\x00\x00\x22\x55\x22\x55\x02\x05\x22\x55\x02\x46\x22\xaa\x55" + /* 224 */ "\xcc\x22\x55\x02\x46\x22\xaa\x00\x22\x55\x22\x55\x02\x05\x22\x55" + /* 240 */ "\x02\x05\x22\x55\x02\x05\x22\x55\x02\x05\x22\x55\x02\x44\x66\xcc" + /* 256 */ "\x66\xcc\x46\xbb\x66\xcc\x46\xbb\x66\xcc\x46\xbb\x66\xcc\x46\xbb" + /* 272 */ "\x66\xcc\x46\xbb\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x33\x00" + /* 288 */ "\x00\x00\x44\x00\x00\x00\x33\x00\x22\x22\x66\x00\x00\x00\x00\x00" + /* 304 */ "\x03\x00\x44\x00\x33\x22\x66\x00\x55\x55\xcc\x00\x33\x22\x66\x00" + /* 320 */ "\x55\x55\xcc\x00\x03\x00\x00\x00\x00\x02\x00\x55\x00\x02\x00\x55" + /* 336 */ "\x00\x02\x00\x05\x00\x02\x00\x55\x00\x02\x02\x46\x00\x02\x00\x55" + /* 352 */ "\x55\x05\x55\x46\xaa\xcc\x55\x46\xaa\xcc\x55\x06\x5a\xbb\x55\x46" + /* 368 */ "\xaa\xcc\x55\x06\x5a\xbb\x55\x46\xaa\xcc\x00\x00\x00\x00\x00\x00" + /* 384 */ "\x00\x00\x00\x00\x03\x00\x00\x00\x44\x00\x00\x00\x33\x00\x22\x22" + /* 400 */ "\x66\x00\x00\x00\x55\x00\x55\x55\x05\x55\x05\x55\x05\x55\x05\x55" + /* 416 */ "\x46\x55\x5a\xaa\xcc\x55\x05\x55\x46\x55\x5a\xaa\xcc\x55\x05\x55" + /* 432 */ "\x06\x55\x0a\x55\x55\x05\x55\x05\x55\x05\x55\x05\x55\x05\x55\x05" + /* 448 */ "\x55\x05\x55\x05\x55\x05\x55\x05\x55\x46\x55\x05\x55\x5a\x55\x5a" + /* 464 */ "\xaa\xcc\xcc\xbb\xcc\xbb\xcc\xbb\xcc\xbb\xcc\xbb\xcc\xbb\xcc\xbb" + /* 480 */ "\xcc\xbb\xcc\xbb\xcc\xbb\xcc\xbb\xcc\xbb\xcc\xbb\xcc\xbb\xcc\xbb" + /* 496 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x33\x00\x00\x00\x44\x00" + /* 512 */ "\x00\x00\x33\x00\x22\x22\x66\x00\x00\x00\x55\x00\x55\x55\xcc\x00" + /* 528 */ "\x00\x00\x00\x00\x33\x00\x44\x00\x33\x22\x66\x00\x55\x55\xcc\x00" + /* 544 */ "\x33\x22\x66\x00\x55\x55\xcc\x00\x33\x02\x46\x00\x05\x05\xbb\x00" + /* 560 */ "\x33\x00\x00\x00\x00\x22\x00\x55\x00\x22\x00\x55\x00\x02\x00\x05" + /* 576 */ "\x00\x22\x00\x55\x00\x02\x02\x46\x00\x22\x00\xaa\x00\x55\x55\xcc" + /* 592 */ "\x00\x22\x00\x00\x33\x44\x33\x66\x55\xcc\x33\x66\x55\xcc\x33\x46" + /* 608 */ "\x05\xbb\x33\x66\x55\xcc\x33\x46\x05\xbb\x33\x66\x55\xcc\x33\x46" + /* 624 */ "\x05\xbb\x33\x66\x55\xcc\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" + /* 640 */ "\x03\x00\x00\x00\x44\x00\x00\x00\x33\x00\x22\x22\x66\x00\x00\x00" + /* 656 */ "\x55\x00\x55\x55\xcc\x00\x00\x00\x33\x00\x00\x22\x55\x22\x55\x02" + /* 672 */ "\x05\x22\x55\x02\x46\x22\xaa\x55\xcc\x22\x55\x02\x46\x22\xaa\x55" + /* 688 */ "\xcc\x22\x55\x02\x06\x22\x5a\x05\xbb\x22\x55\x02\x46\x22\xaa\x00" + /* 704 */ "\x22\x55\x22\x55\x02\x05\x22\x55\x02\x05\x22\x55\x02\x05\x22\x55" + /* 720 */ "\x02\x05\x22\x55\x02\x46\x22\x55\x02\x5a\x22\xaa\x55\xcc\x22\x55" + /* 736 */ "\x02\x05\x22\x55\x02\x44\x66\xcc\x66\xcc\x46\xbb\x66\xcc\x46\xbb" + /* 752 */ "\x66\xcc\x46\xbb\x66\xcc\x46\xbb\x66\xcc\x46\xbb\x66\xcc\x46\xbb" + /* 768 */ "\x66\xcc\x46\xbb\x66\xcc\x46\xbb\x66\xcc\x46\xbb\x00\x00\x00\x00" + /* 784 */ "\x00\x00\x00\x00\x00\x00\x33\x00\x00\x00\x44\x00\x00\x00\x33\x00" + /* 800 */ "\x22\x22\x66\x00\x00\x00\x55\x00\x55\x55\xcc\x00\x00\x00\x33\x00" + /* 816 */ "\x22\x22\x66\x00\x00\x00\x00\x00\x03\x00\x44\x00\x33\x22\x66\x00" + /* 832 */ "\x55\x55\xcc\x00\x33\x22\x66\x00\x55\x55\xcc\x00\x03\x02\x46\x00" + /* 848 */ "\x05\x05\xbb\x00\x33\x22\x66\x00\x55\x55\xcc\x00\x03\x00\x00\x00" + /* 864 */ "\x00\x02\x00\x55\x00\x02\x00\x55\x00\x02\x00\x05\x00\x02\x00\x55" + /* 880 */ "\x00\x02\x02\x46\x00\x02\x00\xaa\x00\x55\x55\xcc\x00\x02\x00\x55" + /* 896 */ "\x00\x02\x02\x46\x00\x02\x00\x55\x55\x05\x55\x46\xaa\xcc\x55\x46" + /* 912 */ "\xaa\xcc\x55\x06\x5a\xbb\x55\x46\xaa\xcc\x55\x06\x5a\xbb\x55\x46" + /* 928 */ "\xaa\xcc\x55\x06\x5a\xbb\x55\x46\xaa\xcc\x55\x06\x5a\xbb\x55\x46" + /* 944 */ "\xaa\xcc\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x03\x00\x00\x00" + /* 960 */ "\x44\x00\x00\x00\x33\x00\x22\x22\x66\x00\x00\x00\x55\x00\x55\x55" + /* 976 */ "\xcc\x00\x00\x00\x33\x00\x22\x22\x66\x00\x00\x00\x55\x00\x55\x55" + /* 992 */ "\x05\x55\x05\x55\x05\x55\x05\x55\x46\x55\x5a\xaa\xcc\x55\x05\x55" + /* 1008 */ "\x46\x55\x5a\xaa\xcc\x55\x05\x55\x06\x55\x0a\x5a\xbb\x55\x05\x55" + /* 1024 */ "\x46\x55\x5a\xaa\xcc\x55\x05\x55\x06\x55\x0a\x55\x55\x05\x55\x05" + /* 1040 */ "\x55\x05\x55\x05\x55\x05\x55\x05\x55\x05\x55\x05\x55\x05\x55\x05" + /* 1056 */ "\x55\x46\x55\x05\x55\x5a\x55\x5a\xaa\xcc\x55\x05\x55\x05\x55\x05" + /* 1072 */ "\x55\x46\x55\x05\x55\x5a\x55\x5a\xaa\xcc\xcc\xbb\xcc\xbb\xcc\xbb" + /* 1088 */ "\xcc\xbb\xcc\xbb\xcc\xbb\xcc\xbb\xcc\xbb\xcc\xbb\xcc\xbb\xcc\xbb" + /* 1104 */ "\xcc\xbb\xcc\xbb\xcc\xbb\xcc\xbb\xcc\xbb\xcc\xbb\xcc\xbb\xcc\xbb" + /* 1120 */ "\xcc\xbb\xcc\xbb\xcc\xbb\xcc\xbb\x00\x00\x00\x00\x00\x00\x00\x00" + /* 1136 */ "\x00\x00\x33\x00\x00\x00\x44\x00\x00\x00\x33\x00\x22\x22\x66\x00" + /* 1152 */ "\x00\x00\x55\x00\x55\x55\xcc\x00\x00\x00\x33\x00\x22\x22\x66\x00" + /* 1168 */ "\x00\x00\x55\x00\x55\x55\xcc\x00\x00\x00\x00\x00\x33\x00\x44\x00" + /* 1184 */ "\x33\x22\x66\x00\x55\x55\xcc\x00\x33\x22\x66\x00\x55\x55\xcc\x00" + /* 1200 */ "\x33\x02\x46\x00\x05\x05\xbb\x00\x33\x22\x66\x00\x55\x55\xcc\x00" + /* 1216 */ "\x33\x02\x46\x00\x05\x05\xbb\x00\x33\x00\x00\x00\x00\x22\x00\x55" + /* 1232 */ "\x00\x22\x00\x55\x00\x02\x00\x05\x00\x22\x00\x55\x00\x02\x02\x46" + /* 1248 */ "\x00\x22\x00\xaa\x00\x55\x55\xcc\x00\x22\x00\x55\x00\x02\x02\x46" + /* 1264 */ "\x00\x22\x00\xaa\x00\x55\x55\xcc\x00\x22\x00\x00\x03\x44\x33\x66" + /* 1280 */ "\x55\xcc\x33\x66\x55\xcc\x03\x46\x05\xbb\x33\x66\x55\xcc\x03\x46" + /* 1296 */ "\x05\xbb\x33\x66\x55\xcc\x03\x46\x05\xbb\x33\x66\x55\xcc\x03\x46" + /* 1312 */ "\x05\xbb\x33\x66\x55\xcc\x03\x46\x05\xbb\x33\x66\x55\xcc\x00\x00" + /* 1328 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x03\x00\x00\x00\x44\x00\x00\x00" + /* 1344 */ "\x33\x00\x22\x22\x66\x00\x00\x00\x55\x00\x55\x55\xcc\x00\x00\x00" + /* 1360 */ "\x33\x00\x22\x22\x66\x00\x00\x00\x55\x00\x55\x55\xcc\x00\x00\x00" + /* 1376 */ "\x03\x00\x00\x02\x55\x02\x55\x02\x05\x02\x55\x02\x46\x02\xaa\x55" + /* 1392 */ "\xcc\x02\x55\x02\x46\x02\xaa\x55\xcc\x02\x55\x02\x06\x02\x5a\x05" + /* 1408 */ "\xbb\x02\x55\x02\x46\x02\xaa\x55\xcc\x02\x55\x02\x06\x02\x5a\x05" + /* 1424 */ "\xbb\x02\x55\x02\x46\x02\xaa\x00\x02\x55\x02\x55\x02\x05\x02\x55" + /* 1440 */ "\x02\x05\x02\x55\x02\x05\x02\x55\x02\x05\x02\x55\x02\x46\x02\x55" + /* 1456 */ "\x02\x5a\x02\xaa\x55\xcc\x02\x55\x02\x05\x02\x55\x02\x46\x02\x55" + /* 1472 */ "\x02\x5a\x02\xaa\x55\xcc\x02\x55\x02\x05\x02\x55\x02\x05\x46\xcc" + /* 1488 */ "\x46\xcc\x06\xbb\x46\xcc\x06\xbb\x46\xcc\x06\xbb\x46\xcc\x06\xbb" + /* 1504 */ "\x46\xcc\x06\xbb\x46\xcc\x06\xbb\x46\xcc\x06\xbb\x46\xcc\x06\xbb" + /* 1520 */ "\x46\xcc\x06\xbb\x46\xcc\x06\xbb\x46\xcc\x06\xbb\x46\xcc\x06\xbb" + /* 1536 */ "\x46\xcc\x06\xbb\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x33\x00" + /* 1552 */ "\x00\x00\x44\x00\x00\x00\x33\x00\x22\x22\x66\x00\x00\x00\x55\x00" + /* 1568 */ "\x55\x55\xcc\x00\x00\x00\x33\x00\x22\x22\x66\x00\x00\x00\x55\x00" + /* 1584 */ "\x55\x55\xcc\x00\x00\x00\x33\x00\x02\x02\x46\x00\x00\x00\x00\x00" + /* 1600 */ "\x03\x00\x44\x00\x33\x22\x66\x00\x55\x55\xcc\x00\x33\x22\x66\x00" + /* 1616 */ "\x55\x55\xcc\x00\x03\x02\x46\x00\x05\x05\xbb\x00\x33\x22\x66\x00" + /* 1632 */ "\x55\x55\xcc\x00\x03\x02\x46\x00\x05\x05\xbb\x00\x33\x22\x66\x00" + /* 1648 */ "\x55\x55\xcc\x00\x03\x00\x00\x00\x00\x02\x00\x55\x00\x02\x00\x55" + /* 1664 */ "\x00\x02\x00\x05\x00\x02\x00\x55\x00\x02\x02\x46\x00\x02\x00\xaa" + /* 1680 */ "\x00\x55\x55\xcc\x00\x02\x00\x55\x00\x02\x02\x46\x00\x02\x00\xaa" + /* 1696 */ "\x00\x55\x55\xcc\x00\x02\x00\x55\x00\x02\x02\x06\x00\x02\x00\x05" + /* 1712 */ "\x05\x05\x05\x46\x5a\xcc\x05\x46\x5a\xcc\x05\x06\x0a\xbb\x05\x46" + /* 1728 */ "\x5a\xcc\x05\x06\x0a\xbb\x05\x46\x5a\xcc\x05\x06\x0a\xbb\x05\x46" + /* 1744 */ "\x5a\xcc\x05\x06\x0a\xbb\x05\x46\x5a\xcc\x05\x06\x0a\xbb\x05\x46" + /* 1760 */ "\x5a\xcc\x05\x06\x0a\xbb\x05\x46\x5a\xcc\x00\x00\x00\x00\x00\x00" + /* 1776 */ "\x00\x00\x00\x00\x03\x00\x00\x00\x44\x00\x00\x00\x33\x00\x22\x22" + /* 1792 */ "\x66\x00\x00\x00\x55\x00\x55\x55\xcc\x00\x00\x00\x33\x00\x22\x22" + /* 1808 */ "\x66\x00\x00\x00\x55\x00\x55\x55\xcc\x00\x00\x00\x03\x00\x02\x02" + /* 1824 */ "\x46\x00\x00\x00\x05\x00\x05\x05\x05\x05\x05\x05\x05\x05\x05\x05" + /* 1840 */ "\x46\x05\x5a\x5a\xcc\x05\x05\x05\x46\x05\x5a\x5a\xcc\x05\x05\x05" + /* 1856 */ "\x06\x05\x0a\x0a\xbb\x05\x05\x05\x46\x05\x5a\x5a\xcc\x05\x05\x05" + /* 1872 */ "\x06\x05\x0a\x0a\xbb\x05\x05\x05\x46\x05\x5a\x5a\xcc\x05\x05\x05" + /* 1888 */ "\x06\x05\x0a\x05\x05\x05\x05\x05\x05\x05\x05\x05\x05\x05\x05\x05" + /* 1904 */ "\x05\x05\x05\x05\x05\x05\x05\x05\x05\x46\x05\x05\x05\x5a\x05\x5a" + /* 1920 */ "\x5a\xcc\x05\x05\x05\x05\x05\x05\x05\x46\x05\x05\x05\x5a\x05\x5a" + /* 1936 */ "\x5a\xcc\x05\x05\x05\x05\x05\x05\x05\x06\x05\x05\x05\x0a\x05\x0a" + /* 1952 */ "\x0a"; + +unsigned char *adv_gomoku /* [978] */ = + /* 0 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" + /* 16 */ "\x00\x00\x00\x00\xa0\x00\xa0\x00\x04\x00\x04\x00\x00\xd0\x00\xd0" + /* 32 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" + /* 48 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" + /* 64 */ "\x00\x70\x00\x00\x00\x00\xa0\x00\xa1\x00\x00\x00\xa0\x00\x04\x00" + /* 80 */ "\x04\x00\x00\x00\x04\x00\xd0\xd0\x00\xd0\x00\xd0\x00\xd0\x00\x00" + /* 96 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x70\x08\x08\x00\x08\x00\x08\x00" + /* 112 */ "\x08\x00\x08\x00\x40\x40\x00\x40\x00\x40\x00\x40\x00\x40\x00\x00" + /* 128 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x70" + /* 144 */ "\x00\x00\x00\x70\x21\x00\x00\x00\x00\x00\xa1\x00\x00\x00\xa1\x00" + /* 160 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" + /* 176 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" + /* 192 */ "\x00\x00\x00\x00\x00\x00\x70\x21\x00\x00\x00\x00\x00\x00\x00\x00" + /* 208 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" + /* 224 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" + /* 240 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x70\x00\x00" + /* 256 */ "\x00\x70\x21\x00\x00\x00\x00\x00\x00\x00\xa0\x00\xa1\x00\x00\x00" + /* 272 */ "\xa1\x00\x00\x00\xa0\x00\x00\x00\xa0\x00\x04\x00\x04\x00\x00\x00" + /* 288 */ "\x04\x00\x00\x00\x04\x00\x00\x00\x04\x00\xd0\xd0\x00\xd0\x00\xd0" + /* 304 */ "\x00\xd0\x00\xd0\x00\xd0\x00\xd0\x00\xd0\x00\x00\x00\x00\x00\x00" + /* 320 */ "\x00\x00\x00\x00\x70\x21\x00\x00\x00\x00\x00\x00\x70\x08\x08\x00" + /* 336 */ "\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00" + /* 352 */ "\x40\x40\x00\x40\x00\x40\x00\x40\x00\x40\x00\x40\x00\x40\x00\x40" + /* 368 */ "\x00\x40\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" + /* 384 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x70\x00\x00\x00\x70" + /* 400 */ "\x21\x00\x00\x00\x00\x00\x00\x70\x21\x00\x00\x00\x00\x00\xa1\x00" + /* 416 */ "\x00\x00\xa1\x00\x00\x00\x00\x00\x00\x00\xa1\x00\x00\x00\x00\x00" + /* 432 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" + /* 448 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" + /* 464 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" + /* 480 */ "\x00\x00\x70\x21\x00\x00\x00\x00\x00\x00\x70\x21\x00\x00\x00\x00" + /* 496 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" + /* 512 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" + /* 528 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" + /* 544 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" + /* 560 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x70\x00\x00\x00\x70\x21\x00" + /* 576 */ "\x00\x00\x00\x00\x00\x70\x21\x00\x00\x00\x00\x00\x00\x00\xa0\x00" + /* 592 */ "\xa1\x00\x00\x00\xa1\x00\x00\x00\xa0\x00\x00\x00\xa1\x00\x00\x00" + /* 608 */ "\xa0\x00\x00\x00\xa0\x00\x04\x00\x04\x00\x00\x00\x04\x00\x00\x00" + /* 624 */ "\x04\x00\x00\x00\x04\x00\x00\x00\x04\x00\x00\x00\x04\x00\x00\xd0" + /* 640 */ "\x00\xd0\x00\x00\x00\xd0\x00\x00\x00\xd0\x00\x00\x00\xd0\x00\x00" + /* 656 */ "\x00\xd0\x00\x00\x00\xd0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" + /* 672 */ "\x70\x21\x00\x00\x00\x00\x00\x00\x70\x21\x00\x00\x00\x00\x00\x00" + /* 688 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" + /* 704 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" + /* 720 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" + /* 736 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" + /* 752 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" + /* 768 */ "\x00\x00\x00\x00\x00\x00\x00\x70\x00\x00\x00\x70\x21\x00\x00\x00" + /* 784 */ "\x00\x00\x00\x70\x21\x00\x00\x00\x00\x00\x00\x70\x00\x00\x00\x00" + /* 800 */ "\x00\x00\xa1\x00\x00\x00\xa1\x00\x00\x00\x00\x00\x00\x00\xa1\x00" + /* 816 */ "\x00\x00\x00\x00\x00\x00\xa1\x00\x00\x00\x00\x00\x00\x00\x00\x00" + /* 832 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" + /* 848 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" + /* 864 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" + /* 880 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x70\x21" + /* 896 */ "\x00\x00\x00\x00\x00\x00\x70\x21\x00\x00\x00\x00\x00\x00\x00\x00" + /* 912 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" + /* 928 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" + /* 944 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" + /* 960 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" + /* 976 */ "\x00"; /* name.c */ -word_t *toplev; +word_t *toplev; /* menu.c */ commands_t cmdlist[] = { - {admin,PERM_SYSOP|PERM_VIEWSYSOP, "00Admin 【 系統維護區 】"}, - {Announce, 0, "AAnnounce 【 精華公佈欄 】"}, - {Boards, 0, "FFavorite 【 我 的 最愛 】"}, - {root_board, 0, "CClass 【 分組討論區 】"}, - {Mail, PERM_BASIC, "MMail 【 私人信件區 】"}, - {Talk, 0, "TTalk 【 休閒聊天區 】"}, - {User, 0, "UUser 【 個人設定區 】"}, - {Xyz, 0, "XXyz 【 系統工具區 】"}, - {Play_Play,0, "PPlay 【 遊樂場/大學查榜】"}, - {Name_Menu,PERM_LOGINOK, "NNamelist 【 編特別名單 】"}, - {Goodbye, 0, "GGoodbye 離開,再見……"}, + {admin, PERM_SYSOP | PERM_VIEWSYSOP, "00Admin 【 系統維護區 】"}, + {Announce, 0, "AAnnounce 【 精華公佈欄 】"}, + {Boards, 0, "FFavorite 【 我 的 最愛 】"}, + {root_board, 0, "CClass 【 分組討論區 】"}, + {Mail, PERM_BASIC, "MMail 【 私人信件區 】"}, + {Talk, 0, "TTalk 【 休閒聊天區 】"}, + {User, 0, "UUser 【 個人設定區 】"}, + {Xyz, 0, "XXyz 【 系統工具區 】"}, + {Play_Play, 0, "PPlay 【 遊樂場/大學查榜】"}, + {Name_Menu, PERM_LOGINOK, "NNamelist 【 編特別名單 】"}, + {Goodbye, 0, "GGoodbye 離開,再見……"}, {NULL, 0, NULL} }; /* friend.c */ /* Ptt 各種特別名單的檔名 */ -char *friend_file[8] = { +char *friend_file[8] = { FN_OVERRIDES, FN_REJECT, "alohaed", diff --git a/pttbbs/mbbsd/vice.c b/pttbbs/mbbsd/vice.c index 8b8abe0f..d52f12ad 100644 --- a/pttbbs/mbbsd/vice.c +++ b/pttbbs/mbbsd/vice.c @@ -1,4 +1,4 @@ -/* $Id: vice.c,v 1.3 2002/06/04 13:08:34 in2 Exp $ */ +/* $Id: vice.c,v 1.4 2002/07/05 17:10:28 in2 Exp $ */ #include "bbs.h" #define VICE_PLAY BBSHOME "/etc/vice/vice.play" @@ -14,122 +14,133 @@ #define MAX_LOST_PICTURE 3 #define MAX_END_PICTURE 5 -static int vice_load(char tbingo[6][15]) { - FILE *fb = fopen(VICE_BINGO, "r"); - char buf[16], *ptr; - int i = 0; - if(!fb) return -1; bzero((char*)tbingo, sizeof(tbingo)); - while(i < 6 && fgets(buf, 15, fb)) { - if((ptr = strchr(buf, '\n'))) - *ptr = 0; - strcpy(tbingo[i++], buf); +static int +vice_load(char tbingo[6][15]) +{ + FILE *fb = fopen(VICE_BINGO, "r"); + char buf[16], *ptr; + int i = 0; + if (!fb) + return -1; + bzero((char *)tbingo, sizeof(tbingo)); + while (i < 6 && fgets(buf, 15, fb)) { + if ((ptr = strchr(buf, '\n'))) + *ptr = 0; + strcpy(tbingo[i++], buf); } fclose(fb); return 0; } -static int check(char tbingo[6][15], char *data) { - int i = 0, j; +static int +check(char tbingo[6][15], char *data) +{ + int i = 0, j; - if(!strcmp(data, tbingo[0])) - return 8; + if (!strcmp(data, tbingo[0])) + return 8; - for(j = 8; j > 0; j--) - for(i = 1; i < 6; i++) - if(!strncmp(data+8-j, tbingo[i]+8-j,j)) - return j - 1; + for (j = 8; j > 0; j--) + for (i = 1; i < 6; i++) + if (!strncmp(data + 8 - j, tbingo[i] + 8 - j, j)) + return j - 1; return 0; } -// Ptt: showfile ran_showfile more 三者要整合 -static int ran_showfile(int y, int x, char *filename, int maxnum) { - FILE *fs; - char buf[512]; +//Ptt:showfile ran_showfile more T 怑n 膃X +static int +ran_showfile(int y, int x, char *filename, int maxnum) +{ + FILE *fs; + char buf[512]; bzero(buf, sizeof(char) * 512); sprintf(buf, "%s%d", filename, rand() % maxnum + 1); - if(!(fs = fopen(buf, "r"))) { - move(10,10); - prints("can't open file: %s", buf); - return 0; + if (!(fs = fopen(buf, "r"))) { + move(10, 10); + prints("can't open file: %s", buf); + return 0; } - move(y, x); - while(fgets(buf, 511, fs)) - prints("%s", buf); + while (fgets(buf, 511, fs)) + prints("%s", buf); fclose(fs); return 1; } -static int ran_showmfile(char *filename, int maxnum) { - char buf[256]; +static int +ran_showmfile(char *filename, int maxnum) +{ + char buf[256]; sprintf(buf, "%s%d", filename, rand() % maxnum + 1); return more(buf, YEA); } -int vice_main() { - FILE *fd; - char tbingo[6][15]; - char buf_data[256] - , serial[16], ch[2], *ptr; - int TABLE[] = {0,10,200,1000,4000,10000,40000,100000,200000}; - int total = 0, money, i = 4, j = 0; +int +vice_main() +{ + FILE *fd; + char tbingo[6][15]; + char buf_data[256] + ,serial[16], ch[2], *ptr; + int TABLE[] = {0, 10, 200, 1000, 4000, 10000, 40000, 100000, 200000}; + int total = 0, money, i = 4, j = 0; setuserfile(buf_data, VICE_DATA); - if(!dashf(buf_data)) { - ran_showmfile(VICE_NO, MAX_NO_PICTURE); - return 0; + if (!dashf(buf_data)) { + ran_showmfile(VICE_NO, MAX_NO_PICTURE); + return 0; } - if(vice_load(tbingo)<0) return -1; + if (vice_load(tbingo) < 0) + return -1; clear(); ran_showfile(0, 0, VICE_PLAY, 1); ran_showfile(10, 0, VICE_SHOW, 1); - if(!(fd = fopen(buf_data, "r"))) - return 0; + if (!(fd = fopen(buf_data, "r"))) + return 0; j = 0; i = 0; - move(10,24); + move(10, 24); clrtoeol(); prints("這一期的發票號碼"); - while(fgets(serial, 15, fd)) { - if((ptr = strchr(serial,'\r'))) - *ptr = 0; - if(j == 0) - i++; - move(10 + i, 24 + j); - prints("%s", serial); - j += 9; - j %= 45; + while (fgets(serial, 15, fd)) { + if ((ptr = strchr(serial, '\r'))) + *ptr = 0; + if (j == 0) + i++; + move(10 + i, 24 + j); + prints("%s", serial); + j += 9; + j %= 45; } getdata(8, 0, "按'c'開始對獎了(或是任意鍵離開)): ", ch, sizeof(ch), LCECHO); - if(ch[0] != 'c' || lockutmpmode(VICE, LOCK_MULTI)){ - fclose(fd); - return 0; - } - + if (ch[0] != 'c' || lockutmpmode(VICE, LOCK_MULTI)) { + fclose(fd); + return 0; + } showtitle("發票對獎", BBSNAME); rewind(fd); - while(fgets(serial, 15, fd)) { - if((ptr = strchr(serial,'\n'))) - *ptr = 0; - money = TABLE[check(tbingo,serial)]; - total += money; - prints("%s 中了 %d\n", serial, money); + while (fgets(serial, 15, fd)) { + if ((ptr = strchr(serial, '\n'))) + *ptr = 0; + money = TABLE[check(tbingo, serial)]; + total += money; + prints("%s 中了 %d\n", serial, money); } pressanykey(); - if(total > 0) { - ran_showmfile(VICE_WIN, MAX_WIN_PICTURE); - move(22,0); - clrtoeol(); - prints("全部的發票中了 %d 塊錢\n", total); - demoney(total); + if (total > 0) { + ran_showmfile(VICE_WIN, MAX_WIN_PICTURE); + move(22, 0); + clrtoeol(); + prints("全部的發票中了 %d 塊錢\n", total); + demoney(total); } else - ran_showmfile(VICE_LOST, MAX_LOST_PICTURE); + ran_showmfile(VICE_LOST, MAX_LOST_PICTURE); fclose(fd); unlink(buf_data); diff --git a/pttbbs/mbbsd/vote.c b/pttbbs/mbbsd/vote.c index 914ac24a..e54bc7a2 100644 --- a/pttbbs/mbbsd/vote.c +++ b/pttbbs/mbbsd/vote.c @@ -1,79 +1,85 @@ -/* $Id: vote.c,v 1.9 2002/06/04 13:08:34 in2 Exp $ */ +/* $Id: vote.c,v 1.10 2002/07/05 17:10:28 in2 Exp $ */ #include "bbs.h" -static int total; - -static char STR_bv_control[] = "control"; /* 投票日期 選項 */ -static char STR_bv_desc[] = "desc"; /* 投票目的 */ -static char STR_bv_ballots[] = "ballots"; -static char STR_bv_flags[] = "flags"; -static char STR_bv_comments[] = "comments"; /* 投票者的建意 */ -static char STR_bv_limited[] = "limited"; /* 私人投票 */ -static char STR_bv_title[] = "vtitle"; - -static char STR_bv_results[] = "results"; - -static char STR_new_control[] = "control0\0"; /* 投票日期 選項 */ -static char STR_new_desc[] = "desc0\0"; /* 投票目的 */ -static char STR_new_ballots[] = "ballots0\0"; -static char STR_new_flags[] = "flags0\0"; -static char STR_new_comments[] = "comments0\0"; /* 投票者的建意 */ -static char STR_new_limited[] = "limited0\0"; /* 私人投票 */ -static char STR_new_title[] = "vtitle0\0"; - -int strip_ansi(char *buf, char *str, int mode) { - register int ansi, count = 0; - - for(ansi = 0; *str /*&& *str != '\n' */; str++) { - if(*str == 27) { - if(mode) { - if(buf) +static int total; + +static char STR_bv_control[] = "control"; /* 投票日期 選項 */ +static char STR_bv_desc[] = "desc"; /* 投票目的 */ +static char STR_bv_ballots[] = "ballots"; +static char STR_bv_flags[] = "flags"; +static char STR_bv_comments[] = "comments"; /* 投票者的建意 */ +static char STR_bv_limited[] = "limited"; /* 私人投票 */ +static char STR_bv_title[] = "vtitle"; + +static char STR_bv_results[] = "results"; + +static char STR_new_control[] = "control0\0"; /* 投票日期 選項 */ +static char STR_new_desc[] = "desc0\0"; /* 投票目的 */ +static char STR_new_ballots[] = "ballots0\0"; +static char STR_new_flags[] = "flags0\0"; +static char STR_new_comments[] = "comments0\0"; /* 投票者的建意 */ +static char STR_new_limited[] = "limited0\0"; /* 私人投票 */ +static char STR_new_title[] = "vtitle0\0"; + +int +strip_ansi(char *buf, char *str, int mode) +{ + register int ansi, count = 0; + + for (ansi = 0; *str /* && *str != '\n' */ ; str++) { + if (*str == 27) { + if (mode) { + if (buf) *buf++ = *str; count++; } ansi = 1; - } else if(ansi && strchr("[;1234567890mfHABCDnsuJKc=n", *str)) { - if((mode == NO_RELOAD && !strchr("c=n", *str)) || - (mode == ONLY_COLOR && strchr("[;1234567890m", *str))) { - if(buf) + } else if (ansi && strchr("[;1234567890mfHABCDnsuJKc=n", *str)) { + if ((mode == NO_RELOAD && !strchr("c=n", *str)) || + (mode == ONLY_COLOR && strchr("[;1234567890m", *str))) { + if (buf) *buf++ = *str; count++; } - if(strchr("mHn ", *str)) + if (strchr("mHn ", *str)) ansi = 0; } else { - ansi =0; - if(buf) + ansi = 0; + if (buf) *buf++ = *str; count++; } } - if(buf) + if (buf) *buf = '\0'; return count; } -void b_suckinfile(FILE *fp, char *fname) { - FILE *sfp; +void +b_suckinfile(FILE * fp, char *fname) +{ + FILE *sfp; - if((sfp = fopen(fname, "r"))) { - char inbuf[256]; + if ((sfp = fopen(fname, "r"))) { + char inbuf[256]; - while(fgets(inbuf, sizeof(inbuf), sfp)) + while (fgets(inbuf, sizeof(inbuf), sfp)) fputs(inbuf, fp); fclose(sfp); } } -static void b_count(char *buf, int counts[]) { - char inchar; - int fd; +static void +b_count(char *buf, int counts[]) +{ + char inchar; + int fd; memset(counts, 0, 31 * sizeof(counts[0])); total = 0; - if((fd = open(buf, O_RDONLY)) != -1) { - flock(fd, LOCK_EX); /* Thor: 防止多人同時算 */ - while(read(fd, &inchar, 1) == 1) { + if ((fd = open(buf, O_RDONLY)) != -1) { + flock(fd, LOCK_EX); /* Thor: 防止多人同時算 */ + while (read(fd, &inchar, 1) == 1) { counts[(int)(inchar - 'A')]++; total++; } @@ -83,92 +89,97 @@ static void b_count(char *buf, int counts[]) { } -static int b_nonzeroNum(char *buf) { - int i = 0; - char inchar; - int fd; +static int +b_nonzeroNum(char *buf) +{ + int i = 0; + char inchar; + int fd; - if((fd = open(buf, O_RDONLY)) != -1) { - while(read(fd, &inchar, 1) == 1) - if(inchar) + if ((fd = open(buf, O_RDONLY)) != -1) { + while (read(fd, &inchar, 1) == 1) + if (inchar) i++; close(fd); } return i; } -static void vote_report(char *bname, char *fname, char *fpath) { - register char *ip; - time_t dtime; - int fd, bid; - fileheader_t header; +static void +vote_report(char *bname, char *fname, char *fpath) +{ + register char *ip; + time_t dtime; + int fd, bid; + fileheader_t header; ip = fpath; - while(*(++ip)); + while (*(++ip)); *ip++ = '/'; /* get a filename by timestamp */ dtime = now; - for(;;) { + for (;;) { sprintf(ip, "M.%ld.A", ++dtime); fd = open(fpath, O_CREAT | O_EXCL | O_WRONLY, 0644); - if(fd >= 0) + if (fd >= 0) break; dtime++; } close(fd); - + unlink(fpath); link(fname, fpath); - + /* append record to .DIR */ - + memset(&header, 0, sizeof(fileheader_t)); strcpy(header.owner, "[馬路探子]"); sprintf(header.title, "[%s] 看板 選情報導", bname); { register struct tm *ptime = localtime(&dtime); - + sprintf(header.date, "%2d/%02d", ptime->tm_mon + 1, ptime->tm_mday); } strcpy(header.filename, ip); strcpy(ip, ".DIR"); - if((fd = open(fpath, O_WRONLY | O_CREAT, 0644)) >= 0) { + if ((fd = open(fpath, O_WRONLY | O_CREAT, 0644)) >= 0) { flock(fd, LOCK_EX); lseek(fd, 0, SEEK_END); write(fd, &header, sizeof(fileheader_t)); flock(fd, LOCK_UN); close(fd); - if((bid = getbnum(bname)) > 0) - setbtotal(bid); + if ((bid = getbnum(bname)) > 0) + setbtotal(bid); } - } -static void b_result_one(boardheader_t *fh, int ind) { - FILE *cfp, *tfp, *frp, *xfp; - char *bname ; - char buf[STRLEN]; - char inbuf[80]; - int counts[31]; - int num ; - int junk; - char b_control[64]; - char b_newresults[64]; - char b_report[64]; - time_t closetime; +static void +b_result_one(boardheader_t * fh, int ind) +{ + FILE *cfp, *tfp, *frp, *xfp; + char *bname; + char buf[STRLEN]; + char inbuf[80]; + int counts[31]; + int num; + int junk; + char b_control[64]; + char b_newresults[64]; + char b_report[64]; + time_t closetime; fh->bvote--; - if(fh->bvote==0) - fh->bvote=2; - else if(fh->bvote==2) - fh->bvote=1; + if (fh->bvote == 0) + fh->bvote = 2; + else if (fh->bvote == 2) + fh->bvote = 1; - if(ind) { + if (ind) { sprintf(STR_new_ballots, "%s%d", STR_bv_ballots, ind); sprintf(STR_new_control, "%s%d", STR_bv_control, ind); sprintf(STR_new_desc, "%s%d", STR_bv_desc, ind); @@ -189,12 +200,12 @@ static void b_result_one(boardheader_t *fh, int ind) { bname = fh->brdname; setbfile(buf, bname, STR_new_control); - cfp = fopen(buf,"r"); + cfp = fopen(buf, "r"); fscanf(cfp, "%d\n%lu\n", &junk, &closetime); fclose(cfp); setbfile(b_control, bname, "tmp"); - if(rename(buf, b_control) == -1) + if (rename(buf, b_control) == -1) return; setbfile(buf, bname, STR_new_flags); num = b_nonzeroNum(buf); @@ -204,61 +215,60 @@ static void b_result_one(boardheader_t *fh, int ind) { unlink(buf); setbfile(b_newresults, bname, "newresults"); - if((tfp = fopen(b_newresults, "w")) == NULL) + if ((tfp = fopen(b_newresults, "w")) == NULL) return; setbfile(buf, bname, STR_new_title); - if((xfp=fopen(buf,"r"))) { + if ((xfp = fopen(buf, "r"))) { fgets(inbuf, sizeof(inbuf), xfp); fprintf(tfp, "%s\n◆ 投票名稱: %s\n\n", msg_seperator, inbuf); } - fprintf(tfp, "%s\n◆ 投票中止於: %s\n\n◆ 票選題目描述:\n\n", msg_seperator, ctime(&closetime)); fh->vtime = now; - + setbfile(buf, bname, STR_new_desc); - + b_suckinfile(tfp, buf); unlink(buf); - - if((cfp = fopen(b_control, "r"))) { + + if ((cfp = fopen(b_control, "r"))) { fgets(inbuf, sizeof(inbuf), cfp); fgets(inbuf, sizeof(inbuf), cfp); fprintf(tfp, "\n◆投票結果:(共有 %d 人投票,每人最多可投 %d 票)\n", num, junk); - while(fgets(inbuf, sizeof(inbuf), cfp)) { + while (fgets(inbuf, sizeof(inbuf), cfp)) { inbuf[(strlen(inbuf) - 1)] = '\0'; num = counts[inbuf[0] - 'A']; fprintf(tfp, " %-42s %3d 票 %02.2f%%\n", inbuf + 3, num, - (float)(num*100)/(float)(total)); + (float)(num * 100) / (float)(total)); } fclose(cfp); } unlink(b_control); - + fprintf(tfp, "%s\n◆ 使用者建議:\n\n", msg_seperator); setbfile(buf, bname, STR_new_comments); b_suckinfile(tfp, buf); unlink(buf); - + fprintf(tfp, "%s\n◆ 總票數 = %d 票\n\n", msg_seperator, total); fclose(tfp); - + setbfile(b_report, bname, "report"); - if((frp = fopen(b_report, "w"))) { + if ((frp = fopen(b_report, "w"))) { b_suckinfile(frp, b_newresults); fclose(frp); } sprintf(inbuf, "boards/%c/%s", bname[0], bname); vote_report(bname, b_report, inbuf); - if(!(fh->brdattr &BRD_NOCOUNT)) { + if (!(fh->brdattr & BRD_NOCOUNT)) { sprintf(inbuf, "boards/%c/%s", 'R', "Record"); vote_report(bname, b_report, inbuf); } unlink(b_report); - + tfp = fopen(b_newresults, "a"); setbfile(buf, bname, STR_bv_results); b_suckinfile(tfp, buf); @@ -266,91 +276,97 @@ static void b_result_one(boardheader_t *fh, int ind) { Rename(b_newresults, buf); } -static void b_result(boardheader_t *fh) { - FILE *cfp; - time_t closetime; - int i; - char buf[STRLEN]; - char temp[STRLEN]; - - for(i = 0; i < 20; i++) { - if(i) +static void +b_result(boardheader_t * fh) +{ + FILE *cfp; + time_t closetime; + int i; + char buf[STRLEN]; + char temp[STRLEN]; + + for (i = 0; i < 20; i++) { + if (i) sprintf(STR_new_control, "%s%d", STR_bv_control, i); - else + else strcpy(STR_new_control, STR_bv_control); - setbfile(buf, fh->brdname, STR_new_control); - cfp = fopen(buf,"r"); - if (!cfp) - continue; - fgets(temp,sizeof(temp),cfp); - fscanf(cfp, "%lu\n", &closetime); - fclose(cfp); - if(closetime < now) - b_result_one(fh,i); + setbfile(buf, fh->brdname, STR_new_control); + cfp = fopen(buf, "r"); + if (!cfp) + continue; + fgets(temp, sizeof(temp), cfp); + fscanf(cfp, "%lu\n", &closetime); + fclose(cfp); + if (closetime < now) + b_result_one(fh, i); } } -static int b_close(boardheader_t *fh) { +static int +b_close(boardheader_t * fh) +{ - if(fh->bvote == 2) { - if(fh->vtime < now - 3 * 86400) { + if (fh->bvote == 2) { + if (fh->vtime < now - 3 * 86400) { fh->bvote = 0; return 1; - } - else + } else return 0; } b_result(fh); return 1; } -int b_closepolls() { - static char *fn_vote_polling = ".polling"; - boardheader_t *fhp; - FILE *cfp; - int pos, dirty; - time_t last; - char timebuf[100]; - -/* Edited by CharlieL for can't auto poll bug */ - - if((cfp = fopen(fn_vote_polling,"r"))) { - fgets(timebuf,100*sizeof(char),cfp); - sscanf(timebuf, "%lu", &last); - fclose(cfp); - if(last + 3600 >= now) - return 0; +int +b_closepolls() +{ + static char *fn_vote_polling = ".polling"; + boardheader_t *fhp; + FILE *cfp; + int pos, dirty; + time_t last; + char timebuf[100]; + + /* Edited by CharlieL for can't auto poll bug */ + + if ((cfp = fopen(fn_vote_polling, "r"))) { + fgets(timebuf, 100 * sizeof(char), cfp); + sscanf(timebuf, "%lu", &last); + fclose(cfp); + if (last + 3600 >= now) + return 0; } - - if((cfp = fopen(fn_vote_polling, "w")) == NULL) + if ((cfp = fopen(fn_vote_polling, "w")) == NULL) return 0; fprintf(cfp, "%lu\n%s\n", now, ctime(&now)); fclose(cfp); dirty = 0; - for(fhp = bcache, pos = 1; pos <= numboards; fhp++, pos++) { - if(fhp->bvote && b_close(fhp)) { - if(substitute_record(fn_board, fhp, sizeof(*fhp), pos) == -1) + for (fhp = bcache, pos = 1; pos <= numboards; fhp++, pos++) { + if (fhp->bvote && b_close(fhp)) { + if (substitute_record(fn_board, fhp, sizeof(*fhp), pos) == -1) outs(err_board_update); dirty = 1; } } - if(dirty) /* vote flag changed */ + if (dirty) /* vote flag changed */ reset_board(pos); return 0; } -static int vote_view(char *bname, int index) { - boardheader_t *fhp; - FILE* fp; - char buf[STRLEN], genbuf[STRLEN], inbuf[STRLEN]; - struct stat stbuf; - int fd, num = 0, i, pos, counts[31]; - time_t closetime; - - if(index) { +static int +vote_view(char *bname, int index) +{ + boardheader_t *fhp; + FILE *fp; + char buf[STRLEN], genbuf[STRLEN], inbuf[STRLEN]; + struct stat stbuf; + int fd, num = 0, i, pos, counts[31]; + time_t closetime; + + if (index) { sprintf(STR_new_ballots, "%s%d", STR_bv_ballots, index); sprintf(STR_new_control, "%s%d", STR_bv_control, index); sprintf(STR_new_desc, "%s%d", STR_bv_desc, index); @@ -369,43 +385,42 @@ static int vote_view(char *bname, int index) { } setbfile(buf, bname, STR_new_ballots); - if((fd = open(buf, O_RDONLY)) > 0) { + if ((fd = open(buf, O_RDONLY)) > 0) { fstat(fd, &stbuf); close(fd); } else stbuf.st_size = 0; - + setbfile(buf, bname, STR_new_title); move(0, 0); clrtobot(); - - if((fp = fopen(buf, "r"))) { + + if ((fp = fopen(buf, "r"))) { fgets(inbuf, sizeof(inbuf), fp); prints("\n投票名稱: %s", inbuf); } - setbfile(buf, bname, STR_new_control); fp = fopen(buf, "r"); fgets(inbuf, sizeof(inbuf), fp); fscanf(fp, "%lu\n", &closetime); prints("\n◆ 預知投票紀事: 每人最多可投 %d 票,目前共有 %d 票,\n" - "本次投票將結束於 %s", atoi(inbuf), stbuf.st_size, + "本次投票將結束於 %s", atoi(inbuf), stbuf.st_size, ctime(&closetime)); - + /* Thor: 開放 票數 預知 */ setbfile(buf, bname, STR_new_flags); num = b_nonzeroNum(buf); - + setbfile(buf, bname, STR_new_ballots); b_count(buf, counts); - + prints("共有 %d 人投票\n", num); total = 0; - - while(fgets(inbuf, sizeof(inbuf), fp)) { + + while (fgets(inbuf, sizeof(inbuf), fp)) { inbuf[(strlen(inbuf) - 1)] = '\0'; - inbuf[30] = '\0'; /* truncate */ + inbuf[30] = '\0'; /* truncate */ i = inbuf[0] - 'A'; num = counts[i]; move(i % 15 + 6, i / 15 * 40); @@ -419,7 +434,7 @@ static int vote_view(char *bname, int index) { prints("◆ 目前總票數 = %d 票", total); getdata(b_lines - 1, 0, "(A)取消投票 (B)提早開票 (C)繼續?[C] ", genbuf, 4, LCECHO); - if(genbuf[0] == 'a') { + if (genbuf[0] == 'a') { setbfile(buf, bname, STR_new_control); unlink(buf); setbfile(buf, bname, STR_new_flags); @@ -430,63 +445,64 @@ static int vote_view(char *bname, int index) { unlink(buf); setbfile(buf, bname, STR_new_limited); unlink(buf); - setbfile(buf,bname, STR_new_title); + setbfile(buf, bname, STR_new_title); unlink(buf); - - if(fhp->bvote) + + if (fhp->bvote) fhp->bvote--; if (fhp->bvote == 2) fhp->bvote = 1; - - if(substitute_record(fn_board, fhp, sizeof(*fhp), pos) == -1) + + if (substitute_record(fn_board, fhp, sizeof(*fhp), pos) == -1) outs(err_board_update); reset_board(pos); - } else if(genbuf[0] == 'b') { - b_result_one(fhp,index); - if(substitute_record(fn_board, fhp, sizeof(*fhp), pos) == -1) + } else if (genbuf[0] == 'b') { + b_result_one(fhp, index); + if (substitute_record(fn_board, fhp, sizeof(*fhp), pos) == -1) outs(err_board_update); - + reset_board(pos); } return FULLUPDATE; } -static int vote_view_all(char *bname) { - int i; - int x = -1; - FILE *fp, *xfp; - char buf[STRLEN], genbuf[STRLEN]; - char inbuf[80]; - +static int +vote_view_all(char *bname) +{ + int i; + int x = -1; + FILE *fp, *xfp; + char buf[STRLEN], genbuf[STRLEN]; + char inbuf[80]; + strcpy(STR_new_control, STR_bv_control); strcpy(STR_new_title, STR_bv_title); setbfile(buf, bname, STR_new_control); move(0, 0); - if((fp=fopen(buf,"r"))) { + if ((fp = fopen(buf, "r"))) { prints("(0) "); x = 0; fclose(fp); - + setbfile(buf, bname, STR_new_title); - if((xfp=fopen(buf,"r"))) + if ((xfp = fopen(buf, "r"))) fgets(inbuf, sizeof(inbuf), xfp); else strcpy(inbuf, "無標題"); prints("%s\n", inbuf); fclose(xfp); } - - for(i = 1; i < 20; i++) { + for (i = 1; i < 20; i++) { sprintf(STR_new_control, "%s%d", STR_bv_control, i); sprintf(STR_new_title, "%s%d", STR_bv_title, i); setbfile(buf, bname, STR_new_control); - if((fp=fopen(buf,"r"))) { + if ((fp = fopen(buf, "r"))) { prints("(%d) ", i); x = i; fclose(fp); setbfile(buf, bname, STR_new_title); - if((xfp=fopen(buf,"r"))) + if ((xfp = fopen(buf, "r"))) fgets(inbuf, sizeof(inbuf), xfp); else strcpy(inbuf, "無標題"); @@ -495,56 +511,57 @@ static int vote_view_all(char *bname) { } } - if(x < 0) + if (x < 0) return FULLUPDATE; sprintf(buf, "要看幾號投票 [%d] ", x); - + getdata(b_lines - 1, 0, buf, genbuf, 4, LCECHO); - if(atoi(genbuf) < 0 || atoi(genbuf) > 20) - sprintf(genbuf,"%d",x); - if(genbuf[0] != '0') + if (atoi(genbuf) < 0 || atoi(genbuf) > 20) + sprintf(genbuf, "%d", x); + if (genbuf[0] != '0') sprintf(STR_new_control, "%s%d", STR_bv_control, atoi(genbuf)); else strcpy(STR_new_control, STR_bv_control); - + setbfile(buf, bname, STR_new_control); - if((fp=fopen(buf,"r"))) { + if ((fp = fopen(buf, "r"))) { fclose(fp); return vote_view(bname, atoi(genbuf)); - } - else + } else return FULLUPDATE; } -static int vote_maintain(char *bname) { - FILE *fp = NULL; - char inbuf[STRLEN], buf[STRLEN]; - int num = 0, aborted, pos, x, i; - time_t closetime; - boardheader_t *fhp; - char genbuf[4]; - - if(!(currmode & MODE_BOARD)) +static int +vote_maintain(char *bname) +{ + FILE *fp = NULL; + char inbuf[STRLEN], buf[STRLEN]; + int num = 0, aborted, pos, x, i; + time_t closetime; + boardheader_t *fhp; + char genbuf[4]; + + if (!(currmode & MODE_BOARD)) return 0; - if((pos = getbnum(bname)) <= 0) + if ((pos = getbnum(bname)) <= 0) return 0; stand_title("舉辦投票"); fhp = bcache + pos - 1; -/* CharlieL */ - if(fhp->bvote != 2 && fhp->bvote !=0) { + /* CharlieL */ + if (fhp->bvote != 2 && fhp->bvote != 0) { getdata(b_lines - 1, 0, "(V)觀察目前投票 (M)舉辦新投票 (A)取消所有投票 (Q)繼續 [Q]", genbuf, 4, LCECHO); - if(genbuf[0] == 'v') + if (genbuf[0] == 'v') return vote_view_all(bname); - else if(genbuf[0] == 'a') { - fhp->bvote=0; - + else if (genbuf[0] == 'a') { + fhp->bvote = 0; + setbfile(buf, bname, STR_bv_control); unlink(buf); setbfile(buf, bname, STR_bv_flags); @@ -557,8 +574,8 @@ static int vote_maintain(char *bname) { unlink(buf); setbfile(buf, bname, STR_bv_title); unlink(buf); - - for(i = 1; i < 20; i++) { + + for (i = 1; i < 20; i++) { sprintf(STR_new_ballots, "%s%d", STR_bv_ballots, i); sprintf(STR_new_control, "%s%d", STR_bv_control, i); sprintf(STR_new_desc, "%s%d", STR_bv_desc, i); @@ -566,7 +583,7 @@ static int vote_maintain(char *bname) { sprintf(STR_new_comments, "%s%d", STR_bv_comments, i); sprintf(STR_new_limited, "%s%d", STR_bv_limited, i); sprintf(STR_new_title, "%s%d", STR_bv_title, i); - + setbfile(buf, bname, STR_new_control); unlink(buf); setbfile(buf, bname, STR_new_flags); @@ -580,35 +597,34 @@ static int vote_maintain(char *bname) { setbfile(buf, bname, STR_new_title); unlink(buf); } - if(substitute_record(fn_board, fhp, sizeof(*fhp), pos) == -1) + if (substitute_record(fn_board, fhp, sizeof(*fhp), pos) == -1) outs(err_board_update); - + return FULLUPDATE; - } else if(genbuf[0] != 'm' || fhp->bvote >= 20) + } else if (genbuf[0] != 'm' || fhp->bvote >= 20) return FULLUPDATE; } - strcpy(STR_new_control, STR_bv_control); - setbfile(buf,bname, STR_new_control); + setbfile(buf, bname, STR_new_control); x = 0; - while(x < 20 && (fp = fopen(buf,"r")) != NULL) { + while (x < 20 && (fp = fopen(buf, "r")) != NULL) { fclose(fp); - x++; - sprintf(STR_new_control, "%s%d", STR_bv_control, x); + x++; + sprintf(STR_new_control, "%s%d", STR_bv_control, x); setbfile(buf, bname, STR_new_control); } - if(fp) + if (fp) fclose(fp); - if(x >=20) - return FULLUPDATE; - if(x) { - sprintf(STR_new_ballots, "%s%d", STR_bv_ballots,x); - sprintf(STR_new_control, "%s%d", STR_bv_control,x); - sprintf(STR_new_desc, "%s%d", STR_bv_desc,x); - sprintf(STR_new_flags, "%s%d", STR_bv_flags,x); - sprintf(STR_new_comments, "%s%d", STR_bv_comments,x); - sprintf(STR_new_limited, "%s%d", STR_bv_limited,x); - sprintf(STR_new_title, "%s%d", STR_bv_title,x); + if (x >= 20) + return FULLUPDATE; + if (x) { + sprintf(STR_new_ballots, "%s%d", STR_bv_ballots, x); + sprintf(STR_new_control, "%s%d", STR_bv_control, x); + sprintf(STR_new_desc, "%s%d", STR_bv_desc, x); + sprintf(STR_new_flags, "%s%d", STR_bv_flags, x); + sprintf(STR_new_comments, "%s%d", STR_bv_comments, x); + sprintf(STR_new_limited, "%s%d", STR_bv_limited, x); + sprintf(STR_new_title, "%s%d", STR_bv_title, x); } else { strcpy(STR_new_ballots, STR_bv_ballots); strcpy(STR_new_control, STR_bv_control); @@ -619,21 +635,21 @@ static int vote_maintain(char *bname) { strcpy(STR_new_title, STR_bv_title); } clear(); - move(0,0); + move(0, 0); prints("第 %d 號投票\n", x); setbfile(buf, bname, STR_new_title); getdata(4, 0, "請輸入投票名稱:", inbuf, 50, LCECHO); - if(inbuf[0]=='\0') - strcpy(inbuf,"不知名的"); + if (inbuf[0] == '\0') + strcpy(inbuf, "不知名的"); fp = fopen(buf, "w"); fprintf(fp, "%s", inbuf); fclose(fp); - + prints("按任何鍵開始編輯此次 [投票宗旨]"); pressanykey(); setbfile(buf, bname, STR_new_desc); aborted = vedit(buf, NA, NULL); - if(aborted== -1) { + if (aborted == -1) { clear(); outs("取消此次投票"); pressanykey(); @@ -642,29 +658,29 @@ static int vote_maintain(char *bname) { aborted = 0; setbfile(buf, bname, STR_new_flags); unlink(buf); - + getdata(4, 0, "是否限定投票者名單:(y)編籍可投票人員名單[n]任何人皆可投票:[N]", inbuf, 2, LCECHO); setbfile(buf, bname, STR_new_limited); - if(inbuf[0] == 'y') { + if (inbuf[0] == 'y') { fp = fopen(buf, "w"); - fprintf(fp,"此次投票設限"); + fprintf(fp, "此次投票設限"); fclose(fp); friend_edit(FRIEND_CANVOTE); } else { - if(dashf(buf)) + if (dashf(buf)) unlink(buf); } clear(); getdata(0, 0, "此次投票進行幾天 (一到十天)?", inbuf, 4, DOECHO); closetime = atoi(inbuf); - if(closetime <= 0) + if (closetime <= 0) closetime = 1; - else if(closetime >10) + else if (closetime > 10) closetime = 10; - + closetime = closetime * 86400 + now; setbfile(buf, bname, STR_new_control); fp = fopen(buf, "w"); @@ -672,67 +688,69 @@ static int vote_maintain(char *bname) { outs("\n請依序輸入選項, 按 ENTER 完成設定"); num = 0; - while(!aborted) { + while (!aborted) { sprintf(buf, "%c) ", num + 'A'); getdata((num % 15) + 2, (num / 15) * 40, buf, inbuf, 50, DOECHO); - if(*inbuf) { - fprintf(fp, "%1c) %s\n", (num+'A'), inbuf); + if (*inbuf) { + fprintf(fp, "%1c) %s\n", (num + 'A'), inbuf); num++; } - if((*inbuf == '\0' && num >= 1) || num == 30) + if ((*inbuf == '\0' && num >= 1) || num == 30) aborted = 1; } sprintf(buf, "請問每人最多可投幾票?([1]∼%d): ", num); - - getdata(t_lines-3, 0, buf, inbuf, 3, DOECHO); - - if(atoi(inbuf) <= 0 || atoi(inbuf) > num) - strcpy(inbuf,"1"); - + + getdata(t_lines - 3, 0, buf, inbuf, 3, DOECHO); + + if (atoi(inbuf) <= 0 || atoi(inbuf) > num) + strcpy(inbuf, "1"); + rewind(fp); fprintf(fp, "%2d\n", MAX(1, atoi(inbuf))); fclose(fp); - - if(fhp->bvote == 2) - fhp->bvote = 0; - else if(fhp->bvote == 1) - fhp->bvote = 2; - else if(fhp->bvote == 2) - fhp->bvote = 1; - - fhp->bvote ++; - - if(substitute_record(fn_board, fhp, sizeof(*fhp), pos) == -1) + + if (fhp->bvote == 2) + fhp->bvote = 0; + else if (fhp->bvote == 1) + fhp->bvote = 2; + else if (fhp->bvote == 2) + fhp->bvote = 1; + + fhp->bvote++; + + if (substitute_record(fn_board, fhp, sizeof(*fhp), pos) == -1) outs(err_board_update); reset_board(pos); outs("開始投票了!"); - + return FULLUPDATE; } -static int vote_flag(char *bname, int index, char val) { - char buf[256], flag; - int fd, num, size; +static int +vote_flag(char *bname, int index, char val) +{ + char buf[256], flag; + int fd, num, size; - if(index) + if (index) sprintf(STR_new_flags, "%s%d", STR_bv_flags, index); else strcpy(STR_new_flags, STR_bv_flags); - + num = usernum - 1; setbfile(buf, bname, STR_new_flags); - if((fd = open(buf, O_RDWR | O_CREAT, 0600)) == -1) + if ((fd = open(buf, O_RDWR | O_CREAT, 0600)) == -1) return -1; size = lseek(fd, 0, SEEK_END); memset(buf, 0, sizeof(buf)); - while(size <= num) { + while (size <= num) { write(fd, buf, sizeof(buf)); size += sizeof(buf); } lseek(fd, num, SEEK_SET); read(fd, &flag, 1); - if(flag == 0 && val != 0) { + if (flag == 0 && val != 0) { lseek(fd, num, SEEK_SET); write(fd, &val, 1); } @@ -740,28 +758,32 @@ static int vote_flag(char *bname, int index, char val) { return flag; } -static int same(char compare, char list[], int num) { - int n; - int rep = 0; +static int +same(char compare, char list[], int num) +{ + int n; + int rep = 0; - for(n = 0; n < num; n++) { - if(compare == list[n]) + for (n = 0; n < num; n++) { + if (compare == list[n]) rep = 1; - if(rep == 1) + if (rep == 1) list[n] = list[n + 1]; } return rep; } -static int user_vote_one(char *bname, int ind) { - FILE* cfp,*fcm; - char buf[STRLEN]; - boardheader_t *fhp; - int pos = 0, i = 0, count = 0, tickets, fd; - char inbuf[80], choices[31], vote[4], chosen[31]; - time_t closetime; - - if(ind) { +static int +user_vote_one(char *bname, int ind) +{ + FILE *cfp, *fcm; + char buf[STRLEN]; + boardheader_t *fhp; + int pos = 0, i = 0, count = 0, tickets, fd; + char inbuf[80], choices[31], vote[4], chosen[31]; + time_t closetime; + + if (ind) { sprintf(STR_new_ballots, "%s%d", STR_bv_ballots, ind); sprintf(STR_new_control, "%s%d", STR_bv_control, ind); sprintf(STR_new_desc, "%s%d", STR_bv_desc, ind); @@ -778,14 +800,14 @@ static int user_vote_one(char *bname, int ind) { } setbfile(buf, bname, STR_new_control); - cfp = fopen(buf,"r"); - if(!cfp) - return FULLUPDATE; + cfp = fopen(buf, "r"); + if (!cfp) + return FULLUPDATE; - setbfile(buf, bname, STR_new_limited); /* Ptt */ - if(dashf(buf)) { + setbfile(buf, bname, STR_new_limited); /* Ptt */ + if (dashf(buf)) { setbfile(buf, bname, FN_CANVOTE); - if(!belong(buf, cuser.userid)) { + if (!belong(buf, cuser.userid)) { fclose(cfp); outs("\n\n對不起! 這是私人投票..你並沒有受邀唷!"); pressanykey(); @@ -796,24 +818,23 @@ static int user_vote_one(char *bname, int ind) { more(buf, YEA); } } - if(vote_flag(bname, ind, '\0')) { + if (vote_flag(bname, ind, '\0')) { outs("\n\n此次投票,你已投過了!"); pressanykey(); return FULLUPDATE; } - setutmpmode(VOTING); setbfile(buf, bname, STR_new_desc); more(buf, YEA); stand_title("投票箱"); - if((pos = getbnum(bname)) <= 0) + if ((pos = getbnum(bname)) <= 0) return 0; fhp = bcache + pos - 1; fgets(inbuf, sizeof(inbuf), cfp); tickets = atoi(inbuf); - fscanf(cfp,"%lu\n", &closetime); + fscanf(cfp, "%lu\n", &closetime); prints("投票方式:確定好您的選擇後,輸入其代碼(A, B, C...)即可。\n" "此次投票你可以投 %1d 票。" @@ -822,61 +843,60 @@ static int user_vote_one(char *bname, int ind) { tickets, ctime(&closetime)); move(5, 0); memset(choices, 0, sizeof(choices)); - memset(chosen , 0, sizeof(chosen)); + memset(chosen, 0, sizeof(chosen)); - while(fgets(inbuf, sizeof(inbuf), cfp)) { + while (fgets(inbuf, sizeof(inbuf), cfp)) { move((count % 15) + 5, (count / 15) * 40); - prints( " %s", strtok(inbuf, "\n\0")); + prints(" %s", strtok(inbuf, "\n\0")); choices[count++] = inbuf[0]; } fclose(cfp); - while(1) { + while (1) { vote[0] = vote[1] = '\0'; move(t_lines - 2, 0); prints("你還可以投 %2d 票", tickets - i); getdata(t_lines - 4, 0, "輸入您的選擇: ", vote, sizeof(vote), DOECHO); *vote = toupper(*vote); - if(vote[0] == '0' || (!vote[0] && !i)) { + if (vote[0] == '0' || (!vote[0] && !i)) { outs("記的再來投喔!!"); break; - } else if(vote[0] == '1' && i) - ; - else if(!vote[0]) + } else if (vote[0] == '1' && i); + else if (!vote[0]) continue; - else if(index(choices, vote[0]) == NULL) /* 無效 */ + else if (index(choices, vote[0]) == NULL) /* 無效 */ continue; - else if(same(vote[0], chosen, i)) { + else if (same(vote[0], chosen, i)) { move(((vote[0] - 'A') % 15) + 5, (((vote[0] - 'A')) / 15) * 40); prints(" "); i--; continue; } else { - if(i == tickets) + if (i == tickets) continue; chosen[i] = vote[0]; - move(((vote[0]-'A') % 15) + 5, (((vote[0] - 'A')) / 15) * 40); + move(((vote[0] - 'A') % 15) + 5, (((vote[0] - 'A')) / 15) * 40); prints("*"); i++; continue; } - - if(vote_flag(bname, ind, vote[0]) != 0) + + if (vote_flag(bname, ind, vote[0]) != 0) prints("重覆投票! 不予計票。"); else { setbfile(buf, bname, STR_new_ballots); - if((fd = open(buf, O_WRONLY | O_CREAT | O_APPEND, 0600)) == 0) + if ((fd = open(buf, O_WRONLY | O_CREAT | O_APPEND, 0600)) == 0) outs("無法投入票匭\n"); else { - struct stat statb; - char buf[3], mycomments[3][74], b_comments[80]; - - for(i = 0; i < 3; i++) + struct stat statb; + char buf[3], mycomments[3][74], b_comments[80]; + + for (i = 0; i < 3; i++) strcpy(mycomments[i], "\n"); flock(fd, LOCK_EX); - for(count = 0; count < 31; count++) { - if(chosen[count]) + for (count = 0; count < 31; count++) { + if (chosen[count]) write(fd, &chosen[count], 1); } flock(fd, LOCK_UN); @@ -884,35 +904,36 @@ static int user_vote_one(char *bname, int ind) { close(fd); getdata(b_lines - 2, 0, "您對這次投票有什麼寶貴的意見嗎?(y/n)[N]", - buf, 3 ,DOECHO); - if(buf[0] == 'Y' || buf[0] == 'y'){ + buf, 3, DOECHO); + if (buf[0] == 'Y' || buf[0] == 'y') { do { - move(5,0);clrtobot(); + move(5, 0); + clrtobot(); outs("請問您對這次投票有什麼寶貴的意見?" "最多三行,按[Enter]結束"); - for(i = 0; (i < 3) && - getdata(7 + i, 0, ":", - mycomments[i], sizeof(mycomments[i]), - DOECHO); i++); - getdata(b_lines-2,0, "(S)儲存 (E)重新來過 " + for (i = 0; (i < 3) && + getdata(7 + i, 0, ":", + mycomments[i], sizeof(mycomments[i]), + DOECHO); i++); + getdata(b_lines - 2, 0, "(S)儲存 (E)重新來過 " "(Q)取消?[S]", buf, 3, LCECHO); - } while(buf[0] == 'E' || buf[0] == 'e'); - if(buf[0] == 'Q' || buf[0] == 'q') + } while (buf[0] == 'E' || buf[0] == 'e'); + if (buf[0] == 'Q' || buf[0] == 'q') break; setbfile(b_comments, bname, STR_new_comments); - if(mycomments[0]) - if((fcm = fopen(b_comments, "a"))){ - fprintf(fcm, - "\033[36m○使用者\033[1;36m %s " - "\033[;36m的建議:\033[m\n", + if (mycomments[0]) + if ((fcm = fopen(b_comments, "a"))) { + fprintf(fcm, + "\033[36m○使用者\033[1;36m %s " + "\033[;36m的建議:\033[m\n", cuser.userid); - for(i = 0; i < 3; i++) + for (i = 0; i < 3; i++) fprintf(fcm, " %s\n", mycomments[i]); fprintf(fcm, "\n"); fclose(fcm); - } + } } - move(b_lines - 1 ,0); + move(b_lines - 1, 0); prints("已完成投票!\n"); } } @@ -922,64 +943,63 @@ static int user_vote_one(char *bname, int ind) { return FULLUPDATE; } -static int user_vote(char *bname) { - int pos; - boardheader_t *fhp; - char buf[STRLEN]; - FILE* fp,*xfp; - int i, x = -1; - char genbuf[STRLEN]; - char inbuf[80]; - - if((pos = getbnum(bname)) <= 0) +static int +user_vote(char *bname) +{ + int pos; + boardheader_t *fhp; + char buf[STRLEN]; + FILE *fp, *xfp; + int i, x = -1; + char genbuf[STRLEN]; + char inbuf[80]; + + if ((pos = getbnum(bname)) <= 0) return 0; - + fhp = bcache + pos - 1; - - move(0,0); + + move(0, 0); clrtobot(); - - if(fhp->bvote == 2 || fhp->bvote == 0) { + + if (fhp->bvote == 2 || fhp->bvote == 0) { outs("\n\n目前並沒有任何投票舉行。"); pressanykey(); return FULLUPDATE; } - - if(!HAS_PERM(PERM_LOGINOK)) { + if (!HAS_PERM(PERM_LOGINOK)) { outs("\n對不起! 您未滿二十歲, 還沒有投票權喔!"); pressanykey(); return FULLUPDATE; } - strcpy(STR_new_control, STR_bv_control); strcpy(STR_new_title, STR_bv_title); setbfile(buf, bname, STR_new_control); move(0, 0); - if((fp = fopen(buf, "r"))) { + if ((fp = fopen(buf, "r"))) { prints("(0) "); x = 0; fclose(fp); setbfile(buf, bname, STR_new_title); - if((xfp = fopen(buf,"r"))) + if ((xfp = fopen(buf, "r"))) fgets(inbuf, sizeof(inbuf), xfp); else strcpy(inbuf, "無標題"); prints("%s\n", inbuf); fclose(xfp); } - - for(i = 1; i < 20; i++) { + for (i = 1; i < 20; i++) { sprintf(STR_new_control, "%s%d", STR_bv_control, i); sprintf(STR_new_title, "%s%d", STR_bv_title, i); setbfile(buf, bname, STR_new_control); - if((fp = fopen(buf, "r"))) { + if ((fp = fopen(buf, "r"))) { prints("(%d) ", i); x = i; fclose(fp); - + setbfile(buf, bname, STR_new_title); - if((xfp = fopen(buf, "r"))) + if ((xfp = fopen(buf, "r"))) fgets(inbuf, sizeof(inbuf), xfp); else strcpy(inbuf, "無標題"); @@ -987,49 +1007,57 @@ static int user_vote(char *bname) { fclose(xfp); } } - - if(x < 0) + + if (x < 0) return FULLUPDATE; - + sprintf(buf, "要投幾號投票 [%d] ", x); - + getdata(b_lines - 1, 0, buf, genbuf, 4, LCECHO); - - if(atoi(genbuf) < 0 || atoi(genbuf) > 20) - sprintf(genbuf,"%d",x); - - if(genbuf[0] != '0') + + if (atoi(genbuf) < 0 || atoi(genbuf) > 20) + sprintf(genbuf, "%d", x); + + if (genbuf[0] != '0') sprintf(STR_new_control, "%s%d", STR_bv_control, atoi(genbuf)); else strcpy(STR_new_control, STR_bv_control); - + setbfile(buf, bname, STR_new_control); - if((fp = fopen(buf, "r"))){ + if ((fp = fopen(buf, "r"))) { fclose(fp); - + return user_vote_one(bname, atoi(genbuf)); } else return FULLUPDATE; } -static int vote_results(char *bname) { - char buf[STRLEN]; +static int +vote_results(char *bname) +{ + char buf[STRLEN]; setbfile(buf, bname, STR_bv_results); - if(more(buf, YEA) == -1) + if (more(buf, YEA) == -1) outs("\n目前沒有任何投票的結果。"); return FULLUPDATE; } -int b_vote_maintain() { +int +b_vote_maintain() +{ return vote_maintain(currboard); } -int b_vote() { +int +b_vote() +{ return user_vote(currboard); } -int b_results() { +int +b_results() +{ return vote_results(currboard); } diff --git a/pttbbs/mbbsd/voteboard.c b/pttbbs/mbbsd/voteboard.c index 3d35cead..e720d920 100644 --- a/pttbbs/mbbsd/voteboard.c +++ b/pttbbs/mbbsd/voteboard.c @@ -1,83 +1,84 @@ -/* $Id: voteboard.c,v 1.8 2002/06/19 13:32:23 lwms Exp $ */ +/* $Id: voteboard.c,v 1.9 2002/07/05 17:10:28 in2 Exp $ */ #include "bbs.h" #define VOTEBOARD "NewBoard" -void do_voteboardreply(fileheader_t *fhdr){ - char genbuf[1024]; - char reason[50]; - char fpath[80]; - char oldfpath[80]; - char opnion[10]; - char *ptr; - FILE *fo, *fp; - fileheader_t votefile; - int len; - int i, j; - int fd; - time_t endtime; - int hastime = 0; - +void +do_voteboardreply(fileheader_t * fhdr) +{ + char genbuf[1024]; + char reason[50]; + char fpath[80]; + char oldfpath[80]; + char opnion[10]; + char *ptr; + FILE *fo, *fp; + fileheader_t votefile; + int len; + int i, j; + int fd; + time_t endtime; + int hastime = 0; + clear(); - if(!(currmode & MODE_POST)) { + if (!(currmode & MODE_POST)) { move(5, 10); outs("對不起,您目前無法在此發表文章!"); pressanykey(); return; - } - + } setbpath(fpath, currboard); stampfile(fpath, &votefile); setbpath(oldfpath, currboard); - + strcat(oldfpath, "/"); strcat(oldfpath, fhdr->filename); - + fp = fopen(oldfpath, "r"); - + len = strlen(cuser.userid); - - while(fgets(genbuf, 1024, fp)){ - if (!strncmp(genbuf, "連署結束時間", 12)){ + + while (fgets(genbuf, 1024, fp)) { + if (!strncmp(genbuf, "連署結束時間", 12)) { hastime = 1; ptr = strchr(genbuf, '('); - sscanf(ptr+1, "%ld", &endtime); - if (endtime < now){ + sscanf(ptr + 1, "%ld", &endtime); + if (endtime < now) { prints("連署時間已過"); pressanykey(); fclose(fp); return; } } - if (!strncmp(genbuf+4, cuser.userid, len)){ + if (!strncmp(genbuf + 4, cuser.userid, len)) { move(5, 10); prints("您已經連署過本篇了"); opnion[0] = 'n'; getdata(7, 0, "要修改您之前的連署嗎?(Y/N) [N]", opnion, 3, LCECHO); - if (opnion[0] != 'y'){ + if (opnion[0] != 'y') { fclose(fp); return; } - strcpy(reason, genbuf+19); + strcpy(reason, genbuf + 19); } } - fclose(fp); - - if((fd = open(oldfpath, O_RDONLY)) == -1) + fclose(fp); + + if ((fd = open(oldfpath, O_RDONLY)) == -1) return; flock(fd, LOCK_EX); - + fo = fopen(fpath, "w"); - + if (!fo) return; i = 0; - while(fo){ + while (fo) { j = 0; - do{ - if (read(fd, genbuf+j, 1)<=0){ + do { + if (read(fd, genbuf + j, 1) <= 0) { flock(fd, LOCK_UN); close(fd); fclose(fo); @@ -85,114 +86,113 @@ void do_voteboardreply(fileheader_t *fhdr){ return; } j++; - }while(genbuf[j-1] !='\n'); - genbuf[j] = '\0'; + } while (genbuf[j - 1] != '\n'); + genbuf[j] = '\0'; i++; if (!strncmp("----------", genbuf, 10)) break; if (i > 3) prints(genbuf); - fprintf(fo, "%s", genbuf); + fprintf(fo, "%s", genbuf); } - if (!hastime){ - now += 14*24*60*60; + if (!hastime) { + now += 14 * 24 * 60 * 60; fprintf(fo, "連署結束時間: (%ld)%s", now, ctime(&now)); - now -= 14*24*60*60; + now -= 14 * 24 * 60 * 60; } - fprintf(fo, "%s", genbuf); - do{ - if (!getdata(18, 0, "請問您 (Y)支持 (N)反對 這個議題:", opnion, 3, LCECHO)){ + do { + if (!getdata(18, 0, "請問您 (Y)支持 (N)反對 這個議題:", opnion, 3, LCECHO)) { flock(fd, LOCK_UN); - close(fd); + close(fd); fclose(fo); unlink(fpath); return; } - }while(opnion[0] != 'y' && opnion[0] != 'n'); - + } while (opnion[0] != 'y' && opnion[0] != 'n'); + if (!getdata(20, 0, "請問您與這個議題的關係或連署理由為何:", - reason, sizeof(reason), DOECHO)){ + reason, sizeof(reason), DOECHO)) { flock(fd, LOCK_UN); - close(fd); + close(fd); fclose(fo); unlink(fpath); - return; + return; } - i = 0; - - while(fo){ + + while (fo) { i++; j = 0; - do{ - if (read(fd, genbuf+j, 1)<=0){ + do { + if (read(fd, genbuf + j, 1) <= 0) { flock(fd, LOCK_UN); close(fd); fclose(fo); unlink(fpath); return; - } + } j++; - }while(genbuf[j-1] !='\n'); + } while (genbuf[j - 1] != '\n'); genbuf[j] = '\0'; if (!strncmp("----------", genbuf, 10)) break; - if (strncmp(genbuf+4, cuser.userid, len)) - fprintf(fo, "%3d.%s", i, genbuf+4); + if (strncmp(genbuf + 4, cuser.userid, len)) + fprintf(fo, "%3d.%s", i, genbuf + 4); else i--; } if (opnion[0] == 'y') - fprintf(fo, "%3d.%-15s%-34s 來源:%s\n", i, cuser.userid, reason,cuser.lasthost); + fprintf(fo, "%3d.%-15s%-34s 來源:%s\n", i, cuser.userid, reason, cuser.lasthost); i = 0; fprintf(fo, "%s", genbuf); - while(fo){ + while (fo) { i++; j = 0; - do{ - if (!read(fd, genbuf+j, 1)) + do { + if (!read(fd, genbuf + j, 1)) break; j++; - }while(genbuf[j-1] !='\n'); + } while (genbuf[j - 1] != '\n'); genbuf[j] = '\0'; if (j <= 3) - break; - if (strncmp(genbuf+4, cuser.userid, len)) - fprintf(fo, "%3d.%s", i, genbuf+4); + break; + if (strncmp(genbuf + 4, cuser.userid, len)) + fprintf(fo, "%3d.%s", i, genbuf + 4); else i--; } if (opnion[0] == 'n') - fprintf(fo, "%3d.%-15s%-34s 來源:%s\n", i, cuser.userid, reason,cuser.lasthost); - flock(fd, LOCK_UN); + fprintf(fo, "%3d.%-15s%-34s 來源:%s\n", i, cuser.userid, reason, cuser.lasthost); + flock(fd, LOCK_UN); close(fd); fclose(fo); unlink(oldfpath); rename(fpath, oldfpath); #ifdef MDCACHE close(updatemdcache(NULL, oldfpath)); -#endif +#endif } -int do_voteboard() { - fileheader_t votefile; - char topic[100]; - char title[80]; - char genbuf[1024]; - char fpath[80]; - FILE* fp; - int temp, i; +int +do_voteboard() +{ + fileheader_t votefile; + char topic[100]; + char title[80]; + char genbuf[1024]; + char fpath[80]; + FILE *fp; + int temp, i; clear(); - if(!(currmode & MODE_POST)) { + if (!(currmode & MODE_POST)) { move(5, 10); outs("對不起,您目前無法在此發表文章!"); pressanykey(); return FULLUPDATE; - } - + } move(0, 0); clrtobot(); prints("您正在使用 PTT 的連署系統\n"); @@ -200,23 +200,23 @@ int do_voteboard() { prints("任意提出連署案者,將被列入本系統不受歡迎使用者喔\n"); pressanykey(); move(0, 0); - clrtobot(); + clrtobot(); prints("(1)申請新板 (2)廢除舊板 (3)連署板主 (4)罷免板主\n"); if (!strcmp(currboard, VOTEBOARD)) prints("(5)連署小組長 (6)罷免小組長 "); if (!strcmp(currboard, VOTEBOARD) && HAS_PERM(PERM_SYSOP)) prints("(7)站民公投"); prints("(8)申請新群組"); - - do{ + + do { getdata(3, 0, "請輸入連署類別:", topic, 3, DOECHO); temp = atoi(topic); - }while(temp <= 0 && temp >= 9); - - switch(temp){ - case 1: - do{ - if (!getdata(4, 0, "請輸入看板英文名稱:", topic, IDLEN+1, DOECHO)) + } while (temp <= 0 && temp >= 9); + + switch (temp) { + case 1: + do { + if (!getdata(4, 0, "請輸入看板英文名稱:", topic, IDLEN + 1, DOECHO)) return FULLUPDATE; else if (invalid_brdname(topic)) outs("不是正確的看板名稱"); @@ -224,198 +224,198 @@ int do_voteboard() { outs("本名稱已經存在"); else break; - }while(temp > 0); + } while (temp > 0); sprintf(title, "[申請新板] %s", topic); - sprintf(genbuf, "%s\n\n%s%s\n%s","申請新板", "英文名稱: ", topic, "中文名稱: "); - + sprintf(genbuf, "%s\n\n%s%s\n%s", "申請新板", "英文名稱: ", topic, "中文名稱: "); + if (!getdata(5, 0, "請輸入看板中文名稱:", topic, 20, DOECHO)) return FULLUPDATE; strcat(genbuf, topic); strcat(genbuf, "\n看板類別: "); if (!getdata(6, 0, "請輸入看板類別:", topic, 20, DOECHO)) return FULLUPDATE; - strcat(genbuf, topic); + strcat(genbuf, topic); strcat(genbuf, "\n板主名單: "); getdata(7, 0, "請輸入板主名單:", topic, IDLEN * 3 + 3, DOECHO); strcat(genbuf, topic); strcat(genbuf, "\n申請原因: \n"); outs("請輸入申請原因(至多五行),要清楚填寫不然不會核准喔"); - for(i= 8;i<13;i++){ + for (i = 8; i < 13; i++) { if (!getdata(i, 0, ":", topic, 60, DOECHO)) break; strcat(genbuf, topic); strcat(genbuf, "\n"); } - if (i==8) + if (i == 8) return FULLUPDATE; break; case 2: - do{ - if (!getdata(4, 0, "請輸入看板英文名稱:", topic, IDLEN+1, DOECHO)) + do { + if (!getdata(4, 0, "請輸入看板英文名稱:", topic, IDLEN + 1, DOECHO)) return FULLUPDATE; else if (getbnum(topic) <= 0) outs("本名稱並不存在"); else break; - }while(temp > 0); + } while (temp > 0); sprintf(title, "[廢除舊板] %s", topic); - sprintf(genbuf, "%s\n\n%s%s\n","廢除舊板", "英文名稱: ", topic); + sprintf(genbuf, "%s\n\n%s%s\n", "廢除舊板", "英文名稱: ", topic); strcat(genbuf, "\n廢除原因: \n"); outs("請輸入廢除原因(至多五行),要清楚填寫不然不會核准喔"); - for(i= 8;i<13;i++){ + for (i = 8; i < 13; i++) { if (!getdata(i, 0, ":", topic, 60, DOECHO)) break; strcat(genbuf, topic); strcat(genbuf, "\n"); } - if (i==8) + if (i == 8) return FULLUPDATE; - + break; - case 3: - do{ - if (!getdata(4, 0, "請輸入看板英文名稱:", topic, IDLEN+1, DOECHO)) + case 3: + do { + if (!getdata(4, 0, "請輸入看板英文名稱:", topic, IDLEN + 1, DOECHO)) return FULLUPDATE; else if (getbnum(topic) <= 0) outs("本名稱並不存在"); else break; - }while(temp > 0); + } while (temp > 0); sprintf(title, "[連署板主] %s", topic); - sprintf(genbuf, "%s\n\n%s%s\n%s%s","連署板主", "英文名稱: ", topic, "申請 ID : ", cuser.userid); + sprintf(genbuf, "%s\n\n%s%s\n%s%s", "連署板主", "英文名稱: ", topic, "申請 ID : ", cuser.userid); strcat(genbuf, "\n申請政見: \n"); outs("請輸入申請政見(至多五行),要清楚填寫不然不會核准喔"); - for(i= 8;i<13;i++){ + for (i = 8; i < 13; i++) { if (!getdata(i, 0, ":", topic, 60, DOECHO)) break; strcat(genbuf, topic); strcat(genbuf, "\n"); } - if (i==8) - return FULLUPDATE; - break; - case 4: - do{ - if (!getdata(4, 0, "請輸入看板英文名稱:", topic, IDLEN+1, DOECHO)) + if (i == 8) + return FULLUPDATE; + break; + case 4: + do { + if (!getdata(4, 0, "請輸入看板英文名稱:", topic, IDLEN + 1, DOECHO)) return FULLUPDATE; else if ((i = getbnum(topic)) <= 0) outs("本名稱並不存在"); else break; - }while(temp > 0); + } while (temp > 0); sprintf(title, "[罷免板主] %s", topic); - sprintf(genbuf, "%s\n\n%s%s\n%s","罷免板主", "英文名稱: ", topic, "板主 ID : "); - do{ + sprintf(genbuf, "%s\n\n%s%s\n%s", "罷免板主", "英文名稱: ", topic, "板主 ID : "); + do { if (!getdata(6, 0, "請輸入板主ID:", topic, IDLEN + 1, DOECHO)) return FULLUPDATE; - else if (!userid_is_BM(topic, bcache[i-1].BM)) + else if (!userid_is_BM(topic, bcache[i - 1].BM)) outs("不是該板的板主"); else break; - }while(temp > 0); + } while (temp > 0); strcat(genbuf, topic); strcat(genbuf, "\n罷免原因: \n"); outs("請輸入罷免原因(至多五行),要清楚填寫不然不會核准喔"); - for(i= 8;i<13;i++){ + for (i = 8; i < 13; i++) { if (!getdata(i, 0, ":", topic, 60, DOECHO)) break; strcat(genbuf, topic); strcat(genbuf, "\n"); } - if (i==8) + if (i == 8) return FULLUPDATE; - break; - case 5: + break; + case 5: if (!getdata(4, 0, "請輸入小組中英文名稱:", topic, 30, DOECHO)) return FULLUPDATE; sprintf(title, "[連署小組長] %s", topic); - sprintf(genbuf, "%s\n\n%s%s\n%s%s","連署小組長", "小組名稱: ", topic, "申請 ID : ", cuser.userid); + sprintf(genbuf, "%s\n\n%s%s\n%s%s", "連署小組長", "小組名稱: ", topic, "申請 ID : ", cuser.userid); strcat(genbuf, "\n申請政見: \n"); outs("請輸入申請政見(至多五行),要清楚填寫不然不會核准喔"); - for(i= 8;i<13;i++){ + for (i = 8; i < 13; i++) { if (!getdata(i, 0, ":", topic, 60, DOECHO)) break; strcat(genbuf, topic); strcat(genbuf, "\n"); } - if (i==8) + if (i == 8) return FULLUPDATE; break; case 6: - + if (!getdata(4, 0, "請輸入小組中英文名稱:", topic, 30, DOECHO)) return FULLUPDATE; sprintf(title, "[罷免小組長] %s", topic); - sprintf(genbuf, "%s\n\n%s%s\n%s","罷免小組長", "小組名稱: ", topic, "小組長 ID : "); + sprintf(genbuf, "%s\n\n%s%s\n%s", "罷免小組長", "小組名稱: ", topic, "小組長 ID : "); if (!getdata(6, 0, "請輸入小組長ID:", topic, IDLEN + 1, DOECHO)) return FULLUPDATE; strcat(genbuf, topic); strcat(genbuf, "\n罷免原因: \n"); outs("請輸入罷免原因(至多五行),要清楚填寫不然不會核准喔"); - for(i= 8;i<13;i++){ + for (i = 8; i < 13; i++) { if (!getdata(i, 0, ":", topic, 60, DOECHO)) break; strcat(genbuf, topic); strcat(genbuf, "\n"); } - if (i==8) + if (i == 8) return FULLUPDATE; - break; - case 7: + break; + case 7: if (!HAS_PERM(PERM_SYSOP)) return FULLUPDATE; if (!getdata(4, 0, "請輸入公投主題:", topic, 30, DOECHO)) return FULLUPDATE; sprintf(title, "%s %s", "[站民公投]", topic); - sprintf(genbuf, "%s\n\n%s%s\n","站民公投", "公投主題: ", topic); + sprintf(genbuf, "%s\n\n%s%s\n", "站民公投", "公投主題: ", topic); strcat(genbuf, "\n公投原因: \n"); outs("請輸入公投原因(至多五行),要清楚填寫不然不會核准喔"); - for(i= 8;i<13;i++){ + for (i = 8; i < 13; i++) { if (!getdata(i, 0, ":", topic, 60, DOECHO)) break; strcat(genbuf, topic); strcat(genbuf, "\n"); } - if (i==8) + if (i == 8) return FULLUPDATE; - break; + break; case 8: - if(!getdata(4, 0, "請輸入群組中英文名稱:", topic, 30, DOECHO)) + if (!getdata(4, 0, "請輸入群組中英文名稱:", topic, 30, DOECHO)) return FULLUPDATE; sprintf(title, "[申請新群組] %s", topic); - sprintf(genbuf, "%s\n\n%s%s\n%s%s","申請群組", "群組名稱: ", topic, "申請 ID : ", cuser.userid); + sprintf(genbuf, "%s\n\n%s%s\n%s%s", "申請群組", "群組名稱: ", topic, "申請 ID : ", cuser.userid); strcat(genbuf, "\n申請政見: \n"); outs("請輸入申請政見(至多五行),要清楚填寫不然不會核准喔"); - for(i= 8;i<13;i++){ + for (i = 8; i < 13; i++) { if (!getdata(i, 0, ":", topic, 60, DOECHO)) break; strcat(genbuf, topic); strcat(genbuf, "\n"); } - if (i==8) + if (i == 8) return FULLUPDATE; break; default: return FULLUPDATE; } strcat(genbuf, "連署結束時間: "); - now += 14*24*60*60; + now += 14 * 24 * 60 * 60; sprintf(topic, "(%ld)", now); strcat(genbuf, topic); strcat(genbuf, ctime(&now)); - now -= 14*24*60*60; + now -= 14 * 24 * 60 * 60; strcat(genbuf, "----------支持----------\n"); - strcat(genbuf, "----------反對----------\n"); + strcat(genbuf, "----------反對----------\n"); outs("開始連署嘍"); setbpath(fpath, currboard); stampfile(fpath, &votefile); - - if (!(fp = fopen(fpath, "w"))){ + + if (!(fp = fopen(fpath, "w"))) { outs("開檔失敗,請稍候重來一次"); return FULLUPDATE; } fprintf(fp, "%s%s %s%s\n%s%s\n%s%s", "作者: ", cuser.userid, - "看板: ", currboard, + "看板: ", currboard, "標題: ", title, "時間: ", ctime(&now)); fprintf(fp, "%s\n", genbuf); @@ -423,7 +423,7 @@ int do_voteboard() { strcpy(votefile.owner, cuser.userid); strcpy(votefile.title, title); setbdir(genbuf, currboard); - if(append_record(genbuf, &votefile, sizeof(votefile)) != -1) + if (append_record(genbuf, &votefile, sizeof(votefile)) != -1) setbtotal(currbid); do_voteboardreply(&votefile); return FULLUPDATE; diff --git a/pttbbs/mbbsd/xyz.c b/pttbbs/mbbsd/xyz.c index 3a14b4b5..21701df8 100644 --- a/pttbbs/mbbsd/xyz.c +++ b/pttbbs/mbbsd/xyz.c @@ -1,9 +1,11 @@ -/* $Id: xyz.c,v 1.9 2002/06/19 13:32:23 lwms Exp $ */ +/* $Id: xyz.c,v 1.10 2002/07/05 17:10:28 in2 Exp $ */ #include "bbs.h" /* 各種統計及相關資訊列表 */ /* Ptt90年度大學聯招查榜系統 */ -int x_90() { +int +x_90() +{ strcpy(dict, "(90)准考證號/姓名/學校/科系/類組"); strcpy(database, "etc/90"); use_dict(); @@ -11,221 +13,258 @@ int x_90() { } /* Ptt89年度大學聯招查榜系統 */ -int x_89() { +int +x_89() +{ strcpy(dict, "(89)准考證號/姓名/學校/科系/類組"); strcpy(database, "etc/89"); use_dict(); return 0; } /* Ptt88年度大學聯招查榜系統 */ -int x_88() { +int +x_88() +{ strcpy(dict, "(88)准考證號/姓名/學校/科系/類組"); strcpy(database, "etc/88"); use_dict(); return 0; -} +} /* Ptt87年度大學聯招查榜系統 */ -int x_87() { +int +x_87() +{ strcpy(dict, "(87)准考證號/姓名/學校/科系"); strcpy(database, "etc/87"); use_dict(); return 0; -} +} /* Ptt86年度大學聯招查榜系統 */ -int x_86() { +int +x_86() +{ strcpy(dict, "(86)准考證號/姓名/學校/科系"); strcpy(database, "etc/86"); use_dict(); return 0; } -int x_boardman() { +int +x_boardman() +{ more("etc/topboardman", YEA); return 0; } -int x_user100() { +int +x_user100() +{ more("etc/topusr100", YEA); return 0; } -int x_history() { +int +x_history() +{ more("etc/history", YEA); return 0; } #ifdef HAVE_X_BOARDS -static int x_boards() { +static int +x_boards() +{ more("etc/topboard.tmp", YEA); return 0; } #endif -int x_birth() { +int +x_birth() +{ more("etc/birth.today", YEA); return 0; } -int x_weather() { +int +x_weather() +{ more("etc/weather.tmp", YEA); return 0; } -int x_stock() { +int +x_stock() +{ more("etc/stock.tmp", YEA); return 0; } -int x_note() { +int +x_note() +{ more(fn_note_ans, YEA); return 0; } -int x_issue() { +int +x_issue() +{ more("etc/day", YEA); return 0; } -int x_week() { +int +x_week() +{ more("etc/week", YEA); return 0; } -int x_today() { +int +x_today() +{ more("etc/today", YEA); return 0; } -int x_yesterday() { +int +x_yesterday() +{ more("etc/yesterday", YEA); return 0; } -int x_login() { +int +x_login() +{ more("etc/Welcome_login.0", YEA); return 0; } #ifdef HAVE_INFO -static int x_program() { +static int +x_program() +{ more("etc/version", YEA); return 0; } #endif #ifdef HAVE_LICENSE -static int x_gpl() { +static int +x_gpl() +{ more("etc/GPL", YEA); return 0; } #endif -int note() { - static char *fn_note_tmp = "note.tmp"; - static char *fn_note_dat = "note.dat"; - int total = 0, i, collect, len; - struct stat st; - char buf[256], buf2[80]; - int fd, fx; - FILE *fp, *foo; +int +note() +{ + static char *fn_note_tmp = "note.tmp"; + static char *fn_note_dat = "note.dat"; + int total = 0, i, collect, len; + struct stat st; + char buf[256], buf2[80]; + int fd, fx; + FILE *fp, *foo; typedef struct notedata_t { - time_t date; - char userid[IDLEN + 1]; - char username[19]; - char buf[3][80]; - } notedata_t; - notedata_t myitem; - - if(cuser.money < 5) { + time_t date; + char userid[IDLEN + 1]; + char username[19]; + char buf[3][80]; + } notedata_t; + notedata_t myitem; + + if (cuser.money < 5) { outmsg("\033[1;41m 哎呀! 要投五銀才能留言...沒錢耶..\033[m"); clrtoeol(); refresh(); return 0; } - setutmpmode(EDNOTE); do { myitem.buf[0][0] = myitem.buf[1][0] = myitem.buf[2][0] = '\0'; move(12, 0); clrtobot(); outs("\n投五銀... 嗶... 請留言 (至多三行),按[Enter]結束"); - for(i = 0; (i < 3) && getdata(16 + i, 0, ":", myitem.buf[i], - sizeof(myitem.buf[i])-5, DOECHO) - && *myitem.buf[i]; i++); + for (i = 0; (i < 3) && getdata(16 + i, 0, ":", myitem.buf[i], + sizeof(myitem.buf[i]) - 5, DOECHO) + && *myitem.buf[i]; i++); getdata(b_lines - 1, 0, "(S)儲存 (E)重新來過 (Q)取消?[S] ", buf, 3, LCECHO); - if(buf[0] == 'q' || (i == 0 && *buf != 'e')) + if (buf[0] == 'q' || (i == 0 && *buf != 'e')) return 0; - } while(buf[0] == 'e'); + } while (buf[0] == 'e'); demoney(-5); strcpy(myitem.userid, cuser.userid); strncpy(myitem.username, cuser.username, 18); myitem.username[18] = '\0'; - myitem.date=now; + myitem.date = now; /* begin load file */ - if((foo = fopen(".note", "a")) == NULL) + if ((foo = fopen(".note", "a")) == NULL) return 0; - if((fp = fopen(fn_note_ans, "w")) == NULL) + if ((fp = fopen(fn_note_ans, "w")) == NULL) return 0; - if((fx = open(fn_note_tmp, O_WRONLY | O_CREAT, 0644)) <= 0) + if ((fx = open(fn_note_tmp, O_WRONLY | O_CREAT, 0644)) <= 0) return 0; - if((fd = open(fn_note_dat, O_RDONLY)) == -1) + if ((fd = open(fn_note_dat, O_RDONLY)) == -1) total = 1; - else if(fstat(fd, &st) != -1) { + else if (fstat(fd, &st) != -1) { total = st.st_size / sizeof(notedata_t) + 1; if (total > MAX_NOTE) total = MAX_NOTE; } - fputs("\033[1;31;44m☉┬──────────────┤" "\033[37m酸甜苦辣板\033[31m├──────────────┬☉" "\033[m\n", fp); collect = 1; - while(total) { + while (total) { sprintf(buf, "\033[1;31m╭┤\033[32m %s \033[37m(%s)", myitem.userid, myitem.username); len = strlen(buf); - for(i = len ; i < 73; i++) + for (i = len; i < 73; i++) strcat(buf, " "); sprintf(buf2, " \033[1;36m%.14s\033[31m ├╮\033[m\n", Cdate(&(myitem.date))); strcat(buf, buf2); fputs(buf, fp); - if(collect) + if (collect) fputs(buf, foo); - for(i = 0 ; i < 3 && *myitem.buf[i]; i++) { - fprintf(fp, "\033[1;31m│\033[m%-74.74s\033[1;31m│\033[m\n", + for (i = 0; i < 3 && *myitem.buf[i]; i++) { + fprintf(fp, "\033[1;31m│\033[m%-74.74s\033[1;31m│\033[m\n", myitem.buf[i]); - if(collect) + if (collect) fprintf(foo, "\033[1;31m│\033[m%-74.74s\033[1;31m│\033[m\n", myitem.buf[i]); - } + } fputs("\033[1;31m╰┬───────────────────────" - "────────────┬╯\033[m\n",fp); + "────────────┬╯\033[m\n", fp); - if(collect) { + if (collect) { fputs("\033[1;31m╰┬─────────────────────" "──────────────┬╯\033[m\n", foo); fclose(foo); collect = 0; } - write(fx, &myitem, sizeof(myitem)); - - if(--total) - read(fd, (char *) &myitem, sizeof(myitem)); + + if (--total) + read(fd, (char *)&myitem, sizeof(myitem)); } fputs("\033[1;31;44m☉┴───────────────────────" - "────────────┴☉\033[m\n",fp); + "────────────┴☉\033[m\n", fp); fclose(fp); close(fd); close(fx); @@ -234,92 +273,97 @@ int note() { return 0; } -static void mail_sysop() { - FILE *fp; - char genbuf[200]; - - if((fp = fopen("etc/sysop", "r"))) { - int i, j; - char *ptr; - +static void +mail_sysop() +{ + FILE *fp; + char genbuf[200]; + + if ((fp = fopen("etc/sysop", "r"))) { + int i, j; + char *ptr; + typedef struct sysoplist_t { - char userid[IDLEN + 1]; - char duty[40]; - } sysoplist_t; - sysoplist_t sysoplist[9]; - + char userid[IDLEN + 1]; + char duty[40]; + } sysoplist_t; + sysoplist_t sysoplist[9]; + j = 0; - while(fgets(genbuf, 128, fp)) { - if((ptr = strchr(genbuf, '\n'))) { + while (fgets(genbuf, 128, fp)) { + if ((ptr = strchr(genbuf, '\n'))) { *ptr = '\0'; - if((ptr = strchr(genbuf, ':'))) { + if ((ptr = strchr(genbuf, ':'))) { *ptr = '\0'; do { i = *++ptr; - } while(i == ' ' || i == '\t'); - if(i) { + } while (i == ' ' || i == '\t'); + if (i) { strcpy(sysoplist[j].userid, genbuf); strcpy(sysoplist[j++].duty, ptr); } } } } - + move(12, 0); clrtobot(); prints("%16s %-18s權責劃分\n\n", "編號", "站長 ID"); - for(i = 0; i < j; i++) + for (i = 0; i < j; i++) prints("%15d. \033[1;%dm%-16s%s\033[0m\n", - i + 1, 31 + i % 7, sysoplist[i].userid, sysoplist[i].duty); + i + 1, 31 + i % 7, sysoplist[i].userid, sysoplist[i].duty); prints("%-14s0. \033[1;%dm離開\033[0m", "", 31 + j % 7); getdata(b_lines - 1, 0, " 請輸入代碼[0]:", genbuf, 4, DOECHO); i = genbuf[0] - '0' - 1; - if(i >= 0 && i < j) { + if (i >= 0 && i < j) { clear(); do_send(sysoplist[i].userid, NULL); } } } -int m_sysop() { +int +m_sysop() +{ setutmpmode(MSYSOP); mail_sysop(); return 0; } -int Goodbye() { - char genbuf[100]; +int +Goodbye() +{ + char genbuf[100]; getdata(b_lines - 1, 0, "您確定要離開【 " BBSNAME " 】嗎(Y/N)?[N] ", genbuf, 3, LCECHO); - if(*genbuf != 'y') + if (*genbuf != 'y') return 0; movie(999); - if(cuser.userlevel) { + if (cuser.userlevel) { getdata(b_lines - 1, 0, "(G)隨風而逝 (M)托夢站長 (N)酸甜苦辣流言板?[G] ", genbuf, 3, LCECHO); - if(genbuf[0] == 'm') + if (genbuf[0] == 'm') mail_sysop(); - else if(genbuf[0] == 'n') + else if (genbuf[0] == 'n') note(); } - clear(); prints("\033[1;36m親愛的 \033[33m%s(%s)\033[36m,別忘了再度光臨\033[45;33m" " %s \033[40;36m!\n以下是您在站內的註冊資料:\033[0m\n", cuser.userid, cuser.username, BBSName); user_display(&cuser, 0); pressanykey(); - - more("etc/Logout",NA); + + more("etc/Logout", NA); pressanykey(); u_exit("EXIT "); - return QUIT; + return QUIT; } /* 支援外掛程式 : tin、gopher、www、bbsnet、game、csh */ @@ -334,36 +378,46 @@ int Goodbye() { #define MAXPATHLEN 256 #ifdef HAVE_TIN -static int x_tin() { +static int +x_tin() +{ clear(); return exec_cmd(NEWS, YEA, "bin/tin.sh", "TIN"); } #endif #ifdef HAVE_GOPHER -static int x_gopher() { +static int +x_gopher() +{ clear(); return exec_cmd(GOPHER, YEA, "bin/gopher.sh", "GOPHER"); } #endif #ifdef HAVE_WWW -static int x_www() { +static int +x_www() +{ return exec_cmd(WWW, NA, "bin/www.sh", "WWW"); } #endif #ifdef HAVE_IRC -static int x_irc() { +static int +x_irc() +{ return exec_cmd(XMODE, NA, "bin/irc.sh", "IRC"); } #endif #ifdef HAVE_ARCHIE -static int x_archie() { - char buf[STRLEN], ans[4]; - char genbuf1[100], genbuf2[200]; - char *s; +static int +x_archie() +{ + char buf[STRLEN], ans[4]; + char genbuf1[100], genbuf2[200]; + char *s; setutmpmode(ARCHIE); clear(); @@ -373,18 +427,17 @@ static int x_archie() { outs("\n請輸入欲搜尋的字串, 或直接按 <ENTER> 取消。\n"); outs("\n coder by Harimau\n"); outs(" modified by Leeym\n"); - getdata(13,0,"搜尋字串:",buf,20,DOECHO,0); - if(buf[0]=='\0') { + getdata(13, 0, "搜尋字串:", buf, 20, DOECHO, 0); + if (buf[0] == '\0') { prints("\n取消搜尋.....\n"); pressanykey(); return; } - - for(s = buf; *s != '\0'; s++) { - if(isspace(*s)) { - prints("\n一次只能搜尋一個字串啦, 不能太貪心喔!!"); - pressanykey(); - return; + for (s = buf; *s != '\0'; s++) { + if (isspace(*s)) { + prints("\n一次只能搜尋一個字串啦, 不能太貪心喔!!"); + pressanykey(); + return; } } bbssetenv("ARCHIESTRING", buf); @@ -392,14 +445,14 @@ static int x_archie() { log_usies("ARCHIE", ""); strcpy(genbuf1, buf); sprintf(buf, BBSHOME "/tmp/archie.%s", cuser.userid); - if(dashf(buf)) { + if (dashf(buf)) { getdata(0, 0, "要將結果寄回信箱嗎(Y/N)?[N]", ans, sizeof(ans), DOECHO, 0); - if(*ans == 'y') { - fileheader_t mhdr; - char title[128], buf1[80]; - FILE* fp; - + if (*ans == 'y') { + fileheader_t mhdr; + char title[128], buf1[80]; + FILE *fp; + sethomepath(buf1, cuser.userid); stampfile(buf1, &mhdr); strcpy(mhdr.owner, cuser.userid); @@ -410,8 +463,8 @@ static int x_archie() { append_record(title, &mhdr, sizeof(mhdr)); Link(buf, buf1); } - more( buf, YEA); - unlink (buf); + more(buf, YEA); + unlink(buf); } } -#endif /* HAVE_ARCHIE */ +#endif /* HAVE_ARCHIE */ -- cgit v1.2.3 From b743f91a71d1b6713cd06ba4bf0c7d43bb839b2f Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sun, 7 Jul 2002 14:36:21 +0000 Subject: register git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@416 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/user.c | 43 ++++++++++++++++++++++++++++++++----------- 1 file changed, 32 insertions(+), 11 deletions(-) diff --git a/pttbbs/mbbsd/user.c b/pttbbs/mbbsd/user.c index f5615a88..ed45b306 100644 --- a/pttbbs/mbbsd/user.c +++ b/pttbbs/mbbsd/user.c @@ -1,4 +1,4 @@ -/* $Id: user.c,v 1.28 2002/07/05 17:10:28 in2 Exp $ */ +/* $Id: user.c,v 1.29 2002/07/07 14:36:21 in2 Exp $ */ #include "bbs.h" static char *sex[8] = { @@ -1045,22 +1045,43 @@ u_register(void) while (1) { getfield(7, "學校(含\033[1;33m系所年級\033[m)或單位職稱", "服務單位", career, 40); - if (removespace(career) && career[0] < 0 && strlen(career) >= 4) - break; - vmsg("您的輸入不正確"); + if(!(removespace(career) && career[0] < 0 && strlen(career) >= 4)){ + vmsg("您的輸入不正確"); + continue; + } + if( strcmp(&career[strlen(career) - 2], "大") == 0 || + strcmp(&career[strlen(career) - 4], "大學") == 0 ){ + vmsg("麻煩請加系所"); + continue; + } + break; } while (1) { - getfield(9, "含縣市及門寢號碼(台北請加\033[1;33m行政區\033[m)", + getfield(9, "含\033[1;33m縣市\033[m及門寢號碼" + "(台北請加\033[1;33m行政區\033[m)", "目前住址", addr, 50); - if (removespace(addr) && addr[0] < 0 && strlen(addr) >= 15) - break; - vmsg("這個地址並不合法"); + if( !removespace(addr) || addr[0] > 0 || strlen(addr) < 15 ){ + vmsg("這個地址並不合法"); + continue; + } + if( strstr(addr, "信箱") != NULL || strstr(addr, "郵政") != NULL ){ + vmsg("抱歉我們不接受郵政信箱"); + continue; + } + if( strstr(addr, "市") == NULL && strstr(addr, "縣") == NULL ){ + vmsg("這個地址並不合法"); + continue; + } + break; } while (1) { getfield(11, "不加-(), 包括長途區號", "連絡電話", phone, 11); - if (removespace(phone) && phone[0] == '0' && strlen(phone) >= 9) - break; - vmsg("這個電話號碼並不合法"); + if( !removespace(phone) || phone[0] != '0' || + strlen(phone) < 9 || phone[1] == '0' ){ + vmsg("這個電話號碼並不合法"); + continue; + } + break; } getfield(13, "只輸入數字 如:0912345678 (可不填)", "手機號碼", mobile, 20); -- cgit v1.2.3 From 1e3962a742facd5fef7a2166d872a29da7597d0b Mon Sep 17 00:00:00 2001 From: ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Wed, 17 Jul 2002 17:09:36 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@417 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/Makefile | 7 +++++-- pttbbs/util/indexuser.c | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 2 deletions(-) create mode 100644 pttbbs/util/indexuser.c diff --git a/pttbbs/util/Makefile b/pttbbs/util/Makefile index 0fc23f70..bfe6429f 100644 --- a/pttbbs/util/Makefile +++ b/pttbbs/util/Makefile @@ -1,4 +1,4 @@ -# $Id: Makefile,v 1.12 2002/06/06 21:35:23 in2 Exp $ +# $Id: Makefile,v 1.13 2002/07/17 17:09:20 ptt Exp $ BBSHOME?=$(HOME) OSTYPE?=linux @@ -30,7 +30,7 @@ CPROGS= bbsmail BM_money post account birth deluserfile expire mandex\ poststat showboard antispam countalldice webgrep bbsrf\ initbbs outmail xchatd userlist tunepasswd buildir reaper shmsweep\ merge_passwd merge_board inndBM buildAnnounce rmuid \ - toplazyBM jungo toplazyBBM shmctl mdclean splitpasswd + toplazyBM jungo toplazyBBM shmctl mdclean splitpasswd indexuser PROGS= $(CPROGS) BM_money.sh backpasswd.sh mailog.sh opendice.sh\ openticket.sh stock.sh topsong.sh weather.sh stock.perl weather.perl\ @@ -87,6 +87,9 @@ openticket: openticket.c $(OBJS) topusr: topusr.c $(OBJS) $(CC) $(CFLAGS) -o $@ $@.c $(OBJS) +indexuser: indexuser.c $(OBJS) + $(CC) $(CFLAGS) -o $@ $@.c $(OBJS) + yearsold: yearsold.c $(OBJS) $(CC) $(CFLAGS) -o $@ $@.c $(OBJS) diff --git a/pttbbs/util/indexuser.c b/pttbbs/util/indexuser.c new file mode 100644 index 00000000..c626303b --- /dev/null +++ b/pttbbs/util/indexuser.c @@ -0,0 +1,41 @@ +#include "bbs.h" +#define INDEXPATH BBSHOME"/index" + +unsigned string_hash(unsigned char *s) +{ + unsigned int v = 0; + while (*s) + { + v = (v << 8) | (v >> 24); + v ^= toupper(*s++); /* note this is case insensitive */ + } + return (v * 2654435769UL) >> (32 - HASH_BITS); +} + + +int main() +{ + int j; + userec_t u; + char buf[256]; + + if(passwd_mmap()) + { + printf("Sorry, the data is not ready.\n"); + exit(0); + } + system("rm -f "INDEXPATH"/realname/* "); + system("rm -f "INDEXPATH"/email/* "); + system("rm -f "INDEXPATH"/ident/* "); + for(j = 1; j <= MAX_USERS; j++) { + passwd_query(j, &u); + if(!u.userid[0]) continue; + sprintf(buf,INDEXPATH"/realname/%X",string_hash(u.realname)); + append_record(buf, &j, sizeof(j)); + sprintf(buf,INDEXPATH"/email/%X",string_hash(u.email)); + append_record(buf, &j, sizeof(j)); + sprintf(buf,INDEXPATH"/ident/%X",string_hash(u.ident)); + append_record(buf, &j, sizeof(j)); + } + return 0; +} -- cgit v1.2.3 From f256ae71eb195f21e344dd26c1d2310bd01794e7 Mon Sep 17 00:00:00 2001 From: ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Wed, 17 Jul 2002 17:16:44 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@418 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/indexuser.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/pttbbs/util/indexuser.c b/pttbbs/util/indexuser.c index c626303b..bd761ccf 100644 --- a/pttbbs/util/indexuser.c +++ b/pttbbs/util/indexuser.c @@ -30,12 +30,21 @@ int main() for(j = 1; j <= MAX_USERS; j++) { passwd_query(j, &u); if(!u.userid[0]) continue; - sprintf(buf,INDEXPATH"/realname/%X",string_hash(u.realname)); - append_record(buf, &j, sizeof(j)); - sprintf(buf,INDEXPATH"/email/%X",string_hash(u.email)); - append_record(buf, &j, sizeof(j)); - sprintf(buf,INDEXPATH"/ident/%X",string_hash(u.ident)); - append_record(buf, &j, sizeof(j)); + if(u.realname[0]) + { + sprintf(buf,INDEXPATH"/realname/%X",string_hash(u.realname)); + append_record(buf, &j, sizeof(j)); + } + if(u.email[0]) + { + sprintf(buf,INDEXPATH"/email/%X",string_hash(u.email)); + append_record(buf, &j, sizeof(j)); + } + if(u.ident[0]) + { + sprintf(buf,INDEXPATH"/ident/%X",string_hash(u.ident)); + append_record(buf, &j, sizeof(j)); + } } return 0; } -- cgit v1.2.3 From 4adca7ccca149b4bbc7d602e734bca21db0006cc Mon Sep 17 00:00:00 2001 From: ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Wed, 17 Jul 2002 17:19:23 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@419 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/indexuser.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/pttbbs/util/indexuser.c b/pttbbs/util/indexuser.c index bd761ccf..4991b919 100644 --- a/pttbbs/util/indexuser.c +++ b/pttbbs/util/indexuser.c @@ -24,9 +24,12 @@ int main() printf("Sorry, the data is not ready.\n"); exit(0); } - system("rm -f "INDEXPATH"/realname/* "); - system("rm -f "INDEXPATH"/email/* "); - system("rm -f "INDEXPATH"/ident/* "); + system("rm -rf "INDEXPATH"/realname"); + system("rm -rf "INDEXPATH"/email"); + system("rm -rf "INDEXPATH"/ident"); + mkdir(INDEXPATH"/realname",0600); + mkdir(INDEXPATH"/email",0600); + mkdir(INDEXPATH"/ident",0600); for(j = 1; j <= MAX_USERS; j++) { passwd_query(j, &u); if(!u.userid[0]) continue; -- cgit v1.2.3 From a1949fa27a614a7ea7fcac0375b32b9f091c23fc Mon Sep 17 00:00:00 2001 From: ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Wed, 17 Jul 2002 17:20:46 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@420 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/indexuser.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pttbbs/util/indexuser.c b/pttbbs/util/indexuser.c index 4991b919..3668269a 100644 --- a/pttbbs/util/indexuser.c +++ b/pttbbs/util/indexuser.c @@ -27,9 +27,9 @@ int main() system("rm -rf "INDEXPATH"/realname"); system("rm -rf "INDEXPATH"/email"); system("rm -rf "INDEXPATH"/ident"); - mkdir(INDEXPATH"/realname",0600); - mkdir(INDEXPATH"/email",0600); - mkdir(INDEXPATH"/ident",0600); + mkdir(INDEXPATH"/realname",0700); + mkdir(INDEXPATH"/email",0700); + mkdir(INDEXPATH"/ident",0700); for(j = 1; j <= MAX_USERS; j++) { passwd_query(j, &u); if(!u.userid[0]) continue; -- cgit v1.2.3 From bf69bb42e4e80379c0e46ed1257889622c058f82 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Fri, 19 Jul 2002 18:01:39 +0000 Subject: remove MULTI_SERVER git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@421 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/include/pttstruct.h | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/pttbbs/include/pttstruct.h b/pttbbs/include/pttstruct.h index a6e71118..56d262e6 100644 --- a/pttbbs/include/pttstruct.h +++ b/pttbbs/include/pttstruct.h @@ -1,4 +1,4 @@ -/* $Id: pttstruct.h,v 1.24 2002/07/05 17:10:23 in2 Exp $ */ +/* $Id: pttstruct.h,v 1.25 2002/07/19 18:01:39 in2 Exp $ */ #ifndef INCLUDE_STRUCT_H #define INCLUDE_STRUCT_H @@ -246,9 +246,6 @@ typedef struct userinfo_t { int sex; char color; char mind[4]; -#ifdef MULTI_SERVER - char hostid; -#endif } userinfo_t; typedef struct water_t { -- cgit v1.2.3 From 6f205556417428ca2a22b59755bf8dd7d1855014 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sat, 20 Jul 2002 08:36:26 +0000 Subject: error return git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@422 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/waterball.pl | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/pttbbs/util/waterball.pl b/pttbbs/util/waterball.pl index 7f49d3c5..63443027 100644 --- a/pttbbs/util/waterball.pl +++ b/pttbbs/util/waterball.pl @@ -127,7 +127,7 @@ sub MakeMail `$TAR zcf $arg->{tartarget} $arg->{tarsource}` if( $arg->{tarsource} ); $sender = new Mail::Sender{smtp => $SMTPSERVER, - from => "$hostname水球整理程式 <in2\@ptt2.csie.ntu.edu.tw>"}; + from => "$hostname水球整理程式 <$userid.bbs\@ptt2.csie.ntu.edu.tw>"}; foreach( 0..3 ){ if( (!$arg->{tartarget} && $sender->MailMsg({to => $arg->{mailto}, @@ -143,7 +143,12 @@ sub MakeMail return 1; } } - print "fault\n"; + $sender->MailMsg({to => "$userid.bbs\@localhost", + subject => "無法寄出水球整理", + msg => + "親愛的使用者您好\n\n". + "你的水球整理記錄無法寄達指定位置 $mailto \n\n". + "$hostname站長群 敬上 ".POSIX::ctime(time())}); unlink $arg->{tartarget} if( $arg->{tartarget} ); - return 0; + return 1; } -- cgit v1.2.3 From 0241cf009abeab3b9ece05ee56c55657be986061 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sat, 20 Jul 2002 08:51:00 +0000 Subject: mail_waterball git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@423 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/mail.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/pttbbs/mbbsd/mail.c b/pttbbs/mbbsd/mail.c index d6d4e3d9..7c88cd1b 100644 --- a/pttbbs/mbbsd/mail.c +++ b/pttbbs/mbbsd/mail.c @@ -1,4 +1,4 @@ -/* $Id: mail.c,v 1.18 2002/07/05 17:10:27 in2 Exp $ */ +/* $Id: mail.c,v 1.19 2002/07/20 08:51:00 in2 Exp $ */ #include "bbs.h" char currmaildir[32]; static char msg_cc[] = "\033[32m[群組名單]\033[m\n"; @@ -297,8 +297,7 @@ do_send(char *userid, char *title) i = belong(fpath, cuser.userid); sethomefile(fpath, userid, FN_REJECT); - if (i || !belong(fpath, cuser.userid)) - //Ptt: 用belong 麻I Q + if (i || !belong(fpath, cuser.userid)) /* Ptt: 用belong有點討厭 */ { sethomedir(fpath, userid); if (append_record(fpath, &mhdr, sizeof(mhdr)) == -1) @@ -1291,13 +1290,13 @@ mail_waterball(int ent, fileheader_t * fhdr, char *direct) } if (!address[0]) strcpy(address, cuser.email); - move(b_lines - 5, 0); + move(b_lines - 8, 0); outs("水球整理程式:\n" "系統將會按照和不同人丟的水球各自獨立\n" "於整點的時候 (尖鋒時段除外) 將資料整理好寄送給您\n\n\n"); if (address[0]) { sprintf(genbuf, "寄給 [%s] 嗎(Y/N/Q)?[Y] ", address); - getdata(b_lines - 2, 0, genbuf, fname, 3, LCECHO); + getdata(b_lines - 5, 0, genbuf, fname, 3, LCECHO); if (fname[0] == 'q') { outmsg("取消處理"); return 1; @@ -1306,7 +1305,7 @@ mail_waterball(int ent, fileheader_t * fhdr, char *direct) address[0] = '\0'; } if (!address[0]) { - getdata(b_lines - 2, 0, "請輸入郵件地址:", fname, 60, DOECHO); + getdata(b_lines - 5, 0, "請輸入郵件地址:", fname, 60, DOECHO); if (fname[0] && strchr(fname, '.')) { strcpy(address, fname); } else { @@ -1318,6 +1317,10 @@ mail_waterball(int ent, fileheader_t * fhdr, char *direct) return -2; //sprintf(fname, "%d\n", cmode); + move(b_lines - 4, 0); + outs("系統提供兩種模式: \n" + "模式 0: 精簡模式, 將不含顏色控制碼, 方便以純文字編輯器整理收藏\n" + "模式 1: 華麗模式, 包含顏色控制碼等, 方便在 bbs上直接編輯收藏\n"); getdata(b_lines - 1, 0, "使用模式(0/1/Q)? [1]", fname, 3, LCECHO); if (fname[0] == 'Q' || fname[0] == 'q') { outmsg("取消處理"); -- cgit v1.2.3 From a53621927c7a954bea4791c3080a17b89766f636 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sat, 20 Jul 2002 08:52:24 +0000 Subject: Xload -> Xinfo git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@424 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/menu.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pttbbs/mbbsd/menu.c b/pttbbs/mbbsd/menu.c index 9379c28f..c7570620 100644 --- a/pttbbs/mbbsd/menu.c +++ b/pttbbs/mbbsd/menu.c @@ -1,4 +1,4 @@ -/* $Id: menu.c,v 1.13 2002/07/05 17:10:27 in2 Exp $ */ +/* $Id: menu.c,v 1.14 2002/07/20 08:52:24 in2 Exp $ */ #include "bbs.h" /* help & menu processring */ @@ -427,7 +427,7 @@ static commands_t xyzlist[] = { {x_yesterday, 0, "YYesterday 《昨日上線人次統計》"}, {x_user100 ,0, "UUsers 《使用者百大排行榜》"}, {x_birth, 0, "BBirthday 《今日壽星大觀》"}, - {p_sysinfo, 0, "XXload 《查看系統負荷》"}, + {p_sysinfo, 0, "XXinfo 《查看系統資訊》"}, {NULL, 0, NULL} }; -- cgit v1.2.3 From d6eb144609bcf18e062a5584df10081c35fb78a4 Mon Sep 17 00:00:00 2001 From: kcwu <kcwu@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sat, 20 Jul 2002 10:53:58 +0000 Subject: clean up `more_web' git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@425 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/more.c | 289 +--------------------------------------------------- 1 file changed, 5 insertions(+), 284 deletions(-) diff --git a/pttbbs/mbbsd/more.c b/pttbbs/mbbsd/more.c index 56efeb57..90b22ab1 100644 --- a/pttbbs/mbbsd/more.c +++ b/pttbbs/mbbsd/more.c @@ -1,4 +1,4 @@ -/* $Id: more.c,v 1.15 2002/07/05 17:10:27 in2 Exp $ */ +/* $Id: more.c,v 1.16 2002/07/20 10:53:58 kcwu Exp $ */ #include "bbs.h" #define MORE_BUFSIZE 4096 #define MORE_WINSIZE 4096 @@ -127,12 +127,11 @@ more_readln(int fd, unsigned char *buf) * len++; buf[i++] = ch; } } buf[i] = '\0'; return bytes; } */ -static int more_web(char *fpath, int promptend); int more(char *fpath, int promptend) { static char *head[4] = {"作者", "標題", "時間", "轉信"}; - char *ptr, *word = NULL, buf[ANSILINELEN + 1], *ch1; + char *ptr, *word = NULL, buf[ANSILINELEN + 1]; struct stat st; /* rocker */ @@ -150,17 +149,7 @@ more(char *fpath, int promptend) int searching = 0; int scrollup = 0; char *printcolor[3] = {"44", "33;45", "0;34;46"}, color = 0; - char *http[80] = {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}; /* Ptt */ - char pagemode = 0; - char pagecount = 0; memset(pagebreak, 0, sizeof(pagebreak)); if (*search_str) @@ -245,30 +234,6 @@ more(char *fpath, int promptend) else if (!strncmp(buf, "※", 2) || !strncmp(buf, "==>", 3)) word = "\033[32m"; - ch1 = buf; - while (1) { - int i; - char e, *ch2; - - if ((ch2 = strstr(ch1, "http://"))); - else if ((ch2 = strstr(ch1, "gopher://"))); - else if ((ch2 = strstr(ch1, "mailto:"))); - else - break; - for (e = 0; ch2[(int)e] != ' ' && ch2[(int)e] != '\n' && - ch2[(int)e] != '\0' && ch2[(int)e] != '"' && - ch2[(int)e] != ';' && ch2[(int)e] != ']'; e++); - for (i = 0; http[i] && i < 80; i++) - if (!strncmp(http[i], ch2, e) && http[(int)e] == 0) - break; - if (!http[i]) { - http[i] = (char *)malloc(e + 1); - strncpy(http[i], ch2, e); - http[i][(int)e] = 0; - pagecount++; - } - ch1 = &ch2[7]; - } if (word) outs(word); { @@ -357,9 +322,9 @@ more(char *fpath, int promptend) printcolor[(int)color], pageno, (int)((viewed * 100) / fsize), - pagemode ? "\033[30;47m" : "\033[31;47m", - pagemode ? http[pagemode - 1] : "(h)\033[30m求助 \033[31m→↓[PgUp][", - pagemode ? "\033[31m[TAB]\033[30m切換 \033[31m[Enter]\033[30m選定 \033[31m←\033[30m放棄\033[m" : "PgDn][Home][End]\033[30m游標移動 \033[31m←[q]\033[30m結束 \033[m"); + "\033[31;47m", + "(h)\033[30m求助 \033[31m→↓[PgUp][", + "PgDn][Home][End]\033[30m游標移動 \033[31m←[q]\033[30m結束 \033[m"); while (line == b_lines || (line > 0 && viewed == fsize)) { @@ -437,14 +402,6 @@ more(char *fpath, int promptend) close(fd); return 12; case KEY_LEFT: - if (pagemode) { - pagemode = 0; - *search_str = 0; - if (pageno) - pageno--; - lino = line = 0; - break; - } close(fd); return 6; case 'q': @@ -492,15 +449,6 @@ more(char *fpath, int promptend) break; case '\r': case '\n': - if (pagemode) { - more_web(http[pagemode - 1], YEA); - pagemode = 0; - *search_str = 0; - if (pageno) - pageno--; - lino = line = 0; - break; - } case KEY_DOWN: if (viewed == fsize || (promptend == 2 && (ch == '\r' || ch == '\n'))) { @@ -556,19 +504,6 @@ more(char *fpath, int promptend) pageno--; lino = line = 0; break; -#if 0 - case Ctrl('I'): - if (!pagecount) - break; - pagemode = (pagemode % pagecount) + 1; - strncpy(search_str, http[pagemode - 1], 80); - search_str[80] = 0; - fptr = strstr; - if (pageno) - pageno--; - lino = line = 0; - break; -#endif case KEY_UP: line = -1; break; @@ -649,217 +584,3 @@ more(char *fpath, int promptend) return 0; } -static int -more_web(char *fpath, int promptend) -{ - char *ch, *ch1 = NULL; - char *hostname = fpath, userfile[MAXPATHLEN], file[MAXPATHLEN] = "/"; - char genbuf[200]; - time_t dtime; -#if !defined(USE_LYNX) && defined(USE_PROXY) - int a; - FILE *fp; - struct hostent *h; - struct sockaddr_in sin; -#endif - - if ((ch = strstr(fpath, "mailto:"))) { - if (!HAS_PERM(PERM_LOGINOK)) { - move(b_lines - 1, 0); - outs("\033[41m 您的權限不足無法使用internet mail... \033[m"); - refresh(); - return 0; - } - if (!invalidaddr(&ch[7]) && - getdata(b_lines - 1, 0, "[寄信]主題:", genbuf, 40, DOECHO)) - do_send(&ch[7], genbuf); - else { - move(b_lines - 1, 0); - outs("\033[41m 收信人email 或 標題 有誤... \033[m"); - refresh(); - } - return 0; - } - if ((ch = strstr(fpath, "gopher://"))) { - item_t item; - - strcpy(item.X.G.server, &ch[9]); - strcpy(item.X.G.path, "1/"); - item.X.G.port = 70; - gem(fpath, &item, 0); - return 0; - } - if ((ch = strstr(fpath, "http://"))) - hostname = &ch[7]; - if ((ch = strchr(hostname, '/'))) { - *ch = 0; - if (&ch1[1]) - strcat(file, &ch[1]); - } - if (file[strlen(file) - 1] == '/') - strcat(file, "index.html"); - move(b_lines - 1, 0); - clrtoeol(); -#ifdef USE_PROXY - sprintf(genbuf, "\033[33;44m 正在連往%s.(proxy:%s).....請稍候....\033[m", - hostname, PROXYSERVER); -#else - sprintf(genbuf, "\033[33;44m 正在連往%s......請稍候....\033[m", hostname); -#endif - outs(genbuf); - refresh(); - -#ifdef LOCAL_PROXY - /* 先找 local disk 的 proxy */ - dtime = now; - sprintf(userfile, "hproxy/%s%s", hostname, file); - if (dashf(userfile) && (dtime - dasht(userfile)) < HPROXYDAY * 24 * 60 - && more(userfile, promptend)) { - return 1; - } - ch = userfile - 1; - while ((ch1 = strchr(ch + 1, '/'))) { - *ch1 = 0; - if (!dashd(ch)) - mkdir(ch + 1, 0755); - chdir(ch + 1); - *ch1 = '/'; - ch = ch1; - } - chdir(BBSHOME); -#endif - -#ifndef USE_LYNX -#ifdef USE_PROXY - if (!(h = gethostbyname(PROXYSERVER))) { - outs("\033[33;44m 找不到這個proxy server!..\033[m"); - refresh(); - return; - } - () memset((char *)&sin, 0, sizeof(sin)); - sin.sin_family = AF_INET; - - if (h == NULL) - sin.sin_addr.s_addr = inet_addr(PROXYSERVER); - else - () memcpy(&sin.sin_addr.s_addr, h->h_addr, h->h_length); - - sin.sin_port = htons((ushort) PROXYPORT); /* HTTP port */ - a = socket(AF_INET, SOCK_STREAM, 0); - if ((connect(a, (struct sockaddr *) & sin, sizeof sin)) < 0) { - outs("\033[1;44m 連接到proxy受到拒絕 ! \033[m"); - refresh(); - return; - } - sprintf(genbuf, "GET http://%s/%s HTTP/1.1\n", hostname, file); -#else - if (!(h = gethostbyname(hostname))) { - outs("\033[33;44m 找不到這個server!..\033[m"); - refresh(); - return; - } - () memset((char *)&sin, 0, sizeof(sin)); - sin.sin_family = AF_INET; - - if (h == NULL) - sin.sin_addr.s_addr = inet_addr(hostname); - else - () memcpy(&sin.sin_addr.s_addr, h->h_addr, h->h_length); - - sin.sin_port = htons((ushort) 80); - a = socket(AF_INET, SOCK_STREAM, 0); - if ((connect(a, (struct sockaddr *) & sin, sizeof sin)) < 0) { - outs("\033[1;44m 連接受到拒絕 ! \033[m"); - refresh(); - return; - } - sprintf(genbuf, "GET %s\n", file); -#endif - - for (i = strlen(file); file[i - 1] != '/' && i > 0; i--); - file[i] = 0; - - i = strlen(genbuf); - write(a, genbuf, i); - -#define BLANK 001 -#define ISPRINT 002 -#define PRE 004 -#define CENTER 010 - if ((fp = fopen(userfile, "w"))) { - int flag = 2, c; - char path[MAXPATHLEN]; - unsigned char j, k; - - while ((i = read(a, genbuf, 200))) { - if (i < 0) - return; - genbuf[i] = 0; - - for (j = 0, k = 0; genbuf[j] && j < i; j++) { - if ((flag & ISPRINT) && genbuf[j] == '<') - flag |= BLANK; - else if ((flag & ISPRINT) && genbuf[j] == '>') - flag &= ~BLANK; - else { - if (!(flag & BLANK)) { - if (j != k && (genbuf[j] != '\n' || flag & PRE)) - genbuf[k++] = genbuf[j]; - } else { - switch (char_lower(genbuf[j])) { - case 'a': - break; - case 'b': - if (genbuf[j + 1] == 'r' && genbuf[j + 2] == '>') - genbuf[k++] = '\n'; - break; - case 'h': - if (genbuf[j + 1] == 'r' && - (genbuf[j + 2] == '>' || - genbuf[j + 2] == 's')) { - strncpy(&genbuf[k], "\n--\n", 4); - k += 4; - } - break; - case 'l': - if (genbuf[j + 1] == 'i' && genbuf[j + 2] == '>') { - strncpy(&genbuf[k], "\n◎ ", 4); - k += 4; - } - break; - case 'p': - if (genbuf[j + 1] == '>') { - genbuf[k++] = '\n'; - genbuf[k++] = '\n'; - } else if (genbuf[j + 1] == 'r' && - genbuf[j + 2] == 'e') - flag ^= PRE; - break; - case 't': - if (genbuf[j + 1] == 'd' && genbuf[j + 2] == '>') { - strncpy(&genbuf[k], "\n-\n", 3); - k += 3; - } - break; - } - } - if ((genbuf[j] & 0x80) && (flag & ISPRINT)) - flag &= ~ISPRINT; - else - flag |= ISPRINT; - } - } - genbuf[k] = 0; - fputs(genbuf, fp); - } - fclose(fp); - close(a); - return more(userfile, promptend); - } - return 0; -#else /* use lynx dump */ - sprintf(genbuf, "lynx -dump http://%s%s > %s", hostname, file, userfile); - system(genbuf); - return more(userfile, promptend); -#endif -} -- cgit v1.2.3 From 4b6c493b607f5cea92e7d4bc30eefb58017883a9 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sat, 20 Jul 2002 13:40:12 +0000 Subject: fix **t bug git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@426 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/kaede.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pttbbs/mbbsd/kaede.c b/pttbbs/mbbsd/kaede.c index e3fd1b62..e1ccd1b5 100644 --- a/pttbbs/mbbsd/kaede.c +++ b/pttbbs/mbbsd/kaede.c @@ -1,4 +1,4 @@ -/* $Id: kaede.c,v 1.8 2002/07/05 17:10:27 in2 Exp $ */ +/* $Id: kaede.c,v 1.9 2002/07/20 13:40:12 in2 Exp $ */ #include "bbs.h" char * @@ -15,7 +15,6 @@ Ptt_prints(char *str, int mode) po[0] = 0; sprintf(strbuf, "%s%s", str, Cdate(&now)); - str[strlen(strbuf) - 1] = 0; strcat(strbuf, po + 3); strcpy(str, strbuf); } -- cgit v1.2.3 From 24dfca20904d1425aa61c001676baca29acc6f1e Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sat, 20 Jul 2002 15:33:46 +0000 Subject: fix applying newboard bug git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@427 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/voteboard.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pttbbs/mbbsd/voteboard.c b/pttbbs/mbbsd/voteboard.c index e720d920..d3df2540 100644 --- a/pttbbs/mbbsd/voteboard.c +++ b/pttbbs/mbbsd/voteboard.c @@ -1,4 +1,4 @@ -/* $Id: voteboard.c,v 1.9 2002/07/05 17:10:28 in2 Exp $ */ +/* $Id: voteboard.c,v 1.10 2002/07/20 15:33:46 in2 Exp $ */ #include "bbs.h" #define VOTEBOARD "NewBoard" @@ -240,13 +240,13 @@ do_voteboard() strcat(genbuf, topic); strcat(genbuf, "\n申請原因: \n"); outs("請輸入申請原因(至多五行),要清楚填寫不然不會核准喔"); - for (i = 8; i < 13; i++) { + for (i = 9; i < 13; i++) { if (!getdata(i, 0, ":", topic, 60, DOECHO)) break; strcat(genbuf, topic); strcat(genbuf, "\n"); } - if (i == 8) + if (i == 9) return FULLUPDATE; break; case 2: -- cgit v1.2.3 From e8f0cdb66cd244a1f344cc37c5aa4dd005174085 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sun, 21 Jul 2002 08:18:42 +0000 Subject: strcpy() -> strlcpy() git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@428 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/admin.c | 26 +++++++------- pttbbs/mbbsd/announce.c | 81 ++++++++++++++++++++++++------------------ pttbbs/mbbsd/args.c | 4 +-- pttbbs/mbbsd/bbcall.c | 6 ++-- pttbbs/mbbsd/bbs.c | 82 +++++++++++++++++++++--------------------- pttbbs/mbbsd/board.c | 4 +-- pttbbs/mbbsd/cache.c | 4 +-- pttbbs/mbbsd/cal.c | 18 +++++----- pttbbs/mbbsd/calendar.c | 4 +-- pttbbs/mbbsd/chat.c | 25 ++++++------- pttbbs/mbbsd/chc_play.c | 16 ++++----- pttbbs/mbbsd/chicken.c | 11 +++--- pttbbs/mbbsd/dark.c | 4 +-- pttbbs/mbbsd/edit.c | 24 ++++++------- pttbbs/mbbsd/friend.c | 4 +-- pttbbs/mbbsd/gamble.c | 6 ++-- pttbbs/mbbsd/gomo.c | 4 +-- pttbbs/mbbsd/indict.c | 10 +++--- pttbbs/mbbsd/io.c | 6 ++-- pttbbs/mbbsd/lovepaper.c | 4 +-- pttbbs/mbbsd/mail.c | 92 ++++++++++++++++++++++++------------------------ pttbbs/mbbsd/mbbsd.c | 27 +++++++------- pttbbs/mbbsd/name.c | 4 +-- pttbbs/mbbsd/page.c | 4 +-- pttbbs/mbbsd/read.c | 20 ++++++----- pttbbs/mbbsd/record.c | 20 +++++------ pttbbs/mbbsd/register.c | 6 ++-- pttbbs/mbbsd/screen.c | 4 +-- pttbbs/mbbsd/syspost.c | 18 +++++----- pttbbs/mbbsd/talk.c | 51 ++++++++++++++------------- pttbbs/mbbsd/topsong.c | 6 ++-- pttbbs/mbbsd/user.c | 48 ++++++++++++------------- pttbbs/mbbsd/vote.c | 92 ++++++++++++++++++++++++------------------------ pttbbs/mbbsd/voteboard.c | 8 ++--- 34 files changed, 382 insertions(+), 361 deletions(-) diff --git a/pttbbs/mbbsd/admin.c b/pttbbs/mbbsd/admin.c index ffe594dc..f6d13042 100644 --- a/pttbbs/mbbsd/admin.c +++ b/pttbbs/mbbsd/admin.c @@ -1,4 +1,4 @@ -/* $Id: admin.c,v 1.25 2002/07/05 17:10:26 in2 Exp $ */ +/* $Id: admin.c,v 1.26 2002/07/21 08:18:41 in2 Exp $ */ #include "bbs.h" /* 使用者管理 */ @@ -275,7 +275,7 @@ m_mod_board(char *bname) if (genbuf[0] != 'y' || !bname[0]) outs(MSG_DEL_CANCEL); else { - strcpy(bname, bh.brdname); + strlcpy(bname, bh.brdname, sizeof(bname)); sprintf(genbuf, "/bin/tar zcvf tmp/board_%s.tgz boards/%c/%s man/boards/%c/%s >/dev/null 2>&1;" "/bin/rm -fr boards/%c/%s man/boards/%c/%s", @@ -301,7 +301,7 @@ m_mod_board(char *bname) move(3, 0); outs("錯誤! 板名雷同"); } else if (!invalid_brdname(genbuf)) { - strcpy(newbh.brdname, genbuf); + strlcpy(newbh.brdname, genbuf, sizeof(newbh.brdname)); break; } } @@ -320,11 +320,11 @@ m_mod_board(char *bname) getdata_str(14, 0, "看板主題:", genbuf, BTLEN + 1, DOECHO, bh.title + 7); if (genbuf[0]) - strcpy(newbh.title + 7, genbuf); + strlcpy(newbh.title + 7, genbuf, sizeof(newbh.title) - 7); if (getdata_str(15, 0, "新板主名單:", genbuf, IDLEN * 3 + 3, DOECHO, bh.BM)) { trim(genbuf); - strcpy(newbh.BM, genbuf); + strlcpy(newbh.BM, genbuf, sizeof(newbh.BM)); } if (HAS_PERM(PERM_SYSOP)) { move(1, 0); @@ -559,7 +559,7 @@ m_newbrd(int recover) getdata(8, 0, "看板主題:", genbuf, BTLEN + 1, DOECHO); if (genbuf[0]) - strcpy(newboard.title + 7, genbuf); + strlcpy(newboard.title + 7, genbuf, sizeof(newboard.title) - 7); setbpath(genbuf, newboard.brdname); if (recover) { @@ -777,7 +777,7 @@ scan_register_form(char *regfile, int automode, int neednum) *ptr = '\0'; for (n = 0; field[n]; n++) { if (strcmp(genbuf, field[n]) == 0) { - strcpy(fdata[n], ptr + 2); + strlcpy(fdata[n], ptr + 2, sizeof(fdata[n])); if ((ptr = (char *)strchr(fdata[n], '\n'))) *ptr = '\0'; } @@ -876,13 +876,13 @@ scan_register_form(char *regfile, int automode, int neednum) FILE *fp; i = buf[0] - '0'; - strcpy(buf, reason[i]); + strlcpy(buf, reason[i], sizeof(buf)); sprintf(genbuf, "[退回原因] 請%s", buf); sethomepath(buf1, muser.userid); stampfile(buf1, &mhdr); - strcpy(mhdr.owner, cuser.userid); - strncpy(mhdr.title, "[註冊失敗]", TTLEN); + strlcpy(mhdr.owner, cuser.userid, sizeof(mhdr.owner)); + strlcpy(mhdr.title, "[註冊失敗]", TTLEN); mhdr.filemode = 0; sethomedir(title, muser.userid); if (append_record(title, &mhdr, sizeof(mhdr)) != -1) { @@ -915,9 +915,9 @@ scan_register_form(char *regfile, int automode, int neednum) prints("以下使用者資料已經更新:\n"); mail_muser(muser, "[註冊成功\囉]", "etc/registered"); muser.userlevel |= (PERM_LOGINOK | PERM_POST); - strcpy(muser.realname, fdata[2]); - strcpy(muser.address, fdata[4]); - strcpy(muser.email, fdata[6]); + strlcpy(muser.realname, fdata[2], sizeof(muser.realname)); + strlcpy(muser.address, fdata[4], sizeof(muser.address)); + strlcpy(muser.email, fdata[6], sizeof(muser.email)); sprintf(genbuf, "%s:%s:%s", fdata[5], fdata[3], uid); strncpy(muser.justify, genbuf, REGLEN); sethomefile(buf, muser.userid, "justify"); diff --git a/pttbbs/mbbsd/announce.c b/pttbbs/mbbsd/announce.c index 3e8700bf..889c986d 100644 --- a/pttbbs/mbbsd/announce.c +++ b/pttbbs/mbbsd/announce.c @@ -1,4 +1,4 @@ -/* $Id: announce.c,v 1.13 2002/07/05 17:10:26 in2 Exp $ */ +/* $Id: announce.c,v 1.14 2002/07/21 08:18:41 in2 Exp $ */ #include "bbs.h" static void @@ -510,7 +510,7 @@ AnnounceSelect() completeboard_permission, completeboard_getname); if (*buf) - strcpy(xboard, buf); + strlcpy(xboard, buf, sizeof(xboard)); if (*xboard && (bp = getbcache(getbnum(xboard)))) { setapath(fpath, xboard); setutmpmode(ANNOUNCE); @@ -621,14 +621,14 @@ gem(char *maintitle, item_t * path, int update) char newpath[PATHLEN]; fileheader_t item; - strcpy(newpath, paste_path); + strlcpy(newpath, paste_path, sizeof(newpath)); if (mode == (char)0xbc) { stampfile(newpath, &item); unlink(newpath); Link(fname, newpath); } else stampdir(newpath, &item); - strcpy(item.owner, cuser.userid); + strlcpy(item.owner, cuser.userid, sizeof(item.owner)); sprintf(item.title, "%s%.72s", (currutmp->pager > 1) ? "" : (mode == (char)0xbc) ? "◇ " : "◆ ", @@ -682,7 +682,7 @@ gem(char *maintitle, item_t * path, int update) int more_result; go_proxy(fname, node, update); - strcpy(vetitle, title); + strlcpy(vetitle, title, sizeof(vetitle)); while ((more_result = more(fname, YEA))) { if (more_result == 1) { if (--me.now < 0) { @@ -700,7 +700,7 @@ gem(char *maintitle, item_t * path, int update) if (node->title[1] != (char)0xbc) break; go_proxy(fname, node, update); - strcpy(vetitle, title); + strlcpy(vetitle, title, sizeof(vetitle)); } } else if (mode == (char)0xbd) { gem(title, node, update); @@ -719,8 +719,8 @@ a_forward(char *path, fileheader_t * pitem, int mode) { fileheader_t fhdr; - strcpy(fhdr.filename, pitem->filename); - strcpy(fhdr.title, pitem->title); + strlcpy(fhdr.filename, pitem->filename, sizeof(fhdr.filename)); + strlcpy(fhdr.title, pitem->title, sizeof(fhdr.title)); switch (doforward(path, &fhdr, mode)) { case 0: outmsg(msg_fwd_ok); @@ -749,7 +749,9 @@ a_additem(menu_t * pm, fileheader_t * myheader) (p_lines / 2) : (pm->now % p_lines)); } /* Ptt */ - strcpy(pm->header[pm->now - pm->page].filename, myheader->filename); + strlcpy(pm->header[pm->now - pm->page].filename, + myheader->filename, + sizeof(pm->header[pm->now - pm->page].filename)); } #define ADDITEM 0 @@ -771,21 +773,21 @@ a_newitem(menu_t * pm, int mode) fileheader_t item; int d; - strcpy(fpath, pm->path); + strlcpy(fpath, pm->path, sizeof(fpath)); switch (mode) { case ADDITEM: stampfile(fpath, &item); - strcpy(item.title, "◇ "); /* A1BA */ + strlcpy(item.title, "◇ ", sizeof(item.title)); /* A1BA */ break; case ADDGROUP: stampdir(fpath, &item); - strcpy(item.title, "◆ "); /* A1BB */ + strlcpy(item.title, "◆ ", sizeof(item.title)); /* A1BB */ break; case ADDGOPHER: bzero(&item, sizeof(item)); - strcpy(item.title, "☉ "); /* A1BB */ + strlcpy(item.title, "☉ ", sizeof(item.title)); /* A1BB */ if (!getdata(b_lines - 2, 1, "輸入URL位址:", item.filename + 2, 61, DOECHO)) return; @@ -821,10 +823,10 @@ a_newitem(menu_t * pm, int mode) break; } if (dashf(lpath)) { - strcpy(item.title, "☆ "); /* A1B3 */ + strlcpy(item.title, "☆ ", sizeof(item.title)); /* A1B3 */ break; } else if (dashd(lpath)) { - strcpy(item.title, "★ "); /* A1B4 */ + strlcpy(item.title, "★ ", sizeof(item.title)); /* A1B4 */ break; } if (!HAS_PERM(PERM_BBSADM) && d == 1) @@ -863,12 +865,12 @@ a_newitem(menu_t * pm, int mode) } break; case ADDGOPHER: - strcpy(item.date, "70"); + strlcpy(item.date, "70", sizeof(item.date)); strncpy(item.filename, "H.", 2); break; } - strcpy(item.owner, cuser.userid); + strlcpy(item.owner, cuser.userid, sizeof(item.owner)); a_additem(pm, &item); } @@ -897,7 +899,7 @@ a_pasteitem(menu_t * pm, int mode) } else ans[0] = 'y'; if (ans[0] == 'y') { - strcpy(newpath, pm->path); + strlcpy(newpath, pm->path, sizeof(newpath)); if (*copyowner) { char *fname = strrchr(copyfile, '/'); @@ -909,7 +911,7 @@ a_pasteitem(menu_t * pm, int mode) if (access(pm->path, X_OK | R_OK | W_OK)) mkdir(pm->path, 0755); memset(&item, 0, sizeof(fileheader_t)); - strcpy(item.filename, fname + 1); + strlcpy(item.filename, fname + 1, sizeof(item.filename)); memcpy(copytitle, "◎", 2); if (HAS_PERM(PERM_BBSADM)) Link(copyfile, newpath); @@ -931,8 +933,9 @@ a_pasteitem(menu_t * pm, int mode) igetch(); return; } - strcpy(item.owner, *copyowner ? copyowner : cuser.userid); - strcpy(item.title, copytitle); + strlcpy(item.owner, *copyowner ? copyowner : cuser.userid, + sizeof(item.owner)); + strlcpy(item.title, copytitle, sizeof(item.title)); if (!*copyowner) system(buf); a_additem(pm, &item); @@ -1122,8 +1125,10 @@ a_delete(menu_t * pm) setbpath(buf, "deleted"); stampfile(buf, &backup); - strcpy(backup.owner, cuser.userid); - strcpy(backup.title, pm->header[pm->now - pm->page].title + 2); + strlcpy(backup.owner, cuser.userid, sizeof(backup.owner)); + strlcpy(backup.title, + pm->header[pm->now - pm->page].title + 2, + sizeof(backup.title)); sprintf(cmd, "mv -f %s %s", fpath, buf); system(cmd); @@ -1143,8 +1148,10 @@ a_delete(menu_t * pm) sprintf(cmd, "rm -rf %s;/bin/mv -f %s %s", buf, fpath, buf); system(cmd); - strcpy(backup.owner, cuser.userid); - strcpy(backup.title, pm->header[pm->now - pm->page].title + 2); + strlcpy(backup.owner, cuser.userid, sizeof(backup.owner)); + strlcpy(backup.title, + pm->header[pm->now - pm->page].title + 2, + sizeof(backup.title)); setapath(buf, "deleted"); setadir(buf, buf); append_record(buf, &backup, sizeof(backup)); @@ -1166,9 +1173,9 @@ a_newtitle(menu_t * pm) fileheader_t item; memcpy(&item, &pm->header[pm->now - pm->page], FHSZ); - strcpy(buf, item.title + 3); + strlcpy(buf, item.title + 3, sizeof(buf)); if (getdata_buf(b_lines - 1, 1, "新標題:", buf, 60, DOECHO)) { - strcpy(item.title + 3, buf); + strlcpy(item.title + 3, buf, sizeof(item.title) - 3); setadir(buf, pm->path); substitute_record(buf, &item, FHSZ, pm->now + 1); } @@ -1283,7 +1290,7 @@ a_menu(char *maintitle, char *path, int lastlevel) Fexit = 0; me.header = (fileheader_t *) calloc(p_lines, FHSZ); me.path = path; - strcpy(me.mtitle, maintitle); + strlcpy(me.mtitle, maintitle, sizeof(me.mtitle)); setadir(fname, me.path); me.num = get_num_records(fname, FHSZ); @@ -1392,12 +1399,16 @@ a_menu(char *maintitle, char *path, int lastlevel) char fpath[200]; fileheader_t fhdr; - strcpy(fpath, path); + strlcpy(fpath, path, sizeof(fpath)); stampfile(fpath, &fhdr); unlink(fpath); Rename(fname, fpath); - strcpy(me.header[me.now - me.page].filename, fhdr.filename); - strcpy(me.header[me.now - me.page].owner, cuser.userid); + strlcpy(me.header[me.now - me.page].filename, + fhdr.filename, + sizeof(me.header[me.now - me.page].filename)); + strlcpy(me.header[me.now - me.page].owner, + cuser.userid, + sizeof(me.header[me.now - me.page].owner)); setadir(fpath, path); substitute_record(fpath, me.header + me.now - me.page, sizeof(fhdr), me.now + 1); @@ -1427,8 +1438,9 @@ a_menu(char *maintitle, char *path, int lastlevel) sprintf(fname, "%s/%s", path, fhdr->filename); if (*fhdr->filename == 'H' && fhdr->filename[1] == '.') { item_t item; - strcpy(item.X.G.server, fhdr->filename + 2); - strcpy(item.X.G.path, "1/"); + strlcpy(item.X.G.server, fhdr->filename + 2, + sizeof(item.X.G.server)); + strlcpy(item.X.G.path, "1/", sizeof(item.X.G.path)); item.X.G.port = 70; gem(fhdr->title, &item, (ch == 'R') ? 1 : 0); } else if (dashf(fname)) { @@ -1447,7 +1459,8 @@ a_menu(char *maintitle, char *path, int lastlevel) "確定要點這首歌嗎?[y/N]", ans, sizeof(ans), LCECHO); if (ans[0] == 'y') { - strcpy(trans_buffer, fname); + strlcpy(trans_buffer, + fname, sizeof(trans_buffer)); Fexit = 1; if (currstat == OSONG) { log_file(FN_USSONG, fhdr->title); diff --git a/pttbbs/mbbsd/args.c b/pttbbs/mbbsd/args.c index 60e1de32..57e6798b 100644 --- a/pttbbs/mbbsd/args.c +++ b/pttbbs/mbbsd/args.c @@ -1,4 +1,4 @@ -/* $Id: args.c,v 1.3 2002/07/05 17:10:26 in2 Exp $ */ +/* $Id: args.c,v 1.4 2002/07/21 08:18:41 in2 Exp $ */ #include "bbs.h" #ifdef HAVE_SETPROCTITLE @@ -49,7 +49,7 @@ do_setproctitle(const char *cmdline) if (i > LastArgv - Argv[0] - 2) { i = LastArgv - Argv[0] - 2; } - strcpy(Argv[0], buf); + strlcpy(Argv[0], buf, sizeof(Argv[0]); p = &Argv[0][i]; while (p < LastArgv) *p++ = '\0'; diff --git a/pttbbs/mbbsd/bbcall.c b/pttbbs/mbbsd/bbcall.c index 2c369be4..dfc6320c 100644 --- a/pttbbs/mbbsd/bbcall.c +++ b/pttbbs/mbbsd/bbcall.c @@ -1,4 +1,4 @@ -/* $Id: bbcall.c,v 1.5 2002/07/05 17:10:26 in2 Exp $ */ +/* $Id: bbcall.c,v 1.6 2002/07/21 08:18:41 in2 Exp $ */ #include "bbs.h" #define SERVER_0941 "www.chips.com.tw" @@ -183,10 +183,10 @@ static void hcall0941() { getdata(9,0, "\033[1;37m如果你要馬上送請按 '1' " "如果要定時送請按 '2': \033[m", ans, sizeof(ans), LCECHO); if(ans[0] != '1') { - strcpy(TIME,"DELAY"); + strlcpy(TIME, "DELAY", sizeof(TIME)); Gettime(0, &year, &month, &day, &hour, &min); } else - strcpy(TIME,"NOW"); + strlcpy(TIME, "NOW", sizeof(TIME)); sprintf(trn,"PAGER_NO=%s&TRAN_MSG=%s&MSG_TYPE=NUMERIC&%s=1" "&year=19%02d&month=%02d&day=%02d&hour=%02d&min=%02d", PAGER_NO, TRAN_MSG, TIME,year,month,day,hour,min); diff --git a/pttbbs/mbbsd/bbs.c b/pttbbs/mbbsd/bbs.c index f3eaf143..46222bed 100644 --- a/pttbbs/mbbsd/bbs.c +++ b/pttbbs/mbbsd/bbs.c @@ -1,4 +1,4 @@ -/* $Id: bbs.c,v 1.63 2002/07/05 17:10:26 in2 Exp $ */ +/* $Id: bbs.c,v 1.64 2002/07/21 08:18:41 in2 Exp $ */ #include "bbs.h" static void @@ -9,7 +9,7 @@ mail_by_link(char *owner, char *title, char *path) sprintf(genbuf, BBSHOME "/home/%c/%s", cuser.userid[0], cuser.userid); stampfile(genbuf, &mymail); - strcpy(mymail.owner, owner); + strlcpy(mymail.owner, owner, sizeof(mymail.owner)); sprintf(mymail.title, title); unlink(genbuf); Link(path, genbuf); @@ -158,7 +158,7 @@ readdoent(int num, fileheader_t * ent) color = '3', mark = "R:"; if (title[47]) - strcpy(title + 44, " …"); /* 把多餘的 string 砍掉 */ + strlcpy(title + 44, " …", sizeof(title) - 44); /* 把多餘的 string 砍掉 */ if (!strncmp(title, "[公告]", 6)) special = 1; @@ -271,7 +271,7 @@ do_select(int ent, fileheader_t * fhdr, char *direct) bh = getbcache(i); if (!Ben_Perm(bh)) return FULLUPDATE; - strcpy(bname, bh->brdname); + strlcpy(bname, bh->brdname, sizeof(bname)); currbid = i; setbpath(bpath, bname); @@ -331,7 +331,7 @@ cancelpost(fileheader_t * fh, int by_BM) if ((ptr = strrchr(genbuf, ')'))) *ptr = '\0'; if ((ptr = (char *)strchr(genbuf, '('))) - strcpy(nick, ptr + 1); + strlcpy(nick, ptr + 1, sizeof(nick)); break; } } @@ -361,7 +361,7 @@ do_reply_title(int row, char *title) if (strncasecmp(title, str_reply, 4)) sprintf(save_title, "Re: %s", title); else - strcpy(save_title, title); + strlcpy(save_title, title, sizeof(save_title)); save_title[TTLEN - 1] = '\0'; sprintf(genbuf, "採用原標題《%.60s》嗎?[Y] ", save_title); getdata(row, 0, genbuf, genbuf2, 4, LCECHO); @@ -381,8 +381,8 @@ do_unanonymous_post(char *fpath) stampfile(genbuf, &mhdr); unlink(genbuf); Link(fpath, genbuf); - strcpy(mhdr.owner, cuser.userid); - strcpy(mhdr.title, save_title); + strlcpy(mhdr.owner, cuser.userid, sizeof(mhdr.owner)); + strlcpy(mhdr.title, save_title, sizeof(mhdr.title)); mhdr.filemode = 0; setbdir(title, "UnAnonymous"); append_record(title, &mhdr, sizeof(mhdr)); @@ -496,8 +496,8 @@ do_general() /* 錢 */ aborted = (aborted > MAX_POST_MONEY * 2) ? MAX_POST_MONEY : aborted / 2; postfile.money = aborted; - strcpy(postfile.owner, owner); - strcpy(postfile.title, save_title); + strlcpy(postfile.owner, owner, sizeof(postfile.owner)); + strlcpy(postfile.title, save_title, sizeof(postfile.title)); if (islocal) /* local save */ postfile.filemode = FILE_LOCAL; @@ -528,8 +528,8 @@ do_general() strcat(abspath, fpath); symlink(abspath, genbuf); } - strcpy(postfile.owner, owner); - strcpy(postfile.title, save_title); + strlcpy(postfile.owner, owner, sizeof(postfile.owner)); + strlcpy(postfile.title, save_title, sizeof(postfile.title)); postfile.filemode = FILE_LOCAL; setbdir(genbuf, ALLPOST); if (append_record(genbuf, &postfile, sizeof(postfile)) != -1) { @@ -569,8 +569,8 @@ do_general() unlink(genbuf); Link(fpath, genbuf); - strcpy(postfile.owner, cuser.userid); - strcpy(postfile.title, save_title); + strlcpy(postfile.owner, cuser.userid, sizeof(postfile.owner)); + strlcpy(postfile.title, save_title, sizeof(postfile.title)); postfile.filemode = FILE_BOTH; /* both-reply flag */ sethomedir(genbuf, quote_user); if (append_record(genbuf, &postfile, sizeof(postfile)) == -1) @@ -615,8 +615,8 @@ do_generalboardreply(fileheader_t * fhdr) case 'b': curredit = EDIT_BOTH; default: - strcpy(currtitle, fhdr->title); - strcpy(quote_user, fhdr->owner); + strlcpy(currtitle, fhdr->title, sizeof(currtitle)); + strlcpy(quote_user, fhdr->owner, sizeof(quote_user)); do_post(); } *quote_file = 0; @@ -712,7 +712,7 @@ edit_post(int ent, fileheader_t * fhdr, char *direct) setutmpmode(REEDIT); setdirpath(genbuf, direct, fhdr->filename); local_article = fhdr->filemode & FILE_LOCAL; - strcpy(save_title, fhdr->title); + strlcpy(save_title, fhdr->title, sizeof(save_title)); /* rocker.011018: 這裡是不是該檢查一下修改文章後的money和原有的比較? */ if (vedit(genbuf, 0, NULL) != -1) { @@ -734,13 +734,13 @@ edit_post(int ent, fileheader_t * fhdr, char *direct) /* 再這裡要check一下原來的dir裡面是不是有被人動過... */ if (!strcmp(hdr.filename, fhdr->filename)) { - strcpy(hdr.filename, postfile.filename); - strcpy(hdr.title, save_title); + strlcpy(hdr.filename, postfile.filename, sizeof(hdr.filename)); + strlcpy(hdr.title, save_title, sizeof(hdr.title)); substitute_record(fpath0, &hdr, sizeof(hdr), num); } } - strcpy(fhdr->filename, postfile.filename); - strcpy(fhdr->title, save_title); + strlcpy(fhdr->filename, postfile.filename, sizeof(fhdr->filename)); + strlcpy(fhdr->title, save_title, sizeof(fhdr->title)); brc_addlist(postfile.filename); substitute_record(direct, fhdr, sizeof(*fhdr), ent); /* rocker.011018: 順便更新一下cache */ @@ -801,13 +801,13 @@ cross_post(int ent, fileheader_t * fhdr, char *direct) if (ent) sprintf(xtitle, "[轉錄]%.66s", fhdr->title); else - strcpy(xtitle, fhdr->title); + strlcpy(xtitle, fhdr->title, sizeof(xtitle)); sprintf(genbuf, "採用原標題《%.60s》嗎?[Y] ", xtitle); getdata(2, 0, genbuf, genbuf2, 4, LCECHO); if (genbuf2[0] == 'n' || genbuf2[0] == 'N') { if (getdata_str(2, 0, "標題:", genbuf, TTLEN, DOECHO, xtitle)) - strcpy(xtitle, genbuf); + strlcpy(xtitle, genbuf, sizeof(xtitle)); } getdata(2, 0, "(S)存檔 (L)站內 (Q)取消?[Q] ", genbuf, 3, LCECHO); if (genbuf[0] == 'l' || genbuf[0] == 's') { @@ -817,10 +817,10 @@ cross_post(int ent, fileheader_t * fhdr, char *direct) setbpath(xfpath, xboard); stampfile(xfpath, &xfile); if (author) - strcpy(xfile.owner, fhdr->owner); + strlcpy(xfile.owner, fhdr->owner, sizeof(xfile.owner)); else - strcpy(xfile.owner, cuser.userid); - strcpy(xfile.title, xtitle); + strlcpy(xfile.owner, cuser.userid, sizeof(xfile.owner)); + strlcpy(xfile.title, xtitle, sizeof(xfile.title)); if (genbuf[0] == 'l') { xfile.filemode = FILE_LOCAL; } @@ -828,11 +828,11 @@ cross_post(int ent, fileheader_t * fhdr, char *direct) //if (ent) { xptr = fopen(xfpath, "w"); - strcpy(save_title, xfile.title); - strcpy(xfpath, currboard); - strcpy(currboard, xboard); + strlcpy(save_title, xfile.title, sizeof(save_title)); + strlcpy(xfpath, currboard, sizeof(xfpath)); + strlcpy(currboard, xboard, sizeof(currboard)); write_header(xptr); - strcpy(currboard, xfpath); + strlcpy(currboard, xfpath, sizeof(currboard)); fprintf(xptr, "※ [本文轉錄自 %s 看板]\n\n", currboard); @@ -888,7 +888,7 @@ cross_post(int ent, fileheader_t * fhdr, char *direct) case 7: case 8: if ((currmode & MODE_POST)) { - strcpy(quote_file, genbuf); + strlcpy(quote_file, genbuf, sizeof(quote_file)); do_reply(fhdr); *quote_file = 0; } @@ -959,7 +959,7 @@ cross_post(int ent, fileheader_t * fhdr, char *direct) case 'R': case 'Y': if ((currmode & MODE_POST)) { - strcpy(quote_file, genbuf); + strlcpy(quote_file, genbuf, sizeof(quote_file)); do_reply(fhdr); *quote_file = 0; } @@ -1108,8 +1108,8 @@ cross_post(int ent, fileheader_t * fhdr, char *direct) char title[TTLEN + 1]; setbfile(fpath, currboard, fhdr->filename); - strcpy(title, "◇ "); - strncpy(title + 3, fhdr->title, TTLEN - 3); + strlcpy(title, "◇ ", sizeof(title)); + strlcpy(title + 3, fhdr->title, TTLEN - 3); title[TTLEN] = '\0'; a_copyitem(fpath, title, 0, 1); b_man(); @@ -1123,13 +1123,13 @@ cross_post(int ent, fileheader_t * fhdr, char *direct) if (currmode & MODE_BOARD || !strcmp(cuser.userid, fhdr->owner)) { if (getdata(b_lines - 1, 0, "標題:", genbuf, TTLEN, DOECHO)) { - strcpy(tmpfhdr.title, genbuf); + strlcpy(tmpfhdr.title, genbuf, sizeof(tmpfhdr.title)); dirty++; } } if (HAS_PERM(PERM_SYSOP)) { if (getdata(b_lines - 1, 0, "作者:", genbuf, IDLEN + 2, DOECHO)) { - strcpy(tmpfhdr.owner, genbuf); + strlcpy(tmpfhdr.owner, genbuf, sizeof(tmpfhdr.owner)); dirty++; } if (getdata(b_lines - 1, 0, "日期:", genbuf, 6, DOECHO)) { @@ -1285,7 +1285,7 @@ cross_post(int ent, fileheader_t * fhdr, char *direct) if (i > inum2) break; now = getindex(genbuf, rsfh.filename, size); - strcpy(currfile, rsfh.filename); + strlcpy(currfile, rsfh.filename, sizeof(currfile)); delete_file(genbuf, sizeof(fileheader_t), now, cmpfilename); i++; @@ -1327,7 +1327,7 @@ cross_post(int ent, fileheader_t * fhdr, char *direct) getdata(1, 0, msg_del_ny, genbuf, 3, LCECHO); if (genbuf[0] == 'y' || genbuf[0] == 'Y') { - strcpy(currfile, fhdr->filename); + strlcpy(currfile, fhdr->filename, sizeof(currfile)); setbfile(genbuf, currboard, fhdr->filename); if (!delete_file(direct, sizeof(fileheader_t), ent, cmpfilename)) { @@ -1491,7 +1491,7 @@ cross_post(int ent, fileheader_t * fhdr, char *direct) case 'Y': case 'R': if (currmode & MODE_POST) { - strcpy(quote_file, genbuf); + strlcpy(quote_file, genbuf, sizeof(quote_file)); do_reply(fptr); *quote_file = 0; } @@ -1620,7 +1620,7 @@ cross_post(int ent, fileheader_t * fhdr, char *direct) if (!genbuf[0]) return 0; strip_ansi(genbuf, genbuf, 0); - strcpy(bp->title + 7, genbuf); + strlcpy(bp->title + 7, genbuf, sizeof(bp->title) - 7); substitute_record(fn_board, bp, sizeof(boardheader_t), currbid); log_usies("SetBoard", currboard); return FULLUPDATE; @@ -1706,7 +1706,7 @@ cross_post(int ent, fileheader_t * fhdr, char *direct) memcpy(&digest, fhdr, sizeof(digest)); digest.filename[0] = 'G'; - strcpy(buf, direct); + strlcpy(buf, direct, sizeof(buf)); ptr = strrchr(buf, '/') + 1; ptr[0] = '\0'; sprintf(genbuf, "%s%s", buf, digest.filename); diff --git a/pttbbs/mbbsd/board.c b/pttbbs/mbbsd/board.c index 4626adb5..859c8c8b 100644 --- a/pttbbs/mbbsd/board.c +++ b/pttbbs/mbbsd/board.c @@ -1,4 +1,4 @@ -/* $Id: board.c,v 1.40 2002/07/05 17:10:26 in2 Exp $ */ +/* $Id: board.c,v 1.41 2002/07/21 08:18:41 in2 Exp $ */ #include "bbs.h" #define BRC_STRLEN 15 /* Length of board name */ #define BRC_MAXSIZE 24576 @@ -113,7 +113,7 @@ brc_initial(char *boardname) return brc_num; } brc_update(); - strcpy(currboard, boardname); + strlcpy(currboard, boardname, sizeof(currboard)); currbid = getbnum(currboard); currbrdattr = bcache[currbid - 1].brdattr; read_brc_buf(); diff --git a/pttbbs/mbbsd/cache.c b/pttbbs/mbbsd/cache.c index 5f97c503..ba0701a8 100644 --- a/pttbbs/mbbsd/cache.c +++ b/pttbbs/mbbsd/cache.c @@ -1,4 +1,4 @@ -/* $Id: cache.c,v 1.41 2002/07/05 17:10:26 in2 Exp $ */ +/* $Id: cache.c,v 1.42 2002/07/21 08:18:41 in2 Exp $ */ #include "bbs.h" #ifndef __FreeBSD__ @@ -154,7 +154,7 @@ add_to_uhash(int n, char *id) { int *p, h = StringHash(id); int times; - strcpy(SHM->userid[n], id); + strlcpy(SHM->userid[n], id, sizeof(SHM->userid[n])); p = &(SHM->hash_head[h]); diff --git a/pttbbs/mbbsd/cal.c b/pttbbs/mbbsd/cal.c index cd2c0d48..f423f8e3 100644 --- a/pttbbs/mbbsd/cal.c +++ b/pttbbs/mbbsd/cal.c @@ -1,4 +1,4 @@ -/* $Id: cal.c,v 1.16 2002/07/05 17:10:26 in2 Exp $ */ +/* $Id: cal.c,v 1.17 2002/07/21 08:18:41 in2 Exp $ */ #include "bbs.h" /* 防堵 Multi play */ @@ -93,7 +93,7 @@ osong(char *defaultid) fileheader_t mail; int nsongs; - strcpy(buf, Cdatedate(&now)); + strlcpy(buf, Cdatedate(&now), sizeof(buf)); lockreturn0(OSONG, LOCK_MULTI); @@ -130,7 +130,7 @@ osong(char *defaultid) destid, sizeof(destid), DOECHO); } } else - strcpy(destid, defaultid); + strlcpy(destid, defaultid, sizeof(destid)); /* Heat:點歌者匿名功能 */ getdata(14, 0, "要匿名嗎?[y/n]:", ano, sizeof(ano), DOECHO); @@ -155,7 +155,7 @@ osong(char *defaultid) unlockutmpmode(); return 0; } - strcpy(filename, OSONGPATH); + strlcpy(filename, OSONGPATH, sizeof(filename)); stampfile(filename, &mail); @@ -166,7 +166,7 @@ osong(char *defaultid) unlockutmpmode(); return 0; } - strcpy(mail.owner, "點歌機"); + strlcpy(mail.owner, "點歌機", sizeof(mail.owner)); sprintf(mail.title, "◇ %s 點給 %s ", (ano[0] == 'y') ? "匿名者" : cuser.userid, destid); while (fgets(buf, 200, fp)) { @@ -183,17 +183,17 @@ osong(char *defaultid) while ((po = strstr(buf, "<~Src~>"))) { po[0] = 0; sprintf(genbuf, "%s%s%s", buf, (ano[0] == 'y') ? "匿名者" : cuser.userid, po + 7); - strcpy(buf, genbuf); + strlcpy(buf, genbuf, sizeof(buf)); } while ((po = strstr(buf, "<~Des~>"))) { po[0] = 0; sprintf(genbuf, "%s%s%s", buf, destid, po + 7); - strcpy(buf, genbuf); + strlcpy(buf, genbuf, sizeof(buf)); } while ((po = strstr(buf, "<~Say~>"))) { po[0] = 0; sprintf(genbuf, "%s%s%s", buf, say, po + 7); - strcpy(buf, genbuf); + strlcpy(buf, genbuf, sizeof(buf)); } fputs(buf, fp1); } @@ -346,7 +346,7 @@ mail_redenvelop(char *from, char *to, int money, char mode) ,from, ctime(&now), to, money); fclose(fp); sprintf(fhdr.title, "招財進寶"); - strcpy(fhdr.owner, from); + strlcpy(fhdr.owner, from, sizeof(fhdr.owner)); if (mode == 'y') vedit(genbuf, NA, NULL); diff --git a/pttbbs/mbbsd/calendar.c b/pttbbs/mbbsd/calendar.c index a3d7943c..13a8ed16 100644 --- a/pttbbs/mbbsd/calendar.c +++ b/pttbbs/mbbsd/calendar.c @@ -1,4 +1,4 @@ -/* $Id: calendar.c,v 1.4 2002/07/05 17:10:26 in2 Exp $ */ +/* $Id: calendar.c,v 1.5 2002/07/21 08:18:41 in2 Exp $ */ #include "bbs.h" typedef struct event_t { @@ -230,7 +230,7 @@ GenerateCalendar(char **buf, int y, int m, int today, event_t * e) e = e->next; } if (today == first_day + i - 1) { - strcpy(attr1, "\33[1;37;42m"); + strlcpy(attr1, "\33[1;37;42m", sizeof(attr1)); attr2 = CALENDAR_COLOR; } p += sprintf(p, "%s%2d%s", attr1, i, attr2); diff --git a/pttbbs/mbbsd/chat.c b/pttbbs/mbbsd/chat.c index 5dd2d768..5f709bb2 100644 --- a/pttbbs/mbbsd/chat.c +++ b/pttbbs/mbbsd/chat.c @@ -1,4 +1,4 @@ -/* $Id: chat.c,v 1.6 2002/07/05 17:10:27 in2 Exp $ */ +/* $Id: chat.c,v 1.7 2002/07/21 08:18:41 in2 Exp $ */ #include "bbs.h" static int chatline, stop_line; @@ -106,8 +106,8 @@ chat_recv(int fd, char *chatid) } if (c > 0) { - strcpy(genbuf, bptr); - strcpy(buf, genbuf); + strlcpy(genbuf, bptr, sizeof(genbuf)); + strlcpy(buf, genbuf, sizeof(buf)); bufstart = len - 1; } else bufstart = 0; @@ -319,7 +319,7 @@ select_address() else buf[0] -= '1'; if (buf[0] >= 0 && buf[0] < c) - strcpy(trans_buffer, iptab[(int)buf[0]]); + strlcpy(trans_buffer, iptab[(int)buf[0]], sizeof(trans_buffer)); } else { outs("本站沒有登記任何合格茶樓"); pressanykey(); @@ -417,11 +417,11 @@ t_chat() setutmpmode(CHATING); currutmp->in_chat = YEA; - strcpy(currutmp->chatid, chatid); + strlcpy(currutmp->chatid, chatid, sizeof(currutmp->chatid)); clear(); chatline = 2; - strcpy(inbuf, chatid); + strlcpy(inbuf, chatid, sizeof(inbuf)); stop_line = t_lines - 3; move(stop_line, 0); @@ -432,7 +432,7 @@ t_chat() memset(inbuf, 0, 80); sethomepath(fpath, cuser.userid); - strcpy(fpath, tempnam(fpath, "chat_")); + strlcpy(fpath, tempnam(fpath, "chat_"), sizeof(fpath)); flog = fopen(fpath, "w"); while (chatting) { @@ -445,7 +445,7 @@ t_chat() case KEY_UP: cmdpos++; cmdpos %= MAXLASTCMD; - strcpy(inbuf, lastcmd[cmdpos]); + strlcpy(inbuf, lastcmd[cmdpos], sizeof(inbuf)); move(b_lines - 1, chatid_len); clrtoeol(); outs(inbuf); @@ -498,8 +498,9 @@ t_chat() break; for (cmdpos = MAXLASTCMD - 1; cmdpos; cmdpos--) - strcpy(lastcmd[cmdpos], lastcmd[cmdpos - 1]); - strcpy(lastcmd[0], inbuf); + strlcpy(lastcmd[cmdpos], + lastcmd[cmdpos - 1], sizeof(lastcmd[cmdpos])); + strlcpy(lastcmd[0], inbuf, sizeof(lastcmd[0])); inbuf[0] = '\0'; currchar = 0; @@ -593,8 +594,8 @@ t_chat() sethomepath(genbuf, cuser.userid); stampfile(genbuf, &mymail); mymail.filemode = FILE_READ | FILE_HOLD; - strcpy(mymail.owner, "[備.忘.錄]"); - strcpy(mymail.title, "會議\033[1;33m記錄\033[m"); + strlcpy(mymail.owner, "[備.忘.錄]", sizeof(mymail.owner)); + strlcpy(mymail.title, "會議\033[1;33m記錄\033[m", sizeof(mymail.title)); sethomedir(title, cuser.userid); append_record(title, &mymail, sizeof(mymail)); Rename(fpath, genbuf); diff --git a/pttbbs/mbbsd/chc_play.c b/pttbbs/mbbsd/chc_play.c index de093052..53c0ceff 100644 --- a/pttbbs/mbbsd/chc_play.c +++ b/pttbbs/mbbsd/chc_play.c @@ -1,4 +1,4 @@ -/* $Id: chc_play.c,v 1.4 2002/07/05 17:10:27 in2 Exp $ */ +/* $Id: chc_play.c,v 1.5 2002/07/21 08:18:41 in2 Exp $ */ #include "bbs.h" typedef int (*play_func_t) (int, board_t, board_t); @@ -52,7 +52,7 @@ hisplay(int s, board_t board, board_t tmpbrd) } else { if (chc_from.r == -1) { chc_hepass = 1; - strcpy(chc_warnmsg, "\033[1;33m要求和局!\033[m"); + strlcpy(chc_warnmsg, "\033[1;33m要求和局!\033[m", sizeof(chc_warnmsg)); chc_drawline(board, WARN_ROW); } else { chc_from.r = 9 - chc_from.r, chc_from.c = 8 - chc_from.c; @@ -130,7 +130,7 @@ myplay(int s, board_t board, board_t tmpbrd) chc_ipass = 1; chc_from.r = -1; chc_sendmove(s); - strcpy(chc_warnmsg, "\033[1;33m要求和棋!\033[m"); + strlcpy(chc_warnmsg, "\033[1;33m要求和棋!\033[m", sizeof(chc_warnmsg)); chc_drawline(board, WARN_ROW); bell(); break; @@ -160,7 +160,7 @@ myplay(int s, board_t board, board_t tmpbrd) chc_drawline(board, LTR(chc_to.r)); endturn = 1; } else { - strcpy(chc_warnmsg, "\033[1;33m不可以王見王\033[m"); + strlcpy(chc_warnmsg, "\033[1;33m不可以王見王\033[m", sizeof(chc_warnmsg)); bell(); chc_drawline(board, WARN_ROW); } @@ -190,7 +190,7 @@ mainloop(int s, board_t board) chc_firststep = 0; chc_drawline(board, TURN_ROW); if (chc_ischeck(board, chc_turn)) { - strcpy(chc_warnmsg, "\033[1;31m將軍!\033[m"); + strlcpy(chc_warnmsg, "\033[1;31m將軍!\033[m", sizeof(chc_warnmsg)); bell(); } else chc_warnmsg[0] = 0; @@ -199,13 +199,13 @@ mainloop(int s, board_t board) } if (endgame == 1) { - strcpy(chc_warnmsg, "對方認輸了!"); + strlcpy(chc_warnmsg, "對方認輸了!", sizeof(chc_warnmsg)); cuser.chc_win++; } else if (endgame == 2) { - strcpy(chc_warnmsg, "你認輸了!"); + strlcpy(chc_warnmsg, "你認輸了!", sizeof(chc_warnmsg)); cuser.chc_lose++; } else { - strcpy(chc_warnmsg, "和棋"); + strlcpy(chc_warnmsg, "和棋", sizeof(chc_warnmsg)); cuser.chc_tie++; } cuser.chc_lose--; diff --git a/pttbbs/mbbsd/chicken.c b/pttbbs/mbbsd/chicken.c index 6b43ee33..f9420a43 100644 --- a/pttbbs/mbbsd/chicken.c +++ b/pttbbs/mbbsd/chicken.c @@ -1,4 +1,4 @@ -/* $Id: chicken.c,v 1.6 2002/07/05 17:10:27 in2 Exp $ */ +/* $Id: chicken.c,v 1.7 2002/07/21 08:18:41 in2 Exp $ */ #include "bbs.h" #define NUM_KINDS 13 /* 有多少種動物 */ @@ -707,7 +707,7 @@ ch_changename() cuser.userid, mychicken->name, chicken_type[(int)mychicken->type], newname, ctime(&now)); - strcpy(mychicken->name, newname); + strlcpy(mychicken->name, newname, sizeof(mychicken->name)); log_file(CHICKENLOG, buf); } } @@ -830,7 +830,7 @@ recover_chicken(chicken_t * thechicken) igetch(); return 0; } - strcpy(thechicken->name, "[撿回來的]"); + strlcpy(thechicken->name, "[撿回來的]", sizeof(thechicken->name)); thechicken->hp = thechicken->hp_max; thechicken->sick = 0; thechicken->satis = 2; @@ -890,7 +890,8 @@ chickenpk(int fd) lockreturn0(CHICKEN, LOCK_MULTI); - strcpy(mateid, currutmp->mateid); /* 把對手的id用local buffer記住 */ + strlcpy(mateid, currutmp->mateid, sizeof(mateid)); + /* 把對手的id用local buffer記住 */ getuser(mateid); memcpy(&ouser, &xuser, sizeof(userec_t)); @@ -990,7 +991,7 @@ chickenpk(int fd) } if (deadtype(ochicken)) { strtok(data, "\n"); - strcpy(buf, data); + strlcpy(buf, data, sizeof(buf)); sprintf(data, "d%s , %s 被 %s 打死了\n", buf + 1, ochicken->name, mychicken->name); } diff --git a/pttbbs/mbbsd/dark.c b/pttbbs/mbbsd/dark.c index 19e17444..f464bf11 100644 --- a/pttbbs/mbbsd/dark.c +++ b/pttbbs/mbbsd/dark.c @@ -1,4 +1,4 @@ -/* $Id: dark.c,v 1.5 2002/07/05 17:10:27 in2 Exp $ */ +/* $Id: dark.c,v 1.6 2002/07/21 08:18:41 in2 Exp $ */ #include "bbs.h" #define RED 1 @@ -154,7 +154,7 @@ draw_line(sint y, sint f) *buf = 0; *tmp = 0; - strcpy(buf, "\033[43;30m"); + strlcpy(buf, "\033[43;30m", sizeof(buf)); for (i = 0; i < 8; i++) { if (brd[y][i].die == 1) sprintf(tmp, "│ "); diff --git a/pttbbs/mbbsd/edit.c b/pttbbs/mbbsd/edit.c index c210ba8f..d7680380 100644 --- a/pttbbs/mbbsd/edit.c +++ b/pttbbs/mbbsd/edit.c @@ -1,4 +1,4 @@ -/* $Id: edit.c,v 1.12 2002/07/05 17:10:27 in2 Exp $ */ +/* $Id: edit.c,v 1.13 2002/07/21 08:18:41 in2 Exp $ */ #include "bbs.h" typedef struct textline_t { struct textline_t *prev; @@ -767,7 +767,7 @@ write_header(FILE * fp) int number; /* post number */ } postlog; - strcpy(postlog.author, cuser.userid); + strlcpy(postlog.author, cuser.userid, sizeof(postlog.author)); ifuseanony = 0; #ifdef HAVE_ANONYMOUS if (currbrdattr & BRD_ANONYMOUS) { @@ -779,8 +779,8 @@ write_header(FILE * fp) getdata(3, 0, "請輸入你想用的ID,也可直接按[Enter]使用原ID:", real_name, sizeof(real_name), DOECHO); if (!real_name[0] && defanony) { - strcpy(real_name, "Anonymous"); - strcpy(postlog.author, real_name); + strlcpy(real_name, "Anonymous", sizeof(real_name)); + strlcpy(postlog.author, real_name, sizeof(postlog.author)); ifuseanony = 1; } else { if (!strcmp("r", real_name) || (!defanony && !real_name[0])) @@ -792,7 +792,7 @@ write_header(FILE * fp) } } #endif - strcpy(postlog.board, currboard); + strlcpy(postlog.board, currboard, sizeof(postlog.board)); ptr = save_title; if (!strncmp(ptr, str_reply, 4)) ptr += 4; @@ -929,9 +929,9 @@ write_file(char *fpath, int saveheader, int *islocal) case 't': move(3, 0); prints("舊標題:%s", save_title); - strcpy(ans, save_title); + strlcpy(ans, save_title, sizeof(ans)); if (getdata_buf(4, 0, "新標題:", ans, sizeof(ans), DOECHO)) - strcpy(save_title, ans); + strlcpy(save_title, ans, sizeof(save_title)); return KEEP_EDITING; case 's': if (!HAS_PERM(PERM_LOGINOK)) { @@ -1429,10 +1429,10 @@ block_del(int hide) char buf[WRAPMARGIN + 2]; if (currpnt > blockpnt) { - strcpy(buf, begin->data + blockpnt); + strlcpy(buf, begin->data + blockpnt, sizeof(buf)); buf[currpnt - blockpnt] = 0; } else { - strcpy(buf, begin->data + currpnt); + strlcpy(buf, begin->data + currpnt, sizeof(buf)); buf[blockpnt - currpnt] = 0; } fputs(buf, fp); @@ -1454,7 +1454,7 @@ block_del(int hide) min = currpnt; max = blockpnt; } - strcpy(begin->data + min, begin->data + max); + strlcpy(begin->data + min, begin->data + max, sizeof(begin->data) - min); begin->len -= max - min; currpnt = min; } else { @@ -1780,7 +1780,7 @@ vedit(char *fpath, int saveheader, int *islocal) char *tmp, *apos = ans; int fg, bg; - strcpy(color, "\033["); + strlcpy(color, "\033[", sizeof(color)); if (isdigit(*apos)) { sprintf(color, "%s%c", color, *(apos++)); if (*apos) @@ -1933,7 +1933,7 @@ vedit(char *fpath, int saveheader, int *islocal) if (strcmp(line, currline->data)) { char buf[WRAPMARGIN]; - strcpy(buf, currline->data); + strlcpy(buf, currline->data, sizeof(buf)); strcpy(currline->data, line); strcpy(line, buf); currline->len = strlen(currline->data); diff --git a/pttbbs/mbbsd/friend.c b/pttbbs/mbbsd/friend.c index 81abf097..2753282c 100644 --- a/pttbbs/mbbsd/friend.c +++ b/pttbbs/mbbsd/friend.c @@ -1,4 +1,4 @@ -/* $Id: friend.c,v 1.9 2002/07/05 17:10:27 in2 Exp $ */ +/* $Id: friend.c,v 1.10 2002/07/21 08:18:41 in2 Exp $ */ #include "bbs.h" /* ------------------------------------- */ @@ -93,7 +93,7 @@ friend_add(char *uident, int type) char t_uident[IDLEN + 1]; /* Thor: avoid uident run away when get data */ - strcpy(t_uident, uident); + strlcpy(t_uident, uident, sizeof(t_uident)); if (type != FRIEND_ALOHA && type != FRIEND_POST) getdata(2, 0, friend_desc[type], buf, sizeof(buf), DOECHO); diff --git a/pttbbs/mbbsd/gamble.c b/pttbbs/mbbsd/gamble.c index 5a93c275..1fa62e13 100644 --- a/pttbbs/mbbsd/gamble.c +++ b/pttbbs/mbbsd/gamble.c @@ -1,4 +1,4 @@ -/* $Id: gamble.c,v 1.25 2002/07/05 17:10:27 in2 Exp $ */ +/* $Id: gamble.c,v 1.26 2002/07/21 08:18:41 in2 Exp $ */ #include "bbs.h" #ifndef _BBS_UTIL_C_ @@ -33,8 +33,8 @@ post_msg(char *bname, char *title, char *msg, char *author) fclose(fp); /* 將檔案加入列表 */ - strcpy(fhdr.title, title); - strcpy(fhdr.owner, author); + strlcpy(fhdr.title, title, sizeof(fhdr.title)); + strlcpy(fhdr.owner, author, sizeof(fhdr.owner)); setbdir(genbuf, bname); if (append_record(genbuf, &fhdr, sizeof(fhdr)) != -1) if ((bid = getbnum(bname)) > 0) diff --git a/pttbbs/mbbsd/gomo.c b/pttbbs/mbbsd/gomo.c index 1eb6ca77..49a1694a 100644 --- a/pttbbs/mbbsd/gomo.c +++ b/pttbbs/mbbsd/gomo.c @@ -1,4 +1,4 @@ -/* $Id: gomo.c,v 1.6 2002/07/05 17:10:27 in2 Exp $ */ +/* $Id: gomo.c,v 1.7 2002/07/21 08:18:41 in2 Exp $ */ #include "bbs.h" static char *chess[] = {"●", "○"}; @@ -72,7 +72,7 @@ HO_log(char *user) stampfile(buf1, &mymail); mymail.filemode = FILE_READ | FILE_HOLD; - strcpy(mymail.owner, "[備.忘.錄]"); + strlcpy(mymail.owner, "[備.忘.錄]", sizeof(mymail.owner)); sprintf(mymail.title, "\033[37;41m棋譜\033[m %s VS %s", cuser.userid, user); sethomedir(title, cuser.userid); diff --git a/pttbbs/mbbsd/indict.c b/pttbbs/mbbsd/indict.c index 5a575211..6e44c612 100644 --- a/pttbbs/mbbsd/indict.c +++ b/pttbbs/mbbsd/indict.c @@ -1,4 +1,4 @@ -/* $Id: indict.c,v 1.5 2002/07/05 17:10:27 in2 Exp $ */ +/* $Id: indict.c,v 1.6 2002/07/21 08:18:41 in2 Exp $ */ #include "bbs.h" #define REFER "etc/dicts" @@ -58,8 +58,8 @@ choose_dict(void) cho[0] = (cho[0] + 1) * 10 + (cho[1] - '1'); if (cho[0] >= 0 && cho[0] < c) { - strcpy(dict, buf[(int)cho[0]]); - strcpy(database, data[(int)cho[0]]); + strlcpy(dict, buf[(int)cho[0]], sizeof(dict)); + strlcpy(database, data[(int)cho[0]], sizeof(database)); return 1; } else return 0; @@ -96,7 +96,7 @@ use_dict() sprintf(buf, "\033[45m ●\033[1;44;33m" " %-14s\033[3;45m ● ", dict); - strcpy(&buf[100], "\033[m\n"); + strlcpy(&buf[100], "\033[m\n", sizeof(buf) - 100); for (;;) { move(0, 0); sprintf(lang, " 請輸入關鍵字串(%s) 或指令(h,t,a)\n", dict); @@ -106,7 +106,7 @@ use_dict() outs(lang); getdata(2, 0, ":", word, 18, DOECHO); outs("資料搜尋中請稍候...."); - strcpy(word, lower(word)); + strlcpy(word, lower(word), sizeof(word)); if (word[0] == 0) return 0; clear(); diff --git a/pttbbs/mbbsd/io.c b/pttbbs/mbbsd/io.c index 7d993d0f..29516595 100644 --- a/pttbbs/mbbsd/io.c +++ b/pttbbs/mbbsd/io.c @@ -1,4 +1,4 @@ -/* $Id: io.c,v 1.18 2002/07/05 17:10:27 in2 Exp $ */ +/* $Id: io.c,v 1.19 2002/07/21 08:18:41 in2 Exp $ */ #include "bbs.h" #if defined(linux) @@ -463,7 +463,7 @@ oldgetdata(int line, int col, char *prompt, char *buf, int len, int echo) if (clen > 1) for (cmdpos = MAXLASTCMD - 1; cmdpos; cmdpos--) { - strcpy(lastcmd[cmdpos], lastcmd[cmdpos - 1]); + strlcpy(lastcmd[cmdpos], lastcmd[cmdpos - 1], sizeof(lastcmd[cmdpos])); strncpy(lastcmd[0], buf, len); } if (echo) @@ -474,7 +474,7 @@ oldgetdata(int line, int col, char *prompt, char *buf, int len, int echo) buf[0] = ch | 32; #ifdef SUPPORT_GB if (echo == DOECHO && current_font_type == TYPE_GB) { - strcpy(buf, hc_convert_str(buf, HC_GBtoBIG, HC_DO_SINGLE)); + strlcpy(buf, hc_convert_str(buf, HC_GBtoBIG, HC_DO_SINGLE), sizeof(buf)); } #endif return clen; diff --git a/pttbbs/mbbsd/lovepaper.c b/pttbbs/mbbsd/lovepaper.c index c2f4459c..1bd4a125 100644 --- a/pttbbs/mbbsd/lovepaper.c +++ b/pttbbs/mbbsd/lovepaper.c @@ -1,4 +1,4 @@ -/* $Id: lovepaper.c,v 1.7 2002/07/05 17:10:27 in2 Exp $ */ +/* $Id: lovepaper.c,v 1.8 2002/07/21 08:18:41 in2 Exp $ */ #include "bbs.h" #define DATA "etc/lovepaper.dat" @@ -95,7 +95,7 @@ x_love() stampfile(buf1, &mhdr); Rename(path, buf1); strncpy(mhdr.title, save_title, TTLEN); - strcpy(mhdr.owner, cuser.userid); + strlcpy(mhdr.owner, cuser.userid, sizeof(mhdr.owner)); sethomedir(path, receiver); if (append_record(path, &mhdr, sizeof(mhdr)) == -1) return -1; diff --git a/pttbbs/mbbsd/mail.c b/pttbbs/mbbsd/mail.c index 7c88cd1b..f8b1ebe3 100644 --- a/pttbbs/mbbsd/mail.c +++ b/pttbbs/mbbsd/mail.c @@ -1,4 +1,4 @@ -/* $Id: mail.c,v 1.19 2002/07/20 08:51:00 in2 Exp $ */ +/* $Id: mail.c,v 1.20 2002/07/21 08:18:41 in2 Exp $ */ #include "bbs.h" char currmaildir[32]; static char msg_cc[] = "\033[32m[群組名單]\033[m\n"; @@ -92,7 +92,7 @@ mail_id(char *id, char *title, char *filename, char *owner) sethomepath(genbuf, id); if (stampfile(genbuf, &mhdr)) return 0; - strcpy(mhdr.owner, owner); + strlcpy(mhdr.owner, owner, sizeof(mhdr.owner)); strncpy(mhdr.title, title, TTLEN); mhdr.filemode = 0; Link(filename, genbuf); @@ -196,12 +196,12 @@ do_hold_mail(char *fpath, char *receiver, char *holder) stampfile(buf, &mymail); mymail.filemode = FILE_READ | FILE_HOLD; - strcpy(mymail.owner, "[備.忘.錄]"); + strlcpy(mymail.owner, "[備.忘.錄]", sizeof(mymail.owner)); if (receiver) { sprintf(title, "(%s) %s", receiver, save_title); strncpy(mymail.title, title, TTLEN); } else - strcpy(mymail.title, save_title); + strlcpy(mymail.title, save_title, sizeof(mymail.title)); sethomedir(title, holder); @@ -282,10 +282,10 @@ do_send(char *userid, char *title) unlink(fpath); return res; } else { - strcpy(receiver, userid); + strlcpy(receiver, userid, sizeof(receiver)); sethomepath(genbuf, userid); stampfile(genbuf, &mhdr); - strcpy(mhdr.owner, cuser.userid); + strlcpy(mhdr.owner, cuser.userid, sizeof(mhdr.owner)); strncpy(mhdr.title, save_title, TTLEN); if (vedit(genbuf, YEA, NULL) == -1) { unlink(genbuf); @@ -520,8 +520,8 @@ multi_send(char *title) unlink(genbuf); Link(fpath, genbuf); - strcpy(mymail.owner, cuser.userid); - strcpy(mymail.title, save_title); + strlcpy(mymail.owner, cuser.userid, sizeof(mymail.owner)); + strlcpy(mymail.title, save_title, sizeof(mymail.title)); mymail.filemode |= FILE_MULTI; /* multi-send flag */ sethomedir(genbuf, p->word); if (append_record(genbuf, &mymail, sizeof(mymail)) == -1) @@ -543,7 +543,7 @@ multi_reply(int ent, fileheader_t * fhdr, char *direct) return mail_reply(ent, fhdr, direct); stand_title("群組回信"); - strcpy(quote_user, fhdr->owner); + strlcpy(quote_user, fhdr->owner, sizeof(quote_user)); setuserfile(quote_file, fhdr->filename); multi_send(fhdr->title); return 0; @@ -603,8 +603,8 @@ mail_all() unlink(fpath); strcpy(fpath, genbuf); - strcpy(mymail.owner, cuser.userid); /* 站長 ID */ - strcpy(mymail.title, save_title); + strlcpy(mymail.owner, cuser.userid, sizeof(mymail.owner)); /* 站長 ID */ + strlcpy(mymail.title, save_title, sizeof(mymail.title)); sethomedir(genbuf, cuser.userid); if (append_record(genbuf, &mymail, sizeof(mymail)) == -1) @@ -622,8 +622,8 @@ mail_all() unlink(genbuf); Link(fpath, genbuf); - strcpy(mymail.owner, cuser.userid); - strcpy(mymail.title, save_title); + strlcpy(mymail.owner, cuser.userid, sizeof(mymail.owner)); + strlcpy(mymail.title, save_title, sizeof(mymail.title)); /* mymail.filemode |= FILE_MARKED; Ptt 公告改成不會mark */ sethomedir(genbuf, userid); if (append_record(genbuf, &mymail, sizeof(mymail)) == -1) @@ -658,7 +658,7 @@ m_forward(int ent, fileheader_t * fhdr, char *direct) if (uid[0] == '\0') return FULLUPDATE; - strcpy(quote_user, fhdr->owner); + strlcpy(quote_user, fhdr->owner, sizeof(quote_user)); setuserfile(quote_file, fhdr->filename); sprintf(save_title, "%.64s (fwd)", fhdr->title); move(1, 0); @@ -862,7 +862,7 @@ mail_del(int ent, fileheader_t * fhdr, char *direct) getdata(1, 0, msg_del_ny, genbuf, 3, LCECHO); if (genbuf[0] == 'y') { - strcpy(currfile, fhdr->filename); + strlcpy(currfile, fhdr->filename, sizeof(currfile)); if (!delete_file(direct, sizeof(*fhdr), ent, cmpfilename)) { setdirpath(genbuf, direct, fhdr->filename); unlink(genbuf); @@ -987,7 +987,7 @@ mail_reply(int ent, fileheader_t * fhdr, char *direct) setbfile(quote_file, currboard, fhdr->filename); /* find the author */ - strcpy(quote_user, fhdr->owner); + strlcpy(quote_user, fhdr->owner, sizeof(quote_user)); if (strchr(quote_user, '.')) { genbuf[0] = '\0'; if ((fp = fopen(quote_file, "r"))) { @@ -996,14 +996,14 @@ mail_reply(int ent, fileheader_t * fhdr, char *direct) } t = strtok(genbuf, str_space); if (!strcmp(t, str_author1) || !strcmp(t, str_author2)) - strcpy(uid, strtok(NULL, str_space)); + strlcpy(uid, strtok(NULL, str_space), sizeof(uid)); else { outs("錯誤: 找不到作者。"); pressanykey(); return FULLUPDATE; } } else - strcpy(uid, quote_user); + strlcpy(uid, quote_user, sizeof(uid)); /* make the title */ do_reply_title(3, fhdr->title); @@ -1137,13 +1137,13 @@ mail_cross_post(int ent, fileheader_t * fhdr, char *direct) if (ent) sprintf(xtitle, "[轉錄]%.66s", fhdr->title); else - strcpy(xtitle, fhdr->title); + strlcpy(xtitle, fhdr->title, sizeof(xtitle)); sprintf(genbuf, "採用原標題《%.60s》嗎?[Y] ", xtitle); getdata(2, 0, genbuf, genbuf2, sizeof(genbuf2), LCECHO); if (*genbuf2 == 'n') if (getdata(2, 0, "標題:", genbuf, TTLEN, DOECHO)) - strcpy(xtitle, genbuf); + strlcpy(xtitle, genbuf, sizeof(xtitle)); getdata(2, 0, "(S)存檔 (L)站內 (Q)取消?[Q] ", genbuf, 3, LCECHO); if (genbuf[0] == 'l' || genbuf[0] == 's') { @@ -1153,10 +1153,10 @@ mail_cross_post(int ent, fileheader_t * fhdr, char *direct) setbpath(xfpath, xboard); stampfile(xfpath, &xfile); if (author) - strcpy(xfile.owner, fhdr->owner); + strlcpy(xfile.owner, fhdr->owner, sizeof(xfile.owner)); else - strcpy(xfile.owner, cuser.userid); - strcpy(xfile.title, xtitle); + strlcpy(xfile.owner, cuser.userid, sizeof(xfile.owner)); + strlcpy(xfile.title, xtitle, sizeof(xfile.title)); if (genbuf[0] == 'l') { xfile.filemode = FILE_LOCAL; } @@ -1164,11 +1164,11 @@ mail_cross_post(int ent, fileheader_t * fhdr, char *direct) if (ent) { xptr = fopen(xfpath, "w"); - strcpy(save_title, xfile.title); - strcpy(xfpath, currboard); - strcpy(currboard, xboard); + strlcpy(save_title, xfile.title, sizeof(save_title)); + strlcpy(xfpath, currboard, sizeof(xfpath)); + strlcpy(currboard, xboard, sizeof(currboard)); write_header(xptr); - strcpy(currboard, xfpath); + strlcpy(currboard, xfpath, sizeof(currboard)); fprintf(xptr, "※ [本文轉錄自 %s 信箱]\n\n", cuser.userid); @@ -1222,7 +1222,7 @@ mail_cite(int ent, fileheader_t * fhdr, char *direct) boardheader_t *bp; setuserfile(fpath, fhdr->filename); - strcpy(title, "◇ "); + strlcpy(title, "◇ ", sizeof(title)); strncpy(title + 3, fhdr->title, TTLEN - 3); title[TTLEN] = '\0'; a_copyitem(fpath, title, 0, 1); @@ -1241,7 +1241,7 @@ mail_cite(int ent, fileheader_t * fhdr, char *direct) completeboard_permission, completeboard_getname); if (*buf) - strcpy(xboard, buf); + strlcpy(xboard, buf, sizeof(xboard)); if (*xboard && (bp = getbcache(getbnum(xboard)))) { setapath(fpath, xboard); setutmpmode(ANNOUNCE); @@ -1265,7 +1265,7 @@ mail_save(int ent, fileheader_t * fhdr, char *direct) if (HAS_PERM(PERM_MAILLIMIT)) { setuserfile(fpath, fhdr->filename); - strcpy(title, "◇ "); + strlcpy(title, "◇ ", sizeof(title)); strncpy(title + 3, fhdr->title, TTLEN - 3); title[TTLEN] = '\0'; a_copyitem(fpath, title, fhdr->owner, 1); @@ -1289,7 +1289,7 @@ mail_waterball(int ent, fileheader_t * fhdr, char *direct) return 1; } if (!address[0]) - strcpy(address, cuser.email); + strlcpy(address, cuser.email, sizeof(address)); move(b_lines - 8, 0); outs("水球整理程式:\n" "系統將會按照和不同人丟的水球各自獨立\n" @@ -1307,7 +1307,7 @@ mail_waterball(int ent, fileheader_t * fhdr, char *direct) if (!address[0]) { getdata(b_lines - 5, 0, "請輸入郵件地址:", fname, 60, DOECHO); if (fname[0] && strchr(fname, '.')) { - strcpy(address, fname); + strlcpy(address, fname, sizeof(address)); } else { vmsg("取消處理"); return 1; @@ -1395,10 +1395,10 @@ send_inner_mail(char *fpath, char *title, char *receiver) sethomepath(genbuf, receiver); stampfile(genbuf, &mymail); if (!strcmp(receiver, cuser.userid)) { - strcpy(mymail.owner, "[" BBSNAME "]"); + strlcpy(mymail.owner, "[" BBSNAME "]", sizeof(mymail.owner)); mymail.filemode = FILE_READ; } else - strcpy(mymail.owner, cuser.userid); + strlcpy(mymail.owner, cuser.userid, sizeof(mymail.owner)); strncpy(mymail.title, title, TTLEN); unlink(genbuf); Link(fpath, genbuf); @@ -1438,7 +1438,7 @@ bbs_sendmail(char *fpath, char *title, char *receiver) memcpy(hacker, receiver, len); hacker[len] = '\0'; } else - strcpy(hacker, receiver); + strlcpy(hacker, receiver, sizeof(hacker)); return send_inner_mail(fpath, title, hacker); } /* setup the hostname and username */ @@ -1507,13 +1507,13 @@ bsmtp(char *fpath, char *title, char *rcpt, int method) memcpy(hacker, rcpt, len); hacker[len] = '\0'; } else - strcpy(hacker, rcpt); + strlcpy(hacker, rcpt, sizeof(hacker)); return send_inner_mail(fpath, title, hacker); } chrono = now; if (method != MQ_JUSTIFY) { /* 認證信 */ /* stamp the queue file */ - strcpy(buf, "out/"); + strlcpy(buf, "out/", sizeof(buf)); for (;;) { sprintf(buf + 4, "M.%ld.A", ++chrono); if (!dashf(buf)) { @@ -1524,15 +1524,15 @@ bsmtp(char *fpath, char *title, char *rcpt, int method) fpath = buf; - strcpy(mqueue.filepath, fpath); - strcpy(mqueue.subject, title); + strlcpy(mqueue.filepath, fpath, sizeof(mqueue.filepath)); + strlcpy(mqueue.subject, title, sizeof(mqueue.subject)); } /* setup mail queue */ mqueue.mailtime = chrono; mqueue.method = method; - strcpy(mqueue.sender, cuser.userid); - strcpy(mqueue.username, cuser.username); - strcpy(mqueue.rcpt, rcpt); + strlcpy(mqueue.sender, cuser.userid, sizeof(mqueue.sender)); + strlcpy(mqueue.username, cuser.username, sizeof(mqueue.username)); + strlcpy(mqueue.rcpt, rcpt, sizeof(mqueue.rcpt)); if (do_append("out/.DIR", (fileheader_t *) & mqueue, sizeof(mqueue)) < 0) return 0; return chrono; @@ -1548,7 +1548,7 @@ doforward(char *direct, fileheader_t * fh, int mode) char genbuf[200]; if (!address[0]) - strcpy(address, cuser.email); + strlcpy(address, cuser.email, sizeof(address)); if (address[0]) { sprintf(genbuf, "確定轉寄給 [%s] 嗎(Y/N/Q)?[Y] ", address); @@ -1566,7 +1566,7 @@ doforward(char *direct, fileheader_t * fh, int mode) getdata(b_lines - 1, 0, "請輸入轉寄地址:", fname, 60, DOECHO); if (fname[0]) { if (strchr(fname, '.')) - strcpy(address, fname); + strlcpy(address, fname, sizeof(address)); else sprintf(address, "%s.bbs@%s", fname, MYHOSTNAME); } else { @@ -1603,7 +1603,7 @@ doforward(char *direct, fileheader_t * fh, int mode) "/usr/bin/uuencode %s.tgz > %s", cuser.userid[0], cuser.userid, cuser.userid, direct); system(fname); - strcpy(fname, direct); + strlcpy(fname, direct, sizeof(fname)); } else if (mode == 'U') { char tmp_buf[128]; @@ -1675,7 +1675,7 @@ mail_justify(userec_t muser) sethomepath(buf1, muser.userid); stampfile(buf1, &mhdr); unlink(buf1); - strcpy(mhdr.owner, cuser.userid); + strlcpy(mhdr.owner, cuser.userid, sizeof(mhdr.owner)); strncpy(mhdr.title, "[審核通過]", TTLEN); mhdr.filemode = 0; diff --git a/pttbbs/mbbsd/mbbsd.c b/pttbbs/mbbsd/mbbsd.c index c9736e1b..954cac82 100644 --- a/pttbbs/mbbsd/mbbsd.c +++ b/pttbbs/mbbsd/mbbsd.c @@ -1,4 +1,4 @@ -/* $Id: mbbsd.c,v 1.40 2002/07/05 17:10:27 in2 Exp $ */ +/* $Id: mbbsd.c,v 1.41 2002/07/21 08:18:41 in2 Exp $ */ #include "bbs.h" #define SOCKET_QLEN 4 @@ -100,8 +100,9 @@ chkload(char *buf) (i > MAX_CPULOAD ? ",高負荷量,請稍後再來 " "(請利用port 3000~3010連線)" : "")); #ifdef INSCREEN - strcpy(buf, (i > MAX_CPULOAD ? BANNER - "高負荷量,請稍後再來(請利用port 3000~3010連線)" : "")); + strlcpy(buf, (i > MAX_CPULOAD ? BANNER + "高負荷量,請稍後再來(請利用port 3000~3010連線)" : ""), + sizeof(buf)); #else sprintf(buf, BANNER "%s\r\n", (i > MAX_CPULOAD ? "高負荷量,請稍後再來(請利用port 3000~3010連線)" : "")); @@ -591,7 +592,7 @@ add_distinct(char *fname, char *line) char tmpname[100]; FILE *fptmp; - strcpy(tmpname, fname); + strlcpy(tmpname, fname, sizeof(tmpname)); strcat(tmpname, "_tmp"); if (!(fptmp = fopen(tmpname, "w"))) { fclose(fp); @@ -637,7 +638,7 @@ del_distinct(char *fname, char *line) char tmpname[100]; FILE *fptmp; - strcpy(tmpname, fname); + strlcpy(tmpname, fname, sizeof(tmpname)); strcat(tmpname, "_tmp"); if (!(fptmp = fopen(tmpname, "w"))) { fclose(fp); @@ -718,10 +719,10 @@ setup_utmp(int mode) uinfo.userlevel = cuser.userlevel; uinfo.sex = cuser.sex % 8; uinfo.lastact = time(NULL); - strcpy(uinfo.userid, cuser.userid); - strcpy(uinfo.realname, cuser.realname); - strcpy(uinfo.username, cuser.username); - strncpy(uinfo.from, fromhost, 23); + strlcpy(uinfo.userid, cuser.userid, sizeof(uinfo.userid)); + strlcpy(uinfo.realname, cuser.realname, sizeof(uinfo.realname)); + strlcpy(uinfo.username, cuser.username, sizeof(uinfo.username)); + strlcpy(uinfo.from, fromhost, sizeof(uinfo.from)); uinfo.five_win = cuser.five_win; uinfo.five_lose = cuser.five_lose; uinfo.five_tie = cuser.five_tie; @@ -734,7 +735,7 @@ setup_utmp(int mode) #ifndef FAST_LOGIN setuserfile(buf, "remoteuser"); - strcpy(remotebuf, fromhost); + strlcpy(remotebuf, fromhost, sizeof(remotebuf)); strcat(remotebuf, ctime(&now)); remotebuf[strlen(remotebuf) - 1] = 0; add_distinct(buf, remotebuf); @@ -766,7 +767,7 @@ user_login() resolve_fcache(); resolve_boards(); memset(&water[0], 0, sizeof(water_t) * 6); - strcpy(water[0].userid, " 全部 "); + strlcpy(water[0].userid, " 全部 ", sizeof(water[0].userid)); /* 初始化 uinfo、flag、mode */ setup_utmp(LOGIN); mysrand(); /* 初始化: random number 增加user跟時間的差異 */ @@ -1115,7 +1116,7 @@ getremotename(struct sockaddr_in * from, char *rhost, char *rname) */ if ((cp = (char *)strchr(user, '\r'))) *cp = 0; - strcpy(rname, user); + strlcpy(rname, user, sizeof(rname)); } } alarm(0); @@ -1199,7 +1200,7 @@ shell_login(int argc, char *argv[], char *envp[]) if (argc > 1) { strcpy(fromhost, argv[1]); if (argc > 3) - strcpy(remoteusername, argv[3]); + strlcpy(remoteusername, argv[3], sizeof(remoteusername)); } close(2); /* don't close fd 1, at least init_tty need it */ diff --git a/pttbbs/mbbsd/name.c b/pttbbs/mbbsd/name.c index d87d8175..949afaf2 100644 --- a/pttbbs/mbbsd/name.c +++ b/pttbbs/mbbsd/name.c @@ -1,4 +1,4 @@ -/* $Id: name.c,v 1.10 2002/07/05 17:10:27 in2 Exp $ */ +/* $Id: name.c,v 1.11 2002/07/21 08:18:41 in2 Exp $ */ #include "bbs.h" static word_t *current = NULL; @@ -37,7 +37,7 @@ UserSubArray(char cwbuf[][IDLEN + 1], char cwlist[][IDLEN + 1], for (n = 0; n < cwnum; n++) { ch = cwlist[n][pos]; if (ch == key || ch == key2) - strcpy(cwbuf[num++], cwlist[n]); + strlcpy(cwbuf[num++], cwlist[n], sizeof(cwbuf[num])); } return num; } diff --git a/pttbbs/mbbsd/page.c b/pttbbs/mbbsd/page.c index 6e8489e2..a3e11466 100644 --- a/pttbbs/mbbsd/page.c +++ b/pttbbs/mbbsd/page.c @@ -1,4 +1,4 @@ -/* $Id: page.c,v 1.6 2002/07/05 17:10:27 in2 Exp $ */ +/* $Id: page.c,v 1.7 2002/07/21 08:18:41 in2 Exp $ */ #include "bbs.h" #define hpressanykey(a) {move(22, 0); prints(a); pressanykey();} @@ -101,7 +101,7 @@ main_railway() break; sethomepath(genbuf, cuser.userid); stampfile(genbuf, &mhdr); - strcpy(mhdr.owner, "Ptt搜尋器"); + strlcpy(mhdr.owner, "Ptt搜尋器", sizeof(mhdr.owner)); strncpy(mhdr.title, "火車時刻搜尋結果", TTLEN); sprintf(command, "echo \"from-station=%s&to-station=%s" diff --git a/pttbbs/mbbsd/read.c b/pttbbs/mbbsd/read.c index 3d661479..4ef38169 100644 --- a/pttbbs/mbbsd/read.c +++ b/pttbbs/mbbsd/read.c @@ -1,4 +1,4 @@ -/* $Id: read.c,v 1.8 2002/07/05 17:10:28 in2 Exp $ */ +/* $Id: read.c,v 1.9 2002/07/21 08:18:41 in2 Exp $ */ #include "bbs.h" #define MAXPATHLEN 256 @@ -342,9 +342,9 @@ thread(keeploc_t * locmem, int stype) query = (stype & RS_TITLE) ? t_ans : a_ans; if (!*query && query == a_ans) { if (*currowner) - strcpy(a_ans, currowner); + strlcpy(a_ans, currowner, sizeof(a_ans)); else if (*currauthor) - strcpy(a_ans, currauthor); + strlcpy(a_ans, currauthor, sizeof(a_ans)); } sprintf(s_pmt, "%s搜尋%s [%s] ", (stype & RS_FORWARD) ? "往後" : "往前", (stype & RS_TITLE) ? "標題" : "作者", query); @@ -464,7 +464,7 @@ select_read(keeploc_t * locmem, int sr_mode) if (sr_mode == RS_TITLE) query = subject(headers[locmem->crs_ln - locmem->top_ln].title); else if (sr_mode == RS_NEWPOST) { - strcpy(buf3, "Re: "); + strlcpy(buf3, "Re: ", sizeof(buf3)); query = buf3; } else { char buff[80]; @@ -535,7 +535,7 @@ select_read(keeploc_t * locmem, int sr_mode) close(fd); if (st.st_size) { currmode |= MODE_SELECT; - strcpy(currdirect, fpath); + strlcpy(currdirect, fpath, sizeof(currdirect)); } } return st.st_size; @@ -672,7 +672,9 @@ i_read_key(onekey_t * rcmdlist, keeploc_t * locmem, int ch, int bid) int id; userec_t muser; - strcpy(currauthor, headers[locmem->crs_ln - locmem->top_ln].owner); + strlcpy(currauthor, + headers[locmem->crs_ln - locmem->top_ln].owner, + sizeof(currauthor)); stand_title("使用者設定"); move(1, 0); if ((id = getuser(headers[locmem->crs_ln - locmem->top_ln].owner))) { @@ -738,11 +740,11 @@ void i_read(int cmdmode, char *direct, void (*dotitle) (), void (*doe int hit_thread0 = hit_thread; fileheader_t *headers0 = headers; - strcpy(currdirect0, currdirect); + strlcpy(currdirect0, currdirect, sizeof(currdirect0)); #define FHSZ sizeof(fileheader_t) //Ptt:這 鄣eaders i H w 麍搌O 熙怮60 g 甥ache headers = (fileheader_t *) calloc(p_lines, FHSZ); - strcpy(currdirect, direct); + strlcpy(currdirect, direct, sizeof(currdirect)); mode = NEWDIRECT; /* rocker.011018: 加入新的tag機制 */ @@ -923,6 +925,6 @@ return_i_read: last_line = last_line0; hit_thread = hit_thread0; headers = headers0; - strcpy(currdirect, currdirect0); + strlcpy(currdirect, currdirect0, sizeof(currdirect)); return; } diff --git a/pttbbs/mbbsd/record.c b/pttbbs/mbbsd/record.c index bc50cbe1..79dd1801 100644 --- a/pttbbs/mbbsd/record.c +++ b/pttbbs/mbbsd/record.c @@ -1,4 +1,4 @@ -/* $Id: record.c,v 1.7 2002/07/05 17:10:28 in2 Exp $ */ +/* $Id: record.c,v 1.8 2002/07/21 08:18:41 in2 Exp $ */ #include "bbs.h" #undef HAVE_MMAP @@ -41,7 +41,7 @@ get_sum_records(char *fpath, int size) if (!(fp = fopen(fpath, "r"))) return -1; - strcpy(buf, fpath); + strlcpy(buf, fpath, sizeof(buf)); p = strrchr(buf, '/') + 1; while (fread(&fhdr, size, 1, fp) == 1) { @@ -237,7 +237,7 @@ delete_range(char *fpath, int id1, int id2) return -1; } count = 1; - strcpy(fullpath, fpath); + strlcpy(fullpath, fpath, sizeof(fullpath)); t = strrchr(fullpath, '/') + 1; while (read(fdr, &fhdr, sizeof(fileheader_t)) == sizeof(fileheader_t)) { @@ -306,12 +306,12 @@ int delete_files(char *dirname, int (*filecheck) (), int record){ fileheader_t delfh; char deletedDIR[] = "boards/d/deleted/.DIR"; - strcpy(deleted, "boards/d/deleted"); + strlcpy(deleted, "boards/d/deleted", sizeof(deleted)); if (!(fp = fopen(dirname, "r"))) return ans; - strcpy(tmpfname, dirname); + strlcpy(tmpfname, dirname, sizeof(tmpfname)); strcat(tmpfname, "_tmp"); if (!(fptmp = fopen(tmpfname, "w"))) { @@ -325,8 +325,8 @@ int delete_files(char *dirname, int (*filecheck) (), int record){ if (record) { deleted[14] = '\0'; stampfile(deleted, &delfh); - strcpy(delfh.owner, fhdr.owner); - strcpy(delfh.title, fhdr.title); + strlcpy(delfh.owner, fhdr.owner, sizeof(delfh.owner)); + strlcpy(delfh.title, fhdr.title, sizeof(delfh.title)); Link(genbuf, deleted); append_record(deletedDIR, &delfh, sizeof(delfh)); } @@ -442,7 +442,7 @@ stampfile(char *fpath, fileheader_t * fh) } while ((fp = open(fpath, O_CREAT | O_EXCL | O_WRONLY, 0644)) == -1); close(fp); memset(fh, 0, sizeof(fileheader_t)); - strcpy(fh->filename, ip); + strlcpy(fh->filename, ip, sizeof(fh->filename)); ptime = localtime(&dtime); sprintf(fh->date, "%2d/%02d", ptime->tm_mon + 1, ptime->tm_mday); return 0; @@ -464,7 +464,7 @@ stampdir(char *fpath, fileheader_t * fh) sprintf(ip, "D%lX", ++dtime & 07777); } while (mkdir(fpath, 0755) == -1); memset(fh, 0, sizeof(fileheader_t)); - strcpy(fh->filename, ip); + strlcpy(fh->filename, ip, sizeof(fh->filename)); ptime = localtime(&dtime); sprintf(fh->date, "%2d/%02d", ptime->tm_mon + 1, ptime->tm_mday); } @@ -485,7 +485,7 @@ stamplink(char *fpath, fileheader_t * fh) sprintf(ip, "S%lX", ++dtime); } while (symlink("temp", fpath) == -1); memset(fh, 0, sizeof(fileheader_t)); - strcpy(fh->filename, ip); + strlcpy(fh->filename, ip, sizeof(fh->filename)); ptime = localtime(&dtime); sprintf(fh->date, "%2d/%02d", ptime->tm_mon + 1, ptime->tm_mday); } diff --git a/pttbbs/mbbsd/register.c b/pttbbs/mbbsd/register.c index f2b50a9b..3cb92cab 100644 --- a/pttbbs/mbbsd/register.c +++ b/pttbbs/mbbsd/register.c @@ -1,4 +1,4 @@ -/* $Id: register.c,v 1.6 2002/07/05 17:10:28 in2 Exp $ */ +/* $Id: register.c,v 1.7 2002/07/21 08:18:41 in2 Exp $ */ #define _XOPEN_SOURCE #include "bbs.h" @@ -24,7 +24,7 @@ genpasswd(char *pw) c += 6; saltc[i] = c; } - strcpy(pwbuf, pw); + strlcpy(pwbuf, pw, sizeof(pwbuf)); return crypt(pwbuf, saltc); } return ""; @@ -177,7 +177,7 @@ getnewuserid() sprintf(genbuf, "uid %d", i); log_usies("APPLY", genbuf); - strcpy(zerorec.userid, str_new); + strlcpy(zerorec.userid, str_new, sizeof(zerorec.userid)); zerorec.lastlogin = clock; passwd_update(i, &zerorec); setuserid(i, zerorec.userid); diff --git a/pttbbs/mbbsd/screen.c b/pttbbs/mbbsd/screen.c index 12901158..a5cbea77 100644 --- a/pttbbs/mbbsd/screen.c +++ b/pttbbs/mbbsd/screen.c @@ -1,4 +1,4 @@ -/* $Id: screen.c,v 1.4 2002/07/05 17:10:28 in2 Exp $ */ +/* $Id: screen.c,v 1.5 2002/07/21 08:18:41 in2 Exp $ */ #include "bbs.h" #ifdef SUPPORT_GB @@ -336,7 +336,7 @@ parsecolor(char *buf) } val = (char *)strtok(NULL, ";"); } - strcpy(buf, data); + strlcpy(buf, data, sizeof(buf)); } #define NORMAL (00) diff --git a/pttbbs/mbbsd/syspost.c b/pttbbs/mbbsd/syspost.c index 15caf482..6439a735 100644 --- a/pttbbs/mbbsd/syspost.c +++ b/pttbbs/mbbsd/syspost.c @@ -1,4 +1,4 @@ -/* $Id: syspost.c,v 1.12 2002/07/05 17:10:28 in2 Exp $ */ +/* $Id: syspost.c,v 1.13 2002/07/21 08:18:41 in2 Exp $ */ #include "bbs.h" void @@ -9,7 +9,7 @@ post_change_perm(int oldperm, int newperm, char *sysopid, char *userid) char genbuf[200], reason[30]; int i, flag = 0; - strcpy(genbuf, "boards/S/Security"); + strlcpy(genbuf, "boards/S/Security", sizeof(genbuf)); stampfile(genbuf, &fhdr); if (!(fp = fopen(genbuf, "w"))) return; @@ -38,7 +38,7 @@ post_change_perm(int oldperm, int newperm, char *sysopid, char *userid) sprintf(fhdr.title, "[公安報告] 站長%s修改%s權限報告", cuser.userid, userid); - strcpy(fhdr.owner, "[系統安全局]"); + strlcpy(fhdr.owner, "[系統安全局]", sizeof(fhdr.owner)); append_record("boards/S/Security/.DIR", &fhdr, sizeof(fhdr)); } } @@ -49,7 +49,7 @@ post_violatelaw(char *crime, char *police, char *reason, char *result) char genbuf[200]; fileheader_t fhdr; FILE *fp; - strcpy(genbuf, "boards/S/Security"); + strlcpy(genbuf, "boards/S/Security", sizeof(genbuf)); stampfile(genbuf, &fhdr); if (!(fp = fopen(genbuf, "w"))) return; @@ -61,10 +61,10 @@ post_violatelaw(char *crime, char *police, char *reason, char *result) crime, ctime(&now), police, crime, reason, result); fclose(fp); sprintf(fhdr.title, "[報告] %-20s 違法判決報告", crime); - strcpy(fhdr.owner, "[Ptt法院]"); + strlcpy(fhdr.owner, "[Ptt法院]", sizeof(fhdr.owner)); append_record("boards/S/Security/.DIR", &fhdr, sizeof(fhdr)); - strcpy(genbuf, "boards/V/ViolateLaw"); + strlcpy(genbuf, "boards/V/ViolateLaw", sizeof(genbuf)); stampfile(genbuf, &fhdr); if (!(fp = fopen(genbuf, "w"))) return; @@ -76,7 +76,7 @@ post_violatelaw(char *crime, char *police, char *reason, char *result) crime, ctime(&now), police, crime, reason, result); fclose(fp); sprintf(fhdr.title, "[報告] %-20s 違法判決報告", crime); - strcpy(fhdr.owner, "[Ptt法院]"); + strlcpy(fhdr.owner, "[Ptt法院]", sizeof(fhdr.owner)); append_record("boards/V/ViolateLaw/.DIR", &fhdr, sizeof(fhdr)); @@ -100,7 +100,7 @@ give_money_post(char *userid, int money) time_t now = time(0); char genbuf[200]; - strcpy(genbuf, "boards/S/Security"); + strlcpy(genbuf, "boards/S/Security", sizeof(genbuf)); stampfile(genbuf, &fhdr); if (!(fp = fopen(genbuf, "w"))) return; @@ -115,6 +115,6 @@ give_money_post(char *userid, int money) fclose(fp); sprintf(fhdr.title, "[公安報告] 站長%s使用紅包機報告", cuser.userid); - strcpy(fhdr.owner, "[系統安全局]"); + strlcpy(fhdr.owner, "[系統安全局]", sizeof(fhdr.owner)); append_record("boards/S/Security/.DIR", &fhdr, sizeof(fhdr)); } diff --git a/pttbbs/mbbsd/talk.c b/pttbbs/mbbsd/talk.c index 5f62d642..c0fdbb12 100644 --- a/pttbbs/mbbsd/talk.c +++ b/pttbbs/mbbsd/talk.c @@ -1,4 +1,4 @@ -/* $Id: talk.c,v 1.78 2002/07/05 17:10:28 in2 Exp $ */ +/* $Id: talk.c,v 1.79 2002/07/21 08:18:41 in2 Exp $ */ #include "bbs.h" #define QCAST int (*)(const void *, const void *) @@ -32,7 +32,7 @@ typedef struct pickup_t { /* 記錄 friend 的 user number */ // #define PICKUP_WAYS 7 //關掉女士優先 -#define PICKUP_WAYS 6 +//#define PICKUP_WAYS 6 static char *fcolor[11] = { "", "\033[36m", "\033[32m", "\033[1;32m", @@ -562,7 +562,7 @@ my_write(pid_t pid, char *prompt, char *id, int flag, userinfo_t * puin) struct tm *ptime; userinfo_t *uin; uin = (puin != NULL) ? puin : (userinfo_t *) search_ulist_pid(pid); - strcpy(destid, id); + strlcpy(destid, id, sizeof(destid)); if (!uin && !(flag == 0 && water_which->count > 0)) { outmsg("\033[1;33;41m糟糕! 對方已落跑了(不在站上)! \033[37m~>_<~\033[m"); @@ -595,11 +595,11 @@ my_write(pid_t pid, char *prompt, char *id, int flag, userinfo_t * puin) i = (water_which->top - watermode + MAX_REVIEW) % MAX_REVIEW; uin = (userinfo_t *) search_ulist_pid(water_which->msg[i].pid); - strcpy(destid, water_which->msg[i].userid); + strlcpy(destid, water_which->msg[i].userid, sizeof(destid)); } } else { /* pre-edit 的水球 */ - strcpy(msg, prompt); + strlcpy(msg, prompt, sizeof(msg)); len = strlen(msg); } @@ -660,8 +660,10 @@ my_write(pid_t pid, char *prompt, char *id, int flag, userinfo_t * puin) uin->pager = 2; uin->msgs[uin->msgcount].pid = currpid; - strcpy(uin->msgs[uin->msgcount].userid, cuser.userid); - strcpy(uin->msgs[uin->msgcount++].last_call_in, msg); + strlcpy(uin->msgs[uin->msgcount].userid, cuser.userid, + sizeof(uin->msgs[uin->msgcount].userid)); + strlcpy(uin->msgs[uin->msgcount++].last_call_in, msg, + sizeof(uin->msgs[uin->msgcount++].last_call_in)); uin->pager = pager0; } else if (flag != 2) outmsg("\033[1;33;41m糟糕! 對方不行了! (收到太多水球) \033[37m@_@\033[m"); @@ -793,8 +795,8 @@ t_display(void) stampfile(buf, &mymail); mymail.filemode = FILE_READ | FILE_HOLD; - strcpy(mymail.owner, "[備.忘.錄]"); - strcpy(mymail.title, "熱線記錄"); + strlcpy(mymail.owner, "[備.忘.錄]", sizeof(mymail.owner)); + strlcpy(mymail.title, "熱線記錄", sizeof(mymail.title)); sethomedir(title, cuser.userid); Rename(genbuf, buf); append_record(title, &mymail, sizeof(mymail)); @@ -963,7 +965,7 @@ do_talk(int fd) ptime = localtime(&now); sethomepath(fpath, cuser.userid); - strcpy(fpath, tempnam(fpath, "talk_")); + strlcpy(fpath, tempnam(fpath, "talk_"), sizeof(fpath)); flog = fopen(fpath, "w"); setuserfile(genbuf, fn_talklog); @@ -1074,7 +1076,7 @@ do_talk(int fd) sethomepath(genbuf, cuser.userid); stampfile(genbuf, &mymail); mymail.filemode = FILE_READ | FILE_HOLD; - strcpy(mymail.owner, "[備.忘.錄]"); + strlcpy(mymail.owner, "[備.忘.錄]", sizeof(mymail.owner)); sprintf(mymail.title, "對話記錄 \033[1;36m(%s)\033[m", getuserid(currutmp->destuid)); sethomedir(title, cuser.userid); @@ -1101,7 +1103,7 @@ my_talk(userinfo_t * uin, int fri_stat) unsigned char mode0 = currutmp->mode; ch = uin->mode; - strcpy(currauthor, uin->userid); + strlcpy(currauthor, uin->userid, sizeof(currauthor)); if (ch == EDITING || ch == TALK || ch == CHATING || ch == PAGE || ch == MAILALL || ch == MONITOR || ch == M_FIVE || ch == CHC || @@ -1164,8 +1166,8 @@ my_talk(userinfo_t * uin, int fri_stat) uin->turn = 1; currutmp->turn = 0; - strcpy(uin->mateid, currutmp->userid); - strcpy(currutmp->mateid, uin->userid); + strlcpy(uin->mateid, currutmp->userid, sizeof(uin->mateid)); + strlcpy(currutmp->mateid, uin->userid, sizeof(currutmp->mateid)); sock = socket(AF_INET, SOCK_STREAM, 0); if (sock < 0) { @@ -1412,7 +1414,7 @@ friend_descript(char *uident) } fclose(fp); if (desc && flag) - strcpy(desc_buf, desc); + strlcpy(desc_buf, desc, sizeof(desc_buf)); else return space_buf; @@ -1668,7 +1670,7 @@ draw_pickup(int drawall, pickup_t * pickup, int pickup_way, #ifdef SHOW_IDLE_TIME idletime = (now - uentp->lastact); if (idletime > 86400) - strcpy(idlestr, " -----"); + strlcpy(idlestr, " -----", sizeof(idlestr)); else if (idletime >= 3600) sprintf(idlestr, "%3dh%02d", idletime / 3600, (idletime / 60) % 60); @@ -1676,7 +1678,7 @@ draw_pickup(int drawall, pickup_t * pickup, int pickup_way, sprintf(idlestr, "%3d'%02d", idletime / 60, idletime % 60); else - strcpy(idlestr, " "); + strlcpy(idlestr, " ", sizeof(idlestr)); #endif if ((uentp->userlevel & PERM_VIOLATELAW)) @@ -1859,7 +1861,7 @@ userlist(void) sprintf(buf, "代號 [%s]:", currutmp->userid); if (!getdata(1, 0, buf, currutmp->userid, sizeof(buf), DOECHO)) - strcpy(currutmp->userid, cuser.userid); + strlcpy(currutmp->userid, cuser.userid, sizeof(currutmp->userid)); redrawall = redraw = 1; } break; @@ -2085,7 +2087,7 @@ userlist(void) if (HAS_PERM(PERM_ACCOUNTS)) { int id; userec_t muser; - strcpy(currauthor, uentp->userid); + strlcpy(currauthor, uentp->userid, sizeof(currauthor)); stand_title("使用者設定"); move(1, 0); if ((id = getuser(uentp->userid)) > 0) { @@ -2209,7 +2211,7 @@ userlist(void) break; case 'q': - strcpy(currauthor, uentp->userid); + strlcpy(currauthor, uentp->userid, sizeof(currauthor)); my_query(uentp->userid); setutmpmode(LUSERS); redrawall = redraw = 1; @@ -2447,8 +2449,9 @@ talkreply(void) getuser(uip->userid); currutmp->msgs[0].pid = uip->pid; - strcpy(currutmp->msgs[0].userid, uip->userid); - strcpy(currutmp->msgs[0].last_call_in, "呼叫、呼叫,聽到請回答 (Ctrl-R)"); + strlcpy(currutmp->msgs[0].userid, uip->userid, sizeof(currutmp->msgs[0].userid)); + strlcpy(currutmp->msgs[0].last_call_in, "呼叫、呼叫,聽到請回答 (Ctrl-R)", + sizeof(currutmp->msgs[0].last_call_in)); prints("對方來自 [%s],共上站 %d 次,文章 %d 篇\n", uip->from, xuser.numlogins, xuser.numposts); showplans(uip->userid); @@ -2464,7 +2467,7 @@ talkreply(void) return; } currutmp->msgcount = 0; - strcpy(save_page_requestor, page_requestor); + strlcpy(save_page_requestor, page_requestor, sizeof(save_page_requestor)); memset(page_requestor, 0, sizeof(page_requestor)); if (!(h = gethostbyname("localhost"))) { perror("gethostbyname"); @@ -2484,7 +2487,7 @@ talkreply(void) write(a, buf, 1); if (buf[0] == 'f' || buf[0] == 'F') { if (!getdata(b_lines, 0, "不能的原因:", genbuf, 60, DOECHO)) - strcpy(genbuf, "不告訴你咧 !! ^o^"); + strlcpy(genbuf, "不告訴你咧 !! ^o^", sizeof(genbuf)); write(a, genbuf, 60); } uip->destuip = currutmp - &SHM->uinfo[0]; diff --git a/pttbbs/mbbsd/topsong.c b/pttbbs/mbbsd/topsong.c index 9d5fd475..277ef85f 100644 --- a/pttbbs/mbbsd/topsong.c +++ b/pttbbs/mbbsd/topsong.c @@ -1,4 +1,4 @@ -/* $Id: topsong.c,v 1.3 2002/07/05 17:10:28 in2 Exp $ */ +/* $Id: topsong.c,v 1.4 2002/07/21 08:18:42 in2 Exp $ */ #include "bbs.h" #define MAX_SONGS 300 @@ -60,8 +60,8 @@ sortsong() for (n = 0; n < MAX_SONGS && songs[n].name[0]; n++) if (!strcmp(songs[n].cname, cbuf)) break; - strcpy(songs[n].name, buf); - strcpy(songs[n].cname, cbuf); + strlcpy(songs[n].name, buf, sizeof(songs[n].name)); + strlcpy(songs[n].cname, cbuf, sizeof(songs[n].cname)); songs[n].count++; totalcount++; } diff --git a/pttbbs/mbbsd/user.c b/pttbbs/mbbsd/user.c index ed45b306..97c9690d 100644 --- a/pttbbs/mbbsd/user.c +++ b/pttbbs/mbbsd/user.c @@ -1,4 +1,4 @@ -/* $Id: user.c,v 1.29 2002/07/07 14:36:21 in2 Exp $ */ +/* $Id: user.c,v 1.30 2002/07/21 08:18:42 in2 Exp $ */ #include "bbs.h" static char *sex[8] = { @@ -75,7 +75,7 @@ user_display(userec_t * u, int real) u->numlogins, u->numposts); if (real) { - strcpy(genbuf, "bTCPRp#@XWBA#VSM0123456789ABCDEF"); + strlcpy(genbuf, "bTCPRp#@XWBA#VSM0123456789ABCDEF", sizeof(genbuf)); for (diff = 0; diff < 32; diff++) if (!(u->userlevel & (1 << diff))) genbuf[diff] = '-'; @@ -135,7 +135,7 @@ mail_violatelaw(char *crime, char *police, char *reason, char *result) ctime(&now), police, crime, reason, result); fclose(fp); sprintf(fhdr.title, "[報告] 違法判決報告"); - strcpy(fhdr.owner, "[Ptt法院]"); + strlcpy(fhdr.owner, "[Ptt法院]", sizeof(fhdr.owner)); sprintf(genbuf, "home/%c/%s/.DIR", crime[0], crime); append_record(genbuf, &fhdr, sizeof(fhdr)); } @@ -253,7 +253,7 @@ uinfo_query(userec_t * u, int real, int unum) getdata_str(i++, 0, "電子信箱[變動要重新認證]:", buf, 50, DOECHO, x.email); if (strcmp(buf, x.email) && strchr(buf, '@')) { - strcpy(x.email, buf); + strlcpy(x.email, buf, sizeof(x.email)); mail_changed = 1 - real; } sprintf(genbuf, "%i", (u->sex + 1) % 8); @@ -445,14 +445,14 @@ uinfo_query(userec_t * u, int real, int unum) outs("錯誤! 已經有同樣 ID 的使用者"); fail++; } else - strcpy(x.userid, genbuf); + strlcpy(x.userid, genbuf, sizeof(x.userid)); } break; case '6': if (x.mychicken.name[0]) x.mychicken.name[0] = 0; else - strcpy(x.mychicken.name, "[死]"); + strlcpy(x.mychicken.name, "[死]", sizeof(x.mychicken.name)); break; default: return; @@ -501,7 +501,7 @@ uinfo_query(userec_t * u, int real, int unum) setumoney(unum, x.money); passwd_update(unum, &x); if (money_change) { - strcpy(genbuf, "boards/S/Security"); + strlcpy(genbuf, "boards/S/Security", sizeof(genbuf)); stampfile(genbuf, &fhdr); if (!(fp = fopen(genbuf, "w"))) return; @@ -523,7 +523,7 @@ uinfo_query(userec_t * u, int real, int unum) fclose(fp); sprintf(fhdr.title, "[公安報告] 站長%s修改%s錢報告", cuser.userid, x.userid); - strcpy(fhdr.owner, "[系統安全局]"); + strlcpy(fhdr.owner, "[系統安全局]", sizeof(fhdr.owner)); append_record("boards/S/Security/.DIR", &fhdr, sizeof(fhdr)); } } @@ -535,8 +535,8 @@ u_info() move(2, 0); user_display(&cuser, 0); uinfo_query(&cuser, 0, usernum); - strcpy(currutmp->realname, cuser.realname); - strcpy(currutmp->username, cuser.username); + strlcpy(currutmp->realname, cuser.realname, sizeof(currutmp->realname)); + strlcpy(currutmp->username, cuser.username, sizeof(currutmp->username)); return 0; } @@ -728,7 +728,7 @@ getfield(int line, char *info, char *desc, char *buf, int len) outs(genbuf); sprintf(prompt, "%s:", desc); if (getdata_str(line + 1, 2, prompt, genbuf, len, DOECHO, buf)) - strcpy(buf, genbuf); + strlcpy(buf, genbuf, sizeof(buf)); move(line, 2); prints("%s:%s", desc, buf); clrtoeol(); @@ -753,7 +753,7 @@ ispersonalid(char *inid) char *lst = "ABCDEFGHJKLMNPQRSTUVWXYZIO", id[20]; int i, j, cksum; - strcpy(id, inid); + strlcpy(id, inid, sizeof(id)); i = cksum = 0; if (!isalpha(id[0]) && (strlen(id) != 10)) return 0; @@ -907,15 +907,15 @@ toregister(char *email, char *genbuf, char *phone, char *career, sethomefile(buf, cuser.userid, "justify"); } sprintf(buf, "您在 " BBSNAME " 的認證碼: %s", getregcode(genbuf)); - strcpy(tmp, cuser.userid); - strcpy(cuser.userid, "SYSOP"); + strlcpy(tmp, cuser.userid, sizeof(tmp)); + strlcpy(cuser.userid, "SYSOP", sizeof(cuser.userid)); #ifdef HAVEMOBILE if (strcmp(email, "m") == 0 || strcmp(email, "M") == 0) mobile_message(mobile, buf); else #endif bsmtp("etc/registermail", buf, email, 0); - strcpy(cuser.userid, tmp); + strlcpy(cuser.userid, tmp, sizeof(cuser.userid)); outs("\n\n\n我們即將寄出認證信 (您應該會在 10 分鐘內收到)\n" "收到後您可以跟據認證信標題的認證碼\n" "輸入到 (U)ser -> (R)egister 後就可以完成註冊"); @@ -952,10 +952,10 @@ u_register(void) } fclose(fn); } - strcpy(ident, cuser.ident); - strcpy(rname, cuser.realname); - strcpy(addr, cuser.address); - strcpy(email, cuser.email); + strlcpy(ident, cuser.ident, sizeof(ident)); + strlcpy(rname, cuser.realname, sizeof(rname)); + strlcpy(addr, cuser.address, sizeof(addr)); + strlcpy(email, cuser.email, sizeof(email)); sprintf(mobile, "0%09d", cuser.mobile); if (cuser.month == 0 && cuser.day && cuser.year == 0) birthday[0] = 0; @@ -1115,10 +1115,10 @@ u_register(void) if (ans[0] == 'y') break; } - strcpy(cuser.ident, ident); - strcpy(cuser.realname, rname); - strcpy(cuser.address, addr); - strcpy(cuser.email, email); + strlcpy(cuser.ident, ident, sizeof(cuser.ident)); + strlcpy(cuser.realname, rname, sizeof(cuser.realname)); + strlcpy(cuser.address, addr, sizeof(cuser.address)); + strlcpy(cuser.email, email, sizeof(cuser.email)); cuser.mobile = atoi(mobile); cuser.sex = (sex_is[0] - '1') % 8; cuser.month = mon; @@ -1184,7 +1184,7 @@ u_list_CB(userec_t * uentp) clrtobot(); } level = uentp->userlevel; - strcpy(permstr, "----"); + strlcpy(permstr, "----", sizeof(permstr)); if (level & PERM_SYSOP) permstr[0] = 'S'; else if (level & PERM_ACCOUNTS) diff --git a/pttbbs/mbbsd/vote.c b/pttbbs/mbbsd/vote.c index e54bc7a2..8f51ee3a 100644 --- a/pttbbs/mbbsd/vote.c +++ b/pttbbs/mbbsd/vote.c @@ -1,4 +1,4 @@ -/* $Id: vote.c,v 1.10 2002/07/05 17:10:28 in2 Exp $ */ +/* $Id: vote.c,v 1.11 2002/07/21 08:18:42 in2 Exp $ */ #include "bbs.h" static int total; @@ -135,14 +135,14 @@ vote_report(char *bname, char *fname, char *fpath) /* append record to .DIR */ memset(&header, 0, sizeof(fileheader_t)); - strcpy(header.owner, "[馬路探子]"); + strlcpy(header.owner, "[馬路探子]", sizeof(header.owner)); sprintf(header.title, "[%s] 看板 選情報導", bname); { register struct tm *ptime = localtime(&dtime); sprintf(header.date, "%2d/%02d", ptime->tm_mon + 1, ptime->tm_mday); } - strcpy(header.filename, ip); + strlcpy(header.filename, ip, sizeof(header.filename)); strcpy(ip, ".DIR"); if ((fd = open(fpath, O_WRONLY | O_CREAT, 0644)) >= 0) { @@ -188,13 +188,13 @@ b_result_one(boardheader_t * fh, int ind) sprintf(STR_new_limited, "%s%d", STR_bv_limited, ind); sprintf(STR_new_title, "%s%d", STR_bv_title, ind); } else { - strcpy(STR_new_ballots, STR_bv_ballots); - strcpy(STR_new_control, STR_bv_control); - strcpy(STR_new_desc, STR_bv_desc); - strcpy(STR_new_flags, STR_bv_flags); - strcpy(STR_new_comments, STR_bv_comments); - strcpy(STR_new_limited, STR_bv_limited); - strcpy(STR_new_title, STR_bv_title); + strlcpy(STR_new_ballots, STR_bv_ballots, sizeof(STR_new_ballots)); + strlcpy(STR_new_control, STR_bv_control, sizeof(STR_new_control)); + strlcpy(STR_new_desc, STR_bv_desc, sizeof(STR_new_desc)); + strlcpy(STR_new_flags, STR_bv_flags, sizeof(STR_new_flags)); + strlcpy(STR_new_comments, STR_bv_comments, sizeof(STR_new_comments)); + strlcpy(STR_new_limited, STR_bv_limited, sizeof(STR_new_limited)); + strlcpy(STR_new_title, STR_bv_title, sizeof(STR_new_title)); } bname = fh->brdname; @@ -289,7 +289,7 @@ b_result(boardheader_t * fh) if (i) sprintf(STR_new_control, "%s%d", STR_bv_control, i); else - strcpy(STR_new_control, STR_bv_control); + strlcpy(STR_new_control, STR_bv_control, sizeof(STR_new_control)); setbfile(buf, fh->brdname, STR_new_control); cfp = fopen(buf, "r"); @@ -375,13 +375,13 @@ vote_view(char *bname, int index) sprintf(STR_new_limited, "%s%d", STR_bv_limited, index); sprintf(STR_new_title, "%s%d", STR_bv_title, index); } else { - strcpy(STR_new_ballots, STR_bv_ballots); - strcpy(STR_new_control, STR_bv_control); - strcpy(STR_new_desc, STR_bv_desc); - strcpy(STR_new_flags, STR_bv_flags); - strcpy(STR_new_comments, STR_bv_comments); - strcpy(STR_new_limited, STR_bv_limited); - strcpy(STR_new_title, STR_bv_title); + strlcpy(STR_new_ballots, STR_bv_ballots, sizeof(STR_new_ballots)); + strlcpy(STR_new_control, STR_bv_control, sizeof(STR_new_control)); + strlcpy(STR_new_desc, STR_bv_desc, sizeof(STR_new_desc)); + strlcpy(STR_new_flags, STR_bv_flags, sizeof(STR_new_flags)); + strlcpy(STR_new_comments, STR_bv_comments, sizeof(STR_new_comments)); + strlcpy(STR_new_limited, STR_bv_limited, sizeof(STR_new_limited)); + strlcpy(STR_new_title, STR_bv_title, sizeof(STR_new_title)); } setbfile(buf, bname, STR_new_ballots); @@ -475,8 +475,8 @@ vote_view_all(char *bname) char buf[STRLEN], genbuf[STRLEN]; char inbuf[80]; - strcpy(STR_new_control, STR_bv_control); - strcpy(STR_new_title, STR_bv_title); + strlcpy(STR_new_control, STR_bv_control, sizeof(STR_new_control)); + strlcpy(STR_new_title, STR_bv_title, sizeof(STR_new_title)); setbfile(buf, bname, STR_new_control); move(0, 0); if ((fp = fopen(buf, "r"))) { @@ -488,7 +488,7 @@ vote_view_all(char *bname) if ((xfp = fopen(buf, "r"))) fgets(inbuf, sizeof(inbuf), xfp); else - strcpy(inbuf, "無標題"); + strlcpy(inbuf, "無標題", sizeof(inbuf)); prints("%s\n", inbuf); fclose(xfp); } @@ -505,7 +505,7 @@ vote_view_all(char *bname) if ((xfp = fopen(buf, "r"))) fgets(inbuf, sizeof(inbuf), xfp); else - strcpy(inbuf, "無標題"); + strlcpy(inbuf, "無標題", sizeof(inbuf)); prints("%s\n", inbuf); fclose(xfp); } @@ -523,7 +523,7 @@ vote_view_all(char *bname) if (genbuf[0] != '0') sprintf(STR_new_control, "%s%d", STR_bv_control, atoi(genbuf)); else - strcpy(STR_new_control, STR_bv_control); + strlcpy(STR_new_control, STR_bv_control, sizeof(STR_new_control)); setbfile(buf, bname, STR_new_control); @@ -604,7 +604,7 @@ vote_maintain(char *bname) } else if (genbuf[0] != 'm' || fhp->bvote >= 20) return FULLUPDATE; } - strcpy(STR_new_control, STR_bv_control); + strlcpy(STR_new_control, STR_bv_control, sizeof(STR_new_control)); setbfile(buf, bname, STR_new_control); x = 0; while (x < 20 && (fp = fopen(buf, "r")) != NULL) { @@ -626,13 +626,13 @@ vote_maintain(char *bname) sprintf(STR_new_limited, "%s%d", STR_bv_limited, x); sprintf(STR_new_title, "%s%d", STR_bv_title, x); } else { - strcpy(STR_new_ballots, STR_bv_ballots); - strcpy(STR_new_control, STR_bv_control); - strcpy(STR_new_desc, STR_bv_desc); - strcpy(STR_new_flags, STR_bv_flags); - strcpy(STR_new_comments, STR_bv_comments); - strcpy(STR_new_limited, STR_bv_limited); - strcpy(STR_new_title, STR_bv_title); + strlcpy(STR_new_ballots, STR_bv_ballots, sizeof(STR_new_ballots)); + strlcpy(STR_new_control, STR_bv_control, sizeof(STR_new_control)); + strlcpy(STR_new_desc, STR_bv_desc, sizeof(STR_new_desc)); + strlcpy(STR_new_flags, STR_bv_flags, sizeof(STR_new_flags)); + strlcpy(STR_new_comments, STR_bv_comments, sizeof(STR_new_comments)); + strlcpy(STR_new_limited, STR_bv_limited, sizeof(STR_new_limited)); + strlcpy(STR_new_title, STR_bv_title, sizeof(STR_new_title)); } clear(); move(0, 0); @@ -640,7 +640,7 @@ vote_maintain(char *bname) setbfile(buf, bname, STR_new_title); getdata(4, 0, "請輸入投票名稱:", inbuf, 50, LCECHO); if (inbuf[0] == '\0') - strcpy(inbuf, "不知名的"); + strlcpy(inbuf, "不知名的", sizeof(inbuf)); fp = fopen(buf, "w"); fprintf(fp, "%s", inbuf); fclose(fp); @@ -704,7 +704,7 @@ vote_maintain(char *bname) getdata(t_lines - 3, 0, buf, inbuf, 3, DOECHO); if (atoi(inbuf) <= 0 || atoi(inbuf) > num) - strcpy(inbuf, "1"); + strlcpy(inbuf, "1", sizeof(inbuf)); rewind(fp); fprintf(fp, "%2d\n", MAX(1, atoi(inbuf))); @@ -736,7 +736,7 @@ vote_flag(char *bname, int index, char val) if (index) sprintf(STR_new_flags, "%s%d", STR_bv_flags, index); else - strcpy(STR_new_flags, STR_bv_flags); + strlcpy(STR_new_flags, STR_bv_flags, sizeof(STR_new_flags)); num = usernum - 1; setbfile(buf, bname, STR_new_flags); @@ -791,12 +791,12 @@ user_vote_one(char *bname, int ind) sprintf(STR_new_comments, "%s%d", STR_bv_comments, ind); sprintf(STR_new_limited, "%s%d", STR_bv_limited, ind); } else { - strcpy(STR_new_ballots, STR_bv_ballots); - strcpy(STR_new_control, STR_bv_control); - strcpy(STR_new_desc, STR_bv_desc); - strcpy(STR_new_flags, STR_bv_flags); - strcpy(STR_new_comments, STR_bv_comments); - strcpy(STR_new_limited, STR_bv_limited); + strlcpy(STR_new_ballots, STR_bv_ballots, sizeof(STR_new_ballots)); + strlcpy(STR_new_control, STR_bv_control, sizeof(STR_new_control)); + strlcpy(STR_new_desc, STR_bv_desc, sizeof(STR_new_desc)); + strlcpy(STR_new_flags, STR_bv_flags, sizeof(STR_new_flags)); + strlcpy(STR_new_comments, STR_bv_comments, sizeof(STR_new_comments)); + strlcpy(STR_new_limited, STR_bv_limited, sizeof(STR_new_limited)); } setbfile(buf, bname, STR_new_control); @@ -892,7 +892,7 @@ user_vote_one(char *bname, int ind) char buf[3], mycomments[3][74], b_comments[80]; for (i = 0; i < 3; i++) - strcpy(mycomments[i], "\n"); + strlcpy(mycomments[i], "\n", sizeof(mycomments[i])); flock(fd, LOCK_EX); for (count = 0; count < 31; count++) { @@ -972,8 +972,8 @@ user_vote(char *bname) pressanykey(); return FULLUPDATE; } - strcpy(STR_new_control, STR_bv_control); - strcpy(STR_new_title, STR_bv_title); + strlcpy(STR_new_control, STR_bv_control, sizeof(STR_new_control)); + strlcpy(STR_new_title, STR_bv_title, sizeof(STR_new_title)); setbfile(buf, bname, STR_new_control); move(0, 0); if ((fp = fopen(buf, "r"))) { @@ -985,7 +985,7 @@ user_vote(char *bname) if ((xfp = fopen(buf, "r"))) fgets(inbuf, sizeof(inbuf), xfp); else - strcpy(inbuf, "無標題"); + strlcpy(inbuf, "無標題", sizeof(inbuf)); prints("%s\n", inbuf); fclose(xfp); } @@ -1002,7 +1002,7 @@ user_vote(char *bname) if ((xfp = fopen(buf, "r"))) fgets(inbuf, sizeof(inbuf), xfp); else - strcpy(inbuf, "無標題"); + strlcpy(inbuf, "無標題", sizeof(inbuf)); prints("%s\n", inbuf); fclose(xfp); } @@ -1021,7 +1021,7 @@ user_vote(char *bname) if (genbuf[0] != '0') sprintf(STR_new_control, "%s%d", STR_bv_control, atoi(genbuf)); else - strcpy(STR_new_control, STR_bv_control); + strlcpy(STR_new_control, STR_bv_control, sizeof(STR_new_control)); setbfile(buf, bname, STR_new_control); diff --git a/pttbbs/mbbsd/voteboard.c b/pttbbs/mbbsd/voteboard.c index d3df2540..1aa05ee9 100644 --- a/pttbbs/mbbsd/voteboard.c +++ b/pttbbs/mbbsd/voteboard.c @@ -1,4 +1,4 @@ -/* $Id: voteboard.c,v 1.10 2002/07/20 15:33:46 in2 Exp $ */ +/* $Id: voteboard.c,v 1.11 2002/07/21 08:18:42 in2 Exp $ */ #include "bbs.h" #define VOTEBOARD "NewBoard" @@ -61,7 +61,7 @@ do_voteboardreply(fileheader_t * fhdr) fclose(fp); return; } - strcpy(reason, genbuf + 19); + strlcpy(reason, genbuf + 19, sizeof(reason)); } } fclose(fp); @@ -420,8 +420,8 @@ do_voteboard() "時間: ", ctime(&now)); fprintf(fp, "%s\n", genbuf); fclose(fp); - strcpy(votefile.owner, cuser.userid); - strcpy(votefile.title, title); + strlcpy(votefile.owner, cuser.userid, sizeof(votefile.owner)); + strlcpy(votefile.title, title, sizeof(votefile.title)); setbdir(genbuf, currboard); if (append_record(genbuf, &votefile, sizeof(votefile)) != -1) setbtotal(currbid); -- cgit v1.2.3 From 227c84fd2245ae15f0d5cad24b63470a526f8d12 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sun, 21 Jul 2002 09:26:02 +0000 Subject: indent -i4 fix indent's word error git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@429 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/admin.c | 40 +- pttbbs/mbbsd/announce.c | 72 +- pttbbs/mbbsd/args.c | 10 +- pttbbs/mbbsd/bbcall.c | 12 +- pttbbs/mbbsd/bbs.c | 2055 ++++++++++++++++++++++++---------------------- pttbbs/mbbsd/board.c | 50 +- pttbbs/mbbsd/cache.c | 123 +-- pttbbs/mbbsd/cal.c | 34 +- pttbbs/mbbsd/calendar.c | 22 +- pttbbs/mbbsd/card.c | 50 +- pttbbs/mbbsd/chat.c | 32 +- pttbbs/mbbsd/chc_draw.c | 10 +- pttbbs/mbbsd/chc_net.c | 6 +- pttbbs/mbbsd/chc_play.c | 12 +- pttbbs/mbbsd/chc_rule.c | 18 +- pttbbs/mbbsd/chicken.c | 56 +- pttbbs/mbbsd/dark.c | 29 +- pttbbs/mbbsd/descrypt.c | 12 +- pttbbs/mbbsd/dice.c | 24 +- pttbbs/mbbsd/edit.c | 76 +- pttbbs/mbbsd/friend.c | 26 +- pttbbs/mbbsd/gamble.c | 24 +- pttbbs/mbbsd/gomo.c | 20 +- pttbbs/mbbsd/gomo1.c | 12 +- pttbbs/mbbsd/guess.c | 22 +- pttbbs/mbbsd/indict.c | 10 +- pttbbs/mbbsd/io.c | 28 +- pttbbs/mbbsd/kaede.c | 6 +- pttbbs/mbbsd/lovepaper.c | 4 +- pttbbs/mbbsd/mail.c | 95 ++- pttbbs/mbbsd/mbbsd.c | 6 +- pttbbs/mbbsd/menu.c | 18 +- pttbbs/mbbsd/more.c | 5 +- pttbbs/mbbsd/name.c | 364 ++++---- pttbbs/mbbsd/osdep.c | 10 +- pttbbs/mbbsd/othello.c | 36 +- pttbbs/mbbsd/page.c | 6 +- pttbbs/mbbsd/passwd.c | 16 +- pttbbs/mbbsd/read.c | 23 +- pttbbs/mbbsd/record.c | 34 +- pttbbs/mbbsd/register.c | 24 +- pttbbs/mbbsd/screen.c | 58 +- pttbbs/mbbsd/stuff.c | 88 +- pttbbs/mbbsd/syspost.c | 10 +- pttbbs/mbbsd/talk.c | 83 +- pttbbs/mbbsd/term.c | 20 +- pttbbs/mbbsd/toolkit.c | 4 +- pttbbs/mbbsd/topsong.c | 10 +- pttbbs/mbbsd/user.c | 64 +- pttbbs/mbbsd/var.c | 8 +- pttbbs/mbbsd/vice.c | 14 +- pttbbs/mbbsd/vote.c | 42 +- pttbbs/mbbsd/voteboard.c | 6 +- pttbbs/mbbsd/xyz.c | 60 +- 54 files changed, 2045 insertions(+), 1954 deletions(-) diff --git a/pttbbs/mbbsd/admin.c b/pttbbs/mbbsd/admin.c index f6d13042..8fe3621c 100644 --- a/pttbbs/mbbsd/admin.c +++ b/pttbbs/mbbsd/admin.c @@ -1,8 +1,8 @@ -/* $Id: admin.c,v 1.26 2002/07/21 08:18:41 in2 Exp $ */ +/* $Id: admin.c,v 1.27 2002/07/21 09:26:02 in2 Exp $ */ #include "bbs.h" /* 使用者管理 */ -int +int m_user() { userec_t muser; @@ -26,7 +26,7 @@ m_user() return 0; } -static int +static int search_key_user(char *passwdfile, int mode) { userec_t user; @@ -111,7 +111,7 @@ search_key_user(char *passwdfile, int mode) } /* 以任意 key 尋找使用者 */ -int +int search_user_bypwd() { search_key_user(FN_PASSWD, 1); @@ -119,7 +119,7 @@ search_user_bypwd() } /* 尋找備份的使用者資料 */ -int +int search_user_bybakpwd() { char *choice[] = { @@ -149,14 +149,14 @@ search_user_bybakpwd() return 0; } -static void +static void bperm_msg(boardheader_t * board) { prints("\n設定 [%s] 看板之(%s)權限:", board->brdname, board->brdattr & BRD_POSTMASK ? "發表" : "閱\讀"); } -unsigned int +unsigned int setperms(unsigned int pbits, char *pstring[]) { register int i; @@ -189,7 +189,7 @@ setperms(unsigned int pbits, char *pstring[]) } /* 自動設立精華區 */ -void +void setup_man(boardheader_t * board) { char genbuf[200]; @@ -199,7 +199,7 @@ setup_man(boardheader_t * board) } -int +int m_mod_board(char *bname) { boardheader_t bh, newbh; @@ -381,7 +381,7 @@ m_mod_board(char *bname) } /* 設定看板 */ -int +int m_board() { char bname[32]; @@ -398,7 +398,7 @@ m_board() } /* 設定系統檔案 */ -int +int x_file() { int aborted; @@ -522,7 +522,7 @@ x_file() return FULLUPDATE; } -int +int m_newbrd(int recover) { boardheader_t newboard; @@ -633,7 +633,7 @@ m_newbrd(int recover) return 0; } -static int +static int auto_scan(char fdata[][STRLEN], char ans[]) { int good = 0; @@ -718,7 +718,7 @@ auto_scan(char fdata[][STRLEN], char ans[]) } /* 處理 Register Form */ -int +int scan_register_form(char *regfile, int automode, int neednum) { char genbuf[200]; @@ -949,8 +949,8 @@ scan_register_form(char *regfile, int automode, int neednum) /** DickG: 將審了幾份的相關資料 post 到 Security 板上 ***********/ /* - * DickG: 因應新的站長上站需審核方案,是故沒有必要留下 record - * ime(buf, 200, "%Y/%m/%d/%H:%M", pt); + * DickG: 因應新的站長上站需審核方案,是故沒有必要留下 record ime(buf, + * 200, "%Y/%m/%d/%H:%M", pt); * * strcpy(xboard, "Security"); setbpath(xfpath, xboard); stampfile(xfpath, * &xfile); strcpy(xfile.owner, "系統"); strcpy(xfile.title, "[報告] @@ -966,7 +966,7 @@ scan_register_form(char *regfile, int automode, int neednum) return (0); } -int +int m_register() { FILE *fn; @@ -1005,7 +1005,7 @@ m_register() return 0; } -int +int cat_register() { if (system("cat register.new.tmp >> register.new") == 0 && @@ -1017,7 +1017,7 @@ cat_register() return 0; } -static void +static void give_id_money(char *user_id, int money, FILE * log_fp, char *mail_title, time_t t) { char tt[TTLEN + 1] = {0}; @@ -1034,7 +1034,7 @@ give_id_money(char *user_id, int money, FILE * log_fp, char *mail_title, time_t } } -int +int give_money() { FILE *fp, *fp2; diff --git a/pttbbs/mbbsd/announce.c b/pttbbs/mbbsd/announce.c index 889c986d..5df8a9fa 100644 --- a/pttbbs/mbbsd/announce.c +++ b/pttbbs/mbbsd/announce.c @@ -1,7 +1,7 @@ -/* $Id: announce.c,v 1.14 2002/07/21 08:18:41 in2 Exp $ */ +/* $Id: announce.c,v 1.15 2002/07/21 09:26:02 in2 Exp $ */ #include "bbs.h" -static void +static void g_showmenu(gmenu_t * pm) { static char *mytype = "編 選 絲路之旅"; @@ -119,7 +119,7 @@ my_open(char *path) static jmp_buf jbuf; -static void +static void isig(int sig) { longjmp(jbuf, 1); @@ -127,7 +127,7 @@ isig(int sig) #define PROXY_HOME "proxy/" -static void +static void go_proxy(char *fpath, item_t * node, int update) { char *ptr, *str, *server; @@ -209,7 +209,7 @@ go_proxy(char *fpath, item_t * node, int update) } } -static void +static void g_additem(gmenu_t * pm, item_t * myitem) { if (pm->num < MAX_ITEMS) { @@ -220,7 +220,7 @@ g_additem(gmenu_t * pm, item_t * myitem) } } -static void +static void go_menu(gmenu_t * pm, item_t * node, int update) { FILE *fp; @@ -264,7 +264,7 @@ go_menu(gmenu_t * pm, item_t * node, int update) } } -static int +static int g_searchtitle(gmenu_t * pm, int rev) { static char search_str[30] = ""; @@ -290,7 +290,7 @@ g_searchtitle(gmenu_t * pm, int rev) return pm->now; } -static void +static void g_showhelp() { clear(); @@ -314,7 +314,7 @@ g_showhelp() static char paste_fname[200]; -static void +static void load_paste() { struct stat st; @@ -343,7 +343,7 @@ static char copyfile[PATHLEN]; static char copytitle[TTLEN + 1]; static char copyowner[IDLEN + 2]; -void +void a_copyitem(char *fpath, char *title, char *owner, int mode) { strcpy(copyfile, fpath); @@ -360,7 +360,7 @@ a_copyitem(char *fpath, char *title, char *owner, int mode) #define FHSZ sizeof(fileheader_t) -static void +static void a_loadname(menu_t * pm) { char buf[PATHLEN]; @@ -372,7 +372,7 @@ a_loadname(menu_t * pm) bzero(&pm->header[len], FHSZ * (p_lines - len)); } -static void +static void a_timestamp(char *buf, time_t * time) { struct tm *pt = localtime(time); @@ -380,7 +380,7 @@ a_timestamp(char *buf, time_t * time) sprintf(buf, "%02d/%02d/%02d", pt->tm_mon + 1, pt->tm_mday, (pt->tm_year + 1900) % 100); } -static void +static void a_showmenu(menu_t * pm) { char *title, *editor; @@ -425,7 +425,7 @@ a_showmenu(menu_t * pm) "\033[31m(enter/→)\033[30m讀取資料 \033[m"); } -static int +static int a_searchtitle(menu_t * pm, int rev) { static char search_str[40] = ""; @@ -460,7 +460,7 @@ enum { NOBODY, MANAGER, SYSOP }; -static void +static void a_showhelp(int level) { clear(); @@ -491,7 +491,7 @@ a_showhelp(int level) pressanykey(); } -static int +static int AnnounceSelect() { static char xboard[20]; @@ -521,7 +521,7 @@ AnnounceSelect() return FULLUPDATE; } -void +void gem(char *maintitle, item_t * path, int update) { gmenu_t me; @@ -714,7 +714,7 @@ gem(char *maintitle, item_t * path, int update) free(me.item[ch]); } -static void +static void a_forward(char *path, fileheader_t * pitem, int mode) { fileheader_t fhdr; @@ -734,7 +734,7 @@ a_forward(char *path, fileheader_t * pitem, int mode) } } -static void +static void a_additem(menu_t * pm, fileheader_t * myheader) { char buf[PATHLEN]; @@ -759,7 +759,7 @@ a_additem(menu_t * pm, fileheader_t * myheader) #define ADDGOPHER 2 #define ADDLINK 3 -static void +static void a_newitem(menu_t * pm, int mode) { static char *mesg[4] = { @@ -874,7 +874,7 @@ a_newitem(menu_t * pm, int mode) a_additem(pm, &item); } -static void +static void a_pasteitem(menu_t * pm, int mode) { char newpath[PATHLEN]; @@ -947,7 +947,7 @@ a_pasteitem(menu_t * pm, int mode) } } -static void +static void a_appenditem(menu_t * pm, int isask) { char fname[PATHLEN]; @@ -1002,7 +1002,7 @@ a_appenditem(menu_t * pm, int isask) } } -static int +static int a_pastetagpost(menu_t * pm, int mode) { fileheader_t fhdr; @@ -1037,7 +1037,7 @@ a_pastetagpost(menu_t * pm, int mode) return ans; } -static void +static void a_moveitem(menu_t * pm) { fileheader_t *tmp; @@ -1079,7 +1079,7 @@ a_moveitem(menu_t * pm) free(tmp); } -static void +static void a_delrange(menu_t * pm) { char fname[256]; @@ -1089,7 +1089,7 @@ a_delrange(menu_t * pm) pm->num = get_num_records(fname, FHSZ); } -static void +static void a_delete(menu_t * pm) { char fpath[PATHLEN], buf[PATHLEN], cmd[PATHLEN]; @@ -1166,7 +1166,7 @@ a_delete(menu_t * pm) pm->num--; } -static void +static void a_newtitle(menu_t * pm) { char buf[PATHLEN]; @@ -1180,7 +1180,7 @@ a_newtitle(menu_t * pm) substitute_record(buf, &item, FHSZ, pm->now + 1); } } -static void +static void a_hideitem(menu_t * pm) { fileheader_t *item = &pm->header[pm->now - pm->page]; @@ -1195,7 +1195,7 @@ a_hideitem(menu_t * pm) setadir(buf, pm->path); substitute_record(buf, item, FHSZ, pm->now + 1); } -static void +static void a_editsign(menu_t * pm) { char buf[PATHLEN]; @@ -1212,7 +1212,7 @@ a_editsign(menu_t * pm) } } -static void +static void a_showname(menu_t * pm) { char buf[PATHLEN]; @@ -1257,7 +1257,7 @@ a_showname(menu_t * pm) #if 0 static char *a_title; -static void +static void atitle() { showtitle("精華文章", a_title); @@ -1267,7 +1267,7 @@ atitle() } #endif -static int +static int isvisible_man(menu_t * me) { fileheader_t *fhdr = &me->header[me->now - me->page]; @@ -1277,7 +1277,7 @@ isvisible_man(menu_t * me) return 0; return 1; } -int +int a_menu(char *maintitle, char *path, int lastlevel) { static char Fexit; @@ -1407,8 +1407,8 @@ a_menu(char *maintitle, char *path, int lastlevel) fhdr.filename, sizeof(me.header[me.now - me.page].filename)); strlcpy(me.header[me.now - me.page].owner, - cuser.userid, - sizeof(me.header[me.now - me.page].owner)); + cuser.userid, + sizeof(me.header[me.now - me.page].owner)); setadir(fpath, path); substitute_record(fpath, me.header + me.now - me.page, sizeof(fhdr), me.now + 1); @@ -1603,7 +1603,7 @@ a_menu(char *maintitle, char *path, int lastlevel) static char *mytitle = BBSNAME "佈告欄"; -int +int Announce() { setutmpmode(ANNOUNCE); diff --git a/pttbbs/mbbsd/args.c b/pttbbs/mbbsd/args.c index 57e6798b..d1291176 100644 --- a/pttbbs/mbbsd/args.c +++ b/pttbbs/mbbsd/args.c @@ -1,8 +1,8 @@ -/* $Id: args.c,v 1.4 2002/07/21 08:18:41 in2 Exp $ */ +/* $Id: args.c,v 1.5 2002/07/21 09:26:02 in2 Exp $ */ #include "bbs.h" #ifdef HAVE_SETPROCTITLE -void +void initsetproctitle(int argc, char **argv, char **envp) { } @@ -14,7 +14,7 @@ char **Argv = NULL; /* pointer to argument vector */ char *LastArgv = NULL;/* end of argv */ extern char **environ; -void +void initsetproctitle(int argc, char **argv, char **envp) { register int i; @@ -37,7 +37,7 @@ initsetproctitle(int argc, char **argv, char **envp) LastArgv = argv[argc - 1] + strlen(argv[argc - 1]); } -static void +static void do_setproctitle(const char *cmdline) { char buf[256], *p; @@ -56,7 +56,7 @@ do_setproctitle(const char *cmdline) Argv[1] = NULL; } -void +void setproctitle(const char *format,...) { char buf[256]; diff --git a/pttbbs/mbbsd/bbcall.c b/pttbbs/mbbsd/bbcall.c index dfc6320c..c3527e01 100644 --- a/pttbbs/mbbsd/bbcall.c +++ b/pttbbs/mbbsd/bbcall.c @@ -1,4 +1,4 @@ -/* $Id: bbcall.c,v 1.6 2002/07/21 08:18:41 in2 Exp $ */ +/* $Id: bbcall.c,v 1.7 2002/07/21 09:26:02 in2 Exp $ */ #include "bbs.h" #define SERVER_0941 "www.chips.com.tw" @@ -21,7 +21,7 @@ #define REFER_0947 "http://web1.hoyard.com.tw/freeway/freewayi.html" #define REFER_0945 "http://203.73.181.254/call.HTM" -static void +static void pager_msg_encode(char *field, char *buf) { char *cc = field; @@ -41,7 +41,7 @@ pager_msg_encode(char *field, char *buf) *cc = 0; } -static void +static void Gettime(int flag, int *Year, int *Month, int *Day, int *Hour, int *Minute) { @@ -69,7 +69,7 @@ Gettime(int flag, int *Year, int *Month, int *Day, int *Hour, #define hpressanykey(a) {move(22, 0); prints(a); pressanykey();} -static int +static int Connect(char *s, char *server) { FILE *fp = fopen(BBSHOME "/log/bbcall.log", "a"); @@ -262,3 +262,7 @@ int main_bbcall() { return 0; } + + + + diff --git a/pttbbs/mbbsd/bbs.c b/pttbbs/mbbsd/bbs.c index 46222bed..a706ff0c 100644 --- a/pttbbs/mbbsd/bbs.c +++ b/pttbbs/mbbsd/bbs.c @@ -1,7 +1,7 @@ -/* $Id: bbs.c,v 1.64 2002/07/21 08:18:41 in2 Exp $ */ +/* $Id: bbs.c,v 1.65 2002/07/21 09:26:02 in2 Exp $ */ #include "bbs.h" -static void +static void mail_by_link(char *owner, char *title, char *path) { char genbuf[200]; @@ -19,7 +19,7 @@ mail_by_link(char *owner, char *title, char *path) } -void +void anticrosspost() { char buf[200]; @@ -39,7 +39,7 @@ anticrosspost() } /* Heat CharlieL */ -int +int save_violatelaw() { char buf[128], ok[3]; @@ -98,7 +98,7 @@ save_violatelaw() static time_t board_note_time; static char *brd_title; -void +void set_board() { boardheader_t *bp; @@ -119,7 +119,7 @@ set_board() currmode |= MODE_POST; } -static void +static void readtitle() { showtitle(currBM, brd_title); @@ -128,7 +128,7 @@ readtitle() " \033[m"); } -static void +static void readdoent(int num, fileheader_t * ent) { int type, uid; @@ -184,25 +184,25 @@ readdoent(int num, fileheader_t * ent) title); } -int +int cmpfilename(fileheader_t * fhdr) { return (!strcmp(fhdr->filename, currfile)); } -int +int cmpfmode(fileheader_t * fhdr) { return (fhdr->filemode & currfmode); } -int +int cmpfowner(fileheader_t * fhdr) { return !strcasecmp(fhdr->owner, currowner); } -int +int whereami(int ent, fileheader_t * fhdr, char *direct) { boardheader_t *bh, *p[32], *root; @@ -229,7 +229,7 @@ whereami(int ent, fileheader_t * fhdr, char *direct) return FULLUPDATE; } -static int +static int substitute_check(fileheader_t * fhdr) { fileheader_t hdr; @@ -250,7 +250,7 @@ substitute_check(fileheader_t * fhdr) } return num; } -static int +static int do_select(int ent, fileheader_t * fhdr, char *direct) { char bname[20]; @@ -295,7 +295,7 @@ do_select(int ent, fileheader_t * fhdr, char *direct) /* ----------------------------------------------------- */ /* 改良 innbbsd 轉出信件、連線砍信之處理程序 */ /* ----------------------------------------------------- */ -void +void outgo_post(fileheader_t * fh, char *board) { FILE *foo; @@ -307,7 +307,7 @@ outgo_post(fileheader_t * fh, char *board) } } -static void +static void cancelpost(fileheader_t * fh, int by_BM) { FILE *fin, *fout; @@ -352,7 +352,7 @@ cancelpost(fileheader_t * fh, int by_BM) /* ----------------------------------------------------- */ /* 發表、回應、編輯、轉錄文章 */ /* ----------------------------------------------------- */ -void +void do_reply_title(int row, char *title) { char genbuf[200]; @@ -369,7 +369,7 @@ do_reply_title(int row, char *title) getdata(++row, 0, "標題:", save_title, TTLEN, DOECHO); } -static void +static void do_unanonymous_post(char *fpath) { fileheader_t mhdr; @@ -394,7 +394,7 @@ static time_t last_post_time = 0; static time_t water_counts = 0; #endif -static int +static int do_general() { fileheader_t postfile; @@ -586,7 +586,7 @@ do_general() return FULLUPDATE; } -int +int do_post() { boardheader_t *bp; @@ -599,7 +599,7 @@ do_post() return 0; } -static void +static void do_generalboardreply(fileheader_t * fhdr) { char genbuf[200]; @@ -622,7 +622,7 @@ do_generalboardreply(fileheader_t * fhdr) *quote_file = 0; } -int +int getindex(char *fpath, char *fname, int size) { int fd, now = 0; @@ -641,7 +641,7 @@ getindex(char *fpath, char *fname, int size) return 0; } -int +int invalid_brdname(char *brd) { register char ch; @@ -656,7 +656,7 @@ invalid_brdname(char *brd) return 0; } -static int +static int b_call_in(int ent, fileheader_t * fhdr, char *direct) { userinfo_t *u = search_ulist(searchuser(fhdr->owner)); @@ -669,7 +669,7 @@ b_call_in(int ent, fileheader_t * fhdr, char *direct) return DONOTHING; } -static void +static void do_reply(fileheader_t * fhdr) { boardheader_t *bp; @@ -680,7 +680,7 @@ do_reply(fileheader_t * fhdr) do_generalboardreply(fhdr); } -static int +static int reply_post(int ent, fileheader_t * fhdr, char *direct) { if (!(currmode & MODE_POST)) @@ -692,7 +692,7 @@ reply_post(int ent, fileheader_t * fhdr, char *direct) return FULLUPDATE; } -static int +static int edit_post(int ent, fileheader_t * fhdr, char *direct) { char fpath[80], fpath0[80]; @@ -751,7 +751,7 @@ edit_post(int ent, fileheader_t * fhdr, char *direct) #define UPDATE_USEREC (currmode |= MODE_DIRTY) -static int +static int cross_post(int ent, fileheader_t * fhdr, char *direct) { char xboard[20], fname[80], xfpath[80], xtitle[80], inputbuf[10]; @@ -825,1140 +825,1213 @@ cross_post(int ent, fileheader_t * fhdr, char *direct) xfile.filemode = FILE_LOCAL; } setbfile(fname, currboard, fhdr->filename); - //if (ent) { - xptr = fopen(xfpath, "w"); + xptr = fopen(xfpath, "w"); + + strlcpy(save_title, xfile.title, sizeof(save_title)); + strlcpy(xfpath, currboard, sizeof(xfpath)); + strlcpy(currboard, xboard, sizeof(currboard)); + write_header(xptr); + strlcpy(currboard, xfpath, sizeof(currboard)); + + fprintf(xptr, "※ [本文轉錄自 %s 看板]\n\n", currboard); + + b_suckinfile(xptr, fname); + addsignature(xptr, 0); + fclose(xptr); + /* + * Cross fs有問題 } else { unlink(xfpath); link(fname, xfpath); } + */ + setbdir(fname, xboard); + append_record(fname, &xfile, sizeof(xfile)); + bp = getbcache(getbnum(xboard)); + if (!xfile.filemode && !(bp->brdattr && BRD_NOTRAN)) + outgo_post(&xfile, xboard); + setbtotal(getbnum(xboard)); + cuser.numposts++; + UPDATE_USEREC; + outs("文章轉錄完成"); + pressanykey(); + currmode = currmode0; + } + return FULLUPDATE; +} +static int +read_post(int ent, fileheader_t * fhdr, char *direct) +{ + char genbuf[200]; + int more_result; - strlcpy(save_title, xfile.title, sizeof(save_title)); - strlcpy(xfpath, currboard, sizeof(xfpath)); - strlcpy(currboard, xboard, sizeof(currboard)); - write_header(xptr); - strlcpy(currboard, xfpath, sizeof(currboard)); + if (fhdr->owner[0] == '-') + return DONOTHING; - fprintf(xptr, "※ [本文轉錄自 %s 看板]\n\n", currboard); + setdirpath(genbuf, direct, fhdr->filename); - b_suckinfile(xptr, fname); - addsignature(xptr, 0); - fclose(xptr); - /* - * Cross fs有問題 } else { unlink(xfpath); link(fname, xfpath); } - */ - setbdir(fname, xboard); - append_record(fname, &xfile, sizeof(xfile)); - bp = getbcache(getbnum(xboard)); - if (!xfile.filemode && !(bp->brdattr && BRD_NOTRAN)) - outgo_post(&xfile, xboard); - setbtotal(getbnum(xboard)); - cuser.numposts++; - UPDATE_USEREC; - outs("文章轉錄完成"); - pressanykey(); - currmode = currmode0; + if ((more_result = more(genbuf, YEA)) == -1) + return DONOTHING; + + brc_addlist(fhdr->filename); + strncpy(currtitle, subject(fhdr->title), TTLEN); + strncpy(currowner, subject(fhdr->owner), IDLEN + 2); + + switch (more_result) { + case 1: + return READ_PREV; + case 2: + return RELATE_PREV; + case 3: + return READ_NEXT; + case 4: + return RELATE_NEXT; + case 5: + return RELATE_FIRST; + case 6: + return FULLUPDATE; + case 7: + case 8: + if ((currmode & MODE_POST)) { + strlcpy(quote_file, genbuf, sizeof(quote_file)); + do_reply(fhdr); + *quote_file = 0; } return FULLUPDATE; + case 9: + return 'A'; + case 10: + return 'a'; + case 11: + return '/'; + case 12: + return '?'; } - static int read_post(int ent, fileheader_t * fhdr, char *direct){ - char genbuf[200]; - int more_result; - - if (fhdr->owner[0] == '-') - return DONOTHING; - - setdirpath(genbuf, direct, fhdr->filename); - - if ((more_result = more(genbuf, YEA)) == -1) - return DONOTHING; - - brc_addlist(fhdr->filename); - strncpy(currtitle, subject(fhdr->title), TTLEN); - strncpy(currowner, subject(fhdr->owner), IDLEN + 2); - - switch (more_result) { - case 1: - return READ_PREV; - case 2: - return RELATE_PREV; - case 3: - return READ_NEXT; - case 4: - return RELATE_NEXT; - case 5: - return RELATE_FIRST; - case 6: - return FULLUPDATE; - case 7: - case 8: - if ((currmode & MODE_POST)) { - strlcpy(quote_file, genbuf, sizeof(quote_file)); - do_reply(fhdr); - *quote_file = 0; - } - return FULLUPDATE; - case 9: - return 'A'; - case 10: - return 'a'; - case 11: - return '/'; - case 12: - return '?'; - } - outmsg("\033[34;46m 閱\讀文章 \033[31;47m (R/Y)\033[30m回信 \033[31m" + outmsg("\033[34;46m 閱\讀文章 \033[31;47m (R/Y)\033[30m回信 \033[31m" "(=[]<>)\033[30m相關主題 \033[31m(↑↓)\033[30m上下封 \033[31m(←)" - "\033[30m離開 \033[m"); + "\033[30m離開 \033[m"); - switch (egetch()) { - case 'q': - case 'Q': - case KEY_LEFT: - break; + switch (egetch()) { + case 'q': + case 'Q': + case KEY_LEFT: + break; - case ' ': - case KEY_RIGHT: - case KEY_DOWN: - case KEY_PGDN: - case 'n': - case Ctrl('N'): - return READ_NEXT; + case ' ': + case KEY_RIGHT: + case KEY_DOWN: + case KEY_PGDN: + case 'n': + case Ctrl('N'): + return READ_NEXT; - case KEY_UP: - case 'p': - case Ctrl('P'): - case KEY_PGUP: - return READ_PREV; + case KEY_UP: + case 'p': + case Ctrl('P'): + case KEY_PGUP: + return READ_PREV; - case '=': - return RELATE_FIRST; + case '=': + return RELATE_FIRST; - case ']': - case 't': - return RELATE_NEXT; + case ']': + case 't': + return RELATE_NEXT; - case '[': - return RELATE_PREV; + case '[': + return RELATE_PREV; - case '.': - case '>': - return THREAD_NEXT; + case '.': + case '>': + return THREAD_NEXT; - case ',': - case '<': - return THREAD_PREV; + case ',': + case '<': + return THREAD_PREV; - case Ctrl('C'): - cal(); - return FULLUPDATE; - break; + case Ctrl('C'): + cal(); + return FULLUPDATE; + break; - case Ctrl('I'): - t_idle(); - return FULLUPDATE; - case 'y': - case 'r': - case 'R': - case 'Y': - if ((currmode & MODE_POST)) { - strlcpy(quote_file, genbuf, sizeof(quote_file)); - do_reply(fhdr); - *quote_file = 0; - } - } + case Ctrl('I'): + t_idle(); return FULLUPDATE; + case 'y': + case 'r': + case 'R': + case 'Y': + if ((currmode & MODE_POST)) { + strlcpy(quote_file, genbuf, sizeof(quote_file)); + do_reply(fhdr); + *quote_file = 0; + } } + return FULLUPDATE; +} - /* ----------------------------------------------------- */ - /* 採集精華區 */ - /* ----------------------------------------------------- */ - static int b_man() { - char buf[64]; - - setapath(buf, currboard); - if ((currmode & MODE_BOARD) || HAS_PERM(PERM_SYSOP)) { - char genbuf[128]; - int fd; - sprintf(genbuf, "%s/.rebuild", buf); - if ((fd = open(genbuf, O_CREAT, 0640)) > 0) - close(fd); - } - return a_menu(currboard, buf, HAS_PERM(PERM_ALLBOARD) ? 2 : - (currmode & MODE_BOARD ? 1 : 0)); +/* ----------------------------------------------------- */ +/* 採集精華區 */ +/* ----------------------------------------------------- */ +static int +b_man() +{ + char buf[64]; + + setapath(buf, currboard); + if ((currmode & MODE_BOARD) || HAS_PERM(PERM_SYSOP)) { + char genbuf[128]; + int fd; + sprintf(genbuf, "%s/.rebuild", buf); + if ((fd = open(genbuf, O_CREAT, 0640)) > 0) + close(fd); } + return a_menu(currboard, buf, HAS_PERM(PERM_ALLBOARD) ? 2 : + (currmode & MODE_BOARD ? 1 : 0)); +} #ifndef NO_GAMBLE - void stop_gamble() { - boardheader_t *bp = getbcache(currbid); - char fn_ticket[128], fn_ticket_end[128]; - if (!bp->endgamble || bp->endgamble > now) - return; - - setbfile(fn_ticket, currboard, FN_TICKET); - setbfile(fn_ticket_end, currboard, FN_TICKET_END); +void +stop_gamble() +{ + boardheader_t *bp = getbcache(currbid); + char fn_ticket[128], fn_ticket_end[128]; + if (!bp->endgamble || bp->endgamble > now) + return; + + setbfile(fn_ticket, currboard, FN_TICKET); + setbfile(fn_ticket_end, currboard, FN_TICKET_END); + + rename(fn_ticket, fn_ticket_end); + if (bp->endgamble) { + bp->endgamble = 0; + substitute_record(fn_board, bp, sizeof(boardheader_t), currbid); + } +} +static int +join_gamble(int ent, fileheader_t * fhdr, char *direct) +{ + if (!HAS_PERM(PERM_LOGINOK)) + return DONOTHING; + stop_gamble(); + ticket(currbid); + return FULLUPDATE; +} +static int +hold_gamble(int ent, fileheader_t * fhdr, char *direct) +{ + char fn_ticket[128], fn_ticket_end[128], genbuf[128], msg[256] = "", + yn[10] = ""; + boardheader_t *bp = getbcache(currbid); + int i; + FILE *fp = NULL; - rename(fn_ticket, fn_ticket_end); - if (bp->endgamble) { + if (!(currmode & MODE_BOARD)) + return 0; + setbfile(fn_ticket, currboard, FN_TICKET); + setbfile(fn_ticket_end, currboard, FN_TICKET_END); + setbfile(genbuf, currboard, FN_TICKET_LOCK); + if (dashf(fn_ticket)) { + getdata(b_lines - 1, 0, "已經有舉辦賭盤, " + "是否要 [停止下注]?(N/y):", yn, 3, LCECHO); + if (yn[0] != 'y') + return FULLUPDATE; + rename(fn_ticket, fn_ticket_end); + if (bp->endgamble) { bp->endgamble = 0; substitute_record(fn_board, bp, sizeof(boardheader_t), currbid); + } - } - static int join_gamble(int ent, fileheader_t * fhdr, char *direct){ - if (!HAS_PERM(PERM_LOGINOK)) - return DONOTHING; - stop_gamble(); - ticket(currbid); return FULLUPDATE; } - static int hold_gamble(int ent, fileheader_t * fhdr, char *direct){ - char fn_ticket[128], fn_ticket_end[128], genbuf[128], msg[256] = "", - yn[10] = ""; - boardheader_t *bp = getbcache(currbid); - int i; - FILE *fp = NULL; - - if (!(currmode & MODE_BOARD)) - return 0; - setbfile(fn_ticket, currboard, FN_TICKET); - setbfile(fn_ticket_end, currboard, FN_TICKET_END); - setbfile(genbuf, currboard, FN_TICKET_LOCK); - if (dashf(fn_ticket)) { - getdata(b_lines - 1, 0, "已經有舉辦賭盤, " - "是否要 [停止下注]?(N/y):", yn, 3, LCECHO); - if (yn[0] != 'y') - return FULLUPDATE; - rename(fn_ticket, fn_ticket_end); - if (bp->endgamble) { - bp->endgamble = 0; - substitute_record(fn_board, bp, sizeof(boardheader_t), currbid); - - } - return FULLUPDATE; - } - if (dashf(fn_ticket_end)) { - getdata(b_lines - 1, 0, "已經有舉辦賭盤, " - "是否要 [開獎/取消]?(N/y):", yn, 3, LCECHO); - if (yn[0] != 'y') - return FULLUPDATE; - openticket(currbid); - return FULLUPDATE; - } else if (dashf(genbuf)) { - move(b_lines - 1, 0); - prints(" 目前系統正在處理開獎事宜, 請結果出爐後再舉辦......."); - pressanykey(); - return FULLUPDATE; - } - getdata(b_lines - 2, 0, "要舉辦賭盤 (N/y):", yn, 3, LCECHO); + if (dashf(fn_ticket_end)) { + getdata(b_lines - 1, 0, "已經有舉辦賭盤, " + "是否要 [開獎/取消]?(N/y):", yn, 3, LCECHO); if (yn[0] != 'y') return FULLUPDATE; - getdata(b_lines - 1, 0, "賭什麼? 請輸入主題 (輸入後編輯內容):", - msg, 20, DOECHO); - if (msg[0] == 0 || - vedit(fn_ticket_end, NA, NULL) < 0) - return FULLUPDATE; + openticket(currbid); + return FULLUPDATE; + } else if (dashf(genbuf)) { + move(b_lines - 1, 0); + prints(" 目前系統正在處理開獎事宜, 請結果出爐後再舉辦......."); + pressanykey(); + return FULLUPDATE; + } + getdata(b_lines - 2, 0, "要舉辦賭盤 (N/y):", yn, 3, LCECHO); + if (yn[0] != 'y') + return FULLUPDATE; + getdata(b_lines - 1, 0, "賭什麼? 請輸入主題 (輸入後編輯內容):", + msg, 20, DOECHO); + if (msg[0] == 0 || + vedit(fn_ticket_end, NA, NULL) < 0) + return FULLUPDATE; - clear(); - showtitle("舉辦賭盤", BBSNAME); - setbfile(genbuf, currboard, FN_TICKET_ITEMS); + clear(); + showtitle("舉辦賭盤", BBSNAME); + setbfile(genbuf, currboard, FN_TICKET_ITEMS); - //sprintf(genbuf, "%s/" FN_TICKET_ITEMS, direct); + //sprintf(genbuf, "%s/" FN_TICKET_ITEMS, direct); - if (!(fp = fopen(genbuf, "w"))) - return FULLUPDATE; - do { - getdata(2, 0, "輸入彩票價格 (價格:10-10000):", yn, 6, LCECHO); - i = atoi(yn); - } while (i < 10 || i > 10000); - fprintf(fp, "%d\n", i); - if (!getdata(3, 0, "設定自動封盤時間?(Y/n)", yn, 3, LCECHO) || yn[0] != 'n') { - bp->endgamble = gettime(4, now); - substitute_record(fn_board, bp, sizeof(boardheader_t), currbid); - } - move(6, 0); - sprintf(genbuf, "請到 %s 板 按'f'參與賭博!\n\n一張 %d Ptt幣, 這是%s的賭博\n%s%s", - currboard, - i, i < 100 ? "小賭式" : i < 500 ? "平民級" : - i < 1000 ? "貴族級" : i < 5000 ? "富豪級" : "傾家蕩產", - bp->endgamble ? "賭盤結束時間: " : "", - bp->endgamble ? Cdate(&bp->endgamble) : "" - ); - strcat(msg, genbuf); - prints("請依次輸入彩票名稱, 需提供2~8項. (未滿八項, 輸入直接按enter)\n"); - for (i = 0; i < 8; i++) { - sprintf(yn, " %d)", i + 1); - getdata(7 + i, 0, yn, genbuf, 9, DOECHO); - if (!genbuf[0] && i > 1) - break; - fprintf(fp, "%s\n", genbuf); - } - fclose(fp); - move(8 + i, 0); - prints("賭盤設定完成"); - sprintf(genbuf, "[公告] %s 板 開始賭博!", currboard); - post_msg(currboard, genbuf, msg, cuser.userid); - post_msg("Record", genbuf + 7, msg, "[馬路探子]"); - /* Tim 控制CS, 以免正在玩的user把資料已經寫進來 */ - rename(fn_ticket_end, fn_ticket); - //設 w 馱~把檔名 儮L - - return FULLUPDATE; + if (!(fp = fopen(genbuf, "w"))) + return FULLUPDATE; + do { + getdata(2, 0, "輸入彩票價格 (價格:10-10000):", yn, 6, LCECHO); + i = atoi(yn); + } while (i < 10 || i > 10000); + fprintf(fp, "%d\n", i); + if (!getdata(3, 0, "設定自動封盤時間?(Y/n)", yn, 3, LCECHO) || yn[0] != 'n') { + bp->endgamble = gettime(4, now); + substitute_record(fn_board, bp, sizeof(boardheader_t), currbid); } + move(6, 0); + sprintf(genbuf, "請到 %s 板 按'f'參與賭博!\n\n一張 %d Ptt幣, 這是%s的賭博\n%s%s", + currboard, + i, i < 100 ? "小賭式" : i < 500 ? "平民級" : + i < 1000 ? "貴族級" : i < 5000 ? "富豪級" : "傾家蕩產", + bp->endgamble ? "賭盤結束時間: " : "", + bp->endgamble ? Cdate(&bp->endgamble) : "" + ); + strcat(msg, genbuf); + prints("請依次輸入彩票名稱, 需提供2~8項. (未滿八項, 輸入直接按enter)\n"); + for (i = 0; i < 8; i++) { + sprintf(yn, " %d)", i + 1); + getdata(7 + i, 0, yn, genbuf, 9, DOECHO); + if (!genbuf[0] && i > 1) + break; + fprintf(fp, "%s\n", genbuf); + } + fclose(fp); + move(8 + i, 0); + prints("賭盤設定完成"); + sprintf(genbuf, "[公告] %s 板 開始賭博!", currboard); + post_msg(currboard, genbuf, msg, cuser.userid); + post_msg("Record", genbuf + 7, msg, "[馬路探子]"); + /* Tim 控制CS, 以免正在玩的user把資料已經寫進來 */ + rename(fn_ticket_end, fn_ticket); + /* 設定完才把檔名改過來 */ + + return FULLUPDATE; +} #endif - static int cite_post(int ent, fileheader_t * fhdr, char *direct){ - char fpath[256]; - char title[TTLEN + 1]; - - setbfile(fpath, currboard, fhdr->filename); - strlcpy(title, "◇ ", sizeof(title)); - strlcpy(title + 3, fhdr->title, TTLEN - 3); - title[TTLEN] = '\0'; - a_copyitem(fpath, title, 0, 1); - b_man(); - return FULLUPDATE; - } +static int +cite_post(int ent, fileheader_t * fhdr, char *direct) +{ + char fpath[256]; + char title[TTLEN + 1]; + + setbfile(fpath, currboard, fhdr->filename); + strlcpy(title, "◇ ", sizeof(title)); + strlcpy(title + 3, fhdr->title, TTLEN - 3); + title[TTLEN] = '\0'; + a_copyitem(fpath, title, 0, 1); + b_man(); + return FULLUPDATE; +} - int edit_title(int ent, fileheader_t * fhdr, char *direct){ - char genbuf[200]; - fileheader_t tmpfhdr = *fhdr; - int dirty = 0; +int +edit_title(int ent, fileheader_t * fhdr, char *direct) +{ + char genbuf[200]; + fileheader_t tmpfhdr = *fhdr; + int dirty = 0; - if (currmode & MODE_BOARD || !strcmp(cuser.userid, fhdr->owner)) { - if (getdata(b_lines - 1, 0, "標題:", genbuf, TTLEN, DOECHO)) { - strlcpy(tmpfhdr.title, genbuf, sizeof(tmpfhdr.title)); - dirty++; - } + if (currmode & MODE_BOARD || !strcmp(cuser.userid, fhdr->owner)) { + if (getdata(b_lines - 1, 0, "標題:", genbuf, TTLEN, DOECHO)) { + strlcpy(tmpfhdr.title, genbuf, sizeof(tmpfhdr.title)); + dirty++; } - if (HAS_PERM(PERM_SYSOP)) { - if (getdata(b_lines - 1, 0, "作者:", genbuf, IDLEN + 2, DOECHO)) { - strlcpy(tmpfhdr.owner, genbuf, sizeof(tmpfhdr.owner)); - dirty++; - } - if (getdata(b_lines - 1, 0, "日期:", genbuf, 6, DOECHO)) { - sprintf(tmpfhdr.date, "%.5s", genbuf); - dirty++; - } + } + if (HAS_PERM(PERM_SYSOP)) { + if (getdata(b_lines - 1, 0, "作者:", genbuf, IDLEN + 2, DOECHO)) { + strlcpy(tmpfhdr.owner, genbuf, sizeof(tmpfhdr.owner)); + dirty++; } - if (currmode & MODE_BOARD || !strcmp(cuser.userid, fhdr->owner)) { - getdata(b_lines - 1, 0, "確定(Y/N)?[n] ", genbuf, 3, DOECHO); - if ((genbuf[0] == 'y' || genbuf[0] == 'Y') && dirty) { - *fhdr = tmpfhdr; - substitute_record(direct, fhdr, sizeof(*fhdr), ent); - /* rocker.011018: 這裡應該改成用reference的方式取得原來的檔案 */ - substitute_check(fhdr); - touchdircache(currbid); - } - return FULLUPDATE; + if (getdata(b_lines - 1, 0, "日期:", genbuf, 6, DOECHO)) { + sprintf(tmpfhdr.date, "%.5s", genbuf); + dirty++; } - return DONOTHING; } - - static int solve_post(int ent, fileheader_t * fhdr, char *direct){ - if (HAS_PERM(PERM_SYSOP)) { - fhdr->filemode ^= FILE_SOLVED; + if (currmode & MODE_BOARD || !strcmp(cuser.userid, fhdr->owner)) { + getdata(b_lines - 1, 0, "確定(Y/N)?[n] ", genbuf, 3, DOECHO); + if ((genbuf[0] == 'y' || genbuf[0] == 'Y') && dirty) { + *fhdr = tmpfhdr; substitute_record(direct, fhdr, sizeof(*fhdr), ent); + /* rocker.011018: 這裡應該改成用reference的方式取得原來的檔案 */ + substitute_check(fhdr); touchdircache(currbid); - return PART_REDRAW; } - return DONOTHING; + return FULLUPDATE; } + return DONOTHING; +} - static int recommend_cancel(int ent, fileheader_t * fhdr, char *direct){ - char yn[5]; - if (!(currmode & MODE_BOARD)) - return DONOTHING; - getdata(b_lines - 1, 0, "確定要推薦歸零(Y/N)?[n] ", yn, 5, LCECHO); - if (yn[0] != 'y') - return FULLUPDATE; - fhdr->recommend = 0; - - substitute_record(direct, fhdr, sizeof(*fhdr), ent); - substitute_check(fhdr); - touchdircache(currbid); - return FULLUPDATE; +static int +solve_post(int ent, fileheader_t * fhdr, char *direct) +{ + if (HAS_PERM(PERM_SYSOP)) { + fhdr->filemode ^= FILE_SOLVED; + substitute_record(direct, fhdr, sizeof(*fhdr), ent); + touchdircache(currbid); + return PART_REDRAW; } - static int recommend(int ent, fileheader_t * fhdr, char *direct){ - struct tm *ptime = localtime(&now); - char buf[200], path[200], yn[5]; - boardheader_t *bp; - bp = getbcache(currbid); - - if (!(currmode & MODE_POST) || !strcmp(fhdr->owner, cuser.userid) || - bp->brdattr & BRD_VOTEBOARD) { - move(b_lines - 1, 0); - prints("您因權限不足無法推薦 或 不能推薦自己的文章!"); - pressanykey(); - return FULLUPDATE; - } - if (fhdr->recommend > 9 || fhdr->recommend < 0) - //暫時性的code 鴩蚋礎陪取消 - fhdr->recommend = 0; - - if (!(currmode & MODE_BOARD) && getuser(cuser.userid) && - now - xuser.recommend < 60) { - move(b_lines - 1, 0); - prints("離上次推薦時間太近囉, 請多花點時間仔細閱\讀文章!"); - pressanykey(); - return FULLUPDATE; - } - if (!getdata(b_lines - 2, 0, "推薦語:", path, 40, DOECHO) || - !getdata(b_lines - 1, 0, "確定要推薦, 請仔細考慮(Y/N)?[n] ", yn, 5, LCECHO) - || yn[0] != 'y') - return FULLUPDATE; + return DONOTHING; +} - sprintf(buf, - "\033[1;31m→ \033[33m%s\033[m\033[33m:%s\033[m%*s推薦自:%s %02d/%02d\n", - cuser.userid, path, - 45 - strlen(cuser.userid) - strlen(path), " ", fromhost, - ptime->tm_mon + 1, ptime->tm_mday); - setdirpath(path, direct, fhdr->filename); - log_file(path, buf); - if (fhdr->recommend < 9) { - fhdr->recommend++; - cuser.recommend = now; - passwd_update(usernum, &cuser); - substitute_record(direct, fhdr, sizeof(*fhdr), ent); - substitute_check(fhdr); - touchdircache(currbid); - } +static int +recommend_cancel(int ent, fileheader_t * fhdr, char *direct) +{ + char yn[5]; + if (!(currmode & MODE_BOARD)) + return DONOTHING; + getdata(b_lines - 1, 0, "確定要推薦歸零(Y/N)?[n] ", yn, 5, LCECHO); + if (yn[0] != 'y') + return FULLUPDATE; + fhdr->recommend = 0; + + substitute_record(direct, fhdr, sizeof(*fhdr), ent); + substitute_check(fhdr); + touchdircache(currbid); + return FULLUPDATE; +} +static int +recommend(int ent, fileheader_t * fhdr, char *direct) +{ + struct tm *ptime = localtime(&now); + char buf[200], path[200], yn[5]; + boardheader_t *bp; + bp = getbcache(currbid); + + if (!(currmode & MODE_POST) || !strcmp(fhdr->owner, cuser.userid) || + bp->brdattr & BRD_VOTEBOARD) { + move(b_lines - 1, 0); + prints("您因權限不足無法推薦 或 不能推薦自己的文章!"); + pressanykey(); return FULLUPDATE; } - static int mark_post(int ent, fileheader_t * fhdr, char *direct){ + if (fhdr->recommend > 9 || fhdr->recommend < 0) + /* 暫時性的 code 原來舊有值取消 */ + fhdr->recommend = 0; - if (!(currmode & MODE_BOARD)) - return DONOTHING; + if (!(currmode & MODE_BOARD) && getuser(cuser.userid) && + now - xuser.recommend < 60) { + move(b_lines - 1, 0); + prints("離上次推薦時間太近囉, 請多花點時間仔細閱\讀文章!"); + pressanykey(); + return FULLUPDATE; + } + if (!getdata(b_lines - 2, 0, "推薦語:", path, 40, DOECHO) || + !getdata(b_lines - 1, 0, "確定要推薦, 請仔細考慮(Y/N)?[n] ", yn, 5, LCECHO) + || yn[0] != 'y') + return FULLUPDATE; - fhdr->filemode ^= FILE_MARKED; + sprintf(buf, + "\033[1;31m→ \033[33m%s\033[m\033[33m:%s\033[m%*s推薦自:%s %02d/%02d\n", + cuser.userid, path, + 45 - strlen(cuser.userid) - strlen(path), " ", fromhost, + ptime->tm_mon + 1, ptime->tm_mday); + setdirpath(path, direct, fhdr->filename); + log_file(path, buf); + if (fhdr->recommend < 9) { + fhdr->recommend++; + cuser.recommend = now; + passwd_update(usernum, &cuser); substitute_record(direct, fhdr, sizeof(*fhdr), ent); substitute_check(fhdr); touchdircache(currbid); - return PART_REDRAW; } + return FULLUPDATE; +} +static int +mark_post(int ent, fileheader_t * fhdr, char *direct) +{ + + if (!(currmode & MODE_BOARD)) + return DONOTHING; + + fhdr->filemode ^= FILE_MARKED; + substitute_record(direct, fhdr, sizeof(*fhdr), ent); + substitute_check(fhdr); + touchdircache(currbid); + return PART_REDRAW; +} - int del_range(int ent, fileheader_t * fhdr, char *direct){ - char num1[8], num2[8]; - int inum1, inum2; - boardheader_t *bp; - bp = getbcache(currbid); +int +del_range(int ent, fileheader_t * fhdr, char *direct) +{ + char num1[8], num2[8]; + int inum1, inum2; + boardheader_t *bp; + bp = getbcache(currbid); - /* rocker.011018: 串接模式下還是不允許刪除比較好 */ - if (currmode & MODE_SELECT) { - outmsg("請先回到正常模式後再進行刪除..."); + /* rocker.011018: 串接模式下還是不允許刪除比較好 */ + if (currmode & MODE_SELECT) { + outmsg("請先回到正常模式後再進行刪除..."); + refresh(); + /* safe_sleep(1); */ + return FULLUPDATE; + } + if (strcmp(bp->brdname, "Security") == 0) + return DONOTHING; + if ((currstat != READING) || (currmode & MODE_BOARD)) { + getdata(1, 0, "[設定刪除範圍] 起點:", num1, 5, DOECHO); + inum1 = atoi(num1); + if (inum1 <= 0) { + outmsg("起點有誤"); refresh(); /* safe_sleep(1); */ return FULLUPDATE; } - if (strcmp(bp->brdname, "Security") == 0) - return DONOTHING; - if ((currstat != READING) || (currmode & MODE_BOARD)) { - getdata(1, 0, "[設定刪除範圍] 起點:", num1, 5, DOECHO); - inum1 = atoi(num1); - if (inum1 <= 0) { - outmsg("起點有誤"); - refresh(); - /* safe_sleep(1); */ - return FULLUPDATE; - } - getdata(1, 28, "終點:", num2, 5, DOECHO); - inum2 = atoi(num2); - if (inum2 < inum1) { - outmsg("終點有誤"); - refresh(); - /* safe_sleep(1); */ - return FULLUPDATE; - } - getdata(1, 48, msg_sure_ny, num1, 3, LCECHO); - if (*num1 == 'y') { - outmsg("處理中,請稍後..."); - refresh(); - if (currmode & MODE_SELECT) { - int fd, size = sizeof(fileheader_t); - char genbuf[100]; - fileheader_t rsfh; - int i = inum1, now; - if (currstat == RMAIL) - sethomedir(genbuf, cuser.userid); - else - setbdir(genbuf, currboard); - if ((fd = (open(direct, O_RDONLY, 0))) != -1) { - if (lseek(fd, (off_t) (size * (inum1 - 1)), SEEK_SET) != - -1) { - while (read(fd, &rsfh, size) == size) { - if (i > inum2) - break; - now = getindex(genbuf, rsfh.filename, size); - strlcpy(currfile, rsfh.filename, sizeof(currfile)); - delete_file(genbuf, sizeof(fileheader_t), now, - cmpfilename); - i++; - } + getdata(1, 28, "終點:", num2, 5, DOECHO); + inum2 = atoi(num2); + if (inum2 < inum1) { + outmsg("終點有誤"); + refresh(); + /* safe_sleep(1); */ + return FULLUPDATE; + } + getdata(1, 48, msg_sure_ny, num1, 3, LCECHO); + if (*num1 == 'y') { + outmsg("處理中,請稍後..."); + refresh(); + if (currmode & MODE_SELECT) { + int fd, size = sizeof(fileheader_t); + char genbuf[100]; + fileheader_t rsfh; + int i = inum1, now; + if (currstat == RMAIL) + sethomedir(genbuf, cuser.userid); + else + setbdir(genbuf, currboard); + if ((fd = (open(direct, O_RDONLY, 0))) != -1) { + if (lseek(fd, (off_t) (size * (inum1 - 1)), SEEK_SET) != + -1) { + while (read(fd, &rsfh, size) == size) { + if (i > inum2) + break; + now = getindex(genbuf, rsfh.filename, size); + strlcpy(currfile, rsfh.filename, sizeof(currfile)); + delete_file(genbuf, sizeof(fileheader_t), now, + cmpfilename); + i++; } - close(fd); } + close(fd); } - delete_range(direct, inum1, inum2); - fixkeep(direct, inum1); + } + delete_range(direct, inum1, inum2); + fixkeep(direct, inum1); - if (currmode & MODE_BOARD) - setbtotal(currbid); + if (currmode & MODE_BOARD) + setbtotal(currbid); - return DIRCHANGED; - } - return FULLUPDATE; + return DIRCHANGED; } - return DONOTHING; + return FULLUPDATE; } + return DONOTHING; +} - static int del_post(int ent, fileheader_t * fhdr, char *direct){ - char genbuf[100]; - int not_owned; - boardheader_t *bp; - - bp = getbcache(currbid); - if (strcmp(bp->brdname, "Security") == 0) - return DONOTHING; - if ((fhdr->filemode & FILE_MARKED) || (fhdr->filemode & FILE_DIGEST) || - (fhdr->owner[0] == '-')) - return DONOTHING; - - not_owned = strcmp(fhdr->owner, cuser.userid); - if ((!(currmode & MODE_BOARD) && not_owned) || - ((bp->brdattr & BRD_VOTEBOARD) && !HAS_PERM(PERM_SYSOP)) || - !strcmp(cuser.userid, STR_GUEST)) - return DONOTHING; - - getdata(1, 0, msg_del_ny, genbuf, 3, LCECHO); - if (genbuf[0] == 'y' || genbuf[0] == 'Y') { - strlcpy(currfile, fhdr->filename, sizeof(currfile)); - - setbfile(genbuf, currboard, fhdr->filename); - if (!delete_file(direct, sizeof(fileheader_t), ent, cmpfilename)) { - - if (currmode & MODE_SELECT) { - /* rocker.011018: 利用reference減低loading */ - fileheader_t hdr; - int num; - - num = fhdr->money & ~FHR_REFERENCE; - setbdir(genbuf, currboard); - get_record(genbuf, &hdr, sizeof(hdr), num); - - /* 再這裡要check一下原來的dir裡面是不是有被人動過... */ - if (strcmp(hdr.filename, fhdr->filename)) { - num = getindex(genbuf, fhdr->filename, sizeof(fileheader_t)); - get_record(genbuf, &hdr, sizeof(hdr), num); - } - /* rocker.011018: 這裡要還原被破壞的money */ - fhdr->money = hdr.money; - delete_file(genbuf, sizeof(fileheader_t), num, cmpfilename); - } - cancelpost(fhdr, not_owned); +static int +del_post(int ent, fileheader_t * fhdr, char *direct) +{ + char genbuf[100]; + int not_owned; + boardheader_t *bp; - setbtotal(currbid); - if (fhdr->money < 0) - fhdr->money = 0; - if (not_owned && strcmp(currboard, "Test")) { - deumoney(searchuser(fhdr->owner), -fhdr->money); - } - if (!not_owned && strcmp(currboard, "Test")) { - if (cuser.numposts) - cuser.numposts--; - move(b_lines - 1, 0); - clrtoeol(); - demoney(-fhdr->money); - passwd_update(usernum, &cuser); /* post 數 */ - prints("%s,您的文章減為 %d 篇,支付清潔費 %d 銀", msg_del_ok, - cuser.numposts, fhdr->money); - refresh(); - pressanykey(); + bp = getbcache(currbid); + if (strcmp(bp->brdname, "Security") == 0) + return DONOTHING; + if ((fhdr->filemode & FILE_MARKED) || (fhdr->filemode & FILE_DIGEST) || + (fhdr->owner[0] == '-')) + return DONOTHING; + + not_owned = strcmp(fhdr->owner, cuser.userid); + if ((!(currmode & MODE_BOARD) && not_owned) || + ((bp->brdattr & BRD_VOTEBOARD) && !HAS_PERM(PERM_SYSOP)) || + !strcmp(cuser.userid, STR_GUEST)) + return DONOTHING; + + getdata(1, 0, msg_del_ny, genbuf, 3, LCECHO); + if (genbuf[0] == 'y' || genbuf[0] == 'Y') { + strlcpy(currfile, fhdr->filename, sizeof(currfile)); + + setbfile(genbuf, currboard, fhdr->filename); + if (!delete_file(direct, sizeof(fileheader_t), ent, cmpfilename)) { + + if (currmode & MODE_SELECT) { + /* rocker.011018: 利用reference減低loading */ + fileheader_t hdr; + int num; + + num = fhdr->money & ~FHR_REFERENCE; + setbdir(genbuf, currboard); + get_record(genbuf, &hdr, sizeof(hdr), num); + + /* 再這裡要check一下原來的dir裡面是不是有被人動過... */ + if (strcmp(hdr.filename, fhdr->filename)) { + num = getindex(genbuf, fhdr->filename, sizeof(fileheader_t)); + get_record(genbuf, &hdr, sizeof(hdr), num); } - return DIRCHANGED; + /* rocker.011018: 這裡要還原被破壞的money */ + fhdr->money = hdr.money; + delete_file(genbuf, sizeof(fileheader_t), num, cmpfilename); + } + cancelpost(fhdr, not_owned); + + setbtotal(currbid); + if (fhdr->money < 0) + fhdr->money = 0; + if (not_owned && strcmp(currboard, "Test")) { + deumoney(searchuser(fhdr->owner), -fhdr->money); + } + if (!not_owned && strcmp(currboard, "Test")) { + if (cuser.numposts) + cuser.numposts--; + move(b_lines - 1, 0); + clrtoeol(); + demoney(-fhdr->money); + passwd_update(usernum, &cuser); /* post 數 */ + prints("%s,您的文章減為 %d 篇,支付清潔費 %d 銀", msg_del_ok, + cuser.numposts, fhdr->money); + refresh(); + pressanykey(); } + return DIRCHANGED; } - return FULLUPDATE; } + return FULLUPDATE; +} - static int view_postmoney(int ent, fileheader_t * fhdr, char *direct){ - move(b_lines - 1, 0); - clrtoeol(); - prints("這一篇文章值 %d 銀", fhdr->money); - refresh(); +static int +view_postmoney(int ent, fileheader_t * fhdr, char *direct) +{ + move(b_lines - 1, 0); + clrtoeol(); + prints("這一篇文章值 %d 銀", fhdr->money); + refresh(); + pressanykey(); + return FULLUPDATE; +} + +#ifdef OUTJOBSPOOL +/* 看板備份 */ +static int +tar_addqueue(int ent, fileheader_t * fhdr, char *direct) +{ + char email[60], qfn[80], ans[2]; + FILE *fp; + char bakboard, bakman; + clear(); + showtitle("看板備份", BBSNAME); + move(2, 0); + if (!((currmode & MODE_BOARD) || HAS_PERM(PERM_SYSOP))) { + move(5, 10); + outs("妳要是板主或是站長才能醬醬啊 -.-\"\""); pressanykey(); return FULLUPDATE; } + sprintf(qfn, BBSHOME "/jobspool/tarqueue.%s", currboard); + if (access(qfn, 0) == 0) { + outs("已經排定行程, 稍後會進行備份"); + pressanykey(); + return FULLUPDATE; + } + if (!getdata(4, 0, "請輸入目的信箱:", email, sizeof(email), DOECHO)) + return FULLUPDATE; -#ifdef OUTJOBSPOOL - /* 看板備份 */ - static int tar_addqueue(int ent, fileheader_t * fhdr, char *direct){ - char email[60], qfn[80], ans[2]; - FILE *fp; - char bakboard, bakman; - clear(); - showtitle("看板備份", BBSNAME); - move(2, 0); - if (!((currmode & MODE_BOARD) || HAS_PERM(PERM_SYSOP))) { - move(5, 10); - outs("妳要是板主或是站長才能醬醬啊 -.-\"\""); - pressanykey(); - return FULLUPDATE; - } - sprintf(qfn, BBSHOME "/jobspool/tarqueue.%s", currboard); - if (access(qfn, 0) == 0) { - outs("已經排定行程, 稍後會進行備份"); - pressanykey(); - return FULLUPDATE; - } - if (!getdata(4, 0, "請輸入目的信箱:", email, sizeof(email), DOECHO)) - return FULLUPDATE; - - /* check email -.-"" */ - if (strstr(email, "@") == NULL || strstr(email, ".bbs@") != NULL) { - move(6, 0); - outs("您指定的信箱不正確! "); - pressanykey(); - return FULLUPDATE; - } - getdata(6, 0, "要備份看板內容嗎(Y/N)?[Y]", ans, sizeof(ans), LCECHO); - bakboard = (ans[0] == 'n' || ans[0] == 'N') ? 0 : 1; - getdata(7, 0, "要備份精華區內容嗎(Y/N)?[N]", ans, sizeof(ans), LCECHO); - bakman = (ans[0] == 'y' || ans[0] == 'Y') ? 1 : 0; - if (!bakboard && !bakman) { - move(8, 0); - outs("可是我們只能備份看板或精華區的耶 ^^\"\"\""); - pressanykey(); - return FULLUPDATE; - } - fp = fopen(qfn, "w"); - fprintf(fp, "%s\n", cuser.userid); - fprintf(fp, "%s\n", email); - fprintf(fp, "%d,%d\n", bakboard, bakman); - fclose(fp); - - move(10, 0); - outs("系統已經將您的備份排入行程, \n"); - outs("稍後將會在系統負荷較低的時候將資料寄給您~ :) "); + /* check email -.-"" */ + if (strstr(email, "@") == NULL || strstr(email, ".bbs@") != NULL) { + move(6, 0); + outs("您指定的信箱不正確! "); + pressanykey(); + return FULLUPDATE; + } + getdata(6, 0, "要備份看板內容嗎(Y/N)?[Y]", ans, sizeof(ans), LCECHO); + bakboard = (ans[0] == 'n' || ans[0] == 'N') ? 0 : 1; + getdata(7, 0, "要備份精華區內容嗎(Y/N)?[N]", ans, sizeof(ans), LCECHO); + bakman = (ans[0] == 'y' || ans[0] == 'Y') ? 1 : 0; + if (!bakboard && !bakman) { + move(8, 0); + outs("可是我們只能備份看板或精華區的耶 ^^\"\"\""); pressanykey(); return FULLUPDATE; } + fp = fopen(qfn, "w"); + fprintf(fp, "%s\n", cuser.userid); + fprintf(fp, "%s\n", email); + fprintf(fp, "%d,%d\n", bakboard, bakman); + fclose(fp); + + move(10, 0); + outs("系統已經將您的備份排入行程, \n"); + outs("稍後將會在系統負荷較低的時候將資料寄給您~ :) "); + pressanykey(); + return FULLUPDATE; +} #endif - static int sequent_ent; - static int continue_flag; +static int sequent_ent; +static int continue_flag; - /* ----------------------------------------------------- */ - /* 依序讀新文章 */ - /* ----------------------------------------------------- */ - static int sequent_messages(fileheader_t * fptr) { - static int idc; - char genbuf[200]; +/* ----------------------------------------------------- */ +/* 依序讀新文章 */ +/* ----------------------------------------------------- */ +static int +sequent_messages(fileheader_t * fptr) +{ + static int idc; + char genbuf[200]; - if (fptr == NULL) - return (idc = 0); + if (fptr == NULL) + return (idc = 0); - if (++idc < sequent_ent) - return 0; + if (++idc < sequent_ent) + return 0; - if (!brc_unread(fptr->filename, brc_num, brc_list)) - return 0; + if (!brc_unread(fptr->filename, brc_num, brc_list)) + return 0; - if (continue_flag) - genbuf[0] = 'y'; - else { - prints("讀取文章於:[%s] 作者:[%s]\n標題:[%s]", - currboard, fptr->owner, fptr->title); - getdata(3, 0, "(Y/N/Quit) [Y]: ", genbuf, 3, LCECHO); - } + if (continue_flag) + genbuf[0] = 'y'; + else { + prints("讀取文章於:[%s] 作者:[%s]\n標題:[%s]", + currboard, fptr->owner, fptr->title); + getdata(3, 0, "(Y/N/Quit) [Y]: ", genbuf, 3, LCECHO); + } - if (genbuf[0] != 'y' && genbuf[0]) { - clear(); - return (genbuf[0] == 'q' ? QUIT : 0); - } - setbfile(genbuf, currboard, fptr->filename); - brc_addlist(fptr->filename); - - if (more(genbuf, YEA) == 0) - outmsg("\033[31;47m \033[31m(R)\033[30m回信 \033[31m(↓,n)" - "\033[30m下一封 \033[31m(←,q)\033[30m離開 \033[m"); - continue_flag = 0; - - switch (egetch()) { - case KEY_LEFT: - case 'e': - case 'q': - case 'Q': - break; + if (genbuf[0] != 'y' && genbuf[0]) { + clear(); + return (genbuf[0] == 'q' ? QUIT : 0); + } + setbfile(genbuf, currboard, fptr->filename); + brc_addlist(fptr->filename); - case 'y': - case 'r': - case 'Y': - case 'R': - if (currmode & MODE_POST) { - strlcpy(quote_file, genbuf, sizeof(quote_file)); - do_reply(fptr); - *quote_file = 0; - } - break; + if (more(genbuf, YEA) == 0) + outmsg("\033[31;47m \033[31m(R)\033[30m回信 \033[31m(↓,n)" + "\033[30m下一封 \033[31m(←,q)\033[30m離開 \033[m"); + continue_flag = 0; - case ' ': - case KEY_DOWN: - case '\n': - case 'n': - continue_flag = 1; + switch (egetch()) { + case KEY_LEFT: + case 'e': + case 'q': + case 'Q': + break; + + case 'y': + case 'r': + case 'Y': + case 'R': + if (currmode & MODE_POST) { + strlcpy(quote_file, genbuf, sizeof(quote_file)); + do_reply(fptr); + *quote_file = 0; } + break; - clear(); - return 0; + case ' ': + case KEY_DOWN: + case '\n': + case 'n': + continue_flag = 1; } - static int sequential_read(int ent, fileheader_t * fhdr, char *direct){ - char buf[40]; + clear(); + return 0; +} - clear(); - sequent_messages((fileheader_t *) NULL); - sequent_ent = ent; - continue_flag = 0; - setbdir(buf, currboard); - apply_record(buf, sequent_messages, sizeof(fileheader_t)); - return FULLUPDATE; - } +static int +sequential_read(int ent, fileheader_t * fhdr, char *direct) +{ + char buf[40]; - /* ----------------------------------------------------- */ - /* 看板備忘錄、文摘、精華區 */ - /* ----------------------------------------------------- */ - int b_note_edit_bname(int bid){ - char buf[64]; - int aborted; - boardheader_t *fh = getbcache(bid); - setbfile(buf, fh->brdname, fn_notes); - aborted = vedit(buf, NA, NULL); - if (aborted == -1) { - clear(); - outs(msg_cancel); - pressanykey(); - } else { - if (!getdata(2, 0, "設定有效期限天?(n/Y)", buf, 3, LCECHO) - || buf[0] != 'n') - fh->bupdate = gettime(3, fh->bupdate ? fh->bupdate : now); - else - fh->bupdate = 0; - substitute_record(fn_board, fh, sizeof(boardheader_t), bid); - } - return 0; - } + clear(); + sequent_messages((fileheader_t *) NULL); + sequent_ent = ent; + continue_flag = 0; + setbdir(buf, currboard); + apply_record(buf, sequent_messages, sizeof(fileheader_t)); + return FULLUPDATE; +} - static int b_notes_edit() { - if (currmode & MODE_BOARD) { - b_note_edit_bname(currbid); - return FULLUPDATE; - } - return 0; +/* ----------------------------------------------------- */ +/* 看板備忘錄、文摘、精華區 */ +/* ----------------------------------------------------- */ +int +b_note_edit_bname(int bid) +{ + char buf[64]; + int aborted; + boardheader_t *fh = getbcache(bid); + setbfile(buf, fh->brdname, fn_notes); + aborted = vedit(buf, NA, NULL); + if (aborted == -1) { + clear(); + outs(msg_cancel); + pressanykey(); + } else { + if (!getdata(2, 0, "設定有效期限天?(n/Y)", buf, 3, LCECHO) + || buf[0] != 'n') + fh->bupdate = gettime(3, fh->bupdate ? fh->bupdate : now); + else + fh->bupdate = 0; + substitute_record(fn_board, fh, sizeof(boardheader_t), bid); } + return 0; +} - static int b_water_edit() { - if (currmode & MODE_BOARD) { - friend_edit(BOARD_WATER); - return FULLUPDATE; - } - return 0; +static int +b_notes_edit() +{ + if (currmode & MODE_BOARD) { + b_note_edit_bname(currbid); + return FULLUPDATE; } + return 0; +} - static int visable_list_edit() { - if (currmode & MODE_BOARD) { - friend_edit(BOARD_VISABLE); - hbflreload(currbid); - return FULLUPDATE; - } - return 0; +static int +b_water_edit() +{ + if (currmode & MODE_BOARD) { + friend_edit(BOARD_WATER); + return FULLUPDATE; } + return 0; +} - static int b_post_note() { - char buf[200], yn[3]; - - if (currmode & MODE_BOARD) { - setbfile(buf, currboard, FN_POST_NOTE); - if (more(buf, NA) == -1) - more("etc/" FN_POST_NOTE, NA); - getdata(b_lines - 2, 0, "是否要用自訂post注意事項?", yn, sizeof(yn), LCECHO); - if (yn[0] == 'y') - vedit(buf, NA, NULL); - else - unlink(buf); - return FULLUPDATE; - } - return 0; +static int +visable_list_edit() +{ + if (currmode & MODE_BOARD) { + friend_edit(BOARD_VISABLE); + hbflreload(currbid); + return FULLUPDATE; } + return 0; +} - static int b_application() { - char buf[200]; - - if (currmode & MODE_BOARD) { - setbfile(buf, currboard, FN_APPLICATION); +static int +b_post_note() +{ + char buf[200], yn[3]; + + if (currmode & MODE_BOARD) { + setbfile(buf, currboard, FN_POST_NOTE); + if (more(buf, NA) == -1) + more("etc/" FN_POST_NOTE, NA); + getdata(b_lines - 2, 0, "是否要用自訂post注意事項?", yn, sizeof(yn), LCECHO); + if (yn[0] == 'y') vedit(buf, NA, NULL); - return FULLUPDATE; - } - return 0; + else + unlink(buf); + return FULLUPDATE; } + return 0; +} - static int can_vote_edit() { - if (currmode & MODE_BOARD) { - friend_edit(FRIEND_CANVOTE); - return FULLUPDATE; - } - return 0; +static int +b_application() +{ + char buf[200]; + + if (currmode & MODE_BOARD) { + setbfile(buf, currboard, FN_APPLICATION); + vedit(buf, NA, NULL); + return FULLUPDATE; } + return 0; +} - static int bh_title_edit() { - boardheader_t *bp; - - if (currmode & MODE_BOARD) { - char genbuf[BTLEN]; - - bp = getbcache(currbid); - move(1, 0); - clrtoeol(); - getdata_str(1, 0, "請輸入看板新中文敘述:", genbuf, - BTLEN - 16, DOECHO, bp->title + 7); - - if (!genbuf[0]) - return 0; - strip_ansi(genbuf, genbuf, 0); - strlcpy(bp->title + 7, genbuf, sizeof(bp->title) - 7); - substitute_record(fn_board, bp, sizeof(boardheader_t), currbid); - log_usies("SetBoard", currboard); - return FULLUPDATE; - } - return 0; +static int +can_vote_edit() +{ + if (currmode & MODE_BOARD) { + friend_edit(FRIEND_CANVOTE); + return FULLUPDATE; } + return 0; +} - static int b_notes() { - char buf[64]; +static int +bh_title_edit() +{ + boardheader_t *bp; - setbfile(buf, currboard, fn_notes); - if (more(buf, NA) == -1) { - clear(); - move(4, 20); - outs("本看板尚無「備忘錄」。"); - } - pressanykey(); + if (currmode & MODE_BOARD) { + char genbuf[BTLEN]; + + bp = getbcache(currbid); + move(1, 0); + clrtoeol(); + getdata_str(1, 0, "請輸入看板新中文敘述:", genbuf, + BTLEN - 16, DOECHO, bp->title + 7); + + if (!genbuf[0]) + return 0; + strip_ansi(genbuf, genbuf, 0); + strlcpy(bp->title + 7, genbuf, sizeof(bp->title) - 7); + substitute_record(fn_board, bp, sizeof(boardheader_t), currbid); + log_usies("SetBoard", currboard); return FULLUPDATE; } + return 0; +} - int board_select() { - char fpath[80]; - char genbuf[100]; +static int +b_notes() +{ + char buf[64]; - currmode &= ~MODE_SELECT; - sprintf(fpath, "SR.%s", cuser.userid); - setbfile(genbuf, currboard, fpath); - unlink(genbuf); - if (currstat == RMAIL) - sethomedir(currdirect, cuser.userid); - else - setbdir(currdirect, currboard); - return NEWDIRECT; + setbfile(buf, currboard, fn_notes); + if (more(buf, NA) == -1) { + clear(); + move(4, 20); + outs("本看板尚無「備忘錄」。"); } + pressanykey(); + return FULLUPDATE; +} - int board_digest() { - if (currmode & MODE_SELECT) - board_select(); - currmode ^= MODE_DIGEST; - if (currmode & MODE_DIGEST) - currmode &= ~MODE_POST; - else if (haspostperm(currboard)) - currmode |= MODE_POST; +int +board_select() +{ + char fpath[80]; + char genbuf[100]; + currmode &= ~MODE_SELECT; + sprintf(fpath, "SR.%s", cuser.userid); + setbfile(genbuf, currboard, fpath); + unlink(genbuf); + if (currstat == RMAIL) + sethomedir(currdirect, cuser.userid); + else setbdir(currdirect, currboard); - return NEWDIRECT; - } + return NEWDIRECT; +} - int board_etc() { - if (!HAS_PERM(PERM_SYSOP)) - return DONOTHING; - currmode ^= MODE_ETC; - if (currmode & MODE_ETC) - currmode &= ~MODE_POST; - else if (haspostperm(currboard)) - currmode |= MODE_POST; +int +board_digest() +{ + if (currmode & MODE_SELECT) + board_select(); + currmode ^= MODE_DIGEST; + if (currmode & MODE_DIGEST) + currmode &= ~MODE_POST; + else if (haspostperm(currboard)) + currmode |= MODE_POST; - setbdir(currdirect, currboard); - return NEWDIRECT; - } + setbdir(currdirect, currboard); + return NEWDIRECT; +} - static int good_post(int ent, fileheader_t * fhdr, char *direct){ - char genbuf[200]; - char genbuf2[200]; - int delta = 0; - - if ((currmode & MODE_DIGEST) || !(currmode & MODE_BOARD)) - return DONOTHING; - - if (fhdr->filemode & FILE_DIGEST) { - fhdr->filemode = (fhdr->filemode & ~FILE_DIGEST); - if (!strcmp(currboard, "Note") || !strcmp(currboard, "PttBug") || - !strcmp(currboard, "Artdsn") || !strcmp(currboard, "PttLaw")) { - deumoney(searchuser(fhdr->owner), -1000); - if (!(currmode & MODE_SELECT)) - fhdr->money -= 1000; - else - delta = -1000; - } - } else { - fileheader_t digest; - char *ptr, buf[64]; - - memcpy(&digest, fhdr, sizeof(digest)); - digest.filename[0] = 'G'; - strlcpy(buf, direct, sizeof(buf)); - ptr = strrchr(buf, '/') + 1; - ptr[0] = '\0'; - sprintf(genbuf, "%s%s", buf, digest.filename); - - if (dashf(genbuf)) - unlink(genbuf); +int +board_etc() +{ + if (!HAS_PERM(PERM_SYSOP)) + return DONOTHING; + currmode ^= MODE_ETC; + if (currmode & MODE_ETC) + currmode &= ~MODE_POST; + else if (haspostperm(currboard)) + currmode |= MODE_POST; - digest.filemode = 0; - sprintf(genbuf2, "%s%s", buf, fhdr->filename); - Link(genbuf2, genbuf); - strcpy(ptr, fn_mandex); - append_record(buf, &digest, sizeof(digest)); - - fhdr->filemode = (fhdr->filemode & ~FILE_MARKED) | FILE_DIGEST; - if (!strcmp(currboard, "Note") || !strcmp(currboard, "PttBug") || - !strcmp(currboard, "Artdsn") || !strcmp(currboard, "PttLaw")) { - deumoney(searchuser(fhdr->owner), 1000); - if (!(currmode & MODE_SELECT)) - fhdr->money += 1000; - else - delta = 1000; - } + setbdir(currdirect, currboard); + return NEWDIRECT; +} + +static int +good_post(int ent, fileheader_t * fhdr, char *direct) +{ + char genbuf[200]; + char genbuf2[200]; + int delta = 0; + + if ((currmode & MODE_DIGEST) || !(currmode & MODE_BOARD)) + return DONOTHING; + + if (fhdr->filemode & FILE_DIGEST) { + fhdr->filemode = (fhdr->filemode & ~FILE_DIGEST); + if (!strcmp(currboard, "Note") || !strcmp(currboard, "PttBug") || + !strcmp(currboard, "Artdsn") || !strcmp(currboard, "PttLaw")) { + deumoney(searchuser(fhdr->owner), -1000); + if (!(currmode & MODE_SELECT)) + fhdr->money -= 1000; + else + delta = -1000; } - substitute_record(direct, fhdr, sizeof(*fhdr), ent); - touchdircache(currbid); - /* rocker.011018: 串接模式用reference增進效率 */ - if ((currmode & MODE_SELECT) && (fhdr->money & FHR_REFERENCE)) { - fileheader_t hdr; - char genbuf[100]; - int num; + } else { + fileheader_t digest; + char *ptr, buf[64]; - num = fhdr->money & ~FHR_REFERENCE; - setbdir(genbuf, currboard); - get_record(genbuf, &hdr, sizeof(hdr), num); + memcpy(&digest, fhdr, sizeof(digest)); + digest.filename[0] = 'G'; + strlcpy(buf, direct, sizeof(buf)); + ptr = strrchr(buf, '/') + 1; + ptr[0] = '\0'; + sprintf(genbuf, "%s%s", buf, digest.filename); - /* 再這裡要check一下原來的dir裡面是不是有被人動過... */ - if (strcmp(hdr.filename, fhdr->filename)) { - num = getindex(genbuf, fhdr->filename, sizeof(fileheader_t)); - get_record(genbuf, &hdr, sizeof(hdr), num); - } - fhdr->money = hdr.money + delta; + if (dashf(genbuf)) + unlink(genbuf); - substitute_record(genbuf, fhdr, sizeof(*fhdr), num); + digest.filemode = 0; + sprintf(genbuf2, "%s%s", buf, fhdr->filename); + Link(genbuf2, genbuf); + strcpy(ptr, fn_mandex); + append_record(buf, &digest, sizeof(digest)); + + fhdr->filemode = (fhdr->filemode & ~FILE_MARKED) | FILE_DIGEST; + if (!strcmp(currboard, "Note") || !strcmp(currboard, "PttBug") || + !strcmp(currboard, "Artdsn") || !strcmp(currboard, "PttLaw")) { + deumoney(searchuser(fhdr->owner), 1000); + if (!(currmode & MODE_SELECT)) + fhdr->money += 1000; + else + delta = 1000; } - return PART_REDRAW; } + substitute_record(direct, fhdr, sizeof(*fhdr), ent); + touchdircache(currbid); + /* rocker.011018: 串接模式用reference增進效率 */ + if ((currmode & MODE_SELECT) && (fhdr->money & FHR_REFERENCE)) { + fileheader_t hdr; + char genbuf[100]; + int num; - /* help for board reading */ - static char *board_help[] = { - "\0全功\能看板操作說明", - "\01基本命令", - "(p)(↑) 上移一篇文章 (^P) 發表文章", - "(n)(↓) 下移一篇文章 (d) 刪除文章", - "(P)(PgUp) 上移一頁 (S) 串連相關文章", - "(N)(PgDn) 下移一頁 (##) 跳到 ## 號文章", - "(r)(→) 閱\讀此篇文章 ($) 跳到最後一篇文章", - "\01進階命令", - "(tab)/z 文摘模式/精華區 (a/A)(^Q)找尋作者/作者資料", - "(b/f) 展讀備忘錄/參與賭盤 (?)(/) 找尋標題", - "(V/R) 投票/查詢投票結果 (^W)(X) 我在哪裡/推薦文章", - "(x)(w) 轉錄文章/丟水球 (=)/([]<>-+) 找尋首篇文章/主題式閱\讀", + num = fhdr->money & ~FHR_REFERENCE; + setbdir(genbuf, currboard); + get_record(genbuf, &hdr, sizeof(hdr), num); + + /* 再這裡要check一下原來的dir裡面是不是有被人動過... */ + if (strcmp(hdr.filename, fhdr->filename)) { + num = getindex(genbuf, fhdr->filename, sizeof(fileheader_t)); + get_record(genbuf, &hdr, sizeof(hdr), num); + } + fhdr->money = hdr.money + delta; + + substitute_record(genbuf, fhdr, sizeof(*fhdr), num); + } + return PART_REDRAW; +} + +/* help for board reading */ +static char *board_help[] = { + "\0全功\能看板操作說明", + "\01基本命令", + "(p)(↑) 上移一篇文章 (^P) 發表文章", + "(n)(↓) 下移一篇文章 (d) 刪除文章", + "(P)(PgUp) 上移一頁 (S) 串連相關文章", + "(N)(PgDn) 下移一頁 (##) 跳到 ## 號文章", + "(r)(→) 閱\讀此篇文章 ($) 跳到最後一篇文章", + "\01進階命令", + "(tab)/z 文摘模式/精華區 (a/A)(^Q)找尋作者/作者資料", + "(b/f) 展讀備忘錄/參與賭盤 (?)(/) 找尋標題", + "(V/R) 投票/查詢投票結果 (^W)(X) 我在哪裡/推薦文章", + "(x)(w) 轉錄文章/丟水球 (=)/([]<>-+) 找尋首篇文章/主題式閱\讀", #ifdef INTERNET_EMAIL - "(F) 文章寄回Internet郵箱 (U) 將文章 uuencode 後寄回郵箱", + "(F) 文章寄回Internet郵箱 (U) 將文章 uuencode 後寄回郵箱", #endif - "(E) 重編文章 (^H) 列出所有的 New Post(s)", - "\01板主命令", - "(G) 舉辦賭盤/停止下注/開獎(W/K/v) 編輯備忘錄/水桶名單/可看見名單", - "(M/o) 舉行投票/編私投票名單 (m/c/g) 保留文章/選錄精華/文摘", - "(D) 刪除一段範圍的文章 (T/B) 重編文章標題/重編看板標題", - "(i) 編輯申請入會表格 (t/^D) 標記文章/砍除標記的文章", - "(O) 編輯Post注意事項 (H)/(Y) 看板隱藏/現身 取消推薦文章", - NULL - }; - - static int b_help() { - show_help(board_help); - return FULLUPDATE; - } + "(E) 重編文章 (^H) 列出所有的 New Post(s)", + "\01板主命令", + "(G) 舉辦賭盤/停止下注/開獎(W/K/v) 編輯備忘錄/水桶名單/可看見名單", + "(M/o) 舉行投票/編私投票名單 (m/c/g) 保留文章/選錄精華/文摘", + "(D) 刪除一段範圍的文章 (T/B) 重編文章標題/重編看板標題", + "(i) 編輯申請入會表格 (t/^D) 標記文章/砍除標記的文章", + "(O) 編輯Post注意事項 (H)/(Y) 看板隱藏/現身 取消推薦文章", + NULL +}; + +static int +b_help() +{ + show_help(board_help); + return FULLUPDATE; +} - /* ----------------------------------------------------- */ - /* 板主設定隱形/ 解隱形 */ - /* ----------------------------------------------------- */ - char board_hidden_status; +/* ----------------------------------------------------- */ +/* 板主設定隱形/ 解隱形 */ +/* ----------------------------------------------------- */ +char board_hidden_status; #ifdef BMCHS - static int change_hidden(int ent, fileheader_t * fhdr, char *direct){ - boardheader_t bh; - int bid; - char ans[4]; - - if (!((currmode & MODE_BOARD) || HAS_PERM(PERM_SYSOP)) || - currboard[0] == 0 || - (bid = getbnum(currboard)) < 0 || - get_record(fn_board, &bh, sizeof(bh), bid) == -1) - return DONOTHING; - - if (((bh.brdattr & BRD_HIDE) && (bh.brdattr & BRD_POSTMASK))) { - getdata(1, 0, "目前板在隱形狀態, 要解隱形嘛(Y/N)?[N]", - ans, sizeof(ans), LCECHO); - if (ans[0] != 'y' && ans[0] != 'Y') - return FULLUPDATE; - getdata(2, 0, "再確認一次, 真的要把板板公開嘛 @____@(Y/N)?[N]", - ans, sizeof(ans), LCECHO); - if (ans[0] != 'y' && ans[0] != 'Y') - return FULLUPDATE; - if (bh.brdattr & BRD_HIDE) - bh.brdattr -= BRD_HIDE; - if (bh.brdattr & BRD_POSTMASK) - bh.brdattr -= BRD_POSTMASK; - log_usies("OpenBoard", bh.brdname); - outs("君心今傳眾人,無處不聞弦歌。\n"); - board_hidden_status = 0; - hbflreload(bid); - } else { - getdata(1, 0, "目前板在現形狀態, 要隱形嘛(Y/N)?[N]", - ans, sizeof(ans), LCECHO); - if (ans[0] != 'y' && ans[0] != 'Y') - return FULLUPDATE; - bh.brdattr |= BRD_HIDE; - bh.brdattr |= BRD_POSTMASK; - log_usies("CloseBoard", bh.brdname); - outs("君心今已掩抑,惟盼善自珍重。\n"); - board_hidden_status = 1; - } - setup_man(&bh); - substitute_record(fn_board, &bh, sizeof(bh), bid); - reset_board(bid); - log_usies("SetBoard", bh.brdname); - pressanykey(); - return FULLUPDATE; +static int +change_hidden(int ent, fileheader_t * fhdr, char *direct) +{ + boardheader_t bh; + int bid; + char ans[4]; + + if (!((currmode & MODE_BOARD) || HAS_PERM(PERM_SYSOP)) || + currboard[0] == 0 || + (bid = getbnum(currboard)) < 0 || + get_record(fn_board, &bh, sizeof(bh), bid) == -1) + return DONOTHING; + + if (((bh.brdattr & BRD_HIDE) && (bh.brdattr & BRD_POSTMASK))) { + getdata(1, 0, "目前板在隱形狀態, 要解隱形嘛(Y/N)?[N]", + ans, sizeof(ans), LCECHO); + if (ans[0] != 'y' && ans[0] != 'Y') + return FULLUPDATE; + getdata(2, 0, "再確認一次, 真的要把板板公開嘛 @____@(Y/N)?[N]", + ans, sizeof(ans), LCECHO); + if (ans[0] != 'y' && ans[0] != 'Y') + return FULLUPDATE; + if (bh.brdattr & BRD_HIDE) + bh.brdattr -= BRD_HIDE; + if (bh.brdattr & BRD_POSTMASK) + bh.brdattr -= BRD_POSTMASK; + log_usies("OpenBoard", bh.brdname); + outs("君心今傳眾人,無處不聞弦歌。\n"); + board_hidden_status = 0; + hbflreload(bid); + } else { + getdata(1, 0, "目前板在現形狀態, 要隱形嘛(Y/N)?[N]", + ans, sizeof(ans), LCECHO); + if (ans[0] != 'y' && ans[0] != 'Y') + return FULLUPDATE; + bh.brdattr |= BRD_HIDE; + bh.brdattr |= BRD_POSTMASK; + log_usies("CloseBoard", bh.brdname); + outs("君心今已掩抑,惟盼善自珍重。\n"); + board_hidden_status = 1; } + setup_man(&bh); + substitute_record(fn_board, &bh, sizeof(bh), bid); + reset_board(bid); + log_usies("SetBoard", bh.brdname); + pressanykey(); + return FULLUPDATE; +} #endif - /* ----------------------------------------------------- */ - /* 看板功能表 */ - /* ----------------------------------------------------- */ - struct onekey_t read_comms[] = { - {KEY_TAB, board_digest}, - {'C', board_etc}, - {'b', b_notes}, - {'c', cite_post}, - {'r', read_post}, - {'z', b_man}, - {'D', del_range}, - {'S', sequential_read}, - {'E', edit_post}, - {'T', edit_title}, - {'s', do_select}, - {'R', b_results}, - {'V', b_vote}, - {'M', b_vote_maintain}, - {'B', bh_title_edit}, - {'W', b_notes_edit}, - {'O', b_post_note}, - {'K', b_water_edit}, - {'w', b_call_in}, - {'v', visable_list_edit}, - {'i', b_application}, - {'o', can_vote_edit}, - {'x', cross_post}, - {'X', recommend}, - {'Y', recommend_cancel}, - {'h', b_help}, +/* ----------------------------------------------------- */ +/* 看板功能表 */ +/* ----------------------------------------------------- */ +struct onekey_t read_comms[] = { + {KEY_TAB, board_digest}, + {'C', board_etc}, + {'b', b_notes}, + {'c', cite_post}, + {'r', read_post}, + {'z', b_man}, + {'D', del_range}, + {'S', sequential_read}, + {'E', edit_post}, + {'T', edit_title}, + {'s', do_select}, + {'R', b_results}, + {'V', b_vote}, + {'M', b_vote_maintain}, + {'B', bh_title_edit}, + {'W', b_notes_edit}, + {'O', b_post_note}, + {'K', b_water_edit}, + {'w', b_call_in}, + {'v', visable_list_edit}, + {'i', b_application}, + {'o', can_vote_edit}, + {'x', cross_post}, + {'X', recommend}, + {'Y', recommend_cancel}, + {'h', b_help}, #ifndef NO_GAMBLE - {'f', join_gamble}, - {'G', hold_gamble}, + {'f', join_gamble}, + {'G', hold_gamble}, #endif - {'g', good_post}, - {'y', reply_post}, - {'d', del_post}, - {'m', mark_post}, - {'L', solve_post}, - {Ctrl('P'), do_post}, - {Ctrl('W'), whereami}, - {'Q', view_postmoney}, + {'g', good_post}, + {'y', reply_post}, + {'d', del_post}, + {'m', mark_post}, + {'L', solve_post}, + {Ctrl('P'), do_post}, + {Ctrl('W'), whereami}, + {'Q', view_postmoney}, #ifdef OUTJOBSPOOL - {'u', tar_addqueue}, + {'u', tar_addqueue}, #endif #ifdef BMCHS - {'H', change_hidden}, + {'H', change_hidden}, #endif - {'\0', NULL} - }; + {'\0', NULL} +}; - int Read() { - int mode0 = currutmp->mode; - int stat0 = currstat, tmpbid = currutmp->brc_id; - char buf[40]; +int +Read() +{ + int mode0 = currutmp->mode; + int stat0 = currstat, tmpbid = currutmp->brc_id; + char buf[40]; #ifdef LOG_BOARD - time_t usetime = now; + time_t usetime = now; #endif - setutmpmode(READING); - set_board(); + setutmpmode(READING); + set_board(); - if (board_visit_time < board_note_time) { - setbfile(buf, currboard, fn_notes); - more(buf, NA); - pressanykey(); - } - setutmpbid(currbid); - setbdir(buf, currboard); - curredit &= ~EDIT_MAIL; - i_read(READING, buf, readtitle, readdoent, read_comms, - currbid); + if (board_visit_time < board_note_time) { + setbfile(buf, currboard, fn_notes); + more(buf, NA); + pressanykey(); + } + setutmpbid(currbid); + setbdir(buf, currboard); + curredit &= ~EDIT_MAIL; + i_read(READING, buf, readtitle, readdoent, read_comms, + currbid); #ifdef LOG_BOARD - log_board(currboard, now - usetime); + log_board(currboard, now - usetime); #endif - brc_update(); - setutmpbid(tmpbid); - currutmp->mode = mode0; - currstat = stat0; - return 0; - } + brc_update(); + setutmpbid(tmpbid); + currutmp->mode = mode0; + currstat = stat0; + return 0; +} - void ReadSelect() { - int mode0 = currutmp->mode; - int stat0 = currstat; - char genbuf[200]; - - currstat = XMODE; - if (do_select(0, 0, genbuf) == NEWDIRECT) - Read(); - setutmpbid(0); - currutmp->mode = mode0; - currstat = stat0; - } +void +ReadSelect() +{ + int mode0 = currutmp->mode; + int stat0 = currstat; + char genbuf[200]; + + currstat = XMODE; + if (do_select(0, 0, genbuf) == NEWDIRECT) + Read(); + setutmpbid(0); + currutmp->mode = mode0; + currstat = stat0; +} #ifdef LOG_BOARD - static void log_board(char *mode, time_t usetime){ - char buf[256]; +static void +log_board(char *mode, time_t usetime) +{ + char buf[256]; - if (usetime > 30) { - sprintf(buf, "USE %-20.20s Stay: %5ld (%s) %s", - mode, usetime, cuser.userid, ctime(&now)); - log_file(FN_USEBOARD, buf); - } + if (usetime > 30) { + sprintf(buf, "USE %-20.20s Stay: %5ld (%s) %s", + mode, usetime, cuser.userid, ctime(&now)); + log_file(FN_USEBOARD, buf); } +} #endif - int Select() { - char genbuf[200]; +int +Select() +{ + char genbuf[200]; - setutmpmode(SELECT); - do_select(0, NULL, genbuf); - return 0; - } + setutmpmode(SELECT); + do_select(0, NULL, genbuf); + return 0; +} #ifdef HAVEMOBILE - void mobile_message(char *mobile, char *message){ +void +mobile_message(char *mobile, char *message) +{ - bsmtp(char *fpath, char *title, char *rcpt, int method); - } + bsmtp(char *fpath, char *title, char *rcpt, int method); +} #endif diff --git a/pttbbs/mbbsd/board.c b/pttbbs/mbbsd/board.c index 859c8c8b..d6d8c8ea 100644 --- a/pttbbs/mbbsd/board.c +++ b/pttbbs/mbbsd/board.c @@ -1,4 +1,4 @@ -/* $Id: board.c,v 1.41 2002/07/21 08:18:41 in2 Exp $ */ +/* $Id: board.c,v 1.42 2002/07/21 09:26:02 in2 Exp $ */ #include "bbs.h" #define BRC_STRLEN 15 /* Length of board name */ #define BRC_MAXSIZE 24576 @@ -49,7 +49,7 @@ static char brc_name[BRC_STRLEN]; static char *fn_boardrc = ".boardrc"; static int brc_size; -void +void brc_update() { if (brc_changed && cuser.userlevel) { @@ -88,7 +88,7 @@ brc_update() } } -static void +static void read_brc_buf() { char dirfile[STRLEN]; @@ -105,7 +105,7 @@ read_brc_buf() } } -int +int brc_initial(char *boardname) { char *ptr; @@ -129,7 +129,7 @@ brc_initial(char *boardname) return 0; } -void +void brc_addlist(char *fname) { int ftime, n, i; @@ -167,7 +167,7 @@ brc_addlist(char *fname) } } -static int +static int brc_unread_time(time_t ftime, int bnum, int *blist) { int n; @@ -186,7 +186,7 @@ brc_unread_time(time_t ftime, int bnum, int *blist) return 0; } -int +int brc_unread(char *fname, int bnum, int *blist) { int ftime, n; @@ -225,7 +225,7 @@ static boardstat_t *nbrd = NULL; #define STR_BBSRC ".bbsrc" #define STR_FAV ".fav" -void +void init_brdbuf() { register int n, size; @@ -260,7 +260,7 @@ init_brdbuf() brc_expire_time = login_start_time - 365 * 86400; } -void +void save_brdbuf() { int fd, size; @@ -288,7 +288,7 @@ save_brdbuf() } } -int +int Ben_Perm(boardheader_t * bptr) { register int level, brdattr; @@ -323,7 +323,7 @@ Ben_Perm(boardheader_t * bptr) } #if 0 -static int +static int have_author(char *brdname) { char dirname[100]; @@ -342,7 +342,7 @@ have_author(char *brdname) } #endif -static int +static int check_newpost(boardstat_t * ptr) { /* Ptt 改 */ int tbrc_list[BRC_MAXNUM], tbrc_num; @@ -377,7 +377,7 @@ check_newpost(boardstat_t * ptr) static int brdnum; static int yank_flag = 1; -static void +static void load_uidofgid(const int gid, const int type) { boardheader_t *bptr, *currbptr; @@ -423,13 +423,13 @@ addnewbrdstat(int n, int state) return ptr; } -static int +static int cmpboardfriends(const void *brd, const void *tmp) { return ((boardstat_t *) tmp)->bh->nuser - ((boardstat_t *) brd)->bh->nuser; } -static void +static void load_boards(char *key) { boardheader_t *bptr = NULL; @@ -476,7 +476,7 @@ load_boards(char *key) } } -static int +static int search_board() { int num; @@ -494,7 +494,7 @@ search_board() return -1; } -static int +static int unread_position(char *dirfile, boardstat_t * ptr) { fileheader_t fh; @@ -535,7 +535,7 @@ unread_position(char *dirfile, boardstat_t * ptr) return num; } -static void +static void brdlist_foot() { prints("\033[34;46m 選擇看板 \033[31;47m (c)\033[30m新文章模式 " @@ -544,7 +544,7 @@ brdlist_foot() yank_flag == 0 ? "最愛" : yank_flag == 1 ? "部份" : "全部"); } -static void +static void show_brdlist(int head, int clsflag, int newflag) { int myrow = 2; @@ -670,7 +670,7 @@ static char *choosebrdhelp[] = { }; -static void +static void set_menu_BM(char *BM) { if (HAS_PERM(PERM_ALLBOARD) || is_BM(BM)) { @@ -681,7 +681,7 @@ set_menu_BM(char *BM) static char *privateboard = "\n\n\n\n 對不起 此板目前只准看板好友進入 請先向板主申請入境許\可"; -static void +static void dozap(int num) { boardstat_t *ptr; @@ -695,7 +695,7 @@ dozap(int num) } -static void +static void choose_board(int newflag) { static int num = 0; @@ -1063,7 +1063,7 @@ choose_board(int newflag) free(nbrd); } -int +int root_board() { class_bid = 1; @@ -1072,7 +1072,7 @@ root_board() return 0; } -int +int Boards() { class_bid = 0; @@ -1082,7 +1082,7 @@ Boards() } -int +int New() { int mode0 = currutmp->mode; diff --git a/pttbbs/mbbsd/cache.c b/pttbbs/mbbsd/cache.c index ba0701a8..fd61cf55 100644 --- a/pttbbs/mbbsd/cache.c +++ b/pttbbs/mbbsd/cache.c @@ -1,4 +1,4 @@ -/* $Id: cache.c,v 1.42 2002/07/21 08:18:41 in2 Exp $ */ +/* $Id: cache.c,v 1.43 2002/07/21 09:26:02 in2 Exp $ */ #include "bbs.h" #ifndef __FreeBSD__ @@ -15,7 +15,7 @@ union semun { * handler routine, while SIGALRM is blocked. if we use the original sleep, * we'll never wake up. */ -unsigned int +unsigned int safe_sleep(unsigned int seconds) { /* jochang sleep有問題時用 */ @@ -39,7 +39,7 @@ safe_sleep(unsigned int seconds) } #if defined(_BBS_UTIL_C_) -static void +static void setapath(char *buf, char *boardname) { sprintf(buf, "man/boards/%c/%s", boardname[0], boardname); @@ -47,14 +47,14 @@ setapath(char *buf, char *boardname) static char *str_dotdir = ".DIR"; -static void +static void setadir(char *buf, char *path) { sprintf(buf, "%s/%s", path, str_dotdir); } #endif -static void +static void attach_err(int shmkey, char *name) { fprintf(stderr, "[%s error] key = %x\n", name, shmkey); @@ -91,7 +91,7 @@ attach_shm(int shmkey, int shmsize) /* ----------------------------------------------------- */ /* semaphore : for critical section */ /* ----------------------------------------------------- */ -void +void sem_init(int semkey, int *semid) { union semun s; @@ -106,7 +106,7 @@ sem_init(int semkey, int *semid) } } -void +void sem_lock(int op, int semid) { struct sembuf sops; @@ -130,7 +130,7 @@ sem_lock(int op, int semid) /* attach_uhash should be called before using uhash */ -void +void attach_SHM(void) { SHM = attach_shm(SHM_KEY, sizeof(SHM_t)); @@ -149,7 +149,7 @@ attach_SHM(void) SHM->Ftouchtime = 1; } -void +void add_to_uhash(int n, char *id) { int *p, h = StringHash(id); @@ -171,7 +171,7 @@ add_to_uhash(int n, char *id) * note: after remove_from_uhash(), you should add_to_uhash() (likely with a * different name) */ -void +void remove_from_uhash(int n) { int h = StringHash(SHM->userid[n]); @@ -188,7 +188,7 @@ remove_from_uhash(int n) *p = SHM->next_in_hash[n]; } -int +int setumoney(int uid, int money) { SHM->money[uid - 1] = money; @@ -196,7 +196,7 @@ setumoney(int uid, int money) return SHM->money[uid - 1]; } -int +int deumoney(int uid, int money) { if (money < 0 && SHM->money[uid - 1] < -money) @@ -204,17 +204,17 @@ deumoney(int uid, int money) else return setumoney(uid, SHM->money[uid - 1] + money); } -int +int demoney(int money) { return deumoney(usernum, money); } -int +int moneyof(int uid) { /* ptt 改進金錢處理效率 */ return SHM->money[uid - 1]; } -int +int searchuser(char *userid) { int h, p, times; @@ -234,7 +234,7 @@ searchuser(char *userid) #if !defined(_BBS_UTIL_C_) -int +int getuser(char *userid) { int uid; @@ -252,7 +252,7 @@ getuserid(int num) return NULL; } -void +void setuserid(int num, char *userid) { if (num > 0 && num <= MAX_USERS) { @@ -267,7 +267,7 @@ setuserid(int num, char *userid) /* 0 ==> 找過期帳號 */ /* 1 ==> 建立新帳號 */ /* should do it by searching "" in the hash */ -int +int searchnewuser(int mode) { register int i, num; @@ -320,7 +320,7 @@ u_namearray(char buf[][IDLEN + 1], int *pnum, char *tag) /* .UTMP cache */ /*-------------------------------------------------------*/ #if !defined(_BBS_UTIL_C_) -void +void setutmpmode(int mode) { if (currstat != mode) @@ -335,31 +335,31 @@ setutmpmode(int mode) } } #endif -static int +static int cmputmpuserid(const void *i, const void *j) { return strcasecmp((*((userinfo_t **) i))->userid, (*((userinfo_t **) j))->userid); } -static int +static int cmputmpmode(const void *i, const void *j) { return (*((userinfo_t **) i))->mode - (*((userinfo_t **) j))->mode; } -static int +static int cmputmpidle(const void *i, const void *j) { return (*((userinfo_t **) i))->lastact - (*((userinfo_t **) j))->lastact; } -static int +static int cmputmpfrom(const void *i, const void *j) { return strcasecmp((*((userinfo_t **) i))->from, (*((userinfo_t **) j))->from); } -static int +static int cmputmpfive(const void *i, const void *j) { int type; @@ -371,7 +371,7 @@ cmputmpfive(const void *i, const void *j) } #if 0 -static int +static int cmputmpsex(const void *i, const void *j) { static int ladyfirst[] = {1, 0, 1, 0, 1, 0, 3, 3}; @@ -379,17 +379,17 @@ cmputmpsex(const void *i, const void *j) ladyfirst[(*(userinfo_t **) j)->sex & 07]; } #endif -static int +static int cmputmppid(const void *i, const void *j) { return (*((userinfo_t **) i))->pid - (*((userinfo_t **) j))->pid; } -static int +static int cmputmpuid(const void *i, const void *j) { return (*((userinfo_t **) i))->uid - (*((userinfo_t **) j))->uid; } -void +void sort_utmp() { userinfo_t *uentp; @@ -446,9 +446,10 @@ sort_utmp() SHM->bcache[i].nuser = nusers[i]; } -//Ptt:這 銗[入hash 觀念找空的utmp - void getnewutmpent(userinfo_t * up) - { +/* Ptt:這裡加上 hash 觀念找空的 utmp */ +void +getnewutmpent(userinfo_t * up) +{ register int i, p; register userinfo_t *uentp; for (i = 0, p = StringHash(up->userid) % USHM_SIZE; i < USHM_SIZE; i++, p++) { @@ -465,7 +466,7 @@ sort_utmp() exit(1); } -int +int apply_ulist(int (*fptr) (userinfo_t *)) { register userinfo_t *uentp; @@ -541,7 +542,7 @@ search_ulistn(int uid, int unum) return 0; } -int +int count_logins(int uid, int show) { register int i = 0, j, start = 0, end = SHM->UTMPnumber - 1, count; @@ -575,7 +576,7 @@ count_logins(int uid, int show) } -void +void purge_utmp(userinfo_t * uentp) { logout_friend_online(uentp); @@ -587,14 +588,14 @@ purge_utmp(userinfo_t * uentp) /*-------------------------------------------------------*/ /* .BOARDS cache */ /*-------------------------------------------------------*/ -void +void touchdircache(int bid) { int *i = (int *)&SHM->dircache[bid - 1][0].filename[0]; *i = 0; } -void +void load_fileheader_cache(int bid, char *direct) { int num = getbtotal(bid); @@ -609,7 +610,7 @@ load_fileheader_cache(int bid, char *direct) } } -int +int get_fileheader_cache(int bid, char *direct, fileheader_t * headers, int recbase, int nlines) { @@ -634,18 +635,18 @@ get_fileheader_cache(int bid, char *direct, fileheader_t * headers, memcpy(headers, &(SHM->dircache[bid - 1][n]), sizeof(fileheader_t) * ret); return ret; } -static int +static int cmpboardname(boardheader_t ** brd, boardheader_t ** tmp) { return strcasecmp((*brd)->brdname, (*tmp)->brdname); } -static int +static int cmpboardclass(boardheader_t ** brd, boardheader_t ** tmp) { return (strncmp((*brd)->title, (*tmp)->title, 4) << 8) + strcasecmp((*brd)->brdname, (*tmp)->brdname); } -static void +static void sort_bcache() { int i; @@ -658,7 +659,7 @@ sort_bcache() qsort(SHM->bsorted[1], SHM->Bnumber, sizeof(boardheader_t *), (QCAST) cmpboardclass); } -static void +static void reload_bcache() { if (SHM->Bbusystate) { @@ -689,7 +690,7 @@ reload_bcache() #endif } -void +void resolve_boards() { while (SHM->Buptime < SHM->Btouchtime) { @@ -698,14 +699,14 @@ resolve_boards() numboards = SHM->Bnumber; } -void +void touch_boards() { SHM->Btouchtime = now; numboards = -1; resolve_boards(); } -void +void addbrd_touchcache() { SHM->Bnumber++; @@ -713,7 +714,7 @@ addbrd_touchcache() reset_board(numboards); } #if !defined(_BBS_UTIL_C_) -void +void reset_board(int bid) { /* Ptt: 這樣就不用老是touch board了 */ int fd, i, nuser; @@ -745,7 +746,7 @@ reset_board(int bid) } } -int +int apply_boards(int (*func) (boardheader_t *)) { register int i; @@ -765,12 +766,12 @@ getbcache(int bid) { /* Ptt改寫 */ return bcache + bid - 1; } -int +int getbtotal(int bid) { return SHM->total[bid - 1]; } -void +void setbtotal(int bid) { boardheader_t *bh = getbcache(bid); @@ -798,7 +799,7 @@ setbtotal(int bid) touchdircache(bid); } -void +void touchbpostnum(int bid, int delta) { int *total = &SHM->total[bid - 1]; @@ -807,7 +808,7 @@ touchbpostnum(int bid, int delta) } -int +int getbnum(char *bname) { register int i = 0, j, start = 0, end = SHM->Bnumber - 1; @@ -830,7 +831,7 @@ getbnum(char *bname) } #if !defined(_BBS_UTIL_C_) -int +int haspostperm(char *bname) { register int i; @@ -871,7 +872,7 @@ haspostperm(char *bname) /* PTT cache */ /*-------------------------------------------------------*/ /* cachefor 動態看板 */ -void +void reload_pttcache() { if (SHM->Pbusystate) @@ -942,7 +943,7 @@ reload_pttcache() } } -void +void resolve_garbage() { int count = 0; @@ -951,8 +952,8 @@ resolve_garbage() reload_pttcache(); if (count++ > 10 && SHM->Pbusystate) { /* - * Ptt: 這邊會有問題 load超過10 秒會所有進loop的process - * tate = 0 這樣會所有prcosee都會在load 動態看板 會造成load大增 + * Ptt: 這邊會有問題 load超過10 秒會所有進loop的process tate = 0 + * 這樣會所有prcosee都會在load 動態看板 會造成load大增 * 但沒有用這個function的話 萬一load passwd檔的process死了 * 又沒有人把他 解開 同樣的問題發生在reload passwd */ @@ -968,7 +969,7 @@ resolve_garbage() /* PTT's cache */ /*-------------------------------------------------------*/ /* cachefor from host 與最多上線人數 */ -static void +static void reload_fcache() { if (SHM->Fbusystate) @@ -1009,14 +1010,14 @@ reload_fcache() } } -void +void resolve_fcache() { while (SHM->Fuptime < SHM->Ftouchtime) reload_fcache(); } -void +void hbflreload(int bid) { int hbfl[MAX_FRIEND + 1], i, num, uid; @@ -1047,7 +1048,7 @@ hbflreload(int bid) memcpy(SHM->hbfl[bid], hbfl, sizeof(hbfl)); } -int +int hbflcheck(int bid, int uid) { int i; @@ -1074,7 +1075,7 @@ cachepath(const char *fpath) return cpath; } -int +int updatemdcache(const char *CPATH, const char *fpath) { /* @@ -1102,7 +1103,7 @@ updatemdcache(const char *CPATH, const char *fpath) return targetfd; } -int +int mdcacheopen(char *fpath) { int fd; diff --git a/pttbbs/mbbsd/cal.c b/pttbbs/mbbsd/cal.c index f423f8e3..fb0c2802 100644 --- a/pttbbs/mbbsd/cal.c +++ b/pttbbs/mbbsd/cal.c @@ -1,8 +1,8 @@ -/* $Id: cal.c,v 1.17 2002/07/21 08:18:41 in2 Exp $ */ +/* $Id: cal.c,v 1.18 2002/07/21 09:26:02 in2 Exp $ */ #include "bbs.h" /* 防堵 Multi play */ -static int +static int count_multiplay(int unmode) { register int i, j; @@ -17,7 +17,7 @@ count_multiplay(int unmode) return j; } -int +int lockutmpmode(int unmode, int state) { int errorno = 0; @@ -45,7 +45,7 @@ lockutmpmode(int unmode, int state) return 0; } -int +int unlockutmpmode() { currutmp->lockmode = 0; @@ -56,7 +56,7 @@ unlockutmpmode() #define VICE_NEW "vice.new" /* Heat:發票 */ -int +int vice(int money, char *item) { char buf[128]; @@ -82,7 +82,7 @@ vice(int money, char *item) #define SONGBOOK "etc/SONGBOOK" #define OSONGPATH "etc/SONGO" -static int +static int osong(char *defaultid) { char destid[IDLEN + 1], buf[200], genbuf[200], filename[256], @@ -239,14 +239,14 @@ osong(char *defaultid) return 1; } -int +int ordersong() { osong(NULL); return 0; } -static int +static int inmailbox(int m) { passwd_query(usernum, &xuser); @@ -258,7 +258,7 @@ inmailbox(int m) #if !HAVE_FREECLOAK /* 花錢選單 */ -int +int p_cloak() { char buf[4]; @@ -278,7 +278,7 @@ p_cloak() } #endif -int +int p_from() { char ans[4]; @@ -297,7 +297,7 @@ p_from() return 0; } -int +int p_exmail() { char ans[4], buf[200]; @@ -327,7 +327,7 @@ p_exmail() return 0; } -void +void mail_redenvelop(char *from, char *to, int money, char mode) { char genbuf[200]; @@ -355,7 +355,7 @@ mail_redenvelop(char *from, char *to, int money, char mode) } /* 計算贈與稅 */ -int +int give_tax(int money) { int i, tax = 0; @@ -369,7 +369,7 @@ give_tax(int money) return (tax <= 0) ? 1 : tax; } -int +int p_give() { int money, tax; @@ -398,7 +398,7 @@ p_give() return 0; } -int +int p_sysinfo(void) { char buf[128], *cpuloadstr; @@ -422,7 +422,7 @@ p_sysinfo(void) } /* 小計算機 */ -static void +static void ccount(float *a, float b, int cmode) { switch (cmode) { @@ -443,7 +443,7 @@ ccount(float *a, float b, int cmode) } } -int +int cal() { float a = 0; diff --git a/pttbbs/mbbsd/calendar.c b/pttbbs/mbbsd/calendar.c index 13a8ed16..03cd84d6 100644 --- a/pttbbs/mbbsd/calendar.c +++ b/pttbbs/mbbsd/calendar.c @@ -1,4 +1,4 @@ -/* $Id: calendar.c,v 1.5 2002/07/21 08:18:41 in2 Exp $ */ +/* $Id: calendar.c,v 1.6 2002/07/21 09:26:02 in2 Exp $ */ #include "bbs.h" typedef struct event_t { @@ -8,7 +8,7 @@ typedef struct event_t { struct event_t *next; } event_t; -static int +static int MonthDay(int m, int leap) { static int day[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; @@ -16,7 +16,7 @@ MonthDay(int m, int leap) return leap && m == 2 ? 29 : day[m - 1]; } -static int +static int IsLeap(int y) { if (y % 400 == 0 || (y % 4 == 0 && y % 100 != 0)) @@ -25,7 +25,7 @@ IsLeap(int y) return 0; } -static int +static int Days(int y, int m, int d) { int i, w; @@ -38,7 +38,7 @@ Days(int y, int m, int d) return w; } -static int +static int ParseDate(char *date, event_t * t) { char *y, *m, *d; @@ -59,7 +59,7 @@ ParseDate(char *date, event_t * t) return 0; } -static int +static int ParseColor(char *color) { struct { @@ -99,7 +99,7 @@ ParseColor(char *color) return 7; } -static void +static void InsertEvent(event_t * head, event_t * t) { event_t *p; @@ -109,7 +109,7 @@ InsertEvent(event_t * head, event_t * t) p->next = t; } -static void +static void FreeEvent(event_t * e) { event_t *n; @@ -173,7 +173,7 @@ AllocCalBuffer(int line, int len) return p; } -static void +static void FreeCalBuffer(char **buf) { free(buf[0]); @@ -185,7 +185,7 @@ FreeCalBuffer(char **buf) #define HEADER_SUNDAY_COLOR "\33[31m" #define HEADER_DAY_COLOR "\33[33m" -static int +static int GenerateCalendar(char **buf, int y, int m, int today, event_t * e) { static char *week_str[7] = {"日", "一", "二", "三", "四", "五", "六"}; @@ -258,7 +258,7 @@ GenerateCalendar(char **buf, int y, int m, int today, event_t * e) return line + 1; } -int +int calendar() { char **buf; diff --git a/pttbbs/mbbsd/card.c b/pttbbs/mbbsd/card.c index 2b09d9c2..1c457046 100644 --- a/pttbbs/mbbsd/card.c +++ b/pttbbs/mbbsd/card.c @@ -1,7 +1,7 @@ -/* $Id: card.c,v 1.4 2002/07/05 17:10:27 in2 Exp $ */ +/* $Id: card.c,v 1.5 2002/07/21 09:26:02 in2 Exp $ */ #include "bbs.h" -static int +static int card_remain(int cards[]) { int i, temp = 0; @@ -14,20 +14,20 @@ card_remain(int cards[]) } /* 0 Spare , 1 heart , ...3 dimon */ -static int +static int card_flower(int card) { return (card / 13); } /* 1...13 */ -static int +static int card_number(int card) { return (card % 13 + 1); } -static int +static int card_select(int *now) { char *cc[2] = {"\033[44m \033[m", @@ -75,7 +75,7 @@ card_select(int *now) } } -static void +static void card_display(int cline, int number, int flower, int show) { int color = 31; @@ -132,7 +132,7 @@ card_display(int cline, int number, int flower, int show) } } -static void +static void card_show(int cpu[], int c[], int me[], int m[]) { int i, j; @@ -152,25 +152,25 @@ card_show(int cpu[], int c[], int me[], int m[]) card_display(j + 1, card_number(me[i]), card_flower(me[i]), m[i]); } } -static void +static void card_new(int cards[]) { memset(cards, 0, sizeof(int) * 52); } -static int +static int card_give(int cards[]) { int i, error; for (error = 0, i = rand() % 52; cards[i] == 1 && error < 52; error++, i = rand() % 52); if (error == 52) card_new(cards); -//Ptt:這 鉿責ead lock 暋D - cards[i] = 1; + /* Ptt: 這邊有 dead lock 的問題 */ + cards[i] = 1; return i; } -static void +static void card_start(char name[]) { clear(); @@ -184,7 +184,7 @@ card_start(char name[]) prints(" \033[1;37;42m 自 己 \033[m"); } -static int +static int card_99_add(int i, int aom, int count) { if (i == 4 || i == 5 || i == 11) @@ -199,7 +199,7 @@ card_99_add(int i, int aom, int count) return count + i; } -static int +static int card_99_cpu(int cpu[], int *count) { int stop = -1; @@ -256,7 +256,7 @@ card_99_cpu(int cpu[], int *count) } } -int +int card_99() { int i, j, turn; @@ -340,7 +340,7 @@ card_99() #define JACK (10) /* 黑傑克的Ticket */ #define NINE99 (99) /* 99 的Ticket */ -static int +static int game_log(int type, int money) { FILE *fp; @@ -367,7 +367,7 @@ game_log(int type, int money) return 0; } -static int +static int card_double_ask() { char buf[100], buf2[3]; @@ -383,7 +383,7 @@ card_double_ask() return 0; } -static int +static int card_ask() { char buf[100], buf2[3]; @@ -396,7 +396,7 @@ card_ask() return 0; } -static int +static int card_alls_lower(int all[]) { int i, count = 0; @@ -408,7 +408,7 @@ card_alls_lower(int all[]) return count; } -static int +static int card_alls_upper(int all[]) { int i, count; @@ -420,7 +420,7 @@ card_alls_upper(int all[]) return count; } -static int +static int card_jack(int *db) { int i, j; @@ -531,7 +531,7 @@ card_jack(int *db) return 0; } -int +int g_card_jack() { int db; @@ -559,7 +559,7 @@ g_card_jack() return 0; } -static int +static int card_all(int all[]) { int i, count = 0; @@ -572,7 +572,7 @@ card_all(int all[]) return count; } -static int +static int ten_helf() { int i, j; @@ -633,7 +633,7 @@ ten_helf() return 0; } -int +int g_ten_helf() { char buf[3]; diff --git a/pttbbs/mbbsd/chat.c b/pttbbs/mbbsd/chat.c index 5f709bb2..e852fbf2 100644 --- a/pttbbs/mbbsd/chat.c +++ b/pttbbs/mbbsd/chat.c @@ -1,9 +1,9 @@ -/* $Id: chat.c,v 1.7 2002/07/21 08:18:41 in2 Exp $ */ +/* $Id: chat.c,v 1.8 2002/07/21 09:26:02 in2 Exp $ */ #include "bbs.h" static int chatline, stop_line; static FILE *flog; -static void +static void printchatline(char *str) { move(chatline, 0); @@ -23,7 +23,7 @@ printchatline(char *str) fprintf(flog, "%s\n", str); } -static void +static void chat_clear() { for (chatline = 2; chatline < stop_line; chatline++) { @@ -36,7 +36,7 @@ chat_clear() outs("→"); } -static void +static void print_chatid(char *chatid) { move(b_lines - 1, 0); @@ -45,7 +45,7 @@ print_chatid(char *chatid) outc(':'); } -static int +static int chat_send(int fd, char *buf) { int len; @@ -58,7 +58,7 @@ chat_send(int fd, char *buf) static char chatroom[IDLEN];/* Chat-Room Name */ -static int +static int chat_recv(int fd, char *chatid) { static char buf[512]; @@ -114,7 +114,7 @@ chat_recv(int fd, char *chatid) return 0; } -static int +static int printuserent(userinfo_t * uentp) { static char uline[80]; @@ -145,7 +145,7 @@ printuserent(userinfo_t * uentp) return 0; } -static void +static void chathelp(char *cmd, char *desc) { char buf[STRLEN]; @@ -154,7 +154,7 @@ chathelp(char *cmd, char *desc) printchatline(buf); } -static void +static void chat_help(char *arg) { if (strstr(arg, " op")) { @@ -185,7 +185,7 @@ chat_help(char *arg) } } -static void +static void chat_date() { char genbuf[200]; @@ -194,7 +194,7 @@ chat_date() printchatline(genbuf); } -static void +static void chat_pager() { char genbuf[200]; @@ -205,7 +205,7 @@ chat_pager() printchatline(genbuf); } -static void +static void chat_query(char *arg) { char *uid; @@ -239,7 +239,7 @@ chat_query(char *arg) printchatline(err_uid); } -static void +static void chat_users() { printchatline(""); @@ -266,7 +266,7 @@ static chat_command_t chat_cmdtbl[] = { {NULL, NULL} }; -static int +static int chat_cmd_match(char *buf, char *str) { while (*str && *buf && !isspace(*buf)) @@ -275,7 +275,7 @@ chat_cmd_match(char *buf, char *str) return 1; } -static int +static int chat_cmd(char *buf, int fd) { int i; @@ -331,7 +331,7 @@ select_address() #define MAXLASTCMD 6 static int chatid_len = 10; -int +int t_chat() { char inbuf[80], chatid[20], lastcmd[MAXLASTCMD][80], *ptr = ""; diff --git a/pttbbs/mbbsd/chc_draw.c b/pttbbs/mbbsd/chc_draw.c index 9f4091b1..8c7e556b 100644 --- a/pttbbs/mbbsd/chc_draw.c +++ b/pttbbs/mbbsd/chc_draw.c @@ -1,4 +1,4 @@ -/* $Id: chc_draw.c,v 1.3 2002/07/05 17:10:27 in2 Exp $ */ +/* $Id: chc_draw.c,v 1.4 2002/07/21 09:26:02 in2 Exp $ */ #include "bbs.h" #define SIDE_ROW 10 @@ -51,7 +51,7 @@ static char *hint_str[] = { "Enter 選擇/移動" }; -void +void chc_movecur(int r, int c) { move(r * 2 + 3, c * 4 + 4); @@ -63,7 +63,7 @@ chc_movecur(int r, int c) #define RED_REVERSE "\033[1;37;41m" #define TURN_COLOR "\033[1;33m" -static void +static void showstep(board_t board) { int turn, fc, tc, eatten; @@ -98,7 +98,7 @@ showstep(board_t board) prints("\033[m"); } -void +void chc_drawline(board_t board, int line) { int i, j; @@ -173,7 +173,7 @@ chc_drawline(board_t board, int line) } } -void +void chc_redraw(board_t board) { int i; diff --git a/pttbbs/mbbsd/chc_net.c b/pttbbs/mbbsd/chc_net.c index ba52bf26..5a8c5169 100644 --- a/pttbbs/mbbsd/chc_net.c +++ b/pttbbs/mbbsd/chc_net.c @@ -1,10 +1,10 @@ -/* $Id: chc_net.c,v 1.3 2002/07/05 17:10:27 in2 Exp $ */ +/* $Id: chc_net.c,v 1.4 2002/07/21 09:26:02 in2 Exp $ */ #include "bbs.h" typedef struct drc_t { rc_t from, to; } drc_t; -int +int chc_recvmove(int s) { drc_t buf; @@ -15,7 +15,7 @@ chc_recvmove(int s) return 0; } -void +void chc_sendmove(int s) { drc_t buf; diff --git a/pttbbs/mbbsd/chc_play.c b/pttbbs/mbbsd/chc_play.c index 53c0ceff..74a9aadb 100644 --- a/pttbbs/mbbsd/chc_play.c +++ b/pttbbs/mbbsd/chc_play.c @@ -1,4 +1,4 @@ -/* $Id: chc_play.c,v 1.5 2002/07/21 08:18:41 in2 Exp $ */ +/* $Id: chc_play.c,v 1.6 2002/07/21 09:26:02 in2 Exp $ */ #include "bbs.h" typedef int (*play_func_t) (int, board_t, board_t); @@ -13,7 +13,7 @@ static int chc_ipass = 0, chc_hepass = 0; #define MYWIN_ROW 17 #define HISWIN_ROW 18 -static int +static int hisplay(int s, board_t board, board_t tmpbrd) { int start_time; @@ -74,7 +74,7 @@ hisplay(int s, board_t board, board_t tmpbrd) return endgame; } -static int +static int myplay(int s, board_t board, board_t tmpbrd) { int ch, start_time; @@ -177,7 +177,7 @@ myplay(int s, board_t board, board_t tmpbrd) return endgame; } -static void +static void mainloop(int s, board_t board) { int endgame; @@ -215,7 +215,7 @@ mainloop(int s, board_t board) oflush(); } -static void +static void chc_init(int s, board_t board) { userinfo_t *my = currutmp; @@ -252,7 +252,7 @@ chc_init(int s, board_t board) chc_redraw(board); } -void +void chc(int s) { board_t board; diff --git a/pttbbs/mbbsd/chc_rule.c b/pttbbs/mbbsd/chc_rule.c index 62996764..df7964a1 100644 --- a/pttbbs/mbbsd/chc_rule.c +++ b/pttbbs/mbbsd/chc_rule.c @@ -1,9 +1,9 @@ -/* $Id: chc_rule.c,v 1.3 2002/07/05 17:10:27 in2 Exp $ */ +/* $Id: chc_rule.c,v 1.4 2002/07/21 09:26:02 in2 Exp $ */ #include "bbs.h" #define CENTER(a, b) (((a) + (b)) >> 1) -void +void chc_init_board(board_t board) { memset(board, 0, sizeof(board_t)); @@ -26,14 +26,14 @@ chc_init_board(board_t board) board[6][6] = board[6][8] = CHE(7, chc_my); /* 兵 */ } -void +void chc_movechess(board_t board) { board[chc_to.r][chc_to.c] = board[chc_from.r][chc_from.c]; board[chc_from.r][chc_from.c] = 0; } -static int +static int dist(rc_t from, rc_t to, int rowcol) { int d; @@ -42,7 +42,7 @@ dist(rc_t from, rc_t to, int rowcol) return d > 0 ? d : -d; } -static int +static int between(board_t board, rc_t from, rc_t to, int rowcol) { int i, rtv = 0; @@ -63,7 +63,7 @@ between(board_t board, rc_t from, rc_t to, int rowcol) return rtv; } -int +int chc_canmove(board_t board, rc_t from, rc_t to) { int i; @@ -152,7 +152,7 @@ chc_canmove(board_t board, rc_t from, rc_t to) return 1; } -static void +static void findking(board_t board, int turn, rc_t * buf) { int i, r, c; @@ -167,7 +167,7 @@ findking(board_t board, int turn, rc_t * buf) } } -int +int chc_iskfk(board_t board) { rc_t from, to; @@ -179,7 +179,7 @@ chc_iskfk(board_t board) return 0; } -int +int chc_ischeck(board_t board, int turn) { rc_t from, to; diff --git a/pttbbs/mbbsd/chicken.c b/pttbbs/mbbsd/chicken.c index f9420a43..e42a2a5a 100644 --- a/pttbbs/mbbsd/chicken.c +++ b/pttbbs/mbbsd/chicken.c @@ -1,4 +1,4 @@ -/* $Id: chicken.c,v 1.7 2002/07/21 08:18:41 in2 Exp $ */ +/* $Id: chicken.c,v 1.8 2002/07/21 09:26:02 in2 Exp $ */ #include "bbs.h" #define NUM_KINDS 13 /* 有多少種動物 */ @@ -79,7 +79,7 @@ static const int time_change[NUM_KINDS][14] = {1, 1, 147, 2, 10, 10, 85, 20, 4, 25, 25, 5, 145, 95} }; -int +int reload_chicken() { passwd_query(usernum, &xuser); @@ -92,7 +92,7 @@ reload_chicken() #define CHICKENLOG "etc/chicken" -static int +static int new_chicken() { char buf[150]; @@ -151,7 +151,7 @@ new_chicken() return 1; } -int +int show_file(char *filename, int y, int lines, int mode) { FILE *fp; @@ -169,7 +169,7 @@ show_file(char *filename, int y, int lines, int mode) return 1; } -static void +static void show_chicken_stat(chicken_t * thechicken) { struct tm *ptime; @@ -202,7 +202,7 @@ show_chicken_stat(chicken_t * thechicken) #define CHICKEN_PIC "etc/chickens" -void +void show_chicken_data(chicken_t * thechicken, chicken_t * pkchicken) { char buf[1024]; @@ -271,7 +271,7 @@ show_chicken_data(chicken_t * thechicken, chicken_t * pkchicken) } } -static void +static void ch_eat() { if (mychicken->food) { @@ -290,7 +290,7 @@ ch_eat() } } -static void +static void ch_clean() { mychicken->clean = 0; @@ -300,7 +300,7 @@ ch_clean() pressanykey(); } -static void +static void ch_guess() { char *guess[3] = {"剪刀", "石頭", "布"}, me, ch, win; @@ -325,7 +325,7 @@ ch_guess() pressanykey(); } -static void +static void ch_book() { mychicken->book += time_change[(int)mychicken->type][BOOK]; @@ -334,7 +334,7 @@ ch_book() pressanykey(); } -static void +static void ch_kiss() { mychicken->happy += time_change[(int)mychicken->type][HAPPY]; @@ -345,7 +345,7 @@ ch_kiss() pressanykey(); } -static void +static void ch_hit() { mychicken->attack += time_change[(int)mychicken->type][ATTACK]; @@ -366,7 +366,7 @@ ch_hit() pressanykey(); } -void +void ch_buyitem(int money, char *picture, int *item) { int num = 0; @@ -390,7 +390,7 @@ ch_buyitem(int money, char *picture, int *item) pressanykey(); } -static void +static void ch_eatoo() { if (mychicken->oo > 0) { @@ -403,7 +403,7 @@ ch_eatoo() } } -static void +static void ch_eatmedicine() { if (mychicken->medicine > 0) { @@ -419,7 +419,7 @@ ch_eatmedicine() } } -static void +static void ch_kill() { char buf[150], ans[4]; @@ -439,7 +439,7 @@ ch_kill() } } -static int +static int ch_sell() { /* @@ -503,7 +503,7 @@ ch_sell() return 0; } -static void +static void geting_old(int *hp, int *weight, int diff, int age) { float ex = 0.9; @@ -523,7 +523,7 @@ geting_old(int *hp, int *weight, int diff, int age) } /* 依時間變動的資料 */ -void +void time_diff(chicken_t * thechicken) { int diff; @@ -607,7 +607,7 @@ time_diff(chicken_t * thechicken) thechicken->mm = thechicken->mm_max; } -static void +static void check_sick() { /* 髒病的 */ @@ -624,7 +624,7 @@ check_sick() } } -static int +static int deadtype(chicken_t * thechicken) { int i; @@ -657,7 +657,7 @@ deadtype(chicken_t * thechicken) return i; } -int +int showdeadth(int type) { switch (type) { @@ -683,7 +683,7 @@ showdeadth(int type) return type; } -int +int isdeadth(chicken_t * thechicken) { int i; @@ -693,7 +693,7 @@ isdeadth(chicken_t * thechicken) return showdeadth(i); } -static void +static void ch_changename() { char buf[150], newname[20] = ""; @@ -712,7 +712,7 @@ ch_changename() } } -static int +static int select_menu() { char ch; @@ -800,7 +800,7 @@ select_menu() return 1; } -static int +static int recover_chicken(chicken_t * thechicken) { char buf[200]; @@ -853,7 +853,7 @@ recover_chicken(chicken_t * thechicken) #define lockreturn0(unmode, state) if(lockutmpmode(unmode, state)) return 0 -int +int chicken_main() { lockreturn0(CHICKEN, LOCK_MULTI); @@ -876,7 +876,7 @@ chicken_main() return 0; } -int +int chickenpk(int fd) { char mateid[IDLEN + 1], data[200], buf[200]; diff --git a/pttbbs/mbbsd/dark.c b/pttbbs/mbbsd/dark.c index f464bf11..cd37fd0b 100644 --- a/pttbbs/mbbsd/dark.c +++ b/pttbbs/mbbsd/dark.c @@ -1,4 +1,4 @@ -/* $Id: dark.c,v 1.6 2002/07/21 08:18:41 in2 Exp $ */ +/* $Id: dark.c,v 1.7 2002/07/21 09:26:02 in2 Exp $ */ #include "bbs.h" #define RED 1 @@ -21,11 +21,10 @@ static char *bname[] = {" static sint cury[] = {3, 5, 7, 9}, curx[] = {5, 9, 13, 17, 21, 25, 29, 33}; static sint rcount, bcount, cont, fix; /* cont:是否可連吃 */ -static sint my = 0, mx = 0, mly = -1, mlx = -1; /* 移動的座標 - * 標 */ +static sint my = 0, mx = 0, mly = -1, mlx = -1; /* 移動的座標 標 */ static sint cur_eaty, cur_eatx; /* 吃掉對方其子的秀出座標 */ -static void +static void brdswap(sint y, sint x, sint ly, sint lx) { memcpy(&brd[y][x], &brd[ly][lx], sizeof(item)); @@ -34,7 +33,7 @@ brdswap(sint y, sint x, sint ly, sint lx) brd[ly][lx].value = -1; } -static void +static void pprints(sint y, sint x, char *s) { move(y, x); @@ -42,7 +41,7 @@ pprints(sint y, sint x, char *s) prints("%s", s); } -static sint +static sint Is_win(item att, item det, sint y, sint x, sint ly, sint lx) { sint i, c = 0, min, max; @@ -95,7 +94,7 @@ Is_win(item att, item det, sint y, sint x, sint ly, sint lx) return 0; } -static sint +static sint Is_move(sint y, sint x, sint ly, sint lx) { if (brd[y][x].die == 1 && ((abs(ly - y) == 1 && x == lx) || (abs(lx - x) == 1 && ly == y))) @@ -103,7 +102,7 @@ Is_move(sint y, sint x, sint ly, sint lx) return 0; } -static void +static void brd_rand() { sint y, x, index; @@ -128,7 +127,7 @@ brd_rand() } } -static void +static void brd_prints() { clear(); @@ -146,7 +145,7 @@ brd_prints() " "); } -static void +static void draw_line(sint y, sint f) { sint i; @@ -175,7 +174,7 @@ draw_line(sint y, sint f) prints("%s", buf); } -static void +static void redraw() { sint i = 0; @@ -183,7 +182,7 @@ redraw() draw_line(i, -1); } -static sint +static sint playing(sint fd, sint color, sint ch, sint * b, userinfo_t * uin) { curr.end = 0; @@ -354,7 +353,7 @@ playing(sint fd, sint color, sint ch, sint * b, userinfo_t * uin) return 0; } -int +int main_dark(int fd, userinfo_t * uin) { sint end = 0, ch = 1, go_on, i = 0, cont = 0; @@ -362,8 +361,8 @@ main_dark(int fd, userinfo_t * uin) *buf = 0; fix = 0; currutmp->color = '.'; - //'.' 磳僋晲S M w C - rcount = 16; + /* '.' 表示還沒決定顏色 */ + rcount = 16; bcount = 16; //initialize cur_eaty = 18, cur_eatx = 5; diff --git a/pttbbs/mbbsd/descrypt.c b/pttbbs/mbbsd/descrypt.c index ede4f9f3..30d33b8b 100644 --- a/pttbbs/mbbsd/descrypt.c +++ b/pttbbs/mbbsd/descrypt.c @@ -1,4 +1,4 @@ -/* $Id: descrypt.c,v 1.3 2002/07/05 17:10:27 in2 Exp $ */ +/* $Id: descrypt.c,v 1.4 2002/07/21 09:26:02 in2 Exp $ */ /* * FreeSec: libcrypt for NetBSD @@ -185,7 +185,7 @@ static unsigned char ascii64[] = /* 0000000000111111111122222222223333333333444444444455555555556666 */ /* 0123456789012345678901234567890123456789012345678901234567890123 */ -static int +static int ascii_to_bin(char ch) { if (ch > 'z') @@ -203,7 +203,7 @@ ascii_to_bin(char ch) return 0; } -static void +static void des_init() { int i, j, b, k, inbit, obit; @@ -333,7 +333,7 @@ des_init() des_initialised = 1; } -static void +static void setup_salt(long salt) { unsigned long obit, saltbit; @@ -354,7 +354,7 @@ setup_salt(long salt) } } -static int +static int des_setkey(const char *key) { unsigned long k0, k1, rawkey0, rawkey1; @@ -433,7 +433,7 @@ des_setkey(const char *key) return 0; } -static int +static int do_des(unsigned long l_in, unsigned long r_in, unsigned long *l_out, unsigned long *r_out, int count) { diff --git a/pttbbs/mbbsd/dice.c b/pttbbs/mbbsd/dice.c index 62aeba16..69d7486f 100644 --- a/pttbbs/mbbsd/dice.c +++ b/pttbbs/mbbsd/dice.c @@ -1,4 +1,4 @@ -/* $Id: dice.c,v 1.4 2002/07/05 17:10:27 in2 Exp $ */ +/* $Id: dice.c,v 1.5 2002/07/21 09:26:02 in2 Exp $ */ #include "bbs.h" #define DICE_TXT BBSHOME "/etc/dice.txt" @@ -19,7 +19,7 @@ typedef struct dicedata_t { int mymoney; } dicedata_t; -static void +static void set_bingo(int bet[]) { int i, j = 0, k = 0, m = 0; @@ -64,13 +64,13 @@ set_bingo(int bet[]) } } -static int +static int bingo(int mybet) { return flag[mybet]; } -int +int IsNum(char *a, int n) { int i; @@ -81,7 +81,7 @@ IsNum(char *a, int n) return 1; } -int +int IsSNum(char *a) { int i; @@ -92,7 +92,7 @@ IsSNum(char *a) return 1; } -static void +static void show_data(void) { move(0, 0); @@ -122,7 +122,7 @@ show_data(void) "─────────┘\033[m\n"); } -static void +static void show_count(int index, int money) { int i = 0, count = 2, j, k; @@ -164,7 +164,7 @@ show_count(int index, int money) prints("[83]:%d", value[83]); } -static int +static int check_index(int index) { int i, tp[] = {1, 2, 3, 4, 5, 6, 7, 8, 11, 12, 13, 14, 15, 16, 23, 24, 25, @@ -177,7 +177,7 @@ check_index(int index) return 0; } -static int +static int del(int total, dicedata_t * table) { int index, money; @@ -220,7 +220,7 @@ del(int total, dicedata_t * table) return 0; } -static int +static int IsLegal(char *data) { int money = atoi(data); @@ -229,7 +229,7 @@ IsLegal(char *data) return 0; } -static void +static void show_output(int bet[]) { int i, j = 10; @@ -326,7 +326,7 @@ show_output(int bet[]) #define lockreturn0(unmode, state) if(lockutmpmode(unmode, state)) return 0 -int +int dice_main(void) { char input[10], data[256], ch; diff --git a/pttbbs/mbbsd/edit.c b/pttbbs/mbbsd/edit.c index d7680380..212f893b 100644 --- a/pttbbs/mbbsd/edit.c +++ b/pttbbs/mbbsd/edit.c @@ -1,4 +1,4 @@ -/* $Id: edit.c,v 1.13 2002/07/21 08:18:41 in2 Exp $ */ +/* $Id: edit.c,v 1.14 2002/07/21 09:26:02 in2 Exp $ */ #include "bbs.h" typedef struct textline_t { struct textline_t *prev; @@ -42,14 +42,14 @@ static int insert_c = ' '; static char fp_bak[] = "bak"; /* 記憶體管理與編輯處理 */ -static void +static void indigestion(i) { fprintf(stderr, "嚴重內傷 %d\n", i); } /* Thor: ansi 座標轉換 for color 編輯模式 */ -static int +static int ansi2n(int ansix, textline_t * line) { register char *data, *tmp; @@ -73,7 +73,7 @@ ansi2n(int ansix, textline_t * line) return tmp - data; } -static int +static int n2ansi(int nx, textline_t * line) { register int ansix = 0; @@ -100,7 +100,7 @@ n2ansi(int nx, textline_t * line) } /* 螢幕處理:輔助訊息、顯示編輯內容 */ -static void +static void edit_msg() { static char *edit_mode[2] = {"取代", "插入"}; @@ -149,7 +149,7 @@ forward_line(textline_t * pos, int num) return pos; } -static int +static int getlineno() { int cnt = 0; @@ -185,7 +185,7 @@ alloc_line() } /* append p after line in list. keeps up with last line */ -static void +static void append(textline_t * p, textline_t * line) { register textline_t *n; @@ -203,7 +203,7 @@ append(textline_t * p, textline_t * line) * firstline pointers. */ -static void +static void delete_line(textline_t * line) { register textline_t *p = line->prev; @@ -227,7 +227,7 @@ delete_line(textline_t * line) totaln--; } -static int +static int ask(char *prompt) { int ch; @@ -243,7 +243,7 @@ ask(char *prompt) return (ch); } -static int +static int indent_spcs() { textline_t *p; @@ -261,7 +261,7 @@ indent_spcs() } /* split 'line' right before the character pos */ -static void +static void split(textline_t * line, int pos) { if (pos <= line->len) { @@ -292,7 +292,7 @@ split(textline_t * line, int pos) } } -static void +static void insert_char(int ch) { register textline_t *p = currline; @@ -340,7 +340,7 @@ insert_char(int ch) } } -static void +static void insert_string(char *str) { int ch; @@ -357,7 +357,7 @@ insert_string(char *str) } } -static int +static int undelete_line() { textline_t *p = deleted_lines; @@ -389,7 +389,7 @@ undelete_line() * 1) lines were joined and one was deleted 2) lines could not be joined 3) * next line is empty returns false if: 1) Some of the joined line wrapped */ -static int +static int join(textline_t * line) { register textline_t *n; @@ -435,7 +435,7 @@ join(textline_t * line) } } -static void +static void delete_char() { register int len; @@ -454,7 +454,7 @@ delete_char() } } -static void +static void load_file(FILE * fp) { int indent_mode0 = indent_mode; @@ -481,7 +481,7 @@ ask_tmpbuf(int y) return fp_buf; } -static void +static void read_tmpbuf(int n) { FILE *fp; @@ -512,7 +512,7 @@ read_tmpbuf(int n) } } -static void +static void write_tmpbuf() { FILE *fp; @@ -537,7 +537,7 @@ write_tmpbuf() } } -static void +static void erase_tmpbuf() { char fp_tmpbuf[80]; @@ -552,7 +552,7 @@ erase_tmpbuf() } /* 編輯器自動備份 */ -void +void auto_backup() { if (currline) { @@ -574,7 +574,7 @@ auto_backup() } } -void +void restore_backup() { char bakfile[80], buf[80]; @@ -593,7 +593,7 @@ restore_backup() } /* 引用文章 */ -static int +static int garbage_line(char *str) { int qlevel = 0; @@ -614,7 +614,7 @@ garbage_line(char *str) return (*str == '\n'); } -static void +static void do_quote() { int op; @@ -688,7 +688,7 @@ do_quote() } /* 審查 user 引言的使用 */ -static int +static int check_quote() { register textline_t *p = firstline; @@ -729,7 +729,7 @@ check_quote() } /* 檔案處理:讀檔、存檔、標題、簽名檔 */ -static void +static void read_file(char *fpath) { FILE *fp; @@ -745,7 +745,7 @@ read_file(char *fpath) load_file(fp); } -void +void write_header(FILE * fp) { @@ -833,7 +833,7 @@ write_header(FILE * fp) fprintf(fp, "標題: %s\n時間: %s\n", save_title, ctime(&now)); } -void +void addsignature(FILE * fp, int ifuseanony) { FILE *fs; @@ -1034,7 +1034,7 @@ write_file(char *fpath, int saveheader, int *islocal) } -static void +static void display_buffer() { register textline_t *p; @@ -1100,7 +1100,7 @@ display_buffer() edit_msg(); } -static void +static void goto_line(int lino) { char buf[10]; @@ -1158,7 +1158,7 @@ strcasestr(const char *big, const char *little) /* * mode: 0: prompt 1: forward -1: backward */ -static void +static void search_str(int mode) { static char str[65]; @@ -1218,7 +1218,7 @@ search_str(int mode) redraw_everything = YEA; } -static void +static void match_paren() { static char parens[] = "()[]{}"; @@ -1339,7 +1339,7 @@ p_outscan: } } -static void +static void block_del(int hide) { if (blockln < 0) { @@ -1471,7 +1471,7 @@ block_del(int hide) } } -static void +static void block_shift_left() { textline_t *begin, *end, *p; @@ -1499,7 +1499,7 @@ block_shift_left() redraw_everything = YEA; } -static void +static void block_shift_right() { textline_t *begin, *end, *p; @@ -1531,7 +1531,7 @@ block_shift_right() redraw_everything = YEA; } -static void +static void transform_to_color(char *line) { while (line[0] && line[1]) @@ -1542,7 +1542,7 @@ transform_to_color(char *line) ++line; } -static void +static void block_color() { textline_t *begin, *end, *p; @@ -1566,7 +1566,7 @@ block_color() } /* 編輯處理:主程式、鍵盤處理 */ -int +int vedit(char *fpath, int saveheader, int *islocal) { FILE *fp1; diff --git a/pttbbs/mbbsd/friend.c b/pttbbs/mbbsd/friend.c index 2753282c..6029bfd8 100644 --- a/pttbbs/mbbsd/friend.c +++ b/pttbbs/mbbsd/friend.c @@ -1,4 +1,4 @@ -/* $Id: friend.c,v 1.10 2002/07/21 08:18:41 in2 Exp $ */ +/* $Id: friend.c,v 1.11 2002/07/21 09:26:02 in2 Exp $ */ #include "bbs.h" /* ------------------------------------- */ @@ -47,7 +47,7 @@ static char *friend_list[8] = { "看板好友名單" }; -static void +static void setfriendfile(char *fpath, int type) { if (type <= 4) /* user list Ptt */ @@ -56,7 +56,7 @@ setfriendfile(char *fpath, int type) setbfile(fpath, currboard, friend_file[type]); } -static int +static int friend_count(char *fname) { FILE *fp; @@ -78,7 +78,7 @@ friend_count(char *fname) return count; } -void +void friend_add(char *uident, int type) { char fpath[80]; @@ -107,7 +107,7 @@ friend_add(char *uident, int type) } } -static void +static void friend_special() { char genbuf[70], i, fname[70]; @@ -138,7 +138,7 @@ friend_special() } } -static void +static void friend_append(int type, int count) { char fpath[80], i, j, buf[80], sfile[80]; @@ -201,7 +201,7 @@ friend_append(int type, int count) } } -void +void friend_delete(char *uident, int type) { FILE *fp, *nfp; @@ -223,7 +223,7 @@ friend_delete(char *uident, int type) } } -static void +static void friend_editdesc(char *uident, int type) { FILE *fp, *nfp; @@ -248,7 +248,7 @@ friend_editdesc(char *uident, int type) } } -void +void friend_load() { FILE *fp; @@ -289,7 +289,7 @@ friend_load() login_friend_online(); } -static void +static void friend_water(char *message, int type) { /* 群體水球 added by Ptt */ char fpath[80], line[80], userid[IDLEN + 1]; @@ -310,7 +310,7 @@ friend_water(char *message, int type) fclose(fp); } -void +void friend_edit(int type) { char fpath[80], line[80], uident[20]; @@ -444,14 +444,14 @@ friend_edit(int type) } } -int +int t_override() { friend_edit(FRIEND_OVERRIDE); return 0; } -int +int t_reject() { friend_edit(FRIEND_REJECT); diff --git a/pttbbs/mbbsd/gamble.c b/pttbbs/mbbsd/gamble.c index 1fa62e13..97961898 100644 --- a/pttbbs/mbbsd/gamble.c +++ b/pttbbs/mbbsd/gamble.c @@ -1,4 +1,4 @@ -/* $Id: gamble.c,v 1.26 2002/07/21 08:18:41 in2 Exp $ */ +/* $Id: gamble.c,v 1.27 2002/07/21 09:26:02 in2 Exp $ */ #include "bbs.h" #ifndef _BBS_UTIL_C_ @@ -9,7 +9,7 @@ static char betname[MAX_ITEM][MAX_ITEM_LEN]; static int currbid; -int +int post_msg(char *bname, char *title, char *msg, char *author) { FILE *fp; @@ -42,7 +42,7 @@ post_msg(char *bname, char *title, char *msg, char *author) return 0; } -int +int post_file(char *bname, char *title, char *filename, char *author) { int size = dashs(filename); @@ -63,7 +63,7 @@ post_file(char *bname, char *title, char *filename, char *author) } -static int +static int load_ticket_record(char *direct, int ticket[]) { char buf[256]; @@ -78,7 +78,7 @@ load_ticket_record(char *direct, int ticket[]) return total; } -static int +static int show_ticket_data(char *direct, int *price, boardheader_t * bh) { int i, count, total = 0, end = 0, ticket[MAX_ITEM] = {0, 0, 0, 0, 0, 0, 0, 0}; @@ -89,7 +89,7 @@ show_ticket_data(char *direct, int *price, boardheader_t * bh) if (bh) { sprintf(genbuf, "%s 賭盤", bh->brdname); if (bh->endgamble && now < bh->endgamble && bh->endgamble - now < 3600) { - sprintf(t, "封盤倒數 %d 秒", bh->endgamble - now); + sprintf(t, "封盤倒數 %d 秒", (int)(bh->endgamble - now)); showtitle(genbuf, t); } else showtitle(genbuf, BBSNAME); @@ -146,7 +146,7 @@ show_ticket_data(char *direct, int *price, boardheader_t * bh) return count; } -static void +static void append_ticket_record(char *direct, int ch, int n, int count) { FILE *fp; @@ -169,7 +169,7 @@ append_ticket_record(char *direct, int ch, int n, int count) } #define lockreturn0(unmode, state) if(lockutmpmode(unmode, state)) return 0 -int +int ticket(int bid) { int ch, n, price, count, end = 0; @@ -223,7 +223,7 @@ ticket(int bid) return 0; } -int +int openticket(int bid) { char path[128], buf[256], outcome[128]; @@ -256,8 +256,8 @@ openticket(int bid) } while (bet != atoi(buf)); if (fork()) { - //Ptt 姱ork 黎謅ㄔ膨`斷 u ~錢 - move(22, 0); + /* Ptt: 用 fork() 防止不正常斷線洗錢 */ + move(22, 0); prints("系統將於稍後自動把中獎結果公佈於看板 若參加者多會需要幾分鐘時間.."); pressanykey(); unlockutmpmode(); @@ -376,7 +376,7 @@ openticket(int bid) return 0; } -int +int ticket_main() { ticket(0); diff --git a/pttbbs/mbbsd/gomo.c b/pttbbs/mbbsd/gomo.c index 49a1694a..c6870e3f 100644 --- a/pttbbs/mbbsd/gomo.c +++ b/pttbbs/mbbsd/gomo.c @@ -1,4 +1,4 @@ -/* $Id: gomo.c,v 1.7 2002/07/21 08:18:41 in2 Exp $ */ +/* $Id: gomo.c,v 1.8 2002/07/21 09:26:02 in2 Exp $ */ #include "bbs.h" static char *chess[] = {"●", "○"}; @@ -11,7 +11,7 @@ typedef struct { static Horder_t *v, pool[225]; -static void +static void HO_init() { memset(pool, 0, sizeof(pool)); @@ -21,13 +21,13 @@ HO_init() memset(ku, 0, sizeof(ku)); } -static void +static void HO_add(Horder_t * mv) { *v++ = *mv; } -static void +static void HO_undo(Horder_t * mv) { char *str = "┌┬┐├┼┤└┴┘"; @@ -42,7 +42,7 @@ HO_undo(Horder_t * mv) prints("%.2s", str + loc); } -static void +static void HO_log(char *user) { int i; @@ -82,7 +82,7 @@ HO_log(char *user) unlink(buf); } -static int +static int countgomo() { Horder_t *ptr; @@ -96,7 +96,7 @@ countgomo() return i; } -static int +static int chkmv(Horder_t * mv, int color, int limit) { char *xtype[] = {"\033[1;31m跳三\033[m", "\033[1;31m活三\033[m", @@ -114,7 +114,7 @@ chkmv(Horder_t * mv, int color, int limit) return chkwin(rule, limit); } -static int +static int gomo_key(int fd, int ch, Horder_t * mv) { if (ch >= 'a' && ch <= 'o') { @@ -157,7 +157,7 @@ gomo_key(int fd, int ch, Horder_t * mv) return 0; } -static int +static int reload_gomo() { passwd_query(usernum, &xuser); @@ -167,7 +167,7 @@ reload_gomo() return 0; } -int +int gomoku(int fd) { Horder_t mv; diff --git a/pttbbs/mbbsd/gomo1.c b/pttbbs/mbbsd/gomo1.c index 462ceb47..260ce88f 100644 --- a/pttbbs/mbbsd/gomo1.c +++ b/pttbbs/mbbsd/gomo1.c @@ -1,18 +1,18 @@ -/* $Id: gomo1.c,v 1.3 2002/07/05 17:10:27 in2 Exp $ */ +/* $Id: gomo1.c,v 1.4 2002/07/21 09:26:02 in2 Exp $ */ #include "bbs.h" #define QCAST int (*)(const void *, const void *) /* pattern and advance map */ -static int +static int intrevcmp(const void *a, const void *b) { return (*(int *)b - *(int *)a); } /* x,y: 0..BRDSIZ-1 ; color: CBLACK,CWHITE ; dx,dy: -1,0,+1 */ -static int +static int gomo_getindex(int x, int y, int color, int dx, int dy) { int i, k, n; @@ -36,7 +36,7 @@ gomo_getindex(int x, int y, int color, int dx, int dy) return n; } -int +int chkwin(int style, int limit) { if (style == 0x0c) @@ -52,7 +52,7 @@ chkwin(int style, int limit) } /* x,y: 0..BRDSIZ-1 ; color: CBLACK,CWHITE ; limit:1,0 ; dx,dy: 0,1 */ -static int +static int dirchk(int x, int y, int color, int limit, int dx, int dy) { int le, ri, loc, style = 0; @@ -100,7 +100,7 @@ dirchk(int x, int y, int color, int limit, int dx, int dy) /* 四三=7 活四=6 斷四=5 死四=4 活三=3 斷三=2 保留=1 無效=0 */ /* x,y: 0..BRDSIZ-1 ; color: CBLACK,CWHITE ; limit: 1,0 */ -int +int getstyle(int x, int y, int color, int limit) { int i, j, dir[4], style; diff --git a/pttbbs/mbbsd/guess.c b/pttbbs/mbbsd/guess.c index 1f683ce2..654f45dc 100644 --- a/pttbbs/mbbsd/guess.c +++ b/pttbbs/mbbsd/guess.c @@ -1,8 +1,8 @@ -/* $Id: guess.c,v 1.4 2002/07/05 17:10:27 in2 Exp $ */ +/* $Id: guess.c,v 1.5 2002/07/21 09:26:02 in2 Exp $ */ #include "bbs.h" #define LOGPASS BBSHOME "/etc/winguess.log" -static void +static void show_table(char TABLE[], char ifcomputer) { int i; @@ -22,7 +22,7 @@ show_table(char TABLE[], char ifcomputer) prints("\033[33m=================\033[m"); } -static unsigned long int +static unsigned long int get_money(void) { int money, i; @@ -57,7 +57,7 @@ get_money(void) return money; } -static int +static int check_data(char *str) { int i, j; @@ -86,7 +86,7 @@ get_data(int count) return data; } -static int +static int guess_play(char *data, char *answer, int count) { int A_num = 0, B_num = 0; @@ -110,7 +110,7 @@ guess_play(char *data, char *answer, int count) return 0; } -static int +static int result(int correct, int number) { char a = 0, b = 0, i, j; @@ -130,7 +130,7 @@ result(int correct, int number) return 10 * a + b; } -static int +static int legal(int number) { char i, j; @@ -144,7 +144,7 @@ legal(int number) return 1; } -static void +static void initcomputer(char flag[]) { int i; @@ -156,7 +156,7 @@ initcomputer(char flag[]) flag[i] = 0; } -static int +static int computer(int correct, int total, char flag[], int n[]) { int guess; @@ -192,7 +192,7 @@ computer(int correct, int total, char flag[], int n[]) return 0; } -static void +static void Diff_Random(char *answer) { register int i = 0, j, k; @@ -212,7 +212,7 @@ Diff_Random(char *answer) #define lockreturn0(unmode, state) if(lockutmpmode(unmode, state)) return 0 -int +int guess_main() { unsigned long int money; diff --git a/pttbbs/mbbsd/indict.c b/pttbbs/mbbsd/indict.c index 6e44c612..13030880 100644 --- a/pttbbs/mbbsd/indict.c +++ b/pttbbs/mbbsd/indict.c @@ -1,9 +1,9 @@ -/* $Id: indict.c,v 1.6 2002/07/21 08:18:41 in2 Exp $ */ +/* $Id: indict.c,v 1.7 2002/07/21 09:26:02 in2 Exp $ */ #include "bbs.h" #define REFER "etc/dicts" -static void +static void addword(char word[]) { char buf[150], temp[150], a[3]; @@ -33,7 +33,7 @@ addword(char word[]) clear(); } -static int +static int choose_dict(void) { int c; @@ -80,7 +80,7 @@ lower(char str[]) return temp; } -int +int use_dict() { FILE *fp; @@ -177,7 +177,7 @@ use_dict() } } -int +int x_dict() { if (choose_dict()) diff --git a/pttbbs/mbbsd/io.c b/pttbbs/mbbsd/io.c index 29516595..f4fd4b28 100644 --- a/pttbbs/mbbsd/io.c +++ b/pttbbs/mbbsd/io.c @@ -1,4 +1,4 @@ -/* $Id: io.c,v 1.19 2002/07/21 08:18:41 in2 Exp $ */ +/* $Id: io.c,v 1.20 2002/07/21 09:26:02 in2 Exp $ */ #include "bbs.h" #if defined(linux) @@ -17,7 +17,7 @@ static int icurrchar = 0; /* output routines */ /* ----------------------------------------------------- */ -void +void oflush() { if (obufsize) { @@ -26,13 +26,13 @@ oflush() } } -void +void init_buf() { memset(inbuf, 0, IBUFSIZE); } -void +void output(char *s, int len) { /* Invalid if len >= OBUFSIZE */ @@ -45,7 +45,7 @@ output(char *s, int len) obufsize += len; } -int +int ochar(int c) { if (obufsize > OBUFSIZE - 1) { @@ -64,7 +64,7 @@ static int i_newfd = 0; static struct timeval i_to, *i_top = NULL; static int (*flushf) () = NULL; -void +void add_io(int fd, int timeout) { i_newfd = fd; @@ -77,7 +77,7 @@ add_io(int fd, int timeout) i_top = NULL; } -int +int num_in_buf() { return icurrchar - ibufsize; @@ -89,7 +89,7 @@ num_in_buf() * be inconsistent. We try to not segfault here... */ -static int +static int dogetch() { int len; @@ -147,7 +147,7 @@ dogetch() } static int water_which_flag = 0; -int +int igetch() { register int ch; @@ -301,7 +301,7 @@ igetch() return 0; } -int +int oldgetdata(int line, int col, char *prompt, char *buf, int len, int echo) { register int ch, i; @@ -481,7 +481,7 @@ oldgetdata(int line, int col, char *prompt, char *buf, int len, int echo) } /* Ptt */ -int +int getdata_buf(int line, int col, char *prompt, char *buf, int len, int echo) { return oldgetdata(line, col, prompt, buf, len, echo); @@ -496,7 +496,7 @@ getans(char *prompt) return ans[0]; } -int +int getdata_str(int line, int col, char *prompt, char *buf, int len, int echo, char *defaultstr) { strncpy(buf, defaultstr, len); @@ -505,7 +505,7 @@ getdata_str(int line, int col, char *prompt, char *buf, int len, int echo, char return oldgetdata(line, col, prompt, buf, len, echo); } -int +int getdata(int line, int col, char *prompt, char *buf, int len, int echo) { buf[0] = 0; @@ -530,7 +530,7 @@ rget(int x, char *prompt) } -int +int igetkey() { int mode; diff --git a/pttbbs/mbbsd/kaede.c b/pttbbs/mbbsd/kaede.c index e1ccd1b5..252984be 100644 --- a/pttbbs/mbbsd/kaede.c +++ b/pttbbs/mbbsd/kaede.c @@ -1,4 +1,4 @@ -/* $Id: kaede.c,v 1.9 2002/07/20 13:40:12 in2 Exp $ */ +/* $Id: kaede.c,v 1.10 2002/07/21 09:26:02 in2 Exp $ */ #include "bbs.h" char * @@ -55,7 +55,7 @@ Ptt_prints(char *str, int mode) return str; } -int +int Rename(char *src, char *dst) { char buf[256]; @@ -70,7 +70,7 @@ Rename(char *src, char *dst) return -1; } -int +int Link(char *src, char *dst) { char cmd[200]; diff --git a/pttbbs/mbbsd/lovepaper.c b/pttbbs/mbbsd/lovepaper.c index 1bd4a125..0ab78aa4 100644 --- a/pttbbs/mbbsd/lovepaper.c +++ b/pttbbs/mbbsd/lovepaper.c @@ -1,8 +1,8 @@ -/* $Id: lovepaper.c,v 1.8 2002/07/21 08:18:41 in2 Exp $ */ +/* $Id: lovepaper.c,v 1.9 2002/07/21 09:26:02 in2 Exp $ */ #include "bbs.h" #define DATA "etc/lovepaper.dat" -int +int x_love() { char buf1[200], save_title[TTLEN + 1]; diff --git a/pttbbs/mbbsd/mail.c b/pttbbs/mbbsd/mail.c index f8b1ebe3..d5426163 100644 --- a/pttbbs/mbbsd/mail.c +++ b/pttbbs/mbbsd/mail.c @@ -1,4 +1,4 @@ -/* $Id: mail.c,v 1.20 2002/07/21 08:18:41 in2 Exp $ */ +/* $Id: mail.c,v 1.21 2002/07/21 09:26:02 in2 Exp $ */ #include "bbs.h" char currmaildir[32]; static char msg_cc[] = "\033[32m[群組名單]\033[m\n"; @@ -6,7 +6,7 @@ static char listfile[] = "list.0"; static int mailkeep = 0, mailsum = 0; static int mailsumlimit = 0, mailmaxkeep = 0; -int +int setforward() { char buf[80], ip[50] = "", yn[4]; @@ -41,7 +41,7 @@ setforward() return 0; } -int +int built_mail_index() { char genbuf[128]; @@ -61,7 +61,7 @@ built_mail_index() return 0; } -int +int mailalert(char *userid) { userinfo_t *uentp = NULL; @@ -77,14 +77,14 @@ mailalert(char *userid) return 0; } -int +int mail_muser(userec_t muser, char *title, char *filename) { return mail_id(muser.userid, title, filename, cuser.userid); } /* Heat: 用id來寄信,內容則link準備好的檔案 */ -int +int mail_id(char *id, char *title, char *filename, char *owner) { fileheader_t mhdr; @@ -102,7 +102,7 @@ mail_id(char *id, char *title, char *filename, char *owner) return 0; } -int +int invalidaddr(char *addr) { if (*addr == '\0') @@ -115,7 +115,7 @@ invalidaddr(char *addr) return 0; } -int +int m_internet() { char receiver[60]; @@ -132,13 +132,13 @@ m_internet() return 0; } -void +void m_init() { sethomedir(currmaildir, cuser.userid); } -int +int chkmailbox() { if (!HAVE_PERM(PERM_SYSOP) && !HAVE_PERM(PERM_MAILLIMIT)) { @@ -185,7 +185,7 @@ chkmailbox() return 0; } -static void +static void do_hold_mail(char *fpath, char *receiver, char *holder) { char buf[80], title[128]; @@ -211,7 +211,7 @@ do_hold_mail(char *fpath, char *receiver, char *holder) do_append(title, &mymail, sizeof(mymail)); } -void +void hold_mail(char *fpath, char *receiver) { char buf[4]; @@ -223,7 +223,7 @@ hold_mail(char *fpath, char *receiver) do_hold_mail(fpath, receiver, cuser.userid); } -int +int do_send(char *userid, char *title) { fileheader_t mhdr; @@ -297,8 +297,7 @@ do_send(char *userid, char *title) i = belong(fpath, cuser.userid); sethomefile(fpath, userid, FN_REJECT); - if (i || !belong(fpath, cuser.userid)) /* Ptt: 用belong有點討厭 */ - { + if (i || !belong(fpath, cuser.userid)) { /* Ptt: 用belong有點討厭 */ sethomedir(fpath, userid); if (append_record(fpath, &mhdr, sizeof(mhdr)) == -1) return -1; @@ -309,7 +308,7 @@ do_send(char *userid, char *title) } } -void +void my_send(char *uident) { switch (do_send(uident, NULL)) { @@ -326,7 +325,7 @@ my_send(char *uident) pressanykey(); } -int +int m_send() { char uident[40]; @@ -340,7 +339,7 @@ m_send() } /* 群組寄信、回信 : multi_send, multi_reply */ -static void +static void multi_list(int *reciper) { char uid[16]; @@ -418,7 +417,7 @@ multi_list(int *reciper) } } -static void +static void multi_send(char *title) { FILE *fp; @@ -536,7 +535,7 @@ multi_send(char *title) pressanykey(); } -static int +static int multi_reply(int ent, fileheader_t * fhdr, char *direct) { if (!(fhdr->filemode & FILE_MULTI)) @@ -549,7 +548,7 @@ multi_reply(int ent, fileheader_t * fhdr, char *direct) return 0; } -int +int mail_list() { stand_title("群組作業"); @@ -557,7 +556,7 @@ mail_list() return 0; } -int +int mail_all() { FILE *fp; @@ -636,7 +635,7 @@ mail_all() return 0; } -int +int mail_mbox() { char cmd[100]; @@ -648,7 +647,7 @@ mail_mbox() return 0; } -static int +static int m_forward(int ent, fileheader_t * fhdr, char *direct) { char uid[STRLEN]; @@ -684,7 +683,7 @@ static int delmsgs[128]; static int delcnt; static int mrd; -static int +static int read_new_mail(fileheader_t * fptr) { static int idc; @@ -775,7 +774,7 @@ read_new_mail(fileheader_t * fptr) return 0; } -int +int m_new() { clear(); @@ -800,7 +799,7 @@ m_new() return -1; } -static void +static void mailtitle() { char buf[256] = ""; @@ -820,7 +819,7 @@ mailtitle() outs(buf); } -static void +static void maildoent(int num, fileheader_t * ent) { char *title, *mark, color, type = "+ Mm"[(ent->filemode & 3)]; @@ -845,14 +844,14 @@ maildoent(int num, fileheader_t * ent) ent->date, ent->owner, color, mark, title); } -static int +static int m_idle(int ent, fileheader_t * fhdr, char *direct) { t_idle(); return FULLUPDATE; } -static int +static int mail_del(int ent, fileheader_t * fhdr, char *direct) { char genbuf[200]; @@ -878,7 +877,7 @@ mail_del(int ent, fileheader_t * fhdr, char *direct) return FULLUPDATE; } -static int +static int mail_read(int ent, fileheader_t * fhdr, char *direct) { char buf[64]; @@ -970,7 +969,7 @@ mail_read(int ent, fileheader_t * fhdr, char *direct) } /* in boards/mail 回信給原作者,轉信站亦可 */ -int +int mail_reply(int ent, fileheader_t * fhdr, char *direct) { char uid[STRLEN]; @@ -1027,7 +1026,7 @@ mail_reply(int ent, fileheader_t * fhdr, char *direct) return FULLUPDATE; } -static int +static int mail_edit(int ent, fileheader_t * fhdr, char *direct) { char genbuf[200]; @@ -1042,7 +1041,7 @@ mail_edit(int ent, fileheader_t * fhdr, char *direct) return FULLUPDATE; } -static int +static int mail_nooutmail(int ent, fileheader_t * fhdr, char *direct) { cuser.userlevel ^= PERM_NOOUTMAIL; @@ -1051,7 +1050,7 @@ mail_nooutmail(int ent, fileheader_t * fhdr, char *direct) } -static int +static int mail_mark(int ent, fileheader_t * fhdr, char *direct) { fhdr->filemode ^= FILE_MARKED; @@ -1093,14 +1092,14 @@ static char *mail_help[] = { NULL }; -static int +static int m_help() { show_help(mail_help); return FULLUPDATE; } -static int +static int mail_cross_post(int ent, fileheader_t * fhdr, char *direct) { char xboard[20], fname[80], xfpath[80], xtitle[80], inputbuf[10]; @@ -1194,7 +1193,7 @@ mail_cross_post(int ent, fileheader_t * fhdr, char *direct) return FULLUPDATE; } -int +int mail_man() { char buf[64], buf1[64]; @@ -1212,7 +1211,7 @@ mail_man() return DONOTHING; } -static int +static int mail_cite(int ent, fileheader_t * fhdr, char *direct) { char fpath[256]; @@ -1257,7 +1256,7 @@ mail_cite(int ent, fileheader_t * fhdr, char *direct) } } -static int +static int mail_save(int ent, fileheader_t * fhdr, char *direct) { char fpath[256]; @@ -1277,7 +1276,7 @@ mail_save(int ent, fileheader_t * fhdr, char *direct) } #ifdef OUTJOBSPOOL -static int +static int mail_waterball(int ent, fileheader_t * fhdr, char *direct) { static char address[60], cmode = 1; @@ -1367,7 +1366,7 @@ static struct onekey_t mail_comms[] = { {'\0', NULL} }; -int +int m_read() { if (get_num_records(currmaildir, sizeof(fileheader_t))) { @@ -1384,7 +1383,7 @@ m_read() } /* 寄站內信 */ -static int +static int send_inner_mail(char *fpath, char *title, char *receiver) { char genbuf[256]; @@ -1411,7 +1410,7 @@ send_inner_mail(char *fpath, char *title, char *receiver) #include <time.h> #ifndef USE_BSMTP -static int +static int bbs_sendmail(char *fpath, char *title, char *receiver) { static int configured = 0; @@ -1490,7 +1489,7 @@ bbs_sendmail(char *fpath, char *title, char *receiver) } #else /* USE_BSMTP */ -int +int bsmtp(char *fpath, char *title, char *rcpt, int method) { char buf[80], *ptr; @@ -1539,7 +1538,7 @@ bsmtp(char *fpath, char *title, char *rcpt, int method) } #endif /* USE_BSMTP */ -int +int doforward(char *direct, fileheader_t * fh, int mode) { static char address[60]; @@ -1630,7 +1629,7 @@ doforward(char *direct, fileheader_t * fh, int mode) return (return_no); } -int +int load_mailalert(char *userid) { struct stat st; @@ -1665,7 +1664,7 @@ load_mailalert(char *userid) } #ifdef EMAIL_JUSTIFY -static void +static void mail_justify(userec_t muser) { fileheader_t mhdr; diff --git a/pttbbs/mbbsd/mbbsd.c b/pttbbs/mbbsd/mbbsd.c index 954cac82..012974ec 100644 --- a/pttbbs/mbbsd/mbbsd.c +++ b/pttbbs/mbbsd/mbbsd.c @@ -1,4 +1,4 @@ -/* $Id: mbbsd.c,v 1.41 2002/07/21 08:18:41 in2 Exp $ */ +/* $Id: mbbsd.c,v 1.42 2002/07/21 09:26:02 in2 Exp $ */ #include "bbs.h" #define SOCKET_QLEN 4 @@ -305,9 +305,7 @@ show_call_in(int save, int which) static int add_history_water(water_t * w, msgque_t * msg) { - //mode:1:all data(including userid, pid); -//0: only last_call_in Ptt:先改回來省不多 i 扑|有問題 - memcpy(&w->msg[w->top], msg, sizeof(msgque_t)); + memcpy(&w->msg[w->top], msg, sizeof(msgque_t)); w->top++; w->top %= WATERMODE(WATER_OFO) ? 5 : MAX_REVIEW; diff --git a/pttbbs/mbbsd/menu.c b/pttbbs/mbbsd/menu.c index c7570620..d51dd01e 100644 --- a/pttbbs/mbbsd/menu.c +++ b/pttbbs/mbbsd/menu.c @@ -1,4 +1,4 @@ -/* $Id: menu.c,v 1.14 2002/07/20 08:52:24 in2 Exp $ */ +/* $Id: menu.c,v 1.15 2002/07/21 09:26:02 in2 Exp $ */ #include "bbs.h" /* help & menu processring */ @@ -6,7 +6,7 @@ static int refscreen = NA; extern char *boardprefix; extern struct utmpfile_t *utmpshm; -int +int egetch() { int rval; @@ -28,7 +28,7 @@ extern userec_t cuser; extern char *fn_board; extern char board_hidden_status; -void +void showtitle(char *title, char *mid) { char buf[40], numreg[50]; @@ -94,14 +94,14 @@ static unsigned char menu_row = 12; static unsigned char menu_column = 20; static char mystatus[160]; -static int +static int u_movie() { cuser.uflag ^= MOVIE_FLAG; return 0; } -void +void movie(int i) { static short history[MAX_HISTORY]; @@ -152,7 +152,7 @@ movie(int i) refresh(); } -static int +static int show_menu(commands_t * p) { register int n = 0; @@ -174,7 +174,7 @@ show_menu(commands_t * p) return n - 1; } -void +void domenu(int cmdmode, char *cmdtitle, int cmd, commands_t cmdtable[]) { int lastcmdptr; @@ -583,3 +583,7 @@ int Name_Menu() } + + + + diff --git a/pttbbs/mbbsd/more.c b/pttbbs/mbbsd/more.c index 90b22ab1..33c6e1b3 100644 --- a/pttbbs/mbbsd/more.c +++ b/pttbbs/mbbsd/more.c @@ -1,4 +1,4 @@ -/* $Id: more.c,v 1.16 2002/07/20 10:53:58 kcwu Exp $ */ +/* $Id: more.c,v 1.17 2002/07/21 09:26:02 in2 Exp $ */ #include "bbs.h" #define MORE_BUFSIZE 4096 #define MORE_WINSIZE 4096 @@ -127,7 +127,7 @@ more_readln(int fd, unsigned char *buf) * len++; buf[i++] = ch; } } buf[i] = '\0'; return bytes; } */ -int +int more(char *fpath, int promptend) { static char *head[4] = {"作者", "標題", "時間", "轉信"}; @@ -583,4 +583,3 @@ more(char *fpath, int promptend) outs(reset_color); return 0; } - diff --git a/pttbbs/mbbsd/name.c b/pttbbs/mbbsd/name.c index 949afaf2..446a136f 100644 --- a/pttbbs/mbbsd/name.c +++ b/pttbbs/mbbsd/name.c @@ -1,4 +1,4 @@ -/* $Id: name.c,v 1.11 2002/07/21 08:18:41 in2 Exp $ */ +/* $Id: name.c,v 1.12 2002/07/21 09:26:02 in2 Exp $ */ #include "bbs.h" static word_t *current = NULL; @@ -7,7 +7,7 @@ static char *msg_more = "\033[7m-- More --\033[m"; typedef char (*arrptr)[]; /* name complete for user ID */ -static int +static int UserMaxLen(char cwlist[][IDLEN + 1], int cwnum, int morenum, int count) { @@ -21,7 +21,7 @@ UserMaxLen(char cwlist[][IDLEN + 1], int cwnum, int morenum, return max; } -static int +static int UserSubArray(char cwbuf[][IDLEN + 1], char cwlist[][IDLEN + 1], int cwnum, int key, int pos) { @@ -42,7 +42,7 @@ UserSubArray(char cwbuf[][IDLEN + 1], char cwlist[][IDLEN + 1], return num; } -static void +static void FreeNameList() { word_t *p, *temp; @@ -54,7 +54,7 @@ FreeNameList() } } -void +void CreateNameList() { if (toplev) @@ -62,7 +62,7 @@ CreateNameList() toplev = current = NULL; } -void +void AddNameList(char *name) { word_t *node; @@ -78,7 +78,7 @@ AddNameList(char *name) current = toplev = node; } -int +int RemoveNameList(char *name) { word_t *curr, *prev = NULL; @@ -101,7 +101,7 @@ RemoveNameList(char *name) return 0; } -int +int InNameList(char *name) { word_t *p; @@ -112,7 +112,7 @@ InNameList(char *name) return 0; } -void +void ShowNameList(int row, int column, char *prompt) { word_t *p; @@ -135,7 +135,7 @@ ShowNameList(int row, int column, char *prompt) } } -void +void ToggleNameList(int *reciper, char *listfile, char *msg) { FILE *fp; @@ -157,7 +157,7 @@ ToggleNameList(int *reciper, char *listfile, char *msg) } } -static int +static int NumInList(word_t * list) { register int i; @@ -167,7 +167,7 @@ NumInList(word_t * list) return i; } -int +int chkstr(char *otag, char *tag, char *name) { char ch, *oname = name; @@ -213,7 +213,7 @@ GetSubList(char *tag, word_t * list) return wlist; } -static void +static void ClearSubList(word_t * list) { struct word_t *tmp_list; @@ -225,7 +225,7 @@ ClearSubList(word_t * list) } } -static int +static int MaxLen(word_t * list, int count) { int len = strlen(list->word); @@ -240,7 +240,7 @@ MaxLen(word_t * list, int count) return len; } -void +void namecomplete(char *prompt, char *data) { char *temp; @@ -368,7 +368,7 @@ namecomplete(char *prompt, char *data) } } -void +void usercomplete(char *prompt, char *data) { char *temp; @@ -490,7 +490,7 @@ usercomplete(char *prompt, char *data) } } -int +int gnc_findbound(char *str, int *START, int *END, size_t nmemb, int (*compar) (int, char *, int)) { @@ -506,186 +506,200 @@ gnc_findbound(char *str, int *START, int *END, start = mid; } ++start; - //if (strncasecmp(brdshm->sorted[0][start]->brdname, str, strl) != 0) { - if (compar(start, str, strl) != 0) { - *START = *END = -1; - return -1; - } - *START = start; - - end = nmemb - 1; - while (start != end && ((mid = (start + end) / 2) != start)) { - cmp = compar(mid, str, strl); - //cmp = strncasecmp(brdshm->sorted[0][mid]->brdname, str, strl); - if (cmp <= 0) - start = mid; - else - end = mid; - } - *END = start; - return 0; + if (compar(start, str, strl) != 0) { + *START = *END = -1; + return -1; } - int gnc_completeone(char *data, int start, int end, - int (*permission) (int), char *(*getname) (int)){ - int i, count, at; - if (start < 0 || end < 0) - return -1; - for (i = start, at = count = 0; i <= end && count < 2; ++i) - if (permission(i)) { - at = i; - ++count; - } - if (count == 1) { - strcpy(data, getname(at)); - return at; - } + *START = start; + + end = nmemb - 1; + while (start != end && ((mid = (start + end) / 2) != start)) { + cmp = compar(mid, str, strl); + //cmp = strncasecmp(brdshm->sorted[0][mid]->brdname, str, strl); + if (cmp <= 0) + start = mid; + else + end = mid; + } + *END = start; + return 0; +} +int +gnc_completeone(char *data, int start, int end, + int (*permission) (int), char *(*getname) (int)) +{ + int i, count, at; + if (start < 0 || end < 0) return -1; + for (i = start, at = count = 0; i <= end && count < 2; ++i) + if (permission(i)) { + at = i; + ++count; + } + if (count == 1) { + strcpy(data, getname(at)); + return at; } + return -1; +} - int generalnamecomplete(char *prompt, char *data, int len, size_t nmemb, - int (*compar) (int, char *, int), - int (*permission) (int), char *(*getname) (int)){ - int x, y, origx, origy, ch, i, morelist = -1, col, - ret = -1; - int start, end, ptr; - int clearbot = NA; - - outs(prompt); - clrtoeol(); - getyx(&y, &x); - getyx(&origy, &origx); - standout(); - prints("%*s", IDLEN + 1, ""); - standend(); - move(y, x); - refresh(); - ptr = 0; - data[ptr] = 0; - - while ((ch = igetch()) != EOF) { - if (ch == '\n' || ch == '\r') { - data[ptr] = 0; - outc('\n'); - if (ptr != 0) { - gnc_findbound(data, &start, &end, nmemb, compar); - ret = gnc_completeone(data, start, end, permission, getname); - } else - ptr = -1; - break; - } else if (ch == ' ') { - if (ptr == 0) - continue; +int +generalnamecomplete(char *prompt, char *data, int len, size_t nmemb, + int (*compar) (int, char *, int), + int (*permission) (int), char *(*getname) (int)) +{ + int x, y, origx, origy, ch, i, morelist = -1, col, ret = -1; + int start, end, ptr; + int clearbot = NA; - if (morelist == -1) { - if (gnc_findbound(data, &start, &end, nmemb, compar) == -1) - continue; - if (gnc_completeone(data, start, end, - permission, getname) >= 0) { - move(origy, origx); - outs(data); - ptr = strlen(data); - getyx(&y, &x); - continue; - } - morelist = start; - } else if (morelist > end) - continue; - clearbot = YEA; - move(2, 0); - clrtobot(); - printdash("相關資訊一覽表"); - - col = 0; - while (len + col < 79) { - for (i = 0; morelist <= end && i < p_lines; ++morelist) { - if (permission(morelist)) { - move(3 + i, col); - prints("%s ", getname(morelist)); - ++i; - } - } + outs(prompt); + clrtoeol(); + getyx(&y, &x); + getyx(&origy, &origx); + standout(); + prints("%*s", IDLEN + 1, ""); + standend(); + move(y, x); + refresh(); + ptr = 0; + data[ptr] = 0; - col += len + 2; - } - if (morelist != end + 1) { - move(b_lines, 0); - outs(msg_more); - } - move(y, x); + while ((ch = igetch()) != EOF) { + if (ch == '\n' || ch == '\r') { + data[ptr] = 0; + outc('\n'); + if (ptr != 0) { + gnc_findbound(data, &start, &end, nmemb, compar); + ret = gnc_completeone(data, start, end, permission, getname); + } else + ptr = -1; + break; + } else if (ch == ' ') { + if (ptr == 0) continue; - } else if (ch == '\177' || ch == '\010') { /* backspace */ - if (ptr == 0) + if (morelist == -1) { + if (gnc_findbound(data, &start, &end, nmemb, compar) == -1) continue; - morelist = -1; - --ptr; - --x; - data[ptr] = 0; - move(y, x); - outc(' '); - move(y, x); + if (gnc_completeone(data, start, end, + permission, getname) >= 0) { + move(origy, origx); + outs(data); + ptr = strlen(data); + getyx(&y, &x); + continue; + } + morelist = start; + } else if (morelist > end) continue; - } else if (isprint(ch) && ptr <= (len - 2)) { - morelist = -1; - data[ptr] = ch; - ++ptr; - data[ptr] = 0; - if (gnc_findbound(data, &start, &end, nmemb, compar) < 0) + clearbot = YEA; + move(2, 0); + clrtobot(); + printdash("相關資訊一覽表"); + + col = 0; + while (len + col < 79) { + for (i = 0; morelist <= end && i < p_lines; ++morelist) { + if (permission(morelist)) { + move(3 + i, col); + prints("%s ", getname(morelist)); + ++i; + } + } + + col += len + 2; + } + if (morelist != end + 1) { + move(b_lines, 0); + outs(msg_more); + } + move(y, x); + continue; + + } else if (ch == '\177' || ch == '\010') { /* backspace */ + if (ptr == 0) + continue; + morelist = -1; + --ptr; + --x; + data[ptr] = 0; + move(y, x); + outc(' '); + move(y, x); + continue; + } else if (isprint(ch) && ptr <= (len - 2)) { + morelist = -1; + data[ptr] = ch; + ++ptr; + data[ptr] = 0; + if (gnc_findbound(data, &start, &end, nmemb, compar) < 0) + data[--ptr] = 0; + else { + for (i = start; i <= end; ++i) + if (permission(i)) + break; + if (i == end + 1) data[--ptr] = 0; else { - for (i = start; i <= end; ++i) - if (permission(i)) - break; - if (i == end + 1) - data[--ptr] = 0; - else { - move(y, x); - outc(ch); - x++; - } + move(y, x); + outc(ch); + x++; } } } + } + outc('\n'); + refresh(); + if (clearbot) { + move(2, 0); + clrtobot(); + } + if (*data) { + move(origy, origx); + outs(data); outc('\n'); - refresh(); - if (clearbot) { - move(2, 0); - clrtobot(); - } - if (*data) { - move(origy, origx); - outs(data); - outc('\n'); - } - return ret; } + return ret; +} - /* general complete functions (brdshm) */ - int completeboard_compar(int where, char *str, int len){ - return strncasecmp(SHM->bsorted[0][where]->brdname, str, len); - } +/* general complete functions (brdshm) */ +int +completeboard_compar(int where, char *str, int len) +{ + return strncasecmp(SHM->bsorted[0][where]->brdname, str, len); +} - int completeboard_permission(int where){ - return Ben_Perm(SHM->bsorted[0][where]); - } +int +completeboard_permission(int where) +{ + return Ben_Perm(SHM->bsorted[0][where]); +} - char *completeboard_getname(int where){ - return SHM->bsorted[0][where]->brdname; - } +char * +completeboard_getname(int where) +{ + return SHM->bsorted[0][where]->brdname; +} - /* general complete functions (utmpshm) */ - int completeutmp_compar(int where, char *str, int len){ - return strncasecmp(SHM->sorted[SHM->currsorted][0][where]->userid, - str, len); - } +/* general complete functions (utmpshm) */ +int +completeutmp_compar(int where, char *str, int len) +{ + return strncasecmp(SHM->sorted[SHM->currsorted][0][where]->userid, + str, len); +} - int completeutmp_permission(int where){ - return (HAS_PERM(PERM_SYSOP) || HAS_PERM(PERM_SEECLOAK) || - !SHM->sorted[SHM->currsorted][0][where]->invisible); - } +int +completeutmp_permission(int where) +{ + return (HAS_PERM(PERM_SYSOP) || HAS_PERM(PERM_SEECLOAK) || + !SHM->sorted[SHM->currsorted][0][where]->invisible); +} - char *completeutmp_getname(int where){ - return SHM->sorted[SHM->currsorted][0][where]->userid; - } +char * +completeutmp_getname(int where) +{ + return SHM->sorted[SHM->currsorted][0][where]->userid; +} diff --git a/pttbbs/mbbsd/osdep.c b/pttbbs/mbbsd/osdep.c index d99395c7..f1b65242 100644 --- a/pttbbs/mbbsd/osdep.c +++ b/pttbbs/mbbsd/osdep.c @@ -1,11 +1,11 @@ -/* $Id: osdep.c,v 1.4 2002/07/05 17:10:27 in2 Exp $ */ +/* $Id: osdep.c,v 1.5 2002/07/21 09:26:02 in2 Exp $ */ #include "bbs.h" #if __FreeBSD__ #include <kvm.h> -int +int cpuload(char *str) { double l[3] = {-1, -1, -1}; @@ -21,7 +21,7 @@ cpuload(char *str) return (int)l[0]; } -double +double swapused(long *total, long *used) { double percent = -1; @@ -44,7 +44,7 @@ swapused(long *total, long *used) } #else -int +int cpuload(char *str) { double l[3] = {-1, -1, -1}; @@ -64,7 +64,7 @@ cpuload(char *str) return (int)l[0]; } -double +double swapused(long *total, long *used) { double percent = -1; diff --git a/pttbbs/mbbsd/othello.c b/pttbbs/mbbsd/othello.c index 76cd2f8c..6f6d69ab 100644 --- a/pttbbs/mbbsd/othello.c +++ b/pttbbs/mbbsd/othello.c @@ -1,4 +1,4 @@ -/* $Id: othello.c,v 1.4 2002/07/05 17:10:27 in2 Exp $ */ +/* $Id: othello.c,v 1.5 2002/07/21 09:26:02 in2 Exp $ */ #include "bbs.h" #define LOGFILE "etc/othello.log" @@ -62,7 +62,7 @@ static char init_table[NR_TABLE + 1][5][5] = { }; static char table[NR_TABLE + 1][10][10]; -static void +static void print_chess(int x, int y, char chess) { move(STARTX - 1 + x * 2, STARTY - 2 + y * 4); @@ -73,7 +73,7 @@ print_chess(int x, int y, char chess) refresh(); } -static void +static void printboard() { int i; @@ -118,7 +118,7 @@ printboard() prints("右:→, l"); } -static int +static int get_key(char nowx, char nowy) { int ch; @@ -133,7 +133,7 @@ get_key(char nowx, char nowy) return ch; } -static int +static int eatline(int i, int j, char color, int dir, char chessboard[][10]) { int tmpx, tmpy; @@ -168,7 +168,7 @@ eatline(int i, int j, char color, int dir, char chessboard[][10]) return false; } -static int +static int if_can_put(int x, int y, char color, char chessboard[][10]) { int i, temp, checkx, checky; @@ -188,7 +188,7 @@ if_can_put(int x, int y, char color, char chessboard[][10]) return false; } -static int +static int get_hint(char color) { int i, j, temp = 0; @@ -206,7 +206,7 @@ get_hint(char color) return temp; } -static void +static void eat(int x, int y, int color, char chessboard[][10]) { int k; @@ -215,7 +215,7 @@ eat(int x, int y, int color, char chessboard[][10]) eatline(x, y, color, k, chessboard); } -static void +static void end_of_game(int quit) { FILE *fp, *fp1; @@ -277,7 +277,7 @@ end_of_game(int quit) igetkey(); } -static void +static void othello_redraw() { int i, j; @@ -287,7 +287,7 @@ othello_redraw() print_chess(i, j, nowboard[i][j]); } -static int +static int player(char color) { int ch; @@ -359,7 +359,7 @@ player(char color) return 0; } -static void +static void init() { int i, j, i1, j1; @@ -381,7 +381,7 @@ init() nowboard[4][5] = nowboard[5][4] = BLACK; } -static void +static void report() { int i, j; @@ -401,7 +401,7 @@ report() prints("電腦 : %02d", number[1]); } -static int +static int EVL(char chessboard[][10], int color, int table_number) { int points = 0, a, b; @@ -416,7 +416,7 @@ EVL(char chessboard[][10], int color, int table_number) return ((color == BLACK) ? points : -points); } -static int +static int alphabeta(int alpha, int beta, int level, char chessboard[][10], int thinkstep, int color, int table) { @@ -448,7 +448,7 @@ alphabeta(int alpha, int beta, int level, char chessboard[][10], return ((level & 1) ? alpha : beta); } -static int +static int Computer(int thinkstep, int table) { int i, j, maxi = 0, maxj = 0, level = 1; @@ -492,7 +492,7 @@ Computer(int thinkstep, int table) return true; } -static int +static int choose() { char thinkstep[2]; @@ -524,7 +524,7 @@ choose() #define lockreturn0(unmode, state) if(lockutmpmode(unmode, state)) return 0 -int +int othello_main() { lockreturn0(OTHELLO, LOCK_MULTI); diff --git a/pttbbs/mbbsd/page.c b/pttbbs/mbbsd/page.c index a3e11466..988b222b 100644 --- a/pttbbs/mbbsd/page.c +++ b/pttbbs/mbbsd/page.c @@ -1,8 +1,8 @@ -/* $Id: page.c,v 1.7 2002/07/21 08:18:41 in2 Exp $ */ +/* $Id: page.c,v 1.8 2002/07/21 09:26:02 in2 Exp $ */ #include "bbs.h" #define hpressanykey(a) {move(22, 0); prints(a); pressanykey();} -static void +static void filt_railway(char *fpath) { char buf[256], tmppath[32]; @@ -24,7 +24,7 @@ filt_railway(char *fpath) unlink(tmppath); } -int +int main_railway() { fileheader_t mhdr; diff --git a/pttbbs/mbbsd/passwd.c b/pttbbs/mbbsd/passwd.c index 9c129dc0..a9b32f0c 100644 --- a/pttbbs/mbbsd/passwd.c +++ b/pttbbs/mbbsd/passwd.c @@ -1,4 +1,4 @@ -/* $Id: passwd.c,v 1.7 2002/07/05 17:10:28 in2 Exp $ */ +/* $Id: passwd.c,v 1.8 2002/07/21 09:26:02 in2 Exp $ */ #include "bbs.h" static int semid = -1; @@ -20,7 +20,7 @@ union semun { }; #endif -int +int passwd_init() { semid = semget(PASSWDSEM_KEY, 1, SEM_R | SEM_A | IPC_CREAT | IPC_EXCL); @@ -48,7 +48,7 @@ passwd_init() return 0; } -int +int passwd_update_money(int num) { userec_t user; @@ -61,7 +61,7 @@ passwd_update_money(int num) return 0; } -int +int passwd_update(int num, userec_t * buf) { int pwdfd; @@ -76,7 +76,7 @@ passwd_update(int num, userec_t * buf) return 0; } -int +int passwd_query(int num, userec_t * buf) { int pwdfd; @@ -90,7 +90,7 @@ passwd_query(int num, userec_t * buf) return 0; } -int +int passwd_apply(int (*fptr) (userec_t *)) { int i; @@ -103,7 +103,7 @@ passwd_apply(int (*fptr) (userec_t *)) return 0; } -void +void passwd_lock() { struct sembuf buf = {0, -1, SEM_UNDO}; @@ -114,7 +114,7 @@ passwd_lock() } } -void +void passwd_unlock() { struct sembuf buf = {0, 1, SEM_UNDO}; diff --git a/pttbbs/mbbsd/read.c b/pttbbs/mbbsd/read.c index 4ef38169..5a915d3b 100644 --- a/pttbbs/mbbsd/read.c +++ b/pttbbs/mbbsd/read.c @@ -1,4 +1,4 @@ -/* $Id: read.c,v 1.9 2002/07/21 08:18:41 in2 Exp $ */ +/* $Id: read.c,v 1.10 2002/07/21 09:26:02 in2 Exp $ */ #include "bbs.h" #define MAXPATHLEN 256 @@ -209,7 +209,7 @@ getkeep(char *s, int def_topline, int def_cursline) return (keeplist = p); } -void +void fixkeep(char *s, int first) { keeploc_t *k; @@ -222,7 +222,7 @@ fixkeep(char *s, int first) } /* calc cursor pos and show cursor correctly */ -static int +static int cursor_pos(keeploc_t * locmem, int val, int from_top) { int top; @@ -249,7 +249,7 @@ cursor_pos(keeploc_t * locmem, int val, int from_top) return PARTUPDATE; } -static int +static int move_cursor_line(keeploc_t * locmem, int mode) { int top, crs; @@ -283,7 +283,7 @@ move_cursor_line(keeploc_t * locmem, int mode) return reload; } -static int +static int thread(keeploc_t * locmem, int stype) { static char a_ans[32], t_ans[32]; @@ -418,7 +418,7 @@ thread(keeploc_t * locmem, int stype) #ifdef INTERNET_EMAIL -static void +static void mail_forward(fileheader_t * fhdr, char *direct, int mode) { int i; @@ -446,7 +446,7 @@ mail_forward(fileheader_t * fhdr, char *direct, int mode) } #endif -static int +static int select_read(keeploc_t * locmem, int sr_mode) { register char *tag, *query, *temp; @@ -541,7 +541,7 @@ select_read(keeploc_t * locmem, int sr_mode) return st.st_size; } -static int +static int i_read_key(onekey_t * rcmdlist, keeploc_t * locmem, int ch, int bid) { int i, mode = DONOTHING; @@ -728,7 +728,8 @@ i_read_key(onekey_t * rcmdlist, keeploc_t * locmem, int ch, int bid) return mode; } -void i_read(int cmdmode, char *direct, void (*dotitle) (), void (*doentry) (), onekey_t * rcmdlist, int bidcache){ +void + i_read(int cmdmode, char *direct, void (*dotitle) (), void (*doentry) (), onekey_t * rcmdlist, int bidcache){ keeploc_t *locmem = NULL; int recbase = 0, mode, ch; int num = 0, entries = 0; @@ -742,8 +743,8 @@ void i_read(int cmdmode, char *direct, void (*dotitle) (), void (*doe strlcpy(currdirect0, currdirect, sizeof(currdirect0)); #define FHSZ sizeof(fileheader_t) -//Ptt:這 鄣eaders i H w 麍搌O 熙怮60 g 甥ache - headers = (fileheader_t *) calloc(p_lines, FHSZ); + /* Ptt: 這邊 headers 可以針對看板的最後 60 篇做 cache */ + headers = (fileheader_t *) calloc(p_lines, FHSZ); strlcpy(currdirect, direct, sizeof(currdirect)); mode = NEWDIRECT; diff --git a/pttbbs/mbbsd/record.c b/pttbbs/mbbsd/record.c index 79dd1801..d8ce7aa2 100644 --- a/pttbbs/mbbsd/record.c +++ b/pttbbs/mbbsd/record.c @@ -1,10 +1,10 @@ -/* $Id: record.c,v 1.8 2002/07/21 08:18:41 in2 Exp $ */ +/* $Id: record.c,v 1.9 2002/07/21 09:26:02 in2 Exp $ */ #include "bbs.h" #undef HAVE_MMAP #define BUFSIZE 512 -static void +static void PttLock(int fd, int size, int mode) { static struct flock lock_it; @@ -20,7 +20,7 @@ PttLock(int fd, int size, int mode) #define safewrite write -int +int get_num_records(char *fpath, int size) { struct stat st; @@ -29,7 +29,7 @@ get_num_records(char *fpath, int size) return st.st_size / size; } -int +int get_sum_records(char *fpath, int size) { struct stat st; @@ -53,7 +53,7 @@ get_sum_records(char *fpath, int size) return ans / 1024; } -int +int get_record(char *fpath, void *rptr, int size, int id) { int fd = -1; @@ -70,7 +70,7 @@ get_record(char *fpath, void *rptr, int size, int id) return -1; } -int +int get_records(char *fpath, void *rptr, int size, int id, int number) { int fd; @@ -90,7 +90,7 @@ get_records(char *fpath, void *rptr, int size, int id, int number) return id / size; } -int +int substitute_record(char *fpath, void *rptr, int size, int id) { int fd; @@ -133,7 +133,7 @@ typedef struct nol_t { char lockfn[256]; } nol_t; -static void +static void nolfilename(nol_t * n, char *fpath) { sprintf(n->newfn, "%s.new", fpath); @@ -141,7 +141,7 @@ nolfilename(nol_t * n, char *fpath) sprintf(n->lockfn, "%s.lock", fpath); } -int +int delete_record(char fpath[], int size, int id) { nol_t my; @@ -207,7 +207,7 @@ title_body(char *title) } #endif -int +int delete_range(char *fpath, int id1, int id2) { fileheader_t fhdr; @@ -275,7 +275,7 @@ delete_range(char *fpath, int id1, int id2) return 0; } -int +int search_rec(char *dirname, int (*filecheck) ()) { fileheader_t fhdr; @@ -343,7 +343,7 @@ int delete_files(char *dirname, int (*filecheck) (), int record){ return ans; } -int +int delete_file(char *dirname, int size, int ent, int (*filecheck) ()) { char abuf[BUFSIZE]; @@ -422,7 +422,7 @@ int apply_record(char *fpath, int (*fptr) (), int size){ } /* mail / post 時,依據時間建立檔案,加上郵戳 */ -int +int stampfile(char *fpath, fileheader_t * fh) { register char *ip = fpath; @@ -448,7 +448,7 @@ stampfile(char *fpath, fileheader_t * fh) return 0; } -void +void stampdir(char *fpath, fileheader_t * fh) { register char *ip = fpath; @@ -469,7 +469,7 @@ stampdir(char *fpath, fileheader_t * fh) sprintf(fh->date, "%2d/%02d", ptime->tm_mon + 1, ptime->tm_mday); } -void +void stamplink(char *fpath, fileheader_t * fh) { register char *ip = fpath; @@ -490,7 +490,7 @@ stamplink(char *fpath, fileheader_t * fh) sprintf(fh->date, "%2d/%02d", ptime->tm_mon + 1, ptime->tm_mday); } -int +int do_append(char *fpath, fileheader_t * record, int size) { int fd; @@ -509,7 +509,7 @@ do_append(char *fpath, fileheader_t * record, int size) return 0; } -int +int append_record(char *fpath, fileheader_t * record, int size) { #if !defined(_BBS_UTIL_C_) diff --git a/pttbbs/mbbsd/register.c b/pttbbs/mbbsd/register.c index 3cb92cab..26204ce8 100644 --- a/pttbbs/mbbsd/register.c +++ b/pttbbs/mbbsd/register.c @@ -1,4 +1,4 @@ -/* $Id: register.c,v 1.7 2002/07/21 08:18:41 in2 Exp $ */ +/* $Id: register.c,v 1.8 2002/07/21 09:26:02 in2 Exp $ */ #define _XOPEN_SOURCE #include "bbs.h" @@ -30,7 +30,7 @@ genpasswd(char *pw) return ""; } -int +int checkpasswd(char *passwd, char *test) { char *pw; @@ -41,7 +41,7 @@ checkpasswd(char *passwd, char *test) } /* 檢查 user 註冊情況 */ -int +int bad_user_id(char *userid) { int len, i; @@ -53,8 +53,8 @@ bad_user_id(char *userid) if (not_alpha(userid[0])) return 1; for (i = 1; i < len; i++) -//DickG:修正了 u 騆userid 臚@個字 葵槓ug - if (not_alnum(userid[i])) + /* DickG: 修正了只比較 userid 第一個字元的 bug */ + if (not_alnum(userid[i])) return 1; if (strcasecmp(userid, str_new) == 0) @@ -71,7 +71,7 @@ bad_user_id(char *userid) /* (a) is the worst user currently */ /* (b) is the object to be compared */ /* -------------------------------- */ -static int +static int compute_user_value(userec_t * urec, time_t clock) { int value; @@ -97,7 +97,7 @@ compute_user_value(userec_t * urec, time_t clock) return (urec->userlevel & PERM_LOGINOK ? 120 : 15) * 24 * 60 - value; } -int +int check_and_expire_account(int uid, userec_t * urec) { userec_t zerorec; @@ -130,7 +130,7 @@ check_and_expire_account(int uid, userec_t * urec) } -int +int getnewuserid() { char genbuf[50]; @@ -185,7 +185,7 @@ getnewuserid() return i; } -void +void new_register() { userec_t newuser; @@ -269,7 +269,7 @@ new_register() } -void +void check_register() { char *ptr = NULL; @@ -297,8 +297,8 @@ check_register() * if(!strchr(cuser.email, '@')) { bell(); move(t_lines - 4, 0); prints(" * 您的權益,請填寫真實的 E-mail address," "以資確認閣下身份,\n" " * 033[44muser@domain_name\033[0m 或 \033[44muser" - * "@\\[ip_number\\]\033[0m。\n\n" "※ 如果您真的沒有 E-mail, - * turn] 即可。"); + * "@\\[ip_number\\]\033[0m。\n\n" "※ 如果您真的沒有 E-mail, turn] + * 即可。"); * * do { getdata(8, 0, "電子信箱:", cuser.email, sizeof(cuser.email), * DOECHO); if(!cuser.email[0]) sprintf(cuser.email, "%s%s", diff --git a/pttbbs/mbbsd/screen.c b/pttbbs/mbbsd/screen.c index a5cbea77..2650f5f9 100644 --- a/pttbbs/mbbsd/screen.c +++ b/pttbbs/mbbsd/screen.c @@ -1,4 +1,4 @@ -/* $Id: screen.c,v 1.5 2002/07/21 08:18:41 in2 Exp $ */ +/* $Id: screen.c,v 1.6 2002/07/21 09:26:02 in2 Exp $ */ #include "bbs.h" #ifdef SUPPORT_GB @@ -23,7 +23,7 @@ static int scrollcnt, tc_col, tc_line; int tputs(const char *str, int affcnt, int (*putc) (int)); -void +void initscr() { if (!big_picture) { @@ -35,21 +35,21 @@ initscr() } } -void +void move(int y, int x) { cur_col = x; cur_ln = y; } -void +void getyx(int *y, int *x) { *y = cur_ln; *x = cur_col; } -static void +static void rel_move(int was_col, int was_ln, int new_col, int new_ln) { if (new_ln >= t_lines || new_col >= t_columns) @@ -81,7 +81,7 @@ rel_move(int was_col, int was_ln, int new_col, int new_ln) do_move(new_col, new_ln); } -static void +static void standoutput(char *buf, int ds, int de, int sso, int eso) { int st_start, st_end; @@ -101,7 +101,7 @@ standoutput(char *buf, int ds, int de, int sso, int eso) } } -void +void redoscr() { register screenline_t *bp; @@ -138,7 +138,7 @@ redoscr() oflush(); } -void +void refresh() { register screenline_t *bp = big_picture; @@ -204,7 +204,7 @@ refresh() oflush(); } -void +void clear() { register screenline_t *slp; @@ -219,7 +219,7 @@ clear() } while (++i < scr_lns); } -void +void clrtoeol() { register screenline_t *slp; @@ -243,7 +243,7 @@ clrtoeol() slp->len = cur_col; } -void +void clrtoline(int line) { register screenline_t *slp; @@ -259,13 +259,13 @@ clrtoline(int line) } } -void +void clrtobot() { clrtoline(scr_lns); } -void +void outch(unsigned char c) { register screenline_t *slp; @@ -319,7 +319,7 @@ outch(unsigned char c) } } -static void +static void parsecolor(char *buf) { char *val; @@ -343,7 +343,7 @@ parsecolor(char *buf) #define ESCAPE (01) #define VTKEYS (02) -void +void outc(unsigned char ch) { if (showansi) @@ -392,7 +392,7 @@ outc(unsigned char ch) } } -static void +static void do_outs(char *str) { while (*str) { @@ -400,7 +400,7 @@ do_outs(char *str) } } #ifdef SUPPORT_GB -static void +static void gb_init() { if (current_font_type == TYPE_GB) { @@ -409,13 +409,13 @@ gb_init() gbinited = 1; } -static void +static void gb_outs(char *str) { do_outs(hc_convert_str(str, HC_BIGtoGB, HC_DO_SINGLE)); } #endif -int +int edit_outs(char *text) { register int column = 0; @@ -430,7 +430,7 @@ edit_outs(char *text) return 0; } -void +void outs(char *str) { #ifdef SUPPORT_GB @@ -448,7 +448,7 @@ outs(char *str) /* Jaky */ -void +void Jaky_outs(char *str, int line) { #ifdef SUPPORT_GB @@ -463,7 +463,7 @@ Jaky_outs(char *str, int line) } } -void +void outmsg(char *msg) { move(b_lines, 0); @@ -476,7 +476,7 @@ outmsg(char *msg) outc(*msg++); } -void +void prints(char *fmt,...) { va_list args; @@ -488,7 +488,7 @@ prints(char *fmt,...) outs(buff); } -void +void mprints(int y, int x, char *str) { move(y, x); @@ -496,7 +496,7 @@ mprints(int y, int x, char *str) prints(str); } -void +void scroll() { scrollcnt++; @@ -506,7 +506,7 @@ scroll() clrtoeol(); } -void +void rscroll() { scrollcnt--; @@ -516,7 +516,7 @@ rscroll() clrtoeol(); } -void +void region_scroll_up(int top, int bottom) { int i; @@ -542,7 +542,7 @@ region_scroll_up(int top, int bottom) refresh(); } -void +void standout() { if (!standing && strtstandoutlen) { @@ -555,7 +555,7 @@ standout() } } -void +void standend() { if (standing && strtstandoutlen) { diff --git a/pttbbs/mbbsd/stuff.c b/pttbbs/mbbsd/stuff.c index 98c38e19..d3297eda 100644 --- a/pttbbs/mbbsd/stuff.c +++ b/pttbbs/mbbsd/stuff.c @@ -1,4 +1,4 @@ -/* $Id: stuff.c,v 1.7 2002/07/05 17:10:28 in2 Exp $ */ +/* $Id: stuff.c,v 1.8 2002/07/21 09:26:02 in2 Exp $ */ #include "bbs.h" /* ----------------------------------------------------- */ @@ -10,61 +10,61 @@ static char *str_board_file = "boards/%c/%s/%s"; #define STR_DOTDIR ".DIR" static char *str_dotdir = STR_DOTDIR; -void +void setcalfile(char *buf, char *userid) { sprintf(buf, "home/%c/%s/calendar", userid[0], userid); } -void +void sethomepath(char *buf, char *userid) { sprintf(buf, "home/%c/%s", userid[0], userid); } -void +void sethomedir(char *buf, char *userid) { sprintf(buf, str_home_file, userid[0], userid, str_dotdir); } -void +void sethomeman(char *buf, char *userid) { sprintf(buf, str_home_file, userid[0], userid, "man"); } -void +void sethomefile(char *buf, char *userid, char *fname) { sprintf(buf, str_home_file, userid[0], userid, fname); } -void +void setuserfile(char *buf, char *fname) { sprintf(buf, str_home_file, cuser.userid[0], cuser.userid, fname); } -void +void setapath(char *buf, char *boardname) { sprintf(buf, "man/boards/%c/%s", boardname[0], boardname); } -void +void setadir(char *buf, char *path) { sprintf(buf, "%s/%s", path, str_dotdir); } -void +void setbpath(char *buf, char *boardname) { sprintf(buf, "boards/%c/%s", boardname[0], boardname); } -void +void setbdir(char *buf, char *boardname) { sprintf(buf, str_board_file, boardname[0], boardname, @@ -72,13 +72,13 @@ setbdir(char *buf, char *boardname) (currmode & MODE_DIGEST ? fn_mandex : str_dotdir)); } -void +void setbfile(char *buf, char *boardname, char *fname) { sprintf(buf, str_board_file, boardname[0], boardname, fname); } -void +void setdirpath(char *buf, char *direct, char *fname) { strcpy(buf, direct); @@ -100,7 +100,7 @@ subject(char *title) /* ----------------------------------------------------- */ /* 字串轉換檢查函數 */ /* ----------------------------------------------------- */ -int +int str_checksum(char *str) { int n = 1; @@ -111,7 +111,7 @@ str_checksum(char *str) return n; } -void +void str_lower(char *t, char *s) { register unsigned char ch; @@ -122,7 +122,7 @@ str_lower(char *t, char *s) } while (ch); } -int +int strstr_lower(char *str, char *tag) { char buf[STRLEN]; @@ -131,7 +131,7 @@ strstr_lower(char *str, char *tag) return (int)strstr(buf, tag); } -void +void trim(char *buf) { /* remove trailing space */ char *p = buf; @@ -149,27 +149,27 @@ trim(char *buf) /* ----------------------------------------------------- */ /* 字串檢查函數:英文、數字、檔名、E-mail address */ /* ----------------------------------------------------- */ -int +int isprint2(char ch) { return ((ch & 0x80) ? 1 : isprint(ch)); //return 1; } -int +int not_alpha(char ch) { return (ch < 'A' || (ch > 'Z' && ch < 'a') || ch > 'z'); } -int +int not_alnum(char ch) { return (ch < '0' || (ch > '9' && ch < 'A') || (ch > 'Z' && ch < 'a') || ch > 'z'); } -int +int invalid_pname(char *str) { char *p1, *p2, *p3; @@ -188,7 +188,7 @@ invalid_pname(char *str) return 0; } -int +int valid_ident(char *ident) { static char *invalid[] = {"unknown@", "root@", "gopher@", "bbs@", @@ -203,7 +203,7 @@ valid_ident(char *ident) return 1; } -int +int is_uBM(char *list, char *id) { register int len; @@ -228,7 +228,7 @@ is_uBM(char *list, char *id) return 0; } -int +int is_BM(char *list) { if (is_uBM(list, cuser.userid)) { @@ -238,7 +238,7 @@ is_BM(char *list) return 0; } -int +int userid_is_BM(char *userid, char *list) { register int ch, len; @@ -264,7 +264,7 @@ userid_is_BM(char *userid, char *list) /* ----------------------------------------------------- */ /* 檔案檢查函數:檔案、目錄、屬於 */ /* ----------------------------------------------------- */ -off_t +off_t dashs(char *fname) { struct stat st; @@ -275,7 +275,7 @@ dashs(char *fname) return -1; } -long +long dasht(char *fname) { struct stat st; @@ -286,7 +286,7 @@ dasht(char *fname) return -1; } -int +int dashl(char *fname) { struct stat st; @@ -294,7 +294,7 @@ dashl(char *fname) return (lstat(fname, &st) == 0 && S_ISLNK(st.st_mode)); } -int +int dashf(char *fname) { struct stat st; @@ -302,7 +302,7 @@ dashf(char *fname) return (stat(fname, &st) == 0 && S_ISREG(st.st_mode)); } -int +int dashd(char *fname) { struct stat st; @@ -310,7 +310,7 @@ dashd(char *fname) return (stat(fname, &st) == 0 && S_ISDIR(st.st_mode)); } -int +int belong(char *filelist, char *key) { FILE *fp; @@ -330,7 +330,7 @@ belong(char *filelist, char *key) return rc; } -time_t +time_t gettime(int line, time_t dt) { char yn[7]; @@ -385,7 +385,7 @@ Cdatedate(time_t * clock) return foo; } -static void +static void capture_screen() { char fname[200]; @@ -405,7 +405,7 @@ capture_screen() } } -void +void pressanykey() { int ch; @@ -426,7 +426,7 @@ pressanykey() refresh(); } -int +int vmsg(const char *fmt,...) { va_list ap; @@ -463,7 +463,7 @@ vmsg(const char *fmt,...) return ch; } -void +void bell() { char c; @@ -472,7 +472,7 @@ bell() write(1, &c, 1); } -int +int search_num(int ch, int max) { int clen = 1; @@ -524,14 +524,14 @@ search_num(int ch, int max) return clen - 1; } -void +void stand_title(char *title) { clear(); prints("\033[1;37;46m【 %s 】\033[m\n", title); } -void +void cursor_show(int row, int column) { move(row, column); @@ -539,14 +539,14 @@ cursor_show(int row, int column) move(row, column + 1); } -void +void cursor_clear(int row, int column) { move(row, column); outs(STR_UNCUR); } -int +int cursor_key(int row, int column) { int ch; @@ -558,7 +558,7 @@ cursor_key(int row, int column) return ch; } -void +void printdash(char *mesg) { int head = 0, tail; @@ -581,7 +581,7 @@ printdash(char *mesg) outch('\n'); } -int +int log_file(char *filename, char *buf) { FILE *fp; @@ -596,7 +596,7 @@ log_file(char *filename, char *buf) return -1; } -void +void show_help(char *helptext[]) { char *str; diff --git a/pttbbs/mbbsd/syspost.c b/pttbbs/mbbsd/syspost.c index 6439a735..965ce93b 100644 --- a/pttbbs/mbbsd/syspost.c +++ b/pttbbs/mbbsd/syspost.c @@ -1,7 +1,7 @@ -/* $Id: syspost.c,v 1.13 2002/07/21 08:18:41 in2 Exp $ */ +/* $Id: syspost.c,v 1.14 2002/07/21 09:26:02 in2 Exp $ */ #include "bbs.h" -void +void post_change_perm(int oldperm, int newperm, char *sysopid, char *userid) { FILE *fp; @@ -43,7 +43,7 @@ post_change_perm(int oldperm, int newperm, char *sysopid, char *userid) } } -void +void post_violatelaw(char *crime, char *police, char *reason, char *result) { char genbuf[200]; @@ -82,7 +82,7 @@ post_violatelaw(char *crime, char *police, char *reason, char *result) } -void +void post_newboard(char *bgroup, char *bname, char *bms) { char genbuf[256], title[128]; @@ -92,7 +92,7 @@ post_newboard(char *bgroup, char *bname, char *bms) post_msg("Record", title, genbuf, "[系統]"); } -void +void give_money_post(char *userid, int money) { FILE *fp; diff --git a/pttbbs/mbbsd/talk.c b/pttbbs/mbbsd/talk.c index c0fdbb12..c78eb24e 100644 --- a/pttbbs/mbbsd/talk.c +++ b/pttbbs/mbbsd/talk.c @@ -1,4 +1,4 @@ -/* $Id: talk.c,v 1.79 2002/07/21 08:18:41 in2 Exp $ */ +/* $Id: talk.c,v 1.80 2002/07/21 09:26:02 in2 Exp $ */ #include "bbs.h" #define QCAST int (*)(const void *, const void *) @@ -31,8 +31,7 @@ typedef struct pickup_t { /* 記錄 friend 的 user number */ // -#define PICKUP_WAYS 7 //關掉女士優先 -//#define PICKUP_WAYS 6 +#define PICKUP_WAYS 6 static char *fcolor[11] = { "", "\033[36m", "\033[32m", "\033[1;32m", @@ -44,7 +43,7 @@ static char page_requestor[40]; static char description[30]; static FILE *flog; -int +int iswritable_stat(userinfo_t * uentp, int fri_stat) { if (uentp == currutmp) @@ -59,7 +58,7 @@ iswritable_stat(userinfo_t * uentp, int fri_stat) return (uentp->pager != 3 && (fri_stat & HFM || uentp->pager != 4)); } -int +int isvisible_stat(userinfo_t * me, userinfo_t * uentp, int fri_stat) { if (uentp->userid[0] == 0) @@ -150,7 +149,7 @@ modestring(userinfo_t * uentp, int simple) return (modestr); } -int +int set_friend_bit(userinfo_t * me, userinfo_t * ui) { int unum, *myfriends, hit = 0, n; @@ -196,7 +195,7 @@ set_friend_bit(userinfo_t * me, userinfo_t * ui) return hit; } -int +int reverse_friend_stat(int stat) { int stat1 = 0; @@ -213,7 +212,7 @@ reverse_friend_stat(int stat) return stat1; } -int +int login_friend_online(void) { userinfo_t *uentp; @@ -236,7 +235,7 @@ login_friend_online(void) return 0; } -int +int logout_friend_online(userinfo_t * utmp) { int i, j, k; @@ -263,7 +262,7 @@ logout_friend_online(userinfo_t * utmp) } -int +int friend_stat(userinfo_t * me, userinfo_t * ui) { int i, j, hit = 0; @@ -283,7 +282,7 @@ friend_stat(userinfo_t * me, userinfo_t * ui) return hit; } -int +int isvisible_uid(int tuid) { userinfo_t *uentp; @@ -294,7 +293,7 @@ isvisible_uid(int tuid) } /* 真實動作 */ -static void +static void my_kick(userinfo_t * uentp) { char genbuf[200]; @@ -312,7 +311,7 @@ my_kick(userinfo_t * uentp) pressanykey(); } -static void +static void chicken_query(char *userid) { char buf[100]; @@ -335,7 +334,7 @@ chicken_query(char *userid) } } -int +int my_query(char *uident) { userec_t muser; @@ -399,7 +398,7 @@ my_query(char *uident) static char t_last_write[200] = ""; -void +void water_scr(water_t * tw, int which, char type) { if (type == 1) { @@ -445,7 +444,7 @@ water_scr(water_t * tw, int which, char type) } } -void +void my_write2(void) { int i, ch, currstat0; @@ -552,7 +551,7 @@ my_write2(void) * flag = 1 (pre-edit) 5. 丟水球 flag = 0 6. my_write2 flag = 4 * (pre-edit) but confirm */ -int +int my_write(pid_t pid, char *prompt, char *id, int flag, userinfo_t * puin) { int len, currstat0 = currstat, fri_stat; @@ -663,7 +662,7 @@ my_write(pid_t pid, char *prompt, char *id, int flag, userinfo_t * puin) strlcpy(uin->msgs[uin->msgcount].userid, cuser.userid, sizeof(uin->msgs[uin->msgcount].userid)); strlcpy(uin->msgs[uin->msgcount++].last_call_in, msg, - sizeof(uin->msgs[uin->msgcount++].last_call_in)); + sizeof(uin->msgs[uin->msgcount++].last_call_in)); uin->pager = pager0; } else if (flag != 2) outmsg("\033[1;33;41m糟糕! 對方不行了! (收到太多水球) \033[37m@_@\033[m"); @@ -685,7 +684,7 @@ my_write(pid_t pid, char *prompt, char *id, int flag, userinfo_t * puin) return 1; } -void +void t_display_new(void) { static int t_display_new_flag = 0; @@ -771,7 +770,7 @@ t_display_new(void) t_display_new_flag = 0; } -int +int t_display(void) { char genbuf[200], ans[4]; @@ -807,7 +806,7 @@ t_display(void) return DONOTHING; } -static void +static void do_talk_nextline(talkwin_t * twin) { twin->curcol = 0; @@ -818,7 +817,7 @@ do_talk_nextline(talkwin_t * twin) move(twin->curln, twin->curcol); } -static void +static void do_talk_char(talkwin_t * twin, int ch) { screenline_t *line; @@ -951,7 +950,7 @@ do_talk_char(talkwin_t * twin, int ch) (ch == Ctrl('P')) ? "\033[37;45m(Up)\033[m" : "\033[m"); } -static void +static void do_talk(int fd) { struct talkwin_t mywin, itswin; @@ -1091,7 +1090,7 @@ do_talk(int fd) #define lockreturn(unmode, state) if(lockutmpmode(unmode, state)) return -static void +static void my_talk(userinfo_t * uin, int fri_stat) { int sock, msgsock, length, ch, error = 0; @@ -1343,7 +1342,7 @@ my_talk(userinfo_t * uin, int fri_stat) #define US_ACTION 1232 #define US_REDRAW 1231 -static void +static void t_showhelp() { clear(); @@ -1452,7 +1451,7 @@ descript(int show_mode, userinfo_t * uentp, time_t diff) } #define MAXPICKUP 20 -static int +static int sort_cmpfriend(const void *a, const void *b) { if (((((pickup_t *) a)->friend) & ST_FRIEND) == @@ -1464,7 +1463,7 @@ sort_cmpfriend(const void *a, const void *b) (((pickup_t *) a)->friend & ST_FRIEND); } -int +int pickup_maxpages(int pickupway, int nfriends) { int number; @@ -1476,7 +1475,7 @@ pickup_maxpages(int pickupway, int nfriends) return (number - 1) / MAXPICKUP + 1; } -static int +static int pickup_myfriend(pickup_t * friends, int *myfriend, int *friendme) { @@ -1508,7 +1507,7 @@ pickup_myfriend(pickup_t * friends, return ngets; } -static int +static int pickup_bfriend(pickup_t * friends, int base) { userinfo_t *uentp; @@ -1527,7 +1526,7 @@ pickup_bfriend(pickup_t * friends, int base) return ngets; } -static void +static void pickup(pickup_t * currpickup, int pickup_way, int *page, int *nfriend, int *myfriend, int *friendme, int *bfriend) { @@ -1559,8 +1558,8 @@ pickup(pickup_t * currpickup, int pickup_way, int *page, *nfriend += *bfriend; which = *page * MAXPICKUP; if (*nfriend > which) { - //Ptt: 只 釵b n q X ~有必要 sort - qsort(friends, *nfriend, sizeof(pickup_t), sort_cmpfriend); + /* 只有在要秀出才有必要 sort */ + qsort(friends, *nfriend, sizeof(pickup_t), sort_cmpfriend); size = *nfriend - which; if (size > MAXPICKUP) size = MAXPICKUP; @@ -1599,7 +1598,7 @@ pickup(pickup_t * currpickup, int pickup_way, int *page, currpickup[size].ui = 0; } -static void +static void draw_pickup(int drawall, pickup_t * pickup, int pickup_way, int page, int show_mode, int show_uid, int show_board, int show_pid, int real_name, @@ -1739,7 +1738,7 @@ draw_pickup(int drawall, pickup_t * pickup, int pickup_way, } } -int +int call_in(userinfo_t * uentp, int fri_stat) { if (iswritable_stat(uentp, fri_stat)) { @@ -1751,7 +1750,7 @@ call_in(userinfo_t * uentp, int fri_stat) return 0; } -static void +static void userlist(void) { /* @@ -2276,7 +2275,7 @@ userlist(void) } } -int +int t_users(void) { int destuid0 = currutmp->destuid; @@ -2291,14 +2290,14 @@ t_users(void) return 0; } -int +int t_pager(void) { currutmp->pager = (currutmp->pager + 1) % 5; return 0; } -int +int t_idle(void) { int destuid0 = currutmp->destuid; @@ -2344,7 +2343,7 @@ t_idle(void) return 0; } -int +int t_qchicken(void) { char uident[STRLEN]; @@ -2356,7 +2355,7 @@ t_qchicken(void) return 0; } -int +int t_query(void) { char uident[STRLEN]; @@ -2368,7 +2367,7 @@ t_query(void) return 0; } -int +int t_talk() { char uident[16]; @@ -2417,7 +2416,7 @@ t_talk() /* 有人來串門子了,回應呼叫器 */ static userinfo_t *uip; -void +void talkreply(void) { struct hostent *h; diff --git a/pttbbs/mbbsd/term.c b/pttbbs/mbbsd/term.c index aa310212..ced6b1c4 100644 --- a/pttbbs/mbbsd/term.c +++ b/pttbbs/mbbsd/term.c @@ -1,4 +1,4 @@ -/* $Id: term.c,v 1.4 2002/07/05 17:10:28 in2 Exp $ */ +/* $Id: term.c,v 1.5 2002/07/21 09:26:02 in2 Exp $ */ #include "bbs.h" int tgetent(const char *bp, char *name); @@ -14,7 +14,7 @@ static struct termios tty_state, tty_new; /* ----------------------------------------------------- */ /* basic tty control */ /* ----------------------------------------------------- */ -void +void init_tty() { if (tcgetattr(1, &tty_state) < 0) { @@ -41,7 +41,7 @@ init_tty() static char *outp; static int *outlp; -static int +static int outcf(int ch) { if (*outlp < TERMCOMSIZE) { @@ -52,7 +52,7 @@ outcf(int ch) } #endif -static void +static void term_resize(int sig) { struct winsize newsize; @@ -77,7 +77,7 @@ term_resize(int sig) signal(SIGWINCH, term_resize); } -int +int term_init() { signal(SIGWINCH, term_resize); @@ -86,7 +86,7 @@ term_init() char term_buf[32]; -void +void do_move(int destcol, int destline) { char buf[16], *p; @@ -96,21 +96,21 @@ do_move(int destcol, int destline) ochar(*p); } -void +void save_cursor() { ochar('\33'); ochar('7'); } -void +void restore_cursor() { ochar('\33'); ochar('8'); } -void +void change_scroll_range(int top, int bottom) { char buf[16], *p; @@ -120,7 +120,7 @@ change_scroll_range(int top, int bottom) ochar(*p); } -void +void scroll_forward() { ochar('\33'); diff --git a/pttbbs/mbbsd/toolkit.c b/pttbbs/mbbsd/toolkit.c index 9623c578..99f80e0b 100644 --- a/pttbbs/mbbsd/toolkit.c +++ b/pttbbs/mbbsd/toolkit.c @@ -1,7 +1,7 @@ -/* $Id: toolkit.c,v 1.3 2002/07/05 17:10:28 in2 Exp $ */ +/* $Id: toolkit.c,v 1.4 2002/07/21 09:26:02 in2 Exp $ */ #include "bbs.h" -unsigned +unsigned StringHash(unsigned char *s) { unsigned int v = 0; diff --git a/pttbbs/mbbsd/topsong.c b/pttbbs/mbbsd/topsong.c index 277ef85f..a745b4a5 100644 --- a/pttbbs/mbbsd/topsong.c +++ b/pttbbs/mbbsd/topsong.c @@ -1,4 +1,4 @@ -/* $Id: topsong.c,v 1.4 2002/07/21 08:18:42 in2 Exp $ */ +/* $Id: topsong.c,v 1.5 2002/07/21 09:26:02 in2 Exp $ */ #include "bbs.h" #define MAX_SONGS 300 @@ -12,20 +12,20 @@ typedef struct songcmp_t { static long int totalcount = 0; -static int +static int count_cmp(songcmp_t * b, songcmp_t * a) { return (a->count - b->count); } -int +int topsong() { more(FN_TOPSONG, YEA); return 0; } -static int +static int strip_blank(char *cbuf, char *buf) { for (; *buf; buf++) @@ -35,7 +35,7 @@ strip_blank(char *cbuf, char *buf) return 0; } -void +void sortsong() { FILE *fo, *fp = fopen(BBSHOME "/" FN_USSONG, "r"); diff --git a/pttbbs/mbbsd/user.c b/pttbbs/mbbsd/user.c index 97c9690d..60b51b1f 100644 --- a/pttbbs/mbbsd/user.c +++ b/pttbbs/mbbsd/user.c @@ -1,4 +1,4 @@ -/* $Id: user.c,v 1.30 2002/07/21 08:18:42 in2 Exp $ */ +/* $Id: user.c,v 1.31 2002/07/21 09:26:02 in2 Exp $ */ #include "bbs.h" static char *sex[8] = { @@ -6,7 +6,7 @@ static char *sex[8] = { MSG_MAN, MSG_WOMAN, MSG_PLANT, MSG_MIME }; -int +int u_loginview() { int i; @@ -39,7 +39,7 @@ u_loginview() return 0; } -void +void user_display(userec_t * u, int real) { int diff = 0; @@ -116,7 +116,7 @@ user_display(userec_t * u, int real) #endif } -void +void mail_violatelaw(char *crime, char *police, char *reason, char *result) { char genbuf[200]; @@ -140,7 +140,7 @@ mail_violatelaw(char *crime, char *police, char *reason, char *result) append_record(genbuf, &fhdr, sizeof(fhdr)); } -static void +static void violate_law(userec_t * u, int unum) { char ans[4], ans2[4]; @@ -196,7 +196,7 @@ violate_law(userec_t * u, int unum) } -void +void uinfo_query(userec_t * u, int real, int unum) { userec_t x; @@ -529,7 +529,7 @@ uinfo_query(userec_t * u, int real, int unum) } } -int +int u_info() { move(2, 0); @@ -540,7 +540,7 @@ u_info() return 0; } -int +int u_ansi() { showansi ^= 1; @@ -549,14 +549,14 @@ u_ansi() return 0; } -int +int u_cloak() { outs((currutmp->invisible ^= 1) ? MSG_CLOAKED : MSG_UNCLOAK); return XEASY; } -int +int u_switchproverb() { /* char *state[4]={"用功\型","安逸型","自定型","SHUTUP"}; */ @@ -574,7 +574,7 @@ u_switchproverb() return 0; } -int +int u_editproverb() { char buf[100]; @@ -591,7 +591,7 @@ u_editproverb() return 0; } -void +void showplans(char *uid) { char genbuf[200]; @@ -601,7 +601,7 @@ showplans(char *uid) prints("《個人名片》%s 目前沒有名片", uid); } -int +int showsignature(char *fname) { FILE *fp; @@ -625,7 +625,7 @@ showsignature(char *fname) return j; } -int +int u_editsig() { int aborted; @@ -664,7 +664,7 @@ u_editsig() return 0; } -int +int u_editplan() { char genbuf[200]; @@ -690,7 +690,7 @@ u_editplan() return 0; } -int +int u_editcalendar() { char genbuf[200]; @@ -717,7 +717,7 @@ u_editcalendar() } /* 使用者填寫註冊表格 */ -static void +static void getfield(int line, char *info, char *desc, char *buf, int len) { char prompt[STRLEN]; @@ -734,7 +734,7 @@ getfield(int line, char *info, char *desc, char *buf, int len) clrtoeol(); } -static int +static int removespace(char *s) { int i, index; @@ -747,7 +747,7 @@ removespace(char *s) return index; } -static int +static int ispersonalid(char *inid) { char *lst = "ABCDEFGHJKLMNPQRSTUVWXYZIO", id[20]; @@ -782,7 +782,7 @@ getregcode(char *buf) return buf; } -static int +static int isvaildemail(char *email) { FILE *fp; @@ -810,7 +810,7 @@ isvaildemail(char *email) return 1; } -static void +static void toregister(char *email, char *genbuf, char *phone, char *career, char *ident, char *rname, char *addr, char *mobile) { @@ -924,7 +924,7 @@ toregister(char *email, char *genbuf, char *phone, char *career, } } -int +int u_register(void) { char rname[21], addr[51], ident[12], mobile[21]; @@ -1045,12 +1045,12 @@ u_register(void) while (1) { getfield(7, "學校(含\033[1;33m系所年級\033[m)或單位職稱", "服務單位", career, 40); - if(!(removespace(career) && career[0] < 0 && strlen(career) >= 4)){ + if (!(removespace(career) && career[0] < 0 && strlen(career) >= 4)) { vmsg("您的輸入不正確"); continue; } - if( strcmp(&career[strlen(career) - 2], "大") == 0 || - strcmp(&career[strlen(career) - 4], "大學") == 0 ){ + if (strcmp(&career[strlen(career) - 2], "大") == 0 || + strcmp(&career[strlen(career) - 4], "大學") == 0) { vmsg("麻煩請加系所"); continue; } @@ -1060,15 +1060,15 @@ u_register(void) getfield(9, "含\033[1;33m縣市\033[m及門寢號碼" "(台北請加\033[1;33m行政區\033[m)", "目前住址", addr, 50); - if( !removespace(addr) || addr[0] > 0 || strlen(addr) < 15 ){ + if (!removespace(addr) || addr[0] > 0 || strlen(addr) < 15) { vmsg("這個地址並不合法"); continue; } - if( strstr(addr, "信箱") != NULL || strstr(addr, "郵政") != NULL ){ + if (strstr(addr, "信箱") != NULL || strstr(addr, "郵政") != NULL) { vmsg("抱歉我們不接受郵政信箱"); continue; } - if( strstr(addr, "市") == NULL && strstr(addr, "縣") == NULL ){ + if (strstr(addr, "市") == NULL && strstr(addr, "縣") == NULL) { vmsg("這個地址並不合法"); continue; } @@ -1076,8 +1076,8 @@ u_register(void) } while (1) { getfield(11, "不加-(), 包括長途區號", "連絡電話", phone, 11); - if( !removespace(phone) || phone[0] != '0' || - strlen(phone) < 9 || phone[1] == '0' ){ + if (!removespace(phone) || phone[0] != '0' || + strlen(phone) < 9 || phone[1] == '0') { vmsg("這個電話號碼並不合法"); continue; } @@ -1147,7 +1147,7 @@ u_register(void) static int usercounter, totalusers, showrealname; static ushort u_list_special; -static int +static int u_list_CB(userec_t * uentp) { static int i; @@ -1217,7 +1217,7 @@ u_list_CB(userec_t * uentp) return 0; } -int +int u_list() { char genbuf[3]; diff --git a/pttbbs/mbbsd/var.c b/pttbbs/mbbsd/var.c index 221c9cb4..2cca1e11 100644 --- a/pttbbs/mbbsd/var.c +++ b/pttbbs/mbbsd/var.c @@ -1,4 +1,4 @@ -/* $Id: var.c,v 1.10 2002/07/05 17:10:28 in2 Exp $ */ +/* $Id: var.c,v 1.11 2002/07/21 09:26:02 in2 Exp $ */ #define INCLUDE_VAR_H #include "bbs.h" @@ -290,9 +290,9 @@ int KEY_ESC_arg; int watermode = -1; int wmofo = -1; /* - * WATERMODE(WATER_ORIG) | WATERMODE(WATER_NEW): Ptt 水球回顧 - * e = -1 沒在回水球 = 0 在回上一顆水球 (Ctrl-R) > 0 在回前 n 顆水球 - * (Ctrl-R Ctrl-R) + * WATERMODE(WATER_ORIG) | WATERMODE(WATER_NEW): Ptt 水球回顧 e = -1 + * 沒在回水球 = 0 在回上一顆水球 (Ctrl-R) > 0 在回前 n 顆水球 (Ctrl-R + * Ctrl-R) * * WATERMODE(WATER_OFO) by in2 wmofo = -1 沒在回水球 = 0 正在回水球 = 1 * 回水球間又接到水球 wmofo >=0 時收到水球將只顯示, 不會到water[]裡, diff --git a/pttbbs/mbbsd/vice.c b/pttbbs/mbbsd/vice.c index d52f12ad..35a5641f 100644 --- a/pttbbs/mbbsd/vice.c +++ b/pttbbs/mbbsd/vice.c @@ -1,4 +1,4 @@ -/* $Id: vice.c,v 1.4 2002/07/05 17:10:28 in2 Exp $ */ +/* $Id: vice.c,v 1.5 2002/07/21 09:26:02 in2 Exp $ */ #include "bbs.h" #define VICE_PLAY BBSHOME "/etc/vice/vice.play" @@ -14,7 +14,7 @@ #define MAX_LOST_PICTURE 3 #define MAX_END_PICTURE 5 -static int +static int vice_load(char tbingo[6][15]) { FILE *fb = fopen(VICE_BINGO, "r"); @@ -32,7 +32,7 @@ vice_load(char tbingo[6][15]) return 0; } -static int +static int check(char tbingo[6][15], char *data) { int i = 0, j; @@ -46,8 +46,8 @@ check(char tbingo[6][15], char *data) return j - 1; return 0; } -//Ptt:showfile ran_showfile more T 怑n 膃X -static int +/* Ptt:showfile ran_showfile more 三者要合 */ +static int ran_showfile(int y, int x, char *filename, int maxnum) { FILE *fs; @@ -69,7 +69,7 @@ ran_showfile(int y, int x, char *filename, int maxnum) return 1; } -static int +static int ran_showmfile(char *filename, int maxnum) { char buf[256]; @@ -79,7 +79,7 @@ ran_showmfile(char *filename, int maxnum) } -int +int vice_main() { FILE *fd; diff --git a/pttbbs/mbbsd/vote.c b/pttbbs/mbbsd/vote.c index 8f51ee3a..f2af6047 100644 --- a/pttbbs/mbbsd/vote.c +++ b/pttbbs/mbbsd/vote.c @@ -1,4 +1,4 @@ -/* $Id: vote.c,v 1.11 2002/07/21 08:18:42 in2 Exp $ */ +/* $Id: vote.c,v 1.12 2002/07/21 09:26:02 in2 Exp $ */ #include "bbs.h" static int total; @@ -21,7 +21,7 @@ static char STR_new_comments[] = "comments0\0"; /* static char STR_new_limited[] = "limited0\0"; /* 私人投票 */ static char STR_new_title[] = "vtitle0\0"; -int +int strip_ansi(char *buf, char *str, int mode) { register int ansi, count = 0; @@ -55,7 +55,7 @@ strip_ansi(char *buf, char *str, int mode) return count; } -void +void b_suckinfile(FILE * fp, char *fname) { FILE *sfp; @@ -69,7 +69,7 @@ b_suckinfile(FILE * fp, char *fname) } } -static void +static void b_count(char *buf, int counts[]) { char inchar; @@ -89,7 +89,7 @@ b_count(char *buf, int counts[]) } -static int +static int b_nonzeroNum(char *buf) { int i = 0; @@ -105,7 +105,7 @@ b_nonzeroNum(char *buf) return i; } -static void +static void vote_report(char *bname, char *fname, char *fpath) { register char *ip; @@ -157,7 +157,7 @@ vote_report(char *bname, char *fname, char *fpath) } } -static void +static void b_result_one(boardheader_t * fh, int ind) { FILE *cfp, *tfp, *frp, *xfp; @@ -276,7 +276,7 @@ b_result_one(boardheader_t * fh, int ind) Rename(b_newresults, buf); } -static void +static void b_result(boardheader_t * fh) { FILE *cfp; @@ -303,7 +303,7 @@ b_result(boardheader_t * fh) } } -static int +static int b_close(boardheader_t * fh) { @@ -318,7 +318,7 @@ b_close(boardheader_t * fh) return 1; } -int +int b_closepolls() { static char *fn_vote_polling = ".polling"; @@ -356,7 +356,7 @@ b_closepolls() return 0; } -static int +static int vote_view(char *bname, int index) { boardheader_t *fhp; @@ -466,7 +466,7 @@ vote_view(char *bname, int index) return FULLUPDATE; } -static int +static int vote_view_all(char *bname) { int i; @@ -534,7 +534,7 @@ vote_view_all(char *bname) return FULLUPDATE; } -static int +static int vote_maintain(char *bname) { FILE *fp = NULL; @@ -727,7 +727,7 @@ vote_maintain(char *bname) return FULLUPDATE; } -static int +static int vote_flag(char *bname, int index, char val) { char buf[256], flag; @@ -758,7 +758,7 @@ vote_flag(char *bname, int index, char val) return flag; } -static int +static int same(char compare, char list[], int num) { int n; @@ -773,7 +773,7 @@ same(char compare, char list[], int num) return rep; } -static int +static int user_vote_one(char *bname, int ind) { FILE *cfp, *fcm; @@ -943,7 +943,7 @@ user_vote_one(char *bname, int ind) return FULLUPDATE; } -static int +static int user_vote(char *bname) { int pos; @@ -1033,7 +1033,7 @@ user_vote(char *bname) return FULLUPDATE; } -static int +static int vote_results(char *bname) { char buf[STRLEN]; @@ -1044,19 +1044,19 @@ vote_results(char *bname) return FULLUPDATE; } -int +int b_vote_maintain() { return vote_maintain(currboard); } -int +int b_vote() { return user_vote(currboard); } -int +int b_results() { return vote_results(currboard); diff --git a/pttbbs/mbbsd/voteboard.c b/pttbbs/mbbsd/voteboard.c index 1aa05ee9..6a7d7b87 100644 --- a/pttbbs/mbbsd/voteboard.c +++ b/pttbbs/mbbsd/voteboard.c @@ -1,9 +1,9 @@ -/* $Id: voteboard.c,v 1.11 2002/07/21 08:18:42 in2 Exp $ */ +/* $Id: voteboard.c,v 1.12 2002/07/21 09:26:02 in2 Exp $ */ #include "bbs.h" #define VOTEBOARD "NewBoard" -void +void do_voteboardreply(fileheader_t * fhdr) { char genbuf[1024]; @@ -175,7 +175,7 @@ do_voteboardreply(fileheader_t * fhdr) #endif } -int +int do_voteboard() { fileheader_t votefile; diff --git a/pttbbs/mbbsd/xyz.c b/pttbbs/mbbsd/xyz.c index 21701df8..e277421d 100644 --- a/pttbbs/mbbsd/xyz.c +++ b/pttbbs/mbbsd/xyz.c @@ -1,9 +1,9 @@ -/* $Id: xyz.c,v 1.10 2002/07/05 17:10:28 in2 Exp $ */ +/* $Id: xyz.c,v 1.11 2002/07/21 09:26:02 in2 Exp $ */ #include "bbs.h" /* 各種統計及相關資訊列表 */ /* Ptt90年度大學聯招查榜系統 */ -int +int x_90() { strcpy(dict, "(90)准考證號/姓名/學校/科系/類組"); @@ -13,7 +13,7 @@ x_90() } /* Ptt89年度大學聯招查榜系統 */ -int +int x_89() { strcpy(dict, "(89)准考證號/姓名/學校/科系/類組"); @@ -22,7 +22,7 @@ x_89() return 0; } /* Ptt88年度大學聯招查榜系統 */ -int +int x_88() { strcpy(dict, "(88)准考證號/姓名/學校/科系/類組"); @@ -31,7 +31,7 @@ x_88() return 0; } /* Ptt87年度大學聯招查榜系統 */ -int +int x_87() { strcpy(dict, "(87)准考證號/姓名/學校/科系"); @@ -41,7 +41,7 @@ x_87() } /* Ptt86年度大學聯招查榜系統 */ -int +int x_86() { strcpy(dict, "(86)准考證號/姓名/學校/科系"); @@ -50,21 +50,21 @@ x_86() return 0; } -int +int x_boardman() { more("etc/topboardman", YEA); return 0; } -int +int x_user100() { more("etc/topusr100", YEA); return 0; } -int +int x_history() { more("etc/history", YEA); @@ -72,7 +72,7 @@ x_history() } #ifdef HAVE_X_BOARDS -static int +static int x_boards() { more("etc/topboard.tmp", YEA); @@ -80,63 +80,63 @@ x_boards() } #endif -int +int x_birth() { more("etc/birth.today", YEA); return 0; } -int +int x_weather() { more("etc/weather.tmp", YEA); return 0; } -int +int x_stock() { more("etc/stock.tmp", YEA); return 0; } -int +int x_note() { more(fn_note_ans, YEA); return 0; } -int +int x_issue() { more("etc/day", YEA); return 0; } -int +int x_week() { more("etc/week", YEA); return 0; } -int +int x_today() { more("etc/today", YEA); return 0; } -int +int x_yesterday() { more("etc/yesterday", YEA); return 0; } -int +int x_login() { more("etc/Welcome_login.0", YEA); @@ -144,7 +144,7 @@ x_login() } #ifdef HAVE_INFO -static int +static int x_program() { more("etc/version", YEA); @@ -153,7 +153,7 @@ x_program() #endif #ifdef HAVE_LICENSE -static int +static int x_gpl() { more("etc/GPL", YEA); @@ -161,7 +161,7 @@ x_gpl() } #endif -int +int note() { static char *fn_note_tmp = "note.tmp"; @@ -273,7 +273,7 @@ note() return 0; } -static void +static void mail_sysop() { FILE *fp; @@ -324,7 +324,7 @@ mail_sysop() } } -int +int m_sysop() { setutmpmode(MSYSOP); @@ -332,7 +332,7 @@ m_sysop() return 0; } -int +int Goodbye() { char genbuf[100]; @@ -378,7 +378,7 @@ Goodbye() #define MAXPATHLEN 256 #ifdef HAVE_TIN -static int +static int x_tin() { clear(); @@ -387,7 +387,7 @@ x_tin() #endif #ifdef HAVE_GOPHER -static int +static int x_gopher() { clear(); @@ -396,7 +396,7 @@ x_gopher() #endif #ifdef HAVE_WWW -static int +static int x_www() { return exec_cmd(WWW, NA, "bin/www.sh", "WWW"); @@ -404,7 +404,7 @@ x_www() #endif #ifdef HAVE_IRC -static int +static int x_irc() { return exec_cmd(XMODE, NA, "bin/irc.sh", "IRC"); @@ -412,7 +412,7 @@ x_irc() #endif #ifdef HAVE_ARCHIE -static int +static int x_archie() { char buf[STRLEN], ans[4]; -- cgit v1.2.3 From eee1f55131d3ade2cd07a9b730e40598afd75e6a Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sun, 21 Jul 2002 09:33:34 +0000 Subject: in Ptt_prints(), sprintf() -> snprintf() git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@430 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/kaede.c | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/pttbbs/mbbsd/kaede.c b/pttbbs/mbbsd/kaede.c index 252984be..41b927c1 100644 --- a/pttbbs/mbbsd/kaede.c +++ b/pttbbs/mbbsd/kaede.c @@ -1,4 +1,4 @@ -/* $Id: kaede.c,v 1.10 2002/07/21 09:26:02 in2 Exp $ */ +/* $Id: kaede.c,v 1.11 2002/07/21 09:33:34 in2 Exp $ */ #include "bbs.h" char * @@ -8,14 +8,12 @@ Ptt_prints(char *str, int mode) while ((po = strstr(str, "\033*s"))) { po[0] = 0; - sprintf(strbuf, "%s%s%s", str, cuser.userid, po + 3); + snprintf(strbuf, sizeof(strbuf), "%s%s%s", str, cuser.userid, po + 3); strcpy(str, strbuf); } while ((po = strstr(str, "\033*t"))) { - po[0] = 0; - sprintf(strbuf, "%s%s", str, Cdate(&now)); - strcat(strbuf, po + 3); + snprintf(strbuf, sizeof(strbuf), "%s%s%s", str, Cdate(&now), po + 3); strcpy(str, strbuf); } while ((po = strstr(str, "\033*u"))) { @@ -23,32 +21,37 @@ Ptt_prints(char *str, int mode) attempts = SHM->UTMPnumber; po[0] = 0; - sprintf(strbuf, "%s%d%s", str, attempts, po + 3); + snprintf(strbuf, sizeof(strbuf), "%s%d%s", str, attempts, po + 3); strcpy(str, strbuf); } while ((po = strstr(str, "\033*b"))) { po[0] = 0; - sprintf(strbuf, "%s%d/%d%s", str, cuser.month, cuser.day, po + 3); + snprintf(strbuf, sizeof(strbuf), + "%s%d/%d%s", str, cuser.month, cuser.day, po + 3); strcpy(str, strbuf); } while ((po = strstr(str, "\033*l"))) { po[0] = 0; - sprintf(strbuf, "%s%d%s", str, cuser.numlogins, po + 3); + snprintf(strbuf, sizeof(strbuf), + "%s%d%s", str, cuser.numlogins, po + 3); strcpy(str, strbuf); } while ((po = strstr(str, "\033*p"))) { po[0] = 0; - sprintf(strbuf, "%s%d%s", str, cuser.numposts, po + 3); + snprintf(strbuf, sizeof(strbuf), + "%s%d%s", str, cuser.numposts, po + 3); strcpy(str, strbuf); } while ((po = strstr(str, "\033*n"))) { po[0] = 0; - sprintf(strbuf, "%s%s%s", str, cuser.username, po + 3); + snprintf(strbuf, sizeof(strbuf), + "%s%s%s", str, cuser.username, po + 3); strcpy(str, strbuf); } while ((po = strstr(str, "\033*m"))) { po[0] = 0; - sprintf(strbuf, "%s%d%s", str, cuser.money, po + 3); + snprintf(strbuf, sizeof(strbuf), + "%s%d%s", str, cuser.money, po + 3); strcpy(str, strbuf); } strip_ansi(str, str, mode); -- cgit v1.2.3 From b617736e90d62041918129d6aa222a60df7c552f Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sun, 21 Jul 2002 10:11:13 +0000 Subject: fix using strlcpy() bug git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@431 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/user.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pttbbs/mbbsd/user.c b/pttbbs/mbbsd/user.c index 60b51b1f..b830fe5c 100644 --- a/pttbbs/mbbsd/user.c +++ b/pttbbs/mbbsd/user.c @@ -1,4 +1,4 @@ -/* $Id: user.c,v 1.31 2002/07/21 09:26:02 in2 Exp $ */ +/* $Id: user.c,v 1.32 2002/07/21 10:11:13 in2 Exp $ */ #include "bbs.h" static char *sex[8] = { @@ -728,7 +728,7 @@ getfield(int line, char *info, char *desc, char *buf, int len) outs(genbuf); sprintf(prompt, "%s:", desc); if (getdata_str(line + 1, 2, prompt, genbuf, len, DOECHO, buf)) - strlcpy(buf, genbuf, sizeof(buf)); + strcpy(buf, genbuf); move(line, 2); prints("%s:%s", desc, buf); clrtoeol(); -- cgit v1.2.3 From 31f988054ac338c6b41e6242a15cb06c9c1e0495 Mon Sep 17 00:00:00 2001 From: kcwu <kcwu@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sun, 21 Jul 2002 20:39:34 +0000 Subject: check the using of `sizeof' with strlcpy() git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@432 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/include/bbs.h | 13 ++++++++++- pttbbs/mbbsd/admin.c | 6 +++--- pttbbs/mbbsd/args.c | 4 ++-- pttbbs/mbbsd/io.c | 4 ++-- pttbbs/mbbsd/mbbsd.c | 6 +++--- pttbbs/mbbsd/name.c | 4 ++-- pttbbs/mbbsd/screen.c | 4 ++-- pttbbs/mbbsd/vote.c | 60 +++++++++++++++++++++++++-------------------------- 8 files changed, 56 insertions(+), 45 deletions(-) diff --git a/pttbbs/include/bbs.h b/pttbbs/include/bbs.h index 7d2ef8d1..023ac1a2 100644 --- a/pttbbs/include/bbs.h +++ b/pttbbs/include/bbs.h @@ -49,5 +49,16 @@ #else #include <limits.h> #endif - +#ifdef DEBUG +static int Sizeof(char *what,int size,char *file,int line) +{ + if(size==4) + printf("WARRNING\r\n"); + printf("%s(%d): sizeof(%s)=%d\r\n",file,line,what,size); + return size; +} +#define SIZEOF(a) Sizeof(#a,sizeof(a),__FILE__,__LINE__) +#else +#define SIZEOF(a) sizeof(a) +#endif #endif /* INCLUDE_BBS_H */ diff --git a/pttbbs/mbbsd/admin.c b/pttbbs/mbbsd/admin.c index 8fe3621c..a9fe35ca 100644 --- a/pttbbs/mbbsd/admin.c +++ b/pttbbs/mbbsd/admin.c @@ -1,4 +1,4 @@ -/* $Id: admin.c,v 1.27 2002/07/21 09:26:02 in2 Exp $ */ +/* $Id: admin.c,v 1.28 2002/07/21 20:39:34 kcwu Exp $ */ #include "bbs.h" /* 使用者管理 */ @@ -275,7 +275,7 @@ m_mod_board(char *bname) if (genbuf[0] != 'y' || !bname[0]) outs(MSG_DEL_CANCEL); else { - strlcpy(bname, bh.brdname, sizeof(bname)); + strlcpy(bname, bh.brdname, SIZEOF(bname)); sprintf(genbuf, "/bin/tar zcvf tmp/board_%s.tgz boards/%c/%s man/boards/%c/%s >/dev/null 2>&1;" "/bin/rm -fr boards/%c/%s man/boards/%c/%s", @@ -777,7 +777,7 @@ scan_register_form(char *regfile, int automode, int neednum) *ptr = '\0'; for (n = 0; field[n]; n++) { if (strcmp(genbuf, field[n]) == 0) { - strlcpy(fdata[n], ptr + 2, sizeof(fdata[n])); + strlcpy(fdata[n], ptr + 2, SIZEOF(fdata[n])); if ((ptr = (char *)strchr(fdata[n], '\n'))) *ptr = '\0'; } diff --git a/pttbbs/mbbsd/args.c b/pttbbs/mbbsd/args.c index d1291176..e517b512 100644 --- a/pttbbs/mbbsd/args.c +++ b/pttbbs/mbbsd/args.c @@ -1,4 +1,4 @@ -/* $Id: args.c,v 1.5 2002/07/21 09:26:02 in2 Exp $ */ +/* $Id: args.c,v 1.6 2002/07/21 20:39:34 kcwu Exp $ */ #include "bbs.h" #ifdef HAVE_SETPROCTITLE @@ -49,7 +49,7 @@ do_setproctitle(const char *cmdline) if (i > LastArgv - Argv[0] - 2) { i = LastArgv - Argv[0] - 2; } - strlcpy(Argv[0], buf, sizeof(Argv[0]); + strlcpy(Argv[0], buf, SIZEOF(Argv[0]); p = &Argv[0][i]; while (p < LastArgv) *p++ = '\0'; diff --git a/pttbbs/mbbsd/io.c b/pttbbs/mbbsd/io.c index f4fd4b28..1e748cc6 100644 --- a/pttbbs/mbbsd/io.c +++ b/pttbbs/mbbsd/io.c @@ -1,4 +1,4 @@ -/* $Id: io.c,v 1.20 2002/07/21 09:26:02 in2 Exp $ */ +/* $Id: io.c,v 1.21 2002/07/21 20:39:34 kcwu Exp $ */ #include "bbs.h" #if defined(linux) @@ -474,7 +474,7 @@ oldgetdata(int line, int col, char *prompt, char *buf, int len, int echo) buf[0] = ch | 32; #ifdef SUPPORT_GB if (echo == DOECHO && current_font_type == TYPE_GB) { - strlcpy(buf, hc_convert_str(buf, HC_GBtoBIG, HC_DO_SINGLE), sizeof(buf)); + strlcpy(buf, hc_convert_str(buf, HC_GBtoBIG, HC_DO_SINGLE), SIZEOF(buf)); } #endif return clen; diff --git a/pttbbs/mbbsd/mbbsd.c b/pttbbs/mbbsd/mbbsd.c index 012974ec..6b3e15f3 100644 --- a/pttbbs/mbbsd/mbbsd.c +++ b/pttbbs/mbbsd/mbbsd.c @@ -1,4 +1,4 @@ -/* $Id: mbbsd.c,v 1.42 2002/07/21 09:26:02 in2 Exp $ */ +/* $Id: mbbsd.c,v 1.43 2002/07/21 20:39:34 kcwu Exp $ */ #include "bbs.h" #define SOCKET_QLEN 4 @@ -733,7 +733,7 @@ setup_utmp(int mode) #ifndef FAST_LOGIN setuserfile(buf, "remoteuser"); - strlcpy(remotebuf, fromhost, sizeof(remotebuf)); + strlcpy(remotebuf, fromhost, SIZEOF(remotebuf)); strcat(remotebuf, ctime(&now)); remotebuf[strlen(remotebuf) - 1] = 0; add_distinct(buf, remotebuf); @@ -1114,7 +1114,7 @@ getremotename(struct sockaddr_in * from, char *rhost, char *rname) */ if ((cp = (char *)strchr(user, '\r'))) *cp = 0; - strlcpy(rname, user, sizeof(rname)); + strlcpy(rname, user, SIZEOF(rname)); } } alarm(0); diff --git a/pttbbs/mbbsd/name.c b/pttbbs/mbbsd/name.c index 446a136f..72aba76c 100644 --- a/pttbbs/mbbsd/name.c +++ b/pttbbs/mbbsd/name.c @@ -1,4 +1,4 @@ -/* $Id: name.c,v 1.12 2002/07/21 09:26:02 in2 Exp $ */ +/* $Id: name.c,v 1.13 2002/07/21 20:39:34 kcwu Exp $ */ #include "bbs.h" static word_t *current = NULL; @@ -37,7 +37,7 @@ UserSubArray(char cwbuf[][IDLEN + 1], char cwlist[][IDLEN + 1], for (n = 0; n < cwnum; n++) { ch = cwlist[n][pos]; if (ch == key || ch == key2) - strlcpy(cwbuf[num++], cwlist[n], sizeof(cwbuf[num])); + strlcpy(cwbuf[num++], cwlist[n], SIZEOF(cwbuf[num])); } return num; } diff --git a/pttbbs/mbbsd/screen.c b/pttbbs/mbbsd/screen.c index 2650f5f9..59032a85 100644 --- a/pttbbs/mbbsd/screen.c +++ b/pttbbs/mbbsd/screen.c @@ -1,4 +1,4 @@ -/* $Id: screen.c,v 1.6 2002/07/21 09:26:02 in2 Exp $ */ +/* $Id: screen.c,v 1.7 2002/07/21 20:39:34 kcwu Exp $ */ #include "bbs.h" #ifdef SUPPORT_GB @@ -336,7 +336,7 @@ parsecolor(char *buf) } val = (char *)strtok(NULL, ";"); } - strlcpy(buf, data, sizeof(buf)); + strlcpy(buf, data, SIZEOF(buf)); } #define NORMAL (00) diff --git a/pttbbs/mbbsd/vote.c b/pttbbs/mbbsd/vote.c index f2af6047..29d648a5 100644 --- a/pttbbs/mbbsd/vote.c +++ b/pttbbs/mbbsd/vote.c @@ -1,4 +1,4 @@ -/* $Id: vote.c,v 1.12 2002/07/21 09:26:02 in2 Exp $ */ +/* $Id: vote.c,v 1.13 2002/07/21 20:39:34 kcwu Exp $ */ #include "bbs.h" static int total; @@ -180,13 +180,13 @@ b_result_one(boardheader_t * fh, int ind) fh->bvote = 1; if (ind) { - sprintf(STR_new_ballots, "%s%d", STR_bv_ballots, ind); - sprintf(STR_new_control, "%s%d", STR_bv_control, ind); - sprintf(STR_new_desc, "%s%d", STR_bv_desc, ind); - sprintf(STR_new_flags, "%s%d", STR_bv_flags, ind); - sprintf(STR_new_comments, "%s%d", STR_bv_comments, ind); - sprintf(STR_new_limited, "%s%d", STR_bv_limited, ind); - sprintf(STR_new_title, "%s%d", STR_bv_title, ind); + snprintf(STR_new_ballots, sizeof(STR_new_ballots), "%s%d", STR_bv_ballots, ind); + snprintf(STR_new_control, sizeof(STR_new_control),"%s%d", STR_bv_control, ind); + snprintf(STR_new_desc, sizeof(STR_new_desc), "%s%d", STR_bv_desc, ind); + snprintf(STR_new_flags, sizeof(STR_new_flags), "%s%d", STR_bv_flags, ind); + snprintf(STR_new_comments, sizeof(STR_new_comments), "%s%d", STR_bv_comments, ind); + snprintf(STR_new_limited, sizeof(STR_new_limited), "%s%d", STR_bv_limited, ind); + snprintf(STR_new_title, sizeof(STR_new_title), "%s%d", STR_bv_title, ind); } else { strlcpy(STR_new_ballots, STR_bv_ballots, sizeof(STR_new_ballots)); strlcpy(STR_new_control, STR_bv_control, sizeof(STR_new_control)); @@ -287,7 +287,7 @@ b_result(boardheader_t * fh) for (i = 0; i < 20; i++) { if (i) - sprintf(STR_new_control, "%s%d", STR_bv_control, i); + sprintf(STR_new_control, sizeof(STR_new_control), "%s%d", STR_bv_control, i); else strlcpy(STR_new_control, STR_bv_control, sizeof(STR_new_control)); @@ -367,13 +367,13 @@ vote_view(char *bname, int index) time_t closetime; if (index) { - sprintf(STR_new_ballots, "%s%d", STR_bv_ballots, index); - sprintf(STR_new_control, "%s%d", STR_bv_control, index); - sprintf(STR_new_desc, "%s%d", STR_bv_desc, index); - sprintf(STR_new_flags, "%s%d", STR_bv_flags, index); - sprintf(STR_new_comments, "%s%d", STR_bv_comments, index); - sprintf(STR_new_limited, "%s%d", STR_bv_limited, index); - sprintf(STR_new_title, "%s%d", STR_bv_title, index); + sprintf(STR_new_ballots, sizeof(STR_new_ballots),"%s%d", STR_bv_ballots, index); + sprintf(STR_new_control, sizeof(STR_new_control), "%s%d", STR_bv_control, index); + sprintf(STR_new_desc, sizeof(STR_new_desc), "%s%d", STR_bv_desc, index); + sprintf(STR_new_flags, sizeof(STR_new_flags), "%s%d", STR_bv_flags, index); + sprintf(STR_new_comments, sizeof(STR_new_comments), "%s%d", STR_bv_comments, index); + sprintf(STR_new_limited, sizeof(STR_new_limited), "%s%d", STR_bv_limited, index); + sprintf(STR_new_title, sizeof(STR_new_title), "%s%d", STR_bv_title, index); } else { strlcpy(STR_new_ballots, STR_bv_ballots, sizeof(STR_new_ballots)); strlcpy(STR_new_control, STR_bv_control, sizeof(STR_new_control)); @@ -618,13 +618,13 @@ vote_maintain(char *bname) if (x >= 20) return FULLUPDATE; if (x) { - sprintf(STR_new_ballots, "%s%d", STR_bv_ballots, x); - sprintf(STR_new_control, "%s%d", STR_bv_control, x); - sprintf(STR_new_desc, "%s%d", STR_bv_desc, x); - sprintf(STR_new_flags, "%s%d", STR_bv_flags, x); - sprintf(STR_new_comments, "%s%d", STR_bv_comments, x); - sprintf(STR_new_limited, "%s%d", STR_bv_limited, x); - sprintf(STR_new_title, "%s%d", STR_bv_title, x); + sprintf(STR_new_ballots, sizeof(STR_new_ballots), "%s%d", STR_bv_ballots, x); + sprintf(STR_new_control, sizeof(STR_new_control), "%s%d", STR_bv_control, x); + sprintf(STR_new_desc, sizeof(STR_new_desc), "%s%d", STR_bv_desc, x); + sprintf(STR_new_flags, sizeof(STR_new_flags), "%s%d", STR_bv_flags, x); + sprintf(STR_new_comments, sizeof(STR_new_comments), "%s%d", STR_bv_comments, x); + sprintf(STR_new_limited, sizeof(STR_new_limited), "%s%d", STR_bv_limited, x); + sprintf(STR_new_title, sizeof(STR_new_title), "%s%d", STR_bv_title, x); } else { strlcpy(STR_new_ballots, STR_bv_ballots, sizeof(STR_new_ballots)); strlcpy(STR_new_control, STR_bv_control, sizeof(STR_new_control)); @@ -734,7 +734,7 @@ vote_flag(char *bname, int index, char val) int fd, num, size; if (index) - sprintf(STR_new_flags, "%s%d", STR_bv_flags, index); + sprintf(STR_new_flags, sizeof(STR_new_flags), "%s%d", STR_bv_flags, index); else strlcpy(STR_new_flags, STR_bv_flags, sizeof(STR_new_flags)); @@ -784,12 +784,12 @@ user_vote_one(char *bname, int ind) time_t closetime; if (ind) { - sprintf(STR_new_ballots, "%s%d", STR_bv_ballots, ind); - sprintf(STR_new_control, "%s%d", STR_bv_control, ind); - sprintf(STR_new_desc, "%s%d", STR_bv_desc, ind); - sprintf(STR_new_flags, "%s%d", STR_bv_flags, ind); - sprintf(STR_new_comments, "%s%d", STR_bv_comments, ind); - sprintf(STR_new_limited, "%s%d", STR_bv_limited, ind); + sprintf(STR_new_ballots, sizeof(STR_new_ballots), "%s%d", STR_bv_ballots, ind); + sprintf(STR_new_control, sizeof(STR_new_control), "%s%d", STR_bv_control, ind); + sprintf(STR_new_desc, sizeof(STR_new_desc), "%s%d", STR_bv_desc, ind); + sprintf(STR_new_flags, sizeof(STR_new_flags),"%s%d", STR_bv_flags, ind); + sprintf(STR_new_comments, sizeof(STR_new_comments), "%s%d", STR_bv_comments, ind); + sprintf(STR_new_limited, sizeof(STR_new_limited), "%s%d", STR_bv_limited, ind); } else { strlcpy(STR_new_ballots, STR_bv_ballots, sizeof(STR_new_ballots)); strlcpy(STR_new_control, STR_bv_control, sizeof(STR_new_control)); -- cgit v1.2.3 From d1e6db6c80349c202d4b5181809856e61bebb774 Mon Sep 17 00:00:00 2001 From: kcwu <kcwu@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sun, 21 Jul 2002 20:43:35 +0000 Subject: fix last commit(about sprintf->snprintf) git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@433 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/vote.c | 46 +++++++++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/pttbbs/mbbsd/vote.c b/pttbbs/mbbsd/vote.c index 29d648a5..fb1c40e9 100644 --- a/pttbbs/mbbsd/vote.c +++ b/pttbbs/mbbsd/vote.c @@ -1,4 +1,4 @@ -/* $Id: vote.c,v 1.13 2002/07/21 20:39:34 kcwu Exp $ */ +/* $Id: vote.c,v 1.14 2002/07/21 20:43:35 kcwu Exp $ */ #include "bbs.h" static int total; @@ -287,7 +287,7 @@ b_result(boardheader_t * fh) for (i = 0; i < 20; i++) { if (i) - sprintf(STR_new_control, sizeof(STR_new_control), "%s%d", STR_bv_control, i); + snprintf(STR_new_control, sizeof(STR_new_control), "%s%d", STR_bv_control, i); else strlcpy(STR_new_control, STR_bv_control, sizeof(STR_new_control)); @@ -367,13 +367,13 @@ vote_view(char *bname, int index) time_t closetime; if (index) { - sprintf(STR_new_ballots, sizeof(STR_new_ballots),"%s%d", STR_bv_ballots, index); - sprintf(STR_new_control, sizeof(STR_new_control), "%s%d", STR_bv_control, index); - sprintf(STR_new_desc, sizeof(STR_new_desc), "%s%d", STR_bv_desc, index); - sprintf(STR_new_flags, sizeof(STR_new_flags), "%s%d", STR_bv_flags, index); - sprintf(STR_new_comments, sizeof(STR_new_comments), "%s%d", STR_bv_comments, index); - sprintf(STR_new_limited, sizeof(STR_new_limited), "%s%d", STR_bv_limited, index); - sprintf(STR_new_title, sizeof(STR_new_title), "%s%d", STR_bv_title, index); + snprintf(STR_new_ballots, sizeof(STR_new_ballots),"%s%d", STR_bv_ballots, index); + snprintf(STR_new_control, sizeof(STR_new_control), "%s%d", STR_bv_control, index); + snprintf(STR_new_desc, sizeof(STR_new_desc), "%s%d", STR_bv_desc, index); + snprintf(STR_new_flags, sizeof(STR_new_flags), "%s%d", STR_bv_flags, index); + snprintf(STR_new_comments, sizeof(STR_new_comments), "%s%d", STR_bv_comments, index); + snprintf(STR_new_limited, sizeof(STR_new_limited), "%s%d", STR_bv_limited, index); + snprintf(STR_new_title, sizeof(STR_new_title), "%s%d", STR_bv_title, index); } else { strlcpy(STR_new_ballots, STR_bv_ballots, sizeof(STR_new_ballots)); strlcpy(STR_new_control, STR_bv_control, sizeof(STR_new_control)); @@ -618,13 +618,13 @@ vote_maintain(char *bname) if (x >= 20) return FULLUPDATE; if (x) { - sprintf(STR_new_ballots, sizeof(STR_new_ballots), "%s%d", STR_bv_ballots, x); - sprintf(STR_new_control, sizeof(STR_new_control), "%s%d", STR_bv_control, x); - sprintf(STR_new_desc, sizeof(STR_new_desc), "%s%d", STR_bv_desc, x); - sprintf(STR_new_flags, sizeof(STR_new_flags), "%s%d", STR_bv_flags, x); - sprintf(STR_new_comments, sizeof(STR_new_comments), "%s%d", STR_bv_comments, x); - sprintf(STR_new_limited, sizeof(STR_new_limited), "%s%d", STR_bv_limited, x); - sprintf(STR_new_title, sizeof(STR_new_title), "%s%d", STR_bv_title, x); + snprintf(STR_new_ballots, sizeof(STR_new_ballots), "%s%d", STR_bv_ballots, x); + snprintf(STR_new_control, sizeof(STR_new_control), "%s%d", STR_bv_control, x); + snprintf(STR_new_desc, sizeof(STR_new_desc), "%s%d", STR_bv_desc, x); + snprintf(STR_new_flags, sizeof(STR_new_flags), "%s%d", STR_bv_flags, x); + snprintf(STR_new_comments, sizeof(STR_new_comments), "%s%d", STR_bv_comments, x); + snprintf(STR_new_limited, sizeof(STR_new_limited), "%s%d", STR_bv_limited, x); + snprintf(STR_new_title, sizeof(STR_new_title), "%s%d", STR_bv_title, x); } else { strlcpy(STR_new_ballots, STR_bv_ballots, sizeof(STR_new_ballots)); strlcpy(STR_new_control, STR_bv_control, sizeof(STR_new_control)); @@ -734,7 +734,7 @@ vote_flag(char *bname, int index, char val) int fd, num, size; if (index) - sprintf(STR_new_flags, sizeof(STR_new_flags), "%s%d", STR_bv_flags, index); + snprintf(STR_new_flags, sizeof(STR_new_flags), "%s%d", STR_bv_flags, index); else strlcpy(STR_new_flags, STR_bv_flags, sizeof(STR_new_flags)); @@ -784,12 +784,12 @@ user_vote_one(char *bname, int ind) time_t closetime; if (ind) { - sprintf(STR_new_ballots, sizeof(STR_new_ballots), "%s%d", STR_bv_ballots, ind); - sprintf(STR_new_control, sizeof(STR_new_control), "%s%d", STR_bv_control, ind); - sprintf(STR_new_desc, sizeof(STR_new_desc), "%s%d", STR_bv_desc, ind); - sprintf(STR_new_flags, sizeof(STR_new_flags),"%s%d", STR_bv_flags, ind); - sprintf(STR_new_comments, sizeof(STR_new_comments), "%s%d", STR_bv_comments, ind); - sprintf(STR_new_limited, sizeof(STR_new_limited), "%s%d", STR_bv_limited, ind); + snprintf(STR_new_ballots, sizeof(STR_new_ballots), "%s%d", STR_bv_ballots, ind); + snprintf(STR_new_control, sizeof(STR_new_control), "%s%d", STR_bv_control, ind); + snprintf(STR_new_desc, sizeof(STR_new_desc), "%s%d", STR_bv_desc, ind); + snprintf(STR_new_flags, sizeof(STR_new_flags),"%s%d", STR_bv_flags, ind); + snprintf(STR_new_comments, sizeof(STR_new_comments), "%s%d", STR_bv_comments, ind); + snprintf(STR_new_limited, sizeof(STR_new_limited), "%s%d", STR_bv_limited, ind); } else { strlcpy(STR_new_ballots, STR_bv_ballots, sizeof(STR_new_ballots)); strlcpy(STR_new_control, STR_bv_control, sizeof(STR_new_control)); -- cgit v1.2.3 From e6f52fda986fa96b5e589c91ef80776a41006e90 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Mon, 22 Jul 2002 16:50:36 +0000 Subject: fix utmpfix bug git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@434 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/shmctl.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/pttbbs/util/shmctl.c b/pttbbs/util/shmctl.c index bdefc8e2..34276bb0 100644 --- a/pttbbs/util/shmctl.c +++ b/pttbbs/util/shmctl.c @@ -1,4 +1,4 @@ -/* $Id: shmctl.c,v 1.24 2002/07/05 10:59:29 in2 Exp $ */ +/* $Id: shmctl.c,v 1.25 2002/07/22 16:50:36 in2 Exp $ */ #include "bbs.h" extern SHM_t *SHM; @@ -55,7 +55,7 @@ int utmpfix(int argc, char **argv) timeout = atoi(optarg); break; default: - printf("usage:\tshmctl\tutmpfix[-n] [-t timeout]\n"); + printf("usage:\tshmctl\tutmpfix [-n] [-t timeout]\n"); return 1; } @@ -79,22 +79,22 @@ int utmpfix(int argc, char **argv) purge_utmp(&SHM->uinfo[i]); } else if( !fast ){ + if( searchuser(SHM->uinfo[i].userid) == 0 ){ + clean = "user not exist"; + } #ifdef DOTIMEOUT - if( now - SHM->uinfo[i].lastact > - (timeout == -1 ? IDLE_TIMEOUT : timeout) ){ + else if( now - SHM->uinfo[i].lastact > + (timeout == -1 ? IDLE_TIMEOUT : timeout) ){ sprintf(buf, "timeout(%s", ctime(&SHM->uinfo[i].lastact)); buf[strlen(buf) - 1] = 0; strcat(buf, ")"); clean = buf; kill(SHM->uinfo[i].pid, SIGHUP); - purge_utmp(&SHM->uinfo[i]); + printf("%s\n", buf); + continue; } - else #endif - if( searchuser(SHM->uinfo[i].userid) == 0 ){ - clean = "user not exist"; - } } if( clean ){ -- cgit v1.2.3 From 09ca9301b64b0dbb552c63c7076ab9d6e7637f48 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Mon, 22 Jul 2002 19:02:01 +0000 Subject: sprintf() -> snprintf() git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@435 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/admin.c | 34 ++++++++------ pttbbs/mbbsd/announce.c | 67 +++++++++++++++------------ pttbbs/mbbsd/args.c | 6 +-- pttbbs/mbbsd/bbcall.c | 36 +++++++++------ pttbbs/mbbsd/bbs.c | 80 +++++++++++++++++--------------- pttbbs/mbbsd/board.c | 7 +-- pttbbs/mbbsd/cache.c | 18 ++++---- pttbbs/mbbsd/cal.c | 53 ++++++++++++--------- pttbbs/mbbsd/card.c | 9 ++-- pttbbs/mbbsd/chat.c | 45 ++++++++++-------- pttbbs/mbbsd/chicken.c | 97 ++++++++++++++++++++------------------ pttbbs/mbbsd/dark.c | 14 +++--- pttbbs/mbbsd/dice.c | 9 ++-- pttbbs/mbbsd/edit.c | 21 +++++---- pttbbs/mbbsd/friend.c | 23 +++++---- pttbbs/mbbsd/gamble.c | 35 +++++++------- pttbbs/mbbsd/gomo.c | 10 ++-- pttbbs/mbbsd/guess.c | 12 ++--- pttbbs/mbbsd/indict.c | 19 ++++---- pttbbs/mbbsd/io.c | 4 +- pttbbs/mbbsd/kaede.c | 11 +++-- pttbbs/mbbsd/lovepaper.c | 4 +- pttbbs/mbbsd/mail.c | 110 +++++++++++++++++++++++-------------------- pttbbs/mbbsd/mbbsd.c | 65 ++++++++++++++------------ pttbbs/mbbsd/menu.c | 30 ++++++------ pttbbs/mbbsd/more.c | 15 +++--- pttbbs/mbbsd/name.c | 4 +- pttbbs/mbbsd/osdep.c | 4 +- pttbbs/mbbsd/page.c | 6 +-- pttbbs/mbbsd/read.c | 17 +++---- pttbbs/mbbsd/record.c | 17 ++++--- pttbbs/mbbsd/register.c | 18 ++++---- pttbbs/mbbsd/screen.c | 6 +-- pttbbs/mbbsd/stuff.c | 12 ++--- pttbbs/mbbsd/syspost.c | 24 ++++++---- pttbbs/mbbsd/talk.c | 118 +++++++++++++++++++++++++++-------------------- pttbbs/mbbsd/term.c | 6 +-- pttbbs/mbbsd/user.c | 78 ++++++++++++++++--------------- pttbbs/mbbsd/vice.c | 6 +-- pttbbs/mbbsd/vote.c | 65 ++++++++++++++++---------- pttbbs/mbbsd/voteboard.c | 45 ++++++++++-------- pttbbs/mbbsd/xyz.c | 11 +++-- 42 files changed, 709 insertions(+), 562 deletions(-) diff --git a/pttbbs/mbbsd/admin.c b/pttbbs/mbbsd/admin.c index a9fe35ca..a060a123 100644 --- a/pttbbs/mbbsd/admin.c +++ b/pttbbs/mbbsd/admin.c @@ -1,4 +1,4 @@ -/* $Id: admin.c,v 1.28 2002/07/21 20:39:34 kcwu Exp $ */ +/* $Id: admin.c,v 1.29 2002/07/22 19:02:00 in2 Exp $ */ #include "bbs.h" /* 使用者管理 */ @@ -41,7 +41,7 @@ search_key_user(char *passwdfile, int mode) while ((fread(&user, sizeof(user), 1, fp1)) > 0 && coun < MAX_USERS) { if (!(++coun & 15)) { move(1, 0); - sprintf(buf, "第 [%d] 筆資料\n", coun); + snprintf(buf, sizeof(buf), "第 [%d] 筆資料\n", coun); outs(buf); refresh(); } @@ -52,7 +52,7 @@ search_key_user(char *passwdfile, int mode) strstr(user.address, key) || strstr(user.justify, key) || strstr(user.mychicken.name, key)))) { move(1, 0); - sprintf(buf, "第 [%d] 筆資料\n", coun); + snprintf(buf, sizeof(buf), "第 [%d] 筆資料\n", coun); outs(buf); refresh(); @@ -218,7 +218,7 @@ m_mod_board(char *bname) /* Ptt 這邊斷行會檔到下面 */ move(9, 0); - sprintf(genbuf, "(E)設定 (V)違法/解除 %s (D)刪除 [Q]取消?", + snprintf(genbuf, sizeof(genbuf), "(E)設定 (V)違法/解除 %s (D)刪除 [Q]取消?", HAS_PERM(PERM_SYSOP) ? " (B)BVote (S)救回文章 (G)賭盤解卡" : ""); getdata(10, 0, genbuf, ans, sizeof(ans), LCECHO); @@ -234,8 +234,9 @@ m_mod_board(char *bname) break; case 's': if (HAS_PERM(PERM_SYSOP)) { - sprintf(genbuf, BBSHOME "/bin/buildir boards/%c/%s &", - bh.brdname[0], bh.brdname); + snprintf(genbuf, sizeof(genbuf), + BBSHOME "/bin/buildir boards/%c/%s &", + bh.brdname[0], bh.brdname); system(genbuf); } break; @@ -244,7 +245,7 @@ m_mod_board(char *bname) char bvotebuf[10]; memcpy(&newbh, &bh, sizeof(bh)); - sprintf(bvotebuf, "%d", newbh.bvote); + snprintf(bvotebuf, sizeof(bvotebuf), "%d", newbh.bvote); move(20, 0); prints("看板 %s 原來的 BVote:%d", bh.brdname, bh.bvote); getdata_str(21, 0, "新的 Bvote:", genbuf, 5, LCECHO, bvotebuf); @@ -275,15 +276,16 @@ m_mod_board(char *bname) if (genbuf[0] != 'y' || !bname[0]) outs(MSG_DEL_CANCEL); else { - strlcpy(bname, bh.brdname, SIZEOF(bname)); - sprintf(genbuf, + strlcpy(bname, bh.brdname, sizeof(bh.brdname)); + snprintf(genbuf, sizeof(genbuf), "/bin/tar zcvf tmp/board_%s.tgz boards/%c/%s man/boards/%c/%s >/dev/null 2>&1;" "/bin/rm -fr boards/%c/%s man/boards/%c/%s", bname, bname[0], bname, bname[0], bname, bname[0], bname, bname[0], bname); system(genbuf); memset(&bh, 0, sizeof(bh)); - sprintf(bh.title, "%s 看板 %s 刪除", bname, cuser.userid); + snprintf(bh.title, sizeof(bh.title), + "%s 看板 %s 刪除", bname, cuser.userid); post_msg("Security", bh.title, "請注意刪除的合法性", "[系統安全局]"); substitute_record(fn_board, &bh, sizeof(bh), bid); reset_board(bid); @@ -749,7 +751,7 @@ scan_register_form(char *regfile, int automode, int neednum) int nSelf = 0, nAuto = 0; uid = cuser.userid; - sprintf(fname, "%s.tmp", regfile); + snprintf(fname, sizeof(fname), "%s.tmp", regfile); move(2, 0); if (dashf(fname)) { if (neednum == 0) { /* 自己進 Admin 來審的 */ @@ -777,7 +779,7 @@ scan_register_form(char *regfile, int automode, int neednum) *ptr = '\0'; for (n = 0; field[n]; n++) { if (strcmp(genbuf, field[n]) == 0) { - strlcpy(fdata[n], ptr + 2, SIZEOF(fdata[n])); + strlcpy(fdata[n], ptr + 2, sizeof(fdata[n])); if ((ptr = (char *)strchr(fdata[n], '\n'))) *ptr = '\0'; } @@ -877,7 +879,8 @@ scan_register_form(char *regfile, int automode, int neednum) i = buf[0] - '0'; strlcpy(buf, reason[i], sizeof(buf)); - sprintf(genbuf, "[退回原因] 請%s", buf); + snprintf(genbuf, sizeof(genbuf), + "[退回原因] 請%s", buf); sethomepath(buf1, muser.userid); stampfile(buf1, &mhdr); @@ -918,7 +921,8 @@ scan_register_form(char *regfile, int automode, int neednum) strlcpy(muser.realname, fdata[2], sizeof(muser.realname)); strlcpy(muser.address, fdata[4], sizeof(muser.address)); strlcpy(muser.email, fdata[6], sizeof(muser.email)); - sprintf(genbuf, "%s:%s:%s", fdata[5], fdata[3], uid); + snprintf(genbuf, sizeof(genbuf), + "%s:%s:%s", fdata[5], fdata[3], uid); strncpy(muser.justify, genbuf, REGLEN); sethomefile(buf, muser.userid, "justify"); log_file(buf, genbuf); @@ -1029,7 +1033,7 @@ give_id_money(char *user_id, int money, FILE * log_fp, char *mail_title, time_t pressanykey(); } else { fprintf(log_fp, "%ld %s %d", t, user_id, money); - sprintf(tt, "%s : %d ptt 幣", mail_title, money); + snprintf(tt, sizeof(tt), "%s : %d ptt 幣", mail_title, money); mail_id(user_id, tt, "~bbs/etc/givemoney.why", "[PTT 銀行]"); } } diff --git a/pttbbs/mbbsd/announce.c b/pttbbs/mbbsd/announce.c index 5df8a9fa..8413897b 100644 --- a/pttbbs/mbbsd/announce.c +++ b/pttbbs/mbbsd/announce.c @@ -1,4 +1,4 @@ -/* $Id: announce.c,v 1.15 2002/07/21 09:26:02 in2 Exp $ */ +/* $Id: announce.c,v 1.16 2002/07/22 19:02:00 in2 Exp $ */ #include "bbs.h" static void @@ -403,7 +403,7 @@ a_showmenu(menu_t * pm) /* * Ptt 把時間改為取檔案時間 dtime = atoi(&item->filename[2]); */ - sprintf(buf, "%s/%s", pm->path, item->filename); + snprintf(buf, sizeof(buf), "%s/%s", pm->path, item->filename); dtime = dasht(buf); a_timestamp(buf, &dtime); prints("\n%6d%c %-47.46s%-13s[%s]", pm->page + n + 1, @@ -629,7 +629,7 @@ gem(char *maintitle, item_t * path, int update) } else stampdir(newpath, &item); strlcpy(item.owner, cuser.userid, sizeof(item.owner)); - sprintf(item.title, "%s%.72s", + snprintf(item.title, sizeof(item.title), "%s%.72s", (currutmp->pager > 1) ? "" : (mode == (char)0xbc) ? "◇ " : "◆ ", title + 3); @@ -806,19 +806,19 @@ a_newitem(menu_t * pm, int mode) for (d = 0; d <= 3; d++) { switch (d) { case 0: - sprintf(lpath, BBSHOME "/man/boards/%c/%s/%s", + snprintf(lpath, sizeof(lpath), BBSHOME "/man/boards/%c/%s/%s", currboard[0], currboard, buf); break; case 1: - sprintf(lpath, "%s%s/%c/%s", + snprintf(lpath, sizeof(lpath), "%s%s/%c/%s", BBSHOME, "/man/boards/", buf[0], buf); break; case 2: - sprintf(lpath, "%s%s%s", + snprintf(lpath, sizeof(lpath), "%s%s%s", BBSHOME, "/", buf); break; case 3: - sprintf(lpath, "%s%s%s", + snprintf(lpath, sizeof(lpath), "%s%s%s", BBSHOME, "/etc/", buf); break; } @@ -894,7 +894,8 @@ a_pasteitem(menu_t * pm, int mode) } } if (mode) { - sprintf(buf, "確定要拷貝[%s]嗎(Y/N)?[N] ", copytitle); + snprintf(buf, sizeof(buf), + "確定要拷貝[%s]嗎(Y/N)?[N] ", copytitle); getdata(b_lines - 1, 1, buf, ans, sizeof(ans), LCECHO); } else ans[0] = 'y'; @@ -916,18 +917,20 @@ a_pasteitem(menu_t * pm, int mode) if (HAS_PERM(PERM_BBSADM)) Link(copyfile, newpath); else { - sprintf(buf, "/bin/cp %s %s", copyfile, newpath); + snprintf(buf, sizeof(buf), + "/bin/cp %s %s", copyfile, newpath); system(buf); } } else if (dashf(copyfile)) { stampfile(newpath, &item); memcpy(copytitle, "◇", 2); - sprintf(buf, "/bin/cp %s %s", copyfile, newpath); + snprintf(buf, sizeof(buf), "/bin/cp %s %s", copyfile, newpath); } else if (dashd(copyfile)) { stampdir(newpath, &item); memcpy(copytitle, "◆", 2); - sprintf(buf, "/bin/cp -r %s/* %s/.D* %s", copyfile, copyfile, - newpath); + snprintf(buf, sizeof(buf), + "/bin/cp -r %s/* %s/.D* %s", copyfile, copyfile, + newpath); } else { outs("無法拷貝!"); igetch(); @@ -958,12 +961,12 @@ a_appenditem(menu_t * pm, int isask) move(b_lines - 1, 1); if (copyfile[0]) { if (dashf(copyfile)) { - sprintf(fname, "%s/%s", pm->path, + snprintf(fname, sizeof(fname), "%s/%s", pm->path, pm->header[pm->now - pm->page].filename); if (dashf(fname)) { if (isask) { - sprintf(buf, "確定要將[%s]附加於此嗎(Y/N)?[N] ", - copytitle); + snprintf(buf, sizeof(buf), + "確定要將[%s]附加於此嗎(Y/N)?[N] ", copytitle); getdata(b_lines - 2, 1, buf, ans, sizeof(ans), LCECHO); } if (ans[0] == 'y') { @@ -1046,7 +1049,7 @@ a_moveitem(menu_t * pm) char buf[PATHLEN]; int fail; - sprintf(buf, "請輸入第 %d 選項的新次序:", pm->now + 1); + snprintf(buf, sizeof(buf), "請輸入第 %d 選項的新次序:", pm->now + 1); if (!getdata(b_lines - 1, 1, buf, newnum, sizeof(newnum), DOECHO)) return; num = (newnum[0] == '$') ? 9999 : atoi(newnum) - 1; @@ -1084,7 +1087,7 @@ a_delrange(menu_t * pm) { char fname[256]; - sprintf(fname, "%s/.DIR", pm->path); + snprintf(fname, sizeof(fname), "%s/.DIR", pm->path); del_range(0, NULL, fname); pm->num = get_num_records(fname, FHSZ); } @@ -1096,7 +1099,8 @@ a_delete(menu_t * pm) char ans[4]; fileheader_t backup; - sprintf(fpath, "%s/%s", pm->path, pm->header[pm->now - pm->page].filename); + snprintf(fpath, sizeof(fpath), + "%s/%s", pm->path, pm->header[pm->now - pm->page].filename); setadir(buf, pm->path); if (pm->header[pm->now - pm->page].filename[0] == 'H' && @@ -1130,7 +1134,8 @@ a_delete(menu_t * pm) pm->header[pm->now - pm->page].title + 2, sizeof(backup.title)); - sprintf(cmd, "mv -f %s %s", fpath, buf); + snprintf(cmd, sizeof(cmd), + "mv -f %s %s", fpath, buf); system(cmd); setbdir(buf, "deleted"); append_record(buf, &backup, sizeof(backup)); @@ -1145,7 +1150,8 @@ a_delete(menu_t * pm) setapath(buf, "deleted"); stampdir(buf, &backup); - sprintf(cmd, "rm -rf %s;/bin/mv -f %s %s", buf, fpath, buf); + snprintf(cmd, sizeof(cmd), + "rm -rf %s;/bin/mv -f %s %s", buf, fpath, buf); system(cmd); strlcpy(backup.owner, cuser.userid, sizeof(backup.owner)); @@ -1202,7 +1208,7 @@ a_editsign(menu_t * pm) fileheader_t item; memcpy(&item, &pm->header[pm->now - pm->page], FHSZ); - sprintf(buf, "%c%c", item.title[0], item.title[1]); + snprintf(buf, sizeof(buf), "%c%c", item.title[0], item.title[1]); if (getdata_buf(b_lines - 1, 1, "符號", buf, 5, DOECHO)) { item.title[0] = buf[0] ? buf[0] : ' '; item.title[1] = buf[1] ? buf[1] : ' '; @@ -1221,7 +1227,8 @@ a_showname(menu_t * pm) int sym; move(b_lines - 1, 1); - sprintf(buf, "%s/%s", pm->path, pm->header[pm->now - pm->page].filename); + snprintf(buf, sizeof(buf), + "%s/%s", pm->path, pm->header[pm->now - pm->page].filename); if (dashl(buf)) { prints("此 symbolic link 名稱為 %s\n", pm->header[pm->now - pm->page].filename); @@ -1392,7 +1399,8 @@ a_menu(char *maintitle, char *path, int lastlevel) case 'e': case 'E': - sprintf(fname, "%s/%s", path, me.header[me.now - me.page].filename); + snprintf(fname, sizeof(fname), + "%s/%s", path, me.header[me.now - me.page].filename); if (dashf(fname) && me.level >= MANAGER) { *quote_file = 0; if (vedit(fname, NA, NULL) != -1) { @@ -1421,8 +1429,8 @@ a_menu(char *maintitle, char *path, int lastlevel) if (me.now < me.num) { if (!isvisible_man(&me)) break; - sprintf(fname, "%s/%s", path, - me.header[me.now - me.page].filename); + snprintf(fname, sizeof(fname), "%s/%s", path, + me.header[me.now - me.page].filename); a_copyitem(fname, me.header[me.now - me.page].title, 0, 1); me.page = 9999; break; @@ -1435,7 +1443,7 @@ a_menu(char *maintitle, char *path, int lastlevel) fileheader_t *fhdr = &me.header[me.now - me.page]; if (!isvisible_man(&me)) break; - sprintf(fname, "%s/%s", path, fhdr->filename); + snprintf(fname, sizeof(fname), "%s/%s", path, fhdr->filename); if (*fhdr->filename == 'H' && fhdr->filename[1] == '.') { item_t item; strlcpy(item.X.G.server, fhdr->filename + 2, @@ -1483,8 +1491,8 @@ a_menu(char *maintitle, char *path, int lastlevel) break; if (!isvisible_man(&me)) break; - sprintf(fname, "%s/%s", path, - me.header[me.now - me.page].filename); + snprintf(fname, sizeof(fname), "%s/%s", path, + me.header[me.now - me.page].filename); if (!dashf(fname)) break; } @@ -1502,7 +1510,8 @@ a_menu(char *maintitle, char *path, int lastlevel) case 'F': case 'U': - sprintf(fname, "%s/%s", path, me.header[me.now - me.page].filename); + snprintf(fname, sizeof(fname), + "%s/%s", path, me.header[me.now - me.page].filename); if (me.now < me.num && HAS_PERM(PERM_BASIC) && dashf(fname)) { a_forward(path, &me.header[me.now - me.page], ch /* == 'U' */ ); /* By CharlieL */ diff --git a/pttbbs/mbbsd/args.c b/pttbbs/mbbsd/args.c index e517b512..1d128673 100644 --- a/pttbbs/mbbsd/args.c +++ b/pttbbs/mbbsd/args.c @@ -1,4 +1,4 @@ -/* $Id: args.c,v 1.6 2002/07/21 20:39:34 kcwu Exp $ */ +/* $Id: args.c,v 1.7 2002/07/22 19:02:00 in2 Exp $ */ #include "bbs.h" #ifdef HAVE_SETPROCTITLE @@ -49,7 +49,7 @@ do_setproctitle(const char *cmdline) if (i > LastArgv - Argv[0] - 2) { i = LastArgv - Argv[0] - 2; } - strlcpy(Argv[0], buf, SIZEOF(Argv[0]); + strlcpy(Argv[0], buf, sizeof(buf)); p = &Argv[0][i]; while (p < LastArgv) *p++ = '\0'; @@ -62,7 +62,7 @@ setproctitle(const char *format,...) char buf[256]; va_list args; va_start(args, format); - vsprintf(buf, format, args); + vsnprintf(buf, sizeof(buf), format, args); do_setproctitle(buf); va_end(args); } diff --git a/pttbbs/mbbsd/bbcall.c b/pttbbs/mbbsd/bbcall.c index c3527e01..676816f7 100644 --- a/pttbbs/mbbsd/bbcall.c +++ b/pttbbs/mbbsd/bbcall.c @@ -1,4 +1,4 @@ -/* $Id: bbcall.c,v 1.7 2002/07/21 09:26:02 in2 Exp $ */ +/* $Id: bbcall.c,v 1.8 2002/07/22 19:02:00 in2 Exp $ */ #include "bbs.h" #define SERVER_0941 "www.chips.com.tw" @@ -144,7 +144,8 @@ static void halpha0943(char* CoId) { char Msg[64], atrn[512], sendform[1024]; int Year = 99, Month = 1, Day = 15, Hour = 13, Minute = 8; - sprintf(tmpbuf, "\033[1;37m請輸入您要傳呼的號碼\033[m : %s-", CoId); + snprintf(tmpbuf, sizeof(tmpbuf), + "\033[1;37m請輸入您要傳呼的號碼\033[m : %s-", CoId); if(!getdata(7,0, tmpbuf, ID, sizeof(ID), LCECHO) || !getdata(8,0, "\033[1;37m請輸入傳呼訊息\033[m:", tmpbuf, 63, LCECHO)) { hpressanykey("放棄傳呼"); @@ -157,10 +158,11 @@ static void halpha0943(char* CoId) { if(ans[0] != '1') Gettime(0, &Year, &Month, &Day, &Hour, &Minute); - sprintf(atrn, "CoId=%s&ID=%s&Year=19%02d&Month=%02d&Day=%02d" - "&Hour=%02d&Minute=%02d&Msg=%s", - CoId, ID,Year,Month,Day,Hour,Minute,Msg); - sprintf(sendform, "POST %s HTTP/1.0\nReferer: " + snprintf(atrn, sizeof(atrn), + "CoId=%s&ID=%s&Year=19%02d&Month=%02d&Day=%02d" + "&Hour=%02d&Minute=%02d&Msg=%s", + CoId, ID,Year,Month,Day,Hour,Minute,Msg); + snprintf(sendform, sizeof(sendform), "POST %s HTTP/1.0\nReferer: " "%s\n%sContent-length:%d\n\n%s", CGI_0943, REFER_0943, PARA, strlen(atrn), atrn); Connect(sendform, SERVER_0943); @@ -187,13 +189,15 @@ static void hcall0941() { Gettime(0, &year, &month, &day, &hour, &min); } else strlcpy(TIME, "NOW", sizeof(TIME)); - sprintf(trn,"PAGER_NO=%s&TRAN_MSG=%s&MSG_TYPE=NUMERIC&%s=1" - "&year=19%02d&month=%02d&day=%02d&hour=%02d&min=%02d", - PAGER_NO, TRAN_MSG, TIME,year,month,day,hour,min); + snprintf(trn, sizeof(trn), + "PAGER_NO=%s&TRAN_MSG=%s&MSG_TYPE=NUMERIC&%s=1" + "&year=19%02d&month=%02d&day=%02d&hour=%02d&min=%02d", + PAGER_NO, TRAN_MSG, TIME,year,month,day,hour,min); - sprintf(sendform, "POST %s HTTP/1.0\nReferer: %s\n%s" - "Content-length:%d\n\n%s", - CGI_0941, REFER_0941, PARA, strlen(trn), trn); + snprintf(sendform, sizeof(sendform), + "POST %s HTTP/1.0\nReferer: %s\n%s" + "Content-length:%d\n\n%s", + CGI_0941, REFER_0941, PARA, strlen(trn), trn); Connect(sendform, SERVER_0941); return ; @@ -220,11 +224,13 @@ static void hcall0948() { ya = 1; } - sprintf(trn, "MfcISAPICommand=SinglePage&svc_no=%s&reminder=%d" - "&year=%02d&month=%02d&day=%02d&hour=%02d&min=%02d&message=%s", + snprintf(trn, sizeof(trn), + "MfcISAPICommand=SinglePage&svc_no=%s&reminder=%d" + "&year=%02d&month=%02d&day=%02d&hour=%02d&min=%02d&message=%s", svc_no, ya, year, month, day, hour, min, message); - sprintf(sendform, "GET %s?%s Http/1.0\n\n", CGI_0948, trn); + snprintf(sendform, sizeof(sendform), + "GET %s?%s Http/1.0\n\n", CGI_0948, trn); Connect(sendform, SERVER_0948); return; diff --git a/pttbbs/mbbsd/bbs.c b/pttbbs/mbbsd/bbs.c index a706ff0c..84749b1c 100644 --- a/pttbbs/mbbsd/bbs.c +++ b/pttbbs/mbbsd/bbs.c @@ -1,4 +1,4 @@ -/* $Id: bbs.c,v 1.65 2002/07/21 09:26:02 in2 Exp $ */ +/* $Id: bbs.c,v 1.66 2002/07/22 19:02:00 in2 Exp $ */ #include "bbs.h" static void @@ -7,13 +7,15 @@ mail_by_link(char *owner, char *title, char *path) char genbuf[200]; fileheader_t mymail; - sprintf(genbuf, BBSHOME "/home/%c/%s", cuser.userid[0], cuser.userid); + snprintf(genbuf, sizeof(genbuf), + BBSHOME "/home/%c/%s", cuser.userid[0], cuser.userid); stampfile(genbuf, &mymail); strlcpy(mymail.owner, owner, sizeof(mymail.owner)); - sprintf(mymail.title, title); + snprintf(mymail.title, sizeof(mymail.title), title); unlink(genbuf); Link(path, genbuf); - sprintf(genbuf, BBSHOME "/home/%c/%s/.DIR", cuser.userid[0], cuser.userid); + snprintf(genbuf, sizeof(genbuf), + BBSHOME "/home/%c/%s/.DIR", cuser.userid[0], cuser.userid); append_record(genbuf, &mymail, sizeof(mymail)); } @@ -24,7 +26,7 @@ anticrosspost() { char buf[200]; - sprintf(buf, + snprintf(buf, sizeof(buf), "\033[1;33;46m%s \033[37;45mcross post 文章 \033[37m %s\033[m", cuser.userid, ctime(&now)); log_file("etc/illegal_money", buf); @@ -55,9 +57,9 @@ save_violatelaw() } reload_money(); if (cuser.money < (int)cuser.vl_count * 1000) { - sprintf(buf, "\033[1;31m這是你第 %d 次違反本站法規" - "必須繳出 %d $Ptt ,你只有 %d 元, 錢不夠啦!!\033[m", - (int)cuser.vl_count, (int)cuser.vl_count * 1000, cuser.money); + snprintf(buf, sizeof(buf), "\033[1;31m這是你第 %d 次違反本站法規" + "必須繳出 %d $Ptt ,你只有 %d 元, 錢不夠啦!!\033[m", + (int)cuser.vl_count, (int)cuser.vl_count * 1000, cuser.money); mprints(22, 0, buf); pressanykey(); return 0; @@ -74,8 +76,8 @@ save_violatelaw() pressanykey(); return 0; } - sprintf(buf, "這是你第 %d 次違法 必須繳出 %d $Ptt", - cuser.vl_count, cuser.vl_count * 1000); + snprintf(buf, sizeof(buf), "這是你第 %d 次違法 必須繳出 %d $Ptt", + cuser.vl_count, cuser.vl_count * 1000); mprints(11, 0, buf); if (!getdata(10, 0, "要付錢[y/n]:", ok, sizeof(ok), LCECHO) || @@ -108,7 +110,7 @@ set_board() brd_title = bp->BM; if (brd_title[0] <= ' ') brd_title = "徵求中"; - sprintf(currBM, "板主:%s", brd_title); + snprintf(currBM, sizeof(currBM), "板主:%s", brd_title); brd_title = ((bp->bvote != 2 && bp->bvote) ? "本看板進行投票中" : bp->title + 7); currmode = (currmode & (MODE_DIRTY | MODE_MENU)) | MODE_STARTED; @@ -359,11 +361,11 @@ do_reply_title(int row, char *title) char genbuf2[4]; if (strncasecmp(title, str_reply, 4)) - sprintf(save_title, "Re: %s", title); + snprintf(save_title, sizeof(save_title), "Re: %s", title); else strlcpy(save_title, title, sizeof(save_title)); save_title[TTLEN - 1] = '\0'; - sprintf(genbuf, "採用原標題《%.60s》嗎?[Y] ", save_title); + snprintf(genbuf, sizeof(genbuf), "採用原標題《%.60s》嗎?[Y] ", save_title); getdata(row, 0, genbuf, genbuf2, 4, LCECHO); if (genbuf2[0] == 'n' || genbuf2[0] == 'N') getdata(++row, 0, "標題:", save_title, TTLEN, DOECHO); @@ -446,7 +448,8 @@ do_general() save_title, 3, LCECHO); local_article = save_title[0] - '1'; if (local_article >= 0 && local_article <= 6) - sprintf(save_title, "[%s] ", ctype[local_article]); + snprintf(save_title, sizeof(save_title), + "[%s] ", ctype[local_article]); else save_title[0] = '\0'; getdata_buf(22, 0, "標題:", save_title, TTLEN, DOECHO); @@ -799,11 +802,11 @@ cross_post(int ent, fileheader_t * fhdr, char *direct) } } if (ent) - sprintf(xtitle, "[轉錄]%.66s", fhdr->title); + snprintf(xtitle, sizeof(xtitle), "[轉錄]%.66s", fhdr->title); else strlcpy(xtitle, fhdr->title, sizeof(xtitle)); - sprintf(genbuf, "採用原標題《%.60s》嗎?[Y] ", xtitle); + snprintf(genbuf, sizeof(genbuf), "採用原標題《%.60s》嗎?[Y] ", xtitle); getdata(2, 0, genbuf, genbuf2, 4, LCECHO); if (genbuf2[0] == 'n' || genbuf2[0] == 'N') { if (getdata_str(2, 0, "標題:", genbuf, TTLEN, DOECHO, xtitle)) @@ -980,7 +983,7 @@ b_man() if ((currmode & MODE_BOARD) || HAS_PERM(PERM_SYSOP)) { char genbuf[128]; int fd; - sprintf(genbuf, "%s/.rebuild", buf); + snprintf(genbuf, sizeof(genbuf), "%s/.rebuild", buf); if ((fd = open(genbuf, O_CREAT, 0640)) > 0) close(fd); } @@ -1082,17 +1085,18 @@ hold_gamble(int ent, fileheader_t * fhdr, char *direct) substitute_record(fn_board, bp, sizeof(boardheader_t), currbid); } move(6, 0); - sprintf(genbuf, "請到 %s 板 按'f'參與賭博!\n\n一張 %d Ptt幣, 這是%s的賭博\n%s%s", - currboard, - i, i < 100 ? "小賭式" : i < 500 ? "平民級" : - i < 1000 ? "貴族級" : i < 5000 ? "富豪級" : "傾家蕩產", - bp->endgamble ? "賭盤結束時間: " : "", - bp->endgamble ? Cdate(&bp->endgamble) : "" - ); + snprintf(genbuf, sizeof(genbuf), + "請到 %s 板 按'f'參與賭博!\n\n一張 %d Ptt幣, 這是%s的賭博\n%s%s", + currboard, + i, i < 100 ? "小賭式" : i < 500 ? "平民級" : + i < 1000 ? "貴族級" : i < 5000 ? "富豪級" : "傾家蕩產", + bp->endgamble ? "賭盤結束時間: " : "", + bp->endgamble ? Cdate(&bp->endgamble) : "" + ); strcat(msg, genbuf); prints("請依次輸入彩票名稱, 需提供2~8項. (未滿八項, 輸入直接按enter)\n"); for (i = 0; i < 8; i++) { - sprintf(yn, " %d)", i + 1); + snprintf(yn, sizeof(yn), " %d)", i + 1); getdata(7 + i, 0, yn, genbuf, 9, DOECHO); if (!genbuf[0] && i > 1) break; @@ -1101,7 +1105,7 @@ hold_gamble(int ent, fileheader_t * fhdr, char *direct) fclose(fp); move(8 + i, 0); prints("賭盤設定完成"); - sprintf(genbuf, "[公告] %s 板 開始賭博!", currboard); + snprintf(genbuf, sizeof(genbuf), "[公告] %s 板 開始賭博!", currboard); post_msg(currboard, genbuf, msg, cuser.userid); post_msg("Record", genbuf + 7, msg, "[馬路探子]"); /* Tim 控制CS, 以免正在玩的user把資料已經寫進來 */ @@ -1146,7 +1150,7 @@ edit_title(int ent, fileheader_t * fhdr, char *direct) dirty++; } if (getdata(b_lines - 1, 0, "日期:", genbuf, 6, DOECHO)) { - sprintf(tmpfhdr.date, "%.5s", genbuf); + snprintf(tmpfhdr.date, sizeof(tmpfhdr.date), "%.5s", genbuf); dirty++; } } @@ -1223,11 +1227,11 @@ recommend(int ent, fileheader_t * fhdr, char *direct) || yn[0] != 'y') return FULLUPDATE; - sprintf(buf, - "\033[1;31m→ \033[33m%s\033[m\033[33m:%s\033[m%*s推薦自:%s %02d/%02d\n", - cuser.userid, path, - 45 - strlen(cuser.userid) - strlen(path), " ", fromhost, - ptime->tm_mon + 1, ptime->tm_mday); + snprintf(buf, sizeof(buf), + "\033[1;31m→ \033[33m%s\033[m\033[33m:%s\033[m%*s推薦自:%s %02d/%02d\n", + cuser.userid, path, + 45 - strlen(cuser.userid) - strlen(path), " ", fromhost, + ptime->tm_mon + 1, ptime->tm_mday); setdirpath(path, direct, fhdr->filename); log_file(path, buf); if (fhdr->recommend < 9) { @@ -1429,7 +1433,7 @@ tar_addqueue(int ent, fileheader_t * fhdr, char *direct) pressanykey(); return FULLUPDATE; } - sprintf(qfn, BBSHOME "/jobspool/tarqueue.%s", currboard); + snprintf(qfn, sizeof(qfn), BBSHOME "/jobspool/tarqueue.%s", currboard); if (access(qfn, 0) == 0) { outs("已經排定行程, 稍後會進行備份"); pressanykey(); @@ -1699,7 +1703,7 @@ board_select() char genbuf[100]; currmode &= ~MODE_SELECT; - sprintf(fpath, "SR.%s", cuser.userid); + snprintf(fpath, sizeof(fpath), "SR.%s", cuser.userid); setbfile(genbuf, currboard, fpath); unlink(genbuf); if (currstat == RMAIL) @@ -1768,13 +1772,13 @@ good_post(int ent, fileheader_t * fhdr, char *direct) strlcpy(buf, direct, sizeof(buf)); ptr = strrchr(buf, '/') + 1; ptr[0] = '\0'; - sprintf(genbuf, "%s%s", buf, digest.filename); + snprintf(genbuf, sizeof(genbuf), "%s%s", buf, digest.filename); if (dashf(genbuf)) unlink(genbuf); digest.filemode = 0; - sprintf(genbuf2, "%s%s", buf, fhdr->filename); + snprintf(genbuf2, sizeof(genbuf2), "%s%s", buf, fhdr->filename); Link(genbuf2, genbuf); strcpy(ptr, fn_mandex); append_record(buf, &digest, sizeof(digest)); @@ -2008,8 +2012,8 @@ log_board(char *mode, time_t usetime) char buf[256]; if (usetime > 30) { - sprintf(buf, "USE %-20.20s Stay: %5ld (%s) %s", - mode, usetime, cuser.userid, ctime(&now)); + snprintf(buf, sizeof(buf), "USE %-20.20s Stay: %5ld (%s) %s", + mode, usetime, cuser.userid, ctime(&now)); log_file(FN_USEBOARD, buf); } } diff --git a/pttbbs/mbbsd/board.c b/pttbbs/mbbsd/board.c index d6d8c8ea..cbbfea1b 100644 --- a/pttbbs/mbbsd/board.c +++ b/pttbbs/mbbsd/board.c @@ -1,4 +1,4 @@ -/* $Id: board.c,v 1.42 2002/07/21 09:26:02 in2 Exp $ */ +/* $Id: board.c,v 1.43 2002/07/22 19:02:00 in2 Exp $ */ #include "bbs.h" #define BRC_STRLEN 15 /* Length of board name */ #define BRC_MAXSIZE 24576 @@ -328,8 +328,9 @@ have_author(char *brdname) { char dirname[100]; - sprintf(dirname, "正在搜尋作者%s 看板:%s.....", - currauthor, brdname); + snprintf(dirname, sizeof(dirname), + "正在搜尋作者%s 看板:%s.....", + currauthor, brdname); move(b_lines, 0); clrtoeol(); outs(dirname); diff --git a/pttbbs/mbbsd/cache.c b/pttbbs/mbbsd/cache.c index fd61cf55..0ceb8376 100644 --- a/pttbbs/mbbsd/cache.c +++ b/pttbbs/mbbsd/cache.c @@ -1,4 +1,4 @@ -/* $Id: cache.c,v 1.43 2002/07/21 09:26:02 in2 Exp $ */ +/* $Id: cache.c,v 1.44 2002/07/22 19:02:00 in2 Exp $ */ #include "bbs.h" #ifndef __FreeBSD__ @@ -42,7 +42,7 @@ safe_sleep(unsigned int seconds) static void setapath(char *buf, char *boardname) { - sprintf(buf, "man/boards/%c/%s", boardname[0], boardname); + snprintf(buf, "man/boards/%c/%s", boardname[0], boardname); } static char *str_dotdir = ".DIR"; @@ -329,8 +329,8 @@ setutmpmode(int mode) /* 追蹤使用者 */ if (HAS_PERM(PERM_LOGUSER)) { char msg[200]; - sprintf(msg, "%s setutmpmode to %s(%d) at %s", - cuser.userid, modestring(currutmp, 0), mode, Cdate(&now)); + snprintf(msg, sizeof(msg), "%s setutmpmode to %s(%d) at %s", + cuser.userid, modestring(currutmp, 0), mode, Cdate(&now)); log_user(msg); } } @@ -779,7 +779,8 @@ setbtotal(int bid) char genbuf[256]; int num, fd; - sprintf(genbuf, "boards/%c/%s/.DIR", bh->brdname[0], bh->brdname); + snprintf(genbuf, sizeof(genbuf), + "boards/%c/%s/.DIR", bh->brdname[0], bh->brdname); if ((fd = open(genbuf, O_RDWR)) < 0) return; /* .DIR掛了 */ @@ -892,15 +893,16 @@ reload_pttcache() if ((fp = fopen(buf, "r"))) { while (fread(&item, sizeof(item), 1, fp)) { if (item.title[3] == '<' && item.title[8] == '>') { - sprintf(buf, "%s/%s", pbuf, item.filename); + snprintf(buf, sizeof(buf), "%s/%s", pbuf, item.filename); setadir(buf, buf); if (!(fp1 = fopen(buf, "r"))) continue; SHM->next_refresh[section] = SHM->n_notes[section] = id; section++; while (fread(&subitem, sizeof(subitem), 1, fp1)) { - sprintf(buf, "%s/%s/%s", pbuf, item.filename, - subitem.filename); + snprintf(buf, sizeof(buf), + "%s/%s/%s", pbuf, item.filename, + subitem.filename); if (!(fp2 = fopen(buf, "r"))) continue; fread(SHM->notes[id], sizeof(char), 200 * 11, fp2); diff --git a/pttbbs/mbbsd/cal.c b/pttbbs/mbbsd/cal.c index fb0c2802..ee23879b 100644 --- a/pttbbs/mbbsd/cal.c +++ b/pttbbs/mbbsd/cal.c @@ -1,4 +1,4 @@ -/* $Id: cal.c,v 1.18 2002/07/21 09:26:02 in2 Exp $ */ +/* $Id: cal.c,v 1.19 2002/07/22 19:02:00 in2 Exp $ */ #include "bbs.h" /* 防堵 Multi play */ @@ -63,15 +63,16 @@ vice(int money, char *item) unsigned int viceserial = (currutmp->lastact % 1000000) * 100 + rand() % 100; FILE *fp; demoney(-money); - sprintf(buf, BBSHOME "/home/%c/%s/%s", - cuser.userid[0], cuser.userid, VICE_NEW); + snprintf(buf, sizeof(buf), BBSHOME "/home/%c/%s/%s", + cuser.userid[0], cuser.userid, VICE_NEW); fp = fopen(buf, "a"); if (!fp) { return 0; } fprintf(fp, "%08d\n", viceserial); fclose(fp); - sprintf(buf, "%s 花了%d$ 編號[%08d]", item, money, viceserial); + snprintf(buf, sizeof(buf), + "%s 花了%d$ 編號[%08d]", item, money, viceserial); mail_id(cuser.userid, buf, "etc/vice.txt", "Ptt經濟部"); return 0; } @@ -117,7 +118,8 @@ osong(char *defaultid) } move(12, 0); clrtobot(); - sprintf(buf, "親愛的 %s 歡迎來到歐桑自動點歌系統\n", cuser.userid); + snprintf(buf, sizeof(buf), + "親愛的 %s 歡迎來到歐桑自動點歌系統\n", cuser.userid); outs(buf); trans_buffer[0] = 0; if (!defaultid) { @@ -141,7 +143,8 @@ osong(char *defaultid) } getdata_str(14, 0, "想要要對他(她)說..:", say, sizeof(say), DOECHO, "我愛妳.."); - sprintf(save_title, "%s:%s", (ano[0] == 'y') ? "匿名者" : cuser.userid, say); + snprintf(save_title, sizeof(save_title), + "%s:%s", (ano[0] == 'y') ? "匿名者" : cuser.userid, say); getdata_str(16, 0, "寄到誰的信箱(可用E-mail)?", receiver, sizeof(receiver), LCECHO, destid); @@ -167,7 +170,9 @@ osong(char *defaultid) return 0; } strlcpy(mail.owner, "點歌機", sizeof(mail.owner)); - sprintf(mail.title, "◇ %s 點給 %s ", (ano[0] == 'y') ? "匿名者" : cuser.userid, destid); + snprintf(mail.title, sizeof(mail.title), + "◇ %s 點給 %s ", + (ano[0] == 'y') ? "匿名者" : cuser.userid, destid); while (fgets(buf, 200, fp)) { char *po; @@ -182,17 +187,19 @@ osong(char *defaultid) } while ((po = strstr(buf, "<~Src~>"))) { po[0] = 0; - sprintf(genbuf, "%s%s%s", buf, (ano[0] == 'y') ? "匿名者" : cuser.userid, po + 7); + snprintf(genbuf, sizeof(genbuf), + "%s%s%s", buf, + (ano[0] == 'y') ? "匿名者" : cuser.userid, po + 7); strlcpy(buf, genbuf, sizeof(buf)); } while ((po = strstr(buf, "<~Des~>"))) { po[0] = 0; - sprintf(genbuf, "%s%s%s", buf, destid, po + 7); + snprintf(genbuf, sizeof(genbuf), "%s%s%s", buf, destid, po + 7); strlcpy(buf, genbuf, sizeof(buf)); } while ((po = strstr(buf, "<~Say~>"))) { po[0] = 0; - sprintf(genbuf, "%s%s%s", buf, say, po + 7); + snprintf(genbuf, sizeof(genbuf), "%s%s%s", buf, say, po + 7); strlcpy(buf, genbuf, sizeof(buf)); } fputs(buf, fp1); @@ -212,7 +219,8 @@ osong(char *defaultid) /* 把第一首拿掉 */ vice(200, "點歌"); } - sprintf(save_title, "%s:%s", (ano[0] == 'y') ? "匿名者" : cuser.userid, say); + snprintf(save_title, sizeof(save_title), + "%s:%s", (ano[0] == 'y') ? "匿名者" : cuser.userid, say); hold_mail(filename, destid); if (receiver[0]) { @@ -304,13 +312,14 @@ p_exmail() int n; if (cuser.exmailbox >= MAX_EXKEEPMAIL) { - sprintf(buf, "容量最多增加 %d 封,不能再買了。", MAX_EXKEEPMAIL); + snprintf(buf, sizeof(buf), + "容量最多增加 %d 封,不能再買了。", MAX_EXKEEPMAIL); outs(buf); refresh(); return 0; } - sprintf(buf, "您曾增購 %d 封容量,還要再買多少?", - cuser.exmailbox); + snprintf(buf, sizeof(buf), + "您曾增購 %d 封容量,還要再買多少?", cuser.exmailbox); getdata_str(b_lines - 2, 0, buf, ans, sizeof(ans), LCECHO, "10"); @@ -333,7 +342,7 @@ mail_redenvelop(char *from, char *to, int money, char mode) char genbuf[200]; fileheader_t fhdr; FILE *fp; - sprintf(genbuf, "home/%c/%s", to[0], to); + snprintf(genbuf, sizeof(genbuf), "home/%c/%s", to[0], to); stampfile(genbuf, &fhdr); if (!(fp = fopen(genbuf, "w"))) return; @@ -345,12 +354,12 @@ mail_redenvelop(char *from, char *to, int money, char mode) " 禮輕情意重,請笑納...... ^_^\033[m\n" ,from, ctime(&now), to, money); fclose(fp); - sprintf(fhdr.title, "招財進寶"); + snprintf(fhdr.title, sizeof(fhdr.title), "招財進寶"); strlcpy(fhdr.owner, from, sizeof(fhdr.owner)); if (mode == 'y') vedit(genbuf, NA, NULL); - sprintf(genbuf, "home/%c/%s/.DIR", to[0], to); + snprintf(genbuf, sizeof(genbuf), "home/%c/%s/.DIR", to[0], to); append_record(genbuf, &fhdr, sizeof(fhdr)); } @@ -388,8 +397,8 @@ p_give() return 0; /* 繳完稅就沒錢給了 */ deumoney(searchuser(id), money - tax); demoney(-money); - sprintf(genbuf, "%s\t給%s\t%d\t%s", cuser.userid, id, money - tax, - ctime(&now)); + snprintf(genbuf, sizeof(genbuf), "%s\t給%s\t%d\t%s", + cuser.userid, id, money - tax, ctime(&now)); log_file(FN_MONEY, genbuf); genbuf[0] = 'n'; getdata(3, 0, "要自行書寫紅包袋嗎?[y/N]", genbuf, 2, LCECHO); @@ -474,7 +483,7 @@ cal() b[0] = '0'; b[1] = 0; move(b_lines - 1, 0); - sprintf(buf, "[%13.2f] [%c] ", a, ch); + snprintf(buf, sizeof(buf), "[%13.2f] [%c] ", a, ch); outs(buf); break; case '.': @@ -495,11 +504,11 @@ cal() if (strlen(b) > 13) break; if (flo || b[0] != '0') - sprintf(b, "%s%c", b, ch); + snprintf(b, sizeof(b), "%s%c", b, ch); else b[0] = ch; move(b_lines - 1, 0); - sprintf(buf, "[%13s] [%c]", b, mode[(int)cmode]); + snprintf(buf, sizeof(buf), "[%13s] [%c]", b, mode[(int)cmode]); outs(buf); break; case 'q': diff --git a/pttbbs/mbbsd/card.c b/pttbbs/mbbsd/card.c index 1c457046..55102df5 100644 --- a/pttbbs/mbbsd/card.c +++ b/pttbbs/mbbsd/card.c @@ -1,4 +1,4 @@ -/* $Id: card.c,v 1.5 2002/07/21 09:26:02 in2 Exp $ */ +/* $Id: card.c,v 1.6 2002/07/22 19:02:00 in2 Exp $ */ #include "bbs.h" static int @@ -372,8 +372,9 @@ card_double_ask() { char buf[100], buf2[3]; - sprintf(buf, "[ %s ]您現在共有 %d P幣, 現在要分組(加收 %d 元)嗎? [y/N]", - cuser.userid, cuser.money, JACK); + snprintf(buf, sizeof(buf), + "[ %s ]您現在共有 %d P幣, 現在要分組(加收 %d 元)嗎? [y/N]", + cuser.userid, cuser.money, JACK); reload_money(); if (cuser.money < JACK) return 0; @@ -388,7 +389,7 @@ card_ask() { char buf[100], buf2[3]; - sprintf(buf, "[ %s ]您現在共有 %d P幣, 還要加牌嗎? [y/N]", + snprintf(buf, sizeof(buf), "[ %s ]您現在共有 %d P幣, 還要加牌嗎? [y/N]", cuser.userid, cuser.money); getdata(20, 0, buf, buf2, sizeof(buf2), LCECHO); if (buf2[0] == 'y' || buf2[0] == 'Y') diff --git a/pttbbs/mbbsd/chat.c b/pttbbs/mbbsd/chat.c index e852fbf2..4c58b290 100644 --- a/pttbbs/mbbsd/chat.c +++ b/pttbbs/mbbsd/chat.c @@ -1,4 +1,4 @@ -/* $Id: chat.c,v 1.8 2002/07/21 09:26:02 in2 Exp $ */ +/* $Id: chat.c,v 1.9 2002/07/22 19:02:00 in2 Exp $ */ #include "bbs.h" static int chatline, stop_line; @@ -51,7 +51,7 @@ chat_send(int fd, char *buf) int len; char genbuf[200]; - sprintf(genbuf, "%s\n", buf); + snprintf(genbuf, sizeof(genbuf), "%s\n", buf); len = strlen(genbuf); return (send(fd, genbuf, len, 0) == len); } @@ -94,7 +94,7 @@ chat_recv(int fd, char *chatid) case 't': move(0, 0); clrtoeol(); - sprintf(genbuf, "談天室 [%s]", chatroom); + snprintf(genbuf, sizeof(genbuf), "談天室 [%s]", chatroom); prints("\033[1;37;46m %-21s \033[45m 話題:%-48s\033[m", genbuf, bptr + 2); } @@ -131,9 +131,9 @@ printuserent(userinfo_t * uentp) if (!HAS_PERM(PERM_SYSOP) && !HAS_PERM(PERM_SEECLOAK) && uentp->invisible) return 0; - sprintf(pline, "%-13s%c%-10s ", uentp->userid, - uentp->invisible ? '#' : ' ', - modestring(uentp, 1)); + snprintf(pline, sizeof(pline), "%-13s%c%-10s ", uentp->userid, + uentp->invisible ? '#' : ' ', + modestring(uentp, 1)); if (cnt < 2) strcat(pline, "│"); strcat(uline, pline); @@ -150,7 +150,7 @@ chathelp(char *cmd, char *desc) { char buf[STRLEN]; - sprintf(buf, " %-20s- %s", cmd, desc); + snprintf(buf, sizeof(buf), " %-20s- %s", cmd, desc); printchatline(buf); } @@ -190,7 +190,8 @@ chat_date() { char genbuf[200]; - sprintf(genbuf, "◆ " BBSNAME "標準時間: %s", Cdate(&now)); + snprintf(genbuf, sizeof(genbuf), + "◆ " BBSNAME "標準時間: %s", Cdate(&now)); printchatline(genbuf); } @@ -200,8 +201,8 @@ chat_pager() char genbuf[200]; char *msgs[] = {"關閉", "打開", "拔掉", "防水", "好友"}; - sprintf(genbuf, "◆ 您的呼叫器:[%s]", - msgs[currutmp->pager = (currutmp->pager + 1) % 5]); + snprintf(genbuf, sizeof(genbuf), "◆ 您的呼叫器:[%s]", + msgs[currutmp->pager = (currutmp->pager + 1) % 5]); printchatline(genbuf); } @@ -217,11 +218,13 @@ chat_query(char *arg) char buf[128], *ptr; FILE *fp; - sprintf(buf, "%s(%s) 共上站 %d 次,發表過 %d 篇文章", - xuser.userid, xuser.username, xuser.numlogins, xuser.numposts); + snprintf(buf, sizeof(buf), "%s(%s) 共上站 %d 次,發表過 %d 篇文章", + xuser.userid, xuser.username, + xuser.numlogins, xuser.numposts); printchatline(buf); - sprintf(buf, "最近(%s)從[%s]上站", Cdate(&xuser.lastlogin), + snprintf(buf, sizeof(buf), + "最近(%s)從[%s]上站", Cdate(&xuser.lastlogin), (xuser.lasthost[0] ? xuser.lasthost : "(不詳)")); printchatline(buf); @@ -308,8 +311,9 @@ select_address() trans_buffer[0] = 0; if ((fp = fopen("etc/teashop", "r"))) { for (c = 0; fscanf(fp, "%s%s", iptab[c], nametab[c]) != EOF; c++) { - sprintf(buf, "\n (\033[36m%d\033[0m) %-30s [%s]", - c + 1, nametab[c], iptab[c]); + snprintf(buf, sizeof(buf), + "\n (\033[36m%d\033[0m) %-30s [%s]", + c + 1, nametab[c], iptab[c]); outs(buf); } getdata(20, 10, "★\033[32m 請選擇,[0]離開:\033[0m", buf, 3, @@ -379,18 +383,19 @@ t_chat() while (1) { getdata(b_lines - 1, 0, "請輸入聊天代號:", inbuf, 9, DOECHO); - sprintf(chatid, "%s", (inbuf[0] ? inbuf : cuser.userid)); + snprintf(chatid, sizeof(chatid), + "%s", (inbuf[0] ? inbuf : cuser.userid)); chatid[8] = '\0'; /* * 舊格式: /! 使用者編號 使用者等級 UserID ChatID 新格式: /! * UserID ChatID Password */ if (roomtype == 1) - sprintf(inbuf, "/! %s %s %s", - cuser.userid, chatid, cuser.passwd); + snprintf(inbuf, sizeof(inbuf), "/! %s %s %s", + cuser.userid, chatid, cuser.passwd); else - sprintf(inbuf, "/! %d %d %s %s", - usernum, cuser.userlevel, cuser.userid, chatid); + snprintf(inbuf, sizeof(inbuf), "/! %d %d %s %s", + usernum, cuser.userlevel, cuser.userid, chatid); chat_send(cfd, inbuf); if (recv(cfd, inbuf, 3, 0) != 3) return 0; diff --git a/pttbbs/mbbsd/chicken.c b/pttbbs/mbbsd/chicken.c index e42a2a5a..4744141e 100644 --- a/pttbbs/mbbsd/chicken.c +++ b/pttbbs/mbbsd/chicken.c @@ -1,4 +1,4 @@ -/* $Id: chicken.c,v 1.8 2002/07/21 09:26:02 in2 Exp $ */ +/* $Id: chicken.c,v 1.9 2002/07/22 19:02:00 in2 Exp $ */ #include "bbs.h" #define NUM_KINDS 13 /* 有多少種動物 */ @@ -128,9 +128,10 @@ new_chicken() getdata(8, 0, "幫牠取個好名字:", mychicken->name, sizeof(mychicken->name), DOECHO); - sprintf(buf, "\033[31m%s \033[m養了一隻叫\033[33m %s \033[m的 " - "\033[32m%s\033[m 於 %s", cuser.userid, - mychicken->name, chicken_type[(int)mychicken->type], ctime(&now)); + snprintf(buf, sizeof(buf), + "\033[31m%s \033[m養了一隻叫\033[33m %s \033[m的 " + "\033[32m%s\033[m 於 %s", cuser.userid, + mychicken->name, chicken_type[(int)mychicken->type], ctime(&now)); log_file(CHICKENLOG, buf); mychicken->lastvisit = mychicken->birthday = mychicken->cbirth = now; mychicken->food = 0; @@ -219,8 +220,8 @@ show_chicken_data(chicken_t * thechicken, chicken_t * pkchicken) show_chicken_stat(thechicken); - sprintf(buf, CHICKEN_PIC "/%c%d", thechicken->type + 'a', - age > 16 ? 16 : age); + snprintf(buf, sizeof(buf), CHICKEN_PIC "/%c%d", thechicken->type + 'a', + age > 16 ? 16 : age); show_file(buf, 5, 14, NO_RELOAD); move(18, 0); @@ -424,16 +425,17 @@ ch_kill() { char buf[150], ans[4]; - sprintf(buf, "棄養這%s要被罰 100 元, 是否要棄養?(y/N)", + snprintf(buf, sizeof(buf), "棄養這%s要被罰 100 元, 是否要棄養?(y/N)", chicken_type[(int)mychicken->type]); getdata_str(23, 0, buf, ans, sizeof(ans), DOECHO, "N"); if (ans[0] == 'y') { vice(100, "棄養寵物費"); more(CHICKEN_PIC "/deadth", YEA); - sprintf(buf, "\033[31m%s \033[m把 \033[33m%s\033[m\033[32m %s " - "\033[m宰了 於 %s", cuser.userid, - mychicken->name, chicken_type[(int)mychicken->type], ctime(&now)); + snprintf(buf, sizeof(buf), + "\033[31m%s \033[m把 \033[33m%s\033[m\033[32m %s " + "\033[m宰了 於 %s", cuser.userid, mychicken->name, + chicken_type[(int)mychicken->type], ctime(&now)); log_file(CHICKENLOG, buf); mychicken->name[0] = 0; } @@ -485,11 +487,11 @@ ch_sell() pressanykey(); return 0; } - sprintf(buf, "這隻%d歲%s可以賣 %d 元, 是否要賣?(y/N)", age, - chicken_type[(int)mychicken->type], money); + snprintf(buf, sizeof(buf), "這隻%d歲%s可以賣 %d 元, 是否要賣?(y/N)", age, + chicken_type[(int)mychicken->type], money); getdata_str(23, 0, buf, ans, sizeof(ans), DOECHO, "N"); if (ans[0] == 'y') { - sprintf(buf, "\033[31m%s\033[m 把 \033[33m%s\033[m " + snprintf(buf, sizeof(buf), "\033[31m%s\033[m 把 \033[33m%s\033[m " "\033[32m%s\033[m 用 \033[36m%d\033[m 賣了 於 %s", cuser.userid, mychicken->name, chicken_type[(int)mychicken->type], money, ctime(&now)); @@ -645,11 +647,12 @@ deadtype(chicken_t * thechicken) return 0; if (thechicken == mychicken) { - sprintf(buf, "\033[31m%s\033[m 所疼愛的\033[33m %s\033[32m %s " - "\033[m掛了 於 %s", - cuser.userid, thechicken->name, - chicken_type[(int)thechicken->type], - ctime(&now)); + snprintf(buf, sizeof(buf), + "\033[31m%s\033[m 所疼愛的\033[33m %s\033[32m %s " + "\033[m掛了 於 %s", + cuser.userid, thechicken->name, + chicken_type[(int)thechicken->type], + ctime(&now)); log_file(CHICKENLOG, buf); mychicken->name[0] = 0; passwd_update(usernum, &cuser); @@ -702,11 +705,12 @@ ch_changename() mychicken->name); if (strlen(newname) >= 3 && strcmp(newname, mychicken->name)) { - sprintf(buf, "\033[31m%s\033[m 把疼愛的\033[33m %s\033[32m %s " - "\033[m改名為\033[33m %s\033[m 於 %s", - cuser.userid, mychicken->name, - chicken_type[(int)mychicken->type], - newname, ctime(&now)); + snprintf(buf, sizeof(buf), + "\033[31m%s\033[m 把疼愛的\033[33m %s\033[32m %s " + "\033[m改名為\033[33m %s\033[m 於 %s", + cuser.userid, mychicken->name, + chicken_type[(int)mychicken->type], + newname, ctime(&now)); strlcpy(mychicken->name, newname, sizeof(mychicken->name)); log_file(CHICKENLOG, buf); } @@ -815,9 +819,9 @@ recover_chicken(chicken_t * thechicken) "最近缺錢想賺外快 \033[m"); bell(); igetch(); - sprintf(buf, "\033[33;44m★靈界守衛\033[37;45m " - "你有一個剛走不久的%s要招換回來嗎? 只要%d元唷 \033[m", - chicken_type[(int)thechicken->type], price * 2); + snprintf(buf, sizeof(buf), "\033[33;44m★靈界守衛\033[37;45m " + "你有一個剛走不久的%s要招換回來嗎? 只要%d元唷 \033[m", + chicken_type[(int)thechicken->type], price * 2); outmsg(buf); bell(); getdata_str(21, 0, " 選擇:(N:坑人嘛/y:請幫幫我)", buf, 3, LCECHO, "N"); @@ -835,8 +839,9 @@ recover_chicken(chicken_t * thechicken) thechicken->sick = 0; thechicken->satis = 2; vice(money, "靈界守衛"); - sprintf(buf, "\033[33;44m★靈界守衛\033[37;45m OK了 記得餵他點東西 " - "不然可能失效 念在我也有玩Ptt 拿你%d就好 \033[m", money); + snprintf(buf, sizeof(buf), + "\033[33;44m★靈界守衛\033[37;45m OK了 記得餵他點東西 " + "不然可能失效 念在我也有玩Ptt 拿你%d就好 \033[m", money); outmsg(buf); bell(); igetch(); @@ -949,8 +954,8 @@ chickenpk(int fd) switch (ch) { case 'y': if (catched == 1) { - sprintf(data, "l讓 %s 落跑了\n", - ochicken->name); + snprintf(data, sizeof(data), + "l讓 %s 落跑了\n", ochicken->name); } break; case 'n': @@ -959,13 +964,15 @@ chickenpk(int fd) case 'k': r = r % (attmax + 2); if (r) { - sprintf(data, "M%s %s%s %s 傷了 %d 點\n", mychicken->name, - damage_degree[r / 3 > 15 ? 15 : r / 3], - attack_type[(int)mychicken->type], - ochicken->name, r); + snprintf(data, sizeof(data), + "M%s %s%s %s 傷了 %d 點\n", mychicken->name, + damage_degree[r / 3 > 15 ? 15 : r / 3], + attack_type[(int)mychicken->type], + ochicken->name, r); ochicken->hp -= r; } else - sprintf(data, "M%s 覺得手軟出擊無效\n", mychicken->name); + snprintf(data, sizeof(data), + "M%s 覺得手軟出擊無效\n", mychicken->name); break; case 'o': if (mychicken->oo > 0) { @@ -974,26 +981,28 @@ chickenpk(int fd) if (mychicken->hp > mychicken->hp_max) mychicken->hp = mychicken->hp_max; mychicken->tiredstrong = 0; - sprintf(data, "M%s 吃了顆大補丸補充體力\n", - mychicken->name); + snprintf(data, sizeof(data), "M%s 吃了顆大補丸補充體力\n", + mychicken->name); } else - sprintf(data, "M%s 想吃大補丸, 可是沒有大補丸可吃\n", + snprintf(data, sizeof(data), + "M%s 想吃大補丸, 可是沒有大補丸可吃\n", mychicken->name); break; case 'q': if (r % (mychicken->run + 1) > r % (ochicken->run + 1)) - sprintf(data, "q%s 落跑了\n", - mychicken->name); + snprintf(data, sizeof(data), "q%s 落跑了\n", + mychicken->name); else - sprintf(data, "c%s 想落跑, 但被 %s 抓到了\n", - mychicken->name, ochicken->name); + snprintf(data, sizeof(data), + "c%s 想落跑, 但被 %s 抓到了\n", + mychicken->name, ochicken->name); break; } if (deadtype(ochicken)) { strtok(data, "\n"); strlcpy(buf, data, sizeof(buf)); - sprintf(data, "d%s , %s 被 %s 打死了\n", - buf + 1, ochicken->name, mychicken->name); + snprintf(data, sizeof(data), "d%s , %s 被 %s 打死了\n", + buf + 1, ochicken->name, mychicken->name); } move(17, 0); outs(data + 1); diff --git a/pttbbs/mbbsd/dark.c b/pttbbs/mbbsd/dark.c index cd37fd0b..4c9c6486 100644 --- a/pttbbs/mbbsd/dark.c +++ b/pttbbs/mbbsd/dark.c @@ -1,4 +1,4 @@ -/* $Id: dark.c,v 1.7 2002/07/21 09:26:02 in2 Exp $ */ +/* $Id: dark.c,v 1.8 2002/07/22 19:02:00 in2 Exp $ */ #include "bbs.h" #define RED 1 @@ -156,14 +156,14 @@ draw_line(sint y, sint f) strlcpy(buf, "\033[43;30m", sizeof(buf)); for (i = 0; i < 8; i++) { if (brd[y][i].die == 1) - sprintf(tmp, "│ "); + snprintf(tmp, sizeof(tmp), "│ "); else if (brd[y][i].out == 0) - sprintf(tmp, "│●"); + snprintf(tmp, sizeof(tmp), "│●"); else { - sprintf(tmp, "│\033[%s1;%dm%s\033[m\033[43;30m", - (f == i) ? "1;47;" : "", (brd[y][i].color) ? 31 : 34, - (brd[y][i].color) ? rname[brd[y][i].value] : - bname[brd[y][i].value]); + snprintf(tmp, sizeof(tmp), "│\033[%s1;%dm%s\033[m\033[43;30m", + (f == i) ? "1;47;" : "", (brd[y][i].color) ? 31 : 34, + (brd[y][i].color) ? rname[brd[y][i].value] : + bname[brd[y][i].value]); } strcat(buf, tmp); } diff --git a/pttbbs/mbbsd/dice.c b/pttbbs/mbbsd/dice.c index 69d7486f..fae9d262 100644 --- a/pttbbs/mbbsd/dice.c +++ b/pttbbs/mbbsd/dice.c @@ -1,4 +1,4 @@ -/* $Id: dice.c,v 1.5 2002/07/21 09:26:02 in2 Exp $ */ +/* $Id: dice.c,v 1.6 2002/07/22 19:02:00 in2 Exp $ */ #include "bbs.h" #define DICE_TXT BBSHOME "/etc/dice.txt" @@ -454,9 +454,10 @@ dice_main(void) demoney(table[j].mymoney * ya + table[j].mymoney); total += table[j].mymoney * ya; if (table[j].mymoney * ya > 500) { /* 超過500塊錢才做log 減少io */ - sprintf(data, "%-15s 押%-2d選項%-8d塊錢 中了%d倍 淨賺:%-8d\n", - cuser.userid, table[j].mybet, - table[j].mymoney, ya, table[j].mymoney * ya); + snprintf(data, sizeof(data), + "%-15s 押%-2d選項%-8d塊錢 中了%d倍 淨賺:%-8d\n", + cuser.userid, table[j].mybet, + table[j].mymoney, ya, table[j].mymoney * ya); fputs(data, winfp); } ya = 0; diff --git a/pttbbs/mbbsd/edit.c b/pttbbs/mbbsd/edit.c index 212f893b..ad210b12 100644 --- a/pttbbs/mbbsd/edit.c +++ b/pttbbs/mbbsd/edit.c @@ -1,4 +1,4 @@ -/* $Id: edit.c,v 1.14 2002/07/21 09:26:02 in2 Exp $ */ +/* $Id: edit.c,v 1.15 2002/07/22 19:02:00 in2 Exp $ */ #include "bbs.h" typedef struct textline_t { struct textline_t *prev; @@ -784,9 +784,11 @@ write_header(FILE * fp) ifuseanony = 1; } else { if (!strcmp("r", real_name) || (!defanony && !real_name[0])) - sprintf(postlog.author, "%s", cuser.userid); + snprintf(postlog.author, sizeof(postlog.author), + "%s", cuser.userid); else { - sprintf(postlog.author, "%s.", real_name); + snprintf(postlog.author, sizeof(postlog.author), + "%s.", real_name); ifuseanony = 1; } } @@ -1644,7 +1646,7 @@ vedit(char *fpath, int saveheader, int *islocal) } /* 連續240個interval一樣 , 分明是在斂財 */ if (count >= 240) { - sprintf(buf, "\033[1;33;46m%s\033[37m在\033[37;45m%s" + snprintf(buf, sizeof(buf), "\033[1;33;46m%s\033[37m在\033[37;45m%s" "\033[37m板違法賺錢 , %s\033[m", cuser.userid, currboard, ctime(&now)); log_file("etc/illegal_money", buf); @@ -1782,25 +1784,26 @@ vedit(char *fpath, int saveheader, int *islocal) strlcpy(color, "\033[", sizeof(color)); if (isdigit(*apos)) { - sprintf(color, "%s%c", color, *(apos++)); + snprintf(color, sizeof(color), + "%s%c", color, *(apos++)); if (*apos) - sprintf(color, "%s;", color); + snprintf(color, sizeof(color), "%s;", color); } if (*apos) { if ((tmp = strchr(t, toupper(*(apos++))))) fg = tmp - t + 30; else fg = 37; - sprintf(color, "%s%d", color, fg); + snprintf(color, sizeof(color), "%s%d", color, fg); } if (*apos) { if ((tmp = strchr(t, toupper(*(apos++))))) bg = tmp - t + 40; else bg = 40; - sprintf(color, "%s;%d", color, bg); + snprintf(color, sizeof(color), "%s;%d", color, bg); } - sprintf(color, "%sm", color); + snprintf(color, sizeof(color), "%sm", color); insert_string(color); } else insert_string(reset_color); diff --git a/pttbbs/mbbsd/friend.c b/pttbbs/mbbsd/friend.c index 6029bfd8..2df2025b 100644 --- a/pttbbs/mbbsd/friend.c +++ b/pttbbs/mbbsd/friend.c @@ -1,4 +1,4 @@ -/* $Id: friend.c,v 1.11 2002/07/21 09:26:02 in2 Exp $ */ +/* $Id: friend.c,v 1.12 2002/07/22 19:02:00 in2 Exp $ */ #include "bbs.h" /* ------------------------------------- */ @@ -114,7 +114,7 @@ friend_special() friend_file[FRIEND_SPECIAL] = special_list; for (i = 0; i <= 9; i++) { - sprintf(genbuf, " (\033[36m%d\033[m) .. ", i); + snprintf(genbuf, sizeof(genbuf), " (\033[36m%d\033[m) .. ", i); special_des[5] = i + '0'; setuserfile(fname, special_des); if (dashf(fname)) { @@ -153,15 +153,17 @@ friend_append(int type, int count) for (j = i = 0; i <= 4; i++) if (i != type) { ++j; - sprintf(buf, " (%d) %-s\n", i + 1, friend_list[(int)i]); + snprintf(buf, sizeof(buf), + " (%d) %-s\n", i + 1, friend_list[(int)i]); outs(buf); } if (HAVE_PERM(PERM_SYSOP) || currmode & MODE_BOARD) for (; i < 8; ++i) if (i != type) { ++j; - sprintf(buf, " (%d) %s 板的 %s\n", j, currboard, - friend_list[(int)i]); + snprintf(buf, sizeof(buf), + " (%d) %s 板的 %s\n", j, currboard, + friend_list[(int)i]); outs(buf); } outs(" (S) 選擇其他看板的特別名單"); @@ -229,7 +231,7 @@ friend_editdesc(char *uident, int type) FILE *fp, *nfp; char fnnew[200], genbuf[200], fn[200]; setfriendfile(fn, type); - sprintf(fnnew, "%s-", fn); + snprintf(fnnew, sizeof(fnnew), "%s-", fn); if ((fp = fopen(fn, "r")) && (nfp = fopen(fnnew, "w"))) { int length = strlen(uident); @@ -324,7 +326,8 @@ friend_edit(int type) if (type == FRIEND_ALOHA || type == FRIEND_POST) { if (dashf(fpath)) { - sprintf(genbuf, "/bin/cp %s %s.old", fpath, fpath); + snprintf(genbuf, sizeof(genbuf), + "/bin/cp %s %s.old", fpath, fpath); system(genbuf); } } @@ -332,7 +335,7 @@ friend_edit(int type) while (1) { stand_title(friend_list[type]); move(0, 40); - sprintf(line, "(名單上限:%d個人)", friend_max[type]); + snprintf(line, sizeof(line), "(名單上限:%d個人)", friend_max[type]); outs(line); count = 0; CreateNameList(); @@ -406,7 +409,7 @@ friend_edit(int type) outs("更新資料中..請稍候....."); refresh(); if (type == FRIEND_ALOHA || type == FRIEND_POST) { - sprintf(genbuf, "%s.old", fpath); + snprintf(genbuf, sizeof(genbuf), "%s.old", fpath); if ((fp = fopen(genbuf, "r"))) { while (fgets(line, 80, fp)) { sscanf(line, "%s", uident); @@ -416,7 +419,7 @@ friend_edit(int type) } fclose(fp); } - sprintf(genbuf, "%s", fpath); + snprintf(genbuf, sizeof(genbuf), "%s", fpath); if ((fp = fopen(genbuf, "r"))) { while (fgets(line, 80, fp)) { sscanf(line, "%s", uident); diff --git a/pttbbs/mbbsd/gamble.c b/pttbbs/mbbsd/gamble.c index 97961898..836dbc25 100644 --- a/pttbbs/mbbsd/gamble.c +++ b/pttbbs/mbbsd/gamble.c @@ -1,4 +1,4 @@ -/* $Id: gamble.c,v 1.27 2002/07/21 09:26:02 in2 Exp $ */ +/* $Id: gamble.c,v 1.28 2002/07/22 19:02:00 in2 Exp $ */ #include "bbs.h" #ifndef _BBS_UTIL_C_ @@ -18,7 +18,7 @@ post_msg(char *bname, char *title, char *msg, char *author) char genbuf[256]; /* 在 bname 板發表新文章 */ - sprintf(genbuf, "boards/%c/%s", bname[0], bname); + snprintf(genbuf, sizeof(genbuf), "boards/%c/%s", bname[0], bname); stampfile(genbuf, &fhdr); fp = fopen(genbuf, "w"); @@ -69,7 +69,7 @@ load_ticket_record(char *direct, int ticket[]) char buf[256]; int i, total = 0; FILE *fp; - sprintf(buf, "%s/" FN_TICKET_RECORD, direct); + snprintf(buf, sizeof(buf), "%s/" FN_TICKET_RECORD, direct); if (!(fp = fopen(buf, "r"))) return 0; for (i = 0; i < MAX_ITEM && fscanf(fp, "%9d ", &ticket[i]); i++) @@ -87,19 +87,21 @@ show_ticket_data(char *direct, int *price, boardheader_t * bh) clear(); if (bh) { - sprintf(genbuf, "%s 賭盤", bh->brdname); - if (bh->endgamble && now < bh->endgamble && bh->endgamble - now < 3600) { - sprintf(t, "封盤倒數 %d 秒", (int)(bh->endgamble - now)); + snprintf(genbuf, sizeof(genbuf), "%s 賭盤", bh->brdname); + if (bh->endgamble && now < bh->endgamble && + bh->endgamble - now < 3600) { + snprintf(t, sizeof(t), + "封盤倒數 %d 秒", (int)(bh->endgamble - now)); showtitle(genbuf, t); } else showtitle(genbuf, BBSNAME); } else showtitle("Ptt賭盤", BBSNAME); move(2, 0); - sprintf(genbuf, "%s/" FN_TICKET_ITEMS, direct); + snprintf(genbuf, sizeof(genbuf), "%s/" FN_TICKET_ITEMS, direct); if (!(fp = fopen(genbuf, "r"))) { prints("\n目前並沒有舉辦賭盤\n"); - sprintf(genbuf, "%s/" FN_TICKET_OUTCOME, direct); + snprintf(genbuf, sizeof(genbuf), "%s/" FN_TICKET_OUTCOME, direct); if (more(genbuf, NA)); return 0; } @@ -121,9 +123,9 @@ show_ticket_data(char *direct, int *price, boardheader_t * bh) bh ? "板主自訂規則及說明" : "前幾次開獎結果"); - sprintf(genbuf, "%s/" FN_TICKET, direct); + snprintf(genbuf, sizeof(genbuf), "%s/" FN_TICKET, direct); if (!dashf(genbuf)) { - sprintf(genbuf, "%s/" FN_TICKET_END, direct); + snprintf(genbuf, sizeof(genbuf), "%s/" FN_TICKET_END, direct); end = 1; } show_file(genbuf, 8, -1, NO_RELOAD); @@ -152,7 +154,7 @@ append_ticket_record(char *direct, int ch, int n, int count) FILE *fp; int ticket[8] = {0, 0, 0, 0, 0, 0, 0, 0}, i; char genbuf[256]; - sprintf(genbuf, "%s/" FN_TICKET_USER, direct); + snprintf(genbuf, sizeof(genbuf), "%s/" FN_TICKET_USER, direct); if ((fp = fopen(genbuf, "a"))) { fprintf(fp, "%s %d %d\n", cuser.userid, ch, n); @@ -160,7 +162,7 @@ append_ticket_record(char *direct, int ch, int n, int count) } load_ticket_record(direct, ticket); ticket[ch] += n; - sprintf(genbuf, "%s/" FN_TICKET_RECORD, direct); + snprintf(genbuf, sizeof(genbuf), "%s/" FN_TICKET_RECORD, direct); if ((fp = fopen(genbuf, "w"))) { for (i = 0; i < count; i++) fprintf(fp, "%d ", ticket[i]); @@ -343,11 +345,12 @@ openticket(int bid) if (bet == 98 && mybet >= 0 && mybet < count) { fprintf(fp, "%s 買了 %d 張 %s, 退回 %d 枚P幣\n" ,userid, i, betname[mybet], money); - sprintf(buf, "%s 賭場退錢! $ %d", bh->brdname, money * i); + snprintf(buf, sizeof(buf), + "%s 賭場退錢! $ %d", bh->brdname, money * i); } else if (mybet == bet) { fprintf(fp, "恭喜 %s 買了%d 張 %s, 獲得 %d 枚P幣\n" ,userid, i, betname[mybet], money); - sprintf(buf, "%s 中獎咧! $ %d", bh->brdname, money * i); + snprintf(buf, sizeof(buf), "%s 中獎咧! $ %d", bh->brdname, money * i); } else continue; if ((uid = searchuser(userid)) == 0) @@ -360,9 +363,9 @@ openticket(int bid) fclose(fp); if (bet != 98) - sprintf(buf, "[公告] %s 賭盤開獎", bh->brdname); + snprintf(buf, sizeof(buf), "[公告] %s 賭盤開獎", bh->brdname); else - sprintf(buf, "[公告] %s 賭盤取消", bh->brdname); + snprintf(buf, sizeof(buf), "[公告] %s 賭盤取消", bh->brdname); post_file(bh->brdname, buf, outcome, "[賭神]"); post_file("Record", buf + 7, outcome, "[馬路探子]"); diff --git a/pttbbs/mbbsd/gomo.c b/pttbbs/mbbsd/gomo.c index c6870e3f..7822b090 100644 --- a/pttbbs/mbbsd/gomo.c +++ b/pttbbs/mbbsd/gomo.c @@ -1,4 +1,4 @@ -/* $Id: gomo.c,v 1.8 2002/07/21 09:26:02 in2 Exp $ */ +/* $Id: gomo.c,v 1.9 2002/07/22 19:02:00 in2 Exp $ */ #include "bbs.h" static char *chess[] = {"●", "○"}; @@ -53,8 +53,8 @@ HO_log(char *user) Horder_t *ptr = pool; fileheader_t mymail; - sprintf(buf, "home/%c/%s/F.%d", cuser.userid[0], cuser.userid, - rand() & 65535); + snprintf(buf, sizeof(buf), "home/%c/%s/F.%d", + cuser.userid[0], cuser.userid, rand() & 65535); log = fopen(buf, "w"); for (i = 1; i < 17; i++) @@ -73,8 +73,8 @@ HO_log(char *user) mymail.filemode = FILE_READ | FILE_HOLD; strlcpy(mymail.owner, "[備.忘.錄]", sizeof(mymail.owner)); - sprintf(mymail.title, "\033[37;41m棋譜\033[m %s VS %s", - cuser.userid, user); + snprintf(mymail.title, sizeof(mymail.title), + "\033[37;41m棋譜\033[m %s VS %s", cuser.userid, user); sethomedir(title, cuser.userid); Rename(buf, buf1); append_record(title, &mymail, sizeof(mymail)); diff --git a/pttbbs/mbbsd/guess.c b/pttbbs/mbbsd/guess.c index 654f45dc..0d655108 100644 --- a/pttbbs/mbbsd/guess.c +++ b/pttbbs/mbbsd/guess.c @@ -1,4 +1,4 @@ -/* $Id: guess.c,v 1.5 2002/07/21 09:26:02 in2 Exp $ */ +/* $Id: guess.c,v 1.6 2002/07/22 19:02:00 in2 Exp $ */ #include "bbs.h" #define LOGPASS BBSHOME "/etc/winguess.log" @@ -116,8 +116,8 @@ result(int correct, int number) char a = 0, b = 0, i, j; char n1[5], n2[5]; - sprintf(n1, "%04d", correct); - sprintf(n2, "%04d", number); + snprintf(n1, sizeof(n1), "%04d", correct); + snprintf(n2, sizeof(n2), "%04d", number); for (i = 0; i < 4; i++) for (j = 0; j < 4; j++) if (n1[(int)i] == n2[(int)j]) @@ -136,7 +136,7 @@ legal(int number) char i, j; char temp[5]; - sprintf(temp, "%04d", number); + snprintf(temp, sizeof(temp), "%04d", number); for (i = 0; i < 4; i++) for (j = i + 1; j < 4; j++) if (temp[(int)i] == temp[(int)j]) @@ -173,12 +173,12 @@ computer(int correct, int total, char flag[], int n[]) k = result(correct, guess); if (k == 40) { move(total + 8, 25); - sprintf(data, "%04d", guess); + snprintf(data, sizeof(data), "%04d", guess); prints("%s => 猜中了!!", data); return 1; } else { move(total + 8, 25); - sprintf(data, "%04d", guess); + snprintf(data, sizeof(data), "%04d", guess); prints("%s => \033[1;32m%dA %dB\033[m", data, k / 10, k % 10); } j = 0; diff --git a/pttbbs/mbbsd/indict.c b/pttbbs/mbbsd/indict.c index 13030880..7eed0828 100644 --- a/pttbbs/mbbsd/indict.c +++ b/pttbbs/mbbsd/indict.c @@ -1,4 +1,4 @@ -/* $Id: indict.c,v 1.7 2002/07/21 09:26:02 in2 Exp $ */ +/* $Id: indict.c,v 1.8 2002/07/22 19:02:00 in2 Exp $ */ #include "bbs.h" #define REFER "etc/dicts" @@ -19,7 +19,7 @@ addword(char word[]) clear(); move(4, 0); outs(" \033[31m警告\033[m:若蓄意填寫假資料將\033[36m砍id\033[m處份\n"); - sprintf(temp, "\n輸入範利\n:\033[33m%s\033[m", buf); + snprintf(temp, sizeof(temp), "\n輸入範利\n:\033[33m%s\033[m", buf); outs(temp); outs("\n請依上列範例輸入一行資料(直接enter放棄)\n"); getdata(10, 0, ":", buf, 65, DOECHO); @@ -47,7 +47,7 @@ choose_dict(void) if ((fp = fopen(REFER, "r"))) { for (c = 0; fscanf(fp, "%s %s", buf[c], data[c]) != EOF; c++) { - sprintf(cho, "\n " + snprintf(cho, sizeof(cho), "\n " "(\033[36m%d\033[m) %-20s大字典", c + 1, buf[c]); outs(cho); } @@ -94,15 +94,18 @@ use_dict() clear(); - sprintf(buf, "\033[45m ●\033[1;44;33m" - " %-14s\033[3;45m ● ", dict); + snprintf(buf, sizeof(buf), + "\033[45m ●\033[1;44;33m" + " %-14s\033[3;45m ● ", dict); strlcpy(&buf[100], "\033[m\n", sizeof(buf) - 100); for (;;) { move(0, 0); - sprintf(lang, " 請輸入關鍵字串(%s) 或指令(h,t,a)\n", dict); + snprintf(lang, sizeof(lang), + " 請輸入關鍵字串(%s) 或指令(h,t,a)\n", dict); outs(lang); - sprintf(lang, "[\033[32m<關鍵字>\033[m|\033[32mh\033[m:help|\033[32m" - "t\033[m:所有資料|\033[32ma\033[m:新增資料%s]\n:", sys); + snprintf(lang, sizeof(lang), + "[\033[32m<關鍵字>\033[m|\033[32mh\033[m:help|\033[32m" + "t\033[m:所有資料|\033[32ma\033[m:新增資料%s]\n:", sys); outs(lang); getdata(2, 0, ":", word, 18, DOECHO); outs("資料搜尋中請稍候...."); diff --git a/pttbbs/mbbsd/io.c b/pttbbs/mbbsd/io.c index 1e748cc6..721b54a2 100644 --- a/pttbbs/mbbsd/io.c +++ b/pttbbs/mbbsd/io.c @@ -1,4 +1,4 @@ -/* $Id: io.c,v 1.21 2002/07/21 20:39:34 kcwu Exp $ */ +/* $Id: io.c,v 1.22 2002/07/22 19:02:00 in2 Exp $ */ #include "bbs.h" #if defined(linux) @@ -474,7 +474,7 @@ oldgetdata(int line, int col, char *prompt, char *buf, int len, int echo) buf[0] = ch | 32; #ifdef SUPPORT_GB if (echo == DOECHO && current_font_type == TYPE_GB) { - strlcpy(buf, hc_convert_str(buf, HC_GBtoBIG, HC_DO_SINGLE), SIZEOF(buf)); + strcpy(buf, hc_convert_str(buf, HC_GBtoBIG, HC_DO_SINGLE)); } #endif return clen; diff --git a/pttbbs/mbbsd/kaede.c b/pttbbs/mbbsd/kaede.c index 41b927c1..b5c1a25e 100644 --- a/pttbbs/mbbsd/kaede.c +++ b/pttbbs/mbbsd/kaede.c @@ -1,4 +1,4 @@ -/* $Id: kaede.c,v 1.11 2002/07/21 09:33:34 in2 Exp $ */ +/* $Id: kaede.c,v 1.12 2002/07/22 19:02:00 in2 Exp $ */ #include "bbs.h" char * @@ -67,7 +67,7 @@ Rename(char *src, char *dst) if (!strchr(src, ';') && !strchr(dst, ';')) //Ptt 黎ㄔ膨`指令 { - sprintf(buf, "/bin/mv %s %s", src, dst); + snprintf(buf, sizeof(buf), "/bin/mv %s %s", src, dst); system(buf); } return -1; @@ -83,7 +83,7 @@ Link(char *src, char *dst) if (symlink(dst, src) == 0) return 0; - sprintf(cmd, "/bin/cp -R %s %s", src, dst); + snprintf(cmd, sizeof(cmd), "/bin/cp -R %s %s", src, dst); return system(cmd); } @@ -94,7 +94,8 @@ my_ctime(const time_t * t) static char ans[100]; tp = localtime(t); - sprintf(ans, "%02d/%02d/%02d %02d:%02d:%02d", (tp->tm_year % 100), - tp->tm_mon + 1, tp->tm_mday, tp->tm_hour, tp->tm_min, tp->tm_sec); + snprintf(ans, sizeof(ans), + "%02d/%02d/%02d %02d:%02d:%02d", (tp->tm_year % 100), + tp->tm_mon + 1, tp->tm_mday, tp->tm_hour, tp->tm_min, tp->tm_sec); return ans; } diff --git a/pttbbs/mbbsd/lovepaper.c b/pttbbs/mbbsd/lovepaper.c index 0ab78aa4..47370524 100644 --- a/pttbbs/mbbsd/lovepaper.c +++ b/pttbbs/mbbsd/lovepaper.c @@ -1,4 +1,4 @@ -/* $Id: lovepaper.c,v 1.9 2002/07/21 09:26:02 in2 Exp $ */ +/* $Id: lovepaper.c,v 1.10 2002/07/22 19:02:00 in2 Exp $ */ #include "bbs.h" #define DATA "etc/lovepaper.dat" @@ -14,7 +14,7 @@ x_love() setutmpmode(LOVE); gtime = localtime(&now); - sprintf(buf1, "%c/%s/love%d%d", + snprintf(buf1, sizeof(buf1), "%c/%s/love%d%d", cuser.userid[0], cuser.userid, gtime->tm_sec, gtime->tm_min); strcat(path, buf1); move(1, 0); diff --git a/pttbbs/mbbsd/mail.c b/pttbbs/mbbsd/mail.c index d5426163..786d3151 100644 --- a/pttbbs/mbbsd/mail.c +++ b/pttbbs/mbbsd/mail.c @@ -1,4 +1,4 @@ -/* $Id: mail.c,v 1.21 2002/07/21 09:26:02 in2 Exp $ */ +/* $Id: mail.c,v 1.22 2002/07/22 19:02:00 in2 Exp $ */ #include "bbs.h" char currmaildir[32]; static char msg_cc[] = "\033[32m[群組名單]\033[m\n"; @@ -52,8 +52,9 @@ built_mail_index() if (genbuf[0] != 'y') return 0; - sprintf(genbuf, BBSHOME "/bin/buildir " BBSHOME "/home/%c/%s", - cuser.userid[0], cuser.userid); + snprintf(genbuf, sizeof(genbuf), + BBSHOME "/bin/buildir " BBSHOME "/home/%c/%s", + cuser.userid[0], cuser.userid); move(22, 0); prints("\033[1;31m已經處理完畢!! 諸多不便 敬請原諒~\033[m"); pressanykey(); @@ -198,7 +199,7 @@ do_hold_mail(char *fpath, char *receiver, char *holder) mymail.filemode = FILE_READ | FILE_HOLD; strlcpy(mymail.owner, "[備.忘.錄]", sizeof(mymail.owner)); if (receiver) { - sprintf(title, "(%s) %s", receiver, save_title); + snprintf(title, sizeof(title), "(%s) %s", receiver, save_title); strncpy(mymail.title, title, TTLEN); } else strlcpy(mymail.title, save_title, sizeof(mymail.title)); @@ -463,7 +464,7 @@ multi_send(char *title) do_reply_title(2, title); else { getdata(2, 0, "主題:", fpath, sizeof(fpath), DOECHO); - sprintf(save_title, "[通告] %s", fpath); + snprintf(save_title, sizeof(save_title), "[通告] %s", fpath); } setuserfile(fpath, fn_notes); @@ -569,7 +570,8 @@ mail_all() stand_title("給所有使用者的系統通告"); setutmpmode(SMAIL); getdata(2, 0, "主題:", fpath, sizeof(fpath), DOECHO); - sprintf(save_title, "[系統通告]\033[1;32m %s\033[m", fpath); + snprintf(save_title, sizeof(save_title), + "[系統通告]\033[1;32m %s\033[m", fpath); setuserfile(fpath, fn_notes); @@ -627,7 +629,8 @@ mail_all() sethomedir(genbuf, userid); if (append_record(genbuf, &mymail, sizeof(mymail)) == -1) outs(err_uid); - sprintf(genbuf, "%*s %5d / %5d", IDLEN + 1, userid, i + 1, unum); + snprintf(genbuf, sizeof(genbuf), + "%*s %5d / %5d", IDLEN + 1, userid, i + 1, unum); outmsg(genbuf); refresh(); } @@ -641,8 +644,8 @@ mail_mbox() char cmd[100]; fileheader_t fhdr; - sprintf(cmd, "/tmp/%s.uu", cuser.userid); - sprintf(fhdr.title, "%s 私人資料", cuser.userid); + snprintf(cmd, sizeof(cmd), "/tmp/%s.uu", cuser.userid); + snprintf(fhdr.title, sizeof(fhdr.title), "%s 私人資料", cuser.userid); doforward(cmd, &fhdr, 'Z'); return 0; } @@ -659,7 +662,7 @@ m_forward(int ent, fileheader_t * fhdr, char *direct) strlcpy(quote_user, fhdr->owner, sizeof(quote_user)); setuserfile(quote_file, fhdr->filename); - sprintf(save_title, "%.64s (fwd)", fhdr->title); + snprintf(save_title, sizeof(save_title), "%.64s (fwd)", fhdr->title); move(1, 0); clrtobot(); prints("轉信給: %s\n標 題: %s\n", uid, save_title); @@ -805,17 +808,19 @@ mailtitle() char buf[256] = ""; showtitle("\0郵件選單", BBSName); - sprintf(buf, "[←]離開[↑↓]選擇[→]閱\讀信件 [R]回信 [x]轉達 " - "[y]群組回信 [O]站外信:%s [h]求助\n\033[7m" - "編號 日 期 作 者 信 件 標 題 \033[32m", - HAS_PERM(PERM_NOOUTMAIL) ? "\033[31m關\033[m" : "開"); + snprintf(buf, sizeof(buf), + "[←]離開[↑↓]選擇[→]閱\讀信件 [R]回信 [x]轉達 " + "[y]群組回信 [O]站外信:%s [h]求助\n\033[7m" + "編號 日 期 作 者 信 件 標 題 \033[32m", + HAS_PERM(PERM_NOOUTMAIL) ? "\033[31m關\033[m" : "開"); outs(buf); buf[0] = 0; if (mailsumlimit) { - sprintf(buf, "(容量:%d/%dk %d/%d篇)", mailsum, mailsumlimit, - mailkeep, mailmaxkeep); + snprintf(buf, sizeof(buf), + "(容量:%d/%dk %d/%d篇)", mailsum, mailsumlimit, + mailkeep, mailmaxkeep); } - sprintf(buf, "%s%*s\033[m", buf, 29 - (int)strlen(buf), ""); + snprintf(buf, sizeof(buf), "%s%*s\033[m", buf, 29 - (int)strlen(buf), ""); outs(buf); } @@ -1134,11 +1139,11 @@ mail_cross_post(int ent, fileheader_t * fhdr, char *direct) } } if (ent) - sprintf(xtitle, "[轉錄]%.66s", fhdr->title); + snprintf(xtitle, sizeof(xtitle), "[轉錄]%.66s", fhdr->title); else strlcpy(xtitle, fhdr->title, sizeof(xtitle)); - sprintf(genbuf, "採用原標題《%.60s》嗎?[Y] ", xtitle); + snprintf(genbuf, sizeof(genbuf), "採用原標題《%.60s》嗎?[Y] ", xtitle); getdata(2, 0, genbuf, genbuf2, sizeof(genbuf2), LCECHO); if (*genbuf2 == 'n') if (getdata(2, 0, "標題:", genbuf, TTLEN, DOECHO)) @@ -1202,7 +1207,7 @@ mail_man() int stat0 = currstat; sethomeman(buf, cuser.userid); - sprintf(buf1, "%s 的信件夾", cuser.userid); + snprintf(buf1, sizeof(buf1), "%s 的信件夾", cuser.userid); a_menu(buf1, buf, 1); currutmp->mode = mode0; currstat = stat0; @@ -1294,7 +1299,7 @@ mail_waterball(int ent, fileheader_t * fhdr, char *direct) "系統將會按照和不同人丟的水球各自獨立\n" "於整點的時候 (尖鋒時段除外) 將資料整理好寄送給您\n\n\n"); if (address[0]) { - sprintf(genbuf, "寄給 [%s] 嗎(Y/N/Q)?[Y] ", address); + snprintf(genbuf, sizeof(genbuf), "寄給 [%s] 嗎(Y/N/Q)?[Y] ", address); getdata(b_lines - 5, 0, genbuf, fname, 3, LCECHO); if (fname[0] == 'q') { outmsg("取消處理"); @@ -1315,7 +1320,7 @@ mail_waterball(int ent, fileheader_t * fhdr, char *direct) if (invalidaddr(address)) return -2; - //sprintf(fname, "%d\n", cmode); + //snprintf(fname, sizeof(fname), "%d\n", cmode); move(b_lines - 4, 0); outs("系統提供兩種模式: \n" "模式 0: 精簡模式, 將不含顏色控制碼, 方便以純文字編輯器整理收藏\n" @@ -1327,14 +1332,14 @@ mail_waterball(int ent, fileheader_t * fhdr, char *direct) } cmode = (fname[0] != '0' && fname[0] != '1') ? 1 : fname[0] - '0'; - sprintf(fname, BBSHOME "/jobspool/water.src.%s-%d", - cuser.userid, (int)now); - sprintf(genbuf, "cp " BBSHOME "/home/%c/%s/%s %s", - cuser.userid[0], cuser.userid, fhdr->filename, fname); + snprintf(fname, sizeof(fname), BBSHOME "/jobspool/water.src.%s-%d", + cuser.userid, (int)now); + snprintf(genbuf, sizeof(genbuf), "cp " BBSHOME "/home/%c/%s/%s %s", + cuser.userid[0], cuser.userid, fhdr->filename, fname); system(genbuf); /* dirty code ;x */ - sprintf(fname, BBSHOME "/jobspool/water.des.%s-%d", - cuser.userid, (int)now); + snprintf(fname, sizeof(fname), BBSHOME "/jobspool/water.des.%s-%d", + cuser.userid, (int)now); fp = fopen(fname, "wt"); fprintf(fp, "%s\n%s\n%d\n", cuser.userid, address, cmode); fclose(fp); @@ -1458,11 +1463,13 @@ bbs_sendmail(char *fpath, char *title, char *receiver) } /* Running the sendmail */ if (fpath == NULL) { - sprintf(genbuf, "/usr/sbin/sendmail %s > /dev/null", receiver); + snprintf(genbuf, sizeof(genbuf), + "/usr/sbin/sendmail %s > /dev/null", receiver); fin = fopen("etc/confirm", "r"); } else { - sprintf(genbuf, "/usr/sbin/sendmail -f %s%s %s > /dev/null", - cuser.userid, str_mail_address, receiver); + snprintf(genbuf, sizeof(genbuf), + "/usr/sbin/sendmail -f %s%s %s > /dev/null", + cuser.userid, str_mail_address, receiver); fin = fopen(fpath, "r"); } fout = popen(genbuf, "w"); @@ -1514,7 +1521,7 @@ bsmtp(char *fpath, char *title, char *rcpt, int method) /* stamp the queue file */ strlcpy(buf, "out/", sizeof(buf)); for (;;) { - sprintf(buf + 4, "M.%ld.A", ++chrono); + snprintf(buf + 4, sizeof(buf) - 4, "M.%ld.A", ++chrono); if (!dashf(buf)) { Link(fpath, buf); break; @@ -1550,7 +1557,8 @@ doforward(char *direct, fileheader_t * fh, int mode) strlcpy(address, cuser.email, sizeof(address)); if (address[0]) { - sprintf(genbuf, "確定轉寄給 [%s] 嗎(Y/N/Q)?[Y] ", address); + snprintf(genbuf, sizeof(genbuf), + "確定轉寄給 [%s] 嗎(Y/N/Q)?[Y] ", address); getdata(b_lines - 1, 0, genbuf, fname, 3, LCECHO); if (fname[0] == 'q') { @@ -1567,7 +1575,8 @@ doforward(char *direct, fileheader_t * fh, int mode) if (strchr(fname, '.')) strlcpy(address, fname, sizeof(address)); else - sprintf(address, "%s.bbs@%s", fname, MYHOSTNAME); + snprintf(address, sizeof(address), + "%s.bbs@%s", fname, MYHOSTNAME); } else { outmsg("取消轉寄"); return 1; @@ -1577,7 +1586,7 @@ doforward(char *direct, fileheader_t * fh, int mode) if (invalidaddr(address)) return -2; - sprintf(fname, "正轉寄給 %s, 請稍候...", address); + snprintf(fname, sizeof(fname), "正轉寄給 %s, 請稍候...", address); outmsg(fname); move(b_lines - 1, 0); refresh(); @@ -1586,19 +1595,20 @@ doforward(char *direct, fileheader_t * fh, int mode) if (HAS_PERM(PERM_LOGUSER)) { char msg[200]; - sprintf(msg, "%s mailforward to %s at %s", - cuser.userid, address, Cdate(&now)); + snprintf(msg, sizeof(msg), "%s mailforward to %s at %s", + cuser.userid, address, Cdate(&now)); log_user(msg); } if (mode == 'Z') { - sprintf(fname, TAR_PATH " cfz /tmp/home.%s.tgz home/%c/%s; " - MUTT_PATH " -a /tmp/home.%s.tgz -s 'home.%s.tgz' '%s' </dev/null;" - "rm /tmp/home.%s.tgz", - cuser.userid, cuser.userid[0], cuser.userid, - cuser.userid, cuser.userid, address, cuser.userid); + snprintf(fname, sizeof(fname), + TAR_PATH " cfz /tmp/home.%s.tgz home/%c/%s; " + MUTT_PATH " -a /tmp/home.%s.tgz -s 'home.%s.tgz' '%s' </dev/null;" + "rm /tmp/home.%s.tgz", + cuser.userid, cuser.userid[0], cuser.userid, + cuser.userid, cuser.userid, address, cuser.userid); system(fname); return 0; - sprintf(fname, TAR_PATH " cfz - home/%c/%s | " + snprintf(fname, sizeof(fname), TAR_PATH " cfz - home/%c/%s | " "/usr/bin/uuencode %s.tgz > %s", cuser.userid[0], cuser.userid, cuser.userid, direct); system(fname); @@ -1606,15 +1616,17 @@ doforward(char *direct, fileheader_t * fh, int mode) } else if (mode == 'U') { char tmp_buf[128]; - sprintf(fname, "/tmp/bbs.uu%05d", currpid); - sprintf(tmp_buf, "/usr/bin/uuencode %s/%s uu.%05d > %s", - direct, fh->filename, currpid, fname); + snprintf(fname, sizeof(fname), "/tmp/bbs.uu%05d", currpid); + snprintf(tmp_buf, sizeof(tmp_buf), + "/usr/bin/uuencode %s/%s uu.%05d > %s", + direct, fh->filename, currpid, fname); system(tmp_buf); } else if (mode == 'F') { char tmp_buf[128]; - sprintf(fname, "/tmp/bbs.f%05d", currpid); - sprintf(tmp_buf, "cp %s/%s %s", direct, fh->filename, fname); + snprintf(fname, sizeof(fname), "/tmp/bbs.f%05d", currpid); + snprintf(tmp_buf, sizeof(tmp_buf), + "cp %s/%s %s", direct, fh->filename, fname); system(tmp_buf); } else return -1; @@ -1693,7 +1705,7 @@ mail_justify(userec_t muser) checksum = (checksum << 1) ^ ch; } - sprintf(title, "[PTT BBS]To %s(%d:%d) [User Justify]", + snprintf(title, sizeof(title), "[PTT BBS]To %s(%d:%d) [User Justify]", muser.userid, getuser(muser.userid) + MAGIC_KEY, checksum); if ( #ifndef USE_BSMTP diff --git a/pttbbs/mbbsd/mbbsd.c b/pttbbs/mbbsd/mbbsd.c index 6b3e15f3..9a3eeb8a 100644 --- a/pttbbs/mbbsd/mbbsd.c +++ b/pttbbs/mbbsd/mbbsd.c @@ -1,4 +1,4 @@ -/* $Id: mbbsd.c,v 1.43 2002/07/21 20:39:34 kcwu Exp $ */ +/* $Id: mbbsd.c,v 1.44 2002/07/22 19:02:00 in2 Exp $ */ #include "bbs.h" #define SOCKET_QLEN 4 @@ -118,8 +118,8 @@ log_user(char *msg) { char filename[200]; - sprintf(filename, BBSHOME "/home/%c/%s/USERLOG", - cuser.userid[0], cuser.userid); + snprintf(filename, sizeof(filename), BBSHOME "/home/%c/%s/USERLOG", + cuser.userid[0], cuser.userid); log_file(filename, msg); } @@ -130,13 +130,15 @@ log_usies(char *mode, char *mesg) char genbuf[200]; if (!mesg) - sprintf(genbuf, cuser.userid[0] ? "%s %s %-12s Stay:%d (%s)" : - "%s %s %s Stay:%d (%s)", - Cdate(&now), mode, cuser.userid, - (int)(now - login_start_time) / 60, cuser.username); + snprintf(genbuf, sizeof(genbuf), + cuser.userid[0] ? "%s %s %-12s Stay:%d (%s)" : + "%s %s %s Stay:%d (%s)", + Cdate(&now), mode, cuser.userid, + (int)(now - login_start_time) / 60, cuser.username); else - sprintf(genbuf, cuser.userid[0] ? "%s %s %-12s %s" : "%s %s %s%s", - Cdate(&now), mode, cuser.userid, mesg); + snprintf(genbuf, sizeof(genbuf), + cuser.userid[0] ? "%s %s %-12s %s" : "%s %s %s%s", + Cdate(&now), mode, cuser.userid, mesg); log_file(FN_USIES, genbuf); /* 追蹤使用者 */ @@ -252,10 +254,11 @@ talk_request(int sig) char buf[200]; time_t now = time(0); - sprintf(buf, "\033[33;41m★%s\033[34;47m [%s] %s \033[0m", - SHM->uinfo[currutmp->destuip].userid, my_ctime(&now), - (currutmp->sig == 2) ? "重要消息廣播!(請Ctrl-U,l查看熱訊記錄)" - : "呼叫、呼叫,聽到請回答"); + snprintf(buf, sizeof(buf), + "\033[33;41m★%s\033[34;47m [%s] %s \033[0m", + SHM->uinfo[currutmp->destuip].userid, my_ctime(&now), + (currutmp->sig == 2) ? "重要消息廣播!(請Ctrl-U,l查看熱訊記錄)" + : "呼叫、呼叫,聽到請回答"); move(0, 0); clrtoeol(); outs(buf); @@ -281,8 +284,8 @@ void show_call_in(int save, int which) { char buf[200]; - sprintf(buf, "\033[1;33;46m★%s\033[37;45m %s \033[m", - currutmp->msgs[which].userid, currutmp->msgs[which].last_call_in); + snprintf(buf, sizeof(buf), "\033[1;33;46m★%s\033[37;45m %s \033[m", + currutmp->msgs[which].userid, currutmp->msgs[which].last_call_in); move(b_lines, 0); clrtoeol(); refresh(); @@ -485,7 +488,7 @@ logattempt(char *uid, char type) int fd, len; char genbuf[200]; - sprintf(genbuf, "%c%-12s[%s] %s@%s\n", type, uid, + snprintf(genbuf, sizeof(genbuf), "%c%-12s[%s] %s@%s\n", type, uid, Cdate(&login_start_time), remoteusername, fromhost); len = strlen(genbuf); if ((fd = open(str_badlogin, O_WRONLY | O_CREAT | O_APPEND, 0644)) > 0) { @@ -493,7 +496,8 @@ logattempt(char *uid, char type) close(fd); } if (type == '-') { - sprintf(genbuf, "[%s] %s\n", Cdate(&login_start_time), fromhost); + snprintf(genbuf, sizeof(genbuf), + "[%s] %s\n", Cdate(&login_start_time), fromhost); len = strlen(genbuf); sethomefile(fname, uid, str_badlogin); if ((fd = open(fname, O_WRONLY | O_CREAT | O_APPEND, 0644)) > 0) { @@ -733,7 +737,7 @@ setup_utmp(int mode) #ifndef FAST_LOGIN setuserfile(buf, "remoteuser"); - strlcpy(remotebuf, fromhost, SIZEOF(remotebuf)); + strlcpy(remotebuf, fromhost, sizeof(fromhost)); strcat(remotebuf, ctime(&now)); remotebuf[strlen(remotebuf) - 1] = 0; add_distinct(buf, remotebuf); @@ -794,7 +798,7 @@ user_login() char buf[80]; int nScreens; for (nScreens = 0; nScreens < 10; ++nScreens) { - sprintf(buf, "etc/Welcome_login.%d", nScreens); + snprintf(buf, sizeof(buf), "etc/Welcome_login.%d", nScreens); if (access(buf, 0) < 0) break; } @@ -803,7 +807,7 @@ user_login() //multi screen error ? more("etc/Welcome_login", NA); } else { - sprintf(buf, "etc/Welcome_login.%d", (int)login_start_time % nScreens); + snprintf(buf, sizeof(buf), "etc/Welcome_login.%d", (int)login_start_time % nScreens); more(buf, NA); } #else @@ -856,11 +860,14 @@ user_login() "愛之味", "天上", "藍色珊瑚礁" }; i = login_start_time % 13; - sprintf(cuser.username, "海邊漂來的%s", nick[(int)i]); - sprintf(currutmp->username, cuser.username); - sprintf(cuser.realname, name[(int)i]); - sprintf(currutmp->realname, cuser.realname); - sprintf(cuser.address, addr[(int)i]); + snprintf(cuser.username, sizeof(cuser.username), + "海邊漂來的%s", nick[(int)i]); + strlcpy(currutmp->username, cuser.username, + sizeof(currutmp->username)); + strlcpy(cuser.realname, name[(int)i], sizeof(cuser.realname)); + strlcpy(currutmp->realname, cuser.realname, + sizeof(currutmp->realname)); + strlcpy(cuser.address, addr[(int)i], sizeof(cuser.address)); cuser.sex = i % 8; currutmp->pager = 2; pressanykey(); @@ -886,7 +893,7 @@ do_aloha(char *hello) setuserfile(genbuf, "aloha"); if ((fp = fopen(genbuf, "r"))) { - sprintf(genbuf, hello); + snprintf(genbuf, sizeof(genbuf), hello); while (fgets(userid, 80, fp)) { userinfo_t *uentp; int tuid; @@ -1114,7 +1121,7 @@ getremotename(struct sockaddr_in * from, char *rhost, char *rname) */ if ((cp = (char *)strchr(user, '\r'))) *cp = 0; - strlcpy(rname, user, SIZEOF(rname)); + strlcpy(rname, user, sizeof(user)); } } alarm(0); @@ -1231,7 +1238,7 @@ daemon_login(int argc, char *argv[], char *envp[]) else if (argc >= 2) listen_port = atoi(argv[1]); - sprintf(margs, "%s %d ", argv[0], listen_port); + snprintf(margs, sizeof(margs), "%s %d ", argv[0], listen_port); /* port binding */ xsin.sin_family = AF_INET; @@ -1248,7 +1255,7 @@ daemon_login(int argc, char *argv[], char *envp[]) setuid(BBSUID); chdir(BBSHOME); - sprintf(buf, "run/mbbsd.%d.pid", listen_port); + snprintf(buf, sizeof(buf), "run/mbbsd.%d.pid", listen_port); if ((fp = fopen(buf, "w"))) { fprintf(fp, "%d\n", getpid()); fclose(fp); diff --git a/pttbbs/mbbsd/menu.c b/pttbbs/mbbsd/menu.c index d51dd01e..08efc53d 100644 --- a/pttbbs/mbbsd/menu.c +++ b/pttbbs/mbbsd/menu.c @@ -1,4 +1,4 @@ -/* $Id: menu.c,v 1.15 2002/07/21 09:26:02 in2 Exp $ */ +/* $Id: menu.c,v 1.16 2002/07/22 19:02:00 in2 Exp $ */ #include "bbs.h" /* help & menu processring */ @@ -41,8 +41,9 @@ showtitle(char *title, char *mid) title++; #ifdef DEBUG else { - sprintf(numreg, "\033[41;5m current pid: %6d " TITLE_COLOR, - getpid()); + snprintf(numreg, sizeof(numreg), + "\033[41;5m current pid: %6d " TITLE_COLOR, + getpid()); mid = numreg; spc = 22; } @@ -51,9 +52,9 @@ showtitle(char *title, char *mid) mid = "\033[41;5m 郵差來按鈴囉 " TITLE_COLOR; spc = 22; } else if (HAS_PERM(PERM_SYSOP) && (nreg = dashs(fn_register) / 163) > 10) { - sprintf(numreg, "\033[41;5m 有%03d/%03d未審核 " TITLE_COLOR, - nreg, - (int)dashs("register.new.tmp") / 163); + snprintf(numreg, sizeof(numreg), + "\033[41;5m 有%03d/%03d未審核 " TITLE_COLOR, + nreg, (int)dashs("register.new.tmp") / 163); mid = numreg; spc = 22; } @@ -141,13 +142,14 @@ movie(int i) outs(reset_color); } i = ptime->tm_wday << 1; - sprintf(mystatus, "\033[34;46m[%d/%d 星期%c%c %d:%02d]\033[1;33;45m%-14s" - "\033[30;47m 目前坊裡有 \033[31m%d\033[30m人, 我是\033[31m%-12s" - "\033[30m[扣機]\033[31m%s\033[0m", - ptime->tm_mon + 1, ptime->tm_mday, myweek[i], myweek[i + 1], - ptime->tm_hour, ptime->tm_min, currutmp->birth ? - "生日要請客唷" : SHM->today_is, - SHM->UTMPnumber, cuser.userid, msgs[currutmp->pager]); + snprintf(mystatus, sizeof(mystatus), + "\033[34;46m[%d/%d 星期%c%c %d:%02d]\033[1;33;45m%-14s" + "\033[30;47m 目前坊裡有 \033[31m%d\033[30m人, 我是\033[31m%-12s" + "\033[30m[扣機]\033[31m%s\033[0m", + ptime->tm_mon + 1, ptime->tm_mday, myweek[i], myweek[i + 1], + ptime->tm_hour, ptime->tm_min, currutmp->birth ? + "生日要請客唷" : SHM->today_is, + SHM->UTMPnumber, cuser.userid, msgs[currutmp->pager]); outmsg(mystatus); refresh(); } @@ -165,7 +167,7 @@ show_menu(commands_t * p) move(menu_row, 0); while ((s = p[n].desc)) { if (HAS_PERM(p[n].level)) { - sprintf(buf, s + 2, state[cuser.proverb % 4]); + snprintf(buf, sizeof(buf), s + 2, state[cuser.proverb % 4]); prints("%*s (\033[1;36m%c\033[0m)%s\n", menu_column, "", s[1], buf); } diff --git a/pttbbs/mbbsd/more.c b/pttbbs/mbbsd/more.c index 33c6e1b3..2acf144d 100644 --- a/pttbbs/mbbsd/more.c +++ b/pttbbs/mbbsd/more.c @@ -1,4 +1,4 @@ -/* $Id: more.c,v 1.17 2002/07/21 09:26:02 in2 Exp $ */ +/* $Id: more.c,v 1.18 2002/07/22 19:02:00 in2 Exp $ */ #include "bbs.h" #define MORE_BUFSIZE 4096 #define MORE_WINSIZE 4096 @@ -246,12 +246,14 @@ more(char *fpath, int promptend) strncpy(SearchStr, pos, strlen(search_str)); SearchStr[strlen(search_str)] = 0; searching = 0; - sprintf(msg, "%.*s\033[7m%s\033[m", pos - buf, buf, - SearchStr); + snprintf(msg, sizeof(msg), + "%.*s\033[7m%s\033[m", pos - buf, buf, + SearchStr); while ((pos = fptr(pos1 = pos + strlen(search_str), search_str))) { - sprintf(buf1, "%.*s\033[7m%s\033[m", pos - pos1, - pos1, SearchStr); + snprintf(buf1, sizeof(buf1), + "%.*s\033[7m%s\033[m", pos - pos1, + pos1, SearchStr); strcat(msg, buf1); } strcat(msg, pos1); @@ -497,7 +499,8 @@ more(char *fpath, int promptend) char tmpbuf[128]; setuserfile(tmpbuf, ask_tmpbuf(b_lines - 1)); - sprintf(buf, "cp -f %s %s", fpath, tmpbuf); + snprintf(buf, sizeof(buf), + "cp -f %s %s", fpath, tmpbuf); system(buf); } if (pageno) diff --git a/pttbbs/mbbsd/name.c b/pttbbs/mbbsd/name.c index 72aba76c..cbd872d9 100644 --- a/pttbbs/mbbsd/name.c +++ b/pttbbs/mbbsd/name.c @@ -1,4 +1,4 @@ -/* $Id: name.c,v 1.13 2002/07/21 20:39:34 kcwu Exp $ */ +/* $Id: name.c,v 1.14 2002/07/22 19:02:00 in2 Exp $ */ #include "bbs.h" static word_t *current = NULL; @@ -37,7 +37,7 @@ UserSubArray(char cwbuf[][IDLEN + 1], char cwlist[][IDLEN + 1], for (n = 0; n < cwnum; n++) { ch = cwlist[n][pos]; if (ch == key || ch == key2) - strlcpy(cwbuf[num++], cwlist[n], SIZEOF(cwbuf[num])); + strlcpy(cwbuf[num++], cwlist[n], sizeof(cwbuf[num])); } return num; } diff --git a/pttbbs/mbbsd/osdep.c b/pttbbs/mbbsd/osdep.c index f1b65242..6357a829 100644 --- a/pttbbs/mbbsd/osdep.c +++ b/pttbbs/mbbsd/osdep.c @@ -1,4 +1,4 @@ -/* $Id: osdep.c,v 1.5 2002/07/21 09:26:02 in2 Exp $ */ +/* $Id: osdep.c,v 1.6 2002/07/22 19:02:00 in2 Exp $ */ #include "bbs.h" #if __FreeBSD__ @@ -57,7 +57,7 @@ cpuload(char *str) } if (str) { if (l[0] != -1) - sprintf(str, " %.2f %.2f %.2f", l[0], l[1], l[2]); + snprintf(str, sizeof(str), " %.2f %.2f %.2f", l[0], l[1], l[2]); else strcpy(str, " (unknown) "); } diff --git a/pttbbs/mbbsd/page.c b/pttbbs/mbbsd/page.c index 988b222b..e32b73f2 100644 --- a/pttbbs/mbbsd/page.c +++ b/pttbbs/mbbsd/page.c @@ -1,4 +1,4 @@ -/* $Id: page.c,v 1.8 2002/07/21 09:26:02 in2 Exp $ */ +/* $Id: page.c,v 1.9 2002/07/22 19:02:00 in2 Exp $ */ #include "bbs.h" #define hpressanykey(a) {move(22, 0); prints(a); pressanykey();} @@ -8,7 +8,7 @@ filt_railway(char *fpath) char buf[256], tmppath[32]; FILE *fp = fopen(fpath, "w"), *tp; - sprintf(tmppath, "%s.railway", fpath); + snprintf(tmppath, sizeof(tmppath), "%s.railway", fpath); if (!fp || !(tp = fopen(tmppath, "r"))) return; @@ -104,7 +104,7 @@ main_railway() strlcpy(mhdr.owner, "Ptt搜尋器", sizeof(mhdr.owner)); strncpy(mhdr.title, "火車時刻搜尋結果", TTLEN); - sprintf(command, "echo \"from-station=%s&to-station=%s" + snprintf(command, sizeof(command), "echo \"from-station=%s&to-station=%s" "&from-time=%02d00&to-time=%02d00&tt=%s&type=%s\" | " "lynx -dump -post_data " "\"http://www.railway.gov.tw/cgi-bin/timetk.cgi\" > %s.railway", diff --git a/pttbbs/mbbsd/read.c b/pttbbs/mbbsd/read.c index 5a915d3b..f979e2dd 100644 --- a/pttbbs/mbbsd/read.c +++ b/pttbbs/mbbsd/read.c @@ -1,4 +1,4 @@ -/* $Id: read.c,v 1.10 2002/07/21 09:26:02 in2 Exp $ */ +/* $Id: read.c,v 1.11 2002/07/22 19:02:00 in2 Exp $ */ #include "bbs.h" #define MAXPATHLEN 256 @@ -76,7 +76,7 @@ Tagger(time_t chrono, int recno, int mode) void EnumTagName(char *fname, int locus) { - sprintf(fname, "M.%d.A", (int)TagList[locus].chrono); + snprintf(fname, sizeof(fname), "M.%d.A", (int)TagList[locus].chrono); } void @@ -96,7 +96,7 @@ AskTag(char *msg) int num; num = TagNum; - sprintf(buf, "◆ %s A)文章 T)標記 Q)uit?", msg); + snprintf(buf, sizeof(buf), "◆ %s A)文章 T)標記 Q)uit?", msg); switch (rget(b_lines - 1, buf)) { case 'q': num = -1; @@ -346,8 +346,9 @@ thread(keeploc_t * locmem, int stype) else if (*currauthor) strlcpy(a_ans, currauthor, sizeof(a_ans)); } - sprintf(s_pmt, "%s搜尋%s [%s] ", (stype & RS_FORWARD) ? "往後" : "往前", - (stype & RS_TITLE) ? "標題" : "作者", query); + snprintf(s_pmt, sizeof(s_pmt), + "%s搜尋%s [%s] ", (stype & RS_FORWARD) ? "往後" : "往前", + (stype & RS_TITLE) ? "標題" : "作者", query); getdata(b_lines - 1, 0, s_pmt, ans, sizeof(ans), DOECHO); if (*ans) strcpy(query, ans); @@ -471,8 +472,8 @@ select_read(keeploc_t * locmem, int sr_mode) char newdata[35]; query = (sr_mode == RS_RELATED) ? t_ans : a_ans; - sprintf(buff, "搜尋%s [%s] ", - (sr_mode == RS_RELATED) ? "標題" : "作者", query); + snprintf(buff, sizeof(buff), "搜尋%s [%s] ", + (sr_mode == RS_RELATED) ? "標題" : "作者", query); getdata(b_lines, 0, buff, newdata, sizeof(newdata), DOECHO); if (newdata[0]) strcpy(query, newdata); @@ -481,7 +482,7 @@ select_read(keeploc_t * locmem, int sr_mode) } if ((fd = open(currdirect, O_RDONLY, 0)) != -1) { - sprintf(genbuf, "SR.%s", cuser.userid); + snprintf(genbuf, sizeof(genbuf), "SR.%s", cuser.userid); if (currstat == RMAIL) sethomefile(fpath, cuser.userid, genbuf); else diff --git a/pttbbs/mbbsd/record.c b/pttbbs/mbbsd/record.c index d8ce7aa2..bd0c5316 100644 --- a/pttbbs/mbbsd/record.c +++ b/pttbbs/mbbsd/record.c @@ -1,4 +1,4 @@ -/* $Id: record.c,v 1.9 2002/07/21 09:26:02 in2 Exp $ */ +/* $Id: record.c,v 1.10 2002/07/22 19:02:00 in2 Exp $ */ #include "bbs.h" #undef HAVE_MMAP @@ -136,9 +136,9 @@ typedef struct nol_t { static void nolfilename(nol_t * n, char *fpath) { - sprintf(n->newfn, "%s.new", fpath); - sprintf(n->oldfn, "%s.old", fpath); - sprintf(n->lockfn, "%s.lock", fpath); + snprintf(n->newfn, sizeof(n->newfn), "%s.new", fpath); + snprintf(n->oldfn, sizeof(n->oldfn), "%s.old", fpath); + snprintf(n->lockfn, sizeof(n->lockfn), "%s.lock", fpath); } int @@ -444,7 +444,8 @@ stampfile(char *fpath, fileheader_t * fh) memset(fh, 0, sizeof(fileheader_t)); strlcpy(fh->filename, ip, sizeof(fh->filename)); ptime = localtime(&dtime); - sprintf(fh->date, "%2d/%02d", ptime->tm_mon + 1, ptime->tm_mday); + snprintf(fh->date, sizeof(fh->date), + "%2d/%02d", ptime->tm_mon + 1, ptime->tm_mday); return 0; } @@ -466,7 +467,8 @@ stampdir(char *fpath, fileheader_t * fh) memset(fh, 0, sizeof(fileheader_t)); strlcpy(fh->filename, ip, sizeof(fh->filename)); ptime = localtime(&dtime); - sprintf(fh->date, "%2d/%02d", ptime->tm_mon + 1, ptime->tm_mday); + snprintf(fh->date, sizeof(fh->date), + "%2d/%02d", ptime->tm_mon + 1, ptime->tm_mday); } void @@ -487,7 +489,8 @@ stamplink(char *fpath, fileheader_t * fh) memset(fh, 0, sizeof(fileheader_t)); strlcpy(fh->filename, ip, sizeof(fh->filename)); ptime = localtime(&dtime); - sprintf(fh->date, "%2d/%02d", ptime->tm_mon + 1, ptime->tm_mday); + snprintf(fh->date, sizeof(fh->date), + "%2d/%02d", ptime->tm_mon + 1, ptime->tm_mday); } int diff --git a/pttbbs/mbbsd/register.c b/pttbbs/mbbsd/register.c index 26204ce8..5ef02f4a 100644 --- a/pttbbs/mbbsd/register.c +++ b/pttbbs/mbbsd/register.c @@ -1,4 +1,4 @@ -/* $Id: register.c,v 1.8 2002/07/21 09:26:02 in2 Exp $ */ +/* $Id: register.c,v 1.9 2002/07/22 19:02:00 in2 Exp $ */ #define _XOPEN_SOURCE #include "bbs.h" @@ -104,18 +104,19 @@ check_and_expire_account(int uid, userec_t * urec) char genbuf[200], genbuf2[200]; int val; if ((val = compute_user_value(urec, now)) < 0) { - sprintf(genbuf, "#%d %-12s %15.15s %d %d %d", + snprintf(genbuf, sizeof(genbuf), "#%d %-12s %15.15s %d %d %d", uid, urec->userid, ctime(&(urec->lastlogin)) + 4, urec->numlogins, urec->numposts, val); if (val > -1 * 60 * 24 * 365) { memset(&zerorec, 0, sizeof(zerorec)); log_usies("CLEAN", genbuf); - sprintf(genbuf, "home/%c/%s", urec->userid[0], + snprintf(genbuf, sizeof(genbuf), "home/%c/%s", urec->userid[0], urec->userid); - sprintf(genbuf2, "tmp/%s", urec->userid); + snprintf(genbuf2, sizeof(genbuf2), "tmp/%s", urec->userid); if (dashd(genbuf) && Rename(genbuf, genbuf2)) { - sprintf(genbuf, "/bin/rm -fr home/%c/%s >/dev/null 2>&1", - urec->userid[0], urec->userid); + snprintf(genbuf, sizeof(genbuf), + "/bin/rm -fr home/%c/%s >/dev/null 2>&1", + urec->userid[0], urec->userid); system(genbuf); } passwd_update(uid, &zerorec); @@ -174,7 +175,7 @@ getnewuserid() safe_sleep(2); exit(1); } - sprintf(genbuf, "uid %d", i); + snprintf(genbuf, sizeof(genbuf), "uid %d", i); log_usies("APPLY", genbuf); strlcpy(zerorec.userid, str_new, sizeof(zerorec.userid)); @@ -214,7 +215,8 @@ new_register() if (id == 999999) outs("此代號已經有人使用 是不死之身"); else { - sprintf(passbuf, "此代號已經有人使用 還有%d天才過期 \n", id / (60 * 24)); + snprintf(passbuf, sizeof(passbuf), + "此代號已經有人使用 還有%d天才過期 \n", id / (60 * 24)); outs(passbuf); } } else diff --git a/pttbbs/mbbsd/screen.c b/pttbbs/mbbsd/screen.c index 59032a85..a7f4526c 100644 --- a/pttbbs/mbbsd/screen.c +++ b/pttbbs/mbbsd/screen.c @@ -1,4 +1,4 @@ -/* $Id: screen.c,v 1.7 2002/07/21 20:39:34 kcwu Exp $ */ +/* $Id: screen.c,v 1.8 2002/07/22 19:02:00 in2 Exp $ */ #include "bbs.h" #ifdef SUPPORT_GB @@ -336,7 +336,7 @@ parsecolor(char *buf) } val = (char *)strtok(NULL, ";"); } - strlcpy(buf, data, SIZEOF(buf)); + strlcpy(buf, data, sizeof(data)); } #define NORMAL (00) @@ -483,7 +483,7 @@ prints(char *fmt,...) char buff[1024]; va_start(args, fmt); - vsprintf(buff, fmt, args); + vsnprintf(buff, sizeof(buff), fmt, args); va_end(args); outs(buff); } diff --git a/pttbbs/mbbsd/stuff.c b/pttbbs/mbbsd/stuff.c index d3297eda..76a3a032 100644 --- a/pttbbs/mbbsd/stuff.c +++ b/pttbbs/mbbsd/stuff.c @@ -1,4 +1,4 @@ -/* $Id: stuff.c,v 1.8 2002/07/21 09:26:02 in2 Exp $ */ +/* $Id: stuff.c,v 1.9 2002/07/22 19:02:00 in2 Exp $ */ #include "bbs.h" /* ----------------------------------------------------- */ @@ -337,19 +337,19 @@ gettime(int line, time_t dt) struct tm *ptime = localtime(&dt), endtime; memcpy(&endtime, ptime, sizeof(struct tm)); - sprintf(yn, "%4d", ptime->tm_year + 1900); + snprintf(yn, sizeof(yn), "%4d", ptime->tm_year + 1900); do { getdata_buf(line, 0, "西元年:", yn, 5, LCECHO); } while ((endtime.tm_year = atoi(yn) - 1900) < 0 || endtime.tm_year > 200); - sprintf(yn, "%d", ptime->tm_mon + 1); + snprintf(yn, sizeof(yn), "%d", ptime->tm_mon + 1); do { getdata_buf(line, 13, "月:", yn, 3, LCECHO); } while ((endtime.tm_mon = atoi(yn) - 1) < 0 || endtime.tm_mon > 11); - sprintf(yn, "%d", ptime->tm_mday); + snprintf(yn, sizeof(yn), "%d", ptime->tm_mday); do { getdata_buf(line, 22, "日:", yn, 3, LCECHO); } while ((endtime.tm_mday = atoi(yn)) < 1 || endtime.tm_mday > 31); - sprintf(yn, "%d", ptime->tm_hour); + snprintf(yn, sizeof(yn), "%d", ptime->tm_hour); do { getdata_buf(line, 31, "時(0-23):", yn, 3, LCECHO); } while ((endtime.tm_hour = atoi(yn)) < 0 || endtime.tm_hour > 23); @@ -434,7 +434,7 @@ vmsg(const char *fmt,...) int ch; va_start(ap, fmt); - vsprintf(msg, fmt, ap); + vsnprintf(msg, sizeof(msg), fmt, ap); va_end(ap); move(b_lines, 0); diff --git a/pttbbs/mbbsd/syspost.c b/pttbbs/mbbsd/syspost.c index 965ce93b..0a527f22 100644 --- a/pttbbs/mbbsd/syspost.c +++ b/pttbbs/mbbsd/syspost.c @@ -1,4 +1,4 @@ -/* $Id: syspost.c,v 1.14 2002/07/21 09:26:02 in2 Exp $ */ +/* $Id: syspost.c,v 1.15 2002/07/22 19:02:00 in2 Exp $ */ #include "bbs.h" void @@ -36,8 +36,9 @@ post_change_perm(int oldperm, int newperm, char *sysopid, char *userid) cuser.userid, reason); fclose(fp); - sprintf(fhdr.title, "[公安報告] 站長%s修改%s權限報告", - cuser.userid, userid); + snprintf(fhdr.title, sizeof(fhdr.title), + "[公安報告] 站長%s修改%s權限報告", + cuser.userid, userid); strlcpy(fhdr.owner, "[系統安全局]", sizeof(fhdr.owner)); append_record("boards/S/Security/.DIR", &fhdr, sizeof(fhdr)); } @@ -60,7 +61,8 @@ post_violatelaw(char *crime, char *police, char *reason, char *result) "因\033[1;35m%s\033[m行為,\n違反本站站規,處以\033[1;35m%s\033[m,特此公告", crime, ctime(&now), police, crime, reason, result); fclose(fp); - sprintf(fhdr.title, "[報告] %-20s 違法判決報告", crime); + snprintf(fhdr.title, sizeof(fhdr.title), + "[報告] %-20s 違法判決報告", crime); strlcpy(fhdr.owner, "[Ptt法院]", sizeof(fhdr.owner)); append_record("boards/S/Security/.DIR", &fhdr, sizeof(fhdr)); @@ -75,7 +77,8 @@ post_violatelaw(char *crime, char *police, char *reason, char *result) "因\033[1;35m%s\033[m行為,\n違反本站站規,處以\033[1;35m%s\033[m,特此公告", crime, ctime(&now), police, crime, reason, result); fclose(fp); - sprintf(fhdr.title, "[報告] %-20s 違法判決報告", crime); + snprintf(fhdr.title, sizeof(fhdr.title), + "[報告] %-20s 違法判決報告", crime); strlcpy(fhdr.owner, "[Ptt法院]", sizeof(fhdr.owner)); append_record("boards/V/ViolateLaw/.DIR", &fhdr, sizeof(fhdr)); @@ -86,9 +89,10 @@ void post_newboard(char *bgroup, char *bname, char *bms) { char genbuf[256], title[128]; - sprintf(title, "[新板成立] %s", bname); - sprintf(genbuf, "%s 開了一個新板 %s : %s\n\n新任板主為 %s\n\n恭喜*^_^*\n", - cuser.userid, bname, bgroup, bms); + snprintf(title, sizeof(title), "[新板成立] %s", bname); + snprintf(genbuf, sizeof(genbuf), + "%s 開了一個新板 %s : %s\n\n新任板主為 %s\n\n恭喜*^_^*\n", + cuser.userid, bname, bgroup, bms); post_msg("Record", title, genbuf, "[系統]"); } @@ -113,8 +117,8 @@ give_money_post(char *userid, int money) cuser.userid, userid, money); fclose(fp); - sprintf(fhdr.title, "[公安報告] 站長%s使用紅包機報告", - cuser.userid); + snprintf(fhdr.title, sizeof(fhdr.title), "[公安報告] 站長%s使用紅包機報告", + cuser.userid); strlcpy(fhdr.owner, "[系統安全局]", sizeof(fhdr.owner)); append_record("boards/S/Security/.DIR", &fhdr, sizeof(fhdr)); } diff --git a/pttbbs/mbbsd/talk.c b/pttbbs/mbbsd/talk.c index c78eb24e..56b2b88b 100644 --- a/pttbbs/mbbsd/talk.c +++ b/pttbbs/mbbsd/talk.c @@ -1,4 +1,4 @@ -/* $Id: talk.c,v 1.80 2002/07/21 09:26:02 in2 Exp $ */ +/* $Id: talk.c,v 1.81 2002/07/22 19:02:00 in2 Exp $ */ #include "bbs.h" #define QCAST int (*)(const void *, const void *) @@ -98,25 +98,27 @@ modestring(userinfo_t * uentp, int simple) !((fri_stat & HFM) && (fri_stat & HRM)))) return notonline; else if (mode == EDITING) { - sprintf(modestr, "E:%s", + snprintf(modestr, sizeof(modestr), "E:%s", ModeTypeTable[uentp->destuid < EDITING ? uentp->destuid : EDITING]); word = modestr; } else if (!mode && *uentp->chatid == 1) { if (!simple) - sprintf(modestr, "回應 %s", getuserid(uentp->destuid)); + snprintf(modestr, sizeof(modestr), + "回應 %s", getuserid(uentp->destuid)); else - sprintf(modestr, "回應呼叫"); + snprintf(modestr, sizeof(modestr), "回應呼叫"); } else if (!mode && *uentp->chatid == 2) if (uentp->msgcount < 10) { char *cnum[10] = {"", "一", "兩", "三", "四", "五", "六", "七", "八", "九"}; - sprintf(modestr, "中%s顆水球", cnum[uentp->msgcount]); + snprintf(modestr, sizeof(modestr), + "中%s顆水球", cnum[uentp->msgcount]); } else - sprintf(modestr, "不行了 @_@"); + snprintf(modestr, sizeof(modestr), "不行了 @_@"); else if (!mode && *uentp->chatid == 3) - sprintf(modestr, "水球準備中"); + snprintf(modestr, sizeof(modestr), "水球準備中"); else if (!mode) return (uentp->destuid == 6) ? uentp->chatid : IdleTypeTable[(0 <= uentp->destuid && uentp->destuid < 6) ? @@ -124,27 +126,30 @@ modestring(userinfo_t * uentp, int simple) else if (simple) return word; else if (uentp->in_chat && mode == CHATING) - sprintf(modestr, "%s (%s)", word, uentp->chatid); + snprintf(modestr, sizeof(modestr), "%s (%s)", word, uentp->chatid); else if (mode == TALK) { if (!isvisible_uid(uentp->destuid)) /* Leeym 對方(紫色)隱形 */ - sprintf(modestr, "%s", "交談 空氣"); /* Leeym - * 大家自己發揮吧! */ + snprintf(modestr, sizeof(modestr), "%s", "交談 空氣"); + /* Leeym * 大家自己發揮吧! */ else - sprintf(modestr, "%s %s", word, getuserid(uentp->destuid)); + snprintf(modestr, sizeof(modestr), + "%s %s", word, getuserid(uentp->destuid)); } else if (mode == M_FIVE) { if (!isvisible_uid(uentp->destuid)) - sprintf(modestr, "%s", "五子棋 空氣"); + snprintf(modestr, sizeof(modestr), "%s", "五子棋 空氣"); else - sprintf(modestr, "%s %s", word, getuserid(uentp->destuid)); + snprintf(modestr, sizeof(modestr), "%s %s", word, getuserid(uentp->destuid)); } else if (mode == CHC) { if (isvisible_uid(uentp->destuid)) - sprintf(modestr, "%s", "下象棋"); + snprintf(modestr, sizeof(modestr), "%s", "下象棋"); else - sprintf(modestr, "下象棋 %s", getuserid(uentp->destuid)); + snprintf(modestr, sizeof(modestr), + "下象棋 %s", getuserid(uentp->destuid)); } else if (mode != PAGE && mode != TQUERY) return word; else - sprintf(modestr, "%s %s", word, getuserid(uentp->destuid)); + snprintf(modestr, sizeof(modestr), + "%s %s", word, getuserid(uentp->destuid)); return (modestr); } @@ -301,7 +306,8 @@ my_kick(userinfo_t * uentp) getdata(1, 0, msg_sure_ny, genbuf, 4, LCECHO); clrtoeol(); if (genbuf[0] == 'y') { - sprintf(genbuf, "%s (%s)", uentp->userid, uentp->username); + snprintf(genbuf, sizeof(genbuf), + "%s (%s)", uentp->userid, uentp->username); log_usies("KICK ", genbuf); if ((uentp->pid <= 0 || kill(uentp->pid, SIGHUP) == -1) && (errno == ESRCH)) purge_utmp(uentp); @@ -321,13 +327,14 @@ chicken_query(char *userid) time_diff(&(xuser.mychicken)); if (!isdeadth(&(xuser.mychicken))) { show_chicken_data(&(xuser.mychicken), NULL); - sprintf(buf, "\n\n以上是 %s 的寵物資料..", userid); + snprintf(buf, sizeof(buf), + "\n\n以上是 %s 的寵物資料..", userid); outs(buf); } } else { move(1, 0); clrtobot(); - sprintf(buf, "\n\n%s 並沒有養寵物..", userid); + snprintf(buf, sizeof(buf), "\n\n%s 並沒有養寵物..", userid); outs(buf); } pressanykey(); @@ -525,7 +532,7 @@ my_write2(void) move(0, 0); prints("\033[m"); clrtoeol(); - sprintf(genbuf, "攻擊 %s:", tw->userid); + snprintf(genbuf, sizeof(genbuf), "攻擊 %s:", tw->userid); if (!oldgetdata(0, 0, genbuf, msg, 80 - strlen(tw->userid) - 6, DOECHO)) break; @@ -604,7 +611,7 @@ my_write(pid_t pid, char *prompt, char *id, int flag, userinfo_t * puin) strip_ansi(msg, msg, 0); if (uin && *uin->userid && (flag == 0 || flag == 4)) { - sprintf(buf, "丟給 %s : %s [Y/n]?", uin->userid, msg); + snprintf(buf, sizeof(buf), "丟給 %s : %s [Y/n]?", uin->userid, msg); getdata(0, 0, buf, genbuf, 3, LCECHO); if (genbuf[0] == 'n') { outmsg("\033[1;33;42m算了! 放你一馬...\033[m"); @@ -976,7 +983,7 @@ do_talk(int fd) setutmpmode(TALK); ch = 58 - strlen(save_page_requestor); - sprintf(genbuf, "%s【%s", cuser.userid, cuser.username); + snprintf(genbuf, sizeof(genbuf), "%s【%s", cuser.userid, cuser.username); i = ch - strlen(genbuf); if (i >= 0) i = (i >> 1) + 1; @@ -987,8 +994,9 @@ do_talk(int fd) memset(data, ' ', i); data[i] = '\0'; - sprintf(mid_line, "\033[1;46;37m 談天說地 \033[45m%s%s】" - " 與 %s%s\033[0m", data, genbuf, save_page_requestor, data); + snprintf(mid_line, sizeof(mid_line), + "\033[1;46;37m 談天說地 \033[45m%s%s】" + " 與 %s%s\033[0m", data, genbuf, save_page_requestor, data); memset(&mywin, 0, sizeof(mywin)); memset(&itswin, 0, sizeof(itswin)); @@ -1076,8 +1084,9 @@ do_talk(int fd) stampfile(genbuf, &mymail); mymail.filemode = FILE_READ | FILE_HOLD; strlcpy(mymail.owner, "[備.忘.錄]", sizeof(mymail.owner)); - sprintf(mymail.title, "對話記錄 \033[1;36m(%s)\033[m", - getuserid(currutmp->destuid)); + snprintf(mymail.title, sizeof(mymail.title), + "對話記錄 \033[1;36m(%s)\033[m", + getuserid(currutmp->destuid)); sethomedir(title, cuser.userid); Rename(fpath, genbuf); append_record(title, &mymail, sizeof(mymail)); @@ -1269,8 +1278,8 @@ my_talk(userinfo_t * uin, int fri_stat) read(msgsock, &c, sizeof c); if (c == 'y') { - sprintf(save_page_requestor, "%s (%s)", - uin->userid, uin->username); + snprintf(save_page_requestor, sizeof(save_page_requestor), + "%s (%s)", uin->userid, uin->username); /* gomo */ switch (uin->sig) { case SIG_DARK: @@ -1399,7 +1408,7 @@ friend_descript(char *uident) setuserfile(fpath, friend_file[0]); if ((fp = fopen(fpath, "r"))) { - sprintf(name, "%s ", uident); + snprintf(name, sizeof(name), "%s ", uident); len = strlen(name); desc = genbuf + 13; @@ -1439,8 +1448,9 @@ descript(int show_mode, userinfo_t * uentp, time_t diff) #endif : "*"); case 2: - sprintf(description, "%3d/%3d/%3d", uentp->five_win, - uentp->five_lose, uentp->five_tie); + snprintf(description, sizeof(description), + "%3d/%3d/%3d", uentp->five_win, + uentp->five_lose, uentp->five_tie); description[20] = 0; return description; default: @@ -1671,11 +1681,11 @@ draw_pickup(int drawall, pickup_t * pickup, int pickup_way, if (idletime > 86400) strlcpy(idlestr, " -----", sizeof(idlestr)); else if (idletime >= 3600) - sprintf(idlestr, "%3dh%02d", - idletime / 3600, (idletime / 60) % 60); + snprintf(idlestr, sizeof(idlestr), "%3dh%02d", + idletime / 3600, (idletime / 60) % 60); else if (idletime > 0) - sprintf(idlestr, "%3d'%02d", - idletime / 60, idletime % 60); + snprintf(idlestr, sizeof(idlestr), "%3d'%02d", + idletime / 60, idletime % 60); else strlcpy(idlestr, " ", sizeof(idlestr)); #endif @@ -1743,7 +1753,7 @@ call_in(userinfo_t * uentp, int fri_stat) { if (iswritable_stat(uentp, fri_stat)) { char genbuf[60]; - sprintf(genbuf, "Call-In %s :", uentp->userid); + snprintf(genbuf, sizeof(genbuf), "Call-In %s :", uentp->userid); my_write(uentp->pid, genbuf, uentp->userid, 0, NULL); return 1; } @@ -1857,7 +1867,8 @@ userlist(void) case 'D': if (HAS_PERM(PERM_SYSOP)) { char buf[100]; - sprintf(buf, "代號 [%s]:", currutmp->userid); + snprintf(buf, sizeof(buf), + "代號 [%s]:", currutmp->userid); if (!getdata(1, 0, buf, currutmp->userid, sizeof(buf), DOECHO)) strlcpy(currutmp->userid, cuser.userid, sizeof(currutmp->userid)); @@ -1869,7 +1880,7 @@ userlist(void) if (HAS_PERM(PERM_SYSOP)) { char buf[100]; - sprintf(buf, "故鄉 [%s]:", currutmp->from); + snprintf(buf, sizeof(buf), "故鄉 [%s]:", currutmp->from); if (!getdata(1, 0, buf, currutmp->from, sizeof(currutmp->from), DOECHO)) strncpy(currutmp->from, fromhost, 23); @@ -2171,7 +2182,8 @@ userlist(void) if (HAS_PERM(PERM_LOGINOK) && strcmp(uentp->userid, cuser.userid) != 0) { move(b_lines - 2, 0); - sprintf(genbuf, "要給 %s 多少錢呢? ", uentp->userid); + snprintf(genbuf, sizeof(genbuf), + "要給 %s 多少錢呢? ", uentp->userid); outs(genbuf); if (getdata(b_lines - 1, 0, "[銀行轉帳]: ", genbuf, 7, LCECHO)) { @@ -2184,12 +2196,14 @@ userlist(void) outs("\033[41m 現金不足~~\033[m"); else { deumoney(uentp->uid, ch - give_tax(ch)); - sprintf(genbuf, "\033[44m 嗯..還剩下 %d 錢.." - "\033[m", demoney(-ch)); + snprintf(genbuf, sizeof(genbuf), + "\033[44m 嗯..還剩下 %d 錢.." + "\033[m", demoney(-ch)); outs(genbuf); - sprintf(genbuf, "%s\t給%s\t%d\t%s", cuser.userid, - uentp->userid, ch, - ctime(&currutmp->lastact)); + snprintf(genbuf, sizeof(genbuf), + "%s\t給%s\t%d\t%s", cuser.userid, + uentp->userid, ch, + ctime(&currutmp->lastact)); log_file(FN_MONEY, genbuf); mail_redenvelop(cuser.userid, uentp->userid, ch - give_tax(ch), 'Y'); @@ -2326,8 +2340,9 @@ t_idle(void) do { move(b_lines - 2, 0); clrtoeol(); - sprintf(buf, "(鎖定螢幕)發呆原因: %s", (currutmp->destuid != 6) ? - IdleTypeTable[currutmp->destuid] : currutmp->chatid); + snprintf(buf, sizeof(buf), + "(鎖定螢幕)發呆原因: %s", (currutmp->destuid != 6) ? + IdleTypeTable[currutmp->destuid] : currutmp->chatid); outs(buf); refresh(); getdata(b_lines - 1, 0, MSG_PASSWD, passbuf, sizeof(passbuf), NOECHO); @@ -2427,7 +2442,8 @@ talkreply(void) talkrequest = NA; uip = &SHM->uinfo[currutmp->destuip]; - sprintf(page_requestor, "%s (%s)", uip->userid, uip->username); + snprintf(page_requestor, sizeof(page_requestor), + "%s (%s)", uip->userid, uip->username); currutmp->destuid = uip->uid; currstat = XMODE; /* 避免出現動畫 */ @@ -2456,12 +2472,14 @@ talkreply(void) showplans(uip->userid); show_call_in(0, 0); - sprintf(genbuf, "你想跟 %s %s啊?請選擇(Y/N/A/B/C/D/E/F/1/2)[N] ", - page_requestor, sig_des[sig]); + snprintf(genbuf, sizeof(genbuf), + "你想跟 %s %s啊?請選擇(Y/N/A/B/C/D/E/F/1/2)[N] ", + page_requestor, sig_des[sig]); getdata(0, 0, genbuf, buf, sizeof(buf), LCECHO); if (uip->mode != PAGE) { - sprintf(genbuf, "%s已停止呼叫,按Enter繼續...", page_requestor); + snprintf(genbuf, sizeof(genbuf), + "%s已停止呼叫,按Enter繼續...", page_requestor); getdata(0, 0, genbuf, buf, sizeof(buf), LCECHO); return; } diff --git a/pttbbs/mbbsd/term.c b/pttbbs/mbbsd/term.c index ced6b1c4..9694add2 100644 --- a/pttbbs/mbbsd/term.c +++ b/pttbbs/mbbsd/term.c @@ -1,4 +1,4 @@ -/* $Id: term.c,v 1.5 2002/07/21 09:26:02 in2 Exp $ */ +/* $Id: term.c,v 1.6 2002/07/22 19:02:00 in2 Exp $ */ #include "bbs.h" int tgetent(const char *bp, char *name); @@ -91,7 +91,7 @@ do_move(int destcol, int destline) { char buf[16], *p; - sprintf(buf, "\33[%d;%dH", destline + 1, destcol + 1); + snprintf(buf, sizeof(buf), "\33[%d;%dH", destline + 1, destcol + 1); for (p = buf; *p; p++) ochar(*p); } @@ -115,7 +115,7 @@ change_scroll_range(int top, int bottom) { char buf[16], *p; - sprintf(buf, "\33[%d;%dr", top + 1, bottom + 1); + snprintf(buf, sizeof(buf), "\33[%d;%dr", top + 1, bottom + 1); for (p = buf; *p; p++) ochar(*p); } diff --git a/pttbbs/mbbsd/user.c b/pttbbs/mbbsd/user.c index b830fe5c..d6dd4b20 100644 --- a/pttbbs/mbbsd/user.c +++ b/pttbbs/mbbsd/user.c @@ -1,4 +1,4 @@ -/* $Id: user.c,v 1.32 2002/07/21 10:11:13 in2 Exp $ */ +/* $Id: user.c,v 1.33 2002/07/22 19:02:00 in2 Exp $ */ #include "bbs.h" static char *sex[8] = { @@ -122,7 +122,7 @@ mail_violatelaw(char *crime, char *police, char *reason, char *result) char genbuf[200]; fileheader_t fhdr; FILE *fp; - sprintf(genbuf, "home/%c/%s", crime[0], crime); + snprintf(genbuf, sizeof(genbuf), "home/%c/%s", crime[0], crime); stampfile(genbuf, &fhdr); if (!(fp = fopen(genbuf, "w"))) return; @@ -134,9 +134,9 @@ mail_violatelaw(char *crime, char *police, char *reason, char *result) "\n請到 PttLaw 查詢相關法規資訊,並到 Play-Pay-ViolateLaw 繳交罰單", ctime(&now), police, crime, reason, result); fclose(fp); - sprintf(fhdr.title, "[報告] 違法判決報告"); + snprintf(fhdr.title, sizeof(fhdr.title), "[報告] 違法判決報告"); strlcpy(fhdr.owner, "[Ptt法院]", sizeof(fhdr.owner)); - sprintf(genbuf, "home/%c/%s/.DIR", crime[0], crime); + snprintf(genbuf, sizeof(genbuf), "home/%c/%s/.DIR", crime[0], crime); append_record(genbuf, &fhdr, sizeof(fhdr)); } @@ -153,13 +153,13 @@ violate_law(userec_t * u, int unum) getdata(5, 0, "(0)結束", ans, sizeof(ans), DOECHO); switch (ans[0]) { case '1': - sprintf(reason, "%s", "Cross-post"); + snprintf(reason, sizeof(reason), "%s", "Cross-post"); break; case '2': - sprintf(reason, "%s", "亂發廣告信"); + snprintf(reason, sizeof(reason), "%s", "亂發廣告信"); break; case '3': - sprintf(reason, "%s", "亂發連鎖信"); + snprintf(reason, sizeof(reason), "%s", "亂發連鎖信"); break; case '4': while (!getdata(7, 0, "請輸入被檢舉理由以示負責:", reason, 50, DOECHO)); @@ -177,8 +177,8 @@ violate_law(userec_t * u, int unum) return; if (ans[0] == '9') { char src[STRLEN], dst[STRLEN]; - sprintf(src, "home/%c/%s", u->userid[0], u->userid); - sprintf(dst, "tmp/%s", u->userid); + snprintf(src, sizeof(src), "home/%c/%s", u->userid[0], u->userid); + snprintf(dst, sizeof(dst), "tmp/%s", u->userid); Rename(src, dst); log_usies("KILL", u->userid); post_violatelaw(u->userid, cuser.userid, reason, "砍除 ID"); @@ -247,7 +247,7 @@ uinfo_query(userec_t * u, int real, int unum) getdata_buf(i++, 0, "居住地址:", x.address, sizeof(x.address), DOECHO); } - sprintf(buf, "%010d", x.mobile); + snprintf(buf, sizeof(buf), "%010d", x.mobile); getdata_buf(i++, 0, "手機號碼:", buf, 11, LCECHO); x.mobile = atoi(buf); getdata_str(i++, 0, "電子信箱[變動要重新認證]:", buf, 50, DOECHO, @@ -256,7 +256,7 @@ uinfo_query(userec_t * u, int real, int unum) strlcpy(x.email, buf, sizeof(x.email)); mail_changed = 1 - real; } - sprintf(genbuf, "%i", (u->sex + 1) % 8); + snprintf(genbuf, sizeof(genbuf), "%i", (u->sex + 1) % 8); getdata_str(i++, 0, "性別 (1)葛格 (2)姐接 (3)底迪 (4)美眉 (5)薯叔 " "(6)阿姨 (7)植物 (8)礦物:", buf, 3, DOECHO, genbuf); @@ -268,8 +268,8 @@ uinfo_query(userec_t * u, int real, int unum) while (1) { int len; - sprintf(genbuf, "%02i/%02i/%02i", - u->month, u->day, u->year % 100); + snprintf(genbuf, sizeof(genbuf), "%02i/%02i/%02i", + u->month, u->day, u->year % 100); len = getdata_str(i, 0, "生日 月月/日日/西元:", buf, 9, DOECHO, genbuf); if (len && len != 8) @@ -293,7 +293,7 @@ uinfo_query(userec_t * u, int real, int unum) if (real) { unsigned long int l; if (HAS_PERM(PERM_BBSADM)) { - sprintf(genbuf, "%d", x.money); + snprintf(genbuf, sizeof(genbuf), "%d", x.money); if (getdata_str(i++, 0, "銀行帳戶:", buf, 10, DOECHO, genbuf)) if ((l = atol(buf)) != 0) { if (l != x.money) { @@ -303,7 +303,7 @@ uinfo_query(userec_t * u, int real, int unum) } } } - sprintf(genbuf, "%d", x.exmailbox); + snprintf(genbuf, sizeof(genbuf), "%d", x.exmailbox); if (getdata_str(i++, 0, "購買信箱數:", buf, 4, DOECHO, genbuf)) if ((l = atol(buf)) != 0) x.exmailbox = (int)l; @@ -313,22 +313,22 @@ uinfo_query(userec_t * u, int real, int unum) getdata_buf(i++, 0, "最近光臨機器:", x.lasthost, sizeof(x.lasthost), DOECHO); - sprintf(genbuf, "%d", x.numlogins); + snprintf(genbuf, sizeof(genbuf), "%d", x.numlogins); if (getdata_str(i++, 0, "上線次數:", buf, 10, DOECHO, genbuf)) if ((fail = atoi(buf)) >= 0) x.numlogins = fail; - sprintf(genbuf, "%d", u->numposts); + snprintf(genbuf, sizeof(genbuf), "%d", u->numposts); if (getdata_str(i++, 0, "文章數目:", buf, 10, DOECHO, genbuf)) if ((fail = atoi(buf)) >= 0) x.numposts = fail; - sprintf(genbuf, "%d", u->vl_count); + snprintf(genbuf, sizeof(genbuf), "%d", u->vl_count); if (getdata_str(i++, 0, "違法記錄:", buf, 10, DOECHO, genbuf)) if ((fail = atoi(buf)) >= 0) x.vl_count = fail; - sprintf(genbuf, "%d/%d/%d", u->five_win, u->five_lose, - u->five_tie); + snprintf(genbuf, sizeof(genbuf), + "%d/%d/%d", u->five_win, u->five_lose, u->five_tie); if (getdata_str(i++, 0, "五子棋戰績 勝/敗/和:", buf, 16, DOECHO, genbuf)) while (1) { @@ -346,7 +346,8 @@ uinfo_query(userec_t * u, int real, int unum) x.five_tie = atoi(p); break; } - sprintf(genbuf, "%d/%d/%d", u->chc_win, u->chc_lose, u->chc_tie); + snprintf(genbuf, sizeof(genbuf), + "%d/%d/%d", u->chc_win, u->chc_lose, u->chc_tie); if (getdata_str(i++, 0, "象棋戰績 勝/敗/和:", buf, 16, DOECHO, genbuf)) while (1) { @@ -484,10 +485,11 @@ uinfo_query(userec_t * u, int real, int unum) if (i == QUIT) { char src[STRLEN], dst[STRLEN]; - sprintf(src, "home/%c/%s", x.userid[0], x.userid); - sprintf(dst, "tmp/%s", x.userid); + snprintf(src, sizeof(src), "home/%c/%s", x.userid[0], x.userid); + snprintf(dst, sizeof(dst), "tmp/%s", x.userid); if (Rename(src, dst)) { - sprintf(genbuf, "/bin/rm -fr %s >/dev/null 2>&1", src); + snprintf(genbuf, sizeof(genbuf), + "/bin/rm -fr %s >/dev/null 2>&1", src); /* * do not remove system(genbuf); */ @@ -521,8 +523,9 @@ uinfo_query(userec_t * u, int real, int unum) fprintf(fp, "\n \033[1;37m站長%s修改錢理由是:%s\033[m", cuser.userid, reason); fclose(fp); - sprintf(fhdr.title, "[公安報告] 站長%s修改%s錢報告", cuser.userid, - x.userid); + snprintf(fhdr.title, sizeof(fhdr.title), + "[公安報告] 站長%s修改%s錢報告", cuser.userid, + x.userid); strlcpy(fhdr.owner, "[系統安全局]", sizeof(fhdr.owner)); append_record("boards/S/Security/.DIR", &fhdr, sizeof(fhdr)); } @@ -723,10 +726,10 @@ getfield(int line, char *info, char *desc, char *buf, int len) char prompt[STRLEN]; char genbuf[200]; - sprintf(genbuf, "原先設定:%-30.30s (%s)", buf, info); + snprintf(genbuf, sizeof(genbuf), "原先設定:%-30.30s (%s)", buf, info); move(line, 2); outs(genbuf); - sprintf(prompt, "%s:", desc); + snprintf(prompt, sizeof(prompt), "%s:", desc); if (getdata_str(line + 1, 2, prompt, genbuf, len, DOECHO, buf)) strcpy(buf, genbuf); move(line, 2); @@ -899,14 +902,17 @@ toregister(char *email, char *genbuf, char *phone, char *career, if (phone != NULL) { #ifdef HAVEMOBILE if (strcmp(email, "m") == 0 || strcmp(email, "M") == 0) - sprintf(genbuf, "%s:%s:<Mobile>", phone, career); + sprintf(genbuf, sizeof(genbuf), + "%s:%s:<Mobile>", phone, career); else #endif - sprintf(genbuf, "%s:%s:<Email>", phone, career); + snprintf(genbuf, sizeof(genbuf), + "%s:%s:<Email>", phone, career); strncpy(cuser.justify, genbuf, REGLEN); sethomefile(buf, cuser.userid, "justify"); } - sprintf(buf, "您在 " BBSNAME " 的認證碼: %s", getregcode(genbuf)); + snprintf(buf, sizeof(buf), + "您在 " BBSNAME " 的認證碼: %s", getregcode(genbuf)); strlcpy(tmp, cuser.userid, sizeof(tmp)); strlcpy(cuser.userid, "SYSOP", sizeof(cuser.userid)); #ifdef HAVEMOBILE @@ -956,12 +962,12 @@ u_register(void) strlcpy(rname, cuser.realname, sizeof(rname)); strlcpy(addr, cuser.address, sizeof(addr)); strlcpy(email, cuser.email, sizeof(email)); - sprintf(mobile, "0%09d", cuser.mobile); + snprintf(mobile, sizeof(mobile), "0%09d", cuser.mobile); if (cuser.month == 0 && cuser.day && cuser.year == 0) birthday[0] = 0; else - sprintf(birthday, "%02i/%02i/%02i", - cuser.month, cuser.day, cuser.year % 100); + snprintf(birthday, sizeof(birthday), "%02i/%02i/%02i", + cuser.month, cuser.day, cuser.year % 100); sex_is[0] = (cuser.sex % 8) + '1'; sex_is[1] = 0; career[0] = phone[0] = '\0'; @@ -1091,8 +1097,8 @@ u_register(void) getfield(15, "月月/日日/西元 如:09/27/76", "生日", birthday, 9); len = strlen(birthday); if (!len) { - sprintf(birthday, "%02i/%02i/%02i", - cuser.month, cuser.day, cuser.year % 100); + snprintf(birthday, sizeof(birthday), "%02i/%02i/%02i", + cuser.month, cuser.day, cuser.year % 100); mon = cuser.month; day = cuser.day; year = cuser.year; diff --git a/pttbbs/mbbsd/vice.c b/pttbbs/mbbsd/vice.c index 35a5641f..acc653fa 100644 --- a/pttbbs/mbbsd/vice.c +++ b/pttbbs/mbbsd/vice.c @@ -1,4 +1,4 @@ -/* $Id: vice.c,v 1.5 2002/07/21 09:26:02 in2 Exp $ */ +/* $Id: vice.c,v 1.6 2002/07/22 19:02:01 in2 Exp $ */ #include "bbs.h" #define VICE_PLAY BBSHOME "/etc/vice/vice.play" @@ -54,7 +54,7 @@ ran_showfile(int y, int x, char *filename, int maxnum) char buf[512]; bzero(buf, sizeof(char) * 512); - sprintf(buf, "%s%d", filename, rand() % maxnum + 1); + snprintf(buf, sizeof(buf), "%s%d", filename, rand() % maxnum + 1); if (!(fs = fopen(buf, "r"))) { move(10, 10); prints("can't open file: %s", buf); @@ -74,7 +74,7 @@ ran_showmfile(char *filename, int maxnum) { char buf[256]; - sprintf(buf, "%s%d", filename, rand() % maxnum + 1); + snprintf(buf, sizeof(buf), "%s%d", filename, rand() % maxnum + 1); return more(buf, YEA); } diff --git a/pttbbs/mbbsd/vote.c b/pttbbs/mbbsd/vote.c index fb1c40e9..48afafd1 100644 --- a/pttbbs/mbbsd/vote.c +++ b/pttbbs/mbbsd/vote.c @@ -1,4 +1,4 @@ -/* $Id: vote.c,v 1.14 2002/07/21 20:43:35 kcwu Exp $ */ +/* $Id: vote.c,v 1.15 2002/07/22 19:02:01 in2 Exp $ */ #include "bbs.h" static int total; @@ -136,11 +136,12 @@ vote_report(char *bname, char *fname, char *fpath) memset(&header, 0, sizeof(fileheader_t)); strlcpy(header.owner, "[馬路探子]", sizeof(header.owner)); - sprintf(header.title, "[%s] 看板 選情報導", bname); + snprintf(header.title, sizeof(header.title), "[%s] 看板 選情報導", bname); { register struct tm *ptime = localtime(&dtime); - sprintf(header.date, "%2d/%02d", ptime->tm_mon + 1, ptime->tm_mday); + snprintf(header.date, sizeof(header.date), + "%2d/%02d", ptime->tm_mon + 1, ptime->tm_mday); } strlcpy(header.filename, ip, sizeof(header.filename)); @@ -261,10 +262,10 @@ b_result_one(boardheader_t * fh, int ind) b_suckinfile(frp, b_newresults); fclose(frp); } - sprintf(inbuf, "boards/%c/%s", bname[0], bname); + snprintf(inbuf, sizeof(inbuf), "boards/%c/%s", bname[0], bname); vote_report(bname, b_report, inbuf); if (!(fh->brdattr & BRD_NOCOUNT)) { - sprintf(inbuf, "boards/%c/%s", 'R', "Record"); + snprintf(inbuf, sizeof(inbuf), "boards/%c/%s", 'R', "Record"); vote_report(bname, b_report, inbuf); } unlink(b_report); @@ -493,8 +494,10 @@ vote_view_all(char *bname) fclose(xfp); } for (i = 1; i < 20; i++) { - sprintf(STR_new_control, "%s%d", STR_bv_control, i); - sprintf(STR_new_title, "%s%d", STR_bv_title, i); + snprintf(STR_new_control, sizeof(STR_new_control), + "%s%d", STR_bv_control, i); + snprintf(STR_new_title, sizeof(STR_new_title), + "%s%d", STR_bv_title, i); setbfile(buf, bname, STR_new_control); if ((fp = fopen(buf, "r"))) { prints("(%d) ", i); @@ -513,15 +516,16 @@ vote_view_all(char *bname) if (x < 0) return FULLUPDATE; - sprintf(buf, "要看幾號投票 [%d] ", x); + snprintf(buf, sizeof(buf), "要看幾號投票 [%d] ", x); getdata(b_lines - 1, 0, buf, genbuf, 4, LCECHO); if (atoi(genbuf) < 0 || atoi(genbuf) > 20) - sprintf(genbuf, "%d", x); + snprintf(genbuf, sizeof(genbuf), "%d", x); if (genbuf[0] != '0') - sprintf(STR_new_control, "%s%d", STR_bv_control, atoi(genbuf)); + snprintf(STR_new_control, sizeof(STR_new_control), + "%s%d", STR_bv_control, atoi(genbuf)); else strlcpy(STR_new_control, STR_bv_control, sizeof(STR_new_control)); @@ -576,13 +580,20 @@ vote_maintain(char *bname) unlink(buf); for (i = 1; i < 20; i++) { - sprintf(STR_new_ballots, "%s%d", STR_bv_ballots, i); - sprintf(STR_new_control, "%s%d", STR_bv_control, i); - sprintf(STR_new_desc, "%s%d", STR_bv_desc, i); - sprintf(STR_new_flags, "%s%d", STR_bv_flags, i); - sprintf(STR_new_comments, "%s%d", STR_bv_comments, i); - sprintf(STR_new_limited, "%s%d", STR_bv_limited, i); - sprintf(STR_new_title, "%s%d", STR_bv_title, i); + snprintf(STR_new_ballots, sizeof(STR_new_ballots), + "%s%d", STR_bv_ballots, i); + snprintf(STR_new_control, sizeof(STR_new_control), + "%s%d", STR_bv_control, i); + snprintf(STR_new_desc, sizeof(STR_new_desc), + "%s%d", STR_bv_desc, i); + snprintf(STR_new_flags, sizeof(STR_new_flags), + "%s%d", STR_bv_flags, i); + snprintf(STR_new_comments, sizeof(STR_new_comments), + "%s%d", STR_bv_comments, i); + snprintf(STR_new_limited, sizeof(STR_new_limited), + "%s%d", STR_bv_limited, i); + snprintf(STR_new_title, sizeof(STR_new_title), + "%s%d", STR_bv_title, i); setbfile(buf, bname, STR_new_control); unlink(buf); @@ -610,7 +621,8 @@ vote_maintain(char *bname) while (x < 20 && (fp = fopen(buf, "r")) != NULL) { fclose(fp); x++; - sprintf(STR_new_control, "%s%d", STR_bv_control, x); + snprintf(STR_new_control, sizeof(STR_new_control), + "%s%d", STR_bv_control, x); setbfile(buf, bname, STR_new_control); } if (fp) @@ -689,7 +701,7 @@ vote_maintain(char *bname) outs("\n請依序輸入選項, 按 ENTER 完成設定"); num = 0; while (!aborted) { - sprintf(buf, "%c) ", num + 'A'); + snprintf(buf, sizeof(buf), "%c) ", num + 'A'); getdata((num % 15) + 2, (num / 15) * 40, buf, inbuf, 50, DOECHO); if (*inbuf) { @@ -699,7 +711,7 @@ vote_maintain(char *bname) if ((*inbuf == '\0' && num >= 1) || num == 30) aborted = 1; } - sprintf(buf, "請問每人最多可投幾票?([1]∼%d): ", num); + snprintf(buf, sizeof(buf), "請問每人最多可投幾票?([1]∼%d): ", num); getdata(t_lines - 3, 0, buf, inbuf, 3, DOECHO); @@ -990,8 +1002,10 @@ user_vote(char *bname) fclose(xfp); } for (i = 1; i < 20; i++) { - sprintf(STR_new_control, "%s%d", STR_bv_control, i); - sprintf(STR_new_title, "%s%d", STR_bv_title, i); + snprintf(STR_new_control, sizeof(STR_new_control), + "%s%d", STR_bv_control, i); + snprintf(STR_new_title, sizeof(STR_new_title), + "%s%d", STR_bv_title, i); setbfile(buf, bname, STR_new_control); if ((fp = fopen(buf, "r"))) { prints("(%d) ", i); @@ -1011,15 +1025,16 @@ user_vote(char *bname) if (x < 0) return FULLUPDATE; - sprintf(buf, "要投幾號投票 [%d] ", x); + snprintf(buf, sizeof(buf), "要投幾號投票 [%d] ", x); getdata(b_lines - 1, 0, buf, genbuf, 4, LCECHO); if (atoi(genbuf) < 0 || atoi(genbuf) > 20) - sprintf(genbuf, "%d", x); + snprintf(genbuf, sizeof(genbuf), "%d", x); if (genbuf[0] != '0') - sprintf(STR_new_control, "%s%d", STR_bv_control, atoi(genbuf)); + snprintf(STR_new_control, sizeof(STR_new_control), + "%s%d", STR_bv_control, atoi(genbuf)); else strlcpy(STR_new_control, STR_bv_control, sizeof(STR_new_control)); diff --git a/pttbbs/mbbsd/voteboard.c b/pttbbs/mbbsd/voteboard.c index 6a7d7b87..27ca0bd3 100644 --- a/pttbbs/mbbsd/voteboard.c +++ b/pttbbs/mbbsd/voteboard.c @@ -1,4 +1,4 @@ -/* $Id: voteboard.c,v 1.12 2002/07/21 09:26:02 in2 Exp $ */ +/* $Id: voteboard.c,v 1.13 2002/07/22 19:02:01 in2 Exp $ */ #include "bbs.h" #define VOTEBOARD "NewBoard" @@ -225,8 +225,9 @@ do_voteboard() else break; } while (temp > 0); - sprintf(title, "[申請新板] %s", topic); - sprintf(genbuf, "%s\n\n%s%s\n%s", "申請新板", "英文名稱: ", topic, "中文名稱: "); + snprintf(title, sizeof(title), "[申請新板] %s", topic); + snprintf(genbuf, sizeof(genbuf), + "%s\n\n%s%s\n%s", "申請新板", "英文名稱: ", topic, "中文名稱: "); if (!getdata(5, 0, "請輸入看板中文名稱:", topic, 20, DOECHO)) return FULLUPDATE; @@ -258,8 +259,9 @@ do_voteboard() else break; } while (temp > 0); - sprintf(title, "[廢除舊板] %s", topic); - sprintf(genbuf, "%s\n\n%s%s\n", "廢除舊板", "英文名稱: ", topic); + snprintf(title, sizeof(title), "[廢除舊板] %s", topic); + snprintf(genbuf, sizeof(genbuf), + "%s\n\n%s%s\n", "廢除舊板", "英文名稱: ", topic); strcat(genbuf, "\n廢除原因: \n"); outs("請輸入廢除原因(至多五行),要清楚填寫不然不會核准喔"); for (i = 8; i < 13; i++) { @@ -281,8 +283,8 @@ do_voteboard() else break; } while (temp > 0); - sprintf(title, "[連署板主] %s", topic); - sprintf(genbuf, "%s\n\n%s%s\n%s%s", "連署板主", "英文名稱: ", topic, "申請 ID : ", cuser.userid); + snprintf(title, sizeof(title), "[連署板主] %s", topic); + snprintf(genbuf, sizeof(genbuf), "%s\n\n%s%s\n%s%s", "連署板主", "英文名稱: ", topic, "申請 ID : ", cuser.userid); strcat(genbuf, "\n申請政見: \n"); outs("請輸入申請政見(至多五行),要清楚填寫不然不會核准喔"); for (i = 8; i < 13; i++) { @@ -303,8 +305,10 @@ do_voteboard() else break; } while (temp > 0); - sprintf(title, "[罷免板主] %s", topic); - sprintf(genbuf, "%s\n\n%s%s\n%s", "罷免板主", "英文名稱: ", topic, "板主 ID : "); + snprintf(title, sizeof(title), "[罷免板主] %s", topic); + snprintf(genbuf, sizeof(genbuf), + "%s\n\n%s%s\n%s", "罷免板主", "英文名稱: ", + topic, "板主 ID : "); do { if (!getdata(6, 0, "請輸入板主ID:", topic, IDLEN + 1, DOECHO)) return FULLUPDATE; @@ -328,8 +332,10 @@ do_voteboard() case 5: if (!getdata(4, 0, "請輸入小組中英文名稱:", topic, 30, DOECHO)) return FULLUPDATE; - sprintf(title, "[連署小組長] %s", topic); - sprintf(genbuf, "%s\n\n%s%s\n%s%s", "連署小組長", "小組名稱: ", topic, "申請 ID : ", cuser.userid); + snprintf(title, sizeof(title), "[連署小組長] %s", topic); + snprintf(genbuf, sizeof(genbuf), + "%s\n\n%s%s\n%s%s", "連署小組長", "小組名稱: ", + topic, "申請 ID : ", cuser.userid); strcat(genbuf, "\n申請政見: \n"); outs("請輸入申請政見(至多五行),要清楚填寫不然不會核准喔"); for (i = 8; i < 13; i++) { @@ -345,8 +351,9 @@ do_voteboard() if (!getdata(4, 0, "請輸入小組中英文名稱:", topic, 30, DOECHO)) return FULLUPDATE; - sprintf(title, "[罷免小組長] %s", topic); - sprintf(genbuf, "%s\n\n%s%s\n%s", "罷免小組長", "小組名稱: ", topic, "小組長 ID : "); + snprintf(title, sizeof(title), "[罷免小組長] %s", topic); + snprintf(genbuf, sizeof(genbuf), "%s\n\n%s%s\n%s", + "罷免小組長", "小組名稱: ", topic, "小組長 ID : "); if (!getdata(6, 0, "請輸入小組長ID:", topic, IDLEN + 1, DOECHO)) return FULLUPDATE; strcat(genbuf, topic); @@ -366,8 +373,9 @@ do_voteboard() return FULLUPDATE; if (!getdata(4, 0, "請輸入公投主題:", topic, 30, DOECHO)) return FULLUPDATE; - sprintf(title, "%s %s", "[站民公投]", topic); - sprintf(genbuf, "%s\n\n%s%s\n", "站民公投", "公投主題: ", topic); + snprintf(title, sizeof(title), "%s %s", "[站民公投]", topic); + snprintf(genbuf, sizeof(genbuf), + "%s\n\n%s%s\n", "站民公投", "公投主題: ", topic); strcat(genbuf, "\n公投原因: \n"); outs("請輸入公投原因(至多五行),要清楚填寫不然不會核准喔"); for (i = 8; i < 13; i++) { @@ -382,8 +390,9 @@ do_voteboard() case 8: if (!getdata(4, 0, "請輸入群組中英文名稱:", topic, 30, DOECHO)) return FULLUPDATE; - sprintf(title, "[申請新群組] %s", topic); - sprintf(genbuf, "%s\n\n%s%s\n%s%s", "申請群組", "群組名稱: ", topic, "申請 ID : ", cuser.userid); + snprintf(title, sizeof(title), "[申請新群組] %s", topic); + snprintf(genbuf, sizeof(genbuf), "%s\n\n%s%s\n%s%s", + "申請群組", "群組名稱: ", topic, "申請 ID : ", cuser.userid); strcat(genbuf, "\n申請政見: \n"); outs("請輸入申請政見(至多五行),要清楚填寫不然不會核准喔"); for (i = 8; i < 13; i++) { @@ -400,7 +409,7 @@ do_voteboard() } strcat(genbuf, "連署結束時間: "); now += 14 * 24 * 60 * 60; - sprintf(topic, "(%ld)", now); + snprintf(topic, sizeof(topic), "(%ld)", now); strcat(genbuf, topic); strcat(genbuf, ctime(&now)); now -= 14 * 24 * 60 * 60; diff --git a/pttbbs/mbbsd/xyz.c b/pttbbs/mbbsd/xyz.c index e277421d..dba8ad13 100644 --- a/pttbbs/mbbsd/xyz.c +++ b/pttbbs/mbbsd/xyz.c @@ -1,4 +1,4 @@ -/* $Id: xyz.c,v 1.11 2002/07/21 09:26:02 in2 Exp $ */ +/* $Id: xyz.c,v 1.12 2002/07/22 19:02:01 in2 Exp $ */ #include "bbs.h" /* 各種統計及相關資訊列表 */ @@ -230,13 +230,13 @@ note() collect = 1; while (total) { - sprintf(buf, "\033[1;31m╭┤\033[32m %s \033[37m(%s)", + snprintf(buf, sizeof(buf), "\033[1;31m╭┤\033[32m %s \033[37m(%s)", myitem.userid, myitem.username); len = strlen(buf); for (i = len; i < 73; i++) strcat(buf, " "); - sprintf(buf2, " \033[1;36m%.14s\033[31m ├╮\033[m\n", + snprintf(buf2, sizeof(buf2), " \033[1;36m%.14s\033[31m ├╮\033[m\n", Cdate(&(myitem.date))); strcat(buf, buf2); fputs(buf, fp); @@ -444,7 +444,7 @@ x_archie() exec_cmd(ARCHIE, YEA, "bin/archie.sh", ARCHIE); log_usies("ARCHIE", ""); strcpy(genbuf1, buf); - sprintf(buf, BBSHOME "/tmp/archie.%s", cuser.userid); + snprintf(buf, sizeof(buf), BBSHOME "/tmp/archie.%s", cuser.userid); if (dashf(buf)) { getdata(0, 0, "要將結果寄回信箱嗎(Y/N)?[N]", ans, sizeof(ans), DOECHO, 0); @@ -456,7 +456,8 @@ x_archie() sethomepath(buf1, cuser.userid); stampfile(buf1, &mhdr); strcpy(mhdr.owner, cuser.userid); - sprintf(genbuf2, "Archie 搜尋檔案: %s 結果", genbuf1); + sprintf(genbuf2, sizeof(genbuf2), + "Archie 搜尋檔案: %s 結果", genbuf1); strcpy(mhdr.title, genbuf2); mhdr.filemode = 0; sethomedir(title, cuser.userid); -- cgit v1.2.3 From 4119353ffeba74abfe879a24e5b5d1d8b55481ea Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Mon, 22 Jul 2002 19:02:55 +0000 Subject: remove SIZEOF git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@436 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/include/bbs.h | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/pttbbs/include/bbs.h b/pttbbs/include/bbs.h index 023ac1a2..1b2a0d38 100644 --- a/pttbbs/include/bbs.h +++ b/pttbbs/include/bbs.h @@ -49,16 +49,4 @@ #else #include <limits.h> #endif -#ifdef DEBUG -static int Sizeof(char *what,int size,char *file,int line) -{ - if(size==4) - printf("WARRNING\r\n"); - printf("%s(%d): sizeof(%s)=%d\r\n",file,line,what,size); - return size; -} -#define SIZEOF(a) Sizeof(#a,sizeof(a),__FILE__,__LINE__) -#else -#define SIZEOF(a) sizeof(a) -#endif #endif /* INCLUDE_BBS_H */ -- cgit v1.2.3 From 0e78400996939f21d85ce0c0d0973d2939609edf Mon Sep 17 00:00:00 2001 From: kcwu <kcwu@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Tue, 23 Jul 2002 13:30:11 +0000 Subject: fix lynx big5 encoding problem MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit reported by lihgong(嚙篆嚙稽) on ptt2/PttSrc git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@437 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/weather.perl | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pttbbs/util/weather.perl b/pttbbs/util/weather.perl index 276ba8a5..88d380c1 100644 --- a/pttbbs/util/weather.perl +++ b/pttbbs/util/weather.perl @@ -1,5 +1,5 @@ #!/usr/bin/perl -# $Id: weather.perl,v 1.2 2002/07/04 09:33:10 in2 Exp $ +# $Id: weather.perl,v 1.3 2002/07/23 13:30:11 kcwu Exp $ # # 不能跑的話,看看 bbspost 的路徑是否正確。 # 如果發出的 post 沒有氣象報告而是說 URL 找不到,則確定一下能不能看到 @@ -15,7 +15,8 @@ close DATE; # Header # 內容 -open(WEATHER, "/usr/bin/lynx -dump http://www.cwb.gov.tw/V3.0/weather/text/W03.htm |"); +open(WEATHER, "/usr/bin/lynx -assume_charset=big5 -assume_local_charset=big5 -dump http://www.cwb.gov.tw/V3.0/weather/text/W03.htm |"); + while (<WEATHER>) { print BBSPOST if ($_ ne "\n"); } -- cgit v1.2.3 From 0b34065271f8f08ae68347fd00c7072d0f1b909d Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Thu, 25 Jul 2002 11:06:15 +0000 Subject: register git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@438 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/user.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/pttbbs/mbbsd/user.c b/pttbbs/mbbsd/user.c index d6dd4b20..9f985ab9 100644 --- a/pttbbs/mbbsd/user.c +++ b/pttbbs/mbbsd/user.c @@ -1,4 +1,4 @@ -/* $Id: user.c,v 1.33 2002/07/22 19:02:00 in2 Exp $ */ +/* $Id: user.c,v 1.34 2002/07/25 11:06:15 in2 Exp $ */ #include "bbs.h" static char *sex[8] = { @@ -1043,7 +1043,8 @@ u_register(void) while (1) { getfield(5, "請用中文", "真實姓名", rname, 20); if (removespace(rname) && rname[0] < 0 && - !strstr(rname, "阿") && !strstr(rname, "小")) + !strstr(rname, "阿") && !strstr(rname, "小") && + !strstr(rname, "ㄚ")) break; vmsg("您的輸入不正確"); } @@ -1074,7 +1075,10 @@ u_register(void) vmsg("抱歉我們不接受郵政信箱"); continue; } - if (strstr(addr, "市") == NULL && strstr(addr, "縣") == NULL) { + if ((strstr(addr, "市") == NULL && strstr(addr, "縣") == NULL) || + strcmp(&addr[strlen(addr) - 2], "路") == 0 || + strcmp(&addr[strlen(addr) - 2], "巷") == 0 || + strcmp(&addr[strlen(addr) - 2], "街") == 0 ) { vmsg("這個地址並不合法"); continue; } -- cgit v1.2.3 From 327b2c3244960ca7f3050185d37641a24227d150 Mon Sep 17 00:00:00 2001 From: kcwu <kcwu@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Thu, 25 Jul 2002 12:31:15 +0000 Subject: indicate which user crash mbbsd git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@439 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/mbbsd.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pttbbs/mbbsd/mbbsd.c b/pttbbs/mbbsd/mbbsd.c index 9a3eeb8a..ec0370c6 100644 --- a/pttbbs/mbbsd/mbbsd.c +++ b/pttbbs/mbbsd/mbbsd.c @@ -1,4 +1,4 @@ -/* $Id: mbbsd.c,v 1.44 2002/07/22 19:02:00 in2 Exp $ */ +/* $Id: mbbsd.c,v 1.45 2002/07/25 12:31:15 kcwu Exp $ */ #include "bbs.h" #define SOCKET_QLEN 4 @@ -222,7 +222,7 @@ abort_bbs_debug(int sig) reentrant = 1; if (currmode) u_exit("AXXED"); - setproctitle("debug me!(%d)", sig); + setproctitle("debug me!(%d)(%s)", sig, cuser.userid); sleep(3600); /* wait 60 mins for debug */ } exit(0); -- cgit v1.2.3 From a6e5987d7cfc811e0d260052cad813a48dc1b8dd Mon Sep 17 00:00:00 2001 From: kcwu <kcwu@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sat, 27 Jul 2002 10:04:34 +0000 Subject: add XXX comment git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@440 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/announce.c | 3 ++- pttbbs/mbbsd/topsong.c | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/pttbbs/mbbsd/announce.c b/pttbbs/mbbsd/announce.c index 8413897b..723a55fb 100644 --- a/pttbbs/mbbsd/announce.c +++ b/pttbbs/mbbsd/announce.c @@ -1,4 +1,4 @@ -/* $Id: announce.c,v 1.16 2002/07/22 19:02:00 in2 Exp $ */ +/* $Id: announce.c,v 1.17 2002/07/27 10:04:34 kcwu Exp $ */ #include "bbs.h" static void @@ -1471,6 +1471,7 @@ a_menu(char *maintitle, char *path, int lastlevel) fname, sizeof(trans_buffer)); Fexit = 1; if (currstat == OSONG) { + /* XXX: 只選歌未點歌可灌排行榜 */ log_file(FN_USSONG, fhdr->title); } free(me.header); diff --git a/pttbbs/mbbsd/topsong.c b/pttbbs/mbbsd/topsong.c index a745b4a5..015f7de5 100644 --- a/pttbbs/mbbsd/topsong.c +++ b/pttbbs/mbbsd/topsong.c @@ -1,4 +1,4 @@ -/* $Id: topsong.c,v 1.5 2002/07/21 09:26:02 in2 Exp $ */ +/* $Id: topsong.c,v 1.6 2002/07/27 10:04:34 kcwu Exp $ */ #include "bbs.h" #define MAX_SONGS 300 @@ -51,6 +51,7 @@ sortsong() return; } totalcount = 0; + /* XXX: 除了前 MAX_SONGS 首, 剩下不會排序 */ while (fgets(buf, 200, fp)) { strtok(buf, "\n\r"); strip_blank(cbuf, buf); -- cgit v1.2.3 From f488d8d2b8f660d9be6e417888d145c85e1e19f1 Mon Sep 17 00:00:00 2001 From: kcwu <kcwu@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sat, 27 Jul 2002 10:04:59 +0000 Subject: typo git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@441 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/indict.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pttbbs/mbbsd/indict.c b/pttbbs/mbbsd/indict.c index 7eed0828..fe7da8c4 100644 --- a/pttbbs/mbbsd/indict.c +++ b/pttbbs/mbbsd/indict.c @@ -1,4 +1,4 @@ -/* $Id: indict.c,v 1.8 2002/07/22 19:02:00 in2 Exp $ */ +/* $Id: indict.c,v 1.9 2002/07/27 10:04:59 kcwu Exp $ */ #include "bbs.h" #define REFER "etc/dicts" @@ -19,7 +19,7 @@ addword(char word[]) clear(); move(4, 0); outs(" \033[31m警告\033[m:若蓄意填寫假資料將\033[36m砍id\033[m處份\n"); - snprintf(temp, sizeof(temp), "\n輸入範利\n:\033[33m%s\033[m", buf); + snprintf(temp, sizeof(temp), "\n輸入範例\n:\033[33m%s\033[m", buf); outs(temp); outs("\n請依上列範例輸入一行資料(直接enter放棄)\n"); getdata(10, 0, ":", buf, 65, DOECHO); -- cgit v1.2.3 From 63a396ef147f1fdc4912a51ef6eacfe118827673 Mon Sep 17 00:00:00 2001 From: kcwu <kcwu@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sat, 27 Jul 2002 10:05:56 +0000 Subject: replace memcpy with memmove git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@442 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/menu.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pttbbs/mbbsd/menu.c b/pttbbs/mbbsd/menu.c index 08efc53d..f4d28259 100644 --- a/pttbbs/mbbsd/menu.c +++ b/pttbbs/mbbsd/menu.c @@ -1,4 +1,4 @@ -/* $Id: menu.c,v 1.16 2002/07/22 19:02:00 in2 Exp $ */ +/* $Id: menu.c,v 1.17 2002/07/27 10:05:56 kcwu Exp $ */ #include "bbs.h" /* help & menu processring */ @@ -130,7 +130,7 @@ movie(int i) } while (i == 0); } - memcpy(history, &history[1], SHM->max_history * sizeof(short)); + memmove(history, &history[1], SHM->max_history * sizeof(short)); history[SHM->max_history] = j = i; if (i == 999) /* Goodbye my friend */ -- cgit v1.2.3 From 7f73e77929d61aa04d0259a8f350c17bfbd86951 Mon Sep 17 00:00:00 2001 From: kcwu <kcwu@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sat, 27 Jul 2002 10:06:19 +0000 Subject: fix indent git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@443 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/board.c | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/pttbbs/mbbsd/board.c b/pttbbs/mbbsd/board.c index cbbfea1b..56d2469a 100644 --- a/pttbbs/mbbsd/board.c +++ b/pttbbs/mbbsd/board.c @@ -1,4 +1,4 @@ -/* $Id: board.c,v 1.43 2002/07/22 19:02:00 in2 Exp $ */ +/* $Id: board.c,v 1.44 2002/07/27 10:06:19 kcwu Exp $ */ #include "bbs.h" #define BRC_STRLEN 15 /* Length of board name */ #define BRC_MAXSIZE 24576 @@ -555,20 +555,19 @@ show_brdlist(int head, int clsflag, int newflag) showtitle("分類看板", BBSName); movie(0); move(1, 0); - prints( + outs( " " - "◣ ╭—\033[33m●\n" - " 寣X \033[m " - "◢█\033[47m☉\033[40m██◣蔌n"); - prints( - " \033[44m ︿︿︿︿︿︿︿︿ " - "\033[33m鱋033[m\033[44m ◣◢███▼▼▼ \033[m\n" - " \033[44m " - "\033[33m \033[m\033[44m ◤◥███▲▲▲ 鱋033[m\n" + "◣ ╭—\033[33m●\n" + " 寣X \033[m " + "◢█\033[47m☉\033[40m██◣蔌n" + " \033[44m ︿︿︿︿︿︿︿︿ " + "\033[33m鱋033[m\033[44m ◣◢███▼▼▼ \033[m\n" + " \033[44m " + "\033[33m \033[m\033[44m ◤◥███▲▲▲ 鱋033[m\n" " ︿︿︿︿︿︿︿︿ \033[33m" - "│\033[m ◥████◤ 鱋n" - " \033[33m" - "——\033[m ◤ —+\033[m"); + "│\033[m ◥████◤ 鱋n" + " \033[33m" + "——\033[m ◤ —+\033[m"); } else if (clsflag) { showtitle("看板列表", BBSName); prints("[←]主選單 [→]閱\讀 [↑↓]選擇 [y]載入 [S]排序 [/]搜尋 " -- cgit v1.2.3 From 0bd7867689a272f1f120901e733cc5598941469c Mon Sep 17 00:00:00 2001 From: kcwu <kcwu@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sat, 27 Jul 2002 10:11:39 +0000 Subject: error handle git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@444 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/cache.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/pttbbs/mbbsd/cache.c b/pttbbs/mbbsd/cache.c index 0ceb8376..2ddfefb4 100644 --- a/pttbbs/mbbsd/cache.c +++ b/pttbbs/mbbsd/cache.c @@ -1,4 +1,4 @@ -/* $Id: cache.c,v 1.44 2002/07/22 19:02:00 in2 Exp $ */ +/* $Id: cache.c,v 1.45 2002/07/27 10:11:39 kcwu Exp $ */ #include "bbs.h" #ifndef __FreeBSD__ @@ -114,7 +114,10 @@ sem_lock(int op, int semid) sops.sem_num = 0; sops.sem_flg = SEM_UNDO; sops.sem_op = op; - semop(semid, &sops, 1); + if (semop(semid, &sops, 1)) { + perror("semop"); + exit(1); + } } /* uhash ****************************************** */ -- cgit v1.2.3 From 5563665c60817e90df1b95dd710821b17dcdc8d3 Mon Sep 17 00:00:00 2001 From: kcwu <kcwu@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sat, 27 Jul 2002 10:55:30 +0000 Subject: replace strlcat with strcat, which cause crash git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@445 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/more.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pttbbs/mbbsd/more.c b/pttbbs/mbbsd/more.c index 2acf144d..d7508ce4 100644 --- a/pttbbs/mbbsd/more.c +++ b/pttbbs/mbbsd/more.c @@ -1,4 +1,4 @@ -/* $Id: more.c,v 1.18 2002/07/22 19:02:00 in2 Exp $ */ +/* $Id: more.c,v 1.19 2002/07/27 10:55:30 kcwu Exp $ */ #include "bbs.h" #define MORE_BUFSIZE 4096 #define MORE_WINSIZE 4096 @@ -254,9 +254,9 @@ more(char *fpath, int promptend) snprintf(buf1, sizeof(buf1), "%.*s\033[7m%s\033[m", pos - pos1, pos1, SearchStr); - strcat(msg, buf1); + strlcat(msg, buf1, sizeof(msg)); } - strcat(msg, pos1); + strlcat(msg, pos1, sizeof(msg)); outs(Ptt_prints(msg, NO_RELOAD)); } else outs(Ptt_prints(buf, NO_RELOAD)); -- cgit v1.2.3 From a6a2335c3c3add32f384eb58112538f03ecb10e4 Mon Sep 17 00:00:00 2001 From: kcwu <kcwu@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sat, 27 Jul 2002 11:47:06 +0000 Subject: show `currstat' when debug me git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@446 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/mbbsd.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pttbbs/mbbsd/mbbsd.c b/pttbbs/mbbsd/mbbsd.c index ec0370c6..91800b4c 100644 --- a/pttbbs/mbbsd/mbbsd.c +++ b/pttbbs/mbbsd/mbbsd.c @@ -1,4 +1,4 @@ -/* $Id: mbbsd.c,v 1.45 2002/07/25 12:31:15 kcwu Exp $ */ +/* $Id: mbbsd.c,v 1.46 2002/07/27 11:47:06 kcwu Exp $ */ #include "bbs.h" #define SOCKET_QLEN 4 @@ -222,7 +222,7 @@ abort_bbs_debug(int sig) reentrant = 1; if (currmode) u_exit("AXXED"); - setproctitle("debug me!(%d)(%s)", sig, cuser.userid); + setproctitle("debug me!(%d)(%s,%d)", sig, cuser.userid, currstat); sleep(3600); /* wait 60 mins for debug */ } exit(0); -- cgit v1.2.3 From a76fd95c065aad3f13f9c274be95975a7bc8c4fa Mon Sep 17 00:00:00 2001 From: kcwu <kcwu@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sat, 27 Jul 2002 13:14:41 +0000 Subject: more specific `currstat' mode git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@447 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/bbs.c | 6 +++--- pttbbs/mbbsd/mbbsd.c | 4 ++-- pttbbs/mbbsd/talk.c | 8 ++++---- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/pttbbs/mbbsd/bbs.c b/pttbbs/mbbsd/bbs.c index 84749b1c..c6615a0c 100644 --- a/pttbbs/mbbsd/bbs.c +++ b/pttbbs/mbbsd/bbs.c @@ -1,4 +1,4 @@ -/* $Id: bbs.c,v 1.66 2002/07/22 19:02:00 in2 Exp $ */ +/* $Id: bbs.c,v 1.67 2002/07/27 13:14:41 kcwu Exp $ */ #include "bbs.h" static void @@ -261,6 +261,7 @@ do_select(int ent, fileheader_t * fhdr, char *direct) struct stat st; int i; + setutmpmode(SELECT); move(0, 0); clrtoeol(); generalnamecomplete(MSG_SELECT_BOARD, bname, sizeof(bname), @@ -1997,7 +1998,7 @@ ReadSelect() int stat0 = currstat; char genbuf[200]; - currstat = XMODE; + currstat = SELECT; if (do_select(0, 0, genbuf) == NEWDIRECT) Read(); setutmpbid(0); @@ -2024,7 +2025,6 @@ Select() { char genbuf[200]; - setutmpmode(SELECT); do_select(0, NULL, genbuf); return 0; } diff --git a/pttbbs/mbbsd/mbbsd.c b/pttbbs/mbbsd/mbbsd.c index 91800b4c..dcb4fd76 100644 --- a/pttbbs/mbbsd/mbbsd.c +++ b/pttbbs/mbbsd/mbbsd.c @@ -1,4 +1,4 @@ -/* $Id: mbbsd.c,v 1.46 2002/07/27 11:47:06 kcwu Exp $ */ +/* $Id: mbbsd.c,v 1.47 2002/07/27 13:14:41 kcwu Exp $ */ #include "bbs.h" #define SOCKET_QLEN 4 @@ -408,7 +408,7 @@ write_request(int sig) currutmp->mode = 0; currutmp->chatid[0] = 2; - currstat = XMODE; + currstat = HIT; do { bell(); diff --git a/pttbbs/mbbsd/talk.c b/pttbbs/mbbsd/talk.c index 56b2b88b..b36aade9 100644 --- a/pttbbs/mbbsd/talk.c +++ b/pttbbs/mbbsd/talk.c @@ -1,4 +1,4 @@ -/* $Id: talk.c,v 1.81 2002/07/22 19:02:00 in2 Exp $ */ +/* $Id: talk.c,v 1.82 2002/07/27 13:14:41 kcwu Exp $ */ #include "bbs.h" #define QCAST int (*)(const void *, const void *) @@ -467,7 +467,7 @@ my_write2(void) mode0 = currutmp->mode; currutmp->mode = 0; currutmp->chatid[0] = 3; - currstat = XMODE; + currstat = DBACK; //init screen move(7, 28); @@ -579,7 +579,7 @@ my_write(pid_t pid, char *prompt, char *id, int flag, userinfo_t * puin) } currutmp->mode = 0; currutmp->chatid[0] = 3; - currstat = XMODE; + currstat = DBACK; ptime = localtime(&now); @@ -2445,7 +2445,7 @@ talkreply(void) snprintf(page_requestor, sizeof(page_requestor), "%s (%s)", uip->userid, uip->username); currutmp->destuid = uip->uid; - currstat = XMODE; /* 避免出現動畫 */ + currstat = REPLY; /* 避免出現動畫 */ clear(); -- cgit v1.2.3 From ea996d22d24ac8c12f1daf21d86b71881cfb6d6b Mon Sep 17 00:00:00 2001 From: kcwu <kcwu@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sat, 27 Jul 2002 13:50:57 +0000 Subject: 1.only sysop can edit database directly 2.fix crash because of missing database git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@448 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/indict.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pttbbs/mbbsd/indict.c b/pttbbs/mbbsd/indict.c index fe7da8c4..14650fea 100644 --- a/pttbbs/mbbsd/indict.c +++ b/pttbbs/mbbsd/indict.c @@ -1,4 +1,4 @@ -/* $Id: indict.c,v 1.9 2002/07/27 10:04:59 kcwu Exp $ */ +/* $Id: indict.c,v 1.10 2002/07/27 13:50:57 kcwu Exp $ */ #include "bbs.h" #define REFER "etc/dicts" @@ -128,7 +128,7 @@ use_dict() more("etc/dict.hlp", YEA); clear(); continue; - } else if (word[0] == 'e') { + } else if (word[0] == 'e' && HAS_PERM(PERM_SYSOP)) { vedit(database, NA, NULL); clear(); continue; @@ -137,9 +137,9 @@ use_dict() continue; } } + i = 0; if ((fp = fopen(database, "r"))) { - i = 0; - while (fgets(lang, 150, fp) != NULL) { + while (fgets(lang, sizeof(lang), fp) != NULL) { if (lang[65] == '[') { lang[65] = 0; f = 1; @@ -166,8 +166,8 @@ use_dict() } } } + fclose(fp); } - fclose(fp); if (i == 0) { getdata(5, 0, "沒這個資料耶,新增嗎?(y/N)", lang, 3, LCECHO); if (lang[0] == 'y') { -- cgit v1.2.3 From a99c5f4489ddb81e6753c0d83ad3b619ce9163ea Mon Sep 17 00:00:00 2001 From: kcwu <kcwu@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sat, 27 Jul 2002 15:04:16 +0000 Subject: fix indent error git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@449 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/read.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pttbbs/mbbsd/read.c b/pttbbs/mbbsd/read.c index f979e2dd..b4879be3 100644 --- a/pttbbs/mbbsd/read.c +++ b/pttbbs/mbbsd/read.c @@ -1,4 +1,4 @@ -/* $Id: read.c,v 1.11 2002/07/22 19:02:00 in2 Exp $ */ +/* $Id: read.c,v 1.12 2002/07/27 15:04:16 kcwu Exp $ */ #include "bbs.h" #define MAXPATHLEN 256 @@ -730,7 +730,7 @@ i_read_key(onekey_t * rcmdlist, keeploc_t * locmem, int ch, int bid) } void - i_read(int cmdmode, char *direct, void (*dotitle) (), void (*doentry) (), onekey_t * rcmdlist, int bidcache){ +i_read(int cmdmode, char *direct, void (*dotitle) (), void (*doentry) (), onekey_t * rcmdlist, int bidcache){ keeploc_t *locmem = NULL; int recbase = 0, mode, ch; int num = 0, entries = 0; -- cgit v1.2.3 From 46c762033353932c3cf689cde32d113e790dec8e Mon Sep 17 00:00:00 2001 From: kcwu <kcwu@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sat, 27 Jul 2002 15:06:39 +0000 Subject: fix indent git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@450 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/read.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pttbbs/mbbsd/read.c b/pttbbs/mbbsd/read.c index b4879be3..33ea06b5 100644 --- a/pttbbs/mbbsd/read.c +++ b/pttbbs/mbbsd/read.c @@ -1,4 +1,4 @@ -/* $Id: read.c,v 1.12 2002/07/27 15:04:16 kcwu Exp $ */ +/* $Id: read.c,v 1.13 2002/07/27 15:06:39 kcwu Exp $ */ #include "bbs.h" #define MAXPATHLEN 256 @@ -730,7 +730,8 @@ i_read_key(onekey_t * rcmdlist, keeploc_t * locmem, int ch, int bid) } void -i_read(int cmdmode, char *direct, void (*dotitle) (), void (*doentry) (), onekey_t * rcmdlist, int bidcache){ +i_read(int cmdmode, char *direct, void (*dotitle) (), void (*doentry) (), onekey_t * rcmdlist, int bidcache) +{ keeploc_t *locmem = NULL; int recbase = 0, mode, ch; int num = 0, entries = 0; -- cgit v1.2.3 From d7e6e078244dddb19fcecf288e45d5bf58c95bfb Mon Sep 17 00:00:00 2001 From: kcwu <kcwu@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sat, 27 Jul 2002 17:23:09 +0000 Subject: fix the numbers of selection bug git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@451 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/friend.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/pttbbs/mbbsd/friend.c b/pttbbs/mbbsd/friend.c index 2df2025b..6becc8f9 100644 --- a/pttbbs/mbbsd/friend.c +++ b/pttbbs/mbbsd/friend.c @@ -1,4 +1,4 @@ -/* $Id: friend.c,v 1.12 2002/07/22 19:02:00 in2 Exp $ */ +/* $Id: friend.c,v 1.13 2002/07/27 17:23:09 kcwu Exp $ */ #include "bbs.h" /* ------------------------------------- */ @@ -154,7 +154,7 @@ friend_append(int type, int count) if (i != type) { ++j; snprintf(buf, sizeof(buf), - " (%d) %-s\n", i + 1, friend_list[(int)i]); + " (%d) %-s\n", j, friend_list[(int)i]); outs(buf); } if (HAVE_PERM(PERM_SYSOP) || currmode & MODE_BOARD) @@ -175,10 +175,9 @@ friend_append(int type, int count) j = buf[0] - '1'; if (j >= type) j++; - if (!(HAVE_PERM(PERM_SYSOP) || currmode & MODE_BOARD) && j >= 4) + if (!(HAVE_PERM(PERM_SYSOP) || currmode & MODE_BOARD) && j >= 5) return; - } - while (buf[0] < '1' || buf[0] > '9'); + } while (buf[0] < '1' || buf[0] > '9'); if (j == FRIEND_SPECIAL) friend_special(); -- cgit v1.2.3 From 6409d8242bf23eb46881dc292717a9413cc28f62 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Tue, 6 Aug 2002 07:12:52 +0000 Subject: fix idcard number bug git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@452 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/user.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pttbbs/mbbsd/user.c b/pttbbs/mbbsd/user.c index 9f985ab9..fc60c08d 100644 --- a/pttbbs/mbbsd/user.c +++ b/pttbbs/mbbsd/user.c @@ -1,4 +1,4 @@ -/* $Id: user.c,v 1.34 2002/07/25 11:06:15 in2 Exp $ */ +/* $Id: user.c,v 1.35 2002/08/06 07:12:52 in2 Exp $ */ #include "bbs.h" static char *sex[8] = { @@ -753,7 +753,7 @@ removespace(char *s) static int ispersonalid(char *inid) { - char *lst = "ABCDEFGHJKLMNPQRSTUVWXYZIO", id[20]; + char *lst = "ABCDEFGHJKLMNPQRSTUVXYWZIO", id[20]; int i, j, cksum; strlcpy(id, inid, sizeof(id)); -- cgit v1.2.3 From 0dd474d70b18c298ecb11049980d99a09db760a6 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Tue, 6 Aug 2002 07:33:35 +0000 Subject: OUTTA_CACHE, nbrd git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@453 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/board.c | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/pttbbs/mbbsd/board.c b/pttbbs/mbbsd/board.c index 56d2469a..149aa33c 100644 --- a/pttbbs/mbbsd/board.c +++ b/pttbbs/mbbsd/board.c @@ -1,4 +1,4 @@ -/* $Id: board.c,v 1.44 2002/07/27 10:06:19 kcwu Exp $ */ +/* $Id: board.c,v 1.45 2002/08/06 07:33:35 in2 Exp $ */ #include "bbs.h" #define BRC_STRLEN 15 /* Length of board name */ #define BRC_MAXSIZE 24576 @@ -220,6 +220,7 @@ typedef struct { } boardstat_t; static int *zapbuf = NULL, *favbuf; +static int nbrdlength; static boardstat_t *nbrd = NULL; #define STR_BBSRC ".bbsrc" @@ -445,7 +446,8 @@ load_boards(char *key) } brdnum = 0; if (class_bid <= 0) { - nbrd = (boardstat_t *) malloc(numboards * sizeof(boardstat_t)); + nbrdlength = numboards * sizeof(boardstat_t); + nbrd = (boardstat_t *) malloc(nbrdlength); for (i = 0; i < numboards; i++) { if ((bptr = SHM->bsorted[type][i]) == NULL) continue; @@ -463,7 +465,8 @@ load_boards(char *key) qsort(nbrd, brdnum, sizeof(boardstat_t), cmpboardfriends); } } else { - nbrd = (boardstat_t *) malloc(bptr->childcount * sizeof(boardstat_t)); + nbrdlength = bptr->childcount * sizeof(boardstat_t); + nbrd = (boardstat_t *) malloc(nbrdlength); for (bptr = bptr->firstchild[type]; bptr != (boardheader_t *) ~ 0; bptr = bptr->next[type]) { n = (int)(bptr - bcache); @@ -1014,7 +1017,27 @@ choose_board(int newflag) board_visit_time = zapbuf[ptr->bid - 1]; if (!(ptr->myattr & BRD_ZAP)) zapbuf[ptr->bid - 1] = now; - Read(); +#ifdef OUTTA_CACHE + { + int fd; + char fn[64]; + sprintf(fn, "cache/" MYHOSTNAME ".b%d", currpid); + if( (fd = open(fn, O_WRONLY | O_CREAT, 0600)) < 0 ) + abort_bbs(0); + write(fd, nbrd, nbrdlength); + close(fd); + free(nbrd); +#endif + Read(); +#ifdef OUTTA_CACHE + if( (fd = open(fn, O_RDONLY)) < 0 ) + abort_bbs(0); + nbrd = (boardstat_t *) malloc(nbrdlength); + read(fd, nbrd, nbrdlength); + close(fd); + unlink(fn); + } +#endif check_newpost(ptr); head = -1; setutmpmode(newflag ? READNEW : READBRD); -- cgit v1.2.3 From 56770ab2f36d9be01f889f99d55d5d50fad7da4f Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Tue, 6 Aug 2002 08:43:06 +0000 Subject: fix nbrd swap out bug git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@454 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/board.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pttbbs/mbbsd/board.c b/pttbbs/mbbsd/board.c index 149aa33c..d665360f 100644 --- a/pttbbs/mbbsd/board.c +++ b/pttbbs/mbbsd/board.c @@ -1,4 +1,4 @@ -/* $Id: board.c,v 1.45 2002/08/06 07:33:35 in2 Exp $ */ +/* $Id: board.c,v 1.46 2002/08/06 08:43:06 in2 Exp $ */ #include "bbs.h" #define BRC_STRLEN 15 /* Length of board name */ #define BRC_MAXSIZE 24576 @@ -1036,6 +1036,7 @@ choose_board(int newflag) read(fd, nbrd, nbrdlength); close(fd); unlink(fn); + ptr = &nbrd[num]; } #endif check_newpost(ptr); -- cgit v1.2.3 From e436c3626d57e536d2f1891c16ac7e6760a7fc40 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Tue, 6 Aug 2002 08:58:25 +0000 Subject: general outta_swap git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@455 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/board.c | 24 +++++------------------- pttbbs/mbbsd/cache.c | 30 +++++++++++++++++++++++++++++- 2 files changed, 34 insertions(+), 20 deletions(-) diff --git a/pttbbs/mbbsd/board.c b/pttbbs/mbbsd/board.c index d665360f..9f20b645 100644 --- a/pttbbs/mbbsd/board.c +++ b/pttbbs/mbbsd/board.c @@ -1,4 +1,4 @@ -/* $Id: board.c,v 1.46 2002/08/06 08:43:06 in2 Exp $ */ +/* $Id: board.c,v 1.47 2002/08/06 08:58:25 in2 Exp $ */ #include "bbs.h" #define BRC_STRLEN 15 /* Length of board name */ #define BRC_MAXSIZE 24576 @@ -1018,26 +1018,12 @@ choose_board(int newflag) if (!(ptr->myattr & BRD_ZAP)) zapbuf[ptr->bid - 1] = now; #ifdef OUTTA_CACHE - { - int fd; - char fn[64]; - sprintf(fn, "cache/" MYHOSTNAME ".b%d", currpid); - if( (fd = open(fn, O_WRONLY | O_CREAT, 0600)) < 0 ) - abort_bbs(0); - write(fd, nbrd, nbrdlength); - close(fd); - free(nbrd); + outta_swapout(&nbrd, nbrdlength, 'b'); #endif - Read(); + Read(); #ifdef OUTTA_CACHE - if( (fd = open(fn, O_RDONLY)) < 0 ) - abort_bbs(0); - nbrd = (boardstat_t *) malloc(nbrdlength); - read(fd, nbrd, nbrdlength); - close(fd); - unlink(fn); - ptr = &nbrd[num]; - } + outta_swapin(&nbrd, nbrdlength, 'b'); + ptr = &nbrd[num]; #endif check_newpost(ptr); head = -1; diff --git a/pttbbs/mbbsd/cache.c b/pttbbs/mbbsd/cache.c index 2ddfefb4..630390c1 100644 --- a/pttbbs/mbbsd/cache.c +++ b/pttbbs/mbbsd/cache.c @@ -1,4 +1,4 @@ -/* $Id: cache.c,v 1.45 2002/07/27 10:11:39 kcwu Exp $ */ +/* $Id: cache.c,v 1.46 2002/08/06 08:58:25 in2 Exp $ */ #include "bbs.h" #ifndef __FreeBSD__ @@ -1129,3 +1129,31 @@ mdcacheopen(char *fpath) return fd; } #endif + +#ifdef OUTTA_CACHE +void outta_swapout(void **ptr, int length, char cacheid) +{ + char fn[64]; + int fd; + sprintf(fn, "cache/" MYHOSTNAME "%c%d", cacheid, currpid); + if( (fd = open(fn, O_WRONLY | O_CREAT, 0600)) < 0 ) + abort_bbs(0); + write(fd, *ptr, length); + close(fd); + free(*ptr); + *ptr = NULL; +} + +void outta_swapin(void **ptr, int length, char cacheid) +{ + char fn[64]; + int fd; + sprintf(fn, "cache/" MYHOSTNAME "%c%d", cacheid, currpid); + if( (fd = open(fn, O_RDONLY)) < 0 ) + abort_bbs(0); + *ptr = (void *)malloc(length); + read(fd, *ptr, length); + close(fd); + unlink(fn); +} +#endif -- cgit v1.2.3 From 0104b90c164007470d214fd67e399b8fafe2af5e Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Tue, 6 Aug 2002 09:03:02 +0000 Subject: outta_swap git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@456 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/include/proto.h | 7 ++++++- pttbbs/mbbsd/board.c | 6 +++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/pttbbs/include/proto.h b/pttbbs/include/proto.h index 5e3d8f91..47f45517 100644 --- a/pttbbs/include/proto.h +++ b/pttbbs/include/proto.h @@ -1,4 +1,4 @@ -/* $Id: proto.h,v 1.24 2002/07/04 19:46:14 in2 Exp $ */ +/* $Id: proto.h,v 1.25 2002/08/06 09:02:59 in2 Exp $ */ #ifndef INCLUDE_PROTO_H #define INCLUDE_PROTO_H @@ -117,6 +117,11 @@ int get_fileheader_cache(int bid, char *direct, fileheader_t *headers, int recbase, int nlines); void *attach_shm(int shmkey, int shmsize); void attach_SHM(void); +#ifdef OUTTA_CACHE +void outta_swapout(void **ptr, int length, char cacheid); +void outta_swapin(void **ptr, int length, char cacheid); +#endif + /* cal */ int give_tax(int money); diff --git a/pttbbs/mbbsd/board.c b/pttbbs/mbbsd/board.c index 9f20b645..7001f730 100644 --- a/pttbbs/mbbsd/board.c +++ b/pttbbs/mbbsd/board.c @@ -1,4 +1,4 @@ -/* $Id: board.c,v 1.47 2002/08/06 08:58:25 in2 Exp $ */ +/* $Id: board.c,v 1.48 2002/08/06 09:03:02 in2 Exp $ */ #include "bbs.h" #define BRC_STRLEN 15 /* Length of board name */ #define BRC_MAXSIZE 24576 @@ -1018,11 +1018,11 @@ choose_board(int newflag) if (!(ptr->myattr & BRD_ZAP)) zapbuf[ptr->bid - 1] = now; #ifdef OUTTA_CACHE - outta_swapout(&nbrd, nbrdlength, 'b'); + outta_swapout((void **)&nbrd, nbrdlength, 'b'); #endif Read(); #ifdef OUTTA_CACHE - outta_swapin(&nbrd, nbrdlength, 'b'); + outta_swapin((void **)&nbrd, nbrdlength, 'b'); ptr = &nbrd[num]; #endif check_newpost(ptr); -- cgit v1.2.3 From 5b490a93c224d78b7a200d4ded081f08e7e35f6a Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Wed, 7 Aug 2002 03:48:28 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@457 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pttbbs/util/Makefile b/pttbbs/util/Makefile index bfe6429f..47623a07 100644 --- a/pttbbs/util/Makefile +++ b/pttbbs/util/Makefile @@ -1,4 +1,4 @@ -# $Id: Makefile,v 1.13 2002/07/17 17:09:20 ptt Exp $ +# $Id: Makefile,v 1.14 2002/08/07 03:48:28 in2 Exp $ BBSHOME?=$(HOME) OSTYPE?=linux @@ -35,7 +35,7 @@ CPROGS= bbsmail BM_money post account birth deluserfile expire mandex\ PROGS= $(CPROGS) BM_money.sh backpasswd.sh mailog.sh opendice.sh\ openticket.sh stock.sh topsong.sh weather.sh stock.perl weather.perl\ toplazyBM.sh toplazyBBM.sh dailybackup.pl tarqueue.pl waterball.pl \ - filtermail.pl getbackup.pl + filtermail.pl getbackup.pl cleancache.pl all: $(PROGS) -- cgit v1.2.3 From 683ab8dd4d5360f03c02c475f79a4490848c3792 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Wed, 7 Aug 2002 03:48:39 +0000 Subject: $MYHOSTNAME git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@458 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/LocalVars.pm.sample | 1 + 1 file changed, 1 insertion(+) diff --git a/pttbbs/util/LocalVars.pm.sample b/pttbbs/util/LocalVars.pm.sample index 67157009..2f93947e 100644 --- a/pttbbs/util/LocalVars.pm.sample +++ b/pttbbs/util/LocalVars.pm.sample @@ -9,6 +9,7 @@ require Exporter; # host $hostname = 'ptt'; +$MYHOSTNAME = 'ptt.cc'; $FQDN = 'ptt.csie.ntu.edu.tw'; $SMTPSERVER = 'ptt2.csie.ntu.edu.tw'; -- cgit v1.2.3 From daabb5fb320b5d610b84f78607d602a9d9518bbe Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Wed, 7 Aug 2002 03:48:52 +0000 Subject: listpid git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@459 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/shmctl.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/pttbbs/util/shmctl.c b/pttbbs/util/shmctl.c index 34276bb0..72d9b301 100644 --- a/pttbbs/util/shmctl.c +++ b/pttbbs/util/shmctl.c @@ -1,4 +1,4 @@ -/* $Id: shmctl.c,v 1.25 2002/07/22 16:50:36 in2 Exp $ */ +/* $Id: shmctl.c,v 1.26 2002/08/07 03:48:52 in2 Exp $ */ #include "bbs.h" extern SHM_t *SHM; @@ -280,6 +280,15 @@ int setglobal(int argc, char **argv) return 0; } +int listpid(int argc, char **argv) +{ + int i; + for( i = 0 ; i < USHM_SIZE ; ++i ) + if( SHM->uinfo[i].pid > 0 ) + printf("%d\n", SHM->uinfo[i].pid); + return 0; +} + struct { int (*func)(int, char **); char *cmd, *descript; @@ -292,6 +301,7 @@ struct { {utmpnum, "utmpnum", "print SHM->number for snmpd"}, {showglobal, "showglobal", "show GLOBALVAR[]"}, {setglobal, "setglobal", "set GLOBALVAR[]"}, + {listpid, "listpid", "list all pids of mbbsd"}, {NULL, NULL, NULL} }; int main(int argc, char **argv) -- cgit v1.2.3 From a708bd65db1e36ef6fde97168a22dd9058dcc4ce Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Wed, 7 Aug 2002 03:49:10 +0000 Subject: add indexuser git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@460 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/.cvsignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pttbbs/util/.cvsignore b/pttbbs/util/.cvsignore index 5b0fde27..d33e906f 100644 --- a/pttbbs/util/.cvsignore +++ b/pttbbs/util/.cvsignore @@ -43,4 +43,4 @@ mandex shmctl mdclean splitpasswd - +indexuser -- cgit v1.2.3 From f20d13469b74e7372ea198e4f6480ba27fc55346 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Wed, 7 Aug 2002 03:49:50 +0000 Subject: add cleancache.pl git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@461 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/cleancache.pl | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 pttbbs/util/cleancache.pl diff --git a/pttbbs/util/cleancache.pl b/pttbbs/util/cleancache.pl new file mode 100644 index 00000000..87701d2d --- /dev/null +++ b/pttbbs/util/cleancache.pl @@ -0,0 +1,24 @@ +#!/usr/bin/perl +use lib '/home/bbs/bin/'; +use LocalVars; + +chdir '/home/bbs/'; +opendir(DIR, "cache") || die "can't open cache/ ($!) "; +foreach( readdir(DIR) ){ + if( index($_, $MYHOSTNAME) == 0 ){ + $hash{$_} = 1; + } +} + +closedir DIR; + +open USEDPID, "bin/shmctl listpid |"; +while( <USEDPID> ){ + chomp; + delete $hash{"${MYHOSTNAME}b$_"}; +} + +foreach( keys %hash ){ + print "$_\n"; + unlink "cache/$_"; +} -- cgit v1.2.3 From 73ea6e52a4af1ec7170b3b0554e8bbdfb26b3ded Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Wed, 7 Aug 2002 09:32:38 +0000 Subject: favbuf, zapbuf swapout git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@462 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/board.c | 33 ++++++++++++++++++++++++++++++++- pttbbs/mbbsd/cache.c | 8 +++++++- 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/pttbbs/mbbsd/board.c b/pttbbs/mbbsd/board.c index 7001f730..b8ef6c08 100644 --- a/pttbbs/mbbsd/board.c +++ b/pttbbs/mbbsd/board.c @@ -1,4 +1,4 @@ -/* $Id: board.c,v 1.48 2002/08/06 09:03:02 in2 Exp $ */ +/* $Id: board.c,v 1.49 2002/08/07 09:32:38 in2 Exp $ */ #include "bbs.h" #define BRC_STRLEN 15 /* Length of board name */ #define BRC_MAXSIZE 24576 @@ -226,6 +226,10 @@ static boardstat_t *nbrd = NULL; #define STR_BBSRC ".bbsrc" #define STR_FAV ".fav" +#ifdef OUTTA_CACHE +int zaplength, favlength; +#endif + void init_brdbuf() { @@ -259,6 +263,11 @@ init_brdbuf() favbuf[n] &= ~BRD_TAG; brc_expire_time = login_start_time - 365 * 86400; + +#ifdef OUTTA_CACHE + outta_swapout((void **)&favbuf, (favlength = size + 4), 'f'); + outta_swapout((void **)&zapbuf, (zaplength = size), 'z'); +#endif } void @@ -267,6 +276,10 @@ save_brdbuf() int fd, size; char fname[60]; +#ifdef OUTTA_CACHE + outta_swapin((void **)&favbuf, favlength, 'f'); + outta_swapin((void **)&zapbuf, zaplength, 'z'); +#endif if (!zapbuf) return; setuserfile(fname, STR_BBSRC); @@ -709,6 +722,14 @@ choose_board(int newflag) char genbuf[200]; #endif +#ifdef OUTTA_CACHE + static char depth = 0; + ++depth; + if( favbuf == NULL ) + outta_swapin((void **)&favbuf, favlength, 'f'); + if( zapbuf == NULL ) + outta_swapin((void **)&zapbuf, zaplength, 'z'); +#endif setutmpmode(newflag ? READNEW : READBRD); brdnum = 0; if (!cuser.userlevel) /* guest yank all boards */ @@ -1018,10 +1039,14 @@ choose_board(int newflag) if (!(ptr->myattr & BRD_ZAP)) zapbuf[ptr->bid - 1] = now; #ifdef OUTTA_CACHE + outta_swapout((void **)&favbuf, favlength, 'f'); + outta_swapout((void **)&zapbuf, zaplength, 'z'); outta_swapout((void **)&nbrd, nbrdlength, 'b'); #endif Read(); #ifdef OUTTA_CACHE + outta_swapin((void **)&favbuf, favlength, 'f'); + outta_swapin((void **)&zapbuf, zaplength, 'z'); outta_swapin((void **)&nbrd, nbrdlength, 'b'); ptr = &nbrd[num]; #endif @@ -1071,6 +1096,12 @@ choose_board(int newflag) } } while (ch != 'q'); free(nbrd); +#ifdef OUTTA_CACHE + if( --depth == 0 ){ + outta_swapout((void **)&favbuf, favlength, 'f'); + outta_swapout((void **)&zapbuf, zaplength, 'z'); + } +#endif } int diff --git a/pttbbs/mbbsd/cache.c b/pttbbs/mbbsd/cache.c index 630390c1..27202de7 100644 --- a/pttbbs/mbbsd/cache.c +++ b/pttbbs/mbbsd/cache.c @@ -1,4 +1,4 @@ -/* $Id: cache.c,v 1.46 2002/08/06 08:58:25 in2 Exp $ */ +/* $Id: cache.c,v 1.47 2002/08/07 09:32:38 in2 Exp $ */ #include "bbs.h" #ifndef __FreeBSD__ @@ -1135,6 +1135,9 @@ void outta_swapout(void **ptr, int length, char cacheid) { char fn[64]; int fd; +#ifdef DEBUG + vmsg("swap out (%c) %d bytes", cacheid, length); +#endif sprintf(fn, "cache/" MYHOSTNAME "%c%d", cacheid, currpid); if( (fd = open(fn, O_WRONLY | O_CREAT, 0600)) < 0 ) abort_bbs(0); @@ -1148,6 +1151,9 @@ void outta_swapin(void **ptr, int length, char cacheid) { char fn[64]; int fd; +#ifdef DEBUG + vmsg("swap in (%c) %d bytes", cacheid, length); +#endif sprintf(fn, "cache/" MYHOSTNAME "%c%d", cacheid, currpid); if( (fd = open(fn, O_RDONLY)) < 0 ) abort_bbs(0); -- cgit v1.2.3 From 79bdda749089b4e45af9e306f3c80706465da464 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Wed, 7 Aug 2002 09:44:04 +0000 Subject: clean fav, zap git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@463 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/cleancache.pl | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pttbbs/util/cleancache.pl b/pttbbs/util/cleancache.pl index 87701d2d..cdd4426c 100644 --- a/pttbbs/util/cleancache.pl +++ b/pttbbs/util/cleancache.pl @@ -16,6 +16,8 @@ open USEDPID, "bin/shmctl listpid |"; while( <USEDPID> ){ chomp; delete $hash{"${MYHOSTNAME}b$_"}; + delete $hash{"${MYHOSTNAME}f$_"}; + delete $hash{"${MYHOSTNAME}z$_"}; } foreach( keys %hash ){ -- cgit v1.2.3 From 1aa48ff382b16e2b50afc59206b22107a9e8cdfe Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Wed, 7 Aug 2002 10:00:13 +0000 Subject: reentrant git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@464 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/board.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/pttbbs/mbbsd/board.c b/pttbbs/mbbsd/board.c index b8ef6c08..2f2dff2b 100644 --- a/pttbbs/mbbsd/board.c +++ b/pttbbs/mbbsd/board.c @@ -1,4 +1,4 @@ -/* $Id: board.c,v 1.49 2002/08/07 09:32:38 in2 Exp $ */ +/* $Id: board.c,v 1.50 2002/08/07 10:00:13 in2 Exp $ */ #include "bbs.h" #define BRC_STRLEN 15 /* Length of board name */ #define BRC_MAXSIZE 24576 @@ -275,7 +275,10 @@ save_brdbuf() { int fd, size; char fname[60]; - + static char reentrant = 0; + if ( reentrant ) + return; + reentrant = 1; #ifdef OUTTA_CACHE outta_swapin((void **)&favbuf, favlength, 'f'); outta_swapin((void **)&zapbuf, zaplength, 'z'); -- cgit v1.2.3 From 204cdde14ce36be5d3f36bcad3ce3841fa27a9bc Mon Sep 17 00:00:00 2001 From: kcwu <kcwu@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Fri, 9 Aug 2002 11:36:23 +0000 Subject: no need to change the case of first char git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@465 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/talk.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pttbbs/mbbsd/talk.c b/pttbbs/mbbsd/talk.c index b36aade9..120d9be0 100644 --- a/pttbbs/mbbsd/talk.c +++ b/pttbbs/mbbsd/talk.c @@ -1,4 +1,4 @@ -/* $Id: talk.c,v 1.82 2002/07/27 13:14:41 kcwu Exp $ */ +/* $Id: talk.c,v 1.83 2002/08/09 11:36:23 kcwu Exp $ */ #include "bbs.h" #define QCAST int (*)(const void *, const void *) @@ -2112,7 +2112,7 @@ userlist(void) case 'i':{ char mindbuf[5]; getdata(b_lines - 1, 0, "現在的心情? ", - mindbuf, sizeof(mindbuf), LCECHO); + mindbuf, sizeof(mindbuf), 0); if (strcmp(mindbuf, "通緝") == 0) vmsg("不可以把自己設通緝啦!"); else if (strcmp(mindbuf, "壽星") == 0) -- cgit v1.2.3 From 9f07076552dc9c4d4a934c83460f2d8ea4449391 Mon Sep 17 00:00:00 2001 From: kcwu <kcwu@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Fri, 9 Aug 2002 13:18:26 +0000 Subject: fix last commit, in this case, it should echo git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@466 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/talk.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pttbbs/mbbsd/talk.c b/pttbbs/mbbsd/talk.c index 120d9be0..5ba9b7f3 100644 --- a/pttbbs/mbbsd/talk.c +++ b/pttbbs/mbbsd/talk.c @@ -1,4 +1,4 @@ -/* $Id: talk.c,v 1.83 2002/08/09 11:36:23 kcwu Exp $ */ +/* $Id: talk.c,v 1.84 2002/08/09 13:18:26 kcwu Exp $ */ #include "bbs.h" #define QCAST int (*)(const void *, const void *) @@ -2112,7 +2112,7 @@ userlist(void) case 'i':{ char mindbuf[5]; getdata(b_lines - 1, 0, "現在的心情? ", - mindbuf, sizeof(mindbuf), 0); + mindbuf, sizeof(mindbuf), DOECHO); if (strcmp(mindbuf, "通緝") == 0) vmsg("不可以把自己設通緝啦!"); else if (strcmp(mindbuf, "壽星") == 0) -- cgit v1.2.3 From c345a17b21ee8d7635f041e85378eb1f2b88f297 Mon Sep 17 00:00:00 2001 From: kcwu <kcwu@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Mon, 12 Aug 2002 15:03:25 +0000 Subject: set OSTYPE by `uname' git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@467 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pttbbs/util/Makefile b/pttbbs/util/Makefile index 47623a07..3ff1a1b3 100644 --- a/pttbbs/util/Makefile +++ b/pttbbs/util/Makefile @@ -1,7 +1,7 @@ -# $Id: Makefile,v 1.14 2002/08/07 03:48:28 in2 Exp $ +# $Id: Makefile,v 1.15 2002/08/12 15:03:25 kcwu Exp $ BBSHOME?=$(HOME) -OSTYPE?=linux +OSTYPE!=uname # FreeBSD CC_FreeBSD= gcc -- cgit v1.2.3 From e8c8abf0a65aa8a98b363e112f296f45e89ad01c Mon Sep 17 00:00:00 2001 From: kcwu <kcwu@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Mon, 12 Aug 2002 15:04:01 +0000 Subject: don't show the listing if it's hidden git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@468 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/mandex.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pttbbs/util/mandex.c b/pttbbs/util/mandex.c index 545ca373..1ca9494c 100644 --- a/pttbbs/util/mandex.c +++ b/pttbbs/util/mandex.c @@ -1,4 +1,4 @@ -/* $Id: mandex.c,v 1.7 2002/06/19 13:38:01 lwms Exp $ */ +/* $Id: mandex.c,v 1.8 2002/08/12 15:04:01 kcwu Exp $ */ /* 'mandex -h' to help */ @@ -99,7 +99,9 @@ mandex(level, num_header, fpath) fputs(buf, fndx); if (dashd(fpath)){ ++ndir; - if (*fhdr.title != '#' && level < 10){ + /* I can't find the code to change title? */ + if (*fhdr.title != '#' && level < 10 && + (fhdr.filemode&(FILE_BM|FILE_HIDE))==0){ strcat(fpath, "/.DIR"); mandex(level + 1, buf, fpath); } -- cgit v1.2.3 From cc51cd4f3a6788518d6a8b57c044891442ea71ce Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Thu, 15 Aug 2002 09:44:12 +0000 Subject: remove cleancache.pl git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@469 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/Makefile | 4 ++-- pttbbs/util/cleancache.pl | 26 -------------------------- 2 files changed, 2 insertions(+), 28 deletions(-) delete mode 100644 pttbbs/util/cleancache.pl diff --git a/pttbbs/util/Makefile b/pttbbs/util/Makefile index 3ff1a1b3..b4e8fb2c 100644 --- a/pttbbs/util/Makefile +++ b/pttbbs/util/Makefile @@ -1,4 +1,4 @@ -# $Id: Makefile,v 1.15 2002/08/12 15:03:25 kcwu Exp $ +# $Id: Makefile,v 1.16 2002/08/15 09:44:12 in2 Exp $ BBSHOME?=$(HOME) OSTYPE!=uname @@ -35,7 +35,7 @@ CPROGS= bbsmail BM_money post account birth deluserfile expire mandex\ PROGS= $(CPROGS) BM_money.sh backpasswd.sh mailog.sh opendice.sh\ openticket.sh stock.sh topsong.sh weather.sh stock.perl weather.perl\ toplazyBM.sh toplazyBBM.sh dailybackup.pl tarqueue.pl waterball.pl \ - filtermail.pl getbackup.pl cleancache.pl + filtermail.pl getbackup.pl all: $(PROGS) diff --git a/pttbbs/util/cleancache.pl b/pttbbs/util/cleancache.pl deleted file mode 100644 index cdd4426c..00000000 --- a/pttbbs/util/cleancache.pl +++ /dev/null @@ -1,26 +0,0 @@ -#!/usr/bin/perl -use lib '/home/bbs/bin/'; -use LocalVars; - -chdir '/home/bbs/'; -opendir(DIR, "cache") || die "can't open cache/ ($!) "; -foreach( readdir(DIR) ){ - if( index($_, $MYHOSTNAME) == 0 ){ - $hash{$_} = 1; - } -} - -closedir DIR; - -open USEDPID, "bin/shmctl listpid |"; -while( <USEDPID> ){ - chomp; - delete $hash{"${MYHOSTNAME}b$_"}; - delete $hash{"${MYHOSTNAME}f$_"}; - delete $hash{"${MYHOSTNAME}z$_"}; -} - -foreach( keys %hash ){ - print "$_\n"; - unlink "cache/$_"; -} -- cgit v1.2.3 From f8bf9ebaa124a041eb54d2a287136db2fb2f8a92 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Thu, 15 Aug 2002 09:44:36 +0000 Subject: udnnews.pl git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@470 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/Makefile | 4 +- pttbbs/util/udnnews.pl | 100 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 102 insertions(+), 2 deletions(-) create mode 100644 pttbbs/util/udnnews.pl diff --git a/pttbbs/util/Makefile b/pttbbs/util/Makefile index b4e8fb2c..2a56cc0e 100644 --- a/pttbbs/util/Makefile +++ b/pttbbs/util/Makefile @@ -1,4 +1,4 @@ -# $Id: Makefile,v 1.16 2002/08/15 09:44:12 in2 Exp $ +# $Id: Makefile,v 1.17 2002/08/15 09:44:36 in2 Exp $ BBSHOME?=$(HOME) OSTYPE!=uname @@ -35,7 +35,7 @@ CPROGS= bbsmail BM_money post account birth deluserfile expire mandex\ PROGS= $(CPROGS) BM_money.sh backpasswd.sh mailog.sh opendice.sh\ openticket.sh stock.sh topsong.sh weather.sh stock.perl weather.perl\ toplazyBM.sh toplazyBBM.sh dailybackup.pl tarqueue.pl waterball.pl \ - filtermail.pl getbackup.pl + filtermail.pl getbackup.pl udnnews.pl all: $(PROGS) diff --git a/pttbbs/util/udnnews.pl b/pttbbs/util/udnnews.pl new file mode 100644 index 00000000..68a56c03 --- /dev/null +++ b/pttbbs/util/udnnews.pl @@ -0,0 +1,100 @@ +#!/usr/bin/perl +# +# 請註意! +# 本程式版權屬於 PttBBS , +# 但只表示您可以公開免費取得本程式, +# 並不表示您可以使用本程式. +# +# 本程式將直接連至 udnnews網站取得當前新聞, +# 而新聞內容的版權是屬於 聯合新聞網 所有. +# 亦即, 您若沒有聯合新聞網之書面授權, +# 您並「不能」使用本程式下載該網新聞. +# + +use LocalVars; +use strict; +use vars qw/@titles/; + +chdir '/home/bbs'; +getudnnewstitle(\@titles); +foreach( @titles ){ + postout({brdname => 'udnnews', + title => $_->[1], + owner => 'udnnews.', + content => getudnnewscontent("http://www.udnnews.com/NEWS/TODAYNEWS/$_->[0]")}); +} + +sub getudnnewscontent($) +{ + my($url) = @_; + my($buf, $content, $ret); + $buf = `$LYNX -source '$url'`; + ($content) = $buf =~ m|<p><font class="text12" color=#CC0033><br>(.*?)<tr valign="top">|s; + ($content) = $buf =~ m|<p><font color="#CC0033" class="text12">(.*?)<tr valign="top">|s if( !$content ); + $content =~ s/<br>/\n/g; + $content =~ s/<p>/\n/gi; + $content =~ s/<.*?>//g; + $content =~ s/\r//g; + $content =~ s/\n\n\n/\n\n/g; + $content =~ s/\n\n\n//g; + undef $ret; + foreach( split(/\n/, $content) ){ + s/ //g; + $ret .= FormatChinese($_, 60). "\n" if( $_ ); + } + return "※ [轉錄自 $url ]\n\n$ret\n\n". + "--\n感謝 http://www.udnnews.com/NEWS/ 熱情贊助"; +} + +sub getudnnewstitle($) +{ + my($ra_titles) = @_; + my($url, $title); + open FH, "$LYNX -source http://www.udnnews.com/NEWS/TODAYNEWS/ | $GREP '<font color=\"#FF9933\">' |"; + while( <FH> ){ + ($url, $title) = $_ =~ m|<font color="#FF9933">.</font><a href="(.*?)"><font color="#003333">(.*?)</font></a><font color="#003333">|; + $title =~ s/<.*?>//g; + push @{$ra_titles}, [$url, $title]; + } + close FH; + return @{$ra_titles}; +} + +sub FormatChinese +{ + my($str, $length) = @_; + my($i, $ret, $count, $s); + return if( !$str ); + for( $i = 0 ; $i < length($str) ; ++$i ){ + if( ord(substr($str, $i, 1)) > 127 ){ + $ret .= substr($str, $i, 2); + ++$i; + } + else{ + for( $count = 0, $s = $i ; $i < length($str) ; ++$i, ++$count ){ + last if( ord(substr($str, $i, 1)) > 127 ); + } + --$i; + $ret .= ' ' if( $count % 2 == 1); + $ret .= substr($str, $s, $count); + } + } + $str = $ret; + undef $ret; + while( $str ){ + $ret .= substr($str, 0, $length)."\n"; + $str = substr($str, $length); + } + return $ret; +} + +sub postout +{ + my($param) = @_; + open FH, ">/tmp/postout.$$"; + print FH $param->{content}; + close FH; + + system("bin/post '$param->{brdname}' '$param->{title}' '$param->{owner}' /tmp/postout.$$"); + unlink "/tmp/postout.$$"; +} -- cgit v1.2.3 From 863d174dff1c6f542b92d766a99462bef319349a Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Thu, 15 Aug 2002 09:45:02 +0000 Subject: add $LYNX $GREP git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@471 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/LocalVars.pm.sample | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/pttbbs/util/LocalVars.pm.sample b/pttbbs/util/LocalVars.pm.sample index 2f93947e..04806da6 100644 --- a/pttbbs/util/LocalVars.pm.sample +++ b/pttbbs/util/LocalVars.pm.sample @@ -3,9 +3,9 @@ package LocalVars; require Exporter; @ISA = qw/Exporter/; @EXPORT = qw/ - $hostname $FQDN $SMTPSERVER + $hostname $MYHOSTNAME $FQDN $SMTPSERVER $BBSHOME $JOBSPOOL $TMP - $TAR/; + $TAR $LYNX $GREP/; # host $hostname = 'ptt'; @@ -20,4 +20,5 @@ $TMP = '/tmp'; # program $TAR = '/bin/tar'; - +$LYNX = '/usr/local/bin/lynx'; +$GREP = '/usr/bin/grep'; -- cgit v1.2.3 From 3c9dca6acad2addda7ca2404718e873cf6bc2558 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Thu, 15 Aug 2002 09:46:30 +0000 Subject: load cache at first time git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@472 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/read.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/pttbbs/mbbsd/read.c b/pttbbs/mbbsd/read.c index 33ea06b5..ec7efeb4 100644 --- a/pttbbs/mbbsd/read.c +++ b/pttbbs/mbbsd/read.c @@ -1,4 +1,4 @@ -/* $Id: read.c,v 1.13 2002/07/27 15:06:39 kcwu Exp $ */ +/* $Id: read.c,v 1.14 2002/08/15 09:46:30 in2 Exp $ */ #include "bbs.h" #define MAXPATHLEN 256 @@ -759,8 +759,12 @@ i_read(int cmdmode, char *direct, void (*dotitle) (), void (*doentry) (), onekey switch (mode) { case NEWDIRECT: /* 第一次載入此目錄 */ case DIRCHANGED: - if (bidcache > 0 && !(currmode & (MODE_SELECT | MODE_DIGEST))) - last_line = getbtotal(currbid); + if (bidcache > 0 && !(currmode & (MODE_SELECT | MODE_DIGEST))){ + if( (last_line = getbtotal(currbid)) == 0 ){ + setbtotal(currbid); + last_line = get_num_records(currdirect, FHSZ); + } + } else last_line = get_num_records(currdirect, FHSZ); -- cgit v1.2.3 From ca5b4821cdfc7d093f683ba7781b33c983f36bd6 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Thu, 15 Aug 2002 16:09:34 +0000 Subject: use lib '/home/bbs/bin/' git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@473 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/udnnews.pl | 1 + 1 file changed, 1 insertion(+) diff --git a/pttbbs/util/udnnews.pl b/pttbbs/util/udnnews.pl index 68a56c03..f198d273 100644 --- a/pttbbs/util/udnnews.pl +++ b/pttbbs/util/udnnews.pl @@ -11,6 +11,7 @@ # 您並「不能」使用本程式下載該網新聞. # +use lib '/home/bbs/bin/'; use LocalVars; use strict; use vars qw/@titles/; -- cgit v1.2.3 From eca065388a32268de0c821f251effdf9ed638aec Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Fri, 16 Aug 2002 18:24:43 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@474 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/udnnews.pl | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/pttbbs/util/udnnews.pl b/pttbbs/util/udnnews.pl index f198d273..d953c388 100644 --- a/pttbbs/util/udnnews.pl +++ b/pttbbs/util/udnnews.pl @@ -20,9 +20,9 @@ chdir '/home/bbs'; getudnnewstitle(\@titles); foreach( @titles ){ postout({brdname => 'udnnews', - title => $_->[1], + title => FormatChinese($_->[1]), owner => 'udnnews.', - content => getudnnewscontent("http://www.udnnews.com/NEWS/TODAYNEWS/$_->[0]")}); + content => getudnnewscontent("http://udnnews.com/NEWS/FOCUSNEWS/$_->[0]")}); } sub getudnnewscontent($) @@ -51,7 +51,7 @@ sub getudnnewstitle($) { my($ra_titles) = @_; my($url, $title); - open FH, "$LYNX -source http://www.udnnews.com/NEWS/TODAYNEWS/ | $GREP '<font color=\"#FF9933\">' |"; + open FH, "$LYNX -source http://udnnews.com/NEWS/FOCUSNEWS/ | $GREP '<font color=\"#FF9933\">' |"; while( <FH> ){ ($url, $title) = $_ =~ m|<font color="#FF9933">.</font><a href="(.*?)"><font color="#003333">(.*?)</font></a><font color="#003333">|; $title =~ s/<.*?>//g; @@ -80,11 +80,13 @@ sub FormatChinese $ret .= substr($str, $s, $count); } } - $str = $ret; - undef $ret; - while( $str ){ - $ret .= substr($str, 0, $length)."\n"; - $str = substr($str, $length); + if( $length ){ + $str = $ret; + undef $ret; + while( $str ){ + $ret .= substr($str, 0, $length)."\n"; + $str = substr($str, $length); + } } return $ret; } -- cgit v1.2.3 From d6b007e0af259f0a3340cc4929750a622f872999 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sat, 17 Aug 2002 12:31:56 +0000 Subject: outta cache git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@475 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/include/bbs.h | 10 ++-- pttbbs/include/outtacache.h | 28 +++++++++++ pttbbs/include/proto.h | 8 +-- pttbbs/util/.cvsignore | 2 + pttbbs/util/Makefile | 14 +++++- pttbbs/util/cacheserver.c | 120 ++++++++++++++++++++++++++++++++++++++++++++ pttbbs/util/localserver.c | 116 ++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 289 insertions(+), 9 deletions(-) create mode 100644 pttbbs/include/outtacache.h create mode 100644 pttbbs/util/cacheserver.c create mode 100644 pttbbs/util/localserver.c diff --git a/pttbbs/include/bbs.h b/pttbbs/include/bbs.h index 1b2a0d38..a56ee944 100644 --- a/pttbbs/include/bbs.h +++ b/pttbbs/include/bbs.h @@ -32,6 +32,7 @@ #include <sys/ipc.h> #include <sys/shm.h> #include <sys/sem.h> +#include <sys/msg.h> #include "config.h" #include "pttstruct.h" @@ -42,11 +43,14 @@ #include "gomo.h" #ifndef INCLUDE_VAR_H - #include "var.h" + #include "var.h" +#endif +#ifdef OUTTA_CACHE + #include "outtacache.h" #endif #ifdef FreeBSD - #include <machine/limits.h> + #include <machine/limits.h> #else - #include <limits.h> + #include <limits.h> #endif #endif /* INCLUDE_BBS_H */ diff --git a/pttbbs/include/outtacache.h b/pttbbs/include/outtacache.h new file mode 100644 index 00000000..90756cde --- /dev/null +++ b/pttbbs/include/outtacache.h @@ -0,0 +1,28 @@ +#ifndef INCLUDE_OUTTACACHE_H +#define INCLUDE_OUTTACACHE_H + +#define CACHE_BUFSIZE (200*1024) +#define OC_HEADERLEN (sizeof(OCkey_t) + sizeof(int)) +#define OC_KEYLEN (sizeof(OCkey_t)) +#define OC_pidadd 10000000 +#define OC_msto 5111 +#define OC_mtos 5112 + +typedef struct { + pid_t pid; + char cacheid; +} OCkey_t; + +typedef struct { + OCkey_t key; + int length; + char buf[CACHE_BUFSIZE]; +} OCbuf_t; + + +typedef struct { + time_t mtime; + OCbuf_t data; +} OCstore_t; + +#endif diff --git a/pttbbs/include/proto.h b/pttbbs/include/proto.h index 47f45517..858f0a8b 100644 --- a/pttbbs/include/proto.h +++ b/pttbbs/include/proto.h @@ -1,4 +1,4 @@ -/* $Id: proto.h,v 1.25 2002/08/06 09:02:59 in2 Exp $ */ +/* $Id: proto.h,v 1.26 2002/08/17 12:31:55 in2 Exp $ */ #ifndef INCLUDE_PROTO_H #define INCLUDE_PROTO_H @@ -118,11 +118,11 @@ int get_fileheader_cache(int bid, char *direct, fileheader_t *headers, void *attach_shm(int shmkey, int shmsize); void attach_SHM(void); #ifdef OUTTA_CACHE -void outta_swapout(void **ptr, int length, char cacheid); -void outta_swapin(void **ptr, int length, char cacheid); +void *outta_malloc(size_t size, char id); +void outta_swapout(void **inptr); +void *outta_swapin(void **inptr, char cacheid); #endif - /* cal */ int give_tax(int money); int vice(int money, char* item); diff --git a/pttbbs/util/.cvsignore b/pttbbs/util/.cvsignore index d33e906f..c72037ba 100644 --- a/pttbbs/util/.cvsignore +++ b/pttbbs/util/.cvsignore @@ -44,3 +44,5 @@ shmctl mdclean splitpasswd indexuser +cacheserver +localserver diff --git a/pttbbs/util/Makefile b/pttbbs/util/Makefile index 2a56cc0e..f704a564 100644 --- a/pttbbs/util/Makefile +++ b/pttbbs/util/Makefile @@ -1,4 +1,4 @@ -# $Id: Makefile,v 1.17 2002/08/15 09:44:36 in2 Exp $ +# $Id: Makefile,v 1.18 2002/08/17 12:31:56 in2 Exp $ BBSHOME?=$(HOME) OSTYPE!=uname @@ -30,7 +30,8 @@ CPROGS= bbsmail BM_money post account birth deluserfile expire mandex\ poststat showboard antispam countalldice webgrep bbsrf\ initbbs outmail xchatd userlist tunepasswd buildir reaper shmsweep\ merge_passwd merge_board inndBM buildAnnounce rmuid \ - toplazyBM jungo toplazyBBM shmctl mdclean splitpasswd indexuser + toplazyBM jungo toplazyBBM shmctl mdclean splitpasswd indexuser \ + cacheserver localserver testoc PROGS= $(CPROGS) BM_money.sh backpasswd.sh mailog.sh opendice.sh\ openticket.sh stock.sh topsong.sh weather.sh stock.perl weather.perl\ @@ -168,6 +169,15 @@ mdclean: mdclean.c splitpasswd: splitpasswd.c $(CC) $(CFLAGS) -o $@ $@.c +cacheserver: cacheserver.c + $(CC) $(CFLAGS) -I/usr/local/include -lavltree -L/usr/local/lib -o $@ $@.c + +localserver: localserver.c + $(CC) $(CFLAGS) -o $@ $@.c + +testoc: testoc.c + $(CC) $(CFLAGS) -o $@ $@.c + install: $(PROGS) install -d $(BBSHOME)/bin/ install -c -m 755 $(PROGS) $(BBSHOME)/bin/ diff --git a/pttbbs/util/cacheserver.c b/pttbbs/util/cacheserver.c new file mode 100644 index 00000000..14fe5909 --- /dev/null +++ b/pttbbs/util/cacheserver.c @@ -0,0 +1,120 @@ +#include "bbs.h" +#include <err.h> +#include <avltree.h> + +int acceptone(int port); +void usage(void); +ssize_t Read(int fd, void *buf, size_t nbytes); + +int main(int argc, char **argv) +{ + int sfd, len; + int port = -1; + char ch; + OCbuf_t OCbuf; + + AVL_IX_DESC ix; + AVL_IX_REC pe; + OCstore_t *store; + avl_create_index(&ix, AVL_COUNT_DUPS, OC_KEYLEN); + + while( (ch = getopt(argc, argv, "p:")) != -1 ) + switch( ch ){ + case 'p': + port = atoi(optarg); + break; + } + if( port == -1 ) + usage(); + + sfd = acceptone(port); + while( Read(sfd, &len, sizeof(len)) > 0 ){ + printf("reading %d bytes\n", len); + Read(sfd, &OCbuf, len); + printf("read! pid: %d\n", OCbuf.key.pid); + + memset(&pe, 0, sizeof(pe)); + if( OCbuf.key.pid <= 1 ){ + /* garbage collection */ + } + else if( OCbuf.key.pid < OC_pidadd ){ + /* store */ + puts("swapin"); + + len = OC_HEADERLEN + OCbuf.length; + store = (OCstore_t *)malloc(sizeof(time_t) + len); + store->mtime = time(NULL); + memcpy(&(store->data), &OCbuf, len); + + pe.recptr = (void *)store; + memcpy(pe.key, &OCbuf.key, OC_KEYLEN); + if( avl_add_key(&pe, &ix) != AVL_IX_OK ) + puts("add key error"); + } + else { + OCbuf.key.pid -= OC_pidadd; + memcpy(pe.key, &OCbuf.key, OC_KEYLEN); + if( avl_find_key(&pe, &ix) == AVL_IX_OK ){ + store = (OCstore_t *)pe.recptr; + + len = store->data.length + OC_HEADERLEN; + write(sfd, &len, sizeof(len)); + write(sfd, &(store->data), len); + free(store); + if( avl_delete_key(&pe, &ix) != AVL_IX_OK ) + puts("delete key error"); + } + else + puts("error"); + } + } + return 0; +} + +int acceptone(int port) +{ + int sockfd, val, cfd, len; + struct sockaddr_in servaddr, clientaddr; + + if( (sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0 ) + err(1, NULL); + setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, (char *)&val, sizeof(val)); + + bzero(&servaddr, sizeof(servaddr)); + servaddr.sin_family = AF_INET; + servaddr.sin_addr.s_addr = htonl(INADDR_ANY); + servaddr.sin_port = htons(port); + if( bind(sockfd, (struct sockaddr *)&servaddr, sizeof(servaddr)) < 0 ) + err(1, NULL); + if( listen(sockfd, 5) < 0 ) + err(1, NULL); + + len = sizeof(struct sockaddr_in); + + if( (cfd = accept(sockfd, (struct sockaddr *)&clientaddr, &len)) < 0 ) + err(1, NULL); + + close(sockfd); + return cfd; +} + +void usage(void) +{ + fprintf(stderr, + "usage:\tcacheserver [options]\n" + "-p port\tlistenport\n"); + exit(0); +} + +ssize_t Read(int fd, void *BUF, size_t nbytes) +{ + char *buf = (char *)BUF; + size_t thisgot, totalgot = nbytes; + while( nbytes > 0 ){ + if( (thisgot = read(fd, buf, nbytes)) <= 0 ) + err(1, "read from socket: "); + nbytes -= thisgot; + buf += thisgot; + } + return totalgot; +} diff --git a/pttbbs/util/localserver.c b/pttbbs/util/localserver.c new file mode 100644 index 00000000..eb90bd6f --- /dev/null +++ b/pttbbs/util/localserver.c @@ -0,0 +1,116 @@ +#include "bbs.h" +#include <err.h> + +void usage(void); +int connectserver(char *, int); +void listennetwork(int, int); +void listenmsgqueue(int, int); + +int main(int argc, char **argv) +{ + char *host = NULL; + int port = 0, ch, sfd, msto, mtos; + pid_t pid; + while( (ch = getopt(argc, argv, "s:p:")) != -1 ) + switch( ch ){ + case 's': + host = strdup(optarg); + break; + case 'p': + port = atoi(optarg); + break; + default: + usage(); + } + + if( host == NULL || port == 0 ) + usage(); + + printf("connecting to server %s:%d\n", host, port); + sfd = connectserver(host, port); + puts("connected"); + + puts("attaching message queue"); + if( (msto = msgget(OC_msto, 0600 | IPC_CREAT)) < 0 ) + err(1, "msgget OC_msto"); + if( (mtos = msgget(OC_mtos, 0600 | IPC_CREAT)) < 0 ) + err(1, "msgget OC_mtos"); + puts("attached"); + + if( (pid = fork()) < 0 ) + err(1, "fork()"); + else if( pid == 0 ) + listennetwork(sfd, msto); + listenmsgqueue(sfd, mtos); + + return 0; +} + +void usage(void) +{ + fprintf(stderr, "usage:\tlocalserver -s host -p port\n"); + exit(0); +} + +int connectserver(char *host, int port) +{ + struct sockaddr_in servaddr; + int fd; + + if( (fd = socket(AF_INET, SOCK_STREAM, 0)) < 0 ) + err(1, "socket"); + bzero(&servaddr, sizeof(servaddr)); + servaddr.sin_family = AF_INET; + inet_pton(AF_INET, host, &servaddr.sin_addr); + servaddr.sin_port = htons(port); + if( connect(fd, (struct sockaddr *)&servaddr, sizeof(servaddr)) < 0 ) + err(1, "connect"); + return fd; +} + +void listennetwork(int netfd, int msgfd) +{ + int len; + char buf[CACHE_BUFSIZE]; + printf("(%d)listening network %d => message queue %d\n", + getpid(), netfd, msgfd); + while( Read(netfd, &len, 4) > 0 ){ + if( Read(netfd, buf, len) < 0 ) + err(1, "(network)read()"); + if( msgsnd(msgfd, buf, len, 0) < 0 ) + err(1, "(network)msgsnd()"); + } + exit(0); +} + +void listenmsgqueue(int netfd, int msgfd) +{ + char buf[CACHE_BUFSIZE]; + OCbuf_t *ptr; + int len; + printf("(%d)listening message queue %d => network %d\n", + getpid(), msgfd, netfd); + while( msgrcv(msgfd, buf, CACHE_BUFSIZE, 0, 0) > 0 ){ + ptr = (OCbuf_t *)buf; + len = ptr->length + OC_HEADERLEN; + if( write(netfd, &len, sizeof(len)) < 0 || + write(netfd, ptr, ptr->length + OC_HEADERLEN) < 0 ) + err(1, "(msgqueue)write()"); + } + err(1, "(msgqueue)msgrcv()"); + exit(0); +} + +ssize_t Read(int fd, void *BUF, size_t nbytes) +{ + char *buf = (char *)BUF; + size_t thisgot, totalgot = nbytes; + while( nbytes > 0 ){ + if( (thisgot = read(fd, buf, nbytes)) <= 0 ) + err(1, "read from socket: "); + nbytes -= thisgot; + buf += thisgot; + } + return totalgot; +} + -- cgit v1.2.3 From 26d85b85993bcb0ae33989edf915b4e9034f3d5b Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Mon, 19 Aug 2002 14:46:46 +0000 Subject: cacheserver.c git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@476 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/cacheserver.c | 73 +++++++++++++++++++++++++++++------------------ 1 file changed, 46 insertions(+), 27 deletions(-) diff --git a/pttbbs/util/cacheserver.c b/pttbbs/util/cacheserver.c index 14fe5909..cc0e36e3 100644 --- a/pttbbs/util/cacheserver.c +++ b/pttbbs/util/cacheserver.c @@ -2,9 +2,22 @@ #include <err.h> #include <avltree.h> -int acceptone(int port); +int toaccept(int port); void usage(void); ssize_t Read(int fd, void *buf, size_t nbytes); +ssize_t Write(int fd, void *BUF, size_t nbytes) +{ + char *buf = (char *)BUF; + size_t thisgot, totalgot = nbytes; + while( nbytes > 0 ){ + if( (thisgot = write(fd, buf, nbytes)) <= 0 ) + err(1, "read from socket: "); + nbytes -= thisgot; + buf += thisgot; + } + return totalgot; +} + int main(int argc, char **argv) { @@ -16,7 +29,8 @@ int main(int argc, char **argv) AVL_IX_DESC ix; AVL_IX_REC pe; OCstore_t *store; - avl_create_index(&ix, AVL_COUNT_DUPS, OC_KEYLEN); + //avl_create_index(&ix, AVL_COUNT_DUPS, OC_KEYLEN); + avl_create_index(&ix, AVL_COUNT_DUPS, 5); while( (ch = getopt(argc, argv, "p:")) != -1 ) switch( ch ){ @@ -27,8 +41,9 @@ int main(int argc, char **argv) if( port == -1 ) usage(); - sfd = acceptone(port); - while( Read(sfd, &len, sizeof(len)) > 0 ){ + while( 1 ){ + sfd = toaccept(port); + Read(sfd, &len, sizeof(len)); printf("reading %d bytes\n", len); Read(sfd, &OCbuf, len); printf("read! pid: %d\n", OCbuf.key.pid); @@ -58,8 +73,8 @@ int main(int argc, char **argv) store = (OCstore_t *)pe.recptr; len = store->data.length + OC_HEADERLEN; - write(sfd, &len, sizeof(len)); - write(sfd, &(store->data), len); + Write(sfd, &len, sizeof(len)); + Write(sfd, &(store->data), len); free(store); if( avl_delete_key(&pe, &ix) != AVL_IX_OK ) puts("delete key error"); @@ -67,34 +82,38 @@ int main(int argc, char **argv) else puts("error"); } + close(sfd); } return 0; } -int acceptone(int port) +int toaccept(int port) { - int sockfd, val, cfd, len; + static int sockfd = 0, len; + int cfd, val; struct sockaddr_in servaddr, clientaddr; + + if( sockfd == 0 ){ + if( (sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0 ) + err(1, NULL); + setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, (char *)&val, sizeof(val)); + setsockopt(sockfd, SOL_SOCKET, SO_REUSEPORT, (char *)&val, sizeof(val)); + + bzero(&servaddr, sizeof(servaddr)); + servaddr.sin_family = AF_INET; + servaddr.sin_addr.s_addr = htonl(INADDR_ANY); + servaddr.sin_port = htons(port); + if( bind(sockfd, (struct sockaddr *)&servaddr, sizeof(servaddr)) < 0 ) + err(1, NULL); + if( listen(sockfd, 5) < 0 ) + err(1, NULL); + + len = sizeof(struct sockaddr_in); + } - if( (sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0 ) - err(1, NULL); - setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, (char *)&val, sizeof(val)); - - bzero(&servaddr, sizeof(servaddr)); - servaddr.sin_family = AF_INET; - servaddr.sin_addr.s_addr = htonl(INADDR_ANY); - servaddr.sin_port = htons(port); - if( bind(sockfd, (struct sockaddr *)&servaddr, sizeof(servaddr)) < 0 ) - err(1, NULL); - if( listen(sockfd, 5) < 0 ) - err(1, NULL); - - len = sizeof(struct sockaddr_in); - - if( (cfd = accept(sockfd, (struct sockaddr *)&clientaddr, &len)) < 0 ) - err(1, NULL); + while( (cfd = accept(sockfd, (struct sockaddr *)&clientaddr, &len)) <= 0 ) + ; - close(sockfd); return cfd; } @@ -109,7 +128,7 @@ void usage(void) ssize_t Read(int fd, void *BUF, size_t nbytes) { char *buf = (char *)BUF; - size_t thisgot, totalgot = nbytes; + ssize_t thisgot, totalgot = nbytes; while( nbytes > 0 ){ if( (thisgot = read(fd, buf, nbytes)) <= 0 ) err(1, "read from socket: "); -- cgit v1.2.3 From 1873ff20ac972d82f1ab43f68e2a97999420cc66 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Mon, 19 Aug 2002 14:47:41 +0000 Subject: cache server2 git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@477 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/board.c | 47 ++++++++++++----------- pttbbs/mbbsd/cache.c | 105 +++++++++++++++++++++++++++++++++++++++++---------- 2 files changed, 111 insertions(+), 41 deletions(-) diff --git a/pttbbs/mbbsd/board.c b/pttbbs/mbbsd/board.c index 2f2dff2b..346de070 100644 --- a/pttbbs/mbbsd/board.c +++ b/pttbbs/mbbsd/board.c @@ -1,4 +1,4 @@ -/* $Id: board.c,v 1.50 2002/08/07 10:00:13 in2 Exp $ */ +/* $Id: board.c,v 1.51 2002/08/19 14:47:40 in2 Exp $ */ #include "bbs.h" #define BRC_STRLEN 15 /* Length of board name */ #define BRC_MAXSIZE 24576 @@ -226,10 +226,6 @@ static boardstat_t *nbrd = NULL; #define STR_BBSRC ".bbsrc" #define STR_FAV ".fav" -#ifdef OUTTA_CACHE -int zaplength, favlength; -#endif - void init_brdbuf() { @@ -239,11 +235,18 @@ init_brdbuf() /* MAXBOARDS ==> 至多看得見 32 個新板 */ n = numboards + 32; size = n * sizeof(int); +#ifdef OUTTA_CACHE + zapbuf = (int *)outta_malloc(size, 'z'); + favbuf = (int *)outta_malloc(size + sizeof(int), 'f'); +#else zapbuf = (int *)malloc(size); favbuf = (int *)malloc(size + sizeof(int)); +#endif +#if 0 favbuf[0] = 0x5c4d3e; /* for check memory */ ++favbuf; +#endif memset(favbuf, 0, size); @@ -265,8 +268,8 @@ init_brdbuf() brc_expire_time = login_start_time - 365 * 86400; #ifdef OUTTA_CACHE - outta_swapout((void **)&favbuf, (favlength = size + 4), 'f'); - outta_swapout((void **)&zapbuf, (zaplength = size), 'z'); + outta_swapout((void **)&favbuf); + outta_swapout((void **)&zapbuf); #endif } @@ -280,8 +283,8 @@ save_brdbuf() return; reentrant = 1; #ifdef OUTTA_CACHE - outta_swapin((void **)&favbuf, favlength, 'f'); - outta_swapin((void **)&zapbuf, zaplength, 'z'); + outta_swapin((void **)&favbuf, 'f'); + outta_swapin((void **)&zapbuf, 'z'); #endif if (!zapbuf) return; @@ -291,12 +294,14 @@ save_brdbuf() write(fd, zapbuf, size); close(fd); } +#if 0 if (favbuf[-1] != 0x5c4d3e) { FILE *fp = fopen(BBSHOME "/log/memorybad", "a"); fprintf(fp, "%s %s %d\n", cuser.userid, Cdatelite(&now), favbuf[-1]); fclose(fp); return; } +#endif setuserfile(fname, STR_FAV); if ((fd = open(fname, O_WRONLY | O_CREAT, 0600)) != -1) { size = numboards * sizeof(int); @@ -463,7 +468,7 @@ load_boards(char *key) brdnum = 0; if (class_bid <= 0) { nbrdlength = numboards * sizeof(boardstat_t); - nbrd = (boardstat_t *) malloc(nbrdlength); + nbrd = (boardstat_t *) outta_malloc(nbrdlength, 'b'); for (i = 0; i < numboards; i++) { if ((bptr = SHM->bsorted[type][i]) == NULL) continue; @@ -482,7 +487,7 @@ load_boards(char *key) } } else { nbrdlength = bptr->childcount * sizeof(boardstat_t); - nbrd = (boardstat_t *) malloc(nbrdlength); + nbrd = (boardstat_t *) outta_malloc(nbrdlength, 'b'); for (bptr = bptr->firstchild[type]; bptr != (boardheader_t *) ~ 0; bptr = bptr->next[type]) { n = (int)(bptr - bcache); @@ -729,9 +734,9 @@ choose_board(int newflag) static char depth = 0; ++depth; if( favbuf == NULL ) - outta_swapin((void **)&favbuf, favlength, 'f'); + outta_swapin((void **)&favbuf, 'f'); if( zapbuf == NULL ) - outta_swapin((void **)&zapbuf, zaplength, 'z'); + outta_swapin((void **)&zapbuf, 'z'); #endif setutmpmode(newflag ? READNEW : READBRD); brdnum = 0; @@ -1042,15 +1047,15 @@ choose_board(int newflag) if (!(ptr->myattr & BRD_ZAP)) zapbuf[ptr->bid - 1] = now; #ifdef OUTTA_CACHE - outta_swapout((void **)&favbuf, favlength, 'f'); - outta_swapout((void **)&zapbuf, zaplength, 'z'); - outta_swapout((void **)&nbrd, nbrdlength, 'b'); + outta_swapout((void **)&favbuf); + outta_swapout((void **)&zapbuf); + outta_swapout((void **)&nbrd); #endif Read(); #ifdef OUTTA_CACHE - outta_swapin((void **)&favbuf, favlength, 'f'); - outta_swapin((void **)&zapbuf, zaplength, 'z'); - outta_swapin((void **)&nbrd, nbrdlength, 'b'); + outta_swapin((void **)&favbuf, 'f'); + outta_swapin((void **)&zapbuf, 'z'); + outta_swapin((void **)&nbrd, 'b'); ptr = &nbrd[num]; #endif check_newpost(ptr); @@ -1101,8 +1106,8 @@ choose_board(int newflag) free(nbrd); #ifdef OUTTA_CACHE if( --depth == 0 ){ - outta_swapout((void **)&favbuf, favlength, 'f'); - outta_swapout((void **)&zapbuf, zaplength, 'z'); + outta_swapout((void **)&favbuf); + outta_swapout((void **)&zapbuf); } #endif } diff --git a/pttbbs/mbbsd/cache.c b/pttbbs/mbbsd/cache.c index 27202de7..c824b4f6 100644 --- a/pttbbs/mbbsd/cache.c +++ b/pttbbs/mbbsd/cache.c @@ -1,4 +1,4 @@ -/* $Id: cache.c,v 1.47 2002/08/07 09:32:38 in2 Exp $ */ +/* $Id: cache.c,v 1.48 2002/08/19 14:47:41 in2 Exp $ */ #include "bbs.h" #ifndef __FreeBSD__ @@ -1131,35 +1131,100 @@ mdcacheopen(char *fpath) #endif #ifdef OUTTA_CACHE -void outta_swapout(void **ptr, int length, char cacheid) +#include <err.h> +static ssize_t Read(int fd, void *BUF, size_t nbytes) { - char fn[64]; + char *buf = (char *)BUF; + ssize_t thisgot, totalgot = nbytes; + while( nbytes > 0 ){ + if( (thisgot = read(fd, buf, nbytes)) <= 0 ) + err(1, "read from socket: "); + nbytes -= thisgot; + buf += thisgot; + } + return totalgot; +} + +static ssize_t Write(int fd, void *BUF, size_t nbytes) +{ + char *buf = (char *)BUF; + ssize_t thisgot, totalgot = nbytes; + while( nbytes > 0 ){ + if( (thisgot = write(fd, buf, nbytes)) <= 0 ) + err(1, "read from socket: "); + nbytes -= thisgot; + buf += thisgot; + } + return totalgot; +} + +int connectserver(char *host, int port) +{ + struct sockaddr_in servaddr; int fd; + + if( (fd = socket(AF_INET, SOCK_STREAM, 0)) < 0 ) + err(1, "socket"); + bzero(&servaddr, sizeof(servaddr)); + servaddr.sin_family = AF_INET; + inet_pton(AF_INET, host, &servaddr.sin_addr); + servaddr.sin_port = htons(port); + if( connect(fd, (struct sockaddr *)&servaddr, sizeof(servaddr)) < 0 ) + err(1, "connect"); + return fd; +} + +void *outta_malloc(size_t size, char id) +{ + OCbuf_t *ptr = (OCbuf_t *)malloc(OC_HEADERLEN + size); #ifdef DEBUG - vmsg("swap out (%c) %d bytes", cacheid, length); + vmsg("outta_malloc(%d, %c)", size, id); #endif - sprintf(fn, "cache/" MYHOSTNAME "%c%d", cacheid, currpid); - if( (fd = open(fn, O_WRONLY | O_CREAT, 0600)) < 0 ) - abort_bbs(0); - write(fd, *ptr, length); + ptr->key.pid = getpid(); + ptr->key.cacheid = id; + ptr->length = size; + return ptr->buf; +} + +void outta_swapout(void **inptr) +{ + OCbuf_t *ptr = (OCbuf_t *)(*inptr - OC_HEADERLEN); + int fd, len; + fd = connectserver("10.2.1.2", 1477); + len = ptr->length + OC_HEADERLEN; +#ifdef DEBUG + vmsg("outta_swapout(%d)", len); +#endif + Write(fd, &len, sizeof(len)); + Write(fd, ptr, len); close(fd); - free(*ptr); - *ptr = NULL; + free(ptr); + *inptr = NULL; } -void outta_swapin(void **ptr, int length, char cacheid) +void *outta_swapin(void **inptr, char cacheid) { - char fn[64]; - int fd; + char buf[OC_HEADERLEN]; + OCbuf_t *ptr = (OCbuf_t *)buf; + int fd, len; + + fd = connectserver("10.2.1.2", 1477); + ptr->key.pid = getpid() + OC_pidadd; + ptr->key.cacheid = cacheid; + ptr->length = 0; + len = OC_HEADERLEN; + Write(fd, &len, sizeof(len)); + Write(fd, ptr, OC_HEADERLEN); + + Read(fd, &len, sizeof(len)); #ifdef DEBUG - vmsg("swap in (%c) %d bytes", cacheid, length); + vmsg("outta_swapin(%d)", len); #endif - sprintf(fn, "cache/" MYHOSTNAME "%c%d", cacheid, currpid); - if( (fd = open(fn, O_RDONLY)) < 0 ) - abort_bbs(0); - *ptr = (void *)malloc(length); - read(fd, *ptr, length); + ptr = (OCbuf_t *)malloc(len); + Read(fd, ptr, len); close(fd); - unlink(fn); + + return (*inptr = ptr->buf); } + #endif -- cgit v1.2.3 From 29e05c28af899e11562f3dddd40c4a4f0c302633 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Mon, 19 Aug 2002 14:53:05 +0000 Subject: fix last commit bug git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@478 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/board.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/pttbbs/mbbsd/board.c b/pttbbs/mbbsd/board.c index 346de070..59dbd68a 100644 --- a/pttbbs/mbbsd/board.c +++ b/pttbbs/mbbsd/board.c @@ -1,4 +1,4 @@ -/* $Id: board.c,v 1.51 2002/08/19 14:47:40 in2 Exp $ */ +/* $Id: board.c,v 1.52 2002/08/19 14:53:05 in2 Exp $ */ #include "bbs.h" #define BRC_STRLEN 15 /* Length of board name */ #define BRC_MAXSIZE 24576 @@ -468,7 +468,11 @@ load_boards(char *key) brdnum = 0; if (class_bid <= 0) { nbrdlength = numboards * sizeof(boardstat_t); +#ifdef OUTTA_CACHE nbrd = (boardstat_t *) outta_malloc(nbrdlength, 'b'); +#else + nbrd = (boardstat_t *) malloc(nbrdlength); +#endif for (i = 0; i < numboards; i++) { if ((bptr = SHM->bsorted[type][i]) == NULL) continue; @@ -487,7 +491,11 @@ load_boards(char *key) } } else { nbrdlength = bptr->childcount * sizeof(boardstat_t); +#ifdef OUTTA_CACHE nbrd = (boardstat_t *) outta_malloc(nbrdlength, 'b'); +#else + nbrd = (boardstat_t *) malloc(nbrdlength); +#endif for (bptr = bptr->firstchild[type]; bptr != (boardheader_t *) ~ 0; bptr = bptr->next[type]) { n = (int)(bptr - bcache); -- cgit v1.2.3 From f3e44b85461086173ad79e59670a3e1f11f36f92 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Tue, 20 Aug 2002 02:40:30 +0000 Subject: larger cachesize git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@479 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/include/outtacache.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pttbbs/include/outtacache.h b/pttbbs/include/outtacache.h index 90756cde..6865935b 100644 --- a/pttbbs/include/outtacache.h +++ b/pttbbs/include/outtacache.h @@ -1,7 +1,7 @@ #ifndef INCLUDE_OUTTACACHE_H #define INCLUDE_OUTTACACHE_H -#define CACHE_BUFSIZE (200*1024) +#define CACHE_BUFSIZE (20000000) #define OC_HEADERLEN (sizeof(OCkey_t) + sizeof(int)) #define OC_KEYLEN (sizeof(OCkey_t)) #define OC_pidadd 10000000 -- cgit v1.2.3 From 21e227425c79889535334afc0cf34ce90824cd08 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Tue, 20 Aug 2002 02:42:36 +0000 Subject: remove OUTTA_CACHE git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@480 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/include/bbs.h | 3 - pttbbs/include/outtacache.h | 28 -------- pttbbs/include/proto.h | 7 +- pttbbs/mbbsd/board.c | 54 +-------------- pttbbs/mbbsd/cache.c | 164 +------------------------------------------- pttbbs/mbbsd/edit.c | 5 +- pttbbs/mbbsd/more.c | 6 +- pttbbs/mbbsd/voteboard.c | 5 +- pttbbs/util/.cvsignore | 2 - pttbbs/util/Makefile | 14 +--- pttbbs/util/cacheserver.c | 139 ------------------------------------- pttbbs/util/localserver.c | 116 ------------------------------- 12 files changed, 9 insertions(+), 534 deletions(-) delete mode 100644 pttbbs/include/outtacache.h delete mode 100644 pttbbs/util/cacheserver.c delete mode 100644 pttbbs/util/localserver.c diff --git a/pttbbs/include/bbs.h b/pttbbs/include/bbs.h index a56ee944..09ce1982 100644 --- a/pttbbs/include/bbs.h +++ b/pttbbs/include/bbs.h @@ -45,9 +45,6 @@ #ifndef INCLUDE_VAR_H #include "var.h" #endif -#ifdef OUTTA_CACHE - #include "outtacache.h" -#endif #ifdef FreeBSD #include <machine/limits.h> #else diff --git a/pttbbs/include/outtacache.h b/pttbbs/include/outtacache.h deleted file mode 100644 index 6865935b..00000000 --- a/pttbbs/include/outtacache.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef INCLUDE_OUTTACACHE_H -#define INCLUDE_OUTTACACHE_H - -#define CACHE_BUFSIZE (20000000) -#define OC_HEADERLEN (sizeof(OCkey_t) + sizeof(int)) -#define OC_KEYLEN (sizeof(OCkey_t)) -#define OC_pidadd 10000000 -#define OC_msto 5111 -#define OC_mtos 5112 - -typedef struct { - pid_t pid; - char cacheid; -} OCkey_t; - -typedef struct { - OCkey_t key; - int length; - char buf[CACHE_BUFSIZE]; -} OCbuf_t; - - -typedef struct { - time_t mtime; - OCbuf_t data; -} OCstore_t; - -#endif diff --git a/pttbbs/include/proto.h b/pttbbs/include/proto.h index 858f0a8b..fe8bad6c 100644 --- a/pttbbs/include/proto.h +++ b/pttbbs/include/proto.h @@ -1,4 +1,4 @@ -/* $Id: proto.h,v 1.26 2002/08/17 12:31:55 in2 Exp $ */ +/* $Id: proto.h,v 1.27 2002/08/20 02:42:36 in2 Exp $ */ #ifndef INCLUDE_PROTO_H #define INCLUDE_PROTO_H @@ -117,11 +117,6 @@ int get_fileheader_cache(int bid, char *direct, fileheader_t *headers, int recbase, int nlines); void *attach_shm(int shmkey, int shmsize); void attach_SHM(void); -#ifdef OUTTA_CACHE -void *outta_malloc(size_t size, char id); -void outta_swapout(void **inptr); -void *outta_swapin(void **inptr, char cacheid); -#endif /* cal */ int give_tax(int money); diff --git a/pttbbs/mbbsd/board.c b/pttbbs/mbbsd/board.c index 59dbd68a..350a482d 100644 --- a/pttbbs/mbbsd/board.c +++ b/pttbbs/mbbsd/board.c @@ -1,4 +1,4 @@ -/* $Id: board.c,v 1.52 2002/08/19 14:53:05 in2 Exp $ */ +/* $Id: board.c,v 1.53 2002/08/20 02:42:36 in2 Exp $ */ #include "bbs.h" #define BRC_STRLEN 15 /* Length of board name */ #define BRC_MAXSIZE 24576 @@ -235,18 +235,11 @@ init_brdbuf() /* MAXBOARDS ==> 至多看得見 32 個新板 */ n = numboards + 32; size = n * sizeof(int); -#ifdef OUTTA_CACHE - zapbuf = (int *)outta_malloc(size, 'z'); - favbuf = (int *)outta_malloc(size + sizeof(int), 'f'); -#else zapbuf = (int *)malloc(size); favbuf = (int *)malloc(size + sizeof(int)); -#endif -#if 0 favbuf[0] = 0x5c4d3e; /* for check memory */ ++favbuf; -#endif memset(favbuf, 0, size); @@ -266,11 +259,6 @@ init_brdbuf() favbuf[n] &= ~BRD_TAG; brc_expire_time = login_start_time - 365 * 86400; - -#ifdef OUTTA_CACHE - outta_swapout((void **)&favbuf); - outta_swapout((void **)&zapbuf); -#endif } void @@ -282,10 +270,7 @@ save_brdbuf() if ( reentrant ) return; reentrant = 1; -#ifdef OUTTA_CACHE - outta_swapin((void **)&favbuf, 'f'); - outta_swapin((void **)&zapbuf, 'z'); -#endif + if (!zapbuf) return; setuserfile(fname, STR_BBSRC); @@ -294,14 +279,12 @@ save_brdbuf() write(fd, zapbuf, size); close(fd); } -#if 0 if (favbuf[-1] != 0x5c4d3e) { FILE *fp = fopen(BBSHOME "/log/memorybad", "a"); fprintf(fp, "%s %s %d\n", cuser.userid, Cdatelite(&now), favbuf[-1]); fclose(fp); return; } -#endif setuserfile(fname, STR_FAV); if ((fd = open(fname, O_WRONLY | O_CREAT, 0600)) != -1) { size = numboards * sizeof(int); @@ -468,11 +451,7 @@ load_boards(char *key) brdnum = 0; if (class_bid <= 0) { nbrdlength = numboards * sizeof(boardstat_t); -#ifdef OUTTA_CACHE - nbrd = (boardstat_t *) outta_malloc(nbrdlength, 'b'); -#else nbrd = (boardstat_t *) malloc(nbrdlength); -#endif for (i = 0; i < numboards; i++) { if ((bptr = SHM->bsorted[type][i]) == NULL) continue; @@ -491,11 +470,7 @@ load_boards(char *key) } } else { nbrdlength = bptr->childcount * sizeof(boardstat_t); -#ifdef OUTTA_CACHE - nbrd = (boardstat_t *) outta_malloc(nbrdlength, 'b'); -#else nbrd = (boardstat_t *) malloc(nbrdlength); -#endif for (bptr = bptr->firstchild[type]; bptr != (boardheader_t *) ~ 0; bptr = bptr->next[type]) { n = (int)(bptr - bcache); @@ -738,14 +713,6 @@ choose_board(int newflag) char genbuf[200]; #endif -#ifdef OUTTA_CACHE - static char depth = 0; - ++depth; - if( favbuf == NULL ) - outta_swapin((void **)&favbuf, 'f'); - if( zapbuf == NULL ) - outta_swapin((void **)&zapbuf, 'z'); -#endif setutmpmode(newflag ? READNEW : READBRD); brdnum = 0; if (!cuser.userlevel) /* guest yank all boards */ @@ -1054,18 +1021,7 @@ choose_board(int newflag) board_visit_time = zapbuf[ptr->bid - 1]; if (!(ptr->myattr & BRD_ZAP)) zapbuf[ptr->bid - 1] = now; -#ifdef OUTTA_CACHE - outta_swapout((void **)&favbuf); - outta_swapout((void **)&zapbuf); - outta_swapout((void **)&nbrd); -#endif Read(); -#ifdef OUTTA_CACHE - outta_swapin((void **)&favbuf, 'f'); - outta_swapin((void **)&zapbuf, 'z'); - outta_swapin((void **)&nbrd, 'b'); - ptr = &nbrd[num]; -#endif check_newpost(ptr); head = -1; setutmpmode(newflag ? READNEW : READBRD); @@ -1112,12 +1068,6 @@ choose_board(int newflag) } } while (ch != 'q'); free(nbrd); -#ifdef OUTTA_CACHE - if( --depth == 0 ){ - outta_swapout((void **)&favbuf); - outta_swapout((void **)&zapbuf); - } -#endif } int diff --git a/pttbbs/mbbsd/cache.c b/pttbbs/mbbsd/cache.c index c824b4f6..7c4a1992 100644 --- a/pttbbs/mbbsd/cache.c +++ b/pttbbs/mbbsd/cache.c @@ -1,4 +1,4 @@ -/* $Id: cache.c,v 1.48 2002/08/19 14:47:41 in2 Exp $ */ +/* $Id: cache.c,v 1.49 2002/08/20 02:42:36 in2 Exp $ */ #include "bbs.h" #ifndef __FreeBSD__ @@ -1066,165 +1066,3 @@ hbflcheck(int bid, int uid) } return 1; } - -#ifdef MDCACHE -char * -cachepath(const char *fpath) -{ - static char cpath[128]; - char *ptr; - snprintf(cpath, sizeof(cpath), "cache/%s", fpath); - for (ptr = &cpath[6]; *ptr != 0; ++ptr) - if (*ptr == '/') - *ptr = '.'; - return cpath; -} - -int -updatemdcache(const char *CPATH, const char *fpath) -{ - /* - * save file to mdcache with *cpath and *fpath, return: -1 if error - * else the fd - */ - int len, sourcefd, targetfd; - char buf[1024], *cpath; - cpath = (CPATH == NULL) ? cachepath(fpath) : (char *)CPATH; - if ((sourcefd = open(fpath, O_RDONLY)) < 0) - return -1; - if ((targetfd = open(cpath, O_RDWR | O_CREAT | O_TRUNC, 0600)) < 0) - /* md is full? */ - return -1; - while ((len = read(sourcefd, buf, sizeof(buf))) > 0) - if (write(targetfd, buf, len) < len) { - /* md is full? */ - close(targetfd); - unlink(cpath); - lseek(sourcefd, 0, SEEK_SET); - return sourcefd; - } - close(sourcefd); - lseek(targetfd, 0, SEEK_SET); - return targetfd; -} - -int -mdcacheopen(char *fpath) -{ - int fd; - char *cpath; - if (strncmp(fpath, "boards/", 7) && strncmp(fpath, "etc/", 4)) - return open(fpath, O_RDONLY); - -#ifdef MDCACHEHITRATE - ++GLOBE[0]; -#endif - if ((fd = open((cpath = cachepath(fpath)), O_RDONLY)) < 0) - return updatemdcache(cpath, fpath); -#ifdef MDCACHEHITRATE - else - ++GLOBE[1]; -#endif - - return fd; -} -#endif - -#ifdef OUTTA_CACHE -#include <err.h> -static ssize_t Read(int fd, void *BUF, size_t nbytes) -{ - char *buf = (char *)BUF; - ssize_t thisgot, totalgot = nbytes; - while( nbytes > 0 ){ - if( (thisgot = read(fd, buf, nbytes)) <= 0 ) - err(1, "read from socket: "); - nbytes -= thisgot; - buf += thisgot; - } - return totalgot; -} - -static ssize_t Write(int fd, void *BUF, size_t nbytes) -{ - char *buf = (char *)BUF; - ssize_t thisgot, totalgot = nbytes; - while( nbytes > 0 ){ - if( (thisgot = write(fd, buf, nbytes)) <= 0 ) - err(1, "read from socket: "); - nbytes -= thisgot; - buf += thisgot; - } - return totalgot; -} - -int connectserver(char *host, int port) -{ - struct sockaddr_in servaddr; - int fd; - - if( (fd = socket(AF_INET, SOCK_STREAM, 0)) < 0 ) - err(1, "socket"); - bzero(&servaddr, sizeof(servaddr)); - servaddr.sin_family = AF_INET; - inet_pton(AF_INET, host, &servaddr.sin_addr); - servaddr.sin_port = htons(port); - if( connect(fd, (struct sockaddr *)&servaddr, sizeof(servaddr)) < 0 ) - err(1, "connect"); - return fd; -} - -void *outta_malloc(size_t size, char id) -{ - OCbuf_t *ptr = (OCbuf_t *)malloc(OC_HEADERLEN + size); -#ifdef DEBUG - vmsg("outta_malloc(%d, %c)", size, id); -#endif - ptr->key.pid = getpid(); - ptr->key.cacheid = id; - ptr->length = size; - return ptr->buf; -} - -void outta_swapout(void **inptr) -{ - OCbuf_t *ptr = (OCbuf_t *)(*inptr - OC_HEADERLEN); - int fd, len; - fd = connectserver("10.2.1.2", 1477); - len = ptr->length + OC_HEADERLEN; -#ifdef DEBUG - vmsg("outta_swapout(%d)", len); -#endif - Write(fd, &len, sizeof(len)); - Write(fd, ptr, len); - close(fd); - free(ptr); - *inptr = NULL; -} - -void *outta_swapin(void **inptr, char cacheid) -{ - char buf[OC_HEADERLEN]; - OCbuf_t *ptr = (OCbuf_t *)buf; - int fd, len; - - fd = connectserver("10.2.1.2", 1477); - ptr->key.pid = getpid() + OC_pidadd; - ptr->key.cacheid = cacheid; - ptr->length = 0; - len = OC_HEADERLEN; - Write(fd, &len, sizeof(len)); - Write(fd, ptr, OC_HEADERLEN); - - Read(fd, &len, sizeof(len)); -#ifdef DEBUG - vmsg("outta_swapin(%d)", len); -#endif - ptr = (OCbuf_t *)malloc(len); - Read(fd, ptr, len); - close(fd); - - return (*inptr = ptr->buf); -} - -#endif diff --git a/pttbbs/mbbsd/edit.c b/pttbbs/mbbsd/edit.c index ad210b12..589be70d 100644 --- a/pttbbs/mbbsd/edit.c +++ b/pttbbs/mbbsd/edit.c @@ -1,4 +1,4 @@ -/* $Id: edit.c,v 1.15 2002/07/22 19:02:00 in2 Exp $ */ +/* $Id: edit.c,v 1.16 2002/08/20 02:42:36 in2 Exp $ */ #include "bbs.h" typedef struct textline_t { struct textline_t *prev; @@ -1025,9 +1025,6 @@ write_file(char *fpath, int saveheader, int *islocal) } fclose(fp); -#ifdef MDCACHE - close(updatemdcache(NULL, fpath)); -#endif if (local_article && (currstat == POSTING)) return 0; return 0; diff --git a/pttbbs/mbbsd/more.c b/pttbbs/mbbsd/more.c index d7508ce4..fc3434ba 100644 --- a/pttbbs/mbbsd/more.c +++ b/pttbbs/mbbsd/more.c @@ -1,4 +1,4 @@ -/* $Id: more.c,v 1.19 2002/07/27 10:55:30 kcwu Exp $ */ +/* $Id: more.c,v 1.20 2002/08/20 02:42:36 in2 Exp $ */ #include "bbs.h" #define MORE_BUFSIZE 4096 #define MORE_WINSIZE 4096 @@ -156,11 +156,7 @@ more(char *fpath, int promptend) search_char0 = *search_str; *search_str = 0; -#ifdef MDCACHE - fd = mdcacheopen(fpath); -#else fd = open(fpath, O_RDONLY, 0600); -#endif if (fd < 0) return -1; diff --git a/pttbbs/mbbsd/voteboard.c b/pttbbs/mbbsd/voteboard.c index 27ca0bd3..76bf0cbc 100644 --- a/pttbbs/mbbsd/voteboard.c +++ b/pttbbs/mbbsd/voteboard.c @@ -1,4 +1,4 @@ -/* $Id: voteboard.c,v 1.13 2002/07/22 19:02:01 in2 Exp $ */ +/* $Id: voteboard.c,v 1.14 2002/08/20 02:42:36 in2 Exp $ */ #include "bbs.h" #define VOTEBOARD "NewBoard" @@ -170,9 +170,6 @@ do_voteboardreply(fileheader_t * fhdr) fclose(fo); unlink(oldfpath); rename(fpath, oldfpath); -#ifdef MDCACHE - close(updatemdcache(NULL, oldfpath)); -#endif } int diff --git a/pttbbs/util/.cvsignore b/pttbbs/util/.cvsignore index c72037ba..d33e906f 100644 --- a/pttbbs/util/.cvsignore +++ b/pttbbs/util/.cvsignore @@ -44,5 +44,3 @@ shmctl mdclean splitpasswd indexuser -cacheserver -localserver diff --git a/pttbbs/util/Makefile b/pttbbs/util/Makefile index f704a564..81f466a7 100644 --- a/pttbbs/util/Makefile +++ b/pttbbs/util/Makefile @@ -1,4 +1,4 @@ -# $Id: Makefile,v 1.18 2002/08/17 12:31:56 in2 Exp $ +# $Id: Makefile,v 1.19 2002/08/20 02:42:36 in2 Exp $ BBSHOME?=$(HOME) OSTYPE!=uname @@ -30,8 +30,7 @@ CPROGS= bbsmail BM_money post account birth deluserfile expire mandex\ poststat showboard antispam countalldice webgrep bbsrf\ initbbs outmail xchatd userlist tunepasswd buildir reaper shmsweep\ merge_passwd merge_board inndBM buildAnnounce rmuid \ - toplazyBM jungo toplazyBBM shmctl mdclean splitpasswd indexuser \ - cacheserver localserver testoc + toplazyBM jungo toplazyBBM shmctl mdclean splitpasswd indexuser PROGS= $(CPROGS) BM_money.sh backpasswd.sh mailog.sh opendice.sh\ openticket.sh stock.sh topsong.sh weather.sh stock.perl weather.perl\ @@ -169,15 +168,6 @@ mdclean: mdclean.c splitpasswd: splitpasswd.c $(CC) $(CFLAGS) -o $@ $@.c -cacheserver: cacheserver.c - $(CC) $(CFLAGS) -I/usr/local/include -lavltree -L/usr/local/lib -o $@ $@.c - -localserver: localserver.c - $(CC) $(CFLAGS) -o $@ $@.c - -testoc: testoc.c - $(CC) $(CFLAGS) -o $@ $@.c - install: $(PROGS) install -d $(BBSHOME)/bin/ install -c -m 755 $(PROGS) $(BBSHOME)/bin/ diff --git a/pttbbs/util/cacheserver.c b/pttbbs/util/cacheserver.c deleted file mode 100644 index cc0e36e3..00000000 --- a/pttbbs/util/cacheserver.c +++ /dev/null @@ -1,139 +0,0 @@ -#include "bbs.h" -#include <err.h> -#include <avltree.h> - -int toaccept(int port); -void usage(void); -ssize_t Read(int fd, void *buf, size_t nbytes); -ssize_t Write(int fd, void *BUF, size_t nbytes) -{ - char *buf = (char *)BUF; - size_t thisgot, totalgot = nbytes; - while( nbytes > 0 ){ - if( (thisgot = write(fd, buf, nbytes)) <= 0 ) - err(1, "read from socket: "); - nbytes -= thisgot; - buf += thisgot; - } - return totalgot; -} - - -int main(int argc, char **argv) -{ - int sfd, len; - int port = -1; - char ch; - OCbuf_t OCbuf; - - AVL_IX_DESC ix; - AVL_IX_REC pe; - OCstore_t *store; - //avl_create_index(&ix, AVL_COUNT_DUPS, OC_KEYLEN); - avl_create_index(&ix, AVL_COUNT_DUPS, 5); - - while( (ch = getopt(argc, argv, "p:")) != -1 ) - switch( ch ){ - case 'p': - port = atoi(optarg); - break; - } - if( port == -1 ) - usage(); - - while( 1 ){ - sfd = toaccept(port); - Read(sfd, &len, sizeof(len)); - printf("reading %d bytes\n", len); - Read(sfd, &OCbuf, len); - printf("read! pid: %d\n", OCbuf.key.pid); - - memset(&pe, 0, sizeof(pe)); - if( OCbuf.key.pid <= 1 ){ - /* garbage collection */ - } - else if( OCbuf.key.pid < OC_pidadd ){ - /* store */ - puts("swapin"); - - len = OC_HEADERLEN + OCbuf.length; - store = (OCstore_t *)malloc(sizeof(time_t) + len); - store->mtime = time(NULL); - memcpy(&(store->data), &OCbuf, len); - - pe.recptr = (void *)store; - memcpy(pe.key, &OCbuf.key, OC_KEYLEN); - if( avl_add_key(&pe, &ix) != AVL_IX_OK ) - puts("add key error"); - } - else { - OCbuf.key.pid -= OC_pidadd; - memcpy(pe.key, &OCbuf.key, OC_KEYLEN); - if( avl_find_key(&pe, &ix) == AVL_IX_OK ){ - store = (OCstore_t *)pe.recptr; - - len = store->data.length + OC_HEADERLEN; - Write(sfd, &len, sizeof(len)); - Write(sfd, &(store->data), len); - free(store); - if( avl_delete_key(&pe, &ix) != AVL_IX_OK ) - puts("delete key error"); - } - else - puts("error"); - } - close(sfd); - } - return 0; -} - -int toaccept(int port) -{ - static int sockfd = 0, len; - int cfd, val; - struct sockaddr_in servaddr, clientaddr; - - if( sockfd == 0 ){ - if( (sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0 ) - err(1, NULL); - setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, (char *)&val, sizeof(val)); - setsockopt(sockfd, SOL_SOCKET, SO_REUSEPORT, (char *)&val, sizeof(val)); - - bzero(&servaddr, sizeof(servaddr)); - servaddr.sin_family = AF_INET; - servaddr.sin_addr.s_addr = htonl(INADDR_ANY); - servaddr.sin_port = htons(port); - if( bind(sockfd, (struct sockaddr *)&servaddr, sizeof(servaddr)) < 0 ) - err(1, NULL); - if( listen(sockfd, 5) < 0 ) - err(1, NULL); - - len = sizeof(struct sockaddr_in); - } - - while( (cfd = accept(sockfd, (struct sockaddr *)&clientaddr, &len)) <= 0 ) - ; - - return cfd; -} - -void usage(void) -{ - fprintf(stderr, - "usage:\tcacheserver [options]\n" - "-p port\tlistenport\n"); - exit(0); -} - -ssize_t Read(int fd, void *BUF, size_t nbytes) -{ - char *buf = (char *)BUF; - ssize_t thisgot, totalgot = nbytes; - while( nbytes > 0 ){ - if( (thisgot = read(fd, buf, nbytes)) <= 0 ) - err(1, "read from socket: "); - nbytes -= thisgot; - buf += thisgot; - } - return totalgot; -} diff --git a/pttbbs/util/localserver.c b/pttbbs/util/localserver.c deleted file mode 100644 index eb90bd6f..00000000 --- a/pttbbs/util/localserver.c +++ /dev/null @@ -1,116 +0,0 @@ -#include "bbs.h" -#include <err.h> - -void usage(void); -int connectserver(char *, int); -void listennetwork(int, int); -void listenmsgqueue(int, int); - -int main(int argc, char **argv) -{ - char *host = NULL; - int port = 0, ch, sfd, msto, mtos; - pid_t pid; - while( (ch = getopt(argc, argv, "s:p:")) != -1 ) - switch( ch ){ - case 's': - host = strdup(optarg); - break; - case 'p': - port = atoi(optarg); - break; - default: - usage(); - } - - if( host == NULL || port == 0 ) - usage(); - - printf("connecting to server %s:%d\n", host, port); - sfd = connectserver(host, port); - puts("connected"); - - puts("attaching message queue"); - if( (msto = msgget(OC_msto, 0600 | IPC_CREAT)) < 0 ) - err(1, "msgget OC_msto"); - if( (mtos = msgget(OC_mtos, 0600 | IPC_CREAT)) < 0 ) - err(1, "msgget OC_mtos"); - puts("attached"); - - if( (pid = fork()) < 0 ) - err(1, "fork()"); - else if( pid == 0 ) - listennetwork(sfd, msto); - listenmsgqueue(sfd, mtos); - - return 0; -} - -void usage(void) -{ - fprintf(stderr, "usage:\tlocalserver -s host -p port\n"); - exit(0); -} - -int connectserver(char *host, int port) -{ - struct sockaddr_in servaddr; - int fd; - - if( (fd = socket(AF_INET, SOCK_STREAM, 0)) < 0 ) - err(1, "socket"); - bzero(&servaddr, sizeof(servaddr)); - servaddr.sin_family = AF_INET; - inet_pton(AF_INET, host, &servaddr.sin_addr); - servaddr.sin_port = htons(port); - if( connect(fd, (struct sockaddr *)&servaddr, sizeof(servaddr)) < 0 ) - err(1, "connect"); - return fd; -} - -void listennetwork(int netfd, int msgfd) -{ - int len; - char buf[CACHE_BUFSIZE]; - printf("(%d)listening network %d => message queue %d\n", - getpid(), netfd, msgfd); - while( Read(netfd, &len, 4) > 0 ){ - if( Read(netfd, buf, len) < 0 ) - err(1, "(network)read()"); - if( msgsnd(msgfd, buf, len, 0) < 0 ) - err(1, "(network)msgsnd()"); - } - exit(0); -} - -void listenmsgqueue(int netfd, int msgfd) -{ - char buf[CACHE_BUFSIZE]; - OCbuf_t *ptr; - int len; - printf("(%d)listening message queue %d => network %d\n", - getpid(), msgfd, netfd); - while( msgrcv(msgfd, buf, CACHE_BUFSIZE, 0, 0) > 0 ){ - ptr = (OCbuf_t *)buf; - len = ptr->length + OC_HEADERLEN; - if( write(netfd, &len, sizeof(len)) < 0 || - write(netfd, ptr, ptr->length + OC_HEADERLEN) < 0 ) - err(1, "(msgqueue)write()"); - } - err(1, "(msgqueue)msgrcv()"); - exit(0); -} - -ssize_t Read(int fd, void *BUF, size_t nbytes) -{ - char *buf = (char *)BUF; - size_t thisgot, totalgot = nbytes; - while( nbytes > 0 ){ - if( (thisgot = read(fd, buf, nbytes)) <= 0 ) - err(1, "read from socket: "); - nbytes -= thisgot; - buf += thisgot; - } - return totalgot; -} - -- cgit v1.2.3 From f1622597d16f7307ef8bb1a4078b705b511938d0 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Tue, 20 Aug 2002 04:58:01 +0000 Subject: nbrd uses smaller memory git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@481 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/board.c | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/pttbbs/mbbsd/board.c b/pttbbs/mbbsd/board.c index 350a482d..586ef01e 100644 --- a/pttbbs/mbbsd/board.c +++ b/pttbbs/mbbsd/board.c @@ -1,4 +1,4 @@ -/* $Id: board.c,v 1.53 2002/08/20 02:42:36 in2 Exp $ */ +/* $Id: board.c,v 1.54 2002/08/20 04:58:01 in2 Exp $ */ #include "bbs.h" #define BRC_STRLEN 15 /* Length of board name */ #define BRC_MAXSIZE 24576 @@ -220,7 +220,7 @@ typedef struct { } boardstat_t; static int *zapbuf = NULL, *favbuf; -static int nbrdlength; +static short nuseboards = 0; static boardstat_t *nbrd = NULL; #define STR_BBSRC ".bbsrc" @@ -450,8 +450,24 @@ load_boards(char *key) } brdnum = 0; if (class_bid <= 0) { - nbrdlength = numboards * sizeof(boardstat_t); - nbrd = (boardstat_t *) malloc(nbrdlength); + if( nuseboards == 0 ){ + nuseboards = 10; /* 多 malloc 十個版 */ + for ( i = 0; i < numboards; i++) { + if ((bptr = SHM->bsorted[type][i]) == NULL) + continue; + n = (int)(bptr - bcache); + if (!bptr->brdname[0] || bptr->brdattr & BRD_GROUPBOARD || + !((state = Ben_Perm(bptr)) || (currmode & MODE_MENU)) || + (yank_flag == 0 && !(favbuf[n] & BRD_FAV)) || + (yank_flag == 1 && !zapbuf[n]) || + (key[0] && !strcasestr(bptr->title, key)) || + (class_bid == -1 && bptr->nuser < 5)) + continue; + ++nuseboards; + } + } + + nbrd = (boardstat_t *) malloc(sizeof(boardstat_t) * nuseboards); for (i = 0; i < numboards; i++) { if ((bptr = SHM->bsorted[type][i]) == NULL) continue; @@ -469,8 +485,7 @@ load_boards(char *key) qsort(nbrd, brdnum, sizeof(boardstat_t), cmpboardfriends); } } else { - nbrdlength = bptr->childcount * sizeof(boardstat_t); - nbrd = (boardstat_t *) malloc(nbrdlength); + nbrd = (boardstat_t *) malloc(bptr->childcount * sizeof(boardstat_t)); for (bptr = bptr->firstchild[type]; bptr != (boardheader_t *) ~ 0; bptr = bptr->next[type]) { n = (int)(bptr - bcache); @@ -876,6 +891,7 @@ choose_board(int newflag) brdnum = -1; break; case 'y': + nuseboards = 0; /* to recount malloc size for nbrd */ if (class_bid == 0) yank_flag = (yank_flag + 1) % 3; else @@ -930,12 +946,14 @@ choose_board(int newflag) ptr->myattr ^= BRD_FAV; favbuf[ptr->bid - 1] = ptr->myattr; head = 9999; + nuseboards = 0; /* to recount malloc size for nbrd */ } break; case 'z': if (HAS_PERM(PERM_BASIC)) { dozap(num); head = 9999; + nuseboards = 0; /* to recount malloc size for nbrd */ } break; case 'Z': /* Ptt */ @@ -944,6 +962,7 @@ choose_board(int newflag) dozap(tmp); } head = 9999; + nuseboards = 0; /* to recount malloc size for nbrd */ } break; case 'v': @@ -1068,6 +1087,8 @@ choose_board(int newflag) } } while (ch != 'q'); free(nbrd); + if( yank_flag != 0 ) + nuseboards = 0; } int -- cgit v1.2.3 From 590aa98936683939aa247bb923e1ec65404678af Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Tue, 20 Aug 2002 06:29:30 +0000 Subject: remove filtermail.pl git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@482 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/Makefile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pttbbs/util/Makefile b/pttbbs/util/Makefile index 81f466a7..5c7184bd 100644 --- a/pttbbs/util/Makefile +++ b/pttbbs/util/Makefile @@ -1,4 +1,4 @@ -# $Id: Makefile,v 1.19 2002/08/20 02:42:36 in2 Exp $ +# $Id: Makefile,v 1.20 2002/08/20 06:29:30 in2 Exp $ BBSHOME?=$(HOME) OSTYPE!=uname @@ -172,8 +172,8 @@ install: $(PROGS) install -d $(BBSHOME)/bin/ install -c -m 755 $(PROGS) $(BBSHOME)/bin/ chmod 4755 $(BBSHOME)/bin/post - mv $(BBSHOME)/bin/bbsmail $(BBSHOME)/bin/realbbsmail - ln -s $(BBSHOME)/bin/filtermail.pl $(BBSHOME)/bin/bbsmail + #mv $(BBSHOME)/bin/bbsmail $(BBSHOME)/bin/realbbsmail + #ln -s $(BBSHOME)/bin/filtermail.pl $(BBSHOME)/bin/bbsmail installbbsctl: bbsctl rm -f /home/bbs/bin/bbsctl -- cgit v1.2.3 From b24a6a1ef2dd5e097d9c19531a775062522167a8 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Tue, 20 Aug 2002 12:13:57 +0000 Subject: abort_bbs() if data of currutmp is wrong ( by cuser.userid[0] <-> currutmp->userid[0] ) git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@483 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/talk.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/pttbbs/mbbsd/talk.c b/pttbbs/mbbsd/talk.c index 5ba9b7f3..e4f64a16 100644 --- a/pttbbs/mbbsd/talk.c +++ b/pttbbs/mbbsd/talk.c @@ -1,4 +1,4 @@ -/* $Id: talk.c,v 1.84 2002/08/09 13:18:26 kcwu Exp $ */ +/* $Id: talk.c,v 1.85 2002/08/20 12:13:57 in2 Exp $ */ #include "bbs.h" #define QCAST int (*)(const void *, const void *) @@ -2296,6 +2296,12 @@ t_users(void) int mode0 = currutmp->mode; int stat0 = currstat; + if( cuser.userid[0] != currutmp->userid[0] ){ + if( HAS_PERM(PERM_SYSOP) ) + vmsg("warning: currutmp userid is changed"); + else + abort_bbs(0); + } setutmpmode(LUSERS); userlist(); currutmp->mode = mode0; -- cgit v1.2.3 From a7cc47446135fb13e6541befe15d928249d43832 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Tue, 20 Aug 2002 14:40:34 +0000 Subject: fix last commit bug git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@484 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/board.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/pttbbs/mbbsd/board.c b/pttbbs/mbbsd/board.c index 586ef01e..ba6c50c2 100644 --- a/pttbbs/mbbsd/board.c +++ b/pttbbs/mbbsd/board.c @@ -1,4 +1,4 @@ -/* $Id: board.c,v 1.54 2002/08/20 04:58:01 in2 Exp $ */ +/* $Id: board.c,v 1.55 2002/08/20 14:40:34 in2 Exp $ */ #include "bbs.h" #define BRC_STRLEN 15 /* Length of board name */ #define BRC_MAXSIZE 24576 @@ -415,6 +415,8 @@ addnewbrdstat(int n, int state) { boardstat_t *ptr = &nbrd[brdnum++]; boardheader_t *bptr = &bcache[n]; + if( brdnum >= nuseboards ) + vmsg("memory error"); ptr->total = &(SHM->total[n]); ptr->lastposttime = &(SHM->lastposttime[n]); ptr->bid = n + 1; @@ -452,7 +454,7 @@ load_boards(char *key) if (class_bid <= 0) { if( nuseboards == 0 ){ nuseboards = 10; /* 多 malloc 十個版 */ - for ( i = 0; i < numboards; i++) { + for (i = 0; i < numboards; i++) { if ((bptr = SHM->bsorted[type][i]) == NULL) continue; n = (int)(bptr - bcache); @@ -462,8 +464,7 @@ load_boards(char *key) (yank_flag == 1 && !zapbuf[n]) || (key[0] && !strcasestr(bptr->title, key)) || (class_bid == -1 && bptr->nuser < 5)) - continue; - ++nuseboards; + ++nuseboards; } } -- cgit v1.2.3 From 4f2e6689e098ed7724d5a3f8fefd7011bea68340 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Tue, 20 Aug 2002 16:29:50 +0000 Subject: (2nd) use smaller memory git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@485 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/board.c | 34 +++++++--------------------------- 1 file changed, 7 insertions(+), 27 deletions(-) diff --git a/pttbbs/mbbsd/board.c b/pttbbs/mbbsd/board.c index ba6c50c2..bc2a3d56 100644 --- a/pttbbs/mbbsd/board.c +++ b/pttbbs/mbbsd/board.c @@ -1,4 +1,4 @@ -/* $Id: board.c,v 1.55 2002/08/20 14:40:34 in2 Exp $ */ +/* $Id: board.c,v 1.56 2002/08/20 16:29:50 in2 Exp $ */ #include "bbs.h" #define BRC_STRLEN 15 /* Length of board name */ #define BRC_MAXSIZE 24576 @@ -220,7 +220,6 @@ typedef struct { } boardstat_t; static int *zapbuf = NULL, *favbuf; -static short nuseboards = 0; static boardstat_t *nbrd = NULL; #define STR_BBSRC ".bbsrc" @@ -415,8 +414,6 @@ addnewbrdstat(int n, int state) { boardstat_t *ptr = &nbrd[brdnum++]; boardheader_t *bptr = &bcache[n]; - if( brdnum >= nuseboards ) - vmsg("memory error"); ptr->total = &(SHM->total[n]); ptr->lastposttime = &(SHM->lastposttime[n]); ptr->bid = n + 1; @@ -452,23 +449,8 @@ load_boards(char *key) } brdnum = 0; if (class_bid <= 0) { - if( nuseboards == 0 ){ - nuseboards = 10; /* 多 malloc 十個版 */ - for (i = 0; i < numboards; i++) { - if ((bptr = SHM->bsorted[type][i]) == NULL) - continue; - n = (int)(bptr - bcache); - if (!bptr->brdname[0] || bptr->brdattr & BRD_GROUPBOARD || - !((state = Ben_Perm(bptr)) || (currmode & MODE_MENU)) || - (yank_flag == 0 && !(favbuf[n] & BRD_FAV)) || - (yank_flag == 1 && !zapbuf[n]) || - (key[0] && !strcasestr(bptr->title, key)) || - (class_bid == -1 && bptr->nuser < 5)) - ++nuseboards; - } - } - - nbrd = (boardstat_t *) malloc(sizeof(boardstat_t) * nuseboards); + static boardstat_t *tmp = NULL; + nbrd = (boardstat_t *) malloc(sizeof(boardstat_t) * numboards); for (i = 0; i < numboards; i++) { if ((bptr = SHM->bsorted[type][i]) == NULL) continue; @@ -485,6 +467,10 @@ load_boards(char *key) if (class_bid == -1) qsort(nbrd, brdnum, sizeof(boardstat_t), cmpboardfriends); } + tmp = (boardstat_t *) malloc(sizeof(boardstat_t) * brdnum); + memcpy(tmp, nbrd, sizeof(boardstat_t) * brdnum); + free(nbrd); + nbrd = tmp; } else { nbrd = (boardstat_t *) malloc(bptr->childcount * sizeof(boardstat_t)); for (bptr = bptr->firstchild[type]; bptr != (boardheader_t *) ~ 0; @@ -892,7 +878,6 @@ choose_board(int newflag) brdnum = -1; break; case 'y': - nuseboards = 0; /* to recount malloc size for nbrd */ if (class_bid == 0) yank_flag = (yank_flag + 1) % 3; else @@ -947,14 +932,12 @@ choose_board(int newflag) ptr->myattr ^= BRD_FAV; favbuf[ptr->bid - 1] = ptr->myattr; head = 9999; - nuseboards = 0; /* to recount malloc size for nbrd */ } break; case 'z': if (HAS_PERM(PERM_BASIC)) { dozap(num); head = 9999; - nuseboards = 0; /* to recount malloc size for nbrd */ } break; case 'Z': /* Ptt */ @@ -963,7 +946,6 @@ choose_board(int newflag) dozap(tmp); } head = 9999; - nuseboards = 0; /* to recount malloc size for nbrd */ } break; case 'v': @@ -1088,8 +1070,6 @@ choose_board(int newflag) } } while (ch != 'q'); free(nbrd); - if( yank_flag != 0 ) - nuseboards = 0; } int -- cgit v1.2.3 From c72f2d637a43414543026a3d0c656aa7635c134e Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Tue, 20 Aug 2002 17:19:11 +0000 Subject: (3rd)smaller memory use git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@486 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/board.c | 116 ++++++++++++++++++++++++++++++--------------------- pttbbs/mbbsd/mbbsd.c | 3 +- 2 files changed, 70 insertions(+), 49 deletions(-) diff --git a/pttbbs/mbbsd/board.c b/pttbbs/mbbsd/board.c index bc2a3d56..bd8e562e 100644 --- a/pttbbs/mbbsd/board.c +++ b/pttbbs/mbbsd/board.c @@ -1,4 +1,4 @@ -/* $Id: board.c,v 1.56 2002/08/20 16:29:50 in2 Exp $ */ +/* $Id: board.c,v 1.57 2002/08/20 17:19:11 in2 Exp $ */ #include "bbs.h" #define BRC_STRLEN 15 /* Length of board name */ #define BRC_MAXSIZE 24576 @@ -221,74 +221,79 @@ typedef struct { static int *zapbuf = NULL, *favbuf; static boardstat_t *nbrd = NULL; +char zapchange = 0, favchange = 0; #define STR_BBSRC ".bbsrc" #define STR_FAV ".fav" -void -init_brdbuf() +void load_brdbuf(void) { - register int n, size; - char fname[60]; + static char firsttime = 1; + int fd, size, i; + char fname[80]; - /* MAXBOARDS ==> 至多看得見 32 個新板 */ - n = numboards + 32; - size = n * sizeof(int); + size = (numboards + 32) * sizeof(int); zapbuf = (int *)malloc(size); - favbuf = (int *)malloc(size + sizeof(int)); + favbuf = (int *)malloc(size); + zapchange = favchange = 0; - favbuf[0] = 0x5c4d3e; /* for check memory */ - ++favbuf; - - memset(favbuf, 0, size); + if( firsttime ){ + memset(favbuf, 0, size); + for( i = (numboards + 32) - 1 ; i >= 0 ; --i ) + zapbuf[i] = login_start_time; + } - while (n) - zapbuf[--n] = login_start_time; setuserfile(fname, STR_BBSRC); - if ((n = open(fname, O_RDONLY, 0600)) != -1) { - read(n, zapbuf, size); - close(n); + if ((fd = open(fname, O_RDONLY, 0600)) != -1) { + read(fd, zapbuf, size); + close(fd); } setuserfile(fname, STR_FAV); - if ((n = open(fname, O_RDONLY, 0600)) != -1) { - read(n, favbuf, size); - close(n); + if ((fd = open(fname, O_RDONLY, 0600)) != -1) { + read(fd, favbuf, size); + close(fd); + } + + if( firsttime ){ + for (i = 0; i < numboards; i++) + favbuf[i] &= ~BRD_TAG; } - for (n = 0; n < numboards; n++) - favbuf[n] &= ~BRD_TAG; + firsttime = 0; +} +void +init_brdbuf() +{ brc_expire_time = login_start_time - 365 * 86400; } void -save_brdbuf() +free_brdbuf() { int fd, size; char fname[60]; - static char reentrant = 0; - if ( reentrant ) - return; - reentrant = 1; - if (!zapbuf) - return; + size = numboards * sizeof(int); setuserfile(fname, STR_BBSRC); - if ((fd = open(fname, O_WRONLY | O_CREAT, 0600)) != -1) { - size = numboards * sizeof(int); - write(fd, zapbuf, size); - close(fd); - } - if (favbuf[-1] != 0x5c4d3e) { - FILE *fp = fopen(BBSHOME "/log/memorybad", "a"); - fprintf(fp, "%s %s %d\n", cuser.userid, Cdatelite(&now), favbuf[-1]); - fclose(fp); - return; + if ( zapbuf != NULL ){ + if( zapchange && + (fd = open(fname, O_WRONLY | O_CREAT, 0600)) != -1) { + write(fd, zapbuf, size); + close(fd); + } + free(zapbuf); + zapbuf = NULL; } setuserfile(fname, STR_FAV); - if ((fd = open(fname, O_WRONLY | O_CREAT, 0600)) != -1) { - size = numboards * sizeof(int); - write(fd, favbuf, size); - close(fd); + if ( favbuf != NULL ){ + if( favchange && + (fd = open(fname, O_WRONLY | O_CREAT, 0600)) != -1) { + size = numboards * sizeof(int); + write(fd, favbuf, size); + close(fd); + } + free(favbuf); + favbuf = NULL; } } @@ -380,8 +385,8 @@ check_newpost(boardstat_t * ptr) return 1; } -static int brdnum; -static int yank_flag = 1; +static short brdnum; +static char yank_flag = 1; static void load_uidofgid(const int gid, const int type) { @@ -700,6 +705,7 @@ dozap(int num) ptr->myattr &= ~BRD_ZAP; if (!(ptr->myattr & BRD_ZAP)) check_newpost(ptr); + zapchange = 1; zapbuf[ptr->bid - 1] = (ptr->myattr & BRD_ZAP ? 0 : login_start_time); } @@ -711,11 +717,15 @@ choose_board(int newflag) boardstat_t *ptr; int head = -1, ch = 0, currmodetmp, tmp, tmp1, bidtmp; char keyword[13] = ""; + static char depth = 0; #if HAVE_SEARCH_ALL char genbuf[200]; #endif setutmpmode(newflag ? READNEW : READBRD); + if( zapbuf == NULL || favbuf == NULL ) + load_brdbuf(); + ++depth; brdnum = 0; if (!cuser.userlevel) /* guest yank all boards */ yank_flag = 2; @@ -832,6 +842,7 @@ choose_board(int newflag) case 't': ptr = &nbrd[num]; ptr->myattr ^= BRD_TAG; + favchange = 1; favbuf[ptr->bid - 1] = ptr->myattr; head = 9999; case KEY_DOWN: @@ -887,6 +898,7 @@ choose_board(int newflag) case Ctrl('D'): for (tmp = 0; tmp < numboards; tmp++) { if (favbuf[tmp] & BRD_TAG) { + favchange = 1; favbuf[tmp] &= ~BRD_FAV; favbuf[tmp] &= ~BRD_TAG; } @@ -896,6 +908,7 @@ choose_board(int newflag) case Ctrl('A'): for (tmp = 0; tmp < numboards; tmp++) { if (favbuf[tmp] & BRD_TAG) { + favchange = 1; favbuf[tmp] |= BRD_FAV; favbuf[tmp] &= ~BRD_TAG; } @@ -905,6 +918,7 @@ choose_board(int newflag) case Ctrl('T'): for (tmp = 0; tmp < numboards; tmp++) favbuf[tmp] &= ~BRD_TAG; + favchange = 1; brdnum = -1; break; case Ctrl('P'): @@ -914,6 +928,7 @@ choose_board(int newflag) boardheader_t *bh = &bcache[tmp]; if (!(favbuf[tmp] & BRD_TAG) || bh->gid == class_bid) continue; + favchange = 1; favbuf[tmp] &= ~BRD_TAG; if (bh->gid != class_bid) { bh->gid = class_bid; @@ -930,6 +945,7 @@ choose_board(int newflag) if (HAS_PERM(PERM_BASIC)) { ptr = &nbrd[num]; ptr->myattr ^= BRD_FAV; + favchange = 1; favbuf[ptr->bid - 1] = ptr->myattr; head = 9999; } @@ -954,8 +970,10 @@ choose_board(int newflag) brc_initial(ptr->bh->brdname); if (ch == 'v') { ptr->myattr &= ~BRD_UNREAD; + zapchange = 1; zapbuf[ptr->bid - 1] = brc_list[0] = now; } else { + zapchange = 1; zapbuf[ptr->bid - 1] = brc_list[0] = 1; ptr->myattr |= BRD_UNREAD; } @@ -1021,8 +1039,10 @@ choose_board(int newflag) getkeep(buf, head > 1 ? head : 1, tmp + 1); } board_visit_time = zapbuf[ptr->bid - 1]; - if (!(ptr->myattr & BRD_ZAP)) + if (!(ptr->myattr & BRD_ZAP)){ + zapchange = 1; zapbuf[ptr->bid - 1] = now; + } Read(); check_newpost(ptr); head = -1; @@ -1070,6 +1090,8 @@ choose_board(int newflag) } } while (ch != 'q'); free(nbrd); + if( --depth == 0 ) + free_brdbuf(); } int diff --git a/pttbbs/mbbsd/mbbsd.c b/pttbbs/mbbsd/mbbsd.c index dcb4fd76..3d626a59 100644 --- a/pttbbs/mbbsd/mbbsd.c +++ b/pttbbs/mbbsd/mbbsd.c @@ -1,4 +1,4 @@ -/* $Id: mbbsd.c,v 1.47 2002/07/27 13:14:41 kcwu Exp $ */ +/* $Id: mbbsd.c,v 1.48 2002/08/20 17:19:11 in2 Exp $ */ #include "bbs.h" #define SOCKET_QLEN 4 @@ -167,7 +167,6 @@ u_exit(char *mode) reload_money(); auto_backup(); - save_brdbuf(); setflags(PAGER_FLAG, currutmp->pager != 1); setflags(CLOAK_FLAG, currutmp->invisible); -- cgit v1.2.3 From b2285929d8dca7928f8e4bb771f696408c37b078 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Fri, 23 Aug 2002 11:33:01 +0000 Subject: DYMAX_ACTIVE git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@487 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/cal.c | 9 +++++++-- pttbbs/mbbsd/mbbsd.c | 8 ++++++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/pttbbs/mbbsd/cal.c b/pttbbs/mbbsd/cal.c index ee23879b..e4ecc8cf 100644 --- a/pttbbs/mbbsd/cal.c +++ b/pttbbs/mbbsd/cal.c @@ -1,4 +1,4 @@ -/* $Id: cal.c,v 1.19 2002/07/22 19:02:00 in2 Exp $ */ +/* $Id: cal.c,v 1.20 2002/08/23 11:33:01 in2 Exp $ */ #include "bbs.h" /* 防堵 Multi play */ @@ -425,7 +425,12 @@ p_sysinfo(void) "編譯時間: %s\n" "起始時間: %s\n", cpuloadstr, SHM->UTMPnumber, - MAX_ACTIVE, COMPILE_TIME, ctime(&start_time)); +#ifdef DYMAX_ACTIVE + GLOBALVAR[9] > 1000 ? GLOBALVAR[9] : MAX_ACTIVE, +#else + MAX_ACTIVE, +#endif + COMPILE_TIME, ctime(&start_time)); pressanykey(); return 0; } diff --git a/pttbbs/mbbsd/mbbsd.c b/pttbbs/mbbsd/mbbsd.c index 3d626a59..29121dd9 100644 --- a/pttbbs/mbbsd/mbbsd.c +++ b/pttbbs/mbbsd/mbbsd.c @@ -1,4 +1,4 @@ -/* $Id: mbbsd.c,v 1.48 2002/08/20 17:19:11 in2 Exp $ */ +/* $Id: mbbsd.c,v 1.49 2002/08/23 11:33:01 in2 Exp $ */ #include "bbs.h" #define SOCKET_QLEN 4 @@ -523,7 +523,11 @@ login_query() show_file("etc/Welcome", 1, -1, NO_RELOAD); #endif output("1", 1); - if (attempts >= MAX_ACTIVE) { + if (attempts >= MAX_ACTIVE +#ifdef DYMAX_ACTIVE + || (GLOBALVAR[9] > 1000 && attempts >= GLOBALVAR[9] ) +#endif + ) { outs("由於人數太多,請您稍後再來。\n"); refresh(); exit(1); -- cgit v1.2.3 From e6c9ac04e376b9040f9364e26026cd6df2aea176 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Fri, 23 Aug 2002 18:01:30 +0000 Subject: fix memory error git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@488 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/include/proto.h | 3 ++- pttbbs/mbbsd/cache.c | 9 ++++++--- pttbbs/mbbsd/mbbsd.c | 3 ++- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/pttbbs/include/proto.h b/pttbbs/include/proto.h index fe8bad6c..2197427b 100644 --- a/pttbbs/include/proto.h +++ b/pttbbs/include/proto.h @@ -1,4 +1,4 @@ -/* $Id: proto.h,v 1.27 2002/08/20 02:42:36 in2 Exp $ */ +/* $Id: proto.h,v 1.28 2002/08/23 18:01:28 in2 Exp $ */ #ifndef INCLUDE_PROTO_H #define INCLUDE_PROTO_H @@ -117,6 +117,7 @@ int get_fileheader_cache(int bid, char *direct, fileheader_t *headers, int recbase, int nlines); void *attach_shm(int shmkey, int shmsize); void attach_SHM(void); +void sort_utmp(); /* cal */ int give_tax(int money); diff --git a/pttbbs/mbbsd/cache.c b/pttbbs/mbbsd/cache.c index 7c4a1992..ccb8ff33 100644 --- a/pttbbs/mbbsd/cache.c +++ b/pttbbs/mbbsd/cache.c @@ -1,4 +1,4 @@ -/* $Id: cache.c,v 1.49 2002/08/20 02:42:36 in2 Exp $ */ +/* $Id: cache.c,v 1.50 2002/08/23 18:01:30 in2 Exp $ */ #include "bbs.h" #ifndef __FreeBSD__ @@ -527,8 +527,11 @@ search_ulistn(int uid, int unum) for (i = ((start + end) / 2);; i = (start + end) / 2) { j = uid - ulist[i]->uid; if (j == 0) { - for (; i > 0 && uid == ulist[i - 1]->uid; --i); /* 指到第一筆 */ - if (ulist[i + unum - 1] != NULL && uid == ulist[i + unum - 1]->uid) + for (; i > 0 && uid == ulist[i - 1]->uid; --i) + ;/* 指到第一筆 */ + if ( i + unum - 1 >= 0 && + (ulist[i + unum - 1] != NULL && + uid == ulist[i + unum - 1]->uid) ) return (userinfo_t *) (ulist[i + unum - 1]); break; /* 超過範圍 */ } diff --git a/pttbbs/mbbsd/mbbsd.c b/pttbbs/mbbsd/mbbsd.c index 29121dd9..419c13e9 100644 --- a/pttbbs/mbbsd/mbbsd.c +++ b/pttbbs/mbbsd/mbbsd.c @@ -1,4 +1,4 @@ -/* $Id: mbbsd.c,v 1.49 2002/08/23 11:33:01 in2 Exp $ */ +/* $Id: mbbsd.c,v 1.50 2002/08/23 18:01:30 in2 Exp $ */ #include "bbs.h" #define SOCKET_QLEN 4 @@ -448,6 +448,7 @@ multi_user_check() return; /* don't check sysops */ if (cuser.userlevel) { + sort_utmp(); if (!(ui = (userinfo_t *) search_ulist(usernum))) return; /* user isn't logged in */ -- cgit v1.2.3 From f7cd50b968e83499f0d44818eca67ce483632b9d Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Fri, 23 Aug 2002 22:03:46 +0000 Subject: pttbbs.conf could overwrite MAX_BOARD git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@489 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/include/config.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pttbbs/include/config.h b/pttbbs/include/config.h index 8f701c92..b509dfd4 100644 --- a/pttbbs/include/config.h +++ b/pttbbs/include/config.h @@ -1,4 +1,4 @@ -/* $Id: config.h,v 1.6 2002/06/19 13:34:23 lwms Exp $ */ +/* $Id: config.h,v 1.7 2002/08/23 22:03:46 in2 Exp $ */ #ifndef INCLUDE_CONFIG_H #define INCLUDE_CONFIG_H @@ -82,7 +82,9 @@ #define MAX_FRIEND (256) /* 載入 cache 之最多朋友數目 */ #define MAX_REJECT (32) /* 載入 cache 之最多壞人數目 */ #define MAX_MSGS (10) /* 水球(熱訊)忍耐上限 */ +#ifndef MAX_BOARD #define MAX_BOARD (8192) /* 最大開板個數 */ +#endif #define MAX_MOVIE (999) /* 最多動態看板數 */ #define MAX_MOVIE_SECTION (10) /* 最多動態看板類別 */ #define MAX_ITEMS (1000) /* 一個目錄最多有幾項 */ -- cgit v1.2.3 From 3985c57525869ff04a71c44e77225a2003679721 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sat, 24 Aug 2002 14:08:30 +0000 Subject: chkload git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@490 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/mbbsd.c | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/pttbbs/mbbsd/mbbsd.c b/pttbbs/mbbsd/mbbsd.c index 419c13e9..0f224366 100644 --- a/pttbbs/mbbsd/mbbsd.c +++ b/pttbbs/mbbsd/mbbsd.c @@ -1,4 +1,4 @@ -/* $Id: mbbsd.c,v 1.50 2002/08/23 18:01:30 in2 Exp $ */ +/* $Id: mbbsd.c,v 1.51 2002/08/24 14:08:30 in2 Exp $ */ #include "bbs.h" #define SOCKET_QLEN 4 @@ -89,28 +89,25 @@ reapchild(int sig) */ /* check load and print approriate banner string in buf */ static int -chkload(char *buf) +chkload(char *buf, int length) { char cpu_load[30]; int i; i = cpuload(cpu_load); - sprintf(buf, BANNER " 系統負荷\r\n %s %s \r\n", cpu_load, - (i > MAX_CPULOAD ? ",高負荷量,請稍後再來 " - "(請利用port 3000~3010連線)" : "")); #ifdef INSCREEN - strlcpy(buf, (i > MAX_CPULOAD ? BANNER - "高負荷量,請稍後再來(請利用port 3000~3010連線)" : ""), - sizeof(buf)); + if( i > MAX_CPULOAD ){ + strlcpy(buf, BANNER "\r\n系統過載, 請稍後再來\r\n", length); + return 1; + } + buf[0] = 0; + return 0; #else sprintf(buf, BANNER "%s\r\n", (i > MAX_CPULOAD ? "高負荷量,請稍後再來(請利用port 3000~3010連線)" : "")); + return i > MAX_CPULOAD ? 1 : 0; #endif - if (i > MAX_CPULOAD) - return 1; - - return 0; } void @@ -1317,7 +1314,7 @@ check_ban_and_load(int fd) static int banned = 0; if ((time(0) - chkload_time) > 1) { - overload = chkload(buf); + overload = chkload(buf, sizeof(buf)); banned = !access(BBSHOME "/BAN", R_OK) && (strcmp(fromhost, "localhost") != 0); chkload_time = time(0); -- cgit v1.2.3 From 98a08b5b0948f96b0a431a7a1d3d420ae5a2318a Mon Sep 17 00:00:00 2001 From: kcwu <kcwu@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sat, 24 Aug 2002 19:15:24 +0000 Subject: let scr_lns = t_lines; git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@491 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/term.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pttbbs/mbbsd/term.c b/pttbbs/mbbsd/term.c index 9694add2..d329e8ba 100644 --- a/pttbbs/mbbsd/term.c +++ b/pttbbs/mbbsd/term.c @@ -1,4 +1,4 @@ -/* $Id: term.c,v 1.6 2002/07/22 19:02:00 in2 Exp $ */ +/* $Id: term.c,v 1.7 2002/08/24 19:15:24 kcwu Exp $ */ #include "bbs.h" int tgetent(const char *bp, char *name); @@ -71,6 +71,7 @@ term_resize(int sig) big_picture = new_picture; } t_lines = newsize.ws_row; + scr_lns = t_lines; b_lines = t_lines - 1; p_lines = t_lines - 4; -- cgit v1.2.3 From 809eece5367b404faf7d1d9fc1b9e9ab2cf4b7c2 Mon Sep 17 00:00:00 2001 From: kcwu <kcwu@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sat, 24 Aug 2002 19:43:07 +0000 Subject: turn on full screen support if shell login. git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@492 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/mbbsd.c | 4 +++- pttbbs/mbbsd/term.c | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/pttbbs/mbbsd/mbbsd.c b/pttbbs/mbbsd/mbbsd.c index 0f224366..fb4917c1 100644 --- a/pttbbs/mbbsd/mbbsd.c +++ b/pttbbs/mbbsd/mbbsd.c @@ -1,4 +1,4 @@ -/* $Id: mbbsd.c,v 1.51 2002/08/24 14:08:30 in2 Exp $ */ +/* $Id: mbbsd.c,v 1.52 2002/08/24 19:43:07 kcwu Exp $ */ #include "bbs.h" #define SOCKET_QLEN 4 @@ -914,6 +914,8 @@ do_term_init() { term_init(); initscr(); + if(use_shell_login_mode) + raise(SIGWINCH); } static void diff --git a/pttbbs/mbbsd/term.c b/pttbbs/mbbsd/term.c index d329e8ba..e3efe3db 100644 --- a/pttbbs/mbbsd/term.c +++ b/pttbbs/mbbsd/term.c @@ -1,4 +1,4 @@ -/* $Id: term.c,v 1.7 2002/08/24 19:15:24 kcwu Exp $ */ +/* $Id: term.c,v 1.8 2002/08/24 19:43:07 kcwu Exp $ */ #include "bbs.h" int tgetent(const char *bp, char *name); @@ -71,7 +71,7 @@ term_resize(int sig) big_picture = new_picture; } t_lines = newsize.ws_row; - scr_lns = t_lines; + scr_lns = t_lines; /* XXX: scr_lns 跟 t_lines 有什麼不同, 為何分成兩個 */ b_lines = t_lines - 1; p_lines = t_lines - 4; -- cgit v1.2.3 From 0705f39cecf1992111f211eaed2881b6ce4aa2b0 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sun, 25 Aug 2002 07:13:53 +0000 Subject: edit lock git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@493 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/include/proto.h | 5 ++++- pttbbs/mbbsd/bbs.c | 13 +++++++++++-- pttbbs/mbbsd/edit.c | 39 ++++++++++++++++++++++++++++++++++++++- 3 files changed, 53 insertions(+), 4 deletions(-) diff --git a/pttbbs/include/proto.h b/pttbbs/include/proto.h index 2197427b..e4e910d7 100644 --- a/pttbbs/include/proto.h +++ b/pttbbs/include/proto.h @@ -1,4 +1,4 @@ -/* $Id: proto.h,v 1.28 2002/08/23 18:01:28 in2 Exp $ */ +/* $Id: proto.h,v 1.29 2002/08/25 07:13:53 in2 Exp $ */ #ifndef INCLUDE_PROTO_H #define INCLUDE_PROTO_H @@ -193,6 +193,9 @@ void auto_backup(); void restore_backup(); char *ask_tmpbuf(int y); char *strcasestr(const char* big, const char* little); +void editlock(char *fpath); +void editunlock(char *fpath); +int iseditlocking(char *fpath, char *action); /* friend */ void friend_edit(int type); diff --git a/pttbbs/mbbsd/bbs.c b/pttbbs/mbbsd/bbs.c index c6615a0c..23d4b4aa 100644 --- a/pttbbs/mbbsd/bbs.c +++ b/pttbbs/mbbsd/bbs.c @@ -1,4 +1,4 @@ -/* $Id: bbs.c,v 1.67 2002/07/27 13:14:41 kcwu Exp $ */ +/* $Id: bbs.c,v 1.68 2002/08/25 07:13:53 in2 Exp $ */ #include "bbs.h" static void @@ -718,6 +718,9 @@ edit_post(int ent, fileheader_t * fhdr, char *direct) local_article = fhdr->filemode & FILE_LOCAL; strlcpy(save_title, fhdr->title, sizeof(save_title)); + if( iseditlocking(genbuf, "重複編輯") ) + return FULLUPDATE; + editlock(genbuf); /* rocker.011018: 這裡是不是該檢查一下修改文章後的money和原有的比較? */ if (vedit(genbuf, 0, NULL) != -1) { setbpath(fpath, currboard); @@ -750,6 +753,7 @@ edit_post(int ent, fileheader_t * fhdr, char *direct) /* rocker.011018: 順便更新一下cache */ touchdircache(currbid); } + editunlock(genbuf); return FULLUPDATE; } @@ -1212,6 +1216,10 @@ recommend(int ent, fileheader_t * fhdr, char *direct) pressanykey(); return FULLUPDATE; } + + setdirpath(path, direct, fhdr->filename); + if( iseditlocking(path, "推薦文章") ) + return FULLUPDATE; if (fhdr->recommend > 9 || fhdr->recommend < 0) /* 暫時性的 code 原來舊有值取消 */ fhdr->recommend = 0; @@ -1233,7 +1241,6 @@ recommend(int ent, fileheader_t * fhdr, char *direct) cuser.userid, path, 45 - strlen(cuser.userid) - strlen(path), " ", fromhost, ptime->tm_mon + 1, ptime->tm_mday); - setdirpath(path, direct, fhdr->filename); log_file(path, buf); if (fhdr->recommend < 9) { fhdr->recommend++; @@ -1360,6 +1367,8 @@ del_post(int ent, fileheader_t * fhdr, char *direct) strlcpy(currfile, fhdr->filename, sizeof(currfile)); setbfile(genbuf, currboard, fhdr->filename); + if( iseditlocking(genbuf, "刪除文章") ) + return FULLUPDATE; if (!delete_file(direct, sizeof(fileheader_t), ent, cmpfilename)) { if (currmode & MODE_SELECT) { diff --git a/pttbbs/mbbsd/edit.c b/pttbbs/mbbsd/edit.c index 589be70d..db335241 100644 --- a/pttbbs/mbbsd/edit.c +++ b/pttbbs/mbbsd/edit.c @@ -1,4 +1,4 @@ -/* $Id: edit.c,v 1.16 2002/08/20 02:42:36 in2 Exp $ */ +/* $Id: edit.c,v 1.17 2002/08/25 07:13:53 in2 Exp $ */ #include "bbs.h" typedef struct textline_t { struct textline_t *prev; @@ -2280,3 +2280,40 @@ vedit(char *fpath, int saveheader, int *islocal) } } } + +void editlock(char *fpath) +{ + char fn[256]; + FILE *fp; + snprintf(fn, sizeof(fn), "%s.lock", fpath); + if( (fp = fopen(fn, "w")) != NULL ){ + fprintf(fp, "%d\n", currpid); + fclose(fp); + } +} + +void editunlock(char *fpath) +{ + char fn[256]; + snprintf(fn, sizeof(fn), "%s.lock", fpath); + unlink(fn); +} + +int iseditlocking(char *fpath, char *action) +{ + char fn[256]; + FILE *fp; + snprintf(fn, sizeof(fn), "%s.lock", fpath); + if( (fp = fopen(fn, "r")) != NULL ){ + int pid; + fscanf(fp, "%d", &pid); + fclose(fp); + if( kill(pid, 0) >= 0 ){ + vmsg("文章編修中, 暫時無法%s", action); + return 1; + } + else + unlink(fn); + } + return 0; +} -- cgit v1.2.3 From 0f5ba4098a7aefab0b675bd580d6954ebbae4d94 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sun, 25 Aug 2002 07:37:39 +0000 Subject: fix recommend git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@494 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/bbs.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/pttbbs/mbbsd/bbs.c b/pttbbs/mbbsd/bbs.c index 23d4b4aa..59d9b24d 100644 --- a/pttbbs/mbbsd/bbs.c +++ b/pttbbs/mbbsd/bbs.c @@ -1,4 +1,4 @@ -/* $Id: bbs.c,v 1.68 2002/08/25 07:13:53 in2 Exp $ */ +/* $Id: bbs.c,v 1.69 2002/08/25 07:37:39 in2 Exp $ */ #include "bbs.h" static void @@ -1224,6 +1224,7 @@ recommend(int ent, fileheader_t * fhdr, char *direct) /* 暫時性的 code 原來舊有值取消 */ fhdr->recommend = 0; +#ifndef DEBUG if (!(currmode & MODE_BOARD) && getuser(cuser.userid) && now - xuser.recommend < 60) { move(b_lines - 1, 0); @@ -1231,16 +1232,18 @@ recommend(int ent, fileheader_t * fhdr, char *direct) pressanykey(); return FULLUPDATE; } +#endif if (!getdata(b_lines - 2, 0, "推薦語:", path, 40, DOECHO) || !getdata(b_lines - 1, 0, "確定要推薦, 請仔細考慮(Y/N)?[n] ", yn, 5, LCECHO) || yn[0] != 'y') return FULLUPDATE; snprintf(buf, sizeof(buf), - "\033[1;31m→ \033[33m%s\033[m\033[33m:%s\033[m%*s推薦自:%s %02d/%02d\n", + "\033[1;31m→ \033[33m%s\033[m\033[33m:%s\033[m%*s推%15s %02d/%02d\n", cuser.userid, path, - 45 - strlen(cuser.userid) - strlen(path), " ", fromhost, + 51 - strlen(cuser.userid) - strlen(path), " ", fromhost, ptime->tm_mon + 1, ptime->tm_mday); + setdirpath(path, direct, fhdr->filename); log_file(path, buf); if (fhdr->recommend < 9) { fhdr->recommend++; -- cgit v1.2.3 From ef609820f2b93bff009511b9e0715c1ff4a1f5af Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sun, 25 Aug 2002 07:37:47 +0000 Subject: fix memory error git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@495 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/edit.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pttbbs/mbbsd/edit.c b/pttbbs/mbbsd/edit.c index db335241..c74dd2b2 100644 --- a/pttbbs/mbbsd/edit.c +++ b/pttbbs/mbbsd/edit.c @@ -1,4 +1,4 @@ -/* $Id: edit.c,v 1.17 2002/08/25 07:13:53 in2 Exp $ */ +/* $Id: edit.c,v 1.18 2002/08/25 07:37:47 in2 Exp $ */ #include "bbs.h" typedef struct textline_t { struct textline_t *prev; @@ -767,6 +767,7 @@ write_header(FILE * fp) int number; /* post number */ } postlog; + memset(&postlog, 0, sizeof(postlog)); strlcpy(postlog.author, cuser.userid, sizeof(postlog.author)); ifuseanony = 0; #ifdef HAVE_ANONYMOUS -- cgit v1.2.3 From e61a6b3f0185fcbd6d74273b5b3dbb61daa1dafd Mon Sep 17 00:00:00 2001 From: kcwu <kcwu@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sun, 25 Aug 2002 11:40:16 +0000 Subject: preserve past screen when growing screen size git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@496 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/term.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pttbbs/mbbsd/term.c b/pttbbs/mbbsd/term.c index e3efe3db..f5b2544b 100644 --- a/pttbbs/mbbsd/term.c +++ b/pttbbs/mbbsd/term.c @@ -1,4 +1,4 @@ -/* $Id: term.c,v 1.8 2002/08/24 19:43:07 kcwu Exp $ */ +/* $Id: term.c,v 1.9 2002/08/25 11:40:16 kcwu Exp $ */ #include "bbs.h" int tgetent(const char *bp, char *name); @@ -67,6 +67,7 @@ term_resize(int sig) syslog(LOG_ERR, "calloc(): %m"); return; } + memcpy(new_picture, big_picture, t_lines * sizeof(screenline_t)); free(big_picture); big_picture = new_picture; } -- cgit v1.2.3 From 0ddf2dcb058ee304f8d88bc159071d83e767ce71 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sun, 25 Aug 2002 18:43:36 +0000 Subject: recommend lock git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@497 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/bbs.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pttbbs/mbbsd/bbs.c b/pttbbs/mbbsd/bbs.c index 59d9b24d..dbe9936d 100644 --- a/pttbbs/mbbsd/bbs.c +++ b/pttbbs/mbbsd/bbs.c @@ -1,4 +1,4 @@ -/* $Id: bbs.c,v 1.69 2002/08/25 07:37:39 in2 Exp $ */ +/* $Id: bbs.c,v 1.70 2002/08/25 18:43:36 in2 Exp $ */ #include "bbs.h" static void @@ -1243,6 +1243,8 @@ recommend(int ent, fileheader_t * fhdr, char *direct) cuser.userid, path, 51 - strlen(cuser.userid) - strlen(path), " ", fromhost, ptime->tm_mon + 1, ptime->tm_mday); + if( iseditlocking(path, "推薦文章") ) + return FULLUPDATE; setdirpath(path, direct, fhdr->filename); log_file(path, buf); if (fhdr->recommend < 9) { -- cgit v1.2.3 From 609d6a7542928e5b3f6bc5b113d50f4c332ca24d Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Tue, 27 Aug 2002 17:42:27 +0000 Subject: register git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@498 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/user.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/pttbbs/mbbsd/user.c b/pttbbs/mbbsd/user.c index fc60c08d..8aaf6df0 100644 --- a/pttbbs/mbbsd/user.c +++ b/pttbbs/mbbsd/user.c @@ -1,4 +1,4 @@ -/* $Id: user.c,v 1.35 2002/08/06 07:12:52 in2 Exp $ */ +/* $Id: user.c,v 1.36 2002/08/27 17:42:27 in2 Exp $ */ #include "bbs.h" static char *sex[8] = { @@ -1075,7 +1075,12 @@ u_register(void) vmsg("抱歉我們不接受郵政信箱"); continue; } - if ((strstr(addr, "市") == NULL && strstr(addr, "縣") == NULL) || + if ((strstr(addr, "市") == NULL && strstr(addr, "縣") == NULL && + strstr(addr, "室") == NULL) || + strstr(addr, "地球") != NULL || + strstr(addr, "銀河") != NULL || + strstr(addr, "某") != NULL || + strcmp(&addr[strlen(addr) - 2], "段") == 0 || strcmp(&addr[strlen(addr) - 2], "路") == 0 || strcmp(&addr[strlen(addr) - 2], "巷") == 0 || strcmp(&addr[strlen(addr) - 2], "街") == 0 ) { @@ -1086,9 +1091,13 @@ u_register(void) } while (1) { getfield(11, "不加-(), 包括長途區號", "連絡電話", phone, 11); + if (strstr(phone, "(") || strstr(phone, ")") || strstr(phone, "-")){ + vmsg("電話請不加 ( ) - 符號"); + continue; + } if (!removespace(phone) || phone[0] != '0' || strlen(phone) < 9 || phone[1] == '0') { - vmsg("這個電話號碼並不合法"); + vmsg("這個電話號碼並不合法(請含區碼)"); continue; } break; -- cgit v1.2.3 From ac198c30b7a0357be7489ad19c205c0d8335eca3 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Tue, 27 Aug 2002 18:08:42 +0000 Subject: overload message git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@499 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/mbbsd.c | 42 +++++++++++++++++++++++++++++------------- 1 file changed, 29 insertions(+), 13 deletions(-) diff --git a/pttbbs/mbbsd/mbbsd.c b/pttbbs/mbbsd/mbbsd.c index fb4917c1..9990357d 100644 --- a/pttbbs/mbbsd/mbbsd.c +++ b/pttbbs/mbbsd/mbbsd.c @@ -1,4 +1,4 @@ -/* $Id: mbbsd.c,v 1.52 2002/08/24 19:43:07 kcwu Exp $ */ +/* $Id: mbbsd.c,v 1.53 2002/08/27 18:08:42 in2 Exp $ */ #include "bbs.h" #define SOCKET_QLEN 4 @@ -510,26 +510,29 @@ login_query() char uid[IDLEN + 1], passbuf[PASSLEN]; int attempts; char genbuf[200]; - attach_SHM(); + //attach_SHM(); resolve_garbage(); now = time(0); attempts = SHM->UTMPnumber; -#ifdef DEBUG - move(1, 0); - prints("debugging mode\ncurrent pid: %d\n", getpid()); -#else - show_file("etc/Welcome", 1, -1, NO_RELOAD); -#endif - output("1", 1); if (attempts >= MAX_ACTIVE #ifdef DYMAX_ACTIVE || (GLOBALVAR[9] > 1000 && attempts >= GLOBALVAR[9] ) #endif ) { + ++GLOBALVAR[8]; outs("由於人數太多,請您稍後再來。\n"); refresh(); exit(1); } + +#ifdef DEBUG + move(1, 0); + prints("debugging mode\ncurrent pid: %d\n", getpid()); +#else + show_file("etc/Welcome", 1, -1, NO_RELOAD); +#endif + output("1", 1); + /* hint */ attempts = 0; @@ -1263,6 +1266,8 @@ daemon_login(int argc, char *argv[], char *envp[]) fprintf(fp, "%d\n", getpid()); fclose(fp); } + + attach_SHM(); /* main loop */ for (;;) { len_of_sock_addr = sizeof(xsin); @@ -1315,6 +1320,10 @@ check_ban_and_load(int fd) * sec */ static int banned = 0; +#ifdef INSCREEN + write(fd, INSCREEN, strlen(INSCREEN)); +#endif + if ((time(0) - chkload_time) > 1) { overload = chkload(buf, sizeof(buf)); banned = !access(BBSHOME "/BAN", R_OK) && @@ -1328,12 +1337,19 @@ check_ban_and_load(int fd) write(fd, buf, strlen(buf)); fclose(fp); } + if (SHM->UTMPnumber >= MAX_ACTIVE +#ifdef DYMAX_ACTIVE + || (GLOBALVAR[9] > 500 && SHM->UTMPnumber >= GLOBALVAR[9] ) +#endif + ) { + ++GLOBALVAR[8]; + snprintf(buf, sizeof(buf), "由於人數過多,請您稍後再來。"); + write(fd, buf, strlen(buf)); + overload = 1; + } + if (banned || overload) return -1; -#ifdef INSCREEN - write(fd, INSCREEN, strlen(INSCREEN)); -#endif - return 0; } -- cgit v1.2.3 From 243f4a2556bcd6cd6833bd02c46c2e7a8e6536e8 Mon Sep 17 00:00:00 2001 From: kcwu <kcwu@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Tue, 27 Aug 2002 20:29:18 +0000 Subject: check permission for mail git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@500 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/talk.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/pttbbs/mbbsd/talk.c b/pttbbs/mbbsd/talk.c index e4f64a16..6ae713b8 100644 --- a/pttbbs/mbbsd/talk.c +++ b/pttbbs/mbbsd/talk.c @@ -1,4 +1,4 @@ -/* $Id: talk.c,v 1.85 2002/08/20 12:13:57 in2 Exp $ */ +/* $Id: talk.c,v 1.86 2002/08/27 20:29:18 kcwu Exp $ */ #include "bbs.h" #define QCAST int (*)(const void *, const void *) @@ -2217,10 +2217,12 @@ userlist(void) break; case 'm': - stand_title("寄 信"); - prints("[寄信] 收信人:%s", uentp->userid); - my_send(uentp->userid); - redrawall = redraw = 1; + if (HAS_PERM(PERM_BASIC)) { + stand_title("寄 信"); + prints("[寄信] 收信人:%s", uentp->userid); + my_send(uentp->userid); + redrawall = redraw = 1; + } break; case 'q': -- cgit v1.2.3 From c33c890fd5181aff6c4933a879cd02c4dfe8b3e9 Mon Sep 17 00:00:00 2001 From: kcwu <kcwu@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Tue, 27 Aug 2002 21:16:12 +0000 Subject: remove sex sort function git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@501 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/cache.c | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/pttbbs/mbbsd/cache.c b/pttbbs/mbbsd/cache.c index ccb8ff33..32da5a7f 100644 --- a/pttbbs/mbbsd/cache.c +++ b/pttbbs/mbbsd/cache.c @@ -1,4 +1,4 @@ -/* $Id: cache.c,v 1.50 2002/08/23 18:01:30 in2 Exp $ */ +/* $Id: cache.c,v 1.51 2002/08/27 21:16:12 kcwu Exp $ */ #include "bbs.h" #ifndef __FreeBSD__ @@ -373,15 +373,6 @@ cmputmpfive(const void *i, const void *j) return (*((userinfo_t **) i))->five_tie - (*((userinfo_t **) j))->five_tie; } -#if 0 -static int -cmputmpsex(const void *i, const void *j) -{ - static int ladyfirst[] = {1, 0, 1, 0, 1, 0, 3, 3}; - return ladyfirst[(*(userinfo_t **) i)->sex & 07] - - ladyfirst[(*(userinfo_t **) j)->sex & 07]; -} -#endif static int cmputmppid(const void *i, const void *j) { @@ -431,7 +422,6 @@ sort_utmp() qsort(SHM->sorted[ns][2], count, sizeof(userinfo_t *), cmputmpidle); qsort(SHM->sorted[ns][3], count, sizeof(userinfo_t *), cmputmpfrom); qsort(SHM->sorted[ns][4], count, sizeof(userinfo_t *), cmputmpfive); - //qsort(SHM->sorted[ns][5], count, sizeof(userinfo_t *), cmputmpsex); qsort(SHM->sorted[ns][6], count, sizeof(userinfo_t *), cmputmpuid); qsort(SHM->sorted[ns][7], count, sizeof(userinfo_t *), cmputmppid); SHM->currsorted = ns; -- cgit v1.2.3 From c5e30ed10765aacc59bc12fdffc8200b5671349d Mon Sep 17 00:00:00 2001 From: kcwu <kcwu@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Tue, 27 Aug 2002 21:49:18 +0000 Subject: when enter menu, relocate position first git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@502 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/include/modes.h | 4 ++-- pttbbs/mbbsd/menu.c | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/pttbbs/include/modes.h b/pttbbs/include/modes.h index fe3a6b79..cc12b3d5 100644 --- a/pttbbs/include/modes.h +++ b/pttbbs/include/modes.h @@ -1,4 +1,4 @@ -/* $Id: modes.h,v 1.1 2002/03/07 15:13:48 in2 Exp $ */ +/* $Id: modes.h,v 1.2 2002/08/27 21:49:18 kcwu Exp $ */ #ifndef INCLUDE_MODES_H #define INCLUDE_MODES_H @@ -57,7 +57,7 @@ #define MAILALL 39 #define MJ 40 #define P_FRIEND 41 -#define LOGIN 42 /* main menu */ +#define LOGIN 42 /* main menu *//* 所有其他選單動態須在此之前 */ #define DICT 43 #define BRIDGE 44 #define ARCHIE 45 diff --git a/pttbbs/mbbsd/menu.c b/pttbbs/mbbsd/menu.c index f4d28259..755a4319 100644 --- a/pttbbs/mbbsd/menu.c +++ b/pttbbs/mbbsd/menu.c @@ -1,4 +1,4 @@ -/* $Id: menu.c,v 1.17 2002/07/27 10:05:56 kcwu Exp $ */ +/* $Id: menu.c,v 1.18 2002/08/27 21:49:18 kcwu Exp $ */ #include "bbs.h" /* help & menu processring */ @@ -187,6 +187,8 @@ domenu(int cmdmode, char *cmdtitle, int cmd, commands_t cmdtable[]) if (cmd0[cmdmode]) cmd = cmd0[cmdmode]; + else + cmd = KEY_HOME; setutmpmode(cmdmode); -- cgit v1.2.3 From 767e9446b7cd77d4ae088af56be3cc7ee6eb2588 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Wed, 28 Aug 2002 02:11:45 +0000 Subject: fix last commit bug git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@503 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/mbbsd.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pttbbs/mbbsd/mbbsd.c b/pttbbs/mbbsd/mbbsd.c index 9990357d..245fd263 100644 --- a/pttbbs/mbbsd/mbbsd.c +++ b/pttbbs/mbbsd/mbbsd.c @@ -1,4 +1,4 @@ -/* $Id: mbbsd.c,v 1.53 2002/08/27 18:08:42 in2 Exp $ */ +/* $Id: mbbsd.c,v 1.54 2002/08/28 02:11:45 in2 Exp $ */ #include "bbs.h" #define SOCKET_QLEN 4 @@ -1183,6 +1183,7 @@ main(int argc, char *argv[], char *envp[]) signal(SIGUSR2, SIG_IGN); /* check if invoked as "bbs" */ + attach_SHM(); if (argc == 3) shell_login(argc, argv, envp); else @@ -1267,7 +1268,6 @@ daemon_login(int argc, char *argv[], char *envp[]) fclose(fp); } - attach_SHM(); /* main loop */ for (;;) { len_of_sock_addr = sizeof(xsin); -- cgit v1.2.3 From 9fd5cfad203d76a73c780b60d8866f665937d498 Mon Sep 17 00:00:00 2001 From: kcwu <kcwu@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Thu, 29 Aug 2002 15:31:48 +0000 Subject: For personal privacy, some functions should only be used on debug purpose. Approved by in2. git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@504 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/talk.c | 57 +++++++++++++++++++++-------------------------------- pttbbs/mbbsd/user.c | 16 +++++---------- 2 files changed, 27 insertions(+), 46 deletions(-) diff --git a/pttbbs/mbbsd/talk.c b/pttbbs/mbbsd/talk.c index 6ae713b8..d9308b4d 100644 --- a/pttbbs/mbbsd/talk.c +++ b/pttbbs/mbbsd/talk.c @@ -1,4 +1,4 @@ -/* $Id: talk.c,v 1.86 2002/08/27 20:29:18 kcwu Exp $ */ +/* $Id: talk.c,v 1.87 2002/08/29 15:31:48 kcwu Exp $ */ #include "bbs.h" #define QCAST int (*)(const void *, const void *) @@ -388,7 +388,7 @@ my_query(char *uident) prints("《上次上站》%-28.28s《上次故鄉》%s\n", Cdate(&muser.lastlogin), (muser.lasthost[0] ? muser.lasthost : "(不詳)")); - if ((uentp && fri_stat & HFM && !uentp->invisible) || HAS_PERM(PERM_SYSOP)) + if ((uentp && fri_stat & HFM && !uentp->invisible)) prints("《 性 別 》%-28.28s《私有財產》%ld 銀兩\n", sex[muser.sex % 8], muser.money); @@ -1357,17 +1357,15 @@ t_showhelp() clear(); outs("\033[36m【 休閒聊天使用說明 】\033[m\n\n" - "(←)(e) 結束離開 (h) 看使用說明\n" - "(↑)/(↓)(n) 上下移動 (TAB) 切換排序方式\n" - "(PgUp)(^B) 上頁選單 ( )(PgDn)(^F) 下頁選單\n" - "(Hm)/($)(Ed) 首/尾 (S) " - "來源/好友描述/戰績 切換\n" - "(m) 寄信 (q/c) " - "查詢網友/寵物\n" - "(r) 閱\讀信件 (l/C) 看上次熱訊/切換隱身\n" - "(f) 全部/好友列表 (數字) 跳至該使用者\n" - "(p) 切換呼叫器 (g/i) 給錢/切換心情\n" - "(a/d/o) 好友 增加/刪除/修改 (/)(s) 網友ID/暱稱搜尋"); + "(←)(e) 結束離開 (h) 看使用說明\n" + "(↑)/(↓)(n) 上下移動 (TAB) 切換排序方式\n" + "(PgUp)(^B) 上頁選單 ( )(PgDn)(^F) 下頁選單\n" + "(Hm)/($)(Ed) 首/尾 (S) 來源/好友描述/戰績 切換\n" + "(m) 寄信 (q/c) 查詢網友/寵物\n" + "(r) 閱\讀信件 (l/C) 看上次熱訊/切換隱身\n" + "(f) 全部/好友列表 (數字) 跳至該使用者\n" + "(p) 切換呼叫器 (g/i) 給錢/切換心情\n" + "(a/d/o) 好友 增加/刪除/修改 (/)(s) 網友ID/暱稱搜尋"); if (HAS_PERM(PERM_PAGE)) { outs("\n\n\033[36m【 交談專用鍵 】\033[m\n\n" @@ -1379,9 +1377,11 @@ t_showhelp() } if (HAS_PERM(PERM_SYSOP)) { outs("\n\n\033[36m【 站長專用鍵 】\033[m\n\n"); - if (HAS_PERM(PERM_SYSOP)) - outs("(u)/(H) 設定使用者資料/切換隱形模式\n"); - outs("(R)/(K) 查詢使用者的真實姓名/把壞蛋踢出去\n"); + outs("(u)/(H) 設定使用者資料/切換隱形模式\n"); + outs("(K) 把壞蛋踢出去\n"); +#if defined(SHOWBOARD) && defined(DEBUG) + outs("(Y) 顯示正在看什麼板\n"); +#endif } pressanykey(); } @@ -1611,8 +1611,7 @@ pickup(pickup_t * currpickup, int pickup_way, int *page, static void draw_pickup(int drawall, pickup_t * pickup, int pickup_way, int page, int show_mode, int show_uid, int show_board, - int show_pid, int real_name, - int myfriend, int friendme, int bfriend) + int show_pid, int myfriend, int friendme, int bfriend) { char *msg_pickup_way[PICKUP_WAYS] = { "嗨! 朋友", "網友代號", "網友動態", "發呆時間", "來自何方", "五子棋 " @@ -1635,7 +1634,7 @@ draw_pickup(int drawall, pickup_t * pickup, int pickup_way, "\033[7m %s P%c代號 %-17s%-17s%-13s%-10s\033[m\n", show_uid ? "UID" : "No.", (HAS_PERM(PERM_SEECLOAK) || HAS_PERM(PERM_SYSOP)) ? 'C' : ' ', - real_name ? "姓名" : "暱稱", + "暱稱", MODE_STRING[show_mode], show_board ? "Board" : "動態", show_pid ? " PID" : "備註 發呆" @@ -1715,10 +1714,7 @@ draw_pickup(int drawall, pickup_t * pickup, int pickup_way, /* color of userid, userid */ fcolor[state], uentp->userid, - /* nickname or realname */ -#ifdef REALINFO - real_name ? uentp->realname : -#endif + /* nickname */ uentp->username, /* from */ @@ -1726,7 +1722,7 @@ draw_pickup(int drawall, pickup_t * pickup, int pickup_way, uentp->pager & !(friend & HRM)), /* board or mode */ -#ifdef SHOWBOARD +#if defined(SHOWBOARD) && defined(DEBUG) show_board ? (uentp->brc_id == 0 ? "" : bcache[uentp->brc_id - 1].brdname) : #endif @@ -1775,7 +1771,6 @@ userlist(void) static int show_uid = 0; static int show_board = 0; static int show_pid = 0; - static int real_name = 0; char genbuf[256]; int page, offset, pickup_way, ch, leave, redraw, redrawall, fri_stat; @@ -1795,7 +1790,7 @@ userlist(void) pickup(currpickup, pickup_way, &page, &nfriend, &myfriend, &friendme, &bfriend); draw_pickup(redrawall, currpickup, pickup_way, page, - show_mode, show_uid, show_board, show_pid, real_name, + show_mode, show_uid, show_board, show_pid, myfriend, friendme, bfriend); /* @@ -2011,14 +2006,6 @@ userlist(void) } break; -#ifdef REALINFO - case 'R': /* 顯示真實姓名 */ - if (HAS_PERM(PERM_SYSOP)) { - real_name ^= 1; - redrawall = redraw = 1; - } - break; -#endif #ifdef SHOWUID case 'U': if (HAS_PERM(PERM_SYSOP)) { @@ -2027,7 +2014,7 @@ userlist(void) } break; #endif -#ifdef SHOWBOARD +#if defined(SHOWBOARD) && defined(DEBUG) case 'Y': if (HAS_PERM(PERM_SYSOP)) { show_board ^= 1; diff --git a/pttbbs/mbbsd/user.c b/pttbbs/mbbsd/user.c index 8aaf6df0..b948dec4 100644 --- a/pttbbs/mbbsd/user.c +++ b/pttbbs/mbbsd/user.c @@ -1,4 +1,4 @@ -/* $Id: user.c,v 1.36 2002/08/27 17:42:27 in2 Exp $ */ +/* $Id: user.c,v 1.37 2002/08/29 15:31:48 kcwu Exp $ */ #include "bbs.h" static char *sex[8] = { @@ -1163,7 +1163,7 @@ u_register(void) } /* 列出所有註冊使用者 */ -static int usercounter, totalusers, showrealname; +static int usercounter, totalusers; static ushort u_list_special; static int @@ -1178,7 +1178,7 @@ u_list_CB(userec_t * uentp) clrtoeol(); prints("\033[7m 使用者代號 %-25s 上站 文章 %s " "最近光臨日期 \033[0m\n", - showrealname ? "真實姓名" : "綽號暱稱", + "綽號暱稱", HAS_PERM(PERM_SEEULEVELS) ? "等級" : ""); i = 3; return 0; @@ -1228,7 +1228,7 @@ u_list_CB(userec_t * uentp) ptr[18] = '\0'; prints("%-14s %-27.27s%5d %5d %s %s\n", uentp->userid, - showrealname ? uentp->realname : uentp->username, + uentp->username, uentp->numlogins, uentp->numposts, HAS_PERM(PERM_SEEULEVELS) ? permstr : "", ptr); usercounter++; @@ -1242,7 +1242,7 @@ u_list() char genbuf[3]; setutmpmode(LAUSERS); - showrealname = u_list_special = usercounter = 0; + u_list_special = usercounter = 0; totalusers = SHM->number; if (HAS_PERM(PERM_SEEULEVELS)) { getdata(b_lines - 1, 0, "觀看 [1]特殊等級 (2)全部?", @@ -1250,12 +1250,6 @@ u_list() if (genbuf[0] != '2') u_list_special = PERM_BASIC | PERM_CHAT | PERM_PAGE | PERM_POST | PERM_LOGINOK | PERM_BM; } - if (HAS_PERM(PERM_CHATROOM) || HAS_PERM(PERM_SYSOP)) { - getdata(b_lines - 1, 0, "顯示 [1]真實姓名 (2)暱稱?", - genbuf, 3, DOECHO); - if (genbuf[0] != '2') - showrealname = 1; - } u_list_CB(NULL); if (passwd_apply(u_list_CB) == -1) { outs(msg_nobody); -- cgit v1.2.3 From 0575042d27f690e5dac667cd22a909e0af07d680 Mon Sep 17 00:00:00 2001 From: kcwu <kcwu@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Thu, 29 Aug 2002 18:31:44 +0000 Subject: fix bug of year display shift by 1 report by zonble.bbs@ptt2 git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@505 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/yearsold.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pttbbs/util/yearsold.c b/pttbbs/util/yearsold.c index 3124d778..e0aa5142 100644 --- a/pttbbs/util/yearsold.c +++ b/pttbbs/util/yearsold.c @@ -1,4 +1,4 @@ -/* $Id: yearsold.c,v 1.2 2002/06/06 21:34:15 in2 Exp $ */ +/* $Id: yearsold.c,v 1.3 2002/08/29 18:31:44 kcwu Exp $ */ /* 站上年齡統計 */ #include "bbs.h" @@ -71,7 +71,7 @@ int main() fprintf(fp, "\t\t\t  " BBSNAME " 年齡統計 [%02d/%02d/%02d] \n\n", - ptime->tm_year % 100, ptime->tm_mon, ptime->tm_mday); + ptime->tm_year % 100, ptime->tm_mon + 1, ptime->tm_mday); for (i = MAX_LINE + 1; i > 0; i--) { strcpy(buf, " "); -- cgit v1.2.3 From 63986e9d1847eca00a7dc365d87be246b7bff50a Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sun, 1 Sep 2002 18:28:45 +0000 Subject: register git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@506 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/user.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/pttbbs/mbbsd/user.c b/pttbbs/mbbsd/user.c index b948dec4..3745cd47 100644 --- a/pttbbs/mbbsd/user.c +++ b/pttbbs/mbbsd/user.c @@ -1,4 +1,4 @@ -/* $Id: user.c,v 1.37 2002/08/29 15:31:48 kcwu Exp $ */ +/* $Id: user.c,v 1.38 2002/09/01 18:28:45 in2 Exp $ */ #include "bbs.h" static char *sex[8] = { @@ -1044,7 +1044,8 @@ u_register(void) getfield(5, "請用中文", "真實姓名", rname, 20); if (removespace(rname) && rname[0] < 0 && !strstr(rname, "阿") && !strstr(rname, "小") && - !strstr(rname, "ㄚ")) + !strstr(rname, "ㄚ") && strstr(rname, "..") == NULL && + !(strlen(rname) == 4 && strncmp(&rname[0], &rname[2], 2) == 0) ) break; vmsg("您的輸入不正確"); } @@ -1052,13 +1053,17 @@ u_register(void) while (1) { getfield(7, "學校(含\033[1;33m系所年級\033[m)或單位職稱", "服務單位", career, 40); - if (!(removespace(career) && career[0] < 0 && strlen(career) >= 4)) { + if (!(removespace(career) && career[0] < 0 + && strlen(career) >= 4) || + strcmp(career, "家裡") == 0 ) { vmsg("您的輸入不正確"); continue; } - if (strcmp(&career[strlen(career) - 2], "大") == 0 || - strcmp(&career[strlen(career) - 4], "大學") == 0) { - vmsg("麻煩請加系所"); + if (strcmp(career, "學校") == 0 || + strcmp(career, "學生") == 0 || + strcmp(&career[strlen(career) - 2], "大") == 0 || + strcmp(&career[strlen(career) - 4], "大學") == 0 ) { + vmsg("麻煩請加學校系所"); continue; } break; @@ -1080,6 +1085,7 @@ u_register(void) strstr(addr, "地球") != NULL || strstr(addr, "銀河") != NULL || strstr(addr, "某") != NULL || + strstr(addr, "..") != NULL || strcmp(&addr[strlen(addr) - 2], "段") == 0 || strcmp(&addr[strlen(addr) - 2], "路") == 0 || strcmp(&addr[strlen(addr) - 2], "巷") == 0 || -- cgit v1.2.3 From eb3739a401a3679d1ab58777f6a47354aedbafea Mon Sep 17 00:00:00 2001 From: ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Mon, 2 Sep 2002 14:57:12 +0000 Subject: advetise ptt2 git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@507 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/mbbsd.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pttbbs/mbbsd/mbbsd.c b/pttbbs/mbbsd/mbbsd.c index 245fd263..18672328 100644 --- a/pttbbs/mbbsd/mbbsd.c +++ b/pttbbs/mbbsd/mbbsd.c @@ -1,4 +1,4 @@ -/* $Id: mbbsd.c,v 1.54 2002/08/28 02:11:45 in2 Exp $ */ +/* $Id: mbbsd.c,v 1.55 2002/09/02 14:57:12 ptt Exp $ */ #include "bbs.h" #define SOCKET_QLEN 4 @@ -520,7 +520,7 @@ login_query() #endif ) { ++GLOBALVAR[8]; - outs("由於人數太多,請您稍後再來。\n"); + outs("由於人數太多,請您稍後再來。分散流量請到 ptt.cc 或 ptt2.cc\n"); refresh(); exit(1); } -- cgit v1.2.3 From da106ffe5cb78dfbda0f6c698efd9dcc0975a428 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Tue, 3 Sep 2002 07:09:34 +0000 Subject: interval every 3mins -> 1min git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@508 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/outmail.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pttbbs/util/outmail.c b/pttbbs/util/outmail.c index 1c282d61..804638e5 100644 --- a/pttbbs/util/outmail.c +++ b/pttbbs/util/outmail.c @@ -1,4 +1,4 @@ -/* $Id: outmail.c,v 1.3 2002/06/28 14:20:12 in2 Exp $ */ +/* $Id: outmail.c,v 1.4 2002/09/03 07:09:34 in2 Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -327,7 +327,7 @@ int main(int argc, char **argv, char **envp) { for(;;) { sendMail(); setproctitle("outmail: sleeping"); - sleep(60 * 3); /* send mail every 3 minute */ + sleep(60); /* send mail every minute */ } return 0; } -- cgit v1.2.3 From f2fe953df54779fec518605029a371ed2b68c579 Mon Sep 17 00:00:00 2001 From: kcwu <kcwu@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Wed, 4 Sep 2002 12:54:51 +0000 Subject: revert last domenu() fix, change the permission setting instead git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@509 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/menu.c | 13 ++++--------- pttbbs/mbbsd/var.c | 4 ++-- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/pttbbs/mbbsd/menu.c b/pttbbs/mbbsd/menu.c index 755a4319..0fe3bd60 100644 --- a/pttbbs/mbbsd/menu.c +++ b/pttbbs/mbbsd/menu.c @@ -1,4 +1,4 @@ -/* $Id: menu.c,v 1.18 2002/08/27 21:49:18 kcwu Exp $ */ +/* $Id: menu.c,v 1.19 2002/09/04 12:54:50 kcwu Exp $ */ #include "bbs.h" /* help & menu processring */ @@ -185,10 +185,9 @@ domenu(int cmdmode, char *cmdtitle, int cmd, commands_t cmdtable[]) int chkmailbox(); static char cmd0[LOGIN]; + /* XXX: 傳進來的 cmd 若權限不足, 則不知 cursor 在哪, 導致 crash */ if (cmd0[cmdmode]) cmd = cmd0[cmdmode]; - else - cmd = KEY_HOME; setutmpmode(cmdmode); @@ -477,7 +476,8 @@ static commands_t playlist[] = { #endif {note, PERM_LOGINOK, "NNote 【 刻刻流言板 】"}, {x_weather,0 , "WWeather 【 氣象預報 】"}, - {x_stock,0 , "SStock 【 股市行情 】"}, +/* XXX 壞掉了 */ +/* {x_stock,0 , "SStock 【 股市行情 】"},*/ #ifdef HAVE_BIG2 {x_big2, 0, "BBig2 【 網路大老二 】"}, #endif @@ -585,9 +585,4 @@ int Name_Menu() domenu(NMENU, "白色恐怖", 'O', namelist); return 0; } - - - - - diff --git a/pttbbs/mbbsd/var.c b/pttbbs/mbbsd/var.c index 2cca1e11..dfabe04a 100644 --- a/pttbbs/mbbsd/var.c +++ b/pttbbs/mbbsd/var.c @@ -1,4 +1,4 @@ -/* $Id: var.c,v 1.11 2002/07/21 09:26:02 in2 Exp $ */ +/* $Id: var.c,v 1.12 2002/09/04 12:54:51 kcwu Exp $ */ #define INCLUDE_VAR_H #include "bbs.h" @@ -551,7 +551,7 @@ commands_t cmdlist[] = { {Talk, 0, "TTalk 【 休閒聊天區 】"}, {User, 0, "UUser 【 個人設定區 】"}, {Xyz, 0, "XXyz 【 系統工具區 】"}, - {Play_Play, 0, "PPlay 【 遊樂場/大學查榜】"}, + {Play_Play, PERM_BASIC, "PPlay 【 遊樂場/大學查榜】"}, {Name_Menu, PERM_LOGINOK, "NNamelist 【 編特別名單 】"}, {Goodbye, 0, "GGoodbye 離開,再見……"}, {NULL, 0, NULL} -- cgit v1.2.3 From 7eabbfac80a690906ce4bb67d380f92e9559fef8 Mon Sep 17 00:00:00 2001 From: kcwu <kcwu@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Wed, 4 Sep 2002 13:33:45 +0000 Subject: when return from hotkey function, restore utmpmode git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@510 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/talk.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pttbbs/mbbsd/talk.c b/pttbbs/mbbsd/talk.c index d9308b4d..845c25e8 100644 --- a/pttbbs/mbbsd/talk.c +++ b/pttbbs/mbbsd/talk.c @@ -1,4 +1,4 @@ -/* $Id: talk.c,v 1.87 2002/08/29 15:31:48 kcwu Exp $ */ +/* $Id: talk.c,v 1.88 2002/09/04 13:33:45 kcwu Exp $ */ #include "bbs.h" #define QCAST int (*)(const void *, const void *) @@ -2208,6 +2208,7 @@ userlist(void) stand_title("寄 信"); prints("[寄信] 收信人:%s", uentp->userid); my_send(uentp->userid); + setutmpmode(LUSERS); redrawall = redraw = 1; } break; @@ -2266,6 +2267,7 @@ userlist(void) case 'r': if (HAS_PERM(PERM_LOGINOK)) { m_read(); + setutmpmode(LUSERS); redrawall = redraw = 1; } break; -- cgit v1.2.3 From 66a91d3d33be1ac88387a4afffb92e069494065c Mon Sep 17 00:00:00 2001 From: kcwu <kcwu@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Wed, 4 Sep 2002 15:08:42 +0000 Subject: only read friend description when he is my friend git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@511 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/talk.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/pttbbs/mbbsd/talk.c b/pttbbs/mbbsd/talk.c index 845c25e8..e7c1d8f8 100644 --- a/pttbbs/mbbsd/talk.c +++ b/pttbbs/mbbsd/talk.c @@ -1,4 +1,4 @@ -/* $Id: talk.c,v 1.88 2002/09/04 13:33:45 kcwu Exp $ */ +/* $Id: talk.c,v 1.89 2002/09/04 15:08:42 kcwu Exp $ */ #include "bbs.h" #define QCAST int (*)(const void *, const void *) @@ -1396,32 +1396,35 @@ t_showhelp() /* Kaede show friend description */ static char * -friend_descript(char *uident) +friend_descript(userinfo_t * uentp) { - static char *space_buf = " "; + static char *space_buf = ""; static char desc_buf[80]; char fpath[80], name[IDLEN + 2], *desc, *ptr; int len, flag; FILE *fp; char genbuf[200]; + if((set_friend_bit(currutmp,uentp)|IFH)==0) + return space_buf; + setuserfile(fpath, friend_file[0]); if ((fp = fopen(fpath, "r"))) { - snprintf(name, sizeof(name), "%s ", uident); + snprintf(name, sizeof(name), "%s ", uentp->userid); len = strlen(name); desc = genbuf + 13; + /* TODO maybe none linear search, or fread, or cache */ while ((flag = (int)fgets(genbuf, STRLEN, fp))) { if (!memcmp(genbuf, name, len)) { if ((ptr = strchr(desc, '\n'))) ptr[0] = '\0'; - if (desc) - break; + break; } } fclose(fp); - if (desc && flag) + if (flag) strlcpy(desc_buf, desc, sizeof(desc_buf)); else return space_buf; @@ -1431,12 +1434,13 @@ friend_descript(char *uident) return space_buf; } +/* XXX 為什麼 diff 是 time_t */ static char * descript(int show_mode, userinfo_t * uentp, time_t diff) { switch (show_mode) { case 1: - return friend_descript(uentp->userid); + return friend_descript(uentp); case 0: return (((uentp->pager != 2 && uentp->pager != 3 && diff) || HAS_PERM(PERM_SYSOP)) ? -- cgit v1.2.3 From 85dc09cebe86d9b8c1fb416fdbd8405700a4a329 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Fri, 6 Sep 2002 03:07:29 +0000 Subject: =?UTF-8?q?s/=EF=BF=BD=EF=BF=BD/=EF=BF=BDQ/g;?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@512 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/udnnews.pl | 1 + 1 file changed, 1 insertion(+) diff --git a/pttbbs/util/udnnews.pl b/pttbbs/util/udnnews.pl index d953c388..66ddc094 100644 --- a/pttbbs/util/udnnews.pl +++ b/pttbbs/util/udnnews.pl @@ -38,6 +38,7 @@ sub getudnnewscontent($) $content =~ s/\r//g; $content =~ s/\n\n\n/\n\n/g; $content =~ s/\n\n\n//g; + $content =~ s/十/十/g; undef $ret; foreach( split(/\n/, $content) ){ s/ //g; -- cgit v1.2.3 From b5c3b2b28b4e49f8684bb4472eaeb7d2b1550277 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sat, 7 Sep 2002 05:42:17 +0000 Subject: badfriend git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@513 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/talk.c | 52 +++++++++++++++++++++++++++++----------------------- 1 file changed, 29 insertions(+), 23 deletions(-) diff --git a/pttbbs/mbbsd/talk.c b/pttbbs/mbbsd/talk.c index e7c1d8f8..183c92a9 100644 --- a/pttbbs/mbbsd/talk.c +++ b/pttbbs/mbbsd/talk.c @@ -1,4 +1,4 @@ -/* $Id: talk.c,v 1.89 2002/09/04 15:08:42 kcwu Exp $ */ +/* $Id: talk.c,v 1.90 2002/09/07 05:42:17 in2 Exp $ */ #include "bbs.h" #define QCAST int (*)(const void *, const void *) @@ -1491,11 +1491,12 @@ pickup_maxpages(int pickupway, int nfriends) static int pickup_myfriend(pickup_t * friends, - int *myfriend, int *friendme) + int *myfriend, int *friendme, int *badfriend) { userinfo_t *uentp; int i, where, frstate, ngets = 0; + *badfriend = 0; *myfriend = *friendme = 1; for (i = 0; currutmp->friend_online[i] && i < MAX_FRIEND; ++i) { where = currutmp->friend_online[i] & 0xFFFFFF; @@ -1504,16 +1505,18 @@ pickup_myfriend(pickup_t * friends, uentp != currutmp && isvisible_stat(currutmp, uentp, frstate = - currutmp->friend_online[i] >> 24) && - (!(frstate & IRH) || ((frstate & IRH) && (frstate & IFH))) - ) { - friends[ngets].ui = uentp; - friends[ngets].uoffset = where; - friends[ngets++].friend = frstate; - if (frstate & IFH) - ++* myfriend; - if (frstate & HFM) - ++* friendme; + currutmp->friend_online[i] >> 24)){ + if( frstate & IRH ) + ++*badfriend; + if( !(frstate & IRH) || ((frstate & IRH) && (frstate & IFH)) ){ + friends[ngets].ui = uentp; + friends[ngets].uoffset = where; + friends[ngets++].friend = frstate; + if (frstate & IFH) + ++* myfriend; + if (frstate & HFM) + ++* friendme; + } } } friends[ngets].ui = currutmp; @@ -1542,7 +1545,7 @@ pickup_bfriend(pickup_t * friends, int base) static void pickup(pickup_t * currpickup, int pickup_way, int *page, - int *nfriend, int *myfriend, int *friendme, int *bfriend) + int *nfriend, int *myfriend, int *friendme, int *bfriend, int *badfriend) { /* avoid race condition */ int currsorted = SHM->currsorted; @@ -1554,7 +1557,7 @@ pickup(pickup_t * currpickup, int pickup_way, int *page, if (friendtotal == 0) *myfriend = *friendme = 1; - + if (cuser.uflag & FRIEND_FLAG || (pickup_way == 0 && *page * MAXPICKUP < MAX_FRIEND)) { /* @@ -1563,7 +1566,7 @@ pickup(pickup_t * currpickup, int pickup_way, int *page, */ pickup_t friends[MAX_FRIEND]; - *nfriend = pickup_myfriend(friends, myfriend, friendme); + *nfriend = pickup_myfriend(friends, myfriend, friendme, badfriend); if (pickup_way == 0 && currutmp->brc_id != 0) *bfriend = pickup_bfriend(friends, *nfriend); @@ -1592,7 +1595,7 @@ pickup(pickup_t * currpickup, int pickup_way, int *page, friend = friend_stat(currutmp, utmp[which]); if ((pickup_way || (currutmp != utmp[which] && !(friend & ST_FRIEND))) && - isvisible_stat(currutmp, utmp[which], 0)) { + isvisible(currutmp, utmp[which])) { currpickup[size].ui = utmp[which]; currpickup[size++].friend = friend; } @@ -1615,12 +1618,14 @@ pickup(pickup_t * currpickup, int pickup_way, int *page, static void draw_pickup(int drawall, pickup_t * pickup, int pickup_way, int page, int show_mode, int show_uid, int show_board, - int show_pid, int myfriend, int friendme, int bfriend) + int show_pid, int myfriend, int friendme, int bfriend, int badfriend) { char *msg_pickup_way[PICKUP_WAYS] = { "嗨! 朋友", "網友代號", "網友動態", "發呆時間", "來自何方", "五子棋 " }; - char *MODE_STRING[MAX_SHOW_MODE] = {"故鄉", "好友描述", "五子棋戰績"}; + char *MODE_STRING[MAX_SHOW_MODE] = { + "故鄉", "好友描述", "五子棋戰績" + }; char pagerchar[5] = "* -Wf"; userinfo_t *uentp; @@ -1654,7 +1659,7 @@ draw_pickup(int drawall, pickup_t * pickup, int pickup_way, "\033[33m與我為友:%-3d\033[36m板友:%-4d\033[31m壞人:" "%-2d\033[m\n", msg_pickup_way[pickup_way], SHM->UTMPnumber, - myfriend, friendme, currutmp->brc_id ? (bfriend + 1) : 0, 0); + myfriend, friendme, currutmp->brc_id ? (bfriend + 1) : 0, badfriend); for (i = 0, ch = page * 20 + 1; i < MAXPICKUP; ++i, ++ch) { move(i + 3, 0); @@ -1778,7 +1783,7 @@ userlist(void) char genbuf[256]; int page, offset, pickup_way, ch, leave, redraw, redrawall, fri_stat; - int nfriend, myfriend, friendme, bfriend, i; + int nfriend, myfriend, friendme, bfriend, badfriend, i; time_t lastupdate; page = offset = 0; @@ -1792,10 +1797,10 @@ userlist(void) */ while (!leave) { pickup(currpickup, pickup_way, &page, - &nfriend, &myfriend, &friendme, &bfriend); + &nfriend, &myfriend, &friendme, &bfriend, &badfriend); draw_pickup(redrawall, currpickup, pickup_way, page, show_mode, show_uid, show_board, show_pid, - myfriend, friendme, bfriend); + myfriend, friendme, bfriend, badfriend); /* * 如果因為換頁的時候, 這一頁有的人數比較少, @@ -1963,7 +1968,8 @@ userlist(void) fi = SHM->sorted[SHM->currsorted][0][si] - &SHM->uinfo[0]; - nGots = pickup_myfriend(friends, &myfriend, &friendme); + nGots = pickup_myfriend(friends, &myfriend, + &friendme, &badfriend); for (i = 0; i < nGots; ++i) if (friends[i].uoffset == fi) break; -- cgit v1.2.3 From da6d4ba3334aeabef9fb7e44780f3902e3b6df4a Mon Sep 17 00:00:00 2001 From: lwms <lwms@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sat, 7 Sep 2002 06:40:46 +0000 Subject: g is useless git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@514 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/talk.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pttbbs/mbbsd/talk.c b/pttbbs/mbbsd/talk.c index 183c92a9..18d0d7a8 100644 --- a/pttbbs/mbbsd/talk.c +++ b/pttbbs/mbbsd/talk.c @@ -1,4 +1,4 @@ -/* $Id: talk.c,v 1.90 2002/09/07 05:42:17 in2 Exp $ */ +/* $Id: talk.c,v 1.91 2002/09/07 06:40:46 lwms Exp $ */ #include "bbs.h" #define QCAST int (*)(const void *, const void *) @@ -2189,9 +2189,9 @@ userlist(void) break; reload_money(); - if (ch > cuser.money) + if (ch > cuser.money) { outs("\033[41m 現金不足~~\033[m"); - else { + } else { deumoney(uentp->uid, ch - give_tax(ch)); snprintf(genbuf, sizeof(genbuf), "\033[44m 嗯..還剩下 %d 錢.." -- cgit v1.2.3 From 933a18995d1721871872631af6f34d946f30b4f6 Mon Sep 17 00:00:00 2001 From: lwms <lwms@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sat, 7 Sep 2002 07:00:58 +0000 Subject: == -> = git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@515 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/talk.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pttbbs/mbbsd/talk.c b/pttbbs/mbbsd/talk.c index 18d0d7a8..478e6846 100644 --- a/pttbbs/mbbsd/talk.c +++ b/pttbbs/mbbsd/talk.c @@ -1,4 +1,4 @@ -/* $Id: talk.c,v 1.91 2002/09/07 06:40:46 lwms Exp $ */ +/* $Id: talk.c,v 1.92 2002/09/07 07:00:58 lwms Exp $ */ #include "bbs.h" #define QCAST int (*)(const void *, const void *) @@ -2185,7 +2185,7 @@ userlist(void) if (getdata(b_lines - 1, 0, "[銀行轉帳]: ", genbuf, 7, LCECHO)) { clrtoeol(); - if ((ch == atoi(genbuf)) <= 0 || ch <= give_tax(ch)) + if ((ch = atoi(genbuf)) <= 0 || ch <= give_tax(ch)) break; reload_money(); -- cgit v1.2.3 From 6470d9b4491886a154f323cd977c21513125a3d4 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sat, 7 Sep 2002 11:21:36 +0000 Subject: remove unused code git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@516 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/mbbsd.c | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/pttbbs/mbbsd/mbbsd.c b/pttbbs/mbbsd/mbbsd.c index 18672328..9309103e 100644 --- a/pttbbs/mbbsd/mbbsd.c +++ b/pttbbs/mbbsd/mbbsd.c @@ -1,4 +1,4 @@ -/* $Id: mbbsd.c,v 1.55 2002/09/02 14:57:12 ptt Exp $ */ +/* $Id: mbbsd.c,v 1.56 2002/09/07 11:21:36 in2 Exp $ */ #include "bbs.h" #define SOCKET_QLEN 4 @@ -510,20 +510,8 @@ login_query() char uid[IDLEN + 1], passbuf[PASSLEN]; int attempts; char genbuf[200]; - //attach_SHM(); resolve_garbage(); now = time(0); - attempts = SHM->UTMPnumber; - if (attempts >= MAX_ACTIVE -#ifdef DYMAX_ACTIVE - || (GLOBALVAR[9] > 1000 && attempts >= GLOBALVAR[9] ) -#endif - ) { - ++GLOBALVAR[8]; - outs("由於人數太多,請您稍後再來。分散流量請到 ptt.cc 或 ptt2.cc\n"); - refresh(); - exit(1); - } #ifdef DEBUG move(1, 0); -- cgit v1.2.3 From dbe746260f374a816af234681401641c9de0dc88 Mon Sep 17 00:00:00 2001 From: kcwu <kcwu@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Wed, 11 Sep 2002 03:22:50 +0000 Subject: fix screen rotate bug when returning from Ctrl-U git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@517 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/io.c | 4 +++- pttbbs/mbbsd/screen.c | 3 +-- pttbbs/mbbsd/var.c | 3 ++- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/pttbbs/mbbsd/io.c b/pttbbs/mbbsd/io.c index 721b54a2..82895f28 100644 --- a/pttbbs/mbbsd/io.c +++ b/pttbbs/mbbsd/io.c @@ -1,4 +1,4 @@ -/* $Id: io.c,v 1.22 2002/07/22 19:02:00 in2 Exp $ */ +/* $Id: io.c,v 1.23 2002/09/11 03:22:50 kcwu Exp $ */ #include "bbs.h" #if defined(linux) @@ -161,6 +161,7 @@ igetch() && currutmp->mode != LUSERS && currutmp->mode) { screenline_t *screen0 = calloc(t_lines, sizeof(screenline_t)); + int oldroll = roll; int y, x, my_newfd; getyx(&y, &x); @@ -170,6 +171,7 @@ igetch() t_users(); i_newfd = my_newfd; memcpy(big_picture, screen0, t_lines * sizeof(screenline_t)); + roll = oldroll; move(y, x); free(screen0); redoscr(); diff --git a/pttbbs/mbbsd/screen.c b/pttbbs/mbbsd/screen.c index a7f4526c..0dc36811 100644 --- a/pttbbs/mbbsd/screen.c +++ b/pttbbs/mbbsd/screen.c @@ -1,4 +1,4 @@ -/* $Id: screen.c,v 1.8 2002/07/22 19:02:00 in2 Exp $ */ +/* $Id: screen.c,v 1.9 2002/09/11 03:22:50 kcwu Exp $ */ #include "bbs.h" #ifdef SUPPORT_GB @@ -15,7 +15,6 @@ static int gbinited = 0; static unsigned char cur_ln = 0, cur_col = 0; static unsigned char docls, downfrom = 0; static unsigned char standing = NA; -static char roll = 0; static int scrollcnt, tc_col, tc_line; #define MODIFIED (1) /* if line has been modifed, screen output */ diff --git a/pttbbs/mbbsd/var.c b/pttbbs/mbbsd/var.c index dfabe04a..819be5ba 100644 --- a/pttbbs/mbbsd/var.c +++ b/pttbbs/mbbsd/var.c @@ -1,4 +1,4 @@ -/* $Id: var.c,v 1.12 2002/09/04 12:54:51 kcwu Exp $ */ +/* $Id: var.c,v 1.13 2002/09/11 03:22:50 kcwu Exp $ */ #define INCLUDE_VAR_H #include "bbs.h" @@ -345,6 +345,7 @@ int chc_hiswin, chc_hislose, chc_histie; /* screen.c */ screenline_t *big_picture = NULL; unsigned char scr_lns, scr_cols; +char roll; /* gomo.c */ char ku[BRDSIZ][BRDSIZ]; -- cgit v1.2.3 From c4c4f8e3bbeef1608f06f145a013ed66e9fd74ac Mon Sep 17 00:00:00 2001 From: kcwu <kcwu@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Wed, 11 Sep 2002 07:16:49 +0000 Subject: not only long screen, but also width screen git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@518 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/board.c | 7 ++++--- pttbbs/mbbsd/edit.c | 8 +++++--- pttbbs/mbbsd/more.c | 10 +++++++--- pttbbs/mbbsd/screen.c | 17 ++++++++++------- pttbbs/mbbsd/term.c | 8 +++++++- 5 files changed, 33 insertions(+), 17 deletions(-) diff --git a/pttbbs/mbbsd/board.c b/pttbbs/mbbsd/board.c index bd8e562e..368241fb 100644 --- a/pttbbs/mbbsd/board.c +++ b/pttbbs/mbbsd/board.c @@ -1,4 +1,4 @@ -/* $Id: board.c,v 1.57 2002/08/20 17:19:11 in2 Exp $ */ +/* $Id: board.c,v 1.58 2002/09/11 07:16:49 kcwu Exp $ */ #include "bbs.h" #define BRC_STRLEN 15 /* Length of board name */ #define BRC_MAXSIZE 24576 @@ -648,10 +648,11 @@ show_brdlist(int head, int clsflag, int newflag) prints("%2d ", ptr->bh->nuser); else prints(" %c ", ptr->bh->bvote ? 'V' : ' '); - prints("%.13s", ptr->bh->BM); + prints("%.*s", t_columns - 67, ptr->bh->BM); refresh(); } else { - prints("%-40.40s %.13s", ptr->bh->title + 7, ptr->bh->BM); + prints("%-40.40s %.*s", ptr->bh->title + 7, + t_columns - 67, ptr->bh->BM); } } clrtoeol(); diff --git a/pttbbs/mbbsd/edit.c b/pttbbs/mbbsd/edit.c index c74dd2b2..5073d10a 100644 --- a/pttbbs/mbbsd/edit.c +++ b/pttbbs/mbbsd/edit.c @@ -1,4 +1,4 @@ -/* $Id: edit.c,v 1.18 2002/08/25 07:37:47 in2 Exp $ */ +/* $Id: edit.c,v 1.19 2002/09/11 07:16:49 kcwu Exp $ */ #include "bbs.h" typedef struct textline_t { struct textline_t *prev; @@ -9,7 +9,6 @@ typedef struct textline_t { #define KEEP_EDITING -2 #define BACKUP_LIMIT 100 -#define SCR_WIDTH 80 enum { NOBODY, MANAGER, SYSOP @@ -2263,7 +2262,10 @@ vedit(char *fpath, int saveheader, int *islocal) } } } - edit_margin = currpnt < SCR_WIDTH - 1 ? 0 : currpnt / 72 * 72; + if (currpnt < t_columns - 1) + edit_margin = 0; + else + edit_margin = currpnt / (t_columns - 8) * (t_columns - 8); if (!redraw_everything) { if (edit_margin != last_margin) { diff --git a/pttbbs/mbbsd/more.c b/pttbbs/mbbsd/more.c index fc3434ba..3afc6ca9 100644 --- a/pttbbs/mbbsd/more.c +++ b/pttbbs/mbbsd/more.c @@ -1,4 +1,4 @@ -/* $Id: more.c,v 1.20 2002/08/20 02:42:36 in2 Exp $ */ +/* $Id: more.c,v 1.21 2002/09/11 07:16:49 kcwu Exp $ */ #include "bbs.h" #define MORE_BUFSIZE 4096 #define MORE_WINSIZE 4096 @@ -83,7 +83,7 @@ more_readln(int fd, unsigned char *buf) do { *buf++ = ' '; } - while ((++len & 7) && len < 80); + while ((++len & 7) && len < t_columns); } else if (ch == '\033') { if (atoi((char *)(data + 1)) > 47) { if ((cc = (unsigned char *)strchr((char *)(data + 1), 'm')) != NULL) { @@ -107,8 +107,12 @@ more_readln(int fd, unsigned char *buf) len++; *buf++ = ch; } + } while (len < t_columns && buf < tail); + if(len==t_columns && head<size && *data=='\n') { + /* XXX: not handle head==size, should read data */ + /* no extra newline dirty hack for exact 80byte line */ + data++; bytes++; head++; } - while (len < 80 && buf < tail); *buf = '\0'; more_head = head; return bytes; diff --git a/pttbbs/mbbsd/screen.c b/pttbbs/mbbsd/screen.c index 0dc36811..fb367618 100644 --- a/pttbbs/mbbsd/screen.c +++ b/pttbbs/mbbsd/screen.c @@ -1,11 +1,10 @@ -/* $Id: screen.c,v 1.9 2002/09/11 03:22:50 kcwu Exp $ */ +/* $Id: screen.c,v 1.10 2002/09/11 07:16:49 kcwu Exp $ */ #include "bbs.h" #ifdef SUPPORT_GB static int current_font_type = TYPE_BIG5; static int gbinited = 0; #endif -#define SCR_WIDTH 80 #define o_clear() output(clearbuf,clearbuflen) #define o_cleol() output(cleolbuf,cleolbuflen) #define o_scrollrev() output(scrollrev,scrollrevlen) @@ -119,6 +118,7 @@ redoscr() output((char *)bp->data, len); tc_col += len; if (tc_col >= t_columns) { + /* XXX Is this code right? */ if (automargins) tc_col = t_columns - 1; else { @@ -182,12 +182,15 @@ refresh() output((char *)&bp->data[bp->smod], bp->emod - bp->smod + 1); tc_col = bp->emod + 1; if (tc_col >= t_columns) { - if (automargins) { + /* XXX Is this code right? */ + if (automargins) + tc_col = t_columns - 1; + else { tc_col -= t_columns; - if (++tc_line >= t_lines) + tc_line++; + if (tc_line >= t_lines) tc_line = b_lines; - } else - tc_col = t_columns - 1; + } } } if (bp->oldlen > len) { @@ -423,7 +426,7 @@ edit_outs(char *text) if (current_font_type == TYPE_GB) text = hc_convert_str(text, HC_BIGtoGB, HC_DO_SINGLE); #endif - while ((ch = *text++) && (++column < SCR_WIDTH)) + while ((ch = *text++) && (++column < t_columns)) outch(ch == 27 ? '*' : ch); return 0; diff --git a/pttbbs/mbbsd/term.c b/pttbbs/mbbsd/term.c index f5b2544b..ed112346 100644 --- a/pttbbs/mbbsd/term.c +++ b/pttbbs/mbbsd/term.c @@ -1,4 +1,4 @@ -/* $Id: term.c,v 1.9 2002/08/25 11:40:16 kcwu Exp $ */ +/* $Id: term.c,v 1.10 2002/09/11 07:16:49 kcwu Exp $ */ #include "bbs.h" int tgetent(const char *bp, char *name); @@ -60,6 +60,11 @@ term_resize(int sig) signal(SIGWINCH, SIG_IGN); /* Don't bother me! */ ioctl(0, TIOCGWINSZ, &newsize); + + /* make sure reasonable size */ + newsize.ws_row = MAX(24, MIN(100, newsize.ws_row)); + newsize.ws_col = MAX(80, MIN(200, newsize.ws_col)); + if (newsize.ws_row > t_lines) { new_picture = (screenline_t *) calloc(newsize.ws_row, sizeof(screenline_t)); @@ -72,6 +77,7 @@ term_resize(int sig) big_picture = new_picture; } t_lines = newsize.ws_row; + t_columns = newsize.ws_col; scr_lns = t_lines; /* XXX: scr_lns 跟 t_lines 有什麼不同, 為何分成兩個 */ b_lines = t_lines - 1; p_lines = t_lines - 4; -- cgit v1.2.3 From 56c589b8418d5197641ae4c0a83608b63aa0101f Mon Sep 17 00:00:00 2001 From: kcwu <kcwu@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Wed, 11 Sep 2002 09:47:32 +0000 Subject: quick hack to fix the clear_to_eol bug in board list the bug may still appear otherwhere git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@519 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/board.c | 5 ++--- pttbbs/mbbsd/screen.c | 4 +++- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/pttbbs/mbbsd/board.c b/pttbbs/mbbsd/board.c index 368241fb..e41f2c5f 100644 --- a/pttbbs/mbbsd/board.c +++ b/pttbbs/mbbsd/board.c @@ -1,4 +1,4 @@ -/* $Id: board.c,v 1.58 2002/09/11 07:16:49 kcwu Exp $ */ +/* $Id: board.c,v 1.59 2002/09/11 09:47:32 kcwu Exp $ */ #include "bbs.h" #define BRC_STRLEN 15 /* Length of board name */ #define BRC_MAXSIZE 24576 @@ -648,8 +648,7 @@ show_brdlist(int head, int clsflag, int newflag) prints("%2d ", ptr->bh->nuser); else prints(" %c ", ptr->bh->bvote ? 'V' : ' '); - prints("%.*s", t_columns - 67, ptr->bh->BM); - refresh(); + prints("%.*s\033[K", t_columns - 67, ptr->bh->BM); } else { prints("%-40.40s %.*s", ptr->bh->title + 7, t_columns - 67, ptr->bh->BM); diff --git a/pttbbs/mbbsd/screen.c b/pttbbs/mbbsd/screen.c index fb367618..76e1a6de 100644 --- a/pttbbs/mbbsd/screen.c +++ b/pttbbs/mbbsd/screen.c @@ -1,4 +1,4 @@ -/* $Id: screen.c,v 1.10 2002/09/11 07:16:49 kcwu Exp $ */ +/* $Id: screen.c,v 1.11 2002/09/11 09:47:32 kcwu Exp $ */ #include "bbs.h" #ifdef SUPPORT_GB @@ -194,6 +194,8 @@ refresh() } } if (bp->oldlen > len) { + /* XXX len/oldlen also count the length of escape sequence, + * before we fix it, we must print \033[K everywhere */ rel_move(tc_col, tc_line, len, i); o_cleol(); } -- cgit v1.2.3 From 24a96dbad6b3de642584473972165b314985251d Mon Sep 17 00:00:00 2001 From: kcwu <kcwu@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Wed, 11 Sep 2002 09:59:02 +0000 Subject: add TODO comment git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@520 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/screen.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pttbbs/mbbsd/screen.c b/pttbbs/mbbsd/screen.c index 76e1a6de..adf05df7 100644 --- a/pttbbs/mbbsd/screen.c +++ b/pttbbs/mbbsd/screen.c @@ -1,4 +1,4 @@ -/* $Id: screen.c,v 1.11 2002/09/11 09:47:32 kcwu Exp $ */ +/* $Id: screen.c,v 1.12 2002/09/11 09:59:02 kcwu Exp $ */ #include "bbs.h" #ifdef SUPPORT_GB @@ -140,6 +140,7 @@ redoscr() void refresh() { + /* TODO remove unnecessary refresh() call, to save CPU time */ register screenline_t *bp = big_picture; register int i, j, len; if (num_in_buf()) -- cgit v1.2.3 From 2e46e59ff7ca640b5c61b9f9d0cf57c1a6d11e60 Mon Sep 17 00:00:00 2001 From: kcwu <kcwu@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Wed, 11 Sep 2002 10:33:11 +0000 Subject: t_columns should not set as ANSILINELEN git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@521 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/screen.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pttbbs/mbbsd/screen.c b/pttbbs/mbbsd/screen.c index adf05df7..eefdbbea 100644 --- a/pttbbs/mbbsd/screen.c +++ b/pttbbs/mbbsd/screen.c @@ -1,4 +1,4 @@ -/* $Id: screen.c,v 1.12 2002/09/11 09:59:02 kcwu Exp $ */ +/* $Id: screen.c,v 1.13 2002/09/11 10:33:11 kcwu Exp $ */ #include "bbs.h" #ifdef SUPPORT_GB @@ -26,7 +26,7 @@ initscr() { if (!big_picture) { scr_lns = t_lines; - scr_cols = t_columns = ANSILINELEN; + scr_cols = ANSILINELEN; /* scr_cols = MIN(t_columns, ANSILINELEN); */ big_picture = (screenline_t *) calloc(scr_lns, sizeof(screenline_t)); docls = YEA; -- cgit v1.2.3 From 18f2f885fe961eae3461afd3d0d88e8ed93dc8a8 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sun, 15 Sep 2002 18:15:22 +0000 Subject: (userlist)long screen support git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@522 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/talk.c | 62 ++++++++++++++++++++++++++++------------------------- 1 file changed, 33 insertions(+), 29 deletions(-) diff --git a/pttbbs/mbbsd/talk.c b/pttbbs/mbbsd/talk.c index 478e6846..af8cd77b 100644 --- a/pttbbs/mbbsd/talk.c +++ b/pttbbs/mbbsd/talk.c @@ -1,4 +1,4 @@ -/* $Id: talk.c,v 1.92 2002/09/07 07:00:58 lwms Exp $ */ +/* $Id: talk.c,v 1.93 2002/09/15 18:15:22 in2 Exp $ */ #include "bbs.h" #define QCAST int (*)(const void *, const void *) @@ -1464,7 +1464,8 @@ descript(int show_mode, userinfo_t * uentp, time_t diff) } } -#define MAXPICKUP 20 +char nPickups; + static int sort_cmpfriend(const void *a, const void *b) { @@ -1486,7 +1487,7 @@ pickup_maxpages(int pickupway, int nfriends) else number = SHM->UTMPnumber + (pickupway == 0 ? nfriends : 0); - return (number - 1) / MAXPICKUP + 1; + return (number - 1) / nPickups + 1; } static int @@ -1559,7 +1560,7 @@ pickup(pickup_t * currpickup, int pickup_way, int *page, *myfriend = *friendme = 1; if (cuser.uflag & FRIEND_FLAG || - (pickup_way == 0 && *page * MAXPICKUP < MAX_FRIEND)) { + (pickup_way == 0 && *page * nPickups < MAX_FRIEND)) { /* * [嗨! 朋友] mode. we need to pickup ALL friends (from currutmp * friend_online), sort, and get pickup from right starting position @@ -1573,25 +1574,25 @@ pickup(pickup_t * currpickup, int pickup_way, int *page, else *bfriend = 0; *nfriend += *bfriend; - which = *page * MAXPICKUP; + which = *page * nPickups; if (*nfriend > which) { /* 只有在要秀出才有必要 sort */ qsort(friends, *nfriend, sizeof(pickup_t), sort_cmpfriend); size = *nfriend - which; - if (size > MAXPICKUP) - size = MAXPICKUP; + if (size > nPickups) + size = nPickups; memcpy(currpickup, friends + which, sizeof(pickup_t) * size); } } else *nfriend = 0; - if (!(cuser.uflag & FRIEND_FLAG) && size < MAXPICKUP) { + if (!(cuser.uflag & FRIEND_FLAG) && size < nPickups) { sorted_way = ((pickup_way == 0) ? 0 : (pickup_way - 1)); utmp = SHM->sorted[currsorted][sorted_way]; - which = *page * MAXPICKUP - *nfriend; + which = *page * nPickups - *nfriend; if (which < 0) which = 0; - for (; which < utmpnumber && size < MAXPICKUP; which++) { + for (; which < utmpnumber && size < nPickups; which++) { friend = friend_stat(currutmp, utmp[which]); if ((pickup_way || (currutmp != utmp[which] && !(friend & ST_FRIEND))) && @@ -1602,7 +1603,7 @@ pickup(pickup_t * currpickup, int pickup_way, int *page, } } /* - * for( which = (which >= 0 ? which : 0) ; got < MAXPICKUP && which + * for( which = (which >= 0 ? which : 0) ; got < nPickups && which * < utmpnumber ; ++got, ++which ){ * * for( ; which < utmpnumber ; ++which ) if( currutmp != utmp[which] && @@ -1611,7 +1612,7 @@ pickup(pickup_t * currpickup, int pickup_way, int *page, * currpickup[got].friend = 0; } */ - for (; size < MAXPICKUP; ++size) + for (; size < nPickups; ++size) currpickup[size].ui = 0; } @@ -1661,7 +1662,7 @@ draw_pickup(int drawall, pickup_t * pickup, int pickup_way, msg_pickup_way[pickup_way], SHM->UTMPnumber, myfriend, friendme, currutmp->brc_id ? (bfriend + 1) : 0, badfriend); - for (i = 0, ch = page * 20 + 1; i < MAXPICKUP; ++i, ++ch) { + for (i = 0, ch = page * nPickups + 1; i < nPickups; ++i, ++ch) { move(i + 3, 0); prints("a"); move(i + 3, 0); @@ -1774,18 +1775,20 @@ userlist(void) * pickup_maxpages : return max pages number of all list pickup_myfriend * : pickup friend (from friend_online) and sort */ - pickup_t currpickup[MAXPICKUP]; + pickup_t *currpickup; userinfo_t *uentp; - static int show_mode = 0; - static int show_uid = 0; - static int show_board = 0; - static int show_pid = 0; + static char show_mode = 0; + static char show_uid = 0; + static char show_board = 0; + static char show_pid = 0; char genbuf[256]; int page, offset, pickup_way, ch, leave, redraw, redrawall, fri_stat; int nfriend, myfriend, friendme, bfriend, badfriend, i; time_t lastupdate; + nPickups = b_lines - 3; + currpickup = (pickup_t *)malloc(sizeof(pickup_t) * nPickups); page = offset = 0; pickup_way = 0; leave = 0; @@ -1808,7 +1811,7 @@ userlist(void) * 以免指到沒有人的地方 */ if (offset == -1 || currpickup[offset].ui == NULL) { - for (offset = (offset == -1 ? MAXPICKUP - 1 : offset); + for (offset = (offset == -1 ? nPickups - 1 : offset); offset >= 0; --offset) if (currpickup[offset].ui != NULL) break; @@ -1845,7 +1848,7 @@ userlist(void) case KEY_DOWN: case 'n': case 'j': - if (++offset == MAXPICKUP || currpickup[offset].ui == NULL) { + if (++offset == nPickups || currpickup[offset].ui == NULL) { redraw = 1; if (++page >= pickup_maxpages(pickup_way, nfriend)) @@ -1920,7 +1923,7 @@ userlist(void) case KEY_UP: case 'k': if (--offset == -1) { - offset = MAXPICKUP - 1; + offset = nPickups - 1; if (--page == -1) page = pickup_maxpages(pickup_way, nfriend) - 1; @@ -1974,11 +1977,11 @@ userlist(void) if (friends[i].uoffset == fi) break; if (i != nGots) { - page = i / 20; - offset = i % 20; + page = i / nPickups; + offset = i % nPickups; } else { - page = (si + nGots) / 20; - offset = (si + nGots) % 20; + page = (si + nGots) / nPickups; + offset = (si + nGots) % nPickups; } } redrawall = redraw = 1; @@ -2001,15 +2004,15 @@ userlist(void) { /* Thor: 可以打數字跳到該人 */ int tmp; if ((tmp = search_num(ch, SHM->UTMPnumber)) >= 0) { - if (tmp / 20 == page) { + if (tmp / nPickups == page) { /* * in2:目的在目前這一頁, 直接 更新 offset , * 不用重畫畫面 */ - offset = tmp % 20; + offset = tmp % nPickups; } else { - page = tmp / 20; - offset = tmp % 20; + page = tmp / nPickups; + offset = tmp % nPickups; } redrawall = redraw = 1; } @@ -2288,6 +2291,7 @@ userlist(void) } } } + free(currpickup); } int -- cgit v1.2.3 From 51f37045c02d69ccac244cd5e37bcb71abbe92c4 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Wed, 18 Sep 2002 01:02:23 +0000 Subject: DEBUGSLEEP git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@523 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/mbbsd.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pttbbs/mbbsd/mbbsd.c b/pttbbs/mbbsd/mbbsd.c index 9309103e..b74a9a22 100644 --- a/pttbbs/mbbsd/mbbsd.c +++ b/pttbbs/mbbsd/mbbsd.c @@ -1,4 +1,4 @@ -/* $Id: mbbsd.c,v 1.56 2002/09/07 11:21:36 in2 Exp $ */ +/* $Id: mbbsd.c,v 1.57 2002/09/18 01:02:23 in2 Exp $ */ #include "bbs.h" #define SOCKET_QLEN 4 @@ -208,6 +208,7 @@ abort_bbs(int sig) static void abort_bbs_debug(int sig) { +#ifdef DEBUGSLEEP static int reentrant = 0; if (!reentrant) { @@ -221,6 +222,7 @@ abort_bbs_debug(int sig) setproctitle("debug me!(%d)(%s,%d)", sig, cuser.userid, currstat); sleep(3600); /* wait 60 mins for debug */ } +#endif exit(0); } -- cgit v1.2.3 From 20bf9b0770139ad2c3a702a78e2a66a870bc9e36 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Thu, 19 Sep 2002 21:19:39 +0000 Subject: url change git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@524 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/udnnews.pl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pttbbs/util/udnnews.pl b/pttbbs/util/udnnews.pl index 66ddc094..f75a50dd 100644 --- a/pttbbs/util/udnnews.pl +++ b/pttbbs/util/udnnews.pl @@ -22,7 +22,7 @@ foreach( @titles ){ postout({brdname => 'udnnews', title => FormatChinese($_->[1]), owner => 'udnnews.', - content => getudnnewscontent("http://udnnews.com/NEWS/FOCUSNEWS/$_->[0]")}); + content => getudnnewscontent("http://www.udn.com/NEWS/FOCUSNEWS/$_->[0]")}); } sub getudnnewscontent($) @@ -45,14 +45,14 @@ sub getudnnewscontent($) $ret .= FormatChinese($_, 60). "\n" if( $_ ); } return "※ [轉錄自 $url ]\n\n$ret\n\n". - "--\n感謝 http://www.udnnews.com/NEWS/ 熱情贊助"; + "--\n感謝 http://www.udn.com/ 熱情贊助"; } sub getudnnewstitle($) { my($ra_titles) = @_; my($url, $title); - open FH, "$LYNX -source http://udnnews.com/NEWS/FOCUSNEWS/ | $GREP '<font color=\"#FF9933\">' |"; + open FH, "$LYNX -source http://www.udn.com/NEWS/FOCUSNEWS/ | $GREP '<font color=\"#FF9933\">' |"; while( <FH> ){ ($url, $title) = $_ =~ m|<font color="#FF9933">.</font><a href="(.*?)"><font color="#003333">(.*?)</font></a><font color="#003333">|; $title =~ s/<.*?>//g; -- cgit v1.2.3 From 7929277c938670c3f5ca3147fd4b15bcd99f59ad Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Fri, 20 Sep 2002 13:37:46 +0000 Subject: fix bug for SYSOP change fromhost git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@525 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/talk.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pttbbs/mbbsd/talk.c b/pttbbs/mbbsd/talk.c index af8cd77b..52f35173 100644 --- a/pttbbs/mbbsd/talk.c +++ b/pttbbs/mbbsd/talk.c @@ -1,4 +1,4 @@ -/* $Id: talk.c,v 1.93 2002/09/15 18:15:22 in2 Exp $ */ +/* $Id: talk.c,v 1.94 2002/09/20 13:37:46 in2 Exp $ */ #include "bbs.h" #define QCAST int (*)(const void *, const void *) @@ -1890,7 +1890,7 @@ userlist(void) snprintf(buf, sizeof(buf), "故鄉 [%s]:", currutmp->from); if (!getdata(1, 0, buf, currutmp->from, sizeof(currutmp->from), DOECHO)) - strncpy(currutmp->from, fromhost, 23); + strncpy(currutmp->from, buf, 23); redrawall = redraw = 1; } break; -- cgit v1.2.3 From b270bc06332782e53d1b2b6108bc92c2b79b27e2 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Fri, 20 Sep 2002 15:04:04 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@526 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/lunar-1,15run.pl | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 pttbbs/util/lunar-1,15run.pl diff --git a/pttbbs/util/lunar-1,15run.pl b/pttbbs/util/lunar-1,15run.pl new file mode 100644 index 00000000..52ea8cea --- /dev/null +++ b/pttbbs/util/lunar-1,15run.pl @@ -0,0 +1,10 @@ +#!/usr/bin/perl +use LocalVars; +# 每農曆初一, 十五就會跑一次 $ARGV[0] +# 資料來源 http://tw.weathers.yahoo.com/ +open FH, "$LYNX -source http://tw.weathers.yahoo.com/ | grep '民國'|"; +$din = <FH>; +close FH; + +($month, $day) = $din =~ /農曆 (.*?)月 (.*?)日/; +system($ARGV[0]) if( $day eq '一' || $day eq '十五' ); -- cgit v1.2.3 From 94f99a779219e98924256d7431398236d9185611 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Fri, 20 Sep 2002 15:22:18 +0000 Subject: fix bug git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@527 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/lunar-1,15run.pl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pttbbs/util/lunar-1,15run.pl b/pttbbs/util/lunar-1,15run.pl index 52ea8cea..7a307027 100644 --- a/pttbbs/util/lunar-1,15run.pl +++ b/pttbbs/util/lunar-1,15run.pl @@ -1,4 +1,5 @@ #!/usr/bin/perl +use lib '/home/bbs/bin/'; use LocalVars; # 每農曆初一, 十五就會跑一次 $ARGV[0] # 資料來源 http://tw.weathers.yahoo.com/ @@ -7,4 +8,4 @@ $din = <FH>; close FH; ($month, $day) = $din =~ /農曆 (.*?)月 (.*?)日/; -system($ARGV[0]) if( $day eq '一' || $day eq '十五' ); +system("@ARGV") if( $day eq '一' || $day eq '十五' ); -- cgit v1.2.3 From 28af56bf4033a97ceaa4a84e8fd19f456195440e Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sat, 21 Sep 2002 05:11:38 +0000 Subject: fix bug git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@528 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/lunar-1,15run.pl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pttbbs/util/lunar-1,15run.pl b/pttbbs/util/lunar-1,15run.pl index 7a307027..d4cd2f20 100644 --- a/pttbbs/util/lunar-1,15run.pl +++ b/pttbbs/util/lunar-1,15run.pl @@ -8,4 +8,4 @@ $din = <FH>; close FH; ($month, $day) = $din =~ /農曆 (.*?)月 (.*?)日/; -system("@ARGV") if( $day eq '一' || $day eq '十五' ); +system("@ARGV") if( $day eq '一' || $day eq '一十五' ); -- cgit v1.2.3 From 4668e1cfd1834bac0b03cccd177ddb15a99b5727 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Wed, 25 Sep 2002 04:30:41 +0000 Subject: =?UTF-8?q?$content=20=3D~=20s/=EF=BF=BD=EF=BF=BD/=EF=BF=BD?= =?UTF-8?q?=EF=BF=BD/g;?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@529 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/udnnews.pl | 1 + 1 file changed, 1 insertion(+) diff --git a/pttbbs/util/udnnews.pl b/pttbbs/util/udnnews.pl index f75a50dd..4d37a26a 100644 --- a/pttbbs/util/udnnews.pl +++ b/pttbbs/util/udnnews.pl @@ -39,6 +39,7 @@ sub getudnnewscontent($) $content =~ s/\n\n\n/\n\n/g; $content =~ s/\n\n\n//g; $content =~ s/十/十/g; + $content =~ s/卅/卅/g; undef $ret; foreach( split(/\n/, $content) ){ s/ //g; -- cgit v1.2.3 From 69b889f7716bb232c81a120b4e500d8cb0cb2471 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Thu, 26 Sep 2002 16:18:36 +0000 Subject: only read favbuf & brdbuf before one need it, save them when logout if memory is correct (by MEM_CHECK) and they were loaded git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@530 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/board.c | 41 +++++++++++++++++++++++++++++++---------- pttbbs/mbbsd/mbbsd.c | 3 ++- 2 files changed, 33 insertions(+), 11 deletions(-) diff --git a/pttbbs/mbbsd/board.c b/pttbbs/mbbsd/board.c index e41f2c5f..4d76e8dd 100644 --- a/pttbbs/mbbsd/board.c +++ b/pttbbs/mbbsd/board.c @@ -1,4 +1,4 @@ -/* $Id: board.c,v 1.59 2002/09/11 09:47:32 kcwu Exp $ */ +/* $Id: board.c,v 1.60 2002/09/26 16:18:35 in2 Exp $ */ #include "bbs.h" #define BRC_STRLEN 15 /* Length of board name */ #define BRC_MAXSIZE 24576 @@ -233,8 +233,16 @@ void load_brdbuf(void) char fname[80]; size = (numboards + 32) * sizeof(int); +#ifdef MEM_CHECK + size += 4; +#endif zapbuf = (int *)malloc(size); favbuf = (int *)malloc(size); +#ifdef MEM_CHECK + zapbuf[0] = favbuf[0] = MEM_CHECK; + zapbuf = &zapbuf[1]; + favbuf = &favbuf[1]; +#endif zapchange = favchange = 0; if( firsttime ){ @@ -268,7 +276,7 @@ init_brdbuf() } void -free_brdbuf() +save_brdbuf() { int fd, size; char fname[60]; @@ -276,23 +284,40 @@ free_brdbuf() size = numboards * sizeof(int); setuserfile(fname, STR_BBSRC); if ( zapbuf != NULL ){ - if( zapchange && - (fd = open(fname, O_WRONLY | O_CREAT, 0600)) != -1) { + if( ( +#ifdef MEM_CHECK + zapbuf[-1] == MEM_CHECK && +#endif + zapchange && + (fd = open(fname, O_WRONLY | O_CREAT, 0600)) != -1) ){ write(fd, zapbuf, size); close(fd); } +#ifdef MEM_CHECK + free(&zapbuf[-1]); +#else free(zapbuf); +#endif zapbuf = NULL; } + setuserfile(fname, STR_FAV); if ( favbuf != NULL ){ - if( favchange && - (fd = open(fname, O_WRONLY | O_CREAT, 0600)) != -1) { + if( ( +#ifdef MEM_CHECK + favbuf[-1] == MEM_CHECK && +#endif + favchange && + (fd = open(fname, O_WRONLY | O_CREAT, 0600)) != -1) ){ size = numboards * sizeof(int); write(fd, favbuf, size); close(fd); } +#ifdef MEM_CHECK + free(&favbuf[-1]); +#else free(favbuf); +#endif favbuf = NULL; } } @@ -717,7 +742,6 @@ choose_board(int newflag) boardstat_t *ptr; int head = -1, ch = 0, currmodetmp, tmp, tmp1, bidtmp; char keyword[13] = ""; - static char depth = 0; #if HAVE_SEARCH_ALL char genbuf[200]; #endif @@ -725,7 +749,6 @@ choose_board(int newflag) setutmpmode(newflag ? READNEW : READBRD); if( zapbuf == NULL || favbuf == NULL ) load_brdbuf(); - ++depth; brdnum = 0; if (!cuser.userlevel) /* guest yank all boards */ yank_flag = 2; @@ -1090,8 +1113,6 @@ choose_board(int newflag) } } while (ch != 'q'); free(nbrd); - if( --depth == 0 ) - free_brdbuf(); } int diff --git a/pttbbs/mbbsd/mbbsd.c b/pttbbs/mbbsd/mbbsd.c index b74a9a22..0adb2756 100644 --- a/pttbbs/mbbsd/mbbsd.c +++ b/pttbbs/mbbsd/mbbsd.c @@ -1,4 +1,4 @@ -/* $Id: mbbsd.c,v 1.57 2002/09/18 01:02:23 in2 Exp $ */ +/* $Id: mbbsd.c,v 1.58 2002/09/26 16:18:36 in2 Exp $ */ #include "bbs.h" #define SOCKET_QLEN 4 @@ -166,6 +166,7 @@ u_exit(char *mode) auto_backup(); setflags(PAGER_FLAG, currutmp->pager != 1); setflags(CLOAK_FLAG, currutmp->invisible); + save_brdbuf(); cuser.invisible = currutmp->invisible; cuser.pager = currutmp->pager; -- cgit v1.2.3 From 52ddc032f17358a7a9a3978215a2d0f61b09a3ec Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Thu, 26 Sep 2002 16:24:38 +0000 Subject: avoid reentrant git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@531 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/board.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pttbbs/mbbsd/board.c b/pttbbs/mbbsd/board.c index 4d76e8dd..c7c84262 100644 --- a/pttbbs/mbbsd/board.c +++ b/pttbbs/mbbsd/board.c @@ -1,4 +1,4 @@ -/* $Id: board.c,v 1.60 2002/09/26 16:18:35 in2 Exp $ */ +/* $Id: board.c,v 1.61 2002/09/26 16:24:38 in2 Exp $ */ #include "bbs.h" #define BRC_STRLEN 15 /* Length of board name */ #define BRC_MAXSIZE 24576 @@ -280,6 +280,11 @@ save_brdbuf() { int fd, size; char fname[60]; + static char reentrant = 0; + + if( reentrant ) + return; + reentrant = 1; size = numboards * sizeof(int); setuserfile(fname, STR_BBSRC); -- cgit v1.2.3 From 53b9a3a3cced41f09fda3a37618314168cb2a698 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Thu, 26 Sep 2002 18:16:12 +0000 Subject: mvdir git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@532 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/mvdir.pl | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 pttbbs/util/mvdir.pl diff --git a/pttbbs/util/mvdir.pl b/pttbbs/util/mvdir.pl new file mode 100644 index 00000000..1587b799 --- /dev/null +++ b/pttbbs/util/mvdir.pl @@ -0,0 +1,35 @@ +#!/usr/bin/perl +if( !@ARGV ){ + print "usage: mvdir.pl which prefix from_id to_id\n"; + exit; +} + +($which, $prefix, $from_id, $to_id) = @ARGV; +$which = 'man/boards' if( $which eq 'man' ); + +$fromdir = "/scsi$from_id/bbs/$which/$prefix"; +$todir = "/scsi$to_id/bbs/$which/$prefix"; + +if( !-e $fromdir ){ + print "from dir ($fromdir) not found\n"; + exit; +} + +mkdir $todir; +chdir $fromdir; +foreach( <*> ){ + next if( /^\./ ); + symlink("$fromdir/$_", "$todir/$_"); + push @dirs, $_; +} + +unlink "/home/bbs/$which/$prefix"; +symlink($todir, "/home/bbs/$which/$prefix"); + +foreach( @dirs ){ + printf("processing %-20s (%04d/%04d)\n", $_, ++$index, $#dirs); + unlink "$todir/$_"; + `mv $fromdir/$_ $todir/$_`; +} + +rmdir "$fromdir"; -- cgit v1.2.3 From 5175d8c924c84645e07029fe4788d9100f6b5afb Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Mon, 30 Sep 2002 05:42:58 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@533 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/mvdir.pl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pttbbs/util/mvdir.pl b/pttbbs/util/mvdir.pl index 1587b799..b88cab28 100644 --- a/pttbbs/util/mvdir.pl +++ b/pttbbs/util/mvdir.pl @@ -5,10 +5,10 @@ if( !@ARGV ){ } ($which, $prefix, $from_id, $to_id) = @ARGV; -$which = 'man/boards' if( $which eq 'man' ); $fromdir = "/scsi$from_id/bbs/$which/$prefix"; $todir = "/scsi$to_id/bbs/$which/$prefix"; +$sym = ($which eq 'man' ? "/home/bbs/man/boards/$prefix" : "/home/bbs/$which/$prefix"); if( !-e $fromdir ){ print "from dir ($fromdir) not found\n"; @@ -23,8 +23,8 @@ foreach( <*> ){ push @dirs, $_; } -unlink "/home/bbs/$which/$prefix"; -symlink($todir, "/home/bbs/$which/$prefix"); +unlink $sym; +symlink($todir, $sym); foreach( @dirs ){ printf("processing %-20s (%04d/%04d)\n", $_, ++$index, $#dirs); -- cgit v1.2.3 From 4f2ef40eefa072364b27e9f71a330d9505200e64 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Tue, 1 Oct 2002 16:02:27 +0000 Subject: KEY_DEL, KEY_HOME, KEY_END of getdata() git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@534 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/io.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pttbbs/mbbsd/io.c b/pttbbs/mbbsd/io.c index 82895f28..84683ce8 100644 --- a/pttbbs/mbbsd/io.c +++ b/pttbbs/mbbsd/io.c @@ -1,4 +1,4 @@ -/* $Id: io.c,v 1.23 2002/09/11 03:22:50 kcwu Exp $ */ +/* $Id: io.c,v 1.24 2002/10/01 16:02:27 in2 Exp $ */ #include "bbs.h" #if defined(linux) @@ -433,6 +433,7 @@ oldgetdata(int line, int col, char *prompt, char *buf, int len, int echo) clen = currchar; break; case Ctrl('D'): + case KEY_DEL: if (buf[currchar]) { clen--; for (i = currchar; i <= clen; i++) @@ -444,9 +445,11 @@ oldgetdata(int line, int col, char *prompt, char *buf, int len, int echo) } break; case Ctrl('A'): + case KEY_HOME: currchar = 0; break; case Ctrl('E'): + case KEY_END: currchar = clen; break; default: -- cgit v1.2.3 From f0cd184927f455a8c5b44a81dcbb5069adac2fec Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sat, 5 Oct 2002 05:23:01 +0000 Subject: fix host bug git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@535 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/waterball.pl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pttbbs/util/waterball.pl b/pttbbs/util/waterball.pl index 63443027..2cfa2a61 100644 --- a/pttbbs/util/waterball.pl +++ b/pttbbs/util/waterball.pl @@ -49,7 +49,7 @@ foreach $fndes ( <$JOBSPOOL/water.des.*> ){ #des: userid, mailto, outmode mailto => "$userid <$mailto>", subject => "水球紀錄", body => - "\n ptt2 站長群 ". POSIX::ctime(time())} + "\n $hostname 站長群 ". POSIX::ctime(time())} ) ){ unlink $fnsrc; unlink $fndes; @@ -127,7 +127,7 @@ sub MakeMail `$TAR zcf $arg->{tartarget} $arg->{tarsource}` if( $arg->{tarsource} ); $sender = new Mail::Sender{smtp => $SMTPSERVER, - from => "$hostname水球整理程式 <$userid.bbs\@ptt2.csie.ntu.edu.tw>"}; + from => "$hostname水球整理程式 <$userid.bbs\@$MYHOSTNAME>"}; foreach( 0..3 ){ if( (!$arg->{tartarget} && $sender->MailMsg({to => $arg->{mailto}, @@ -143,7 +143,7 @@ sub MakeMail return 1; } } - $sender->MailMsg({to => "$userid.bbs\@localhost", + $sender->MailMsg({to => "$userid.bbs\@$MYHOSTNAME", subject => "無法寄出水球整理", msg => "親愛的使用者您好\n\n". -- cgit v1.2.3 From 454ba78e58a18107aac3ee10572c010568bdbd80 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sat, 5 Oct 2002 16:08:53 +0000 Subject: first commit git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@536 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/web/.cvsignore | 3 + pttbbs/web/Makefile | 4 + pttbbs/web/mod_ptt.c | 1064 +++++++++++++++++++++++++++++++++++++++++++++++ pttbbs/web/mod_ptt.h | 17 + pttbbs/web/mytime.h | 189 +++++++++ pttbbs/web/parse_html.c | 294 +++++++++++++ 6 files changed, 1571 insertions(+) create mode 100644 pttbbs/web/.cvsignore create mode 100644 pttbbs/web/Makefile create mode 100644 pttbbs/web/mod_ptt.c create mode 100644 pttbbs/web/mod_ptt.h create mode 100755 pttbbs/web/mytime.h create mode 100755 pttbbs/web/parse_html.c diff --git a/pttbbs/web/.cvsignore b/pttbbs/web/.cvsignore new file mode 100644 index 00000000..33ec1741 --- /dev/null +++ b/pttbbs/web/.cvsignore @@ -0,0 +1,3 @@ +*.o +*.so +*.a diff --git a/pttbbs/web/Makefile b/pttbbs/web/Makefile new file mode 100644 index 00000000..44830419 --- /dev/null +++ b/pttbbs/web/Makefile @@ -0,0 +1,4 @@ +all: mod_ptt.c mod_ptt.h + apxs -I ../include -c mod_ptt.c + cp mod_ptt.so /usr/local/libexec/apache/mod_ptt.so + chmod 755 /usr/local/libexec/apache/mod_ptt.so diff --git a/pttbbs/web/mod_ptt.c b/pttbbs/web/mod_ptt.c new file mode 100644 index 00000000..a6427a32 --- /dev/null +++ b/pttbbs/web/mod_ptt.c @@ -0,0 +1,1064 @@ +/* + * Apache example module. Provide demonstrations of how modules do things. + * + */ + +#include "mod_ptt.h" +extern int numboards; +extern boardheader_t *bcache; +/*--------------------------------------------------------------------------*/ +/* */ +/* Data declarations. */ +/* */ +/* Here are the static cells and structure declarations private to our */ +/* module. */ +/* */ +/*--------------------------------------------------------------------------*/ + +/* + * Sample configuration record. Used for both per-directory and per-server + * configuration data. + * + * It's perfectly reasonable to have two different structures for the two + * different environments. The same command handlers will be called for + * both, though, so the handlers need to be able to tell them apart. One + * possibility is for both structures to start with an int which is zero for + * one and 1 for the other. + * + * Note that while the per-directory and per-server configuration records are + * available to most of the module handlers, they should be treated as + * READ-ONLY by all except the command and merge handlers. Sometimes handlers + * are handed a record that applies to the current location by implication or + * inheritance, and modifying it will change the rules for other locations. + */ +typedef struct excfg { + int cmode; /* Environment to which record applies (directory, + * server, or combination). + */ +#define CONFIG_MODE_SERVER 1 +#define CONFIG_MODE_DIRECTORY 2 +#define CONFIG_MODE_COMBO 3 /* Shouldn't ever happen. */ + int local; /* Boolean: "Example" directive declared here? */ + int congenital; /* Boolean: did we inherit an "Example"? */ + char *trace; /* Pointer to trace string. */ + char *loc; /* Location to which this record applies. */ +} excfg; + +/* + * Let's set up a module-local static cell to point to the accreting callback + * trace. As each API callback is made to us, we'll tack on the particulars + * to whatever we've already recorded. To avoid massive memory bloat as + * directories are walked again and again, we record the routine/environment + * the first time (non-request context only), and ignore subsequent calls for + * the same routine/environment. + */ +static const char *trace = NULL; +static table *static_calls_made = NULL; + +/* + * To avoid leaking memory from pools other than the per-request one, we + * allocate a module-private pool, and then use a sub-pool of that which gets + * freed each time we modify the trace. That way previous layers of trace + * data don't get lost. + */ +static pool *ptt_pool = NULL; +static pool *ptt_subpool = NULL; + +/* + * Declare ourselves so the configuration routines can find and know us. + * We'll fill it in at the end of the module. + */ +module MODULE_VAR_EXPORT ptt_module; + +/*--------------------------------------------------------------------------*/ +/* */ +/* The following pseudo-prototype declarations illustrate the parameters */ +/* passed to command handlers for the different types of directive */ +/* syntax. If an argument was specified in the directive definition */ +/* (look for "command_rec" below), it's available to the command handler */ +/* via the (void *) info field in the cmd_parms argument passed to the */ +/* handler (cmd->info for the examples below). */ +/* */ +/*--------------------------------------------------------------------------*/ + +/* + * Command handler for a NO_ARGS directive. + * + * static const char *handle_NO_ARGS(cmd_parms *cmd, void *mconfig); + */ + +/* + * Command handler for a RAW_ARGS directive. The "args" argument is the text + * of the commandline following the directive itself. + * + * static const char *handle_RAW_ARGS(cmd_parms *cmd, void *mconfig, + * const char *args); + */ + +/* + * Command handler for a FLAG directive. The single parameter is passed in + * "bool", which is either zero or not for Off or On respectively. + * + * static const char *handle_FLAG(cmd_parms *cmd, void *mconfig, int bool); + */ + +/* + * Command handler for a TAKE1 directive. The single parameter is passed in + * "word1". + * + * static const char *handle_TAKE1(cmd_parms *cmd, void *mconfig, + * char *word1); + */ + +/* + * Command handler for a TAKE2 directive. TAKE2 commands must always have + * exactly two arguments. + * + * static const char *handle_TAKE2(cmd_parms *cmd, void *mconfig, + * char *word1, char *word2); + */ + +/* + * Command handler for a TAKE3 directive. Like TAKE2, these must have exactly + * three arguments, or the parser complains and doesn't bother calling us. + * + * static const char *handle_TAKE3(cmd_parms *cmd, void *mconfig, + * char *word1, char *word2, char *word3); + */ + +/* + * Command handler for a TAKE12 directive. These can take either one or two + * arguments. + * - word2 is a NULL pointer if no second argument was specified. + * + * static const char *handle_TAKE12(cmd_parms *cmd, void *mconfig, + * char *word1, char *word2); + */ + +/* + * Command handler for a TAKE123 directive. A TAKE123 directive can be given, + * as might be expected, one, two, or three arguments. + * - word2 is a NULL pointer if no second argument was specified. + * - word3 is a NULL pointer if no third argument was specified. + * + * static const char *handle_TAKE123(cmd_parms *cmd, void *mconfig, + * char *word1, char *word2, char *word3); + */ + +/* + * Command handler for a TAKE13 directive. Either one or three arguments are + * permitted - no two-parameters-only syntax is allowed. + * - word2 and word3 are NULL pointers if only one argument was specified. + * + * static const char *handle_TAKE13(cmd_parms *cmd, void *mconfig, + * char *word1, char *word2, char *word3); + */ + +/* + * Command handler for a TAKE23 directive. At least two and as many as three + * arguments must be specified. + * - word3 is a NULL pointer if no third argument was specified. + * + * static const char *handle_TAKE23(cmd_parms *cmd, void *mconfig, + * char *word1, char *word2, char *word3); + */ + +/* + * Command handler for a ITERATE directive. + * - Handler is called once for each of n arguments given to the directive. + * - word1 points to each argument in turn. + * + * static const char *handle_ITERATE(cmd_parms *cmd, void *mconfig, + * char *word1); + */ + +/* + * Command handler for a ITERATE2 directive. + * - Handler is called once for each of the second and subsequent arguments + * given to the directive. + * - word1 is the same for each call for a particular directive instance (the + * first argument). + * - word2 points to each of the second and subsequent arguments in turn. + * + * static const char *handle_ITERATE2(cmd_parms *cmd, void *mconfig, + * char *word1, char *word2); + */ + +/*--------------------------------------------------------------------------*/ +/* */ +/* These routines are strictly internal to this module, and support its */ +/* operation. They are not referenced by any external portion of the */ +/* server. */ +/* */ +/*--------------------------------------------------------------------------*/ + +/* + * Locate our directory configuration record for the current request. + */ +static excfg *our_dconfig(request_rec *r) +{ + + return (excfg *) ap_get_module_config(r->per_dir_config, &ptt_module); +} + +#if 0 +/* + * Locate our server configuration record for the specified server. + */ +static excfg *our_sconfig(server_rec *s) +{ + + return (excfg *) ap_get_module_config(s->module_config, &ptt_module); +} + +/* + * Likewise for our configuration record for the specified request. + */ +static excfg *our_rconfig(request_rec *r) +{ + + return (excfg *) ap_get_module_config(r->request_config, &ptt_module); +} +#endif + +/* + * This routine sets up some module-wide cells if they haven't been already. + */ +static void setup_module_cells() +{ + /* + * If we haven't already allocated our module-private pool, do so now. + */ + if (ptt_pool == NULL) { + ptt_pool = ap_make_sub_pool(NULL); + }; + /* + * Likewise for the table of routine/environment pairs we visit outside of + * request context. + */ + if (static_calls_made == NULL) { + static_calls_made = ap_make_table(ptt_pool, 16); + }; +} + +/* + * This routine is used to add a trace of a callback to the list. We're + * passed the server record (if available), the request record (if available), + * a pointer to our private configuration record (if available) for the + * environment to which the callback is supposed to apply, and some text. We + * turn this into a textual representation and add it to the tail of the list. + * The list can be displayed by the example_handler() routine. + * + * If the call occurs within a request context (i.e., we're passed a request + * record), we put the trace into the request pool and attach it to the + * request via the notes mechanism. Otherwise, the trace gets added + * to the static (non-request-specific) list. + * + * Note that the r->notes table is only for storing strings; if you need to + * maintain per-request data of any other type, you need to use another + * mechanism. + */ + +#define TRACE_NOTE "ptt-trace" + +static void trace_add(server_rec *s, request_rec *r, excfg *mconfig, + const char *note) +{ + + const char *sofar; + char *addon; + char *where; + pool *p; + const char *trace_copy; + + /* + * Make sure our pools and tables are set up - we need 'em. + */ + setup_module_cells(); + /* + * Now, if we're in request-context, we use the request pool. + */ + if (r != NULL) { + p = r->pool; + if ((trace_copy = ap_table_get(r->notes, TRACE_NOTE)) == NULL) { + trace_copy = ""; + } + } + else { + /* + * We're not in request context, so the trace gets attached to our + * module-wide pool. We do the create/destroy every time we're called + * in non-request context; this avoids leaking memory in some of + * the subsequent calls that allocate memory only once (such as the + * key formation below). + * + * Make a new sub-pool and copy any existing trace to it. Point the + * trace cell at the copied value. + */ + p = ap_make_sub_pool(ptt_pool); + if (trace != NULL) { + trace = ap_pstrdup(p, trace); + } + /* + * Now, if we have a sub-pool from before, nuke it and replace with + * the one we just allocated. + */ + if (ptt_subpool != NULL) { + ap_destroy_pool(ptt_subpool); + } + ptt_subpool = p; + trace_copy = trace; + } + /* + * If we weren't passed a configuration record, we can't figure out to + * what location this call applies. This only happens for co-routines + * that don't operate in a particular directory or server context. If we + * got a valid record, extract the location (directory or server) to which + * it applies. + */ + where = (mconfig != NULL) ? mconfig->loc : "nowhere"; + where = (where != NULL) ? where : ""; + /* + * Now, if we're not in request context, see if we've been called with + * this particular combination before. The table is allocated in the + * module's private pool, which doesn't get destroyed. + */ + if (r == NULL) { + char *key; + + key = ap_pstrcat(p, note, ":", where, NULL); + if (ap_table_get(static_calls_made, key) != NULL) { + /* + * Been here, done this. + */ + return; + } + else { + /* + * First time for this combination of routine and environment - + * log it so we don't do it again. + */ + ap_table_set(static_calls_made, key, "been here"); + } + } + addon = ap_pstrcat(p, " <LI>\n", " <DL>\n", " <DT><SAMP>", + note, "</SAMP>\n", " </DT>\n", " <DD><SAMP>[", + where, "]</SAMP>\n", " </DD>\n", " </DL>\n", + " </LI>\n", NULL); + sofar = (trace_copy == NULL) ? "" : trace_copy; + trace_copy = ap_pstrcat(p, sofar, addon, NULL); + if (r != NULL) { + ap_table_set(r->notes, TRACE_NOTE, trace_copy); + } + else { + trace = trace_copy; + } + /* + * You *could* change the following if you wanted to see the calling + * sequence reported in the server's error_log, but beware - almost all of + * these co-routines are called for every single request, and the impact + * on the size (and readability) of the error_log is considerable. + */ +#define EXAMPLE_LOG_EACH 0 +#if EXAMPLE_LOG_EACH + if (s != NULL) { + ap_log_error(APLOG_MARK, APLOG_DEBUG, s, "mod_ptt: %s", note); + } +#endif +} + +/*--------------------------------------------------------------------------*/ +/* We prototyped the various syntax for command handlers (routines that */ +/* are called when the configuration parser detects a directive declared */ +/* by our module) earlier. Now we actually declare a "real" routine that */ +/* will be invoked by the parser when our "real" directive is */ +/* encountered. */ +/* */ +/* If a command handler encounters a problem processing the directive, it */ +/* signals this fact by returning a non-NULL pointer to a string */ +/* describing the problem. */ +/* */ +/* The magic return value DECLINE_CMD is used to deal with directives */ +/* that might be declared by multiple modules. If the command handler */ +/* returns NULL, the directive was processed; if it returns DECLINE_CMD, */ +/* the next module (if any) that declares the directive is given a chance */ +/* at it. If it returns any other value, it's treated as the text of an */ +/* error message. */ +/*--------------------------------------------------------------------------*/ +/* + * Command handler for the NO_ARGS "Example" directive. All we do is mark the + * call in the trace log, and flag the applicability of the directive to the + * current location in that location's configuration record. + */ +static const char *cmd_ptt(cmd_parms *cmd, void *mconfig) +{ + + excfg *cfg = (excfg *) mconfig; + + /* + * "Example Wuz Here" + */ + cfg->local = 1; + trace_add(cmd->server, NULL, cfg, "cmd_ptt()"); + return NULL; +} + +/*--------------------------------------------------------------------------*/ +/* */ +/* Now we declare our content handlers, which are invoked when the server */ +/* encounters a document which our module is supposed to have a chance to */ +/* see. (See mod_mime's SetHandler and AddHandler directives, and the */ +/* mod_info and mod_status examples, for more details.) */ +/* */ +/* Since content handlers are dumping data directly into the connexion */ +/* (using the r*() routines, such as rputs() and rprintf()) without */ +/* intervention by other parts of the server, they need to make */ +/* sure any accumulated HTTP headers are sent first. This is done by */ +/* calling send_http_header(). Otherwise, no header will be sent at all, */ +/* and the output sent to the client will actually be HTTP-uncompliant. */ +/*--------------------------------------------------------------------------*/ +/* + * Sample content handler. All this does is display the call list that has + * been built up so far. + * + * The return value instructs the caller concerning what happened and what to + * do next: + * OK ("we did our thing") + * DECLINED ("this isn't something with which we want to get involved") + * HTTP_mumble ("an error status should be reported") + */ +static int ptt_handler(request_rec *r) +{ + int i; + excfg *dcfg; + + dcfg = our_dconfig(r); + trace_add(r->server, r, dcfg, "ptt_handler()"); + /* + * We're about to start sending content, so we need to force the HTTP + * headers to be sent at this point. Otherwise, no headers will be sent + * at all. We can set any we like first, of course. **NOTE** Here's + * where you set the "Content-type" header, and you do so by putting it in + * r->content_type, *not* r->headers_out("Content-type"). If you don't + * set it, it will be filled in with the server's default type (typically + * "text/plain"). You *must* also ensure that r->content_type is lower + * case. + * + * We also need to start a timer so the server can know if the connexion + * is broken. + */ + r->content_type = "text/html"; + + ap_soft_timeout("send ptt call trace", r); + ap_send_http_header(r); +#ifdef CHARSET_EBCDIC + /* Server-generated response, converted */ + ap_bsetflag(r->connection->client, B_EBCDIC2ASCII, r->ebcdic.conv_out = 1); +#endif + + /* + * If we're only supposed to send header information (HEAD request), we're + * already there. + */ + if (r->header_only) { + ap_kill_timeout(r); + return OK; + } + + /* + * Now send our actual output. Since we tagged this as being + * "text/html", we need to embed any HTML. + */ + ap_rputs(" ptt3 <P>\n", r); + + ap_rprintf(r, " Apache HTTP Server version: \"%s\"\n", + ap_get_server_version()); + ap_rprintf(r,"r->filename : %s <br>",r->filename); + ap_rprintf(r,"r->request_time : %s <br>",ctime(&r->request_time)); + ap_rprintf(r,"r->method : %s <br>",r->method); + ap_rprintf(r,"r->method_number : %d <br>",r->method_number); + ap_rprintf(r,"r->path_info : %s <br>",r->path_info); + ap_rprintf(r,"r->args : %s <br>",r->args); + ap_rprintf(r,"r->unparsed_uri : %s <br>",r->unparsed_uri); + ap_rprintf(r,"r->handler : %s <br>",r->handler); + ap_rprintf(r,"r->content_type : %s <br>",r->content_type); + ap_rprintf(r, " Server built: \"%s\"\n", ap_get_server_built()); + + for(i = 0; i++ < numboards; i++) + ap_rprintf(r,"%s %s<br>",bcache[i].brdname,bcache[i].title); + /* + * We're all done, so cancel the timeout we set. Since this is probably + * the end of the request we *could* assume this would be done during + * post-processing - but it's possible that another handler might be + * called and inherit our outstanding timer. Not good; to each its own. + */ + ap_kill_timeout(r); + /* + * We did what we wanted to do, so tell the rest of the server we + * succeeded. + */ + return OK; +} + +/*--------------------------------------------------------------------------*/ +/* */ +/* Now let's declare routines for each of the callback phase in order. */ +/* (That's the order in which they're listed in the callback list, *not */ +/* the order in which the server calls them! See the command_rec */ +/* declaration near the bottom of this file.) Note that these may be */ +/* called for situations that don't relate primarily to our function - in */ +/* other words, the fixup handler shouldn't assume that the request has */ +/* to do with "example" stuff. */ +/* */ +/* With the exception of the content handler, all of our routines will be */ +/* called for each request, unless an earlier handler from another module */ +/* aborted the sequence. */ +/* */ +/* Handlers that are declared as "int" can return the following: */ +/* */ +/* OK Handler accepted the request and did its thing with it. */ +/* DECLINED Handler took no action. */ +/* HTTP_mumble Handler looked at request and found it wanting. */ +/* */ +/* What the server does after calling a module handler depends upon the */ +/* handler's return value. In all cases, if the handler returns */ +/* DECLINED, the server will continue to the next module with an handler */ +/* for the current phase. However, if the handler return a non-OK, */ +/* non-DECLINED status, the server aborts the request right there. If */ +/* the handler returns OK, the server's next action is phase-specific; */ +/* see the individual handler comments below for details. */ +/* */ +/*--------------------------------------------------------------------------*/ +/* + * This function is called during server initialisation. Any information + * that needs to be recorded must be in static cells, since there's no + * configuration record. + * + * There is no return value. + */ + +/* + * All our module-initialiser does is add its trace to the log. + */ +static void ptt_init(server_rec *s, pool *p) +{ + + char *note; + char *sname = s->server_hostname; + + /* + * Set up any module cells that ought to be initialised. + */ + setup_module_cells(); + /* + * The arbitrary text we add to our trace entry indicates for which server + * we're being called. + */ + sname = (sname != NULL) ? sname : ""; + note = ap_pstrcat(p, "ptt_init(", sname, ")", NULL); + trace_add(s, NULL, NULL, note); +} + +/* + * This function is called during server initialisation when an heavy-weight + * process (such as a child) is being initialised. As with the + * module-initialisation function, any information that needs to be recorded + * must be in static cells, since there's no configuration record. + * + * There is no return value. + */ + +/* + * All our process-initialiser does is add its trace to the log. + */ +static void ptt_child_init(server_rec *s, pool *p) +{ + + char *note; + char *sname = s->server_hostname; + + resolve_utmp(); + resolve_boards(); + resolve_garbage(); + resolve_fcache(); + /* + * Set up any module cells that ought to be initialised. + */ + setup_module_cells(); + /* + * The arbitrary text we add to our trace entry indicates for which server + * we're being called. + */ + sname = (sname != NULL) ? sname : ""; + note = ap_pstrcat(p, "ptt_child_init(", sname, ")", NULL); + trace_add(s, NULL, NULL, note); +} + +/* + * This function is called when an heavy-weight process (such as a child) is + * being run down or destroyed. As with the child-initialisation function, + * any information that needs to be recorded must be in static cells, since + * there's no configuration record. + * + * There is no return value. + */ + +/* + * All our process-death routine does is add its trace to the log. + */ +static void ptt_child_exit(server_rec *s, pool *p) +{ + + char *note; + char *sname = s->server_hostname; + + /* + * The arbitrary text we add to our trace entry indicates for which server + * we're being called. + */ + sname = (sname != NULL) ? sname : ""; + note = ap_pstrcat(p, "ptt_child_exit(", sname, ")", NULL); + trace_add(s, NULL, NULL, note); +} + +/* + * This function gets called to create a per-directory configuration + * record. This will be called for the "default" server environment, and for + * each directory for which the parser finds any of our directives applicable. + * If a directory doesn't have any of our directives involved (i.e., they + * aren't in the .htaccess file, or a <Location>, <Directory>, or related + * block), this routine will *not* be called - the configuration for the + * closest ancestor is used. + * + * The return value is a pointer to the created module-specific + * structure. + */ +static void *ptt_create_dir_config(pool *p, char *dirspec) +{ + + excfg *cfg; + char *dname = dirspec; + + /* + * Allocate the space for our record from the pool supplied. + */ + cfg = (excfg *) ap_pcalloc(p, sizeof(excfg)); + /* + * Now fill in the defaults. If there are any `parent' configuration + * records, they'll get merged as part of a separate callback. + */ + cfg->local = 0; + cfg->congenital = 0; + cfg->cmode = CONFIG_MODE_DIRECTORY; + /* + * Finally, add our trace to the callback list. + */ + dname = (dname != NULL) ? dname : ""; + cfg->loc = ap_pstrcat(p, "DIR(", dname, ")", NULL); + trace_add(NULL, NULL, cfg, "ptt_create_dir_config()"); + return (void *) cfg; +} + +/* + * This function gets called to merge two per-directory configuration + * records. This is typically done to cope with things like .htaccess files + * or <Location> directives for directories that are beneath one for which a + * configuration record was already created. The routine has the + * responsibility of creating a new record and merging the contents of the + * other two into it appropriately. If the module doesn't declare a merge + * routine, the record for the closest ancestor location (that has one) is + * used exclusively. + * + * The routine MUST NOT modify any of its arguments! + * + * The return value is a pointer to the created module-specific structure + * containing the merged values. + */ +static void *ptt_merge_dir_config(pool *p, void *parent_conf, + void *newloc_conf) +{ + + excfg *merged_config = (excfg *) ap_pcalloc(p, sizeof(excfg)); + excfg *pconf = (excfg *) parent_conf; + excfg *nconf = (excfg *) newloc_conf; + char *note; + + /* + * Some things get copied directly from the more-specific record, rather + * than getting merged. + */ + merged_config->local = nconf->local; + merged_config->loc = ap_pstrdup(p, nconf->loc); + /* + * Others, like the setting of the `congenital' flag, get ORed in. The + * setting of that particular flag, for instance, is TRUE if it was ever + * true anywhere in the upstream configuration. + */ + merged_config->congenital = (pconf->congenital | pconf->local); + /* + * If we're merging records for two different types of environment (server + * and directory), mark the new record appropriately. Otherwise, inherit + * the current value. + */ + merged_config->cmode = + (pconf->cmode == nconf->cmode) ? pconf->cmode : CONFIG_MODE_COMBO; + /* + * Now just record our being called in the trace list. Include the + * locations we were asked to merge. + */ + note = ap_pstrcat(p, "ptt_merge_dir_config(\"", pconf->loc, "\",\"", + nconf->loc, "\")", NULL); + trace_add(NULL, NULL, merged_config, note); + return (void *) merged_config; +} + +/* + * This function gets called to create a per-server configuration + * record. It will always be called for the "default" server. + * + * The return value is a pointer to the created module-specific + * structure. + */ +static void *ptt_create_server_config(pool *p, server_rec *s) +{ + + excfg *cfg; + char *sname = s->server_hostname; + + /* + * As with the ptt_create_dir_config() reoutine, we allocate and fill + * in an empty record. + */ + cfg = (excfg *) ap_pcalloc(p, sizeof(excfg)); + cfg->local = 0; + cfg->congenital = 0; + cfg->cmode = CONFIG_MODE_SERVER; + /* + * Note that we were called in the trace list. + */ + sname = (sname != NULL) ? sname : ""; + cfg->loc = ap_pstrcat(p, "SVR(", sname, ")", NULL); + trace_add(s, NULL, cfg, "ptt_create_server_config()"); + return (void *) cfg; +} + +/* + * This function gets called to merge two per-server configuration + * records. This is typically done to cope with things like virtual hosts and + * the default server configuration The routine has the responsibility of + * creating a new record and merging the contents of the other two into it + * appropriately. If the module doesn't declare a merge routine, the more + * specific existing record is used exclusively. + * + * The routine MUST NOT modify any of its arguments! + * + * The return value is a pointer to the created module-specific structure + * containing the merged values. + */ +static void *ptt_merge_server_config(pool *p, void *server1_conf, + void *server2_conf) +{ + + excfg *merged_config = (excfg *) ap_pcalloc(p, sizeof(excfg)); + excfg *s1conf = (excfg *) server1_conf; + excfg *s2conf = (excfg *) server2_conf; + char *note; + + /* + * Our inheritance rules are our own, and part of our module's semantics. + * Basically, just note whence we came. + */ + merged_config->cmode = + (s1conf->cmode == s2conf->cmode) ? s1conf->cmode : CONFIG_MODE_COMBO; + merged_config->local = s2conf->local; + merged_config->congenital = (s1conf->congenital | s1conf->local); + merged_config->loc = ap_pstrdup(p, s2conf->loc); + /* + * Trace our call, including what we were asked to merge. + */ + note = ap_pstrcat(p, "ptt_merge_server_config(\"", s1conf->loc, "\",\"", + s2conf->loc, "\")", NULL); + trace_add(NULL, NULL, merged_config, note); + return (void *) merged_config; +} + +/* + * This routine is called after the request has been read but before any other + * phases have been processed. This allows us to make decisions based upon + * the input header fields. + * + * The return value is OK, DECLINED, or HTTP_mumble. If we return OK, no + * further modules are called for this phase. + */ +static int ptt_post_read_request(request_rec *r) +{ + + excfg *cfg; + + cfg = our_dconfig(r); + /* + * We don't actually *do* anything here, except note the fact that we were + * called. + */ + trace_add(r->server, r, cfg, "ptt_post_read_request()"); + return DECLINED; +} + +/* + * This routine gives our module an opportunity to translate the URI into an + * actual filename. If we don't do anything special, the server's default + * rules (Alias directives and the like) will continue to be followed. + * + * The return value is OK, DECLINED, or HTTP_mumble. If we return OK, no + * further modules are called for this phase. + */ +static int ptt_translate_handler(request_rec *r) +{ + + excfg *cfg; + + cfg = our_dconfig(r); + /* + * We don't actually *do* anything here, except note the fact that we were + * called. + */ + trace_add(r->server, r, cfg, "ptt_translate_handler()"); + return DECLINED; +} + +/* + * This routine is called to check the authentication information sent with + * the request (such as looking up the user in a database and verifying that + * the [encrypted] password sent matches the one in the database). + * + * The return value is OK, DECLINED, or some HTTP_mumble error (typically + * HTTP_UNAUTHORIZED). If we return OK, no other modules are given a chance + * at the request during this phase. + */ +static int ptt_check_user_id(request_rec *r) +{ + + excfg *cfg; + + cfg = our_dconfig(r); + /* + * Don't do anything except log the call. + */ + trace_add(r->server, r, cfg, "ptt_check_user_id()"); + return DECLINED; +} + +/* + * This routine is called to check to see if the resource being requested + * requires authorisation. + * + * The return value is OK, DECLINED, or HTTP_mumble. If we return OK, no + * other modules are called during this phase. + * + * If *all* modules return DECLINED, the request is aborted with a server + * error. + */ +static int ptt_auth_checker(request_rec *r) +{ + + excfg *cfg; + + cfg = our_dconfig(r); + /* + * Log the call and return OK, or access will be denied (even though we + * didn't actually do anything). + */ + trace_add(r->server, r, cfg, "ptt_auth_checker()"); + return DECLINED; +} + +/* + * This routine is called to check for any module-specific restrictions placed + * upon the requested resource. (See the mod_access module for an example.) + * + * The return value is OK, DECLINED, or HTTP_mumble. All modules with an + * handler for this phase are called regardless of whether their predecessors + * return OK or DECLINED. The first one to return any other status, however, + * will abort the sequence (and the request) as usual. + */ +static int ptt_access_checker(request_rec *r) +{ + + excfg *cfg; + + cfg = our_dconfig(r); + trace_add(r->server, r, cfg, "ptt_access_checker()"); + return DECLINED; +} + +/* + * This routine is called to determine and/or set the various document type + * information bits, like Content-type (via r->content_type), language, et + * cetera. + * + * The return value is OK, DECLINED, or HTTP_mumble. If we return OK, no + * further modules are given a chance at the request for this phase. + */ +static int ptt_type_checker(request_rec *r) +{ + + excfg *cfg; + + cfg = our_dconfig(r); + /* + * Log the call, but don't do anything else - and report truthfully that + * we didn't do anything. + */ + trace_add(r->server, r, cfg, "ptt_type_checker()"); + return DECLINED; +} + +/* + * This routine is called to perform any module-specific fixing of header + * fields, et cetera. It is invoked just before any content-handler. + * + * The return value is OK, DECLINED, or HTTP_mumble. If we return OK, the + * server will still call any remaining modules with an handler for this + * phase. + */ +static int ptt_fixer_upper(request_rec *r) +{ + + excfg *cfg; + + cfg = our_dconfig(r); + /* + * Log the call and exit. + */ + trace_add(r->server, r, cfg, "ptt_fixer_upper()"); + return OK; +} + +/* + * This routine is called to perform any module-specific logging activities + * over and above the normal server things. + * + * The return value is OK, DECLINED, or HTTP_mumble. If we return OK, any + * remaining modules with an handler for this phase will still be called. + */ +static int ptt_logger(request_rec *r) +{ + + excfg *cfg; + + cfg = our_dconfig(r); + trace_add(r->server, r, cfg, "ptt_logger()"); + return DECLINED; +} + +/* + * This routine is called to give the module a chance to look at the request + * headers and take any appropriate specific actions early in the processing + * sequence. + * + * The return value is OK, DECLINED, or HTTP_mumble. If we return OK, any + * remaining modules with handlers for this phase will still be called. + */ +static int ptt_header_parser(request_rec *r) +{ + + excfg *cfg; + + cfg = our_dconfig(r); + trace_add(r->server, r, cfg, "ptt_header_parser()"); + return DECLINED; +} + +/*--------------------------------------------------------------------------*/ +/* */ +/* All of the routines have been declared now. Here's the list of */ +/* directives specific to our module, and information about where they */ +/* may appear and how the command parser should pass them to us for */ +/* processing. Note that care must be taken to ensure that there are NO */ +/* collisions of directive names between modules. */ +/* */ +/*--------------------------------------------------------------------------*/ +/* + * List of directives specific to our module. + */ +static const command_rec ptt_cmds[] = +{ + { + "ptt", /* directive name */ + cmd_ptt, /* config action routine */ + NULL, /* argument to include in call */ + OR_OPTIONS, /* where available */ + NO_ARGS, /* arguments */ + "Example directive - no arguments" + /* directive description */ + }, + {NULL} +}; + +/*--------------------------------------------------------------------------*/ +/* */ +/* Now the list of content handlers available from this module. */ +/* */ +/*--------------------------------------------------------------------------*/ +/* + * List of content handlers our module supplies. Each handler is defined by + * two parts: a name by which it can be referenced (such as by + * {Add,Set}Handler), and the actual routine name. The list is terminated by + * a NULL block, since it can be of variable length. + * + * Note that content-handlers are invoked on a most-specific to least-specific + * basis; that is, a handler that is declared for "text/plain" will be + * invoked before one that was declared for "text / *". Note also that + * if a content-handler returns anything except DECLINED, no other + * content-handlers will be called. + */ +static const handler_rec ptt_handlers[] = +{ + {"ptt-handler", ptt_handler}, + {NULL} +}; + +/*--------------------------------------------------------------------------*/ +/* */ +/* Finally, the list of callback routines and data structures that */ +/* provide the hooks into our module from the other parts of the server. */ +/* */ +/*--------------------------------------------------------------------------*/ +/* + * Module definition for configuration. If a particular callback is not + * needed, replace its routine name below with the word NULL. + * + * The number in brackets indicates the order in which the routine is called + * during request processing. Note that not all routines are necessarily + * called (such as if a resource doesn't have access restrictions). + */ +module MODULE_VAR_EXPORT ptt_module = +{ + STANDARD_MODULE_STUFF, + ptt_init, /* module initializer */ + ptt_create_dir_config, /* per-directory config creator */ + ptt_merge_dir_config, /* dir config merger */ + ptt_create_server_config, /* server config creator */ + ptt_merge_server_config, /* server config merger */ + ptt_cmds, /* command table */ + ptt_handlers, /* [9] list of handlers */ + ptt_translate_handler, /* [2] filename-to-URI translation */ + ptt_check_user_id, /* [5] check/validate user_id */ + ptt_auth_checker, /* [6] check user_id is valid *here* */ + ptt_access_checker, /* [4] check access by host address */ + ptt_type_checker, /* [7] MIME type checker/setter */ + ptt_fixer_upper, /* [8] fixups */ + ptt_logger, /* [10] logger */ +#if MODULE_MAGIC_NUMBER >= 19970103 + ptt_header_parser, /* [3] header parser */ +#endif +#if MODULE_MAGIC_NUMBER >= 19970719 + ptt_child_init, /* process initializer */ +#endif +#if MODULE_MAGIC_NUMBER >= 19970728 + ptt_child_exit, /* process exit/cleanup */ +#endif +#if MODULE_MAGIC_NUMBER >= 19970902 + ptt_post_read_request /* [1] post read_request handling */ +#endif +}; diff --git a/pttbbs/web/mod_ptt.h b/pttbbs/web/mod_ptt.h new file mode 100644 index 00000000..2d7946b9 --- /dev/null +++ b/pttbbs/web/mod_ptt.h @@ -0,0 +1,17 @@ +#include "httpd.h" +#include "http_config.h" +#include "http_core.h" +#include "http_log.h" +#include "http_main.h" +#include "http_protocol.h" +#include "util_script.h" +#include "config.h" +#include "pttstruct.h" +#include "modes.h" +#include "common.h" +#include "proto.h" + +#include <stdio.h> + + +#define PATHLEN 512 diff --git a/pttbbs/web/mytime.h b/pttbbs/web/mytime.h new file mode 100755 index 00000000..c9e4f29d --- /dev/null +++ b/pttbbs/web/mytime.h @@ -0,0 +1,189 @@ +/* Ptt : 常用函式整理 */ + +/* + * 時間處理 + */ +#include <time.h> +#ifdef _BBS_UTIL + #undef pstrdup + #define pstrdup(p, str) strdup(str) +#endif + +int +mygetdate(time_t clock, int *year, int *mon, int *mday, int *week) +{ + struct tm *mytm = localtime(&clock); + if(year) *year = mytm->tm_year; /* 98 */ + if(mon) *mon = mytm->tm_mon + 1; /* 1~12 */ + if(mday) *mday = mytm->tm_mday; /* 1~31 */ + if(week) *week = mytm->tm_wday; /* 0~6 */ + return 0; +} + +char * +Cdatenum_slash(pool *p,time_t *clock) /* 98/04/21 */ +{ + char foo[22]; + struct tm *mytm = localtime(clock); + strftime(foo, 22, "%y/%m/%d", mytm); + return pstrdup(p, foo); +} + +char * +Cdatenum(pool *p,time_t *clock) /* 980421 */ +{ + char foo[22]; + struct tm *mytm = localtime(clock); + strftime(foo, 22, "%y%m%d", mytm); + return pstrdup(p, foo); +} + + +#ifndef _BBS_UTIL +char * +Cdatefullnum(pool *p,time_t *clock) /* 19980421 */ +{ + char foo[22]; + struct tm *mytm = localtime(clock); + strftime(foo, 22, "%Y%m%d", mytm); + return pstrdup(p, foo); +} +#else +char * +Cdatefullnum(char *p,time_t *clock) /* 19980421 */ +{ + static char foo[22]; + struct tm *mytm = localtime(clock); + strftime(foo, 22, "%Y%m%d", mytm); + return foo; +} +#endif + +char * +Cdate(char *p,time_t *clock) +{ + char foo[22]; + struct tm *mytm = localtime(clock); + strftime(foo, 22, "%D %T %a", mytm); + return pstrdup(p, foo); +} + +char * +Cdatelite(char *p,time_t *clock) +{ + char foo[18]; + struct tm *mytm = localtime(clock); + strftime(foo, 18, "%D %T", mytm); + return pstrdup(p, foo); +} + +char * +whattime(char *p,time_t *clock) +{ + char foo[18]; + struct tm *mytm = localtime(clock); + strftime(foo, 18, "%H:%M:%S", mytm); + return pstrdup(p, foo); +} + +char * +whatyear(char *p,time_t *clock) +{ + char foo[6]; + struct tm *mytm = localtime(clock); + strftime(foo, 6, "%Y", mytm); + return pstrdup(p, foo); +} + +char * +whatmonth(char *p,time_t *clock) +{ + char foo[4]; + struct tm *mytm = localtime(clock); + strftime(foo, 4, "%m", mytm); + return pstrdup(p, foo); +} + +char * +whatday(char *p,time_t *clock) +{ + char foo[4]; + struct tm *mytm = localtime(clock); + strftime(foo, 4, "%d", mytm); + return pstrdup(p, foo); +} + +char * +C_week(pool *p, int a) +{ + char foo[5]=""; + switch(a) + { + case 0: + case 7: + strcpy(foo,"日"); + break; + case 1: + strcpy(foo,"一"); + break; + case 2: + strcpy(foo,"二"); + break; + case 3: + strcpy(foo,"三"); + break; + case 4: + strcpy(foo,"四"); + break; + case 5: + strcpy(foo,"五"); + break; + case 6: + strcpy(foo,"六"); + break; + } + return pstrdup(p, foo); +} + +char * +whatweek(char *p,time_t *clock) +{ + struct tm *mytm = localtime(clock); + return C_week(p, mytm->tm_wday); +} + +char * +whathour(char *p,time_t *clock) +{ + char foo[4]=""; + struct tm *mytm = localtime(clock); + strftime(foo, 6, "%H", mytm); + return pstrdup(p, foo); +} + +char * +whatminute(char *p,time_t *clock) +{ + char foo[4]=""; + struct tm *mytm = localtime(clock); + strftime(foo, 6, "%M", mytm); + return pstrdup(p, foo); +} + +char * +whatsecond(char *p,time_t *clock) +{ + char foo[4]=""; + struct tm *mytm = localtime(clock); + strftime(foo, 6, "%S", mytm); + return pstrdup(p, foo); +} + +char * +Wholetime(char *p,time_t *clock) /* 19980421 */ +{ + char foo[40]; + struct tm *mytm = localtime(clock); + strftime(foo, 40, "%Y年%m月%d日%H時%M分%S秒", mytm); + return pstrdup(p, foo); +} diff --git a/pttbbs/web/parse_html.c b/pttbbs/web/parse_html.c new file mode 100755 index 00000000..402412de --- /dev/null +++ b/pttbbs/web/parse_html.c @@ -0,0 +1,294 @@ +#include "mod_ptt.h" +#include <time.h> +#include <math.h> +#define KUSERINFO "$userinfo$" +#define KUSERID "$userid$" +#define KUSERNAME "$username$" +#define KUSERMONEY "$usermoney$" +#define KTIMEYEAR "$timeyear$" +#define KTIMEMONTH "$timemonth$" +#define KTIMEMDAY "$timemday$" +#define KTIMEWEEK "$timeweek$" +#define KSERVERTIME "$servertime$" +#define KTIMEHOUR "$hour$" +#define KTIMEMINUTE "$minute$" +#define KTIMESECOND "$second$" +#define KMSGONLOAD "$MSGonLoad$" +#define KFCSONLOAD "$FCSonLoad$" +#define KHTMLTITLE "$HTMLtitle$" +#define KSCROLLTITLE "$SCROLLtitle$" +#define KBGCOLOR "$BGCOLOR$" +#define KBGSOUND "$BGSOUND$" +#define KINCHTML "$file:" + + + +char * +ap_parseline(request_rec *r, const char *str, char *str_substiute[]) { + int i, off=0; + char *strbuf, *po; + pool *p = r->pool; + strbuf = pstrdup(p, str); + + if(str_substiute == NULL) return strbuf; + for(i=0; str_substiute[i]!=NULL; i+=2) + { + off = 0; + while(po = strstr(strbuf + off, str_substiute[i])) + { + *po = 0; + strbuf = pstrcat(p, strbuf, str_substiute[i+1] !=NULL + ? str_substiute[i+1] : "", po+strlen(str_substiute[i]), NULL); + off += str_substiute[i+1] ? strlen(str_substiute[i+1]) : 0; + } + } + return strbuf; +} + +char * +ap_standard_parseline(request_rec *r, char *str) +{ + time_t now = time(NULL); + pool *p = r->pool; + char *str_substiute[]= // 關鍵字的代換表 + { + KUSERID, "ptt", + KUSERNAME, "name", +/* + KTIMEYEAR, whatyear(p,&now), + KTIMEMONTH,whatmonth(p,&now), + KTIMEMDAY, whatday(p,&now), + KTIMEWEEK, whatweek(p,&now), + KSERVERTIME, whattime(p,&now), + KTIMEHOUR, whathour(p,&now), + KTIMEMINUTE, whatminute(p,&now), + KTIMESECOND, whatsecond(p,&now), +*/ + KUSERINFO, NULL, + KUSERMONEY, "100", + NULL,NULL + }; + return ap_parseline(r, str, str_substiute); +} + +int +ap_showfile(request_rec *r, char *filename, char *table[], char *t2[], FILE *fo) +{ + pool *p = r->pool; + FILE *fp = pfopen(p, filename, "r"); + char *str, *incfile, buf[512]; + + if (!fp) { +#if DEBUG + rputs(filename, r); +#endif + return -1; + } + + while (fgets(buf, 512, fp)) + { + + str = ap_standard_parseline(r, + ap_parseline(r, + ap_parseline(r, buf, table), + t2)); + + if ((incfile = strstr(str, KINCHTML)) != NULL) { + incfile += strlen(KINCHTML); + incfile = strtok(incfile, "$"); +#if 0 + if (*incfile != '/') + incfile = ap_pstrcat(p, TEMPLATEDIR "/", incfile, NULL); +#endif + ap_showfile(r, incfile, table, t2, fo); + } else if(fo) fputs(str, fo); + else rputs(str, r); + } + + pfclose(p, fp); + return 0; +} + +char * +add_href(pool *p, char *l) +{ + char *href[] = {"http://", "ftp://", "gopher://", "file://", + "telnet://", "mailto:", NULL}, + *end, url[PATHLEN], *tl, *po; + int i, urllen, off; + + tl = pstrdup(p, l); + + for(i=0; href[i]!=NULL; i++) + { + off = 0; + //Ptt: while 應該用 while 但 while 有bug + if((po = strstr(tl + off, href[i]))) + { + for(end = po; (*end>='&' && *end<='z')||*end=='~' ; end++); + urllen = end - po; + + if(urllen > PATHLEN) + { + off += PATHLEN; continue; + } + + strncpy(url, po, urllen); + *po= 0; + url[urllen] = 0; + tl = psprintf(p, "%s<a href=\"%s\" target=\"%s\">%s</a>%s", tl, + url, "new", url, end); + off += 2 * urllen + 15; + } + } + + return tl; +} + +/* + format: + char *name, void *ptr, size_t length + char *name, int *ptr, -1 + char *name, char **ptr, 0 +*/ +int +GetQueryDatas(request_rec *r, int **table) +{ + int rc, i, match=0, dlen, maxlen; + char *name, *value, *str; + pool *p = r->pool; + + for(i=1; table[i]!=NULL; i+=3) + { + if((int) table[i+1]) *table[i]=0; + else (char *) (*table[i]) = pstrdup(p, ""); + } + do + { + if((rc = unescape(r, &name, &value))<0) break; + for(i=0; table[i]; i+=3) + { + if(!strcmp((char *)table[i], name)) break; + +#if 0 +/* SiE990313 test: 抓 未定義的變數 */ + if(!strcmp((char *)table[i], "$SPARE$")) + { + (char *) (*table[i + 1]) = pstrdup(p, name); + continue; + } +#endif + } + if(table[i] && table[i+1]) + { + if((maxlen = (int) table[i+2]) > 0) + { + if(!*value) continue; + dlen = strlen((char *)table[i+1]); + str = ap_escape_html(p, value); + if(maxlen > dlen) + strexam( + strncat((char *)table[i+1],str,maxlen-dlen) + ); + } + else if((int) table[i+2] == 0) // for file upload + { +// str = ap_escape_html(p, value); + //if(value) + (*table[i+1]) = (int) value; +// else (*table[i+1]) = (int) pstrdup(p,""); + } + else + { + if(!*value) continue; + *(table[i+1]) += atoi(value); + } + match++; + } + } while(rc>0); + return match; +} + + +int +ap_url_redirect(request_rec *r, char *url) +{ + r->status = REDIRECT; + + ap_table_setn(r->headers_out, "Location", pstrdup(r->pool, url)); + return MOVED; + //return REDIRECT, MOVED 或 HTTP_SEE_OTHER 都可 +} + +char * +pint2str(pool* p, int c) +{ + return ap_psprintf(p,"%d",c); +} + +char* +preplace(request_rec *r, char* src, char* sig, char* rep) +{ + char *ptr; + int siglen=strlen(sig), off=0; + + while((ptr = strstr(src+off,sig))) + { + *ptr = 0; + src = pstrcat(r->pool, src, rep, NULL); + off = strlen(src); + src = pstrcat(r->pool, src, ptr+siglen, NULL); + } + return src; +} + +int +hex2dig(char *str) +{ + int base,ret=0,i,len=strlen(str); + + for(i=0; i<len; i++) + { + if(str[i]>='a' && str[i]<='f') base = str[i]-'a'+10; + else if(str[i]>='A' && str[i]<='F') base = str[i]-'A'+10; + else if(str[i]>='0' && str[i]<='9') base = str[i]-'0'; + else return -1; + + ret += base*pow(16,len-i-1); + } + return ret; +} + +char * +pstrncpy(pool* p, char tmp[], int n) +{ + char *ptr; + ptr=pstrdup(p,tmp); + *(ptr+n)=0; + return psprintf(p,"%s",ptr); +} + +char * +GetPathToken(request_rec *r, int count) +{ + char *str, *token, *sepr = "/\\?&"; + int i; + str = pstrdup(r->pool, r->path_info + 1); + token = strtok(str, sepr); + for( i = 1 ; i < count; i++) + { + token = strtok(NULL, sepr); + if(!token) return "-1"; /* Heat:count超過也要考慮 */ + } + return token; +} + + +/* + 個人信件夾檔保管方式: + + mail/@/rec/FF/F/UUDDTT + mail/@/dat/FF/F/UUDDTT + +*/ + -- cgit v1.2.3 From d366828f1df12c71d5e0e884ddba452aca90197e Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sat, 5 Oct 2002 16:09:46 +0000 Subject: group writable git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@537 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/web/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pttbbs/web/Makefile b/pttbbs/web/Makefile index 44830419..bff43078 100644 --- a/pttbbs/web/Makefile +++ b/pttbbs/web/Makefile @@ -1,4 +1,4 @@ all: mod_ptt.c mod_ptt.h apxs -I ../include -c mod_ptt.c cp mod_ptt.so /usr/local/libexec/apache/mod_ptt.so - chmod 755 /usr/local/libexec/apache/mod_ptt.so + chmod 775 /usr/local/libexec/apache/mod_ptt.so -- cgit v1.2.3 From 9be018da4538559d64506edf06757111b1f15f5e Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Wed, 16 Oct 2002 13:04:11 +0000 Subject: register git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@538 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/user.c | 52 +++++++++++++++++++++++++++++++++------------------- 1 file changed, 33 insertions(+), 19 deletions(-) diff --git a/pttbbs/mbbsd/user.c b/pttbbs/mbbsd/user.c index 3745cd47..d77d6721 100644 --- a/pttbbs/mbbsd/user.c +++ b/pttbbs/mbbsd/user.c @@ -1,4 +1,4 @@ -/* $Id: user.c,v 1.38 2002/09/01 18:28:45 in2 Exp $ */ +/* $Id: user.c,v 1.39 2002/10/16 13:04:11 in2 Exp $ */ #include "bbs.h" static char *sex[8] = { @@ -761,6 +761,9 @@ ispersonalid(char *inid) if (!isalpha(id[0]) && (strlen(id) != 10)) return 0; id[0] = toupper(id[0]); + + if( strcmp(id, "A100000001") == 0 ) + return 0; /* A->10, B->11, ..H->17,I->34, J->18... */ while (lst[i] != id[0]) i++; @@ -1035,33 +1038,39 @@ u_register(void) move(1, 0); prints("%s(%s) 您好,請據實填寫以下的資料:", cuser.userid, cuser.username); - do { - getfield(3, "D120908396", "身分證號", ident, 11); + while( 1 ){ + getfield(3, "D123456789", "身分證號", ident, 11); if ('a' <= ident[0] && ident[0] <= 'z') ident[0] -= 32; - } while (!ispersonalid(ident)); + if( ispersonalid(ident) ) + break; + vmsg("您的輸入不正確(若有問題麻煩至SYSOP板)"); + } while (1) { getfield(5, "請用中文", "真實姓名", rname, 20); if (removespace(rname) && rname[0] < 0 && !strstr(rname, "阿") && !strstr(rname, "小") && !strstr(rname, "ㄚ") && strstr(rname, "..") == NULL && - !(strlen(rname) == 4 && strncmp(&rname[0], &rname[2], 2) == 0) ) + !(strlen(rname) == 4 && strncmp(&rname[2], "兒", 2) == 0) && + !(strlen(rname) >= 4 && strncmp(&rname[0], &rname[2], 2) == 0)) break; vmsg("您的輸入不正確"); } + move(7, 0); + prints("麻煩您盡量詳細的填寫您的服務單位, 大專院校請麻煩" + "加系所, 公司單位請加職稱"); while (1) { - getfield(7, "學校(含\033[1;33m系所年級\033[m)或單位職稱", + getfield(8, "學校(含\033[1;33m系所年級\033[m)或單位職稱", "服務單位", career, 40); if (!(removespace(career) && career[0] < 0 - && strlen(career) >= 4) || - strcmp(career, "家裡") == 0 ) { + && strlen(career) >= 6) || + strcmp(career, "家裡") == 0 || + strstr(career, "某") != NULL ) { vmsg("您的輸入不正確"); continue; } - if (strcmp(career, "學校") == 0 || - strcmp(career, "學生") == 0 || - strcmp(&career[strlen(career) - 2], "大") == 0 || + if (strcmp(&career[strlen(career) - 2], "大") == 0 || strcmp(&career[strlen(career) - 4], "大學") == 0 ) { vmsg("麻煩請加學校系所"); continue; @@ -1069,7 +1078,7 @@ u_register(void) break; } while (1) { - getfield(9, "含\033[1;33m縣市\033[m及門寢號碼" + getfield(10, "含\033[1;33m縣市\033[m及門寢號碼" "(台北請加\033[1;33m行政區\033[m)", "目前住址", addr, 50); if (!removespace(addr) || addr[0] > 0 || strlen(addr) < 15) { @@ -1084,6 +1093,7 @@ u_register(void) strstr(addr, "室") == NULL) || strstr(addr, "地球") != NULL || strstr(addr, "銀河") != NULL || + strstr(addr, "火星") != NULL || strstr(addr, "某") != NULL || strstr(addr, "..") != NULL || strcmp(&addr[strlen(addr) - 2], "段") == 0 || @@ -1096,7 +1106,7 @@ u_register(void) break; } while (1) { - getfield(11, "不加-(), 包括長途區號", "連絡電話", phone, 11); + getfield(12, "不加-(), 包括長途區號", "連絡電話", phone, 11); if (strstr(phone, "(") || strstr(phone, ")") || strstr(phone, "-")){ vmsg("電話請不加 ( ) - 符號"); continue; @@ -1108,12 +1118,12 @@ u_register(void) } break; } - getfield(13, "只輸入數字 如:0912345678 (可不填)", + getfield(14, "只輸入數字 如:0912345678 (可不填)", "手機號碼", mobile, 20); while (1) { int len; - getfield(15, "月月/日日/西元 如:09/27/76", "生日", birthday, 9); + getfield(16, "月月/日日/西元 如:09/27/76", "生日", birthday, 9); len = strlen(birthday); if (!len) { snprintf(birthday, sizeof(birthday), "%02i/%02i/%02i", @@ -1125,15 +1135,19 @@ u_register(void) mon = (birthday[0] - '0') * 10 + (birthday[1] - '0'); day = (birthday[3] - '0') * 10 + (birthday[4] - '0'); year = (birthday[6] - '0') * 10 + (birthday[7] - '0'); - } else + } else{ + vmsg("您的輸入不正確"); continue; + } if (mon > 12 || mon < 1 || day > 31 || day < 1 || year > 90 || - year < 40) + year < 40){ + vmsg("您的輸入不正確"); continue; + } break; } - getfield(17, "1.葛格 2.姐接 ", "性別", sex_is, 2); - getdata(18, 0, "以上資料是否正確(Y/N)?(Q)取消註冊 [N] ", + getfield(18, "1.葛格 2.姐接 ", "性別", sex_is, 2); + getdata(19, 0, "以上資料是否正確(Y/N)?(Q)取消註冊 [N] ", ans, sizeof(ans), LCECHO); if (ans[0] == 'q') return 0; -- cgit v1.2.3 From 0ce4cbf58524a4382e9b1991b29c74e62c9eade4 Mon Sep 17 00:00:00 2001 From: ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Fri, 18 Oct 2002 14:43:58 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@539 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/web/Makefile.old | 120 ++++++++++ pttbbs/web/Makefile.tmpl | 16 ++ pttbbs/web/Makefile.tmpl.bak | 17 ++ pttbbs/web/args.c | 228 +++++++++++++++++++ pttbbs/web/board.c | 39 ++++ pttbbs/web/chmod | 1 + pttbbs/web/libptt.a | Bin 0 -> 107932 bytes pttbbs/web/mail.c | 6 + pttbbs/web/post.c | 6 + pttbbs/web/stuff.c | 269 ++++++++++++++++++++++ pttbbs/web/user.c | 6 + pttbbs/web/util_cache.c | 516 +++++++++++++++++++++++++++++++++++++++++++ pttbbs/web/util_passwd.c | 141 ++++++++++++ pttbbs/web/util_record.c | 245 ++++++++++++++++++++ 14 files changed, 1610 insertions(+) create mode 100644 pttbbs/web/Makefile.old create mode 100644 pttbbs/web/Makefile.tmpl create mode 100644 pttbbs/web/Makefile.tmpl.bak create mode 100755 pttbbs/web/args.c create mode 100644 pttbbs/web/board.c create mode 100644 pttbbs/web/chmod create mode 100644 pttbbs/web/libptt.a create mode 100644 pttbbs/web/mail.c create mode 100644 pttbbs/web/post.c create mode 100755 pttbbs/web/stuff.c create mode 100644 pttbbs/web/user.c create mode 100755 pttbbs/web/util_cache.c create mode 100755 pttbbs/web/util_passwd.c create mode 100755 pttbbs/web/util_record.c diff --git a/pttbbs/web/Makefile.old b/pttbbs/web/Makefile.old new file mode 100644 index 00000000..db2735bf --- /dev/null +++ b/pttbbs/web/Makefile.old @@ -0,0 +1,120 @@ +## +## Apache Makefile, automatically generated by Configure script. +## Hand-edited changes will be lost if the Configure script is re-run. +## Sources: - ../../Makefile.config (via Configuration) +## - ./Makefile.tmpl +## + +## +## Inherited Makefile options from Configure script +## (Begin of automatically generated section) +## +SRCDIR=../.. +EXTRA_CFLAGS= +EXTRA_LDFLAGS= +EXTRA_LIBS= +EXTRA_INCLUDES= +EXTRA_DEPS= +OSDIR=$(SRCDIR)/os/unix +INCDIR=$(SRCDIR)/include +INCLUDES0=-I$(OSDIR) -I$(INCDIR) -I../$(INCDIR) +SHELL=/bin/sh +OS=FreeBSD 4.6 +CC=gcc +CPP=gcc -E +TARGET=httpd +OPTIM= +CFLAGS1= -funsigned-char -DUSE_EXPAT -I$(SRCDIR)/lib/expat-lite -DNO_DL_NEEDED +INCLUDES1= +LIBS_SHLIB= +LDFLAGS1= +MFLAGS_STATIC= +REGLIB= +EXPATLIB=lib/expat-lite/libexpat.a +RANLIB=ranlib +LIBS1= -lcrypt +## +## (End of automatically generated section) +## + +## +## Default Makefile options from Configure script +## (Begin of automatically generated section) +## +CFLAGS=$(OPTIM) $(CFLAGS1) $(EXTRA_CFLAGS) +LIBS=$(EXTRA_LIBS) $(LIBS1) +INCLUDES=$(INCLUDES1) $(INCLUDES0) $(EXTRA_INCLUDES) +LDFLAGS=$(LDFLAGS1) $(EXTRA_LDFLAGS) +INCDIR=$(SRCDIR)/include +OBJS=mod_ptt.o parse_html.o +BBSLIBS=util_cache.o util_passwd.o util_record.o +LIB=libptt.a +SHLIBS= +OBJS_PIC= + +all: lib shlib + +lib: $(LIB) + +shlib: $(SHLIBS) + +dummy $(LIB): $(OBJS) + rm -f $@ + ar cr $@ $(OBJS) $(BBSLIBS) + $(RANLIB) $@ + +.SUFFIXES: .o .so .dll + +.c.o: + $(CC) -c $(INCLUDES) $(CFLAGS) $< + +.c.so: + $(CC) -c $(INCLUDES) $(CFLAGS) $(CFLAGS_SHLIB) $< && mv $*.o $*.lo + $(LD_SHLIB) $(LDFLAGS_SHLIB) -o $@ $*.lo $(LIBS_SHLIB) + +clean: + rm -f $(LIB) $(OBJS) $(SHLIBS) $(OBJS_PIC) + +distclean: clean + rm -f Makefile + +# NOT FOR END USERS! +depend: + cp Makefile.tmpl Makefile.tmpl.bak \ + && sed -ne '1,/^# DO NOT REMOVE/p' Makefile.tmpl > Makefile.new \ + && gcc -MM $(INCLUDES) $(CFLAGS) *.c >> Makefile.new \ + && sed -e '1,$$s: $(INCDIR)/: $$(INCDIR)/:g' \ + -e '1,$$s: $(OSDIR)/: $$(OSDIR)/:g' Makefile.new \ + > Makefile.tmpl \ + && rm Makefile.new + +## +## (End of automatically generated section) +## + +#Dependencies + +$(OBJS) $(OBJS_PIC): Makefile + +# DO NOT REMOVE +mod_ptt.o: mod_ptt.c $(INCDIR)/httpd.h \ + $(INCDIR)/ap_config.h $(INCDIR)/ap_mmn.h \ + $(INCDIR)/ap_config_auto.h $(OSDIR)/os.h \ + $(INCDIR)/ap_ctype.h $(INCDIR)/hsregex.h \ + $(INCDIR)/ap_alloc.h $(INCDIR)/buff.h $(INCDIR)/ap.h \ + $(INCDIR)/util_uri.h $(INCDIR)/http_config.h \ + $(INCDIR)/http_core.h $(INCDIR)/http_log.h \ + $(INCDIR)/http_main.h $(INCDIR)/http_protocol.h \ + $(INCDIR)/util_script.h \ + /home/bbs/pttbbs/include/bbs.h + +parse_html.o: parse_html.c $(INCDIR)/httpd.h \ + $(INCDIR)/ap_config.h $(INCDIR)/ap_mmn.h \ + $(INCDIR)/ap_config_auto.h $(OSDIR)/os.h \ + $(INCDIR)/ap_ctype.h $(INCDIR)/hsregex.h \ + $(INCDIR)/ap_alloc.h $(INCDIR)/buff.h $(INCDIR)/ap.h \ + $(INCDIR)/util_uri.h $(INCDIR)/http_config.h \ + $(INCDIR)/http_core.h $(INCDIR)/http_log.h \ + $(INCDIR)/http_main.h $(INCDIR)/http_protocol.h \ + $(INCDIR)/util_script.h \ + /home/bbs/pttbbs/include/bbs.h diff --git a/pttbbs/web/Makefile.tmpl b/pttbbs/web/Makefile.tmpl new file mode 100644 index 00000000..83ed1e84 --- /dev/null +++ b/pttbbs/web/Makefile.tmpl @@ -0,0 +1,16 @@ + +#Dependencies + +$(OBJS) $(OBJS_PIC): Makefile + +BBSLIBS= util_cache.o util_record.o util_passwd.o + +# DO NOT REMOVE +mod_ptt.o: mod_ptt.c $(INCDIR)/httpd.h $(INCDIR)/ap_config.h \ + $(INCDIR)/ap_mmn.h $(INCDIR)/ap_config_auto.h \ + $(OSDIR)/os.h $(OSDIR)/os-inline.c $(INCDIR)/ap_ctype.h \ + $(INCDIR)/ap_alloc.h $(INCDIR)/buff.h $(INCDIR)/ap.h \ + $(INCDIR)/util_uri.h $(INCDIR)/http_config.h \ + $(INCDIR)/http_core.h $(INCDIR)/http_log.h \ + $(INCDIR)/http_main.h $(INCDIR)/http_protocol.h \ + $(INCDIR)/util_script.h diff --git a/pttbbs/web/Makefile.tmpl.bak b/pttbbs/web/Makefile.tmpl.bak new file mode 100644 index 00000000..e686b7a9 --- /dev/null +++ b/pttbbs/web/Makefile.tmpl.bak @@ -0,0 +1,17 @@ + +#Dependencies + +$(OBJS) $(OBJS_PIC): Makefile + +BBSLIBS= util_cache.o util_record.o util_passwd.o + +# DO NOT REMOVE +mod_ptt.o: mod_ptt.c $(INCDIR)/httpd.h \ + $(INCDIR)/ap_config.h $(INCDIR)/ap_mmn.h \ + $(INCDIR)/ap_config_auto.h $(OSDIR)/os.h \ + $(INCDIR)/ap_ctype.h $(INCDIR)/hsregex.h \ + $(INCDIR)/ap_alloc.h $(INCDIR)/buff.h $(INCDIR)/ap.h \ + $(INCDIR)/util_uri.h $(INCDIR)/http_config.h \ + $(INCDIR)/http_core.h $(INCDIR)/http_log.h \ + $(INCDIR)/http_main.h $(INCDIR)/http_protocol.h \ + $(INCDIR)/util_script.h diff --git a/pttbbs/web/args.c b/pttbbs/web/args.c new file mode 100755 index 00000000..02e0fad0 --- /dev/null +++ b/pttbbs/web/args.c @@ -0,0 +1,228 @@ +/* 使用方法: 自己先用 r->method_number 判斷是 M_GET 或 M_POST + */ +#include "mod_ptt.h" + +unsigned char xtoc(char ch1, char ch2) { + unsigned char d, up1, up2; + + if (!isxdigit(ch1) || !isxdigit(ch2)) return ' '; + + up1 = toupper(ch1); + up2 = toupper(ch2); + + if (up1>='0' && up1<='9') d = up1-'0'; + else d = up1-'A'+10; + d <<= 4; + if (up2>='0' && up2<='9') d += up2-'0'; + else d += up2-'A'+10; + + return d; +} + +char * cstoxs(pool *p, char *str) +{ + char * newstr = pstrdup(p,""), *po = str; + + for(po = str; *po; po++) + { + if(isprint(*po) && *po!=' ') newstr=psprintf(p, "%s%c", newstr,*po); + else newstr=psprintf(p, "%s%%%X", newstr, *po& 0xFF); + } + return newstr; +} + +int // Ptt: 我重寫拿掉mygetchar 並加上fileupload的功能 +inital_postdata(request_rec *r, int *fileupload, char *boundary, + char **data) +{ + char *buf, *mb; + int size, off = 0, len_read; + void (*handler)(); + + buf = table_get(r->subprocess_env,"CONTENT_TYPE"); + if(!buf || + (strncasecmp(buf,"application/x-www-form-urlencoded",33) && + strncasecmp(buf,"multipart/form-data",19))) + return -1; + + if(!strncasecmp(buf,"multipart/form-data",19)) { + if(!fileupload) return -1; + *fileupload=1; + mb = strchr(buf,'='); + if(mb) { + strcpy(boundary,mb+1); + strtok(boundary, " ;\n"); + } + else return -1; + } + + buf = table_get(r->subprocess_env,"CONTENT_LENGTH"); + if(buf==NULL) return -1; + + size = atoi(buf); + mb = (char *)palloc(r->pool,(size+1)*sizeof(char)); + + if(!mb || + (setup_client_block(r ,REQUEST_CHUNKED_ERROR) != 0) || + (should_client_block(r) == 0)) + return -1; + + hard_timeout("args.c copy script args", r); + handler = signal(SIGPIPE, SIG_IGN); + + while(size-off > 0 && (len_read = get_client_block + (r, mb + off, size - off)) > 0) { + off += len_read; + } + + signal(SIGPIPE, handler); + kill_timeout(r); + + if(len_read < 0) return -1; // 讀的中途有中斷 + mb[size]=0; // Ptt:截掉不需要吧 因為不是用字串處理方式 + (*data) = mb; + return size; +} + +#define ENCODED_NAME " name=\"" +#define ENCODED_FILENAME " filename=\"" +#define ENCODED_CONTENT "Content-Type: " + +//#define FILEDATAFILE DATABASEDIR "/" FDATA + +int +unescape(request_rec *r, char** name, char** value) { + static char *sp=NULL, boundary[150]; + static int fileupload, boundarylen, dsize; + pool *p = r->pool; + char ch, ch1, *dp, *p0, *p1, *temp_sp, *ftype; + int type; + + if (sp==NULL) { + fileupload=0; + switch (r->method_number) { + case M_GET: + if (r->args) sp = pstrdup(p, r->args); + else {sp=NULL; return -1;} + break; + case M_POST: + if ((dsize = + inital_postdata(r, &fileupload, boundary,&sp))<0) + {sp=NULL; return -1; } + if(fileupload) boundarylen = strlen(boundary); + break; + default: + sp=NULL; + return -1; + } + } + + if(fileupload) + { + if(dsize >0 && (temp_sp = memstr(sp, boundary, dsize))) + { + temp_sp += boundarylen; + p0 = strstr(temp_sp, "\r\n\r\n"); + p1 = strstr(temp_sp, "\n\n"); + + if(!((*name) = strstr(temp_sp, ENCODED_NAME))) + {sp=NULL; return -1; } + (*name) += strlen(ENCODED_NAME); + strtok((*name) + 1 , "\""); + if( (!p0 && p1) || (p0 && p1 && p1<p0)) + { + (*value) = sp = p1 + 2; + type = 2; + } + else if(p0) + { + (*value) = sp = p0 + 4; + type = 4; + } + else + { + sp=NULL; + return -1; + } + + if((p1 = memstr(temp_sp, boundary, dsize - boundarylen))) + temp_sp = p1; + else + temp_sp = sp + dsize; + + *(temp_sp - type) = 0; + + // 檢查是不是file 若是就給fileinfo + if((dp=memstr( + (*name) + strlen(*name) +1, ENCODED_FILENAME, dsize)) && + dp < *value) + { + dp += strlen(ENCODED_FILENAME); + p0 = strchr(dp,'"'); + *p0 = 0; + if(p0 - dp>3) + { + fileheader_t *file=(fileheader_t *)pcalloc(p, sizeof(fileheader_t)); + if((ftype = strstr(p0 + 1, ENCODED_CONTENT))) + { + ftype += strlen(ENCODED_CONTENT); + strtok(ftype, "\r\n"); + } + while(p0 > dp && *p0 !='/' && *p0 !='\\') p0--; + strcpy(file->name, p0+1); + strcpy(file->content_type, ftype); + file->icontent_type = filetype(ftype); + // if(file->icontent_type & (FILE_TXT | FILE_HTML)) + // file->size = strlen(sp); + // else + file->size = temp_sp - sp - type; + file->uploadtime = time(NULL); + file->data = (*value); + (*value) = (char *)file; + } + else + { + (*value) = NULL; + } + } + + dsize -= (temp_sp - sp); + sp = temp_sp; + return 1; + } + else + { + sp=NULL; + return -1; + } + } + + dp = (*name) = sp; + while(1) { + ch = *sp++; + switch(ch) { + case '+': + *dp++ = ' '; + break; + case '=': + *dp++ = '\0'; + (*value) = dp; + break; + case '&': case '|': + *dp++ = '\0'; + return 1; + case '\0': case EOF: + *dp = '\0'; + sp=NULL; + return 0; + case '%': + ch = *sp++; ch1 = *sp++; + *dp++ = xtoc(ch, ch1); + break; + default: + *dp++=ch; + break; + } + } +} + diff --git a/pttbbs/web/board.c b/pttbbs/web/board.c new file mode 100644 index 00000000..43347912 --- /dev/null +++ b/pttbbs/web/board.c @@ -0,0 +1,39 @@ +#include "mod_ptt.h" + +extern int numboards; +extern boardheader_t *bcache; +extern int ptt_handler(request_rec *r, void *args); + +int bbs_board(request_rec *r, void *args) +{ + int i; + r->content_type = "text/xml"; + ap_send_http_header(r); + ap_rputs("<hr> Ptt \n", r); +return ptt_handler (r,args); + + ap_rprintf(r,"r->filename : %s <br>",r->filename); + ap_rprintf(r,"r->request_time : %s <br>",ctime(&r->request_time)); + ap_rprintf(r,"r->method : %s <br>",r->method); + ap_rprintf(r,"r->method_number : %d <br>",r->method_number); + ap_rprintf(r,"r->path_info : %s <br>",r->path_info); + ap_rprintf(r,"r->args : %s <br>",r->args); + ap_rprintf(r,"r->unparsed_uri : %s <br>",r->unparsed_uri); + ap_rprintf(r,"r->uri : %s <br>",r->uri); + ap_rprintf(r,"r->handler : %s <br>",r->handler); + ap_rprintf(r,"r->content_type : %s <br>",r->content_type); + ap_rprintf(r, "Server built: \"%s\"\n", ap_get_server_built()); + + ap_rputs("<hr> Ptt \n", r); + + ap_rputs("<XML>",r); +/* + for(i = 0; i++ < numboards; i++) + { + ap_rputs("<board>",r); + ap_rputs("</board>",r); + } +*/ + + return OK; +} diff --git a/pttbbs/web/chmod b/pttbbs/web/chmod new file mode 100644 index 00000000..a91df6d5 --- /dev/null +++ b/pttbbs/web/chmod @@ -0,0 +1 @@ +ftasfdsf diff --git a/pttbbs/web/libptt.a b/pttbbs/web/libptt.a new file mode 100644 index 00000000..26c2f527 Binary files /dev/null and b/pttbbs/web/libptt.a differ diff --git a/pttbbs/web/mail.c b/pttbbs/web/mail.c new file mode 100644 index 00000000..9f226afe --- /dev/null +++ b/pttbbs/web/mail.c @@ -0,0 +1,6 @@ +#include "mod_ptt.h" + +int bbs_mail(request_rec *r, void *args) +{ + return OK; +} diff --git a/pttbbs/web/post.c b/pttbbs/web/post.c new file mode 100644 index 00000000..3e67937e --- /dev/null +++ b/pttbbs/web/post.c @@ -0,0 +1,6 @@ +#include "mod_ptt.h" + +int bbs_post(request_rec *r, void *args) +{ + return OK; +} diff --git a/pttbbs/web/stuff.c b/pttbbs/web/stuff.c new file mode 100755 index 00000000..b02dbb0d --- /dev/null +++ b/pttbbs/web/stuff.c @@ -0,0 +1,269 @@ +/* Ptt : 常用字串函式整理 */ +#include "mod_ptt.h" + +// 缺少 escape_url的東西 + +/* + * 檔案判別 + */ + + /* 傳回:路徑大小 */ + +off_t +dashs(fname) + char *fname; +{ + struct stat st; + + if (!stat(fname, &st)) + return (st.st_size); + else + return 0; /* 無此檔是 size 0 */ +} + + /* 傳回:路徑時間 */ +long +dasht(char *fname) +{ + struct stat st; + + if (!stat(fname, &st)) + return (st.st_mtime); + else + return -1; +} + + /* 傳回:路徑是否為link檔 */ +int +dashl(char *fname) +{ + struct stat st; + return (lstat(fname, &st) == 0 && S_ISLNK(st.st_mode)); +} + + /* 傳回:路徑是否為檔案 */ +dashf(char *fname) +{ + struct stat st; + + return (stat(fname, &st) == 0 && S_ISREG(st.st_mode)); +} + +/* 字串的小寫 */ +#define char_lower(c) ((c >= 'A' && c <= 'Z') ? c|32 : c) + +void +str_lower(t, s) + char *t, *s; +{ + register char ch; + do + { + ch = *s++; + *t++ = char_lower(ch); + } while (ch); +} + +int +str_ncmp(s1, s2, n) + char *s1, *s2; + int n; +{ + int c1, c2; + + while (n--) + { + c1 = *s1++; + if (c1 >= 'A' && c1 <= 'Z') + c1 |= 32; + + c2 = *s2++; + if (c2 >= 'A' && c2 <= 'Z') + c2 |= 32; + + if (c1 -= c2) + return (c1); + + if (!c2) + break; + } + return 0; +} +char * +memstr(char *mem, char *str, int size) +{ + char *loc, *ptr=mem, *end=mem+size; + int len = strlen(str); + while((loc = memchr(ptr, *str, size))) + { + if(!strncmp(loc, str, len)) + return loc; + ptr = loc +1; + size = (end - ptr); + if(size <=0 ) return NULL; + } + return NULL; +} + +/* 傳回: strstr的比較但不計大小寫的結果 */ +/* +char * +strcasestr(str, tag) + char *str, *tag; +{ + char buf[BUFLEN]; + + str_lower(buf, str); + return strstr(buf, tag); +} +*/ + +/* 傳回: 一個checksum 給字串比較用 */ + +int str_checksum(char *str) +{ + int n=1; + if(strlen(str) < 6) return 0; + while(*str) + n += *str++ ^ n; + return n; +} + +int +not_alpha(ch) + register char ch; +{ + return (ch < 'A' || (ch > 'Z' && ch < 'a') || ch > 'z'); +} + +int +not_alnum(ch) + register char ch; +{ + return (ch < '0' || (ch > '9' && ch < 'A') || + (ch > 'Z' && ch < 'a') || ch > 'z'); +} + +char +ch2ph(char ch) +{ + static const + // a b c d e f g h i j k l m n o + char table[]={'2','2','2','3','3','3','4','4','4','5','5','5','6','6','6', + // p q r s t u v w x y z + '7','1','7','7','8','8','8','9','9','9','1'}; + static char d; + d = char_lower(ch); + if(d>='a' && d<='z') d=table[d-'a']; + return d; +} + +void +archiv32(chrono, fname) + time_t chrono; /* 32 bits */ + char *fname; /* 7 chars */ +{ + char *str; + char radix32[32] = { + '0', '1', '2', '3', '4', '5', '6', '7', + '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', + 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', + 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', + }; + + str = fname + 7; + *str = '\0'; + for (;;) + { + *(--str) = radix32[chrono & 31]; + if (str == fname) + return; + chrono >>= 5; + } +} + +/* ARPANET時間格式 */ +char * +Atime(clock) + time_t *clock; +{ + static char datemsg[40]; + /* ARPANET format: Thu, 11 Feb 1999 06:00:37 +0800 (CST) */ + /* strftime(datemsg, 40, "%a, %d %b %Y %T %Z", localtime(clock)); */ + /* time zone的傳回值不知和ARPANET格式是否一樣,先硬給,同sendmail*/ + strftime(datemsg, 40, "%a, %d %b %Y %T +0800 (CST)", localtime(clock)); + return (datemsg); +} + + +/* userid是否合法 */ +int +bad_user_id(userid) + char *userid; +{ + register char ch; + if (strlen(userid) < 2) + return 1; + if (not_alpha(*userid)) + return 1; + if (!strcasecmp(userid, "new") || !strcasecmp(userid, "guest") || + !strcasecmp(userid, "root") || !strcasecmp(userid, "webadm") || + !strncasecmp(userid,"yam",3) + ) + return 1; + + while (ch = *(++userid)) + { + if (not_alnum(ch) || ch == '0') + return 1; + } + return 0; +} + + +int +logfile(pool *p, char *filename,char *buf) +{ + FILE *fp; + time_t now; + if( (fp = ap_pfopen(p, filename, "a" )) ) { + + fputs( buf, fp ); + if(!strchr(buf,'\n')) + { + now = time(NULL); + fputs(ctime(&now), fp); + } + ap_pfclose(p, fp ); + return 0; + } + else{ + printf("error open file"); + return -1; + } +} + +/* 檢查中文斷字問題 */ +char *strexam(char *s) +{ + int i; + int odd; + for (i = 0, odd = 0; s[i]; i++) + if (odd) odd = 0; + else if (s[i] & 128) odd = 1; + if (odd) s[--i] = 0; + return s; +} + +int +maxline(char *data,char *newline, int max) +{ + register int n, nlen=strlen(newline); + register char *po; + + for(n=0, po = data; (po = strstr(po, newline)); po+=nlen) + { + if(++n>=max) {*po=0; return -1;} + } + return n; +} diff --git a/pttbbs/web/user.c b/pttbbs/web/user.c new file mode 100644 index 00000000..fe5d0696 --- /dev/null +++ b/pttbbs/web/user.c @@ -0,0 +1,6 @@ +#include "mod_ptt.h" + +int bbs_user(request_rec *r, void *args) +{ + return OK; +} diff --git a/pttbbs/web/util_cache.c b/pttbbs/web/util_cache.c new file mode 100755 index 00000000..5178dad5 --- /dev/null +++ b/pttbbs/web/util_cache.c @@ -0,0 +1,516 @@ +/* $Id: util_cache.c,v 1.1 2002/10/18 14:43:58 ptt Exp $ */ +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <signal.h> +#include <unistd.h> +#include <fcntl.h> +#include <ctype.h> +#include <errno.h> +#include <time.h> +#include <sys/types.h> +#include <sys/types.h> +#include <sys/mman.h> +#include <sys/ipc.h> +#include <sys/shm.h> +#include <sys/sem.h> + +#ifdef __FreeBSD__ +#include <machine/param.h> +#endif + +#include "config.h" +#include "pttstruct.h" +#include "common.h" +#include "perm.h" +#include "modes.h" +#include "proto.h" + +/* the reason for "safe_sleep" is that we may call sleep during + SIGALRM handler routine, while SIGALRM is blocked. + if we use the original sleep, we'll never wake up. */ +unsigned int safe_sleep(unsigned int seconds) { + /* jochang sleep有問題時用*/ + sigset_t set,oldset; + + sigemptyset(&set); + sigprocmask(SIG_BLOCK, &set, &oldset); + if(sigismember(&oldset, SIGALRM)) { + unsigned long retv; + sigemptyset(&set); + sigaddset(&set,SIGALRM); + sigprocmask(SIG_UNBLOCK,&set,NULL); + retv=sleep(seconds); + sigprocmask(SIG_BLOCK,&set,NULL); + return retv; + } + return sleep(seconds); +} + +void setapath(char *buf, char *boardname) { + sprintf(buf, "man/boards/%c/%s", boardname[0], boardname); +} + +static char *str_dotdir = ".DIR"; + +void setadir(char *buf, char *path) { + sprintf(buf, "%s/%s", path, str_dotdir); +} + +static void attach_err(int shmkey, char *name) { + fprintf(stderr, "[%s error] key = %x\n", name, shmkey); + fprintf(stderr, "errno = %d: %s\n", errno, strerror(errno)); + exit(1); +} + +void *attach_shm(int shmkey, int shmsize) { + void *shmptr; + int shmid; + + char *empty_addr; + /* set up one page in-accessible -- jochang */ + { + int fd = open("/dev/zero",O_RDONLY); + int size = ((shmsize + 4095) / 4096) * 4096; + + munmap( + (empty_addr=mmap(0,4096+size,PROT_NONE,MAP_PRIVATE,fd,0))+4096 + ,size); + + close(fd); + } + + shmid = shmget(shmkey, shmsize, 0); + if(shmid < 0) { + shmid = shmget(shmkey, shmsize, IPC_CREAT | 0600); + if(shmid < 0) + attach_err(shmkey, "shmget"); + shmptr = (void *)shmat(shmid, NULL, 0); + if(shmptr == (void *)-1) + attach_err(shmkey, "shmat"); + } else { + shmptr = (void *)shmat(shmid, NULL, 0); + if(shmptr == (void *)-1) + attach_err(shmkey, "shmat"); + } + + /* unmap the page -- jochang */ + { + munmap(empty_addr,4096); + } + return shmptr; +} + +#ifndef __FreeBSD__ +/* according to X/OPEN we have to define it ourselves */ +union semun { + int val; /* value for SETVAL */ + struct semid_ds *buf; /* buffer for IPC_STAT, IPC_SET */ + unsigned short int *array; /* array for GETALL, SETALL */ + struct seminfo *__buf; /* buffer for IPC_INFO */ +}; +#endif + +#define SEM_FLG 0600 /* semaphore mode */ + +/* ----------------------------------------------------- */ +/* semaphore : for critical section */ +/* ----------------------------------------------------- */ +void sem_init(int semkey,int *semid) { + union semun s; + + s.val=1; + *semid = semget(semkey, 1, 0); + if(*semid == -1) { + *semid = semget(semkey, 1, IPC_CREAT | SEM_FLG); + if(*semid == -1) + attach_err(semkey, "semget"); + semctl(*semid, 0, SETVAL, s); + } +} + +void sem_lock(int op,int semid) { + struct sembuf sops; + + sops.sem_num = 0; + sops.sem_flg = SEM_UNDO; + sops.sem_op = op; + semop(semid, &sops, 1); +} + +SHM_t *SHM; +int *GLOBALVAR; +boardheader_t *bcache; +int numboards = -1; + +void attach_SHM(void) +{ + SHM = attach_shm(SHM_KEY, sizeof(SHM_t)); + if( !SHM->loaded ) /* (uhash) assume fresh shared memory is zeroed */ + exit(1); + if( SHM->Btouchtime == 0 ) + SHM->Btouchtime = 1; + bcache = SHM->bcache; + + GLOBALVAR = SHM->GLOBALVAR; + if( SHM->Ptouchtime == 0 ) + SHM->Ptouchtime = 1; + + if( SHM->Ftouchtime == 0 ) + SHM->Ftouchtime = 1; + + bcache = SHM->bcache; + numboards = SHM->Bnumber; +} + +int setumoney(int uid, int money) { + SHM->money[uid-1]=money; + passwd_update_money(uid); + return SHM->money[uid-1]; +} + +int deumoney(int uid, int money) { + if(money<0 && SHM->money[uid-1]<-money) + return setumoney(uid,0); + else + return setumoney(uid,SHM->money[uid-1]+money); +} +int moneyof(int uid){ /* ptt 改進金錢處理效率 */ + return SHM->money[uid-1]; +} + +static unsigned string_hash(unsigned char *s) { + unsigned int v=0; + while(*s) { + v = (v << 8) | (v >> 24); + v ^= toupper(*s++); /* note this is case insensitive */ + } + return (v * 2654435769UL) >> (32 - HASH_BITS); +} + +void add_to_uhash(int n, char *id) { + int *p, h = string_hash(id); + strcpy(SHM->userid[n], id); + + p = &(SHM->hash_head[h]); + + while(*p != -1) + p = &(SHM->next_in_hash[*p]); + + SHM->next_in_hash[*p = n] = -1; +} + +/* note: after remove_from_uhash(), you should add_to_uhash() + (likely with a different name) */ +void remove_from_uhash(int n) { + int h = string_hash(SHM->userid[n]); + int *p = &(SHM->hash_head[h]); + + while(*p != -1 && *p != n) + p = &(SHM->next_in_hash[*p]); + if(*p == n) + *p = SHM->next_in_hash[n]; +} + +int searchuser(char *userid) { + int h,p; + + if(SHM == NULL) + attach_SHM(); /* for sloopy util programs */ + + h = string_hash(userid); + p = SHM->hash_head[h]; + + while(p != -1) { + if(strcasecmp(SHM->userid[p],userid) == 0) { + strcpy(userid,SHM->userid[p]); + return p + 1; + } + p = SHM->next_in_hash[p]; + } + return 0; +} +userec_t xuser; + +int getuser(char *userid) { + int uid; + if((uid = searchuser(userid))) + passwd_query(uid, &xuser); + return uid; +} + +void setuserid(int num, char *userid) { + if(num > 0 && num <= MAX_USERS) { + if(num > SHM->number) + SHM->number = num; + else + remove_from_uhash(num-1); + add_to_uhash(num-1,userid); + } +} + +/*-------------------------------------------------------*/ +/* .UTMP cache */ +/*-------------------------------------------------------*/ +void resolve_utmp() { + if(SHM == NULL) { + attach_SHM(); + if(SHM->UTMPuptime == 0) + SHM->UTMPuptime = SHM->UTMPnumber = 1; + } +} + +userinfo_t *currutmp = NULL; + +void getnewutmpent(userinfo_t *up) { + extern int errno; + register int i; + register userinfo_t *uentp; + + resolve_utmp(); + + for(i = 0; i < USHM_SIZE; i++) { + uentp = &(SHM->uinfo[i]); + if(!(uentp->pid)) { + memcpy(uentp, up, sizeof(userinfo_t)); + currutmp = uentp; + SHM->number++; + return; + } + } + exit(1); +} + +int apply_ulist(int (*fptr)(userinfo_t *)) { + register userinfo_t *uentp; + register int i, state; + + resolve_utmp(); + for(i = 0; i < USHM_SIZE; i++) { + uentp = &(SHM->uinfo[i]); + if(uentp->pid && (PERM_HIDE(currutmp) || !PERM_HIDE(uentp))) + if((state = (*fptr) (uentp))) + return state; + } + return 0; +} + +userinfo_t *search_ulist(int uid) { + register int i; + register userinfo_t *uentp; + + resolve_utmp(); + for(i = 0; i < USHM_SIZE; i++) { + uentp = &(SHM->uinfo[i]); + if(uid==uentp->uid) + return uentp; + } + return 0; +} + +/*-------------------------------------------------------*/ +/* .BOARDS cache */ +/*-------------------------------------------------------*/ +char *fn_board=BBSHOME"/"FN_BOARD; +static void reload_bcache() { + if(SHM->Bbusystate) { + safe_sleep(1); + } +} + +void resolve_boards() { + if(SHM == NULL) { + attach_SHM(); + if(SHM->Btouchtime == 0) + SHM->Btouchtime = 1; + } + + while(SHM->Buptime < SHM->Btouchtime) + reload_bcache(); + numboards = SHM->Bnumber; +} + +void touch_boards() { + time(&(SHM->Btouchtime)); + numboards = -1; + resolve_boards(); +} +void reset_board(int bid) +{ + int fd; + boardheader_t bh; + if(--bid<0)return; + if(SHM->Bbusystate==0) + { + SHM->Bbusystate = 1; + if((fd = open(fn_board, O_RDONLY)) > 0) { + lseek(fd, (off_t)(bid * sizeof(boardheader_t)), SEEK_SET); + read(fd, &bh , sizeof(boardheader_t)); + close(fd); + if(bh.brdname[0] && !strcmp(bh.brdname,bcache[bid].brdname)) + memcpy(&bcache[bid],&bh, sizeof(boardheader_t)); + } + SHM->Bbusystate = 0; + } +} +boardheader_t *getbcache(int bid) { /* Ptt改寫 */ + return bcache + bid - 1; +} + +void touchbtotal(int bid) { + SHM->total[bid - 1] = 0; + SHM->lastposttime[bid - 1] = 0; +} + + +int getbnum(char *bname) { + register int i; + register boardheader_t *bhdr; + + for(i = 0, bhdr = bcache; i++ < numboards; bhdr++) + if( + !strcasecmp(bname, bhdr->brdname)) + return i; + return 0; +} + +/*-------------------------------------------------------*/ +/* PTT cache */ +/*-------------------------------------------------------*/ +/* cachefor 動態看版 */ +void reload_pttcache(void) +{ + if(SHM->Pbusystate) + safe_sleep(1); + else { /* jochang: temporary workaround */ + fileheader_t item, subitem; + char pbuf[256], buf[256], *chr; + FILE *fp, *fp1, *fp2; + int id, section = 0; + + SHM->Pbusystate = 1; + SHM->max_film = 0; + bzero(SHM->notes, sizeof SHM->notes); + setapath(pbuf, "Note"); + setadir(buf, pbuf); + id = 0; + if((fp = fopen(buf, "r"))) { + while(fread(&item, sizeof(item), 1, fp)) { + if(item.title[3]=='<' && item.title[8]=='>') { + sprintf(buf,"%s/%s", pbuf, item.filename); + setadir(buf, buf); + if(!(fp1 = fopen(buf, "r"))) + continue; + SHM->next_refresh[section] = SHM->n_notes[section] = id; + section ++; + while(fread(&subitem, sizeof(subitem), 1, fp1)) { + sprintf(buf,"%s/%s/%s", pbuf, item.filename , + subitem.filename); + if(!(fp2=fopen(buf,"r"))) + continue; + fread(SHM->notes[id],sizeof(char), 200*11, fp2); + SHM->notes[id][200*11 - 1]=0; + id++; + fclose(fp2); + if(id >= MAX_MOVIE) + break; + } + fclose(fp1); + if(id >= MAX_MOVIE || section >= MAX_MOVIE_SECTION) + break; + } + } + fclose(fp); + } + SHM->next_refresh[section] = -1; + SHM->n_notes[section] = SHM->max_film = id-1; + SHM->max_history = SHM->max_film - 2; + if(SHM->max_history > MAX_HISTORY - 1) + SHM->max_history = MAX_HISTORY - 1; + if(SHM->max_history <0) SHM->max_history=0; + + fp = fopen("etc/today_is","r"); + if(fp) { + fgets(SHM->today_is,15,fp); + if((chr = strchr(SHM->today_is,'\n'))) + *chr = 0; + SHM->today_is[15] = 0; + fclose(fp); + } + + /* 等所有資料更新後再設定 uptime */ + + SHM->Puptime = SHM->Ptouchtime ; + SHM->Pbusystate = 0; + } +} + +void resolve_garbage() { + int count=0; + + if(SHM == NULL) { + attach_SHM(); + if(SHM->Ptouchtime == 0) + SHM->Ptouchtime = 1; + } + while(SHM->Puptime < SHM->Ptouchtime) { /* 不用while等 */ + reload_pttcache(); + if(count ++ > 10 && SHM->Pbusystate) { +/* Ptt: 這邊會有問題 load超過10 秒會所有進loop的process都讓 busystate = 0 + 這樣會所有prcosee都會在load 動態看板 會造成load大增 + 但沒有用這個function的話 萬一load passwd檔的process死了 又沒有人把他 + 解開 同樣的問題發生在reload passwd +*/ + SHM->Pbusystate = 0; + } + } +} + +/*-------------------------------------------------------*/ +/* PTT's cache */ +/*-------------------------------------------------------*/ +/* cachefor from host 與最多上線人數 */ +static void reload_fcache() { + if(SHM->Fbusystate) + safe_sleep(1); + else { + FILE *fp; + + SHM->Fbusystate = 1; + bzero(SHM->domain, sizeof SHM->domain); + if((fp = fopen("etc/domain_name_query","r"))) { + char buf[101],*po; + + SHM->top=0; + while(fgets(buf,100,fp)) { + if(buf[0] && buf[0] != '#' && buf[0] != ' ' && + buf[0] != '\n') { + sscanf(buf,"%s",SHM->domain[SHM->top]); + po = buf + strlen(SHM->domain[SHM->top]); + while(*po == ' ') + po++; + strncpy(SHM->replace[SHM->top],po,49); + SHM->replace[SHM->top] + [strlen(SHM->replace[SHM->top])-1] = 0; + (SHM->top)++; + } + } + } + + SHM->max_user=0; + + /* 等所有資料更新後再設定 uptime */ + SHM->Fuptime = SHM->Ftouchtime; + SHM->Fbusystate = 0; + } +} + +void resolve_fcache() { + if(SHM == NULL) { + attach_SHM(); + if(SHM->Ftouchtime == 0) + SHM->Ftouchtime = 1; + } + while(SHM->Fuptime < SHM->Ftouchtime) + reload_fcache(); +} diff --git a/pttbbs/web/util_passwd.c b/pttbbs/web/util_passwd.c new file mode 100755 index 00000000..03e90f6c --- /dev/null +++ b/pttbbs/web/util_passwd.c @@ -0,0 +1,141 @@ +/* $Id: util_passwd.c,v 1.1 2002/10/18 14:43:58 ptt Exp $ */ +#include <stdio.h> +#include <string.h> +#include <fcntl.h> +#include <errno.h> +#include <unistd.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <sys/mman.h> +#include <sys/ipc.h> +#include <sys/sem.h> +#include "config.h" +#include "pttstruct.h" +#include "modes.h" +#include "common.h" +#include "proto.h" + +#ifndef SEM_R +#define SEM_R 0400 +#endif + +#ifndef SEM_A +#define SEM_A 0200 +#endif + +#ifndef __FreeBSD__ +union semun { + int val; /* value for SETVAL */ + struct semid_ds *buf; /* buffer for IPC_STAT & IPC_SET */ + u_short *array; /* array for GETALL & SETALL */ + struct seminfo *__buf; /* buffer for IPC_INFO */ +}; +#endif + +static userec_t *passwd_image = NULL; +static int passwd_image_size; +static int semid = -1; + +int passwd_mmap() { + int fd; + + if(passwd_image!=NULL) return 0; + fd = open(FN_PASSWD, O_RDWR); + if(fd > 0) { + struct stat st; + + fstat(fd, &st); + passwd_image_size = st.st_size; + passwd_image = mmap(NULL, passwd_image_size, + PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); + if(passwd_image == (userec_t *)-1) { + perror("mmap"); + return -1; + } + close(fd); + semid = semget(PASSWDSEM_KEY, 1, SEM_R | SEM_A | IPC_CREAT | IPC_EXCL); + if(semid == -1) { + if(errno == EEXIST) { + semid = semget(PASSWDSEM_KEY, 1, SEM_R | SEM_A); + if(semid == -1) { + perror("semget"); + exit(1); + } + } else { + perror("semget"); + exit(1); + } + } else { + union semun s; + + s.val = 1; + if(semctl(semid, 0, SETVAL, s) == -1) { + perror("semctl"); + exit(1); + } + } + } else { + perror(FN_PASSWD); + return -1; + } + return 0; +} +int passwd_update_money(int num) { + int money; + if(num < 1 || num > MAX_USERS) + return -1; + money = moneyof(num); + memcpy(&passwd_image[num - 1].money, &money, sizeof(int)); + return 0; +} + +int passwd_update(int num, userec_t *buf) { + if(num < 1 || num > MAX_USERS) + return -1; + buf->money = moneyof(num); + memcpy(&passwd_image[num - 1], buf, sizeof(userec_t)); + return 0; +} + +int passwd_query(int num, userec_t *buf) { + if(num < 1 || num > MAX_USERS) + return -1; + memcpy(buf, &passwd_image[num - 1], sizeof(userec_t)); + return 0; +} + +int passwd_apply(int (*fptr)(userec_t *)) { + int i; + + for(i = 0; i < MAX_USERS; i++) + if((*fptr)(&passwd_image[i]) == QUIT) + return QUIT; + return 0; +} + +int passwd_apply2(int (*fptr)(int, userec_t *)) { + int i; + + for(i = 0; i < MAX_USERS; i++) + if((*fptr)(i, &passwd_image[i]) == QUIT) + return QUIT; + return 0; +} + +void passwd_lock() { + struct sembuf buf = { 0, -1, SEM_UNDO }; + + if(semop(semid, &buf, 1)) { + perror("semop"); + exit(1); + } +} + +void passwd_unlock() { + struct sembuf buf = { 0, 1, SEM_UNDO }; + + if(semop(semid, &buf, 1)) { + perror("semop"); + exit(1); + } +} diff --git a/pttbbs/web/util_record.c b/pttbbs/web/util_record.c new file mode 100755 index 00000000..bc74d575 --- /dev/null +++ b/pttbbs/web/util_record.c @@ -0,0 +1,245 @@ +/* $Id: util_record.c,v 1.1 2002/10/18 14:43:58 ptt Exp $ */ +#include <stdio.h> +#include <errno.h> +#include <string.h> +#include <unistd.h> +#include <time.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <sys/file.h> +#include "config.h" +#include "pttstruct.h" +#include "modes.h" +#include "proto.h" + +#undef HAVE_MMAP +#define BUFSIZE 512 + +extern char *str_reply; + +static void PttLock(int fd, int size, int mode) { + static struct flock lock_it; + int ret; + + lock_it.l_whence = SEEK_CUR; /* from current point */ + lock_it.l_start = 0; /* -"- */ + lock_it.l_len = size; /* length of data */ + lock_it.l_type = mode; /* set exclusive/write lock */ + lock_it.l_pid = 0; /* pid not actually interesting */ + while((ret = fcntl(fd, F_SETLKW, &lock_it)) < 0 && errno == EINTR); +} + +#define safewrite write + +int get_num_records(char *fpath, int size) { + struct stat st; + if(stat(fpath, &st) == -1) + return 0; + return st.st_size / size; +} + +int get_sum_records(char* fpath, int size) { + struct stat st; + long ans = 0; + FILE* fp; + fileheader_t fhdr; + char buf[200], *p; + + if(!(fp = fopen(fpath, "r"))) + return -1; + + strcpy(buf, fpath); + p = strrchr(buf, '/') + 1; + + while(fread(&fhdr, size, 1, fp) == 1) { + strcpy(p, fhdr.filename); + if(stat(buf, &st) == 0 && S_ISREG(st.st_mode) && st.st_nlink == 1) + ans += st.st_size; + } + fclose(fp); + return ans / 1024; +} + +int get_record(char *fpath, void *rptr, int size, int id) { + int fd = -1; + + if(id < 1 || (fd = open(fpath, O_RDONLY, 0)) != -1) { + if(lseek(fd, (off_t)(size * (id - 1)), SEEK_SET) != -1) { + if(read(fd, rptr, size) == size) { + close(fd); + return 0; + } + } + close(fd); + } + return -1; +} + +int get_records(char *fpath, void *rptr, int size, int id, int number) { + int fd; + + if(id < 1 || (fd = open(fpath, O_RDONLY, 0)) == -1) + return -1; + + if(lseek(fd, (off_t)(size * (id - 1)), SEEK_SET) == -1) { + close(fd); + return 0; + } + if((id = read(fd, rptr, size * number)) == -1) { + close(fd); + return -1; + } + close(fd); + return id / size; +} + +int substitute_record(char *fpath, void *rptr, int size, int id) { + int fd; + +#ifdef POSTBUG + if(size == sizeof(fileheader) && (id > 1) && ((id - 1) % 4 == 0)) + saverecords(fpath, size, id); +#endif + + if(id < 1 || (fd = open(fpath, O_WRONLY | O_CREAT, 0644)) == -1) + return -1; + +#ifdef HAVE_REPORT + if(lseek(fd, (off_t)(size * (id - 1)), SEEK_SET) == -1) + report("substitute_record failed!!! (lseek)"); + PttLock(fd, size, F_WRLCK); + if(safewrite(fd, rptr, size) != size) + report("substitute_record failed!!! (safewrite)"); + PttLock(fd, size, F_UNLCK); +#else + lseek(fd, (off_t) (size * (id - 1)), SEEK_SET); + PttLock(fd, size, F_WRLCK); + safewrite(fd, rptr, size); + PttLock(fd, size, F_UNLCK); +#endif + close(fd); + +#ifdef POSTBUG + if(size == sizeof(fileheader) && (id > 1) && ((id - 1) % 4 == 0)) + restorerecords(fpath, size, id); +#endif + + return 0; +} + +int apply_record(char *fpath, int (*fptr)(), int size) { + char abuf[BUFSIZE]; + FILE* fp; + + if(!(fp = fopen(fpath, "r"))) + return -1; + + while(fread(abuf, 1, size, fp) == size) + if((*fptr) (abuf) == QUIT) { + fclose(fp); + return QUIT; + } + fclose(fp); + return 0; +} + +/* mail / post 時,依據時間建立檔案,加上郵戳 */ +int stampfile(char *fpath, fileheader_t *fh) { + register char *ip = fpath; + time_t dtime; + struct tm *ptime; + int fp = 0; + + if(access(fpath, X_OK | R_OK | W_OK)) + mkdir(fpath, 0755); + + time(&dtime); + while (*(++ip)); + *ip++ = '/'; + do { + sprintf(ip, "M.%ld.A.%3.3X", ++dtime, rand()&0xfff ); + if(fp == -1 && errno != EEXIST) + return -1; + } while((fp = open(fpath, O_CREAT | O_EXCL | O_WRONLY, 0644)) == -1); + close(fp); + memset(fh, 0, sizeof(fileheader_t)); + strcpy(fh->filename, ip); + ptime = localtime(&dtime); + sprintf(fh->date, "%2d/%02d", ptime->tm_mon + 1, ptime->tm_mday); + return 0; +} + +void stampdir(char *fpath, fileheader_t *fh) { + register char *ip = fpath; + time_t dtime; + struct tm *ptime; + + if(access(fpath, X_OK | R_OK | W_OK)) + mkdir(fpath, 0755); + + time(&dtime); + while(*(++ip)); + *ip++ = '/'; + do { + sprintf(ip, "D%lX", ++dtime & 07777); + } while(mkdir(fpath, 0755) == -1); + memset(fh, 0, sizeof(fileheader_t)); + strcpy(fh->filename, ip); + ptime = localtime(&dtime); + sprintf(fh->date, "%2d/%02d", ptime->tm_mon + 1, ptime->tm_mday); +} + +void stamplink(char *fpath, fileheader_t *fh) { + register char *ip = fpath; + time_t dtime; + struct tm *ptime; + + if(access(fpath, X_OK | R_OK | W_OK)) + mkdir(fpath, 0755); + + time(&dtime); + while(*(++ip)); + *ip++ = '/'; + do { + sprintf(ip, "S%lX", ++dtime ); + } while(symlink("temp", fpath) == -1); + memset(fh, 0, sizeof(fileheader_t)); + strcpy(fh->filename, ip); + ptime = localtime(&dtime); + sprintf(fh->date, "%2d/%02d", ptime->tm_mon + 1, ptime->tm_mday); +} + +int do_append(char *fpath, fileheader_t *record, int size) { + int fd; + + if((fd = open(fpath, O_WRONLY | O_CREAT, 0644)) == -1) { + perror("open"); + return -1; + } + flock(fd, LOCK_EX); + lseek(fd, 0, SEEK_END); + + safewrite(fd, record, size); + + flock(fd, LOCK_UN); + close(fd); + return 0; +} + +int append_record(char *fpath, fileheader_t *record, int size) { +#ifdef POSTBUG + int numrecs = (int)get_num_records(fpath, size); + + bug_possible = 1; + if(size == sizeof(fileheader) && numrecs && (numrecs % 4 == 0)) + saverecords(fpath, size, numrecs + 1); +#endif + do_append(fpath,record,size); + +#ifdef POSTBUG + if(size == sizeof(fileheader) && numrecs && (numrecs % 4 == 0)) + restorerecords(fpath, size, numrecs + 1); + bug_possible = 0; +#endif + return 0; +} -- cgit v1.2.3 From e74b8edb14901f7ed88d97e84f738dd81a9daf5d Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Wed, 23 Oct 2002 17:10:04 +0000 Subject: in searchuser, return 0 if uhash is wrong git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@540 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/cache.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pttbbs/mbbsd/cache.c b/pttbbs/mbbsd/cache.c index 32da5a7f..ff3a8340 100644 --- a/pttbbs/mbbsd/cache.c +++ b/pttbbs/mbbsd/cache.c @@ -1,4 +1,4 @@ -/* $Id: cache.c,v 1.51 2002/08/27 21:16:12 kcwu Exp $ */ +/* $Id: cache.c,v 1.52 2002/10/23 17:10:04 in2 Exp $ */ #include "bbs.h" #ifndef __FreeBSD__ @@ -224,7 +224,7 @@ searchuser(char *userid) h = StringHash(userid); p = SHM->hash_head[h]; - for (times = 0; times < MAX_USERS && p != -1; ++times) { + for (times = 0; times < MAX_USERS && p != -1 && p < MAX_USERS ; ++times) { if (strcasecmp(SHM->userid[p], userid) == 0) { strcpy(userid, SHM->userid[p]); return p + 1; -- cgit v1.2.3 From e9e0834ee240032dd172a9f39e6cc4fdc728022f Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sat, 26 Oct 2002 00:12:52 +0000 Subject: register git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@541 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/user.c | 135 +++++++++++++++++++++++++++++++--------------------- 1 file changed, 81 insertions(+), 54 deletions(-) diff --git a/pttbbs/mbbsd/user.c b/pttbbs/mbbsd/user.c index d77d6721..6e51a9fa 100644 --- a/pttbbs/mbbsd/user.c +++ b/pttbbs/mbbsd/user.c @@ -1,4 +1,4 @@ -/* $Id: user.c,v 1.39 2002/10/16 13:04:11 in2 Exp $ */ +/* $Id: user.c,v 1.40 2002/10/26 00:12:52 in2 Exp $ */ #include "bbs.h" static char *sex[8] = { @@ -933,6 +933,68 @@ toregister(char *email, char *genbuf, char *phone, char *career, } } +static char *isvaildname(char *rname) +{ + if( removespace(rname) && rname[0] < 0 && + strlen(rname) >= 4 && + !strstr(rname, "阿") && !strstr(rname, "小") && + !strstr(rname, "ㄚ") && strstr(rname, "..") == NULL && + !strstr(rname, "美女") && !strstr(rname, "帥哥") && + !(strlen(rname) == 4 && strncmp(&rname[2], "兒", 2) == 0) && + !(strlen(rname) >= 4 && strncmp(&rname[0], &rname[2], 2) == 0)) + return NULL; + return "您的輸入不正確"; +} + +static char *isvaildcareer(char *career) +{ + if (!(removespace(career) && career[0] < 0 + && strlen(career) >= 6) || + strcmp(career, "家裡") == 0 || + strstr(career, "某") != NULL ) { + return "您的輸入不正確"; + } + if (strcmp(&career[strlen(career) - 2], "大") == 0 || + strcmp(&career[strlen(career) - 4], "大學") == 0 ) + return "麻煩請加學校系所"; + return NULL; +} + +static char *isvaildaddr(char *addr) +{ + if (!removespace(addr) || addr[0] > 0 || strlen(addr) < 15) + return "這個地址並不合法"; + if (strstr(addr, "信箱") != NULL || strstr(addr, "郵政") != NULL) + return "抱歉我們不接受郵政信箱"; + if ((strstr(addr, "市") == NULL && strstr(addr, "巿") == NULL && + strstr(addr, "縣") == NULL && strstr(addr, "室") == NULL) || + strstr(addr, "地球") != NULL || + strstr(addr, "銀河") != NULL || + strstr(addr, "火星") != NULL || + strstr(addr, "某") != NULL || + strstr(addr, "..") != NULL || + strcmp(&addr[strlen(addr) - 2], "段") == 0 || + strcmp(&addr[strlen(addr) - 2], "路") == 0 || + strcmp(&addr[strlen(addr) - 2], "巷") == 0 || + strcmp(&addr[strlen(addr) - 2], "街") == 0 ) + return "這個地址並不合法"; + return NULL; +} + +static char *isvaildphone(char *phone) +{ + if (strstr(phone, "(") || strstr(phone, ")") || strstr(phone, "-")){ + return "電話請不加 ( ) - 符號"; + } + if (!removespace(phone) || phone[0] != '0' || + strlen(phone) < 9 || phone[1] == '0' || + strstr(phone, "00000000") != NULL || + strstr(phone, "22222222") != NULL ) { + return "這個電話號碼並不合法(請含區碼)" ; + } + return NULL; +} + int u_register(void) { @@ -940,7 +1002,7 @@ u_register(void) char phone[21], career[41], email[51], birthday[9], sex_is[2], year, mon, day; char inregcode[14], regcode[50]; - char ans[3], *ptr; + char ans[3], *ptr, *errcode; char genbuf[200]; FILE *fn; @@ -990,6 +1052,7 @@ u_register(void) mobile[strlen(mobile) - 1] = 0; fclose(fn); } + if (cuser.year != 0 && /* 已經第一次填過了~ ^^" */ strcmp(cuser.email, "x") != 0 && /* 上次手動認證失敗 */ strcmp(cuser.email, "X") != 0) { @@ -1026,6 +1089,7 @@ u_register(void) toregister(email, genbuf, phone, career, ident, rname, addr, mobile); return FULLUPDATE; } + getdata(b_lines - 1, 0, "您確定要填寫註冊單嗎(Y/N)?[N] ", ans, sizeof(ans), LCECHO); if (ans[0] != 'y') @@ -1048,13 +1112,10 @@ u_register(void) } while (1) { getfield(5, "請用中文", "真實姓名", rname, 20); - if (removespace(rname) && rname[0] < 0 && - !strstr(rname, "阿") && !strstr(rname, "小") && - !strstr(rname, "ㄚ") && strstr(rname, "..") == NULL && - !(strlen(rname) == 4 && strncmp(&rname[2], "兒", 2) == 0) && - !(strlen(rname) >= 4 && strncmp(&rname[0], &rname[2], 2) == 0)) + if( (errcode = isvaildname(rname)) == NULL ) break; - vmsg("您的輸入不正確"); + else + vmsg(errcode); } move(7, 0); @@ -1063,60 +1124,26 @@ u_register(void) while (1) { getfield(8, "學校(含\033[1;33m系所年級\033[m)或單位職稱", "服務單位", career, 40); - if (!(removespace(career) && career[0] < 0 - && strlen(career) >= 6) || - strcmp(career, "家裡") == 0 || - strstr(career, "某") != NULL ) { - vmsg("您的輸入不正確"); - continue; - } - if (strcmp(&career[strlen(career) - 2], "大") == 0 || - strcmp(&career[strlen(career) - 4], "大學") == 0 ) { - vmsg("麻煩請加學校系所"); - continue; - } - break; + if( (errcode = isvaildcareer(career)) == NULL ) + break; + else + vmsg(errcode); } while (1) { getfield(10, "含\033[1;33m縣市\033[m及門寢號碼" "(台北請加\033[1;33m行政區\033[m)", "目前住址", addr, 50); - if (!removespace(addr) || addr[0] > 0 || strlen(addr) < 15) { - vmsg("這個地址並不合法"); - continue; - } - if (strstr(addr, "信箱") != NULL || strstr(addr, "郵政") != NULL) { - vmsg("抱歉我們不接受郵政信箱"); - continue; - } - if ((strstr(addr, "市") == NULL && strstr(addr, "縣") == NULL && - strstr(addr, "室") == NULL) || - strstr(addr, "地球") != NULL || - strstr(addr, "銀河") != NULL || - strstr(addr, "火星") != NULL || - strstr(addr, "某") != NULL || - strstr(addr, "..") != NULL || - strcmp(&addr[strlen(addr) - 2], "段") == 0 || - strcmp(&addr[strlen(addr) - 2], "路") == 0 || - strcmp(&addr[strlen(addr) - 2], "巷") == 0 || - strcmp(&addr[strlen(addr) - 2], "街") == 0 ) { - vmsg("這個地址並不合法"); - continue; - } - break; + if( (errcode = isvaildaddr(addr)) == NULL ) + break; + else + vmsg(errcode); } while (1) { getfield(12, "不加-(), 包括長途區號", "連絡電話", phone, 11); - if (strstr(phone, "(") || strstr(phone, ")") || strstr(phone, "-")){ - vmsg("電話請不加 ( ) - 符號"); - continue; - } - if (!removespace(phone) || phone[0] != '0' || - strlen(phone) < 9 || phone[1] == '0') { - vmsg("這個電話號碼並不合法(請含區碼)"); - continue; - } - break; + if( (errcode = isvaildphone(phone)) == NULL ) + break; + else + vmsg(errcode); } getfield(14, "只輸入數字 如:0912345678 (可不填)", "手機號碼", mobile, 20); -- cgit v1.2.3 From d5f292c4e80f8fe182c4a5ddff05cb8703b27377 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sat, 26 Oct 2002 03:54:15 +0000 Subject: MAX_EDIT_LINE git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@542 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/edit.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/pttbbs/mbbsd/edit.c b/pttbbs/mbbsd/edit.c index 5073d10a..8685dfc5 100644 --- a/pttbbs/mbbsd/edit.c +++ b/pttbbs/mbbsd/edit.c @@ -1,4 +1,4 @@ -/* $Id: edit.c,v 1.19 2002/09/11 07:16:49 kcwu Exp $ */ +/* $Id: edit.c,v 1.20 2002/10/26 03:54:15 in2 Exp $ */ #include "bbs.h" typedef struct textline_t { struct textline_t *prev; @@ -268,6 +268,12 @@ split(textline_t * line, int pos) register char *ptr; int spcs = indent_spcs(); +#ifdef MAX_EDIT_LINE + if( totaln == MAX_EDIT_LINE ){ + vmsg("MAX_EDIT_LINE exceed"); + return; + } +#endif totaln++; p->len = line->len - pos + spcs; -- cgit v1.2.3 From a37bbf0c896ca712cf28d8cd48bc9401518a6193 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sat, 26 Oct 2002 18:10:37 +0000 Subject: new git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@543 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/sample/pttbbs.conf | 63 ++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 59 insertions(+), 4 deletions(-) diff --git a/pttbbs/sample/pttbbs.conf b/pttbbs/sample/pttbbs.conf index 343c0299..f791f328 100644 --- a/pttbbs/sample/pttbbs.conf +++ b/pttbbs/sample/pttbbs.conf @@ -1,10 +1,65 @@ /* 定義 BBS 站名位址 */ +#define BBSNAME "新批踢踢" /* 中文站名 */ +#define MYHOSTNAME "ptt2.cc" /* 網路位址 */ +#define MYIP "140.112.30.143" /* IP位址 */ -#define BBSNAME "新批踢踢" /* 中文站名 */ -#define MYHOSTNAME "ptt2.twbbs.org.tw" /* 網路位址 */ -#define MYIP "140.112.8.192" /* IP位址 */ +/* 定義系統資訊 */ #define BBSUSER "bbs" #define BBSUID 9999 #define BBSGID 99 -#define MAX_USERS 10000 +/* 最大編輯行數, 以防有惡意使用使 post 巨大文章 */ +#define MAX_EDIT_LINE 2048 + +/* 若定義, 則可以免費隱形 */ +#define HAVE_FREECLOAK 1 + +/* 可以設定多重進站畫面 */ +#define MULTI_WELCOME_LOGIN + +/* 最大 CPU負荷, 超過的時候將拒決 login */ +#define MAX_CPULOAD 400 + +/* 最多註冊人數, 每個人會用掉 21 bytes 的 shared-memory */ +#define MAX_USERS 150000 + +/* 最多同時上線人數, 每個人會用掉 3456 bytes 的 shared-memory */ +#define MAX_ACTIVE 4096 + +/* 寄信的 relay server */ +#define RELAY_SERVER_IP "140.112.30.144" // to pttx + +/* 抬頭色彩 */ +#define TITLE_COLOR "\33[0;1;37;46m" + +/* 若定義, 則所有編輯文章最下方都會加入編輯來源. + 否則只有 SYSOP板會加入來源 */ +//#define ALL_REEDIT_LOG + +/* 定義看板好友名單將會在幾秒鐘後失效強迫重載 */ +#define HBFLexpire 432000 + +/* 板主可以按大寫 H切換隱形與否 */ +#define BMCHS + +/* 水球整理, 看板備份等等外部程式 */ +#define OUTJOBSPOOL + +/* 若定義, 則不能舉辦賭盤 */ +#define NO_GAMBLE + +/* 可動態透過 GLOBALVAR[9]調整使用者上限 */ +#define DYMAX_ACTIVE + +/* 程式最多可以跑多久 (in min) 因為有的時候會出現跑不停的 process */ +#define CPULIMIT 1 + +/* 若程式失敗, 會等待 86400 秒以讓 gdb來 attach */ +#define DEBUGSLEEP + +/* 用一個奇怪的數字來檢查我的最愛和看板列表是否錯誤 */ +#define MEM_CHECK 0x98761234 + +/* 前進站畫面 */ +#define INSCREEN \ +"前站站畫面" -- cgit v1.2.3 From 2d2f38521dbf53907b57d43fb3bb6c2df1c01e26 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sat, 26 Oct 2002 18:13:47 +0000 Subject: MAX_BOARD git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@544 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/sample/pttbbs.conf | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/pttbbs/sample/pttbbs.conf b/pttbbs/sample/pttbbs.conf index f791f328..9dda2061 100644 --- a/pttbbs/sample/pttbbs.conf +++ b/pttbbs/sample/pttbbs.conf @@ -18,13 +18,16 @@ #define MULTI_WELCOME_LOGIN /* 最大 CPU負荷, 超過的時候將拒決 login */ -#define MAX_CPULOAD 400 +#define MAX_CPULOAD (400) /* 最多註冊人數, 每個人會用掉 21 bytes 的 shared-memory */ -#define MAX_USERS 150000 +#define MAX_USERS (150000) /* 最多同時上線人數, 每個人會用掉 3456 bytes 的 shared-memory */ -#define MAX_ACTIVE 4096 +#define MAX_ACTIVE (4096) + +/* 最大開板個數, 每個會用掉 6420 bytes 的 shared-memory */ +#define MAX_BOARD (8192) /* 寄信的 relay server */ #define RELAY_SERVER_IP "140.112.30.144" // to pttx @@ -37,7 +40,7 @@ //#define ALL_REEDIT_LOG /* 定義看板好友名單將會在幾秒鐘後失效強迫重載 */ -#define HBFLexpire 432000 +#define HBFLexpire (432000) /* 板主可以按大寫 H切換隱形與否 */ #define BMCHS -- cgit v1.2.3 From bffe119e737d257a462f9b203d07b0ab2d6c13d5 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sat, 26 Oct 2002 18:30:44 +0000 Subject: new git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@545 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/sample/etc/bad_host | 0 pttbbs/sample/etc/banemail | 22 ++++++++++++++++++++++ pttbbs/sample/etc/expire.conf | 4 ++++ pttbbs/sample/etc/feast | 3 ++- pttbbs/sample/etc/register | 2 +- pttbbs/sample/etc/registeredmail | 21 +++++++++++++++++++++ pttbbs/sample/etc/registermail | 11 +++++++++++ pttbbs/sample/etc/sysop | 6 ++++++ pttbbs/util/initbbs.c | 33 ++++++++++++++++++++++++++++++++- 9 files changed, 99 insertions(+), 3 deletions(-) create mode 100644 pttbbs/sample/etc/bad_host create mode 100644 pttbbs/sample/etc/banemail create mode 100644 pttbbs/sample/etc/expire.conf create mode 100644 pttbbs/sample/etc/registeredmail create mode 100644 pttbbs/sample/etc/registermail create mode 100644 pttbbs/sample/etc/sysop diff --git a/pttbbs/sample/etc/bad_host b/pttbbs/sample/etc/bad_host new file mode 100644 index 00000000..e69de29b diff --git a/pttbbs/sample/etc/banemail b/pttbbs/sample/etc/banemail new file mode 100644 index 00000000..03286bf0 --- /dev/null +++ b/pttbbs/sample/etc/banemail @@ -0,0 +1,22 @@ +# 用來設定哪些信箱不接受 +# 開頭 A表示全部 match的時候就不接受 (ex: 不歡迎的使用者) +# 開頭 P表示 match這個部份就不接受 +# 開頭 S表示不接受這台 server +#-- +# 不接受打 ip 的mail server +P@[ +Purl.com.tw +P.bbs@ +Skkcity.com.tw +Syahoo.com +Syahoo.com.tw +Syahoo.com.hk +Skimo.com.tw +Skimo.com +Ssinamail.com +Spchome.com.tw +Shotmail.com +Smsn.com +Syam.com +Syammail.com +Smail.taipeilink.net diff --git a/pttbbs/sample/etc/expire.conf b/pttbbs/sample/etc/expire.conf new file mode 100644 index 00000000..9cb8340d --- /dev/null +++ b/pttbbs/sample/etc/expire.conf @@ -0,0 +1,4 @@ +# board days max min +# --------------------------------------- +cvslog 999 9999 +asciiart 50 3000 diff --git a/pttbbs/sample/etc/feast b/pttbbs/sample/etc/feast index 29473341..e4ea9199 100644 --- a/pttbbs/sample/etc/feast +++ b/pttbbs/sample/etc/feast @@ -1,5 +1,5 @@ 01 01 元旦放假 -01 02 元旦又放假 +01 02 元旦隔天不放假 01 11 司法節 01 23 自由日 02 14 情人節 @@ -15,6 +15,7 @@ 04 04 婦幼節 04 04 兒童節 04 05 清明節 +04 21 創站週年慶 05 01 勞動節 05 04 文藝節 06 03 禁煙節 diff --git a/pttbbs/sample/etc/register b/pttbbs/sample/etc/register index 53b5e2d6..be131b06 100644 --- a/pttbbs/sample/etc/register +++ b/pttbbs/sample/etc/register @@ -10,7 +10,7 @@ │目前住址: 新竹縣子虛鄉烏有村543號 │ 您目前的聯絡地址(詳細填寫) │ │網路郵件地址: whoami@cs.ntnu.edu.tw │ 您的 E-Mail address │ └───────────────────┴─────────────────┘ - ※ 在本站註冊者,代表願意尊從本站制度與站規,否則請離開。 + ※ 在本站註冊者,代表願意尊從本站制度與站規,否則請離開。 ※ 代號 [ID] 至少要兩個字,不宜採用數字。 ※ 密碼 至少要四個字,不可與 [ID] 雷同,不宜全部小寫。 ※ 請確實按照規定詳細填寫,否則不予通過! diff --git a/pttbbs/sample/etc/registeredmail b/pttbbs/sample/etc/registeredmail new file mode 100644 index 00000000..255f2708 --- /dev/null +++ b/pttbbs/sample/etc/registeredmail @@ -0,0 +1,21 @@ + 歈歈 + 僓僓 EMail認證通過  +◇── 裺裺────────────────────────◇ + + 嗨嗨,*s你好: + + 歡迎加入 ptt2 的行列 ^o^ + + 若還不能Post請重新login一次 ^_^ (要換身份囉) + + + + 祝 使用愉快 + + 記得常常來玩喔.... ^_^ + + + + + 站長~~ +◇────────────────────────────────────◇ diff --git a/pttbbs/sample/etc/registermail b/pttbbs/sample/etc/registermail new file mode 100644 index 00000000..aa38aef1 --- /dev/null +++ b/pttbbs/sample/etc/registermail @@ -0,0 +1,11 @@ +親愛的使用者您好: + + 歡迎您到 ptt2 註冊, + 請直接到 (U)ser -> (R)egister 填入您的認證碼 (在主旨上) + 即可通過認證取得所有功能喔~ :) + 如果有須要服務的地方, + 請到 SYSOP板, 我們會竭誠為您服務~ :) + + ptt站長群敬上 + +注意: 若您並沒有至 ptt2 註冊, 請直接刪除這封信. diff --git a/pttbbs/sample/etc/sysop b/pttbbs/sample/etc/sysop new file mode 100644 index 00000000..d0276ccd --- /dev/null +++ b/pttbbs/sample/etc/sysop @@ -0,0 +1,6 @@ +in2: 程設站長/root +clifflu: 程設站長 +CChess: 看板總管 +windsheep: 看板總管 +ltlmouse: 帳號總管 +Sunicer: 帳號總管 diff --git a/pttbbs/util/initbbs.c b/pttbbs/util/initbbs.c index f88daf92..8d95534c 100644 --- a/pttbbs/util/initbbs.c +++ b/pttbbs/util/initbbs.c @@ -1,4 +1,4 @@ -/* $Id: initbbs.c,v 1.4 2002/05/25 11:17:55 ptt Exp $ */ +/* $Id: initbbs.c,v 1.5 2002/10/26 18:30:44 in2 Exp $ */ #include <stdio.h> #include <string.h> #include <stdlib.h> @@ -34,6 +34,35 @@ static void initHome() { } } +static void initBoardsDIR() { + int i; + char buf[256]; + + mkdir("boards", 0755); + strcpy(buf, "boards/?"); + for(i = 0; i < 26; i++) { + buf[7] = 'A' + i; + mkdir(buf, 0755); + buf[7] = 'a' + i; + mkdir(buf, 0755); + } +} + +static void initManDIR() { + int i; + char buf[256]; + + mkdir("man", 0755); + mkdir("man/boards", 0755); + strcpy(buf, "man/boards/?"); + for(i = 0; i < 26; i++) { + buf[11] = 'A' + i; + mkdir(buf, 0755); + buf[11] = 'a' + i; + mkdir(buf, 0755); + } +} + static void initPasswds() { int i; userec_t u; @@ -212,6 +241,8 @@ int main() { initDir(); initHome(); + initBoardsDIR(); + initManDIR(); initPasswds(); initBoards(); initMan(); -- cgit v1.2.3 From 5d411dcc79eea177bedc960fad5f3fb47c50eaf3 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sat, 26 Oct 2002 18:52:10 +0000 Subject: new git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@546 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/docs/ADVANCE | 39 +++++++++++++ pttbbs/docs/FAQ | 98 ++------------------------------ pttbbs/docs/FAQ.old | 146 ++++++++++++++++++++++++++++++++++++++++++++++++ pttbbs/docs/INSTALL | 20 ++++++- pttbbs/docs/INSTALL.old | 49 ++++++++++++++++ 5 files changed, 258 insertions(+), 94 deletions(-) create mode 100644 pttbbs/docs/ADVANCE create mode 100755 pttbbs/docs/FAQ.old create mode 100755 pttbbs/docs/INSTALL.old diff --git a/pttbbs/docs/ADVANCE b/pttbbs/docs/ADVANCE new file mode 100644 index 00000000..dd1a2e28 --- /dev/null +++ b/pttbbs/docs/ADVANCE @@ -0,0 +1,39 @@ +我們在這個版本裡面加入了一些好玩的東西, +最主要是希望可以偷懶做一些事情. + +bbsctl +------ +bbsctl是一個很特別的程式, 安裝有點複雜. + 1.先用 bbsadm 的權限在 util/下 make bbsctl + 2.改成 root 的權限在 util/下 make installbbsctl +如此會把 bbsctl 安裝到 /usr/local/bin 下, 以方便在任何目錄下皆可使用. +!!請注意, bbsctl 是有 root setuid的, 這可能會有安全上的問題!! + +您可以直接打 bbsctl 來看有什麼功能. +主要的功能說明如下: +1.bbsctl start + 用於啟動 mbbsd (須先跑 uhash_loader) + 以往因為要 bind port 23 須要 root 所以要手動 su , + 不過現在有 bbsctl with setuid , + 請直接使用 bbsctl start , 即可將 mbbsd跑起來. +2.bbsctl stop + 會將所有正在 listen 的 mbbsd都砍掉 +3.bbsctl restart + 即 bbsctl stop; bbsctl start + 主要是如果程式更新的話, 可以透過這個來直接重跑. +4.bbsctl bbsadm + 若該使用者有加入 bbsadm 群組, 則同於直接 su 成 bbsadm + (不須密碼) + 如此您可以將某些有管理權限的使用者, + 透過 /etc/group 放進 bbsadm 的群組, + 讓她們在 login後可以直接用 bbsctl bbsadm來換成 bbsadm 的權限. + + + +shmctl +------ +這隻程式主要是外部用來輔助 shared-memory正常運作的. +1.shmctl utmpfix + 將 shared-memory中 utmp 不正確的 record 清掉. + 建議至少每小時跑一次. + 另外可以用這個來外部設定 idle 多久後就踢人. diff --git a/pttbbs/docs/FAQ b/pttbbs/docs/FAQ index bc2904a0..9faf6109 100644 --- a/pttbbs/docs/FAQ +++ b/pttbbs/docs/FAQ @@ -1,74 +1,9 @@ - 作者 DavidYu (^^Y) 看板 PttSrc - 標題 Re: 安裝完連線時..... - 時間 Thu May 18 15:08:04 2000 -─────────────────────────────────────── - -※ 引述《JamesCheng (網球比排球好玩啦!)》之銘言: -: 我在安裝完之後 用root執行 mbbsd 23 -: 連線看出現 -: Escape character is '^]'. -: 【物治樂園】◎ 物治第二站 ◎(pt.mc.ntu.edu.tw) -: 調幅(140.112.122.44) 系統負荷 0.00 0.01 0.00 -: Connection closed by foreign host. -: 然後系統出現下列訊息 -: [shmget error] key = 8ab -: errno = 12: Cannot allocate memory -: 這是何原因呢? -shared memory要加大 -在kernel config file中加一行 -options SHMMAXPGS=4100 -重新make kernel - --- -※ 發信站: 批踢踢實業坊(ptt.twbbs.org) -◆ From: oio.m6.ntu.edu.t - - 作者 DavidYu (Do it YOURSELF!) 看板 PttSrc - 標題 Re: 請問一下... - 時間 Sat May 27 18:41:39 2000 -─────────────────────────────────────── - -※ 引述《clifflu ( 煩呀煩呀煩~~~)》之銘言: -: ※ 引述《hscat (復站了!)》之銘言: -: : 不過我有一個小小的問題 -: : 能不能指導一下...想要開新的版應該從哪邊開呢? -: 主選單下的 (0)Admin ?? -: : 因為我實在找不到怎麼開新看板...:~~~~... -不不不.. -開板要從分類看板的地方開,這部份有點小小的複雜, -和以往的版本不一樣,我來簡單說明一下: - -首先介紹看板. -看板有兩種, 一般看板和群組看板. 如果用檔案系統的架構來看的話, -一般看板如同 file, 而群組看板就是 directory -(在所有看板列表的地方只會出現一般看板) - -一個看板有UID及GID這兩個屬性. UID是unique的,從1開始分配,系統在開板時會 -菾佧llocate一個. 而GID是指定這個看板在哪一個群組看板之下(看板是樹狀架構的) -所以如果有一個群組看板的UID是x, 則GID為x的看板都會擺在該群組看板之下 -而如果看板GID為0(保留的UID)的話,該看板就會出現在一開始從主選單進CLASS的 -那個地方 - -至於開板的方法. -首先從CLASS進到你想要開新板的類別下,然後按大B設定 -如此新開的板就會自動assign GID 到那個類別下 - -如果要般動一個已經開好的板到其他類別的話 -先找出那個類別(群組看板)的UID, 按大E可以看到 -然後把要搬動的板的GID設成那個UID及可 - -值得注意的是, 如果把某個使用者設成某群組看板的板主的話 -則當他從CLASS進到那個群組時會獲得小組長的權限(可以開板,設定看板等等) -要特別小心 - -比較麻煩的地方: -一個新開的群組裡面並沒有任何看板,所以無法從選單進去裡面開板 -這時候就需要在可開板的地方先開個板,然後再把那個板的GID設過去即可 -(這也是為什麼需要一個initial的.BOARDS的原因 :p) - --- -※ 發信站: 批踢踢實業坊(ptt.twbbs.org) -◆ From: meow.cc.ntu.edu. +加大 shared-memory: +如果您是用 FreeBSD, 請在 /boot/loader.conf 裡面加入 +kern.ipc.shmmax=104857600 +kern.ipc.shmall=25600 +這兩個數值可視須要調整, +在重新開機後會生效. 作者 DavidYu (軱~~~~~~~~~~) 看板 PttSrc 標題 sendmail.cf要改的地方(參考用) @@ -123,24 +58,3 @@ Mbbsmail, P=/home/bbs/bin/bbsmail, F=lsSDFMhPu, U=bbs, S=10,R=20/40, -- ※ 發信站: 批踢踢實業坊(ptt.twbbs.org) ◆ From: oio.m6.ntu.edu.t - - 作者 DavidYu (鴰~~~~~~~~~~~~~~) 看板 PttSrc - 標題 [anno] tunepasswd - 時間 Sat Jul 29 09:18:06 2000 -─────────────────────────────────────── - -新增了一個 tunepasswd 的程式 - -如果你在 .PASSWD 建立後又改過了 MAX_USERS - -你必須要執行 tunepasswd 一次來修改 .PASSWD 檔的大小 - -執行的時候不可以有任何BBS的程式在執行 - -shared memory 也應該要清除, 否則會有不預期的錯誤發生 - -執行 tunepasswd 會產生一個原來的備份檔 .PASSWD~ - --- -※ 發信站: 批踢踢實業坊(ptt.twbbs.org) -◆ From: oio.m6.ntu.edu.t diff --git a/pttbbs/docs/FAQ.old b/pttbbs/docs/FAQ.old new file mode 100755 index 00000000..bc2904a0 --- /dev/null +++ b/pttbbs/docs/FAQ.old @@ -0,0 +1,146 @@ + 作者 DavidYu (^^Y) 看板 PttSrc + 標題 Re: 安裝完連線時..... + 時間 Thu May 18 15:08:04 2000 +─────────────────────────────────────── + +※ 引述《JamesCheng (網球比排球好玩啦!)》之銘言: +: 我在安裝完之後 用root執行 mbbsd 23 +: 連線看出現 +: Escape character is '^]'. +: 【物治樂園】◎ 物治第二站 ◎(pt.mc.ntu.edu.tw) +: 調幅(140.112.122.44) 系統負荷 0.00 0.01 0.00 +: Connection closed by foreign host. +: 然後系統出現下列訊息 +: [shmget error] key = 8ab +: errno = 12: Cannot allocate memory +: 這是何原因呢? +shared memory要加大 +在kernel config file中加一行 +options SHMMAXPGS=4100 +重新make kernel + +-- +※ 發信站: 批踢踢實業坊(ptt.twbbs.org) +◆ From: oio.m6.ntu.edu.t + + 作者 DavidYu (Do it YOURSELF!) 看板 PttSrc + 標題 Re: 請問一下... + 時間 Sat May 27 18:41:39 2000 +─────────────────────────────────────── + +※ 引述《clifflu ( 煩呀煩呀煩~~~)》之銘言: +: ※ 引述《hscat (復站了!)》之銘言: +: : 不過我有一個小小的問題 +: : 能不能指導一下...想要開新的版應該從哪邊開呢? +: 主選單下的 (0)Admin ?? +: : 因為我實在找不到怎麼開新看板...:~~~~... +不不不.. +開板要從分類看板的地方開,這部份有點小小的複雜, +和以往的版本不一樣,我來簡單說明一下: + +首先介紹看板. +看板有兩種, 一般看板和群組看板. 如果用檔案系統的架構來看的話, +一般看板如同 file, 而群組看板就是 directory +(在所有看板列表的地方只會出現一般看板) + +一個看板有UID及GID這兩個屬性. UID是unique的,從1開始分配,系統在開板時會 +菾佧llocate一個. 而GID是指定這個看板在哪一個群組看板之下(看板是樹狀架構的) +所以如果有一個群組看板的UID是x, 則GID為x的看板都會擺在該群組看板之下 +而如果看板GID為0(保留的UID)的話,該看板就會出現在一開始從主選單進CLASS的 +那個地方 + +至於開板的方法. +首先從CLASS進到你想要開新板的類別下,然後按大B設定 +如此新開的板就會自動assign GID 到那個類別下 + +如果要般動一個已經開好的板到其他類別的話 +先找出那個類別(群組看板)的UID, 按大E可以看到 +然後把要搬動的板的GID設成那個UID及可 + +值得注意的是, 如果把某個使用者設成某群組看板的板主的話 +則當他從CLASS進到那個群組時會獲得小組長的權限(可以開板,設定看板等等) +要特別小心 + +比較麻煩的地方: +一個新開的群組裡面並沒有任何看板,所以無法從選單進去裡面開板 +這時候就需要在可開板的地方先開個板,然後再把那個板的GID設過去即可 +(這也是為什麼需要一個initial的.BOARDS的原因 :p) + +-- +※ 發信站: 批踢踢實業坊(ptt.twbbs.org) +◆ From: meow.cc.ntu.edu. + + 作者 DavidYu (軱~~~~~~~~~~) 看板 PttSrc + 標題 sendmail.cf要改的地方(參考用) + 時間 Sun Jul 9 09:39:53 2000 +─────────────────────────────────────── + +有顏色的是要加上去的 +要注意,tab和space不能混用 + +###################################### +### Ruleset 0 -- Parse Address ### +###################################### +S0 + +R$* $: $>Parse0 $1 initial parsing +R<@> $#local $: <@> special case error msgs +R$* $: $>98 $1 handle local hacks +R$+.bbs < @ $=w .> $#bbsmail $: $1 bbs mail gateway +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +R$* $: $>Parse1 $1 final parsing + +...... + +# handle locally delivered names +R$+.bbs $#bbsmail $:$1 bbs mail gateway +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +R$=L $#local $: @ $1 special local names +R$+ $#local $: $1 regular local names + +########################################################################### +### Ruleset 5 -- special rewriting after aliases have been expanded ### +########################################################################### + +...... + +################################################## +### Local and Program Mailer specification ### +################################################## + +##### @(#)local.m4 8.30 (Berkeley) 6/30/1998 ##### + +Mlocal, P=/usr/libexec/mail.local, F=lsDFMAw5:/|@qSXfmnz9P, S=10/30, R= + T=DNS/RFC822/X-Unix, + A=mail.local -l +Mprog, P=/bin/sh, F=lsDFMoqeu9, S=10/30, R=20/40, D=$z:/, + T=X-Unix, + A=sh -c $u +Mbbsmail, P=/home/bbs/bin/bbsmail, F=lsSDFMhPu, U=bbs, S=10,R=20/40, +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + A=bbsmail $u +^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +-- +※ 發信站: 批踢踢實業坊(ptt.twbbs.org) +◆ From: oio.m6.ntu.edu.t + + 作者 DavidYu (鴰~~~~~~~~~~~~~~) 看板 PttSrc + 標題 [anno] tunepasswd + 時間 Sat Jul 29 09:18:06 2000 +─────────────────────────────────────── + +新增了一個 tunepasswd 的程式 + +如果你在 .PASSWD 建立後又改過了 MAX_USERS + +你必須要執行 tunepasswd 一次來修改 .PASSWD 檔的大小 + +執行的時候不可以有任何BBS的程式在執行 + +shared memory 也應該要清除, 否則會有不預期的錯誤發生 + +執行 tunepasswd 會產生一個原來的備份檔 .PASSWD~ + +-- +※ 發信站: 批踢踢實業坊(ptt.twbbs.org) +◆ From: oio.m6.ntu.edu.t diff --git a/pttbbs/docs/INSTALL b/pttbbs/docs/INSTALL index 5bd484d5..2cff5971 100644 --- a/pttbbs/docs/INSTALL +++ b/pttbbs/docs/INSTALL @@ -21,6 +21,16 @@ 然後切換成 bbsadm 的身份 7. 取得解開 pttbbs-VERSION.tar.gz (任何目錄下皆可). + + 或透過 cvs來取得 (強烈建議) + touch ~/.cvspass + cvs -d :pserver:cvs@ptt2.csie.ntu.edu.tw:/var/db/cvsroot login + (不用打密碼, 直接按 Enter過去) + cvs -d :pserver:cvs@ptt2.csie.ntu.edu.tw:/var/db/cvsroot checkout pttbbs + 使用此法的朋友, 將來您可以直接在 pttbbs/ 下用 + cvs update + 更新到最新版本的 pttbbs + 8. 執行 cd pttbbs 9. 如果之前沒有設定過 pttbbs.conf 的話, 請 cp sample/pttbbs.conf pttbbs.conf 10. 修改 pttbbs.conf @@ -32,9 +42,10 @@ 假如一切都很順利的話,這樣子大概就安裝完了 接下來是啟動 bbs 的部份 -13. 執行 bin/uhash_loader (*註1) +13. 執行 bin/uhash_loader (*註1, *註2) 14. 用 root 執行 bin/mbbsd 23 (註2) +15. 新功能請參考 ADVANCE telnet localhost 23 看看 new一個帳號叫SYSOP,然後logout再login, 這樣子就會擁有站長權限囉~ 再new一個帳號叫 guest, 這樣子別人就可以用 guest 參觀你的站了 @@ -44,6 +55,11 @@ new 1. 這個程式是在 initial shared memory 用的, 只有開機後第一次執行, 或是 你手動清除 shm 後才需要執行 -2. bin/mbbsd 23 是指定要 bind 23 port, 依照 UNIX 規定, 1024 以下的 port +2. 如果您跑了 uhash_loader 並沒有看到 + total XXXXX names loaded. + 而是看到其他的錯誤訊息, 可能是您作業系統 shared-memory 上限不足, + 請參考 FAQ第一部份加大 shared-memory. + +3. bin/mbbsd 23 是指定要 bind 23 port, 依照 UNIX 規定, 1024 以下的 port 須要有 root 權限, 所以如果要 bind 23 port 的話就要用 root 去執行, 3000 port 則不需要 diff --git a/pttbbs/docs/INSTALL.old b/pttbbs/docs/INSTALL.old new file mode 100755 index 00000000..5bd484d5 --- /dev/null +++ b/pttbbs/docs/INSTALL.old @@ -0,0 +1,49 @@ +底下是快速安裝的方法 + +== + +先取得 root 權限 + +1. 打 vipw, 加入底下兩行 + + bbs:*:9999:99::0:0:Ptt BBS:/home/bbs:/home/bbs/bin/bbsrf + bbsadm::9999:99::0:0:Ptt BBS:/home/bbs:/bin/csh + +2. 執行 passwd bbsadm 設 bbsadm的密碼 +3. 在 /etc/group 中加入一行 + + bbs:*:99: + +4. 執行 mkdir /home/bbs +5. 執行 chown bbs.bbs /home/bbs +6. 執行 chmod 700 /home/bbs + +然後切換成 bbsadm 的身份 + +7. 取得解開 pttbbs-VERSION.tar.gz (任何目錄下皆可). +8. 執行 cd pttbbs +9. 如果之前沒有設定過 pttbbs.conf 的話, 請 cp sample/pttbbs.conf pttbbs.conf +10. 修改 pttbbs.conf +11. 執行 make OSTYPE=FreeBSD BBSHOME=/home/bbs all install + (Linux使用者請把 "FreeBSD" 改成 "linux") +12. 如果是新架起來的站, 請執行 cd sample; make install +12. 執行 cd /home/bbs; bin/initbbs + +假如一切都很順利的話,這樣子大概就安裝完了 +接下來是啟動 bbs 的部份 + +13. 執行 bin/uhash_loader (*註1) +14. 用 root 執行 bin/mbbsd 23 (註2) + +telnet localhost 23 看看 +new一個帳號叫SYSOP,然後logout再login, 這樣子就會擁有站長權限囉~ +再new一個帳號叫 guest, 這樣子別人就可以用 guest 參觀你的站了 +開板,開群組,以及搬動群組的方法請看 PttSrc 板的文摘 + +註: +1. 這個程式是在 initial shared memory 用的, 只有開機後第一次執行, 或是 + 你手動清除 shm 後才需要執行 + +2. bin/mbbsd 23 是指定要 bind 23 port, 依照 UNIX 規定, 1024 以下的 port + 須要有 root 權限, 所以如果要 bind 23 port 的話就要用 root 去執行, + 3000 port 則不需要 -- cgit v1.2.3 From c1fde53aeacb537f2cefdc85df3d65b39f530cb9 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sat, 26 Oct 2002 19:04:31 +0000 Subject: Makefile of mbbsd/ git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@547 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/docs/ADVANCE | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/pttbbs/docs/ADVANCE b/pttbbs/docs/ADVANCE index dd1a2e28..118b8aae 100644 --- a/pttbbs/docs/ADVANCE +++ b/pttbbs/docs/ADVANCE @@ -37,3 +37,16 @@ shmctl 將 shared-memory中 utmp 不正確的 record 清掉. 建議至少每小時跑一次. 另外可以用這個來外部設定 idle 多久後就踢人. + +Makefile of mbbsd/ +------------------ +1.make all + 自動加上 -O 的最佳化參數 +2.make DEBUG=1 + 一般用來 debug的情況下會用到, + 會開啟一些 DEBUG的程式碼, + gcc不用 -O 而改加上 -g , + menu title 顯示目前的 pid, + 以方便用 gdb來 attach. +3.make NO_FORK=1 + 這通常都是很特別的情況才會用到. \ No newline at end of file -- cgit v1.2.3 From 24bedd5b2633024c2fc63051696f2eeef7527448 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Tue, 29 Oct 2002 12:53:42 +0000 Subject: disable NO_OUT_MAIL before writing to jobspool git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@548 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/mail.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/pttbbs/mbbsd/mail.c b/pttbbs/mbbsd/mail.c index 786d3151..8fafa0c1 100644 --- a/pttbbs/mbbsd/mail.c +++ b/pttbbs/mbbsd/mail.c @@ -1,4 +1,4 @@ -/* $Id: mail.c,v 1.22 2002/07/22 19:02:00 in2 Exp $ */ +/* $Id: mail.c,v 1.23 2002/10/29 12:53:42 in2 Exp $ */ #include "bbs.h" char currmaildir[32]; static char msg_cc[] = "\033[32m[群組名單]\033[m\n"; @@ -1319,6 +1319,14 @@ mail_waterball(int ent, fileheader_t * fhdr, char *direct) } if (invalidaddr(address)) return -2; + if( strstr(address, ".bbs") && HAS_PERM(PERM_NOOUTMAIL) ){ + move(b_lines - 4, 0); + outs("\n您必須要打開接受站外信, 水球整理系統才能寄入結果\n" + "請麻煩到【郵件選單】按大寫 O改成接受站外信 (在右上角)\n" + "再重新執行本功\能 :)\n"); + vmsg("請打開站外信, 再重新執行本功\能"); + return FULLUPDATE; + } //snprintf(fname, sizeof(fname), "%d\n", cmode); move(b_lines - 4, 0); -- cgit v1.2.3 From 111f0f42ed9932b5bbee2d2f36867bbd4f43bcab Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sat, 2 Nov 2002 11:02:32 +0000 Subject: strip_ansi title git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@549 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/bbsmail.c | 53 +++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 43 insertions(+), 10 deletions(-) diff --git a/pttbbs/util/bbsmail.c b/pttbbs/util/bbsmail.c index 54e4dc47..7c671418 100644 --- a/pttbbs/util/bbsmail.c +++ b/pttbbs/util/bbsmail.c @@ -1,4 +1,4 @@ -/* $Id: bbsmail.c,v 1.4 2002/07/01 08:03:55 in2 Exp $ */ +/* $Id: bbsmail.c,v 1.5 2002/11/02 11:02:32 in2 Exp $ */ #define _BBS_UTIL_C_ #include "bbs.h" @@ -11,6 +11,40 @@ extern char *notitle[], *nofrom[], *nocont[]; extern userec_t xuser; +int +strip_ansi(char *buf, char *str, int mode) +{ + register int ansi, count = 0; + + for (ansi = 0; *str /* && *str != '\n' */ ; str++) { + if (*str == 27) { + if (mode) { + if (buf) + *buf++ = *str; + count++; + } + ansi = 1; + } else if (ansi && strchr("[;1234567890mfHABCDnsuJKc=n", *str)) { + if ((mode == NO_RELOAD && !strchr("c=n", *str)) || + (mode == ONLY_COLOR && strchr("[;1234567890m", *str))) { + if (buf) + *buf++ = *str; + count++; + } + if (strchr("mHn ", *str)) + ansi = 0; + } else { + ansi = 0; + if (buf) + *buf++ = *str; + count++; + } + } + if (buf) + *buf = '\0'; + return count; +} + int mailalertuid(int tuid) { userinfo_t *uentp=NULL; @@ -46,7 +80,7 @@ mail2bbs(userid) { int uid; fileheader_t mymail; - char genbuf[256], title[80], sender[80], filename[80], *ip, *ptr; + char genbuf[512], title[512], sender[512], filename[512], *ip, *ptr; time_t tmp_time; struct stat st; FILE *fout; @@ -107,13 +141,13 @@ mail2bbs(userid) strtok(genbuf, " \t\n\r"); ptr= strtok(NULL, " \t\n\r"); if(ptr) - strcpy(sender, ptr); + strlcpy(sender, ptr, sizeof(sender)); } continue; } if (!strncmp(genbuf, "Subject: ", 9)) { - strcpy(title, genbuf + 9); + strlcpy(title, genbuf + 9, sizeof(title)); continue; } if (genbuf[0] == '\n') @@ -186,13 +220,13 @@ mail2bbs(userid) mailog(genbuf); /* append the record to the MAIL control file */ - - strcpy(mymail.title, title); + strip_ansi(title, title, 0); + strlcpy(mymail.title, title, sizeof(mymail.title)); if (strtok(sender, " .@\t\n\r")) strcat(sender, "."); sender[IDLEN + 1] = '\0'; - strcpy(mymail.owner, sender); + strlcpy(mymail.owner, sender, sizeof(mymail.owner)); sprintf(genbuf, BBSHOME "/home/%c/%s/.DIR", userid[0], userid); mailalertuid(uid); @@ -203,7 +237,7 @@ mail2bbs(userid) int main(int argc, char* argv[]) { - char receiver[256]; + char receiver[512]; chdir(BBSHOME); /* argv[1] is userid in bbs */ @@ -216,8 +250,7 @@ main(int argc, char* argv[]) (void) setgid(BBSGID); (void) setuid(BBSUID); - if(passwd_mmap()) exit(-1); - strcpy(receiver, argv[1]); + strlcpy(receiver, argv[1], sizeof(receiver)); strtok(receiver,"."); if (mail2bbs(receiver)) -- cgit v1.2.3 From cd5f14736cc70fa6eb57085f2532955d6f20af50 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sat, 2 Nov 2002 11:02:44 +0000 Subject: warning free git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@550 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/BM_money.c | 3 ++- pttbbs/util/birth.c | 1 + pttbbs/util/horoscope.c | 3 ++- pttbbs/util/indexuser.c | 8 +++++--- pttbbs/util/jungo.c | 3 ++- pttbbs/util/openticket.c | 3 ++- pttbbs/util/reaper.c | 3 ++- pttbbs/util/toplazyBBM.c | 3 ++- pttbbs/util/toplazyBM.c | 3 ++- pttbbs/util/topusr.c | 4 ++-- pttbbs/util/userlist.c | 4 ++-- pttbbs/util/util_passwd.c | 4 ++-- pttbbs/util/util_record.c | 3 ++- pttbbs/util/yearsold.c | 4 ++-- 14 files changed, 30 insertions(+), 19 deletions(-) diff --git a/pttbbs/util/BM_money.c b/pttbbs/util/BM_money.c index db7b1538..e2ed960f 100644 --- a/pttbbs/util/BM_money.c +++ b/pttbbs/util/BM_money.c @@ -1,7 +1,8 @@ -/* $Id: BM_money.c,v 1.5 2002/06/19 13:38:01 lwms Exp $ */ +/* $Id: BM_money.c,v 1.6 2002/11/02 11:02:44 in2 Exp $ */ /* 給板主錢的程式 */ +#define _UTIL_C_ #include "bbs.h" #define FUNCTION (2100 - c*5) diff --git a/pttbbs/util/birth.c b/pttbbs/util/birth.c index 5c13c54f..23272d6f 100644 --- a/pttbbs/util/birth.c +++ b/pttbbs/util/birth.c @@ -1,5 +1,6 @@ /* 壽星程式 96 10/11 */ +#define _UTIL_C_ #include "bbs.h" #define OUTFILE BBSHOME "/etc/birth.today" diff --git a/pttbbs/util/horoscope.c b/pttbbs/util/horoscope.c index f1183591..53d69e31 100644 --- a/pttbbs/util/horoscope.c +++ b/pttbbs/util/horoscope.c @@ -1,4 +1,5 @@ -/* $Id: horoscope.c,v 1.2 2002/06/06 21:34:14 in2 Exp $ */ +/* $Id: horoscope.c,v 1.3 2002/11/02 11:02:44 in2 Exp $ */ +#define _UTIL_C_ #include "bbs.h" struct userec_t cuser; diff --git a/pttbbs/util/indexuser.c b/pttbbs/util/indexuser.c index 3668269a..8b39fdd0 100644 --- a/pttbbs/util/indexuser.c +++ b/pttbbs/util/indexuser.c @@ -1,3 +1,5 @@ +/* $Id: indexuser.c,v 1.5 2002/11/02 11:02:44 in2 Exp $ */ +#define _UTIL_C_ #include "bbs.h" #define INDEXPATH BBSHOME"/index" @@ -36,17 +38,17 @@ int main() if(u.realname[0]) { sprintf(buf,INDEXPATH"/realname/%X",string_hash(u.realname)); - append_record(buf, &j, sizeof(j)); + append_record(buf, (fileheader_t*)&j, sizeof(j)); } if(u.email[0]) { sprintf(buf,INDEXPATH"/email/%X",string_hash(u.email)); - append_record(buf, &j, sizeof(j)); + append_record(buf, (fileheader_t*)&j, sizeof(j)); } if(u.ident[0]) { sprintf(buf,INDEXPATH"/ident/%X",string_hash(u.ident)); - append_record(buf, &j, sizeof(j)); + append_record(buf, (fileheader_t*)&j, sizeof(j)); } } return 0; diff --git a/pttbbs/util/jungo.c b/pttbbs/util/jungo.c index 6221023b..4c7c2d94 100644 --- a/pttbbs/util/jungo.c +++ b/pttbbs/util/jungo.c @@ -1,4 +1,5 @@ -/* $Id: jungo.c,v 1.5 2002/06/19 13:38:01 lwms Exp $ */ +/* $Id: jungo.c,v 1.6 2002/11/02 11:02:44 in2 Exp $ */ +#define _UTIL_C_ #include "bbs.h" #define OUTFILE BBSHOME "/etc/toplazyBBM" diff --git a/pttbbs/util/openticket.c b/pttbbs/util/openticket.c index 643c55fb..55e04b0e 100644 --- a/pttbbs/util/openticket.c +++ b/pttbbs/util/openticket.c @@ -1,5 +1,6 @@ -/* $Id: openticket.c,v 1.8 2002/06/16 22:21:12 ptt Exp $ */ +/* $Id: openticket.c,v 1.9 2002/11/02 11:02:44 in2 Exp $ */ /* 開獎的 utility */ +#define _UTIL_C_ #include "bbs.h" static char *betname[8] = {"Ptt", "Jaky", "Action", "Heat", diff --git a/pttbbs/util/reaper.c b/pttbbs/util/reaper.c index d605bb70..9ed1b11f 100644 --- a/pttbbs/util/reaper.c +++ b/pttbbs/util/reaper.c @@ -1,4 +1,5 @@ -/* $Id: reaper.c,v 1.2 2002/06/06 21:34:14 in2 Exp $ */ +/* $Id: reaper.c,v 1.3 2002/11/02 11:02:44 in2 Exp $ */ +#define _UTIL_C_ #include "bbs.h" time_t now; diff --git a/pttbbs/util/toplazyBBM.c b/pttbbs/util/toplazyBBM.c index 076e6cc0..1b12eab9 100644 --- a/pttbbs/util/toplazyBBM.c +++ b/pttbbs/util/toplazyBBM.c @@ -1,4 +1,5 @@ -/* $Id: toplazyBBM.c,v 1.5 2002/06/19 13:38:01 lwms Exp $ */ +/* $Id: toplazyBBM.c,v 1.6 2002/11/02 11:02:44 in2 Exp $ */ +#define _UTIL_C_ #include "bbs.h" #define OUTFILE BBSHOME "/etc/toplazyBBM" diff --git a/pttbbs/util/toplazyBM.c b/pttbbs/util/toplazyBM.c index f54d7770..fc656817 100644 --- a/pttbbs/util/toplazyBM.c +++ b/pttbbs/util/toplazyBM.c @@ -1,4 +1,5 @@ -/* $Id: toplazyBM.c,v 1.16 2002/06/30 04:14:46 ptt Exp $ */ +/* $Id: toplazyBM.c,v 1.17 2002/11/02 11:02:44 in2 Exp $ */ +#define _UTIL_C_ #include "bbs.h" #define OUTFILE BBSHOME "/etc/toplazyBM" #define FIREFILE BBSHOME "/etc/firelazyBM" diff --git a/pttbbs/util/topusr.c b/pttbbs/util/topusr.c index 0f64777d..3b90a7e2 100644 --- a/pttbbs/util/topusr.c +++ b/pttbbs/util/topusr.c @@ -1,6 +1,6 @@ -/* $Id: topusr.c,v 1.2 2002/06/06 21:34:14 in2 Exp $ */ +/* $Id: topusr.c,v 1.3 2002/11/02 11:02:44 in2 Exp $ */ /* 使用者 上站記錄/文章篇數 排行榜 */ - +#define _UTIL_C_ #include "bbs.h" #define REAL_INFO diff --git a/pttbbs/util/userlist.c b/pttbbs/util/userlist.c index c8d53389..794a3daf 100644 --- a/pttbbs/util/userlist.c +++ b/pttbbs/util/userlist.c @@ -33,9 +33,9 @@ int main(int argc, char **argv) { f = &SHM->uinfo[i]; printf( - "%4d(%d) p[%d] i[%d] u[%s] n[%s] f[%s] m[%d] d[%d] t[%ld]\n", + "%4d(%d) p[%d] i[%d] u[%s] n[%s] f[%s] m[%d] t[%ld]\n", ++counter, i, f->pager, f->invisible, f->userid, - f->username, f->from, f->mode, f->mind, f->lastact); + f->username, f->from, f->mode, f->lastact); } printf("\nTotal: %d(%d)\n", counter, SHM->number); if(counter != SHM->number) { diff --git a/pttbbs/util/util_passwd.c b/pttbbs/util/util_passwd.c index c9fe4eac..17961d87 100644 --- a/pttbbs/util/util_passwd.c +++ b/pttbbs/util/util_passwd.c @@ -1,4 +1,4 @@ -/* $Id: util_passwd.c,v 1.2 2002/03/09 17:44:30 in2 Exp $ */ +/* $Id: util_passwd.c,v 1.3 2002/11/02 11:02:44 in2 Exp $ */ #include <stdio.h> #include <string.h> #include <fcntl.h> @@ -36,7 +36,7 @@ static userec_t *passwd_image = NULL; static int passwd_image_size; static int semid = -1; -int passwd_mmap() { +int passwd_mmap(void) { int fd; if(passwd_image!=NULL) return 0; diff --git a/pttbbs/util/util_record.c b/pttbbs/util/util_record.c index 8f1c9d02..98b6e43f 100644 --- a/pttbbs/util/util_record.c +++ b/pttbbs/util/util_record.c @@ -1,5 +1,6 @@ -/* $Id: util_record.c,v 1.2 2002/06/22 18:21:25 ptt Exp $ */ +/* $Id: util_record.c,v 1.3 2002/11/02 11:02:44 in2 Exp $ */ #include <stdio.h> +#include <stdlib.h> #include <errno.h> #include <string.h> #include <unistd.h> diff --git a/pttbbs/util/yearsold.c b/pttbbs/util/yearsold.c index e0aa5142..93cb4a1b 100644 --- a/pttbbs/util/yearsold.c +++ b/pttbbs/util/yearsold.c @@ -1,6 +1,6 @@ -/* $Id: yearsold.c,v 1.3 2002/08/29 18:31:44 kcwu Exp $ */ +/* $Id: yearsold.c,v 1.4 2002/11/02 11:02:44 in2 Exp $ */ /* 站上年齡統計 */ - +#define _UTIL_C_ #include "bbs.h" #define MAX_LINE 16 -- cgit v1.2.3 From fda321941af663cd65191c20db9637cec1cf8e3d Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sat, 2 Nov 2002 11:02:56 +0000 Subject: for util/ git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@551 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/include/bbs.h | 4 ++++ pttbbs/include/util.h | 7 +++++++ 2 files changed, 11 insertions(+) create mode 100644 pttbbs/include/util.h diff --git a/pttbbs/include/bbs.h b/pttbbs/include/bbs.h index 09ce1982..9163656b 100644 --- a/pttbbs/include/bbs.h +++ b/pttbbs/include/bbs.h @@ -42,6 +42,10 @@ #include "proto.h" #include "gomo.h" +#ifdef _UTIL_C_ + #include "util.h" +#endif + #ifndef INCLUDE_VAR_H #include "var.h" #endif diff --git a/pttbbs/include/util.h b/pttbbs/include/util.h new file mode 100644 index 00000000..d19944cc --- /dev/null +++ b/pttbbs/include/util.h @@ -0,0 +1,7 @@ +#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 *)); + +#endif // INCLUDE_UTIL_H -- cgit v1.2.3 From c469cbc91d6fb5edc887a3bb3462a24e07daa5dd Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sat, 2 Nov 2002 11:15:27 +0000 Subject: fix bug git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@552 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/bbsmail.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pttbbs/util/bbsmail.c b/pttbbs/util/bbsmail.c index 7c671418..0663a5c8 100644 --- a/pttbbs/util/bbsmail.c +++ b/pttbbs/util/bbsmail.c @@ -1,6 +1,6 @@ -/* $Id: bbsmail.c,v 1.5 2002/11/02 11:02:32 in2 Exp $ */ +/* $Id: bbsmail.c,v 1.6 2002/11/02 11:15:27 in2 Exp $ */ -#define _BBS_UTIL_C_ +#define _UTIL_C_ #include "bbs.h" #define LOG_FILE (BBSHOME "/etc/mailog") @@ -239,6 +239,8 @@ main(int argc, char* argv[]) { char receiver[512]; + if( passwd_mmap() ) + return 0; chdir(BBSHOME); /* argv[1] is userid in bbs */ -- cgit v1.2.3 From 7876508e31f8a22e86cdacfc79d636b9b2043890 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sun, 3 Nov 2002 07:48:51 +0000 Subject: (utmpfix)clean lowerbound git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@553 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/shmctl.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/pttbbs/util/shmctl.c b/pttbbs/util/shmctl.c index 72d9b301..4d9a96ee 100644 --- a/pttbbs/util/shmctl.c +++ b/pttbbs/util/shmctl.c @@ -1,4 +1,4 @@ -/* $Id: shmctl.c,v 1.26 2002/08/07 03:48:52 in2 Exp $ */ +/* $Id: shmctl.c,v 1.27 2002/11/03 07:48:51 in2 Exp $ */ #include "bbs.h" extern SHM_t *SHM; @@ -42,11 +42,11 @@ void purge_utmp(userinfo_t *uentp) int utmpfix(int argc, char **argv) { - int i, fast = 0; + int i, fast = 0, lowerbound = 100, nownum = SHM->UTMPnumber; time_t now, timeout = -1; char *clean, buf[1024], ch; - while( (ch = getopt(argc, argv, "nt:")) != -1 ) + while( (ch = getopt(argc, argv, "nt:l:")) != -1 ) switch( ch ){ case 'n': fast = 1; @@ -54,6 +54,9 @@ int utmpfix(int argc, char **argv) case 't': timeout = atoi(optarg); break; + case 'l': + lowerbound = atoi(optarg); + break; default: printf("usage:\tshmctl\tutmpfix [-n] [-t timeout]\n"); return 1; @@ -67,6 +70,7 @@ int utmpfix(int argc, char **argv) puts("utmpshm is busy...."); sleep(1); } + printf("starting scaning... %s \n", (fast ? "(fast mode)" : "")); SHM->UTMPbusystate = 1; for( i = 0 ; i < USHM_SIZE ; ++i ) @@ -83,7 +87,8 @@ int utmpfix(int argc, char **argv) clean = "user not exist"; } #ifdef DOTIMEOUT - else if( now - SHM->uinfo[i].lastact > + else if( nownum > lowerbound && + now - SHM->uinfo[i].lastact > (timeout == -1 ? IDLE_TIMEOUT : timeout) ){ sprintf(buf, "timeout(%s", ctime(&SHM->uinfo[i].lastact)); @@ -92,6 +97,7 @@ int utmpfix(int argc, char **argv) clean = buf; kill(SHM->uinfo[i].pid, SIGHUP); printf("%s\n", buf); + --nownum; continue; } #endif @@ -101,6 +107,7 @@ int utmpfix(int argc, char **argv) printf("clean %06d(%s), userid: %s\n", i, clean, SHM->uinfo[i].userid); memset(&SHM->uinfo[i], 0, sizeof(userinfo_t)); + --nownum; } } SHM->UTMPbusystate = 0; -- cgit v1.2.3 From f3d41ebc2add98a2ee478a3a51df60a7f3eb4c2b Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sun, 3 Nov 2002 15:19:36 +0000 Subject: (utmpfix)timeout by idle time git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@554 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/shmctl.c | 92 ++++++++++++++++++++++++++++++++-------------------- 1 file changed, 57 insertions(+), 35 deletions(-) diff --git a/pttbbs/util/shmctl.c b/pttbbs/util/shmctl.c index 4d9a96ee..e658c304 100644 --- a/pttbbs/util/shmctl.c +++ b/pttbbs/util/shmctl.c @@ -1,4 +1,4 @@ -/* $Id: shmctl.c,v 1.27 2002/11/03 07:48:51 in2 Exp $ */ +/* $Id: shmctl.c,v 1.28 2002/11/03 15:19:36 in2 Exp $ */ #include "bbs.h" extern SHM_t *SHM; @@ -40,11 +40,23 @@ void purge_utmp(userinfo_t *uentp) //memset(uentp, 0, sizeof(userinfo_t)); } +typedef struct { + int index; + int idle; +} IDLE_t; + +int sfIDLE(const void *a, const void *b) +{ + return ((IDLE_t *)b)->idle - ((IDLE_t *)a)->idle; +} + int utmpfix(int argc, char **argv) { int i, fast = 0, lowerbound = 100, nownum = SHM->UTMPnumber; + int which, nactive = 0; time_t now, timeout = -1; char *clean, buf[1024], ch; + IDLE_t idle[USHM_SIZE]; while( (ch = getopt(argc, argv, "nt:l:")) != -1 ) switch( ch ){ @@ -62,7 +74,6 @@ int utmpfix(int argc, char **argv) return 1; } - time(&now); for( i = 0 ; i < 5 ; ++i ) if( !SHM->UTMPbusystate ) break; @@ -71,45 +82,56 @@ int utmpfix(int argc, char **argv) sleep(1); } - printf("starting scaning... %s \n", (fast ? "(fast mode)" : "")); SHM->UTMPbusystate = 1; - for( i = 0 ; i < USHM_SIZE ; ++i ) - if( SHM->uinfo[i].pid ){ - clean = NULL; - if( !isalpha(SHM->uinfo[i].userid[0]) ) - clean = "userid error"; - else if( kill(SHM->uinfo[i].pid, 0) < 0 ){ - clean = "process error"; - purge_utmp(&SHM->uinfo[i]); + printf("starting scaning... %s \n", (fast ? "(fast mode)" : "")); + if( !fast ){ + time(&now); + for( i = 0, nactive = 0 ; i < USHM_SIZE ; ++i ) + if( SHM->uinfo[i].pid ){ + idle[nactive].index = i; + idle[nactive].idle = now - SHM->uinfo[i].lastact; + ++nactive; } - else if( !fast ){ - if( searchuser(SHM->uinfo[i].userid) == 0 ){ - clean = "user not exist"; - } + qsort(idle, nactive, sizeof(IDLE_t), sfIDLE); + } + + for( i = 0 ; i < nactive ; ++i ){ + which = idle[i].index; + clean = NULL; + if( !isalpha(SHM->uinfo[which].userid[0]) ) + clean = "userid error"; + else if( kill(SHM->uinfo[which].pid, 0) < 0 ){ + clean = "process error"; + purge_utmp(&SHM->uinfo[which]); + } + else if( !fast ){ + if( searchuser(SHM->uinfo[which].userid) == 0 ){ + clean = "user not exist"; + } #ifdef DOTIMEOUT - else if( nownum > lowerbound && - now - SHM->uinfo[i].lastact > - (timeout == -1 ? IDLE_TIMEOUT : timeout) ){ - sprintf(buf, "timeout(%s", - ctime(&SHM->uinfo[i].lastact)); - buf[strlen(buf) - 1] = 0; - strcat(buf, ")"); - clean = buf; - kill(SHM->uinfo[i].pid, SIGHUP); - printf("%s\n", buf); - --nownum; - continue; - } -#endif - } - - if( clean ){ - printf("clean %06d(%s), userid: %s\n", - i, clean, SHM->uinfo[i].userid); - memset(&SHM->uinfo[i], 0, sizeof(userinfo_t)); + else if( nownum > lowerbound && + idle[i].idle > + (timeout == -1 ? IDLE_TIMEOUT : timeout) ){ + sprintf(buf, "timeout(%s", + ctime(&SHM->uinfo[which].lastact)); + buf[strlen(buf) - 1] = 0; + strcat(buf, ")"); + clean = buf; + kill(SHM->uinfo[which].pid, SIGHUP); + printf("%s\n", buf); --nownum; + continue; } +#endif + } + + if( clean ){ + printf("clean %06d(%s), userid: %s\n", + i, clean, SHM->uinfo[which].userid); + memset(&SHM->uinfo[which], 0, sizeof(userinfo_t)); + --nownum; } + } SHM->UTMPbusystate = 0; return 0; } -- cgit v1.2.3 From 269a290c6b68f3e81312daa489c568cf3991bef4 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Mon, 4 Nov 2002 08:46:50 +0000 Subject: rebuildaloha git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@555 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/Makefile | 4 ++-- pttbbs/util/rebuildaloha.pl | Bin 0 -> 639 bytes 2 files changed, 2 insertions(+), 2 deletions(-) create mode 100644 pttbbs/util/rebuildaloha.pl diff --git a/pttbbs/util/Makefile b/pttbbs/util/Makefile index 5c7184bd..e3b2a783 100644 --- a/pttbbs/util/Makefile +++ b/pttbbs/util/Makefile @@ -1,4 +1,4 @@ -# $Id: Makefile,v 1.20 2002/08/20 06:29:30 in2 Exp $ +# $Id: Makefile,v 1.21 2002/11/04 08:46:50 in2 Exp $ BBSHOME?=$(HOME) OSTYPE!=uname @@ -35,7 +35,7 @@ CPROGS= bbsmail BM_money post account birth deluserfile expire mandex\ PROGS= $(CPROGS) BM_money.sh backpasswd.sh mailog.sh opendice.sh\ openticket.sh stock.sh topsong.sh weather.sh stock.perl weather.perl\ toplazyBM.sh toplazyBBM.sh dailybackup.pl tarqueue.pl waterball.pl \ - filtermail.pl getbackup.pl udnnews.pl + filtermail.pl getbackup.pl udnnews.pl rebuildaloha.pl all: $(PROGS) diff --git a/pttbbs/util/rebuildaloha.pl b/pttbbs/util/rebuildaloha.pl new file mode 100644 index 00000000..06c06a82 Binary files /dev/null and b/pttbbs/util/rebuildaloha.pl differ -- cgit v1.2.3 From 47a8604b6e25bdc9d2fb8bfe8c591e22e92033c5 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Tue, 5 Nov 2002 14:18:47 +0000 Subject: fix bug of utmpfix fast mode git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@556 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/shmctl.c | 35 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/pttbbs/util/shmctl.c b/pttbbs/util/shmctl.c index e658c304..72b7174b 100644 --- a/pttbbs/util/shmctl.c +++ b/pttbbs/util/shmctl.c @@ -1,4 +1,4 @@ -/* $Id: shmctl.c,v 1.28 2002/11/03 15:19:36 in2 Exp $ */ +/* $Id: shmctl.c,v 1.29 2002/11/05 14:18:47 in2 Exp $ */ #include "bbs.h" extern SHM_t *SHM; @@ -84,16 +84,15 @@ int utmpfix(int argc, char **argv) SHM->UTMPbusystate = 1; printf("starting scaning... %s \n", (fast ? "(fast mode)" : "")); - if( !fast ){ - time(&now); - for( i = 0, nactive = 0 ; i < USHM_SIZE ; ++i ) - if( SHM->uinfo[i].pid ){ - idle[nactive].index = i; - idle[nactive].idle = now - SHM->uinfo[i].lastact; - ++nactive; - } + time(&now); + for( i = 0, nactive = 0 ; i < USHM_SIZE ; ++i ) + if( SHM->uinfo[i].pid ){ + idle[nactive].index = i; + idle[nactive].idle = now - SHM->uinfo[i].lastact; + ++nactive; + } + if( !fast ) qsort(idle, nactive, sizeof(IDLE_t), sfIDLE); - } for( i = 0 ; i < nactive ; ++i ){ which = idle[i].index; @@ -104,14 +103,14 @@ int utmpfix(int argc, char **argv) clean = "process error"; purge_utmp(&SHM->uinfo[which]); } - else if( !fast ){ - if( searchuser(SHM->uinfo[which].userid) == 0 ){ - clean = "user not exist"; - } + else if( searchuser(SHM->uinfo[which].userid) == 0 ){ + clean = "user not exist"; + } #ifdef DOTIMEOUT - else if( nownum > lowerbound && - idle[i].idle > - (timeout == -1 ? IDLE_TIMEOUT : timeout) ){ + else if( !fast ){ + if( nownum > lowerbound && + idle[i].idle > + (timeout == -1 ? IDLE_TIMEOUT : timeout) ){ sprintf(buf, "timeout(%s", ctime(&SHM->uinfo[which].lastact)); buf[strlen(buf) - 1] = 0; @@ -122,8 +121,8 @@ int utmpfix(int argc, char **argv) --nownum; continue; } -#endif } +#endif if( clean ){ printf("clean %06d(%s), userid: %s\n", -- cgit v1.2.3 From a2bbaa58252a69acf4110abd71ec4e30b7a0dfa6 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Wed, 6 Nov 2002 12:07:59 +0000 Subject: fix bug git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@557 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/expire.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pttbbs/util/expire.c b/pttbbs/util/expire.c index dc75a03a..50c568da 100644 --- a/pttbbs/util/expire.c +++ b/pttbbs/util/expire.c @@ -1,4 +1,4 @@ -/* $Id: expire.c,v 1.4 2002/06/06 21:34:14 in2 Exp $ */ +/* $Id: expire.c,v 1.5 2002/11/06 12:07:59 in2 Exp $ */ /* 自動砍信工具程式 */ #include "bbs.h" @@ -199,7 +199,7 @@ char *argv[]; sprintf(bpath, BBSHOME "/boards/%c", dirs[i]); if (!(dirp = opendir(bpath))){ printf(":Err: unable to open %s\n", bpath); - //return -1; + continue; } while((de = readdir(dirp))){ ptr = de->d_name; -- cgit v1.2.3 From ba88eea172450f18024d56dbe69f6b2ab63fefef Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Wed, 6 Nov 2002 16:25:15 +0000 Subject: editlock by flock() git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@558 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/include/proto.h | 3 ++- pttbbs/mbbsd/bbs.c | 34 ++++++++++++++-------------------- pttbbs/mbbsd/edit.c | 38 +------------------------------------- pttbbs/mbbsd/record.c | 34 +++++++++++++++++++++++++++++++++- 4 files changed, 50 insertions(+), 59 deletions(-) diff --git a/pttbbs/include/proto.h b/pttbbs/include/proto.h index e4e910d7..1c72178c 100644 --- a/pttbbs/include/proto.h +++ b/pttbbs/include/proto.h @@ -1,4 +1,4 @@ -/* $Id: proto.h,v 1.29 2002/08/25 07:13:53 in2 Exp $ */ +/* $Id: proto.h,v 1.30 2002/11/06 16:25:14 in2 Exp $ */ #ifndef INCLUDE_PROTO_H #define INCLUDE_PROTO_H @@ -346,6 +346,7 @@ void EnumTagFhdr(fileheader_t *fhdr, char *direct, int locus); void UnTagger (int locus); /* record */ int substitute_record(char *fpath, void *rptr, int size, int id); +int lock_substitute_record(char *fpath, void *rptr, int size, int id, int); int get_record(char *fpath, void *rptr, int size, int id); void prints(char *fmt, ...); int append_record(char *fpath, fileheader_t *record, int size); diff --git a/pttbbs/mbbsd/bbs.c b/pttbbs/mbbsd/bbs.c index dbe9936d..f32f5b91 100644 --- a/pttbbs/mbbsd/bbs.c +++ b/pttbbs/mbbsd/bbs.c @@ -1,4 +1,4 @@ -/* $Id: bbs.c,v 1.70 2002/08/25 18:43:36 in2 Exp $ */ +/* $Id: bbs.c,v 1.71 2002/11/06 16:25:14 in2 Exp $ */ #include "bbs.h" static void @@ -718,11 +718,9 @@ edit_post(int ent, fileheader_t * fhdr, char *direct) local_article = fhdr->filemode & FILE_LOCAL; strlcpy(save_title, fhdr->title, sizeof(save_title)); - if( iseditlocking(genbuf, "重複編輯") ) - return FULLUPDATE; - editlock(genbuf); /* rocker.011018: 這裡是不是該檢查一下修改文章後的money和原有的比較? */ if (vedit(genbuf, 0, NULL) != -1) { + lock_substitute_record(direct, fhdr, sizeof(*fhdr), ent, LOCK_EX); setbpath(fpath, currboard); stampfile(fpath, &postfile); unlink(fpath); @@ -749,11 +747,10 @@ edit_post(int ent, fileheader_t * fhdr, char *direct) strlcpy(fhdr->filename, postfile.filename, sizeof(fhdr->filename)); strlcpy(fhdr->title, save_title, sizeof(fhdr->title)); brc_addlist(postfile.filename); - substitute_record(direct, fhdr, sizeof(*fhdr), ent); + lock_substitute_record(direct, fhdr, sizeof(*fhdr), ent, LOCK_UN); /* rocker.011018: 順便更新一下cache */ touchdircache(currbid); } - editunlock(genbuf); return FULLUPDATE; } @@ -1209,21 +1206,19 @@ recommend(int ent, fileheader_t * fhdr, char *direct) boardheader_t *bp; bp = getbcache(currbid); - if (!(currmode & MODE_POST) || !strcmp(fhdr->owner, cuser.userid) || - bp->brdattr & BRD_VOTEBOARD) { + if (!(currmode & MODE_POST) || bp->brdattr & BRD_VOTEBOARD) { move(b_lines - 1, 0); - prints("您因權限不足無法推薦 或 不能推薦自己的文章!"); + prints("您因權限不足無法推薦!"); pressanykey(); return FULLUPDATE; } setdirpath(path, direct, fhdr->filename); - if( iseditlocking(path, "推薦文章") ) - return FULLUPDATE; if (fhdr->recommend > 9 || fhdr->recommend < 0) /* 暫時性的 code 原來舊有值取消 */ fhdr->recommend = 0; +#if 0 #ifndef DEBUG if (!(currmode & MODE_BOARD) && getuser(cuser.userid) && now - xuser.recommend < 60) { @@ -1233,6 +1228,8 @@ recommend(int ent, fileheader_t * fhdr, char *direct) return FULLUPDATE; } #endif +#endif + if (!getdata(b_lines - 2, 0, "推薦語:", path, 40, DOECHO) || !getdata(b_lines - 1, 0, "確定要推薦, 請仔細考慮(Y/N)?[n] ", yn, 5, LCECHO) || yn[0] != 'y') @@ -1243,20 +1240,22 @@ recommend(int ent, fileheader_t * fhdr, char *direct) cuser.userid, path, 51 - strlen(cuser.userid) - strlen(path), " ", fromhost, ptime->tm_mon + 1, ptime->tm_mday); - if( iseditlocking(path, "推薦文章") ) - return FULLUPDATE; + lock_substitute_record(direct, fhdr, sizeof(*fhdr), ent, LOCK_EX); setdirpath(path, direct, fhdr->filename); log_file(path, buf); - if (fhdr->recommend < 9) { + if (!(fhdr->recommend < 9)) + lock_substitute_record(direct, fhdr, sizeof(*fhdr), ent, LOCK_UN); + else{ fhdr->recommend++; cuser.recommend = now; passwd_update(usernum, &cuser); - substitute_record(direct, fhdr, sizeof(*fhdr), ent); + lock_substitute_record(direct, fhdr, sizeof(*fhdr), ent, LOCK_UN); substitute_check(fhdr); touchdircache(currbid); } return FULLUPDATE; } + static int mark_post(int ent, fileheader_t * fhdr, char *direct) { @@ -1370,12 +1369,7 @@ del_post(int ent, fileheader_t * fhdr, char *direct) getdata(1, 0, msg_del_ny, genbuf, 3, LCECHO); if (genbuf[0] == 'y' || genbuf[0] == 'Y') { strlcpy(currfile, fhdr->filename, sizeof(currfile)); - - setbfile(genbuf, currboard, fhdr->filename); - if( iseditlocking(genbuf, "刪除文章") ) - return FULLUPDATE; if (!delete_file(direct, sizeof(fileheader_t), ent, cmpfilename)) { - if (currmode & MODE_SELECT) { /* rocker.011018: 利用reference減低loading */ fileheader_t hdr; diff --git a/pttbbs/mbbsd/edit.c b/pttbbs/mbbsd/edit.c index 8685dfc5..f560167d 100644 --- a/pttbbs/mbbsd/edit.c +++ b/pttbbs/mbbsd/edit.c @@ -1,4 +1,4 @@ -/* $Id: edit.c,v 1.20 2002/10/26 03:54:15 in2 Exp $ */ +/* $Id: edit.c,v 1.21 2002/11/06 16:25:15 in2 Exp $ */ #include "bbs.h" typedef struct textline_t { struct textline_t *prev; @@ -2290,39 +2290,3 @@ vedit(char *fpath, int saveheader, int *islocal) } } -void editlock(char *fpath) -{ - char fn[256]; - FILE *fp; - snprintf(fn, sizeof(fn), "%s.lock", fpath); - if( (fp = fopen(fn, "w")) != NULL ){ - fprintf(fp, "%d\n", currpid); - fclose(fp); - } -} - -void editunlock(char *fpath) -{ - char fn[256]; - snprintf(fn, sizeof(fn), "%s.lock", fpath); - unlink(fn); -} - -int iseditlocking(char *fpath, char *action) -{ - char fn[256]; - FILE *fp; - snprintf(fn, sizeof(fn), "%s.lock", fpath); - if( (fp = fopen(fn, "r")) != NULL ){ - int pid; - fscanf(fp, "%d", &pid); - fclose(fp); - if( kill(pid, 0) >= 0 ){ - vmsg("文章編修中, 暫時無法%s", action); - return 1; - } - else - unlink(fn); - } - return 0; -} diff --git a/pttbbs/mbbsd/record.c b/pttbbs/mbbsd/record.c index bd0c5316..13db0da6 100644 --- a/pttbbs/mbbsd/record.c +++ b/pttbbs/mbbsd/record.c @@ -1,4 +1,4 @@ -/* $Id: record.c,v 1.10 2002/07/22 19:02:00 in2 Exp $ */ +/* $Id: record.c,v 1.11 2002/11/06 16:25:15 in2 Exp $ */ #include "bbs.h" #undef HAVE_MMAP @@ -90,6 +90,38 @@ get_records(char *fpath, void *rptr, int size, int id, int number) return id / size; } +int +lock_substitute_record(char *fpath, void *rptr, int size, int id, int mode) +{ + static int fd = -1; + switch( mode ){ + case LOCK_EX: + if( id < 1 || (fd = open(fpath, O_RDWR | O_CREAT, 0644)) == -1 ) + return -1; + + if( flock(fd, LOCK_EX) < 0 ){ + close(fd); + return -1; + } + lseek(fd, (off_t) (size * (id - 1)), SEEK_SET); + read(fd, rptr, size); + return 0; + + case LOCK_UN: + if( fd < 0 ) + return -1; + lseek(fd, (off_t) (size * (id - 1)), SEEK_SET); + write(fd, rptr, size); + flock(fd, LOCK_UN); + close(fd); + fd = -1; + return 0; + + default: + return -1; + } +} + int substitute_record(char *fpath, void *rptr, int size, int id) { -- cgit v1.2.3 From 927f17a75a35fc9a074fa75414f86c50e52019ed Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Thu, 7 Nov 2002 09:13:24 +0000 Subject: BRD_NORECOMMEND git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@559 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/include/common.h | 13 +------ pttbbs/include/pttstruct.h | 27 +++++++------- pttbbs/mbbsd/bbs.c | 93 +++++++++++++++++++++++++++++----------------- pttbbs/mbbsd/var.c | 6 +-- 4 files changed, 77 insertions(+), 62 deletions(-) diff --git a/pttbbs/include/common.h b/pttbbs/include/common.h index 90b4aca1..d70e8b82 100644 --- a/pttbbs/include/common.h +++ b/pttbbs/include/common.h @@ -1,4 +1,4 @@ -/* $Id: common.h,v 1.4 2002/06/22 07:24:47 ptt Exp $ */ +/* $Id: common.h,v 1.5 2002/11/07 09:13:23 in2 Exp $ */ #ifndef INCLUDE_COMMON_H #define INCLUDE_COMMON_H @@ -172,17 +172,6 @@ #define LTR(x) ((x) * 2 + 3) #define CHE(a, b) ((a) | ((b) << 3)) -#define BRD_NOZAP 00001 /* 不可zap */ -#define BRD_NOCOUNT 00002 /* 不列入統計 */ -#define BRD_NOTRAN 00004 /* 不轉信 */ -#define BRD_GROUPBOARD 00010 /* 群組板 */ -#define BRD_HIDE 00020 /* 隱藏板 (看板好友才可看) */ -#define BRD_POSTMASK 00040 /* 限制發表或閱讀 */ -#define BRD_ANONYMOUS 00100 /* 匿名板 */ -#define BRD_DEFAULTANONYMOUS 00200 /* 預設匿名板 */ -#define BRD_BAD 00400 /* 違法改進中看板 */ -#define BRD_VOTEBOARD 01000 /* 連署機看板 */ - #define MAX_MODES 80 #ifndef MIN diff --git a/pttbbs/include/pttstruct.h b/pttbbs/include/pttstruct.h index 56d262e6..7d546415 100644 --- a/pttbbs/include/pttstruct.h +++ b/pttbbs/include/pttstruct.h @@ -1,4 +1,4 @@ -/* $Id: pttstruct.h,v 1.25 2002/07/19 18:01:39 in2 Exp $ */ +/* $Id: pttstruct.h,v 1.26 2002/11/07 09:13:23 in2 Exp $ */ #ifndef INCLUDE_STRUCT_H #define INCLUDE_STRUCT_H @@ -120,18 +120,19 @@ typedef struct boardheader_t { char pad3[84]; } boardheader_t; -#define BRD_NOZAP 00001 /* 不可zap */ -#define BRD_NOCOUNT 00002 /* 不列入統計 */ -#define BRD_NOTRAN 00004 /* 不轉信 */ -#define BRD_GROUPBOARD 00010 /* 群組板 */ -#define BRD_HIDE 00020 /* 隱藏板 (看板好友才可看) */ -#define BRD_POSTMASK 00040 /* 限制發表或閱讀 */ -#define BRD_ANONYMOUS 00100 /* 匿名板? */ -#define BRD_DEFAULTANONYMOUS 00200 /* 預設匿名板 */ -#define BRD_BAD 00400 /* 違法改進中看板 */ -#define BRD_VOTEBOARD 01000 /* 連署機看板 */ -#define BRD_WARNDEL 02000 /* 已警告要廢除的看板 */ -#define BRD_TOP 04000 /* 熱門看板的群組 設群組板才有用*/ +#define BRD_NOZAP 000000001 /* 不可zap */ +#define BRD_NOCOUNT 000000002 /* 不列入統計 */ +#define BRD_NOTRAN 000000004 /* 不轉信 */ +#define BRD_GROUPBOARD 000000010 /* 群組板 */ +#define BRD_HIDE 000000020 /* 隱藏板 (看板好友才可看) */ +#define BRD_POSTMASK 000000040 /* 限制發表或閱讀 */ +#define BRD_ANONYMOUS 000000100 /* 匿名板 */ +#define BRD_DEFAULTANONYMOUS 000000200 /* 預設匿名板 */ +#define BRD_BAD 000000400 /* 違法改進中看板 */ +#define BRD_VOTEBOARD 000001000 /* 連署機看板 */ +#define BRD_WARNEL 000002000 /* 連署機看板 */ +#define BRD_TOP 000004000 /* 熱門看板群組 */ +#define BRD_NORECOMMEND 000010000 /* 不可推薦 */ #define TTLEN 64 /* Length of title */ #define FNLEN 33 /* Length of filename */ diff --git a/pttbbs/mbbsd/bbs.c b/pttbbs/mbbsd/bbs.c index f32f5b91..0c720dda 100644 --- a/pttbbs/mbbsd/bbs.c +++ b/pttbbs/mbbsd/bbs.c @@ -1,4 +1,4 @@ -/* $Id: bbs.c,v 1.71 2002/11/06 16:25:14 in2 Exp $ */ +/* $Id: bbs.c,v 1.72 2002/11/07 09:13:24 in2 Exp $ */ #include "bbs.h" static void @@ -1204,12 +1204,14 @@ recommend(int ent, fileheader_t * fhdr, char *direct) struct tm *ptime = localtime(&now); char buf[200], path[200], yn[5]; boardheader_t *bp; - bp = getbcache(currbid); + bp = getbcache(currbid); + if( bp->brdattr & BRD_NORECOMMEND ){ + vmsg("抱歉, 本板禁止推薦"); + return FULLUPDATE; + } if (!(currmode & MODE_POST) || bp->brdattr & BRD_VOTEBOARD) { - move(b_lines - 1, 0); - prints("您因權限不足無法推薦!"); - pressanykey(); + vmsg("您因權限不足無法推薦!"); return FULLUPDATE; } @@ -1860,6 +1862,28 @@ b_help() return FULLUPDATE; } +static int +b_changerecommend(int ent, fileheader_t * fhdr, char *direct) +{ + boardheader_t bh; + int bid; + if (!((currmode & MODE_BOARD) || HAS_PERM(PERM_SYSOP)) || + currboard[0] == 0 || + (bid = getbnum(currboard)) < 0 || + get_record(fn_board, &bh, sizeof(bh), bid) == -1) + return DONOTHING; + if( bh.brdattr & BRD_NORECOMMEND ) + bh.brdattr -= BRD_NORECOMMEND; + else + bh.brdattr += BRD_NORECOMMEND; + setup_man(&bh); + substitute_record(fn_board, &bh, sizeof(bh), bid); + reset_board(bid); + vmsg("本板現在 %s 推薦", + (bh.brdattr & BRD_NORECOMMEND) ? "禁止" : "開放"); + return FULLUPDATE; +} + /* ----------------------------------------------------- */ /* 板主設定隱形/ 解隱形 */ /* ----------------------------------------------------- */ @@ -1920,49 +1944,50 @@ change_hidden(int ent, fileheader_t * fhdr, char *direct) /* ----------------------------------------------------- */ struct onekey_t read_comms[] = { {KEY_TAB, board_digest}, - {'C', board_etc}, + {'B', bh_title_edit}, {'b', b_notes}, + {'C', board_etc}, {'c', cite_post}, - {'r', read_post}, - {'z', b_man}, {'D', del_range}, - {'S', sequential_read}, + {'d', del_post}, {'E', edit_post}, - {'T', edit_title}, - {'s', do_select}, - {'R', b_results}, - {'V', b_vote}, - {'M', b_vote_maintain}, - {'B', bh_title_edit}, - {'W', b_notes_edit}, - {'O', b_post_note}, - {'K', b_water_edit}, - {'w', b_call_in}, - {'v', visable_list_edit}, - {'i', b_application}, - {'o', can_vote_edit}, - {'x', cross_post}, - {'X', recommend}, - {'Y', recommend_cancel}, - {'h', b_help}, #ifndef NO_GAMBLE {'f', join_gamble}, {'G', hold_gamble}, #endif {'g', good_post}, - {'y', reply_post}, - {'d', del_post}, - {'m', mark_post}, +#ifdef BMCHS + {'H', change_hidden}, +#endif + {'h', b_help}, + {'I', b_changerecommend}, + {'i', b_application}, + {'K', b_water_edit}, {'L', solve_post}, - {Ctrl('P'), do_post}, - {Ctrl('W'), whereami}, + {'M', b_vote_maintain}, + {'m', mark_post}, + {'O', b_post_note}, + {'o', can_vote_edit}, {'Q', view_postmoney}, + {'R', b_results}, + {'r', read_post}, + {'S', sequential_read}, + {'s', do_select}, + {'T', edit_title}, #ifdef OUTJOBSPOOL {'u', tar_addqueue}, #endif -#ifdef BMCHS - {'H', change_hidden}, -#endif + {'V', b_vote}, + {'v', visable_list_edit}, + {'W', b_notes_edit}, + {'w', b_call_in}, + {'X', recommend}, + {'x', cross_post}, + {'Y', recommend_cancel}, + {'y', reply_post}, + {'z', b_man}, + {Ctrl('P'), do_post}, + {Ctrl('W'), whereami}, {'\0', NULL} }; diff --git a/pttbbs/mbbsd/var.c b/pttbbs/mbbsd/var.c index 819be5ba..e7f6996f 100644 --- a/pttbbs/mbbsd/var.c +++ b/pttbbs/mbbsd/var.c @@ -1,4 +1,4 @@ -/* $Id: var.c,v 1.13 2002/09/11 03:22:50 kcwu Exp $ */ +/* $Id: var.c,v 1.14 2002/11/07 09:13:24 in2 Exp $ */ #define INCLUDE_VAR_H #include "bbs.h" @@ -41,7 +41,7 @@ char *str_permboard[] = { "不可 Zap", /* BRD_NOZAP */ "不列入統計", /* BRD_NOCOUNT */ "不轉信", /* BRD_NOTRAN */ - "群組板", /* BRD_GROUP */ + "群組板", /* BRD_GROUPBOARD */ "隱藏板", /* BRD_HIDE */ "限制(不需設定)", /* BRD_POSTMASK */ "匿名板", /* BRD_ANONYMOUS */ @@ -50,7 +50,7 @@ char *str_permboard[] = { "連署專用看板", /* BRD_VOTEBOARD */ "已警告要廢除", /* BRD_WARNEL */ "熱門看板群組", /* BRD_TOP */ - "沒想到", + "不可推薦", /* BRD_NORECOMMEND */ "沒想到", "沒想到", "沒想到", -- cgit v1.2.3 From 0f0026e4f78819b2d67b1748e0fea384e42f8ae2 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Thu, 7 Nov 2002 09:35:51 +0000 Subject: could NOT delete/edit/recommend in MODE_SELECT git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@560 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/bbs.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/pttbbs/mbbsd/bbs.c b/pttbbs/mbbsd/bbs.c index 0c720dda..cf64faaa 100644 --- a/pttbbs/mbbsd/bbs.c +++ b/pttbbs/mbbsd/bbs.c @@ -1,4 +1,4 @@ -/* $Id: bbs.c,v 1.72 2002/11/07 09:13:24 in2 Exp $ */ +/* $Id: bbs.c,v 1.73 2002/11/07 09:35:51 in2 Exp $ */ #include "bbs.h" static void @@ -713,6 +713,10 @@ edit_post(int ent, fileheader_t * fhdr, char *direct) if ((!HAS_PERM(PERM_SYSOP)) && strcmp(fhdr->owner, cuser.userid)) return DONOTHING; + + if( currmode & MODE_SELECT ) + return DONOTHING; + setutmpmode(REEDIT); setdirpath(genbuf, direct, fhdr->filename); local_article = fhdr->filemode & FILE_LOCAL; @@ -1205,6 +1209,9 @@ recommend(int ent, fileheader_t * fhdr, char *direct) char buf[200], path[200], yn[5]; boardheader_t *bp; + if( currmode & MODE_SELECT ) + return DONOTHING; + bp = getbcache(currbid); if( bp->brdattr & BRD_NORECOMMEND ){ vmsg("抱歉, 本板禁止推薦"); @@ -1355,6 +1362,9 @@ del_post(int ent, fileheader_t * fhdr, char *direct) int not_owned; boardheader_t *bp; + if( currmode & MODE_SELECT ) + return DONOTHING; + bp = getbcache(currbid); if (strcmp(bp->brdname, "Security") == 0) return DONOTHING; -- cgit v1.2.3 From aa4fa070bc7e5a7ff1f06b0378d9337e18e5bc6a Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Thu, 7 Nov 2002 13:59:35 +0000 Subject: BRD_NORECOMMEND help git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@561 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/bbs.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pttbbs/mbbsd/bbs.c b/pttbbs/mbbsd/bbs.c index cf64faaa..9e905b90 100644 --- a/pttbbs/mbbsd/bbs.c +++ b/pttbbs/mbbsd/bbs.c @@ -1,4 +1,4 @@ -/* $Id: bbs.c,v 1.73 2002/11/07 09:35:51 in2 Exp $ */ +/* $Id: bbs.c,v 1.74 2002/11/07 13:59:35 in2 Exp $ */ #include "bbs.h" static void @@ -1860,7 +1860,7 @@ static char *board_help[] = { "(G) 舉辦賭盤/停止下注/開獎(W/K/v) 編輯備忘錄/水桶名單/可看見名單", "(M/o) 舉行投票/編私投票名單 (m/c/g) 保留文章/選錄精華/文摘", "(D) 刪除一段範圍的文章 (T/B) 重編文章標題/重編看板標題", - "(i) 編輯申請入會表格 (t/^D) 標記文章/砍除標記的文章", + "(I) 開放/禁止看版推薦 (t/^D) 標記文章/砍除標記的文章", "(O) 編輯Post注意事項 (H)/(Y) 看板隱藏/現身 取消推薦文章", NULL }; -- cgit v1.2.3 From 0e98301333915f6ad4a7caf99d3d90b8f448c928 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Thu, 7 Nov 2002 14:22:34 +0000 Subject: fix bug of help in (MODE_ETC | MODE_DIGEST) mode git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@562 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/read.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/pttbbs/mbbsd/read.c b/pttbbs/mbbsd/read.c index ec7efeb4..cd0811e0 100644 --- a/pttbbs/mbbsd/read.c +++ b/pttbbs/mbbsd/read.c @@ -1,4 +1,4 @@ -/* $Id: read.c,v 1.14 2002/08/15 09:46:30 in2 Exp $ */ +/* $Id: read.c,v 1.15 2002/11/07 14:22:34 in2 Exp $ */ #include "bbs.h" #define MAXPATHLEN 256 @@ -714,6 +714,8 @@ i_read_key(onekey_t * rcmdlist, keeploc_t * locmem, int ch, int bid) case KEY_RIGHT: ch = 'r'; default: + if( ch == 'h' && currmode & (MODE_ETC | MODE_DIGEST) ) + return DONOTHING; for (i = 0; rcmdlist[i].fptr; i++) { if (rcmdlist[i].key == ch) { mode = (*(rcmdlist[i].fptr)) (locmem->crs_ln, @@ -721,9 +723,6 @@ i_read_key(onekey_t * rcmdlist, keeploc_t * locmem, int ch, int bid) locmem->top_ln], currdirect); break; } - if (rcmdlist[i].key == 'h') - if (currmode & (MODE_ETC | MODE_DIGEST)) - return DONOTHING; } } return mode; -- cgit v1.2.3 From 7894efba356df7180602cec5a1ef64228c92e9f6 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Fri, 8 Nov 2002 17:45:43 +0000 Subject: =?UTF-8?q?=EF=BF=BD=EF=BF=BD=EF=BF=BD@=EF=BF=BD=EF=BF=BD=EF=BF=BD?= =?UTF-8?q?=EF=BF=BD=EF=BF=BDi=EF=BF=BDH=EF=BF=BD=EF=BF=BD=EF=BF=BD?= =?UTF-8?q?=EF=BF=BD,=2040=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD?= =?UTF-8?q?=EF=BF=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@563 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/bbs.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/pttbbs/mbbsd/bbs.c b/pttbbs/mbbsd/bbs.c index 9e905b90..e8fa0075 100644 --- a/pttbbs/mbbsd/bbs.c +++ b/pttbbs/mbbsd/bbs.c @@ -1,4 +1,4 @@ -/* $Id: bbs.c,v 1.74 2002/11/07 13:59:35 in2 Exp $ */ +/* $Id: bbs.c,v 1.75 2002/11/08 17:45:43 in2 Exp $ */ #include "bbs.h" static void @@ -1202,6 +1202,7 @@ recommend_cancel(int ent, fileheader_t * fhdr, char *direct) touchdircache(currbid); return FULLUPDATE; } + static int recommend(int ent, fileheader_t * fhdr, char *direct) { @@ -1227,20 +1228,23 @@ recommend(int ent, fileheader_t * fhdr, char *direct) /* 暫時性的 code 原來舊有值取消 */ fhdr->recommend = 0; -#if 0 + if (fhdr->recommend < 0 && strcmp(cuser.userid, fhdr->owner) == 0){ + vmsg("警告! 本人不能推薦第一次!"); + return FULLUPDATE; + } #ifndef DEBUG if (!(currmode & MODE_BOARD) && getuser(cuser.userid) && - now - xuser.recommend < 60) { + now - xuser.recommend < 40) { move(b_lines - 1, 0); prints("離上次推薦時間太近囉, 請多花點時間仔細閱\讀文章!"); pressanykey(); return FULLUPDATE; } -#endif #endif if (!getdata(b_lines - 2, 0, "推薦語:", path, 40, DOECHO) || - !getdata(b_lines - 1, 0, "確定要推薦, 請仔細考慮(Y/N)?[n] ", yn, 5, LCECHO) + !getdata(b_lines - 1, 0, "確定要推薦, 請仔細考慮(Y/N)?[n] ", + yn, 5, LCECHO) || yn[0] != 'y') return FULLUPDATE; -- cgit v1.2.3 From db544260afa4568e942559cf45a382e18c5d1783 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Fri, 8 Nov 2002 17:49:03 +0000 Subject: fix bug git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@564 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/bbs.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pttbbs/mbbsd/bbs.c b/pttbbs/mbbsd/bbs.c index e8fa0075..2ee8423d 100644 --- a/pttbbs/mbbsd/bbs.c +++ b/pttbbs/mbbsd/bbs.c @@ -1,4 +1,4 @@ -/* $Id: bbs.c,v 1.75 2002/11/08 17:45:43 in2 Exp $ */ +/* $Id: bbs.c,v 1.76 2002/11/08 17:49:03 in2 Exp $ */ #include "bbs.h" static void @@ -1228,7 +1228,7 @@ recommend(int ent, fileheader_t * fhdr, char *direct) /* 暫時性的 code 原來舊有值取消 */ fhdr->recommend = 0; - if (fhdr->recommend < 0 && strcmp(cuser.userid, fhdr->owner) == 0){ + if (fhdr->recommend == 0 && strcmp(cuser.userid, fhdr->owner) == 0){ vmsg("警告! 本人不能推薦第一次!"); return FULLUPDATE; } -- cgit v1.2.3 From 4773b76890277b1487c42c65b02922b3159841da Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Fri, 8 Nov 2002 20:28:36 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@565 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/docs/z6ibbs.1.txt | 122 ++++++++++++++++++++++++++++++++++++ pttbbs/docs/z6ibbs.2.txt | 159 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 281 insertions(+) create mode 100644 pttbbs/docs/z6ibbs.1.txt create mode 100644 pttbbs/docs/z6ibbs.2.txt diff --git a/pttbbs/docs/z6ibbs.1.txt b/pttbbs/docs/z6ibbs.1.txt new file mode 100644 index 00000000..6ff5f0d6 --- /dev/null +++ b/pttbbs/docs/z6ibbs.1.txt @@ -0,0 +1,122 @@ +作者: in2 (中秋玉兔 *^^*) 看板: in2 +標題: [隨意] 關於架設一個 z6ibbs (硬體篇) +時間: Mon Oct 21 14:17:31 2002 + +唔, 只是隨手寫寫東西, +如果下面有提到任何價格那都是僅供參考, +並不代表妳可以用這個價格買到東西 + (當然妳可能買到比較便宜就是了 A_AY ) +所有的價格以 k為單位, 即中文的 仟 . + +也許我會拿 Ptt/Ptt2 來做些例子 ;p +當然我並不會告訴妳現在到底是用什麼 :P +不過也許我會偷偷告訴妳一些好玩的東西 ;p + +第一個先說到 CPU. +就一般的情況來說, 只要程式寫的有一點好 + (尤其是 userlist 不要惡搞的話) +通常不會要到很高, +一般的 PIII-class 等級應該就是可以動了, +當然妳可以考慮用 Xeon幾顆, 再打開 hyper-threading.... + Xeon 的價格差不多是 10k (2.4G, socket 603) +據說醬子跑 setiathome 相當快 A_AY +事實上我並不會告訴妳 Ptt是用什麼樣的 CPU, +不過我可以偷偷告訴妳, +我們不過用了 PIII-class 某某兩顆, + clock並沒有很快, 據不知道可不可靠的消息, +她們是不到 1G Hz的 :X + +說到 memory 的話, 就是大家心中的痛了 Q_Q +就我所知道目前沒有在怕記憶體的, +只有小旭旭長輩的 天火BBS . +就我手邊的兩台機器, 都幾乎是卡死在 ram不夠. +並且, 一般的 motherboard都不能支援到很高的 ram, +或是她雖然可以支援到很高, 可是她的 bank 數並不夠. +像有些 motherboard雖然可以插到 4G , +但是只有 4 banks. 也就是妳須要一條 1G 的 ram x 4才能達到. +再者, 到夠高級的 motherboard通常要求 ram要是 registered 的. +有 registered 的 ram比一般用的 non-registered 還要貴的多. +前陣子問到的是 512MB 5~7k , 1GB 一條要 13k. +這真的是: + 平平是 ram, 成份不同, 效果也不同 XD +以我們自己估算的話, +差不多 1G 可以撐到 2k+人 (同時在線上) +當然實際值比這個還要再多一點, +我覺得再上去都已經是讓系統死命的在跑, +我自然是不會告訴妳現在 Ptt是用多少記憶體在跑, +不過可以偷偷告訴妳, 事實上和妳偷猜的應該差不多, 或者是少點多點. + +大概考慮了 cpu和 ram後, 就可以來找一塊合適的 motherboard了. +個人滿喜歡 tyan 的 (http://www.tyan.com) + (呃, 好像有點打廣告 ^^") + tyan 有生產不少高級板子 (請往 Thunder系列走) +像是可以插至少兩顆 processor(s), dual-LAN, SCSI onboard, +價格差不多都是至少 15k, 一般所用的 chipset應該 FreeBSD都有 support . +當然, 妳最好在刷卡前確認好價錢以及是不是有支援. +請去買一張樂透以及把板子拿去換另一個型號或退貨, +如果妳運氣好到買的那張剛剛好是 FreeBSD沒有支援的. + tyan 的高級板, 像是這一張: + http://www.tyan.com/products/html/thundergche.html +Intel Xeon MP x 4, MAX 24GB DDR ram, dual LAN, SCSI onboard .... +motherboard 算 20k, CPU 一顆算 10k, 再加 24GB DDR算 13k/GB +差不多 400k 左右就可以買的到全套, +這應該是叫她送一個好機殼外加一大堆風扇, power supply(s). +買了這張之後, 一打 top看到的前 8個 process(es) 應該都是 setiathome A_AY +當然, 我並打算要告訴妳我們現在用哪一張, +也不會偷偷告訴妳我們現在用哪一張 -_-!# + +硬碟算是 bbs滿主要的一個地方. +這個時候就要套 D某, 某K 大大的一句話: + IDE 硬碟是什麼? 沒聽過... 拿去丟掉吧 -_- +是的, SCSI 硬碟是最佳的選擇, + SCSI 硬碟沒有幾家有在做, 所以也不用急 ;p +價格差不多是 9G 6k, 18G 8k, 32G 16k 左右. +就我自己的經驗, 硬碟通常不用很大, 不過越多越好~ ;p +因為 SCSI 硬碟基本上各顆間可以平行存取, +所以越多顆理論上可以越快一點, +而一般來說 bbs都會卡在 io 速度不夠快. +IDE 硬碟則是拿來開機和備份的好東西, +便宜又大碗, 反正壞了就丟, 也不怎麼貴 -_-!# +或許有人會很有錢的用 hardware-raid A_AY, +又或是用 vinum把她整個弄成一大塊 ;p +不過個人還是習慣切很多塊自己搞 ;x + (事實上是因為沒錢買硬碟 raid :X ) + vinum好像又出過一些小問題, 所以就自己惡搞了 ;o +另外一般情況, 市面上只能買到可以接四個 SCSI 裝置的排線. +雖然一個 SCSI bus 理論上可以接 15 (還是 16 ? ) 個 SCSI 裝置, +不過超過四個的話就要訂做了. +如果有人去訂一條可以插十五個裝置線的話, 麻煩借我看一下 A_AY +我自然也不會告訴妳 Ptt現在有幾顆硬碟在上面, +不過可以偷偷告訴妳, 在今年內, 最少有四顆, 最多有九顆硬碟同時在上面. + +其他剩下的就是很次要的了, +像是要準備很大的殼子以塞進這麼多硬碟 @_@;;; +另外裝置一多的時候, 一個小小的 power可能會不夠力, +於是也許妳要用兩個 (以上) 的 power supply . +幸運的, tyan 有不少 motherboard都可以插兩個 power supply上去. +另外還要注意散熱, 事實上當買完上面那些東西, +風扇大概都可以直接叫她送了~ ;p +比較要緊的是也許要為硬碟加個風扇 ;d +以免像某大一樣把硬碟測到燒掉 ;ppp +另外, 有不少 motherboard都是直接音效和顯示內建的. +自然我還是不打算告訴妳我們現在用的 onboard 音效和顯示卡到底是哪個 chip. +不過我可以偷偷告訴妳, + 也許我哪天心情好的時候, 實驗室裡的人會聽到 ptt正在放 mp3 -__-!# + +我自然不會告訴妳現在 ptt or ptt2到底花掉了多少錢 @_@;;; +不過我可以偷偷告訴妳: + + 我好窮喔 >O< + +-- +  ▂▅▇▇▅   裺嘵○ 摃丐丐片    ▃ ◢◢  +  ▊ /    摃片裐朅 遉丐丐片歈 歈稙裐遉丐片  ◢ ▃  ██  +  ▎ ◤◢█◤  裺稙潁矙 聝丐丐片/裐歈朅裐═ ◥◤▌◢◢◢  +  ▌ ▎◣ ◢▎ 矙矙矙矙 ══煍片/ 矙僓朅禊歈屣片  ◢ ◣   +  ◣        潁 ═嘵嘵 矙矙裺朅潁裺屣丑  _ '_ ' _   + ◢█\ ‾◤    裺潁  ◥ ▼ \◤  + +-- +※ 發信站: 新批踢踢(ptt2.cc) +◆ From: 140.112.30.143 +→ windsheep:好好笑喔...借我偷回家放..@_@s 推140.112.182.151 10/21 diff --git a/pttbbs/docs/z6ibbs.2.txt b/pttbbs/docs/z6ibbs.2.txt new file mode 100644 index 00000000..1a704c6d --- /dev/null +++ b/pttbbs/docs/z6ibbs.2.txt @@ -0,0 +1,159 @@ +作者: in2 (中秋玉兔 *^^*) 看板: in2 +標題: [隨意] 關於架設一個 z6ibbs (隨筆篇) +時間: Tue Oct 22 21:59:12 2002 + +只是剛剛好想到一些事情, 隨手寫了下來 ;d +不過我想某些東西, 也許可以提供大家在某些地方上面用. + +我們先來說整個系統的架構. +尤其像是 bbs這種不是很容易分散到多台機器跑的系統, + (也就是要用一台強力的機器硬撐的) +最好要再多準備一台電腦, +幫忙把一些其餘的服務分掉. +像是郵件 (尤其加上擋信) , 轉信, make world 以及一些後面會描述到的東西. +我們姑且將這台機器稱為後援機好了, +他主要的目的只是想要幫前端機分掉一點事情, +8像是郵件, 就由後援機去對外收 (並進行擋信) 以及替前端機發信. +好處是, 信件並不是太須要即時 (妳大概不會要求按下 send 後 100ms內要送到) +可是有的時候可能會花掉大量的資源, +像是要擋信, 或是和對方網路上的問題一直重送, +又或是 queue一大堆信件在硬碟裡面, 每過一些時候又一直要 retry一次. +又或是妳大概不會想要在一台 load > 30的機器上 make world or ports +於是我們在前端機旁加一台後援, 讓這種煩人的事情由後援機去做, +於是前端機就可以更 focus在他的服務上. +像這種情況, 兩台機器最好串在很近的地方, +像是同一個 switch 上, 又或是直接用 cross-over 線互聯. + +要怎麼來備份一個足夠龐大又會不斷亂長的系統? +我想應該不會有人想要把 bbs丟到 cvs裡面, 雖然 cvs很好用 :X +bbs 一般可以考慮直接把她整個 tar + gz 起來, +就算爆炸了要還原應該也不會算是什麼大困難. +好像有某長輩是用 dump 的 @_@;;;; +備份最好兩地備份, +當然妳可以考慮直接備份在妳的後援機上, +這決對會比妳備份在前端機要好的太多了. +當然若妳可以再備份到另外一地 (像是備份到美國) +醬子會大大增加爆炸時的損失. + +一般應該是會把 bbs架在 i386 上, +自然用的是 FreeBSD或是 Solaris(i386) +我當然不會告訴妳我們用的是什麼, +不過據說我們頗崇尚 berkeley A_AY +另外我還可以偷偷的告訴妳一些小道消息, +像是據說某間很大的動物園, 她們好像也是用 FreeBSD , +某個喀喀城市, 用的也是 FreeBSD, +另外有一個神祕據說叫做天火的 bbs, 用的是 Solaris(i386) +曾經有位 I零 大大, 說他都直接跟客戶說: + Linux, no tech support +因為他不會用 Linux, 然後如果人家硬要用的話, +他就會拿 RedHat 光碟把他 install all :PP + (要用什麼是個人信仰, 請不要找我來吵架 ;p ) + +在 FreeBSD分成三個主要的 branch(es): stable, release, current, +除非妳心臟很夠力或很年輕或是夠大, +一般情況下並不會拿 current的版本在正式的 server 上玩. +雖然 current有些強力的功能, 不過正如 handbook 說的: +21.2.1.3 What Is FreeBSD-CURRENT Not? +1. A fast-track to getting pre-release bits because you heard there + is some cool new feature in there and you want to be the first on + your block to have it. Being the first on the block to get the new + feature means that you're the first on the block to get the new bugs. +2. A quick way of getting bug fixes. Any given version of FreeBSD-CURRENT + is just as likely to introduce new bugs as to fix existing ones. + (引自 http://www.freebsd.org/doc/en_US.ISO8859-1/ + books/handbook/current-stable.html ) +不過不管你用哪一個, 記得時時要注意一下, +看看有沒有什麼 security hole又被爆破. +通常 follow release 是比較保險的做法, +不過這項事情好像在最近並不成立. +我自然不會告訴妳我到底是不是偷偷昇級到 current了 A"A + +關於 security 上的問題, +一般的通訊顯然應該要走 ssh一類的通道, +而至於 telnetd, rsh 等等, 請直接拿去馬桶沖掉 @_@;;;; +另外建議設簡單的 firewall , +在發生火災的時候會有比較高的存活率~ ;d +通常至少會有 + allow ip from any to any via lo0 + deny ip from any to 127.0.0.0/8 + deny ip from 127.0.0.0/8 to any +就正常的情況下來說, 127.0.0.0/8 應該是不可能會從非 lo0來. +而對於 < 1024 的 resvered port , +通常會只 allow幾個有開 service的 port , 其他全擋. +像是: + allow tcp from any to me 22,23,25 in + deny tcp from any to me 1-1023 in +若機器並不須要提供大家 ssh的 login + (像是妳的 bbs只開放 port 23, 並沒有開放由 ssh轉到 bbs) +事實上可以考慮直接把 port 22 (ssh)設死在只有某個 ip 可以連進來, +像是上面改成: + allow tcp from 140.112.30.142 to me 22 in + # 只給 140.112.30.142 連到本機 port 22 + allow tcp from any to me 23,25 in + # 大家都可以連本機 port 23,25 + deny tcp from any to me 1-1023 in + # 其他每個 port 的 tcp都不給連 +醬子就算 ssh暴出 security hole , +只要唯一(s) 可以連到的幾台機器都沒有被攻破, +或是跟本就沒有人知道只有那一(s) 台電腦可以連到該台的 port 22 , +至少又比大家都可以連到妳的 ssh安全許多. + +我相信在一般情況下, +或多或少妳都會碰到那種非到 console解決的事情不可, +像是 fsck 失敗了, console提示要妳打入 root's passsword , +然後問妳 shell, 要妳手動 fsck , +通常發生這種 (或其他) 的情況的時候, +網路並還沒有起來, 妳並是 ping 不到, 更別說要 ssh進去了. +如果這個時候妳妳人就在機器旁的話自然還好, +不過如果妳人不在機器旁 (ex妳在北京, 機器在台灣) 呢? +我建議如果妳有這種考量 or 吃過大苦頭 or 不想吃大苦頭的, +最好使用 serial console. + serial console 差不多是把 console的訊息, +透過 serial (也就是 com port) 導到另外一台機器上 (假設接到後援機) +啟動 serial console 是在相當早的, +在 BIOS 等等開機程序完成把 loader 載進來後, +就會把所有的 console訊息導到 serial 上 + (這部份我並不是很確定, 若有錯誤請指正 ^^" ) +也就是, serial console 可以看到完整的開機畫面, +就算是 kernel panic , 也可以在 serial console 進 kdb. +於是, 一旦前端機 crash掉, 連網路都 ping 不到的時候, +只要這個時候後援機還活著, 就可以透過網路連進後援機, +透過 serial console 看看前端機目前的情況, +在大多數的情況下, 透過 serial console 都可以把問題解決掉. + (當然, 如果像是硬碟爆炸, CPU燒掉的話, 顯然就沒辦法了 ^^" ) +我會建議在後援機開隻 screen 把前端機的 console ALWAYS attach. +如此一旦出問題的話, 妳可以看到最後到底發生什麼事情. + +自然也許有朋友會有疑問, 如果後援機 crash的話怎麼辦 @"@ +唔, 我們當然只會在後援機上找外星人和做一些簡單的事情, +一般的情況下醬子要把機器搞爆應該不是很容易的. +當然妳可以把後援機的 console接到前端機上, +醬如果後援機 crash而前端機沒有的話就可以用的到..... +雖然這應該是很奇怪的事情 -____-!# + +如果 serial console 還是不能解決妳的問題的話, +也許妳可以考慮接一個遠端 reboot 的裝置. +我說的是妳可以下指令給後援機, +當她去 short前端機 motherboard上的 reset pin(s) +醬子當然是很暴力的做法, +不過在某些情況下確實有醬子惡搞的必要就是了~ ;p +我當然不會告訴妳我們到底有沒有遠端 reboot 的系統, +不過我可以偷偷告訴妳, 我們有用 serial console. + +唔 @"@ +我當然不會把這篇寫的很好笑或是一點都一正經, +不過我可以偷偷告訴妳, +竟然有人說我上次寫的那篇很好玩 -_______________-!# + +-- +  ▂▅▇▇▅   裺嘵○ 摃丐丐片    ▃ ◢◢  +  ▊ /    摃片裐朅 遉丐丐片歈 歈稙裐遉丐片  ◢ ▃  ██  +  ▎ ◤◢█◤  裺稙潁矙 聝丐丐片/裐歈朅裐═ ◥◤▌◢◢◢  +  ▌ ▎◣ ◢▎ 矙矙矙矙 ══煍片/ 矙僓朅禊歈屣片  ◢ ◣   +  ◣        潁 ═嘵嘵 矙矙裺朅潁裺屣丑  _ '_ ' _   + ◢█\ ‾◤    裺潁  ◥ ▼ \◤  + +-- +※ 發信站: 新批踢踢(ptt2.cc) +◆ From: 140.112.30.143 +→ windsheep:看到最後才發現好像比第一篇還好笑..^^ 推140.112.182.151 10/22 -- cgit v1.2.3 From b948b023854eea7c78a9d58228eb1ffdbc942fd7 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Fri, 8 Nov 2002 21:12:58 +0000 Subject: Linux compatible git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@566 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/docs/FAQ | 5 +++++ pttbbs/docs/INSTALL | 1 + pttbbs/include/bbs.h | 11 +++++++++-- pttbbs/mbbsd/term.c | 6 +++++- 4 files changed, 20 insertions(+), 3 deletions(-) diff --git a/pttbbs/docs/FAQ b/pttbbs/docs/FAQ index 9faf6109..bd1f94e9 100644 --- a/pttbbs/docs/FAQ +++ b/pttbbs/docs/FAQ @@ -1,3 +1,8 @@ +使用 Linux, 在 compile的時候出如 Makefile:20: *** missing separator. Stop. +請安裝 pmake, 並將 make alias 成 pmake . +如: apt-get install pmake + alias make pmake + 加大 shared-memory: 如果您是用 FreeBSD, 請在 /boot/loader.conf 裡面加入 kern.ipc.shmmax=104857600 diff --git a/pttbbs/docs/INSTALL b/pttbbs/docs/INSTALL index 2cff5971..5afa900f 100644 --- a/pttbbs/docs/INSTALL +++ b/pttbbs/docs/INSTALL @@ -34,6 +34,7 @@ 8. 執行 cd pttbbs 9. 如果之前沒有設定過 pttbbs.conf 的話, 請 cp sample/pttbbs.conf pttbbs.conf 10. 修改 pttbbs.conf + * 如果您是用 Linux系統, 請先安裝 pmake, 然後將 make alias 成 pmake * 11. 執行 make OSTYPE=FreeBSD BBSHOME=/home/bbs all install (Linux使用者請把 "FreeBSD" 改成 "linux") 12. 如果是新架起來的站, 請執行 cd sample; make install diff --git a/pttbbs/include/bbs.h b/pttbbs/include/bbs.h index 9163656b..a83cd84f 100644 --- a/pttbbs/include/bbs.h +++ b/pttbbs/include/bbs.h @@ -28,7 +28,6 @@ #include <sys/types.h> #include <dirent.h> #include <sys/mman.h> -#include <machine/param.h> #include <sys/ipc.h> #include <sys/shm.h> #include <sys/sem.h> @@ -49,9 +48,17 @@ #ifndef INCLUDE_VAR_H #include "var.h" #endif + +/* os dependant include file, define */ #ifdef FreeBSD #include <machine/limits.h> -#else + #include <machine/param.h> +#endif +#ifdef Linux + #include <sys/param.h> #include <limits.h> + #define strlcpy(a,b,c) strncpy(a,b,c) + #define strlcat(a,b,c) strncat(a,b,c) #endif + #endif /* INCLUDE_BBS_H */ diff --git a/pttbbs/mbbsd/term.c b/pttbbs/mbbsd/term.c index ed112346..a0f83354 100644 --- a/pttbbs/mbbsd/term.c +++ b/pttbbs/mbbsd/term.c @@ -1,4 +1,4 @@ -/* $Id: term.c,v 1.10 2002/09/11 07:16:49 kcwu Exp $ */ +/* $Id: term.c,v 1.11 2002/11/08 21:12:58 in2 Exp $ */ #include "bbs.h" int tgetent(const char *bp, char *name); @@ -52,6 +52,7 @@ outcf(int ch) } #endif +#ifndef Linux static void term_resize(int sig) { @@ -84,11 +85,14 @@ term_resize(int sig) signal(SIGWINCH, term_resize); } +#endif int term_init() { +#ifndef Linux signal(SIGWINCH, term_resize); +#endif return YEA; } -- cgit v1.2.3 From 6df96b0d023d5e9acc05ac68d9ef4aef90e0296e Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Fri, 8 Nov 2002 21:16:25 +0000 Subject: remove mdclean, splitpasswd git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@567 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/.cvsignore | 2 - pttbbs/util/Makefile | 10 +---- pttbbs/util/mdclean.c | 98 ----------------------------------------------- pttbbs/util/splitpasswd.c | 32 ---------------- 4 files changed, 2 insertions(+), 140 deletions(-) delete mode 100644 pttbbs/util/mdclean.c delete mode 100644 pttbbs/util/splitpasswd.c diff --git a/pttbbs/util/.cvsignore b/pttbbs/util/.cvsignore index d33e906f..28defeaa 100644 --- a/pttbbs/util/.cvsignore +++ b/pttbbs/util/.cvsignore @@ -41,6 +41,4 @@ jungo bbsctl mandex shmctl -mdclean -splitpasswd indexuser diff --git a/pttbbs/util/Makefile b/pttbbs/util/Makefile index e3b2a783..8e0479e4 100644 --- a/pttbbs/util/Makefile +++ b/pttbbs/util/Makefile @@ -1,4 +1,4 @@ -# $Id: Makefile,v 1.21 2002/11/04 08:46:50 in2 Exp $ +# $Id: Makefile,v 1.22 2002/11/08 21:16:25 in2 Exp $ BBSHOME?=$(HOME) OSTYPE!=uname @@ -30,7 +30,7 @@ CPROGS= bbsmail BM_money post account birth deluserfile expire mandex\ poststat showboard antispam countalldice webgrep bbsrf\ initbbs outmail xchatd userlist tunepasswd buildir reaper shmsweep\ merge_passwd merge_board inndBM buildAnnounce rmuid \ - toplazyBM jungo toplazyBBM shmctl mdclean splitpasswd indexuser + toplazyBM jungo toplazyBBM shmctl indexuser PROGS= $(CPROGS) BM_money.sh backpasswd.sh mailog.sh opendice.sh\ openticket.sh stock.sh topsong.sh weather.sh stock.perl weather.perl\ @@ -162,12 +162,6 @@ bbsctl: bbsctl.c shmctl: shmctl.c $(OBJS) $(CC) $(CFLAGS) -o $@ $@.c $(OBJS) -mdclean: mdclean.c - $(CC) $(CFLAGS) -o $@ $@.c - -splitpasswd: splitpasswd.c - $(CC) $(CFLAGS) -o $@ $@.c - install: $(PROGS) install -d $(BBSHOME)/bin/ install -c -m 755 $(PROGS) $(BBSHOME)/bin/ diff --git a/pttbbs/util/mdclean.c b/pttbbs/util/mdclean.c deleted file mode 100644 index 196fc9ee..00000000 --- a/pttbbs/util/mdclean.c +++ /dev/null @@ -1,98 +0,0 @@ -#include <stdio.h> -#include <stdlib.h> -#include "config.h" -#include <sys/types.h> -#include <dirent.h> -#include <unistd.h> -#include <err.h> -#include <sys/types.h> -#include <sys/stat.h> -#include <sys/param.h> -#include <sys/mount.h> - -#define MAXDSs 1048576 - -typedef struct { - time_t atime; - char name[60]; -} DS; - -DS ds[MAXDSs]; -int nDSs; - -int compar(const void *a, const void *b) -{ - return ((DS *)a)->atime - ((DS *)b)->atime; -} - -int main(int argc, char **argv) -{ - DIR *dirp; - struct dirent *dp; - struct stat sb; - struct statfs sf; - char *fn; - time_t now; - int sleeptime, leavespace, clean; - - if( argc != 4 ){ - puts("usage:\tmdclean sleeptime(secs) leavespace(k) clean(%%)\n"); - return 0; - } - sleeptime = (atoi(argv[1]) < 1) ? 1 : atoi(argv[1]); - leavespace= (atoi(argv[2]) <100)?100: atoi(argv[2]); - clean = (atoi(argv[3]) < 1) ? 1 : atoi(argv[3]); - - if( chdir(BBSHOME "/cache") < 0 ) - err(1, "chdir"); - - while( 1 ){ - puts("sleeping..."); - sleep(sleeptime); - if( (dirp = opendir(".")) == NULL ) - err(1, "opendir"); - - statfs(".", &sf); - if( sf.f_bfree * sf.f_bsize / 1024 > leavespace ) - continue; - - nDSs = 0; - now = time(NULL); - while( (dp = readdir(dirp)) != NULL ){ - fn = dp->d_name; - if( fn[0] != 'e' && fn[0] != 'b' ){ - unlink(fn); - continue; - } - if( stat(fn, &sb) < 0 ) - continue; - if( sb.st_atime < now - 1800 ){ - printf("atime: %s\n", fn); - unlink(fn); - } - else if( sb.st_mtime < now - 10800 ){ - printf("mtime: %s\n", fn); - unlink(fn); - } - else{ - if( nDSs != MAXDSs ){ - strcpy(ds[nDSs].name, fn); - ds[nDSs].atime = sb.st_atime; - ++nDSs; - } - } - } - closedir(dirp); - - statfs(".", &sf); - if( sf.f_bfree * sf.f_bsize / 1024 <= leavespace ){ - qsort(ds, nDSs, sizeof(DS), compar); - nDSs = nDSs * clean / 100; - while( nDSs-- ){ - printf("%s\n", ds[nDSs].name); - unlink(ds[nDSs].name); - } - } - } - return 0; -} diff --git a/pttbbs/util/splitpasswd.c b/pttbbs/util/splitpasswd.c deleted file mode 100644 index 1a800f6c..00000000 --- a/pttbbs/util/splitpasswd.c +++ /dev/null @@ -1,32 +0,0 @@ -#include "bbs.h" -#include <err.h> - -int main(int argc, char **argv) -{ - userec_t xuser; - int fd, ufd; - char path[80], fn[80]; - - chdir(BBSHOME); - if( (fd = open(".PASSWDS", O_RDONLY)) < 0 ) - err(1, ".PASSWDS"); - - while( read(fd, &xuser, sizeof(xuser)) > 0 ){ - if( strcmp(xuser.userid, "in2") != 0 ) - continue; - sprintf(path, "home/%c/%s", xuser.userid[0], xuser.userid); - if( access(path, 0) < 0 ){ - printf("user home error (%s) (%s)\n", xuser.userid, path); - continue; - } - sprintf(fn, "%s/.passwd", path); - if( (ufd = open(fn, O_WRONLY | O_CREAT, 0600)) < 0 ){ - perror(path); - continue; - } - write(ufd, &xuser, sizeof(xuser)); - close(ufd); - } - - return 0; -} -- cgit v1.2.3 From a452530f13fb16ab02b2fb7c0da22e0d16e6b8da Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Fri, 8 Nov 2002 21:18:23 +0000 Subject: Linux compatible git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@568 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/bbsctl.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pttbbs/util/bbsctl.c b/pttbbs/util/bbsctl.c index 9618f5de..998cd98c 100644 --- a/pttbbs/util/bbsctl.c +++ b/pttbbs/util/bbsctl.c @@ -183,6 +183,7 @@ int bbstest(int argc, char **argv) int Xipcrm(int argc, char **argv) { +#ifdef FreeBSD char buf[256], cmd[256]; FILE *fp; sprintf(buf, IPCS " | " AWK " '{print $1 $2}'"); @@ -200,6 +201,10 @@ int Xipcrm(int argc, char **argv) pclose(fp); system(IPCS); return 0; +#else + puts("not implement!"); + return 1; +#endif } int permreport(int argc, char **argv) -- cgit v1.2.3 From cd043e35bea77be54d476a6ac3bc843eaea8b11f Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sun, 10 Nov 2002 17:25:34 +0000 Subject: inc shared-memory git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@569 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/docs/FAQ | 9 ++++++++- pttbbs/docs/INSTALL | 6 ++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/pttbbs/docs/FAQ b/pttbbs/docs/FAQ index bd1f94e9..57430991 100644 --- a/pttbbs/docs/FAQ +++ b/pttbbs/docs/FAQ @@ -4,12 +4,19 @@ alias make pmake 加大 shared-memory: -如果您是用 FreeBSD, 請在 /boot/loader.conf 裡面加入 +in FreeBSD: +請在 /boot/loader.conf 裡面加入 kern.ipc.shmmax=104857600 kern.ipc.shmall=25600 這兩個數值可視須要調整, 在重新開機後會生效. +in Linux: +法一: 用 sysctl 改 kernel.shmmax +法二: 在 kernel source找出 (可用 grep -R ) + #define SHMMAX 將其加大 + 重新 make kernel並且 reboot + 作者 DavidYu (軱~~~~~~~~~~) 看板 PttSrc 標題 sendmail.cf要改的地方(參考用) 時間 Sun Jul 9 09:39:53 2000 diff --git a/pttbbs/docs/INSTALL b/pttbbs/docs/INSTALL index 5afa900f..4ebd5a0d 100644 --- a/pttbbs/docs/INSTALL +++ b/pttbbs/docs/INSTALL @@ -58,8 +58,10 @@ new 2. 如果您跑了 uhash_loader 並沒有看到 total XXXXX names loaded. - 而是看到其他的錯誤訊息, 可能是您作業系統 shared-memory 上限不足, - 請參考 FAQ第一部份加大 shared-memory. + 而是看到其他的錯誤訊息 + (例如 [shmget error] key = 4cc, errno = 22: Invalid argument) + 可能是您作業系統 shared-memory 上限不足, + 請參考 FAQ中加大 shared-memory 部份的說明. 3. bin/mbbsd 23 是指定要 bind 23 port, 依照 UNIX 規定, 1024 以下的 port 須要有 root 權限, 所以如果要 bind 23 port 的話就要用 root 去執行, -- cgit v1.2.3 From 6cd67a42dd883db9aa234143c58a5447756b1cc3 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Mon, 11 Nov 2002 02:58:52 +0000 Subject: doc git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@570 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/docs/INSTALL | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pttbbs/docs/INSTALL b/pttbbs/docs/INSTALL index 4ebd5a0d..448e09f5 100644 --- a/pttbbs/docs/INSTALL +++ b/pttbbs/docs/INSTALL @@ -65,4 +65,7 @@ new 3. bin/mbbsd 23 是指定要 bind 23 port, 依照 UNIX 規定, 1024 以下的 port 須要有 root 權限, 所以如果要 bind 23 port 的話就要用 root 去執行, - 3000 port 則不需要 + 3000 port 則不需要. + 請參考 docs/ADVANCE , 安裝好 bbsctl , + 之後您就可以透過 bbsctl 直接在其他權限下 (如 bbsadm ) + 來啟動可以 bind port 23 的 mbbsd. -- cgit v1.2.3 From 0385ac6b36473eb38257f52ed8b9ada106a049d7 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Mon, 11 Nov 2002 03:06:03 +0000 Subject: move error board to boards.error/ git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@571 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/expire.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/pttbbs/util/expire.c b/pttbbs/util/expire.c index 50c568da..30e9ab2f 100644 --- a/pttbbs/util/expire.c +++ b/pttbbs/util/expire.c @@ -1,4 +1,4 @@ -/* $Id: expire.c,v 1.5 2002/11/06 12:07:59 in2 Exp $ */ +/* $Id: expire.c,v 1.6 2002/11/11 03:06:03 in2 Exp $ */ /* 自動砍信工具程式 */ #include "bbs.h" @@ -39,7 +39,11 @@ life *brd; if((bid = getbnum(brd->bname)) == 0 || strcmp(brd->bname, bcache[bid-1].brdname)) { - printf("no such board?: %s\n", brd->bname); + char cmd[1024]; + printf("no such board?: %s\n", brd->bname); + sprintf(cmd, "mv %s/boards/%c/%s %s/boards.error/%s", + BBSHOME, brd->bname[0], brd->bname, BBSHOME, brd->bname); + system(cmd); return; } #ifdef VERBOSE -- cgit v1.2.3 From 73f60759a83b8f549a70805ab59d6791d69fae0a Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Thu, 14 Nov 2002 13:55:26 +0000 Subject: join bbsadm group in bbsctl git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@572 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/docs/ADVANCE | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/pttbbs/docs/ADVANCE b/pttbbs/docs/ADVANCE index 118b8aae..c1e8d8f2 100644 --- a/pttbbs/docs/ADVANCE +++ b/pttbbs/docs/ADVANCE @@ -6,9 +6,33 @@ bbsctl bbsctl是一個很特別的程式, 安裝有點複雜. 1.先用 bbsadm 的權限在 util/下 make bbsctl 2.改成 root 的權限在 util/下 make installbbsctl -如此會把 bbsctl 安裝到 /usr/local/bin 下, 以方便在任何目錄下皆可使用. +如此會把 bbsctl 安裝到 $(BBSHOME)/bin/bbsctl下. +我們會建議您將 bbsctl 所在目錄加進您的 path 裡面, +或是建立 symbolic link把 bbsctl 放到一個有設 path 的目錄 + (像是 /usr/local/bin 將是一個符合 FreeBSD程式置放路徑的目錄) +您可以用 ln -s $(BBSHOME)/bbs/bbsctl /usr/local/bin/bbsctl + (其中 $(BBSHOME) 請用您所設的 bbs路徑代替, 如 /home/bbs) +如此您將可以在任何一個目錄下使用 bbsctl + + !!請注意, bbsctl 是有 root setuid的, 這可能會有安全上的問題!! + +其中 bbsctl 設計是只有該帳號有加入 bbsadm 這個 group的人才能使用. +以 FreeBSD為例, 您須要更動 /etc/group 這個檔案, + /etc/group 的語法是: + group:passwd:gid:member + + group是該 group的名字, + passwd一般情況下不設, 以 *代替, + gid 為一個十進位的數字, 最好不要和其他的重複, + member為哪些人有在該群組內, 以逗號 (,)隔開. +詳細用法請見group(5) +例如您要將 aaa, bbb 加入 bbsadm 這個 group, 您可能會用: + bbsadm:*:9876:aaa,bbb +您應該至少要將 bbs和 bbsadm 這兩個帳號加入 bbsadm 這個 group + + 您可以直接打 bbsctl 來看有什麼功能. 主要的功能說明如下: 1.bbsctl start -- cgit v1.2.3 From c8c598045c5142fd413909728e074609d824b851 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Thu, 14 Nov 2002 13:59:26 +0000 Subject: /etc/group git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@573 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/docs/ADVANCE | 12 +----------- pttbbs/docs/FAQ | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/pttbbs/docs/ADVANCE b/pttbbs/docs/ADVANCE index c1e8d8f2..352cad36 100644 --- a/pttbbs/docs/ADVANCE +++ b/pttbbs/docs/ADVANCE @@ -19,17 +19,7 @@ bbsctl 其中 bbsctl 設計是只有該帳號有加入 bbsadm 這個 group的人才能使用. -以 FreeBSD為例, 您須要更動 /etc/group 這個檔案, - /etc/group 的語法是: - group:passwd:gid:member - - group是該 group的名字, - passwd一般情況下不設, 以 *代替, - gid 為一個十進位的數字, 最好不要和其他的重複, - member為哪些人有在該群組內, 以逗號 (,)隔開. -詳細用法請見group(5) -例如您要將 aaa, bbb 加入 bbsadm 這個 group, 您可能會用: - bbsadm:*:9876:aaa,bbb + (關於如何設定 group請見 FAQ) 您應該至少要將 bbs和 bbsadm 這兩個帳號加入 bbsadm 這個 group diff --git a/pttbbs/docs/FAQ b/pttbbs/docs/FAQ index 57430991..deae4001 100644 --- a/pttbbs/docs/FAQ +++ b/pttbbs/docs/FAQ @@ -3,6 +3,8 @@ 如: apt-get install pmake alias make pmake +─────────────────────────────────────── + 加大 shared-memory: in FreeBSD: 請在 /boot/loader.conf 裡面加入 @@ -17,6 +19,23 @@ in Linux: #define SHMMAX 將其加大 重新 make kernel並且 reboot +─────────────────────────────────────── +設定 group +以 FreeBSD為例, 您須要更動 /etc/group 這個檔案, + /etc/group 的語法是: + group:passwd:gid:member + + group是該 group的名字, + passwd一般情況下不設, 以 *代替, + gid 為一個十進位的數字, 最好不要和其他的重複, + member為哪些人有在該群組內, 以逗號 (,)隔開. +詳細用法請見group(5) +例如您要將 aaa, bbb 加入 bbsadm 這個 group, 您可能會用: + bbsadm:*:9876:aaa,bbb +在設定完成後, 原來已經登入的使用者須要重新登入, +才會重新載入至新設的 group內. + + 作者 DavidYu (軱~~~~~~~~~~) 看板 PttSrc 標題 sendmail.cf要改的地方(參考用) 時間 Sun Jul 9 09:39:53 2000 -- cgit v1.2.3 From 74944ca99f6660037a871b63ec4318001a388f6b Mon Sep 17 00:00:00 2001 From: lwms <lwms@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Fri, 15 Nov 2002 05:56:10 +0000 Subject: remove post_violatelaw to Security git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@574 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/syspost.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pttbbs/mbbsd/syspost.c b/pttbbs/mbbsd/syspost.c index 0a527f22..36939485 100644 --- a/pttbbs/mbbsd/syspost.c +++ b/pttbbs/mbbsd/syspost.c @@ -1,4 +1,4 @@ -/* $Id: syspost.c,v 1.15 2002/07/22 19:02:00 in2 Exp $ */ +/* $Id: syspost.c,v 1.16 2002/11/15 05:56:10 lwms Exp $ */ #include "bbs.h" void @@ -50,6 +50,7 @@ post_violatelaw(char *crime, char *police, char *reason, char *result) char genbuf[200]; fileheader_t fhdr; FILE *fp; +/* strlcpy(genbuf, "boards/S/Security", sizeof(genbuf)); stampfile(genbuf, &fhdr); if (!(fp = fopen(genbuf, "w"))) @@ -66,6 +67,7 @@ post_violatelaw(char *crime, char *police, char *reason, char *result) strlcpy(fhdr.owner, "[Ptt法院]", sizeof(fhdr.owner)); append_record("boards/S/Security/.DIR", &fhdr, sizeof(fhdr)); +*/ strlcpy(genbuf, "boards/V/ViolateLaw", sizeof(genbuf)); stampfile(genbuf, &fhdr); if (!(fp = fopen(genbuf, "w"))) -- cgit v1.2.3 From 33e2d90fcc75e6089066fdd81402f43b96d0a63b Mon Sep 17 00:00:00 2001 From: kcwu <kcwu@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sat, 16 Nov 2002 13:41:07 +0000 Subject: =?UTF-8?q?show=20=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD?= =?UTF-8?q?=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD?= =?UTF-8?q?=20in=20user=20list?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@575 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/include/pttstruct.h | 5 ++++- pttbbs/mbbsd/cache.c | 14 +++++++++++++- pttbbs/mbbsd/chc_play.c | 5 ++++- pttbbs/mbbsd/mbbsd.c | 5 ++++- pttbbs/mbbsd/talk.c | 18 ++++++++++++------ 5 files changed, 37 insertions(+), 10 deletions(-) diff --git a/pttbbs/include/pttstruct.h b/pttbbs/include/pttstruct.h index 7d546415..29984823 100644 --- a/pttbbs/include/pttstruct.h +++ b/pttbbs/include/pttstruct.h @@ -1,4 +1,4 @@ -/* $Id: pttstruct.h,v 1.26 2002/11/07 09:13:23 in2 Exp $ */ +/* $Id: pttstruct.h,v 1.27 2002/11/16 13:41:06 kcwu Exp $ */ #ifndef INCLUDE_STRUCT_H #define INCLUDE_STRUCT_H @@ -243,6 +243,9 @@ typedef struct userinfo_t { unsigned short int five_win; unsigned short int five_lose; unsigned short int five_tie; + unsigned short int chc_win; + unsigned short int chc_lose; + unsigned short int chc_tie; int mailalert; int sex; char color; diff --git a/pttbbs/mbbsd/cache.c b/pttbbs/mbbsd/cache.c index ff3a8340..1289dd51 100644 --- a/pttbbs/mbbsd/cache.c +++ b/pttbbs/mbbsd/cache.c @@ -1,4 +1,4 @@ -/* $Id: cache.c,v 1.52 2002/10/23 17:10:04 in2 Exp $ */ +/* $Id: cache.c,v 1.53 2002/11/16 13:41:07 kcwu Exp $ */ #include "bbs.h" #ifndef __FreeBSD__ @@ -373,6 +373,17 @@ cmputmpfive(const void *i, const void *j) return (*((userinfo_t **) i))->five_tie - (*((userinfo_t **) j))->five_tie; } +static int +cmputmpchc(const void *i, const void *j) +{ + int type; + if ((type = (*((userinfo_t **) j))->chc_win - (*((userinfo_t **) i))->chc_win)) + return type; + if ((type = (*((userinfo_t **) i))->chc_lose - (*((userinfo_t **) j))->chc_lose)) + return type; + return (*((userinfo_t **) i))->chc_tie - (*((userinfo_t **) j))->chc_tie; +} + static int cmputmppid(const void *i, const void *j) { @@ -422,6 +433,7 @@ sort_utmp() qsort(SHM->sorted[ns][2], count, sizeof(userinfo_t *), cmputmpidle); qsort(SHM->sorted[ns][3], count, sizeof(userinfo_t *), cmputmpfrom); qsort(SHM->sorted[ns][4], count, sizeof(userinfo_t *), cmputmpfive); + qsort(SHM->sorted[ns][5], count, sizeof(userinfo_t *), cmputmpchc); qsort(SHM->sorted[ns][6], count, sizeof(userinfo_t *), cmputmpuid); qsort(SHM->sorted[ns][7], count, sizeof(userinfo_t *), cmputmppid); SHM->currsorted = ns; diff --git a/pttbbs/mbbsd/chc_play.c b/pttbbs/mbbsd/chc_play.c index 74a9aadb..08eead20 100644 --- a/pttbbs/mbbsd/chc_play.c +++ b/pttbbs/mbbsd/chc_play.c @@ -1,4 +1,4 @@ -/* $Id: chc_play.c,v 1.6 2002/07/21 09:26:02 in2 Exp $ */ +/* $Id: chc_play.c,v 1.7 2002/11/16 13:41:07 kcwu Exp $ */ #include "bbs.h" typedef int (*play_func_t) (int, board_t, board_t); @@ -201,12 +201,15 @@ mainloop(int s, board_t board) if (endgame == 1) { strlcpy(chc_warnmsg, "對方認輸了!", sizeof(chc_warnmsg)); cuser.chc_win++; + currutmp->chc_win++; } else if (endgame == 2) { strlcpy(chc_warnmsg, "你認輸了!", sizeof(chc_warnmsg)); cuser.chc_lose++; + currutmp->chc_lose++; } else { strlcpy(chc_warnmsg, "和棋", sizeof(chc_warnmsg)); cuser.chc_tie++; + currutmp->chc_tie++; } cuser.chc_lose--; passwd_update(usernum, &cuser); diff --git a/pttbbs/mbbsd/mbbsd.c b/pttbbs/mbbsd/mbbsd.c index 0adb2756..0f2cd58f 100644 --- a/pttbbs/mbbsd/mbbsd.c +++ b/pttbbs/mbbsd/mbbsd.c @@ -1,4 +1,4 @@ -/* $Id: mbbsd.c,v 1.58 2002/09/26 16:18:36 in2 Exp $ */ +/* $Id: mbbsd.c,v 1.59 2002/11/16 13:41:07 kcwu Exp $ */ #include "bbs.h" #define SOCKET_QLEN 4 @@ -723,6 +723,9 @@ setup_utmp(int mode) uinfo.five_win = cuser.five_win; uinfo.five_lose = cuser.five_lose; uinfo.five_tie = cuser.five_tie; + uinfo.chc_win = cuser.chc_win; + uinfo.chc_lose = cuser.chc_lose; + uinfo.chc_tie = cuser.chc_tie; uinfo.invisible = cuser.invisible % 2; uinfo.pager = cuser.pager % 5; memcpy(uinfo.mind, cuser.mind, 4); diff --git a/pttbbs/mbbsd/talk.c b/pttbbs/mbbsd/talk.c index 52f35173..76c1276f 100644 --- a/pttbbs/mbbsd/talk.c +++ b/pttbbs/mbbsd/talk.c @@ -1,4 +1,4 @@ -/* $Id: talk.c,v 1.94 2002/09/20 13:37:46 in2 Exp $ */ +/* $Id: talk.c,v 1.95 2002/11/16 13:41:07 kcwu Exp $ */ #include "bbs.h" #define QCAST int (*)(const void *, const void *) @@ -10,7 +10,7 @@ static char *sig_des[] = { "鬥雞", "聊天", "", "下棋", "象棋", "暗棋" }; -#define MAX_SHOW_MODE 3 +#define MAX_SHOW_MODE 4 #define M_INT 15 /* monitor mode update interval */ #define P_INT 20 /* interval to check for page req. in * talk/chat */ @@ -31,7 +31,7 @@ typedef struct pickup_t { /* 記錄 friend 的 user number */ // -#define PICKUP_WAYS 6 +#define PICKUP_WAYS 7 static char *fcolor[11] = { "", "\033[36m", "\033[32m", "\033[1;32m", @@ -1457,6 +1457,12 @@ descript(int show_mode, userinfo_t * uentp, time_t diff) uentp->five_lose, uentp->five_tie); description[20] = 0; return description; + case 3: + snprintf(description, sizeof(description), + "%3d/%3d/%3d", uentp->chc_win, + uentp->chc_lose, uentp->chc_tie); + description[20] = 0; + return description; default: syslog(LOG_WARNING, "damn!!! what's wrong?? show_mode = %d", show_mode); @@ -1622,10 +1628,10 @@ draw_pickup(int drawall, pickup_t * pickup, int pickup_way, int show_pid, int myfriend, int friendme, int bfriend, int badfriend) { char *msg_pickup_way[PICKUP_WAYS] = { - "嗨! 朋友", "網友代號", "網友動態", "發呆時間", "來自何方", "五子棋 " + "嗨! 朋友", "網友代號", "網友動態", "發呆時間", "來自何方", " 五子棋 ", " 象棋 " }; char *MODE_STRING[MAX_SHOW_MODE] = { - "故鄉", "好友描述", "五子棋戰績" + "故鄉", "好友描述", "五子棋戰績", "象棋戰績" }; char pagerchar[5] = "* -Wf"; @@ -2089,7 +2095,7 @@ userlist(void) break; case 'S': /* 顯示好友描述 */ - show_mode = (++show_mode) % MAX_SHOW_MODE; + show_mode = (show_mode+1) % MAX_SHOW_MODE; redrawall = redraw = 1; break; -- cgit v1.2.3 From e07f3d0a84b85285057d047077395b61fd1b37ba Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sun, 17 Nov 2002 05:06:20 +0000 Subject: some comment in mail body git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@576 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/waterball.pl | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/pttbbs/util/waterball.pl b/pttbbs/util/waterball.pl index 2cfa2a61..05d59999 100644 --- a/pttbbs/util/waterball.pl +++ b/pttbbs/util/waterball.pl @@ -44,13 +44,21 @@ foreach $fndes ( <$JOBSPOOL/water.des.*> ){ #des: userid, mailto, outmode unlink $fndes; } else{ + my $body = + "親愛的使用者您好:\n\n". + "歡迎您使用 Ptt系列的水球整理功能 ^_^\n". + "水球整理的結果被壓縮好附加在本信中\n". + "您須要先將其解壓縮 (如用 tar+gunzip, winzip 等程式)\n". + "解出來的檔案為純文字格式, \n". + "您可以透過任何純文字編輯程式 (如 emacs, notepad, word)\n". + "打開它進行編輯整理\n\n". + "再次感謝您使用本系統以及對 $hostname 的支持 ^^\n". + "\n $hostname 站長群 ". POSIX::ctime(time()); if( MakeMail({tartarget => "$TMP/$userid.waterball.tgz", tarsource => "*", mailto => "$userid <$mailto>", subject => "水球紀錄", - body => - "\n $hostname 站長群 ". POSIX::ctime(time())} - ) ){ + body => $body}) ){ unlink $fnsrc; unlink $fndes; } -- cgit v1.2.3 From ad7a6a0b3c67bf3c4f781c3af4bb298682e5709e Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Wed, 20 Nov 2002 02:07:51 +0000 Subject: =?UTF-8?q?s/=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD\&\#22531\;/?= =?UTF-8?q?=EF=BF=BD=EF=BF=BD=EF=BF=BD}/g;?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@577 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/udnnews.pl | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/pttbbs/util/udnnews.pl b/pttbbs/util/udnnews.pl index 4d37a26a..5e19ae88 100644 --- a/pttbbs/util/udnnews.pl +++ b/pttbbs/util/udnnews.pl @@ -20,11 +20,20 @@ chdir '/home/bbs'; getudnnewstitle(\@titles); foreach( @titles ){ postout({brdname => 'udnnews', - title => FormatChinese($_->[1]), + title => strreplace(FormatChinese($_->[1])), owner => 'udnnews.', content => getudnnewscontent("http://www.udn.com/NEWS/FOCUSNEWS/$_->[0]")}); } +sub strreplace +{ + my($str) = @_; + $str =~ s/十/十/g; + $str =~ s/卅/卅/g; + $str =~ s/游錫\&\#22531\;/游揆/g; + return $str; +} + sub getudnnewscontent($) { my($url) = @_; @@ -38,8 +47,7 @@ sub getudnnewscontent($) $content =~ s/\r//g; $content =~ s/\n\n\n/\n\n/g; $content =~ s/\n\n\n//g; - $content =~ s/十/十/g; - $content =~ s/卅/卅/g; + $content = strreplace($content); undef $ret; foreach( split(/\n/, $content) ){ s/ //g; -- cgit v1.2.3 From a4acf169cd59dc0f22b724ad098706bd06e6ab98 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Fri, 22 Nov 2002 17:44:48 +0000 Subject: change shared-memory setting in /etc/sysctl.conf git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@578 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/docs/FAQ | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pttbbs/docs/FAQ b/pttbbs/docs/FAQ index deae4001..a96d0f86 100644 --- a/pttbbs/docs/FAQ +++ b/pttbbs/docs/FAQ @@ -7,7 +7,7 @@ 加大 shared-memory: in FreeBSD: -請在 /boot/loader.conf 裡面加入 +請在 /etc/sysctl.conf 裡面加入 kern.ipc.shmmax=104857600 kern.ipc.shmall=25600 這兩個數值可視須要調整, -- cgit v1.2.3 From d24c0cf9f810b9ec03a9bf4f8ca93b5f75f1c0e9 Mon Sep 17 00:00:00 2001 From: ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sat, 23 Nov 2002 04:15:30 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@579 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/edit.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pttbbs/mbbsd/edit.c b/pttbbs/mbbsd/edit.c index f560167d..0d77f9a8 100644 --- a/pttbbs/mbbsd/edit.c +++ b/pttbbs/mbbsd/edit.c @@ -1,4 +1,4 @@ -/* $Id: edit.c,v 1.21 2002/11/06 16:25:15 in2 Exp $ */ +/* $Id: edit.c,v 1.22 2002/11/23 04:15:30 ptt Exp $ */ #include "bbs.h" typedef struct textline_t { struct textline_t *prev; @@ -1647,7 +1647,7 @@ vedit(char *fpath, int saveheader, int *islocal) count = 0; tin = interval; } - /* 連續240個interval一樣 , 分明是在斂財 */ + /* 連續240個interval一樣 , 分明是在斂財 if (count >= 240) { snprintf(buf, sizeof(buf), "\033[1;33;46m%s\033[37m在\033[37;45m%s" "\033[37m板違法賺錢 , %s\033[m", cuser.userid, @@ -1656,9 +1656,9 @@ vedit(char *fpath, int saveheader, int *islocal) money = 0; post_violatelaw(cuser.userid, "Ptt 系統警察", "違法賺錢", "扣除不法所得"); mail_violatelaw(cuser.userid, "Ptt 系統警察", "違法賺錢", "扣除不法所得"); - //demoney(10000); - //abort_bbs(0); - } + demoney(10000); + abort_bbs(0); + } */ if (raw_mode) switch (ch) { case Ctrl('S'): -- cgit v1.2.3 From 4cf706eefce88b66f76f142a079bc5cd4d463626 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sat, 30 Nov 2002 04:51:13 +0000 Subject: reject for registering userid containing shit or fuck git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@580 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/register.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pttbbs/mbbsd/register.c b/pttbbs/mbbsd/register.c index 5ef02f4a..a138a4c3 100644 --- a/pttbbs/mbbsd/register.c +++ b/pttbbs/mbbsd/register.c @@ -1,4 +1,4 @@ -/* $Id: register.c,v 1.9 2002/07/22 19:02:00 in2 Exp $ */ +/* $Id: register.c,v 1.10 2002/11/30 04:51:13 in2 Exp $ */ #define _XOPEN_SOURCE #include "bbs.h" @@ -60,6 +60,10 @@ bad_user_id(char *userid) if (strcasecmp(userid, str_new) == 0) return 1; + if (strcasestr(userid, "fuck") != NULL || + strcasestr(userid, "shit") != NULL ) + return 1; + /* * while((ch = *(++userid))) if(not_alnum(ch)) return 1; */ -- cgit v1.2.3 From 51a1858e75305e33c87ea12e1dd9a39040c0cca8 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Wed, 4 Dec 2002 10:14:07 +0000 Subject: fix bug git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@581 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/talk.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pttbbs/mbbsd/talk.c b/pttbbs/mbbsd/talk.c index 76c1276f..af88bc01 100644 --- a/pttbbs/mbbsd/talk.c +++ b/pttbbs/mbbsd/talk.c @@ -1,4 +1,4 @@ -/* $Id: talk.c,v 1.95 2002/11/16 13:41:07 kcwu Exp $ */ +/* $Id: talk.c,v 1.96 2002/12/04 10:14:07 in2 Exp $ */ #include "bbs.h" #define QCAST int (*)(const void *, const void *) @@ -669,7 +669,7 @@ my_write(pid_t pid, char *prompt, char *id, int flag, userinfo_t * puin) strlcpy(uin->msgs[uin->msgcount].userid, cuser.userid, sizeof(uin->msgs[uin->msgcount].userid)); strlcpy(uin->msgs[uin->msgcount++].last_call_in, msg, - sizeof(uin->msgs[uin->msgcount++].last_call_in)); + sizeof(uin->msgs[uin->msgcount].last_call_in)); uin->pager = pager0; } else if (flag != 2) outmsg("\033[1;33;41m糟糕! 對方不行了! (收到太多水球) \033[37m@_@\033[m"); -- cgit v1.2.3 From f5295530478fb9bfb615caf2bd62def21c95e34b Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Thu, 5 Dec 2002 12:37:00 +0000 Subject: register git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@582 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/user.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pttbbs/mbbsd/user.c b/pttbbs/mbbsd/user.c index 6e51a9fa..3bb78601 100644 --- a/pttbbs/mbbsd/user.c +++ b/pttbbs/mbbsd/user.c @@ -1,4 +1,4 @@ -/* $Id: user.c,v 1.40 2002/10/26 00:12:52 in2 Exp $ */ +/* $Id: user.c,v 1.41 2002/12/05 12:37:00 in2 Exp $ */ #include "bbs.h" static char *sex[8] = { @@ -762,7 +762,8 @@ ispersonalid(char *inid) return 0; id[0] = toupper(id[0]); - if( strcmp(id, "A100000001") == 0 ) + if( strcmp(id, "A100000001") == 0 || + strcmp(id, "A200000003") == 0 ) return 0; /* A->10, B->11, ..H->17,I->34, J->18... */ while (lst[i] != id[0]) -- cgit v1.2.3 From 85d4ba956b81029752935f145171c986ee082e2a Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Tue, 10 Dec 2002 11:59:02 +0000 Subject: after setup_utmp(), renice to +5. to let system faver the processes which are listening or setup_utmp()ing git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@583 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/mbbsd.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pttbbs/mbbsd/mbbsd.c b/pttbbs/mbbsd/mbbsd.c index 0f2cd58f..9cfb91d2 100644 --- a/pttbbs/mbbsd/mbbsd.c +++ b/pttbbs/mbbsd/mbbsd.c @@ -1,4 +1,4 @@ -/* $Id: mbbsd.c,v 1.59 2002/11/16 13:41:07 kcwu Exp $ */ +/* $Id: mbbsd.c,v 1.60 2002/12/10 11:59:02 in2 Exp $ */ #include "bbs.h" #define SOCKET_QLEN 4 @@ -745,6 +745,7 @@ setup_utmp(int mode) getnewutmpent(&uinfo); #ifndef _BBS_UTIL_C_ friend_load(); + nice(3); #endif } -- cgit v1.2.3 From 2170afe2abd1fa75825740fd4ce72fe86683836f Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Tue, 10 Dec 2002 12:06:19 +0000 Subject: change help content git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@584 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/board.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pttbbs/mbbsd/board.c b/pttbbs/mbbsd/board.c index c7c84262..ebb4e851 100644 --- a/pttbbs/mbbsd/board.c +++ b/pttbbs/mbbsd/board.c @@ -1,4 +1,4 @@ -/* $Id: board.c,v 1.61 2002/09/26 16:24:38 in2 Exp $ */ +/* $Id: board.c,v 1.62 2002/12/10 12:06:19 in2 Exp $ */ #include "bbs.h" #define BRC_STRLEN 15 /* Length of board name */ #define BRC_MAXSIZE 24576 @@ -705,8 +705,8 @@ static char *choosebrdhelp[] = { "(y) 我的最愛/訂閱\看板/出所有看板", "(v/V) 通通看完/全部未讀", "(S) 按照字母/分類排序", - "(t/^T/^A/^D) 標記看板/取消所有標記/已標記的加入我的最愛/取消我的最愛", - "(m) 把看板加入我的最愛", + "(t/^T/^A/^D) 標記看板/取消所有標記/ 將已標記者加入/移出我的最愛", + "(m) 把看板加入或移出我的最愛", "\01小組長指令", "(E/W/B) 設定看板/設定小組備忘/開新看板", "(^P) 移動已標記看板到此分類", -- cgit v1.2.3 From f556b681c9a1222a5c5a63c39b9be70f7ee2646d Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sat, 14 Dec 2002 08:02:18 +0000 Subject: remove personal id from userinfo git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@585 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/user.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/pttbbs/mbbsd/user.c b/pttbbs/mbbsd/user.c index 3bb78601..d3501822 100644 --- a/pttbbs/mbbsd/user.c +++ b/pttbbs/mbbsd/user.c @@ -1,4 +1,4 @@ -/* $Id: user.c,v 1.41 2002/12/05 12:37:00 in2 Exp $ */ +/* $Id: user.c,v 1.42 2002/12/14 08:02:18 in2 Exp $ */ #include "bbs.h" static char *sex[8] = { @@ -61,12 +61,11 @@ user_display(userec_t * u, int real) sethomedir(genbuf, u->userid); prints(" 私人信箱: %d 封 (購買信箱: %d 封)\n" - " 身分證號: %s\n" " 手機號碼: %010d\n" " 生 日: %02i/%02i/%02i\n" " 小雞名字: %s\n", get_num_records(genbuf, sizeof(fileheader_t)), - u->exmailbox, u->ident, u->mobile, + u->exmailbox, u->mobile, u->month, u->day, u->year % 100, u->mychicken.name); prints(" 註冊日期: %s", ctime(&u->firstlogin)); prints(" 前次光臨: %s", ctime(&u->lastlogin)); -- cgit v1.2.3 From 596f84066e076f9a9cc134f0f0aa7d209e2c40d7 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Tue, 24 Dec 2002 08:20:15 +0000 Subject: fix buffer overflow in oldgetdata() git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@586 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/io.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/pttbbs/mbbsd/io.c b/pttbbs/mbbsd/io.c index 84683ce8..aa6e525b 100644 --- a/pttbbs/mbbsd/io.c +++ b/pttbbs/mbbsd/io.c @@ -1,4 +1,4 @@ -/* $Id: io.c,v 1.24 2002/10/01 16:02:27 in2 Exp $ */ +/* $Id: io.c,v 1.25 2002/12/24 08:20:15 in2 Exp $ */ #include "bbs.h" #if defined(linux) @@ -303,6 +303,8 @@ igetch() return 0; } +#define min(a, b) (((a) > (b)) ? (b) : (a)) + int oldgetdata(int line, int col, char *prompt, char *buf, int len, int echo) { @@ -365,7 +367,7 @@ oldgetdata(int line, int col, char *prompt, char *buf, int len, int echo) outc('\n'); oflush(); } else { - int cmdpos = -1; + int cmdpos = 0; int currchar = 0; standout(); @@ -382,17 +384,17 @@ oldgetdata(int line, int col, char *prompt, char *buf, int len, int echo) case KEY_DOWN: case Ctrl('N'): buf[clen] = '\0'; /* Ptt */ - strncpy(lastcmd[cmdpos], buf, 79); + strncpy(lastcmd[cmdpos], buf, min(clen, 79)); cmdpos += MAXLASTCMD - 2; case Ctrl('P'): case KEY_UP: if (ch == KEY_UP || ch == Ctrl('P')) { buf[clen] = '\0'; /* Ptt */ - strncpy(lastcmd[cmdpos], buf, 79); + strncpy(lastcmd[cmdpos], buf, min(clen, 79)); } cmdpos++; cmdpos %= MAXLASTCMD; - strncpy(buf, lastcmd[cmdpos], len); + strncpy(buf, lastcmd[cmdpos], min(len, 79)); buf[len] = 0; move(y, x); /* clrtoeof */ @@ -468,7 +470,8 @@ oldgetdata(int line, int col, char *prompt, char *buf, int len, int echo) if (clen > 1) for (cmdpos = MAXLASTCMD - 1; cmdpos; cmdpos--) { - strlcpy(lastcmd[cmdpos], lastcmd[cmdpos - 1], sizeof(lastcmd[cmdpos])); + strlcpy(lastcmd[cmdpos], lastcmd[cmdpos - 1], + sizeof(lastcmd[cmdpos])); strncpy(lastcmd[0], buf, len); } if (echo) -- cgit v1.2.3 From 1e9a3ab393d34898d09a93453fe7b7c96aebf886 Mon Sep 17 00:00:00 2001 From: kcwu <kcwu@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Thu, 26 Dec 2002 06:16:13 +0000 Subject: prevent array index out of boundary when defined MEM_CHECK git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@587 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/board.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pttbbs/mbbsd/board.c b/pttbbs/mbbsd/board.c index ebb4e851..57a521cc 100644 --- a/pttbbs/mbbsd/board.c +++ b/pttbbs/mbbsd/board.c @@ -1,4 +1,4 @@ -/* $Id: board.c,v 1.62 2002/12/10 12:06:19 in2 Exp $ */ +/* $Id: board.c,v 1.63 2002/12/26 06:16:13 kcwu Exp $ */ #include "bbs.h" #define BRC_STRLEN 15 /* Length of board name */ #define BRC_MAXSIZE 24576 @@ -234,7 +234,7 @@ void load_brdbuf(void) size = (numboards + 32) * sizeof(int); #ifdef MEM_CHECK - size += 4; + size += sizeof(int); #endif zapbuf = (int *)malloc(size); favbuf = (int *)malloc(size); @@ -242,6 +242,7 @@ void load_brdbuf(void) zapbuf[0] = favbuf[0] = MEM_CHECK; zapbuf = &zapbuf[1]; favbuf = &favbuf[1]; + size -= sizeof(int); #endif zapchange = favchange = 0; -- cgit v1.2.3 From 7214f6eb1e94583d30ec6474a1b308fdd6280250 Mon Sep 17 00:00:00 2001 From: kcwu <kcwu@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Thu, 26 Dec 2002 09:46:04 +0000 Subject: use gcc's extension to check format string and make compiler happier git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@588 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/include/proto.h | 14 ++++++++++---- pttbbs/mbbsd/edit.c | 5 +++-- pttbbs/mbbsd/gamble.c | 11 +++++------ pttbbs/mbbsd/guess.c | 14 +++++++------- pttbbs/mbbsd/user.c | 4 ++-- 5 files changed, 27 insertions(+), 21 deletions(-) diff --git a/pttbbs/include/proto.h b/pttbbs/include/proto.h index 1c72178c..a340a943 100644 --- a/pttbbs/include/proto.h +++ b/pttbbs/include/proto.h @@ -1,7 +1,13 @@ -/* $Id: proto.h,v 1.30 2002/11/06 16:25:14 in2 Exp $ */ +/* $Id: proto.h,v 1.31 2002/12/26 09:46:03 kcwu Exp $ */ #ifndef INCLUDE_PROTO_H #define INCLUDE_PROTO_H +#ifdef __GNUC__ +#define GCC_CHECK_FORMAT(a,b) __attribute__ ((format (printf, a, b))) +#else +#define GCC_CHECK_FORMAT(a,b) +#endif + /* admin */ int m_mod_board(char *bname); int m_newbrd(int recover); @@ -23,7 +29,7 @@ void gem(char* maintitle, item_t* path, int update); /* args */ void initsetproctitle(int argc, char **argv, char **envp); -void setproctitle(const char* format, ...); +void setproctitle(const char* format, ...) GCC_CHECK_FORMAT(1,2); /* bbcall */ int main_bbcall(); @@ -348,7 +354,7 @@ void UnTagger (int locus); int substitute_record(char *fpath, void *rptr, int size, int id); int lock_substitute_record(char *fpath, void *rptr, int size, int id, int); int get_record(char *fpath, void *rptr, int size, int id); -void prints(char *fmt, ...); +void prints(char *fmt, ...) GCC_CHECK_FORMAT(1,2); int append_record(char *fpath, fileheader_t *record, int size); int stampfile(char *fpath, fileheader_t *fh); void stampdir(char *fpath, fileheader_t *fh); @@ -400,7 +406,7 @@ time_t gettime(int line, time_t dt); void setcalfile(char *buf, char *userid); void stand_title(char *title); void pressanykey(); -int vmsg (const char *fmt,...); +int vmsg (const char *fmt,...) GCC_CHECK_FORMAT(1,2); void trim(char *buf); void bell(); void setbpath(char *buf, char *boardname); diff --git a/pttbbs/mbbsd/edit.c b/pttbbs/mbbsd/edit.c index 0d77f9a8..1107a6f1 100644 --- a/pttbbs/mbbsd/edit.c +++ b/pttbbs/mbbsd/edit.c @@ -1,4 +1,4 @@ -/* $Id: edit.c,v 1.22 2002/11/23 04:15:30 ptt Exp $ */ +/* $Id: edit.c,v 1.23 2002/12/26 09:46:04 kcwu Exp $ */ #include "bbs.h" typedef struct textline_t { struct textline_t *prev; @@ -1575,7 +1575,7 @@ int vedit(char *fpath, int saveheader, int *islocal) { FILE *fp1; - char last = 0, buf[200]; /* the last key you press */ + char last = 0; /* the last key you press */ int ch, foo; int lastindent = -1; int last_margin; @@ -1649,6 +1649,7 @@ vedit(char *fpath, int saveheader, int *islocal) } /* 連續240個interval一樣 , 分明是在斂財 if (count >= 240) { + char buf[200]; snprintf(buf, sizeof(buf), "\033[1;33;46m%s\033[37m在\033[37;45m%s" "\033[37m板違法賺錢 , %s\033[m", cuser.userid, currboard, ctime(&now)); diff --git a/pttbbs/mbbsd/gamble.c b/pttbbs/mbbsd/gamble.c index 836dbc25..8ade3999 100644 --- a/pttbbs/mbbsd/gamble.c +++ b/pttbbs/mbbsd/gamble.c @@ -1,4 +1,4 @@ -/* $Id: gamble.c,v 1.28 2002/07/22 19:02:00 in2 Exp $ */ +/* $Id: gamble.c,v 1.29 2002/12/26 09:46:04 kcwu Exp $ */ #include "bbs.h" #ifndef _BBS_UTIL_C_ @@ -113,12 +113,11 @@ show_ticket_data(char *direct, int *price, boardheader_t * bh) prints("\033[32m站規:\033[m 1.可購買以下不同類型的彩票。每張要花 \033[32m%d\033[m 元。\n" " 2.%s\n" - " 3.開獎時只有一種彩票中獎, 有購買該彩票者, 則可依購買的張數均分" - "總賭金。\n" - " 4.每筆獎金由系統抽取 5% 之稅金%s。\n\n" + " 3.開獎時只有一種彩票中獎, 有購買該彩票者, 則可依購買的張數均分總賭金。\n" + " 4.每筆獎金由系統抽取 5%% 之稅金%s。\n\n" "\033[32m%s:\033[m", *price, - bh ? "此賭盤由板主負責舉辦並且決定開獎時間結果, 站長不管, 願賭服輸。" : - "系統每天 2:00 11:00 16:00 21:00 開獎。", + bh ? "此賭盤由板主負責舉辦並且決定開獎時間結果, 站長不管, 願賭服輸。" : + "系統每天 2:00 11:00 16:00 21:00 開獎。", bh ? ", 其中 2% 分給開獎板主" : "", bh ? "板主自訂規則及說明" : "前幾次開獎結果"); diff --git a/pttbbs/mbbsd/guess.c b/pttbbs/mbbsd/guess.c index 0d655108..bd32450c 100644 --- a/pttbbs/mbbsd/guess.c +++ b/pttbbs/mbbsd/guess.c @@ -1,4 +1,4 @@ -/* $Id: guess.c,v 1.6 2002/07/22 19:02:00 in2 Exp $ */ +/* $Id: guess.c,v 1.7 2002/12/26 09:46:04 kcwu Exp $ */ #include "bbs.h" #define LOGPASS BBSHOME "/etc/winguess.log" @@ -246,7 +246,7 @@ guess_main() Diff_Random(answer); move(2, 0); clrtoeol(); - prints("您下注 :%d Ptt$", money); + prints("您下注 :%lu Ptt$", money); getdata_str(4, 0, "您要和電腦比賽嗎? <y/n>[y]:", ifcomputer, sizeof(ifcomputer), LCECHO, "y"); @@ -292,7 +292,7 @@ guess_main() if (count > c_count) { prints("你輸給電腦了"); move(18, 35); - prints("你賠了 %d ", money); + prints("你賠了 %lu ", money); if ((file = fopen(LOGPASS, "a"))) { fprintf(file, "電腦第%d次猜中, ", c_count); if (youwin) @@ -308,7 +308,7 @@ guess_main() } else if (count < c_count) { prints("真厲害, 讓你賺到囉"); move(18, 35); - prints("你賺走了 %d ", money * 2); + prints("你賺走了 %lu ", money * 2); demoney(money * 2); if ((file = fopen(LOGPASS, "a"))) { fprintf(file, "id: %s, 第%d次猜中, 電腦第%d次猜中, " @@ -320,7 +320,7 @@ guess_main() pressanykey(); return 1; } else { - prints("真厲害, 和電腦打成平手了, 拿回本錢%d\n", money); + prints("真厲害, 和電腦打成平手了, 拿回本錢%lu\n", money); demoney(money); if ((file = fopen(LOGPASS, "a"))) { fprintf(file, "id: %s 和電腦打成了平手\n", cuser.userid); @@ -351,9 +351,9 @@ guess_main() prints("五次猜出來, 還你本錢吧"); move(18, 35); clrtoeol(); - prints("你拿回了%d Ptt$\n", money); + prints("你拿回了%lu Ptt$\n", money); if ((file = fopen(LOGPASS, "a"))) { - fprintf(file, "id: %s, 第%d次猜中, 拿回了本錢 %ld Ptt$\n", + fprintf(file, "id: %s, 第%d次猜中, 拿回了本錢 %lu Ptt$\n", cuser.userid, count, money); fclose(file); } diff --git a/pttbbs/mbbsd/user.c b/pttbbs/mbbsd/user.c index d3501822..5de29e36 100644 --- a/pttbbs/mbbsd/user.c +++ b/pttbbs/mbbsd/user.c @@ -1,4 +1,4 @@ -/* $Id: user.c,v 1.42 2002/12/14 08:02:18 in2 Exp $ */ +/* $Id: user.c,v 1.43 2002/12/26 09:46:04 kcwu Exp $ */ #include "bbs.h" static char *sex[8] = { @@ -55,7 +55,7 @@ user_display(userec_t * u, int real) " 居住住址: %s\n" " 電子信箱: %s\n" " 性 別: %s\n" - " 銀行帳戶: %ld 銀兩\n", + " 銀行帳戶: %d 銀兩\n", u->userid, u->username, u->realname, u->address, u->email, sex[u->sex % 8], u->money); -- cgit v1.2.3 From 7218fa87823fdf5fc3ee6b23b883dc2ddaa083b8 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Fri, 27 Dec 2002 09:12:20 +0000 Subject: warning for broken reaper git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@589 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/sample/crontab | 1 + 1 file changed, 1 insertion(+) diff --git a/pttbbs/sample/crontab b/pttbbs/sample/crontab index 4be44b03..e7d0c957 100644 --- a/pttbbs/sample/crontab +++ b/pttbbs/sample/crontab @@ -5,6 +5,7 @@ 0 2,11,16,21 * * * bin/openticket.sh # 每天早上清除過期使用者 +# warning: 目前這個程式無法正常運作, 且可能會搞爛整個密碼檔!! #10 7 * * * bin/reaper # 每個小時 1分執行上站人次統計 -- cgit v1.2.3 From f5f4a61b8ac36ad6d74f4dac22b1a06ca11bc554 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sun, 29 Dec 2002 08:04:18 +0000 Subject: store favbuf[] by char array instand of int array. save 24KB memory (in 8192 boards environment) for each user. git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@590 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/board.c | 44 ++++++++++++++++++++++++++++++++------------ 1 file changed, 32 insertions(+), 12 deletions(-) diff --git a/pttbbs/mbbsd/board.c b/pttbbs/mbbsd/board.c index 57a521cc..c7543ef2 100644 --- a/pttbbs/mbbsd/board.c +++ b/pttbbs/mbbsd/board.c @@ -1,4 +1,4 @@ -/* $Id: board.c,v 1.63 2002/12/26 06:16:13 kcwu Exp $ */ +/* $Id: board.c,v 1.64 2002/12/29 08:04:18 in2 Exp $ */ #include "bbs.h" #define BRC_STRLEN 15 /* Length of board name */ #define BRC_MAXSIZE 24576 @@ -219,35 +219,41 @@ typedef struct { unsigned int myattr; } boardstat_t; -static int *zapbuf = NULL, *favbuf; +static int *zapbuf = NULL; +static char *favbuf = NULL; static boardstat_t *nbrd = NULL; char zapchange = 0, favchange = 0; #define STR_BBSRC ".bbsrc" #define STR_FAV ".fav" +#define STR_FAV2 ".fav2" void load_brdbuf(void) { static char firsttime = 1; - int fd, size, i; + int fd, size, favsize, i; char fname[80]; size = (numboards + 32) * sizeof(int); + favsize = (numboards + 32) * sizeof(char); #ifdef MEM_CHECK size += sizeof(int); + favsize += sizeof(int); #endif zapbuf = (int *)malloc(size); - favbuf = (int *)malloc(size); + favbuf = (char *)malloc(favsize); #ifdef MEM_CHECK - zapbuf[0] = favbuf[0] = MEM_CHECK; + zapbuf[0] = MEM_CHECK; zapbuf = &zapbuf[1]; - favbuf = &favbuf[1]; + ((int *)favbuf)[0] = MEM_CHECK; + favbuf = &favbuf[ sizeof(int) ]; size -= sizeof(int); + favsize -= sizeof(int); #endif zapchange = favchange = 0; if( firsttime ){ - memset(favbuf, 0, size); + memset(favbuf, 0, favsize); for( i = (numboards + 32) - 1 ; i >= 0 ; --i ) zapbuf[i] = login_start_time; } @@ -257,11 +263,25 @@ void load_brdbuf(void) read(fd, zapbuf, size); close(fd); } - setuserfile(fname, STR_FAV); + setuserfile(fname, STR_FAV2); if ((fd = open(fname, O_RDONLY, 0600)) != -1) { - read(fd, favbuf, size); + read(fd, favbuf, favsize); close(fd); } + else{ + setuserfile(fname, STR_FAV); + if( (fd = open(fname, O_RDONLY, 0600)) != -1 ){ + int *oldfav = (int *)malloc(size); + read(fd, oldfav, size); + close(fd); + unlink(fname); + + for( i = (numboards + 32) - 1 ; i >= 0 ; --i ) + favbuf[i] = oldfav[i]; + free(oldfav); + favchange = 1; + } + } if( firsttime ){ for (i = 0; i < numboards; i++) @@ -307,15 +327,15 @@ save_brdbuf() zapbuf = NULL; } - setuserfile(fname, STR_FAV); + setuserfile(fname, STR_FAV2); if ( favbuf != NULL ){ if( ( #ifdef MEM_CHECK - favbuf[-1] == MEM_CHECK && + ((int*)favbuf)[-1] == MEM_CHECK && #endif favchange && (fd = open(fname, O_WRONLY | O_CREAT, 0600)) != -1) ){ - size = numboards * sizeof(int); + size = numboards * sizeof(char); write(fd, favbuf, size); close(fd); } -- cgit v1.2.3 From d438645ba03445a3ae5c51435ce9c0a2d6f075ae Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sun, 29 Dec 2002 08:18:29 +0000 Subject: after translating from old format, save favorite file in new format immediately git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@591 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/board.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/pttbbs/mbbsd/board.c b/pttbbs/mbbsd/board.c index c7543ef2..ddeef92e 100644 --- a/pttbbs/mbbsd/board.c +++ b/pttbbs/mbbsd/board.c @@ -1,4 +1,4 @@ -/* $Id: board.c,v 1.64 2002/12/29 08:04:18 in2 Exp $ */ +/* $Id: board.c,v 1.65 2002/12/29 08:18:29 in2 Exp $ */ #include "bbs.h" #define BRC_STRLEN 15 /* Length of board name */ #define BRC_MAXSIZE 24576 @@ -269,17 +269,29 @@ void load_brdbuf(void) close(fd); } else{ + // translate old fav format(int array) to new format(char array) setuserfile(fname, STR_FAV); if( (fd = open(fname, O_RDONLY, 0600)) != -1 ){ int *oldfav = (int *)malloc(size); read(fd, oldfav, size); close(fd); - unlink(fname); for( i = (numboards + 32) - 1 ; i >= 0 ; --i ) favbuf[i] = oldfav[i]; free(oldfav); - favchange = 1; + + setuserfile(fname, STR_FAV2); + if( (fd = open(fname, O_WRONLY | O_CREAT, 0600)) != -1 ){ + size = numboards * sizeof(char); + write(fd, favbuf, size); + close(fd); + + // remove old favorite file + setuserfile(fname, STR_FAV); + unlink(fname); + } + else + favchange = 1; } } -- cgit v1.2.3 From 8599eca3002d14d76068677bf3dfe1b5dfe3183a Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Tue, 31 Dec 2002 17:40:52 +0000 Subject: make gcc33 happy git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@592 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/board.c | 6 +++--- pttbbs/mbbsd/cache.c | 4 ++-- pttbbs/mbbsd/calendar.c | 4 ++-- pttbbs/mbbsd/chat.c | 6 +++--- pttbbs/mbbsd/chc_draw.c | 4 ++-- pttbbs/mbbsd/edit.c | 16 +++++++++------- pttbbs/mbbsd/friend.c | 6 +++--- pttbbs/mbbsd/more.c | 8 +++++--- pttbbs/mbbsd/record.c | 4 ++-- pttbbs/mbbsd/talk.c | 4 ++-- pttbbs/mbbsd/user.c | 6 +++--- pttbbs/mbbsd/var.c | 5 +++-- pttbbs/mbbsd/vote.c | 4 ++-- 13 files changed, 41 insertions(+), 36 deletions(-) diff --git a/pttbbs/mbbsd/board.c b/pttbbs/mbbsd/board.c index ddeef92e..87ebbeb2 100644 --- a/pttbbs/mbbsd/board.c +++ b/pttbbs/mbbsd/board.c @@ -1,4 +1,4 @@ -/* $Id: board.c,v 1.65 2002/12/29 08:18:29 in2 Exp $ */ +/* $Id: board.c,v 1.66 2002/12/31 17:40:51 in2 Exp $ */ #include "bbs.h" #define BRC_STRLEN 15 /* Length of board name */ #define BRC_MAXSIZE 24576 @@ -324,7 +324,7 @@ save_brdbuf() if ( zapbuf != NULL ){ if( ( #ifdef MEM_CHECK - zapbuf[-1] == MEM_CHECK && + (unsigned)zapbuf[-1] == (unsigned)MEM_CHECK && #endif zapchange && (fd = open(fname, O_WRONLY | O_CREAT, 0600)) != -1) ){ @@ -343,7 +343,7 @@ save_brdbuf() if ( favbuf != NULL ){ if( ( #ifdef MEM_CHECK - ((int*)favbuf)[-1] == MEM_CHECK && + (unsigned)((int*)favbuf)[-1] == (unsigned)MEM_CHECK && #endif favchange && (fd = open(fname, O_WRONLY | O_CREAT, 0600)) != -1) ){ diff --git a/pttbbs/mbbsd/cache.c b/pttbbs/mbbsd/cache.c index 1289dd51..f8cc453f 100644 --- a/pttbbs/mbbsd/cache.c +++ b/pttbbs/mbbsd/cache.c @@ -1,4 +1,4 @@ -/* $Id: cache.c,v 1.53 2002/11/16 13:41:07 kcwu Exp $ */ +/* $Id: cache.c,v 1.54 2002/12/31 17:40:51 in2 Exp $ */ #include "bbs.h" #ifndef __FreeBSD__ @@ -324,7 +324,7 @@ u_namearray(char buf[][IDLEN + 1], int *pnum, char *tag) /*-------------------------------------------------------*/ #if !defined(_BBS_UTIL_C_) void -setutmpmode(int mode) +setutmpmode(unsigned int mode) { if (currstat != mode) currutmp->mode = currstat = mode; diff --git a/pttbbs/mbbsd/calendar.c b/pttbbs/mbbsd/calendar.c index 03cd84d6..c4b86e89 100644 --- a/pttbbs/mbbsd/calendar.c +++ b/pttbbs/mbbsd/calendar.c @@ -1,4 +1,4 @@ -/* $Id: calendar.c,v 1.6 2002/07/21 09:26:02 in2 Exp $ */ +/* $Id: calendar.c,v 1.7 2002/12/31 17:40:51 in2 Exp $ */ #include "bbs.h" typedef struct event_t { @@ -93,7 +93,7 @@ ParseColor(char *color) }; int i; - for (i = 0; i < sizeof(c) / sizeof(c[0]); i++) + for (i = 0; (unsigned)i < sizeof(c) / sizeof(c[0]); i++) if (strcasecmp(color, c[i].str) == 0) return c[i].val; return 7; diff --git a/pttbbs/mbbsd/chat.c b/pttbbs/mbbsd/chat.c index 4c58b290..66954248 100644 --- a/pttbbs/mbbsd/chat.c +++ b/pttbbs/mbbsd/chat.c @@ -1,4 +1,4 @@ -/* $Id: chat.c,v 1.9 2002/07/22 19:02:00 in2 Exp $ */ +/* $Id: chat.c,v 1.10 2002/12/31 17:40:51 in2 Exp $ */ #include "bbs.h" static int chatline, stop_line; @@ -75,7 +75,7 @@ chat_recv(int fd, char *chatid) bptr = buf; while (c > 0) { len = strlen(bptr) + 1; - if (len > c && len < (sizeof buf / 2)) + if (len > c && (unsigned)len < (sizeof(buf)/ 2) ) break; if (*bptr == '/') { @@ -538,7 +538,7 @@ t_chat() break; } if (ch == Ctrl('D')) { - if (currchar < strlen(inbuf)) { + if ((size_t)currchar < strlen(inbuf)) { inbuf[69] = '\0'; memcpy(&inbuf[currchar], &inbuf[currchar + 1], 69 - currchar); move(b_lines - 1, currchar + chatid_len); diff --git a/pttbbs/mbbsd/chc_draw.c b/pttbbs/mbbsd/chc_draw.c index 8c7e556b..a3cda935 100644 --- a/pttbbs/mbbsd/chc_draw.c +++ b/pttbbs/mbbsd/chc_draw.c @@ -1,4 +1,4 @@ -/* $Id: chc_draw.c,v 1.4 2002/07/21 09:26:02 in2 Exp $ */ +/* $Id: chc_draw.c,v 1.5 2002/12/31 17:40:51 in2 Exp $ */ #include "bbs.h" #define SIDE_ROW 10 @@ -131,7 +131,7 @@ chc_drawline(board_t board, int line) } outs(" "); - if (line >= 3 && line < 3 + dim(hint_str)) { + if (line >= 3 && line < 3 + (int)dim(hint_str)) { outs(hint_str[line - 3]); } else if (line == SIDE_ROW) { prints("\033[1m你是%s%s\033[m", diff --git a/pttbbs/mbbsd/edit.c b/pttbbs/mbbsd/edit.c index 1107a6f1..ec20e7c1 100644 --- a/pttbbs/mbbsd/edit.c +++ b/pttbbs/mbbsd/edit.c @@ -1,4 +1,4 @@ -/* $Id: edit.c,v 1.23 2002/12/26 09:46:04 kcwu Exp $ */ +/* $Id: edit.c,v 1.24 2002/12/31 17:40:51 in2 Exp $ */ #include "bbs.h" typedef struct textline_t { struct textline_t *prev; @@ -1244,14 +1244,14 @@ match_paren() for (lino = currln, p = currline; p; p = p->next, lino++) { lino = lino; for (i = (lino == currln) ? currpnt + 1 : 0; - i < strlen(p->data); i++) + (size_t)i < strlen(p->data); i++) if (p->data[i] == '/' && p->data[++i] == '*') { ++i; while (1) { - while (i < strlen(p->data) - 1 && + while ((size_t)i < strlen(p->data) - 1 && !(p->data[i] == '*' && p->data[i + 1] == '/')) i++; - if (i >= strlen(p->data) - 1 && p->next) { + if ((size_t)i >= strlen(p->data) - 1 && p->next) { p = p->next; ++lino; i = 0; @@ -1261,11 +1261,11 @@ match_paren() } else if ((c = p->data[i]) == '\'' || c == '"') { while (1) { while (i < (int)(strlen(p->data) - 1)) - if (p->data[++i] == '\\' && i < strlen(p->data) - 2) + if (p->data[++i] == '\\' && (size_t)i < strlen(p->data) - 2) ++i; else if (p->data[i] == c) goto end_quote; - if (i >= strlen(p->data) - 1 && p->next) { + if ((size_t)i >= strlen(p->data) - 1 && p->next) { p = p->next; ++lino; i = -1; @@ -1281,7 +1281,9 @@ match_paren() } } else { for (lino = currln, p = currline; p; p = p->prev, lino--) - for (i = (lino == currln) ? currpnt - 1 : strlen(p->data) - 1; + for (i = ((lino == currln) ? + currpnt - 1 : + (int)strlen(p->data) - 1); i >= 0; i--) if (p->data[i] == '/' && p->data[--i] == '*' && i > 0) { --i; diff --git a/pttbbs/mbbsd/friend.c b/pttbbs/mbbsd/friend.c index 6becc8f9..15a00c50 100644 --- a/pttbbs/mbbsd/friend.c +++ b/pttbbs/mbbsd/friend.c @@ -1,4 +1,4 @@ -/* $Id: friend.c,v 1.13 2002/07/27 17:23:09 kcwu Exp $ */ +/* $Id: friend.c,v 1.14 2002/12/31 17:40:51 in2 Exp $ */ #include "bbs.h" /* ------------------------------------- */ @@ -56,7 +56,7 @@ setfriendfile(char *fpath, int type) setbfile(fpath, currboard, friend_file[type]); } -static int +static unsigned int friend_count(char *fname) { FILE *fp; @@ -185,7 +185,7 @@ friend_append(int type, int count) setfriendfile(sfile, j); if ((fp = fopen(sfile, "r")) != NULL) { - while (fgets(buf, 80, fp) && count <= friend_max[type]) { + while (fgets(buf, 80, fp) && (unsigned)count <= friend_max[type]) { char the_id[15]; sscanf(buf, "%s", the_id); diff --git a/pttbbs/mbbsd/more.c b/pttbbs/mbbsd/more.c index 3afc6ca9..a1d82e42 100644 --- a/pttbbs/mbbsd/more.c +++ b/pttbbs/mbbsd/more.c @@ -1,4 +1,4 @@ -/* $Id: more.c,v 1.21 2002/09/11 07:16:49 kcwu Exp $ */ +/* $Id: more.c,v 1.22 2002/12/31 17:40:51 in2 Exp $ */ #include "bbs.h" #define MORE_BUFSIZE 4096 #define MORE_WINSIZE 4096 @@ -293,7 +293,9 @@ more(char *fpath, int promptend) else pos++; - if (!scrollup && ++lino >= b_lines && pageno < MAX_PAGES - 1) { + if (!scrollup && + ++lino >= (unsigned)b_lines && + pageno < MAX_PAGES - 1 ) { pagebreak[++pageno] = viewed; lino = 1; } @@ -553,7 +555,7 @@ more(char *fpath, int promptend) clear(); } } - if (pageno && lino > 1 + local) { + if (pageno && (int)lino > 1 + local) { line = (lino - 2) - local; if (pageno > 1 && viewed == fsize) line += local; diff --git a/pttbbs/mbbsd/record.c b/pttbbs/mbbsd/record.c index 13db0da6..cc82cde8 100644 --- a/pttbbs/mbbsd/record.c +++ b/pttbbs/mbbsd/record.c @@ -1,4 +1,4 @@ -/* $Id: record.c,v 1.11 2002/11/06 16:25:15 in2 Exp $ */ +/* $Id: record.c,v 1.12 2002/12/31 17:40:51 in2 Exp $ */ #include "bbs.h" #undef HAVE_MMAP @@ -444,7 +444,7 @@ int apply_record(char *fpath, int (*fptr) (), int size){ if (!(fp = fopen(fpath, "r"))) return -1; - while (fread(abuf, 1, size, fp) == size) + while (fread(abuf, 1, size, fp) == (size_t)size) if ((*fptr) (abuf) == QUIT) { fclose(fp); return QUIT; diff --git a/pttbbs/mbbsd/talk.c b/pttbbs/mbbsd/talk.c index af88bc01..c7f6e7a7 100644 --- a/pttbbs/mbbsd/talk.c +++ b/pttbbs/mbbsd/talk.c @@ -1,4 +1,4 @@ -/* $Id: talk.c,v 1.96 2002/12/04 10:14:07 in2 Exp $ */ +/* $Id: talk.c,v 1.97 2002/12/31 17:40:51 in2 Exp $ */ #include "bbs.h" #define QCAST int (*)(const void *, const void *) @@ -389,7 +389,7 @@ my_query(char *uident) Cdate(&muser.lastlogin), (muser.lasthost[0] ? muser.lasthost : "(不詳)")); if ((uentp && fri_stat & HFM && !uentp->invisible)) - prints("《 性 別 》%-28.28s《私有財產》%ld 銀兩\n", + prints("《 性 別 》%-28.28s《私有財產》%d 銀兩\n", sex[muser.sex % 8], muser.money); prints("《五子棋戰績》%3d 勝 %3d 敗 %3d 和 " diff --git a/pttbbs/mbbsd/user.c b/pttbbs/mbbsd/user.c index 5de29e36..e3bb1f89 100644 --- a/pttbbs/mbbsd/user.c +++ b/pttbbs/mbbsd/user.c @@ -1,4 +1,4 @@ -/* $Id: user.c,v 1.43 2002/12/26 09:46:04 kcwu Exp $ */ +/* $Id: user.c,v 1.44 2002/12/31 17:40:52 in2 Exp $ */ #include "bbs.h" static char *sex[8] = { @@ -295,7 +295,7 @@ uinfo_query(userec_t * u, int real, int unum) snprintf(genbuf, sizeof(genbuf), "%d", x.money); if (getdata_str(i++, 0, "銀行帳戶:", buf, 10, DOECHO, genbuf)) if ((l = atol(buf)) != 0) { - if (l != x.money) { + if (l != (unsigned)x.money) { money_change = 1; money = x.money; x.money = l; @@ -425,7 +425,7 @@ uinfo_query(userec_t * u, int real, int unum) case '3': i = setperms(x.userlevel, str_permid); - if (i == x.userlevel) + if ((unsigned)i == x.userlevel) fail++; else { flag = 1; diff --git a/pttbbs/mbbsd/var.c b/pttbbs/mbbsd/var.c index e7f6996f..68c0abdc 100644 --- a/pttbbs/mbbsd/var.c +++ b/pttbbs/mbbsd/var.c @@ -1,4 +1,4 @@ -/* $Id: var.c,v 1.14 2002/11/07 09:13:24 in2 Exp $ */ +/* $Id: var.c,v 1.15 2002/12/31 17:40:52 in2 Exp $ */ #define INCLUDE_VAR_H #include "bbs.h" @@ -344,7 +344,8 @@ int chc_hiswin, chc_hislose, chc_histie; /* screen.c */ screenline_t *big_picture = NULL; -unsigned char scr_lns, scr_cols; +unsigned char scr_lns; +unsigned short scr_cols; char roll; /* gomo.c */ diff --git a/pttbbs/mbbsd/vote.c b/pttbbs/mbbsd/vote.c index 48afafd1..8a8faa63 100644 --- a/pttbbs/mbbsd/vote.c +++ b/pttbbs/mbbsd/vote.c @@ -1,4 +1,4 @@ -/* $Id: vote.c,v 1.15 2002/07/22 19:02:01 in2 Exp $ */ +/* $Id: vote.c,v 1.16 2002/12/31 17:40:52 in2 Exp $ */ #include "bbs.h" static int total; @@ -406,7 +406,7 @@ vote_view(char *bname, int index) fscanf(fp, "%lu\n", &closetime); prints("\n◆ 預知投票紀事: 每人最多可投 %d 票,目前共有 %d 票,\n" - "本次投票將結束於 %s", atoi(inbuf), stbuf.st_size, + "本次投票將結束於 %s", atoi(inbuf), (int)stbuf.st_size, ctime(&closetime)); /* Thor: 開放 票數 預知 */ -- cgit v1.2.3 From 34db5ce208feef79265c401379f2ae13b9a29462 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Tue, 31 Dec 2002 17:42:23 +0000 Subject: flexible Makefile git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@593 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/Makefile | 65 +++++++++++++++++++++++++++++---------------------- 1 file changed, 37 insertions(+), 28 deletions(-) diff --git a/pttbbs/mbbsd/Makefile b/pttbbs/mbbsd/Makefile index 5d9d4f2b..33f239b1 100644 --- a/pttbbs/mbbsd/Makefile +++ b/pttbbs/mbbsd/Makefile @@ -1,42 +1,51 @@ -# $Id: Makefile,v 1.12 2002/07/05 13:18:27 in2 Exp $ - -BBSHOME?=$(HOME) -OSTYPE=FreeBSD - -# FreeBSD -CFLAGS_FreeBSD= -pipe -Wall -DHAVE_SETPROCTITLE -DBBSHOME='"$(BBSHOME)"' -DFreeBSD -I../include -LDFLAGS_FreeBSD=-pipe -Wall -LIBS_FreeBSD= -lkvm -lcrypt - -# Linux -CFLAGS_linux= -pipe -Wall -DHAVE_DES_CRYPT -DBBSHOME='"$(BBSHOME)"' -DLinux -I../include -s +# $Id: Makefile,v 1.13 2002/12/31 17:42:23 in2 Exp $ + +# 訂義基本初值 +BBSHOME?= $(HOME) +BBSHOME?= /home/bbs +OSTYPE?= FreeBSD +CC?= gcc +CFLAGS+= -Wall -pipe -DBBSHOME='"$(BBSHOME)"' -I../include +LDFLAGS+= -pipe -Wall +LIBS+= -lcrypt + +# 在 CFLAGS內加入定義 COMPILE_TIME +CFLAGS+= "-DCOMPILE_TIME=\"`date`\"" + +# FreeBSD特有的環境 +CFLAGS_FreeBSD= -DHAVE_SETPROCTITLE -DFreeBSD +LDFLAGS_FreeBSD= +LIBS_FreeBSD= -lkvm + +# Linux特有的環境 +CFLAGS_linux= -DHAVE_DES_CRYPT -DLinux LDFLAGS_linux= -pipe -Wall -LIBS_linux= -lcrypt +LIBS_linux= -CFLAGS= $(CFLAGS_$(OSTYPE)) -LDFLAGS=$(LDFLAGS_$(OSTYPE)) -LIBS= $(LIBS_$(OSTYPE)) +# CFLAGS, LDFLAGS, LIBS 加入 OS 相關參數 +CFLAGS+= $(CFLAGS_$(OSTYPE)) +LDFLAGS+= $(LDFLAGS_$(OSTYPE)) +LIBS+= $(LIBS_$(OSTYPE)) +# 若有定義 GDB或 DEBUG, 則加入 -g , 否則用 -O .if defined(GDB) || defined(DEBUG) -CFLAGS+= -g -FDFLAGS+= -g +CFLAGS+= -g +FDFLAGS+= -g .else -CFLAGS+= -O -LDFLAGS+= -O +CFLAGS+= -O +LDFLAGS+= -O .endif +# 若有定義 DEBUG, 則在 CFLAGS內定義 DEBUG .if defined(DEBUG) -CFLAGS+= -DDEBUG -LDFLAGS+= -DDEBUG +CFLAGS+= -DDEBUG .endif +# 若有定義 NO_FORK, 則在 CFLAGS內定義 NO_FORK .if defined(NO_FORK) -CFLAGS+= -DNO_FORK +CFLAGS+= -DNO_FORK .endif -CFLAGS+= "-DCOMPILE_TIME=\"`date`\"" - -CC= gcc PROG= mbbsd OBJS= admin.o announce.o args.o bbs.o board.o cache.o cal.o card.o\ chat.o chc_draw.o chc_net.o chc_play.o chc_rule.o chicken.o dark.o\ @@ -49,12 +58,12 @@ OBJS= admin.o announce.o args.o bbs.o board.o cache.o cal.o card.o\ .SUFFIXES: .c .o .c.o: ../include/var.h - $(CC) $(ADDFLAGS) $(CFLAGS) -c $*.c + $(CC) $(CFLAGS) -c $*.c all: $(PROG) $(PROG): $(OBJS) - $(CC) $(ADDFLAGS) $(LDFLAGS) -o $(PROG) $(OBJS) $(LIBS) + $(CC) $(LDFLAGS) -o $(PROG) $(OBJS) $(LIBS) ../include/var.h: var.c perl ../util/parsevar.pl < var.c > ../include/var.h -- cgit v1.2.3 From ba28ae0da2436fbd906a9eed58a7ca8596aded08 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Thu, 9 Jan 2003 11:44:28 +0000 Subject: prototype of setutmpmode has beed changed git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@594 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/include/proto.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pttbbs/include/proto.h b/pttbbs/include/proto.h index a340a943..4cfcef28 100644 --- a/pttbbs/include/proto.h +++ b/pttbbs/include/proto.h @@ -1,4 +1,4 @@ -/* $Id: proto.h,v 1.31 2002/12/26 09:46:03 kcwu Exp $ */ +/* $Id: proto.h,v 1.32 2003/01/09 11:44:28 in2 Exp $ */ #ifndef INCLUDE_PROTO_H #define INCLUDE_PROTO_H @@ -80,7 +80,7 @@ void reset_board(int bid); void touch_boards(); void addbrd_touchcache(); void setapath(char *buf, char *boardname); -void setutmpmode(int mode); +void setutmpmode(unsigned int mode); void setadir(char *buf, char *path); boardheader_t *getbcache(int bid); int apply_boards(int (*func)(boardheader_t *)); -- cgit v1.2.3 From cbcff1a5e671941caeca2ba53637a784c5d05448 Mon Sep 17 00:00:00 2001 From: kcwu <kcwu@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Fri, 10 Jan 2003 17:20:13 +0000 Subject: unlock after losing git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@595 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/guess.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pttbbs/mbbsd/guess.c b/pttbbs/mbbsd/guess.c index bd32450c..69167617 100644 --- a/pttbbs/mbbsd/guess.c +++ b/pttbbs/mbbsd/guess.c @@ -1,4 +1,4 @@ -/* $Id: guess.c,v 1.7 2002/12/26 09:46:04 kcwu Exp $ */ +/* $Id: guess.c,v 1.8 2003/01/10 17:20:13 kcwu Exp $ */ #include "bbs.h" #define LOGPASS BBSHOME "/etc/winguess.log" @@ -370,5 +370,6 @@ guess_main() fprintf(file, "id: %s 賭了 %ld Ptt$\n", cuser.userid, money); fclose(file); } + unlockutmpmode(); return 1; } -- cgit v1.2.3 From 6cfd07173fbcaa9b43a63276c36cd74f2da8581c Mon Sep 17 00:00:00 2001 From: kcwu <kcwu@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Fri, 10 Jan 2003 17:23:48 +0000 Subject: pause after losing git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@596 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/guess.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pttbbs/mbbsd/guess.c b/pttbbs/mbbsd/guess.c index 69167617..4c365708 100644 --- a/pttbbs/mbbsd/guess.c +++ b/pttbbs/mbbsd/guess.c @@ -1,4 +1,4 @@ -/* $Id: guess.c,v 1.8 2003/01/10 17:20:13 kcwu Exp $ */ +/* $Id: guess.c,v 1.9 2003/01/10 17:23:48 kcwu Exp $ */ #include "bbs.h" #define LOGPASS BBSHOME "/etc/winguess.log" @@ -371,5 +371,6 @@ guess_main() fclose(file); } unlockutmpmode(); + pressanykey(); return 1; } -- cgit v1.2.3 From d823cffd0b10833e7a74c67571e9fac822cd20db Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Tue, 14 Jan 2003 11:19:39 +0000 Subject: saving stack usage by reducing function call git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@597 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/mbbsd.c | 28 ++++++++++++---------------- pttbbs/mbbsd/talk.c | 4 ++-- 2 files changed, 14 insertions(+), 18 deletions(-) diff --git a/pttbbs/mbbsd/mbbsd.c b/pttbbs/mbbsd/mbbsd.c index 9cfb91d2..521673c5 100644 --- a/pttbbs/mbbsd/mbbsd.c +++ b/pttbbs/mbbsd/mbbsd.c @@ -1,4 +1,4 @@ -/* $Id: mbbsd.c,v 1.60 2002/12/10 11:59:02 in2 Exp $ */ +/* $Id: mbbsd.c,v 1.61 2003/01/14 11:19:39 in2 Exp $ */ #include "bbs.h" #define SOCKET_QLEN 4 @@ -916,7 +916,7 @@ do_term_init() raise(SIGWINCH); } -static void +inline static void start_client() { #ifdef CPULIMIT @@ -1161,8 +1161,8 @@ bind_port(int port) /*******************************************************/ -static void shell_login(int argc, char *argv[], char *envp[]); -static void daemon_login(int argc, char *argv[], char *envp[]); +static int shell_login(int argc, char *argv[], char *envp[]); +static int daemon_login(int argc, char *argv[], char *envp[]); static int check_ban_and_load(int fd); int @@ -1177,17 +1177,15 @@ main(int argc, char *argv[], char *envp[]) signal(SIGUSR1, SIG_IGN); signal(SIGUSR2, SIG_IGN); - /* check if invoked as "bbs" */ attach_SHM(); - if (argc == 3) - shell_login(argc, argv, envp); - else - daemon_login(argc, argv, envp); + if( (argc == 3 && shell_login(argc, argv, envp)) || + (argc != 3 && daemon_login(argc, argv, envp)) ) + start_client(); return 0; } -static void +static int shell_login(int argc, char *argv[], char *envp[]) { @@ -1214,12 +1212,12 @@ shell_login(int argc, char *argv[], char *envp[]) init_tty(); if (check_ban_and_load(0)) { - exit(0); + return 0; } - start_client(); + return 1; } -static void +static int daemon_login(int argc, char *argv[], char *envp[]) { int msock, csock; /* socket for Master and Child */ @@ -1296,9 +1294,7 @@ daemon_login(int argc, char *argv[], char *envp[]) getremotename(&xsin, fromhost, remoteusername); telnet_init(); - start_client(); - close(0); - close(1); + return 1; } /* diff --git a/pttbbs/mbbsd/talk.c b/pttbbs/mbbsd/talk.c index c7f6e7a7..6909d726 100644 --- a/pttbbs/mbbsd/talk.c +++ b/pttbbs/mbbsd/talk.c @@ -1,4 +1,4 @@ -/* $Id: talk.c,v 1.97 2002/12/31 17:40:51 in2 Exp $ */ +/* $Id: talk.c,v 1.98 2003/01/14 11:19:39 in2 Exp $ */ #include "bbs.h" #define QCAST int (*)(const void *, const void *) @@ -1772,7 +1772,7 @@ call_in(userinfo_t * uentp, int fri_stat) return 0; } -static void +inline static void userlist(void) { /* -- cgit v1.2.3 From 38df492e4667f7a1eae14f9f9e806b1146f2f3b3 Mon Sep 17 00:00:00 2001 From: kcwu <kcwu@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Wed, 15 Jan 2003 09:11:47 +0000 Subject: clean unused code git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@598 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/board.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/pttbbs/mbbsd/board.c b/pttbbs/mbbsd/board.c index 87ebbeb2..fadba9d8 100644 --- a/pttbbs/mbbsd/board.c +++ b/pttbbs/mbbsd/board.c @@ -1,4 +1,4 @@ -/* $Id: board.c,v 1.66 2002/12/31 17:40:51 in2 Exp $ */ +/* $Id: board.c,v 1.67 2003/01/15 09:11:47 kcwu Exp $ */ #include "bbs.h" #define BRC_STRLEN 15 /* Length of board name */ #define BRC_MAXSIZE 24576 @@ -780,9 +780,6 @@ choose_board(int newflag) boardstat_t *ptr; int head = -1, ch = 0, currmodetmp, tmp, tmp1, bidtmp; char keyword[13] = ""; -#if HAVE_SEARCH_ALL - char genbuf[200]; -#endif setutmpmode(newflag ? READNEW : READBRD); if( zapbuf == NULL || favbuf == NULL ) -- cgit v1.2.3 From 6cf160e4215089eb1538be77b32c07d856ae0e10 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Wed, 15 Jan 2003 09:41:19 +0000 Subject: show memory usage by hitting Ctrl-Q in DEBUG mode git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@599 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/io.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pttbbs/mbbsd/io.c b/pttbbs/mbbsd/io.c index aa6e525b..9b34bd12 100644 --- a/pttbbs/mbbsd/io.c +++ b/pttbbs/mbbsd/io.c @@ -1,4 +1,4 @@ -/* $Id: io.c,v 1.25 2002/12/24 08:20:15 in2 Exp $ */ +/* $Id: io.c,v 1.26 2003/01/15 09:41:19 in2 Exp $ */ #include "bbs.h" #if defined(linux) @@ -153,6 +153,11 @@ igetch() register int ch; while ((ch = dogetch())) { switch (ch) { +#ifdef DEBUG + case Ctrl('Q'): + vmsg("memory usage: %d KB", ((int)sbrk(0) - 0x8048000) / 1024); + continue; +#endif case Ctrl('L'): redoscr(); continue; -- cgit v1.2.3 From 1277c9996112ad4386111dbd027f9c04e0fc0077 Mon Sep 17 00:00:00 2001 From: kcwu <kcwu@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Wed, 15 Jan 2003 14:41:40 +0000 Subject: try optimize for size -Os git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@600 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pttbbs/mbbsd/Makefile b/pttbbs/mbbsd/Makefile index 33f239b1..0a0c94f8 100644 --- a/pttbbs/mbbsd/Makefile +++ b/pttbbs/mbbsd/Makefile @@ -1,4 +1,4 @@ -# $Id: Makefile,v 1.13 2002/12/31 17:42:23 in2 Exp $ +# $Id: Makefile,v 1.14 2003/01/15 14:41:40 kcwu Exp $ # 訂義基本初值 BBSHOME?= $(HOME) @@ -32,7 +32,7 @@ LIBS+= $(LIBS_$(OSTYPE)) CFLAGS+= -g FDFLAGS+= -g .else -CFLAGS+= -O +CFLAGS+= -Os LDFLAGS+= -O .endif -- cgit v1.2.3 From 9e13f340dd064d257119acdf7697a90f582d9159 Mon Sep 17 00:00:00 2001 From: kcwu <kcwu@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Thu, 16 Jan 2003 11:53:54 +0000 Subject: code clean up git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@601 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/screen.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pttbbs/mbbsd/screen.c b/pttbbs/mbbsd/screen.c index eefdbbea..23aa9e71 100644 --- a/pttbbs/mbbsd/screen.c +++ b/pttbbs/mbbsd/screen.c @@ -1,4 +1,4 @@ -/* $Id: screen.c,v 1.13 2002/09/11 10:33:11 kcwu Exp $ */ +/* $Id: screen.c,v 1.14 2003/01/16 11:53:54 kcwu Exp $ */ #include "bbs.h" #ifdef SUPPORT_GB @@ -379,7 +379,7 @@ outc(unsigned char ch) if (ch == 'm') { buf[p++] = '\0'; parsecolor(buf); - } else if ((p < 24) && (not_alpha(ch))) { + } else if ((p < sizeof(buf)) && (not_alpha(ch))) { buf[p++] = ch; return; } @@ -387,8 +387,8 @@ outc(unsigned char ch) outch(''); outch('['); - for (i = 0; (p = buf[i]); i++) - outch(p); + for (i = 0; buf[i]; i++) + outch(buf[i]); outch(ch); } p = 0; -- cgit v1.2.3 From 1d2e421cf04e3a98c61ff696b90ed4c4d88d3aef Mon Sep 17 00:00:00 2001 From: kcwu <kcwu@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Thu, 16 Jan 2003 11:58:05 +0000 Subject: remove unnecessary `static' keyword from some local variable git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@602 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/admin.c | 12 ++++++------ pttbbs/mbbsd/announce.c | 6 +++--- pttbbs/mbbsd/board.c | 8 ++++---- pttbbs/mbbsd/cal.c | 6 +++--- pttbbs/mbbsd/calendar.c | 10 +++++----- pttbbs/mbbsd/edit.c | 6 +++--- pttbbs/mbbsd/guess.c | 4 ++-- pttbbs/mbbsd/menu.c | 4 ++-- pttbbs/mbbsd/more.c | 4 ++-- pttbbs/mbbsd/register.c | 4 ++-- pttbbs/mbbsd/stuff.c | 4 ++-- pttbbs/mbbsd/talk.c | 10 +++++----- pttbbs/mbbsd/vote.c | 4 ++-- pttbbs/mbbsd/xyz.c | 6 +++--- 14 files changed, 44 insertions(+), 44 deletions(-) diff --git a/pttbbs/mbbsd/admin.c b/pttbbs/mbbsd/admin.c index a060a123..3b41802f 100644 --- a/pttbbs/mbbsd/admin.c +++ b/pttbbs/mbbsd/admin.c @@ -1,4 +1,4 @@ -/* $Id: admin.c,v 1.29 2002/07/22 19:02:00 in2 Exp $ */ +/* $Id: admin.c,v 1.30 2003/01/16 11:58:04 kcwu Exp $ */ #include "bbs.h" /* 使用者管理 */ @@ -724,15 +724,15 @@ int scan_register_form(char *regfile, int automode, int neednum) { char genbuf[200]; - static char *logfile = "register.log"; - static char *field[] = { + char *logfile = "register.log"; + char *field[] = { "uid", "ident", "name", "career", "addr", "phone", "email", NULL }; - static char *finfo[] = { + char *finfo[] = { "帳號", "身分證號", "真實姓名", "服務單位", "目前住址", "連絡電話", "電子郵件信箱", NULL }; - static char *reason[] = { + char *reason[] = { "輸入真實姓名", "詳細填寫您的「學校以及『科系』『年級』」或「服務單位(詳細至職稱)」", "填寫完整的住址資料 (含縣市名稱, 台北市請含行政區域)", @@ -741,7 +741,7 @@ scan_register_form(char *regfile, int automode, int neednum) "用中文填寫申請單", NULL }; - static char *autoid = "AutoScan"; + char *autoid = "AutoScan"; userec_t muser; FILE *fn, *fout, *freg; char fdata[7][STRLEN]; diff --git a/pttbbs/mbbsd/announce.c b/pttbbs/mbbsd/announce.c index 723a55fb..a1a5797b 100644 --- a/pttbbs/mbbsd/announce.c +++ b/pttbbs/mbbsd/announce.c @@ -1,10 +1,10 @@ -/* $Id: announce.c,v 1.17 2002/07/27 10:04:34 kcwu Exp $ */ +/* $Id: announce.c,v 1.18 2003/01/16 11:58:04 kcwu Exp $ */ #include "bbs.h" static void g_showmenu(gmenu_t * pm) { - static char *mytype = "編 選 絲路之旅"; + char *mytype = "編 選 絲路之旅"; char *title, ch; int n, max; item_t *item; @@ -762,7 +762,7 @@ a_additem(menu_t * pm, fileheader_t * myheader) static void a_newitem(menu_t * pm, int mode) { - static char *mesg[4] = { + char *mesg[4] = { "[新增文章] 請輸入標題:", /* ADDITEM */ "[新增目錄] 請輸入標題:", /* ADDGROUP */ "[新增連線] 請輸入標題:", /* ADDGOPHER */ diff --git a/pttbbs/mbbsd/board.c b/pttbbs/mbbsd/board.c index fadba9d8..98b88b87 100644 --- a/pttbbs/mbbsd/board.c +++ b/pttbbs/mbbsd/board.c @@ -1,4 +1,4 @@ -/* $Id: board.c,v 1.67 2003/01/15 09:11:47 kcwu Exp $ */ +/* $Id: board.c,v 1.68 2003/01/16 11:58:04 kcwu Exp $ */ #include "bbs.h" #define BRC_STRLEN 15 /* Length of board name */ #define BRC_MAXSIZE 24576 @@ -517,7 +517,7 @@ load_boards(char *key) } brdnum = 0; if (class_bid <= 0) { - static boardstat_t *tmp = NULL; + boardstat_t *tmp = NULL; nbrd = (boardstat_t *) malloc(sizeof(boardstat_t) * numboards); for (i = 0; i < numboards; i++) { if ((bptr = SHM->bsorted[type][i]) == NULL) @@ -657,10 +657,10 @@ show_brdlist(int head, int clsflag, int newflag) } if (brdnum > 0) { boardstat_t *ptr; - static char *color[8] = {"", "\033[32m", + char *color[8] = {"", "\033[32m", "\033[33m", "\033[36m", "\033[34m", "\033[1m", "\033[1;32m", "\033[1;33m"}; - static char *unread[2] = {"\33[37m \033[m", "\033[1;31mˇ\033[m"}; + char *unread[2] = {"\33[37m \033[m", "\033[1;31mˇ\033[m"}; while (++myrow < b_lines) { move(myrow, 0); diff --git a/pttbbs/mbbsd/cal.c b/pttbbs/mbbsd/cal.c index e4ecc8cf..48151b7c 100644 --- a/pttbbs/mbbsd/cal.c +++ b/pttbbs/mbbsd/cal.c @@ -1,4 +1,4 @@ -/* $Id: cal.c,v 1.20 2002/08/23 11:33:01 in2 Exp $ */ +/* $Id: cal.c,v 1.21 2003/01/16 11:58:04 kcwu Exp $ */ #include "bbs.h" /* 防堵 Multi play */ @@ -368,8 +368,8 @@ int give_tax(int money) { int i, tax = 0; - static int tax_bound[] = {1000000, 100000, 10000, 1000, 0}; - static double tax_rate[] = {0.4, 0.3, 0.2, 0.1, 0.08}; + int tax_bound[] = {1000000, 100000, 10000, 1000, 0}; + double tax_rate[] = {0.4, 0.3, 0.2, 0.1, 0.08}; for (i = 0; i <= 4; i++) if (money > tax_bound[i]) { tax += (money - tax_bound[i]) * tax_rate[i]; diff --git a/pttbbs/mbbsd/calendar.c b/pttbbs/mbbsd/calendar.c index c4b86e89..67524a91 100644 --- a/pttbbs/mbbsd/calendar.c +++ b/pttbbs/mbbsd/calendar.c @@ -1,4 +1,4 @@ -/* $Id: calendar.c,v 1.7 2002/12/31 17:40:51 in2 Exp $ */ +/* $Id: calendar.c,v 1.8 2003/01/16 11:58:04 kcwu Exp $ */ #include "bbs.h" typedef struct event_t { @@ -11,7 +11,7 @@ typedef struct event_t { static int MonthDay(int m, int leap) { - static int day[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; + int day[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; return leap && m == 2 ? 29 : day[m - 1]; } @@ -188,13 +188,13 @@ FreeCalBuffer(char **buf) static int GenerateCalendar(char **buf, int y, int m, int today, event_t * e) { - static char *week_str[7] = {"日", "一", "二", "三", "四", "五", "六"}; - static char *month_color[12] = { + char *week_str[7] = {"日", "一", "二", "三", "四", "五", "六"}; + char *month_color[12] = { "\33[1;32m", "\33[1;33m", "\33[1;35m", "\33[1;36m", "\33[1;32m", "\33[1;33m", "\33[1;35m", "\33[1;36m", "\33[1;32m", "\33[1;33m", "\33[1;35m", "\33[1;36m" }; - static char *month_str[12] = { + char *month_str[12] = { "一月 ", "二月 ", "三月 ", "四月 ", "五月 ", "六月 ", "七月 ", "八月 ", "九月 ", "十月 ", "十一月", "十二月" }; diff --git a/pttbbs/mbbsd/edit.c b/pttbbs/mbbsd/edit.c index ec20e7c1..354a2abb 100644 --- a/pttbbs/mbbsd/edit.c +++ b/pttbbs/mbbsd/edit.c @@ -1,4 +1,4 @@ -/* $Id: edit.c,v 1.24 2002/12/31 17:40:51 in2 Exp $ */ +/* $Id: edit.c,v 1.25 2003/01/16 11:58:04 kcwu Exp $ */ #include "bbs.h" typedef struct textline_t { struct textline_t *prev; @@ -102,7 +102,7 @@ n2ansi(int nx, textline_t * line) static void edit_msg() { - static char *edit_mode[2] = {"取代", "插入"}; + char *edit_mode[2] = {"取代", "插入"}; register int n = currpnt; if (my_ansimode) /* Thor: 作 ansi 編輯 */ @@ -1226,7 +1226,7 @@ search_str(int mode) static void match_paren() { - static char parens[] = "()[]{}"; + char *parens = "()[]{}"; int type; int parenum = 0; char *ptype; diff --git a/pttbbs/mbbsd/guess.c b/pttbbs/mbbsd/guess.c index 4c365708..c2203942 100644 --- a/pttbbs/mbbsd/guess.c +++ b/pttbbs/mbbsd/guess.c @@ -1,4 +1,4 @@ -/* $Id: guess.c,v 1.9 2003/01/10 17:23:48 kcwu Exp $ */ +/* $Id: guess.c,v 1.10 2003/01/16 11:58:04 kcwu Exp $ */ #include "bbs.h" #define LOGPASS BBSHOME "/etc/winguess.log" @@ -223,7 +223,7 @@ guess_main() int *n = NULL; char yournum[5]; char *flag = NULL; - static char TABLE[] = {0, 10, 8, 4, 2, 1, 0, 0, 0, 0, 0}; + char TABLE[] = {0, 10, 8, 4, 2, 1, 0, 0, 0, 0, 0}; FILE *file; clear(); diff --git a/pttbbs/mbbsd/menu.c b/pttbbs/mbbsd/menu.c index 0fe3bd60..89c82fea 100644 --- a/pttbbs/mbbsd/menu.c +++ b/pttbbs/mbbsd/menu.c @@ -1,4 +1,4 @@ -/* $Id: menu.c,v 1.19 2002/09/04 12:54:50 kcwu Exp $ */ +/* $Id: menu.c,v 1.20 2003/01/16 11:58:04 kcwu Exp $ */ #include "bbs.h" /* help & menu processring */ @@ -106,7 +106,7 @@ void movie(int i) { static short history[MAX_HISTORY]; - static char myweek[] = "天一二三四五六"; + char *myweek = "天一二三四五六"; const char *msgs[] = {"關閉", "打開", "拔掉", "防水", "好友"}; struct tm *ptime = localtime(&now); int j; diff --git a/pttbbs/mbbsd/more.c b/pttbbs/mbbsd/more.c index a1d82e42..46f77c87 100644 --- a/pttbbs/mbbsd/more.c +++ b/pttbbs/mbbsd/more.c @@ -1,4 +1,4 @@ -/* $Id: more.c,v 1.22 2002/12/31 17:40:51 in2 Exp $ */ +/* $Id: more.c,v 1.23 2003/01/16 11:58:04 kcwu Exp $ */ #include "bbs.h" #define MORE_BUFSIZE 4096 #define MORE_WINSIZE 4096 @@ -134,7 +134,7 @@ more_readln(int fd, unsigned char *buf) int more(char *fpath, int promptend) { - static char *head[4] = {"作者", "標題", "時間", "轉信"}; + char *head[4] = {"作者", "標題", "時間", "轉信"}; char *ptr, *word = NULL, buf[ANSILINELEN + 1]; struct stat st; diff --git a/pttbbs/mbbsd/register.c b/pttbbs/mbbsd/register.c index a138a4c3..29d9ad7d 100644 --- a/pttbbs/mbbsd/register.c +++ b/pttbbs/mbbsd/register.c @@ -1,4 +1,4 @@ -/* $Id: register.c,v 1.10 2002/11/30 04:51:13 in2 Exp $ */ +/* $Id: register.c,v 1.11 2003/01/16 11:58:04 kcwu Exp $ */ #define _XOPEN_SOURCE #include "bbs.h" @@ -139,7 +139,7 @@ int getnewuserid() { char genbuf[50]; - static char *fn_fresh = ".fresh"; + char *fn_fresh = ".fresh"; userec_t utmp, zerorec; time_t clock; struct stat st; diff --git a/pttbbs/mbbsd/stuff.c b/pttbbs/mbbsd/stuff.c index 76a3a032..41d5d93e 100644 --- a/pttbbs/mbbsd/stuff.c +++ b/pttbbs/mbbsd/stuff.c @@ -1,4 +1,4 @@ -/* $Id: stuff.c,v 1.9 2002/07/22 19:02:00 in2 Exp $ */ +/* $Id: stuff.c,v 1.10 2003/01/16 11:58:04 kcwu Exp $ */ #include "bbs.h" /* ----------------------------------------------------- */ @@ -191,7 +191,7 @@ invalid_pname(char *str) int valid_ident(char *ident) { - static char *invalid[] = {"unknown@", "root@", "gopher@", "bbs@", + char *invalid[] = {"unknown@", "root@", "gopher@", "bbs@", "@bbs", "guest@", "@ppp", "@slip", NULL}; char buf[128]; int i; diff --git a/pttbbs/mbbsd/talk.c b/pttbbs/mbbsd/talk.c index 6909d726..2bc1ac53 100644 --- a/pttbbs/mbbsd/talk.c +++ b/pttbbs/mbbsd/talk.c @@ -1,4 +1,4 @@ -/* $Id: talk.c,v 1.98 2003/01/14 11:19:39 in2 Exp $ */ +/* $Id: talk.c,v 1.99 2003/01/16 11:58:04 kcwu Exp $ */ #include "bbs.h" #define QCAST int (*)(const void *, const void *) @@ -81,7 +81,7 @@ char * modestring(userinfo_t * uentp, int simple) { static char modestr[40]; - static char *notonline = "不在站上"; + char *notonline = "不在站上"; register int mode = uentp->mode; register char *word; int fri_stat; @@ -348,10 +348,10 @@ my_query(char *uident) int tuid, i, fri_stat = 0; unsigned long int j; userinfo_t *uentp; - static const char *money[10] = + const char *money[10] = {"債台高築", "赤貧", "清寒", "普通", "小康", "小富", "中富", "大富翁", "富可敵國", "比爾蓋\天"}; - static const char *sex[8] = + const char *sex[8] = {MSG_BIG_BOY, MSG_BIG_GIRL, MSG_LITTLE_BOY, MSG_LITTLE_GIRL, MSG_MAN, MSG_WOMAN, MSG_PLANT, MSG_MIME}; @@ -1398,7 +1398,7 @@ t_showhelp() static char * friend_descript(userinfo_t * uentp) { - static char *space_buf = ""; + char *space_buf = ""; static char desc_buf[80]; char fpath[80], name[IDLEN + 2], *desc, *ptr; int len, flag; diff --git a/pttbbs/mbbsd/vote.c b/pttbbs/mbbsd/vote.c index 8a8faa63..70313920 100644 --- a/pttbbs/mbbsd/vote.c +++ b/pttbbs/mbbsd/vote.c @@ -1,4 +1,4 @@ -/* $Id: vote.c,v 1.16 2002/12/31 17:40:52 in2 Exp $ */ +/* $Id: vote.c,v 1.17 2003/01/16 11:58:05 kcwu Exp $ */ #include "bbs.h" static int total; @@ -322,7 +322,7 @@ b_close(boardheader_t * fh) int b_closepolls() { - static char *fn_vote_polling = ".polling"; + char *fn_vote_polling = ".polling"; boardheader_t *fhp; FILE *cfp; int pos, dirty; diff --git a/pttbbs/mbbsd/xyz.c b/pttbbs/mbbsd/xyz.c index dba8ad13..f00087f2 100644 --- a/pttbbs/mbbsd/xyz.c +++ b/pttbbs/mbbsd/xyz.c @@ -1,4 +1,4 @@ -/* $Id: xyz.c,v 1.12 2002/07/22 19:02:01 in2 Exp $ */ +/* $Id: xyz.c,v 1.13 2003/01/16 11:58:05 kcwu Exp $ */ #include "bbs.h" /* 各種統計及相關資訊列表 */ @@ -164,8 +164,8 @@ x_gpl() int note() { - static char *fn_note_tmp = "note.tmp"; - static char *fn_note_dat = "note.dat"; + char *fn_note_tmp = "note.tmp"; + char *fn_note_dat = "note.dat"; int total = 0, i, collect, len; struct stat st; char buf[256], buf2[80]; -- cgit v1.2.3 From 1ce4aec44c60de9fd9adc55631d00d1fda1cf2bd Mon Sep 17 00:00:00 2001 From: kcwu <kcwu@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Thu, 16 Jan 2003 12:23:03 +0000 Subject: eliminate global array save 800 byte git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@603 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/dice.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/pttbbs/mbbsd/dice.c b/pttbbs/mbbsd/dice.c index fae9d262..12572965 100644 --- a/pttbbs/mbbsd/dice.c +++ b/pttbbs/mbbsd/dice.c @@ -1,4 +1,4 @@ -/* $Id: dice.c,v 1.6 2002/07/22 19:02:00 in2 Exp $ */ +/* $Id: dice.c,v 1.7 2003/01/16 12:23:03 kcwu Exp $ */ #include "bbs.h" #define DICE_TXT BBSHOME "/etc/dice.txt" @@ -12,7 +12,6 @@ #define B_TIMES 5 #define B_THIRD 3 -static int flag[100], value[100]; typedef struct dicedata_t { int mybet; @@ -20,7 +19,7 @@ typedef struct dicedata_t { } dicedata_t; static void -set_bingo(int bet[]) +set_bingo(int flag[100],int bet[]) { int i, j = 0, k = 0, m = 0; @@ -65,7 +64,7 @@ set_bingo(int bet[]) } static int -bingo(int mybet) +bingo(int flag[100],int mybet) { return flag[mybet]; } @@ -123,7 +122,7 @@ show_data(void) } static void -show_count(int index, int money) +show_count(int value[100],int index, int money) { int i = 0, count = 2, j, k; @@ -178,7 +177,7 @@ check_index(int index) } static int -del(int total, dicedata_t * table) +del(int value[100],int total, dicedata_t * table) { int index, money; char data[10]; @@ -212,7 +211,7 @@ del(int total, dicedata_t * table) clrtoeol(); prints("你現在有 %u Ptt$歐", cuser.money); table[i].mymoney -= money; - show_count(index, -money); + show_count(value, index, -money); break; } } @@ -329,6 +328,7 @@ show_output(int bet[]) int dice_main(void) { + int flag[100], value[100]; char input[10], data[256], ch; dicedata_t table[256]; int bet[3], index, money = 0, i, ya = 0, j, total, sig = 0; @@ -374,7 +374,7 @@ dice_main(void) continue; } if (input[0] == 'd' || input[0] == 'D') { - del(i, table); + del(value, i, table); continue; } if (input[0] == 's' || input[0] == 'S') @@ -428,7 +428,7 @@ dice_main(void) prints("\033[1;32m你現在有 \033[1;31m%u\033[1;32m Ptt$歐", cuser.money); if (sig != 2) - show_count(index, money); + show_count(value,index, money); } if (i == 0) { @@ -438,12 +438,12 @@ dice_main(void) return 0; } show_output(bet); - set_bingo(bet); + set_bingo(flag, bet); for (j = 0; j < i; j++) { if (table[j].mymoney <= 0) continue; - ya = bingo(table[j].mybet); + ya = bingo(flag, table[j].mybet); if (ya == 0) { /* * sprintf(data, "%-15s 輸了 %-8d $", cuser.userid, -- cgit v1.2.3 From 1561ad75cd09735ed95019eeae0855cd9dcf6152 Mon Sep 17 00:00:00 2001 From: kcwu <kcwu@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Thu, 16 Jan 2003 12:27:54 +0000 Subject: don't link unused code -_- git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@604 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pttbbs/mbbsd/Makefile b/pttbbs/mbbsd/Makefile index 0a0c94f8..2a206efe 100644 --- a/pttbbs/mbbsd/Makefile +++ b/pttbbs/mbbsd/Makefile @@ -1,4 +1,4 @@ -# $Id: Makefile,v 1.14 2003/01/15 14:41:40 kcwu Exp $ +# $Id: Makefile,v 1.15 2003/01/16 12:27:54 kcwu Exp $ # 訂義基本初值 BBSHOME?= $(HOME) @@ -49,7 +49,7 @@ CFLAGS+= -DNO_FORK PROG= mbbsd OBJS= admin.o announce.o args.o bbs.o board.o cache.o cal.o card.o\ chat.o chc_draw.o chc_net.o chc_play.o chc_rule.o chicken.o dark.o\ - dice.o edit.o friend.o gamble.o gomo.o gomo1.o guess.o indict.o io.o\ + edit.o friend.o gamble.o gomo.o gomo1.o guess.o indict.o io.o\ kaede.o lovepaper.o mail.o mbbsd.o menu.o more.o name.o osdep.o\ othello.o page.o read.o record.o register.o screen.o stuff.o\ talk.o term.o topsong.o user.o vice.o vote.o xyz.o\ -- cgit v1.2.3 From 66864757981956771bff233dc5fbc62da4a5140f Mon Sep 17 00:00:00 2001 From: kcwu <kcwu@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Thu, 16 Jan 2003 12:33:38 +0000 Subject: don't link unused code -_- git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@605 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd.icc/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pttbbs/mbbsd.icc/Makefile b/pttbbs/mbbsd.icc/Makefile index c78d8f86..f40f420b 100644 --- a/pttbbs/mbbsd.icc/Makefile +++ b/pttbbs/mbbsd.icc/Makefile @@ -4,7 +4,7 @@ BBSHOME=/home/bbs PROG= mbbsd.icc OBJS= admin.o announce.o args.o bbs.o board.o cache.o cal.o card.o\ chat.o chc_draw.o chc_net.o chc_play.o chc_rule.o chicken.o dark.o\ - dice.o edit.o friend.o gamble.o gomo.o gomo1.o guess.o indict.o io.o\ + edit.o friend.o gamble.o gomo.o gomo1.o guess.o indict.o io.o\ kaede.o lovepaper.o mail.o mbbsd.o menu.o more.o name.o osdep.o\ othello.o page.o read.o record.o register.o screen.o stuff.o\ talk.o term.o topsong.o user.o vice.o vote.o xyz.o\ -- cgit v1.2.3 From a6e4b335f05b75a755532cf208cbab7f22db1796 Mon Sep 17 00:00:00 2001 From: kcwu <kcwu@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Thu, 16 Jan 2003 12:41:14 +0000 Subject: clean up git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@606 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/menu.c | 26 +------------------------- 1 file changed, 1 insertion(+), 25 deletions(-) diff --git a/pttbbs/mbbsd/menu.c b/pttbbs/mbbsd/menu.c index 89c82fea..309cb0ec 100644 --- a/pttbbs/mbbsd/menu.c +++ b/pttbbs/mbbsd/menu.c @@ -1,4 +1,4 @@ -/* $Id: menu.c,v 1.20 2003/01/16 11:58:04 kcwu Exp $ */ +/* $Id: menu.c,v 1.21 2003/01/16 12:41:14 kcwu Exp $ */ #include "bbs.h" /* help & menu processring */ @@ -358,9 +358,6 @@ static commands_t talklist[] = { {t_qchicken, 0, "WWatch Pet 查詢寵物"}, {t_talk, PERM_PAGE, "TTalk 找人聊聊"}, {t_chat, PERM_CHAT, "CChat 找家茶坊喫茶去"}, -#ifdef HAVE_MUD - {x_mud, 0, "VVrChat \033[1;32m虛擬實業聊天廣場\033[m"}, -#endif {t_display, 0, "DDisplay 顯示上幾次熱訊"}, {NULL, 0, NULL} }; @@ -478,27 +475,6 @@ static commands_t playlist[] = { {x_weather,0 , "WWeather 【 氣象預報 】"}, /* XXX 壞掉了 */ /* {x_stock,0 , "SStock 【 股市行情 】"},*/ -#ifdef HAVE_BIG2 - {x_big2, 0, "BBig2 【 網路大老二 】"}, -#endif -#ifdef HAVE_MJ - {x_mj, PERM_LOGINOK, "QQkmj 【 網路打麻將 】"}, -#endif -#ifdef HAVE_BRIDGE - {x_bridge, PERM_LOGINOK, "OOkBridge 【 橋牌競技 】"}, -#endif -#ifdef HAVE_GOPHER - {x_gopher, PERM_LOGINOK, "GGopher 【 地鼠資料庫 】"}, -#endif -#ifdef HAVE_TIN - {x_tin, PERM_LOGINOK, "NNEWS 【 網際新聞 】"}, -#endif -#ifdef BBSDOORS - {x_bbsnet, PERM_LOGINOK, "BBBSNet 【 其他 BBS站 】"}, -#endif -#ifdef HAVE_WWW - {x_www, PERM_LOGINOK, "WWWW Browser 【 汪汪汪 】"}, -#endif {forsearch,PERM_LOGINOK, "SSearchEngine【\033[1;35m Ptt搜尋器 \033[m】"}, {topsong,PERM_LOGINOK, "TTop Songs 【\033[1;32m歐桑點歌排行榜\033[m】"}, {p_money,PERM_LOGINOK, "PPay 【\033[1;31m Ptt量販店 \033[m】"}, -- cgit v1.2.3 From f41fbbb9af280205a52926cffe4af7503f4d5966 Mon Sep 17 00:00:00 2001 From: kcwu <kcwu@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Thu, 16 Jan 2003 12:59:48 +0000 Subject: reduce array size, save 360byte git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@607 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/chicken.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pttbbs/mbbsd/chicken.c b/pttbbs/mbbsd/chicken.c index 4744141e..d1938791 100644 --- a/pttbbs/mbbsd/chicken.c +++ b/pttbbs/mbbsd/chicken.c @@ -1,4 +1,4 @@ -/* $Id: chicken.c,v 1.9 2002/07/22 19:02:00 in2 Exp $ */ +/* $Id: chicken.c,v 1.10 2003/01/16 12:59:48 kcwu Exp $ */ #include "bbs.h" #define NUM_KINDS 13 /* 有多少種動物 */ @@ -48,7 +48,7 @@ enum { static chicken_t *mychicken = &cuser.mychicken; static int age; -static const int time_change[NUM_KINDS][14] = +static const short time_change[NUM_KINDS][14] = /* 補品 食物 體重 乾淨 敏捷 攻擊力 知識 快樂 滿意 氣質 疲勞 病氣 滿血 滿法 */ { /* 雞 */ -- cgit v1.2.3 From 1878c9944f58a85f6a7754118616137f667bafa0 Mon Sep 17 00:00:00 2001 From: kcwu <kcwu@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Thu, 16 Jan 2003 13:28:48 +0000 Subject: move post_msg() and post_file() from gamble.c to syspost.c git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@608 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/include/proto.h | 5 +++-- pttbbs/mbbsd/gamble.c | 56 +------------------------------------------------- pttbbs/mbbsd/syspost.c | 55 ++++++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 58 insertions(+), 58 deletions(-) diff --git a/pttbbs/include/proto.h b/pttbbs/include/proto.h index 4cfcef28..7d847285 100644 --- a/pttbbs/include/proto.h +++ b/pttbbs/include/proto.h @@ -1,4 +1,4 @@ -/* $Id: proto.h,v 1.32 2003/01/09 11:44:28 in2 Exp $ */ +/* $Id: proto.h,v 1.33 2003/01/16 13:28:48 kcwu Exp $ */ #ifndef INCLUDE_PROTO_H #define INCLUDE_PROTO_H @@ -213,7 +213,6 @@ void friend_delete(char *uident, int type); /* gamble */ int ticket_main(); -int post_msg(char* bname, char* title, char *msg, char* author); int openticket(int bid); int ticket(int bid); @@ -448,6 +447,8 @@ int userid_is_BM(char *userid, char *list); int is_uBM(char *list, char *id); /* syspost */ +int post_msg(char* bname, char* title, char *msg, char* author); +int post_file(char *bname, char *title, char *filename, char *author); void post_newboard(char *bgroup, char *bname, char *bms); void post_violatelaw(char *crime, char *police, char *reason, char *result); void post_change_perm(int oldperm, int newperm, char *sysopid, char *userid); diff --git a/pttbbs/mbbsd/gamble.c b/pttbbs/mbbsd/gamble.c index 8ade3999..ed4cb724 100644 --- a/pttbbs/mbbsd/gamble.c +++ b/pttbbs/mbbsd/gamble.c @@ -1,4 +1,4 @@ -/* $Id: gamble.c,v 1.29 2002/12/26 09:46:04 kcwu Exp $ */ +/* $Id: gamble.c,v 1.30 2003/01/16 13:28:48 kcwu Exp $ */ #include "bbs.h" #ifndef _BBS_UTIL_C_ @@ -9,60 +9,6 @@ static char betname[MAX_ITEM][MAX_ITEM_LEN]; static int currbid; -int -post_msg(char *bname, char *title, char *msg, char *author) -{ - FILE *fp; - int bid; - fileheader_t fhdr; - char genbuf[256]; - - /* 在 bname 板發表新文章 */ - snprintf(genbuf, sizeof(genbuf), "boards/%c/%s", bname[0], bname); - stampfile(genbuf, &fhdr); - fp = fopen(genbuf, "w"); - - if (!fp) - return -1; - - fprintf(fp, "作者: %s 看板: %s\n標題: %s \n", author, bname, title); - fprintf(fp, "時間: %s\n", ctime(&now)); - - /* 文章的內容 */ - fprintf(fp, "%s", msg); - fclose(fp); - - /* 將檔案加入列表 */ - strlcpy(fhdr.title, title, sizeof(fhdr.title)); - strlcpy(fhdr.owner, author, sizeof(fhdr.owner)); - setbdir(genbuf, bname); - if (append_record(genbuf, &fhdr, sizeof(fhdr)) != -1) - if ((bid = getbnum(bname)) > 0) - setbtotal(bid); - return 0; -} - -int -post_file(char *bname, char *title, char *filename, char *author) -{ - int size = dashs(filename); - char *msg; - FILE *fp; - - if (size <= 0) - return -1; - if (!(fp = fopen(filename, "r"))) - return -1; - msg = (char *)malloc(size + 1); - size = fread(msg, 1, size, fp); - msg[size] = 0; - size = post_msg(bname, title, msg, author); - fclose(fp); - free(msg); - return size; -} - - static int load_ticket_record(char *direct, int ticket[]) { diff --git a/pttbbs/mbbsd/syspost.c b/pttbbs/mbbsd/syspost.c index 36939485..a44ffdb3 100644 --- a/pttbbs/mbbsd/syspost.c +++ b/pttbbs/mbbsd/syspost.c @@ -1,6 +1,59 @@ -/* $Id: syspost.c,v 1.16 2002/11/15 05:56:10 lwms Exp $ */ +/* $Id: syspost.c,v 1.17 2003/01/16 13:28:48 kcwu Exp $ */ #include "bbs.h" +int +post_msg(char *bname, char *title, char *msg, char *author) +{ + FILE *fp; + int bid; + fileheader_t fhdr; + char genbuf[256]; + + /* 在 bname 板發表新文章 */ + snprintf(genbuf, sizeof(genbuf), "boards/%c/%s", bname[0], bname); + stampfile(genbuf, &fhdr); + fp = fopen(genbuf, "w"); + + if (!fp) + return -1; + + fprintf(fp, "作者: %s 看板: %s\n標題: %s \n", author, bname, title); + fprintf(fp, "時間: %s\n", ctime(&now)); + + /* 文章的內容 */ + fprintf(fp, "%s", msg); + fclose(fp); + + /* 將檔案加入列表 */ + strlcpy(fhdr.title, title, sizeof(fhdr.title)); + strlcpy(fhdr.owner, author, sizeof(fhdr.owner)); + setbdir(genbuf, bname); + if (append_record(genbuf, &fhdr, sizeof(fhdr)) != -1) + if ((bid = getbnum(bname)) > 0) + setbtotal(bid); + return 0; +} + +int +post_file(char *bname, char *title, char *filename, char *author) +{ + int size = dashs(filename); + char *msg; + FILE *fp; + + if (size <= 0) + return -1; + if (!(fp = fopen(filename, "r"))) + return -1; + msg = (char *)malloc(size + 1); + size = fread(msg, 1, size, fp); + msg[size] = 0; + size = post_msg(bname, title, msg, author); + fclose(fp); + free(msg); + return size; +} + void post_change_perm(int oldperm, int newperm, char *sysopid, char *userid) { -- cgit v1.2.3 From bb08f92f76be2a24f5101a8354038438a2d98cc0 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Thu, 16 Jan 2003 13:51:27 +0000 Subject: if SYSOP, show memory usage in system status git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@609 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/cal.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pttbbs/mbbsd/cal.c b/pttbbs/mbbsd/cal.c index 48151b7c..d3c00bdd 100644 --- a/pttbbs/mbbsd/cal.c +++ b/pttbbs/mbbsd/cal.c @@ -1,4 +1,4 @@ -/* $Id: cal.c,v 1.21 2003/01/16 11:58:04 kcwu Exp $ */ +/* $Id: cal.c,v 1.22 2003/01/16 13:51:27 in2 Exp $ */ #include "bbs.h" /* 防堵 Multi play */ @@ -431,6 +431,9 @@ p_sysinfo(void) MAX_ACTIVE, #endif COMPILE_TIME, ctime(&start_time)); + if (HAS_PERM(PERM_SYSOP)) { + prints("記憶體使用量: %d\n", ((int)sbrk(0) - 0x8048000) / 1024); + } pressanykey(); return 0; } -- cgit v1.2.3 From 67cfe98259eff4e68469e90beb24c0fed9d54d2e Mon Sep 17 00:00:00 2001 From: kcwu <kcwu@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Thu, 16 Jan 2003 13:52:25 +0000 Subject: who wrote this.... @@ ptr = pool; i = 0; do { i++; } while (++ptr < v); return i; git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@610 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/gomo.c | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/pttbbs/mbbsd/gomo.c b/pttbbs/mbbsd/gomo.c index 7822b090..bf9c9b97 100644 --- a/pttbbs/mbbsd/gomo.c +++ b/pttbbs/mbbsd/gomo.c @@ -1,4 +1,4 @@ -/* $Id: gomo.c,v 1.9 2002/07/22 19:02:00 in2 Exp $ */ +/* $Id: gomo.c,v 1.10 2003/01/16 13:52:25 kcwu Exp $ */ #include "bbs.h" static char *chess[] = {"●", "○"}; @@ -85,15 +85,7 @@ HO_log(char *user) static int countgomo() { - Horder_t *ptr; - int i; - - ptr = pool; - i = 0; - do { - i++; - } while (++ptr < v); - return i; + return v-pool; } static int -- cgit v1.2.3 From 1b2127e02850cd7a817cd34d54856a52392fa2a6 Mon Sep 17 00:00:00 2001 From: kcwu <kcwu@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Thu, 16 Jan 2003 14:14:12 +0000 Subject: move global array into local. git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@611 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/gamble.c | 11 ++++++----- pttbbs/mbbsd/gomo.c | 21 +++++++++++---------- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/pttbbs/mbbsd/gamble.c b/pttbbs/mbbsd/gamble.c index ed4cb724..d9b3ea2b 100644 --- a/pttbbs/mbbsd/gamble.c +++ b/pttbbs/mbbsd/gamble.c @@ -1,4 +1,4 @@ -/* $Id: gamble.c,v 1.30 2003/01/16 13:28:48 kcwu Exp $ */ +/* $Id: gamble.c,v 1.31 2003/01/16 14:14:12 kcwu Exp $ */ #include "bbs.h" #ifndef _BBS_UTIL_C_ @@ -6,7 +6,6 @@ #define MAX_ITEM_LEN 30 //最大 每一賭項名字長度 #define MAX_SUBJECT_LEN 650 //8*81 = 648 最大 主題長度 -static char betname[MAX_ITEM][MAX_ITEM_LEN]; static int currbid; static int @@ -25,7 +24,7 @@ load_ticket_record(char *direct, int ticket[]) } static int -show_ticket_data(char *direct, int *price, boardheader_t * bh) +show_ticket_data(char betname[MAX_ITEM][MAX_ITEM_LEN],char *direct, int *price, boardheader_t * bh) { int i, count, total = 0, end = 0, ticket[MAX_ITEM] = {0, 0, 0, 0, 0, 0, 0, 0}; FILE *fp; @@ -121,6 +120,7 @@ ticket(int bid) { int ch, n, price, count, end = 0; char path[128], fn_ticket[128]; + char betname[MAX_ITEM][MAX_ITEM_LEN]; boardheader_t *bh = NULL; if (bid) { @@ -133,7 +133,7 @@ ticket(int bid) lockreturn0(TICKET, LOCK_MULTI); while (1) { - count = show_ticket_data(path, &price, bh); + count = show_ticket_data(betname, path, &price, bh); if (count <= 0) { pressanykey(); break; @@ -177,9 +177,10 @@ openticket(int bid) int i, money = 0, count, bet, price, total = 0, ticket[8] = {0, 0, 0, 0, 0, 0, 0, 0}; boardheader_t *bh = getbcache(bid); FILE *fp, *fp1; + char betname[MAX_ITEM][MAX_ITEM_LEN]; setbpath(path, bh->brdname); - count = -show_ticket_data(path, &price, bh); + count = -show_ticket_data(betname, path, &price, bh); if (count == 0) { setbfile(buf, bh->brdname, FN_TICKET_END); unlink(buf); diff --git a/pttbbs/mbbsd/gomo.c b/pttbbs/mbbsd/gomo.c index bf9c9b97..b7665bae 100644 --- a/pttbbs/mbbsd/gomo.c +++ b/pttbbs/mbbsd/gomo.c @@ -1,4 +1,4 @@ -/* $Id: gomo.c,v 1.10 2003/01/16 13:52:25 kcwu Exp $ */ +/* $Id: gomo.c,v 1.11 2003/01/16 14:14:12 kcwu Exp $ */ #include "bbs.h" static char *chess[] = {"●", "○"}; @@ -9,12 +9,12 @@ typedef struct { char y; } Horder_t; -static Horder_t *v, pool[225]; +static Horder_t *v; static void -HO_init() +HO_init(Horder_t *pool) { - memset(pool, 0, sizeof(pool)); + memset(pool, 0, sizeof(Horder_t)*BRDSIZ*BRDSIZ); v = pool; pat = pat_gomoku; adv = adv_gomoku; @@ -43,7 +43,7 @@ HO_undo(Horder_t * mv) } static void -HO_log(char *user) +HO_log(Horder_t *pool, char *user) { int i; FILE *log; @@ -83,7 +83,7 @@ HO_log(char *user) } static int -countgomo() +countgomo(Horder_t *pool) { return v-pool; } @@ -166,8 +166,9 @@ gomoku(int fd) int me, he, win, ch; int hewantpass, iwantpass; userinfo_t *my = currutmp; + Horder_t pool[BRDSIZ*BRDSIZ]; - HO_init(); + HO_init(pool); me = !(my->turn) + 1; he = my->turn + 1; win = 1; @@ -247,7 +248,7 @@ gomoku(int fd) if (ch != I_OTHERDATA) iwantpass = 0; if (ch == 'q') { - if (countgomo() < 10) { + if (countgomo(pool) < 10) { cuser.five_lose--; passwd_update(usernum, &cuser); } @@ -292,7 +293,7 @@ gomoku(int fd) if (lastcount >= 0) { win = 1; cuser.five_lose--; - if (countgomo() >= 10) { + if (countgomo(pool) >= 10) { cuser.five_win++; my->five_win++; } @@ -394,7 +395,7 @@ gomoku(int fd) getdata(19, 0, "要保留本局成棋譜嗎?(y/N)", ans, sizeof(ans), LCECHO); if (*ans == 'y') - HO_log(my->mateid); + HO_log(pool, my->mateid); } return 0; } -- cgit v1.2.3 From 7102d46d7f9cfdae6baa350f1a6c6c64f862f96a Mon Sep 17 00:00:00 2001 From: kcwu <kcwu@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Thu, 16 Jan 2003 14:38:35 +0000 Subject: eliminate `static' array git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@612 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/include/proto.h | 4 ++-- pttbbs/mbbsd/guess.c | 10 +++++----- pttbbs/mbbsd/indict.c | 19 +++---------------- pttbbs/mbbsd/kaede.c | 7 +++---- pttbbs/mbbsd/mbbsd.c | 5 +++-- 5 files changed, 16 insertions(+), 29 deletions(-) diff --git a/pttbbs/include/proto.h b/pttbbs/include/proto.h index 7d847285..a844e483 100644 --- a/pttbbs/include/proto.h +++ b/pttbbs/include/proto.h @@ -1,4 +1,4 @@ -/* $Id: proto.h,v 1.33 2003/01/16 13:28:48 kcwu Exp $ */ +/* $Id: proto.h,v 1.34 2003/01/16 14:38:35 kcwu Exp $ */ #ifndef INCLUDE_PROTO_H #define INCLUDE_PROTO_H @@ -251,7 +251,7 @@ char getans(char *prompt); int Rename(char* src, char* dst); int Link(char* src, char* dst); char *Ptt_prints(char *str, int mode); -char *my_ctime(const time_t *t); +char *my_ctime(const time_t *t, char *ans, int len); /* lovepaper */ int x_love(); diff --git a/pttbbs/mbbsd/guess.c b/pttbbs/mbbsd/guess.c index c2203942..539388e2 100644 --- a/pttbbs/mbbsd/guess.c +++ b/pttbbs/mbbsd/guess.c @@ -1,4 +1,4 @@ -/* $Id: guess.c,v 1.10 2003/01/16 11:58:04 kcwu Exp $ */ +/* $Id: guess.c,v 1.11 2003/01/16 14:37:32 kcwu Exp $ */ #include "bbs.h" #define LOGPASS BBSHOME "/etc/winguess.log" @@ -75,11 +75,10 @@ check_data(char *str) } static char * -get_data(int count) +get_data(char data[5], int count) { - static char data[5]; while (1) { - getdata(6, 0, "輸入四位數字(不重複): ", data, sizeof(data), LCECHO); + getdata(6, 0, "輸入四位數字(不重複): ", data, 5, LCECHO); if (check_data(data) == 1) break; } @@ -215,6 +214,7 @@ Diff_Random(char *answer) int guess_main() { + char data[5]; unsigned long int money; char computerwin = 0, youwin = 0; int count = 0, c_count = 0; @@ -281,7 +281,7 @@ guess_main() prints("第 %d 次機會 ", count + 1); if (!youwin) { ++count; - if (guess_play(get_data(count), answer, count)) + if (guess_play(get_data(data, count), answer, count)) youwin = 1; } } diff --git a/pttbbs/mbbsd/indict.c b/pttbbs/mbbsd/indict.c index 14650fea..93d955a1 100644 --- a/pttbbs/mbbsd/indict.c +++ b/pttbbs/mbbsd/indict.c @@ -1,4 +1,4 @@ -/* $Id: indict.c,v 1.10 2002/07/27 13:50:57 kcwu Exp $ */ +/* $Id: indict.c,v 1.11 2003/01/16 14:37:31 kcwu Exp $ */ #include "bbs.h" #define REFER "etc/dicts" @@ -67,19 +67,6 @@ choose_dict(void) return 0; } -static char * -lower(char str[]) -{ - int c; - static char temp[200]; - - strcpy(temp, str); - for (c = 0; temp[c] != 0; c++) - if (temp[c] >= 'A' && temp[c] <= 'Z') - temp[c] += 'a' - 'A'; - return temp; -} - int use_dict() { @@ -109,7 +96,7 @@ use_dict() outs(lang); getdata(2, 0, ":", word, 18, DOECHO); outs("資料搜尋中請稍候...."); - strlcpy(word, lower(word), sizeof(word)); + str_lower(word, word); if (word[0] == 0) return 0; clear(); @@ -145,7 +132,7 @@ use_dict() f = 1; } else f = 0; - if (strstr(lower(lang), word)) { + if (strstr_lower(lang, word)) { if (f == 1) lang[65] = '['; outs(lang); diff --git a/pttbbs/mbbsd/kaede.c b/pttbbs/mbbsd/kaede.c index b5c1a25e..0bdc3ef0 100644 --- a/pttbbs/mbbsd/kaede.c +++ b/pttbbs/mbbsd/kaede.c @@ -1,4 +1,4 @@ -/* $Id: kaede.c,v 1.12 2002/07/22 19:02:00 in2 Exp $ */ +/* $Id: kaede.c,v 1.13 2003/01/16 14:38:35 kcwu Exp $ */ #include "bbs.h" char * @@ -88,13 +88,12 @@ Link(char *src, char *dst) } char * -my_ctime(const time_t * t) +my_ctime(const time_t * t, char *ans, int len) { struct tm *tp; - static char ans[100]; tp = localtime(t); - snprintf(ans, sizeof(ans), + snprintf(ans, len, "%02d/%02d/%02d %02d:%02d:%02d", (tp->tm_year % 100), tp->tm_mon + 1, tp->tm_mday, tp->tm_hour, tp->tm_min, tp->tm_sec); return ans; diff --git a/pttbbs/mbbsd/mbbsd.c b/pttbbs/mbbsd/mbbsd.c index 521673c5..74418777 100644 --- a/pttbbs/mbbsd/mbbsd.c +++ b/pttbbs/mbbsd/mbbsd.c @@ -1,4 +1,4 @@ -/* $Id: mbbsd.c,v 1.61 2003/01/14 11:19:39 in2 Exp $ */ +/* $Id: mbbsd.c,v 1.62 2003/01/16 14:38:35 kcwu Exp $ */ #include "bbs.h" #define SOCKET_QLEN 4 @@ -251,11 +251,12 @@ talk_request(int sig) bell(); if (currutmp->msgcount) { char buf[200]; + char timebuf[100]; time_t now = time(0); snprintf(buf, sizeof(buf), "\033[33;41m★%s\033[34;47m [%s] %s \033[0m", - SHM->uinfo[currutmp->destuip].userid, my_ctime(&now), + SHM->uinfo[currutmp->destuip].userid, my_ctime(&now,timebuf,sizeof(timebuf)), (currutmp->sig == 2) ? "重要消息廣播!(請Ctrl-U,l查看熱訊記錄)" : "呼叫、呼叫,聽到請回答"); move(0, 0); -- cgit v1.2.3 From e3f10d604963a9b356831d9efdf1643d4b944ef9 Mon Sep 17 00:00:00 2001 From: kcwu <kcwu@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Thu, 16 Jan 2003 14:47:43 +0000 Subject: clean up git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@613 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/mail.c | 25 +------------------------ 1 file changed, 1 insertion(+), 24 deletions(-) diff --git a/pttbbs/mbbsd/mail.c b/pttbbs/mbbsd/mail.c index 8fafa0c1..7f145867 100644 --- a/pttbbs/mbbsd/mail.c +++ b/pttbbs/mbbsd/mail.c @@ -1,4 +1,4 @@ -/* $Id: mail.c,v 1.23 2002/10/29 12:53:42 in2 Exp $ */ +/* $Id: mail.c,v 1.24 2003/01/16 14:47:43 kcwu Exp $ */ #include "bbs.h" char currmaildir[32]; static char msg_cc[] = "\033[32m[群組名單]\033[m\n"; @@ -1426,19 +1426,12 @@ send_inner_mail(char *fpath, char *title, char *receiver) static int bbs_sendmail(char *fpath, char *title, char *receiver) { - static int configured = 0; - static char myhostname[STRLEN]; - static char myusername[20]; - struct hostent *hbuf; - struct passwd *pbuf; char *ptr; char genbuf[256]; FILE *fin, *fout; /* 中途攔截 */ if ((ptr = strchr(receiver, ';'))) { - struct tm *ptime; - *ptr = '\0'; } if ((ptr = strstr(receiver, str_mail_address)) || !strchr(receiver, '@')) { @@ -1453,22 +1446,6 @@ bbs_sendmail(char *fpath, char *title, char *receiver) strlcpy(hacker, receiver, sizeof(hacker)); return send_inner_mail(fpath, title, hacker); } - /* setup the hostname and username */ - if (!configured) { - /* get host name */ - hbuf = gethostbyname("localhost"); - if (hbuf) - strncpy(myhostname, hbuf->h_name, STRLEN); - - /* get bbs uident */ - pbuf = getpwuid(getuid()); - if (pbuf) - strncpy(myusername, pbuf->pw_name, 20); - if (hbuf && pbuf) - configured = 1; - else - return -1; - } /* Running the sendmail */ if (fpath == NULL) { snprintf(genbuf, sizeof(genbuf), -- cgit v1.2.3 From 156f0db4aa2d21774742f042711d2b51e5dc6ca9 Mon Sep 17 00:00:00 2001 From: kcwu <kcwu@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Thu, 16 Jan 2003 15:49:57 +0000 Subject: garbage git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@614 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/BOARDS.bid | Bin 1006592 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 pttbbs/util/BOARDS.bid diff --git a/pttbbs/util/BOARDS.bid b/pttbbs/util/BOARDS.bid deleted file mode 100644 index 8d0312e5..00000000 Binary files a/pttbbs/util/BOARDS.bid and /dev/null differ -- cgit v1.2.3 From de169e16fd9f0731d709e36099abc3f5c9eb0884 Mon Sep 17 00:00:00 2001 From: kcwu <kcwu@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Thu, 16 Jan 2003 20:22:06 +0000 Subject: counting memory usage git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@615 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/xyz.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/pttbbs/mbbsd/xyz.c b/pttbbs/mbbsd/xyz.c index f00087f2..707ae02e 100644 --- a/pttbbs/mbbsd/xyz.c +++ b/pttbbs/mbbsd/xyz.c @@ -1,4 +1,4 @@ -/* $Id: xyz.c,v 1.13 2003/01/16 11:58:05 kcwu Exp $ */ +/* $Id: xyz.c,v 1.14 2003/01/16 20:22:06 kcwu Exp $ */ #include "bbs.h" /* 各種統計及相關資訊列表 */ @@ -332,6 +332,17 @@ m_sysop() return 0; } +void +log_memoryusage(void) +{ + int use=((int)sbrk(0)-0x8048000)/1024; + if(use<500) + use=499; + if(use>1000) + use=1000; + GLOBALVAR[use/100-4]++; // use [0]~[6] +} + int Goodbye() { @@ -353,6 +364,7 @@ Goodbye() else if (genbuf[0] == 'n') note(); } + log_memoryusage(); clear(); prints("\033[1;36m親愛的 \033[33m%s(%s)\033[36m,別忘了再度光臨\033[45;33m" " %s \033[40;36m!\n以下是您在站內的註冊資料:\033[0m\n", -- cgit v1.2.3 From 68630befaef74138775994f1269b906e8ad56992 Mon Sep 17 00:00:00 2001 From: kcwu <kcwu@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Fri, 17 Jan 2003 07:08:04 +0000 Subject: fix bug: access bache[-2] if sysop enter hot-board-list and hit 'f' git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@616 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/board.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pttbbs/mbbsd/board.c b/pttbbs/mbbsd/board.c index 98b88b87..4d5a42dc 100644 --- a/pttbbs/mbbsd/board.c +++ b/pttbbs/mbbsd/board.c @@ -1,4 +1,4 @@ -/* $Id: board.c,v 1.68 2003/01/16 11:58:04 kcwu Exp $ */ +/* $Id: board.c,v 1.69 2003/01/17 07:08:04 kcwu Exp $ */ #include "bbs.h" #define BRC_STRLEN 15 /* Length of board name */ #define BRC_MAXSIZE 24576 @@ -48,6 +48,7 @@ static char brc_buf[BRC_MAXSIZE]; static char brc_name[BRC_STRLEN]; static char *fn_boardrc = ".boardrc"; static int brc_size; +char *brc_buf_addr=brc_buf; void brc_update() @@ -927,7 +928,7 @@ choose_board(int newflag) break; case 'F': case 'f': - if (class_bid && HAS_PERM(PERM_SYSOP)) { + if (class_bid>0 && HAS_PERM(PERM_SYSOP)) { bcache[class_bid - 1].firstchild[cuser.uflag & BRDSORT_FLAG ? 1 : 0] = NULL; brdnum = -1; -- cgit v1.2.3 From d66d1361509acbb4452776eb5621051ebd9c2c08 Mon Sep 17 00:00:00 2001 From: kcwu <kcwu@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Fri, 17 Jan 2003 07:10:54 +0000 Subject: don't sort many times within loop -_- git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@617 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/board.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/pttbbs/mbbsd/board.c b/pttbbs/mbbsd/board.c index 4d5a42dc..58444c27 100644 --- a/pttbbs/mbbsd/board.c +++ b/pttbbs/mbbsd/board.c @@ -1,4 +1,4 @@ -/* $Id: board.c,v 1.69 2003/01/17 07:08:04 kcwu Exp $ */ +/* $Id: board.c,v 1.70 2003/01/17 07:10:54 kcwu Exp $ */ #include "bbs.h" #define BRC_STRLEN 15 /* Length of board name */ #define BRC_MAXSIZE 24576 @@ -532,10 +532,9 @@ load_boards(char *key) (class_bid == -1 && bptr->nuser < 5)) continue; addnewbrdstat(n, state); - - if (class_bid == -1) - qsort(nbrd, brdnum, sizeof(boardstat_t), cmpboardfriends); } + if (class_bid == -1) + qsort(nbrd, brdnum, sizeof(boardstat_t), cmpboardfriends); tmp = (boardstat_t *) malloc(sizeof(boardstat_t) * brdnum); memcpy(tmp, nbrd, sizeof(boardstat_t) * brdnum); free(nbrd); -- cgit v1.2.3 From 668ce01b03bd7e81c9cae1ce22f21df2d1c0a647 Mon Sep 17 00:00:00 2001 From: kcwu <kcwu@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Fri, 17 Jan 2003 07:14:14 +0000 Subject: Use realloc. Don't malloc, memcpy, and free. git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@618 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/board.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/pttbbs/mbbsd/board.c b/pttbbs/mbbsd/board.c index 58444c27..fa57f806 100644 --- a/pttbbs/mbbsd/board.c +++ b/pttbbs/mbbsd/board.c @@ -1,4 +1,4 @@ -/* $Id: board.c,v 1.70 2003/01/17 07:10:54 kcwu Exp $ */ +/* $Id: board.c,v 1.71 2003/01/17 07:14:14 kcwu Exp $ */ #include "bbs.h" #define BRC_STRLEN 15 /* Length of board name */ #define BRC_MAXSIZE 24576 @@ -518,7 +518,6 @@ load_boards(char *key) } brdnum = 0; if (class_bid <= 0) { - boardstat_t *tmp = NULL; nbrd = (boardstat_t *) malloc(sizeof(boardstat_t) * numboards); for (i = 0; i < numboards; i++) { if ((bptr = SHM->bsorted[type][i]) == NULL) @@ -535,10 +534,7 @@ load_boards(char *key) } if (class_bid == -1) qsort(nbrd, brdnum, sizeof(boardstat_t), cmpboardfriends); - tmp = (boardstat_t *) malloc(sizeof(boardstat_t) * brdnum); - memcpy(tmp, nbrd, sizeof(boardstat_t) * brdnum); - free(nbrd); - nbrd = tmp; + nbrd = realloc(nbrd, sizeof(boardstat_t) * brdnum); } else { nbrd = (boardstat_t *) malloc(bptr->childcount * sizeof(boardstat_t)); for (bptr = bptr->firstchild[type]; bptr != (boardheader_t *) ~ 0; -- cgit v1.2.3 From 59c5821cdce432639e9216a42b74942c3b447d03 Mon Sep 17 00:00:00 2001 From: kcwu <kcwu@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Fri, 17 Jan 2003 07:29:01 +0000 Subject: realloc to shrink array size, git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@619 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/board.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pttbbs/mbbsd/board.c b/pttbbs/mbbsd/board.c index fa57f806..c63dc3b8 100644 --- a/pttbbs/mbbsd/board.c +++ b/pttbbs/mbbsd/board.c @@ -1,4 +1,4 @@ -/* $Id: board.c,v 1.71 2003/01/17 07:14:14 kcwu Exp $ */ +/* $Id: board.c,v 1.72 2003/01/17 07:29:01 kcwu Exp $ */ #include "bbs.h" #define BRC_STRLEN 15 /* Length of board name */ #define BRC_MAXSIZE 24576 @@ -547,6 +547,7 @@ load_boards(char *key) continue; addnewbrdstat(n, state); } + nbrd = realloc(nbrd, sizeof(boardstat_t) * brdnum); } } -- cgit v1.2.3 From 086ef46c925a1d0d4792a24d5f34acce2e5ac3cd Mon Sep 17 00:00:00 2001 From: kcwu <kcwu@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Fri, 17 Jan 2003 07:47:10 +0000 Subject: fix memory leak git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@620 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/board.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/pttbbs/mbbsd/board.c b/pttbbs/mbbsd/board.c index c63dc3b8..cf6b0769 100644 --- a/pttbbs/mbbsd/board.c +++ b/pttbbs/mbbsd/board.c @@ -1,4 +1,4 @@ -/* $Id: board.c,v 1.72 2003/01/17 07:29:01 kcwu Exp $ */ +/* $Id: board.c,v 1.73 2003/01/17 07:47:10 kcwu Exp $ */ #include "bbs.h" #define BRC_STRLEN 15 /* Length of board name */ #define BRC_MAXSIZE 24576 @@ -517,6 +517,10 @@ load_boards(char *key) load_uidofgid(class_bid, type); } brdnum = 0; + if (nbrd) { + free(nbrd); + nbrd = NULL; + } if (class_bid <= 0) { nbrd = (boardstat_t *) malloc(sizeof(boardstat_t) * numboards); for (i = 0; i < numboards; i++) { @@ -1134,6 +1138,7 @@ choose_board(int newflag) tmp = currutmp->brc_id; setutmpbid(ptr->bid); free(nbrd); + nbrd = NULL; choose_board(0); currmode = currmodetmp; /* 離開板板後就把權限拿掉喔 */ num = tmp1; @@ -1145,6 +1150,7 @@ choose_board(int newflag) } } while (ch != 'q'); free(nbrd); + nbrd = NULL; } int -- cgit v1.2.3 From a85fb02f94cb7265127fe279c2bcf2314f955b9e Mon Sep 17 00:00:00 2001 From: kcwu <kcwu@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Fri, 17 Jan 2003 07:59:35 +0000 Subject: fix memory leak git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@621 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/guess.c | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/pttbbs/mbbsd/guess.c b/pttbbs/mbbsd/guess.c index 539388e2..ece753b4 100644 --- a/pttbbs/mbbsd/guess.c +++ b/pttbbs/mbbsd/guess.c @@ -1,4 +1,4 @@ -/* $Id: guess.c,v 1.11 2003/01/16 14:37:32 kcwu Exp $ */ +/* $Id: guess.c,v 1.12 2003/01/17 07:59:35 kcwu Exp $ */ #include "bbs.h" #define LOGPASS BBSHOME "/etc/winguess.log" @@ -286,9 +286,9 @@ guess_main() } } move(17, 35); + free(flag); + free(n); if (ifcomputer[0]) { - free(flag); - free(n); if (count > c_count) { prints("你輸給電腦了"); move(18, 35); @@ -302,9 +302,6 @@ guess_main() fprintf(file, "電腦賺走了%s %ld Ptt$\n", cuser.userid, money); fclose(file); } - unlockutmpmode(); - pressanykey(); - return 1; } else if (count < c_count) { prints("真厲害, 讓你賺到囉"); move(18, 35); @@ -316,9 +313,6 @@ guess_main() c_count, money * 2); fclose(file); } - unlockutmpmode(); - pressanykey(); - return 1; } else { prints("真厲害, 和電腦打成平手了, 拿回本錢%lu\n", money); demoney(money); @@ -326,10 +320,10 @@ guess_main() fprintf(file, "id: %s 和電腦打成了平手\n", cuser.userid); fclose(file); } - unlockutmpmode(); - pressanykey(); - return 1; } + unlockutmpmode(); + pressanykey(); + return 1; } if (youwin) { demoney(TABLE[count] * money); -- cgit v1.2.3 From 4be55551cb2c4cbad4b36b5dadd3a99860f301fb Mon Sep 17 00:00:00 2001 From: kcwu <kcwu@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Fri, 17 Jan 2003 08:16:21 +0000 Subject: clean up git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@622 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/read.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pttbbs/mbbsd/read.c b/pttbbs/mbbsd/read.c index cd0811e0..b926a852 100644 --- a/pttbbs/mbbsd/read.c +++ b/pttbbs/mbbsd/read.c @@ -1,4 +1,4 @@ -/* $Id: read.c,v 1.15 2002/11/07 14:22:34 in2 Exp $ */ +/* $Id: read.c,v 1.16 2003/01/17 08:16:21 kcwu Exp $ */ #include "bbs.h" #define MAXPATHLEN 256 @@ -188,7 +188,6 @@ getkeep(char *s, int def_topline, int def_cursline) { static struct keeploc_t *keeplist = NULL; struct keeploc_t *p; - void *malloc(); if (def_cursline >= 0) for (p = keeplist; p; p = p->next) { -- cgit v1.2.3 From 513e785dd6647f275fb21dcc3d6eec215a139759 Mon Sep 17 00:00:00 2001 From: kcwu <kcwu@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Fri, 17 Jan 2003 08:42:46 +0000 Subject: missing case break git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@623 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/board.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pttbbs/mbbsd/board.c b/pttbbs/mbbsd/board.c index cf6b0769..138b93a9 100644 --- a/pttbbs/mbbsd/board.c +++ b/pttbbs/mbbsd/board.c @@ -1,4 +1,4 @@ -/* $Id: board.c,v 1.73 2003/01/17 07:47:10 kcwu Exp $ */ +/* $Id: board.c,v 1.74 2003/01/17 08:42:46 kcwu Exp $ */ #include "bbs.h" #define BRC_STRLEN 15 /* Length of board name */ #define BRC_MAXSIZE 24576 @@ -1046,6 +1046,7 @@ choose_board(int newflag) break; } num = tmp; + break; case 'E': if (HAS_PERM(PERM_SYSOP) || (currmode & MODE_MENU)) { ptr = &nbrd[num]; -- cgit v1.2.3 From d194a664d5cadd9e69d15bc6d397108a4ae4528a Mon Sep 17 00:00:00 2001 From: kcwu <kcwu@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Fri, 17 Jan 2003 08:49:34 +0000 Subject: free namelist after using immediately git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@624 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/include/proto.h | 3 ++- pttbbs/mbbsd/board.c | 4 +++- pttbbs/mbbsd/name.c | 4 ++-- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/pttbbs/include/proto.h b/pttbbs/include/proto.h index a844e483..708353c8 100644 --- a/pttbbs/include/proto.h +++ b/pttbbs/include/proto.h @@ -1,4 +1,4 @@ -/* $Id: proto.h,v 1.34 2003/01/16 14:38:35 kcwu Exp $ */ +/* $Id: proto.h,v 1.35 2003/01/17 08:49:34 kcwu Exp $ */ #ifndef INCLUDE_PROTO_H #define INCLUDE_PROTO_H @@ -314,6 +314,7 @@ int more(char *fpath, int promptend); void usercomplete(char *prompt, char *data); void namecomplete(char *prompt, char *data); void AddNameList(char *name); +void FreeNameList(); void CreateNameList(); int chkstr(char *otag, char *tag, char *name); int InNameList(char *name); diff --git a/pttbbs/mbbsd/board.c b/pttbbs/mbbsd/board.c index 138b93a9..3ac9396c 100644 --- a/pttbbs/mbbsd/board.c +++ b/pttbbs/mbbsd/board.c @@ -1,4 +1,4 @@ -/* $Id: board.c,v 1.74 2003/01/17 08:42:46 kcwu Exp $ */ +/* $Id: board.c,v 1.75 2003/01/17 08:49:34 kcwu Exp $ */ #include "bbs.h" #define BRC_STRLEN 15 /* Length of board name */ #define BRC_MAXSIZE 24576 @@ -566,6 +566,8 @@ search_board() for (num = 0; num < brdnum; num++) AddNameList(nbrd[num].bh->brdname); namecomplete(MSG_SELECT_BOARD, genbuf); + FreeNameList(); + toplev = NULL; for (num = 0; num < brdnum; num++) if (!strcasecmp(nbrd[num].bh->brdname, genbuf)) diff --git a/pttbbs/mbbsd/name.c b/pttbbs/mbbsd/name.c index cbd872d9..ef1a4c5f 100644 --- a/pttbbs/mbbsd/name.c +++ b/pttbbs/mbbsd/name.c @@ -1,4 +1,4 @@ -/* $Id: name.c,v 1.14 2002/07/22 19:02:00 in2 Exp $ */ +/* $Id: name.c,v 1.15 2003/01/17 08:49:34 kcwu Exp $ */ #include "bbs.h" static word_t *current = NULL; @@ -42,7 +42,7 @@ UserSubArray(char cwbuf[][IDLEN + 1], char cwlist[][IDLEN + 1], return num; } -static void +void FreeNameList() { word_t *p, *temp; -- cgit v1.2.3 From 0f69fb11da15ece8b014bb65b20432b5b0dda00b Mon Sep 17 00:00:00 2001 From: kcwu <kcwu@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Fri, 17 Jan 2003 10:15:16 +0000 Subject: clean up git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@625 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/menu.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pttbbs/mbbsd/menu.c b/pttbbs/mbbsd/menu.c index 309cb0ec..9e234488 100644 --- a/pttbbs/mbbsd/menu.c +++ b/pttbbs/mbbsd/menu.c @@ -1,4 +1,4 @@ -/* $Id: menu.c,v 1.21 2003/01/16 12:41:14 kcwu Exp $ */ +/* $Id: menu.c,v 1.22 2003/01/17 10:15:16 kcwu Exp $ */ #include "bbs.h" /* help & menu processring */ @@ -182,7 +182,6 @@ domenu(int cmdmode, char *cmdtitle, int cmd, commands_t cmdtable[]) int lastcmdptr; int n, pos, total, i; int err; - int chkmailbox(); static char cmd0[LOGIN]; /* XXX: 傳進來的 cmd 若權限不足, 則不知 cursor 在哪, 導致 crash */ -- cgit v1.2.3 From c4c73d9c9f1008db77c55f60afade7ab6ce2ba9c Mon Sep 17 00:00:00 2001 From: kcwu <kcwu@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Fri, 17 Jan 2003 10:16:17 +0000 Subject: damn printf() buffer eat 36k memory git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@626 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/mbbsd.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pttbbs/mbbsd/mbbsd.c b/pttbbs/mbbsd/mbbsd.c index 74418777..e85215cc 100644 --- a/pttbbs/mbbsd/mbbsd.c +++ b/pttbbs/mbbsd/mbbsd.c @@ -1,4 +1,4 @@ -/* $Id: mbbsd.c,v 1.62 2003/01/16 14:38:35 kcwu Exp $ */ +/* $Id: mbbsd.c,v 1.63 2003/01/17 10:16:17 kcwu Exp $ */ #include "bbs.h" #define SOCKET_QLEN 4 @@ -802,7 +802,6 @@ user_login() if (access(buf, 0) < 0) break; } - printf("%d\n", nScreens); if (nScreens == 0) { //multi screen error ? more("etc/Welcome_login", NA); -- cgit v1.2.3 From 310758a8e3f89ed6c4848a2759e0221036e13369 Mon Sep 17 00:00:00 2001 From: kcwu <kcwu@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Fri, 17 Jan 2003 10:26:22 +0000 Subject: forget to fclose() git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@627 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/cache.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pttbbs/mbbsd/cache.c b/pttbbs/mbbsd/cache.c index f8cc453f..7016239b 100644 --- a/pttbbs/mbbsd/cache.c +++ b/pttbbs/mbbsd/cache.c @@ -1,4 +1,4 @@ -/* $Id: cache.c,v 1.54 2002/12/31 17:40:51 in2 Exp $ */ +/* $Id: cache.c,v 1.55 2003/01/17 10:26:22 kcwu Exp $ */ #include "bbs.h" #ifndef __FreeBSD__ @@ -1008,6 +1008,7 @@ reload_fcache() break; } } + fclose(fp); } SHM->max_user = 0; -- cgit v1.2.3 From da815dd1b43615e075061e322877678503ba981b Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sat, 18 Jan 2003 01:01:06 +0000 Subject: reduce memory usage of struct boardstat_t (saving 12 bytes for each board) suggested by kcwu git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@628 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/board.c | 108 ++++++++++++++++++++++++++------------------------- 1 file changed, 55 insertions(+), 53 deletions(-) diff --git a/pttbbs/mbbsd/board.c b/pttbbs/mbbsd/board.c index 3ac9396c..714e6b9f 100644 --- a/pttbbs/mbbsd/board.c +++ b/pttbbs/mbbsd/board.c @@ -1,4 +1,4 @@ -/* $Id: board.c,v 1.75 2003/01/17 08:49:34 kcwu Exp $ */ +/* $Id: board.c,v 1.76 2003/01/18 01:01:06 in2 Exp $ */ #include "bbs.h" #define BRC_STRLEN 15 /* Length of board name */ #define BRC_MAXSIZE 24576 @@ -213,10 +213,11 @@ brc_unread(char *fname, int bnum, int *blist) #define BRD_ZAP 4 #define BRD_TAG 8 +#define B_TOTAL(bptr) (SHM->total[(bptr)->bid - 1]) +#define B_LASTPOSTTIME(bptr) (SHM->lastposttime[(bptr)->bid - 1]) +#define B_BH(bptr) (&bcache[(bptr)->bid - 1]) typedef struct { - int bid, *total; - time_t *lastposttime; - boardheader_t *bh; + int bid; unsigned int myattr; } boardstat_t; @@ -425,19 +426,19 @@ check_newpost(boardstat_t * ptr) time_t ftime; ptr->myattr &= ~BRD_UNREAD; - if (ptr->bh->brdattr & BRD_GROUPBOARD) + if (B_BH(ptr)->brdattr & BRD_GROUPBOARD) return 0; - if (*(ptr->total) == 0) + if (B_TOTAL(ptr) == 0) setbtotal(ptr->bid); - if (*(ptr->total) == 0) + if (B_TOTAL(ptr) == 0) return 0; - ftime = *(ptr->lastposttime); + ftime = B_LASTPOSTTIME(ptr); read_brc_buf(); po = brc_buf; while (po < &brc_buf[brc_size] && (*po >= ' ' && *po <= 'z')) { po = brc_getrecord(po, bname, &tbrc_num, tbrc_list); - if (strncmp(bname, ptr->bh->brdname, BRC_STRLEN) == 0) { + if (strncmp(bname, B_BH(ptr)->brdname, BRC_STRLEN) == 0) { if (brc_unread_time(ftime, tbrc_num, tbrc_list)) { ptr->myattr |= BRD_UNREAD; } @@ -482,17 +483,17 @@ static boardstat_t * addnewbrdstat(int n, int state) { boardstat_t *ptr = &nbrd[brdnum++]; - boardheader_t *bptr = &bcache[n]; - ptr->total = &(SHM->total[n]); - ptr->lastposttime = &(SHM->lastposttime[n]); + //boardheader_t *bptr = &bcache[n]; + //ptr->total = &(SHM->total[n]); + //ptr->lastposttime = &(SHM->lastposttime[n]); ptr->bid = n + 1; ptr->myattr = 0; ptr->myattr = (favbuf[n] & ~BRD_ZAP); if (zapbuf[n] == 0) ptr->myattr |= BRD_ZAP; - ptr->bh = bptr; - if ((bptr->brdattr & BRD_HIDE) && state == 1) - bptr->brdattr |= BRD_POSTMASK; + //ptr->bh = bptr; + if ((B_BH(ptr)->brdattr & BRD_HIDE) && state == 1) + B_BH(ptr)->brdattr |= BRD_POSTMASK; check_newpost(ptr); return ptr; } @@ -500,7 +501,8 @@ addnewbrdstat(int n, int state) static int cmpboardfriends(const void *brd, const void *tmp) { - return ((boardstat_t *) tmp)->bh->nuser - ((boardstat_t *) brd)->bh->nuser; + return ((B_BH((boardstat_t*)tmp)->nuser) - + (B_BH((boardstat_t*)brd)->nuser)); } static void @@ -564,13 +566,13 @@ search_board() clrtoeol(); CreateNameList(); for (num = 0; num < brdnum; num++) - AddNameList(nbrd[num].bh->brdname); + AddNameList(B_BH(&nbrd[num])->brdname); namecomplete(MSG_SELECT_BOARD, genbuf); FreeNameList(); toplev = NULL; for (num = 0; num < brdnum; num++) - if (!strcasecmp(nbrd[num].bh->brdname, genbuf)) + if (!strcasecmp(B_BH(&nbrd[num])->brdname, genbuf)) return num; return -1; } @@ -582,10 +584,10 @@ unread_position(char *dirfile, boardstat_t * ptr) char fname[FNLEN]; register int num, fd, step, total; - total = *(ptr->total); + total = B_TOTAL(ptr); num = total + 1; if ((ptr->myattr & BRD_UNREAD) && (fd = open(dirfile, O_RDWR)) > 0) { - if (!brc_initial(ptr->bh->brdname)) { + if (!brc_initial(B_BH(ptr)->brdname)) { num = 1; } else { num = total - 1; @@ -674,21 +676,21 @@ show_brdlist(int head, int clsflag, int newflag) prints(" "); if (!newflag) { prints("%5d%c%s", head, - !(ptr->bh->brdattr & BRD_HIDE) ? ' ' : - (ptr->bh->brdattr & BRD_POSTMASK) ? ')' : '-', + !(B_BH(ptr)->brdattr & BRD_HIDE) ? ' ' : + (B_BH(ptr)->brdattr & BRD_POSTMASK) ? ')' : '-', (ptr->myattr & BRD_TAG) ? "D " : (ptr->myattr & BRD_ZAP) ? "- " : - (ptr->bh->brdattr & BRD_GROUPBOARD) ? " " : + (B_BH(ptr)->brdattr & BRD_GROUPBOARD) ? " " : unread[ptr->myattr & BRD_UNREAD]); } else if (ptr->myattr & BRD_ZAP) { ptr->myattr &= ~BRD_UNREAD; prints(" ﹣ ﹣"); } else { if (newflag) { - if ((ptr->bh->brdattr & BRD_GROUPBOARD)) + if ((B_BH(ptr)->brdattr & BRD_GROUPBOARD)) prints(" "); else - prints("%6d%s", (int)(*(ptr->total)), + prints("%6d%s", (int)(B_TOTAL(ptr)), unread[ptr->myattr & BRD_UNREAD]); } } @@ -696,28 +698,28 @@ show_brdlist(int head, int clsflag, int newflag) prints("%s%-13s\033[m%s%5.5s\033[0;37m%2.2s\033[m" "%-34.34s", (ptr->myattr & BRD_FAV) ? "\033[1;36m" : "", - ptr->bh->brdname, + B_BH(ptr)->brdname, color[(unsigned int) - (ptr->bh->title[1] + ptr->bh->title[2] + - ptr->bh->title[3] + ptr->bh->title[0]) & 07], - ptr->bh->title, ptr->bh->title + 5, ptr->bh->title + 7); + (B_BH(ptr)->title[1] + B_BH(ptr)->title[2] + + B_BH(ptr)->title[3] + B_BH(ptr)->title[0]) & 07], + B_BH(ptr)->title, B_BH(ptr)->title + 5, B_BH(ptr)->title + 7); - if (ptr->bh->brdattr & BRD_BAD) + if (B_BH(ptr)->brdattr & BRD_BAD) prints(" X "); - else if (ptr->bh->nuser >= 100) + else if (B_BH(ptr)->nuser >= 100) prints("\033[1mHOT\033[m"); - else if (ptr->bh->nuser > 50) - prints("\033[1;31m%2d\033[m ", ptr->bh->nuser); - else if (ptr->bh->nuser > 10) - prints("\033[1;33m%2d\033[m ", ptr->bh->nuser); - else if (ptr->bh->nuser > 0) - prints("%2d ", ptr->bh->nuser); + else if (B_BH(ptr)->nuser > 50) + prints("\033[1;31m%2d\033[m ", B_BH(ptr)->nuser); + else if (B_BH(ptr)->nuser > 10) + prints("\033[1;33m%2d\033[m ", B_BH(ptr)->nuser); + else if (B_BH(ptr)->nuser > 0) + prints("%2d ", B_BH(ptr)->nuser); else - prints(" %c ", ptr->bh->bvote ? 'V' : ' '); - prints("%.*s\033[K", t_columns - 67, ptr->bh->BM); + prints(" %c ", B_BH(ptr)->bvote ? 'V' : ' '); + prints("%.*s\033[K", t_columns - 67, B_BH(ptr)->BM); } else { - prints("%-40.40s %.*s", ptr->bh->title + 7, - t_columns - 67, ptr->bh->BM); + prints("%-40.40s %.*s", B_BH(ptr)->title + 7, + t_columns - 67, B_BH(ptr)->BM); } } clrtoeol(); @@ -767,7 +769,7 @@ dozap(int num) boardstat_t *ptr; ptr = &nbrd[num]; ptr->myattr ^= BRD_ZAP; - if (ptr->bh->brdattr & BRD_NOZAP) + if (B_BH(ptr)->brdattr & BRD_NOZAP) ptr->myattr &= ~BRD_ZAP; if (!(ptr->myattr & BRD_ZAP)) check_newpost(ptr); @@ -1028,7 +1030,7 @@ choose_board(int newflag) case 'v': case 'V': ptr = &nbrd[num]; - brc_initial(ptr->bh->brdname); + brc_initial(B_BH(ptr)->brdname); if (ch == 'v') { ptr->myattr &= ~BRD_UNREAD; zapchange = 1; @@ -1054,7 +1056,7 @@ choose_board(int newflag) ptr = &nbrd[num]; move(1, 1); clrtobot(); - m_mod_board(ptr->bh->brdname); + m_mod_board(B_BH(ptr)->brdname); brdnum = -1; } break; @@ -1089,10 +1091,10 @@ choose_board(int newflag) ptr = &nbrd[num]; - if (!(ptr->bh->brdattr & BRD_GROUPBOARD)) { /* 非sub class */ - if (!(ptr->bh->brdattr & BRD_HIDE) || - (ptr->bh->brdattr & BRD_POSTMASK)) { - brc_initial(ptr->bh->brdname); + if (!(B_BH(ptr)->brdattr & BRD_GROUPBOARD)) { /* 非sub class */ + if (!(B_BH(ptr)->brdattr & BRD_HIDE) || + (B_BH(ptr)->brdattr & BRD_POSTMASK)) { + brc_initial(B_BH(ptr)->brdname); if (newflag) { setbdir(buf, currboard); @@ -1110,7 +1112,7 @@ choose_board(int newflag) head = -1; setutmpmode(newflag ? READNEW : READBRD); } else { - setbfile(buf, ptr->bh->brdname, FN_APPLICATION); + setbfile(buf, B_BH(ptr)->brdname, FN_APPLICATION); if (more(buf, YEA) == -1) { move(1, 0); clrtobot(); @@ -1125,16 +1127,16 @@ choose_board(int newflag) currmodetmp = currmode; tmp1 = num; num = 0; - if (!(ptr->bh->brdattr & BRD_TOP)) + if (!(B_BH(ptr)->brdattr & BRD_TOP)) class_bid = ptr->bid; else class_bid = -1; /* 熱門群組用 */ if (!(currmode & MODE_MENU)) /* 如果還沒有小組長權限 */ - set_menu_BM(ptr->bh->BM); + set_menu_BM(B_BH(ptr)->BM); - if (now < ptr->bh->bupdate) { - setbfile(buf, ptr->bh->brdname, fn_notes); + if (now < B_BH(ptr)->bupdate) { + setbfile(buf, B_BH(ptr)->brdname, fn_notes); if (more(buf, NA) != -1) pressanykey(); } -- cgit v1.2.3 From 44626fc19363bd3306dd7a38dbcd3eb7aa0aa86e Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sat, 18 Jan 2003 11:54:19 +0000 Subject: reduce boardstatus_t git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@629 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/board.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pttbbs/mbbsd/board.c b/pttbbs/mbbsd/board.c index 714e6b9f..bf7c6cab 100644 --- a/pttbbs/mbbsd/board.c +++ b/pttbbs/mbbsd/board.c @@ -1,4 +1,4 @@ -/* $Id: board.c,v 1.76 2003/01/18 01:01:06 in2 Exp $ */ +/* $Id: board.c,v 1.77 2003/01/18 11:54:19 in2 Exp $ */ #include "bbs.h" #define BRC_STRLEN 15 /* Length of board name */ #define BRC_MAXSIZE 24576 @@ -218,8 +218,8 @@ brc_unread(char *fname, int bnum, int *blist) #define B_BH(bptr) (&bcache[(bptr)->bid - 1]) typedef struct { int bid; - unsigned int myattr; -} boardstat_t; + unsigned char myattr; +} __attribute__ ((packed)) boardstat_t; static int *zapbuf = NULL; static char *favbuf = NULL; -- cgit v1.2.3 From 49b617ff793a5118f9efaf0bf325cb3462b0c05b Mon Sep 17 00:00:00 2001 From: kcwu <kcwu@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sat, 18 Jan 2003 18:10:07 +0000 Subject: fix bug introduced in reversion 1.64 forget change pointer offset git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@630 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/board.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pttbbs/mbbsd/board.c b/pttbbs/mbbsd/board.c index bf7c6cab..44241fcc 100644 --- a/pttbbs/mbbsd/board.c +++ b/pttbbs/mbbsd/board.c @@ -1,4 +1,4 @@ -/* $Id: board.c,v 1.77 2003/01/18 11:54:19 in2 Exp $ */ +/* $Id: board.c,v 1.78 2003/01/18 18:10:07 kcwu Exp $ */ #include "bbs.h" #define BRC_STRLEN 15 /* Length of board name */ #define BRC_MAXSIZE 24576 @@ -354,7 +354,7 @@ save_brdbuf() close(fd); } #ifdef MEM_CHECK - free(&favbuf[-1]); + free(&favbuf[-sizeof(int)]); #else free(favbuf); #endif -- cgit v1.2.3 From 6738e3c8ddba7bd55901693bc3003ce8860650ae Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sun, 19 Jan 2003 00:17:19 +0000 Subject: skip null data git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@631 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/udnnews.pl | 1 + 1 file changed, 1 insertion(+) diff --git a/pttbbs/util/udnnews.pl b/pttbbs/util/udnnews.pl index 5e19ae88..07c49d4b 100644 --- a/pttbbs/util/udnnews.pl +++ b/pttbbs/util/udnnews.pl @@ -104,6 +104,7 @@ sub FormatChinese sub postout { my($param) = @_; + return if( !$param->{title} ); open FH, ">/tmp/postout.$$"; print FH $param->{content}; close FH; -- cgit v1.2.3 From bc4f16528510496070a05a300c0ceed15c1e5032 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sun, 19 Jan 2003 01:29:40 +0000 Subject: critical memory usage git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@632 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/include/proto.h | 5 ++++- pttbbs/mbbsd/board.c | 57 ++++++++++++++++++++++++++++++++++++++++++++++---- pttbbs/mbbsd/mbbsd.c | 5 ++++- 3 files changed, 61 insertions(+), 6 deletions(-) diff --git a/pttbbs/include/proto.h b/pttbbs/include/proto.h index 708353c8..20963df0 100644 --- a/pttbbs/include/proto.h +++ b/pttbbs/include/proto.h @@ -1,4 +1,4 @@ -/* $Id: proto.h,v 1.35 2003/01/17 08:49:34 kcwu Exp $ */ +/* $Id: proto.h,v 1.36 2003/01/19 01:29:39 in2 Exp $ */ #ifndef INCLUDE_PROTO_H #define INCLUDE_PROTO_H @@ -69,6 +69,9 @@ int Boards(); int root_board(); void save_brdbuf(void); void init_brdbuf(void); +#ifdef CRITICAL_MEMORY +void sigfree(int); +#endif /* cache */ int moneyof(int uid); diff --git a/pttbbs/mbbsd/board.c b/pttbbs/mbbsd/board.c index 44241fcc..33ef661d 100644 --- a/pttbbs/mbbsd/board.c +++ b/pttbbs/mbbsd/board.c @@ -1,4 +1,4 @@ -/* $Id: board.c,v 1.78 2003/01/18 18:10:07 kcwu Exp $ */ +/* $Id: board.c,v 1.79 2003/01/19 01:29:40 in2 Exp $ */ #include "bbs.h" #define BRC_STRLEN 15 /* Length of board name */ #define BRC_MAXSIZE 24576 @@ -224,12 +224,45 @@ typedef struct { static int *zapbuf = NULL; static char *favbuf = NULL; static boardstat_t *nbrd = NULL; -char zapchange = 0, favchange = 0; +char zapchange = 0, favchange = 0, choose_board_depth = 0; #define STR_BBSRC ".bbsrc" #define STR_FAV ".fav" #define STR_FAV2 ".fav2" +#ifdef CRITICAL_MEMORY +void *MALLOC(int size) +{ + int *p; + p = (int *)mmap(NULL, (size + 4), PROT_READ | PROT_WRITE, MAP_ANON, -1, 0); + p[0] = size; +#ifdef DEBUG + vmsg("critical malloc %d bytes", size); +#endif + return (void *)&p[1]; +} + +void FREE(void *ptr) +{ + int size = ((int *)ptr)[-1]; + munmap((void *)(&(((int *)ptr)[-1])), size); +#ifdef DEBUG + vmsg("critical free %d bytes", size); +#endif +} + +void sigfree(int sig) +{ + vmsg("SIG_FREE"); + if( !choose_board_depth ){ + vmsg("save"); + save_brdbuf(); + } + else + vmsg("nosave"); +} +#endif + void load_brdbuf(void) { static char firsttime = 1; @@ -242,8 +275,14 @@ void load_brdbuf(void) size += sizeof(int); favsize += sizeof(int); #endif + +#ifdef CRITICAL_MEMORY + zapbuf = (int *)MALLOC(size); +#else zapbuf = (int *)malloc(size); +#endif favbuf = (char *)malloc(favsize); + #ifdef MEM_CHECK zapbuf[0] = MEM_CHECK; zapbuf = &zapbuf[1]; @@ -311,7 +350,7 @@ init_brdbuf() } void -save_brdbuf() +save_brdbuf(void) { int fd, size; char fname[60]; @@ -334,9 +373,17 @@ save_brdbuf() close(fd); } #ifdef MEM_CHECK +# ifdef CRITICAL_MEMORY + FREE(&zapbuf[-1]); +# else free(&zapbuf[-1]); +# endif #else +# ifdef CRITICAL_MEMORY + FREE(zapbuf); +# else free(zapbuf); +# endif #endif zapbuf = NULL; } @@ -360,6 +407,7 @@ save_brdbuf() #endif favbuf = NULL; } + reentrant = 0; } int @@ -777,7 +825,6 @@ dozap(int num) zapbuf[ptr->bid - 1] = (ptr->myattr & BRD_ZAP ? 0 : login_start_time); } - static void choose_board(int newflag) { @@ -789,6 +836,7 @@ choose_board(int newflag) setutmpmode(newflag ? READNEW : READBRD); if( zapbuf == NULL || favbuf == NULL ) load_brdbuf(); + ++choose_board_depth; brdnum = 0; if (!cuser.userlevel) /* guest yank all boards */ yank_flag = 2; @@ -1156,6 +1204,7 @@ choose_board(int newflag) } while (ch != 'q'); free(nbrd); nbrd = NULL; + --choose_board_depth; } int diff --git a/pttbbs/mbbsd/mbbsd.c b/pttbbs/mbbsd/mbbsd.c index e85215cc..f0431a12 100644 --- a/pttbbs/mbbsd/mbbsd.c +++ b/pttbbs/mbbsd/mbbsd.c @@ -1,4 +1,4 @@ -/* $Id: mbbsd.c,v 1.63 2003/01/17 10:16:17 kcwu Exp $ */ +/* $Id: mbbsd.c,v 1.64 2003/01/19 01:29:40 in2 Exp $ */ #include "bbs.h" #define SOCKET_QLEN 4 @@ -942,6 +942,9 @@ start_client() signal(SIGFPE, abort_bbs_debug); signal(SIGBUS, abort_bbs_debug); signal(SIGSEGV, abort_bbs_debug); +#ifdef CRITICAL_MEMORY + signal(CMSIGNAL, sigfree); +#endif signal_restart(SIGUSR1, talk_request); signal_restart(SIGUSR2, write_request); -- cgit v1.2.3 From dce979528f9e301eed0157bec2862310a7fea58b Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sun, 19 Jan 2003 01:44:35 +0000 Subject: critical memory clean git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@633 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/shmctl.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/pttbbs/util/shmctl.c b/pttbbs/util/shmctl.c index 72b7174b..5e58654e 100644 --- a/pttbbs/util/shmctl.c +++ b/pttbbs/util/shmctl.c @@ -1,4 +1,4 @@ -/* $Id: shmctl.c,v 1.29 2002/11/05 14:18:47 in2 Exp $ */ +/* $Id: shmctl.c,v 1.30 2003/01/19 01:44:35 in2 Exp $ */ #include "bbs.h" extern SHM_t *SHM; @@ -317,6 +317,22 @@ int listpid(int argc, char **argv) return 0; } +#ifdef CRITICAL_MEMORY +int cmsignal(int argc, char **argv) +{ + int i; + time_t timebound = time(NULL) - 1200; + char buf[32]; + for( i = 0 ; i < USHM_SIZE ; ++i ) + if( SHM->uinfo[i].pid > 0 && SHM->uinfo[i].lastact < timebound ){ + printf("CMSIGNAL: pid: %6d, lastact: %s\n", + SHM->uinfo[i].pid, CTIMEx(buf, SHM->uinfo[i].lastact)); + kill(SHM->uinfo[i].pid, CMSIGNAL); + } + return 0; +} +#endif + struct { int (*func)(int, char **); char *cmd, *descript; @@ -330,6 +346,9 @@ struct { {showglobal, "showglobal", "show GLOBALVAR[]"}, {setglobal, "setglobal", "set GLOBALVAR[]"}, {listpid, "listpid", "list all pids of mbbsd"}, +#ifdef CRITICAL_MEMORY + {cmsignal, "cmsignal", "send cmsignal"}, +#endif {NULL, NULL, NULL} }; int main(int argc, char **argv) -- cgit v1.2.3 From 079f4d118782dad0ca8ff21e99ee53f423568944 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sun, 19 Jan 2003 01:44:49 +0000 Subject: fix bug git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@634 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/board.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/pttbbs/mbbsd/board.c b/pttbbs/mbbsd/board.c index 33ef661d..52fef094 100644 --- a/pttbbs/mbbsd/board.c +++ b/pttbbs/mbbsd/board.c @@ -1,4 +1,4 @@ -/* $Id: board.c,v 1.79 2003/01/19 01:29:40 in2 Exp $ */ +/* $Id: board.c,v 1.80 2003/01/19 01:44:49 in2 Exp $ */ #include "bbs.h" #define BRC_STRLEN 15 /* Length of board name */ #define BRC_MAXSIZE 24576 @@ -253,13 +253,8 @@ void FREE(void *ptr) void sigfree(int sig) { - vmsg("SIG_FREE"); - if( !choose_board_depth ){ - vmsg("save"); + if( !choose_board_depth ) save_brdbuf(); - } - else - vmsg("nosave"); } #endif -- cgit v1.2.3 From 7230c889931d6f92e0dc18906f596811c11f8141 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sun, 19 Jan 2003 01:55:17 +0000 Subject: comments for CRITICAL_MEMORY git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@635 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/sample/pttbbs.conf | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/pttbbs/sample/pttbbs.conf b/pttbbs/sample/pttbbs.conf index 9dda2061..9a2f1433 100644 --- a/pttbbs/sample/pttbbs.conf +++ b/pttbbs/sample/pttbbs.conf @@ -57,12 +57,20 @@ /* 程式最多可以跑多久 (in min) 因為有的時候會出現跑不停的 process */ #define CPULIMIT 1 -/* 若程式失敗, 會等待 86400 秒以讓 gdb來 attach */ +/* 若定義, 若程式失敗, 會等待 86400 秒以讓 gdb來 attach */ #define DEBUGSLEEP -/* 用一個奇怪的數字來檢查我的最愛和看板列表是否錯誤 */ +/* 若定義, 用一個奇怪的數字來檢查我的最愛和看板列表是否錯誤 */ #define MEM_CHECK 0x98761234 +/* 若定義, 則可在外部 (shmctl cmsignal) 要求將 mbbsd將 zapbuf 釋放掉. + 會使用非正規的記憶體要求函式. (目前只在 FreeBSD上測試過) + !!請注意!! + 除非您確切知道這個能能在做什麼並且有須要, + 否則請不要打開這個功能!! */ +//#define CRITICAL_MEMORY +//#define CMSIGNAL SIGINFO + /* 前進站畫面 */ #define INSCREEN \ -"前站站畫面" +"前進站畫面 (請至 pttbbs.conf 修改您的前進站畫面)" -- cgit v1.2.3 From d05f3cb0524d9e170cd4145d9a6043933f19d4e8 Mon Sep 17 00:00:00 2001 From: kcwu <kcwu@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sun, 19 Jan 2003 13:24:14 +0000 Subject: add some assert() code, but disable first. git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@636 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/include/bbs.h | 1 + pttbbs/mbbsd/Makefile | 5 ++++- pttbbs/mbbsd/io.c | 3 ++- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/pttbbs/include/bbs.h b/pttbbs/include/bbs.h index a83cd84f..87b038a7 100644 --- a/pttbbs/include/bbs.h +++ b/pttbbs/include/bbs.h @@ -4,6 +4,7 @@ #include <stdio.h> #include <string.h> +#include <assert.h> #include <stdlib.h> #include <stdarg.h> #include <setjmp.h> diff --git a/pttbbs/mbbsd/Makefile b/pttbbs/mbbsd/Makefile index 2a206efe..1cd74870 100644 --- a/pttbbs/mbbsd/Makefile +++ b/pttbbs/mbbsd/Makefile @@ -1,4 +1,4 @@ -# $Id: Makefile,v 1.15 2003/01/16 12:27:54 kcwu Exp $ +# $Id: Makefile,v 1.16 2003/01/19 13:24:14 kcwu Exp $ # 訂義基本初值 BBSHOME?= $(HOME) @@ -12,6 +12,9 @@ LIBS+= -lcrypt # 在 CFLAGS內加入定義 COMPILE_TIME CFLAGS+= "-DCOMPILE_TIME=\"`date`\"" +# 稍後再 enable assert() +CFLAGS+= -DNDEBUG + # FreeBSD特有的環境 CFLAGS_FreeBSD= -DHAVE_SETPROCTITLE -DFreeBSD LDFLAGS_FreeBSD= diff --git a/pttbbs/mbbsd/io.c b/pttbbs/mbbsd/io.c index 9b34bd12..1629f7cb 100644 --- a/pttbbs/mbbsd/io.c +++ b/pttbbs/mbbsd/io.c @@ -1,4 +1,4 @@ -/* $Id: io.c,v 1.26 2003/01/15 09:41:19 in2 Exp $ */ +/* $Id: io.c,v 1.27 2003/01/19 13:24:14 kcwu Exp $ */ #include "bbs.h" #if defined(linux) @@ -37,6 +37,7 @@ output(char *s, int len) { /* Invalid if len >= OBUFSIZE */ + assert(len<OBUFSIZE); if (obufsize + len > OBUFSIZE) { write(1, outbuf, obufsize); obufsize = 0; -- cgit v1.2.3 From de7a373cd0657189ccd04baae24d7f4538ab1d95 Mon Sep 17 00:00:00 2001 From: kcwu <kcwu@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sun, 19 Jan 2003 16:02:25 +0000 Subject: gcc -W, for more warning git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@637 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pttbbs/mbbsd/Makefile b/pttbbs/mbbsd/Makefile index 1cd74870..85e695f0 100644 --- a/pttbbs/mbbsd/Makefile +++ b/pttbbs/mbbsd/Makefile @@ -1,11 +1,11 @@ -# $Id: Makefile,v 1.16 2003/01/19 13:24:14 kcwu Exp $ +# $Id: Makefile,v 1.17 2003/01/19 16:02:25 kcwu Exp $ # 訂義基本初值 BBSHOME?= $(HOME) BBSHOME?= /home/bbs OSTYPE?= FreeBSD CC?= gcc -CFLAGS+= -Wall -pipe -DBBSHOME='"$(BBSHOME)"' -I../include +CFLAGS+= -Wall -W -pipe -DBBSHOME='"$(BBSHOME)"' -I../include LDFLAGS+= -pipe -Wall LIBS+= -lcrypt -- cgit v1.2.3 From 76c31483e0955d13ff9ff995a2e6c56d3bfd310f Mon Sep 17 00:00:00 2001 From: kcwu <kcwu@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sun, 19 Jan 2003 16:06:06 +0000 Subject: * there are so many fopen() without fclose() * assert fopen() * clean up git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@638 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/admin.c | 13 ++++++++++--- pttbbs/mbbsd/cal.c | 3 ++- pttbbs/mbbsd/edit.c | 6 ++++-- pttbbs/mbbsd/friend.c | 15 +++++++++------ pttbbs/mbbsd/gamble.c | 4 ++-- pttbbs/mbbsd/gomo.c | 3 ++- pttbbs/mbbsd/indict.c | 3 ++- pttbbs/mbbsd/lovepaper.c | 4 +++- pttbbs/mbbsd/mail.c | 10 +++++++--- pttbbs/mbbsd/page.c | 4 ++-- pttbbs/mbbsd/syspost.c | 5 +++-- pttbbs/mbbsd/user.c | 8 ++++++-- pttbbs/mbbsd/vice.c | 6 +++--- pttbbs/mbbsd/vote.c | 39 +++++++++++++++++++++------------------ pttbbs/mbbsd/voteboard.c | 3 ++- pttbbs/mbbsd/xyz.c | 13 +++++++++---- 16 files changed, 87 insertions(+), 52 deletions(-) diff --git a/pttbbs/mbbsd/admin.c b/pttbbs/mbbsd/admin.c index 3b41802f..b1d48245 100644 --- a/pttbbs/mbbsd/admin.c +++ b/pttbbs/mbbsd/admin.c @@ -1,4 +1,4 @@ -/* $Id: admin.c,v 1.30 2003/01/16 11:58:04 kcwu Exp $ */ +/* $Id: admin.c,v 1.31 2003/01/19 16:06:05 kcwu Exp $ */ #include "bbs.h" /* 使用者管理 */ @@ -35,6 +35,7 @@ search_key_user(char *passwdfile, int mode) FILE *fp1 = fopen(passwdfile, "r"); char buf[128], key[22], genbuf[8]; + assert(fp1); clear(); getdata(0, 0, mode ? "請輸入使用者關鍵字[電話|地址|姓名|上站地點|" "email|小雞id] :" : "請輸入id :", key, sizeof(key), DOECHO); @@ -66,12 +67,15 @@ search_key_user(char *passwdfile, int mode) while ((ch = igetch()) == 0); if (ch == ' ') break; - if (ch == 'q' || ch == 'Q') + if (ch == 'q' || ch == 'Q') { + fclose(fp1); return 0; + } if (ch == 's' && !mode) { if ((ch = searchuser(user.userid))) { setumoney(ch, user.money); passwd_update(ch, &user); + fclose(fp1); return 0; } else { move(b_lines - 1, 0); @@ -98,6 +102,7 @@ search_key_user(char *passwdfile, int mode) fprintf(stderr, "無法建立帳號\n"); exit(1); } + fclose(fp1); return 0; } } @@ -1080,8 +1085,10 @@ give_money() prints("編紅包袋內容"); pressanykey(); - if (vedit("etc/givemoney.why", NA, NULL) < 0) + if (vedit("etc/givemoney.why", NA, NULL) < 0) { + fclose(fp2); return 1; + } stand_title("發錢中..."); if (to_all) { diff --git a/pttbbs/mbbsd/cal.c b/pttbbs/mbbsd/cal.c index d3c00bdd..fe35bd7e 100644 --- a/pttbbs/mbbsd/cal.c +++ b/pttbbs/mbbsd/cal.c @@ -1,4 +1,4 @@ -/* $Id: cal.c,v 1.22 2003/01/16 13:51:27 in2 Exp $ */ +/* $Id: cal.c,v 1.23 2003/01/19 16:06:06 kcwu Exp $ */ #include "bbs.h" /* 防堵 Multi play */ @@ -182,6 +182,7 @@ osong(char *defaultid) prints("%s", buf); pressanykey(); fclose(fp); + fclose(fp1); unlockutmpmode(); return 0; } diff --git a/pttbbs/mbbsd/edit.c b/pttbbs/mbbsd/edit.c index 354a2abb..f585fab8 100644 --- a/pttbbs/mbbsd/edit.c +++ b/pttbbs/mbbsd/edit.c @@ -1,4 +1,4 @@ -/* $Id: edit.c,v 1.25 2003/01/16 11:58:04 kcwu Exp $ */ +/* $Id: edit.c,v 1.26 2003/01/19 16:06:06 kcwu Exp $ */ #include "bbs.h" typedef struct textline_t { struct textline_t *prev; @@ -460,10 +460,11 @@ delete_char() } static void -load_file(FILE * fp) +load_file(FILE * fp) /* NOTE it will fclose(fp) */ { int indent_mode0 = indent_mode; + assert(fp); indent_mode = 0; while (fgets(line, WRAPMARGIN + 2, fp)) insert_string(line); @@ -972,6 +973,7 @@ write_file(char *fpath, int saveheader, int *islocal) for (p = firstline; p; p = v) { v = p->next; if (!aborted) { + assert(fp); msg = p->data; if (v || msg[0]) { trim(msg); diff --git a/pttbbs/mbbsd/friend.c b/pttbbs/mbbsd/friend.c index 15a00c50..88cc28f7 100644 --- a/pttbbs/mbbsd/friend.c +++ b/pttbbs/mbbsd/friend.c @@ -1,4 +1,4 @@ -/* $Id: friend.c,v 1.14 2002/12/31 17:40:51 in2 Exp $ */ +/* $Id: friend.c,v 1.15 2003/01/19 16:06:06 kcwu Exp $ */ #include "bbs.h" /* ------------------------------------- */ @@ -118,11 +118,13 @@ friend_special() special_des[5] = i + '0'; setuserfile(fname, special_des); if (dashf(fname)) { - /* no NULL check?? */ + /* XXX no NULL check?? */ FILE *fp = fopen(fname, "r"); + assert(fp); fgets(genbuf + 15, 40, fp); genbuf[47] = 0; + fclose(fp); } move(i + 12, 0); clrtoeol(); @@ -212,7 +214,7 @@ friend_delete(char *uident, int type) setfriendfile(fn, type); sprintf(fnnew, "%s-", fn); - if ((fp = fopen(fn, "r")) && (nfp = fopen(fnnew, "w"))) { + if ((fp = fopen(fn, "r")) && (nfp = fopen(fnnew, "w"))) { // XXX fclose(fp) if nfp fail int length = strlen(uident); while (fgets(genbuf, STRLEN, fp)) @@ -231,7 +233,7 @@ friend_editdesc(char *uident, int type) char fnnew[200], genbuf[200], fn[200]; setfriendfile(fn, type); snprintf(fnnew, sizeof(fnnew), "%s-", fn); - if ((fp = fopen(fn, "r")) && (nfp = fopen(fnnew, "w"))) { + if ((fp = fopen(fn, "r")) && (nfp = fopen(fnnew, "w"))) { // XXX fclose(fp) if nfp fail int length = strlen(uident); while (fgets(genbuf, STRLEN, fp)) { @@ -297,7 +299,7 @@ friend_water(char *message, int type) FILE *fp; setfriendfile(fpath, type); - if ((fp = fopen(fpath, "r"))) + if ((fp = fopen(fpath, "r"))) { while (fgets(line, 80, fp)) { userinfo_t *uentp; int tuid; @@ -308,7 +310,8 @@ friend_water(char *message, int type) isvisible_uid(tuid)) my_write(uentp->pid, message, uentp->userid, 1, NULL); } - fclose(fp); + fclose(fp); + } } void diff --git a/pttbbs/mbbsd/gamble.c b/pttbbs/mbbsd/gamble.c index d9b3ea2b..b1643fb5 100644 --- a/pttbbs/mbbsd/gamble.c +++ b/pttbbs/mbbsd/gamble.c @@ -1,4 +1,4 @@ -/* $Id: gamble.c,v 1.31 2003/01/16 14:14:12 kcwu Exp $ */ +/* $Id: gamble.c,v 1.32 2003/01/19 16:06:06 kcwu Exp $ */ #include "bbs.h" #ifndef _BBS_UTIL_C_ @@ -273,7 +273,7 @@ openticket(int bid) } else fprintf(fp, "\n\n賭盤取消退錢: %s \n\n", Cdatelite(&now)); - } + } // XXX somebody may use fp even fp==NULL fclose(fp1); setbfile(buf, bh->brdname, FN_TICKET_END); diff --git a/pttbbs/mbbsd/gomo.c b/pttbbs/mbbsd/gomo.c index b7665bae..3a8fcd5f 100644 --- a/pttbbs/mbbsd/gomo.c +++ b/pttbbs/mbbsd/gomo.c @@ -1,4 +1,4 @@ -/* $Id: gomo.c,v 1.11 2003/01/16 14:14:12 kcwu Exp $ */ +/* $Id: gomo.c,v 1.12 2003/01/19 16:06:06 kcwu Exp $ */ #include "bbs.h" static char *chess[] = {"●", "○"}; @@ -56,6 +56,7 @@ HO_log(Horder_t *pool, char *user) snprintf(buf, sizeof(buf), "home/%c/%s/F.%d", cuser.userid[0], cuser.userid, rand() & 65535); log = fopen(buf, "w"); + assert(log); for (i = 1; i < 17; i++) fprintf(log, "%.*s\n", big_picture[i].len, big_picture[i].data); diff --git a/pttbbs/mbbsd/indict.c b/pttbbs/mbbsd/indict.c index 93d955a1..1de9b02c 100644 --- a/pttbbs/mbbsd/indict.c +++ b/pttbbs/mbbsd/indict.c @@ -1,4 +1,4 @@ -/* $Id: indict.c,v 1.11 2003/01/16 14:37:31 kcwu Exp $ */ +/* $Id: indict.c,v 1.12 2003/01/19 16:06:06 kcwu Exp $ */ #include "bbs.h" #define REFER "etc/dicts" @@ -51,6 +51,7 @@ choose_dict(void) "(\033[36m%d\033[m) %-20s大字典", c + 1, buf[c]); outs(cho); } + fclose(fp); getdata(22, 14, " ★ 請選擇,[Enter]離開:", cho, 3, LCECHO); cho[0] -= '1'; diff --git a/pttbbs/mbbsd/lovepaper.c b/pttbbs/mbbsd/lovepaper.c index 47370524..1ab87944 100644 --- a/pttbbs/mbbsd/lovepaper.c +++ b/pttbbs/mbbsd/lovepaper.c @@ -1,4 +1,4 @@ -/* $Id: lovepaper.c,v 1.10 2002/07/22 19:02:00 in2 Exp $ */ +/* $Id: lovepaper.c,v 1.11 2003/01/19 16:06:06 kcwu Exp $ */ #include "bbs.h" #define DATA "etc/lovepaper.dat" @@ -34,6 +34,7 @@ x_love() return 0; } fpo = fopen(path, "w"); + assert(fpo); fprintf(fpo, "\n"); if ((fp = fopen(DATA, "r"))) { while (fgets(buf1, 100, fp)) { @@ -102,5 +103,6 @@ x_love() hold_mail(buf1, receiver); return 1; } + fclose(fpo); return 0; } diff --git a/pttbbs/mbbsd/mail.c b/pttbbs/mbbsd/mail.c index 7f145867..3d06e087 100644 --- a/pttbbs/mbbsd/mail.c +++ b/pttbbs/mbbsd/mail.c @@ -1,4 +1,4 @@ -/* $Id: mail.c,v 1.24 2003/01/16 14:47:43 kcwu Exp $ */ +/* $Id: mail.c,v 1.25 2003/01/19 16:06:06 kcwu Exp $ */ #include "bbs.h" char currmaildir[32]; static char msg_cc[] = "\033[32m[群組名單]\033[m\n"; @@ -434,6 +434,7 @@ multi_send(char *title) AddNameList(quote_user); reciper = 1; fp = fopen(quote_file, "r"); + assert(fp); while (fgets(genbuf, 256, fp)) { if (strncmp(genbuf, "※ ", 3)) { if (listing) @@ -452,6 +453,7 @@ multi_send(char *title) listing = 1; } } + fclose(fp); ShowNameList(3, 0, msg_cc); } multi_list(&reciper); @@ -995,7 +997,7 @@ mail_reply(int ent, fileheader_t * fhdr, char *direct) if (strchr(quote_user, '.')) { genbuf[0] = '\0'; if ((fp = fopen(quote_file, "r"))) { - fgets(genbuf, 512, fp); + fgets(genbuf, sizeof(genbuf), fp); fclose(fp); } t = strtok(genbuf, str_space); @@ -1167,6 +1169,7 @@ mail_cross_post(int ent, fileheader_t * fhdr, char *direct) setuserfile(fname, fhdr->filename); if (ent) { xptr = fopen(xfpath, "w"); + assert(xptr); strlcpy(save_title, xfile.title, sizeof(save_title)); strlcpy(xfpath, currboard, sizeof(xfpath)); @@ -1349,6 +1352,7 @@ mail_waterball(int ent, fileheader_t * fhdr, char *direct) snprintf(fname, sizeof(fname), BBSHOME "/jobspool/water.des.%s-%d", cuser.userid, (int)now); fp = fopen(fname, "wt"); + assert(fp); fprintf(fp, "%s\n%s\n%d\n", cuser.userid, address, cmode); fclose(fp); vmsg("設定完成, 系統將在下一個整點(尖鋒時段除外)將資料寄給您"); @@ -1458,7 +1462,7 @@ bbs_sendmail(char *fpath, char *title, char *receiver) fin = fopen(fpath, "r"); } fout = popen(genbuf, "w"); - if (fin == NULL || fout == NULL) + if (fin == NULL || fout == NULL) // XXX no fclose() if only one fopen succeed return -1; if (fpath) diff --git a/pttbbs/mbbsd/page.c b/pttbbs/mbbsd/page.c index e32b73f2..9c01eb6d 100644 --- a/pttbbs/mbbsd/page.c +++ b/pttbbs/mbbsd/page.c @@ -1,4 +1,4 @@ -/* $Id: page.c,v 1.9 2002/07/22 19:02:00 in2 Exp $ */ +/* $Id: page.c,v 1.10 2003/01/19 16:06:06 kcwu Exp $ */ #include "bbs.h" #define hpressanykey(a) {move(22, 0); prints(a); pressanykey();} @@ -9,7 +9,7 @@ filt_railway(char *fpath) FILE *fp = fopen(fpath, "w"), *tp; snprintf(tmppath, sizeof(tmppath), "%s.railway", fpath); - if (!fp || !(tp = fopen(tmppath, "r"))) + if (!fp || !(tp = fopen(tmppath, "r"))) // XXX fclose(fp) if tp fail return; while (fgets(buf, 255, tp)) { diff --git a/pttbbs/mbbsd/syspost.c b/pttbbs/mbbsd/syspost.c index a44ffdb3..8fdc361c 100644 --- a/pttbbs/mbbsd/syspost.c +++ b/pttbbs/mbbsd/syspost.c @@ -1,4 +1,4 @@ -/* $Id: syspost.c,v 1.17 2003/01/16 13:28:48 kcwu Exp $ */ +/* $Id: syspost.c,v 1.18 2003/01/19 16:06:06 kcwu Exp $ */ #include "bbs.h" int @@ -94,7 +94,8 @@ post_change_perm(int oldperm, int newperm, char *sysopid, char *userid) cuser.userid, userid); strlcpy(fhdr.owner, "[系統安全局]", sizeof(fhdr.owner)); append_record("boards/S/Security/.DIR", &fhdr, sizeof(fhdr)); - } + } else + fclose(fp); } void diff --git a/pttbbs/mbbsd/user.c b/pttbbs/mbbsd/user.c index e3bb1f89..c236279a 100644 --- a/pttbbs/mbbsd/user.c +++ b/pttbbs/mbbsd/user.c @@ -1,4 +1,4 @@ -/* $Id: user.c,v 1.44 2002/12/31 17:40:52 in2 Exp $ */ +/* $Id: user.c,v 1.45 2003/01/19 16:06:06 kcwu Exp $ */ #include "bbs.h" static char *sex[8] = { @@ -568,6 +568,7 @@ u_switchproverb() setuserfile(buf, fn_proverb); if (cuser.proverb == 2 && dashd(buf)) { FILE *fp = fopen(buf, "a"); + assert(fp); fprintf(fp, "座右銘狀態為[自定型]要記得設座右銘的內容唷!!"); fclose(fp); @@ -620,7 +621,9 @@ showsignature(char *fname) fname[j] = ch; if ((fp = fopen(fname, "r"))) { prints("\033[36m【 簽名檔.%c 】\033[m\n", ch); - for (i = 0; i++ < MAX_SIGLINES && fgets(buf, 256, fp); outs(buf)); + for (i = 0; i < MAX_SIGLINES && fgets(buf, sizeof(buf), fp); i++) + outs(buf); + fclose(fp); } } @@ -826,6 +829,7 @@ toregister(char *email, char *genbuf, char *phone, char *career, sethomefile(buf, cuser.userid, "justify.wait"); if (phone[0] != 0) { fn = fopen(buf, "w"); + assert(fn); fprintf(fn, "%s\n%s\n%s\n%s\n%s\n%s\n", phone, career, ident, rname, addr, mobile); fclose(fn); diff --git a/pttbbs/mbbsd/vice.c b/pttbbs/mbbsd/vice.c index acc653fa..2f5aa310 100644 --- a/pttbbs/mbbsd/vice.c +++ b/pttbbs/mbbsd/vice.c @@ -1,4 +1,4 @@ -/* $Id: vice.c,v 1.6 2002/07/22 19:02:01 in2 Exp $ */ +/* $Id: vice.c,v 1.7 2003/01/19 16:06:06 kcwu Exp $ */ #include "bbs.h" #define VICE_PLAY BBSHOME "/etc/vice/vice.play" @@ -22,7 +22,7 @@ vice_load(char tbingo[6][15]) int i = 0; if (!fb) return -1; - bzero((char *)tbingo, sizeof(tbingo)); + bzero((char *)tbingo, 6*15); while (i < 6 && fgets(buf, 15, fb)) { if ((ptr = strchr(buf, '\n'))) *ptr = 0; @@ -53,7 +53,7 @@ ran_showfile(int y, int x, char *filename, int maxnum) FILE *fs; char buf[512]; - bzero(buf, sizeof(char) * 512); + bzero(buf, sizeof(buf)); snprintf(buf, sizeof(buf), "%s%d", filename, rand() % maxnum + 1); if (!(fs = fopen(buf, "r"))) { move(10, 10); diff --git a/pttbbs/mbbsd/vote.c b/pttbbs/mbbsd/vote.c index 70313920..618da18a 100644 --- a/pttbbs/mbbsd/vote.c +++ b/pttbbs/mbbsd/vote.c @@ -1,4 +1,4 @@ -/* $Id: vote.c,v 1.17 2003/01/16 11:58:05 kcwu Exp $ */ +/* $Id: vote.c,v 1.18 2003/01/19 16:06:06 kcwu Exp $ */ #include "bbs.h" static int total; @@ -224,6 +224,7 @@ b_result_one(boardheader_t * fh, int ind) if ((xfp = fopen(buf, "r"))) { fgets(inbuf, sizeof(inbuf), xfp); fprintf(tfp, "%s\n◆ 投票名稱: %s\n\n", msg_seperator, inbuf); + fclose(xfp); } fprintf(tfp, "%s\n◆ 投票中止於: %s\n\n◆ 票選題目描述:\n\n", msg_seperator, ctime(&closetime)); @@ -399,6 +400,7 @@ vote_view(char *bname, int index) if ((fp = fopen(buf, "r"))) { fgets(inbuf, sizeof(inbuf), fp); prints("\n投票名稱: %s", inbuf); + fclose(fp); } setbfile(buf, bname, STR_new_control); fp = fopen(buf, "r"); @@ -486,12 +488,12 @@ vote_view_all(char *bname) fclose(fp); setbfile(buf, bname, STR_new_title); - if ((xfp = fopen(buf, "r"))) + if ((xfp = fopen(buf, "r"))) { fgets(inbuf, sizeof(inbuf), xfp); - else + fclose(xfp); + } else strlcpy(inbuf, "無標題", sizeof(inbuf)); prints("%s\n", inbuf); - fclose(xfp); } for (i = 1; i < 20; i++) { snprintf(STR_new_control, sizeof(STR_new_control), @@ -505,12 +507,12 @@ vote_view_all(char *bname) fclose(fp); setbfile(buf, bname, STR_new_title); - if ((xfp = fopen(buf, "r"))) + if ((xfp = fopen(buf, "r"))) { fgets(inbuf, sizeof(inbuf), xfp); - else + fclose(xfp); + } else strlcpy(inbuf, "無標題", sizeof(inbuf)); prints("%s\n", inbuf); - fclose(xfp); } } @@ -531,7 +533,7 @@ vote_view_all(char *bname) setbfile(buf, bname, STR_new_control); - if ((fp = fopen(buf, "r"))) { + if ((fp = fopen(buf, "r"))) { // TODO try access() fclose(fp); return vote_view(bname, atoi(genbuf)); } else @@ -618,15 +620,13 @@ vote_maintain(char *bname) strlcpy(STR_new_control, STR_bv_control, sizeof(STR_new_control)); setbfile(buf, bname, STR_new_control); x = 0; - while (x < 20 && (fp = fopen(buf, "r")) != NULL) { + while (x < 20 && (fp = fopen(buf, "r")) != NULL) { // TODO try access() fclose(fp); x++; snprintf(STR_new_control, sizeof(STR_new_control), "%s%d", STR_bv_control, x); setbfile(buf, bname, STR_new_control); } - if (fp) - fclose(fp); if (x >= 20) return FULLUPDATE; if (x) { @@ -654,6 +654,7 @@ vote_maintain(char *bname) if (inbuf[0] == '\0') strlcpy(inbuf, "不知名的", sizeof(inbuf)); fp = fopen(buf, "w"); + assert(fp); fprintf(fp, "%s", inbuf); fclose(fp); @@ -677,6 +678,7 @@ vote_maintain(char *bname) setbfile(buf, bname, STR_new_limited); if (inbuf[0] == 'y') { fp = fopen(buf, "w"); + assert(fp); fprintf(fp, "此次投票設限"); fclose(fp); friend_edit(FRIEND_CANVOTE); @@ -696,6 +698,7 @@ vote_maintain(char *bname) closetime = closetime * 86400 + now; setbfile(buf, bname, STR_new_control); fp = fopen(buf, "w"); + assert(fp); fprintf(fp, "00\n%lu\n", closetime); outs("\n請依序輸入選項, 按 ENTER 完成設定"); @@ -994,12 +997,12 @@ user_vote(char *bname) fclose(fp); setbfile(buf, bname, STR_new_title); - if ((xfp = fopen(buf, "r"))) + if ((xfp = fopen(buf, "r"))) { fgets(inbuf, sizeof(inbuf), xfp); - else + fclose(xfp); + } else strlcpy(inbuf, "無標題", sizeof(inbuf)); prints("%s\n", inbuf); - fclose(xfp); } for (i = 1; i < 20; i++) { snprintf(STR_new_control, sizeof(STR_new_control), @@ -1013,12 +1016,12 @@ user_vote(char *bname) fclose(fp); setbfile(buf, bname, STR_new_title); - if ((xfp = fopen(buf, "r"))) + if ((xfp = fopen(buf, "r"))) { fgets(inbuf, sizeof(inbuf), xfp); - else + fclose(xfp); + } else strlcpy(inbuf, "無標題", sizeof(inbuf)); prints("%s\n", inbuf); - fclose(xfp); } } @@ -1040,7 +1043,7 @@ user_vote(char *bname) setbfile(buf, bname, STR_new_control); - if ((fp = fopen(buf, "r"))) { + if ((fp = fopen(buf, "r"))) { // TODO try access() fclose(fp); return user_vote_one(bname, atoi(genbuf)); diff --git a/pttbbs/mbbsd/voteboard.c b/pttbbs/mbbsd/voteboard.c index 76bf0cbc..d1696547 100644 --- a/pttbbs/mbbsd/voteboard.c +++ b/pttbbs/mbbsd/voteboard.c @@ -1,4 +1,4 @@ -/* $Id: voteboard.c,v 1.14 2002/08/20 02:42:36 in2 Exp $ */ +/* $Id: voteboard.c,v 1.15 2003/01/19 16:06:06 kcwu Exp $ */ #include "bbs.h" #define VOTEBOARD "NewBoard" @@ -37,6 +37,7 @@ do_voteboardreply(fileheader_t * fhdr) strcat(oldfpath, fhdr->filename); fp = fopen(oldfpath, "r"); + assert(fp); len = strlen(cuser.userid); diff --git a/pttbbs/mbbsd/xyz.c b/pttbbs/mbbsd/xyz.c index 707ae02e..948a4275 100644 --- a/pttbbs/mbbsd/xyz.c +++ b/pttbbs/mbbsd/xyz.c @@ -1,4 +1,4 @@ -/* $Id: xyz.c,v 1.14 2003/01/16 20:22:06 kcwu Exp $ */ +/* $Id: xyz.c,v 1.15 2003/01/19 16:06:06 kcwu Exp $ */ #include "bbs.h" /* 各種統計及相關資訊列表 */ @@ -211,11 +211,16 @@ note() if ((foo = fopen(".note", "a")) == NULL) return 0; - if ((fp = fopen(fn_note_ans, "w")) == NULL) + if ((fp = fopen(fn_note_ans, "w")) == NULL) { + fclose(fp); return 0; + } - if ((fx = open(fn_note_tmp, O_WRONLY | O_CREAT, 0644)) <= 0) + if ((fx = open(fn_note_tmp, O_WRONLY | O_CREAT, 0644)) <= 0) { + fclose(foo); + fclose(fp); return 0; + } if ((fd = open(fn_note_dat, O_RDONLY)) == -1) total = 1; @@ -305,6 +310,7 @@ mail_sysop() } } } + fclose(fp); move(12, 0); clrtobot(); @@ -463,7 +469,6 @@ x_archie() if (*ans == 'y') { fileheader_t mhdr; char title[128], buf1[80]; - FILE *fp; sethomepath(buf1, cuser.userid); stampfile(buf1, &mhdr); -- cgit v1.2.3 From be832437888f20a4b5fd3788db2a7c06edbdb24d Mon Sep 17 00:00:00 2001 From: kcwu <kcwu@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sun, 19 Jan 2003 16:18:17 +0000 Subject: fix strange syntax informed by gcc -W git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@639 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/edit.c | 4 ++-- pttbbs/mbbsd/read.c | 8 ++++---- pttbbs/mbbsd/talk.c | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/pttbbs/mbbsd/edit.c b/pttbbs/mbbsd/edit.c index f585fab8..dd8bb578 100644 --- a/pttbbs/mbbsd/edit.c +++ b/pttbbs/mbbsd/edit.c @@ -1,4 +1,4 @@ -/* $Id: edit.c,v 1.26 2003/01/19 16:06:06 kcwu Exp $ */ +/* $Id: edit.c,v 1.27 2003/01/19 16:18:17 kcwu Exp $ */ #include "bbs.h" typedef struct textline_t { struct textline_t *prev; @@ -42,7 +42,7 @@ static char fp_bak[] = "bak"; /* 記憶體管理與編輯處理 */ static void -indigestion(i) +indigestion(int i) { fprintf(stderr, "嚴重內傷 %d\n", i); } diff --git a/pttbbs/mbbsd/read.c b/pttbbs/mbbsd/read.c index b926a852..5243a0cd 100644 --- a/pttbbs/mbbsd/read.c +++ b/pttbbs/mbbsd/read.c @@ -1,4 +1,4 @@ -/* $Id: read.c,v 1.16 2003/01/17 08:16:21 kcwu Exp $ */ +/* $Id: read.c,v 1.17 2003/01/19 16:18:17 kcwu Exp $ */ #include "bbs.h" #define MAXPATHLEN 256 @@ -164,6 +164,7 @@ int TagPruner(int bid) { boardheader_t *bp; + assert(bid>0); bp = getbcache(bid); if (strcmp(bp->brdname, "Security") == 0) return DONOTHING; @@ -172,7 +173,6 @@ TagPruner(int bid) return FULLUPDATE; delete_range(currdirect, 0, 0); TagNum = 0; - if (bid > 0); setbtotal(bid); return NEWDIRECT; } @@ -452,8 +452,8 @@ select_read(keeploc_t * locmem, int sr_mode) register char *tag, *query, *temp; fileheader_t fh; char fpath[80], genbuf[MAXPATHLEN], buf3[5]; - char static t_ans[TTLEN + 1] = ""; - char static a_ans[TTLEN + 1] = ""; + static char t_ans[TTLEN + 1] = ""; + static char a_ans[TTLEN + 1] = ""; int fd, fr, size = sizeof(fileheader_t); struct stat st; /* rocker.011018: make a reference number for process article */ diff --git a/pttbbs/mbbsd/talk.c b/pttbbs/mbbsd/talk.c index 2bc1ac53..60f2aa85 100644 --- a/pttbbs/mbbsd/talk.c +++ b/pttbbs/mbbsd/talk.c @@ -1,4 +1,4 @@ -/* $Id: talk.c,v 1.99 2003/01/16 11:58:04 kcwu Exp $ */ +/* $Id: talk.c,v 1.100 2003/01/19 16:18:17 kcwu Exp $ */ #include "bbs.h" #define QCAST int (*)(const void *, const void *) @@ -252,7 +252,7 @@ logout_friend_online(userinfo_t * utmp) utmp->friend_online[i] = 0; ui = &SHM->uinfo[j]; if (ui->pid && ui != utmp) { - for (k = 0; k < ui->friendtotal > 0 && k < MAX_FRIEND && + for (k = 0; k < ui->friendtotal && k < MAX_FRIEND && (int)(ui->friend_online[k] & 0xFFFFFF) != offset; k++); if (k < ui->friendtotal) { ui->friendtotal--; -- cgit v1.2.3 From 0a46fb4aa9c0ea2d74d122972a306af19aea82b4 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Thu, 23 Jan 2003 18:19:55 +0000 Subject: import strlcat(), strlcpy() for fucking linux git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@640 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/include/bbs.h | 8 ++- pttbbs/mbbsd/osdep.c | 142 ++++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 147 insertions(+), 3 deletions(-) diff --git a/pttbbs/include/bbs.h b/pttbbs/include/bbs.h index 87b038a7..600ad781 100644 --- a/pttbbs/include/bbs.h +++ b/pttbbs/include/bbs.h @@ -58,8 +58,12 @@ #ifdef Linux #include <sys/param.h> #include <limits.h> - #define strlcpy(a,b,c) strncpy(a,b,c) - #define strlcat(a,b,c) strncat(a,b,c) + #include <sys/file.h> // for flock() + size_t + strlcpy(char *dst, const char *src, size_t size); + + size_t + strlcat(char *dst, const char *src, size_t size); #endif #endif /* INCLUDE_BBS_H */ diff --git a/pttbbs/mbbsd/osdep.c b/pttbbs/mbbsd/osdep.c index 6357a829..0c32db7a 100644 --- a/pttbbs/mbbsd/osdep.c +++ b/pttbbs/mbbsd/osdep.c @@ -1,6 +1,146 @@ -/* $Id: osdep.c,v 1.6 2002/07/22 19:02:00 in2 Exp $ */ +/* $Id: osdep.c,v 1.7 2003/01/23 18:19:55 in2 Exp $ */ #include "bbs.h" +#ifdef Linux +#include <sys/types.h> +#include <string.h> + +/* size_t + * strlcat(char *dst, const char *src, size_t size); + */ +/* + * Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com> + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * Appends src to string dst of size siz (unlike strncat, siz is the + * full size of dst, not space left). At most siz-1 characters + * will be copied. Always NUL terminates (unless siz <= strlen(dst)). + * Returns strlen(src) + MIN(siz, strlen(initial dst)). + * If retval >= siz, truncation occurred. + */ +size_t +strlcat(dst, src, siz) + char *dst; + const char *src; + size_t siz; +{ + char *d = dst; + const char *s = src; + size_t n = siz; + size_t dlen; + + /* Find the end of dst and adjust bytes left but don't go past end */ + while (n-- != 0 && *d != '\0') + d++; + dlen = d - dst; + n = siz - dlen; + + if (n == 0) + return(dlen + strlen(s)); + while (*s != '\0') { + if (n != 1) { + *d++ = *s; + n--; + } + s++; + } + *d = '\0'; + + return(dlen + (s - src)); /* count does not include NUL */ +} + +/* ------------------------------------------------------------------------ */ + +/* size_t + * strlcpy(char *dst, const char *src, size_t size); + */ + +/* + * Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com> + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * Copy src to string dst of size siz. At most siz-1 characters + * will be copied. Always NUL terminates (unless siz == 0). + * Returns strlen(src); if retval >= siz, truncation occurred. + */ +size_t strlcpy(dst, src, siz) + char *dst; + const char *src; + size_t siz; +{ + char *d = dst; + const char *s = src; + size_t n = siz; + + /* Copy as many bytes as will fit */ + if (n != 0 && --n != 0) { + do { + if ((*d++ = *s++) == 0) + break; + } while (--n != 0); + } + + /* Not enough room in dst, add NUL and traverse rest of src */ + if (n == 0) { + if (siz != 0) + *d = '\0'; /* NUL-terminate dst */ + while (*s++) + ; + } + + return(s - src - 1); /* count does not include NUL */ +} + +#endif + #if __FreeBSD__ #include <kvm.h> -- cgit v1.2.3 From 91373b6759ef927b47de4838c94f8859f5d2bfaf Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Thu, 23 Jan 2003 18:21:06 +0000 Subject: make compiler happy git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@641 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/cache.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pttbbs/mbbsd/cache.c b/pttbbs/mbbsd/cache.c index 7016239b..5bcecb08 100644 --- a/pttbbs/mbbsd/cache.c +++ b/pttbbs/mbbsd/cache.c @@ -1,4 +1,4 @@ -/* $Id: cache.c,v 1.55 2003/01/17 10:26:22 kcwu Exp $ */ +/* $Id: cache.c,v 1.56 2003/01/23 18:21:06 in2 Exp $ */ #include "bbs.h" #ifndef __FreeBSD__ @@ -556,7 +556,7 @@ count_logins(int uid, int show) register int i = 0, j, start = 0, end = SHM->UTMPnumber - 1, count; register userinfo_t **ulist; if (end == -1) - return NULL; + return 0; ulist = SHM->sorted[SHM->currsorted][6]; for (i = ((start + end) / 2);; i = (start + end) / 2) { j = uid - ulist[i]->uid; -- cgit v1.2.3 From 04f7afa934ee0b2e9a0c7cecef34676e9cb32dd9 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Thu, 23 Jan 2003 18:36:55 +0000 Subject: to prevent some @#$$* by strange os (like linux), place our header files after os-dependent headers git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@642 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/include/bbs.h | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/pttbbs/include/bbs.h b/pttbbs/include/bbs.h index 600ad781..7b4b4319 100644 --- a/pttbbs/include/bbs.h +++ b/pttbbs/include/bbs.h @@ -34,22 +34,6 @@ #include <sys/sem.h> #include <sys/msg.h> -#include "config.h" -#include "pttstruct.h" -#include "common.h" -#include "perm.h" -#include "modes.h" -#include "proto.h" -#include "gomo.h" - -#ifdef _UTIL_C_ - #include "util.h" -#endif - -#ifndef INCLUDE_VAR_H - #include "var.h" -#endif - /* os dependant include file, define */ #ifdef FreeBSD #include <machine/limits.h> @@ -66,4 +50,21 @@ strlcat(char *dst, const char *src, size_t size); #endif +/* our header */ +#include "config.h" +#include "pttstruct.h" +#include "common.h" +#include "perm.h" +#include "modes.h" +#include "proto.h" +#include "gomo.h" + +#ifdef _UTIL_C_ + #include "util.h" +#endif + +#ifndef INCLUDE_VAR_H + #include "var.h" +#endif + #endif /* INCLUDE_BBS_H */ -- cgit v1.2.3 From 5816ca53acc840f31416d702cac5f0f0d0adffa9 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Thu, 23 Jan 2003 18:39:01 +0000 Subject: define MAXPATHLEN ifndef MAXPATHLEN git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@643 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/include/config.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pttbbs/include/config.h b/pttbbs/include/config.h index b509dfd4..5360a85d 100644 --- a/pttbbs/include/config.h +++ b/pttbbs/include/config.h @@ -1,4 +1,4 @@ -/* $Id: config.h,v 1.7 2002/08/23 22:03:46 in2 Exp $ */ +/* $Id: config.h,v 1.8 2003/01/23 18:39:01 in2 Exp $ */ #ifndef INCLUDE_CONFIG_H #define INCLUDE_CONFIG_H @@ -77,6 +77,9 @@ #define HBFLexpire (432000) /* 5 days */ #endif +#ifndef MAXPATHLEN +#define MAXPATHLEN (256) +#endif /* 以下還未整理 */ #define DIRCACHESIZE (40) /* cache 文章列表中最後40篇 */ #define MAX_FRIEND (256) /* 載入 cache 之最多朋友數目 */ -- cgit v1.2.3 From f451dab9a3b073631fef5894f780df5c292a3e52 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Thu, 23 Jan 2003 18:39:24 +0000 Subject: remove #define MAXPATHLEN 256 git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@644 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/more.c | 3 +-- pttbbs/mbbsd/read.c | 4 +--- pttbbs/mbbsd/xyz.c | 4 +--- 3 files changed, 3 insertions(+), 8 deletions(-) diff --git a/pttbbs/mbbsd/more.c b/pttbbs/mbbsd/more.c index 46f77c87..b4fe1948 100644 --- a/pttbbs/mbbsd/more.c +++ b/pttbbs/mbbsd/more.c @@ -1,4 +1,4 @@ -/* $Id: more.c,v 1.23 2003/01/16 11:58:04 kcwu Exp $ */ +/* $Id: more.c,v 1.24 2003/01/23 18:39:23 in2 Exp $ */ #include "bbs.h" #define MORE_BUFSIZE 4096 #define MORE_WINSIZE 4096 @@ -8,7 +8,6 @@ static int more_base, more_size, more_head; static unsigned char more_pool[MORE_BUFSIZE]; -#define MAXPATHLEN 256 static char *more_help[] = { "\0閱\讀文章功\能鍵使用說明", "\01游標移動功\能鍵", diff --git a/pttbbs/mbbsd/read.c b/pttbbs/mbbsd/read.c index 5243a0cd..ea2e4a73 100644 --- a/pttbbs/mbbsd/read.c +++ b/pttbbs/mbbsd/read.c @@ -1,8 +1,6 @@ -/* $Id: read.c,v 1.17 2003/01/19 16:18:17 kcwu Exp $ */ +/* $Id: read.c,v 1.18 2003/01/23 18:39:24 in2 Exp $ */ #include "bbs.h" -#define MAXPATHLEN 256 - static fileheader_t *headers = NULL; static int last_line; static int hit_thread; diff --git a/pttbbs/mbbsd/xyz.c b/pttbbs/mbbsd/xyz.c index 948a4275..d1e386f1 100644 --- a/pttbbs/mbbsd/xyz.c +++ b/pttbbs/mbbsd/xyz.c @@ -1,4 +1,4 @@ -/* $Id: xyz.c,v 1.15 2003/01/19 16:06:06 kcwu Exp $ */ +/* $Id: xyz.c,v 1.16 2003/01/23 18:39:24 in2 Exp $ */ #include "bbs.h" /* 各種統計及相關資訊列表 */ @@ -393,8 +393,6 @@ Goodbye() #define MAXENVS (20) #define BINDIR BBSHOME"/bin/" -#define MAXPATHLEN 256 - #ifdef HAVE_TIN static int x_tin() -- cgit v1.2.3 From 0fd11efda8c299b511664ca8044a1710ec02ea9c Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Fri, 24 Jan 2003 14:41:19 +0000 Subject: remove field "recommend" from userec_t git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@645 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/include/pttstruct.h | 5 ++--- pttbbs/mbbsd/bbs.c | 7 ++++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/pttbbs/include/pttstruct.h b/pttbbs/include/pttstruct.h index 29984823..12054171 100644 --- a/pttbbs/include/pttstruct.h +++ b/pttbbs/include/pttstruct.h @@ -1,4 +1,4 @@ -/* $Id: pttstruct.h,v 1.27 2002/11/16 13:41:06 kcwu Exp $ */ +/* $Id: pttstruct.h,v 1.28 2003/01/24 14:41:19 in2 Exp $ */ #ifndef INCLUDE_STRUCT_H #define INCLUDE_STRUCT_H @@ -75,8 +75,7 @@ typedef struct userec_t { char mind[4]; char ident[11]; unsigned int uflag2; - time_t recommend; - char pad[68]; + char pad[72]; } userec_t; /* these are flags in userec_t.uflag */ #define SIG_FLAG 0x3 /* signature number, 2 bits */ diff --git a/pttbbs/mbbsd/bbs.c b/pttbbs/mbbsd/bbs.c index 2ee8423d..0622e720 100644 --- a/pttbbs/mbbsd/bbs.c +++ b/pttbbs/mbbsd/bbs.c @@ -1,4 +1,4 @@ -/* $Id: bbs.c,v 1.76 2002/11/08 17:49:03 in2 Exp $ */ +/* $Id: bbs.c,v 1.77 2003/01/24 14:41:19 in2 Exp $ */ #include "bbs.h" static void @@ -1209,6 +1209,7 @@ recommend(int ent, fileheader_t * fhdr, char *direct) struct tm *ptime = localtime(&now); char buf[200], path[200], yn[5]; boardheader_t *bp; + static time_t lastrecommend = 0; if( currmode & MODE_SELECT ) return DONOTHING; @@ -1234,7 +1235,7 @@ recommend(int ent, fileheader_t * fhdr, char *direct) } #ifndef DEBUG if (!(currmode & MODE_BOARD) && getuser(cuser.userid) && - now - xuser.recommend < 40) { + now - lastrecommend < 40) { move(b_lines - 1, 0); prints("離上次推薦時間太近囉, 請多花點時間仔細閱\讀文章!"); pressanykey(); @@ -1260,7 +1261,7 @@ recommend(int ent, fileheader_t * fhdr, char *direct) lock_substitute_record(direct, fhdr, sizeof(*fhdr), ent, LOCK_UN); else{ fhdr->recommend++; - cuser.recommend = now; + lastrecommend = now; passwd_update(usernum, &cuser); lock_substitute_record(direct, fhdr, sizeof(*fhdr), ent, LOCK_UN); substitute_check(fhdr); -- cgit v1.2.3 From d279ae7da9ca16874f0965c84ebfa25ce3e1c431 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Fri, 24 Jan 2003 19:48:14 +0000 Subject: remove sort_utmp() (in shmctl utmpsortd now) git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@646 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/cache.c | 115 +-------------------------------------------------- pttbbs/mbbsd/mbbsd.c | 3 +- 2 files changed, 2 insertions(+), 116 deletions(-) diff --git a/pttbbs/mbbsd/cache.c b/pttbbs/mbbsd/cache.c index 5bcecb08..ae5caad3 100644 --- a/pttbbs/mbbsd/cache.c +++ b/pttbbs/mbbsd/cache.c @@ -1,4 +1,4 @@ -/* $Id: cache.c,v 1.56 2003/01/23 18:21:06 in2 Exp $ */ +/* $Id: cache.c,v 1.57 2003/01/24 19:48:14 in2 Exp $ */ #include "bbs.h" #ifndef __FreeBSD__ @@ -338,118 +338,6 @@ setutmpmode(unsigned int mode) } } #endif -static int -cmputmpuserid(const void *i, const void *j) -{ - return strcasecmp((*((userinfo_t **) i))->userid, (*((userinfo_t **) j))->userid); -} - -static int -cmputmpmode(const void *i, const void *j) -{ - return (*((userinfo_t **) i))->mode - (*((userinfo_t **) j))->mode; -} - -static int -cmputmpidle(const void *i, const void *j) -{ - return (*((userinfo_t **) i))->lastact - (*((userinfo_t **) j))->lastact; -} - -static int -cmputmpfrom(const void *i, const void *j) -{ - return strcasecmp((*((userinfo_t **) i))->from, (*((userinfo_t **) j))->from); -} - -static int -cmputmpfive(const void *i, const void *j) -{ - int type; - if ((type = (*((userinfo_t **) j))->five_win - (*((userinfo_t **) i))->five_win)) - return type; - if ((type = (*((userinfo_t **) i))->five_lose - (*((userinfo_t **) j))->five_lose)) - return type; - return (*((userinfo_t **) i))->five_tie - (*((userinfo_t **) j))->five_tie; -} - -static int -cmputmpchc(const void *i, const void *j) -{ - int type; - if ((type = (*((userinfo_t **) j))->chc_win - (*((userinfo_t **) i))->chc_win)) - return type; - if ((type = (*((userinfo_t **) i))->chc_lose - (*((userinfo_t **) j))->chc_lose)) - return type; - return (*((userinfo_t **) i))->chc_tie - (*((userinfo_t **) j))->chc_tie; -} - -static int -cmputmppid(const void *i, const void *j) -{ - return (*((userinfo_t **) i))->pid - (*((userinfo_t **) j))->pid; -} -static int -cmputmpuid(const void *i, const void *j) -{ - return (*((userinfo_t **) i))->uid - (*((userinfo_t **) j))->uid; -} -void -sort_utmp() -{ - userinfo_t *uentp; - int count, i, ns; - short nusers[MAX_BOARD]; - now = time(0); - if (now - SHM->UTMPuptime < 60 && - (now == SHM->UTMPuptime || SHM->UTMPbusystate)) - return; /* lazy sort */ - SHM->UTMPbusystate = 1; - SHM->UTMPuptime = now; - ns = (SHM->currsorted ? 0 : 1); - - for (uentp = &SHM->uinfo[0], count = i = 0; - i < USHM_SIZE; - ++i, uentp = &SHM->uinfo[i]) { - if (uentp->pid) { - if (uentp->sex < 0 || uentp->sex > 7) - purge_utmp(uentp); - else - SHM->sorted[ns][0][count++] = uentp; - } - } - SHM->UTMPnumber = count; - qsort(SHM->sorted[ns][0], count, sizeof(userinfo_t *), cmputmpuserid); - for (i = 0; i < count; ++i) - ((userinfo_t *) SHM->sorted[ns][0][i])->idoffset = i; - memcpy(SHM->sorted[ns][1], SHM->sorted[ns][0], sizeof(userinfo_t *) * count); - memcpy(SHM->sorted[ns][2], SHM->sorted[ns][0], sizeof(userinfo_t *) * count); - memcpy(SHM->sorted[ns][3], SHM->sorted[ns][0], sizeof(userinfo_t *) * count); - memcpy(SHM->sorted[ns][4], SHM->sorted[ns][0], sizeof(userinfo_t *) * count); - memcpy(SHM->sorted[ns][5], SHM->sorted[ns][0], sizeof(userinfo_t *) * count); - memcpy(SHM->sorted[ns][6], SHM->sorted[ns][0], sizeof(userinfo_t *) * count); - memcpy(SHM->sorted[ns][7], SHM->sorted[ns][0], sizeof(userinfo_t *) * count); - qsort(SHM->sorted[ns][1], count, sizeof(userinfo_t *), cmputmpmode); - qsort(SHM->sorted[ns][2], count, sizeof(userinfo_t *), cmputmpidle); - qsort(SHM->sorted[ns][3], count, sizeof(userinfo_t *), cmputmpfrom); - qsort(SHM->sorted[ns][4], count, sizeof(userinfo_t *), cmputmpfive); - qsort(SHM->sorted[ns][5], count, sizeof(userinfo_t *), cmputmpchc); - qsort(SHM->sorted[ns][6], count, sizeof(userinfo_t *), cmputmpuid); - qsort(SHM->sorted[ns][7], count, sizeof(userinfo_t *), cmputmppid); - SHM->currsorted = ns; - SHM->UTMPbusystate = 0; - - memset(nusers, 0, sizeof(nusers)); - for (i = 0; i < count; ++i) { - uentp = SHM->sorted[ns][0][i]; - if (uentp && uentp->pid && - 0 < uentp->brc_id && uentp->brc_id < MAX_BOARD) - ++nusers[uentp->brc_id - 1]; - } - for (i = 0; i < SHM->Bnumber; ++i) - if (SHM->bcache[i].brdname[0] != 0) - SHM->bcache[i].nuser = nusers[i]; -} /* Ptt:這裡加上 hash 觀念找空的 utmp */ void @@ -464,7 +352,6 @@ getnewutmpent(userinfo_t * up) if (!(uentp->pid)) { memcpy(uentp, up, sizeof(userinfo_t)); currutmp = uentp; - sort_utmp(); return; } } diff --git a/pttbbs/mbbsd/mbbsd.c b/pttbbs/mbbsd/mbbsd.c index f0431a12..2ef59687 100644 --- a/pttbbs/mbbsd/mbbsd.c +++ b/pttbbs/mbbsd/mbbsd.c @@ -1,4 +1,4 @@ -/* $Id: mbbsd.c,v 1.64 2003/01/19 01:29:40 in2 Exp $ */ +/* $Id: mbbsd.c,v 1.65 2003/01/24 19:48:14 in2 Exp $ */ #include "bbs.h" #define SOCKET_QLEN 4 @@ -449,7 +449,6 @@ multi_user_check() return; /* don't check sysops */ if (cuser.userlevel) { - sort_utmp(); if (!(ui = (userinfo_t *) search_ulist(usernum))) return; /* user isn't logged in */ -- cgit v1.2.3 From a32306e9f66f518cd19f7bef83026cf3de46c075 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Fri, 24 Jan 2003 19:48:29 +0000 Subject: utmpsortd git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@647 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/shmctl.c | 237 ++++++++++++++++++++++++++++++--------------------- 1 file changed, 139 insertions(+), 98 deletions(-) diff --git a/pttbbs/util/shmctl.c b/pttbbs/util/shmctl.c index 5e58654e..1eea2825 100644 --- a/pttbbs/util/shmctl.c +++ b/pttbbs/util/shmctl.c @@ -1,8 +1,10 @@ -/* $Id: shmctl.c,v 1.30 2003/01/19 01:44:35 in2 Exp $ */ +/* $Id: shmctl.c,v 1.31 2003/01/24 19:48:29 in2 Exp $ */ #include "bbs.h" +#include <sys/wait.h> extern SHM_t *SHM; +/* utmpfix ----------------------------------------------------------------- */ int logout_friend_online(userinfo_t *utmp) { int i, j, k; @@ -134,6 +136,141 @@ int utmpfix(int argc, char **argv) SHM->UTMPbusystate = 0; return 0; } +/* end of utmpfix ---------------------------------------------------------- */ + +/* utmpsortd --------------------------------------------------------------- */ +static int +cmputmpuserid(const void *i, const void *j) +{ + return strcasecmp((*((userinfo_t **) i))->userid, (*((userinfo_t **) j))->userid); +} + +static int +cmputmpmode(const void *i, const void *j) +{ + return (*((userinfo_t **) i))->mode - (*((userinfo_t **) j))->mode; +} + +static int +cmputmpidle(const void *i, const void *j) +{ + return (*((userinfo_t **) i))->lastact - (*((userinfo_t **) j))->lastact; +} + +static int +cmputmpfrom(const void *i, const void *j) +{ + return strcasecmp((*((userinfo_t **) i))->from, (*((userinfo_t **) j))->from); +} + +static int +cmputmpfive(const void *i, const void *j) +{ + int type; + if ((type = (*((userinfo_t **) j))->five_win - (*((userinfo_t **) i))->five_win)) + return type; + if ((type = (*((userinfo_t **) i))->five_lose - (*((userinfo_t **) j))->five_lose)) + return type; + return (*((userinfo_t **) i))->five_tie - (*((userinfo_t **) j))->five_tie; +} + +static int +cmputmpchc(const void *i, const void *j) +{ + int type; + if ((type = (*((userinfo_t **) j))->chc_win - (*((userinfo_t **) i))->chc_win)) + return type; + if ((type = (*((userinfo_t **) i))->chc_lose - (*((userinfo_t **) j))->chc_lose)) + return type; + return (*((userinfo_t **) i))->chc_tie - (*((userinfo_t **) j))->chc_tie; +} + +static int +cmputmppid(const void *i, const void *j) +{ + return (*((userinfo_t **) i))->pid - (*((userinfo_t **) j))->pid; +} + +static int +cmputmpuid(const void *i, const void *j) +{ + return (*((userinfo_t **) i))->uid - (*((userinfo_t **) j))->uid; +} + +inline void utmpsort(void) +{ + userinfo_t *uentp; + int count, i, ns; + short nusers[MAX_BOARD]; + SHM->UTMPbusystate = 1; + SHM->UTMPuptime = time(NULL); + ns = (SHM->currsorted ? 0 : 1); + + for (uentp = &SHM->uinfo[0], count = i = 0; + i < USHM_SIZE; + ++i, uentp = &SHM->uinfo[i]) { + if (uentp->pid) { + if (uentp->sex < 0 || uentp->sex > 7) + purge_utmp(uentp); + else + SHM->sorted[ns][0][count++] = uentp; + } + } + SHM->UTMPnumber = count; + qsort(SHM->sorted[ns][0], count, sizeof(userinfo_t *), cmputmpuserid); + for (i = 0; i < count; ++i) + ((userinfo_t *) SHM->sorted[ns][0][i])->idoffset = i; + memcpy(SHM->sorted[ns][1], SHM->sorted[ns][0], sizeof(userinfo_t *) * count); + memcpy(SHM->sorted[ns][2], SHM->sorted[ns][0], sizeof(userinfo_t *) * count); + memcpy(SHM->sorted[ns][3], SHM->sorted[ns][0], sizeof(userinfo_t *) * count); + memcpy(SHM->sorted[ns][4], SHM->sorted[ns][0], sizeof(userinfo_t *) * count); + memcpy(SHM->sorted[ns][5], SHM->sorted[ns][0], sizeof(userinfo_t *) * count); + memcpy(SHM->sorted[ns][6], SHM->sorted[ns][0], sizeof(userinfo_t *) * count); + memcpy(SHM->sorted[ns][7], SHM->sorted[ns][0], sizeof(userinfo_t *) * count); + qsort(SHM->sorted[ns][1], count, sizeof(userinfo_t *), cmputmpmode); + qsort(SHM->sorted[ns][2], count, sizeof(userinfo_t *), cmputmpidle); + qsort(SHM->sorted[ns][3], count, sizeof(userinfo_t *), cmputmpfrom); + qsort(SHM->sorted[ns][4], count, sizeof(userinfo_t *), cmputmpfive); + qsort(SHM->sorted[ns][5], count, sizeof(userinfo_t *), cmputmpchc); + qsort(SHM->sorted[ns][6], count, sizeof(userinfo_t *), cmputmpuid); + qsort(SHM->sorted[ns][7], count, sizeof(userinfo_t *), cmputmppid); + SHM->currsorted = ns; + SHM->UTMPbusystate = 0; + + memset(nusers, 0, sizeof(nusers)); + for (i = 0; i < count; ++i) { + uentp = SHM->sorted[ns][0][i]; + if (uentp && uentp->pid && + 0 < uentp->brc_id && uentp->brc_id < MAX_BOARD) + ++nusers[uentp->brc_id - 1]; + } + for (i = 0; i < SHM->Bnumber; ++i) + if (SHM->bcache[i].brdname[0] != 0) + SHM->bcache[i].nuser = nusers[i]; +} + +int utmpsortd(int argc, char **argv) +{ + pid_t pid; + if( fork() > 0 ){ + puts("sortutmpd daemonized..."); + return 0; + } + + while( 1 ){ + if( (pid = fork()) != 0 ){ + int s; + waitpid(pid, &s, 0); + } + else{ + while( 1 ){ + utmpsort(); + sleep(1); + } + } + } +} +/* end of utmpsortd -------------------------------------------------------- */ char *CTIMEx(char *buf, time_t t) { @@ -164,102 +301,6 @@ int utmpreset(int argc, char **argv) return 0; } -/* ulistsort */ -static int cmputmpuserid(const void *i, const void *j){ - return strcasecmp((*((userinfo_t**)i))->userid, - (*((userinfo_t**)j))->userid); -} - -static int cmputmpmode(const void *i, const void *j){ - return (*((userinfo_t**)i))->mode- - (*((userinfo_t**)j))->mode; -} - -static int cmputmpidle(const void *i, const void *j){ - return (*((userinfo_t**)i))->lastact- - (*((userinfo_t**)j))->lastact; -} - -static int cmputmpfrom(const void *i, const void *j){ - return strcasecmp((*((userinfo_t**)i))->from, - (*((userinfo_t**)j))->from); -} - -static int cmputmpfive(const void *i, const void *j){ - int type; - if((type=(*((userinfo_t**)j))->five_win - (*((userinfo_t**)i))->five_win)) - return type; - if((type=(*((userinfo_t**)i))->five_lose-(*((userinfo_t**)j))->five_lose)) - return type; - return (*((userinfo_t**)i))->five_tie-(*((userinfo_t**)j))->five_tie; -} - -#if 0 -static int cmputmpsex(const void *i, const void *j){ - static int ladyfirst[]={1,0,1,0,1,0,3,3}; - return ladyfirst[(*((userinfo_t**)i))->sex]- - ladyfirst[(*((userinfo_t**)j))->sex]; -} -#endif - -static int cmputmppid(const void *i, const void *j){ - return (*((userinfo_t**)i))->pid-(*((userinfo_t**)j))->pid; -} -static int cmputmpuid(const void *i, const void *j){ - return (*((userinfo_t**)i))->uid-(*((userinfo_t**)j))->uid; -} - -int utmpsort(int argc, char **argv) -{ - time_t now=time(NULL); - int count, i, ns; - userinfo_t *uentp; - - if(now-SHM->UTMPuptime<60 && (now==SHM->UTMPuptime || SHM->UTMPbusystate)){ - puts("lazy sort"); - //return; /* lazy sort */ - } - SHM->UTMPbusystate=1; - SHM->UTMPuptime = now; - ns=(SHM->currsorted?0:1); - - for(uentp = &SHM->uinfo[0], count=0, i=0; - i< USHM_SIZE; i++,uentp = &SHM->uinfo[i]) - if(uentp->pid){ - SHM->sorted[ns][0][count++]= uentp; - } - SHM->number = count; - qsort(SHM->sorted[ns][0],count,sizeof(userinfo_t*),cmputmpuserid); - memcpy(SHM->sorted[ns][1],SHM->sorted[ns][0], - sizeof(userinfo_t *)*count); - memcpy(SHM->sorted[ns][2],SHM->sorted[ns][0], - sizeof(userinfo_t *)*count); - memcpy(SHM->sorted[ns][3],SHM->sorted[ns][0], - sizeof(userinfo_t *)*count); - memcpy(SHM->sorted[ns][4],SHM->sorted[ns][0], - sizeof(userinfo_t *)*count); - memcpy(SHM->sorted[ns][5],SHM->sorted[ns][0], - sizeof(userinfo_t *)*count); - memcpy(SHM->sorted[ns][6],SHM->sorted[ns][0], - sizeof(userinfo_t *)*count); - memcpy(SHM->sorted[ns][7],SHM->sorted[ns][0], - sizeof(userinfo_t *)*count); - qsort(SHM->sorted[ns][1], count, sizeof(userinfo_t *), cmputmpmode ); - qsort(SHM->sorted[ns][2], count, sizeof(userinfo_t *), cmputmpidle ); - qsort(SHM->sorted[ns][3], count, sizeof(userinfo_t *), cmputmpfrom ); - qsort(SHM->sorted[ns][4], count, sizeof(userinfo_t *), cmputmpfive ); - //qsort(SHM->sorted[ns][5], count, sizeof(userinfo_t *), cmputmpsex ); - qsort(SHM->sorted[ns][6], count, sizeof(userinfo_t *), cmputmpuid ); - qsort(SHM->sorted[ns][7], count, sizeof(userinfo_t *), cmputmppid ); - SHM->currsorted=ns; - SHM->UTMPbusystate=0; - - puts("new utmpstate"); - utmpstate(0, NULL); - return 0; -} -/* end of ulistsort */ - #define TIMES 10 int utmpwatch(int argc, char **argv) { @@ -338,9 +379,9 @@ struct { char *cmd, *descript; } cmd[] = { {utmpfix, "utmpfix", "clear dead userlist entry"}, + {utmpsortd, "utmpsortd", "utmp sorting daemon"}, {utmpstate, "utmpstate", "list utmpstate"}, {utmpreset, "utmpreset", "SHM->busystate=0"}, - {utmpsort, "utmpsort", "sort ulist"}, {utmpwatch, "utmpwatch", "to see if busystate is always 1 then fix it"}, {utmpnum, "utmpnum", "print SHM->number for snmpd"}, {showglobal, "showglobal", "show GLOBALVAR[]"}, -- cgit v1.2.3 From 4e0e61ccab3dae9288224f91508e0816abca1381 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Fri, 24 Jan 2003 20:06:23 +0000 Subject: for utmpsortd git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@648 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/docs/INSTALL | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pttbbs/docs/INSTALL b/pttbbs/docs/INSTALL index 448e09f5..a8cd6dcc 100644 --- a/pttbbs/docs/INSTALL +++ b/pttbbs/docs/INSTALL @@ -44,9 +44,10 @@ 接下來是啟動 bbs 的部份 13. 執行 bin/uhash_loader (*註1, *註2) -14. 用 root 執行 bin/mbbsd 23 (註2) +14. 執行 bin/shmctl utmpsortd +15. 用 root 執行 bin/mbbsd 23 (註2) -15. 新功能請參考 ADVANCE +16. 新功能請參考 ADVANCE telnet localhost 23 看看 new一個帳號叫SYSOP,然後logout再login, 這樣子就會擁有站長權限囉~ 再new一個帳號叫 guest, 這樣子別人就可以用 guest 參觀你的站了 -- cgit v1.2.3 From 1c6d57c7636da4a4c3ba8dc135bfa7cd3b8f5e6d Mon Sep 17 00:00:00 2001 From: kcwu <kcwu@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sun, 2 Feb 2003 10:31:35 +0000 Subject: fix cursor position thanks to akiecs.bbs@ptt2 (AK) git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@649 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/mail.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pttbbs/mbbsd/mail.c b/pttbbs/mbbsd/mail.c index 3d06e087..d2a84154 100644 --- a/pttbbs/mbbsd/mail.c +++ b/pttbbs/mbbsd/mail.c @@ -1,4 +1,4 @@ -/* $Id: mail.c,v 1.25 2003/01/19 16:06:06 kcwu Exp $ */ +/* $Id: mail.c,v 1.26 2003/02/02 10:31:35 kcwu Exp $ */ #include "bbs.h" char currmaildir[32]; static char msg_cc[] = "\033[32m[群組名單]\033[m\n"; @@ -349,10 +349,10 @@ multi_list(int *reciper) while (1) { stand_title("群組寄信名單"); ShowNameList(3, 0, msg_cc); - getdata(1, 0, - "(I)引入好友 (O)引入上線通知 (N)引入新文章通知 " - "(0-9)引入其他特別名單\n" - "(A)增加 (D)刪除 (M)確認寄信名單 (Q)取消 ?[M]", + move(1, 0); + prints("(I)引入好友 (O)引入上線通知 (N)引入新文章通知 (0-9)引入其他特別名單"); + getdata(2, 0, + "(A)增加 (D)刪除 (M)確認寄信名單 (Q)取消 ?[M]", genbuf, 4, LCECHO); switch (genbuf[0]) { case 'a': -- cgit v1.2.3 From edaf69a83b6a439662cd67c4fce78176c6f73267 Mon Sep 17 00:00:00 2001 From: victor <victor@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Fri, 7 Feb 2003 15:09:14 +0000 Subject: =?UTF-8?q?=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD?= =?UTF-8?q?=EF=BF=BD=EF=BF=BD=EF=BF=BDg=EF=BF=BD=EF=BF=BD=EF=BF=BD?= =?UTF-8?q?=EF=BF=BDlynx=EF=BF=BD=EF=BF=BD=EF=BF=BD|?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@650 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/weather.perl | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/pttbbs/util/weather.perl b/pttbbs/util/weather.perl index 88d380c1..911ff804 100644 --- a/pttbbs/util/weather.perl +++ b/pttbbs/util/weather.perl @@ -1,11 +1,15 @@ #!/usr/bin/perl -# $Id: weather.perl,v 1.3 2002/07/23 13:30:11 kcwu Exp $ +# $Id: weather.perl,v 1.4 2003/02/07 15:09:14 victor Exp $ # # 不能跑的話,看看 bbspost 的路徑是否正確。 # 如果發出的 post 沒有氣象報告而是說 URL 找不到,則確定一下能不能看到 # 中央氣象局的 WWW 及 URL 是否正確。 # 理論上適用所有 Eagle BBS 系列。 # -- Beagle Apr 13 1997 + +use lib '/home/bbs/bin'; +use LocalVars; + open(BBSPOST, "| bin/webgrep>etc/weather.tmp"); # 日期 open(DATE, "date +'%a %b %d %T %Y' |"); @@ -15,7 +19,7 @@ close DATE; # Header # 內容 -open(WEATHER, "/usr/bin/lynx -assume_charset=big5 -assume_local_charset=big5 -dump http://www.cwb.gov.tw/V3.0/weather/text/W03.htm |"); +open(WEATHER, "$LYNX -assume_charset=big5 -assume_local_charset=big5 -dump http://www.cwb.gov.tw/V3.0/weather/text/W03.htm |"); while (<WEATHER>) { print BBSPOST if ($_ ne "\n"); -- cgit v1.2.3 From 048cae8a45503b416403a909c5ca031c8a5ba54a Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sat, 8 Feb 2003 13:57:18 +0000 Subject: rm boards/d/deleted git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@651 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/sample/crontab | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pttbbs/sample/crontab b/pttbbs/sample/crontab index e7d0c957..3cf76fdc 100644 --- a/pttbbs/sample/crontab +++ b/pttbbs/sample/crontab @@ -43,6 +43,9 @@ # 每天執行一次生日程式 1 2 * * * bin/birth +# 每星期二五砍掉 boards/d/deleted +20 6 * * 2,5 /bin/rm -rf boards/d/deleted; mkdir boards/d/deleted + # 除每月一號整個重新計算精華區, 其他都只在星期二, 四, 六算有更動過的 # 計算前先砍掉 deleted的精華區 20 6 * * * /bin/rm -rf man/boards/d/deleted; mkdir man/boards/d/deleted -- cgit v1.2.3 From 8e17d57f61a19c92cff08e7cd16c245091d82c08 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Mon, 10 Feb 2003 17:34:39 +0000 Subject: fix bug in resolve_board() git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@652 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/util_cache.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pttbbs/util/util_cache.c b/pttbbs/util/util_cache.c index 2426044c..ee6325c3 100644 --- a/pttbbs/util/util_cache.c +++ b/pttbbs/util/util_cache.c @@ -1,4 +1,4 @@ -/* $Id: util_cache.c,v 1.8 2002/06/30 16:06:43 in2 Exp $ */ +/* $Id: util_cache.c,v 1.9 2003/02/10 17:34:39 in2 Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -316,6 +316,9 @@ static void reload_bcache() { if(SHM->Bbusystate) { safe_sleep(1); } + else{ + SHM->Buptime = SHM->Btouchtime; + } } void resolve_boards() { -- cgit v1.2.3 From a9fd14e2b5daad846f720389453dffc56c3becce Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Mon, 10 Feb 2003 17:41:45 +0000 Subject: lazy sort utmp git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@653 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/include/pttstruct.h | 6 ++++-- pttbbs/mbbsd/Makefile | 4 ++-- pttbbs/mbbsd/cache.c | 3 ++- pttbbs/mbbsd/mbbsd.c | 3 ++- pttbbs/util/shmctl.c | 15 +++++++++++++-- 5 files changed, 23 insertions(+), 8 deletions(-) diff --git a/pttbbs/include/pttstruct.h b/pttbbs/include/pttstruct.h index 12054171..898d4447 100644 --- a/pttbbs/include/pttstruct.h +++ b/pttbbs/include/pttstruct.h @@ -1,4 +1,4 @@ -/* $Id: pttstruct.h,v 1.28 2003/01/24 14:41:19 in2 Exp $ */ +/* $Id: pttstruct.h,v 1.29 2003/02/10 17:41:45 in2 Exp $ */ #ifndef INCLUDE_STRUCT_H #define INCLUDE_STRUCT_H @@ -313,7 +313,9 @@ typedef struct { int currsorted; time_t UTMPuptime; int UTMPnumber; - int UTMPbusystate; + char UTMPneedsort; + char UTMPbusystate; + char pad[2]; char gap[1024]; /* avoid some memory error / buffer overflow */ /* brdshm */ diff --git a/pttbbs/mbbsd/Makefile b/pttbbs/mbbsd/Makefile index 85e695f0..9204ead9 100644 --- a/pttbbs/mbbsd/Makefile +++ b/pttbbs/mbbsd/Makefile @@ -1,11 +1,11 @@ -# $Id: Makefile,v 1.17 2003/01/19 16:02:25 kcwu Exp $ +# $Id: Makefile,v 1.18 2003/02/10 17:41:45 in2 Exp $ # 訂義基本初值 BBSHOME?= $(HOME) BBSHOME?= /home/bbs OSTYPE?= FreeBSD CC?= gcc -CFLAGS+= -Wall -W -pipe -DBBSHOME='"$(BBSHOME)"' -I../include +CFLAGS+= -Wall -pipe -DBBSHOME='"$(BBSHOME)"' -I../include LDFLAGS+= -pipe -Wall LIBS+= -lcrypt diff --git a/pttbbs/mbbsd/cache.c b/pttbbs/mbbsd/cache.c index ae5caad3..023ac8a7 100644 --- a/pttbbs/mbbsd/cache.c +++ b/pttbbs/mbbsd/cache.c @@ -1,4 +1,4 @@ -/* $Id: cache.c,v 1.57 2003/01/24 19:48:14 in2 Exp $ */ +/* $Id: cache.c,v 1.58 2003/02/10 17:41:45 in2 Exp $ */ #include "bbs.h" #ifndef __FreeBSD__ @@ -476,6 +476,7 @@ purge_utmp(userinfo_t * uentp) { logout_friend_online(uentp); memset(uentp, 0, sizeof(userinfo_t)); + SHM->UTMPneedsort = 1; } #endif diff --git a/pttbbs/mbbsd/mbbsd.c b/pttbbs/mbbsd/mbbsd.c index 2ef59687..3a5828b0 100644 --- a/pttbbs/mbbsd/mbbsd.c +++ b/pttbbs/mbbsd/mbbsd.c @@ -1,4 +1,4 @@ -/* $Id: mbbsd.c,v 1.65 2003/01/24 19:48:14 in2 Exp $ */ +/* $Id: mbbsd.c,v 1.66 2003/02/10 17:41:45 in2 Exp $ */ #include "bbs.h" #define SOCKET_QLEN 4 @@ -743,6 +743,7 @@ setup_utmp(int mode) if (enter_uflag & CLOAK_FLAG) uinfo.invisible = YEA; getnewutmpent(&uinfo); + SHM->UTMPneedsort = 1; #ifndef _BBS_UTIL_C_ friend_load(); nice(3); diff --git a/pttbbs/util/shmctl.c b/pttbbs/util/shmctl.c index 1eea2825..f1b7765c 100644 --- a/pttbbs/util/shmctl.c +++ b/pttbbs/util/shmctl.c @@ -1,4 +1,4 @@ -/* $Id: shmctl.c,v 1.31 2003/01/24 19:48:29 in2 Exp $ */ +/* $Id: shmctl.c,v 1.32 2003/02/10 17:41:45 in2 Exp $ */ #include "bbs.h" #include <sys/wait.h> @@ -59,6 +59,7 @@ int utmpfix(int argc, char **argv) time_t now, timeout = -1; char *clean, buf[1024], ch; IDLE_t idle[USHM_SIZE]; + char changeflag = 0; while( (ch = getopt(argc, argv, "nt:l:")) != -1 ) switch( ch ){ @@ -131,9 +132,12 @@ int utmpfix(int argc, char **argv) i, clean, SHM->uinfo[which].userid); memset(&SHM->uinfo[which], 0, sizeof(userinfo_t)); --nownum; + changeflag = 1; } } SHM->UTMPbusystate = 0; + if( changeflag ) + SHM->UTMPneedsort = 1; return 0; } /* end of utmpfix ---------------------------------------------------------- */ @@ -202,6 +206,7 @@ inline void utmpsort(void) userinfo_t *uentp; int count, i, ns; short nusers[MAX_BOARD]; + SHM->UTMPbusystate = 1; SHM->UTMPuptime = time(NULL); ns = (SHM->currsorted ? 0 : 1); @@ -264,7 +269,13 @@ int utmpsortd(int argc, char **argv) } else{ while( 1 ){ - utmpsort(); + int i; + for( i = 0 ; SHM->UTMPbusystate && i < 5 ; ++i ) + usleep(300000); + + if( SHM->UTMPneedsort ) + utmpsort(); + sleep(1); } } -- cgit v1.2.3 From 8767f8623f62aa65f9130d07a1f7deba0e6e1a7e Mon Sep 17 00:00:00 2001 From: victor <victor@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Tue, 11 Feb 2003 06:03:31 +0000 Subject: train git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@654 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/page.c | 180 ++++++++++++++++++++++++----------------- pttbbs/util/Makefile | 4 +- pttbbs/util/railway_wrapper.pl | 119 +++++++++++++++++++++++++++ 3 files changed, 229 insertions(+), 74 deletions(-) create mode 100755 pttbbs/util/railway_wrapper.pl diff --git a/pttbbs/mbbsd/page.c b/pttbbs/mbbsd/page.c index 9c01eb6d..e1bcd052 100644 --- a/pttbbs/mbbsd/page.c +++ b/pttbbs/mbbsd/page.c @@ -1,27 +1,26 @@ -/* $Id: page.c,v 1.10 2003/01/19 16:06:06 kcwu Exp $ */ +/* $Id: page.c,v 1.11 2003/02/11 06:03:31 victor Exp $ */ #include "bbs.h" #define hpressanykey(a) {move(22, 0); prints(a); pressanykey();} -static void -filt_railway(char *fpath) -{ - char buf[256], tmppath[32]; - FILE *fp = fopen(fpath, "w"), *tp; +#define TITLE "\033[1;37;45m 火車查詢系統 \033[1;44;33m原作者:Heat\033[m" - snprintf(tmppath, sizeof(tmppath), "%s.railway", fpath); - if (!fp || !(tp = fopen(tmppath, "r"))) // XXX fclose(fp) if tp fail - return; +void +print_station(const char *addr[6][100], int path, int *line, int *num) +{ + int i; + char genbuf[128]; - while (fgets(buf, 255, tp)) { - if (strstr(buf, "INLINE")) - continue; - if (strstr(buf, "LINK")) - break; - fprintf(fp, "%s", buf); - } - fclose(fp); - fclose(tp); - unlink(tmppath); + *num = 0; + move(*line,0); + do{ + for(i=0; i<7 && addr[path - 1][*num]!=NULL; i++){ + sprintf(genbuf, " %2d.%-6s", (*num)+1, addr[path - 1][*num]); + (*num)++; + outs(genbuf); + } + outs("\n"); + (*line)++; + }while(i==7); } int @@ -29,94 +28,131 @@ main_railway() { fileheader_t mhdr; char genbuf[200]; - int from, to, time_go, time_reach; + int from, to, time_go, time_reach, date, path; + int line, station_num; char tt[2], type[2]; char command[256], buf[8]; - char *addr[] = { - "基隆", "八堵", "七堵", "五堵", "汐止", "南港", "松山", "台北", "萬華", - "板橋", "樹林", "山佳", "鶯歌", "桃園", "內壢", "中壢", "埔心", "楊梅", - "湖口", "新豐", "竹北", "新竹", "香山", "崎頂", "竹南", "造橋", "豐富", - "談文", "大山", "後龍", "龍港", "白沙屯", "新埔", "通霄", "苑裡", - "日南", "大甲", "臺中港", "清水", "沙鹿", "龍井", "大肚", "追分", - "苗栗", "南勢", "銅鑼", "三義", "勝興", "泰安", "后里", "豐原", "潭子", - "台中", "烏日", "成功\", "彰化", "花壇", "員林", "永靖", "社頭", - "田中", "二水", "林內", "石榴", "斗六", "斗南", "石龜", "大林", - "民雄", "嘉義", "水上", "南靖", "後壁", "新營", "柳營", "林鳳營", - "隆田", "拔林", "善化", "新市", "永康", "台南", "保安", "中洲", - "大湖", "路竹", "岡山", "橋頭", "楠梓", "左營", "高雄", "鳳山", - "九曲堂", "屏東", NULL, NULL - }; + static const char *addr[6][100] = { + { + "基隆", "八堵", "七堵", "五堵", "汐止", "南港", "松山", "台北", "萬華", + "板橋", "樹林", "山佳", "鶯歌", "桃園", "內壢", "中壢", "埔心", "楊梅", + "湖口", "新豐", "竹北", "新竹", "香山", "崎頂", "竹南", "造橋", "豐富", + "談文", "大山", "後龍", "龍港", "白沙屯", "新埔", "通霄", "苑裡", + "日南", "大甲", "臺中港", "清水", "沙鹿", "龍井", "大肚", "追分", + "苗栗", "南勢", "銅鑼", "三義", "勝興", "泰安", "后里", "豐原", "潭子", + "台中", "烏日", "成功\", "彰化", "花壇", "員林", "永靖", "社頭", + "田中", "二水", "林內", "石榴", "斗六", "斗南", "石龜", "大林", + "民雄", "嘉義", "水上", "南靖", "後壁", "新營", "柳營", "林鳳營", + "隆田", "拔林", "善化", "新市", "永康", "台南", "保安", "中洲", + "大湖", "路竹", "岡山", "橋頭", "楠梓", "左營", "高雄", "鳳山", + "九曲堂", "屏東", NULL + }, + { + "樹林", "板橋", "萬華", "台北", "松山", "南港", "汐止", "基隆", "八堵", + "暖暖", "四腳亭", "瑞芳", "侯硐", "三貂嶺", "牡丹", "雙溪", "貢寮", + "福隆", "石城", "大里", "大溪", "龜山", "外澳", "頭城", "頂埔", "礁溪", + "四城", "宜蘭", "二結", "中里", "羅東", "冬山", "新馬", "蘇澳新站", + "蘇澳", "永樂", "東澳", "南澳", "武塔", "漢本", "和平", "和仁", "崇德", + "新城", "景美", "北埔", "花蓮", "吉安", "志學", "平和", "壽豐", "豐田", + "溪口", "南平", "鳳林", "萬榮", "光復", "大富", "富源", "瑞北", "瑞穗", + "三民", "玉里", "安通", "東里", "東竹", "富里", "池上", "海瑞", "關山", + "月美", "瑞和", "瑞源", "鹿野", "山里", "台東", NULL + }, + { + "高雄", "鳳山", "後庄", "九曲堂", "六塊厝", "屏東", "歸來", "麟洛", + "西勢", "竹田", "潮州", "崁頂", "南州", "鎮安", "林邊", "佳冬", "東海", + "枋寮", "加祿", "內獅", "枋山", "古莊", "大武", "瀧溪", "多良", "金崙", + "太麻里", "知本", "康樂", "台東", NULL + }, + { + "八堵", "暖暖", "四腳亭", "瑞芳", "侯硐", "三貂嶺", "大華", "十分", + "望古", "嶺腳", "平溪", "菁桐", NULL + }, + { + "新竹", "竹中", "上員", "榮華", "竹東", "橫山", "九讚頭", "合興", "南河", + "內灣", NULL + }, + { + "台中", "烏日", "成功\", "彰化", "花壇", "員林", "永靖", "社頭", "田中", + "二水", "源泉", "濁水", "龍泉", "集集", "水里", "車埕", NULL + } + }; setutmpmode(RAIL_WAY); clear(); move(0, 25); - prints("\033[1;37;45m 火車查詢系統 \033[1;44;33m作者:Heat\033[m"); + prints(TITLE); move(1, 0); - outs("\033[1;33m\n" - " 1.基隆 16.中壢 31.龍港 46.銅鑼 61.田中 76.林鳳營 91.高雄\n" - " 2.八堵 17.埔心 32.白沙屯 47.三義 62.二水 77.隆田 92.鳳山\n" - " 3.七堵 18.楊梅 33.新埔 48.勝興 63.林內 78.拔林 93.九曲堂\n" - " 4.五堵 19.湖口 34.通霄 49.泰安 64.石榴 79.善化 94.屏東\n" - " 5.汐止 20.新豐 35.苑裡 50.后里 65.斗六 80.新市\n" - " 6.南港 21.竹北 36.日南 51.豐原 66.斗南 81.永康\n" - " 7.松山 22.新竹 37.大甲 52.潭子 67.石龜 82.台南\n" - " 8.台北 23.香山 38.臺中港 53.台中 68.大林 83.保安\n" - " 9.萬華 24.崎頂 39.清水 54.烏日 69.民雄 84.中洲\n" - "10.板橋 25.竹南 40.沙鹿 55.成功\ 70.嘉義 85.大湖\n" - "11.樹林 26.造橋 41.龍井 56.彰化 71.水上 86.路竹\n" - "12.山佳 27.豐富 42.大肚 57.花壇 72.南靖 87.岡山\n" - "13.鶯歌 28.談文 43.追分 58.員林 73.後壁 88.橋頭\n" - "14.桃園 29.大山 44.苗栗 59.永靖 74.新營 89.楠梓\n" - "15.內壢 30.後龍 45.南勢 60.社頭 75.柳營 90.左營\033[m"); - getdata(17, 0, "\033[1;35m你確定要搜尋嗎?[y/n]:\033[m", buf, 2, LCECHO); + getdata(3, 0, "\033[1;35m你確定要搜尋嗎?[y/n]:\033[m", buf, 2, LCECHO); if (buf[0] != 'y' && buf[0] != 'Y') return 0; + outs("\033[1;33m1.西部幹線(含台中線) 2.東部幹線(含北迴線)\n"); + outs("\033[1;33m3.南迴線 4.平溪線 5.內灣線 6.集集線\n"); while (1) - if (getdata(18, 0, "\033[1;35m請輸入起站(1-94):\033[m", buf, 3, LCECHO) && - (from = atoi(buf)) >= 1 && from <= 94) + if (getdata(7, 0, "\033[1;35m請選擇路線(1-6):\033[m", buf, 2, LCECHO) && + (path = atoi(buf)) >= 1 && path <= 6) break; + + clear(); + move(0, 25); + prints(TITLE); + line = 3; + print_station(addr, path, &line, &station_num); + sprintf(genbuf, "\033[1;35m請輸入起站(1-%d):\033[m", station_num); while (1) - if (getdata(18, 40, "\033[1;35m請輸入目的地(1-94):\033[m", - buf, 3, LCECHO) && - (to = atoi(buf)) >= 1 && to <= 94) - break; + if (getdata(line, 0, genbuf, buf, 3, LCECHO) && (from = atoi(buf)) >= 1 && from <= station_num) + break; + sprintf(genbuf, "\033[1;35m請輸入終站(1-%d):\033[m", station_num); + while (1) + if (getdata(line, 40, genbuf, buf, 3, LCECHO) && (to = atoi(buf)) >= 1 && to <= station_num) + break; + line++; + while (1) - if (getdata(19, 0, "\033[1;35m請輸入時間區段(0-23) 由:\033[m", + if (getdata(line, 0, "\033[1;35m請輸入時間區段(0-23) 由:\033[m", buf, 3, LCECHO) && (time_go = atoi(buf)) >= 0 && time_go <= 23) break; while (1) - if (getdata(19, 40, "\033[1;35m到:\033[m", buf, 3, LCECHO) && + if (getdata(line, 40, "\033[1;35m到:\033[m", buf, 3, LCECHO) && (time_reach = atoi(buf)) >= 0 && time_reach <= 23) break; + line++; + if (path<=3){ while (1) - if (getdata(20, 0, "\033[1;35m想查詢 1:對號快車 2:普通平快\033[m", - type, 2, LCECHO) && (type[0] == '1' || type[0] == '2')) - break; + if (getdata(line, 0, "\033[1;35m想查詢 1:對號快車 2:普通平快\033[m", + type, 2, LCECHO) && (type[0] == '1' || type[0] == '2')) + break; + line++; + } while (1) - if (getdata(21, 0, "\033[1;35m欲查詢 1:出發時間 2:到達時間\033[m", + if (getdata(line, 0, "\033[1;35m欲查詢 1:出發時間 2:到達時間\033[m", tt, sizeof(tt), LCECHO) && (tt[0] == '1' || tt[0] == '2')) break; + line++; + while (1) + if (getdata(line, 0, "\033[1;35m請輸入欲查詢日期(0-29)天後\033[m", + buf, 3, LCECHO) && (date = atoi(buf))>=0 && date<=29) + break; + line++; + sethomepath(genbuf, cuser.userid); stampfile(genbuf, &mhdr); strlcpy(mhdr.owner, "Ptt搜尋器", sizeof(mhdr.owner)); strncpy(mhdr.title, "火車時刻搜尋結果", TTLEN); - snprintf(command, sizeof(command), "echo \"from-station=%s&to-station=%s" - "&from-time=%02d00&to-time=%02d00&tt=%s&type=%s\" | " - "lynx -dump -post_data " - "\"http://www.railway.gov.tw/cgi-bin/timetk.cgi\" > %s.railway", - addr[from - 1], addr[to - 1], time_go, time_reach, + snprintf(command, sizeof(command), "echo \"path=%d from-station=%s to-station=%s" + " from-time=%02d to-time=%02d tt=%s type=%s date=%d\" | /home/bbs/bin/railway_wrapper.pl > %s", + path, addr[path - 1][from - 1], addr[path - 1][to - 1], time_go, time_reach, (tt[0] == '1') ? "start" : "arriv", - (type[0] == '1') ? "fast" : "slow", genbuf); + (type[0] == '1') ? "fast" : "slow", date, genbuf); system(command); - filt_railway(genbuf); sethomedir(genbuf, cuser.userid); if (append_record(genbuf, &mhdr, sizeof(mhdr)) == -1) return -1; - hpressanykey("\033[1;31m我們會把搜尋結果很快就寄給你唷 ^_^\033[m"); + hpressanykey("\033[1;31m我們會把搜尋結果很快地寄給你唷 ^_^\033[m"); return 0; } diff --git a/pttbbs/util/Makefile b/pttbbs/util/Makefile index 8e0479e4..06a4e471 100644 --- a/pttbbs/util/Makefile +++ b/pttbbs/util/Makefile @@ -1,4 +1,4 @@ -# $Id: Makefile,v 1.22 2002/11/08 21:16:25 in2 Exp $ +# $Id: Makefile,v 1.23 2003/02/11 06:03:31 victor Exp $ BBSHOME?=$(HOME) OSTYPE!=uname @@ -35,7 +35,7 @@ CPROGS= bbsmail BM_money post account birth deluserfile expire mandex\ PROGS= $(CPROGS) BM_money.sh backpasswd.sh mailog.sh opendice.sh\ openticket.sh stock.sh topsong.sh weather.sh stock.perl weather.perl\ toplazyBM.sh toplazyBBM.sh dailybackup.pl tarqueue.pl waterball.pl \ - filtermail.pl getbackup.pl udnnews.pl rebuildaloha.pl + filtermail.pl getbackup.pl udnnews.pl rebuildaloha.pl railway_wrapper.pl all: $(PROGS) diff --git a/pttbbs/util/railway_wrapper.pl b/pttbbs/util/railway_wrapper.pl new file mode 100755 index 00000000..b6885173 --- /dev/null +++ b/pttbbs/util/railway_wrapper.pl @@ -0,0 +1,119 @@ +#!/usr/bin/perl +# +# 您可以使用這個檔案應付鐵路局網址的異動 +# 或是以擅於字串處理的 perl 修正以下程式碼 :) +# +#VictorHsieh 2003.02.11 + +use lib '/home/bbs/bin'; +use LocalVars; +use vars qw/ %opt %station_num @arg $command $addr/; +use strict; + +$addr = "http://passenger.tra.gov.tw/ap/index.asp"; + +@arg = split ' ', <STDIN>; +map { /(.+)=(.+)/ and $opt{$1} = $2 } grep /.+=.+/, @arg; + +station_init(); +translate(); + +$command = "MIval=Train_Time&encode=Big5&action=on"; +map { $command .= "&$_=$opt{$_}"} keys %opt; +exec "$LYNX -dump -assume_charset=big5 -nolist \"$addr?$command\""; + +# 將 page.c 中的格式轉為鐵路局所使用的格式 +sub translate{ + change_opt('from-station', 'Station1'); + change_opt('to-station', 'Station2'); + change_opt('from-time', 'From_Time'); + change_opt('to-time', 'To_Time'); + change_opt('type', 'Type'); + change_opt('tt', 'Time'); + change_opt('date','Departure_Date'); + change_opt('path', 'line'); +} + +# 轉換參數的表示法 +sub change_opt{ + my ($old, $new) = @_; + if(defined $opt{$old}){ + if( $old =~ /station/ ){ + $opt{$old} = $station_num{$opt{$old}}; + } + elsif( $old =~ /type/ ){ + $opt{$old} = ($opt{$old} eq 'fast')? 'F' : 'S'; + } + elsif( $old =~ /tt/ ){ + $opt{$old} = ($opt{$old} eq 'start')? 'D' : 'A'; + } + elsif( $old =~ /date/ ){ + my ($sec, $min, $hour, $mday, $mon, $year) = gmtime; + $mday = $mday + $opt{$old}; + $mon++; + $opt{$old} = join '/', + ($year+1900, + ($mon>9)? $mon : "0$mon", + ($mday>9)? $mday : "0$mday"); + } + elsif( $old =~ /path/ ){ + my @line = qw/ mainwest maineast mainsouth pin innerbay gg/; + $opt{$old} = $line[$opt{$old}-1]; + } + + $opt{$new} = $opt{$old} and delete $opt{$old}; + } +} + +# 各站代碼對應 +sub station_init{ + %station_num = ( + "基隆" => 1001, "八堵" => 1002, "七堵" => 1003, "五堵" => 1004, + "汐止" => 1005, "南港" => 1006, "松山" => 1007, "台北" => 1008, + "萬華" => 1009, "板橋" => 1011, "樹林" => 1012, "山佳" => 1013, + "鶯歌" => 1014, "桃園" => 1015, "內壢" => 1016, "中壢" => 1017, + "埔心" => 1018, "楊梅" => 1019, "富岡" => 1020, "湖口" => 1021, + "新豐" => 1022, "竹北" => 1023, "新竹" => 1025, "香山" => 1026, + "崎頂" => 1027, "竹南" => 1028, "談文" => 1102, "大山" => 1104, + "後龍" => 1105, "龍港" => 1106, "白沙屯" => 1107, "新埔" => 1108, + "通霄" => 1109, "苑裡" => 1110, "日南" => 1111, "大甲" => 1112, + "臺中港" => 1113, "清水" => 1114, "沙鹿" => 1115, "龍井" => 1116, + "大肚" => 1117, "追分" => 1118, "彰化" => 1120, "花壇" => 1202, + "員林" => 1203, "永靖" => 1204, "社頭" => 1205, "田中" => 1206, + "二水" => 1207, "林內" => 1208, "石榴" => 1209, "斗六" => 1210, + "斗南" => 1211, "石龜" => 1212, "大林" => 1213, "民雄" => 1214, + "嘉義" => 1215, "水上" => 1217, "南靖" => 1218, "後壁" => 1219, + "新營" => 1220, "柳營" => 1221, "林鳳營" => 1222, "隆田" => 1223, + "拔林" => 1224, "善化" => 1225, "新市" => 1226, "永康" => 1227, + "台南" => 1228, "保安" => 1229, "中洲" => 1230, "大湖" => 1231, + "路竹" => 1232, "岡山" => 1233, "橋頭" => 1234, "楠梓" => 1235, + "左營" => 1236, "高雄" => 1238, "大橋" => 1239, "造橋" => 1302, + "豐富" => 1304, "苗栗" => 1305, "南勢" => 1307, "銅鑼" => 1308, + "三義" => 1310, "泰安" => 1314, "后里" => 1315, "豐原" => 1317, + "潭子" => 1318, "台中" => 1319, "烏日" => 1320, "成功\" => 1321, + "大慶" => 1322, "太原" => 1323, "鳳山" => 1402, "後庄" => 1403, + "九曲堂" => 1404, "六塊厝" => 1405, "屏東" => 1406, "吉安" => 1602, + "志學" => 1604, "平和" => 1605, "壽豐" => 1606, "豐田" => 1607, + "溪口" => 1608, "南平" => 1609, "鳳林" => 1610, "萬榮" => 1611, + "光復" => 1612, "大富" => 1613, "富源" => 1614, "瑞北" => 1615, + "瑞穗" => 1616, "三民" => 1617, "玉里" => 1619, "安通" => 1620, + "東里" => 1621, "東竹" => 1622, "富里" => 1623, "池上" => 1624, + "海瑞" => 1625, "關山" => 1626, "月美" => 1627, "瑞和" => 1628, + "瑞源" => 1629, "鹿野" => 1630, "山里" => 1631, "台東" => 1632, + "永樂" => 1703, "東澳" => 1704, "南澳" => 1705, "武塔" => 1706, + "漢本" => 1708, "和平" => 1709, "和仁" => 1710, "崇德" => 1711, + "新城" => 1712, "景美" => 1713, "北埔" => 1714, "花蓮" => 1715, + "暖暖" => 1802, "四腳亭" => 1803, "瑞芳" => 1804, "侯硐" => 1805, + "三貂嶺" => 1806, "牡丹" => 1807, "雙溪" => 1808, "貢寮" => 1809, + "福隆" => 1810, "石城" => 1811, "大里" => 1812, "大溪" => 1813, + "龜山" => 1814, "外澳" => 1815, "頭城" => 1816, "頂埔" => 1817, + "礁溪" => 1818, "四城" => 1819, "宜蘭" => 1820, "二結" => 1821, + "中里" => 1822, "羅東" => 1823, "冬山" => 1824, "新馬" => 1825, + "蘇澳新站" => 1826, "蘇澳" => 1827, "大華" => 1903, "十分" => 1904, + "望古" => 1905, "嶺腳" => 1906, "平溪" => 1907, "菁桐 " => 1908, + "竹中" => 2203, "上員" => 2204, "竹東" => 2205, "橫山" => 2206, + "九讚頭" => 2207, "合興" => 2208, "南河" => 2209, "內灣" => 2210, + "榮華" => 2211, "源泉" => 2702, "濁水" => 2703, "龍泉" => 2704, + "集集" => 2705, "水里" => 2706, "車埕" => 2707, + ); +} -- cgit v1.2.3 From 661af1704d003c535cbde59ccae11a2cdd232bd3 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Tue, 11 Feb 2003 07:22:45 +0000 Subject: add @five git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@655 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/sample/etc/@five | 16 ++++++++++++++++ pttbbs/sample/etc/Makefile | 2 +- 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 pttbbs/sample/etc/@five diff --git a/pttbbs/sample/etc/@five b/pttbbs/sample/etc/@five new file mode 100644 index 00000000..8c51c8d6 --- /dev/null +++ b/pttbbs/sample/etc/@five @@ -0,0 +1,16 @@ + A B C D E F G H I J K L M N O + 15┌┬┬┬┬┬┬┬┬┬┬┬┬┬┐ + 14├┼┼┼┼┼┼┼┼┼┼┼┼┼┤ [q] 認輸離開 + 13├┼┼┼┼┼┼┼┼┼┼┼┼┼┤ [u] 悔棋 + 12├┼┼┼┼┼┼┼┼┼┼┼┼┼┤ [p] 要求和棋 + 11├┼┼┼┼┼┼┼┼┼┼┼┼┼┤ + 10├┼┼┼┼┼┼┼┼┼┼┼┼┼┤ + 9├┼┼┼┼┼┼┼┼┼┼┼┼┼┤ + 8├┼┼┼┼┼┼┼┼┼┼┼┼┼┤ [歡迎到five_chess討論五子棋喔] + 7├┼┼┼┼┼┼┼┼┼┼┼┼┼┤ + 6├┼┼┼┼┼┼┼┼┼┼┼┼┼┤ + 5├┼┼┼┼┼┼┼┼┼┼┼┼┼┤ + 4├┼┼┼┼┼┼┼┼┼┼┼┼┼┤ + 3├┼┼┼┼┼┼┼┼┼┼┼┼┼┤ + 2├┼┼┼┼┼┼┼┼┼┼┼┼┼┤ + 1└┴┴┴┴┴┴┴┴┴┴┴┴┴┘ diff --git a/pttbbs/sample/etc/Makefile b/pttbbs/sample/etc/Makefile index 8881af2a..b607587f 100644 --- a/pttbbs/sample/etc/Makefile +++ b/pttbbs/sample/etc/Makefile @@ -2,7 +2,7 @@ SUBDIR=chickens BBSHOME?=$(HOME) TARGET=$(BBSHOME)/etc/ FILES= Welcome Welcome_login goodbye register registered ve.hlp Logout\ - Welcome_birth domain_name_query feast today_boring + Welcome_birth domain_name_query feast today_boring @five all: -- cgit v1.2.3 From f82532a162b29aa32d1ff3a741f80f708c9f15ec Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Tue, 11 Feb 2003 07:23:57 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@656 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/docs/FAQ | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pttbbs/docs/FAQ b/pttbbs/docs/FAQ index a96d0f86..fb0ddb9f 100644 --- a/pttbbs/docs/FAQ +++ b/pttbbs/docs/FAQ @@ -35,6 +35,9 @@ in Linux: 在設定完成後, 原來已經登入的使用者須要重新登入, 才會重新載入至新設的 group內. +─────────────────────────────────────── +五子棋盤沒有出現 +請將 sample/etc/@five 拷貝到 ~bbs/etc/ 即可. 作者 DavidYu (軱~~~~~~~~~~) 看板 PttSrc 標題 sendmail.cf要改的地方(參考用) -- cgit v1.2.3 From bbbeb087065c9982d6b6eca84fa9180d1c745162 Mon Sep 17 00:00:00 2001 From: victor <victor@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Tue, 11 Feb 2003 15:30:15 +0000 Subject: 'G' for searching marked article git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@657 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/read.c | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/pttbbs/mbbsd/read.c b/pttbbs/mbbsd/read.c index ea2e4a73..e527cac7 100644 --- a/pttbbs/mbbsd/read.c +++ b/pttbbs/mbbsd/read.c @@ -1,4 +1,4 @@ -/* $Id: read.c,v 1.18 2003/01/23 18:39:24 in2 Exp $ */ +/* $Id: read.c,v 1.19 2003/02/11 15:30:15 victor Exp $ */ #include "bbs.h" static fileheader_t *headers = NULL; @@ -464,7 +464,10 @@ select_read(keeploc_t * locmem, int sr_mode) else if (sr_mode == RS_NEWPOST) { strlcpy(buf3, "Re: ", sizeof(buf3)); query = buf3; - } else { + } + else if (sr_mode == RS_THREAD) { + + } else { char buff[80]; char newdata[35]; @@ -526,6 +529,15 @@ select_read(keeploc_t * locmem, int sr_mode) } } break; + case RS_THREAD: + while (read(fd, &fh, size) == size) { + ++reference; + if (fh.filemode & FILE_MARKED) { + write(fr, &fh, size); + fh.money = reference | FHR_REFERENCE; + } + } + break; } fstat(fr, &st); close(fr); @@ -574,6 +586,13 @@ i_read_key(onekey_t * rcmdlist, keeploc_t * locmem, int ch, int bid) return NEWDIRECT; else return READ_REDRAW; + + case 'G': + if (select_read(locmem,RS_THREAD)) /* marked articles */ + return NEWDIRECT; + else + return READ_REDRAW; + case '/': case '?': if (select_read(locmem, RS_RELATED)) -- cgit v1.2.3 From 419f7ab06f8d89e505150d67108624c12edadb78 Mon Sep 17 00:00:00 2001 From: victor <victor@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Wed, 12 Feb 2003 05:20:04 +0000 Subject: Gamble -> Ctrl('G') git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@658 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/bbs.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pttbbs/mbbsd/bbs.c b/pttbbs/mbbsd/bbs.c index 0622e720..d24e9575 100644 --- a/pttbbs/mbbsd/bbs.c +++ b/pttbbs/mbbsd/bbs.c @@ -1,4 +1,4 @@ -/* $Id: bbs.c,v 1.77 2003/01/24 14:41:19 in2 Exp $ */ +/* $Id: bbs.c,v 1.78 2003/02/12 05:20:04 victor Exp $ */ #include "bbs.h" static void @@ -1862,7 +1862,7 @@ static char *board_help[] = { #endif "(E) 重編文章 (^H) 列出所有的 New Post(s)", "\01板主命令", - "(G) 舉辦賭盤/停止下注/開獎(W/K/v) 編輯備忘錄/水桶名單/可看見名單", + "(^G) 舉辦賭盤/停止下注/開獎(W/K/v) 編輯備忘錄/水桶名單/可看見名單", "(M/o) 舉行投票/編私投票名單 (m/c/g) 保留文章/選錄精華/文摘", "(D) 刪除一段範圍的文章 (T/B) 重編文章標題/重編看板標題", "(I) 開放/禁止看版推薦 (t/^D) 標記文章/砍除標記的文章", @@ -1968,7 +1968,7 @@ struct onekey_t read_comms[] = { {'E', edit_post}, #ifndef NO_GAMBLE {'f', join_gamble}, - {'G', hold_gamble}, + {Ctrl('G'), hold_gamble}, #endif {'g', good_post}, #ifdef BMCHS -- cgit v1.2.3 From 69cb4d987975d19c5f51f3dacd9c7714d845ae05 Mon Sep 17 00:00:00 2001 From: victor <victor@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Wed, 12 Feb 2003 05:22:31 +0000 Subject: help page @@; git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@659 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/bbs.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pttbbs/mbbsd/bbs.c b/pttbbs/mbbsd/bbs.c index d24e9575..0587a5ee 100644 --- a/pttbbs/mbbsd/bbs.c +++ b/pttbbs/mbbsd/bbs.c @@ -1,4 +1,4 @@ -/* $Id: bbs.c,v 1.78 2003/02/12 05:20:04 victor Exp $ */ +/* $Id: bbs.c,v 1.79 2003/02/12 05:22:31 victor Exp $ */ #include "bbs.h" static void @@ -1862,7 +1862,7 @@ static char *board_help[] = { #endif "(E) 重編文章 (^H) 列出所有的 New Post(s)", "\01板主命令", - "(^G) 舉辦賭盤/停止下注/開獎(W/K/v) 編輯備忘錄/水桶名單/可看見名單", + "(^G) 舉辦賭盤/停止下注/開獎(W/K/v) 編輯備忘錄/水桶名單/可看見名單", "(M/o) 舉行投票/編私投票名單 (m/c/g) 保留文章/選錄精華/文摘", "(D) 刪除一段範圍的文章 (T/B) 重編文章標題/重編看板標題", "(I) 開放/禁止看版推薦 (t/^D) 標記文章/砍除標記的文章", -- cgit v1.2.3 From 031c662b8f4894e01f97b0edaabaa06280c46492 Mon Sep 17 00:00:00 2001 From: victor <victor@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Wed, 12 Feb 2003 14:31:36 +0000 Subject: MRT map git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@660 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/include/proto.h | 3 ++- pttbbs/mbbsd/menu.c | 4 ++- pttbbs/mbbsd/xyz.c | 9 ++++++- pttbbs/sample/etc/MRT.map | 62 +++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 75 insertions(+), 3 deletions(-) create mode 100644 pttbbs/sample/etc/MRT.map diff --git a/pttbbs/include/proto.h b/pttbbs/include/proto.h index 20963df0..0fb19043 100644 --- a/pttbbs/include/proto.h +++ b/pttbbs/include/proto.h @@ -1,4 +1,4 @@ -/* $Id: proto.h,v 1.36 2003/01/19 01:29:39 in2 Exp $ */ +/* $Id: proto.h,v 1.37 2003/02/12 14:31:36 victor Exp $ */ #ifndef INCLUDE_PROTO_H #define INCLUDE_PROTO_H @@ -559,6 +559,7 @@ int x_86(); int x_history(); int x_weather(); int x_stock(); +int x_mrtmap(); int note(); int Goodbye(); diff --git a/pttbbs/mbbsd/menu.c b/pttbbs/mbbsd/menu.c index 9e234488..3293e1d2 100644 --- a/pttbbs/mbbsd/menu.c +++ b/pttbbs/mbbsd/menu.c @@ -1,4 +1,4 @@ -/* $Id: menu.c,v 1.22 2003/01/17 10:15:16 kcwu Exp $ */ +/* $Id: menu.c,v 1.23 2003/02/12 14:31:34 victor Exp $ */ #include "bbs.h" /* help & menu processring */ @@ -507,6 +507,8 @@ static int playground() { static commands_t slist[] = { {x_dict,0, "11Dictionary " "【\033[1;33m 趣味大字典 \033[m】"}, + {x_mrtmap, 0, "22MRTmap " + "【\033[1;34m 捷運地圖 \033[m】"}, {main_railway, PERM_LOGINOK, "33Railway " "【\033[1;32m 火車表查詢 \033[m】"}, {NULL, 0, NULL} diff --git a/pttbbs/mbbsd/xyz.c b/pttbbs/mbbsd/xyz.c index d1e386f1..55f9e475 100644 --- a/pttbbs/mbbsd/xyz.c +++ b/pttbbs/mbbsd/xyz.c @@ -1,4 +1,4 @@ -/* $Id: xyz.c,v 1.16 2003/01/23 18:39:24 in2 Exp $ */ +/* $Id: xyz.c,v 1.17 2003/02/12 14:31:34 victor Exp $ */ #include "bbs.h" /* 各種統計及相關資訊列表 */ @@ -94,6 +94,13 @@ x_weather() return 0; } +int +x_mrtmap() +{ + more("etc/MRT.map", YEA); + return 0; +} + int x_stock() { diff --git a/pttbbs/sample/etc/MRT.map b/pttbbs/sample/etc/MRT.map new file mode 100644 index 00000000..4732ae32 --- /dev/null +++ b/pttbbs/sample/etc/MRT.map @@ -0,0 +1,62 @@ + + ●淡水 ※ 感謝本站 MRT 版提供 ※ +  + ○紅樹林 +  + ○竹圍 ▆▆▆▆▆▆▆▆ +  ▋' ' ▋ + ○關渡 ▋新店 ▋ +  ▋__ __ ▋ + ○忠義 ▋ ▏ ▏ ▏ ▏▋ +  歈龤新北投 ▋ ▏ ▏ ▏ ▏▋ + 耤堡龤盟 ▋ ▏ ▏ ▏ ▏▋ + 復 北 ○奇岩 ▆▆▆▆▆▆▆▆▆▆▆ + 興 投  ███████████ + 崗 ○唭哩岸  ███████████ +  ███████████ + ○石牌 ◥█████████◤ +  ■ ■ + ○明德 ______ ___ _________________ +  ____ |/ /___  __ \____ __/ + ○芝山 ____/ /|_/ /___/ /_/ /___/ / +  ____/ / / /___/ _, _/___/ / + ○士林 ____/_/ /_/___/_/ |_|___/_/ +  + ○劍潭 +  + ○圓山 +  + ○民權西路 搳堡龤堡龤堡龤堡龤堡龤堡龤堡 +   ○ + ○雙連 ○中  +  山 國 ● + ○中山 忠 南●國 忠 父 +  善 孝 京中 孝 紀 市 + 西  導 新 東○ 敦 念 政 + 門  寺 生 路 化 館 府 搳堡龤堡龤 + 歈龤盟◎龤堡龤堡龤盟龤堡龤堡龤堡永 後 昆 +   台北車站 忠孝復興 春 山 陽 +     埤 + 龍山寺○  ○臺大醫院 ○大安 +     +    ○科技大樓 + 江子翠○ ○◎中正紀念堂 裺 +  小南門   + 新埔● ◎古亭 ○六張犁 +  歈  + 板橋○ 頂溪○ ○台電大樓 ○麟光 +     + 府中○ 景安○ ○公館 ○辛亥 +     + 湳子○永安市場○ ○萬隆 ○萬芳醫院 +     + 海山○ 南勢角● ○景美 耤堡龤堡龤 +   萬 木 動 + 土城○ ○大坪林 芳 柵 物 +   社 園 + 永寧● ○七張 區 +  + ○新店市公所 +  + ●新店 + -- cgit v1.2.3 From 0cd6cfb110f891c13f30ab88db5498d39b0fcd8b Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sun, 16 Feb 2003 07:47:16 +0000 Subject: add posting header: Mime-Version: 1.0 Content-Type: text/plain; charset="big5" Content-Transfer-Encoding: 8bit suggested by viking@ptt git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@661 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/innbbsd/bbslink.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pttbbs/innbbsd/bbslink.c b/pttbbs/innbbsd/bbslink.c index fa5716ac..bd1cf3fe 100644 --- a/pttbbs/innbbsd/bbslink.c +++ b/pttbbs/innbbsd/bbslink.c @@ -906,6 +906,9 @@ post_article(node, site, sover, textline) fprintf(NNTPwfp, "Date: %s\r\n", sover->date); fprintf(NNTPwfp, "Organization: %s\r\n", MYSITE); fprintf(NNTPwfp, "Message-ID: <%s>\r\n", sover->msgid); + fprintf(NNTPwfp, "Mime-Version: 1.0\r\n"); + fprintf(NNTPwfp, "Content-Type: text/plain; charset=\"big5\"\r\n"); + fprintf(NNTPwfp, "Content-Transfer-Encoding: 8bit\r\n"); fprintf(NNTPwfp, "X-Filename: %s/%s\r\n", sover->board, sover->filename); } if (NNTPHOST && *NNTPHOST && USEIHAVE) -- cgit v1.2.3 From 82c72d60464468657f16e545874e41405ea1a777 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sun, 16 Feb 2003 08:58:00 +0000 Subject: exit if bcache if not loaded git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@662 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/util_cache.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pttbbs/util/util_cache.c b/pttbbs/util/util_cache.c index ee6325c3..4d69bef8 100644 --- a/pttbbs/util/util_cache.c +++ b/pttbbs/util/util_cache.c @@ -1,4 +1,4 @@ -/* $Id: util_cache.c,v 1.9 2003/02/10 17:34:39 in2 Exp $ */ +/* $Id: util_cache.c,v 1.10 2003/02/16 08:58:00 in2 Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -317,7 +317,8 @@ static void reload_bcache() { safe_sleep(1); } else{ - SHM->Buptime = SHM->Btouchtime; + puts("bcache is not loaded? resolve_boards() fail"); + exit(1); } } -- cgit v1.2.3 From 068a5c6ed8a14735536e1c782b25ed5b4c3d84f8 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Mon, 17 Feb 2003 18:33:31 +0000 Subject: add utmpsortd git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@663 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/sample/rc.local | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/pttbbs/sample/rc.local b/pttbbs/sample/rc.local index 8fd6c714..d31a009a 100644 --- a/pttbbs/sample/rc.local +++ b/pttbbs/sample/rc.local @@ -2,3 +2,16 @@ /usr/bin/su bbsadm -c /home/bbs/bin/uhash_loader /usr/bin/su bbsadm -c /home/bbs/bin/outmail& /usr/bin/su bbsadm -c /home/bbs/innd/innbbsd 7777 +/home/bbs/bin/mbbsd 23 & +/home/bbs/bin/mbbsd 3000 & +/home/bbs/bin/mbbsd 3001 & +/home/bbs/bin/mbbsd 3002 & +/home/bbs/bin/mbbsd 3003 & +/home/bbs/bin/mbbsd 3004 & +/home/bbs/bin/mbbsd 3005 & +/home/bbs/bin/mbbsd 3006 & +/home/bbs/bin/mbbsd 3007 & +/home/bbs/bin/mbbsd 3008 & +/home/bbs/bin/mbbsd 3009 & +/home/bbs/bin/mbbsd 3010 & +/usr/bin/su -fm bbsadm -c "/home/bbs/bin/shmctl utmpsortd" -- cgit v1.2.3 From efa44455dbf75ed730573e73dd26f746bb3a67df Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Mon, 17 Feb 2003 18:36:55 +0000 Subject: shmctl doesn't need resolve_boards() first git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@664 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/shmctl.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pttbbs/util/shmctl.c b/pttbbs/util/shmctl.c index f1b7765c..20850b00 100644 --- a/pttbbs/util/shmctl.c +++ b/pttbbs/util/shmctl.c @@ -1,4 +1,4 @@ -/* $Id: shmctl.c,v 1.32 2003/02/10 17:41:45 in2 Exp $ */ +/* $Id: shmctl.c,v 1.33 2003/02/17 18:36:55 in2 Exp $ */ #include "bbs.h" #include <sys/wait.h> @@ -417,7 +417,8 @@ int main(int argc, char **argv) } chdir(BBSHOME); resolve_utmp(); - resolve_boards(); + /* shmctl doesn't need resolve_boards() first */ + //resolve_boards(); resolve_garbage(); resolve_fcache(); for( i = 0 ; cmd[i].func != NULL ; ++i ) -- cgit v1.2.3 From dcace34b32f85250e047230b687d384465e5db0b Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Mon, 17 Feb 2003 18:38:01 +0000 Subject: -O3 => -O git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@665 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/innbbsd/Makefile | 2 +- pttbbs/util/Makefile | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pttbbs/innbbsd/Makefile b/pttbbs/innbbsd/Makefile index fb82be2a..95bcc415 100644 --- a/pttbbs/innbbsd/Makefile +++ b/pttbbs/innbbsd/Makefile @@ -19,7 +19,7 @@ TARGET = $(INNBBSD) $(BBSNNRP) $(BBSLINK) CC=gcc INSTALL=cp # -OPT= -O3 -s -pipe -fomit-frame-pointer -g +OPT= -O -s -pipe -fomit-frame-pointer -g BBS_DEP = MapleBBS BBS_UTIL = $(BBS_SRC)/util diff --git a/pttbbs/util/Makefile b/pttbbs/util/Makefile index 06a4e471..e291cdee 100644 --- a/pttbbs/util/Makefile +++ b/pttbbs/util/Makefile @@ -1,18 +1,18 @@ -# $Id: Makefile,v 1.23 2003/02/11 06:03:31 victor Exp $ +# $Id: Makefile,v 1.24 2003/02/17 18:37:48 in2 Exp $ BBSHOME?=$(HOME) OSTYPE!=uname # FreeBSD CC_FreeBSD= gcc -CFLAGS_FreeBSD= -DFreeBSD -pipe -Wall -g -O3 -DHAVE_SETPROCTITLE -DBBSHOME='"$(BBSHOME)"' -I../include +CFLAGS_FreeBSD= -DFreeBSD -pipe -Wall -g -O -DHAVE_SETPROCTITLE -DBBSHOME='"$(BBSHOME)"' -I../include LIBS_FreeBSD= LIBMAIL_FreeBSD=-lutil LIBCHAT_FreeBSD= # Linux CC_linux= gcc -CFLAGS_linux= -DLinux -pipe -Wall -g -O3 -DHAVE_DES_CRYPT -DBBSHOME='"$(BBSHOME)"' -I../include +CFLAGS_linux= -DLinux -pipe -Wall -g -O -DHAVE_DES_CRYPT -DBBSHOME='"$(BBSHOME)"' -I../include LIBS_linux= -lresolv LIBMAIL_linux= LIBCHAT_linux= -lcrypt -- cgit v1.2.3 From 664ec975991a10baab3e5b9087a5401eac944b7d Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Wed, 19 Feb 2003 15:26:15 +0000 Subject: add charset, encoding, and ctype by rafan git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@666 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/tarqueue.pl | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/pttbbs/util/tarqueue.pl b/pttbbs/util/tarqueue.pl index f3463f30..d99221a8 100644 --- a/pttbbs/util/tarqueue.pl +++ b/pttbbs/util/tarqueue.pl @@ -67,9 +67,12 @@ sub MakeMail `$TAR zcf $arg->{tartarget} $arg->{tarsource}`; $sender = new Mail::Sender{smtp => $SMTPSERVER, from => 'pttadmin <in2@ptt2.csie.ntu.edu.tw>'}; - $sender->MailFile({to => $arg->{mailto}, - subject => $arg->{subject}, - msg => $arg->{body}, - file => $arg->{tartarget}}); + $sender->MailFile({to => $arg->{mailto}, + subject => $arg->{subject}, + msg => $arg->{body}, + file => $arg->{tartarget}, + b_charset => 'big5', + b_encoding => '8bit', + ctype => 'application/x-tar-gz'}); unlink $arg->{tartarget}; } -- cgit v1.2.3 From 4663c16faedd0fc422e0bb8c89eb073d3fb81c77 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Thu, 20 Feb 2003 00:53:23 +0000 Subject: =?UTF-8?q?s/=EF=BF=BD=EF=BF=BD/=EF=BF=BDO/=20by=20rafan?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@667 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/tarqueue.pl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pttbbs/util/tarqueue.pl b/pttbbs/util/tarqueue.pl index d99221a8..0edf5bc0 100644 --- a/pttbbs/util/tarqueue.pl +++ b/pttbbs/util/tarqueue.pl @@ -36,8 +36,8 @@ sub ProcessBoard MakeMail({tartarget => "$TMP/$board.tgz", tarsource => "boards/". substr($board, 0, 1). "/$board", - mailto => "$board的版主$owner <$email>", - subject => "$board的看版備份", + mailto => "$board的板主$owner <$email>", + subject => "$board的看板備份", body => "\n\n\t $owner 您好,收到這封信,表示您已經收到看板備份。\n\n". "\t謝謝您的耐心等待,以及使用 $hostname的看板備份系統,\n\n". @@ -48,7 +48,7 @@ sub ProcessBoard MakeMail({tartarget => "$TMP/man.$board.tgz", tarsource => "man/boards/". substr($board, 0, 1). "/$board", - mailto => "$board的版主$owner <$email>", + mailto => "$board的板主$owner <$email>", subject => "$board的精華區備份", body => "\n\n\t $owner 您好,收到這封信,表示您已經收到精華區備份。\n\n". -- cgit v1.2.3 From 877afb48f0c476dd0515e8e7d1857e8787e12158 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Thu, 20 Feb 2003 11:06:03 +0000 Subject: one could not enter into group board git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@668 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/board.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pttbbs/mbbsd/board.c b/pttbbs/mbbsd/board.c index 52fef094..32d0c628 100644 --- a/pttbbs/mbbsd/board.c +++ b/pttbbs/mbbsd/board.c @@ -1,4 +1,4 @@ -/* $Id: board.c,v 1.80 2003/01/19 01:44:49 in2 Exp $ */ +/* $Id: board.c,v 1.81 2003/02/20 11:06:03 in2 Exp $ */ #include "bbs.h" #define BRC_STRLEN 15 /* Length of board name */ #define BRC_MAXSIZE 24576 @@ -414,6 +414,9 @@ Ben_Perm(boardheader_t * bptr) level = bptr->level; brdattr = bptr->brdattr; + if (brdattr & BRD_GROUPBOARD) + return 0; + if (HAS_PERM(PERM_SYSOP)) return 1; -- cgit v1.2.3 From 418fe0cb9e9901c46407dcf18d2bc168e1c26f2e Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Thu, 20 Feb 2003 16:12:13 +0000 Subject: fix last commit bug git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@669 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/board.c | 5 +---- pttbbs/mbbsd/name.c | 5 +++-- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/pttbbs/mbbsd/board.c b/pttbbs/mbbsd/board.c index 32d0c628..28b1bc71 100644 --- a/pttbbs/mbbsd/board.c +++ b/pttbbs/mbbsd/board.c @@ -1,4 +1,4 @@ -/* $Id: board.c,v 1.81 2003/02/20 11:06:03 in2 Exp $ */ +/* $Id: board.c,v 1.82 2003/02/20 16:12:12 in2 Exp $ */ #include "bbs.h" #define BRC_STRLEN 15 /* Length of board name */ #define BRC_MAXSIZE 24576 @@ -414,9 +414,6 @@ Ben_Perm(boardheader_t * bptr) level = bptr->level; brdattr = bptr->brdattr; - if (brdattr & BRD_GROUPBOARD) - return 0; - if (HAS_PERM(PERM_SYSOP)) return 1; diff --git a/pttbbs/mbbsd/name.c b/pttbbs/mbbsd/name.c index ef1a4c5f..b16f19ef 100644 --- a/pttbbs/mbbsd/name.c +++ b/pttbbs/mbbsd/name.c @@ -1,4 +1,4 @@ -/* $Id: name.c,v 1.15 2003/01/17 08:49:34 kcwu Exp $ */ +/* $Id: name.c,v 1.16 2003/02/20 16:12:13 in2 Exp $ */ #include "bbs.h" static word_t *current = NULL; @@ -674,7 +674,8 @@ completeboard_compar(int where, char *str, int len) int completeboard_permission(int where) { - return Ben_Perm(SHM->bsorted[0][where]); + return (Ben_Perm(SHM->bsorted[0][where]) && + !(SHM->bsorted[0][where]->brdattr & BRD_GROUPBOARD)); } char * -- cgit v1.2.3 From a881060b28f509ea08065a3f2d6280c746a537ec Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Thu, 20 Feb 2003 16:18:24 +0000 Subject: warning free git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@670 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/read.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pttbbs/mbbsd/read.c b/pttbbs/mbbsd/read.c index e527cac7..68c253c2 100644 --- a/pttbbs/mbbsd/read.c +++ b/pttbbs/mbbsd/read.c @@ -1,4 +1,4 @@ -/* $Id: read.c,v 1.19 2003/02/11 15:30:15 victor Exp $ */ +/* $Id: read.c,v 1.20 2003/02/20 16:18:24 in2 Exp $ */ #include "bbs.h" static fileheader_t *headers = NULL; @@ -447,7 +447,7 @@ mail_forward(fileheader_t * fhdr, char *direct, int mode) static int select_read(keeploc_t * locmem, int sr_mode) { - register char *tag, *query, *temp; + char *tag, *query = NULL, *temp; fileheader_t fh; char fpath[80], genbuf[MAXPATHLEN], buf3[5]; static char t_ans[TTLEN + 1] = ""; -- cgit v1.2.3 From aff8a4df62072cbc50906b17a98cb8f06d40cb1d Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Thu, 20 Feb 2003 16:52:56 +0000 Subject: register git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@671 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/user.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/pttbbs/mbbsd/user.c b/pttbbs/mbbsd/user.c index c236279a..2319220e 100644 --- a/pttbbs/mbbsd/user.c +++ b/pttbbs/mbbsd/user.c @@ -1,4 +1,4 @@ -/* $Id: user.c,v 1.45 2003/01/19 16:06:06 kcwu Exp $ */ +/* $Id: user.c,v 1.46 2003/02/20 16:52:56 in2 Exp $ */ #include "bbs.h" static char *sex[8] = { @@ -941,9 +941,12 @@ static char *isvaildname(char *rname) { if( removespace(rname) && rname[0] < 0 && strlen(rname) >= 4 && - !strstr(rname, "阿") && !strstr(rname, "小") && + !strstr(rname, "阿") && !strstr(rname, "某") && !strstr(rname, "ㄚ") && strstr(rname, "..") == NULL && !strstr(rname, "美女") && !strstr(rname, "帥哥") && + !strstr(rname, "先生") && !strstr(rname, "小姐") && + !strstr(rname, "老頭") && !strstr(rname, "豬頭") && + strncmp(rname, "小", 2) != 0 && !(strlen(rname) == 4 && strncmp(&rname[2], "兒", 2) == 0) && !(strlen(rname) >= 4 && strncmp(&rname[0], &rname[2], 2) == 0)) return NULL; -- cgit v1.2.3 From 78f7e8a97ee24e92ee3772143394f0660224ee30 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sat, 22 Feb 2003 09:12:42 +0000 Subject: register git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@672 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/user.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pttbbs/mbbsd/user.c b/pttbbs/mbbsd/user.c index 2319220e..f290e449 100644 --- a/pttbbs/mbbsd/user.c +++ b/pttbbs/mbbsd/user.c @@ -1,4 +1,4 @@ -/* $Id: user.c,v 1.46 2003/02/20 16:52:56 in2 Exp $ */ +/* $Id: user.c,v 1.47 2003/02/22 09:12:42 in2 Exp $ */ #include "bbs.h" static char *sex[8] = { @@ -765,7 +765,8 @@ ispersonalid(char *inid) id[0] = toupper(id[0]); if( strcmp(id, "A100000001") == 0 || - strcmp(id, "A200000003") == 0 ) + strcmp(id, "A200000003") == 0 || + strcmp(id, "A123456789") == 0 ) return 0; /* A->10, B->11, ..H->17,I->34, J->18... */ while (lst[i] != id[0]) -- cgit v1.2.3 From 1b066dcacdffe55fbcbe942556927f75ccbd128c Mon Sep 17 00:00:00 2001 From: victor <victor@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sun, 23 Feb 2003 16:39:27 +0000 Subject: remove unreasonable checking git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@673 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/chat.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/pttbbs/mbbsd/chat.c b/pttbbs/mbbsd/chat.c index 66954248..6346335a 100644 --- a/pttbbs/mbbsd/chat.c +++ b/pttbbs/mbbsd/chat.c @@ -1,4 +1,4 @@ -/* $Id: chat.c,v 1.10 2002/12/31 17:40:51 in2 Exp $ */ +/* $Id: chat.c,v 1.11 2003/02/23 16:39:27 victor Exp $ */ #include "bbs.h" static int chatline, stop_line; @@ -349,9 +349,6 @@ t_chat() char genbuf[200]; char roomtype; - if (inbuf[0] == 0) - return -1; - outs(" 驅車前往 請梢候........ "); if (!(h = gethostbyname("localhost"))) { perror("gethostbyname"); -- cgit v1.2.3 From 18d2507f60d78198de12b971daf56d6bb145d564 Mon Sep 17 00:00:00 2001 From: victor <victor@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Mon, 24 Feb 2003 11:42:04 +0000 Subject: make users be able to see their own sex and money git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@674 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/talk.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pttbbs/mbbsd/talk.c b/pttbbs/mbbsd/talk.c index 60f2aa85..4f1688fc 100644 --- a/pttbbs/mbbsd/talk.c +++ b/pttbbs/mbbsd/talk.c @@ -1,4 +1,4 @@ -/* $Id: talk.c,v 1.100 2003/01/19 16:18:17 kcwu Exp $ */ +/* $Id: talk.c,v 1.101 2003/02/24 11:42:04 victor Exp $ */ #include "bbs.h" #define QCAST int (*)(const void *, const void *) @@ -388,7 +388,7 @@ my_query(char *uident) prints("《上次上站》%-28.28s《上次故鄉》%s\n", Cdate(&muser.lastlogin), (muser.lasthost[0] ? muser.lasthost : "(不詳)")); - if ((uentp && fri_stat & HFM && !uentp->invisible)) + if ((uentp && ((fri_stat & HFM) || strcmp(muser.userid,cuser.userid) == 0) && !uentp->invisible)) prints("《 性 別 》%-28.28s《私有財產》%d 銀兩\n", sex[muser.sex % 8], muser.money); -- cgit v1.2.3 From 048bd9c24e8ac142ba9563ad58cc526ad65f7d50 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Tue, 25 Feb 2003 11:54:22 +0000 Subject: charset=Big5 git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@675 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/innbbsd/bbslink.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pttbbs/innbbsd/bbslink.c b/pttbbs/innbbsd/bbslink.c index bd1cf3fe..300f3f7d 100644 --- a/pttbbs/innbbsd/bbslink.c +++ b/pttbbs/innbbsd/bbslink.c @@ -907,7 +907,7 @@ post_article(node, site, sover, textline) fprintf(NNTPwfp, "Organization: %s\r\n", MYSITE); fprintf(NNTPwfp, "Message-ID: <%s>\r\n", sover->msgid); fprintf(NNTPwfp, "Mime-Version: 1.0\r\n"); - fprintf(NNTPwfp, "Content-Type: text/plain; charset=\"big5\"\r\n"); + fprintf(NNTPwfp, "Content-Type: text/plain; charset=Big5\r\n"); fprintf(NNTPwfp, "Content-Transfer-Encoding: 8bit\r\n"); fprintf(NNTPwfp, "X-Filename: %s/%s\r\n", sover->board, sover->filename); } -- cgit v1.2.3 From 7b25c8824e09aa526a9935022c621f4851e8aa2f Mon Sep 17 00:00:00 2001 From: victor <victor@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Wed, 26 Feb 2003 14:58:33 +0000 Subject: you can add 'group' into myfavorite now git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@676 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/board.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/pttbbs/mbbsd/board.c b/pttbbs/mbbsd/board.c index 28b1bc71..a7c8b289 100644 --- a/pttbbs/mbbsd/board.c +++ b/pttbbs/mbbsd/board.c @@ -1,4 +1,4 @@ -/* $Id: board.c,v 1.82 2003/02/20 16:12:12 in2 Exp $ */ +/* $Id: board.c,v 1.83 2003/02/26 14:58:33 victor Exp $ */ #include "bbs.h" #define BRC_STRLEN 15 /* Length of board name */ #define BRC_MAXSIZE 24576 @@ -572,7 +572,7 @@ load_boards(char *key) if ((bptr = SHM->bsorted[type][i]) == NULL) continue; n = (int)(bptr - bcache); - if (!bptr->brdname[0] || bptr->brdattr & BRD_GROUPBOARD || + if (!bptr->brdname[0] || (yank_flag != 0 && bptr->brdattr & BRD_GROUPBOARD) || !((state = Ben_Perm(bptr)) || (currmode & MODE_MENU)) || (yank_flag == 0 && !(favbuf[n] & BRD_FAV)) || (yank_flag == 1 && !zapbuf[n]) || @@ -848,11 +848,13 @@ choose_board(int newflag) brdnum = -1; continue; } + /* Victor: it seams unused ? if (yank_flag < 2) { brdnum = -1; yank_flag++; continue; } + */ if (HAS_PERM(PERM_SYSOP) || (currmode & MODE_MENU)) { if (m_newbrd(0) == -1) break; @@ -1187,7 +1189,13 @@ choose_board(int newflag) setutmpbid(ptr->bid); free(nbrd); nbrd = NULL; - choose_board(0); + if (yank_flag == 0 ) { + yank_flag = 1; + choose_board(0); + yank_flag = 0; + } + else + choose_board(0); currmode = currmodetmp; /* 離開板板後就把權限拿掉喔 */ num = tmp1; class_bid = bidtmp; -- cgit v1.2.3 From fe15113c18cd5757c6490db2becd37fcb4c8f040 Mon Sep 17 00:00:00 2001 From: victor <victor@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Wed, 26 Feb 2003 15:44:21 +0000 Subject: recover something back :p git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@677 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/board.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/pttbbs/mbbsd/board.c b/pttbbs/mbbsd/board.c index a7c8b289..8d91f3fe 100644 --- a/pttbbs/mbbsd/board.c +++ b/pttbbs/mbbsd/board.c @@ -1,4 +1,4 @@ -/* $Id: board.c,v 1.83 2003/02/26 14:58:33 victor Exp $ */ +/* $Id: board.c,v 1.84 2003/02/26 15:44:21 victor Exp $ */ #include "bbs.h" #define BRC_STRLEN 15 /* Length of board name */ #define BRC_MAXSIZE 24576 @@ -848,13 +848,11 @@ choose_board(int newflag) brdnum = -1; continue; } - /* Victor: it seams unused ? if (yank_flag < 2) { brdnum = -1; yank_flag++; continue; } - */ if (HAS_PERM(PERM_SYSOP) || (currmode & MODE_MENU)) { if (m_newbrd(0) == -1) break; -- cgit v1.2.3 From 74129f0f1d53e8ddc9c71783cb0745581f5a5fa4 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Thu, 27 Feb 2003 05:50:41 +0000 Subject: SHM should be created by uhash_loader, NOT by mbbsd git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@678 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/cache.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/pttbbs/mbbsd/cache.c b/pttbbs/mbbsd/cache.c index 023ac8a7..992b6721 100644 --- a/pttbbs/mbbsd/cache.c +++ b/pttbbs/mbbsd/cache.c @@ -1,4 +1,4 @@ -/* $Id: cache.c,v 1.58 2003/02/10 17:41:45 in2 Exp $ */ +/* $Id: cache.c,v 1.59 2003/02/27 05:50:41 in2 Exp $ */ #include "bbs.h" #ifndef __FreeBSD__ @@ -70,12 +70,8 @@ attach_shm(int shmkey, int shmsize) shmid = shmget(shmkey, shmsize, 0); if (shmid < 0) { - shmid = shmget(shmkey, shmsize, IPC_CREAT | 0600); - if (shmid < 0) - attach_err(shmkey, "shmget"); - shmptr = (void *)shmat(shmid, NULL, 0); - if (shmptr == (void *)-1) - attach_err(shmkey, "shmat"); + // SHM should be created by uhash_loader, NOT mbbsd. + attach_err(shmkey, "shmget"); } else { shmptr = (void *)shmat(shmid, NULL, 0); if (shmptr == (void *)-1) -- cgit v1.2.3 From 610ff0b10e08dc5e9321e819f338acc0bd805c14 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Thu, 27 Feb 2003 05:52:51 +0000 Subject: warning free git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@679 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/cache.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pttbbs/mbbsd/cache.c b/pttbbs/mbbsd/cache.c index 992b6721..3a011825 100644 --- a/pttbbs/mbbsd/cache.c +++ b/pttbbs/mbbsd/cache.c @@ -1,4 +1,4 @@ -/* $Id: cache.c,v 1.59 2003/02/27 05:50:41 in2 Exp $ */ +/* $Id: cache.c,v 1.60 2003/02/27 05:52:51 in2 Exp $ */ #include "bbs.h" #ifndef __FreeBSD__ @@ -65,7 +65,7 @@ attach_err(int shmkey, char *name) void * attach_shm(int shmkey, int shmsize) { - void *shmptr; + void *shmptr = (void *)NULL; int shmid; shmid = shmget(shmkey, shmsize, 0); -- cgit v1.2.3 From 63a3064bdaf6547a3257c62c542b7657fc3992d9 Mon Sep 17 00:00:00 2001 From: victor <victor@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Thu, 27 Feb 2003 10:48:41 +0000 Subject: check lock when get_record git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@680 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/record.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pttbbs/mbbsd/record.c b/pttbbs/mbbsd/record.c index cc82cde8..61f58dbc 100644 --- a/pttbbs/mbbsd/record.c +++ b/pttbbs/mbbsd/record.c @@ -1,4 +1,4 @@ -/* $Id: record.c,v 1.12 2002/12/31 17:40:51 in2 Exp $ */ +/* $Id: record.c,v 1.13 2003/02/27 10:48:41 victor Exp $ */ #include "bbs.h" #undef HAVE_MMAP @@ -78,6 +78,11 @@ get_records(char *fpath, void *rptr, int size, int id, int number) if (id < 1 || (fd = open(fpath, O_RDONLY, 0)) == -1) return -1; + if( flock(fd, LOCK_EX) < 0 ){ + close(fd); + return -1; + } + if (lseek(fd, (off_t) (size * (id - 1)), SEEK_SET) == -1) { close(fd); return 0; -- cgit v1.2.3 From e9e094563c64aea95858955835e417d0d6083b0a Mon Sep 17 00:00:00 2001 From: bbs <bbs@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sat, 1 Mar 2003 06:12:20 +0000 Subject: use another source instead git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@681 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/weather.perl | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/pttbbs/util/weather.perl b/pttbbs/util/weather.perl index 911ff804..5e2c8d4f 100644 --- a/pttbbs/util/weather.perl +++ b/pttbbs/util/weather.perl @@ -1,5 +1,5 @@ #!/usr/bin/perl -# $Id: weather.perl,v 1.4 2003/02/07 15:09:14 victor Exp $ +# $Id: weather.perl,v 1.5 2003/03/01 06:12:20 bbs Exp $ # # 不能跑的話,看看 bbspost 的路徑是否正確。 # 如果發出的 post 沒有氣象報告而是說 URL 找不到,則確定一下能不能看到 @@ -19,9 +19,15 @@ close DATE; # Header # 內容 -open(WEATHER, "$LYNX -assume_charset=big5 -assume_local_charset=big5 -dump http://www.cwb.gov.tw/V3.0/weather/text/W03.htm |"); +#open(WEATHER, "$LYNX -assume_charset=big5 -assume_local_charset=big5 -dump http://www.cwb.gov.tw/V3.0/weather/text/W03.htm |"); +open(WEATHER, "$LYNX -assume_charset=big5 -assume_local_charset=big5 -dump -nolist http://www.libertytimes.com.tw/2003/new/mar/today/Wnews1.htm|"); while (<WEATHER>) { + last if /今日天氣/; +} + +while (<WEATHER>) { + last if /top\.gif/; print BBSPOST if ($_ ne "\n"); } close WEATHER; -- cgit v1.2.3 From 04984dc8e37a29a788a7cf867c6ff88e65e03322 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sun, 2 Mar 2003 08:51:28 +0000 Subject: comment for RELAY_SERVER_IP git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@682 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/sample/pttbbs.conf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pttbbs/sample/pttbbs.conf b/pttbbs/sample/pttbbs.conf index 9a2f1433..84a9938c 100644 --- a/pttbbs/sample/pttbbs.conf +++ b/pttbbs/sample/pttbbs.conf @@ -29,8 +29,8 @@ /* 最大開板個數, 每個會用掉 6420 bytes 的 shared-memory */ #define MAX_BOARD (8192) -/* 寄信的 relay server */ -#define RELAY_SERVER_IP "140.112.30.144" // to pttx +/* 幫忙寄信的 server, 一般設成自己(即ip: 127.0.0.1)就可以 */ +#define RELAY_SERVER_IP "127.0.0.1" /* 抬頭色彩 */ #define TITLE_COLOR "\33[0;1;37;46m" -- cgit v1.2.3 From 17e632916ad1295e46dc9d2fa208334c4a96735b Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Mon, 3 Mar 2003 15:32:15 +0000 Subject: fix input length of voting git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@683 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/vote.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/pttbbs/mbbsd/vote.c b/pttbbs/mbbsd/vote.c index 618da18a..a71040c9 100644 --- a/pttbbs/mbbsd/vote.c +++ b/pttbbs/mbbsd/vote.c @@ -1,4 +1,4 @@ -/* $Id: vote.c,v 1.18 2003/01/19 16:06:06 kcwu Exp $ */ +/* $Id: vote.c,v 1.19 2003/03/03 15:32:15 in2 Exp $ */ #include "bbs.h" static int total; @@ -704,9 +704,17 @@ vote_maintain(char *bname) outs("\n請依序輸入選項, 按 ENTER 完成設定"); num = 0; while (!aborted) { + if( num % 15 == 0 ){ + for( i = num ; i < num + 15 ; ++i ){ + snprintf(buf, sizeof(buf), "\033[1;30m%c)\033[m ", i + 'A'); + move((i % 15) + 2, (i / 15) * 40); + prints(buf); + } + refresh(); + } snprintf(buf, sizeof(buf), "%c) ", num + 'A'); getdata((num % 15) + 2, (num / 15) * 40, buf, - inbuf, 50, DOECHO); + inbuf, 37, DOECHO); if (*inbuf) { fprintf(fp, "%1c) %s\n", (num + 'A'), inbuf); num++; -- cgit v1.2.3 From 561b92be52241d0d2264ff29fd11c5b47c01dfcb Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Tue, 4 Mar 2003 09:39:34 +0000 Subject: document git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@684 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/docs/INSTALL | 20 ++++++++++++-------- pttbbs/sample/pttbbs.sh | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 8 deletions(-) create mode 100755 pttbbs/sample/pttbbs.sh diff --git a/pttbbs/docs/INSTALL b/pttbbs/docs/INSTALL index a8cd6dcc..6b7d8c81 100644 --- a/pttbbs/docs/INSTALL +++ b/pttbbs/docs/INSTALL @@ -33,26 +33,30 @@ 8. 執行 cd pttbbs 9. 如果之前沒有設定過 pttbbs.conf 的話, 請 cp sample/pttbbs.conf pttbbs.conf -10. 修改 pttbbs.conf +10.修改 pttbbs.conf * 如果您是用 Linux系統, 請先安裝 pmake, 然後將 make alias 成 pmake * -11. 執行 make OSTYPE=FreeBSD BBSHOME=/home/bbs all install +11.執行 make OSTYPE=FreeBSD BBSHOME=/home/bbs all install (Linux使用者請把 "FreeBSD" 改成 "linux") -12. 如果是新架起來的站, 請執行 cd sample; make install -12. 執行 cd /home/bbs; bin/initbbs +12.如果是新架起來的站, 請執行 cd sample; make install +13.執行 cd /home/bbs; bin/initbbs 假如一切都很順利的話,這樣子大概就安裝完了 接下來是啟動 bbs 的部份 -13. 執行 bin/uhash_loader (*註1, *註2) -14. 執行 bin/shmctl utmpsortd -15. 用 root 執行 bin/mbbsd 23 (註2) +14.執行 bin/uhash_loader (*註1, *註2) +15.執行 bin/shmctl utmpsortd +16.用 root 執行 bin/mbbsd 23 (註2) -16. 新功能請參考 ADVANCE +17.新功能請參考 ADVANCE telnet localhost 23 看看 new一個帳號叫SYSOP,然後logout再login, 這樣子就會擁有站長權限囉~ 再new一個帳號叫 guest, 這樣子別人就可以用 guest 參觀你的站了 開板,開群組,以及搬動群組的方法請看 PttSrc 板的文摘 +18.為了讓開機的時候會自己把 bbs (以及所須要的程式) 跑起來, + 若您使用 FreeBSD, 您可以將 sample/pttbbs.sh 拷貝到 /usr/local/etc/rc.d/ + 之後您可以重新開機試試看是不是在重開後可以正常運作 :) + 註: 1. 這個程式是在 initial shared memory 用的, 只有開機後第一次執行, 或是 你手動清除 shm 後才需要執行 diff --git a/pttbbs/sample/pttbbs.sh b/pttbbs/sample/pttbbs.sh new file mode 100755 index 00000000..056aacb8 --- /dev/null +++ b/pttbbs/sample/pttbbs.sh @@ -0,0 +1,37 @@ +#!/bin/sh +# 請注意! 這個檔案將以 root 的權限執行. +# 預設使用 bbs這個帳號, 安裝目錄為 /home/bbs + +case "$1" in +start) + # 初始化 shared-memory, 載入使用者帳號 + /usr/bin/su -fm bbs -c /home/bbs/bin/uhash_loader + + # 寄信至站外 + /usr/bin/su -fm bbs -c /home/bbs/bin/outmail & + + # 轉信 + /usr/bin/su -fm bbs -c /home/bbs/innd/innbbsd & + + # 啟動 port 23 (port 23須使用 root 才能進行 bind ) + /home/bbs/bin/mbbsd 23 & + + # 啟動 utmpsortd + /bin/sleep 5; /usr/bin/su -fm bbs -c /home/bbs/bin/shmctl utmpsortd & + + # 提示 + echo -n ' mbbsd' + ;; +stop) + /usr/bin/killall outmail + /usr/bin/killall innbbsd + /usr/bin/killall mbbsd + /usr/bin/killall shmctl + /bin/sleep 2; /usr/bin/killall shmctl + ;; +*) + echo "Usage: `basename $0` {start|stop}" >&2 + ;; +esac + +exit 0 -- cgit v1.2.3 From 5b7d278d6d808e0bbb1721661b8b48c8c62c15bd Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Tue, 4 Mar 2003 09:53:28 +0000 Subject: document git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@685 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/docs/FAQ | 39 ++++++++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/pttbbs/docs/FAQ b/pttbbs/docs/FAQ index fb0ddb9f..ce55511e 100644 --- a/pttbbs/docs/FAQ +++ b/pttbbs/docs/FAQ @@ -1,11 +1,25 @@ +PttBBS FAQ: + + 1. PttBBS的討論區 + 2. 在 Linux底下出現 Makefile 錯誤. + 3. 加大 shared-memory + 4. 設定 group + 5. 五子棋盤沒有出現 + 6. sendmail.cf要改的地方(參考用) (by DavidYu) +------------------------------------------------------------------------------ +1.PttBBS的討論區 +位於批踢踢實業坊 (telnet://ptt.csie.ntu.edu.tw) 的 PttCurrent 看板. + +------------------------------------------------------------------------------ +2.在 Linux底下出現 Makefile 錯誤. + 使用 Linux, 在 compile的時候出如 Makefile:20: *** missing separator. Stop. 請安裝 pmake, 並將 make alias 成 pmake . 如: apt-get install pmake alias make pmake -─────────────────────────────────────── - -加大 shared-memory: +------------------------------------------------------------------------------ +3.加大 shared-memory in FreeBSD: 請在 /etc/sysctl.conf 裡面加入 kern.ipc.shmmax=104857600 @@ -19,8 +33,8 @@ in Linux: #define SHMMAX 將其加大 重新 make kernel並且 reboot -─────────────────────────────────────── -設定 group +------------------------------------------------------------------------------ +4.設定 group 以 FreeBSD為例, 您須要更動 /etc/group 這個檔案, /etc/group 的語法是: group:passwd:gid:member @@ -34,17 +48,15 @@ in Linux: bbsadm:*:9876:aaa,bbb 在設定完成後, 原來已經登入的使用者須要重新登入, 才會重新載入至新設的 group內. +您可以參考 group(5) -─────────────────────────────────────── -五子棋盤沒有出現 +------------------------------------------------------------------------------ +5.五子棋盤沒有出現 請將 sample/etc/@five 拷貝到 ~bbs/etc/ 即可. - 作者 DavidYu (軱~~~~~~~~~~) 看板 PttSrc - 標題 sendmail.cf要改的地方(參考用) - 時間 Sun Jul 9 09:39:53 2000 -─────────────────────────────────────── +------------------------------------------------------------------------------ +6. sendmail.cf要改的地方(參考用) (by DavidYu) -有顏色的是要加上去的 要注意,tab和space不能混用 ###################################### @@ -89,6 +101,3 @@ Mbbsmail, P=/home/bbs/bin/bbsmail, F=lsSDFMhPu, U=bbs, S=10,R=20/40, ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ A=bbsmail $u ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ --- -※ 發信站: 批踢踢實業坊(ptt.twbbs.org) -◆ From: oio.m6.ntu.edu.t -- cgit v1.2.3 From 43cae09c309ae2787f9f495733204c4e6be3b3a4 Mon Sep 17 00:00:00 2001 From: kcwu <kcwu@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Tue, 4 Mar 2003 12:25:42 +0000 Subject: Fix date display bug due to bad y2k patch Thank wushangju.bbs@ptt2 git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@686 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/xyz.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pttbbs/mbbsd/xyz.c b/pttbbs/mbbsd/xyz.c index 55f9e475..40578519 100644 --- a/pttbbs/mbbsd/xyz.c +++ b/pttbbs/mbbsd/xyz.c @@ -1,4 +1,4 @@ -/* $Id: xyz.c,v 1.17 2003/02/12 14:31:34 victor Exp $ */ +/* $Id: xyz.c,v 1.18 2003/03/04 12:25:42 kcwu Exp $ */ #include "bbs.h" /* 各種統計及相關資訊列表 */ @@ -246,9 +246,9 @@ note() myitem.userid, myitem.username); len = strlen(buf); - for (i = len; i < 73; i++) + for (i = len; i < 71; i++) strcat(buf, " "); - snprintf(buf2, sizeof(buf2), " \033[1;36m%.14s\033[31m ├╮\033[m\n", + snprintf(buf2, sizeof(buf2), " \033[1;36m%.16s\033[31m ├╮\033[m\n", Cdate(&(myitem.date))); strcat(buf, buf2); fputs(buf, fp); -- cgit v1.2.3 From 1060d638cf97c19bf47c7fd3e290b3a57c1ed944 Mon Sep 17 00:00:00 2001 From: victor <victor@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Wed, 5 Mar 2003 10:42:03 +0000 Subject: fix 'stone article' git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@687 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/bbs.c | 23 ++++++----------------- 1 file changed, 6 insertions(+), 17 deletions(-) diff --git a/pttbbs/mbbsd/bbs.c b/pttbbs/mbbsd/bbs.c index 0587a5ee..2d498b59 100644 --- a/pttbbs/mbbsd/bbs.c +++ b/pttbbs/mbbsd/bbs.c @@ -1,4 +1,4 @@ -/* $Id: bbs.c,v 1.79 2003/02/12 05:22:31 victor Exp $ */ +/* $Id: bbs.c,v 1.80 2003/03/05 10:42:03 victor Exp $ */ #include "bbs.h" static void @@ -699,9 +699,7 @@ reply_post(int ent, fileheader_t * fhdr, char *direct) static int edit_post(int ent, fileheader_t * fhdr, char *direct) { - char fpath[80], fpath0[80]; char genbuf[200]; - fileheader_t postfile; boardheader_t *bp; bp = getbcache(currbid); if (strcmp(bp->brdname, "Security") == 0) @@ -720,37 +718,28 @@ edit_post(int ent, fileheader_t * fhdr, char *direct) setutmpmode(REEDIT); setdirpath(genbuf, direct, fhdr->filename); local_article = fhdr->filemode & FILE_LOCAL; - strlcpy(save_title, fhdr->title, sizeof(save_title)); /* rocker.011018: 這裡是不是該檢查一下修改文章後的money和原有的比較? */ if (vedit(genbuf, 0, NULL) != -1) { lock_substitute_record(direct, fhdr, sizeof(*fhdr), ent, LOCK_EX); - setbpath(fpath, currboard); - stampfile(fpath, &postfile); - unlink(fpath); - setbfile(fpath0, currboard, fhdr->filename); - - Rename(fpath0, fpath); /* rocker.011018: fix 串接模式改文章後文章就不見的bug */ if ((currmode & MODE_SELECT) && (fhdr->money & FHR_REFERENCE)) { fileheader_t hdr; + char fpath[80]; int num; num = fhdr->money & ~FHR_REFERENCE; - setbdir(fpath0, currboard); - get_record(fpath0, &hdr, sizeof(hdr), num); + setbdir(fpath, currboard); + get_record(fpath, &hdr, sizeof(hdr), num); /* 再這裡要check一下原來的dir裡面是不是有被人動過... */ if (!strcmp(hdr.filename, fhdr->filename)) { - strlcpy(hdr.filename, postfile.filename, sizeof(hdr.filename)); + strlcpy(hdr.filename, fhdr->filename, sizeof(hdr.filename)); strlcpy(hdr.title, save_title, sizeof(hdr.title)); - substitute_record(fpath0, &hdr, sizeof(hdr), num); + substitute_record(fpath, &hdr, sizeof(hdr), num); } } - strlcpy(fhdr->filename, postfile.filename, sizeof(fhdr->filename)); - strlcpy(fhdr->title, save_title, sizeof(fhdr->title)); - brc_addlist(postfile.filename); lock_substitute_record(direct, fhdr, sizeof(*fhdr), ent, LOCK_UN); /* rocker.011018: 順便更新一下cache */ touchdircache(currbid); -- cgit v1.2.3 From 997c24947ff3d27f1d06c6449cdc77c425976ed6 Mon Sep 17 00:00:00 2001 From: victor <victor@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Wed, 5 Mar 2003 10:44:43 +0000 Subject: force mv git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@688 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pttbbs/mbbsd/Makefile b/pttbbs/mbbsd/Makefile index 9204ead9..557ca7a2 100644 --- a/pttbbs/mbbsd/Makefile +++ b/pttbbs/mbbsd/Makefile @@ -1,4 +1,4 @@ -# $Id: Makefile,v 1.18 2003/02/10 17:41:45 in2 Exp $ +# $Id: Makefile,v 1.19 2003/03/05 10:44:43 victor Exp $ # 訂義基本初值 BBSHOME?= $(HOME) @@ -80,7 +80,7 @@ test: $(PROG) install: $(PROG) install -d $(BBSHOME)/bin/ install -c -m 755 $(PROG) $(BBSHOME)/bin/ - mv $(BBSHOME)/bin/mbbsd $(BBSHOME)/bin/mbbsd.`date '+%m%d%H'` + mv -f $(BBSHOME)/bin/mbbsd $(BBSHOME)/bin/mbbsd.`date '+%m%d%H'` ln -sv $(BBSHOME)/bin/mbbsd.`date '+%m%d%H'` $(BBSHOME)/bin/mbbsd clean: -- cgit v1.2.3 From eb3e6d48d444fbc54420a814ff78c24161b6f437 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sat, 8 Mar 2003 01:43:28 +0000 Subject: register git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@689 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/user.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/pttbbs/mbbsd/user.c b/pttbbs/mbbsd/user.c index f290e449..e1ff5a3a 100644 --- a/pttbbs/mbbsd/user.c +++ b/pttbbs/mbbsd/user.c @@ -1,4 +1,4 @@ -/* $Id: user.c,v 1.47 2003/02/22 09:12:42 in2 Exp $ */ +/* $Id: user.c,v 1.48 2003/03/08 01:43:28 in2 Exp $ */ #include "bbs.h" static char *sex[8] = { @@ -942,12 +942,21 @@ static char *isvaildname(char *rname) { if( removespace(rname) && rname[0] < 0 && strlen(rname) >= 4 && - !strstr(rname, "阿") && !strstr(rname, "某") && - !strstr(rname, "ㄚ") && strstr(rname, "..") == NULL && + !strstr(rname, "幹") && !strstr(rname, "肥") && + !strstr(rname, "胖") && !strstr(rname, "笨") && + !strstr(rname, "阿") && !strstr(rname, "某") && + !strstr(rname, "ㄚ") && !strstr(rname, "..") && + !strstr(rname, "呆") && + !strstr(rname, "美女") && !strstr(rname, "帥哥") && !strstr(rname, "先生") && !strstr(rname, "小姐") && !strstr(rname, "老頭") && !strstr(rname, "豬頭") && - strncmp(rname, "小", 2) != 0 && + !strstr(rname, "寶貝") && !strstr(rname, "小白") && + !strstr(rname, "小明") && !strstr(rname, "小妹") && + !strstr(rname, "路人") && + + strncmp(rname, "小", 2) != 0 && //起頭是「小」 + strncmp(rname, "我是", 4) != 0 && //起頭是「我是」 !(strlen(rname) == 4 && strncmp(&rname[2], "兒", 2) == 0) && !(strlen(rname) >= 4 && strncmp(&rname[0], &rname[2], 2) == 0)) return NULL; -- cgit v1.2.3 From 109194c3b5373e94b0563ae02efc9e717553bfa7 Mon Sep 17 00:00:00 2001 From: victor <victor@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sat, 8 Mar 2003 01:44:42 +0000 Subject: install: MRT.map git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@690 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/sample/etc/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pttbbs/sample/etc/Makefile b/pttbbs/sample/etc/Makefile index b607587f..2cc29755 100644 --- a/pttbbs/sample/etc/Makefile +++ b/pttbbs/sample/etc/Makefile @@ -2,7 +2,7 @@ SUBDIR=chickens BBSHOME?=$(HOME) TARGET=$(BBSHOME)/etc/ FILES= Welcome Welcome_login goodbye register registered ve.hlp Logout\ - Welcome_birth domain_name_query feast today_boring @five + Welcome_birth domain_name_query feast today_boring @five MRT.map all: -- cgit v1.2.3 From 91b255f154fb18b1ddb279316e2988a1331b8453 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sat, 8 Mar 2003 06:36:18 +0000 Subject: =?UTF-8?q?s/=EF=BF=BD=EF=BF=BD/=EF=BF=BDO/?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@691 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/sample/etc/MRT.map | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pttbbs/sample/etc/MRT.map b/pttbbs/sample/etc/MRT.map index 4732ae32..a5615bbc 100644 --- a/pttbbs/sample/etc/MRT.map +++ b/pttbbs/sample/etc/MRT.map @@ -1,5 +1,5 @@ - ●淡水 ※ 感謝本站 MRT 版提供 ※ + ●淡水 ※ 感謝本站 MRT 板提供 ※  ○紅樹林  -- cgit v1.2.3 From 7e3f49000d2e2041ae2cb2a4f1df93150eeb8cba Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Mon, 10 Mar 2003 03:13:03 +0000 Subject: MAX_EXKEEPMAIL could be overwrited in pttbbs.conf git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@692 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/include/config.h | 15 ++++++++++----- pttbbs/sample/pttbbs.conf | 3 +++ 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/pttbbs/include/config.h b/pttbbs/include/config.h index 5360a85d..d5d80cdc 100644 --- a/pttbbs/include/config.h +++ b/pttbbs/include/config.h @@ -1,4 +1,4 @@ -/* $Id: config.h,v 1.8 2003/01/23 18:39:01 in2 Exp $ */ +/* $Id: config.h,v 1.9 2003/03/10 03:13:02 in2 Exp $ */ #ifndef INCLUDE_CONFIG_H #define INCLUDE_CONFIG_H @@ -80,14 +80,20 @@ #ifndef MAXPATHLEN #define MAXPATHLEN (256) #endif + +#ifndef MAX_BOARD +#define MAX_BOARD (8192) /* 最大開板個數 */ +#endif + +#ifndef MAX_EXKEEPMAIL +#define MAX_EXKEEPMAIL (1000) /* 最多信箱加大多少封 */ +#endif + /* 以下還未整理 */ #define DIRCACHESIZE (40) /* cache 文章列表中最後40篇 */ #define MAX_FRIEND (256) /* 載入 cache 之最多朋友數目 */ #define MAX_REJECT (32) /* 載入 cache 之最多壞人數目 */ #define MAX_MSGS (10) /* 水球(熱訊)忍耐上限 */ -#ifndef MAX_BOARD -#define MAX_BOARD (8192) /* 最大開板個數 */ -#endif #define MAX_MOVIE (999) /* 最多動態看板數 */ #define MAX_MOVIE_SECTION (10) /* 最多動態看板類別 */ #define MAX_ITEMS (1000) /* 一個目錄最多有幾項 */ @@ -99,7 +105,6 @@ #define MAX_NAMELIST (128) /* 最多其他特別名單人數 */ #define MAX_PAGES (999) /* more.c 中文章頁數上限(lines/22) */ #define MAX_KEEPMAIL (200) /* 最多保留幾封 MAIL? */ -#define MAX_EXKEEPMAIL (1000) /* 最多信箱加大多少封 */ #define MAX_NOTE (20) /* 最多保留幾篇留言? */ #define MAX_SIGLINES (6) /* 簽名檔引入最大行數 */ #define MAX_CROSSNUM (9) /* 最多crosspost次數 */ diff --git a/pttbbs/sample/pttbbs.conf b/pttbbs/sample/pttbbs.conf index 84a9938c..0b0e51d6 100644 --- a/pttbbs/sample/pttbbs.conf +++ b/pttbbs/sample/pttbbs.conf @@ -71,6 +71,9 @@ //#define CRITICAL_MEMORY //#define CMSIGNAL SIGINFO +/* 設定最大可再買幾封信箱 (default: 1000) */ +#define MAX_EXKEEPMAIL (1000) + /* 前進站畫面 */ #define INSCREEN \ "前進站畫面 (請至 pttbbs.conf 修改您的前進站畫面)" -- cgit v1.2.3 From 48ff7860bf5e32dd66b0f6299e5a112d8aec705d Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Mon, 10 Mar 2003 05:55:26 +0000 Subject: =?UTF-8?q?=EF=BF=BDW=EF=BF=BD[=EF=BF=BD=EF=BF=BD=EF=BF=BDJ=20?= =?UTF-8?q?=EF=BF=BD=EF=BF=BD=EF=BF=BDR=EF=BF=BDH=EF=BF=BDc=EF=BF=BD?= =?UTF-8?q?=EF=BF=BD=20=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@693 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/user.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pttbbs/mbbsd/user.c b/pttbbs/mbbsd/user.c index e1ff5a3a..364a0420 100644 --- a/pttbbs/mbbsd/user.c +++ b/pttbbs/mbbsd/user.c @@ -1,4 +1,4 @@ -/* $Id: user.c,v 1.48 2003/03/08 01:43:28 in2 Exp $ */ +/* $Id: user.c,v 1.49 2003/03/10 05:55:26 in2 Exp $ */ #include "bbs.h" static char *sex[8] = { @@ -303,7 +303,8 @@ uinfo_query(userec_t * u, int real, int unum) } } snprintf(genbuf, sizeof(genbuf), "%d", x.exmailbox); - if (getdata_str(i++, 0, "購買信箱數:", buf, 4, DOECHO, genbuf)) + if (getdata_str(i++, 0, "購買信箱數:", buf, sizeof(buf), + DOECHO, genbuf)) if ((l = atol(buf)) != 0) x.exmailbox = (int)l; -- cgit v1.2.3 From 3647f577f131ae005ffa9dd324fd56ae800ddd96 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sat, 15 Mar 2003 03:33:16 +0000 Subject: add comments for PERM_* git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@694 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/include/perm.h | 66 +++++++++++++++++++++++++-------------------------- 1 file changed, 33 insertions(+), 33 deletions(-) diff --git a/pttbbs/include/perm.h b/pttbbs/include/perm.h index eece624e..607201b7 100644 --- a/pttbbs/include/perm.h +++ b/pttbbs/include/perm.h @@ -1,39 +1,39 @@ -/* $Id: perm.h,v 1.1 2002/03/07 15:13:48 in2 Exp $ */ +/* $Id: perm.h,v 1.2 2003/03/15 03:33:16 in2 Exp $ */ #ifndef INCLUDE_PERM_H #define INCLUDE_PERM_H -#define PERM_BASIC 000000000001 -#define PERM_CHAT 000000000002 -#define PERM_PAGE 000000000004 -#define PERM_POST 000000000010 -#define PERM_LOGINOK 000000000020 -#define PERM_MAILLIMIT 000000000040 -#define PERM_CLOAK 000000000100 -#define PERM_SEECLOAK 000000000200 -#define PERM_XEMPT 000000000400 -#define PERM_DENYPOST 000000001000 -#define PERM_BM 000000002000 -#define PERM_ACCOUNTS 000000004000 -#define PERM_CHATROOM 000000010000 -#define PERM_BOARD 000000020000 -#define PERM_SYSOP 000000040000 -#define PERM_BBSADM 000000100000 -#define PERM_NOTOP 000000200000 -#define PERM_VIOLATELAW 000000400000 -#define PERM_NOOUTMAIL 000001000000 -#define PERM_20 000002000000 -#define PERM_VIEWSYSOP 000004000000 -#define PERM_LOGUSER 000010000000 -#define PERM_ANNOUNCE 000020000000 -#define PERM_RELATION 000040000000 -#define PERM_SMG 000100000000 -#define PERM_PRG 000200000000 -#define PERM_ACTION 000400000000 -#define PERM_PAINT 001000000000 -#define PERM_LAW 002000000000 -#define PERM_SYSSUBOP 004000000000 -#define PERM_MSYSOP 010000000000 -#define PERM_PTT 020000000000 +#define PERM_BASIC 000000000001 /* 基本權力 */ +#define PERM_CHAT 000000000002 /* 進入聊天室 */ +#define PERM_PAGE 000000000004 /* 找人聊天 */ +#define PERM_POST 000000000010 /* 發表文章 */ +#define PERM_LOGINOK 000000000020 /* 註冊程序認證 */ +#define PERM_MAILLIMIT 000000000040 /* 信件無上限 */ +#define PERM_CLOAK 000000000100 /* 目前隱形中 */ +#define PERM_SEECLOAK 000000000200 /* 看見忍者 */ +#define PERM_XEMPT 000000000400 /* 永久保留帳號 */ +#define PERM_DENYPOST 000000001000 /* 站長隱身術 */ +#define PERM_BM 000000002000 /* 板主 */ +#define PERM_ACCOUNTS 000000004000 /* 帳號總管 */ +#define PERM_CHATROOM 000000010000 /* 聊天室總管 */ +#define PERM_BOARD 000000020000 /* 看板總管 */ +#define PERM_SYSOP 000000040000 /* 站長 */ +#define PERM_BBSADM 000000100000 /* BBSADM */ +#define PERM_NOTOP 000000200000 /* 不列入排行榜 */ +#define PERM_VIOLATELAW 000000400000 /* 違法通緝中 */ +#define PERM_NOOUTMAIL 000001000000 /* 不接受站外的信 */ +#define PERM_20 000002000000 /* 沒想到 */ +#define PERM_VIEWSYSOP 000004000000 /* 視覺站長 */ +#define PERM_LOGUSER 000010000000 /* 觀察使用者行蹤 */ +#define PERM_ANNOUNCE 000020000000 /* 精華區總整理權 */ +#define PERM_RELATION 000040000000 /* 公關組 */ +#define PERM_SMG 000100000000 /* 特務組 */ +#define PERM_PRG 000200000000 /* 程式組 */ +#define PERM_ACTION 000400000000 /* 活動組 */ +#define PERM_PAINT 001000000000 /* 美工組 */ +#define PERM_LAW 002000000000 /* 立法組 */ +#define PERM_SYSSUBOP 004000000000 /* 小組長 */ +#define PERM_MSYSOP 010000000000 /* 一級主管 */ +#define PERM_PTT 020000000000 /* Ptt */ #define NUMPERMS 32 -- cgit v1.2.3 From c08ffd0a8ca09b3bb2ca5d8f38ae0cb275e17e0d Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sat, 15 Mar 2003 12:06:39 +0000 Subject: remove sigfree git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@695 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/board.c | 20 +------------------- pttbbs/mbbsd/mbbsd.c | 5 +---- 2 files changed, 2 insertions(+), 23 deletions(-) diff --git a/pttbbs/mbbsd/board.c b/pttbbs/mbbsd/board.c index 8d91f3fe..e8fbe5ca 100644 --- a/pttbbs/mbbsd/board.c +++ b/pttbbs/mbbsd/board.c @@ -1,4 +1,4 @@ -/* $Id: board.c,v 1.84 2003/02/26 15:44:21 victor Exp $ */ +/* $Id: board.c,v 1.85 2003/03/15 12:06:39 in2 Exp $ */ #include "bbs.h" #define BRC_STRLEN 15 /* Length of board name */ #define BRC_MAXSIZE 24576 @@ -250,12 +250,6 @@ void FREE(void *ptr) vmsg("critical free %d bytes", size); #endif } - -void sigfree(int sig) -{ - if( !choose_board_depth ) - save_brdbuf(); -} #endif void load_brdbuf(void) @@ -271,11 +265,7 @@ void load_brdbuf(void) favsize += sizeof(int); #endif -#ifdef CRITICAL_MEMORY - zapbuf = (int *)MALLOC(size); -#else zapbuf = (int *)malloc(size); -#endif favbuf = (char *)malloc(favsize); #ifdef MEM_CHECK @@ -368,17 +358,9 @@ save_brdbuf(void) close(fd); } #ifdef MEM_CHECK -# ifdef CRITICAL_MEMORY - FREE(&zapbuf[-1]); -# else free(&zapbuf[-1]); -# endif #else -# ifdef CRITICAL_MEMORY - FREE(zapbuf); -# else free(zapbuf); -# endif #endif zapbuf = NULL; } diff --git a/pttbbs/mbbsd/mbbsd.c b/pttbbs/mbbsd/mbbsd.c index 3a5828b0..3aee5ce4 100644 --- a/pttbbs/mbbsd/mbbsd.c +++ b/pttbbs/mbbsd/mbbsd.c @@ -1,4 +1,4 @@ -/* $Id: mbbsd.c,v 1.66 2003/02/10 17:41:45 in2 Exp $ */ +/* $Id: mbbsd.c,v 1.67 2003/03/15 12:06:39 in2 Exp $ */ #include "bbs.h" #define SOCKET_QLEN 4 @@ -942,9 +942,6 @@ start_client() signal(SIGFPE, abort_bbs_debug); signal(SIGBUS, abort_bbs_debug); signal(SIGSEGV, abort_bbs_debug); -#ifdef CRITICAL_MEMORY - signal(CMSIGNAL, sigfree); -#endif signal_restart(SIGUSR1, talk_request); signal_restart(SIGUSR2, write_request); -- cgit v1.2.3 From a4b817990639a49e6e7fa40f718ce01288adba28 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sat, 15 Mar 2003 12:26:18 +0000 Subject: save memory usage of nbrd in CRITICAL_MEMORY mode git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@696 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/board.c | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/pttbbs/mbbsd/board.c b/pttbbs/mbbsd/board.c index e8fbe5ca..e2950b28 100644 --- a/pttbbs/mbbsd/board.c +++ b/pttbbs/mbbsd/board.c @@ -1,4 +1,4 @@ -/* $Id: board.c,v 1.85 2003/03/15 12:06:39 in2 Exp $ */ +/* $Id: board.c,v 1.86 2003/03/15 12:26:18 in2 Exp $ */ #include "bbs.h" #define BRC_STRLEN 15 /* Length of board name */ #define BRC_MAXSIZE 24576 @@ -230,7 +230,10 @@ char zapchange = 0, favchange = 0, choose_board_depth = 0; #define STR_FAV ".fav" #define STR_FAV2 ".fav2" -#ifdef CRITICAL_MEMORY +#ifndef CRITICAL_MEMORY + #define MALLOC(p) malloc(p) + #define FREE(p) free(p) +#else void *MALLOC(int size) { int *p; @@ -537,6 +540,9 @@ load_boards(char *key) int type = cuser.uflag & BRDSORT_FLAG ? 1 : 0; register int i, n; register int state; +#ifdef CRITICAL_MEMORY + boardstat_t *tmpnbrd; +#endif if (class_bid > 0) { bptr = &bcache[class_bid - 1]; @@ -549,7 +555,7 @@ load_boards(char *key) nbrd = NULL; } if (class_bid <= 0) { - nbrd = (boardstat_t *) malloc(sizeof(boardstat_t) * numboards); + nbrd = (boardstat_t *) MALLOC(sizeof(boardstat_t) * numboards); for (i = 0; i < numboards; i++) { if ((bptr = SHM->bsorted[type][i]) == NULL) continue; @@ -565,9 +571,8 @@ load_boards(char *key) } if (class_bid == -1) qsort(nbrd, brdnum, sizeof(boardstat_t), cmpboardfriends); - nbrd = realloc(nbrd, sizeof(boardstat_t) * brdnum); } else { - nbrd = (boardstat_t *) malloc(bptr->childcount * sizeof(boardstat_t)); + nbrd = (boardstat_t *) MALLOC(bptr->childcount * sizeof(boardstat_t)); for (bptr = bptr->firstchild[type]; bptr != (boardheader_t *) ~ 0; bptr = bptr->next[type]) { n = (int)(bptr - bcache); @@ -578,8 +583,15 @@ load_boards(char *key) continue; addnewbrdstat(n, state); } - nbrd = realloc(nbrd, sizeof(boardstat_t) * brdnum); } +#ifndef CRITICAL_MEMORY + nbrd = realloc(nbrd, sizeof(boardstat_t) * brdnum); +#else + tmpnbrd = (boardstat_t *) malloc(sizeof(boardstat_t) * brdnum); + memcpy(tmpnbrd, nbrd, sizeof(boardstat_t) * brdnum); + FREE(nbrd); + nbrd = tmpnbrd; +#endif } static int -- cgit v1.2.3 From 64b01299e64d6e777998fa2abe6758d4eab28891 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sat, 15 Mar 2003 12:33:00 +0000 Subject: show if mbbsd is in CRITICAL_MEMORY mode git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@697 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/cal.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pttbbs/mbbsd/cal.c b/pttbbs/mbbsd/cal.c index fe35bd7e..71091fac 100644 --- a/pttbbs/mbbsd/cal.c +++ b/pttbbs/mbbsd/cal.c @@ -1,4 +1,4 @@ -/* $Id: cal.c,v 1.23 2003/01/19 16:06:06 kcwu Exp $ */ +/* $Id: cal.c,v 1.24 2003/03/15 12:33:00 in2 Exp $ */ #include "bbs.h" /* 防堵 Multi play */ @@ -434,6 +434,9 @@ p_sysinfo(void) COMPILE_TIME, ctime(&start_time)); if (HAS_PERM(PERM_SYSOP)) { prints("記憶體使用量: %d\n", ((int)sbrk(0) - 0x8048000) / 1024); +#ifdef CRITICAL_MEMORY + prints("目前在 CRITICAL_MEMORY 模式下\n"); +#endif } pressanykey(); return 0; -- cgit v1.2.3 From 39f76f7867231d7ce7213350ccdeedbd00835bfa Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sat, 15 Mar 2003 15:30:58 +0000 Subject: show sbrk, idrss, isrss git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@698 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/cal.c | 8 ++++++-- pttbbs/mbbsd/io.c | 11 ++++++++--- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/pttbbs/mbbsd/cal.c b/pttbbs/mbbsd/cal.c index 71091fac..83e56465 100644 --- a/pttbbs/mbbsd/cal.c +++ b/pttbbs/mbbsd/cal.c @@ -1,4 +1,4 @@ -/* $Id: cal.c,v 1.24 2003/03/15 12:33:00 in2 Exp $ */ +/* $Id: cal.c,v 1.25 2003/03/15 15:30:58 in2 Exp $ */ #include "bbs.h" /* 防堵 Multi play */ @@ -433,7 +433,11 @@ p_sysinfo(void) #endif COMPILE_TIME, ctime(&start_time)); if (HAS_PERM(PERM_SYSOP)) { - prints("記憶體使用量: %d\n", ((int)sbrk(0) - 0x8048000) / 1024); + struct rusage ru; + getrusage(RUSAGE_SELF, &ru); + prints("記憶體用量: sbrk: %d KB, idrss: %d KB, isrss: %d KB\n", + ((int)sbrk(0) - 0x8048000) / 1024, + (int)ru.ru_idrss, (int)ru.ru_isrss); #ifdef CRITICAL_MEMORY prints("目前在 CRITICAL_MEMORY 模式下\n"); #endif diff --git a/pttbbs/mbbsd/io.c b/pttbbs/mbbsd/io.c index 1629f7cb..3e8f79a7 100644 --- a/pttbbs/mbbsd/io.c +++ b/pttbbs/mbbsd/io.c @@ -1,4 +1,4 @@ -/* $Id: io.c,v 1.27 2003/01/19 13:24:14 kcwu Exp $ */ +/* $Id: io.c,v 1.28 2003/03/15 15:30:58 in2 Exp $ */ #include "bbs.h" #if defined(linux) @@ -155,8 +155,13 @@ igetch() while ((ch = dogetch())) { switch (ch) { #ifdef DEBUG - case Ctrl('Q'): - vmsg("memory usage: %d KB", ((int)sbrk(0) - 0x8048000) / 1024); + case Ctrl('Q'):{ + struct rusage ru; + getrusage(RUSAGE_SELF, &ru); + vmsg("sbrk: %d KB, idrss: %d KB, isrss: %d KB", + ((int)sbrk(0) - 0x8048000) / 1024, + (int)ru.ru_idrss, (int)ru.ru_isrss); + } continue; #endif case Ctrl('L'): -- cgit v1.2.3 From aae025ea393f1fbca2581a1caf9fdb4b777d86f9 Mon Sep 17 00:00:00 2001 From: victor <victor@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Mon, 17 Mar 2003 12:34:15 +0000 Subject: rm unusable variable git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@699 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/voteboard.c | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/pttbbs/mbbsd/voteboard.c b/pttbbs/mbbsd/voteboard.c index d1696547..18ee5854 100644 --- a/pttbbs/mbbsd/voteboard.c +++ b/pttbbs/mbbsd/voteboard.c @@ -1,4 +1,4 @@ -/* $Id: voteboard.c,v 1.15 2003/01/19 16:06:06 kcwu Exp $ */ +/* $Id: voteboard.c,v 1.16 2003/03/17 12:34:15 victor Exp $ */ #include "bbs.h" #define VOTEBOARD "NewBoard" @@ -12,7 +12,7 @@ do_voteboardreply(fileheader_t * fhdr) char oldfpath[80]; char opnion[10]; char *ptr; - FILE *fo, *fp; + FILE *fp; fileheader_t votefile; int len; int i, j; @@ -71,18 +71,18 @@ do_voteboardreply(fileheader_t * fhdr) return; flock(fd, LOCK_EX); - fo = fopen(fpath, "w"); + fp = fopen(fpath, "w"); - if (!fo) + if (!fp) return; i = 0; - while (fo) { + while (fp) { j = 0; do { if (read(fd, genbuf + j, 1) <= 0) { flock(fd, LOCK_UN); close(fd); - fclose(fo); + fclose(fp); unlink(fpath); return; } @@ -94,20 +94,20 @@ do_voteboardreply(fileheader_t * fhdr) break; if (i > 3) prints(genbuf); - fprintf(fo, "%s", genbuf); + fprintf(fp, "%s", genbuf); } if (!hastime) { now += 14 * 24 * 60 * 60; - fprintf(fo, "連署結束時間: (%ld)%s", now, ctime(&now)); + fprintf(fp, "連署結束時間: (%ld)%s", now, ctime(&now)); now -= 14 * 24 * 60 * 60; } - fprintf(fo, "%s", genbuf); + fprintf(fp, "%s", genbuf); do { if (!getdata(18, 0, "請問您 (Y)支持 (N)反對 這個議題:", opnion, 3, LCECHO)) { flock(fd, LOCK_UN); close(fd); - fclose(fo); + fclose(fp); unlink(fpath); return; } @@ -117,20 +117,20 @@ do_voteboardreply(fileheader_t * fhdr) reason, sizeof(reason), DOECHO)) { flock(fd, LOCK_UN); close(fd); - fclose(fo); + fclose(fp); unlink(fpath); return; } i = 0; - while (fo) { + while (fp) { i++; j = 0; do { if (read(fd, genbuf + j, 1) <= 0) { flock(fd, LOCK_UN); close(fd); - fclose(fo); + fclose(fp); unlink(fpath); return; } @@ -140,15 +140,15 @@ do_voteboardreply(fileheader_t * fhdr) if (!strncmp("----------", genbuf, 10)) break; if (strncmp(genbuf + 4, cuser.userid, len)) - fprintf(fo, "%3d.%s", i, genbuf + 4); + fprintf(fp, "%3d.%s", i, genbuf + 4); else i--; } if (opnion[0] == 'y') - fprintf(fo, "%3d.%-15s%-34s 來源:%s\n", i, cuser.userid, reason, cuser.lasthost); + fprintf(fp, "%3d.%-15s%-34s 來源:%s\n", i, cuser.userid, reason, cuser.lasthost); i = 0; - fprintf(fo, "%s", genbuf); - while (fo) { + fprintf(fp, "%s", genbuf); + while (fp) { i++; j = 0; do { @@ -160,15 +160,15 @@ do_voteboardreply(fileheader_t * fhdr) if (j <= 3) break; if (strncmp(genbuf + 4, cuser.userid, len)) - fprintf(fo, "%3d.%s", i, genbuf + 4); + fprintf(fp, "%3d.%s", i, genbuf + 4); else i--; } if (opnion[0] == 'n') - fprintf(fo, "%3d.%-15s%-34s 來源:%s\n", i, cuser.userid, reason, cuser.lasthost); + fprintf(fp, "%3d.%-15s%-34s 來源:%s\n", i, cuser.userid, reason, cuser.lasthost); flock(fd, LOCK_UN); close(fd); - fclose(fo); + fclose(fp); unlink(oldfpath); rename(fpath, oldfpath); } -- cgit v1.2.3 From eb9059f0b0b135dec77c83aab41dd04f89f78e0c Mon Sep 17 00:00:00 2001 From: victor <victor@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Mon, 17 Mar 2003 13:41:04 +0000 Subject: move flock to another place git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@700 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/voteboard.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pttbbs/mbbsd/voteboard.c b/pttbbs/mbbsd/voteboard.c index 18ee5854..eac92529 100644 --- a/pttbbs/mbbsd/voteboard.c +++ b/pttbbs/mbbsd/voteboard.c @@ -1,4 +1,4 @@ -/* $Id: voteboard.c,v 1.16 2003/03/17 12:34:15 victor Exp $ */ +/* $Id: voteboard.c,v 1.17 2003/03/17 13:41:04 victor Exp $ */ #include "bbs.h" #define VOTEBOARD "NewBoard" @@ -69,7 +69,6 @@ do_voteboardreply(fileheader_t * fhdr) if ((fd = open(oldfpath, O_RDONLY)) == -1) return; - flock(fd, LOCK_EX); fp = fopen(fpath, "w"); @@ -121,6 +120,7 @@ do_voteboardreply(fileheader_t * fhdr) unlink(fpath); return; } + flock(fd, LOCK_EX); i = 0; while (fp) { -- cgit v1.2.3 From e5d653f545e12b4c6684b8abcc3ce307fe80a5e7 Mon Sep 17 00:00:00 2001 From: victor <victor@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Tue, 18 Mar 2003 14:27:13 +0000 Subject: do_allpost after edit_postbbs.c git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@701 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/bbs.c | 77 ++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 49 insertions(+), 28 deletions(-) diff --git a/pttbbs/mbbsd/bbs.c b/pttbbs/mbbsd/bbs.c index 2d498b59..5c0b914b 100644 --- a/pttbbs/mbbsd/bbs.c +++ b/pttbbs/mbbsd/bbs.c @@ -1,4 +1,4 @@ -/* $Id: bbs.c,v 1.80 2003/03/05 10:42:03 victor Exp $ */ +/* $Id: bbs.c,v 1.81 2003/03/18 14:27:13 victor Exp $ */ #include "bbs.h" static void @@ -397,6 +397,35 @@ static time_t last_post_time = 0; static time_t water_counts = 0; #endif +void +do_allpost(fileheader_t *postfile, const char *fpath, const char *owner) +{ + char genbuf[200]; + + setbpath(genbuf, ALLPOST); + stampfile(genbuf, postfile); + unlink(genbuf); + + /* jochang: boards may spread across many disk */ + /* + * link doesn't work across device, Link doesn't work if we have + * same-time-across-device posts, we try symlink now + */ + { + /* we need absolute path for symlink */ + char abspath[256] = BBSHOME "/"; + strcat(abspath, fpath); + symlink(abspath, genbuf); + } + strlcpy(postfile->owner, owner, sizeof(postfile->owner)); + strlcpy(postfile->title, save_title, sizeof(postfile->title)); + postfile->filemode = FILE_LOCAL; + setbdir(genbuf, ALLPOST); + if (append_record(genbuf, postfile, sizeof(fileheader_t)) != -1) { + setbtotal(getbnum(ALLPOST)); + } +} + static int do_general() { @@ -517,28 +546,7 @@ do_general() if (!(currbrdattr & BRD_HIDE) && (!bp->level || (currbrdattr & BRD_POSTMASK))) { - setbpath(genbuf, ALLPOST); - stampfile(genbuf, &postfile); - unlink(genbuf); - - /* jochang: boards may spread across many disk */ - /* - * link doesn't work across device, Link doesn't work if we have - * same-time-across-device posts, we try symlink now - */ - { - /* we need absolute path for symlink */ - char abspath[256] = BBSHOME "/"; - strcat(abspath, fpath); - symlink(abspath, genbuf); - } - strlcpy(postfile.owner, owner, sizeof(postfile.owner)); - strlcpy(postfile.title, save_title, sizeof(postfile.title)); - postfile.filemode = FILE_LOCAL; - setbdir(genbuf, ALLPOST); - if (append_record(genbuf, &postfile, sizeof(postfile)) != -1) { - setbtotal(getbnum(ALLPOST)); - } + do_allpost(&postfile, fpath, owner); } outs("順利貼出佈告,"); @@ -699,7 +707,9 @@ reply_post(int ent, fileheader_t * fhdr, char *direct) static int edit_post(int ent, fileheader_t * fhdr, char *direct) { + char fpath[80], fpath0[80]; char genbuf[200]; + fileheader_t postfile; boardheader_t *bp; bp = getbcache(currbid); if (strcmp(bp->brdname, "Security") == 0) @@ -718,32 +728,43 @@ edit_post(int ent, fileheader_t * fhdr, char *direct) setutmpmode(REEDIT); setdirpath(genbuf, direct, fhdr->filename); local_article = fhdr->filemode & FILE_LOCAL; + strlcpy(save_title, fhdr->title, sizeof(save_title)); /* rocker.011018: 這裡是不是該檢查一下修改文章後的money和原有的比較? */ if (vedit(genbuf, 0, NULL) != -1) { lock_substitute_record(direct, fhdr, sizeof(*fhdr), ent, LOCK_EX); + setbpath(fpath, currboard); + stampfile(fpath, &postfile); + unlink(fpath); + setbfile(fpath0, currboard, fhdr->filename); + + Rename(fpath0, fpath); /* rocker.011018: fix 串接模式改文章後文章就不見的bug */ if ((currmode & MODE_SELECT) && (fhdr->money & FHR_REFERENCE)) { fileheader_t hdr; - char fpath[80]; int num; num = fhdr->money & ~FHR_REFERENCE; - setbdir(fpath, currboard); - get_record(fpath, &hdr, sizeof(hdr), num); + setbdir(fpath0, currboard); + get_record(fpath0, &hdr, sizeof(hdr), num); /* 再這裡要check一下原來的dir裡面是不是有被人動過... */ if (!strcmp(hdr.filename, fhdr->filename)) { - strlcpy(hdr.filename, fhdr->filename, sizeof(hdr.filename)); + strlcpy(hdr.filename, postfile.filename, sizeof(hdr.filename)); strlcpy(hdr.title, save_title, sizeof(hdr.title)); - substitute_record(fpath, &hdr, sizeof(hdr), num); + substitute_record(fpath0, &hdr, sizeof(hdr), num); } } + strlcpy(fhdr->filename, postfile.filename, sizeof(fhdr->filename)); + strlcpy(fhdr->title, save_title, sizeof(fhdr->title)); + brc_addlist(postfile.filename); lock_substitute_record(direct, fhdr, sizeof(*fhdr), ent, LOCK_UN); /* rocker.011018: 順便更新一下cache */ touchdircache(currbid); } + + do_allpost(&postfile, fpath, cuser.userid); return FULLUPDATE; } -- cgit v1.2.3 From 42ae760766ba3b538c014c393f53c62174c57f43 Mon Sep 17 00:00:00 2001 From: victor <victor@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Tue, 18 Mar 2003 14:40:17 +0000 Subject: rm old form '.fav' git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@702 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/board.c | 29 +---------------------------- 1 file changed, 1 insertion(+), 28 deletions(-) diff --git a/pttbbs/mbbsd/board.c b/pttbbs/mbbsd/board.c index e2950b28..7f725ea4 100644 --- a/pttbbs/mbbsd/board.c +++ b/pttbbs/mbbsd/board.c @@ -1,4 +1,4 @@ -/* $Id: board.c,v 1.86 2003/03/15 12:26:18 in2 Exp $ */ +/* $Id: board.c,v 1.87 2003/03/18 14:40:17 victor Exp $ */ #include "bbs.h" #define BRC_STRLEN 15 /* Length of board name */ #define BRC_MAXSIZE 24576 @@ -227,7 +227,6 @@ static boardstat_t *nbrd = NULL; char zapchange = 0, favchange = 0, choose_board_depth = 0; #define STR_BBSRC ".bbsrc" -#define STR_FAV ".fav" #define STR_FAV2 ".fav2" #ifndef CRITICAL_MEMORY @@ -297,32 +296,6 @@ void load_brdbuf(void) read(fd, favbuf, favsize); close(fd); } - else{ - // translate old fav format(int array) to new format(char array) - setuserfile(fname, STR_FAV); - if( (fd = open(fname, O_RDONLY, 0600)) != -1 ){ - int *oldfav = (int *)malloc(size); - read(fd, oldfav, size); - close(fd); - - for( i = (numboards + 32) - 1 ; i >= 0 ; --i ) - favbuf[i] = oldfav[i]; - free(oldfav); - - setuserfile(fname, STR_FAV2); - if( (fd = open(fname, O_WRONLY | O_CREAT, 0600)) != -1 ){ - size = numboards * sizeof(char); - write(fd, favbuf, size); - close(fd); - - // remove old favorite file - setuserfile(fname, STR_FAV); - unlink(fname); - } - else - favchange = 1; - } - } if( firsttime ){ for (i = 0; i < numboards; i++) -- cgit v1.2.3 From ece31d2ba76ba5dae66f3f16d8297c86bca86424 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Thu, 20 Mar 2003 14:46:50 +0000 Subject: do NOT post edited article to ALLPOST in hidden board git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@703 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/bbs.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/pttbbs/mbbsd/bbs.c b/pttbbs/mbbsd/bbs.c index 5c0b914b..2f69eeba 100644 --- a/pttbbs/mbbsd/bbs.c +++ b/pttbbs/mbbsd/bbs.c @@ -1,4 +1,4 @@ -/* $Id: bbs.c,v 1.81 2003/03/18 14:27:13 victor Exp $ */ +/* $Id: bbs.c,v 1.82 2003/03/20 14:46:50 in2 Exp $ */ #include "bbs.h" static void @@ -764,7 +764,10 @@ edit_post(int ent, fileheader_t * fhdr, char *direct) touchdircache(currbid); } - do_allpost(&postfile, fpath, cuser.userid); + if (!(currbrdattr & BRD_HIDE) && + (!bp->level || (currbrdattr & BRD_POSTMASK))) { + do_allpost(&postfile, fpath, cuser.userid); + } return FULLUPDATE; } -- cgit v1.2.3 From d17a7554b1d0189bfa82b273080e661ba9634f6e Mon Sep 17 00:00:00 2001 From: victor <victor@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Thu, 20 Mar 2003 15:10:49 +0000 Subject: whether do_allpost git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@704 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/bbs.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/pttbbs/mbbsd/bbs.c b/pttbbs/mbbsd/bbs.c index 2f69eeba..65c5408a 100644 --- a/pttbbs/mbbsd/bbs.c +++ b/pttbbs/mbbsd/bbs.c @@ -1,4 +1,4 @@ -/* $Id: bbs.c,v 1.82 2003/03/20 14:46:50 in2 Exp $ */ +/* $Id: bbs.c,v 1.83 2003/03/20 15:10:49 victor Exp $ */ #include "bbs.h" static void @@ -764,10 +764,8 @@ edit_post(int ent, fileheader_t * fhdr, char *direct) touchdircache(currbid); } - if (!(currbrdattr & BRD_HIDE) && - (!bp->level || (currbrdattr & BRD_POSTMASK))) { + if (!(currbrdattr & BRD_HIDE) && (!bp->level || (currbrdattr & BRD_POSTMASK))) do_allpost(&postfile, fpath, cuser.userid); - } return FULLUPDATE; } -- cgit v1.2.3 From efbf6f9718cd8f4c8d307c26ce2840ada84708f7 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sat, 22 Mar 2003 09:40:56 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@705 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/mvdir.pl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pttbbs/util/mvdir.pl b/pttbbs/util/mvdir.pl index b88cab28..53acd9b3 100644 --- a/pttbbs/util/mvdir.pl +++ b/pttbbs/util/mvdir.pl @@ -15,7 +15,8 @@ if( !-e $fromdir ){ exit; } -mkdir $todir; +mkdir($todir, 0755); + chdir $fromdir; foreach( <*> ){ next if( /^\./ ); -- cgit v1.2.3 From ff43b9becddd9cb2e1c0e3b893b715491a500c8e Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sat, 22 Mar 2003 12:02:50 +0000 Subject: remove cmsignal() git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@706 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/shmctl.c | 18 +----------------- 1 file changed, 1 insertion(+), 17 deletions(-) diff --git a/pttbbs/util/shmctl.c b/pttbbs/util/shmctl.c index 20850b00..a772bd42 100644 --- a/pttbbs/util/shmctl.c +++ b/pttbbs/util/shmctl.c @@ -1,4 +1,4 @@ -/* $Id: shmctl.c,v 1.33 2003/02/17 18:36:55 in2 Exp $ */ +/* $Id: shmctl.c,v 1.34 2003/03/22 12:02:50 in2 Exp $ */ #include "bbs.h" #include <sys/wait.h> @@ -369,22 +369,6 @@ int listpid(int argc, char **argv) return 0; } -#ifdef CRITICAL_MEMORY -int cmsignal(int argc, char **argv) -{ - int i; - time_t timebound = time(NULL) - 1200; - char buf[32]; - for( i = 0 ; i < USHM_SIZE ; ++i ) - if( SHM->uinfo[i].pid > 0 && SHM->uinfo[i].lastact < timebound ){ - printf("CMSIGNAL: pid: %6d, lastact: %s\n", - SHM->uinfo[i].pid, CTIMEx(buf, SHM->uinfo[i].lastact)); - kill(SHM->uinfo[i].pid, CMSIGNAL); - } - return 0; -} -#endif - struct { int (*func)(int, char **); char *cmd, *descript; -- cgit v1.2.3 From c26c9952c3c9e44bb7af7f7d4e480bae0daaf528 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sat, 22 Mar 2003 12:18:15 +0000 Subject: remove cmsignal git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@707 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/shmctl.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/pttbbs/util/shmctl.c b/pttbbs/util/shmctl.c index a772bd42..828e9d38 100644 --- a/pttbbs/util/shmctl.c +++ b/pttbbs/util/shmctl.c @@ -1,4 +1,4 @@ -/* $Id: shmctl.c,v 1.34 2003/03/22 12:02:50 in2 Exp $ */ +/* $Id: shmctl.c,v 1.35 2003/03/22 12:18:15 in2 Exp $ */ #include "bbs.h" #include <sys/wait.h> @@ -382,9 +382,6 @@ struct { {showglobal, "showglobal", "show GLOBALVAR[]"}, {setglobal, "setglobal", "set GLOBALVAR[]"}, {listpid, "listpid", "list all pids of mbbsd"}, -#ifdef CRITICAL_MEMORY - {cmsignal, "cmsignal", "send cmsignal"}, -#endif {NULL, NULL, NULL} }; int main(int argc, char **argv) -- cgit v1.2.3 From 98c49497bcceafc996d7ce482d9c258405fb64f1 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sat, 22 Mar 2003 13:45:56 +0000 Subject: fix bug of screen overflow git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@708 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/vice.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pttbbs/mbbsd/vice.c b/pttbbs/mbbsd/vice.c index 2f5aa310..2792e47e 100644 --- a/pttbbs/mbbsd/vice.c +++ b/pttbbs/mbbsd/vice.c @@ -1,4 +1,4 @@ -/* $Id: vice.c,v 1.7 2003/01/19 16:06:06 kcwu Exp $ */ +/* $Id: vice.c,v 1.8 2003/03/22 13:45:56 in2 Exp $ */ #include "bbs.h" #define VICE_PLAY BBSHOME "/etc/vice/vice.play" @@ -112,6 +112,8 @@ vice_main() *ptr = 0; if (j == 0) i++; + if( i >= 14 ) + break; move(10 + i, 24 + j); prints("%s", serial); j += 9; -- cgit v1.2.3 From daf7c6ad48650733ee674c77f91946868d113fee Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sat, 22 Mar 2003 13:57:23 +0000 Subject: overwrite CFLAGS(in make.conf) if DEBUG git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@709 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/Makefile | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/pttbbs/mbbsd/Makefile b/pttbbs/mbbsd/Makefile index 557ca7a2..b3256a76 100644 --- a/pttbbs/mbbsd/Makefile +++ b/pttbbs/mbbsd/Makefile @@ -1,19 +1,19 @@ -# $Id: Makefile,v 1.19 2003/03/05 10:44:43 victor Exp $ +# $Id: Makefile,v 1.20 2003/03/22 13:57:23 in2 Exp $ # 訂義基本初值 BBSHOME?= $(HOME) BBSHOME?= /home/bbs OSTYPE?= FreeBSD CC?= gcc -CFLAGS+= -Wall -pipe -DBBSHOME='"$(BBSHOME)"' -I../include -LDFLAGS+= -pipe -Wall -LIBS+= -lcrypt +PTT_CFLAGS= -Wall -pipe -DBBSHOME='"$(BBSHOME)"' -I../include +PTT_LDFLAGS= -pipe -Wall +PTT_LIBS= -lcrypt # 在 CFLAGS內加入定義 COMPILE_TIME -CFLAGS+= "-DCOMPILE_TIME=\"`date`\"" +PTT_CFLAGS+= "-DCOMPILE_TIME=\"`date`\"" # 稍後再 enable assert() -CFLAGS+= -DNDEBUG +PTT_CFLAGS+= -DNDEBUG # FreeBSD特有的環境 CFLAGS_FreeBSD= -DHAVE_SETPROCTITLE -DFreeBSD @@ -26,17 +26,17 @@ LDFLAGS_linux= -pipe -Wall LIBS_linux= # CFLAGS, LDFLAGS, LIBS 加入 OS 相關參數 -CFLAGS+= $(CFLAGS_$(OSTYPE)) -LDFLAGS+= $(LDFLAGS_$(OSTYPE)) -LIBS+= $(LIBS_$(OSTYPE)) +PTT_CFLAGS+= $(CFLAGS_$(OSTYPE)) +PTT_LDFLAGS+= $(LDFLAGS_$(OSTYPE)) +PTT_LIBS+= $(LIBS_$(OSTYPE)) # 若有定義 GDB或 DEBUG, 則加入 -g , 否則用 -O .if defined(GDB) || defined(DEBUG) -CFLAGS+= -g -FDFLAGS+= -g +CFLAGS= -g $(PTT_CFLAGS) +LDFLAGS= -g $(PTT_LDFLAGS) $(PTT_LIBS) .else -CFLAGS+= -Os -LDFLAGS+= -O +CFLAGS+= -Os $(PTT_CFLAGS) +LDFLAGS+= -O $(PTT_LDFLAGS) $(PTT_LIBS) .endif # 若有定義 DEBUG, 則在 CFLAGS內定義 DEBUG -- cgit v1.2.3 From e63d8b6929f47fcf04a2f31c5b8600f91c6f5c9b Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Mon, 24 Mar 2003 10:28:24 +0000 Subject: show Welcome_login before login initialization. (when system load is heavy, users will be blocked in Welcome_login instead of Welcome) git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@710 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/mbbsd.c | 81 ++++++++++++++++++++++++++-------------------------- 1 file changed, 41 insertions(+), 40 deletions(-) diff --git a/pttbbs/mbbsd/mbbsd.c b/pttbbs/mbbsd/mbbsd.c index 3aee5ce4..00e4fa7a 100644 --- a/pttbbs/mbbsd/mbbsd.c +++ b/pttbbs/mbbsd/mbbsd.c @@ -1,4 +1,4 @@ -/* $Id: mbbsd.c,v 1.67 2003/03/15 12:06:39 in2 Exp $ */ +/* $Id: mbbsd.c,v 1.68 2003/03/24 10:28:24 in2 Exp $ */ #include "bbs.h" #define SOCKET_QLEN 4 @@ -231,7 +231,7 @@ abort_bbs_debug(int sig) static void mysrand() { - srand(time(NULL) + currutmp->pid); /* 時間跟 pid 當 rand 的 seed */ + srand(time(NULL) + getpid()); /* 時間跟 pid 當 rand 的 seed */ } int @@ -757,12 +757,41 @@ user_login() char genbuf[200]; struct tm *ptime, *tmp; time_t now; - int a; - /*** Heat:廣告詞 - char *ADV[] = { - "7/17 @LIVE 亂彈, 何欣穗 的 入場卷要送給 ptt 的愛用者!", - "欲知詳情請看 PttAct 板!!", - }; ***/ + int a, ifbirth; + + /* get local time */ + time(&now); + ptime = localtime(&now); + + /* 初始化: random number 增加user跟時間的差異 */ + mysrand(); + + /* show welcome_login */ + ifbirth = (ptime->tm_mday == cuser.day && + ptime->tm_mon + 1 == cuser.month); + if (ifbirth) + more("etc/Welcome_birth", NA); + else { +#ifndef MULTI_WELCOME_LOGIN + more("etc/Welcome_login", NA); +#else + char buf[80]; + int nScreens; + + for (nScreens = 0; nScreens < 5; ++nScreens) { + snprintf(buf, sizeof(buf), "etc/Welcome_login.%d", nScreens); + if (access(buf, 0) < 0) + break; + } + if (nScreens == 0) { + //multi screen error ? + more("etc/Welcome_login", NA); + } else { + snprintf(buf, sizeof(buf), "etc/Welcome_login.%d", (int)login_start_time % nScreens); + more(buf, NA); + } +#endif + } log_usies("ENTER", fromhost); setproctitle("%s: %s", margs, cuser.userid); @@ -772,13 +801,10 @@ user_login() strlcpy(water[0].userid, " 全部 ", sizeof(water[0].userid)); /* 初始化 uinfo、flag、mode */ setup_utmp(LOGIN); - mysrand(); /* 初始化: random number 增加user跟時間的差異 */ currmode = MODE_STARTED; enter_uflag = cuser.uflag; + currutmp->birth = ifbirth; - /* get local time */ - time(&now); - ptime = localtime(&now); tmp = localtime(&cuser.lastlogin); if ((a = SHM->UTMPnumber) > SHM->max_user) { SHM->max_user = a; @@ -787,35 +813,10 @@ user_login() init_brdbuf(); brc_initial(DEFAULT_BOARD); set_board(); - /* 畫面處理開始 */ - if (!(HAS_PERM(PERM_SYSOP) && HAS_PERM(PERM_DENYPOST)) && !currutmp->invisible) + + if (!(HAS_PERM(PERM_SYSOP) && HAS_PERM(PERM_DENYPOST)) && + !currutmp->invisible) do_aloha("<<上站通知>> -- 我來啦!"); - if (ptime->tm_mday == cuser.day && ptime->tm_mon + 1 == cuser.month) { - more("etc/Welcome_birth", NA); - currutmp->birth = 1; - } else { -#ifdef MULTI_WELCOME_LOGIN - char buf[80]; - int nScreens; - for (nScreens = 0; nScreens < 10; ++nScreens) { - snprintf(buf, sizeof(buf), "etc/Welcome_login.%d", nScreens); - if (access(buf, 0) < 0) - break; - } - if (nScreens == 0) { - //multi screen error ? - more("etc/Welcome_login", NA); - } else { - snprintf(buf, sizeof(buf), "etc/Welcome_login.%d", (int)login_start_time % nScreens); - more(buf, NA); - } -#else - more("etc/Welcome_login", NA); -#endif - //pressanykey(); - //more("etc/CSIE_Week", NA); - currutmp->birth = 0; - } if (cuser.userlevel) { /* not guest */ move(t_lines - 4, 0); -- cgit v1.2.3 From ce458b079822c0935acdbf8cc7acc300c2b03a0d Mon Sep 17 00:00:00 2001 From: ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Mon, 24 Mar 2003 20:44:09 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@711 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/web/Makefile | 4 +- pttbbs/web/libptt.a | Bin 107932 -> 0 bytes pttbbs/web/mod_ptt.c | 895 ++--------------------------------------------- pttbbs/web/util_cache.c | 6 +- pttbbs/web/util_passwd.c | 4 +- pttbbs/web/util_record.c | 3 +- 6 files changed, 38 insertions(+), 874 deletions(-) delete mode 100644 pttbbs/web/libptt.a diff --git a/pttbbs/web/Makefile b/pttbbs/web/Makefile index bff43078..42a1a84a 100644 --- a/pttbbs/web/Makefile +++ b/pttbbs/web/Makefile @@ -1,4 +1,6 @@ all: mod_ptt.c mod_ptt.h - apxs -I ../include -c mod_ptt.c + apxs -I ../include -c mod_ptt.c util_cache.c util_passwd.c util_record.c cp mod_ptt.so /usr/local/libexec/apache/mod_ptt.so chmod 775 /usr/local/libexec/apache/mod_ptt.so +clean: + rm -f *.o *.a *.so diff --git a/pttbbs/web/libptt.a b/pttbbs/web/libptt.a deleted file mode 100644 index 26c2f527..00000000 Binary files a/pttbbs/web/libptt.a and /dev/null differ diff --git a/pttbbs/web/mod_ptt.c b/pttbbs/web/mod_ptt.c index a6427a32..be4a8071 100644 --- a/pttbbs/web/mod_ptt.c +++ b/pttbbs/web/mod_ptt.c @@ -1,36 +1,6 @@ -/* - * Apache example module. Provide demonstrations of how modules do things. - * - */ - #include "mod_ptt.h" extern int numboards; extern boardheader_t *bcache; -/*--------------------------------------------------------------------------*/ -/* */ -/* Data declarations. */ -/* */ -/* Here are the static cells and structure declarations private to our */ -/* module. */ -/* */ -/*--------------------------------------------------------------------------*/ - -/* - * Sample configuration record. Used for both per-directory and per-server - * configuration data. - * - * It's perfectly reasonable to have two different structures for the two - * different environments. The same command handlers will be called for - * both, though, so the handlers need to be able to tell them apart. One - * possibility is for both structures to start with an int which is zero for - * one and 1 for the other. - * - * Note that while the per-directory and per-server configuration records are - * available to most of the module handlers, they should be treated as - * READ-ONLY by all except the command and merge handlers. Sometimes handlers - * are handed a record that applies to the current location by implication or - * inheritance, and modifying it will change the rules for other locations. - */ typedef struct excfg { int cmode; /* Environment to which record applies (directory, * server, or combination). @@ -44,186 +14,19 @@ typedef struct excfg { char *loc; /* Location to which this record applies. */ } excfg; -/* - * Let's set up a module-local static cell to point to the accreting callback - * trace. As each API callback is made to us, we'll tack on the particulars - * to whatever we've already recorded. To avoid massive memory bloat as - * directories are walked again and again, we record the routine/environment - * the first time (non-request context only), and ignore subsequent calls for - * the same routine/environment. - */ static const char *trace = NULL; static table *static_calls_made = NULL; -/* - * To avoid leaking memory from pools other than the per-request one, we - * allocate a module-private pool, and then use a sub-pool of that which gets - * freed each time we modify the trace. That way previous layers of trace - * data don't get lost. - */ static pool *ptt_pool = NULL; static pool *ptt_subpool = NULL; -/* - * Declare ourselves so the configuration routines can find and know us. - * We'll fill it in at the end of the module. - */ module MODULE_VAR_EXPORT ptt_module; - -/*--------------------------------------------------------------------------*/ -/* */ -/* The following pseudo-prototype declarations illustrate the parameters */ -/* passed to command handlers for the different types of directive */ -/* syntax. If an argument was specified in the directive definition */ -/* (look for "command_rec" below), it's available to the command handler */ -/* via the (void *) info field in the cmd_parms argument passed to the */ -/* handler (cmd->info for the examples below). */ -/* */ -/*--------------------------------------------------------------------------*/ - -/* - * Command handler for a NO_ARGS directive. - * - * static const char *handle_NO_ARGS(cmd_parms *cmd, void *mconfig); - */ - -/* - * Command handler for a RAW_ARGS directive. The "args" argument is the text - * of the commandline following the directive itself. - * - * static const char *handle_RAW_ARGS(cmd_parms *cmd, void *mconfig, - * const char *args); - */ - -/* - * Command handler for a FLAG directive. The single parameter is passed in - * "bool", which is either zero or not for Off or On respectively. - * - * static const char *handle_FLAG(cmd_parms *cmd, void *mconfig, int bool); - */ - -/* - * Command handler for a TAKE1 directive. The single parameter is passed in - * "word1". - * - * static const char *handle_TAKE1(cmd_parms *cmd, void *mconfig, - * char *word1); - */ - -/* - * Command handler for a TAKE2 directive. TAKE2 commands must always have - * exactly two arguments. - * - * static const char *handle_TAKE2(cmd_parms *cmd, void *mconfig, - * char *word1, char *word2); - */ - -/* - * Command handler for a TAKE3 directive. Like TAKE2, these must have exactly - * three arguments, or the parser complains and doesn't bother calling us. - * - * static const char *handle_TAKE3(cmd_parms *cmd, void *mconfig, - * char *word1, char *word2, char *word3); - */ - -/* - * Command handler for a TAKE12 directive. These can take either one or two - * arguments. - * - word2 is a NULL pointer if no second argument was specified. - * - * static const char *handle_TAKE12(cmd_parms *cmd, void *mconfig, - * char *word1, char *word2); - */ - -/* - * Command handler for a TAKE123 directive. A TAKE123 directive can be given, - * as might be expected, one, two, or three arguments. - * - word2 is a NULL pointer if no second argument was specified. - * - word3 is a NULL pointer if no third argument was specified. - * - * static const char *handle_TAKE123(cmd_parms *cmd, void *mconfig, - * char *word1, char *word2, char *word3); - */ - -/* - * Command handler for a TAKE13 directive. Either one or three arguments are - * permitted - no two-parameters-only syntax is allowed. - * - word2 and word3 are NULL pointers if only one argument was specified. - * - * static const char *handle_TAKE13(cmd_parms *cmd, void *mconfig, - * char *word1, char *word2, char *word3); - */ - -/* - * Command handler for a TAKE23 directive. At least two and as many as three - * arguments must be specified. - * - word3 is a NULL pointer if no third argument was specified. - * - * static const char *handle_TAKE23(cmd_parms *cmd, void *mconfig, - * char *word1, char *word2, char *word3); - */ - -/* - * Command handler for a ITERATE directive. - * - Handler is called once for each of n arguments given to the directive. - * - word1 points to each argument in turn. - * - * static const char *handle_ITERATE(cmd_parms *cmd, void *mconfig, - * char *word1); - */ - -/* - * Command handler for a ITERATE2 directive. - * - Handler is called once for each of the second and subsequent arguments - * given to the directive. - * - word1 is the same for each call for a particular directive instance (the - * first argument). - * - word2 points to each of the second and subsequent arguments in turn. - * - * static const char *handle_ITERATE2(cmd_parms *cmd, void *mconfig, - * char *word1, char *word2); - */ - -/*--------------------------------------------------------------------------*/ -/* */ -/* These routines are strictly internal to this module, and support its */ -/* operation. They are not referenced by any external portion of the */ -/* server. */ -/* */ -/*--------------------------------------------------------------------------*/ - -/* - * Locate our directory configuration record for the current request. - */ -static excfg *our_dconfig(request_rec *r) +excfg * our_dconfig(request_rec *r) { return (excfg *) ap_get_module_config(r->per_dir_config, &ptt_module); } -#if 0 -/* - * Locate our server configuration record for the specified server. - */ -static excfg *our_sconfig(server_rec *s) -{ - - return (excfg *) ap_get_module_config(s->module_config, &ptt_module); -} - -/* - * Likewise for our configuration record for the specified request. - */ -static excfg *our_rconfig(request_rec *r) -{ - - return (excfg *) ap_get_module_config(r->request_config, &ptt_module); -} -#endif - -/* - * This routine sets up some module-wide cells if they haven't been already. - */ static void setup_module_cells() { /* @@ -241,212 +44,19 @@ static void setup_module_cells() }; } -/* - * This routine is used to add a trace of a callback to the list. We're - * passed the server record (if available), the request record (if available), - * a pointer to our private configuration record (if available) for the - * environment to which the callback is supposed to apply, and some text. We - * turn this into a textual representation and add it to the tail of the list. - * The list can be displayed by the example_handler() routine. - * - * If the call occurs within a request context (i.e., we're passed a request - * record), we put the trace into the request pool and attach it to the - * request via the notes mechanism. Otherwise, the trace gets added - * to the static (non-request-specific) list. - * - * Note that the r->notes table is only for storing strings; if you need to - * maintain per-request data of any other type, you need to use another - * mechanism. - */ - -#define TRACE_NOTE "ptt-trace" - -static void trace_add(server_rec *s, request_rec *r, excfg *mconfig, - const char *note) -{ - - const char *sofar; - char *addon; - char *where; - pool *p; - const char *trace_copy; - - /* - * Make sure our pools and tables are set up - we need 'em. - */ - setup_module_cells(); - /* - * Now, if we're in request-context, we use the request pool. - */ - if (r != NULL) { - p = r->pool; - if ((trace_copy = ap_table_get(r->notes, TRACE_NOTE)) == NULL) { - trace_copy = ""; - } - } - else { - /* - * We're not in request context, so the trace gets attached to our - * module-wide pool. We do the create/destroy every time we're called - * in non-request context; this avoids leaking memory in some of - * the subsequent calls that allocate memory only once (such as the - * key formation below). - * - * Make a new sub-pool and copy any existing trace to it. Point the - * trace cell at the copied value. - */ - p = ap_make_sub_pool(ptt_pool); - if (trace != NULL) { - trace = ap_pstrdup(p, trace); - } - /* - * Now, if we have a sub-pool from before, nuke it and replace with - * the one we just allocated. - */ - if (ptt_subpool != NULL) { - ap_destroy_pool(ptt_subpool); - } - ptt_subpool = p; - trace_copy = trace; - } - /* - * If we weren't passed a configuration record, we can't figure out to - * what location this call applies. This only happens for co-routines - * that don't operate in a particular directory or server context. If we - * got a valid record, extract the location (directory or server) to which - * it applies. - */ - where = (mconfig != NULL) ? mconfig->loc : "nowhere"; - where = (where != NULL) ? where : ""; - /* - * Now, if we're not in request context, see if we've been called with - * this particular combination before. The table is allocated in the - * module's private pool, which doesn't get destroyed. - */ - if (r == NULL) { - char *key; - - key = ap_pstrcat(p, note, ":", where, NULL); - if (ap_table_get(static_calls_made, key) != NULL) { - /* - * Been here, done this. - */ - return; - } - else { - /* - * First time for this combination of routine and environment - - * log it so we don't do it again. - */ - ap_table_set(static_calls_made, key, "been here"); - } - } - addon = ap_pstrcat(p, " <LI>\n", " <DL>\n", " <DT><SAMP>", - note, "</SAMP>\n", " </DT>\n", " <DD><SAMP>[", - where, "]</SAMP>\n", " </DD>\n", " </DL>\n", - " </LI>\n", NULL); - sofar = (trace_copy == NULL) ? "" : trace_copy; - trace_copy = ap_pstrcat(p, sofar, addon, NULL); - if (r != NULL) { - ap_table_set(r->notes, TRACE_NOTE, trace_copy); - } - else { - trace = trace_copy; - } - /* - * You *could* change the following if you wanted to see the calling - * sequence reported in the server's error_log, but beware - almost all of - * these co-routines are called for every single request, and the impact - * on the size (and readability) of the error_log is considerable. - */ -#define EXAMPLE_LOG_EACH 0 -#if EXAMPLE_LOG_EACH - if (s != NULL) { - ap_log_error(APLOG_MARK, APLOG_DEBUG, s, "mod_ptt: %s", note); - } -#endif -} - -/*--------------------------------------------------------------------------*/ -/* We prototyped the various syntax for command handlers (routines that */ -/* are called when the configuration parser detects a directive declared */ -/* by our module) earlier. Now we actually declare a "real" routine that */ -/* will be invoked by the parser when our "real" directive is */ -/* encountered. */ -/* */ -/* If a command handler encounters a problem processing the directive, it */ -/* signals this fact by returning a non-NULL pointer to a string */ -/* describing the problem. */ -/* */ -/* The magic return value DECLINE_CMD is used to deal with directives */ -/* that might be declared by multiple modules. If the command handler */ -/* returns NULL, the directive was processed; if it returns DECLINE_CMD, */ -/* the next module (if any) that declares the directive is given a chance */ -/* at it. If it returns any other value, it's treated as the text of an */ -/* error message. */ -/*--------------------------------------------------------------------------*/ -/* - * Command handler for the NO_ARGS "Example" directive. All we do is mark the - * call in the trace log, and flag the applicability of the directive to the - * current location in that location's configuration record. - */ -static const char *cmd_ptt(cmd_parms *cmd, void *mconfig) -{ - excfg *cfg = (excfg *) mconfig; - /* - * "Example Wuz Here" - */ - cfg->local = 1; - trace_add(cmd->server, NULL, cfg, "cmd_ptt()"); - return NULL; -} - -/*--------------------------------------------------------------------------*/ -/* */ -/* Now we declare our content handlers, which are invoked when the server */ -/* encounters a document which our module is supposed to have a chance to */ -/* see. (See mod_mime's SetHandler and AddHandler directives, and the */ -/* mod_info and mod_status examples, for more details.) */ -/* */ -/* Since content handlers are dumping data directly into the connexion */ -/* (using the r*() routines, such as rputs() and rprintf()) without */ -/* intervention by other parts of the server, they need to make */ -/* sure any accumulated HTTP headers are sent first. This is done by */ -/* calling send_http_header(). Otherwise, no header will be sent at all, */ -/* and the output sent to the client will actually be HTTP-uncompliant. */ -/*--------------------------------------------------------------------------*/ -/* - * Sample content handler. All this does is display the call list that has - * been built up so far. - * - * The return value instructs the caller concerning what happened and what to - * do next: - * OK ("we did our thing") - * DECLINED ("this isn't something with which we want to get involved") - * HTTP_mumble ("an error status should be reported") - */ static int ptt_handler(request_rec *r) { int i; excfg *dcfg; dcfg = our_dconfig(r); - trace_add(r->server, r, dcfg, "ptt_handler()"); - /* - * We're about to start sending content, so we need to force the HTTP - * headers to be sent at this point. Otherwise, no headers will be sent - * at all. We can set any we like first, of course. **NOTE** Here's - * where you set the "Content-type" header, and you do so by putting it in - * r->content_type, *not* r->headers_out("Content-type"). If you don't - * set it, it will be filled in with the server's default type (typically - * "text/plain"). You *must* also ensure that r->content_type is lower - * case. - * - * We also need to start a timer so the server can know if the connexion - * is broken. - */ + //resolve_utmp(); + //resolve_boards(); + // resolve_garbage(); + // resolve_fcache(); + r->content_type = "text/html"; ap_soft_timeout("send ptt call trace", r); @@ -537,50 +147,16 @@ static int ptt_handler(request_rec *r) * There is no return value. */ -/* - * All our module-initialiser does is add its trace to the log. - */ -static void ptt_init(server_rec *s, pool *p) -{ - - char *note; - char *sname = s->server_hostname; - - /* - * Set up any module cells that ought to be initialised. - */ - setup_module_cells(); - /* - * The arbitrary text we add to our trace entry indicates for which server - * we're being called. - */ - sname = (sname != NULL) ? sname : ""; - note = ap_pstrcat(p, "ptt_init(", sname, ")", NULL); - trace_add(s, NULL, NULL, note); -} - -/* - * This function is called during server initialisation when an heavy-weight - * process (such as a child) is being initialised. As with the - * module-initialisation function, any information that needs to be recorded - * must be in static cells, since there's no configuration record. - * - * There is no return value. - */ - -/* - * All our process-initialiser does is add its trace to the log. - */ static void ptt_child_init(server_rec *s, pool *p) { char *note; char *sname = s->server_hostname; - resolve_utmp(); - resolve_boards(); - resolve_garbage(); - resolve_fcache(); + //resolve_utmp(); + //resolve_boards(); + //resolve_garbage(); + //resolve_fcache(); /* * Set up any module cells that ought to be initialised. */ @@ -591,21 +167,8 @@ static void ptt_child_init(server_rec *s, pool *p) */ sname = (sname != NULL) ? sname : ""; note = ap_pstrcat(p, "ptt_child_init(", sname, ")", NULL); - trace_add(s, NULL, NULL, note); } -/* - * This function is called when an heavy-weight process (such as a child) is - * being run down or destroyed. As with the child-initialisation function, - * any information that needs to be recorded must be in static cells, since - * there's no configuration record. - * - * There is no return value. - */ - -/* - * All our process-death routine does is add its trace to the log. - */ static void ptt_child_exit(server_rec *s, pool *p) { @@ -618,439 +181,33 @@ static void ptt_child_exit(server_rec *s, pool *p) */ sname = (sname != NULL) ? sname : ""; note = ap_pstrcat(p, "ptt_child_exit(", sname, ")", NULL); - trace_add(s, NULL, NULL, note); -} - -/* - * This function gets called to create a per-directory configuration - * record. This will be called for the "default" server environment, and for - * each directory for which the parser finds any of our directives applicable. - * If a directory doesn't have any of our directives involved (i.e., they - * aren't in the .htaccess file, or a <Location>, <Directory>, or related - * block), this routine will *not* be called - the configuration for the - * closest ancestor is used. - * - * The return value is a pointer to the created module-specific - * structure. - */ -static void *ptt_create_dir_config(pool *p, char *dirspec) -{ - - excfg *cfg; - char *dname = dirspec; - - /* - * Allocate the space for our record from the pool supplied. - */ - cfg = (excfg *) ap_pcalloc(p, sizeof(excfg)); - /* - * Now fill in the defaults. If there are any `parent' configuration - * records, they'll get merged as part of a separate callback. - */ - cfg->local = 0; - cfg->congenital = 0; - cfg->cmode = CONFIG_MODE_DIRECTORY; - /* - * Finally, add our trace to the callback list. - */ - dname = (dname != NULL) ? dname : ""; - cfg->loc = ap_pstrcat(p, "DIR(", dname, ")", NULL); - trace_add(NULL, NULL, cfg, "ptt_create_dir_config()"); - return (void *) cfg; -} - -/* - * This function gets called to merge two per-directory configuration - * records. This is typically done to cope with things like .htaccess files - * or <Location> directives for directories that are beneath one for which a - * configuration record was already created. The routine has the - * responsibility of creating a new record and merging the contents of the - * other two into it appropriately. If the module doesn't declare a merge - * routine, the record for the closest ancestor location (that has one) is - * used exclusively. - * - * The routine MUST NOT modify any of its arguments! - * - * The return value is a pointer to the created module-specific structure - * containing the merged values. - */ -static void *ptt_merge_dir_config(pool *p, void *parent_conf, - void *newloc_conf) -{ - - excfg *merged_config = (excfg *) ap_pcalloc(p, sizeof(excfg)); - excfg *pconf = (excfg *) parent_conf; - excfg *nconf = (excfg *) newloc_conf; - char *note; - - /* - * Some things get copied directly from the more-specific record, rather - * than getting merged. - */ - merged_config->local = nconf->local; - merged_config->loc = ap_pstrdup(p, nconf->loc); - /* - * Others, like the setting of the `congenital' flag, get ORed in. The - * setting of that particular flag, for instance, is TRUE if it was ever - * true anywhere in the upstream configuration. - */ - merged_config->congenital = (pconf->congenital | pconf->local); - /* - * If we're merging records for two different types of environment (server - * and directory), mark the new record appropriately. Otherwise, inherit - * the current value. - */ - merged_config->cmode = - (pconf->cmode == nconf->cmode) ? pconf->cmode : CONFIG_MODE_COMBO; - /* - * Now just record our being called in the trace list. Include the - * locations we were asked to merge. - */ - note = ap_pstrcat(p, "ptt_merge_dir_config(\"", pconf->loc, "\",\"", - nconf->loc, "\")", NULL); - trace_add(NULL, NULL, merged_config, note); - return (void *) merged_config; -} - -/* - * This function gets called to create a per-server configuration - * record. It will always be called for the "default" server. - * - * The return value is a pointer to the created module-specific - * structure. - */ -static void *ptt_create_server_config(pool *p, server_rec *s) -{ - - excfg *cfg; - char *sname = s->server_hostname; - - /* - * As with the ptt_create_dir_config() reoutine, we allocate and fill - * in an empty record. - */ - cfg = (excfg *) ap_pcalloc(p, sizeof(excfg)); - cfg->local = 0; - cfg->congenital = 0; - cfg->cmode = CONFIG_MODE_SERVER; - /* - * Note that we were called in the trace list. - */ - sname = (sname != NULL) ? sname : ""; - cfg->loc = ap_pstrcat(p, "SVR(", sname, ")", NULL); - trace_add(s, NULL, cfg, "ptt_create_server_config()"); - return (void *) cfg; -} - -/* - * This function gets called to merge two per-server configuration - * records. This is typically done to cope with things like virtual hosts and - * the default server configuration The routine has the responsibility of - * creating a new record and merging the contents of the other two into it - * appropriately. If the module doesn't declare a merge routine, the more - * specific existing record is used exclusively. - * - * The routine MUST NOT modify any of its arguments! - * - * The return value is a pointer to the created module-specific structure - * containing the merged values. - */ -static void *ptt_merge_server_config(pool *p, void *server1_conf, - void *server2_conf) -{ - - excfg *merged_config = (excfg *) ap_pcalloc(p, sizeof(excfg)); - excfg *s1conf = (excfg *) server1_conf; - excfg *s2conf = (excfg *) server2_conf; - char *note; - - /* - * Our inheritance rules are our own, and part of our module's semantics. - * Basically, just note whence we came. - */ - merged_config->cmode = - (s1conf->cmode == s2conf->cmode) ? s1conf->cmode : CONFIG_MODE_COMBO; - merged_config->local = s2conf->local; - merged_config->congenital = (s1conf->congenital | s1conf->local); - merged_config->loc = ap_pstrdup(p, s2conf->loc); - /* - * Trace our call, including what we were asked to merge. - */ - note = ap_pstrcat(p, "ptt_merge_server_config(\"", s1conf->loc, "\",\"", - s2conf->loc, "\")", NULL); - trace_add(NULL, NULL, merged_config, note); - return (void *) merged_config; -} - -/* - * This routine is called after the request has been read but before any other - * phases have been processed. This allows us to make decisions based upon - * the input header fields. - * - * The return value is OK, DECLINED, or HTTP_mumble. If we return OK, no - * further modules are called for this phase. - */ -static int ptt_post_read_request(request_rec *r) -{ - - excfg *cfg; - - cfg = our_dconfig(r); - /* - * We don't actually *do* anything here, except note the fact that we were - * called. - */ - trace_add(r->server, r, cfg, "ptt_post_read_request()"); - return DECLINED; -} - -/* - * This routine gives our module an opportunity to translate the URI into an - * actual filename. If we don't do anything special, the server's default - * rules (Alias directives and the like) will continue to be followed. - * - * The return value is OK, DECLINED, or HTTP_mumble. If we return OK, no - * further modules are called for this phase. - */ -static int ptt_translate_handler(request_rec *r) -{ - - excfg *cfg; - - cfg = our_dconfig(r); - /* - * We don't actually *do* anything here, except note the fact that we were - * called. - */ - trace_add(r->server, r, cfg, "ptt_translate_handler()"); - return DECLINED; -} - -/* - * This routine is called to check the authentication information sent with - * the request (such as looking up the user in a database and verifying that - * the [encrypted] password sent matches the one in the database). - * - * The return value is OK, DECLINED, or some HTTP_mumble error (typically - * HTTP_UNAUTHORIZED). If we return OK, no other modules are given a chance - * at the request during this phase. - */ -static int ptt_check_user_id(request_rec *r) -{ - - excfg *cfg; - - cfg = our_dconfig(r); - /* - * Don't do anything except log the call. - */ - trace_add(r->server, r, cfg, "ptt_check_user_id()"); - return DECLINED; -} - -/* - * This routine is called to check to see if the resource being requested - * requires authorisation. - * - * The return value is OK, DECLINED, or HTTP_mumble. If we return OK, no - * other modules are called during this phase. - * - * If *all* modules return DECLINED, the request is aborted with a server - * error. - */ -static int ptt_auth_checker(request_rec *r) -{ - - excfg *cfg; - - cfg = our_dconfig(r); - /* - * Log the call and return OK, or access will be denied (even though we - * didn't actually do anything). - */ - trace_add(r->server, r, cfg, "ptt_auth_checker()"); - return DECLINED; -} - -/* - * This routine is called to check for any module-specific restrictions placed - * upon the requested resource. (See the mod_access module for an example.) - * - * The return value is OK, DECLINED, or HTTP_mumble. All modules with an - * handler for this phase are called regardless of whether their predecessors - * return OK or DECLINED. The first one to return any other status, however, - * will abort the sequence (and the request) as usual. - */ -static int ptt_access_checker(request_rec *r) -{ - - excfg *cfg; - - cfg = our_dconfig(r); - trace_add(r->server, r, cfg, "ptt_access_checker()"); - return DECLINED; -} - -/* - * This routine is called to determine and/or set the various document type - * information bits, like Content-type (via r->content_type), language, et - * cetera. - * - * The return value is OK, DECLINED, or HTTP_mumble. If we return OK, no - * further modules are given a chance at the request for this phase. - */ -static int ptt_type_checker(request_rec *r) -{ - - excfg *cfg; - - cfg = our_dconfig(r); - /* - * Log the call, but don't do anything else - and report truthfully that - * we didn't do anything. - */ - trace_add(r->server, r, cfg, "ptt_type_checker()"); - return DECLINED; -} - -/* - * This routine is called to perform any module-specific fixing of header - * fields, et cetera. It is invoked just before any content-handler. - * - * The return value is OK, DECLINED, or HTTP_mumble. If we return OK, the - * server will still call any remaining modules with an handler for this - * phase. - */ -static int ptt_fixer_upper(request_rec *r) -{ - - excfg *cfg; - - cfg = our_dconfig(r); - /* - * Log the call and exit. - */ - trace_add(r->server, r, cfg, "ptt_fixer_upper()"); - return OK; -} - -/* - * This routine is called to perform any module-specific logging activities - * over and above the normal server things. - * - * The return value is OK, DECLINED, or HTTP_mumble. If we return OK, any - * remaining modules with an handler for this phase will still be called. - */ -static int ptt_logger(request_rec *r) -{ - - excfg *cfg; - - cfg = our_dconfig(r); - trace_add(r->server, r, cfg, "ptt_logger()"); - return DECLINED; -} - -/* - * This routine is called to give the module a chance to look at the request - * headers and take any appropriate specific actions early in the processing - * sequence. - * - * The return value is OK, DECLINED, or HTTP_mumble. If we return OK, any - * remaining modules with handlers for this phase will still be called. - */ -static int ptt_header_parser(request_rec *r) -{ - - excfg *cfg; - - cfg = our_dconfig(r); - trace_add(r->server, r, cfg, "ptt_header_parser()"); - return DECLINED; } -/*--------------------------------------------------------------------------*/ -/* */ -/* All of the routines have been declared now. Here's the list of */ -/* directives specific to our module, and information about where they */ -/* may appear and how the command parser should pass them to us for */ -/* processing. Note that care must be taken to ensure that there are NO */ -/* collisions of directive names between modules. */ -/* */ -/*--------------------------------------------------------------------------*/ -/* - * List of directives specific to our module. - */ -static const command_rec ptt_cmds[] = -{ - { - "ptt", /* directive name */ - cmd_ptt, /* config action routine */ - NULL, /* argument to include in call */ - OR_OPTIONS, /* where available */ - NO_ARGS, /* arguments */ - "Example directive - no arguments" - /* directive description */ - }, - {NULL} -}; - -/*--------------------------------------------------------------------------*/ -/* */ -/* Now the list of content handlers available from this module. */ -/* */ -/*--------------------------------------------------------------------------*/ -/* - * List of content handlers our module supplies. Each handler is defined by - * two parts: a name by which it can be referenced (such as by - * {Add,Set}Handler), and the actual routine name. The list is terminated by - * a NULL block, since it can be of variable length. - * - * Note that content-handlers are invoked on a most-specific to least-specific - * basis; that is, a handler that is declared for "text/plain" will be - * invoked before one that was declared for "text / *". Note also that - * if a content-handler returns anything except DECLINED, no other - * content-handlers will be called. - */ static const handler_rec ptt_handlers[] = { - {"ptt-handler", ptt_handler}, + {"ptt_h", ptt_handler}, {NULL} }; -/*--------------------------------------------------------------------------*/ -/* */ -/* Finally, the list of callback routines and data structures that */ -/* provide the hooks into our module from the other parts of the server. */ -/* */ -/*--------------------------------------------------------------------------*/ -/* - * Module definition for configuration. If a particular callback is not - * needed, replace its routine name below with the word NULL. - * - * The number in brackets indicates the order in which the routine is called - * during request processing. Note that not all routines are necessarily - * called (such as if a resource doesn't have access restrictions). - */ module MODULE_VAR_EXPORT ptt_module = { STANDARD_MODULE_STUFF, - ptt_init, /* module initializer */ - ptt_create_dir_config, /* per-directory config creator */ - ptt_merge_dir_config, /* dir config merger */ - ptt_create_server_config, /* server config creator */ - ptt_merge_server_config, /* server config merger */ - ptt_cmds, /* command table */ + NULL, /* module initializer */ + NULL, /* per-directory config creator */ + NULL, /* dir config merger */ + NULL, /* server config creator */ + NULL, /* server config merger */ + NULL, /* command table */ ptt_handlers, /* [9] list of handlers */ - ptt_translate_handler, /* [2] filename-to-URI translation */ - ptt_check_user_id, /* [5] check/validate user_id */ - ptt_auth_checker, /* [6] check user_id is valid *here* */ - ptt_access_checker, /* [4] check access by host address */ - ptt_type_checker, /* [7] MIME type checker/setter */ - ptt_fixer_upper, /* [8] fixups */ - ptt_logger, /* [10] logger */ + NULL, /* [2] filename-to-URI translation */ + NULL, /* [5] check/validate user_id */ + NULL, /* [6] check user_id is valid *here* */ + NULL, /* [4] check access by host address */ + NULL, /* [7] MIME type checker/setter */ + NULL, /* [8] fixups */ + NULL, /* [10] logger */ #if MODULE_MAGIC_NUMBER >= 19970103 - ptt_header_parser, /* [3] header parser */ + NULL, /* [3] header parser */ #endif #if MODULE_MAGIC_NUMBER >= 19970719 ptt_child_init, /* process initializer */ @@ -1059,6 +216,6 @@ module MODULE_VAR_EXPORT ptt_module = ptt_child_exit, /* process exit/cleanup */ #endif #if MODULE_MAGIC_NUMBER >= 19970902 - ptt_post_read_request /* [1] post read_request handling */ + NULL #endif }; diff --git a/pttbbs/web/util_cache.c b/pttbbs/web/util_cache.c index 5178dad5..7bfb67cc 100755 --- a/pttbbs/web/util_cache.c +++ b/pttbbs/web/util_cache.c @@ -1,4 +1,4 @@ -/* $Id: util_cache.c,v 1.1 2002/10/18 14:43:58 ptt Exp $ */ +/* $Id: util_cache.c,v 1.2 2003/03/24 20:44:09 ptt Exp $ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -316,6 +316,10 @@ static void reload_bcache() { if(SHM->Bbusystate) { safe_sleep(1); } + else{ + puts("bcache is not loaded? resolve_boards() fail"); + exit(1); + } } void resolve_boards() { diff --git a/pttbbs/web/util_passwd.c b/pttbbs/web/util_passwd.c index 03e90f6c..6fa94302 100755 --- a/pttbbs/web/util_passwd.c +++ b/pttbbs/web/util_passwd.c @@ -1,4 +1,4 @@ -/* $Id: util_passwd.c,v 1.1 2002/10/18 14:43:58 ptt Exp $ */ +/* $Id: util_passwd.c,v 1.2 2003/03/24 20:44:09 ptt Exp $ */ #include <stdio.h> #include <string.h> #include <fcntl.h> @@ -36,7 +36,7 @@ static userec_t *passwd_image = NULL; static int passwd_image_size; static int semid = -1; -int passwd_mmap() { +int passwd_mmap(void) { int fd; if(passwd_image!=NULL) return 0; diff --git a/pttbbs/web/util_record.c b/pttbbs/web/util_record.c index bc74d575..93d060e0 100755 --- a/pttbbs/web/util_record.c +++ b/pttbbs/web/util_record.c @@ -1,5 +1,6 @@ -/* $Id: util_record.c,v 1.1 2002/10/18 14:43:58 ptt Exp $ */ +/* $Id: util_record.c,v 1.2 2003/03/24 20:44:09 ptt Exp $ */ #include <stdio.h> +#include <stdlib.h> #include <errno.h> #include <string.h> #include <unistd.h> -- cgit v1.2.3 From 43368a1231f54df5cae1b71d5c240504ff92f9a6 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Wed, 26 Mar 2003 10:22:42 +0000 Subject: CRITICAL_MEMORY git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@712 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/include/proto.h | 10 +++++++++- pttbbs/mbbsd/stuff.c | 27 ++++++++++++++++++++++++++- 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/pttbbs/include/proto.h b/pttbbs/include/proto.h index 0fb19043..ef5693cc 100644 --- a/pttbbs/include/proto.h +++ b/pttbbs/include/proto.h @@ -1,4 +1,4 @@ -/* $Id: proto.h,v 1.37 2003/02/12 14:31:36 victor Exp $ */ +/* $Id: proto.h,v 1.38 2003/03/26 10:21:29 in2 Exp $ */ #ifndef INCLUDE_PROTO_H #define INCLUDE_PROTO_H @@ -449,6 +449,13 @@ int not_alpha(char ch); int valid_ident(char *ident); int userid_is_BM(char *userid, char *list); int is_uBM(char *list, char *id); +#ifndef CRITICAL_MEMORY + #define MALLOC(p) malloc(p) + #define FREE(p) free(p) +#else + void *MALLOC(int size); + void FREE(void *ptr); +#endif /* syspost */ int post_msg(char* bname, char* title, char *msg, char* author); @@ -583,4 +590,5 @@ void touchbtotal(int bid); /* util_cache.c */ void reload_pttcache(void); + #endif diff --git a/pttbbs/mbbsd/stuff.c b/pttbbs/mbbsd/stuff.c index 41d5d93e..f79ec1ae 100644 --- a/pttbbs/mbbsd/stuff.c +++ b/pttbbs/mbbsd/stuff.c @@ -1,4 +1,4 @@ -/* $Id: stuff.c,v 1.10 2003/01/16 11:58:04 kcwu Exp $ */ +/* $Id: stuff.c,v 1.11 2003/03/26 10:22:42 in2 Exp $ */ #include "bbs.h" /* ----------------------------------------------------- */ @@ -613,3 +613,28 @@ show_help(char *helptext[]) } pressanykey(); } + +/* ----------------------------------------------------- */ +/* use mmap() to malloc large memory in CRITICAL_MEMORY */ +/* ----------------------------------------------------- */ +#ifdef CRITICAL_MEMORY +void *MALLOC(int size) +{ + int *p; + p = (int *)mmap(NULL, (size + 4), PROT_READ | PROT_WRITE, MAP_ANON, -1, 0); + p[0] = size; +#ifdef DEBUG + vmsg("critical malloc %d bytes", size); +#endif + return (void *)&p[1]; +} + +void FREE(void *ptr) +{ + int size = ((int *)ptr)[-1]; + munmap((void *)(&(((int *)ptr)[-1])), size); +#ifdef DEBUG + vmsg("critical free %d bytes", size); +#endif +} +#endif -- cgit v1.2.3 From 8953bbd2c87d363881095cf639743fce972daa93 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Wed, 26 Mar 2003 10:22:54 +0000 Subject: customize git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@713 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/user.c | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 61 insertions(+), 3 deletions(-) diff --git a/pttbbs/mbbsd/user.c b/pttbbs/mbbsd/user.c index 364a0420..3c1ad1e6 100644 --- a/pttbbs/mbbsd/user.c +++ b/pttbbs/mbbsd/user.c @@ -1,4 +1,4 @@ -/* $Id: user.c,v 1.49 2003/03/10 05:55:26 in2 Exp $ */ +/* $Id: user.c,v 1.50 2003/03/26 10:22:54 in2 Exp $ */ #include "bbs.h" static char *sex[8] = { @@ -194,6 +194,60 @@ violate_law(userec_t * u, int unum) pressanykey(); } +static void Customize(void) +{ + char ans[4], done = 0, mindbuf[5]; + char *wm[3] = {"一般", "進階", "未來"}; + + showtitle("個人化設定", "個人化設定"); + memcpy(mindbuf, &currutmp->mind, 4); + mindbuf[4] = 0; + while( !done ){ + move(2, 0); + prints("您目前的個人化設定: "); + move(4, 0); + prints("%-30s%10s\n", "A. 水球模式", + wm[(cuser.uflag2 & WATER_MASK)]); + prints("%-30s%10s\n", "B. 接受站外信", + ((cuser.userlevel & PERM_NOOUTMAIL) ? "否" : "是")); + prints("%-30s%10s\n", "C. 新板自動進我的最愛", + ((cuser.uflag2 & FAVNEW_FLAG) ? "是" : "否")); + prints("%-30s%10s\n", "D. 目前的心情", mindbuf); + getdata(b_lines - 1, 0, "請按 [A-5] 切換設定,按 [Return] 結束:", + ans, sizeof(ans), DOECHO); + + switch( ans[0] ){ + case 'a':{ + int currentset = cuser.uflag2 & WATER_MASK; + currentset = (currentset + 1) % 3; + cuser.uflag2 &= ~WATER_MASK; + cuser.uflag2 |= currentset; + vmsg("修正水球模式後請正常離線再重新上線"); + } + break; + case 'b': + cuser.userlevel ^= PERM_NOOUTMAIL; + break; + case 'c': + cuser.uflag2 ^= FAVNEW_FLAG; + break; + case 'd':{ + getdata(b_lines - 1, 0, "現在的心情? ", + mindbuf, sizeof(mindbuf), DOECHO); + if (strcmp(mindbuf, "通緝") == 0) + vmsg("不可以把自己設通緝啦!"); + else if (strcmp(mindbuf, "壽星") == 0) + vmsg("你不是今天生日欸!"); + else + memcpy(currutmp->mind, mindbuf, 4); + } + break; + default: + done = 1; + } + } + pressanykey(); +} void uinfo_query(userec_t * u, int real, int unum) @@ -215,10 +269,10 @@ uinfo_query(userec_t * u, int real, int unum) getdata(b_lines - 1, 0, real ? "(1)改資料(2)設密碼(3)設權限(4)砍帳號(5)改ID" "(6)殺/復活寵物(7)審判 [0]結束 " : - "請選擇 (1)修改資料 (2)設定密碼 ==> [0]結束 ", + "請選擇 (1)修改資料 (2)設定密碼 (C) 個人化設定 ==> [0]結束 ", ans, sizeof(ans), DOECHO); - if (ans[0] > '2' && !real) + if (ans[0] > '2' && ans[0] != 'C' && ans[0] != 'c' && !real) ans[0] = '0'; if (ans[0] == '1' || ans[0] == '3') { @@ -229,6 +283,10 @@ uinfo_query(userec_t * u, int real, int unum) outs(x.userid); } switch (ans[0]) { + case 'C': + case 'c': + Customize(); + return; case '7': violate_law(&x, unum); return; -- cgit v1.2.3 From 5dda1a33e92eb1fc4cd791628490a0be1833afd4 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Wed, 26 Mar 2003 10:23:01 +0000 Subject: FAVng git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@714 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/include/pttstruct.h | 13 +- pttbbs/mbbsd/board.c | 668 ++++++++++++++++++++++++++++++++------------- 2 files changed, 478 insertions(+), 203 deletions(-) diff --git a/pttbbs/include/pttstruct.h b/pttbbs/include/pttstruct.h index 898d4447..d424d24d 100644 --- a/pttbbs/include/pttstruct.h +++ b/pttbbs/include/pttstruct.h @@ -1,4 +1,4 @@ -/* $Id: pttstruct.h,v 1.29 2003/02/10 17:41:45 in2 Exp $ */ +/* $Id: pttstruct.h,v 1.30 2003/03/26 10:21:40 in2 Exp $ */ #ifndef INCLUDE_STRUCT_H #define INCLUDE_STRUCT_H @@ -86,11 +86,12 @@ typedef struct userec_t { #define MOVIE_FLAG 0x40 /* true if show movie */ #define COLOR_FLAG 0x80 /* true if the color mode open */ #define MIND_FLAG 0x100 /* true if mind search mode open <-Heat*/ +#define FAVNEW_FLAG 0x20 /* true if add new board into one's fav */ /* these are flags in userec_t.uflag2 */ #define WATER_MASK 000003 /* water mask */ -#define WATER_ORIG 0 -#define WATER_NEW 1 -#define WATER_OFO 2 +#define WATER_ORIG 0x0 +#define WATER_NEW 0x1 +#define WATER_OFO 0x2 #define WATERMODE(mode) ((cuser.uflag2 & WATER_MASK) == mode) @@ -191,8 +192,8 @@ typedef struct { int num, page, now, level; } gmenu_t; -#define FAVMAX 74 /* Max boards of Myfavorite */ -#define FAVGMAX 16 /* Max groups of Myfavorite */ +#define FAVMAX 1024 /* Max boards of Myfavorite */ +#define FAVGMAX 32 /* Max groups of Myfavorite */ #define FAVGSLEN 8 /* Max Length of Description String */ typedef struct msgque_t { diff --git a/pttbbs/mbbsd/board.c b/pttbbs/mbbsd/board.c index 7f725ea4..027bd4cc 100644 --- a/pttbbs/mbbsd/board.c +++ b/pttbbs/mbbsd/board.c @@ -1,4 +1,4 @@ -/* $Id: board.c,v 1.87 2003/03/18 14:40:17 victor Exp $ */ +/* $Id: board.c,v 1.88 2003/03/26 10:23:01 in2 Exp $ */ #include "bbs.h" #define BRC_STRLEN 15 /* Length of board name */ #define BRC_MAXSIZE 24576 @@ -209,10 +209,11 @@ brc_unread(char *fname, int bnum, int *blist) } #define BRD_UNREAD 1 -#define BRD_FAV 2 -#define BRD_ZAP 4 -#define BRD_TAG 8 +#define BRD_FAV 2 +#define BRD_LINE 4 +#define BRD_TAG 8 +#define FAVNB ".favnb" #define B_TOTAL(bptr) (SHM->total[(bptr)->bid - 1]) #define B_LASTPOSTTIME(bptr) (SHM->lastposttime[(bptr)->bid - 1]) #define B_BH(bptr) (&bcache[(bptr)->bid - 1]) @@ -221,86 +222,286 @@ typedef struct { unsigned char myattr; } __attribute__ ((packed)) boardstat_t; -static int *zapbuf = NULL; -static char *favbuf = NULL; +typedef struct { + short bid; + char attr; + time_t lastvisit; +} fav_board_t; + +typedef struct { +#ifdef MEM_CHECK + int memcheck; +#endif + short nDatas; + short nAllocs; + char nLines; + fav_board_t b[0]; +} fav_t; + static boardstat_t *nbrd = NULL; -char zapchange = 0, favchange = 0, choose_board_depth = 0; +char favchange = 0, choose_board_depth = 0; +fav_t *fav; +static short brdnum; +static char yank_flag = 1; -#define STR_BBSRC ".bbsrc" -#define STR_FAV2 ".fav2" +int cmpfav(const void *a, const void *b) +{ + if( *(short *)a > ((fav_board_t *)b)->bid ) + return 1; + else if( *(short *)a == ((fav_board_t *)b)->bid ) + return 0; + return -1; +} -#ifndef CRITICAL_MEMORY - #define MALLOC(p) malloc(p) - #define FREE(p) free(p) -#else -void *MALLOC(int size) +fav_board_t *getfav(short bid) { - int *p; - p = (int *)mmap(NULL, (size + 4), PROT_READ | PROT_WRITE, MAP_ANON, -1, 0); - p[0] = size; -#ifdef DEBUG - vmsg("critical malloc %d bytes", size); -#endif - return (void *)&p[1]; + int i; + for(i = 0; i < fav->nDatas; i++) + if(fav->b[i].bid == bid) + break; + return i == fav->nDatas ? NULL : &fav->b[i]; } -void FREE(void *ptr) +char getfavattr(short bid) { - int size = ((int *)ptr)[-1]; - munmap((void *)(&(((int *)ptr)[-1])), size); -#ifdef DEBUG - vmsg("critical free %d bytes", size); -#endif + fav_board_t *ptr = getfav(bid); + if( ptr == NULL ) + return 0; // default here + else + return ptr->attr; } -#endif -void load_brdbuf(void) +time_t getfavtime(short bid) { - static char firsttime = 1; - int fd, size, favsize, i; - char fname[80]; + fav_board_t *ptr = getfav(bid); + if( ptr == NULL ) + return login_start_time; // default here + else + return ptr->lastvisit; +} - size = (numboards + 32) * sizeof(int); - favsize = (numboards + 32) * sizeof(char); -#ifdef MEM_CHECK - size += sizeof(int); - favsize += sizeof(int); -#endif +void movefav(int old, int new) +{ + boardstat_t tmp; + fav_board_t *des, *src, *ptr1, *ptr2, t; + + if( !(src = getfav(nbrd[old].bid)) || !(des = getfav(nbrd[new].bid)) ) + return; + + t = *src; + tmp = nbrd[old]; + if(new < old){ + for(ptr1 = ptr2 = src; ptr1 > des && ptr2 > des; ptr1--) + if(ptr1->attr & BRD_FAV){ + *ptr2 = *(ptr1 - 1); + ptr2--; + while(ptr2 > des && !(ptr2->attr & BRD_FAV)) + ptr2--; + } + for( ; old > new; old--) + nbrd[old] = nbrd[old - 1]; + } + else{ + for(ptr1 = ptr2 = src; ptr1 < des && ptr2 < des; ptr1++) + if(ptr1->attr & BRD_FAV){ + *ptr2 = *(ptr1 + 1); + ptr2++; + while(ptr2 < des && !(ptr2->attr & BRD_FAV)) + ptr2++; + } + for( ; old < new; old++) + nbrd[old] = nbrd[old + 1]; + } + nbrd[new] = tmp; + *des = t; +} - zapbuf = (int *)malloc(size); - favbuf = (char *)malloc(favsize); +void delfavline(int bid, int num) +{ + int i; + + movefav(num, --brdnum); + fav->nLines++; + fav->nDatas--; + + for(i = 0; i < fav->nDatas; i++) + if(fav->b[i].bid < bid) + fav->b[i].bid++; + for(i = 0; i < brdnum; i++) + if(nbrd[i].bid < bid) + nbrd[i].bid++; +} -#ifdef MEM_CHECK - zapbuf[0] = MEM_CHECK; - zapbuf = &zapbuf[1]; - ((int *)favbuf)[0] = MEM_CHECK; - favbuf = &favbuf[ sizeof(int) ]; - size -= sizeof(int); - favsize -= sizeof(int); +void setfav(short bid, char attr, char mode, time_t t) +{ + /* mode: 0: 設成 off, 1: 設成 on, 2: 反相 */ + fav_board_t *ptr = getfav(bid); + if( ptr != NULL ){ + if( mode == 2 ) + ptr->attr ^= attr; + else if( mode ) + ptr->attr |= attr; + else + ptr->attr &= ~attr; + if( t ) + ptr->lastvisit = t; + } + else{ + int where; + if( fav->nDatas == fav->nAllocs ){ +#ifdef DEBUG + vmsg("realloc fav"); #endif - zapchange = favchange = 0; + fav = realloc(fav, + sizeof(fav_t) + + sizeof(fav_board_t) * + (16 + fav->nAllocs)); + fav->nAllocs += 16; + } - if( firsttime ){ - memset(favbuf, 0, favsize); - for( i = (numboards + 32) - 1 ; i >= 0 ; --i ) - zapbuf[i] = login_start_time; + // insertion sort: + if(!(attr & BRD_LINE)){ + for( where = 0 ; where < fav->nDatas ; ++where ) + if( fav->b[where].bid > bid ) + break; + if( where != fav->nDatas ){ + int i; + for( i = fav->nDatas - 1 ; i >= where ; --i ) + fav->b[i + 1] = fav->b[i]; + } + + fav->b[where].bid = bid ; + fav->b[where].attr = mode ? attr : 0; + } + else{ + where = fav->nDatas; + fav->b[where].bid = --(fav->nLines); + fav->b[where].attr = attr; + } + + fav->b[where].lastvisit = t ? t : login_start_time; + fav->nDatas++; } +} - setuserfile(fname, STR_BBSRC); - if ((fd = open(fname, O_RDONLY, 0600)) != -1) { - read(fd, zapbuf, size); - close(fd); +void imovefav(int old) +{ + char buf[5]; + int new; + + getdata(b_lines - 1, 0, "請輸入新次序:", buf, sizeof(buf), DOECHO); + new = atoi(buf) - 1; + if (new < 0 || brdnum <= new){ + vmsg("輸入範圍有誤!"); + return; } - setuserfile(fname, STR_FAV2); - if ((fd = open(fname, O_RDONLY, 0600)) != -1) { - read(fd, favbuf, favsize); + movefav(old, new); +} + +#define BRD_OLD 0 +#define BRD_NEW 1 +#define BRD_END 2 + +void updatenewfav(int mode) +{ + /* mode: 0: don't write to fav 1: write to fav */ + int i, fd; + char fname[80], *brd; + + if(!(cuser.uflag2 & FAVNEW_FLAG)) + return; + + setuserfile(fname, FAVNB); + + if( (fd = open(fname, O_RDWR, 0600)) != -1 ){ + + brd = (char *)malloc((numboards + 1) * sizeof(char)); + read(fd, brd, (numboards + 1) * sizeof(char)); + + for(i = 0; i < numboards && brd[i] != BRD_END; i++){ + if(brd[i] == BRD_NEW && Ben_Perm(&bcache[i])){ + if(mode) + setfav(i + 1, BRD_FAV, 1, 0); + brd[i] = BRD_OLD; + } + } + if( i != numboards ) + for(i-- ; i < numboards; i++){ + if(Ben_Perm(&bcache[i])){ + if(mode) + setfav(i + 1, BRD_FAV, 1, 0); + brd[i] = BRD_OLD; + } + else + brd[i] = BRD_NEW; + } + + brd[i] = BRD_END; + + lseek(fd, 0, SEEK_SET); + write(fd, brd, (numboards + 1 ) * sizeof(char)); + free(brd); close(fd); } +} - if( firsttime ){ - for (i = 0; i < numboards; i++) - favbuf[i] &= ~BRD_TAG; +void load_brdbuf(void) +{ + static char firsttime = 1; + int fd, r, w; + char fname[80]; + + setuserfile(fname, ".fav3"); + if( (fd = open(fname, O_RDONLY)) == -1 ){ + // not found. + int i; + char favrec; + fav = (fav_t *)malloc(sizeof(fav_t) + + sizeof(fav_board_t) * 16); + fav->nDatas = 0; + fav->nAllocs = 16; + fav->nLines = 0; + favchange = 1; + + setuserfile(fname, ".fav2"); + + if( (fd = open(fname, O_RDONLY)) != -1 ){ + for( i = 1; i <= numboards; i++){ + if(read(fd, &favrec, sizeof(char)) < 0) + break; + if( (favrec & BRD_FAV) ) + setfav(i, BRD_FAV, 1, 0); + } + close(fd); + } } + else{ + short nDatas; + char nLines; + read(fd, &nDatas, sizeof(nDatas)); + read(fd, &nLines, sizeof(nLines)); + fav = (fav_t *)malloc(sizeof(fav_t) + + sizeof(fav_board_t) * (nDatas + 16)); + fav->nDatas = nDatas; + fav->nAllocs = nDatas + 16; + fav->nLines = nLines; + read(fd, fav->b, sizeof(fav_board_t) * nDatas); + close(fd); + } + + // check if fav is correct + for( r = w = 0 ; r < fav->nDatas ; ++r ) + if( fav->b[r].attr & BRD_FAV ) // 須是 BRD_FAV + if( (fav->b[r].bid < 0) || // 分隔線 + (fav->b[r].bid > 0 && // bid > 0 且該看板存在 + bcache[fav->b[r].bid - 1].brdname[0]) ) + fav->b[w++] = fav->b[r]; + fav->nDatas = w; + + updatenewfav(1); +#ifdef MEM_CHECK + fav->memcheck = MEM_CHECK; +#endif firsttime = 0; } @@ -313,54 +514,36 @@ init_brdbuf() void save_brdbuf(void) { - int fd, size; - char fname[60]; - static char reentrant = 0; - - if( reentrant ) + int r, w, fd; + char fname[80]; + if( !fav ) return; - reentrant = 1; - - size = numboards * sizeof(int); - setuserfile(fname, STR_BBSRC); - if ( zapbuf != NULL ){ - if( ( -#ifdef MEM_CHECK - (unsigned)zapbuf[-1] == (unsigned)MEM_CHECK && -#endif - zapchange && - (fd = open(fname, O_WRONLY | O_CREAT, 0600)) != -1) ){ - write(fd, zapbuf, size); - close(fd); - } + /* + favchange is not implement yet + if( !favchange ) + return; + */ #ifdef MEM_CHECK - free(&zapbuf[-1]); -#else - free(zapbuf); + if( fav->memcheck != MEM_CHECK ) + return; #endif - zapbuf = NULL; - } - setuserfile(fname, STR_FAV2); - if ( favbuf != NULL ){ - if( ( -#ifdef MEM_CHECK - (unsigned)((int*)favbuf)[-1] == (unsigned)MEM_CHECK && -#endif - favchange && - (fd = open(fname, O_WRONLY | O_CREAT, 0600)) != -1) ){ - size = numboards * sizeof(char); - write(fd, favbuf, size); - close(fd); - } -#ifdef MEM_CHECK - free(&favbuf[-sizeof(int)]); -#else - free(favbuf); -#endif - favbuf = NULL; + for( r = w = 0 ; r < fav->nDatas ; ++r ) + if( fav->b[r].attr & BRD_FAV ) + fav->b[w++] = fav->b[r]; + fav->nDatas = w; + setuserfile(fname, ".fav3"); + if( (fd = open(fname, O_WRONLY | O_CREAT, 0600)) != -1 ){ + int i; + write(fd, &fav->nDatas, sizeof(short)); + write(fd, &fav->nLines, sizeof(char)); + for(i = 0; i < fav->nDatas; i++) + if(fav->b[i].attr & BRD_FAV) + write(fd, &fav->b[i], sizeof(fav_board_t)); + close(fd); } - reentrant = 0; + free(fav); + fav = NULL; } int @@ -451,8 +634,6 @@ check_newpost(boardstat_t * ptr) return 1; } -static short brdnum; -static char yank_flag = 1; static void load_uidofgid(const int gid, const int type) { @@ -483,16 +664,15 @@ load_uidofgid(const int gid, const int type) static boardstat_t * addnewbrdstat(int n, int state) { - boardstat_t *ptr = &nbrd[brdnum++]; + boardstat_t *ptr; + + ptr = &nbrd[brdnum++]; //boardheader_t *bptr = &bcache[n]; //ptr->total = &(SHM->total[n]); //ptr->lastposttime = &(SHM->lastposttime[n]); + ptr->bid = n + 1; - ptr->myattr = 0; - ptr->myattr = (favbuf[n] & ~BRD_ZAP); - if (zapbuf[n] == 0) - ptr->myattr |= BRD_ZAP; - //ptr->bh = bptr; + ptr->myattr = getfavattr(ptr->bid); if ((B_BH(ptr)->brdattr & BRD_HIDE) && state == 1) B_BH(ptr)->brdattr |= BRD_POSTMASK; check_newpost(ptr); @@ -506,13 +686,42 @@ cmpboardfriends(const void *brd, const void *tmp) (B_BH((boardstat_t*)brd)->nuser)); } +static int +favcmpboardname(const void *brd, const void *tmp) +{ + int b1 = ((fav_board_t *)brd)->bid; + int b2 = ((fav_board_t *)tmp)->bid; + + if( b1 <= 0 || b2 <= 0 ) // 分隔線 + return 1; + + return strcasecmp(bcache[b1 - 1].brdname, bcache[b2 - 1].brdname); +} + +static int +favcmpboardclass(const void *brd, const void *tmp) +{ + int b1 = ((fav_board_t *)brd)->bid; + int b2 = ((fav_board_t *)tmp)->bid; + int cmp; + + if( b1 <= 0 || b2 <= 0 ) // 分隔線 + return 1; + + cmp = strncasecmp(bcache[b1 - 1].title, bcache[b2 - 1].title, 4); + if( cmp ) + return cmp; + else + return strcasecmp(bcache[b1 - 1].brdname, bcache[b2 - 1].brdname); +} + static void load_boards(char *key) { boardheader_t *bptr = NULL; int type = cuser.uflag & BRDSORT_FLAG ? 1 : 0; - register int i, n; - register int state; + int i, n; + int state; #ifdef CRITICAL_MEMORY boardstat_t *tmpnbrd; #endif @@ -529,33 +738,44 @@ load_boards(char *key) } if (class_bid <= 0) { nbrd = (boardstat_t *) MALLOC(sizeof(boardstat_t) * numboards); - for (i = 0; i < numboards; i++) { - if ((bptr = SHM->bsorted[type][i]) == NULL) - continue; - n = (int)(bptr - bcache); - if (!bptr->brdname[0] || (yank_flag != 0 && bptr->brdattr & BRD_GROUPBOARD) || - !((state = Ben_Perm(bptr)) || (currmode & MODE_MENU)) || - (yank_flag == 0 && !(favbuf[n] & BRD_FAV)) || - (yank_flag == 1 && !zapbuf[n]) || - (key[0] && !strcasestr(bptr->title, key)) || - (class_bid == -1 && bptr->nuser < 5)) - continue; - addnewbrdstat(n, state); + if( yank_flag == 0 ){ // fav mode + for( i = 0 ; i < fav->nDatas ; ++i ){ + if( fav->b[i].attr & (BRD_FAV | BRD_LINE) ) + addnewbrdstat(fav->b[i].bid - 1, BRD_LINE); + else if (fav->b[i].attr & BRD_FAV && (state = Ben_Perm( (bptr = &bcache[ fav->b[i].bid - 1 ])))) + addnewbrdstat(fav->b[i].bid - 1, state); + } + } + else{ // general case + for (i = 0; i < numboards; i++) { + if ((bptr = SHM->bsorted[type][i]) == NULL) + continue; + n = (int)(bptr - bcache); + if (!bptr->brdname[0] || + (bptr->brdattr & BRD_GROUPBOARD) || + !((state = Ben_Perm(bptr)) || (currmode & MODE_MENU)) || + (key[0] && !strcasestr(bptr->title, key)) || + (class_bid == -1 && bptr->nuser < 5)) + continue; + addnewbrdstat(n, state); + } } if (class_bid == -1) qsort(nbrd, brdnum, sizeof(boardstat_t), cmpboardfriends); + } else { nbrd = (boardstat_t *) MALLOC(bptr->childcount * sizeof(boardstat_t)); +#if 1 for (bptr = bptr->firstchild[type]; bptr != (boardheader_t *) ~ 0; bptr = bptr->next[type]) { n = (int)(bptr - bcache); if (!((state = Ben_Perm(bptr)) || (currmode & MODE_MENU)) - || (yank_flag == 0 && !(favbuf[n] & BRD_FAV)) - || (yank_flag == 1 && !zapbuf[n]) || + || (yank_flag == 0 && !(getfavattr(n) & BRD_FAV)) || (key[0] && !strcasestr(bptr->title, key))) continue; addnewbrdstat(n, state); } +#endif } #ifndef CRITICAL_MEMORY nbrd = realloc(nbrd, sizeof(boardstat_t) * brdnum); @@ -682,6 +902,10 @@ show_brdlist(int head, int clsflag, int newflag) clrtoeol(); if (head < brdnum) { ptr = &nbrd[head++]; + if(ptr->myattr & BRD_LINE){ + prints("%5d ------------ ------------------------------------------", head, ptr->bid); + continue; + } if (class_bid == 1) prints(" "); if (!newflag) { @@ -689,30 +913,26 @@ show_brdlist(int head, int clsflag, int newflag) !(B_BH(ptr)->brdattr & BRD_HIDE) ? ' ' : (B_BH(ptr)->brdattr & BRD_POSTMASK) ? ')' : '-', (ptr->myattr & BRD_TAG) ? "D " : - (ptr->myattr & BRD_ZAP) ? "- " : (B_BH(ptr)->brdattr & BRD_GROUPBOARD) ? " " : unread[ptr->myattr & BRD_UNREAD]); - } else if (ptr->myattr & BRD_ZAP) { - ptr->myattr &= ~BRD_UNREAD; - prints(" ﹣ ﹣"); } else { if (newflag) { if ((B_BH(ptr)->brdattr & BRD_GROUPBOARD)) prints(" "); else prints("%6d%s", (int)(B_TOTAL(ptr)), - unread[ptr->myattr & BRD_UNREAD]); + unread[ptr->myattr & BRD_UNREAD]); } } if (class_bid != 1) { prints("%s%-13s\033[m%s%5.5s\033[0;37m%2.2s\033[m" - "%-34.34s", - (ptr->myattr & BRD_FAV) ? "\033[1;36m" : "", - B_BH(ptr)->brdname, - color[(unsigned int) - (B_BH(ptr)->title[1] + B_BH(ptr)->title[2] + - B_BH(ptr)->title[3] + B_BH(ptr)->title[0]) & 07], - B_BH(ptr)->title, B_BH(ptr)->title + 5, B_BH(ptr)->title + 7); + "%-34.34s", + (ptr->myattr & BRD_FAV) ? "\033[1;36m" : "", + B_BH(ptr)->brdname, + color[(unsigned int) + (B_BH(ptr)->title[1] + B_BH(ptr)->title[2] + + B_BH(ptr)->title[3] + B_BH(ptr)->title[0]) & 07], + B_BH(ptr)->title, B_BH(ptr)->title + 5, B_BH(ptr)->title + 7); if (B_BH(ptr)->brdattr & BRD_BAD) prints(" X "); @@ -749,12 +969,12 @@ static char *choosebrdhelp[] = { "(^W) 迷路了 我在哪裡", "(r)(→)(Rtn) 進入多功\能閱\讀選單", "(q)(←) 回到主選單", - "(z)(Z) 訂閱\/反訂閱\看板 訂閱\/反訂閱\所有看板", - "(y) 我的最愛/訂閱\看板/出所有看板", + "(y/Z) 我的最愛/訂閱\看板/出所有看板/訂閱\新開看板", + "(L) 加入分隔線至我的最愛", "(v/V) 通通看完/全部未讀", - "(S) 按照字母/分類排序", + "(S) 按照字母/分類排序/自訂順序(我的最愛裡)", "(t/^T/^A/^D) 標記看板/取消所有標記/ 將已標記者加入/移出我的最愛", - "(m) 把看板加入或移出我的最愛", + "(m/M) 把看板加入或移出我的最愛, 移除分隔線/搬移我的最愛", "\01小組長指令", "(E/W/B) 設定看板/設定小組備忘/開新看板", "(^P) 移動已標記看板到此分類", @@ -773,19 +993,6 @@ set_menu_BM(char *BM) static char *privateboard = "\n\n\n\n 對不起 此板目前只准看板好友進入 請先向板主申請入境許\可"; -static void -dozap(int num) -{ - boardstat_t *ptr; - ptr = &nbrd[num]; - ptr->myattr ^= BRD_ZAP; - if (B_BH(ptr)->brdattr & BRD_NOZAP) - ptr->myattr &= ~BRD_ZAP; - if (!(ptr->myattr & BRD_ZAP)) - check_newpost(ptr); - zapchange = 1; - zapbuf[ptr->bid - 1] = (ptr->myattr & BRD_ZAP ? 0 : login_start_time); -} static void choose_board(int newflag) @@ -796,7 +1003,7 @@ choose_board(int newflag) char keyword[13] = ""; setutmpmode(newflag ? READNEW : READBRD); - if( zapbuf == NULL || favbuf == NULL ) + if( fav == NULL ) load_brdbuf(); ++choose_board_depth; brdnum = 0; @@ -913,11 +1120,13 @@ choose_board(int newflag) num = brdnum - 1; break; case 't': +#if 1 ptr = &nbrd[num]; - ptr->myattr ^= BRD_TAG; favchange = 1; - favbuf[ptr->bid - 1] = ptr->myattr; + setfav(ptr->bid, BRD_TAG, 2, 0); + ptr->myattr ^= BRD_TAG; head = 9999; +#endif case KEY_DOWN: case 'n': case 'j': @@ -959,50 +1168,66 @@ choose_board(int newflag) break; case 'S': cuser.uflag ^= BRDSORT_FLAG; + if(yank_flag == 0){ + if(cuser.uflag & BRDSORT_FLAG){ + vmsg("favcmpboardclass"); + qsort(&fav->b, fav->nDatas, sizeof(fav_board_t), + favcmpboardclass); + } + else{ + vmsg("favcmpboardname"); + qsort(&fav->b, fav->nDatas, sizeof(fav_board_t), + favcmpboardname); + } + } brdnum = -1; break; case 'y': - if (class_bid == 0) - yank_flag = (yank_flag + 1) % 3; - else - yank_flag = yank_flag % 2 + 1; + yank_flag = (yank_flag + 1) % 2; brdnum = -1; break; case Ctrl('D'): - for (tmp = 0; tmp < numboards; tmp++) { - if (favbuf[tmp] & BRD_TAG) { +#if 1 + for (tmp = 0; tmp < fav->nDatas; tmp++) { + if (fav->b[tmp].attr & BRD_TAG) { favchange = 1; - favbuf[tmp] &= ~BRD_FAV; - favbuf[tmp] &= ~BRD_TAG; + fav->b[tmp].attr &= ~BRD_FAV; + fav->b[tmp].attr &= ~BRD_TAG; } +#endif } brdnum = -1; break; case Ctrl('A'): - for (tmp = 0; tmp < numboards; tmp++) { - if (favbuf[tmp] & BRD_TAG) { +#if 1 + for (tmp = 0; tmp < fav->nDatas; tmp++) { + if (fav->b[tmp].attr & BRD_TAG) { favchange = 1; - favbuf[tmp] |= BRD_FAV; - favbuf[tmp] &= ~BRD_TAG; + fav->b[tmp].attr |= BRD_FAV; + fav->b[tmp].attr &= ~BRD_TAG; } } +#endif brdnum = -1; break; case Ctrl('T'): - for (tmp = 0; tmp < numboards; tmp++) - favbuf[tmp] &= ~BRD_TAG; +#if 1 + for (tmp = 0; tmp < fav->nDatas; tmp++) + fav->b[tmp].attr &= ~BRD_TAG; favchange = 1; brdnum = -1; +#endif break; case Ctrl('P'): +#if 1 if (class_bid != 0 && (HAS_PERM(PERM_SYSOP) || (currmode & MODE_MENU))) { - for (tmp = 0; tmp < numboards; tmp++) { + for (tmp = 0; tmp < fav->nDatas; tmp++) { boardheader_t *bh = &bcache[tmp]; - if (!(favbuf[tmp] & BRD_TAG) || bh->gid == class_bid) + if (!(fav->b[tmp].attr & BRD_TAG) || bh->gid == class_bid) continue; favchange = 1; - favbuf[tmp] &= ~BRD_TAG; + fav->b[tmp].attr &= ~BRD_TAG; if (bh->gid != class_bid) { bh->gid = class_bid; substitute_record(FN_BOARD, bh, @@ -1013,46 +1238,97 @@ choose_board(int newflag) } brdnum = -1; } +#endif break; - case 'm': + case 'L': if (HAS_PERM(PERM_BASIC)) { - ptr = &nbrd[num]; - ptr->myattr ^= BRD_FAV; + if(fav->nDatas > FAVMAX){ + vmsg("你的最愛太多了啦 真花心"); + break; + } + setfav(0, BRD_FAV | BRD_LINE, 1, 0); + nbrd[brdnum].bid = fav->nLines; + nbrd[brdnum].myattr = (BRD_FAV | BRD_LINE); + movefav(brdnum++, num); favchange = 1; - favbuf[ptr->bid - 1] = ptr->myattr; head = 9999; } break; - case 'z': + case 'm': if (HAS_PERM(PERM_BASIC)) { - dozap(num); + if(nbrd[num].myattr & BRD_LINE){ + delfavline(nbrd[num].bid, num); + } + else if(fav->nDatas > FAVMAX){ + vmsg("你的最愛太多了啦 真花心"); + break; + } + else{ + setfav(nbrd[num].bid, BRD_FAV, 2, 0); + nbrd[num].myattr ^= BRD_FAV; + } + favchange = 1; head = 9999; } break; - case 'Z': /* Ptt */ + case 'M': if (HAS_PERM(PERM_BASIC)) { - for (tmp = 0; tmp < brdnum; tmp++) { - dozap(tmp); - } + imovefav(num); + favchange = 1; head = 9999; } break; + case 'z': + vmsg("嘿嘿 這個功\能已經被我的最愛取代掉了喔!"); + break; + case 'Z': + cuser.uflag2 ^= FAVNEW_FLAG; + if(cuser.uflag2 & FAVNEW_FLAG){ + int fd; + char fname[80]; + + setuserfile(fname, FAVNB); + + if( (fd = open(fname, O_RDONLY, 0600)) != -1 ){ + close(fd); + updatenewfav(0); + } + else{ + int i; + char stat; + if( (fd = open(fname, O_WRONLY | O_CREAT, 0600)) != -1 ){ + for(i = 0; i < numboards; i++){ + stat = Ben_Perm(&bcache[i]) ? BRD_OLD : BRD_NEW; + write(fd, &stat, sizeof(char)); + } + stat = BRD_END; + write(fd, &stat, sizeof(char)); + close(fd); + } + } + } + vmsg((cuser.uflag2 & FAVNEW_FLAG) ? "切換為訂閱\新看板模式" : "切換為正常模式"); + break; case 'v': case 'V': +#if 1 ptr = &nbrd[num]; brc_initial(B_BH(ptr)->brdname); if (ch == 'v') { ptr->myattr &= ~BRD_UNREAD; - zapchange = 1; - zapbuf[ptr->bid - 1] = brc_list[0] = now; + favchange = 1; + brc_list[0] = now; + setfav(ptr->bid, 0, 0, now); } else { - zapchange = 1; - zapbuf[ptr->bid - 1] = brc_list[0] = 1; + favchange = 1; + brc_list[0] = 1; + setfav(ptr->bid, 0, 0, 1); ptr->myattr |= BRD_UNREAD; } brc_num = brc_changed = 1; brc_update(); show_brdlist(head, 0, newflag); +#endif break; case 's': if ((tmp = search_board()) == -1) { @@ -1100,6 +1376,8 @@ choose_board(int newflag) char buf[STRLEN]; ptr = &nbrd[num]; + if(ptr->myattr & BRD_LINE) + break; if (!(B_BH(ptr)->brdattr & BRD_GROUPBOARD)) { /* 非sub class */ if (!(B_BH(ptr)->brdattr & BRD_HIDE) || @@ -1112,11 +1390,7 @@ choose_board(int newflag) head = tmp - t_lines / 2; getkeep(buf, head > 1 ? head : 1, tmp + 1); } - board_visit_time = zapbuf[ptr->bid - 1]; - if (!(ptr->myattr & BRD_ZAP)){ - zapchange = 1; - zapbuf[ptr->bid - 1] = now; - } + board_visit_time = getfavtime(ptr->bid); Read(); check_newpost(ptr); head = -1; -- cgit v1.2.3 From bbfce6b6f815a957b7e19eae3983797e77e88d92 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Wed, 26 Mar 2003 10:30:59 +0000 Subject: remove debug message git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@715 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/board.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/pttbbs/mbbsd/board.c b/pttbbs/mbbsd/board.c index 027bd4cc..e5e0460e 100644 --- a/pttbbs/mbbsd/board.c +++ b/pttbbs/mbbsd/board.c @@ -1,4 +1,4 @@ -/* $Id: board.c,v 1.88 2003/03/26 10:23:01 in2 Exp $ */ +/* $Id: board.c,v 1.89 2003/03/26 10:30:59 in2 Exp $ */ #include "bbs.h" #define BRC_STRLEN 15 /* Length of board name */ #define BRC_MAXSIZE 24576 @@ -903,7 +903,7 @@ show_brdlist(int head, int clsflag, int newflag) if (head < brdnum) { ptr = &nbrd[head++]; if(ptr->myattr & BRD_LINE){ - prints("%5d ------------ ------------------------------------------", head, ptr->bid); + prints("%5d ------------ ------------------------------------------", head); continue; } if (class_bid == 1) @@ -1169,16 +1169,12 @@ choose_board(int newflag) case 'S': cuser.uflag ^= BRDSORT_FLAG; if(yank_flag == 0){ - if(cuser.uflag & BRDSORT_FLAG){ - vmsg("favcmpboardclass"); + if(cuser.uflag & BRDSORT_FLAG) qsort(&fav->b, fav->nDatas, sizeof(fav_board_t), favcmpboardclass); - } - else{ - vmsg("favcmpboardname"); + else qsort(&fav->b, fav->nDatas, sizeof(fav_board_t), favcmpboardname); - } } brdnum = -1; break; -- cgit v1.2.3 From f13ba123a3159ccb1515d1ba3cb49b8e0892f5ae Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Wed, 26 Mar 2003 10:51:15 +0000 Subject: security fix git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@716 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/board.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/pttbbs/mbbsd/board.c b/pttbbs/mbbsd/board.c index e5e0460e..f45c9815 100644 --- a/pttbbs/mbbsd/board.c +++ b/pttbbs/mbbsd/board.c @@ -1,4 +1,4 @@ -/* $Id: board.c,v 1.89 2003/03/26 10:30:59 in2 Exp $ */ +/* $Id: board.c,v 1.90 2003/03/26 10:51:15 in2 Exp $ */ #include "bbs.h" #define BRC_STRLEN 15 /* Length of board name */ #define BRC_MAXSIZE 24576 @@ -740,10 +740,15 @@ load_boards(char *key) nbrd = (boardstat_t *) MALLOC(sizeof(boardstat_t) * numboards); if( yank_flag == 0 ){ // fav mode for( i = 0 ; i < fav->nDatas ; ++i ){ - if( fav->b[i].attr & (BRD_FAV | BRD_LINE) ) - addnewbrdstat(fav->b[i].bid - 1, BRD_LINE); - else if (fav->b[i].attr & BRD_FAV && (state = Ben_Perm( (bptr = &bcache[ fav->b[i].bid - 1 ])))) - addnewbrdstat(fav->b[i].bid - 1, state); + if( fav->b[i].attr & BRD_FAV ){ + if( fav->b[i].attr & BRD_LINE ) + addnewbrdstat(fav->b[i].bid - 1, BRD_LINE); + else{ + bptr = &bcache[ fav->b[i].bid - 1 ]; + if( (state = Ben_Perm(bptr)) ) + addnewbrdstat(fav->b[i].bid - 1, state); + } + } } } else{ // general case -- cgit v1.2.3 From 68995d4a451a1e4e76b3ce80636d64419b299854 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Wed, 26 Mar 2003 11:06:05 +0000 Subject: user could set if hilight favorite git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@717 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/include/pttstruct.h | 5 +++-- pttbbs/mbbsd/board.c | 17 +++++++++-------- pttbbs/mbbsd/user.c | 7 ++++++- 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/pttbbs/include/pttstruct.h b/pttbbs/include/pttstruct.h index d424d24d..dc457e75 100644 --- a/pttbbs/include/pttstruct.h +++ b/pttbbs/include/pttstruct.h @@ -1,4 +1,4 @@ -/* $Id: pttstruct.h,v 1.30 2003/03/26 10:21:40 in2 Exp $ */ +/* $Id: pttstruct.h,v 1.31 2003/03/26 11:06:04 in2 Exp $ */ #ifndef INCLUDE_STRUCT_H #define INCLUDE_STRUCT_H @@ -86,13 +86,14 @@ typedef struct userec_t { #define MOVIE_FLAG 0x40 /* true if show movie */ #define COLOR_FLAG 0x80 /* true if the color mode open */ #define MIND_FLAG 0x100 /* true if mind search mode open <-Heat*/ -#define FAVNEW_FLAG 0x20 /* true if add new board into one's fav */ /* these are flags in userec_t.uflag2 */ #define WATER_MASK 000003 /* water mask */ #define WATER_ORIG 0x0 #define WATER_NEW 0x1 #define WATER_OFO 0x2 #define WATERMODE(mode) ((cuser.uflag2 & WATER_MASK) == mode) +#define FAVNOHILIGHT 0x10 /* false if hilight favorite */ +#define FAVNEW_FLAG 0x20 /* true if add new board into one's fav */ #define BTLEN 48 /* Length of board title */ diff --git a/pttbbs/mbbsd/board.c b/pttbbs/mbbsd/board.c index f45c9815..999daf4a 100644 --- a/pttbbs/mbbsd/board.c +++ b/pttbbs/mbbsd/board.c @@ -1,4 +1,4 @@ -/* $Id: board.c,v 1.90 2003/03/26 10:51:15 in2 Exp $ */ +/* $Id: board.c,v 1.91 2003/03/26 11:06:05 in2 Exp $ */ #include "bbs.h" #define BRC_STRLEN 15 /* Length of board name */ #define BRC_MAXSIZE 24576 @@ -932,13 +932,14 @@ show_brdlist(int head, int clsflag, int newflag) if (class_bid != 1) { prints("%s%-13s\033[m%s%5.5s\033[0;37m%2.2s\033[m" "%-34.34s", - (ptr->myattr & BRD_FAV) ? "\033[1;36m" : "", - B_BH(ptr)->brdname, - color[(unsigned int) - (B_BH(ptr)->title[1] + B_BH(ptr)->title[2] + - B_BH(ptr)->title[3] + B_BH(ptr)->title[0]) & 07], - B_BH(ptr)->title, B_BH(ptr)->title + 5, B_BH(ptr)->title + 7); - + ((ptr->myattr & BRD_FAV) && + !(cuser.uflag2 & FAVNOHILIGHT)) ? "\033[1;36m":"", + B_BH(ptr)->brdname, + color[(unsigned int) + (B_BH(ptr)->title[1] + B_BH(ptr)->title[2] + + B_BH(ptr)->title[3] + B_BH(ptr)->title[0]) & 07], + B_BH(ptr)->title, B_BH(ptr)->title + 5, B_BH(ptr)->title + 7); + if (B_BH(ptr)->brdattr & BRD_BAD) prints(" X "); else if (B_BH(ptr)->nuser >= 100) diff --git a/pttbbs/mbbsd/user.c b/pttbbs/mbbsd/user.c index 3c1ad1e6..68c7f048 100644 --- a/pttbbs/mbbsd/user.c +++ b/pttbbs/mbbsd/user.c @@ -1,4 +1,4 @@ -/* $Id: user.c,v 1.50 2003/03/26 10:22:54 in2 Exp $ */ +/* $Id: user.c,v 1.51 2003/03/26 11:06:05 in2 Exp $ */ #include "bbs.h" static char *sex[8] = { @@ -213,6 +213,8 @@ static void Customize(void) prints("%-30s%10s\n", "C. 新板自動進我的最愛", ((cuser.uflag2 & FAVNEW_FLAG) ? "是" : "否")); prints("%-30s%10s\n", "D. 目前的心情", mindbuf); + prints("%-30s%10s\n", "E. 高亮度顯示我的最愛", + ((cuser.uflag2 & FAVNOHILIGHT) ? "否" : "是")); getdata(b_lines - 1, 0, "請按 [A-5] 切換設定,按 [Return] 結束:", ans, sizeof(ans), DOECHO); @@ -242,6 +244,9 @@ static void Customize(void) memcpy(currutmp->mind, mindbuf, 4); } break; + case 'e': + cuser.uflag2 ^= FAVNOHILIGHT; + break; default: done = 1; } -- cgit v1.2.3 From b9b9c634c15a1a7557c5b6287e6c38427a3c2e47 Mon Sep 17 00:00:00 2001 From: victor <victor@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Wed, 26 Mar 2003 11:21:22 +0000 Subject: help git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@718 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/board.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pttbbs/mbbsd/board.c b/pttbbs/mbbsd/board.c index 999daf4a..a4ce590f 100644 --- a/pttbbs/mbbsd/board.c +++ b/pttbbs/mbbsd/board.c @@ -1,4 +1,4 @@ -/* $Id: board.c,v 1.91 2003/03/26 11:06:05 in2 Exp $ */ +/* $Id: board.c,v 1.92 2003/03/26 11:21:22 victor Exp $ */ #include "bbs.h" #define BRC_STRLEN 15 /* Length of board name */ #define BRC_MAXSIZE 24576 @@ -975,11 +975,11 @@ static char *choosebrdhelp[] = { "(^W) 迷路了 我在哪裡", "(r)(→)(Rtn) 進入多功\能閱\讀選單", "(q)(←) 回到主選單", - "(y/Z) 我的最愛/訂閱\看板/出所有看板/訂閱\新開看板", + "(y/Z) 我的最愛, 訂閱\看板, 所有看板/訂閱\新開看板", "(L) 加入分隔線至我的最愛", "(v/V) 通通看完/全部未讀", "(S) 按照字母/分類排序/自訂順序(我的最愛裡)", - "(t/^T/^A/^D) 標記看板/取消所有標記/ 將已標記者加入/移出我的最愛", + "(t/^T/^A/^D) 標記看板/取消所有標記/將已標記者加入/移出我的最愛", "(m/M) 把看板加入或移出我的最愛, 移除分隔線/搬移我的最愛", "\01小組長指令", "(E/W/B) 設定看板/設定小組備忘/開新看板", -- cgit v1.2.3 From 8cebc25c5f48d618bc42741d032918182ff431d6 Mon Sep 17 00:00:00 2001 From: victor <victor@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Wed, 26 Mar 2003 11:38:04 +0000 Subject: don't save a deleted board git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@719 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/board.c | 48 +++++++++++++++++++++++------------------------- 1 file changed, 23 insertions(+), 25 deletions(-) diff --git a/pttbbs/mbbsd/board.c b/pttbbs/mbbsd/board.c index a4ce590f..e8b4d4bd 100644 --- a/pttbbs/mbbsd/board.c +++ b/pttbbs/mbbsd/board.c @@ -1,4 +1,4 @@ -/* $Id: board.c,v 1.92 2003/03/26 11:21:22 victor Exp $ */ +/* $Id: board.c,v 1.93 2003/03/26 11:38:04 victor Exp $ */ #include "bbs.h" #define BRC_STRLEN 15 /* Length of board name */ #define BRC_MAXSIZE 24576 @@ -529,7 +529,7 @@ save_brdbuf(void) #endif for( r = w = 0 ; r < fav->nDatas ; ++r ) - if( fav->b[r].attr & BRD_FAV ) + if( fav->b[r].attr & BRD_FAV && bcache[fav->b[r].bid - 1].brdname[0]) fav->b[w++] = fav->b[r]; fav->nDatas = w; setuserfile(fname, ".fav3"); @@ -740,15 +740,10 @@ load_boards(char *key) nbrd = (boardstat_t *) MALLOC(sizeof(boardstat_t) * numboards); if( yank_flag == 0 ){ // fav mode for( i = 0 ; i < fav->nDatas ; ++i ){ - if( fav->b[i].attr & BRD_FAV ){ - if( fav->b[i].attr & BRD_LINE ) - addnewbrdstat(fav->b[i].bid - 1, BRD_LINE); - else{ - bptr = &bcache[ fav->b[i].bid - 1 ]; - if( (state = Ben_Perm(bptr)) ) - addnewbrdstat(fav->b[i].bid - 1, state); - } - } + if( fav->b[i].attr & (BRD_FAV | BRD_LINE) ) + addnewbrdstat(fav->b[i].bid - 1, BRD_LINE); + else if (fav->b[i].attr & BRD_FAV && (state = Ben_Perm( (bptr = &bcache[ fav->b[i].bid - 1 ])))) + addnewbrdstat(fav->b[i].bid - 1, state); } } else{ // general case @@ -908,7 +903,7 @@ show_brdlist(int head, int clsflag, int newflag) if (head < brdnum) { ptr = &nbrd[head++]; if(ptr->myattr & BRD_LINE){ - prints("%5d ------------ ------------------------------------------", head); + prints("%5d ------------ ------------------------------------------", head, ptr->bid); continue; } if (class_bid == 1) @@ -932,14 +927,13 @@ show_brdlist(int head, int clsflag, int newflag) if (class_bid != 1) { prints("%s%-13s\033[m%s%5.5s\033[0;37m%2.2s\033[m" "%-34.34s", - ((ptr->myattr & BRD_FAV) && - !(cuser.uflag2 & FAVNOHILIGHT)) ? "\033[1;36m":"", - B_BH(ptr)->brdname, - color[(unsigned int) - (B_BH(ptr)->title[1] + B_BH(ptr)->title[2] + - B_BH(ptr)->title[3] + B_BH(ptr)->title[0]) & 07], - B_BH(ptr)->title, B_BH(ptr)->title + 5, B_BH(ptr)->title + 7); - + (ptr->myattr & BRD_FAV) ? "\033[1;36m" : "", + B_BH(ptr)->brdname, + color[(unsigned int) + (B_BH(ptr)->title[1] + B_BH(ptr)->title[2] + + B_BH(ptr)->title[3] + B_BH(ptr)->title[0]) & 07], + B_BH(ptr)->title, B_BH(ptr)->title + 5, B_BH(ptr)->title + 7); + if (B_BH(ptr)->brdattr & BRD_BAD) prints(" X "); else if (B_BH(ptr)->nuser >= 100) @@ -975,12 +969,12 @@ static char *choosebrdhelp[] = { "(^W) 迷路了 我在哪裡", "(r)(→)(Rtn) 進入多功\能閱\讀選單", "(q)(←) 回到主選單", - "(y/Z) 我的最愛, 訂閱\看板, 所有看板/訂閱\新開看板", + "(y/Z) 我的最愛,訂閱\看板,所有看板/訂閱\新開看板", "(L) 加入分隔線至我的最愛", "(v/V) 通通看完/全部未讀", "(S) 按照字母/分類排序/自訂順序(我的最愛裡)", - "(t/^T/^A/^D) 標記看板/取消所有標記/將已標記者加入/移出我的最愛", - "(m/M) 把看板加入或移出我的最愛, 移除分隔線/搬移我的最愛", + "(t/^T/^A/^D) 標記看板/取消所有標記/ 將已標記者加入/移出我的最愛", + "(m/M) 把看板加入或移出我的最愛,移除分隔線/搬移我的最愛", "\01小組長指令", "(E/W/B) 設定看板/設定小組備忘/開新看板", "(^P) 移動已標記看板到此分類", @@ -1175,12 +1169,16 @@ choose_board(int newflag) case 'S': cuser.uflag ^= BRDSORT_FLAG; if(yank_flag == 0){ - if(cuser.uflag & BRDSORT_FLAG) + if(cuser.uflag & BRDSORT_FLAG){ + vmsg("favcmpboardclass"); qsort(&fav->b, fav->nDatas, sizeof(fav_board_t), favcmpboardclass); - else + } + else{ + vmsg("favcmpboardname"); qsort(&fav->b, fav->nDatas, sizeof(fav_board_t), favcmpboardname); + } } brdnum = -1; break; -- cgit v1.2.3 From f563723cdc02b5f49b2f8a06a1603de3564c47f7 Mon Sep 17 00:00:00 2001 From: victor <victor@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Wed, 26 Mar 2003 12:11:40 +0000 Subject: help again git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@720 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/board.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pttbbs/mbbsd/board.c b/pttbbs/mbbsd/board.c index e8b4d4bd..2aed6b3e 100644 --- a/pttbbs/mbbsd/board.c +++ b/pttbbs/mbbsd/board.c @@ -1,4 +1,4 @@ -/* $Id: board.c,v 1.93 2003/03/26 11:38:04 victor Exp $ */ +/* $Id: board.c,v 1.94 2003/03/26 12:11:40 victor Exp $ */ #include "bbs.h" #define BRC_STRLEN 15 /* Length of board name */ #define BRC_MAXSIZE 24576 @@ -972,7 +972,7 @@ static char *choosebrdhelp[] = { "(y/Z) 我的最愛,訂閱\看板,所有看板/訂閱\新開看板", "(L) 加入分隔線至我的最愛", "(v/V) 通通看完/全部未讀", - "(S) 按照字母/分類排序/自訂順序(我的最愛裡)", + "(S) 按照字母/分類排序", "(t/^T/^A/^D) 標記看板/取消所有標記/ 將已標記者加入/移出我的最愛", "(m/M) 把看板加入或移出我的最愛,移除分隔線/搬移我的最愛", "\01小組長指令", -- cgit v1.2.3 From fb4aa021bc6aadde5b5339aec9dec820714dc5b5 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Wed, 26 Mar 2003 12:24:40 +0000 Subject: security fix git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@721 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/board.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/pttbbs/mbbsd/board.c b/pttbbs/mbbsd/board.c index 2aed6b3e..dc2596ed 100644 --- a/pttbbs/mbbsd/board.c +++ b/pttbbs/mbbsd/board.c @@ -1,4 +1,4 @@ -/* $Id: board.c,v 1.94 2003/03/26 12:11:40 victor Exp $ */ +/* $Id: board.c,v 1.95 2003/03/26 12:24:40 in2 Exp $ */ #include "bbs.h" #define BRC_STRLEN 15 /* Length of board name */ #define BRC_MAXSIZE 24576 @@ -739,11 +739,16 @@ load_boards(char *key) if (class_bid <= 0) { nbrd = (boardstat_t *) MALLOC(sizeof(boardstat_t) * numboards); if( yank_flag == 0 ){ // fav mode - for( i = 0 ; i < fav->nDatas ; ++i ){ - if( fav->b[i].attr & (BRD_FAV | BRD_LINE) ) - addnewbrdstat(fav->b[i].bid - 1, BRD_LINE); - else if (fav->b[i].attr & BRD_FAV && (state = Ben_Perm( (bptr = &bcache[ fav->b[i].bid - 1 ])))) - addnewbrdstat(fav->b[i].bid - 1, state); + for( i = 0 ; i < fav->nDatas ; ++i ){ + if( fav->b[i].attr & BRD_FAV ){ + if( fav->b[i].attr & BRD_LINE ) + addnewbrdstat(fav->b[i].bid - 1, BRD_LINE); + else{ + bptr = &bcache[ fav->b[i].bid - 1 ]; + if( (state = Ben_Perm(bptr)) ) + addnewbrdstat(fav->b[i].bid - 1, state); + } + } } } else{ // general case -- cgit v1.2.3 From 4dec70697e5d932d7ae2d375bc0dca4ec87be060 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Wed, 26 Mar 2003 12:32:16 +0000 Subject: FAVNOHILIGHT git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@722 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/board.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/pttbbs/mbbsd/board.c b/pttbbs/mbbsd/board.c index dc2596ed..bc454b0f 100644 --- a/pttbbs/mbbsd/board.c +++ b/pttbbs/mbbsd/board.c @@ -1,4 +1,4 @@ -/* $Id: board.c,v 1.95 2003/03/26 12:24:40 in2 Exp $ */ +/* $Id: board.c,v 1.96 2003/03/26 12:32:16 in2 Exp $ */ #include "bbs.h" #define BRC_STRLEN 15 /* Length of board name */ #define BRC_MAXSIZE 24576 @@ -931,8 +931,9 @@ show_brdlist(int head, int clsflag, int newflag) } if (class_bid != 1) { prints("%s%-13s\033[m%s%5.5s\033[0;37m%2.2s\033[m" - "%-34.34s", - (ptr->myattr & BRD_FAV) ? "\033[1;36m" : "", + "%-34.34s", + ((ptr->myattr & BRD_FAV) && + !cuser.uflag2 & FAVNOHILIGHT)? "\033[1;36m" : "", B_BH(ptr)->brdname, color[(unsigned int) (B_BH(ptr)->title[1] + B_BH(ptr)->title[2] + -- cgit v1.2.3 From 4812b9e9e087decc4d79fa4408ced6eba57d90ce Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Wed, 26 Mar 2003 12:43:55 +0000 Subject: fix HILIGHT git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@723 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/board.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pttbbs/mbbsd/board.c b/pttbbs/mbbsd/board.c index bc454b0f..a939d19f 100644 --- a/pttbbs/mbbsd/board.c +++ b/pttbbs/mbbsd/board.c @@ -1,4 +1,4 @@ -/* $Id: board.c,v 1.96 2003/03/26 12:32:16 in2 Exp $ */ +/* $Id: board.c,v 1.97 2003/03/26 12:43:55 in2 Exp $ */ #include "bbs.h" #define BRC_STRLEN 15 /* Length of board name */ #define BRC_MAXSIZE 24576 @@ -933,7 +933,7 @@ show_brdlist(int head, int clsflag, int newflag) prints("%s%-13s\033[m%s%5.5s\033[0;37m%2.2s\033[m" "%-34.34s", ((ptr->myattr & BRD_FAV) && - !cuser.uflag2 & FAVNOHILIGHT)? "\033[1;36m" : "", + !(cuser.uflag2 & FAVNOHILIGHT))? "\033[1;36m" : "", B_BH(ptr)->brdname, color[(unsigned int) (B_BH(ptr)->title[1] + B_BH(ptr)->title[2] + -- cgit v1.2.3 From e87aeb9ca17b9abed049fadad030732b979e799b Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Wed, 26 Mar 2003 12:59:14 +0000 Subject: remove debug message git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@724 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/board.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/pttbbs/mbbsd/board.c b/pttbbs/mbbsd/board.c index a939d19f..71c9cc9c 100644 --- a/pttbbs/mbbsd/board.c +++ b/pttbbs/mbbsd/board.c @@ -1,4 +1,4 @@ -/* $Id: board.c,v 1.97 2003/03/26 12:43:55 in2 Exp $ */ +/* $Id: board.c,v 1.98 2003/03/26 12:59:14 in2 Exp $ */ #include "bbs.h" #define BRC_STRLEN 15 /* Length of board name */ #define BRC_MAXSIZE 24576 @@ -1175,16 +1175,12 @@ choose_board(int newflag) case 'S': cuser.uflag ^= BRDSORT_FLAG; if(yank_flag == 0){ - if(cuser.uflag & BRDSORT_FLAG){ - vmsg("favcmpboardclass"); + if(cuser.uflag & BRDSORT_FLAG) qsort(&fav->b, fav->nDatas, sizeof(fav_board_t), favcmpboardclass); - } - else{ - vmsg("favcmpboardname"); + else qsort(&fav->b, fav->nDatas, sizeof(fav_board_t), favcmpboardname); - } } brdnum = -1; break; -- cgit v1.2.3 From 9a95b6b77400bdd093534e6f6d7c4eda5b680e78 Mon Sep 17 00:00:00 2001 From: victor <victor@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Wed, 26 Mar 2003 14:20:56 +0000 Subject: init new fav git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@725 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/board.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pttbbs/mbbsd/board.c b/pttbbs/mbbsd/board.c index 71c9cc9c..e7228638 100644 --- a/pttbbs/mbbsd/board.c +++ b/pttbbs/mbbsd/board.c @@ -1,4 +1,4 @@ -/* $Id: board.c,v 1.98 2003/03/26 12:59:14 in2 Exp $ */ +/* $Id: board.c,v 1.99 2003/03/26 14:20:56 victor Exp $ */ #include "bbs.h" #define BRC_STRLEN 15 /* Length of board name */ #define BRC_MAXSIZE 24576 @@ -469,8 +469,10 @@ void load_brdbuf(void) for( i = 1; i <= numboards; i++){ if(read(fd, &favrec, sizeof(char)) < 0) break; - if( (favrec & BRD_FAV) ) + if( (favrec & BRD_FAV) ){ + memset(&fav->b[fav->nDatas++], 0, sizeof(fav_board_t)); setfav(i, BRD_FAV, 1, 0); + } } close(fd); } -- cgit v1.2.3 From ad10aa3a6df9e73675aed575b7df88f353184521 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Wed, 26 Mar 2003 15:05:09 +0000 Subject: fix bug git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@726 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/board.c | 27 ++++++++------------------- 1 file changed, 8 insertions(+), 19 deletions(-) diff --git a/pttbbs/mbbsd/board.c b/pttbbs/mbbsd/board.c index e7228638..d06502fc 100644 --- a/pttbbs/mbbsd/board.c +++ b/pttbbs/mbbsd/board.c @@ -1,4 +1,4 @@ -/* $Id: board.c,v 1.99 2003/03/26 14:20:56 victor Exp $ */ +/* $Id: board.c,v 1.100 2003/03/26 15:05:09 in2 Exp $ */ #include "bbs.h" #define BRC_STRLEN 15 /* Length of board name */ #define BRC_MAXSIZE 24576 @@ -359,24 +359,15 @@ void setfav(short bid, char attr, char mode, time_t t) fav->nAllocs += 16; } - // insertion sort: - if(!(attr & BRD_LINE)){ - for( where = 0 ; where < fav->nDatas ; ++where ) - if( fav->b[where].bid > bid ) - break; - if( where != fav->nDatas ){ - int i; - for( i = fav->nDatas - 1 ; i >= where ; --i ) - fav->b[i + 1] = fav->b[i]; - } + where = fav->nDatas; - fav->b[where].bid = bid ; - fav->b[where].attr = mode ? attr : 0; + if( attr & BRD_LINE ){ + fav->b[where].bid = --(fav->nLines); + fav->b[where].attr = mode ? (BRD_LINE | BRD_FAV) : 0; } else{ - where = fav->nDatas; - fav->b[where].bid = --(fav->nLines); - fav->b[where].attr = attr; + fav->b[where].bid = bid ; + fav->b[where].attr = mode ? attr : 0; } fav->b[where].lastvisit = t ? t : login_start_time; @@ -469,10 +460,8 @@ void load_brdbuf(void) for( i = 1; i <= numboards; i++){ if(read(fd, &favrec, sizeof(char)) < 0) break; - if( (favrec & BRD_FAV) ){ - memset(&fav->b[fav->nDatas++], 0, sizeof(fav_board_t)); + if( (favrec & BRD_FAV) ) setfav(i, BRD_FAV, 1, 0); - } } close(fd); } -- cgit v1.2.3 From bbf3f8e0273931b3afb32286a310536975a829c0 Mon Sep 17 00:00:00 2001 From: victor <victor@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Wed, 26 Mar 2003 15:36:42 +0000 Subject: init new 16 fav git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@727 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/board.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pttbbs/mbbsd/board.c b/pttbbs/mbbsd/board.c index d06502fc..47c8ee80 100644 --- a/pttbbs/mbbsd/board.c +++ b/pttbbs/mbbsd/board.c @@ -1,4 +1,4 @@ -/* $Id: board.c,v 1.100 2003/03/26 15:05:09 in2 Exp $ */ +/* $Id: board.c,v 1.101 2003/03/26 15:36:42 victor Exp $ */ #include "bbs.h" #define BRC_STRLEN 15 /* Length of board name */ #define BRC_MAXSIZE 24576 @@ -356,6 +356,7 @@ void setfav(short bid, char attr, char mode, time_t t) sizeof(fav_t) + sizeof(fav_board_t) * (16 + fav->nAllocs)); + memset(&fav->b[fav->nDatas], 0, sizeof(fav_board_t) * 16); fav->nAllocs += 16; } -- cgit v1.2.3 From a2e804bd2c653359579881f7d3625243945697bd Mon Sep 17 00:00:00 2001 From: victor <victor@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Wed, 26 Mar 2003 17:51:53 +0000 Subject: final git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@728 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/board.c | 61 +++++++++++++++++++++++++++------------------------- 1 file changed, 32 insertions(+), 29 deletions(-) diff --git a/pttbbs/mbbsd/board.c b/pttbbs/mbbsd/board.c index 47c8ee80..f7ab6b57 100644 --- a/pttbbs/mbbsd/board.c +++ b/pttbbs/mbbsd/board.c @@ -1,4 +1,4 @@ -/* $Id: board.c,v 1.101 2003/03/26 15:36:42 victor Exp $ */ +/* $Id: board.c,v 1.102 2003/03/26 17:51:53 victor Exp $ */ #include "bbs.h" #define BRC_STRLEN 15 /* Length of board name */ #define BRC_MAXSIZE 24576 @@ -282,38 +282,32 @@ time_t getfavtime(short bid) void movefav(int old, int new) { - boardstat_t tmp; - fav_board_t *des, *src, *ptr1, *ptr2, t; - if( !(src = getfav(nbrd[old].bid)) || !(des = getfav(nbrd[new].bid)) ) + int i, src = -1, des = -1; + fav_board_t tmp; + + for(i = 0; i < fav->nDatas; i++){ + if(nbrd[old].bid == fav->b[i].bid) + src = i; + if(nbrd[new].bid == fav->b[i].bid) + des = i; + } + + if(src == -1 || des == -1) return; - t = *src; - tmp = nbrd[old]; - if(new < old){ - for(ptr1 = ptr2 = src; ptr1 > des && ptr2 > des; ptr1--) - if(ptr1->attr & BRD_FAV){ - *ptr2 = *(ptr1 - 1); - ptr2--; - while(ptr2 > des && !(ptr2->attr & BRD_FAV)) - ptr2--; - } - for( ; old > new; old--) - nbrd[old] = nbrd[old - 1]; + tmp = fav->b[src]; + if(src < des){ + for(i = src; i < des; i++) + fav->b[i] = fav->b[i + 1]; } - else{ - for(ptr1 = ptr2 = src; ptr1 < des && ptr2 < des; ptr1++) - if(ptr1->attr & BRD_FAV){ - *ptr2 = *(ptr1 + 1); - ptr2++; - while(ptr2 < des && !(ptr2->attr & BRD_FAV)) - ptr2++; - } - for( ; old < new; old++) - nbrd[old] = nbrd[old + 1]; + else{ // des < src + for(i = src; i > des; i--) + fav->b[i] = fav->b[i - 1]; } - nbrd[new] = tmp; - *des = t; + fav->b[des] = tmp; + + brdnum = -1; } void delfavline(int bid, int num) @@ -900,7 +894,7 @@ show_brdlist(int head, int clsflag, int newflag) if (head < brdnum) { ptr = &nbrd[head++]; if(ptr->myattr & BRD_LINE){ - prints("%5d ------------ ------------------------------------------", head, ptr->bid); + prints("%5d ------------ ------------------------------------------", head); continue; } if (class_bid == 1) @@ -1272,6 +1266,15 @@ choose_board(int newflag) head = 9999; } break; + case 'K': + if (HAS_PERM(PERM_BASIC)) { + char fname[80]; + setuserfile(fname, ".fav3"); + unlink(fname); + load_brdbuf(); + brdnum = -1; + } + break; case 'z': vmsg("嘿嘿 這個功\能已經被我的最愛取代掉了喔!"); break; -- cgit v1.2.3 From a3f101a8ad4054179bafa4c40c70ac19a24f48d3 Mon Sep 17 00:00:00 2001 From: victor <victor@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Thu, 27 Mar 2003 05:10:21 +0000 Subject: fix favline git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@729 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/board.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pttbbs/mbbsd/board.c b/pttbbs/mbbsd/board.c index f7ab6b57..ec2fd372 100644 --- a/pttbbs/mbbsd/board.c +++ b/pttbbs/mbbsd/board.c @@ -1,4 +1,4 @@ -/* $Id: board.c,v 1.102 2003/03/26 17:51:53 victor Exp $ */ +/* $Id: board.c,v 1.103 2003/03/27 05:10:21 victor Exp $ */ #include "bbs.h" #define BRC_STRLEN 15 /* Length of board name */ #define BRC_MAXSIZE 24576 @@ -515,7 +515,8 @@ save_brdbuf(void) #endif for( r = w = 0 ; r < fav->nDatas ; ++r ) - if( fav->b[r].attr & BRD_FAV && bcache[fav->b[r].bid - 1].brdname[0]) + if( ( fav->b[r].attr & BRD_LINE ) || + (fav->b[r].attr & BRD_FAV && bcache[fav->b[r].bid - 1].brdname[0])) fav->b[w++] = fav->b[r]; fav->nDatas = w; setuserfile(fname, ".fav3"); @@ -1235,10 +1236,9 @@ choose_board(int newflag) break; } setfav(0, BRD_FAV | BRD_LINE, 1, 0); - nbrd[brdnum].bid = fav->nLines; - nbrd[brdnum].myattr = (BRD_FAV | BRD_LINE); movefav(brdnum++, num); favchange = 1; + brdnum = -1; head = 9999; } break; @@ -1253,9 +1253,9 @@ choose_board(int newflag) } else{ setfav(nbrd[num].bid, BRD_FAV, 2, 0); - nbrd[num].myattr ^= BRD_FAV; } favchange = 1; + brdnum = -1; head = 9999; } break; -- cgit v1.2.3 From 6a6418fbb4af016da8a957a42942bf90d3f27fbb Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Thu, 27 Mar 2003 05:44:42 +0000 Subject: check if sort fav git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@730 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/board.c | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/pttbbs/mbbsd/board.c b/pttbbs/mbbsd/board.c index ec2fd372..b61854fa 100644 --- a/pttbbs/mbbsd/board.c +++ b/pttbbs/mbbsd/board.c @@ -1,4 +1,4 @@ -/* $Id: board.c,v 1.103 2003/03/27 05:10:21 victor Exp $ */ +/* $Id: board.c,v 1.104 2003/03/27 05:44:42 in2 Exp $ */ #include "bbs.h" #define BRC_STRLEN 15 /* Length of board name */ #define BRC_MAXSIZE 24576 @@ -1159,16 +1159,21 @@ choose_board(int newflag) keyword, sizeof(keyword), DOECHO); brdnum = -1; break; - case 'S': - cuser.uflag ^= BRDSORT_FLAG; - if(yank_flag == 0){ - if(cuser.uflag & BRDSORT_FLAG) - qsort(&fav->b, fav->nDatas, sizeof(fav_board_t), - favcmpboardclass); - else - qsort(&fav->b, fav->nDatas, sizeof(fav_board_t), - favcmpboardname); - } + case 'S':{ + char input[4]; + move(b_lines - 2, 0); + prints("重新排序看板 " + "\033[1;33m(注意, 這個動作會覆寫原來設定)\033[m \n"); + getdata(b_lines - 1, 0, + "排序方式 (1)按照板名排序 (2)按照類別排序 ==> [0]取消 ", + input, sizeof(input), DOECHO); + if( input[0] == '1' ) + qsort(&fav->b, fav->nDatas, sizeof(fav_board_t), + favcmpboardname); + else if( input[0] == '2' ) + qsort(&fav->b, fav->nDatas, sizeof(fav_board_t), + favcmpboardclass); + } brdnum = -1; break; case 'y': -- cgit v1.2.3 From 22c73f4ffcbda6e6ea75dc798a65e145bce71f69 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Thu, 27 Mar 2003 05:53:09 +0000 Subject: fix last commit bug git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@731 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/board.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/pttbbs/mbbsd/board.c b/pttbbs/mbbsd/board.c index b61854fa..36421670 100644 --- a/pttbbs/mbbsd/board.c +++ b/pttbbs/mbbsd/board.c @@ -1,4 +1,4 @@ -/* $Id: board.c,v 1.104 2003/03/27 05:44:42 in2 Exp $ */ +/* $Id: board.c,v 1.105 2003/03/27 05:53:09 in2 Exp $ */ #include "bbs.h" #define BRC_STRLEN 15 /* Length of board name */ #define BRC_MAXSIZE 24576 @@ -706,7 +706,7 @@ static void load_boards(char *key) { boardheader_t *bptr = NULL; - int type = cuser.uflag & BRDSORT_FLAG ? 1 : 0; + int type = (cuser.uflag & BRDSORT_FLAG) ? 0 : 1; int i, n; int state; #ifdef CRITICAL_MEMORY @@ -1167,12 +1167,16 @@ choose_board(int newflag) getdata(b_lines - 1, 0, "排序方式 (1)按照板名排序 (2)按照類別排序 ==> [0]取消 ", input, sizeof(input), DOECHO); - if( input[0] == '1' ) + if( input[0] == '1' ){ + cuser.uflag |= BRDSORT_FLAG; qsort(&fav->b, fav->nDatas, sizeof(fav_board_t), favcmpboardname); - else if( input[0] == '2' ) + } + else if( input[0] == '2' ){ + cuser.uflag &= ~BRDSORT_FLAG; qsort(&fav->b, fav->nDatas, sizeof(fav_board_t), favcmpboardclass); + } } brdnum = -1; break; -- cgit v1.2.3 From 5869677552d866169f36b56b4a9834bf9108c00d Mon Sep 17 00:00:00 2001 From: victor <victor@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Thu, 27 Mar 2003 13:14:15 +0000 Subject: rm #if-#else and sharpen something, check the existence of board in updatenewfav() git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@732 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/board.c | 110 +++++++++++++++++++++++++++++---------------------- 1 file changed, 62 insertions(+), 48 deletions(-) diff --git a/pttbbs/mbbsd/board.c b/pttbbs/mbbsd/board.c index 36421670..5dfa8b88 100644 --- a/pttbbs/mbbsd/board.c +++ b/pttbbs/mbbsd/board.c @@ -1,4 +1,4 @@ -/* $Id: board.c,v 1.105 2003/03/27 05:53:09 in2 Exp $ */ +/* $Id: board.c,v 1.106 2003/03/27 13:14:15 victor Exp $ */ #include "bbs.h" #define BRC_STRLEN 15 /* Length of board name */ #define BRC_MAXSIZE 24576 @@ -214,6 +214,8 @@ brc_unread(char *fname, int bnum, int *blist) #define BRD_TAG 8 #define FAVNB ".favnb" +#define FAV3 ".fav3" + #define B_TOTAL(bptr) (SHM->total[(bptr)->bid - 1]) #define B_LASTPOSTTIME(bptr) (SHM->lastposttime[(bptr)->bid - 1]) #define B_BH(bptr) (&bcache[(bptr)->bid - 1]) @@ -405,15 +407,17 @@ void updatenewfav(int mode) read(fd, brd, (numboards + 1) * sizeof(char)); for(i = 0; i < numboards && brd[i] != BRD_END; i++){ - if(brd[i] == BRD_NEW && Ben_Perm(&bcache[i])){ - if(mode) - setfav(i + 1, BRD_FAV, 1, 0); - brd[i] = BRD_OLD; + if(brd[i] == BRD_NEW){ + if(bcache[i].brdname[0] && Ben_Perm(&bcache[i])){ // check the permission if the board exsits + if(mode) + setfav(i + 1, BRD_FAV, 1, 0); + brd[i] = BRD_OLD; + } } } - if( i != numboards ) + if( i != numboards ) // the board number may change for(i-- ; i < numboards; i++){ - if(Ben_Perm(&bcache[i])){ + if(bcache[i].brdname[0] && Ben_Perm(&bcache[i])){ if(mode) setfav(i + 1, BRD_FAV, 1, 0); brd[i] = BRD_OLD; @@ -437,7 +441,7 @@ void load_brdbuf(void) int fd, r, w; char fname[80]; - setuserfile(fname, ".fav3"); + setuserfile(fname, FAV3); if( (fd = open(fname, O_RDONLY)) == -1 ){ // not found. int i; @@ -519,7 +523,7 @@ save_brdbuf(void) (fav->b[r].attr & BRD_FAV && bcache[fav->b[r].bid - 1].brdname[0])) fav->b[w++] = fav->b[r]; fav->nDatas = w; - setuserfile(fname, ".fav3"); + setuserfile(fname, FAV3); if( (fd = open(fname, O_WRONLY | O_CREAT, 0600)) != -1 ){ int i; write(fd, &fav->nDatas, sizeof(short)); @@ -706,7 +710,7 @@ static void load_boards(char *key) { boardheader_t *bptr = NULL; - int type = (cuser.uflag & BRDSORT_FLAG) ? 0 : 1; + int type = cuser.uflag & BRDSORT_FLAG ? 1 : 0; int i, n; int state; #ifdef CRITICAL_MEMORY @@ -729,12 +733,12 @@ load_boards(char *key) for( i = 0 ; i < fav->nDatas ; ++i ){ if( fav->b[i].attr & BRD_FAV ){ if( fav->b[i].attr & BRD_LINE ) - addnewbrdstat(fav->b[i].bid - 1, BRD_LINE); + addnewbrdstat(fav->b[i].bid - 1, BRD_FAV | BRD_LINE); else{ bptr = &bcache[ fav->b[i].bid - 1 ]; if( (state = Ben_Perm(bptr)) ) addnewbrdstat(fav->b[i].bid - 1, state); - } + } } } } @@ -757,7 +761,6 @@ load_boards(char *key) } else { nbrd = (boardstat_t *) MALLOC(bptr->childcount * sizeof(boardstat_t)); -#if 1 for (bptr = bptr->firstchild[type]; bptr != (boardheader_t *) ~ 0; bptr = bptr->next[type]) { n = (int)(bptr - bcache); @@ -767,7 +770,6 @@ load_boards(char *key) continue; addnewbrdstat(n, state); } -#endif } #ifndef CRITICAL_MEMORY nbrd = realloc(nbrd, sizeof(boardstat_t) * brdnum); @@ -1113,13 +1115,11 @@ choose_board(int newflag) num = brdnum - 1; break; case 't': -#if 1 ptr = &nbrd[num]; favchange = 1; setfav(ptr->bid, BRD_TAG, 2, 0); ptr->myattr ^= BRD_TAG; head = 9999; -#endif case KEY_DOWN: case 'n': case 'j': @@ -1167,16 +1167,12 @@ choose_board(int newflag) getdata(b_lines - 1, 0, "排序方式 (1)按照板名排序 (2)按照類別排序 ==> [0]取消 ", input, sizeof(input), DOECHO); - if( input[0] == '1' ){ - cuser.uflag |= BRDSORT_FLAG; + if( input[0] == '1' ) qsort(&fav->b, fav->nDatas, sizeof(fav_board_t), favcmpboardname); - } - else if( input[0] == '2' ){ - cuser.uflag &= ~BRDSORT_FLAG; + else if( input[0] == '2' ) qsort(&fav->b, fav->nDatas, sizeof(fav_board_t), favcmpboardclass); - } } brdnum = -1; break; @@ -1185,19 +1181,17 @@ choose_board(int newflag) brdnum = -1; break; case Ctrl('D'): -#if 1 for (tmp = 0; tmp < fav->nDatas; tmp++) { if (fav->b[tmp].attr & BRD_TAG) { favchange = 1; fav->b[tmp].attr &= ~BRD_FAV; fav->b[tmp].attr &= ~BRD_TAG; + fav->nDatas--; } -#endif } brdnum = -1; break; case Ctrl('A'): -#if 1 for (tmp = 0; tmp < fav->nDatas; tmp++) { if (fav->b[tmp].attr & BRD_TAG) { favchange = 1; @@ -1205,19 +1199,15 @@ choose_board(int newflag) fav->b[tmp].attr &= ~BRD_TAG; } } -#endif brdnum = -1; break; case Ctrl('T'): -#if 1 for (tmp = 0; tmp < fav->nDatas; tmp++) fav->b[tmp].attr &= ~BRD_TAG; favchange = 1; brdnum = -1; -#endif break; case Ctrl('P'): -#if 1 if (class_bid != 0 && (HAS_PERM(PERM_SYSOP) || (currmode & MODE_MENU))) { for (tmp = 0; tmp < fav->nDatas; tmp++) { @@ -1236,7 +1226,6 @@ choose_board(int newflag) } brdnum = -1; } -#endif break; case 'L': if (HAS_PERM(PERM_BASIC)) { @@ -1255,6 +1244,7 @@ choose_board(int newflag) if (HAS_PERM(PERM_BASIC)) { if(nbrd[num].myattr & BRD_LINE){ delfavline(nbrd[num].bid, num); + brdnum = -1; } else if(fav->nDatas > FAVMAX){ vmsg("你的最愛太多了啦 真花心"); @@ -1264,7 +1254,6 @@ choose_board(int newflag) setfav(nbrd[num].bid, BRD_FAV, 2, 0); } favchange = 1; - brdnum = -1; head = 9999; } break; @@ -1277,11 +1266,37 @@ choose_board(int newflag) break; case 'K': if (HAS_PERM(PERM_BASIC)) { - char fname[80]; - setuserfile(fname, ".fav3"); - unlink(fname); - load_brdbuf(); - brdnum = -1; + char buf[2], fname[80]; + getdata(b_lines - 1, 0, "請選擇匯入列表 1)我的最愛 2)訂閱\看板 (警告! 這將覆寫我的最愛!)", buf, sizeof(buf), DOECHO); + tmp = atoi(buf); + if(tmp == 1){ + setuserfile(fname, FAV3); + unlink(fname); + load_brdbuf(); + } + else if(tmp == 2){ + int fd, zap, count = 0; + setuserfile(fname, FAV3); + unlink(fname); + setuserfile(fname, ".bbsrc"); + if( (fd = open(fname, O_RDONLY)) != -1 ){ + for(tmp = 0; tmp < numboards; tmp++){ + if(read(fd, &zap, sizeof(zap)) > 0){ + if(zap > 0 && bcache[tmp].brdname[0]){ + if(getfav(tmp + 1) != NULL){ + setfav(tmp + 1, BRD_FAV, 1, zap); + count++; + } + } + } + if(count >= FAVMAX){ + vmsg("已到達最愛上限 :("); + break; + } + } + } + brdnum = -1; + } } break; case 'z': @@ -1290,26 +1305,27 @@ choose_board(int newflag) case 'Z': cuser.uflag2 ^= FAVNEW_FLAG; if(cuser.uflag2 & FAVNEW_FLAG){ - int fd; char fname[80]; setuserfile(fname, FAVNB); - if( (fd = open(fname, O_RDONLY, 0600)) != -1 ){ - close(fd); + if( (tmp = open(fname, O_RDONLY, 0600)) != -1 ){ + close(tmp); updatenewfav(0); } else{ - int i; char stat; - if( (fd = open(fname, O_WRONLY | O_CREAT, 0600)) != -1 ){ - for(i = 0; i < numboards; i++){ - stat = Ben_Perm(&bcache[i]) ? BRD_OLD : BRD_NEW; - write(fd, &stat, sizeof(char)); + if( (tmp = open(fname, O_WRONLY | O_CREAT, 0600)) != -1 ){ + for(tmp1 = 0; tmp1 < numboards; tmp1++){ + if(bcache[tmp1].brdname[0] && Ben_Perm(&bcache[tmp1])) + stat = BRD_OLD; + else + stat = BRD_NEW; + write(tmp, &stat, sizeof(char)); } stat = BRD_END; - write(fd, &stat, sizeof(char)); - close(fd); + write(tmp, &stat, sizeof(char)); + close(tmp); } } } @@ -1317,7 +1333,6 @@ choose_board(int newflag) break; case 'v': case 'V': -#if 1 ptr = &nbrd[num]; brc_initial(B_BH(ptr)->brdname); if (ch == 'v') { @@ -1334,7 +1349,6 @@ choose_board(int newflag) brc_num = brc_changed = 1; brc_update(); show_brdlist(head, 0, newflag); -#endif break; case 's': if ((tmp = search_board()) == -1) { -- cgit v1.2.3 From 06c82578562754afc7ecca632ef0c9ab7c22cad6 Mon Sep 17 00:00:00 2001 From: victor <victor@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Thu, 27 Mar 2003 15:07:23 +0000 Subject: fix sort in non-fav git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@733 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/board.c | 48 ++++++++++++++++++++++++++++++------------------ 1 file changed, 30 insertions(+), 18 deletions(-) diff --git a/pttbbs/mbbsd/board.c b/pttbbs/mbbsd/board.c index 5dfa8b88..95606b73 100644 --- a/pttbbs/mbbsd/board.c +++ b/pttbbs/mbbsd/board.c @@ -1,4 +1,4 @@ -/* $Id: board.c,v 1.106 2003/03/27 13:14:15 victor Exp $ */ +/* $Id: board.c,v 1.107 2003/03/27 15:07:23 victor Exp $ */ #include "bbs.h" #define BRC_STRLEN 15 /* Length of board name */ #define BRC_MAXSIZE 24576 @@ -1159,21 +1159,24 @@ choose_board(int newflag) keyword, sizeof(keyword), DOECHO); brdnum = -1; break; - case 'S':{ - char input[4]; - move(b_lines - 2, 0); - prints("重新排序看板 " - "\033[1;33m(注意, 這個動作會覆寫原來設定)\033[m \n"); - getdata(b_lines - 1, 0, - "排序方式 (1)按照板名排序 (2)按照類別排序 ==> [0]取消 ", - input, sizeof(input), DOECHO); - if( input[0] == '1' ) - qsort(&fav->b, fav->nDatas, sizeof(fav_board_t), - favcmpboardname); - else if( input[0] == '2' ) - qsort(&fav->b, fav->nDatas, sizeof(fav_board_t), - favcmpboardclass); - } + case 'S': + if(yank_flag == 0){ + char input[4]; + move(b_lines - 2, 0); + prints("重新排序看板 " + "\033[1;33m(注意, 這個動作會覆寫原來設定)\033[m \n"); + getdata(b_lines - 1, 0, + "排序方式 (1)按照板名排序 (2)按照類別排序 ==> [0]取消 ", + input, sizeof(input), DOECHO); + if( input[0] == '1' ) + qsort(&fav->b, fav->nDatas, sizeof(fav_board_t), + favcmpboardname); + else if( input[0] == '2' ) + qsort(&fav->b, fav->nDatas, sizeof(fav_board_t), + favcmpboardclass); + } + else + cuser.uflag ^= BRDSORT_FLAG; brdnum = -1; break; case 'y': @@ -1267,13 +1270,21 @@ choose_board(int newflag) case 'K': if (HAS_PERM(PERM_BASIC)) { char buf[2], fname[80]; +#if 1 + getdata(b_lines - 1, 0, "請確定是否匯入舊的我的最愛(警告! 這將覆寫我的最愛!)[y/N]", buf, sizeof(buf), DOECHO); +#else getdata(b_lines - 1, 0, "請選擇匯入列表 1)我的最愛 2)訂閱\看板 (警告! 這將覆寫我的最愛!)", buf, sizeof(buf), DOECHO); tmp = atoi(buf); if(tmp == 1){ - setuserfile(fname, FAV3); +#endif +#if 1 + if(buf[0] == 'Y' || buf[0] == 'y'){ +#endif + setuserfile(fname, FAV3); unlink(fname); load_brdbuf(); } +#if 0 else if(tmp == 2){ int fd, zap, count = 0; setuserfile(fname, FAV3); @@ -1295,8 +1306,9 @@ choose_board(int newflag) } } } - brdnum = -1; } +#endif + brdnum = -1; } break; case 'z': -- cgit v1.2.3 From 0c8ef6458e975813040574071256be74ffc524ef Mon Sep 17 00:00:00 2001 From: victor <victor@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Thu, 27 Mar 2003 15:14:33 +0000 Subject: let un-fav board change color git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@734 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/board.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pttbbs/mbbsd/board.c b/pttbbs/mbbsd/board.c index 95606b73..fb598591 100644 --- a/pttbbs/mbbsd/board.c +++ b/pttbbs/mbbsd/board.c @@ -1,4 +1,4 @@ -/* $Id: board.c,v 1.107 2003/03/27 15:07:23 victor Exp $ */ +/* $Id: board.c,v 1.108 2003/03/27 15:14:33 victor Exp $ */ #include "bbs.h" #define BRC_STRLEN 15 /* Length of board name */ #define BRC_MAXSIZE 24576 @@ -1255,6 +1255,7 @@ choose_board(int newflag) } else{ setfav(nbrd[num].bid, BRD_FAV, 2, 0); + nbrd[num].myattr ^= BRD_FAV; } favchange = 1; head = 9999; -- cgit v1.2.3 From ab630c2235ea603c92efdc8bb82b02908080c6d0 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Thu, 27 Mar 2003 19:18:52 +0000 Subject: bug fix of moving board git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@735 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/board.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/pttbbs/mbbsd/board.c b/pttbbs/mbbsd/board.c index fb598591..d041ec65 100644 --- a/pttbbs/mbbsd/board.c +++ b/pttbbs/mbbsd/board.c @@ -1,4 +1,4 @@ -/* $Id: board.c,v 1.108 2003/03/27 15:14:33 victor Exp $ */ +/* $Id: board.c,v 1.109 2003/03/27 19:18:52 in2 Exp $ */ #include "bbs.h" #define BRC_STRLEN 15 /* Length of board name */ #define BRC_MAXSIZE 24576 @@ -1214,16 +1214,21 @@ choose_board(int newflag) if (class_bid != 0 && (HAS_PERM(PERM_SYSOP) || (currmode & MODE_MENU))) { for (tmp = 0; tmp < fav->nDatas; tmp++) { - boardheader_t *bh = &bcache[tmp]; + short bid = fav->b[tmp].bid; + boardheader_t *bh = &bcache[ bid - 1 ]; + /* if (!(fav->b[tmp].attr & BRD_TAG) || bh->gid == class_bid) continue; + */ + if( !(fav->b[tmp].attr & BRD_TAG) ) + continue; favchange = 1; fav->b[tmp].attr &= ~BRD_TAG; if (bh->gid != class_bid) { bh->gid = class_bid; substitute_record(FN_BOARD, bh, - sizeof(boardheader_t), tmp + 1); - reset_board(tmp + 1); + sizeof(boardheader_t), bid); + reset_board(bid); log_usies("SetBoardGID", bh->brdname); } } -- cgit v1.2.3 From c61c6e8e83b9705c88a38579ffdd086a48ef66fb Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Thu, 27 Mar 2003 19:47:47 +0000 Subject: dirty fix lastposttime git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@736 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/board.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pttbbs/mbbsd/board.c b/pttbbs/mbbsd/board.c index d041ec65..6722217d 100644 --- a/pttbbs/mbbsd/board.c +++ b/pttbbs/mbbsd/board.c @@ -1,4 +1,4 @@ -/* $Id: board.c,v 1.109 2003/03/27 19:18:52 in2 Exp $ */ +/* $Id: board.c,v 1.110 2003/03/27 19:47:47 in2 Exp $ */ #include "bbs.h" #define BRC_STRLEN 15 /* Length of board name */ #define BRC_MAXSIZE 24576 @@ -609,6 +609,8 @@ check_newpost(boardstat_t * ptr) if (B_TOTAL(ptr) == 0) return 0; ftime = B_LASTPOSTTIME(ptr); + if( ftime > now ) + ftime = B_LASTPOSTTIME(ptr) = now - 1; read_brc_buf(); po = brc_buf; while (po < &brc_buf[brc_size] && (*po >= ' ' && *po <= 'z')) { -- cgit v1.2.3 From 10b70d8c76ec20d4ad06b18c77a4cc0a25375336 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Thu, 27 Mar 2003 19:50:28 +0000 Subject: dirty fix if bid was wrong git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@737 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/board.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pttbbs/mbbsd/board.c b/pttbbs/mbbsd/board.c index 6722217d..40826a4c 100644 --- a/pttbbs/mbbsd/board.c +++ b/pttbbs/mbbsd/board.c @@ -1,4 +1,4 @@ -/* $Id: board.c,v 1.110 2003/03/27 19:47:47 in2 Exp $ */ +/* $Id: board.c,v 1.111 2003/03/27 19:50:28 in2 Exp $ */ #include "bbs.h" #define BRC_STRLEN 15 /* Length of board name */ #define BRC_MAXSIZE 24576 @@ -484,6 +484,7 @@ void load_brdbuf(void) if( fav->b[r].attr & BRD_FAV ) // 須是 BRD_FAV if( (fav->b[r].bid < 0) || // 分隔線 (fav->b[r].bid > 0 && // bid > 0 且該看板存在 + fav->b[r].bid < numboards && bcache[fav->b[r].bid - 1].brdname[0]) ) fav->b[w++] = fav->b[r]; fav->nDatas = w; -- cgit v1.2.3 From a1c587259156e3264686eb1d5ed90fc2e74d9c11 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Fri, 28 Mar 2003 13:32:02 +0000 Subject: remove duplication favorite entry git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@738 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/board.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/pttbbs/mbbsd/board.c b/pttbbs/mbbsd/board.c index 40826a4c..a929fe99 100644 --- a/pttbbs/mbbsd/board.c +++ b/pttbbs/mbbsd/board.c @@ -1,4 +1,4 @@ -/* $Id: board.c,v 1.111 2003/03/27 19:50:28 in2 Exp $ */ +/* $Id: board.c,v 1.112 2003/03/28 13:32:02 in2 Exp $ */ #include "bbs.h" #define BRC_STRLEN 15 /* Length of board name */ #define BRC_MAXSIZE 24576 @@ -480,13 +480,21 @@ void load_brdbuf(void) } // check if fav is correct + // 'r' for current reading position, 'w' for current writing position + // 'i' for checking duplication for( r = w = 0 ; r < fav->nDatas ; ++r ) - if( fav->b[r].attr & BRD_FAV ) // 須是 BRD_FAV - if( (fav->b[r].bid < 0) || // 分隔線 - (fav->b[r].bid > 0 && // bid > 0 且該看板存在 + if( fav->b[r].attr & BRD_FAV ) // 須是 BRD_FAV + if( (fav->b[r].bid < 0) || // 分隔線 + (fav->b[r].bid > 0 && // bid 在合理範圍 fav->b[r].bid < numboards && - bcache[fav->b[r].bid - 1].brdname[0]) ) - fav->b[w++] = fav->b[r]; + bcache[fav->b[r].bid - 1].brdname[0]) ){ // 看板存在 + int i; + for( i = 0 ; i < w ; ++i ) + if( fav->b[i].bid == fav->b[r].bid ) + break; + if( i == w ) // 無和之前的重覆 + fav->b[w++] = fav->b[r]; + } fav->nDatas = w; updatenewfav(1); -- cgit v1.2.3 From 6bbab84a766e78561fa7e990978d729152a772d2 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Fri, 28 Mar 2003 13:39:29 +0000 Subject: comments git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@739 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/LocalVars.pm.sample | 4 ++-- pttbbs/util/Makefile | 9 ++++++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/pttbbs/util/LocalVars.pm.sample b/pttbbs/util/LocalVars.pm.sample index 04806da6..1f24872d 100644 --- a/pttbbs/util/LocalVars.pm.sample +++ b/pttbbs/util/LocalVars.pm.sample @@ -19,6 +19,6 @@ $JOBSPOOL = "$BBSHOME/jobspool"; $TMP = '/tmp'; # program -$TAR = '/bin/tar'; -$LYNX = '/usr/local/bin/lynx'; +$TAR = '/usr/bin/tar'; +$LYNX = '/usr/local/bin/lynx'; # /usr/ports/www/lynx $GREP = '/usr/bin/grep'; diff --git a/pttbbs/util/Makefile b/pttbbs/util/Makefile index e291cdee..3daa4579 100644 --- a/pttbbs/util/Makefile +++ b/pttbbs/util/Makefile @@ -1,4 +1,4 @@ -# $Id: Makefile,v 1.24 2003/02/17 18:37:48 in2 Exp $ +# $Id: Makefile,v 1.25 2003/03/28 13:39:29 in2 Exp $ BBSHOME?=$(HOME) OSTYPE!=uname @@ -37,6 +37,10 @@ PROGS= $(CPROGS) BM_money.sh backpasswd.sh mailog.sh opendice.sh\ toplazyBM.sh toplazyBBM.sh dailybackup.pl tarqueue.pl waterball.pl \ filtermail.pl getbackup.pl udnnews.pl rebuildaloha.pl railway_wrapper.pl +.if ${OSTYPE} == "FreeBSD" +CPROGS += diskstat +.endif + all: $(PROGS) bbsmail: bbsmail.c $(OBJS) @@ -162,6 +166,9 @@ bbsctl: bbsctl.c shmctl: shmctl.c $(OBJS) $(CC) $(CFLAGS) -o $@ $@.c $(OBJS) +diskstat: diskstat.c + $(CC) $(CFLAGS) -o diskstat diskstat.c -ldevstat + install: $(PROGS) install -d $(BBSHOME)/bin/ install -c -m 755 $(PROGS) $(BBSHOME)/bin/ -- cgit v1.2.3 From 84b91cda10d6d475d48dd7fb76516e9d07a6b11d Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Fri, 28 Mar 2003 13:40:18 +0000 Subject: add diskstat.c git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@740 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/diskstat.c | 99 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 pttbbs/util/diskstat.c diff --git a/pttbbs/util/diskstat.c b/pttbbs/util/diskstat.c new file mode 100644 index 00000000..86b6291c --- /dev/null +++ b/pttbbs/util/diskstat.c @@ -0,0 +1,99 @@ +#include <stdio.h> +#include <stdlib.h> +#include <sys/dkstat.h> +#include <devstat.h> +#include <err.h> + +int main(int argc, char **argv) +{ + return 0; +} + +#if 0 +typedef enum { + DS_MATCHTYPE_NONE, + DS_MATCHTYPE_SPEC, + DS_MATCHTYPE_PATTERN +} last_match_type; +last_match_type last_type; +struct device_selection *dev_select; +long generation; +int num_devices, num_selected; +int num_selections; +long select_generation; +struct devstat_match *matches = NULL; +int num_matches = 0; +char **specified_devices; +int num_devices_specified = 0; + +int +dsinit(int maxshowdevs, struct statinfo *s1, struct statinfo *s2, + struct statinfo *s3) +{ + generation = 0; + num_devices = 0; + num_selected = 0; + num_selections = 0; + select_generation = 0; + last_type = DS_MATCHTYPE_NONE; + + if (getdevs(s1) == -1) + errx(1, "%s", devstat_errbuf); + + num_devices = s1->dinfo->numdevs; + generation = s1->dinfo->generation; + + dev_select = NULL; + + /* + * At this point, selectdevs will almost surely indicate that the + * device list has changed, so we don't look for return values of 0 + * or 1. If we get back -1, though, there is an error. + */ + if (selectdevs(&dev_select, &num_selected, &num_selections, + &select_generation, generation, s1->dinfo->devices, + num_devices, NULL, 0, NULL, 0, DS_SELECT_ADD, + maxshowdevs, 0) == -1) + errx(1, "%s", devstat_errbuf); + + return(1); +} + +static void +dinfo(dn, lc, now, then) + int dn, lc; + struct statinfo *now, *then; +{ + long double transfers_per_second; + long double kb_per_transfer, mb_per_second; + long double elapsed_time, device_busy; + int di; + + di = dev_select[dn].position; + + elapsed_time = devstat_compute_etime(now->busy_time, + then ? then->busy_time : now->dinfo->devices[di].dev_creation_time); + + device_busy = devstat_compute_etime(now->dinfo->devices[di].busy_time, + then ? then->dinfo->devices[di].busy_time : + now->dinfo->devices[di].dev_creation_time); + + if ((device_busy == 0) && (transfers_per_second > 5)) + /* the device has been 100% busy, fake it because + * as long as the device is 100% busy the busy_time + * field in the devstat struct is not updated */ + device_busy = elapsed_time; + if (device_busy > elapsed_time) + /* this normally happens after one or more periods + * where the device has been 100% busy, correct it */ + device_busy = elapsed_time; + + /* + putlongdouble(kb_per_transfer, DISKROW + 1, lc, 5, 2, 0); + putlongdouble(transfers_per_second, DISKROW + 2, lc, 5, 0, 0); + putlongdouble(mb_per_second, DISKROW + 3, lc, 5, 2, 0); + putlongdouble(device_busy * 100 / elapsed_time, DISKROW + 4, lc, 5, 0, 0); + */ +} + +#endif -- cgit v1.2.3 From 372812302ef4bf1808c00f8adfa1f00a5f6ad984 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Fri, 28 Mar 2003 14:15:20 +0000 Subject: PRE_FORK git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@741 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/mbbsd.c | 15 +++++++++++++-- pttbbs/sample/pttbbs.conf | 4 ++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/pttbbs/mbbsd/mbbsd.c b/pttbbs/mbbsd/mbbsd.c index 00e4fa7a..97ba847a 100644 --- a/pttbbs/mbbsd/mbbsd.c +++ b/pttbbs/mbbsd/mbbsd.c @@ -1,4 +1,4 @@ -/* $Id: mbbsd.c,v 1.68 2003/03/24 10:28:24 in2 Exp $ */ +/* $Id: mbbsd.c,v 1.69 2003/03/28 14:15:20 in2 Exp $ */ #include "bbs.h" #define SOCKET_QLEN 4 @@ -1256,7 +1256,18 @@ daemon_login(int argc, char *argv[], char *envp[]) setuid(BBSUID); chdir(BBSHOME); - snprintf(buf, sizeof(buf), "run/mbbsd.%d.pid", listen_port); +#ifndef NO_FORK +#ifdef PRE_FORK + if( listen_port == 23 ){ // only pre-fork in port 23 + int i; + for( i = 0 ; i < PRE_FORK ; ++i ) + if( fork() <= 0 ) + break; + } +#endif +#endif + + snprintf(buf, sizeof(buf), "run/mbbsd.%d.%d.pid", listen_port, getpid()); if ((fp = fopen(buf, "w"))) { fprintf(fp, "%d\n", getpid()); fclose(fp); diff --git a/pttbbs/sample/pttbbs.conf b/pttbbs/sample/pttbbs.conf index 0b0e51d6..1903a6af 100644 --- a/pttbbs/sample/pttbbs.conf +++ b/pttbbs/sample/pttbbs.conf @@ -74,6 +74,10 @@ /* 設定最大可再買幾封信箱 (default: 1000) */ #define MAX_EXKEEPMAIL (1000) +/* 對於 port 23的, 會預先 fork 幾隻出來. 如此在系統負荷高的時候, + 仍可有好的上站率 */ +//#define PRE_FORK 10 + /* 前進站畫面 */ #define INSCREEN \ "前進站畫面 (請至 pttbbs.conf 修改您的前進站畫面)" -- cgit v1.2.3 From 1966f91de1a2b95fbd0a713877c92a9ad9e467ed Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Fri, 28 Mar 2003 14:30:40 +0000 Subject: show man path in DEBUG mode git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@742 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/announce.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pttbbs/mbbsd/announce.c b/pttbbs/mbbsd/announce.c index a1a5797b..e9068638 100644 --- a/pttbbs/mbbsd/announce.c +++ b/pttbbs/mbbsd/announce.c @@ -1,4 +1,4 @@ -/* $Id: announce.c,v 1.18 2003/01/16 11:58:04 kcwu Exp $ */ +/* $Id: announce.c,v 1.19 2003/03/28 14:30:40 in2 Exp $ */ #include "bbs.h" static void @@ -1443,6 +1443,9 @@ a_menu(char *maintitle, char *path, int lastlevel) fileheader_t *fhdr = &me.header[me.now - me.page]; if (!isvisible_man(&me)) break; +#ifdef DEBUG + vmsg("%s/%s", &path[11], fhdr->filename);; +#endif snprintf(fname, sizeof(fname), "%s/%s", path, fhdr->filename); if (*fhdr->filename == 'H' && fhdr->filename[1] == '.') { item_t item; -- cgit v1.2.3 From b6141a5d11a11b3bc233a55a8772693ce3658bb6 Mon Sep 17 00:00:00 2001 From: victor <victor@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Fri, 28 Mar 2003 15:14:26 +0000 Subject: fix add fav_line problem git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@743 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/board.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pttbbs/mbbsd/board.c b/pttbbs/mbbsd/board.c index a929fe99..84ab7e54 100644 --- a/pttbbs/mbbsd/board.c +++ b/pttbbs/mbbsd/board.c @@ -1,4 +1,4 @@ -/* $Id: board.c,v 1.112 2003/03/28 13:32:02 in2 Exp $ */ +/* $Id: board.c,v 1.113 2003/03/28 15:14:26 victor Exp $ */ #include "bbs.h" #define BRC_STRLEN 15 /* Length of board name */ #define BRC_MAXSIZE 24576 @@ -1253,7 +1253,8 @@ choose_board(int newflag) break; } setfav(0, BRD_FAV | BRD_LINE, 1, 0); - movefav(brdnum++, num); + nbrd[brdnum].bid = fav->nLines; + movefav(brdnum, num); favchange = 1; brdnum = -1; head = 9999; -- cgit v1.2.3 From 9d1530ed67d4f06ebf9163c561c86270a6f13094 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sat, 29 Mar 2003 08:01:49 +0000 Subject: diskstat git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@744 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/Makefile | 4 +- pttbbs/util/diskstat.c | 760 ++++++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 690 insertions(+), 74 deletions(-) diff --git a/pttbbs/util/Makefile b/pttbbs/util/Makefile index 3daa4579..6babd188 100644 --- a/pttbbs/util/Makefile +++ b/pttbbs/util/Makefile @@ -1,4 +1,4 @@ -# $Id: Makefile,v 1.25 2003/03/28 13:39:29 in2 Exp $ +# $Id: Makefile,v 1.26 2003/03/29 08:01:49 in2 Exp $ BBSHOME?=$(HOME) OSTYPE!=uname @@ -167,7 +167,7 @@ shmctl: shmctl.c $(OBJS) $(CC) $(CFLAGS) -o $@ $@.c $(OBJS) diskstat: diskstat.c - $(CC) $(CFLAGS) -o diskstat diskstat.c -ldevstat + $(CC) $(CFLAGS) -o diskstat diskstat.c -ldevstat -lkvm install: $(PROGS) install -d $(BBSHOME)/bin/ diff --git a/pttbbs/util/diskstat.c b/pttbbs/util/diskstat.c index 86b6291c..0eef081b 100644 --- a/pttbbs/util/diskstat.c +++ b/pttbbs/util/diskstat.c @@ -1,99 +1,715 @@ +#ifndef FreeBSD + #include <stdio.h> + int main(int argc, char **argv) + { + puts("sorry, this program is designed for FreeBSD only"); + return 0; + } +#else +/* + * Copyright (c) 1997, 1998 Kenneth D. Merry. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD: src/usr.sbin/iostat/iostat.c,v 1.17.2.2 2001/07/19 04:15:42 kris Exp $ + */ +/* + * Parts of this program are derived from the original FreeBSD iostat + * program: + */ +/*- + * Copyright (c) 1986, 1991, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ +/* + * Ideas for the new iostat statistics output modes taken from the NetBSD + * version of iostat: + */ +/* + * Copyright (c) 1996 John M. Vinopal + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed for the NetBSD Project + * by John M. Vinopal. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + + +#include <sys/param.h> +#include <sys/errno.h> +#include <sys/dkstat.h> + +#include <err.h> +#include <ctype.h> +#include <fcntl.h> +#include <kvm.h> #include <stdio.h> #include <stdlib.h> -#include <sys/dkstat.h> +#include <string.h> +#include <unistd.h> +#include <limits.h> #include <devstat.h> -#include <err.h> -int main(int argc, char **argv) -{ - return 0; -} +struct nlist namelist[] = { +#define X_TK_NIN 0 + { "_tk_nin" }, +#define X_TK_NOUT 1 + { "_tk_nout" }, +#define X_CP_TIME 2 + { "_cp_time" }, +#define X_HZ 3 + { "_hz" }, +#define X_STATHZ 4 + { "_stathz" }, +#define X_END 4 + { NULL }, +}; -#if 0 -typedef enum { - DS_MATCHTYPE_NONE, - DS_MATCHTYPE_SPEC, - DS_MATCHTYPE_PATTERN -} last_match_type; -last_match_type last_type; +struct statinfo cur, last; +int num_devices; struct device_selection *dev_select; -long generation; -int num_devices, num_selected; -int num_selections; -long select_generation; -struct devstat_match *matches = NULL; -int num_matches = 0; -char **specified_devices; -int num_devices_specified = 0; +int maxshowdevs; +int dflag = 1, Iflag = 0, Cflag = 0, Tflag = 0, oflag = 0, Kflag = 0, Bflag = 1; + +#define nlread(x, v) \ + kvm_read(kd, namelist[x].n_value, &(v), sizeof(v)) + +/* local function declarations */ +static void usage(void); +static void phdr(int signo); +static void devstats(int perf_select); +static void cpustats(void); +static void printresult(int p); + +static void +usage(void) +{ + /* + * We also support the following 'traditional' syntax: + * iostat [drives] [wait [count]] + * This isn't mentioned in the man page, or the usage statement, + * but it is supported. + */ + fprintf(stderr, "usage: iostat [-CdhIKoT?] [-c count] [-M core]" + " [-n devs] [-N system]\n" + "\t [-t type,if,pass] [-w wait] [drives]\n"); +} int -dsinit(int maxshowdevs, struct statinfo *s1, struct statinfo *s2, - struct statinfo *s3) +main(int argc, char **argv) { - generation = 0; - num_devices = 0; - num_selected = 0; - num_selections = 0; - select_generation = 0; - last_type = DS_MATCHTYPE_NONE; - - if (getdevs(s1) == -1) + int c; + register int i; + int tflag = 0, hflag = 0, cflag = 0, wflag = 1, nflag = 0; + int count = 0, waittime = 2; + char *memf = NULL, *nlistf = NULL; + struct devstat_match *matches; + int num_matches = 0; + char errbuf[_POSIX2_LINE_MAX]; + kvm_t *kd; + int hz, stathz; + int headercount; + long generation; + int num_devices_specified; + int num_selected, num_selections; + long select_generation; + char **specified_devices; + devstat_select_mode select_mode; + + matches = NULL; + maxshowdevs = 10; + + while ((c = getopt(argc, argv, "c:CdhIKM:n:N:ot:Tw:?")) != -1) { + switch(c) { + case 'c': + cflag++; + count = atoi(optarg); + if (count < 1) + errx(1, "count %d is < 1", count); + break; + case 'C': + Cflag++; + break; + case 'd': + dflag++; + break; + case 'h': + hflag++; + break; + case 'I': + Iflag++; + break; + case 'K': + Kflag++; + break; + case 'M': + memf = optarg; + break; + case 'n': + nflag++; + maxshowdevs = atoi(optarg); + if (maxshowdevs < 0) + errx(1, "number of devices %d is < 0", + maxshowdevs); + break; + case 'N': + nlistf = optarg; + break; + case 'o': + oflag++; + break; + case 't': + tflag++; + if (buildmatch(optarg, &matches, + &num_matches) != 0) + errx(1, "%s", devstat_errbuf); + break; + case 'T': + Tflag++; + break; + case 'w': + wflag++; + waittime = atoi(optarg); + if (waittime < 1) + errx(1, "wait time is < 1"); + break; + default: + usage(); + exit(1); + break; + } + } + + argc -= optind; + argv += optind; + + /* + * Discard setgid privileges if not the running kernel so that bad + * guys can't print interesting stuff from kernel memory. + */ + if (nlistf != NULL || memf != NULL) + setgid(getgid()); + + /* + * Make sure that the userland devstat version matches the kernel + * devstat version. If not, exit and print a message informing + * the user of his mistake. + */ + if (checkversion() < 0) errx(1, "%s", devstat_errbuf); - num_devices = s1->dinfo->numdevs; - generation = s1->dinfo->generation; +#if 0 + /* + * Figure out how many devices we should display. + */ + if (nflag == 0) { + if (oflag > 0) { + if ((dflag > 0) && (Cflag == 0) && (Tflag == 0)) + maxshowdevs = 5; + else if ((dflag > 0) && (Tflag > 0) && (Cflag == 0)) + maxshowdevs = 5; + else + maxshowdevs = 4; + } else { + if ((dflag > 0) && (Cflag == 0)) + maxshowdevs = 4; + else + maxshowdevs = 3; + } + } +#endif + + signal(SIGINT, printresult); + /* find out how many devices we have */ + if ((num_devices = getnumdevs()) < 0) + err(1, "can't get number of devices"); + + if ((cur.dinfo = (struct devinfo *)malloc(sizeof(struct devinfo))) == + NULL) + err(1, "devinfo malloc failed"); + if ((last.dinfo = (struct devinfo *)malloc(sizeof(struct devinfo))) == + NULL) + err(1, "devinfo malloc failed"); + bzero(cur.dinfo, sizeof(struct devinfo)); + bzero(last.dinfo, sizeof(struct devinfo)); + + /* + * Grab all the devices. We don't look to see if the list has + * changed here, since it almost certainly has. We only look for + * errors. + */ + if (getdevs(&cur) == -1) + errx(1, "%s", devstat_errbuf); + + num_devices = cur.dinfo->numdevs; + generation = cur.dinfo->generation; + + /* + * If the user specified any devices on the command line, see if + * they are in the list of devices we have now. + */ + if ((specified_devices = (char **)malloc(sizeof(char *))) == NULL) + err(1, "specified_devices malloc failed"); + for (num_devices_specified = 0; *argv; ++argv) { + if (isdigit(**argv)) + break; + num_devices_specified++; + specified_devices = (char **)realloc(specified_devices, + sizeof(char *) * + num_devices_specified); + specified_devices[num_devices_specified - 1] = *argv; + + } + if (nflag == 0 && maxshowdevs < num_devices_specified) + maxshowdevs = num_devices_specified; dev_select = NULL; + if ((num_devices_specified == 0) && (num_matches == 0)) + select_mode = DS_SELECT_ADD; + else + select_mode = DS_SELECT_ONLY; + /* * At this point, selectdevs will almost surely indicate that the * device list has changed, so we don't look for return values of 0 * or 1. If we get back -1, though, there is an error. */ - if (selectdevs(&dev_select, &num_selected, &num_selections, - &select_generation, generation, s1->dinfo->devices, - num_devices, NULL, 0, NULL, 0, DS_SELECT_ADD, - maxshowdevs, 0) == -1) + if (selectdevs(&dev_select, &num_selected, + &num_selections, &select_generation, + generation, cur.dinfo->devices, num_devices, + matches, num_matches, + specified_devices, num_devices_specified, + select_mode, maxshowdevs, hflag) == -1) errx(1, "%s", devstat_errbuf); - return(1); + /* + * Look for the traditional wait time and count arguments. + */ + if (*argv) { + waittime = atoi(*argv); + + /* Let the user know he goofed, but keep going anyway */ + if (wflag != 0) + warnx("discarding previous wait interval, using" + " %d instead", waittime); + wflag++; + + if (*++argv) { + count = atoi(*argv); + if (cflag != 0) + warnx("discarding previous count, using %d" + " instead", count); + cflag++; + } else + count = -1; + } + + /* + * If the user specified a count, but not an interval, we default + * to an interval of 1 second. + */ + if ((wflag == 0) && (cflag > 0)) + waittime = 1; + + /* + * If the user specified a wait time, but not a count, we want to + * go on ad infinitum. This can be redundant if the user uses the + * traditional method of specifying the wait, since in that case we + * already set count = -1 above. Oh well. + */ + if ((wflag > 0) && (cflag == 0)) + count = -1; + + kd = kvm_openfiles(nlistf, memf, NULL, O_RDONLY, errbuf); + + if (kd == 0) + errx(1, "kvm_openfiles: %s", errbuf); + + if (kvm_nlist(kd, namelist) == -1) + errx(1, "kvm_nlist: %s", kvm_geterr(kd)); + + (void)nlread(X_HZ, hz); + (void)nlread(X_STATHZ, stathz); + if (stathz) + hz = stathz; + + /* + * If the user stops the program (control-Z) and then resumes it, + * print out the header again. + */ + (void)signal(SIGCONT, phdr); + + for (headercount = 1;;) { + struct devinfo *tmp_dinfo; + long tmp; + double etime; + + if (!--headercount) { + phdr(0); + headercount = 20; + } + (void)kvm_read(kd, namelist[X_TK_NIN].n_value, + &cur.tk_nin, sizeof(cur.tk_nin)); + (void)kvm_read(kd, namelist[X_TK_NOUT].n_value, + &cur.tk_nout, sizeof(cur.tk_nout)); + (void)kvm_read(kd, namelist[X_CP_TIME].n_value, + cur.cp_time, sizeof(cur.cp_time)); + + tmp_dinfo = last.dinfo; + last.dinfo = cur.dinfo; + cur.dinfo = tmp_dinfo; + + last.busy_time = cur.busy_time; + + /* + * Here what we want to do is refresh our device stats. + * getdevs() returns 1 when the device list has changed. + * If the device list has changed, we want to go through + * the selection process again, in case a device that we + * were previously displaying has gone away. + */ + switch (getdevs(&cur)) { + case -1: + errx(1, "%s", devstat_errbuf); + break; + case 1: { + int retval; + + num_devices = cur.dinfo->numdevs; + generation = cur.dinfo->generation; + retval = selectdevs(&dev_select, &num_selected, + &num_selections, &select_generation, + generation, cur.dinfo->devices, + num_devices, matches, num_matches, + specified_devices, + num_devices_specified, + select_mode, maxshowdevs, hflag); + switch(retval) { + case -1: + errx(1, "%s", devstat_errbuf); + break; + case 1: + phdr(0); + headercount = 20; + break; + default: + break; + } + break; + } + default: + break; + } + + /* + * We only want to re-select devices if we're in 'top' + * mode. This is the only mode where the devices selected + * could actually change. + */ + if (hflag > 0) { + int retval; + retval = selectdevs(&dev_select, &num_selected, + &num_selections, &select_generation, + generation, cur.dinfo->devices, + num_devices, matches, num_matches, + specified_devices, + num_devices_specified, + select_mode, maxshowdevs, hflag); + switch(retval) { + case -1: + errx(1,"%s", devstat_errbuf); + break; + case 1: + phdr(0); + headercount = 20; + break; + default: + break; + } + } + + tmp = cur.tk_nin; + cur.tk_nin -= last.tk_nin; + last.tk_nin = tmp; + tmp = cur.tk_nout; + cur.tk_nout -= last.tk_nout; + last.tk_nout = tmp; + + etime = 0.0; + +#define X(fld) tmp = cur.fld[i]; cur.fld[i] -= last.fld[i]; last.fld[i] = tmp + + for (i = 0; i < CPUSTATES; i++) { + X(cp_time); + etime += cur.cp_time[i]; + } + if (etime == 0.0) + etime = 1.0; + etime /= (float)hz; + if ((dflag == 0) || (Tflag > 0)) + printf("%4.0f%5.0f", cur.tk_nin / etime, + cur.tk_nout/etime); + devstats(hflag); + if ((dflag == 0) || (Cflag > 0)) + cpustats(); + printf("\n"); + fflush(stdout); + + if (count >= 0 && --count <= 0) + break; + + sleep(waittime); + } + + exit(0); } static void -dinfo(dn, lc, now, then) - int dn, lc; - struct statinfo *now, *then; +phdr(int signo) { - long double transfers_per_second; - long double kb_per_transfer, mb_per_second; - long double elapsed_time, device_busy; - int di; - - di = dev_select[dn].position; - - elapsed_time = devstat_compute_etime(now->busy_time, - then ? then->busy_time : now->dinfo->devices[di].dev_creation_time); - - device_busy = devstat_compute_etime(now->dinfo->devices[di].busy_time, - then ? then->dinfo->devices[di].busy_time : - now->dinfo->devices[di].dev_creation_time); - - if ((device_busy == 0) && (transfers_per_second > 5)) - /* the device has been 100% busy, fake it because - * as long as the device is 100% busy the busy_time - * field in the devstat struct is not updated */ - device_busy = elapsed_time; - if (device_busy > elapsed_time) - /* this normally happens after one or more periods - * where the device has been 100% busy, correct it */ - device_busy = elapsed_time; - - /* - putlongdouble(kb_per_transfer, DISKROW + 1, lc, 5, 2, 0); - putlongdouble(transfers_per_second, DISKROW + 2, lc, 5, 0, 0); - putlongdouble(mb_per_second, DISKROW + 3, lc, 5, 2, 0); - putlongdouble(device_busy * 100 / elapsed_time, DISKROW + 4, lc, 5, 0, 0); - */ + register int i; + int printed; + + if ((dflag == 0) || (Tflag > 0)) + (void)printf(" tty"); + for (i = 0, printed=0;(i < num_devices) && (printed < maxshowdevs);i++){ + int di; + if ((dev_select[i].selected != 0) + && (dev_select[i].selected <= maxshowdevs)) { + di = dev_select[i].position; + if (oflag > 0) + (void)printf("%12.6s%d ", + cur.dinfo->devices[di].device_name, + cur.dinfo->devices[di].unit_number); + else + printf("%4s%d ", + cur.dinfo->devices[di].device_name, + cur.dinfo->devices[di].unit_number); + printed++; + } + } + if ((dflag == 0) || (Cflag > 0)) + (void)printf(" cpu\n"); + else + (void)printf("\n"); + + if ((dflag == 0) || (Tflag > 0)) + (void)printf(" tin tout"); + + for (i=0, printed = 0;(i < num_devices) && (printed < maxshowdevs);i++){ + if ((dev_select[i].selected != 0) + && (dev_select[i].selected <= maxshowdevs)) { + if (oflag > 0) { + if (Iflag == 0) + (void)printf(" sps tps msps "); + else + (void)printf(" blk xfr msps "); + } else { + if(Bflag) + printf(" busy "); + else if (Iflag == 0) + printf(" KB/t tps MB/s "); + else + printf(" KB/t xfrs MB "); + } + printed++; + } + } + if ((dflag == 0) || (Cflag > 0)) + (void)printf(" us ni sy in id\n"); + else + printf("\n"); + } -#endif +int counttimes, busydata[1024]; + +static void printresult(int p) +{ + int dn; + for (dn = 0; dn < num_devices; dn++) + printf(" %3d%% ", (busydata[dn] / counttimes)); + printf("\n"); + exit(0); +} + +static void +devstats(int perf_select) +{ + register int dn; + long double transfers_per_second; + long double kb_per_transfer, mb_per_second; + u_int64_t total_bytes, total_transfers, total_blocks; + long double busy_seconds; + long double total_mb; + long double blocks_per_second, ms_per_transaction; + long double device_busy; + + /* + * Calculate elapsed time up front, since it's the same for all + * devices. + */ + busy_seconds = compute_etime(cur.busy_time, last.busy_time); + + for (dn = 0; dn < num_devices; dn++) { + int di; + + if (((perf_select == 0) && (dev_select[dn].selected == 0)) + || (dev_select[dn].selected > maxshowdevs)) + continue; + + di = dev_select[dn].position; + + device_busy = compute_etime(cur.dinfo->devices[di].busy_time, + last.dinfo->devices[di].busy_time); + + busydata[dn] += (int)(device_busy*100/busy_seconds); + if (compute_stats(&cur.dinfo->devices[di], + &last.dinfo->devices[di], busy_seconds, + &total_bytes, &total_transfers, + &total_blocks, &kb_per_transfer, + &transfers_per_second, &mb_per_second, + &blocks_per_second, &ms_per_transaction)!= 0) + errx(1, "%s", devstat_errbuf); + + if (perf_select != 0) { + dev_select[dn].bytes = total_bytes; + if ((dev_select[dn].selected == 0) + || (dev_select[dn].selected > maxshowdevs)) + continue; + } + + if (Kflag) { + int block_size = cur.dinfo->devices[di].block_size; + total_blocks = total_blocks * (block_size ? + block_size : 512) / 1024; + } + + if (oflag > 0) { + int msdig = (ms_per_transaction < 100.0) ? 1 : 0; + + if (Iflag == 0) + printf("%4.0Lf%4.0Lf%5.*Lf ", + blocks_per_second, + transfers_per_second, + msdig, + ms_per_transaction); + else + printf("%4.1qu%4.1qu%5.*Lf ", + total_blocks, + total_transfers, + msdig, + ms_per_transaction); + } else { + if (Bflag) + printf(" %3d%% ", (int)(device_busy*100/busy_seconds)); + else if (Iflag == 0){ + printf(" %5.2Lf %3.0Lf %5.2Lf ", + kb_per_transfer, + transfers_per_second, + mb_per_second); + + } + else { + total_mb = total_bytes; + total_mb /= 1024 * 1024; + + printf(" %5.2Lf %3.1qu %5.2Lf ", + kb_per_transfer, + total_transfers, + total_mb); + } + } + } + ++counttimes; +} + +static void +cpustats(void) +{ + register int state; + double time; + + time = 0.0; + + for (state = 0; state < CPUSTATES; ++state) + time += cur.cp_time[state]; + for (state = 0; state < CPUSTATES; ++state) + printf("%3.0f", + 100. * cur.cp_time[state] / (time ? time : 1)); +} +#endif // FreeBSD -- cgit v1.2.3 From f54197b0ef9cfb15ed9d7201d14639e2a7afc9df Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sat, 29 Mar 2003 09:42:48 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@745 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/.cvsignore | 1 + 1 file changed, 1 insertion(+) diff --git a/pttbbs/util/.cvsignore b/pttbbs/util/.cvsignore index 28defeaa..4e206253 100644 --- a/pttbbs/util/.cvsignore +++ b/pttbbs/util/.cvsignore @@ -42,3 +42,4 @@ bbsctl mandex shmctl indexuser +diskstat -- cgit v1.2.3 From 408c58ec3136251732b1684bc506d7f314c47f5e Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sat, 29 Mar 2003 09:52:18 +0000 Subject: reprint header when SIGINT. discard first data git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@746 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/diskstat.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pttbbs/util/diskstat.c b/pttbbs/util/diskstat.c index 0eef081b..f4146026 100644 --- a/pttbbs/util/diskstat.c +++ b/pttbbs/util/diskstat.c @@ -596,12 +596,14 @@ phdr(int signo) } -int counttimes, busydata[1024]; +int counttimes = -1, busydata[1024]; static void printresult(int p) { int dn; - for (dn = 0; dn < num_devices; dn++) + printf("\n"); + phdr(0); + for (dn = 0; dn < maxshowdevs; dn++) printf(" %3d%% ", (busydata[dn] / counttimes)); printf("\n"); exit(0); -- cgit v1.2.3 From c1b34e975bf5d56afaab5a2db73b5a821cee78d0 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sat, 29 Mar 2003 09:53:34 +0000 Subject: add installdiskstat git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@747 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/Makefile | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pttbbs/util/Makefile b/pttbbs/util/Makefile index 6babd188..5dfe6c19 100644 --- a/pttbbs/util/Makefile +++ b/pttbbs/util/Makefile @@ -1,4 +1,4 @@ -# $Id: Makefile,v 1.26 2003/03/29 08:01:49 in2 Exp $ +# $Id: Makefile,v 1.27 2003/03/29 09:53:34 in2 Exp $ BBSHOME?=$(HOME) OSTYPE!=uname @@ -169,6 +169,11 @@ shmctl: shmctl.c $(OBJS) diskstat: diskstat.c $(CC) $(CFLAGS) -o diskstat diskstat.c -ldevstat -lkvm +installdiskstat: diskstat + cp -f diskstat /usr/local/bin/ + chgrp kmem /usr/local/bin/diskstat + chmod 2755 /usr/local/bin/diskstat + install: $(PROGS) install -d $(BBSHOME)/bin/ install -c -m 755 $(PROGS) $(BBSHOME)/bin/ -- cgit v1.2.3 From cff3d0edeeb3d7242a341ee11fbb16b3ffa96403 Mon Sep 17 00:00:00 2001 From: victor <victor@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sun, 30 Mar 2003 03:00:10 +0000 Subject: tag fav line git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@748 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/board.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pttbbs/mbbsd/board.c b/pttbbs/mbbsd/board.c index 84ab7e54..04edce42 100644 --- a/pttbbs/mbbsd/board.c +++ b/pttbbs/mbbsd/board.c @@ -1,4 +1,4 @@ -/* $Id: board.c,v 1.113 2003/03/28 15:14:26 victor Exp $ */ +/* $Id: board.c,v 1.114 2003/03/30 03:00:10 victor Exp $ */ #include "bbs.h" #define BRC_STRLEN 15 /* Length of board name */ #define BRC_MAXSIZE 24576 @@ -908,7 +908,7 @@ show_brdlist(int head, int clsflag, int newflag) if (head < brdnum) { ptr = &nbrd[head++]; if(ptr->myattr & BRD_LINE){ - prints("%5d ------------ ------------------------------------------", head); + prints("%5d %c ------------ ------------------------------------------", head, ptr->myattr & BRD_TAG ? 'D' : ' '); continue; } if (class_bid == 1) -- cgit v1.2.3 From 3181a7555a3dc5eb65bda294def5352169db9f2c Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sun, 30 Mar 2003 06:52:09 +0000 Subject: A-E git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@749 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/user.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/pttbbs/mbbsd/user.c b/pttbbs/mbbsd/user.c index 68c7f048..4059a275 100644 --- a/pttbbs/mbbsd/user.c +++ b/pttbbs/mbbsd/user.c @@ -1,4 +1,4 @@ -/* $Id: user.c,v 1.51 2003/03/26 11:06:05 in2 Exp $ */ +/* $Id: user.c,v 1.52 2003/03/30 06:52:09 in2 Exp $ */ #include "bbs.h" static char *sex[8] = { @@ -215,10 +215,11 @@ static void Customize(void) prints("%-30s%10s\n", "D. 目前的心情", mindbuf); prints("%-30s%10s\n", "E. 高亮度顯示我的最愛", ((cuser.uflag2 & FAVNOHILIGHT) ? "否" : "是")); - getdata(b_lines - 1, 0, "請按 [A-5] 切換設定,按 [Return] 結束:", + getdata(b_lines - 1, 0, "請按 [A-E] 切換設定,按 [Return] 結束:", ans, sizeof(ans), DOECHO); switch( ans[0] ){ + case 'A': case 'a':{ int currentset = cuser.uflag2 & WATER_MASK; currentset = (currentset + 1) % 3; @@ -227,12 +228,15 @@ static void Customize(void) vmsg("修正水球模式後請正常離線再重新上線"); } break; + case 'B': case 'b': cuser.userlevel ^= PERM_NOOUTMAIL; break; + case 'C': case 'c': cuser.uflag2 ^= FAVNEW_FLAG; break; + case 'D': case 'd':{ getdata(b_lines - 1, 0, "現在的心情? ", mindbuf, sizeof(mindbuf), DOECHO); @@ -244,6 +248,7 @@ static void Customize(void) memcpy(currutmp->mind, mindbuf, 4); } break; + case 'E': case 'e': cuser.uflag2 ^= FAVNOHILIGHT; break; -- cgit v1.2.3 From 764d155c9c35725ed60ac7c6b4bd63a7d2b407ce Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sun, 30 Mar 2003 07:40:20 +0000 Subject: =?UTF-8?q?=EF=BF=BD=EF=BF=BD=EF=BF=BDT=EF=BF=BD=EF=BF=BD=EF=BF=BD?= =?UTF-8?q?p=EF=BF=BD=EF=BF=BD=EF=BF=BD@=EF=BF=BD=EF=BF=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@750 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/diskstat.c | 35 ++++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/pttbbs/util/diskstat.c b/pttbbs/util/diskstat.c index f4146026..829613f9 100644 --- a/pttbbs/util/diskstat.c +++ b/pttbbs/util/diskstat.c @@ -543,6 +543,18 @@ phdr(int signo) { register int i; int printed; + static char firsttime = 1; + if( firsttime ){ + firsttime = 0; + for( i = 0 ; i < num_devices ; ++i ){ + int di = dev_select[i].position; + if( strcmp(cur.dinfo->devices[di].device_name, "ad") != 0 && + strcmp(cur.dinfo->devices[di].device_name, "da") != 0 ){ + maxshowdevs = i; + break; + } + } + } if ((dflag == 0) || (Tflag > 0)) (void)printf(" tty"); @@ -556,7 +568,7 @@ phdr(int signo) cur.dinfo->devices[di].device_name, cur.dinfo->devices[di].unit_number); else - printf("%4s%d ", + printf("%6s%d", cur.dinfo->devices[di].device_name, cur.dinfo->devices[di].unit_number); printed++; @@ -580,7 +592,7 @@ phdr(int signo) (void)printf(" blk xfr msps "); } else { if(Bflag) - printf(" busy "); + printf(" busy"); else if (Iflag == 0) printf(" KB/t tps MB/s "); else @@ -602,10 +614,13 @@ static void printresult(int p) { int dn; printf("\n"); - phdr(0); - for (dn = 0; dn < maxshowdevs; dn++) - printf(" %3d%% ", (busydata[dn] / counttimes)); - printf("\n"); + if( counttimes > 0 ){ + printf("--- diskstat statistics (%d samples)---\n", counttimes); + phdr(0); + for (dn = 0; dn < maxshowdevs; dn++) + printf(" %5.1f%%", ((float)busydata[dn] / 10 / counttimes)); + printf("\n"); + } exit(0); } @@ -628,7 +643,7 @@ devstats(int perf_select) busy_seconds = compute_etime(cur.busy_time, last.busy_time); for (dn = 0; dn < num_devices; dn++) { - int di; + int di, thisbusy; if (((perf_select == 0) && (dev_select[dn].selected == 0)) || (dev_select[dn].selected > maxshowdevs)) @@ -639,7 +654,9 @@ devstats(int perf_select) device_busy = compute_etime(cur.dinfo->devices[di].busy_time, last.dinfo->devices[di].busy_time); - busydata[dn] += (int)(device_busy*100/busy_seconds); + thisbusy = device_busy*1000/busy_seconds; + busydata[dn] += thisbusy; + if (compute_stats(&cur.dinfo->devices[di], &last.dinfo->devices[di], busy_seconds, &total_bytes, &total_transfers, @@ -678,7 +695,7 @@ devstats(int perf_select) ms_per_transaction); } else { if (Bflag) - printf(" %3d%% ", (int)(device_busy*100/busy_seconds)); + printf(" %5.1f%%", (float)thisbusy / 10); else if (Iflag == 0){ printf(" %5.2Lf %3.0Lf %5.2Lf ", kb_per_transfer, -- cgit v1.2.3 From 45349dc5075ef8902a97b4b0411262f93ada33d7 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sun, 30 Mar 2003 07:43:38 +0000 Subject: printresult() after normal terminated git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@751 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/diskstat.c | 1 + 1 file changed, 1 insertion(+) diff --git a/pttbbs/util/diskstat.c b/pttbbs/util/diskstat.c index 829613f9..d6988156 100644 --- a/pttbbs/util/diskstat.c +++ b/pttbbs/util/diskstat.c @@ -535,6 +535,7 @@ main(int argc, char **argv) sleep(waittime); } + printresult(0); exit(0); } -- cgit v1.2.3 From b8d65bcbeefc6082a8d54fa8c9226a98738e7d76 Mon Sep 17 00:00:00 2001 From: victor <victor@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sun, 30 Mar 2003 15:36:47 +0000 Subject: check favline num while logging out git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@752 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/board.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/pttbbs/mbbsd/board.c b/pttbbs/mbbsd/board.c index 04edce42..c0e7774e 100644 --- a/pttbbs/mbbsd/board.c +++ b/pttbbs/mbbsd/board.c @@ -1,4 +1,4 @@ -/* $Id: board.c,v 1.114 2003/03/30 03:00:10 victor Exp $ */ +/* $Id: board.c,v 1.115 2003/03/30 15:36:47 victor Exp $ */ #include "bbs.h" #define BRC_STRLEN 15 /* Length of board name */ #define BRC_MAXSIZE 24576 @@ -527,10 +527,15 @@ save_brdbuf(void) return; #endif - for( r = w = 0 ; r < fav->nDatas ; ++r ) + fav->nLines = 0; + for( r = w = 0 ; r < fav->nDatas ; ++r ){ if( ( fav->b[r].attr & BRD_LINE ) || - (fav->b[r].attr & BRD_FAV && bcache[fav->b[r].bid - 1].brdname[0])) + (fav->b[r].attr & BRD_FAV && bcache[fav->b[r].bid - 1].brdname[0])){ fav->b[w++] = fav->b[r]; + if(fav->b[w].attr & BRD_LINE) + fav->nLines--; + } + } fav->nDatas = w; setuserfile(fname, FAV3); if( (fd = open(fname, O_WRONLY | O_CREAT, 0600)) != -1 ){ -- cgit v1.2.3 From a9d417d906d58373591da22002094a94bb57f216 Mon Sep 17 00:00:00 2001 From: ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Mon, 31 Mar 2003 06:26:48 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@753 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/web/Makefile | 2 +- pttbbs/web/mod_ptt.c | 94 ++------- pttbbs/web/mod_ptt.h | 6 +- pttbbs/web/util_cache.c | 520 ----------------------------------------------- pttbbs/web/util_passwd.c | 141 ------------- pttbbs/web/util_record.c | 246 ---------------------- 6 files changed, 15 insertions(+), 994 deletions(-) delete mode 100755 pttbbs/web/util_cache.c delete mode 100755 pttbbs/web/util_passwd.c delete mode 100755 pttbbs/web/util_record.c diff --git a/pttbbs/web/Makefile b/pttbbs/web/Makefile index 42a1a84a..095610b3 100644 --- a/pttbbs/web/Makefile +++ b/pttbbs/web/Makefile @@ -1,5 +1,5 @@ all: mod_ptt.c mod_ptt.h - apxs -I ../include -c mod_ptt.c util_cache.c util_passwd.c util_record.c + apxs -I ../include -c mod_ptt.c ../util/util_cache.c ../util/util_passwd.c ../util/util_record.c cp mod_ptt.so /usr/local/libexec/apache/mod_ptt.so chmod 775 /usr/local/libexec/apache/mod_ptt.so clean: diff --git a/pttbbs/web/mod_ptt.c b/pttbbs/web/mod_ptt.c index be4a8071..ee32ede4 100644 --- a/pttbbs/web/mod_ptt.c +++ b/pttbbs/web/mod_ptt.c @@ -20,6 +20,7 @@ static table *static_calls_made = NULL; static pool *ptt_pool = NULL; static pool *ptt_subpool = NULL; + module MODULE_VAR_EXPORT ptt_module; excfg * our_dconfig(request_rec *r) { @@ -29,16 +30,9 @@ excfg * our_dconfig(request_rec *r) static void setup_module_cells() { - /* - * If we haven't already allocated our module-private pool, do so now. - */ if (ptt_pool == NULL) { ptt_pool = ap_make_sub_pool(NULL); }; - /* - * Likewise for the table of routine/environment pairs we visit outside of - * request context. - */ if (static_calls_made == NULL) { static_calls_made = ap_make_table(ptt_pool, 16); }; @@ -51,34 +45,18 @@ static int ptt_handler(request_rec *r) int i; excfg *dcfg; + dcfg = our_dconfig(r); - //resolve_utmp(); - //resolve_boards(); - // resolve_garbage(); - // resolve_fcache(); r->content_type = "text/html"; - ap_soft_timeout("send ptt call trace", r); ap_send_http_header(r); -#ifdef CHARSET_EBCDIC - /* Server-generated response, converted */ - ap_bsetflag(r->connection->client, B_EBCDIC2ASCII, r->ebcdic.conv_out = 1); -#endif - /* - * If we're only supposed to send header information (HEAD request), we're - * already there. - */ if (r->header_only) { ap_kill_timeout(r); return OK; } - /* - * Now send our actual output. Since we tagged this as being - * "text/html", we need to embed any HTML. - */ ap_rputs(" ptt3 <P>\n", r); ap_rprintf(r, " Apache HTTP Server version: \"%s\"\n", @@ -92,79 +70,33 @@ static int ptt_handler(request_rec *r) ap_rprintf(r,"r->unparsed_uri : %s <br>",r->unparsed_uri); ap_rprintf(r,"r->handler : %s <br>",r->handler); ap_rprintf(r,"r->content_type : %s <br>",r->content_type); - ap_rprintf(r, " Server built: \"%s\"\n", ap_get_server_built()); - for(i = 0; i++ < numboards; i++) - ap_rprintf(r,"%s %s<br>",bcache[i].brdname,bcache[i].title); - /* - * We're all done, so cancel the timeout we set. Since this is probably - * the end of the request we *could* assume this would be done during - * post-processing - but it's possible that another handler might be - * called and inherit our outstanding timer. Not good; to each its own. - */ + + ap_rprintf(r, " Server built: \"%s\"<br>", ap_get_server_built()); + ap_rprintf(r, " numboards: \"%d\"<br>", numboards); + + for(i = 0; i < 10; i++) + ap_rprintf(r,"%d. %s %s<br>",i,bcache[i].brdname,bcache[i].title); + + // for(i = 0; i < 10 /*numboards*/; i++) + // ap_rprintf(r,"%s %s<br>",bcache[i].brdname,bcache[i].title); ap_kill_timeout(r); - /* - * We did what we wanted to do, so tell the rest of the server we - * succeeded. - */ return OK; } -/*--------------------------------------------------------------------------*/ -/* */ -/* Now let's declare routines for each of the callback phase in order. */ -/* (That's the order in which they're listed in the callback list, *not */ -/* the order in which the server calls them! See the command_rec */ -/* declaration near the bottom of this file.) Note that these may be */ -/* called for situations that don't relate primarily to our function - in */ -/* other words, the fixup handler shouldn't assume that the request has */ -/* to do with "example" stuff. */ -/* */ -/* With the exception of the content handler, all of our routines will be */ -/* called for each request, unless an earlier handler from another module */ -/* aborted the sequence. */ -/* */ -/* Handlers that are declared as "int" can return the following: */ -/* */ /* OK Handler accepted the request and did its thing with it. */ /* DECLINED Handler took no action. */ /* HTTP_mumble Handler looked at request and found it wanting. */ -/* */ -/* What the server does after calling a module handler depends upon the */ -/* handler's return value. In all cases, if the handler returns */ -/* DECLINED, the server will continue to the next module with an handler */ -/* for the current phase. However, if the handler return a non-OK, */ -/* non-DECLINED status, the server aborts the request right there. If */ -/* the handler returns OK, the server's next action is phase-specific; */ -/* see the individual handler comments below for details. */ -/* */ -/*--------------------------------------------------------------------------*/ -/* - * This function is called during server initialisation. Any information - * that needs to be recorded must be in static cells, since there's no - * configuration record. - * - * There is no return value. - */ static void ptt_child_init(server_rec *s, pool *p) { char *note; char *sname = s->server_hostname; + attach_SHM(); + - //resolve_utmp(); - //resolve_boards(); - //resolve_garbage(); - //resolve_fcache(); - /* - * Set up any module cells that ought to be initialised. - */ setup_module_cells(); - /* - * The arbitrary text we add to our trace entry indicates for which server - * we're being called. - */ sname = (sname != NULL) ? sname : ""; note = ap_pstrcat(p, "ptt_child_init(", sname, ")", NULL); } diff --git a/pttbbs/web/mod_ptt.h b/pttbbs/web/mod_ptt.h index 2d7946b9..125046d6 100644 --- a/pttbbs/web/mod_ptt.h +++ b/pttbbs/web/mod_ptt.h @@ -5,11 +5,7 @@ #include "http_main.h" #include "http_protocol.h" #include "util_script.h" -#include "config.h" -#include "pttstruct.h" -#include "modes.h" -#include "common.h" -#include "proto.h" +#include "bbs.h" #include <stdio.h> diff --git a/pttbbs/web/util_cache.c b/pttbbs/web/util_cache.c deleted file mode 100755 index 7bfb67cc..00000000 --- a/pttbbs/web/util_cache.c +++ /dev/null @@ -1,520 +0,0 @@ -/* $Id: util_cache.c,v 1.2 2003/03/24 20:44:09 ptt Exp $ */ -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <signal.h> -#include <unistd.h> -#include <fcntl.h> -#include <ctype.h> -#include <errno.h> -#include <time.h> -#include <sys/types.h> -#include <sys/types.h> -#include <sys/mman.h> -#include <sys/ipc.h> -#include <sys/shm.h> -#include <sys/sem.h> - -#ifdef __FreeBSD__ -#include <machine/param.h> -#endif - -#include "config.h" -#include "pttstruct.h" -#include "common.h" -#include "perm.h" -#include "modes.h" -#include "proto.h" - -/* the reason for "safe_sleep" is that we may call sleep during - SIGALRM handler routine, while SIGALRM is blocked. - if we use the original sleep, we'll never wake up. */ -unsigned int safe_sleep(unsigned int seconds) { - /* jochang sleep有問題時用*/ - sigset_t set,oldset; - - sigemptyset(&set); - sigprocmask(SIG_BLOCK, &set, &oldset); - if(sigismember(&oldset, SIGALRM)) { - unsigned long retv; - sigemptyset(&set); - sigaddset(&set,SIGALRM); - sigprocmask(SIG_UNBLOCK,&set,NULL); - retv=sleep(seconds); - sigprocmask(SIG_BLOCK,&set,NULL); - return retv; - } - return sleep(seconds); -} - -void setapath(char *buf, char *boardname) { - sprintf(buf, "man/boards/%c/%s", boardname[0], boardname); -} - -static char *str_dotdir = ".DIR"; - -void setadir(char *buf, char *path) { - sprintf(buf, "%s/%s", path, str_dotdir); -} - -static void attach_err(int shmkey, char *name) { - fprintf(stderr, "[%s error] key = %x\n", name, shmkey); - fprintf(stderr, "errno = %d: %s\n", errno, strerror(errno)); - exit(1); -} - -void *attach_shm(int shmkey, int shmsize) { - void *shmptr; - int shmid; - - char *empty_addr; - /* set up one page in-accessible -- jochang */ - { - int fd = open("/dev/zero",O_RDONLY); - int size = ((shmsize + 4095) / 4096) * 4096; - - munmap( - (empty_addr=mmap(0,4096+size,PROT_NONE,MAP_PRIVATE,fd,0))+4096 - ,size); - - close(fd); - } - - shmid = shmget(shmkey, shmsize, 0); - if(shmid < 0) { - shmid = shmget(shmkey, shmsize, IPC_CREAT | 0600); - if(shmid < 0) - attach_err(shmkey, "shmget"); - shmptr = (void *)shmat(shmid, NULL, 0); - if(shmptr == (void *)-1) - attach_err(shmkey, "shmat"); - } else { - shmptr = (void *)shmat(shmid, NULL, 0); - if(shmptr == (void *)-1) - attach_err(shmkey, "shmat"); - } - - /* unmap the page -- jochang */ - { - munmap(empty_addr,4096); - } - return shmptr; -} - -#ifndef __FreeBSD__ -/* according to X/OPEN we have to define it ourselves */ -union semun { - int val; /* value for SETVAL */ - struct semid_ds *buf; /* buffer for IPC_STAT, IPC_SET */ - unsigned short int *array; /* array for GETALL, SETALL */ - struct seminfo *__buf; /* buffer for IPC_INFO */ -}; -#endif - -#define SEM_FLG 0600 /* semaphore mode */ - -/* ----------------------------------------------------- */ -/* semaphore : for critical section */ -/* ----------------------------------------------------- */ -void sem_init(int semkey,int *semid) { - union semun s; - - s.val=1; - *semid = semget(semkey, 1, 0); - if(*semid == -1) { - *semid = semget(semkey, 1, IPC_CREAT | SEM_FLG); - if(*semid == -1) - attach_err(semkey, "semget"); - semctl(*semid, 0, SETVAL, s); - } -} - -void sem_lock(int op,int semid) { - struct sembuf sops; - - sops.sem_num = 0; - sops.sem_flg = SEM_UNDO; - sops.sem_op = op; - semop(semid, &sops, 1); -} - -SHM_t *SHM; -int *GLOBALVAR; -boardheader_t *bcache; -int numboards = -1; - -void attach_SHM(void) -{ - SHM = attach_shm(SHM_KEY, sizeof(SHM_t)); - if( !SHM->loaded ) /* (uhash) assume fresh shared memory is zeroed */ - exit(1); - if( SHM->Btouchtime == 0 ) - SHM->Btouchtime = 1; - bcache = SHM->bcache; - - GLOBALVAR = SHM->GLOBALVAR; - if( SHM->Ptouchtime == 0 ) - SHM->Ptouchtime = 1; - - if( SHM->Ftouchtime == 0 ) - SHM->Ftouchtime = 1; - - bcache = SHM->bcache; - numboards = SHM->Bnumber; -} - -int setumoney(int uid, int money) { - SHM->money[uid-1]=money; - passwd_update_money(uid); - return SHM->money[uid-1]; -} - -int deumoney(int uid, int money) { - if(money<0 && SHM->money[uid-1]<-money) - return setumoney(uid,0); - else - return setumoney(uid,SHM->money[uid-1]+money); -} -int moneyof(int uid){ /* ptt 改進金錢處理效率 */ - return SHM->money[uid-1]; -} - -static unsigned string_hash(unsigned char *s) { - unsigned int v=0; - while(*s) { - v = (v << 8) | (v >> 24); - v ^= toupper(*s++); /* note this is case insensitive */ - } - return (v * 2654435769UL) >> (32 - HASH_BITS); -} - -void add_to_uhash(int n, char *id) { - int *p, h = string_hash(id); - strcpy(SHM->userid[n], id); - - p = &(SHM->hash_head[h]); - - while(*p != -1) - p = &(SHM->next_in_hash[*p]); - - SHM->next_in_hash[*p = n] = -1; -} - -/* note: after remove_from_uhash(), you should add_to_uhash() - (likely with a different name) */ -void remove_from_uhash(int n) { - int h = string_hash(SHM->userid[n]); - int *p = &(SHM->hash_head[h]); - - while(*p != -1 && *p != n) - p = &(SHM->next_in_hash[*p]); - if(*p == n) - *p = SHM->next_in_hash[n]; -} - -int searchuser(char *userid) { - int h,p; - - if(SHM == NULL) - attach_SHM(); /* for sloopy util programs */ - - h = string_hash(userid); - p = SHM->hash_head[h]; - - while(p != -1) { - if(strcasecmp(SHM->userid[p],userid) == 0) { - strcpy(userid,SHM->userid[p]); - return p + 1; - } - p = SHM->next_in_hash[p]; - } - return 0; -} -userec_t xuser; - -int getuser(char *userid) { - int uid; - if((uid = searchuser(userid))) - passwd_query(uid, &xuser); - return uid; -} - -void setuserid(int num, char *userid) { - if(num > 0 && num <= MAX_USERS) { - if(num > SHM->number) - SHM->number = num; - else - remove_from_uhash(num-1); - add_to_uhash(num-1,userid); - } -} - -/*-------------------------------------------------------*/ -/* .UTMP cache */ -/*-------------------------------------------------------*/ -void resolve_utmp() { - if(SHM == NULL) { - attach_SHM(); - if(SHM->UTMPuptime == 0) - SHM->UTMPuptime = SHM->UTMPnumber = 1; - } -} - -userinfo_t *currutmp = NULL; - -void getnewutmpent(userinfo_t *up) { - extern int errno; - register int i; - register userinfo_t *uentp; - - resolve_utmp(); - - for(i = 0; i < USHM_SIZE; i++) { - uentp = &(SHM->uinfo[i]); - if(!(uentp->pid)) { - memcpy(uentp, up, sizeof(userinfo_t)); - currutmp = uentp; - SHM->number++; - return; - } - } - exit(1); -} - -int apply_ulist(int (*fptr)(userinfo_t *)) { - register userinfo_t *uentp; - register int i, state; - - resolve_utmp(); - for(i = 0; i < USHM_SIZE; i++) { - uentp = &(SHM->uinfo[i]); - if(uentp->pid && (PERM_HIDE(currutmp) || !PERM_HIDE(uentp))) - if((state = (*fptr) (uentp))) - return state; - } - return 0; -} - -userinfo_t *search_ulist(int uid) { - register int i; - register userinfo_t *uentp; - - resolve_utmp(); - for(i = 0; i < USHM_SIZE; i++) { - uentp = &(SHM->uinfo[i]); - if(uid==uentp->uid) - return uentp; - } - return 0; -} - -/*-------------------------------------------------------*/ -/* .BOARDS cache */ -/*-------------------------------------------------------*/ -char *fn_board=BBSHOME"/"FN_BOARD; -static void reload_bcache() { - if(SHM->Bbusystate) { - safe_sleep(1); - } - else{ - puts("bcache is not loaded? resolve_boards() fail"); - exit(1); - } -} - -void resolve_boards() { - if(SHM == NULL) { - attach_SHM(); - if(SHM->Btouchtime == 0) - SHM->Btouchtime = 1; - } - - while(SHM->Buptime < SHM->Btouchtime) - reload_bcache(); - numboards = SHM->Bnumber; -} - -void touch_boards() { - time(&(SHM->Btouchtime)); - numboards = -1; - resolve_boards(); -} -void reset_board(int bid) -{ - int fd; - boardheader_t bh; - if(--bid<0)return; - if(SHM->Bbusystate==0) - { - SHM->Bbusystate = 1; - if((fd = open(fn_board, O_RDONLY)) > 0) { - lseek(fd, (off_t)(bid * sizeof(boardheader_t)), SEEK_SET); - read(fd, &bh , sizeof(boardheader_t)); - close(fd); - if(bh.brdname[0] && !strcmp(bh.brdname,bcache[bid].brdname)) - memcpy(&bcache[bid],&bh, sizeof(boardheader_t)); - } - SHM->Bbusystate = 0; - } -} -boardheader_t *getbcache(int bid) { /* Ptt改寫 */ - return bcache + bid - 1; -} - -void touchbtotal(int bid) { - SHM->total[bid - 1] = 0; - SHM->lastposttime[bid - 1] = 0; -} - - -int getbnum(char *bname) { - register int i; - register boardheader_t *bhdr; - - for(i = 0, bhdr = bcache; i++ < numboards; bhdr++) - if( - !strcasecmp(bname, bhdr->brdname)) - return i; - return 0; -} - -/*-------------------------------------------------------*/ -/* PTT cache */ -/*-------------------------------------------------------*/ -/* cachefor 動態看版 */ -void reload_pttcache(void) -{ - if(SHM->Pbusystate) - safe_sleep(1); - else { /* jochang: temporary workaround */ - fileheader_t item, subitem; - char pbuf[256], buf[256], *chr; - FILE *fp, *fp1, *fp2; - int id, section = 0; - - SHM->Pbusystate = 1; - SHM->max_film = 0; - bzero(SHM->notes, sizeof SHM->notes); - setapath(pbuf, "Note"); - setadir(buf, pbuf); - id = 0; - if((fp = fopen(buf, "r"))) { - while(fread(&item, sizeof(item), 1, fp)) { - if(item.title[3]=='<' && item.title[8]=='>') { - sprintf(buf,"%s/%s", pbuf, item.filename); - setadir(buf, buf); - if(!(fp1 = fopen(buf, "r"))) - continue; - SHM->next_refresh[section] = SHM->n_notes[section] = id; - section ++; - while(fread(&subitem, sizeof(subitem), 1, fp1)) { - sprintf(buf,"%s/%s/%s", pbuf, item.filename , - subitem.filename); - if(!(fp2=fopen(buf,"r"))) - continue; - fread(SHM->notes[id],sizeof(char), 200*11, fp2); - SHM->notes[id][200*11 - 1]=0; - id++; - fclose(fp2); - if(id >= MAX_MOVIE) - break; - } - fclose(fp1); - if(id >= MAX_MOVIE || section >= MAX_MOVIE_SECTION) - break; - } - } - fclose(fp); - } - SHM->next_refresh[section] = -1; - SHM->n_notes[section] = SHM->max_film = id-1; - SHM->max_history = SHM->max_film - 2; - if(SHM->max_history > MAX_HISTORY - 1) - SHM->max_history = MAX_HISTORY - 1; - if(SHM->max_history <0) SHM->max_history=0; - - fp = fopen("etc/today_is","r"); - if(fp) { - fgets(SHM->today_is,15,fp); - if((chr = strchr(SHM->today_is,'\n'))) - *chr = 0; - SHM->today_is[15] = 0; - fclose(fp); - } - - /* 等所有資料更新後再設定 uptime */ - - SHM->Puptime = SHM->Ptouchtime ; - SHM->Pbusystate = 0; - } -} - -void resolve_garbage() { - int count=0; - - if(SHM == NULL) { - attach_SHM(); - if(SHM->Ptouchtime == 0) - SHM->Ptouchtime = 1; - } - while(SHM->Puptime < SHM->Ptouchtime) { /* 不用while等 */ - reload_pttcache(); - if(count ++ > 10 && SHM->Pbusystate) { -/* Ptt: 這邊會有問題 load超過10 秒會所有進loop的process都讓 busystate = 0 - 這樣會所有prcosee都會在load 動態看板 會造成load大增 - 但沒有用這個function的話 萬一load passwd檔的process死了 又沒有人把他 - 解開 同樣的問題發生在reload passwd -*/ - SHM->Pbusystate = 0; - } - } -} - -/*-------------------------------------------------------*/ -/* PTT's cache */ -/*-------------------------------------------------------*/ -/* cachefor from host 與最多上線人數 */ -static void reload_fcache() { - if(SHM->Fbusystate) - safe_sleep(1); - else { - FILE *fp; - - SHM->Fbusystate = 1; - bzero(SHM->domain, sizeof SHM->domain); - if((fp = fopen("etc/domain_name_query","r"))) { - char buf[101],*po; - - SHM->top=0; - while(fgets(buf,100,fp)) { - if(buf[0] && buf[0] != '#' && buf[0] != ' ' && - buf[0] != '\n') { - sscanf(buf,"%s",SHM->domain[SHM->top]); - po = buf + strlen(SHM->domain[SHM->top]); - while(*po == ' ') - po++; - strncpy(SHM->replace[SHM->top],po,49); - SHM->replace[SHM->top] - [strlen(SHM->replace[SHM->top])-1] = 0; - (SHM->top)++; - } - } - } - - SHM->max_user=0; - - /* 等所有資料更新後再設定 uptime */ - SHM->Fuptime = SHM->Ftouchtime; - SHM->Fbusystate = 0; - } -} - -void resolve_fcache() { - if(SHM == NULL) { - attach_SHM(); - if(SHM->Ftouchtime == 0) - SHM->Ftouchtime = 1; - } - while(SHM->Fuptime < SHM->Ftouchtime) - reload_fcache(); -} diff --git a/pttbbs/web/util_passwd.c b/pttbbs/web/util_passwd.c deleted file mode 100755 index 6fa94302..00000000 --- a/pttbbs/web/util_passwd.c +++ /dev/null @@ -1,141 +0,0 @@ -/* $Id: util_passwd.c,v 1.2 2003/03/24 20:44:09 ptt Exp $ */ -#include <stdio.h> -#include <string.h> -#include <fcntl.h> -#include <errno.h> -#include <unistd.h> -#include <sys/types.h> -#include <sys/stat.h> -#include <sys/mman.h> -#include <sys/ipc.h> -#include <sys/sem.h> -#include "config.h" -#include "pttstruct.h" -#include "modes.h" -#include "common.h" -#include "proto.h" - -#ifndef SEM_R -#define SEM_R 0400 -#endif - -#ifndef SEM_A -#define SEM_A 0200 -#endif - -#ifndef __FreeBSD__ -union semun { - int val; /* value for SETVAL */ - struct semid_ds *buf; /* buffer for IPC_STAT & IPC_SET */ - u_short *array; /* array for GETALL & SETALL */ - struct seminfo *__buf; /* buffer for IPC_INFO */ -}; -#endif - -static userec_t *passwd_image = NULL; -static int passwd_image_size; -static int semid = -1; - -int passwd_mmap(void) { - int fd; - - if(passwd_image!=NULL) return 0; - fd = open(FN_PASSWD, O_RDWR); - if(fd > 0) { - struct stat st; - - fstat(fd, &st); - passwd_image_size = st.st_size; - passwd_image = mmap(NULL, passwd_image_size, - PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); - if(passwd_image == (userec_t *)-1) { - perror("mmap"); - return -1; - } - close(fd); - semid = semget(PASSWDSEM_KEY, 1, SEM_R | SEM_A | IPC_CREAT | IPC_EXCL); - if(semid == -1) { - if(errno == EEXIST) { - semid = semget(PASSWDSEM_KEY, 1, SEM_R | SEM_A); - if(semid == -1) { - perror("semget"); - exit(1); - } - } else { - perror("semget"); - exit(1); - } - } else { - union semun s; - - s.val = 1; - if(semctl(semid, 0, SETVAL, s) == -1) { - perror("semctl"); - exit(1); - } - } - } else { - perror(FN_PASSWD); - return -1; - } - return 0; -} -int passwd_update_money(int num) { - int money; - if(num < 1 || num > MAX_USERS) - return -1; - money = moneyof(num); - memcpy(&passwd_image[num - 1].money, &money, sizeof(int)); - return 0; -} - -int passwd_update(int num, userec_t *buf) { - if(num < 1 || num > MAX_USERS) - return -1; - buf->money = moneyof(num); - memcpy(&passwd_image[num - 1], buf, sizeof(userec_t)); - return 0; -} - -int passwd_query(int num, userec_t *buf) { - if(num < 1 || num > MAX_USERS) - return -1; - memcpy(buf, &passwd_image[num - 1], sizeof(userec_t)); - return 0; -} - -int passwd_apply(int (*fptr)(userec_t *)) { - int i; - - for(i = 0; i < MAX_USERS; i++) - if((*fptr)(&passwd_image[i]) == QUIT) - return QUIT; - return 0; -} - -int passwd_apply2(int (*fptr)(int, userec_t *)) { - int i; - - for(i = 0; i < MAX_USERS; i++) - if((*fptr)(i, &passwd_image[i]) == QUIT) - return QUIT; - return 0; -} - -void passwd_lock() { - struct sembuf buf = { 0, -1, SEM_UNDO }; - - if(semop(semid, &buf, 1)) { - perror("semop"); - exit(1); - } -} - -void passwd_unlock() { - struct sembuf buf = { 0, 1, SEM_UNDO }; - - if(semop(semid, &buf, 1)) { - perror("semop"); - exit(1); - } -} diff --git a/pttbbs/web/util_record.c b/pttbbs/web/util_record.c deleted file mode 100755 index 93d060e0..00000000 --- a/pttbbs/web/util_record.c +++ /dev/null @@ -1,246 +0,0 @@ -/* $Id: util_record.c,v 1.2 2003/03/24 20:44:09 ptt Exp $ */ -#include <stdio.h> -#include <stdlib.h> -#include <errno.h> -#include <string.h> -#include <unistd.h> -#include <time.h> -#include <sys/types.h> -#include <sys/stat.h> -#include <sys/file.h> -#include "config.h" -#include "pttstruct.h" -#include "modes.h" -#include "proto.h" - -#undef HAVE_MMAP -#define BUFSIZE 512 - -extern char *str_reply; - -static void PttLock(int fd, int size, int mode) { - static struct flock lock_it; - int ret; - - lock_it.l_whence = SEEK_CUR; /* from current point */ - lock_it.l_start = 0; /* -"- */ - lock_it.l_len = size; /* length of data */ - lock_it.l_type = mode; /* set exclusive/write lock */ - lock_it.l_pid = 0; /* pid not actually interesting */ - while((ret = fcntl(fd, F_SETLKW, &lock_it)) < 0 && errno == EINTR); -} - -#define safewrite write - -int get_num_records(char *fpath, int size) { - struct stat st; - if(stat(fpath, &st) == -1) - return 0; - return st.st_size / size; -} - -int get_sum_records(char* fpath, int size) { - struct stat st; - long ans = 0; - FILE* fp; - fileheader_t fhdr; - char buf[200], *p; - - if(!(fp = fopen(fpath, "r"))) - return -1; - - strcpy(buf, fpath); - p = strrchr(buf, '/') + 1; - - while(fread(&fhdr, size, 1, fp) == 1) { - strcpy(p, fhdr.filename); - if(stat(buf, &st) == 0 && S_ISREG(st.st_mode) && st.st_nlink == 1) - ans += st.st_size; - } - fclose(fp); - return ans / 1024; -} - -int get_record(char *fpath, void *rptr, int size, int id) { - int fd = -1; - - if(id < 1 || (fd = open(fpath, O_RDONLY, 0)) != -1) { - if(lseek(fd, (off_t)(size * (id - 1)), SEEK_SET) != -1) { - if(read(fd, rptr, size) == size) { - close(fd); - return 0; - } - } - close(fd); - } - return -1; -} - -int get_records(char *fpath, void *rptr, int size, int id, int number) { - int fd; - - if(id < 1 || (fd = open(fpath, O_RDONLY, 0)) == -1) - return -1; - - if(lseek(fd, (off_t)(size * (id - 1)), SEEK_SET) == -1) { - close(fd); - return 0; - } - if((id = read(fd, rptr, size * number)) == -1) { - close(fd); - return -1; - } - close(fd); - return id / size; -} - -int substitute_record(char *fpath, void *rptr, int size, int id) { - int fd; - -#ifdef POSTBUG - if(size == sizeof(fileheader) && (id > 1) && ((id - 1) % 4 == 0)) - saverecords(fpath, size, id); -#endif - - if(id < 1 || (fd = open(fpath, O_WRONLY | O_CREAT, 0644)) == -1) - return -1; - -#ifdef HAVE_REPORT - if(lseek(fd, (off_t)(size * (id - 1)), SEEK_SET) == -1) - report("substitute_record failed!!! (lseek)"); - PttLock(fd, size, F_WRLCK); - if(safewrite(fd, rptr, size) != size) - report("substitute_record failed!!! (safewrite)"); - PttLock(fd, size, F_UNLCK); -#else - lseek(fd, (off_t) (size * (id - 1)), SEEK_SET); - PttLock(fd, size, F_WRLCK); - safewrite(fd, rptr, size); - PttLock(fd, size, F_UNLCK); -#endif - close(fd); - -#ifdef POSTBUG - if(size == sizeof(fileheader) && (id > 1) && ((id - 1) % 4 == 0)) - restorerecords(fpath, size, id); -#endif - - return 0; -} - -int apply_record(char *fpath, int (*fptr)(), int size) { - char abuf[BUFSIZE]; - FILE* fp; - - if(!(fp = fopen(fpath, "r"))) - return -1; - - while(fread(abuf, 1, size, fp) == size) - if((*fptr) (abuf) == QUIT) { - fclose(fp); - return QUIT; - } - fclose(fp); - return 0; -} - -/* mail / post 時,依據時間建立檔案,加上郵戳 */ -int stampfile(char *fpath, fileheader_t *fh) { - register char *ip = fpath; - time_t dtime; - struct tm *ptime; - int fp = 0; - - if(access(fpath, X_OK | R_OK | W_OK)) - mkdir(fpath, 0755); - - time(&dtime); - while (*(++ip)); - *ip++ = '/'; - do { - sprintf(ip, "M.%ld.A.%3.3X", ++dtime, rand()&0xfff ); - if(fp == -1 && errno != EEXIST) - return -1; - } while((fp = open(fpath, O_CREAT | O_EXCL | O_WRONLY, 0644)) == -1); - close(fp); - memset(fh, 0, sizeof(fileheader_t)); - strcpy(fh->filename, ip); - ptime = localtime(&dtime); - sprintf(fh->date, "%2d/%02d", ptime->tm_mon + 1, ptime->tm_mday); - return 0; -} - -void stampdir(char *fpath, fileheader_t *fh) { - register char *ip = fpath; - time_t dtime; - struct tm *ptime; - - if(access(fpath, X_OK | R_OK | W_OK)) - mkdir(fpath, 0755); - - time(&dtime); - while(*(++ip)); - *ip++ = '/'; - do { - sprintf(ip, "D%lX", ++dtime & 07777); - } while(mkdir(fpath, 0755) == -1); - memset(fh, 0, sizeof(fileheader_t)); - strcpy(fh->filename, ip); - ptime = localtime(&dtime); - sprintf(fh->date, "%2d/%02d", ptime->tm_mon + 1, ptime->tm_mday); -} - -void stamplink(char *fpath, fileheader_t *fh) { - register char *ip = fpath; - time_t dtime; - struct tm *ptime; - - if(access(fpath, X_OK | R_OK | W_OK)) - mkdir(fpath, 0755); - - time(&dtime); - while(*(++ip)); - *ip++ = '/'; - do { - sprintf(ip, "S%lX", ++dtime ); - } while(symlink("temp", fpath) == -1); - memset(fh, 0, sizeof(fileheader_t)); - strcpy(fh->filename, ip); - ptime = localtime(&dtime); - sprintf(fh->date, "%2d/%02d", ptime->tm_mon + 1, ptime->tm_mday); -} - -int do_append(char *fpath, fileheader_t *record, int size) { - int fd; - - if((fd = open(fpath, O_WRONLY | O_CREAT, 0644)) == -1) { - perror("open"); - return -1; - } - flock(fd, LOCK_EX); - lseek(fd, 0, SEEK_END); - - safewrite(fd, record, size); - - flock(fd, LOCK_UN); - close(fd); - return 0; -} - -int append_record(char *fpath, fileheader_t *record, int size) { -#ifdef POSTBUG - int numrecs = (int)get_num_records(fpath, size); - - bug_possible = 1; - if(size == sizeof(fileheader) && numrecs && (numrecs % 4 == 0)) - saverecords(fpath, size, numrecs + 1); -#endif - do_append(fpath,record,size); - -#ifdef POSTBUG - if(size == sizeof(fileheader) && numrecs && (numrecs % 4 == 0)) - restorerecords(fpath, size, numrecs + 1); - bug_possible = 0; -#endif - return 0; -} -- cgit v1.2.3 From 552920db1528cc8ac2cc18d3df1266a023cde1f9 Mon Sep 17 00:00:00 2001 From: ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Mon, 31 Mar 2003 06:41:03 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@754 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/web/l | 1 + pttbbs/web/mod_ptt.c | 6 +++++- pttbbs/web/r | 1 + pttbbs/web/s | 1 + pttbbs/web/t | 1 + 5 files changed, 9 insertions(+), 1 deletion(-) create mode 100755 pttbbs/web/l create mode 100755 pttbbs/web/r create mode 100755 pttbbs/web/s create mode 100755 pttbbs/web/t diff --git a/pttbbs/web/l b/pttbbs/web/l new file mode 100755 index 00000000..2ceb6767 --- /dev/null +++ b/pttbbs/web/l @@ -0,0 +1 @@ +lynx -dump ptt.cc/test.ptt diff --git a/pttbbs/web/mod_ptt.c b/pttbbs/web/mod_ptt.c index ee32ede4..ecb77117 100644 --- a/pttbbs/web/mod_ptt.c +++ b/pttbbs/web/mod_ptt.c @@ -1,4 +1,7 @@ #include "mod_ptt.h" +extern SHM_t *SHM; +extern int *GLOBALVAR; + extern int numboards; extern boardheader_t *bcache; typedef struct excfg { @@ -74,7 +77,8 @@ static int ptt_handler(request_rec *r) ap_rprintf(r, " Server built: \"%s\"<br>", ap_get_server_built()); ap_rprintf(r, " numboards: \"%d\"<br>", numboards); - + ap_rprintf(r, " shm: \"%d\"<br>", SHM->loaded ); + ap_rprintf(r, " max_user:%d<br>", SHM->max_user ); for(i = 0; i < 10; i++) ap_rprintf(r,"%d. %s %s<br>",i,bcache[i].brdname,bcache[i].title); diff --git a/pttbbs/web/r b/pttbbs/web/r new file mode 100755 index 00000000..5e18e14c --- /dev/null +++ b/pttbbs/web/r @@ -0,0 +1 @@ +sudo apachectl restart diff --git a/pttbbs/web/s b/pttbbs/web/s new file mode 100755 index 00000000..e1384f10 --- /dev/null +++ b/pttbbs/web/s @@ -0,0 +1 @@ +sudo apachectl stop diff --git a/pttbbs/web/t b/pttbbs/web/t new file mode 100755 index 00000000..6e8b84bc --- /dev/null +++ b/pttbbs/web/t @@ -0,0 +1 @@ +tail /var/log/httpd-error.log -- cgit v1.2.3 From 2ecf77c9e6fde7f8c0f9040968d45cc42ae6fcbe Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Mon, 31 Mar 2003 08:27:50 +0000 Subject: remove JCEE git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@755 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/menu.c | 6 +++++- pttbbs/mbbsd/xyz.c | 4 +++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/pttbbs/mbbsd/menu.c b/pttbbs/mbbsd/menu.c index 3293e1d2..4455605c 100644 --- a/pttbbs/mbbsd/menu.c +++ b/pttbbs/mbbsd/menu.c @@ -1,4 +1,4 @@ -/* $Id: menu.c,v 1.23 2003/02/12 14:31:34 victor Exp $ */ +/* $Id: menu.c,v 1.24 2003/03/31 08:27:50 in2 Exp $ */ #include "bbs.h" /* help & menu processring */ @@ -448,6 +448,7 @@ static int p_money() { return 0; }; +#if 0 static commands_t jceelist[] = { {x_90,PERM_LOGINOK, "0090 JCEE 【90學年度大學聯招查榜系統】"}, {x_89,PERM_LOGINOK, "1189 JCEE 【89學年度大學聯招查榜系統】"}, @@ -461,14 +462,17 @@ static int m_jcee() { domenu(JCEE, "Ptt查榜系統", '0', jceelist); return 0; } +#endif static int forsearch(); static int playground(); /* Ptt Play menu */ static commands_t playlist[] = { +#if 0 #if HAVE_JCEE {m_jcee, PERM_LOGINOK, "JJCEE 【 大學聯考查榜系統 】"}, +#endif #endif {note, PERM_LOGINOK, "NNote 【 刻刻流言板 】"}, {x_weather,0 , "WWeather 【 氣象預報 】"}, diff --git a/pttbbs/mbbsd/xyz.c b/pttbbs/mbbsd/xyz.c index 40578519..9f9aa4d0 100644 --- a/pttbbs/mbbsd/xyz.c +++ b/pttbbs/mbbsd/xyz.c @@ -1,6 +1,7 @@ -/* $Id: xyz.c,v 1.18 2003/03/04 12:25:42 kcwu Exp $ */ +/* $Id: xyz.c,v 1.19 2003/03/31 08:27:50 in2 Exp $ */ #include "bbs.h" +#if 0 /* 各種統計及相關資訊列表 */ /* Ptt90年度大學聯招查榜系統 */ int @@ -50,6 +51,7 @@ x_86() return 0; } +#endif int x_boardman() { -- cgit v1.2.3 From 54c0f500ce9378ac45395511a5aa6667554ee3ba Mon Sep 17 00:00:00 2001 From: victor <victor@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Mon, 31 Mar 2003 10:29:24 +0000 Subject: fix 'v' on favline git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@756 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/board.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pttbbs/mbbsd/board.c b/pttbbs/mbbsd/board.c index c0e7774e..eca597ff 100644 --- a/pttbbs/mbbsd/board.c +++ b/pttbbs/mbbsd/board.c @@ -1,4 +1,4 @@ -/* $Id: board.c,v 1.115 2003/03/30 15:36:47 victor Exp $ */ +/* $Id: board.c,v 1.116 2003/03/31 10:29:24 victor Exp $ */ #include "bbs.h" #define BRC_STRLEN 15 /* Length of board name */ #define BRC_MAXSIZE 24576 @@ -863,7 +863,7 @@ brdlist_foot() { prints("\033[34;46m 選擇看板 \033[31;47m (c)\033[30m新文章模式 " "\033[31m(v/V)\033[30m標記已讀/未讀 \033[31m(y)\033[30m篩選%s" - " \033[31m(z)\033[30m切換選擇 \033[m", + " \033[31m(m)\033[30m切換最愛 \033[m", yank_flag == 0 ? "最愛" : yank_flag == 1 ? "部份" : "全部"); } @@ -1368,6 +1368,8 @@ choose_board(int newflag) break; case 'v': case 'V': + if(nbrd[num].bid < 0) + break; ptr = &nbrd[num]; brc_initial(B_BH(ptr)->brdname); if (ch == 'v') { -- cgit v1.2.3 From f574b3f0db789e7c42c9793177f3c220d79042a9 Mon Sep 17 00:00:00 2001 From: victor <victor@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Mon, 31 Mar 2003 16:05:47 +0000 Subject: fix little error git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@757 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/board.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/pttbbs/mbbsd/board.c b/pttbbs/mbbsd/board.c index eca597ff..b77f11f9 100644 --- a/pttbbs/mbbsd/board.c +++ b/pttbbs/mbbsd/board.c @@ -1,4 +1,4 @@ -/* $Id: board.c,v 1.116 2003/03/31 10:29:24 victor Exp $ */ +/* $Id: board.c,v 1.117 2003/03/31 16:05:47 victor Exp $ */ #include "bbs.h" #define BRC_STRLEN 15 /* Length of board name */ #define BRC_MAXSIZE 24576 @@ -406,7 +406,7 @@ void updatenewfav(int mode) brd = (char *)malloc((numboards + 1) * sizeof(char)); read(fd, brd, (numboards + 1) * sizeof(char)); - for(i = 0; i < numboards && brd[i] != BRD_END; i++){ + for(i = 0; i < numboards + 1 && brd[i] != BRD_END; i++){ if(brd[i] == BRD_NEW){ if(bcache[i].brdname[0] && Ben_Perm(&bcache[i])){ // check the permission if the board exsits if(mode) @@ -414,8 +414,12 @@ void updatenewfav(int mode) brd[i] = BRD_OLD; } } + else{ + if(!bcache[i].brdname[0]) + brd[i] = BRD_NEW; + } } - if( i != numboards ) // the board number may change + if( i < numboards + 1) // the board number may change for(i-- ; i < numboards; i++){ if(bcache[i].brdname[0] && Ben_Perm(&bcache[i])){ if(mode) -- cgit v1.2.3 From ffba4184620f802da73362ad05c86e6289d822fc Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Tue, 1 Apr 2003 09:41:12 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@758 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/docs/INSTALL | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/pttbbs/docs/INSTALL b/pttbbs/docs/INSTALL index 6b7d8c81..0ab93f0f 100644 --- a/pttbbs/docs/INSTALL +++ b/pttbbs/docs/INSTALL @@ -57,6 +57,15 @@ new 若您使用 FreeBSD, 您可以將 sample/pttbbs.sh 拷貝到 /usr/local/etc/rc.d/ 之後您可以重新開機試試看是不是在重開後可以正常運作 :) +19. pttbbs 須要定時執行一些小 tool 來維持系統正常運作, + reload cache, 備份, 特殊外部程式等等. + 請用 bbs的權限, 執行 crontab -e , 內容請參照 sample/crontab + (在大部份的情況下, 直接將 sample/crontab 內容拷備進去即可) + +20.在某些情況下, pttbbs會須要一些其他的程式來輔助. + 下面列出所須要的程式, 預設的路徑, 以及在 FreeBSD ports內對映的路徑 + + 註: 1. 這個程式是在 initial shared memory 用的, 只有開機後第一次執行, 或是 你手動清除 shm 後才需要執行 -- cgit v1.2.3 From e323691eef81c733e7de4ad3a16d6bdff365ec0d Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Tue, 1 Apr 2003 09:45:03 +0000 Subject: re-indent git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@759 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/docs/INSTALL | 101 ++++++++++++++++++++++++++-------------------------- 1 file changed, 50 insertions(+), 51 deletions(-) diff --git a/pttbbs/docs/INSTALL b/pttbbs/docs/INSTALL index 0ab93f0f..b11c7457 100644 --- a/pttbbs/docs/INSTALL +++ b/pttbbs/docs/INSTALL @@ -1,70 +1,69 @@ 底下是快速安裝的方法 -== +============== +以 root 的權限 +============== -先取得 root 權限 + 1. 打 vipw, 加入底下兩行 -1. 打 vipw, 加入底下兩行 + bbs:*:9999:99::0:0:Ptt BBS:/home/bbs:/home/bbs/bin/bbsrf + bbsadm::9999:99::0:0:Ptt BBS:/home/bbs:/bin/csh - bbs:*:9999:99::0:0:Ptt BBS:/home/bbs:/home/bbs/bin/bbsrf - bbsadm::9999:99::0:0:Ptt BBS:/home/bbs:/bin/csh + 2. 執行 passwd bbsadm 設 bbsadm的密碼 + 3. 在 /etc/group 中加入一行 -2. 執行 passwd bbsadm 設 bbsadm的密碼 -3. 在 /etc/group 中加入一行 + bbs:*:99: - bbs:*:99: + 4. 執行 mkdir /home/bbs + 5. 執行 chown bbs.bbs /home/bbs + 6. 執行 chmod 700 /home/bbs -4. 執行 mkdir /home/bbs -5. 執行 chown bbs.bbs /home/bbs -6. 執行 chmod 700 /home/bbs +==================== +以下用 bbsadm 的身份 +==================== -然後切換成 bbsadm 的身份 + 7. 取得解開 pttbbs-VERSION.tar.gz (任何目錄下皆可). -7. 取得解開 pttbbs-VERSION.tar.gz (任何目錄下皆可). + 或透過 cvs來取得 (強烈建議) + touch ~/.cvspass + cvs -d :pserver:cvs@ptt2.csie.ntu.edu.tw:/var/db/cvsroot login + (不用打密碼, 直接按 Enter過去) + cvs -d :pserver:cvs@ptt2.csie.ntu.edu.tw:/var/db/cvsroot checkout pttbbs + 使用此法的朋友, 將來您可以直接在 pttbbs/ 下用 + cvs update + 更新到最新版本的 pttbbs - 或透過 cvs來取得 (強烈建議) - touch ~/.cvspass - cvs -d :pserver:cvs@ptt2.csie.ntu.edu.tw:/var/db/cvsroot login - (不用打密碼, 直接按 Enter過去) - cvs -d :pserver:cvs@ptt2.csie.ntu.edu.tw:/var/db/cvsroot checkout pttbbs - 使用此法的朋友, 將來您可以直接在 pttbbs/ 下用 - cvs update - 更新到最新版本的 pttbbs - -8. 執行 cd pttbbs -9. 如果之前沒有設定過 pttbbs.conf 的話, 請 cp sample/pttbbs.conf pttbbs.conf -10.修改 pttbbs.conf - * 如果您是用 Linux系統, 請先安裝 pmake, 然後將 make alias 成 pmake * -11.執行 make OSTYPE=FreeBSD BBSHOME=/home/bbs all install + 8. 執行 cd pttbbs + 9. 如果之前沒有設定過 pttbbs.conf 的話, 請 cp sample/pttbbs.conf pttbbs.conf + 10.修改 pttbbs.conf + * 如果您是用 Linux系統, 請先安裝 pmake, 然後將 make alias 成 pmake * + 11.執行 make OSTYPE=FreeBSD BBSHOME=/home/bbs all install (Linux使用者請把 "FreeBSD" 改成 "linux") -12.如果是新架起來的站, 請執行 cd sample; make install -13.執行 cd /home/bbs; bin/initbbs + 12.如果是新架起來的站, 請執行 cd sample; make install + 13.執行 cd /home/bbs; bin/initbbs 假如一切都很順利的話,這樣子大概就安裝完了 接下來是啟動 bbs 的部份 -14.執行 bin/uhash_loader (*註1, *註2) -15.執行 bin/shmctl utmpsortd -16.用 root 執行 bin/mbbsd 23 (註2) - -17.新功能請參考 ADVANCE -telnet localhost 23 看看 -new一個帳號叫SYSOP,然後logout再login, 這樣子就會擁有站長權限囉~ -再new一個帳號叫 guest, 這樣子別人就可以用 guest 參觀你的站了 -開板,開群組,以及搬動群組的方法請看 PttSrc 板的文摘 - -18.為了讓開機的時候會自己把 bbs (以及所須要的程式) 跑起來, - 若您使用 FreeBSD, 您可以將 sample/pttbbs.sh 拷貝到 /usr/local/etc/rc.d/ - 之後您可以重新開機試試看是不是在重開後可以正常運作 :) - -19. pttbbs 須要定時執行一些小 tool 來維持系統正常運作, - reload cache, 備份, 特殊外部程式等等. - 請用 bbs的權限, 執行 crontab -e , 內容請參照 sample/crontab - (在大部份的情況下, 直接將 sample/crontab 內容拷備進去即可) - -20.在某些情況下, pttbbs會須要一些其他的程式來輔助. - 下面列出所須要的程式, 預設的路徑, 以及在 FreeBSD ports內對映的路徑 - + 14.執行 bin/uhash_loader (*註1, *註2) + 15.執行 bin/shmctl utmpsortd + 16.用 root 執行 bin/mbbsd 23 (註2) + + 17.測試整個系統是否完成: + telnet localhost 23 看看 + new 一個帳號叫SYSOP, 然後 logout再 login, 這樣子就會擁有站長權限囉~ + 再 new一個帳號叫 guest , 這樣子別人就可以用 guest 參觀你的站了 + 開板, 開群組, 以及搬動群組的方法請看 PttSrc 板的文摘 + 18.新功能請參考 ADVANCE + 19.為了讓開機的時候會自己把 bbs (以及所須要的程式) 跑起來, + 若您使用 FreeBSD, 您可以將 sample/pttbbs.sh 拷貝到 /usr/local/etc/rc.d/ + 之後您可以重新開機試試看是不是在重開後可以正常運作 :) + 20. pttbbs 須要定時執行一些小 tool 來維持系統正常運作, + reload cache, 備份, 特殊外部程式等等. + 請用 bbs的權限, 執行 crontab -e , 內容請參照 sample/crontab + (在大部份的情況下, 直接將 sample/crontab 內容拷備進去即可) + 21.在某些情況下, pttbbs會須要一些其他的程式來輔助. + 下面列出所須要的程式, 預設的路徑, 以及在 FreeBSD ports內對映的路徑 註: 1. 這個程式是在 initial shared memory 用的, 只有開機後第一次執行, 或是 -- cgit v1.2.3 From 89909944a48bb497e7e42df5a7524da8b19b91ce Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Tue, 1 Apr 2003 09:46:56 +0000 Subject: add in2, kcwu, victor git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@760 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/docs/ANCESTOR | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pttbbs/docs/ANCESTOR b/pttbbs/docs/ANCESTOR index 269e7cea..1683c8fb 100644 --- a/pttbbs/docs/ANCESTOR +++ b/pttbbs/docs/ANCESTOR @@ -19,5 +19,6 @@ Copyright (C) 1994-1995 Jeng-Hermes Lin, Hung-Pin Chen SunOfBeach Bulletin Board System Version: 0.22 Copyleft ($) 1996 Kaede, woju -Ptt Bulletin Board System Ptt, Jaky, Action, Heat, Dunk -批踢踢實業坊 CharlieL, DickG, DavidYu +Ptt Bulletin Board System Ptt, Jaky, Action, Heat, Dunk, +批踢踢實業坊 CharlieL, DickG, DavidYu, + in2, kcwu, victor \ No newline at end of file -- cgit v1.2.3 From 989fe015584c963c8add563a7361bbe36108581f Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Tue, 1 Apr 2003 09:52:17 +0000 Subject: mv LocalVars.pm.sample sample/LocalVars.pm git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@761 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/LocalVars.pm.sample | 24 ------------------------ 1 file changed, 24 deletions(-) delete mode 100644 pttbbs/util/LocalVars.pm.sample diff --git a/pttbbs/util/LocalVars.pm.sample b/pttbbs/util/LocalVars.pm.sample deleted file mode 100644 index 1f24872d..00000000 --- a/pttbbs/util/LocalVars.pm.sample +++ /dev/null @@ -1,24 +0,0 @@ -#!/usr/bin/perl -package LocalVars; -require Exporter; -@ISA = qw/Exporter/; -@EXPORT = qw/ - $hostname $MYHOSTNAME $FQDN $SMTPSERVER - $BBSHOME $JOBSPOOL $TMP - $TAR $LYNX $GREP/; - -# host -$hostname = 'ptt'; -$MYHOSTNAME = 'ptt.cc'; -$FQDN = 'ptt.csie.ntu.edu.tw'; -$SMTPSERVER = 'ptt2.csie.ntu.edu.tw'; - -# dir -$BBSHOME = '/home/bbs'; -$JOBSPOOL = "$BBSHOME/jobspool"; -$TMP = '/tmp'; - -# program -$TAR = '/usr/bin/tar'; -$LYNX = '/usr/local/bin/lynx'; # /usr/ports/www/lynx -$GREP = '/usr/bin/grep'; -- cgit v1.2.3 From a3831fcb2d1e29f3d6d1a8b51b8a056b738a9844 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Tue, 1 Apr 2003 09:53:00 +0000 Subject: mv util/LocalVars.pm.sample sample/LocalVars.pm git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@762 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/sample/LocalVars.pm | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 pttbbs/sample/LocalVars.pm diff --git a/pttbbs/sample/LocalVars.pm b/pttbbs/sample/LocalVars.pm new file mode 100644 index 00000000..1f24872d --- /dev/null +++ b/pttbbs/sample/LocalVars.pm @@ -0,0 +1,24 @@ +#!/usr/bin/perl +package LocalVars; +require Exporter; +@ISA = qw/Exporter/; +@EXPORT = qw/ + $hostname $MYHOSTNAME $FQDN $SMTPSERVER + $BBSHOME $JOBSPOOL $TMP + $TAR $LYNX $GREP/; + +# host +$hostname = 'ptt'; +$MYHOSTNAME = 'ptt.cc'; +$FQDN = 'ptt.csie.ntu.edu.tw'; +$SMTPSERVER = 'ptt2.csie.ntu.edu.tw'; + +# dir +$BBSHOME = '/home/bbs'; +$JOBSPOOL = "$BBSHOME/jobspool"; +$TMP = '/tmp'; + +# program +$TAR = '/usr/bin/tar'; +$LYNX = '/usr/local/bin/lynx'; # /usr/ports/www/lynx +$GREP = '/usr/bin/grep'; -- cgit v1.2.3 From 8549683e3b19321600b692d1aeeb2540096b7861 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Tue, 1 Apr 2003 10:00:26 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@763 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/docs/INSTALL | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/pttbbs/docs/INSTALL b/pttbbs/docs/INSTALL index b11c7457..485935d7 100644 --- a/pttbbs/docs/INSTALL +++ b/pttbbs/docs/INSTALL @@ -64,6 +64,19 @@ (在大部份的情況下, 直接將 sample/crontab 內容拷備進去即可) 21.在某些情況下, pttbbs會須要一些其他的程式來輔助. 下面列出所須要的程式, 預設的路徑, 以及在 FreeBSD ports內對映的路徑 + tar /usr/bin/tar FreeBSD default install + gzip /usr/bin/gzip FreeBSD default install + rm /bin/rm FreeBSD default install + perl /usr/bin/perl /usr/ports/lang/perl5.8/ + mutt /usr/local/bin/mutt /usr/ports/mail/mutt/ + lynx /usr/local/bin/lynx /usr/ports/www/lynx/ + + 我們大部份的 perl script會用到 LocalVars.pm , 該檔案內負責定義 + 各別機器的設定 (如外部程式的路徑) . 請將該檔拷份一份至 ~/bin/ + 下, 並修正該檔以符合貴環境的設定. + + 另外列出我們 perl script會用到的 perl module, 以 FreeBSD ports相對目錄. + Mail::Sender /usr/ports/mail/p5-Mail-Sender/ 註: 1. 這個程式是在 initial shared memory 用的, 只有開機後第一次執行, 或是 -- cgit v1.2.3 From 9fd9939d57ab532b443bf3b60fac39844f139def Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Wed, 2 Apr 2003 02:48:46 +0000 Subject: change url git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@764 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/weather.perl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pttbbs/util/weather.perl b/pttbbs/util/weather.perl index 5e2c8d4f..f7a1559c 100644 --- a/pttbbs/util/weather.perl +++ b/pttbbs/util/weather.perl @@ -1,5 +1,5 @@ #!/usr/bin/perl -# $Id: weather.perl,v 1.5 2003/03/01 06:12:20 bbs Exp $ +# $Id: weather.perl,v 1.6 2003/04/02 02:48:46 in2 Exp $ # # 不能跑的話,看看 bbspost 的路徑是否正確。 # 如果發出的 post 沒有氣象報告而是說 URL 找不到,則確定一下能不能看到 @@ -20,7 +20,7 @@ close DATE; # Header # 內容 #open(WEATHER, "$LYNX -assume_charset=big5 -assume_local_charset=big5 -dump http://www.cwb.gov.tw/V3.0/weather/text/W03.htm |"); -open(WEATHER, "$LYNX -assume_charset=big5 -assume_local_charset=big5 -dump -nolist http://www.libertytimes.com.tw/2003/new/mar/today/Wnews1.htm|"); +open(WEATHER, "$LYNX -assume_charset=big5 -assume_local_charset=big5 -dump -nolist http://www.libertytimes.com.tw/2003/new/apr/today/Wnews1.htm|"); while (<WEATHER>) { last if /今日天氣/; -- cgit v1.2.3 From babbfe41dd8ccff1e4ae63c430811e18af01cdf0 Mon Sep 17 00:00:00 2001 From: victor <victor@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Wed, 2 Apr 2003 08:07:47 +0000 Subject: fix new fav bug git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@765 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/board.c | 40 ++++++++++++++++------------------------ 1 file changed, 16 insertions(+), 24 deletions(-) diff --git a/pttbbs/mbbsd/board.c b/pttbbs/mbbsd/board.c index b77f11f9..b6c107c7 100644 --- a/pttbbs/mbbsd/board.c +++ b/pttbbs/mbbsd/board.c @@ -1,4 +1,4 @@ -/* $Id: board.c,v 1.117 2003/03/31 16:05:47 victor Exp $ */ +/* $Id: board.c,v 1.118 2003/04/02 08:07:47 victor Exp $ */ #include "bbs.h" #define BRC_STRLEN 15 /* Length of board name */ #define BRC_MAXSIZE 24576 @@ -419,7 +419,7 @@ void updatenewfav(int mode) brd[i] = BRD_NEW; } } - if( i < numboards + 1) // the board number may change + if( i < numboards) // the board number may change for(i-- ; i < numboards; i++){ if(bcache[i].brdname[0] && Ben_Perm(&bcache[i])){ if(mode) @@ -442,7 +442,7 @@ void updatenewfav(int mode) void load_brdbuf(void) { static char firsttime = 1; - int fd, r, w; + int fd; char fname[80]; setuserfile(fname, FAV3); @@ -482,25 +482,6 @@ void load_brdbuf(void) read(fd, fav->b, sizeof(fav_board_t) * nDatas); close(fd); } - - // check if fav is correct - // 'r' for current reading position, 'w' for current writing position - // 'i' for checking duplication - for( r = w = 0 ; r < fav->nDatas ; ++r ) - if( fav->b[r].attr & BRD_FAV ) // 須是 BRD_FAV - if( (fav->b[r].bid < 0) || // 分隔線 - (fav->b[r].bid > 0 && // bid 在合理範圍 - fav->b[r].bid < numboards && - bcache[fav->b[r].bid - 1].brdname[0]) ){ // 看板存在 - int i; - for( i = 0 ; i < w ; ++i ) - if( fav->b[i].bid == fav->b[r].bid ) - break; - if( i == w ) // 無和之前的重覆 - fav->b[w++] = fav->b[r]; - } - fav->nDatas = w; - updatenewfav(1); #ifdef MEM_CHECK fav->memcheck = MEM_CHECK; @@ -535,9 +516,9 @@ save_brdbuf(void) for( r = w = 0 ; r < fav->nDatas ; ++r ){ if( ( fav->b[r].attr & BRD_LINE ) || (fav->b[r].attr & BRD_FAV && bcache[fav->b[r].bid - 1].brdname[0])){ - fav->b[w++] = fav->b[r]; - if(fav->b[w].attr & BRD_LINE) + if(fav->b[r].attr & BRD_LINE) fav->nLines--; + fav->b[w++] = fav->b[r]; } } fav->nDatas = w; @@ -1294,6 +1275,17 @@ choose_board(int newflag) head = 9999; } break; + case 'X': + move(0,0); + prints(" Datas: %hd Lines: %hd\n", fav->nDatas, fav->nLines); + for(tmp = 0; tmp < fav->nDatas; tmp++){ + prints(" bid: %5hd attr:%s%s%s\n", fav->b[tmp].bid, + fav->b[tmp].attr & BRD_FAV ? " BRD_FAV" : "", + fav->b[tmp].attr & BRD_TAG ? " BRD_TAG" : "", + fav->b[tmp].attr & BRD_LINE ? " BRD_LINE" : ""); + } + pressanykey(); + break; case 'K': if (HAS_PERM(PERM_BASIC)) { char buf[2], fname[80]; -- cgit v1.2.3 From 08009fbf6f58efc85671edf7baf4bd70a3e63095 Mon Sep 17 00:00:00 2001 From: victor <victor@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Wed, 2 Apr 2003 09:19:46 +0000 Subject: change link git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@766 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/weather.perl | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pttbbs/util/weather.perl b/pttbbs/util/weather.perl index f7a1559c..2cfd9e13 100644 --- a/pttbbs/util/weather.perl +++ b/pttbbs/util/weather.perl @@ -1,5 +1,5 @@ #!/usr/bin/perl -# $Id: weather.perl,v 1.6 2003/04/02 02:48:46 in2 Exp $ +# $Id: weather.perl,v 1.7 2003/04/02 09:19:46 victor Exp $ # # 不能跑的話,看看 bbspost 的路徑是否正確。 # 如果發出的 post 沒有氣象報告而是說 URL 找不到,則確定一下能不能看到 @@ -20,14 +20,14 @@ close DATE; # Header # 內容 #open(WEATHER, "$LYNX -assume_charset=big5 -assume_local_charset=big5 -dump http://www.cwb.gov.tw/V3.0/weather/text/W03.htm |"); -open(WEATHER, "$LYNX -assume_charset=big5 -assume_local_charset=big5 -dump -nolist http://www.libertytimes.com.tw/2003/new/apr/today/Wnews1.htm|"); +open(WEATHER, "$LYNX -assume_charset=big5 -assume_local_charset=big5 -dump -nolist http://www.gigigaga.com/home/weather.asp|"); while (<WEATHER>) { - last if /今日天氣/; + last if /首頁/; } while (<WEATHER>) { - last if /top\.gif/; + last if /dot\.gif/; print BBSPOST if ($_ ne "\n"); } close WEATHER; -- cgit v1.2.3 From 38761a4f0fdb76c9bcf405ad09e3a703eed8663c Mon Sep 17 00:00:00 2001 From: victor <victor@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Thu, 3 Apr 2003 04:24:33 +0000 Subject: check if fav brd is deleted git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@767 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/board.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/pttbbs/mbbsd/board.c b/pttbbs/mbbsd/board.c index b6c107c7..46eb27f2 100644 --- a/pttbbs/mbbsd/board.c +++ b/pttbbs/mbbsd/board.c @@ -1,4 +1,4 @@ -/* $Id: board.c,v 1.118 2003/04/02 08:07:47 victor Exp $ */ +/* $Id: board.c,v 1.119 2003/04/03 04:24:33 victor Exp $ */ #include "bbs.h" #define BRC_STRLEN 15 /* Length of board name */ #define BRC_MAXSIZE 24576 @@ -470,16 +470,17 @@ void load_brdbuf(void) } } else{ - short nDatas; - char nLines; - read(fd, &nDatas, sizeof(nDatas)); - read(fd, &nLines, sizeof(nLines)); + short i; + read(fd, &fav->nDatas, sizeof(fav->nDatas)); + read(fd, &fav->nLines, sizeof(fav->nLines)); fav = (fav_t *)malloc(sizeof(fav_t) + - sizeof(fav_board_t) * (nDatas + 16)); - fav->nDatas = nDatas; - fav->nAllocs = nDatas + 16; - fav->nLines = nLines; - read(fd, fav->b, sizeof(fav_board_t) * nDatas); + sizeof(fav_board_t) * (fav->nDatas + 16)); + fav->nAllocs = fav->nDatas + 16; + read(fd, fav->b, sizeof(fav_board_t) * fav->nDatas); + for(i = 0; i < fav->nDatas; i++){ + if( !(fav->b[i].attr & BRD_LINE) && !bcache[fav->b[i].bid - 1].brdname[0]) + fav->b[i].attr ^= BRD_FAV; + } close(fd); } updatenewfav(1); -- cgit v1.2.3 From 1e70436ba6463954a6fdba57538154fa9f3cd5f5 Mon Sep 17 00:00:00 2001 From: victor <victor@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Thu, 3 Apr 2003 04:41:30 +0000 Subject: fix last commit bug git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@768 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/board.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/pttbbs/mbbsd/board.c b/pttbbs/mbbsd/board.c index 46eb27f2..20c46d28 100644 --- a/pttbbs/mbbsd/board.c +++ b/pttbbs/mbbsd/board.c @@ -1,4 +1,4 @@ -/* $Id: board.c,v 1.119 2003/04/03 04:24:33 victor Exp $ */ +/* $Id: board.c,v 1.120 2003/04/03 04:41:30 victor Exp $ */ #include "bbs.h" #define BRC_STRLEN 15 /* Length of board name */ #define BRC_MAXSIZE 24576 @@ -470,12 +470,15 @@ void load_brdbuf(void) } } else{ - short i; - read(fd, &fav->nDatas, sizeof(fav->nDatas)); - read(fd, &fav->nLines, sizeof(fav->nLines)); + short nDatas, i; + char nLines; + read(fd, &nDatas, sizeof(nDatas)); + read(fd, &nLines, sizeof(nLines)); fav = (fav_t *)malloc(sizeof(fav_t) + - sizeof(fav_board_t) * (fav->nDatas + 16)); - fav->nAllocs = fav->nDatas + 16; + sizeof(fav_board_t) * (nDatas + 16)); + fav->nDatas = nDatas; + fav->nAllocs = nDatas + 16; + fav->nLines = nLines; read(fd, fav->b, sizeof(fav_board_t) * fav->nDatas); for(i = 0; i < fav->nDatas; i++){ if( !(fav->b[i].attr & BRD_LINE) && !bcache[fav->b[i].bid - 1].brdname[0]) -- cgit v1.2.3 From 398b23e97aeb721a822e6d59f7649084ce207ea2 Mon Sep 17 00:00:00 2001 From: victor <victor@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Fri, 4 Apr 2003 16:06:02 +0000 Subject: rm debug cmd :p git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@769 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/board.c | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/pttbbs/mbbsd/board.c b/pttbbs/mbbsd/board.c index 20c46d28..a6cc38e2 100644 --- a/pttbbs/mbbsd/board.c +++ b/pttbbs/mbbsd/board.c @@ -1,4 +1,4 @@ -/* $Id: board.c,v 1.120 2003/04/03 04:41:30 victor Exp $ */ +/* $Id: board.c,v 1.121 2003/04/04 16:06:02 victor Exp $ */ #include "bbs.h" #define BRC_STRLEN 15 /* Length of board name */ #define BRC_MAXSIZE 24576 @@ -1279,17 +1279,6 @@ choose_board(int newflag) head = 9999; } break; - case 'X': - move(0,0); - prints(" Datas: %hd Lines: %hd\n", fav->nDatas, fav->nLines); - for(tmp = 0; tmp < fav->nDatas; tmp++){ - prints(" bid: %5hd attr:%s%s%s\n", fav->b[tmp].bid, - fav->b[tmp].attr & BRD_FAV ? " BRD_FAV" : "", - fav->b[tmp].attr & BRD_TAG ? " BRD_TAG" : "", - fav->b[tmp].attr & BRD_LINE ? " BRD_LINE" : ""); - } - pressanykey(); - break; case 'K': if (HAS_PERM(PERM_BASIC)) { char buf[2], fname[80]; -- cgit v1.2.3 From 57db1d1a622fffdb823e993d3e28d0f3a0222485 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sat, 5 Apr 2003 13:09:03 +0000 Subject: use make.conf's CFLAG git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@770 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/innbbsd/Makefile | 4 ++-- pttbbs/util/Makefile | 47 ++++++++++++++++++++++++----------------------- 2 files changed, 26 insertions(+), 25 deletions(-) diff --git a/pttbbs/innbbsd/Makefile b/pttbbs/innbbsd/Makefile index 95bcc415..38e9a2db 100644 --- a/pttbbs/innbbsd/Makefile +++ b/pttbbs/innbbsd/Makefile @@ -19,7 +19,7 @@ TARGET = $(INNBBSD) $(BBSNNRP) $(BBSLINK) CC=gcc INSTALL=cp # -OPT= -O -s -pipe -fomit-frame-pointer -g +OPT= -O -s -pipe -fomit-frame-pointer BBS_DEP = MapleBBS BBS_UTIL = $(BBS_SRC)/util @@ -29,7 +29,7 @@ BBS_REC = $(BBS_UTIL)/util_record.o $(BBS_UTIL)/util_cache.o $(BBS_UTIL)/util_pa # ############### DEBUGOBJ = /usr/lib/debug/mallocmap.o -CFLAGS= -c -I. -I$(BBS_SRC)/include -I$(BBS_SRC)/mbbsd -D$(BBS_DEP) \ +CFLAGS+= -c -I. -I$(BBS_SRC)/include -I$(BBS_SRC)/mbbsd -D$(BBS_DEP) \ $(EXTRAFLAGS) -DDBZDEBUG -DBBSHOME='"$(BBSHOME)"' \ -D_PATH_BBSHOME=\"$(BBSHOME)\" \ -DVERSION=\"$(VERSION)\" -DADMINUSER=\"$(ADMINUSER)\" diff --git a/pttbbs/util/Makefile b/pttbbs/util/Makefile index 5dfe6c19..d94eb736 100644 --- a/pttbbs/util/Makefile +++ b/pttbbs/util/Makefile @@ -1,27 +1,28 @@ -# $Id: Makefile,v 1.27 2003/03/29 09:53:34 in2 Exp $ - -BBSHOME?=$(HOME) -OSTYPE!=uname - -# FreeBSD -CC_FreeBSD= gcc -CFLAGS_FreeBSD= -DFreeBSD -pipe -Wall -g -O -DHAVE_SETPROCTITLE -DBBSHOME='"$(BBSHOME)"' -I../include -LIBS_FreeBSD= -LIBMAIL_FreeBSD=-lutil -LIBCHAT_FreeBSD= - -# Linux -CC_linux= gcc -CFLAGS_linux= -DLinux -pipe -Wall -g -O -DHAVE_DES_CRYPT -DBBSHOME='"$(BBSHOME)"' -I../include +# $Id: Makefile,v 1.28 2003/04/05 13:09:03 in2 Exp $ + +# 訂義基本初值 +BBSHOME?= $(HOME) +BBSHOME?= /home/bbs +OSTYPE?= FreeBSD +CC?= gcc +CFLAGS+= -Wall -pipe -DBBSHOME='"$(BBSHOME)"' -I../include +LDFLAGS+= -pipe -Wall +LIBS+= -lcrypt + +# FreeBSD特有的環境 +CFLAGS_FreeBSD= -DHAVE_SETPROCTITLE -DFreeBSD +LDFLAGS_FreeBSD= +LIBS_FreeBSD= -lkvm + +# Linux特有的環境 +CFLAGS_linux= -DHAVE_DES_CRYPT -DLinux +LDFLAGS_linux= -pipe -Wall LIBS_linux= -lresolv -LIBMAIL_linux= -LIBCHAT_linux= -lcrypt - -CC= $(CC_$(OSTYPE)) -CFLAGS= $(CFLAGS_$(OSTYPE)) -LDFLAGS=$(LDFLAGS_$(OSTYPE)) -LIBMAIL=$(LIBMAIL_$(OSTYPE)) -LIBCHAT=$(LIBCHAT_$(OSTYPE)) + +# CFLAGS, LDFLAGS, LIBS 加入 OS 相關參數 +CFLAGS+= $(CFLAGS_$(OSTYPE)) +LDFLAGS+= $(LDFLAGS_$(OSTYPE)) +LIBS+= $(LIBS_$(OSTYPE)) OBJS= util_cache.o util_record.o util_passwd.o -- cgit v1.2.3 From 03b895ce16245594989fe3702c2b1e05e2b69d5b Mon Sep 17 00:00:00 2001 From: victor <victor@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sun, 6 Apr 2003 04:11:10 +0000 Subject: rename menu git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@771 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/var.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pttbbs/mbbsd/var.c b/pttbbs/mbbsd/var.c index 68c0abdc..8d43e7d5 100644 --- a/pttbbs/mbbsd/var.c +++ b/pttbbs/mbbsd/var.c @@ -1,4 +1,4 @@ -/* $Id: var.c,v 1.15 2002/12/31 17:40:52 in2 Exp $ */ +/* $Id: var.c,v 1.16 2003/04/06 04:11:10 victor Exp $ */ #define INCLUDE_VAR_H #include "bbs.h" @@ -553,7 +553,7 @@ commands_t cmdlist[] = { {Talk, 0, "TTalk 【 休閒聊天區 】"}, {User, 0, "UUser 【 個人設定區 】"}, {Xyz, 0, "XXyz 【 系統工具區 】"}, - {Play_Play, PERM_BASIC, "PPlay 【 遊樂場/大學查榜】"}, + {Play_Play, PERM_BASIC, "PPlay 【 娛樂/休閒生活】"}, {Name_Menu, PERM_LOGINOK, "NNamelist 【 編特別名單 】"}, {Goodbye, 0, "GGoodbye 離開,再見……"}, {NULL, 0, NULL} -- cgit v1.2.3 From 34a72d5a81ce57b0292aff0638c71fe9557f5ad4 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sun, 6 Apr 2003 05:46:17 +0000 Subject: confirm again if SYSOP broadcast git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@772 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/talk.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/pttbbs/mbbsd/talk.c b/pttbbs/mbbsd/talk.c index 4f1688fc..c6014dfd 100644 --- a/pttbbs/mbbsd/talk.c +++ b/pttbbs/mbbsd/talk.c @@ -1,4 +1,4 @@ -/* $Id: talk.c,v 1.101 2003/02/24 11:42:04 victor Exp $ */ +/* $Id: talk.c,v 1.102 2003/04/06 05:46:17 in2 Exp $ */ #include "bbs.h" #define QCAST int (*)(const void *, const void *) @@ -2061,6 +2061,12 @@ userlist(void) *ans == 'n') break; if (!(cuser.uflag & FRIEND_FLAG) && HAS_PERM(PERM_SYSOP)) { + if( getdata(1, 0, "再次確定站長廣播? [N]", + ans, sizeof(ans), LCECHO) && + *ans != 'y' && *ans != 'Y' ){ + vmsg("abort"); + break; + } for (i = 0; i < SHM->UTMPnumber; ++i) { uentp = SHM->sorted[SHM->currsorted][0][i]; if (uentp->pid && kill(uentp->pid, 0) != -1) -- cgit v1.2.3 From ac682551c70b1cdb3ae299ceae92e6f597455b3c Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sun, 6 Apr 2003 05:55:07 +0000 Subject: press 'N' to change nickname in userlist git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@773 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/talk.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/pttbbs/mbbsd/talk.c b/pttbbs/mbbsd/talk.c index c6014dfd..ed952f44 100644 --- a/pttbbs/mbbsd/talk.c +++ b/pttbbs/mbbsd/talk.c @@ -1,4 +1,4 @@ -/* $Id: talk.c,v 1.102 2003/04/06 05:46:17 in2 Exp $ */ +/* $Id: talk.c,v 1.103 2003/04/06 05:55:07 in2 Exp $ */ #include "bbs.h" #define QCAST int (*)(const void *, const void *) @@ -2297,6 +2297,13 @@ userlist(void) } break; + case 'N': + oldgetdata(1, 0, "新的暱稱: ", + cuser.username, sizeof(cuser.username), LCECHO); + strcpy(currutmp->username, cuser.username); + redrawall = redraw = 1; + break; + default: if (now >= lastupdate + 2) redraw = 1; -- cgit v1.2.3 From 0a7878db86ee5c18cce6ce5ed318a455e132e5ed Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sun, 6 Apr 2003 05:58:31 +0000 Subject: add 'N' to help page git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@774 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/talk.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/pttbbs/mbbsd/talk.c b/pttbbs/mbbsd/talk.c index ed952f44..e0980e85 100644 --- a/pttbbs/mbbsd/talk.c +++ b/pttbbs/mbbsd/talk.c @@ -1,4 +1,4 @@ -/* $Id: talk.c,v 1.103 2003/04/06 05:55:07 in2 Exp $ */ +/* $Id: talk.c,v 1.104 2003/04/06 05:58:31 in2 Exp $ */ #include "bbs.h" #define QCAST int (*)(const void *, const void *) @@ -1357,18 +1357,19 @@ t_showhelp() clear(); outs("\033[36m【 休閒聊天使用說明 】\033[m\n\n" - "(←)(e) 結束離開 (h) 看使用說明\n" - "(↑)/(↓)(n) 上下移動 (TAB) 切換排序方式\n" - "(PgUp)(^B) 上頁選單 ( )(PgDn)(^F) 下頁選單\n" - "(Hm)/($)(Ed) 首/尾 (S) 來源/好友描述/戰績 切換\n" - "(m) 寄信 (q/c) 查詢網友/寵物\n" - "(r) 閱\讀信件 (l/C) 看上次熱訊/切換隱身\n" - "(f) 全部/好友列表 (數字) 跳至該使用者\n" - "(p) 切換呼叫器 (g/i) 給錢/切換心情\n" - "(a/d/o) 好友 增加/刪除/修改 (/)(s) 網友ID/暱稱搜尋"); + "(←)(e) 結束離開 (h) 看使用說明\n" + "(↑)/(↓)(n) 上下移動 (TAB) 切換排序方式\n" + "(PgUp)(^B) 上頁選單 ( )(PgDn)(^F) 下頁選單\n" + "(Hm)/($)(Ed) 首/尾 (S) 來源/好友描述/戰績 切換\n" + "(m) 寄信 (q/c) 查詢網友/寵物\n" + "(r) 閱\讀信件 (l/C) 看上次熱訊/切換隱身\n" + "(f) 全部/好友列表 (數字) 跳至該使用者\n" + "(p) 切換呼叫器 (g/i) 給錢/切換心情\n" + "(a/d/o) 好友 增加/刪除/修改 (/)(s) 網友ID/暱稱搜尋\n" + "(N) 修改暱稱"); if (HAS_PERM(PERM_PAGE)) { - outs("\n\n\033[36m【 交談專用鍵 】\033[m\n\n" + outs("\n\n\033[36m【 交談專用鍵 】\033[m\n" "(→)(t)(Enter) 跟他/她聊天\n" "(w) 熱線 Call in\n" "(W)切換水球方式 一般 / 進階 / 未來\n" -- cgit v1.2.3 From abe9f1d358bc45f861b127f4a98db615de930e0e Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sun, 6 Apr 2003 16:45:13 +0000 Subject: use DOECHO instead of LCECHO in changing nickname git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@775 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/talk.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pttbbs/mbbsd/talk.c b/pttbbs/mbbsd/talk.c index e0980e85..e32db7d3 100644 --- a/pttbbs/mbbsd/talk.c +++ b/pttbbs/mbbsd/talk.c @@ -1,4 +1,4 @@ -/* $Id: talk.c,v 1.104 2003/04/06 05:58:31 in2 Exp $ */ +/* $Id: talk.c,v 1.105 2003/04/06 16:45:13 in2 Exp $ */ #include "bbs.h" #define QCAST int (*)(const void *, const void *) @@ -2300,7 +2300,7 @@ userlist(void) case 'N': oldgetdata(1, 0, "新的暱稱: ", - cuser.username, sizeof(cuser.username), LCECHO); + cuser.username, sizeof(cuser.username), DOECHO); strcpy(currutmp->username, cuser.username); redrawall = redraw = 1; break; -- cgit v1.2.3 From 6cab902ae1466028ea35e50cc17df25e0817a69a Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Mon, 7 Apr 2003 03:55:17 +0000 Subject: add GV2(globalvar2) structure into gap3[] git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@776 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/include/pttstruct.h | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/pttbbs/include/pttstruct.h b/pttbbs/include/pttstruct.h index dc457e75..5ea7e799 100644 --- a/pttbbs/include/pttstruct.h +++ b/pttbbs/include/pttstruct.h @@ -1,4 +1,4 @@ -/* $Id: pttstruct.h,v 1.31 2003/03/26 11:06:04 in2 Exp $ */ +/* $Id: pttstruct.h,v 1.32 2003/04/07 03:55:17 in2 Exp $ */ #ifndef INCLUDE_STRUCT_H #define INCLUDE_STRUCT_H @@ -349,7 +349,15 @@ typedef struct { int GLOBALVAR[10]; /* mbbsd間的 global variable 用以做統計等資料 (非常態) */ - char gap3[1024]; /* avoid some memory error / buffer overflow */ + char gap3_1[128]; /* gap3 1024 bytes */ + union { + int v[192]; + struct { + int dyactive; + } e; + } GV2; + char gap3_2[128]; + /* fromcache */ char domain[MAX_FROM][50]; char replace[MAX_FROM][50]; -- cgit v1.2.3 From dce13d9c47121fd29a7b4165bd6b87976857e8d5 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Mon, 7 Apr 2003 03:55:30 +0000 Subject: support GV2 git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@777 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/shmctl.c | 36 ++++++++++++++++++++++++++---------- 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/pttbbs/util/shmctl.c b/pttbbs/util/shmctl.c index 828e9d38..1417c2b0 100644 --- a/pttbbs/util/shmctl.c +++ b/pttbbs/util/shmctl.c @@ -1,4 +1,4 @@ -/* $Id: shmctl.c,v 1.35 2003/03/22 12:18:15 in2 Exp $ */ +/* $Id: shmctl.c,v 1.36 2003/04/07 03:55:30 in2 Exp $ */ #include "bbs.h" #include <sys/wait.h> @@ -337,27 +337,43 @@ int utmpnum(int argc, char **argv) return 0; } +char *GV2str[] = {"dyactive", NULL}; int showglobal(int argc, char **argv) { int i; for( i = 0 ; i < 10 ; ++i ) printf("GLOBALVAR[%d] = %d\n", i, SHM->GLOBALVAR[i]); + for( i = 0 ; GV2str[i] != NULL ; ++i ) + printf("GV2.%s = %d\n", GV2str[i], SHM->GV2.v[i]); return 0; } int setglobal(int argc, char **argv) { - int where; - if( argc != 3 ) - return 1; - where = atoi(argv[1]); - if( !(0 <= where && where <= 9) ){ - puts("only GLOBALVAR[0] ~ GLOBALVAR[9]"); + int where, value; + if( argc != 3 ){ + puts("usage: shmctl setglobal ([0-9]|GV2) newvalue"); return 1; } - printf("GLOBALVAR[%d] = %d -> ", where, SHM->GLOBALVAR[where]); - printf("%d\n", SHM->GLOBALVAR[where] = atoi(argv[2])); - return 0; + where = argv[1][0] - '0'; + value = atoi(argv[2]); + + if( 0 <= where && where <= 9 ){ + printf("GLOBALVAR[%d] = %d -> ", where, SHM->GLOBALVAR[where]); + printf("%d\n", SHM->GLOBALVAR[where] = value); + return 0; + } + else{ + for( where = 0 ; GV2str[where] != NULL ; ++where ) + if( strcmp(GV2str[where], argv[1]) == 0 ){ + printf("GV2.%s = %d -> ", GV2str[where], SHM->GV2.v[where]); + printf("%d\n", SHM->GV2.v[where] = value); + return 0; + } + } + printf("GLOBALVAR %s not found\n", argv[1]); + + return 1; } int listpid(int argc, char **argv) -- cgit v1.2.3 From ba6ab8e0ba499442e2964661620647d544aa2583 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Mon, 7 Apr 2003 08:08:47 +0000 Subject: dymaxactive, toomanyusers git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@778 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/include/pttstruct.h | 5 +++-- pttbbs/mbbsd/mbbsd.c | 7 ++++--- pttbbs/util/shmctl.c | 4 ++-- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/pttbbs/include/pttstruct.h b/pttbbs/include/pttstruct.h index 5ea7e799..2e3e5492 100644 --- a/pttbbs/include/pttstruct.h +++ b/pttbbs/include/pttstruct.h @@ -1,4 +1,4 @@ -/* $Id: pttstruct.h,v 1.32 2003/04/07 03:55:17 in2 Exp $ */ +/* $Id: pttstruct.h,v 1.33 2003/04/07 08:08:47 in2 Exp $ */ #ifndef INCLUDE_STRUCT_H #define INCLUDE_STRUCT_H @@ -353,7 +353,8 @@ typedef struct { union { int v[192]; struct { - int dyactive; + int dymaxactive; + int toomanyusers; } e; } GV2; char gap3_2[128]; diff --git a/pttbbs/mbbsd/mbbsd.c b/pttbbs/mbbsd/mbbsd.c index 97ba847a..6eade791 100644 --- a/pttbbs/mbbsd/mbbsd.c +++ b/pttbbs/mbbsd/mbbsd.c @@ -1,4 +1,4 @@ -/* $Id: mbbsd.c,v 1.69 2003/03/28 14:15:20 in2 Exp $ */ +/* $Id: mbbsd.c,v 1.70 2003/04/07 08:08:47 in2 Exp $ */ #include "bbs.h" #define SOCKET_QLEN 4 @@ -1342,10 +1342,11 @@ check_ban_and_load(int fd) } if (SHM->UTMPnumber >= MAX_ACTIVE #ifdef DYMAX_ACTIVE - || (GLOBALVAR[9] > 500 && SHM->UTMPnumber >= GLOBALVAR[9] ) + || (SHM->GV2.e.dymaxactive > 2000 && + SHM->UTMPnumber >= SHM->GV2.e.dymaxactive) #endif ) { - ++GLOBALVAR[8]; + ++SHM->GV2.e.toomanyusers; snprintf(buf, sizeof(buf), "由於人數過多,請您稍後再來。"); write(fd, buf, strlen(buf)); overload = 1; diff --git a/pttbbs/util/shmctl.c b/pttbbs/util/shmctl.c index 1417c2b0..2232c42d 100644 --- a/pttbbs/util/shmctl.c +++ b/pttbbs/util/shmctl.c @@ -1,4 +1,4 @@ -/* $Id: shmctl.c,v 1.36 2003/04/07 03:55:30 in2 Exp $ */ +/* $Id: shmctl.c,v 1.37 2003/04/07 08:08:47 in2 Exp $ */ #include "bbs.h" #include <sys/wait.h> @@ -337,7 +337,7 @@ int utmpnum(int argc, char **argv) return 0; } -char *GV2str[] = {"dyactive", NULL}; +char *GV2str[] = {"dymaxactive", "toomanyusers", NULL}; int showglobal(int argc, char **argv) { int i; -- cgit v1.2.3 From 488f3a6b8feac5a4a97c820f7abaf1eee9181519 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Tue, 8 Apr 2003 09:50:59 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@779 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/mvdir.pl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pttbbs/util/mvdir.pl b/pttbbs/util/mvdir.pl index 53acd9b3..e853df05 100644 --- a/pttbbs/util/mvdir.pl +++ b/pttbbs/util/mvdir.pl @@ -28,7 +28,7 @@ unlink $sym; symlink($todir, $sym); foreach( @dirs ){ - printf("processing %-20s (%04d/%04d)\n", $_, ++$index, $#dirs); + printf("processing %-20s (%04d/%04d)\n", $_, $index++, $#dirs); unlink "$todir/$_"; `mv $fromdir/$_ $todir/$_`; } -- cgit v1.2.3 From 4b85795a7dcfdd30466e327ae465f4c6a1fd7528 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Tue, 8 Apr 2003 09:53:21 +0000 Subject: when GV2.e.noonlineuser, do NOT search if the author is online in article list git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@780 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/include/pttstruct.h | 7 ++++--- pttbbs/mbbsd/bbs.c | 3 ++- pttbbs/util/shmctl.c | 5 +++-- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/pttbbs/include/pttstruct.h b/pttbbs/include/pttstruct.h index 2e3e5492..0d60a7a5 100644 --- a/pttbbs/include/pttstruct.h +++ b/pttbbs/include/pttstruct.h @@ -1,4 +1,4 @@ -/* $Id: pttstruct.h,v 1.33 2003/04/07 08:08:47 in2 Exp $ */ +/* $Id: pttstruct.h,v 1.34 2003/04/08 09:53:21 in2 Exp $ */ #ifndef INCLUDE_STRUCT_H #define INCLUDE_STRUCT_H @@ -353,8 +353,9 @@ typedef struct { union { int v[192]; struct { - int dymaxactive; - int toomanyusers; + int dymaxactive; /* 動態設定最大人數上限 */ + int toomanyusers; /* 超過人數上限不給進的個數 */ + int noonlineuser; /* 站上使用者不高亮度顯示 */ } e; } GV2; char gap3_2[128]; diff --git a/pttbbs/mbbsd/bbs.c b/pttbbs/mbbsd/bbs.c index 65c5408a..2651e328 100644 --- a/pttbbs/mbbsd/bbs.c +++ b/pttbbs/mbbsd/bbs.c @@ -1,4 +1,4 @@ -/* $Id: bbs.c,v 1.83 2003/03/20 15:10:49 victor Exp $ */ +/* $Id: bbs.c,v 1.84 2003/04/08 09:53:21 in2 Exp $ */ #include "bbs.h" static void @@ -165,6 +165,7 @@ readdoent(int num, fileheader_t * ent) if (!strncmp(title, "[公告]", 6)) special = 1; if (!strchr(ent->owner, '.') && (uid = searchuser(ent->owner)) && + !SHM->GV2.e.noonlineuser && (uentp = search_ulist(uid)) && isvisible(currutmp, uentp)) isonline = 1; diff --git a/pttbbs/util/shmctl.c b/pttbbs/util/shmctl.c index 2232c42d..89c9069a 100644 --- a/pttbbs/util/shmctl.c +++ b/pttbbs/util/shmctl.c @@ -1,4 +1,4 @@ -/* $Id: shmctl.c,v 1.37 2003/04/07 08:08:47 in2 Exp $ */ +/* $Id: shmctl.c,v 1.38 2003/04/08 09:53:21 in2 Exp $ */ #include "bbs.h" #include <sys/wait.h> @@ -337,7 +337,8 @@ int utmpnum(int argc, char **argv) return 0; } -char *GV2str[] = {"dymaxactive", "toomanyusers", NULL}; +char *GV2str[] = {"dymaxactive", "toomanyusers", + "noonlineuser", NULL}; int showglobal(int argc, char **argv) { int i; -- cgit v1.2.3 From d347859dc8f127cbb9009da4cf48303b46241c18 Mon Sep 17 00:00:00 2001 From: victor <victor@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Tue, 8 Apr 2003 16:05:03 +0000 Subject: fix rm fav while > max git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@781 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/board.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pttbbs/mbbsd/board.c b/pttbbs/mbbsd/board.c index a6cc38e2..c39f704d 100644 --- a/pttbbs/mbbsd/board.c +++ b/pttbbs/mbbsd/board.c @@ -1,4 +1,4 @@ -/* $Id: board.c,v 1.121 2003/04/04 16:06:02 victor Exp $ */ +/* $Id: board.c,v 1.122 2003/04/08 16:05:03 victor Exp $ */ #include "bbs.h" #define BRC_STRLEN 15 /* Length of board name */ #define BRC_MAXSIZE 24576 @@ -1260,7 +1260,7 @@ choose_board(int newflag) delfavline(nbrd[num].bid, num); brdnum = -1; } - else if(fav->nDatas > FAVMAX){ + else if(!(nbrd[num].myattr & BRD_FAV) && (fav->nDatas > FAVMAX)){ vmsg("你的最愛太多了啦 真花心"); break; } -- cgit v1.2.3 From ad3fa1ab29ab3b73e5b846bf7762995a7f31a177 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Tue, 8 Apr 2003 17:25:01 +0000 Subject: double check if access control violation git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@782 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/bbs.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pttbbs/mbbsd/bbs.c b/pttbbs/mbbsd/bbs.c index 2651e328..f031d919 100644 --- a/pttbbs/mbbsd/bbs.c +++ b/pttbbs/mbbsd/bbs.c @@ -1,4 +1,4 @@ -/* $Id: bbs.c,v 1.84 2003/04/08 09:53:21 in2 Exp $ */ +/* $Id: bbs.c,v 1.85 2003/04/08 17:25:01 in2 Exp $ */ #include "bbs.h" static void @@ -106,6 +106,10 @@ set_board() boardheader_t *bp; bp = getbcache(currbid); + if( !Ben_Perm(bp) ){ + vmsg("access control violation, exit"); + u_exit("access control violation!"); + } board_note_time = bp->bupdate; brd_title = bp->BM; if (brd_title[0] <= ' ') -- cgit v1.2.3 From a362428334fa331fde037a3cb2b93312c70a4001 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Wed, 9 Apr 2003 11:43:35 +0000 Subject: reduce memory usage git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@783 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/edit.c | 63 +++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 47 insertions(+), 16 deletions(-) diff --git a/pttbbs/mbbsd/edit.c b/pttbbs/mbbsd/edit.c index dd8bb578..a30b92cb 100644 --- a/pttbbs/mbbsd/edit.c +++ b/pttbbs/mbbsd/edit.c @@ -1,10 +1,10 @@ -/* $Id: edit.c,v 1.27 2003/01/19 16:18:17 kcwu Exp $ */ +/* $Id: edit.c,v 1.28 2003/04/09 11:43:35 in2 Exp $ */ #include "bbs.h" typedef struct textline_t { struct textline_t *prev; struct textline_t *next; int len; - char data[WRAPMARGIN + 1]; + char data[1]; } textline_t; #define KEEP_EDITING -2 @@ -170,12 +170,12 @@ killsp(char *s) } static textline_t * -alloc_line() +alloc_line(short length) { register textline_t *p; - if ((p = (textline_t *) malloc(sizeof(textline_t)))) { - memset(p, 0, sizeof(textline_t)); + if ((p = (textline_t *) malloc(length + sizeof(textline_t)))) { + memset(p, 0, length + sizeof(textline_t)); return p; } indigestion(13); @@ -259,21 +259,36 @@ indent_spcs() return 0; } +static textline_t * +adjustline(textline_t *oldp, short len) +{ + textline_t tmpl[sizeof(textline_t) + WRAPMARGIN]; + textline_t *newp; + memcpy(tmpl, oldp, len + sizeof(textline_t)); + free(oldp); + + newp = alloc_line(len); + memcpy(newp, tmpl, len + sizeof(textline_t)); + if( oldp == firstline ) firstline = newp; + if( oldp == lastline ) lastline = newp; + if( oldp == currline ) currline = newp; + if( oldp == blockline ) blockline = newp; + if( oldp == top_of_win) top_of_win= newp; + if( newp->prev != NULL ) newp->prev->next = newp; + if( newp->next != NULL ) newp->next->prev = newp; + // vmsg("adjust %x to %x, length: %d", (int)oldp, (int)newp, len); + return newp; +} + /* split 'line' right before the character pos */ -static void +static textline_t * split(textline_t * line, int pos) { if (pos <= line->len) { - register textline_t *p = alloc_line(); + register textline_t *p = alloc_line(WRAPMARGIN); register char *ptr; int spcs = indent_spcs(); -#ifdef MAX_EDIT_LINE - if( totaln == MAX_EDIT_LINE ){ - vmsg("MAX_EDIT_LINE exceed"); - return; - } -#endif totaln++; p->len = line->len - pos + spcs; @@ -284,6 +299,7 @@ split(textline_t * line, int pos) strcat(p->data, (ptr = line->data + pos)); ptr[0] = '\0'; append(p, line); + line = adjustline(line, line->len); if (line == currline && pos <= currpnt) { currline = p; if (pos == currpnt) @@ -295,6 +311,7 @@ split(textline_t * line, int pos) } redraw_everything = YEA; } + return line; } static void @@ -333,7 +350,7 @@ insert_char(int ch) wordwrap = NA; s = p->data + (i - 2); } - split(p, (s - p->data) + 1); + p = split(p, (s - p->data) + 1); p = p->next; i = p->len; if (wordwrap && i >= 1) { @@ -1419,7 +1436,7 @@ block_del(int hide) top_of_win = firstline = end->next; else { currline = top_of_win = firstline = - lastline = alloc_line(); + lastline = alloc_line(WRAPMARGIN); currln = curr_window_line = edit_margin = 0; } @@ -1594,6 +1611,7 @@ vedit(char *fpath, int saveheader, int *islocal) textline_t *currline0 = currline; textline_t *blockline0 = blockline; textline_t *top_of_win0 = top_of_win; + textline_t *oldcurrline; int local_article0 = local_article; int currpnt0 = currpnt; int currln0 = currln; @@ -1610,7 +1628,8 @@ vedit(char *fpath, int saveheader, int *islocal) prevln = blockln = -1; line_dirty = currpnt = totaln = my_ansimode = 0; - currline = top_of_win = firstline = lastline = alloc_line(); + oldcurrline = currline = top_of_win = + firstline = lastline = alloc_line(WRAPMARGIN); if (*fpath) read_file(fpath); @@ -1629,6 +1648,10 @@ vedit(char *fpath, int saveheader, int *islocal) display_buffer(); redraw_everything = NA; } + if( oldcurrline != currline ){ + oldcurrline = adjustline(oldcurrline, oldcurrline->len); + oldcurrline = currline = adjustline(currline, WRAPMARGIN); + } if (my_ansimode) ch = n2ansi(currpnt, currline); else @@ -1975,7 +1998,14 @@ vedit(char *fpath, int saveheader, int *islocal) break; case '\r': case '\n': +#ifdef MAX_EDIT_LINE + if( totaln == MAX_EDIT_LINE ){ + vmsg("MAX_EDIT_LINE exceed"); + break; + } +#endif split(currline, currpnt); + oldcurrline = currline; line_dirty = 0; break; case Ctrl('G'): @@ -2229,6 +2259,7 @@ vedit(char *fpath, int saveheader, int *islocal) currline = p; redraw_everything = YEA; line_dirty = 0; + oldcurrline = currline = adjustline(currline, WRAPMARGIN); break; } if (currline->len == currpnt) { -- cgit v1.2.3 From 3022b87714abc18dfdd7cf2f9e799a54e4fc5ad5 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Thu, 10 Apr 2003 05:43:44 +0000 Subject: fix bug, add debug information if DEBUG git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@784 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/edit.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/pttbbs/mbbsd/edit.c b/pttbbs/mbbsd/edit.c index a30b92cb..731f5177 100644 --- a/pttbbs/mbbsd/edit.c +++ b/pttbbs/mbbsd/edit.c @@ -1,9 +1,12 @@ -/* $Id: edit.c,v 1.28 2003/04/09 11:43:35 in2 Exp $ */ +/* $Id: edit.c,v 1.29 2003/04/10 05:43:44 in2 Exp $ */ #include "bbs.h" typedef struct textline_t { struct textline_t *prev; struct textline_t *next; - int len; + short len; +#ifdef DEBUG + short mlength; +#endif char data[1]; } textline_t; @@ -176,6 +179,9 @@ alloc_line(short length) if ((p = (textline_t *) malloc(length + sizeof(textline_t)))) { memset(p, 0, length + sizeof(textline_t)); +#ifdef DEBUG + p->mlength = length; +#endif return p; } indigestion(13); @@ -269,6 +275,9 @@ adjustline(textline_t *oldp, short len) newp = alloc_line(len); memcpy(newp, tmpl, len + sizeof(textline_t)); +#ifdef DEBUG + newp->mlength = len; +#endif if( oldp == firstline ) firstline = newp; if( oldp == lastline ) lastline = newp; if( oldp == currline ) currline = newp; @@ -2198,6 +2207,7 @@ vedit(char *fpath, int saveheader, int *islocal) curr_window_line--; currln--; currline = currline->prev; + currline = adjustline(currline, WRAPMARGIN); currpnt = currline->len; redraw_everything = YEA; if (*killsp(currline->next->data) == '\0') { -- cgit v1.2.3 From 387b2ab2360d7bee720c0c14e1153309ae578cf4 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Thu, 10 Apr 2003 06:01:28 +0000 Subject: dirty fix. would this cause memory leak? git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@785 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/edit.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pttbbs/mbbsd/edit.c b/pttbbs/mbbsd/edit.c index 731f5177..f3dce0b2 100644 --- a/pttbbs/mbbsd/edit.c +++ b/pttbbs/mbbsd/edit.c @@ -1,4 +1,4 @@ -/* $Id: edit.c,v 1.29 2003/04/10 05:43:44 in2 Exp $ */ +/* $Id: edit.c,v 1.30 2003/04/10 06:01:28 in2 Exp $ */ #include "bbs.h" typedef struct textline_t { struct textline_t *prev; @@ -2208,6 +2208,10 @@ vedit(char *fpath, int saveheader, int *islocal) currln--; currline = currline->prev; currline = adjustline(currline, WRAPMARGIN); + + // dirty fix. would this cause memory leak? + oldcurrline = currline; + currpnt = currline->len; redraw_everything = YEA; if (*killsp(currline->next->data) == '\0') { -- cgit v1.2.3 From 7298a3413e72dad05ecc833f3bedb1732c956304 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Thu, 10 Apr 2003 10:26:08 +0000 Subject: handle bad input to avoid SIGSEGV git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@786 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/bbsmail.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/pttbbs/util/bbsmail.c b/pttbbs/util/bbsmail.c index 0663a5c8..8e326ad7 100644 --- a/pttbbs/util/bbsmail.c +++ b/pttbbs/util/bbsmail.c @@ -1,4 +1,4 @@ -/* $Id: bbsmail.c,v 1.6 2002/11/02 11:15:27 in2 Exp $ */ +/* $Id: bbsmail.c,v 1.7 2003/04/10 10:26:08 in2 Exp $ */ #define _UTIL_C_ #include "bbs.h" @@ -133,7 +133,11 @@ mail2bbs(userid) if (ip[-1] == ' ') ip[-1] = '\0'; ptr = (char *) strchr(genbuf, ' '); - while (*ptr == ' ') ptr++; + if( ptr ) + while (*ptr == ' ') + ptr++; + else + ptr = "unknown"; sprintf(sender, "%s (%s)", ip + 1, ptr); } else -- cgit v1.2.3 From 902e750f69a4c6873d9dd70a4f86cbae3f0cea25 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Thu, 10 Apr 2003 18:05:45 +0000 Subject: sleep interval in argv[1] git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@787 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/shmctl.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/pttbbs/util/shmctl.c b/pttbbs/util/shmctl.c index 89c9069a..04f5b112 100644 --- a/pttbbs/util/shmctl.c +++ b/pttbbs/util/shmctl.c @@ -1,4 +1,4 @@ -/* $Id: shmctl.c,v 1.38 2003/04/08 09:53:21 in2 Exp $ */ +/* $Id: shmctl.c,v 1.39 2003/04/10 18:05:45 in2 Exp $ */ #include "bbs.h" #include <sys/wait.h> @@ -257,11 +257,16 @@ inline void utmpsort(void) int utmpsortd(int argc, char **argv) { pid_t pid; + int interval; // sleep interval in microsecond(1/10**6) + if( fork() > 0 ){ puts("sortutmpd daemonized..."); return 0; } + if( argc != 2 || (interval = atoi(argv[1])) < 500000 ) + interval = 1000000; // default to 1 sec + while( 1 ){ if( (pid = fork()) != 0 ){ int s; @@ -276,7 +281,7 @@ int utmpsortd(int argc, char **argv) if( SHM->UTMPneedsort ) utmpsort(); - sleep(1); + usleep(interval); } } } -- cgit v1.2.3 From abc5a845c8e1ba64a17156e9c0d1aab7dc32efcb Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sun, 13 Apr 2003 03:26:45 +0000 Subject: remove mrtg program git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@788 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/sample/crontab | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/pttbbs/sample/crontab b/pttbbs/sample/crontab index 3cf76fdc..5cda4092 100644 --- a/pttbbs/sample/crontab +++ b/pttbbs/sample/crontab @@ -70,10 +70,7 @@ # mrtg每五分鐘計算一次 -*/5 * * * * bin/shmctl utmpnum > /tmp/utmpnum -*/5 * * * * bin/lookhdd.pl > /tmp/hdd -*/5 * * * * /usr/local/bin/getuptime -x > /tmp/uptime -*/5 * * * * /bin/ps -ax | /usr/bin/wc -l > /tmp/nps +#*/5 * * * * bin/shmctl utmpnum > /tmp/utmpnum # ??? 10 7 * * * bin/buildAnnounce -- cgit v1.2.3 From 3446eda54d5e50c9a3147cd5b7599e7ee938613f Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sun, 13 Apr 2003 22:34:46 +0000 Subject: remove bad dir git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@789 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/rebuildaloha.pl | Bin 639 -> 737 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/pttbbs/util/rebuildaloha.pl b/pttbbs/util/rebuildaloha.pl index 06c06a82..c8262e41 100644 Binary files a/pttbbs/util/rebuildaloha.pl and b/pttbbs/util/rebuildaloha.pl differ -- cgit v1.2.3 From ef673aba95903ecbc44a8cafd1956365b7b73b40 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Mon, 14 Apr 2003 07:47:54 +0000 Subject: open /dev/null to fd:2 (stderr) git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@790 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/mbbsd.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/pttbbs/mbbsd/mbbsd.c b/pttbbs/mbbsd/mbbsd.c index 6eade791..ef35cfe9 100644 --- a/pttbbs/mbbsd/mbbsd.c +++ b/pttbbs/mbbsd/mbbsd.c @@ -1,4 +1,4 @@ -/* $Id: mbbsd.c,v 1.70 2003/04/07 08:08:47 in2 Exp $ */ +/* $Id: mbbsd.c,v 1.71 2003/04/14 07:47:54 in2 Exp $ */ #include "bbs.h" #define SOCKET_QLEN 4 @@ -32,7 +32,7 @@ signal_restart(int signum, void (*handler) (int)) static void start_daemon() { - int n; + int n, fd; char buf[80]; /* @@ -56,6 +56,13 @@ start_daemon() n = getdtablesize(); while (n) close(--n); + + /* in2: open /dev/null to fd:2 */ + if( ((fd = open("/dev/null", O_WRONLY)) >= 0) && fd != 2 ){ + dup2(fd, 2); + close(fd); + } + /* * rocker.011018: we don't need to remember original tty, so request a * new session id -- cgit v1.2.3 From 4d65af300be80eb3f4a99547d1dec8c59853d0c9 Mon Sep 17 00:00:00 2001 From: victor <victor@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Mon, 14 Apr 2003 08:54:30 +0000 Subject: allow recommend in search mode in a board git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@791 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/bbs.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/pttbbs/mbbsd/bbs.c b/pttbbs/mbbsd/bbs.c index f031d919..61234a36 100644 --- a/pttbbs/mbbsd/bbs.c +++ b/pttbbs/mbbsd/bbs.c @@ -1,4 +1,4 @@ -/* $Id: bbs.c,v 1.85 2003/04/08 17:25:01 in2 Exp $ */ +/* $Id: bbs.c,v 1.86 2003/04/14 08:54:30 victor Exp $ */ #include "bbs.h" static void @@ -1227,9 +1227,6 @@ recommend(int ent, fileheader_t * fhdr, char *direct) boardheader_t *bp; static time_t lastrecommend = 0; - if( currmode & MODE_SELECT ) - return DONOTHING; - bp = getbcache(currbid); if( bp->brdattr & BRD_NORECOMMEND ){ vmsg("抱歉, 本板禁止推薦"); -- cgit v1.2.3 From cc21260a3dcf96d779098e75a9f7206f670eb494 Mon Sep 17 00:00:00 2001 From: victor <victor@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Mon, 14 Apr 2003 15:23:07 +0000 Subject: fix ^D (tolower), and allow del in MODE_SELECT git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@792 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/read.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pttbbs/mbbsd/read.c b/pttbbs/mbbsd/read.c index 68c253c2..fdf8183e 100644 --- a/pttbbs/mbbsd/read.c +++ b/pttbbs/mbbsd/read.c @@ -1,4 +1,4 @@ -/* $Id: read.c,v 1.20 2003/02/20 16:18:24 in2 Exp $ */ +/* $Id: read.c,v 1.21 2003/04/14 15:23:07 victor Exp $ */ #include "bbs.h" static fileheader_t *headers = NULL; @@ -167,7 +167,7 @@ TagPruner(int bid) if (strcmp(bp->brdname, "Security") == 0) return DONOTHING; if (TagNum && ((currstat != READING) || (currmode & MODE_BOARD))) { - if (getans("刪除所有標記[N]?") != 'y') + if (tolower(getans("刪除所有標記[N]?")) != 'y') return FULLUPDATE; delete_range(currdirect, 0, 0); TagNum = 0; -- cgit v1.2.3 From adbf834e452bd2d3cd9dc9207f928f0ca689babd Mon Sep 17 00:00:00 2001 From: ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Mon, 14 Apr 2003 18:27:08 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@793 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/web/l | 2 +- pttbbs/web/mod_ptt.c | 155 +++++++++++++++++++++++++++++++++++++++++---------- 2 files changed, 126 insertions(+), 31 deletions(-) diff --git a/pttbbs/web/l b/pttbbs/web/l index 2ceb6767..5feafa93 100755 --- a/pttbbs/web/l +++ b/pttbbs/web/l @@ -1 +1 @@ -lynx -dump ptt.cc/test.ptt +lynx -dump ptt.cc/menu diff --git a/pttbbs/web/mod_ptt.c b/pttbbs/web/mod_ptt.c index ecb77117..d5606e9f 100644 --- a/pttbbs/web/mod_ptt.c +++ b/pttbbs/web/mod_ptt.c @@ -42,48 +42,143 @@ static void setup_module_cells() } - -static int ptt_handler(request_rec *r) +static int xml_header(request_rec *r) +{ + r->content_type = "text/xml"; + ap_send_http_header(r); + ap_rputs("<?xml version=\"1.0\" encoding=\"Big5\"?> \n", r); + ap_rprintf(r, "<!-- HTTP-Server-version=\"%s\"\n", + ap_get_server_version()); + ap_rprintf(r," r-filename=\"%s\"\n",r->filename); + ap_rprintf(r," r-request_time=\"%s\"\n",ctime(&r->request_time)); + ap_rprintf(r," r-method=\"%s\"\n",r->method); + ap_rprintf(r," r-method_number=\"%d\"\n",r->method_number); + ap_rprintf(r," r-path_info=\"%s\"\n",r->path_info); + ap_rprintf(r," r-args=\"%s\"\n",r->args); + ap_rprintf(r," r-unparsed_uri=\"%s\"\n",r->unparsed_uri); + ap_rprintf(r," r-handler=\"%s\"\n",r->handler); + ap_rprintf(r," r-content_type=\"%s\"\n",r->content_type); + ap_rprintf(r, " Serverbuilt=\"%s\" \n", ap_get_server_built()); + ap_rprintf(r, " numboards=\"%d\" \n", numboards); + ap_rprintf(r, " shm=\"%d\" \n", SHM->loaded ); + ap_rprintf(r, " max_user=\"%d\" -->", SHM->max_user ); +} +static int showboard(request_rec *r, int id) { int i; - excfg *dcfg; - + boardheader_t *bptr=NULL; + id=id-1; + ap_rprintf(r,"<brdlist>"); + bptr = (boardheader_t *)bcache[id].firstchild[0]; + for(; bptr!= (boardheader_t*)~0; ) + { + if((bcache[id].brdattr&BRD_HIDE)|| + bcache[id].level&& !(bcache[id].brdattr & BRD_POSTMASK )) continue; + ap_rprintf(r,"<brd>\n"); + i=(bptr-bcache); + ap_rprintf(r," <bid>%d</bid>",i+1); + ap_rprintf(r," <brdname>%s</brdname>\n",bptr->brdname); + ap_rprintf(r," <title>%s\n",ap_escape_html(r->pool,bptr->title)); + ap_rprintf(r," %d\n",bptr->nuser); + ap_rprintf(r," %d\n",bptr->gid); + ap_rprintf(r," %d\n",bptr->childcount); + ap_rprintf(r," %s\n",bptr->BM); + ap_rprintf(r," %d\n",bptr->brdattr); + ap_rprintf(r," %d\n",SHM->total[i]); + ap_rprintf(r,"\n"); + bptr=(boardheader_t*)bptr->next[0]; + } + + ap_rprintf(r,""); +} - dcfg = our_dconfig(r); - r->content_type = "text/html"; - ap_soft_timeout("send ptt call trace", r); +static int showpost(request_rec *r,int bid,int id, int num) +{ + int i; + num=256; + id=1; + char path[512]; + fileheader_t headers[256]; + memset(headers,0, sizeof(fileheader_t)*256); + sprintf(path,BBSHOME"/boards/%c/%s/.DIR", + bcache[bid-1].brdname[0],bcache[bid-1].brdname); + get_records(path, headers, sizeof(fileheader_t)*256, id,num); + + ap_rprintf(r,""); + + for(i=0;i<256;i++) + { + ap_rprintf(r,"\n"); + ap_rprintf(r," %d",i+1); + ap_rprintf(r," %s\n",headers[i].filename); + ap_rprintf(r," %s\n",headers[i].owner); + ap_rprintf(r," %s\n",headers[i].date); + ap_rprintf(r," %s\n", + ap_escape_html(r->pool,headers[i].title)); + ap_rprintf(r," %d\n",headers[i].money); + ap_rprintf(r," %c\n",headers[i].filemode); + ap_rprintf(r," %d\n",headers[i].recommend); + ap_rprintf(r,"\n"); + } + ap_rprintf(r,""); +} +static int showmenujs(request_rec *r) +{ + int i; + boardheader_t *bptr; + r->content_type = "text/text"; ap_send_http_header(r); + ap_rputs("d=new dTree('d');\n",r); + ap_rputs("d.add(0,-1,'Class','');\n",r); + for(i=1;i<=numboards;i++) + { + bptr=&bcache[i-1]; + if(!isalpha(bptr->brdname[0]))continue; + + ap_rprintf(r,"d.add(%d,%d,\"%s %s..\",'/boards?%s');\n", + i,bptr->gid-1, + bptr->gid==1?"":bptr->brdname, + ap_escape_quotes(r->pool, + ap_escape_html(r->pool,bptr->title+7)),i); + } + ap_rputs("d.draw()\n",r); + return OK; +} +static int showxml(request_rec *r) +{ + int bid=1; + xml_header(r); if (r->header_only) { ap_kill_timeout(r); return OK; } + if(r->args) bid=atoi(r->args); + if(bid<1 || bid>numboards)bid=1; + + if( + !(bcache[bid-1].brdattr&BRD_HIDE)&& + !(bcache[bid-1].level&&!(bcache[bid-1].brdattr & BRD_POSTMASK))) + if( bid==1||bcache[bid-1].brdattr&BRD_GROUPBOARD) + showboard(r,bid); + else + showpost(r,bid,0,0); + return OK; +} +static int ptt_handler(request_rec *r) +{ + excfg *dcfg; - ap_rputs(" ptt3

\n", r); + dcfg = our_dconfig(r); + + ap_soft_timeout("send ptt call trace", r); + + if(!strncmp(r->unparsed_uri,"/menu",5)) + showmenujs(r); + else + showxml(r); - ap_rprintf(r, " Apache HTTP Server version: \"%s\"\n", - ap_get_server_version()); - ap_rprintf(r,"r->filename : %s
",r->filename); - ap_rprintf(r,"r->request_time : %s
",ctime(&r->request_time)); - ap_rprintf(r,"r->method : %s
",r->method); - ap_rprintf(r,"r->method_number : %d
",r->method_number); - ap_rprintf(r,"r->path_info : %s
",r->path_info); - ap_rprintf(r,"r->args : %s
",r->args); - ap_rprintf(r,"r->unparsed_uri : %s
",r->unparsed_uri); - ap_rprintf(r,"r->handler : %s
",r->handler); - ap_rprintf(r,"r->content_type : %s
",r->content_type); - - - ap_rprintf(r, " Server built: \"%s\"
", ap_get_server_built()); - ap_rprintf(r, " numboards: \"%d\"
", numboards); - ap_rprintf(r, " shm: \"%d\"
", SHM->loaded ); - ap_rprintf(r, " max_user:%d
", SHM->max_user ); - for(i = 0; i < 10; i++) - ap_rprintf(r,"%d. %s %s
",i,bcache[i].brdname,bcache[i].title); - - // for(i = 0; i < 10 /*numboards*/; i++) - // ap_rprintf(r,"%s %s
",bcache[i].brdname,bcache[i].title); ap_kill_timeout(r); return OK; } -- cgit v1.2.3 From 6aefa4e7ec12559226be6269a78631f93cfd8503 Mon Sep 17 00:00:00 2001 From: ptt Date: Mon, 14 Apr 2003 19:46:14 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@794 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/web/mod_ptt.c | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/pttbbs/web/mod_ptt.c b/pttbbs/web/mod_ptt.c index d5606e9f..3c4309ed 100644 --- a/pttbbs/web/mod_ptt.c +++ b/pttbbs/web/mod_ptt.c @@ -63,6 +63,37 @@ static int xml_header(request_rec *r) ap_rprintf(r, " shm=\"%d\" \n", SHM->loaded ); ap_rprintf(r, " max_user=\"%d\" -->", SHM->max_user ); } +static int userlist(request_rec *r) +{ + int i,offset=0; + userinfo_t *ptr; + xml_header(r); + if (r->header_only) { + return OK; + } + if(r->args) offset=atoi(r->args); + if(offset<0 || offset>SHM->UTMPnumber)offset=0; + + ap_rprintf(r,""); + for(i=offset;iUTMPnumber && i<50+offset;i++) + { + ptr= (userinfo_t *)SHM->sorted[SHM->currsorted][0][i]; + if(!ptr || ptr->userid[0]==0 || ptr->invisible ) continue; + ap_rprintf(r,"\n"); + ap_rprintf(r," %d\n",i+1); + ap_rprintf(r," %d\n",SHM->UTMPnumber); + ap_rprintf(r," %d\n",ptr->uid); + ap_rprintf(r," %s\n",ptr->userid); + ap_rprintf(r," %s\n", + ap_escape_html(r->pool,ptr->username)); + ap_rprintf(r," %s\n",ptr->from); + ap_rprintf(r," %d\n",ptr->from_alias); + ap_rprintf(r," %d\n",ptr->mailalert); + ap_rprintf(r," %s\n",ap_escape_html(r->pool,ptr->mind)); + ap_rprintf(r,""); + } + ap_rprintf(r,""); +} static int showboard(request_rec *r, int id) { int i; @@ -151,7 +182,6 @@ static int showxml(request_rec *r) int bid=1; xml_header(r); if (r->header_only) { - ap_kill_timeout(r); return OK; } if(r->args) bid=atoi(r->args); @@ -176,7 +206,9 @@ static int ptt_handler(request_rec *r) if(!strncmp(r->unparsed_uri,"/menu",5)) showmenujs(r); - else + else if(!strncmp(r->unparsed_uri,"/userlist",9)) + userlist(r); + else showxml(r); ap_kill_timeout(r); -- cgit v1.2.3 From b455c6218f2abb4aa70b929767e3f5660b65a87d Mon Sep 17 00:00:00 2001 From: in2 Date: Tue, 15 Apr 2003 06:01:18 +0000 Subject: reduce MALLOC()/FREE() git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@795 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/board.c | 43 +++++++++++++++++++++++++++++-------------- 1 file changed, 29 insertions(+), 14 deletions(-) diff --git a/pttbbs/mbbsd/board.c b/pttbbs/mbbsd/board.c index c39f704d..30501181 100644 --- a/pttbbs/mbbsd/board.c +++ b/pttbbs/mbbsd/board.c @@ -1,4 +1,4 @@ -/* $Id: board.c,v 1.122 2003/04/08 16:05:03 victor Exp $ */ +/* $Id: board.c,v 1.123 2003/04/15 06:01:18 in2 Exp $ */ #include "bbs.h" #define BRC_STRLEN 15 /* Length of board name */ #define BRC_MAXSIZE 24576 @@ -718,9 +718,7 @@ load_boards(char *key) int type = cuser.uflag & BRDSORT_FLAG ? 1 : 0; int i, n; int state; -#ifdef CRITICAL_MEMORY - boardstat_t *tmpnbrd; -#endif + char byMALLOC = 0, needREALLOC = 0; if (class_bid > 0) { bptr = &bcache[class_bid - 1]; @@ -733,8 +731,8 @@ load_boards(char *key) nbrd = NULL; } if (class_bid <= 0) { - nbrd = (boardstat_t *) MALLOC(sizeof(boardstat_t) * numboards); if( yank_flag == 0 ){ // fav mode + nbrd = (boardstat_t *)malloc(sizeof(boardstat_t) * fav->nDatas); for( i = 0 ; i < fav->nDatas ; ++i ){ if( fav->b[i].attr & BRD_FAV ){ if( fav->b[i].attr & BRD_LINE ) @@ -746,8 +744,11 @@ load_boards(char *key) } } } + byMALLOC = 0; + needREALLOC = (fav->nDatas != brdnum); } else{ // general case + nbrd = (boardstat_t *) MALLOC(sizeof(boardstat_t) * numboards); for (i = 0; i < numboards; i++) { if ((bptr = SHM->bsorted[type][i]) == NULL) continue; @@ -760,12 +761,19 @@ load_boards(char *key) continue; addnewbrdstat(n, state); } +#ifdef CRITICAL_MEMORY + byMALLOC = 1; +#else + byMALLOC = 0; +#endif + needREALLOC = 1; } if (class_bid == -1) qsort(nbrd, brdnum, sizeof(boardstat_t), cmpboardfriends); } else { - nbrd = (boardstat_t *) MALLOC(bptr->childcount * sizeof(boardstat_t)); + int childcount = bptr->childcount; + nbrd = (boardstat_t *) malloc(childcount * sizeof(boardstat_t)); for (bptr = bptr->firstchild[type]; bptr != (boardheader_t *) ~ 0; bptr = bptr->next[type]) { n = (int)(bptr - bcache); @@ -775,15 +783,22 @@ load_boards(char *key) continue; addnewbrdstat(n, state); } + byMALLOC = 0; + needREALLOC = (childcount != brdnum); + } + + if( needREALLOC ){ + if( byMALLOC ){ + boardstat_t *newnbrd; + newnbrd = (boardstat_t *)malloc(sizeof(boardstat_t) * brdnum); + memcpy(newnbrd, nbrd, sizeof(boardstat_t) * brdnum); + FREE(nbrd); + nbrd = newnbrd; + } + else { + nbrd = (boardstat_t *)realloc(nbrd, sizeof(boardstat_t) * brdnum); + } } -#ifndef CRITICAL_MEMORY - nbrd = realloc(nbrd, sizeof(boardstat_t) * brdnum); -#else - tmpnbrd = (boardstat_t *) malloc(sizeof(boardstat_t) * brdnum); - memcpy(tmpnbrd, nbrd, sizeof(boardstat_t) * brdnum); - FREE(nbrd); - nbrd = tmpnbrd; -#endif } static int -- cgit v1.2.3 From cd3c3d2099700d5e948e6c448e491100275fd4d5 Mon Sep 17 00:00:00 2001 From: in2 Date: Tue, 15 Apr 2003 06:07:23 +0000 Subject: revert to 1.122, some problems with new favorite system git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@796 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/board.c | 43 ++++++++++++++----------------------------- 1 file changed, 14 insertions(+), 29 deletions(-) diff --git a/pttbbs/mbbsd/board.c b/pttbbs/mbbsd/board.c index 30501181..ccd208b9 100644 --- a/pttbbs/mbbsd/board.c +++ b/pttbbs/mbbsd/board.c @@ -1,4 +1,4 @@ -/* $Id: board.c,v 1.123 2003/04/15 06:01:18 in2 Exp $ */ +/* $Id: board.c,v 1.124 2003/04/15 06:07:23 in2 Exp $ */ #include "bbs.h" #define BRC_STRLEN 15 /* Length of board name */ #define BRC_MAXSIZE 24576 @@ -718,7 +718,9 @@ load_boards(char *key) int type = cuser.uflag & BRDSORT_FLAG ? 1 : 0; int i, n; int state; - char byMALLOC = 0, needREALLOC = 0; +#ifdef CRITICAL_MEMORY + boardstat_t *tmpnbrd; +#endif if (class_bid > 0) { bptr = &bcache[class_bid - 1]; @@ -731,8 +733,8 @@ load_boards(char *key) nbrd = NULL; } if (class_bid <= 0) { + nbrd = (boardstat_t *) MALLOC(sizeof(boardstat_t) * numboards); if( yank_flag == 0 ){ // fav mode - nbrd = (boardstat_t *)malloc(sizeof(boardstat_t) * fav->nDatas); for( i = 0 ; i < fav->nDatas ; ++i ){ if( fav->b[i].attr & BRD_FAV ){ if( fav->b[i].attr & BRD_LINE ) @@ -744,11 +746,8 @@ load_boards(char *key) } } } - byMALLOC = 0; - needREALLOC = (fav->nDatas != brdnum); } else{ // general case - nbrd = (boardstat_t *) MALLOC(sizeof(boardstat_t) * numboards); for (i = 0; i < numboards; i++) { if ((bptr = SHM->bsorted[type][i]) == NULL) continue; @@ -761,19 +760,12 @@ load_boards(char *key) continue; addnewbrdstat(n, state); } -#ifdef CRITICAL_MEMORY - byMALLOC = 1; -#else - byMALLOC = 0; -#endif - needREALLOC = 1; } if (class_bid == -1) qsort(nbrd, brdnum, sizeof(boardstat_t), cmpboardfriends); } else { - int childcount = bptr->childcount; - nbrd = (boardstat_t *) malloc(childcount * sizeof(boardstat_t)); + nbrd = (boardstat_t *) MALLOC(bptr->childcount * sizeof(boardstat_t)); for (bptr = bptr->firstchild[type]; bptr != (boardheader_t *) ~ 0; bptr = bptr->next[type]) { n = (int)(bptr - bcache); @@ -783,22 +775,15 @@ load_boards(char *key) continue; addnewbrdstat(n, state); } - byMALLOC = 0; - needREALLOC = (childcount != brdnum); - } - - if( needREALLOC ){ - if( byMALLOC ){ - boardstat_t *newnbrd; - newnbrd = (boardstat_t *)malloc(sizeof(boardstat_t) * brdnum); - memcpy(newnbrd, nbrd, sizeof(boardstat_t) * brdnum); - FREE(nbrd); - nbrd = newnbrd; - } - else { - nbrd = (boardstat_t *)realloc(nbrd, sizeof(boardstat_t) * brdnum); - } } +#ifndef CRITICAL_MEMORY + nbrd = realloc(nbrd, sizeof(boardstat_t) * brdnum); +#else + tmpnbrd = (boardstat_t *) malloc(sizeof(boardstat_t) * brdnum); + memcpy(tmpnbrd, nbrd, sizeof(boardstat_t) * brdnum); + FREE(nbrd); + nbrd = tmpnbrd; +#endif } static int -- cgit v1.2.3 From 539a5d2d3dcc15d8d8f936ffcdfdcaab8b242336 Mon Sep 17 00:00:00 2001 From: in2 Date: Tue, 15 Apr 2003 09:31:46 +0000 Subject: revert to 1.123 git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@797 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/board.c | 43 +++++++++++++++++++++++++++++-------------- 1 file changed, 29 insertions(+), 14 deletions(-) diff --git a/pttbbs/mbbsd/board.c b/pttbbs/mbbsd/board.c index ccd208b9..131c9e8e 100644 --- a/pttbbs/mbbsd/board.c +++ b/pttbbs/mbbsd/board.c @@ -1,4 +1,4 @@ -/* $Id: board.c,v 1.124 2003/04/15 06:07:23 in2 Exp $ */ +/* $Id: board.c,v 1.125 2003/04/15 09:31:46 in2 Exp $ */ #include "bbs.h" #define BRC_STRLEN 15 /* Length of board name */ #define BRC_MAXSIZE 24576 @@ -718,9 +718,7 @@ load_boards(char *key) int type = cuser.uflag & BRDSORT_FLAG ? 1 : 0; int i, n; int state; -#ifdef CRITICAL_MEMORY - boardstat_t *tmpnbrd; -#endif + char byMALLOC = 0, needREALLOC = 0; if (class_bid > 0) { bptr = &bcache[class_bid - 1]; @@ -733,8 +731,8 @@ load_boards(char *key) nbrd = NULL; } if (class_bid <= 0) { - nbrd = (boardstat_t *) MALLOC(sizeof(boardstat_t) * numboards); if( yank_flag == 0 ){ // fav mode + nbrd = (boardstat_t *)malloc(sizeof(boardstat_t) * fav->nDatas); for( i = 0 ; i < fav->nDatas ; ++i ){ if( fav->b[i].attr & BRD_FAV ){ if( fav->b[i].attr & BRD_LINE ) @@ -746,8 +744,11 @@ load_boards(char *key) } } } + byMALLOC = 0; + needREALLOC = (fav->nDatas != brdnum); } else{ // general case + nbrd = (boardstat_t *) MALLOC(sizeof(boardstat_t) * numboards); for (i = 0; i < numboards; i++) { if ((bptr = SHM->bsorted[type][i]) == NULL) continue; @@ -760,12 +761,19 @@ load_boards(char *key) continue; addnewbrdstat(n, state); } +#ifdef CRITICAL_MEMORY + byMALLOC = 1; +#else + byMALLOC = 0; +#endif + needREALLOC = 1; } if (class_bid == -1) qsort(nbrd, brdnum, sizeof(boardstat_t), cmpboardfriends); } else { - nbrd = (boardstat_t *) MALLOC(bptr->childcount * sizeof(boardstat_t)); + int childcount = bptr->childcount; + nbrd = (boardstat_t *) malloc(childcount * sizeof(boardstat_t)); for (bptr = bptr->firstchild[type]; bptr != (boardheader_t *) ~ 0; bptr = bptr->next[type]) { n = (int)(bptr - bcache); @@ -775,15 +783,22 @@ load_boards(char *key) continue; addnewbrdstat(n, state); } + byMALLOC = 0; + needREALLOC = (childcount != brdnum); + } + + if( needREALLOC ){ + if( byMALLOC ){ + boardstat_t *newnbrd; + newnbrd = (boardstat_t *)malloc(sizeof(boardstat_t) * brdnum); + memcpy(newnbrd, nbrd, sizeof(boardstat_t) * brdnum); + FREE(nbrd); + nbrd = newnbrd; + } + else { + nbrd = (boardstat_t *)realloc(nbrd, sizeof(boardstat_t) * brdnum); + } } -#ifndef CRITICAL_MEMORY - nbrd = realloc(nbrd, sizeof(boardstat_t) * brdnum); -#else - tmpnbrd = (boardstat_t *) malloc(sizeof(boardstat_t) * brdnum); - memcpy(tmpnbrd, nbrd, sizeof(boardstat_t) * brdnum); - FREE(nbrd); - nbrd = tmpnbrd; -#endif } static int -- cgit v1.2.3 From 97e68df5e2a465e7bf5cab14ff347eac82f6a129 Mon Sep 17 00:00:00 2001 From: victor Date: Tue, 15 Apr 2003 14:28:56 +0000 Subject: forget to commit last time git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@798 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/bbs.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/pttbbs/mbbsd/bbs.c b/pttbbs/mbbsd/bbs.c index 61234a36..6e776f95 100644 --- a/pttbbs/mbbsd/bbs.c +++ b/pttbbs/mbbsd/bbs.c @@ -1,4 +1,4 @@ -/* $Id: bbs.c,v 1.86 2003/04/14 08:54:30 victor Exp $ */ +/* $Id: bbs.c,v 1.87 2003/04/15 14:28:56 victor Exp $ */ #include "bbs.h" static void @@ -1380,9 +1380,6 @@ del_post(int ent, fileheader_t * fhdr, char *direct) int not_owned; boardheader_t *bp; - if( currmode & MODE_SELECT ) - return DONOTHING; - bp = getbcache(currbid); if (strcmp(bp->brdname, "Security") == 0) return DONOTHING; -- cgit v1.2.3 From 85ae8fdf6e1118df1dc9382c00f65013aa06c86b Mon Sep 17 00:00:00 2001 From: victor Date: Wed, 16 Apr 2003 09:25:13 +0000 Subject: may be not closed git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@799 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/friend.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/pttbbs/mbbsd/friend.c b/pttbbs/mbbsd/friend.c index 88cc28f7..9876b396 100644 --- a/pttbbs/mbbsd/friend.c +++ b/pttbbs/mbbsd/friend.c @@ -1,4 +1,4 @@ -/* $Id: friend.c,v 1.15 2003/01/19 16:06:06 kcwu Exp $ */ +/* $Id: friend.c,v 1.16 2003/04/16 09:25:13 victor Exp $ */ #include "bbs.h" /* ------------------------------------- */ @@ -220,10 +220,12 @@ friend_delete(char *uident, int type) while (fgets(genbuf, STRLEN, fp)) if ((genbuf[0] > ' ') && strncmp(genbuf, uident, length)) fputs(genbuf, nfp); - fclose(fp); - fclose(nfp); Rename(fnnew, fn); } + if(fp) + fclose(fp); + if(nfp) + fclose(nfp); } static void -- cgit v1.2.3 From 59f986c6ac5c21b75a2ccf144e40026b762d2ea0 Mon Sep 17 00:00:00 2001 From: in2 Date: Thu, 17 Apr 2003 01:26:58 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@800 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/sample/pttbbs.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pttbbs/sample/pttbbs.sh b/pttbbs/sample/pttbbs.sh index 056aacb8..9e1efc26 100755 --- a/pttbbs/sample/pttbbs.sh +++ b/pttbbs/sample/pttbbs.sh @@ -17,7 +17,7 @@ start) /home/bbs/bin/mbbsd 23 & # 啟動 utmpsortd - /bin/sleep 5; /usr/bin/su -fm bbs -c /home/bbs/bin/shmctl utmpsortd & + /bin/sleep 5; "/usr/bin/su -fm bbs -c /home/bbs/bin/shmctl utmpsortd" & # 提示 echo -n ' mbbsd' -- cgit v1.2.3 From a0da9c0b8d4bf6325ce0e5fde914dad4ab2699f9 Mon Sep 17 00:00:00 2001 From: victor Date: Thu, 17 Apr 2003 14:20:41 +0000 Subject: change key binding git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@801 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/talk.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pttbbs/mbbsd/talk.c b/pttbbs/mbbsd/talk.c index e32db7d3..126d739f 100644 --- a/pttbbs/mbbsd/talk.c +++ b/pttbbs/mbbsd/talk.c @@ -1,4 +1,4 @@ -/* $Id: talk.c,v 1.105 2003/04/06 16:45:13 in2 Exp $ */ +/* $Id: talk.c,v 1.106 2003/04/17 14:20:41 victor Exp $ */ #include "bbs.h" #define QCAST int (*)(const void *, const void *) @@ -1372,7 +1372,7 @@ t_showhelp() outs("\n\n\033[36m【 交談專用鍵 】\033[m\n" "(→)(t)(Enter) 跟他/她聊天\n" "(w) 熱線 Call in\n" - "(W)切換水球方式 一般 / 進階 / 未來\n" + "(^W)切換水球方式 一般 / 進階 / 未來\n" "(b) 對好友廣播 (一定要在好友列表中)\n" "(^R) 即時回應 (有人 Call in 你時)"); } @@ -2272,7 +2272,7 @@ userlist(void) } break; - case 'W': + case Ctrl('W'): if (HAS_PERM(PERM_LOGINOK)) { int tmp; char *wm[3] = {"一般", "進階", "未來"}; -- cgit v1.2.3 From 6f06972bcd8ff5a4933ddf40f2913c9b8e8e59cc Mon Sep 17 00:00:00 2001 From: in2 Date: Sat, 19 Apr 2003 16:46:15 +0000 Subject: for icc 7.1.006 git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@802 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd.icc/Makefile | 32 ++++++++++++-------------------- 1 file changed, 12 insertions(+), 20 deletions(-) diff --git a/pttbbs/mbbsd.icc/Makefile b/pttbbs/mbbsd.icc/Makefile index f40f420b..fb6d6fc0 100644 --- a/pttbbs/mbbsd.icc/Makefile +++ b/pttbbs/mbbsd.icc/Makefile @@ -11,7 +11,10 @@ OBJS= admin.o announce.o args.o bbs.o board.o cache.o cal.o card.o\ voteboard.o syspost.o var.o toolkit.o passwd.o\ calendar.o -CFLAGS= -DHAVE_SETPROCTITLE -DBBSHOME='"$(BBSHOME)"' -DFreeBSD -I../include +ICCFLAGS= -O -march=pentiumiii +GCCFLAGS= -O -march=pentium3 + +CFLAGS= -DHAVE_SETPROCTITLE -DBBSHOME='"$(BBSHOME)"' -DFreeBSD -I../include LDFLAGS= -lutil -lkvm -lcrypt .if defined(GDB) || defined(DEBUG) @@ -36,38 +39,27 @@ GCCUSE=gcc -pipe -Wall $(CFLAGS) -c .SUFFIXES: .c .o .c.o: ../include/var.h - iccbin -D__FreeBSD__ -D__FreeBSD $(CFLAGS) -c ../mbbsd/$*.c + icc -D__FreeBSD__ -D__FreeBSD $(CFLAGS) $(ICCFLAGS) -c ../mbbsd/$*.c all: $(PROG) $(PROG): $(OBJS) - cc $(LDFLAGS) -o $(PROG) $(OBJS) + icc $(LDFLAGS) $(ICCFLAGS) -o $(PROG) $(OBJS) ../include/var.h: var.c perl ../util/parsevar.pl < ../mbbsd/var.c > ../include/var.h +cache.o: cache.c + $(GCCUSE) $(GCCFLAGS) ../mbbsd/$*.c + +topsong.o: topsong.c + $(GCCUSE) $(GCCFLAGS) ../mbbsd/$*.c + install: $(PROG) install -d $(BBSHOME)/bin/ install -c -m 755 $(PROG) $(BBSHOME)/bin/ rm -f $(BBSHOME)/bin/mbbsd ln -sv $(BBSHOME)/bin/$(PROG) $(BBSHOME)/bin/mbbsd -cache.o: cache.c - $(GCCUSE) ../mbbsd/$*.c - -mail.o: mail.c - $(GCCUSE) ../mbbsd/$*.c - -menu.o: menu.c - $(GCCUSE) ../mbbsd/$*.c - -record.o: record.c - $(GCCUSE) ../mbbsd/$*.c - -topsong.o: topsong.c - $(GCCUSE) ../mbbsd/$*.c - -xyz.o: xyz.c - $(GCCUSE) ../mbbsd/$*.c test: $(PROG) killall -9 testmbbsd || true -- cgit v1.2.3 From 2978142804c88a847e4f610b2db84206335eb136 Mon Sep 17 00:00:00 2001 From: in2 Date: Sat, 19 Apr 2003 18:36:10 +0000 Subject: add mail header: Mime-Version, Content-Type, Content-Transfer-Encoding git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@803 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/outmail.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/pttbbs/util/outmail.c b/pttbbs/util/outmail.c index 804638e5..d8efb526 100644 --- a/pttbbs/util/outmail.c +++ b/pttbbs/util/outmail.c @@ -1,4 +1,4 @@ -/* $Id: outmail.c,v 1.4 2002/09/03 07:09:34 in2 Exp $ */ +/* $Id: outmail.c,v 1.5 2003/04/19 18:36:10 in2 Exp $ */ #include #include #include @@ -155,10 +155,18 @@ void doSendBody(int sock, FILE *fp, char *from, char *to, char *subject) { int n; char buf[2048]; - n = snprintf(buf, sizeof(buf), "From: %s\nTo: %s\nSubject: %s\n\n", + n = snprintf(buf, sizeof(buf), + "From: %s\r\n" + "To: %s\r\n" + "Subject: %s\r\n" + "X-Sender: outmail of pttbbs\r\n" + "Mime-Version: 1.0\r\n" + "Content-Type: text/plain; charset=\"big5\"\r\n" + "Content-Transfer-Encoding: 8bit\r\n" + "X-Disclaimer: [" BBSNAME "]對本信內容恕不負責\r\n\r\n", from, to, subject); write(sock, buf, n); - + while(fgets(buf, sizeof(buf), fp)) { if(buf[0] == '.' && buf[1] == '\n') strcpy(buf, "..\n"); -- cgit v1.2.3 From eee64d85889731c982e078415747e39c0a0c7714 Mon Sep 17 00:00:00 2001 From: in2 Date: Sat, 19 Apr 2003 20:33:34 +0000 Subject: ignore *.il git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@804 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd.icc/.cvsignore | 1 + 1 file changed, 1 insertion(+) diff --git a/pttbbs/mbbsd.icc/.cvsignore b/pttbbs/mbbsd.icc/.cvsignore index 0ffc7757..7eaf2809 100644 --- a/pttbbs/mbbsd.icc/.cvsignore +++ b/pttbbs/mbbsd.icc/.cvsignore @@ -1,2 +1,3 @@ *.o mbbsd.icc +*.il -- cgit v1.2.3 From 4bcac867fe7e7aeb967bb1c7897481443821ffa7 Mon Sep 17 00:00:00 2001 From: in2 Date: Sat, 19 Apr 2003 20:33:47 +0000 Subject: add optimization flags git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@805 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd.icc/Makefile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pttbbs/mbbsd.icc/Makefile b/pttbbs/mbbsd.icc/Makefile index fb6d6fc0..bbbe1a7a 100644 --- a/pttbbs/mbbsd.icc/Makefile +++ b/pttbbs/mbbsd.icc/Makefile @@ -11,7 +11,8 @@ OBJS= admin.o announce.o args.o bbs.o board.o cache.o cal.o card.o\ voteboard.o syspost.o var.o toolkit.o passwd.o\ calendar.o -ICCFLAGS= -O -march=pentiumiii +ICCFLAGS= -O -march=pentiumiii -Ob2 -tpp6 -mcpu=pentiumpro -march=pentiumiii \ + -ipo -ipo_obj GCCFLAGS= -O -march=pentium3 CFLAGS= -DHAVE_SETPROCTITLE -DBBSHOME='"$(BBSHOME)"' -DFreeBSD -I../include -- cgit v1.2.3 From af6236b5ebb86393e3b30392b25a4cb705cb0a21 Mon Sep 17 00:00:00 2001 From: in2 Date: Sun, 20 Apr 2003 03:21:07 +0000 Subject: =?UTF-8?q?s/=EF=BF=BDs=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD?= =?UTF-8?q?=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD/=EF=BF=BDs=EF=BF=BDi?= =?UTF-8?q?=EF=BF=BDO=EF=BF=BDe=EF=BF=BD=EF=BF=BD/?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@806 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/bbs.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pttbbs/mbbsd/bbs.c b/pttbbs/mbbsd/bbs.c index 6e776f95..5a84149f 100644 --- a/pttbbs/mbbsd/bbs.c +++ b/pttbbs/mbbsd/bbs.c @@ -1,4 +1,4 @@ -/* $Id: bbs.c,v 1.87 2003/04/15 14:28:56 victor Exp $ */ +/* $Id: bbs.c,v 1.88 2003/04/20 03:21:07 in2 Exp $ */ #include "bbs.h" static void @@ -1872,7 +1872,7 @@ static char *board_help[] = { #endif "(E) 重編文章 (^H) 列出所有的 New Post(s)", "\01板主命令", - "(^G) 舉辦賭盤/停止下注/開獎(W/K/v) 編輯備忘錄/水桶名單/可看見名單", + "(^G) 舉辦賭盤/停止下注/開獎(W/K/v) 編進板畫面/水桶名單/可看見名單", "(M/o) 舉行投票/編私投票名單 (m/c/g) 保留文章/選錄精華/文摘", "(D) 刪除一段範圍的文章 (T/B) 重編文章標題/重編看板標題", "(I) 開放/禁止看版推薦 (t/^D) 標記文章/砍除標記的文章", -- cgit v1.2.3 From e3c5900e9ceaef5367fbd367187de15835ab0798 Mon Sep 17 00:00:00 2001 From: in2 Date: Tue, 22 Apr 2003 09:29:54 +0000 Subject: re-initiate counter git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@807 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/bbsctl.c | 1 + 1 file changed, 1 insertion(+) diff --git a/pttbbs/util/bbsctl.c b/pttbbs/util/bbsctl.c index 998cd98c..8daa89c3 100644 --- a/pttbbs/util/bbsctl.c +++ b/pttbbs/util/bbsctl.c @@ -226,6 +226,7 @@ int permreport(int argc, char **argv) return 1; } for( count = i = 0 ; check[i].perm != 0 ; ++i ){ + count = 0; lseek(fd, 0, SEEK_SET); printf("%s\n", check[i].desc); while( read(fd, &usr, sizeof(usr)) > 0 ){ -- cgit v1.2.3 From 44ad7d6182c2d40eaf9a39f7178b229360b9aea4 Mon Sep 17 00:00:00 2001 From: in2 Date: Thu, 24 Apr 2003 08:49:25 +0000 Subject: fix > 100% busy, sorted output git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@808 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/diskstat.c | 45 +++++++++++++++++++++++++++++++++++---------- 1 file changed, 35 insertions(+), 10 deletions(-) diff --git a/pttbbs/util/diskstat.c b/pttbbs/util/diskstat.c index d6988156..7ffa7a24 100644 --- a/pttbbs/util/diskstat.c +++ b/pttbbs/util/diskstat.c @@ -609,17 +609,30 @@ phdr(int signo) } -int counttimes = -1, busydata[1024]; +int counttimes = -1; +float busydata[1024]; +int sf(const void *a, const void *b) +{ + if( busydata[*(int *)b] > busydata[*(int *)a] ) + return 1; + return -1; +} static void printresult(int p) { - int dn; + int dn, id[1024], i; printf("\n"); if( counttimes > 0 ){ + for( i = 0 ; i < maxshowdevs ; ++i ) + id[i] = i; + qsort(id, maxshowdevs, sizeof(int), sf); + printf("--- diskstat statistics (%d samples)---\n", counttimes); - phdr(0); for (dn = 0; dn < maxshowdevs; dn++) - printf(" %5.1f%%", ((float)busydata[dn] / 10 / counttimes)); + printf(" %s%d: %10f%%\n", + cur.dinfo->devices[ id[dn] ].device_name, + cur.dinfo->devices[ id[dn] ].unit_number, + (float)busydata[ id[dn] ] / counttimes); printf("\n"); } exit(0); @@ -644,7 +657,8 @@ devstats(int perf_select) busy_seconds = compute_etime(cur.busy_time, last.busy_time); for (dn = 0; dn < num_devices; dn++) { - int di, thisbusy; + int di; + float thisbusy; if (((perf_select == 0) && (dev_select[dn].selected == 0)) || (dev_select[dn].selected > maxshowdevs)) @@ -654,9 +668,6 @@ devstats(int perf_select) device_busy = compute_etime(cur.dinfo->devices[di].busy_time, last.dinfo->devices[di].busy_time); - - thisbusy = device_busy*1000/busy_seconds; - busydata[dn] += thisbusy; if (compute_stats(&cur.dinfo->devices[di], &last.dinfo->devices[di], busy_seconds, @@ -664,7 +675,21 @@ devstats(int perf_select) &total_blocks, &kb_per_transfer, &transfers_per_second, &mb_per_second, &blocks_per_second, &ms_per_transaction)!= 0) - errx(1, "%s", devstat_errbuf); + errx(1, "%s", devstat_errbuf); + + if( (device_busy == 0) && (transfers_per_second > 5) ) + /* the device has been 100% busy, fake it because + * as long as the device is 100% busy the busy_time + * field in the devstat struct is not updated */ + device_busy = busy_seconds; + if (device_busy > busy_seconds) + /* this normally happens after one or more periods + * where the device has been 100% busy, correct it */ + device_busy = busy_seconds; + + thisbusy = device_busy*100/busy_seconds; + busydata[dn] += thisbusy; + if (perf_select != 0) { dev_select[dn].bytes = total_bytes; @@ -696,7 +721,7 @@ devstats(int perf_select) ms_per_transaction); } else { if (Bflag) - printf(" %5.1f%%", (float)thisbusy / 10); + printf(" %5.1f%%", thisbusy); else if (Iflag == 0){ printf(" %5.2Lf %3.0Lf %5.2Lf ", kb_per_transfer, -- cgit v1.2.3 From 61b33542c6ecdf9ffcb6f32008df1a48711d110c Mon Sep 17 00:00:00 2001 From: in2 Date: Thu, 24 Apr 2003 16:59:09 +0000 Subject: add flag qacf git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@809 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/diskstat.c | 68 +++++++++++++++++++++++++++++++++++--------------- 1 file changed, 48 insertions(+), 20 deletions(-) diff --git a/pttbbs/util/diskstat.c b/pttbbs/util/diskstat.c index 7ffa7a24..b1c7b100 100644 --- a/pttbbs/util/diskstat.c +++ b/pttbbs/util/diskstat.c @@ -142,7 +142,7 @@ struct statinfo cur, last; int num_devices; struct device_selection *dev_select; int maxshowdevs; -int dflag = 1, Iflag = 0, Cflag = 0, Tflag = 0, oflag = 0, Kflag = 0, Bflag = 1; +int dflag = 1, Iflag = 0, Cflag = 0, Tflag = 0, oflag = 0, Kflag = 0, Bflag = 1, qflag = 0, sflag = 0, aflag = 0, fflag = 1; #define nlread(x, v) \ kvm_read(kd, namelist[x].n_value, &(v), sizeof(v)) @@ -168,6 +168,7 @@ usage(void) "\t [-t type,if,pass] [-w wait] [drives]\n"); } +char firsttime = 1; int main(int argc, char **argv) { @@ -192,7 +193,7 @@ main(int argc, char **argv) matches = NULL; maxshowdevs = 10; - while ((c = getopt(argc, argv, "c:CdhIKM:n:N:ot:Tw:?")) != -1) { + while ((c = getopt(argc, argv, "c:CdhIKM:n:N:ot:Tw:?qsaf:")) != -1) { switch(c) { case 'c': cflag++; @@ -246,6 +247,18 @@ main(int argc, char **argv) if (waittime < 1) errx(1, "wait time is < 1"); break; + case 'q': /* statistics only */ + qflag++; + break; + case 's': /* scsi only */ + sflag++; + break; + case 'a': /* average only */ + aflag++; + break; + case 'f': /* factor output */ + fflag = atoi(optarg); + break; default: usage(); exit(1); @@ -526,13 +539,14 @@ main(int argc, char **argv) devstats(hflag); if ((dflag == 0) || (Cflag > 0)) cpustats(); - printf("\n"); + if( !qflag ) printf("\n"); fflush(stdout); if (count >= 0 && --count <= 0) break; sleep(waittime); + firsttime = 0; } printresult(0); @@ -544,9 +558,7 @@ phdr(int signo) { register int i; int printed; - static char firsttime = 1; if( firsttime ){ - firsttime = 0; for( i = 0 ; i < num_devices ; ++i ){ int di = dev_select[i].position; if( strcmp(cur.dinfo->devices[di].device_name, "ad") != 0 && @@ -557,6 +569,8 @@ phdr(int signo) } } + if( qflag ) + return; if ((dflag == 0) || (Tflag > 0)) (void)printf(" tty"); for (i = 0, printed=0;(i < num_devices) && (printed < maxshowdevs);i++){ @@ -604,7 +618,7 @@ phdr(int signo) } if ((dflag == 0) || (Cflag > 0)) (void)printf(" us ni sy in id\n"); - else + else printf("\n"); } @@ -621,19 +635,32 @@ int sf(const void *a, const void *b) static void printresult(int p) { int dn, id[1024], i; - printf("\n"); if( counttimes > 0 ){ - for( i = 0 ; i < maxshowdevs ; ++i ) - id[i] = i; - qsort(id, maxshowdevs, sizeof(int), sf); - - printf("--- diskstat statistics (%d samples)---\n", counttimes); - for (dn = 0; dn < maxshowdevs; dn++) - printf(" %s%d: %10f%%\n", - cur.dinfo->devices[ id[dn] ].device_name, - cur.dinfo->devices[ id[dn] ].unit_number, - (float)busydata[ id[dn] ] / counttimes); - printf("\n"); + if( aflag ){ + float dat = 0; + int nDrivers = 0; + for( i = 0 ; i < maxshowdevs ; ++i ) + if( !sflag || + strcmp(cur.dinfo->devices[i].device_name, "da") == 0 ){ + dat += busydata[i]; + ++nDrivers; + } + printf("%f\n", dat * fflag / nDrivers / counttimes); + } + else{ + printf("\n"); + for( i = 0 ; i < maxshowdevs ; ++i ) + id[i] = i; + qsort(id, maxshowdevs, sizeof(int), sf); + + printf("--- diskstat statistics (%d samples)---\n", counttimes); + for (dn = 0; dn < maxshowdevs; dn++) + printf(" %s%d: %10f%%\n", + cur.dinfo->devices[ id[dn] ].device_name, + cur.dinfo->devices[ id[dn] ].unit_number, + (float)busydata[ id[dn] ] / counttimes); + printf("\n"); + } } exit(0); } @@ -687,7 +714,7 @@ devstats(int perf_select) * where the device has been 100% busy, correct it */ device_busy = busy_seconds; - thisbusy = device_busy*100/busy_seconds; + thisbusy = (firsttime) ? 0 : device_busy * 100 / busy_seconds; busydata[dn] += thisbusy; @@ -719,7 +746,8 @@ devstats(int perf_select) total_transfers, msdig, ms_per_transaction); - } else { + } else if( !qflag ) { + if (Bflag) printf(" %5.1f%%", thisbusy); else if (Iflag == 0){ -- cgit v1.2.3 From 6a7e38fcae2a2bf3f5a03c861673cb6d953362cb Mon Sep 17 00:00:00 2001 From: in2 Date: Sun, 27 Apr 2003 13:00:16 +0000 Subject: =?UTF-8?q?=EF=BF=BD=EF=BF=BD=EF=BF=BDL=EF=BF=BD=EF=BF=BD=EF=BF=BD?= =?UTF-8?q?=EF=BF=BD=EF=BF=BDo=EF=BF=BD=EF=BF=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@810 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/chicken.c | 15 +++++++++------ pttbbs/mbbsd/gamble.c | 4 ++-- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/pttbbs/mbbsd/chicken.c b/pttbbs/mbbsd/chicken.c index d1938791..2bc1e64c 100644 --- a/pttbbs/mbbsd/chicken.c +++ b/pttbbs/mbbsd/chicken.c @@ -1,4 +1,4 @@ -/* $Id: chicken.c,v 1.10 2003/01/16 12:59:48 kcwu Exp $ */ +/* $Id: chicken.c,v 1.11 2003/04/27 13:00:16 in2 Exp $ */ #include "bbs.h" #define NUM_KINDS 13 /* 有多少種動物 */ @@ -368,7 +368,7 @@ ch_hit() } void -ch_buyitem(int money, char *picture, int *item) +ch_buyitem(int money, char *picture, int *item, int haveticket) { int num = 0; char buf[5]; @@ -381,7 +381,10 @@ ch_buyitem(int money, char *picture, int *item) reload_money(); if (cuser.money > money * num) { *item += num; - vice(money * num, "購買寵物,賭盤項目"); + if( haveticket ) + vice(money * num, "購買寵物,賭盤項目"); + else + demoney(-money * num); show_file(picture, 5, 14, NO_RELOAD); } else { move(b_lines - 1, 0); @@ -768,7 +771,7 @@ select_menu() break; case '7': ch_buyitem(food_price[(int)mychicken->type], CHICKEN_PIC "/food", - &mychicken->food); + &mychicken->food, 1); break; case '8': ch_eatoo(); @@ -778,11 +781,11 @@ select_menu() break; case 'O': case 'o': - ch_buyitem(100, CHICKEN_PIC "/buyoo", &mychicken->oo); + ch_buyitem(100, CHICKEN_PIC "/buyoo", &mychicken->oo, 1); break; case 'M': case 'm': - ch_buyitem(10, CHICKEN_PIC "/buymedicine", &mychicken->medicine); + ch_buyitem(10, CHICKEN_PIC "/buymedicine", &mychicken->medicine, 1); break; case 'N': case 'n': diff --git a/pttbbs/mbbsd/gamble.c b/pttbbs/mbbsd/gamble.c index b1643fb5..b6b0d61c 100644 --- a/pttbbs/mbbsd/gamble.c +++ b/pttbbs/mbbsd/gamble.c @@ -1,4 +1,4 @@ -/* $Id: gamble.c,v 1.32 2003/01/19 16:06:06 kcwu Exp $ */ +/* $Id: gamble.c,v 1.33 2003/04/27 13:00:16 in2 Exp $ */ #include "bbs.h" #ifndef _BBS_UTIL_C_ @@ -162,7 +162,7 @@ ticket(int bid) if (end || ch >= count || ch < 0) continue; n = 0; - ch_buyitem(price, "etc/buyticket", &n); + ch_buyitem(price, "etc/buyticket", &n, 0); if (n > 0) append_ticket_record(path, ch, n, count); } -- cgit v1.2.3 From 6621eaf791c69c05594775b4e0874903c84695c3 Mon Sep 17 00:00:00 2001 From: in2 Date: Mon, 28 Apr 2003 01:02:46 +0000 Subject: =?UTF-8?q?for=20=EF=BF=BD=EF=BF=BD=EF=BF=BDL=EF=BF=BD=EF=BF=BD?= =?UTF-8?q?=EF=BF=BD=EF=BF=BD=EF=BF=BDo=EF=BF=BD=EF=BF=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@811 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/include/proto.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pttbbs/include/proto.h b/pttbbs/include/proto.h index ef5693cc..e4bcf25c 100644 --- a/pttbbs/include/proto.h +++ b/pttbbs/include/proto.h @@ -1,4 +1,4 @@ -/* $Id: proto.h,v 1.38 2003/03/26 10:21:29 in2 Exp $ */ +/* $Id: proto.h,v 1.39 2003/04/28 01:02:46 in2 Exp $ */ #ifndef INCLUDE_PROTO_H #define INCLUDE_PROTO_H @@ -178,7 +178,7 @@ void chc_init_board(board_t board); /* chicken */ int show_file(char *filename, int y, int lines, int mode); -void ch_buyitem(int money, char *picture, int *item); +void ch_buyitem(int money, char *picture, int *item, int haveticket); int chicken_main(); int chickenpk(int fd); void time_diff(chicken_t *thechicken); -- cgit v1.2.3 From 3fab20d1144fe4a9bfa33fe7222b1005c88c5524 Mon Sep 17 00:00:00 2001 From: in2 Date: Mon, 28 Apr 2003 01:19:40 +0000 Subject: =?UTF-8?q?=EF=BF=BDR=EF=BF=BDt=EF=BF=BD=EF=BF=BD=EF=BF=BDH?= =?UTF-8?q?=EF=BF=BDc=3D>=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BDR100?= =?UTF-8?q?=EF=BF=BD=EF=BF=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@812 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/cal.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pttbbs/mbbsd/cal.c b/pttbbs/mbbsd/cal.c index 83e56465..bae8ca71 100644 --- a/pttbbs/mbbsd/cal.c +++ b/pttbbs/mbbsd/cal.c @@ -1,4 +1,4 @@ -/* $Id: cal.c,v 1.25 2003/03/15 15:30:58 in2 Exp $ */ +/* $Id: cal.c,v 1.26 2003/04/28 01:19:40 in2 Exp $ */ #include "bbs.h" /* 防堵 Multi play */ @@ -327,6 +327,8 @@ p_exmail() n = atoi(ans); if (!ans[0] || !n) return 0; + if (n < 0) + n = 100; if (n + cuser.exmailbox > MAX_EXKEEPMAIL) n = MAX_EXKEEPMAIL - cuser.exmailbox; reload_money(); -- cgit v1.2.3 From c53b607bd29a079613005026d5114bf043054d8f Mon Sep 17 00:00:00 2001 From: in2 Date: Mon, 28 Apr 2003 11:02:19 +0000 Subject: =?UTF-8?q?=EF=BF=BDO=EF=BF=BD=EF=BF=BD/=EF=BF=BD=EF=BF=BD?= =?UTF-8?q?=EF=BF=BD=EF=BF=BD=EF=BF=BDW=EF=BF=BD=EF=BF=BD=3D>256?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@813 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/friend.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pttbbs/mbbsd/friend.c b/pttbbs/mbbsd/friend.c index 9876b396..e2616ec3 100644 --- a/pttbbs/mbbsd/friend.c +++ b/pttbbs/mbbsd/friend.c @@ -1,4 +1,4 @@ -/* $Id: friend.c,v 1.16 2003/04/16 09:25:13 victor Exp $ */ +/* $Id: friend.c,v 1.17 2003/04/28 11:02:19 in2 Exp $ */ #include "bbs.h" /* ------------------------------------- */ @@ -16,9 +16,9 @@ static unsigned int friend_max[8] = { MAX_LOGIN_INFO, MAX_POST_INFO, MAX_NAMELIST, + MAX_FRIEND, MAX_NAMELIST, - MAX_NAMELIST, - MAX_NAMELIST + MAX_FRIEND, }; /* 雖然好友跟壞人名單都是 * 2 但是一次最多load到shm只能有128 */ -- cgit v1.2.3 From 32f5c7eea9917cd8d4736afad6710690b5ae3d30 Mon Sep 17 00:00:00 2001 From: victor Date: Tue, 29 Apr 2003 08:48:06 +0000 Subject: recommend while reaging git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@814 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/bbs.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/pttbbs/mbbsd/bbs.c b/pttbbs/mbbsd/bbs.c index 5a84149f..44c0c2ba 100644 --- a/pttbbs/mbbsd/bbs.c +++ b/pttbbs/mbbsd/bbs.c @@ -1,6 +1,8 @@ -/* $Id: bbs.c,v 1.88 2003/04/20 03:21:07 in2 Exp $ */ +/* $Id: bbs.c,v 1.89 2003/04/29 08:48:06 victor Exp $ */ #include "bbs.h" +static int recommend(int ent, fileheader_t * fhdr, char *direct); + static void mail_by_link(char *owner, char *title, char *path) { @@ -975,11 +977,15 @@ read_post(int ent, fileheader_t * fhdr, char *direct) case Ctrl('C'): cal(); return FULLUPDATE; - break; case Ctrl('I'): t_idle(); return FULLUPDATE; + + case 'X': + recommend(ent, fhdr, direct); + return FULLUPDATE; + case 'y': case 'r': case 'R': -- cgit v1.2.3 From a39e551cc4046adcaaf0741184e5efa6640c1fd4 Mon Sep 17 00:00:00 2001 From: in2 Date: Tue, 29 Apr 2003 11:20:19 +0000 Subject: -O2 -Os -fomit-frame-pointer -fstrength-reduce -fthread-jumps -fexpensive-optimizations (save 12kb :P ) git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@815 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/Makefile | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/pttbbs/mbbsd/Makefile b/pttbbs/mbbsd/Makefile index b3256a76..05744bb7 100644 --- a/pttbbs/mbbsd/Makefile +++ b/pttbbs/mbbsd/Makefile @@ -1,4 +1,4 @@ -# $Id: Makefile,v 1.20 2003/03/22 13:57:23 in2 Exp $ +# $Id: Makefile,v 1.21 2003/04/29 11:20:19 in2 Exp $ # 訂義基本初值 BBSHOME?= $(HOME) @@ -35,8 +35,10 @@ PTT_LIBS+= $(LIBS_$(OSTYPE)) CFLAGS= -g $(PTT_CFLAGS) LDFLAGS= -g $(PTT_LDFLAGS) $(PTT_LIBS) .else -CFLAGS+= -Os $(PTT_CFLAGS) -LDFLAGS+= -O $(PTT_LDFLAGS) $(PTT_LIBS) +CFLAGS+= -O2 -Os -fomit-frame-pointer -fstrength-reduce \ + -fthread-jumps -fexpensive-optimizations \ + $(PTT_CFLAGS) +LDFLAGS+= -O2 $(PTT_LDFLAGS) $(PTT_LIBS) .endif # 若有定義 DEBUG, 則在 CFLAGS內定義 DEBUG -- cgit v1.2.3 From d1db5c3a3f9f3215e2d9ba483d1356126fbfbadb Mon Sep 17 00:00:00 2001 From: in2 Date: Thu, 1 May 2003 08:12:17 +0000 Subject: add $(EXT_LIBS) to LDFLAGS git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@816 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pttbbs/mbbsd/Makefile b/pttbbs/mbbsd/Makefile index 05744bb7..088a4262 100644 --- a/pttbbs/mbbsd/Makefile +++ b/pttbbs/mbbsd/Makefile @@ -1,4 +1,4 @@ -# $Id: Makefile,v 1.21 2003/04/29 11:20:19 in2 Exp $ +# $Id: Makefile,v 1.22 2003/05/01 08:12:17 in2 Exp $ # 訂義基本初值 BBSHOME?= $(HOME) @@ -33,7 +33,7 @@ PTT_LIBS+= $(LIBS_$(OSTYPE)) # 若有定義 GDB或 DEBUG, 則加入 -g , 否則用 -O .if defined(GDB) || defined(DEBUG) CFLAGS= -g $(PTT_CFLAGS) -LDFLAGS= -g $(PTT_LDFLAGS) $(PTT_LIBS) +LDFLAGS= -g $(PTT_LDFLAGS) $(PTT_LIBS) $(EXT_LIBS) .else CFLAGS+= -O2 -Os -fomit-frame-pointer -fstrength-reduce \ -fthread-jumps -fexpensive-optimizations \ -- cgit v1.2.3 From 1d6b6850697730fa1156e184fd6c1b9fc7f51f32 Mon Sep 17 00:00:00 2001 From: in2 Date: Thu, 1 May 2003 08:14:37 +0000 Subject: fix git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@817 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/Makefile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pttbbs/mbbsd/Makefile b/pttbbs/mbbsd/Makefile index 088a4262..8a79683f 100644 --- a/pttbbs/mbbsd/Makefile +++ b/pttbbs/mbbsd/Makefile @@ -1,4 +1,4 @@ -# $Id: Makefile,v 1.22 2003/05/01 08:12:17 in2 Exp $ +# $Id: Makefile,v 1.23 2003/05/01 08:14:37 in2 Exp $ # 訂義基本初值 BBSHOME?= $(HOME) @@ -33,12 +33,12 @@ PTT_LIBS+= $(LIBS_$(OSTYPE)) # 若有定義 GDB或 DEBUG, 則加入 -g , 否則用 -O .if defined(GDB) || defined(DEBUG) CFLAGS= -g $(PTT_CFLAGS) -LDFLAGS= -g $(PTT_LDFLAGS) $(PTT_LIBS) $(EXT_LIBS) +LDFLAGS= -g $(PTT_LDFLAGS) $(PTT_LIBS) .else CFLAGS+= -O2 -Os -fomit-frame-pointer -fstrength-reduce \ -fthread-jumps -fexpensive-optimizations \ $(PTT_CFLAGS) -LDFLAGS+= -O2 $(PTT_LDFLAGS) $(PTT_LIBS) +LDFLAGS+= -O2 $(PTT_LDFLAGS) $(PTT_LIBS) $(EXT_LIBS) .endif # 若有定義 DEBUG, 則在 CFLAGS內定義 DEBUG -- cgit v1.2.3 From c87a7a60f38505b19c9b7bc72c8408dc157672d5 Mon Sep 17 00:00:00 2001 From: in2 Date: Thu, 1 May 2003 08:19:23 +0000 Subject: fix git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@818 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/Makefile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pttbbs/mbbsd/Makefile b/pttbbs/mbbsd/Makefile index 8a79683f..a3d17c64 100644 --- a/pttbbs/mbbsd/Makefile +++ b/pttbbs/mbbsd/Makefile @@ -1,4 +1,4 @@ -# $Id: Makefile,v 1.23 2003/05/01 08:14:37 in2 Exp $ +# $Id: Makefile,v 1.24 2003/05/01 08:19:23 in2 Exp $ # 訂義基本初值 BBSHOME?= $(HOME) @@ -38,7 +38,7 @@ LDFLAGS= -g $(PTT_LDFLAGS) $(PTT_LIBS) CFLAGS+= -O2 -Os -fomit-frame-pointer -fstrength-reduce \ -fthread-jumps -fexpensive-optimizations \ $(PTT_CFLAGS) -LDFLAGS+= -O2 $(PTT_LDFLAGS) $(PTT_LIBS) $(EXT_LIBS) +LDFLAGS+= -O2 $(PTT_LDFLAGS) $(PTT_LIBS) .endif # 若有定義 DEBUG, 則在 CFLAGS內定義 DEBUG @@ -68,7 +68,7 @@ OBJS= admin.o announce.o args.o bbs.o board.o cache.o cal.o card.o\ all: $(PROG) $(PROG): $(OBJS) - $(CC) $(LDFLAGS) -o $(PROG) $(OBJS) $(LIBS) + $(CC) $(LDFLAGS) -o $(PROG) $(OBJS) $(LIBS) $(EXT_LIBS) ../include/var.h: var.c perl ../util/parsevar.pl < var.c > ../include/var.h -- cgit v1.2.3 From 126b582e2155d3f100b4fde2a794fad0939d0e1d Mon Sep 17 00:00:00 2001 From: victor Date: Fri, 2 May 2003 13:22:09 +0000 Subject: implement favchange fix Ctrl('D') git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@819 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/board.c | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/pttbbs/mbbsd/board.c b/pttbbs/mbbsd/board.c index 131c9e8e..2dba2da1 100644 --- a/pttbbs/mbbsd/board.c +++ b/pttbbs/mbbsd/board.c @@ -1,4 +1,4 @@ -/* $Id: board.c,v 1.125 2003/04/15 09:31:46 in2 Exp $ */ +/* $Id: board.c,v 1.126 2003/05/02 13:22:09 victor Exp $ */ #include "bbs.h" #define BRC_STRLEN 15 /* Length of board name */ #define BRC_MAXSIZE 24576 @@ -287,6 +287,7 @@ void movefav(int old, int new) int i, src = -1, des = -1; fav_board_t tmp; + favchange = 1; for(i = 0; i < fav->nDatas; i++){ if(nbrd[old].bid == fav->b[i].bid) @@ -332,6 +333,9 @@ void setfav(short bid, char attr, char mode, time_t t) { /* mode: 0: 設成 off, 1: 設成 on, 2: 反相 */ fav_board_t *ptr = getfav(bid); + + favchange = 1; + if( ptr != NULL ){ if( mode == 2 ) ptr->attr ^= attr; @@ -506,11 +510,10 @@ save_brdbuf(void) char fname[80]; if( !fav ) return; - /* - favchange is not implement yet - if( !favchange ) - return; - */ + + if( !favchange ) + return; + #ifdef MEM_CHECK if( fav->memcheck != MEM_CHECK ) return; @@ -527,7 +530,7 @@ save_brdbuf(void) } fav->nDatas = w; setuserfile(fname, FAV3); - if( (fd = open(fname, O_WRONLY | O_CREAT, 0600)) != -1 ){ + if( (fd = open(fname, O_WRONLY | O_CREAT | O_TRUNC, 0600)) != -1 ){ int i; write(fd, &fav->nDatas, sizeof(short)); write(fd, &fav->nLines, sizeof(char)); @@ -1136,7 +1139,6 @@ choose_board(int newflag) break; case 't': ptr = &nbrd[num]; - favchange = 1; setfav(ptr->bid, BRD_TAG, 2, 0); ptr->myattr ^= BRD_TAG; head = 9999; @@ -1197,6 +1199,7 @@ choose_board(int newflag) } else cuser.uflag ^= BRDSORT_FLAG; + favchange = 1; brdnum = -1; break; case 'y': @@ -1209,7 +1212,6 @@ choose_board(int newflag) favchange = 1; fav->b[tmp].attr &= ~BRD_FAV; fav->b[tmp].attr &= ~BRD_TAG; - fav->nDatas--; } } brdnum = -1; @@ -1264,7 +1266,6 @@ choose_board(int newflag) setfav(0, BRD_FAV | BRD_LINE, 1, 0); nbrd[brdnum].bid = fav->nLines; movefav(brdnum, num); - favchange = 1; brdnum = -1; head = 9999; } @@ -1283,14 +1284,12 @@ choose_board(int newflag) setfav(nbrd[num].bid, BRD_FAV, 2, 0); nbrd[num].myattr ^= BRD_FAV; } - favchange = 1; head = 9999; } break; case 'M': if (HAS_PERM(PERM_BASIC)) { imovefav(num); - favchange = 1; head = 9999; } break; @@ -1378,11 +1377,9 @@ choose_board(int newflag) brc_initial(B_BH(ptr)->brdname); if (ch == 'v') { ptr->myattr &= ~BRD_UNREAD; - favchange = 1; brc_list[0] = now; setfav(ptr->bid, 0, 0, now); } else { - favchange = 1; brc_list[0] = 1; setfav(ptr->bid, 0, 0, 1); ptr->myattr |= BRD_UNREAD; -- cgit v1.2.3 From 56024c90ccb11792b3d0fea986af7fb9fb88fb0d Mon Sep 17 00:00:00 2001 From: victor Date: Sat, 3 May 2003 02:48:57 +0000 Subject: limit nLines git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@820 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/board.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pttbbs/mbbsd/board.c b/pttbbs/mbbsd/board.c index 2dba2da1..af285004 100644 --- a/pttbbs/mbbsd/board.c +++ b/pttbbs/mbbsd/board.c @@ -1,4 +1,4 @@ -/* $Id: board.c,v 1.126 2003/05/02 13:22:09 victor Exp $ */ +/* $Id: board.c,v 1.127 2003/05/03 02:48:57 victor Exp $ */ #include "bbs.h" #define BRC_STRLEN 15 /* Length of board name */ #define BRC_MAXSIZE 24576 @@ -1259,7 +1259,7 @@ choose_board(int newflag) break; case 'L': if (HAS_PERM(PERM_BASIC)) { - if(fav->nDatas > FAVMAX){ + if(fav->nDatas > FAVMAX || fav->nLines <= -127){ vmsg("你的最愛太多了啦 真花心"); break; } -- cgit v1.2.3 From 448e079102f385b9205e29859b9850c80c2770aa Mon Sep 17 00:00:00 2001 From: in2 Date: Mon, 5 May 2003 05:30:02 +0000 Subject: replace varvars.h by stdarg.h (because gcc 3.3 no longer support varvars.h) git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@821 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/innbbsd/Makefile | 7 ++++--- pttbbs/innbbsd/bbslib.c | 30 +++++++++++++++--------------- pttbbs/innbbsd/bbslib.h | 2 +- pttbbs/innbbsd/bbslink.c | 11 ++++------- pttbbs/innbbsd/bbslink2.c | 1 - pttbbs/innbbsd/echobbslib.c | 30 +++++++++++++++--------------- pttbbs/innbbsd/file.c | 34 ++++++++++++++++------------------ pttbbs/innbbsd/inntobbs.c | 4 +--- 8 files changed, 56 insertions(+), 63 deletions(-) diff --git a/pttbbs/innbbsd/Makefile b/pttbbs/innbbsd/Makefile index 38e9a2db..8fd415ad 100644 --- a/pttbbs/innbbsd/Makefile +++ b/pttbbs/innbbsd/Makefile @@ -5,13 +5,14 @@ # create : 95/03/29 # # update : 95/12/15 # # ------------------------------------------------------- # +# stdarg.h patch for pttbbs by in2 03/05/05 # #################################################### # this is a bbs <--> news gateway ##################################################### -VERSION=0.50beta-4 -LASTVERSION=0.50beta-3 -ADMINUSER= root@your.domain.name +VERSION=0.51 +LASTVERSION=0.50beta-4 +ADMINUSER?= root@your.domain.name BBSHOME?=$(HOME) BBS_SRC = .. TARGET = $(INNBBSD) $(BBSNNRP) $(BBSLINK) diff --git a/pttbbs/innbbsd/bbslib.c b/pttbbs/innbbsd/bbslib.c index 0dc808c3..c0177e87 100644 --- a/pttbbs/innbbsd/bbslib.c +++ b/pttbbs/innbbsd/bbslib.c @@ -1,9 +1,9 @@ #if defined( LINUX ) # include "innbbsconf.h" # include "bbslib.h" -# include +# include #else -# include +# include # include "innbbsconf.h" # include "bbslib.h" #endif @@ -76,17 +76,15 @@ setverboseoff() } } -verboselog(va_alist) -va_dcl +verboselog(char *fmt, ...) { va_list ap; - register char* fmt; char datebuf[40]; time_t now; if (verboseFlag == 0) return; - va_start(ap); + va_start(ap, fmt); time(&now); strftime(datebuf, sizeof(datebuf), "%b %d %X ", localtime(&now)); @@ -97,8 +95,10 @@ va_dcl else bbslogfp = fdopen(1, "a"); } - if (bbslogfp == NULL) { va_end(ap); return; } - fmt = va_arg(ap, char *) ; + if (bbslogfp == NULL) { + va_end(ap); + return; + } fprintf(bbslogfp,"%s[%d] ",datebuf, getpid()); vfprintf(bbslogfp, fmt, ap); fflush(bbslogfp); @@ -106,18 +106,16 @@ va_dcl } #ifdef PalmBBS -xbbslog(va_alist) +xbbslog(char *fmt, ...) #else -bbslog(va_alist) +bbslog(char *fmt, ...) #endif -va_dcl { va_list ap; - register char* fmt; char datebuf[40]; time_t now; - va_start(ap); + va_start(ap, fmt); time(&now); strftime(datebuf, sizeof(datebuf), "%b %d %X ", localtime(&now)); @@ -125,8 +123,10 @@ va_dcl if (bbslogfp == NULL) { bbslogfp = fopen(LOGFILE, "a"); } - if (bbslogfp == NULL) { va_end(ap); return; } - fmt = va_arg(ap, char *) ; + if (bbslogfp == NULL) { + va_end(ap); + return; + } fprintf(bbslogfp,"%s[%d] ",datebuf,getpid()); vfprintf(bbslogfp, fmt, ap); fflush(bbslogfp); diff --git a/pttbbs/innbbsd/bbslib.h b/pttbbs/innbbsd/bbslib.h index 190672b7..a03a1d67 100644 --- a/pttbbs/innbbsd/bbslib.h +++ b/pttbbs/innbbsd/bbslib.h @@ -51,7 +51,7 @@ int initial_bbs ARG((char* )); char *restrdup ARG((char *, char *)); nodelist_t *search_nodelist ARG((char *, char *)); newsfeeds_t *search_group ARG((char *)); -int bbslog ARG(()); +int bbslog(char *fmt, ...); void *mymalloc ARG((int)); void *myrealloc ARG((void *, int)); diff --git a/pttbbs/innbbsd/bbslink.c b/pttbbs/innbbsd/bbslink.c index 300f3f7d..1c0b1565 100644 --- a/pttbbs/innbbsd/bbslink.c +++ b/pttbbs/innbbsd/bbslink.c @@ -1,9 +1,9 @@ #if defined( LINUX ) # include "innbbsconf.h" # include "bbslib.h" -# include +# include #else -# include +# include # include "innbbsconf.h" # include "bbslib.h" #endif @@ -248,15 +248,12 @@ bbslink_get_lock(file) int -tcpcommand(va_alist) -va_dcl +tcpcommand(char *fmt, ...) { va_list ap; - register char *fmt; char *ptr; - va_start(ap); - fmt = va_arg(ap, char *); + va_start(ap, fmt); vfprintf(NNTPwfp, fmt, ap); fprintf(NNTPwfp, "\r\n"); fflush(NNTPwfp); diff --git a/pttbbs/innbbsd/bbslink2.c b/pttbbs/innbbsd/bbslink2.c index 70d39766..7a6834b3 100644 --- a/pttbbs/innbbsd/bbslink2.c +++ b/pttbbs/innbbsd/bbslink2.c @@ -223,7 +223,6 @@ va_dcl char *ptr; va_start(ap); - fmt = va_arg(ap, char *); vfprintf(NNTPwfp, fmt, ap); fprintf(NNTPwfp, "\r\n"); fflush(NNTPwfp); diff --git a/pttbbs/innbbsd/echobbslib.c b/pttbbs/innbbsd/echobbslib.c index 84d77de6..2511b50a 100644 --- a/pttbbs/innbbsd/echobbslib.c +++ b/pttbbs/innbbsd/echobbslib.c @@ -1,9 +1,9 @@ #if defined( LINUX ) # include "innbbsconf.h" # include "bbslib.h" -# include +# include #else -# include +# include # include "innbbsconf.h" # include "bbslib.h" #endif @@ -76,17 +76,15 @@ setverboseoff() } } -verboselog(va_alist) -va_dcl +verboselog(char *fmt, ...) { va_list ap; - register char* fmt; char datebuf[40]; time_t now; if (verboseFlag == 0) return; - va_start(ap); + va_start(ap, fmt); time(&now); strftime(datebuf, sizeof(datebuf), "%b %d %X ", localtime(&now)); @@ -97,8 +95,10 @@ va_dcl else bbslogfp = fdopen(1, "a"); } - if (bbslogfp == NULL) { va_end(ap); return; } - fmt = va_arg(ap, char *) ; + if (bbslogfp == NULL) { + va_end(ap); + return; + } fprintf(bbslogfp,"%s[%d] ",datebuf, getpid()); vfprintf(bbslogfp, fmt, ap); fflush(bbslogfp); @@ -106,18 +106,16 @@ va_dcl } #ifdef PalmBBS -xbbslog(va_alist) +xbbslog(char *fmt, ...) #else -bbslog(va_alist) +bbslog(char *fmt, ...) #endif -va_dcl { va_list ap; - register char* fmt; char datebuf[40]; time_t now; - va_start(ap); + va_start(ap, fmt); time(&now); strftime(datebuf, sizeof(datebuf), "%b %d %X ", localtime(&now)); @@ -125,8 +123,10 @@ va_dcl if (bbslogfp == NULL) { bbslogfp = fopen(LOGFILE, "a"); } - if (bbslogfp == NULL) { va_end(ap); return; } - fmt = va_arg(ap, char *) ; + if (bbslogfp == NULL) { + va_end(ap); + return; + } fprintf(bbslogfp,"%s[%d] ",datebuf,getpid()); vfprintf(bbslogfp, fmt, ap); fflush(bbslogfp); diff --git a/pttbbs/innbbsd/file.c b/pttbbs/innbbsd/file.c index d4df15b2..7016f940 100644 --- a/pttbbs/innbbsd/file.c +++ b/pttbbs/innbbsd/file.c @@ -1,7 +1,7 @@ #include #include #include -#include +#include #define MAXARGS 100 /* isfile is called by @@ -25,20 +25,14 @@ FILE *fp; fileglue("%s/%s",home,".newsrc"); */ -char *fileglue(va_alist) -va_dcl +char *fileglue(char *fmt, ...) { - va_list ap; - register char* fmt; - static char *newstring; - static char gluebuffer[8192]; - - va_start(ap); - fmt = va_arg(ap, char *) ; - vsprintf(gluebuffer, fmt, ap); - newstring = gluebuffer; - va_end(ap); - return newstring; + va_list ap; + static char gluebuffer[8192]; + va_start(ap, fmt); + vsprintf(gluebuffer, fmt, ap); + va_end(ap); + return gluebuffer; } long @@ -71,8 +65,8 @@ char* filename; return 1; } +#ifdef TEST int isfilev(va_alist) -va_dcl { va_list ap; struct stat st; @@ -88,6 +82,7 @@ va_dcl va_end(ap); return isfile(FILEBUF); } +#endif int isdir(filename) @@ -100,8 +95,8 @@ char* filename; return 1; } +#ifdef TEST int isdirv(va_alist) -va_dcl { va_list ap; struct stat st; @@ -116,6 +111,7 @@ va_dcl va_end(ap); return isdir(FILEBUF); } +#endif unsigned long mtime(filename) char* filename; @@ -125,8 +121,8 @@ char* filename; return st.st_mtime; } +#ifdef TEST unsigned long mtimev(va_alist) -va_dcl { va_list ap; struct stat st; @@ -141,6 +137,7 @@ va_dcl va_end(ap); return mtime(FILEBUF); } +#endif unsigned long atime(filename) char *filename; @@ -150,8 +147,8 @@ char *filename; return st.st_atime; } +#ifdef TEST unsigned long atimev(va_alist) -va_dcl { va_list ap; struct stat st; @@ -166,6 +163,7 @@ va_dcl va_end(ap); return atime(FILEBUF); } +#endif /*#undef TEST*/ #ifdef TEST diff --git a/pttbbs/innbbsd/inntobbs.c b/pttbbs/innbbsd/inntobbs.c index b57d8bb1..653ea488 100644 --- a/pttbbs/innbbsd/inntobbs.c +++ b/pttbbs/innbbsd/inntobbs.c @@ -18,9 +18,7 @@ ORGANIZATION_H, LASTHEADER, }; */ -char *strchr ARG((char*,int)); -char *strrchr ARG((char*,int)); -char *strstr ARG((char*,char*)); +#include header_t headertable[] = { "Subject" ,SUBJECT_H, -- cgit v1.2.3 From 5f49b1b39de5dfb342fb35bf0b31003ef88928b4 Mon Sep 17 00:00:00 2001 From: victor Date: Tue, 6 May 2003 16:54:42 +0000 Subject: change source git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@822 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/weather.perl | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/pttbbs/util/weather.perl b/pttbbs/util/weather.perl index 2cfd9e13..5edc147a 100644 --- a/pttbbs/util/weather.perl +++ b/pttbbs/util/weather.perl @@ -1,5 +1,5 @@ #!/usr/bin/perl -# $Id: weather.perl,v 1.7 2003/04/02 09:19:46 victor Exp $ +# $Id: weather.perl,v 1.8 2003/05/06 16:54:42 victor Exp $ # # 不能跑的話,看看 bbspost 的路徑是否正確。 # 如果發出的 post 沒有氣象報告而是說 URL 找不到,則確定一下能不能看到 @@ -20,14 +20,9 @@ close DATE; # Header # 內容 #open(WEATHER, "$LYNX -assume_charset=big5 -assume_local_charset=big5 -dump http://www.cwb.gov.tw/V3.0/weather/text/W03.htm |"); -open(WEATHER, "$LYNX -assume_charset=big5 -assume_local_charset=big5 -dump -nolist http://www.gigigaga.com/home/weather.asp|"); +open(WEATHER, "$LYNX -assume_charset=big5 -assume_local_charset=big5 -dump -nolist ftp://ftpsv.cwb.gov.tw/pub/forecast/W002.txt|"); while () { - last if /首頁/; -} - -while () { - last if /dot\.gif/; print BBSPOST if ($_ ne "\n"); } close WEATHER; -- cgit v1.2.3 From ef5d42566f789af3de7dd13567b06210afe74ea7 Mon Sep 17 00:00:00 2001 From: bbs Date: Wed, 7 May 2003 03:35:07 +0000 Subject: OUTTA_TIMER git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@823 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/include/pttstruct.h | 5 ++++- pttbbs/mbbsd/io.c | 6 +++++- pttbbs/sample/pttbbs.conf | 4 ++++ pttbbs/util/shmctl.c | 5 ++++- 4 files changed, 17 insertions(+), 3 deletions(-) diff --git a/pttbbs/include/pttstruct.h b/pttbbs/include/pttstruct.h index 0d60a7a5..cb60f97d 100644 --- a/pttbbs/include/pttstruct.h +++ b/pttbbs/include/pttstruct.h @@ -1,4 +1,4 @@ -/* $Id: pttstruct.h,v 1.34 2003/04/08 09:53:21 in2 Exp $ */ +/* $Id: pttstruct.h,v 1.35 2003/05/07 03:35:07 bbs Exp $ */ #ifndef INCLUDE_STRUCT_H #define INCLUDE_STRUCT_H @@ -356,6 +356,9 @@ typedef struct { int dymaxactive; /* 動態設定最大人數上限 */ int toomanyusers; /* 超過人數上限不給進的個數 */ int noonlineuser; /* 站上使用者不高亮度顯示 */ +#ifdef OUTTA_TIMER + time_t now; +#endif } e; } GV2; char gap3_2[128]; diff --git a/pttbbs/mbbsd/io.c b/pttbbs/mbbsd/io.c index 3e8f79a7..3b15bbe7 100644 --- a/pttbbs/mbbsd/io.c +++ b/pttbbs/mbbsd/io.c @@ -1,4 +1,4 @@ -/* $Id: io.c,v 1.28 2003/03/15 15:30:58 in2 Exp $ */ +/* $Id: io.c,v 1.29 2003/05/07 03:35:07 bbs Exp $ */ #include "bbs.h" #if defined(linux) @@ -139,7 +139,11 @@ dogetch() icurrchar = 0; } if (currutmp) { +#ifdef OUTTA_TIMER + now = SHM->GV2.e.now; +#else now = time(0); +#endif if (now - lastact < 3) currutmp->lastact = now; lastact = now; diff --git a/pttbbs/sample/pttbbs.conf b/pttbbs/sample/pttbbs.conf index 1903a6af..e222a34d 100644 --- a/pttbbs/sample/pttbbs.conf +++ b/pttbbs/sample/pttbbs.conf @@ -78,6 +78,10 @@ 仍可有好的上站率 */ //#define PRE_FORK 10 +/* 若定義, 則由 shmctl utmpsortd 將 time(NULL) 寫入 SHM->GV2.e.now, + 則不須每個 mbbsd都自己透過 time(NULL) 取得時間, 導致大量的 system call */ +//#define OUTTA_TIMER + /* 前進站畫面 */ #define INSCREEN \ "前進站畫面 (請至 pttbbs.conf 修改您的前進站畫面)" diff --git a/pttbbs/util/shmctl.c b/pttbbs/util/shmctl.c index 04f5b112..ac9cb15b 100644 --- a/pttbbs/util/shmctl.c +++ b/pttbbs/util/shmctl.c @@ -1,4 +1,4 @@ -/* $Id: shmctl.c,v 1.39 2003/04/10 18:05:45 in2 Exp $ */ +/* $Id: shmctl.c,v 1.40 2003/05/07 03:35:07 bbs Exp $ */ #include "bbs.h" #include @@ -275,6 +275,9 @@ int utmpsortd(int argc, char **argv) else{ while( 1 ){ int i; +#ifdef OUTTA_TIMER + SHM->GV2.e.now = time(NULL); +#endif for( i = 0 ; SHM->UTMPbusystate && i < 5 ; ++i ) usleep(300000); -- cgit v1.2.3 From 864ec40de97447d03cea3480004033a850162ecb Mon Sep 17 00:00:00 2001 From: bbs Date: Wed, 7 May 2003 08:14:21 +0000 Subject: do not permit subop to del brd git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@824 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/admin.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/pttbbs/mbbsd/admin.c b/pttbbs/mbbsd/admin.c index b1d48245..dc792e47 100644 --- a/pttbbs/mbbsd/admin.c +++ b/pttbbs/mbbsd/admin.c @@ -1,4 +1,4 @@ -/* $Id: admin.c,v 1.31 2003/01/19 16:06:05 kcwu Exp $ */ +/* $Id: admin.c,v 1.32 2003/05/07 08:14:21 bbs Exp $ */ #include "bbs.h" /* 使用者管理 */ @@ -223,9 +223,9 @@ m_mod_board(char *bname) /* Ptt 這邊斷行會檔到下面 */ move(9, 0); - snprintf(genbuf, sizeof(genbuf), "(E)設定 (V)違法/解除 %s (D)刪除 [Q]取消?", - HAS_PERM(PERM_SYSOP) ? - " (B)BVote (S)救回文章 (G)賭盤解卡" : ""); + snprintf(genbuf, sizeof(genbuf), "(E)設定 (V)違法/解除%s%s [Q]取消?", + HAS_PERM(PERM_SYSOP) ? " (B)BVote (S)救回文章 (G)賭盤解卡" : "", + HAS_PERM(PERM_SYSSUBOP) ? " (D)刪除" : ""); getdata(10, 0, genbuf, ans, sizeof(ans), LCECHO); switch (*ans) { @@ -277,6 +277,8 @@ m_mod_board(char *bname) } break; case 'd': + if (HAS_PERM(PERM_SYSSUBOP) && !HAS_PERM(PERM_SYSOP)) + break; getdata_str(9, 0, msg_sure_ny, genbuf, 3, LCECHO, "N"); if (genbuf[0] != 'y' || !bname[0]) outs(MSG_DEL_CANCEL); -- cgit v1.2.3 From 8b8a7d2805b53e3d1149f274497f7d780c20da67 Mon Sep 17 00:00:00 2001 From: victor Date: Wed, 7 May 2003 08:16:30 +0000 Subject: don't show gamble msg if not define it git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@825 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/bbs.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/pttbbs/mbbsd/bbs.c b/pttbbs/mbbsd/bbs.c index 44c0c2ba..bc1cdcb3 100644 --- a/pttbbs/mbbsd/bbs.c +++ b/pttbbs/mbbsd/bbs.c @@ -1,4 +1,4 @@ -/* $Id: bbs.c,v 1.89 2003/04/29 08:48:06 victor Exp $ */ +/* $Id: bbs.c,v 1.90 2003/05/07 08:16:30 victor Exp $ */ #include "bbs.h" static int recommend(int ent, fileheader_t * fhdr, char *direct); @@ -1878,11 +1878,15 @@ static char *board_help[] = { #endif "(E) 重編文章 (^H) 列出所有的 New Post(s)", "\01板主命令", - "(^G) 舉辦賭盤/停止下注/開獎(W/K/v) 編進板畫面/水桶名單/可看見名單", "(M/o) 舉行投票/編私投票名單 (m/c/g) 保留文章/選錄精華/文摘", "(D) 刪除一段範圍的文章 (T/B) 重編文章標題/重編看板標題", "(I) 開放/禁止看版推薦 (t/^D) 標記文章/砍除標記的文章", "(O) 編輯Post注意事項 (H)/(Y) 看板隱藏/現身 取消推薦文章", +#ifdef NO_GAMBLE + "(W/K/v) 編進板畫面/水桶名單/可看見名單", +#else + "(^G) 舉辦賭盤/停止下注/開獎(W/K/v) 編進板畫面/水桶名單/可看見名單", +#endif NULL }; -- cgit v1.2.3 From 151e9ac62458286eff0f124c80081d4c093ee7f1 Mon Sep 17 00:00:00 2001 From: victor Date: Wed, 7 May 2003 08:45:51 +0000 Subject: rfc2047 (but just decode @@) git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@826 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/innbbsd/Makefile | 6 +- pttbbs/innbbsd/receive_article.c | 7 +- pttbbs/innbbsd/str_decode.c | 281 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 290 insertions(+), 4 deletions(-) create mode 100644 pttbbs/innbbsd/str_decode.c diff --git a/pttbbs/innbbsd/Makefile b/pttbbs/innbbsd/Makefile index 8fd415ad..92214f93 100644 --- a/pttbbs/innbbsd/Makefile +++ b/pttbbs/innbbsd/Makefile @@ -31,21 +31,23 @@ BBS_REC = $(BBS_UTIL)/util_record.o $(BBS_UTIL)/util_cache.o $(BBS_UTIL)/util_pa ############### DEBUGOBJ = /usr/lib/debug/mallocmap.o CFLAGS+= -c -I. -I$(BBS_SRC)/include -I$(BBS_SRC)/mbbsd -D$(BBS_DEP) \ +-I/usr/local/include -L/usr/local/lib \ $(EXTRAFLAGS) -DDBZDEBUG -DBBSHOME='"$(BBSHOME)"' \ -D_PATH_BBSHOME=\"$(BBSHOME)\" \ -DVERSION=\"$(VERSION)\" -DADMINUSER=\"$(ADMINUSER)\" +LDFLAGS+= -liconv # #################################################### OBJS = inndchannel.o innbbsd.o connectsock.o rfc931.o \ daemon.o file.o pmain.o his.o dbz.o \ closeonexec.o dbztool.o inntobbs.o receive_article.o \ - echobbslib.o $(BBS_REC) + echobbslib.o str_decode.o $(BBS_REC) # $(BBS_REC) SRCS = inndchannel.c innbbsd.c connectsock.c rfc931.c \ daemon.c file.c pmain.c parsdate.y his.c dbz.c \ closeonexec.c dbztool.c inntobbs.c bbslib.c receive_article.c \ - port.c + port.c str_decode.c MOBJS = makedbz.o bbslib.o file.o dbz.o closeonexec.o HOBJS = mkhistory.o bbslib.o file.o his.o dbz.o port.o closeonexec.o diff --git a/pttbbs/innbbsd/receive_article.c b/pttbbs/innbbsd/receive_article.c index 0c2827da..6b1e59c7 100644 --- a/pttbbs/innbbsd/receive_article.c +++ b/pttbbs/innbbsd/receive_article.c @@ -545,6 +545,7 @@ receive_control() *firstpath = '\0'; if (isdir(boardhome)) { + strcpy(SUBJECT, str_decode_M3(SUBJECT)); fname = (char *) post_article(boardhome, FROM, "control", bbspost_write_control, NULL, firstpath); if (fname != NULL) { @@ -678,8 +679,10 @@ cancel_article_front(msgid) if (body2 != NULL) *body = '\n'; } - if (*subject) - SUBJECT = subject; + if (*subject){ + strcpy(subject, str_decode_M3(subject)); + SUBJECT = subject; + } fname = (char *) post_article(boardhome, FROM, "deleted", bbspost_write_cancel, filename, firstpath); if (fname != NULL) { diff --git a/pttbbs/innbbsd/str_decode.c b/pttbbs/innbbsd/str_decode.c new file mode 100644 index 00000000..23a10551 --- /dev/null +++ b/pttbbs/innbbsd/str_decode.c @@ -0,0 +1,281 @@ +/* 使用方法大致如下: innbbsd 中 + 在 SUBJECT 從 news 讀進來後, 呼叫 str_decode_M3(SUBJECT) 就行了 */ + +/* bsd 底下使用要編譯時要加 -I/usr/local/include -L/usr/local/lib -liconv + 並安裝 libiconv, + 若真的沒有iconv就把底下的 #define USE_ICONV 1 刪了 */ + +/*-------------------------------------------------------*/ +/* lib/str_decode.c ( NTHU CS MapleBBS Ver 3.00 ) */ +/*-------------------------------------------------------*/ +/* target : included C for QP/BASE64 decoding */ +/* create : 95/03/29 */ +/* update : 97/03/29 */ +/*-------------------------------------------------------*/ + + +/* ----------------------------------------------------- */ +/* QP code : "0123456789ABCDEF" */ +/* ----------------------------------------------------- */ + +#include +#include +#include + +#define USE_ICONV 1 +/* bsd 底下使用要編譯時要加 -I/usr/local/include -L/usr/local/lib -liconv + 若真的沒有iconv就把上面這行 #define 刪了 */ + +#ifdef USE_ICONV +#include +#endif + +static int qp_code(int x) +{ + if (x >= '0' && x <= '9') + return x - '0'; + if (x >= 'a' && x <= 'f') + return x - 'a' + 10; + if (x >= 'A' && x <= 'F') + return x - 'A' + 10; + return -1; +} + + +/* ------------------------------------------------------------------ */ +/* BASE64 : */ +/* "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/" */ +/* ------------------------------------------------------------------ */ + + +static int base64_code(int x) +{ + if (x >= 'A' && x <= 'Z') + return x - 'A'; + if (x >= 'a' && x <= 'z') + return x - 'a' + 26; + if (x >= '0' && x <= '9') + return x - '0' + 52; + if (x == '+') + return 62; + if (x == '/') + return 63; + return -1; +} + + +/* ----------------------------------------------------- */ +/* judge & decode QP / BASE64 */ +/* ----------------------------------------------------- */ + +static inline int isreturn(unsigned char c) +{ + return c == '\r' || c == '\n'; +} + +static inline int isspace(unsigned char c) +{ + return c == ' ' || c == '\t' || isreturn(c); +} + +/* static inline */ +int mmdecode(unsigned char *src, unsigned char encode, unsigned char *dst) +{ + /* Thor.980901: src和dst可相同, 但src 一定有?或\0結束 */ + /* Thor.980901: 注意, decode出的結果不會自己加上 \0 */ + unsigned char *t = dst; + int pattern = 0, bits = 0; + encode |= 0x20; /* Thor: to lower */ + switch(encode) + { + case 'q': /* Thor: quoted-printable */ + while(*src && *src != '?') /* Thor: delimiter */ + { /* Thor.980901: 0 算是 delimiter */ + if(*src == '=') + { + int x = *++src, y = x ? *++src : 0; + if(isreturn(x)) continue; + if( (x = qp_code(x)) < 0 || ( y = qp_code(y)) < 0) return -1; + *t++ = (x << 4) + y , src++; + } + else if(*src == '_') + *t++ = ' ', src++; +#if 0 + else if(!*src) /* Thor: no delimiter is not successful */ + return -1; +#endif + else /* Thor: *src != '=' '_' */ + *t++ = *src++; + } + return t - dst; + case 'b': /* Thor: base 64 */ + while(*src && *src != '?') /* Thor: delimiter */ /* Thor.980901: 0也算 */ + { /* Thor: pattern & bits are cleared outside */ + int x; +#if 0 + if (!*src) return -1; /* Thor: no delimiter is not successful */ +#endif + x = base64_code(*src++); + if(x < 0) continue; /* Thor: ignore everything not in the base64,=,.. */ + pattern = (pattern << 6) | x; + bits += 6; /* Thor: 1 code gains 6 bits */ + if(bits >= 8) /* Thor: enough to form a byte */ + { + bits -= 8; + *t++ = (pattern >> bits) & 0xff; + } + } + return t - dst; + } + return -1; +} + +#ifdef USE_ICONV +int str_iconv( + const char *fromcode, /* charset of source string*/ + const char *tocode, /* charset of destination string */ + char *src, /* source string */ + int srclen, /* source string length */ + char *dst, /* destination string */ + int dstlen) /* destination string length */ +/* 這個函式會將一個字串 (src) 從 charset=fromcode 轉成 charset=tocode, + srclen 是 src 的長度, dst 是輸出的buffer, dstlen 則指定了 + dst 的大小, 最後會補 '\0', 所以要留一個byte給'\0'. + 如果遇到 src 中有非字集的字, 或是 src 中有未完整的 byte, + 都會砍掉. + */ +{ + iconv_t iconv_descriptor; + int iconv_ret,dstlen_old; + + dstlen--; /* keep space for '\0' */ + + dstlen_old = dstlen; + + /* Open a descriptor for iconv */ + iconv_descriptor = iconv_open(tocode, fromcode); + + if (iconv_descriptor == ((iconv_t)(-1)) ) /* if open fail */ + { + strncpy(dst,src,dstlen); + return dstlen; + } + + /* Start translation */ + while (srclen > 0 && dstlen > 0) + { + iconv_ret = iconv(iconv_descriptor, &src, &srclen, + &dst, &dstlen); + if (iconv_ret != 0) + { + switch(errno) + { + /* invalid multibyte happened */ + case EILSEQ: + /* forward that byte */ + *dst = *src; + src++; srclen--; + dst++; dstlen--; + break; + /* incomplete multibyte happened */ + case EINVAL: + /* forward that byte (maybe wrong)*/ + *dst = *src; + src++; srclen--; + dst++; dstlen--; + break; + /* dst no rooms */ + case E2BIG: + /* break out the while loop */ + srclen = 0; + break; + } + } + } + *dst = '\0'; + /* close descriptor of iconv*/ + iconv_close(iconv_descriptor); + + return (dstlen_old - dstlen); +} +#endif + + +void str_decode_M3(unsigned char *str) +{ + int adj; + int i; + unsigned char *src, *dst; + unsigned char buf[512]; + unsigned char charset[512],dst1[512]; + + + src = str; + dst = buf; + adj = 0; + + while (*src && (dst - buf) < sizeof(buf) - 1) + { + if (*src != '=') + { /* Thor: not coded */ + unsigned char *tmp = src; + while(adj && *tmp && isspace(*tmp)) tmp++; + if(adj && *tmp=='=') + { /* Thor: jump over space */ + adj = 0; + src = tmp; + } + else + *dst++ = *src++; + /* continue;*/ /* Thor: take out */ + } + else /* Thor: *src == '=' */ + { + unsigned char *tmp = src + 1; + if(*tmp == '?') /* Thor: =? coded */ + { + /* "=?%s?Q?" for QP, "=?%s?B?" for BASE64 */ + tmp ++; + i=0; + while(*tmp && *tmp != '?') + { + if (i+1= 0) + { + tmp += 3; /* Thor: decode's src */ +#if 0 + while(*tmp++ != '?'); /* Thor: no ? end, mmdecode -1 */ +#endif + while(*tmp && *tmp++ != '?'); /* Thor: no ? end, mmdecode -1 */ + /* Thor.980901: 0 也算 decode 結束 */ + if(*tmp == '=') tmp++; + src = tmp; /* Thor: decode over */ + dst += i; + adj = 1; /* Thor: adjcent */ + } + } + } + + while(src != tmp) /* Thor: not coded */ + *dst++ = *src++; + } + } + *dst = 0; + strcpy(str, buf); +} -- cgit v1.2.3 From d9b29d8cd690ed9db933cc975f299ab745c463f4 Mon Sep 17 00:00:00 2001 From: victor Date: Wed, 7 May 2003 23:45:31 +0000 Subject: rfc2047 again git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@827 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/innbbsd/Makefile | 3 ++- pttbbs/innbbsd/bbslink.c | 1 + pttbbs/innbbsd/innbbsd.c | 5 +++++ pttbbs/innbbsd/inntobbs.c | 2 +- pttbbs/innbbsd/receive_article.c | 2 -- 5 files changed, 9 insertions(+), 4 deletions(-) diff --git a/pttbbs/innbbsd/Makefile b/pttbbs/innbbsd/Makefile index 92214f93..56c91213 100644 --- a/pttbbs/innbbsd/Makefile +++ b/pttbbs/innbbsd/Makefile @@ -55,7 +55,8 @@ DBZOBJS = dbzserver.o dbzinnbbsd.o pmain.o connectsock.o bbslib.o his.o \ daemon.o file.o dbz.o dbztool.o rfc931.o port.o closeonexec.o \ morelog.o NNRPOBJS = bbsnnrp.o pmain.o bbslib.o connectsock.o file.o -LINKOBJS = bbslink.o pmain.o inntobbs.o echobbslib.o connectsock.o file.o port.o +LINKOBJS = bbslink.o pmain.o inntobbs.o echobbslib.o connectsock.o file.o port.o\ + str_decode.o LINKOBJS2 = bbslink2.o pmain.o inntobbs.o echobbslib.o connectsock.o file.o port.o CTLOBJS = ctlinnbbsd.o pmain.o bbslib.o connectsock.o file.o INNBBSD = innbbsd mkhistory bbsnnrp ctlinnbbsd $(BBSLINK) diff --git a/pttbbs/innbbsd/bbslink.c b/pttbbs/innbbsd/bbslink.c index 1c0b1565..d0a4bb21 100644 --- a/pttbbs/innbbsd/bbslink.c +++ b/pttbbs/innbbsd/bbslink.c @@ -1487,6 +1487,7 @@ try_read_outgoing: soverview.group = group; soverview.mtime = atol(mtime); soverview.from = from; + strcpy(subject, str_decode_M3(subject)); soverview.subject = subject; soverview.outgoingtype = outgoingtype; soverview.msgid = msgid; diff --git a/pttbbs/innbbsd/innbbsd.c b/pttbbs/innbbsd/innbbsd.c index f35c1cfb..f89d95ab 100644 --- a/pttbbs/innbbsd/innbbsd.c +++ b/pttbbs/innbbsd/innbbsd.c @@ -678,6 +678,11 @@ ClientType *client; HEADER[MID_H] && HEADER[NEWSGROUPS_H] ) { char *path1, *path2; int rel ; + strcpy(HEADER[SUBJECT_H], str_decode_M3(HEADER[SUBJECT_H])); + strcpy(HEADER[FROM_H], str_decode_M3(HEADER[FROM_H])); + strcpy(HEADER[DATE_H], str_decode_M3(HEADER[DATE_H])); + strcpy(HEADER[MID_H], str_decode_M3(HEADER[MID_H])); + strcpy(HEADER[NEWSGROUPS_H], str_decode_M3(HEADER[NEWSGROUPS_H])); rel = 0; path1 = (char*)mymalloc(strlen(HEADER[PATH_H]) + 3); path2 = (char*)mymalloc(strlen(MYBBSID) + 3); diff --git a/pttbbs/innbbsd/inntobbs.c b/pttbbs/innbbsd/inntobbs.c index 653ea488..b10c44e5 100644 --- a/pttbbs/innbbsd/inntobbs.c +++ b/pttbbs/innbbsd/inntobbs.c @@ -205,7 +205,7 @@ echomaillog() if( echomailfp != NULL ) { fprintf(echomailfp,"\n"); fprintf(echomailfp,"發信人: %s, 信區: %s\n", FROM, GROUPS); - fprintf(echomailfp,"標 題: %s\n", SUBJECT); + fprintf(echomailfp,"標 題: %s\n", str_decode_M3(SUBJECT)); fprintf(echomailfp,"發信站: %s (%s)\n", SITE, DATE); fprintf(echomailfp,"轉信站: %s (%s)\n", PATH, REMOTEHOSTNAME); fflush(echomailfp); diff --git a/pttbbs/innbbsd/receive_article.c b/pttbbs/innbbsd/receive_article.c index 6b1e59c7..29790a96 100644 --- a/pttbbs/innbbsd/receive_article.c +++ b/pttbbs/innbbsd/receive_article.c @@ -545,7 +545,6 @@ receive_control() *firstpath = '\0'; if (isdir(boardhome)) { - strcpy(SUBJECT, str_decode_M3(SUBJECT)); fname = (char *) post_article(boardhome, FROM, "control", bbspost_write_control, NULL, firstpath); if (fname != NULL) { @@ -680,7 +679,6 @@ cancel_article_front(msgid) *body = '\n'; } if (*subject){ - strcpy(subject, str_decode_M3(subject)); SUBJECT = subject; } fname = (char *) post_article(boardhome, FROM, "deleted", bbspost_write_cancel, filename, firstpath); -- cgit v1.2.3 From c1dc98be9b7c75bd335cf831a0e5fe9e23f4ac97 Mon Sep 17 00:00:00 2001 From: victor Date: Fri, 9 May 2003 07:44:48 +0000 Subject: foreigner identification git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@828 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/include/pttstruct.h | 8 +++-- pttbbs/mbbsd/admin.c | 17 ++++++--- pttbbs/mbbsd/mbbsd.c | 10 +++++- pttbbs/mbbsd/user.c | 86 ++++++++++++++++++++++++++++++++++------------ pttbbs/sample/pttbbs.conf | 3 ++ 5 files changed, 95 insertions(+), 29 deletions(-) diff --git a/pttbbs/include/pttstruct.h b/pttbbs/include/pttstruct.h index cb60f97d..044704ad 100644 --- a/pttbbs/include/pttstruct.h +++ b/pttbbs/include/pttstruct.h @@ -1,4 +1,4 @@ -/* $Id: pttstruct.h,v 1.35 2003/05/07 03:35:07 bbs Exp $ */ +/* $Id: pttstruct.h,v 1.36 2003/05/09 07:44:48 victor Exp $ */ #ifndef INCLUDE_STRUCT_H #define INCLUDE_STRUCT_H @@ -75,7 +75,8 @@ typedef struct userec_t { char mind[4]; char ident[11]; unsigned int uflag2; - char pad[72]; + char foreign; + char pad[71]; } userec_t; /* these are flags in userec_t.uflag */ #define SIG_FLAG 0x3 /* signature number, 2 bits */ @@ -95,6 +96,9 @@ typedef struct userec_t { #define FAVNOHILIGHT 0x10 /* false if hilight favorite */ #define FAVNEW_FLAG 0x20 /* true if add new board into one's fav */ +/* these are flags in userec_t.foreign */ +#define FOREIGN 0x1 +#define LIVERIGHT 0x2 #define BTLEN 48 /* Length of board title */ diff --git a/pttbbs/mbbsd/admin.c b/pttbbs/mbbsd/admin.c index dc792e47..4b87f98a 100644 --- a/pttbbs/mbbsd/admin.c +++ b/pttbbs/mbbsd/admin.c @@ -1,4 +1,4 @@ -/* $Id: admin.c,v 1.32 2003/05/07 08:14:21 bbs Exp $ */ +/* $Id: admin.c,v 1.33 2003/05/09 07:43:57 victor Exp $ */ #include "bbs.h" /* 使用者管理 */ @@ -413,16 +413,18 @@ x_file() int aborted; char ans[4], *fpath; - move(b_lines - 4, 0); + move(b_lines - 6, 0); /* Ptt */ outs("設定 (1)身份確認信 (4)post注意事項 (5)錯誤登入訊息 (6)註冊範例 (7)通過確認通知\n"); outs(" (8)email post通知 (9)系統功\能精靈 (A)茶樓 (B)站長名單 (C)email通過確認\n"); - outs(" (D)新使用者需知 (E)身份確認方法 (F)歡迎畫面 (G)進站畫面 " + outs(" (D)新使用者需知 (E)身份確認方法 (F)歡迎畫面 (G)進站畫面" #ifdef MULTI_WELCOME_LOGIN "(X)刪除進站畫面" #endif "\n"); - getdata(b_lines - 1, 0, " (H)看板期限 (I)故鄉 (J)出站畫面 (K)生日卡 (L)節日 [Q]取消?", ans, sizeof(ans), LCECHO); + outs(" (H)看板期限 (I)故鄉 (J)出站畫面 (K)生日卡 (L)節日 (M)外籍使用者認證通知\n"); + outs(" (N)外籍使用者過期警告通知\n"); + getdata(b_lines - 1, 0, "[Q]取消[1-9 A-N]?", ans, sizeof(ans), LCECHO); switch (ans[0]) { case '1': @@ -521,6 +523,12 @@ x_file() case 'l': fpath = "etc/feast"; break; + case 'm': + fpath = "etc/foreign_expired"; + break; + case 'n': + fpath = "etc/foreign_expired_warn"; + break; default: return FULLUPDATE; } @@ -754,6 +762,7 @@ scan_register_form(char *regfile, int automode, int neednum) char fdata[7][STRLEN]; char fname[STRLEN], buf[STRLEN]; char ans[4], *ptr, *uid; + char foreign; int n = 0, unum = 0; int nSelf = 0, nAuto = 0; diff --git a/pttbbs/mbbsd/mbbsd.c b/pttbbs/mbbsd/mbbsd.c index ef35cfe9..9c360550 100644 --- a/pttbbs/mbbsd/mbbsd.c +++ b/pttbbs/mbbsd/mbbsd.c @@ -1,4 +1,4 @@ -/* $Id: mbbsd.c,v 1.71 2003/04/14 07:47:54 in2 Exp $ */ +/* $Id: mbbsd.c,v 1.72 2003/05/09 07:43:57 victor Exp $ */ #include "bbs.h" #define SOCKET_QLEN 4 @@ -884,6 +884,14 @@ user_login() if (!PERM_HIDE(currutmp)) cuser.lastlogin = login_start_time; + if (login_start_time - cuser.firstlogin > (FOREIGN_REG_DAY - 5) * 24 * 3600){ + mail_muser(cuser, "[出入境管理局]", "etc/foreign_expired_warn"); + } + else if (login_start_time - cuser.firstlogin > FOREIGN_REG_DAY * 24 * 3600){ + cuser.userlevel &= ~(PERM_LOGINOK | PERM_POST); + mail_muser(cuser, "[出入境管理局]", "etc/foreign_expired"); + } + passwd_update(usernum, &cuser); for (i = 0; i < NUMVIEWFILE; i++) diff --git a/pttbbs/mbbsd/user.c b/pttbbs/mbbsd/user.c index 4059a275..5568854b 100644 --- a/pttbbs/mbbsd/user.c +++ b/pttbbs/mbbsd/user.c @@ -1,4 +1,4 @@ -/* $Id: user.c,v 1.52 2003/03/30 06:52:09 in2 Exp $ */ +/* $Id: user.c,v 1.53 2003/05/09 07:43:57 victor Exp $ */ #include "bbs.h" static char *sex[8] = { @@ -51,12 +51,12 @@ user_display(userec_t * u, int real) " 資 料 " " \033[m \033[30;41m┴┬┴┬┴┬\033[m\n"); prints(" 代號暱稱: %s(%s)\n" - " 真實姓名: %s\n" + " 真實姓名: %s %s\n" " 居住住址: %s\n" " 電子信箱: %s\n" " 性 別: %s\n" " 銀行帳戶: %d 銀兩\n", - u->userid, u->username, u->realname, u->address, u->email, + u->userid, u->username, u->realname, u->foreign & FOREIGN ? "(外籍)" : "", u->address, u->email, sex[u->sex % 8], u->money); sethomedir(genbuf, u->userid); @@ -309,7 +309,7 @@ uinfo_query(userec_t * u, int real, int unum) if (real) { getdata_buf(i++, 0, "真實姓名:", x.realname, sizeof(x.realname), DOECHO); - getdata_buf(i++, 0, "身分證號:", + getdata_buf(i++, 0, cuser.foreign & FOREIGN ? "護照號碼" : "身分證號:", x.ident, sizeof(x.ident), DOECHO); getdata_buf(i++, 0, "居住地址:", x.address, sizeof(x.address), DOECHO); @@ -433,6 +433,13 @@ uinfo_query(userec_t * u, int real, int unum) x.chc_tie = atoi(p); break; } + if (getdata_str(i++, 0, "國籍 1)本國 2)外國:", buf, 2, DOECHO, x.foreign & FOREIGN ? "2" : "1")) + if ((fail = atoi(buf)) >= 0){ + if (fail == 0) + x.foreign |= FOREIGN; + else + x.foreign &= ~FOREIGN; + } fail = 0; } break; @@ -890,7 +897,7 @@ isvaildemail(char *email) } static void -toregister(char *email, char *genbuf, char *phone, char *career, +toregister(char *email, char *genbuf, char *phone, char *career, char fore, char *ident, char *rname, char *addr, char *mobile) { FILE *fn; @@ -900,7 +907,8 @@ toregister(char *email, char *genbuf, char *phone, char *career, if (phone[0] != 0) { fn = fopen(buf, "w"); assert(fn); - fprintf(fn, "%s\n%s\n%s\n%s\n%s\n%s\n", + fprintf(fn, "%s%s\n%s\n%s\n%s\n%s\n%s\n", + fore & FOREIGN ? "#foreign\n" : "", phone, career, ident, rname, addr, mobile); fclose(fn); } @@ -1085,6 +1093,9 @@ int u_register(void) { char rname[21], addr[51], ident[12], mobile[21]; +//#ifdef FOREIGN_REG_DAY + char fore[2]; +//#endif char phone[21], career[41], email[51], birthday[9], sex_is[2], year, mon, day; char inregcode[14], regcode[50]; @@ -1125,6 +1136,10 @@ u_register(void) sethomefile(genbuf, cuser.userid, "justify.wait"); if ((fn = fopen(genbuf, "r"))) { fgets(phone, 21, fn); + if(strcmp(ident, "#foreign") == 0){ + fore[0] |= FOREIGN; + fgets(ident, 21, fn); + } phone[strlen(phone) - 1] = 0; fgets(career, 41, fn); career[strlen(career) - 1] = 0; @@ -1172,7 +1187,7 @@ u_register(void) outs("認證碼錯誤\n"); pressanykey(); } - toregister(email, genbuf, phone, career, ident, rname, addr, mobile); + toregister(email, genbuf, phone, career, fore[0], ident, rname, addr, mobile); return FULLUPDATE; } @@ -1188,16 +1203,42 @@ u_register(void) move(1, 0); prints("%s(%s) 您好,請據實填寫以下的資料:", cuser.userid, cuser.username); - while( 1 ){ - getfield(3, "D123456789", "身分證號", ident, 11); - if ('a' <= ident[0] && ident[0] <= 'z') - ident[0] -= 32; - if( ispersonalid(ident) ) + while (1) { + getfield(2, "Y/n", "是否為本國籍?", fore, 2); + fore[0] = tolower(fore[0]); + if (fore[0] == 'y'){ + fore[0] = '\0'; break; - vmsg("您的輸入不正確(若有問題麻煩至SYSOP板)"); + } + else if (fore[0] == 'n'){ + getdata(4, 0, "是否確定(Y/N)", ans, sizeof(ans), LCECHO); + if (ans[0] == 'y' || ans[0] == 'Y'){ + fore[0] |= FOREIGN; + break; + } + } + } + if (!fore[0]){ + while( 1 ){ + getfield(5, "D123456789", "身分證號", ident, 11); + if ('a' <= ident[0] && ident[0] <= 'z') + ident[0] -= 32; + if( ispersonalid(ident) ) + break; + vmsg("您的輸入不正確(若有問題麻煩至SYSOP板)"); + } + } + else{ + while( 1 ){ + getfield(5, "0123456789", "護照號碼", ident, 11); + getdata(7, 0, "是否確定(Y/N)", ans, sizeof(ans), LCECHO); + if (ans[0] == 'y' || ans[0] == 'Y') + break; + vmsg("請重新輸入(若有問題麻煩至SYSOP板)"); + } } while (1) { - getfield(5, "請用中文", "真實姓名", rname, 20); + getfield(8, "請用中文", "真實姓名", rname, 20); if( (errcode = isvaildname(rname)) == NULL ) break; else @@ -1208,7 +1249,7 @@ u_register(void) prints("麻煩您盡量詳細的填寫您的服務單位, 大專院校請麻煩" "加系所, 公司單位請加職稱"); while (1) { - getfield(8, "學校(含\033[1;33m系所年級\033[m)或單位職稱", + getfield(9, "學校(含\033[1;33m系所年級\033[m)或單位職稱", "服務單位", career, 40); if( (errcode = isvaildcareer(career)) == NULL ) break; @@ -1216,7 +1257,7 @@ u_register(void) vmsg(errcode); } while (1) { - getfield(10, "含\033[1;33m縣市\033[m及門寢號碼" + getfield(11, "含\033[1;33m縣市\033[m及門寢號碼" "(台北請加\033[1;33m行政區\033[m)", "目前住址", addr, 50); if( (errcode = isvaildaddr(addr)) == NULL ) @@ -1225,18 +1266,18 @@ u_register(void) vmsg(errcode); } while (1) { - getfield(12, "不加-(), 包括長途區號", "連絡電話", phone, 11); + getfield(13, "不加-(), 包括長途區號", "連絡電話", phone, 11); if( (errcode = isvaildphone(phone)) == NULL ) break; else vmsg(errcode); } - getfield(14, "只輸入數字 如:0912345678 (可不填)", + getfield(15, "只輸入數字 如:0912345678 (可不填)", "手機號碼", mobile, 20); while (1) { int len; - getfield(16, "月月/日日/西元 如:09/27/76", "生日", birthday, 9); + getfield(17, "月月/日日/西元 如:09/27/76", "生日", birthday, 9); len = strlen(birthday); if (!len) { snprintf(birthday, sizeof(birthday), "%02i/%02i/%02i", @@ -1259,8 +1300,8 @@ u_register(void) } break; } - getfield(18, "1.葛格 2.姐接 ", "性別", sex_is, 2); - getdata(19, 0, "以上資料是否正確(Y/N)?(Q)取消註冊 [N] ", + getfield(19, "1.葛格 2.姐接 ", "性別", sex_is, 2); + getdata(20, 0, "以上資料是否正確(Y/N)?(Q)取消註冊 [N] ", ans, sizeof(ans), LCECHO); if (ans[0] == 'q') return 0; @@ -1276,11 +1317,12 @@ u_register(void) cuser.month = mon; cuser.day = day; cuser.year = year; + cuser.foreign = fore[0]; trim(career); trim(addr); trim(phone); - toregister(email, genbuf, phone, career, ident, rname, addr, mobile); + toregister(email, genbuf, phone, career, fore[0], ident, rname, addr, mobile); clear(); move(9, 3); diff --git a/pttbbs/sample/pttbbs.conf b/pttbbs/sample/pttbbs.conf index e222a34d..8a09e6a0 100644 --- a/pttbbs/sample/pttbbs.conf +++ b/pttbbs/sample/pttbbs.conf @@ -42,6 +42,9 @@ /* 定義看板好友名單將會在幾秒鐘後失效強迫重載 */ #define HBFLexpire (432000) +/* 定義外國人最長居留時間,之後需向站方申請永久居留權 */ +#define FOREIGN_REG_DAY 30 + /* 板主可以按大寫 H切換隱形與否 */ #define BMCHS -- cgit v1.2.3 From a09db53ba1a2b3c1079109f79161386298c40abc Mon Sep 17 00:00:00 2001 From: victor Date: Fri, 9 May 2003 07:53:55 +0000 Subject: fix last commit bug git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@829 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/mbbsd.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/pttbbs/mbbsd/mbbsd.c b/pttbbs/mbbsd/mbbsd.c index 9c360550..77dc98e3 100644 --- a/pttbbs/mbbsd/mbbsd.c +++ b/pttbbs/mbbsd/mbbsd.c @@ -1,4 +1,4 @@ -/* $Id: mbbsd.c,v 1.72 2003/05/09 07:43:57 victor Exp $ */ +/* $Id: mbbsd.c,v 1.73 2003/05/09 07:53:55 victor Exp $ */ #include "bbs.h" #define SOCKET_QLEN 4 @@ -884,14 +884,15 @@ user_login() if (!PERM_HIDE(currutmp)) cuser.lastlogin = login_start_time; - if (login_start_time - cuser.firstlogin > (FOREIGN_REG_DAY - 5) * 24 * 3600){ - mail_muser(cuser, "[出入境管理局]", "etc/foreign_expired_warn"); - } - else if (login_start_time - cuser.firstlogin > FOREIGN_REG_DAY * 24 * 3600){ - cuser.userlevel &= ~(PERM_LOGINOK | PERM_POST); - mail_muser(cuser, "[出入境管理局]", "etc/foreign_expired"); + if (cuser.foreign & FOREIGN){ + if (login_start_time - cuser.firstlogin > (FOREIGN_REG_DAY - 5) * 24 * 3600){ + mail_muser(cuser, "[出入境管理局]", "etc/foreign_expired_warn"); + } + else if (login_start_time - cuser.firstlogin > FOREIGN_REG_DAY * 24 * 3600){ + cuser.userlevel &= ~(PERM_LOGINOK | PERM_POST); + mail_muser(cuser, "[出入境管理局]", "etc/foreign_expired"); + } } - passwd_update(usernum, &cuser); for (i = 0; i < NUMVIEWFILE; i++) -- cgit v1.2.3 From a15cada9176bcfd32e362f627175a484ce9436e9 Mon Sep 17 00:00:00 2001 From: victor Date: Fri, 9 May 2003 13:30:32 +0000 Subject: use another clear bits -_- git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@830 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/include/pttstruct.h | 11 ++++------- pttbbs/mbbsd/admin.c | 14 ++++++-------- pttbbs/mbbsd/mbbsd.c | 4 ++-- pttbbs/mbbsd/user.c | 44 +++++++++++++++++++++++++++++++------------- 4 files changed, 43 insertions(+), 30 deletions(-) diff --git a/pttbbs/include/pttstruct.h b/pttbbs/include/pttstruct.h index 044704ad..80bbe7f3 100644 --- a/pttbbs/include/pttstruct.h +++ b/pttbbs/include/pttstruct.h @@ -1,4 +1,4 @@ -/* $Id: pttstruct.h,v 1.36 2003/05/09 07:44:48 victor Exp $ */ +/* $Id: pttstruct.h,v 1.37 2003/05/09 13:30:32 victor Exp $ */ #ifndef INCLUDE_STRUCT_H #define INCLUDE_STRUCT_H @@ -75,8 +75,7 @@ typedef struct userec_t { char mind[4]; char ident[11]; unsigned int uflag2; - char foreign; - char pad[71]; + char pad[72]; } userec_t; /* these are flags in userec_t.uflag */ #define SIG_FLAG 0x3 /* signature number, 2 bits */ @@ -95,10 +94,8 @@ typedef struct userec_t { #define WATERMODE(mode) ((cuser.uflag2 & WATER_MASK) == mode) #define FAVNOHILIGHT 0x10 /* false if hilight favorite */ #define FAVNEW_FLAG 0x20 /* true if add new board into one's fav */ - -/* these are flags in userec_t.foreign */ -#define FOREIGN 0x1 -#define LIVERIGHT 0x2 +#define FOREIGN 0x100 /* true if a foreign */ +#define LIVERIGHT 0x200 /* true if get "liveright" already */ #define BTLEN 48 /* Length of board title */ diff --git a/pttbbs/mbbsd/admin.c b/pttbbs/mbbsd/admin.c index 4b87f98a..d021c2f0 100644 --- a/pttbbs/mbbsd/admin.c +++ b/pttbbs/mbbsd/admin.c @@ -1,4 +1,4 @@ -/* $Id: admin.c,v 1.33 2003/05/09 07:43:57 victor Exp $ */ +/* $Id: admin.c,v 1.34 2003/05/09 13:30:32 victor Exp $ */ #include "bbs.h" /* 使用者管理 */ @@ -762,7 +762,6 @@ scan_register_form(char *regfile, int automode, int neednum) char fdata[7][STRLEN]; char fname[STRLEN], buf[STRLEN]; char ans[4], *ptr, *uid; - char foreign; int n = 0, unum = 0; int nSelf = 0, nAuto = 0; @@ -822,12 +821,11 @@ scan_register_form(char *regfile, int automode, int neednum) user_display(&muser, 1); move(14, 0); prints("\033[1;32m------------- 請站長嚴格審核使用者資料,您還有 %d 份---------------\033[m\n", neednum); - for (n = 0; field[n]; n++) { - if (n >= 2 && n <= 5) - prints("%d.", n - 2); - else - prints(" "); - prints("%-12s:%s\n", finfo[n], fdata[n]); + prints(" %-12s:%s\n", finfo[0], fdata[0]); + prints(" %-12s:%s\n", finfo[1], fdata[1]); + prints("1.%-12s:%s%s\n", finfo[n], fdata[n], muser.uflag2 & FOREIGN ? "外籍" : ""); + for (n = 3; field[n]; n++) { + prints("%d.%-12s:%s\n", n - 2, finfo[n], fdata[n]); } if (muser.userlevel & PERM_LOGINOK) { getdata(b_lines - 1, 0, "\033[1;32m此帳號已經完成註冊, " diff --git a/pttbbs/mbbsd/mbbsd.c b/pttbbs/mbbsd/mbbsd.c index 77dc98e3..7fc41c85 100644 --- a/pttbbs/mbbsd/mbbsd.c +++ b/pttbbs/mbbsd/mbbsd.c @@ -1,4 +1,4 @@ -/* $Id: mbbsd.c,v 1.73 2003/05/09 07:53:55 victor Exp $ */ +/* $Id: mbbsd.c,v 1.74 2003/05/09 13:30:32 victor Exp $ */ #include "bbs.h" #define SOCKET_QLEN 4 @@ -884,7 +884,7 @@ user_login() if (!PERM_HIDE(currutmp)) cuser.lastlogin = login_start_time; - if (cuser.foreign & FOREIGN){ + if (cuser.uflag2 & (FOREIGN | LIVERIGHT)){ if (login_start_time - cuser.firstlogin > (FOREIGN_REG_DAY - 5) * 24 * 3600){ mail_muser(cuser, "[出入境管理局]", "etc/foreign_expired_warn"); } diff --git a/pttbbs/mbbsd/user.c b/pttbbs/mbbsd/user.c index 5568854b..58a67ef3 100644 --- a/pttbbs/mbbsd/user.c +++ b/pttbbs/mbbsd/user.c @@ -1,4 +1,4 @@ -/* $Id: user.c,v 1.53 2003/05/09 07:43:57 victor Exp $ */ +/* $Id: user.c,v 1.54 2003/05/09 13:30:32 victor Exp $ */ #include "bbs.h" static char *sex[8] = { @@ -51,12 +51,15 @@ user_display(userec_t * u, int real) " 資 料 " " \033[m \033[30;41m┴┬┴┬┴┬\033[m\n"); prints(" 代號暱稱: %s(%s)\n" - " 真實姓名: %s %s\n" + " 真實姓名: %s %s%s\n" " 居住住址: %s\n" " 電子信箱: %s\n" " 性 別: %s\n" " 銀行帳戶: %d 銀兩\n", - u->userid, u->username, u->realname, u->foreign & FOREIGN ? "(外籍)" : "", u->address, u->email, + u->userid, u->username, u->realname, + u->uflag2 & FOREIGN ? "(外籍: " : "", + u->uflag2 & LIVERIGHT ? "永久居留)" : "未取得居留權)", + u->address, u->email, sex[u->sex % 8], u->money); sethomedir(genbuf, u->userid); @@ -309,7 +312,7 @@ uinfo_query(userec_t * u, int real, int unum) if (real) { getdata_buf(i++, 0, "真實姓名:", x.realname, sizeof(x.realname), DOECHO); - getdata_buf(i++, 0, cuser.foreign & FOREIGN ? "護照號碼" : "身分證號:", + getdata_buf(i++, 0, cuser.uflag2 & FOREIGN ? "護照號碼" : "身分證號:", x.ident, sizeof(x.ident), DOECHO); getdata_buf(i++, 0, "居住地址:", x.address, sizeof(x.address), DOECHO); @@ -433,12 +436,26 @@ uinfo_query(userec_t * u, int real, int unum) x.chc_tie = atoi(p); break; } - if (getdata_str(i++, 0, "國籍 1)本國 2)外國:", buf, 2, DOECHO, x.foreign & FOREIGN ? "2" : "1")) - if ((fail = atoi(buf)) >= 0){ - if (fail == 0) - x.foreign |= FOREIGN; + if (getdata_str(i++, 0, "國籍 1)本國 2)外國:", buf, 2, DOECHO, x.uflag2 & FOREIGN ? "2" : "1")) + if ((fail = atoi(buf)) > 0){ + if (fail == 2){ + x.uflag2 |= FOREIGN; + } else - x.foreign &= ~FOREIGN; + x.uflag2 &= ~FOREIGN; + } + if (x.uflag2 & FOREIGN) + if (getdata_str(i++, 0, "永久居留權 1)是 2)否:", buf, 2, DOECHO, x.uflag2 & LIVERIGHT ? "1" : "2")){ + if ((fail = atoi(buf)) > 0){ + if (fail == 1){ + x.uflag2 |= LIVERIGHT; + x.userlevel |= (PERM_LOGINOK | PERM_POST); + } + else{ + x.uflag2 &= ~LIVERIGHT; + x.userlevel &= ~(PERM_LOGINOK | PERM_POST); + } + } } fail = 0; } @@ -1093,9 +1110,7 @@ int u_register(void) { char rname[21], addr[51], ident[12], mobile[21]; -//#ifdef FOREIGN_REG_DAY char fore[2]; -//#endif char phone[21], career[41], email[51], birthday[9], sex_is[2], year, mon, day; char inregcode[14], regcode[50]; @@ -1137,7 +1152,7 @@ u_register(void) if ((fn = fopen(genbuf, "r"))) { fgets(phone, 21, fn); if(strcmp(ident, "#foreign") == 0){ - fore[0] |= FOREIGN; + fore[0] = 'y'; fore[1] = '\n'; fgets(ident, 21, fn); } phone[strlen(phone) - 1] = 0; @@ -1317,7 +1332,10 @@ u_register(void) cuser.month = mon; cuser.day = day; cuser.year = year; - cuser.foreign = fore[0]; + if (fore[0]) + cuser.uflag2 |= FOREIGN; + else + cuser.uflag2 &= ~FOREIGN; trim(career); trim(addr); trim(phone); -- cgit v1.2.3 From 5b06ab032b6b00c189ed40f5d0efcc48e0a49172 Mon Sep 17 00:00:00 2001 From: victor Date: Fri, 9 May 2003 15:06:22 +0000 Subject: exit if recommend a blank line git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@831 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/bbs.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pttbbs/mbbsd/bbs.c b/pttbbs/mbbsd/bbs.c index bc1cdcb3..6df7f4da 100644 --- a/pttbbs/mbbsd/bbs.c +++ b/pttbbs/mbbsd/bbs.c @@ -1,4 +1,4 @@ -/* $Id: bbs.c,v 1.90 2003/05/07 08:16:30 victor Exp $ */ +/* $Id: bbs.c,v 1.91 2003/05/09 15:06:22 victor Exp $ */ #include "bbs.h" static int recommend(int ent, fileheader_t * fhdr, char *direct); @@ -1263,6 +1263,7 @@ recommend(int ent, fileheader_t * fhdr, char *direct) #endif if (!getdata(b_lines - 2, 0, "推薦語:", path, 40, DOECHO) || + path == NULL || !getdata(b_lines - 1, 0, "確定要推薦, 請仔細考慮(Y/N)?[n] ", yn, 5, LCECHO) || yn[0] != 'y') -- cgit v1.2.3 From e631f2ee0c53b3030c9f19958103f90e318d92ce Mon Sep 17 00:00:00 2001 From: victor Date: Fri, 9 May 2003 16:27:29 +0000 Subject: fix err show git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@832 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/user.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pttbbs/mbbsd/user.c b/pttbbs/mbbsd/user.c index 58a67ef3..99a830b0 100644 --- a/pttbbs/mbbsd/user.c +++ b/pttbbs/mbbsd/user.c @@ -1,4 +1,4 @@ -/* $Id: user.c,v 1.54 2003/05/09 13:30:32 victor Exp $ */ +/* $Id: user.c,v 1.55 2003/05/09 16:27:29 victor Exp $ */ #include "bbs.h" static char *sex[8] = { @@ -58,7 +58,9 @@ user_display(userec_t * u, int real) " 銀行帳戶: %d 銀兩\n", u->userid, u->username, u->realname, u->uflag2 & FOREIGN ? "(外籍: " : "", - u->uflag2 & LIVERIGHT ? "永久居留)" : "未取得居留權)", + u->uflag2 & FOREIGN ? + (u->uflag2 & LIVERIGHT) ? "永久居留)" : "未取得居留權)" + : "", u->address, u->email, sex[u->sex % 8], u->money); -- cgit v1.2.3 From 8a015da1cad893e55a5db35873c668eb403749da Mon Sep 17 00:00:00 2001 From: bbs Date: Sat, 10 May 2003 07:30:12 +0000 Subject: wrong usage -_- git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@833 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/innbbsd/bbslink.c | 2 +- pttbbs/innbbsd/innbbsd.c | 10 +++++----- pttbbs/innbbsd/inntobbs.c | 3 ++- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/pttbbs/innbbsd/bbslink.c b/pttbbs/innbbsd/bbslink.c index d0a4bb21..b7ca2f9d 100644 --- a/pttbbs/innbbsd/bbslink.c +++ b/pttbbs/innbbsd/bbslink.c @@ -1487,7 +1487,7 @@ try_read_outgoing: soverview.group = group; soverview.mtime = atol(mtime); soverview.from = from; - strcpy(subject, str_decode_M3(subject)); + str_decode_M3(subject); soverview.subject = subject; soverview.outgoingtype = outgoingtype; soverview.msgid = msgid; diff --git a/pttbbs/innbbsd/innbbsd.c b/pttbbs/innbbsd/innbbsd.c index f89d95ab..f7fc0fc0 100644 --- a/pttbbs/innbbsd/innbbsd.c +++ b/pttbbs/innbbsd/innbbsd.c @@ -678,11 +678,11 @@ ClientType *client; HEADER[MID_H] && HEADER[NEWSGROUPS_H] ) { char *path1, *path2; int rel ; - strcpy(HEADER[SUBJECT_H], str_decode_M3(HEADER[SUBJECT_H])); - strcpy(HEADER[FROM_H], str_decode_M3(HEADER[FROM_H])); - strcpy(HEADER[DATE_H], str_decode_M3(HEADER[DATE_H])); - strcpy(HEADER[MID_H], str_decode_M3(HEADER[MID_H])); - strcpy(HEADER[NEWSGROUPS_H], str_decode_M3(HEADER[NEWSGROUPS_H])); + str_decode_M3(HEADER[SUBJECT_H]); + str_decode_M3(HEADER[FROM_H]); + str_decode_M3(HEADER[DATE_H]); + str_decode_M3(HEADER[MID_H]); + str_decode_M3(HEADER[NEWSGROUPS_H]); rel = 0; path1 = (char*)mymalloc(strlen(HEADER[PATH_H]) + 3); path2 = (char*)mymalloc(strlen(MYBBSID) + 3); diff --git a/pttbbs/innbbsd/inntobbs.c b/pttbbs/innbbsd/inntobbs.c index b10c44e5..fb854867 100644 --- a/pttbbs/innbbsd/inntobbs.c +++ b/pttbbs/innbbsd/inntobbs.c @@ -205,7 +205,8 @@ echomaillog() if( echomailfp != NULL ) { fprintf(echomailfp,"\n"); fprintf(echomailfp,"發信人: %s, 信區: %s\n", FROM, GROUPS); - fprintf(echomailfp,"標 題: %s\n", str_decode_M3(SUBJECT)); + str_decode_M3(SUBJECT); + fprintf(echomailfp,"標 題: %s\n", SUBJECT); fprintf(echomailfp,"發信站: %s (%s)\n", SITE, DATE); fprintf(echomailfp,"轉信站: %s (%s)\n", PATH, REMOTEHOSTNAME); fflush(echomailfp); -- cgit v1.2.3 From 84ae1a69b74fd601461574ce592ab6577b1d3f73 Mon Sep 17 00:00:00 2001 From: bbs Date: Sat, 10 May 2003 16:52:01 +0000 Subject: ifdef-else-endif :Q git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@834 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/include/config.h | 6 +++++- pttbbs/mbbsd/admin.c | 6 +++++- pttbbs/mbbsd/mbbsd.c | 4 +++- pttbbs/mbbsd/user.c | 27 ++++++++++++++++++++++++--- 4 files changed, 37 insertions(+), 6 deletions(-) diff --git a/pttbbs/include/config.h b/pttbbs/include/config.h index d5d80cdc..23bca878 100644 --- a/pttbbs/include/config.h +++ b/pttbbs/include/config.h @@ -1,4 +1,4 @@ -/* $Id: config.h,v 1.9 2003/03/10 03:13:02 in2 Exp $ */ +/* $Id: config.h,v 1.10 2003/05/10 16:52:01 bbs Exp $ */ #ifndef INCLUDE_CONFIG_H #define INCLUDE_CONFIG_H @@ -49,6 +49,10 @@ #define HAVE_JCEE 1 #endif +#ifndef FOREIGN_REG_DAY /* 外籍使用者試用日期上限 */ +#define FOREIGN_REG_DAY 30 +#endif + #ifndef HAVE_FREECLOAK #define HAVE_FREECLOAK 0 #endif diff --git a/pttbbs/mbbsd/admin.c b/pttbbs/mbbsd/admin.c index d021c2f0..309f0f8d 100644 --- a/pttbbs/mbbsd/admin.c +++ b/pttbbs/mbbsd/admin.c @@ -1,4 +1,4 @@ -/* $Id: admin.c,v 1.34 2003/05/09 13:30:32 victor Exp $ */ +/* $Id: admin.c,v 1.35 2003/05/10 16:52:01 bbs Exp $ */ #include "bbs.h" /* 使用者管理 */ @@ -823,7 +823,11 @@ scan_register_form(char *regfile, int automode, int neednum) prints("\033[1;32m------------- 請站長嚴格審核使用者資料,您還有 %d 份---------------\033[m\n", neednum); prints(" %-12s:%s\n", finfo[0], fdata[0]); prints(" %-12s:%s\n", finfo[1], fdata[1]); +#ifdef FOREIGN_REG_DAY prints("1.%-12s:%s%s\n", finfo[n], fdata[n], muser.uflag2 & FOREIGN ? "外籍" : ""); +#else + prints("1.%-12s:%s\n", finfo[n], fdata[n]); +#endif for (n = 3; field[n]; n++) { prints("%d.%-12s:%s\n", n - 2, finfo[n], fdata[n]); } diff --git a/pttbbs/mbbsd/mbbsd.c b/pttbbs/mbbsd/mbbsd.c index 7fc41c85..33f45264 100644 --- a/pttbbs/mbbsd/mbbsd.c +++ b/pttbbs/mbbsd/mbbsd.c @@ -1,4 +1,4 @@ -/* $Id: mbbsd.c,v 1.74 2003/05/09 13:30:32 victor Exp $ */ +/* $Id: mbbsd.c,v 1.75 2003/05/10 16:52:01 bbs Exp $ */ #include "bbs.h" #define SOCKET_QLEN 4 @@ -884,6 +884,7 @@ user_login() if (!PERM_HIDE(currutmp)) cuser.lastlogin = login_start_time; +#ifdef FOREIGN_REG_DAY if (cuser.uflag2 & (FOREIGN | LIVERIGHT)){ if (login_start_time - cuser.firstlogin > (FOREIGN_REG_DAY - 5) * 24 * 3600){ mail_muser(cuser, "[出入境管理局]", "etc/foreign_expired_warn"); @@ -893,6 +894,7 @@ user_login() mail_muser(cuser, "[出入境管理局]", "etc/foreign_expired"); } } +#endif passwd_update(usernum, &cuser); for (i = 0; i < NUMVIEWFILE; i++) diff --git a/pttbbs/mbbsd/user.c b/pttbbs/mbbsd/user.c index 99a830b0..0ff9a7f0 100644 --- a/pttbbs/mbbsd/user.c +++ b/pttbbs/mbbsd/user.c @@ -1,4 +1,4 @@ -/* $Id: user.c,v 1.55 2003/05/09 16:27:29 victor Exp $ */ +/* $Id: user.c,v 1.56 2003/05/10 16:52:01 bbs Exp $ */ #include "bbs.h" static char *sex[8] = { @@ -51,16 +51,22 @@ user_display(userec_t * u, int real) " 資 料 " " \033[m \033[30;41m┴┬┴┬┴┬\033[m\n"); prints(" 代號暱稱: %s(%s)\n" - " 真實姓名: %s %s%s\n" + " 真實姓名: %s" +#ifdef FOREIGN_REG_DAY + " %s%s" +#endif + "\n" " 居住住址: %s\n" " 電子信箱: %s\n" " 性 別: %s\n" " 銀行帳戶: %d 銀兩\n", u->userid, u->username, u->realname, +#ifdef FOREIGN_REG_DAY u->uflag2 & FOREIGN ? "(外籍: " : "", u->uflag2 & FOREIGN ? (u->uflag2 & LIVERIGHT) ? "永久居留)" : "未取得居留權)" : "", +#endif u->address, u->email, sex[u->sex % 8], u->money); @@ -314,7 +320,11 @@ uinfo_query(userec_t * u, int real, int unum) if (real) { getdata_buf(i++, 0, "真實姓名:", x.realname, sizeof(x.realname), DOECHO); +#ifdef FOREIGN_REG_DAY getdata_buf(i++, 0, cuser.uflag2 & FOREIGN ? "護照號碼" : "身分證號:", +#else + getdata_buf(i++, 0, "身分證號:", +#endif x.ident, sizeof(x.ident), DOECHO); getdata_buf(i++, 0, "居住地址:", x.address, sizeof(x.address), DOECHO); @@ -438,6 +448,7 @@ uinfo_query(userec_t * u, int real, int unum) x.chc_tie = atoi(p); break; } +#ifdef FOREIGN_REG_DAY if (getdata_str(i++, 0, "國籍 1)本國 2)外國:", buf, 2, DOECHO, x.uflag2 & FOREIGN ? "2" : "1")) if ((fail = atoi(buf)) > 0){ if (fail == 2){ @@ -459,6 +470,7 @@ uinfo_query(userec_t * u, int real, int unum) } } } +#endif fail = 0; } break; @@ -927,7 +939,10 @@ toregister(char *email, char *genbuf, char *phone, char *career, char fore, fn = fopen(buf, "w"); assert(fn); fprintf(fn, "%s%s\n%s\n%s\n%s\n%s\n%s\n", - fore & FOREIGN ? "#foreign\n" : "", +#ifdef FOREIGN_REG_DAY + fore & FOREIGN ? "#foreign\n" : +#endif + "", phone, career, ident, rname, addr, mobile); fclose(fn); } @@ -1220,6 +1235,7 @@ u_register(void) move(1, 0); prints("%s(%s) 您好,請據實填寫以下的資料:", cuser.userid, cuser.username); +#ifdef FOREIGN_REG_DAY while (1) { getfield(2, "Y/n", "是否為本國籍?", fore, 2); fore[0] = tolower(fore[0]); @@ -1236,6 +1252,7 @@ u_register(void) } } if (!fore[0]){ +#endif while( 1 ){ getfield(5, "D123456789", "身分證號", ident, 11); if ('a' <= ident[0] && ident[0] <= 'z') @@ -1244,6 +1261,7 @@ u_register(void) break; vmsg("您的輸入不正確(若有問題麻煩至SYSOP板)"); } +#ifdef FOREIGN_REG_DAY } else{ while( 1 ){ @@ -1254,6 +1272,7 @@ u_register(void) vmsg("請重新輸入(若有問題麻煩至SYSOP板)"); } } +#endif while (1) { getfield(8, "請用中文", "真實姓名", rname, 20); if( (errcode = isvaildname(rname)) == NULL ) @@ -1334,10 +1353,12 @@ u_register(void) cuser.month = mon; cuser.day = day; cuser.year = year; +#ifdef FOREIGN_REG_DAY if (fore[0]) cuser.uflag2 |= FOREIGN; else cuser.uflag2 &= ~FOREIGN; +#endif trim(career); trim(addr); trim(phone); -- cgit v1.2.3 From c5948fdb98c790e0cf40669473888ea5da94f413 Mon Sep 17 00:00:00 2001 From: victor Date: Sun, 11 May 2003 00:35:16 +0000 Subject: last commit err git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@835 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/admin.c | 4 ++-- pttbbs/mbbsd/mbbsd.c | 4 ++-- pttbbs/mbbsd/user.c | 18 +++++++++--------- pttbbs/sample/pttbbs.conf | 4 +++- 4 files changed, 16 insertions(+), 14 deletions(-) diff --git a/pttbbs/mbbsd/admin.c b/pttbbs/mbbsd/admin.c index 309f0f8d..5253a37c 100644 --- a/pttbbs/mbbsd/admin.c +++ b/pttbbs/mbbsd/admin.c @@ -1,4 +1,4 @@ -/* $Id: admin.c,v 1.35 2003/05/10 16:52:01 bbs Exp $ */ +/* $Id: admin.c,v 1.36 2003/05/11 00:35:16 victor Exp $ */ #include "bbs.h" /* 使用者管理 */ @@ -823,7 +823,7 @@ scan_register_form(char *regfile, int automode, int neednum) prints("\033[1;32m------------- 請站長嚴格審核使用者資料,您還有 %d 份---------------\033[m\n", neednum); prints(" %-12s:%s\n", finfo[0], fdata[0]); prints(" %-12s:%s\n", finfo[1], fdata[1]); -#ifdef FOREIGN_REG_DAY +#ifdef FOREIGN_REG prints("1.%-12s:%s%s\n", finfo[n], fdata[n], muser.uflag2 & FOREIGN ? "外籍" : ""); #else prints("1.%-12s:%s\n", finfo[n], fdata[n]); diff --git a/pttbbs/mbbsd/mbbsd.c b/pttbbs/mbbsd/mbbsd.c index 33f45264..d52ffbcb 100644 --- a/pttbbs/mbbsd/mbbsd.c +++ b/pttbbs/mbbsd/mbbsd.c @@ -1,4 +1,4 @@ -/* $Id: mbbsd.c,v 1.75 2003/05/10 16:52:01 bbs Exp $ */ +/* $Id: mbbsd.c,v 1.76 2003/05/11 00:35:16 victor Exp $ */ #include "bbs.h" #define SOCKET_QLEN 4 @@ -884,7 +884,7 @@ user_login() if (!PERM_HIDE(currutmp)) cuser.lastlogin = login_start_time; -#ifdef FOREIGN_REG_DAY +#ifdef FOREIGN_REG if (cuser.uflag2 & (FOREIGN | LIVERIGHT)){ if (login_start_time - cuser.firstlogin > (FOREIGN_REG_DAY - 5) * 24 * 3600){ mail_muser(cuser, "[出入境管理局]", "etc/foreign_expired_warn"); diff --git a/pttbbs/mbbsd/user.c b/pttbbs/mbbsd/user.c index 0ff9a7f0..98c8eac1 100644 --- a/pttbbs/mbbsd/user.c +++ b/pttbbs/mbbsd/user.c @@ -1,4 +1,4 @@ -/* $Id: user.c,v 1.56 2003/05/10 16:52:01 bbs Exp $ */ +/* $Id: user.c,v 1.57 2003/05/11 00:35:16 victor Exp $ */ #include "bbs.h" static char *sex[8] = { @@ -52,7 +52,7 @@ user_display(userec_t * u, int real) " \033[m \033[30;41m┴┬┴┬┴┬\033[m\n"); prints(" 代號暱稱: %s(%s)\n" " 真實姓名: %s" -#ifdef FOREIGN_REG_DAY +#ifdef FOREIGN_REG " %s%s" #endif "\n" @@ -61,7 +61,7 @@ user_display(userec_t * u, int real) " 性 別: %s\n" " 銀行帳戶: %d 銀兩\n", u->userid, u->username, u->realname, -#ifdef FOREIGN_REG_DAY +#ifdef FOREIGN_REG u->uflag2 & FOREIGN ? "(外籍: " : "", u->uflag2 & FOREIGN ? (u->uflag2 & LIVERIGHT) ? "永久居留)" : "未取得居留權)" @@ -320,7 +320,7 @@ uinfo_query(userec_t * u, int real, int unum) if (real) { getdata_buf(i++, 0, "真實姓名:", x.realname, sizeof(x.realname), DOECHO); -#ifdef FOREIGN_REG_DAY +#ifdef FOREIGN_REG getdata_buf(i++, 0, cuser.uflag2 & FOREIGN ? "護照號碼" : "身分證號:", #else getdata_buf(i++, 0, "身分證號:", @@ -448,7 +448,7 @@ uinfo_query(userec_t * u, int real, int unum) x.chc_tie = atoi(p); break; } -#ifdef FOREIGN_REG_DAY +#ifdef FOREIGN_REG if (getdata_str(i++, 0, "國籍 1)本國 2)外國:", buf, 2, DOECHO, x.uflag2 & FOREIGN ? "2" : "1")) if ((fail = atoi(buf)) > 0){ if (fail == 2){ @@ -939,7 +939,7 @@ toregister(char *email, char *genbuf, char *phone, char *career, char fore, fn = fopen(buf, "w"); assert(fn); fprintf(fn, "%s%s\n%s\n%s\n%s\n%s\n%s\n", -#ifdef FOREIGN_REG_DAY +#ifdef FOREIGN_REG fore & FOREIGN ? "#foreign\n" : #endif "", @@ -1235,7 +1235,7 @@ u_register(void) move(1, 0); prints("%s(%s) 您好,請據實填寫以下的資料:", cuser.userid, cuser.username); -#ifdef FOREIGN_REG_DAY +#ifdef FOREIGN_REG while (1) { getfield(2, "Y/n", "是否為本國籍?", fore, 2); fore[0] = tolower(fore[0]); @@ -1261,7 +1261,7 @@ u_register(void) break; vmsg("您的輸入不正確(若有問題麻煩至SYSOP板)"); } -#ifdef FOREIGN_REG_DAY +#ifdef FOREIGN_REG } else{ while( 1 ){ @@ -1353,7 +1353,7 @@ u_register(void) cuser.month = mon; cuser.day = day; cuser.year = year; -#ifdef FOREIGN_REG_DAY +#ifdef FOREIGN_REG if (fore[0]) cuser.uflag2 |= FOREIGN; else diff --git a/pttbbs/sample/pttbbs.conf b/pttbbs/sample/pttbbs.conf index 8a09e6a0..73a324bd 100644 --- a/pttbbs/sample/pttbbs.conf +++ b/pttbbs/sample/pttbbs.conf @@ -42,7 +42,9 @@ /* 定義看板好友名單將會在幾秒鐘後失效強迫重載 */ #define HBFLexpire (432000) -/* 定義外國人最長居留時間,之後需向站方申請永久居留權 */ +/* 定義是否使用外籍使用者註冊 + 及外國人最長居留時間,之後需向站方申請永久居留權 */ +#define FOREIGN_REG #define FOREIGN_REG_DAY 30 /* 板主可以按大寫 H切換隱形與否 */ -- cgit v1.2.3 From 2c7f087f852c48722eb19091a428deb4981c5f52 Mon Sep 17 00:00:00 2001 From: victor Date: Sun, 11 May 2003 00:40:25 +0000 Subject: un-init var git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@836 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/admin.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pttbbs/mbbsd/admin.c b/pttbbs/mbbsd/admin.c index 5253a37c..8df3ef1b 100644 --- a/pttbbs/mbbsd/admin.c +++ b/pttbbs/mbbsd/admin.c @@ -1,4 +1,4 @@ -/* $Id: admin.c,v 1.36 2003/05/11 00:35:16 victor Exp $ */ +/* $Id: admin.c,v 1.37 2003/05/11 00:40:25 victor Exp $ */ #include "bbs.h" /* 使用者管理 */ @@ -824,9 +824,9 @@ scan_register_form(char *regfile, int automode, int neednum) prints(" %-12s:%s\n", finfo[0], fdata[0]); prints(" %-12s:%s\n", finfo[1], fdata[1]); #ifdef FOREIGN_REG - prints("1.%-12s:%s%s\n", finfo[n], fdata[n], muser.uflag2 & FOREIGN ? "外籍" : ""); + prints("1.%-12s:%s%s\n", finfo[2], fdata[2], muser.uflag2 & FOREIGN ? "外籍" : ""); #else - prints("1.%-12s:%s\n", finfo[n], fdata[n]); + prints("1.%-12s:%s\n", finfo[2], fdata[2]); #endif for (n = 3; field[n]; n++) { prints("%d.%-12s:%s\n", n - 2, finfo[n], fdata[n]); -- cgit v1.2.3 From 0c4734bacc69b31879c2d9bad771a80d940e7e0f Mon Sep 17 00:00:00 2001 From: victor Date: Sun, 11 May 2003 00:44:42 +0000 Subject: wrong index >< git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@837 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/admin.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pttbbs/mbbsd/admin.c b/pttbbs/mbbsd/admin.c index 8df3ef1b..7e6b39d9 100644 --- a/pttbbs/mbbsd/admin.c +++ b/pttbbs/mbbsd/admin.c @@ -1,4 +1,4 @@ -/* $Id: admin.c,v 1.37 2003/05/11 00:40:25 victor Exp $ */ +/* $Id: admin.c,v 1.38 2003/05/11 00:44:42 victor Exp $ */ #include "bbs.h" /* 使用者管理 */ @@ -824,9 +824,9 @@ scan_register_form(char *regfile, int automode, int neednum) prints(" %-12s:%s\n", finfo[0], fdata[0]); prints(" %-12s:%s\n", finfo[1], fdata[1]); #ifdef FOREIGN_REG - prints("1.%-12s:%s%s\n", finfo[2], fdata[2], muser.uflag2 & FOREIGN ? "外籍" : ""); + prints("0.%-12s:%s%s\n", finfo[2], fdata[2], muser.uflag2 & FOREIGN ? "外籍" : ""); #else - prints("1.%-12s:%s\n", finfo[2], fdata[2]); + prints("0.%-12s:%s\n", finfo[2], fdata[2]); #endif for (n = 3; field[n]; n++) { prints("%d.%-12s:%s\n", n - 2, finfo[n], fdata[n]); -- cgit v1.2.3 From 5bbabe2cf7a255d8637bac74a27f6e796ac3d9e5 Mon Sep 17 00:00:00 2001 From: victor Date: Sun, 11 May 2003 07:29:43 +0000 Subject: fix wrong var git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@838 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/user.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pttbbs/mbbsd/user.c b/pttbbs/mbbsd/user.c index 98c8eac1..de8cc761 100644 --- a/pttbbs/mbbsd/user.c +++ b/pttbbs/mbbsd/user.c @@ -1,4 +1,4 @@ -/* $Id: user.c,v 1.57 2003/05/11 00:35:16 victor Exp $ */ +/* $Id: user.c,v 1.58 2003/05/11 07:29:43 victor Exp $ */ #include "bbs.h" static char *sex[8] = { @@ -1168,9 +1168,9 @@ u_register(void) sethomefile(genbuf, cuser.userid, "justify.wait"); if ((fn = fopen(genbuf, "r"))) { fgets(phone, 21, fn); - if(strcmp(ident, "#foreign") == 0){ + if(strcmp(phone, "#foreign") == 0){ fore[0] = 'y'; fore[1] = '\n'; - fgets(ident, 21, fn); + fgets(phone, 21, fn); } phone[strlen(phone) - 1] = 0; fgets(career, 41, fn); -- cgit v1.2.3 From e9eb2371813eb0c65fa3bd773ed846478d0262be Mon Sep 17 00:00:00 2001 From: victor Date: Sun, 11 May 2003 13:19:01 +0000 Subject: change prompt git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@839 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/bbs.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pttbbs/mbbsd/bbs.c b/pttbbs/mbbsd/bbs.c index 6df7f4da..ce1ed173 100644 --- a/pttbbs/mbbsd/bbs.c +++ b/pttbbs/mbbsd/bbs.c @@ -1,4 +1,4 @@ -/* $Id: bbs.c,v 1.91 2003/05/09 15:06:22 victor Exp $ */ +/* $Id: bbs.c,v 1.92 2003/05/11 13:19:01 victor Exp $ */ #include "bbs.h" static int recommend(int ent, fileheader_t * fhdr, char *direct); @@ -1075,7 +1075,7 @@ hold_gamble(int ent, fileheader_t * fhdr, char *direct) } if (dashf(fn_ticket_end)) { getdata(b_lines - 1, 0, "已經有舉辦賭盤, " - "是否要 [開獎/取消]?(N/y):", yn, 3, LCECHO); + "是否要取消 [否/是]?(N/y):", yn, 3, LCECHO); if (yn[0] != 'y') return FULLUPDATE; openticket(currbid); -- cgit v1.2.3 From af342e629e8429ffc7c48e9953a237a7613f4de8 Mon Sep 17 00:00:00 2001 From: victor Date: Mon, 12 May 2003 04:06:35 +0000 Subject: stupid git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@840 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/user.c | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/pttbbs/mbbsd/user.c b/pttbbs/mbbsd/user.c index de8cc761..6ca5e408 100644 --- a/pttbbs/mbbsd/user.c +++ b/pttbbs/mbbsd/user.c @@ -1,4 +1,4 @@ -/* $Id: user.c,v 1.58 2003/05/11 07:29:43 victor Exp $ */ +/* $Id: user.c,v 1.59 2003/05/12 04:06:35 victor Exp $ */ #include "bbs.h" static char *sex[8] = { @@ -938,11 +938,7 @@ toregister(char *email, char *genbuf, char *phone, char *career, char fore, if (phone[0] != 0) { fn = fopen(buf, "w"); assert(fn); - fprintf(fn, "%s%s\n%s\n%s\n%s\n%s\n%s\n", -#ifdef FOREIGN_REG - fore & FOREIGN ? "#foreign\n" : -#endif - "", + fprintf(fn, "%s\n%s\n%s\n%s\n%s\n%s\n", phone, career, ident, rname, addr, mobile); fclose(fn); } @@ -1168,10 +1164,6 @@ u_register(void) sethomefile(genbuf, cuser.userid, "justify.wait"); if ((fn = fopen(genbuf, "r"))) { fgets(phone, 21, fn); - if(strcmp(phone, "#foreign") == 0){ - fore[0] = 'y'; fore[1] = '\n'; - fgets(phone, 21, fn); - } phone[strlen(phone) - 1] = 0; fgets(career, 41, fn); career[strlen(career) - 1] = 0; -- cgit v1.2.3 From fa881399c546080029ca906c907d415f6dcd6f8a Mon Sep 17 00:00:00 2001 From: victor Date: Mon, 12 May 2003 04:10:13 +0000 Subject: show git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@841 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/admin.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pttbbs/mbbsd/admin.c b/pttbbs/mbbsd/admin.c index 7e6b39d9..0dee134b 100644 --- a/pttbbs/mbbsd/admin.c +++ b/pttbbs/mbbsd/admin.c @@ -1,4 +1,4 @@ -/* $Id: admin.c,v 1.38 2003/05/11 00:44:42 victor Exp $ */ +/* $Id: admin.c,v 1.39 2003/05/12 04:10:13 victor Exp $ */ #include "bbs.h" /* 使用者管理 */ @@ -824,7 +824,7 @@ scan_register_form(char *regfile, int automode, int neednum) prints(" %-12s:%s\n", finfo[0], fdata[0]); prints(" %-12s:%s\n", finfo[1], fdata[1]); #ifdef FOREIGN_REG - prints("0.%-12s:%s%s\n", finfo[2], fdata[2], muser.uflag2 & FOREIGN ? "外籍" : ""); + prints("0.%-12s:%s%s\n", finfo[2], fdata[2], muser.uflag2 & FOREIGN ? " (外籍)" : ""); #else prints("0.%-12s:%s\n", finfo[2], fdata[2]); #endif -- cgit v1.2.3 From faa620d8accbd87ee629cb95c3e6ac81752f827e Mon Sep 17 00:00:00 2001 From: victor Date: Mon, 12 May 2003 12:47:18 +0000 Subject: rename git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@842 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/admin.c | 6 ++++-- pttbbs/mbbsd/mbbsd.c | 4 ++-- pttbbs/mbbsd/user.c | 4 +++- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/pttbbs/mbbsd/admin.c b/pttbbs/mbbsd/admin.c index 0dee134b..15659d31 100644 --- a/pttbbs/mbbsd/admin.c +++ b/pttbbs/mbbsd/admin.c @@ -1,4 +1,4 @@ -/* $Id: admin.c,v 1.39 2003/05/12 04:10:13 victor Exp $ */ +/* $Id: admin.c,v 1.40 2003/05/12 12:47:18 victor Exp $ */ #include "bbs.h" /* 使用者管理 */ @@ -524,7 +524,7 @@ x_file() fpath = "etc/feast"; break; case 'm': - fpath = "etc/foreign_expired"; + fpath = "etc/foreign_welcome"; break; case 'n': fpath = "etc/foreign_expired_warn"; @@ -935,6 +935,8 @@ scan_register_form(char *regfile, int automode, int neednum) default: prints("以下使用者資料已經更新:\n"); mail_muser(muser, "[註冊成功\囉]", "etc/registered"); + if(muser.uflag2 & FOREIGN) + mail_muser(muser, "[出入境管理局]", "etc/foreign_welcome"); muser.userlevel |= (PERM_LOGINOK | PERM_POST); strlcpy(muser.realname, fdata[2], sizeof(muser.realname)); strlcpy(muser.address, fdata[4], sizeof(muser.address)); diff --git a/pttbbs/mbbsd/mbbsd.c b/pttbbs/mbbsd/mbbsd.c index d52ffbcb..1aaf9900 100644 --- a/pttbbs/mbbsd/mbbsd.c +++ b/pttbbs/mbbsd/mbbsd.c @@ -1,4 +1,4 @@ -/* $Id: mbbsd.c,v 1.76 2003/05/11 00:35:16 victor Exp $ */ +/* $Id: mbbsd.c,v 1.77 2003/05/12 12:47:18 victor Exp $ */ #include "bbs.h" #define SOCKET_QLEN 4 @@ -891,7 +891,7 @@ user_login() } else if (login_start_time - cuser.firstlogin > FOREIGN_REG_DAY * 24 * 3600){ cuser.userlevel &= ~(PERM_LOGINOK | PERM_POST); - mail_muser(cuser, "[出入境管理局]", "etc/foreign_expired"); + vmsg("警告:請至出入境管理局申請永久居留"); } } #endif diff --git a/pttbbs/mbbsd/user.c b/pttbbs/mbbsd/user.c index 6ca5e408..5eac671d 100644 --- a/pttbbs/mbbsd/user.c +++ b/pttbbs/mbbsd/user.c @@ -1,4 +1,4 @@ -/* $Id: user.c,v 1.59 2003/05/12 04:06:35 victor Exp $ */ +/* $Id: user.c,v 1.60 2003/05/12 12:47:18 victor Exp $ */ #include "bbs.h" static char *sex[8] = { @@ -1198,6 +1198,8 @@ u_register(void) exit(0); } mail_muser(cuser, "[註冊成功\囉]", "etc/registeredmail"); + if(cuser.uflag2 & FOREIGN) + mail_muser(cuser, "[出入境管理局]", "etc/foreign_welcome"); cuser.userlevel |= (PERM_LOGINOK | PERM_POST); prints("\n註冊成功\, 重新上站後將取得完整權限\n" "請按下任一鍵跳離後重新上站~ :)"); -- cgit v1.2.3 From 9e955a9169e267d83b24128af0ef44920d7db667 Mon Sep 17 00:00:00 2001 From: in2 Date: Wed, 14 May 2003 08:20:11 +0000 Subject: add comments for userlist git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@843 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/talk.c | 71 ++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 51 insertions(+), 20 deletions(-) diff --git a/pttbbs/mbbsd/talk.c b/pttbbs/mbbsd/talk.c index 126d739f..9e734457 100644 --- a/pttbbs/mbbsd/talk.c +++ b/pttbbs/mbbsd/talk.c @@ -1,4 +1,4 @@ -/* $Id: talk.c,v 1.106 2003/04/17 14:20:41 victor Exp $ */ +/* $Id: talk.c,v 1.107 2003/05/14 08:20:11 in2 Exp $ */ #include "bbs.h" #define QCAST int (*)(const void *, const void *) @@ -1471,6 +1471,50 @@ descript(int show_mode, userinfo_t * uentp, time_t diff) } } +/* + * userlist + * + * 有別於其他大部份 bbs在實作使用者名單時, 都是將所有 online users 取一份到 + * local space 中, 按照所須要的方式 sort 好 (如按照 userid , 五子棋, 來源等 + * 等) . 這將造成大量的浪費: 為什麼每個人都要為了產生這一頁僅 20 個人的資料 + * 而去 sort 其他一萬人的資料? + * + * 一般來說, 一份完整的使用者名單可以分成「好友區」和「非好友區」. 不同人的 + * 「好友區」應該會長的不一樣, 不過「非好友區」應該是長的一樣的. 針對這項特 + * 性, 兩區有不同的實作方式. + * + * + 好友區 + * 好友區只有在排列方式為 [嗨! 朋友] 的時候「可能」會用到. + * 每個 process可以透過 currutmp->friend_online[]得到互相間有好友關係的資 + * 料 (不包括板友, 板友是另外生出來的) 不過 friend_online[]是 unorder的. + * 所以須要先把所有的人拿出來, 重新 sort 一次. + * 好友區 (互相任一方有設好友+ 板友) 最多只會有 MAX_FRIENDS個 + * + * + 非好友區 + * 透過 shmctl utmpsortd , 定期 (通常一秒一次) 將全站的人按照各種不同的方 + * 式 sort 好, 放置在 SHM->sorted中. + * + * 接下來, 我們每次只從確定的起始位置拿, 特別是除非有須要, 不然不會去產生好 + * 友區. + * + * 各個 function 摘要 + * sort_cmpfriend() sort function, key: friend type + * pickup_maxpages() # pages of userlist + * pickup_myfriend() 產生好友區 + * pickup_bfriend() 產生板友 + * pickup() 產生某一頁使用者名單 + * draw_pickup() 把畫面輸出 + * userlist() 主函式, 負責呼叫 pickup()/draw_pickup() 以及按鍵處理 + * + * SEE ALSO + * include/pttstruct.h + * + * BUGS + * 搜尋的時候沒有辦法移到該人上面 + * + * AUTHOR + * in2 + */ char nPickups; static int @@ -1527,8 +1571,9 @@ pickup_myfriend(pickup_t * friends, } } } + /* 把自己加入好友區 */ friends[ngets].ui = currutmp; - friends[ngets++].friend = 24; + friends[ngets++].friend = (IFH | HFM); return ngets; } @@ -1609,15 +1654,6 @@ pickup(pickup_t * currpickup, int pickup_way, int *page, } } } - /* - * for( which = (which >= 0 ? which : 0) ; got < nPickups && which - * < utmpnumber ; ++got, ++which ){ - * - * for( ; which < utmpnumber ; ++which ) if( currutmp != utmp[which] && - * isvisible_stat(currutmp, utmp[which], 0) ) break; if( which == - * utmpnumber ) break; currpickup[got].ui = utmp[which]; - * currpickup[got].friend = 0; } - */ for (; size < nPickups; ++size) currpickup[size].ui = 0; @@ -1776,12 +1812,6 @@ call_in(userinfo_t * uentp, int fri_stat) inline static void userlist(void) { - /* - * 使用者名單: userlist() : main loop draw_pickup() : show out - * screen pickup() : generate THIS PAGE pickup list - * pickup_maxpages : return max pages number of all list pickup_myfriend - * : pickup friend (from friend_online) and sort - */ pickup_t *currpickup; userinfo_t *uentp; static char show_mode = 0; @@ -1801,9 +1831,10 @@ userlist(void) leave = 0; redrawall = 1; /* - * redraw : 會離開鍵盤處理 loop , 重新 pickup, draw_pickup - * (只重畫中間使用者部份) redrawall : 會重畫所有的部份 (上面的標題列, - * 下面的說明列等等) leave : 返回上一選單 + * 各個 flag : + * redraw: 重新 pickup(), draw_pickup() (僅中間區, 不含標題列等等) + * redrawall: 全部重畫 (含標題列等等, 須再指定 redraw 才會有效) + * leave: 離開使用者名單 */ while (!leave) { pickup(currpickup, pickup_way, &page, -- cgit v1.2.3 From 303a4ffce7f830c3af3e40dca7e153f6de3c9fa7 Mon Sep 17 00:00:00 2001 From: in2 Date: Wed, 14 May 2003 08:31:29 +0000 Subject: =?UTF-8?q?s/=EF=BF=BDO=EF=BF=BD=5F=EF=BF=BDn=EF=BF=BD=EF=BF=BD?= =?UTF-8?q?=EF=BF=BD=EF=BF=BD/=EF=BF=BDO=EF=BF=BD=5F=EF=BF=BDn=EF=BF=BD}?= =?UTF-8?q?=EF=BF=BD=EF=BF=BD/?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@844 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/bbs.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pttbbs/mbbsd/bbs.c b/pttbbs/mbbsd/bbs.c index ce1ed173..bd0e82a4 100644 --- a/pttbbs/mbbsd/bbs.c +++ b/pttbbs/mbbsd/bbs.c @@ -1,4 +1,4 @@ -/* $Id: bbs.c,v 1.92 2003/05/11 13:19:01 victor Exp $ */ +/* $Id: bbs.c,v 1.93 2003/05/14 08:31:29 in2 Exp $ */ #include "bbs.h" static int recommend(int ent, fileheader_t * fhdr, char *direct); @@ -1075,7 +1075,7 @@ hold_gamble(int ent, fileheader_t * fhdr, char *direct) } if (dashf(fn_ticket_end)) { getdata(b_lines - 1, 0, "已經有舉辦賭盤, " - "是否要取消 [否/是]?(N/y):", yn, 3, LCECHO); + "是否要開獎 [否/是]?(N/y):", yn, 3, LCECHO); if (yn[0] != 'y') return FULLUPDATE; openticket(currbid); -- cgit v1.2.3 From 45e17fddc47c2b4862a192d478c0bfd7dda903cc Mon Sep 17 00:00:00 2001 From: in2 Date: Wed, 14 May 2003 09:46:19 +0000 Subject: =?UTF-8?q?lazily=20generate=20=EF=BF=BDn=EF=BF=BD=EF=BF=BD?= =?UTF-8?q?=EF=BF=BD=EF=BF=BD=20in=20userlist?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@845 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/talk.c | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/pttbbs/mbbsd/talk.c b/pttbbs/mbbsd/talk.c index 9e734457..273dd215 100644 --- a/pttbbs/mbbsd/talk.c +++ b/pttbbs/mbbsd/talk.c @@ -1,4 +1,4 @@ -/* $Id: talk.c,v 1.107 2003/05/14 08:20:11 in2 Exp $ */ +/* $Id: talk.c,v 1.108 2003/05/14 09:46:19 in2 Exp $ */ #include "bbs.h" #define QCAST int (*)(const void *, const void *) @@ -1489,6 +1489,7 @@ descript(int show_mode, userinfo_t * uentp, time_t diff) * 料 (不包括板友, 板友是另外生出來的) 不過 friend_online[]是 unorder的. * 所以須要先把所有的人拿出來, 重新 sort 一次. * 好友區 (互相任一方有設好友+ 板友) 最多只會有 MAX_FRIENDS個 + * 因為產生好友區的 cost 相當高, "能不產生就不要產生" * * + 非好友區 * 透過 shmctl utmpsortd , 定期 (通常一秒一次) 將全站的人按照各種不同的方 @@ -1610,13 +1611,19 @@ pickup(pickup_t * currpickup, int pickup_way, int *page, if (friendtotal == 0) *myfriend = *friendme = 1; - - if (cuser.uflag & FRIEND_FLAG || - (pickup_way == 0 && *page * nPickups < MAX_FRIEND)) { - /* - * [嗨! 朋友] mode. we need to pickup ALL friends (from currutmp - * friend_online), sort, and get pickup from right starting position - */ + + /* 產生好友區 */ + which = *page * nPickups; + if( (cuser.uflag & FRIEND_FLAG) || /* 只顯示好友模式 */ + ((pickup_way == 0) && /* [嗨! 朋友] mode */ + ( + /* 含板友, 好友區最多只會有 (friendtotal + 板友) 個*/ + (currutmp->brc_id && which < (friendtotal + + bcache[currutmp->brc_id-1].nuser)) || + + /* 不含板友, 最多只會有 friendtotal個 */ + (!currutmp->brc_id && which < friendtotal) + ))) { pickup_t friends[MAX_FRIEND]; *nfriend = pickup_myfriend(friends, myfriend, friendme, badfriend); @@ -1626,7 +1633,6 @@ pickup(pickup_t * currpickup, int pickup_way, int *page, else *bfriend = 0; *nfriend += *bfriend; - which = *page * nPickups; if (*nfriend > which) { /* 只有在要秀出才有必要 sort */ qsort(friends, *nfriend, sizeof(pickup_t), sort_cmpfriend); -- cgit v1.2.3 From bab93348f6a806cd88357fd980bafd77d87eea42 Mon Sep 17 00:00:00 2001 From: in2 Date: Thu, 15 May 2003 06:48:46 +0000 Subject: timed git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@846 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/shmctl.c | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/pttbbs/util/shmctl.c b/pttbbs/util/shmctl.c index ac9cb15b..0348c768 100644 --- a/pttbbs/util/shmctl.c +++ b/pttbbs/util/shmctl.c @@ -1,4 +1,4 @@ -/* $Id: shmctl.c,v 1.40 2003/05/07 03:35:07 bbs Exp $ */ +/* $Id: shmctl.c,v 1.41 2003/05/15 06:48:46 in2 Exp $ */ #include "bbs.h" #include @@ -275,9 +275,6 @@ int utmpsortd(int argc, char **argv) else{ while( 1 ){ int i; -#ifdef OUTTA_TIMER - SHM->GV2.e.now = time(NULL); -#endif for( i = 0 ; SHM->UTMPbusystate && i < 5 ; ++i ) usleep(300000); @@ -394,6 +391,22 @@ int listpid(int argc, char **argv) return 0; } +#ifdef OUTTA_TIMER +int timed(int argc, char **argv) +{ + pid_t pid; + if( (pid = fork()) < 0 ) + perror("fork()"); + if( pid != 0 ) + return 0; + while( 1 ){ + SHM->GV2.e.now = time(NULL); + sleep(1); + } +} +#endif + + struct { int (*func)(int, char **); char *cmd, *descript; @@ -407,6 +420,9 @@ struct { {showglobal, "showglobal", "show GLOBALVAR[]"}, {setglobal, "setglobal", "set GLOBALVAR[]"}, {listpid, "listpid", "list all pids of mbbsd"}, +#ifdef OUTTA_TIMER + {timed, "timed", "time daemon for OUTTA_TIMER"}, +#endif {NULL, NULL, NULL} }; int main(int argc, char **argv) -- cgit v1.2.3 From c11188d938ebd10003de94b29083c84ca21196fc Mon Sep 17 00:00:00 2001 From: in2 Date: Thu, 15 May 2003 08:20:05 +0000 Subject: use pttbbs.mk git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@847 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/Makefile | 53 +------------ pttbbs/pttbbs.mk | 52 +++++++++++++ pttbbs/util/Makefile | 200 +++++++++++--------------------------------------- 3 files changed, 95 insertions(+), 210 deletions(-) create mode 100644 pttbbs/pttbbs.mk diff --git a/pttbbs/mbbsd/Makefile b/pttbbs/mbbsd/Makefile index a3d17c64..c4c5c320 100644 --- a/pttbbs/mbbsd/Makefile +++ b/pttbbs/mbbsd/Makefile @@ -1,55 +1,6 @@ -# $Id: Makefile,v 1.24 2003/05/01 08:19:23 in2 Exp $ +# $Id: Makefile,v 1.25 2003/05/15 08:20:05 in2 Exp $ -# 訂義基本初值 -BBSHOME?= $(HOME) -BBSHOME?= /home/bbs -OSTYPE?= FreeBSD -CC?= gcc -PTT_CFLAGS= -Wall -pipe -DBBSHOME='"$(BBSHOME)"' -I../include -PTT_LDFLAGS= -pipe -Wall -PTT_LIBS= -lcrypt - -# 在 CFLAGS內加入定義 COMPILE_TIME -PTT_CFLAGS+= "-DCOMPILE_TIME=\"`date`\"" - -# 稍後再 enable assert() -PTT_CFLAGS+= -DNDEBUG - -# FreeBSD特有的環境 -CFLAGS_FreeBSD= -DHAVE_SETPROCTITLE -DFreeBSD -LDFLAGS_FreeBSD= -LIBS_FreeBSD= -lkvm - -# Linux特有的環境 -CFLAGS_linux= -DHAVE_DES_CRYPT -DLinux -LDFLAGS_linux= -pipe -Wall -LIBS_linux= - -# CFLAGS, LDFLAGS, LIBS 加入 OS 相關參數 -PTT_CFLAGS+= $(CFLAGS_$(OSTYPE)) -PTT_LDFLAGS+= $(LDFLAGS_$(OSTYPE)) -PTT_LIBS+= $(LIBS_$(OSTYPE)) - -# 若有定義 GDB或 DEBUG, 則加入 -g , 否則用 -O -.if defined(GDB) || defined(DEBUG) -CFLAGS= -g $(PTT_CFLAGS) -LDFLAGS= -g $(PTT_LDFLAGS) $(PTT_LIBS) -.else -CFLAGS+= -O2 -Os -fomit-frame-pointer -fstrength-reduce \ - -fthread-jumps -fexpensive-optimizations \ - $(PTT_CFLAGS) -LDFLAGS+= -O2 $(PTT_LDFLAGS) $(PTT_LIBS) -.endif - -# 若有定義 DEBUG, 則在 CFLAGS內定義 DEBUG -.if defined(DEBUG) -CFLAGS+= -DDEBUG -.endif - -# 若有定義 NO_FORK, 則在 CFLAGS內定義 NO_FORK -.if defined(NO_FORK) -CFLAGS+= -DNO_FORK -.endif +.include "../pttbbs.mk" PROG= mbbsd OBJS= admin.o announce.o args.o bbs.o board.o cache.o cal.o card.o\ diff --git a/pttbbs/pttbbs.mk b/pttbbs/pttbbs.mk new file mode 100644 index 00000000..a246651c --- /dev/null +++ b/pttbbs/pttbbs.mk @@ -0,0 +1,52 @@ +# $Id: pttbbs.mk,v 1.1 2003/05/15 08:20:05 in2 Exp $ +# 訂義基本初值 +BBSHOME?= $(HOME) +BBSHOME?= /home/bbs +OSTYPE?= FreeBSD +CC?= gcc +PTT_CFLAGS= -Wall -pipe -DBBSHOME='"$(BBSHOME)"' -I../include +PTT_LDFLAGS= -pipe -Wall +PTT_LIBS= -lcrypt + +# 在 CFLAGS內加入定義 COMPILE_TIME +PTT_CFLAGS+= "-DCOMPILE_TIME=\"`date`\"" + +# 稍後再 enable assert() +PTT_CFLAGS+= -DNDEBUG + +# FreeBSD特有的環境 +CFLAGS_FreeBSD= -DHAVE_SETPROCTITLE -DFreeBSD +LDFLAGS_FreeBSD= +LIBS_FreeBSD= -lkvm + +# Linux特有的環境 +CFLAGS_linux= -DHAVE_DES_CRYPT -DLinux +LDFLAGS_linux= -pipe -Wall +LIBS_linux= + +# CFLAGS, LDFLAGS, LIBS 加入 OS 相關參數 +PTT_CFLAGS+= $(CFLAGS_$(OSTYPE)) +PTT_LDFLAGS+= $(LDFLAGS_$(OSTYPE)) +PTT_LIBS+= $(LIBS_$(OSTYPE)) + +# 若有定義 GDB或 DEBUG, 則加入 -g , 否則用 -O +.if defined(GDB) || defined(DEBUG) +CFLAGS= -g $(PTT_CFLAGS) +LDFLAGS= -g $(PTT_LDFLAGS) $(PTT_LIBS) +.else +CFLAGS+= -O2 -Os -fomit-frame-pointer -fstrength-reduce \ + -fthread-jumps -fexpensive-optimizations \ + $(PTT_CFLAGS) +LDFLAGS+= -O2 $(PTT_LDFLAGS) $(PTT_LIBS) +.endif + +# 若有定義 DEBUG, 則在 CFLAGS內定義 DEBUG +.if defined(DEBUG) +CFLAGS+= -DDEBUG +.endif + +# 若有定義 NO_FORK, 則在 CFLAGS內定義 NO_FORK +.if defined(NO_FORK) +CFLAGS+= -DNO_FORK +.endif + diff --git a/pttbbs/util/Makefile b/pttbbs/util/Makefile index d94eb736..deecbd2b 100644 --- a/pttbbs/util/Makefile +++ b/pttbbs/util/Makefile @@ -1,172 +1,59 @@ -# $Id: Makefile,v 1.28 2003/04/05 13:09:03 in2 Exp $ +# $Id: Makefile,v 1.29 2003/05/15 08:20:05 in2 Exp $ -# 訂義基本初值 -BBSHOME?= $(HOME) -BBSHOME?= /home/bbs -OSTYPE?= FreeBSD -CC?= gcc -CFLAGS+= -Wall -pipe -DBBSHOME='"$(BBSHOME)"' -I../include -LDFLAGS+= -pipe -Wall -LIBS+= -lcrypt +.include "../pttbbs.mk" -# FreeBSD特有的環境 -CFLAGS_FreeBSD= -DHAVE_SETPROCTITLE -DFreeBSD -LDFLAGS_FreeBSD= -LIBS_FreeBSD= -lkvm +UTIL_OBJS= \ + util_cache.o util_record.o util_passwd.o -# Linux特有的環境 -CFLAGS_linux= -DHAVE_DES_CRYPT -DLinux -LDFLAGS_linux= -pipe -Wall -LIBS_linux= -lresolv +CPROG_WITH_UTIL= \ + bbsmail BM_money post poststat \ + jungo account birth deluserfile \ + expire mandex rmuid horoscope \ + openvice parse_news openticket topusr \ + indexuser yearsold toplazyBM toplazyBBM \ + reaper buildAnnounce inndBM shmctl -# CFLAGS, LDFLAGS, LIBS 加入 OS 相關參數 -CFLAGS+= $(CFLAGS_$(OSTYPE)) -LDFLAGS+= $(LDFLAGS_$(OSTYPE)) -LIBS+= $(LIBS_$(OSTYPE)) +CPROG_WITHOUT_UTIL= \ + shmsweep uhash_loader showboard antispam \ + countalldice webgrep bbsrf initbbs \ + userlist tunepasswd buildir merge_passwd \ + merge_board xchatd outmail -OBJS= util_cache.o util_record.o util_passwd.o +PROGS= ${UTIL_OBJS} ${CPROG_WITH_UTIL} ${CPROG_WITHOUT_UTIL} \ + BM_money.sh backpasswd.sh mailog.sh opendice.sh \ + openticket.sh stock.sh topsong.sh weather.sh \ + stock.perl weather.perl toplazyBM.sh toplazyBBM.sh \ + dailybackup.pl tarqueue.pl waterball.pl filtermail.pl \ + getbackup.pl udnnews.pl rebuildaloha.pl railway_wrapper.pl -CPROGS= bbsmail BM_money post account birth deluserfile expire mandex\ - horoscope openvice parse_news openticket topusr yearsold uhash_loader\ - poststat showboard antispam countalldice webgrep bbsrf\ - initbbs outmail xchatd userlist tunepasswd buildir reaper shmsweep\ - merge_passwd merge_board inndBM buildAnnounce rmuid \ - toplazyBM jungo toplazyBBM shmctl indexuser +all: ${CPROG_WITH_UTIL} ${CPROG_WITHOUT_UTIL} ${PROGS} -PROGS= $(CPROGS) BM_money.sh backpasswd.sh mailog.sh opendice.sh\ - openticket.sh stock.sh topsong.sh weather.sh stock.perl weather.perl\ - toplazyBM.sh toplazyBBM.sh dailybackup.pl tarqueue.pl waterball.pl \ - filtermail.pl getbackup.pl udnnews.pl rebuildaloha.pl railway_wrapper.pl - -.if ${OSTYPE} == "FreeBSD" -CPROGS += diskstat -.endif - -all: $(PROGS) - -bbsmail: bbsmail.c $(OBJS) - $(CC) $(CFLAGS) -o $@ $@.c $(OBJS) - -BM_money: BM_money.c $(OBJS) - $(CC) $(CFLAGS) -o $@ $@.c $(OBJS) - -post: post.c $(OBJS) - $(CC) $(CFLAGS) -o $@ $@.c $(OBJS) - -poststat: poststat.c $(OBJS) - $(CC) $(CFLAGS) -o $@ $@.c $(OBJS) - -jungo: jungo.c $(OBJS) - $(CC) $(CFLAGS) -o $@ $@.c $(OBJS) - -account: account.c $(OBJS) - $(CC) $(CFLAGS) -o $@ $@.c $(OBJS) - -birth: birth.c $(OBJS) - $(CC) $(CFLAGS) -o $@ $@.c $(OBJS) - -deluserfile: deluserfile.c $(OBJS) - $(CC) $(CFLAGS) -o $@ $@.c $(OBJS) - -expire: expire.c $(OBJS) - $(CC) $(CFLAGS) -o $@ $@.c $(OBJS) - -mandex: mandex.c $(OBJS) - $(CC) $(CFLAGS) -o $@ $@.c $(OBJS) - -rmuid: rmuid.c $(OBJS) - $(CC) $(CFLAGS) -o $@ $@.c $(OBJS) - -horoscope: horoscope.c $(OBJS) - $(CC) $(CFLAGS) -o $@ $@.c $(OBJS) - -openvice: openvice.c $(OBJS) - $(CC) $(CFLAGS) -o $@ $@.c $(OBJS) - -parse_news: parse_news.c $(OBJS) - $(CC) $(CFLAGS) -o $@ $@.c $(OBJS) - -openticket: openticket.c $(OBJS) - $(CC) $(CFLAGS) -o $@ $@.c $(OBJS) - -topusr: topusr.c $(OBJS) - $(CC) $(CFLAGS) -o $@ $@.c $(OBJS) - -indexuser: indexuser.c $(OBJS) - $(CC) $(CFLAGS) -o $@ $@.c $(OBJS) - -yearsold: yearsold.c $(OBJS) - $(CC) $(CFLAGS) -o $@ $@.c $(OBJS) +.for fn in ${CPROG_WITH_UTIL} +${fn}: ${fn}.c ${UTIL_OBJS} + ${CC} ${CFLAGS} -o ${fn} ${fn}.c ${UTIL_OBJS} +.endfor xchatd: xchatd.c $(OBJS) descrypt.c $(CC) $(CFLAGS) -o $@ $@.c $(OBJS) descrypt.c $(LIBCHAT) -toplazyBM: toplazyBM.c $(OBJS) - $(CC) $(CFLAGS) -o $@ $@.c $(OBJS) - -toplazyBBM: toplazyBBM.c $(OBJS) - $(CC) $(CFLAGS) -o $@ $@.c $(OBJS) - -smtest: smtest.c $(OBJS) - $(CC) $(CFLAGS) -o $@ $@.c $(OBJS) - -reaper: reaper.c $(OBJS) - $(CC) $(CFLAGS) -o $@ $@.c $(OBJS) - -buildAnnounce: buildAnnounce.c $(OBJS) - $(CC) $(CFLAGS) -o $@ $@.c $(OBJS) - -inndBM: inndBM.c $(OBJS) - $(CC) $(CFLAGS) -o $@ $@.c $(OBJS) - -shmsweep: shmsweep.c - $(CC) $(CFLAGS) -o $@ $@.c - -uhash_loader: uhash_loader.c - $(CC) $(CFLAGS) -o $@ $@.c - -showboard: showboard.c - $(CC) $(CFLAGS) -o $@ $@.c - -antispam: antispam.c - $(CC) $(CFLAGS) -o $@ $@.c - -countalldice: countalldice.c - $(CC) $(CFLAGS) -o $@ $@.c - -webgrep: webgrep.c - $(CC) $(CFLAGS) -o $@ $@.c - -bbsrf: bbsrf.c - $(CC) $(CFLAGS) -o $@ $@.c - -initbbs: initbbs.c - $(CC) $(CFLAGS) -o $@ $@.c - outmail: outmail.c $(CC) $(CFLAGS) -o $@ $@.c $(LIBMAIL) -userlist: userlist.c - $(CC) $(CFLAGS) -o $@ $@.c - -tunepasswd: tunepasswd.c - $(CC) $(CFLAGS) -o $@ $@.c - -buildir: buildir.c - $(CC) $(CFLAGS) -o $@ $@.c - -merge_passwd: merge_passwd.c - $(CC) $(CFLAGS) -o $@ $@.c +install: $(PROGS) + install -d $(BBSHOME)/bin/ + install -c -m 755 $(PROGS) $(BBSHOME)/bin/ + chmod 4755 $(BBSHOME)/bin/post -merge_board : merge_board.c - $(CC) $(CFLAGS) -o $@ $@.c +clean: + rm -f *.o $(CPROGS) $(CPROG_WITH_UTIL) $(CPROG_WITHOUT_UTIL) -bbsctl: bbsctl.c - $(CC) $(CFLAGS) -o $@ $@.c -shmctl: shmctl.c $(OBJS) - $(CC) $(CFLAGS) -o $@ $@.c $(OBJS) +installfiltermail: + mv $(BBSHOME)/bin/bbsmail $(BBSHOME)/bin/realbbsmail + ln -s $(BBSHOME)/bin/filtermail.pl $(BBSHOME)/bin/bbsmail +# for diskstat(FreeBSD 4.x only) . +# diskstat should be compiled with bbs and installed with root diskstat: diskstat.c $(CC) $(CFLAGS) -o diskstat diskstat.c -ldevstat -lkvm @@ -175,12 +62,9 @@ installdiskstat: diskstat chgrp kmem /usr/local/bin/diskstat chmod 2755 /usr/local/bin/diskstat -install: $(PROGS) - install -d $(BBSHOME)/bin/ - install -c -m 755 $(PROGS) $(BBSHOME)/bin/ - chmod 4755 $(BBSHOME)/bin/post - #mv $(BBSHOME)/bin/bbsmail $(BBSHOME)/bin/realbbsmail - #ln -s $(BBSHOME)/bin/filtermail.pl $(BBSHOME)/bin/bbsmail +# for bbsctl. bbsctl should be compiled with bbs and installed with root +bbsctl: bbsctl.c + $(CC) $(CFLAGS) -o $@ $@.c installbbsctl: bbsctl rm -f /home/bbs/bin/bbsctl @@ -188,5 +72,3 @@ installbbsctl: bbsctl chown root /home/bbs/bin/bbsctl chmod 4755 /home/bbs/bin/bbsctl -clean: - rm -f *.o $(CPROGS) -- cgit v1.2.3 From 7feefec57ac0571c2c68995244b08c172f4eb726 Mon Sep 17 00:00:00 2001 From: in2 Date: Thu, 15 May 2003 08:20:37 +0000 Subject: remove smtest git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@848 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/smtest.c | 289 --------------------------------------------- pttbbs/util/smtest.c.save | 172 --------------------------- pttbbs/util/smtest.result1 | 191 ------------------------------ pttbbs/util/smtest.result2 | 3 - pttbbs/util/smtest.temp | 231 ------------------------------------ 5 files changed, 886 deletions(-) delete mode 100644 pttbbs/util/smtest.c delete mode 100644 pttbbs/util/smtest.c.save delete mode 100644 pttbbs/util/smtest.result1 delete mode 100644 pttbbs/util/smtest.result2 delete mode 100644 pttbbs/util/smtest.temp diff --git a/pttbbs/util/smtest.c b/pttbbs/util/smtest.c deleted file mode 100644 index e46157f2..00000000 --- a/pttbbs/util/smtest.c +++ /dev/null @@ -1,289 +0,0 @@ -/* $Id: smtest.c,v 1.5 2002/06/19 13:38:01 lwms Exp $ */ -#include "bbs.h" - -#define WARNFILE BBSHOME "/etc/DeleteBoard.warn" -#define EXECFILE BBSHOME"/etc/DeleteBoard.exec" -#define WARNLIST BBSHOME"/etc/DeleteBoardList.warn" -#define EXECLIST BBSHOME"/etc/DeleteBoardList.exec" - -extern boardheader_t *bcache; -extern int numboards; - -boardheader_t allbrd[MAX_BOARD]; -extern userec_t xuser; - - -int LINK(char* src, char* dst){ - char cmd[200]; - - if( link(src, dst) == 0){ - return 0; - } - - sprintf(cmd, "/bin/cp -R %s %s", src, dst); - return system(cmd); -} - -int outofdate(char *hdrdate, char thedate[], int *zf) -{ - int k = 0; - char *dd; - char latestdate[6]; - int date1[2], date2[2],datetemp; - *zf = 0; - - strcpy(latestdate, thedate); - - dd = strtok(hdrdate,"/"); - if(dd == NULL) return 2; - if(dd) - k = 0; - do{ - if (*dd == '[' ){dd[strlen(dd)-1]='\0'; dd++;} - date1[k] = atoi(dd); - k++; - } while((dd=strtok(NULL,"/ "))!=NULL); - - dd = strtok(latestdate,"/"); - if(dd) - k = 0; - do{ - if (*dd == '[' ){dd[strlen(dd)-1]='\0'; dd++;} - date2[k] = atoi(dd); - k++; - } while((dd=strtok(NULL,"/ "))!=NULL); - - if(date2[0] == date1[0] && date2[1] >= date1[1]) - return 0; - - datetemp = date2[0]; - - for(k = 1;k <= 5;k++) - { - datetemp -= 1; - if((datetemp) <= 0){ - datetemp = 12; - } - if(k < 3 && datetemp == date1[0]) return 0; - if(k == 3 && datetemp == date1[0] && date2[1] <= date1[1]) return 0; - if(k == 3 && datetemp == date1[0] && date2[1] > date1[1]) return 1; - if(k == 4 && datetemp == date1[0] && date2[1] > date1[1]) return 1; - } - *zf = 1; - return 1; -} - -void mailtouser(char *bmname, char *bname, int zf) -{ - fileheader_t mymail; - char genbuf[200]; - - sprintf(genbuf, BBSHOME "/home/%c/%s", bmname[0], bmname); - stampfile(genbuf, &mymail); - strcpy(mymail.owner, "[PTT警察局]"); - - if(zf == 0){ - sprintf(mymail.title,"\033[32m [廢板警告通知]" - "\033[m %s板(BM:%s)",bname, bmname); - }else{ - sprintf(mymail.title,"\033[32m [廢板通知] " - "\033[m %s板(BM:%s)",bname, bmname); - } - unlink(genbuf); - if(zf == 0){ - LINK(WARNFILE, genbuf); - }else{ - LINK(EXECFILE, genbuf); - } - - sprintf(genbuf, BBSHOME "/home/%c/%s/.DIR", bmname[0], bmname); - append_record(genbuf, &mymail, sizeof(mymail)); -} - -int main() -{ - int bmid, i, j, k, rd, ood, flag, zapflag = 0,warncount = 0,execcount = 0; - char *p, *bmsname[3], fname[256], hdrdatetemp[6],thedate[6]; - char bname[32],genbuf[200]; - fileheader_t hdr; - FILE *inf, *def; - - ///// set date ////// - time_t t = time(NULL); - struct tm *tm = localtime(&t); - sprintf(thedate, "%2d/%02d", tm->tm_mon + 1, tm->tm_mday); - - ////// board ////// - - resolve_boards(); - if(passwd_mmap()) - exit(1); - memcpy(allbrd,bcache,numboards*sizeof(boardheader_t)); - - ////// write out the target file ////// - inf = fopen(WARNLIST, "w+"); - if(inf == NULL){ - printf("open file error : %s\n", WARNLIST); - exit(1); - } - - def = fopen(EXECLIST, "w+"); - if(def == NULL) - { - printf("open file error : %s\n", EXECLIST); - exit(1); - } - - ////// fprint table title ///// - fprintf(inf,"\n[廢板警告]即日起一個月內若看板" - "使用率仍然過低,則予以廢除。\n\n" - "英文板名 類別 中文板名 日期 " - " 板主名單\n\n"); - - fprintf(def,"\n[廢板公告]下列看板因使用率仍然過低,故予以廢除。\n\n" - "英文板名 類別 中文板名 日期 " - " 板主名單\n\n"); - - ////// start process ///// - j = 0 ; - for (i = 0; i < numboards; i++) { - rd = 0; - if(allbrd[i].brdname[0] == '\0') continue; - if((allbrd[i].brdattr & BRD_NOZAP) || - (allbrd[i].brdattr & BRD_GROUPBOARD) || - (allbrd[i].brdattr & BRD_WARNDEL) || - (allbrd[i].brdattr & BRD_HIDE) || - (allbrd[i].brdattr & BRD_POSTMASK) || - (allbrd[i].brdattr & BRD_VOTEBOARD) || - (allbrd[i].brdattr & BRD_BAD) || - (allbrd[i].level != 0)) continue; - - sprintf(fname, BBSHOME "/boards/%c/%s/.DIR", allbrd[i].brdname[0], allbrd[i].brdname); - - /* get date to choose junk board */ - /* exception when ood == 2 */ - flag = 30; - rd = get_num_records(fname, sizeof(fileheader_t)); - if(rd <= 30) - { - get_record(fname, &hdr, sizeof (hdr), 1); - strcpy(hdrdatetemp, hdr.date); - ood = outofdate(hdrdatetemp,thedate, &zapflag); - } - else - { - do{ - if(rd == 0) - { - ood = 0; - break; - } - get_record(fname, &hdr, sizeof (hdr), rd - flag); - strcpy(hdrdatetemp, hdr.date); - ood = outofdate(hdrdatetemp,thedate, &zapflag); - flag += 5; - }while(ood == 2 && flag < 60); - } - if(ood == 0) continue; - - warncount++; - /* print to file */ - fprintf(inf,"%-*.*s%-*.*s %-*.*s%-*.*s\n", IDLEN, IDLEN, - allbrd[i].brdname, BTLEN-26, BTLEN-26, allbrd[i].title, - IDLEN - 5, IDLEN-5,hdr.date, IDLEN * 3, IDLEN * 3, allbrd[i].BM); - - /* post warn file to each board */ - sprintf(genbuf,"~/bin/post %s [廢板警告通知]" - " [PTT警察局] %s",allbrd[i].brdname,WARNFILE); - system(genbuf); - - /* user extract to mail */ - p=strtok(allbrd[i].BM,"/ "); - if(p){ - k = 0; - do - { - if (*p == '[' ){p[strlen(p)-1]='\0'; p++;} - bmid=getuser(p); - bmsname[k] = p; - if(isalpha(allbrd[i].BM[0])&& !(xuser.userlevel &PERM_SYSOP)) - { - mailtouser(bmsname[k],allbrd[i].title, zapflag); - } - k++; - } while((p=strtok(NULL,"/ "))!=NULL); - } - /* set attribute of DeleteBoardWarn Flag */ - bcache[i].brdattr = allbrd[i].brdattr | BRD_WARNDEL; - - /* zap boards */ - if (zapflag == 1) - { - execcount++; - /* print to file */ - fprintf(def,"%-*.*s%-*.*s %-*.*s%-*.*s\n", IDLEN, IDLEN, - allbrd[i].brdname, BTLEN-26, BTLEN-26, allbrd[i].title, - IDLEN - 5, IDLEN-5,hdr.date, IDLEN * 3, IDLEN * 3, allbrd[i].BM); - - /* if you want to unmark these code, - make sure board, man path have changed to [man/]boards//brdname - */ - -// strcpy(bname, allbrd[i].brdname); -// sprintf(genbuf, -// "/bin/tar zcvf ~/tmp/board_%s.tgz boards/%s man/%s>/dev/null 2>&1;" -// "/bin/rm -fr ~/boards/%s man/%s",bname, bname, bname, bname,bname); -// system(genbuf); - -// memset(&allbrd[i], 0, sizeof(allbrd[i])); -// sprintf(allbrd[i].title, "[%s] deleted by System", bname); -// substitute_record(fn_board, &bh, sizeof(allbrd[i]), bid); -// reset_board(bid); - } - - } - - /* post to Record, ViolateLaw */ - if(warncount > 0){ - sprintf(genbuf,"~/bin/post Record [廢板警告通知]" - " [PTT警察局] %s",WARNLIST); - system(genbuf); - sprintf(genbuf,"~/bin/post ViolateLaw [廢板警告通知]" - " [PTT警察局] %s",WARNLIST); - system(genbuf); - } - if(execcount > 0){ - sprintf(genbuf,"~/bin/post Record [廢板公告]" - " [PTT警察局] %s",EXECLIST); - system(genbuf); - sprintf(genbuf,"~/bin/post ViolateLaw [廢板公告]" - " [PTT警察局] %s",EXECLIST); - system(genbuf); - } - - -/* Below is for test only */ -/* - mailtouser("Smile","test", 1); - mailtouser("Smile","test", 0); - - strcpy(bname, "Test"); - sprintf(genbuf,"~/bin/post %s test Smile ~/etc/test.fileaaa",bname); - system(genbuf); - - - bid = getbnum(bname); - strcpy(bname,"jourslamdunk"); - sprintf(genbuf, - "/bin/tar zcvf ~/tmp/board_%s.tgz boards/%c/%s man/%c/%s>/dev/null 2>&1;" - "/bin/rm -fr ~/boards/%c/%s man/%c/%s", - bname, bname[0], bname, bname[0], bname, bname[0], bname, bname[0], bname); - system(genbuf); - - memset(&bh, 0, sizeof(bh)); - sprintf(bh.title, "[%s] deleted by %s", bname,cuser.userid); - substitute_record(fn_board, &bh, sizeof(bh), bid); - reset_board(bid); -*/ - return 0; -} diff --git a/pttbbs/util/smtest.c.save b/pttbbs/util/smtest.c.save deleted file mode 100644 index 7e678881..00000000 --- a/pttbbs/util/smtest.c.save +++ /dev/null @@ -1,172 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include "config.h" -#include "pttstruct.h" -#include "util.h" -#include "perm.h" -#include "common.h" -#include "proto.h" - -#define OUTFILE BBSHOME "/pttbbs/util/smtest.result1" -#define FIREFILE BBSHOME "/pttbbs/util/smtest.result2" - -extern boardheader_t *bcache; -extern int numboards; - -boardheader_t allbrd[MAX_BOARD]; -struct userec_t xuser; - -int getuser(char *userid) { - int uid; - if((uid = searchuser(userid))) - passwd_query(uid, &xuser); - return uid; -} - -int LINK(char* src, char* dst){ - char cmd[200]; - - if( link(src, dst) == 0){ - return 0; - } - - sprintf(cmd, "/bin/cp -R %s %s", src, dst); - return system(cmd); -} - -int main() -{ - int bmid, i, j, k, rd; - char *p, *bmsname[3], bmbuf[IDLEN * 3 + 3], fname[256]; - fileheader_t hdr; - FILE *inf; - - resolve_boards(); - if(passwd_mmap()) - exit(1); - memcpy(allbrd,bcache,numboards*sizeof(boardheader_t)); - - /* write out the target file */ - inf = fopen(OUTFILE, "w+"); - if(inf == NULL){ - printf("open file error : %s\n", OUTFILE); - exit(1); - } - - /*the ouput table title*/ - fprintf(inf,"英文版名 類別 中文版名 版主名單" - " 日期 備註 \n"); - - j = 0 ; - for (i = 0; i < 30; i++) { - rd = 0; - if(allbrd[i].brdname[0] == '\0') continue; - - sprintf(fname, BBSHOME "/boards/%s/.DIR",allbrd[i].brdname); - - rd = get_num_records(fname, sizeof(fileheader_t)); - get_record(fname, &hdr, sizeof (hdr), rd - 30); -// printf(" %s %s\n",hdr.title,hdr.date); - - printf("%-*.*s%-*s%s", IDLEN, IDLEN, allbrd[i].brdname, BTLEN, - allbrd[i].title,allbrd[i].BM); - - p=strtok(allbrd[i].BM,"/ "); - if(p){ - int k = 0; - do - { - if (*p == '[' ){p[strlen(p)-1]='\0'; p++;} - bmid=getuser(p); - bmsname[k] = p; - if(isalpha(allbrd[i].BM[0])&& !(xuser.userlevel &PERM_SYSOP)) - { - // printf("%s", bmsname[k]); - } - k++; - } while((p=strtok(NULL,"/ "))!=NULL); - } - - printf("\n"); - -} - - -/* - - - - if(flag == 1){ - bmbuf[0] = '\0'; - for(k = 0 , n = 0; k < index; k++){ - if(!bms[k].flag){ - if( n++ != 0) strcat(bmbuf, "/"); - strcat(bmbuf, bms[k].bmname); - } - } - strcpy(bcache[i].BM, bmbuf); - } - } - qsort(lostbms, j, sizeof(lostbm), bmlostdays_cmp); - - //write to the etc/toplazyBM - for ( i=0; i 60){ - fprintf(firef, "%-*.*s%-*.*s%-*.*s%3d天沒上站\n", IDLEN, IDLEN, - lostbms[i].title, BTLEN-10, BTLEN-10, lostbms[i].ctitle, IDLEN,IDLEN, - lostbms[i].bmname,lostbms[i].lostdays); - }else{ - fprintf(inf, "%-*.*s%-*.*s%-*.*s%3d天沒上站\n", IDLEN, IDLEN, lostbms[i].title, - BTLEN-10, BTLEN-10, lostbms[i].ctitle, IDLEN,IDLEN, - lostbms[i].bmname,lostbms[i].lostdays); - } - } - fclose(inf); - fclose(firef); - - //printf("Total %d boards.\n", count); - - //mail to the users - for( i=0; i -#include -#include -#include -#include -#include -#include -#include "config.h" -#include "pttstruct.h" -#include "util.h" -#include "perm.h" -#include "common.h" -#include "proto.h" - -#define OUTFILE BBSHOME "/pttbbs/util/smtest.result1" -#define FIREFILE BBSHOME "/pttbbs/util/smtest.result2" - -extern boardheader_t *bcache; -extern int numboards; - -boardheader_t allbrd[MAX_BOARD]; -struct userec_t xuser; - -int getuser(char *userid) { - int uid; - if((uid = searchuser(userid))) - passwd_query(uid, &xuser); - return uid; -} - -int LINK(char* src, char* dst){ - char cmd[200]; - - if( link(src, dst) == 0){ - return 0; - } - - sprintf(cmd, "/bin/cp -R %s %s", src, dst); - return system(cmd); -} - -int outofdate(char *hdrdate, char latestdate[]) -{ - int k,rr; - char *dd; - - dd = strtok(hdrdate,"/"); - - if(dd){ - k = 0; - do - { - if (*dd == '[' ){dd[strlen(dd)-1]='\0'; dd++;} - rr = atoi(dd); - printf("%d/", rr); - } while((dd = strtok(NULL,"/")) != NULL); - } - - printf("\n"); - - if(1) - return 1; - else - return 0; -} - -int main() -{ - int bmid, i, j, k, rd,rr; - char *p, *bmsname[3], fname[256], *dd; - fileheader_t hdr; - FILE *inf; - - /* set date */ - char thedate[5]; - time_t t = time(NULL); - struct tm *tm = localtime(&t); - - sprintf(thedate, "%2d/%02d", tm->tm_mon + 1, tm->tm_mday); - - resolve_boards(); - if(passwd_mmap()) - exit(1); - memcpy(allbrd,bcache,numboards*sizeof(boardheader_t)); - /* write out the target file */ - inf = fopen(OUTFILE, "w+"); - if(inf == NULL){ - printf("open file error : %s\n", OUTFILE); - exit(1); - } - - /*the ouput table title*/ - fprintf(inf,"英文版名 類別 中文版名 版主名單" - " 日期 備註 \n"); - - j = 0 ; - for (i = 0; i < 30; i++) { - rd = 0; - if(allbrd[i].brdname[0] == '\0') continue; - if((allbrd[i].brdattr & BRD_NOZAP) == 1) continue; - - sprintf(fname, BBSHOME "/boards/%s/.DIR",allbrd[i].brdname); - - /* get date to choose junk board */ - - rd = get_num_records(fname, sizeof(fileheader_t)); - get_record(fname, &hdr, sizeof (hdr), rd - 30); - - - if(outofdate(hdr.date,thedate)) printf("yest\n"); - -/* - dd = strtok(hdr.date,"/"); - - if(dd){ - k = 0; - do - { - if (*dd == '[' ){dd[strlen(dd)-1]='\0'; dd++;} - rr = atoi(dd); - printf("%d/", rr); - - } while((dd = strtok(NULL,"/")) != NULL); - } - printf("\n"); -*/ - /* print to file */ - printf("%-*.*s%-*.*s%-*.*s%-*.*s", IDLEN, IDLEN, allbrd[i].brdname, - BTLEN-24, BTLEN-26, allbrd[i].title, IDLEN - 5, IDLEN-5,hdr.date, - IDLEN * 3, IDLEN * 3, allbrd[i].BM); - - /* post to board */ - - - - /* user extract to mail */ - - p=strtok(allbrd[i].BM,"/ "); - if(p){ - k = 0; - do - { - if (*p == '[' ){p[strlen(p)-1]='\0'; p++;} - bmid=getuser(p); - bmsname[k] = p; - if(isalpha(allbrd[i].BM[0])&& !(xuser.userlevel &PERM_SYSOP)) - { - // printf("%s", bmsname[k]); - } - k++; - } while((p=strtok(NULL,"/ "))!=NULL); - } - - printf("\n"); - -} - - -/* - - - - if(flag == 1){ - bmbuf[0] = '\0'; - for(k = 0 , n = 0; k < index; k++){ - if(!bms[k].flag){ - if( n++ != 0) strcat(bmbuf, "/"); - strcat(bmbuf, bms[k].bmname); - } - } - strcpy(bcache[i].BM, bmbuf); - } - } - qsort(lostbms, j, sizeof(lostbm), bmlostdays_cmp); - - //write to the etc/toplazyBM - for ( i=0; i 60){ - fprintf(firef, "%-*.*s%-*.*s%-*.*s%3d天沒上站\n", IDLEN, IDLEN, lostbms[i].title, - BTLEN-10, BTLEN-10, lostbms[i].ctitle, IDLEN,IDLEN, - lostbms[i].bmname,lostbms[i].lostdays); - }else{ - fprintf(inf, "%-*.*s%-*.*s%-*.*s%3d天沒上站\n", IDLEN, IDLEN, lostbms[i].title, - BTLEN-10, BTLEN-10, lostbms[i].ctitle, IDLEN,IDLEN, - lostbms[i].bmname,lostbms[i].lostdays); - } - } - fclose(inf); - fclose(firef); - - //printf("Total %d boards.\n", count); - - //mail to the users - for( i=0; i Date: Thu, 15 May 2003 08:22:44 +0000 Subject: fix xchatd rule git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@849 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/Makefile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pttbbs/util/Makefile b/pttbbs/util/Makefile index deecbd2b..60dc2871 100644 --- a/pttbbs/util/Makefile +++ b/pttbbs/util/Makefile @@ -1,4 +1,4 @@ -# $Id: Makefile,v 1.29 2003/05/15 08:20:05 in2 Exp $ +# $Id: Makefile,v 1.30 2003/05/15 08:22:44 in2 Exp $ .include "../pttbbs.mk" @@ -33,8 +33,8 @@ ${fn}: ${fn}.c ${UTIL_OBJS} ${CC} ${CFLAGS} -o ${fn} ${fn}.c ${UTIL_OBJS} .endfor -xchatd: xchatd.c $(OBJS) descrypt.c - $(CC) $(CFLAGS) -o $@ $@.c $(OBJS) descrypt.c $(LIBCHAT) +xchatd: xchatd.c $(UTIL_OBJS) descrypt.c + $(CC) $(CFLAGS) -o $@ $@.c $(UTIL_OBJS) descrypt.c $(LIBCHAT) outmail: outmail.c $(CC) $(CFLAGS) -o $@ $@.c $(LIBMAIL) -- cgit v1.2.3 From 33eaca262a5a2ea400139d46ea6f366a0a902d7f Mon Sep 17 00:00:00 2001 From: in2 Date: Thu, 15 May 2003 08:27:23 +0000 Subject: warning free git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@850 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/mandex.c | 4 ++-- pttbbs/util/uhash_loader.c | 4 +++- pttbbs/util/util_passwd.c | 3 ++- pttbbs/util/util_record.c | 4 ++-- 4 files changed, 9 insertions(+), 6 deletions(-) diff --git a/pttbbs/util/mandex.c b/pttbbs/util/mandex.c index 1ca9494c..6088bc75 100644 --- a/pttbbs/util/mandex.c +++ b/pttbbs/util/mandex.c @@ -1,4 +1,4 @@ -/* $Id: mandex.c,v 1.8 2002/08/12 15:04:01 kcwu Exp $ */ +/* $Id: mandex.c,v 1.9 2003/05/15 08:27:23 in2 Exp $ */ /* 'mandex -h' to help */ @@ -154,7 +154,7 @@ mandex(level, num_header, fpath) int main(int argc, char* argv[]) { - boardheader_t *bptr; + boardheader_t *bptr = NULL; DIR *dirp; struct dirent *de; int ch, n, place = 0, fd, i; diff --git a/pttbbs/util/uhash_loader.c b/pttbbs/util/uhash_loader.c index 5fadd48e..7d066ab9 100644 --- a/pttbbs/util/uhash_loader.c +++ b/pttbbs/util/uhash_loader.c @@ -1,6 +1,8 @@ -/* $Id: uhash_loader.c,v 1.3 2002/06/06 21:34:14 in2 Exp $ */ +/* $Id: uhash_loader.c,v 1.4 2003/05/15 08:27:23 in2 Exp $ */ /* standalone uhash loader -- jochang */ #include +#include +#include #include #include #include diff --git a/pttbbs/util/util_passwd.c b/pttbbs/util/util_passwd.c index 17961d87..d7f1cea2 100644 --- a/pttbbs/util/util_passwd.c +++ b/pttbbs/util/util_passwd.c @@ -1,5 +1,6 @@ -/* $Id: util_passwd.c,v 1.3 2002/11/02 11:02:44 in2 Exp $ */ +/* $Id: util_passwd.c,v 1.4 2003/05/15 08:27:23 in2 Exp $ */ #include +#include #include #include #include diff --git a/pttbbs/util/util_record.c b/pttbbs/util/util_record.c index 98b6e43f..80a7ff56 100644 --- a/pttbbs/util/util_record.c +++ b/pttbbs/util/util_record.c @@ -1,4 +1,4 @@ -/* $Id: util_record.c,v 1.3 2002/11/02 11:02:44 in2 Exp $ */ +/* $Id: util_record.c,v 1.4 2003/05/15 08:27:23 in2 Exp $ */ #include #include #include @@ -135,7 +135,7 @@ int apply_record(char *fpath, int (*fptr)(), int size) { if(!(fp = fopen(fpath, "r"))) return -1; - while(fread(abuf, 1, size, fp) == size) + while(fread(abuf, 1, size, fp) == (unsigned)size) if((*fptr) (abuf) == QUIT) { fclose(fp); return QUIT; -- cgit v1.2.3 From fefd820c94eb4c2843d02c64a2ea5f847b633697 Mon Sep 17 00:00:00 2001 From: in2 Date: Thu, 15 May 2003 08:28:59 +0000 Subject: add comments git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@851 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/Makefile | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pttbbs/util/Makefile b/pttbbs/util/Makefile index 60dc2871..090f7217 100644 --- a/pttbbs/util/Makefile +++ b/pttbbs/util/Makefile @@ -1,10 +1,11 @@ -# $Id: Makefile,v 1.30 2003/05/15 08:22:44 in2 Exp $ +# $Id: Makefile,v 1.31 2003/05/15 08:28:59 in2 Exp $ .include "../pttbbs.mk" UTIL_OBJS= \ util_cache.o util_record.o util_passwd.o +# 下面這些程式, 會被 compile 並且和 $(UTIL_OBJS) 聯結 CPROG_WITH_UTIL= \ bbsmail BM_money post poststat \ jungo account birth deluserfile \ @@ -13,12 +14,14 @@ CPROG_WITH_UTIL= \ indexuser yearsold toplazyBM toplazyBBM \ reaper buildAnnounce inndBM shmctl +# 下面這些程式, 會直接被 compile CPROG_WITHOUT_UTIL= \ shmsweep uhash_loader showboard antispam \ countalldice webgrep bbsrf initbbs \ userlist tunepasswd buildir merge_passwd \ merge_board xchatd outmail +# 下面這些程式會被 install PROGS= ${UTIL_OBJS} ${CPROG_WITH_UTIL} ${CPROG_WITHOUT_UTIL} \ BM_money.sh backpasswd.sh mailog.sh opendice.sh \ openticket.sh stock.sh topsong.sh weather.sh \ -- cgit v1.2.3 From 060a9ece4c0bb997b3cd92b49c9d31bad347b688 Mon Sep 17 00:00:00 2001 From: victor Date: Thu, 15 May 2003 23:54:07 +0000 Subject: fix foreign git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@852 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/mbbsd.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pttbbs/mbbsd/mbbsd.c b/pttbbs/mbbsd/mbbsd.c index 1aaf9900..b9999eb4 100644 --- a/pttbbs/mbbsd/mbbsd.c +++ b/pttbbs/mbbsd/mbbsd.c @@ -1,4 +1,4 @@ -/* $Id: mbbsd.c,v 1.77 2003/05/12 12:47:18 victor Exp $ */ +/* $Id: mbbsd.c,v 1.78 2003/05/15 23:54:07 victor Exp $ */ #include "bbs.h" #define SOCKET_QLEN 4 @@ -885,7 +885,7 @@ user_login() cuser.lastlogin = login_start_time; #ifdef FOREIGN_REG - if (cuser.uflag2 & (FOREIGN | LIVERIGHT)){ + if ((cuser.uflag2 & FOREIGN) && !(cuser.uflag2 & LIVERIGHT)){ if (login_start_time - cuser.firstlogin > (FOREIGN_REG_DAY - 5) * 24 * 3600){ mail_muser(cuser, "[出入境管理局]", "etc/foreign_expired_warn"); } -- cgit v1.2.3 From e67708ab59ae055257ebf92cf4b671b9fe9a667a Mon Sep 17 00:00:00 2001 From: in2 Date: Fri, 16 May 2003 05:57:38 +0000 Subject: only BMs could copy directory in man git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@853 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/announce.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/pttbbs/mbbsd/announce.c b/pttbbs/mbbsd/announce.c index e9068638..2b52bbc2 100644 --- a/pttbbs/mbbsd/announce.c +++ b/pttbbs/mbbsd/announce.c @@ -1,4 +1,4 @@ -/* $Id: announce.c,v 1.19 2003/03/28 14:30:40 in2 Exp $ */ +/* $Id: announce.c,v 1.20 2003/05/16 05:57:38 in2 Exp $ */ #include "bbs.h" static void @@ -1427,11 +1427,26 @@ a_menu(char *maintitle, char *path, int lastlevel) case 'c': if (me.now < me.num) { + boardheader_t *bp; if (!isvisible_man(&me)) break; + + if( !(bp = getbcache(getbnum(currboard))) ) + break; + snprintf(fname, sizeof(fname), "%s/%s", path, me.header[me.now - me.page].filename); - a_copyitem(fname, me.header[me.now - me.page].title, 0, 1); + + /* XXX: dirty fix + 應該要改成如果發現該目錄裡面有隱形目錄的話才拒絕. + 不過這樣的話須要整個搜一遍, 而且目前判斷該資料是目錄 + 還是檔案竟然是用 fstat(2) 而不是直接存在 .DIR 內 |||b + 須等該資料寫入 .DIR 內再 implement才有效率. + */ + if( !HAS_PERM(PERM_SYSOP) && !is_BM(bp->BM) && dashd(fname) ) + vmsg("只有板主才可以拷貝目錄唷!"); + else + a_copyitem(fname, me.header[me.now - me.page].title, 0, 1); me.page = 9999; break; } -- cgit v1.2.3 From bae6202ea518b5f09cf37ebba8636f15deb31208 Mon Sep 17 00:00:00 2001 From: in2 Date: Fri, 16 May 2003 06:31:33 +0000 Subject: security fix git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@854 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/announce.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/pttbbs/mbbsd/announce.c b/pttbbs/mbbsd/announce.c index 2b52bbc2..0e4d3fc4 100644 --- a/pttbbs/mbbsd/announce.c +++ b/pttbbs/mbbsd/announce.c @@ -1,4 +1,4 @@ -/* $Id: announce.c,v 1.20 2003/05/16 05:57:38 in2 Exp $ */ +/* $Id: announce.c,v 1.21 2003/05/16 06:31:33 in2 Exp $ */ #include "bbs.h" static void @@ -1393,8 +1393,12 @@ a_menu(char *maintitle, char *path, int lastlevel) break; case 's': - AnnounceSelect(); - me.page = 9999; + /* XXX: security problem + 透過這個方式跳的時候不會 update currboard , + 可能會導致像是 check BM 的時候不正確 + AnnounceSelect(); + me.page = 9999; + */ break; case 'e': -- cgit v1.2.3 From ecc0a37d2e230e64268871d1e649649d9cf36d4c Mon Sep 17 00:00:00 2001 From: in2 Date: Fri, 16 May 2003 07:44:30 +0000 Subject: for OUTTA_TIMER git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@855 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/sample/pttbbs.conf | 3 ++- pttbbs/sample/rc.local | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/pttbbs/sample/pttbbs.conf b/pttbbs/sample/pttbbs.conf index 73a324bd..67e696d9 100644 --- a/pttbbs/sample/pttbbs.conf +++ b/pttbbs/sample/pttbbs.conf @@ -84,7 +84,8 @@ //#define PRE_FORK 10 /* 若定義, 則由 shmctl utmpsortd 將 time(NULL) 寫入 SHM->GV2.e.now, - 則不須每個 mbbsd都自己透過 time(NULL) 取得時間, 導致大量的 system call */ + 則不須每個 mbbsd都自己透過 time(NULL) 取得時間, 導致大量的 system call. + 須要加跑 shmctl timed 來提供時間 */ //#define OUTTA_TIMER /* 前進站畫面 */ diff --git a/pttbbs/sample/rc.local b/pttbbs/sample/rc.local index d31a009a..96d2cb00 100644 --- a/pttbbs/sample/rc.local +++ b/pttbbs/sample/rc.local @@ -15,3 +15,6 @@ /home/bbs/bin/mbbsd 3009 & /home/bbs/bin/mbbsd 3010 & /usr/bin/su -fm bbsadm -c "/home/bbs/bin/shmctl utmpsortd" + +# 若您在 pttbbs.conf 中有開 OUTTA_TIMER 的話, 則須跑下面這行 +# /usr/bin/su -fm bbsadm -c "/home/bbs/bin/shmctl timed" -- cgit v1.2.3 From e60f6717fc3fe696756fceb7ffb024885bcc2281 Mon Sep 17 00:00:00 2001 From: in2 Date: Fri, 16 May 2003 07:49:39 +0000 Subject: libiconv path git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@856 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/docs/FAQ | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/pttbbs/docs/FAQ b/pttbbs/docs/FAQ index ce55511e..c4267063 100644 --- a/pttbbs/docs/FAQ +++ b/pttbbs/docs/FAQ @@ -6,6 +6,7 @@ PttBBS FAQ: 4. 設定 group 5. 五子棋盤沒有出現 6. sendmail.cf要改的地方(參考用) (by DavidYu) + 7. /usr/libexec/elf/ld: cannot find -liconv ------------------------------------------------------------------------------ 1.PttBBS的討論區 位於批踢踢實業坊 (telnet://ptt.csie.ntu.edu.tw) 的 PttCurrent 看板. @@ -101,3 +102,16 @@ Mbbsmail, P=/home/bbs/bin/bbsmail, F=lsSDFMhPu, U=bbs, S=10,R=20/40, ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ A=bbsmail $u ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +------------------------------------------------------------------------------ +7./usr/libexec/elf/ld: cannot find -liconv +因為新的 innbbsd中加入了 RFC 2045 support, 須要 libiconv . +您須先要有安裝 libiconv (/usr/ports/converters/libiconv/ in FreeBSD) +再重新 make 即可 + +若您已經安裝了 libiconv 不過還是找不到, +請將該 lib所在的 path (/usr/local/lib in FreeBSD) +加到 innbbsd/Makefile 的 LDFLAGS中, ex: + LDFLAGS+= -liconv +改成: + LDFLAGS+= -liconv -L/usr/local/lib -- cgit v1.2.3 From 2069e898fce53914e3269e38cf072afb138aeb62 Mon Sep 17 00:00:00 2001 From: ptt Date: Fri, 16 May 2003 08:25:29 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@857 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/include/proto.h | 4 ++-- pttbbs/mbbsd/admin.c | 48 ++++++++++++++++++++++++++++++++++++++---------- pttbbs/mbbsd/friend.c | 17 ++++++++++------- pttbbs/mbbsd/talk.c | 4 ++-- 4 files changed, 52 insertions(+), 21 deletions(-) diff --git a/pttbbs/include/proto.h b/pttbbs/include/proto.h index e4bcf25c..a2bd7459 100644 --- a/pttbbs/include/proto.h +++ b/pttbbs/include/proto.h @@ -1,4 +1,4 @@ -/* $Id: proto.h,v 1.39 2003/04/28 01:02:46 in2 Exp $ */ +/* $Id: proto.h,v 1.40 2003/05/16 08:25:29 ptt Exp $ */ #ifndef INCLUDE_PROTO_H #define INCLUDE_PROTO_H @@ -211,7 +211,7 @@ void friend_edit(int type); void friend_load(); int t_override(); int t_reject(); -void friend_add(char *uident, int type); +void friend_add(char *uident, int type, char *des); void friend_delete(char *uident, int type); /* gamble */ diff --git a/pttbbs/mbbsd/admin.c b/pttbbs/mbbsd/admin.c index 15659d31..9ffe5a08 100644 --- a/pttbbs/mbbsd/admin.c +++ b/pttbbs/mbbsd/admin.c @@ -1,4 +1,4 @@ -/* $Id: admin.c,v 1.40 2003/05/12 12:47:18 victor Exp $ */ +/* $Id: admin.c,v 1.41 2003/05/16 08:25:10 ptt Exp $ */ #include "bbs.h" /* 使用者管理 */ @@ -32,8 +32,10 @@ search_key_user(char *passwdfile, int mode) userec_t user; int ch; int coun = 0; - FILE *fp1 = fopen(passwdfile, "r"); - char buf[128], key[22], genbuf[8]; + FILE *fp1 = fopen(passwdfile, "r"); + char friendfile[128]="",buf[128], key[22], genbuf[8], + *keymatch; + assert(fp1); clear(); @@ -46,12 +48,28 @@ search_key_user(char *passwdfile, int mode) outs(buf); refresh(); } - if (!strcasecmp(user.userid, key) || - (mode && ( - strstr(user.realname, key) || strstr(user.username, key) || - strstr(user.lasthost, key) || strstr(user.email, key) || - strstr(user.address, key) || strstr(user.justify, key) || - strstr(user.mychicken.name, key)))) { + keymatch=NULL; + if (!strcasecmp(user.userid, key)) + sprintf(keymatch,"id:%s",user.userid); + else if(mode) + { + if(strstr(user.realname, key)) + keymatch=user.realname; + else if(strstr(user.username, key)) + keymatch=user.username; + else if(strstr(user.lasthost, key)) + keymatch=user.lasthost; + else if(strstr(user.email, key)) + keymatch=user.email; + else if(strstr(user.address, key)) + keymatch=user.address; + else if(strstr(user.justify, key)) + keymatch=user.justify; + else if(strstr(user.mychicken.name, key)) + keymatch=user.mychicken.name; + } + if(keymatch) + { move(1, 0); snprintf(buf, sizeof(buf), "第 [%d] 筆資料\n", coun); outs(buf); @@ -61,10 +79,20 @@ search_key_user(char *passwdfile, int mode) uinfo_query(&user, 1, coun); outs("\033[44m 空白鍵\033[37m:搜尋下一個" " \033[33m Q\033[37m: 離開"); - outs(mode ? " \033[m " : + outs(mode ? + " A: add to namelist \033[m " : " S: 取用備份資料 \033[m "); while (1) { while ((ch = igetch()) == 0); + if (ch == 'a' || ch=='A' ) + { + if(!friendfile[0]) + { + friend_special(); + setfriendfile(friendfile, FRIEND_SPECIAL); + } + friend_add(user.userid, FRIEND_SPECIAL, keymatch); + } if (ch == ' ') break; if (ch == 'q' || ch == 'Q') { diff --git a/pttbbs/mbbsd/friend.c b/pttbbs/mbbsd/friend.c index e2616ec3..15fd35dc 100644 --- a/pttbbs/mbbsd/friend.c +++ b/pttbbs/mbbsd/friend.c @@ -1,4 +1,4 @@ -/* $Id: friend.c,v 1.17 2003/04/28 11:02:19 in2 Exp $ */ +/* $Id: friend.c,v 1.18 2003/05/16 08:25:10 ptt Exp $ */ #include "bbs.h" /* ------------------------------------- */ @@ -6,8 +6,8 @@ /* ------------------------------------- */ /* Ptt 其他特別名單的檔名 */ -static char special_list[] = "list.0"; -static char special_des[] = "ldes.0"; +char special_list[] = "list.0"; +char special_des[] = "ldes.0"; /* 特別名單的上限 */ static unsigned int friend_max[8] = { @@ -47,7 +47,7 @@ static char *friend_list[8] = { "看板好友名單" }; -static void +void setfriendfile(char *fpath, int type) { if (type <= 4) /* user list Ptt */ @@ -79,7 +79,7 @@ friend_count(char *fname) } void -friend_add(char *uident, int type) +friend_add(char *uident, int type, char* des) { char fpath[80]; @@ -96,7 +96,10 @@ friend_add(char *uident, int type) strlcpy(t_uident, uident, sizeof(t_uident)); if (type != FRIEND_ALOHA && type != FRIEND_POST) + if(!des) getdata(2, 0, friend_desc[type], buf, sizeof(buf), DOECHO); + else + getdata_str(2, 0, friend_desc[type], buf, sizeof(buf), DOECHO, des); if ((fp = fopen(fpath, "a"))) { flock(fileno(fp), LOCK_EX); @@ -107,7 +110,7 @@ friend_add(char *uident, int type) } } -static void +void friend_special() { char genbuf[70], i, fname[70]; @@ -370,7 +373,7 @@ friend_edit(int type) move(1, 0); usercomplete(msg_uid, uident); if (uident[0] && searchuser(uident) && !InNameList(uident)) { - friend_add(uident, type); + friend_add(uident, type, NULL); dirty = 1; } } else if (*uident == 'p') { diff --git a/pttbbs/mbbsd/talk.c b/pttbbs/mbbsd/talk.c index 273dd215..725300bc 100644 --- a/pttbbs/mbbsd/talk.c +++ b/pttbbs/mbbsd/talk.c @@ -1,4 +1,4 @@ -/* $Id: talk.c,v 1.108 2003/05/14 09:46:19 in2 Exp $ */ +/* $Id: talk.c,v 1.109 2003/05/16 08:25:10 ptt Exp $ */ #include "bbs.h" #define QCAST int (*)(const void *, const void *) @@ -2200,7 +2200,7 @@ userlist(void) break; case 'a': if (HAS_PERM(PERM_LOGINOK)) { - friend_add(uentp->userid, FRIEND_OVERRIDE); + friend_add(uentp->userid, FRIEND_OVERRIDE,uentp->username); friend_load(); redrawall = redraw = 1; } -- cgit v1.2.3 From 82dd0ae1bccdb4de78d214cf5f3bbd7b5eb7bc01 Mon Sep 17 00:00:00 2001 From: ptt Date: Fri, 16 May 2003 08:30:48 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@858 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/admin.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pttbbs/mbbsd/admin.c b/pttbbs/mbbsd/admin.c index 9ffe5a08..29145dd7 100644 --- a/pttbbs/mbbsd/admin.c +++ b/pttbbs/mbbsd/admin.c @@ -1,4 +1,4 @@ -/* $Id: admin.c,v 1.41 2003/05/16 08:25:10 ptt Exp $ */ +/* $Id: admin.c,v 1.42 2003/05/16 08:30:48 ptt Exp $ */ #include "bbs.h" /* 使用者管理 */ @@ -92,6 +92,7 @@ search_key_user(char *passwdfile, int mode) setfriendfile(friendfile, FRIEND_SPECIAL); } friend_add(user.userid, FRIEND_SPECIAL, keymatch); + break; } if (ch == ' ') break; -- cgit v1.2.3 From 0a0856dda8e799e39e0e3a3e1f0aa5f7a89aa67a Mon Sep 17 00:00:00 2001 From: ptt Date: Fri, 16 May 2003 18:58:49 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@859 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/inndBM.c | 2 +- pttbbs/util/util_cache.c | 61 +++++++++++++++++++++++++++++++++++++++++------- 2 files changed, 54 insertions(+), 9 deletions(-) diff --git a/pttbbs/util/inndBM.c b/pttbbs/util/inndBM.c index 73f66c5e..8f1a69a0 100644 --- a/pttbbs/util/inndBM.c +++ b/pttbbs/util/inndBM.c @@ -92,7 +92,7 @@ int load_newsfeeds() feedline[feedcount].server); bid=getbnum(feedline[feedcount].board); if(!bid) { - fprintf(fo,"%s\n", feedline[feedcount].group ); + fprintf(fo,"%s %s\n", feedline[feedcount].board, feedline[feedcount].group ); feedcount--; continue; /*移除沒有的看板i*/} diff --git a/pttbbs/util/util_cache.c b/pttbbs/util/util_cache.c index 4d69bef8..a8dd6b71 100644 --- a/pttbbs/util/util_cache.c +++ b/pttbbs/util/util_cache.c @@ -1,4 +1,4 @@ -/* $Id: util_cache.c,v 1.10 2003/02/16 08:58:00 in2 Exp $ */ +/* $Id: util_cache.c,v 1.11 2003/05/16 18:58:49 ptt Exp $ */ #include #include #include @@ -312,13 +312,58 @@ userinfo_t *search_ulist(int uid) { /* .BOARDS cache */ /*-------------------------------------------------------*/ char *fn_board=BBSHOME"/"FN_BOARD; -static void reload_bcache() { - if(SHM->Bbusystate) { - safe_sleep(1); +static int +cmpboardname(boardheader_t ** brd, boardheader_t ** tmp) +{ + return strcasecmp((*brd)->brdname, (*tmp)->brdname); +} + +static int +cmpboardclass(boardheader_t ** brd, boardheader_t ** tmp) +{ + return (strncmp((*brd)->title, (*tmp)->title, 4) << 8) + + strcasecmp((*brd)->brdname, (*tmp)->brdname); +} +static void +sort_bcache() +{ + int i; + /* critical section \xa4\xa3\xaf\xe0\xb3\xe6\xbfW\xa9I\xa5s \xa9I\xa5sreload +_bcache or reset_board */ + for (i = 0; i < SHM->Bnumber; i++) { + SHM->bsorted[1][i] = SHM->bsorted[0][i] = &bcache[i]; } - else{ - puts("bcache is not loaded? resolve_boards() fail"); - exit(1); + qsort(SHM->bsorted[0], SHM->Bnumber, sizeof(boardheader_t *), + (QCAST) cmpboardname); + qsort(SHM->bsorted[1], SHM->Bnumber, sizeof(boardheader_t *), + (QCAST) cmpboardclass); +} + + +static void +reload_bcache() +{ + if (SHM->Bbusystate) { + safe_sleep(1); + } + else { + int fd, i; + + SHM->Bbusystate = 1; + if ((fd = open(fn_board, O_RDONLY)) > 0) { + SHM->Bnumber = + read(fd, bcache, MAX_BOARD * sizeof(boardheader_t)) / + sizeof(boardheader_t); + close(fd); + } + memset(SHM->lastposttime, 0, MAX_BOARD * sizeof(time_t)); + SHM->Buptime = SHM->Btouchtime; + sort_bcache(); + for (i = 0; i < SHM->Bnumber; ++i) { + bcache[i].firstchild[0] = NULL; + bcache[i].firstchild[1] = NULL; + } + SHM->Bbusystate = 0; } } @@ -329,7 +374,7 @@ void resolve_boards() { SHM->Btouchtime = 1; } - while(SHM->Buptime < SHM->Btouchtime) + if(SHM->Buptime < SHM->Btouchtime) reload_bcache(); numboards = SHM->Bnumber; } -- cgit v1.2.3 From 20ea5c957f268fb9862ffb9474dd6c0b09f1e9e5 Mon Sep 17 00:00:00 2001 From: ptt Date: Fri, 16 May 2003 19:38:05 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@860 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/innbbsd/bbsnnrp.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/pttbbs/innbbsd/bbsnnrp.c b/pttbbs/innbbsd/bbsnnrp.c index 11993629..6682f7ba 100644 --- a/pttbbs/innbbsd/bbsnnrp.c +++ b/pttbbs/innbbsd/bbsnnrp.c @@ -293,7 +293,7 @@ char **argv; signal(SIGHUP, doterm); signal(SIGPIPE, doterm); - readnews(&BBSNNRP); + readnews(server, &BBSNNRP); writerc(&BBSNNRP); closesockets(); @@ -1010,7 +1010,8 @@ ULONG *low, *high; } -readnews(bbsnnrp) +readnews(server,bbsnnrp) +char *server; nnrp_t *bbsnnrp; { int i; @@ -1074,7 +1075,13 @@ nnrp_t *bbsnnrp; printf("got reply %d %ld %ld\n",code, low, high); #endif artcount = 0; - if (code == NNRPGroupOK) { + if (code == 411) + { + FILE *ff=fopen(BBSHOME"/innd/log/badgroup.log","a"); + fprintf(ff,"%s\t%-.*s\r\n", server, rcptr->namelen, rcptr->nameptr); + fclose(ff); + } + else if (code == NNRPGroupOK) { int xcount; ULONG maxartno= rcptr->high; int isCancelControl = (strncmp(rcptr->nameptr,"control",rcptr->namelen)==0) -- cgit v1.2.3 From a83dd22adce9e049e3b64b99faf8af0db0e46eae Mon Sep 17 00:00:00 2001 From: victor Date: Sat, 17 May 2003 04:41:02 +0000 Subject: outta timer:p git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@861 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/shmctl.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/pttbbs/util/shmctl.c b/pttbbs/util/shmctl.c index 0348c768..86e65cb3 100644 --- a/pttbbs/util/shmctl.c +++ b/pttbbs/util/shmctl.c @@ -1,4 +1,4 @@ -/* $Id: shmctl.c,v 1.41 2003/05/15 06:48:46 in2 Exp $ */ +/* $Id: shmctl.c,v 1.42 2003/05/17 04:41:02 victor Exp $ */ #include "bbs.h" #include @@ -87,7 +87,11 @@ int utmpfix(int argc, char **argv) SHM->UTMPbusystate = 1; printf("starting scaning... %s \n", (fast ? "(fast mode)" : "")); +#ifdef OUTTA_TIMER + now = SHM->GV2.e.now; +#else time(&now); +#endif for( i = 0, nactive = 0 ; i < USHM_SIZE ; ++i ) if( SHM->uinfo[i].pid ){ idle[nactive].index = i; @@ -208,7 +212,11 @@ inline void utmpsort(void) short nusers[MAX_BOARD]; SHM->UTMPbusystate = 1; +#ifdef OUTTA_TIMER + SHM->UTMPuptime = SHM->GV2.e.now; +#else SHM->UTMPuptime = time(NULL); +#endif ns = (SHM->currsorted ? 0 : 1); for (uentp = &SHM->uinfo[0], count = i = 0; @@ -299,9 +307,13 @@ int utmpstate(int argc, char **argv) { time_t now; char upbuf[64], nowbuf[64]; +#ifdef OUTTA_TIMER + now = SHM->GV2.e.now; +#else now = time(NULL); +#endif CTIMEx(upbuf, SHM->UTMPuptime); - CTIMEx(nowbuf, time(NULL)); + CTIMEx(nowbuf, now); printf("now: %s\n", nowbuf); printf("currsorted: %d\n", SHM->currsorted); printf("uptime: %s\n", upbuf); -- cgit v1.2.3 From 84da9cf6fa290d5c5a19964424ccc81a8dc1da15 Mon Sep 17 00:00:00 2001 From: in2 Date: Sun, 18 May 2003 07:20:29 +0000 Subject: fix bug when no other friend is online git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@862 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/talk.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pttbbs/mbbsd/talk.c b/pttbbs/mbbsd/talk.c index 725300bc..08ef5020 100644 --- a/pttbbs/mbbsd/talk.c +++ b/pttbbs/mbbsd/talk.c @@ -1,4 +1,4 @@ -/* $Id: talk.c,v 1.109 2003/05/16 08:25:10 ptt Exp $ */ +/* $Id: talk.c,v 1.110 2003/05/18 07:20:29 in2 Exp $ */ #include "bbs.h" #define QCAST int (*)(const void *, const void *) @@ -1618,11 +1618,11 @@ pickup(pickup_t * currpickup, int pickup_way, int *page, ((pickup_way == 0) && /* [嗨! 朋友] mode */ ( /* 含板友, 好友區最多只會有 (friendtotal + 板友) 個*/ - (currutmp->brc_id && which < (friendtotal + + (currutmp->brc_id && which < (friendtotal + 1 + bcache[currutmp->brc_id-1].nuser)) || /* 不含板友, 最多只會有 friendtotal個 */ - (!currutmp->brc_id && which < friendtotal) + (!currutmp->brc_id && which < friendtotal + 1) ))) { pickup_t friends[MAX_FRIEND]; -- cgit v1.2.3 From 1d6d7c66f7d0c188179b5c77c4b747706ecb261e Mon Sep 17 00:00:00 2001 From: in2 Date: Sun, 18 May 2003 07:31:09 +0000 Subject: warning free git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@863 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/friend.c | 9 +++++---- pttbbs/mbbsd/mbbsd.c | 12 ++++++++---- pttbbs/mbbsd/screen.c | 4 ++-- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/pttbbs/mbbsd/friend.c b/pttbbs/mbbsd/friend.c index 15fd35dc..127f9f5d 100644 --- a/pttbbs/mbbsd/friend.c +++ b/pttbbs/mbbsd/friend.c @@ -1,4 +1,4 @@ -/* $Id: friend.c,v 1.18 2003/05/16 08:25:10 ptt Exp $ */ +/* $Id: friend.c,v 1.19 2003/05/18 07:31:09 in2 Exp $ */ #include "bbs.h" /* ------------------------------------- */ @@ -95,11 +95,12 @@ friend_add(char *uident, int type, char* des) /* Thor: avoid uident run away when get data */ strlcpy(t_uident, uident, sizeof(t_uident)); - if (type != FRIEND_ALOHA && type != FRIEND_POST) + if (type != FRIEND_ALOHA && type != FRIEND_POST){ if(!des) getdata(2, 0, friend_desc[type], buf, sizeof(buf), DOECHO); else getdata_str(2, 0, friend_desc[type], buf, sizeof(buf), DOECHO, des); + } if ((fp = fopen(fpath, "a"))) { flock(fileno(fp), LOCK_EX); @@ -111,7 +112,7 @@ friend_add(char *uident, int type, char* des) } void -friend_special() +friend_special(void) { char genbuf[70], i, fname[70]; @@ -210,7 +211,7 @@ friend_append(int type, int count) void friend_delete(char *uident, int type) { - FILE *fp, *nfp; + FILE *fp, *nfp = NULL; char fn[80], fnnew[80]; char genbuf[200]; diff --git a/pttbbs/mbbsd/mbbsd.c b/pttbbs/mbbsd/mbbsd.c index b9999eb4..9498f963 100644 --- a/pttbbs/mbbsd/mbbsd.c +++ b/pttbbs/mbbsd/mbbsd.c @@ -1,4 +1,4 @@ -/* $Id: mbbsd.c,v 1.78 2003/05/15 23:54:07 victor Exp $ */ +/* $Id: mbbsd.c,v 1.79 2003/05/18 07:31:09 in2 Exp $ */ #include "bbs.h" #define SOCKET_QLEN 4 @@ -1004,17 +1004,21 @@ telnet_init() IAC, WILL, TELOPT_SGA }; char *cmd; - int n, len, rset; + int n, len; struct timeval to; char buf[64]; + fd_set ReadSet, r; + + FD_ZERO(&ReadSet); + FD_SET(0, &ReadSet); for (n = 0, cmd = svr; n < 4; n++) { len = (n == 1 ? 6 : 3); write(0, cmd, len); cmd += len; to.tv_sec = 3; to.tv_usec = 0; - rset = 1; - if (select(1, (fd_set *) & rset, NULL, NULL, &to) > 0) + r = ReadSet; + if (select(1, &r, NULL, NULL, &to) > 0) recv(0, buf, sizeof(buf), 0); } } diff --git a/pttbbs/mbbsd/screen.c b/pttbbs/mbbsd/screen.c index 23aa9e71..832abfca 100644 --- a/pttbbs/mbbsd/screen.c +++ b/pttbbs/mbbsd/screen.c @@ -1,4 +1,4 @@ -/* $Id: screen.c,v 1.14 2003/01/16 11:53:54 kcwu Exp $ */ +/* $Id: screen.c,v 1.15 2003/05/18 07:31:09 in2 Exp $ */ #include "bbs.h" #ifdef SUPPORT_GB @@ -379,7 +379,7 @@ outc(unsigned char ch) if (ch == 'm') { buf[p++] = '\0'; parsecolor(buf); - } else if ((p < sizeof(buf)) && (not_alpha(ch))) { + } else if (((size_t)p < sizeof(buf)) && (not_alpha(ch))) { buf[p++] = ch; return; } -- cgit v1.2.3 From 1124bede817fa208b09d7e09a71d33fb6edbd7e4 Mon Sep 17 00:00:00 2001 From: in2 Date: Sun, 18 May 2003 07:46:37 +0000 Subject: warning free git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@864 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/include/proto.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pttbbs/include/proto.h b/pttbbs/include/proto.h index a2bd7459..c0c2326e 100644 --- a/pttbbs/include/proto.h +++ b/pttbbs/include/proto.h @@ -1,4 +1,4 @@ -/* $Id: proto.h,v 1.40 2003/05/16 08:25:29 ptt Exp $ */ +/* $Id: proto.h,v 1.41 2003/05/18 07:46:37 in2 Exp $ */ #ifndef INCLUDE_PROTO_H #define INCLUDE_PROTO_H @@ -213,6 +213,8 @@ int t_override(); int t_reject(); void friend_add(char *uident, int type, char *des); void friend_delete(char *uident, int type); +void friend_special(void); +void setfriendfile(char *fpath, int type); /* gamble */ int ticket_main(); -- cgit v1.2.3 From 3ffb601708ca9fe26339d492b057770b3f329e76 Mon Sep 17 00:00:00 2001 From: victor Date: Sun, 18 May 2003 13:42:55 +0000 Subject: 1. never mark a non-exist post 2. avoid incorrect sequence after rebuilder if there is any edited post git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@865 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/bbs.c | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/pttbbs/mbbsd/bbs.c b/pttbbs/mbbsd/bbs.c index bd0e82a4..01324b22 100644 --- a/pttbbs/mbbsd/bbs.c +++ b/pttbbs/mbbsd/bbs.c @@ -1,4 +1,4 @@ -/* $Id: bbs.c,v 1.93 2003/05/14 08:31:29 in2 Exp $ */ +/* $Id: bbs.c,v 1.94 2003/05/18 13:42:55 victor Exp $ */ #include "bbs.h" static int recommend(int ent, fileheader_t * fhdr, char *direct); @@ -714,11 +714,12 @@ reply_post(int ent, fileheader_t * fhdr, char *direct) static int edit_post(int ent, fileheader_t * fhdr, char *direct) { + int num; char fpath[80], fpath0[80]; char genbuf[200]; fileheader_t postfile; - boardheader_t *bp; - bp = getbcache(currbid); + boardheader_t *bp = getbcache(currbid); + if (strcmp(bp->brdname, "Security") == 0) return DONOTHING; @@ -742,15 +743,25 @@ edit_post(int ent, fileheader_t * fhdr, char *direct) lock_substitute_record(direct, fhdr, sizeof(*fhdr), ent, LOCK_EX); setbpath(fpath, currboard); stampfile(fpath, &postfile); - unlink(fpath); + strlcpy(genbuf, fhdr->filename, strlen(genbuf)); setbfile(fpath0, currboard, fhdr->filename); + for(num = 2; genbuf[num] != NULL; num++){ + if(genbuf[num] == '.'){ + genbuf[num] = 0; + break; + } + } + + sprintf(postfile.filename, "%s.A.%3.3X", genbuf, rand() & 0xFFF); + setdirpath(fpath, fpath, postfile.filename); + unlink(fpath); + Rename(fpath0, fpath); /* rocker.011018: fix 串接模式改文章後文章就不見的bug */ if ((currmode & MODE_SELECT) && (fhdr->money & FHR_REFERENCE)) { fileheader_t hdr; - int num; num = fhdr->money & ~FHR_REFERENCE; setbdir(fpath0, currboard); @@ -1293,10 +1304,17 @@ recommend(int ent, fileheader_t * fhdr, char *direct) static int mark_post(int ent, fileheader_t * fhdr, char *direct) { + char buf[STRLEN], fpath[STRLEN]; if (!(currmode & MODE_BOARD)) return DONOTHING; + setbpath(fpath, currboard); + sprintf(buf, "%s/%s", fpath, fhdr->filename); + + if(access(buf, F_OK) < 0) + return DONOTHING; + fhdr->filemode ^= FILE_MARKED; substitute_record(direct, fhdr, sizeof(*fhdr), ent); substitute_check(fhdr); -- cgit v1.2.3 From 0769eaf9f67be2d200e976d74f0fa8d6e82c7c24 Mon Sep 17 00:00:00 2001 From: in2 Date: Mon, 19 May 2003 01:19:36 +0000 Subject: pttpi error code git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@866 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/pttpi/include/pierr.h | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 pttbbs/pttpi/include/pierr.h diff --git a/pttbbs/pttpi/include/pierr.h b/pttbbs/pttpi/include/pierr.h new file mode 100644 index 00000000..da462a36 --- /dev/null +++ b/pttbbs/pttpi/include/pierr.h @@ -0,0 +1,9 @@ +#ifndef _PIERR_H_ +#define _PIERR_H_ + +#define PIERR_OK (int32)0 /* no error */ +#define PIERR_INT (int32)1 /* internal error (ex: syscall failure) */ +#define PIERR_NOBRD (int32)2 /* no such board or permission denied */ +#define PIERR_NOMORE (int32)3 /* no more data */ +#define PIERR_NOTCLASS (int32)4 /* this bid is NOT class */ +#endif -- cgit v1.2.3 From f6feb9cfe3a0eaaee60523a098cf92a7410de91d Mon Sep 17 00:00:00 2001 From: in2 Date: Mon, 19 May 2003 01:21:43 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@867 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/pttpi/README | 4 ++++ pttbbs/pttpi/doc/spec | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 pttbbs/pttpi/README create mode 100644 pttbbs/pttpi/doc/spec diff --git a/pttbbs/pttpi/README b/pttbbs/pttpi/README new file mode 100644 index 00000000..8f60ff6c --- /dev/null +++ b/pttbbs/pttpi/README @@ -0,0 +1,4 @@ +PTT Programming Interface + +這目前還是一個實驗性的東西, +它還不穩定, 沒有效率, 沒有經過完整測試, 並且 spec 還在編修中. diff --git a/pttbbs/pttpi/doc/spec b/pttbbs/pttpi/doc/spec new file mode 100644 index 00000000..e1460030 --- /dev/null +++ b/pttbbs/pttpi/doc/spec @@ -0,0 +1,50 @@ +board.getBid get bid from board name +input (s) + (board name) +output ({s:i, s:s, s:i}) + {errno => errno, + brdname => boardname, + bid => boardid} (bid = -1 if error) + + +board.getBrdInfo +get board information (by bid) +input (i) + (bid) +output ({s:i,s:s,s:i,s:6,s:6,s:i}) + {errno => errno, + brdname => boardname + bid => bid, + title => title (Base64), + BM => board manager(s) (Base64), + nuser => #users in this board, + } + +board.getNarticle +get # articles in the board +input (i) + (bid) +output ({s:i, s:s, s:i}) + {errno => errno, + narticle => #articles in the board} + +article.list +get article list of bid +input (ii) + (bid, from # article) +output: ({s:i,s:s,s:i,s:s,s:s,s:6}...) + [{articleid => article id, + filename => file name, + recommend => recommend, + owner => owner's userid, + date => date (format: mm/dd), + title => article title (Base64)}, + {...},...] + +article.readfn +read article by bid and filename +input (is) + (bid, filename) +output ({s:6}) + {content => content} + -- cgit v1.2.3 From 5993937074bf7c7424addbf50eae2854b29637fb Mon Sep 17 00:00:00 2001 From: in2 Date: Mon, 19 May 2003 01:33:00 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@868 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/pttpi/cgi/.cvsignore | 1 + pttbbs/pttpi/cgi/Makefile | 16 +++ pttbbs/pttpi/cgi/pttpi.c | 244 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 261 insertions(+) create mode 100644 pttbbs/pttpi/cgi/.cvsignore create mode 100644 pttbbs/pttpi/cgi/Makefile create mode 100644 pttbbs/pttpi/cgi/pttpi.c diff --git a/pttbbs/pttpi/cgi/.cvsignore b/pttbbs/pttpi/cgi/.cvsignore new file mode 100644 index 00000000..169dce0c --- /dev/null +++ b/pttbbs/pttpi/cgi/.cvsignore @@ -0,0 +1 @@ +*.cgi diff --git a/pttbbs/pttpi/cgi/Makefile b/pttbbs/pttpi/cgi/Makefile new file mode 100644 index 00000000..42613de3 --- /dev/null +++ b/pttbbs/pttpi/cgi/Makefile @@ -0,0 +1,16 @@ +# $Id: Makefile,v 1.1 2003/05/19 01:33:00 in2 Exp $ + +.include "../../pttbbs.mk" + +CFLAGS+= -I../../include `xmlrpc-c-config cgi-server --cflags` +LDFLAGS+= `xmlrpc-c-config cgi-server --libs` + +UTIL_OBJS= \ + ../../util/util_cache.o ../../util/util_record.o ../../util/util_passwd.o +all: pttpi.cgi + +pttpi.cgi: pttpi.c + $(CC) $(CFLAGS) $(LDFLAGS) -o pttpi.cgi pttpi.c $(UTIL_OBJS) + +clean: + rm -f *.cgi *~ diff --git a/pttbbs/pttpi/cgi/pttpi.c b/pttbbs/pttpi/cgi/pttpi.c new file mode 100644 index 00000000..187c4f63 --- /dev/null +++ b/pttbbs/pttpi/cgi/pttpi.c @@ -0,0 +1,244 @@ +/* $Id: pttpi.c,v 1.1 2003/05/19 01:33:00 in2 Exp $ */ +#include "bbs.h" +#include "pierr.h" +#include +#include + +extern SHM_t *SHM; +typedef xmlrpc_int32 int32; + +#define errorexit() if( env->fault_occurred ) return NULL +#define check_board_and_permission(bid) \ + if( bid < 0 || bid > MAX_BOARD || \ + !bcache[bid].brdname[0] || \ + (bcache[bid].brdattr & BRD_HIDE) || \ + (!(bcache[bid].brdattr & BRD_GROUPBOARD) && \ + (bcache[bid].brdattr & BRD_POSTMASK)) ) \ + return xmlrpc_build_value(env, "{s:i}", \ + "errno", PIERR_NOBRD); + +#define errorreturn(returncode) \ + return xmlrpc_build_value(env, "{s:i}", \ + "errno", returncode) + +xmlrpc_value * +getBid(xmlrpc_env *env, xmlrpc_value *param_array, void *user_data) +{ + /* !!! overwrite util_cache.c !!! */ + char *brdname; + int bid; + + xmlrpc_parse_value(env, param_array, "(s)", &brdname); + errorexit(); + + bid = getbnum(brdname); + return xmlrpc_build_value(env, "{s:i,s:s,s:i}", + "errno", (bid == -1 ? PIERR_NOBRD : PIERR_OK), + "brdname", brdname, + "bid", (int32)bid); +} + +xmlrpc_value * +getBrdInfo(xmlrpc_env *env, xmlrpc_value *param_array, void *user_data) +{ + int32 bid; + + xmlrpc_parse_value(env, param_array, "(i)", &bid); + errorexit(); + check_board_and_permission(bid); + + return xmlrpc_build_value(env, "{s:i,s:s,s:i,s:6,s:s,s:i}", + "errno", PIERR_OK, + "brdname", bcache[bid].brdname, + "bid", (int32)bid, + "title", bcache[bid].title, strlen(bcache[bid].title), + "BM", bcache[bid].BM, + "nuser", bcache[bid].nuser); +} + +char *getpath(int bid, char *fn) +{ + static char fpath[MAXPATHLEN]; + if( fn == NULL ) + fn = ""; + snprintf(fpath, sizeof(fpath), "boards/%c/%s/%s", + bcache[bid].brdname[0], bcache[bid].brdname, fn); + return fpath; +} + +int getfilesize(int bid, char *fn, int *fd) +{ + struct stat sb; + if( fd == NULL ){ + if( stat(getpath(bid, fn), &sb) < 0 ) + return -1; + } + else { + if( (*fd = open(getpath(bid, fn), O_RDONLY)) < 0 ) + return -1; + if( fstat(*fd, &sb) < 0 ){ + close(*fd); + return -1; + } + } + return sb.st_size; +} + +xmlrpc_value * +getNarticle(xmlrpc_env *env, xmlrpc_value *param_array, void *user_data) +{ + int bid, nas; + + xmlrpc_parse_value(env, param_array, "(i)", &bid); + errorexit(); + check_board_and_permission(bid); + nas = getfilesize(bid, ".DIR", NULL); + + return xmlrpc_build_value(env, "{s:i,s:i}", + "errno", (nas == -1 ? PIERR_INT : PIERR_OK), + "narticle", nas / sizeof(fileheader_t)); +} + +xmlrpc_value * +class_list(xmlrpc_env *env, xmlrpc_value *param_array, void *user_data) +{ + int bid; + boardheader_t *bptr; + xmlrpc_value *ret, *t; + + xmlrpc_parse_value(env, param_array, "(i)", &bid); + errorexit(); + + if( bid != 0 ) + check_board_and_permission(bid); + + if( bid != 0 && !(bcache[bid].brdattr & BRD_GROUPBOARD) ) + errorreturn(PIERR_NOTCLASS); + + ret = xmlrpc_build_value(env, "()"); + for( bptr = bcache[bid].firstchild[0] ; + bptr != (boardheader_t*)~0 ; + bptr = bptr->next[0] ){ + if( (bptr->brdattr & BRD_HIDE) || + (bptr->level && !bptr->brdattr & BRD_POSTMASK) ) + continue; + t = xmlrpc_build_value(env, "{s:i,s:s,s:6,s:i,s:6,s:i,s:b}", + "bid", (int32)(bptr - bcache), + "brdname", bptr->brdname, + "title", bptr->title + 5, strlen(bptr->title) - 5, + "gid", bptr->gid, + "BM", bptr->BM, strlen(bptr->BM), + "nuser", (int32)bptr->nuser, + "isclass", (xmlrpc_bool) + (bptr->brdattr & BRD_GROUPBOARD) ? 1 : 0 + ); + xmlrpc_array_append_item(env, ret, t); + } + return ret; +} + +xmlrpc_value * +article_list(xmlrpc_env *env, xmlrpc_value *param_array, void *user_data) +{ +#define MAXGETARTICLES 20 + xmlrpc_value *ret, *t; + fileheader_t art[MAXGETARTICLES]; + int32 bid, from, nArticles, fd, nGets, i; + + xmlrpc_parse_value(env, param_array, "(ii)", &bid, &from); + errorexit(); + check_board_and_permission(bid); + + if( (nArticles = getfilesize(bid, ".DIR", &fd)) < 0 ) + errorreturn(PIERR_INT); + nArticles /= sizeof(fileheader_t); + + if( from < 0 ) + from += nArticles; + if( from < 0 || from > nArticles ){ + close(fd); + errorreturn(PIERR_NOMORE); + } + + nGets = (((from + MAXGETARTICLES) < nArticles) ? + MAXGETARTICLES : (nArticles - from)); + if( (nGets = read(fd, art, nGets * sizeof(fileheader_t))) < 0 ){ + close(fd); + errorreturn(PIERR_INT); + } + close(fd); + nGets /= sizeof(fileheader_t); + + ret = xmlrpc_build_value(env, "()"); + for( i = 0 ; i < nGets ; ++i ){ + t = xmlrpc_build_value(env, "{s:i,s:s,s:i,s:s,s:s,s:6}", + "articleid", (int32)(from + i), + "filename", art[i].filename, + "recommend", (int32)art[i].recommend, + "owner", art[i].owner, + "date", art[i].date, + "title", art[i].title, strlen(art[i].title) + ); + xmlrpc_array_append_item(env, ret, t); + } + return ret; +} + +xmlrpc_value * +_article_readfn(xmlrpc_env *env, int bid, char *fn) +{ + char *content; + int fd, size; + xmlrpc_value *ret; + if( (size = getfilesize(bid, fn, &fd)) < 0 ) + errorreturn(PIERR_INT); + + content = (char *)malloc(sizeof(char) * size); + read(fd, content, size); + close(fd); + ret = xmlrpc_build_value(env, "{s:6}", "content", content, size); + free(content); + + return ret; +} + +xmlrpc_value * +article_readfn(xmlrpc_env *env, xmlrpc_value *param_array, void *user_data) +{ + int bid; + char *fn; + + xmlrpc_parse_value(env, param_array, "(is)", &bid, &fn); + errorexit(); + + if( fn == NULL || fn[0] != 'M' || fn[1] != '.' ) + errorreturn(PIERR_NOBRD); + check_board_and_permission(bid); + + return _article_readfn(env, bid, fn); +} + +int main(int argc, char **argv) +{ + attach_SHM(); + chdir(BBSHOME); + xmlrpc_cgi_init(XMLRPC_CGI_NO_FLAGS); + xmlrpc_cgi_add_method_w_doc("board.getBid", &getBid, NULL, "?", + "get bid from brdname"); + xmlrpc_cgi_add_method_w_doc("board.getBrdInfo", &getBrdInfo, NULL, "?", + "get board information"); + xmlrpc_cgi_add_method_w_doc("board.getNarticle", &getNarticle, NULL, "?", + "get # articles in the board"); + + xmlrpc_cgi_add_method_w_doc("class.list", &class_list, NULL, "?", + "list (C)lass"); + + xmlrpc_cgi_add_method_w_doc("article.list", &article_list, NULL, "?", + "article list"); + xmlrpc_cgi_add_method_w_doc("article.readfn", &article_readfn, NULL, "?", + "read the article by filename"); + + xmlrpc_cgi_process_call(); + xmlrpc_cgi_cleanup(); + return 0; +} -- cgit v1.2.3 From c4cd69c39fe5ec3c27f286f510bc7bef6c74f44c Mon Sep 17 00:00:00 2001 From: in2 Date: Mon, 19 May 2003 01:52:05 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@869 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/pttpi/cgi/t/.cvsignore | 1 + pttbbs/pttpi/cgi/t/1.board.getBid.pl | 11 +++++++++++ pttbbs/pttpi/cgi/t/2.getBrdInfo.pl | 15 +++++++++++++++ pttbbs/pttpi/cgi/t/host.pl.sample | 2 ++ 4 files changed, 29 insertions(+) create mode 100644 pttbbs/pttpi/cgi/t/.cvsignore create mode 100644 pttbbs/pttpi/cgi/t/1.board.getBid.pl create mode 100644 pttbbs/pttpi/cgi/t/2.getBrdInfo.pl create mode 100644 pttbbs/pttpi/cgi/t/host.pl.sample diff --git a/pttbbs/pttpi/cgi/t/.cvsignore b/pttbbs/pttpi/cgi/t/.cvsignore new file mode 100644 index 00000000..9f20a79c --- /dev/null +++ b/pttbbs/pttpi/cgi/t/.cvsignore @@ -0,0 +1 @@ +host.pl diff --git a/pttbbs/pttpi/cgi/t/1.board.getBid.pl b/pttbbs/pttpi/cgi/t/1.board.getBid.pl new file mode 100644 index 00000000..04be5b89 --- /dev/null +++ b/pttbbs/pttpi/cgi/t/1.board.getBid.pl @@ -0,0 +1,11 @@ +#!/usr/bin/perl +use Frontier::Client; +use Data::Dumper; +do 'host.pl'; + +$brdname = $ARGV[0] || 'SYSOP'; +$server = Frontier::Client->new(url => $server_url); +$result = $server->call('board.getBid', $brdname); + +print "board.getBid($brdname) from $server_url:\n"; +print Dumper($result); diff --git a/pttbbs/pttpi/cgi/t/2.getBrdInfo.pl b/pttbbs/pttpi/cgi/t/2.getBrdInfo.pl new file mode 100644 index 00000000..a0ae95eb --- /dev/null +++ b/pttbbs/pttpi/cgi/t/2.getBrdInfo.pl @@ -0,0 +1,15 @@ +#!/usr/bin/perl +# $Id: 2.getBrdInfo.pl,v 1.1 2003/05/19 01:52:05 in2 Exp $ +use Frontier::Client; +use Frontier::RPC2; +use MIME::Base64; +use Data::Dumper; +do 'host.pl'; + +$bid = $ARGV[0] || 0; + +$server = Frontier::Client->new(url => $server_url); +$result = $server->call('board.getBrdInfo', $bid); + +print Dumper($result); +print decode_base64($result->{title}->value()); diff --git a/pttbbs/pttpi/cgi/t/host.pl.sample b/pttbbs/pttpi/cgi/t/host.pl.sample new file mode 100644 index 00000000..72669230 --- /dev/null +++ b/pttbbs/pttpi/cgi/t/host.pl.sample @@ -0,0 +1,2 @@ +#!/usr/bin/perl +$server_url = 'http://host_to_pttpi/path_to_pttpi/pttpi.cgi' -- cgit v1.2.3 From cb3aec9232aa035f92baec6b6febc935085f42fa Mon Sep 17 00:00:00 2001 From: in2 Date: Mon, 19 May 2003 01:52:22 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@870 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/pttpi/cgi/t/1.board.getBid.pl | 1 + 1 file changed, 1 insertion(+) diff --git a/pttbbs/pttpi/cgi/t/1.board.getBid.pl b/pttbbs/pttpi/cgi/t/1.board.getBid.pl index 04be5b89..576e9a05 100644 --- a/pttbbs/pttpi/cgi/t/1.board.getBid.pl +++ b/pttbbs/pttpi/cgi/t/1.board.getBid.pl @@ -1,4 +1,5 @@ #!/usr/bin/perl +# $Id: 1.board.getBid.pl,v 1.2 2003/05/19 01:52:22 in2 Exp $ use Frontier::Client; use Data::Dumper; do 'host.pl'; -- cgit v1.2.3 From efa3fada14c0436014fe3bb2d72705063a6f5e6f Mon Sep 17 00:00:00 2001 From: in2 Date: Mon, 19 May 2003 01:57:22 +0000 Subject: rename 1.board.getBid.pl board.getBid.pl git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@871 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/pttpi/cgi/t/1.board.getBid.pl | 12 ------------ pttbbs/pttpi/cgi/t/board.getBid.pl | 12 ++++++++++++ 2 files changed, 12 insertions(+), 12 deletions(-) delete mode 100644 pttbbs/pttpi/cgi/t/1.board.getBid.pl create mode 100644 pttbbs/pttpi/cgi/t/board.getBid.pl diff --git a/pttbbs/pttpi/cgi/t/1.board.getBid.pl b/pttbbs/pttpi/cgi/t/1.board.getBid.pl deleted file mode 100644 index 576e9a05..00000000 --- a/pttbbs/pttpi/cgi/t/1.board.getBid.pl +++ /dev/null @@ -1,12 +0,0 @@ -#!/usr/bin/perl -# $Id: 1.board.getBid.pl,v 1.2 2003/05/19 01:52:22 in2 Exp $ -use Frontier::Client; -use Data::Dumper; -do 'host.pl'; - -$brdname = $ARGV[0] || 'SYSOP'; -$server = Frontier::Client->new(url => $server_url); -$result = $server->call('board.getBid', $brdname); - -print "board.getBid($brdname) from $server_url:\n"; -print Dumper($result); diff --git a/pttbbs/pttpi/cgi/t/board.getBid.pl b/pttbbs/pttpi/cgi/t/board.getBid.pl new file mode 100644 index 00000000..a628da4e --- /dev/null +++ b/pttbbs/pttpi/cgi/t/board.getBid.pl @@ -0,0 +1,12 @@ +#!/usr/bin/perl +# $Id: board.getBid.pl,v 1.1 2003/05/19 01:57:22 in2 Exp $ +use Frontier::Client; +use Data::Dumper; +do 'host.pl'; + +$brdname = $ARGV[0] || 'SYSOP'; +$server = Frontier::Client->new(url => $server_url); +$result = $server->call('board.getBid', $brdname); + +print "board.getBid($brdname) from $server_url:\n"; +print Dumper($result); -- cgit v1.2.3 From 3b16ce18fecf57ebd5f16d5198d708502aac6c88 Mon Sep 17 00:00:00 2001 From: in2 Date: Mon, 19 May 2003 01:58:27 +0000 Subject: rename 2.getBrdInfo.pl board.getBrdInfo.pl git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@872 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/pttpi/cgi/t/2.getBrdInfo.pl | 15 --------------- pttbbs/pttpi/cgi/t/board.getBrdInfo.pl | 15 +++++++++++++++ 2 files changed, 15 insertions(+), 15 deletions(-) delete mode 100644 pttbbs/pttpi/cgi/t/2.getBrdInfo.pl create mode 100644 pttbbs/pttpi/cgi/t/board.getBrdInfo.pl diff --git a/pttbbs/pttpi/cgi/t/2.getBrdInfo.pl b/pttbbs/pttpi/cgi/t/2.getBrdInfo.pl deleted file mode 100644 index a0ae95eb..00000000 --- a/pttbbs/pttpi/cgi/t/2.getBrdInfo.pl +++ /dev/null @@ -1,15 +0,0 @@ -#!/usr/bin/perl -# $Id: 2.getBrdInfo.pl,v 1.1 2003/05/19 01:52:05 in2 Exp $ -use Frontier::Client; -use Frontier::RPC2; -use MIME::Base64; -use Data::Dumper; -do 'host.pl'; - -$bid = $ARGV[0] || 0; - -$server = Frontier::Client->new(url => $server_url); -$result = $server->call('board.getBrdInfo', $bid); - -print Dumper($result); -print decode_base64($result->{title}->value()); diff --git a/pttbbs/pttpi/cgi/t/board.getBrdInfo.pl b/pttbbs/pttpi/cgi/t/board.getBrdInfo.pl new file mode 100644 index 00000000..7870e386 --- /dev/null +++ b/pttbbs/pttpi/cgi/t/board.getBrdInfo.pl @@ -0,0 +1,15 @@ +#!/usr/bin/perl +# $Id: board.getBrdInfo.pl,v 1.1 2003/05/19 01:58:27 in2 Exp $ +use Frontier::Client; +use Frontier::RPC2; +use MIME::Base64; +use Data::Dumper; +do 'host.pl'; + +$bid = $ARGV[0] || 0; + +$server = Frontier::Client->new(url => $server_url); +$result = $server->call('board.getBrdInfo', $bid); + +print Dumper($result); +print decode_base64($result->{title}->value()); -- cgit v1.2.3 From 9a0d22610b299b1695bf9f6d7c84f6b7f578610b Mon Sep 17 00:00:00 2001 From: in2 Date: Mon, 19 May 2003 02:01:15 +0000 Subject: add board.getNarticle.pl git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@873 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/pttpi/cgi/t/board.getNarticle.pl | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 pttbbs/pttpi/cgi/t/board.getNarticle.pl diff --git a/pttbbs/pttpi/cgi/t/board.getNarticle.pl b/pttbbs/pttpi/cgi/t/board.getNarticle.pl new file mode 100644 index 00000000..a5fb56a1 --- /dev/null +++ b/pttbbs/pttpi/cgi/t/board.getNarticle.pl @@ -0,0 +1,14 @@ +#!/usr/bin/perl +# $Id: board.getNarticle.pl,v 1.1 2003/05/19 02:01:15 in2 Exp $ +use Frontier::Client; +use Frontier::RPC2; +use MIME::Base64; +use Data::Dumper; +do 'host.pl'; + +$bid = $ARGV[0] || 0; + +$server = Frontier::Client->new(url => $server_url); +$result = $server->call('board.getNarticle', $bid); + +print Dumper($result); -- cgit v1.2.3 From 42524365455d965c51342414b796f1b397cf7361 Mon Sep 17 00:00:00 2001 From: in2 Date: Mon, 19 May 2003 02:02:52 +0000 Subject: add class.list.pl git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@874 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/pttpi/cgi/t/class.list.pl | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 pttbbs/pttpi/cgi/t/class.list.pl diff --git a/pttbbs/pttpi/cgi/t/class.list.pl b/pttbbs/pttpi/cgi/t/class.list.pl new file mode 100644 index 00000000..9e10932b --- /dev/null +++ b/pttbbs/pttpi/cgi/t/class.list.pl @@ -0,0 +1,14 @@ +#!/usr/bin/perl +# $Id: class.list.pl,v 1.1 2003/05/19 02:02:52 in2 Exp $ +use Frontier::Client; +use Frontier::RPC2; +use MIME::Base64; +use Data::Dumper; +do 'host.pl'; + +$bid = $ARGV[0] || 0; + +$server = Frontier::Client->new(url => $server_url); +$result = $server->call('class.list', $bid); + +print Dumper($result); -- cgit v1.2.3 From 2db090737e374ab6a77f5487c1ceacf36eab884a Mon Sep 17 00:00:00 2001 From: in2 Date: Mon, 19 May 2003 02:04:14 +0000 Subject: add article.list.pl git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@875 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/pttpi/cgi/t/article.list.pl | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 pttbbs/pttpi/cgi/t/article.list.pl diff --git a/pttbbs/pttpi/cgi/t/article.list.pl b/pttbbs/pttpi/cgi/t/article.list.pl new file mode 100644 index 00000000..27370aa1 --- /dev/null +++ b/pttbbs/pttpi/cgi/t/article.list.pl @@ -0,0 +1,16 @@ +#!/usr/bin/perl +# $Id: article.list.pl,v 1.1 2003/05/19 02:04:14 in2 Exp $ +use Frontier::Client; +use Frontier::RPC2; +use MIME::Base64; +use Data::Dumper; +do 'host.pl'; + +$bid = $ARGV[0] || 0; + +$server = Frontier::Client->new(url => $server_url); +$result = $server->call('article.list', + $bid, # bid + 0); # from # article + +print Dumper($result); -- cgit v1.2.3 From 475fad506c14970123a068de0a7d8fb545c345ba Mon Sep 17 00:00:00 2001 From: in2 Date: Mon, 19 May 2003 02:06:34 +0000 Subject: add article.readfn.pl git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@876 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/pttpi/cgi/t/article.readfn.pl | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 pttbbs/pttpi/cgi/t/article.readfn.pl diff --git a/pttbbs/pttpi/cgi/t/article.readfn.pl b/pttbbs/pttpi/cgi/t/article.readfn.pl new file mode 100644 index 00000000..e2d0bc27 --- /dev/null +++ b/pttbbs/pttpi/cgi/t/article.readfn.pl @@ -0,0 +1,15 @@ +#!/usr/bin/perl +# $Id: article.readfn.pl,v 1.1 2003/05/19 02:06:34 in2 Exp $ +use Frontier::Client; +use Frontier::RPC2; +use MIME::Base64; +use Data::Dumper; +do 'host.pl'; + +$bid = $ARGV[0] || 0; +$fn = $ARGV[1] || 'M.1047292518.A.48E'; + +$server = Frontier::Client->new(url => $server_url); +$result = $server->call('article.readfn', $bid, $fn); + +print decode_base64($result->{content}->value()); -- cgit v1.2.3 From c98b14d3f6279f7ee5a1f294feb0a8395ea6281b Mon Sep 17 00:00:00 2001 From: in2 Date: Mon, 19 May 2003 02:39:58 +0000 Subject: use Base64 in BM git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@877 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/pttpi/cgi/pttpi.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pttbbs/pttpi/cgi/pttpi.c b/pttbbs/pttpi/cgi/pttpi.c index 187c4f63..dbaf75ce 100644 --- a/pttbbs/pttpi/cgi/pttpi.c +++ b/pttbbs/pttpi/cgi/pttpi.c @@ -1,4 +1,4 @@ -/* $Id: pttpi.c,v 1.1 2003/05/19 01:33:00 in2 Exp $ */ +/* $Id: pttpi.c,v 1.2 2003/05/19 02:39:58 in2 Exp $ */ #include "bbs.h" #include "pierr.h" #include @@ -47,12 +47,12 @@ getBrdInfo(xmlrpc_env *env, xmlrpc_value *param_array, void *user_data) errorexit(); check_board_and_permission(bid); - return xmlrpc_build_value(env, "{s:i,s:s,s:i,s:6,s:s,s:i}", + return xmlrpc_build_value(env, "{s:i,s:s,s:i,s:6,s:6,s:i}", "errno", PIERR_OK, "brdname", bcache[bid].brdname, "bid", (int32)bid, "title", bcache[bid].title, strlen(bcache[bid].title), - "BM", bcache[bid].BM, + "BM", bcache[bid].BM, strlen(bcache[bid].BM), "nuser", bcache[bid].nuser); } -- cgit v1.2.3 From 4a59e6165e8d7a117f68dfdcf14be1a9c9ed9106 Mon Sep 17 00:00:00 2001 From: in2 Date: Mon, 19 May 2003 03:21:32 +0000 Subject: security fix git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@878 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/pttpi/cgi/pttpi.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pttbbs/pttpi/cgi/pttpi.c b/pttbbs/pttpi/cgi/pttpi.c index dbaf75ce..7c9fd766 100644 --- a/pttbbs/pttpi/cgi/pttpi.c +++ b/pttbbs/pttpi/cgi/pttpi.c @@ -1,4 +1,4 @@ -/* $Id: pttpi.c,v 1.2 2003/05/19 02:39:58 in2 Exp $ */ +/* $Id: pttpi.c,v 1.3 2003/05/19 03:21:32 in2 Exp $ */ #include "bbs.h" #include "pierr.h" #include @@ -12,7 +12,7 @@ typedef xmlrpc_int32 int32; if( bid < 0 || bid > MAX_BOARD || \ !bcache[bid].brdname[0] || \ (bcache[bid].brdattr & BRD_HIDE) || \ - (!(bcache[bid].brdattr & BRD_GROUPBOARD) && \ + (bcache[bid].level && \ (bcache[bid].brdattr & BRD_POSTMASK)) ) \ return xmlrpc_build_value(env, "{s:i}", \ "errno", PIERR_NOBRD); -- cgit v1.2.3 From 1ec7641a10a3a05075a9e8ba3433e6419a43a23d Mon Sep 17 00:00:00 2001 From: in2 Date: Mon, 19 May 2003 03:52:33 +0000 Subject: security fix git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@879 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/pttpi/cgi/pttpi.c | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/pttbbs/pttpi/cgi/pttpi.c b/pttbbs/pttpi/cgi/pttpi.c index 7c9fd766..1265968b 100644 --- a/pttbbs/pttpi/cgi/pttpi.c +++ b/pttbbs/pttpi/cgi/pttpi.c @@ -1,4 +1,4 @@ -/* $Id: pttpi.c,v 1.3 2003/05/19 03:21:32 in2 Exp $ */ +/* $Id: pttpi.c,v 1.4 2003/05/19 03:52:33 in2 Exp $ */ #include "bbs.h" #include "pierr.h" #include @@ -8,12 +8,18 @@ extern SHM_t *SHM; typedef xmlrpc_int32 int32; #define errorexit() if( env->fault_occurred ) return NULL -#define check_board_and_permission(bid) \ - if( bid < 0 || bid > MAX_BOARD || \ - !bcache[bid].brdname[0] || \ - (bcache[bid].brdattr & BRD_HIDE) || \ - (bcache[bid].level && \ - (bcache[bid].brdattr & BRD_POSTMASK)) ) \ +int check_board_and_permission(int bid) +{ + return (bid < 0 || bid > MAX_BOARD || + !bcache[bid].brdname[0] || + (bcache[bid].brdattr & BRD_HIDE) || + (bcache[bid].level && !(bcache[bid].brdattr & BRD_POSTMASK) && + (bcache[bid].level & + ~(PERM_BASIC|PERM_CHAT|PERM_PAGE|PERM_POST|PERM_LOGINOK)))); +} + +#define check_bp_return(bid) \ + if( check_board_and_permission(bid) ) \ return xmlrpc_build_value(env, "{s:i}", \ "errno", PIERR_NOBRD); @@ -45,7 +51,7 @@ getBrdInfo(xmlrpc_env *env, xmlrpc_value *param_array, void *user_data) xmlrpc_parse_value(env, param_array, "(i)", &bid); errorexit(); - check_board_and_permission(bid); + check_bp_return(bid); return xmlrpc_build_value(env, "{s:i,s:s,s:i,s:6,s:6,s:i}", "errno", PIERR_OK, @@ -91,7 +97,7 @@ getNarticle(xmlrpc_env *env, xmlrpc_value *param_array, void *user_data) xmlrpc_parse_value(env, param_array, "(i)", &bid); errorexit(); - check_board_and_permission(bid); + check_bp_return(bid); nas = getfilesize(bid, ".DIR", NULL); return xmlrpc_build_value(env, "{s:i,s:i}", @@ -110,7 +116,7 @@ class_list(xmlrpc_env *env, xmlrpc_value *param_array, void *user_data) errorexit(); if( bid != 0 ) - check_board_and_permission(bid); + check_bp_return(bid); if( bid != 0 && !(bcache[bid].brdattr & BRD_GROUPBOARD) ) errorreturn(PIERR_NOTCLASS); @@ -119,8 +125,7 @@ class_list(xmlrpc_env *env, xmlrpc_value *param_array, void *user_data) for( bptr = bcache[bid].firstchild[0] ; bptr != (boardheader_t*)~0 ; bptr = bptr->next[0] ){ - if( (bptr->brdattr & BRD_HIDE) || - (bptr->level && !bptr->brdattr & BRD_POSTMASK) ) + if( check_board_and_permission(bptr - bcache) ) continue; t = xmlrpc_build_value(env, "{s:i,s:s,s:6,s:i,s:6,s:i,s:b}", "bid", (int32)(bptr - bcache), @@ -147,7 +152,7 @@ article_list(xmlrpc_env *env, xmlrpc_value *param_array, void *user_data) xmlrpc_parse_value(env, param_array, "(ii)", &bid, &from); errorexit(); - check_board_and_permission(bid); + check_bp_return(bid); if( (nArticles = getfilesize(bid, ".DIR", &fd)) < 0 ) errorreturn(PIERR_INT); @@ -213,7 +218,7 @@ article_readfn(xmlrpc_env *env, xmlrpc_value *param_array, void *user_data) if( fn == NULL || fn[0] != 'M' || fn[1] != '.' ) errorreturn(PIERR_NOBRD); - check_board_and_permission(bid); + check_bp_return(bid); return _article_readfn(env, bid, fn); } -- cgit v1.2.3 From 48bf3a18a8c928b685fbf6d300d405fe34c36c9a Mon Sep 17 00:00:00 2001 From: in2 Date: Mon, 19 May 2003 05:15:36 +0000 Subject: filename ^G. is vaild git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@880 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/pttpi/cgi/pttpi.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pttbbs/pttpi/cgi/pttpi.c b/pttbbs/pttpi/cgi/pttpi.c index 1265968b..1e452f68 100644 --- a/pttbbs/pttpi/cgi/pttpi.c +++ b/pttbbs/pttpi/cgi/pttpi.c @@ -1,4 +1,4 @@ -/* $Id: pttpi.c,v 1.4 2003/05/19 03:52:33 in2 Exp $ */ +/* $Id: pttpi.c,v 1.5 2003/05/19 05:15:36 in2 Exp $ */ #include "bbs.h" #include "pierr.h" #include @@ -216,7 +216,7 @@ article_readfn(xmlrpc_env *env, xmlrpc_value *param_array, void *user_data) xmlrpc_parse_value(env, param_array, "(is)", &bid, &fn); errorexit(); - if( fn == NULL || fn[0] != 'M' || fn[1] != '.' ) + if( fn == NULL || (fn[0] != 'M' && fn[0] != 'G') || fn[1] != '.' ) errorreturn(PIERR_NOBRD); check_bp_return(bid); -- cgit v1.2.3 From c3a05e2e298282775ad058dad4a4f5591a7836b7 Mon Sep 17 00:00:00 2001 From: in2 Date: Mon, 19 May 2003 07:10:19 +0000 Subject: warning for SaveEMail git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@881 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/mail.c | 10 +++++++--- pttbbs/mbbsd/menu.c | 4 ++-- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/pttbbs/mbbsd/mail.c b/pttbbs/mbbsd/mail.c index d2a84154..70549fbe 100644 --- a/pttbbs/mbbsd/mail.c +++ b/pttbbs/mbbsd/mail.c @@ -1,4 +1,4 @@ -/* $Id: mail.c,v 1.26 2003/02/02 10:31:35 kcwu Exp $ */ +/* $Id: mail.c,v 1.27 2003/05/19 07:10:19 in2 Exp $ */ #include "bbs.h" char currmaildir[32]; static char msg_cc[] = "\033[32m[群組名單]\033[m\n"; @@ -46,8 +46,12 @@ built_mail_index() { char genbuf[128]; - getdata(b_lines, 0, - "重建信箱?(警告:請確定信箱有問題時才使用)(y/N)", genbuf, 3, + move(b_lines - 4, 0); + outs("本功\能只在信箱檔毀損時使用,\033[1;33m無法\033[m救回被刪除的信件。\n" + "除非您清楚這個功\能的作用,否則\033[1;33m請不要使用\033[m。\n" + "警告:任意的使用將導致\033[1;33m不可預期的結果\033[m!\n"); + getdata(b_lines - 1, 0, + "確定重建信箱?(y/N)", genbuf, 3, LCECHO); if (genbuf[0] != 'y') return 0; diff --git a/pttbbs/mbbsd/menu.c b/pttbbs/mbbsd/menu.c index 4455605c..5cd8c132 100644 --- a/pttbbs/mbbsd/menu.c +++ b/pttbbs/mbbsd/menu.c @@ -1,4 +1,4 @@ -/* $Id: menu.c,v 1.24 2003/03/31 08:27:50 in2 Exp $ */ +/* $Id: menu.c,v 1.25 2003/05/19 07:10:19 in2 Exp $ */ #include "bbs.h" /* help & menu processring */ @@ -343,7 +343,7 @@ static commands_t maillist[] = { {m_sysop, 0, "YYes, sir! 諂媚站長"}, {m_internet, PERM_INTERNET, "RInternet 寄信到 Internet"}, {mail_mbox, PERM_INTERNET, "RZip UserHome 把所有私人資料打包回去"}, - {built_mail_index, PERM_LOGINOK, "SSavemail 把信件救回來"}, + {built_mail_index, PERM_LOGINOK, "SSavemail 重建信箱索引"}, {mail_all, PERM_SYSOP, "RAll 寄信給所有使用者"}, {NULL, 0, NULL} }; -- cgit v1.2.3 From acfb1e1978e90543a64b19827a341f2f435f7fb6 Mon Sep 17 00:00:00 2001 From: in2 Date: Mon, 19 May 2003 07:12:39 +0000 Subject: PttSrc -> PttCurrent git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@882 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/sample/etc/Welcome_login | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pttbbs/sample/etc/Welcome_login b/pttbbs/sample/etc/Welcome_login index e5560602..8a2fe993 100644 --- a/pttbbs/sample/etc/Welcome_login +++ b/pttbbs/sample/etc/Welcome_login @@ -9,4 +9,4 @@ 歡迎使用 PttBBS ! - 有任何問題請到 ptt2.csie.ntu.edu.tw 的 PttSrc 板討論唷! + 有任何問題請到 ptt.csie.ntu.edu.tw 的 PttCurrent 板討論唷! -- cgit v1.2.3 From d961ad0c11580ffc52bf44bdf2c5676677a5b58b Mon Sep 17 00:00:00 2001 From: bbs Date: Tue, 20 May 2003 01:51:01 +0000 Subject: search_ulist_userid() git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@883 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/bbs.c | 8 +++++++- pttbbs/mbbsd/cache.c | 27 ++++++++++++++++++++++++++- 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/pttbbs/mbbsd/bbs.c b/pttbbs/mbbsd/bbs.c index 01324b22..7129703e 100644 --- a/pttbbs/mbbsd/bbs.c +++ b/pttbbs/mbbsd/bbs.c @@ -1,4 +1,4 @@ -/* $Id: bbs.c,v 1.94 2003/05/18 13:42:55 victor Exp $ */ +/* $Id: bbs.c,v 1.95 2003/05/20 01:51:01 bbs Exp $ */ #include "bbs.h" static int recommend(int ent, fileheader_t * fhdr, char *direct); @@ -170,10 +170,16 @@ readdoent(int num, fileheader_t * ent) if (!strncmp(title, "[公告]", 6)) special = 1; +#if 1 + if (!strchr(ent->owner, '.') && !SHM->GV2.e.noonlineuser && + (uentp = search_ulist_userid(ent->owner)) && isvisible(currutmp, uentp)) + isonline = 1; +#else if (!strchr(ent->owner, '.') && (uid = searchuser(ent->owner)) && !SHM->GV2.e.noonlineuser && (uentp = search_ulist(uid)) && isvisible(currutmp, uentp)) isonline = 1; +#endif if (strncmp(currtitle, title, TTLEN)) prints("%6d %c\033[1;32m%c\033[m%-6s\033[%dm%-13.12s\033[m%s " diff --git a/pttbbs/mbbsd/cache.c b/pttbbs/mbbsd/cache.c index 3a011825..a5c6c43c 100644 --- a/pttbbs/mbbsd/cache.c +++ b/pttbbs/mbbsd/cache.c @@ -1,4 +1,4 @@ -/* $Id: cache.c,v 1.60 2003/02/27 05:52:51 in2 Exp $ */ +/* $Id: cache.c,v 1.61 2003/05/20 01:51:01 bbs Exp $ */ #include "bbs.h" #ifndef __FreeBSD__ @@ -432,6 +432,31 @@ search_ulistn(int uid, int unum) } return 0; } +userinfo_t * +search_ulist_userid(char *userid) +{ + register int i = 0, j, start = 0, end = SHM->UTMPnumber - 1; + register userinfo_t **ulist; + if (end == -1) + return NULL; + ulist = SHM->sorted[SHM->currsorted][0]; + for (i = ((start + end) / 2);; i = (start + end) / 2) { + j = strcasecmp(userid, ulist[i]->userid); + if (!j) { + return (userinfo_t *) (ulist[i]); + } + if (end == start) { + break; + } else if (i == start) { + i = end; + start = end; + } else if (j > 0) + start = i; + else + end = i; + } + return 0; +} int count_logins(int uid, int show) -- cgit v1.2.3 From 5a2cdcadcc3d0c32dccf7f7927da0c17da4a558e Mon Sep 17 00:00:00 2001 From: bbs Date: Tue, 20 May 2003 02:01:09 +0000 Subject: search_ulist_userid() git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@884 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/include/proto.h | 3 ++- pttbbs/mbbsd/mbbsd.c | 9 ++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/pttbbs/include/proto.h b/pttbbs/include/proto.h index c0c2326e..3aae3190 100644 --- a/pttbbs/include/proto.h +++ b/pttbbs/include/proto.h @@ -1,4 +1,4 @@ -/* $Id: proto.h,v 1.41 2003/05/18 07:46:37 in2 Exp $ */ +/* $Id: proto.h,v 1.42 2003/05/20 02:01:09 bbs Exp $ */ #ifndef INCLUDE_PROTO_H #define INCLUDE_PROTO_H @@ -115,6 +115,7 @@ void add_to_uhash(int n, char *id); int setumoney(int uid, int money); int getbtotal(int bid); userinfo_t *search_ulist_pid(int pid); +userinfo_t *search_ulist_userid(int userid); int moneyof(int uid); void hbflreload(int bid); int hbflcheck(int bid, int uid); diff --git a/pttbbs/mbbsd/mbbsd.c b/pttbbs/mbbsd/mbbsd.c index 9498f963..c8bfec24 100644 --- a/pttbbs/mbbsd/mbbsd.c +++ b/pttbbs/mbbsd/mbbsd.c @@ -1,4 +1,4 @@ -/* $Id: mbbsd.c,v 1.79 2003/05/18 07:31:09 in2 Exp $ */ +/* $Id: mbbsd.c,v 1.80 2003/05/20 02:01:09 bbs Exp $ */ #include "bbs.h" #define SOCKET_QLEN 4 @@ -916,11 +916,18 @@ do_aloha(char *hello) userinfo_t *uentp; int tuid; +#if 1 + if ((uentp = (userinfo_t *) search_ulist_userid(userid)) && + isvisible(uentp, currutmp)) { + my_write(uentp->pid, genbuf, uentp->userid, 2, NULL); + } +#else if ((tuid = searchuser(userid)) && tuid != usernum && (uentp = (userinfo_t *) search_ulist(tuid)) && isvisible(uentp, currutmp)) { my_write(uentp->pid, genbuf, uentp->userid, 2, NULL); } +#endif } fclose(fp); } -- cgit v1.2.3 From 6c5cba4d0c51cf289cb2249b79546a9273a60a91 Mon Sep 17 00:00:00 2001 From: bbs Date: Tue, 20 May 2003 02:03:35 +0000 Subject: :p git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@885 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/include/proto.h | 4 ++-- pttbbs/mbbsd/mbbsd.c | 10 +--------- 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/pttbbs/include/proto.h b/pttbbs/include/proto.h index 3aae3190..298f0a2b 100644 --- a/pttbbs/include/proto.h +++ b/pttbbs/include/proto.h @@ -1,4 +1,4 @@ -/* $Id: proto.h,v 1.42 2003/05/20 02:01:09 bbs Exp $ */ +/* $Id: proto.h,v 1.43 2003/05/20 02:03:35 bbs Exp $ */ #ifndef INCLUDE_PROTO_H #define INCLUDE_PROTO_H @@ -115,7 +115,7 @@ void add_to_uhash(int n, char *id); int setumoney(int uid, int money); int getbtotal(int bid); userinfo_t *search_ulist_pid(int pid); -userinfo_t *search_ulist_userid(int userid); +userinfo_t *search_ulist_userid(char *userid); int moneyof(int uid); void hbflreload(int bid); int hbflcheck(int bid, int uid); diff --git a/pttbbs/mbbsd/mbbsd.c b/pttbbs/mbbsd/mbbsd.c index c8bfec24..688bd0c9 100644 --- a/pttbbs/mbbsd/mbbsd.c +++ b/pttbbs/mbbsd/mbbsd.c @@ -1,4 +1,4 @@ -/* $Id: mbbsd.c,v 1.80 2003/05/20 02:01:09 bbs Exp $ */ +/* $Id: mbbsd.c,v 1.81 2003/05/20 02:03:35 bbs Exp $ */ #include "bbs.h" #define SOCKET_QLEN 4 @@ -916,18 +916,10 @@ do_aloha(char *hello) userinfo_t *uentp; int tuid; -#if 1 if ((uentp = (userinfo_t *) search_ulist_userid(userid)) && isvisible(uentp, currutmp)) { my_write(uentp->pid, genbuf, uentp->userid, 2, NULL); } -#else - if ((tuid = searchuser(userid)) && tuid != usernum && - (uentp = (userinfo_t *) search_ulist(tuid)) && - isvisible(uentp, currutmp)) { - my_write(uentp->pid, genbuf, uentp->userid, 2, NULL); - } -#endif } fclose(fp); } -- cgit v1.2.3 From 8cb3ba350919426b51ad9774e6bd67fbacc1cd22 Mon Sep 17 00:00:00 2001 From: in2 Date: Thu, 22 May 2003 01:06:11 +0000 Subject: warning free git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@886 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/mbbsd.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/pttbbs/mbbsd/mbbsd.c b/pttbbs/mbbsd/mbbsd.c index 688bd0c9..e5815c2d 100644 --- a/pttbbs/mbbsd/mbbsd.c +++ b/pttbbs/mbbsd/mbbsd.c @@ -1,4 +1,4 @@ -/* $Id: mbbsd.c,v 1.81 2003/05/20 02:03:35 bbs Exp $ */ +/* $Id: mbbsd.c,v 1.82 2003/05/22 01:06:11 in2 Exp $ */ #include "bbs.h" #define SOCKET_QLEN 4 @@ -914,8 +914,6 @@ do_aloha(char *hello) snprintf(genbuf, sizeof(genbuf), hello); while (fgets(userid, 80, fp)) { userinfo_t *uentp; - int tuid; - if ((uentp = (userinfo_t *) search_ulist_userid(userid)) && isvisible(uentp, currutmp)) { my_write(uentp->pid, genbuf, uentp->userid, 2, NULL); -- cgit v1.2.3 From 0188e9da95e59a4024f3a2d6c27d5d1980a147ef Mon Sep 17 00:00:00 2001 From: in2 Date: Thu, 22 May 2003 01:16:45 +0000 Subject: (C)alendarEdit -> (E)ditCalendar suggested by Sunicer git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@887 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/menu.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pttbbs/mbbsd/menu.c b/pttbbs/mbbsd/menu.c index 5cd8c132..d7984950 100644 --- a/pttbbs/mbbsd/menu.c +++ b/pttbbs/mbbsd/menu.c @@ -1,4 +1,4 @@ -/* $Id: menu.c,v 1.25 2003/05/19 07:10:19 in2 Exp $ */ +/* $Id: menu.c,v 1.26 2003/05/22 01:16:45 in2 Exp $ */ #include "bbs.h" /* help & menu processring */ @@ -387,7 +387,7 @@ static commands_t namelist[] = { static commands_t userlist[] = { {u_info, PERM_LOGINOK, "IInfo 設定個人資料與密碼"}, {calendar, PERM_LOGINOK, "CCalendar 個人行事曆"}, - {u_editcalendar, PERM_LOGINOK, "CCalendarEdit 編輯個人行事曆"}, + {u_editcalendar, PERM_LOGINOK, "EEditCalendar 編輯個人行事曆"}, {u_loginview, PERM_LOGINOK, "LLogin View 選擇進站畫面"}, {u_ansi, 0, "AANSI 切換 ANSI \033[36m彩\033[35m色\033[37m/" "\033[30;47m黑\033[1;37m白\033[m模示"}, -- cgit v1.2.3 From b13df7e1224d41f413133f054257d7350690fd4f Mon Sep 17 00:00:00 2001 From: in2 Date: Fri, 23 May 2003 00:58:32 +0000 Subject: add dir 'run' add warning if not first time git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@888 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/initbbs.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/pttbbs/util/initbbs.c b/pttbbs/util/initbbs.c index 8d95534c..72988353 100644 --- a/pttbbs/util/initbbs.c +++ b/pttbbs/util/initbbs.c @@ -1,4 +1,4 @@ -/* $Id: initbbs.c,v 1.5 2002/10/26 18:30:44 in2 Exp $ */ +/* $Id: initbbs.c,v 1.6 2003/05/23 00:58:32 in2 Exp $ */ #include #include #include @@ -18,6 +18,7 @@ static void initDir() { mkdir("man/boards", 0755); mkdir("out", 0755); mkdir("tmp", 0755); + mkdir("run", 0755); } static void initHome() { @@ -233,7 +234,16 @@ static void initHistory() { } } -int main() { +int main(int argc, char **argv) +{ + if( argc != 2 || strcmp(argv[1], "-DoIt") != 0 ){ + fprintf(stderr, + "警告! initbbs只用在「第一次安裝」的時候.\n" + "若您的站台已經上線, initbbs將會破壞掉原有資料!\n\n" + "確定要執行, 請使用 initbbs -DoIt\n"); + return 1; + } + if(chdir(BBSHOME)) { perror(BBSHOME); exit(1); -- cgit v1.2.3 From 44877d2b78ae0732be61f1de873b298361409ef8 Mon Sep 17 00:00:00 2001 From: in2 Date: Fri, 23 May 2003 09:02:26 +0000 Subject: add BBSFileHeader.pm, builddb.pl git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@889 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/blog/BBSFileHeader.pm | 56 ++++++++++++++++++ pttbbs/blog/builddb.pl | 135 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 191 insertions(+) create mode 100644 pttbbs/blog/BBSFileHeader.pm create mode 100755 pttbbs/blog/builddb.pl diff --git a/pttbbs/blog/BBSFileHeader.pm b/pttbbs/blog/BBSFileHeader.pm new file mode 100644 index 00000000..4865da8b --- /dev/null +++ b/pttbbs/blog/BBSFileHeader.pm @@ -0,0 +1,56 @@ +#!/usr/bin/perl +package BBSFileHeader; +use strict; +use IO::Handle; +use Data::Dumper; + +use fields qw/dir fh cache/; + +sub TIEHASH +{ + my($class, $dir) = @_; + my $self = fields::new($class); + + open $self->{fh}, "<$dir/.DIR"; + return undef if( !$self->{fh} ); + + $self->{dir} = $dir; + return $self; +} + +sub FETCH +{ + my($self, $k) = @_; + + return $self->{dir} if( $k eq 'dir' ); + return ((-s "$self->{dir}/.DIR") / 128) if( $k eq 'num' ); + + my($num, $key) = $k =~ /(.*)\.(.*)/; + my($t, %h); + + $num += $self->FETCH('num') if( $num < 0 ); + + return $self->{cache}{$num}{$key} if( $self->{cache}{$num}{$key} ); + + seek($self->{fh}, $num * 128, 0); + $self->{fh}->read($t, 128); + + if( $key eq 'isdir' ){ + my $fn = "$self->{dir}/" . $self->FETCH("$num.filename"); + return (-d $fn); + } + elsif( $key eq 'content' ){ + my $fn = "$self->{dir}/" . $self->FETCH("$num.filename"); + return `/bin/cat $fn`; + } + else{ + ($h{filename}, $h{recommend}, $h{owner}, $h{date}, $h{title}) = + unpack('Z33cZ14Z6Z65', $t); + $h{title} = substr($h{title}, 3); + $self->{cache}{$num}{$_} = $h{$_} + foreach( 'filename', 'owner', 'date', 'title' ); + return $h{$key}; + } +} + +1; diff --git a/pttbbs/blog/builddb.pl b/pttbbs/blog/builddb.pl new file mode 100755 index 00000000..18660e48 --- /dev/null +++ b/pttbbs/blog/builddb.pl @@ -0,0 +1,135 @@ +#!/usr/bin/perl +use strict; +use Getopt::Std; +use LocalVars; +use IO::Handle; +use Data::Dumper; +use BBSFileHeader; +use DB_File; + +sub main +{ + my($fh); + die usage() unless( getopts('ca') ); + die usage() if( !@ARGV ); + builddb($_) foreach( @ARGV ); +} + +sub usage +{ + return ("$0 [-ca] [board ...]\n". + "\t-c build configure\n". + "\t-a rebuild all files\n"); +} + +sub builddb($) +{ + my($board) = @_; + my(%bh, %ch); + + print "building $board\n"; + return if( !getdir("$BBSHOME/man/boards/".substr($board,0,1)."/$board", + \%bh, \%ch) ); + buildconfigure($board, \%ch) + if( $Getopt::Std::opt_c || $Getopt::Std::opt_a ); + builddata($board, \%bh, $Getopt::Std::opt_a); +} + +sub buildconfigure($$) +{ + my($board, $rch) = @_; + my($outdir, $fn, $flag, %config, %attr); + + $outdir = "$BLOGROOT/$board"; + `/bin/rm -rf $outdir; /bin/mkdir -p $outdir`; + + tie(%config, 'DB_File', "$outdir/config.db", + O_CREAT | O_RDWR, 0666, $DB_HASH); + tie(%attr, 'DB_File', "$outdir/attr.db", + O_CREAT | O_RDWR, 0666, $DB_HASH); + + for ( 0..($rch->{num} - 1) ){ + print "\texporting ".$rch->{"$_.title"}."\n"; + if( $rch->{"$_.title"} =~ /^config$/i ){ + foreach( split("\n", $rch->{"$_.content"}) ){ + $config{$1} = $2 if( /(.*?):\s*(.*)/ ); + } + } + else{ + my(@ls, $t); + + @ls = split("\n", $rch->{"$_.content"}); + open FH, ">$outdir/". $rch->{"$_.title"}; + if( $rch->{"$_.title"} =~ /\.html$/ ){ + while( $t = shift @ls ){ + last if( $t !~ /^\*/ ); + $attr{($rch->{"$_.title"}. ".$1")} = $2 + if( $t =~ /^\*\s+(\w+): (.*)/ ); + } + unshift @ls, $t; + } + print FH "$_\n" + foreach( @ls ); + } + } + print Dumper(\%config); + print Dumper(\%attr); +} + +sub builddata($$$) +{ + my($board, $rbh, $rebuild) = @_; + my(%dat, $dbfn, $y, $m, $d, $t, $currid); + + $dbfn = "$BLOGROOT/$board.db"; + unlink $dbfn if( $rebuild ); + + tie %dat, 'DB_File', $dbfn, O_CREAT | O_RDWR, 0666, $DB_HASH; + foreach( 1..($rbh->{num} - 1) ){ + if( ($y, $m, $d, $t) = + $rbh->{"$_.title"} =~ /(\d+)\.(\d+).(\d+),(.*)/ ){ + + $currid = sprintf('%04d%02d%02d', $y, $m, $d); + if( $currid <= $dat{last} ){ + print "\t$currid skipped\n"; + } + else{ + $dat{ sprintf('%04d%02d', $y, $m) } = 1; + $dat{"$currid.title"} = $t; + $dat{"$currid.content"} = $rbh->{"$_.content"}; + $dat{"$currid.author"} = $rbh->{"$_.owner"}; + $dat{"$currid.prev"} = $dat{'last'}; + $dat{"$dat{last}.next"} = $currid + if( $dat{'last'} ); + $dat{'last'} = $currid; + $dat{head} = $currid if( !$dat{head} ); + print "\t${currid} built\n"; + } + } + } + untie %dat; +} + +sub getdir($$$$$) +{ + my($bdir, $rh_bh, $rh_ch) = @_; + my(%h); + tie %h, 'BBSFileHeader', "$bdir/"; + if( $h{"-1.title"} !~ /blog/i || !$h{"-1.isdir"} ){ + print "blogdir not found\n"; + return; + } + + tie %{$rh_bh}, 'BBSFileHeader', "$bdir/". $h{'-1.filename'}.'/'; + if( $rh_bh->{'0.title'} !~ /configure/i || + !$rh_bh->{'0.isdir'} ){ + print "configure not found\n"; + return; + } + + tie %{$rh_ch}, 'BBSFileHeader', $rh_bh->{dir}. '/'. $rh_bh->{'0.filename'}; + return 1; +} + +main(); +1; -- cgit v1.2.3 From e7f4a00757b9a0b97a386adb68180497238a3694 Mon Sep 17 00:00:00 2001 From: in2 Date: Fri, 23 May 2003 09:02:52 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@890 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/blog/blog.pl | 144 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 144 insertions(+) create mode 100755 pttbbs/blog/blog.pl diff --git a/pttbbs/blog/blog.pl b/pttbbs/blog/blog.pl new file mode 100755 index 00000000..30577d14 --- /dev/null +++ b/pttbbs/blog/blog.pl @@ -0,0 +1,144 @@ +#!/usr/bin/perl +use CGI qw/:standard/; +use LocalVars; +use DB_File; +use strict; +use Data::Dumper; +use Date::Calc qw(:all); +use Template; + +sub main +{ + my($brdname, $fn, %config, %attr, %article, $y, $m, $d); + my($tmpl, %th); + + my @emonth = ('', 'January', 'February', 'March', 'April', 'May', + 'June', 'July', 'August', 'September', 'October', + 'November', 'December'); + my @cnumber = ('零', '一', '二', '三', '四', '五', '六', + '七', '八', '九', '十', '十一', '十二'); + + if( !$ENV{PATH_INFO} ){ + print header(-status => 400); + return; + } + if( !(($brdname, $fn) = $ENV{PATH_INFO} =~ m|/(\w+?)/([\.,\w]*)|) || + !( ($fn, $y, $m, $d) = parsefn($fn) ) || + !(-e "$BLOGDATA/$brdname/$fn") || + !(tie %config, 'DB_File', + "$BLOGDATA/$brdname/config.db", O_RDONLY, 0666, $DB_HASH) || + !(tie %attr, 'DB_File', + "$BLOGDATA/$brdname/attr.db", O_RDONLY, 0666, $DB_HASH) ){ + print header(-status => 404); + return; + } + + charset(''); + print header(-type => GetType($fn)); + $fn ||= 'index.html'; + + # first, import all settings in %config + %th = %config; + + # loadBlog --------------------------------------------------------------- + tie %article, 'DB_File', "$BLOGDATA/$brdname.db", O_RDONLY, 0666, $DB_HASH; + if( $attr{"$fn.loadBlog"} =~ /month/i ){ + my($s, $y1, $m1, $d1); + for( ($y1, $m1, $d1) = ($y, $m, 32) ; $d1 > 0 ; --$d1 ){ + AddArticle('blog', $y1, $m1, $d1, + \%th, \%article, \@emonth, \@cnumber); + } + } + + # loadArchives ----------------------------------------------------------- + if( $attr{"$fn.loadArchives"} =~ /^monthly/i ){ + # 找尋 +-1 year 內有資料的月份 + my($c, $y1, $m1); + for( $c = 0, ($y1, $m1) = ($y + 1, $m) ; + $c < 48 ; + ++$c, --$m1 ) { + + if( $m1 == 0 ){ $m1 = 12; --$y1; } + if( $article{ sprintf('%04d%02d', $y1, $m1) } ){ + push @{$th{Archives}}, {year => $y1, month => $m1, + emonth => $emonth[$m1], + cmonth => $cnumber[$m1], + key => packdate($y1, $m1, 1)}; + } + } + } + + # loadRecentEntries ------------------------------------------------------ + if( $attr{"$fn.loadRecentEntries"} ){ + my($i, $ptr, $y, $m, $d); + print $attr{"$fn.loadRecentEntries:"}; + for( $i = 0, $ptr = $article{'last'} ; + $ptr && $i < $attr{"$fn.loadRecentEntries"} ; + ++$i, $ptr = $article{"$ptr.prev"} ){ + ($y, $m, $d) = unpackdate($ptr); + push @{$th{RecentEntries}}, {year => $y, month => $m, + emonth => $emonth[$m], + cmonth => $cnumber[$m], + title => $article{"$ptr.title"}, + key => $ptr}; + } + } + + # output + $tmpl = Template->new({INCLUDE_PATH => '.', + ABSOLUTE => 0, + RELATIVE => 0, + RECURSION => 0, + EVAL_PERL => 0, + }); + chdir "$BLOGDATA/$brdname/"; + $tmpl->process($fn, \%th) || + print "

template error: ". $tmpl->error();
+}
+
+sub AddArticle($$$$$$$$)
+{
+    my($cl, $y, $m, $d, $th, $article, $emonth, $cnumber) = @_;
+    my $s = packdate($y, $m, $d);
+    push @{$th->{$cl}}, {year   => $y,
+		       month  => $m,
+		       emonth => $emonth->[$m],
+		       cmonth => $cnumber->[$m],
+		       day    => $d,
+		       key    => $s,
+		       title  => $article->{"$s.title"},
+		       body   => $article->{"$s.content"},
+		       author => $article->{"$s.author"}}
+    if( $article->{"$s.title"} );
+}
+
+sub parsefn($)
+{
+    my($fs) = @_;
+    return ("$1.$3", unpackdate($2))
+	if( $fs =~ /^(.*),(\w+)\.(.*)$/ );
+    return ($fs, Today());
+}
+
+sub GetType($)
+{
+    my($f) = @_;
+    return 'text/css' if( $f =~ /.css$/i );
+    return 'text/html';
+}
+
+sub packdate($$$)
+{
+    return $_[0] * 10000 + $_[1] * 100 + $_[2];
+}
+
+sub unpackdate($)
+{
+    return (int($_[0] / 10000),
+	    (int($_[0] / 100)) % 100,
+	    $_[0] % 100);
+}
+
+main();
+1;
+
-- 
cgit v1.2.3


From 945684d92cb89151c40b7ac5e8c76ce879e745cf Mon Sep 17 00:00:00 2001
From: in2 
Date: Fri, 23 May 2003 09:04:38 +0000
Subject: ignore LocalVars.pm

git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@891 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
---
 pttbbs/blog/.cvsignore | 1 +
 1 file changed, 1 insertion(+)
 create mode 100644 pttbbs/blog/.cvsignore

diff --git a/pttbbs/blog/.cvsignore b/pttbbs/blog/.cvsignore
new file mode 100644
index 00000000..896fc449
--- /dev/null
+++ b/pttbbs/blog/.cvsignore
@@ -0,0 +1 @@
+LocalVars.pm
-- 
cgit v1.2.3


From 898a6e2f39ec2ba4dde67ff8af3d8df39af0031b Mon Sep 17 00:00:00 2001
From: in2 
Date: Fri, 23 May 2003 10:18:15 +0000
Subject: calendar support, XHTML valid

git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@892 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
---
 pttbbs/blog/blog.pl | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 52 insertions(+), 1 deletion(-)

diff --git a/pttbbs/blog/blog.pl b/pttbbs/blog/blog.pl
index 30577d14..f4875b57 100755
--- a/pttbbs/blog/blog.pl
+++ b/pttbbs/blog/blog.pl
@@ -6,6 +6,7 @@ use strict;
 use Data::Dumper;
 use Date::Calc qw(:all);
 use Template;
+use HTML::Calendar::Simple;
 
 sub main
 {
@@ -84,7 +85,57 @@ sub main
 	}
     }
 
-    # output
+    # Calendar ---------------------------------------------------------------
+    if( $attr{"$fn.loadCalendar"} ){
+	# 沒有合適的 module , 自己寫一個 |||b
+	my($c, $week, $day, $t, $link);
+	$c = ("\n".
+	      "\n".
+	      "\n");
+	$c .= ("\n")
+	    foreach( ['Sunday', 'Sun'], ['Monday', 'Mon'],
+		     ['Tuesday', 'Tue'], ['Wednesday', 'Wed'],
+		     ['Thursday', 'Thu'], ['Friday', 'Fri'],
+		     ['Saturday', 'Sat'] );
+
+	$week = Day_of_Week($y, $m, 1);
+	$c .= "\n\n";
+
+	if( $week == 7 ){
+	    $week = 0;
+	}
+	else{
+	    $c .= ("\n")
+		foreach( 1..$week );
+	}
+	foreach( 1..31 ){
+	    $c .= "\n";
+	    if( ++$week == 7 ){
+		$c .= "\n\n\n";
+		$week = 0;
+	    }
+	}
+
+	$c .= "\n
$emonth[$m] $y
[0]\" align=\"center\">". + "$_->[1]
". + " "; + + $t = packdate($y, $m, $_); + if( !$article{"$t.title"} ){ + $c .= "$_"; + } + else{ + my $link = $attr{"$fn.loadCalendar"}; + $link =~ s/\[\% key \%\]/$t/g; + $c .= "$_"; + } + + $c .= "
\n"; + $th{calendar} = $c; + #my $cal = HTML::Calendar::Simple->new({month => $m, year => $y}); + #$th{calendar} = $cal->calendar_month; + } + $tmpl = Template->new({INCLUDE_PATH => '.', ABSOLUTE => 0, RELATIVE => 0, -- cgit v1.2.3 From b832ea1647b29ac449d9b24103c08054b512db1f Mon Sep 17 00:00:00 2001 From: bbs Date: Fri, 23 May 2003 14:52:44 +0000 Subject: build short git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@893 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/blog/builddb.pl | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/pttbbs/blog/builddb.pl b/pttbbs/blog/builddb.pl index 18660e48..66b3ad3b 100755 --- a/pttbbs/blog/builddb.pl +++ b/pttbbs/blog/builddb.pl @@ -96,8 +96,14 @@ sub builddata($$$) else{ $dat{ sprintf('%04d%02d', $y, $m) } = 1; $dat{"$currid.title"} = $t; - $dat{"$currid.content"} = $rbh->{"$_.content"}; $dat{"$currid.author"} = $rbh->{"$_.owner"}; + # $dat{"$currid.content"} = $rbh->{"$_.content"}; + # ugly code for making short + my @c = split("\n", + $dat{"$currid.content"} = $rbh->{"$_.content"}); + $dat{"$currid.short"} = ("$c[0]\n$c[1]\n$c[2]\n". + $c[3] ? '....' : ''); + $dat{"$currid.prev"} = $dat{'last'}; $dat{"$dat{last}.next"} = $currid if( $dat{'last'} ); -- cgit v1.2.3 From 4aed7a4e2912d5005efb1da3882fe92af303e0a7 Mon Sep 17 00:00:00 2001 From: in2 Date: Fri, 23 May 2003 14:53:46 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@894 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/blog/blog.pl | 72 ++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 49 insertions(+), 23 deletions(-) diff --git a/pttbbs/blog/blog.pl b/pttbbs/blog/blog.pl index f4875b57..4f177972 100755 --- a/pttbbs/blog/blog.pl +++ b/pttbbs/blog/blog.pl @@ -8,17 +8,19 @@ use Date::Calc qw(:all); use Template; use HTML::Calendar::Simple; +use vars qw/@emonth @cnumber %config %attr %article %th/; + sub main { - my($brdname, $fn, %config, %attr, %article, $y, $m, $d); - my($tmpl, %th); - - my @emonth = ('', 'January', 'February', 'March', 'April', 'May', - 'June', 'July', 'August', 'September', 'October', - 'November', 'December'); - my @cnumber = ('零', '一', '二', '三', '四', '五', '六', - '七', '八', '九', '十', '十一', '十二'); - + my($brdname, $fn, $y, $m, $d); + my($tmpl); + + @emonth = ('', 'January', 'February', 'March', 'April', 'May', + 'June', 'July', 'August', 'September', 'October', + 'November', 'December'); + @cnumber = ('零', '一', '二', '三', '四', '五', '六', + '七', '八', '九', '十', '十一', '十二'); + if( !$ENV{PATH_INFO} ){ print header(-status => 400); return; @@ -43,14 +45,24 @@ sub main # loadBlog --------------------------------------------------------------- tie %article, 'DB_File', "$BLOGDATA/$brdname.db", O_RDONLY, 0666, $DB_HASH; - if( $attr{"$fn.loadBlog"} =~ /month/i ){ + if( $attr{"$fn.loadBlog"} =~ /article/i ){ + AddArticle('blog', $attr{"$fn.loadBlogFields"}, packdate($y, $m, $d)); + } + elsif( $attr{"$fn.loadBlog"} =~ /month/i ){ my($s, $y1, $m1, $d1); for( ($y1, $m1, $d1) = ($y, $m, 32) ; $d1 > 0 ; --$d1 ){ - AddArticle('blog', $y1, $m1, $d1, - \%th, \%article, \@emonth, \@cnumber); + AddArticle('blog', $attr{"$fn.loadBlogFields"}, + packdate($y1, $m1, $d1)); } } + if( $attr{"$fn.loadBlogPrevNext"} ){ + my $s = packdate($y, $m, $d); + AddArticle('next', $attr{"$fn.loadBlogPrevNext"}, + $article{"$s.next"}); + AddArticle('prev', $attr{"$fn.loadBlogPrevNext"}, + $article{"$s.prev"}); + } # loadArchives ----------------------------------------------------------- if( $attr{"$fn.loadArchives"} =~ /^monthly/i ){ # 找尋 +-1 year 內有資料的月份 @@ -119,7 +131,7 @@ sub main } else{ my $link = $attr{"$fn.loadCalendar"}; - $link =~ s/\[\% key \%\]/$t/g; + $link =~ s/\[\% key \%\]/,$t/g; $c .= "$_"; } @@ -136,6 +148,7 @@ sub main #$th{calendar} = $cal->calendar_month; } + # 用 Template Toolkit 輸出 $tmpl = Template->new({INCLUDE_PATH => '.', ABSOLUTE => 0, RELATIVE => 0, @@ -147,20 +160,33 @@ sub main print "
template error: ". $tmpl->error();
 }
 
-sub AddArticle($$$$$$$$)
+sub AddArticle($$$)
 {
-    my($cl, $y, $m, $d, $th, $article, $emonth, $cnumber) = @_;
-    my $s = packdate($y, $m, $d);
-    push @{$th->{$cl}}, {year   => $y,
+    my($cl, $fields, $s) = @_;
+    my $content = '';
+    if( $fields =~ /content/i ){
+	$content = $article{"$s.content"};
+	if( $config{outputfilter} == 1 ){
+	    $content =~ s/\n/
\n/gs; + } + } + + my($y, $m, $d) = unpackdate($s); + push @{$th{$cl}}, {year => $y, month => $m, - emonth => $emonth->[$m], - cmonth => $cnumber->[$m], + emonth => $emonth[$m], + cmonth => $cnumber[$m], day => $d, key => $s, - title => $article->{"$s.title"}, - body => $article->{"$s.content"}, - author => $article->{"$s.author"}} - if( $article->{"$s.title"} ); + title => (($fields !~ /title/i) ? '' : + $article{"$s.title"}), + content=> $content, + author => (($fields !~ /author/i) ? '' : + $article{"$s.author"}), + short => (($fields !~ /short/i) ? '' : + $article{"$s.short"}), + } + if( $article{"$s.title"} ); } sub parsefn($) -- cgit v1.2.3 From 2fc4460f6b0473b2922b86b6ead146ff33d18918 Mon Sep 17 00:00:00 2001 From: in2 Date: Sat, 24 May 2003 03:45:14 +0000 Subject: use bcache instead getbcache git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@895 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/announce.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/pttbbs/mbbsd/announce.c b/pttbbs/mbbsd/announce.c index 0e4d3fc4..8bd39115 100644 --- a/pttbbs/mbbsd/announce.c +++ b/pttbbs/mbbsd/announce.c @@ -1,4 +1,4 @@ -/* $Id: announce.c,v 1.21 2003/05/16 06:31:33 in2 Exp $ */ +/* $Id: announce.c,v 1.22 2003/05/24 03:45:14 in2 Exp $ */ #include "bbs.h" static void @@ -1431,13 +1431,9 @@ a_menu(char *maintitle, char *path, int lastlevel) case 'c': if (me.now < me.num) { - boardheader_t *bp; if (!isvisible_man(&me)) break; - if( !(bp = getbcache(getbnum(currboard))) ) - break; - snprintf(fname, sizeof(fname), "%s/%s", path, me.header[me.now - me.page].filename); @@ -1447,7 +1443,8 @@ a_menu(char *maintitle, char *path, int lastlevel) 還是檔案竟然是用 fstat(2) 而不是直接存在 .DIR 內 |||b 須等該資料寫入 .DIR 內再 implement才有效率. */ - if( !HAS_PERM(PERM_SYSOP) && !is_BM(bp->BM) && dashd(fname) ) + if( !HAS_PERM(PERM_SYSOP) && !is_BM(bcache[currbid - 1].BM) && + dashd(fname) ) vmsg("只有板主才可以拷貝目錄唷!"); else a_copyitem(fname, me.header[me.now - me.page].title, 0, 1); -- cgit v1.2.3 From 2bcd0c156fdc735cc2482a58dfb50b191bf834cf Mon Sep 17 00:00:00 2001 From: in2 Date: Mon, 26 May 2003 02:00:16 +0000 Subject: add flags: ofn git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@896 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/blog/builddb.pl | 101 ++++++++++++++++++++++++++++++++----------------- 1 file changed, 67 insertions(+), 34 deletions(-) diff --git a/pttbbs/blog/builddb.pl b/pttbbs/blog/builddb.pl index 66b3ad3b..1be4c25a 100755 --- a/pttbbs/blog/builddb.pl +++ b/pttbbs/blog/builddb.pl @@ -10,16 +10,19 @@ use DB_File; sub main { my($fh); - die usage() unless( getopts('ca') ); + die usage() unless( getopts('caofn:') ); die usage() if( !@ARGV ); builddb($_) foreach( @ARGV ); } sub usage { - return ("$0 [-ca] [board ...]\n". - "\t-c build configure\n". - "\t-a rebuild all files\n"); + return ("$0 [-cfao] [-n NUMBER] [board ...]\n". + "\t-c\t\tbuild configure\n". + "\t-a\t\trebuild all files\n". + "\t-o\t\tonly build content(not building link)\n". + "\t-f\t\tforce build\n". + "\t-n NUMBER\tonly build \#NUMBER article\n"); } sub builddb($) @@ -32,7 +35,11 @@ sub builddb($) \%bh, \%ch) ); buildconfigure($board, \%ch) if( $Getopt::Std::opt_c || $Getopt::Std::opt_a ); - builddata($board, \%bh, $Getopt::Std::opt_a); + builddata($board, \%bh, + $Getopt::Std::opt_a, + $Getopt::Std::opt_o, + $Getopt::Std::opt_n, + $Getopt::Std::opt_f,); } sub buildconfigure($$) @@ -52,13 +59,16 @@ sub buildconfigure($$) print "\texporting ".$rch->{"$_.title"}."\n"; if( $rch->{"$_.title"} =~ /^config$/i ){ foreach( split("\n", $rch->{"$_.content"}) ){ - $config{$1} = $2 if( /(.*?):\s*(.*)/ ); + $config{$1} = $2 if( !/^\#/ && /(.*?):\s*(.*)/ ); } } else{ - my(@ls, $t); + my(@ls, $t, $c); - @ls = split("\n", $rch->{"$_.content"}); + $c = $rch->{"$_.content"}; + $c =~ s/^\#.*?\n//g; + + @ls = split("\n", $c); open FH, ">$outdir/". $rch->{"$_.title"}; if( $rch->{"$_.title"} =~ /\.html$/ ){ while( $t = shift @ls ){ @@ -76,43 +86,66 @@ sub buildconfigure($$) print Dumper(\%attr); } -sub builddata($$$) +sub builddata($$$$$$) { - my($board, $rbh, $rebuild) = @_; + my($board, $rbh, $rebuild, $contentonly, $number, $force) = @_; my(%dat, $dbfn, $y, $m, $d, $t, $currid); $dbfn = "$BLOGROOT/$board.db"; unlink $dbfn if( $rebuild ); - - tie %dat, 'DB_File', $dbfn, O_CREAT | O_RDWR, 0666, $DB_HASH; - foreach( 1..($rbh->{num} - 1) ){ - if( ($y, $m, $d, $t) = - $rbh->{"$_.title"} =~ /(\d+)\.(\d+).(\d+),(.*)/ ){ + tie %dat, 'DB_File', $dbfn, O_CREAT | O_RDWR, 0666, $DB_HASH; + foreach( $number ? $number : (1..($rbh->{num} - 1)) ){ + if( !(($y, $m, $d, $t) = + $rbh->{"$_.title"} =~ /(\d+)\.(\d+).(\d+),(.*)/) ){ + print "\terror parsing $_: ".$rbh->{"$_.title"}."\n"; + } + else{ $currid = sprintf('%04d%02d%02d', $y, $m, $d); - if( $currid <= $dat{last} ){ - print "\t$currid skipped\n"; + if( $dat{$currid} && !$force ){ + print "\t$currid is already in db\n"; + next; } - else{ - $dat{ sprintf('%04d%02d', $y, $m) } = 1; - $dat{"$currid.title"} = $t; - $dat{"$currid.author"} = $rbh->{"$_.owner"}; - # $dat{"$currid.content"} = $rbh->{"$_.content"}; - # ugly code for making short - my @c = split("\n", - $dat{"$currid.content"} = $rbh->{"$_.content"}); - $dat{"$currid.short"} = ("$c[0]\n$c[1]\n$c[2]\n". - $c[3] ? '....' : ''); - - $dat{"$currid.prev"} = $dat{'last'}; - $dat{"$dat{last}.next"} = $currid - if( $dat{'last'} ); - $dat{'last'} = $currid; - $dat{head} = $currid if( !$dat{head} ); - print "\t${currid} built\n"; + + print "\tbuilding $currid content\n"; + $dat{ sprintf('%04d%02d', $y, $m) } = 1; + $dat{"$currid.title"} = $t; + $dat{"$currid.author"} = $rbh->{"$_.owner"}; + # $dat{"$currid.content"} = $rbh->{"$_.content"}; + # ugly code for making short + my @c = split("\n", + $dat{"$currid.content"} = $rbh->{"$_.content"}); + $dat{"$currid.short"} = ("$c[0]\n$c[1]\n$c[2]\n". + $c[3] ? '....' : ''); + + if( !$contentonly ){ + print "\tbuilding $currid linking... "; + if( $dat{$currid} ){ + print "already linked"; + } + elsif( !$dat{head} ){ # first article + $dat{head} = $currid; + $dat{last} = $currid; + } + elsif( $currid < $dat{head} ){ # before head ? + $dat{"$currid.next"} = $dat{head}; + $dat{"$dat{head}.prev"} = $currid; + $dat{head} = $currid; + } + elsif( $currid > $dat{last} ){ # after last ? + $dat{"$currid.prev"} = $dat{last}; + $dat{"$dat{last}.next"} = $currid; + $dat{last} = $currid; + } + else{ # inside ? @_@;;; + print "not implement yet"; + } + $dat{$currid} = 1; + print "\n"; } } } + print Dumper(\%dat); untie %dat; } -- cgit v1.2.3 From d1c4d88cd821ea262928ed9ac3dacaf4a3164658 Mon Sep 17 00:00:00 2001 From: in2 Date: Mon, 26 May 2003 02:29:15 +0000 Subject: counter support by DBI git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@897 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/blog/blog.pl | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 50 insertions(+), 2 deletions(-) diff --git a/pttbbs/blog/blog.pl b/pttbbs/blog/blog.pl index 4f177972..6fc63b1b 100755 --- a/pttbbs/blog/blog.pl +++ b/pttbbs/blog/blog.pl @@ -55,6 +55,15 @@ sub main packdate($y1, $m1, $d1)); } } + elsif( $attr{"$fn.loadBlog"} =~ /^last(\d+)/i ){ + my($ptr, $i); + for( $ptr = $article{last}, $i = 0 ; + $ptr && $i < $1 ; + $ptr = $article{"$ptr.prev"} ){ + AddArticle('blog', $attr{"$fn.loadBlogFields"}, + $ptr); + } + } if( $attr{"$fn.loadBlogPrevNext"} ){ my $s = packdate($y, $m, $d); @@ -63,6 +72,7 @@ sub main AddArticle('prev', $attr{"$fn.loadBlogPrevNext"}, $article{"$s.prev"}); } + # loadArchives ----------------------------------------------------------- if( $attr{"$fn.loadArchives"} =~ /^monthly/i ){ # 找尋 +-1 year 內有資料的月份 @@ -97,6 +107,25 @@ sub main } } + # Counter ---------------------------------------------------------------- + if( $attr{"$fn.loadCounter"} ){ + my($c); + $c = dodbi(sub { + my($dbh) = @_; + my($sth, $t); + $dbh->do("update counter set v = v + 1 where k = '$brdname'"); + $sth = $dbh->prepare("select v from counter where k='$brdname'"); + $sth->execute(); + $t = $sth->fetchrow_hashref(); + return $t->{v} if( $t->{v} ); + + $dbh->do("insert into counter (k, v) ". + "values ('$brdname', 1)"); + return 1; + }); + $th{counter} = $c; + } + # Calendar --------------------------------------------------------------- if( $attr{"$fn.loadCalendar"} ){ # 沒有合適的 module , 自己寫一個 |||b @@ -131,7 +160,7 @@ sub main } else{ my $link = $attr{"$fn.loadCalendar"}; - $link =~ s/\[\% key \%\]/,$t/g; + $link =~ s/\[\% key \%\]/$t/g; $c .= "$_"; } @@ -167,7 +196,7 @@ sub AddArticle($$$) if( $fields =~ /content/i ){ $content = $article{"$s.content"}; if( $config{outputfilter} == 1 ){ - $content =~ s/\n/
\n/gs; + $content =~ s/\n/
\n/gs; } } @@ -216,6 +245,25 @@ sub unpackdate($) $_[0] % 100); } +sub dodbi +{ + my($func) = @_; + my($ret); + use DBI; + use DBD::mysql; + my $dbh = DBI->connect("DBI:mysql:database=blog;". + "host=localhost", + 'root', + '', + {'RaiseError' => 1}); + eval { + $ret = &{$func}($dbh); + }; + $dbh->disconnect(); + print "SQL: $@\n" if( $@ ); + return $ret; +} + main(); 1; -- cgit v1.2.3 From d645e3f05823fff7341dc118435da3b69bf2bb89 Mon Sep 17 00:00:00 2001 From: in2 Date: Mon, 26 May 2003 02:30:04 +0000 Subject: add $Id$ git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@898 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/blog/blog.pl | 1 + 1 file changed, 1 insertion(+) diff --git a/pttbbs/blog/blog.pl b/pttbbs/blog/blog.pl index 6fc63b1b..12d67328 100755 --- a/pttbbs/blog/blog.pl +++ b/pttbbs/blog/blog.pl @@ -1,4 +1,5 @@ #!/usr/bin/perl +# $Id: blog.pl,v 1.5 2003/05/26 02:30:04 in2 Exp $ use CGI qw/:standard/; use LocalVars; use DB_File; -- cgit v1.2.3 From d0e4a318a04b7100d2ff244c6755e4eefb132c23 Mon Sep 17 00:00:00 2001 From: in2 Date: Mon, 26 May 2003 02:56:39 +0000 Subject: reformat short git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@899 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/blog/builddb.pl | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/pttbbs/blog/builddb.pl b/pttbbs/blog/builddb.pl index 1be4c25a..49d2562e 100755 --- a/pttbbs/blog/builddb.pl +++ b/pttbbs/blog/builddb.pl @@ -115,8 +115,7 @@ sub builddata($$$$$$) # ugly code for making short my @c = split("\n", $dat{"$currid.content"} = $rbh->{"$_.content"}); - $dat{"$currid.short"} = ("$c[0]\n$c[1]\n$c[2]\n". - $c[3] ? '....' : ''); + $dat{"$currid.short"} = ("$c[0]\n$c[1]\n$c[2]\n$c[3]\n"); if( !$contentonly ){ print "\tbuilding $currid linking... "; @@ -145,7 +144,6 @@ sub builddata($$$$$$) } } } - print Dumper(\%dat); untie %dat; } -- cgit v1.2.3 From ace70671188e651d66c1aa1461cad13789868192 Mon Sep 17 00:00:00 2001 From: in2 Date: Mon, 26 May 2003 02:57:15 +0000 Subject: apply outputfilter at short git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@900 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/blog/blog.pl | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/pttbbs/blog/blog.pl b/pttbbs/blog/blog.pl index 12d67328..d4dcc426 100755 --- a/pttbbs/blog/blog.pl +++ b/pttbbs/blog/blog.pl @@ -1,5 +1,5 @@ #!/usr/bin/perl -# $Id: blog.pl,v 1.5 2003/05/26 02:30:04 in2 Exp $ +# $Id: blog.pl,v 1.6 2003/05/26 02:57:15 in2 Exp $ use CGI qw/:standard/; use LocalVars; use DB_File; @@ -49,7 +49,7 @@ sub main if( $attr{"$fn.loadBlog"} =~ /article/i ){ AddArticle('blog', $attr{"$fn.loadBlogFields"}, packdate($y, $m, $d)); } - elsif( $attr{"$fn.loadBlog"} =~ /month/i ){ + elsif( $attr{"$fn.loadBlog"} =~ /monthly/i ){ my($s, $y1, $m1, $d1); for( ($y1, $m1, $d1) = ($y, $m, 32) ; $d1 > 0 ; --$d1 ){ AddArticle('blog', $attr{"$fn.loadBlogFields"}, @@ -193,13 +193,19 @@ sub main sub AddArticle($$$) { my($cl, $fields, $s) = @_; - my $content = ''; + my($content, $short) = (); if( $fields =~ /content/i ){ $content = $article{"$s.content"}; if( $config{outputfilter} == 1 ){ $content =~ s/\n/
\n/gs; } } + if( $fields =~ /short/i ){ + $short = $article{"$s.short"}; + if( $config{outputfilter} == 1 ){ + $short =~ s/\n/
\n/gs; + } + } my($y, $m, $d) = unpackdate($s); push @{$th{$cl}}, {year => $y, @@ -213,8 +219,7 @@ sub AddArticle($$$) content=> $content, author => (($fields !~ /author/i) ? '' : $article{"$s.author"}), - short => (($fields !~ /short/i) ? '' : - $article{"$s.short"}), + short => $short, } if( $article{"$s.title"} ); } -- cgit v1.2.3 From 1cb1e2a3524df12b34ef7641b353202dd5619567 Mon Sep 17 00:00:00 2001 From: in2 Date: Mon, 26 May 2003 03:31:28 +0000 Subject: loadTopBlogs, replase <, >, " git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@901 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/blog/blog.pl | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/pttbbs/blog/blog.pl b/pttbbs/blog/blog.pl index d4dcc426..135bf63d 100755 --- a/pttbbs/blog/blog.pl +++ b/pttbbs/blog/blog.pl @@ -1,5 +1,5 @@ #!/usr/bin/perl -# $Id: blog.pl,v 1.6 2003/05/26 02:57:15 in2 Exp $ +# $Id: blog.pl,v 1.7 2003/05/26 03:31:28 in2 Exp $ use CGI qw/:standard/; use LocalVars; use DB_File; @@ -108,6 +108,21 @@ sub main } } + # topBlogs + if( $attr{"$fn.loadTopBlogs"} ){ + dodbi(sub { + my($dbh) = @_; + my($sth); + $sth = $dbh->prepare("select k, v from counter order by v desc ". + "limit 0,". $attr{"$fn.loadTopBlogs"}); + $sth->execute(); + while( $_ = $sth->fetchrow_hashref() ){ + push @{$th{topBlogs}}, {brdname => $_->{k}, + counter => $_->{v}}; + } + }); + } + # Counter ---------------------------------------------------------------- if( $attr{"$fn.loadCounter"} ){ my($c); @@ -197,6 +212,9 @@ sub AddArticle($$$) if( $fields =~ /content/i ){ $content = $article{"$s.content"}; if( $config{outputfilter} == 1 ){ + $content =~ s/\/>/gs; + $content =~ s/\"/"/gs; $content =~ s/\n/
\n/gs; } } -- cgit v1.2.3 From ee86ca2fc17f9bb3da2b384f9021aaa09406b946 Mon Sep 17 00:00:00 2001 From: in2 Date: Mon, 26 May 2003 04:01:40 +0000 Subject: for XHTML git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@902 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/blog/blog.pl | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/pttbbs/blog/blog.pl b/pttbbs/blog/blog.pl index 135bf63d..69e039b1 100755 --- a/pttbbs/blog/blog.pl +++ b/pttbbs/blog/blog.pl @@ -1,5 +1,5 @@ #!/usr/bin/perl -# $Id: blog.pl,v 1.7 2003/05/26 03:31:28 in2 Exp $ +# $Id: blog.pl,v 1.8 2003/05/26 04:01:40 in2 Exp $ use CGI qw/:standard/; use LocalVars; use DB_File; @@ -125,8 +125,7 @@ sub main # Counter ---------------------------------------------------------------- if( $attr{"$fn.loadCounter"} ){ - my($c); - $c = dodbi(sub { + $th{counter} = dodbi(sub { my($dbh) = @_; my($sth, $t); $dbh->do("update counter set v = v + 1 where k = '$brdname'"); @@ -139,13 +138,12 @@ sub main "values ('$brdname', 1)"); return 1; }); - $th{counter} = $c; } # Calendar --------------------------------------------------------------- if( $attr{"$fn.loadCalendar"} ){ # 沒有合適的 module , 自己寫一個 |||b - my($c, $week, $day, $t, $link); + my($c, $week, $day, $t, $link, $newtr); $c = ("\n". "\n". "\n"); @@ -168,6 +166,8 @@ sub main foreach( 1..$week ); } foreach( 1..31 ){ + last if( !check_date($y, $m, $_) ); + $c .= "\n" if( $newtr ); $c .= "\n"; if( ++$week == 7 ){ - $c .= "\n\n\n"; + $c .= "\n\n"; $week = 0; + $newtr = 1; + } + else{ + $newtr = 0; } } - $c .= "\n
$emonth[$m] $y
"; $t = packdate($y, $m, $_); @@ -182,12 +182,17 @@ sub main $c .= "
\n"; + $c .= "\n" if( !$newtr ); + $c .= "\n"; $th{calendar} = $c; #my $cal = HTML::Calendar::Simple->new({month => $m, year => $y}); #$th{calendar} = $cal->calendar_month; -- cgit v1.2.3 From c3d6ba7413b1b4d2dc041b90ef3efeb8d41a777c Mon Sep 17 00:00:00 2001 From: in2 Date: Mon, 26 May 2003 05:25:03 +0000 Subject: blog support git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@903 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/include/modes.h | 3 +- pttbbs/include/proto.h | 5 ++- pttbbs/include/pttstruct.h | 3 +- pttbbs/mbbsd/announce.c | 77 +++++++++++++++++++++++++++++++++++++++++++++- pttbbs/mbbsd/var.c | 13 +++++++- pttbbs/sample/LocalVars.pm | 7 ++++- pttbbs/sample/pttbbs.conf | 4 +++ 7 files changed, 106 insertions(+), 6 deletions(-) diff --git a/pttbbs/include/modes.h b/pttbbs/include/modes.h index cc12b3d5..3606cb1a 100644 --- a/pttbbs/include/modes.h +++ b/pttbbs/include/modes.h @@ -1,4 +1,4 @@ -/* $Id: modes.h,v 1.2 2002/08/27 21:49:18 kcwu Exp $ */ +/* $Id: modes.h,v 1.3 2003/05/26 05:23:13 in2 Exp $ */ #ifndef INCLUDE_MODES_H #define INCLUDE_MODES_H @@ -95,6 +95,7 @@ #define TMPJACK 77 #define JCEE 78 #define REEDIT 79 +#define BLOGGING 80 /* menu.c 中的模式 */ #define QUIT 0x666 /* Return value to abort recursive functions */ diff --git a/pttbbs/include/proto.h b/pttbbs/include/proto.h index 298f0a2b..a460650d 100644 --- a/pttbbs/include/proto.h +++ b/pttbbs/include/proto.h @@ -1,4 +1,4 @@ -/* $Id: proto.h,v 1.43 2003/05/20 02:03:35 bbs Exp $ */ +/* $Id: proto.h,v 1.44 2003/05/26 05:23:13 in2 Exp $ */ #ifndef INCLUDE_PROTO_H #define INCLUDE_PROTO_H @@ -26,6 +26,9 @@ int a_menu(char *maintitle, char *path, int lastlevel); void a_copyitem(char* fpath, char* title, char* owner, int mode); int Announce(); void gem(char* maintitle, item_t* path, int update); +#ifdef BLOG +void BlogMain(int); +#endif /* args */ void initsetproctitle(int argc, char **argv, char **envp); diff --git a/pttbbs/include/pttstruct.h b/pttbbs/include/pttstruct.h index 80bbe7f3..a85c031d 100644 --- a/pttbbs/include/pttstruct.h +++ b/pttbbs/include/pttstruct.h @@ -1,4 +1,4 @@ -/* $Id: pttstruct.h,v 1.37 2003/05/09 13:30:32 victor Exp $ */ +/* $Id: pttstruct.h,v 1.38 2003/05/26 05:23:13 in2 Exp $ */ #ifndef INCLUDE_STRUCT_H #define INCLUDE_STRUCT_H @@ -135,6 +135,7 @@ typedef struct boardheader_t { #define BRD_WARNEL 000002000 /* 連署機看板 */ #define BRD_TOP 000004000 /* 熱門看板群組 */ #define BRD_NORECOMMEND 000010000 /* 不可推薦 */ +#define BRD_BLOG 000020000 /* BLOG */ #define TTLEN 64 /* Length of title */ #define FNLEN 33 /* Length of filename */ diff --git a/pttbbs/mbbsd/announce.c b/pttbbs/mbbsd/announce.c index 8bd39115..dd89ff1b 100644 --- a/pttbbs/mbbsd/announce.c +++ b/pttbbs/mbbsd/announce.c @@ -1,4 +1,4 @@ -/* $Id: announce.c,v 1.22 2003/05/24 03:45:14 in2 Exp $ */ +/* $Id: announce.c,v 1.23 2003/05/26 05:23:13 in2 Exp $ */ #include "bbs.h" static void @@ -1542,6 +1542,30 @@ a_menu(char *maintitle, char *path, int lastlevel) refresh(); sleep(1); break; + +#ifdef BLOG + case 'b': + if( !HAS_PERM(SYSOP) && !is_BM(bcache[currbid - 1].BM) ) + vmsg("只有板主才可以用唷!"); + else{ + char genbuf[128]; + snprintf(genbuf, sizeof(genbuf), + "bin/builddb.pl -f -n %d %s", me.now, currboard); + system(genbuf); + vmsg("資料更新完成"); + } + me.page = 9999; + break; + + case 'B': + if( !HAS_PERM(SYSOP) && !is_BM(bcache[currbid - 1].BM) ) + vmsg("只有板主才可以用唷!"); + else + BlogMain(me.now); + me.page = 9999; + + break; +#endif } if (me.level >= MANAGER) { @@ -1641,3 +1665,54 @@ Announce() NOBODY)); return 0; } + +#ifdef BLOG +void BlogMain(int num) +{ + int oldmode = currutmp->mode; + char genbuf[128], exit = 0; + + //setutmpmode(BLOGGING); /* will crash someone using old program */ + sprintf(genbuf, "%s的布落格", currboard); + showtitle("布落格", genbuf); + while( !exit ){ + move(1, 0); + prints("請選擇您要執行的重作:\n" + "0.回到上一層\n" + "1.製作布落格樣板格式\n" + " 使用新的 config 目錄下樣板資料\n" + " 通常在第一次使用布落格或樣板更新的時候使用\n" + "\n" + "2.重新製作布落格\n" + " 只在布落格資料整個亂掉的時候才使用\n" + "\n" + "3.將本文加入布落格\n" + " 將游標所在位置的文章加入布落格\n"); + switch( getans("請選擇(0-3)?[0]") ){ + case '1': + snprintf(genbuf, sizeof(genbuf), + "bin/builddb.pl -c %s", currboard); + system(genbuf); + break; + case '2': + snprintf(genbuf, sizeof(genbuf), + "bin/builddb.pl -a %s", currboard); + vmsg(genbuf); + system(genbuf); + break; + case '3': + snprintf(genbuf, sizeof(genbuf), + "bin/builddb.pl -f -n %d %s", num, currboard); + system(genbuf); + break; + default: + exit = 1; + break; + } + if( !exit ) + vmsg("布落格完成"); + } + currutmp->mode = oldmode; + pressanykey(); +} +#endif diff --git a/pttbbs/mbbsd/var.c b/pttbbs/mbbsd/var.c index 8d43e7d5..d8356d02 100644 --- a/pttbbs/mbbsd/var.c +++ b/pttbbs/mbbsd/var.c @@ -1,4 +1,4 @@ -/* $Id: var.c,v 1.16 2003/04/06 04:11:10 victor Exp $ */ +/* $Id: var.c,v 1.17 2003/05/26 05:23:13 in2 Exp $ */ #define INCLUDE_VAR_H #include "bbs.h" @@ -262,6 +262,17 @@ char *ModeTypeTable[MAX_MODES] = { "NBA大猜測" /* TMPJACK */ "Ptt查榜系統", /* JCEE */ "重編文章" /* REEDIT */ + "布落格", /* BLOGGING */ + "", /* for future usage */ + "", + "", + "", + "", + "", + "", + "", + "", + "", }; /* indict.c */ diff --git a/pttbbs/sample/LocalVars.pm b/pttbbs/sample/LocalVars.pm index 1f24872d..a2ad4ab5 100644 --- a/pttbbs/sample/LocalVars.pm +++ b/pttbbs/sample/LocalVars.pm @@ -5,7 +5,9 @@ require Exporter; @EXPORT = qw/ $hostname $MYHOSTNAME $FQDN $SMTPSERVER $BBSHOME $JOBSPOOL $TMP - $TAR $LYNX $GREP/; + $TAR $LYNX $GREP + $BLOGDATA +/; # host $hostname = 'ptt'; @@ -22,3 +24,6 @@ $TMP = '/tmp'; $TAR = '/usr/bin/tar'; $LYNX = '/usr/local/bin/lynx'; # /usr/ports/www/lynx $GREP = '/usr/bin/grep'; + +# blog +$BLOGDATA = '/home/bbs/blog/data'; diff --git a/pttbbs/sample/pttbbs.conf b/pttbbs/sample/pttbbs.conf index 67e696d9..b76d0ef4 100644 --- a/pttbbs/sample/pttbbs.conf +++ b/pttbbs/sample/pttbbs.conf @@ -88,6 +88,10 @@ 須要加跑 shmctl timed 來提供時間 */ //#define OUTTA_TIMER +/* 若定義, 則啟動 bbs中連至 BLOG 的 interface + 請參閱 pttbbs/blog/ */ +//#define BLOG + /* 前進站畫面 */ #define INSCREEN \ "前進站畫面 (請至 pttbbs.conf 修改您的前進站畫面)" -- cgit v1.2.3 From 84afcc76fcf695a5346d8b3ef84f25b8d2414412 Mon Sep 17 00:00:00 2001 From: in2 Date: Mon, 26 May 2003 05:29:39 +0000 Subject: warning free git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@904 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/bbs.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pttbbs/mbbsd/bbs.c b/pttbbs/mbbsd/bbs.c index 7129703e..80ec2767 100644 --- a/pttbbs/mbbsd/bbs.c +++ b/pttbbs/mbbsd/bbs.c @@ -1,4 +1,4 @@ -/* $Id: bbs.c,v 1.95 2003/05/20 01:51:01 bbs Exp $ */ +/* $Id: bbs.c,v 1.96 2003/05/26 05:29:39 in2 Exp $ */ #include "bbs.h" static int recommend(int ent, fileheader_t * fhdr, char *direct); @@ -139,7 +139,7 @@ readtitle() static void readdoent(int num, fileheader_t * ent) { - int type, uid; + int type; char *mark, *title, color, special = 0, isonline = 0; userinfo_t *uentp; if (ent->recommend > 9 || ent->recommend < 0) -- cgit v1.2.3 From ad952d254a6839f1fa14ad6cf19ce2dc89160b4f Mon Sep 17 00:00:00 2001 From: in2 Date: Mon, 26 May 2003 05:30:22 +0000 Subject: expand modes git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@905 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/include/common.h | 4 ++-- pttbbs/mbbsd/var.c | 39 ++++++++++++++++++++++++++++++++++++++- 2 files changed, 40 insertions(+), 3 deletions(-) diff --git a/pttbbs/include/common.h b/pttbbs/include/common.h index d70e8b82..309f49c5 100644 --- a/pttbbs/include/common.h +++ b/pttbbs/include/common.h @@ -1,4 +1,4 @@ -/* $Id: common.h,v 1.5 2002/11/07 09:13:23 in2 Exp $ */ +/* $Id: common.h,v 1.6 2003/05/26 05:30:22 in2 Exp $ */ #ifndef INCLUDE_COMMON_H #define INCLUDE_COMMON_H @@ -172,7 +172,7 @@ #define LTR(x) ((x) * 2 + 3) #define CHE(a, b) ((a) | ((b) << 3)) -#define MAX_MODES 80 +#define MAX_MODES 127 #ifndef MIN #define MIN(a,b) ((a Date: Mon, 26 May 2003 05:31:35 +0000 Subject: quiet mode git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@906 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/blog/builddb.pl | 43 +++++++++++++++++++++++++++---------------- 1 file changed, 27 insertions(+), 16 deletions(-) diff --git a/pttbbs/blog/builddb.pl b/pttbbs/blog/builddb.pl index 49d2562e..fc53cff5 100755 --- a/pttbbs/blog/builddb.pl +++ b/pttbbs/blog/builddb.pl @@ -1,4 +1,5 @@ #!/usr/bin/perl +use lib '/home/bbs/bin/'; use strict; use Getopt::Std; use LocalVars; @@ -17,11 +18,12 @@ sub main sub usage { - return ("$0 [-cfao] [-n NUMBER] [board ...]\n". - "\t-c\t\tbuild configure\n". + return ("$0 [-acdfo] [-n NUMBER] [board ...]\n". "\t-a\t\trebuild all files\n". - "\t-o\t\tonly build content(not building link)\n". + "\t-c\t\tbuild configure\n". + "\t-d\t\tprint debug message\n". "\t-f\t\tforce build\n". + "\t-o\t\tonly build content(not building link)\n". "\t-n NUMBER\tonly build \#NUMBER article\n"); } @@ -30,7 +32,7 @@ sub builddb($) my($board) = @_; my(%bh, %ch); - print "building $board\n"; + print "building $board\n" if( $Getopt::Std::opt_d ); return if( !getdir("$BBSHOME/man/boards/".substr($board,0,1)."/$board", \%bh, \%ch) ); buildconfigure($board, \%ch) @@ -56,7 +58,8 @@ sub buildconfigure($$) O_CREAT | O_RDWR, 0666, $DB_HASH); for ( 0..($rch->{num} - 1) ){ - print "\texporting ".$rch->{"$_.title"}."\n"; + print "\texporting ".$rch->{"$_.title"}."\n" + if( $Getopt::Std::opt_d ); if( $rch->{"$_.title"} =~ /^config$/i ){ foreach( split("\n", $rch->{"$_.content"}) ){ $config{$1} = $2 if( !/^\#/ && /(.*?):\s*(.*)/ ); @@ -82,8 +85,8 @@ sub buildconfigure($$) foreach( @ls ); } } - print Dumper(\%config); - print Dumper(\%attr); + print Dumper(\%config) if( $Getopt::Std::opt_d ); + print Dumper(\%attr) if( $Getopt::Std::opt_d ); } sub builddata($$$$$$) @@ -98,16 +101,18 @@ sub builddata($$$$$$) foreach( $number ? $number : (1..($rbh->{num} - 1)) ){ if( !(($y, $m, $d, $t) = $rbh->{"$_.title"} =~ /(\d+)\.(\d+).(\d+),(.*)/) ){ - print "\terror parsing $_: ".$rbh->{"$_.title"}."\n"; + print "\terror parsing $_: ".$rbh->{"$_.title"}."\n" + if( $Getopt::Std::opt_d ); } else{ $currid = sprintf('%04d%02d%02d', $y, $m, $d); if( $dat{$currid} && !$force ){ - print "\t$currid is already in db\n"; + print "\t$currid is already in db\n" + if( $Getopt::Std::opt_d ); next; } - print "\tbuilding $currid content\n"; + print "\tbuilding $currid content\n" if( $Getopt::Std::opt_d ); $dat{ sprintf('%04d%02d', $y, $m) } = 1; $dat{"$currid.title"} = $t; $dat{"$currid.author"} = $rbh->{"$_.owner"}; @@ -118,9 +123,11 @@ sub builddata($$$$$$) $dat{"$currid.short"} = ("$c[0]\n$c[1]\n$c[2]\n$c[3]\n"); if( !$contentonly ){ - print "\tbuilding $currid linking... "; + print "\tbuilding $currid linking... " + if( $Getopt::Std::opt_d ); if( $dat{$currid} ){ - print "already linked"; + print "already linked" + if( $Getopt::Std::opt_d ); } elsif( !$dat{head} ){ # first article $dat{head} = $currid; @@ -137,10 +144,12 @@ sub builddata($$$$$$) $dat{last} = $currid; } else{ # inside ? @_@;;; - print "not implement yet"; + print "not implement yet" + if( $Getopt::Std::opt_d ); } $dat{$currid} = 1; - print "\n"; + print "\n" + if( $Getopt::Std::opt_d ); } } } @@ -153,14 +162,16 @@ sub getdir($$$$$) my(%h); tie %h, 'BBSFileHeader', "$bdir/"; if( $h{"-1.title"} !~ /blog/i || !$h{"-1.isdir"} ){ - print "blogdir not found\n"; + print "blogdir not found\n" + if( $Getopt::Std::opt_d ); return; } tie %{$rh_bh}, 'BBSFileHeader', "$bdir/". $h{'-1.filename'}.'/'; if( $rh_bh->{'0.title'} !~ /configure/i || !$rh_bh->{'0.isdir'} ){ - print "configure not found\n"; + print "configure not found\n" + if( $Getopt::Std::opt_d ); return; } -- cgit v1.2.3 From 998945b8c37f47b9b68842c2dc32066efca6f8e0 Mon Sep 17 00:00:00 2001 From: ptt Date: Mon, 26 May 2003 11:24:28 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@907 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/gamble.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/pttbbs/mbbsd/gamble.c b/pttbbs/mbbsd/gamble.c index b6b0d61c..93342e00 100644 --- a/pttbbs/mbbsd/gamble.c +++ b/pttbbs/mbbsd/gamble.c @@ -1,4 +1,4 @@ -/* $Id: gamble.c,v 1.33 2003/04/27 13:00:16 in2 Exp $ */ +/* $Id: gamble.c,v 1.34 2003/05/26 11:24:28 ptt Exp $ */ #include "bbs.h" #ifndef _BBS_UTIL_C_ @@ -150,12 +150,6 @@ ticket(int bid) 很有可能跑到下次賭盤的紀錄去, 也很有可能被板主新開賭盤時洗掉 不過這邊至少可以做到的是, 頂多只會有一筆資料是錯的 --*/ - if (bid && !dashf(fn_ticket)) { - move(b_lines - 1, 0); - prints("哇!! 耐ㄚ捏...板主已經停止下注了 不能賭嚕"); - pressanykey(); - break; - } if (ch == 'q' || ch == 'Q') break; ch -= '1'; @@ -163,6 +157,14 @@ ticket(int bid) continue; n = 0; ch_buyitem(price, "etc/buyticket", &n, 0); + + if (bid && !dashf(fn_ticket)) { + move(b_lines - 1, 0); + prints("哇!! 耐ㄚ捏...板主已經停止下注了 不能賭嚕"); + pressanykey(); + break; + } + if (n > 0) append_ticket_record(path, ch, n, count); } -- cgit v1.2.3 From 7cc44901c5a4c8d57c2d99c483be78ac8cbe72fd Mon Sep 17 00:00:00 2001 From: in2 Date: Tue, 27 May 2003 07:53:41 +0000 Subject: fix a bug of buffer overflow git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@908 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/edit.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pttbbs/mbbsd/edit.c b/pttbbs/mbbsd/edit.c index f3dce0b2..5621ef3f 100644 --- a/pttbbs/mbbsd/edit.c +++ b/pttbbs/mbbsd/edit.c @@ -1,4 +1,4 @@ -/* $Id: edit.c,v 1.30 2003/04/10 06:01:28 in2 Exp $ */ +/* $Id: edit.c,v 1.31 2003/05/27 07:53:41 in2 Exp $ */ #include "bbs.h" typedef struct textline_t { struct textline_t *prev; @@ -1123,7 +1123,7 @@ display_buffer() outs("\033[m"); edit_outs(p->data + max); } else - edit_outs(&p->data[edit_margin]); + edit_outs((edit_margin < p->len) ? &p->data[edit_margin] : ""); p = p->next; if (inblock) outs("\033[m"); -- cgit v1.2.3 From d94e84aa02633b970496bddec65708aab2e72ba2 Mon Sep 17 00:00:00 2001 From: victor Date: Fri, 30 May 2003 07:57:08 +0000 Subject: fix error to get backup data git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@909 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/admin.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/pttbbs/mbbsd/admin.c b/pttbbs/mbbsd/admin.c index 29145dd7..e01cd4da 100644 --- a/pttbbs/mbbsd/admin.c +++ b/pttbbs/mbbsd/admin.c @@ -1,4 +1,4 @@ -/* $Id: admin.c,v 1.42 2003/05/16 08:30:48 ptt Exp $ */ +/* $Id: admin.c,v 1.43 2003/05/30 07:57:08 victor Exp $ */ #include "bbs.h" /* 使用者管理 */ @@ -41,6 +41,8 @@ search_key_user(char *passwdfile, int mode) clear(); getdata(0, 0, mode ? "請輸入使用者關鍵字[電話|地址|姓名|上站地點|" "email|小雞id] :" : "請輸入id :", key, sizeof(key), DOECHO); + if(!key[0]) + return 0; while ((fread(&user, sizeof(user), 1, fp1)) > 0 && coun < MAX_USERS) { if (!(++coun & 15)) { move(1, 0); @@ -48,25 +50,25 @@ search_key_user(char *passwdfile, int mode) outs(buf); refresh(); } - keymatch=NULL; + keymatch = NULL; if (!strcasecmp(user.userid, key)) - sprintf(keymatch,"id:%s",user.userid); + keymatch = user.userid; else if(mode) { if(strstr(user.realname, key)) - keymatch=user.realname; + keymatch = user.realname; else if(strstr(user.username, key)) - keymatch=user.username; + keymatch = user.username; else if(strstr(user.lasthost, key)) - keymatch=user.lasthost; + keymatch = user.lasthost; else if(strstr(user.email, key)) - keymatch=user.email; + keymatch = user.email; else if(strstr(user.address, key)) - keymatch=user.address; + keymatch = user.address; else if(strstr(user.justify, key)) - keymatch=user.justify; + keymatch = user.justify; else if(strstr(user.mychicken.name, key)) - keymatch=user.mychicken.name; + keymatch = user.mychicken.name; } if(keymatch) { -- cgit v1.2.3 From 1f2ef74c9a23e1bfc244aa1ab29b288cddf6e8e5 Mon Sep 17 00:00:00 2001 From: bbs Date: Fri, 30 May 2003 10:16:42 +0000 Subject: debugmsg, attribute support git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@910 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/blog/builddb.pl | 78 +++++++++++++++++++++++++------------------------- 1 file changed, 39 insertions(+), 39 deletions(-) diff --git a/pttbbs/blog/builddb.pl b/pttbbs/blog/builddb.pl index fc53cff5..36e09a68 100755 --- a/pttbbs/blog/builddb.pl +++ b/pttbbs/blog/builddb.pl @@ -11,7 +11,7 @@ use DB_File; sub main { my($fh); - die usage() unless( getopts('caofn:') ); + die usage() unless( getopts('cdaofn:') ); die usage() if( !@ARGV ); builddb($_) foreach( @ARGV ); } @@ -27,12 +27,17 @@ sub usage "\t-n NUMBER\tonly build \#NUMBER article\n"); } +sub debugmsg($) +{ + print "$_\n" if( $Getopt::Std::opt_d ); +} + sub builddb($) { my($board) = @_; my(%bh, %ch); - - print "building $board\n" if( $Getopt::Std::opt_d ); + + debugmsg("building $board"); return if( !getdir("$BBSHOME/man/boards/".substr($board,0,1)."/$board", \%bh, \%ch) ); buildconfigure($board, \%ch) @@ -58,35 +63,39 @@ sub buildconfigure($$) O_CREAT | O_RDWR, 0666, $DB_HASH); for ( 0..($rch->{num} - 1) ){ - print "\texporting ".$rch->{"$_.title"}."\n" - if( $Getopt::Std::opt_d ); + debugmsg("\texporting ".$rch->{"$_.title"}); if( $rch->{"$_.title"} =~ /^config$/i ){ foreach( split("\n", $rch->{"$_.content"}) ){ $config{$1} = $2 if( !/^\#/ && /(.*?):\s*(.*)/ ); } } else{ - my(@ls, $t, $c); - + my(@ls, $c, $a, $fn); + + $fn = $rch->{"$_.title"}; + if( $fn !~ /\.(css|htm|html|js)$/i ){ + print "not supported filetype ". $rch->{"$_.title"}. "\n"; + next; + } + $c = $rch->{"$_.content"}; - $c =~ s/^\#.*?\n//g; - - @ls = split("\n", $c); - open FH, ">$outdir/". $rch->{"$_.title"}; - if( $rch->{"$_.title"} =~ /\.html$/ ){ - while( $t = shift @ls ){ - last if( $t !~ /^\*/ ); - $attr{($rch->{"$_.title"}. ".$1")} = $2 - if( $t =~ /^\*\s+(\w+): (.*)/ ); + open FH, ">$outdir/$fn"; + + if( $c =~ m|(.*?)(.*)|s ){ + ($a, $c) = ($1, $2); + $a =~ s/^\s*\#.*?\n//gm; + foreach( split("\n", $a) ){ + if( /^\s*(\w+):\s+(.*)/ ){ + $attr{"$fn.$1"} = $2; + print "\t$1: $2\n"; + } } - unshift @ls, $t; } - print FH "$_\n" - foreach( @ls ); + print FH $c; } } - print Dumper(\%config) if( $Getopt::Std::opt_d ); - print Dumper(\%attr) if( $Getopt::Std::opt_d ); + debugmsg(Dumper(\%config)); + debugmsg(Dumper(\%attr)); } sub builddata($$$$$$) @@ -101,18 +110,16 @@ sub builddata($$$$$$) foreach( $number ? $number : (1..($rbh->{num} - 1)) ){ if( !(($y, $m, $d, $t) = $rbh->{"$_.title"} =~ /(\d+)\.(\d+).(\d+),(.*)/) ){ - print "\terror parsing $_: ".$rbh->{"$_.title"}."\n" - if( $Getopt::Std::opt_d ); + debugmsg("\terror parsing $_: ".$rbh->{"$_.title"}); } else{ $currid = sprintf('%04d%02d%02d', $y, $m, $d); if( $dat{$currid} && !$force ){ - print "\t$currid is already in db\n" - if( $Getopt::Std::opt_d ); + debugmsg("\t$currid is already in db"); next; } - print "\tbuilding $currid content\n" if( $Getopt::Std::opt_d ); + debugmsg("\tbuilding $currid content"); $dat{ sprintf('%04d%02d', $y, $m) } = 1; $dat{"$currid.title"} = $t; $dat{"$currid.author"} = $rbh->{"$_.owner"}; @@ -123,11 +130,9 @@ sub builddata($$$$$$) $dat{"$currid.short"} = ("$c[0]\n$c[1]\n$c[2]\n$c[3]\n"); if( !$contentonly ){ - print "\tbuilding $currid linking... " - if( $Getopt::Std::opt_d ); + debugmsg("\tbuilding $currid linking... "); if( $dat{$currid} ){ - print "already linked" - if( $Getopt::Std::opt_d ); + debugmsg("\t\talready linked"); } elsif( !$dat{head} ){ # first article $dat{head} = $currid; @@ -144,12 +149,9 @@ sub builddata($$$$$$) $dat{last} = $currid; } else{ # inside ? @_@;;; - print "not implement yet" - if( $Getopt::Std::opt_d ); + debugmsg("not implement yet"); } $dat{$currid} = 1; - print "\n" - if( $Getopt::Std::opt_d ); } } } @@ -162,16 +164,14 @@ sub getdir($$$$$) my(%h); tie %h, 'BBSFileHeader', "$bdir/"; if( $h{"-1.title"} !~ /blog/i || !$h{"-1.isdir"} ){ - print "blogdir not found\n" - if( $Getopt::Std::opt_d ); + debugmsg("blogdir not found"); return; } tie %{$rh_bh}, 'BBSFileHeader', "$bdir/". $h{'-1.filename'}.'/'; - if( $rh_bh->{'0.title'} !~ /configure/i || + if( $rh_bh->{'0.title'} !~ /config/i || !$rh_bh->{'0.isdir'} ){ - print "configure not found\n" - if( $Getopt::Std::opt_d ); + debugmsg("configure not found"); return; } -- cgit v1.2.3 From 6e026dbeaa9bbc8d1a222cc2c87578f4dbe768d0 Mon Sep 17 00:00:00 2001 From: in2 Date: Fri, 30 May 2003 10:17:34 +0000 Subject: outputfilter git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@911 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/blog/blog.pl | 44 ++++++++++++++++++++++++++++---------------- 1 file changed, 28 insertions(+), 16 deletions(-) diff --git a/pttbbs/blog/blog.pl b/pttbbs/blog/blog.pl index 69e039b1..af2112fa 100755 --- a/pttbbs/blog/blog.pl +++ b/pttbbs/blog/blog.pl @@ -1,5 +1,5 @@ #!/usr/bin/perl -# $Id: blog.pl,v 1.8 2003/05/26 04:01:40 in2 Exp $ +# $Id: blog.pl,v 1.9 2003/05/30 10:17:34 in2 Exp $ use CGI qw/:standard/; use LocalVars; use DB_File; @@ -214,21 +214,11 @@ sub AddArticle($$$) { my($cl, $fields, $s) = @_; my($content, $short) = (); - if( $fields =~ /content/i ){ - $content = $article{"$s.content"}; - if( $config{outputfilter} == 1 ){ - $content =~ s/\/>/gs; - $content =~ s/\"/"/gs; - $content =~ s/\n/
\n/gs; - } - } - if( $fields =~ /short/i ){ - $short = $article{"$s.short"}; - if( $config{outputfilter} == 1 ){ - $short =~ s/\n/
\n/gs; - } - } + $content = applyfilter($article{"$s.content"}, $config{outputfilter}) + if( $fields =~ /content/i ); + + $short = applyfilter($article{"$s.short"}, $config{outputfilter}) + if( $fields =~ /short/i ); my($y, $m, $d) = unpackdate($s); push @{$th{$cl}}, {year => $y, @@ -247,6 +237,28 @@ sub AddArticle($$$) if( $article{"$s.title"} ); } +sub applyfilter($$) +{ + my($c, $filter) = @_; + foreach( split(',', $filter) ){ + if( /^generic$/i ){ + $c =~ s/\/>/gs; + $c =~ s/\"/"/gs; + $c =~ s/\n/
\n/gs; + } + elsif( /^ubb$/i ){ + $c =~ s|\[url\](.*?)\[/url\]|\1|gsi; + $c =~ s|\[url=(.*?)\](.*?)\[/url\]|\2|gsi; + $c =~ s|\[email\](.*?)\[/email\]|\1|gsi; + $c =~ s|\[b\](.*?)\[/b\]|\1|gsi; + $c =~ s|\[i\](.*?)\[/i\]|\1|gsi; + $c =~ s|\[img\](.*?)\[/img\]||gsi; + } + } + return $c; +} + sub parsefn($) { my($fs) = @_; -- cgit v1.2.3 From 65d8c05872bc6266a739a495e7118a446dfc3e6b Mon Sep 17 00:00:00 2001 From: in2 Date: Fri, 30 May 2003 10:28:32 +0000 Subject: =?UTF-8?q?s/=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD?= =?UTF-8?q?=EF=BF=BD/=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD?= =?UTF-8?q?=EF=BF=BD/?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@912 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/announce.c | 20 ++++++++++---------- pttbbs/mbbsd/var.c | 4 ++-- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/pttbbs/mbbsd/announce.c b/pttbbs/mbbsd/announce.c index dd89ff1b..61158c95 100644 --- a/pttbbs/mbbsd/announce.c +++ b/pttbbs/mbbsd/announce.c @@ -1,4 +1,4 @@ -/* $Id: announce.c,v 1.23 2003/05/26 05:23:13 in2 Exp $ */ +/* $Id: announce.c,v 1.24 2003/05/30 10:28:32 in2 Exp $ */ #include "bbs.h" static void @@ -1673,21 +1673,21 @@ void BlogMain(int num) char genbuf[128], exit = 0; //setutmpmode(BLOGGING); /* will crash someone using old program */ - sprintf(genbuf, "%s的布落格", currboard); - showtitle("布落格", genbuf); + sprintf(genbuf, "%s的部落格", currboard); + showtitle("部落格", genbuf); while( !exit ){ move(1, 0); prints("請選擇您要執行的重作:\n" "0.回到上一層\n" - "1.製作布落格樣板格式\n" + "1.製作部落格樣板格式\n" " 使用新的 config 目錄下樣板資料\n" - " 通常在第一次使用布落格或樣板更新的時候使用\n" + " 通常在第一次使用部落格或樣板更新的時候使用\n" "\n" - "2.重新製作布落格\n" - " 只在布落格資料整個亂掉的時候才使用\n" + "2.重新製作部落格\n" + " 只在部落格資料整個亂掉的時候才使用\n" "\n" - "3.將本文加入布落格\n" - " 將游標所在位置的文章加入布落格\n"); + "3.將本文加入部落格\n" + " 將游標所在位置的文章加入部落格\n"); switch( getans("請選擇(0-3)?[0]") ){ case '1': snprintf(genbuf, sizeof(genbuf), @@ -1710,7 +1710,7 @@ void BlogMain(int num) break; } if( !exit ) - vmsg("布落格完成"); + vmsg("部落格完成"); } currutmp->mode = oldmode; pressanykey(); diff --git a/pttbbs/mbbsd/var.c b/pttbbs/mbbsd/var.c index b9c96319..09a90850 100644 --- a/pttbbs/mbbsd/var.c +++ b/pttbbs/mbbsd/var.c @@ -1,4 +1,4 @@ -/* $Id: var.c,v 1.18 2003/05/26 05:30:04 in2 Exp $ */ +/* $Id: var.c,v 1.19 2003/05/30 10:28:32 in2 Exp $ */ #define INCLUDE_VAR_H #include "bbs.h" @@ -262,7 +262,7 @@ char *ModeTypeTable[MAX_MODES] = { "NBA大猜測" /* TMPJACK */ "Ptt查榜系統", /* JCEE */ "重編文章" /* REEDIT */ - "布落格", /* BLOGGING */ + "部落格", /* BLOGGING */ "", /* for future usage */ "", "", -- cgit v1.2.3 From 09a1c9d6913cc50e4236049d462b7b109096f042 Mon Sep 17 00:00:00 2001 From: in2 Date: Fri, 30 May 2003 10:31:37 +0000 Subject: for attribute git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@913 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/blog/builddb.pl | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/pttbbs/blog/builddb.pl b/pttbbs/blog/builddb.pl index 36e09a68..74bd5d99 100755 --- a/pttbbs/blog/builddb.pl +++ b/pttbbs/blog/builddb.pl @@ -81,14 +81,11 @@ sub buildconfigure($$) $c = $rch->{"$_.content"}; open FH, ">$outdir/$fn"; - if( $c =~ m|(.*?)(.*)|s ){ + if( $c =~ m|(.*?)\n\s*\s*\n(.*)|s ){ ($a, $c) = ($1, $2); $a =~ s/^\s*\#.*?\n//gm; foreach( split("\n", $a) ){ - if( /^\s*(\w+):\s+(.*)/ ){ - $attr{"$fn.$1"} = $2; - print "\t$1: $2\n"; - } + $attr{"$fn.$1"} = $2 if( /^\s*(\w+):\s+(.*)/ ); } } print FH $c; -- cgit v1.2.3 From cd2a166c57814ed27b89bfa903ae3d227fec209b Mon Sep 17 00:00:00 2001 From: in2 Date: Fri, 30 May 2003 13:58:11 +0000 Subject: use vmsg() git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@914 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/announce.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/pttbbs/mbbsd/announce.c b/pttbbs/mbbsd/announce.c index 61158c95..81293fea 100644 --- a/pttbbs/mbbsd/announce.c +++ b/pttbbs/mbbsd/announce.c @@ -1,4 +1,4 @@ -/* $Id: announce.c,v 1.24 2003/05/30 10:28:32 in2 Exp $ */ +/* $Id: announce.c,v 1.25 2003/05/30 13:58:11 in2 Exp $ */ #include "bbs.h" static void @@ -353,8 +353,7 @@ a_copyitem(char *fpath, char *title, char *owner, int mode) else *copyowner = 0; if (mode) { - outmsg("檔案標記完成。[注意] 拷貝後才能刪除原文!"); - igetch(); + vmsg("檔案標記完成。[注意] 拷貝後才能刪除原文!"); } } -- cgit v1.2.3 From 279728a516ab54039261a4061cdba9f3dbed0270 Mon Sep 17 00:00:00 2001 From: in2 Date: Sat, 31 May 2003 12:40:27 +0000 Subject: overwrite BOARDNAME, ignore s/[<>"] git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@915 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/blog/blog.pl | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/pttbbs/blog/blog.pl b/pttbbs/blog/blog.pl index af2112fa..6f77f858 100755 --- a/pttbbs/blog/blog.pl +++ b/pttbbs/blog/blog.pl @@ -1,5 +1,5 @@ #!/usr/bin/perl -# $Id: blog.pl,v 1.9 2003/05/30 10:17:34 in2 Exp $ +# $Id: blog.pl,v 1.10 2003/05/31 12:40:27 in2 Exp $ use CGI qw/:standard/; use LocalVars; use DB_File; @@ -43,6 +43,7 @@ sub main # first, import all settings in %config %th = %config; + $th{BOARDNAME} = $brdname; # loadBlog --------------------------------------------------------------- tie %article, 'DB_File', "$BLOGDATA/$brdname.db", O_RDONLY, 0666, $DB_HASH; @@ -242,9 +243,9 @@ sub applyfilter($$) my($c, $filter) = @_; foreach( split(',', $filter) ){ if( /^generic$/i ){ - $c =~ s/\/>/gs; - $c =~ s/\"/"/gs; + #$c =~ s/\/>/gs; + #$c =~ s/\"/"/gs; $c =~ s/\n/
\n/gs; } elsif( /^ubb$/i ){ -- cgit v1.2.3 From 1b8913058fb642723ce9a47d7bc1a78783afc86f Mon Sep 17 00:00:00 2001 From: in2 Date: Sat, 31 May 2003 13:39:18 +0000 Subject: code for inserting data inside linked-list git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@916 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/blog/builddb.pl | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/pttbbs/blog/builddb.pl b/pttbbs/blog/builddb.pl index 74bd5d99..b5262017 100755 --- a/pttbbs/blog/builddb.pl +++ b/pttbbs/blog/builddb.pl @@ -146,7 +146,16 @@ sub builddata($$$$$$) $dat{last} = $currid; } else{ # inside ? @_@;;; - debugmsg("not implement yet"); + my($p, $c); + for( $p = $dat{last} ; $p>$currid ; $p = $dat{"$p.prev"} ){ + ; + } + $c = $dat{"$p.next"}; + + $dat{"$currid.next"} = $c; + $dat{"$currid.prev"} = $p; + $dat{"$p.next"} = $currid; + $dat{"$c.prev"} = $currid; } $dat{$currid} = 1; } -- cgit v1.2.3 From 78bed9eef483e7367b4a0b171d910713f6dcdc91 Mon Sep 17 00:00:00 2001 From: in2 Date: Sun, 1 Jun 2003 08:44:07 +0000 Subject: allow brdname has - git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@917 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/blog/blog.pl | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pttbbs/blog/blog.pl b/pttbbs/blog/blog.pl index 6f77f858..0106db76 100755 --- a/pttbbs/blog/blog.pl +++ b/pttbbs/blog/blog.pl @@ -1,5 +1,5 @@ #!/usr/bin/perl -# $Id: blog.pl,v 1.10 2003/05/31 12:40:27 in2 Exp $ +# $Id: blog.pl,v 1.11 2003/06/01 08:44:07 in2 Exp $ use CGI qw/:standard/; use LocalVars; use DB_File; @@ -26,11 +26,11 @@ sub main print header(-status => 400); return; } - if( !(($brdname, $fn) = $ENV{PATH_INFO} =~ m|/(\w+?)/([\.,\w]*)|) || - !( ($fn, $y, $m, $d) = parsefn($fn) ) || - !(-e "$BLOGDATA/$brdname/$fn") || + if( !(($brdname, $fn) = $ENV{PATH_INFO} =~ m|/([\w\-]+?)/([\.,\w]*)|) || + !( ($fn, $y, $m, $d) = parsefn($fn) ) || + !(-e "$BLOGDATA/$brdname/$fn") || !(tie %config, 'DB_File', - "$BLOGDATA/$brdname/config.db", O_RDONLY, 0666, $DB_HASH) || + "$BLOGDATA/$brdname/config.db", O_RDONLY, 0666, $DB_HASH) || !(tie %attr, 'DB_File', "$BLOGDATA/$brdname/attr.db", O_RDONLY, 0666, $DB_HASH) ){ print header(-status => 404); -- cgit v1.2.3 From 87085e940d1c48c9baf9fe264cfb422ab38511a8 Mon Sep 17 00:00:00 2001 From: in2 Date: Sun, 1 Jun 2003 09:19:25 +0000 Subject: fix ubb git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@918 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/blog/blog.pl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pttbbs/blog/blog.pl b/pttbbs/blog/blog.pl index 0106db76..86469046 100755 --- a/pttbbs/blog/blog.pl +++ b/pttbbs/blog/blog.pl @@ -1,5 +1,5 @@ #!/usr/bin/perl -# $Id: blog.pl,v 1.11 2003/06/01 08:44:07 in2 Exp $ +# $Id: blog.pl,v 1.12 2003/06/01 09:19:25 in2 Exp $ use CGI qw/:standard/; use LocalVars; use DB_File; @@ -249,8 +249,8 @@ sub applyfilter($$) $c =~ s/\n/
\n/gs; } elsif( /^ubb$/i ){ - $c =~ s|\[url\](.*?)\[/url\]|\1|gsi; - $c =~ s|\[url=(.*?)\](.*?)\[/url\]|\2|gsi; + $c =~ s|\[url\](.*?)\[/url\]|\1|gsi; + $c =~ s|\[url=(.*?)\](.*?)\[/url\]|\2|gsi; $c =~ s|\[email\](.*?)\[/email\]|\1|gsi; $c =~ s|\[b\](.*?)\[/b\]|\1|gsi; $c =~ s|\[i\](.*?)\[/i\]|\1|gsi; -- cgit v1.2.3 From f9d8e92a0be24a72b8bffedfaca050ec6b346c95 Mon Sep 17 00:00:00 2001 From: in2 Date: Mon, 2 Jun 2003 01:43:16 +0000 Subject: register git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@919 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/user.c | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/pttbbs/mbbsd/user.c b/pttbbs/mbbsd/user.c index 5eac671d..33288f0a 100644 --- a/pttbbs/mbbsd/user.c +++ b/pttbbs/mbbsd/user.c @@ -1,4 +1,4 @@ -/* $Id: user.c,v 1.60 2003/05/12 12:47:18 victor Exp $ */ +/* $Id: user.c,v 1.61 2003/06/02 01:43:16 in2 Exp $ */ #include "bbs.h" static char *sex[8] = { @@ -1060,7 +1060,8 @@ static char *isvaildname(char *rname) !strstr(rname, "老頭") && !strstr(rname, "豬頭") && !strstr(rname, "寶貝") && !strstr(rname, "小白") && !strstr(rname, "小明") && !strstr(rname, "小妹") && - !strstr(rname, "路人") && + !strstr(rname, "路人") && !strstr(rname, "不說") && + !strstr(rname, "不知") && !strstr(rname, "你媽") && strncmp(rname, "小", 2) != 0 && //起頭是「小」 strncmp(rname, "我是", 4) != 0 && //起頭是「我是」 @@ -1073,9 +1074,14 @@ static char *isvaildname(char *rname) static char *isvaildcareer(char *career) { if (!(removespace(career) && career[0] < 0 - && strlen(career) >= 6) || - strcmp(career, "家裡") == 0 || - strstr(career, "某") != NULL ) { + && strlen(career) >= 6) || + strcmp(career, "家裡") == 0 || + strstr(career, "幹") != NULL || + strstr(career, "不知") != NULL || + strstr(career, "不說") != NULL || + strstr(career, "你管") != NULL || + strstr(career, "管我") != NULL || + strstr(career, "某") != NULL ) { return "您的輸入不正確"; } if (strcmp(&career[strlen(career) - 2], "大") == 0 || @@ -1095,11 +1101,18 @@ static char *isvaildaddr(char *addr) strstr(addr, "地球") != NULL || strstr(addr, "銀河") != NULL || strstr(addr, "火星") != NULL || + strstr(addr, "不知") != NULL || + strstr(addr, "不說") != NULL || + strstr(addr, "你管") != NULL || + strstr(addr, "管我") != NULL || strstr(addr, "某") != NULL || strstr(addr, "..") != NULL || + strstr(addr, "xx") != NULL || + strstr(addr, "幹") != NULL || strcmp(&addr[strlen(addr) - 2], "段") == 0 || strcmp(&addr[strlen(addr) - 2], "路") == 0 || strcmp(&addr[strlen(addr) - 2], "巷") == 0 || + strcmp(&addr[strlen(addr) - 2], "區") == 0 || strcmp(&addr[strlen(addr) - 2], "街") == 0 ) return "這個地址並不合法"; return NULL; -- cgit v1.2.3 From 8579eb578d99e56d0510cef600baf0de439388a0 Mon Sep 17 00:00:00 2001 From: in2 Date: Mon, 2 Jun 2003 02:09:38 +0000 Subject: correct 'blog.pl/xxx' to 'blog.pl/xxx/' git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@920 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/blog/blog.pl | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pttbbs/blog/blog.pl b/pttbbs/blog/blog.pl index 86469046..e0100d4e 100755 --- a/pttbbs/blog/blog.pl +++ b/pttbbs/blog/blog.pl @@ -1,5 +1,5 @@ #!/usr/bin/perl -# $Id: blog.pl,v 1.12 2003/06/01 09:19:25 in2 Exp $ +# $Id: blog.pl,v 1.13 2003/06/02 02:09:38 in2 Exp $ use CGI qw/:standard/; use LocalVars; use DB_File; @@ -26,13 +26,15 @@ sub main print header(-status => 400); return; } - if( !(($brdname, $fn) = $ENV{PATH_INFO} =~ m|/([\w\-]+?)/([\.,\w]*)|) || + if( !(($brdname, $fn) = $ENV{PATH_INFO} =~ m|^/([\w\-]+?)/([\.,\w]*)$|) || !( ($fn, $y, $m, $d) = parsefn($fn) ) || !(-e "$BLOGDATA/$brdname/$fn") || !(tie %config, 'DB_File', "$BLOGDATA/$brdname/config.db", O_RDONLY, 0666, $DB_HASH) || !(tie %attr, 'DB_File', "$BLOGDATA/$brdname/attr.db", O_RDONLY, 0666, $DB_HASH) ){ + return redirect("http://blog.ptt2.cc/blog.pl/$1/") + if( $ENV{PATH_INFO} =~ m|^/([\w\-]+?)$| ); print header(-status => 404); return; } -- cgit v1.2.3 From 9c0c3379944ab2a8dd3b17f0bcf597f2168d5177 Mon Sep 17 00:00:00 2001 From: in2 Date: Mon, 2 Jun 2003 03:39:24 +0000 Subject: add lib ., fix regex for ubb git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@921 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/blog/blog.pl | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/pttbbs/blog/blog.pl b/pttbbs/blog/blog.pl index e0100d4e..ccfeb5c3 100755 --- a/pttbbs/blog/blog.pl +++ b/pttbbs/blog/blog.pl @@ -1,6 +1,7 @@ #!/usr/bin/perl -# $Id: blog.pl,v 1.13 2003/06/02 02:09:38 in2 Exp $ +# $Id: blog.pl,v 1.14 2003/06/02 03:39:24 in2 Exp $ use CGI qw/:standard/; +use lib qw/./; use LocalVars; use DB_File; use strict; @@ -251,12 +252,12 @@ sub applyfilter($$) $c =~ s/\n/
\n/gs; } elsif( /^ubb$/i ){ - $c =~ s|\[url\](.*?)\[/url\]|\1|gsi; - $c =~ s|\[url=(.*?)\](.*?)\[/url\]|\2|gsi; - $c =~ s|\[email\](.*?)\[/email\]|\1|gsi; - $c =~ s|\[b\](.*?)\[/b\]|\1|gsi; - $c =~ s|\[i\](.*?)\[/i\]|\1|gsi; - $c =~ s|\[img\](.*?)\[/img\]||gsi; + $c =~ s|\[url\](.*?)\[/url\]|$1|gsi; + $c =~ s|\[url=(.*?)\](.*?)\[/url\]|$2|gsi; + $c =~ s|\[email\](.*?)\[/email\]|$1|gsi; + $c =~ s|\[b\](.*?)\[/b\]|$1|gsi; + $c =~ s|\[i\](.*?)\[/i\]|$1|gsi; + $c =~ s|\[img\](.*?)\[/img\]||gsi; } } return $c; -- cgit v1.2.3 From d27183540fee8c1a21f73d0582b1fef5eba4fcd1 Mon Sep 17 00:00:00 2001 From: in2 Date: Mon, 2 Jun 2003 05:34:57 +0000 Subject: anti flooding counter git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@922 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/blog/blog.pl | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/pttbbs/blog/blog.pl b/pttbbs/blog/blog.pl index ccfeb5c3..ab8b4aa9 100755 --- a/pttbbs/blog/blog.pl +++ b/pttbbs/blog/blog.pl @@ -1,5 +1,5 @@ #!/usr/bin/perl -# $Id: blog.pl,v 1.14 2003/06/02 03:39:24 in2 Exp $ +# $Id: blog.pl,v 1.15 2003/06/02 05:34:57 in2 Exp $ use CGI qw/:standard/; use lib qw/./; use LocalVars; @@ -131,8 +131,10 @@ sub main if( $attr{"$fn.loadCounter"} ){ $th{counter} = dodbi(sub { my($dbh) = @_; - my($sth, $t); - $dbh->do("update counter set v = v + 1 where k = '$brdname'"); + my($sth, $t, $time); + $time = time(); + $dbh->do("update counter set v = v + 1, mtime = $time ". + "where k = '$brdname' && mtime < ". ($time - 2)); $sth = $dbh->prepare("select v from counter where k='$brdname'"); $sth->execute(); $t = $sth->fetchrow_hashref(); -- cgit v1.2.3 From 641d2c20b6328487b0d74e6474e29a15fd4884ed Mon Sep 17 00:00:00 2001 From: victor Date: Mon, 2 Jun 2003 14:49:04 +0000 Subject: let foreigner be able to post in PttForeign git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@923 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/bbs.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/pttbbs/mbbsd/bbs.c b/pttbbs/mbbsd/bbs.c index 80ec2767..5accfca2 100644 --- a/pttbbs/mbbsd/bbs.c +++ b/pttbbs/mbbsd/bbs.c @@ -1,4 +1,4 @@ -/* $Id: bbs.c,v 1.96 2003/05/26 05:29:39 in2 Exp $ */ +/* $Id: bbs.c,v 1.97 2003/06/02 14:49:04 victor Exp $ */ #include "bbs.h" static int recommend(int ent, fileheader_t * fhdr, char *direct); @@ -453,7 +453,12 @@ do_general() bp = getbcache(currbid); clear(); - if (!(currmode & MODE_POST)) { + if (!(currmode & MODE_POST) +#ifdef FOREIGN_REG + // 不是外籍使用者在 PttForeign 板 + && !((cuser.uflag2 & FOREIGN) && strcmp(bp->brdname, "PttForeign")) +#endif + ) { move(5, 10); outs("對不起,您目前無法在此發表文章!"); pressanykey(); -- cgit v1.2.3 From c22b7b8966dd9902a424f898d29cf7de71f44cbd Mon Sep 17 00:00:00 2001 From: in2 Date: Mon, 2 Jun 2003 14:59:09 +0000 Subject: fix bug git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@924 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/blog/blog.pl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pttbbs/blog/blog.pl b/pttbbs/blog/blog.pl index ab8b4aa9..5e4f411d 100755 --- a/pttbbs/blog/blog.pl +++ b/pttbbs/blog/blog.pl @@ -1,5 +1,5 @@ #!/usr/bin/perl -# $Id: blog.pl,v 1.15 2003/06/02 05:34:57 in2 Exp $ +# $Id: blog.pl,v 1.16 2003/06/02 14:59:09 in2 Exp $ use CGI qw/:standard/; use lib qw/./; use LocalVars; @@ -64,7 +64,7 @@ sub main my($ptr, $i); for( $ptr = $article{last}, $i = 0 ; $ptr && $i < $1 ; - $ptr = $article{"$ptr.prev"} ){ + $ptr = $article{"$ptr.prev"}, ++$i ){ AddArticle('blog', $attr{"$fn.loadBlogFields"}, $ptr); } -- cgit v1.2.3 From 39b1c94e625510bce9452b4cbf24bea106a8d3ff Mon Sep 17 00:00:00 2001 From: in2 Date: Mon, 2 Jun 2003 15:22:48 +0000 Subject: add git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@925 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/blog/INSTALL | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 pttbbs/blog/INSTALL diff --git a/pttbbs/blog/INSTALL b/pttbbs/blog/INSTALL new file mode 100644 index 00000000..b5dafd6c --- /dev/null +++ b/pttbbs/blog/INSTALL @@ -0,0 +1,45 @@ +這篇文章在描述怎麼架設 PttBlog, 最後一次修正的時間為: +$Id: INSTALL,v 1.1 2003/06/02 15:22:48 in2 Exp $ + +請注意, PttBlog本來主要是設計給 Ptt2 站台使用, 目前正在開發階段, +並未接受嚴密的測試, 可能還缺少很多功能, 以及可能有許多的 bug. + +您可以按照下列的步驟安裝好 PttBlog. +1.安裝好下列的東西, 我們並同時列上 FreeBSD ports內的目錄: + apache /usr/ports/www/apache13/ + perl /usr/ports/lang/perl5.8/ + mod_perl /usr/ports/www/mod_perl/ + + 以及下列的 module + Template /usr/ports/www/p5-Template-Toolkit/ + Date::Calc /usr/ports/devel/p5-Date-Calc/ + +2.設定 apache 可以直接透過 mod_perl 來跑 perl script . + 在您的 apache.conf (or httpd.conf)中, 應該會有: + LoadModule perl_module libexec/apache/libperl.so + AddModule mod_perl.c + 在中間, 加上這兩行: + AddHandler perl-script .pl + PerlHandler Apache::Registry + +3.設定好 blog 的 web目錄. 裡面至少要有 index.pl, blog.pl, LocalVars.pm + (其中 LocalVars.pm 建議用 symbolic link 到 /home/bbs/bin/的那一份) + 其中 *.pl 的權限要是可以執行的 (ex: chmod 755 *.pl) + +4.設定 apache 指到 blog 的目錄. 並將該目錄開始 ExecCGI的 option. + 例如使用 Virtual Host : + NameVirtualHost * + + ServerName blog.ptt2.cc + DocumentRoot /home/bbs/blog/web + + Options ExecCGI + + + +5.將 builddb.pl, BBSFileHeader.pm 拷貝進 ~bbs/bin + 您可以嘗試用 perl -c ~bbs/bin/builddb.pl 測試看看能不能過. + 若不行的話, 通常是 LocalVars.pm 裡面少東西, + 請參考 pttbbs/sample/LocalVars.pm 的 blog 區. + +6.將 #define BLOG 加入您的 pttbbs.conf裡面, 重新 build並且 restart. -- cgit v1.2.3 From 80a0e256d801f235fb07888e38f7da59df96a1c0 Mon Sep 17 00:00:00 2001 From: in2 Date: Mon, 2 Jun 2003 15:23:32 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@926 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/blog/index.pl | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100755 pttbbs/blog/index.pl diff --git a/pttbbs/blog/index.pl b/pttbbs/blog/index.pl new file mode 100755 index 00000000..cad0fba3 --- /dev/null +++ b/pttbbs/blog/index.pl @@ -0,0 +1,8 @@ +#!/usr/bin/perl +# $Id: index.pl,v 1.1 2003/06/02 15:23:32 in2 Exp $ +use CGI qw/:standard/; + +print redirect("http://blog.ptt2.cc/blog.pl/$1/") + if( $ENV{REDIRECT_REQUEST_URI} =~ m|/\?(.*)| ); + +return redirect("http://blog.ptt2.cc/blog.pl/Blog/"); -- cgit v1.2.3 From 157234a6ed4a6858dd2c5e7a904d49db4a87ab39 Mon Sep 17 00:00:00 2001 From: in2 Date: Tue, 3 Jun 2003 02:50:38 +0000 Subject: for XHTML 1.0 git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@927 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/blog/blog.pl | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pttbbs/blog/blog.pl b/pttbbs/blog/blog.pl index 5e4f411d..8568c759 100755 --- a/pttbbs/blog/blog.pl +++ b/pttbbs/blog/blog.pl @@ -1,5 +1,5 @@ #!/usr/bin/perl -# $Id: blog.pl,v 1.16 2003/06/02 14:59:09 in2 Exp $ +# $Id: blog.pl,v 1.17 2003/06/03 02:50:38 in2 Exp $ use CGI qw/:standard/; use lib qw/./; use LocalVars; @@ -254,12 +254,12 @@ sub applyfilter($$) $c =~ s/\n/
\n/gs; } elsif( /^ubb$/i ){ - $c =~ s|\[url\](.*?)\[/url\]|$1|gsi; - $c =~ s|\[url=(.*?)\](.*?)\[/url\]|$2|gsi; - $c =~ s|\[email\](.*?)\[/email\]|$1|gsi; + $c =~ s|\[url\](.*?)\[/url\]|$1|gsi; + $c =~ s|\[url=(.*?)\](.*?)\[/url\]|$2|gsi; + $c =~ s|\[email\](.*?)\[/email\]|$1|gsi; $c =~ s|\[b\](.*?)\[/b\]|$1|gsi; $c =~ s|\[i\](.*?)\[/i\]|$1|gsi; - $c =~ s|\[img\](.*?)\[/img\]||gsi; + $c =~ s|\[img\](.*?)\[/img\]|(null)|gsi; } } return $c; -- cgit v1.2.3 From db2481f2070857efbb17202226f4d958de2347c1 Mon Sep 17 00:00:00 2001 From: in2 Date: Tue, 3 Jun 2003 07:07:00 +0000 Subject: add Template-Compiled for blog git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@928 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/blog/blog.pl | 5 ++++- pttbbs/sample/LocalVars.pm | 8 ++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/pttbbs/blog/blog.pl b/pttbbs/blog/blog.pl index 8568c759..c14ca34a 100755 --- a/pttbbs/blog/blog.pl +++ b/pttbbs/blog/blog.pl @@ -1,5 +1,5 @@ #!/usr/bin/perl -# $Id: blog.pl,v 1.17 2003/06/03 02:50:38 in2 Exp $ +# $Id: blog.pl,v 1.18 2003/06/03 07:06:59 in2 Exp $ use CGI qw/:standard/; use lib qw/./; use LocalVars; @@ -205,11 +205,14 @@ sub main } # 用 Template Toolkit 輸出 + mkdir "$BLOGCACHE/$brdname"; $tmpl = Template->new({INCLUDE_PATH => '.', ABSOLUTE => 0, RELATIVE => 0, RECURSION => 0, EVAL_PERL => 0, + COMPILE_EXT => '.pl', + COMPILE_DIR => "$BLOGCACHE/$brdname/", }); chdir "$BLOGDATA/$brdname/"; $tmpl->process($fn, \%th) || diff --git a/pttbbs/sample/LocalVars.pm b/pttbbs/sample/LocalVars.pm index a2ad4ab5..4e52d0f0 100644 --- a/pttbbs/sample/LocalVars.pm +++ b/pttbbs/sample/LocalVars.pm @@ -6,7 +6,7 @@ require Exporter; $hostname $MYHOSTNAME $FQDN $SMTPSERVER $BBSHOME $JOBSPOOL $TMP $TAR $LYNX $GREP - $BLOGDATA + $BLOGDATA $BLOGCACHE /; # host @@ -25,5 +25,9 @@ $TAR = '/usr/bin/tar'; $LYNX = '/usr/local/bin/lynx'; # /usr/ports/www/lynx $GREP = '/usr/bin/grep'; -# blog +# BLOG: +# $BLOGDATA 是用來放置 Blog 資料的路徑 +# $BLOGCACHE是用來放置 Template compiled 資料的路徑, +# 須為 apache owner 可寫入 $BLOGDATA = '/home/bbs/blog/data'; +$BLOGCACHE = '/home/bbs/blog/cache'; -- cgit v1.2.3 From 8a74483c9f883c77d56c356641063480b235d9b0 Mon Sep 17 00:00:00 2001 From: in2 Date: Tue, 3 Jun 2003 08:51:25 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@929 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/docs/DONATE | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 pttbbs/docs/DONATE diff --git a/pttbbs/docs/DONATE b/pttbbs/docs/DONATE new file mode 100644 index 00000000..7b572441 --- /dev/null +++ b/pttbbs/docs/DONATE @@ -0,0 +1,27 @@ +這篇文章描述關於贊助 PttBBS . 最後一次修正的時間在: +$Id: DONATE,v 1.1 2003/06/03 08:51:25 in2 Exp $ + +Donate to PttBBS! + PttBBS 是免費自由軟體, 我們透過這套系統(正如您手上這一份), 在台大 +資訊系裡面架起了批踢踢實業坊以及批踢踢兔, 直到今日 Ptt及 Ptt2 引起 +不錯的回響, 而 Ptt更在日前站上了同時服務一萬人的里程碑, 而這份服務 +也是完全不收取任何費用的. +我們希望所有的使用者, 不論您是直接連上 Ptt/Ptt2 , 或是透過本系統自 +行架設站台, 都可以享受在其中; 事實上, 我們花了許多時間, 精力, 甚至 +金錢, 用在研發改善, 以及提供服務. 而這一份系統就含有超過三萬行的程 +式碼, 為了要讓 Ptt/Ptt2 可以營運, 就用掉超過十顆 SCSI 硬碟, 再加上 +無數人的心血. + +對於我們的貢獻, 或許有人願意向我們說聲感謝, 而這邊有一個方便的方式 +, 可以讓您表達對我們的謝意. + +我們歡迎您提供贊助給我們, 不論是提供金錢上的贊助, 或是設備上的贊助 + (我們建議是贊助設備, 因為錢總是帶來麻煩的事情 :( ) . 而您的贊助我 +們將全數使用在 Ptt/Ptt2 上面. +我們主要須要多數的硬碟以提供存放使用者資料, 由於 SCSI 的硬碟得以同 +時讀寫, 越多顆硬碟可以分散原來的負荷. 我們須要的規格是, +Ultra SCSI 160 (或 320) , 68 pins , 4MB 或以上的 cache, 10000rpm +或以上, 容量 18GB 或以上. 或者是我們希望可以整個更新機器, 須要 + cpu Xeon 2.0G以上 1~2 , 記憶體 6GB或以上. + +詳細的情況, 請和當時的系統站長聯絡^^ -- cgit v1.2.3 From c7d2264784fe600553fd4e7f67d3a172f95103b3 Mon Sep 17 00:00:00 2001 From: in2 Date: Tue, 3 Jun 2003 09:01:15 +0000 Subject: new version git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@930 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/README | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/pttbbs/README b/pttbbs/README index 672bb33c..b79f12c8 100644 --- a/pttbbs/README +++ b/pttbbs/README @@ -1,12 +1,24 @@ +$Id: README,v 1.2 2003/06/03 09:01:15 in2 Exp $ -快速安裝方法請參閱 INSTALL +若有任何問請, 請到批踢踢實業坊 telnet://ptt.csie.ntu.edu.tw +的 PttCurrent 看板詢問 -常見問題及 sendmail.cf 的設法請見 FAQ +您可以參考 docs/INSTALL , 介紹快速安裝的方式, +以及 docs/FAQ 的常見問題集. -sample 下有 crontab 及 rc.local 的範例 +目錄結構: + LICENSE 本軟體的授權方式 + + docs/ 文件 + INSTALL 快速安裝方式 + FAQ 常見的問題, sendmail.cf的設定方法等等 -有任何問題請mail給 pttbbs@ptt2.csie.ntu.edu.tw + sample/ 範例 + crontab 提供 bbs執行時須透過 crontab 定時跑的設定 -也可到 ptt2.csie.ntu.edu.tw / ptt2.twbbs.org 的 PttSrc 板詢問 - -謝謝 :) + blog/ PttBLOG + include/ include 檔 + innbbsd/ 轉信 + mbbsd/ bbs 主程式 + mbbsd.icc/ 提供使用 icc來編譯所須要的 Makefile + pttpi/ Ptt Programming Interface -- cgit v1.2.3 From 6a19f8bff0289b526f4a0163bdb2de8f814c2d40 Mon Sep 17 00:00:00 2001 From: in2 Date: Tue, 3 Jun 2003 09:25:12 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@931 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/README | 37 +++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/pttbbs/README b/pttbbs/README index b79f12c8..7825c087 100644 --- a/pttbbs/README +++ b/pttbbs/README @@ -1,24 +1,29 @@ -$Id: README,v 1.2 2003/06/03 09:01:15 in2 Exp $ +$Id: README,v 1.3 2003/06/03 09:25:12 in2 Exp $ + +快速安裝請參考 docs/INSTALL 以及 docs/FAQ +詳細文件請見 docs/ 若有任何問請, 請到批踢踢實業坊 telnet://ptt.csie.ntu.edu.tw 的 PttCurrent 看板詢問 -您可以參考 docs/INSTALL , 介紹快速安裝的方式, -以及 docs/FAQ 的常見問題集. - 目錄結構: - LICENSE 本軟體的授權方式 + LICENSE 本軟體的授權方式 - docs/ 文件 - INSTALL 快速安裝方式 - FAQ 常見的問題, sendmail.cf的設定方法等等 + docs/ 文件 + + ADVANCE 進階功能 + ANCESTOR 沿承歷史 + DONATE 贊助方式 + FAQ 常見的問題, sendmail.cf的設定方法等等 + INSTALL 快速安裝方式 + z6ibbs.[12].txt in2 隨筆 - sample/ 範例 - crontab 提供 bbs執行時須透過 crontab 定時跑的設定 + sample/ 範例 + crontab 提供 bbs執行時須透過 crontab 定時跑的設定 - blog/ PttBLOG - include/ include 檔 - innbbsd/ 轉信 - mbbsd/ bbs 主程式 - mbbsd.icc/ 提供使用 icc來編譯所須要的 Makefile - pttpi/ Ptt Programming Interface + blog/ PttBLOG + include/ include 檔 + innbbsd/ 轉信 + mbbsd/ bbs 主程式 + mbbsd.icc/ 提供使用 icc來編譯所須要的 Makefile + pttpi/ Ptt Programming Interface -- cgit v1.2.3 From e6da6d1d7a00750e940b6ca4c1d2eba98f57ea9f Mon Sep 17 00:00:00 2001 From: victor Date: Wed, 4 Jun 2003 02:09:53 +0000 Subject: let subop cp man dir git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@932 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/announce.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pttbbs/mbbsd/announce.c b/pttbbs/mbbsd/announce.c index 81293fea..3d4361cf 100644 --- a/pttbbs/mbbsd/announce.c +++ b/pttbbs/mbbsd/announce.c @@ -1,4 +1,4 @@ -/* $Id: announce.c,v 1.25 2003/05/30 13:58:11 in2 Exp $ */ +/* $Id: announce.c,v 1.26 2003/06/04 02:09:53 victor Exp $ */ #include "bbs.h" static void @@ -1442,7 +1442,7 @@ a_menu(char *maintitle, char *path, int lastlevel) 還是檔案竟然是用 fstat(2) 而不是直接存在 .DIR 內 |||b 須等該資料寫入 .DIR 內再 implement才有效率. */ - if( !HAS_PERM(PERM_SYSOP) && !is_BM(bcache[currbid - 1].BM) && + if( !HAS_PERM(PERM_SYSOP) && !HAS_PERM(PERM_SYSSUBOP) && !is_BM(bcache[currbid - 1].BM) && dashd(fname) ) vmsg("只有板主才可以拷貝目錄唷!"); else -- cgit v1.2.3 From 3fd07b1f3b350e740243febed4b8d89577e976ed Mon Sep 17 00:00:00 2001 From: in2 Date: Thu, 5 Jun 2003 03:42:06 +0000 Subject: need mysql support git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@933 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/blog/INSTALL | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pttbbs/blog/INSTALL b/pttbbs/blog/INSTALL index b5dafd6c..e176ab88 100644 --- a/pttbbs/blog/INSTALL +++ b/pttbbs/blog/INSTALL @@ -1,5 +1,5 @@ 這篇文章在描述怎麼架設 PttBlog, 最後一次修正的時間為: -$Id: INSTALL,v 1.1 2003/06/02 15:22:48 in2 Exp $ +$Id: INSTALL,v 1.2 2003/06/05 03:42:06 in2 Exp $ 請注意, PttBlog本來主要是設計給 Ptt2 站台使用, 目前正在開發階段, 並未接受嚴密的測試, 可能還缺少很多功能, 以及可能有許多的 bug. @@ -9,10 +9,13 @@ $Id: INSTALL,v 1.1 2003/06/02 15:22:48 in2 Exp $ apache /usr/ports/www/apache13/ perl /usr/ports/lang/perl5.8/ mod_perl /usr/ports/www/mod_perl/ + mysql /usr/ports/databases/mysql323-server/ 以及下列的 module Template /usr/ports/www/p5-Template-Toolkit/ Date::Calc /usr/ports/devel/p5-Date-Calc/ + DBI /usr/ports/databases/p5-DBI/ + DBD::mysql /usr/ports/databases/p5-DBD-mysql/ 2.設定 apache 可以直接透過 mod_perl 來跑 perl script . 在您的 apache.conf (or httpd.conf)中, 應該會有: -- cgit v1.2.3 From ca72aaa5fd8d893def9110dff502263a3431b071 Mon Sep 17 00:00:00 2001 From: kcwu Date: Sat, 7 Jun 2003 14:19:12 +0000 Subject: fix corrupted big5 comment git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@934 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/cache.c | 4 ++-- pttbbs/mbbsd/kaede.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pttbbs/mbbsd/cache.c b/pttbbs/mbbsd/cache.c index a5c6c43c..fb7baca8 100644 --- a/pttbbs/mbbsd/cache.c +++ b/pttbbs/mbbsd/cache.c @@ -1,4 +1,4 @@ -/* $Id: cache.c,v 1.61 2003/05/20 01:51:01 bbs Exp $ */ +/* $Id: cache.c,v 1.62 2003/06/07 14:19:12 kcwu Exp $ */ #include "bbs.h" #ifndef __FreeBSD__ @@ -789,7 +789,7 @@ haspostperm(char *bname) /*-------------------------------------------------------*/ /* PTT cache */ /*-------------------------------------------------------*/ -/* cachefor 動態看板 */ +/* cachefor 動態看板 */ void reload_pttcache() { diff --git a/pttbbs/mbbsd/kaede.c b/pttbbs/mbbsd/kaede.c index 0bdc3ef0..a3fd96ad 100644 --- a/pttbbs/mbbsd/kaede.c +++ b/pttbbs/mbbsd/kaede.c @@ -1,4 +1,4 @@ -/* $Id: kaede.c,v 1.13 2003/01/16 14:38:35 kcwu Exp $ */ +/* $Id: kaede.c,v 1.14 2003/06/07 14:19:12 kcwu Exp $ */ #include "bbs.h" char * @@ -65,7 +65,7 @@ Rename(char *src, char *dst) if (rename(src, dst) == 0) return 0; if (!strchr(src, ';') && !strchr(dst, ';')) - //Ptt 黎ㄔ膨`指令 + // Ptt 防不正常指令 { snprintf(buf, sizeof(buf), "/bin/mv %s %s", src, dst); system(buf); -- cgit v1.2.3 From e4f9c43846823bc1e149a71520a8bc36459909f3 Mon Sep 17 00:00:00 2001 From: victor Date: Sun, 8 Jun 2003 16:50:00 +0000 Subject: add fav backup, clean git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@935 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/board.c | 89 +++++++++++++++++++++++++++++----------------------- 1 file changed, 49 insertions(+), 40 deletions(-) diff --git a/pttbbs/mbbsd/board.c b/pttbbs/mbbsd/board.c index af285004..d8d667ab 100644 --- a/pttbbs/mbbsd/board.c +++ b/pttbbs/mbbsd/board.c @@ -1,4 +1,4 @@ -/* $Id: board.c,v 1.127 2003/05/03 02:48:57 victor Exp $ */ +/* $Id: board.c,v 1.128 2003/06/08 16:50:00 victor Exp $ */ #include "bbs.h" #define BRC_STRLEN 15 /* Length of board name */ #define BRC_MAXSIZE 24576 @@ -443,6 +443,27 @@ void updatenewfav(int mode) } } +void favclean(fav_t *fav){ + int i; + boardheader_t *bptr; + + for(i = 0; i < fav->nDatas; i++){ + if(fav->b[i].attr & BRD_LINE) + continue; + bptr = &bcache[ fav->b[i].bid - 1 ]; + if(!(fav->b[i].attr & BRD_FAV) || !Ben_Perm(bptr)){ + move(i, --fav->nDatas); + continue; + } + } +} + +void freefav(fav_t *fav){ + free(fav->b); + free(fav); + fav = NULL; +} + void load_brdbuf(void) { static char firsttime = 1; @@ -539,8 +560,7 @@ save_brdbuf(void) write(fd, &fav->b[i], sizeof(fav_board_t)); close(fd); } - free(fav); - fav = NULL; + freefav(fav); } int @@ -1295,45 +1315,34 @@ choose_board(int newflag) break; case 'K': if (HAS_PERM(PERM_BASIC)) { - char buf[2], fname[80]; -#if 1 - getdata(b_lines - 1, 0, "請確定是否匯入舊的我的最愛(警告! 這將覆寫我的最愛!)[y/N]", buf, sizeof(buf), DOECHO); -#else - getdata(b_lines - 1, 0, "請選擇匯入列表 1)我的最愛 2)訂閱\看板 (警告! 這將覆寫我的最愛!)", buf, sizeof(buf), DOECHO); - tmp = atoi(buf); - if(tmp == 1){ -#endif -#if 1 - if(buf[0] == 'Y' || buf[0] == 'y'){ -#endif - setuserfile(fname, FAV3); - unlink(fname); - load_brdbuf(); - } -#if 0 - else if(tmp == 2){ - int fd, zap, count = 0; - setuserfile(fname, FAV3); - unlink(fname); - setuserfile(fname, ".bbsrc"); - if( (fd = open(fname, O_RDONLY)) != -1 ){ - for(tmp = 0; tmp < numboards; tmp++){ - if(read(fd, &zap, sizeof(zap)) > 0){ - if(zap > 0 && bcache[tmp].brdname[0]){ - if(getfav(tmp + 1) != NULL){ - setfav(tmp + 1, BRD_FAV, 1, zap); - count++; - } - } - } - if(count >= FAVMAX){ - vmsg("已到達最愛上限 :("); - break; - } + char buf[2], buf2[2], fname[80], genbuf[256]; + int fd; + getdata(b_lines - 1, 0, "請選擇 1)清除不可見看板 2)備份我的最愛 3)取回最愛備份 [Q]", buf, sizeof(buf), DOECHO); + getdata(b_lines - 1, 0, "確定嗎 [y/N] ", buf2, sizeof(buf2), DOECHO); + if(buf2[0] != 'y') + break; + switch(buf[0]){ + case '1': + favclean(fav); + break; + case '2': + setuserfile(fname, FAV3); + sprintf(genbuf, "cp -f %s %s.bak", fname, fname); + system(genbuf); + break; + case '3': + setuserfile(fname, FAV3); + sprintf(genbuf, "%s.bak", fname); + if((fd = open(genbuf, O_RDONLY)) < 0){ + vmsg("你沒有備份你的最愛喔"); + break; } - } + close(fd); + freefav(fav); + load_brdbuf(); + favchange = 1; + break; } -#endif brdnum = -1; } break; -- cgit v1.2.3 From 4f9b34a2593a7c0a0bce7e5b25f208ebf4ec2072 Mon Sep 17 00:00:00 2001 From: victor Date: Sun, 8 Jun 2003 16:52:36 +0000 Subject: fix last commit bug git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@936 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/board.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pttbbs/mbbsd/board.c b/pttbbs/mbbsd/board.c index d8d667ab..5a8ccd59 100644 --- a/pttbbs/mbbsd/board.c +++ b/pttbbs/mbbsd/board.c @@ -1,4 +1,4 @@ -/* $Id: board.c,v 1.128 2003/06/08 16:50:00 victor Exp $ */ +/* $Id: board.c,v 1.129 2003/06/08 16:52:36 victor Exp $ */ #include "bbs.h" #define BRC_STRLEN 15 /* Length of board name */ #define BRC_MAXSIZE 24576 @@ -1318,6 +1318,8 @@ choose_board(int newflag) char buf[2], buf2[2], fname[80], genbuf[256]; int fd; getdata(b_lines - 1, 0, "請選擇 1)清除不可見看板 2)備份我的最愛 3)取回最愛備份 [Q]", buf, sizeof(buf), DOECHO); + if(!buf[0]) + break; getdata(b_lines - 1, 0, "確定嗎 [y/N] ", buf2, sizeof(buf2), DOECHO); if(buf2[0] != 'y') break; -- cgit v1.2.3 From 07756f440610eadbbb269204756478c3a00c6526 Mon Sep 17 00:00:00 2001 From: victor Date: Mon, 9 Jun 2003 03:18:17 +0000 Subject: fix bug git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@937 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/board.c | 51 ++++++++++++++++++++++++++++----------------------- 1 file changed, 28 insertions(+), 23 deletions(-) diff --git a/pttbbs/mbbsd/board.c b/pttbbs/mbbsd/board.c index 5a8ccd59..845134fc 100644 --- a/pttbbs/mbbsd/board.c +++ b/pttbbs/mbbsd/board.c @@ -1,4 +1,4 @@ -/* $Id: board.c,v 1.129 2003/06/08 16:52:36 victor Exp $ */ +/* $Id: board.c,v 1.130 2003/06/09 03:18:17 victor Exp $ */ #include "bbs.h" #define BRC_STRLEN 15 /* Length of board name */ #define BRC_MAXSIZE 24576 @@ -282,11 +282,27 @@ time_t getfavtime(short bid) return ptr->lastvisit; } -void movefav(int old, int new) +void basemovefav(int src, int des) { + int i; + fav_board_t tmp = fav->b[src]; + + if(src < des){ + for(i = src; i < des; i++) + fav->b[i] = fav->b[i + 1]; + } + else{ // des < src + for(i = src; i > des; i--) + fav->b[i] = fav->b[i - 1]; + } + fav->b[des] = tmp; + + brdnum = -1; +} +void movefav(int old, int new) +{ int i, src = -1, des = -1; - fav_board_t tmp; favchange = 1; for(i = 0; i < fav->nDatas; i++){ @@ -298,19 +314,7 @@ void movefav(int old, int new) if(src == -1 || des == -1) return; - - tmp = fav->b[src]; - if(src < des){ - for(i = src; i < des; i++) - fav->b[i] = fav->b[i + 1]; - } - else{ // des < src - for(i = src; i > des; i--) - fav->b[i] = fav->b[i - 1]; - } - fav->b[des] = tmp; - - brdnum = -1; + basemovefav(src, des); } void delfavline(int bid, int num) @@ -452,7 +456,7 @@ void favclean(fav_t *fav){ continue; bptr = &bcache[ fav->b[i].bid - 1 ]; if(!(fav->b[i].attr & BRD_FAV) || !Ben_Perm(bptr)){ - move(i, --fav->nDatas); + basemovefav(i, fav->nDatas--); continue; } } @@ -1315,15 +1319,14 @@ choose_board(int newflag) break; case 'K': if (HAS_PERM(PERM_BASIC)) { - char buf[2], buf2[2], fname[80], genbuf[256]; + char c, fname[80], genbuf[256]; int fd; - getdata(b_lines - 1, 0, "請選擇 1)清除不可見看板 2)備份我的最愛 3)取回最愛備份 [Q]", buf, sizeof(buf), DOECHO); - if(!buf[0]) + c = getans("請選擇 1)清除不可見看板 2)備份我的最愛 3)取回最愛備份 [Q]"); + if(!c) break; - getdata(b_lines - 1, 0, "確定嗎 [y/N] ", buf2, sizeof(buf2), DOECHO); - if(buf2[0] != 'y') + if(getans("確定嗎 [y/N] ") != 'y') break; - switch(buf[0]){ + switch(c){ case '1': favclean(fav); break; @@ -1340,6 +1343,8 @@ choose_board(int newflag) break; } close(fd); + sprintf(genbuf, "cp -f %s.bak %s", fname, fname); + system(genbuf); freefav(fav); load_brdbuf(); favchange = 1; -- cgit v1.2.3 From aabb4061b1d17570872473aefc14bbb66edbaab7 Mon Sep 17 00:00:00 2001 From: in2 Date: Tue, 10 Jun 2003 08:46:06 +0000 Subject: add filter strict git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@938 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/blog/blog.pl | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/pttbbs/blog/blog.pl b/pttbbs/blog/blog.pl index c14ca34a..0dc59914 100755 --- a/pttbbs/blog/blog.pl +++ b/pttbbs/blog/blog.pl @@ -1,5 +1,5 @@ #!/usr/bin/perl -# $Id: blog.pl,v 1.18 2003/06/03 07:06:59 in2 Exp $ +# $Id: blog.pl,v 1.19 2003/06/10 08:46:06 in2 Exp $ use CGI qw/:standard/; use lib qw/./; use LocalVars; @@ -251,11 +251,15 @@ sub applyfilter($$) my($c, $filter) = @_; foreach( split(',', $filter) ){ if( /^generic$/i ){ - #$c =~ s/\/>/gs; - #$c =~ s/\"/"/gs; $c =~ s/\n/
\n/gs; } + elsif( /^strict$/i ){ + $c =~ s/\/>/gs; + $c =~ s/\"/"/gs; + $c =~ s/\'/'/gs; + $c =~ s/ / /gs; + } elsif( /^ubb$/i ){ $c =~ s|\[url\](.*?)\[/url\]|$1|gsi; $c =~ s|\[url=(.*?)\](.*?)\[/url\]|$2|gsi; -- cgit v1.2.3 From 346497bfde9faeafd4af4a31ba1b427babf2ad53 Mon Sep 17 00:00:00 2001 From: in2 Date: Sat, 14 Jun 2003 03:55:10 +0000 Subject: support 'all' in loadTopBlogs git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@939 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/blog/blog.pl | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pttbbs/blog/blog.pl b/pttbbs/blog/blog.pl index 0dc59914..07b72011 100755 --- a/pttbbs/blog/blog.pl +++ b/pttbbs/blog/blog.pl @@ -1,5 +1,5 @@ #!/usr/bin/perl -# $Id: blog.pl,v 1.19 2003/06/10 08:46:06 in2 Exp $ +# $Id: blog.pl,v 1.20 2003/06/14 03:55:10 in2 Exp $ use CGI qw/:standard/; use lib qw/./; use LocalVars; @@ -118,7 +118,8 @@ sub main my($dbh) = @_; my($sth); $sth = $dbh->prepare("select k, v from counter order by v desc ". - "limit 0,". $attr{"$fn.loadTopBlogs"}); + ($attr{"$fn.loadTopBlogs"} eq 'all' ? '' : + 'limit 0,'. $attr{"$fn.loadTopBlogs"})); $sth->execute(); while( $_ = $sth->fetchrow_hashref() ){ push @{$th{topBlogs}}, {brdname => $_->{k}, -- cgit v1.2.3 From bb63e93ea0d898b396ba6545377813fca64061c4 Mon Sep 17 00:00:00 2001 From: in2 Date: Mon, 16 Jun 2003 02:38:18 +0000 Subject: remove git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@940 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/blog/builddb.pl | 1 + 1 file changed, 1 insertion(+) diff --git a/pttbbs/blog/builddb.pl b/pttbbs/blog/builddb.pl index b5262017..b519587b 100755 --- a/pttbbs/blog/builddb.pl +++ b/pttbbs/blog/builddb.pl @@ -79,6 +79,7 @@ sub buildconfigure($$) } $c = $rch->{"$_.content"}; + $c =~ s/$outdir/$fn"; if( $c =~ m|(.*?)\n\s*\s*\n(.*)|s ){ -- cgit v1.2.3 From ba7c6e238e724e6d5ee2215a7d4666b548acbabf Mon Sep 17 00:00:00 2001 From: in2 Date: Tue, 17 Jun 2003 06:38:21 +0000 Subject: comments for having login error log git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@941 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/mbbsd.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/pttbbs/mbbsd/mbbsd.c b/pttbbs/mbbsd/mbbsd.c index e5815c2d..511555c0 100644 --- a/pttbbs/mbbsd/mbbsd.c +++ b/pttbbs/mbbsd/mbbsd.c @@ -1,4 +1,4 @@ -/* $Id: mbbsd.c,v 1.82 2003/05/22 01:06:11 in2 Exp $ */ +/* $Id: mbbsd.c,v 1.83 2003/06/17 06:38:21 in2 Exp $ */ #include "bbs.h" #define SOCKET_QLEN 4 @@ -760,7 +760,7 @@ setup_utmp(int mode) static void user_login() { - char ans[4], i; + char i; char genbuf[200]; struct tm *ptime, *tmp; time_t now; @@ -841,9 +841,11 @@ user_login() } setuserfile(genbuf, str_badlogin); if (more(genbuf, NA) != -1) { - getdata(b_lines - 1, 0, "您要刪除以上錯誤嘗試的記錄嗎(Y/N)?[Y]", - ans, 3, LCECHO); - if (*ans != 'n') + move(b_lines - 3, 0); + prints("通常並沒有辦法知道該ip是誰所有, " + "以及其意圖(是不小心按錯或有意測您密碼)\n" + "若您有帳號被盜用疑慮, 請經常更改您的密碼或使用加密連線"); + if (getans("您要刪除以上錯誤嘗試的記錄嗎(Y/N)?[Y]") != 'n') unlink(genbuf); } check_register(); -- cgit v1.2.3 From 0d75a368cb85cbfe7a4d0cdd000cc38bab5816ac Mon Sep 17 00:00:00 2001 From: in2 Date: Wed, 18 Jun 2003 09:06:21 +0000 Subject: randomBlog git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@942 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/blog/blog.pl | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/pttbbs/blog/blog.pl b/pttbbs/blog/blog.pl index 07b72011..e3ba2744 100755 --- a/pttbbs/blog/blog.pl +++ b/pttbbs/blog/blog.pl @@ -1,5 +1,5 @@ #!/usr/bin/perl -# $Id: blog.pl,v 1.20 2003/06/14 03:55:10 in2 Exp $ +# $Id: blog.pl,v 1.21 2003/06/18 09:06:21 in2 Exp $ use CGI qw/:standard/; use lib qw/./; use LocalVars; @@ -113,19 +113,24 @@ sub main } # topBlogs - if( $attr{"$fn.loadTopBlogs"} ){ - dodbi(sub { - my($dbh) = @_; - my($sth); - $sth = $dbh->prepare("select k, v from counter order by v desc ". - ($attr{"$fn.loadTopBlogs"} eq 'all' ? '' : - 'limit 0,'. $attr{"$fn.loadTopBlogs"})); - $sth->execute(); - while( $_ = $sth->fetchrow_hashref() ){ - push @{$th{topBlogs}}, {brdname => $_->{k}, - counter => $_->{v}}; - } - }); + my($t); + foreach $t ( ['loadTopBlogs', 'v', 'topBlogs'], + ['loadRandomBlogs', 'RAND()', 'randomBlogs'] ){ + if( $attr{"$fn.$t->[0]"} ){ + dodbi(sub { + my($dbh) = @_; + my($sth); + $sth = $dbh->prepare("select k, v from counter ". + "order by $t->[1] desc ". + ($attr{"$fn.$t->[0]"} eq 'all' ? '' : + 'limit 0,'. $attr{"$fn.$t->[0]"})); + $sth->execute(); + while( $_ = $sth->fetchrow_hashref() ){ + push @{$th{$t->[2]}}, {brdname => $_->{k}, + counter => $_->{v}}; + } + }); + } } # Counter ---------------------------------------------------------------- -- cgit v1.2.3 From df56f27bce3e2d1308d05caf90b962b5bee736a3 Mon Sep 17 00:00:00 2001 From: in2 Date: Thu, 19 Jun 2003 12:40:24 +0000 Subject: $BLOG(dbname|dbhost|dbuser|dbpasswd) git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@943 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/blog/blog.pl | 9 ++++----- pttbbs/sample/LocalVars.pm | 5 +++++ 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/pttbbs/blog/blog.pl b/pttbbs/blog/blog.pl index e3ba2744..725d3d01 100755 --- a/pttbbs/blog/blog.pl +++ b/pttbbs/blog/blog.pl @@ -1,5 +1,5 @@ #!/usr/bin/perl -# $Id: blog.pl,v 1.21 2003/06/18 09:06:21 in2 Exp $ +# $Id: blog.pl,v 1.22 2003/06/19 12:40:24 in2 Exp $ use CGI qw/:standard/; use lib qw/./; use LocalVars; @@ -311,10 +311,9 @@ sub dodbi my($ret); use DBI; use DBD::mysql; - my $dbh = DBI->connect("DBI:mysql:database=blog;". - "host=localhost", - 'root', - '', + my $dbh = DBI->connect("DBI:mysql:database=$BLOGdbname;". + "host=$BLOGdbhost", + $BLOGdbuser, $BLOGdbpasswd, {'RaiseError' => 1}); eval { $ret = &{$func}($dbh); diff --git a/pttbbs/sample/LocalVars.pm b/pttbbs/sample/LocalVars.pm index 4e52d0f0..de215da7 100644 --- a/pttbbs/sample/LocalVars.pm +++ b/pttbbs/sample/LocalVars.pm @@ -7,6 +7,7 @@ require Exporter; $BBSHOME $JOBSPOOL $TMP $TAR $LYNX $GREP $BLOGDATA $BLOGCACHE + $BLOGdbname $BLOGdbhost $BLOGdbuser $BLOGdbpasswd /; # host @@ -31,3 +32,7 @@ $GREP = '/usr/bin/grep'; # 須為 apache owner 可寫入 $BLOGDATA = '/home/bbs/blog/data'; $BLOGCACHE = '/home/bbs/blog/cache'; +$BLOGdbname = 'myblog'; +$BLOGdbhost = 'localhost'; +$BLOGdbuser = 'root'; +$BLOGdbpasswd = ''; -- cgit v1.2.3 From e4e18eef22bfb337612821012cf88e1a1e48b6e9 Mon Sep 17 00:00:00 2001 From: in2 Date: Thu, 19 Jun 2003 12:42:58 +0000 Subject: perl module should return 1 git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@944 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/sample/LocalVars.pm | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pttbbs/sample/LocalVars.pm b/pttbbs/sample/LocalVars.pm index de215da7..93bb44e4 100644 --- a/pttbbs/sample/LocalVars.pm +++ b/pttbbs/sample/LocalVars.pm @@ -36,3 +36,5 @@ $BLOGdbname = 'myblog'; $BLOGdbhost = 'localhost'; $BLOGdbuser = 'root'; $BLOGdbpasswd = ''; + +1; -- cgit v1.2.3 From 31ce84e798a63c32362f253a44bfea766b47d13c Mon Sep 17 00:00:00 2001 From: in2 Date: Thu, 19 Jun 2003 13:06:58 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@945 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/blog/blog.pl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pttbbs/blog/blog.pl b/pttbbs/blog/blog.pl index 725d3d01..96c929af 100755 --- a/pttbbs/blog/blog.pl +++ b/pttbbs/blog/blog.pl @@ -1,5 +1,5 @@ #!/usr/bin/perl -# $Id: blog.pl,v 1.22 2003/06/19 12:40:24 in2 Exp $ +# $Id: blog.pl,v 1.23 2003/06/19 13:06:58 in2 Exp $ use CGI qw/:standard/; use lib qw/./; use LocalVars; @@ -34,7 +34,7 @@ sub main "$BLOGDATA/$brdname/config.db", O_RDONLY, 0666, $DB_HASH) || !(tie %attr, 'DB_File', "$BLOGDATA/$brdname/attr.db", O_RDONLY, 0666, $DB_HASH) ){ - return redirect("http://blog.ptt2.cc/blog.pl/$1/") + return redirect("/blog.pl/$1/") if( $ENV{PATH_INFO} =~ m|^/([\w\-]+?)$| ); print header(-status => 404); return; -- cgit v1.2.3 From 82f6e37dcba528bcdd5827003f08f2c35df556d1 Mon Sep 17 00:00:00 2001 From: in2 Date: Thu, 19 Jun 2003 14:33:09 +0000 Subject: fix bug git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@946 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/edit.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pttbbs/mbbsd/edit.c b/pttbbs/mbbsd/edit.c index 5621ef3f..f9578db0 100644 --- a/pttbbs/mbbsd/edit.c +++ b/pttbbs/mbbsd/edit.c @@ -1,4 +1,4 @@ -/* $Id: edit.c,v 1.31 2003/05/27 07:53:41 in2 Exp $ */ +/* $Id: edit.c,v 1.32 2003/06/19 14:33:09 in2 Exp $ */ #include "bbs.h" typedef struct textline_t { struct textline_t *prev; @@ -270,7 +270,7 @@ adjustline(textline_t *oldp, short len) { textline_t tmpl[sizeof(textline_t) + WRAPMARGIN]; textline_t *newp; - memcpy(tmpl, oldp, len + sizeof(textline_t)); + memcpy(tmpl, oldp, oldp->len + sizeof(textline_t)); free(oldp); newp = alloc_line(len); -- cgit v1.2.3 From d846ff33a2286cd1b9323e70ac8177e53ec3d98b Mon Sep 17 00:00:00 2001 From: bbs Date: Thu, 19 Jun 2003 15:49:07 +0000 Subject: default: don't add new brd to fav git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@947 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/register.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pttbbs/mbbsd/register.c b/pttbbs/mbbsd/register.c index 29d9ad7d..63aa579f 100644 --- a/pttbbs/mbbsd/register.c +++ b/pttbbs/mbbsd/register.c @@ -1,4 +1,4 @@ -/* $Id: register.c,v 1.11 2003/01/16 11:58:04 kcwu Exp $ */ +/* $Id: register.c,v 1.12 2003/06/19 15:49:07 bbs Exp $ */ #define _XOPEN_SOURCE #include "bbs.h" @@ -255,6 +255,7 @@ new_register() } newuser.userlevel = PERM_DEFAULT; newuser.uflag = COLOR_FLAG | BRDSORT_FLAG | MOVIE_FLAG; + newuser.uflag2 = FAVNEW_FLAG; newuser.firstlogin = newuser.lastlogin = now; newuser.money = 0; newuser.pager = 1; -- cgit v1.2.3 From 52e7fb48e79ab29498026e3b4b2f8c676c3d3d4f Mon Sep 17 00:00:00 2001 From: in2 Date: Fri, 20 Jun 2003 04:35:51 +0000 Subject: use LocalVars git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@948 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/blog/index.pl | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/pttbbs/blog/index.pl b/pttbbs/blog/index.pl index cad0fba3..091bc1f3 100755 --- a/pttbbs/blog/index.pl +++ b/pttbbs/blog/index.pl @@ -1,8 +1,17 @@ #!/usr/bin/perl -# $Id: index.pl,v 1.1 2003/06/02 15:23:32 in2 Exp $ +# $Id: index.pl,v 1.2 2003/06/20 04:35:51 in2 Exp $ use CGI qw/:standard/; +use lib qw/./; +use LocalVars; -print redirect("http://blog.ptt2.cc/blog.pl/$1/") - if( $ENV{REDIRECT_REQUEST_URI} =~ m|/\?(.*)| ); +sub main +{ + print redirect("/blog.pl/$1/") + if( $ENV{REDIRECT_REQUEST_URI} =~ m|/\?(.*)| ); + + return redirect("/blog.pl/$BLOGdefault/"); +} + +main(); +1; -return redirect("http://blog.ptt2.cc/blog.pl/Blog/"); -- cgit v1.2.3 From 65ca81366dfe8e7f7ff9ad602e8deb2b03c1f75c Mon Sep 17 00:00:00 2001 From: in2 Date: Fri, 20 Jun 2003 04:36:30 +0000 Subject: add $BLOGdefault git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@949 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/sample/LocalVars.pm | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pttbbs/sample/LocalVars.pm b/pttbbs/sample/LocalVars.pm index 93bb44e4..70b4925f 100644 --- a/pttbbs/sample/LocalVars.pm +++ b/pttbbs/sample/LocalVars.pm @@ -7,7 +7,7 @@ require Exporter; $BBSHOME $JOBSPOOL $TMP $TAR $LYNX $GREP $BLOGDATA $BLOGCACHE - $BLOGdbname $BLOGdbhost $BLOGdbuser $BLOGdbpasswd + $BLOGdbname $BLOGdbhost $BLOGdbuser $BLOGdbpasswd $BLOGdefault /; # host @@ -36,5 +36,6 @@ $BLOGdbname = 'myblog'; $BLOGdbhost = 'localhost'; $BLOGdbuser = 'root'; $BLOGdbpasswd = ''; +$BLOGdefault = 'Blog'; 1; -- cgit v1.2.3 From db28202fdc5f1975e62e937437889576a69d45ce Mon Sep 17 00:00:00 2001 From: in2 Date: Fri, 20 Jun 2003 22:06:30 +0000 Subject: add $Id$ git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@950 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/parsevar.pl | 1 + 1 file changed, 1 insertion(+) diff --git a/pttbbs/util/parsevar.pl b/pttbbs/util/parsevar.pl index 60063608..d532c786 100644 --- a/pttbbs/util/parsevar.pl +++ b/pttbbs/util/parsevar.pl @@ -1,4 +1,5 @@ #!/usr/bin/perl +# $Id: parsevar.pl,v 1.2 2003/06/20 22:06:30 in2 Exp $ print << '.'; /* * This header file is auto-generated from pttbbs/mbbsd/var.c . -- cgit v1.2.3 From eb0a60c7959bafdff115a1b911dafcb52db6d9e8 Mon Sep 17 00:00:00 2001 From: in2 Date: Sat, 21 Jun 2003 05:27:03 +0000 Subject: typeo git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@951 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/shmctl.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pttbbs/util/shmctl.c b/pttbbs/util/shmctl.c index 86e65cb3..b7ca5dab 100644 --- a/pttbbs/util/shmctl.c +++ b/pttbbs/util/shmctl.c @@ -1,4 +1,4 @@ -/* $Id: shmctl.c,v 1.42 2003/05/17 04:41:02 victor Exp $ */ +/* $Id: shmctl.c,v 1.43 2003/06/21 05:27:03 in2 Exp $ */ #include "bbs.h" #include @@ -303,7 +303,7 @@ char *CTIMEx(char *buf, time_t t) return buf; } -int utmpstate(int argc, char **argv) +int utmpstatus(int argc, char **argv) { time_t now; char upbuf[64], nowbuf[64]; @@ -325,7 +325,7 @@ int utmpstate(int argc, char **argv) int utmpreset(int argc, char **argv) { SHM->UTMPbusystate=0; - utmpstate(0, NULL); + utmpstatus(0, NULL); return 0; } @@ -425,7 +425,7 @@ struct { } cmd[] = { {utmpfix, "utmpfix", "clear dead userlist entry"}, {utmpsortd, "utmpsortd", "utmp sorting daemon"}, - {utmpstate, "utmpstate", "list utmpstate"}, + {utmpstatus, "utmpstatus", "list utmpstatus"}, {utmpreset, "utmpreset", "SHM->busystate=0"}, {utmpwatch, "utmpwatch", "to see if busystate is always 1 then fix it"}, {utmpnum, "utmpnum", "print SHM->number for snmpd"}, -- cgit v1.2.3 From 8f6d69717ad3071ef963d4ab375311ca3c0366bc Mon Sep 17 00:00:00 2001 From: in2 Date: Sat, 21 Jun 2003 05:50:47 +0000 Subject: register git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@952 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/user.c | 88 +++++++++++++++++++++++++---------------------------- 1 file changed, 41 insertions(+), 47 deletions(-) diff --git a/pttbbs/mbbsd/user.c b/pttbbs/mbbsd/user.c index 33288f0a..9031107e 100644 --- a/pttbbs/mbbsd/user.c +++ b/pttbbs/mbbsd/user.c @@ -1,4 +1,4 @@ -/* $Id: user.c,v 1.61 2003/06/02 01:43:16 in2 Exp $ */ +/* $Id: user.c,v 1.62 2003/06/21 05:50:47 in2 Exp $ */ #include "bbs.h" static char *sex[8] = { @@ -900,7 +900,7 @@ getregcode(char *buf) } static int -isvaildemail(char *email) +isvalidemail(char *email) { FILE *fp; char buf[128], *c; @@ -971,7 +971,7 @@ toregister(char *email, char *genbuf, char *phone, char *career, char fore, break; #ifdef HAVEMOBILE else if (strcmp(email, "m") == 0 || strcmp(email, "M") == 0) { - if (isvaildmobile(mobile)) { + if (isvalidmobile(mobile)) { char yn[3]; getdata(16, 0, "請再次確認您輸入的手機號碼正確嘛? [y/N]", yn, sizeof(yn), LCECHO); @@ -985,7 +985,7 @@ toregister(char *email, char *genbuf, char *phone, char *career, char fore, } #endif - else if (isvaildemail(email)) { + else if (isvalidemail(email)) { char yn[3]; getdata(16, 0, "請再次確認您輸入的 E-Mail 位置正確嘛? [y/N]", yn, sizeof(yn), LCECHO); @@ -1045,24 +1045,32 @@ toregister(char *email, char *genbuf, char *phone, char *career, char fore, } } -static char *isvaildname(char *rname) +static int HaveRejectStr(char *s, char **rej) { + int i; + char *rejectstr[] = + {"幹", "阿", "ㄚ", "不", "你媽", "某", "笨", "呆", "..", "xx", + "你管", "管我", NULL}; + + if( rej != NULL ) + for( i = 0 ; rej[i] != NULL ; ++i ) + if( strstr(s, rej[i]) ) + return 1; + + for( i = 0 ; rejectstr[i] != NULL ; ++i ) + if( strstr(s, rejectstr[i]) ) + return 1; + return 0; +} + +static char *isvalidname(char *rname) +{ + char *rejectstr[] = + {"肥", "胖", "豬頭", "小白", "小明", "路人", "老王", "老李", "寶貝", + "先生", "師哥", "老頭", "小姊", "小姐", "美女", "小妹", NULL}; if( removespace(rname) && rname[0] < 0 && strlen(rname) >= 4 && - !strstr(rname, "幹") && !strstr(rname, "肥") && - !strstr(rname, "胖") && !strstr(rname, "笨") && - !strstr(rname, "阿") && !strstr(rname, "某") && - !strstr(rname, "ㄚ") && !strstr(rname, "..") && - !strstr(rname, "呆") && - - !strstr(rname, "美女") && !strstr(rname, "帥哥") && - !strstr(rname, "先生") && !strstr(rname, "小姐") && - !strstr(rname, "老頭") && !strstr(rname, "豬頭") && - !strstr(rname, "寶貝") && !strstr(rname, "小白") && - !strstr(rname, "小明") && !strstr(rname, "小妹") && - !strstr(rname, "路人") && !strstr(rname, "不說") && - !strstr(rname, "不知") && !strstr(rname, "你媽") && - + !HaveRejectStr(rname, rejectstr) && strncmp(rname, "小", 2) != 0 && //起頭是「小」 strncmp(rname, "我是", 4) != 0 && //起頭是「我是」 !(strlen(rname) == 4 && strncmp(&rname[2], "兒", 2) == 0) && @@ -1071,44 +1079,30 @@ static char *isvaildname(char *rname) return "您的輸入不正確"; } -static char *isvaildcareer(char *career) +static char *isvalidcareer(char *career) { - if (!(removespace(career) && career[0] < 0 - && strlen(career) >= 6) || - strcmp(career, "家裡") == 0 || - strstr(career, "幹") != NULL || - strstr(career, "不知") != NULL || - strstr(career, "不說") != NULL || - strstr(career, "你管") != NULL || - strstr(career, "管我") != NULL || - strstr(career, "某") != NULL ) { + char *rejectstr[] = {NULL}; + if (!(removespace(career) && career[0] < 0 && strlen(career) >= 6) || + strcmp(career, "家裡") == 0 || HaveRejectStr(career, rejectstr) ) return "您的輸入不正確"; - } if (strcmp(&career[strlen(career) - 2], "大") == 0 || strcmp(&career[strlen(career) - 4], "大學") == 0 ) return "麻煩請加學校系所"; return NULL; } -static char *isvaildaddr(char *addr) +static char *isvalidaddr(char *addr) { + char *rejectstr[] = + {"地球", "銀河", "火星", NULL}; + if (!removespace(addr) || addr[0] > 0 || strlen(addr) < 15) return "這個地址並不合法"; if (strstr(addr, "信箱") != NULL || strstr(addr, "郵政") != NULL) return "抱歉我們不接受郵政信箱"; if ((strstr(addr, "市") == NULL && strstr(addr, "巿") == NULL && strstr(addr, "縣") == NULL && strstr(addr, "室") == NULL) || - strstr(addr, "地球") != NULL || - strstr(addr, "銀河") != NULL || - strstr(addr, "火星") != NULL || - strstr(addr, "不知") != NULL || - strstr(addr, "不說") != NULL || - strstr(addr, "你管") != NULL || - strstr(addr, "管我") != NULL || - strstr(addr, "某") != NULL || - strstr(addr, "..") != NULL || - strstr(addr, "xx") != NULL || - strstr(addr, "幹") != NULL || + HaveRejectStr(addr, rejectstr) || strcmp(&addr[strlen(addr) - 2], "段") == 0 || strcmp(&addr[strlen(addr) - 2], "路") == 0 || strcmp(&addr[strlen(addr) - 2], "巷") == 0 || @@ -1118,7 +1112,7 @@ static char *isvaildaddr(char *addr) return NULL; } -static char *isvaildphone(char *phone) +static char *isvalidphone(char *phone) { if (strstr(phone, "(") || strstr(phone, ")") || strstr(phone, "-")){ return "電話請不加 ( ) - 符號"; @@ -1282,7 +1276,7 @@ u_register(void) #endif while (1) { getfield(8, "請用中文", "真實姓名", rname, 20); - if( (errcode = isvaildname(rname)) == NULL ) + if( (errcode = isvalidname(rname)) == NULL ) break; else vmsg(errcode); @@ -1294,7 +1288,7 @@ u_register(void) while (1) { getfield(9, "學校(含\033[1;33m系所年級\033[m)或單位職稱", "服務單位", career, 40); - if( (errcode = isvaildcareer(career)) == NULL ) + if( (errcode = isvalidcareer(career)) == NULL ) break; else vmsg(errcode); @@ -1303,14 +1297,14 @@ u_register(void) getfield(11, "含\033[1;33m縣市\033[m及門寢號碼" "(台北請加\033[1;33m行政區\033[m)", "目前住址", addr, 50); - if( (errcode = isvaildaddr(addr)) == NULL ) + if( (errcode = isvalidaddr(addr)) == NULL ) break; else vmsg(errcode); } while (1) { getfield(13, "不加-(), 包括長途區號", "連絡電話", phone, 11); - if( (errcode = isvaildphone(phone)) == NULL ) + if( (errcode = isvalidphone(phone)) == NULL ) break; else vmsg(errcode); -- cgit v1.2.3 From a797f9fcd9393396bf8dd56e6d6cee0c6ced8dba Mon Sep 17 00:00:00 2001 From: victor Date: Sat, 21 Jun 2003 17:10:31 +0000 Subject: =?UTF-8?q?=EF=BF=BDp=EF=BF=BDO=EF=BF=BDD=20cp=20=EF=BF=BD?= =?UTF-8?q?=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD?= =?UTF-8?q?=EF=BF=BD=EF=BF=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@953 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/announce.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pttbbs/mbbsd/announce.c b/pttbbs/mbbsd/announce.c index 3d4361cf..3b101816 100644 --- a/pttbbs/mbbsd/announce.c +++ b/pttbbs/mbbsd/announce.c @@ -1,4 +1,4 @@ -/* $Id: announce.c,v 1.26 2003/06/04 02:09:53 victor Exp $ */ +/* $Id: announce.c,v 1.27 2003/06/21 17:10:31 victor Exp $ */ #include "bbs.h" static void @@ -1442,7 +1442,7 @@ a_menu(char *maintitle, char *path, int lastlevel) 還是檔案竟然是用 fstat(2) 而不是直接存在 .DIR 內 |||b 須等該資料寫入 .DIR 內再 implement才有效率. */ - if( !HAS_PERM(PERM_SYSOP) && !HAS_PERM(PERM_SYSSUBOP) && !is_BM(bcache[currbid - 1].BM) && + if( !lastlevel && !HAS_PERM(PERM_SYSOP) && !HAS_PERM(PERM_SYSSUBOP) && !is_BM(bcache[currbid - 1].BM) && dashd(fname) ) vmsg("只有板主才可以拷貝目錄唷!"); else -- cgit v1.2.3 From 67b062c32208cc4d12d7995e439e27b2013ad685 Mon Sep 17 00:00:00 2001 From: in2 Date: Sun, 22 Jun 2003 04:32:38 +0000 Subject: move COMPILE_TIME from .mk to vers.c git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@954 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/.cvsignore | 1 + pttbbs/mbbsd/Makefile | 5 +++-- pttbbs/mbbsd/cal.c | 5 +++-- pttbbs/pttbbs.mk | 5 +---- pttbbs/util/newvers.sh | 8 ++++++++ 5 files changed, 16 insertions(+), 8 deletions(-) create mode 100644 pttbbs/util/newvers.sh diff --git a/pttbbs/mbbsd/.cvsignore b/pttbbs/mbbsd/.cvsignore index 35f9f2d1..b5881695 100644 --- a/pttbbs/mbbsd/.cvsignore +++ b/pttbbs/mbbsd/.cvsignore @@ -1,2 +1,3 @@ *.o mbbsd +vers.c diff --git a/pttbbs/mbbsd/Makefile b/pttbbs/mbbsd/Makefile index c4c5c320..33db03b6 100644 --- a/pttbbs/mbbsd/Makefile +++ b/pttbbs/mbbsd/Makefile @@ -1,4 +1,4 @@ -# $Id: Makefile,v 1.25 2003/05/15 08:20:05 in2 Exp $ +# $Id: Makefile,v 1.26 2003/06/22 04:32:38 in2 Exp $ .include "../pttbbs.mk" @@ -19,7 +19,8 @@ OBJS= admin.o announce.o args.o bbs.o board.o cache.o cal.o card.o\ all: $(PROG) $(PROG): $(OBJS) - $(CC) $(LDFLAGS) -o $(PROG) $(OBJS) $(LIBS) $(EXT_LIBS) + sh ../util/newvers.sh + $(CC) $(LDFLAGS) -o $(PROG) $(OBJS) $(LIBS) $(EXT_LIBS) vers.c ../include/var.h: var.c perl ../util/parsevar.pl < var.c > ../include/var.h diff --git a/pttbbs/mbbsd/cal.c b/pttbbs/mbbsd/cal.c index bae8ca71..1567f0c2 100644 --- a/pttbbs/mbbsd/cal.c +++ b/pttbbs/mbbsd/cal.c @@ -1,4 +1,4 @@ -/* $Id: cal.c,v 1.26 2003/04/28 01:19:40 in2 Exp $ */ +/* $Id: cal.c,v 1.27 2003/06/22 04:32:38 in2 Exp $ */ #include "bbs.h" /* 防堵 Multi play */ @@ -415,6 +415,7 @@ p_sysinfo(void) { char buf[128], *cpuloadstr; int load; + extern char *compile_time; load = cpuload(buf); cpuloadstr = (load < 5 ? "良好" : (load < 20 ? "尚可" : "過重")); @@ -433,7 +434,7 @@ p_sysinfo(void) #else MAX_ACTIVE, #endif - COMPILE_TIME, ctime(&start_time)); + compile_time, ctime(&start_time)); if (HAS_PERM(PERM_SYSOP)) { struct rusage ru; getrusage(RUSAGE_SELF, &ru); diff --git a/pttbbs/pttbbs.mk b/pttbbs/pttbbs.mk index a246651c..8bd1e04d 100644 --- a/pttbbs/pttbbs.mk +++ b/pttbbs/pttbbs.mk @@ -1,4 +1,4 @@ -# $Id: pttbbs.mk,v 1.1 2003/05/15 08:20:05 in2 Exp $ +# $Id: pttbbs.mk,v 1.2 2003/06/22 04:32:38 in2 Exp $ # 訂義基本初值 BBSHOME?= $(HOME) BBSHOME?= /home/bbs @@ -8,9 +8,6 @@ PTT_CFLAGS= -Wall -pipe -DBBSHOME='"$(BBSHOME)"' -I../include PTT_LDFLAGS= -pipe -Wall PTT_LIBS= -lcrypt -# 在 CFLAGS內加入定義 COMPILE_TIME -PTT_CFLAGS+= "-DCOMPILE_TIME=\"`date`\"" - # 稍後再 enable assert() PTT_CFLAGS+= -DNDEBUG diff --git a/pttbbs/util/newvers.sh b/pttbbs/util/newvers.sh new file mode 100644 index 00000000..eaaff3c3 --- /dev/null +++ b/pttbbs/util/newvers.sh @@ -0,0 +1,8 @@ +#!/bin/sh +# $Id: newvers.sh,v 1.1 2003/06/22 04:32:38 in2 Exp $ + +t=`date` + +cat << EOF > vers.c +char compile_time[] = "${t}"; +EOF -- cgit v1.2.3 From 3854a9b848f41c213dbeb169faf82bae2f4bceaf Mon Sep 17 00:00:00 2001 From: in2 Date: Sun, 22 Jun 2003 13:30:49 +0000 Subject: for iconv git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@955 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/docs/FAQ | 2 ++ pttbbs/docs/INSTALL | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/pttbbs/docs/FAQ b/pttbbs/docs/FAQ index c4267063..41b5aae1 100644 --- a/pttbbs/docs/FAQ +++ b/pttbbs/docs/FAQ @@ -7,6 +7,7 @@ PttBBS FAQ: 5. 五子棋盤沒有出現 6. sendmail.cf要改的地方(參考用) (by DavidYu) 7. /usr/libexec/elf/ld: cannot find -liconv + 或 iconv.h: No such file or directory ------------------------------------------------------------------------------ 1.PttBBS的討論區 位於批踢踢實業坊 (telnet://ptt.csie.ntu.edu.tw) 的 PttCurrent 看板. @@ -105,6 +106,7 @@ Mbbsmail, P=/home/bbs/bin/bbsmail, F=lsSDFMhPu, U=bbs, S=10,R=20/40, ------------------------------------------------------------------------------ 7./usr/libexec/elf/ld: cannot find -liconv + 或 iconv.h: No such file or directory 因為新的 innbbsd中加入了 RFC 2045 support, 須要 libiconv . 您須先要有安裝 libiconv (/usr/ports/converters/libiconv/ in FreeBSD) 再重新 make 即可 diff --git a/pttbbs/docs/INSTALL b/pttbbs/docs/INSTALL index 485935d7..f03e94b8 100644 --- a/pttbbs/docs/INSTALL +++ b/pttbbs/docs/INSTALL @@ -38,7 +38,8 @@ 10.修改 pttbbs.conf * 如果您是用 Linux系統, 請先安裝 pmake, 然後將 make alias 成 pmake * 11.執行 make OSTYPE=FreeBSD BBSHOME=/home/bbs all install - (Linux使用者請把 "FreeBSD" 改成 "linux") + ( Linux使用者請把 "FreeBSD" 改成 "linux") + (如果出現 iconv.h找不到的話, 請見 FAQ 7 ) 12.如果是新架起來的站, 請執行 cd sample; make install 13.執行 cd /home/bbs; bin/initbbs -- cgit v1.2.3 From 7f29e8006ddfed2afa38c4b20adbc345bfbb4e52 Mon Sep 17 00:00:00 2001 From: in2 Date: Sun, 22 Jun 2003 14:39:34 +0000 Subject: remove post limit in DEBUG mode git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@956 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/bbs.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pttbbs/mbbsd/bbs.c b/pttbbs/mbbsd/bbs.c index 5accfca2..7e3e11f8 100644 --- a/pttbbs/mbbsd/bbs.c +++ b/pttbbs/mbbsd/bbs.c @@ -1,4 +1,4 @@ -/* $Id: bbs.c,v 1.97 2003/06/02 14:49:04 victor Exp $ */ +/* $Id: bbs.c,v 1.98 2003/06/22 14:39:34 in2 Exp $ */ #include "bbs.h" static int recommend(int ent, fileheader_t * fhdr, char *direct); @@ -465,6 +465,7 @@ do_general() return FULLUPDATE; } #ifdef NO_WATER_POST +#ifndef DEBUG /* why we need this in DEBUG mode? */ /* 三分鐘內最多發表五篇文章 */ if (currutmp->lastact - last_post_time < 60 * 3) { if (water_counts >= 5) { @@ -477,6 +478,7 @@ do_general() last_post_time = currutmp->lastact; water_counts = 0; } +#endif #endif setbfile(genbuf, currboard, FN_POST_NOTE); -- cgit v1.2.3 From 0300bfc24ff0236115447c00b070878b59b9dff4 Mon Sep 17 00:00:00 2001 From: in2 Date: Sun, 22 Jun 2003 14:39:55 +0000 Subject: fix "recbase bug" git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@957 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/read.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/pttbbs/mbbsd/read.c b/pttbbs/mbbsd/read.c index fdf8183e..1c7aeb16 100644 --- a/pttbbs/mbbsd/read.c +++ b/pttbbs/mbbsd/read.c @@ -1,4 +1,4 @@ -/* $Id: read.c,v 1.21 2003/04/14 15:23:07 victor Exp $ */ +/* $Id: read.c,v 1.22 2003/06/22 14:39:55 in2 Exp $ */ #include "bbs.h" static fileheader_t *headers = NULL; @@ -839,15 +839,16 @@ i_read(int cmdmode, char *direct, void (*dotitle) (), void (*doentry) (), onekey else if (recbase != locmem->top_ln) { recbase = locmem->top_ln; if (recbase > last_line) { - recbase = (last_line - p_lines) >> 1; + recbase = last_line - p_lines + 1; if (recbase < 1) recbase = 1; locmem->top_ln = recbase; } - if (bidcache > 0 && !(currmode & (MODE_SELECT | MODE_DIGEST)) - && (last_line - recbase) < DIRCACHESIZE) - entries = get_fileheader_cache(currbid, currdirect, headers, - recbase, p_lines); + if( bidcache > 0 && + !(currmode & (MODE_SELECT | MODE_DIGEST) + && (last_line - recbase) < DIRCACHESIZE) ) + entries = get_fileheader_cache(currbid, currdirect, + headers, recbase, p_lines); else entries = get_records(currdirect, headers, FHSZ, recbase, p_lines); -- cgit v1.2.3 From 3ab478f6cc9a4ec30f5c63ad2e42719bb4a0a7c3 Mon Sep 17 00:00:00 2001 From: in2 Date: Sun, 22 Jun 2003 14:45:17 +0000 Subject: change [] to * git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@958 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/newvers.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pttbbs/util/newvers.sh b/pttbbs/util/newvers.sh index eaaff3c3..992fd7fe 100644 --- a/pttbbs/util/newvers.sh +++ b/pttbbs/util/newvers.sh @@ -1,8 +1,8 @@ #!/bin/sh -# $Id: newvers.sh,v 1.1 2003/06/22 04:32:38 in2 Exp $ +# $Id: newvers.sh,v 1.2 2003/06/22 14:45:17 in2 Exp $ t=`date` cat << EOF > vers.c -char compile_time[] = "${t}"; +char *compile_time = "${t}"; EOF -- cgit v1.2.3 From 61ce3e8ac1d4bc621391f7319415dd0a620c8f22 Mon Sep 17 00:00:00 2001 From: in2 Date: Sun, 22 Jun 2003 15:06:00 +0000 Subject: fix last committed bug git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@959 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/read.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pttbbs/mbbsd/read.c b/pttbbs/mbbsd/read.c index 1c7aeb16..e6620cb4 100644 --- a/pttbbs/mbbsd/read.c +++ b/pttbbs/mbbsd/read.c @@ -1,4 +1,4 @@ -/* $Id: read.c,v 1.22 2003/06/22 14:39:55 in2 Exp $ */ +/* $Id: read.c,v 1.23 2003/06/22 15:06:00 in2 Exp $ */ #include "bbs.h" static fileheader_t *headers = NULL; @@ -845,8 +845,8 @@ i_read(int cmdmode, char *direct, void (*dotitle) (), void (*doentry) (), onekey locmem->top_ln = recbase; } if( bidcache > 0 && - !(currmode & (MODE_SELECT | MODE_DIGEST) - && (last_line - recbase) < DIRCACHESIZE) ) + !(currmode & (MODE_SELECT | MODE_DIGEST)) && + (last_line - recbase) < DIRCACHESIZE ) entries = get_fileheader_cache(currbid, currdirect, headers, recbase, p_lines); else -- cgit v1.2.3 From a5d2454cc5f2c3059e8e445f25d1728f60c2cb6d Mon Sep 17 00:00:00 2001 From: in2 Date: Sun, 22 Jun 2003 15:12:59 +0000 Subject: COLORDATE git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@960 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/bbs.c | 32 +++++++++++++++++--------------- pttbbs/sample/pttbbs.conf | 3 +++ 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/pttbbs/mbbsd/bbs.c b/pttbbs/mbbsd/bbs.c index 7e3e11f8..1169f764 100644 --- a/pttbbs/mbbsd/bbs.c +++ b/pttbbs/mbbsd/bbs.c @@ -1,4 +1,4 @@ -/* $Id: bbs.c,v 1.98 2003/06/22 14:39:34 in2 Exp $ */ +/* $Id: bbs.c,v 1.99 2003/06/22 15:12:59 in2 Exp $ */ #include "bbs.h" static int recommend(int ent, fileheader_t * fhdr, char *direct); @@ -181,22 +181,24 @@ readdoent(int num, fileheader_t * ent) isonline = 1; #endif + prints( +#ifdef COLORDATE + "%6d %c\033[1;32m%c\033[%dm%-6s\033[m\033[%dm%-13.12s", +#else + "%6d %c\033[1;32m%c\033[m%-6s\033[%dm%-13.12s", +#endif + num, type, ent->recommend ? ent->recommend + '0' : ' ', +#ifdef COLORDATE + (ent->date[3] + ent->date[4]) % 7 + 31, +#endif + ent->date, isonline, ent->owner); + if (strncmp(currtitle, title, TTLEN)) - prints("%6d %c\033[1;32m%c\033[m%-6s\033[%dm%-13.12s\033[m%s " - "\033[1m%.*s\033[m%s\n", num, type, - ent->recommend ? ent->recommend + '0' : ' ', - ent->date, - isonline, - ent->owner, mark, - special ? 6 : 0, title, special ? title + 6 : title); + prints("\033[m%s \033[1m%.*s\033[m%s\n", + mark, special ? 6 : 0, title, special ? title + 6 : title); else - prints("%6d %c\033[1;32m%c\033[m%-6s\033[%dm%-13.12s\033[1;3%cm%s " - "%s\033[m\n", num, type, - ent->recommend ? ent->recommend + '0' : ' ', - ent->date, - isonline, - ent->owner, color, mark, - title); + prints("\033[1;3%cm%s %s\033[m\n", + color, mark, title); } int diff --git a/pttbbs/sample/pttbbs.conf b/pttbbs/sample/pttbbs.conf index b76d0ef4..982f0007 100644 --- a/pttbbs/sample/pttbbs.conf +++ b/pttbbs/sample/pttbbs.conf @@ -92,6 +92,9 @@ 請參閱 pttbbs/blog/ */ //#define BLOG +/* 若定義, 則在文章列表的時候不同日期會標上不同顏色 */ +//#define COLORDATE + /* 前進站畫面 */ #define INSCREEN \ "前進站畫面 (請至 pttbbs.conf 修改您的前進站畫面)" -- cgit v1.2.3 From 12d5dfe24b888d5e0dd40eda1cc3602a07790fe6 Mon Sep 17 00:00:00 2001 From: kcwu Date: Sun, 22 Jun 2003 18:19:59 +0000 Subject: fix comment typo git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@961 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/pttbbs.mk | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pttbbs/pttbbs.mk b/pttbbs/pttbbs.mk index 8bd1e04d..e1a9e505 100644 --- a/pttbbs/pttbbs.mk +++ b/pttbbs/pttbbs.mk @@ -1,5 +1,5 @@ -# $Id: pttbbs.mk,v 1.2 2003/06/22 04:32:38 in2 Exp $ -# 訂義基本初值 +# $Id: pttbbs.mk,v 1.3 2003/06/22 18:19:59 kcwu Exp $ +# 定義基本初值 BBSHOME?= $(HOME) BBSHOME?= /home/bbs OSTYPE?= FreeBSD -- cgit v1.2.3 From cbdcdd209e391a99b791a36717c1e288b13e0ca7 Mon Sep 17 00:00:00 2001 From: kcwu Date: Sun, 22 Jun 2003 18:20:43 +0000 Subject: fix corrupted big5 text git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@962 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/sample/crontab.old | 2 +- pttbbs/sample/etc/Welcome_birth | 4 ++-- pttbbs/sample/etc/register | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pttbbs/sample/crontab.old b/pttbbs/sample/crontab.old index 5acc8403..edec7b89 100644 --- a/pttbbs/sample/crontab.old +++ b/pttbbs/sample/crontab.old @@ -34,7 +34,7 @@ 30 4 * * 2 /usr/bin/find /home/bbs/boards/ -mtime +7 -name SR\* -exec rm -f {} ';' 30 4 * * 2 /bin/rm -f ~/tmp/* -# 每天執行一次生日程 +# 每天執行一次生日程式 1 2 * * * bin/birth > /dev/null # 每天精華區index一次 index前砍掉deleted的精華區 diff --git a/pttbbs/sample/etc/Welcome_birth b/pttbbs/sample/etc/Welcome_birth index c0496fed..5ea57404 100644 --- a/pttbbs/sample/etc/Welcome_birth +++ b/pttbbs/sample/etc/Welcome_birth @@ -1,4 +1,4 @@ - 嗨*s 忙嗎? 不要忘記自己的生日喔!! 記得發表感言.... + 嗨*s 忙嗎? 不要忘記自己的生日喔!! 記得發表感言...   ╭╮╭╮╭──╮╭──╮╭──╮╭╮╭╮  │╰╯││ ☆ ││ ☆ ││ ☆ ││╰╯│ @@ -20,4 +20,4 @@ 樂音環身樂自添. ┌┴──────────┴┐ └────────────┘ ★★祝你生日快樂★祝你生日快樂★祝你生日快樂★祝你生日快樂★祝你生日快樂★ - ▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁ + ▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁ diff --git a/pttbbs/sample/etc/register b/pttbbs/sample/etc/register index be131b06..5772eb2c 100644 --- a/pttbbs/sample/etc/register +++ b/pttbbs/sample/etc/register @@ -14,4 +14,4 @@ ※ 代號 [ID] 至少要兩個字,不宜採用數字。 ※ 密碼 至少要四個字,不可與 [ID] 雷同,不宜全部小寫。 ※ 請確實按照規定詳細填寫,否則不予通過! - ※ 以上資料缺一不可A敬請合作! + ※ 以上資料缺一不可,敬請合作! -- cgit v1.2.3 From b6701a3629efe257710afa2ffe5234b6dba00d77 Mon Sep 17 00:00:00 2001 From: kcwu Date: Sun, 22 Jun 2003 20:23:35 +0000 Subject: code audit git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@963 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/edit.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pttbbs/mbbsd/edit.c b/pttbbs/mbbsd/edit.c index f9578db0..1197a34d 100644 --- a/pttbbs/mbbsd/edit.c +++ b/pttbbs/mbbsd/edit.c @@ -1,4 +1,4 @@ -/* $Id: edit.c,v 1.32 2003/06/19 14:33:09 in2 Exp $ */ +/* $Id: edit.c,v 1.33 2003/06/22 20:23:35 kcwu Exp $ */ #include "bbs.h" typedef struct textline_t { struct textline_t *prev; @@ -1268,9 +1268,10 @@ match_paren() type = (ptype - parens) / 2; parenum += ((ptype - parens) % 2) ? -1 : 1; + /* FIXME 太多 strlen() */ + /* FIXME CRASH */ if (parenum > 0) { for (lino = currln, p = currline; p; p = p->next, lino++) { - lino = lino; for (i = (lino == currln) ? currpnt + 1 : 0; (size_t)i < strlen(p->data); i++) if (p->data[i] == '/' && p->data[++i] == '*') { -- cgit v1.2.3 From c6dfb4aad80c346e834fd785fa510baed49ac592 Mon Sep 17 00:00:00 2001 From: in2 Date: Tue, 24 Jun 2003 20:58:55 +0000 Subject: add comments git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@964 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/edit.c | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/pttbbs/mbbsd/edit.c b/pttbbs/mbbsd/edit.c index 1197a34d..c036362d 100644 --- a/pttbbs/mbbsd/edit.c +++ b/pttbbs/mbbsd/edit.c @@ -1,4 +1,22 @@ -/* $Id: edit.c,v 1.33 2003/06/22 20:23:35 kcwu Exp $ */ +/* $Id: edit.c,v 1.34 2003/06/24 20:58:55 in2 Exp $ */ +/* edit.c, 用來提供 bbs上的文字編輯器, 即 ve. + * 現在這一個是惡搞過的版本, 比較不穩定, 用比較多的 cpu, 但是可以省下許多 + * 的記憶體 (以 Ptt為例, 在九千人上站的時候, 約可省下 50MB 的記憶體) + * 如果您認為「拿 cpu換記憶體」並不合乎您的須求, 您可以考慮改使用修正前的 + * 版本 (Revision 1.27) + * + * 原本 ve 的做法是, 因為每一行最大可以輸入 WRAPMARGIN 個字, 於是就替每一 + * 行保留了 WRAPMARGIN 這麼大的空間 (約 512 bytes) . 但是實際上, 站在修正 + * 成本最小的考量上, 我們只須要使得游標所在這一行維持 WRAPMARGIN 這麼大, + * 其他每一行其實不須要這麼多的空間. 於是這個 patch就在每次游標在行間移動 + * 的時候, 將原本的那行記憶體縮小, 再將新移到的那行重新加大, 以達成最小的 + * 記憶體用量. + * 以上說的這個動作在 adjustline() 中完成, adjustline()另外包括修正數個 + * global pointer, 以避免 dangling pointer . + * 另外若定義 DEBUG, 在 textline_t 結構中將加入 mlength, 表示該行實際佔的 + * 記憶體大小. 以方便測試結果. + * 這個版本似乎還有地方沒有修正好, 可能導致 segmentation fault . + */ #include "bbs.h" typedef struct textline_t { struct textline_t *prev; @@ -268,6 +286,14 @@ indent_spcs() static textline_t * adjustline(textline_t *oldp, short len) { + /* adjustline(oldp, len); + * 用來將 oldp 指到的那一行, 重新修正成 len這麼長. + * 在這邊一共做了兩次的 memcpy() , 第一次從 heap 拷到 stack , + * 把原來記憶體 free() 後, 又重新在 stack上 malloc() 一次, + * 然後再拷貝回來. + * 主要是用 sbrk() 觀察到的結果, 這樣子才真的能縮減記憶體用量. + * 詳見 /usr/share/doc/papers/malloc.ascii.gz (in FreeBSD) + */ textline_t tmpl[sizeof(textline_t) + WRAPMARGIN]; textline_t *newp; memcpy(tmpl, oldp, oldp->len + sizeof(textline_t)); -- cgit v1.2.3 From 9951c564414cf94a89880890faef600430865d12 Mon Sep 17 00:00:00 2001 From: in2 Date: Wed, 25 Jun 2003 03:35:39 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@965 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/get.cs.flt.pl | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 pttbbs/util/get.cs.flt.pl diff --git a/pttbbs/util/get.cs.flt.pl b/pttbbs/util/get.cs.flt.pl new file mode 100644 index 00000000..9421abc4 --- /dev/null +++ b/pttbbs/util/get.cs.flt.pl @@ -0,0 +1,8 @@ +#!/usr/bin/perl +@r = split(' ', $t = `/usr/bin/vmstat -n 0 -c 5 1`); +open FH, '>/tmp/mrtg.cs'; +print FH (($r[52]+$r[69]+$r[86]+$r[103])/4); +close FH; +open FH, '>/tmp/mrtg.flt'; +print FH (($r[44]+$r[61]+$r[78]+$r[95])/4); +close FH; -- cgit v1.2.3 From 501f3802cfd351a0237486c38b1b307fca59f036 Mon Sep 17 00:00:00 2001 From: in2 Date: Wed, 25 Jun 2003 08:00:32 +0000 Subject: FuzzyIndex git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@966 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/blog/blog.pl | 17 ++++++++++++++--- pttbbs/blog/builddb.pl | 16 ++++++++++++++-- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/pttbbs/blog/blog.pl b/pttbbs/blog/blog.pl index 96c929af..515c1e65 100755 --- a/pttbbs/blog/blog.pl +++ b/pttbbs/blog/blog.pl @@ -1,5 +1,5 @@ #!/usr/bin/perl -# $Id: blog.pl,v 1.23 2003/06/19 13:06:58 in2 Exp $ +# $Id: blog.pl,v 1.24 2003/06/25 08:00:32 in2 Exp $ use CGI qw/:standard/; use lib qw/./; use LocalVars; @@ -9,6 +9,7 @@ use Data::Dumper; use Date::Calc qw(:all); use Template; use HTML::Calendar::Simple; +use OurNet::FuzzyIndex; use vars qw/@emonth @cnumber %config %attr %article %th/; @@ -69,6 +70,15 @@ sub main $ptr); } } + elsif( $attr{"$fn.loadBlog"} =~ /FuzzySearch/i ){ + my $idx = OurNet::FuzzyIndex->new("$BLOGDATA/$brdname.idx"); + my %result = $idx->query($th{SearchKey} = param('SearchKey'), + MATCH_FUZZY); + foreach my $t (sort { $result{$b} <=> $result{$a} } keys(%result)) { + AddArticle('blog', $attr{"$fn.loadBlogFields"}, + $idx->getkey($t), sprintf("%5.1f", $result{$t} / 10)); + } + } if( $attr{"$fn.loadBlogPrevNext"} ){ my $s = packdate($y, $m, $d); @@ -225,9 +235,9 @@ sub main print "
template error: ". $tmpl->error();
 }
 
-sub AddArticle($$$)
+sub AddArticle($$$;$)
 {
-    my($cl, $fields, $s) = @_;
+    my($cl, $fields, $s, $score) = @_;
     my($content, $short) = ();
     $content = applyfilter($article{"$s.content"}, $config{outputfilter})
 	if( $fields =~ /content/i );
@@ -248,6 +258,7 @@ sub AddArticle($$$)
 		       author => (($fields !~ /author/i) ? '' :
 				  $article{"$s.author"}),
 		       short  => $short,
+		       score  => $score,
 		   }
         if( $article{"$s.title"} );
 }
diff --git a/pttbbs/blog/builddb.pl b/pttbbs/blog/builddb.pl
index b519587b..1cec2615 100755
--- a/pttbbs/blog/builddb.pl
+++ b/pttbbs/blog/builddb.pl
@@ -7,6 +7,7 @@ use IO::Handle;
 use Data::Dumper;
 use BBSFileHeader;
 use DB_File;
+use OurNet::FuzzyIndex;
 
 sub main
 {
@@ -99,12 +100,17 @@ sub buildconfigure($$)
 sub builddata($$$$$$)
 {
     my($board, $rbh, $rebuild, $contentonly, $number, $force) = @_;
-    my(%dat, $dbfn, $y, $m, $d, $t, $currid);
+    my(%dat, $dbfn, $idxfn, $y, $m, $d, $t, $currid, $idx);
 
     $dbfn = "$BLOGROOT/$board.db";
-    unlink $dbfn if( $rebuild );
+    $idxfn = "$BLOGROOT/$board.idx";
+    if( $rebuild ){
+	unlink $dbfn;
+	unlink $idxfn;
+    }
 
     tie %dat, 'DB_File', $dbfn, O_CREAT | O_RDWR, 0666, $DB_HASH;
+    $idx = OurNet::FuzzyIndex->new($idxfn);
     foreach( $number ? $number : (1..($rbh->{num} - 1)) ){
 	if( !(($y, $m, $d, $t) =
 	      $rbh->{"$_.title"} =~ /(\d+)\.(\d+).(\d+),(.*)/) ){
@@ -127,6 +133,9 @@ sub builddata($$$$$$)
 			  $dat{"$currid.content"} = $rbh->{"$_.content"});
 	    $dat{"$currid.short"} = ("$c[0]\n$c[1]\n$c[2]\n$c[3]\n");
 
+	    $idx->delete($currid) if( $idx->findkey($currid) );
+	    $idx->insert($currid, $rbh->{"$_.content"});
+
 	    if( !$contentonly ){
 		debugmsg("\tbuilding $currid linking... ");
 		if( $dat{$currid} ){
@@ -163,6 +172,9 @@ sub builddata($$$$$$)
 	}
     }
     untie %dat;
+    $idx->sync();
+    undef $idx;
+    chmod 0666, $idxfn;
 }
 
 sub getdir($$$$$)
-- 
cgit v1.2.3


From 155753c5c6de6bb9916e6c8b6a0ba00c18859c47 Mon Sep 17 00:00:00 2001
From: in2 
Date: Wed, 25 Jun 2003 08:06:15 +0000
Subject: save title into FuzzyIndex

git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@967 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
---
 pttbbs/blog/builddb.pl | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/pttbbs/blog/builddb.pl b/pttbbs/blog/builddb.pl
index 1cec2615..17c681fe 100755
--- a/pttbbs/blog/builddb.pl
+++ b/pttbbs/blog/builddb.pl
@@ -134,7 +134,8 @@ sub builddata($$$$$$)
 	    $dat{"$currid.short"} = ("$c[0]\n$c[1]\n$c[2]\n$c[3]\n");
 
 	    $idx->delete($currid) if( $idx->findkey($currid) );
-	    $idx->insert($currid, $rbh->{"$_.content"});
+	    $idx->insert($currid, ($dat{"$currid.title"}. "\n".
+				   $rbh->{"$_.content"}));
 
 	    if( !$contentonly ){
 		debugmsg("\tbuilding $currid linking... ");
-- 
cgit v1.2.3


From d0fec1ff0d2edbaff360f9843a5d7c926d493483 Mon Sep 17 00:00:00 2001
From: kcwu 
Date: Wed, 25 Jun 2003 22:56:19 +0000
Subject: remove unused variable

git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@968 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
---
 pttbbs/mbbsd/edit.c | 18 ++----------------
 1 file changed, 2 insertions(+), 16 deletions(-)

diff --git a/pttbbs/mbbsd/edit.c b/pttbbs/mbbsd/edit.c
index c036362d..738cb4f8 100644
--- a/pttbbs/mbbsd/edit.c
+++ b/pttbbs/mbbsd/edit.c
@@ -1,4 +1,4 @@
-/* $Id: edit.c,v 1.34 2003/06/24 20:58:55 in2 Exp $ */
+/* $Id: edit.c,v 1.35 2003/06/25 22:56:19 kcwu Exp $ */
 /* edit.c, 用來提供 bbs上的文字編輯器, 即 ve.
  * 現在這一個是惡搞過的版本, 比較不穩定, 用比較多的 cpu, 但是可以省下許多
  * 的記憶體 (以 Ptt為例, 在九千人上站的時候, 約可省下 50MB 的記憶體)
@@ -53,8 +53,6 @@ static int      raw_mode;
 static int      edit_margin;
 static int      blockln = -1;
 static int      blockpnt;
-static int      prevln = -1;
-static int      prevpnt;
 static int      line_dirty;
 static int      indent_mode;
 static int      insert_c = ' ';
@@ -560,8 +558,6 @@ read_tmpbuf(int n)
     if (n != 0 && n != 5 && more(fp_tmpbuf, NA) != -1)
 	getdata(b_lines - 1, 0, "確定讀入嗎(Y/N)?[Y]", ans, sizeof(ans), LCECHO);
     if (*ans != 'n' && (fp = fopen(fp_tmpbuf, "r"))) {
-	prevln = currln;
-	prevpnt = currpnt;
 	load_file(fp);
 	while (curr_window_line >= b_lines) {
 	    curr_window_line--;
@@ -1169,8 +1165,6 @@ goto_line(int lino)
 	 sscanf(buf, "%d", &lino) && lino > 0)) {
 	textline_t     *p;
 
-	prevln = currln;
-	prevpnt = currpnt;
 	p = firstline;
 	currln = lino - 1;
 
@@ -1254,8 +1248,6 @@ search_str(int mode)
 		    break;
 	}
 	if (pos) {
-	    prevln = currln;
-	    prevpnt = currpnt;
 	    currline = p;
 	    currln = lino;
 	    currpnt = pos - p->data;
@@ -1661,7 +1653,7 @@ vedit(char *fpath, int saveheader, int *islocal)
     currutmp->mode = EDITING;
     currutmp->destuid = currstat;
     insert_character = redraw_everything = 1;
-    prevln = blockln = -1;
+    blockln = -1;
 
     line_dirty = currpnt = totaln = my_ansimode = 0;
     oldcurrline = currline = top_of_win =
@@ -2057,8 +2049,6 @@ vedit(char *fpath, int saveheader, int *islocal)
 			int             indent_mode0 = indent_mode;
 
 			indent_mode = 0;
-			prevln = currln;
-			prevpnt = currpnt;
 			while (fgets(line, WRAPMARGIN + 2, fp1)) {
 			    if (!strncmp(line, "作者:", 5) ||
 				!strncmp(line, "標題:", 5) ||
@@ -2181,16 +2171,12 @@ vedit(char *fpath, int saveheader, int *islocal)
 		line_dirty = 1;
 		break;
 	    case Ctrl(']'):	/* start of file */
-		prevln = currln;
-		prevpnt = currpnt;
 		currline = top_of_win = firstline;
 		currpnt = currln = curr_window_line = 0;
 		redraw_everything = YEA;
 		line_dirty = 0;
 		break;
 	    case Ctrl('T'):	/* tail of file */
-		prevln = currln;
-		prevpnt = currpnt;
 		top_of_win = back_line(lastline, 23);
 		currline = lastline;
 		curr_window_line = getlineno();
-- 
cgit v1.2.3


From b5f3a52a1c8b7b6442f4d3e5b48b917f5584b9c9 Mon Sep 17 00:00:00 2001
From: kcwu 
Date: Thu, 26 Jun 2003 01:04:03 +0000
Subject: code clean up

git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@969 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
---
 pttbbs/mbbsd/args.c | 20 +++++++-------------
 1 file changed, 7 insertions(+), 13 deletions(-)

diff --git a/pttbbs/mbbsd/args.c b/pttbbs/mbbsd/args.c
index 1d128673..bf36827b 100644
--- a/pttbbs/mbbsd/args.c
+++ b/pttbbs/mbbsd/args.c
@@ -1,4 +1,4 @@
-/* $Id: args.c,v 1.7 2002/07/22 19:02:00 in2 Exp $ */
+/* $Id: args.c,v 1.8 2003/06/26 01:04:03 kcwu Exp $ */
 #include "bbs.h"
 #ifdef HAVE_SETPROCTITLE
 
@@ -40,19 +40,13 @@ initsetproctitle(int argc, char **argv, char **envp)
 static void
 do_setproctitle(const char *cmdline)
 {
-    char            buf[256], *p;
-    int             i;
+    int             len;
 
-    strncpy(buf, cmdline, 256);
-    buf[255] = '\0';
-    i = strlen(buf);
-    if (i > LastArgv - Argv[0] - 2) {
-	i = LastArgv - Argv[0] - 2;
-    }
-    strlcpy(Argv[0], buf, sizeof(buf));
-    p = &Argv[0][i];
-    while (p < LastArgv)
-	*p++ = '\0';
+    len = strlen(cmdline) + 1; // +1 for '\0'
+    if(len > LastArgv - Argv[0] - 2) // 2 ??
+        len = LastArgv - Argv[0] - 2;
+    memset(Argv[0], 0, LastArgv-Argv[0]);
+    strlcpy(Argv[0], cmdline, len);
     Argv[1] = NULL;
 }
 
-- 
cgit v1.2.3


From 8275ac7896966f7e57411bc0b6592c5dc7a9d01f Mon Sep 17 00:00:00 2001
From: kcwu 
Date: Thu, 26 Jun 2003 01:28:02 +0000
Subject: clean up

git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@970 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
---
 pttbbs/mbbsd/mbbsd.c | 21 ++++++++-------------
 1 file changed, 8 insertions(+), 13 deletions(-)

diff --git a/pttbbs/mbbsd/mbbsd.c b/pttbbs/mbbsd/mbbsd.c
index 511555c0..e68aae26 100644
--- a/pttbbs/mbbsd/mbbsd.c
+++ b/pttbbs/mbbsd/mbbsd.c
@@ -1,4 +1,4 @@
-/* $Id: mbbsd.c,v 1.83 2003/06/17 06:38:21 in2 Exp $ */
+/* $Id: mbbsd.c,v 1.84 2003/06/26 01:28:02 kcwu Exp $ */
 #include "bbs.h"
 
 #define SOCKET_QLEN 4
@@ -33,7 +33,6 @@ static void
 start_daemon()
 {
     int             n, fd;
-    char            buf[80];
 
     /*
      * More idiot speed-hacking --- the first time conversion makes the C
@@ -43,8 +42,9 @@ start_daemon()
      */
     time_t          dummy = time(NULL);
     struct tm      *dummy_time = localtime(&dummy);
+    char            buf[32];
 
-    strftime(buf, 80, "%d/%b/%Y:%H:%M:%S", dummy_time);
+    strftime(buf, sizeof(buf), "%d/%b/%Y:%H:%M:%S", dummy_time);
 
 #ifndef NO_FORK
     if ((n = fork())) {
@@ -90,10 +90,6 @@ reapchild(int sig)
 
 #define BANNER \
 "【" BBSNAME "】◎ 台大流行網 ◎(" MYHOSTNAME ") 調幅(" MYIP ") "
-/*
- * #define BANNER \ "【" BBSNAME "】◎ 台大流行網 ◎(" MYHOSTNAME ")\r\n"\ "
- * 調幅(" MYIP ") "
- */
 /* check load and print approriate banner string in buf */
 static int
 chkload(char *buf, int length)
@@ -103,18 +99,16 @@ chkload(char *buf, int length)
 
     i = cpuload(cpu_load);
 
+    buf[0] = 0;
 #ifdef INSCREEN
     if( i > MAX_CPULOAD ){
 	strlcpy(buf, BANNER "\r\n系統過載, 請稍後再來\r\n", length);
-	return 1;
     }
-    buf[0] = 0;
-    return 0;
 #else
-    sprintf(buf, BANNER "%s\r\n",
+    snprintf(buf, length, BANNER "%s\r\n",
 	    (i > MAX_CPULOAD ? "高負荷量,請稍後再來(請利用port 3000~3010連線)" : ""));
-    return i > MAX_CPULOAD ? 1 : 0;
 #endif
+    return i > MAX_CPULOAD ? 1 : 0;
 }
 
 void
@@ -1357,7 +1351,8 @@ check_ban_and_load(int fd)
     write(fd, buf, strlen(buf));
 
     if (banned && (fp = fopen(BBSHOME "/BAN", "r"))) {
-	while (fgets(buf, 256, fp))
+        // XXX this will mess up buf
+	while (fgets(buf, sizeof(buf), fp))
 	    write(fd, buf, strlen(buf));
 	fclose(fp);
     }
-- 
cgit v1.2.3


From 0424e0c7f04fb43d3185a19bfd3ac415510728a2 Mon Sep 17 00:00:00 2001
From: in2 
Date: Thu, 26 Jun 2003 01:33:01 +0000
Subject: register

git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@971 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
---
 pttbbs/mbbsd/user.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/pttbbs/mbbsd/user.c b/pttbbs/mbbsd/user.c
index 9031107e..5b164c19 100644
--- a/pttbbs/mbbsd/user.c
+++ b/pttbbs/mbbsd/user.c
@@ -1,4 +1,4 @@
-/* $Id: user.c,v 1.62 2003/06/21 05:50:47 in2 Exp $ */
+/* $Id: user.c,v 1.63 2003/06/26 01:33:01 in2 Exp $ */
 #include "bbs.h"
 
 static char    *sex[8] = {
@@ -1050,7 +1050,7 @@ static int HaveRejectStr(char *s, char **rej)
     int     i;
     char    *rejectstr[] =
 	{"幹", "阿", "ㄚ", "不", "你媽", "某", "笨", "呆", "..", "xx",
-	 "你管", "管我", NULL};
+	 "你管", "管我", "猜", NULL};
 
     if( rej != NULL )
 	for( i = 0 ; rej[i] != NULL ; ++i )
@@ -1067,7 +1067,7 @@ static char *isvalidname(char *rname)
 {
     char    *rejectstr[] =
 	{"肥", "胖", "豬頭", "小白", "小明", "路人", "老王", "老李", "寶貝",
-	 "先生", "師哥", "老頭", "小姊", "小姐", "美女", "小妹", NULL};
+	 "先生", "師哥", "老頭", "小姊", "小姐", "美女", "小妹", "大頭", NULL};
     if( removespace(rname) && rname[0] < 0 &&
 	strlen(rname) >= 4 &&
 	!HaveRejectStr(rname, rejectstr) &&
@@ -1106,6 +1106,7 @@ static char *isvalidaddr(char *addr)
 	strcmp(&addr[strlen(addr) - 2], "段") == 0 ||
 	strcmp(&addr[strlen(addr) - 2], "路") == 0 ||
 	strcmp(&addr[strlen(addr) - 2], "巷") == 0 ||
+	strcmp(&addr[strlen(addr) - 2], "弄") == 0 ||
 	strcmp(&addr[strlen(addr) - 2], "區") == 0 ||
 	strcmp(&addr[strlen(addr) - 2], "街") == 0    )
 	return "這個地址並不合法";
-- 
cgit v1.2.3


From a317253f12deeeb4e262c9d34865ac0013ef4c15 Mon Sep 17 00:00:00 2001
From: kcwu 
Date: Thu, 26 Jun 2003 02:25:40 +0000
Subject: always clear plaintext password in memory after checking code clean
 up

git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@972 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
---
 pttbbs/mbbsd/register.c | 21 ++++++++++++---------
 1 file changed, 12 insertions(+), 9 deletions(-)

diff --git a/pttbbs/mbbsd/register.c b/pttbbs/mbbsd/register.c
index 63aa579f..51880eb7 100644
--- a/pttbbs/mbbsd/register.c
+++ b/pttbbs/mbbsd/register.c
@@ -1,9 +1,7 @@
-/* $Id: register.c,v 1.12 2003/06/19 15:49:07 bbs Exp $ */
+/* $Id: register.c,v 1.13 2003/06/26 02:25:40 kcwu Exp $ */
 #define _XOPEN_SOURCE
 
 #include "bbs.h"
-/* password encryption */
-static char     pwbuf[14];
 
 char           *
 genpasswd(char *pw)
@@ -24,20 +22,25 @@ genpasswd(char *pw)
 		c += 6;
 	    saltc[i] = c;
 	}
-	strlcpy(pwbuf, pw, sizeof(pwbuf));
-	return crypt(pwbuf, saltc);
+	return crypt(pw, saltc);
     }
     return "";
 }
 
+// NOTE it will clean string in "plain"
 int
-checkpasswd(char *passwd, char *test)
+checkpasswd(char *passwd, char *plain)
 {
+    int             ok;
     char           *pw;
 
-    strncpy(pwbuf, test, 14);
-    pw = crypt(pwbuf, passwd);
-    return (!strncmp(pw, passwd, 14));
+    ok = 0;
+    pw = crypt(plain, passwd);
+    if(pw && strcmp(pw, passwd)==0)
+	ok = 1;
+    memset(plain, 0, strlen(plain));
+
+    return ok;
 }
 
 /* 檢查 user 註冊情況 */
-- 
cgit v1.2.3


From 5a0183e22f8168822df7ffce4eb20d9ffe2aead3 Mon Sep 17 00:00:00 2001
From: kcwu 
Date: Thu, 26 Jun 2003 03:16:10 +0000
Subject: give warning prompt when user use insecure(non-ssh) connection

git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@973 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
---
 pttbbs/mbbsd/mbbsd.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/pttbbs/mbbsd/mbbsd.c b/pttbbs/mbbsd/mbbsd.c
index e68aae26..1ea9b1b8 100644
--- a/pttbbs/mbbsd/mbbsd.c
+++ b/pttbbs/mbbsd/mbbsd.c
@@ -1,4 +1,4 @@
-/* $Id: mbbsd.c,v 1.84 2003/06/26 01:28:02 kcwu Exp $ */
+/* $Id: mbbsd.c,v 1.85 2003/06/26 03:16:10 kcwu Exp $ */
 #include "bbs.h"
 
 #define SOCKET_QLEN 4
@@ -551,7 +551,12 @@ login_query()
 	} else if (uid[0] == '\0' || !dosearchuser(uid)) {
 	    outs(err_uid);
 	} else if (strcmp(uid, STR_GUEST)) {
-	    getdata(21, 0, MSG_PASSWD, passbuf, sizeof(passbuf), NOECHO);
+	    if(getenv("SSH_CLIENT"))
+		getdata(21, 0, MSG_PASSWD,
+			passbuf, sizeof(passbuf), NOECHO);
+	    else
+		getdata(21, 0, MSG_PASSWD"(注意: 使用未加密的傳輸方式, 連線內容可能被監聽)",
+			passbuf, sizeof(passbuf), NOECHO);
 	    passbuf[8] = '\0';
 
 	    if (!checkpasswd(cuser.passwd, passbuf)
-- 
cgit v1.2.3


From 35cd85c4de01114db3dc42539cbcbcadc5d16625 Mon Sep 17 00:00:00 2001
From: kcwu 
Date: Thu, 26 Jun 2003 03:38:02 +0000
Subject: unset SSH_CLIENT env variable in daemon mode

git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@974 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
---
 pttbbs/mbbsd/mbbsd.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/pttbbs/mbbsd/mbbsd.c b/pttbbs/mbbsd/mbbsd.c
index 1ea9b1b8..376cc696 100644
--- a/pttbbs/mbbsd/mbbsd.c
+++ b/pttbbs/mbbsd/mbbsd.c
@@ -1,4 +1,4 @@
-/* $Id: mbbsd.c,v 1.85 2003/06/26 03:16:10 kcwu Exp $ */
+/* $Id: mbbsd.c,v 1.86 2003/06/26 03:38:02 kcwu Exp $ */
 #include "bbs.h"
 
 #define SOCKET_QLEN 4
@@ -78,6 +78,9 @@ start_daemon()
 	exit(0);
     }
 #endif
+
+    if(getenv("SSH_CLIENT"))
+      unsetenv("SSH_CLIENT");
 }
 
 static void
-- 
cgit v1.2.3


From 266c1d85db778429fd1bc073a3533643e6f72536 Mon Sep 17 00:00:00 2001
From: kcwu 
Date: Thu, 26 Jun 2003 16:27:12 +0000
Subject: add one assert() line

git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@975 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
---
 pttbbs/mbbsd/read.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/pttbbs/mbbsd/read.c b/pttbbs/mbbsd/read.c
index e6620cb4..7ec54a9d 100644
--- a/pttbbs/mbbsd/read.c
+++ b/pttbbs/mbbsd/read.c
@@ -1,4 +1,4 @@
-/* $Id: read.c,v 1.23 2003/06/22 15:06:00 in2 Exp $ */
+/* $Id: read.c,v 1.24 2003/06/26 16:27:12 kcwu Exp $ */
 #include "bbs.h"
 
 static fileheader_t *headers = NULL;
@@ -882,6 +882,7 @@ i_read(int cmdmode, char *direct, void (*dotitle) (), void (*doentry) (), onekey
 
 	/* 讀取鍵盤,加以處理,設定 mode */
 	if (!jump) {
+	    assert(3 + locmem->crs_ln - locmem->top_ln>=0); // FIXME dunno why
 	    cursor_show(3 + locmem->crs_ln - locmem->top_ln, 0);
 	    ch = egetch();
 	    mode = DONOTHING;
-- 
cgit v1.2.3


From ca4cf33f380baf1e4c555487f44e5e1be2ca9196 Mon Sep 17 00:00:00 2001
From: kcwu 
Date: Thu, 26 Jun 2003 16:29:02 +0000
Subject: enable assert()

git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@976 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
---
 pttbbs/pttbbs.mk | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/pttbbs/pttbbs.mk b/pttbbs/pttbbs.mk
index e1a9e505..7944f956 100644
--- a/pttbbs/pttbbs.mk
+++ b/pttbbs/pttbbs.mk
@@ -1,4 +1,4 @@
-# $Id: pttbbs.mk,v 1.3 2003/06/22 18:19:59 kcwu Exp $
+# $Id: pttbbs.mk,v 1.4 2003/06/26 16:29:02 kcwu Exp $
 # 定義基本初值
 BBSHOME?=	$(HOME)
 BBSHOME?=	/home/bbs
@@ -8,8 +8,8 @@ PTT_CFLAGS=	-Wall -pipe -DBBSHOME='"$(BBSHOME)"' -I../include
 PTT_LDFLAGS=	-pipe -Wall
 PTT_LIBS=	-lcrypt
 
-# 稍後再 enable assert()
-PTT_CFLAGS+=	-DNDEBUG 
+# enable assert()
+#PTT_CFLAGS+=	-DNDEBUG 
 
 # FreeBSD特有的環境
 CFLAGS_FreeBSD=	-DHAVE_SETPROCTITLE -DFreeBSD
-- 
cgit v1.2.3


From 2addd2fa93757bc5114e9b1c44a64a79096a4da7 Mon Sep 17 00:00:00 2001
From: in2 
Date: Fri, 27 Jun 2003 02:39:26 +0000
Subject: fixbug

git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@977 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
---
 pttbbs/mbbsd/bbs.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/pttbbs/mbbsd/bbs.c b/pttbbs/mbbsd/bbs.c
index 1169f764..00343018 100644
--- a/pttbbs/mbbsd/bbs.c
+++ b/pttbbs/mbbsd/bbs.c
@@ -1,4 +1,4 @@
-/* $Id: bbs.c,v 1.99 2003/06/22 15:12:59 in2 Exp $ */
+/* $Id: bbs.c,v 1.100 2003/06/27 02:39:26 in2 Exp $ */
 #include "bbs.h"
 
 static int recommend(int ent, fileheader_t * fhdr, char *direct);
@@ -1307,12 +1307,12 @@ recommend(int ent, fileheader_t * fhdr, char *direct)
 	lock_substitute_record(direct, fhdr, sizeof(*fhdr), ent, LOCK_UN);
     else{
 	fhdr->recommend++;
-	lastrecommend = now;
 	passwd_update(usernum, &cuser);
 	lock_substitute_record(direct, fhdr, sizeof(*fhdr), ent, LOCK_UN);
 	substitute_check(fhdr);
 	touchdircache(currbid);
     }
+    lastrecommend = now;
     return FULLUPDATE;
 }
 
-- 
cgit v1.2.3


From 7348c58d16e7cb2857bd55305b1c57ca4104017e Mon Sep 17 00:00:00 2001
From: in2 
Date: Fri, 27 Jun 2003 02:39:32 +0000
Subject: register

git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@978 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
---
 pttbbs/mbbsd/user.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/pttbbs/mbbsd/user.c b/pttbbs/mbbsd/user.c
index 5b164c19..6772500d 100644
--- a/pttbbs/mbbsd/user.c
+++ b/pttbbs/mbbsd/user.c
@@ -1,4 +1,4 @@
-/* $Id: user.c,v 1.63 2003/06/26 01:33:01 in2 Exp $ */
+/* $Id: user.c,v 1.64 2003/06/27 02:39:32 in2 Exp $ */
 #include "bbs.h"
 
 static char    *sex[8] = {
@@ -1050,7 +1050,7 @@ static int HaveRejectStr(char *s, char **rej)
     int     i;
     char    *rejectstr[] =
 	{"幹", "阿", "ㄚ", "不", "你媽", "某", "笨", "呆", "..", "xx",
-	 "你管", "管我", "猜", NULL};
+	 "你管", "管我", "猜", "天才", "超人", NULL};
 
     if( rej != NULL )
 	for( i = 0 ; rej[i] != NULL ; ++i )
@@ -1067,7 +1067,8 @@ static char *isvalidname(char *rname)
 {
     char    *rejectstr[] =
 	{"肥", "胖", "豬頭", "小白", "小明", "路人", "老王", "老李", "寶貝",
-	 "先生", "師哥", "老頭", "小姊", "小姐", "美女", "小妹", "大頭", NULL};
+	 "先生", "師哥", "老頭", "小姊", "小姐", "美女", "小妹", "大頭", 
+	 "公主", NULL};
     if( removespace(rname) && rname[0] < 0 &&
 	strlen(rname) >= 4 &&
 	!HaveRejectStr(rname, rejectstr) &&
-- 
cgit v1.2.3


From 2edad035c1c11196abf0382d715e3ef6359eabf0 Mon Sep 17 00:00:00 2001
From: in2 
Date: Fri, 27 Jun 2003 07:44:02 +0000
Subject: undo 1.85

git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@979 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
---
 pttbbs/mbbsd/mbbsd.c | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)

diff --git a/pttbbs/mbbsd/mbbsd.c b/pttbbs/mbbsd/mbbsd.c
index 376cc696..a4c3abe9 100644
--- a/pttbbs/mbbsd/mbbsd.c
+++ b/pttbbs/mbbsd/mbbsd.c
@@ -1,4 +1,4 @@
-/* $Id: mbbsd.c,v 1.86 2003/06/26 03:38:02 kcwu Exp $ */
+/* $Id: mbbsd.c,v 1.87 2003/06/27 07:44:02 in2 Exp $ */
 #include "bbs.h"
 
 #define SOCKET_QLEN 4
@@ -554,12 +554,8 @@ login_query()
 	} else if (uid[0] == '\0' || !dosearchuser(uid)) {
 	    outs(err_uid);
 	} else if (strcmp(uid, STR_GUEST)) {
-	    if(getenv("SSH_CLIENT"))
-		getdata(21, 0, MSG_PASSWD,
-			passbuf, sizeof(passbuf), NOECHO);
-	    else
-		getdata(21, 0, MSG_PASSWD"(注意: 使用未加密的傳輸方式, 連線內容可能被監聽)",
-			passbuf, sizeof(passbuf), NOECHO);
+	    getdata(21, 0, MSG_PASSWD,
+		    passbuf, sizeof(passbuf), NOECHO);
 	    passbuf[8] = '\0';
 
 	    if (!checkpasswd(cuser.passwd, passbuf)
-- 
cgit v1.2.3


From 6029c7046537609df3b5c73c3159abfade9963ef Mon Sep 17 00:00:00 2001
From: kcwu 
Date: Sat, 28 Jun 2003 08:42:37 +0000
Subject: avoid format string bug

git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@980 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
---
 pttbbs/mbbsd/screen.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/pttbbs/mbbsd/screen.c b/pttbbs/mbbsd/screen.c
index 832abfca..1f27dd86 100644
--- a/pttbbs/mbbsd/screen.c
+++ b/pttbbs/mbbsd/screen.c
@@ -1,4 +1,4 @@
-/* $Id: screen.c,v 1.15 2003/05/18 07:31:09 in2 Exp $ */
+/* $Id: screen.c,v 1.16 2003/06/28 08:42:37 kcwu Exp $ */
 #include "bbs.h"
 
 #ifdef SUPPORT_GB
@@ -498,7 +498,7 @@ mprints(int y, int x, char *str)
 {
     move(y, x);
     clrtoeol();
-    prints(str);
+    prints("%s",str);
 }
 
 void
-- 
cgit v1.2.3


From 9dcc7c3bc773e4d34a793c29f15a31d14bdf3e16 Mon Sep 17 00:00:00 2001
From: kcwu 
Date: Sat, 28 Jun 2003 08:45:02 +0000
Subject: fix strange syntax

git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@981 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
---
 pttbbs/mbbsd/chicken.c | 6 +++---
 pttbbs/mbbsd/gamble.c  | 4 ++--
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/pttbbs/mbbsd/chicken.c b/pttbbs/mbbsd/chicken.c
index 2bc1e64c..553cdbd5 100644
--- a/pttbbs/mbbsd/chicken.c
+++ b/pttbbs/mbbsd/chicken.c
@@ -1,4 +1,4 @@
-/* $Id: chicken.c,v 1.11 2003/04/27 13:00:16 in2 Exp $ */
+/* $Id: chicken.c,v 1.12 2003/06/28 08:44:35 kcwu Exp $ */
 #include "bbs.h"
 
 #define NUM_KINDS   13		/* 有多少種動物 */
@@ -1021,10 +1021,10 @@ chickenpk(int fd)
 		break;
 	}
     }
-    add_io(0, 0);		/* 把igetch恢護回 */
+    add_io(0, 0);		/* 把igetch恢復回 */
     pressanykey();
     close(fd);
-    if (!showdeadth(deadtype(mychicken)));
+    showdeadth(deadtype(mychicken));
     unlockutmpmode();
     return 0;
 }
diff --git a/pttbbs/mbbsd/gamble.c b/pttbbs/mbbsd/gamble.c
index 93342e00..4d64e416 100644
--- a/pttbbs/mbbsd/gamble.c
+++ b/pttbbs/mbbsd/gamble.c
@@ -1,4 +1,4 @@
-/* $Id: gamble.c,v 1.34 2003/05/26 11:24:28 ptt Exp $ */
+/* $Id: gamble.c,v 1.35 2003/06/28 08:45:02 kcwu Exp $ */
 #include "bbs.h"
 
 #ifndef _BBS_UTIL_C_
@@ -47,7 +47,7 @@ show_ticket_data(char betname[MAX_ITEM][MAX_ITEM_LEN],char *direct, int *price,
     if (!(fp = fopen(genbuf, "r"))) {
 	prints("\n目前並沒有舉辦賭盤\n");
 	snprintf(genbuf, sizeof(genbuf), "%s/" FN_TICKET_OUTCOME, direct);
-	if (more(genbuf, NA));
+	more(genbuf, NA);
 	return 0;
     }
     fgets(genbuf, MAX_ITEM_LEN, fp);
-- 
cgit v1.2.3


From cd9a39213923e0b3ea7a2dcdc68d244b0e038f0c Mon Sep 17 00:00:00 2001
From: kcwu 
Date: Sat, 28 Jun 2003 08:47:45 +0000
Subject: assert() the return value of strchr() strrchr()

git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@982 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
---
 pttbbs/mbbsd/bbs.c       |  6 ++++--
 pttbbs/mbbsd/edit.c      |  3 ++-
 pttbbs/mbbsd/record.c    | 10 +++++++---
 pttbbs/mbbsd/stuff.c     |  8 +++++++-
 pttbbs/mbbsd/voteboard.c |  5 +++--
 5 files changed, 23 insertions(+), 9 deletions(-)

diff --git a/pttbbs/mbbsd/bbs.c b/pttbbs/mbbsd/bbs.c
index 00343018..b89cbbef 100644
--- a/pttbbs/mbbsd/bbs.c
+++ b/pttbbs/mbbsd/bbs.c
@@ -1,4 +1,4 @@
-/* $Id: bbs.c,v 1.100 2003/06/27 02:39:26 in2 Exp $ */
+/* $Id: bbs.c,v 1.101 2003/06/28 08:47:45 kcwu Exp $ */
 #include "bbs.h"
 
 static int recommend(int ent, fileheader_t * fhdr, char *direct);
@@ -1846,7 +1846,9 @@ good_post(int ent, fileheader_t * fhdr, char *direct)
 	memcpy(&digest, fhdr, sizeof(digest));
 	digest.filename[0] = 'G';
 	strlcpy(buf, direct, sizeof(buf));
-	ptr = strrchr(buf, '/') + 1;
+	ptr = strrchr(buf, '/');
+	assert(ptr);
+	ptr++;
 	ptr[0] = '\0';
 	snprintf(genbuf, sizeof(genbuf), "%s%s", buf, digest.filename);
 
diff --git a/pttbbs/mbbsd/edit.c b/pttbbs/mbbsd/edit.c
index 738cb4f8..c3e2fdc5 100644
--- a/pttbbs/mbbsd/edit.c
+++ b/pttbbs/mbbsd/edit.c
@@ -1,4 +1,4 @@
-/* $Id: edit.c,v 1.35 2003/06/25 22:56:19 kcwu Exp $ */
+/* $Id: edit.c,v 1.36 2003/06/28 08:47:45 kcwu Exp $ */
 /* edit.c, 用來提供 bbs上的文字編輯器, 即 ve.
  * 現在這一個是惡搞過的版本, 比較不穩定, 用比較多的 cpu, 但是可以省下許多
  * 的記憶體 (以 Ptt為例, 在九千人上站的時候, 約可省下 50MB 的記憶體)
@@ -700,6 +700,7 @@ do_quote()
 		if ((curredit & EDIT_BOTH) && (str = strchr(quote_user, '.'))) {
 		    strcpy(++str, ptr);
 		    str = strchr(str, ' ');
+		    assert(str);
 		    str[0] = '\0';
 		}
 	    } else
diff --git a/pttbbs/mbbsd/record.c b/pttbbs/mbbsd/record.c
index 61f58dbc..2bd06b16 100644
--- a/pttbbs/mbbsd/record.c
+++ b/pttbbs/mbbsd/record.c
@@ -1,4 +1,4 @@
-/* $Id: record.c,v 1.13 2003/02/27 10:48:41 victor Exp $ */
+/* $Id: record.c,v 1.14 2003/06/28 08:47:45 kcwu Exp $ */
 #include "bbs.h"
 
 #undef  HAVE_MMAP
@@ -42,7 +42,9 @@ get_sum_records(char *fpath, int size)
 	return -1;
 
     strlcpy(buf, fpath, sizeof(buf));
-    p = strrchr(buf, '/') + 1;
+    p = strrchr(buf, '/');
+    assert(p);
+    p++;
 
     while (fread(&fhdr, size, 1, fp) == 1) {
 	strcpy(p, fhdr.filename);
@@ -275,7 +277,9 @@ delete_range(char *fpath, int id1, int id2)
     }
     count = 1;
     strlcpy(fullpath, fpath, sizeof(fullpath));
-    t = strrchr(fullpath, '/') + 1;
+    t = strrchr(fullpath, '/');
+    assert(t);
+    t++;
 
     while (read(fdr, &fhdr, sizeof(fileheader_t)) == sizeof(fileheader_t)) {
 	strcpy(t, fhdr.filename);
diff --git a/pttbbs/mbbsd/stuff.c b/pttbbs/mbbsd/stuff.c
index f79ec1ae..a254b42c 100644
--- a/pttbbs/mbbsd/stuff.c
+++ b/pttbbs/mbbsd/stuff.c
@@ -1,4 +1,4 @@
-/* $Id: stuff.c,v 1.11 2003/03/26 10:22:42 in2 Exp $ */
+/* $Id: stuff.c,v 1.12 2003/06/28 08:47:45 kcwu Exp $ */
 #include "bbs.h"
 
 /* ----------------------------------------------------- */
@@ -78,11 +78,17 @@ setbfile(char *buf, char *boardname, char *fname)
     sprintf(buf, str_board_file, boardname[0], boardname, fname);
 }
 
+/*
+ * input	direct
+ * output	buf: copy direct
+ * 		fname: direct 的檔名部分
+ */
 void
 setdirpath(char *buf, char *direct, char *fname)
 {
     strcpy(buf, direct);
     direct = strrchr(buf, '/');
+    assert(direct);
     strcpy(direct + 1, fname);
 }
 
diff --git a/pttbbs/mbbsd/voteboard.c b/pttbbs/mbbsd/voteboard.c
index eac92529..d477a12d 100644
--- a/pttbbs/mbbsd/voteboard.c
+++ b/pttbbs/mbbsd/voteboard.c
@@ -1,4 +1,4 @@
-/* $Id: voteboard.c,v 1.17 2003/03/17 13:41:04 victor Exp $ */
+/* $Id: voteboard.c,v 1.18 2003/06/28 08:47:45 kcwu Exp $ */
 #include "bbs.h"
 
 #define VOTEBOARD "NewBoard"
@@ -41,10 +41,11 @@ do_voteboardreply(fileheader_t * fhdr)
 
     len = strlen(cuser.userid);
 
-    while (fgets(genbuf, 1024, fp)) {
+    while (fgets(genbuf, sizeof(genbuf), fp)) {
 	if (!strncmp(genbuf, "連署結束時間", 12)) {
 	    hastime = 1;
 	    ptr = strchr(genbuf, '(');
+	    assert(ptr);
 	    sscanf(ptr + 1, "%ld", &endtime);
 	    if (endtime < now) {
 		prints("連署時間已過");
-- 
cgit v1.2.3


From 1b0401ddcc658fe320bed910259cf2ee67783cdf Mon Sep 17 00:00:00 2001
From: kcwu 
Date: Sat, 28 Jun 2003 08:48:36 +0000
Subject: fix typo

git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@983 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
---
 pttbbs/mbbsd/bbcall.c | 4 ++--
 pttbbs/mbbsd/indict.c | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/pttbbs/mbbsd/bbcall.c b/pttbbs/mbbsd/bbcall.c
index 676816f7..93fe499d 100644
--- a/pttbbs/mbbsd/bbcall.c
+++ b/pttbbs/mbbsd/bbcall.c
@@ -1,4 +1,4 @@
-/* $Id: bbcall.c,v 1.8 2002/07/22 19:02:00 in2 Exp $ */
+/* $Id: bbcall.c,v 1.9 2003/06/28 08:44:03 kcwu Exp $ */
 #include "bbs.h"
 
 #define SERVER_0941     "www.chips.com.tw"
@@ -99,7 +99,7 @@ Connect(char *s, char *server)
 	hpressanykey("無法與伺服器取得連結,傳呼失敗");
 	return 0;
     } else {
-	mprints(20, 0, "\033[1;33m伺服器已經連接上,請稍後"
+	mprints(20, 0, "\033[1;33m伺服器已經連接上,請稍候"
 		".....................\033[m");
 	refresh();
     }
diff --git a/pttbbs/mbbsd/indict.c b/pttbbs/mbbsd/indict.c
index 1de9b02c..cdd2712d 100644
--- a/pttbbs/mbbsd/indict.c
+++ b/pttbbs/mbbsd/indict.c
@@ -1,4 +1,4 @@
-/* $Id: indict.c,v 1.12 2003/01/19 16:06:06 kcwu Exp $ */
+/* $Id: indict.c,v 1.13 2003/06/28 08:48:36 kcwu Exp $ */
 #include "bbs.h"
 
 #define REFER "etc/dicts"
@@ -73,7 +73,7 @@ use_dict()
 {
     FILE           *fp;
     char            lang[150], word[80] = "";
-    char            j, f, buf[120], sys[] = "|\033[31me\033[m:編籍字典";
+    char            j, f, buf[120], sys[] = "|\033[31me\033[m:編輯字典";
     int             i = 0;
 
     setutmpmode(DICT);
-- 
cgit v1.2.3


From 5df1418a61b15be7a2d740a1bcf4cd936050c9bd Mon Sep 17 00:00:00 2001
From: kcwu 
Date: Sat, 28 Jun 2003 08:49:26 +0000
Subject: fix syntax

git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@984 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
---
 pttbbs/mbbsd/vice.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/pttbbs/mbbsd/vice.c b/pttbbs/mbbsd/vice.c
index 2792e47e..e774479c 100644
--- a/pttbbs/mbbsd/vice.c
+++ b/pttbbs/mbbsd/vice.c
@@ -1,4 +1,4 @@
-/* $Id: vice.c,v 1.8 2003/03/22 13:45:56 in2 Exp $ */
+/* $Id: vice.c,v 1.9 2003/06/28 08:49:26 kcwu Exp $ */
 #include "bbs.h"
 
 #define VICE_PLAY   BBSHOME "/etc/vice/vice.play"
@@ -46,7 +46,7 @@ check(char tbingo[6][15], char *data)
 		return j - 1;
     return 0;
 }
-/* Ptt:showfile ran_showfile more 三者要合 */
+/* TODO Ptt:showfile ran_showfile more 三者要合 */
 static int
 ran_showfile(int y, int x, char *filename, int maxnum)
 {
@@ -62,7 +62,7 @@ ran_showfile(int y, int x, char *filename, int maxnum)
     }
     move(y, x);
 
-    while (fgets(buf, 511, fs))
+    while (fgets(buf, sizeof(buf), fs))
 	prints("%s", buf);
 
     fclose(fs);
@@ -84,8 +84,8 @@ vice_main()
 {
     FILE           *fd;
     char            tbingo[6][15];
-    char            buf_data[256]
-                   ,serial[16], ch[2], *ptr;
+    char            buf_data[256],
+                    serial[16], ch[2], *ptr;
     int             TABLE[] = {0, 10, 200, 1000, 4000, 10000, 40000, 100000, 200000};
     int             total = 0, money, i = 4, j = 0;
 
-- 
cgit v1.2.3


From 0f24ac93c8bf57f8476d94551b0075fddeb0fb21 Mon Sep 17 00:00:00 2001
From: kcwu 
Date: Sat, 28 Jun 2003 08:51:14 +0000
Subject: trim space

git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@985 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
---
 pttbbs/mbbsd/admin.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/pttbbs/mbbsd/admin.c b/pttbbs/mbbsd/admin.c
index e01cd4da..ccc3fe89 100644
--- a/pttbbs/mbbsd/admin.c
+++ b/pttbbs/mbbsd/admin.c
@@ -1,4 +1,4 @@
-/* $Id: admin.c,v 1.43 2003/05/30 07:57:08 victor Exp $ */
+/* $Id: admin.c,v 1.44 2003/06/28 08:51:14 kcwu Exp $ */
 #include "bbs.h"
 
 /* 使用者管理 */
@@ -1065,9 +1065,9 @@ cat_register()
 {
     if (system("cat register.new.tmp >> register.new") == 0 &&
 	system("rm -f register.new.tmp") == 0)
-	mprints(22, 0, "OK 嚕~~ 繼續去奮鬥吧!!                                                ");
+	mprints(22, 0, "OK 嚕~~ 繼續去奮鬥吧!!");
     else
-	mprints(22, 0, "沒辦法CAT過去呢 去檢查一下系統吧!!                                    ");
+	mprints(22, 0, "沒辦法CAT過去呢 去檢查一下系統吧!!");
     pressanykey();
     return 0;
 }
-- 
cgit v1.2.3


From dbe5213241c118317fd09734ef591b75b78616aa Mon Sep 17 00:00:00 2001
From: kcwu 
Date: Sat, 28 Jun 2003 08:52:18 +0000
Subject: comment

git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@986 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
---
 pttbbs/mbbsd/kaede.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/pttbbs/mbbsd/kaede.c b/pttbbs/mbbsd/kaede.c
index a3fd96ad..8b9d859e 100644
--- a/pttbbs/mbbsd/kaede.c
+++ b/pttbbs/mbbsd/kaede.c
@@ -1,4 +1,4 @@
-/* $Id: kaede.c,v 1.14 2003/06/07 14:19:12 kcwu Exp $ */
+/* $Id: kaede.c,v 1.15 2003/06/28 08:52:18 kcwu Exp $ */
 #include "bbs.h"
 
 char           *
@@ -65,7 +65,7 @@ Rename(char *src, char *dst)
     if (rename(src, dst) == 0)
 	return 0;
     if (!strchr(src, ';') && !strchr(dst, ';'))
-	// Ptt 防不正常指令
+	// Ptt 防不正常指令 // XXX 這樣是不夠的
     {
 	snprintf(buf, sizeof(buf), "/bin/mv %s %s", src, dst);
 	system(buf);
-- 
cgit v1.2.3


From ee2a749b2c162cccf037e31c54ba331edde72df3 Mon Sep 17 00:00:00 2001
From: kcwu 
Date: Sat, 28 Jun 2003 08:54:02 +0000
Subject: remove gopher mode support, there is security hole

git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@987 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
---
 pttbbs/mbbsd/announce.c | 604 +-----------------------------------------------
 1 file changed, 8 insertions(+), 596 deletions(-)

diff --git a/pttbbs/mbbsd/announce.c b/pttbbs/mbbsd/announce.c
index 3b101816..02ea115d 100644
--- a/pttbbs/mbbsd/announce.c
+++ b/pttbbs/mbbsd/announce.c
@@ -1,344 +1,8 @@
-/* $Id: announce.c,v 1.27 2003/06/21 17:10:31 victor Exp $ */
+/* $Id: announce.c,v 1.28 2003/06/28 08:54:02 kcwu Exp $ */
 #include "bbs.h"
 
-static void
-g_showmenu(gmenu_t * pm)
-{
-    char    *mytype = "編    選     絲路之旅";
-    char           *title, ch;
-    int             n, max;
-    item_t         *item;
-
-    showtitle("精華文章", pm->mtitle);
-    prints("  \033[1;36m編號    標      題%56s\033[m", mytype);
-
-    if (pm->num) {
-	n = pm->page;
-	max = n + p_lines;
-	if (max > pm->num)
-	    max = pm->num;
-	while (n < max) {
-	    item = pm->item[n++];
-	    title = item->title;
-	    ch = title[1];
-	    prints("\n%5d. %-72.71s", n, title);
-	}
-    } else
-	outs("\n  《精華區》尚在吸取天地間的日精月華 :)");
-
-    move(b_lines, 1);
-    outs(pm->level ?
-	 "\033[34;46m 【板  主】 \033[31;47m  (h)\033[30m說明  "
-	 "\033[31m(q/←)\033[30m離開  \033[31m(n)\033[30m新增文章  "
-	 "\033[31m(g)\033[30m新增目錄  \033[31m(e)\033[30m編輯檔案  \033[m" :
-	 "\033[34;46m 【功\能鍵】 \033[31;47m  (h)\033[30m說明  "
-	 "\033[31m(q/←)\033[30m離開  \033[31m(k↑j↓)\033[30m移動游標  "
-	 "\033[31m(enter/→)\033[30m讀取資料  \033[m");
-}
-
-static FILE    *
-go_cmd(item_t * node, int *sock)
-{
-    struct sockaddr_in sin;
-    struct hostent *host;
-    char           *site;
-    FILE           *fp;
-
-    *sock = socket(AF_INET, SOCK_STREAM, 0);
-
-    if (*sock < 0) {
-	syslog(LOG_ERR, "socket(): %m");
-	return NULL;
-    }
-    memset((char *)&sin, 0, sizeof(sin));
-    sin.sin_family = AF_INET;
-    sin.sin_port = htons(node->X.G.port);
-
-    host = gethostbyname(site = node->X.G.server);
-    if (host == NULL)
-	sin.sin_addr.s_addr = inet_addr(site);
-    else
-	memcpy(&sin.sin_addr.s_addr, host->h_addr, host->h_length);
-
-    if (connect(*sock, (struct sockaddr *) & sin, sizeof(sin)) < 0) {
-	syslog(LOG_ERR, "connect(): %m");
-	return NULL;
-    }
-    fp = fdopen(*sock, "r+");
-    if (fp != NULL) {
-	setbuf(fp, (char *)0);
-	fprintf(fp, "%s\r\n", node->X.G.path);
-	fflush(fp);
-    } else
-	close(*sock);
-    return fp;
-}
-
-static char    *
-nextfield(char *data, char *field)
-{
-    register int    ch;
-
-    while ((ch = *data)) {
-	data++;
-	if ((ch == '\t') || (ch == '\r' && *data == '\n'))
-	    break;
-	*field++ = ch;
-    }
-    *field = '\0';
-    return data;
-}
-
-static FILE    *
-my_open(char *path)
-{
-    FILE           *ans = 0;
-    char            buf[80];
-    struct stat     st;
-
-    if (stat(path, &st) == 0 && st.st_mtime < now - 3600 * 24 * 7) {
-	return fopen(path, "w");
-    }
-    if ((ans = fopen(path, "r+"))) {
-	fclose(ans);
-	return 0;
-	/*
-	 * return directly due to currutmp->pager > 1 mode (real copy)
-	 */
-	fgets(buf, 80, ans);
-	if (!strncmp(buf, str_author1, strlen(str_author1)) ||
-	    *buf == '0' || *buf == '1') {
-	    fclose(ans);
-	    return 0;
-	}
-	rewind(ans);
-    } else
-	ans = fopen(path, "w");
-    return ans;
-}
-
-static jmp_buf  jbuf;
-
-static void
-isig(int sig)
-{
-    longjmp(jbuf, 1);
-}
-
-#define PROXY_HOME      "proxy/"
-
-static void
-go_proxy(char *fpath, item_t * node, int update)
-{
-    char           *ptr, *str, *server;
-    int             ch;
-    static FILE    *fo;
-
-    strcpy(fpath, PROXY_HOME);
-    ptr = fpath + sizeof(PROXY_HOME) - 1;
-    str = server = node->X.G.server;
-    while ((ch = *str)) {
-	str++;
-	if (ch == '.') {
-	    if (!strcmp(str, "edu.tw"))
-		break;
-	} else if (ch >= 'A' && ch <= 'Z') {
-	    ch |= 0x20;
-	}
-	*ptr++ = ch;
-    }
-    *ptr = '\0';
-    mkdir(fpath, 0755);
-
-    *ptr++ = '/';
-    str = node->X.G.path;
-    while ((ch = *str)) {
-	str++;
-	if (ch == '/') {
-	    ch = '.';
-	}
-	*ptr++ = ch;
-    }
-    *ptr = '\0';
-
-    /* expire proxy data */
-
-    if ((fo = update ? fopen(fpath, "w") : my_open(fpath))) {
-	FILE           *fp;
-	char            buf[512];
-	int             sock;
-
-	if (fo == NULL)
-	    return;
-
-	outmsg("★ 建立 proxy 資料連線中 ... ");
-	refresh();
-
-	sock = -1;
-	if (setjmp(jbuf)) {
-	    if (sock != -1)
-		close(sock);
-	    fseek(fo, 0, SEEK_SET);
-	    fwrite("", 0, 0, fo);
-	    fclose(fo);
-	    alarm(0);
-	    return;
-	}
-	signal(SIGALRM, isig);
-	alarm(5);
-	fp = go_cmd(node, &sock);
-	alarm(0);
-
-	str = node->title;
-	ch = str[1];
-	if (ch == (char)0xbc &&
-	    !(HAS_PERM(PERM_SYSOP) && currutmp->pager > 1)) {
-	    fprintf(fo, "作者: %s (連線精華區)\n標題: %s\n時間: %s\n",
-		    server, str + 3, ctime(&now)
-		);
-	}
-	while (fgets(buf, 511, fp)) {
-	    if (!strcmp(buf, ".\r\n"))
-		break;
-	    if ((ptr = strstr(buf, "\r\n")))
-		strcpy(ptr, "\n");
-	    fputs(buf, fo);
-	}
-	fclose(fo);
-	fclose(fp);
-    }
-}
-
-static void
-g_additem(gmenu_t * pm, item_t * myitem)
-{
-    if (pm->num < MAX_ITEMS) {
-	item_t         *newitem = (item_t *) malloc(sizeof(item_t));
-
-	memcpy(newitem, myitem, sizeof(item_t));
-	pm->item[(pm->num)++] = newitem;
-    }
-}
-
-static void
-go_menu(gmenu_t * pm, item_t * node, int update)
-{
-    FILE           *fp;
-    char            buf[512], *ptr, *title;
-    item_t          item;
-    int             ch;
-
-    go_proxy(buf, node, update);
-    pm->num = 0;
-    if ((fp = fopen(buf, "r"))) {
-	title = item.title;
-	while (fgets(buf, 511, fp)) {
-	    ptr = buf;
-	    ch = *ptr++;
-	    if (ch != '0' && ch != '1')
-		continue;
-
-	    strcpy(title, "□ ");
-	    if (ch == '1')
-		title[1] = (char)0xbd;
-
-	    ptr = nextfield(ptr, title + 3);
-	    if (!*ptr)
-		continue;
-	    title[sizeof(item.title) - 1] = '\0';
-
-	    ptr = nextfield(ptr, item.X.G.path);
-	    if (!*ptr)
-		continue;
-
-	    ptr = nextfield(ptr, item.X.G.server);
-	    if (!*ptr)
-		continue;
-
-	    nextfield(ptr, buf);
-	    item.X.G.port = atoi(buf);
-
-	    g_additem(pm, &item);
-	}
-	fclose(fp);
-    }
-}
-
-static int
-g_searchtitle(gmenu_t * pm, int rev)
-{
-    static char     search_str[30] = "";
-    int             pos;
-
-    if (getdata(b_lines - 1, 1, "[搜尋]關鍵字:", search_str, sizeof(search_str), DOECHO))
-	if (!*search_str)
-	    return pm->now;
-
-    str_lower(search_str, search_str);
-
-    rev = rev ? -1 : 1;
-    pos = pm->now;
-    do {
-	pos += rev;
-	if (pos == pm->num)
-	    pos = 0;
-	else if (pos < 0)
-	    pos = pm->num - 1;
-	if (strstr_lower(pm->item[pos]->title, search_str))
-	    return pos;
-    } while (pos != pm->now);
-    return pm->now;
-}
-
-static void
-g_showhelp()
-{
-    clear();
-    outs("\033[36m【 " BBSNAME "連線精華區使用說明 】\033[m\n\n"
-	 "[←][q]         離開到上一層目錄\n"
-	 "[↑][k]         上一個選項\n"
-	 "[↓][j]         下一個選項\n"
-	 "[→][r][enter]  進入目錄/讀取文章\n"
-	 "[b][PgUp]       上頁選單\n"
-	 "[^F][PgDn][Spc] 下頁選單\n"
-	 "[##]            移到該選項\n"
-	 "[^S]            將文章存到信箱\n"
-	 "[R]             更新資料\n"
-	 "[N]             查詢檔名\n"
-	 "[c][C][^C]      拷貝文章/並跳至上次貼文章的地方/"
-	 "直接貼到上次貼的地方\n");
-    pressanykey();
-}
-
 #define PATHLEN     256
 
-static char     paste_fname[200];
-
-static void
-load_paste()
-{
-    struct stat     st;
-    FILE           *fp;
-
-    if (!*paste_fname)
-	setuserfile(paste_fname, "paste_path");
-    if (stat(paste_fname, &st) == 0 && st.st_mtime > paste_time &&
-	(fp = fopen(paste_fname, "r"))) {
-	int             i;
-	fgets(paste_path, PATHLEN, fp);
-	i = strlen(paste_path) - 1;
-	if (paste_path[i] == '\n')
-	    paste_path[i] = 0;
-	fgets(paste_title, STRLEN, fp);
-	i = strlen(paste_title) - 1;
-	if (paste_title[i] == '\n')
-	    paste_title[i] = 0;
-	fscanf(fp, "%d", &paste_level);
-	paste_time = st.st_mtime;
-	fclose(fp);
-    }
-}
-
 static char     copyfile[PATHLEN];
 static char     copytitle[TTLEN + 1];
 static char     copyowner[IDLEN + 2];
@@ -490,229 +154,6 @@ a_showhelp(int level)
     pressanykey();
 }
 
-static int
-AnnounceSelect()
-{
-    static char     xboard[20];
-    char            buf[20];
-    char            fpath[256];
-    boardheader_t  *bp;
-
-    move(2, 0);
-    clrtoeol();
-    move(3, 0);
-    clrtoeol();
-    move(1, 0);
-    generalnamecomplete("選擇精華區看板:", buf, sizeof(buf),
-			SHM->Bnumber,
-			completeboard_compar,
-			completeboard_permission,
-			completeboard_getname);
-    if (*buf)
-	strlcpy(xboard, buf, sizeof(xboard));
-    if (*xboard && (bp = getbcache(getbnum(xboard)))) {
-	setapath(fpath, xboard);
-	setutmpmode(ANNOUNCE);
-	a_menu(xboard, fpath,
-	       (HAS_PERM(PERM_ALLBOARD) ||
-		(HAS_PERM(PERM_BM) && is_BM(bp->BM))) ? 1 : 0);
-    }
-    return FULLUPDATE;
-}
-
-void
-gem(char *maintitle, item_t * path, int update)
-{
-    gmenu_t         me;
-    int             ch;
-    char            fname[PATHLEN];
-
-    strncpy(me.mtitle, maintitle, 40);
-    me.mtitle[40] = 0;
-    go_menu(&me, path, update);
-
-    /* 精華區-tree 中部份結構屬於 cuser ==> BM */
-
-    me.level = 0;
-    me.page = 9999;
-    me.now = 0;
-    for (;;) {
-	if (me.now >= me.num && me.num > 0)
-	    me.now = me.num - 1;
-	else if (me.now < 0)
-	    me.now = 0;
-
-	if (me.now < me.page || me.now >= me.page + p_lines) {
-	    me.page = me.now - (me.now % p_lines);
-	    g_showmenu(&me);
-	}
-	ch = cursor_key(2 + me.now - me.page, 0);
-	if (ch == 'q' || ch == 'Q' || ch == KEY_LEFT)
-	    break;
-
-	if (ch >= '0' && ch <= '9') {
-	    if ((ch = search_num(ch, me.num)) != -1)
-		me.now = ch;
-	    me.page = 9999;
-	    continue;
-	}
-	switch (ch) {
-	case KEY_UP:
-	case 'k':
-	    if (--me.now < 0)
-		me.now = me.num - 1;
-	    break;
-	case KEY_DOWN:
-	case 'j':
-	    if (++me.now >= me.num)
-		me.now = 0;
-	    break;
-	case KEY_PGUP:
-	case 'b':
-	    if (me.now >= p_lines)
-		me.now -= p_lines;
-	    else if (me.now > 0)
-		me.now = 0;
-	    else
-		me.now = me.num - 1;
-	    break;
-	case ' ':
-	case KEY_PGDN:
-	case Ctrl('F'):
-	    if (me.now < me.num - p_lines)
-		me.now += p_lines;
-	    else if (me.now < me.num - 1)
-		me.now = me.num - 1;
-	    else
-		me.now = 0;
-	    break;
-	case 'h':
-	    g_showhelp();
-	    me.page = 9999;
-	    break;
-	case '?':
-	case '/':
-	    me.now = g_searchtitle(&me, ch == '?');
-	    me.page = 9999;
-	    break;
-	case 'N':
-	    if (HAS_PERM(PERM_SYSOP)) {
-		go_proxy(fname, me.item[me.now], 0);
-		move(b_lines - 1, 0);
-		outs(fname);
-		pressanykey();
-		me.page = 9999;
-	    }
-	    break;
-	case 'c':
-	case 'C':
-	case Ctrl('C'):
-	    if (me.now < me.num) {
-		item_t         *node = me.item[me.now];
-		char           *title = node->title;
-		int             mode = title[1];
-
-		load_paste();
-		if (mode == (char)0xbc || ch == Ctrl('C')) {
-		    if (mode == (char)0xbc)
-			go_proxy(fname, node, 0);
-		    if (ch == Ctrl('C') && *paste_path && paste_level) {
-			char            newpath[PATHLEN];
-			fileheader_t    item;
-
-			strlcpy(newpath, paste_path, sizeof(newpath));
-			if (mode == (char)0xbc) {
-			    stampfile(newpath, &item);
-			    unlink(newpath);
-			    Link(fname, newpath);
-			} else
-			    stampdir(newpath, &item);
-			strlcpy(item.owner, cuser.userid, sizeof(item.owner));
-			snprintf(item.title, sizeof(item.title), "%s%.72s",
-				(currutmp->pager > 1) ? "" :
-				(mode == (char)0xbc) ? "◇ " : "◆ ",
-				title + 3);
-			strcpy(strrchr(newpath, '/') + 1, ".DIR");
-			append_record(newpath, &item, FHSZ);
-			if (++me.now >= me.num)
-			    me.now = 0;
-			break;
-		    }
-		    if (mode == (char)0xbc) {
-			a_copyitem(fname,
-				   title + ((currutmp->pager > 1) ? 3 : 0),
-				   0, 1);
-			if (ch == 'C' && *paste_path) {
-			    setutmpmode(ANNOUNCE);
-			    a_menu(paste_title, paste_path, paste_level);
-			}
-			me.page = 9999;
-		    } else
-			bell();
-		}
-	    }
-	    break;
-	case Ctrl('B'):
-	    m_read();
-	    me.page = 9999;
-	    break;
-	case Ctrl('I'):
-	    t_idle();
-	    me.page = 9999;
-	    break;
-	case 's':
-	    AnnounceSelect();
-	    me.page = 9999;
-	    break;
-	case '\n':
-	case '\r':
-	case KEY_RIGHT:
-	case 'r':
-	case 'R':
-	    if (me.now < me.num) {
-		item_t         *node = me.item[me.now];
-		char           *title = node->title;
-		int             mode = title[1];
-		int             update = (ch == 'R') ? 1 : 0;
-
-		title += 3;
-
-		if (mode == (char)0xbc) {
-		    int             more_result;
-
-		    go_proxy(fname, node, update);
-		    strlcpy(vetitle, title, sizeof(vetitle));
-		    while ((more_result = more(fname, YEA))) {
-			if (more_result == 1) {
-			    if (--me.now < 0) {
-				me.now = 0;
-				break;
-			    }
-			} else if (more_result == 3) {
-			    if (++me.now >= me.num) {
-				me.now = me.num - 1;
-				break;
-			    }
-			} else
-			    break;
-			node = me.item[me.now];
-			if (node->title[1] != (char)0xbc)
-			    break;
-			go_proxy(fname, node, update);
-			strlcpy(vetitle, title, sizeof(vetitle));
-		    }
-		} else if (mode == (char)0xbd) {
-		    gem(title, node, update);
-		}
-		me.page = 9999;
-	    }
-	    break;
-	}
-    }
-    for (ch = 0; ch < me.num; ch++)
-	free(me.item[ch]);
-}
-
 static void
 a_forward(char *path, fileheader_t * pitem, int mode)
 {
@@ -755,16 +196,14 @@ a_additem(menu_t * pm, fileheader_t * myheader)
 
 #define ADDITEM         0
 #define ADDGROUP        1
-#define ADDGOPHER       2
-#define ADDLINK         3
+#define ADDLINK         2
 
 static void
 a_newitem(menu_t * pm, int mode)
 {
-    char    *mesg[4] = {
+    char    *mesg[3] = {
 	"[新增文章] 請輸入標題:",	/* ADDITEM */
 	"[新增目錄] 請輸入標題:",	/* ADDGROUP */
-	"[新增連線] 請輸入標題:",	/* ADDGOPHER */
 	"請輸入標題:"		/* ADDLINK */
     };
 
@@ -784,13 +223,6 @@ a_newitem(menu_t * pm, int mode)
 	stampdir(fpath, &item);
 	strlcpy(item.title, "◆ ", sizeof(item.title));	/* A1BB */
 	break;
-    case ADDGOPHER:
-	bzero(&item, sizeof(item));
-	strlcpy(item.title, "☉ ", sizeof(item.title));	/* A1BB */
-	if (!getdata(b_lines - 2, 1, "輸入URL位址:",
-		     item.filename + 2, 61, DOECHO))
-	    return;
-	break;
     case ADDLINK:
 	stamplink(fpath, &item);
 	if (!getdata(b_lines - 2, 1, "新增連線:", buf, 61, DOECHO))
@@ -802,6 +234,8 @@ a_newitem(menu_t * pm, int mode)
 	    return;
 	}
 	item.title[0] = 0;
+	// XXX Is it alright?
+	// ex: path= "PASSWD"
 	for (d = 0; d <= 3; d++) {
 	    switch (d) {
 	    case 0:
@@ -843,7 +277,7 @@ a_newitem(menu_t * pm, int mode)
     if (!getdata(b_lines - 1, 1, mesg[mode], &item.title[3], 55, DOECHO)) {
 	if (mode == ADDGROUP)
 	    rmdir(fpath);
-	else if (mode != ADDGOPHER)
+	else
 	    unlink(fpath);
 	return;
     }
@@ -863,10 +297,6 @@ a_newitem(menu_t * pm, int mode)
 	    return;
 	}
 	break;
-    case ADDGOPHER:
-	strlcpy(item.date, "70", sizeof(item.date));
-	strncpy(item.filename, "H.", 2);
-	break;
     }
 
     strlcpy(item.owner, cuser.userid, sizeof(item.owner));
@@ -1286,7 +716,7 @@ isvisible_man(menu_t * me)
 int
 a_menu(char *maintitle, char *path, int lastlevel)
 {
-    static char     Fexit;
+    static char     Fexit;	// 用來跳出 recursion
     menu_t          me;
     char            fname[PATHLEN];
     int             ch, returnvalue = FULLUPDATE;
@@ -1391,15 +821,6 @@ a_menu(char *maintitle, char *path, int lastlevel)
 	    me.page = 9999;
 	    break;
 
-	case 's':
-	    /* XXX: security problem
-	       透過這個方式跳的時候不會 update currboard ,
-	       可能會導致像是 check BM 的時候不正確
-	       AnnounceSelect();
-	       me.page = 9999;
-	     */
-	    break;
-
 	case 'e':
 	case 'E':
 	    snprintf(fname, sizeof(fname),
@@ -1463,12 +884,7 @@ a_menu(char *maintitle, char *path, int lastlevel)
 #endif
 		snprintf(fname, sizeof(fname), "%s/%s", path, fhdr->filename);
 		if (*fhdr->filename == 'H' && fhdr->filename[1] == '.') {
-		    item_t          item;
-		    strlcpy(item.X.G.server, fhdr->filename + 2,
-			    sizeof(item.X.G.server));
-		    strlcpy(item.X.G.path, "1/", sizeof(item.X.G.path));
-		    item.X.G.port = 70;
-		    gem(fhdr->title, &item, (ch == 'R') ? 1 : 0);
+		  vmsg("不再支援 gopher mode, 請使用瀏覽器瀏覽 gopher://%s/1/",fhdr->filename);
 		} else if (dashf(fname)) {
 		    int             more_result;
 
@@ -1579,10 +995,6 @@ a_menu(char *maintitle, char *path, int lastlevel)
 		a_newitem(&me, ADDGROUP);
 		me.page = 9999;
 		break;
-	    case 'G':
-		a_newitem(&me, ADDGOPHER);
-		me.page = 9999;
-		break;
 	    case 'p':
 		a_pasteitem(&me, 1);
 		me.page = 9999;
-- 
cgit v1.2.3


From 50341713431a7482650735a4050a008c8d967170 Mon Sep 17 00:00:00 2001
From: kcwu 
Date: Sat, 28 Jun 2003 08:55:40 +0000
Subject: use ccache if it exists

git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@988 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
---
 pttbbs/mbbsd/Makefile | 4 ++--
 pttbbs/pttbbs.mk      | 3 ++-
 2 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/pttbbs/mbbsd/Makefile b/pttbbs/mbbsd/Makefile
index 33db03b6..a8ebd584 100644
--- a/pttbbs/mbbsd/Makefile
+++ b/pttbbs/mbbsd/Makefile
@@ -1,4 +1,4 @@
-# $Id: Makefile,v 1.26 2003/06/22 04:32:38 in2 Exp $
+# $Id: Makefile,v 1.27 2003/06/28 08:55:40 kcwu Exp $
 
 .include "../pttbbs.mk"
 
@@ -14,7 +14,7 @@ OBJS=	admin.o announce.o args.o bbs.o board.o cache.o cal.o card.o\
 
 .SUFFIXES: .c .o
 .c.o:	../include/var.h
-	$(CC) $(CFLAGS) -c $*.c
+	$(CCACHE) $(CC) $(CFLAGS) -c $*.c
 
 all: $(PROG)
 
diff --git a/pttbbs/pttbbs.mk b/pttbbs/pttbbs.mk
index 7944f956..6822c537 100644
--- a/pttbbs/pttbbs.mk
+++ b/pttbbs/pttbbs.mk
@@ -1,9 +1,10 @@
-# $Id: pttbbs.mk,v 1.4 2003/06/26 16:29:02 kcwu Exp $
+# $Id: pttbbs.mk,v 1.5 2003/06/28 08:55:40 kcwu Exp $
 # 定義基本初值
 BBSHOME?=	$(HOME)
 BBSHOME?=	/home/bbs
 OSTYPE?=	FreeBSD
 CC?=		gcc
+CCACHE!=	which ccache|sed -e 's/^.*\///'
 PTT_CFLAGS=	-Wall -pipe -DBBSHOME='"$(BBSHOME)"' -I../include
 PTT_LDFLAGS=	-pipe -Wall
 PTT_LIBS=	-lcrypt
-- 
cgit v1.2.3


From f8f95969d2bc64e6ccad3ba4f9784f1efe248d4a Mon Sep 17 00:00:00 2001
From: kcwu 
Date: Sat, 28 Jun 2003 09:27:15 +0000
Subject: correct message of last commit

git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@989 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
---
 pttbbs/mbbsd/announce.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/pttbbs/mbbsd/announce.c b/pttbbs/mbbsd/announce.c
index 02ea115d..b0130d92 100644
--- a/pttbbs/mbbsd/announce.c
+++ b/pttbbs/mbbsd/announce.c
@@ -1,4 +1,4 @@
-/* $Id: announce.c,v 1.28 2003/06/28 08:54:02 kcwu Exp $ */
+/* $Id: announce.c,v 1.29 2003/06/28 09:27:15 kcwu Exp $ */
 #include "bbs.h"
 
 #define PATHLEN     256
@@ -884,7 +884,8 @@ a_menu(char *maintitle, char *path, int lastlevel)
 #endif
 		snprintf(fname, sizeof(fname), "%s/%s", path, fhdr->filename);
 		if (*fhdr->filename == 'H' && fhdr->filename[1] == '.') {
-		  vmsg("不再支援 gopher mode, 請使用瀏覽器瀏覽 gopher://%s/1/",fhdr->filename);
+		  vmsg("不再支援 gopher mode, 請使用瀏覽器直接瀏覽");
+		  vmsg("gopher://%s/1/",fhdr->filename+2);
 		} else if (dashf(fname)) {
 		    int             more_result;
 
-- 
cgit v1.2.3


From 5be8cb8ed0ebffd4889e9dbbbe2c83dc6569f4f8 Mon Sep 17 00:00:00 2001
From: in2 
Date: Sun, 29 Jun 2003 06:06:17 +0000
Subject: border:0 for [img]

git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@990 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
---
 pttbbs/blog/blog.pl | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/pttbbs/blog/blog.pl b/pttbbs/blog/blog.pl
index 515c1e65..f64b6b5b 100755
--- a/pttbbs/blog/blog.pl
+++ b/pttbbs/blog/blog.pl
@@ -1,5 +1,5 @@
 #!/usr/bin/perl
-# $Id: blog.pl,v 1.24 2003/06/25 08:00:32 in2 Exp $
+# $Id: blog.pl,v 1.25 2003/06/29 06:06:17 in2 Exp $
 use CGI qw/:standard/;
 use lib qw/./;
 use LocalVars;
@@ -283,7 +283,7 @@ sub applyfilter($$)
 	    $c =~ s|\[email\](.*?)\[/email\]|$1|gsi;
 	    $c =~ s|\[b\](.*?)\[/b\]|$1|gsi;
 	    $c =~ s|\[i\](.*?)\[/i\]|$1|gsi;
-	    $c =~ s|\[img\](.*?)\[/img\]|(null)|gsi;
+	    $c =~ s|\[img\](.*?)\[/img\]|(null)|gsi;
 	}
     }
     return $c;
-- 
cgit v1.2.3


From e1a559eb449564b89c754e4dac612c8cfcee7072 Mon Sep 17 00:00:00 2001
From: in2 
Date: Sun, 29 Jun 2003 12:33:26 +0000
Subject: root overwrite

git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@991 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
---
 pttbbs/util/bbsctl.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/pttbbs/util/bbsctl.c b/pttbbs/util/bbsctl.c
index 8daa89c3..936547a3 100644
--- a/pttbbs/util/bbsctl.c
+++ b/pttbbs/util/bbsctl.c
@@ -33,6 +33,10 @@ int HaveBBSADM(void)
     gid_t   gids[NGROUPS_MAX];
     int     i, ngids;
     struct  group *gr; 
+
+    if( getuid() == 0 || geteuid() == 0 )
+	return 1;
+
     ngids = getgroups(NGROUPS_MAX, gids);
     if( (gr = getgrnam("bbsadm")) == NULL ){
 	puts("group bbsadm not found");
@@ -40,7 +44,7 @@ int HaveBBSADM(void)
     }
 
     for( i = 0 ; i < ngids ; ++i )
-	if( gr->gr_gid == gids[i] )
+	if( gr->gr_gid == (int)gids[i] )
 	    break;
 
     if( i == ngids ){
-- 
cgit v1.2.3


From ecdde03bbb9f1a0b6521e2579ac6e3ba35b2be6a Mon Sep 17 00:00:00 2001
From: victor 
Date: Tue, 1 Jul 2003 16:17:08 +0000
Subject: wrong station

git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@992 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
---
 pttbbs/sample/etc/MRT.map | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/pttbbs/sample/etc/MRT.map b/pttbbs/sample/etc/MRT.map
index a5615bbc..aac37d4f 100644
--- a/pttbbs/sample/etc/MRT.map
+++ b/pttbbs/sample/etc/MRT.map
@@ -46,9 +46,9 @@
                 歈                
     板橋○    頂溪○  ○台電大樓        ○麟光
                                   
-    府中○    景安○  ○公館            ○辛亥
+    府中○永安市場○  ○公館            ○辛亥
                                   
-    湳子○永安市場○  ○萬隆            ○萬芳醫院
+    湳子○    景安○  ○萬隆            ○萬芳醫院
                                   
     海山○  南勢角●  ○景美            耤堡龤堡龤
                                       萬  木  動
-- 
cgit v1.2.3


From d52d93b523043d20e7bdef723dc120f38eade56b Mon Sep 17 00:00:00 2001
From: victor 
Date: Tue, 1 Jul 2003 17:39:27 +0000
Subject: don't reduce bm's money in digest mode

git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@993 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
---
 pttbbs/mbbsd/bbs.c | 20 +++++++++++---------
 1 file changed, 11 insertions(+), 9 deletions(-)

diff --git a/pttbbs/mbbsd/bbs.c b/pttbbs/mbbsd/bbs.c
index b89cbbef..b5e5c454 100644
--- a/pttbbs/mbbsd/bbs.c
+++ b/pttbbs/mbbsd/bbs.c
@@ -1,4 +1,4 @@
-/* $Id: bbs.c,v 1.101 2003/06/28 08:47:45 kcwu Exp $ */
+/* $Id: bbs.c,v 1.102 2003/07/01 17:39:27 victor Exp $ */
 #include "bbs.h"
 
 static int recommend(int ent, fileheader_t * fhdr, char *direct);
@@ -1466,14 +1466,16 @@ del_post(int ent, fileheader_t * fhdr, char *direct)
 	    if (!not_owned && strcmp(currboard, "Test")) {
 		if (cuser.numposts)
 		    cuser.numposts--;
-		move(b_lines - 1, 0);
-		clrtoeol();
-		demoney(-fhdr->money);
-		passwd_update(usernum, &cuser);	/* post 數 */
-		prints("%s,您的文章減為 %d 篇,支付清潔費 %d 銀", msg_del_ok,
-		       cuser.numposts, fhdr->money);
-		refresh();
-		pressanykey();
+		if (!(currmode & MODE_DIGEST && is_BM(cuser.userid))){
+		    move(b_lines - 1, 0);
+		    clrtoeol();
+		    demoney(-fhdr->money);
+		    passwd_update(usernum, &cuser);	/* post 數 */
+		    prints("%s,您的文章減為 %d 篇,支付清潔費 %d 銀", msg_del_ok,
+			    cuser.numposts, fhdr->money);
+		    refresh();
+		    pressanykey();
+		}
 	    }
 	    return DIRCHANGED;
 	}
-- 
cgit v1.2.3


From ebdb6f330188744c189650e7315ebebfc1cc647f Mon Sep 17 00:00:00 2001
From: victor 
Date: Wed, 2 Jul 2003 08:04:01 +0000
Subject: stop at the right article after searching

git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@994 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
---
 pttbbs/mbbsd/read.c | 26 +++++++++++++++++++-------
 1 file changed, 19 insertions(+), 7 deletions(-)

diff --git a/pttbbs/mbbsd/read.c b/pttbbs/mbbsd/read.c
index 7ec54a9d..e66ab22c 100644
--- a/pttbbs/mbbsd/read.c
+++ b/pttbbs/mbbsd/read.c
@@ -1,4 +1,4 @@
-/* $Id: read.c,v 1.24 2003/06/26 16:27:12 kcwu Exp $ */
+/* $Id: read.c,v 1.25 2003/07/02 08:04:01 victor Exp $ */
 #include "bbs.h"
 
 static fileheader_t *headers = NULL;
@@ -465,9 +465,9 @@ select_read(keeploc_t * locmem, int sr_mode)
 	strlcpy(buf3, "Re: ", sizeof(buf3));
 	query = buf3;
     } 
-	else if (sr_mode == RS_THREAD) {
-	
-	} else {
+    else if (sr_mode == RS_THREAD) {
+    
+    } else {
 	char            buff[80];
 	char            newdata[35];
 
@@ -548,7 +548,7 @@ select_read(keeploc_t * locmem, int sr_mode)
 	    strlcpy(currdirect, fpath, sizeof(currdirect));
 	}
     }
-    return st.st_size;
+    return READ_REDRAW;
 }
 
 static int
@@ -560,8 +560,20 @@ i_read_key(onekey_t * rcmdlist, keeploc_t * locmem, int ch, int bid)
     case 'q':
     case 'e':
     case KEY_LEFT:
-	return (currmode & MODE_SELECT) ? board_select() :
-	    (currmode & MODE_ETC) ? board_etc() :
+	if(currmode & MODE_SELECT){
+	    char genbuf[256];
+	    fileheader_t *fhdr = &headers[locmem->crs_ln - locmem->top_ln];
+
+	    board_select();
+	    setbdir(genbuf, currboard);
+
+	    locmem = getkeep(genbuf, 0, 1);
+	    locmem->crs_ln = getindex(genbuf, fhdr->filename, sizeof(fileheader_t));
+	    locmem->top_ln = locmem->crs_ln - p_lines + 1;
+
+	    return NEWDIRECT;
+	}
+	return (currmode & MODE_ETC) ? board_etc() :
 	    (currmode & MODE_DIGEST) ? board_digest() : DOQUIT;
     case Ctrl('L'):
 	redoscr();
-- 
cgit v1.2.3


From d4aaf1614a98ef8816d00c7d3a0a59850c992564 Mon Sep 17 00:00:00 2001
From: ptt 
Date: Wed, 2 Jul 2003 13:53:10 +0000
Subject: *** empty log message ***

git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@995 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
---
 pttbbs/util/udnnews.pl | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/pttbbs/util/udnnews.pl b/pttbbs/util/udnnews.pl
index 07c49d4b..ba0fc072 100644
--- a/pttbbs/util/udnnews.pl
+++ b/pttbbs/util/udnnews.pl
@@ -39,8 +39,8 @@ sub getudnnewscontent($)
     my($url) = @_;
     my($buf, $content, $ret);
     $buf = `$LYNX -source '$url'`;
-    ($content) = $buf =~ m|


(.*?)|s; - ($content) = $buf =~ m|

(.*?)|s if( !$content ); + ($content) = $buf =~ m|(.*?)|s; +# ($content) = $buf =~ m|

(.*?)|s if( !$content ); $content =~ s/
/\n/g; $content =~ s/

/\n/gi; $content =~ s/<.*?>//g; @@ -105,10 +105,11 @@ sub postout { my($param) = @_; return if( !$param->{title} ); - open FH, ">/tmp/postout.$$"; - print FH $param->{content}; - close FH; +# open FH, ">/tmp/postout.$$"; +# print FH $param->{content}; +print "$param->{content}"; +# close FH; - system("bin/post '$param->{brdname}' '$param->{title}' '$param->{owner}' /tmp/postout.$$"); - unlink "/tmp/postout.$$"; +# system("bin/post '$param->{brdname}' '$param->{title}' '$param->{owner}' /tmp/postout.$$"); +# unlink "/tmp/postout.$$"; } -- cgit v1.2.3 From 49225a6929ff3bd8c4730fc14ebb3d09e88b61a2 Mon Sep 17 00:00:00 2001 From: ptt Date: Wed, 2 Jul 2003 13:55:21 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@996 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/udnnews.pl | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/pttbbs/util/udnnews.pl b/pttbbs/util/udnnews.pl index ba0fc072..99d690c3 100644 --- a/pttbbs/util/udnnews.pl +++ b/pttbbs/util/udnnews.pl @@ -105,11 +105,11 @@ sub postout { my($param) = @_; return if( !$param->{title} ); -# open FH, ">/tmp/postout.$$"; -# print FH $param->{content}; -print "$param->{content}"; -# close FH; + open FH, ">/tmp/postout.$$"; + print FH $param->{content}; +#print "$param->{content}"; + close FH; -# system("bin/post '$param->{brdname}' '$param->{title}' '$param->{owner}' /tmp/postout.$$"); -# unlink "/tmp/postout.$$"; + system("bin/post '$param->{brdname}' '$param->{title}' '$param->{owner}' /tmp/postout.$$"); + unlink "/tmp/postout.$$"; } -- cgit v1.2.3 From d3efe45a3e241e63eb4fa946de4b619ccc622332 Mon Sep 17 00:00:00 2001 From: ptt Date: Wed, 2 Jul 2003 14:09:48 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@997 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/udnnews.pl | 61 +++++++++++++++++++++++++++----------------------- 1 file changed, 33 insertions(+), 28 deletions(-) diff --git a/pttbbs/util/udnnews.pl b/pttbbs/util/udnnews.pl index 99d690c3..b09944b0 100644 --- a/pttbbs/util/udnnews.pl +++ b/pttbbs/util/udnnews.pl @@ -20,9 +20,9 @@ chdir '/home/bbs'; getudnnewstitle(\@titles); foreach( @titles ){ postout({brdname => 'udnnews', - title => strreplace(FormatChinese($_->[1])), - owner => 'udnnews.', - content => getudnnewscontent("http://www.udn.com/NEWS/FOCUSNEWS/$_->[0]")}); + title => strreplace(FormatChinese($_->[1])), + owner => 'udnnews.', + content => getudnnewscontent("http://www.udn.com/NEWS/FOCUSNEWS/$_->[0]")}); } sub strreplace @@ -50,11 +50,16 @@ sub getudnnewscontent($) $content = strreplace($content); undef $ret; foreach( split(/\n/, $content) ){ - s/ //g; - $ret .= FormatChinese($_, 60). "\n" if( $_ ); + s/ //g; + $ret .= FormatChinese($_, 60). "\n" if( $_ ); } - return "※ [轉錄自 $url ]\n\n$ret\n\n". - "--\n感謝 http://www.udn.com/ 熱情贊助"; + return + "作者: udnnews.(聯合新聞) 看板: udnnews". + "標題: ". + "時間: 即時". + "※ [轉錄自 $url ]\n\n$ret\n\n". + "--\n$param->{title}\n 聯合新聞網 http://www.udn.com/ 獨家授權批踢踢實業坊轉載 ". + "\n 未經允許請勿擅自使用 "; } sub getudnnewstitle($) @@ -63,9 +68,9 @@ sub getudnnewstitle($) my($url, $title); open FH, "$LYNX -source http://www.udn.com/NEWS/FOCUSNEWS/ | $GREP '' |"; while( ){ - ($url, $title) = $_ =~ m|(.*?)|; - $title =~ s/<.*?>//g; - push @{$ra_titles}, [$url, $title]; + ($url, $title) = $_ =~ m|(.*?)|; + $title =~ s/<.*?>//g; + push @{$ra_titles}, [$url, $title]; } close FH; return @{$ra_titles}; @@ -77,26 +82,26 @@ sub FormatChinese my($i, $ret, $count, $s); return if( !$str ); for( $i = 0 ; $i < length($str) ; ++$i ){ - if( ord(substr($str, $i, 1)) > 127 ){ - $ret .= substr($str, $i, 2); - ++$i; - } - else{ - for( $count = 0, $s = $i ; $i < length($str) ; ++$i, ++$count ){ - last if( ord(substr($str, $i, 1)) > 127 ); - } - --$i; - $ret .= ' ' if( $count % 2 == 1); - $ret .= substr($str, $s, $count); - } + if( ord(substr($str, $i, 1)) > 127 ){ + $ret .= substr($str, $i, 2); + ++$i; + } + else{ + for( $count = 0, $s = $i ; $i < length($str) ; ++$i, ++$count ){ + last if( ord(substr($str, $i, 1)) > 127 ); + } + --$i; + $ret .= ' ' if( $count % 2 == 1); + $ret .= substr($str, $s, $count); + } } if( $length ){ - $str = $ret; - undef $ret; - while( $str ){ - $ret .= substr($str, 0, $length)."\n"; - $str = substr($str, $length); - } + $str = $ret; + undef $ret; + while( $str ){ + $ret .= substr($str, 0, $length)."\n"; + $str = substr($str, $length); + } } return $ret; } -- cgit v1.2.3 From 03323031cd073090a1c57e945a075653dfafdc2d Mon Sep 17 00:00:00 2001 From: ptt Date: Wed, 2 Jul 2003 14:12:47 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@998 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/udnnews.pl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pttbbs/util/udnnews.pl b/pttbbs/util/udnnews.pl index b09944b0..79483503 100644 --- a/pttbbs/util/udnnews.pl +++ b/pttbbs/util/udnnews.pl @@ -58,7 +58,7 @@ sub getudnnewscontent($) "標題: ". "時間: 即時". "※ [轉錄自 $url ]\n\n$ret\n\n". - "--\n$param->{title}\n 聯合新聞網 http://www.udn.com/ 獨家授權批踢踢實業坊轉載 ". + "--\n\n 聯合新聞網 http://www.udn.com/ 獨家授權批踢踢實業坊 ". "\n 未經允許請勿擅自使用 "; } -- cgit v1.2.3 From c33da22fa99b6d77a0ed164bae2af99db4ffb092 Mon Sep 17 00:00:00 2001 From: ptt Date: Wed, 2 Jul 2003 14:17:05 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@999 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/udnnews.pl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pttbbs/util/udnnews.pl b/pttbbs/util/udnnews.pl index 79483503..871b33b3 100644 --- a/pttbbs/util/udnnews.pl +++ b/pttbbs/util/udnnews.pl @@ -54,9 +54,9 @@ sub getudnnewscontent($) $ret .= FormatChinese($_, 60). "\n" if( $_ ); } return - "作者: udnnews.(聯合新聞) 看板: udnnews". - "標題: ". - "時間: 即時". + "作者: udnnews.(聯合新聞) 看板: udnnews\n". + "標題: \n". + "時間: 即時\n". "※ [轉錄自 $url ]\n\n$ret\n\n". "--\n\n 聯合新聞網 http://www.udn.com/ 獨家授權批踢踢實業坊 ". "\n 未經允許請勿擅自使用 "; -- cgit v1.2.3 From acaf8e6819cb70e431e5f8cba9667bc98fac6f6c Mon Sep 17 00:00:00 2001 From: victor Date: Thu, 3 Jul 2003 03:26:34 +0000 Subject: fix '/' in fav mode git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@1000 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/board.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/pttbbs/mbbsd/board.c b/pttbbs/mbbsd/board.c index 845134fc..7b959286 100644 --- a/pttbbs/mbbsd/board.c +++ b/pttbbs/mbbsd/board.c @@ -1,4 +1,4 @@ -/* $Id: board.c,v 1.130 2003/06/09 03:18:17 victor Exp $ */ +/* $Id: board.c,v 1.131 2003/07/03 03:26:34 victor Exp $ */ #include "bbs.h" #define BRC_STRLEN 15 /* Length of board name */ #define BRC_MAXSIZE 24576 @@ -208,10 +208,14 @@ brc_unread(char *fname, int bnum, int *blist) return 0; } -#define BRD_UNREAD 1 -#define BRD_FAV 2 -#define BRD_LINE 4 -#define BRD_TAG 8 +#define BRD_UNREAD 1 +#define BRD_FAV 2 +#define BRD_LINE 4 +#define BRD_TAG 8 +#define BRD_GRP_HEADER 16 + +#define MAX_GRP_BRD 16 +#define MAX_GRP #define FAVNB ".favnb" #define FAV3 ".fav3" @@ -762,13 +766,13 @@ load_boards(char *key) nbrd = (boardstat_t *)malloc(sizeof(boardstat_t) * fav->nDatas); for( i = 0 ; i < fav->nDatas ; ++i ){ if( fav->b[i].attr & BRD_FAV ){ - if( fav->b[i].attr & BRD_LINE ) + if( fav->b[i].attr & BRD_LINE && !key[0]) addnewbrdstat(fav->b[i].bid - 1, BRD_FAV | BRD_LINE); else{ bptr = &bcache[ fav->b[i].bid - 1 ]; - if( (state = Ben_Perm(bptr)) ) + if( (state = Ben_Perm(bptr)) && (!key[0] || strcasestr(bptr->title, key))) addnewbrdstat(fav->b[i].bid - 1, state); - } + } } } byMALLOC = 0; -- cgit v1.2.3 From 89d453055f6fac7fd67c0f7148d429f51356e6eb Mon Sep 17 00:00:00 2001 From: victor Date: Thu, 3 Jul 2003 03:37:39 +0000 Subject: fix bug, to move fav outside the fav mode (thanks lihgong.bbs@ptt2) git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@1001 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/board.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pttbbs/mbbsd/board.c b/pttbbs/mbbsd/board.c index 7b959286..415dabe1 100644 --- a/pttbbs/mbbsd/board.c +++ b/pttbbs/mbbsd/board.c @@ -1,4 +1,4 @@ -/* $Id: board.c,v 1.131 2003/07/03 03:26:34 victor Exp $ */ +/* $Id: board.c,v 1.132 2003/07/03 03:37:39 victor Exp $ */ #include "bbs.h" #define BRC_STRLEN 15 /* Length of board name */ #define BRC_MAXSIZE 24576 @@ -1316,9 +1316,9 @@ choose_board(int newflag) } break; case 'M': - if (HAS_PERM(PERM_BASIC)) { + if (HAS_PERM(PERM_BASIC) && class_bid == 0 && yank_flag == 0){ imovefav(num); - head = 9999; + head = 9999; } break; case 'K': -- cgit v1.2.3 From 7dd329b898761fd898fdeba082f9083625390506 Mon Sep 17 00:00:00 2001 From: in2 Date: Thu, 3 Jul 2003 05:49:06 +0000 Subject: move BBSFileHeader.pm to util/ git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@1002 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/blog/BBSFileHeader.pm | 56 ------------------------------------------ pttbbs/util/BBSFileHeader.pm | 58 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+), 56 deletions(-) delete mode 100644 pttbbs/blog/BBSFileHeader.pm create mode 100644 pttbbs/util/BBSFileHeader.pm diff --git a/pttbbs/blog/BBSFileHeader.pm b/pttbbs/blog/BBSFileHeader.pm deleted file mode 100644 index 4865da8b..00000000 --- a/pttbbs/blog/BBSFileHeader.pm +++ /dev/null @@ -1,56 +0,0 @@ -#!/usr/bin/perl -package BBSFileHeader; -use strict; -use IO::Handle; -use Data::Dumper; - -use fields qw/dir fh cache/; - -sub TIEHASH -{ - my($class, $dir) = @_; - my $self = fields::new($class); - - open $self->{fh}, "<$dir/.DIR"; - return undef if( !$self->{fh} ); - - $self->{dir} = $dir; - return $self; -} - -sub FETCH -{ - my($self, $k) = @_; - - return $self->{dir} if( $k eq 'dir' ); - return ((-s "$self->{dir}/.DIR") / 128) if( $k eq 'num' ); - - my($num, $key) = $k =~ /(.*)\.(.*)/; - my($t, %h); - - $num += $self->FETCH('num') if( $num < 0 ); - - return $self->{cache}{$num}{$key} if( $self->{cache}{$num}{$key} ); - - seek($self->{fh}, $num * 128, 0); - $self->{fh}->read($t, 128); - - if( $key eq 'isdir' ){ - my $fn = "$self->{dir}/" . $self->FETCH("$num.filename"); - return (-d $fn); - } - elsif( $key eq 'content' ){ - my $fn = "$self->{dir}/" . $self->FETCH("$num.filename"); - return `/bin/cat $fn`; - } - else{ - ($h{filename}, $h{recommend}, $h{owner}, $h{date}, $h{title}) = - unpack('Z33cZ14Z6Z65', $t); - $h{title} = substr($h{title}, 3); - $self->{cache}{$num}{$_} = $h{$_} - foreach( 'filename', 'owner', 'date', 'title' ); - return $h{$key}; - } -} - -1; diff --git a/pttbbs/util/BBSFileHeader.pm b/pttbbs/util/BBSFileHeader.pm new file mode 100644 index 00000000..e9cf3cdd --- /dev/null +++ b/pttbbs/util/BBSFileHeader.pm @@ -0,0 +1,58 @@ +#!/usr/bin/perl +package BBSFileHeader; +use strict; +use IO::Handle; +use Data::Dumper; + +use fields qw/dir fh cache/; + +sub TIEHASH +{ + my($class, $dir) = @_; + my $self = fields::new($class); + + open $self->{fh}, "<$dir/.DIR"; + return undef if( !$self->{fh} ); + + $self->{dir} = $dir; + return $self; +} + +sub FETCH +{ + my($self, $k) = @_; + + return $self->{dir} if( $k eq 'dir' ); + return ((-s "$self->{dir}/.DIR") / 128) if( $k eq 'num' ); + + my($num, $key) = $k =~ /(.*)\.(.*)/; + my($t, %h); + + $num += $self->FETCH('num') if( $num < 0 ); + + return $self->{cache}{$num}{$key} if( $self->{cache}{$num}{$key} ); + + seek($self->{fh}, $num * 128, 0); + $self->{fh}->read($t, 128); + + if( $key eq 'isdir' ){ + my $fn = "$self->{dir}/" . $self->FETCH("$num.filename"); + return (-d $fn); + } + elsif( $key eq 'content' ){ + my $fn = "$self->{dir}/" . $self->FETCH("$num.filename"); + return `/bin/cat $fn`; + } + else{ + ($h{filename}, $h{recommend}, $h{owner}, $h{date}, $h{title}, + $h{money}, undef, $h{filemode}) = + unpack('Z33cZ14Z6Z65iCC', $t); + $h{title} = substr($h{title}, 3); + $self->{cache}{$num}{$_} = $h{$_} + foreach( 'filename', 'owner', 'date', + 'title', 'money', 'filemode' ); + return $h{$key}; + } +} + +1; -- cgit v1.2.3 From f7441119f0e3051bf21057d2bf9367260033daf5 Mon Sep 17 00:00:00 2001 From: in2 Date: Thu, 3 Jul 2003 05:49:45 +0000 Subject: add manbuilder.pl git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@1003 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/staticweb/manbuilder.pl | 59 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100755 pttbbs/staticweb/manbuilder.pl diff --git a/pttbbs/staticweb/manbuilder.pl b/pttbbs/staticweb/manbuilder.pl new file mode 100755 index 00000000..ecb0972e --- /dev/null +++ b/pttbbs/staticweb/manbuilder.pl @@ -0,0 +1,59 @@ +#!/usr/bin/perl +# $Id: manbuilder.pl,v 1.1 2003/07/03 05:49:45 in2 Exp $ +use lib '/home/bbs/bin/'; +use strict; +use OurNet::FuzzyIndex; +use Getopt::Std; +use DB_File; +use BBSFileHeader; +use Data::Serializer; + +my(%db, %idx, $serial); + +sub main +{ + die usage() unless( @ARGV ); + + $serial = Data::Serializer->new(serializer => 'Storable', + digester => 'MD5', + compress => 0, + ); + + foreach( @ARGV ){ + tie %db, 'DB_File', "$_.db", O_CREAT | O_RDWR, 0666, $DB_HASH; + build("/home/bbs/man/boards/".substr($_, 0, 1)."/$_", ''); + untie %db; + } +} + +sub build($$) +{ + my($basedir, $doffset) = @_; + my(%bfh, $fn, @tdir); + + print "$basedir, $doffset\n"; + tie %bfh, 'BBSFileHeader', $basedir; + foreach( 0..($bfh{num} - 1) ){ + next if( $bfh{"$_.filemode"} & 32 ); # skip HIDDEN + + $fn = $bfh{"$_.filename"}; + if( $bfh{"$_.isdir"} ){ + push @tdir, ["$doffset/$fn/", $bfh{"$_.title"}]; + build("$basedir/$fn", "$doffset/$fn"); + } + else{ + push @tdir, ["$doffset/$fn", $bfh{"$_.title"}]; + $db{"$doffset/$fn"} = $bfh{"$_.content"}; + } + } + $db{"$doffset/"} = $serial->serialize(\@tdir); +} + +sub usage +{ + print ("$0 boardname ...\n"); + exit(0); +} + +main(); +1; -- cgit v1.2.3 From 2e21f11c011f80278f812f966bb468292e45e512 Mon Sep 17 00:00:00 2001 From: in2 Date: Thu, 3 Jul 2003 06:50:54 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@1004 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/staticweb/man.pl | 67 ++++++++++++++++++++++++++++++++++++++++++ pttbbs/staticweb/manbuilder.pl | 11 +++++-- 2 files changed, 76 insertions(+), 2 deletions(-) create mode 100755 pttbbs/staticweb/man.pl diff --git a/pttbbs/staticweb/man.pl b/pttbbs/staticweb/man.pl new file mode 100755 index 00000000..307108c7 --- /dev/null +++ b/pttbbs/staticweb/man.pl @@ -0,0 +1,67 @@ +#!/usr/bin/perl +# $Id: man.pl,v 1.1 2003/07/03 06:49:23 in2 Exp $ +use CGI qw/:standard/; +use lib qw/./; +use LocalVars; +use DB_File; +use strict; +use Data::Dumper; +use Date::Calc qw(:all); +use Template; +use HTML::Calendar::Simple; +use OurNet::FuzzyIndex; +use Data::Serializer; +use vars qw/%db $brdname $fpath/; + +sub main +{ + my($tmpl, $rh); + + if( !(($brdname, $fpath) = $ENV{PATH_INFO} =~ m|^/([\w\-]+?)(/.*)|) || + !(tie %db, 'DB_File', + "$MANDATA/$brdname.db", O_RDONLY, 0666, $DB_HASH) ){ + return redirect("/man.pl/$1/") + if( $ENV{PATH_INFO} =~ m|^/([\w\-]+?)$| ); + print header(-status => 404); + return; + } + + charset(''); + print header(); + + $rh = (($fpath =~ m|/$|) ? dirmode($fpath) : articlemode($fpath)); + $tmpl = Template->new({INCLUDE_PATH => '.', + ABSOLUTE => 0, + RELATIVE => 0, + RECURSION => 0, + EVAL_PERL => 0}); + $tmpl->process($rh->{tmpl}, $rh); +} + +sub dirmode +{ + my(%th); + my $serial = Data::Serializer->new(serializer => 'Storable', + digester => 'MD5', + compress => 0, + ); + foreach( @{$serial->deserialize($db{$fpath})} ){ + push @{$th{dat}}, {isdir => (($_->[0] =~ m|/$|) ? 1 : 0), + fn => "/man.pl/$brdname$_->[0]", + title => $_->[1]}; + } + + $th{tmpl} = 'dir.html'; + return \%th; +} + +sub articlemode +{ + my(%th); + $th{tmpl} = 'article.html'; + $th{content} = $db{$fpath}; + return \%th; +} + +main(); +1; diff --git a/pttbbs/staticweb/manbuilder.pl b/pttbbs/staticweb/manbuilder.pl index ecb0972e..3ae5b22a 100755 --- a/pttbbs/staticweb/manbuilder.pl +++ b/pttbbs/staticweb/manbuilder.pl @@ -1,5 +1,5 @@ #!/usr/bin/perl -# $Id: manbuilder.pl,v 1.1 2003/07/03 05:49:45 in2 Exp $ +# $Id: manbuilder.pl,v 1.2 2003/07/03 06:50:54 in2 Exp $ use lib '/home/bbs/bin/'; use strict; use OurNet::FuzzyIndex; @@ -43,7 +43,14 @@ sub build($$) } else{ push @tdir, ["$doffset/$fn", $bfh{"$_.title"}]; - $db{"$doffset/$fn"} = $bfh{"$_.content"}; + my $c = $bfh{"$_.content"}; + $c =~ s/\/>/gs; + $c =~ s/\"/"/gs; + $c =~ s/\'/'/gs; + $c =~ s/ / /gs; + $c =~ s/\n/
\n/gs; + $db{"$doffset/$fn"} = $c; } } $db{"$doffset/"} = $serial->serialize(\@tdir); -- cgit v1.2.3 From 3b24526b69828d742f8325575613f31ef51551a8 Mon Sep 17 00:00:00 2001 From: in2 Date: Thu, 3 Jul 2003 06:57:35 +0000 Subject: FuzzyIndex support git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@1005 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/staticweb/manbuilder.pl | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/pttbbs/staticweb/manbuilder.pl b/pttbbs/staticweb/manbuilder.pl index 3ae5b22a..872506f2 100755 --- a/pttbbs/staticweb/manbuilder.pl +++ b/pttbbs/staticweb/manbuilder.pl @@ -1,5 +1,5 @@ #!/usr/bin/perl -# $Id: manbuilder.pl,v 1.2 2003/07/03 06:50:54 in2 Exp $ +# $Id: manbuilder.pl,v 1.3 2003/07/03 06:57:35 in2 Exp $ use lib '/home/bbs/bin/'; use strict; use OurNet::FuzzyIndex; @@ -8,7 +8,7 @@ use DB_File; use BBSFileHeader; use Data::Serializer; -my(%db, %idx, $serial); +my(%db, $idx, $serial); sub main { @@ -21,6 +21,7 @@ sub main foreach( @ARGV ){ tie %db, 'DB_File', "$_.db", O_CREAT | O_RDWR, 0666, $DB_HASH; + $idx = OurNet::FuzzyIndex->new("$_.idx"); build("/home/bbs/man/boards/".substr($_, 0, 1)."/$_", ''); untie %db; } @@ -31,7 +32,7 @@ sub build($$) my($basedir, $doffset) = @_; my(%bfh, $fn, @tdir); - print "$basedir, $doffset\n"; + print "building $basedir\n"; tie %bfh, 'BBSFileHeader', $basedir; foreach( 0..($bfh{num} - 1) ){ next if( $bfh{"$_.filemode"} & 32 ); # skip HIDDEN @@ -44,6 +45,8 @@ sub build($$) else{ push @tdir, ["$doffset/$fn", $bfh{"$_.title"}]; my $c = $bfh{"$_.content"}; + $idx->insert("$doffset/$fn", $c); + $c =~ s/\/>/gs; $c =~ s/\"/"/gs; -- cgit v1.2.3 From e99a1e6546fab01ff20aac9c97f4ce5b3a0f77bc Mon Sep 17 00:00:00 2001 From: in2 Date: Thu, 3 Jul 2003 07:22:24 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@1006 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/staticweb/manbuilder.pl | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/pttbbs/staticweb/manbuilder.pl b/pttbbs/staticweb/manbuilder.pl index 872506f2..1e9e95d7 100755 --- a/pttbbs/staticweb/manbuilder.pl +++ b/pttbbs/staticweb/manbuilder.pl @@ -1,5 +1,5 @@ #!/usr/bin/perl -# $Id: manbuilder.pl,v 1.3 2003/07/03 06:57:35 in2 Exp $ +# $Id: manbuilder.pl,v 1.4 2003/07/03 07:22:24 in2 Exp $ use lib '/home/bbs/bin/'; use strict; use OurNet::FuzzyIndex; @@ -46,13 +46,6 @@ sub build($$) push @tdir, ["$doffset/$fn", $bfh{"$_.title"}]; my $c = $bfh{"$_.content"}; $idx->insert("$doffset/$fn", $c); - - $c =~ s/\/>/gs; - $c =~ s/\"/"/gs; - $c =~ s/\'/'/gs; - $c =~ s/ / /gs; - $c =~ s/\n/
\n/gs; $db{"$doffset/$fn"} = $c; } } -- cgit v1.2.3 From 85242c916849264154d18aa4c9493f435e915e10 Mon Sep 17 00:00:00 2001 From: in2 Date: Thu, 3 Jul 2003 12:39:05 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@1007 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/staticweb/article.html | 17 +++++++++++++++++ pttbbs/staticweb/dir.html | 43 +++++++++++++++++++++++++++++++++++++++++++ pttbbs/staticweb/header.html | 15 +++++++++++++++ pttbbs/staticweb/index.html | 26 ++++++++++++++++++++++++++ pttbbs/staticweb/index.pl | 32 ++++++++++++++++++++++++++++++++ pttbbs/staticweb/man.pl | 9 +++++++-- pttbbs/staticweb/styles.css | 19 +++++++++++++++++++ 7 files changed, 159 insertions(+), 2 deletions(-) create mode 100644 pttbbs/staticweb/article.html create mode 100644 pttbbs/staticweb/dir.html create mode 100644 pttbbs/staticweb/header.html create mode 100644 pttbbs/staticweb/index.html create mode 100755 pttbbs/staticweb/index.pl create mode 100644 pttbbs/staticweb/styles.css diff --git a/pttbbs/staticweb/article.html b/pttbbs/staticweb/article.html new file mode 100644 index 00000000..9cfee318 --- /dev/null +++ b/pttbbs/staticweb/article.html @@ -0,0 +1,17 @@ +[% INCLUDE header.html %] + +
+看板: [% brdname %]
回上頁
+
+
+
+[% content %]
+
+
+
+回上頁
+批踢踢實業坊 (PttWeb) +
+ + + diff --git a/pttbbs/staticweb/dir.html b/pttbbs/staticweb/dir.html new file mode 100644 index 00000000..fe4392ba --- /dev/null +++ b/pttbbs/staticweb/dir.html @@ -0,0 +1,43 @@ +[% INCLUDE header.html %] + + + + + + + + +
+ +
+網頁版精華區首頁 +[% brdname %]精華區首頁 +批踢踢部落格 +
+看板名稱: [% brdname %] +
+
+[% IF !isroot %] +返回上一層
+[% END %] + +[% FOREACH x=dat %] + + +[% x.title %]
+[% END %] +
+
+
+在這個精華區內翻弄 (under construction) + + +
+
+批踢踢實業坊 (PttWeb) +
+ + diff --git a/pttbbs/staticweb/header.html b/pttbbs/staticweb/header.html new file mode 100644 index 00000000..465e9ff7 --- /dev/null +++ b/pttbbs/staticweb/header.html @@ -0,0 +1,15 @@ + + + + + + 批踢踢實業坊 + + + + + + diff --git a/pttbbs/staticweb/index.html b/pttbbs/staticweb/index.html new file mode 100644 index 00000000..d0722654 --- /dev/null +++ b/pttbbs/staticweb/index.html @@ -0,0 +1,26 @@ +[% INCLUDE header.html %] + + + + + + + +
+ +
+批踢踢實業坊之精華區(experimental)
+目前提供下列精華區資料:
+
+[% FOREACH x=dat %] +[% x.brdname %]
+[% END %] +
+
+批踢踢實業坊 (PttWeb) +
+ + diff --git a/pttbbs/staticweb/index.pl b/pttbbs/staticweb/index.pl new file mode 100755 index 00000000..ea48b874 --- /dev/null +++ b/pttbbs/staticweb/index.pl @@ -0,0 +1,32 @@ +#!/usr/bin/perl +# $Id: index.pl,v 1.1 2003/07/03 12:39:05 in2 Exp $ +use lib qw/./; +use LocalVars; +use CGI qw/:standard/; +use strict; +use Template; + +sub main +{ + my($tmpl, %rh); + + charset(''); + print header(); + + foreach( ){ + s/.*\///; + s/\.db//; + push @{$rh{dat}}, {brdname => $_}; + } + $tmpl = Template->new({INCLUDE_PATH => '.', + ABSOLUTE => 0, + RELATIVE => 0, + RECURSION => 0, + EVAL_PERL => 0, + COMPILE_EXT => '.tmpl', + COMPILE_DIR => $MANCACHE}); + $tmpl->process('index.html', \%rh); +} + +main(); +1; diff --git a/pttbbs/staticweb/man.pl b/pttbbs/staticweb/man.pl index 307108c7..db5b84d5 100755 --- a/pttbbs/staticweb/man.pl +++ b/pttbbs/staticweb/man.pl @@ -1,5 +1,5 @@ #!/usr/bin/perl -# $Id: man.pl,v 1.1 2003/07/03 06:49:23 in2 Exp $ +# $Id: man.pl,v 1.2 2003/07/03 12:39:05 in2 Exp $ use CGI qw/:standard/; use lib qw/./; use LocalVars; @@ -30,11 +30,14 @@ sub main print header(); $rh = (($fpath =~ m|/$|) ? dirmode($fpath) : articlemode($fpath)); + $rh->{brdname} = $brdname; $tmpl = Template->new({INCLUDE_PATH => '.', ABSOLUTE => 0, RELATIVE => 0, RECURSION => 0, - EVAL_PERL => 0}); + EVAL_PERL => 0, + COMPILE_EXT => '.tmpl', + COMPILE_DIR => $MANCACHE}); $tmpl->process($rh->{tmpl}, $rh); } @@ -52,6 +55,7 @@ sub dirmode } $th{tmpl} = 'dir.html'; + $th{isroot} = ($fpath eq '/') ? 1 : 0; return \%th; } @@ -60,6 +64,7 @@ sub articlemode my(%th); $th{tmpl} = 'article.html'; $th{content} = $db{$fpath}; + $th{content} =~ s/\033\[.*?m//g; return \%th; } diff --git a/pttbbs/staticweb/styles.css b/pttbbs/staticweb/styles.css new file mode 100644 index 00000000..973c6ec7 --- /dev/null +++ b/pttbbs/staticweb/styles.css @@ -0,0 +1,19 @@ +#banner { + font-family: georgia, verdana, arial, sans-serif; + color: #FFFFFF; + font-size: 20px; + font-weight: bold; + + padding: 8px 8px 8px 8px; + border: none; +} + +A:link {color: #FFFFFF; text-decoration:none;} +A:active {color: #CCFFCC; text-decoration:none;} +A:visited {color: #FFFFCC; text-decoration:none;} +A:hover {background: #555555;} + +body { + background: #000000; + color: #FFFFFF; +} \ No newline at end of file -- cgit v1.2.3 From 3fa7fa5cbc0f9878179414f74346df169f1c4f0a Mon Sep 17 00:00:00 2001 From: in2 Date: Thu, 3 Jul 2003 13:06:56 +0000 Subject: add title git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@1008 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/staticweb/manbuilder.pl | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/pttbbs/staticweb/manbuilder.pl b/pttbbs/staticweb/manbuilder.pl index 1e9e95d7..e7a0f46e 100755 --- a/pttbbs/staticweb/manbuilder.pl +++ b/pttbbs/staticweb/manbuilder.pl @@ -1,5 +1,5 @@ #!/usr/bin/perl -# $Id: manbuilder.pl,v 1.4 2003/07/03 07:22:24 in2 Exp $ +# $Id: manbuilder.pl,v 1.5 2003/07/03 13:06:56 in2 Exp $ use lib '/home/bbs/bin/'; use strict; use OurNet::FuzzyIndex; @@ -39,13 +39,15 @@ sub build($$) $fn = $bfh{"$_.filename"}; if( $bfh{"$_.isdir"} ){ - push @tdir, ["$doffset/$fn/", $bfh{"$_.title"}]; + push @tdir, ["$doffset/$fn/", # 目錄結尾要加 / + $db{"title-$doffset/$fn/"} = $bfh{"$_.title"}]; build("$basedir/$fn", "$doffset/$fn"); } else{ - push @tdir, ["$doffset/$fn", $bfh{"$_.title"}]; + push @tdir, ["$doffset/$fn", + $db{"title-$doffset/$fn/"} = $bfh{"$_.title"}]; my $c = $bfh{"$_.content"}; - $idx->insert("$doffset/$fn", $c); + $idx->insert("$doffset/$fn", $bfh{"$_.title"}. "\n$c"); $db{"$doffset/$fn"} = $c; } } -- cgit v1.2.3 From 009f0b469857e692b4185f072d052998019a7e7f Mon Sep 17 00:00:00 2001 From: in2 Date: Thu, 3 Jul 2003 13:38:53 +0000 Subject: bug fix, -n git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@1009 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/staticweb/manbuilder.pl | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/pttbbs/staticweb/manbuilder.pl b/pttbbs/staticweb/manbuilder.pl index e7a0f46e..ed15d57e 100755 --- a/pttbbs/staticweb/manbuilder.pl +++ b/pttbbs/staticweb/manbuilder.pl @@ -1,5 +1,5 @@ #!/usr/bin/perl -# $Id: manbuilder.pl,v 1.5 2003/07/03 13:06:56 in2 Exp $ +# $Id: manbuilder.pl,v 1.6 2003/07/03 13:38:53 in2 Exp $ use lib '/home/bbs/bin/'; use strict; use OurNet::FuzzyIndex; @@ -12,7 +12,7 @@ my(%db, $idx, $serial); sub main { - die usage() unless( @ARGV ); + die usage() unless( getopts('n') || !@ARGV ); $serial = Data::Serializer->new(serializer => 'Storable', digester => 'MD5', @@ -45,7 +45,7 @@ sub build($$) } else{ push @tdir, ["$doffset/$fn", - $db{"title-$doffset/$fn/"} = $bfh{"$_.title"}]; + $db{"title-$doffset/$fn"} = $bfh{"$_.title"}]; my $c = $bfh{"$_.content"}; $idx->insert("$doffset/$fn", $bfh{"$_.title"}. "\n$c"); $db{"$doffset/$fn"} = $c; @@ -56,7 +56,8 @@ sub build($$) sub usage { - print ("$0 boardname ...\n"); + print ("$0 [-n] boardname ...\n". + "\t -n for .db only (no .idx)\n"); exit(0); } -- cgit v1.2.3 From 601cb25be39aa81ea7508c22281100f699c9494a Mon Sep 17 00:00:00 2001 From: in2 Date: Thu, 3 Jul 2003 13:49:07 +0000 Subject: search support git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@1010 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/staticweb/man.pl | 29 ++++++++++++++++++++++++++--- pttbbs/staticweb/search.html | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+), 3 deletions(-) create mode 100644 pttbbs/staticweb/search.html diff --git a/pttbbs/staticweb/man.pl b/pttbbs/staticweb/man.pl index db5b84d5..e9e45a2a 100755 --- a/pttbbs/staticweb/man.pl +++ b/pttbbs/staticweb/man.pl @@ -1,5 +1,5 @@ #!/usr/bin/perl -# $Id: man.pl,v 1.2 2003/07/03 12:39:05 in2 Exp $ +# $Id: man.pl,v 1.3 2003/07/03 13:49:07 in2 Exp $ use CGI qw/:standard/; use lib qw/./; use LocalVars; @@ -15,7 +15,7 @@ use vars qw/%db $brdname $fpath/; sub main { - my($tmpl, $rh); + my($tmpl, $rh, $key); if( !(($brdname, $fpath) = $ENV{PATH_INFO} =~ m|^/([\w\-]+?)(/.*)|) || !(tie %db, 'DB_File', @@ -29,7 +29,12 @@ sub main charset(''); print header(); - $rh = (($fpath =~ m|/$|) ? dirmode($fpath) : articlemode($fpath)); + if( ($key = param('key')) ){ + $rh = search($key); + } + else{ + $rh = (($fpath =~ m|/$|) ? dirmode($fpath) : articlemode($fpath)); + } $rh->{brdname} = $brdname; $tmpl = Template->new({INCLUDE_PATH => '.', ABSOLUTE => 0, @@ -68,5 +73,23 @@ sub articlemode return \%th; } +sub search($) +{ + my($key) = @_; + my(%th, $idx, $k); + $idx = OurNet::FuzzyIndex->new("$MANDATA/$brdname.idx"); + my %result = $idx->query($th{key} = $key, MATCH_FUZZY); + foreach my $t (sort { $result{$b} <=> $result{$a} } keys(%result)) { + $k = $idx->getkey($t); + push @{$th{search}}, {title => $db{"title-$k"}, + fn => $k, + score => $result{$t} / 10}; + } + + $th{key} = $key; + $th{tmpl} = 'search.html'; + return \%th; +} + main(); 1; diff --git a/pttbbs/staticweb/search.html b/pttbbs/staticweb/search.html new file mode 100644 index 00000000..191c412f --- /dev/null +++ b/pttbbs/staticweb/search.html @@ -0,0 +1,40 @@ +[% INCLUDE header.html %] + + + + + + + +
+ +
+網頁版精華區首頁 +[% brdname %]精華區首頁 +批踢踢部落格 +
+在看板 [% brdname %] 內搜尋 [% key %] +
+
+ +
    +[% FOREACH x=search %] +
  • [% x.title %] (score: [% x.score %])
  • +[% END %] +
+ +
+
+
+在這個精華區內翻弄 (under construction) + + +
+
+批踢踢實業坊 (PttWeb) +
+ + -- cgit v1.2.3 From 44d3f81ae00d8428182460ef8c26dc646857a419 Mon Sep 17 00:00:00 2001 From: in2 Date: Thu, 3 Jul 2003 14:01:36 +0000 Subject: bug fix git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@1011 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/staticweb/manbuilder.pl | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/pttbbs/staticweb/manbuilder.pl b/pttbbs/staticweb/manbuilder.pl index ed15d57e..a6020357 100755 --- a/pttbbs/staticweb/manbuilder.pl +++ b/pttbbs/staticweb/manbuilder.pl @@ -1,5 +1,5 @@ #!/usr/bin/perl -# $Id: manbuilder.pl,v 1.6 2003/07/03 13:38:53 in2 Exp $ +# $Id: manbuilder.pl,v 1.7 2003/07/03 14:01:36 in2 Exp $ use lib '/home/bbs/bin/'; use strict; use OurNet::FuzzyIndex; @@ -21,7 +21,8 @@ sub main foreach( @ARGV ){ tie %db, 'DB_File', "$_.db", O_CREAT | O_RDWR, 0666, $DB_HASH; - $idx = OurNet::FuzzyIndex->new("$_.idx"); + $idx = OurNet::FuzzyIndex->new("$_.idx") + if( !$Getopt::Std::opt_n ); build("/home/bbs/man/boards/".substr($_, 0, 1)."/$_", ''); untie %db; } @@ -47,7 +48,8 @@ sub build($$) push @tdir, ["$doffset/$fn", $db{"title-$doffset/$fn"} = $bfh{"$_.title"}]; my $c = $bfh{"$_.content"}; - $idx->insert("$doffset/$fn", $bfh{"$_.title"}. "\n$c"); + $idx->insert("$doffset/$fn", $bfh{"$_.title"}. "\n$c") + if( !$Getopt::Std::opt_n ); $db{"$doffset/$fn"} = $c; } } -- cgit v1.2.3 From 9044e25754dca52610021110045b449a1d67221c Mon Sep 17 00:00:00 2001 From: in2 Date: Thu, 3 Jul 2003 14:02:03 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@1012 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/staticweb/dir.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pttbbs/staticweb/dir.html b/pttbbs/staticweb/dir.html index fe4392ba..82ea6a12 100644 --- a/pttbbs/staticweb/dir.html +++ b/pttbbs/staticweb/dir.html @@ -31,7 +31,7 @@


-在這個精華區內翻弄 (under construction) +在這個精華區內翻弄
-- cgit v1.2.3 From 83ff8c35aff7ab6cea786b29cb3fbc3ebbf3273c Mon Sep 17 00:00:00 2001 From: in2 Date: Thu, 3 Jul 2003 14:12:53 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@1013 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/staticweb/search.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pttbbs/staticweb/search.html b/pttbbs/staticweb/search.html index 191c412f..612300e4 100644 --- a/pttbbs/staticweb/search.html +++ b/pttbbs/staticweb/search.html @@ -28,7 +28,7 @@
-在這個精華區內翻弄 (under construction) +在這個精華區內翻弄
-- cgit v1.2.3 From 8788bd126f858813b2ef854886f6dba2798fa418 Mon Sep 17 00:00:00 2001 From: in2 Date: Fri, 4 Jul 2003 02:31:58 +0000 Subject: add listbrd git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@1014 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/shmctl.c | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/pttbbs/util/shmctl.c b/pttbbs/util/shmctl.c index b7ca5dab..66c9888e 100644 --- a/pttbbs/util/shmctl.c +++ b/pttbbs/util/shmctl.c @@ -1,4 +1,4 @@ -/* $Id: shmctl.c,v 1.43 2003/06/21 05:27:03 in2 Exp $ */ +/* $Id: shmctl.c,v 1.44 2003/07/04 02:31:58 in2 Exp $ */ #include "bbs.h" #include @@ -403,6 +403,34 @@ int listpid(int argc, char **argv) return 0; } +int listbrd(int argc, char **argv) +{ + int i, ch; + int noHidden = 0; + + while( (ch = getopt(argc, argv, "hn")) != -1 ) + switch( ch ){ + case 'n': + noHidden = 1; + break; + case 'h': + default: + printf("usage:\tshmctl\tlistbrd [-n]\n" + "\t-n no hidden board\n"); + return 0; + } + + for( i = 0 ; i < MAX_BOARD ; ++i ) + if( bcache[i].brdname[0] && !(bcache[i].brdattr & BRD_GROUPBOARD) && + (!noHidden || + !((bcache[i].brdattr & BRD_HIDE) || + (bcache[i].level && !(bcache[i].brdattr & BRD_POSTMASK) && + (bcache[i].level & + ~(PERM_BASIC|PERM_CHAT|PERM_PAGE|PERM_POST|PERM_LOGINOK))))) ) + printf("%s\n", bcache[i].brdname); + return 0; +} + #ifdef OUTTA_TIMER int timed(int argc, char **argv) { @@ -418,7 +446,6 @@ int timed(int argc, char **argv) } #endif - struct { int (*func)(int, char **); char *cmd, *descript; @@ -432,6 +459,7 @@ struct { {showglobal, "showglobal", "show GLOBALVAR[]"}, {setglobal, "setglobal", "set GLOBALVAR[]"}, {listpid, "listpid", "list all pids of mbbsd"}, + {listbrd, "listbrd", "list board info in SHM"}, #ifdef OUTTA_TIMER {timed, "timed", "time daemon for OUTTA_TIMER"}, #endif -- cgit v1.2.3 From 23fd54faa139a94e1d5ba7c548e6173affe9a836 Mon Sep 17 00:00:00 2001 From: in2 Date: Fri, 4 Jul 2003 02:50:36 +0000 Subject: build .idx from .db git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@1015 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/staticweb/manbuilder.pl | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/pttbbs/staticweb/manbuilder.pl b/pttbbs/staticweb/manbuilder.pl index a6020357..dda94a8a 100755 --- a/pttbbs/staticweb/manbuilder.pl +++ b/pttbbs/staticweb/manbuilder.pl @@ -1,5 +1,5 @@ #!/usr/bin/perl -# $Id: manbuilder.pl,v 1.7 2003/07/03 14:01:36 in2 Exp $ +# $Id: manbuilder.pl,v 1.8 2003/07/04 02:50:36 in2 Exp $ use lib '/home/bbs/bin/'; use strict; use OurNet::FuzzyIndex; @@ -20,11 +20,28 @@ sub main ); foreach( @ARGV ){ - tie %db, 'DB_File', "$_.db", O_CREAT | O_RDWR, 0666, $DB_HASH; - $idx = OurNet::FuzzyIndex->new("$_.idx") - if( !$Getopt::Std::opt_n ); - build("/home/bbs/man/boards/".substr($_, 0, 1)."/$_", ''); - untie %db; + if( /\.db$/ ){ + next if( $Getopt::Std::opt_n ); + + tie %db, 'DB_File', $_, O_RDONLY, 0666, $DB_HASH; + $idx = OurNet::FuzzyIndex->new(substr($_, 0, -3). '.idx'); + buildidx(); + } + else{ + tie %db, 'DB_File', "$_.db", O_CREAT | O_RDWR, 0666, $DB_HASH; + $idx = OurNet::FuzzyIndex->new("$_.idx") + if( !$Getopt::Std::opt_n ); + build("/home/bbs/man/boards/".substr($_, 0, 1)."/$_", ''); + untie %db; + } + } +} + +sub buildidx +{ + foreach( keys %db ){ + next if( /^title/ || /\/$/ ); # 是 title 或目錄的都跳過 + $idx->insert($_, $db{"title-$_"}. "\n". $db{$_}); } } -- cgit v1.2.3 From ef6f6ef05d4cc5b5234393f76e4f92f231778160 Mon Sep 17 00:00:00 2001 From: in2 Date: Fri, 4 Jul 2003 03:23:19 +0000 Subject: use open/read instead cat git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@1016 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/BBSFileHeader.pm | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pttbbs/util/BBSFileHeader.pm b/pttbbs/util/BBSFileHeader.pm index e9cf3cdd..f203f57c 100644 --- a/pttbbs/util/BBSFileHeader.pm +++ b/pttbbs/util/BBSFileHeader.pm @@ -41,7 +41,10 @@ sub FETCH } elsif( $key eq 'content' ){ my $fn = "$self->{dir}/" . $self->FETCH("$num.filename"); - return `/bin/cat $fn`; + my($c, $fh); + open $fh, "<$fn" || return ''; + $fh->read($c, (-s $fn)); + return $c; } else{ ($h{filename}, $h{recommend}, $h{owner}, $h{date}, $h{title}, -- cgit v1.2.3 From 182426413cdd81f1d2b9ec5a6a1e741ea669521f Mon Sep 17 00:00:00 2001 From: in2 Date: Fri, 4 Jul 2003 03:40:02 +0000 Subject: display something when buildidx git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@1017 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/staticweb/manbuilder.pl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pttbbs/staticweb/manbuilder.pl b/pttbbs/staticweb/manbuilder.pl index dda94a8a..c0b88db1 100755 --- a/pttbbs/staticweb/manbuilder.pl +++ b/pttbbs/staticweb/manbuilder.pl @@ -1,5 +1,5 @@ #!/usr/bin/perl -# $Id: manbuilder.pl,v 1.8 2003/07/04 02:50:36 in2 Exp $ +# $Id: manbuilder.pl,v 1.9 2003/07/04 03:40:02 in2 Exp $ use lib '/home/bbs/bin/'; use strict; use OurNet::FuzzyIndex; @@ -23,6 +23,7 @@ sub main if( /\.db$/ ){ next if( $Getopt::Std::opt_n ); + print "building idx for $_\n"; tie %db, 'DB_File', $_, O_RDONLY, 0666, $DB_HASH; $idx = OurNet::FuzzyIndex->new(substr($_, 0, -3). '.idx'); buildidx(); -- cgit v1.2.3 From ee41ba430a04f1e18fbe1cfb37ea83a9807f0305 Mon Sep 17 00:00:00 2001 From: in2 Date: Fri, 4 Jul 2003 05:59:05 +0000 Subject: add ?brdname support git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@1018 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/staticweb/index.pl | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pttbbs/staticweb/index.pl b/pttbbs/staticweb/index.pl index ea48b874..2fcd7e30 100755 --- a/pttbbs/staticweb/index.pl +++ b/pttbbs/staticweb/index.pl @@ -1,5 +1,5 @@ #!/usr/bin/perl -# $Id: index.pl,v 1.1 2003/07/03 12:39:05 in2 Exp $ +# $Id: index.pl,v 1.2 2003/07/04 05:59:05 in2 Exp $ use lib qw/./; use LocalVars; use CGI qw/:standard/; @@ -10,6 +10,9 @@ sub main { my($tmpl, %rh); + print redirect("/man.pl/$1/") + if( $ENV{REDIRECT_REQUEST_URI} =~ m|/\?(.*)| ); + charset(''); print header(); -- cgit v1.2.3 From 2d1717477dd9ed79a7b47479e37e6ff110d9e966 Mon Sep 17 00:00:00 2001 From: in2 Date: Fri, 4 Jul 2003 05:59:08 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@1019 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/staticweb/article.html | 3 ++- pttbbs/staticweb/dir.html | 2 +- pttbbs/staticweb/man.pl | 13 ++++++++++++- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/pttbbs/staticweb/article.html b/pttbbs/staticweb/article.html index 9cfee318..706626a0 100644 --- a/pttbbs/staticweb/article.html +++ b/pttbbs/staticweb/article.html @@ -1,6 +1,7 @@ [% INCLUDE header.html %] diff --git a/pttbbs/staticweb/man.pl b/pttbbs/staticweb/man.pl index e9e45a2a..28d21ae0 100755 --- a/pttbbs/staticweb/man.pl +++ b/pttbbs/staticweb/man.pl @@ -1,5 +1,5 @@ #!/usr/bin/perl -# $Id: man.pl,v 1.3 2003/07/03 13:49:07 in2 Exp $ +# $Id: man.pl,v 1.4 2003/07/04 05:58:45 in2 Exp $ use CGI qw/:standard/; use lib qw/./; use LocalVars; @@ -70,6 +70,17 @@ sub articlemode $th{tmpl} = 'article.html'; $th{content} = $db{$fpath}; $th{content} =~ s/\033\[.*?m//g; + + $th{content} =~ s|(http://[\w\-\.\:\/\,@]+)|$1|gs; + $th{content} =~ s|(ftp://[\w\-\.\:\/\,@]+)|$1|gs; + $th{content} =~ + s|批踢踢兔|批踢踢兔|gs; + $th{content} =~ + s|發信站: 批踢踢實業坊|發信站: 批踢踢實業坊|gs; + $th{content} =~ + s|ptt\.csie\.ntu\.edu\.tw|ptt.csie.ntu.edu.tw|gs; + $th{content} =~ + s|ptt\.twbbs\.org|ptt.twbbs.org|gs; return \%th; } -- cgit v1.2.3 From be81b019953e7b378524d1ffc85b2bd8c71b0d1c Mon Sep 17 00:00:00 2001 From: in2 Date: Fri, 4 Jul 2003 08:35:51 +0000 Subject: register git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@1020 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/user.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/pttbbs/mbbsd/user.c b/pttbbs/mbbsd/user.c index 6772500d..d880f706 100644 --- a/pttbbs/mbbsd/user.c +++ b/pttbbs/mbbsd/user.c @@ -1,4 +1,4 @@ -/* $Id: user.c,v 1.64 2003/06/27 02:39:32 in2 Exp $ */ +/* $Id: user.c,v 1.65 2003/07/04 08:35:51 in2 Exp $ */ #include "bbs.h" static char *sex[8] = { @@ -1049,8 +1049,12 @@ static int HaveRejectStr(char *s, char **rej) { int i; char *rejectstr[] = - {"幹", "阿", "ㄚ", "不", "你媽", "某", "笨", "呆", "..", "xx", - "你管", "管我", "猜", "天才", "超人", NULL}; + {"幹", "阿", "不", "你媽", "某", "笨", "呆", "..", "xx", + "你管", "管我", "猜", "天才", "超人", + "ㄅ", "ㄆ", "ㄇ", "ㄈ", "ㄉ", "ㄊ", "ㄋ", "ㄌ", "ㄍ", "ㄎ", "ㄏ", + "ㄐ", "ㄑ", "ㄒ", "ㄓ", "ㄔ", "ㄕ", "ㄖ", "ㄗ", "ㄘ", "ㄙ", "ㄧ", + "ㄨ", "ㄩ", "ㄚ", "ㄛ", "ㄜ", "ㄝ", "ㄞ", "ㄟ", "ㄠ", "ㄡ", "ㄢ", + "ㄣ", "ㄤ", "ㄥ", "ㄦ", NULL}; if( rej != NULL ) for( i = 0 ; rej[i] != NULL ; ++i ) @@ -1068,7 +1072,7 @@ static char *isvalidname(char *rname) char *rejectstr[] = {"肥", "胖", "豬頭", "小白", "小明", "路人", "老王", "老李", "寶貝", "先生", "師哥", "老頭", "小姊", "小姐", "美女", "小妹", "大頭", - "公主", NULL}; + "公主", "同學", "寶寶", "公子", "大頭", NULL}; if( removespace(rname) && rname[0] < 0 && strlen(rname) >= 4 && !HaveRejectStr(rname, rejectstr) && @@ -1109,6 +1113,7 @@ static char *isvalidaddr(char *addr) strcmp(&addr[strlen(addr) - 2], "巷") == 0 || strcmp(&addr[strlen(addr) - 2], "弄") == 0 || strcmp(&addr[strlen(addr) - 2], "區") == 0 || + strcmp(&addr[strlen(addr) - 2], "市") == 0 || strcmp(&addr[strlen(addr) - 2], "街") == 0 ) return "這個地址並不合法"; return NULL; -- cgit v1.2.3 From f58c2415c960044e4a3240a3f0bbac281b3eb2a5 Mon Sep 17 00:00:00 2001 From: victor Date: Fri, 4 Jul 2003 11:37:02 +0000 Subject: fix last commit bug git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@1021 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/read.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/pttbbs/mbbsd/read.c b/pttbbs/mbbsd/read.c index e66ab22c..cc5f480a 100644 --- a/pttbbs/mbbsd/read.c +++ b/pttbbs/mbbsd/read.c @@ -1,4 +1,4 @@ -/* $Id: read.c,v 1.25 2003/07/02 08:04:01 victor Exp $ */ +/* $Id: read.c,v 1.26 2003/07/04 11:37:02 victor Exp $ */ #include "bbs.h" static fileheader_t *headers = NULL; @@ -562,6 +562,8 @@ i_read_key(onekey_t * rcmdlist, keeploc_t * locmem, int ch, int bid) case KEY_LEFT: if(currmode & MODE_SELECT){ char genbuf[256]; + int num; + fileheader_t *fhdr = &headers[locmem->crs_ln - locmem->top_ln]; board_select(); @@ -569,7 +571,8 @@ i_read_key(onekey_t * rcmdlist, keeploc_t * locmem, int ch, int bid) locmem = getkeep(genbuf, 0, 1); locmem->crs_ln = getindex(genbuf, fhdr->filename, sizeof(fileheader_t)); - locmem->top_ln = locmem->crs_ln - p_lines + 1; + num = locmem->crs_ln - p_lines + 1; + locmem->top_ln = num < 1 ? 1 : num; return NEWDIRECT; } -- cgit v1.2.3 From 6bcdaf98b7fc1567bc1343e2e91664dfcbac0d8c Mon Sep 17 00:00:00 2001 From: in2 Date: Sat, 5 Jul 2003 05:19:18 +0000 Subject: gb support git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@1022 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/staticweb/article.html | 8 ++++---- pttbbs/staticweb/dir.html | 20 ++++++++++---------- pttbbs/staticweb/header.html | 8 ++++---- pttbbs/staticweb/index.html | 10 +++++----- pttbbs/staticweb/index.pl | 16 +++++++++++++--- pttbbs/staticweb/man.pl | 33 +++++++++++++++++++++++++-------- 6 files changed, 61 insertions(+), 34 deletions(-) diff --git a/pttbbs/staticweb/article.html b/pttbbs/staticweb/article.html index 706626a0..0d7d3e57 100644 --- a/pttbbs/staticweb/article.html +++ b/pttbbs/staticweb/article.html @@ -1,7 +1,7 @@ [% INCLUDE header.html %]
-看板: [% brdname %]
回上頁
+看板: [% brdname %]
+回上頁

diff --git a/pttbbs/staticweb/dir.html b/pttbbs/staticweb/dir.html
index 82ea6a12..a70d9a04 100644
--- a/pttbbs/staticweb/dir.html
+++ b/pttbbs/staticweb/dir.html
@@ -13,7 +13,7 @@
 [% brdname %]精華區首頁
 批踢踢部落格
 
-看板名稱: [% brdname %] +看板名稱: [% brdname %]
-看板: [% brdname %]
-回上頁
+[% IF gb %]艘啣[% ELSE %]看板[% END %]: [% brdname %]
+[% IF gb %]隙奻珜[% ELSE %]回上頁[% END %]

@@ -9,8 +9,8 @@
 

-回上頁
-批踢踢實業坊 (PttWeb) +[% IF gb %]隙奻珜[% ELSE %]回上頁[% END %]
+[% IF gb %]蠶杺杺妗珛溶[% ELSE %]批踢踢實業坊[% END %] (PttWeb)
diff --git a/pttbbs/staticweb/dir.html b/pttbbs/staticweb/dir.html index a70d9a04..6b626a93 100644 --- a/pttbbs/staticweb/dir.html +++ b/pttbbs/staticweb/dir.html @@ -4,39 +4,39 @@ -網頁版精華區首頁 -[% brdname %]精華區首頁 -批踢踢部落格 +[% IF gb %]厙珜唳儕貌⑹忑珜[% ELSE %]網頁版精華區首頁[% END %] +[% brdname %][% IF gb %]儕貌⑹忑珜[% ELSE %]精華區首頁[% END %] +[% IF gb %]蠶杺杺窒邈跡(big5 only)[% ELSE %]批踢踢部落格[% END %]
-看板名稱: [% brdname %] +[% IF gb %]艘啣靡備[% ELSE %]看板名稱[% END %]: [% brdname %]
[% IF !isroot %] -返回上一層
+[% IF gb %]殿隙奻珨脯[% ELSE %]返回上一層[% END %]
[% END %] [% FOREACH x=dat %] - + [% x.title %]
[% END %]
-在這個精華區內翻弄 +[% IF gb %]婓涴跺儕貌⑹囀楹讀[% ELSE %]在這個精華區內翻弄[% END %] - +

-批踢踢實業坊 (PttWeb) +[% IF gb %]蠶杺杺妗珛溶[% ELSE %]批踢踢實業坊[% END %] (PttWeb) diff --git a/pttbbs/staticweb/header.html b/pttbbs/staticweb/header.html index 465e9ff7..7f33ab66 100644 --- a/pttbbs/staticweb/header.html +++ b/pttbbs/staticweb/header.html @@ -1,13 +1,13 @@ - + + xml:lang="[% lang %]" lang="[% lang %]"> - 批踢踢實業坊 + [% IF gb %]蠶杺杺妗珛溶[% ELSE %]批踢踢實業坊[% END %] + content="text/html; charset=[% charset %]"> diff --git a/pttbbs/staticweb/index.html b/pttbbs/staticweb/index.html index d0722654..a9f37606 100644 --- a/pttbbs/staticweb/index.html +++ b/pttbbs/staticweb/index.html @@ -4,22 +4,22 @@ -批踢踢實業坊之精華區(experimental)
-目前提供下列精華區資料:
+[% IF gb %]蠶杺杺妗珛溶眳儕貌⑹[% ELSE %]批踢踢實業坊之精華區[% END %](experimental)
+[% IF gb %]醴ヶ枑鼎狟蹈儕貌⑹訧蹋[% ELSE %]目前提供下列精華區資料[% END %]:

[% FOREACH x=dat %] -[% x.brdname %]
+[% x.brdname %]
[% END %]
-批踢踢實業坊 (PttWeb) +[% IF gb %]蠶杺杺妗珛溶[% ELSE %]批踢踢實業坊[% END %] (PttWeb) diff --git a/pttbbs/staticweb/index.pl b/pttbbs/staticweb/index.pl index 2fcd7e30..71ad6117 100755 --- a/pttbbs/staticweb/index.pl +++ b/pttbbs/staticweb/index.pl @@ -1,5 +1,5 @@ #!/usr/bin/perl -# $Id: index.pl,v 1.2 2003/07/04 05:59:05 in2 Exp $ +# $Id: index.pl,v 1.3 2003/07/05 05:19:18 in2 Exp $ use lib qw/./; use LocalVars; use CGI qw/:standard/; @@ -10,8 +10,18 @@ sub main { my($tmpl, %rh); - print redirect("/man.pl/$1/") - if( $ENV{REDIRECT_REQUEST_URI} =~ m|/\?(.*)| ); + if( param('gb') ){ + $rh{gb} = 1; + $rh{encoding} = 'gb2312'; + $rh{lang} = 'zh_CN'; + $rh{charset} = 'gb2312'; } + else{ + print redirect("/man.pl/$1/") + if( $ENV{REDIRECT_REQUEST_URI} =~ m|/\?(.*)| ); + $rh{encoding} = 'Big5'; + $rh{lang} = 'zh_TW'; + $rh{charset} = 'big5'; + } charset(''); print header(); diff --git a/pttbbs/staticweb/man.pl b/pttbbs/staticweb/man.pl index 28d21ae0..0baa69be 100755 --- a/pttbbs/staticweb/man.pl +++ b/pttbbs/staticweb/man.pl @@ -1,5 +1,5 @@ #!/usr/bin/perl -# $Id: man.pl,v 1.4 2003/07/04 05:58:45 in2 Exp $ +# $Id: man.pl,v 1.5 2003/07/05 05:19:18 in2 Exp $ use CGI qw/:standard/; use lib qw/./; use LocalVars; @@ -11,7 +11,8 @@ use Template; use HTML::Calendar::Simple; use OurNet::FuzzyIndex; use Data::Serializer; -use vars qw/%db $brdname $fpath/; +use Encode; +use vars qw/%db $brdname $fpath $isgb/; sub main { @@ -26,6 +27,7 @@ sub main return; } + $isgb = (param('gb') ? 1 : 0); charset(''); print header(); @@ -41,21 +43,34 @@ sub main RELATIVE => 0, RECURSION => 0, EVAL_PERL => 0, - COMPILE_EXT => '.tmpl', - COMPILE_DIR => $MANCACHE}); +# COMPILE_EXT => '.tmpl', +# COMPILE_DIR => $MANCACHE, + }); + if( $rh->{gb} = $isgb ){ + $rh->{encoding} = 'gb2312'; + $rh->{lang} = 'zh_CN'; + $rh->{charset} = 'gb2312'; + } + else{ + $rh->{encoding} = 'Big5'; + $rh->{lang} = 'zh_TW'; + $rh->{charset} = 'big5'; + } $tmpl->process($rh->{tmpl}, $rh); } sub dirmode { - my(%th); + my(%th, $isdir); my $serial = Data::Serializer->new(serializer => 'Storable', digester => 'MD5', compress => 0, ); foreach( @{$serial->deserialize($db{$fpath})} ){ - push @{$th{dat}}, {isdir => (($_->[0] =~ m|/$|) ? 1 : 0), - fn => "/man.pl/$brdname$_->[0]", + Encode::from_to($_->[1], 'big5', 'gb2312') if( $isgb ); + $isdir = (($_->[0] =~ m|/$|) ? 1 : 0); + push @{$th{dat}}, {isdir => $isdir, + fn => "man.pl/$brdname$_->[0]", title => $_->[1]}; } @@ -71,7 +86,7 @@ sub articlemode $th{content} = $db{$fpath}; $th{content} =~ s/\033\[.*?m//g; - $th{content} =~ s|(http://[\w\-\.\:\/\,@]+)|$1|gs; + $th{content} =~ s|(http://[\w\-\.\:\/\,@\?=]+)|$1|gs; $th{content} =~ s|(ftp://[\w\-\.\:\/\,@]+)|$1|gs; $th{content} =~ s|批踢踢兔|批踢踢兔|gs; @@ -81,6 +96,8 @@ sub articlemode s|ptt\.csie\.ntu\.edu\.tw|ptt.csie.ntu.edu.tw|gs; $th{content} =~ s|ptt\.twbbs\.org|ptt.twbbs.org|gs; + + Encode::from_to($th{content}, 'big5', 'gb2312') if( $isgb ); return \%th; } -- cgit v1.2.3 From f44a4588eafd2c51422008320b91d8ecf1301beb Mon Sep 17 00:00:00 2001 From: in2 Date: Sat, 5 Jul 2003 05:40:05 +0000 Subject: gb2312 -> gbk git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@1023 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/staticweb/man.pl | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pttbbs/staticweb/man.pl b/pttbbs/staticweb/man.pl index 0baa69be..189df02e 100755 --- a/pttbbs/staticweb/man.pl +++ b/pttbbs/staticweb/man.pl @@ -1,5 +1,5 @@ #!/usr/bin/perl -# $Id: man.pl,v 1.5 2003/07/05 05:19:18 in2 Exp $ +# $Id: man.pl,v 1.6 2003/07/05 05:40:05 in2 Exp $ use CGI qw/:standard/; use lib qw/./; use LocalVars; @@ -43,8 +43,8 @@ sub main RELATIVE => 0, RECURSION => 0, EVAL_PERL => 0, -# COMPILE_EXT => '.tmpl', -# COMPILE_DIR => $MANCACHE, + COMPILE_EXT => '.tmpl', + COMPILE_DIR => $MANCACHE, }); if( $rh->{gb} = $isgb ){ $rh->{encoding} = 'gb2312'; @@ -67,7 +67,7 @@ sub dirmode compress => 0, ); foreach( @{$serial->deserialize($db{$fpath})} ){ - Encode::from_to($_->[1], 'big5', 'gb2312') if( $isgb ); + Encode::from_to($_->[1], 'big5', 'gbk') if( $isgb ); $isdir = (($_->[0] =~ m|/$|) ? 1 : 0); push @{$th{dat}}, {isdir => $isdir, fn => "man.pl/$brdname$_->[0]", @@ -97,7 +97,7 @@ sub articlemode $th{content} =~ s|ptt\.twbbs\.org|ptt.twbbs.org|gs; - Encode::from_to($th{content}, 'big5', 'gb2312') if( $isgb ); + Encode::from_to($th{content}, 'big5', 'gbk') if( $isgb ); return \%th; } -- cgit v1.2.3 From aee7d5bd566e6ccc534a67af8f993e1c7376f54a Mon Sep 17 00:00:00 2001 From: in2 Date: Sat, 5 Jul 2003 05:52:13 +0000 Subject: gb support git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@1024 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/staticweb/dir.html | 6 ++++++ pttbbs/staticweb/index.html | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/pttbbs/staticweb/dir.html b/pttbbs/staticweb/dir.html index 6b626a93..a533481b 100644 --- a/pttbbs/staticweb/dir.html +++ b/pttbbs/staticweb/dir.html @@ -5,6 +5,12 @@ diff --git a/pttbbs/staticweb/index.html b/pttbbs/staticweb/index.html index a9f37606..2484bd5a 100644 --- a/pttbbs/staticweb/index.html +++ b/pttbbs/staticweb/index.html @@ -5,6 +5,12 @@ -- cgit v1.2.3 From b12955b3ddc7f001913d72b2a71db32acde59d23 Mon Sep 17 00:00:00 2001 From: in2 Date: Sat, 5 Jul 2003 06:01:20 +0000 Subject: banner.html git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@1025 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/staticweb/banner.html | 10 ++++++++++ pttbbs/staticweb/dir.html | 16 ++++------------ pttbbs/staticweb/index.html | 15 ++------------- pttbbs/staticweb/search.html | 8 ++------ 4 files changed, 18 insertions(+), 31 deletions(-) create mode 100644 pttbbs/staticweb/banner.html diff --git a/pttbbs/staticweb/banner.html b/pttbbs/staticweb/banner.html new file mode 100644 index 00000000..4a8d0678 --- /dev/null +++ b/pttbbs/staticweb/banner.html @@ -0,0 +1,10 @@ + diff --git a/pttbbs/staticweb/dir.html b/pttbbs/staticweb/dir.html index a533481b..c3ce33ac 100644 --- a/pttbbs/staticweb/dir.html +++ b/pttbbs/staticweb/dir.html @@ -1,17 +1,7 @@ [% INCLUDE header.html %] - - diff --git a/pttbbs/staticweb/index.html b/pttbbs/staticweb/index.html index 2484bd5a..3a62ed51 100644 --- a/pttbbs/staticweb/index.html +++ b/pttbbs/staticweb/index.html @@ -1,20 +1,9 @@ [% INCLUDE header.html %]
- +
+[% INCLUDE banner.html %]
@@ -35,12 +25,14 @@ [% END %]
+[% IF !gb %]
[% IF gb %]婓涴跺儕貌⑹囀楹讀[% ELSE %]在這個精華區內翻弄[% END %]
+[% END %]
[% IF gb %]蠶杺杺妗珛溶[% ELSE %]批踢踢實業坊[% END %] (PttWeb)
- - -
- +
+[% INCLUDE banner.html %]
[% IF gb %]蠶杺杺妗珛溶眳儕貌⑹[% ELSE %]批踢踢實業坊之精華區[% END %](experimental)
[% IF gb %]醴ヶ枑鼎狟蹈儕貌⑹訧蹋[% ELSE %]目前提供下列精華區資料[% END %]:
diff --git a/pttbbs/staticweb/search.html b/pttbbs/staticweb/search.html index 612300e4..4688617d 100644 --- a/pttbbs/staticweb/search.html +++ b/pttbbs/staticweb/search.html @@ -1,11 +1,7 @@ [% INCLUDE header.html %] - -|s if( !$content ); - $content =~ s/
/\n/g; $content =~ s/

/\n/gi; $content =~ s/<.*?>//g; $content =~ s/\r//g; - $content =~ s/\n\n\n/\n\n/g; - $content =~ s/\n\n\n//g; + $content =~ s/\n+/\n/gs; $content = strreplace($content); undef $ret; foreach( split(/\n/, $content) ){ @@ -54,8 +52,8 @@ sub getudnnewscontent($) $ret .= FormatChinese($_, 60). "\n" if( $_ ); } return - "作者: udnnews.(聯合新聞) 看板: udnnews\n". - "標題: \n". + "作者: udnnews.(聯合新聞網) 看板: udnnews\n". + "標題: $title\n". "時間: 即時\n". "※ [轉錄自 $url ]\n\n$ret\n\n". "--\n\n 聯合新聞網 http://www.udn.com/ 獨家授權批踢踢實業坊 ". -- cgit v1.2.3 From 95f6b3c78f07da448bf74b0e7f4286047bb9a5ad Mon Sep 17 00:00:00 2001 From: in2 Date: Fri, 11 Jul 2003 02:23:33 +0000 Subject: ignore   git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@1044 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/udnnews.pl | 1 + 1 file changed, 1 insertion(+) diff --git a/pttbbs/util/udnnews.pl b/pttbbs/util/udnnews.pl index 21e3262c..fd02efc3 100644 --- a/pttbbs/util/udnnews.pl +++ b/pttbbs/util/udnnews.pl @@ -43,6 +43,7 @@ sub getudnnewscontent($$) # ($content) = $buf =~ m|

(.*?)

|s if( !$content ); $content =~ s/

/\n/gi; $content =~ s/<.*?>//g; + $content =~ s/ //g; $content =~ s/\r//g; $content =~ s/\n+/\n/gs; $content = strreplace($content); -- cgit v1.2.3 From eff4d07538653fafe9a43f1fcf9860b03b10be7a Mon Sep 17 00:00:00 2001 From: in2 Date: Fri, 11 Jul 2003 09:02:40 +0000 Subject: *** empty log message *** git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@1045 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/.cvsignore | 2 + pttbbs/util/boardlist.c | 105 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 107 insertions(+) create mode 100644 pttbbs/util/boardlist.c diff --git a/pttbbs/util/.cvsignore b/pttbbs/util/.cvsignore index 4e206253..431c9ff0 100644 --- a/pttbbs/util/.cvsignore +++ b/pttbbs/util/.cvsignore @@ -43,3 +43,5 @@ mandex shmctl indexuser diskstat +boardlist +boardlist.pm diff --git a/pttbbs/util/boardlist.c b/pttbbs/util/boardlist.c new file mode 100644 index 00000000..b28b2b03 --- /dev/null +++ b/pttbbs/util/boardlist.c @@ -0,0 +1,105 @@ +/* $Id: boardlist.c,v 1.1 2003/07/11 09:02:40 in2 Exp $ */ +#include "bbs.h" + +static void +load_uidofgid(const int gid, const int type) +{ + boardheader_t *bptr, *currbptr; + int n, childcount = 0; + currbptr = &bcache[gid - 1]; + for (n = 0; n < numboards; ++n) { + bptr = SHM->bsorted[type][n]; + if (bptr->brdname[0] == '\0') + continue; + if (bptr->gid == gid) { + if (currbptr == &bcache[gid - 1]) + currbptr->firstchild[type] = bptr; + else { + currbptr->next[type] = bptr; + currbptr->parent = &bcache[gid - 1]; + } + childcount++; + currbptr = bptr; + } + } + bcache[gid - 1].childcount = childcount; + if (currbptr == &bcache[gid - 1]) + currbptr->firstchild[type] = (boardheader_t *) ~ 0; + else + currbptr->next[type] = (boardheader_t *) ~ 0; +} + +char *skipEscape(char *s) +{ + static char buf[TTLEN * 2 + 1]; + int r, w; + for( w = r = 0 ; s[r] != 0 ; ++r ){ + if( s[r] == '\'' || s[r] == '\\' ) + buf[w++] = '\\'; + buf[w++] = s[r]; + } + buf[w++] = 0; + return buf; +} + +void dumpclass(int bid) +{ + boardheader_t *bptr; + int r, w; + bptr = &bcache[bid]; + if (bptr->firstchild[0] == NULL || bptr->childcount <= 0) + load_uidofgid(bid + 1, 0); /* 因為這邊 bid從 0開始, 所以再 +1 回來 */ + printf(" %5d => [\n", bid); + for (bptr = bptr->firstchild[0]; bptr != (boardheader_t *) ~ 0; + bptr = bptr->next[0]) { + if( (bptr->brdattr & (BRD_HIDE | BRD_TOP)) || + (bptr->level && !(bptr->brdattr & BRD_POSTMASK) && + (bptr->level & + ~(PERM_BASIC|PERM_CHAT|PERM_PAGE|PERM_POST|PERM_LOGINOK))) ) + continue; + + printf(" [%5d, '%s', '%s'], \n", + (bptr->brdattr & BRD_GROUPBOARD) ? bptr - bcache : -1, + bptr->brdname, skipEscape(&bptr->title[7])); + } + printf(" ],\n"); + + bptr = &bcache[bid]; + for (bptr = bptr->firstchild[0]; bptr != (boardheader_t *) ~ 0; + bptr = bptr->next[0]) { + if( (bptr->brdattr & (BRD_HIDE | BRD_TOP)) || + (bptr->level && !(bptr->brdattr & BRD_POSTMASK) && + (bptr->level & + ~(PERM_BASIC|PERM_CHAT|PERM_PAGE|PERM_POST|PERM_LOGINOK))) ) + continue; + + printf(" '%d.title' => '%s',\n", + bptr - bcache, skipEscape(&bptr->title[7])); + if( bptr->brdattr & BRD_GROUPBOARD ) + dumpclass(bptr - bcache); + } +} + +int main(int argc, char **argv) +{ + attach_SHM(); + + printf("# this is auto-generated perl module from boardlist.c\n" + "# please do NOT modify this directly\n" + "\n" + "package boardlist;\n" + "require 5.6;\n" + "use Exporter;\n" + "$VERSION = '0.1';\n" + "use vars qw(%%brd);\n" + "\n" + "%%brd = (\n"); + dumpclass(0); + printf(");\n" + "our(@ISA, @EXPORT);\n" + "@ISA = qw(Exporter);\n" + "@EXPORT = qw(%%brd);\n" + "\n" + "1;\n"); + return 0; +} -- cgit v1.2.3 From 4473e162e491f2fa3b89dcaef8040026c4a0b1de Mon Sep 17 00:00:00 2001 From: in2 Date: Fri, 11 Jul 2003 09:03:21 +0000 Subject: add boardlist git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@1046 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/Makefile | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pttbbs/util/Makefile b/pttbbs/util/Makefile index 090f7217..baf0bf6a 100644 --- a/pttbbs/util/Makefile +++ b/pttbbs/util/Makefile @@ -1,4 +1,4 @@ -# $Id: Makefile,v 1.31 2003/05/15 08:28:59 in2 Exp $ +# $Id: Makefile,v 1.32 2003/07/11 09:03:21 in2 Exp $ .include "../pttbbs.mk" @@ -12,7 +12,8 @@ CPROG_WITH_UTIL= \ expire mandex rmuid horoscope \ openvice parse_news openticket topusr \ indexuser yearsold toplazyBM toplazyBBM \ - reaper buildAnnounce inndBM shmctl + reaper buildAnnounce inndBM shmctl \ + boardlist # 下面這些程式, 會直接被 compile CPROG_WITHOUT_UTIL= \ -- cgit v1.2.3 From afac2353fd96dfd6edf3ecf57acdd58cd9be7678 Mon Sep 17 00:00:00 2001 From: in2 Date: Fri, 11 Jul 2003 09:03:42 +0000 Subject: remove unused vars git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@1047 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/boardlist.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pttbbs/util/boardlist.c b/pttbbs/util/boardlist.c index b28b2b03..be1c8111 100644 --- a/pttbbs/util/boardlist.c +++ b/pttbbs/util/boardlist.c @@ -1,4 +1,4 @@ -/* $Id: boardlist.c,v 1.1 2003/07/11 09:02:40 in2 Exp $ */ +/* $Id: boardlist.c,v 1.2 2003/07/11 09:03:42 in2 Exp $ */ #include "bbs.h" static void @@ -45,7 +45,6 @@ char *skipEscape(char *s) void dumpclass(int bid) { boardheader_t *bptr; - int r, w; bptr = &bcache[bid]; if (bptr->firstchild[0] == NULL || bptr->childcount <= 0) load_uidofgid(bid + 1, 0); /* 因為這邊 bid從 0開始, 所以再 +1 回來 */ -- cgit v1.2.3 From 0cdbb36aff2faa2e6392814cfa2c4a5b6ae1c23f Mon Sep 17 00:00:00 2001 From: in2 Date: Fri, 11 Jul 2003 10:11:24 +0000 Subject: use boardlist git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@1048 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/staticweb/index.html | 12 +++++++++--- pttbbs/staticweb/index.pl | 23 +++++++++++++++++------ 2 files changed, 26 insertions(+), 9 deletions(-) diff --git a/pttbbs/staticweb/index.html b/pttbbs/staticweb/index.html index 3a62ed51..45372764 100644 --- a/pttbbs/staticweb/index.html +++ b/pttbbs/staticweb/index.html @@ -5,11 +5,17 @@

- +
+[% INCLUDE banner.html %]
-- cgit v1.2.3 From 376f3adee774bf822777f3f7369194ea19f00a17 Mon Sep 17 00:00:00 2001 From: in2 Date: Sat, 5 Jul 2003 06:12:25 +0000 Subject: =?UTF-8?q?s/=EF=BF=BD\/=EF=BF=BD\\//?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@1026 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/udnnews.pl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pttbbs/util/udnnews.pl b/pttbbs/util/udnnews.pl index 871b33b3..1c49dc8c 100644 --- a/pttbbs/util/udnnews.pl +++ b/pttbbs/util/udnnews.pl @@ -59,7 +59,7 @@ sub getudnnewscontent($) "時間: 即時\n". "※ [轉錄自 $url ]\n\n$ret\n\n". "--\n\n 聯合新聞網 http://www.udn.com/ 獨家授權批踢踢實業坊 ". - "\n 未經允許請勿擅自使用 "; + "\n 未經允許\請勿擅自使用 "; } sub getudnnewstitle($) -- cgit v1.2.3 From a8f934deec819d6f3616a653b125902d01a8f9b7 Mon Sep 17 00:00:00 2001 From: in2 Date: Sat, 5 Jul 2003 06:16:15 +0000 Subject: add ~ to http/ftp pattern git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@1027 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/staticweb/man.pl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pttbbs/staticweb/man.pl b/pttbbs/staticweb/man.pl index 189df02e..4f20889c 100755 --- a/pttbbs/staticweb/man.pl +++ b/pttbbs/staticweb/man.pl @@ -1,5 +1,5 @@ #!/usr/bin/perl -# $Id: man.pl,v 1.6 2003/07/05 05:40:05 in2 Exp $ +# $Id: man.pl,v 1.7 2003/07/05 06:16:15 in2 Exp $ use CGI qw/:standard/; use lib qw/./; use LocalVars; @@ -86,8 +86,8 @@ sub articlemode $th{content} = $db{$fpath}; $th{content} =~ s/\033\[.*?m//g; - $th{content} =~ s|(http://[\w\-\.\:\/\,@\?=]+)|$1|gs; - $th{content} =~ s|(ftp://[\w\-\.\:\/\,@]+)|$1|gs; + $th{content} =~ s|(http://[\w\-\.\:\/\,@\?=~]+)|$1|gs; + $th{content} =~ s|(ftp://[\w\-\.\:\/\,@~]+)|$1|gs; $th{content} =~ s|批踢踢兔|批踢踢兔|gs; $th{content} =~ -- cgit v1.2.3 From c9197f7218686de2e351cbc446fb392ea9aa1e5e Mon Sep 17 00:00:00 2001 From: in2 Date: Sat, 5 Jul 2003 06:16:37 +0000 Subject: =?UTF-8?q?font-family:=20=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD?= =?UTF-8?q?=EF=BF=BD=EF=BF=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@1028 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/staticweb/styles.css | 1 + 1 file changed, 1 insertion(+) diff --git a/pttbbs/staticweb/styles.css b/pttbbs/staticweb/styles.css index 973c6ec7..87382c7b 100644 --- a/pttbbs/staticweb/styles.css +++ b/pttbbs/staticweb/styles.css @@ -16,4 +16,5 @@ A:hover {background: #555555;} body { background: #000000; color: #FFFFFF; + font-family: 細明體; } \ No newline at end of file -- cgit v1.2.3 From c52ef64c986d12f6c7101c2a75f098919bbbe326 Mon Sep 17 00:00:00 2001 From: in2 Date: Sat, 5 Jul 2003 07:58:09 +0000 Subject: count #Welcomes in account to SHM instead of mbbsd.c git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@1029 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/include/pttstruct.h | 3 ++- pttbbs/mbbsd/mbbsd.c | 19 +++++-------------- pttbbs/util/account.c | 10 +++++++++- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/pttbbs/include/pttstruct.h b/pttbbs/include/pttstruct.h index a85c031d..d693f985 100644 --- a/pttbbs/include/pttstruct.h +++ b/pttbbs/include/pttstruct.h @@ -1,4 +1,4 @@ -/* $Id: pttstruct.h,v 1.38 2003/05/26 05:23:13 in2 Exp $ */ +/* $Id: pttstruct.h,v 1.39 2003/07/05 07:58:09 in2 Exp $ */ #ifndef INCLUDE_STRUCT_H #define INCLUDE_STRUCT_H @@ -361,6 +361,7 @@ typedef struct { #ifdef OUTTA_TIMER time_t now; #endif + int nWelcomes; } e; } GV2; char gap3_2[128]; diff --git a/pttbbs/mbbsd/mbbsd.c b/pttbbs/mbbsd/mbbsd.c index a4c3abe9..a20188a6 100644 --- a/pttbbs/mbbsd/mbbsd.c +++ b/pttbbs/mbbsd/mbbsd.c @@ -1,4 +1,4 @@ -/* $Id: mbbsd.c,v 1.87 2003/06/27 07:44:02 in2 Exp $ */ +/* $Id: mbbsd.c,v 1.88 2003/07/05 07:58:09 in2 Exp $ */ #include "bbs.h" #define SOCKET_QLEN 4 @@ -780,19 +780,10 @@ user_login() #ifndef MULTI_WELCOME_LOGIN more("etc/Welcome_login", NA); #else - char buf[80]; - int nScreens; - - for (nScreens = 0; nScreens < 5; ++nScreens) { - snprintf(buf, sizeof(buf), "etc/Welcome_login.%d", nScreens); - if (access(buf, 0) < 0) - break; - } - if (nScreens == 0) { - //multi screen error ? - more("etc/Welcome_login", NA); - } else { - snprintf(buf, sizeof(buf), "etc/Welcome_login.%d", (int)login_start_time % nScreens); + if( SHM->GV2.e.nWelcomes ){ + char buf[80]; + snprintf(buf, sizeof(buf), "etc/Welcome_login.%d", + (int)login_start_time % SHM->GV2.e.nWelcomes); more(buf, NA); } #endif diff --git a/pttbbs/util/account.c b/pttbbs/util/account.c index 5220f713..bbc84244 100644 --- a/pttbbs/util/account.c +++ b/pttbbs/util/account.c @@ -1,4 +1,4 @@ -/* $Id: account.c,v 1.7 2002/06/16 22:21:12 ptt Exp $ */ +/* $Id: account.c,v 1.8 2003/07/05 07:58:09 in2 Exp $ */ #include "bbs.h" #define MAX_LINE 16 @@ -399,5 +399,13 @@ int main() { SHM->Puptime = 0; resolve_fcache(); reset_garbage(); + + printf("計算進站畫面數: "); + for( i = 0 ; i < 5 ; ++i ){ + sprintf(buf, "etc/Welcome_login.%d", i); + if( access(buf, 0) < 0 ) + break; + } + printf("%d\n", SHM->GV2.e.nWelcomes = i); return 0; } -- cgit v1.2.3 From 85b7349eac000090b1ee075bd56361ad488cf528 Mon Sep 17 00:00:00 2001 From: in2 Date: Sat, 5 Jul 2003 09:31:12 +0000 Subject: comment support git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@1030 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/blog/blog.pl | 67 ++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 61 insertions(+), 6 deletions(-) diff --git a/pttbbs/blog/blog.pl b/pttbbs/blog/blog.pl index f64b6b5b..b7f2dc5d 100755 --- a/pttbbs/blog/blog.pl +++ b/pttbbs/blog/blog.pl @@ -1,5 +1,5 @@ #!/usr/bin/perl -# $Id: blog.pl,v 1.25 2003/06/29 06:06:17 in2 Exp $ +# $Id: blog.pl,v 1.26 2003/07/05 09:31:12 in2 Exp $ use CGI qw/:standard/; use lib qw/./; use LocalVars; @@ -10,14 +10,18 @@ use Date::Calc qw(:all); use Template; use HTML::Calendar::Simple; use OurNet::FuzzyIndex; +use DBI; +use DBD::mysql; +use POSIX; -use vars qw/@emonth @cnumber %config %attr %article %th/; +use vars qw/@emonth @cnumber %config %attr %article %th $dbh/; sub main { my($brdname, $fn, $y, $m, $d); my($tmpl); + $dbh = undef; @emonth = ('', 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'); @@ -48,6 +52,7 @@ sub main # first, import all settings in %config %th = %config; $th{BOARDNAME} = $brdname; + $th{key} = $y * 10000 + $m * 100 + $d; # loadBlog --------------------------------------------------------------- tie %article, 'DB_File', "$BLOGDATA/$brdname.db", O_RDONLY, 0666, $DB_HASH; @@ -220,6 +225,57 @@ sub main #$th{calendar} = $cal->calendar_month; } + # Comments --------------------------------------------------------------- + if( $attr{"$fn.loadRecentComments"} ){ + print "here\n"; + dodbi(sub { + my($dbh) = @_; + my($sth, $t); + $sth = $dbh->prepare("select artid,name,mail,mtime ". + "from comment ". + "where brdname='$brdname' ". + "order by mtime desc ". + "LIMIT 0,". $attr{"$fn.loadRecentComments"}); + $sth->execute(); + while( $t = $sth->fetchrow_hashref() ){ + $t->{title} = $article{"$t->{artid}.title"}; + $t->{key} = $t->{artid}; + $t->{time} = POSIX::strftime('%D', localtime($t->{mtime})); + push @{$th{RecentComments}}, $t; + } + }); + } + + if( $attr{"$fn.loadComments"} ){ + my($name, $mail, $comment) = (param('name'), + param('mail'), param('comment')); + + if( $name && $comment ){ + dodbi(sub { + my($dbh) = @_; + $dbh->do("insert into comment (brdname, artid, name, mail, ". + "content, mtime) values ('$brdname', '$th{key}', ". + "'$name', '$mail', '$comment', ". time(). ")"); + }); + } + + dodbi(sub { + my($dbh) = @_; + my($sth, $t); + $sth = $dbh->prepare("select mtime,name,mail,content ". + "from comment ". + "where brdname='$brdname'&&artid='$th{key}' ". + "order by mtime desc"); + $sth->execute(); + while( $t = $sth->fetchrow_hashref() ){ + $t->{time} = POSIX::ctime($t->{mtime}); + $t->{content} = applyfilter($t->{content}, + $config{outputfilter}); + push @{$th{comment}}, $t; + } + }); + } + # 用 Template Toolkit 輸出 mkdir "$BLOGCACHE/$brdname"; $tmpl = Template->new({INCLUDE_PATH => '.', @@ -233,6 +289,7 @@ sub main chdir "$BLOGDATA/$brdname/"; $tmpl->process($fn, \%th) || print "
template error: ". $tmpl->error();
+    $dbh->disconnect() if( $dbh );
 }
 
 sub AddArticle($$$;$)
@@ -320,16 +377,14 @@ sub dodbi
 {
     my($func) = @_;
     my($ret);
-    use DBI;
-    use DBD::mysql;
     my $dbh = DBI->connect("DBI:mysql:database=$BLOGdbname;".
 			   "host=$BLOGdbhost",
 			   $BLOGdbuser, $BLOGdbpasswd,
-			   {'RaiseError' => 1});
+			   {'RaiseError' => 1})
+	if( !$dbh );
     eval {
 	$ret = &{$func}($dbh);
     };
-    $dbh->disconnect();
     print "SQL: $@\n" if( $@ );
     return $ret;
 }
-- 
cgit v1.2.3


From 18cc301a589b3d90606063bbf46a30af74d9f79d Mon Sep 17 00:00:00 2001
From: in2 
Date: Sat, 5 Jul 2003 09:58:53 +0000
Subject: for comments

git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@1031 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
---
 pttbbs/blog/blog.pl | 20 +++++++++++++++-----
 1 file changed, 15 insertions(+), 5 deletions(-)

diff --git a/pttbbs/blog/blog.pl b/pttbbs/blog/blog.pl
index b7f2dc5d..78885190 100755
--- a/pttbbs/blog/blog.pl
+++ b/pttbbs/blog/blog.pl
@@ -1,5 +1,5 @@
 #!/usr/bin/perl
-# $Id: blog.pl,v 1.26 2003/07/05 09:31:12 in2 Exp $
+# $Id: blog.pl,v 1.27 2003/07/05 09:58:53 in2 Exp $
 use CGI qw/:standard/;
 use lib qw/./;
 use LocalVars;
@@ -14,11 +14,11 @@ use DBI;
 use DBD::mysql;
 use POSIX;
 
-use vars qw/@emonth @cnumber %config %attr %article %th $dbh/;
+use vars qw/@emonth @cnumber %config %attr %article %th $dbh $brdname/;
 
 sub main
 {
-    my($brdname, $fn, $y, $m, $d);
+    my($fn, $y, $m, $d);
     my($tmpl);
 
     $dbh = undef;
@@ -227,7 +227,6 @@ sub main
 
     # Comments ---------------------------------------------------------------
     if( $attr{"$fn.loadRecentComments"} ){
-	print "here\n";
 	dodbi(sub {
 	    my($dbh) = @_;
 	    my($sth, $t);
@@ -295,13 +294,23 @@ sub main
 sub AddArticle($$$;$)
 {
     my($cl, $fields, $s, $score) = @_;
-    my($content, $short) = ();
+    my($content, $short, $nComments) = ();
     $content = applyfilter($article{"$s.content"}, $config{outputfilter})
 	if( $fields =~ /content/i );
 
     $short = applyfilter($article{"$s.short"}, $config{outputfilter})
 	if( $fields =~ /short/i );
 
+    if( $fields =~ /nComments/i ){
+	$nComments = dodbi(sub {
+	    my($dbh) = @_;
+	    my $sth = $dbh->prepare("select count(*) from comment ".
+				    "where brdname='$brdname'&&artid='$s'");
+	    $sth->execute();
+	    return $sth->fetchrow_hashref()->{'count(*)'};
+	}) || 0;
+    }
+
     my($y, $m, $d) = unpackdate($s);
     push @{$th{$cl}}, {year   => $y,
 		       month  => $m,
@@ -316,6 +325,7 @@ sub AddArticle($$$;$)
 				  $article{"$s.author"}),
 		       short  => $short,
 		       score  => $score,
+		       nComments => $nComments,
 		   }
         if( $article{"$s.title"} );
 }
-- 
cgit v1.2.3


From c813760b6a26482eaec0624b74ee968864cee3bc Mon Sep 17 00:00:00 2001
From: in2 
Date: Sun, 6 Jul 2003 03:41:08 +0000
Subject: delete blog comments from mbbsd

git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@1032 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
---
 pttbbs/blog/INSTALL       |  7 +++++--
 pttbbs/mbbsd/Makefile     |  7 ++++++-
 pttbbs/mbbsd/announce.c   | 39 +++++++++++++++++++++++++++++++++++++--
 pttbbs/sample/pttbbs.conf |  9 ++++++++-
 4 files changed, 56 insertions(+), 6 deletions(-)

diff --git a/pttbbs/blog/INSTALL b/pttbbs/blog/INSTALL
index e176ab88..cf0ac672 100644
--- a/pttbbs/blog/INSTALL
+++ b/pttbbs/blog/INSTALL
@@ -1,5 +1,5 @@
 這篇文章在描述怎麼架設 PttBlog, 最後一次修正的時間為:
-$Id: INSTALL,v 1.2 2003/06/05 03:42:06 in2 Exp $
+$Id: INSTALL,v 1.3 2003/07/06 03:41:08 in2 Exp $
 
 請注意,  PttBlog本來主要是設計給 Ptt2 站台使用, 目前正在開發階段,
 並未接受嚴密的測試, 可能還缺少很多功能, 以及可能有許多的 bug.
@@ -45,4 +45,7 @@ $Id: INSTALL,v 1.2 2003/06/05 03:42:06 in2 Exp $
   若不行的話, 通常是 LocalVars.pm 裡面少東西,
   請參考 pttbbs/sample/LocalVars.pm 的 blog 區.
 
-6.將 #define BLOG 加入您的 pttbbs.conf裡面, 重新 build並且 restart.
+6.參考 pttbbs/sample/pttbbs.conf中, 在您的 pttbbs.conf中加入
+  BLOGDB_HOST, BLOGDB_USER, BLOGDB_PASSWD, BLOGDB_DB, BLOGDB_PORT, BLOGDB_SOCK
+  並且重新 compile mbbsd, 在 make 時加入 WITH_BLOG=yes .
+  然後 install 並且 restart
diff --git a/pttbbs/mbbsd/Makefile b/pttbbs/mbbsd/Makefile
index a8ebd584..7d16b04f 100644
--- a/pttbbs/mbbsd/Makefile
+++ b/pttbbs/mbbsd/Makefile
@@ -1,7 +1,12 @@
-# $Id: Makefile,v 1.27 2003/06/28 08:55:40 kcwu Exp $
+# $Id: Makefile,v 1.28 2003/07/06 03:41:08 in2 Exp $
 
 .include "../pttbbs.mk"
 
+.if defined(WITH_BLOG)
+CFLAGS+=  -I/usr/local/include -DBLOG
+LDFLAGS+= -L/usr/local/lib/mysql -lmysqlclient
+.endif
+
 PROG=	mbbsd
 OBJS=	admin.o announce.o args.o bbs.o board.o cache.o cal.o card.o\
 	chat.o chc_draw.o chc_net.o chc_play.o chc_rule.o chicken.o dark.o\
diff --git a/pttbbs/mbbsd/announce.c b/pttbbs/mbbsd/announce.c
index b0130d92..f0db7535 100644
--- a/pttbbs/mbbsd/announce.c
+++ b/pttbbs/mbbsd/announce.c
@@ -1,4 +1,4 @@
-/* $Id: announce.c,v 1.29 2003/06/28 09:27:15 kcwu Exp $ */
+/* $Id: announce.c,v 1.30 2003/07/06 03:41:08 in2 Exp $ */
 #include "bbs.h"
 
 #define PATHLEN     256
@@ -1079,6 +1079,7 @@ Announce()
 }
 
 #ifdef BLOG
+#include 
 void BlogMain(int num)
 {
     int     oldmode = currutmp->mode;
@@ -1099,7 +1100,9 @@ void BlogMain(int num)
 	       "  只在部落格資料整個亂掉的時候才使用\n"
 	       "\n"
 	       "3.將本文加入部落格\n"
-	       "  將游標所在位置的文章加入部落格\n");
+	       "  將游標所在位置的文章加入部落格\n"
+	       "\n"
+	       "4.刪除迴響\n");
 	switch( getans("請選擇(0-3)?[0]") ){
 	case '1':
 	    snprintf(genbuf, sizeof(genbuf),
@@ -1117,6 +1120,38 @@ void BlogMain(int num)
 		     "bin/builddb.pl -f -n %d %s", num, currboard);
 	    system(genbuf);
 	    break;
+	case '4':{
+	    char    hash[35];
+	    getdata(16, 0, "請輸入該篇的雜湊值: ",
+		    hash, sizeof(hash), DOECHO);
+	    if( hash[0] != 0 && 
+		getans("請確定刪除(Y/N)?[N] ") == 'y' ){
+		MYSQL   mysql;
+		char    cmd[256];
+		
+		sprintf(cmd, "delete from comment where "
+			"hash='%s'&&brdname='%s'", hash, currboard);
+#ifdef DEBUG
+		vmsg(cmd);
+#endif
+		if( !(!mysql_init(&mysql) ||
+		      !mysql_real_connect(&mysql, BLOGDB_HOST, BLOGDB_USER,
+					  BLOGDB_PASSWD, BLOGDB_DB, 
+					  BLOGDB_PORT, BLOGDB_SOCK, 0) ||
+		      mysql_query(&mysql, cmd)) )
+		    vmsg("資料刪除完成");
+		else
+		    vmsg(
+#ifdef DEBUG
+			 mysql_error(&mysql)
+#else
+			 "database internal error"
+#endif
+			 );
+		mysql_close(&mysql);
+	    }
+	}
+	    break;
 	default:
 	    exit = 1;
 	    break;
diff --git a/pttbbs/sample/pttbbs.conf b/pttbbs/sample/pttbbs.conf
index 982f0007..8728884f 100644
--- a/pttbbs/sample/pttbbs.conf
+++ b/pttbbs/sample/pttbbs.conf
@@ -1,3 +1,5 @@
+/* $Id: pttbbs.conf,v 1.14 2003/07/06 03:41:08 in2 Exp $ */
+
 /* 定義 BBS 站名位址 */
 #define BBSNAME         "新批踢踢"			/* 中文站名 */
 #define MYHOSTNAME      "ptt2.cc"          		/* 網路位址 */
@@ -90,7 +92,12 @@
 
 /* 若定義, 則啟動 bbs中連至 BLOG 的 interface
    請參閱 pttbbs/blog/ */
-//#define BLOG
+//#define BLOGDB_HOST   "10.1.1.1"
+//#define BLOGDB_USER   "USER"
+//#define BLOGDB_PASSWD "PASSWORD"
+//#define BLOGDB_DB     "DATABASE"
+//#define BLOGDB_PORT   3306
+//#define BLOGDB_SOCK   NULL
 
 /* 若定義, 則在文章列表的時候不同日期會標上不同顏色 */
 //#define COLORDATE
-- 
cgit v1.2.3


From a8bdd6f8b19e162209dbc247d322e1a24322a96b Mon Sep 17 00:00:00 2001
From: in2 
Date: Sun, 6 Jul 2003 03:56:38 +0000
Subject: for deleting, add hash

git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@1033 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
---
 pttbbs/blog/blog.pl | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/pttbbs/blog/blog.pl b/pttbbs/blog/blog.pl
index 78885190..838fa676 100755
--- a/pttbbs/blog/blog.pl
+++ b/pttbbs/blog/blog.pl
@@ -1,5 +1,5 @@
 #!/usr/bin/perl
-# $Id: blog.pl,v 1.27 2003/07/05 09:58:53 in2 Exp $
+# $Id: blog.pl,v 1.28 2003/07/06 03:56:38 in2 Exp $
 use CGI qw/:standard/;
 use lib qw/./;
 use LocalVars;
@@ -13,6 +13,7 @@ use OurNet::FuzzyIndex;
 use DBI;
 use DBD::mysql;
 use POSIX;
+use MD5;
 
 use vars qw/@emonth @cnumber %config %attr %article %th $dbh $brdname/;
 
@@ -252,16 +253,20 @@ sub main
 	if( $name && $comment ){
 	    dodbi(sub {
 		my($dbh) = @_;
-		$dbh->do("insert into comment (brdname, artid, name, mail, ".
-			 "content, mtime) values ('$brdname', '$th{key}', ".
-			 "'$name', '$mail', '$comment', ". time(). ")");
+		my($t, $hash);
+		$t = time();
+		$hash = MD5->hexhash("$t$th{key}$name$mail$comment");
+		$dbh->do('insert into comment '.
+			 '(brdname, artid, name, mail, content, mtime, hash) '.
+			 "values ('$brdname', '$th{key}', '$name', '$mail', ".
+			 "'$comment', '$t', '$hash')");
 	    });
 	}
 
 	dodbi(sub {
 	    my($dbh) = @_;
 	    my($sth, $t);
-	    $sth = $dbh->prepare("select mtime,name,mail,content ".
+	    $sth = $dbh->prepare("select mtime,name,mail,content,hash ".
 				 "from comment ".
 				 "where brdname='$brdname'&&artid='$th{key}' ".
 				 "order by mtime desc");
-- 
cgit v1.2.3


From 3281d8c586d5ca6732951ae7a71430bcc925ab41 Mon Sep 17 00:00:00 2001
From: in2 
Date: Sun, 6 Jul 2003 03:58:43 +0000
Subject: add mysql table structure

git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@1034 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
---
 pttbbs/blog/INSTALL | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)

diff --git a/pttbbs/blog/INSTALL b/pttbbs/blog/INSTALL
index cf0ac672..29f1e566 100644
--- a/pttbbs/blog/INSTALL
+++ b/pttbbs/blog/INSTALL
@@ -1,5 +1,5 @@
 這篇文章在描述怎麼架設 PttBlog, 最後一次修正的時間為:
-$Id: INSTALL,v 1.3 2003/07/06 03:41:08 in2 Exp $
+$Id: INSTALL,v 1.4 2003/07/06 03:58:43 in2 Exp $
 
 請注意,  PttBlog本來主要是設計給 Ptt2 站台使用, 目前正在開發階段,
 並未接受嚴密的測試, 可能還缺少很多功能, 以及可能有許多的 bug.
@@ -49,3 +49,21 @@ $Id: INSTALL,v 1.3 2003/07/06 03:41:08 in2 Exp $
   BLOGDB_HOST, BLOGDB_USER, BLOGDB_PASSWD, BLOGDB_DB, BLOGDB_PORT, BLOGDB_SOCK
   並且重新 compile mbbsd, 在 make 時加入 WITH_BLOG=yes .
   然後 install 並且 restart
+
+7.關於 Mysql共須要下面兩個 table (可以直接複製過去跑)
+	CREATE TABLE `comment` (
+	  `brdname` varchar(13) NOT NULL default '',
+	  `artid` int(11) NOT NULL default '0',
+	  `name` varchar(32) NOT NULL default '',
+	  `mail` varchar(64) NOT NULL default '',
+	  `content` text NOT NULL,
+	  `mtime` int(11) NOT NULL default '0',
+	  `hash` varchar(32) NOT NULL default ''
+	) TYPE=MyISAM;
+
+	CREATE TABLE `counter` (
+	  `k` char(32) NOT NULL default '',
+	  `v` int(11) NOT NULL default '0',
+	  `mtime` int(11) NOT NULL default '0',
+	  PRIMARY KEY  (`k`)
+	) TYPE=MyISAM;
-- 
cgit v1.2.3


From 4cbd7f088f1acc75c05304f7809761a18f20ff58 Mon Sep 17 00:00:00 2001
From: in2 
Date: Sun, 6 Jul 2003 06:45:51 +0000
Subject: =?UTF-8?q?strstr("=EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD",=20"?=
 =?UTF-8?q?=EF=BF=BD=EF=BF=BD")=20return=20true?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@1035 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
---
 pttbbs/mbbsd/user.c | 16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)

diff --git a/pttbbs/mbbsd/user.c b/pttbbs/mbbsd/user.c
index d880f706..553021cc 100644
--- a/pttbbs/mbbsd/user.c
+++ b/pttbbs/mbbsd/user.c
@@ -1,4 +1,4 @@
-/* $Id: user.c,v 1.65 2003/07/04 08:35:51 in2 Exp $ */
+/* $Id: user.c,v 1.66 2003/07/06 06:45:51 in2 Exp $ */
 #include "bbs.h"
 
 static char    *sex[8] = {
@@ -1048,13 +1048,13 @@ toregister(char *email, char *genbuf, char *phone, char *career, char fore,
 static int HaveRejectStr(char *s, char **rej)
 {
     int     i;
-    char    *rejectstr[] =
+    char    *ptr, *rejectstr[] =
 	{"幹", "阿", "不", "你媽", "某", "笨", "呆", "..", "xx",
 	 "你管", "管我", "猜", "天才", "超人", 
 	 "ㄅ", "ㄆ", "ㄇ", "ㄈ", "ㄉ", "ㄊ", "ㄋ", "ㄌ", "ㄍ", "ㄎ", "ㄏ",
-	 "ㄐ", "ㄑ", "ㄒ", "ㄓ", "ㄔ", "ㄕ", "ㄖ", "ㄗ", "ㄘ", "ㄙ", "ㄧ",
-	 "ㄨ", "ㄩ", "ㄚ", "ㄛ", "ㄜ", "ㄝ", "ㄞ", "ㄟ", "ㄠ", "ㄡ", "ㄢ",
-	 "ㄣ", "ㄤ", "ㄥ", "ㄦ", NULL};
+	 "ㄐ", "ㄑ", "ㄒ", "ㄓ",/*"ㄔ",*/    "ㄕ", "ㄖ", "ㄗ", "ㄘ", "ㄙ",
+	 "ㄧ", "ㄨ", "ㄩ", "ㄚ", "ㄛ", "ㄜ", "ㄝ", "ㄞ", "ㄟ", "ㄠ", "ㄡ",
+	 "ㄢ", "ㄣ", "ㄤ", "ㄥ", "ㄦ", NULL};
 
     if( rej != NULL )
 	for( i = 0 ; rej[i] != NULL ; ++i )
@@ -1064,6 +1064,12 @@ static int HaveRejectStr(char *s, char **rej)
     for( i = 0 ; rejectstr[i] != NULL ; ++i )
 	if( strstr(s, rejectstr[i]) )
 	    return 1;
+
+    if( (ptr = strstr(s, "ㄔ")) != NULL ){
+	if( ptr != s && strncmp(ptr - 1, "都市", 4) == 0 )
+	    return 0;
+	return 1;
+    }
     return 0;
 }
 
-- 
cgit v1.2.3


From 134f7a261f1013f3fcd231d54b399cb4e9b0d908 Mon Sep 17 00:00:00 2001
From: in2 
Date: Sun, 6 Jul 2003 07:23:10 +0000
Subject: dirty fix search in userlist

git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@1036 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
---
 pttbbs/mbbsd/talk.c | 43 ++++++++++++++++++++++++++++++-------------
 1 file changed, 30 insertions(+), 13 deletions(-)

diff --git a/pttbbs/mbbsd/talk.c b/pttbbs/mbbsd/talk.c
index 08ef5020..239c2ded 100644
--- a/pttbbs/mbbsd/talk.c
+++ b/pttbbs/mbbsd/talk.c
@@ -1,4 +1,4 @@
-/* $Id: talk.c,v 1.110 2003/05/18 07:20:29 in2 Exp $ */
+/* $Id: talk.c,v 1.111 2003/07/06 07:23:10 in2 Exp $ */
 #include "bbs.h"
 
 #define QCAST   int (*)(const void *, const void *)
@@ -1824,9 +1824,8 @@ userlist(void)
     static char     show_uid = 0;
     static char     show_board = 0;
     static char     show_pid = 0;
-    char            genbuf[256];
-    int             page, offset, pickup_way, ch, leave, redraw, redrawall,
-                    fri_stat;
+    char            genbuf[256], skippickup = 0, redraw, redrawall;
+    int             page, offset, pickup_way, ch, leave, fri_stat;
     int             nfriend, myfriend, friendme, bfriend, badfriend, i;
     time_t          lastupdate;
 
@@ -1843,8 +1842,9 @@ userlist(void)
      * leave:     離開使用者名單
      */
     while (!leave) {
-	pickup(currpickup, pickup_way, &page,
-	       &nfriend, &myfriend, &friendme, &bfriend, &badfriend);
+	if( !skippickup )
+	    pickup(currpickup, pickup_way, &page,
+		   &nfriend, &myfriend, &friendme, &bfriend, &badfriend);
 	draw_pickup(redrawall, currpickup, pickup_way, page,
 		    show_mode, show_uid, show_board, show_pid,
 		    myfriend, friendme, bfriend, badfriend);
@@ -1866,7 +1866,7 @@ userlist(void)
 		continue;
 	    }
 	}
-	redraw = redrawall = 0;
+	skippickup = redraw = redrawall = 0;
 	lastupdate = now;
 	while (!redraw) {
 	    ch = cursor_key(offset + 3, 0);
@@ -2012,21 +2012,38 @@ userlist(void)
 		    if (si >= 0) {
 			pickup_t        friends[MAX_FRIEND + 1];
 			int             nGots, i;
-			fi = SHM->sorted[SHM->currsorted][0][si] -
-			    &SHM->uinfo[0];
+			userinfo_t **utmp =
+			    SHM->sorted[SHM->currsorted]
+			    [((pickup_way == 0) ? 0 : (pickup_way - 1))];
+			
+			fi = utmp[si] - &SHM->uinfo[0];
 
 			nGots = pickup_myfriend(friends, &myfriend,
 						&friendme, &badfriend);
 			for (i = 0; i < nGots; ++i)
 			    if (friends[i].uoffset == fi)
 				break;
-			if (i != nGots) {
+
+			fi = 0;
+			offset = 0;
+			if( i != nGots ){
 			    page = i / nPickups;
-			    offset = i % nPickups;
-			} else {
+			    for( ; i < nGots && fi < nPickups ; ++i )
+				if( isvisible(currutmp, friends[i].ui) )
+				    currpickup[fi++] = friends[i];
+			    i = 0;
+			}
+			else{
 			    page = (si + nGots) / nPickups;
-			    offset = (si + nGots) % nPickups;
+			    i = si;
 			}
+
+			for( ; fi < nPickups && i < SHM->UTMPnumber ; ++i )
+			    if( isvisible(currutmp, utmp[i]) ){
+				currpickup[fi].ui = utmp[i];
+				currpickup[fi++].friend = 0;
+			    }
+			skippickup = 1;
 		    }
 		    redrawall = redraw = 1;
 		}
-- 
cgit v1.2.3


From 2e595aa432ea149ee50b160ed6bd71b04e68a628 Mon Sep 17 00:00:00 2001
From: kcwu 
Date: Sun, 6 Jul 2003 23:09:25 +0000
Subject: fix typo

git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@1037 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
---
 pttbbs/mbbsd/bbs.c  |  4 ++--
 pttbbs/mbbsd/var.c  |  6 +++---
 pttbbs/mbbsd/vote.c | 10 +++++-----
 3 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/pttbbs/mbbsd/bbs.c b/pttbbs/mbbsd/bbs.c
index b5e5c454..a113b03d 100644
--- a/pttbbs/mbbsd/bbs.c
+++ b/pttbbs/mbbsd/bbs.c
@@ -1,4 +1,4 @@
-/* $Id: bbs.c,v 1.102 2003/07/01 17:39:27 victor Exp $ */
+/* $Id: bbs.c,v 1.103 2003/07/06 23:09:25 kcwu Exp $ */
 #include "bbs.h"
 
 static int recommend(int ent, fileheader_t * fhdr, char *direct);
@@ -1918,7 +1918,7 @@ static char    *board_help[] = {
     "\01板主命令",
     "(M/o)     舉行投票/編私投票名單 (m/c/g) 保留文章/選錄精華/文摘",
     "(D)       刪除一段範圍的文章    (T/B)   重編文章標題/重編看板標題",
-    "(I)       開放/禁止看版推薦     (t/^D)  標記文章/砍除標記的文章",
+    "(I)       開放/禁止看板推薦     (t/^D)  標記文章/砍除標記的文章",
     "(O)       編輯Post注意事項      (H)/(Y) 看板隱藏/現身 取消推薦文章",
 #ifdef NO_GAMBLE
     "(W/K/v)   編進板畫面/水桶名單/可看見名單",
diff --git a/pttbbs/mbbsd/var.c b/pttbbs/mbbsd/var.c
index 09a90850..59e40eb4 100644
--- a/pttbbs/mbbsd/var.c
+++ b/pttbbs/mbbsd/var.c
@@ -1,4 +1,4 @@
-/* $Id: var.c,v 1.19 2003/05/30 10:28:32 in2 Exp $ */
+/* $Id: var.c,v 1.20 2003/07/06 23:09:25 kcwu Exp $ */
 #define INCLUDE_VAR_H
 #include "bbs.h"
 
@@ -231,12 +231,12 @@ char           *ModeTypeTable[MAX_MODES] = {
     "打地鼠",			/* GOPHER */
     "看News",			/* NEWS */
     "情書產生器",		/* LOVE */
-    "編籍輔助器",		/* EDITEXP */
+    "編輯輔助器",		/* EDITEXP */
     "申請IP位址",		/* IPREG */
     "網管辦公中",		/* NetAdm */
     "虛擬實業坊",		/* DRINK */
     "計算機",			/* CAL */
-    "編籍座右銘",		/* PROVERB */
+    "編輯座右銘",		/* PROVERB */
     "公佈欄",			/* ANNOUNCE */
     "刻流言板",			/* EDNOTE */
     "英漢翻譯機",		/* CDICT */
diff --git a/pttbbs/mbbsd/vote.c b/pttbbs/mbbsd/vote.c
index a71040c9..9304a697 100644
--- a/pttbbs/mbbsd/vote.c
+++ b/pttbbs/mbbsd/vote.c
@@ -1,4 +1,4 @@
-/* $Id: vote.c,v 1.19 2003/03/03 15:32:15 in2 Exp $ */
+/* $Id: vote.c,v 1.20 2003/07/06 23:09:25 kcwu Exp $ */
 #include "bbs.h"
 
 static int      total;
@@ -7,7 +7,7 @@ static char     STR_bv_control[] = "control";	/* 
 static char     STR_bv_desc[] = "desc";	/* 投票目的 */
 static char     STR_bv_ballots[] = "ballots";
 static char     STR_bv_flags[] = "flags";
-static char     STR_bv_comments[] = "comments";	/* 投票者的建意 */
+static char     STR_bv_comments[] = "comments";	/* 投票者的建議 */
 static char     STR_bv_limited[] = "limited";	/* 私人投票 */
 static char     STR_bv_title[] = "vtitle";
 
@@ -17,7 +17,7 @@ static char     STR_new_control[] = "control0\0";	/* 
 static char     STR_new_desc[] = "desc0\0";	/* 投票目的 */
 static char     STR_new_ballots[] = "ballots0\0";
 static char     STR_new_flags[] = "flags0\0";
-static char     STR_new_comments[] = "comments0\0";	/* 投票者的建意 */
+static char     STR_new_comments[] = "comments0\0";	/* 投票者的建議 */
 static char     STR_new_limited[] = "limited0\0";	/* 私人投票 */
 static char     STR_new_title[] = "vtitle0\0";
 
@@ -673,7 +673,7 @@ vote_maintain(char *bname)
     unlink(buf);
 
     getdata(4, 0,
-	    "是否限定投票者名單:(y)編籍可投票人員名單[n]任何人皆可投票:[N]",
+	    "是否限定投票者名單:(y)編輯可投票人員名單[n]任何人皆可投票:[N]",
 	    inbuf, 2, LCECHO);
     setbfile(buf, bname, STR_new_limited);
     if (inbuf[0] == 'y') {
@@ -905,7 +905,7 @@ user_vote_one(char *bname, int ind)
 	}
 
 	if (vote_flag(bname, ind, vote[0]) != 0)
-	    prints("重覆投票! 不予計票。");
+	    prints("重複投票! 不予計票。");
 	else {
 	    setbfile(buf, bname, STR_new_ballots);
 	    if ((fd = open(buf, O_WRONLY | O_CREAT | O_APPEND, 0600)) == 0)
-- 
cgit v1.2.3


From 7bf913c8ea67498ee4f70aa4f65e3af6703ebe9a Mon Sep 17 00:00:00 2001
From: in2 
Date: Mon, 7 Jul 2003 04:16:58 +0000
Subject: b2g

git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@1038 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
---
 pttbbs/staticweb/b2g.pm | 13985 ++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 13985 insertions(+)
 create mode 100644 pttbbs/staticweb/b2g.pm

diff --git a/pttbbs/staticweb/b2g.pm b/pttbbs/staticweb/b2g.pm
new file mode 100644
index 00000000..c7cf318d
--- /dev/null
+++ b/pttbbs/staticweb/b2g.pm
@@ -0,0 +1,13985 @@
+package b2g;
+use Exporter;
+use vars qw(%b2g);
+
+%b2g = (
+' ' => '﹛',
+',' => 'ㄛ',
+'、' => '﹜',
+'。' => '﹝',
+'.' => 'ㄝ',
+'•' => '﹞',
+';' => '˙',
+':' => 'ㄩ',
+'?' => 'ˋ',
+'!' => 'ㄐ',
+'︰' => 'ㄩ',
+'…' => '#',
+'‥' => '“',
+'﹐' => 'ㄛ',
+'、' => '﹜',
+'﹒' => 'ㄝ',
+'·' => '﹞',
+'﹔' => '˙',
+'﹕' => 'ㄩ',
+'﹖' => 'ˋ',
+'﹗' => 'ㄐ',
+'|' => '',
+'–' => '求',
+'︱' => '',
+'—' => '〞',
+'︳' => '估',
+'╴' => '',
+'︴' => '佐',
+'﹏\' => '姊',
+'(' => 'ㄗ',
+')' => 'ㄘ',
+'︵' => 'ㄗ',
+'︶' => '艮',
+'{' => '',
+'}' => '',
+'︷' => '佞',
+'︸' => '伴',
+'〔' => '〃',
+'〕' => '○',
+'︹' => '色',
+'︺' => '艾',
+'【' => '▽',
+'】' => '▼',
+'︻' => '佇',
+'︼' => '佗',
+'《' => '▲',
+'》' => '◎',
+'︽' => '行',
+'︾' => '衣',
+'〈' => '●',
+'〉' => '△',
+'︿' => '_',
+'﹀' => 'ˍ',
+'「' => '☆',
+'」' => '★',
+'﹁' => '西',
+'﹂' => '阡',
+'『' => '◇',
+'』' => '◆',
+'﹃' => '串',
+'﹄' => '亨',
+'﹙' => 'ㄗ',
+'﹚' => 'ㄘ',
+'﹛' => '',
+'﹜' => '',
+'﹝' => '〃',
+'﹞' => '○',
+'‘' => '&',
+'’' => '*',
+'“' => '※',
+'”' => '§',
+'〝' => '',
+'〞' => 'ㄑ',
+'‵' => '',
+'′' => '∩',
+'#' => 'ㄒ',
+'&' => 'ㄕ',
+'*' => 'ㄙ',
+'※' => '↗',
+'§' => '∫',
+'〃' => '”',
+'○' => '♀',
+'●' => '♂',
+'△' => '→',
+'▲' => '↖',
+'◎' => '♁',
+'☆' => '∵',
+'★' => '∴',
+'◇' => '☉',
+'◆' => '↑',
+'□' => '↓',
+'■' => '←',
+'▽' => '',
+'▼' => '',
+'㊣' => '呼',
+'℅' => '沁',
+'‾' => '‘',
+' ̄' => '',
+'_' => '',
+'ˍ' => 'ㄜ',
+'﹉' => '姑',
+'﹊' => '姆',
+'﹍' => '始',
+'﹎' => '姓',
+'﹋' => '姐',
+'﹌' => '姍',
+'﹟' => 'ㄒ',
+'﹠' => 'ㄕ',
+'﹡' => 'ㄙ',
+'+' => 'ㄚ',
+'-' => 'ㄜ',
+'×' => '℅',
+'÷' => '‾',
+'±' => '㊣',
+'√' => '﹟',
+'<' => 'ˉ',
+'>' => 'ˇ',
+'=' => 'ˊ',
+'≦' => '≒',
+'≧' => '≡',
+'≠' => '≧',
+'∞' => '﹢',
+'≒' => '沌',
+'≡' => '√',
+'﹢' => '',
+'﹣' => '',
+'﹤' => '',
+'﹥' => '',
+'﹦' => '',
+'∼' => '‵',
+'∩' => '﹎',
+'∪' => '﹍',
+'⊥' => '﹠',
+'∠' => '+',
+'∟' => '沐',
+'⊿' => '沒',
+'㏒' => '咎',
+'㏑' => '命',
+'∫' => '÷',
+'∮' => '±',
+'∵' => '﹣',
+'∴' => '﹤',
+'♀' => '﹦',
+'♂' => '﹥',
+'♁' => '',
+'☉' => '×',
+'↑' => '∥',
+'↓' => '∣',
+'←' => '↘',
+'→' => '↙',
+'↖' => '沉',
+'↗' => '沅',
+'↙' => '汪',
+'↘' => '沛',
+'∥' => '′',
+'∣' => '',
+'/' => 'ㄞ',
+'\' => '',
+'/' => 'ㄞ',
+'\' => '',
+'$' => '∠',
+'¥' => 'ㄓ',
+'〒' => '',
+'¢' => '⊿',
+'£' => '㏒',
+'%' => 'ㄔ',
+'@' => '',
+'℃' => '⊥',
+'℉' => '沈',
+'﹩' => '',
+'﹪' => '',
+'﹫' => '',
+'㏕' => '固',
+'㎜' => '呶',
+'㎝' => '和',
+'㎞' => '咚',
+'㏎' => '咋',
+'㎡' => '呢',
+'㎎' => '咐',
+'㎏' => '呱',
+'㏄' => '周',
+'°' => '∼',
+'兙' => '',
+'兛' => '',
+'兞' => '',
+'兝\' => '',
+'兡' => '',
+'兣' => '',
+'嗧' => '',
+'瓩' => '',
+'糎' => '嘻',
+'▁' => '肝',
+'▂' => '肘',
+'▃' => '肛',
+'▄' => '肚',
+'▅' => '育',
+'▆' => '良',
+'▇' => '芒',
+'█' => '',
+'▏' => '',
+'▎' => '',
+'▍' => '',
+'▌' => '',
+'▋' => '',
+'▊' => '',
+'▉' => '',
+'┼' => '拈',
+'┴' => '拂',
+'┬' => '房',
+'┤' => '怕',
+'├' => '念',
+'▔' => '',
+'─' => '岸',
+'│' => '岫',
+'▕' => '',
+'┌' => '庚',
+'┐' => '庖',
+'└' => '弩',
+'┘' => '彼',
+'╭' => '秀',
+'╮' => '禿',
+'╰' => '系',
+'╯' => '究',
+'═' => '/',
+'╞' => '忿',
+'╪' => '押',
+'╡' => '怡',
+'◢' => '',
+'◣' => '',
+'◥' => '',
+'◤' => '',
+'╱' => '罕',
+'╲' => '肖',
+'╳' => '肓',
+'0' => 'ㄟ',
+'1' => 'ㄠ',
+'2' => 'ㄡ',
+'3' => 'ㄢ',
+'4' => 'ㄣ',
+'5' => 'ㄤ',
+'6' => 'ㄥ',
+'7' => 'ㄦ',
+'8' => 'ㄧ',
+'9' => 'ㄨ',
+'Ⅰ' => 'i',
+'Ⅱ' => 'j',
+'Ⅲ' => 'k',
+'Ⅳ' => 'l',
+'Ⅴ' => 'm',
+'Ⅵ' => 'n',
+'Ⅶ' => 'o',
+'Ⅷ' => 'p',
+'Ⅸ' => 'q',
+'Ⅹ' => 'r',
+'〡' => '咖',
+'〢' => '呸',
+'〣' => '咕',
+'〤' => '咀',
+'〥' => '呻',
+'〦' => '呷',
+'〧' => '咄',
+'〨' => '咒',
+'〩' => '恅',
+'十' => '坋',
+'卄' => '`',
+'卅' => '埵',
+'A' => '',
+'B' => '',
+'C' => '',
+'D' => '',
+'E' => '',
+'F' => '',
+'G' => '',
+'H' => '',
+'I' => '',
+'J' => '',
+'K' => '',
+'L' => '',
+'M' => '',
+'N' => '',
+'O' => '',
+'P' => '',
+'Q' => '',
+'R' => '',
+'S' => '',
+'T' => '',
+'U' => '',
+'V' => '',
+'W' => '',
+'X' => '',
+'Y' => '',
+'Z' => '',
+'a' => '',
+'b' => '',
+'c' => '',
+'d' => '',
+'e' => '',
+'f' => '',
+'g' => '',
+'h' => '',
+'i' => '',
+'j' => '',
+'k' => '',
+'l' => '',
+'m' => '',
+'n' => '',
+'o' => '',
+'p' => '',
+'q' => '',
+'r' => '',
+'s' => '',
+'t' => '',
+'u' => '',
+'v' => '',
+'w' => '',
+'x' => '',
+'y' => '',
+'z' => '',
+'Α' => '式',
+'Β' => '弛',
+'Γ' => '忙',
+'Δ' => '忖',
+'Ε' => '戎',
+'Ζ' => '戌',
+'Η' => '戍',
+'Θ' => '成',
+'Ι' => '扣',
+'Κ' => '扛',
+'Λ' => '托',
+'Μ' => '收',
+'Ν' => '早',
+'Ξ' => '旨',
+'Ο' => '旬',
+'Π' => '旭',
+'Ρ' => '曲',
+'Σ' => '曳',
+'Τ' => '有',
+'Υ' => '朽',
+'Φ' => '朴',
+'Χ' => '朱',
+'Ψ' => '朵',
+'Ω' => '次',
+'α\' => '汐',
+'β' => '汕',
+'γ' => '污',
+'δ' => '汛',
+'ε' => '汍',
+'ζ' => '汎',
+'η' => '灰',
+'θ' => '牟',
+'ι' => '牝',
+'κ' => '百',
+'λ' => '竹',
+'μ' => '米',
+'ν' => '糸',
+'ξ' => '缶',
+'ο' => '羊',
+'π' => '羽',
+'ρ' => '老',
+'σ' => '考',
+'τ' => '而',
+'υ' => '耒',
+'φ' => '耳',
+'χ' => '聿',
+'ψ' => '肉',
+'ω' => '肋',
+'ㄅ' => '乳',
+'ㄆ' => '事',
+'ㄇ' => '些',
+'ㄈ' => '亞',
+'ㄉ' => '享',
+'ㄊ' => '京',
+'ㄋ' => '佯',
+'ㄌ' => '依',
+'ㄍ' => '侍',
+'ㄎ' => '佳',
+'ㄏ' => '使',
+'ㄐ' => '佬',
+'ㄑ' => '供',
+'ㄒ' => '例',
+'ㄓ' => '來',
+'ㄔ' => '侃',
+'ㄕ' => '佰',
+'ㄖ' => '併',
+'ㄗ' => '侈',
+'ㄘ' => '佩',
+'ㄙ' => '佻',
+'ㄚ' => '侖',
+'ㄛ' => '佾',
+'ㄜ' => '侏',
+'ㄝ' => '侑',
+'ㄞ' => '佺',
+'ㄟ' => '兔',
+'ㄠ' => '兒',
+'ㄡ' => '兕',
+'ㄢ' => '兩',
+'ㄣ' => '具',
+'ㄤ' => '其',
+'ㄥ' => '典',
+'ㄦ' => '冽',
+'ㄧ' => '函',
+'ㄨ' => '刻',
+'ㄩ' => '券',
+'˙' => '步',
+'ˉ' => '‘',
+'ˊ' => '杓',
+'ˇ' => '’',
+'ˋ' => '',
+'' => '↓',
+'' => '↓',
+'' => '↓',
+'' => '↓',
+'' => '↓',
+'' => '↓',
+'' => '↓',
+'' => '↓',
+'' => '↓',
+'' => '↓',
+'' => '↓',
+'' => '↓',
+'' => '↓',
+'' => '↓',
+'' => '↓',
+'' => '↓',
+'' => '↓',
+'' => '↓',
+'' => '↓',
+'' => '↓',
+'' => '↓',
+'' => '↓',
+'' => '↓',
+'' => '↓',
+'' => '↓',
+'' => '↓',
+'' => '↓',
+'' => '↓',
+'' => '↓',
+'' => '↓',
+'' => '↓',
+'' => '↓',
+'' => '↓',
+'' => '↓',
+'' => '↓',
+'' => '↓',
+'' => '↓',
+'' => '↓',
+'' => '↓',
+'' => '↓',
+'' => '↓',
+'' => '↓',
+'' => '↓',
+'' => '↓',
+'' => '↓',
+'' => '↓',
+'' => '↓',
+'' => '↓',
+'' => '↓',
+'' => '↓',
+'' => '↓',
+'' => '↓',
+'' => '↓',
+'' => '↓',
+'' => '↓',
+'' => '↓',
+'' => '↓',
+'' => '↓',
+'' => '↓',
+'' => '↓',
+'' => '↓',
+'' => '↓',
+'' => '↓',
+'一' => '珨',
+'乙' => '眣',
+'丁' => '間',
+'七' => 'ほ',
+'乃' => '騰',
+'九' => '嬝',
+'了' => '賸',
+'二' => '媼',
+'人' => '',
+'儿' => '嫁',
+'入' => '',
+'八' => '匐',
+'几' => '撓',
+'刀' => '絮',
+'刁' => '街',
+'力' => '薯',
+'匕' => '堸',
+'十' => '坋',
+'卜' => '眺',
+'又' => '衱',
+'三' => '',
+'下' => '狟',
+'丈' => '桾',
+'上' => '奻',
+'丫' => '挩',
+'丸' => '侳',
+'凡' => '歇',
+'久' => '壅',
+'么\' => '繫',
+'也' => '珩',
+'乞' => 'ゎ',
+'于' => '衾',
+'亡' => '厗',
+'兀' => '堧',
+'刃' => '',
+'勺' => '屺',
+'千' => 'ロ',
+'叉' => '脫',
+'口' => '諳',
+'土' => '芩',
+'士' => '尪',
+'夕' => '浀',
+'大' => '湮',
+'女' => '躓',
+'子' => '赽',
+'孑' => '篊',
+'孓' => '箵',
+'寸' => '渡',
+'小' => '苤',
+'尢' => '痼',
+'尸' => '坌',
+'山' => '刓',
+'川' => '捶',
+'工' => '馱',
+'己' => '撩',
+'已' => '眒',
+'巳' => '侒',
+'巾' => '踫',
+'干' => '補',
+'廾' => '甝',
+'弋' => '蒏',
+'弓' => '僮',
+'才' => '符',
+'丑' => '堯',
+'丐' => '堣',
+'不' => '祥',
+'中' => '笢',
+'丰' => '猿',
+'丹' => '竣',
+'之' => '眳',
+'尹' => '窇',
+'予' => '軑',
+'云' => '堁',
+'井' => '凝',
+'互' => '誑',
+'五' => '拻',
+'亢' => '蕩',
+'仁' => '',
+'什' => '妦',
+'仃' => '崹',
+'仆' => 'ど',
+'仇' => '喫',
+'仍' => '',
+'今' => '踏',
+'介' => '賡',
+'仄' => '媃',
+'元' => '啋',
+'允' => '埰',
+'內' => '囀',
+'六' => '鞠',
+'兮' => '殽',
+'公' => '鼠',
+'冗' => '',
+'凶' => '倜',
+'分' => '煦',
+'切' => 'з',
+'刈' => '尌',
+'勻' => '埱',
+'勾' => '僑',
+'勿' => '昦',
+'化' => '趙',
+'匹' => 'ぁ',
+'午' => '敁',
+'升' => '汔',
+'卅' => '埵',
+'卞' => '勗',
+'厄' => '塌',
+'友' => '衭',
+'及' => '摯',
+'反' => '毀',
+'壬' => '',
+'天' => '毞',
+'夫' => '痲',
+'太' => '怮',
+'夭' => '堬',
+'孔' => '謂',
+'少' => '屾',
+'尤' => '蚧',
+'尺' => '喜',
+'屯' => '迋',
+'巴' => '匙',
+'幻' => '酵',
+'廿' => '堨',
+'弔' => '裂',
+'引' => '竘',
+'心' => '陑',
+'戈' => '資',
+'戶' => '誧',
+'手' => '忒',
+'扎' => '崨',
+'支' => '盓',
+'文' => '恅',
+'斗' => '須',
+'斤' => '踝',
+'方' => '源',
+'日' => '',
+'曰' => '堇',
+'月' => '堎',
+'木' => '躂',
+'欠' => 'Й',
+'止' => '砦',
+'歹' => '渦',
+'毋' => '拺',
+'比' => '掀',
+'毛' => '禱',
+'氏' => '庌',
+'水' => '阨',
+'火' => '鳶',
+'爪' => '蛈',
+'父' => '虜',
+'爻' => '堻',
+'片' => 'え',
+'牙' => '挴',
+'牛' => '籟',
+'犬' => '',
+'王' => '卼',
+'丙' => '梡',
+'世' => '岍',
+'丕' => '塈',
+'且' => 'й',
+'丘' => '⑧',
+'主' => '翋',
+'乍' => '敓',
+'乏' => '椰',
+'乎' => '綱',
+'以' => '眕',
+'付' => '葆',
+'仔' => '豝',
+'仕' => '帊',
+'他' => '坻',
+'仗' => '梋',
+'代' => '測',
+'令' => '鍔',
+'仙' => '珈',
+'仞' => '嵀',
+'充' => '喃',
+'兄' => '倗',
+'冉' => '',
+'冊' => '聊',
+'冬' => '隄',
+'凹' => '側',
+'出' => '堤',
+'凸' => '芧',
+'刊' => '膳',
+'加' => '樓',
+'功\' => '髡',
+'包' => '婦',
+'匆' => '棍',
+'北' => '控',
+'匝' => '婧',
+'仟' => 'ヰ',
+'半' => '圉',
+'卉' => '雒',
+'卡' => '縐',
+'占' => '梩',
+'卯' => '簾',
+'卮' => '奡',
+'去' => '',
+'可' => '褫',
+'古' => '嘉',
+'右' => '衵',
+'召' => '欸',
+'叮' => '閎',
+'叩' => '萰',
+'叨' => '葍',
+'叼' => '蛤',
+'司' => '侗',
+'叵' => '媝',
+'叫' => '請',
+'另' => '鍚',
+'只' => '硐',
+'史' => '妢',
+'叱' => '蒆',
+'台' => '怢',
+'句' => '曆',
+'叭' => '務',
+'叻' => '葽',
+'四' => '侐',
+'囚' => '⑵',
+'外' => '俋',
+'央' => '栝',
+'失' => '囮',
+'奴' => '贖',
+'奶' => '騷',
+'孕' => '婕',
+'它' => '坳',
+'尼' => '攝',
+'巨' => '操',
+'巧' => 'б',
+'左' => '酘',
+'市' => '庈',
+'布' => '票',
+'平' => 'す',
+'幼' => '衿',
+'弁' => '袲',
+'弘' => '精',
+'弗' => '艇',
+'必' => '斛',
+'戊' => '昡',
+'打' => '湖',
+'扔' => '',
+'扒' => '勒',
+'扑' => 'で',
+'斥' => '喇',
+'旦' => '筒',
+'朮' => '扲',
+'本' => '掛',
+'未' => '帤',
+'末' => '藺',
+'札' => '崥',
+'正' => '淏',
+'母' => '譫',
+'民' => '鏍',
+'氐' => '媯',
+'永' => '蚗',
+'汁' => '眴',
+'汀' => '矷',
+'氾' => '滓',
+'犯' => '溢',
+'玄' => '哱',
+'玉' => '迶',
+'瓜' => '圖',
+'瓦' => '俓',
+'甘' => '裘',
+'生' => '汜',
+'用' => '蚚',
+'甩' => '辿',
+'田' => '泬',
+'由' => '蚕',
+'甲' => '樅',
+'申' => '扠',
+'疋' => '鼀',
+'白' => '啞',
+'皮' => '々',
+'皿' => '鏤',
+'目' => '醴',
+'矛' => '穫',
+'矢' => '妐',
+'石' => '坒',
+'示' => '尨',
+'禾' => '睽',
+'穴' => '悃',
+'立' => '蕾',
+'丞' => '堜',
+'丟' => '隍',
+'乒' => 'さ',
+'乓' => '籤',
+'乩' => '媕',
+'亙' => '堥',
+'交' => '蝠',
+'亦' => '砫',
+'亥' => '漸',
+'仿' => '溘',
+'伉' => '惉',
+'伙' => '鳴',
+'伊' => '畛',
+'伕' => '痲',
+'伍' => '斪',
+'伐' => '極',
+'休' => '倎',
+'伏' => '睦',
+'仲' => '笯',
+'件' => '璃',
+'任' => '',
+'仰' => '欯',
+'仳' => '幄',
+'份' => '爺',
+'企' => 'わ',
+'伋' => '',
+'光' => '嫖',
+'兇' => '倜',
+'兆' => '欳',
+'先' => '珂',
+'全' => '',
+'共' => '僕',
+'再' => '婬',
+'冰' => '梨',
+'列' => '蹈',
+'刑' => '倢',
+'划' => '赫',
+'刎' => '尰',
+'刖' => '踾',
+'劣' => '輾',
+'匈' => '倧',
+'匡' => '選',
+'匠' => '蔔',
+'印' => '荂',
+'危' => '峉',
+'吉' => '憚',
+'吏' => '環',
+'同' => '肮',
+'吊' => '裂',
+'吐' => '苂',
+'吁' => '郚',
+'吋' => '渡',
+'各' => '跪',
+'向' => '砃',
+'名' => '靡',
+'合' => '磁',
+'吃' => '勛',
+'后' => '綴',
+'吆' => '葴',
+'吒\' => '葚',
+'因' => '秪',
+'回' => '隙',
+'囝' => '麀',
+'圳' => '詀',
+'地' => '華',
+'在' => '婓',
+'圭' => '寧',
+'圬' => '訹',
+'圯' => '詄',
+'圩' => '詍',
+'夙' => '渼',
+'多' => '嗣',
+'夷' => '痁',
+'夸' => '蹂',
+'妄' => '咥',
+'奸' => '潮',
+'妃' => '漦',
+'好' => '疑',
+'她' => '坴',
+'如' => '',
+'妁' => '潁',
+'字' => '趼',
+'存' => '湔',
+'宇' => '迻',
+'守' => '忐',
+'宅' => '晙',
+'安' => '假',
+'寺' => '侁',
+'尖' => '潑',
+'屹' => '砣',
+'州' => '笣',
+'帆' => '楞',
+'并' => '甜',
+'年' => '爛',
+'式' => '宒',
+'弛' => '啼',
+'忙' => '疆',
+'忖' => '瞁',
+'戎' => '',
+'戌' => '剚',
+'戍' => '旴',
+'成' => '傖',
+'扣' => '諶',
+'扛' => '蕈',
+'托' => '迖',
+'收' => '彶',
+'早' => '婌',
+'旨' => '祤',
+'旬' => '悎',
+'旭' => '哢',
+'曲' => '⑻',
+'曳' => '珝',
+'有' => '衄',
+'朽' => '冓',
+'朴' => 'は',
+'朱' => '紾',
+'朵' => '嗡',
+'次' => '棒',
+'此' => '森',
+'死' => '侚',
+'氖' => '騫',
+'汝' => '',
+'汗' => '犒',
+'汙' => '拹',
+'江' => '蔬',
+'池' => '喀',
+'汐' => '洢',
+'汕' => '囟',
+'污' => '拹',
+'汛' => '挬',
+'汍' => '',
+'汎' => '滓',
+'灰' => '閡',
+'牟' => '觸',
+'牝' => '膷',
+'百' => '啃',
+'竹' => '罣',
+'米' => '譙',
+'糸' => '鏻',
+'缶' => '騞',
+'羊' => '栺',
+'羽' => '迼',
+'老' => '橾',
+'考' => '蕉',
+'而' => '奧',
+'耒' => '鼩',
+'耳' => '嫉',
+'聿' => '穛',
+'肉' => '',
+'肋' => '澀',
+'肌' => '慼',
+'臣' => '頃',
+'自' => '赻',
+'至' => '祫',
+'臼' => '彊',
+'舌' => '忕',
+'舛' => '漍',
+'舟' => '笸',
+'艮' => '轘',
+'色' => '伎',
+'艾' => '鬲',
+'虫' => '單',
+'血' => '悛',
+'行' => '俴',
+'衣' => '畟',
+'西' => '昹',
+'阡' => '筀',
+'串' => '揹',
+'亨' => '箋',
+'位' => '弇',
+'住' => '蛂',
+'佇' => '悹',
+'佗' => '晬',
+'佞' => '惌',
+'伴' => '圈',
+'佛' => '痰',
+'何' => '睡',
+'估' => '嘛',
+'佐' => '酚',
+'佑' => '衶',
+'伽' => '暀',
+'伺' => '侜',
+'伸' => '扥',
+'佃' => '菔',
+'佔' => '梩',
+'似' => '侔',
+'但' => '筍',
+'佣' => '荈',
+'作' => '釬',
+'你' => '斕',
+'伯' => '皎',
+'低' => '腴',
+'伶' => '鍥',
+'余' => '豻',
+'佝' => '愔',
+'佈' => '票',
+'佚' => '惄',
+'兌' => '募',
+'克' => '親',
+'免' => '轎',
+'兵' => '條',
+'冶' => '珣',
+'冷' => '濮',
+'別' => '梗',
+'判' => '瓚',
+'利' => '瞳',
+'刪' => '刉',
+'刨' => '蘸',
+'劫' => '誶',
+'助' => '翑',
+'努' => '贗',
+'劬' => '蛨',
+'匣' => '牰',
+'即' => '撈',
+'卵' => '覲',
+'吝' => '醞',
+'吭\' => '諮',
+'吞' => '迒',
+'吾' => '挓',
+'否' => '瘁',
+'呎' => '喜',
+'吧' => '勘',
+'呆' => '渭',
+'呃' => '萺',
+'吳' => '挔',
+'呈' => '傘',
+'呂' => '臍',
+'君' => '澱',
+'吩' => '煜',
+'告' => '豢',
+'吹' => '斯',
+'吻' => '恉',
+'吸' => '柲',
+'吮' => '丳',
+'吵' => '陶',
+'吶' => '霰',
+'吠' => '溴',
+'吼' => '綾',
+'呀' => '挼',
+'吱' => '眹',
+'含' => '漪',
+'吟' => '窉',
+'听' => '泭',
+'囪' => '棋',
+'困' => '嬪',
+'囤' => '嗓',
+'囫' => '僔',
+'坊' => '溶',
+'坑' => '諧',
+'址' => '硊',
+'坍' => '怌',
+'均' => '歙',
+'坎' => '臻',
+'圾' => '僵',
+'坐' => '釴',
+'坏' => '輓',
+'圻' => '詒',
+'壯' => '袕',
+'夾' => '標',
+'妝' => '衒',
+'妒' => '催',
+'妨' => '溥',
+'妞' => '璊',
+'妣' => '澒',
+'妙' => '鏝',
+'妖' => '毦',
+'妍' => '潾',
+'妤' => '璆',
+'妓' => '樣',
+'妊' => '',
+'妥' => '邰',
+'孝' => '苠',
+'孜' => '谻',
+'孚' => '篎',
+'孛' => '媄',
+'完' => '俇',
+'宋' => '冼',
+'宏' => '粽',
+'尬' => '痸',
+'局' => '擁',
+'屁' => 'い',
+'尿' => '續',
+'尾' => '帣',
+'岐' => '嶊',
+'岑' => '嶍',
+'岔' => '舶',
+'岌' => '嵺',
+'巫' => '拵',
+'希' => '洷',
+'序' => '唗',
+'庇' => '敏',
+'床' => '散',
+'廷' => '祂',
+'弄' => '讀',
+'弟' => '萊',
+'彤' => '肸',
+'形' => '倛',
+'彷' => '摴',
+'役' => '砢',
+'忘' => '咭',
+'忌' => '暴',
+'志' => '祩',
+'忍' => '',
+'忱' => '鹿',
+'快' => '辦',
+'忸' => '碭',
+'忪' => '碪',
+'戒' => '賭',
+'我' => '扂',
+'抄' => '陪',
+'抗' => '蕨',
+'抖' => '順',
+'技' => '撮',
+'扶' => '痴',
+'抉' => '橄',
+'扭' => '聾',
+'把' => '參',
+'扼' => '塭',
+'找' => '梑',
+'批' => '蠶',
+'扳' => '售',
+'抒' => '忻',
+'扯' => '雀',
+'折' => '殏',
+'扮' => '啁',
+'投' => '芘',
+'抓' => '蚰',
+'抑' => '眚',
+'抆' => '^',
+'改' => '蜊',
+'攻' => '馴',
+'攸' => '惎',
+'旱' => '熊',
+'更' => '載',
+'束' => '旰',
+'李' => '燠',
+'杏' => '倬',
+'材' => '第',
+'村' => '游',
+'杜' => '債',
+'杖' => '桱',
+'杞' => '頧',
+'杉' => '冱',
+'杆' => '裝',
+'杠' => '話',
+'杓' => '頛',
+'杗' => 'n',
+'步' => '祭',
+'每' => '藩',
+'求' => '⑴',
+'汞' => '僖',
+'沙' => '伈',
+'沁' => 'ц',
+'沈' => '朻',
+'沉' => '麥',
+'沅' => '蜠',
+'沛' => '驛',
+'汪' => '匽',
+'決' => '樵',
+'沐' => '蜲',
+'汰' => '怑',
+'沌' => '蜭',
+'汨' => '蜼',
+'沖' => '喳',
+'沒' => '羶',
+'汽' => 'イ',
+'沃' => '挋',
+'汲' => '撲',
+'汾' => '煆',
+'汴' => '蜺',
+'沆' => '蜵',
+'汶' => '蜱',
+'沍' => '渃',
+'沔\' => '蜪',
+'沘' => 'a',
+'沂' => '疺',
+'灶' => '婜',
+'灼' => '觖',
+'災' => '婐',
+'灸' => '奮',
+'牢' => '檣',
+'牡' => '警',
+'牠' => '坳',
+'狄' => '菸',
+'狂' => '遼',
+'玖' => '墾',
+'甬' => '薿',
+'甫' => '蒂',
+'男' => '鹹',
+'甸' => '菟',
+'皂' => '婂',
+'盯' => '閒',
+'矣' => '眑',
+'私' => '佌',
+'秀' => '凅',
+'禿' => '芮',
+'究' => '噶',
+'系' => '炵',
+'罕' => '滷',
+'肖' => '苳',
+'肓' => '蹅',
+'肝' => '裕',
+'肘' => '紵',
+'肛' => '誇',
+'肚' => '傳',
+'育' => '郤',
+'良' => '謎',
+'芒' => '璽',
+'芋' => '郠',
+'芍' => '屼',
+'見' => '獗',
+'角' => '褒',
+'言' => '晟',
+'谷' => '嗷',
+'豆' => '飪',
+'豕' => '鼮',
+'貝' => '探',
+'赤' => '喪',
+'走' => '軗',
+'足' => '逋',
+'身' => '旯',
+'車' => '陬',
+'辛' => '釓',
+'辰' => '魚',
+'迂' => '衯',
+'迆' => '暲',
+'迅' => '捃',
+'迄' => 'ア',
+'巡' => '挐',
+'邑' => '眧',
+'邢' => '俵',
+'邪' => '訄',
+'邦' => '堊',
+'那' => '饒',
+'酉' => '衃',
+'釆' => '粒',
+'里' => '爵',
+'防' => '滅',
+'阮' => '',
+'阱' => '筘',
+'阪' => '筅',
+'阬' => '諧',
+'並' => '甜',
+'乖' => '墊',
+'乳' => '',
+'事' => '岈',
+'些' => '虳',
+'亞' => '捚',
+'享' => '砅',
+'京' => '儔',
+'佯' => '栮',
+'依' => '甡',
+'侍' => '帎',
+'佳' => '槽',
+'使' => '妏',
+'佬' => '檗',
+'供' => '鼎',
+'例' => '瞰',
+'來' => '懂',
+'侃' => '朁',
+'佰' => '唱',
+'併' => '甜',
+'侈' => '喂',
+'佩' => '驚',
+'佻' => '椄',
+'侖' => '贅',
+'佾' => '棓',
+'侏' => '椌',
+'侑' => '晪',
+'佺' => '',
+'兔' => '芤',
+'兒' => '嫁',
+'兕' => '渽',
+'兩' => '謗',
+'具' => '撿',
+'其' => 'む',
+'典' => '萎',
+'冽' => '渮',
+'函' => '滲',
+'刻' => '覦',
+'券' => '',
+'刷' => '芃',
+'刺' => '棧',
+'到' => '善',
+'刮' => '團',
+'制' => '秶',
+'剁' => '嗥',
+'劾' => '衈',
+'劻' => '',
+'卒' => '逑',
+'協' => '衪',
+'卓' => '袗',
+'卑' => '掠',
+'卦' => '寑',
+'卷' => '橙',
+'卸' => '迠',
+'卹' => '哧',
+'取' => '',
+'叔' => '忴',
+'受' => '忳',
+'味' => '庤',
+'呵' => '瘉',
+'咖' => '縉',
+'呸' => '邏',
+'咕' => '嗾',
+'咀' => '擋',
+'呻' => '扚',
+'呷' => '菙',
+'咄' => '葟',
+'咒' => '紸',
+'咆' => '臢',
+'呼' => '網',
+'咐' => '蛻',
+'呱' => '葋',
+'呶' => '葰',
+'和' => '睿',
+'咚' => '葂',
+'呢' => '儸',
+'周' => '笚',
+'咋' => '捰',
+'命' => '韜',
+'咎' => '憑',
+'固' => '嘐',
+'垃' => '嶼',
+'坷' => '螃',
+'坪' => 'ざ',
+'坩' => '詑',
+'坡' => 'ぞ',
+'坦' => '拊',
+'坤' => '壑',
+'坼\' => '豟',
+'夜' => '珗',
+'奉' => '畸',
+'奇' => 'も',
+'奈' => '鰓',
+'奄' => '栟',
+'奔' => '掉',
+'妾' => '瑼',
+'妻' => 'ぺ',
+'委' => '巹',
+'妹' => '藤',
+'妮' => '屬',
+'姑' => '嘔',
+'姆' => '譟',
+'姐' => '賬',
+'姍' => '璈',
+'始' => '宎',
+'姓' => '俷',
+'姊' => '璇',
+'妯' => '璅',
+'妳' => '斕',
+'姒' => '璁',
+'姅' => '',
+'孟' => '譁',
+'孤' => '嗽',
+'季' => '撫',
+'宗' => '跁',
+'定' => '隅',
+'官' => '夥',
+'宜' => '皊',
+'宙' => '紺',
+'宛' => '剄',
+'尚' => '奾',
+'屈' => '⑽',
+'居' => '懈',
+'屆' => '趣',
+'岷' => '廕',
+'岡' => '詳',
+'岸' => '偉',
+'岩' => '旂',
+'岫' => '廑',
+'岱' => '廗',
+'岳' => '埬',
+'帘' => '螫',
+'帚' => '紽',
+'帖' => '泃',
+'帕' => '鰻',
+'帛' => '盔',
+'帑' => '僰',
+'幸' => '倷',
+'庚' => '軾',
+'店' => '虛',
+'府' => '葬',
+'底' => '菁',
+'庖' => '瑲',
+'延' => '晊',
+'弦' => '玾',
+'弧' => '說',
+'弩' => '殢',
+'往' => '厘',
+'征' => '涽',
+'彿' => '痰',
+'彼' => '捨',
+'忝' => '蓇',
+'忠' => '笳',
+'忽' => '綺',
+'念' => '癩',
+'忿' => '牒',
+'怏' => '碥',
+'怔' => '涺',
+'怯' => 'к',
+'怵' => '硾',
+'怖' => '窕',
+'怪' => '墅',
+'怕' => '鷓',
+'怡' => '禊',
+'性' => '俶',
+'怩' => '碬',
+'怫' => '碢',
+'怛' => '碞',
+'或' => '麼',
+'戕' => '蜛',
+'房' => '滇',
+'戾' => '懤',
+'所' => '垀',
+'承' => '創',
+'拉' => '嶺',
+'拌' => '啗',
+'拄' => '羝',
+'抿' => '鏘',
+'拂' => '痳',
+'抹' => '蘑',
+'拒' => '擇',
+'招' => '桸',
+'披' => '蠹',
+'拓' => '阹',
+'拔' => '匿',
+'拋' => '纔',
+'拈' => '灌',
+'抨' => '髑',
+'抽' => '喲',
+'押' => '挹',
+'拐' => '塹',
+'拙' => '袛',
+'拇' => '譬',
+'拍' => '鼴',
+'抵' => '萋',
+'拚' => '皙',
+'抱' => '惕',
+'拘' => '憶',
+'拖' => '迍',
+'拗' => '皵',
+'拆' => '莞',
+'抬' => '怬',
+'拎' => '醜',
+'放' => '溫',
+'斧' => '葦',
+'於' => '衾',
+'旺' => '咺',
+'昔' => '昺',
+'易' => '眢',
+'昌' => '荻',
+'昆' => '壎',
+'昂' => '偕',
+'明' => '隴',
+'昀' => '篔',
+'昏' => '餉',
+'昕' => '篹',
+'昊' => '篕',
+'昇' => '汔',
+'服' => '督',
+'朋' => '攬',
+'杭' => '獐',
+'枋' => '駔',
+'枕' => '淠',
+'東' => '陲',
+'果' => '彆',
+'杳' => '餖',
+'杷' => '駎',
+'枇' => '餑',
+'枝' => '皉',
+'林' => '輿',
+'杯' => '戚',
+'杰' => '豌',
+'板' => '啣',
+'枉' => '厖',
+'松' => '侂',
+'析' => '昴',
+'杵' => '駜',
+'枚' => '繹',
+'枓' => '',
+'杼' => '駉',
+'杪' => '餔',
+'杲' => '篚',
+'欣' => '釔',
+'武' => '挕',
+'歧' => 'ゃ',
+'歿\' => '殪',
+'氓' => '疇',
+'氛' => '煬',
+'泣' => 'ゥ',
+'注' => '蛁',
+'泳' => '蚞',
+'沱' => '裮',
+'泌' => '蹼',
+'泥' => '懾',
+'河' => '碩',
+'沽' => '嘗',
+'沾' => '桭',
+'沼' => '梌',
+'波' => '疏',
+'沫' => '蘊',
+'法' => '楊',
+'泓' => '裼',
+'沸' => '煩',
+'泄' => '邿',
+'油' => '蚐',
+'況' => '錶',
+'沮' => '據',
+'泗' => '蜑',
+'泅' => '⑷',
+'泱' => '蜰',
+'沿' => '朓',
+'治' => '笥',
+'泡' => '邐',
+'泛' => '滓',
+'泊' => '眼',
+'沬' => 'i',
+'泯' => '裶',
+'泜' => '',
+'泖' => '裱',
+'泠' => '裧',
+'炕' => '蕃',
+'炎' => '朒',
+'炒' => '陷',
+'炊' => '普',
+'炙' => '笵',
+'爬' => '鰾',
+'爭' => '淰',
+'爸' => '啄',
+'版' => '唳',
+'牧' => '鐘',
+'物' => '昜',
+'狀' => '袨',
+'狎' => '摥',
+'狙' => '憾',
+'狗' => '僩',
+'狐' => '緒',
+'玩' => '俙',
+'玨' => '谾',
+'玟' => '諙',
+'玫' => '繭',
+'玥' => '則',
+'甽' => '峽',
+'疝' => '謰',
+'疙' => '貲',
+'疚' => '憊',
+'的' => '腔',
+'盂' => '衴',
+'盲' => '瓣',
+'直' => '眻',
+'知' => '眭',
+'矽' => '朏',
+'社' => '扦',
+'祀' => '擫',
+'祁' => 'り',
+'秉' => '梂',
+'秈' => '覹',
+'空' => '諾',
+'穹' => '騇',
+'竺' => '鬊',
+'糾' => '壁',
+'罔' => '嵙',
+'羌' => 'Ф',
+'羋' => '娷',
+'者' => '氪',
+'肺' => '煎',
+'肥' => '滔',
+'肢' => '眱',
+'肱' => '蹁',
+'股' => '嘖',
+'肫' => '踰',
+'肩' => '潛',
+'肴' => '躽',
+'肪' => '溝',
+'肯' => '諫',
+'臥' => '拏',
+'臾' => '籈',
+'舍' => '忔',
+'芳' => '滂',
+'芝' => '皏',
+'芙' => '傰',
+'芭' => '剪',
+'芽' => '捁',
+'芟' => '嗊',
+'芹' => 'т',
+'花' => '豪',
+'芬' => '煉',
+'芥' => '賣',
+'芯' => '郋',
+'芸' => '傺',
+'芣' => '釁',
+'芰' => '僋',
+'芾' => '傱',
+'芷' => '剺',
+'虎' => '誥',
+'虱' => '坉',
+'初' => '場',
+'表' => '桶',
+'軋' => '崏',
+'迎' => '茩',
+'返' => '殿',
+'近' => '輪',
+'邵' => '幵',
+'邸' => '菕',
+'邱' => '⑨',
+'邶' => '缿',
+'采' => '粒',
+'金' => '踢',
+'長' => '酗',
+'門' => '藷',
+'阜' => '虞',
+'陀' => '邲',
+'阿' => '陝',
+'阻' => '郯',
+'附' => '蜇',
+'陂' => '粨',
+'隹' => '鶹',
+'雨' => '迾',
+'青' => 'ч',
+'非' => '準',
+'亟' => '婼',
+'亭' => '秅',
+'亮' => '謠',
+'信' => '陓',
+'侵' => 'н',
+'侯' => '綜',
+'便' => '晞',
+'俠' => '狨',
+'俑' => '椓',
+'俏' => 'ё',
+'保' => '悵',
+'促' => '棻',
+'侶' => '舊',
+'俘' => '睞',
+'俟' => '椐',
+'俊' => '縑',
+'俗' => '匋',
+'侮' => '斿',
+'俐' => '瞬',
+'俄' => '塘',
+'係' => '炵',
+'俚' => '棫',
+'俎' => '殔',
+'俞\' => '貤',
+'侷' => '擁',
+'兗' => '湢',
+'冒' => '簸',
+'冑' => '遶',
+'冠' => '夢',
+'剎' => '价',
+'剃' => '殀',
+'削' => '祅',
+'前' => 'ヶ',
+'剌' => '嵋',
+'剋' => '親',
+'則' => '寀',
+'勇' => '蚋',
+'勉' => '辭',
+'勃' => '痕',
+'勁' => '麩',
+'匍' => '湇',
+'南' => '鰍',
+'卻' => '',
+'厚' => '綠',
+'叛' => '竊',
+'咬' => '狶',
+'哀' => '飢',
+'咨' => '訰',
+'哎' => '陞',
+'哉' => '婭',
+'咸' => '玶',
+'咦' => '葇',
+'咳' => '褥',
+'哇' => '阺',
+'哂' => '葯',
+'咽' => '捗',
+'咪' => '蛷',
+'品' => 'こ',
+'哄' => '箏',
+'哈' => '慇',
+'咯' => '罹',
+'咫' => '槶',
+'咱' => '婤',
+'咻' => '萫',
+'咩' => '蜄',
+'咧' => '萻',
+'咿' => '葠',
+'囿' => '僨',
+'垂' => '晶',
+'型' => '倰',
+'垠' => '跇',
+'垣' => '圊',
+'垢' => '兢',
+'城' => '傑',
+'垮' => '踹',
+'垓' => '跍',
+'奕' => '瘏',
+'契' => 'ゑ',
+'奏' => '軠',
+'奎' => '錫',
+'奐' => '蛩',
+'姜' => '蔽',
+'姘' => '瘞',
+'姿' => '訬',
+'姣' => '瘥',
+'姨' => '盉',
+'娃' => '俅',
+'姥' => '檐',
+'姪' => '硍',
+'姚' => '狾',
+'姦' => '潮',
+'威' => '哏',
+'姻' => '窆',
+'孩' => '滯',
+'宣' => '哫',
+'宦' => '鄞',
+'室' => '弅',
+'客' => '諦',
+'宥' => '撊',
+'封' => '猾',
+'屎' => '妧',
+'屏' => 'そ',
+'屍' => '坌',
+'屋' => '挌',
+'峙' => '秸',
+'峒' => '廒',
+'巷' => '砏',
+'帝' => '著',
+'帥' => '邟',
+'帟' => '',
+'幽' => '蚅',
+'庠' => '瑮',
+'度' => '僅',
+'建' => '膘',
+'弈' => '畹',
+'弭' => '殦',
+'彥' => '栫',
+'很' => '竭',
+'待' => '渾',
+'徊' => '輔',
+'律' => '薺',
+'徇' => '摲',
+'後' => '綴',
+'徉' => '摳',
+'怒' => '躑',
+'思' => '佷',
+'怠' => '窗',
+'急' => '摹',
+'怎' => '崋',
+'怨' => '埳',
+'恍' => '鉼',
+'恰' => 'ョ',
+'恨' => '管',
+'恢' => '閥',
+'恆' => '箝',
+'恃' => '庍',
+'恬' => '泮',
+'恫' => '雯',
+'恪' => '耤',
+'恤' => '哧',
+'扁' => '晦',
+'拜' => '問',
+'挖' => '阼',
+'按' => '偌',
+'拼' => 'ぐ',
+'拭' => '岋',
+'持' => '厥',
+'拮' => '盝',
+'拽' => '蚹',
+'指' => '硌',
+'拱' => '僭',
+'拷' => '蕭',
+'拯' => '淂',
+'括' => '嬤',
+'拾' => '夆',
+'拴' => '邥',
+'挑' => '泔',
+'挂' => '境',
+'政' => '淉',
+'故' => '嘟',
+'斫' => '簀',
+'施' => '囥',
+'既' => '暫',
+'春' => '景',
+'昭' => '桻',
+'映' => '茬',
+'昧' => '藪',
+'是' => '岆',
+'星' => '陎',
+'昨' => '酖',
+'昱' => '篘',
+'昤' => '`',
+'曷' => '篢',
+'柿' => '岏',
+'染' => '',
+'柱' => '翐',
+'柔' => '',
+'某' => '議',
+'柬' => '潤',
+'架' => '殤',
+'枯\' => '豫',
+'柵' => '掑',
+'柩' => '駌',
+'柯' => '螞',
+'柄' => '梟',
+'柑' => '裡',
+'枴' => '塹',
+'柚' => '髲',
+'查' => '脤',
+'枸' => '魴',
+'柏' => '啡',
+'柞' => '酓',
+'柳' => '霞',
+'枰' => '骳',
+'柙' => '髫',
+'柢' => '魱',
+'柝' => '魆',
+'柒' => 'ま',
+'歪' => '俉',
+'殃' => '栴',
+'殆' => '渺',
+'段' => '僇',
+'毒' => '馮',
+'毗' => '讒',
+'氟' => '睛',
+'泉' => '',
+'洋' => '栥',
+'洲' => '粔',
+'洪' => '粹',
+'流' => '霜',
+'津' => '踩',
+'洌' => '銫',
+'洱' => '媽',
+'洞' => '韌',
+'洗' => '炴',
+'活' => '魂',
+'洽' => 'ヨ',
+'派' => '巖',
+'洶' => '倵',
+'洛' => '醫',
+'泵' => '掙',
+'洹' => '銦',
+'洧' => '銚',
+'洸' => '',
+'洩' => '邿',
+'洮' => '銢',
+'洵' => '鉽',
+'洎' => '銎',
+'洫' => '銂',
+'炫' => '嚃',
+'為' => '峈',
+'炳' => '殺',
+'炬' => '暹',
+'炯' => '噯',
+'炭' => '抰',
+'炸' => '旍',
+'炮' => '蘿',
+'炤' => '桽',
+'爰' => '趧',
+'牲' => '汊',
+'牯' => '臲',
+'牴' => '萋',
+'狩' => '暠',
+'狠' => '端',
+'狡' => '複',
+'玷' => '賥',
+'珊' => '仴',
+'玻' => '產',
+'玲' => '鍍',
+'珍' => '湴',
+'珀' => '賙',
+'玳' => '賟',
+'甚' => '朼',
+'甭' => '授',
+'畏' => '庢',
+'界' => '賜',
+'畎' => '謚',
+'畋' => '豏',
+'疫' => '砮',
+'疤' => '匏',
+'疥' => '赭',
+'疢' => '烘',
+'疣' => '譇',
+'癸' => '對',
+'皆' => '諂',
+'皇' => '銘',
+'皈' => '藃',
+'盈' => '荅',
+'盆' => '髓',
+'盃' => '戚',
+'盅' => '笤',
+'省' => '吽',
+'盹' => '臩',
+'相' => '眈',
+'眉' => '羹',
+'看' => '艘',
+'盾' => '嗎',
+'盼' => '曬',
+'眇' => '艛',
+'矜' => '鼪',
+'砂' => '仱',
+'研' => '旃',
+'砌' => 'を',
+'砍' => '興',
+'祆' => '擤',
+'祉' => '擨',
+'祈' => 'ら',
+'祇' => '發',
+'禹' => '迿',
+'禺' => '堮',
+'科' => '褪',
+'秒' => '鏃',
+'秋' => '⑦',
+'穿' => '援',
+'突' => '芼',
+'竿' => '裊',
+'竽' => '鬎',
+'籽' => '豽',
+'紂' => '聤',
+'紅' => '綻',
+'紀' => '槨',
+'紉' => '',
+'紇' => '聧',
+'約' => '埮',
+'紆' => '翨',
+'缸' => '詰',
+'美' => '藝',
+'羿' => '邍',
+'耄' => '諴',
+'耐' => '騵',
+'耍' => '芄',
+'耑' => '蚳',
+'耶' => '珖',
+'胖' => '纖',
+'胥' => '鼖',
+'胚' => '鑣',
+'胃' => '庛',
+'胄' => '遶',
+'背' => '掖',
+'胡' => '綸',
+'胛' => '輷',
+'胎' => '怚',
+'胞' => '婉',
+'胤' => '媟',
+'胝' => '鄳',
+'致' => '祡',
+'舢' => '纁',
+'苧' => '嗀',
+'范' => '毓',
+'茅' => '矇',
+'苣' => '傸',
+'苛' => '螟',
+'苦' => '賴',
+'茄' => 'и',
+'若' => '',
+'茂' => '簿',
+'茉' => '嗩',
+'苒\' => '嗖',
+'苗' => '醮',
+'英' => '荎',
+'茁' => '袌',
+'苜' => '嗕',
+'苔' => '怞',
+'苑' => '埸',
+'苞' => '婁',
+'苓' => '嗙',
+'苟' => '僎',
+'苯' => '掃',
+'茆' => '塓',
+'虐' => '酈',
+'虹' => '箇',
+'虻' => '繺',
+'虺' => '繷',
+'衍' => '栲',
+'衫' => '劦',
+'要' => '猁',
+'觔' => '踐',
+'計' => '數',
+'訂' => '隆',
+'訃' => '蜈',
+'貞' => '淔',
+'負' => '蛹',
+'赴' => '萼',
+'赳' => '鐙',
+'趴' => '鰱',
+'軍' => '濂',
+'軌' => '寢',
+'述' => '扴',
+'迦' => '暪',
+'迢' => '泧',
+'迪' => '舜',
+'迥' => '暰',
+'迭' => '詞',
+'迫' => 'つ',
+'迤' => '暲',
+'迨' => '樀',
+'郊' => '蝦',
+'郎' => '檔',
+'郁' => '郙',
+'郃' => '磁',
+'酋' => '⑶',
+'酊' => '鏺',
+'重' => '笭',
+'閂' => '蒛',
+'限' => '癹',
+'陋' => '穠',
+'陌' => '襤',
+'降' => '蔥',
+'面' => '醱',
+'革' => '賂',
+'韋' => '峇',
+'韭' => '壇',
+'音' => '秞',
+'頁' => '珜',
+'風' => '瑞',
+'飛' => '滄',
+'食' => '妘',
+'首' => '忑',
+'香' => '眅',
+'乘' => '傚',
+'亳' => '渫',
+'倌' => '椔',
+'倍' => '捷',
+'倣' => '溘',
+'俯' => '萱',
+'倦' => '樸',
+'倥' => '棸',
+'俸' => '棳',
+'倩' => '棡',
+'倖' => '倷',
+'倆' => '薨',
+'值' => '硉',
+'借' => '質',
+'倚' => '眓',
+'倒' => '給',
+'們' => '蠅',
+'俺' => '偃',
+'倀' => '徥',
+'倔' => '橡',
+'倨' => '棐',
+'俱' => '整',
+'倡' => '釩',
+'個' => '跺',
+'候' => '緊',
+'倘' => '昈',
+'俳' => '棌',
+'修' => '党',
+'倭' => '椑',
+'倪' => '懼',
+'俾' => '棯',
+'倫' => '豐',
+'倉' => '累',
+'兼' => '潭',
+'冤' => '啀',
+'冥' => '琱',
+'冢' => '琭',
+'凍' => '雲',
+'凌' => '錘',
+'准' => '袧',
+'凋' => '蛞',
+'剖' => 'て',
+'剜' => '嵑',
+'剔' => '枌',
+'剛' => '試',
+'剝' => '婀',
+'匪' => '溪',
+'卿' => 'ы',
+'原' => '埻',
+'厝' => '媩',
+'叟' => '袹',
+'哨' => '巟',
+'唐' => '昄',
+'唁' => '栵',
+'唷' => '遄',
+'哼' => '箕',
+'哥' => '貊',
+'哲' => '殍',
+'唆' => '坭',
+'哺' => '硫',
+'唔' => '蜁',
+'哩' => '薇',
+'哭' => '豭',
+'員' => '埜',
+'唉' => '隻',
+'哮' => '祄',
+'哪' => '闡',
+'哦' => '韃',
+'唧' => '裍',
+'唇' => '晾',
+'哽' => '蜉',
+'唏' => '裖',
+'圃' => 'ば',
+'圄' => '僳',
+'埂' => '飽',
+'埔' => 'の',
+'埋' => '鎚',
+'埃' => '除',
+'堉' => '',
+'夏' => '狦',
+'套' => '杶',
+'奘' => '痷',
+'奚' => '瘃',
+'娑' => '瘨',
+'娘' => '矓',
+'娜' => '饑',
+'娟' => '樽',
+'娛' => '軓',
+'娓' => '皜',
+'姬' => '憫',
+'娠' => '朾',
+'娣' => '瘛',
+'娩' => '邊',
+'娥' => '塔',
+'娌' => '瘝',
+'娉\' => '瘜',
+'孫' => '呤',
+'屘' => '',
+'宰' => '婟',
+'害' => '漲',
+'家' => '模',
+'宴' => '栯',
+'宮' => '僧',
+'宵' => '秖',
+'容' => '',
+'宸' => '撌',
+'射' => '扞',
+'屑' => '邾',
+'展' => '桯',
+'屐' => '樦',
+'峭' => 'е',
+'峽' => '狤',
+'峻' => '澡',
+'峪' => '郥',
+'峨' => '塞',
+'峰' => '瑕',
+'島' => '絢',
+'崁' => '',
+'峴' => '嵾',
+'差' => '船',
+'席' => '炟',
+'師' => '呇',
+'庫' => '踱',
+'庭' => '穸',
+'座' => '釱',
+'弱' => '',
+'徒' => '芺',
+'徑' => '噤',
+'徐' => '剢',
+'恙' => '磽',
+'恣' => '礂',
+'恥' => '喝',
+'恐' => '謁',
+'恕' => '芊',
+'恭' => '鳩',
+'恩' => '塋',
+'息' => '洘',
+'悄' => 'Ь',
+'悟' => '昳',
+'悚' => '膉',
+'悍' => '熒',
+'悔' => '際',
+'悌' => '膌',
+'悅' => '埼',
+'悖' => '聜',
+'扇' => '圮',
+'拳' => '',
+'挈' => '蕓',
+'拿' => '鏽',
+'捎' => '孖',
+'挾' => '衩',
+'振' => '淥',
+'捕' => '眸',
+'捂' => '拰',
+'捆' => '嬰',
+'捏' => '羼',
+'捉' => '袙',
+'挺' => '穻',
+'捐' => '曇',
+'挽' => '侺',
+'挪' => '鑑',
+'挫' => '渥',
+'挨' => '陘',
+'捍' => '煽',
+'捌' => '副',
+'效' => '虴',
+'敉' => '觷',
+'料' => '蹋',
+'旁' => '籥',
+'旅' => '藏',
+'時' => '奀',
+'晉' => '輩',
+'晏' => '縒',
+'晃' => '銜',
+'晒' => '伄',
+'晌' => '妅',
+'晅' => 't',
+'晁' => '糑',
+'書' => '抎',
+'朔' => '侇',
+'朕' => '錞',
+'朗' => '檄',
+'校' => '苺',
+'核' => '瞄',
+'案' => '偶',
+'框' => '遺',
+'桓' => '遘',
+'根' => '跦',
+'桂' => '屢',
+'桔' => '諛',
+'栩' => '鼏',
+'梳' => '忯',
+'栗' => '璦',
+'桌' => '袤',
+'桑' => '氿',
+'栽' => '娵',
+'柴' => '莘',
+'桐' => '糽',
+'桀' => '鴅',
+'格' => '跡',
+'桃' => '朊',
+'株' => '絁',
+'桅' => '峖',
+'栓' => '邡',
+'栘' => '',
+'桁' => '鳻',
+'殊' => '忷',
+'殉' => '捖',
+'殷' => '秜',
+'氣' => 'ァ',
+'氧' => '欬',
+'氨' => '停',
+'氦' => '漱',
+'氤' => '貐',
+'泰' => '怍',
+'浪' => '檢',
+'涕' => '欥',
+'消' => '秏',
+'涇' => '裻',
+'浦' => 'ひ',
+'浸' => '輞',
+'海' => '漆',
+'浙' => '涳',
+'涓' => '銝',
+'浬' => '爵',
+'涉' => '扡',
+'浮' => '腹',
+'浚' => '縛',
+'浴' => '唌',
+'浩' => '瘋',
+'涌' => '蚇',
+'涊' => '',
+'浹' => '鉹',
+'涅' => '蠡',
+'浥' => '',
+'涔' => '銋',
+'烊' => '噿',
+'烘' => '箸',
+'烤' => '蕪',
+'烙' => '歜',
+'烈' => '轄',
+'烏' => '拫',
+'爹' => '註',
+'特' => '杻',
+'狼' => '曖',
+'狹' => '狫',
+'狽' => '捧',
+'狸' => '燥',
+'狷' => '朄',
+'玆' => '觕',
+'班' => '啤',
+'琉' => '闋',
+'珮\' => '驚',
+'珠' => '紩',
+'珪' => '寧',
+'珞' => '踠',
+'畔' => '欐',
+'畝' => '譯',
+'畜' => '唒',
+'畚' => '褁',
+'留' => '隱',
+'疾' => '撞',
+'病' => '瓷',
+'症' => '痌',
+'疲' => 'ゞ',
+'疳' => '謯',
+'疽' => '懊',
+'疼' => '构',
+'疹' => '淟',
+'痂' => '謶',
+'疸' => '謾',
+'皋' => '詭',
+'皰' => '謥',
+'益' => '祔',
+'盍' => '轀',
+'盎' => '偵',
+'眩' => '悈',
+'真' => '淩',
+'眠' => '蹺',
+'眨' => '掁',
+'矩' => '撻',
+'砰' => '體',
+'砧' => '涷',
+'砸' => '婞',
+'砝' => '簎',
+'破' => 'ぢ',
+'砷' => '扙',
+'砥' => '簃',
+'砭' => '篿',
+'砠' => '訟',
+'砟' => '簂',
+'砲' => '蘿',
+'祕' => '贈',
+'祐' => '衶',
+'祠' => '檖',
+'祟' => '呧',
+'祖' => '逌',
+'神' => '朸',
+'祝' => '蛅',
+'祗' => '檍',
+'祚' => '旚',
+'秤' => '勝',
+'秣' => '濷',
+'秧' => '栔',
+'租' => '逤',
+'秦' => 'п',
+'秩' => '窏',
+'秘' => '贈',
+'窄' => '晜',
+'窈' => '髜',
+'站' => '桴',
+'笆' => '動',
+'笑' => '虷',
+'粉' => '煨',
+'紡' => '溺',
+'紗' => '伝',
+'紋' => '恇',
+'紊' => '恌',
+'素' => '匼',
+'索' => '坰',
+'純' => '曾',
+'紐' => '臟',
+'紕' => '蝣',
+'級' => '撰',
+'紜' => '蝖',
+'納' => '馨',
+'紙' => '祧',
+'紛' => '煌',
+'缺' => '',
+'罟' => '赯',
+'羔' => '詬',
+'翅' => '喔',
+'翁' => '恟',
+'耆' => '糔',
+'耘' => '埧',
+'耕' => '較',
+'耙' => '曼',
+'耗' => '瘧',
+'耽' => '窖',
+'耿' => '飾',
+'胱' => '鄶',
+'脂' => '眲',
+'胰' => '疿',
+'脅' => '赲',
+'胭' => '醐',
+'胴' => '醓',
+'脆' => '毯',
+'胸' => '倠',
+'胳' => '賄',
+'脈' => '闕',
+'能' => '夔',
+'脊' => '撕',
+'胼' => '錧',
+'胯' => '輯',
+'臭' => '堪',
+'臬' => '糮',
+'舀' => '狳',
+'舐' => '鬋',
+'航' => '瑤',
+'舫' => '臛',
+'舨' => '聹',
+'般' => '啜',
+'芻' => '蛬',
+'茫' => '瓊',
+'荒' => '酸',
+'荔' => '璩',
+'荊' => '麾',
+'茸' => '',
+'荐' => '熱',
+'草' => '翌',
+'茵' => '秮',
+'茴' => '塛',
+'荏' => '嫇',
+'茲' => '觕',
+'茹' => '',
+'茶' => '脰',
+'茗' => '媱',
+'荀' => '媸',
+'茱' => '堽',
+'茨' => '棕',
+'荃' => '嫋',
+'虔' => '繶',
+'蚊' => '恞',
+'蚪' => '羷',
+'蚓' => '翽',
+'蚤' => '婩',
+'蚩' => '翾',
+'蚌' => '培',
+'蚣' => '羆',
+'蚜' => '捘',
+'衰' => '迉',
+'衷' => '笪',
+'袁' => '圇',
+'袂' => '鯁',
+'衽' => '鯃',
+'衹' => '硐',
+'記' => '暮',
+'訐' => '琣',
+'討' => '枒',
+'訌' => '琝',
+'訕' => '琩',
+'訊' => '捅',
+'託' => '迖',
+'訓' => '捄',
+'訖' => 'ウ',
+'訏' => '郚',
+'訑' => '',
+'豈' => 'ろ',
+'豺' => '荸',
+'豹\' => '悸',
+'財' => '笙',
+'貢' => '僚',
+'起' => 'れ',
+'躬' => '鼓',
+'軒' => '唄',
+'軔' => '澼',
+'軏' => '',
+'辱' => '',
+'送' => '冞',
+'逆' => '欄',
+'迷' => '譎',
+'退' => '豖',
+'迺' => '騰',
+'迴' => '隙',
+'逃' => '枅',
+'追' => '袚',
+'逅' => '樆',
+'迸' => '掬',
+'邕' => '諅',
+'郡' => '縣',
+'郝' => '甄',
+'郢' => '菻',
+'酒' => '嬴',
+'配' => '饜',
+'酌' => '袓',
+'釘' => '隊',
+'針' => '渀',
+'釗' => '醙',
+'釜' => '葵',
+'釙' => '醛',
+'閃' => '匢',
+'院' => '埏',
+'陣' => '淝',
+'陡' => '飧',
+'陛' => '旎',
+'陝' => '匟',
+'除' => '壺',
+'陘' => '粡',
+'陞' => '汔',
+'隻' => '硐',
+'飢' => '慰',
+'馬' => '鎮',
+'骨' => '嘎',
+'高' => '詢',
+'鬥' => '須',
+'鬲' => '堛',
+'鬼' => '寤',
+'乾' => 'ヲ',
+'偺' => '',
+'偽' => '帢',
+'停' => '礿',
+'假' => '樑',
+'偃' => '棼',
+'偌' => '椇',
+'做' => '酕',
+'偉' => '帡',
+'健' => '翩',
+'偶' => '髒',
+'偎' => '椊',
+'偕' => '棨',
+'偵' => '淈',
+'側' => '耜',
+'偷' => '芚',
+'偏' => 'ぇ',
+'倏' => '楰',
+'偯' => '',
+'偭' => '',
+'兜' => '項',
+'冕' => '轔',
+'凰' => '銖',
+'剪' => '熟',
+'副' => '萵',
+'勒' => '毚',
+'務' => '昢',
+'勘' => '膨',
+'動' => '雄',
+'匐' => '湉',
+'匏' => '痾',
+'匙' => '啻',
+'匿' => '曩',
+'區' => '⑹',
+'匾' => '寋',
+'參' => '統',
+'曼' => '霤',
+'商' => '妀',
+'啪' => '鱉',
+'啦' => '徽',
+'啄' => '袎',
+'啞' => '挳',
+'啡' => '溜',
+'啃' => '諱',
+'啊' => '陛',
+'唱' => '釭',
+'啖' => '遉',
+'問' => '恀',
+'啕' => '覛',
+'唯' => '峔',
+'啤' => 'ヾ',
+'唸' => '癩',
+'售' => '忮',
+'啜' => '鄖',
+'唬' => '誨',
+'啣' => '玴',
+'唳' => '鄏',
+'啁' => '覅',
+'啗' => '',
+'圈' => '',
+'國' => '弊',
+'圉' => '僪',
+'域' => '郖',
+'堅' => '澄',
+'堊' => '覘',
+'堆' => '剽',
+'埠' => '硎',
+'埤' => '軷',
+'基' => '價',
+'堂' => '斻',
+'堵' => '黑',
+'執' => '硒',
+'培' => '鑠',
+'夠' => '劂',
+'奢' => '异',
+'娶' => '',
+'婁' => '礎',
+'婉' => '剉',
+'婦' => '蜀',
+'婪' => '懋',
+'婀' => '皝',
+'娼' => '瞏',
+'婢' => '瞉',
+'婚' => '駁',
+'婆' => 'ち',
+'婊' => '皛',
+'孰' => '抔',
+'寇' => '諼',
+'寅' => '窌',
+'寄' => '敵',
+'寂' => '敷',
+'宿' => '咑',
+'密' => '躇',
+'尉' => '徆',
+'專' => '蚳',
+'將' => '蔚',
+'屠' => '芡',
+'屜' => '歾',
+'屝' => '',
+'崇' => '喟',
+'崆' => '慳',
+'崎' => 'ゅ',
+'崛' => '慒',
+'崖' => '捔',
+'崢' => '彃',
+'崑' => '壎',
+'崩' => '推',
+'崔' => '殖',
+'崙' => '贅',
+'崤\' => '慞',
+'崧' => '愬',
+'崗' => '詣',
+'巢' => '陴',
+'常' => '都',
+'帶' => '湍',
+'帳' => '梛',
+'帷' => '寣',
+'康' => '艙',
+'庸' => '蚢',
+'庶' => '旵',
+'庵' => '甂',
+'庾' => '甃',
+'張' => '桲',
+'強' => 'Ч',
+'彗' => '樄',
+'彬' => '梃',
+'彩' => '粗',
+'彫' => '蛐',
+'得' => '腕',
+'徙' => '摦',
+'從' => '植',
+'徘' => '龔',
+'御' => '郘',
+'徠' => '摵',
+'徜' => '撦',
+'恿' => '蚆',
+'患' => '遞',
+'悉' => '洃',
+'悠' => '蚙',
+'您' => '蠟',
+'惋' => '俬',
+'悴' => '蓂',
+'惦' => '蛟',
+'悽' => 'ぼ',
+'情' => '①',
+'悻' => '蒗',
+'悵' => '瞃',
+'惜' => '洇',
+'悼' => '翕',
+'惘' => '蒟',
+'惕' => '枔',
+'惆' => '蒺',
+'惟' => '峏',
+'悸' => '撢',
+'惚' => '蓎',
+'惇' => '嗟',
+'戚' => 'べ',
+'戛' => '磡',
+'扈' => '擯',
+'掠' => '謨',
+'控' => '諷',
+'捲' => '橙',
+'掖' => '珒',
+'探' => '抻',
+'接' => '諉',
+'捷' => '豎',
+'捧' => '癱',
+'掘' => '橢',
+'措' => '渠',
+'捱' => '睧',
+'掩' => '栚',
+'掉' => '裁',
+'掃' => '禸',
+'掛' => '境',
+'捫' => '痶',
+'推' => '芢',
+'掄' => '謬',
+'授' => '忨',
+'掙' => '淴',
+'採' => '粒',
+'掬' => '碇',
+'排' => '齬',
+'掏' => '昅',
+'掀' => '玅',
+'捻' => '瓔',
+'捩' => '碔',
+'捨' => '忔',
+'捺' => '睔',
+'敝' => '敔',
+'敖' => '偷',
+'救' => '寰',
+'教' => '諒',
+'敗' => '啖',
+'啟' => 'ゐ',
+'敏' => '鏗',
+'敘' => '唦',
+'敕' => '賰',
+'敔' => '',
+'斜' => '訇',
+'斛' => '蘡',
+'斬' => '梮',
+'族' => '逜',
+'旋' => '唅',
+'旌' => '儥',
+'旎' => '儢',
+'晝' => '絅',
+'晚' => '俀',
+'晤' => '昵',
+'晨' => '鹵',
+'晦' => '靼',
+'晞' => '',
+'曹' => '羚',
+'勗' => '袺',
+'望' => '咡',
+'梁' => '褽',
+'梯' => '枍',
+'梢' => '奿',
+'梓' => '儚',
+'梵' => '鼐',
+'桿' => '裝',
+'桶' => '肭',
+'梱' => '嬰',
+'梧' => '挀',
+'梗' => '馳',
+'械' => '迮',
+'梃' => '鳷',
+'棄' => 'ィ',
+'梭' => '坲',
+'梆' => '埠',
+'梅' => '繩',
+'梔' => '魃',
+'條' => '沭',
+'梨' => '燧',
+'梟' => '駓',
+'梡' => 'p',
+'梂' => 'W',
+'欲' => '郗',
+'殺' => '伀',
+'毫' => '瑭',
+'毬' => '⑩',
+'氫' => 'щ',
+'涎' => '珇',
+'涼' => '褸',
+'淳' => '晷',
+'淙' => '靿',
+'液' => '珘',
+'淡' => '筏',
+'淌' => '昃',
+'淤' => '袃',
+'添' => '氝',
+'淺' => 'Ё',
+'清' => 'ь',
+'淇' => '靽',
+'淋' => '邀',
+'涯' => '挭',
+'淑' => '抃',
+'涮' => '颭',
+'淞' => '靾',
+'淹' => '敊',
+'涸' => '碣',
+'混' => '髦',
+'淵' => '唻',
+'淅' => '靺',
+'淒' => 'ぼ',
+'渚' => '靘',
+'涵' => '滬',
+'淚\' => '濡',
+'淫' => '窋',
+'淘' => '杬',
+'淪' => '蹙',
+'深' => '旮',
+'淮' => '輕',
+'淨' => '噱',
+'淆' => '秎',
+'淄' => '谹',
+'涪' => '腺',
+'淬' => '氬',
+'涿' => '鞀',
+'淦' => '鞄',
+'烹' => '鱔',
+'焉' => '挸',
+'焊' => '爾',
+'烽' => '琿',
+'烯' => '洬',
+'爽' => '邠',
+'牽' => 'ラ',
+'犁' => '營',
+'猜' => '笨',
+'猛' => '襖',
+'猖' => '荼',
+'猓' => '滹',
+'猙' => '淭',
+'率' => '薹',
+'琅' => '斃',
+'琊' => '趜',
+'球' => '⑩',
+'理' => '燴',
+'現' => '珋',
+'琍' => '薛',
+'瓠' => '藄',
+'瓶' => 'せ',
+'瓷' => '棟',
+'甜' => '泫',
+'產' => '莉',
+'略' => '謹',
+'畦' => 'や',
+'畢' => '救',
+'異' => '祑',
+'疏' => '抌',
+'痔' => '筇',
+'痕' => '窩',
+'疵' => '棺',
+'痊' => '',
+'痍' => '謤',
+'皎' => '藂',
+'盔' => '錳',
+'盒' => '碟',
+'盛' => '呏',
+'眷' => '樺',
+'眾' => '笲',
+'眼' => '桉',
+'眶' => '醒',
+'眸' => '薠',
+'眺' => '沷',
+'硫' => '闈',
+'硃' => '紾',
+'硎' => '簆',
+'祥' => '矨',
+'票' => 'き',
+'祭' => '撬',
+'移' => '痄',
+'窒' => '笰',
+'窕' => '鬈',
+'笠' => '鯜',
+'笨' => '捫',
+'笛' => '萃',
+'第' => '菴',
+'符' => '睫',
+'笙' => '鯔',
+'笞' => '鯚',
+'笮' => '鯗',
+'粒' => '薜',
+'粗' => '棉',
+'粕' => 'づ',
+'絆' => '堅',
+'絃' => '玾',
+'統' => '苀',
+'紮' => '崨',
+'紹' => '庄',
+'紼' => '蝔',
+'絀' => '蝛',
+'細' => '牉',
+'紳' => '朹',
+'組' => '郪',
+'累' => '濛',
+'終' => '笝',
+'紲' => '蟡',
+'紱' => '蝳',
+'缽' => '異',
+'羞' => '冔',
+'羚' => '鍋',
+'翌' => '秬',
+'翎' => '酃',
+'習' => '炾',
+'耜' => '齕',
+'聊' => '謐',
+'聆' => '壚',
+'脯' => '葫',
+'脖' => '盛',
+'脣' => '晾',
+'脫' => '迕',
+'脩' => '党',
+'脰' => '',
+'脤' => '',
+'舂' => '籇',
+'舵' => '嗆',
+'舷' => '珫',
+'舶' => '盒',
+'船' => '摒',
+'莎' => '伔',
+'莞' => '搛',
+'莘' => '揧',
+'荸' => '搣',
+'莢' => '樊',
+'莖' => '墨',
+'莽' => '癟',
+'莫' => '蘆',
+'莒' => '塙',
+'莊' => '蚽',
+'莓' => '摁',
+'莉' => '獲',
+'莠' => '搰',
+'荷' => '盡',
+'荻' => '搋',
+'荼' => '搊',
+'莆' => 'な',
+'莧' => '剻',
+'處' => '揭',
+'彪' => '梵',
+'蛇' => '彴',
+'蛀' => '翇',
+'蚶' => '聸',
+'蛄' => '臗',
+'蚵' => '臕',
+'蛆' => '⑺',
+'蛋' => '粥',
+'蚱' => '藫',
+'蚯' => '藱',
+'蛉' => '藭',
+'術' => '扲',
+'袞' => '渿',
+'袈' => '蘌',
+'被' => '掩',
+'袒' => '抳',
+'袖' => '凈',
+'袍' => '蠱',
+'袋' => '渝',
+'覓' => '贊',
+'規' => '寞',
+'訪' => '溼',
+'訝' => '捑',
+'訣' => '機',
+'訥' => '瓻',
+'許\' => '勍',
+'設' => '扢',
+'訟' => '冾',
+'訛' => '塚',
+'訢' => '釔',
+'豉' => '鐒',
+'豚' => '錟',
+'販' => '毽',
+'責' => '孮',
+'貫' => '嫗',
+'貨' => '億',
+'貪' => '怜',
+'貧' => 'げ',
+'赧' => '鐇',
+'赦' => '忏',
+'趾' => '硅',
+'趺' => '劗',
+'軛' => '濎',
+'軟' => '',
+'這' => '涴',
+'逍' => '槱',
+'通' => '籵',
+'逗' => '飯',
+'連' => '蟀',
+'速' => '厒',
+'逝' => '岒',
+'逐' => '紨',
+'逕' => '暯',
+'逞' => '剩',
+'造' => '婖',
+'透' => '芵',
+'逢' => '瑙',
+'逖' => '槤',
+'逛' => '嫣',
+'途' => '芴',
+'部' => '窒',
+'郭' => '廖',
+'都' => '飲',
+'酗' => '厞',
+'野' => '珧',
+'釵' => '鎃',
+'釦' => '諶',
+'釣' => '袱',
+'釧' => '醝',
+'釭' => '榙',
+'釩' => '楣',
+'閉' => '敕',
+'陪' => '顯',
+'陵' => '鍬',
+'陳' => '麻',
+'陸' => '翻',
+'陰' => '秝',
+'陴' => '絧',
+'陶' => '枎',
+'陷' => '疪',
+'陬' => '絓',
+'雀' => '',
+'雪' => '悕',
+'雩' => '鬺',
+'章' => '梒',
+'竟' => '器',
+'頂' => '階',
+'頃' => '②',
+'魚' => '赶',
+'鳥' => '纏',
+'鹵' => '簣',
+'鹿' => '繒',
+'麥' => '闔',
+'麻' => '鎊',
+'傢' => '模',
+'傍' => '奢',
+'傅' => '葭',
+'備' => '掘',
+'傑' => '豌',
+'傀' => '錚',
+'傖' => '徫',
+'傘' => '氶',
+'傚' => '虴',
+'最' => '郔',
+'凱' => '翮',
+'割' => '賃',
+'剴' => '嵁',
+'創' => '斐',
+'剩' => '呁',
+'勞' => '櫛',
+'勝' => '吨',
+'勛' => '悗',
+'博' => '痔',
+'厥' => '婽',
+'啻' => '鉥',
+'喀' => '縝',
+'喧' => '唈',
+'啼' => '杽',
+'喊' => '滌',
+'喝' => '瘓',
+'喘' => '揚',
+'喂' => '庣',
+'喜' => '炰',
+'喪' => '犮',
+'喔' => '鉊',
+'喇' => '嶽',
+'喋' => '鄔',
+'喃' => '鄎',
+'喳' => '崍',
+'單' => '等',
+'喟' => '鈰',
+'唾' => '阽',
+'喲' => '荋',
+'喚' => '遢',
+'喻' => '郟',
+'喬' => 'Я',
+'喱' => '酮',
+'啾' => '鈺',
+'喉' => '綰',
+'喫' => '勛',
+'喙' => '鉆',
+'圍' => '峓',
+'堯' => '牶',
+'堪' => '膩',
+'場' => '部',
+'堤' => '腓',
+'堰' => '桋',
+'報' => '惆',
+'堡' => '惜',
+'堝' => '跏',
+'堠' => '靬',
+'壹' => '瓞',
+'壺' => '綿',
+'奠' => '蛙',
+'婷' => '磌',
+'媚' => '藥',
+'婿' => '哤',
+'媒' => '羸',
+'媛' => '磏',
+'媧' => '瘣',
+'孳' => '箹',
+'孱' => '槴',
+'寒' => '漁',
+'富' => '蜓',
+'寓' => '唲',
+'寐' => '藕',
+'尊' => '郬',
+'尋' => '扆',
+'就' => '憩',
+'嵌' => 'И',
+'嵐' => '嵹',
+'崴' => '慬',
+'嵇' => '燿',
+'巽' => '毰',
+'幅' => '盟',
+'帽' => '簽',
+'幀' => '痋',
+'幃' => '僤',
+'幾' => '撓',
+'廊' => '檀',
+'廁' => '翎',
+'廂' => '眃',
+'廄\' => '學',
+'弼' => '氀',
+'彭' => '鱖',
+'復' => '葩',
+'循' => '悜',
+'徨' => '摎',
+'惑' => '鼻',
+'惡' => '填',
+'悲' => '扈',
+'悶' => '蟻',
+'惠' => '需',
+'愜' => '舕',
+'愣' => '蒹',
+'惺' => '倇',
+'愕' => '蒫',
+'惰' => '嗉',
+'惻' => '禕',
+'惴' => '蒴',
+'慨' => '耨',
+'惱' => '齣',
+'愎' => '蓍',
+'惶' => '鉻',
+'愉' => '赸',
+'愀' => '蓁',
+'愒' => '',
+'戟' => '磢',
+'扉' => '擩',
+'掣' => '雩',
+'掌' => '梪',
+'描' => '鏡',
+'揀' => '滕',
+'揩' => '翰',
+'揉' => '',
+'揆' => '碖',
+'揍' => '軡',
+'插' => '脣',
+'揣' => '揮',
+'提' => '枑',
+'握' => '挍',
+'揖' => '瓴',
+'揭' => '課',
+'揮' => '閨',
+'捶' => '晰',
+'援' => '堔',
+'揪' => '噢',
+'換' => '遙',
+'摒' => '碀',
+'揚' => '栨',
+'揹' => '掖',
+'敞' => '釣',
+'敦' => '嗟',
+'敢' => '詫',
+'散' => '汃',
+'斑' => '唯',
+'斐' => '麭',
+'斯' => '佴',
+'普' => 'ぱ',
+'晰' => '朐',
+'晴' => 'ю',
+'晶' => '儒',
+'景' => '劓',
+'暑' => '扻',
+'智' => '秷',
+'晾' => '謊',
+'晷' => '縟',
+'曾' => '崠',
+'替' => '杸',
+'期' => 'ぶ',
+'朝' => '陳',
+'棺' => '塽',
+'棕' => '趹',
+'棠' => '昉',
+'棘' => '憔',
+'棗' => '娹',
+'椅' => '眛',
+'棟' => '集',
+'棵' => '螢',
+'森' => '伬',
+'棧' => '梬',
+'棹' => '噮',
+'棒' => '堵',
+'棲' => 'へ',
+'棣' => '擐',
+'棋' => 'め',
+'棍' => '幔',
+'植' => '眵',
+'椒' => '蔆',
+'椎' => '袢',
+'棉' => '蹬',
+'棚' => '麟',
+'楮' => '匴',
+'棻' => '',
+'款' => '遴',
+'欺' => 'ぷ',
+'欽' => 'м',
+'殘' => '紹',
+'殖' => '硈',
+'殼' => '褲',
+'毯' => '抮',
+'氮' => '答',
+'氯' => '薰',
+'氬' => '貒',
+'港' => '誠',
+'游' => '蚔',
+'湔' => '馻',
+'渡' => '傾',
+'渲' => '馺',
+'湧' => '蚇',
+'湊' => '椎',
+'渠' => '',
+'渥' => '駂',
+'渣' => '崦',
+'減' => '熬',
+'湛' => '梲',
+'湘' => '盻',
+'渤' => '眾',
+'湖' => '綬',
+'湮' => '餂',
+'渭' => '弮',
+'渦' => '恦',
+'湯' => '抸',
+'渴' => '褡',
+'湍' => '苃',
+'渺' => '鏈',
+'測' => '聆',
+'湃' => '囌',
+'渝' => '趵',
+'渾' => '骰',
+'滋' => '訞',
+'溉' => '裙',
+'渙' => '鄘',
+'湎' => '餀',
+'湣' => '裶',
+'湄' => '馽',
+'湲' => '',
+'湩' => '',
+'湟' => '馜',
+'焙' => '捱',
+'焚' => '煞',
+'焦' => '蝴',
+'焰' => '栭',
+'無' => '拸',
+'然' => '',
+'煮' => '羜',
+'焜' => 'j',
+'牌' => '齪',
+'犄' => '艗',
+'犀' => '洉',
+'猶' => '蚝',
+'猥' => '漇',
+'猴' => '綽',
+'猩' => '倅',
+'琺' => '楨',
+'琪' => '踮',
+'琳' => '轅',
+'琢' => '袬',
+'琥' => '踖',
+'琵\' => '讓',
+'琶' => '鷗',
+'琴' => 'р',
+'琯' => '奪',
+'琛' => '銵',
+'琦' => '踛',
+'琨' => '踑',
+'甥' => '汏',
+'甦' => '劼',
+'畫' => '賒',
+'番' => '楓',
+'痢' => '薄',
+'痛' => '芫',
+'痣' => '謻',
+'痙' => '噸',
+'痘' => '飩',
+'痞' => 'あ',
+'痠' => '呫',
+'登' => '腎',
+'發' => '楷',
+'皖' => '侹',
+'皓' => '薳',
+'皴' => '鼫',
+'盜' => '聒',
+'睏' => '嬪',
+'短' => '傻',
+'硝' => '祌',
+'硬' => '茞',
+'硯' => '栱',
+'稍' => '尕',
+'稈' => '解',
+'程' => '最',
+'稅' => '阭',
+'稀' => '洁',
+'窘' => '噬',
+'窗' => '敦',
+'窖' => '諸',
+'童' => '肵',
+'竣' => '縈',
+'等' => '脹',
+'策' => '習',
+'筆' => '捩',
+'筐' => '遲',
+'筒' => '芠',
+'答' => '湘',
+'筍' => '囹',
+'筋' => '踐',
+'筏' => '楔',
+'筑' => '耟',
+'粟' => '厔',
+'粥' => '粖',
+'絞' => '褊',
+'結' => '賦',
+'絨' => '',
+'絕' => '橈',
+'紫' => '豜',
+'絮' => '哳',
+'絲' => '佪',
+'絡' => '釐',
+'給' => '跤',
+'絢' => '悀',
+'絰' => '',
+'絳' => '蝑',
+'善' => '囡',
+'翔' => '矧',
+'翕' => '酁',
+'耋' => '嚧',
+'聒' => '壛',
+'肅' => '咈',
+'腕' => '勂',
+'腔' => 'У',
+'腋' => '珚',
+'腑' => '葉',
+'腎' => '朳',
+'脹' => '梠',
+'腆' => '沶',
+'脾' => 'ゝ',
+'腌' => '錣',
+'腓' => '錒',
+'腴' => '錁',
+'舒' => '戺',
+'舜' => '侅',
+'菩' => 'ぬ',
+'萃' => '楢',
+'菸' => '楱',
+'萍' => 'じ',
+'菠' => '略',
+'菅' => '楪',
+'萋' => '暐',
+'菁' => '敯',
+'華' => '貌',
+'菱' => '鎂',
+'菴' => 'C',
+'著' => '翍',
+'萊' => '應',
+'菰' => '楗',
+'萌' => '蠍',
+'菌' => '歷',
+'菽' => '暊',
+'菲' => '滑',
+'菊' => '擅',
+'萸' => '晸',
+'萎' => '峸',
+'萄' => '曶',
+'菜' => '粕',
+'萇' => '剼',
+'菔' => '楟',
+'菟' => '椸',
+'虛' => '剞',
+'蛟' => '藜',
+'蛙' => '陃',
+'蛭' => '藬',
+'蛔' => '閤',
+'蛛' => '絇',
+'蛤' => '跟',
+'蛐' => '藸',
+'蛞' => '藟',
+'街' => '誰',
+'裁' => '笛',
+'裂' => '蹊',
+'袱' => '舅',
+'覃' => '嬾',
+'視' => '弝',
+'註' => '蛁',
+'詠' => '蚑',
+'評' => 'ぜ',
+'詞' => '棵',
+'証' => '痐',
+'詁' => '甯',
+'詔' => '痧',
+'詛' => '逡',
+'詐' => '晥',
+'詆' => '畬',
+'訴' => '咂',
+'診' => '淖',
+'訶' => '畯',
+'詖' => '',
+'象' => '砓',
+'貂' => '蘣',
+'貯' => '翏',
+'貼' => '泂',
+'貳' => '楚',
+'貽' => '縥',
+'賁' => '縖',
+'費' => '煤',
+'賀' => '種',
+'貴' => '幛',
+'買' => '鎗',
+'貶' => '晨',
+'貿' => '籀',
+'貸' => '湃',
+'越' => '埣',
+'超' => '閉',
+'趁' => '傢',
+'跎' => '巋',
+'距' => '擒',
+'跋' => '區',
+'跚\' => '孈',
+'跑' => '變',
+'跌' => '視',
+'跛' => '廱',
+'跆' => '懽',
+'軻' => '潞',
+'軸' => '粣',
+'軼' => '澞',
+'辜' => '匱',
+'逮' => '滋',
+'逵' => '槿',
+'週' => '笚',
+'逸' => '砯',
+'進' => '輛',
+'逶' => '槬',
+'鄂' => '塢',
+'郵' => '蚘',
+'鄉' => '盺',
+'郾' => '蛘',
+'酣' => '漕',
+'酥' => '匊',
+'量' => '講',
+'鈔' => '陵',
+'鈕' => '聽',
+'鈣' => '裟',
+'鈉' => '飄',
+'鈞' => '氅',
+'鈍' => '嗦',
+'鈐' => '鍘',
+'鈇' => '榥',
+'鈑' => '鍼',
+'閔' => '蓖',
+'閏' => '',
+'開' => '羲',
+'閑' => '玿',
+'間' => '潔',
+'閒' => '玿',
+'閎' => '蒨',
+'隊' => '勦',
+'階' => '論',
+'隋' => '呬',
+'陽' => '栠',
+'隅' => '趶',
+'隆' => '癒',
+'隍' => '絏',
+'陲' => '絖',
+'隄' => '腓',
+'雁' => '栜',
+'雅' => '捇',
+'雄' => '倯',
+'集' => '摩',
+'雇' => '嗶',
+'雯' => '鰫',
+'雲' => '堁',
+'韌' => '',
+'項' => '砐',
+'順' => '佼',
+'須' => '剕',
+'飧' => '漈',
+'飪' => '熂',
+'飯' => '溯',
+'飩' => '熀',
+'飲' => '窊',
+'飭' => '煻',
+'馮' => '瑛',
+'馭' => '啈',
+'黃' => '酴',
+'黍' => '抈',
+'黑' => '窪',
+'亂' => '觴',
+'傭' => '荈',
+'債' => '晢',
+'傲' => '偭',
+'傳' => '換',
+'僅' => '躺',
+'傾' => 'ъ',
+'催' => '殼',
+'傷' => '夼',
+'傻' => '伂',
+'傯' => '椗',
+'僇' => 'J',
+'剿' => '誼',
+'剷' => '莓',
+'剽' => '嵕',
+'募' => '躁',
+'勦' => '誼',
+'勤' => 'с',
+'勢' => '岊',
+'勣' => '憎',
+'匯' => '颯',
+'嗟' => '鉞',
+'嗨' => '鉖',
+'嗓' => '氻',
+'嗦' => '鉰',
+'嗎' => '鎘',
+'嗜' => '岓',
+'嗇' => '媊',
+'嗑' => '鉧',
+'嗣' => '佸',
+'嗤' => '閟',
+'嗯' => '鉣',
+'嗚' => '挎',
+'嗡' => '恂',
+'嗅' => '凊',
+'嗆' => 'М',
+'嗥' => '鉐',
+'嗉' => '鉏',
+'園' => '埶',
+'圓' => '埴',
+'塞' => '',
+'塑' => '呿',
+'塘' => '攽',
+'塗' => '芨',
+'塚' => '琭',
+'塔' => '坢',
+'填' => '沓',
+'塌' => '坵',
+'塭' => '恔',
+'塊' => '輸',
+'塢' => '昶',
+'塒' => '跜',
+'塋' => '塨',
+'奧' => '兜',
+'嫁' => '毆',
+'嫉' => '撐',
+'嫌' => '珃',
+'媾' => '磎',
+'媽' => '鎔',
+'媼' => '碻',
+'媳' => '炱',
+'嫂' => '肊',
+'媲' => '磈',
+'嵩' => '慡',
+'嵯' => '慺',
+'幌' => '銨',
+'幹' => '補',
+'廉' => '螳',
+'廈' => '狪',
+'弒' => '葑',
+'彙' => '颯',
+'徬' => '籥',
+'微' => '峚',
+'愚' => '豇',
+'意' => '砩',
+'慈' => '椅',
+'感' => '覜',
+'想' => '砑',
+'愛' => '乾',
+'惹' => '',
+'愁' => '啾',
+'愈' => '郛',
+'慎' => '氘',
+'慌' => '酷',
+'慄' => '璦',
+'慍' => '蒬',
+'愾' => '睾',
+'愴' => '碲',
+'愧\' => '壕',
+'愍' => '磲',
+'愆' => '磼',
+'愷' => '禔',
+'戡' => '磟',
+'戢' => '磭',
+'搓' => '湊',
+'搾' => '掍',
+'搞' => '詻',
+'搪' => '斨',
+'搭' => '減',
+'搽' => '舵',
+'搬' => '唸',
+'搏' => '疵',
+'搜' => '刲',
+'搔' => '犰',
+'損' => '囷',
+'搶' => 'Ш',
+'搖' => '牷',
+'搗' => '絲',
+'搆' => '凳',
+'敬' => '噹',
+'斟' => '涬',
+'新' => '陔',
+'暗' => '做',
+'暉' => '縡',
+'暇' => '狊',
+'暈' => '婠',
+'暖' => '轡',
+'暄' => '縠',
+'暘' => 'D',
+'暍' => '',
+'會' => '頗',
+'榔' => '曙',
+'業' => '珛',
+'楚' => '奠',
+'楷' => '翱',
+'楠' => '撉',
+'楔' => '虼',
+'極' => '憤',
+'椰' => '珙',
+'概' => '衙',
+'楊' => '栦',
+'楨' => '鳺',
+'楫' => '擙',
+'楞' => '濕',
+'楓' => '瑯',
+'楹' => '暻',
+'榆' => '衼',
+'楝' => '擛',
+'楣' => '暽',
+'楛' => '',
+'歇' => '衁',
+'歲' => '呡',
+'毀' => '障',
+'殿' => '蛔',
+'毓' => '媢',
+'毽' => '謔',
+'溢' => '祛',
+'溯' => '咁',
+'滓' => '貥',
+'溶' => '',
+'滂' => '儰',
+'源' => '埭',
+'溝' => '僱',
+'滇' => '菲',
+'滅' => '鏢',
+'溥' => '魠',
+'溘' => '髣',
+'溼' => '坁',
+'溺' => '櫺',
+'溫' => '恲',
+'滑' => '賑',
+'準' => '袧',
+'溜' => '闊',
+'滄' => '終',
+'滔' => '昑',
+'溪' => '洈',
+'溧' => '魡',
+'溴' => '麧',
+'煎' => '澆',
+'煙' => '捈',
+'煩' => '歲',
+'煤' => '繳',
+'煉' => '褻',
+'照' => '桽',
+'煜' => '嬥',
+'煬' => '儩',
+'煦' => '懠',
+'煌' => '銓',
+'煥' => '鄙',
+'煞' => '伢',
+'煆' => '牬',
+'煨' => '嬲',
+'煖' => '轡',
+'爺' => '玼',
+'牒' => '赮',
+'猷' => '歖',
+'獅' => '囧',
+'猿' => '堀',
+'猾' => '賓',
+'瑯' => '斃',
+'瑚' => '綢',
+'瑕' => '閬',
+'瑟' => '阞',
+'瑞' => '',
+'瑁' => '鋆',
+'琿' => '踥',
+'瑙' => '閫',
+'瑛' => '踕',
+'瑜' => '銴',
+'當' => '絞',
+'畸' => '儈',
+'瘀' => '贀',
+'痰' => '拑',
+'瘁' => '氮',
+'痲' => '鎊',
+'痱' => '貗',
+'痺' => '敘',
+'痿' => '贄',
+'痴' => '博',
+'痳' => '鎊',
+'盞' => '桮',
+'盟' => '襠',
+'睛' => '齒',
+'睫' => '豬',
+'睦' => '釋',
+'睞' => '薋',
+'督' => '飭',
+'睹' => '亂',
+'睪' => '媞',
+'睬' => '笞',
+'睜' => '淊',
+'睥' => '謖',
+'睨' => '薞',
+'睢' => '謘',
+'矮' => '鬥',
+'碎' => '呯',
+'碰' => '癲',
+'碗' => '俖',
+'碘' => '菊',
+'碌' => '繕',
+'碉' => '蛛',
+'硼' => '黴',
+'碑' => '戛',
+'碓' => '顈',
+'硿' => '',
+'祺' => '檉',
+'祿' => '罈',
+'禁' => '輦',
+'萬' => '勀',
+'禽' => 'ф',
+'稜' => '濩',
+'稚' => '窔',
+'稠' => '喱',
+'稔' => '獶',
+'稟' => '渳',
+'稞\' => '燽',
+'窟' => '貓',
+'窠' => '鬅',
+'筷' => '輳',
+'節' => '誹',
+'筠' => '鶀',
+'筮' => '鵸',
+'筧' => '鯫',
+'粱' => '覬',
+'粳' => '冀',
+'粵' => '埡',
+'經' => '冪',
+'絹' => '橫',
+'綑' => '嬪',
+'綁' => '堂',
+'綏' => '呦',
+'絛' => '昐',
+'置' => '离',
+'罩' => '欶',
+'罪' => '郫',
+'署' => '扰',
+'義' => '砱',
+'羨' => '畈',
+'群' => '',
+'聖' => '吤',
+'聘' => 'ご',
+'肆' => '佹',
+'肄' => '砨',
+'腱' => '錎',
+'腰' => '殈',
+'腸' => '釵',
+'腥' => '倞',
+'腮' => '',
+'腳' => '褐',
+'腫' => '笫',
+'腹' => '號',
+'腺' => '甮',
+'腦' => '齟',
+'舅' => '憲',
+'艇' => '竻',
+'蒂' => '菱',
+'葷' => '餌',
+'落' => '邈',
+'萱' => '楘',
+'葵' => '鋼',
+'葦' => '峟',
+'葫' => '綵',
+'葉' => '珔',
+'葬' => '婛',
+'葛' => '賅',
+'萼' => '椴',
+'萵' => '搦',
+'葡' => 'に',
+'董' => '雁',
+'葩' => '楀',
+'葭' => '楁',
+'葆' => '楩',
+'虞' => '訒',
+'虜' => '簡',
+'號' => '瘍',
+'蛹' => '蚍',
+'蜓' => '藘',
+'蜈' => '藢',
+'蜇' => '藯',
+'蜀' => '抁',
+'蛾' => '圓',
+'蛻' => '虭',
+'蜂' => '瑚',
+'蜃' => '藦',
+'蜆' => '罋',
+'蜊' => '蠀',
+'衙' => '捙',
+'裟' => '蠙',
+'裔' => '砡',
+'裙' => '',
+'補' => '硃',
+'裘' => '藽',
+'裝' => '蚾',
+'裡' => '爵',
+'裊' => '蘅',
+'裕' => '啥',
+'裒' => '渜',
+'覜' => '沷',
+'解' => '賤',
+'詫' => '莎',
+'該' => '蜆',
+'詳' => '砆',
+'試' => '彸',
+'詩' => '坅',
+'詰' => '痤',
+'誇' => '蹂',
+'詼' => '痗',
+'詣' => '祏',
+'誠' => '剴',
+'話' => '趕',
+'誅' => '紻',
+'詭' => '察',
+'詢' => '戙',
+'詮' => '盚',
+'詬' => '皒',
+'詹' => '梐',
+'詻' => '',
+'訾' => '鬗',
+'詨' => '',
+'豢' => '遛',
+'貊' => '蘜',
+'貉' => '碧',
+'賊' => '崞',
+'資' => '訧',
+'賈' => '樂',
+'賄' => '鞅',
+'貲' => '罃',
+'賃' => '醣',
+'賂' => '繡',
+'賅' => '罻',
+'跡' => '慫',
+'跟' => '躲',
+'跨' => '輻',
+'路' => '繚',
+'跳' => '泐',
+'跺' => '嗅',
+'跪' => '嶇',
+'跤' => '灃',
+'跦' => '胾',
+'躲' => '嗚',
+'較' => '誕',
+'載' => '婥',
+'軾' => '澮',
+'輊' => '澺',
+'辟' => '斬',
+'農' => '觼',
+'運' => '堍',
+'遊' => '蚔',
+'道' => '耋',
+'遂' => '咘',
+'達' => '湛',
+'逼' => '排',
+'違' => '峊',
+'遐' => '槲',
+'遇' => '郣',
+'遏' => '塊',
+'過' => '徹',
+'遍' => '梢',
+'遑' => '槾',
+'逾' => '貣',
+'遁' => '嗜',
+'鄒' => '軜',
+'鄗' => '輈',
+'酬' => '喚',
+'酪' => '檠',
+'酩' => '鶪',
+'釉' => '衲',
+'鈷' => '鎏',
+'鉗' => 'ヵ',
+'鈸' => '鍗',
+'鈽' => '鍹',
+'鉀' => '槭',
+'鈾\' => '蚎',
+'鉛' => 'レ',
+'鉋' => '蘸',
+'鉤' => '像',
+'鉑' => '痊',
+'鈴' => '鍊',
+'鉉' => '鍡',
+'鉍' => '鍣',
+'鉅' => '鍇',
+'鈹' => '鎀',
+'鈿' => '鍱',
+'鉚' => '穩',
+'閘' => '掅',
+'隘' => '偺',
+'隔' => '路',
+'隕' => '埩',
+'雍' => '蚨',
+'雋' => '鶬',
+'雉' => '濻',
+'雊' => '螅',
+'雷' => '濘',
+'電' => '萇',
+'雹' => '悻',
+'零' => '錨',
+'靖' => '噪',
+'靴' => '悒',
+'靶' => '匾',
+'預' => '啎',
+'頑' => '侻',
+'頓' => '嗨',
+'頊' => '趠',
+'頒' => '唬',
+'頌' => '佮',
+'飼' => '侞',
+'飴' => '熆',
+'飽' => '悼',
+'飾' => '庉',
+'馳' => '喊',
+'馱' => '邴',
+'馴' => '拲',
+'髡' => '孍',
+'鳩' => '藋',
+'麂' => '灛',
+'鼎' => '隋',
+'鼓' => '嘆',
+'鼠' => '扷',
+'僧' => '仵',
+'僮' => '椕',
+'僥' => '衝',
+'僖' => '棴',
+'僭' => '椆',
+'僚' => '豁',
+'僕' => 'ど',
+'像' => '砉',
+'僑' => 'а',
+'僱' => '嗶',
+'僎' => 'Q',
+'僩' => 'g',
+'兢' => '黎',
+'凳' => '脾',
+'劃' => '赫',
+'劂' => '崳',
+'匱' => '寍',
+'厭' => '栖',
+'嗾' => '雎',
+'嘀' => '雺',
+'嘛' => '鎰',
+'嘗' => '郭',
+'嗽' => '刱',
+'嘔' => '驍',
+'嘆' => '抩',
+'嘉' => '樁',
+'嘍' => '銃',
+'嘎' => '蜃',
+'嗷' => '鉬',
+'嘖' => '裞',
+'嘟' => '鉠',
+'嘈' => '閛',
+'嘐' => 'E',
+'嗶' => '萳',
+'團' => '芶',
+'圖' => '芞',
+'塵' => '鳥',
+'塾' => '觝',
+'境' => '噫',
+'墓' => '贏',
+'墊' => '菜',
+'塹' => 'З',
+'墅' => '旲',
+'塽' => 'u',
+'壽' => '忭',
+'夥' => '漞',
+'夢' => '襞',
+'夤' => '漡',
+'奪' => '嗤',
+'奩' => '榃',
+'嫡' => '菅',
+'嫦' => '禢',
+'嫩' => '囂',
+'嫗' => '濆',
+'嫖' => '禜',
+'嫘' => '禛',
+'嫣' => '禡',
+'孵' => '痿',
+'寞' => '蠕',
+'寧' => '譴',
+'寡' => '塾',
+'寥' => '賺',
+'實' => '妗',
+'寨' => '朘',
+'寢' => 'х',
+'寤' => '撱',
+'察' => '舷',
+'對' => '勤',
+'屢' => '藍',
+'嶄' => '楖',
+'嶇' => '嶉',
+'幛' => '嶀',
+'幣' => '啟',
+'幕' => '躉',
+'幗' => '僠',
+'幔' => '嶂',
+'廓' => '尷',
+'廖' => '蹉',
+'弊' => '斜',
+'彆' => '梗',
+'彰' => '桼',
+'徹' => '章',
+'慇' => '秜',
+'愿' => '堋',
+'態' => '怓',
+'慷' => '蕊',
+'慢' => '鞣',
+'慣' => '嫦',
+'慟' => '禋',
+'慚' => '紼',
+'慘' => '絀',
+'慵' => '蒱',
+'截' => '諍',
+'撇' => 'ぎ',
+'摘' => '晡',
+'摔' => '豸',
+'撤' => '雪',
+'摸' => '類',
+'摟' => '禮',
+'摺' => '腄',
+'摑' => '睭',
+'摧' => '殘',
+'搴' => '摨',
+'摭' => '稢',
+'摻' => '莖',
+'敲' => 'Ы',
+'斡' => '扃',
+'旗' => 'よ',
+'旖' => '儠',
+'暢' => '釧',
+'暨' => '轚',
+'暝\' => '縜',
+'榜' => '埤',
+'榨' => '掍',
+'榕' => '橝',
+'槁' => '樲',
+'榮' => '',
+'槓' => '話',
+'構' => '凳',
+'榛' => '暺',
+'榷' => '',
+'榻' => '朣',
+'榫' => '樴',
+'榴' => '闌',
+'槐' => '跼',
+'槍' => 'Л',
+'榭' => '橦',
+'槌' => '曈',
+'榦' => '補',
+'槃' => '攫',
+'榣' => 'l',
+'歉' => 'К',
+'歌' => '貉',
+'氳' => '賮',
+'漳' => '桫',
+'演' => '栳',
+'滾' => '幗',
+'漓' => '燬',
+'滴' => '舒',
+'漩' => '噈',
+'漾' => '歭',
+'漠' => '蠔',
+'漬' => '赹',
+'漏' => '穢',
+'漂' => 'か',
+'漢' => '犖',
+'滿' => '雛',
+'滯' => '笴',
+'漆' => 'ぽ',
+'漱' => '杇',
+'漸' => '膝',
+'漲' => '梀',
+'漣' => '蟆',
+'漕' => '儋',
+'漫' => '鞦',
+'漯' => '僽',
+'澈' => '竟',
+'漪' => '勱',
+'滬' => '誚',
+'漁' => '趷',
+'滲' => '汆',
+'滌' => '萍',
+'滷' => '簣',
+'熔' => '',
+'熙' => '昝',
+'煽' => '刐',
+'熊' => '倱',
+'熄' => '洠',
+'熒' => '茷',
+'爾' => '嫌',
+'犒' => '蕍',
+'犖' => '媻',
+'獄' => '郜',
+'獐' => '滽',
+'瑤' => '毤',
+'瑣' => '坱',
+'瑪' => '鎖',
+'瑰' => '孵',
+'瑭' => '閰',
+'甄' => '淢',
+'疑' => '疶',
+'瘧' => '鑄',
+'瘍' => '桍',
+'瘋' => '瑁',
+'瘉' => '郛',
+'瘓' => '遝',
+'盡' => '鴃',
+'監' => '潼',
+'瞄' => '鏑',
+'睽' => '謋',
+'睿' => '謑',
+'睡' => '阯',
+'磁' => '棠',
+'碟' => '詠',
+'碧' => '捺',
+'碳' => '抯',
+'碩' => '侀',
+'碣' => '繇',
+'禎' => '檁',
+'福' => '腦',
+'禍' => '儀',
+'種' => '笱',
+'稱' => '備',
+'窪' => '俍',
+'窩' => '恮',
+'竭' => '賠',
+'端' => '傷',
+'管' => '奪',
+'箕' => '凜',
+'箋' => '潦',
+'筵' => '鶄',
+'算' => '呾',
+'箝' => '鶅',
+'箔' => '痍',
+'箏' => '鵱',
+'箸' => '鵰',
+'箇' => '跺',
+'箄' => '靴',
+'粹' => '氯',
+'粽' => '譭',
+'精' => '儕',
+'綻' => '梏',
+'綰' => '蝥',
+'綜' => '軘',
+'綽' => '朝',
+'綾' => '蝐',
+'綠' => '蟯',
+'緊' => '踡',
+'綴' => '袟',
+'網' => '厙',
+'綱' => '詼',
+'綺' => '蝎',
+'綢' => '喙',
+'綿' => '蹴',
+'綵' => '粗',
+'綸' => '蹣',
+'維' => '峎',
+'緒' => '唚',
+'緇' => '蝏',
+'綬' => '蝺',
+'罰' => '楠',
+'翠' => '港',
+'翡' => '醵',
+'翟' => '菠',
+'聞' => '恓',
+'聚' => '擄',
+'肇' => '欷',
+'腐' => '葛',
+'膀' => '基',
+'膏' => '詮',
+'膈' => '錴',
+'膊' => '眷',
+'腿' => '虯',
+'膂' => '錂',
+'臧' => '穈',
+'臺' => '怢',
+'與' => '迵',
+'舔' => '泙',
+'舞' => '敃',
+'艋' => '藾',
+'蓉' => '',
+'蒿' => '楑',
+'蓆' => '炟',
+'蓄' => '匎',
+'蒙' => '蟹',
+'蒞' => '搯',
+'蒲' => 'ね',
+'蒜' => '呺',
+'蓋\' => '裔',
+'蒸' => '淛',
+'蓀' => '搘',
+'蓓' => '楜',
+'蒐' => '彳',
+'蒼' => '紳',
+'蓑' => '坯',
+'蓊' => '楏',
+'蜿' => '襚',
+'蜜' => '蹲',
+'蜻' => '蟷',
+'蜢' => '襗',
+'蜥' => '蠌',
+'蜴' => '蟿',
+'蜘' => '眯',
+'蝕' => '妠',
+'蜷' => '襢',
+'蜩' => '蠂',
+'裳' => '奷',
+'褂' => '墓',
+'裴' => '鑤',
+'裹' => '彰',
+'裸' => '邃',
+'製' => '秶',
+'裨' => '鵋',
+'褚' => '鵊',
+'裯' => '峮',
+'誦' => '刵',
+'誌' => '祩',
+'語' => '逄',
+'誣' => '挏',
+'認' => '',
+'誡' => '趟',
+'誓' => '岉',
+'誤' => '昫',
+'說' => '佽',
+'誥' => '睅',
+'誨' => '餃',
+'誘' => '袀',
+'誑' => '睊',
+'誚' => '睍',
+'誧' => '惃',
+'豪' => '瑰',
+'貍' => '燥',
+'貌' => '簷',
+'賓' => '梅',
+'賑' => '罺',
+'賒' => '弚',
+'赫' => '禎',
+'趙' => '梊',
+'趕' => '裒',
+'跼' => '擁',
+'輔' => '落',
+'輒' => '濏',
+'輕' => 'ш',
+'輓' => '侺',
+'辣' => '彌',
+'遠' => '堈',
+'遘' => '樔',
+'遜' => '挶',
+'遣' => 'Е',
+'遙' => '猀',
+'遞' => '菰',
+'遢' => '槷',
+'遝' => '穖',
+'遛' => '槧',
+'鄙' => '捻',
+'鄘' => '颩',
+'鄞' => '蛓',
+'酵' => '談',
+'酸' => '呫',
+'酷' => '蹄',
+'酴' => '鶨',
+'鉸' => '蝓',
+'銀' => '窅',
+'銅' => '肣',
+'銘' => '霧',
+'銖' => '霘',
+'鉻' => '跳',
+'銓' => '鞡',
+'銜' => '玴',
+'銨' => '鴽',
+'鉼' => '綦',
+'銑' => '炡',
+'閡' => '碳',
+'閨' => '寨',
+'閩' => '關',
+'閣' => '跨',
+'閥' => '概',
+'閤' => '跨',
+'隙' => '炩',
+'障' => '梤',
+'際' => '暱',
+'雌' => '棘',
+'雒' => '鶱',
+'需' => '剒',
+'靼' => '鱁',
+'鞅' => '鰼',
+'韶' => '屻',
+'頗' => 'だ',
+'領' => '鍰',
+'颯' => '鴘',
+'颱' => '怢',
+'餃' => '褓',
+'餅' => '欲',
+'餌' => '媾',
+'餉' => '熁',
+'駁' => '眶',
+'骯' => '偎',
+'骰' => '鷋',
+'髦' => '巘',
+'魁' => '錄',
+'魂' => '骯',
+'鳴' => '霪',
+'鳶' => '藎',
+'鳳' => '瘀',
+'麼' => '繫',
+'鼻' => '掏',
+'齊' => 'ょ',
+'億' => '砬',
+'儀' => '痀',
+'僻' => 'ぃ',
+'僵' => '蔗',
+'價' => '歎',
+'儂' => '棬',
+'儈' => '辨',
+'儉' => '潟',
+'儅' => '絞',
+'凜' => '鄹',
+'劇' => '曄',
+'劈' => '衢',
+'劉' => '隸',
+'劍' => '膛',
+'劊' => '幣',
+'勰' => '裗',
+'厲' => '癆',
+'嘮' => '蜎',
+'嘻' => '柁',
+'嘹' => '靳',
+'嘲' => '陸',
+'嘿' => '稱',
+'嘴' => '郲',
+'嘩' => '貍',
+'噓' => '剟',
+'噎' => '珥',
+'噗' => '靷',
+'噴' => '驗',
+'嘶' => '侄',
+'嘯' => '苭',
+'嘰' => '葧',
+'墀' => '鳦',
+'墟' => '剡',
+'增' => '崝',
+'墳' => '煥',
+'墜' => '袡',
+'墮' => '園',
+'墩' => '勢',
+'墦\' => '',
+'奭' => ']',
+'嬉' => '稹',
+'嫻' => '瘚',
+'嬋' => '瞈',
+'嫵' => '澇',
+'嬌' => '蝙',
+'嬈' => '甈',
+'寮' => '撘',
+'寬' => '遵',
+'審' => '机',
+'寫' => '迡',
+'層' => '脯',
+'履' => '薩',
+'嶝' => '戫',
+'嶔' => '',
+'幢' => '敢',
+'幟' => '秺',
+'幡' => '嶆',
+'廢' => '煙',
+'廚' => '報',
+'廟' => '鏜',
+'廝' => '媌',
+'廣' => '嫘',
+'廠' => '釦',
+'彈' => '粟',
+'影' => '荌',
+'德' => '肅',
+'徵' => '摞',
+'慶' => '④',
+'慧' => '雌',
+'慮' => '藉',
+'慝' => '礅',
+'慕' => '躅',
+'憂' => '蚡',
+'慼' => 'べ',
+'慰' => '怷',
+'慫' => '佫',
+'慾' => '郗',
+'憧' => '蒧',
+'憐' => '蟒',
+'憫' => '鏨',
+'憎' => '崚',
+'憬' => '蓐',
+'憚' => '筋',
+'憤' => '猷',
+'憔' => '蒝',
+'憮' => '瞅',
+'戮' => '職',
+'摩' => '藻',
+'摯' => '祪',
+'摹' => '纂',
+'撞' => '袉',
+'撲' => 'で',
+'撈' => '檜',
+'撐' => '傅',
+'撰' => '蚴',
+'撥' => '畢',
+'撓' => '鼯',
+'撕' => '侉',
+'撩' => '謄',
+'撒' => '',
+'撮' => '湧',
+'播' => '畦',
+'撫' => '葷',
+'撚' => '瓔',
+'撬' => 'г',
+'撙' => '艉',
+'撢' => '筆',
+'撳' => '碡',
+'敵' => '菩',
+'敷' => '痱',
+'數' => '杅',
+'暮' => '贍',
+'暫' => '婃',
+'暴' => '惟',
+'暱' => '糒',
+'樣' => '欴',
+'樟' => '桷',
+'槨' => '擗',
+'樁' => '蛃',
+'樞' => '忺',
+'標' => '梓',
+'槽' => '羞',
+'模' => '耀',
+'樓' => '瞼',
+'樊' => '榆',
+'槳' => '蔑',
+'樂' => '氈',
+'樅' => '駏',
+'槭' => '樨',
+'樑' => '褽',
+'歐' => '韁',
+'歎' => '抩',
+'殤' => '毈',
+'毅' => '砳',
+'毆' => '饕',
+'漿' => '蓮',
+'潼' => '噉',
+'澄' => '割',
+'潑' => 'た',
+'潦' => '購',
+'潔' => '賞',
+'澆' => '蝸',
+'潭' => '抾',
+'潛' => 'Д',
+'潸' => '噁',
+'潮' => '陰',
+'澎' => '鱗',
+'潺' => '噆',
+'潰' => '壓',
+'潤' => '',
+'澗' => '膚',
+'潘' => '攣',
+'滕' => '鋿',
+'潯' => '銆',
+'潠' => '',
+'潟' => '籅',
+'熟' => '抇',
+'熬' => '偏',
+'熱' => '',
+'熨' => '寲',
+'牖' => '趥',
+'犛' => '膧',
+'獎' => '蔣',
+'獗' => '漹',
+'瑩' => '茖',
+'璋' => '靚',
+'璃' => '薛',
+'瑾' => '隤',
+'璀' => '霅',
+'畿' => '諗',
+'瘠' => '韙',
+'瘩' => '渤',
+'瘟' => '恔',
+'瘤' => '雖',
+'瘦' => '忡',
+'瘡' => '敞',
+'瘢' => '韗',
+'皚' => '馬',
+'皺' => '紶',
+'盤' => '攫',
+'瞎' => '牊',
+'瞇' => '譜',
+'瞌' => '謏',
+'瞑' => '謒',
+'瞋' => '淪',
+'磋' => '渲',
+'磅' => '執',
+'確' => '',
+'磊' => '濠',
+'碾' => '犧',
+'磕' => '融',
+'碼' => '鎢',
+'磐' => '攪',
+'稿' => '詨',
+'稼' => '歐',
+'穀\' => '嗷',
+'稽' => '儉',
+'稷' => '艟',
+'稻' => '翔',
+'窯' => '狺',
+'窮' => '⑥',
+'箭' => '璋',
+'箱' => '眊',
+'範' => '毓',
+'箴' => '鶇',
+'篆' => '蚼',
+'篇' => 'う',
+'篁' => '麔',
+'箠' => '憸',
+'篌' => '麑',
+'糊' => '緇',
+'締' => '萌',
+'練' => '褶',
+'緯' => '帠',
+'緻' => '祡',
+'緘' => '澎',
+'緬' => '邋',
+'緝' => '憬',
+'編' => '晤',
+'緣' => '埽',
+'線' => '盄',
+'緞' => '剷',
+'緩' => '遣',
+'綞' => '蝬',
+'緙' => '蝻',
+'緲' => '蝧',
+'緹' => '蝢',
+'罵' => '鎬',
+'罷' => '啦',
+'羯' => '蠖',
+'翩' => '醳',
+'耦' => '勷',
+'膛' => '旼',
+'膜' => '臚',
+'膝' => '洏',
+'膠' => '蝶',
+'膚' => '痺',
+'膘' => '桿',
+'蔗' => '涫',
+'蔽' => '敖',
+'蔚' => '庰',
+'蓮' => '虧',
+'蔬' => '忣',
+'蔭' => '秭',
+'蔓' => '雞',
+'蔑' => '鏖',
+'蔣' => '蔓',
+'蔡' => '絆',
+'蔔' => '眺',
+'蓬' => '鷥',
+'蔥' => '棣',
+'蓿' => '煚',
+'蔆' => '鎂',
+'螂' => '襛',
+'蝴' => '維',
+'蝶' => '評',
+'蝠' => '襝',
+'蝦' => '牬',
+'蝸' => '恘',
+'蝨' => '坉',
+'蝙' => '譀',
+'蝗' => '銀',
+'蝌' => '覈',
+'蝓' => '觶',
+'衛' => '怹',
+'衝' => '喳',
+'褐' => '福',
+'複' => '葩',
+'褒' => '婪',
+'褓' => '鵒',
+'褕' => '',
+'褊' => '鵟',
+'誼' => '祓',
+'諒' => '謝',
+'談' => '抶',
+'諄' => '袘',
+'誕' => '筑',
+'請' => '③',
+'諸' => '絊',
+'課' => '諺',
+'諉' => '矞',
+'諂' => '硤',
+'調' => '覃',
+'誰' => '阰',
+'論' => '蹦',
+'諍' => '睆',
+'誶' => '硥',
+'誹' => '溧',
+'諛' => '矬',
+'豌' => '俁',
+'豎' => '旳',
+'豬' => '紿',
+'賠' => '靨',
+'賞' => '奼',
+'賦' => '董',
+'賤' => '獎',
+'賬' => '梖',
+'賭' => '傭',
+'賢' => '玵',
+'賣' => '闖',
+'賜' => '棹',
+'質' => '窐',
+'賡' => '疐',
+'赭' => '鐎',
+'趟' => '昋',
+'趣' => '',
+'踫' => '菋',
+'踐' => '犛',
+'踝' => '灉',
+'踢' => '杺',
+'踏' => '怳',
+'踩' => '笮',
+'踟' => '灅',
+'踡' => '襢',
+'踞' => '擔',
+'躺' => '旻',
+'輝' => '閩',
+'輛' => '謙',
+'輟' => '瞗',
+'輩' => '捲',
+'輦' => '澿',
+'輪' => '謫',
+'輜' => '磝',
+'輞' => '澸',
+'輥' => '幕',
+'適' => '巠',
+'遮' => '殑',
+'遨' => '槮',
+'遭' => '婈',
+'遷' => 'ヮ',
+'鄰' => '邁',
+'鄭' => '痑',
+'鄧' => '腌',
+'鄱' => '蛚',
+'醇' => '智',
+'醉' => '郳',
+'醋' => '棚',
+'醃' => '錣',
+'鋅' => '郈',
+'銻' => '枟',
+'銷' => '种',
+'鋪' => 'と',
+'銬' => '鍙',
+'鋤' => '堝',
+'鋁' => '臏',
+'銳' => '',
+'銼' => '黿',
+'鋒' => '瑟',
+'鋇' => '接',
+'鋰' => '黈',
+'銲' => '爾',
+'閭' => '蓏',
+'閱\' => '堐',
+'霄' => '祋',
+'霆' => '鰝',
+'震' => '涾',
+'霉' => '羅',
+'靠' => '蕞',
+'鞍' => '偽',
+'鞋' => '衧',
+'鞏' => '僥',
+'頡' => '礡',
+'頫' => '萱',
+'頜' => '礜',
+'颳' => '團',
+'養' => '欱',
+'餓' => '塒',
+'餒' => '囁',
+'餘' => '牄',
+'駝' => '邯',
+'駐' => '蚺',
+'駟' => '糌',
+'駛' => '妡',
+'駑' => '緪',
+'駕' => '毅',
+'駒' => '戰',
+'駙' => '糋',
+'骷' => '鷐',
+'髮' => '楷',
+'髯' => '蠯',
+'鬧' => '齡',
+'魅' => '黰',
+'魄' => 'っ',
+'魷' => '鼘',
+'魯' => '糧',
+'鴆' => '藅',
+'鴉' => '捋',
+'鴃' => '蘠',
+'麩' => '鐐',
+'麾' => '欏',
+'黎' => '燮',
+'墨' => '蘋',
+'齒' => '喘',
+'儒' => '',
+'儘' => '鴃',
+'儔' => '棱',
+'儐' => '棝',
+'儕' => '棜',
+'冀' => '播',
+'冪' => '蹶',
+'凝' => '覽',
+'劑' => '撙',
+'劓' => '崽',
+'勳' => '悗',
+'噙' => '頍',
+'噫' => '馰',
+'噹' => '絞',
+'噩' => '堿',
+'噤' => '馯',
+'噸' => '勣',
+'噪' => '婑',
+'器' => 'ん',
+'噥' => '蛺',
+'噱' => '馲',
+'噯' => '鉎',
+'噬' => '岕',
+'噢' => '頏',
+'噶' => '蜂',
+'壁' => '族',
+'墾' => '謀',
+'壇' => '抭',
+'壅' => '觛',
+'奮' => '煖',
+'嬝' => '蘅',
+'嬴' => '湋',
+'學' => '悝',
+'寰' => '敺',
+'導' => '絳',
+'彊' => 'Ч',
+'憲' => '疧',
+'憑' => 'ず',
+'憩' => '磹',
+'憊' => '措',
+'懍' => '蒢',
+'憶' => '砪',
+'憾' => '熄',
+'懊' => '冕',
+'懈' => '邽',
+'戰' => '桵',
+'擅' => '卍',
+'擁' => '茧',
+'擋' => '結',
+'撻' => '怊',
+'撼' => '熙',
+'據' => '擂',
+'擄' => '簞',
+'擇' => '寁',
+'擂' => '濯',
+'操' => '紱',
+'撿' => '潯',
+'擒' => 'у',
+'擔' => '童',
+'撾' => '恄',
+'整' => '淕',
+'曆' => '盪',
+'曉' => '窀',
+'暹' => '橀',
+'曄' => '糐',
+'曇' => '篥',
+'暸' => '',
+'樽' => '樼',
+'樸' => 'は',
+'樺' => '鳹',
+'橙' => '傀',
+'橫' => '筵',
+'橘' => '橖',
+'樹' => '攷',
+'橄' => '橪',
+'橢' => '邳',
+'橡' => '砎',
+'橋' => 'Э',
+'橇' => 'Щ',
+'樵' => '橯',
+'機' => '儂',
+'橈' => '魬',
+'歙' => '鴩',
+'歷' => '盪',
+'氅' => '諰',
+'濂' => '憟',
+'澱' => '蛭',
+'澡' => '婰',
+'濃' => '襯',
+'澤' => '屙',
+'濁' => '觙',
+'澧' => '憓',
+'澳' => '凰',
+'激' => '慾',
+'澹' => '憯',
+'澶' => '憭',
+'澦' => '',
+'澠' => '靻',
+'澴' => '',
+'熾' => '喋',
+'燉' => '嚓',
+'燐' => '避',
+'燒' => '尥',
+'燈' => '腑',
+'燕' => '桏',
+'熹' => '懥',
+'燎' => '豳',
+'燙' => '昍',
+'燜' => '壔',
+'燃' => '',
+'燄' => '栭',
+'獨' => '黃',
+'璜' => '隢',
+'璣' => '諃',
+'璘' => '苣',
+'璟' => '茂',
+'璞\' => '鞊',
+'瓢' => 'が',
+'甌' => '穇',
+'甍' => '歈',
+'瘴' => '梉',
+'瘸' => '',
+'瘺' => '蹞',
+'盧' => '竅',
+'盥' => '邅',
+'瞠' => '謇',
+'瞞' => '離',
+'瞟' => '謕',
+'瞥' => 'く',
+'磨' => '艦',
+'磚' => '蚸',
+'磬' => '縺',
+'磧' => '縳',
+'禦' => '郘',
+'積' => '儅',
+'穎' => '荓',
+'穆' => '鐃',
+'穌' => '龒',
+'穋' => '搾',
+'窺' => '錢',
+'篙' => '誅',
+'簑' => '坯',
+'築' => '耟',
+'篤' => '鬷',
+'篛' => '鵩',
+'篡' => '欺',
+'篩' => '伓',
+'篦' => '齀',
+'糕' => '詹',
+'糖' => '昒',
+'縊' => '褑',
+'縑' => '褎',
+'縈' => '楂',
+'縛' => '蛾',
+'縣' => '瓮',
+'縞' => '褆',
+'縝' => '褘',
+'縉' => '褗',
+'縐' => '蝘',
+'罹' => '蹌',
+'羲' => '襦',
+'翰' => '熔',
+'翱' => '倏',
+'翮' => '鐋',
+'耨' => '嚭',
+'膳' => '吇',
+'膩' => '櫻',
+'膨' => '壩',
+'臻' => '淶',
+'興' => '倓',
+'艘' => '刳',
+'艙' => '組',
+'蕊' => '',
+'蕙' => '犍',
+'蕈' => '犌',
+'蕨' => '犑',
+'蕩' => '絕',
+'蕃' => '猻',
+'蕉' => '蓿',
+'蕭' => '祊',
+'蕪' => '拶',
+'蕞' => '犎',
+'螃' => '韟',
+'螟' => '難',
+'螞' => '鎳',
+'螢' => '茤',
+'融' => '',
+'衡' => '算',
+'褪' => '虮',
+'褲' => '踴',
+'褥' => '',
+'褫' => '鵚',
+'褡' => '鵌',
+'親' => 'о',
+'覦' => '膵',
+'諦' => '硞',
+'諺' => '桎',
+'諫' => '硭',
+'諱' => '颱',
+'謀' => '覺',
+'諜' => '証',
+'諧' => '迣',
+'諮' => '硢',
+'諾' => '霾',
+'謁' => '硪',
+'謂' => '彖',
+'諷' => '當',
+'諭' => '硰',
+'諳' => '硨',
+'諶' => '硜',
+'諼' => '硩',
+'豫' => '唹',
+'豭' => '啷',
+'貓' => '癡',
+'賴' => '懇',
+'蹄' => '枃',
+'踱' => '礱',
+'踴' => '蚖',
+'蹂' => '籓',
+'踹' => '癪',
+'踵' => '矐',
+'輻' => '盞',
+'輯' => '憮',
+'輸' => '怀',
+'輳' => '磩',
+'辨' => '望',
+'辦' => '域',
+'遵' => '郩',
+'遴' => '樈',
+'選' => '恁',
+'遲' => '喧',
+'遼' => '賽',
+'遺' => '疻',
+'鄴' => '罥',
+'醒' => '倳',
+'錠' => '陽',
+'錶' => '桶',
+'鋸' => '撾',
+'錳' => '襟',
+'錯' => '渣',
+'錢' => 'ヴ',
+'鋼' => '詩',
+'錫' => '柈',
+'錄' => '翹',
+'錚' => '鵃',
+'錐' => '袪',
+'錦' => '踞',
+'錡' => '',
+'錕' => '嚙',
+'錮' => '奰',
+'錙' => '幭',
+'閻' => '晑',
+'隧' => '呣',
+'隨' => '呴',
+'險' => '玸',
+'雕' => '蛐',
+'霎' => '鰨',
+'霑' => '桭',
+'霖' => '遽',
+'霍' => '齊',
+'霓' => '巍',
+'霏' => '鰣',
+'靛' => '萄',
+'靜' => '噙',
+'靦' => '沶',
+'鞘' => 'в',
+'頰' => '槳',
+'頸' => '勳',
+'頻' => 'け',
+'頷' => '禰',
+'頭' => '芛',
+'頹' => '虰',
+'頤' => '疰',
+'餐\' => '絃',
+'館' => '奩',
+'餞' => '膜',
+'餛' => '牓',
+'餡' => '畇',
+'餚' => '躽',
+'駭' => '漣',
+'駢' => '縃',
+'駱' => '醬',
+'骸' => '滿',
+'骼' => '鷩',
+'髻' => '戁',
+'髭' => '戃',
+'鬨' => '箏',
+'鮑' => '惚',
+'鴕' => '迗',
+'鴣' => '薱',
+'鴦' => '栒',
+'鴨' => '捊',
+'鴒' => '鍔',
+'鴛' => '唭',
+'默' => '蘇',
+'黔' => 'ン',
+'龍' => '韓',
+'龜' => '實',
+'優' => '蚥',
+'償' => '野',
+'儡' => '濤',
+'儲' => '揣',
+'勵' => '療',
+'嚎' => '瑪',
+'嚀' => '萭',
+'嚐' => '郭',
+'嚅' => '骫',
+'嚇' => '狣',
+'嚏' => '杹',
+'壕' => '瑣',
+'壓' => '揤',
+'壑' => '詎',
+'壎' => '跕',
+'嬰' => '茪',
+'嬪' => '磄',
+'嬤' => '箷',
+'孺' => '',
+'尷' => '瘐',
+'屨' => '歑',
+'嶼' => '适',
+'嶺' => '鍛',
+'嶽' => '埬',
+'嶸' => '慓',
+'幫' => '堆',
+'彌' => '譆',
+'徽' => '閣',
+'應' => '茼',
+'懂' => '雅',
+'懇' => '諜',
+'懦' => '鑒',
+'懋' => '礄',
+'戲' => '牁',
+'戴' => '渴',
+'擎' => 'э',
+'擊' => '僻',
+'擘' => '諲',
+'擠' => '撥',
+'擰' => '禳',
+'擦' => '笠',
+'擬' => '攜',
+'擱' => '賊',
+'擢' => '萿',
+'擭' => 'N',
+'斂' => '螻',
+'斃' => '教',
+'曙' => '扺',
+'曖' => '縎',
+'檀' => '抴',
+'檔' => '紫',
+'檄' => '洐',
+'檢' => '潰',
+'檜' => '鴈',
+'櫛' => '駘',
+'檣' => '橑',
+'橾' => '癲',
+'檗' => '歕',
+'檐' => '橎',
+'檠' => '橐',
+'歜' => 'b',
+'殮' => '氃',
+'毚' => '',
+'氈' => '梇',
+'濘' => '籠',
+'濱' => '梆',
+'濟' => '撳',
+'濠' => '憍',
+'濛' => '蟹',
+'濤' => '旽',
+'濫' => '斂',
+'濯' => '慦',
+'澀' => '优',
+'濬' => '縛',
+'濡' => '憒',
+'濩' => 'C',
+'濕' => '坁',
+'濮' => '憪',
+'濰' => '峆',
+'燧' => '徾',
+'營' => '茠',
+'燮' => '袸',
+'燦' => '細',
+'燥' => '孲',
+'燭' => '羕',
+'燬' => '障',
+'燴' => '領',
+'燠' => '幬',
+'爵' => '橋',
+'牆' => 'Х',
+'獰' => '襬',
+'獲' => '鳳',
+'璩' => '鞈',
+'環' => '遠',
+'璦' => '閮',
+'璨' => '鞎',
+'癆' => '謽',
+'療' => '谿',
+'癌' => '骨',
+'盪' => '絕',
+'瞳' => '肏',
+'瞪' => '腆',
+'瞰' => '謍',
+'瞬' => '侘',
+'瞧' => 'Ю',
+'瞭' => '賸',
+'矯' => '衛',
+'磷' => '避',
+'磺' => '鉸',
+'磴' => '罾',
+'磯' => '穚',
+'礁' => '螂',
+'禧' => '檞',
+'禪' => '檟',
+'穗' => '呠',
+'窿' => '騁',
+'簇' => '楮',
+'簍' => '穡',
+'篾' => '齖',
+'篷' => '囑',
+'簌' => '齍',
+'篠' => '鵽',
+'糠' => '蕙',
+'糜' => '譚',
+'糞' => '獅',
+'糢' => '耀',
+'糟' => '媎',
+'糙' => '缽',
+'糝' => '趮',
+'縮' => '坫',
+'績' => '憎',
+'繆' => '觭',
+'縷\' => '藐',
+'縲' => '覣',
+'繃' => '掄',
+'縫' => '瑜',
+'總' => '軞',
+'縱' => '軝',
+'繅' => '觰',
+'繁' => '楛',
+'縴' => '玹',
+'縹' => '覢',
+'繈' => '麌',
+'縵' => '覤',
+'縿' => '',
+'縯' => '栳',
+'罄' => '騔',
+'翳' => '鐓',
+'翼' => '秫',
+'聱' => '嬽',
+'聲' => '汒',
+'聰' => '棲',
+'聯' => '薊',
+'聳' => '侕',
+'臆' => '砵',
+'臃' => '虓',
+'膺' => '瘊',
+'臂' => '旋',
+'臀' => '迓',
+'膿' => '襲',
+'膽' => '筐',
+'臉' => '螺',
+'膾' => '醑',
+'臨' => '還',
+'舉' => '撼',
+'艱' => '潸',
+'薪' => '郇',
+'薄' => '情',
+'蕾' => '濟',
+'薜' => '瑑',
+'薑' => '蔽',
+'薔' => 'Ц',
+'薯' => '扱',
+'薛' => '悁',
+'薇' => '瑄',
+'薨' => '獉',
+'薊' => '撒',
+'虧' => '鋸',
+'蟀' => '饇',
+'蟑' => '饈',
+'螳' => '颿',
+'蟒' => '譕',
+'蟆' => '鞳',
+'螫' => '顜',
+'螻' => '譈',
+'螺' => '蹟',
+'蟈' => '蠈',
+'蟋' => '颽',
+'褻' => '湝',
+'褶' => '麎',
+'襄' => '盷',
+'褸' => '鵔',
+'褽' => '浺',
+'覬' => '膦',
+'謎' => '譏',
+'謗' => '娶',
+'謙' => 'ヱ',
+'講' => '蔡',
+'謊' => '銑',
+'謠' => '狴',
+'謝' => '郅',
+'謄' => '杴',
+'謐' => '稊',
+'豁' => '魁',
+'谿' => '洈',
+'豳' => '搫',
+'賺' => '蚻',
+'賽' => '',
+'購' => '劃',
+'賸' => '呁',
+'賻' => '聬',
+'趨' => '⑸',
+'蹉' => '礯',
+'蹋' => '怗',
+'蹈' => '絡',
+'蹊' => '纇',
+'轄' => '牮',
+'輾' => '梫',
+'轂' => '麇',
+'轅' => '埢',
+'輿' => '豗',
+'避' => '旌',
+'遽' => '槦',
+'還' => '遜',
+'邁' => '闐',
+'邂' => '槻',
+'邀' => '肂',
+'鄹' => '蛝',
+'醣' => '麙',
+'醞' => '奜',
+'醜' => '堯',
+'鍍' => '傲',
+'鎂' => '臘',
+'錨' => '礙',
+'鍵' => '瑩',
+'鍊' => '',
+'鍥' => '幮',
+'鍋' => '廓',
+'錘' => '晴',
+'鍾' => '瀎',
+'鍬' => 'Ъ',
+'鍛' => '傯',
+'鍰' => '懪',
+'鍚' => '',
+'鍔' => '懭',
+'闊' => '屨',
+'闋' => '蜨',
+'闌' => '擊',
+'闈' => '蒯',
+'闆' => '啣',
+'隱' => '笐',
+'隸' => '薔',
+'雖' => '呥',
+'霜' => '邞',
+'霞' => '牳',
+'鞠' => '懍',
+'韓' => '澈',
+'顆' => '衡',
+'颶' => '鴢',
+'餵' => '庣',
+'騁' => '勞',
+'駿' => '縞',
+'鮮' => '珅',
+'鮫' => '巑',
+'鮪' => '孋',
+'鮭' => '囋',
+'鴻' => '箄',
+'鴿' => '賈',
+'麋' => '玂',
+'黏' => '薴',
+'點' => '萸',
+'黜' => '籦',
+'黝' => '纕',
+'黛' => '籧',
+'鼾' => '襳',
+'齋' => '晛',
+'叢' => '椒',
+'嚕' => '頎',
+'嚮' => '砃',
+'壙' => '詗',
+'壘' => '濫',
+'嬸' => '朿',
+'彝' => '眝',
+'懣' => '禫',
+'戳' => '期',
+'擴' => '孺',
+'擲' => '祣',
+'擾' => '',
+'攆' => '瓖',
+'擺\' => '啊',
+'擻' => '剆',
+'擷' => '腡',
+'斷' => '剿',
+'曜' => '縢',
+'朦' => '錪',
+'檳' => '樾',
+'檬' => '蟾',
+'櫃' => '嶄',
+'檻' => '熨',
+'檸' => '襪',
+'櫂' => '噮',
+'檮' => '',
+'檯' => '怢',
+'歟' => '鴥',
+'歸' => '寥',
+'殯' => '澣',
+'瀉' => '郕',
+'瀋' => '韎',
+'濾' => '薦',
+'瀆' => '鞃',
+'濺' => '膠',
+'瀑' => 'ふ',
+'瀏' => '銡',
+'燻' => '悇',
+'燼' => '輜',
+'燾' => '懧',
+'燸' => '^',
+'獷' => '搿',
+'獵' => '轂',
+'璧' => '韏',
+'璿' => '霂',
+'甕' => '怤',
+'癖' => '騉',
+'癘' => '謳',
+'癒' => '郛',
+'瞽' => '謆',
+'瞿' => '鶭',
+'瞻' => '桹',
+'瞼' => '薣',
+'礎' => '插',
+'禮' => '獰',
+'穡' => '艞',
+'穢' => '韶',
+'穠' => '',
+'竄' => '欽',
+'竅' => 'ж',
+'簫' => '鵿',
+'簧' => '銅',
+'簪' => '穮',
+'簞' => '鶂',
+'簣' => '鵨',
+'簡' => '潠',
+'糧' => '襄',
+'織' => '眽',
+'繕' => '圪',
+'繞' => '',
+'繚' => '諏',
+'繡' => '凎',
+'繒' => '諆',
+'繙' => '楹',
+'罈' => '抭',
+'翹' => 'д',
+'翻' => '楹',
+'職' => '眥',
+'聶' => '蘗',
+'臍' => 'ゆ',
+'臏' => '錤',
+'舊' => '導',
+'藏' => '紲',
+'薩' => '',
+'藍' => '懦',
+'藐' => '鏟',
+'藉' => '賢',
+'薰' => '瑐',
+'薺' => '媵',
+'薹' => '瑀',
+'薦' => '熱',
+'蟯' => '藗',
+'蟬' => '莽',
+'蟲' => '單',
+'蟠' => '騚',
+'覆' => '葡',
+'覲' => '膰',
+'觴' => '蘩',
+'謨' => '祳',
+'謹' => '輝',
+'謬' => '韻',
+'謫' => '稃',
+'豐' => '猿',
+'贅' => '袑',
+'蹙' => '齙',
+'蹣' => '纊',
+'蹦' => '採',
+'蹤' => '趿',
+'蹟' => '慫',
+'蹕' => '櫼',
+'軀' => '⑼',
+'轉' => '蛌',
+'轍' => '殌',
+'邇' => '暷',
+'邃' => '槼',
+'邈' => '樍',
+'醫' => '瓟',
+'醬' => '蓬',
+'釐' => '濰',
+'鎔' => '',
+'鎊' => '夠',
+'鎖' => '坶',
+'鎢' => '挃',
+'鎳' => '蠢',
+'鎮' => '淜',
+'鎬' => '訾',
+'鎰' => '擼',
+'鎘' => '擽',
+'鎚' => '晴',
+'鎗' => 'Л',
+'闔' => '蝫',
+'闖' => '斑',
+'闐' => '蝀',
+'闕' => '蜮',
+'離' => '燭',
+'雜' => '娸',
+'雙' => '邧',
+'雛' => '堠',
+'雞' => '憐',
+'霤' => '闊',
+'鞣' => '鷛',
+'鞦' => '⑦',
+'鞭' => '晝',
+'韹' => '',
+'額' => '塗',
+'顏' => '晇',
+'題' => '枙',
+'顎' => '穧',
+'顓' => '穨',
+'颺' => '栨',
+'餾' => '闆',
+'餿' => '犕',
+'餽' => '嚏',
+'餮' => '劙',
+'馥' => '藆',
+'騎' => 'る',
+'髁' => '鷙',
+'鬃' => '跂',
+'鬆' => '侂',
+'魏' => '庥',
+'魎' => '鼲',
+'魍' => '齫',
+'鯊' => '灕',
+'鯉' => '牆',
+'鯽' => '灗',
+'鯈' => '',
+'鯀' => '氍',
+'鵑' => '暸',
+'鵝' => '塑',
+'鵠' => '蟪',
+'黠\' => '艬',
+'鼕' => '',
+'鼬' => '蠲',
+'儳' => '莫',
+'嚥' => '捗',
+'壞' => '輓',
+'壟' => '瞽',
+'壢' => '詅',
+'寵' => '唾',
+'龐' => '籣',
+'廬' => '簧',
+'懲' => '凱',
+'懷' => '輒',
+'懶' => '擱',
+'懵' => '蒔',
+'攀' => '戀',
+'攏' => '瞿',
+'曠' => '錠',
+'曝' => 'ぴ',
+'櫥' => '堰',
+'櫝' => '噰',
+'櫚' => '曀',
+'櫓' => '橠',
+'瀛' => '摮',
+'瀟' => '僶',
+'瀨' => '噘',
+'瀚' => '憳',
+'瀝' => '薑',
+'瀕' => '梭',
+'瀘' => '蜚',
+'爆' => '惇',
+'爍' => '佶',
+'牘' => '赬',
+'犢' => '馭',
+'獸' => '忤',
+'獺' => '怴',
+'璽' => '踣',
+'瓊' => '⑤',
+'瓣' => '國',
+'疇' => '喻',
+'疆' => '蔭',
+'癟' => '械',
+'癡' => '博',
+'矇' => '蟹',
+'礙' => '鬼',
+'禱' => '絰',
+'穫' => '鳳',
+'穩' => '恛',
+'簾' => '螫',
+'簿' => '移',
+'簸' => '穭',
+'簽' => 'ワ',
+'簷' => '橎',
+'籀' => '籉',
+'繫' => '炵',
+'繭' => '潺',
+'繹' => '秠',
+'繩' => '汋',
+'繪' => '餅',
+'羅' => '蹕',
+'繳' => '褕',
+'羶' => '錌',
+'羹' => '輊',
+'羸' => '湑',
+'臘' => '幫',
+'藩' => '楫',
+'藝' => '眙',
+'藪' => '瑒',
+'藕' => '驕',
+'藤' => '枘',
+'藥' => '狻',
+'藷' => '',
+'蟻' => '眐',
+'蠅' => '茯',
+'蠍' => '衎',
+'蟹' => '郱',
+'蟾' => '騤',
+'襠' => '鮸',
+'襟' => '踟',
+'襖' => '偯',
+'襞' => '蠐',
+'譁' => '貍',
+'譜' => 'び',
+'識' => '妎',
+'證' => '痐',
+'譚' => '抪',
+'譎' => '竦',
+'譏' => '憧',
+'譆' => '柁',
+'譙' => '窙',
+'贈' => '崌',
+'贊' => '婝',
+'蹼' => '纆',
+'蹲' => '匯',
+'躇' => '堡',
+'蹶' => '纋',
+'蹬' => '腋',
+'蹺' => '欂',
+'蹴' => '罍',
+'轔' => '磪',
+'轎' => '諄',
+'辭' => '棗',
+'邊' => '晚',
+'邋' => '槫',
+'醱' => 'づ',
+'醮' => '黥',
+'鏡' => '噩',
+'鏑' => '櫆',
+'鏟' => '莓',
+'鏃' => '檽',
+'鏈' => '蟈',
+'鏜' => '曛',
+'鏝' => '曘',
+'鏖' => '玃',
+'鏢' => '曚',
+'鏍' => '櫅',
+'鏘' => '懖',
+'鏤' => '懫',
+'鏗' => '麍',
+'鏨' => '鹺',
+'關' => '壽',
+'隴' => '瞻',
+'難' => '麵',
+'霪' => '鰩',
+'霧' => '昲',
+'靡' => '證',
+'韜' => '頨',
+'韻' => '婘',
+'類' => '濬',
+'願' => '堋',
+'顛' => '菌',
+'颼' => '鴐',
+'饅' => '雜',
+'饉' => '獍',
+'騖' => '緟',
+'騙' => 'ぉ',
+'鬍' => '綸',
+'鯨' => '儘',
+'鯧' => '瓘',
+'鯖' => '灒',
+'鯛' => '癭',
+'鶉' => '蟭',
+'鵡' => '蟤',
+'鵲' => '',
+'鵪' => '蟜',
+'鵬' => '灞',
+'麒' => '玁',
+'麗' => '璨',
+'麓' => '織',
+'麴' => '鐨',
+'勸' => '',
+'嚨' => '颶',
+'嚷' => '',
+'嚶' => '隑',
+'嚴' => '旆',
+'嚼' => '蝗',
+'壤' => '',
+'孀\' => '篋',
+'孃' => '矓',
+'孽' => '蘭',
+'寶' => '惘',
+'巉' => 'f',
+'懸' => '唑',
+'懺' => '睼',
+'攘' => '',
+'攔' => '戴',
+'攙' => '莢',
+'曦' => '縋',
+'朧' => '輮',
+'櫬' => '暾',
+'瀾' => '擠',
+'瀰' => '譆',
+'瀲' => '劋',
+'爐' => '簪',
+'獻' => '瓬',
+'瓏' => '貏',
+'癢' => '欭',
+'癥' => '痌',
+'礦' => '鄴',
+'礪' => '簋',
+'礬' => '楝',
+'礫' => '癌',
+'竇' => '鬄',
+'競' => '噥',
+'籌' => '喉',
+'籃' => '擎',
+'籍' => '戮',
+'糯' => '霽',
+'糰' => '芶',
+'辮' => '梯',
+'繽' => '褉',
+'繼' => '樟',
+'纂' => '郴',
+'罌' => '騜',
+'耀' => '珓',
+'臚' => '輹',
+'艦' => '耦',
+'藻' => '婍',
+'藹' => '高',
+'蘑' => '罌',
+'藺' => '毼',
+'蘆' => '竄',
+'蘋' => 'し',
+'蘇' => '劼',
+'蘊' => '堄',
+'蠔' => '罊',
+'蠕' => '',
+'襤' => '鵘',
+'覺' => '橇',
+'觸' => '揖',
+'議' => '祜',
+'譬' => 'ぅ',
+'警' => '劑',
+'譯' => '祒',
+'譟' => '婑',
+'譫' => '筊',
+'贏' => '荇',
+'贍' => '厊',
+'躉' => '齠',
+'躁' => '婇',
+'躅' => '羻',
+'躂' => '怳',
+'醴' => '黦',
+'釋' => '庋',
+'鐘' => '笘',
+'鐃' => '閷',
+'鏽' => '凄',
+'闡' => '莠',
+'霰' => '鰡',
+'飄' => 'お',
+'饒' => '',
+'饑' => '慰',
+'馨' => '黹',
+'騫' => '撟',
+'騰' => '枆',
+'騷' => '玊',
+'騵' => '矄',
+'鰓' => '',
+'鰍' => '籗',
+'鹹' => '玶',
+'麵' => '醱',
+'黨' => '絨',
+'鼯' => '蠮',
+'齟' => '鶼',
+'齣' => '堤',
+'齡' => '鍵',
+'儷' => '棖',
+'儸' => '蹕',
+'囁' => '鉯',
+'囀' => '裐',
+'囂' => '秕',
+'夔' => '淼',
+'屬' => '扽',
+'巍' => '峞',
+'懼' => '曉',
+'懾' => '扤',
+'攝' => '扜',
+'攜' => '觓',
+'斕' => '黖',
+'曩' => '縏',
+'櫻' => '茛',
+'欄' => '戲',
+'櫺' => '凞',
+'殲' => '漿',
+'灌' => '嫩',
+'爛' => '擭',
+'犧' => '枺',
+'瓖' => '',
+'瓔' => '雓',
+'癩' => '餺',
+'矓' => '輮',
+'籐' => '枘',
+'纏' => '莊',
+'續' => '哿',
+'羼' => '殥',
+'蘗' => '瓾',
+'蘭' => '擘',
+'蘚' => '瑎',
+'蠣' => '艤',
+'蠢' => '替',
+'蠡' => '騠',
+'蠟' => '嶸',
+'襪' => '侲',
+'襬' => '缹',
+'覽' => '擬',
+'譴' => 'Ж',
+'護' => '誘',
+'譽' => '酐',
+'贓' => '婒',
+'躊' => '喬',
+'躍' => '埲',
+'躋' => '欀',
+'轟' => '箔',
+'辯' => '梁',
+'醺' => '鼰',
+'鐮' => '蟑',
+'鐳' => '濱',
+'鐵' => '沺',
+'鐺' => '隰',
+'鐸' => '鍎',
+'鐲' => '瀍',
+'鐫' => '擸',
+'闢' => '斬',
+'霸' => '啪',
+'霹' => '羈',
+'露' => '繞',
+'響' => '砒',
+'顧' => '嘈',
+'顥' => '簬',
+'饗' => '龢',
+'驅' => '',
+'驃' => '羭',
+'驀' => '楋',
+'騾' => '邇',
+'髏\' => '鷖',
+'魔' => '藹',
+'魑' => '龕',
+'鰭' => '驒',
+'鰥' => '髐',
+'鶯' => '搡',
+'鶴' => '禍',
+'鷂' => '蠁',
+'鶸' => '',
+'麝' => '癰',
+'黯' => '蘾',
+'鼙' => '亃',
+'齜' => '鷊',
+'齦' => '鷏',
+'齧' => '蘚',
+'儼' => '椏',
+'儻' => '棈',
+'囈' => '蔇',
+'囊' => '黨',
+'囉' => '蹕',
+'孿' => '蟠',
+'巔' => '摛',
+'巒' => '蟬',
+'彎' => '俔',
+'懿' => '亄',
+'攤' => '怉',
+'權' => '',
+'歡' => '辣',
+'灑' => '',
+'灘' => '戽',
+'玀' => '滮',
+'瓤' => '',
+'疊' => '詁',
+'癮' => '颸',
+'癬' => '悢',
+'禳' => '檇',
+'籠' => '餵',
+'籟' => '竷',
+'聾' => '顆',
+'聽' => '泭',
+'臟' => '婄',
+'襲' => '炷',
+'襯' => '傍',
+'觼' => '',
+'讀' => '黍',
+'贖' => '抏',
+'贗' => '媏',
+'躑' => '爙',
+'躓' => '灆',
+'轡' => '閜',
+'酈' => '菄',
+'鑄' => '翉',
+'鑑' => '牖',
+'鑒' => '牖',
+'霽' => '鰜',
+'霾' => '鶷',
+'韃' => '鰷',
+'韁' => '誸',
+'顫' => '荷',
+'饕' => '壨',
+'驕' => '蝨',
+'驍' => '緗',
+'髒' => '婄',
+'鬚' => '剕',
+'鱉' => '梱',
+'鰱' => '攢',
+'鰾' => '鬻',
+'鰻' => '魕',
+'鷓' => '蟝',
+'鷗' => '顫',
+'鼴' => '蠳',
+'齬' => '鶾',
+'齪' => '鷅',
+'龔' => '麂',
+'囌' => '劼',
+'巖' => '旂',
+'戀' => '蟋',
+'攣' => '蟲',
+'攫' => '樹',
+'攪' => '蝌',
+'曬' => '伄',
+'欐' => '',
+'瓚' => '頞',
+'竊' => 'л',
+'籤' => 'ワ',
+'籣' => '蓓',
+'籥' => '殗',
+'纓' => '荍',
+'纖' => '玹',
+'纔' => '符',
+'臢' => '醺',
+'蘸' => '梣',
+'蘿' => '蹤',
+'蠱' => '嘍',
+'變' => '曹',
+'邐' => '槸',
+'邏' => '軀',
+'鑣' => '瀔',
+'鑠' => '鍷',
+'鑤' => '蘸',
+'靨' => '媜',
+'顯' => '珆',
+'饜' => '儽',
+'驚' => '儐',
+'驛' => '緛',
+'驗' => '桄',
+'髓' => '咍',
+'體' => '极',
+'髑' => '麶',
+'鱔' => '鱄',
+'鱗' => '邂',
+'鱖' => '鰿',
+'鷥' => '薷',
+'麟' => '矔',
+'黴' => '羅',
+'囑' => '翊',
+'壩' => '商',
+'攬' => '擦',
+'灞' => '撅',
+'癱' => '戔',
+'癲' => '騍',
+'矗' => '提',
+'罐' => '嫡',
+'羈' => '蹇',
+'蠶' => '紮',
+'蠹' => '騧',
+'衢' => '摋',
+'讓' => '',
+'讒' => '莒',
+'讖' => '笻',
+'艷' => '栻',
+'贛' => '該',
+'釀' => '籐',
+'鑪' => '簪',
+'靂' => '魒',
+'靈' => '鍾',
+'靄' => '鰤',
+'韆' => 'ロ',
+'顰' => '糬',
+'驟' => '紬',
+'鬢' => '斖',
+'魘' => '鼳',
+'鱟' => '囆',
+'鷹' => '茈',
+'鷺' => '襑',
+'鹼' => '潘',
+'鹽' => '敆',
+'鼇' => '驉',
+'齷' => '鷃',
+'齲' => '',
+'廳' => '泆',
+'欖' => '擳',
+'灣' => '俜',
+'籬' => '燦',
+'籮' => '轍',
+'蠻' => '雙',
+'觀' => '夤',
+'躡\' => '糲',
+'釁' => '陊',
+'鑲' => '眄',
+'鑰' => '埥',
+'顱' => '簫',
+'饞' => '莫',
+'髖' => '鷕',
+'鬣' => '欑',
+'黌' => '毲',
+'灤' => '覆',
+'矚' => '羛',
+'讚' => '婝',
+'鑷' => '蠣',
+'韉' => '鰽',
+'驢' => '聶',
+'驥' => '翪',
+'纜' => '擢',
+'讜' => '祲',
+'躪' => '耰',
+'釅' => '鶡',
+'鑽' => '郰',
+'鑾' => '鷍',
+'鑼' => '轉',
+'鱷' => '穱',
+'鱸' => '齤',
+'黷' => '蘹',
+'豔' => '栻',
+'鑿' => '娾',
+'鸚' => '蟨',
+'爨' => '憵',
+'驪' => '緺',
+'鬱' => '郙',
+'鸛' => '襉',
+'鸞' => '蟢',
+'籲' => '郚',
+'ヾ' => 'K',
+'ゝ' => 'L',
+'ゞ' => 'M',
+'々' => 'N',
+'ぁ' => 'O',
+'あ' => 'P',
+'ぃ' => 'Q',
+'い' => 'R',
+'ぅ' => 'S',
+'う' => 'T',
+'ぇ' => '〣',
+'え' => '〤',
+'ぉ' => '〥',
+'お' => '〦',
+'か' => '〧',
+'が' => '〨',
+'き' => '〩',
+'ぎ' => '十',
+'く' => '卄',
+'ぐ' => '卅',
+'け' => '仃',
+'げ' => '仆',
+'こ' => '仇',
+'ご' => '仍',
+'さ' => '今',
+'ざ' => '介',
+'し' => '仄',
+'じ' => '元',
+'す' => '允',
+'ず' => '內',
+'せ' => '媦',
+'ぜ' => '堹',
+'そ' => '公',
+'ぞ' => '湅',
+'た' => '崱',
+'だ' => '琡',
+'ち' => '渻',
+'ぢ' => '湆',
+'っ' => '勻',
+'つ' => '筄',
+'づ' => '袽',
+'て' => '熇',
+'で' => '撗',
+'と' => '誾',
+'ど' => '誻',
+'な' => '嫘',
+'に' => '袾',
+'ぬ' => '樉',
+'ね' => '摓',
+'の' => '篞',
+'は' => '拸',
+'ば' => '謪',
+'ぱ' => '天',
+'ひ' => '夫',
+'び' => '薔',
+'ぴ' => '熇',
+'ふ' => '',
+'ぶ' => '少',
+'ぷ' => '尤',
+'へ' => '尺',
+'べ' => '屯',
+'ぺ' => 'ㄑ',
+'ほ' => '幻',
+'ぼ' => '〝',
+'ぽ' => '﹞',
+'ま' => '引',
+'み' => '心',
+'む' => '',
+'め' => '',
+'も' => '手',
+'ゃ' => '丑',
+'や' => '丐',
+'ゅ' => '不',
+'ゆ' => '中',
+'ょ' => '丰',
+'よ' => '丹',
+'ら' => '之',
+'り' => '尹',
+'る' => '予',
+'れ' => '云',
+'ろ' => '井',
+'ゎ' => '互',
+'わ' => '五',
+'ゐ' => '亢',
+'ゑ' => '仁',
+'を' => '什',
+'ん' => '仃',
+'ァ' => '仆',
+'ア' => '仇',
+'ィ' => '仍',
+'イ' => '今',
+'ゥ' => '介',
+'ウ' => '仄',
+'ェ' => '元',
+'エ' => '允',
+'ォ' => '內',
+'オ' => '六',
+'カ' => '兮',
+'ガ' => '公',
+'キ' => '冗',
+'ギ' => '凶',
+'ク' => '分',
+'グ' => '切',
+'ケ' => '刈',
+'ゲ' => '勻',
+'コ' => '勾',
+'ゴ' => '勿',
+'サ' => '化',
+'ザ' => '匹',
+'シ' => '午',
+'ジ' => '升',
+'ス' => '卅',
+'ズ' => '卞',
+'セ' => '厄',
+'ゼ' => '友',
+'ソ' => '及',
+'ゾ' => '反',
+'タ' => '壬',
+'ダ' => '天',
+'チ' => '夫',
+'ヂ' => '太',
+'ッ' => '夭',
+'ツ\' => '孔',
+'ヅ' => '少',
+'テ' => '尤',
+'デ' => '尺',
+'ト' => '屯',
+'ド' => '巴',
+'ナ' => '幻',
+'ニ' => '廿',
+'ヌ' => '弔',
+'ネ' => '引',
+'ノ' => '心',
+'ハ' => '戈',
+'バ' => '戶',
+'パ' => '手',
+'ヒ' => '扎',
+'ビ' => '支',
+'ピ' => '文',
+'フ' => '斗',
+'ブ' => '斤',
+'プ' => '方',
+'ヘ' => '日',
+'ベ' => '曰',
+'ペ' => '月',
+'ホ' => '木',
+'ボ' => '欠',
+'ポ' => '止',
+'マ' => '歹',
+'ミ' => '毋',
+'ム' => '比',
+'メ' => '毛',
+'モ' => '氏',
+'ャ' => '央',
+'ヤ' => '失',
+'ュ' => '奴',
+'ユ' => '奶',
+'ョ' => '孕',
+'ヨ' => '它',
+'ラ' => '尼',
+'リ' => '巨',
+'ル' => '巧',
+'レ' => '左',
+'ロ' => '市',
+'ヮ' => '布',
+'ワ' => '平',
+'ヰ' => '幼',
+'ヱ' => '弁',
+'ヲ' => '弘',
+'ン' => '弗',
+'ヴ' => '必',
+'ヵ' => '戊',
+'ヶ' => '打',
+'Д' => '扔',
+'Е' => '扒',
+'Ё' => '扑',
+'Ж' => '斥',
+'З' => '旦',
+'И' => '朮',
+'Й' => '本',
+'К' => '未',
+'Л' => '末',
+'М' => '札',
+'У' => '正',
+'Ф' => '母',
+'Х' => '民',
+'Ц' => '氐',
+'Ч' => '永',
+'Ш' => '汁',
+'Щ' => '汀',
+'Ъ' => '氾',
+'Ы' => '犯',
+'Ь' => '玄',
+'Э' => '玉',
+'Ю' => '瓜',
+'Я' => '瓦',
+'а' => '甘',
+'б' => '生',
+'в' => '用',
+'г' => '甩',
+'д' => '田',
+'е' => '由',
+'ё' => '甲',
+'ж' => '申',
+'з' => '疋',
+'и' => '白',
+'й' => '皮',
+'к' => '皿',
+'л' => '目',
+'м' => '矛',
+'н' => '矢',
+'о' => '石',
+'п' => '示',
+'р' => '禾',
+'с' => '穴',
+'т' => '立',
+'у' => '丞',
+'ф' => '丟',
+'х' => '乒',
+'ц' => '乓',
+'ч' => '乩',
+'ш' => '亙',
+'щ' => '交',
+'ъ' => '亦',
+'ы' => '亥',
+'ь' => '仿',
+'э' => '伉',
+'ю' => '伙',
+'я' => '伊',
+'①' => '伕',
+'②' => '伍',
+'③' => '伐',
+'④' => '休',
+'⑤' => '伏',
+'⑥' => '仲',
+'⑦' => '件',
+'⑧' => '任',
+'⑨' => '仰',
+'⑩' => '仳',
+'⑴' => '均',
+'⑵' => '坎',
+'⑶' => '圾',
+'⑷' => '坐',
+'⑸' => '坏',
+'⑹' => '圻',
+'⑺' => '漼',
+'⑻' => '夾',
+'⑼' => '妝',
+'⑽' => '淊',
+'' => '妨',
+'' => '妞',
+'@' => '妣',
+'A' => '妙',
+'B' => '譪',
+'C' => '妍',
+'D' => '妤',
+'E' => '妓',
+'F' => '妊',
+'G' => '妥',
+'H' => '孝',
+'I' => '孜',
+'J' => '孚',
+'K' => '嘍',
+'L' => '完',
+'M' => '宋',
+'N' => '宏',
+'O' => '尬',
+'P' => '局',
+'Q' => '屁',
+'R' => '尿',
+'S' => '尾',
+'T' => '╰',
+'U' => '╰',
+'V' => '忌',
+'W' => '志',
+'X' => '忍',
+'Y' => '忱',
+'Z' => '快',
+'[' => '忸',
+'\\' => '忪',
+']' => '戒',
+'^' => '我',
+'_' => '抄',
+'`' => '抗',
+'a' => '抖',
+'b' => '技',
+'c' => '扶',
+'d' => '抉',
+'e' => '雰',
+'f' => '把',
+'g' => '扼',
+'h' => '兜',
+'i' => '批',
+'j' => '扳',
+'k' => '抒',
+'l' => '扯',
+'m' => '折',
+'n' => '扮',
+'o' => '投',
+'p' => '抓',
+'q' => '抑',
+'r' => '抆',
+'s' => '改',
+'t' => '攻',
+'u' => '攸',
+'v' => '跺',
+'w' => '駃',
+'x' => 'X',
+'y' => '豱',
+'z' => '禿',
+'{' => '系',
+'|' => '絰',
+'}' => '寎',
+'~' => '蜡',
+'' => '斲',
+'' => '厙',
+'' => '儴',
+'' => '畟',
+'' => '↓',
+'' => '↓',
+'' => '↓',
+'' => '↓',
+'' => '↓',
+'' => '↓',
+'' => '↓',
+'' => '↓',
+'' => '↓',
+'' => '↓',
+'' => '↓',
+'' => '↓',
+'' => '↓',
+'' => '↓',
+'' => '↓',
+'' => '↓',
+'' => '↓',
+'' => '↓',
+'' => '↓',
+'' => '↓',
+'' => '↓',
+'' => '↓',
+'' => '↓',
+'' => '↓',
+'' => 'х',
+'' => '↓',
+'' => '↓',
+'' => '慖',
+'' => '↓',
+'' => '↓',
+'' => '↓',
+'' => '↓',
+'' => '↓',
+'' => '↓',
+'' => '↓',
+'' => '↓',
+'' => '↓',
+'' => '↓',
+'' => '↓',
+'' => '↓',
+'' => '☆',
+'' => '帚',
+'' => '*',
+'' => '§',
+'' => '↓',
+'' => '∮',
+'' => '↓',
+'' => '蕫',
+'' => '↓',
+'' => '↓',
+'' => '↓',
+'' => '↓',
+'' => '↓',
+'' => '↓',
+'' => '↓',
+'' => '↓',
+'' => '↓',
+'' => '↓',
+'' => '↓',
+'' => '嵂',
+'' => '湆',
+'' => '筌',
+'' => '亶',
+'' => '痻',
+'' => '摠',
+'' => '鶜',
+'' => '瘔',
+'' => '蜡',
+'' => '蝃',
+'' => '斲',
+'' => '篞',
+'' => '憼',
+'' => '擣',
+'' => '穜',
+'' => '鷟',
+'' => '鼱',
+'' => '懰',
+'' => '↓',
+'' => '↓',
+'' => '↓',
+'' => '↓',
+'' => '↓',
+'' => '↓',
+'' => '↓',
+'' => '↓',
+'' => '檶',
+'' => '獑',
+'' => '↓',
+'' => '↓',
+'' => '↓',
+'乂' => 'V',
+'乜' => '媬',
+'凵' => '袶',
+'匚' => '媓',
+'厂' => '釦',
+'万' => '勀',
+'丌' => '堞',
+'乇' => '堭',
+'亍' => '堙',
+'囗' => '鳧',
+'兀' => '堧',
+'屮' => '氂',
+'彳' => '摝',
+'丏' => 'D',
+'冇' => '',
+'与' => '迵',
+'丮' => 'M',
+'亓' => '媮',
+'仂' => '崸',
+'仉' => '嵉',
+'仈' => '',
+'冘' => '',
+'勼' => '',
+'卬' => 'n',
+'厹' => '',
+'圠' => 'L',
+'夃' => '',
+'夬' => '',
+'尐\' => '',
+'巿' => '',
+'旡' => '拸',
+'殳' => '麈',
+'毌' => '',
+'气' => 'ァ',
+'爿' => '蜙',
+'丱' => 'O',
+'丼' => 'S',
+'仨' => '崼',
+'仜' => '',
+'仩' => '',
+'仡' => '崲',
+'仝' => '欹',
+'仚' => '',
+'刌' => 'Y',
+'匜' => 'F',
+'卌' => 'c',
+'圢' => 'N',
+'圣' => '吤',
+'夗' => '',
+'夯' => '獄',
+'宁' => '譴',
+'宄' => '撜',
+'尒' => '嫌',
+'尻' => '樏',
+'屴' => '',
+'屳' => '',
+'帄' => '',
+'庀' => '瑳',
+'庂' => '',
+'忉' => '皸',
+'戉' => '鍕',
+'扐' => 'A',
+'氕' => '諨',
+'氶' => '',
+'汃' => '',
+'氿' => '',
+'氻' => '',
+'犮' => '',
+'犰' => '摐',
+'玊' => '俊',
+'禸' => '軸',
+'肊' => '砵',
+'阞' => '瑿',
+'伎' => '撚',
+'优' => '蚥',
+'伬' => '',
+'仵' => '徦',
+'伔' => '',
+'仱' => '',
+'伀' => '碪',
+'价' => '歎',
+'伈' => '',
+'伝' => '換',
+'伂' => '',
+'伅' => '',
+'伢' => '幁',
+'伓' => '',
+'伄' => '',
+'仴' => '',
+'伒' => '',
+'冱' => '渃',
+'刓' => '\\',
+'刉' => 'W',
+'刐' => '[',
+'劦' => '',
+'匢' => 'I',
+'匟' => '蕃',
+'卍' => 'd',
+'厊' => '|',
+'吇' => '',
+'囡' => '黽',
+'囟' => '媔',
+'圮' => '詘',
+'圪' => '詙',
+'圴' => 'V',
+'夼' => '畷',
+'妀' => 'j',
+'奼' => '瘙',
+'妅' => 'k',
+'奻' => 'f',
+'奾' => 'h',
+'奷' => 'd',
+'奿' => 'i',
+'孖' => 'I',
+'尕' => '箾',
+'尥' => '痹',
+'屼' => '',
+'屺' => '嶁',
+'屻' => '',
+'屾' => '',
+'巟' => 'x',
+'幵' => '',
+'庄' => '蚽',
+'异' => '祑',
+'弚' => 'w',
+'彴' => '',
+'忕' => '',
+'忔' => '',
+'忏' => '睼',
+'扜' => 'G',
+'扞' => '煽',
+'扤' => 'N',
+'扡' => '迍',
+'扦' => 'リ',
+'扢' => 'M',
+'扙' => 'E',
+'扠' => '脫',
+'扚' => 'F',
+'扥' => 'O',
+'旯' => '篧',
+'旮' => '篣',
+'朾' => 'b',
+'朹' => '_',
+'朸' => '^',
+'朻' => '`',
+'机' => '儂',
+'朿' => 'c',
+'朼' => 'a',
+'朳' => '[',
+'氘' => '諿',
+'汆' => '殙',
+'汒' => '',
+'汜' => '蝁',
+'汏' => '',
+'汊' => '蜾',
+'汔' => '蜬',
+'汋' => '',
+'汌' => '',
+'灱' => '',
+'牞' => '',
+'犴' => '摿',
+'犵' => '',
+'玎' => '諘',
+'甪' => '宸',
+'癿' => '逅',
+'穵' => '阼',
+'网' => '厙',
+'艸' => '翌',
+'艼' => '驟',
+'芀' => '鬢',
+'艽' => '傽',
+'艿' => '傿',
+'虍' => '糪',
+'襾' => '',
+'邙' => '絩',
+'邗' => '絫',
+'邘' => '',
+'邛' => '絒',
+'邔' => '',
+'阢' => '筎',
+'阤' => '邲',
+'阠' => '璚',
+'阣' => '砣',
+'佖' => '',
+'伻' => '',
+'佢\' => '',
+'佉' => '',
+'体' => '极',
+'佤' => '彘',
+'伾' => '',
+'佧' => '惢',
+'佒' => '',
+'佟' => '晼',
+'佁' => '',
+'佘' => '欿',
+'伭' => '',
+'伳' => '',
+'伿' => '',
+'佡' => '',
+'冏' => '',
+'冹' => '',
+'刜' => '_',
+'刞' => '`',
+'刡' => 'b',
+'劭' => '蛑',
+'劮' => '',
+'匉' => '體',
+'卣' => '寊',
+'卲' => 'p',
+'厎' => '簃',
+'厏' => '~',
+'吰' => '',
+'吷' => '',
+'吪' => '塚',
+'呔' => '葞',
+'呅' => '',
+'吙' => '',
+'吜' => '',
+'吥' => '',
+'吘' => '',
+'吽' => '',
+'呏' => '',
+'呁' => '',
+'吨' => '勣',
+'吤' => '',
+'呇' => '',
+'囮' => '',
+'囧' => '',
+'囥' => '',
+'坁' => '^',
+'坅' => 'a',
+'坌' => '覕',
+'坉' => 'd',
+'坋' => 'e',
+'坒' => 'f',
+'夆' => '',
+'奀' => 'C',
+'妦' => '~',
+'妘' => 'u',
+'妠' => '{',
+'妗' => '獢',
+'妎' => 'o',
+'妢' => '}',
+'妐' => 'q',
+'妏' => 'p',
+'妧' => '',
+'妡' => '|',
+'宎' => 'a',
+'宒' => 'd',
+'尨' => '',
+'尪' => '',
+'岍' => '嵷',
+'岏' => '',
+'岈' => '嶈',
+'岋' => '',
+'岉' => '',
+'岒' => '',
+'岊' => '嵿',
+'岆' => '',
+'岓' => '',
+'岕' => '',
+'巠' => 'y',
+'帊' => '',
+'帎' => '',
+'庋' => '瑵',
+'庉' => '',
+'庌' => '',
+'庈' => '',
+'庍' => '',
+'弅' => 'k',
+'弝' => 'y',
+'彸' => '',
+'彶' => '',
+'忒' => '蒍',
+'忑' => '檓',
+'忐' => '檎',
+'忭' => '碴',
+'忨' => '',
+'忮' => '瞂',
+'忳' => '',
+'忡' => '瞀',
+'忤' => '睯',
+'忣' => '摹',
+'忺' => '',
+'忯' => '',
+'忷' => '',
+'忻' => '陏',
+'怀' => '輒',
+'忴' => '',
+'戺' => '',
+'抃' => '皙',
+'抌' => 'b',
+'抎' => 'd',
+'抏' => 'e',
+'抔' => 'g',
+'抇' => '_',
+'扱' => 'Q',
+'扻' => 'X',
+'扺' => 'W',
+'扰' => '',
+'抁' => 'Z',
+'抈' => '`',
+'扷' => 'U',
+'扽' => 'Y',
+'扲' => 'R',
+'扴' => 'S',
+'攷' => '蕉',
+'旰' => '篝',
+'旴' => 'B',
+'旳' => 'A',
+'旲' => '@',
+'旵' => 'C',
+'杅' => 'f',
+'杇' => '訹',
+'杙' => 'p',
+'杕' => 'm',
+'杌' => '頠',
+'杈' => '颲',
+'杝' => 's',
+'杍' => 'j',
+'杚' => 'q',
+'杋' => 'i',
+'毐' => '',
+'氙' => '諯',
+'氚' => '諻',
+'汸' => 'P',
+'汧' => 'F',
+'汫' => 'G',
+'沄' => 'V',
+'沋' => 'Y',
+'沏' => 'み',
+'汱' => 'L',
+'汯' => 'K',
+'汩' => '蜒',
+'沚' => 'b',
+'汭' => 'I',
+'沇' => 'W',
+'沕' => '^',
+'沜' => 'c',
+'汦' => 'E',
+'汳' => 'M',
+'汥' => 'D',
+'汻\' => '銊',
+'沎' => '[',
+'灴' => '',
+'灺' => '',
+'牣' => '',
+'犿' => '',
+'犽' => '',
+'狃' => '摫',
+'狆' => '',
+'狁' => '摙',
+'犺' => '',
+'狅' => '',
+'玕' => '俞\',
+'玗' => '侷',
+'玓' => '俚',
+'玔' => '醝',
+'玒' => '係',
+'町' => '謜',
+'甹' => '屐',
+'疔' => '謧',
+'疕' => '浹',
+'皁' => '婂',
+'礽' => '痣',
+'耴' => '歸',
+'肕' => '騎',
+'肙' => '鬃',
+'肐' => '賄',
+'肒' => '餮',
+'肜' => '蹀',
+'芐' => '嗝',
+'芏' => '僆',
+'芅' => '鷹',
+'芎' => '傴',
+'芑' => '僈',
+'芓' => '齲',
+'芊' => '傮',
+'芃' => '鱟',
+'芄' => '僊',
+'豸' => '蘟',
+'迉' => '',
+'辿' => '煰',
+'邟' => '',
+'邡' => '絟',
+'邥' => '',
+'邞' => '',
+'邧' => '',
+'邠' => '',
+'阰' => '瘳',
+'阨' => '塌',
+'阯' => '硊',
+'阭' => '瘱',
+'丳' => 'P',
+'侘' => '',
+'佼' => '椪',
+'侅' => '',
+'佽' => '',
+'侀' => '',
+'侇' => '',
+'佶' => '晱',
+'佴' => '晹',
+'侉' => '晲',
+'侄' => '硍',
+'佷' => '',
+'佌' => '',
+'侗' => '雇',
+'佪' => '輔',
+'侚' => '',
+'佹' => '',
+'侁' => '',
+'佸' => '',
+'侐' => '',
+'侜' => '',
+'侔' => '棪',
+'侞' => '',
+'侒' => '',
+'侂' => '',
+'侕' => '',
+'佫' => '',
+'佮' => '',
+'冞' => '',
+'冼' => '湞',
+'冾' => '',
+'刵' => 'n',
+'刲' => 'l',
+'刳' => '嵃',
+'剆' => 's',
+'刱' => '斐',
+'劼' => '',
+'匊' => '碇',
+'匋' => '',
+'匼' => '\\',
+'厒' => '',
+'厔' => '',
+'咇' => '',
+'呿' => '',
+'咁' => '',
+'咑' => '',
+'咂' => '葅',
+'咈' => '',
+'呫' => '',
+'呺' => '',
+'呾' => '',
+'呥' => '',
+'呬' => '',
+'呴' => '',
+'呦' => '萹',
+'咍' => '',
+'呯' => '',
+'呡' => '',
+'呠' => '',
+'咘' => '',
+'呣' => '',
+'呧' => '畬',
+'呤' => '萯',
+'囷' => '',
+'囹' => '僗',
+'坯' => '矗',
+'坲' => 'u',
+'坭' => '貺',
+'坫' => '詌',
+'坱' => 't',
+'坰' => 's',
+'坶' => '貾',
+'垀' => '~',
+'坵' => '⑧',
+'坻' => '貁',
+'坳' => '貰',
+'坴' => 'v',
+'坢' => 'm',
+'坨' => '貀',
+'坽' => '{',
+'夌' => '',
+'奅' => 'E',
+'妵' => '',
+'妺' => '',
+'姏' => '',
+'姎' => '',
+'妲' => '瑽',
+'姌' => '',
+'姁' => '',
+'妶' => '',
+'妼' => '',
+'姃' => '',
+'姖' => '',
+'妱' => '',
+'妽' => '',
+'姀' => '',
+'姈' => '',
+'妴' => '',
+'姇' => '',
+'孢' => '糅',
+'孥' => '箯',
+'宓' => '撋',
+'宕' => '撏',
+'屄' => '',
+'屇' => '',
+'岮' => 'A',
+'岤\' => '',
+'岠' => '',
+'岵' => '幘',
+'岯' => 'B',
+'岨' => '',
+'岬' => '廘',
+'岟' => '',
+'岣' => '廎',
+'岭' => '鍛',
+'岢' => '幙',
+'岪' => '@',
+'岧' => '',
+'岝' => '',
+'岥' => 'ぞ',
+'岶' => 'F',
+'岰' => 'C',
+'岦' => '',
+'帗' => '',
+'帔' => '僬',
+'帙' => '僓',
+'弨' => '',
+'弢' => '|',
+'弣' => '}',
+'弤' => '~',
+'彔' => '翹',
+'徂' => '摶',
+'彾' => '鍥',
+'彽' => '',
+'忞' => '',
+'忥' => '',
+'怭' => 'P',
+'怦' => '碫',
+'怙' => '碨',
+'怲' => 'T',
+'怋' => 'B',
+'怴' => 'V',
+'怊' => '碤',
+'怗' => 'G',
+'怳' => '鉼',
+'怚' => 'I',
+'怞' => 'J',
+'怬' => 'O',
+'怢' => 'L',
+'怍' => '碠',
+'怐' => 'D',
+'怮' => 'Q',
+'怓' => 'F',
+'怑' => '﹜',
+'怌' => '輒',
+'怉' => 'A',
+'怜' => '蟒',
+'戔' => '磣',
+'戽' => '懨',
+'抭' => '狳',
+'抴' => '蚹',
+'拑' => 'ヵ',
+'抾' => '|',
+'抪' => 'p',
+'抶' => 'x',
+'拊' => '痽',
+'抮' => 'r',
+'抳' => 'v',
+'抯' => 's',
+'抻' => '痵',
+'抩' => 'o',
+'抰' => 't',
+'抸' => 'z',
+'攽' => '',
+'斨' => '',
+'斻' => '',
+'昉' => 'P',
+'旼' => 'G',
+'昄' => 'L',
+'昒' => 'U',
+'昈' => 'O',
+'旻' => 'F',
+'昃' => '篨',
+'昋' => 'Q',
+'昍' => 'R',
+'昅' => 'M',
+'旽' => 'H',
+'昑' => 'T',
+'昐' => 'S',
+'曶' => '',
+'朊' => '踼',
+'枅' => '',
+'杬' => 'z',
+'枎' => '',
+'枒' => '挩',
+'杶' => '~',
+'杻' => '',
+'枘' => '餗',
+'枆' => '',
+'构' => '凳',
+'杴' => '珌',
+'枍' => '',
+'枌' => '',
+'杺' => '',
+'枟' => '抴',
+'枑' => '',
+'枙' => '',
+'枃' => '',
+'杽' => '',
+'极' => '憤',
+'杸' => '',
+'杹' => '',
+'枔' => '',
+'欥' => '',
+'殀' => '堬',
+'歾' => '殪',
+'毞' => '蝣',
+'氝' => '',
+'沓' => '穖',
+'泬' => '',
+'泫' => '裺',
+'泮' => '裾',
+'泙' => '',
+'沶' => 'n',
+'泔' => '蜧',
+'沭' => '蜸',
+'泧' => '',
+'沷' => 'o',
+'泐' => '蜦',
+'泂' => 's',
+'沺' => 'p',
+'泃' => 't',
+'泆' => 'u',
+'泭' => '',
+'泲' => '',
+'泒' => '}',
+'泝' => '',
+'沴' => '咁',
+'沊' => 'X',
+'沝' => 'd',
+'沀' => 'U',
+'泞' => '籠',
+'泀' => 'q',
+'洰' => '',
+'泍' => 'y',
+'泇' => 'v',
+'沰' => 'k',
+'泹' => '',
+'泏' => '{',
+'泩' => '',
+'泑' => '|',
+'炔' => '',
+'炘' => '',
+'炅' => '篪',
+'炓' => '',
+'炆' => '',
+'炄' => '',
+'炑' => '',
+'炖' => '嚓',
+'炂' => '',
+'炚' => '',
+'炃' => '',
+'牪' => '',
+'狖\' => '',
+'狋' => '',
+'狘' => '',
+'狉' => '',
+'狜' => '昇',
+'狒' => '敳',
+'狔' => '',
+'狚' => '',
+'狌' => '倅',
+'狑' => '',
+'玤' => '剋',
+'玡' => '趜',
+'玭' => '南',
+'玦' => '勇',
+'玢' => '誽',
+'玠' => '削',
+'玬' => '匍',
+'玝' => '剎',
+'瓝' => '',
+'瓨' => '',
+'甿' => '疇',
+'畀' => '謓',
+'甾' => '諀',
+'疌' => '浚',
+'疘' => '誇',
+'皯' => '',
+'盳' => '崔',
+'盱' => '臅',
+'盰' => '崩',
+'盵' => '崙',
+'矸' => '窾',
+'矼' => '蛉',
+'矹' => '蛋',
+'矻' => '蚯',
+'矺' => '蚱',
+'矷' => '蛆',
+'祂' => '痘',
+'礿' => '痙',
+'秅' => '週',
+'穸' => '騅',
+'穻' => '',
+'竻' => '',
+'籵' => '褂',
+'糽' => '幢',
+'耵' => '嚪',
+'肏' => '餾',
+'肮' => '偎',
+'肣' => '魏',
+'肸' => '鵝',
+'肵' => '鯀',
+'肭' => '踿',
+'舠' => '彎',
+'芠' => '觀',
+'苀' => '矚',
+'芫' => '僁',
+'芚' => '籬',
+'芘' => '凗',
+'芛' => '籮',
+'芵' => '顱',
+'芧' => '鑲',
+'芮' => '剸',
+'芼' => '黌',
+'芞' => '蠻',
+'芺' => '髖',
+'芴' => '嗌',
+'芨' => '僄',
+'芡' => '嗐',
+'芩' => '嗛',
+'苂' => '讚',
+'芤' => '嗔',
+'苃' => '嗏',
+'芶' => '饞',
+'芢' => '躡\',
+'虰' => '沴',
+'虯' => '繵',
+'虭' => '泒',
+'虮' => '繸',
+'豖' => '傌',
+'迒' => '',
+'迋' => '',
+'迓' => '斳',
+'迍' => '',
+'迖' => '',
+'迕' => '暵',
+'迗' => '',
+'邲' => '',
+'邴' => '絎',
+'邯' => '漯',
+'邳' => '缾',
+'邰' => '菺',
+'阹' => '瘲',
+'阽' => '粢',
+'阼' => '粞',
+'阺' => '瘰',
+'陃' => '瞚',
+'俍' => 'Z',
+'俅' => '棷',
+'俓' => '\\',
+'侲' => 'E',
+'俉' => 'W',
+'俋' => 'X',
+'俁' => '棤',
+'俔' => ']',
+'俜' => '棶',
+'俙' => '`',
+'侻' => 'M',
+'侳' => 'F',
+'俛' => '萱',
+'俇' => 'U',
+'俖' => '_',
+'侺' => 'L',
+'俀' => 'Q',
+'侹' => 'K',
+'俬' => 'h',
+'剄' => '崷',
+'剉' => '黿',
+'勀' => '',
+'勂' => '',
+'匽' => ']',
+'卼' => 't',
+'厗' => '',
+'厖' => '',
+'厙' => '媋',
+'厘' => '濰',
+'咺' => 'I',
+'咡' => '',
+'咭' => '葒',
+'咥' => 'A',
+'哏' => '蛖',
+'哃' => 'L',
+'茍' => '',
+'咷' => '覛',
+'咮' => 'B',
+'哖' => 'P',
+'咶' => 'F',
+'哅' => 'M',
+'哆' => '嗑',
+'咠' => '',
+'呰' => '隊',
+'咼' => '葃',
+'咢' => '@',
+'咾' => 'K',
+'呲' => '葨',
+'哞' => '蛵',
+'咰' => 'C',
+'垵' => '跅',
+'垞' => '',
+'垟' => '',
+'垤' => '貵',
+'垌' => '趄',
+'垗' => '',
+'垝' => '',
+'垛' => '嗯',
+'垔' => '雱',
+'垘' => '',
+'垏' => '',
+'垙' => '',
+'垥\' => '',
+'垚' => '',
+'垕' => '',
+'壴' => '',
+'复' => '葩',
+'奓' => 'L',
+'姡' => '',
+'姞' => '',
+'姮' => '禢',
+'娀' => '',
+'姱' => '',
+'姝' => '甇',
+'姺' => '',
+'姽' => '',
+'姼' => '',
+'姶' => '',
+'姤' => '',
+'姲' => '',
+'姷' => '晪',
+'姛' => '',
+'姩' => '',
+'姳' => '',
+'姵' => '',
+'姠' => '',
+'姾' => '',
+'姴' => '',
+'姭' => '',
+'宨' => 'i',
+'屌' => '',
+'峐' => 'Y',
+'峘' => '`',
+'峌' => 'U',
+'峗' => '_',
+'峋' => '彄',
+'峛' => 'b',
+'峞' => 'e',
+'峚' => 'a',
+'峉' => 'S',
+'峇' => 'Q',
+'峊' => 'T',
+'峖' => '^',
+'峓' => '[',
+'峔' => '\\',
+'峏' => 'X',
+'峈' => 'R',
+'峆' => 'P',
+'峎' => 'W',
+'峟' => 'f',
+'峸' => 'w',
+'巹' => '筈',
+'帡' => '',
+'帢' => '',
+'帣' => '',
+'帠' => '',
+'帤' => '',
+'庰' => '',
+'庤' => '',
+'庢' => '',
+'庛' => '',
+'庣' => '',
+'庥' => '瑧',
+'弇' => 'm',
+'弮' => '',
+'彖' => '樘',
+'徆' => '',
+'怷' => 'X',
+'怹' => 'Z',
+'恔' => 'k',
+'恲' => 'y',
+'恞' => 'q',
+'恅' => '`',
+'恓' => 'j',
+'恇' => 'b',
+'恉' => '祤',
+'恛' => 'o',
+'恌' => '╰',
+'恀' => '^',
+'恂' => '禓',
+'恟' => 'r',
+'怤' => 'N',
+'恄' => '_',
+'恘' => 'n',
+'恦' => 'v',
+'恮' => 'w',
+'扂' => '',
+'扃' => '懞',
+'拏' => '',
+'挍' => '',
+'挋' => '',
+'拵' => '',
+'挎' => '踵',
+'挃' => '',
+'拫' => '',
+'拹' => '',
+'挏' => '',
+'挌' => '',
+'拸' => '',
+'拶' => '睟',
+'挀' => '',
+'挓' => '',
+'挔' => '',
+'拺' => '',
+'挕' => '',
+'拻' => '',
+'拰' => '',
+'敁' => '',
+'敃' => '',
+'斪' => '',
+'斿' => '',
+'昶' => '篟',
+'昡' => ']',
+'昲' => 'h',
+'昵' => '糒',
+'昜' => '[',
+'昦' => 'a',
+'昢' => '^',
+'昳' => 'i',
+'昫' => '懠',
+'昺' => '殺',
+'昝' => '篜',
+'昴' => '篫',
+'昹' => 'l',
+'昮' => 'f',
+'朏' => 'F',
+'朐' => '郺',
+'柁' => '魶',
+'柲' => '',
+'柈' => '',
+'枺' => '',
+'柜' => '嶄',
+'枻' => '',
+'柸' => '',
+'柘' => '駋',
+'柀' => '',
+'枷' => '樞',
+'柅' => '',
+'柫' => '',
+'柤' => '',
+'柟' => '撉',
+'枵' => '髳',
+'柍' => '',
+'枳' => '髱',
+'柷' => '',
+'柶' => '',
+'柮' => '',
+'柣' => '',
+'柂' => '',
+'枹' => '',
+'柎' => '',
+'柧' => '',
+'柰' => '駖',
+'枲' => '',
+'柼' => '',
+'柆' => '',
+'柭' => '',
+'柌' => '',
+'枮' => '',
+'柦\' => '',
+'柛' => '',
+'柺' => '',
+'柉' => '',
+'柊' => '',
+'柃' => '魧',
+'柪' => '',
+'柋' => '',
+'欨' => '',
+'殂' => '殫',
+'殄' => '毇',
+'殶' => '',
+'毖' => '敗',
+'毘' => '讒',
+'毠' => '蘌',
+'氠' => '',
+'氡' => '貑',
+'洨' => '',
+'洴' => '',
+'洭' => '',
+'洟' => '',
+'洼' => '俍',
+'洿' => '',
+'洒' => '',
+'洊' => '',
+'泚' => '',
+'洳' => '銌',
+'洄' => '銣',
+'洙' => '鋮',
+'洺' => '',
+'洚' => '銈',
+'洑' => '',
+'洀' => '',
+'洝' => '',
+'浂' => '',
+'洁' => '賞',
+'洘' => '',
+'洷' => '',
+'洃' => '',
+'洏' => '',
+'浀' => '',
+'洇' => '鉿',
+'洠' => '',
+'洬' => '',
+'洈' => '',
+'洢' => '',
+'洉' => '',
+'洐' => '',
+'炷' => '嚄',
+'炟' => '',
+'炾' => '',
+'炱' => '噾',
+'炰' => '',
+'炡' => '',
+'炴' => '',
+'炵' => '',
+'炩' => '',
+'牁' => '',
+'牉' => '',
+'牊' => '',
+'牬' => '',
+'牰' => '',
+'牳' => '',
+'牮' => '膴',
+'狊' => '',
+'狤' => '枕',
+'狨' => '斠',
+'狫' => '枇',
+'狟' => '朋',
+'狪' => '杷',
+'狦' => '果',
+'狣' => '枋',
+'玅' => '鏝',
+'珌' => '',
+'珂' => '豍',
+'珈' => '賚',
+'珅' => '咽',
+'玹' => '咨',
+'玶' => '咬',
+'玵' => '叛',
+'玴' => '厚',
+'珫' => '',
+'玿' => '咦',
+'珇' => '品',
+'玾' => '咸',
+'珃' => '哇',
+'珆' => '咪',
+'玸' => '哀',
+'珋' => '',
+'瓬' => '',
+'瓮' => '怤',
+'甮' => '射',
+'畇' => '峴',
+'畈' => '豰',
+'疧' => '烙',
+'疪' => '爹',
+'癹' => '迴',
+'盄' => '娼',
+'眈' => '艚',
+'眃' => '康',
+'眄' => '臇',
+'眅' => '庸',
+'眊' => '庵',
+'盷' => '崧',
+'盻' => '巢',
+'盺' => '崗',
+'矧' => '濿',
+'矨' => '莧',
+'砆' => '被',
+'砑' => '篲',
+'砒' => '罐',
+'砅' => '袈',
+'砐' => '訪',
+'砏' => '規',
+'砎' => '覓',
+'砉' => '竁',
+'砃' => '術',
+'砓' => '訝',
+'祊' => '皖',
+'祌' => '皴',
+'祋' => '皓',
+'祅' => '偯',
+'祄' => '痠',
+'秕' => '瀦',
+'种' => '笱',
+'秏' => '鄉',
+'秖' => '硐',
+'秎' => '郵',
+'窀' => '騆',
+'穾' => '',
+'竑' => '粵',
+'笀' => '',
+'笁' => '',
+'籺' => '裨',
+'籸' => '裸',
+'籹' => '衒',
+'籿' => '裯',
+'粀' => '誦',
+'粁' => '誌',
+'紃' => '廝',
+'紈' => '膣',
+'紁' => '廚',
+'罘' => '貔',
+'羑' => '袀',
+'羍' => '縹',
+'羾' => '',
+'耇' => '嬸',
+'耎' => '擴',
+'耏' => '擲',
+'耔' => '鼨',
+'耷' => '痯',
+'胘' => '懵',
+'胇' => '鼬',
+'胠' => '攏',
+'胑' => '眱',
+'胈' => '儳',
+'胂' => '輴',
+'胐\' => '寵',
+'胅' => '鼕',
+'胣' => '曝',
+'胙' => '遹',
+'胜' => '吨',
+'胊' => '郺',
+'胕' => '懶',
+'胉' => '嚥',
+'胏' => '壢',
+'胗' => '邆',
+'胦' => '櫥',
+'胍' => '遻',
+'臿' => '鶯',
+'舡' => '繾',
+'芔' => '雒',
+'苙' => '躪',
+'苾' => '',
+'苹' => 'し',
+'茇' => '嗏',
+'苨' => '鱷',
+'茀' => '',
+'苕' => '塍',
+'茺' => '媿',
+'苫' => '伒',
+'苖' => '讜',
+'苴' => '嗢',
+'苬' => '豔',
+'苡' => '嗄',
+'苲' => '驪',
+'苵' => '鸛',
+'茌' => '嗲',
+'苻' => '嗍',
+'苶' => '鸞',
+'苰' => '爨',
+'苪' => '黷',
+'苤' => '嗒',
+'苠' => '塏',
+'苺' => '',
+'苳' => '鬱',
+'苭' => '鑿',
+'虷' => '洰',
+'虴' => '沀',
+'虼' => '繯',
+'虳' => '沝',
+'衁' => '胑',
+'衎' => '胕',
+'衧' => '苫',
+'衪' => '苖',
+'衩' => '鯇',
+'觓' => '羖',
+'訄' => '',
+'訇' => '渟',
+'赲' => '焮\',
+'迣' => '',
+'迡' => '',
+'迮' => '暩',
+'迠' => '',
+'郱' => '貅',
+'邽' => '',
+'邿' => '',
+'郕' => '詷',
+'郅' => '菑',
+'邾' => '菪',
+'郇' => '菬',
+'郋' => '詶',
+'郈' => '觜',
+'釔' => '醢',
+'釓' => '醚',
+'陔' => '絘',
+'陏' => '瞜',
+'陑' => '瞛',
+'陓' => '瞣',
+'陊' => '瞝',
+'陎' => '瞡',
+'倞' => '',
+'倅' => 'y',
+'倇' => '{',
+'倓' => '',
+'倢' => '',
+'倰' => '',
+'倛' => '',
+'俵' => 'l',
+'俴' => 'k',
+'倳' => '',
+'倷' => '',
+'倬' => '椈',
+'俶' => '棆',
+'俷' => 'n',
+'倗' => '',
+'倜' => '棆',
+'倠' => '',
+'倧' => '',
+'倵' => '',
+'倯' => '',
+'倱' => '',
+'倎' => '',
+'党' => '絨',
+'冔' => '',
+'冓' => '',
+'凊' => '',
+'凄' => 'ぼ',
+'凅' => '',
+'凈' => '噱',
+'凎' => '',
+'剡' => '崵',
+'剚' => '',
+'剒' => 'z',
+'剞' => '崿',
+'剟' => '',
+'剕' => '|',
+'剢' => '',
+'勍' => '',
+'匎' => '',
+'厞' => '',
+'唦' => '~',
+'哢' => 'U',
+'唗' => 't',
+'唒' => 'p',
+'哧' => '蛸',
+'哳' => '蛶',
+'哤' => 'W',
+'唚' => '葸',
+'哿' => '衖',
+'唄' => '葺',
+'唈' => 'j',
+'哫' => 'X',
+'唑' => '裋',
+'唅' => '漪',
+'哱' => '\\',
+'唊' => 'k',
+'哻' => 'c',
+'哷' => '`',
+'哸' => 'a',
+'哠' => 'S',
+'唎' => 'o',
+'唃' => 'g',
+'唋' => 'l',
+'圁' => '',
+'圂' => '',
+'埌' => '',
+'堲' => '',
+'埕' => '跖',
+'埒' => '跙',
+'垺' => '',
+'埆' => '',
+'垽' => '',
+'垼' => '',
+'垸' => '跈',
+'垶' => '',
+'垿' => '',
+'埇' => '',
+'埐' => '',
+'垹' => '',
+'埁' => '',
+'夎' => '',
+'奊' => 'G',
+'娙' => '',
+'娖\' => '',
+'娭' => '',
+'娮' => '',
+'娕' => '',
+'娏' => '',
+'娗' => '',
+'娊' => '',
+'娞' => '',
+'娳' => '',
+'孬' => '堳',
+'宧' => 'h',
+'宭' => 'l',
+'宬' => 'k',
+'尃' => '',
+'屖' => '',
+'屔' => '',
+'峬' => 'm',
+'峿' => '}',
+'峮' => 'n',
+'峱' => 'p',
+'峷' => 'v',
+'崀' => '~',
+'峹' => 'x',
+'帩' => '',
+'帨' => '',
+'庨' => '',
+'庮' => '',
+'庪' => '',
+'庬' => '',
+'弳' => '殣',
+'弰' => '',
+'彧' => '',
+'恝' => '瞱',
+'恚' => '瞨',
+'恧' => '矰',
+'恁' => '磳',
+'悢' => '',
+'悈' => '',
+'悀' => '~',
+'悒' => '膍',
+'悁' => '',
+'悝' => '膃',
+'悃' => '膇',
+'悕' => '',
+'悛' => '膋',
+'悗' => '',
+'悇' => '',
+'悜' => '',
+'悎' => '',
+'戙' => '',
+'扆' => '',
+'拲' => '',
+'挐' => '',
+'捖' => '',
+'挬' => '匿',
+'捄' => '寰',
+'捅' => '舠',
+'挶' => '',
+'捃' => '睖',
+'揤' => 'V',
+'挹' => '睠',
+'捋' => '睒',
+'捊' => '',
+'挼' => '鑑',
+'挩' => '',
+'捁' => '',
+'挴' => '',
+'捘' => '',
+'捔' => '',
+'捙' => '',
+'挭' => '',
+'捇' => '',
+'挳' => '',
+'捚' => '',
+'捑' => '',
+'挸' => '',
+'捗' => '',
+'捀' => '',
+'捈' => '',
+'敊' => '',
+'敆' => '',
+'旆' => '鼒',
+'旃' => '儦',
+'旄' => '鼽',
+'旂' => 'よ',
+'晊' => 'y',
+'晟' => '糗',
+'晇' => 'v',
+'晑' => '}',
+'朒' => 'H',
+'朓' => 'I',
+'栟' => '',
+'栚' => '',
+'桉' => '黓',
+'栲' => '魰',
+'栳' => '魨',
+'栻' => '',
+'桋' => '',
+'桏' => '',
+'栖' => 'へ',
+'栱' => '',
+'栜' => '',
+'栵' => '',
+'栫' => '',
+'栭' => '',
+'栯' => '',
+'桎' => '鳼',
+'桄' => '鳽',
+'栴' => '',
+'栝' => '鴇',
+'栒' => '',
+'栔' => 'ゑ',
+'栦' => '',
+'栨' => '',
+'栮' => '',
+'桍' => '',
+'栺' => '',
+'栥' => '',
+'栠' => '',
+'欬' => '褥',
+'欯' => '@',
+'欭' => '',
+'欱' => 'B',
+'欴' => 'D',
+'歭' => 'l',
+'肂' => '額',
+'殈' => '~',
+'毦' => '',
+'毤' => '',
+'毨' => '',
+'毣' => '',
+'毢' => '',
+'毧' => '',
+'氥' => '',
+'浺' => '',
+'浣' => '雿',
+'浤' => '',
+'浶' => '',
+'洍' => '',
+'浡' => '',
+'涒' => '',
+'浘' => '',
+'浢' => '',
+'浭' => '',
+'浯' => '銧',
+'涑' => '銙',
+'涍' => '',
+'淯' => 'U',
+'浿' => '',
+'涆' => '',
+'浞' => '銩',
+'浧' => '',
+'浠' => '隞',
+'涗' => '',
+'浰' => '',
+'浼' => '隡',
+'浟' => '',
+'涂\' => '芨',
+'涘' => '',
+'洯' => '',
+'浨' => '',
+'涋' => '',
+'浾' => '',
+'涀' => '',
+'涄' => '',
+'洖' => '',
+'涃' => '',
+'浻' => '',
+'浽' => '',
+'浵' => '',
+'涐' => '',
+'烜' => '@',
+'烓' => '',
+'烑' => '',
+'烝' => 'A',
+'烋' => '',
+'缹' => '',
+'烢' => 'E',
+'烗' => '',
+'烒' => '',
+'烞' => 'B',
+'烠' => 'C',
+'烔' => '',
+'烍' => '',
+'烅' => '',
+'烆' => '',
+'烇' => '',
+'烚' => '',
+'烎' => '',
+'烡' => 'D',
+'牂' => '',
+'牸' => '',
+'牷' => '',
+'牶' => '',
+'猀' => '松',
+'狺' => '槉',
+'狴' => '朅',
+'狾' => '板',
+'狶' => '林',
+'狳' => '榱',
+'狻' => '漶',
+'猁' => '朢',
+'珓' => '',
+'珙' => '賧',
+'珥' => '賝',
+'珖' => '',
+'玼' => '哎',
+'珧' => '趛',
+'珣' => '',
+'珩' => '趡',
+'珜' => '',
+'珒' => '',
+'珛' => '',
+'珔' => '',
+'珝' => '',
+'珚' => '',
+'珗' => '',
+'珘' => '',
+'珨' => '',
+'瓞' => '藇',
+'瓟' => '',
+'瓴' => '窶',
+'瓵' => '唧',
+'甡' => '害',
+'畛' => '豲',
+'畟' => '',
+'疰' => '謷',
+'痁' => '班',
+'疻' => '狸',
+'痄' => '謱',
+'痀' => '玆',
+'疿' => '貗',
+'疶' => '狼',
+'疺' => '狽',
+'皊' => '酒',
+'盉' => '婚',
+'眝' => '恿',
+'眛' => '徠',
+'眐' => '彗',
+'眓' => '彫',
+'眒' => '彩',
+'眣' => '悠',
+'眑' => '彬',
+'眕' => '徙',
+'眙' => '薀',
+'眚' => '艜',
+'眢' => '薃',
+'眧' => '悴',
+'砣' => '篸',
+'砬' => '簁',
+'砢' => '訢',
+'砵' => '赦',
+'砯' => '貨',
+'砨' => '豚',
+'砮' => '貫',
+'砫' => '責',
+'砡' => '訛',
+'砩' => '篽',
+'砳' => '赧',
+'砪' => '販',
+'砱' => '貪',
+'祔' => '稍',
+'祛' => '斁',
+'祏' => '短',
+'祜' => '斀',
+'祓' => '斶',
+'祒' => '硯',
+'祑' => '硬',
+'秫' => '瀊',
+'秬' => '',
+'秠' => '鈇',
+'秮' => '',
+'秭' => '濼',
+'秪' => '閑',
+'秜' => '鈞',
+'秞' => '鈐',
+'秝' => '鈍',
+'窆' => '髀',
+'窉' => '',
+'窅' => '',
+'窋' => '',
+'窌' => '',
+'窊' => '',
+'窇' => '',
+'竘' => '絛',
+'笐' => '',
+'笄' => '鯪',
+'笓' => '',
+'笅' => '',
+'笏' => '鯤',
+'笈' => '鬌',
+'笊' => '鯠',
+'笎' => '',
+'笉' => '',
+'笒' => '',
+'粄' => '認',
+'粑' => '譠',
+'粊' => '',
+'粌' => '',
+'粈' => '',
+'粍' => '',
+'粅' => '誡',
+'紞' => '',
+'紝' => '',
+'紑' => '',
+'紎' => '慝',
+'紘' => '',
+'紖' => '',
+'紓' => '蝤',
+'紟' => '',
+'紒' => '',
+'紏' => '慕',
+'紌' => '慧',
+'罜' => '磷',
+'罡\' => '賹',
+'罞' => '磴',
+'罠' => '磯',
+'罝' => '磺',
+'罛' => '矯',
+'羖' => '翼',
+'羒' => '縯',
+'翃' => '',
+'翂' => '',
+'翀' => '',
+'耖' => '齌',
+'耾' => '濾',
+'耹' => '殯',
+'胺' => '健',
+'胲' => '醏',
+'胹' => '瀛',
+'胵' => '櫚',
+'脁' => '瀕',
+'胻' => '瀟',
+'脀' => '瀝',
+'舁' => '籊',
+'舯' => '翿',
+'舥' => '攤',
+'茳' => '嫈',
+'茭' => '媰',
+'荄' => 'ガ',
+'茙' => '',
+'荑' => '塯',
+'茥' => '',
+'荖' => 'ザ',
+'茿' => 'ォ',
+'荁' => 'オ',
+'茦' => '',
+'茜' => '塉',
+'茢' => '',
+'荂' => 'カ',
+'荎' => 'コ',
+'茛' => '摃',
+'茪' => '',
+'茈' => '塝',
+'茼' => '塥',
+'荍' => 'ゲ',
+'茖' => '塱',
+'茤' => '',
+'茠' => '',
+'茷' => '瑗',
+'茯' => '壼',
+'茩' => '',
+'荇' => '嫄',
+'荅' => 'キ',
+'荌' => '滕',
+'荓' => 'ゴ',
+'茞' => '',
+'茬' => '脩',
+'荋' => 'グ',
+'茧' => '潺',
+'荈' => 'ギ',
+'虓' => '潺',
+'虒' => '',
+'蚢' => '狒',
+'蚨' => '繲',
+'蚖' => '鞷',
+'蚍' => '繴',
+'蚑' => '炆',
+'蚞' => '狋',
+'蚇' => '泩',
+'蚗' => '炂',
+'蚆' => '泏',
+'蚋' => '繨',
+'蚚' => '羃',
+'蚅' => '紮',
+'蚥' => '閤',
+'蚙' => '炃',
+'蚡' => '罊',
+'蚧' => '羃',
+'蚕' => '紮',
+'蚘' => '炚',
+'蚎' => '炘',
+'蚝' => '罊',
+'蚐' => '炓',
+'蚔' => '炑',
+'衃' => '胂',
+'衄' => '繻',
+'衭' => '苴',
+'衵' => '茌',
+'衶' => '苻',
+'衲' => '鯆',
+'袀' => '',
+'衱' => '苡',
+'衿' => '鮿',
+'衯' => '苬',
+'袃' => '',
+'衾' => '蘉',
+'衴' => '苵',
+'衼' => '',
+'訒' => '',
+'豇' => '鐖',
+'豗' => '傎',
+'豻' => '喤',
+'貤' => '摿',
+'貣' => '',
+'赶' => '裒',
+'赸' => '裒',
+'趵' => '儺',
+'趷' => '',
+'趶' => '',
+'軑' => '',
+'軓' => '',
+'迾' => '',
+'迵' => '',
+'适' => '巠',
+'迿' => '巠',
+'迻' => '',
+'逄' => '樗',
+'迼' => '',
+'迶' => '',
+'郖' => '誂',
+'郠' => '詺',
+'郙' => '詵',
+'郚' => '誃',
+'郣' => '谼',
+'郟' => '菇',
+'郥' => '豊',
+'郘' => '誄',
+'郛' => '萛',
+'郗' => '菢',
+'郜' => '菗',
+'郤' => '豋',
+'酐' => '鐉',
+'酎' => '鏸',
+'酏' => '鐊',
+'釕' => '醟',
+'釢' => '',
+'釚' => '',
+'陜' => '',
+'陟' => '絯',
+'隼' => '鶺',
+'飣' => '鴸',
+'髟' => '奲',
+'鬯' => '袷',
+'乿' => 'v',
+'偰' => '',
+'偪' => '排',
+'偡' => '排',
+'偞' => '',
+'偠' => '',
+'偓' => '',
+'偋' => '',
+'偝' => '',
+'偲' => '',
+'偈' => '椋',
+'偍' => '',
+'偁' => '',
+'偛' => '',
+'偊' => '',
+'偢' => '礭',
+'倕' => '',
+'偅\' => '',
+'偟' => '',
+'偩' => '',
+'偫' => '',
+'偣' => '',
+'偤' => '',
+'偆' => '',
+'偀' => '',
+'偮' => '',
+'偳' => '',
+'偗' => '',
+'偑' => '',
+'凐' => '',
+'剫' => '',
+'剭' => '',
+'剬' => '',
+'剮' => '塵',
+'勖' => '袺',
+'勓' => '',
+'匭' => '寪',
+'厜' => '',
+'啵' => '逽',
+'啶' => '鄐',
+'唼' => '觤',
+'啍' => '',
+'啐' => '觥',
+'唴' => '',
+'唪' => '裎',
+'啑' => '',
+'啢' => '鄔',
+'唶' => '',
+'唵' => '',
+'唰' => '鄑',
+'啒' => '',
+'啅' => '',
+'唌' => 'm',
+'唲' => '',
+'啥' => '伅',
+'啎' => '',
+'唹' => '睯',
+'啈' => '',
+'唭' => '',
+'唻' => '',
+'啀' => '',
+'啋' => '',
+'圊' => '僛',
+'圇' => '僦',
+'埻' => '',
+'堔' => '',
+'埢' => '',
+'埶' => '',
+'埜' => '',
+'埴' => '跗',
+'堀' => '雈',
+'埭' => '雂',
+'埽' => '隀',
+'堈' => '',
+'埸' => '軯',
+'堋' => '隉',
+'埳' => '隉',
+'埏' => '趉',
+'堇' => '暌',
+'埮' => '',
+'埣' => '',
+'埲' => '',
+'埥' => '',
+'埬' => '',
+'埡' => '貹',
+'堎' => '',
+'埼' => '',
+'堐' => '',
+'埧' => '',
+'堁' => '商',
+'堌' => '',
+'埱' => '',
+'埩' => '',
+'埰' => '',
+'堍' => '隃',
+'堄' => '',
+'奜' => 'O',
+'婠' => '',
+'婘' => '',
+'婕' => '瞍',
+'婧' => '皞',
+'婞' => '',
+'娸' => '',
+'娵' => '',
+'婭' => '瑹',
+'婐' => '',
+'婟' => '皝',
+'婥' => 'C',
+'婬' => 'H',
+'婓' => '窋',
+'婤' => 'B',
+'婗' => '',
+'婃' => '',
+'婝' => '',
+'婒' => '',
+'婄' => '',
+'婛' => '',
+'婈' => '',
+'媎' => 'd',
+'娾' => '',
+'婍' => '',
+'娹' => '',
+'婌' => '',
+'婰' => 'L',
+'婩' => 'F',
+'婇' => '',
+'婑' => '',
+'婖' => '',
+'婂' => '',
+'婜' => '',
+'孲' => 'S',
+'孮' => 'Q',
+'寁' => 'v',
+'寀' => 'u',
+'屙' => '樇',
+'崞' => '慱',
+'崋' => '',
+'崝' => '',
+'崚' => '彃',
+'崠' => '幓',
+'崌' => '',
+'崨' => '',
+'崍' => '徶',
+'崦' => '愨',
+'崥' => '',
+'崏' => '',
+'崰' => '廕',
+'崒' => '',
+'崣' => '',
+'崟' => '',
+'崮' => '慁',
+'帾' => '',
+'帴' => '',
+'庱' => '',
+'庴' => '',
+'庹' => '甀',
+'庲' => '',
+'庳' => '畽',
+'弶' => '',
+'弸' => '',
+'徛' => '',
+'徖' => '',
+'徟' => '',
+'悊' => '',
+'悐' => '殍',
+'悆' => '',
+'悾' => '',
+'悰' => '',
+'悺' => '',
+'惓' => '',
+'惔' => '',
+'惏' => '',
+'惤' => '懋',
+'惙' => '╰',
+'惝\' => '蒡',
+'惈' => '蒡',
+'悱' => '蒤',
+'惛' => '',
+'悷' => '',
+'惊' => '儐',
+'悿' => '儐',
+'惃' => '',
+'惍' => '',
+'惀' => '',
+'挲' => '蕡',
+'捥' => '',
+'掊' => '碚',
+'掂' => '菽',
+'捽' => '',
+'掽' => '',
+'掞' => '癲',
+'掭' => '睚',
+'掝' => '',
+'掗' => '',
+'掫' => '',
+'掎' => '睙',
+'捯' => '',
+'掇' => '嗇',
+'掐' => 'ェ',
+'据' => '擂',
+'掯' => '擂',
+'捵' => '',
+'掜' => '痵',
+'捭' => '矠',
+'掮' => '碏',
+'捼' => '',
+'掤' => '鑑',
+'挻' => '',
+'掟' => '',
+'捸' => '',
+'掅' => '',
+'掁' => '',
+'掑' => '',
+'掍' => '',
+'捰' => '',
+'敓' => '',
+'旍' => '嗤',
+'晥' => '儥',
+'晡' => '縗',
+'晛' => '',
+'晙' => '',
+'晜' => '',
+'晢' => '',
+'朘' => 'K',
+'桹' => 'O',
+'梇' => '曙',
+'梐' => 'a',
+'梜' => 'k',
+'桭' => 'F',
+'桮' => 'G',
+'梮' => '戚',
+'梫' => 'v',
+'楖' => '',
+'桯' => 'H',
+'梣' => 'q',
+'梬' => 'w',
+'梩' => 't',
+'桵' => 'M',
+'桴' => '儓',
+'梲' => 'z',
+'梏' => '儜',
+'桷' => '儗',
+'梒' => 'c',
+'桼' => 'R',
+'桫' => '儑',
+'桲' => 'K',
+'梪' => 'u',
+'梀' => 'V',
+'桱' => 'J',
+'桾' => 'T',
+'梛' => 'j',
+'梖' => 'f',
+'梋' => ']',
+'梠' => 'o',
+'梉' => '[',
+'梤' => 'r',
+'桸' => 'N',
+'桻' => 'Q',
+'梑' => 'b',
+'梌' => '^',
+'梊' => '\\',
+'桽' => 'S',
+'欶' => 'F',
+'欳' => 'C',
+'欷' => '鴗',
+'欸' => 'G',
+'殑' => '',
+'殏' => '',
+'殍' => '氆',
+'殎' => '',
+'殌' => '',
+'氪' => '賵',
+'淀' => '蛭',
+'涫' => '韍',
+'涴' => '',
+'涳' => '',
+'湴' => '',
+'涬' => '',
+'淩' => 'R',
+'淢' => 'M',
+'涷' => '銂',
+'淶' => '鉾',
+'淔' => 'F',
+'渀' => '`',
+'淈' => '',
+'淠' => '鞂',
+'淟' => 'L',
+'淖' => '儷',
+'涾' => '',
+'淥' => '頖',
+'淜' => 'K',
+'淝' => '鞁',
+'淛' => 'J',
+'淴' => '涳',
+'淊' => '',
+'涽' => '敊',
+'淭' => 'T',
+'淰' => 'V',
+'涺' => '',
+'淕' => 'G',
+'淂' => '',
+'淏' => '傅',
+'淉' => '',
+'淐' => 'C',
+'淲' => 'W',
+'淓' => 'E',
+'淽' => ']',
+'淗' => 'H',
+'淍' => '@',
+'淣' => 'N',
+'涻' => '',
+'烺' => 'R',
+'焍' => 'b',
+'烷' => '俛',
+'焗' => 'h',
+'烴' => '泲',
+'焌' => 'a',
+'烰' => 'J',
+'焄' => '[',
+'烳' => 'M',
+'焐' => '嚁',
+'烼' => 'T',
+'烿' => 'V',
+'焆' => ']',
+'焓' => '壖',
+'焀' => 'W',
+'烸' => 'Q',
+'烶' => 'P',
+'焋' => '`',
+'焂' => 'Y',
+'焎' => 'c',
+'牾\' => '艕',
+'牻' => '',
+'牼' => '',
+'牿' => '艖',
+'猝' => '漰',
+'猗' => '潳',
+'猇' => '杼',
+'猑' => '氛',
+'猘' => '泳',
+'猊' => '漭',
+'猈' => '杪',
+'狿' => '枉',
+'猏' => '歿\',
+'猞' => '潀',
+'玈' => '俟',
+'珶' => '',
+'珸' => '拯',
+'珵' => '',
+'琄' => '春',
+'琁' => '施',
+'珽' => '霂',
+'琇' => '昭',
+'琀' => '斫',
+'珺' => '漪',
+'珼' => '挑',
+'珿' => '故',
+'琌' => '是',
+'琋' => '昧',
+'珴' => '',
+'琈' => '映',
+'畤' => '',
+'畣' => '',
+'痎' => '湘',
+'痒' => '欭',
+'痏' => '欭',
+'痋' => '珮\',
+'痌' => '珠',
+'痑' => '雯',
+'痐' => '畔',
+'皏' => '閤',
+'皉' => '郢',
+'盓' => '孰',
+'眹' => '',
+'眯' => '譜',
+'眭' => '薏',
+'眱' => '',
+'眲' => '',
+'眴' => '',
+'眳' => '',
+'眽' => '',
+'眥' => '薧',
+'眻' => '躺',
+'眵' => '薕',
+'硈' => '連',
+'硒' => '昮',
+'硉' => '速',
+'硍' => '逕',
+'硊' => '逝',
+'硌' => '縼',
+'砦' => '簊',
+'硅' => '寡',
+'硐' => '糨',
+'祤' => '',
+'祧' => '檥',
+'祩' => '',
+'祪' => '',
+'祣' => '窘',
+'祫' => '',
+'祡' => '標',
+'离' => '燭',
+'秺' => '燭',
+'秸' => '調',
+'秶' => '',
+'秷' => '',
+'窏' => '',
+'窔' => '',
+'窐' => '',
+'笵' => '道',
+'筇' => '鯦',
+'笴' => '遊',
+'笥' => '鯙',
+'笰' => '農',
+'笢' => '',
+'笤' => '鯥',
+'笳' => '鯕',
+'笘' => '',
+'笪' => '鯰',
+'笝' => '',
+'笱' => '鯬',
+'笫' => '鯞',
+'笭' => '',
+'笯' => '辟',
+'笲' => '運',
+'笸' => '鯢',
+'笚' => '',
+'笣' => '',
+'粔' => '',
+'粘' => '梜',
+'粖' => '',
+'粣' => '',
+'紵' => '',
+'紽' => '瘤',
+'紸' => '璀',
+'紶' => '',
+'紺' => '蝷',
+'絅' => '瞇',
+'紬' => '',
+'紩' => '喙',
+'絁' => '皚',
+'絇' => '瞑',
+'紾' => '瘦',
+'紿' => '蝒',
+'絊' => '磅',
+'紻' => '瘩',
+'紨' => '',
+'罣' => '礁',
+'羕' => '境',
+'羜' => '聳',
+'羝' => '蠑',
+'羛' => '聯',
+'翊' => '騑',
+'翋' => '',
+'翍' => '',
+'翐' => '',
+'翑' => '',
+'翇' => '',
+'翏' => '',
+'翉' => '',
+'耟' => '曜',
+'耞' => '斷',
+'耛' => '擻',
+'聇' => '燻',
+'聃' => '嚬',
+'聈' => '燼',
+'脘' => '錸',
+'脥' => '錸',
+'脙' => '',
+'脛' => '鄵',
+'脭' => '',
+'脟' => '',
+'脬' => '鍺',
+'脞' => '錏',
+'脡' => '',
+'脕' => '錸',
+'脧' => '',
+'脝' => '',
+'脢' => '',
+'舑' => '齧',
+'舸' => '臙',
+'舳' => '艨',
+'舺' => '瓤',
+'舴' => '艩',
+'舲' => '玀',
+'艴' => '氁',
+'莐' => 'ビ',
+'莣' => 'ミ',
+'莨' => '搮',
+'莍\' => 'パ',
+'荺' => 'ツ\',
+'荳' => '飪',
+'莤' => '飪',
+'荴' => 'ダ',
+'莏' => 'ヒ',
+'莁' => 'ト',
+'莕' => 'ブ',
+'莙' => '嫄',
+'荵' => 'チ',
+'莔' => 'フ',
+'莩' => '摀',
+'荽' => '搥',
+'莃' => 'ナ',
+'莌' => 'バ',
+'莝' => 'ホ',
+'莛' => '塣',
+'莪' => '搨',
+'莋' => 'ハ',
+'荾' => 'ヅ',
+'莥' => 'メ',
+'莯' => '',
+'莈' => 'ネ',
+'莗' => 'ヘ',
+'莰' => '搢',
+'荿' => 'テ',
+'莦' => 'モ',
+'莇' => 'ヌ',
+'莮' => 'ユ',
+'荶' => 'ヂ',
+'莚' => 'ペ',
+'虙' => '',
+'虖' => '撋',
+'蚿' => '網',
+'蚷' => '玦',
+'蛂' => '甾',
+'蛁' => '畀',
+'蛅' => '疘',
+'蚺' => '艣',
+'蚰' => '艡',
+'蛈' => '皯',
+'蚹' => '玠',
+'蚳' => '玭',
+'蚸' => '玢',
+'蛌' => '盳',
+'蚴' => '藡',
+'蚻' => '玬',
+'蚼' => '玝',
+'蛃' => '疌',
+'蚽' => '瓝',
+'蚾' => '瓨',
+'衒' => '胦',
+'袉' => '嚃',
+'袕' => '',
+'袨' => '',
+'袢' => '鮵',
+'袪' => '',
+'袚' => '',
+'袑' => '',
+'袡' => '',
+'袟' => '棉',
+'袘' => '蹠',
+'袧' => '',
+'袙' => '',
+'袛' => '',
+'袗' => '',
+'袤' => '湁',
+'袬' => '唊',
+'袌' => '',
+'袓' => '蠱',
+'袎' => '',
+'覂' => '',
+'觖' => '蘠',
+'觙' => '耖',
+'觕' => '翃',
+'訰' => '偋',
+'訧' => '髟',
+'訬' => '偡',
+'訞' => '酎',
+'谹' => '釷',
+'谻' => '釮',
+'豜' => '傒',
+'豝' => '傂',
+'豽' => '喌',
+'貥' => '',
+'赽' => '焟',
+'赻' => '焢',
+'赹' => '焣',
+'趼' => '劘',
+'跂' => '',
+'趹' => '',
+'趿' => '儹',
+'跁' => '',
+'軘' => '',
+'軞' => '',
+'軝' => '',
+'軜' => '',
+'軗' => '',
+'軠' => '',
+'軡' => '',
+'逤' => '窢',
+'逋' => '槥',
+'逑' => '樕',
+'逜' => '稐',
+'逌' => '',
+'逡' => '樠',
+'郯' => '菾',
+'郪' => '豤',
+'郰' => '貄',
+'郴' => '頂',
+'郲' => '賌',
+'郳' => '赨\',
+'郔' => '訿',
+'郫' => '菛',
+'郬' => '豦',
+'郩' => '豥',
+'酖' => '嘧',
+'酘' => '嘕',
+'酚' => '照',
+'酓' => '勫',
+'酕' => '厬',
+'釬' => '榑',
+'釴' => '爾',
+'釱' => '榩',
+'釳' => '榯',
+'釸' => '槔',
+'釤' => '醠',
+'釹' => '鎯',
+'釪' => '榬',
+'釫' => '榼',
+'釷' => '醡',
+'釨' => '榖',
+'釮' => '榎',
+'镺' => '墼',
+'閆' => '蒩',
+'閈' => '嬞\',
+'陼' => '',
+'陭' => '',
+'陫' => '',
+'陱' => '',
+'陯' => '',
+'隿' => '螘',
+'靪' => '魾',
+'頄' => '',
+'飥' => '',
+'馗' => '婺',
+'傛' => '',
+'傕' => '',
+'傔' => '',
+'傞' => '',
+'傋' => '',
+'傣' => '湯',
+'傃' => '',
+'傌' => '',
+'傎' => '鎬',
+'傝' => '',
+'偨' => '',
+'傜\' => '',
+'傒' => '撂',
+'傂' => '',
+'傇' => '',
+'兟' => '',
+'凔' => '',
+'匒' => 'A',
+'匑' => '@',
+'厤' => '',
+'厧' => '盪',
+'喑' => '鈳',
+'喨' => '',
+'喥' => '謠',
+'喭' => '',
+'啷' => '鄍',
+'噅' => 'j',
+'喢' => '',
+'喓' => '',
+'喈' => '鉈',
+'喏' => '裛',
+'喵' => '裚',
+'喁' => '鉒',
+'喣' => '',
+'喒' => '',
+'喤' => '',
+'啽' => '',
+'喌' => '',
+'喦' => '',
+'啿' => '旂',
+'喕' => '',
+'喡' => '',
+'喎' => '',
+'圌' => '葃',
+'堩' => '',
+'堷' => '',
+'堙' => '雱',
+'堞' => '雃',
+'堧' => '',
+'堣' => '',
+'堨' => '',
+'埵' => '',
+'塈' => 'I',
+'堥' => '',
+'堜' => '',
+'堛' => '',
+'堳' => '',
+'堿' => '澗',
+'堶' => '',
+'堮' => '',
+'堹' => '',
+'堸' => '',
+'堭' => '',
+'堬' => '',
+'堻' => '',
+'奡' => 'S',
+'媯' => '璉',
+'媔' => 'i',
+'媟' => 'r',
+'婺' => '磑',
+'媢' => 'u',
+'媞' => 'q',
+'婸' => 'P',
+'媦' => 'y',
+'婼' => 'S',
+'媥' => 'x',
+'媬' => '~',
+'媕' => 'j',
+'媮' => '',
+'娷' => '芚',
+'媄' => 'Z',
+'媊' => '`',
+'媗' => 'l',
+'媃' => 'Y',
+'媋' => 'a',
+'媩' => '|',
+'婻' => 'R',
+'婽' => 'T',
+'媌' => 'b',
+'媜' => 'o',
+'媏' => 'e',
+'媓' => 'h',
+'媝' => 'p',
+'寪' => '',
+'寍' => '|',
+'寋' => '{',
+'寔' => '',
+'寑' => '妗',
+'寊' => 'х',
+'寎' => '}',
+'尌' => '',
+'尰' => '',
+'崷' => '',
+'嵃' => '',
+'嵫' => '慥',
+'嵁' => '',
+'嵋' => '愻',
+'崿' => '',
+'崵' => '',
+'嵑' => '竀',
+'嵎' => '',
+'嵕' => '趶',
+'崳' => '慔',
+'崺' => '',
+'嵒' => '',
+'崽' => '憀',
+'崱' => '',
+'嵙' => '',
+'嵂' => '',
+'崹' => '',
+'嵉' => '',
+'崸' => '',
+'崼' => '',
+'崲' => '',
+'崶' => '',
+'嵀' => '',
+'嵅' => '',
+'幄' => '屣',
+'幁' => '',
+'彘' => '樥',
+'徦' => '',
+'徥' => '',
+'徫' => '',
+'惉' => '',
+'悹' => '',
+'惌' => '',
+'惢' => '',
+'惎' => '',
+'惄' => '',
+'愔' => '',
+'惲' => '聝',
+'愊' => '',
+'愖' => '',
+'愅' => '鹿',
+'惵' => '',
+'愓' => '',
+'惸' => '',
+'惼' => '娾',
+'惾' => '',
+'惁' => '',
+'愃' => '',
+'愘' => '',
+'愝' => '',
+'愐' => '',
+'惿' => '',
+'愄' => '',
+'愋' => '',
+'扊' => '',
+'掔' => '',
+'掱' => '',
+'掰' => '蕘',
+'揎' => '碙',
+'揥' => 'W',
+'揨' => 'Z',
+'揯' => '^',
+'揃' => 'B',
+'撝' => '',
+'揳' => 'a',
+'揊\' => 'F',
+'揠' => '碆',
+'揶' => '睩',
+'揕' => 'L',
+'揲' => '碕',
+'揵' => 'b',
+'摡' => '',
+'揟' => 'T',
+'掾' => '硻',
+'揝' => 'S',
+'揜' => 'R',
+'揄' => '碃',
+'揘' => 'N',
+'揓' => 'J',
+'揂' => 'A',
+'揇' => 'D',
+'揌' => 'H',
+'揋' => 'G',
+'揈' => 'E',
+'揰' => '箔',
+'揗' => 'M',
+'揙' => 'O',
+'攲' => '',
+'敧' => '',
+'敪' => '',
+'敤' => '',
+'敜' => '',
+'敨' => '',
+'敥' => '',
+'斌' => '棄',
+'斝' => '',
+'斞' => '',
+'斮' => '',
+'旐' => '簀',
+'旒' => '儤',
+'晼' => '',
+'晬' => '',
+'晻' => '',
+'暀' => '做',
+'晱' => '',
+'晹' => '',
+'晪' => '',
+'晲' => '',
+'朁' => '',
+'椌' => '',
+'棓' => '',
+'椄' => '',
+'棜' => '',
+'椪' => '',
+'棬' => '',
+'棪' => '',
+'棱' => '濩',
+'椏' => '魤',
+'棖' => '駍',
+'棷' => '﹜',
+'棫' => '勷',
+'棤' => '',
+'棶' => '',
+'椓' => '',
+'椐' => '擏',
+'棳' => '',
+'棡' => '',
+'椇' => '',
+'棌' => '',
+'椈' => '',
+'楰' => 'K',
+'梴' => '{',
+'椑' => '',
+'棯' => '',
+'棆' => '',
+'椔' => '',
+'棸' => '',
+'棐' => '',
+'棽' => '',
+'棼' => '叡',
+'棨' => '',
+'椋' => '憌',
+'椊' => '',
+'椗' => '縪',
+'棎' => '',
+'棈' => '',
+'棝' => '',
+'棞' => '',
+'棦' => '',
+'棴' => '',
+'棑' => '',
+'椆' => '',
+'棔' => '',
+'棩' => '',
+'椕' => '',
+'椥' => '',
+'棇' => '',
+'欹' => '鴠',
+'欻' => 'H',
+'欿' => 'K',
+'欼' => 'I',
+'殔' => '',
+'殗' => '',
+'殙' => '',
+'殕' => '',
+'殽' => '秎',
+'毰' => '',
+'毲' => '',
+'毳' => '諝',
+'氰' => 'я',
+'淼' => '穔',
+'湆' => '',
+'湇' => '',
+'渟' => 's',
+'湉' => '',
+'溈' => '蝂',
+'渼' => '',
+'渽' => '',
+'湅' => '',
+'湢' => '',
+'渫' => '颮',
+'渿' => '',
+'湁' => '',
+'湝' => '',
+'湳' => '',
+'渜' => 'q',
+'渳' => '}',
+'湋' => '',
+'湀' => '',
+'湑' => '',
+'渻' => '',
+'渃' => 'c',
+'渮' => '監',
+'湞' => '銗',
+'湨' => '',
+'湜' => '',
+'湡' => '',
+'渱' => '|',
+'渨' => 'w',
+'湠' => '',
+'湱' => '',
+'湫' => '餇',
+'渹' => '',
+'渢' => 't',
+'渰' => '{',
+'湓' => '馹',
+'湥' => '',
+'渧' => 'v',
+'湸' => '',
+'湤' => '',
+'湷' => '',
+'湕' => '',
+'湹' => '',
+'湒' => '',
+'湦' => '',
+'渵' => '~',
+'渶' => '',
+'湚' => '',
+'焠' => 'n',
+'焞' => 'l',
+'焯' => '壏',
+'烻' => 'S',
+'焮\' => '{',
+'焱' => '壒',
+'焣' => '陷',
+'焥' => 's',
+'焢' => 'p',
+'焲' => '|',
+'焟' => 'm',
+'焨' => 'u',
+'焺' => '',
+'焛' => 'i',
+'牋' => '潦',
+'牚' => '',
+'犈' => '',
+'犉' => '',
+'犆' => '',
+'犅' => '',
+'犋' => '蕖',
+'猒' => '泣',
+'猋' => '鴙',
+'猰' => '沸',
+'猢' => '漵',
+'猱' => '漅',
+'猳' => '油',
+'猧' => '波',
+'猲' => '泄',
+'猭' => '法',
+'猦' => '沼',
+'猣' => '沽',
+'猵' => '況',
+'猌' => '武',
+'琮' => '踦',
+'琬' => '踧',
+'琰' => '踙',
+'琫' => '枸',
+'琖' => '桮',
+'琚' => '鋡',
+'琡' => '柄',
+'琭' => '柏',
+'琱' => '蛐',
+'琤' => '枴',
+'琣' => '柑',
+'琝' => '枯\',
+'琩' => '查',
+'琠' => '柯',
+'琲' => '枰',
+'瓻' => '圃',
+'甯' => '撣',
+'畯' => '',
+'畬' => '豱',
+'痧' => '貙',
+'痚' => '疾',
+'痡' => '疽',
+'痦' => '謺',
+'痝' => '症',
+'痟' => '疲',
+'痤' => '豂',
+'痗' => '畚',
+'皕' => '釙',
+'皒' => '釗',
+'盚' => '寄',
+'睆' => '',
+'睇' => '蕻',
+'睄' => 'Ю',
+'睍' => '',
+'睅' => '',
+'睊' => '',
+'睎' => '',
+'睋' => '',
+'睌' => '',
+'矞' => '',
+'矬' => '瀀',
+'硠' => '',
+'硤' => '篱',
+'硥' => '',
+'硜' => '',
+'硭' => '篰',
+'硱' => '',
+'硪' => '繂',
+'确' => '',
+'硰' => '',
+'硩' => '',
+'硨' => '簅',
+'硞' => '',
+'硢' => '',
+'祴' => '',
+'祳' => '',
+'祲' => '',
+'祰' => '',
+'稂' => '爃',
+'稊' => '',
+'稃' => '燹',
+'稌' => '',
+'稄' => '',
+'窙' => '',
+'竦' => '騊',
+'竤' => '群',
+'筊' => '鄗',
+'笻' => '違',
+'筄' => '逾',
+'筈' => '鄒',
+'筌' => '鶈',
+'筎' => '酪',
+'筀' => '遏',
+'筘' => '鵷',
+'筅' => '鶊',
+'粢' => '譣',
+'粞' => '譨',
+'粨' => '',
+'粡' => '',
+'絘' => '窮',
+'絯' => '緩',
+'絣' => '締',
+'絓' => '穀\',
+'絖' => '膟',
+'絧' => '緘',
+'絪' => '編',
+'絏' => '蟡',
+'絭' => '緞',
+'絜' => '賞',
+'絫' => '緣',
+'絒' => '稼',
+'絔' => '稽',
+'絩' => '緝',
+'絑' => '稿',
+'絟' => '篁',
+'絎' => '蝚',
+'缾' => 'せ',
+'缿' => '',
+'罥' => '禪',
+'罦' => '穗',
+'羢' => '',
+'羠' => '臆',
+'羡' => '畈',
+'翗' => '',
+'聑' => '璧',
+'聏' => '獷',
+'聐' => '獵',
+'胾' => '瀨',
+'胔' => '懷',
+'腃' => '饅',
+'腊' => '幫',
+'腒' => '鯛',
+'腏' => '鯖',
+'腇' => '騙',
+'脽' => '',
+'腍' => '鯨',
+'脺' => '毯',
+'臦' => '霸',
+'臮' => '顧',
+'臷' => '髏\',
+'臸' => '魔',
+'臹' => '魑',
+'舄' => '籅',
+'舼' => '疊',
+'舽' => '癮',
+'舿' => '癬',
+'艵' => '靂',
+'茻\' => '',
+'菏' => '監',
+'菹' => '椿',
+'萣' => 'b',
+'菀' => '椹',
+'菨' => '',
+'萒' => 'T',
+'菧' => '',
+'菤' => '',
+'菼' => 'I',
+'菶' => 'E',
+'萐' => 'S',
+'菆' => '',
+'菈' => '',
+'菫' => '',
+'菣' => '',
+'莿' => '',
+'萁' => '斒',
+'菝' => '暋',
+'菥' => '旓',
+'菘' => '暆',
+'菿' => 'K',
+'菡' => '楙',
+'菋' => '',
+'菎' => '',
+'菖' => '暙',
+'菵' => 'D',
+'菉' => '蟯',
+'萉' => 'Q',
+'萏' => '楎',
+'菞' => '',
+'萑' => '朠',
+'萆' => '楦',
+'菂' => '',
+'菳' => 'B',
+'菕' => '',
+'菺' => 'G',
+'菇' => '厭',
+'菑' => '婐',
+'菪' => '楅',
+'萓' => 'U',
+'菃' => '',
+'菬' => '',
+'菮' => '@',
+'菄' => '',
+'菻' => 'H',
+'菗' => '',
+'菢' => '惕',
+'萛' => '\\',
+'菛' => '',
+'菾' => 'J',
+'蛘' => '藑',
+'蛢' => '',
+'蛦' => '',
+'蛓' => '盵',
+'蛣' => '奱',
+'蛚' => '矻',
+'蛪' => '',
+'蛝' => '',
+'蛫' => '',
+'蛜' => '矺',
+'蛬' => '',
+'蛩' => '藨',
+'蛗' => '矹',
+'蛨' => '',
+'蛑' => '藰',
+'衈' => '胣',
+'衖' => '讀',
+'衕' => '肮',
+'袺' => '標',
+'裗' => '娮',
+'袹' => '埌',
+'袸' => '圂',
+'裀' => '垽',
+'袾' => '垺',
+'袶' => '圁',
+'袼' => '鮶',
+'袷' => '鯓',
+'袽' => '埒',
+'袲' => '哠',
+'褁' => '庬',
+'裉' => '鯄',
+'覕' => '╰',
+'覘' => '膱',
+'覗' => '',
+'觝' => '萋',
+'觚' => '蘞',
+'觛' => '耾',
+'詎' => '琲',
+'詍' => '勖',
+'訹' => '倕',
+'詙' => '啢',
+'詀' => '偤',
+'詗' => '唪',
+'詘' => '痚',
+'詄' => '偳',
+'詅' => '偗',
+'詒' => '痡',
+'詈' => '蹎',
+'詑' => '啵',
+'詊' => '剭',
+'詌' => '剮',
+'詏' => '匭',
+'豟' => '兟',
+'貁' => '喡',
+'貀' => '喕',
+'貺' => '縔',
+'貾' => '愋',
+'貰' => '縍',
+'貹' => '愘',
+'貵' => '惼',
+'趄' => '鐍',
+'趀' => '焛',
+'趉' => '犅',
+'跘' => '羢',
+'跓' => '',
+'跍' => '',
+'跇' => '',
+'跖' => '嚽',
+'跜' => '羡',
+'跏' => '巏',
+'跕' => '罦',
+'跙' => '羠',
+'跈' => '',
+'跗' => '嚾',
+'跅' => '',
+'軯' => '寙',
+'軷' => '嵬',
+'軺' => '澥',
+'軹' => '澽',
+'軦' => '嫀',
+'軮' => '寘',
+'軥' => '媷',
+'軵' => '嵥',
+'軧' => '嫊',
+'軨' => '媴',
+'軶' => '濎',
+'軫' => '濊',
+'軱' => '尳',
+'軬' => '媐',
+'軴' => '嵊',
+'軩' => '媶',
+'逭' => '槢',
+'逴' => '筰',
+'逯' => '樛',
+'鄆' => '菮',
+'鄬' => '',
+'鄄' => '蛢',
+'郿' => '趔',
+'郼' => '趓',
+'鄈' => '跮',
+'郹' => '趎',
+'郻' => '趍',
+'鄁' => '缿',
+'鄀' => '趐',
+'鄇' => '跱',
+'鄅' => '跠',
+'鄃\' => '跰',
+'酡' => '鶔',
+'酤' => '鏿',
+'酟' => '嘏',
+'酢' => '鶠',
+'酠' => '嘜',
+'鈁' => '鍜',
+'鈊' => '歍',
+'鈥' => '鍐',
+'鈃' => '榗',
+'鈚' => '漮',
+'鈦' => '鍖',
+'鈏' => '毃',
+'鈌' => '殞',
+'鈀' => '鍑',
+'鈒' => '滎',
+'釿' => '榪',
+'釽' => '榳',
+'鈆' => 'レ',
+'鈄' => '鍉',
+'鈧' => '鍶',
+'鈂' => '槙\',
+'鈜' => '潎',
+'鈤' => '漊',
+'鈙' => '滻',
+'鈗' => '滸',
+'鈅' => '埥',
+'鈖' => '漥',
+'镻' => '壆',
+'閍' => '嶧',
+'閌' => '蒘',
+'閐' => '嶮',
+'隇' => '',
+'陾' => '',
+'隈' => '絪',
+'隉' => '絣',
+'隃' => '',
+'隀' => '',
+'雂' => '蝹',
+'雈' => '螣',
+'雃' => '螇',
+'雱' => '',
+'雰' => '煬',
+'靬' => '鮂',
+'靰' => '魺',
+'靮' => '鮒',
+'頇' => '嬿',
+'颩' => '餬',
+'飫' => '熏',
+'鳦' => '讈',
+'黹' => '臄',
+'亃' => 'z',
+'亄' => '{',
+'亶' => '',
+'傽' => '@',
+'傿' => 'B',
+'僆' => 'I',
+'傮' => '',
+'僄' => 'G',
+'僊' => '珈',
+'傴' => '嵅',
+'僈' => 'K',
+'僂' => '棎',
+'傰' => '',
+'僁' => 'D',
+'傺' => '棦',
+'傱' => '',
+'僋' => 'N',
+'僉' => '欼',
+'傶' => '',
+'傸' => '',
+'凗' => '',
+'剺' => '',
+'剸' => '',
+'剻' => '',
+'剼' => '',
+'嗃' => '',
+'嗛' => '',
+'嗌' => '鉓',
+'嗐' => '',
+'嗋' => '',
+'嗊' => '',
+'嗝' => '鈱',
+'嗀' => '',
+'嗔' => '鉡',
+'嗄' => '鉔',
+'嗩' => '蜍',
+'喿' => '',
+'嗒' => '鄋',
+'喍' => '',
+'嗏' => '',
+'嗕' => '',
+'嗢' => '',
+'嗖' => '鉦',
+'嗈' => '',
+'嗲' => '鉲',
+'嗍' => '鉌',
+'嗙' => '',
+'嗂' => '',
+'圔' => 'B',
+'塓' => 'Q',
+'塨' => 'b',
+'塤' => '跕',
+'塏' => '趀',
+'塍' => '鋹',
+'塉' => 'J',
+'塯' => 'g',
+'塕' => 'R',
+'塎' => 'M',
+'塝' => 'Y',
+'塙' => '',
+'塥' => '靰',
+'塛' => 'W',
+'堽' => '詳',
+'塣' => '^',
+'塱' => 'i',
+'壼' => '',
+'嫇' => '',
+'嫄' => '',
+'嫋' => '蘅',
+'媺' => '',
+'媸' => '磉',
+'媱' => '',
+'媵' => '鋷',
+'媰' => '',
+'媿' => '壕',
+'嫈' => '',
+'媻' => '',
+'嫆' => '',
+'媷' => '',
+'嫀' => '',
+'嫊' => '',
+'媴' => '',
+'媶' => '',
+'嫍' => '',
+'媹' => '',
+'媐' => 'f',
+'寖' => '輞',
+'寘' => '离',
+'寙' => '',
+'尟' => '珅',
+'尳' => '',
+'嵱' => '',
+'嵣' => '',
+'嵊' => '慪',
+'嵥' => '',
+'嵲' => '',
+'嵬' => '慴',
+'嵞' => '',
+'嵨' => '昶',
+'嵧' => '',
+'嵢' => '',
+'巰' => '裉',
+'幏' => '',
+'幎' => '蹶',
+'幊' => '',
+'幍' => '',
+'幋\' => '',
+'廅' => '',
+'廌' => 'D',
+'廆' => '@',
+'廋' => 'C',
+'廇' => 'A',
+'彀' => '麆',
+'徯' => '',
+'徭' => '撂',
+'惷' => '替',
+'慉' => 'A',
+'慊' => '蒚',
+'愫' => '蒪',
+'慅' => '',
+'愶' => '',
+'愲' => '',
+'愮' => '',
+'慆' => '',
+'愯' => '',
+'慏' => 'D',
+'愩' => '',
+'慀' => '',
+'戠' => '',
+'酨' => '嘂',
+'戣' => '',
+'戥' => '磠',
+'戤' => '禤',
+'揅' => 'C',
+'揱' => '`',
+'揫' => '噢',
+'搐' => '握',
+'搒' => '埤',
+'搉' => 'n',
+'搠' => '稑',
+'搤' => '塭',
+'搳' => '',
+'摃' => '蕈',
+'搟' => '{',
+'搕' => 't',
+'搘' => 'w',
+'搹' => '塭',
+'搷' => '',
+'搢' => '|',
+'搣' => '}',
+'搌' => '稘',
+'搦' => '稙',
+'搰' => '',
+'搨' => '阹',
+'摁' => '禂',
+'搵' => '',
+'搯' => '',
+'搊' => '昅',
+'搚' => 'y',
+'摀' => '拰',
+'搥' => '晰',
+'搧' => '圮',
+'搋' => '祽',
+'揧' => 'Y',
+'搛' => '祹',
+'搮' => '',
+'搡' => '稒',
+'搎' => 'q',
+'敯' => '',
+'斒' => '唯',
+'旓' => '',
+'暆' => '',
+'暌' => '縓',
+'暕' => '',
+'暐' => '',
+'暋' => '',
+'暊' => '',
+'暙' => '',
+'暔' => '',
+'晸' => '',
+'朠' => 'P',
+'楦' => '曏',
+'楟' => '',
+'椸' => '',
+'楎' => '',
+'楢' => 'A',
+'楱' => '擉',
+'椿' => '暑',
+'楅' => '',
+'楪' => 'G',
+'椹' => '撽',
+'楂' => '擃',
+'楗' => '擖',
+'楙' => '',
+'楺' => 'Q',
+'楈' => '',
+'楉' => '',
+'椵' => '',
+'楬' => 'H',
+'椳' => '',
+'椽' => '揪',
+'楥' => '曏',
+'棰' => '憸',
+'楸' => '敼',
+'椴' => '斢',
+'楩' => 'F',
+'楀' => '',
+'楯' => 'J',
+'楄' => '',
+'楶' => 'P',
+'楘' => '',
+'楁' => '',
+'楴' => 'N',
+'楌' => '',
+'椻' => '',
+'楋' => '',
+'椷' => '澎',
+'楜' => '',
+'楏' => '',
+'楑' => '',
+'椲' => '',
+'楒' => '',
+'椯' => '',
+'楻' => 'R',
+'椼' => '',
+'歆' => '鴔',
+'歅' => 'P',
+'歃' => '鴞',
+'歂' => 'N',
+'歈' => 'Q',
+'歁' => 'M',
+'殛' => '濋',
+'嗀' => 'A',
+'毻' => '',
+'毼' => '',
+'毹' => '諟',
+'毷' => '',
+'毸' => '',
+'溛' => '',
+'滖' => '',
+'滈' => '',
+'溏' => '儃',
+'滀' => '',
+'溟' => '僸',
+'溓' => '',
+'溔' => '',
+'溠' => '',
+'溱' => '骱',
+'溹' => '咁',
+'滆' => '',
+'滒' => '',
+'溽' => '魟',
+'滁' => '壹',
+'溞' => '',
+'滉' => '',
+'溷' => '鳲',
+'溰' => '馬',
+'滍' => '',
+'溦' => '',
+'滏' => '僿',
+'溲' => '馝',
+'溾' => '',
+'滃' => '',
+'滜\' => '',
+'滘' => '',
+'溙' => '',
+'溒' => '',
+'溎' => '',
+'溍' => '',
+'溤' => '',
+'溡' => '',
+'溿' => '',
+'溳' => '',
+'滐' => '',
+'滊' => '',
+'溗' => '',
+'溮' => '',
+'溣' => '',
+'煇' => '閩',
+'煔' => '',
+'煒' => '勴',
+'煣' => '',
+'煠' => '',
+'煁' => '',
+'煝' => '',
+'煢' => '塤',
+'煲' => '嬬',
+'煸' => '嬦',
+'煪' => '',
+'煡' => '',
+'煂' => '',
+'煘' => '',
+'煃' => '',
+'煋' => '',
+'煰' => '',
+'煟' => '',
+'煐' => '',
+'煓' => '',
+'煄' => '',
+'煍' => '',
+'煚' => '',
+'牏' => '',
+'犍' => '蕅',
+'犌' => '',
+'犑' => '',
+'犐' => '',
+'犎' => '',
+'猼' => '泱',
+'獂' => '泛',
+'猻' => '暟',
+'猺' => '泗',
+'獀' => '治',
+'獊' => '',
+'獉' => '暺',
+'瑄' => '泉',
+'瑊' => '洌',
+'瑋' => '誺',
+'瑒' => '',
+'瑑' => '',
+'瑗' => '镼',
+'瑀' => '毒',
+'瑏' => '',
+'瑐' => '',
+'瑎' => '',
+'瑂' => '毗',
+'瑆' => '洲',
+'瑍' => '洗',
+'瑔' => '',
+'瓡' => '',
+'瓿' => '窸',
+'瓾' => '埔',
+'瓽' => '埂',
+'甝' => '孫',
+'畹' => '豯',
+'畷' => '',
+'榃' => 'W',
+'痯' => '皰',
+'瘏' => '',
+'瘃' => '貘',
+'痷' => '真',
+'痾' => '謼',
+'痼' => '賾',
+'痹' => '敘',
+'痸' => '眠',
+'瘐' => '贂',
+'痻' => '矩',
+'痶' => '眩',
+'痭' => '疸',
+'痵' => '盎',
+'痽' => '砰',
+'皙' => '薵',
+'皵' => '',
+'盝' => '宿',
+'睕' => '',
+'睟' => '氫',
+'睠' => '樺',
+'睒' => '',
+'睖' => '',
+'睚' => '薚',
+'睩' => '淙',
+'睧' => '淳',
+'睔' => '',
+'睙' => '',
+'睭' => '淡',
+'矠' => '',
+'碇' => '縪',
+'碚' => '縸',
+'碔' => '富',
+'碏' => '孳',
+'碄' => '婷',
+'碕' => '寓',
+'碅' => '媚',
+'碆' => '婿',
+'碡' => '繀',
+'碃' => '',
+'硹' => '',
+'碙' => '尊',
+'碀' => '',
+'碖' => '寐',
+'硻' => '',
+'祼' => '',
+'禂' => '',
+'祽' => '',
+'祹' => '',
+'稑' => '',
+'稘' => '',
+'稙' => '',
+'稒' => '',
+'稗' => '啕',
+'稕' => '',
+'稢' => '嵩',
+'稓' => '',
+'稛' => '',
+'稐' => '',
+'窣' => '睹',
+'窢' => '',
+'窞' => '袼',
+'竫' => '腱',
+'筦' => '奪',
+'筤' => '鉋',
+'筭' => '呾',
+'筴' => '翎',
+'筩' => '芠',
+'筲' => '鶌',
+'筥' => '鉤',
+'筳' => '隔',
+'筱' => '鵽',
+'筰' => '隘',
+'筡' => '鈾\',
+'筸' => '雋',
+'筶' => '雍',
+'筣' => '鉛',
+'粲' => '譥',
+'粴' => '',
+'粯' => '',
+'綈' => '蝪',
+'綆' => '蝞',
+'綀' => '',
+'綍' => '蝔',
+'絿' => '',
+'綅\' => '',
+'絺' => '',
+'綎' => '',
+'絻' => '',
+'綃' => '蝭',
+'絼' => '',
+'綌' => '',
+'綔' => '',
+'綄' => '',
+'絽' => '',
+'綒' => '',
+'罭' => '篾',
+'罫' => '簇',
+'罧' => '窿',
+'罨' => '蹍',
+'罬' => '簍',
+'羦' => '臀',
+'羥' => '蠗',
+'羧' => '蠓',
+'翛' => '',
+'翜' => '',
+'耡' => '堝',
+'腤' => '嚷',
+'腠' => '錍',
+'腷' => '懺',
+'腜' => '鵬',
+'腩' => '鋋',
+'腛' => '鵪',
+'腢' => '勸',
+'腲' => '孽',
+'朡' => 'Q',
+'腞' => '麗',
+'腶' => '懸',
+'腧' => '錓',
+'腯' => '孃',
+'腄' => '饉',
+'腡' => '錆',
+'舝' => '巒',
+'艉' => '蘁',
+'艄' => '藿',
+'艀' => '',
+'艂' => '',
+'艅' => '',
+'蓱' => 'げ',
+'萿' => 'u',
+'葖' => '',
+'葶' => '楯',
+'葹' => '',
+'蒏' => '屮',
+'蒍' => '兀',
+'葥' => '',
+'葑' => '楈',
+'葀' => 'v',
+'蒆' => '亍',
+'葧' => '',
+'萰' => 'j',
+'葍' => '',
+'葽' => '乂',
+'葚' => '楉',
+'葙' => '椵',
+'葴' => '',
+'葳' => '楬',
+'葝' => '',
+'蔇' => '犵',
+'葞' => '',
+'萷' => 'е',
+'萺' => 'r',
+'萴' => 'm',
+'葺' => '楥',
+'葃' => 'y',
+'葸' => '楸',
+'萲' => 'k',
+'葅' => '{',
+'萩' => 'c',
+'菙' => '',
+'葋' => '',
+'萯' => 'i',
+'葂' => 'x',
+'萭' => 'g',
+'葟' => '',
+'葰' => '',
+'萹' => 'q',
+'葎' => '',
+'葌' => '',
+'葒' => '搹',
+'葯' => '狻',
+'蓅' => '宄',
+'蒎' => '楶',
+'萻' => 's',
+'葇' => '|',
+'萶' => 'o',
+'萳' => 'l',
+'葨' => '',
+'葾' => '殲',
+'葄' => 'z',
+'萫' => 'e',
+'葠' => '統',
+'葔' => '',
+'葮' => '楁',
+'葐' => '',
+'蜋' => '譖',
+'蜄' => '',
+'蛷' => '',
+'蜌' => '',
+'蛺' => '藚',
+'蛖' => '矼',
+'蛵' => '',
+'蝍' => '奓',
+'蛸' => '藞',
+'蜎' => '',
+'蜉' => '蠃',
+'蜁' => '',
+'蛶' => '',
+'蜍' => '蟺',
+'蜅' => '',
+'裖' => '娭',
+'裋' => '埐',
+'裍' => '埁',
+'裎' => '鮽',
+'裞' => '娞',
+'裛' => '娏',
+'裚' => '娕',
+'裌' => '標',
+'裐' => '奊',
+'覅' => '',
+'覛' => '',
+'觟' => '胺',
+'觥' => '騿',
+'觤' => '脁',
+'觡' => '胹',
+'觠' => '胲',
+'觢' => '胵',
+'觜' => '蘥',
+'触' => '揖',
+'詶' => '',
+'誆' => '痦',
+'詿' => '痟',
+'詡' => '睄',
+'訿' => '鬗',
+'詷' => '',
+'誂' => '崒',
+'誄' => '痝',
+'詵' => '皕',
+'誃' => '崣',
+'誁' => '崰',
+'詴' => '',
+'詺' => '',
+'谼' => '镺',
+'豋' => '飥',
+'豊' => '頄',
+'豥' => '厤',
+'豤' => '匑',
+'豦' => '厧',
+'貆' => '堩',
+'貄' => '圌',
+'貅' => '蘙',
+'賌' => '揶',
+'赨\' => '渵',
+'赩' => '渶',
+'趑' => '鐀',
+'趌' => '犋',
+'趎' => '猋',
+'趏' => '猰',
+'趍' => '猒',
+'趓' => '猳',
+'趔' => '鏵',
+'趐' => '猢',
+'趒' => '猱',
+'跰' => '錧',
+'跠' => '翗',
+'跬' => '攛',
+'跱' => '腇',
+'跮' => '腒',
+'跐' => '',
+'跩' => '腃',
+'跣' => '欃',
+'跢' => '聏',
+'跧' => '胔',
+'跲' => '脽',
+'跫' => '齞',
+'跴' => '笮',
+'輆' => '廇',
+'軿' => '幊',
+'輁' => '幋\',
+'輀' => '幍',
+'輅' => '澪',
+'輇' => '澬',
+'輈' => '徯',
+'輂' => '廅',
+'輋' => '慉',
+'遒' => '樧',
+'逿' => '粲',
+'遄' => '樝',
+'遉' => '淈',
+'逽' => '筣',
+'鄐' => '跴',
+'鄍' => '跧',
+'鄏' => '跫',
+'鄑' => '輆',
+'鄖' => '堌',
+'鄔' => '絑',
+'鄋' => '跣',
+'鄎' => '跲',
+'酮' => '耵',
+'酯' => '鶗',
+'鉈' => '鍞',
+'鉒' => '窬',
+'鈰' => '鍻',
+'鈺' => '鍠',
+'鉦' => '鍭',
+'鈳' => '鍌',
+'鉥' => '粿',
+'鉞' => '鍕',
+'銃' => '鴷',
+'鈮' => '鍧',
+'鉊' => '稫',
+'鉆' => '郰',
+'鉭' => '鍏',
+'鉬' => '鍒',
+'鉏' => '堝',
+'鉠' => '劄',
+'鉧' => '粺',
+'鉯' => '緅',
+'鈶' => '',
+'鉡' => '箙',
+'鉰' => '綝',
+'鈱' => '',
+'鉔' => '箈',
+'鉣' => '箂',
+'鉐' => '窨',
+'鉲' => '鼢',
+'鉎' => '稨',
+'鉓' => '竮',
+'鉌' => '稰',
+'鉖' => '箊',
+'鈲' => '',
+'閟' => '廥',
+'閜' => '廧',
+'閞' => '廨',
+'閛' => '廩',
+'隒' => '蕁',
+'隓' => '蕢',
+'隑' => '蕤',
+'隗' => '絭',
+'雎' => '鷈',
+'雺' => '',
+'雽' => '',
+'雸' => '',
+'雵' => '',
+'靳' => '輟',
+'靷' => '',
+'靸' => '',
+'靲' => '',
+'頏' => '幰',
+'頍' => '',
+'頎' => '巃',
+'颬' => '餲',
+'飶' => '',
+'飹' => '',
+'馯' => '鎒',
+'馲' => '鎝',
+'馰' => '鎷',
+'馵' => '鎎',
+'骭' => '醭',
+'骫' => '鄿',
+'魛' => '',
+'鳪' => '轤',
+'鳭' => '鑢',
+'鳧' => '溈',
+'麀' => '~',
+'黽' => '鶻',
+'僦' => '棩',
+'僔' => 'V',
+'僗' => 'X',
+'僨' => '棽',
+'僳' => '咇',
+'僛' => '[',
+'僪' => 'h',
+'僝' => ']',
+'僤' => 'd',
+'僓' => 'U',
+'僬' => '棔',
+'僰' => 'k',
+'僯' => 'j',
+'僣' => '椆',
+'僠' => '`',
+'凘' => '@',
+'劀' => '',
+'劁' => '崺',
+'勩' => '',
+'勫' => '',
+'匰' => 'S',
+'厬' => '',
+'嘧' => '雽',
+'嘕' => 'J',
+'嘌' => '隒',
+'嘒' => 'G',
+'嗼' => '',
+'嘏' => '媗',
+'嘜' => '蝍',
+'嘁' => '隓',
+'嘓' => 'H',
+'嘂' => '',
+'嗺' => '',
+'嘝' => 'P',
+'嘄' => '',
+'嗿' => '',
+'嗹' => '',
+'墉' => '颩',
+'塼' => 't',
+'墐' => '',
+'墘' => '',
+'墆' => 'y',
+'墁' => '頇',
+'塿\' => 'v',
+'塴' => '隉',
+'墋' => '}',
+'塺' => 'r',
+'墇' => 'z',
+'墑' => '圴',
+'墎' => '',
+'塶' => 'n',
+'墂' => 'w',
+'墈' => '{',
+'塻' => 's',
+'墔' => '',
+'墏' => '',
+'壾' => '',
+'奫' => '[',
+'嫜' => '歶',
+'嫮' => '',
+'嫥' => '',
+'嫕' => '',
+'嫪' => '',
+'嫚' => '',
+'嫭' => '',
+'嫫' => '磔',
+'嫳' => '',
+'嫢' => '',
+'嫠' => '禚',
+'嫛' => '',
+'嫬' => '',
+'嫞' => '',
+'嫝' => '',
+'嫙' => '',
+'嫨' => '',
+'嫟' => '',
+'孷' => '糒',
+'寠' => '',
+'寣' => '',
+'屣' => '樖',
+'嶂' => '戩',
+'嶀' => '',
+'嵽' => '',
+'嶆' => '',
+'嵺' => '',
+'嶁' => '慛',
+'嵷' => '',
+'嶊' => '',
+'嶉' => '',
+'嶈' => '',
+'嵾' => '統',
+'嵼' => '',
+'嶍' => '',
+'嵹' => '',
+'嵿' => '',
+'幘' => '僣',
+'幙' => '躉',
+'幓' => '',
+'廘' => 'L',
+'廑' => '瘈',
+'廗' => 'K',
+'廎' => 'F',
+'廜' => 'O',
+'廕' => '秭',
+'廙' => 'M',
+'廒' => '瘖',
+'廔' => 'I',
+'彄' => '',
+'彃' => '',
+'彯' => '',
+'徶' => '',
+'愬' => '咂',
+'愨' => '磻',
+'慁' => '',
+'慞' => 'P',
+'慱' => '_',
+'慳' => '膆',
+'慒' => 'F',
+'慓' => 'G',
+'慲' => '`',
+'慬' => '[',
+'憀' => 'l',
+'慴' => '扤',
+'慔' => 'H',
+'慺' => 'f',
+'慛' => 'N',
+'慥' => 'V',
+'愻' => '',
+'慪' => '睮',
+'慡' => 'S',
+'慖' => 'I',
+'戩' => '穄',
+'戧' => '磛',
+'戫' => '',
+'搫' => '唸',
+'摍' => '',
+'摛' => '',
+'摝' => '',
+'摴' => '',
+'摶' => '痭',
+'摲' => '',
+'摳' => '諭',
+'摽' => '',
+'摵' => '',
+'摦' => '',
+'撦' => '雀',
+'摎' => '',
+'撂' => '賻',
+'摞' => '稗',
+'摜' => '碄',
+'摋' => '',
+'摓' => '',
+'摠' => '',
+'摐' => '',
+'摿' => '',
+'搿' => '諢',
+'摬' => '',
+'摫' => '',
+'摙' => '',
+'摥' => '',
+'摷' => '',
+'敳' => '',
+'斠' => '',
+'暡' => '',
+'暠' => '',
+'暟' => '',
+'朅' => 'A',
+'朄' => '@',
+'朢' => '咡',
+'榱' => '橧',
+'榶' => 'y',
+'槉' => '',
+'榠' => 'i',
+'槎' => '曊',
+'榖' => 'b',
+'榰' => 'u',
+'榬' => 'r',
+'榼' => '}',
+'榑' => '_',
+'榙' => 'd',
+'榎' => '\\',
+'榧' => '曌',
+'榍' => '橶',
+'榩' => 'p',
+'榾' => '',
+'榯' => 't',
+'榿' => '鳿',
+'槄' => '',
+'榽' => '~',
+'榤' => 'm',
+'槔' => '橉',
+'榹' => '{',
+'槊' => '橨',
+'榚' => 'e',
+'槏' => '',
+'榳' => 'w',
+'榓' => 'a',
+'榪' => '餈',
+'榡' => 'j',
+'榞' => 'g',
+'槙\' => '',
+'榗' => 'c',
+'榐' => '^',
+'槂' => '',
+'榵' => 'x',
+'榥' => 'n',
+'槆' => '╰',
+'歊' => '╰',
+'歍' => 'T',
+'歋' => 'S',
+'殞' => '氄',
+'殟' => '',
+'殠' => '',
+'毃' => '',
+'毄' => '',
+'毾' => '',
+'滎' => '嫆',
+'滵' => 'D',
+'滱' => 'A',
+'漃' => 'P',
+'漥' => 'j',
+'滸' => '銊',
+'漷' => 't',
+'滻' => 'I',
+'漮' => 'o',
+'漉' => '勯',
+'潎' => '',
+'漙' => '`',
+'漚' => '鬚',
+'漧' => '補',
+'漘' => '_',
+'漻' => 'x',
+'漒' => '\\',
+'滭' => '',
+'漊' => 'U',
+'漶' => '儊',
+'潳' => '',
+'滹' => '儌',
+'滮' => '',
+'漭' => '鬾',
+'潀' => '|',
+'漰' => 'p',
+'漼' => 'y',
+'漵' => '駃',
+'滫' => '',
+'漇' => 'S',
+'漎' => 'Y',
+'潃' => '',
+'漅' => 'R',
+'滽' => 'K',
+'滶' => 'E',
+'漹' => 'v',
+'漜' => 'c',
+'滼' => 'J',
+'漺' => 'w',
+'漟' => 'f',
+'漍' => 'X',
+'漞' => 'e',
+'漈' => 'T',
+'漡' => 'g',
+'熇' => '',
+'熐' => '',
+'熉' => '',
+'熀' => '',
+'熅' => '',
+'熂' => '',
+'熏' => '悇',
+'煻' => '',
+'熆' => '',
+'熁' => '',
+'熗' => '嚌',
+'牄' => '',
+'牓' => '埤',
+'犗' => '',
+'犕' => '',
+'犓' => '',
+'獃' => '渭',
+'獍' => '滶',
+'獑' => '',
+'獌' => '',
+'瑢' => '',
+'瑳' => '',
+'瑱' => '',
+'瑵' => '',
+'瑲' => '',
+'瑧' => '',
+'瑮' => '',
+'甀' => '埋',
+'甂' => '堉',
+'甃' => '夏',
+'畽' => '貕',
+'疐' => '涌',
+'瘖' => '鈳',
+'瘈' => '',
+'瘌' => '蹢',
+'瘕' => '蹥',
+'瘑' => '',
+'瘊' => '蹗',
+'瘔' => '',
+'皸' => '鼥',
+'瞁' => '淵',
+'睼' => '混',
+'瞅' => '圍',
+'瞂' => '淅',
+'睮' => '淌',
+'瞀' => '謢',
+'睯' => '淤',
+'睾' => '媞',
+'瞃' => '淒',
+'碲' => '縩',
+'碪' => '涷',
+'碴' => '舂',
+'碭' => '竀',
+'碨' => '巽',
+'硾' => '',
+'碫' => '幀',
+'碞' => '就',
+'碥' => '縰',
+'碠' => '嵌',
+'碬' => '幃',
+'碢' => '篸',
+'碤' => '崴',
+'禘' => '診',
+'禊' => '檛',
+'禋' => '',
+'禖' => '詆',
+'禕' => '詐',
+'禔' => '詛',
+'禓' => '詔',
+'禗' => '訴',
+'禈' => '',
+'禒' => '',
+'禐' => '',
+'稫' => '徬',
+'穊' => '搓',
+'稰' => '感',
+'稯' => '慈',
+'稨' => '廈',
+'稦' => '幹',
+'窨' => '鬵',
+'窫' => '睨',
+'窬' => '鬩',
+'竮' => '腸',
+'箈' => '頑',
+'箜' => '鵯',
+'箊' => '頊',
+'箑' => '',
+'箐' => '鵫',
+'箖' => '',
+'箍' => '嘀',
+'箌' => '頌',
+'箛' => '',
+'箎' => '齁',
+'箅' => '鵻',
+'箘' => '',
+'劄' => '崥',
+'箙' => '',
+'箤\' => '',
+'箂' => '零',
+'粻' => '',
+'粿' => '劇',
+'粼' => '譧',
+'粺' => '啕',
+'綧' => '醃',
+'綷' => '閱\',
+'緂' => '頜',
+'綣' => '蝜',
+'綪' => '銷',
+'緁' => '頫',
+'緀' => '頡',
+'緅' => '餓',
+'綝' => '遭',
+'緎' => '駒',
+'緄' => '蝯',
+'緆' => '餒',
+'緋' => '蝟',
+'緌' => '駑',
+'綯' => '鋁',
+'綹' => '蝮',
+'綖' => '',
+'綼' => '靠',
+'綟' => '鄰',
+'綦' => '鐏',
+'綮' => '鐔',
+'綩' => '銻',
+'綡' => '鄧',
+'緉' => '駐',
+'罳' => '篠',
+'翢' => '',
+'翣' => '',
+'翥' => '醷',
+'翞' => '',
+'耤' => '檬',
+'聝' => '毳',
+'聜' => '',
+'膉' => '瀰',
+'膆' => '櫬',
+'膃' => '鋺',
+'膇' => '瀾',
+'膍' => '獻',
+'膌' => '爐',
+'膋' => '瀲',
+'舕' => '儻',
+'蒗' => '歆',
+'蒤' => '尐\',
+'蒡' => '椯',
+'蒟' => '厹',
+'蒺' => '椲',
+'蓎' => '庀',
+'蓂' => '夯',
+'蒬' => '丼',
+'蒮' => '仜',
+'蒫' => '丱',
+'蒹' => '楻',
+'蒴' => '椼',
+'蓁' => '楴',
+'蓍' => '楌',
+'蒪' => '爿',
+'蒚' => '仈',
+'蒱' => '仡',
+'蓐' => '椻',
+'蒝' => '勼',
+'蒧' => '殳',
+'蒻' => '卌',
+'蒢' => '夃',
+'蒔' => '搌',
+'蓇' => '尻',
+'蓌' => '帄',
+'蒛' => '冘',
+'蒩' => '椿',
+'蒯' => '嵎',
+'蒨' => '塉',
+'蓖' => '敝',
+'蒘' => '仉',
+'蒶' => '刌',
+'蓏' => '庂',
+'蒠' => '圠',
+'蓗' => '氕',
+'蓔' => '戉',
+'蓒' => '忉',
+'蓛' => '',
+'蒰' => '仩',
+'蒑' => '丏',
+'虡' => '',
+'蜳' => '垵',
+'蜣' => '蟶',
+'蜨' => '評',
+'蝫' => '宨',
+'蝀' => '垔',
+'蜮' => '蠋',
+'蜞' => '蠉',
+'蜡' => '嶸',
+'蜙' => '哃',
+'蜛' => '茍',
+'蝃' => '垙',
+'蜬' => '咢',
+'蝁' => '垘',
+'蜾' => '蟼',
+'蝆' => '垕',
+'蜠' => '哖',
+'蜲' => '咰',
+'蜪' => '呰',
+'蜭' => '咾',
+'蜼' => '垝',
+'蜒' => '旄',
+'蜺' => '巍',
+'蜱' => '蠊',
+'蜵' => '垞',
+'蝂' => '垏',
+'蜦' => '哅',
+'蜧' => '哆',
+'蜸' => '垤',
+'蜤' => '咶',
+'蜚' => '蠆',
+'蜰' => '哞',
+'蜑' => '粥',
+'裷' => '峹',
+'裧' => '宭',
+'裱' => '鵏',
+'裲' => '峱',
+'裺' => '帩',
+'裾' => '鵙',
+'裮' => '峿',
+'裼' => '鵛',
+'裶' => '崀',
+'裻' => '帨',
+'裰' => '鵖',
+'裬' => '屔',
+'裫' => '屖',
+'覝' => '',
+'覡' => '膮',
+'覟' => '',
+'覞' => '',
+'觩' => '舁',
+'觫' => '髍',
+'觨' => '脀',
+'誫' => '捥',
+'誙' => '悰',
+'誋' => '庴',
+'誒' => '睎',
+'誏' => '弶',
+'誖' => '聜',
+'谽' => '閆',
+'豨' => '喨',
+'豩' => '喥',
+'賕' => '翯',
+'賏' => '揵',
+'賗' => '揓',
+'趖' => '猲',
+'踉' => '灄',
+'踂' => '舄',
+'跿' => '臷',
+'踍' => '菹',
+'跽' => '灊',
+'踊\' => '蚖',
+'踃' => '舼',
+'踇' => '艵',
+'踆' => '舿',
+'踅' => '齝',
+'跾' => '臮',
+'踀' => '臸',
+'踄' => '舽',
+'輐' => '愲',
+'輑' => '愮',
+'輎' => '慅',
+'輍' => '愫',
+'鄣' => '蛣',
+'鄜' => '逿',
+'鄠' => '',
+'鄢' => '蛦',
+'鄟' => '',
+'鄝' => '',
+'鄚' => '輋',
+'鄤' => '',
+'鄡' => '',
+'鄛' => '遒',
+'酺' => '嗿',
+'酲' => '鶢',
+'酹' => '鶞',
+'酳' => '嘄',
+'銥' => '瓵',
+'銤' => '',
+'鉶' => '緌',
+'銛' => '',
+'鉺' => '闀',
+'銠' => '闇',
+'銔' => '',
+'銪' => '闉',
+'銍' => '',
+'銦' => '霠',
+'銚' => '鵂',
+'銫' => '鴾',
+'鉹' => '綖',
+'銗' => '',
+'鉿' => '鞜',
+'銣' => '翵',
+'鋮' => '闃',
+'銎' => '鶳',
+'銂' => '翢',
+'銕' => '沺',
+'銢' => '',
+'鉽' => '綮',
+'銈' => '',
+'銡' => '',
+'銊' => '',
+'銆' => '',
+'銌' => '',
+'銙' => '',
+'銧' => '',
+'鉾' => '綩',
+'銇' => '',
+'銩' => '霙',
+'銝' => '',
+'銋' => '',
+'鈭' => '',
+'隞' => '蕛',
+'隡' => '蕮',
+'雿' => '',
+'靘' => '骻',
+'靽' => '堅',
+'靺' => '',
+'靾' => '',
+'鞃' => '',
+'鞀' => '婸',
+'鞂' => '',
+'靻' => '',
+'鞄' => '',
+'鞁' => '鷞',
+'靿' => '',
+'韎' => '璐',
+'韍' => '璫',
+'頖' => '裾',
+'颭' => '餯',
+'颮' => '鴝',
+'餂' => '',
+'餀' => '',
+'餇' => '',
+'馝' => '蹔',
+'馜' => '蹩',
+'駃' => '鎴',
+'馹' => '鎕',
+'馻' => '鎙',
+'馺' => '鎈',
+'駂' => '鎨',
+'馽' => '鐠',
+'駇' => '闓',
+'骱' => '鷚',
+'髣' => '溘',
+'髧' => '',
+'鬾' => '獼',
+'鬿' => '璺',
+'魠' => '',
+'魡' => '',
+'魟' => '',
+'鳱' => '鑞',
+'鳲' => '韄',
+'鳵' => '藈',
+'麧' => '',
+'僿' => 'w',
+'儃' => '{',
+'儰' => '',
+'僸' => 'q',
+'儆' => '棑',
+'儇' => '椥',
+'僶' => 'o',
+'僾' => 'v',
+'儋' => '棇',
+'儌' => '衝',
+'僽' => 'u',
+'儊' => '',
+'劋' => '誼',
+'劌' => '嵫',
+'勱' => '蛗',
+'勯' => '',
+'噈' => 'm',
+'噂' => 'g',
+'噌' => '颬',
+'嘵' => '萶',
+'噁' => '填',
+'噊' => 'o',
+'噉' => '遉',
+'噆' => 'k',
+'噘' => '雵',
+'噚' => 'x',
+'噀' => 'e',
+'嘳' => ']',
+'嘽' => 'c',
+'嘬' => '靸',
+'嘾' => 'd',
+'嘸' => '葝',
+'嘪' => 'X',
+'嘺' => 'a',
+'圚' => 'H',
+'墫' => '',
+'墝' => '',
+'墱' => '',
+'墠' => '',
+'墣' => '',
+'墯' => '',
+'墬' => '',
+'墥' => '',
+'墡' => '',
+'壿' => '',
+'嫿' => '',
+'嫴' => '',
+'嫽' => '',
+'嫷' => '',
+'嫶' => '',
+'嬃' => '',
+'嫸' => '',
+'嬂' => '',
+'嫹\' => '',
+'嬁' => '',
+'嬇' => '',
+'嬅' => '',
+'嬏' => '',
+'屧' => '',
+'嶙' => '戧',
+'嶗' => '彯',
+'嶟' => '',
+'嶒' => '',
+'嶢' => 'A',
+'嶓' => '',
+'嶕' => '',
+'嶠' => '廔',
+'嶜' => '',
+'嶡' => '@',
+'嶚' => '',
+'嶞' => '',
+'幩' => '',
+'幝' => '',
+'幠' => '',
+'幜' => '',
+'緳' => '',
+'廛' => '瘌',
+'廞' => 'Q',
+'廡' => '瑱',
+'彉' => '',
+'徲' => '',
+'憋' => '梧',
+'憃' => '樼',
+'慹' => '簐',
+'憱' => '',
+'憰' => '',
+'憢' => '',
+'憉' => 'u',
+'憛' => '',
+'憓' => '需',
+'憯' => '',
+'憭' => '樼',
+'憟' => '',
+'憒' => '蒮',
+'憪' => '',
+'憡' => '',
+'憍' => 'x',
+'慦' => 'W',
+'憳' => '',
+'戭' => '',
+'摮' => '',
+'摰' => '',
+'撖' => '稓',
+'撠' => '',
+'撅' => '橘',
+'撗' => '',
+'撜' => '',
+'撏' => '',
+'撋' => '',
+'撊' => '',
+'撌' => '',
+'撣' => '筆',
+'撟' => '睕',
+'摨' => '',
+'撱' => '',
+'撘' => '減',
+'敶' => '淝',
+'敺' => '',
+'敹' => '',
+'敻' => '',
+'斲' => '簀',
+'斳' => '',
+'暵' => '殲',
+'暰' => '',
+'暩' => '',
+'暲' => '',
+'暷' => '',
+'暪' => '',
+'暯' => '',
+'樀' => '',
+'樆' => '',
+'樗' => '橚',
+'槥' => '',
+'槸' => '',
+'樕' => '',
+'槱' => '',
+'槤' => '',
+'樠' => '',
+'槿' => '橛',
+'槬' => '',
+'槢' => '',
+'樛' => '',
+'樝' => '',
+'槾' => '頇',
+'樧' => '',
+'槲' => '橁',
+'槮' => '',
+'樔' => '',
+'槷' => '',
+'槧' => '噠',
+'橀' => '',
+'樈' => '',
+'槦' => '',
+'槻' => '',
+'樍' => '',
+'槼' => '寞',
+'槫' => '',
+'樉' => '',
+'樄' => '',
+'樘' => '樻',
+'樥' => '',
+'樏' => '',
+'槶' => '',
+'樦' => '',
+'樇' => '',
+'槴' => '',
+'樖' => '',
+'歑' => 'X',
+'殥' => '',
+'殣' => '',
+'殢' => '',
+'殦' => '',
+'氁' => '',
+'氀' => '',
+'毿' => '諤',
+'氂' => '',
+'潁' => '礗',
+'漦' => 'k',
+'潾' => '',
+'澇' => '殮',
+'濆' => '',
+'澒' => '',
+'澍' => '噌',
+'澉' => '噂',
+'澌' => '嘵',
+'潢' => '儆',
+'潏' => '',
+'澅' => '',
+'潚' => '僶',
+'澖' => '',
+'潶' => '',
+'潬' => '戽',
+'澂' => '割',
+'潕' => '',
+'潲' => '噊',
+'潒' => '',
+'潐' => '',
+'潗' => '',
+'澔' => '瘋',
+'澓' => '',
+'潝' => '',
+'漀' => 'N',
+'潡' => '',
+'潫' => '',
+'潽' => '',
+'潧' => '',
+'澐' => '',
+'潓' => '',
+'澋' => '',
+'潩' => '',
+'潿\' => '銇',
+'澕' => '',
+'潣' => '',
+'潷' => '鳵',
+'潪' => '',
+'潻' => '',
+'熲' => '',
+'熯' => '',
+'熛' => '',
+'熰' => '',
+'熠' => '嶷',
+'熚' => '',
+'熩' => '',
+'熵' => '寱',
+'熝' => '',
+'熥' => '',
+'熞' => '',
+'熤' => '',
+'熡' => '',
+'熪' => '',
+'熜' => '',
+'熧' => '',
+'熳' => '孻',
+'犘' => '',
+'犚' => '',
+'獘' => '教',
+'獒' => '殧',
+'獞' => '',
+'獟' => '',
+'獠' => '漜',
+'獝' => '',
+'獛' => '',
+'獡' => '',
+'獚' => '',
+'獙' => '',
+'獢' => '',
+'璇' => '霂',
+'璉' => '踤',
+'璊' => '胡',
+'璆' => '⑩',
+'璁' => '霈',
+'瑽' => '耑',
+'璅' => '坱',
+'璈' => '胄',
+'瑼' => '耍',
+'瑹' => '',
+'甈' => '娑',
+'甇' => '奚',
+'畾' => '',
+'瘥' => '蹖',
+'瘞' => '蹠',
+'瘙' => '蹧',
+'瘝' => '',
+'瘜' => '',
+'瘣' => '',
+'瘚' => '',
+'瘨' => '騍',
+'瘛' => '鞢',
+'皜' => '簬',
+'皝' => '',
+'皞' => '',
+'皛' => '謋',
+'瞍' => '謅',
+'瞏' => '深',
+'瞉' => '淫',
+'瞈' => '淚\',
+'磍' => '惻',
+'碻' => '',
+'磏' => '慨',
+'磌' => '惰',
+'磑' => '惱',
+'磎' => '惴',
+'磔' => '縻',
+'磈' => '愕',
+'磃' => '惠',
+'磄' => '愜',
+'磉' => '繄',
+'禚' => '檡',
+'禡' => '貽',
+'禠' => '貳',
+'禜' => '象',
+'禢' => '賁',
+'禛' => '詖',
+'歶' => 'u',
+'稹' => '臐',
+'窲' => '碗',
+'窴' => '沓',
+'窳' => '魌',
+'箷' => '',
+'篋' => '鵵',
+'箾' => '',
+'箬' => '鵩',
+'篎' => '慚',
+'箯' => '',
+'箹' => '',
+'篊' => '慢',
+'箵' => '',
+'糅' => '轖',
+'糈' => '轙',
+'糌' => '躈',
+'糋' => '嘮',
+'緷' => '',
+'緛' => '',
+'緪' => '',
+'緧' => '',
+'緗' => '蝵',
+'緡' => '褋',
+'縃' => '澦',
+'緺' => '',
+'緦' => '衚',
+'緶' => '褅',
+'緱' => '褌',
+'緰' => '',
+'緮' => '',
+'緟' => '',
+'罶' => '糜',
+'羬' => '臨',
+'羰' => '襣',
+'羭' => '舉',
+'翭' => '鴿',
+'翫' => '俙',
+'翪' => '鮪',
+'翬' => '鴻',
+'翦' => '醲',
+'翨' => '喔',
+'聤' => '',
+'聧' => '',
+'膣' => '錩',
+'膟' => '籍',
+'膞' => '籃',
+'膕' => '礬',
+'膢' => '辮',
+'膙' => '競',
+'膗' => '竇',
+'舖' => 'と',
+'艏' => '蘛',
+'艓' => '',
+'艒' => '',
+'艐' => '',
+'艎' => '',
+'艑' => '',
+'蔤' => '佖',
+'蔻' => '煍',
+'蔏' => '艼',
+'蔀' => '',
+'蔩' => '佤',
+'蔎' => '艸',
+'蔉' => '甪',
+'蔍' => '网',
+'蔟' => '毻',
+'蔊' => '癿',
+'蔧' => '佉',
+'蔜' => '邛',
+'蓻' => '眙',
+'蔫' => '殲',
+'蓺' => '',
+'蔈' => '玎',
+'蔌\' => '歂',
+'蓴' => '搎',
+'蔪' => '伾',
+'蓲' => '',
+'蔕' => '菱',
+'蓷' => '',
+'蓫' => '',
+'蓳' => '',
+'蓼' => '牏',
+'蔒' => '艽',
+'蓪' => '',
+'蓩' => '',
+'蔖' => '襾',
+'蓾' => '',
+'蔨' => '体',
+'蔝' => '邔',
+'蔮' => '佒',
+'蔂' => '',
+'蓽' => '塎',
+'蔞' => '楄',
+'蓶' => '',
+'蔱' => '佘',
+'蔦' => '嗂',
+'蓧' => '',
+'蓨' => '搵',
+'蓰' => '殛',
+'蓯' => '嗃',
+'蓹' => '',
+'蔘' => '邙',
+'蔠' => '阤',
+'蔰' => '佁',
+'蔋' => '穵',
+'蔙' => '邗',
+'蔯' => '佟',
+'虢' => '踳',
+'蝖' => '姺',
+'蝣' => '譐',
+'蝤' => '譊',
+'蝷' => '',
+'蟡' => '毠',
+'蝳' => '賟',
+'蝘' => '姽',
+'蝔' => '姱',
+'蝛' => '姶',
+'蝒' => '娀',
+'蝡' => '',
+'蝚' => '姼',
+'蝑' => '姮',
+'蝞' => '潃',
+'蝭' => '峐',
+'蝪' => '姭',
+'蝐' => '姞',
+'蝎' => '衎',
+'蝟' => '漎',
+'蝝' => '姲',
+'蝯' => '堀',
+'蝬' => '屌',
+'蝺' => '',
+'蝮' => '覷',
+'蝜' => '姤',
+'蝥' => '譓',
+'蝏' => '姡',
+'蝻' => '襘',
+'蝵' => '峛',
+'蝢' => '姳',
+'蝧' => '姠',
+'蝩' => '姴',
+'衚' => '苙',
+'褅' => '彧',
+'褌' => '',
+'褔' => '',
+'褋' => '',
+'褗' => '',
+'褘' => '',
+'褙' => '鵗',
+'褆' => '恝',
+'褖' => '',
+'褑' => '',
+'褎' => '凈',
+'褉' => '',
+'覢' => '笄',
+'覤' => '笅',
+'覣' => '笓',
+'觭' => '茳',
+'觰' => '荄',
+'觬' => '舥',
+'諏' => '睋',
+'諆' => '',
+'誸' => '掐',
+'諓' => '',
+'諑' => '睌',
+'諔' => '',
+'諕' => '',
+'誻' => '捵',
+'諗' => '硠',
+'誾' => '掮',
+'諀' => '掤',
+'諅' => '',
+'諘' => '',
+'諃' => '',
+'誺' => '掯',
+'誽' => '捭',
+'諙' => '',
+'谾' => '閈',
+'豍' => '馗',
+'貏' => '',
+'賥' => '敨',
+'賟' => '揙',
+'賙' => '揇',
+'賨' => '斝',
+'賚' => '羱',
+'賝' => '銵',
+'賧' => '耩',
+'趠' => '琫',
+'趜' => '琮',
+'趡' => '琖',
+'趛' => '猌',
+'踠' => '莿',
+'踣' => '爚',
+'踥' => '菥',
+'踤' => '菝',
+'踮' => '爝',
+'踕' => '菤',
+'踛' => '菫',
+'踖' => '菼',
+'踑' => '菨',
+'踙' => '菆',
+'踦' => '菘',
+'踧' => '菿',
+'踔' => '灈',
+'踒' => '萒',
+'踘' => '萐',
+'踓' => '菧',
+'踜' => '菣',
+'踗' => '菶',
+'踚' => '菈',
+'輬' => '',
+'輤' => '',
+'輘' => '酨',
+'輚' => '戥',
+'輠' => '廓',
+'輣' => '搤',
+'輖' => '慀',
+'輗' => '戠',
+'遳' => '腜',
+'遰' => '菰',
+'遯' => '嗜',
+'遧' => '羦',
+'遫' => '翛',
+'鄯' => '蛪',
+'鄫' => '',
+'鄩' => '',
+'鄪' => '',
+'鄲' => '策',
+'鄦' => '勍',
+'鄮' => '',
+'醅' => '鶿',
+'醆\' => '桮',
+'醊' => '墋',
+'醁' => '墐',
+'醂' => '墘',
+'醄' => '墁',
+'醀' => '塼',
+'鋐' => '輎',
+'鋃' => '龠',
+'鋄' => '跽',
+'鋀' => '踉',
+'鋙' => '鄤',
+'銶' => '誒',
+'鋏' => '闅',
+'鋱' => '麉',
+'鋟' => '儱',
+'鋘' => '鄚',
+'鋩' => '',
+'鋗' => '鄝',
+'鋝' => '鼤',
+'鋌' => '霝',
+'鋯' => '黚',
+'鋂' => '擿',
+'鋨' => '黻',
+'鋊' => '踅',
+'鋈' => '鶲',
+'鋎' => '輐',
+'鋦' => '儭',
+'鋍' => '毿',
+'鋕' => '鄢',
+'鋉' => '踆',
+'鋠' => '銥',
+'鋞' => '酹',
+'鋧' => '銪',
+'鋑' => '輍',
+'鋓' => '鄜',
+'銵' => '麍',
+'鋡' => '銤',
+'鋆' => '踃',
+'銴' => '誙',
+'镼' => '嬗',
+'閬' => '蓔',
+'閫' => '蒠',
+'閮' => '',
+'閰' => '',
+'隤' => '虰',
+'隢' => '蕵',
+'雓' => '螄',
+'霅' => '',
+'霈' => '鰬',
+'霂' => '',
+'靚' => '鬖',
+'鞊' => '',
+'鞎' => '',
+'鞈' => '',
+'韐' => '璭',
+'韏' => '璪',
+'頞' => '薂',
+'頝' => '薢',
+'頦' => '礞',
+'頩' => '螭',
+'頨' => '螪',
+'頠' => '薅',
+'頛' => '薝',
+'頧' => '螾',
+'颲' => '馣',
+'餈' => '躄',
+'飺' => '',
+'餑' => '熗',
+'餔' => '癜',
+'餖' => '癙',
+'餗' => '癐',
+'餕' => '癤',
+'駜' => '',
+'駍' => '雟',
+'駏' => '雝',
+'駓' => '鞬',
+'駔' => '糈',
+'駎' => '雘',
+'駉' => '隳',
+'駖' => '鞫',
+'駘' => '緧',
+'駋' => '雚',
+'駗' => '鞤',
+'駌' => '巂',
+'骳' => '鏂',
+'髬' => '',
+'髫' => '彏',
+'髳' => '巘',
+'髲' => '',
+'髱' => '╰',
+'魆' => '皪',
+'魃' => '鼵',
+'魧' => '',
+'魴' => '鼚',
+'魱' => '',
+'魦' => '',
+'魶' => '',
+'魵' => '',
+'魰' => '',
+'魨' => '',
+'魤' => '',
+'魬' => '',
+'鳼' => '鱐',
+'鳺' => '鱒',
+'鳽' => '鱊',
+'鳿' => '鱋\',
+'鳷' => '鬞',
+'鴇' => '藈',
+'鴀' => '鱕',
+'鳹' => '鬠',
+'鳻' => '鱘',
+'鴈' => '栜',
+'鴅' => '鷷',
+'鴄' => '鷻',
+'麃' => '栥',
+'黓' => ']',
+'鼏' => '',
+'鼐' => '媥',
+'儜' => '',
+'儓' => '',
+'儗' => '',
+'儚' => '',
+'儑' => '',
+'凞' => 'D',
+'匴' => 'W',
+'叡' => '謑',
+'噰' => '',
+'噠' => '蒎',
+'噮' => '',
+'噳' => '',
+'噦' => '葄',
+'噣' => '',
+'噭' => '',
+'噲' => '葮',
+'噞' => '{',
+'噷' => '',
+'圜' => '僝',
+'圛' => 'I',
+'壈' => '',
+'墽' => '',
+'壉' => '',
+'墿' => '',
+'墺' => '',
+'壂' => '',
+'墼' => '觚',
+'壆' => '',
+'嬗' => '窲',
+'嬙' => '禠',
+'嬛' => '',
+'嬡' => '磃',
+'嬔' => '',
+'嬓' => '',
+'嬐' => '',
+'嬖' => '窴',
+'嬨' => '',
+'嬚' => '',
+'嬠' => '',
+'嬞\' => '',
+'寯' => '',
+'嶬' => 'K',
+'嶱' => 'P',
+'嶩' => 'H',
+'嶧' => '廙',
+'嶵' => 'T',
+'嶰' => 'O',
+'嶮' => '玸',
+'嶪' => 'I',
+'嶨' => '嵼',
+'嶲' => 'Q',
+'嶭' => 'L',
+'嶯' => 'N',
+'嶴' => '嵼',
+'幧' => '',
+'幨' => '',
+'幦' => '',
+'幯' => '',
+'廩' => '瘑',
+'廧' => 'Z',
+'廦' => 'Y',
+'廨' => '瘕',
+'廥' => 'X',
+'彋' => '',
+'徼' => '摜',
+'憝' => '磾',
+'憨' => '漫',
+'憖' => '',
+'懅' => '',
+'憴' => '',
+'懆' => '',
+'懁' => '',
+'懌' => '禘',
+'憺' => '',
+'憿' => '',
+'憸' => '',
+'憌' => 'w',
+'擗' => '艅',
+'擖' => '',
+'擐' => '艂',
+'擏' => 'э',
+'擉' => '',
+'撽' => '',
+'撉' => '',
+'擃' => '',
+'擛' => '@',
+'擳' => 'T',
+'擙' => '',
+'攳' => '',
+'敿' => '',
+'敼' => '',
+'斢' => '',
+'曈' => '',
+'暾' => '縕',
+'曀' => '',
+'曊' => '',
+'曋' => '',
+'曏' => '砃',
+'暽' => '',
+'暻' => '',
+'暺' => '',
+'曌' => '',
+'朣' => 'S',
+'樴' => '',
+'橦' => 'H',
+'橉' => '',
+'橧' => 'I',
+'樲' => '',
+'橨' => 'J',
+'樾' => '橤',
+'橝' => 'A',
+'橭' => 'O',
+'橶' => 'W',
+'橛' => '橔',
+'橑' => '',
+'樨' => '橞',
+'橚' => '',
+'樻' => '',
+'樿' => '',
+'橁' => '',
+'橪' => 'L',
+'橤' => '',
+'橐' => '橏',
+'橏' => '',
+'橔' => '',
+'橯' => 'Q',
+'橩' => 'K',
+'橠' => 'D',
+'樼' => '',
+'橞' => 'B',
+'橖' => '',
+'橕' => '傅',
+'橍' => '',
+'橎' => '',
+'橆' => '拸',
+'歕' => '\\',
+'歔' => '[',
+'歖' => ']',
+'殧' => '',
+'殪' => '濇',
+'殫' => '澭',
+'毈' => '',
+'毇' => '',
+'氄' => '',
+'氃' => '',
+'氆' => '諞',
+'澭' => '',
+'濋' => '',
+'澣' => '雿',
+'濇' => '优',
+'澼' => '',
+'濎' => '',
+'濈' => '',
+'潞' => '繙',
+'濄' => '',
+'澽' => '',
+'澞' => '',
+'濊' => '魁',
+'澨' => '',
+'瀄' => '\\',
+'澥' => '',
+'澮' => '銕',
+'澺' => '',
+'澬' => '',
+'澪' => '',
+'濏' => '',
+'澿' => '',
+'澸' => '',
+'澢' => '',
+'濉' => '憛',
+'澫' => '驕',
+'濍' => '',
+'澯' => '',
+'澲' => '',
+'澰' => '',
+'燅' => '',
+'燂' => '',
+'熿' => '銓',
+'熸' => '',
+'燖' => '@',
+'燀' => '',
+'燁' => '嚂',
+'燋' => '',
+'燔' => '幪',
+'燊' => '',
+'燇' => '',
+'燏' => '',
+'熽' => '',
+'燘' => 'B',
+'熼' => '',
+'燆' => '',
+'燚' => 'D',
+'燛' => 'E',
+'犝' => '',
+'犞' => '',
+'獩' => '',
+'獦\' => '',
+'獧' => '朄',
+'獬' => '滼',
+'獥' => '',
+'獫' => '榶',
+'獪' => '暡',
+'瑿' => '耶',
+'璚' => '⑤',
+'璠' => '茉',
+'璔' => '舢',
+'璒' => '胝',
+'璕' => '苧',
+'璡' => '苒\',
+'甋' => '娟',
+'疀' => '',
+'瘯' => '',
+'瘭' => '韘',
+'瘱' => '',
+'瘽' => '',
+'瘳' => '饁',
+'瘼' => '鞥',
+'瘵' => '顑',
+'瘲' => '',
+'瘰' => '韺',
+'皻' => '觾',
+'盦' => '屝',
+'瞚' => '烹',
+'瞝' => '烽',
+'瞡' => '爽',
+'瞜' => '焊',
+'瞛' => '焉',
+'瞢' => '獂',
+'瞣' => '牽',
+'瞕' => '淄',
+'瞙' => '淦',
+'瞗' => '淬',
+'磝' => '掌',
+'磩' => '',
+'磥' => '濠',
+'磪' => '',
+'磞' => '描',
+'磣' => '繉',
+'磛' => '扉',
+'磡' => '揉',
+'磢' => '揆',
+'磭' => '',
+'磟' => '繕',
+'磠' => '揩',
+'禤' => '賀',
+'穄' => '愍',
+'穈' => '戡',
+'穇' => '愷',
+'窶' => '魊',
+'窸' => '碑',
+'窵' => '碌',
+'窱' => '碰',
+'窷' => '硼',
+'篞' => '摑',
+'篣' => '摻',
+'篧' => '斡',
+'篝' => '黀',
+'篕' => '摘',
+'篥' => '鼭',
+'篚' => '黼',
+'篨' => '旗',
+'篹' => '榷',
+'篔' => '撇',
+'篪' => '齁',
+'篢' => '摭',
+'篜' => '摺',
+'篫' => '暢',
+'篘' => '摸',
+'篟' => '摧',
+'糒' => '嘴',
+'糔' => '噓',
+'糗' => '轗',
+'糐' => '嘲',
+'糑' => '嘿',
+'縒' => '獨',
+'縡' => '瞞',
+'縗' => '璞\',
+'縌' => '熹',
+'縟' => '褙',
+'縠' => '瞠',
+'縓' => '璜',
+'縎' => '燙',
+'縜' => '瘸',
+'縕' => '璘',
+'縚' => '昐',
+'縢' => '瞟',
+'縋' => '褔',
+'縏' => '燜',
+'縖' => '璟',
+'縍' => '燎',
+'縔' => '璣',
+'縥' => '磚',
+'縤' => '磨',
+'罃' => '',
+'罻' => '糙',
+'罼' => '救',
+'罺' => '糟',
+'羱' => '薪',
+'翯' => '麋',
+'耪' => '纓',
+'耩' => '嚫',
+'聬' => '',
+'膱' => '',
+'膦' => '鮈',
+'膮' => '',
+'膹' => '',
+'膵' => '',
+'膫' => '',
+'膰' => '',
+'膬' => '毯',
+'膴' => '',
+'膲' => '',
+'膷' => '',
+'膧' => '',
+'臲' => '驃',
+'艕' => '',
+'艖' => '',
+'艗' => '',
+'蕖' => '煄',
+'蕅' => '匉',
+'蕫' => '',
+'蕍' => '吰',
+'蕓' => '傺',
+'蕡' => '',
+'蕘' => '塕',
+'蕀' => '刞',
+'蕆' => '椳',
+'蕤' => '犐',
+'蕁' => '搳',
+'蕢' => '棰',
+'蕄' => '劮',
+'蕑' => '呅',
+'蕇' => '卲',
+'蕣' => '',
+'蔾' => '冹',
+'蕛' => '',
+'蕱' => '',
+'蕎' => '塱',
+'蕮' => '',
+'蕵' => '',
+'蕕' => '搧',
+'蕧' => '',
+'蕠' => '',
+'薌' => '僂',
+'蕦' => '',
+'蕝' => '',
+'蕔' => '吥',
+'蕥' => '',
+'蕬' => '',
+'虣' => '',
+'虥' => '',
+'虤' => '',
+'螛' => '',
+'螏\' => '',
+'螗' => '韞',
+'螓' => '譖',
+'螒' => '',
+'螈' => '鞷',
+'螁' => '',
+'螖' => '',
+'螘' => '眐',
+'蝹' => '',
+'螇' => '',
+'螣' => '',
+'螅' => '鞶',
+'螐' => '',
+'螑' => '',
+'螝' => '',
+'螄' => '藲',
+'螔' => '',
+'螜' => '',
+'螚' => '',
+'螉' => '',
+'褞' => '',
+'褦' => '',
+'褰' => '敶',
+'褭' => '蘅',
+'褮' => '',
+'褧' => '',
+'褱' => '',
+'褢' => '',
+'褩' => '',
+'褣' => '',
+'褯' => '',
+'褬' => '',
+'褟' => '',
+'觱' => '茙',
+'諠' => '唈',
+'諢' => '睇',
+'諲' => '烰',
+'諴' => '烳',
+'諵' => '焐',
+'諝' => '',
+'謔' => '硱',
+'諤' => '确',
+'諟' => '',
+'諰' => '烴',
+'諈' => '',
+'諞' => '祴',
+'諡' => '',
+'諨' => '淗',
+'諿' => '焎',
+'諯' => '焗',
+'諻' => '烸',
+'貑' => '',
+'貒' => '',
+'貐' => '',
+'賵' => '',
+'賮' => '',
+'賱' => '',
+'賰' => '',
+'賳' => '',
+'赬' => '焠',
+'赮' => '焞',
+'趥' => '',
+'趧' => '',
+'踳' => '菉',
+'踾' => '菳',
+'踸' => '萑',
+'蹀' => '甗',
+'蹅' => '',
+'踶' => '萏',
+'踼' => '菂',
+'踽' => '礭',
+'蹁' => '籔',
+'踰' => '貣',
+'踿' => '',
+'躽' => '閍',
+'輶' => '',
+'輮' => '',
+'輵' => '',
+'輲' => '',
+'輹' => '',
+'輷' => '箔',
+'輴' => '',
+'遶' => '',
+'遹' => '腲',
+'遻' => '腞',
+'邆' => '',
+'郺' => '趏',
+'鄳' => '',
+'鄵' => '',
+'鄶' => '萓',
+'醓' => '墑',
+'醐' => '鶩',
+'醑' => '鶦',
+'醍' => '鶖',
+'醏' => '墇',
+'錧' => '嬁',
+'錞' => '檴',
+'錈' => '屪',
+'錟' => '巀',
+'錆' => '嚘',
+'錏' => '嘾',
+'鍺' => '淀',
+'錸' => '麊',
+'錼' => '緳',
+'錛' => '嚗',
+'錣' => '嬃',
+'錒' => '儮',
+'錁' => '嚝',
+'鍆' => '鎡',
+'錭' => '嶗',
+'錎' => '嘬',
+'錍' => '嘽',
+'鋋' => '跾',
+'錝' => '壿',
+'鋺' => '',
+'錥' => '嬂',
+'錓' => '圚',
+'鋹' => '',
+'鋷' => '',
+'錴' => '嶜',
+'錂' => '',
+'錤' => '嫸',
+'鋿' => '',
+'錩' => '嬅',
+'錹' => '幝',
+'錵' => '嶡',
+'錪' => '嬏',
+'錔' => '墫',
+'錌' => '嘳',
+'錋' => '噀',
+'鋾' => '',
+'錉' => '',
+'錀' => '',
+'鋻' => '',
+'錖' => '墱',
+'閼' => '蜳',
+'闍' => '濉',
+'閾' => '蓒',
+'閹' => '捀',
+'閺' => '',
+'閶' => '蓛',
+'閿' => '蒑',
+'閵' => '',
+'閽' => '虡',
+'隩' => '蕝',
+'雔' => '螔',
+'霋' => '',
+'霒' => '秝',
+'霐' => '',
+'鞙' => '',
+'鞗' => '',
+'鞔' => '鰲',
+'韰' => '',
+'韸' => '',
+'頵' => '螷',
+'頯' => '螼',
+'頲' => '蟃',
+'餤\' => '礉',
+'餟' => '瞺',
+'餧' => '庣',
+'餩' => '禬',
+'馞' => '轆',
+'駮' => '眶',
+'駬' => '',
+'駥' => '',
+'駤' => '',
+'駰' => '',
+'駣' => '',
+'駪' => '',
+'駩' => '',
+'駧' => '',
+'骹' => '鏹',
+'骿' => '錧',
+'骴' => '鏚',
+'骻' => '輯',
+'髶' => '',
+'髺' => '',
+'髹' => '戄',
+'髷' => '',
+'鬳' => '瀹',
+'鮀' => '鐆',
+'鮅' => '霯',
+'鮇' => '鞻',
+'魼' => '齤',
+'魾' => '鏶',
+'魻' => '',
+'鮂' => '闠',
+'鮓' => '饌',
+'鮒' => '亹',
+'鮐' => '囅',
+'魺' => '',
+'鮕' => '饓',
+'魽' => '鐌',
+'鮈' => '韽',
+'鴥' => '',
+'鴗' => '黂',
+'鴠' => '齃',
+'鴞' => '鼷',
+'鴔' => '鷳',
+'鴩' => '',
+'鴝' => '蘤',
+'鴘' => '黐',
+'鴢' => '',
+'鴐' => '鷰',
+'鴙' => '黲',
+'鴟' => '薸',
+'麈' => '爢',
+'麆' => '',
+'麇' => '灚',
+'麮' => 'C',
+'麭' => '婦',
+'黕' => '^',
+'黖' => '_',
+'黺' => 'v',
+'鼒' => '',
+'鼽' => '襴',
+'儦' => '',
+'儥' => '',
+'儢' => '',
+'儤' => '',
+'儠' => '',
+'儩' => '',
+'勴' => '',
+'嚓' => '魛',
+'嚌' => '蜋',
+'嚍' => '',
+'嚆' => '飹',
+'嚄' => '',
+'嚃' => '',
+'噾' => '',
+'嚂' => '',
+'噿' => '',
+'嚁' => '',
+'壖' => '',
+'壔' => '',
+'壏' => '',
+'壒' => '',
+'嬭' => '騷',
+'嬥' => '',
+'嬲' => '窳',
+'嬣' => '',
+'嬬' => '',
+'嬧' => '',
+'嬦' => '',
+'嬯' => '',
+'嬮' => '',
+'孻' => 'Y',
+'寱' => '蔇',
+'寲' => '',
+'嶷' => '摍',
+'幬' => '僯',
+'幪' => '',
+'徾' => '',
+'徻' => '',
+'懃' => 'с',
+'憵' => '',
+'憼' => '',
+'懧' => '',
+'懠' => '',
+'懥' => '',
+'懤' => '',
+'懨' => '禖',
+'懞' => '蟹',
+'擯' => '梔',
+'擩' => '絲',
+'擣' => 'F',
+'擫' => 'L',
+'擤' => '蓱',
+'擨' => 'I',
+'斁' => '',
+'斀' => '',
+'斶' => '',
+'旚' => '',
+'曒' => '',
+'檍' => 'j',
+'檖' => 'p',
+'檁' => '橆',
+'檥' => '纀',
+'檉' => '魵',
+'檟' => 'x',
+'檛' => 't',
+'檡' => 'y',
+'檞' => 'w',
+'檇' => 'd',
+'檓' => 'm',
+'檎' => '橩',
+'檕' => 'o',
+'檃' => 'a',
+'檨' => '',
+'檤' => '|',
+'檑' => '橍',
+'橿' => '^',
+'檦' => '~',
+'檚' => 's',
+'檅' => 'b',
+'檌' => 'i',
+'檒' => 'l',
+'歛' => '螻',
+'殭' => '蔗',
+'氉' => '',
+'濌' => '',
+'澩' => '穘',
+'濴' => 'L',
+'濔' => '譆',
+'濣' => '',
+'濜' => '',
+'濭' => 'G',
+'濧' => 'A',
+'濦' => '@',
+'濞' => '憡',
+'濲' => 'J',
+'濝' => '',
+'濢' => '',
+'濨' => 'B',
+'燡\' => 'J',
+'燱' => 'W',
+'燨' => 'O',
+'燲' => 'X',
+'燤' => 'M',
+'燰' => 'V',
+'燢' => 'K',
+'獳' => '隹',
+'獮' => '',
+'獯' => '漺',
+'璗' => '茅',
+'璲' => '虻',
+'璫' => '苞',
+'璐' => '韐',
+'璪' => '苑',
+'璭' => '苟',
+'璱' => '虹',
+'璥' => '苜',
+'璯' => '茆',
+'甐' => '姬',
+'甑' => '窱',
+'甒' => '娠',
+'甏' => '窵',
+'疄' => '',
+'癃' => '顒',
+'癈' => '煙',
+'癉' => '蹜',
+'癇' => '豵',
+'皤' => '薽',
+'盩' => '崎',
+'瞵' => '謈',
+'瞫' => '猖',
+'瞲' => '琊',
+'瞷' => '現',
+'瞶' => '理',
+'瞴' => '球',
+'瞱' => '琅',
+'瞨' => '猛',
+'矰' => '蛇',
+'磳' => '',
+'磽' => '簐',
+'礂' => '',
+'磻' => '',
+'磼' => '',
+'磲' => '罅',
+'礅' => '罿',
+'磹' => '',
+'磾' => '',
+'礄' => '',
+'禫' => '越',
+'禨' => '貶',
+'穜' => '斟',
+'穛' => '敬',
+'穖' => '搶',
+'穘' => '搖',
+'穔' => '搔',
+'穚' => '搆',
+'窾' => '萬',
+'竀' => '禽',
+'竁' => '稜',
+'簅' => '榣',
+'簏' => '齘',
+'篲' => '榕',
+'簀' => '鵴',
+'篿' => '槐',
+'篻' => '榫',
+'簎' => '滾',
+'篴' => '榮',
+'簋' => '嚲',
+'篳' => '鶁',
+'簂' => '槌',
+'簉' => '氳',
+'簃' => '榦',
+'簁' => '榭',
+'篸' => '榛',
+'篽' => '榴',
+'簆' => '歉',
+'篰' => '榨',
+'篱' => '燦',
+'簐' => '漓',
+'簊' => '漳',
+'糨' => '轕',
+'縭' => '褖',
+'縼' => '',
+'繂' => '',
+'縳' => '篛',
+'顈' => '覭',
+'縸' => '糖',
+'縪' => '穎',
+'繉' => '',
+'繀' => '',
+'繇' => '鏾',
+'縩' => '積',
+'繌' => '',
+'縰' => '簑',
+'縻' => '毊',
+'縶' => '鐠',
+'繄' => '',
+'縺' => '',
+'罅' => '髂',
+'罿' => '績',
+'罾' => '轃',
+'罽' => '縮',
+'翴' => '點',
+'翲' => '黏',
+'耬' => '厴',
+'膻' => '錌',
+'臄' => '',
+'臌' => '錵',
+'臊' => '錔',
+'臅' => '',
+'臇' => '',
+'膼' => '',
+'臩' => '露',
+'艛' => '',
+'艚' => '蘀',
+'艜' => '',
+'薃' => '杕',
+'薀' => '堄',
+'薏' => '瑊',
+'薧' => '灴',
+'薕' => '沋',
+'薠' => '沜',
+'薋' => '杚',
+'薣' => '汥',
+'蕻' => '獀',
+'薤' => '獊',
+'薚' => '沚',
+'薞' => '沇',
+'蕷' => '歃',
+'蕼' => '',
+'薉' => '韶',
+'薡' => '汦',
+'蕺' => '猼',
+'蕸' => '',
+'蕗' => '',
+'薎' => '氙',
+'薖' => '沏',
+'薆' => '杌',
+'薍' => '毐',
+'薙' => '殀',
+'薝' => '汭',
+'薁' => '',
+'薢' => '汳',
+'薂' => '杙',
+'薈' => '媺',
+'薅' => '瑗',
+'蕹' => '瑋',
+'蕶' => '',
+'薘' => '汯',
+'薐' => '氚',
+'薟' => '搚',
+'虨' => '',
+'螾' => '翽',
+'螪' => '柀',
+'螭' => '韝',
+'蟅' => '枲',
+'螰\' => '柅',
+'螬' => '顝',
+'螹' => '柷',
+'螵' => '顗',
+'螼' => '柮',
+'螮' => '枷',
+'蟉' => '柭',
+'蟃' => '柧',
+'蟂' => '柎',
+'蟌' => '柌',
+'螷' => '柍',
+'螯' => '譔',
+'蟄' => '殎',
+'蟊' => '饃',
+'螴' => '柟',
+'螶' => '枵',
+'螿' => '柂',
+'螸' => '枳',
+'螽' => '颾',
+'蟞' => '毖',
+'螲' => '柤',
+'褵' => '褖',
+'褳' => '鮹',
+'褼' => '氥',
+'褾' => '浣',
+'襁' => '麌',
+'襒' => '涗',
+'褷' => '',
+'襂' => '洍',
+'覭' => '粊',
+'覯' => '膫',
+'覮' => '粌',
+'觲' => '荑',
+'觳' => '麮',
+'謞' => '琈',
+'謘' => '珺',
+'謖' => '祰',
+'謑' => '珸',
+'謅' => '粘',
+'謋' => '猈',
+'謢' => '痒',
+'謏' => '玈',
+'謒' => '珵',
+'謕' => '珽',
+'謇' => '敻',
+'謍' => '猏',
+'謈' => '猑',
+'謆' => '猇',
+'謜' => '琋',
+'謓' => '琄',
+'謚' => '稂',
+'豏' => '傕',
+'豰' => '喓',
+'豲' => '喏',
+'豱' => '喈',
+'豯' => '喢',
+'貕' => '',
+'貔' => '蘮',
+'賹' => '',
+'赯' => '焯',
+'蹎' => '',
+'蹍' => '',
+'蹓' => '槧',
+'蹐' => '',
+'蹌' => '囃',
+'蹇' => '敹',
+'轃' => '',
+'轀' => '',
+'邅' => '',
+'遾' => '腧',
+'鄸' => '',
+'醚' => '識',
+'醢' => '鶧',
+'醛' => '',
+'醙' => '墔',
+'醟' => '嫜',
+'醡' => '嫥',
+'醝' => '壾',
+'醠' => '嫮',
+'鎡' => '犚',
+'鎃' => '潧',
+'鎯' => '',
+'鍤' => '懮',
+'鍖' => '',
+'鍇' => '懘',
+'鍼' => '渀',
+'鍘' => '捸',
+'鍜' => '',
+'鍶' => '懟',
+'鍉' => '憉',
+'鍐' => '',
+'鍑' => '',
+'鍠' => '',
+'鍭' => '澉',
+'鎏' => '黮',
+'鍌' => '',
+'鍪' => '麜',
+'鍹' => '潒',
+'鍗' => '',
+'鍕' => '',
+'鍒' => '',
+'鍏' => '',
+'鍱' => '澅',
+'鍷' => '潕',
+'鍻' => '潗',
+'鍡' => '',
+'鍞' => '',
+'鍣' => '',
+'鍧' => '',
+'鎀' => '潡',
+'鍎' => '',
+'鍙' => '',
+'闇' => '做',
+'闀' => '箏',
+'闉' => '',
+'闃' => '蜣',
+'闅' => '',
+'閷' => '',
+'隮' => '欀',
+'隰' => '絜',
+'隬' => '蕬',
+'霠' => '',
+'霟' => '',
+'霘' => '',
+'霝' => '',
+'霙' => '',
+'鞚' => '',
+'鞡' => '亃',
+'鞜' => '蝝',
+'鞞' => '檕',
+'鞝' => '',
+'韕' => '甑',
+'韔' => '甐',
+'韱' => '',
+'顁' => '褳',
+'顄' => '襁',
+'顊' => '覮',
+'顉' => '覯',
+'顅' => '襒',
+'顃' => '褾',
+'餥' => '礐',
+'餫' => '簜',
+'餬' => '緇',
+'餪' => '穟',
+'餳' => '熉',
+'餲' => '簝',
+'餯' => '簠',
+'餭' => '簙',
+'餱' => '躆',
+'餰' => '簟',
+'馘' => '毳',
+'馣' => '鄺',
+'馡' => '轋',
+'騂' => '斄',
+'駺' => '徿',
+'駴' => '',
+'駷' => '',
+'駹\' => '',
+'駸' => '',
+'駶' => '',
+'駻' => '懻',
+'駽' => '攐',
+'駾' => '攍',
+'駼' => '攇',
+'騃' => '渭',
+'骾' => '攠',
+'髾' => '',
+'髽' => '',
+'鬁' => '',
+'髼' => '',
+'魈' => '齂',
+'鮚' => '奱',
+'鮨' => '鯷',
+'鮞' => '孌',
+'鮛' => '騶',
+'鮦' => '鰋',
+'鮡' => '髊',
+'鮥' => '鬑',
+'鮤' => '鬒',
+'鮆' => '巕',
+'鮢' => '髆',
+'鮠' => '髇',
+'鮯' => '鰆',
+'鴳' => '',
+'鵁' => '',
+'鵧' => '黵',
+'鴶' => '',
+'鴮' => '',
+'鴯' => '薾',
+'鴱' => '',
+'鴸' => '',
+'鴰' => '蟧',
+'鵅' => '纙',
+'鵂' => '蟦',
+'鵃' => 'b',
+'鴾' => '',
+'鴷' => '',
+'鵀' => '',
+'鴽' => '',
+'翵' => '黜',
+'鴭' => '',
+'麊' => '',
+'麉' => '',
+'麍' => '',
+'麰' => 'E',
+'黈' => 'W',
+'黚' => 'b',
+'黻' => '臌',
+'黿' => '鶵',
+'鼤' => '',
+'鼣' => '',
+'鼢' => '蠰',
+'齔' => '鶶',
+'龠' => '殗',
+'儱' => '',
+'儭' => '',
+'儮' => '',
+'嚘' => '',
+'嚜' => '',
+'嚗' => '',
+'嚚' => '',
+'嚝' => '',
+'嚙' => '蘚',
+'奰' => '`',
+'嬼' => '',
+'屩' => '',
+'屪' => '',
+'巀' => '^',
+'幭' => '',
+'幮' => '',
+'懘' => '',
+'懟' => '瞴',
+'懭' => '',
+'懮' => '',
+'懱' => '',
+'懪' => '',
+'懰' => '',
+'懫' => '',
+'懖' => '',
+'懩' => '欭',
+'擿' => '祣',
+'攄' => '祼',
+'擽' => '^',
+'擸' => 'Y',
+'攁' => 'a',
+'攃' => 'c',
+'擼' => '舝',
+'斔' => '',
+'旛' => '',
+'曚' => '',
+'曛' => '縚',
+'曘' => '',
+'櫅' => '',
+'檹' => '',
+'檽' => '',
+'櫡' => '',
+'櫆' => '',
+'檺' => '',
+'檶' => '',
+'檷' => '',
+'櫇' => '',
+'檴' => '鳹',
+'檭' => '',
+'歞' => 'd',
+'毉' => '瓟',
+'氋' => '',
+'瀇' => '_',
+'瀌' => 'd',
+'瀍' => 'e',
+'瀁' => 'Y',
+'瀅' => '鬿',
+'瀔' => 'k',
+'瀎' => 'f',
+'濿' => 'W',
+'瀀' => 'X',
+'濻' => 'S',
+'瀦' => '劌',
+'濼' => '裲',
+'濷' => 'O',
+'瀊' => 'b',
+'爁' => 'f',
+'燿' => '珓',
+'燹' => '徻',
+'爃' => 'h',
+'燽' => 'b',
+'獶' => '非',
+'璸' => '計',
+'瓀' => '趴',
+'璵' => '衫',
+'瓁' => '軍',
+'璾' => '赴',
+'璶' => '要',
+'璻' => '訃',
+'瓂' => '軌',
+'甔' => '娣',
+'甓' => '窷',
+'癜' => '騋',
+'癤' => '謣',
+'癙' => '訐',
+'癐' => '衰',
+'癓' => '袂',
+'癗' => '衹',
+'癚' => '討',
+'皦' => '',
+'皽' => '',
+'盬' => '崢',
+'矂' => '',
+'瞺' => '瓶',
+'磿' => '',
+'礌' => '濠',
+'礓' => '罽',
+'礔' => '羈',
+'礉' => '',
+'礐' => '湣',
+'礒\' => '湲',
+'礑' => '湄',
+'禭' => '趁',
+'禬' => '超',
+'穟' => '暉',
+'簜' => '',
+'簩' => '',
+'簙' => '漢',
+'簠' => '',
+'簟' => '禲',
+'簭' => '',
+'簝' => '',
+'簦' => '穬',
+'簨' => '',
+'簢' => '',
+'簥' => '',
+'簰' => '鵻',
+'繜' => '',
+'繐' => '',
+'繖' => '氶',
+'繣' => '錙',
+'繘' => '',
+'繢' => '蝩',
+'繟' => '錦',
+'繑' => '',
+'繠' => '錡',
+'繗' => '',
+'繓' => '',
+'羵' => '',
+'羳' => '',
+'翷' => '黛',
+'翸' => '鼾',
+'聵' => '夒',
+'臑' => '',
+'臒' => '',
+'臐' => '',
+'艟' => '藶',
+'艞' => '',
+'薴' => '犺',
+'藆' => '肙',
+'藀' => '疕',
+'藃' => '礽',
+'藂' => '椒',
+'薳' => '狁',
+'薵' => '狅',
+'薽' => '町',
+'藇' => '歃',
+'藄' => '耴',
+'薿' => '疔',
+'藋' => '芐',
+'藎' => '搟',
+'藈' => '肒',
+'藅' => '肕',
+'薱' => '狃',
+'薶' => '鎚',
+'藒' => '芓',
+'蘤' => '岪',
+'薸' => '玗',
+'薷' => '瑏',
+'薾' => '甹',
+'虩' => '',
+'蟧' => '洭',
+'蟦' => '洴',
+'蟢' => '氠',
+'蟛' => '馦',
+'蟫' => '洿',
+'蟪' => '馧',
+'蟥' => '顙',
+'蟟' => '毘',
+'蟳' => '洺',
+'蟤' => '洨',
+'蟔' => '柉',
+'蟜' => '殄',
+'蟓' => '颻',
+'蟭' => '洊',
+'蟘' => '柋',
+'蟣' => '繸',
+'螤' => '',
+'蟗' => '柪',
+'蟙' => '欨',
+'蠁' => '',
+'蟴' => '洚',
+'蟨' => '洟',
+'蟝' => '殶',
+'襓' => '浰',
+'襋' => '涍',
+'襏' => '浞',
+'襌' => '淯',
+'襆' => '嵽',
+'襐' => '浧',
+'襑' => '浠',
+'襉' => '鵓',
+'謪' => '',
+'謧' => '',
+'謣' => '痏',
+'謳' => '琠',
+'謰' => '',
+'謵' => '',
+'譇' => '耛',
+'謯' => '逡',
+'謼' => '網',
+'謾' => '獺',
+'謱' => '',
+'謥' => '',
+'謷' => '',
+'謦' => '鬘',
+'謶' => '',
+'謮' => '裞',
+'謤' => '',
+'謻' => '',
+'謽' => '',
+'謺' => '',
+'豂' => '陫',
+'豵' => '喁',
+'貙' => '',
+'貘' => '蘧',
+'貗' => '',
+'賾' => '寔',
+'贄' => '縤',
+'贂' => '',
+'贀' => '',
+'蹜' => '',
+'蹢' => '爙',
+'蹠' => '嚽',
+'蹗' => '',
+'蹖' => '',
+'蹞' => '爙',
+'蹥' => '',
+'蹧' => '媎',
+'蹛' => '',
+'蹚' => '昋',
+'蹡' => '',
+'蹝' => '樖',
+'蹩' => '龑',
+'蹔' => '',
+'轆' => '磥',
+'轇' => '毸',
+'轈' => '溛',
+'轋' => '溏',
+'鄨' => '',
+'鄺' => '絔',
+'鄻' => '',
+'鄾' => '',
+'醨' => '嫫',
+'醥' => '嫪',
+'醧' => '嫭',
+'醯' => '黤',
+'醪' => '麛',
+'鎵' => '斔',
+'鎌' => '蟑',
+'鎒' => '嚭',
+'鎷' => '',
+'鎛' => '熡',
+'鎝' => '嚚',
+'鎉' => '澕',
+'鎧' => '霟',
+'鎎' => '熲',
+'鎪\' => '懱',
+'鎞' => '熧',
+'鎦' => '攃',
+'鎕' => '熩',
+'鎈' => '潿\',
+'鎙' => '熞',
+'鎟' => '熳',
+'鎍' => '潻',
+'鎱' => '',
+'鎑' => '熛',
+'鎲' => '',
+'鎤' => '獞',
+'鎨' => '獛',
+'鎴' => '',
+'鎣' => '獒',
+'鎥' => '獟',
+'闒' => '澰',
+'闓' => '燅',
+'闑' => '澲',
+'隳' => '蓌',
+'雗' => '螚',
+'雚' => '褦',
+'巂' => '`',
+'雟' => '褱',
+'雘' => '螉',
+'雝' => '褮',
+'霣' => '錉',
+'霢' => '鋾',
+'霥' => '鋻',
+'鞬' => '歛',
+'鞮' => '殭',
+'鞨' => '檅',
+'鞫' => '鰶',
+'鞤' => '檑',
+'鞪' => '檒',
+'鞢' => '檤',
+'鞥' => '橿',
+'韗' => '甏',
+'韙' => '頦',
+'韖' => '甒',
+'韘' => '疄',
+'韺' => '',
+'顐' => '睇',
+'顑' => '',
+'顒' => '',
+'颸' => '駹\',
+'饁' => '繗',
+'餼' => '熅',
+'餺' => '繖',
+'騏' => '緦',
+'騋' => '櫋',
+'騉' => '櫑',
+'騍' => '緶',
+'騄' => '旝',
+'騑' => '櫍',
+'騊' => '櫙',
+'騅' => '緱',
+'騇' => '櫠',
+'騆' => '櫧',
+'髀' => '鷘',
+'髜' => '霦',
+'鬈' => '攩',
+'鬄' => '',
+'鬅' => '',
+'鬩' => '蒰',
+'鬵' => '瀻',
+'魊' => '蠋',
+'魌' => '矌',
+'魋' => '盭',
+'鯇' => '灖',
+'鯆' => '',
+'鯃' => '',
+'鮿' => '',
+'鯁' => '攠',
+'鮵' => '鶤',
+'鮸' => '鶘',
+'鯓' => '',
+'鮶' => '鶝',
+'鯄' => '',
+'鮹' => '鶐',
+'鮽' => '',
+'鵜' => '蟳',
+'鵓' => '蟛',
+'鵏' => '觿',
+'鵊' => '虈',
+'鵛' => '顲',
+'鵋' => '襹',
+'鵙' => '鑳',
+'鵖' => '鑭',
+'鵌' => '襺',
+'鵗' => '鑯',
+'鵒' => '蟥',
+'鵔' => '躣',
+'鵟' => '鱭\',
+'鵘' => '鑱',
+'鵚' => '靉',
+'麎' => '',
+'麌' => '',
+'黟' => '蘺',
+'鼁' => 'z',
+'鼀' => 'y',
+'鼖' => '',
+'鼥' => '',
+'鼫' => '',
+'鼪' => '',
+'鼩' => '',
+'鼨' => '',
+'齌' => 'T',
+'齕' => '[',
+'儴' => '',
+'儵' => '',
+'劖' => '',
+'勷' => '',
+'厴' => '婻',
+'嚫' => '',
+'嚭' => '',
+'嚦' => '萷',
+'嚧' => '',
+'嚪' => '遉',
+'嚬' => 'け',
+'壚' => '詏',
+'壝' => '',
+'壛' => '',
+'夒' => '',
+'嬽' => '擱',
+'嬾' => '',
+'嬿' => '',
+'巃' => 'a',
+'幰' => '',
+'徿' => '',
+'懻' => '',
+'攇' => 'g',
+'攐' => 'o',
+'攍' => 'l',
+'攉' => '葖',
+'攌' => 'k',
+'攎' => 'm',
+'斄' => '',
+'旞' => '',
+'旝' => '',
+'曞' => '',
+'櫧' => '橭',
+'櫠' => '',
+'櫌' => '',
+'櫑' => '',
+'櫙' => '',
+'櫋' => '',
+'櫟' => '魦',
+'櫜' => '',
+'櫐' => '',
+'櫫' => '樿',
+'櫏' => '',
+'櫍' => '',
+'櫞' => '橕',
+'歠' => 'f',
+'殰' => '',
+'氌' => '諈',
+'瀙\' => 'p',
+'瀧' => '蜤',
+'瀠' => '儇',
+'瀖' => 'm',
+'瀫' => '',
+'瀡' => 'v',
+'瀢' => 'w',
+'瀣' => '戭',
+'瀩' => '}',
+'瀗' => 'n',
+'瀤' => 'x',
+'瀜' => 'q',
+'瀪' => '~',
+'爌' => 'p',
+'爊' => 'n',
+'爇' => 'k',
+'爂' => 'g',
+'爅' => 'j',
+'犥' => '偏',
+'犦' => '',
+'犤' => '',
+'犣' => '',
+'犡' => '',
+'瓋' => '',
+'瓅' => '迢',
+'璷' => '觔',
+'瓃' => '述',
+'甖' => '騜',
+'癠' => '託',
+'矉' => 'け',
+'矊' => '',
+'矄' => '',
+'矱' => '蛀',
+'礝' => '焜',
+'礛' => '然',
+'礡' => '耬',
+'礜' => '煮',
+'礗' => '焚',
+'礞' => '翲',
+'禰' => '曒',
+'穧' => '榔',
+'穨' => '虰',
+'簳' => '',
+'簼' => '',
+'簹' => '',
+'簬' => '',
+'簻' => '',
+'糬' => '嬉',
+'糪' => '墦\',
+'繶' => '頷',
+'繵' => '頻',
+'繸' => '頹',
+'繰' => '諑',
+'繷' => '頭',
+'繯' => '諔',
+'繺' => '餐\',
+'繲' => '鞘',
+'繴' => '頸',
+'繨' => '雕',
+'罋' => '怤',
+'罊' => '',
+'羃' => '蹶',
+'羆' => '蹓',
+'羷' => '',
+'翽' => '嚕',
+'翾' => '嚮',
+'聸' => '',
+'臗' => '躊',
+'臕' => '桿',
+'艤' => '纀',
+'艡' => '',
+'艣' => '',
+'藫' => '',
+'藱' => '',
+'藭' => '',
+'藙' => '',
+'藡' => '',
+'藨' => '',
+'藚' => '',
+'藗' => '',
+'藬' => '',
+'藲' => '',
+'藸' => '',
+'藘' => '',
+'藟' => '',
+'藣' => '',
+'藜' => '瑆',
+'藑' => '芑',
+'藰' => '',
+'藦' => '',
+'藯' => '',
+'藞' => '',
+'藢' => '',
+'蠀' => '',
+'蟺' => '騕',
+'蠃' => '湀',
+'蟶' => '藙',
+'蟷' => '颿',
+'蠉' => '',
+'蠌' => '',
+'蠋' => '',
+'蠆' => '繰',
+'蟼' => '',
+'蠈' => '',
+'蟿' => '騢',
+'蠊' => '騛',
+'蠂' => '',
+'襢' => '抳',
+'襚' => '涋',
+'襛' => '浾',
+'襗' => '涘',
+'襡' => '涃',
+'襜' => '涀',
+'襘' => '洯',
+'襝' => '鵜',
+'襙' => '浨',
+'覈' => '瞄',
+'覷' => '膬',
+'覶' => '紘',
+'觶' => '鬕',
+'譐' => '脟',
+'譈' => '磾',
+'譊' => '聈',
+'譀' => '',
+'譓' => '脡',
+'譖' => '稄',
+'譔' => '蚴',
+'譋' => '擰',
+'譕' => '脧',
+'譑' => '脬',
+'譂' => '',
+'譒' => '脞',
+'譗' => '脢',
+'豃' => '陱',
+'豷' => '喒',
+'豶' => '喣',
+'貚' => '',
+'贆' => '',
+'贇' => '',
+'贉' => '',
+'趬' => '',
+'趪' => '',
+'趭' => '',
+'趫' => '',
+'蹭' => '脖',
+'蹸' => '耰',
+'蹳' => '軹',
+'蹪' => '',
+'蹯' => '纍',
+'蹻' => '軨',
+'軂' => '隈',
+'轒' => '溹',
+'轑' => '溱',
+'轏' => '溔',
+'轐' => '溠',
+'轓' => '滆',
+'辴' => '煸',
+'酀\' => '',
+'鄿' => '',
+'醰' => '嫛',
+'醭' => '麚',
+'鏞' => '檹',
+'鏇' => '櫡',
+'鏏' => '膕',
+'鏂' => '',
+'鏚' => '艑',
+'鏐' => '膢',
+'鏹' => '氋',
+'鏬' => '髂',
+'鏌' => '攄',
+'鏙' => '艎',
+'鎩' => '鵅',
+'鏦' => '蔜',
+'鏊' => '黫',
+'鏔' => '艏',
+'鏮' => '蓲',
+'鏣' => '蔟',
+'鏕' => '艓',
+'鏄' => '',
+'鏎' => '膞',
+'鏀' => '',
+'鏒' => '膗',
+'鏧' => '蓻',
+'镽' => '嬙',
+'闚' => '燋',
+'闛' => '燔',
+'雡' => '褢',
+'霩' => '閾',
+'霫' => '閹',
+'霬' => '閺',
+'霨' => '闍',
+'霦' => '錖',
+'鞳' => '澩',
+'鞷' => '濣',
+'鞶' => '濔',
+'韝' => '鷒',
+'韞' => '頩',
+'韟' => '瞵',
+'顜' => '',
+'顙' => '簹',
+'顝' => '',
+'顗' => '',
+'颿' => '楞',
+'颽' => '駾',
+'颻' => '駻',
+'颾' => '駼',
+'饈' => '獃',
+'饇' => '熏',
+'饃' => '犓',
+'馦' => '鄾',
+'馧' => '醨',
+'騚' => '瀫',
+'騕' => '氌',
+'騥' => '爇',
+'騝' => '瀣',
+'騤' => '爊',
+'騛' => '瀡',
+'騢' => '瀪',
+'騠' => '瀤',
+'騧' => '爅',
+'騣' => '跂',
+'騞' => '瀩',
+'騜' => '瀢',
+'騔' => '殰',
+'髂' => '鷵',
+'鬋' => '孅',
+'鬊' => '壣',
+'鬎' => '廮',
+'鬌' => '巆',
+'鬷' => '灁',
+'鯪' => '爞',
+'鯫' => '爟',
+'鯠' => '蠤',
+'鯞' => '蠛',
+'鯤' => '獿',
+'鯦' => '襮',
+'鯢' => '瓙',
+'鯰' => '瓗',
+'鯔' => '礵',
+'鯗' => '廲',
+'鯬' => '譺',
+'鯜' => '蠩',
+'鯙' => '',
+'鯥' => '襩',
+'鯕' => '',
+'鯡' => '犩',
+'鯚' => '',
+'鵷' => '鑶',
+'鶁' => '鼊',
+'鶊' => '',
+'鶄' => '',
+'鶈' => '',
+'鵱' => '蠼',
+'鶀' => '黶',
+'鵸' => '鑵',
+'鶆' => '',
+'鶋' => '',
+'鶌' => '',
+'鵽' => '鱵',
+'鵫' => '齻',
+'鵴' => '釃',
+'鵵' => '鑴',
+'鵰' => '蛐',
+'鵩' => '齇',
+'鶅' => '',
+'鵳' => '躦',
+'鵻' => '鱳',
+'鶂' => '',
+'鵯' => '蟓',
+'鵹' => '驠',
+'鵿' => '鸓',
+'鶇' => '薶',
+'鵨' => '鼉',
+'麔' => '',
+'麑' => '簷',
+'黀' => 'P',
+'黼' => '臊',
+'鼭' => '',
+'齀' => 'I',
+'齁' => 'J',
+'齍' => 'U',
+'齖' => '\\',
+'齗' => ']',
+'齘' => '^',
+'匷' => 'Z',
+'嚲' => '',
+'嚵' => '',
+'嚳' => '鈮',
+'壣' => '',
+'孅' => '',
+'巆' => 'c',
+'巇' => 'd',
+'廮' => '_',
+'廯' => '`',
+'忀' => '',
+'忁' => '',
+'懹' => '',
+'攗' => '睖',
+'攖' => '稕',
+'攕' => 's',
+'攓' => '摨',
+'旟' => '',
+'曨' => '',
+'曣' => '',
+'曤' => '',
+'櫳' => '駗',
+'櫰' => '跼',
+'櫪' => '飺',
+'櫨' => '髬',
+'櫹' => '',
+'櫱' => '',
+'櫮' => '',
+'櫯' => '',
+'瀼' => '',
+'瀵\' => '撖',
+'瀯' => '',
+'瀷' => '',
+'瀴' => '',
+'瀱' => '',
+'灂' => '',
+'瀸' => '',
+'瀿' => '',
+'瀺' => '',
+'瀹' => '摰',
+'灀' => '',
+'瀻' => '',
+'瀳' => '',
+'灁' => '',
+'爓' => '栭',
+'爔' => 'x',
+'犨' => '',
+'獽' => '便',
+'獼' => '漼',
+'璺' => '頝',
+'皫' => '',
+'皪' => '',
+'皾' => '',
+'盭' => '崑',
+'矌' => '',
+'矎' => '',
+'矏' => '',
+'矍' => '裀',
+'矲' => '蚶',
+'礥' => '猴',
+'礣' => '猥',
+'礧' => '濠',
+'礨' => '琪',
+'礤' => '翴',
+'礩' => '琳',
+'禲' => '跑',
+'穮' => '',
+'穬' => '',
+'穭' => '爁',
+'竷' => '',
+'籉' => '鯚',
+'籈' => '聚',
+'籊' => '腐',
+'籇' => '聞',
+'籅' => '翡',
+'糮' => '嬋',
+'繻' => '館',
+'繾' => '諓',
+'纁' => '駢',
+'纀' => '駭',
+'羺' => '',
+'翿' => '壙',
+'聹' => '壝',
+'臛' => '辯',
+'臙' => '醐',
+'舋' => '鼙',
+'艨' => '蘄',
+'艩' => '',
+'蘢' => '喍',
+'藿' => '瑍',
+'蘁' => '姏',
+'藾' => '妵',
+'蘛' => '岠',
+'蘀' => '妺',
+'藶' => '僉',
+'蘄' => '猺',
+'蘉' => '蚸',
+'蘅' => '瓡',
+'蘌' => '妽',
+'藽' => '奅',
+'蠙' => '',
+'蠐' => '藣',
+'蠑' => '襜',
+'蠗' => '',
+'蠓' => '騝',
+'蠖' => '騥',
+'襣' => '浽',
+'襦' => '黟',
+'覹' => '紟',
+'觷' => '荁',
+'譠' => '莣',
+'譪' => '莕',
+'譝' => '舲',
+'譨' => '莏',
+'譣' => '桄',
+'譥' => '莤',
+'譧' => '荴',
+'譭' => '障',
+'趮' => '婇',
+'躆' => '逭',
+'躈' => '逴',
+'躄' => '軩',
+'轙' => '溷',
+'轖' => '滁',
+'轗' => '溞',
+'轕' => '溽',
+'轘' => '滉',
+'轚' => '溰',
+'邍' => '',
+'酃' => '蛫',
+'酁' => '',
+'醷' => '嫨',
+'醵' => '黧',
+'醲' => '嫞',
+'醳' => '嫝',
+'鐋' => '鵀',
+'鐓' => '檴',
+'鏻' => '蔮',
+'鐠' => '歞',
+'鐏' => '',
+'鐔' => '檺',
+'鏾' => '蔞',
+'鐕' => '',
+'鐐' => '趨',
+'鐨' => '懩',
+'鐙' => '瀇',
+'鐍' => '虢',
+'鏵' => '鞚',
+'鐀' => '嶄',
+'鏷' => '檷',
+'鐇' => '蔘',
+'鐎' => '',
+'鐖' => '',
+'鐒' => '鴭',
+'鏺' => '蔝',
+'鐉' => '蔰',
+'鏸' => '蓾',
+'鐊' => '蔋',
+'鏿' => '蓶',
+'鏼' => '蔂',
+'鐌' => '蔯',
+'鏶' => '蓩',
+'鐑' => '幮',
+'鐆' => '蓹',
+'闞' => '蜞',
+'闠' => '燘',
+'闟' => '熽',
+'霮' => '閶',
+'霯' => '閿',
+'鞹' => '濭',
+'鞻' => '濦',
+'韽' => '',
+'韾' => '',
+'顠' => '',
+'顢' => '簼',
+'顣' => '',
+'顟' => '',
+'飁' => '髾',
+'飂' => '髽',
+'饐' => '',
+'饎' => '',
+'饙' => '',
+'饌' => '獌',
+'饋' => '嚏',
+'饓' => '',
+'騲' => '翌',
+'騴' => '矊',
+'騱\' => '甖',
+'騬' => '犡',
+'騪' => '犤',
+'騶' => '緷',
+'騩' => '犦',
+'騮' => '羬',
+'騸' => '羰',
+'騭' => '緮',
+'髇' => '鏮',
+'髊' => '鏄',
+'髆' => '眷',
+'鬐' => '廯',
+'鬒' => '褘',
+'鬑' => '忀',
+'鰋' => '霺',
+'鰈' => '穰',
+'鯷' => '酄',
+'鰅' => '鑀',
+'鰒' => '籜',
+'鯸' => '酅\',
+'鱀' => '羇',
+'鰇' => '闥',
+'鰎' => '顤',
+'鰆' => '鐱',
+'鰗' => '驄',
+'鰔' => '騹',
+'鰉' => '籙',
+'鶟' => '',
+'鶙' => '',
+'鶤' => 'A',
+'鶝' => '',
+'鶒' => '',
+'鶘' => '蟘',
+'鶐' => '',
+'鶛' => '',
+'鶠' => '',
+'鶔' => '',
+'鶜' => '',
+'鶪' => 'G',
+'鶗' => '',
+'鶡' => '',
+'鶚' => '蟣',
+'鶢' => '',
+'鶨' => 'E',
+'鶞' => '',
+'鶣' => '@',
+'鶿' => '螤',
+'鶩' => '蟙',
+'鶖' => '',
+'鶦' => 'C',
+'鶧' => 'D',
+'麙' => '',
+'麛' => '',
+'麚' => '',
+'黥' => '蘱',
+'黤' => 'f',
+'黧' => '蘼',
+'黦' => 'g',
+'鼰' => '',
+'鼮' => '',
+'齛' => 'a',
+'齠' => '鷇',
+'齞' => 'd',
+'齝' => 'c',
+'齙' => '鷁',
+'龑' => '',
+'儺' => '棞',
+'儹' => '婗',
+'劘' => '',
+'劗' => '',
+'囃' => '',
+'嚽' => '',
+'嚾' => '辣',
+'孈' => '@',
+'孇' => '',
+'巋' => '錯',
+'巏' => 'k',
+'廱' => 'b',
+'懽' => '辣',
+'攛' => '艄',
+'欂' => '',
+'櫼' => '',
+'欃' => '',
+'櫸' => '曋',
+'欀' => '',
+'灃' => '蝆',
+'灄' => '髧',
+'灊' => '',
+'灈' => '',
+'灉' => '',
+'灅' => '',
+'灆' => '',
+'爝' => '懃',
+'爚' => '~',
+'爙' => '}',
+'獾' => '漟',
+'甗' => '娌',
+'癪' => '貢',
+'矐' => '',
+'礭' => '琶',
+'礱' => '篳',
+'礯' => '琯',
+'籔' => '與',
+'籓' => '臺',
+'糲' => '譪',
+'纊' => '膟',
+'纇' => '髭',
+'纈' => '觬',
+'纋' => '鴣',
+'纆' => '髻',
+'纍' => '濛',
+'罍' => '',
+'羻' => '',
+'耰' => '檯',
+'臝' => '邃',
+'蘘' => '屇',
+'蘪' => '瓽',
+'蘦' => '岝',
+'蘟' => '岬',
+'蘣' => '岢',
+'蘜' => '擅',
+'蘙' => '岮',
+'蘧' => '瑔',
+'蘮' => '帔',
+'蘡' => '岣',
+'蘠' => 'Ц',
+'蘩' => '瓿',
+'蘞' => '嗀',
+'蘥' => '岧',
+'蠩' => '籸',
+'蠝' => '',
+'蠛' => '騢',
+'蠠' => '',
+'蠤' => '穾',
+'蠜' => '',
+'蠫' => '籿',
+'衊' => '鏖',
+'襭' => '觬',
+'襩' => '烑',
+'襮' => '烗',
+'襫' => '烋',
+'觺' => '茢',
+'譹' => '莯',
+'譸' => '莥',
+'譅' => '',
+'譺' => '莈',
+'譻' => '莗',
+'贐' => '罼',
+'贔' => '湱',
+'趯' => '',
+'躎' => '郼',
+'躌' => '鄄',
+'轞' => '熨',
+'轛' => '滍',
+'轝' => '豗',
+'酆' => '蛜',
+'酄' => '',
+'酅\' => '凘',
+'醹' => '孷',
+'鐿' => '瀁',
+'鐻' => '輣',
+'鐶' => '鍤',
+'鐩' => '',
+'鐽' => '輗',
+'鐼' => '輖',
+'鐰' => '踒',
+'鐹' => '輚',
+'鐪' => '',
+'鐷' => '輤',
+'鐬' => '',
+'鑀' => '懰',
+'鐱' => '膛',
+'闥' => '蒶',
+'闤' => '燛',
+'闣' => '燚',
+'霵' => '雔',
+'霺' => '霐',
+'鞿' => '濢',
+'韡' => '瞲',
+'顤' => '',
+'飉' => '鮛',
+'飆' => '鴙',
+'飀' => '骾',
+'饘' => '',
+'饖' => '',
+'騹' => '',
+'騽' => '',
+'驆' => '',
+'驄' => '翭',
+'驂' => '緰',
+'驁' => '罶',
+'騺' => '',
+'騿' => '',
+'髍' => '鏎',
+'鬕' => '攗',
+'鬗' => '攕',
+'鬘' => '攓',
+'鬖' => '攖',
+'鬺' => '犨',
+'魒' => '矍',
+'鰫' => '',
+'鰝' => '',
+'鰜' => '',
+'鰬' => '',
+'鰣' => '欈',
+'鰨' => '驐',
+'鰩' => '鬙',
+'鰤' => '',
+'鰡' => '',
+'鶷' => 'T',
+'鶶' => 'S',
+'鶼' => '蟴',
+'鷁' => '^',
+'鷇' => 'd',
+'鷊' => 'g',
+'鷏' => 'l',
+'鶾' => '[',
+'鷅' => 'b',
+'鷃' => '`',
+'鶻' => '鷜',
+'鶵' => 'R',
+'鷎' => 'k',
+'鶹' => 'V',
+'鶺' => 'W',
+'鶬' => 'I',
+'鷈' => 'e',
+'鶱' => 'N',
+'鶭' => 'J',
+'鷌' => 'i',
+'鶳' => 'P',
+'鷍' => 'j',
+'鶲' => 'O',
+'鹺' => '齛',
+'麜' => '',
+'黫' => 'i',
+'黮' => 'l',
+'黭' => 'k',
+'鼛' => '',
+'鼘' => '',
+'鼚' => '',
+'鼱' => '',
+'齎' => '耪',
+'齥' => 'k',
+'齤' => 'j',
+'龒' => '',
+'亹' => '皜',
+'囆' => '',
+'囅' => '氰',
+'囋' => '',
+'奱' => 'a',
+'孋' => 'C',
+'孌' => '畾',
+'巕' => 'q',
+'巑' => 'm',
+'廲' => 'c',
+'攡' => '~',
+'攠' => '}',
+'攦' => '',
+'攢' => '婗',
+'欋' => '噮',
+'欈' => '',
+'欉' => '',
+'氍' => '諡',
+'灕' => '燬',
+'灖' => '',
+'灗' => '',
+'灒' => '',
+'爞' => '',
+'爟' => '辣',
+'犩' => '',
+'獿' => '俠',
+'瓘' => '',
+'瓕' => '譆',
+'瓙' => '',
+'瓗' => '',
+'癭' => '顐',
+'皭' => '',
+'礵' => '甦',
+'禴' => '跌',
+'穰' => '藀',
+'穱' => '',
+'籗' => '艋',
+'籜' => '鵳',
+'籙' => '蒿',
+'籛' => '蓄',
+'籚' => '蓆',
+'糴' => '殕',
+'糱' => '嬌',
+'纑' => '黔',
+'罏' => '詏',
+'羇' => '縱',
+'臞' => '鐳',
+'艫' => '舋',
+'蘴' => '彔',
+'蘵' => '徂',
+'蘳' => '弤',
+'蘬' => '岦',
+'蘲' => '弣',
+'蘶' => '彾',
+'蠬' => '粀',
+'蠨' => '籺',
+'蠦' => '笀',
+'蠪' => '籹',
+'蠥' => '竑',
+'襱' => '烠',
+'覿' => '膹',
+'覾' => '罡\',
+'觻' => '',
+'譾' => '稌',
+'讄' => '虖',
+'讂' => '莚',
+'讆' => '蚷',
+'讅' => '机',
+'譿' => '莇',
+'贕\' => '湫',
+'躕' => '纈',
+'躔' => '臝',
+'躚' => '櫸',
+'躒' => '孇',
+'躐' => '蘘',
+'躖' => '鄀',
+'躗' => '鄇',
+'轠' => '滃',
+'轢' => '瀄',
+'酇' => '劀',
+'鑌' => '旛',
+'鑐' => '醄',
+'鑊' => '瀌',
+'鑋' => '醅',
+'鑏' => '醂',
+'鑇' => '鄪',
+'鑅' => '鄫',
+'鑈' => '鄲',
+'鑉' => '鄦',
+'鑆' => '鄩',
+'霿' => '韰',
+'韣' => '瞶',
+'顪' => '',
+'顩' => '',
+'飋' => '鮡',
+'饔' => '壧',
+'饛' => '',
+'驎' => '',
+'驓' => '',
+'驔' => '',
+'驌' => '',
+'驏' => '翫',
+'驈' => '',
+'驊' => '緡',
+'驉' => '',
+'驒' => '',
+'驐' => '',
+'髐' => '鏧',
+'鬙' => '旟',
+'鬫' => '瀴',
+'鬻' => '毿',
+'魖' => '礣',
+'魕' => '礥',
+'鱆' => '蘬',
+'鱈' => '魖',
+'鰿' => '罏',
+'鱄' => '蘵',
+'鰹' => '欋',
+'鰳' => '鬫',
+'鱁' => '臞',
+'鰼' => '',
+'鰷' => '欉',
+'鰴' => '',
+'鰲' => '驉',
+'鰽' => '糱',
+'鰶' => '',
+'鷛' => 'x',
+'鷒' => 'o',
+'鷞' => '{',
+'鷚' => '襓',
+'鷋' => 'h',
+'鷐' => 'm',
+'鷜' => 'y',
+'鷑' => 'n',
+'鷟' => '|',
+'鷩' => '',
+'鷙' => '虩',
+'鷘' => 'u',
+'鷖' => 's',
+'鷵' => '',
+'鷕' => 'r',
+'鷝' => 'z',
+'麶' => 'J',
+'黰' => '褘',
+'鼵' => 'C',
+'鼳' => 'A',
+'鼲' => '@',
+'齂' => 'K',
+'齫' => 'q',
+'龕' => '膻',
+'龢' => '睿',
+'儽' => '',
+'劙' => '',
+'壨' => '',
+'壧' => '',
+'奲' => 'b',
+'孍' => 'E',
+'巘' => 't',
+'蠯' => '紈',
+'彏' => '',
+'戁' => '',
+'戃' => '',
+'戄' => '',
+'攩' => '結',
+'攥' => '葶',
+'斖' => '',
+'曫' => '',
+'欑' => '婗',
+'欒' => '鴄',
+'欏' => '憿',
+'毊' => '',
+'灛' => '',
+'灚' => '',
+'爢' => '',
+'玂' => '保',
+'玁' => '榶',
+'玃' => '騣',
+'癰' => '虒',
+'矔' => '',
+'籧' => '蓊',
+'籦' => '蓑',
+'纕' => '償',
+'艬' => '贛',
+'蘺' => '楒',
+'虀' => '怋',
+'蘹' => '忞',
+'蘼' => '瓽',
+'蘱' => '弢',
+'蘻' => '怭',
+'蘾' => '怙',
+'蠰' => '紁',
+'蠲' => '遾',
+'蠮' => '紃',
+'蠳' => '羑',
+'襶' => '烇',
+'襴' => '烅',
+'襳' => '烍',
+'觾' => '',
+'讌' => '栯',
+'讎' => '鷌',
+'讋' => '',
+'讈' => '',
+'豅' => '隿',
+'贙' => '湓',
+'躘' => '鄅',
+'轤' => '濄',
+'轣' => '溙',
+'醼' => '',
+'鑢' => '鋨',
+'鑕' => '鋀',
+'鑝' => '鋗',
+'鑗' => '銶',
+'鑞' => '鋝',
+'韄' => '燲',
+'韅' => '燤',
+'頀' => '',
+'驖' => '',
+'驙' => '',
+'鬞' => '櫰',
+'鬟' => '曫',
+'鬠' => '櫪',
+'鱒' => '鰹',
+'鱘' => '攡',
+'鱐' => '覾',
+'鱊' => '蠨',
+'鱍' => '鼱',
+'鱋\' => '蠦',
+'鱕' => '讆',
+'鱙' => '躕',
+'鱌' => '蠪',
+'鱎' => '襱',
+'鷻' => '',
+'鷷' => '',
+'鷯' => '襋',
+'鷣' => '',
+'鷫' => '',
+'鷸' => '襆',
+'鷤' => '',
+'鷶' => '',
+'鷡' => '~',
+'鷮' => '',
+'鷦' => '襏',
+'鷲' => '襌',
+'鷰' => '桏',
+'鷢' => '',
+'鷬' => '',
+'鷴' => '',
+'鷳' => '蟟',
+'鷨' => '',
+'鷭' => '',
+'黂' => 'R',
+'黐' => '[',
+'黲' => '蘻',
+'黳' => 'p',
+'鼆' => '',
+'鼜' => '',
+'鼸' => 'E',
+'鼷' => '襶',
+'鼶' => 'D',
+'齃' => 'L',
+'齏' => '黕',
+'齱' => 'w',
+'齰' => '捰',
+'齮' => 't',
+'齯' => 'u',
+'囓' => '蘚',
+'囍' => '',
+'孎' => 'F',
+'屭' => '',
+'攭' => '',
+'曭' => '',
+'曮' => '',
+'欓' => '',
+'灟' => '',
+'灡' => '',
+'灝' => '撠',
+'灠' => '僾',
+'爣' => '',
+'瓛' => '',
+'瓥' => '',
+'矕' => '',
+'礸' => '痢',
+'禷' => '軻',
+'禶' => '跆',
+'籪' => '匷',
+'纗' => '儲',
+'羉' => '繁',
+'艭' => '釀',
+'虃' => '',
+'蠸' => '耏',
+'蠷' => '耎',
+'蠵' => '羾',
+'衋' => '胊',
+'讔' => '',
+'讕' => '擰',
+'躞' => '蘦',
+'躟' => '酢',
+'躠' => '酠',
+'躝' => '酟',
+'醾' => '',
+'醽' => '',
+'釂' => '',
+'鑫' => '鼛',
+'鑨' => '鋕',
+'鑩' => '鋉',
+'雥' => '褬',
+'靆' => '餧',
+'靃' => '齊',
+'靇' => '餩',
+'韇' => '燢',
+'韥' => '',
+'驞' => '豃',
+'髕' => '鷝',
+'魙' => '礤',
+'鱣' => '鱄',
+'鱧' => '鰳',
+'鱦' => '鑋',
+'鱢' => '酇',
+'鱞' => '躖',
+'鱠' => '醑',
+'鸂' => '',
+'鷾' => '',
+'鸇' => 'D',
+'鸃' => '@',
+'鸆' => 'C',
+'鸅' => 'B',
+'鸀' => '',
+'鸁' => '',
+'鸉' => 'F',
+'鷿' => '',
+'鷽' => '',
+'鸄' => 'A',
+'麠' => '',
+'鼞' => '隄',
+'齆' => 'N',
+'齴' => 'z',
+'齵' => '{',
+'齶' => '錥',
+'囔' => '鳭',
+'攮' => '葹',
+'斸' => '',
+'欘' => '',
+'欙' => '',
+'欗' => '',
+'欚' => '',
+'灢' => '',
+'爦' => '',
+'犪' => '',
+'矘' => '',
+'矙' => '謍',
+'礹' => '痛',
+'籩' => '鯡',
+'籫' => '蜢',
+'糶' => '譝',
+'纚' => '嚀',
+'纘' => '諕',
+'纛' => '鐕',
+'纙' => '嚎',
+'臠' => '湳',
+'臡' => '鐸',
+'虆' => '',
+'虇' => '',
+'虈' => '',
+'襹' => '烡',
+'襺' => '牂',
+'襼' => '牸',
+'襻' => '鼁',
+'觿' => '',
+'讘' => '',
+'讙' => '辣',
+'躥' => '款',
+'躤' => '鈃',
+'躣' => '鈥',
+'鑮' => '鋑',
+'鑭' => '檭',
+'鑯' => '鋓',
+'鑱' => '',
+'鑳' => '瑩',
+'靉' => '駮',
+'顲' => '韔',
+'饟' => '熁',
+'鱨' => '鑇',
+'鱮' => '韣',
+'鱭\' => '巕',
+'鸋' => 'H',
+'鸍' => 'J',
+'鸐' => 'M',
+'鸏' => 'L',
+'鸒' => 'O',
+'鸑' => 'N',
+'麡' => '',
+'黵' => 'r',
+'鼉' => '鷎',
+'齇' => 'O',
+'齸' => '~',
+'齻' => '',
+'齺' => '',
+'齹' => '',
+'圞' => '鴄',
+'灦' => '',
+'籯' => '蝕',
+'蠼' => '騣',
+'趲' => '鏷',
+'躦' => '蘪',
+'釃' => '鶚',
+'鑴' => '',
+'鑸' => '',
+'鑶' => '',
+'鑵' => '嫡',
+'驠' => '豶',
+'鱴' => '驎',
+'鱳' => '饛',
+'鱱' => '飋',
+'鱵' => '驓',
+'鸔' => 'Q',
+'鸓' => 'P',
+'黶' => 's',
+'鼊' => '',
+'龤' => '迣',
+'灨' => '該',
+'灥' => '',
+'糷' => '層',
+'虪' => '',
+'蠾' => '胇',
+'蠽' => '胘',
+'蠿' => '胠',
+'讞' => '竤',
+'貜' => '',
+'躩' => '鈀',
+'軉' => '',
+'靋' => '駥',
+'顳' => '簳',
+'顴' => '',
+'飌' => '鮥',
+'饡' => '',
+'馫' => '醯',
+'驤' => '翬',
+'驦' => '轓',
+'驧' => '趭',
+'鬤' => '櫱',
+'鸕' => '藒',
+'鸗' => 'T',
+'齈' => 'P',
+'戇' => '禨',
+'欞' => '凞',
+'爧' => '',
+'虌' => '',
+'躨' => '鈌',
+'钂' => '噞',
+'钀' => '',
+'钁' => '檶',
+'驩' => '蹭',
+'驨' => '趫',
+'鬮' => '蓗',
+'鸙' => 'V',
+'爩' => '',
+'虋' => '',
+'讟' => '',
+'钃' => '',
+'鱹' => '驈',
+'麷' => 'K',
+'癵' => '迷',
+'驫' => '蹻',
+'鱺' => '攦',
+'鸝' => '蟫',
+'灩' => '駇',
+'灪' => '',
+'麤' => '棉',
+'齾' => '',
+'齉' => 'Q',
+'龘' => '',
+'' => '',
+'' => '凄',
+'' => '爵',
+'' => 'Х',
+'' => '箝',
+'' => '衒',
+'' => '瘚',
+'' => '汴',
+'' => '甫',
+'' => '沍',
+'' => '牡',
+'' => '私',
+'' => '狂',
+'' => '沂',
+'' => '皂',
+'' => '災',
+'' => '汲',
+'' => '玖',
+'' => '沆',
+'' => '灸',
+'' => '盯',
+'' => '牠',
+'' => '沔\',
+'' => '男',
+'' => '灶',
+'' => '汾',
+'' => '甬',
+'' => '汶',
+'' => '牢',
+'' => '矣',
+'' => '狄',
+'' => '沘',
+'' => '甸',
+'' => '灼',
+'' => '沃',
+'' => '汽',
+'' => '秀',
+'' => '禿',
+'' => '系',
+'' => '究',
+'' => '',
+);
+
+our(@ISA, @EXPORT);
+@ISA = qw(Exporter);
+@EXPORT = qw(%b2g);
+
+1;
-- 
cgit v1.2.3


From e3c08f8066b5e8036b0dbf386dc390ae507d12e5 Mon Sep 17 00:00:00 2001
From: in2 
Date: Mon, 7 Jul 2003 04:17:58 +0000
Subject: b2g support by b2g.pm, count elapsed time

git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@1039 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
---
 pttbbs/staticweb/man.pl | 20 ++++++++++++++------
 1 file changed, 14 insertions(+), 6 deletions(-)

diff --git a/pttbbs/staticweb/man.pl b/pttbbs/staticweb/man.pl
index 4f20889c..7d33ee5a 100755
--- a/pttbbs/staticweb/man.pl
+++ b/pttbbs/staticweb/man.pl
@@ -1,5 +1,5 @@
 #!/usr/bin/perl
-# $Id: man.pl,v 1.7 2003/07/05 06:16:15 in2 Exp $
+# $Id: man.pl,v 1.8 2003/07/07 04:17:58 in2 Exp $
 use CGI qw/:standard/;
 use lib qw/./;
 use LocalVars;
@@ -12,7 +12,10 @@ use HTML::Calendar::Simple;
 use OurNet::FuzzyIndex;
 use Data::Serializer;
 use Encode;
-use vars qw/%db $brdname $fpath $isgb/;
+use Time::HiRes qw/gettimeofday tv_interval/;
+use b2g;
+
+use vars qw/%db $brdname $fpath $isgb %b2g/;
 
 sub main
 {
@@ -27,10 +30,11 @@ sub main
 	return;
     }
 
-    $isgb = (param('gb') ? 1 : 0);
     charset('');
     print header();
 
+    $isgb = (param('gb') ? 1 : 0);
+
     if( ($key = param('key')) ){
 	$rh = search($key);
     }
@@ -67,7 +71,8 @@ sub dirmode
 				       compress   => 0,
 				       );
     foreach( @{$serial->deserialize($db{$fpath})} ){
-	Encode::from_to($_->[1], 'big5', 'gbk') if( $isgb );
+	$_->[1] =~ s/([\xA1-\xF9].)/$b2g{$1}/eg if( $isgb );
+	#Encode::from_to($_->[1], 'big5', 'gbk') if( $isgb );
 	$isdir = (($_->[0] =~ m|/$|) ? 1 : 0);
 	push @{$th{dat}}, {isdir => $isdir,
 			   fn    => "man.pl/$brdname$_->[0]",
@@ -97,14 +102,16 @@ sub articlemode
     $th{content} =~
 	s|ptt\.twbbs\.org|ptt.twbbs.org|gs;
 
-    Encode::from_to($th{content}, 'big5', 'gbk') if( $isgb );
+    $th{content} =~ s/([\xA1-\xF9].)/$b2g{$1}/eg if( $isgb );
+    #Encode::from_to($th{content}, 'big5', 'gbk') if( $isgb );
     return \%th;
 }
 
 sub search($)
 {
     my($key) = @_;
-    my(%th, $idx, $k);
+    my(%th, $idx, $k, $t0);
+    $t0 = [gettimeofday()];
     $idx = OurNet::FuzzyIndex->new("$MANDATA/$brdname.idx");
     my %result = $idx->query($th{key} = $key, MATCH_FUZZY);
     foreach my $t (sort { $result{$b} <=> $result{$a} } keys(%result)) {
@@ -114,6 +121,7 @@ sub search($)
 			      score => $result{$t} / 10};
     }
 
+    $th{elapsed} = tv_interval($t0);
     $th{key} = $key;
     $th{tmpl} = 'search.html';
     return \%th;
-- 
cgit v1.2.3


From 792fb835bceea4ec78670cc395fa855d0efcc020 Mon Sep 17 00:00:00 2001
From: in2 
Date: Mon, 7 Jul 2003 04:18:09 +0000
Subject: for elapsed time

git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@1040 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
---
 pttbbs/staticweb/search.html | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pttbbs/staticweb/search.html b/pttbbs/staticweb/search.html
index 4688617d..d19fdc1d 100644
--- a/pttbbs/staticweb/search.html
+++ b/pttbbs/staticweb/search.html
@@ -9,7 +9,7 @@
 [% brdname %]精華區首頁
 批踢踢部落格
 
-在看板 [% brdname %] 內搜尋 [% key %] +在看板 [% brdname %] 內搜尋 [% key %] (共費時 [% elapsed %] 秒)
-- cgit v1.2.3 From 61bb8e2eb136076c52adc1e7b88381c683c0ca7b Mon Sep 17 00:00:00 2001 From: in2 Date: Tue, 8 Jul 2003 04:09:36 +0000 Subject: use $dbh->quote git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@1041 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/blog/blog.pl | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/pttbbs/blog/blog.pl b/pttbbs/blog/blog.pl index 838fa676..c4984e7c 100755 --- a/pttbbs/blog/blog.pl +++ b/pttbbs/blog/blog.pl @@ -1,5 +1,5 @@ #!/usr/bin/perl -# $Id: blog.pl,v 1.28 2003/07/06 03:56:38 in2 Exp $ +# $Id: blog.pl,v 1.29 2003/07/08 04:09:36 in2 Exp $ use CGI qw/:standard/; use lib qw/./; use LocalVars; @@ -255,11 +255,14 @@ sub main my($dbh) = @_; my($t, $hash); $t = time(); + $name = $dbh->quote($name); + $mail = $dbh->quote($mail); + $comment = $dbh->quote($comment); $hash = MD5->hexhash("$t$th{key}$name$mail$comment"); $dbh->do('insert into comment '. '(brdname, artid, name, mail, content, mtime, hash) '. - "values ('$brdname', '$th{key}', '$name', '$mail', ". - "'$comment', '$t', '$hash')"); + "values ('$brdname', '$th{key}', $name, $mail, ". + "$comment, '$t', '$hash')"); }); } -- cgit v1.2.3 From 8139fd1ddae611a52ed7ef9e18424aaa571d9330 Mon Sep 17 00:00:00 2001 From: in2 Date: Tue, 8 Jul 2003 04:34:19 +0000 Subject: forward comments to mail git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@1042 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/blog/blog.pl | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/pttbbs/blog/blog.pl b/pttbbs/blog/blog.pl index c4984e7c..e3a91126 100755 --- a/pttbbs/blog/blog.pl +++ b/pttbbs/blog/blog.pl @@ -1,5 +1,5 @@ #!/usr/bin/perl -# $Id: blog.pl,v 1.29 2003/07/08 04:09:36 in2 Exp $ +# $Id: blog.pl,v 1.30 2003/07/08 04:34:19 in2 Exp $ use CGI qw/:standard/; use lib qw/./; use LocalVars; @@ -14,12 +14,13 @@ use DBI; use DBD::mysql; use POSIX; use MD5; +use Mail::Sender; use vars qw/@emonth @cnumber %config %attr %article %th $dbh $brdname/; sub main { - my($fn, $y, $m, $d); + my($fn, $y, $m, $d, $ofn); my($tmpl); $dbh = undef; @@ -33,8 +34,8 @@ sub main print header(-status => 400); return; } - if( !(($brdname, $fn) = $ENV{PATH_INFO} =~ m|^/([\w\-]+?)/([\.,\w]*)$|) || - !( ($fn, $y, $m, $d) = parsefn($fn) ) || + if( !(($brdname, $ofn) = $ENV{PATH_INFO} =~ m|^/([\w\-]+?)/([\.,\w]*)$|) || + !( ($fn, $y, $m, $d) = parsefn($ofn) ) || !(-e "$BLOGDATA/$brdname/$fn") || !(tie %config, 'DB_File', "$BLOGDATA/$brdname/config.db", O_RDONLY, 0666, $DB_HASH) || @@ -251,6 +252,22 @@ sub main param('mail'), param('comment')); if( $name && $comment ){ + if( $attr{"$fn.loadComments"} =~ /\@/ ){ + my $sr = new Mail::Sender{smtp => 'localhost'}; + $sr->MailMsg({from => '批踢踢部落格 ', + to => $attr{"$fn.loadComments"}, + subject => "您的部落格收到 $name 給您的迴響", + charset => 'big5', + msg => " +您的部落格 http://blog.ptt2.cc/blog.pl/$brdname/$ofn +剛才收到來自 $name <$mail> 給您的迴響 +-------------------------------------------------------------------- +$comment +-------------------------------------------------------------------- + (這封信件是由程式自動發出, 請不要直接回複這封信^^) +", + }); + } dodbi(sub { my($dbh) = @_; my($t, $hash); -- cgit v1.2.3 From 709f973a7fb0b23121b6b55257b0631df5a08784 Mon Sep 17 00:00:00 2001 From: in2 Date: Fri, 11 Jul 2003 02:20:36 +0000 Subject: better formatting git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@1043 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/udnnews.pl | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/pttbbs/util/udnnews.pl b/pttbbs/util/udnnews.pl index 1c49dc8c..21e3262c 100644 --- a/pttbbs/util/udnnews.pl +++ b/pttbbs/util/udnnews.pl @@ -22,7 +22,7 @@ foreach( @titles ){ postout({brdname => 'udnnews', title => strreplace(FormatChinese($_->[1])), owner => 'udnnews.', - content => getudnnewscontent("http://www.udn.com/NEWS/FOCUSNEWS/$_->[0]")}); + content => getudnnewscontent("http://www.udn.com/NEWS/FOCUSNEWS/$_->[0]", $_)}); } sub strreplace @@ -34,19 +34,17 @@ sub strreplace return $str; } -sub getudnnewscontent($) +sub getudnnewscontent($$) { - my($url) = @_; + my($url, $title) = @_; my($buf, $content, $ret); $buf = `$LYNX -source '$url'`; ($content) = $buf =~ m|(.*?)|s; # ($content) = $buf =~ m|

(.*?)

-[% IF gb %]蠶杺杺妗珛溶眳儕貌⑹[% ELSE %]批踢踢實業坊之精華區[% END %](experimental)
-[% IF gb %]醴ヶ枑鼎狟蹈儕貌⑹訧蹋[% ELSE %]目前提供下列精華區資料[% END %]:
+[% IF gb %]蠶杺杺妗珛溶眳儕貌⑹[% ELSE %]批踢踢實業坊之精華區[% END %](experimental)

[% FOREACH x=dat %] -[% x.brdname %]
+[% IF x.0 == -1 %] + + +[% ELSE %] + + +[% END %] +[% x.2 %]
[% END %]
diff --git a/pttbbs/staticweb/index.pl b/pttbbs/staticweb/index.pl index 71ad6117..6280ebd5 100755 --- a/pttbbs/staticweb/index.pl +++ b/pttbbs/staticweb/index.pl @@ -1,14 +1,16 @@ #!/usr/bin/perl -# $Id: index.pl,v 1.3 2003/07/05 05:19:18 in2 Exp $ +# $Id: index.pl,v 1.4 2003/07/11 10:11:24 in2 Exp $ use lib qw/./; use LocalVars; use CGI qw/:standard/; use strict; use Template; +use boardlist; +use b2g; sub main { - my($tmpl, %rh); + my($tmpl, %rh, $bid); if( param('gb') ){ $rh{gb} = 1; @@ -26,11 +28,20 @@ sub main charset(''); print header(); - foreach( ){ - s/.*\///; - s/\.db//; - push @{$rh{dat}}, {brdname => $_}; + ($bid) = $ENV{PATH_INFO} =~ m|^/(\d+)/$|; + $bid ||= 0; + + if( !$brd{$bid} ){ + print "sorry, this bid $bid not found :("; + return ; + } + + foreach( @{$brd{$bid}} ){ + next if( $_->[0] == -1 && ! -e "$MANDATA/$_->[1].db" ); + $_->[2] =~ s/([\xA1-\xF9].)/$b2g{$1}/eg if( $rh{gb} ); + push @{$rh{dat}}, $_; } + $tmpl = Template->new({INCLUDE_PATH => '.', ABSOLUTE => 0, RELATIVE => 0, -- cgit v1.2.3 From 2d078659df246856c75e831a1d28a6f7f57dab97 Mon Sep 17 00:00:00 2001 From: in2 Date: Fri, 11 Jul 2003 10:13:49 +0000 Subject: remove require and add comments git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@1049 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/boardlist.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pttbbs/util/boardlist.c b/pttbbs/util/boardlist.c index be1c8111..bb23393a 100644 --- a/pttbbs/util/boardlist.c +++ b/pttbbs/util/boardlist.c @@ -1,4 +1,5 @@ -/* $Id: boardlist.c,v 1.2 2003/07/11 09:03:42 in2 Exp $ */ +/* $Id: boardlist.c,v 1.3 2003/07/11 10:13:49 in2 Exp $ */ +/* 這是用來將樹狀分類輸出成 perl module (可以給像是 man/ 使用) */ #include "bbs.h" static void @@ -87,7 +88,6 @@ int main(int argc, char **argv) "# please do NOT modify this directly\n" "\n" "package boardlist;\n" - "require 5.6;\n" "use Exporter;\n" "$VERSION = '0.1';\n" "use vars qw(%%brd);\n" -- cgit v1.2.3 From a9113c230287f83e7a30541940060ee41363659e Mon Sep 17 00:00:00 2001 From: bbs Date: Sun, 13 Jul 2003 11:47:18 +0000 Subject: fix rule git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@1050 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/user.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pttbbs/mbbsd/user.c b/pttbbs/mbbsd/user.c index 553021cc..cd80d57b 100644 --- a/pttbbs/mbbsd/user.c +++ b/pttbbs/mbbsd/user.c @@ -1,4 +1,4 @@ -/* $Id: user.c,v 1.66 2003/07/06 06:45:51 in2 Exp $ */ +/* $Id: user.c,v 1.67 2003/07/13 11:47:18 bbs Exp $ */ #include "bbs.h" static char *sex[8] = { @@ -869,6 +869,8 @@ ispersonalid(char *inid) i = cksum = 0; if (!isalpha(id[0]) && (strlen(id) != 10)) return 0; + if (!(id[1] == '1' || id[1] == '2')) + return 0; id[0] = toupper(id[0]); if( strcmp(id, "A100000001") == 0 || -- cgit v1.2.3 From 994b9559295f9d5bd19581e71027b3a74fff2403 Mon Sep 17 00:00:00 2001 From: victor Date: Mon, 14 Jul 2003 07:22:10 +0000 Subject: for porting to linux git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@1051 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/pttbbs.mk | 7 ++++--- pttbbs/util/Makefile | 14 ++++++++------ 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/pttbbs/pttbbs.mk b/pttbbs/pttbbs.mk index 6822c537..3d138fe5 100644 --- a/pttbbs/pttbbs.mk +++ b/pttbbs/pttbbs.mk @@ -1,8 +1,8 @@ -# $Id: pttbbs.mk,v 1.5 2003/06/28 08:55:40 kcwu Exp $ +# $Id: pttbbs.mk,v 1.6 2003/07/14 07:22:09 victor Exp $ # 定義基本初值 BBSHOME?= $(HOME) BBSHOME?= /home/bbs -OSTYPE?= FreeBSD +OSTYPE?= Linux CC?= gcc CCACHE!= which ccache|sed -e 's/^.*\///' PTT_CFLAGS= -Wall -pipe -DBBSHOME='"$(BBSHOME)"' -I../include @@ -18,7 +18,8 @@ LDFLAGS_FreeBSD= LIBS_FreeBSD= -lkvm # Linux特有的環境 -CFLAGS_linux= -DHAVE_DES_CRYPT -DLinux +# CFLAGS_linux= -DHAVE_DES_CRYPT -DLinux +CFLAGS_linux= -DLinux LDFLAGS_linux= -pipe -Wall LIBS_linux= diff --git a/pttbbs/util/Makefile b/pttbbs/util/Makefile index baf0bf6a..5bd45409 100644 --- a/pttbbs/util/Makefile +++ b/pttbbs/util/Makefile @@ -1,19 +1,18 @@ -# $Id: Makefile,v 1.32 2003/07/11 09:03:21 in2 Exp $ +# $Id: Makefile,v 1.33 2003/07/14 07:22:10 victor Exp $ .include "../pttbbs.mk" UTIL_OBJS= \ - util_cache.o util_record.o util_passwd.o + util_cache.o util_record.o util_passwd.o # 下面這些程式, 會被 compile 並且和 $(UTIL_OBJS) 聯結 CPROG_WITH_UTIL= \ - bbsmail BM_money post poststat \ + boardlist BM_money post poststat \ jungo account birth deluserfile \ expire mandex rmuid horoscope \ openvice parse_news openticket topusr \ indexuser yearsold toplazyBM toplazyBBM \ - reaper buildAnnounce inndBM shmctl \ - boardlist + reaper buildAnnounce inndBM shmctl # 下面這些程式, 會直接被 compile CPROG_WITHOUT_UTIL= \ @@ -30,13 +29,16 @@ PROGS= ${UTIL_OBJS} ${CPROG_WITH_UTIL} ${CPROG_WITHOUT_UTIL} \ dailybackup.pl tarqueue.pl waterball.pl filtermail.pl \ getbackup.pl udnnews.pl rebuildaloha.pl railway_wrapper.pl -all: ${CPROG_WITH_UTIL} ${CPROG_WITHOUT_UTIL} ${PROGS} +all: ${CPROG_WITH_UTIL} ${CPROG_WITHOUT_UTIL} ${PROGS} bbsmail .for fn in ${CPROG_WITH_UTIL} ${fn}: ${fn}.c ${UTIL_OBJS} ${CC} ${CFLAGS} -o ${fn} ${fn}.c ${UTIL_OBJS} .endfor +bbsmail: bbsmail.c ${CPROG_WITH_UTIL} ../mbbsd/osdep.o + ${CC} ${CFLAGS} -o bbsmail bbsmail.c ${UTIL_OBJS} ../mbbsd/osdep.o + xchatd: xchatd.c $(UTIL_OBJS) descrypt.c $(CC) $(CFLAGS) -o $@ $@.c $(UTIL_OBJS) descrypt.c $(LIBCHAT) -- cgit v1.2.3 From c4309ceca3c3a46ff57e2719af2a53e9e6437171 Mon Sep 17 00:00:00 2001 From: in2 Date: Tue, 15 Jul 2003 09:07:27 +0000 Subject: class hierarchy support git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@1052 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/staticweb/index.html | 42 +++++++++++++++++++++++++++++++----------- pttbbs/staticweb/index.pl | 15 +++++++++++++-- 2 files changed, 44 insertions(+), 13 deletions(-) diff --git a/pttbbs/staticweb/index.html b/pttbbs/staticweb/index.html index 45372764..6ad6e831 100644 --- a/pttbbs/staticweb/index.html +++ b/pttbbs/staticweb/index.html @@ -5,18 +5,38 @@
-[% IF gb %]蠶杺杺妗珛溶眳儕貌⑹[% ELSE %]批踢踢實業坊之精華區[% END %](experimental)
-
-[% FOREACH x=dat %] -[% IF x.0 == -1 %] - - -[% ELSE %] - - -[% END %] -[% x.2 %]
+[% IF gb %]蠶杺杺妗珛溶眳儕貌⑹[% ELSE %]批踢踢實業坊之精華區[% END %] +[% FOREACH x=class %] +»[% x.title %] [% END %] +
+
+ + [% IF !isroot %] + + + + + + [% END %] + [% FOREACH x=dat %] + + + + + + [% END %] +
+ + + + 返回上一層 +
+ + [% x.1 %] + [% IF x.0 == -1 %][% ELSE %][% END %] + [% x.2 %] +

diff --git a/pttbbs/staticweb/index.pl b/pttbbs/staticweb/index.pl index 6280ebd5..cb475725 100755 --- a/pttbbs/staticweb/index.pl +++ b/pttbbs/staticweb/index.pl @@ -1,5 +1,5 @@ #!/usr/bin/perl -# $Id: index.pl,v 1.4 2003/07/11 10:11:24 in2 Exp $ +# $Id: index.pl,v 1.5 2003/07/15 09:07:27 in2 Exp $ use lib qw/./; use LocalVars; use CGI qw/:standard/; @@ -25,11 +25,15 @@ sub main $rh{charset} = 'big5'; } + return redirect('/index.pl/'.($rh{gb}?'?gb=1':'')) + if( $ENV{REQUEST_URI} eq '/' ); + charset(''); print header(); - ($bid) = $ENV{PATH_INFO} =~ m|^/(\d+)/$|; + ($bid) = $ENV{PATH_INFO} =~ m|.*/(\d+)/$|; $bid ||= 0; + $rh{isroot} = ($bid == 0); if( !$brd{$bid} ){ print "sorry, this bid $bid not found :("; @@ -42,6 +46,13 @@ sub main push @{$rh{dat}}, $_; } + my $path = ''; + foreach( $ENV{PATH_INFO} =~ m|(\w+)|g ){ + push @{$rh{class}}, {path => "$path/$_/", + title => $brd{"$_.title"}}; + $path .= "/$_"; + } + $tmpl = Template->new({INCLUDE_PATH => '.', ABSOLUTE => 0, RELATIVE => 0, -- cgit v1.2.3 From c16a944a81a28aa2f13173e5421ba0d97749caac Mon Sep 17 00:00:00 2001 From: in2 Date: Thu, 17 Jul 2003 00:56:39 +0000 Subject: register git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@1053 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/user.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pttbbs/mbbsd/user.c b/pttbbs/mbbsd/user.c index cd80d57b..1a8fd81d 100644 --- a/pttbbs/mbbsd/user.c +++ b/pttbbs/mbbsd/user.c @@ -1,4 +1,4 @@ -/* $Id: user.c,v 1.67 2003/07/13 11:47:18 bbs Exp $ */ +/* $Id: user.c,v 1.68 2003/07/17 00:56:39 in2 Exp $ */ #include "bbs.h" static char *sex[8] = { @@ -1080,7 +1080,7 @@ static char *isvalidname(char *rname) char *rejectstr[] = {"肥", "胖", "豬頭", "小白", "小明", "路人", "老王", "老李", "寶貝", "先生", "師哥", "老頭", "小姊", "小姐", "美女", "小妹", "大頭", - "公主", "同學", "寶寶", "公子", "大頭", NULL}; + "公主", "同學", "寶寶", "公子", "大頭", "佚名", NULL}; if( removespace(rname) && rname[0] < 0 && strlen(rname) >= 4 && !HaveRejectStr(rname, rejectstr) && @@ -1107,7 +1107,7 @@ static char *isvalidcareer(char *career) static char *isvalidaddr(char *addr) { char *rejectstr[] = - {"地球", "銀河", "火星", NULL}; + {"地球", "銀河", "火星", "附近", NULL}; if (!removespace(addr) || addr[0] > 0 || strlen(addr) < 15) return "這個地址並不合法"; -- cgit v1.2.3 From f03487bbd42b9b3fb500284d58c0c6888f2aa1c6 Mon Sep 17 00:00:00 2001 From: in2 Date: Thu, 17 Jul 2003 00:57:21 +0000 Subject: reduce SHM size(remove realname) git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@1054 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/include/pttstruct.h | 8 +++----- pttbbs/mbbsd/mbbsd.c | 7 +++---- pttbbs/mbbsd/user.c | 8 ++++---- 3 files changed, 10 insertions(+), 13 deletions(-) diff --git a/pttbbs/include/pttstruct.h b/pttbbs/include/pttstruct.h index d693f985..a69f48cc 100644 --- a/pttbbs/include/pttstruct.h +++ b/pttbbs/include/pttstruct.h @@ -1,4 +1,4 @@ -/* $Id: pttstruct.h,v 1.39 2003/07/05 07:58:09 in2 Exp $ */ +/* $Id: pttstruct.h,v 1.40 2003/07/17 00:57:21 in2 Exp $ */ #ifndef INCLUDE_STRUCT_H #define INCLUDE_STRUCT_H @@ -221,7 +221,6 @@ typedef struct userinfo_t { unsigned char sig; /* signal type */ char userid[IDLEN + 1]; char chatid[11]; /* chat id, if in chat mode */ - char realname[20]; char username[24]; char from[27]; /* machine name the user called in from */ int from_alias; @@ -231,7 +230,6 @@ typedef struct userinfo_t { int friend_online[MAX_FRIEND];/* point到線上好友 utmpshm的位置 */ /* 好友比較的cache 前兩個bit是狀態 */ int reject[MAX_REJECT]; - char pad[4]; /* original void *nextbfriend; */ int idoffset; /* shm id上的 offset */ int lock; int friendtotal; /* 好友比較的cache 大小 */ @@ -249,8 +247,8 @@ typedef struct userinfo_t { unsigned short int chc_win; unsigned short int chc_lose; unsigned short int chc_tie; - int mailalert; - int sex; + char mailalert; + char sex; char color; char mind[4]; } userinfo_t; diff --git a/pttbbs/mbbsd/mbbsd.c b/pttbbs/mbbsd/mbbsd.c index a20188a6..da5c6c94 100644 --- a/pttbbs/mbbsd/mbbsd.c +++ b/pttbbs/mbbsd/mbbsd.c @@ -1,4 +1,4 @@ -/* $Id: mbbsd.c,v 1.88 2003/07/05 07:58:09 in2 Exp $ */ +/* $Id: mbbsd.c,v 1.89 2003/07/17 00:57:21 in2 Exp $ */ #include "bbs.h" #define SOCKET_QLEN 4 @@ -722,7 +722,7 @@ setup_utmp(int mode) uinfo.sex = cuser.sex % 8; uinfo.lastact = time(NULL); strlcpy(uinfo.userid, cuser.userid, sizeof(uinfo.userid)); - strlcpy(uinfo.realname, cuser.realname, sizeof(uinfo.realname)); + //strlcpy(uinfo.realname, cuser.realname, sizeof(uinfo.realname)); strlcpy(uinfo.username, cuser.username, sizeof(uinfo.username)); strlcpy(uinfo.from, fromhost, sizeof(uinfo.from)); uinfo.five_win = cuser.five_win; @@ -863,8 +863,7 @@ user_login() strlcpy(currutmp->username, cuser.username, sizeof(currutmp->username)); strlcpy(cuser.realname, name[(int)i], sizeof(cuser.realname)); - strlcpy(currutmp->realname, cuser.realname, - sizeof(currutmp->realname)); + //strlcpy(currutmp->realname, cuser.realname, sizeof(currutmp->realname)); strlcpy(cuser.address, addr[(int)i], sizeof(cuser.address)); cuser.sex = i % 8; currutmp->pager = 2; diff --git a/pttbbs/mbbsd/user.c b/pttbbs/mbbsd/user.c index 1a8fd81d..c706b741 100644 --- a/pttbbs/mbbsd/user.c +++ b/pttbbs/mbbsd/user.c @@ -1,4 +1,4 @@ -/* $Id: user.c,v 1.68 2003/07/17 00:56:39 in2 Exp $ */ +/* $Id: user.c,v 1.69 2003/07/17 00:57:21 in2 Exp $ */ #include "bbs.h" static char *sex[8] = { @@ -644,7 +644,7 @@ u_info() move(2, 0); user_display(&cuser, 0); uinfo_query(&cuser, 0, usernum); - strlcpy(currutmp->realname, cuser.realname, sizeof(currutmp->realname)); + //strlcpy(currutmp->realname, cuser.realname, sizeof(currutmp->realname)); strlcpy(currutmp->username, cuser.username, sizeof(currutmp->username)); return 0; } @@ -1080,7 +1080,7 @@ static char *isvalidname(char *rname) char *rejectstr[] = {"肥", "胖", "豬頭", "小白", "小明", "路人", "老王", "老李", "寶貝", "先生", "師哥", "老頭", "小姊", "小姐", "美女", "小妹", "大頭", - "公主", "同學", "寶寶", "公子", "大頭", "佚名", NULL}; + "公主", "同學", "寶寶", "公子", "大頭", NULL}; if( removespace(rname) && rname[0] < 0 && strlen(rname) >= 4 && !HaveRejectStr(rname, rejectstr) && @@ -1107,7 +1107,7 @@ static char *isvalidcareer(char *career) static char *isvalidaddr(char *addr) { char *rejectstr[] = - {"地球", "銀河", "火星", "附近", NULL}; + {"地球", "銀河", "火星", NULL}; if (!removespace(addr) || addr[0] > 0 || strlen(addr) < 15) return "這個地址並不合法"; -- cgit v1.2.3 From 9004ef4a9f06a9c0ab5ac611bad41e7318e402e9 Mon Sep 17 00:00:00 2001 From: in2 Date: Thu, 17 Jul 2003 01:33:14 +0000 Subject: remove gap and add BMcache git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@1055 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/include/pttstruct.h | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/pttbbs/include/pttstruct.h b/pttbbs/include/pttstruct.h index a69f48cc..64f2bd90 100644 --- a/pttbbs/include/pttstruct.h +++ b/pttbbs/include/pttstruct.h @@ -1,4 +1,4 @@ -/* $Id: pttstruct.h,v 1.40 2003/07/17 00:57:21 in2 Exp $ */ +/* $Id: pttstruct.h,v 1.41 2003/07/17 01:33:14 in2 Exp $ */ #ifndef INCLUDE_STRUCT_H #define INCLUDE_STRUCT_H @@ -317,10 +317,9 @@ typedef struct { int UTMPnumber; char UTMPneedsort; char UTMPbusystate; - char pad[2]; - char gap[1024]; /* avoid some memory error / buffer overflow */ /* brdshm */ + int BMcache[MAX_BOARD][4]; boardheader_t bcache[MAX_BOARD]; boardheader_t *bsorted[2][MAX_BOARD]; /* 0: by name 1: by class */ fileheader_t dircache[MAX_BOARD][DIRCACHESIZE]; @@ -334,7 +333,6 @@ typedef struct { int Bbusystate; time_t close_vote_time; - char gap2[1020]; /* avoid some memory error / buffer overflow */ /* pttcache */ char notes[MAX_MOVIE][200*11]; char today_is[20]; @@ -349,9 +347,8 @@ typedef struct { int GLOBALVAR[10]; /* mbbsd間的 global variable 用以做統計等資料 (非常態) */ - char gap3_1[128]; /* gap3 1024 bytes */ union { - int v[192]; + int v[256]; struct { int dymaxactive; /* 動態設定最大人數上限 */ int toomanyusers; /* 超過人數上限不給進的個數 */ @@ -362,7 +359,6 @@ typedef struct { int nWelcomes; } e; } GV2; - char gap3_2[128]; /* fromcache */ char domain[MAX_FROM][50]; -- cgit v1.2.3 From 944fa43afc342444ae1a3ab3c76910567fe552b1 Mon Sep 17 00:00:00 2001 From: victor Date: Thu, 17 Jul 2003 03:27:29 +0000 Subject: random signature git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@1056 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/include/proto.h | 4 ++-- pttbbs/include/pttstruct.h | 6 +++--- pttbbs/mbbsd/edit.c | 19 +++++++++++-------- pttbbs/mbbsd/user.c | 16 ++++++++-------- 4 files changed, 24 insertions(+), 21 deletions(-) diff --git a/pttbbs/include/proto.h b/pttbbs/include/proto.h index a460650d..f02f7c1d 100644 --- a/pttbbs/include/proto.h +++ b/pttbbs/include/proto.h @@ -1,4 +1,4 @@ -/* $Id: proto.h,v 1.44 2003/05/26 05:23:13 in2 Exp $ */ +/* $Id: proto.h,v 1.45 2003/07/17 03:27:27 victor Exp $ */ #ifndef INCLUDE_PROTO_H #define INCLUDE_PROTO_H @@ -524,7 +524,7 @@ int topsong(); int u_editcalendar(); void user_display(userec_t *u, int real); void uinfo_query(userec_t *u, int real, int unum); -int showsignature(char *fname); +int showsignature(char *fname, int *j); void mail_violatelaw(char* crime, char* police, char* reason, char* result); void showplans(char *uid); int u_info(); diff --git a/pttbbs/include/pttstruct.h b/pttbbs/include/pttstruct.h index 64f2bd90..d34e8f3a 100644 --- a/pttbbs/include/pttstruct.h +++ b/pttbbs/include/pttstruct.h @@ -1,4 +1,4 @@ -/* $Id: pttstruct.h,v 1.41 2003/07/17 01:33:14 in2 Exp $ */ +/* $Id: pttstruct.h,v 1.42 2003/07/17 03:27:27 victor Exp $ */ #ifndef INCLUDE_STRUCT_H #define INCLUDE_STRUCT_H @@ -75,10 +75,10 @@ typedef struct userec_t { char mind[4]; char ident[11]; unsigned int uflag2; - char pad[72]; + unsigned char signature; + char pad[71]; } userec_t; /* these are flags in userec_t.uflag */ -#define SIG_FLAG 0x3 /* signature number, 2 bits */ #define PAGER_FLAG 0x4 /* true if pager was OFF last session */ #define CLOAK_FLAG 0x8 /* true if cloak was ON last session */ #define FRIEND_FLAG 0x10 /* true if show friends only */ diff --git a/pttbbs/mbbsd/edit.c b/pttbbs/mbbsd/edit.c index c3e2fdc5..81fc73da 100644 --- a/pttbbs/mbbsd/edit.c +++ b/pttbbs/mbbsd/edit.c @@ -1,4 +1,4 @@ -/* $Id: edit.c,v 1.36 2003/06/28 08:47:45 kcwu Exp $ */ +/* $Id: edit.c,v 1.37 2003/07/17 03:27:29 victor Exp $ */ /* edit.c, 用來提供 bbs上的文字編輯器, 即 ve. * 現在這一個是惡搞過的版本, 比較不穩定, 用比較多的 cpu, 但是可以省下許多 * 的記憶體 (以 Ptt為例, 在九千人上站的時候, 約可省下 50MB 的記憶體) @@ -895,11 +895,11 @@ void addsignature(FILE * fp, int ifuseanony) { FILE *fs; - int i; + int i, num; char buf[WRAPMARGIN + 1]; char fpath[STRLEN]; - static char msg[] = "請選擇簽名檔 (1-9, 0=不加)[0]: "; + static char msg[] = "請選擇簽名檔 (1-9, 0=不加 X=隨機)[X]: "; char ch; if (!strcmp(cuser.userid, STR_GUEST)) { @@ -908,13 +908,16 @@ addsignature(FILE * fp, int ifuseanony) return; } if (!ifuseanony) { - i = showsignature(fpath); - msg[27] = ch = '0' | (cuser.uflag & SIG_FLAG); + num = showsignature(fpath, &i); + msg[34] = ch = isdigit(cuser.signature) ? cuser.signature : 'X'; getdata(0, 0, msg, buf, 4, DOECHO); - if (ch != buf[0] && buf[0] >= '0' && buf[0] <= '9') { - ch = buf[0]; - cuser.uflag = (cuser.uflag & ~SIG_FLAG) | (ch & SIG_FLAG); + if (buf[0] == 0 || buf[0] == 'x' || isdigit(buf[0])) { + if (isdigit(buf[0])) + ch = buf[0]; + else + ch = '1' + rand() % num; + cuser.signature = buf[0]; } if (ch != '0') { fpath[i] = ch; diff --git a/pttbbs/mbbsd/user.c b/pttbbs/mbbsd/user.c index c706b741..4e12167d 100644 --- a/pttbbs/mbbsd/user.c +++ b/pttbbs/mbbsd/user.c @@ -1,4 +1,4 @@ -/* $Id: user.c,v 1.69 2003/07/17 00:57:21 in2 Exp $ */ +/* $Id: user.c,v 1.70 2003/07/17 03:27:29 victor Exp $ */ #include "bbs.h" static char *sex[8] = { @@ -712,29 +712,29 @@ showplans(char *uid) } int -showsignature(char *fname) +showsignature(char *fname, int *j) { FILE *fp; char buf[256]; - int i, j; + int i, num = 0; char ch; clear(); move(2, 0); setuserfile(fname, "sig.0"); - j = strlen(fname) - 1; + *j = strlen(fname) - 1; for (ch = '1'; ch <= '9'; ch++) { - fname[j] = ch; + fname[*j] = ch; if ((fp = fopen(fname, "r"))) { prints("\033[36m【 簽名檔.%c 】\033[m\n", ch); for (i = 0; i < MAX_SIGLINES && fgets(buf, sizeof(buf), fp); i++) outs(buf); - + num++; fclose(fp); } } - return j; + return num; } int @@ -745,7 +745,7 @@ u_editsig() int j; char genbuf[200]; - j = showsignature(genbuf); + showsignature(genbuf, &j); getdata(0, 0, "簽名檔 (E)編輯 (D)刪除 (Q)取消?[Q] ", ans, sizeof(ans), LCECHO); -- cgit v1.2.3 From c23f452daeffe23e6887561fe7cb850c2541f7a5 Mon Sep 17 00:00:00 2001 From: victor Date: Thu, 17 Jul 2003 03:47:26 +0000 Subject: wrong default OS :p git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@1057 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/pttbbs.mk | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pttbbs/pttbbs.mk b/pttbbs/pttbbs.mk index 3d138fe5..7b69dda6 100644 --- a/pttbbs/pttbbs.mk +++ b/pttbbs/pttbbs.mk @@ -1,8 +1,8 @@ -# $Id: pttbbs.mk,v 1.6 2003/07/14 07:22:09 victor Exp $ +# $Id: pttbbs.mk,v 1.7 2003/07/17 03:47:26 victor Exp $ # 定義基本初值 BBSHOME?= $(HOME) BBSHOME?= /home/bbs -OSTYPE?= Linux +OSTYPE?= FreeBSD CC?= gcc CCACHE!= which ccache|sed -e 's/^.*\///' PTT_CFLAGS= -Wall -pipe -DBBSHOME='"$(BBSHOME)"' -I../include -- cgit v1.2.3 From 5c05177ac6eedad1f6cc8dc31923fcadbbc1ab14 Mon Sep 17 00:00:00 2001 From: victor Date: Thu, 17 Jul 2003 04:35:07 +0000 Subject: fix last commit error git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@1058 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/edit.c | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/pttbbs/mbbsd/edit.c b/pttbbs/mbbsd/edit.c index 81fc73da..56dc46cf 100644 --- a/pttbbs/mbbsd/edit.c +++ b/pttbbs/mbbsd/edit.c @@ -1,4 +1,4 @@ -/* $Id: edit.c,v 1.37 2003/07/17 03:27:29 victor Exp $ */ +/* $Id: edit.c,v 1.38 2003/07/17 04:35:07 victor Exp $ */ /* edit.c, 用來提供 bbs上的文字編輯器, 即 ve. * 現在這一個是惡搞過的版本, 比較不穩定, 用比較多的 cpu, 但是可以省下許多 * 的記憶體 (以 Ptt為例, 在九千人上站的時候, 約可省下 50MB 的記憶體) @@ -909,24 +909,25 @@ addsignature(FILE * fp, int ifuseanony) } if (!ifuseanony) { num = showsignature(fpath, &i); - msg[34] = ch = isdigit(cuser.signature) ? cuser.signature : 'X'; - getdata(0, 0, msg, buf, 4, DOECHO); + if (num){ + msg[34] = ch = isdigit(cuser.signature) ? cuser.signature : 'X'; + getdata(0, 0, msg, buf, 4, DOECHO); - if (buf[0] == 0 || buf[0] == 'x' || isdigit(buf[0])) { if (isdigit(buf[0])) ch = buf[0]; else ch = '1' + rand() % num; cuser.signature = buf[0]; - } - if (ch != '0') { - fpath[i] = ch; - if ((fs = fopen(fpath, "r"))) { - fputs("\n--\n", fp); - for (i = 0; i < MAX_SIGLINES && - fgets(buf, sizeof(buf), fs); i++) - fputs(buf, fp); - fclose(fs); + + if (ch != '0') { + fpath[i] = ch; + if ((fs = fopen(fpath, "r"))) { + fputs("\n--\n", fp); + for (i = 0; i < MAX_SIGLINES && + fgets(buf, sizeof(buf), fs); i++) + fputs(buf, fp); + fclose(fs); + } } } } -- cgit v1.2.3 From 38803994d0bae4203b5a641c553399d5b1277540 Mon Sep 17 00:00:00 2001 From: victor Date: Thu, 17 Jul 2003 06:11:14 +0000 Subject: fix last commit bug git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@1059 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/edit.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pttbbs/mbbsd/edit.c b/pttbbs/mbbsd/edit.c index 56dc46cf..202157ae 100644 --- a/pttbbs/mbbsd/edit.c +++ b/pttbbs/mbbsd/edit.c @@ -1,4 +1,4 @@ -/* $Id: edit.c,v 1.38 2003/07/17 04:35:07 victor Exp $ */ +/* $Id: edit.c,v 1.39 2003/07/17 06:11:14 victor Exp $ */ /* edit.c, 用來提供 bbs上的文字編輯器, 即 ve. * 現在這一個是惡搞過的版本, 比較不穩定, 用比較多的 cpu, 但是可以省下許多 * 的記憶體 (以 Ptt為例, 在九千人上站的時候, 約可省下 50MB 的記憶體) @@ -913,6 +913,9 @@ addsignature(FILE * fp, int ifuseanony) msg[34] = ch = isdigit(cuser.signature) ? cuser.signature : 'X'; getdata(0, 0, msg, buf, 4, DOECHO); + if (!buf[0]) + buf[0] = ch; + if (isdigit(buf[0])) ch = buf[0]; else -- cgit v1.2.3 From 9c5d975e391467b11758bba4715426d980abd6af Mon Sep 17 00:00:00 2001 From: in2 Date: Thu, 17 Jul 2003 07:58:45 +0000 Subject: add LDFLAG in bbsmail git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@1060 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pttbbs/util/Makefile b/pttbbs/util/Makefile index 5bd45409..c1a099bb 100644 --- a/pttbbs/util/Makefile +++ b/pttbbs/util/Makefile @@ -1,4 +1,4 @@ -# $Id: Makefile,v 1.33 2003/07/14 07:22:10 victor Exp $ +# $Id: Makefile,v 1.34 2003/07/17 07:58:45 in2 Exp $ .include "../pttbbs.mk" @@ -37,7 +37,7 @@ ${fn}: ${fn}.c ${UTIL_OBJS} .endfor bbsmail: bbsmail.c ${CPROG_WITH_UTIL} ../mbbsd/osdep.o - ${CC} ${CFLAGS} -o bbsmail bbsmail.c ${UTIL_OBJS} ../mbbsd/osdep.o + ${CC} ${CFLAGS} -o bbsmail bbsmail.c ${UTIL_OBJS} ../mbbsd/osdep.o ${LDFLAGS} xchatd: xchatd.c $(UTIL_OBJS) descrypt.c $(CC) $(CFLAGS) -o $@ $@.c $(UTIL_OBJS) descrypt.c $(LIBCHAT) -- cgit v1.2.3 From 38a55293fab9c0f81afd3246deae127e29fa070a Mon Sep 17 00:00:00 2001 From: in2 Date: Fri, 18 Jul 2003 09:28:53 +0000 Subject: correct files git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@1061 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/sample/etc/Makefile | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/pttbbs/sample/etc/Makefile b/pttbbs/sample/etc/Makefile index 2cc29755..154d39d9 100644 --- a/pttbbs/sample/etc/Makefile +++ b/pttbbs/sample/etc/Makefile @@ -1,8 +1,12 @@ SUBDIR=chickens BBSHOME?=$(HOME) TARGET=$(BBSHOME)/etc/ -FILES= Welcome Welcome_login goodbye register registered ve.hlp Logout\ - Welcome_birth domain_name_query feast today_boring @five MRT.map +FILES= @five Welcome register today_boring \ + Welcome_birth domain_name_query registered \ + ve.hlp Logout Welcome_login expire.conf \ + registeredmail MRT.map bad_host feast \ + registermail Makefile banemail goodbye \ + sysop all: -- cgit v1.2.3 From e7e78a97b4917e6cbfcc6a807007a11353c91eff Mon Sep 17 00:00:00 2001 From: victor Date: Fri, 18 Jul 2003 11:03:45 +0000 Subject: not allow a foreigner with Taiwan ID git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@1062 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/user.c | 35 +++++++++++++---------------------- 1 file changed, 13 insertions(+), 22 deletions(-) diff --git a/pttbbs/mbbsd/user.c b/pttbbs/mbbsd/user.c index 4e12167d..39a68c0b 100644 --- a/pttbbs/mbbsd/user.c +++ b/pttbbs/mbbsd/user.c @@ -1,4 +1,4 @@ -/* $Id: user.c,v 1.70 2003/07/17 03:27:29 victor Exp $ */ +/* $Id: user.c,v 1.71 2003/07/18 11:03:45 victor Exp $ */ #include "bbs.h" static char *sex[8] = { @@ -321,11 +321,10 @@ uinfo_query(userec_t * u, int real, int unum) getdata_buf(i++, 0, "真實姓名:", x.realname, sizeof(x.realname), DOECHO); #ifdef FOREIGN_REG - getdata_buf(i++, 0, cuser.uflag2 & FOREIGN ? "護照號碼" : "身分證號:", + getdata_buf(i++, 0, cuser.uflag2 & FOREIGN ? "護照號碼" : "身分證號:", x.ident, sizeof(x.ident), DOECHO); #else - getdata_buf(i++, 0, "身分證號:", + getdata_buf(i++, 0, "身分證號:", x.ident, sizeof(x.ident), DOECHO); #endif - x.ident, sizeof(x.ident), DOECHO); getdata_buf(i++, 0, "居住地址:", x.address, sizeof(x.address), DOECHO); } @@ -1252,25 +1251,13 @@ u_register(void) prints("%s(%s) 您好,請據實填寫以下的資料:", cuser.userid, cuser.username); #ifdef FOREIGN_REG - while (1) { - getfield(2, "Y/n", "是否為本國籍?", fore, 2); - fore[0] = tolower(fore[0]); - if (fore[0] == 'y'){ - fore[0] = '\0'; - break; - } - else if (fore[0] == 'n'){ - getdata(4, 0, "是否確定(Y/N)", ans, sizeof(ans), LCECHO); - if (ans[0] == 'y' || ans[0] == 'Y'){ - fore[0] |= FOREIGN; - break; - } - } - } + getfield(2, "Y/n", "是否為本國籍?", fore, 2); + if (fore[0] == 'n') + fore[0] |= FOREIGN; if (!fore[0]){ #endif while( 1 ){ - getfield(5, "D123456789", "身分證號", ident, 11); + getfield(3, "D123456789", "身分證號", ident, 11); if ('a' <= ident[0] && ident[0] <= 'z') ident[0] -= 32; if( ispersonalid(ident) ) @@ -1281,12 +1268,16 @@ u_register(void) } else{ while( 1 ){ - getfield(5, "0123456789", "護照號碼", ident, 11); - getdata(7, 0, "是否確定(Y/N)", ans, sizeof(ans), LCECHO); + getfield(3, "0123456789", "護照號碼", ident, 11); + getdata(6, 0, "是否確定(Y/N)", ans, sizeof(ans), LCECHO); if (ans[0] == 'y' || ans[0] == 'Y') break; vmsg("請重新輸入(若有問題麻煩至SYSOP板)"); } + if( ispersonalid(ident) ){ + vmsg("請以本國籍身份註冊"); + continue; + } } #endif while (1) { -- cgit v1.2.3 From 0baac29ac307d631a2dbba908cd695c1101dbbbb Mon Sep 17 00:00:00 2001 From: in2 Date: Sat, 19 Jul 2003 01:26:33 +0000 Subject: fix bug of SYSOP broadcast git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@1063 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/talk.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pttbbs/mbbsd/talk.c b/pttbbs/mbbsd/talk.c index 239c2ded..8246801b 100644 --- a/pttbbs/mbbsd/talk.c +++ b/pttbbs/mbbsd/talk.c @@ -1,4 +1,4 @@ -/* $Id: talk.c,v 1.111 2003/07/06 07:23:10 in2 Exp $ */ +/* $Id: talk.c,v 1.112 2003/07/19 01:26:33 in2 Exp $ */ #include "bbs.h" #define QCAST int (*)(const void *, const void *) @@ -2116,9 +2116,9 @@ userlist(void) *ans == 'n') break; if (!(cuser.uflag & FRIEND_FLAG) && HAS_PERM(PERM_SYSOP)) { - if( getdata(1, 0, "再次確定站長廣播? [N]", - ans, sizeof(ans), LCECHO) && - *ans != 'y' && *ans != 'Y' ){ + getdata(1, 0, "再次確定站長廣播? [N]", + ans, sizeof(ans), LCECHO); + if( *ans != 'y' && *ans != 'Y' ){ vmsg("abort"); break; } -- cgit v1.2.3 From 351efd4c05836d683c16ecc3f1576b9d6f30f81f Mon Sep 17 00:00:00 2001 From: in2 Date: Sat, 19 Jul 2003 09:33:34 +0000 Subject: add bbsmail to CPROG_WITHOUT_UTIL git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@1064 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pttbbs/util/Makefile b/pttbbs/util/Makefile index c1a099bb..2f11c9ea 100644 --- a/pttbbs/util/Makefile +++ b/pttbbs/util/Makefile @@ -1,4 +1,4 @@ -# $Id: Makefile,v 1.34 2003/07/17 07:58:45 in2 Exp $ +# $Id: Makefile,v 1.35 2003/07/19 09:33:34 in2 Exp $ .include "../pttbbs.mk" @@ -19,7 +19,7 @@ CPROG_WITHOUT_UTIL= \ shmsweep uhash_loader showboard antispam \ countalldice webgrep bbsrf initbbs \ userlist tunepasswd buildir merge_passwd \ - merge_board xchatd outmail + merge_board xchatd outmail bbsmail # 下面這些程式會被 install PROGS= ${UTIL_OBJS} ${CPROG_WITH_UTIL} ${CPROG_WITHOUT_UTIL} \ -- cgit v1.2.3 From 178f6b24131cbe3fce9ff98f1fd942fccb1205d9 Mon Sep 17 00:00:00 2001 From: in2 Date: Sun, 20 Jul 2003 00:55:34 +0000 Subject: merge from MergeCache git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@1065 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/include/proto.h | 7 +- pttbbs/include/pttstruct.h | 9 +- pttbbs/innbbsd/Makefile | 2 +- pttbbs/innbbsd/antisplam.h | 13 - pttbbs/innbbsd/inndchannel.c | 1 + pttbbs/innbbsd/str_decode.c | 2 +- pttbbs/mbbsd/Makefile | 5 +- pttbbs/mbbsd/announce.c | 9 +- pttbbs/mbbsd/bbs.c | 5 +- pttbbs/mbbsd/board.c | 7 +- pttbbs/mbbsd/cache.c | 307 ++++++++++++----------- pttbbs/mbbsd/mail.c | 8 +- pttbbs/mbbsd/mbbsd.c | 17 +- pttbbs/mbbsd/stuff.c | 23 +- pttbbs/mbbsd/toolkit.c | 13 - pttbbs/mbbsd/var.c | 4 +- pttbbs/sample/pttbbs.sh | 7 +- pttbbs/sample/rc.local | 6 +- pttbbs/util/BM_money.c | 6 +- pttbbs/util/Makefile | 15 +- pttbbs/util/account.c | 11 +- pttbbs/util/antispam.c | 4 +- pttbbs/util/birth.c | 1 + pttbbs/util/buildAnnounce.c | 3 +- pttbbs/util/expire.c | 4 +- pttbbs/util/horoscope.c | 3 +- pttbbs/util/indexuser.c | 5 +- pttbbs/util/inndBM.c | 4 +- pttbbs/util/jungo.c | 3 +- pttbbs/util/mandex.c | 12 +- pttbbs/util/openticket.c | 20 +- pttbbs/util/openvice.c | 11 +- pttbbs/util/parse_news.c | 5 +- pttbbs/util/post.c | 9 +- pttbbs/util/poststat.c | 3 +- pttbbs/util/reaper.c | 8 +- pttbbs/util/rmuid.c | 5 +- pttbbs/util/shmctl.c | 94 ++++++- pttbbs/util/toplazyBBM.c | 3 +- pttbbs/util/toplazyBM.c | 3 +- pttbbs/util/topusr.c | 21 +- pttbbs/util/util_cache.c | 565 ------------------------------------------- pttbbs/util/xchatd.c | 22 +- pttbbs/util/yearsold.c | 5 +- 44 files changed, 406 insertions(+), 884 deletions(-) delete mode 100644 pttbbs/mbbsd/toolkit.c delete mode 100644 pttbbs/util/util_cache.c diff --git a/pttbbs/include/proto.h b/pttbbs/include/proto.h index f02f7c1d..ee59329d 100644 --- a/pttbbs/include/proto.h +++ b/pttbbs/include/proto.h @@ -1,4 +1,4 @@ -/* $Id: proto.h,v 1.45 2003/07/17 03:27:27 victor Exp $ */ +/* $Id: proto.h,v 1.46 2003/07/20 00:55:34 in2 Exp $ */ #ifndef INCLUDE_PROTO_H #define INCLUDE_PROTO_H @@ -130,7 +130,10 @@ int get_fileheader_cache(int bid, char *direct, fileheader_t *headers, int recbase, int nlines); void *attach_shm(int shmkey, int shmsize); void attach_SHM(void); -void sort_utmp(); +void sort_utmp(void); +int is_BM_cache(int); +void buildBMcache(int); +void reload_bcache(void); /* cal */ int give_tax(int money); diff --git a/pttbbs/include/pttstruct.h b/pttbbs/include/pttstruct.h index d34e8f3a..2401c26b 100644 --- a/pttbbs/include/pttstruct.h +++ b/pttbbs/include/pttstruct.h @@ -1,4 +1,4 @@ -/* $Id: pttstruct.h,v 1.42 2003/07/17 03:27:27 victor Exp $ */ +/* $Id: pttstruct.h,v 1.43 2003/07/20 00:55:34 in2 Exp $ */ #ifndef INCLUDE_STRUCT_H #define INCLUDE_STRUCT_H @@ -102,7 +102,7 @@ typedef struct userec_t { typedef struct boardheader_t { char brdname[IDLEN + 1]; /* bid */ char title[BTLEN + 1]; - char BM[IDLEN * 3 + 3]; /* BMs' uid, token '/' */ + char BM[IDLEN * 3 + 3]; /* BMs' userid, token '/' */ unsigned int brdattr; /* board的屬性 */ char pad[3]; /* 沒用到的 */ time_t bupdate; /* note update time */ @@ -298,6 +298,9 @@ typedef struct keeploc_t { #define USHM_SIZE (MAX_ACTIVE + 4) /* why+4? */ +/* MAX_BMs is dirty hardcode 4 in mbbsd/cache.c:is_BM_cache() */ +#define MAX_BMs 4 /* for BMcache, 一個看板最多幾板主 */ + typedef struct { /* uhash */ char userid[MAX_USERS][IDLEN + 1]; @@ -319,7 +322,7 @@ typedef struct { char UTMPbusystate; /* brdshm */ - int BMcache[MAX_BOARD][4]; + int BMcache[MAX_BOARD][MAX_BMs]; boardheader_t bcache[MAX_BOARD]; boardheader_t *bsorted[2][MAX_BOARD]; /* 0: by name 1: by class */ fileheader_t dircache[MAX_BOARD][DIRCACHESIZE]; diff --git a/pttbbs/innbbsd/Makefile b/pttbbs/innbbsd/Makefile index 56c91213..5fa6c566 100644 --- a/pttbbs/innbbsd/Makefile +++ b/pttbbs/innbbsd/Makefile @@ -24,7 +24,7 @@ OPT= -O -s -pipe -fomit-frame-pointer BBS_DEP = MapleBBS BBS_UTIL = $(BBS_SRC)/util -BBS_REC = $(BBS_UTIL)/util_record.o $(BBS_UTIL)/util_cache.o $(BBS_UTIL)/util_passwd.o +BBS_REC = $(BBS_UTIL)/util_record.o $(BBS_UTIL)/util_cache.o $(BBS_UTIL)/util_passwd.o $(BBS_UTIL)/util_stuff.o $(BBS_UTIL)/util_var.o ######################### # diff --git a/pttbbs/innbbsd/antisplam.h b/pttbbs/innbbsd/antisplam.h index 30289da1..f72f5348 100644 --- a/pttbbs/innbbsd/antisplam.h +++ b/pttbbs/innbbsd/antisplam.h @@ -1,18 +1,5 @@ #define char_lower(c) ((c >= 'A' && c <= 'Z') ? c|32 : c) -/*void -str_lower(t, s) - char *t, *s;*/ -void str_lower(char *t, char *s) -{ - register char ch; - do - { - ch = *s++; - *t++ = char_lower(ch); - } while (ch); -} - #if 0 /* string.h , libc */ int strcasestr(str, tag) diff --git a/pttbbs/innbbsd/inndchannel.c b/pttbbs/innbbsd/inndchannel.c index 439b2af0..b784bde4 100644 --- a/pttbbs/innbbsd/inndchannel.c +++ b/pttbbs/innbbsd/inndchannel.c @@ -578,6 +578,7 @@ woju setgid(BBSGID); setuid(BBSUID); chdir(BBSHOME); + attach_SHM(); resolve_boards(); port = DefaultINNBBSPort; diff --git a/pttbbs/innbbsd/str_decode.c b/pttbbs/innbbsd/str_decode.c index 23a10551..73ad5f64 100644 --- a/pttbbs/innbbsd/str_decode.c +++ b/pttbbs/innbbsd/str_decode.c @@ -164,7 +164,7 @@ int str_iconv( /* Start translation */ while (srclen > 0 && dstlen > 0) { - iconv_ret = iconv(iconv_descriptor, &src, &srclen, + iconv_ret = iconv(iconv_descriptor, (const char* *)&src, &srclen, &dst, &dstlen); if (iconv_ret != 0) { diff --git a/pttbbs/mbbsd/Makefile b/pttbbs/mbbsd/Makefile index 7d16b04f..5762a2d7 100644 --- a/pttbbs/mbbsd/Makefile +++ b/pttbbs/mbbsd/Makefile @@ -1,4 +1,4 @@ -# $Id: Makefile,v 1.28 2003/07/06 03:41:08 in2 Exp $ +# $Id: Makefile,v 1.29 2003/07/20 00:55:34 in2 Exp $ .include "../pttbbs.mk" @@ -14,8 +14,7 @@ OBJS= admin.o announce.o args.o bbs.o board.o cache.o cal.o card.o\ kaede.o lovepaper.o mail.o mbbsd.o menu.o more.o name.o osdep.o\ othello.o page.o read.o record.o register.o screen.o stuff.o\ talk.o term.o topsong.o user.o vice.o vote.o xyz.o\ - voteboard.o syspost.o var.o toolkit.o passwd.o\ - calendar.o + voteboard.o syspost.o var.o passwd.o calendar.o .SUFFIXES: .c .o .c.o: ../include/var.h diff --git a/pttbbs/mbbsd/announce.c b/pttbbs/mbbsd/announce.c index f0db7535..92b89d7f 100644 --- a/pttbbs/mbbsd/announce.c +++ b/pttbbs/mbbsd/announce.c @@ -1,4 +1,4 @@ -/* $Id: announce.c,v 1.30 2003/07/06 03:41:08 in2 Exp $ */ +/* $Id: announce.c,v 1.31 2003/07/20 00:55:34 in2 Exp $ */ #include "bbs.h" #define PATHLEN 256 @@ -863,7 +863,8 @@ a_menu(char *maintitle, char *path, int lastlevel) 還是檔案竟然是用 fstat(2) 而不是直接存在 .DIR 內 |||b 須等該資料寫入 .DIR 內再 implement才有效率. */ - if( !lastlevel && !HAS_PERM(PERM_SYSOP) && !HAS_PERM(PERM_SYSSUBOP) && !is_BM(bcache[currbid - 1].BM) && + if( !lastlevel && !HAS_PERM(PERM_SYSOP) && + !HAS_PERM(PERM_SYSSUBOP) && is_BM_cache(currbid) && dashd(fname) ) vmsg("只有板主才可以拷貝目錄唷!"); else @@ -961,7 +962,7 @@ a_menu(char *maintitle, char *path, int lastlevel) #ifdef BLOG case 'b': - if( !HAS_PERM(SYSOP) && !is_BM(bcache[currbid - 1].BM) ) + if( !HAS_PERM(PERM_SYSOP) && !is_BM_cache(currbid) ) vmsg("只有板主才可以用唷!"); else{ char genbuf[128]; @@ -974,7 +975,7 @@ a_menu(char *maintitle, char *path, int lastlevel) break; case 'B': - if( !HAS_PERM(SYSOP) && !is_BM(bcache[currbid - 1].BM) ) + if( !HAS_PERM(SYSOP) && !is_BM_cache(currbid) ) vmsg("只有板主才可以用唷!"); else BlogMain(me.now); diff --git a/pttbbs/mbbsd/bbs.c b/pttbbs/mbbsd/bbs.c index a113b03d..3aaae9c2 100644 --- a/pttbbs/mbbsd/bbs.c +++ b/pttbbs/mbbsd/bbs.c @@ -1,4 +1,4 @@ -/* $Id: bbs.c,v 1.103 2003/07/06 23:09:25 kcwu Exp $ */ +/* $Id: bbs.c,v 1.104 2003/07/20 00:55:34 in2 Exp $ */ #include "bbs.h" static int recommend(int ent, fileheader_t * fhdr, char *direct); @@ -121,7 +121,7 @@ set_board() bp->title + 7); currmode = (currmode & (MODE_DIRTY | MODE_MENU)) | MODE_STARTED; - if (HAS_PERM(PERM_ALLBOARD) || is_BM(bp->BM)) + if (HAS_PERM(PERM_ALLBOARD) || is_BM_cache(currbid)) currmode = currmode | MODE_BOARD | MODE_POST; else if (haspostperm(currboard)) currmode |= MODE_POST; @@ -1466,6 +1466,7 @@ del_post(int ent, fileheader_t * fhdr, char *direct) if (!not_owned && strcmp(currboard, "Test")) { if (cuser.numposts) cuser.numposts--; + /* XXX: is_BM(cuser.userid) is always true @_@ */ if (!(currmode & MODE_DIGEST && is_BM(cuser.userid))){ move(b_lines - 1, 0); clrtoeol(); diff --git a/pttbbs/mbbsd/board.c b/pttbbs/mbbsd/board.c index 415dabe1..7351d1e9 100644 --- a/pttbbs/mbbsd/board.c +++ b/pttbbs/mbbsd/board.c @@ -1,4 +1,4 @@ -/* $Id: board.c,v 1.132 2003/07/03 03:37:39 victor Exp $ */ +/* $Id: board.c,v 1.133 2003/07/20 00:55:34 in2 Exp $ */ #include "bbs.h" #define BRC_STRLEN 15 /* Length of board name */ #define BRC_MAXSIZE 24576 @@ -575,7 +575,6 @@ int Ben_Perm(boardheader_t * bptr) { register int level, brdattr; - register char *ptr; level = bptr->level; brdattr = bptr->brdattr; @@ -583,8 +582,7 @@ Ben_Perm(boardheader_t * bptr) if (HAS_PERM(PERM_SYSOP)) return 1; - ptr = bptr->BM; - if (is_BM(ptr)) + if( is_BM_cache(bptr - bcache + 1) ) /* XXXbid */ return 1; /* 祕密看板:核對首席板主的好友名單 */ @@ -688,6 +686,7 @@ load_uidofgid(const int gid, const int type) else currbptr->next[type] = (boardheader_t *) ~ 0; } + static boardstat_t * addnewbrdstat(int n, int state) { diff --git a/pttbbs/mbbsd/cache.c b/pttbbs/mbbsd/cache.c index fb7baca8..ad2d7a7d 100644 --- a/pttbbs/mbbsd/cache.c +++ b/pttbbs/mbbsd/cache.c @@ -1,15 +1,10 @@ -/* $Id: cache.c,v 1.62 2003/06/07 14:19:12 kcwu Exp $ */ +/* $Id: cache.c,v 1.63 2003/07/20 00:55:34 in2 Exp $ */ #include "bbs.h" -#ifndef __FreeBSD__ -union semun { - int val; /* value for SETVAL */ - struct semid_ds *buf; /* buffer for IPC_STAT, IPC_SET */ - unsigned short int *array; /* array for GETALL, SETALL */ - struct seminfo *__buf; /* buffer for IPC_INFO */ -}; +#ifdef _BBS_UTIL_C_ +# define log_usies(a, b) ; +# define abort_bbs(a) exit(1) #endif - /* * the reason for "safe_sleep" is that we may call sleep during SIGALRM * handler routine, while SIGALRM is blocked. if we use the original sleep, @@ -25,9 +20,7 @@ safe_sleep(unsigned int seconds) sigprocmask(SIG_BLOCK, &set, &oldset); if (sigismember(&oldset, SIGALRM)) { unsigned long retv; -#if !defined(_BBS_UTIL_C_) log_usies("SAFE_SLEEP ", "avoid hang"); -#endif sigemptyset(&set); sigaddset(&set, SIGALRM); sigprocmask(SIG_UNBLOCK, &set, NULL); @@ -38,22 +31,9 @@ safe_sleep(unsigned int seconds) return sleep(seconds); } -#if defined(_BBS_UTIL_C_) -static void -setapath(char *buf, char *boardname) -{ - snprintf(buf, "man/boards/%c/%s", boardname[0], boardname); -} - -static char *str_dotdir = ".DIR"; - -static void -setadir(char *buf, char *path) -{ - sprintf(buf, "%s/%s", path, str_dotdir); -} -#endif - +/* + * section - SHM + */ static void attach_err(int shmkey, char *name) { @@ -70,7 +50,7 @@ attach_shm(int shmkey, int shmsize) shmid = shmget(shmkey, shmsize, 0); if (shmid < 0) { - // SHM should be created by uhash_loader, NOT mbbsd. + // SHM should be created by uhash_loader, NOT mbbsd or other utils attach_err(shmkey, "shmget"); } else { shmptr = (void *)shmat(shmid, NULL, 0); @@ -81,12 +61,40 @@ attach_shm(int shmkey, int shmsize) return shmptr; } +void +attach_SHM(void) +{ + SHM = attach_shm(SHM_KEY, sizeof(SHM_t)); + if (!SHM->loaded) /* (uhash) assume fresh shared memory is + * zeroed */ + exit(1); + if (SHM->Btouchtime == 0) + SHM->Btouchtime = 1; + bcache = SHM->bcache; -#define SEM_FLG 0600 /* semaphore mode */ + GLOBALVAR = SHM->GLOBALVAR; + if (SHM->Ptouchtime == 0) + SHM->Ptouchtime = 1; + + if (SHM->Ftouchtime == 0) + SHM->Ftouchtime = 1; +} /* ----------------------------------------------------- */ /* semaphore : for critical section */ /* ----------------------------------------------------- */ +#define SEM_FLG 0600 /* semaphore mode */ + +#ifndef __FreeBSD__ +/* according to X/OPEN, we have to define it ourselves */ +union semun { + int val; /* value for SETVAL */ + struct semid_ds *buf; /* buffer for IPC_STAT, IPC_SET */ + unsigned short int *array; /* array for GETALL, SETALL */ + struct seminfo *__buf; /* buffer for IPC_INFO */ +}; +#endif + void sem_init(int semkey, int *semid) { @@ -116,6 +124,9 @@ sem_lock(int op, int semid) } } +/* + * section - user cache(including uhash) + */ /* uhash ****************************************** */ /* * the design is this: we use another stand-alone program to create and load @@ -127,27 +138,6 @@ sem_lock(int op, int semid) * loaded yet. */ -/* attach_uhash should be called before using uhash */ - -void -attach_SHM(void) -{ - SHM = attach_shm(SHM_KEY, sizeof(SHM_t)); - if (!SHM->loaded) /* (uhash) assume fresh shared memory is - * zeroed */ - exit(1); - if (SHM->Btouchtime == 0) - SHM->Btouchtime = 1; - bcache = SHM->bcache; - - GLOBALVAR = SHM->GLOBALVAR; - if (SHM->Ptouchtime == 0) - SHM->Ptouchtime = 1; - - if (SHM->Ftouchtime == 0) - SHM->Ftouchtime = 1; -} - void add_to_uhash(int n, char *id) { @@ -166,13 +156,13 @@ add_to_uhash(int n, char *id) SHM->next_in_hash[*p = n] = -1; } +void +remove_from_uhash(int n) +{ /* * note: after remove_from_uhash(), you should add_to_uhash() (likely with a * different name) */ -void -remove_from_uhash(int n) -{ int h = StringHash(SHM->userid[n]); int *p = &(SHM->hash_head[h]); int times; @@ -187,32 +177,6 @@ remove_from_uhash(int n) *p = SHM->next_in_hash[n]; } -int -setumoney(int uid, int money) -{ - SHM->money[uid - 1] = money; - passwd_update_money(uid); - return SHM->money[uid - 1]; -} - -int -deumoney(int uid, int money) -{ - if (money < 0 && SHM->money[uid - 1] < -money) - return setumoney(uid, 0); - else - return setumoney(uid, SHM->money[uid - 1] + money); -} -int -demoney(int money) -{ - return deumoney(usernum, money); -} -int -moneyof(int uid) -{ /* ptt 改進金錢處理效率 */ - return SHM->money[uid - 1]; -} int searchuser(char *userid) { @@ -231,8 +195,6 @@ searchuser(char *userid) return 0; } -#if !defined(_BBS_UTIL_C_) - int getuser(char *userid) { @@ -284,6 +246,7 @@ searchnewuser(int mode) return 0; } +#ifndef _BBS_UTIL_C_ char * u_namearray(char buf[][IDLEN + 1], int *pnum, char *tag) { @@ -315,30 +278,10 @@ u_namearray(char buf[][IDLEN + 1], int *pnum, char *tag) } #endif -/*-------------------------------------------------------*/ -/* .UTMP cache */ -/*-------------------------------------------------------*/ -#if !defined(_BBS_UTIL_C_) -void -setutmpmode(unsigned int mode) -{ - if (currstat != mode) - currutmp->mode = currstat = mode; - - /* 追蹤使用者 */ - if (HAS_PERM(PERM_LOGUSER)) { - char msg[200]; - snprintf(msg, sizeof(msg), "%s setutmpmode to %s(%d) at %s", - cuser.userid, modestring(currutmp, 0), mode, Cdate(&now)); - log_user(msg); - } -} -#endif - -/* Ptt:這裡加上 hash 觀念找空的 utmp */ void getnewutmpent(userinfo_t * up) { +/* Ptt:這裡加上 hash 觀念找空的 utmp */ register int i, p; register userinfo_t *uentp; for (i = 0, p = StringHash(up->userid) % USHM_SIZE; i < USHM_SIZE; i++, p++) { @@ -375,7 +318,6 @@ search_ulist(int uid) return search_ulistn(uid, 1); } -#if !defined(_BBS_UTIL_C_) userinfo_t * search_ulist_pid(int pid) { @@ -401,6 +343,7 @@ search_ulist_pid(int pid) } return 0; } + userinfo_t * search_ulistn(int uid, int unum) { @@ -432,6 +375,7 @@ search_ulistn(int uid, int unum) } return 0; } + userinfo_t * search_ulist_userid(char *userid) { @@ -458,6 +402,7 @@ search_ulist_userid(char *userid) return 0; } +#ifndef _BBS_UTIL_C_ int count_logins(int uid, int show) { @@ -491,7 +436,6 @@ count_logins(int uid, int show) return 0; } - void purge_utmp(userinfo_t * uentp) { @@ -499,12 +443,68 @@ purge_utmp(userinfo_t * uentp) memset(uentp, 0, sizeof(userinfo_t)); SHM->UTMPneedsort = 1; } +#endif + +/* + * section - money cache + */ +int +setumoney(int uid, int money) +{ + SHM->money[uid - 1] = money; + passwd_update_money(uid); + return SHM->money[uid - 1]; +} + +int +deumoney(int uid, int money) +{ + if (money < 0 && SHM->money[uid - 1] < -money) + return setumoney(uid, 0); + else + return setumoney(uid, SHM->money[uid - 1] + money); +} + +int +demoney(int money) +{ + return deumoney(usernum, money); +} + +int +moneyof(int uid) +{ /* ptt 改進金錢處理效率 */ + return SHM->money[uid - 1]; +} + +/* + * section - utmp + */ +#if !defined(_BBS_UTIL_C_) /* _BBS_UTIL_C_ 不會有 utmp */ +void +setutmpmode(unsigned int mode) +{ + if (currstat != mode) + currutmp->mode = currstat = mode; + /* 追蹤使用者 */ + if (HAS_PERM(PERM_LOGUSER)) { + char msg[200]; + snprintf(msg, sizeof(msg), "%s setutmpmode to %s(%d) at %s", + cuser.userid, modestring(currutmp, 0), mode, Cdate(&now)); + log_user(msg); + } +} #endif -/*-------------------------------------------------------*/ -/* .BOARDS cache */ -/*-------------------------------------------------------*/ +/* + * section - board cache + */ +void touchbtotal(int bid) { + SHM->total[bid - 1] = 0; + SHM->lastposttime[bid - 1] = 0; +} + void touchdircache(int bid) { @@ -552,19 +552,22 @@ get_fileheader_cache(int bid, char *direct, fileheader_t * headers, memcpy(headers, &(SHM->dircache[bid - 1][n]), sizeof(fileheader_t) * ret); return ret; } + static int cmpboardname(boardheader_t ** brd, boardheader_t ** tmp) { return strcasecmp((*brd)->brdname, (*tmp)->brdname); } + static int cmpboardclass(boardheader_t ** brd, boardheader_t ** tmp) { return (strncmp((*brd)->title, (*tmp)->title, 4) << 8) + strcasecmp((*brd)->brdname, (*tmp)->brdname); } + static void -sort_bcache() +sort_bcache(void) { int i; /* critical section 不能單獨呼叫 呼叫reload_bcache or reset_board */ @@ -576,13 +579,13 @@ sort_bcache() qsort(SHM->bsorted[1], SHM->Bnumber, sizeof(boardheader_t *), (QCAST) cmpboardclass); } -static void -reload_bcache() + +void +reload_bcache(void) { if (SHM->Bbusystate) { safe_sleep(1); } -#if !defined(_BBS_UTIL_C_) else { int fd, i; @@ -604,11 +607,9 @@ reload_bcache() } SHM->Bbusystate = 0; } -#endif } -void -resolve_boards() +void resolve_boards(void) { while (SHM->Buptime < SHM->Btouchtime) { reload_bcache(); @@ -616,35 +617,32 @@ resolve_boards() numboards = SHM->Bnumber; } -void -touch_boards() +void touch_boards(void) { SHM->Btouchtime = now; numboards = -1; resolve_boards(); } -void -addbrd_touchcache() +void addbrd_touchcache(void) { SHM->Bnumber++; numboards = SHM->Bnumber; reset_board(numboards); } -#if !defined(_BBS_UTIL_C_) + void -reset_board(int bid) +reset_board(int bid) /* XXXbid: from 1 */ { /* Ptt: 這樣就不用老是touch board了 */ int fd, i, nuser; boardheader_t *bhdr; - if (--bid < 0) return; - if (SHM->Bbusystate || now - SHM->busystate_b[bid - 1] < 10) { + if (SHM->Bbusystate || now - SHM->busystate_b[bid] < 10) { safe_sleep(1); } else { - SHM->busystate_b[bid - 1] = now; - nuser = bcache[bid - 1].nuser; + SHM->busystate_b[bid] = now; + nuser = bcache[bid].nuser; bhdr = bcache; bhdr += bid; @@ -658,11 +656,13 @@ reset_board(int bid) bcache[i].firstchild[0] = NULL; bcache[i].firstchild[1] = NULL; } - nuser = bcache[bid - 1].nuser; - SHM->busystate_b[bid - 1] = 0; + SHM->busystate_b[bid] = 0; + + buildBMcache(bid + 1); /* XXXbid */ } } +#ifndef _BBS_UTIL_C_ /* because of Ben_Perm() in board.c */ int apply_boards(int (*func) (boardheader_t *)) { @@ -683,11 +683,13 @@ getbcache(int bid) { /* Ptt改寫 */ return bcache + bid - 1; } + int getbtotal(int bid) { return SHM->total[bid - 1]; } + void setbtotal(int bid) { @@ -725,7 +727,6 @@ touchbpostnum(int bid, int delta) *total += delta; } - int getbnum(char *bname) { @@ -748,7 +749,6 @@ getbnum(char *bname) return 0; } -#if !defined(_BBS_UTIL_C_) int haspostperm(char *bname) { @@ -784,14 +784,46 @@ haspostperm(char *bname) return HAS_PERM(i & ~PERM_POST); } -#endif + +void buildBMcache(int bid) /* bid starts from 1 */ +{ + char s[IDLEN * 3 + 3], *ptr; + int i, uid; + --bid; + + strncpy(s, bcache[bid].BM, sizeof(s)); + for( i = 0 ; s[i] != 0 ; ++i ) + if( !isalpha(s[i]) && !isdigit(s[i]) ) + s[i] = ' '; + + for( ptr = strtok(s, " "), i = 0 ; + i < MAX_BMs && ptr != NULL ; + ptr = strtok(NULL, " "), ++i ) + if( (uid = searchuser(ptr)) != 0 ) + SHM->BMcache[bid][i] = uid; + for( ; i < MAX_BMs ; ++i ) + SHM->BMcache[bid][i] = -1; +} + +int is_BM_cache(int bid) /* bid starts from 1 */ +{ + --bid; + if( currutmp->uid == SHM->BMcache[bid][0] || + currutmp->uid == SHM->BMcache[bid][1] || + currutmp->uid == SHM->BMcache[bid][2] || + currutmp->uid == SHM->BMcache[bid][3] ){ + cuser.userlevel |= PERM_BM; + return 1; + } + return 0; +} /*-------------------------------------------------------*/ /* PTT cache */ /*-------------------------------------------------------*/ -/* cachefor 動態看板 */ +/* cache for 動態看板 */ void -reload_pttcache() +reload_pttcache(void) { if (SHM->Pbusystate) safe_sleep(1); @@ -855,15 +887,13 @@ reload_pttcache() /* 等所有資料更新後再設定 uptime */ SHM->Puptime = SHM->Ptouchtime; -#if !defined(_BBS_UTIL_C_) log_usies("CACHE", "reload pttcache"); -#endif SHM->Pbusystate = 0; } } void -resolve_garbage() +resolve_garbage(void) { int count = 0; @@ -887,9 +917,9 @@ resolve_garbage() /*-------------------------------------------------------*/ /* PTT's cache */ /*-------------------------------------------------------*/ -/* cachefor from host 與最多上線人數 */ +/* cache for from host 與最多上線人數 */ static void -reload_fcache() +reload_fcache(void) { if (SHM->Fbusystate) safe_sleep(1); @@ -931,12 +961,15 @@ reload_fcache() } void -resolve_fcache() +resolve_fcache(void) { while (SHM->Fuptime < SHM->Ftouchtime) reload_fcache(); } +/* + * section - hbfl (hidden board friend list) + */ void hbflreload(int bid) { diff --git a/pttbbs/mbbsd/mail.c b/pttbbs/mbbsd/mail.c index 70549fbe..ff434498 100644 --- a/pttbbs/mbbsd/mail.c +++ b/pttbbs/mbbsd/mail.c @@ -1,4 +1,4 @@ -/* $Id: mail.c,v 1.27 2003/05/19 07:10:19 in2 Exp $ */ +/* $Id: mail.c,v 1.28 2003/07/20 00:55:34 in2 Exp $ */ #include "bbs.h" char currmaildir[32]; static char msg_cc[] = "\033[32m[群組名單]\033[m\n"; @@ -1230,7 +1230,7 @@ mail_cite(int ent, fileheader_t * fhdr, char *direct) char title[TTLEN + 1]; static char xboard[20]; char buf[20]; - boardheader_t *bp; + int bid; setuserfile(fpath, fhdr->filename); strlcpy(title, "◇ ", sizeof(title)); @@ -1253,11 +1253,11 @@ mail_cite(int ent, fileheader_t * fhdr, char *direct) completeboard_getname); if (*buf) strlcpy(xboard, buf, sizeof(xboard)); - if (*xboard && (bp = getbcache(getbnum(xboard)))) { + if (*xboard && ((bid = getbnum(xboard)) >= 0)){ /* XXXbid */ setapath(fpath, xboard); setutmpmode(ANNOUNCE); a_menu(xboard, fpath, HAS_PERM(PERM_ALLBOARD) ? 2 : - is_BM(bp->BM) ? 1 : 0); + is_BM_cache(bid) ? 1 : 0); } else { mail_man(); } diff --git a/pttbbs/mbbsd/mbbsd.c b/pttbbs/mbbsd/mbbsd.c index da5c6c94..4220f9b0 100644 --- a/pttbbs/mbbsd/mbbsd.c +++ b/pttbbs/mbbsd/mbbsd.c @@ -1,4 +1,4 @@ -/* $Id: mbbsd.c,v 1.89 2003/07/17 00:57:21 in2 Exp $ */ +/* $Id: mbbsd.c,v 1.90 2003/07/20 00:55:34 in2 Exp $ */ #include "bbs.h" #define SOCKET_QLEN 4 @@ -162,7 +162,7 @@ u_exit(char *mode) //userec_t xuser; int diff = (time(0) - login_start_time) / 60; - /* close fd 0 & a to terminate network */ + /* close fd 0 & 1 to terminate network */ close(0); close(1); @@ -697,13 +697,16 @@ where(char *from) #endif static void -check_BM() +check_BM(void) { + /* XXX: -_- */ int i; - boardheader_t *bhdr; cuser.userlevel &= ~PERM_BM; - for (i = 0, bhdr = bcache; i < numboards && !is_BM(bhdr->BM); i++, bhdr++); + for( i = 0 ; i < numboards ; ++i ) + if( is_BM_cache(i + 1) ) /* XXXbid */ + return; + //for (i = 0, bhdr = bcache; i < numboards && !is_BM(bhdr->BM); i++, bhdr++); } static void @@ -715,8 +718,6 @@ setup_utmp(int mode) uinfo.uid = usernum; uinfo.mode = currstat = mode; uinfo.mailalert = load_mailalert(cuser.userid); - if (!(cuser.numlogins % 20) && cuser.userlevel & PERM_BM) - check_BM(); /* Ptt 自動取下離職板主權力 */ uinfo.userlevel = cuser.userlevel; uinfo.sex = cuser.sex % 8; @@ -749,6 +750,8 @@ setup_utmp(int mode) uinfo.invisible = YEA; getnewutmpent(&uinfo); SHM->UTMPneedsort = 1; + if (!(cuser.numlogins % 20) && cuser.userlevel & PERM_BM) + check_BM(); /* Ptt 自動取下離職板主權力 */ #ifndef _BBS_UTIL_C_ friend_load(); nice(3); diff --git a/pttbbs/mbbsd/stuff.c b/pttbbs/mbbsd/stuff.c index a254b42c..80428954 100644 --- a/pttbbs/mbbsd/stuff.c +++ b/pttbbs/mbbsd/stuff.c @@ -1,4 +1,4 @@ -/* $Id: stuff.c,v 1.12 2003/06/28 08:47:45 kcwu Exp $ */ +/* $Id: stuff.c,v 1.13 2003/07/20 00:55:34 in2 Exp $ */ #include "bbs.h" /* ----------------------------------------------------- */ @@ -336,6 +336,7 @@ belong(char *filelist, char *key) return rc; } +#ifndef _BBS_UTIL_C_ /* getdata_buf */ time_t gettime(int line, time_t dt) { @@ -361,6 +362,8 @@ gettime(int line, time_t dt) } while ((endtime.tm_hour = atoi(yn)) < 0 || endtime.tm_hour > 23); return mktime(&endtime); } +#endif + char * Cdate(time_t * clock) { @@ -391,6 +394,8 @@ Cdatedate(time_t * clock) return foo; } +#ifndef _BBS_UTIL_C_ +/* 這一區都是有關於畫面處理的, 故 _BBS_UTIL_C_ 不須要 */ static void capture_screen() { @@ -619,6 +624,7 @@ show_help(char *helptext[]) } pressanykey(); } +#endif // _BBS_UTIL_C_ /* ----------------------------------------------------- */ /* use mmap() to malloc large memory in CRITICAL_MEMORY */ @@ -629,7 +635,7 @@ void *MALLOC(int size) int *p; p = (int *)mmap(NULL, (size + 4), PROT_READ | PROT_WRITE, MAP_ANON, -1, 0); p[0] = size; -#ifdef DEBUG +#if defined(DEBUG) && !defined(_BBS_UTIL_C_) vmsg("critical malloc %d bytes", size); #endif return (void *)&p[1]; @@ -639,8 +645,19 @@ void FREE(void *ptr) { int size = ((int *)ptr)[-1]; munmap((void *)(&(((int *)ptr)[-1])), size); -#ifdef DEBUG +#if defined(DEBUG) && !defined(_BBS_UTIL_C_) vmsg("critical free %d bytes", size); #endif } #endif + +unsigned +StringHash(unsigned char *s) +{ + unsigned int v = 0; + while (*s) { + v = (v << 8) | (v >> 24); + v ^= toupper(*s++); /* note this is case insensitive */ + } + return (v * 2654435769UL) >> (32 - HASH_BITS); +} diff --git a/pttbbs/mbbsd/toolkit.c b/pttbbs/mbbsd/toolkit.c deleted file mode 100644 index 99f80e0b..00000000 --- a/pttbbs/mbbsd/toolkit.c +++ /dev/null @@ -1,13 +0,0 @@ -/* $Id: toolkit.c,v 1.4 2002/07/21 09:26:02 in2 Exp $ */ -#include "bbs.h" - -unsigned -StringHash(unsigned char *s) -{ - unsigned int v = 0; - while (*s) { - v = (v << 8) | (v >> 24); - v ^= toupper(*s++); /* note this is case insensitive */ - } - return (v * 2654435769UL) >> (32 - HASH_BITS); -} diff --git a/pttbbs/mbbsd/var.c b/pttbbs/mbbsd/var.c index 59e40eb4..4ba3cf9e 100644 --- a/pttbbs/mbbsd/var.c +++ b/pttbbs/mbbsd/var.c @@ -1,4 +1,4 @@ -/* $Id: var.c,v 1.20 2003/07/06 23:09:25 kcwu Exp $ */ +/* $Id: var.c,v 1.21 2003/07/20 00:55:34 in2 Exp $ */ #define INCLUDE_VAR_H #include "bbs.h" @@ -591,6 +591,7 @@ unsigned char *adv_gomoku /* [978] */ = /* name.c */ word_t *toplev; +#ifndef _BBS_UTIL_C_ /* menu.c */ commands_t cmdlist[] = { {admin, PERM_SYSOP | PERM_VIEWSYSOP, "00Admin 【 系統維護區 】"}, @@ -606,6 +607,7 @@ commands_t cmdlist[] = { {Goodbye, 0, "GGoodbye 離開,再見……"}, {NULL, 0, NULL} }; +#endif /* friend.c */ /* Ptt 各種特別名單的檔名 */ diff --git a/pttbbs/sample/pttbbs.sh b/pttbbs/sample/pttbbs.sh index 9e1efc26..d5588b8a 100755 --- a/pttbbs/sample/pttbbs.sh +++ b/pttbbs/sample/pttbbs.sh @@ -4,8 +4,8 @@ case "$1" in start) - # 初始化 shared-memory, 載入使用者帳號 - /usr/bin/su -fm bbs -c /home/bbs/bin/uhash_loader + # 初始化 shared-memory, 載入 uhash, utmpsortd, timed(if necessary) + /usr/bin/su -fm bbs -c /home/bbs/bin/shmctl init # 寄信至站外 /usr/bin/su -fm bbs -c /home/bbs/bin/outmail & @@ -16,9 +16,6 @@ start) # 啟動 port 23 (port 23須使用 root 才能進行 bind ) /home/bbs/bin/mbbsd 23 & - # 啟動 utmpsortd - /bin/sleep 5; "/usr/bin/su -fm bbs -c /home/bbs/bin/shmctl utmpsortd" & - # 提示 echo -n ' mbbsd' ;; diff --git a/pttbbs/sample/rc.local b/pttbbs/sample/rc.local index 96d2cb00..4da3d8d5 100644 --- a/pttbbs/sample/rc.local +++ b/pttbbs/sample/rc.local @@ -1,5 +1,5 @@ #!/bin/sh -/usr/bin/su bbsadm -c /home/bbs/bin/uhash_loader +/usr/bin/su bbsadm -c /home/bbs/bin/shmctl init /usr/bin/su bbsadm -c /home/bbs/bin/outmail& /usr/bin/su bbsadm -c /home/bbs/innd/innbbsd 7777 /home/bbs/bin/mbbsd 23 & @@ -14,7 +14,3 @@ /home/bbs/bin/mbbsd 3008 & /home/bbs/bin/mbbsd 3009 & /home/bbs/bin/mbbsd 3010 & -/usr/bin/su -fm bbsadm -c "/home/bbs/bin/shmctl utmpsortd" - -# 若您在 pttbbs.conf 中有開 OUTTA_TIMER 的話, 則須跑下面這行 -# /usr/bin/su -fm bbsadm -c "/home/bbs/bin/shmctl timed" diff --git a/pttbbs/util/BM_money.c b/pttbbs/util/BM_money.c index e2ed960f..075f53ae 100644 --- a/pttbbs/util/BM_money.c +++ b/pttbbs/util/BM_money.c @@ -1,4 +1,4 @@ -/* $Id: BM_money.c,v 1.6 2002/11/02 11:02:44 in2 Exp $ */ +/* $Id: BM_money.c,v 1.7 2003/07/20 00:55:34 in2 Exp $ */ /* 給板主錢的程式 */ @@ -27,12 +27,14 @@ int Link(char *src, char *dst) { } -int main() { +int main(int argc, char **argv) +{ FILE *fp = fopen(BBSHOME "/etc/topboardman", "r"); char buf[201], bname[20], BM[90], *ch; boardheader_t *bptr = NULL; int nBM; + attach_SHM(); resolve_boards(); if(passwd_mmap()) exit(1); diff --git a/pttbbs/util/Makefile b/pttbbs/util/Makefile index 2f11c9ea..a62ee3a8 100644 --- a/pttbbs/util/Makefile +++ b/pttbbs/util/Makefile @@ -1,9 +1,9 @@ -# $Id: Makefile,v 1.35 2003/07/19 09:33:34 in2 Exp $ +# $Id: Makefile,v 1.36 2003/07/20 00:55:34 in2 Exp $ .include "../pttbbs.mk" UTIL_OBJS= \ - util_cache.o util_record.o util_passwd.o + util_cache.o util_record.o util_passwd.o util_var.o util_stuff.o # 下面這些程式, 會被 compile 並且和 $(UTIL_OBJS) 聯結 CPROG_WITH_UTIL= \ @@ -33,9 +33,18 @@ all: ${CPROG_WITH_UTIL} ${CPROG_WITHOUT_UTIL} ${PROGS} bbsmail .for fn in ${CPROG_WITH_UTIL} ${fn}: ${fn}.c ${UTIL_OBJS} - ${CC} ${CFLAGS} -o ${fn} ${fn}.c ${UTIL_OBJS} + ${CC} ${CFLAGS} -o ${fn} ${UTIL_OBJS} ${fn}.c .endfor +util_var.o: ../mbbsd/var.c + ${CC} ${CFLAGS} -D_BBS_UTIL_C_ -c -o util_var.o ../mbbsd/var.c + +util_stuff.o: ../mbbsd/stuff.c + ${CC} ${CFLAGS} -D_BBS_UTIL_C_ -c -o util_stuff.o ../mbbsd/stuff.c + +util_cache.o: ../mbbsd/cache.c + ${CC} ${CFLAGS} -D_BBS_UTIL_C_ -c -o util_cache.o ../mbbsd/cache.c + bbsmail: bbsmail.c ${CPROG_WITH_UTIL} ../mbbsd/osdep.o ${CC} ${CFLAGS} -o bbsmail bbsmail.c ${UTIL_OBJS} ../mbbsd/osdep.o ${LDFLAGS} diff --git a/pttbbs/util/account.c b/pttbbs/util/account.c index bbc84244..827eefb4 100644 --- a/pttbbs/util/account.c +++ b/pttbbs/util/account.c @@ -1,4 +1,4 @@ -/* $Id: account.c,v 1.8 2003/07/05 07:58:09 in2 Exp $ */ +/* $Id: account.c,v 1.9 2003/07/20 00:55:34 in2 Exp $ */ #include "bbs.h" #define MAX_LINE 16 @@ -55,8 +55,9 @@ keeplog(fpath, board, title) strcpy(fhdr.owner, "[歷史老師]"); sprintf(genbuf, "boards/%c/%s/.DIR", board[0], board); append_record(genbuf, &fhdr, sizeof(fhdr)); - if((bid = getbnum(board)) > 0)touchbtotal(bid); - + /* XXX: bid of cache.c's getbnum starts from 1 */ + if((bid = getbnum(board)) > 0) + touchbtotal(bid); } @@ -86,7 +87,8 @@ void gzip(source, target, stamp) system(buf); } -int main() { +int main(int argc, char **argv) +{ int hour, max, item, total, i, j, mo, da, max_user = 0, max_login = 0, max_reg = 0, mahour = 0, k; char *act_file = ".act"; @@ -97,6 +99,7 @@ int main() { time_t now; struct tm *ptime; + attach_SHM(); nice(10); chdir(BBSHOME); now = time(NULL) - ADJUST_M * 60; /* back to ancent */ diff --git a/pttbbs/util/antispam.c b/pttbbs/util/antispam.c index f7b77569..e29549aa 100644 --- a/pttbbs/util/antispam.c +++ b/pttbbs/util/antispam.c @@ -1,4 +1,4 @@ -/* $Id: antispam.c,v 1.1 2002/03/07 15:13:45 in2 Exp $ */ +/* $Id: antispam.c,v 1.2 2003/07/20 00:55:34 in2 Exp $ */ /* 抓廣告信的程式 */ #include #include @@ -22,7 +22,7 @@ typedef struct sendinfo sendinfo; int - main() +main(int argc, char **argv) { char buf[200], *from, *userid; int num = -1, numb = -1, n, nb; diff --git a/pttbbs/util/birth.c b/pttbbs/util/birth.c index 23272d6f..b7f65761 100644 --- a/pttbbs/util/birth.c +++ b/pttbbs/util/birth.c @@ -45,6 +45,7 @@ int main(argc, argv) struct tm *ptime; int j; + attach_SHM(); now = time(NULL); /* back to ancent */ ptime = localtime(&now); diff --git a/pttbbs/util/buildAnnounce.c b/pttbbs/util/buildAnnounce.c index 1db151f9..0bfbefbd 100644 --- a/pttbbs/util/buildAnnounce.c +++ b/pttbbs/util/buildAnnounce.c @@ -62,13 +62,14 @@ void buildchilds(int level,char *path,int gid) } -int main() +int main(int argc, char **argv) { char path[512]; setsid(); strcpy(path,GROUPROOT); system("rm -rf "GROUPROOT); mkdir(GROUPROOT,0766); + attach_SHM(); resolve_boards(); buildchilds(0,path,1); return 0; diff --git a/pttbbs/util/expire.c b/pttbbs/util/expire.c index 30e9ab2f..b75c85b8 100644 --- a/pttbbs/util/expire.c +++ b/pttbbs/util/expire.c @@ -1,4 +1,4 @@ -/* $Id: expire.c,v 1.6 2002/11/11 03:06:03 in2 Exp $ */ +/* $Id: expire.c,v 1.7 2003/07/20 00:55:34 in2 Exp $ */ /* 自動砍信工具程式 */ #include "bbs.h" @@ -36,6 +36,7 @@ life *brd; int duetime, ftime; printf("%s\n", brd->bname); + /* XXX: bid of cache.c's getbnum starts from 1 */ if((bid = getbnum(brd->bname)) == 0 || strcmp(brd->bname, bcache[bid-1].brdname)) { @@ -144,6 +145,7 @@ char *argv[]; 'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', 'Z', 'X', 'C', 'V', 'B', 'N', 'M', NULL}; + attach_SHM(); resolve_boards(); db.days = ((argc > 1) && (number = atoi(argv[1])) > 0) ? number : DEF_DAYS; db.maxp = ((argc > 2) && (number = atoi(argv[2])) > 0) ? number : DEF_MAXP; diff --git a/pttbbs/util/horoscope.c b/pttbbs/util/horoscope.c index 53d69e31..b47634aa 100644 --- a/pttbbs/util/horoscope.c +++ b/pttbbs/util/horoscope.c @@ -1,4 +1,4 @@ -/* $Id: horoscope.c,v 1.3 2002/11/02 11:02:44 in2 Exp $ */ +/* $Id: horoscope.c,v 1.4 2003/07/20 00:55:34 in2 Exp $ */ #define _UTIL_C_ #include "bbs.h" @@ -32,6 +32,7 @@ int main() { "▋", "▊", "▉", "█", "█", }; + attach_SHM(); memset(act, 0, sizeof(act)); if(passwd_mmap()) exit(1); diff --git a/pttbbs/util/indexuser.c b/pttbbs/util/indexuser.c index 8b39fdd0..e0975130 100644 --- a/pttbbs/util/indexuser.c +++ b/pttbbs/util/indexuser.c @@ -1,4 +1,4 @@ -/* $Id: indexuser.c,v 1.5 2002/11/02 11:02:44 in2 Exp $ */ +/* $Id: indexuser.c,v 1.6 2003/07/20 00:55:34 in2 Exp $ */ #define _UTIL_C_ #include "bbs.h" #define INDEXPATH BBSHOME"/index" @@ -15,12 +15,13 @@ unsigned string_hash(unsigned char *s) } -int main() +int main(int argc, char **argv) { int j; userec_t u; char buf[256]; + attach_SHM(); if(passwd_mmap()) { printf("Sorry, the data is not ready.\n"); diff --git a/pttbbs/util/inndBM.c b/pttbbs/util/inndBM.c index 8f1a69a0..363220f5 100644 --- a/pttbbs/util/inndBM.c +++ b/pttbbs/util/inndBM.c @@ -90,6 +90,7 @@ int load_newsfeeds() sscanf(str,"%s %s %s", feedline[feedcount].group,feedline[feedcount].board, feedline[feedcount].server); + /* XXX: bid of cache.c's getbnum starts from 1 */ bid=getbnum(feedline[feedcount].board); if(!bid) { fprintf(fo,"%s %s\n", feedline[feedcount].board, feedline[feedcount].group ); @@ -129,12 +130,13 @@ int dobbsnnrp(char *serverstr, int serverid,FILE *fpscript) fprintf(fpscript, buf); return 0; } -int main() +int main(int argc, char **argv) { int i,serverid=0; FILE *fp=NULL,*fpscript=fopen(INND_SCRIPT,"w"); char buf[256],serverstr[30]=""; chdir(BBSHOME "/innd"); + attach_SHM(); resolve_boards(); memset(istran,0,sizeof(int)*MAX_BOARD); load_server(); diff --git a/pttbbs/util/jungo.c b/pttbbs/util/jungo.c index 4c7c2d94..4f038efe 100644 --- a/pttbbs/util/jungo.c +++ b/pttbbs/util/jungo.c @@ -1,4 +1,4 @@ -/* $Id: jungo.c,v 1.6 2002/11/02 11:02:44 in2 Exp $ */ +/* $Id: jungo.c,v 1.7 2003/07/20 00:55:34 in2 Exp $ */ #define _UTIL_C_ #include "bbs.h" @@ -47,6 +47,7 @@ int main(int argc, char *argv[]) int bmid, i, j=0; FILE *inf, *firef; + attach_SHM(); resolve_boards(); if(passwd_mmap()) diff --git a/pttbbs/util/mandex.c b/pttbbs/util/mandex.c index 6088bc75..f1059f68 100644 --- a/pttbbs/util/mandex.c +++ b/pttbbs/util/mandex.c @@ -1,4 +1,4 @@ -/* $Id: mandex.c,v 1.9 2003/05/15 08:27:23 in2 Exp $ */ +/* $Id: mandex.c,v 1.10 2003/07/20 00:55:34 in2 Exp $ */ /* 'mandex -h' to help */ @@ -36,15 +36,6 @@ int k_cmp(b, a) return ((a->k / 100 + a->ndir + a->nfile) - (b->k / 100 + b->ndir + b->nfile)); } -int dashd(fname) - char *fname; -{ - struct stat st; - - return (stat(fname, &st) == 0 && S_ISDIR(st.st_mode)); -} - - /* visit the hierarchy recursively */ void @@ -189,6 +180,7 @@ int main(int argc, char* argv[]) argc -= optind; argv += optind; + attach_SHM(); resolve_boards(); /* if( argc == 0 ){ diff --git a/pttbbs/util/openticket.c b/pttbbs/util/openticket.c index 55e04b0e..5d7584bc 100644 --- a/pttbbs/util/openticket.c +++ b/pttbbs/util/openticket.c @@ -1,4 +1,4 @@ -/* $Id: openticket.c,v 1.9 2002/11/02 11:02:44 in2 Exp $ */ +/* $Id: openticket.c,v 1.10 2003/07/20 00:55:34 in2 Exp $ */ /* 開獎的 utility */ #define _UTIL_C_ #include "bbs.h" @@ -21,19 +21,7 @@ int Link(char *src, char *dst) return system(cmd); } -char * - Cdatelite(clock) -time_t *clock; -{ - static char foo[18]; - struct tm *mytm = localtime(clock); - - strftime(foo, 18, "%D %T", mytm); - return (foo); -} - - -int main() +int main(int argc, char **argv) { int money, bet, n, total = 0, ticket[8] = {0, 0, 0, 0, 0, 0, 0, 0}; @@ -43,6 +31,7 @@ int main() {"", "", "", ""}; nice(10); + attach_SHM(); if(passwd_mmap()) exit(1); @@ -93,7 +82,8 @@ int main() bet=random() % 8; - resolve_utmp(); + //XXX: resolve_utmp(); + attach_SHM(); bet = SHM->UTMPnumber % 8; /* diff --git a/pttbbs/util/openvice.c b/pttbbs/util/openvice.c index b622eb55..41c146ab 100644 --- a/pttbbs/util/openvice.c +++ b/pttbbs/util/openvice.c @@ -1,4 +1,4 @@ -/* $Id: openvice.c,v 1.2 2002/06/06 21:34:14 in2 Exp $ */ +/* $Id: openvice.c,v 1.3 2003/07/20 00:55:34 in2 Exp $ */ /* 發票開獎小程式 */ #include "bbs.h" @@ -9,17 +9,16 @@ #define VICE_DATA "vice.data" #define MAX_BINGO 99999999 -int main() +int main(int argc, char **argv) { - char TABLE[5][3] = - {"一", "二", "三", "四", "五"}; - + char *TABLE[5] = {"一", "二", "三", "四", "五"}; int i = 0, bingo, base = 0; FILE *fp = fopen(VICE_SHOW, "w"), *fb = fopen(VICE_BINGO, "w"); - resolve_utmp(); + // XXX: resolve_utmp(); + attach_SHM(); srand(SHM->number); diff --git a/pttbbs/util/parse_news.c b/pttbbs/util/parse_news.c index 042cf107..b1f0ad25 100644 --- a/pttbbs/util/parse_news.c +++ b/pttbbs/util/parse_news.c @@ -1,10 +1,11 @@ -/* $Id: parse_news.c,v 1.4 2002/06/06 21:34:14 in2 Exp $ */ +/* $Id: parse_news.c,v 1.5 2003/07/20 00:55:34 in2 Exp $ */ #include "bbs.h" #define NEWSDIRECT BBSHOME "/boards/n/newspaper" #define MOVIEDIRECT BBSHOME "/etc/NEWS" -int main() { +int main(int argc, char **argv) +{ int fd; fileheader_t fh, news; struct stat st; diff --git a/pttbbs/util/post.c b/pttbbs/util/post.c index 0d93e0a0..ba6ee1d7 100644 --- a/pttbbs/util/post.c +++ b/pttbbs/util/post.c @@ -1,4 +1,4 @@ -/* $Id: post.c,v 1.4 2002/06/06 21:34:14 in2 Exp $ */ +/* $Id: post.c,v 1.5 2003/07/20 00:55:34 in2 Exp $ */ #include "bbs.h" void keeplog(FILE *fin, char *fpath, char *board, char *title, char *owner) { @@ -27,14 +27,17 @@ void keeplog(FILE *fin, char *fpath, char *board, char *title, char *owner) { strcpy(fhdr.owner, owner); sprintf(genbuf, BBSHOME "/boards/%c/%s/.DIR", board[0], board); append_record(genbuf, &fhdr, sizeof(fhdr)); + /* XXX: bid of cache.c's getbnum starts from 1 */ if((bid = getbnum(board)) > 0) touchbtotal(bid); } -int main(int argc, char **argv) { +int main(int argc, char **argv) +{ FILE *fp; - + + attach_SHM(); resolve_boards(); if(argc != 5) { printf("usage: %s <owner> <file>\n", argv[0]); diff --git a/pttbbs/util/poststat.c b/pttbbs/util/poststat.c index acd4aed4..37bcc399 100644 --- a/pttbbs/util/poststat.c +++ b/pttbbs/util/poststat.c @@ -1,4 +1,4 @@ -/* $Id: poststat.c,v 1.4 2002/06/30 16:06:19 in2 Exp $ */ +/* $Id: poststat.c,v 1.5 2003/07/20 00:55:34 in2 Exp $ */ /* 統計今日、週、月、年熱門話題 */ #include "bbs.h" @@ -184,6 +184,7 @@ filter(board) boardheader_t bh; int bid; + /* XXX: bid of cache.c's getbnum starts from 1 */ bid = getbnum(board); if (get_record(".BRD", &bh, sizeof(bh), bid) == -1) return 1; diff --git a/pttbbs/util/reaper.c b/pttbbs/util/reaper.c index 9ed1b11f..633a4c78 100644 --- a/pttbbs/util/reaper.c +++ b/pttbbs/util/reaper.c @@ -1,4 +1,4 @@ -/* $Id: reaper.c,v 1.3 2002/11/02 11:02:44 in2 Exp $ */ +/* $Id: reaper.c,v 1.4 2003/07/20 00:55:34 in2 Exp $ */ #define _UTIL_C_ #include "bbs.h" @@ -46,11 +46,13 @@ int check(int n, userec_t *u) { return 0; } -int main() { +int main(int argc, char **argv) +{ now = time(NULL); openlog("reaper", LOG_PID | LOG_PERROR, SYSLOG_FACILITY); chdir(BBSHOME); - + + attach_SHM(); if(passwd_mmap()) exit(1); passwd_apply2(check); diff --git a/pttbbs/util/rmuid.c b/pttbbs/util/rmuid.c index 901a31c8..2bd1017a 100644 --- a/pttbbs/util/rmuid.c +++ b/pttbbs/util/rmuid.c @@ -1,4 +1,4 @@ -/* $Id: rmuid.c,v 1.3 2002/06/06 21:34:14 in2 Exp $ */ +/* $Id: rmuid.c,v 1.4 2003/07/20 00:55:34 in2 Exp $ */ #include "bbs.h" extern int numboards; @@ -23,7 +23,8 @@ int main(int argc, char* argv[]) int n; boardheader_t bh; //char pathname[1024]; - + + attach_SHM(); resolve_boards(); for (n=0;n<numboards;n++){ memcpy( &bh, &bcache[n], sizeof(bh)); diff --git a/pttbbs/util/shmctl.c b/pttbbs/util/shmctl.c index 66c9888e..382a823b 100644 --- a/pttbbs/util/shmctl.c +++ b/pttbbs/util/shmctl.c @@ -1,4 +1,4 @@ -/* $Id: shmctl.c,v 1.44 2003/07/04 02:31:58 in2 Exp $ */ +/* $Id: shmctl.c,v 1.45 2003/07/20 00:55:34 in2 Exp $ */ #include "bbs.h" #include <sys/wait.h> @@ -272,6 +272,7 @@ int utmpsortd(int argc, char **argv) return 0; } + setproctitle("shmctl utmpsortd"); if( argc != 2 || (interval = atoi(argv[1])) < 500000 ) interval = 1000000; // default to 1 sec @@ -439,6 +440,7 @@ int timed(int argc, char **argv) perror("fork()"); if( pid != 0 ) return 0; + setproctitle("shmctl timed"); while( 1 ){ SHM->GV2.e.now = time(NULL); sleep(1); @@ -446,6 +448,79 @@ int timed(int argc, char **argv) } #endif +#if 0 +void buildclass(int bid, int level) +{ + boardheader_t *bptr; + if( level == 20 ){ /* for safty */ + printf("is there something wrong? class level: %d\n", level); + return; + } + bptr = &bcache[bid]; + if (bptr->firstchild[0] == NULL || bptr->childcount <= 0) + load_uidofgid(bid + 1, 1); /* 因為這邊 bid從 0開始, 所以再 +1 回來 */ + if (bptr->firstchild[1] == NULL || bptr->childcount <= 0) + load_uidofgid(bid + 1, 1); /* 因為這邊 bid從 0開始, 所以再 +1 回來 */ + + for (bptr = bptr->firstchild[0]; bptr != (boardheader_t *) ~ 0; + bptr = bptr->next[0]) { + if( bptr->brdattr & BRD_GROUPBOARD ) + buildclass(bptr - bcache, level + 1); + } +} +#endif + +int bBMC(int argc, char **argv) +{ + int i; + for( i = 0 ; i < MAX_BOARD ; ++i ) + if( bcache[i].brdname[0] ) + buildBMcache(i + 1); /* XXXbid */ + return 0; +} + +int SHMinit(int argc, char **argv) +{ + int ch; + int no_uhash_loader = 0; + while( (ch = getopt(argc, argv, "n")) != -1 ) + switch( ch ){ + case 'n': + no_uhash_loader = 1; + break; + default: + printf("usage:\tshmctl\tSHMinit\n"); + return 0; + } + + puts("loading uhash..."); + system("bin/uhash_loader"); + + attach_SHM(); + + puts("loading bcache..."); + reload_bcache(); + + puts("building BMcache..."); + bBMC(1, NULL); + +#if 0 + puts("building class..."); + buildclass(0, 0); +#endif + + if( !no_uhash_loader ){ + puts("utmpsortd..."); + utmpsortd(1, NULL); + } + +#ifdef OUTTA_TIMER + puts("timed..."); + timed(1, NULL); +#endif + return 0; +} + struct { int (*func)(int, char **); char *cmd, *descript; @@ -463,22 +538,23 @@ struct { #ifdef OUTTA_TIMER {timed, "timed", "time daemon for OUTTA_TIMER"}, #endif + {bBMC, "bBMC", "build BM cache"}, + {SHMinit, "SHMinit", "initialize SHM (including uhash_loader)"}, {NULL, NULL, NULL} }; int main(int argc, char **argv) { int i = 0; + chdir(BBSHOME); if( argc >= 2 ){ - /* shmctl shouldn't create shm itself */ - int shmid = shmget(SHM_KEY, sizeof(SHM_t), 0); - if( shmid < 0 ){ - printf("%d\n", errno); - perror("attach utmpshm"); - return 1; + if( strcmp(argv[1], "init") == 0 ){ + /* in this case, do NOT run attach_SHM here. + because uhash_loader is not run yet. */ + return SHMinit(argc - 1, &argv[1]); } - chdir(BBSHOME); - resolve_utmp(); + + attach_SHM(); /* shmctl doesn't need resolve_boards() first */ //resolve_boards(); resolve_garbage(); diff --git a/pttbbs/util/toplazyBBM.c b/pttbbs/util/toplazyBBM.c index 1b12eab9..0e5b078b 100644 --- a/pttbbs/util/toplazyBBM.c +++ b/pttbbs/util/toplazyBBM.c @@ -1,4 +1,4 @@ -/* $Id: toplazyBBM.c,v 1.6 2002/11/02 11:02:44 in2 Exp $ */ +/* $Id: toplazyBBM.c,v 1.7 2003/07/20 00:55:34 in2 Exp $ */ #define _UTIL_C_ #include "bbs.h" @@ -48,6 +48,7 @@ int main(int argc, char *argv[]) int bmid, i, j=0; FILE *inf, *firef; + attach_SHM(); resolve_boards(); if(passwd_mmap()) diff --git a/pttbbs/util/toplazyBM.c b/pttbbs/util/toplazyBM.c index fc656817..5dc9a3df 100644 --- a/pttbbs/util/toplazyBM.c +++ b/pttbbs/util/toplazyBM.c @@ -1,4 +1,4 @@ -/* $Id: toplazyBM.c,v 1.17 2002/11/02 11:02:44 in2 Exp $ */ +/* $Id: toplazyBM.c,v 1.18 2003/07/20 00:55:34 in2 Exp $ */ #define _UTIL_C_ #include "bbs.h" #define OUTFILE BBSHOME "/etc/toplazyBM" @@ -46,6 +46,7 @@ int main(int argc, char *argv[]) int bmid, i, j=0; FILE *inf, *firef; time_t now=time(NULL); + attach_SHM(); resolve_boards(); if(passwd_mmap()) diff --git a/pttbbs/util/topusr.c b/pttbbs/util/topusr.c index 3b90a7e2..37b051d9 100644 --- a/pttbbs/util/topusr.c +++ b/pttbbs/util/topusr.c @@ -1,4 +1,4 @@ -/* $Id: topusr.c,v 1.3 2002/11/02 11:02:44 in2 Exp $ */ +/* $Id: topusr.c,v 1.4 2003/07/20 00:55:34 in2 Exp $ */ /* 使用者 上站記錄/文章篇數 排行榜 */ #define _UTIL_C_ #include "bbs.h" @@ -90,20 +90,6 @@ int } } #endif /* HAVE_TIN */ -int - not_alpha(ch) -register char ch; -{ - return (ch < 'A' || (ch > 'Z' && ch < 'a') || ch > 'z'); -} - -int - not_alnum(ch) -register char ch; -{ - return (ch < '0' || (ch > '9' && ch < 'A') || - (ch > 'Z' && ch < 'a') || ch > 'z'); -} int bad_user_id(userid) @@ -122,9 +108,7 @@ char *userid; return 0; } -int main(argc, argv) -int argc; -char **argv; +int main(int argc, char **argv) { int i, j; @@ -138,6 +122,7 @@ char **argv; if (num == 0) num = 30; + attach_SHM(); if(passwd_mmap()) { printf("Sorry, the data is not ready.\n"); diff --git a/pttbbs/util/util_cache.c b/pttbbs/util/util_cache.c deleted file mode 100644 index a8dd6b71..00000000 --- a/pttbbs/util/util_cache.c +++ /dev/null @@ -1,565 +0,0 @@ -/* $Id: util_cache.c,v 1.11 2003/05/16 18:58:49 ptt Exp $ */ -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <signal.h> -#include <unistd.h> -#include <fcntl.h> -#include <ctype.h> -#include <errno.h> -#include <time.h> -#include <sys/types.h> -#include <sys/types.h> -#include <sys/mman.h> -#include <sys/ipc.h> -#include <sys/shm.h> -#include <sys/sem.h> - -#ifdef __FreeBSD__ -#include <machine/param.h> -#endif - -#include "config.h" -#include "pttstruct.h" -#include "common.h" -#include "perm.h" -#include "modes.h" -#include "proto.h" - -/* the reason for "safe_sleep" is that we may call sleep during - SIGALRM handler routine, while SIGALRM is blocked. - if we use the original sleep, we'll never wake up. */ -unsigned int safe_sleep(unsigned int seconds) { - /* jochang sleep有問題時用*/ - sigset_t set,oldset; - - sigemptyset(&set); - sigprocmask(SIG_BLOCK, &set, &oldset); - if(sigismember(&oldset, SIGALRM)) { - unsigned long retv; - sigemptyset(&set); - sigaddset(&set,SIGALRM); - sigprocmask(SIG_UNBLOCK,&set,NULL); - retv=sleep(seconds); - sigprocmask(SIG_BLOCK,&set,NULL); - return retv; - } - return sleep(seconds); -} - -void setapath(char *buf, char *boardname) { - sprintf(buf, "man/boards/%c/%s", boardname[0], boardname); -} - -static char *str_dotdir = ".DIR"; - -void setadir(char *buf, char *path) { - sprintf(buf, "%s/%s", path, str_dotdir); -} - -static void attach_err(int shmkey, char *name) { - fprintf(stderr, "[%s error] key = %x\n", name, shmkey); - fprintf(stderr, "errno = %d: %s\n", errno, strerror(errno)); - exit(1); -} - -void *attach_shm(int shmkey, int shmsize) { - void *shmptr; - int shmid; - - char *empty_addr; - /* set up one page in-accessible -- jochang */ - { - int fd = open("/dev/zero",O_RDONLY); - int size = ((shmsize + 4095) / 4096) * 4096; - - munmap( - (empty_addr=mmap(0,4096+size,PROT_NONE,MAP_PRIVATE,fd,0))+4096 - ,size); - - close(fd); - } - - shmid = shmget(shmkey, shmsize, 0); - if(shmid < 0) { - shmid = shmget(shmkey, shmsize, IPC_CREAT | 0600); - if(shmid < 0) - attach_err(shmkey, "shmget"); - shmptr = (void *)shmat(shmid, NULL, 0); - if(shmptr == (void *)-1) - attach_err(shmkey, "shmat"); - } else { - shmptr = (void *)shmat(shmid, NULL, 0); - if(shmptr == (void *)-1) - attach_err(shmkey, "shmat"); - } - - /* unmap the page -- jochang */ - { - munmap(empty_addr,4096); - } - return shmptr; -} - -#ifndef __FreeBSD__ -/* according to X/OPEN we have to define it ourselves */ -union semun { - int val; /* value for SETVAL */ - struct semid_ds *buf; /* buffer for IPC_STAT, IPC_SET */ - unsigned short int *array; /* array for GETALL, SETALL */ - struct seminfo *__buf; /* buffer for IPC_INFO */ -}; -#endif - -#define SEM_FLG 0600 /* semaphore mode */ - -/* ----------------------------------------------------- */ -/* semaphore : for critical section */ -/* ----------------------------------------------------- */ -void sem_init(int semkey,int *semid) { - union semun s; - - s.val=1; - *semid = semget(semkey, 1, 0); - if(*semid == -1) { - *semid = semget(semkey, 1, IPC_CREAT | SEM_FLG); - if(*semid == -1) - attach_err(semkey, "semget"); - semctl(*semid, 0, SETVAL, s); - } -} - -void sem_lock(int op,int semid) { - struct sembuf sops; - - sops.sem_num = 0; - sops.sem_flg = SEM_UNDO; - sops.sem_op = op; - semop(semid, &sops, 1); -} - -SHM_t *SHM; -int *GLOBALVAR; -boardheader_t *bcache; -int numboards = -1; - -void attach_SHM(void) -{ - SHM = attach_shm(SHM_KEY, sizeof(SHM_t)); - if( !SHM->loaded ) /* (uhash) assume fresh shared memory is zeroed */ - exit(1); - if( SHM->Btouchtime == 0 ) - SHM->Btouchtime = 1; - bcache = SHM->bcache; - - GLOBALVAR = SHM->GLOBALVAR; - if( SHM->Ptouchtime == 0 ) - SHM->Ptouchtime = 1; - - if( SHM->Ftouchtime == 0 ) - SHM->Ftouchtime = 1; - - bcache = SHM->bcache; - numboards = SHM->Bnumber; -} - -int setumoney(int uid, int money) { - SHM->money[uid-1]=money; - passwd_update_money(uid); - return SHM->money[uid-1]; -} - -int deumoney(int uid, int money) { - if(money<0 && SHM->money[uid-1]<-money) - return setumoney(uid,0); - else - return setumoney(uid,SHM->money[uid-1]+money); -} -int moneyof(int uid){ /* ptt 改進金錢處理效率 */ - return SHM->money[uid-1]; -} - -static unsigned string_hash(unsigned char *s) { - unsigned int v=0; - while(*s) { - v = (v << 8) | (v >> 24); - v ^= toupper(*s++); /* note this is case insensitive */ - } - return (v * 2654435769UL) >> (32 - HASH_BITS); -} - -void add_to_uhash(int n, char *id) { - int *p, h = string_hash(id); - strcpy(SHM->userid[n], id); - - p = &(SHM->hash_head[h]); - - while(*p != -1) - p = &(SHM->next_in_hash[*p]); - - SHM->next_in_hash[*p = n] = -1; -} - -/* note: after remove_from_uhash(), you should add_to_uhash() - (likely with a different name) */ -void remove_from_uhash(int n) { - int h = string_hash(SHM->userid[n]); - int *p = &(SHM->hash_head[h]); - - while(*p != -1 && *p != n) - p = &(SHM->next_in_hash[*p]); - if(*p == n) - *p = SHM->next_in_hash[n]; -} - -int searchuser(char *userid) { - int h,p; - - if(SHM == NULL) - attach_SHM(); /* for sloopy util programs */ - - h = string_hash(userid); - p = SHM->hash_head[h]; - - while(p != -1) { - if(strcasecmp(SHM->userid[p],userid) == 0) { - strcpy(userid,SHM->userid[p]); - return p + 1; - } - p = SHM->next_in_hash[p]; - } - return 0; -} -userec_t xuser; - -int getuser(char *userid) { - int uid; - if((uid = searchuser(userid))) - passwd_query(uid, &xuser); - return uid; -} - -void setuserid(int num, char *userid) { - if(num > 0 && num <= MAX_USERS) { - if(num > SHM->number) - SHM->number = num; - else - remove_from_uhash(num-1); - add_to_uhash(num-1,userid); - } -} - -/*-------------------------------------------------------*/ -/* .UTMP cache */ -/*-------------------------------------------------------*/ -void resolve_utmp() { - if(SHM == NULL) { - attach_SHM(); - if(SHM->UTMPuptime == 0) - SHM->UTMPuptime = SHM->UTMPnumber = 1; - } -} - -userinfo_t *currutmp = NULL; - -void getnewutmpent(userinfo_t *up) { - extern int errno; - register int i; - register userinfo_t *uentp; - - resolve_utmp(); - - for(i = 0; i < USHM_SIZE; i++) { - uentp = &(SHM->uinfo[i]); - if(!(uentp->pid)) { - memcpy(uentp, up, sizeof(userinfo_t)); - currutmp = uentp; - SHM->number++; - return; - } - } - exit(1); -} - -int apply_ulist(int (*fptr)(userinfo_t *)) { - register userinfo_t *uentp; - register int i, state; - - resolve_utmp(); - for(i = 0; i < USHM_SIZE; i++) { - uentp = &(SHM->uinfo[i]); - if(uentp->pid && (PERM_HIDE(currutmp) || !PERM_HIDE(uentp))) - if((state = (*fptr) (uentp))) - return state; - } - return 0; -} - -userinfo_t *search_ulist(int uid) { - register int i; - register userinfo_t *uentp; - - resolve_utmp(); - for(i = 0; i < USHM_SIZE; i++) { - uentp = &(SHM->uinfo[i]); - if(uid==uentp->uid) - return uentp; - } - return 0; -} - -/*-------------------------------------------------------*/ -/* .BOARDS cache */ -/*-------------------------------------------------------*/ -char *fn_board=BBSHOME"/"FN_BOARD; -static int -cmpboardname(boardheader_t ** brd, boardheader_t ** tmp) -{ - return strcasecmp((*brd)->brdname, (*tmp)->brdname); -} - -static int -cmpboardclass(boardheader_t ** brd, boardheader_t ** tmp) -{ - return (strncmp((*brd)->title, (*tmp)->title, 4) << 8) + - strcasecmp((*brd)->brdname, (*tmp)->brdname); -} -static void -sort_bcache() -{ - int i; - /* critical section \xa4\xa3\xaf\xe0\xb3\xe6\xbfW\xa9I\xa5s \xa9I\xa5sreload -_bcache or reset_board */ - for (i = 0; i < SHM->Bnumber; i++) { - SHM->bsorted[1][i] = SHM->bsorted[0][i] = &bcache[i]; - } - qsort(SHM->bsorted[0], SHM->Bnumber, sizeof(boardheader_t *), - (QCAST) cmpboardname); - qsort(SHM->bsorted[1], SHM->Bnumber, sizeof(boardheader_t *), - (QCAST) cmpboardclass); -} - - -static void -reload_bcache() -{ - if (SHM->Bbusystate) { - safe_sleep(1); - } - else { - int fd, i; - - SHM->Bbusystate = 1; - if ((fd = open(fn_board, O_RDONLY)) > 0) { - SHM->Bnumber = - read(fd, bcache, MAX_BOARD * sizeof(boardheader_t)) / - sizeof(boardheader_t); - close(fd); - } - memset(SHM->lastposttime, 0, MAX_BOARD * sizeof(time_t)); - SHM->Buptime = SHM->Btouchtime; - sort_bcache(); - for (i = 0; i < SHM->Bnumber; ++i) { - bcache[i].firstchild[0] = NULL; - bcache[i].firstchild[1] = NULL; - } - SHM->Bbusystate = 0; - } -} - -void resolve_boards() { - if(SHM == NULL) { - attach_SHM(); - if(SHM->Btouchtime == 0) - SHM->Btouchtime = 1; - } - - if(SHM->Buptime < SHM->Btouchtime) - reload_bcache(); - numboards = SHM->Bnumber; -} - -void touch_boards() { - time(&(SHM->Btouchtime)); - numboards = -1; - resolve_boards(); -} -void reset_board(int bid) -{ - int fd; - boardheader_t bh; - if(--bid<0)return; - if(SHM->Bbusystate==0) - { - SHM->Bbusystate = 1; - if((fd = open(fn_board, O_RDONLY)) > 0) { - lseek(fd, (off_t)(bid * sizeof(boardheader_t)), SEEK_SET); - read(fd, &bh , sizeof(boardheader_t)); - close(fd); - if(bh.brdname[0] && !strcmp(bh.brdname,bcache[bid].brdname)) - memcpy(&bcache[bid],&bh, sizeof(boardheader_t)); - } - SHM->Bbusystate = 0; - } -} -boardheader_t *getbcache(int bid) { /* Ptt改寫 */ - return bcache + bid - 1; -} - -void touchbtotal(int bid) { - SHM->total[bid - 1] = 0; - SHM->lastposttime[bid - 1] = 0; -} - - -int getbnum(char *bname) { - register int i; - register boardheader_t *bhdr; - - for(i = 0, bhdr = bcache; i++ < numboards; bhdr++) - if( - !strcasecmp(bname, bhdr->brdname)) - return i; - return 0; -} - -/*-------------------------------------------------------*/ -/* PTT cache */ -/*-------------------------------------------------------*/ -/* cachefor 動態看版 */ -void reload_pttcache(void) -{ - if(SHM->Pbusystate) - safe_sleep(1); - else { /* jochang: temporary workaround */ - fileheader_t item, subitem; - char pbuf[256], buf[256], *chr; - FILE *fp, *fp1, *fp2; - int id, section = 0; - - SHM->Pbusystate = 1; - SHM->max_film = 0; - bzero(SHM->notes, sizeof SHM->notes); - setapath(pbuf, "Note"); - setadir(buf, pbuf); - id = 0; - if((fp = fopen(buf, "r"))) { - while(fread(&item, sizeof(item), 1, fp)) { - if(item.title[3]=='<' && item.title[8]=='>') { - sprintf(buf,"%s/%s", pbuf, item.filename); - setadir(buf, buf); - if(!(fp1 = fopen(buf, "r"))) - continue; - SHM->next_refresh[section] = SHM->n_notes[section] = id; - section ++; - while(fread(&subitem, sizeof(subitem), 1, fp1)) { - sprintf(buf,"%s/%s/%s", pbuf, item.filename , - subitem.filename); - if(!(fp2=fopen(buf,"r"))) - continue; - fread(SHM->notes[id],sizeof(char), 200*11, fp2); - SHM->notes[id][200*11 - 1]=0; - id++; - fclose(fp2); - if(id >= MAX_MOVIE) - break; - } - fclose(fp1); - if(id >= MAX_MOVIE || section >= MAX_MOVIE_SECTION) - break; - } - } - fclose(fp); - } - SHM->next_refresh[section] = -1; - SHM->n_notes[section] = SHM->max_film = id-1; - SHM->max_history = SHM->max_film - 2; - if(SHM->max_history > MAX_HISTORY - 1) - SHM->max_history = MAX_HISTORY - 1; - if(SHM->max_history <0) SHM->max_history=0; - - fp = fopen("etc/today_is","r"); - if(fp) { - fgets(SHM->today_is,15,fp); - if((chr = strchr(SHM->today_is,'\n'))) - *chr = 0; - SHM->today_is[15] = 0; - fclose(fp); - } - - /* 等所有資料更新後再設定 uptime */ - - SHM->Puptime = SHM->Ptouchtime ; - SHM->Pbusystate = 0; - } -} - -void resolve_garbage() { - int count=0; - - if(SHM == NULL) { - attach_SHM(); - if(SHM->Ptouchtime == 0) - SHM->Ptouchtime = 1; - } - while(SHM->Puptime < SHM->Ptouchtime) { /* 不用while等 */ - reload_pttcache(); - if(count ++ > 10 && SHM->Pbusystate) { -/* Ptt: 這邊會有問題 load超過10 秒會所有進loop的process都讓 busystate = 0 - 這樣會所有prcosee都會在load 動態看板 會造成load大增 - 但沒有用這個function的話 萬一load passwd檔的process死了 又沒有人把他 - 解開 同樣的問題發生在reload passwd -*/ - SHM->Pbusystate = 0; - } - } -} - -/*-------------------------------------------------------*/ -/* PTT's cache */ -/*-------------------------------------------------------*/ -/* cachefor from host 與最多上線人數 */ -static void reload_fcache() { - if(SHM->Fbusystate) - safe_sleep(1); - else { - FILE *fp; - - SHM->Fbusystate = 1; - bzero(SHM->domain, sizeof SHM->domain); - if((fp = fopen("etc/domain_name_query","r"))) { - char buf[101],*po; - - SHM->top=0; - while(fgets(buf,100,fp)) { - if(buf[0] && buf[0] != '#' && buf[0] != ' ' && - buf[0] != '\n') { - sscanf(buf,"%s",SHM->domain[SHM->top]); - po = buf + strlen(SHM->domain[SHM->top]); - while(*po == ' ') - po++; - strncpy(SHM->replace[SHM->top],po,49); - SHM->replace[SHM->top] - [strlen(SHM->replace[SHM->top])-1] = 0; - (SHM->top)++; - } - } - } - - SHM->max_user=0; - - /* 等所有資料更新後再設定 uptime */ - SHM->Fuptime = SHM->Ftouchtime; - SHM->Fbusystate = 0; - } -} - -void resolve_fcache() { - if(SHM == NULL) { - attach_SHM(); - if(SHM->Ftouchtime == 0) - SHM->Ftouchtime = 1; - } - while(SHM->Fuptime < SHM->Ftouchtime) - reload_fcache(); -} diff --git a/pttbbs/util/xchatd.c b/pttbbs/util/xchatd.c index 97cb33fe..b4aef8a6 100644 --- a/pttbbs/util/xchatd.c +++ b/pttbbs/util/xchatd.c @@ -1,4 +1,4 @@ -/* $Id: xchatd.c,v 1.2 2002/06/06 21:34:15 in2 Exp $ */ +/* $Id: xchatd.c,v 1.3 2003/07/20 00:55:34 in2 Exp $ */ #include "bbs.h" #include "xchatd.h" @@ -158,25 +158,6 @@ acct_load(acct, userid) } } - -/* ----------------------------------------------------- */ -/* str_lower for check acct */ -/* ----------------------------------------------------- */ -void -str_lower(dst, src) - char *dst, *src; -{ - register int ch; - - do - { - ch = *src++; - if (ch >= 'A' && ch <= 'Z') - ch |= 0x20; - *dst++ = ch; - } while (ch); -} - /* * str_ncpy() - similar to strncpy(3) but terminates string always with '\0' * if n != 0, and doesn't do padding @@ -3121,6 +3102,7 @@ start_daemon() setsid(); + attach_SHM(); /* --------------------------------------------------- */ /* adjust the resource limit */ /* --------------------------------------------------- */ diff --git a/pttbbs/util/yearsold.c b/pttbbs/util/yearsold.c index 93cb4a1b..3229b709 100644 --- a/pttbbs/util/yearsold.c +++ b/pttbbs/util/yearsold.c @@ -1,4 +1,4 @@ -/* $Id: yearsold.c,v 1.4 2002/11/02 11:02:44 in2 Exp $ */ +/* $Id: yearsold.c,v 1.5 2003/07/20 00:55:34 in2 Exp $ */ /* 站上年齡統計 */ #define _UTIL_C_ #include "bbs.h" @@ -23,7 +23,7 @@ char buf[], mode; } } -int main() +int main(int argc, char **argv) { int i, j, k; char buf[256]; @@ -37,6 +37,7 @@ int main() now = time(NULL); ptime = localtime(&now); + attach_SHM(); if(passwd_mmap()) exit(1); -- cgit v1.2.3 From 8e27397ff2298d6afd6067d2ffae8a65db5adf58 Mon Sep 17 00:00:00 2001 From: bbs <bbs@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sun, 20 Jul 2003 01:20:11 +0000 Subject: non-init var git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@1066 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/user.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pttbbs/mbbsd/user.c b/pttbbs/mbbsd/user.c index 39a68c0b..53ea8d19 100644 --- a/pttbbs/mbbsd/user.c +++ b/pttbbs/mbbsd/user.c @@ -1,4 +1,4 @@ -/* $Id: user.c,v 1.71 2003/07/18 11:03:45 victor Exp $ */ +/* $Id: user.c,v 1.72 2003/07/20 01:20:11 bbs Exp $ */ #include "bbs.h" static char *sex[8] = { @@ -1254,6 +1254,8 @@ u_register(void) getfield(2, "Y/n", "是否為本國籍?", fore, 2); if (fore[0] == 'n') fore[0] |= FOREIGN; + else + fore[0] = 0; if (!fore[0]){ #endif while( 1 ){ -- cgit v1.2.3 From acf2c948cd7217ae10ecd5f29bd21d317a848d73 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sun, 20 Jul 2003 02:46:43 +0000 Subject: use shmctl init git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@1067 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/docs/INSTALL | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pttbbs/docs/INSTALL b/pttbbs/docs/INSTALL index f03e94b8..474db2ae 100644 --- a/pttbbs/docs/INSTALL +++ b/pttbbs/docs/INSTALL @@ -46,8 +46,7 @@ 假如一切都很順利的話,這樣子大概就安裝完了 接下來是啟動 bbs 的部份 - 14.執行 bin/uhash_loader (*註1, *註2) - 15.執行 bin/shmctl utmpsortd + 14.執行 bin/shmctl init (*註1, *註2) 16.用 root 執行 bin/mbbsd 23 (註2) 17.測試整個系統是否完成: -- cgit v1.2.3 From 4d04208a5ed7b2fa3d2669638ce03ead8874f93e Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sun, 20 Jul 2003 02:48:03 +0000 Subject: remove INSTALL.old git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@1068 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/docs/INSTALL.old | 49 ------------------------------------------------- 1 file changed, 49 deletions(-) delete mode 100755 pttbbs/docs/INSTALL.old diff --git a/pttbbs/docs/INSTALL.old b/pttbbs/docs/INSTALL.old deleted file mode 100755 index 5bd484d5..00000000 --- a/pttbbs/docs/INSTALL.old +++ /dev/null @@ -1,49 +0,0 @@ -底下是快速安裝的方法 - -== - -先取得 root 權限 - -1. 打 vipw, 加入底下兩行 - - bbs:*:9999:99::0:0:Ptt BBS:/home/bbs:/home/bbs/bin/bbsrf - bbsadm::9999:99::0:0:Ptt BBS:/home/bbs:/bin/csh - -2. 執行 passwd bbsadm 設 bbsadm的密碼 -3. 在 /etc/group 中加入一行 - - bbs:*:99: - -4. 執行 mkdir /home/bbs -5. 執行 chown bbs.bbs /home/bbs -6. 執行 chmod 700 /home/bbs - -然後切換成 bbsadm 的身份 - -7. 取得解開 pttbbs-VERSION.tar.gz (任何目錄下皆可). -8. 執行 cd pttbbs -9. 如果之前沒有設定過 pttbbs.conf 的話, 請 cp sample/pttbbs.conf pttbbs.conf -10. 修改 pttbbs.conf -11. 執行 make OSTYPE=FreeBSD BBSHOME=/home/bbs all install - (Linux使用者請把 "FreeBSD" 改成 "linux") -12. 如果是新架起來的站, 請執行 cd sample; make install -12. 執行 cd /home/bbs; bin/initbbs - -假如一切都很順利的話,這樣子大概就安裝完了 -接下來是啟動 bbs 的部份 - -13. 執行 bin/uhash_loader (*註1) -14. 用 root 執行 bin/mbbsd 23 (註2) - -telnet localhost 23 看看 -new一個帳號叫SYSOP,然後logout再login, 這樣子就會擁有站長權限囉~ -再new一個帳號叫 guest, 這樣子別人就可以用 guest 參觀你的站了 -開板,開群組,以及搬動群組的方法請看 PttSrc 板的文摘 - -註: -1. 這個程式是在 initial shared memory 用的, 只有開機後第一次執行, 或是 - 你手動清除 shm 後才需要執行 - -2. bin/mbbsd 23 是指定要 bind 23 port, 依照 UNIX 規定, 1024 以下的 port - 須要有 root 權限, 所以如果要 bind 23 port 的話就要用 root 去執行, - 3000 port 則不需要 -- cgit v1.2.3 From 2f58e3bc5711ffc00207497feaf4eced2e4731e3 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sun, 20 Jul 2003 02:48:09 +0000 Subject: use shmctl init git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@1069 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/docs/ADVANCE | 2 +- pttbbs/docs/INSTALL | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pttbbs/docs/ADVANCE b/pttbbs/docs/ADVANCE index 352cad36..6c40d53a 100644 --- a/pttbbs/docs/ADVANCE +++ b/pttbbs/docs/ADVANCE @@ -26,7 +26,7 @@ bbsctl 您可以直接打 bbsctl 來看有什麼功能. 主要的功能說明如下: 1.bbsctl start - 用於啟動 mbbsd (須先跑 uhash_loader) + 用於啟動 mbbsd (須先跑 shmctl init) 以往因為要 bind port 23 須要 root 所以要手動 su , 不過現在有 bbsctl with setuid , 請直接使用 bbsctl start , 即可將 mbbsd跑起來. diff --git a/pttbbs/docs/INSTALL b/pttbbs/docs/INSTALL index 474db2ae..9912d930 100644 --- a/pttbbs/docs/INSTALL +++ b/pttbbs/docs/INSTALL @@ -82,7 +82,7 @@ 1. 這個程式是在 initial shared memory 用的, 只有開機後第一次執行, 或是 你手動清除 shm 後才需要執行 -2. 如果您跑了 uhash_loader 並沒有看到 +2. 如果您跑了 shmctl init 或 uhash_loader 並沒有看到 total XXXXX names loaded. 而是看到其他的錯誤訊息 (例如 [shmget error] key = 4cc, errno = 22: Invalid argument) -- cgit v1.2.3 From fbfb35c92cc07b638294e35c9d9d8e14794afe2a Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sun, 20 Jul 2003 02:50:21 +0000 Subject: use bbsctl start git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@1070 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/sample/pttbbs.sh | 4 ++-- pttbbs/sample/rc.local | 15 +++------------ 2 files changed, 5 insertions(+), 14 deletions(-) diff --git a/pttbbs/sample/pttbbs.sh b/pttbbs/sample/pttbbs.sh index d5588b8a..24d19106 100755 --- a/pttbbs/sample/pttbbs.sh +++ b/pttbbs/sample/pttbbs.sh @@ -13,8 +13,8 @@ start) # 轉信 /usr/bin/su -fm bbs -c /home/bbs/innd/innbbsd & - # 啟動 port 23 (port 23須使用 root 才能進行 bind ) - /home/bbs/bin/mbbsd 23 & + # 啟動 port 23 (port 23須使用 root 才能進行 bind ) 以其他 + /home/bbs/bin/bbsctl start # 提示 echo -n ' mbbsd' diff --git a/pttbbs/sample/rc.local b/pttbbs/sample/rc.local index 4da3d8d5..c266f9bf 100644 --- a/pttbbs/sample/rc.local +++ b/pttbbs/sample/rc.local @@ -1,16 +1,7 @@ #!/bin/sh +# WARNING: this script is run by root!! + /usr/bin/su bbsadm -c /home/bbs/bin/shmctl init /usr/bin/su bbsadm -c /home/bbs/bin/outmail& /usr/bin/su bbsadm -c /home/bbs/innd/innbbsd 7777 -/home/bbs/bin/mbbsd 23 & -/home/bbs/bin/mbbsd 3000 & -/home/bbs/bin/mbbsd 3001 & -/home/bbs/bin/mbbsd 3002 & -/home/bbs/bin/mbbsd 3003 & -/home/bbs/bin/mbbsd 3004 & -/home/bbs/bin/mbbsd 3005 & -/home/bbs/bin/mbbsd 3006 & -/home/bbs/bin/mbbsd 3007 & -/home/bbs/bin/mbbsd 3008 & -/home/bbs/bin/mbbsd 3009 & -/home/bbs/bin/mbbsd 3010 & +/home/bbs/bin/bbsctl start -- cgit v1.2.3 From 945330d89fc30f1747bd536350c211787fec08c2 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Mon, 21 Jul 2003 07:11:50 +0000 Subject: add attach_SHM() git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@1071 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/bbsmail.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/pttbbs/util/bbsmail.c b/pttbbs/util/bbsmail.c index 8e326ad7..7ef9435d 100644 --- a/pttbbs/util/bbsmail.c +++ b/pttbbs/util/bbsmail.c @@ -1,4 +1,4 @@ -/* $Id: bbsmail.c,v 1.7 2003/04/10 10:26:08 in2 Exp $ */ +/* $Id: bbsmail.c,v 1.8 2003/07/21 07:11:50 in2 Exp $ */ #define _UTIL_C_ #include "bbs.h" @@ -243,18 +243,18 @@ main(int argc, char* argv[]) { char receiver[512]; - if( passwd_mmap() ) - return 0; - chdir(BBSHOME); /* argv[1] is userid in bbs */ - if (argc < 2) - { + if (argc < 2){ printf("Usage:\t%s <bbs_uid>\n", argv[0]); exit(-1); } (void) setgid(BBSGID); (void) setuid(BBSUID); + attach_SHM(); + if( passwd_mmap() ) + return 0; + chdir(BBSHOME); strlcpy(receiver, argv[1], sizeof(receiver)); -- cgit v1.2.3 From 483d8cd52226af689a5f2a3a4265fe4b6700c69d Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Mon, 21 Jul 2003 09:27:00 +0000 Subject: fix error make rule for bbsmail git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@1072 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/Makefile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pttbbs/util/Makefile b/pttbbs/util/Makefile index a62ee3a8..4929a5a2 100644 --- a/pttbbs/util/Makefile +++ b/pttbbs/util/Makefile @@ -1,4 +1,4 @@ -# $Id: Makefile,v 1.36 2003/07/20 00:55:34 in2 Exp $ +# $Id: Makefile,v 1.37 2003/07/21 09:27:00 in2 Exp $ .include "../pttbbs.mk" @@ -29,7 +29,7 @@ PROGS= ${UTIL_OBJS} ${CPROG_WITH_UTIL} ${CPROG_WITHOUT_UTIL} \ dailybackup.pl tarqueue.pl waterball.pl filtermail.pl \ getbackup.pl udnnews.pl rebuildaloha.pl railway_wrapper.pl -all: ${CPROG_WITH_UTIL} ${CPROG_WITHOUT_UTIL} ${PROGS} bbsmail +all: ${CPROG_WITH_UTIL} ${CPROG_WITHOUT_UTIL} ${PROGS} .for fn in ${CPROG_WITH_UTIL} ${fn}: ${fn}.c ${UTIL_OBJS} @@ -45,7 +45,7 @@ util_stuff.o: ../mbbsd/stuff.c util_cache.o: ../mbbsd/cache.c ${CC} ${CFLAGS} -D_BBS_UTIL_C_ -c -o util_cache.o ../mbbsd/cache.c -bbsmail: bbsmail.c ${CPROG_WITH_UTIL} ../mbbsd/osdep.o +bbsmail: bbsmail.c ${UTIL_OBJS} ../mbbsd/osdep.o ${CC} ${CFLAGS} -o bbsmail bbsmail.c ${UTIL_OBJS} ../mbbsd/osdep.o ${LDFLAGS} xchatd: xchatd.c $(UTIL_OBJS) descrypt.c -- cgit v1.2.3 From 757ddf2c2c6ef87af84cab5583fc53f513a7285d Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Mon, 21 Jul 2003 09:27:16 +0000 Subject: add BM git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@1073 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/boardlist.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/pttbbs/util/boardlist.c b/pttbbs/util/boardlist.c index bb23393a..42fd707a 100644 --- a/pttbbs/util/boardlist.c +++ b/pttbbs/util/boardlist.c @@ -1,4 +1,4 @@ -/* $Id: boardlist.c,v 1.3 2003/07/11 10:13:49 in2 Exp $ */ +/* $Id: boardlist.c,v 1.4 2003/07/21 09:27:16 in2 Exp $ */ /* 這是用來將樹狀分類輸出成 perl module (可以給像是 man/ 使用) */ #include "bbs.h" @@ -46,6 +46,8 @@ char *skipEscape(char *s) void dumpclass(int bid) { boardheader_t *bptr; + char BM[IDLEN * 3 + 3], *p; + bptr = &bcache[bid]; if (bptr->firstchild[0] == NULL || bptr->childcount <= 0) load_uidofgid(bid + 1, 0); /* 因為這邊 bid從 0開始, 所以再 +1 回來 */ @@ -58,9 +60,17 @@ void dumpclass(int bid) ~(PERM_BASIC|PERM_CHAT|PERM_PAGE|PERM_POST|PERM_LOGINOK))) ) continue; - printf(" [%5d, '%s', '%s'], \n", + printf(" [%5d, '%s', '%s', [", (bptr->brdattr & BRD_GROUPBOARD) ? bptr - bcache : -1, bptr->brdname, skipEscape(&bptr->title[7])); + strlcpy(BM, bptr->BM, sizeof(BM)); + for( p = BM ; *p != 0 ; ++p ) + if( !isalpha(*p) && !isdigit(*p) ) + *p = ' '; + for( p = strtok(BM, " ") ; p != NULL ; p = strtok(NULL, " ") ){ + printf("'%s',", p); + } + printf("]],\n"); } printf(" ],\n"); -- cgit v1.2.3 From 8eb6342572fb997b86dbe6c6b07ba0cd056db4b4 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Tue, 22 Jul 2003 03:51:43 +0000 Subject: for FreeBSD5 git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@1074 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/docs/INSTALL | 1 + pttbbs/include/bbs.h | 6 +++++- pttbbs/pttbbs.mk | 5 ++++- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/pttbbs/docs/INSTALL b/pttbbs/docs/INSTALL index 9912d930..0c5b884e 100644 --- a/pttbbs/docs/INSTALL +++ b/pttbbs/docs/INSTALL @@ -38,6 +38,7 @@ 10.修改 pttbbs.conf * 如果您是用 Linux系統, 請先安裝 pmake, 然後將 make alias 成 pmake * 11.執行 make OSTYPE=FreeBSD BBSHOME=/home/bbs all install + (若是使用 FreeBSD 5.x的話, 請如上 FreeBSD5=1 ) ( Linux使用者請把 "FreeBSD" 改成 "linux") (如果出現 iconv.h找不到的話, 請見 FAQ 7 ) 12.如果是新架起來的站, 請執行 cd sample; make install diff --git a/pttbbs/include/bbs.h b/pttbbs/include/bbs.h index 7b4b4319..e119265d 100644 --- a/pttbbs/include/bbs.h +++ b/pttbbs/include/bbs.h @@ -36,7 +36,11 @@ /* os dependant include file, define */ #ifdef FreeBSD - #include <machine/limits.h> + #ifdef FreeBSD5 + #include <sys/limits.h> + #else + #include <machine/limits.h> + #endif #include <machine/param.h> #endif #ifdef Linux diff --git a/pttbbs/pttbbs.mk b/pttbbs/pttbbs.mk index 7b69dda6..265aaa46 100644 --- a/pttbbs/pttbbs.mk +++ b/pttbbs/pttbbs.mk @@ -1,4 +1,4 @@ -# $Id: pttbbs.mk,v 1.7 2003/07/17 03:47:26 victor Exp $ +# $Id: pttbbs.mk,v 1.8 2003/07/22 03:51:43 in2 Exp $ # 定義基本初值 BBSHOME?= $(HOME) BBSHOME?= /home/bbs @@ -49,3 +49,6 @@ CFLAGS+= -DDEBUG CFLAGS+= -DNO_FORK .endif +.if defined(FreeBSD5) +CFLAGS+= -DFreeBSD5 +.endif -- cgit v1.2.3 From 323a29ae9f3474b8b017ffe8c7ee18d5633a9f9a Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Tue, 22 Jul 2003 06:06:39 +0000 Subject: check program for newsfeeds.bbs git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk@1075 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/innbbsd/inncheck.pl | 47 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 pttbbs/innbbsd/inncheck.pl diff --git a/pttbbs/innbbsd/inncheck.pl b/pttbbs/innbbsd/inncheck.pl new file mode 100644 index 00000000..2b98a305 --- /dev/null +++ b/pttbbs/innbbsd/inncheck.pl @@ -0,0 +1,47 @@ +#!/usr/bin/perl +use IO::Socket::INET; +$BBSHOME = '/home/bbs'; + +open NODES, "<$BBSHOME/innd/nodelist.bbs"; +while( <NODES> ){ + next if( /^\#/ ); + + ($nodename, $host) = $_ =~ /^(\S+)\s+(\S+)/; + next if( !$nodename ); + + $sock = IO::Socket::INET->new(PeerAddr => $host, + PeerPort => 119, + Proto => 'tcp'); + next if( !$sock ); + $sock->write("list\r\nquit\r\n"); + $sock->read($data, 104857600); + + foreach( split("\n", $data) ){ + $group{$nodename}{$1} = 1 + if( /^([A-Za-z0-9\.]+) \d+ \d+ y/ ); + } +} + +open FEEDS, "<$BBSHOME/innd/newsfeeds.bbs"; +while( <FEEDS> ){ + ++$line; + next if( /^\#/ ); + + next if( !(($gname, $board, $nodename) = + $_ =~ /^([\w\.]+)\s+(\w+)\s+(\w+)/) ); + + if( !-d ("$BBSHOME/boards/". substr($board, 0, 1). "/$board") ){ + print "$line: board not found ($board)\n"; + next; + } + + if( !$group{$nodename} ){ + print "$line: node not found ($nodename)\n"; + next; + } + + if( !$group{$nodename}{$gname} ){ + print "$line: group not found ($gname)\n"; + } +} + -- cgit v1.2.3 -- cgit v1.2.3 From eb1d25d59c39b69ee696771cb9a807dea5d29818 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Fri, 25 Jul 2003 13:55:37 +0000 Subject: switch to svn git-svn-id: http://opensvn.csie.org/pttbbs/trunk@1078 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/docs/INSTALL | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/pttbbs/docs/INSTALL b/pttbbs/docs/INSTALL index 0c5b884e..b1297830 100644 --- a/pttbbs/docs/INSTALL +++ b/pttbbs/docs/INSTALL @@ -22,18 +22,23 @@ 以下用 bbsadm 的身份 ==================== - 7. 取得解開 pttbbs-VERSION.tar.gz (任何目錄下皆可). - - 或透過 cvs來取得 (強烈建議) - touch ~/.cvspass - cvs -d :pserver:cvs@ptt2.csie.ntu.edu.tw:/var/db/cvsroot login - (不用打密碼, 直接按 Enter過去) - cvs -d :pserver:cvs@ptt2.csie.ntu.edu.tw:/var/db/cvsroot checkout pttbbs - 使用此法的朋友, 將來您可以直接在 pttbbs/ 下用 - cvs update - 更新到最新版本的 pttbbs - - 8. 執行 cd pttbbs + 7. 先切到所要放置源碼的目錄下 (一般在 /home/bbs) , + 您可以透過下列任一方式取得 pttbbs 的源碼: + + 1)至 ftp://ptt2.csie.ntu.edu.tw 抓得每日自動製作的 snapshot , + 通常檔名長的會像是 pttbbs-DATE-SNAP.tar.gz + + 2)透過 subversion 直接 checkout 一份當前最新的源碼 (強烈建議) + 您必須先安裝 subversion + (in FreeBSD, `cd /usr/ports/devel/subversion/; make all install clean` ) + + 再執行 svn checkout svn://ptt2.csie.ntu.edu.tw/trunk/pttbbs 即可. + + 其中不論您以方式 1或 2取得源碼, 您都可以在該目錄下直接透過 svn update + 更新至 pttbbs 最新的源碼. 如: + cd /home/bbs/pttbbs; svn update + + 8. 執行 cd ~bbs/pttbbs 9. 如果之前沒有設定過 pttbbs.conf 的話, 請 cp sample/pttbbs.conf pttbbs.conf 10.修改 pttbbs.conf * 如果您是用 Linux系統, 請先安裝 pmake, 然後將 make alias 成 pmake * -- cgit v1.2.3 -- cgit v1.2.3 From 0f51b44287062fef303f8196602ad6c119bab7ed Mon Sep 17 00:00:00 2001 From: victor <victor@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sun, 3 Aug 2003 11:20:13 +0000 Subject: fix bug in select_mode git-svn-id: http://opensvn.csie.org/pttbbs/trunk@1080 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/read.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pttbbs/mbbsd/read.c b/pttbbs/mbbsd/read.c index cc5f480a..9cc2c398 100644 --- a/pttbbs/mbbsd/read.c +++ b/pttbbs/mbbsd/read.c @@ -1,4 +1,4 @@ -/* $Id: read.c,v 1.26 2003/07/04 11:37:02 victor Exp $ */ +/* $Id$ */ #include "bbs.h" static fileheader_t *headers = NULL; @@ -515,8 +515,8 @@ select_read(keeploc_t * locmem, int sr_mode) tag = fh.title; temp = strstr(tag, query); if (temp == NULL || temp != tag) { - write(fr, &fh, size); fh.money = reference | FHR_REFERENCE; + write(fr, &fh, size); } } case RS_AUTHOR: @@ -524,8 +524,8 @@ select_read(keeploc_t * locmem, int sr_mode) ++reference; tag = fh.owner; if (strcasestr(tag, query)) { - write(fr, &fh, size); fh.money = reference | FHR_REFERENCE; + write(fr, &fh, size); } } break; @@ -533,8 +533,8 @@ select_read(keeploc_t * locmem, int sr_mode) while (read(fd, &fh, size) == size) { ++reference; if (fh.filemode & FILE_MARKED) { - write(fr, &fh, size); fh.money = reference | FHR_REFERENCE; + write(fr, &fh, size); } } break; -- cgit v1.2.3 From 9d219a8d0e3104888f2d707650eb41ec6b9ee924 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Mon, 4 Aug 2003 06:45:10 +0000 Subject: remove necessary control code in water log git-svn-id: http://opensvn.csie.org/pttbbs/trunk@1081 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/mbbsd.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pttbbs/mbbsd/mbbsd.c b/pttbbs/mbbsd/mbbsd.c index 4220f9b0..f4026102 100644 --- a/pttbbs/mbbsd/mbbsd.c +++ b/pttbbs/mbbsd/mbbsd.c @@ -1,4 +1,4 @@ -/* $Id: mbbsd.c,v 1.90 2003/07/20 00:55:34 in2 Exp $ */ +/* $Id$ */ #include "bbs.h" #define SOCKET_QLEN 4 @@ -304,7 +304,7 @@ show_call_in(int save, int which) } if (fp_writelog) { time(&now); - fprintf(fp_writelog, "%s \033[0m[%s]\n", buf, Cdatelite(&now)); + fprintf(fp_writelog, "%s [%s]\n", buf, Cdatelite(&now)); } } } -- cgit v1.2.3 From 3e340b3ca9f3abc9ce93bcab47136acd8974dcab Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Mon, 4 Aug 2003 06:58:02 +0000 Subject: add SKIP_TELNET_CONTROL_SIGNAL git-svn-id: http://opensvn.csie.org/pttbbs/trunk@1082 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/io.c | 18 ++++++++++++------ pttbbs/sample/pttbbs.conf | 4 ++++ 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/pttbbs/mbbsd/io.c b/pttbbs/mbbsd/io.c index 3b15bbe7..0a48893d 100644 --- a/pttbbs/mbbsd/io.c +++ b/pttbbs/mbbsd/io.c @@ -1,4 +1,4 @@ -/* $Id: io.c,v 1.29 2003/05/07 03:35:07 bbs Exp $ */ +/* $Id$ */ #include "bbs.h" #if defined(linux) @@ -130,11 +130,17 @@ dogetch() if (i_newfd && FD_ISSET(i_newfd, &readfds)) return I_OTHERDATA; } - while ((len = read(0, inbuf, IBUFSIZE)) <= 0) { - if (len == 0 || errno != EINTR) - abort_bbs(0); - /* raise(SIGHUP); */ - } +#ifdef SKIP_TELNET_CONTROL_SIGNAL + do{ +#endif + while ((len = read(0, inbuf, IBUFSIZE)) <= 0) { + if (len == 0 || errno != EINTR) + abort_bbs(0); + /* raise(SIGHUP); */ + } +#ifdef SKIP_TELNET_CONTROL_SIGNAL + } while( inbuf[0] == -1 ); +#endif ibufsize = len; icurrchar = 0; } diff --git a/pttbbs/sample/pttbbs.conf b/pttbbs/sample/pttbbs.conf index 8728884f..8811b6d9 100644 --- a/pttbbs/sample/pttbbs.conf +++ b/pttbbs/sample/pttbbs.conf @@ -102,6 +102,10 @@ /* 若定義, 則在文章列表的時候不同日期會標上不同顏色 */ //#define COLORDATE +/* 若定義, 則會在 read socket的時候, 則會跳過讀入時第一個 byte 是 -1 + (即 telnet 的 control packet), 可避免循環錯誤 */ +//#define SKIP_TELNET_CONTROL_SIGNAL + /* 前進站畫面 */ #define INSCREEN \ "前進站畫面 (請至 pttbbs.conf 修改您的前進站畫面)" -- cgit v1.2.3 From f907798461220997a337195703ba945fd0d2743a Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Mon, 4 Aug 2003 07:03:17 +0000 Subject: use svn:ignore git-svn-id: http://opensvn.csie.org/pttbbs/trunk@1083 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/.cvsignore | 2 -- pttbbs/include/.cvsignore | 1 - pttbbs/mbbsd/.cvsignore | 3 --- pttbbs/pttpi/cgi/.cvsignore | 1 - pttbbs/util/.cvsignore | 47 --------------------------------------------- 5 files changed, 54 deletions(-) delete mode 100644 pttbbs/.cvsignore delete mode 100755 pttbbs/include/.cvsignore delete mode 100644 pttbbs/mbbsd/.cvsignore delete mode 100644 pttbbs/pttpi/cgi/.cvsignore delete mode 100644 pttbbs/util/.cvsignore diff --git a/pttbbs/.cvsignore b/pttbbs/.cvsignore deleted file mode 100644 index 80c7b7f0..00000000 --- a/pttbbs/.cvsignore +++ /dev/null @@ -1,2 +0,0 @@ -tmp -pttbbs.conf diff --git a/pttbbs/include/.cvsignore b/pttbbs/include/.cvsignore deleted file mode 100755 index 38c67d55..00000000 --- a/pttbbs/include/.cvsignore +++ /dev/null @@ -1 +0,0 @@ -var.h diff --git a/pttbbs/mbbsd/.cvsignore b/pttbbs/mbbsd/.cvsignore deleted file mode 100644 index b5881695..00000000 --- a/pttbbs/mbbsd/.cvsignore +++ /dev/null @@ -1,3 +0,0 @@ -*.o -mbbsd -vers.c diff --git a/pttbbs/pttpi/cgi/.cvsignore b/pttbbs/pttpi/cgi/.cvsignore deleted file mode 100644 index 169dce0c..00000000 --- a/pttbbs/pttpi/cgi/.cvsignore +++ /dev/null @@ -1 +0,0 @@ -*.cgi diff --git a/pttbbs/util/.cvsignore b/pttbbs/util/.cvsignore deleted file mode 100644 index 431c9ff0..00000000 --- a/pttbbs/util/.cvsignore +++ /dev/null @@ -1,47 +0,0 @@ -bbsmail -BM_money -post -account -birth -deluserfile -expire -mandex -horoscope -openvice -parse_news -openticket -bmda -uhash_loader -poststat -showboard -topusr -yearsold -cutpasswd -inndBM -antispam -countalldice -webgrep -bbsrf -initbbs -outmail -xchatd -userlist -tunepasswd -buildir -reaper -shmsweep -merge_passwd -merge_board -cpdeadbrd -rmuid -buildAnnounce -toplazyBBM -toplazyBM -jungo -bbsctl -mandex -shmctl -indexuser -diskstat -boardlist -boardlist.pm -- cgit v1.2.3 From 7fd26dab310859c669ee139ae21357ebc2e29778 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Wed, 6 Aug 2003 06:14:06 +0000 Subject: add brc.txt by scw git-svn-id: http://opensvn.csie.org/pttbbs/trunk@1084 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/docs/brc.txt | 154 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 154 insertions(+) create mode 100644 pttbbs/docs/brc.txt diff --git a/pttbbs/docs/brc.txt b/pttbbs/docs/brc.txt new file mode 100644 index 00000000..d25692bf --- /dev/null +++ b/pttbbs/docs/brc.txt @@ -0,0 +1,154 @@ + + BRC documentation by scw 08/05/2003 + +源起: + 這篇文章主要是介紹 brc_* 的函式,這組函式是 pttbbs 用來紀錄文章已讀/未讀 + 的工具,但因為內部的儲存方式十分 tricky 連帶使的內容相當難懂。為了重現及修正 + 其中的一個 bug,筆者有幸弄清了其中運作方式,並為其撰寫說明,希望對管理者有幫 + 助。 + +什麼人該看這篇文章? + 1. pttbbs 的系統管理者。如果您要對這部份進行修改或抓蟲,希望這篇文章能對 + 您有所助益。 + 2. 想要研究這種用極少空間記下極大資訊的方法的人。 + +BRC 是什麼?如何運作? + brc_* 是定義在 pttbbs/mbbsd/board.c 中的一組函式,負責紀錄文章已讀/未讀, + 它的特點是育的空間極少。可以在 2.4k 以內的空間記下一個人在全站的文章已讀/ + 未讀。當然,這樣的方法不可能真正完美,但是對於使用上已經足夠了。為什麼說是不 + 完美呢?這跟紀錄的儲存方式有關。 + 紀錄檔在 home/[first charactor of id]/[id]/.boardrc。檔案格式如下: + + FILE := RECORDS ; + RECORDS := RECORDS RECORD | ; + RECORD := BOARD_NAME BRC_DATA ; + BRC_DATA := BRC_NUM BRC_LIST ; + BRC_LIST := NUM NUM ... NUM ; (共 BRC_NUM 個 NUM) + BOARD_NAME 是 15 bytes 的版名 (#define BRC_STRLEN 15) + BRC_NUM 是對這個版的儲存量,1 byte 以 binary 方式儲存,其值 <= MAX_NUM (80) + BRC_LIST 是對這個版的紀錄,剛好有 BRC_NUM 個 4 bytes integers。 + 另外在 24576 bytes (#define BRC_MAXSIZE 24576) 之外的資料不會被用到。 + + 在下面會看到,BOARD_NAME 不用另外儲存(已經放在user的全域資料裡了),其他 + 兩項, BRC_NUM 跟 BRC_LIST 都會放在相應的全域變數中, brc_num & brc_list 。 + 判定一個檔案是否已經讀過的方法是在 brc_list 中搜尋檔案建立的時間,也就是 + 檔名 M.xxxxxxxxxx.A.yyy 中 xxxxxxxxx 的那個數字。如果這個數字有在 brc_list 中 + 出現就是已讀,要不如果 brc_list 中所以的數字都比這個檔案的建立時間大(也就是 + 這個檔案的建立時間在所有 brc_list 中的時間點之前)也是已讀,最後為了節省空間 + 還有一個判定(其實這個判定是第一個做的),如果檔案建立時間在 login 時間的一年 + 之前,一律是已讀。 + 這樣可以看出為什麼這個方法不是真正完美但是已經足夠。不完美的原因有三個: + 首先, brc_num <= 80 也就是 brc_list 最多存八十個數,這表示除了很久以前的文章 + 外,只會有八十篇是已讀的。第二就是所有一年前的文章都會被判為已讀。最後,如果一 + 個人看的版太多,讓 .boardrc 大小超過 BRC_MAXSIZE 有些版的紀錄就會不見( 24576 + bytes 最少可以存 73 個版的資料,這還是用全部版 brc_num 都是 80 計算的)。但這 + 三個小缺點影響應該不大吧? + +BRC 實作 + + interface: (in proto.h) + + int brc_unread(char *fname, int bnum, int *blist); + 判斷一篇文章是否已讀。 + 傳入值:文章檔名 (fname) 以及 brc_num (bnum) 和 brc_list (blist)。 + 傳回值:如果由 bnum 和 blist 判斷本篇文章未讀傳回 1。 + 否則傳回 0。 + 額外效果:無。 + + int brc_initial(char *boardname); + 初始化在一個版的已讀未讀狀態。 + 傳入值:要初始化的版名。 + 傳回值:若找到之前的紀錄傳回新的 brc_num,否則傳回 0。 + 額外效果:如果傳入的看板就是目前看板會直接傳回 brc_num, 不做別的事。否則 + 本函式會先將目前的 brc data 寫入 .boardrc 中,更改 currboard ,取得 + currbid 和 currbrdattr 後再讀取並更新 brc_num 及 brc_list。如果在使用者 + 的 .boardrc 中沒有關於這個版的紀錄,會設定 brc_num = 1,brc_list[0] = 1 + 並傳回 0。 + + void brc_update(); + 將目前的 brc data 寫入 .boardrc 中。 + 額外效果:如果 brc data 未被更改或使用者權限不足則不會有動作。 + + void brc_addlist(char *fname); + 將文章標示為未讀。 + 傳入值:要標示為未讀的文章檔名。 + + global variables: (in var.c) + + int brc_num; + brc_list 中的有效數字個數。 + + int brc_list[BRC_MAXNUM]; + 已讀文章的存檔時間。 + + (in var.h) + extern int brc_num; + extern int brc_list[BRC_MAXNUM]; + + constant definition: (in board.c) + + #define BRC_STRLEN 15 /* Length of board name */ + 板名最大長度。 + + #define BRC_MAXSIZE 24576 + .boardrc 的有效大小。 + + #define BRC_ITEMSIZE (BRC_STRLEN + 1 + BRC_MAXNUM * sizeof( int )) + 每個 record 的最大大小。 + + #define BRC_MAXNUM 80 + brc_num 的最大值。 + + private variables: (in board.c) + + static time_t brc_expire_time; + brc_list 中值的下限,時間在此之前的一律當作已讀。會在 init_brdbuf 中被設 + 定為 login_start_time - 365 * 86400。 + + static int brc_changed = 0; + 從上次讀取 .boardrc 到當時為止,brc_num 與 brc_list 是否改變過(為減少寫 + 檔的次數)。 + + static char brc_buf[BRC_MAXSIZE]; + 呼叫 read_brc_buf 後 .boardrc 的前 BRC_MAXSIZE bytes 會被置入這個 buffer + 中。 + + static int brc_size; + 呼叫 read_brc_buf 後 brc_buf 中的有效字元數。 + + static char brc_name[BRC_STRLEN]; + 目前 brc data 的版名。 (不知道可否用 currboard 代替? by scw) + + static char * fn_boardrc = ".boardrc"; + brc 設定檔名。 + + char * brc_buf_addr=brc_buf; + unused variable + + private funcions: (in board.c) + + static void read_brc_buf(); + 從 .boardrc 中讀取最多 BRC_MAXSIZE bytes 並存入 brc_buf 中,將存入的字元 + 數存在 brc_size 中。 + + static char * brc_getrecord(char *ptr, char *name, int *pnum, int *list); + 從 buffer 中讀取一項紀錄。 (通常在 read_brc_bufi() 之後使用) + 傳入值:ptr 為要讀取的 buffer, name, pnum, 和 list 分別寫入讀到的資料。 + 傳回值:指向讀出的 record 下一個字元的指標。 + 額外效果:name 會被存入最多 BRC_MAXLEN 個字元,為讀到的 record 的版名。 + pnum 會被存入讀到的 brc_num,list 會被寫入 *pnum 的整數,為 brc_list + 的資料。 + + static char * brc_putrecord(char *ptr, char *name, int num, int *list); + 與 brc_getrecord() 的作用正好相反,將資料寫入 puffer 中。 + 傳入值:ptr 只向要寫入的 buffer,name, num, list 分別是要寫入的資料。 + 傳回值:指向寫入的 record 下一個字元的指標。 + 額外效果:若資料是合法的 (num > 0 && list[0] > brc_expire_time) ptr 會被 + 寫入 BRC_ITEMSIZE bytes 的資料。在 list 中比 brc_expire_time 的數字不會 + 被寫入(所以寫入的 brc_num 可能比 num 小)。 + + static int brc_unread_time(time_t ftime, int bnum, int *blist); + 跟 brc_unread() 類似,只是傳入的是檔案建立的時間。 + 傳入值:文章的建立時間 (ftime) 及 brc_num (bnum) 和 brc_list (blist)。 + 傳回值:如果由 bnum 和 blist 判斷本篇文章未讀傳回 1。 + 否則傳回 0。 -- cgit v1.2.3 From 03ea0eafbeb20f1418ed033f3107ecac63b53f1e Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Wed, 6 Aug 2003 06:15:51 +0000 Subject: * Fix the bug that sometime after reading old articles, the newer one will be set unread. * Remove global variablt brc_name from bourd.c. * Change prototypes of brc_unread, brc_initial, and brc_addlist. Add const modifier. * Add commants in brc_* funtions. by scw git-svn-id: http://opensvn.csie.org/pttbbs/trunk@1085 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/include/proto.h | 8 ++--- pttbbs/mbbsd/board.c | 90 +++++++++++++++++++++++++++++++------------------- 2 files changed, 60 insertions(+), 38 deletions(-) diff --git a/pttbbs/include/proto.h b/pttbbs/include/proto.h index ee59329d..5e902289 100644 --- a/pttbbs/include/proto.h +++ b/pttbbs/include/proto.h @@ -1,4 +1,4 @@ -/* $Id: proto.h,v 1.46 2003/07/20 00:55:34 in2 Exp $ */ +/* $Id$ */ #ifndef INCLUDE_PROTO_H #define INCLUDE_PROTO_H @@ -63,8 +63,8 @@ int board_digest(); /* board */ #define setutmpbid(bid) currutmp->brc_id=bid; -int brc_unread(char *fname, int bnum, int *blist); -int brc_initial(char *boardname); +int brc_unread(const char *fname, int bnum, const int *blist); +int brc_initial(const char *boardname); void brc_update(); int Ben_Perm(boardheader_t *bptr); int New(); @@ -92,7 +92,7 @@ boardheader_t *getbcache(int bid); int apply_boards(int (*func)(boardheader_t *)); int haspostperm(char *bname); void inbtotal(int bid, int add); -void brc_addlist(char *fname); +void brc_addlist(const char *fname); void setbtotal(int bid); unsigned int safe_sleep(unsigned int seconds); int apply_ulist(int (*fptr)(userinfo_t *)); diff --git a/pttbbs/mbbsd/board.c b/pttbbs/mbbsd/board.c index 7351d1e9..5307fa04 100644 --- a/pttbbs/mbbsd/board.c +++ b/pttbbs/mbbsd/board.c @@ -1,9 +1,15 @@ -/* $Id: board.c,v 1.133 2003/07/20 00:55:34 in2 Exp $ */ +/* $Id$ */ #include "bbs.h" #define BRC_STRLEN 15 /* Length of board name */ -#define BRC_MAXSIZE 24576 +#define BRC_MAXSIZE 24576 /* Effective size of brc rc file */ #define BRC_ITEMSIZE (BRC_STRLEN + 1 + BRC_MAXNUM * sizeof( int )) -#define BRC_MAXNUM 80 + /* Maximum size of each record */ +#define BRC_MAXNUM 80 /* Upper bound of brc_num, size of brc_list */ + +/* brc rc file form: + * board_name 15 bytes + * brc_num 1 byte, binary integer + * brc_list brc_num * sizeof(int) bytes, brc_num binary integer(s) */ static char * brc_getrecord(char *ptr, char *name, int *pnum, int *list) @@ -11,44 +17,49 @@ brc_getrecord(char *ptr, char *name, int *pnum, int *list) int num; char *tmp; - strncpy(name, ptr, BRC_STRLEN); + strncpy(name, ptr, BRC_STRLEN); /* board_name */ ptr += BRC_STRLEN; - num = (*ptr++) & 0xff; - tmp = ptr + num * sizeof(int); - if (num > BRC_MAXNUM) + num = (*ptr++) & 0xff; /* brc_num */ + tmp = ptr + num * sizeof(int); /* end of this record */ + if (num > BRC_MAXNUM) /* FIXME if this happens... may crash next time. */ num = BRC_MAXNUM; *pnum = num; - memcpy(list, ptr, num * sizeof(int)); + memcpy(list, ptr, num * sizeof(int)); /* brc_list */ return tmp; } static time_t brc_expire_time; + /* Will be set to the time one year before login. All the files created + * before then will be recognized read. */ static char * -brc_putrecord(char *ptr, char *name, int num, int *list) +brc_putrecord(char *ptr, const char *name, int num, const int *list) { if (num > 0 && list[0] > brc_expire_time) { if (num > BRC_MAXNUM) num = BRC_MAXNUM; while (num > 1 && list[num - 1] < brc_expire_time) - num--; + num--; /* not to write the times before brc_expire_time */ - strncpy(ptr, name, BRC_STRLEN); + strncpy(ptr, name, BRC_STRLEN); /* write in board_name */ ptr += BRC_STRLEN; - *ptr++ = num; - memcpy(ptr, list, num * sizeof(int)); + *ptr++ = num; /* write in brc_num */ + memcpy(ptr, list, num * sizeof(int)); /* write in brc_list */ ptr += num * sizeof(int); } return ptr; } static int brc_changed = 0; +/* The below two will be filled by read_brc_buf() and brc_update() */ static char brc_buf[BRC_MAXSIZE]; -static char brc_name[BRC_STRLEN]; -static char *fn_boardrc = ".boardrc"; static int brc_size; +//static char brc_name[BRC_STRLEN]; /* board name of the brc data */ +static char * const fn_boardrc = ".boardrc"; +/* unused variable char *brc_buf_addr=brc_buf; +*/ void brc_update() @@ -62,7 +73,7 @@ brc_update() ptr = brc_buf; if (brc_num > 0) - ptr = brc_putrecord(ptr, brc_name, brc_num, brc_list); + ptr = brc_putrecord(ptr, currboard, brc_num, brc_list); setuserfile(dirfile, fn_boardrc); if ((fd = open(dirfile, O_RDONLY)) != -1) { @@ -74,8 +85,10 @@ brc_update() tmp = tmp_buf; while (tmp < &tmp_buf[tmp_size] && (*tmp >= ' ' && *tmp <= 'z')) { + /* for each available records */ tmp = brc_getrecord(tmp, tmp_name, &tmp_num, tmp_list); if (strncmp(tmp_name, currboard, BRC_STRLEN)) + /* not overwrite the currend record */ ptr = brc_putrecord(ptr, tmp_name, tmp_num, tmp_list); } brc_size = (int)(ptr - brc_buf); @@ -107,13 +120,14 @@ read_brc_buf() } int -brc_initial(char *boardname) +brc_initial(const char *boardname) { char *ptr; + char tmp_name[BRC_STRLEN]; if (strcmp(currboard, boardname) == 0) { return brc_num; } - brc_update(); + brc_update(); /* write back first */ strlcpy(currboard, boardname, sizeof(currboard)); currbid = getbnum(currboard); currbrdattr = bcache[currbid - 1].brdattr; @@ -121,17 +135,20 @@ brc_initial(char *boardname) ptr = brc_buf; while (ptr < &brc_buf[brc_size] && (*ptr >= ' ' && *ptr <= 'z')) { - ptr = brc_getrecord(ptr, brc_name, &brc_num, brc_list); - if (strncmp(brc_name, currboard, BRC_STRLEN) == 0) + /* for each available records */ + ptr = brc_getrecord(ptr, tmp_name, &brc_num, brc_list); + if (strncmp(tmp_name, currboard, BRC_STRLEN) == 0) return brc_num; } - strncpy(brc_name, boardname, BRC_STRLEN); + strncpy(tmp_name, boardname, BRC_STRLEN); brc_num = brc_list[0] = 1; + /* We don't have to set brc_changed to 0 here, since brc_update() already + * did that. */ return 0; } void -brc_addlist(char *fname) +brc_addlist(const char *fname) { int ftime, n, i; @@ -139,46 +156,51 @@ brc_addlist(char *fname) return; ftime = atoi(&fname[2]); - if (ftime <= brc_expire_time + if (ftime <= brc_expire_time /* too old, don't do any thing */ /* || fname[0] != 'M' || fname[1] != '.' */ ) { return; } - if (brc_num <= 0) { - brc_list[brc_num++] = ftime; + if (brc_num <= 0) { /* uninitialized */ + brc_list[0] = ftime; + brc_num = 1; brc_changed = 1; return; } - if ((brc_num == 1) && (ftime < brc_list[0])) + if ((brc_num == 1) && (ftime < brc_list[0])) /* most when after 'v' */ return; - for (n = 0; n < brc_num; n++) { + for (n = 0; n < brc_num; n++) { /* using linear search */ if (ftime == brc_list[n]) { return; } else if (ftime > brc_list[n]) { if (brc_num < BRC_MAXNUM) brc_num++; + /* insert ftime in to brc_list */ for (i = brc_num - 1; --i >= n; brc_list[i + 1] = brc_list[i]); brc_list[n] = ftime; brc_changed = 1; return; } } + /* (by scw) These lines are no used. Since if it reachs here, this file + * is already been labeled read. if (brc_num < BRC_MAXNUM) { brc_list[brc_num++] = ftime; brc_changed = 1; } + */ } static int -brc_unread_time(time_t ftime, int bnum, int *blist) +brc_unread_time(time_t ftime, int bnum, const int *blist) { int n; - if (ftime <= brc_expire_time) + if (ftime <= brc_expire_time) /* too old */ return 0; if (brc_num <= 0) return 1; - for (n = 0; n < bnum; n++) { + for (n = 0; n < bnum; n++) { /* using linear search */ if (ftime > blist[n]) return 1; else if (ftime == blist[n]) @@ -188,18 +210,18 @@ brc_unread_time(time_t ftime, int bnum, int *blist) } int -brc_unread(char *fname, int bnum, int *blist) +brc_unread(const char *fname, int bnum, const int *blist) { int ftime, n; - ftime = atoi(&fname[2]); + ftime = atoi(&fname[2]); /* this will get the time of the file created */ - if (ftime <= brc_expire_time) + if (ftime <= brc_expire_time) /* too old */ return 0; if (brc_num <= 0) return 1; - for (n = 0; n < bnum; n++) { + for (n = 0; n < bnum; n++) { /* using linear search */ if (ftime > blist[n]) return 1; else if (ftime == blist[n]) -- cgit v1.2.3 From 54ae07cc4acd6662e29a841073de94eab5acc0a9 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Wed, 6 Aug 2003 15:23:08 +0000 Subject: new match patter for rev 1081 git-svn-id: http://opensvn.csie.org/pttbbs/trunk@1086 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/waterball.pl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pttbbs/util/waterball.pl b/pttbbs/util/waterball.pl index 05d59999..651372fa 100644 --- a/pttbbs/util/waterball.pl +++ b/pttbbs/util/waterball.pl @@ -119,7 +119,7 @@ sub parse else{ $cmode = 1; ($who, $say, $month, $day, $year, $hour, $min, $sec) = - $dat =~ m|★(\w+?)\[37;45m\s*(.*)\[m \[0m\[(\w+)/(\w+)/(\w+) (\w+):(\w+):(\w+)\]|; + $dat =~ m|★(\w+?)\[37;45m\s*(.*).*?\[(\w+)/(\w+)/(\w+) (\w+):(\w+):(\w+)\]|; } # $time = timelocal($sec,$min,$hours,$mday,$mon,$year); -- cgit v1.2.3 From 4e50c74e1d787e2e75a079ab927fb26dcf46f131 Mon Sep 17 00:00:00 2001 From: victor <victor@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Fri, 8 Aug 2003 05:26:45 +0000 Subject: wrong output of the result thanks scwg.bbs@ptt2.cc git-svn-id: http://opensvn.csie.org/pttbbs/trunk@1087 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/gamble.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pttbbs/mbbsd/gamble.c b/pttbbs/mbbsd/gamble.c index 4d64e416..eb42d085 100644 --- a/pttbbs/mbbsd/gamble.c +++ b/pttbbs/mbbsd/gamble.c @@ -1,4 +1,4 @@ -/* $Id: gamble.c,v 1.35 2003/06/28 08:45:02 kcwu Exp $ */ +/* $Id$ */ #include "bbs.h" #ifndef _BBS_UTIL_C_ @@ -292,12 +292,12 @@ openticket(int bid) while (fscanf(fp1, "%s %d %d\n", userid, &mybet, &i) != EOF) { if (bet == 98 && mybet >= 0 && mybet < count) { fprintf(fp, "%s 買了 %d 張 %s, 退回 %d 枚P幣\n" - ,userid, i, betname[mybet], money); + ,userid, i, betname[mybet], money * i); snprintf(buf, sizeof(buf), "%s 賭場退錢! $ %d", bh->brdname, money * i); } else if (mybet == bet) { fprintf(fp, "恭喜 %s 買了%d 張 %s, 獲得 %d 枚P幣\n" - ,userid, i, betname[mybet], money); + ,userid, i, betname[mybet], money * i); snprintf(buf, sizeof(buf), "%s 中獎咧! $ %d", bh->brdname, money * i); } else continue; -- cgit v1.2.3 From 43a689285a0f9a5ae322d83d4a829f622ff5bb00 Mon Sep 17 00:00:00 2001 From: victor <victor@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sat, 9 Aug 2003 03:43:26 +0000 Subject: ignore hidden boards git-svn-id: http://opensvn.csie.org/pttbbs/trunk@1088 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/poststat.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pttbbs/util/poststat.c b/pttbbs/util/poststat.c index 37bcc399..e46f77a2 100644 --- a/pttbbs/util/poststat.c +++ b/pttbbs/util/poststat.c @@ -1,4 +1,4 @@ -/* $Id: poststat.c,v 1.5 2003/07/20 00:55:34 in2 Exp $ */ +/* $Id$ */ /* 統計今日、週、月、年熱門話題 */ #include "bbs.h" @@ -188,7 +188,7 @@ filter(board) bid = getbnum(board); if (get_record(".BRD", &bh, sizeof(bh), bid) == -1) return 1; - if (bh.brdattr & BRD_NOCOUNT) + if (bh.brdattr & BRD_NOCOUNT || bh.brdattr & BRD_HIDE) return 1; /* if (bh.brdattr & BRD_POSTMASK) -- cgit v1.2.3 From c58fcc3e25c56e935e27355d49cf564edea0046b Mon Sep 17 00:00:00 2001 From: "(no author)" <(no author)@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sat, 9 Aug 2003 14:08:52 +0000 Subject: fix typo git-svn-id: http://opensvn.csie.org/pttbbs/trunk@1089 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/docs/brc.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pttbbs/docs/brc.txt b/pttbbs/docs/brc.txt index d25692bf..ebdf3c29 100644 --- a/pttbbs/docs/brc.txt +++ b/pttbbs/docs/brc.txt @@ -14,7 +14,7 @@ BRC 是什麼?如何運作? brc_* 是定義在 pttbbs/mbbsd/board.c 中的一組函式,負責紀錄文章已讀/未讀, - 它的特點是育的空間極少。可以在 2.4k 以內的空間記下一個人在全站的文章已讀/ + 它的特點是用的空間極少。可以在 2.4k 以內的空間記下一個人在全站的文章已讀/ 未讀。當然,這樣的方法不可能真正完美,但是對於使用上已經足夠了。為什麼說是不 完美呢?這跟紀錄的儲存方式有關。 紀錄檔在 home/[first charactor of id]/[id]/.boardrc。檔案格式如下: @@ -33,7 +33,7 @@ BRC 兩項, BRC_NUM 跟 BRC_LIST 都會放在相應的全域變數中, brc_num & brc_list 。 判定一個檔案是否已經讀過的方法是在 brc_list 中搜尋檔案建立的時間,也就是 檔名 M.xxxxxxxxxx.A.yyy 中 xxxxxxxxx 的那個數字。如果這個數字有在 brc_list 中 - 出現就是已讀,要不如果 brc_list 中所以的數字都比這個檔案的建立時間大(也就是 + 出現就是已讀,要不如果 brc_list 中所有的數字都比這個檔案的建立時間大(也就是 這個檔案的建立時間在所有 brc_list 中的時間點之前)也是已讀,最後為了節省空間 還有一個判定(其實這個判定是第一個做的),如果檔案建立時間在 login 時間的一年 之前,一律是已讀。 -- cgit v1.2.3 From 94d34256f6d045b9905ca8f1b1e7637fae382c5f Mon Sep 17 00:00:00 2001 From: "(no author)" <(no author)@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sat, 9 Aug 2003 14:12:42 +0000 Subject: * Fix the bug that sometime after reading old articles, the newer one will be set unread. * Remove global variablt brc_name from bourd.c. * Change prototypes of brc_unread, brc_initial, and brc_addlist. Add const modifier. * Add commants in brc_* funtions. by scw git-svn-id: http://opensvn.csie.org/pttbbs/trunk@1090 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/docs/brc.txt | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/pttbbs/docs/brc.txt b/pttbbs/docs/brc.txt index ebdf3c29..366b5ed0 100644 --- a/pttbbs/docs/brc.txt +++ b/pttbbs/docs/brc.txt @@ -24,9 +24,9 @@ BRC RECORD := BOARD_NAME BRC_DATA ; BRC_DATA := BRC_NUM BRC_LIST ; BRC_LIST := NUM NUM ... NUM ; (共 BRC_NUM 個 NUM) - BOARD_NAME 是 15 bytes 的版名 (#define BRC_STRLEN 15) - BRC_NUM 是對這個版的儲存量,1 byte 以 binary 方式儲存,其值 <= MAX_NUM (80) - BRC_LIST 是對這個版的紀錄,剛好有 BRC_NUM 個 4 bytes integers。 + BOARD_NAME 是 15 bytes 的板名 (#define BRC_STRLEN 15) + BRC_NUM 是對這個板的儲存量,1 byte 以 binary 方式儲存,其值 <= MAX_NUM (80) + BRC_LIST 是對這個板的紀錄,剛好有 BRC_NUM 個 4 bytes integers。 另外在 24576 bytes (#define BRC_MAXSIZE 24576) 之外的資料不會被用到。 在下面會看到,BOARD_NAME 不用另外儲存(已經放在user的全域資料裡了),其他 @@ -40,8 +40,8 @@ BRC 這樣可以看出為什麼這個方法不是真正完美但是已經足夠。不完美的原因有三個: 首先, brc_num <= 80 也就是 brc_list 最多存八十個數,這表示除了很久以前的文章 外,只會有八十篇是已讀的。第二就是所有一年前的文章都會被判為已讀。最後,如果一 - 個人看的版太多,讓 .boardrc 大小超過 BRC_MAXSIZE 有些版的紀錄就會不見( 24576 - bytes 最少可以存 73 個版的資料,這還是用全部版 brc_num 都是 80 計算的)。但這 + 個人看的板太多,讓 .boardrc 大小超過 BRC_MAXSIZE 有些板的紀錄就會不見( 24576 + bytes 最少可以存 73 個板的資料,這還是用全部板 brc_num 都是 80 計算的)。但這 三個小缺點影響應該不大吧? BRC 實作 @@ -56,13 +56,13 @@ BRC 額外效果:無。 int brc_initial(char *boardname); - 初始化在一個版的已讀未讀狀態。 - 傳入值:要初始化的版名。 + 初始化在一個板的已讀未讀狀態。 + 傳入值:要初始化的板名。 傳回值:若找到之前的紀錄傳回新的 brc_num,否則傳回 0。 額外效果:如果傳入的看板就是目前看板會直接傳回 brc_num, 不做別的事。否則 本函式會先將目前的 brc data 寫入 .boardrc 中,更改 currboard ,取得 currbid 和 currbrdattr 後再讀取並更新 brc_num 及 brc_list。如果在使用者 - 的 .boardrc 中沒有關於這個版的紀錄,會設定 brc_num = 1,brc_list[0] = 1 + 的 .boardrc 中沒有關於這個板的紀錄,會設定 brc_num = 1,brc_list[0] = 1 並傳回 0。 void brc_update(); @@ -117,7 +117,7 @@ BRC 呼叫 read_brc_buf 後 brc_buf 中的有效字元數。 static char brc_name[BRC_STRLEN]; - 目前 brc data 的版名。 (不知道可否用 currboard 代替? by scw) + 目前 brc data 的板名。 (不知道可否用 currboard 代替? by scw) static char * fn_boardrc = ".boardrc"; brc 設定檔名。 @@ -135,7 +135,7 @@ BRC 從 buffer 中讀取一項紀錄。 (通常在 read_brc_bufi() 之後使用) 傳入值:ptr 為要讀取的 buffer, name, pnum, 和 list 分別寫入讀到的資料。 傳回值:指向讀出的 record 下一個字元的指標。 - 額外效果:name 會被存入最多 BRC_MAXLEN 個字元,為讀到的 record 的版名。 + 額外效果:name 會被存入最多 BRC_MAXLEN 個字元,為讀到的 record 的板名。 pnum 會被存入讀到的 brc_num,list 會被寫入 *pnum 的整數,為 brc_list 的資料。 -- cgit v1.2.3 From bdff4dbef19105560a6e0357d8c2d4bf2e1c603c Mon Sep 17 00:00:00 2001 From: kcwu <kcwu@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sun, 10 Aug 2003 12:23:11 +0000 Subject: replace FreeBSD macro with __FreeBSD__ replace Linux macro with __linux__ replace make with $(MAKE) OSTYPE in cmdline doesn't need anymore git-svn-id: http://opensvn.csie.org/pttbbs/trunk@1091 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/Makefile | 2 +- pttbbs/docs/INSTALL | 4 +--- pttbbs/include/bbs.h | 6 +++--- pttbbs/innbbsd/Makefile | 1 + pttbbs/mbbsd/chat.c | 4 ++-- pttbbs/mbbsd/osdep.c | 4 ++-- pttbbs/mbbsd/term.c | 6 +++--- pttbbs/pttbbs.mk | 14 +++++--------- pttbbs/sample/Makefile | 2 +- pttbbs/sample/etc/Makefile | 2 +- pttbbs/util/bbsctl.c | 6 +++--- 11 files changed, 23 insertions(+), 28 deletions(-) diff --git a/pttbbs/Makefile b/pttbbs/Makefile index f294ae0d..e94a522e 100644 --- a/pttbbs/Makefile +++ b/pttbbs/Makefile @@ -5,6 +5,6 @@ OSTYPE!=uname all install clean: @for i in $(SUBDIR); do\ cd $$i;\ - make BBSHOME=$(BBSHOME) OSTYPE=$(OSTYPE) $@;\ + $(MAKE) BBSHOME=$(BBSHOME) $@;\ cd ..;\ done diff --git a/pttbbs/docs/INSTALL b/pttbbs/docs/INSTALL index b1297830..4311cc70 100644 --- a/pttbbs/docs/INSTALL +++ b/pttbbs/docs/INSTALL @@ -42,9 +42,7 @@ 9. 如果之前沒有設定過 pttbbs.conf 的話, 請 cp sample/pttbbs.conf pttbbs.conf 10.修改 pttbbs.conf * 如果您是用 Linux系統, 請先安裝 pmake, 然後將 make alias 成 pmake * - 11.執行 make OSTYPE=FreeBSD BBSHOME=/home/bbs all install - (若是使用 FreeBSD 5.x的話, 請如上 FreeBSD5=1 ) - ( Linux使用者請把 "FreeBSD" 改成 "linux") + 11.執行 make BBSHOME=/home/bbs all install (如果出現 iconv.h找不到的話, 請見 FAQ 7 ) 12.如果是新架起來的站, 請執行 cd sample; make install 13.執行 cd /home/bbs; bin/initbbs diff --git a/pttbbs/include/bbs.h b/pttbbs/include/bbs.h index e119265d..71a3332f 100644 --- a/pttbbs/include/bbs.h +++ b/pttbbs/include/bbs.h @@ -35,15 +35,15 @@ #include <sys/msg.h> /* os dependant include file, define */ -#ifdef FreeBSD - #ifdef FreeBSD5 +#ifdef __FreeBSD__ + #if __FreeBSD__ >=5 #include <sys/limits.h> #else #include <machine/limits.h> #endif #include <machine/param.h> #endif -#ifdef Linux +#ifdef __linux__ #include <sys/param.h> #include <limits.h> #include <sys/file.h> // for flock() diff --git a/pttbbs/innbbsd/Makefile b/pttbbs/innbbsd/Makefile index 5fa6c566..1422ec65 100644 --- a/pttbbs/innbbsd/Makefile +++ b/pttbbs/innbbsd/Makefile @@ -7,6 +7,7 @@ # ------------------------------------------------------- # # stdarg.h patch for pttbbs by in2 03/05/05 # +OSTYPE!=uname #################################################### # this is a bbs <--> news gateway ##################################################### diff --git a/pttbbs/mbbsd/chat.c b/pttbbs/mbbsd/chat.c index 6346335a..55d3129d 100644 --- a/pttbbs/mbbsd/chat.c +++ b/pttbbs/mbbsd/chat.c @@ -1,4 +1,4 @@ -/* $Id: chat.c,v 1.11 2003/02/23 16:39:27 victor Exp $ */ +/* $Id$ */ #include "bbs.h" static int chatline, stop_line; @@ -355,7 +355,7 @@ t_chat() return -1; } memset(&sin, 0, sizeof sin); -#ifdef FreeBSD +#ifdef __FreeBSD__ sin.sin_len = sizeof(sin); #endif sin.sin_family = PF_INET; diff --git a/pttbbs/mbbsd/osdep.c b/pttbbs/mbbsd/osdep.c index 0c32db7a..4e6d286e 100644 --- a/pttbbs/mbbsd/osdep.c +++ b/pttbbs/mbbsd/osdep.c @@ -1,7 +1,7 @@ -/* $Id: osdep.c,v 1.7 2003/01/23 18:19:55 in2 Exp $ */ +/* $Id$ */ #include "bbs.h" -#ifdef Linux +#ifdef __linux__ #include <sys/types.h> #include <string.h> diff --git a/pttbbs/mbbsd/term.c b/pttbbs/mbbsd/term.c index a0f83354..54acc2a6 100644 --- a/pttbbs/mbbsd/term.c +++ b/pttbbs/mbbsd/term.c @@ -1,4 +1,4 @@ -/* $Id: term.c,v 1.11 2002/11/08 21:12:58 in2 Exp $ */ +/* $Id$ */ #include "bbs.h" int tgetent(const char *bp, char *name); @@ -52,7 +52,7 @@ outcf(int ch) } #endif -#ifndef Linux +#ifndef __linux__ static void term_resize(int sig) { @@ -90,7 +90,7 @@ term_resize(int sig) int term_init() { -#ifndef Linux +#ifndef __linux__ signal(SIGWINCH, term_resize); #endif return YEA; diff --git a/pttbbs/pttbbs.mk b/pttbbs/pttbbs.mk index 265aaa46..90e9c36f 100644 --- a/pttbbs/pttbbs.mk +++ b/pttbbs/pttbbs.mk @@ -2,7 +2,7 @@ # 定義基本初值 BBSHOME?= $(HOME) BBSHOME?= /home/bbs -OSTYPE?= FreeBSD +OSTYPE!= uname CC?= gcc CCACHE!= which ccache|sed -e 's/^.*\///' PTT_CFLAGS= -Wall -pipe -DBBSHOME='"$(BBSHOME)"' -I../include @@ -13,15 +13,15 @@ PTT_LIBS= -lcrypt #PTT_CFLAGS+= -DNDEBUG # FreeBSD特有的環境 -CFLAGS_FreeBSD= -DHAVE_SETPROCTITLE -DFreeBSD +CFLAGS_FreeBSD= -DHAVE_SETPROCTITLE LDFLAGS_FreeBSD= LIBS_FreeBSD= -lkvm # Linux特有的環境 # CFLAGS_linux= -DHAVE_DES_CRYPT -DLinux -CFLAGS_linux= -DLinux -LDFLAGS_linux= -pipe -Wall -LIBS_linux= +CFLAGS_Linux= +LDFLAGS_Linux= -pipe -Wall +LIBS_Linux= # CFLAGS, LDFLAGS, LIBS 加入 OS 相關參數 PTT_CFLAGS+= $(CFLAGS_$(OSTYPE)) @@ -48,7 +48,3 @@ CFLAGS+= -DDEBUG .if defined(NO_FORK) CFLAGS+= -DNO_FORK .endif - -.if defined(FreeBSD5) -CFLAGS+= -DFreeBSD5 -.endif diff --git a/pttbbs/sample/Makefile b/pttbbs/sample/Makefile index 7ba47da6..832eba59 100644 --- a/pttbbs/sample/Makefile +++ b/pttbbs/sample/Makefile @@ -6,6 +6,6 @@ all: install: @for i in $(SUBDIR); do\ cd $$i;\ - make BBSHOME=$(BBSHOME) OSTYPE=$(OSTYPE) $@;\ + $(MAKE) BBSHOME=$(BBSHOME) $@;\ cd ..;\ done diff --git a/pttbbs/sample/etc/Makefile b/pttbbs/sample/etc/Makefile index 154d39d9..6a2755ef 100644 --- a/pttbbs/sample/etc/Makefile +++ b/pttbbs/sample/etc/Makefile @@ -13,7 +13,7 @@ all: install_sub: @for i in $(SUBDIR); do\ cd $$i;\ - make BBSHOME=$(BBSHOME) OSTYPE=$(OSTYPE) install;\ + $(MAKE) BBSHOME=$(BBSHOME) install;\ cd ..;\ done diff --git a/pttbbs/util/bbsctl.c b/pttbbs/util/bbsctl.c index 936547a3..53aaede3 100644 --- a/pttbbs/util/bbsctl.c +++ b/pttbbs/util/bbsctl.c @@ -12,7 +12,7 @@ #include "pttstruct.h" #include "perm.h" -#ifdef FreeBSD +#ifdef __FreeBSD__ #include <sys/syslimits.h> #define SU "/usr/bin/su" #define CP "/bin/cp" @@ -21,7 +21,7 @@ #define IPCRM "/usr/bin/ipcrm" #define AWK "/usr/bin/awk" #endif -#ifdef Linux +#ifdef __linux__ #include <linux/limits.h> #define SU "/bin/su" #define CP "/bin/cp" @@ -187,7 +187,7 @@ int bbstest(int argc, char **argv) int Xipcrm(int argc, char **argv) { -#ifdef FreeBSD +#ifdef __FreeBSD__ char buf[256], cmd[256]; FILE *fp; sprintf(buf, IPCS " | " AWK " '{print $1 $2}'"); -- cgit v1.2.3 From 76ba995e77c3bb6ff2b6e1a64f215c457a8c48f5 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Tue, 12 Aug 2003 07:24:51 +0000 Subject: use NULL instead of (~ 0) in class linked-list git-svn-id: http://opensvn.csie.org/pttbbs/trunk@1092 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/board.c | 6 +++--- pttbbs/util/boardlist.c | 12 +++++------- pttbbs/util/shmctl.c | 5 ++--- pttbbs/util/toplazyBM.c | 2 +- 4 files changed, 11 insertions(+), 14 deletions(-) diff --git a/pttbbs/mbbsd/board.c b/pttbbs/mbbsd/board.c index 5307fa04..eb6a13d4 100644 --- a/pttbbs/mbbsd/board.c +++ b/pttbbs/mbbsd/board.c @@ -704,9 +704,9 @@ load_uidofgid(const int gid, const int type) } bcache[gid - 1].childcount = childcount; if (currbptr == &bcache[gid - 1]) - currbptr->firstchild[type] = (boardheader_t *) ~ 0; + currbptr->firstchild[type] = NULL; else - currbptr->next[type] = (boardheader_t *) ~ 0; + currbptr->next[type] = NULL; } static boardstat_t * @@ -826,7 +826,7 @@ load_boards(char *key) } else { int childcount = bptr->childcount; nbrd = (boardstat_t *) malloc(childcount * sizeof(boardstat_t)); - for (bptr = bptr->firstchild[type]; bptr != (boardheader_t *) ~ 0; + for (bptr = bptr->firstchild[type]; bptr != NULL; bptr = bptr->next[type]) { n = (int)(bptr - bcache); if (!((state = Ben_Perm(bptr)) || (currmode & MODE_MENU)) diff --git a/pttbbs/util/boardlist.c b/pttbbs/util/boardlist.c index 42fd707a..4c338328 100644 --- a/pttbbs/util/boardlist.c +++ b/pttbbs/util/boardlist.c @@ -1,4 +1,4 @@ -/* $Id: boardlist.c,v 1.4 2003/07/21 09:27:16 in2 Exp $ */ +/* $Id$ */ /* 這是用來將樹狀分類輸出成 perl module (可以給像是 man/ 使用) */ #include "bbs.h" @@ -25,9 +25,9 @@ load_uidofgid(const int gid, const int type) } bcache[gid - 1].childcount = childcount; if (currbptr == &bcache[gid - 1]) - currbptr->firstchild[type] = (boardheader_t *) ~ 0; + currbptr->firstchild[type] = NULL; else - currbptr->next[type] = (boardheader_t *) ~ 0; + currbptr->next[type] = NULL; } char *skipEscape(char *s) @@ -52,8 +52,7 @@ void dumpclass(int bid) if (bptr->firstchild[0] == NULL || bptr->childcount <= 0) load_uidofgid(bid + 1, 0); /* 因為這邊 bid從 0開始, 所以再 +1 回來 */ printf(" %5d => [\n", bid); - for (bptr = bptr->firstchild[0]; bptr != (boardheader_t *) ~ 0; - bptr = bptr->next[0]) { + for (bptr = bptr->firstchild[0]; bptr != NULL ; bptr = bptr->next[0]) { if( (bptr->brdattr & (BRD_HIDE | BRD_TOP)) || (bptr->level && !(bptr->brdattr & BRD_POSTMASK) && (bptr->level & @@ -75,8 +74,7 @@ void dumpclass(int bid) printf(" ],\n"); bptr = &bcache[bid]; - for (bptr = bptr->firstchild[0]; bptr != (boardheader_t *) ~ 0; - bptr = bptr->next[0]) { + for (bptr = bptr->firstchild[0]; bptr != NULL ; bptr = bptr->next[0]) { if( (bptr->brdattr & (BRD_HIDE | BRD_TOP)) || (bptr->level && !(bptr->brdattr & BRD_POSTMASK) && (bptr->level & diff --git a/pttbbs/util/shmctl.c b/pttbbs/util/shmctl.c index 382a823b..1eb33bd1 100644 --- a/pttbbs/util/shmctl.c +++ b/pttbbs/util/shmctl.c @@ -1,4 +1,4 @@ -/* $Id: shmctl.c,v 1.45 2003/07/20 00:55:34 in2 Exp $ */ +/* $Id$ */ #include "bbs.h" #include <sys/wait.h> @@ -462,8 +462,7 @@ void buildclass(int bid, int level) if (bptr->firstchild[1] == NULL || bptr->childcount <= 0) load_uidofgid(bid + 1, 1); /* 因為這邊 bid從 0開始, 所以再 +1 回來 */ - for (bptr = bptr->firstchild[0]; bptr != (boardheader_t *) ~ 0; - bptr = bptr->next[0]) { + for (bptr = bptr->firstchild[0]; bptr != NULL ; bptr = bptr->next[0]) { if( bptr->brdattr & BRD_GROUPBOARD ) buildclass(bptr - bcache, level + 1); } diff --git a/pttbbs/util/toplazyBM.c b/pttbbs/util/toplazyBM.c index 5dc9a3df..55267927 100644 --- a/pttbbs/util/toplazyBM.c +++ b/pttbbs/util/toplazyBM.c @@ -1,4 +1,4 @@ -/* $Id: toplazyBM.c,v 1.18 2003/07/20 00:55:34 in2 Exp $ */ +/* $Id$ */ #define _UTIL_C_ #include "bbs.h" #define OUTFILE BBSHOME "/etc/toplazyBM" -- cgit v1.2.3 From c6ff3d039a8e5a7f72208142f5b32228b078dcb0 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Tue, 12 Aug 2003 07:35:07 +0000 Subject: numboards = SHM->Bnumber in attach_SHM() git-svn-id: http://opensvn.csie.org/pttbbs/trunk@1093 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/cache.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pttbbs/mbbsd/cache.c b/pttbbs/mbbsd/cache.c index ad2d7a7d..7b26f8f2 100644 --- a/pttbbs/mbbsd/cache.c +++ b/pttbbs/mbbsd/cache.c @@ -1,4 +1,4 @@ -/* $Id: cache.c,v 1.63 2003/07/20 00:55:34 in2 Exp $ */ +/* $Id$ */ #include "bbs.h" #ifdef _BBS_UTIL_C_ @@ -71,6 +71,7 @@ attach_SHM(void) if (SHM->Btouchtime == 0) SHM->Btouchtime = 1; bcache = SHM->bcache; + numboards = SHM->Bnumber; GLOBALVAR = SHM->GLOBALVAR; if (SHM->Ptouchtime == 0) -- cgit v1.2.3 From 68380f6d9605d24cf2bab5c14dd85d4bfeca3ef8 Mon Sep 17 00:00:00 2001 From: victor <victor@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Thu, 14 Aug 2003 05:13:54 +0000 Subject: warn if a foreigner git-svn-id: http://opensvn.csie.org/pttbbs/trunk@1094 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/user.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/pttbbs/mbbsd/user.c b/pttbbs/mbbsd/user.c index 53ea8d19..c55b1335 100644 --- a/pttbbs/mbbsd/user.c +++ b/pttbbs/mbbsd/user.c @@ -1,4 +1,4 @@ -/* $Id: user.c,v 1.72 2003/07/20 01:20:11 bbs Exp $ */ +/* $Id$ */ #include "bbs.h" static char *sex[8] = { @@ -1269,16 +1269,22 @@ u_register(void) #ifdef FOREIGN_REG } else{ + int i; while( 1 ){ getfield(3, "0123456789", "護照號碼", ident, 11); + move(5, 2); + prints("注意:護照號碼有誤者將無法取得進一步的權限!"); getdata(6, 0, "是否確定(Y/N)", ans, sizeof(ans), LCECHO); if (ans[0] == 'y' || ans[0] == 'Y') break; vmsg("請重新輸入(若有問題麻煩至SYSOP板)"); } + for(i = 0; ans[i] != 0; i++) + if ('a' <= ident[0] && ident[0] <= 'z') + ident[0] -= 32; if( ispersonalid(ident) ){ - vmsg("請以本國籍身份註冊"); - continue; + fore[0] = 0; + vmsg("您的身份已更改為本國籍"); } } #endif -- cgit v1.2.3 From 230bdfd80008a27cdc1f12daf1f97f035f28df37 Mon Sep 17 00:00:00 2001 From: victor <victor@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Fri, 15 Aug 2003 05:05:10 +0000 Subject: clean the source git-svn-id: http://opensvn.csie.org/pttbbs/trunk@1095 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/Makefile | 35 ++++++++++++------------- pttbbs/util/outmail.c | 72 +-------------------------------------------------- 2 files changed, 17 insertions(+), 90 deletions(-) diff --git a/pttbbs/util/Makefile b/pttbbs/util/Makefile index 4929a5a2..d1a80835 100644 --- a/pttbbs/util/Makefile +++ b/pttbbs/util/Makefile @@ -1,9 +1,15 @@ -# $Id: Makefile,v 1.37 2003/07/21 09:27:00 in2 Exp $ +# $Id$ .include "../pttbbs.mk" UTIL_OBJS= \ - util_cache.o util_record.o util_passwd.o util_var.o util_stuff.o + util_cache.o util_record.o util_passwd.o util_var.o util_stuff.o\ + util_osdep.o util_args.o + +# 用來從 ../mbbsd/xxx.c 產生 util_xxx.o +MBBSD_OBJS= \ + var stuff cache osdep \ + args # 下面這些程式, 會被 compile 並且和 $(UTIL_OBJS) 聯結 CPROG_WITH_UTIL= \ @@ -12,14 +18,15 @@ CPROG_WITH_UTIL= \ expire mandex rmuid horoscope \ openvice parse_news openticket topusr \ indexuser yearsold toplazyBM toplazyBBM \ - reaper buildAnnounce inndBM shmctl + reaper buildAnnounce inndBM shmctl \ + outmail bbsmail # 下面這些程式, 會直接被 compile CPROG_WITHOUT_UTIL= \ shmsweep uhash_loader showboard antispam \ countalldice webgrep bbsrf initbbs \ userlist tunepasswd buildir merge_passwd \ - merge_board xchatd outmail bbsmail + merge_board xchatd # 下面這些程式會被 install PROGS= ${UTIL_OBJS} ${CPROG_WITH_UTIL} ${CPROG_WITHOUT_UTIL} \ @@ -36,23 +43,13 @@ ${fn}: ${fn}.c ${UTIL_OBJS} ${CC} ${CFLAGS} -o ${fn} ${UTIL_OBJS} ${fn}.c .endfor -util_var.o: ../mbbsd/var.c - ${CC} ${CFLAGS} -D_BBS_UTIL_C_ -c -o util_var.o ../mbbsd/var.c - -util_stuff.o: ../mbbsd/stuff.c - ${CC} ${CFLAGS} -D_BBS_UTIL_C_ -c -o util_stuff.o ../mbbsd/stuff.c - -util_cache.o: ../mbbsd/cache.c - ${CC} ${CFLAGS} -D_BBS_UTIL_C_ -c -o util_cache.o ../mbbsd/cache.c - -bbsmail: bbsmail.c ${UTIL_OBJS} ../mbbsd/osdep.o - ${CC} ${CFLAGS} -o bbsmail bbsmail.c ${UTIL_OBJS} ../mbbsd/osdep.o ${LDFLAGS} +.for fn in ${MBBSD_OBJS} +util_${fn}.o: ../mbbsd/${fn}.c + ${CC} ${CFLAGS} -D_BBS_UTIL_C_ -c -o $@ ../mbbsd/${fn}.c +.endfor xchatd: xchatd.c $(UTIL_OBJS) descrypt.c - $(CC) $(CFLAGS) -o $@ $@.c $(UTIL_OBJS) descrypt.c $(LIBCHAT) - -outmail: outmail.c - $(CC) $(CFLAGS) -o $@ $@.c $(LIBMAIL) + $(CC) $(CFLAGS) -o $@ $@.c $(UTIL_OBJS) descrypt.c install: $(PROGS) install -d $(BBSHOME)/bin/ diff --git a/pttbbs/util/outmail.c b/pttbbs/util/outmail.c index d8efb526..f818d2c6 100644 --- a/pttbbs/util/outmail.c +++ b/pttbbs/util/outmail.c @@ -1,4 +1,4 @@ -/* $Id: outmail.c,v 1.5 2003/04/19 18:36:10 in2 Exp $ */ +/* $Id$ */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -16,76 +16,6 @@ #include "pttstruct.h" -#ifdef HAVE_SETPROCTITLE - -#include <sys/types.h> -#include <libutil.h> - -void initsetproctitle(int argc, char **argv, char **envp) { -} - -#else - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <stdarg.h> - -char **Argv = NULL; /* pointer to argument vector */ -char *LastArgv = NULL; /* end of argv */ -extern char **environ; - -void initsetproctitle(int argc, char **argv, char **envp) { - register int i; - - /* Move the environment so setproctitle can use the space at - the top of memory. */ - for(i = 0; envp[i]; i++); - environ = malloc(sizeof(char *) * (i + 1)); - for(i = 0; envp[i]; i++) - environ[i] = strdup(envp[i]); - environ[i] = NULL; - - /* Save start and extent of argv for setproctitle. */ - Argv = argv; - if(i > 0) - LastArgv = envp[i - 1] + strlen(envp[i - 1]); - else - LastArgv = argv[argc - 1] + strlen(argv[argc - 1]); -} - -static void do_setproctitle(const char *cmdline) { - char buf[256], *p; - int i; - - strncpy(buf, cmdline, 256); - buf[255] = '\0'; - i = strlen(buf); - if(i > LastArgv - Argv[0] - 2) { - i = LastArgv - Argv[0] - 2; - } - strcpy(Argv[0], buf); - p = &Argv[0][i]; - while(p < LastArgv) - *p++='\0'; - Argv[1] = NULL; -} - -void setproctitle(const char* format, ...) { - char buf[256]; - - va_list args; - va_start(args, format); - vsprintf(buf, format,args); - do_setproctitle(buf); - va_end(args); -} -#endif - - - - - #define SPOOL BBSHOME "/out" #define INDEX SPOOL "/.DIR" #define NEWINDEX SPOOL "/.DIR.sending" -- cgit v1.2.3 From 48d91e48b677250ed62fc8ee10b8629eeba89948 Mon Sep 17 00:00:00 2001 From: victor <victor@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Fri, 15 Aug 2003 06:13:29 +0000 Subject: merge util_record.c to mbbsd/record.c git-svn-id: http://opensvn.csie.org/pttbbs/trunk@1096 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/BM_money.c | 4 +- pttbbs/util/Makefile | 6 +- pttbbs/util/account.c | 2 +- pttbbs/util/antispam.c | 2 +- pttbbs/util/bbsmail.c | 4 +- pttbbs/util/bbsrf.c | 2 +- pttbbs/util/birth.c | 2 +- pttbbs/util/buildir.c | 2 +- pttbbs/util/countalldice.c | 2 +- pttbbs/util/deluserfile.c | 2 +- pttbbs/util/descrypt.c | 2 +- pttbbs/util/expire.c | 2 +- pttbbs/util/horoscope.c | 4 +- pttbbs/util/indexuser.c | 4 +- pttbbs/util/initbbs.c | 2 +- pttbbs/util/jungo.c | 4 +- pttbbs/util/mandex.c | 2 +- pttbbs/util/merge_board.c | 2 +- pttbbs/util/merge_passwd.c | 2 +- pttbbs/util/openticket.c | 4 +- pttbbs/util/openvice.c | 2 +- pttbbs/util/parse_news.c | 2 +- pttbbs/util/post.c | 2 +- pttbbs/util/reaper.c | 4 +- pttbbs/util/rmuid.c | 2 +- pttbbs/util/showboard.c | 2 +- pttbbs/util/toplazyBBM.c | 4 +- pttbbs/util/toplazyBM.c | 2 +- pttbbs/util/topusr.c | 4 +- pttbbs/util/tunepasswd.c | 2 +- pttbbs/util/uhash_loader.c | 2 +- pttbbs/util/util_passwd.c | 2 +- pttbbs/util/util_record.c | 246 --------------------------------------------- pttbbs/util/webgrep.c | 2 +- pttbbs/util/xchatd.c | 2 +- pttbbs/util/yearsold.c | 4 +- 36 files changed, 47 insertions(+), 293 deletions(-) delete mode 100644 pttbbs/util/util_record.c diff --git a/pttbbs/util/BM_money.c b/pttbbs/util/BM_money.c index 075f53ae..09e66257 100644 --- a/pttbbs/util/BM_money.c +++ b/pttbbs/util/BM_money.c @@ -1,4 +1,4 @@ -/* $Id: BM_money.c,v 1.7 2003/07/20 00:55:34 in2 Exp $ */ +/* $Id$ */ /* 給板主錢的程式 */ @@ -36,7 +36,7 @@ int main(int argc, char **argv) attach_SHM(); resolve_boards(); - if(passwd_mmap()) + if(passwd_init()) exit(1); if (!fp) return 0; diff --git a/pttbbs/util/Makefile b/pttbbs/util/Makefile index d1a80835..6b847752 100644 --- a/pttbbs/util/Makefile +++ b/pttbbs/util/Makefile @@ -9,7 +9,7 @@ UTIL_OBJS= \ # 用來從 ../mbbsd/xxx.c 產生 util_xxx.o MBBSD_OBJS= \ var stuff cache osdep \ - args + args passwd # 下面這些程式, 會被 compile 並且和 $(UTIL_OBJS) 聯結 CPROG_WITH_UTIL= \ @@ -40,7 +40,7 @@ all: ${CPROG_WITH_UTIL} ${CPROG_WITHOUT_UTIL} ${PROGS} .for fn in ${CPROG_WITH_UTIL} ${fn}: ${fn}.c ${UTIL_OBJS} - ${CC} ${CFLAGS} -o ${fn} ${UTIL_OBJS} ${fn}.c + ${CC} ${CFLAGS} ${LDFLAGS} -o ${fn} ${UTIL_OBJS} ${fn}.c .endfor .for fn in ${MBBSD_OBJS} @@ -49,7 +49,7 @@ util_${fn}.o: ../mbbsd/${fn}.c .endfor xchatd: xchatd.c $(UTIL_OBJS) descrypt.c - $(CC) $(CFLAGS) -o $@ $@.c $(UTIL_OBJS) descrypt.c + $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $@.c $(UTIL_OBJS) descrypt.c install: $(PROGS) install -d $(BBSHOME)/bin/ diff --git a/pttbbs/util/account.c b/pttbbs/util/account.c index 827eefb4..b3f65f82 100644 --- a/pttbbs/util/account.c +++ b/pttbbs/util/account.c @@ -1,4 +1,4 @@ -/* $Id: account.c,v 1.9 2003/07/20 00:55:34 in2 Exp $ */ +/* $Id$ */ #include "bbs.h" #define MAX_LINE 16 diff --git a/pttbbs/util/antispam.c b/pttbbs/util/antispam.c index e29549aa..e5b2ed59 100644 --- a/pttbbs/util/antispam.c +++ b/pttbbs/util/antispam.c @@ -1,4 +1,4 @@ -/* $Id: antispam.c,v 1.2 2003/07/20 00:55:34 in2 Exp $ */ +/* $Id$ */ /* 抓廣告信的程式 */ #include <stdio.h> #include <string.h> diff --git a/pttbbs/util/bbsmail.c b/pttbbs/util/bbsmail.c index 7ef9435d..f2390254 100644 --- a/pttbbs/util/bbsmail.c +++ b/pttbbs/util/bbsmail.c @@ -1,4 +1,4 @@ -/* $Id: bbsmail.c,v 1.8 2003/07/21 07:11:50 in2 Exp $ */ +/* $Id$ */ #define _UTIL_C_ #include "bbs.h" @@ -252,7 +252,7 @@ main(int argc, char* argv[]) (void) setgid(BBSGID); (void) setuid(BBSUID); attach_SHM(); - if( passwd_mmap() ) + if( passwd_init() ) return 0; chdir(BBSHOME); diff --git a/pttbbs/util/bbsrf.c b/pttbbs/util/bbsrf.c index 66f6cee0..c527d761 100644 --- a/pttbbs/util/bbsrf.c +++ b/pttbbs/util/bbsrf.c @@ -1,4 +1,4 @@ -/* $Id: bbsrf.c,v 1.1 2002/03/07 15:13:45 in2 Exp $ */ +/* $Id$ */ #include <stdio.h> #include <string.h> diff --git a/pttbbs/util/birth.c b/pttbbs/util/birth.c index b7f65761..20bd65c0 100644 --- a/pttbbs/util/birth.c +++ b/pttbbs/util/birth.c @@ -49,7 +49,7 @@ int main(argc, argv) now = time(NULL); /* back to ancent */ ptime = localtime(&now); - if(passwd_mmap()) + if(passwd_init()) exit(1); printf("*製表\n"); diff --git a/pttbbs/util/buildir.c b/pttbbs/util/buildir.c index 38573e7f..e6b7f9d2 100644 --- a/pttbbs/util/buildir.c +++ b/pttbbs/util/buildir.c @@ -1,4 +1,4 @@ -/* $Id: buildir.c,v 1.2 2002/03/09 17:44:30 in2 Exp $ */ +/* $Id$ */ #include <stdio.h> #include <stdlib.h> #include <dirent.h> diff --git a/pttbbs/util/countalldice.c b/pttbbs/util/countalldice.c index badd4bad..63354668 100644 --- a/pttbbs/util/countalldice.c +++ b/pttbbs/util/countalldice.c @@ -1,4 +1,4 @@ -/* $Id: countalldice.c,v 1.1 2002/03/07 15:13:45 in2 Exp $ */ +/* $Id$ */ /**********************************************/ /*這個程式是用來計算賭骰子賺得錢跟賠的錢的程式 */ diff --git a/pttbbs/util/deluserfile.c b/pttbbs/util/deluserfile.c index 543048d0..73f3750a 100644 --- a/pttbbs/util/deluserfile.c +++ b/pttbbs/util/deluserfile.c @@ -1,4 +1,4 @@ -/* $Id: deluserfile.c,v 1.3 2002/06/06 21:34:14 in2 Exp $ */ +/* $Id$ */ /* 自動砍user目錄檔案程式 */ #include "bbs.h" diff --git a/pttbbs/util/descrypt.c b/pttbbs/util/descrypt.c index 97475c1a..6ea6dbe8 100644 --- a/pttbbs/util/descrypt.c +++ b/pttbbs/util/descrypt.c @@ -1,4 +1,4 @@ -/* $Id: descrypt.c,v 1.1 2002/03/07 15:13:45 in2 Exp $ */ +/* $Id$ */ /* * FreeSec: libcrypt for NetBSD diff --git a/pttbbs/util/expire.c b/pttbbs/util/expire.c index b75c85b8..4335ca16 100644 --- a/pttbbs/util/expire.c +++ b/pttbbs/util/expire.c @@ -1,4 +1,4 @@ -/* $Id: expire.c,v 1.7 2003/07/20 00:55:34 in2 Exp $ */ +/* $Id$ */ /* 自動砍信工具程式 */ #include "bbs.h" diff --git a/pttbbs/util/horoscope.c b/pttbbs/util/horoscope.c index b47634aa..04479108 100644 --- a/pttbbs/util/horoscope.c +++ b/pttbbs/util/horoscope.c @@ -1,4 +1,4 @@ -/* $Id: horoscope.c,v 1.4 2003/07/20 00:55:34 in2 Exp $ */ +/* $Id$ */ #define _UTIL_C_ #include "bbs.h" @@ -34,7 +34,7 @@ int main() { attach_SHM(); memset(act, 0, sizeof(act)); - if(passwd_mmap()) + if(passwd_init()) exit(1); for(k = 1; k <= MAX_USERS; k++) { passwd_query(k, &cuser); diff --git a/pttbbs/util/indexuser.c b/pttbbs/util/indexuser.c index e0975130..8dde8f06 100644 --- a/pttbbs/util/indexuser.c +++ b/pttbbs/util/indexuser.c @@ -1,4 +1,4 @@ -/* $Id: indexuser.c,v 1.6 2003/07/20 00:55:34 in2 Exp $ */ +/* $Id$ */ #define _UTIL_C_ #include "bbs.h" #define INDEXPATH BBSHOME"/index" @@ -22,7 +22,7 @@ int main(int argc, char **argv) char buf[256]; attach_SHM(); - if(passwd_mmap()) + if(passwd_init()) { printf("Sorry, the data is not ready.\n"); exit(0); diff --git a/pttbbs/util/initbbs.c b/pttbbs/util/initbbs.c index 72988353..e093fe02 100644 --- a/pttbbs/util/initbbs.c +++ b/pttbbs/util/initbbs.c @@ -1,4 +1,4 @@ -/* $Id: initbbs.c,v 1.6 2003/05/23 00:58:32 in2 Exp $ */ +/* $Id$ */ #include <stdio.h> #include <string.h> #include <stdlib.h> diff --git a/pttbbs/util/jungo.c b/pttbbs/util/jungo.c index 4f038efe..c0723c61 100644 --- a/pttbbs/util/jungo.c +++ b/pttbbs/util/jungo.c @@ -1,4 +1,4 @@ -/* $Id: jungo.c,v 1.7 2003/07/20 00:55:34 in2 Exp $ */ +/* $Id$ */ #define _UTIL_C_ #include "bbs.h" @@ -50,7 +50,7 @@ int main(int argc, char *argv[]) attach_SHM(); resolve_boards(); - if(passwd_mmap()) + if(passwd_init()) exit(1); memcpy(allbrd,bcache,numboards*sizeof(boardheader_t)); diff --git a/pttbbs/util/mandex.c b/pttbbs/util/mandex.c index f1059f68..ed8ee9c9 100644 --- a/pttbbs/util/mandex.c +++ b/pttbbs/util/mandex.c @@ -1,4 +1,4 @@ -/* $Id: mandex.c,v 1.10 2003/07/20 00:55:34 in2 Exp $ */ +/* $Id$ */ /* 'mandex -h' to help */ diff --git a/pttbbs/util/merge_board.c b/pttbbs/util/merge_board.c index 743ffc14..12f41346 100644 --- a/pttbbs/util/merge_board.c +++ b/pttbbs/util/merge_board.c @@ -1,4 +1,4 @@ -/* $Id: merge_board.c,v 1.1 2002/03/07 15:13:46 in2 Exp $ */ +/* $Id$ */ #include <stdio.h> #include <stdlib.h> #include <ctype.h> diff --git a/pttbbs/util/merge_passwd.c b/pttbbs/util/merge_passwd.c index d27c473b..20f59aae 100644 --- a/pttbbs/util/merge_passwd.c +++ b/pttbbs/util/merge_passwd.c @@ -1,4 +1,4 @@ -/* $Id: merge_passwd.c,v 1.1 2002/03/07 15:13:46 in2 Exp $ */ +/* $Id$ */ #include <stdio.h> #include <stdlib.h> #include <ctype.h> diff --git a/pttbbs/util/openticket.c b/pttbbs/util/openticket.c index 5d7584bc..bcc58d0a 100644 --- a/pttbbs/util/openticket.c +++ b/pttbbs/util/openticket.c @@ -1,4 +1,4 @@ -/* $Id: openticket.c,v 1.10 2003/07/20 00:55:34 in2 Exp $ */ +/* $Id$ */ /* 開獎的 utility */ #define _UTIL_C_ #include "bbs.h" @@ -32,7 +32,7 @@ int main(int argc, char **argv) nice(10); attach_SHM(); - if(passwd_mmap()) + if(passwd_init()) exit(1); rename(BBSHOME "/etc/" FN_TICKET_RECORD, diff --git a/pttbbs/util/openvice.c b/pttbbs/util/openvice.c index 41c146ab..abc08272 100644 --- a/pttbbs/util/openvice.c +++ b/pttbbs/util/openvice.c @@ -1,4 +1,4 @@ -/* $Id: openvice.c,v 1.3 2003/07/20 00:55:34 in2 Exp $ */ +/* $Id$ */ /* 發票開獎小程式 */ #include "bbs.h" diff --git a/pttbbs/util/parse_news.c b/pttbbs/util/parse_news.c index b1f0ad25..6ea75454 100644 --- a/pttbbs/util/parse_news.c +++ b/pttbbs/util/parse_news.c @@ -1,4 +1,4 @@ -/* $Id: parse_news.c,v 1.5 2003/07/20 00:55:34 in2 Exp $ */ +/* $Id$ */ #include "bbs.h" #define NEWSDIRECT BBSHOME "/boards/n/newspaper" diff --git a/pttbbs/util/post.c b/pttbbs/util/post.c index ba6ee1d7..c3af5269 100644 --- a/pttbbs/util/post.c +++ b/pttbbs/util/post.c @@ -1,4 +1,4 @@ -/* $Id: post.c,v 1.5 2003/07/20 00:55:34 in2 Exp $ */ +/* $Id$ */ #include "bbs.h" void keeplog(FILE *fin, char *fpath, char *board, char *title, char *owner) { diff --git a/pttbbs/util/reaper.c b/pttbbs/util/reaper.c index 633a4c78..03f7a694 100644 --- a/pttbbs/util/reaper.c +++ b/pttbbs/util/reaper.c @@ -1,4 +1,4 @@ -/* $Id: reaper.c,v 1.4 2003/07/20 00:55:34 in2 Exp $ */ +/* $Id$ */ #define _UTIL_C_ #include "bbs.h" @@ -53,7 +53,7 @@ int main(int argc, char **argv) chdir(BBSHOME); attach_SHM(); - if(passwd_mmap()) + if(passwd_init()) exit(1); passwd_apply2(check); diff --git a/pttbbs/util/rmuid.c b/pttbbs/util/rmuid.c index 2bd1017a..01898721 100644 --- a/pttbbs/util/rmuid.c +++ b/pttbbs/util/rmuid.c @@ -1,4 +1,4 @@ -/* $Id: rmuid.c,v 1.4 2003/07/20 00:55:34 in2 Exp $ */ +/* $Id$ */ #include "bbs.h" extern int numboards; diff --git a/pttbbs/util/showboard.c b/pttbbs/util/showboard.c index 91593b12..7dee4002 100644 --- a/pttbbs/util/showboard.c +++ b/pttbbs/util/showboard.c @@ -1,4 +1,4 @@ -/* $Id: showboard.c,v 1.2 2002/04/05 14:36:25 in2 Exp $ */ +/* $Id$ */ /* 看板一覽表(sorted) */ #include <stdio.h> diff --git a/pttbbs/util/toplazyBBM.c b/pttbbs/util/toplazyBBM.c index 0e5b078b..97cb62ae 100644 --- a/pttbbs/util/toplazyBBM.c +++ b/pttbbs/util/toplazyBBM.c @@ -1,4 +1,4 @@ -/* $Id: toplazyBBM.c,v 1.7 2003/07/20 00:55:34 in2 Exp $ */ +/* $Id$ */ #define _UTIL_C_ #include "bbs.h" @@ -51,7 +51,7 @@ int main(int argc, char *argv[]) attach_SHM(); resolve_boards(); - if(passwd_mmap()) + if(passwd_init()) exit(1); memcpy(allbrd,bcache,numboards*sizeof(boardheader_t)); diff --git a/pttbbs/util/toplazyBM.c b/pttbbs/util/toplazyBM.c index 55267927..bf31be58 100644 --- a/pttbbs/util/toplazyBM.c +++ b/pttbbs/util/toplazyBM.c @@ -49,7 +49,7 @@ int main(int argc, char *argv[]) attach_SHM(); resolve_boards(); - if(passwd_mmap()) + if(passwd_init()) exit(1); memcpy(allbrd,bcache,numboards*sizeof(boardheader_t)); diff --git a/pttbbs/util/topusr.c b/pttbbs/util/topusr.c index 37b051d9..5aa2eb7a 100644 --- a/pttbbs/util/topusr.c +++ b/pttbbs/util/topusr.c @@ -1,4 +1,4 @@ -/* $Id: topusr.c,v 1.4 2003/07/20 00:55:34 in2 Exp $ */ +/* $Id$ */ /* 使用者 上站記錄/文章篇數 排行榜 */ #define _UTIL_C_ #include "bbs.h" @@ -123,7 +123,7 @@ int main(int argc, char **argv) num = 30; attach_SHM(); - if(passwd_mmap()) + if(passwd_init()) { printf("Sorry, the data is not ready.\n"); exit(0); diff --git a/pttbbs/util/tunepasswd.c b/pttbbs/util/tunepasswd.c index 15a3fe1f..1d575dcc 100644 --- a/pttbbs/util/tunepasswd.c +++ b/pttbbs/util/tunepasswd.c @@ -1,4 +1,4 @@ -/* $Id: tunepasswd.c,v 1.1 2002/03/07 15:13:46 in2 Exp $ */ +/* $Id$ */ #include <stdio.h> #include <string.h> #include <unistd.h> diff --git a/pttbbs/util/uhash_loader.c b/pttbbs/util/uhash_loader.c index 7d066ab9..d5171d56 100644 --- a/pttbbs/util/uhash_loader.c +++ b/pttbbs/util/uhash_loader.c @@ -1,4 +1,4 @@ -/* $Id: uhash_loader.c,v 1.4 2003/05/15 08:27:23 in2 Exp $ */ +/* $Id$ */ /* standalone uhash loader -- jochang */ #include <stdio.h> #include <stdlib.h> diff --git a/pttbbs/util/util_passwd.c b/pttbbs/util/util_passwd.c index d7f1cea2..6fdf136c 100644 --- a/pttbbs/util/util_passwd.c +++ b/pttbbs/util/util_passwd.c @@ -1,4 +1,4 @@ -/* $Id: util_passwd.c,v 1.4 2003/05/15 08:27:23 in2 Exp $ */ +/* $Id$ */ #include <stdio.h> #include <stdlib.h> #include <string.h> diff --git a/pttbbs/util/util_record.c b/pttbbs/util/util_record.c deleted file mode 100644 index 80a7ff56..00000000 --- a/pttbbs/util/util_record.c +++ /dev/null @@ -1,246 +0,0 @@ -/* $Id: util_record.c,v 1.4 2003/05/15 08:27:23 in2 Exp $ */ -#include <stdio.h> -#include <stdlib.h> -#include <errno.h> -#include <string.h> -#include <unistd.h> -#include <time.h> -#include <sys/types.h> -#include <sys/stat.h> -#include <sys/file.h> -#include "config.h" -#include "pttstruct.h" -#include "modes.h" -#include "proto.h" - -#undef HAVE_MMAP -#define BUFSIZE 512 - -extern char *str_reply; - -static void PttLock(int fd, int size, int mode) { - static struct flock lock_it; - int ret; - - lock_it.l_whence = SEEK_CUR; /* from current point */ - lock_it.l_start = 0; /* -"- */ - lock_it.l_len = size; /* length of data */ - lock_it.l_type = mode; /* set exclusive/write lock */ - lock_it.l_pid = 0; /* pid not actually interesting */ - while((ret = fcntl(fd, F_SETLKW, &lock_it)) < 0 && errno == EINTR); -} - -#define safewrite write - -int get_num_records(char *fpath, int size) { - struct stat st; - if(stat(fpath, &st) == -1) - return 0; - return st.st_size / size; -} - -int get_sum_records(char* fpath, int size) { - struct stat st; - long ans = 0; - FILE* fp; - fileheader_t fhdr; - char buf[200], *p; - - if(!(fp = fopen(fpath, "r"))) - return -1; - - strcpy(buf, fpath); - p = strrchr(buf, '/') + 1; - - while(fread(&fhdr, size, 1, fp) == 1) { - strcpy(p, fhdr.filename); - if(stat(buf, &st) == 0 && S_ISREG(st.st_mode) && st.st_nlink == 1) - ans += st.st_size; - } - fclose(fp); - return ans / 1024; -} - -int get_record(char *fpath, void *rptr, int size, int id) { - int fd = -1; - - if(id < 1 || (fd = open(fpath, O_RDONLY, 0)) != -1) { - if(lseek(fd, (off_t)(size * (id - 1)), SEEK_SET) != -1) { - if(read(fd, rptr, size) == size) { - close(fd); - return 0; - } - } - close(fd); - } - return -1; -} - -int get_records(char *fpath, void *rptr, int size, int id, int number) { - int fd; - - if(id < 1 || (fd = open(fpath, O_RDONLY, 0)) == -1) - return -1; - - if(lseek(fd, (off_t)(size * (id - 1)), SEEK_SET) == -1) { - close(fd); - return 0; - } - if((id = read(fd, rptr, size * number)) == -1) { - close(fd); - return -1; - } - close(fd); - return id / size; -} - -int substitute_record(char *fpath, void *rptr, int size, int id) { - int fd; - -#ifdef POSTBUG - if(size == sizeof(fileheader) && (id > 1) && ((id - 1) % 4 == 0)) - saverecords(fpath, size, id); -#endif - - if(id < 1 || (fd = open(fpath, O_WRONLY | O_CREAT, 0644)) == -1) - return -1; - -#ifdef HAVE_REPORT - if(lseek(fd, (off_t)(size * (id - 1)), SEEK_SET) == -1) - report("substitute_record failed!!! (lseek)"); - PttLock(fd, size, F_WRLCK); - if(safewrite(fd, rptr, size) != size) - report("substitute_record failed!!! (safewrite)"); - PttLock(fd, size, F_UNLCK); -#else - lseek(fd, (off_t) (size * (id - 1)), SEEK_SET); - PttLock(fd, size, F_WRLCK); - safewrite(fd, rptr, size); - PttLock(fd, size, F_UNLCK); -#endif - close(fd); - -#ifdef POSTBUG - if(size == sizeof(fileheader) && (id > 1) && ((id - 1) % 4 == 0)) - restorerecords(fpath, size, id); -#endif - - return 0; -} - -int apply_record(char *fpath, int (*fptr)(), int size) { - char abuf[BUFSIZE]; - FILE* fp; - - if(!(fp = fopen(fpath, "r"))) - return -1; - - while(fread(abuf, 1, size, fp) == (unsigned)size) - if((*fptr) (abuf) == QUIT) { - fclose(fp); - return QUIT; - } - fclose(fp); - return 0; -} - -/* mail / post 時,依據時間建立檔案,加上郵戳 */ -int stampfile(char *fpath, fileheader_t *fh) { - register char *ip = fpath; - time_t dtime; - struct tm *ptime; - int fp = 0; - - if(access(fpath, X_OK | R_OK | W_OK)) - mkdir(fpath, 0755); - - time(&dtime); - while (*(++ip)); - *ip++ = '/'; - do { - sprintf(ip, "M.%ld.A.%3.3X", ++dtime, rand()&0xfff ); - if(fp == -1 && errno != EEXIST) - return -1; - } while((fp = open(fpath, O_CREAT | O_EXCL | O_WRONLY, 0644)) == -1); - close(fp); - memset(fh, 0, sizeof(fileheader_t)); - strcpy(fh->filename, ip); - ptime = localtime(&dtime); - sprintf(fh->date, "%2d/%02d", ptime->tm_mon + 1, ptime->tm_mday); - return 0; -} - -void stampdir(char *fpath, fileheader_t *fh) { - register char *ip = fpath; - time_t dtime; - struct tm *ptime; - - if(access(fpath, X_OK | R_OK | W_OK)) - mkdir(fpath, 0755); - - time(&dtime); - while(*(++ip)); - *ip++ = '/'; - do { - sprintf(ip, "D%lX", ++dtime & 07777); - } while(mkdir(fpath, 0755) == -1); - memset(fh, 0, sizeof(fileheader_t)); - strcpy(fh->filename, ip); - ptime = localtime(&dtime); - sprintf(fh->date, "%2d/%02d", ptime->tm_mon + 1, ptime->tm_mday); -} - -void stamplink(char *fpath, fileheader_t *fh) { - register char *ip = fpath; - time_t dtime; - struct tm *ptime; - - if(access(fpath, X_OK | R_OK | W_OK)) - mkdir(fpath, 0755); - - time(&dtime); - while(*(++ip)); - *ip++ = '/'; - do { - sprintf(ip, "S%lX", ++dtime ); - } while(symlink("temp", fpath) == -1); - memset(fh, 0, sizeof(fileheader_t)); - strcpy(fh->filename, ip); - ptime = localtime(&dtime); - sprintf(fh->date, "%2d/%02d", ptime->tm_mon + 1, ptime->tm_mday); -} - -int do_append(char *fpath, fileheader_t *record, int size) { - int fd; - - if((fd = open(fpath, O_WRONLY | O_CREAT, 0644)) == -1) { - perror("open"); - return -1; - } - flock(fd, LOCK_EX); - lseek(fd, 0, SEEK_END); - - safewrite(fd, record, size); - - flock(fd, LOCK_UN); - close(fd); - return 0; -} - -int append_record(char *fpath, fileheader_t *record, int size) { -#ifdef POSTBUG - int numrecs = (int)get_num_records(fpath, size); - - bug_possible = 1; - if(size == sizeof(fileheader) && numrecs && (numrecs % 4 == 0)) - saverecords(fpath, size, numrecs + 1); -#endif - do_append(fpath,record,size); - -#ifdef POSTBUG - if(size == sizeof(fileheader) && numrecs && (numrecs % 4 == 0)) - restorerecords(fpath, size, numrecs + 1); - bug_possible = 0; -#endif - return 0; -} diff --git a/pttbbs/util/webgrep.c b/pttbbs/util/webgrep.c index d3d7304f..d101e035 100644 --- a/pttbbs/util/webgrep.c +++ b/pttbbs/util/webgrep.c @@ -1,4 +1,4 @@ -/* $Id: webgrep.c,v 1.2 2002/06/19 13:38:01 lwms Exp $ */ +/* $Id$ */ #include <stdio.h> #include <string.h> #include <stdlib.h> diff --git a/pttbbs/util/xchatd.c b/pttbbs/util/xchatd.c index b4aef8a6..906bded0 100644 --- a/pttbbs/util/xchatd.c +++ b/pttbbs/util/xchatd.c @@ -1,4 +1,4 @@ -/* $Id: xchatd.c,v 1.3 2003/07/20 00:55:34 in2 Exp $ */ +/* $Id$ */ #include "bbs.h" #include "xchatd.h" diff --git a/pttbbs/util/yearsold.c b/pttbbs/util/yearsold.c index 3229b709..f93134a6 100644 --- a/pttbbs/util/yearsold.c +++ b/pttbbs/util/yearsold.c @@ -1,4 +1,4 @@ -/* $Id: yearsold.c,v 1.5 2003/07/20 00:55:34 in2 Exp $ */ +/* $Id$ */ /* 站上年齡統計 */ #define _UTIL_C_ #include "bbs.h" @@ -38,7 +38,7 @@ int main(int argc, char **argv) ptime = localtime(&now); attach_SHM(); - if(passwd_mmap()) + if(passwd_init()) exit(1); memset(act, 0, sizeof(act)); -- cgit v1.2.3 From 43300dcd86375c3e9da361909aacd32b56f7bd1b Mon Sep 17 00:00:00 2001 From: victor <victor@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Fri, 15 Aug 2003 06:35:53 +0000 Subject: merge util_record.c to mbbsd/record.c git-svn-id: http://opensvn.csie.org/pttbbs/trunk@1097 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/Makefile | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/pttbbs/util/Makefile b/pttbbs/util/Makefile index 6b847752..7d1073d7 100644 --- a/pttbbs/util/Makefile +++ b/pttbbs/util/Makefile @@ -3,13 +3,12 @@ .include "../pttbbs.mk" UTIL_OBJS= \ - util_cache.o util_record.o util_passwd.o util_var.o util_stuff.o\ - util_osdep.o util_args.o + util_cache.o util_record.o util_passwd.o util_var.o \ + util_stuff.o util_osdep.o util_args.o -# 用來從 ../mbbsd/xxx.c 產生 util_xxx.o MBBSD_OBJS= \ - var stuff cache osdep \ - args passwd + cache record passwd var \ + stuff osdep args # 下面這些程式, 會被 compile 並且和 $(UTIL_OBJS) 聯結 CPROG_WITH_UTIL= \ -- cgit v1.2.3 From 5a03c8b2d1ee29a731d8fe9570f3c79c4b4535b7 Mon Sep 17 00:00:00 2001 From: victor <victor@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Fri, 15 Aug 2003 06:36:23 +0000 Subject: merge util_passwd.c to mbbsd/passwd.c git-svn-id: http://opensvn.csie.org/pttbbs/trunk@1098 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/util_passwd.c | 142 ---------------------------------------------- 1 file changed, 142 deletions(-) delete mode 100644 pttbbs/util/util_passwd.c diff --git a/pttbbs/util/util_passwd.c b/pttbbs/util/util_passwd.c deleted file mode 100644 index 6fdf136c..00000000 --- a/pttbbs/util/util_passwd.c +++ /dev/null @@ -1,142 +0,0 @@ -/* $Id$ */ -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <fcntl.h> -#include <errno.h> -#include <unistd.h> -#include <sys/types.h> -#include <sys/stat.h> -#include <sys/mman.h> -#include <sys/ipc.h> -#include <sys/sem.h> -#include "config.h" -#include "pttstruct.h" -#include "modes.h" -#include "common.h" -#include "proto.h" - -#ifndef SEM_R -#define SEM_R 0400 -#endif - -#ifndef SEM_A -#define SEM_A 0200 -#endif - -#ifndef __FreeBSD__ -union semun { - int val; /* value for SETVAL */ - struct semid_ds *buf; /* buffer for IPC_STAT & IPC_SET */ - u_short *array; /* array for GETALL & SETALL */ - struct seminfo *__buf; /* buffer for IPC_INFO */ -}; -#endif - -static userec_t *passwd_image = NULL; -static int passwd_image_size; -static int semid = -1; - -int passwd_mmap(void) { - int fd; - - if(passwd_image!=NULL) return 0; - fd = open(FN_PASSWD, O_RDWR); - if(fd > 0) { - struct stat st; - - fstat(fd, &st); - passwd_image_size = st.st_size; - passwd_image = mmap(NULL, passwd_image_size, - PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); - if(passwd_image == (userec_t *)-1) { - perror("mmap"); - return -1; - } - close(fd); - semid = semget(PASSWDSEM_KEY, 1, SEM_R | SEM_A | IPC_CREAT | IPC_EXCL); - if(semid == -1) { - if(errno == EEXIST) { - semid = semget(PASSWDSEM_KEY, 1, SEM_R | SEM_A); - if(semid == -1) { - perror("semget"); - exit(1); - } - } else { - perror("semget"); - exit(1); - } - } else { - union semun s; - - s.val = 1; - if(semctl(semid, 0, SETVAL, s) == -1) { - perror("semctl"); - exit(1); - } - } - } else { - perror(FN_PASSWD); - return -1; - } - return 0; -} -int passwd_update_money(int num) { - int money; - if(num < 1 || num > MAX_USERS) - return -1; - money = moneyof(num); - memcpy(&passwd_image[num - 1].money, &money, sizeof(int)); - return 0; -} - -int passwd_update(int num, userec_t *buf) { - if(num < 1 || num > MAX_USERS) - return -1; - buf->money = moneyof(num); - memcpy(&passwd_image[num - 1], buf, sizeof(userec_t)); - return 0; -} - -int passwd_query(int num, userec_t *buf) { - if(num < 1 || num > MAX_USERS) - return -1; - memcpy(buf, &passwd_image[num - 1], sizeof(userec_t)); - return 0; -} - -int passwd_apply(int (*fptr)(userec_t *)) { - int i; - - for(i = 0; i < MAX_USERS; i++) - if((*fptr)(&passwd_image[i]) == QUIT) - return QUIT; - return 0; -} - -int passwd_apply2(int (*fptr)(int, userec_t *)) { - int i; - - for(i = 0; i < MAX_USERS; i++) - if((*fptr)(i, &passwd_image[i]) == QUIT) - return QUIT; - return 0; -} - -void passwd_lock() { - struct sembuf buf = { 0, -1, SEM_UNDO }; - - if(semop(semid, &buf, 1)) { - perror("semop"); - exit(1); - } -} - -void passwd_unlock() { - struct sembuf buf = { 0, 1, SEM_UNDO }; - - if(semop(semid, &buf, 1)) { - perror("semop"); - exit(1); - } -} -- cgit v1.2.3 From c3b09300bde274fe080fd0a457d22248aeed0a2f Mon Sep 17 00:00:00 2001 From: victor <victor@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Fri, 15 Aug 2003 07:09:24 +0000 Subject: useless git-svn-id: http://opensvn.csie.org/pttbbs/trunk@1099 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/util.h | 31 ------------------------------- 1 file changed, 31 deletions(-) delete mode 100644 pttbbs/util/util.h diff --git a/pttbbs/util/util.h b/pttbbs/util/util.h deleted file mode 100644 index 9128e575..00000000 --- a/pttbbs/util/util.h +++ /dev/null @@ -1,31 +0,0 @@ -/* $Id: util.h,v 1.1 2002/03/07 15:13:46 in2 Exp $ */ -#ifndef INCLUDE_UTIL_H -#define INCLUDE_UTIL_H - -int searchuser(char *userid); -int stampfile(char *fpath, fileheader_t *fh); -int append_record(char *fpath, fileheader_t *record, int size); -int get_record(char *fpath, void *rptr, int size, int id); -int substitute_record(char *fpath, void *rptr, int size, int id); -void resolve_boards(); -int getbnum(char *bname); -void inbtotal(int bid, int add); -void *attach_shm(int shmkey, int shmsize); -void reload_pttcache(); -void resolve_fcache(); -void attach_uhash(); -void stamplink(char *fpath, fileheader_t *fh); -void resolve_utmp(); -void remove_from_uhash(int n); -void setuserid(int num, char *userid); - -int passwd_mmap(); -int passwd_update(int num, userec_t *buf); -int passwd_query(int num, userec_t *buf); -int passwd_apply(int (*fptr)(userec_t *)); -int passwd_apply2(int (*fptr)(int, userec_t *)); -void passwd_lock(); -void passwd_unlock(); - -#endif - -- cgit v1.2.3 From 873703eecad2b2d743bba25ddc3fdbad75b1391c Mon Sep 17 00:00:00 2001 From: victor <victor@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Fri, 15 Aug 2003 07:13:20 +0000 Subject: forget to commit git-svn-id: http://opensvn.csie.org/pttbbs/trunk@1100 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/passwd.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/pttbbs/mbbsd/passwd.c b/pttbbs/mbbsd/passwd.c index a9b32f0c..7686e566 100644 --- a/pttbbs/mbbsd/passwd.c +++ b/pttbbs/mbbsd/passwd.c @@ -1,4 +1,4 @@ -/* $Id: passwd.c,v 1.8 2002/07/21 09:26:02 in2 Exp $ */ +/* $Id$ */ #include "bbs.h" static int semid = -1; @@ -103,6 +103,19 @@ passwd_apply(int (*fptr) (userec_t *)) return 0; } +int +passwd_apply2(int (*fptr)(int, userec_t *)) +{ + int i; + userec_t user; + for(i = 0; i < MAX_USERS; i++){ + passwd_query(i + 1, &user); + if((*fptr)(i, &user) == QUIT) + return QUIT; + } + return 0; +} + void passwd_lock() { -- cgit v1.2.3 -- cgit v1.2.3 From 406c91945b4e5cdbe6dd7e70ad8872899e8e8b12 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sun, 17 Aug 2003 01:01:10 +0000 Subject: remove HTML::Calendar::Simple git-svn-id: http://opensvn.csie.org/pttbbs/trunk@1103 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/blog/blog.pl | 5 +---- pttbbs/staticweb/man.pl | 3 +-- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/pttbbs/blog/blog.pl b/pttbbs/blog/blog.pl index e3a91126..d964e58e 100755 --- a/pttbbs/blog/blog.pl +++ b/pttbbs/blog/blog.pl @@ -1,5 +1,5 @@ #!/usr/bin/perl -# $Id: blog.pl,v 1.30 2003/07/08 04:34:19 in2 Exp $ +# $Id$ use CGI qw/:standard/; use lib qw/./; use LocalVars; @@ -8,7 +8,6 @@ use strict; use Data::Dumper; use Date::Calc qw(:all); use Template; -use HTML::Calendar::Simple; use OurNet::FuzzyIndex; use DBI; use DBD::mysql; @@ -223,8 +222,6 @@ sub main $c .= "</tr>\n" if( !$newtr ); $c .= "</table>\n"; $th{calendar} = $c; - #my $cal = HTML::Calendar::Simple->new({month => $m, year => $y}); - #$th{calendar} = $cal->calendar_month; } # Comments --------------------------------------------------------------- diff --git a/pttbbs/staticweb/man.pl b/pttbbs/staticweb/man.pl index 7d33ee5a..729a78d1 100755 --- a/pttbbs/staticweb/man.pl +++ b/pttbbs/staticweb/man.pl @@ -1,5 +1,5 @@ #!/usr/bin/perl -# $Id: man.pl,v 1.8 2003/07/07 04:17:58 in2 Exp $ +# $Id$ use CGI qw/:standard/; use lib qw/./; use LocalVars; @@ -8,7 +8,6 @@ use strict; use Data::Dumper; use Date::Calc qw(:all); use Template; -use HTML::Calendar::Simple; use OurNet::FuzzyIndex; use Data::Serializer; use Encode; -- cgit v1.2.3 From 3c6b96daa7b5b88cc3d6e975d738e27dc41f5f9c Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sun, 17 Aug 2003 01:04:04 +0000 Subject: use svn:ignore git-svn-id: http://opensvn.csie.org/pttbbs/trunk@1104 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/blog/.cvsignore | 1 - 1 file changed, 1 deletion(-) delete mode 100644 pttbbs/blog/.cvsignore diff --git a/pttbbs/blog/.cvsignore b/pttbbs/blog/.cvsignore deleted file mode 100644 index 896fc449..00000000 --- a/pttbbs/blog/.cvsignore +++ /dev/null @@ -1 +0,0 @@ -LocalVars.pm -- cgit v1.2.3 From 9e0cca51f9f15b4d67a56592fe4ec81d22a4ddc6 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sun, 17 Aug 2003 01:07:30 +0000 Subject: remove use LocalVars git-svn-id: http://opensvn.csie.org/pttbbs/trunk@1105 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/blog/index.pl | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pttbbs/blog/index.pl b/pttbbs/blog/index.pl index 091bc1f3..9b2e6dc1 100755 --- a/pttbbs/blog/index.pl +++ b/pttbbs/blog/index.pl @@ -1,8 +1,7 @@ #!/usr/bin/perl -# $Id: index.pl,v 1.2 2003/06/20 04:35:51 in2 Exp $ +# $Id$ use CGI qw/:standard/; use lib qw/./; -use LocalVars; sub main { -- cgit v1.2.3 From e7586158938262d19905030d3e0be61bcdba5113 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sun, 17 Aug 2003 01:09:33 +0000 Subject: param('searchboard') git-svn-id: http://opensvn.csie.org/pttbbs/trunk@1106 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/blog/blog.pl | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/pttbbs/blog/blog.pl b/pttbbs/blog/blog.pl index d964e58e..db9c4c9d 100755 --- a/pttbbs/blog/blog.pl +++ b/pttbbs/blog/blog.pl @@ -29,6 +29,17 @@ sub main @cnumber = ('零', '一', '二', '三', '四', '五', '六', '七', '八', '九', '十', '十一', '十二'); + if( $brdname = param('searchboard') ){ + dodbi(sub { + my($dbh) = @_; + my($sth); + $sth = $dbh->prepare("select k from counter where k='$brdname'"); + $sth->execute(); + $brdname = $sth->fetchrow_hashref()->{k}; + }); + return redirect("/blog.pl/$brdname/"); + } + if( !$ENV{PATH_INFO} ){ print header(-status => 400); return; -- cgit v1.2.3 From f4024411c06cd704e9b30ac9cfe5bdba07e21733 Mon Sep 17 00:00:00 2001 From: victor <victor@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Mon, 18 Aug 2003 11:48:17 +0000 Subject: fix util merging error git-svn-id: http://opensvn.csie.org/pttbbs/trunk@1107 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/cache.c | 14 +++++++------- pttbbs/mbbsd/record.c | 8 ++++---- pttbbs/mbbsd/var.c | 12 +++++++++++- pttbbs/util/Makefile | 2 ++ pttbbs/util/parsevar.pl | 4 ++-- 5 files changed, 26 insertions(+), 14 deletions(-) diff --git a/pttbbs/mbbsd/cache.c b/pttbbs/mbbsd/cache.c index 7b26f8f2..945fed88 100644 --- a/pttbbs/mbbsd/cache.c +++ b/pttbbs/mbbsd/cache.c @@ -492,7 +492,7 @@ setutmpmode(unsigned int mode) if (HAS_PERM(PERM_LOGUSER)) { char msg[200]; snprintf(msg, sizeof(msg), "%s setutmpmode to %s(%d) at %s", - cuser.userid, modestring(currutmp, 0), mode, Cdate(&now)); + cuser.userid, modestring(currutmp, 0), mode, Cdate(&COMMON_TIME)); log_user(msg); } } @@ -518,8 +518,8 @@ load_fileheader_cache(int bid, char *direct) { int num = getbtotal(bid); int n = num - DIRCACHESIZE + 1; - if (SHM->Bbusystate != 1 && now - SHM->busystate_b[bid - 1] >= 10) { - SHM->busystate_b[bid - 1] = now; + if (SHM->Bbusystate != 1 && COMMON_TIME - SHM->busystate_b[bid - 1] >= 10) { + SHM->busystate_b[bid - 1] = COMMON_TIME; get_records(direct, SHM->dircache[bid - 1], sizeof(fileheader_t), n < 1 ? 1 : n, DIRCACHESIZE); SHM->busystate_b[bid - 1] = 0; @@ -620,7 +620,7 @@ void resolve_boards(void) void touch_boards(void) { - SHM->Btouchtime = now; + SHM->Btouchtime = COMMON_TIME; numboards = -1; resolve_boards(); } @@ -639,10 +639,10 @@ reset_board(int bid) /* XXXbid: from 1 */ if (--bid < 0) return; - if (SHM->Bbusystate || now - SHM->busystate_b[bid] < 10) { + if (SHM->Bbusystate || COMMON_TIME - SHM->busystate_b[bid] < 10) { safe_sleep(1); } else { - SHM->busystate_b[bid] = now; + SHM->busystate_b[bid] = COMMON_TIME; nuser = bcache[bid].nuser; bhdr = bcache; @@ -998,7 +998,7 @@ hbflreload(int bid) } fclose(fp); } - hbfl[0] = now; + hbfl[0] = COMMON_TIME; memcpy(SHM->hbfl[bid], hbfl, sizeof(hbfl)); } diff --git a/pttbbs/mbbsd/record.c b/pttbbs/mbbsd/record.c index 2bd06b16..e16b9404 100644 --- a/pttbbs/mbbsd/record.c +++ b/pttbbs/mbbsd/record.c @@ -1,4 +1,4 @@ -/* $Id: record.c,v 1.14 2003/06/28 08:47:45 kcwu Exp $ */ +/* $Id$ */ #include "bbs.h" #undef HAVE_MMAP @@ -467,7 +467,7 @@ int stampfile(char *fpath, fileheader_t * fh) { register char *ip = fpath; - time_t dtime = now; + time_t dtime = COMMON_TIME; struct tm *ptime; int fp = 0; @@ -494,7 +494,7 @@ void stampdir(char *fpath, fileheader_t * fh) { register char *ip = fpath; - time_t dtime = now; + time_t dtime = COMMON_TIME; struct tm *ptime; if (access(fpath, X_OK | R_OK | W_OK)) @@ -516,7 +516,7 @@ void stamplink(char *fpath, fileheader_t * fh) { register char *ip = fpath; - time_t dtime = now; + time_t dtime = COMMON_TIME; struct tm *ptime; if (access(fpath, X_OK | R_OK | W_OK)) diff --git a/pttbbs/mbbsd/var.c b/pttbbs/mbbsd/var.c index 4ba3cf9e..7df518e5 100644 --- a/pttbbs/mbbsd/var.c +++ b/pttbbs/mbbsd/var.c @@ -1,4 +1,4 @@ -/* $Id: var.c,v 1.21 2003/07/20 00:55:34 in2 Exp $ */ +/* $Id$ */ #define INCLUDE_VAR_H #include "bbs.h" @@ -621,3 +621,13 @@ char *friend_file[8] = { FN_WATER, FN_VISABLE }; + +#ifdef PTTBBS_UTIL + #ifdef OUTTA_TIMER + #define COMMON_TIME (SHM->GV2.e.now) + #else + #define COMMON_TIME (time(0)) + #endif +#else + #define COMMON_TIME (now) +#endif diff --git a/pttbbs/util/Makefile b/pttbbs/util/Makefile index 7d1073d7..b4788abd 100644 --- a/pttbbs/util/Makefile +++ b/pttbbs/util/Makefile @@ -2,6 +2,8 @@ .include "../pttbbs.mk" +CFLAGS+= -DPTTBBS_UTIL + UTIL_OBJS= \ util_cache.o util_record.o util_passwd.o util_var.o \ util_stuff.o util_osdep.o util_args.o diff --git a/pttbbs/util/parsevar.pl b/pttbbs/util/parsevar.pl index d532c786..fe2f2dc0 100644 --- a/pttbbs/util/parsevar.pl +++ b/pttbbs/util/parsevar.pl @@ -1,5 +1,5 @@ #!/usr/bin/perl -# $Id: parsevar.pl,v 1.2 2003/06/20 22:06:30 in2 Exp $ +# $Id$ print << '.'; /* * This header file is auto-generated from pttbbs/mbbsd/var.c . @@ -16,7 +16,7 @@ while( <> ){ $_ = substr($_, 0, index($_, '=') - 1) if( index($_, '=') != -1 ); $_ .= ';' if( index($_, ';') == -1 ); print "extern $_\n"; - } elsif( /^\#/ && !/include/ ){ + } elsif( /^\s*\#/ && !/include/ ){ print; } } -- cgit v1.2.3 From 444afef085b3b4dbb9086a8e152054be00587152 Mon Sep 17 00:00:00 2001 From: victor <victor@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Mon, 18 Aug 2003 12:08:25 +0000 Subject: do not allow querying money of article git-svn-id: http://opensvn.csie.org/pttbbs/trunk@1108 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/bbs.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pttbbs/mbbsd/bbs.c b/pttbbs/mbbsd/bbs.c index 3aaae9c2..50a5eee3 100644 --- a/pttbbs/mbbsd/bbs.c +++ b/pttbbs/mbbsd/bbs.c @@ -1,4 +1,4 @@ -/* $Id: bbs.c,v 1.104 2003/07/20 00:55:34 in2 Exp $ */ +/* $Id$ */ #include "bbs.h" static int recommend(int ent, fileheader_t * fhdr, char *direct); @@ -1488,6 +1488,10 @@ static int view_postmoney(int ent, fileheader_t * fhdr, char *direct) { move(b_lines - 1, 0); + if(currmode & MODE_SELECT){ + vmsg("請在離開目前的選擇模式再查詢"); + return FULLUPDATE; + } clrtoeol(); prints("這一篇文章值 %d 銀", fhdr->money); refresh(); -- cgit v1.2.3 From f2727d82e5c05d62ec618f72316f298def7b4f52 Mon Sep 17 00:00:00 2001 From: victor <victor@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Tue, 19 Aug 2003 07:59:14 +0000 Subject: paste taged file across board and mailbox git-svn-id: http://opensvn.csie.org/pttbbs/trunk@1109 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/announce.c | 18 ++++++++++++++---- pttbbs/mbbsd/mail.c | 2 +- pttbbs/mbbsd/read.c | 11 ++++++++--- pttbbs/mbbsd/var.c | 4 +++- 4 files changed, 26 insertions(+), 9 deletions(-) diff --git a/pttbbs/mbbsd/announce.c b/pttbbs/mbbsd/announce.c index 92b89d7f..4dc5438e 100644 --- a/pttbbs/mbbsd/announce.c +++ b/pttbbs/mbbsd/announce.c @@ -1,4 +1,4 @@ -/* $Id: announce.c,v 1.31 2003/07/20 00:55:34 in2 Exp $ */ +/* $Id$ */ #include "bbs.h" #define PATHLEN 256 @@ -438,11 +438,18 @@ static int a_pastetagpost(menu_t * pm, int mode) { fileheader_t fhdr; + boardheader_t *bh; int ans = 0, ent = 0, tagnum; char title[TTLEN + 1] = "◇ "; char dirname[200], buf[200]; - setbdir(dirname, currboard); + if (TagBoard == 0){ + sethomedir(dirname, cuser.userid); + } + else{ + bh = getbcache(TagBoard); + setbdir(dirname, bh->brdname); + } tagnum = TagNum; if (!tagnum) @@ -450,7 +457,10 @@ a_pastetagpost(menu_t * pm, int mode) while (tagnum--) { EnumTagFhdr(&fhdr, dirname, ent++); - setbfile(buf, currboard, fhdr.filename); + if (TagBoard == 0) + sethomefile(buf, cuser.userid, fhdr.filename); + else + setbfile(buf, bh->brdname, fhdr.filename); if (dashf(buf)) { strncpy(title + 3, fhdr.title, TTLEN - 3); @@ -464,7 +474,7 @@ a_pastetagpost(menu_t * pm, int mode) ++ans; UnTagger(tagnum); } - }; + } return ans; } diff --git a/pttbbs/mbbsd/mail.c b/pttbbs/mbbsd/mail.c index ff434498..52c8884c 100644 --- a/pttbbs/mbbsd/mail.c +++ b/pttbbs/mbbsd/mail.c @@ -1,4 +1,4 @@ -/* $Id: mail.c,v 1.28 2003/07/20 00:55:34 in2 Exp $ */ +/* $Id$ */ #include "bbs.h" char currmaildir[32]; static char msg_cc[] = "\033[32m[群組名單]\033[m\n"; diff --git a/pttbbs/mbbsd/read.c b/pttbbs/mbbsd/read.c index 9cc2c398..d6260e12 100644 --- a/pttbbs/mbbsd/read.c +++ b/pttbbs/mbbsd/read.c @@ -720,6 +720,14 @@ i_read_key(onekey_t * rcmdlist, keeploc_t * locmem, int ch, int bid) /* rocker.011018: 採用新的tag模式 */ case 't': + /* 將原本在 Read() 裡面的 "TagNum = 0" 移至此處 */ + if (!(TagBoard == bid) && !(currstat & RMAIL && TagBoard == 0)) { + if (currstat & RMAIL) + TagBoard = 0; + else + TagBoard = bid; + TagNum = 0; + } /* rocker.011112: 解決再select mode標記文章的問題 */ if (Tagger(atoi(headers[locmem->crs_ln - locmem->top_ln].filename + 2), (currmode & MODE_SELECT) ? @@ -780,9 +788,6 @@ i_read(int cmdmode, char *direct, void (*dotitle) (), void (*doentry) (), onekey strlcpy(currdirect, direct, sizeof(currdirect)); mode = NEWDIRECT; - /* rocker.011018: 加入新的tag機制 */ - TagNum = 0; - do { /* 依據 mode 顯示 fileheader */ setutmpmode(cmdmode); diff --git a/pttbbs/mbbsd/var.c b/pttbbs/mbbsd/var.c index 7df518e5..9c2c443c 100644 --- a/pttbbs/mbbsd/var.c +++ b/pttbbs/mbbsd/var.c @@ -361,8 +361,10 @@ int brc_num; int brc_list[BRC_MAXNUM]; /* read.c */ -int TagNum; /* tag's number */ +int TagNum; /* tag's number */ TagItem TagList[MAXTAGS]; /* ascending list */ +int TagBoard = -1; /* TagBoard = 0 : user's mailbox + TagBoard > 0 : bid where last taged*/ char currdirect[64]; /* edit.c */ -- cgit v1.2.3 From 25a637b9b0ed04b0d284ffd342fa552ccff3112e Mon Sep 17 00:00:00 2001 From: victor <victor@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Tue, 19 Aug 2003 08:54:43 +0000 Subject: fix last commit bug git-svn-id: http://opensvn.csie.org/pttbbs/trunk@1110 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/read.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pttbbs/mbbsd/read.c b/pttbbs/mbbsd/read.c index d6260e12..009b6912 100644 --- a/pttbbs/mbbsd/read.c +++ b/pttbbs/mbbsd/read.c @@ -721,7 +721,8 @@ i_read_key(onekey_t * rcmdlist, keeploc_t * locmem, int ch, int bid) /* rocker.011018: 採用新的tag模式 */ case 't': /* 將原本在 Read() 裡面的 "TagNum = 0" 移至此處 */ - if (!(TagBoard == bid) && !(currstat & RMAIL && TagBoard == 0)) { + if ((currstat & RMAIL && TagBoard != 0) || + (!(currstat & RMAIL) && TagBoard != bid)) { if (currstat & RMAIL) TagBoard = 0; else -- cgit v1.2.3 From 2aee618ec1a61abaebf38ed43e196c1a588aeb2d Mon Sep 17 00:00:00 2001 From: victor <victor@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Wed, 20 Aug 2003 14:38:56 +0000 Subject: for vary OS git-svn-id: http://opensvn.csie.org/pttbbs/trunk@1111 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/shmctl.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pttbbs/util/shmctl.c b/pttbbs/util/shmctl.c index 1eb33bd1..750f0763 100644 --- a/pttbbs/util/shmctl.c +++ b/pttbbs/util/shmctl.c @@ -541,11 +541,14 @@ struct { {SHMinit, "SHMinit", "initialize SHM (including uhash_loader)"}, {NULL, NULL, NULL} }; +extern char ** environ; + int main(int argc, char **argv) { int i = 0; chdir(BBSHOME); + initsetproctitle(argc, argv, environ); if( argc >= 2 ){ if( strcmp(argv[1], "init") == 0 ){ /* in this case, do NOT run attach_SHM here. -- cgit v1.2.3 From 7f4935bd59390a56270281c3bbd2cf57000423a0 Mon Sep 17 00:00:00 2001 From: victor <victor@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Wed, 20 Aug 2003 15:51:45 +0000 Subject: prevent opening file error git-svn-id: http://opensvn.csie.org/pttbbs/trunk@1112 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/gamble.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/pttbbs/mbbsd/gamble.c b/pttbbs/mbbsd/gamble.c index eb42d085..4e2f348f 100644 --- a/pttbbs/mbbsd/gamble.c +++ b/pttbbs/mbbsd/gamble.c @@ -291,13 +291,15 @@ openticket(int bid) while (fscanf(fp1, "%s %d %d\n", userid, &mybet, &i) != EOF) { if (bet == 98 && mybet >= 0 && mybet < count) { - fprintf(fp, "%s 買了 %d 張 %s, 退回 %d 枚P幣\n" - ,userid, i, betname[mybet], money * i); + if (fp) + fprintf(fp, "%s 買了 %d 張 %s, 退回 %d 枚P幣\n" + ,userid, i, betname[mybet], money * i); snprintf(buf, sizeof(buf), "%s 賭場退錢! $ %d", bh->brdname, money * i); } else if (mybet == bet) { - fprintf(fp, "恭喜 %s 買了%d 張 %s, 獲得 %d 枚P幣\n" - ,userid, i, betname[mybet], money * i); + if (fp) + fprintf(fp, "恭喜 %s 買了%d 張 %s, 獲得 %d 枚P幣\n" + ,userid, i, betname[mybet], money * i); snprintf(buf, sizeof(buf), "%s 中獎咧! $ %d", bh->brdname, money * i); } else continue; @@ -308,7 +310,8 @@ openticket(int bid) } fclose(fp1); } - fclose(fp); + if (fp) + fclose(fp); if (bet != 98) snprintf(buf, sizeof(buf), "[公告] %s 賭盤開獎", bh->brdname); -- cgit v1.2.3 From 4af22b063f805bfb4f2c0e34b47b459904aba610 Mon Sep 17 00:00:00 2001 From: "(no author)" <(no author)@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Fri, 22 Aug 2003 07:11:12 +0000 Subject: register git-svn-id: http://opensvn.csie.org/pttbbs/trunk@1121 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/user.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pttbbs/mbbsd/user.c b/pttbbs/mbbsd/user.c index c55b1335..124d08ed 100644 --- a/pttbbs/mbbsd/user.c +++ b/pttbbs/mbbsd/user.c @@ -1079,7 +1079,7 @@ static char *isvalidname(char *rname) char *rejectstr[] = {"肥", "胖", "豬頭", "小白", "小明", "路人", "老王", "老李", "寶貝", "先生", "師哥", "老頭", "小姊", "小姐", "美女", "小妹", "大頭", - "公主", "同學", "寶寶", "公子", "大頭", NULL}; + "公主", "同學", "寶寶", "公子", "大頭", "小小", "小弟", "小妹", NULL}; if( removespace(rname) && rname[0] < 0 && strlen(rname) >= 4 && !HaveRejectStr(rname, rejectstr) && -- cgit v1.2.3 From 1423cfc70e613ed1e97cba4faa83f26ec6d32eb1 Mon Sep 17 00:00:00 2001 From: victor <victor@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Fri, 22 Aug 2003 08:20:54 +0000 Subject: merge from my branch git-svn-id: http://opensvn.csie.org/pttbbs/trunk@1124 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/chc_draw.c | 18 +++--- pttbbs/mbbsd/chc_play.c | 159 ++++++++++++++++++++++++++++++------------------ pttbbs/mbbsd/talk.c | 23 ++++--- pttbbs/mbbsd/var.c | 1 - 4 files changed, 126 insertions(+), 75 deletions(-) diff --git a/pttbbs/mbbsd/chc_draw.c b/pttbbs/mbbsd/chc_draw.c index a3cda935..2cca2f19 100644 --- a/pttbbs/mbbsd/chc_draw.c +++ b/pttbbs/mbbsd/chc_draw.c @@ -1,4 +1,4 @@ -/* $Id: chc_draw.c,v 1.5 2002/12/31 17:40:51 in2 Exp $ */ +/* $Id$ */ #include "bbs.h" #define SIDE_ROW 10 @@ -99,7 +99,7 @@ showstep(board_t board) } void -chc_drawline(board_t board, int line) +chc_drawline(board_t board, chcusr_t *user1, chcusr_t *user2, int line) { int i, j; @@ -107,7 +107,7 @@ chc_drawline(board_t board, int line) clrtoeol(); if (line == 0) { prints("\033[1;46m 象棋對戰 \033[45m%30s VS %-30s\033[m", - cuser.userid, chc_mateid); + user1->userid, user2->userid); } else if (line >= 3 && line <= 21) { outs(" "); for (i = 0; i < 9; i++) { @@ -152,15 +152,15 @@ chc_drawline(board_t board, int line) "\033[1;31m%2d\033[37m勝 " "\033[34m%2d\033[37m敗 " "\033[36m%2d\033[37m和\033[m", - cuser.userid, - cuser.chc_win, cuser.chc_lose - 1, cuser.chc_tie); + user1->userid, + user1->win, user1->lose - 1, user1->tie); } else if (line == HISWIN_ROW) { prints("\033[1;33m%12.12s " "\033[1;31m%2d\033[37m勝 " "\033[34m%2d\033[37m敗 " "\033[36m%2d\033[37m和\033[m", - chc_mateid, - chc_hiswin, chc_hislose - 1, chc_histie); + user2->userid, + user2->win, user2->lose - 1, user2->tie); } } else if (line == 2 || line == 22) { outs(" "); @@ -174,10 +174,10 @@ chc_drawline(board_t board, int line) } void -chc_redraw(board_t board) +chc_redraw(chcusr_t *user1, chcusr_t *user2, board_t board) { int i; for (i = 0; i <= 22; i++) - chc_drawline(board, i); + chc_drawline(board, user1, user2, i); } diff --git a/pttbbs/mbbsd/chc_play.c b/pttbbs/mbbsd/chc_play.c index 08eead20..d6a714cf 100644 --- a/pttbbs/mbbsd/chc_play.c +++ b/pttbbs/mbbsd/chc_play.c @@ -1,6 +1,6 @@ -/* $Id: chc_play.c,v 1.7 2002/11/16 13:41:07 kcwu Exp $ */ +/* $Id$ */ #include "bbs.h" -typedef int (*play_func_t) (int, board_t, board_t); +typedef int (*play_func_t) (int, chcusr_t *, chcusr_t *, board_t, board_t); static int chc_ipass = 0, chc_hepass = 0; @@ -13,8 +13,25 @@ static int chc_ipass = 0, chc_hepass = 0; #define MYWIN_ROW 17 #define HISWIN_ROW 18 +static void +chcusr_put(userec_t *userec, chcusr_t *user) +{ + userec->chc_win = user->win; + userec->chc_lose = user->lose; + userec->chc_tie = user->tie; +} + +static void +chcusr_get(userec_t *userec, chcusr_t *user) +{ + strlcpy(user->userid, userec->userid, sizeof(user->userid)); + user->win = userec->chc_win; + user->lose = userec->chc_lose; + user->tie = userec->chc_tie; +} + static int -hisplay(int s, board_t board, board_t tmpbrd) +hisplay(int s, chcusr_t *user1, chcusr_t *user2, board_t board, board_t tmpbrd) { int start_time; int endgame = 0, endturn = 0; @@ -29,7 +46,7 @@ hisplay(int s, board_t board, board_t tmpbrd) chc_from.r = -2; chc_sendmove(s); } - chc_drawline(board, TIME_ROW); + chc_drawline(board, user1, user2, TIME_ROW); move(1, 0); oflush(); switch (igetkey()) { @@ -53,7 +70,7 @@ hisplay(int s, board_t board, board_t tmpbrd) if (chc_from.r == -1) { chc_hepass = 1; strlcpy(chc_warnmsg, "\033[1;33m要求和局!\033[m", sizeof(chc_warnmsg)); - chc_drawline(board, WARN_ROW); + chc_drawline(board, user1, user2, WARN_ROW); } else { chc_from.r = 9 - chc_from.r, chc_from.c = 8 - chc_from.c; chc_to.r = 9 - chc_to.r, chc_to.c = 8 - chc_to.c; @@ -62,10 +79,10 @@ hisplay(int s, board_t board, board_t tmpbrd) endgame = 2; endturn = 1; chc_hepass = 0; - chc_drawline(board, STEP_ROW); + chc_drawline(board, user1, user2, STEP_ROW); chc_movechess(board); - chc_drawline(board, LTR(chc_from.r)); - chc_drawline(board, LTR(chc_to.r)); + chc_drawline(board, user1, user2, LTR(chc_from.r)); + chc_drawline(board, user1, user2, LTR(chc_to.r)); } } break; @@ -75,7 +92,7 @@ hisplay(int s, board_t board, board_t tmpbrd) } static int -myplay(int s, board_t board, board_t tmpbrd) +myplay(int s, chcusr_t *user1, chcusr_t *user2, board_t board, board_t tmpbrd) { int ch, start_time; int endgame = 0, endturn = 0; @@ -85,7 +102,7 @@ myplay(int s, board_t board, board_t tmpbrd) chc_lefttime = CHC_TIMEOUT - (now - start_time); bell(); while (!endturn) { - chc_drawline(board, TIME_ROW); + chc_drawline(board, user1, user2, TIME_ROW); chc_movecur(chc_cursor.r, chc_cursor.c); oflush(); ch = igetkey(); @@ -131,7 +148,7 @@ myplay(int s, board_t board, board_t tmpbrd) chc_from.r = -1; chc_sendmove(s); strlcpy(chc_warnmsg, "\033[1;33m要求和棋!\033[m", sizeof(chc_warnmsg)); - chc_drawline(board, WARN_ROW); + chc_drawline(board, user1, user2, WARN_ROW); bell(); break; case '\r': @@ -141,7 +158,7 @@ myplay(int s, board_t board, board_t tmpbrd) if (chc_cursor.r == chc_select.r && chc_cursor.c == chc_select.c) { chc_selected = 0; - chc_drawline(board, LTR(chc_cursor.r)); + chc_drawline(board, user1, user2, LTR(chc_cursor.r)); } else if (chc_canmove(board, chc_select, chc_cursor)) { if (CHE_P(board[chc_cursor.r][chc_cursor.c]) == 1) endgame = 1; @@ -152,24 +169,24 @@ myplay(int s, board_t board, board_t tmpbrd) chc_movechess(tmpbrd); } if (endgame || !chc_iskfk(tmpbrd)) { - chc_drawline(board, STEP_ROW); + chc_drawline(board, user1, user2, STEP_ROW); chc_movechess(board); chc_sendmove(s); chc_selected = 0; - chc_drawline(board, LTR(chc_from.r)); - chc_drawline(board, LTR(chc_to.r)); + chc_drawline(board, user1, user2, LTR(chc_from.r)); + chc_drawline(board, user1, user2, LTR(chc_to.r)); endturn = 1; } else { strlcpy(chc_warnmsg, "\033[1;33m不可以王見王\033[m", sizeof(chc_warnmsg)); bell(); - chc_drawline(board, WARN_ROW); + chc_drawline(board, user1, user2, WARN_ROW); } } } else if (board[chc_cursor.r][chc_cursor.c] && CHE_O(board[chc_cursor.r][chc_cursor.c]) == chc_turn) { chc_selected = 1; chc_select = chc_cursor; - chc_drawline(board, LTR(chc_cursor.r)); + chc_drawline(board, user1, user2, LTR(chc_cursor.r)); } break; } @@ -178,91 +195,117 @@ myplay(int s, board_t board, board_t tmpbrd) } static void -mainloop(int s, board_t board) +mainloop(int s, chcusr_t *user1, chcusr_t *user2, board_t board, play_func_t play_func[2]) { int endgame; board_t tmpbrd; - play_func_t play_func[2]; play_func[chc_my] = myplay; - play_func[chc_my ^ 1] = hisplay; + if(s != 0) + play_func[chc_my ^ 1] = hisplay; + else /* 跟自己下棋 */ + play_func[chc_my ^ 1] = myplay; + for (chc_turn = 1, endgame = 0; !endgame; chc_turn ^= 1) { chc_firststep = 0; - chc_drawline(board, TURN_ROW); + chc_drawline(board, user1, user2, TURN_ROW); if (chc_ischeck(board, chc_turn)) { strlcpy(chc_warnmsg, "\033[1;31m將軍!\033[m", sizeof(chc_warnmsg)); bell(); } else chc_warnmsg[0] = 0; - chc_drawline(board, WARN_ROW); - endgame = play_func[chc_turn] (s, board, tmpbrd); + chc_drawline(board, user1, user2, WARN_ROW); + endgame = play_func[chc_turn] (s, user1, user2, board, tmpbrd); } - if (endgame == 1) { - strlcpy(chc_warnmsg, "對方認輸了!", sizeof(chc_warnmsg)); - cuser.chc_win++; - currutmp->chc_win++; - } else if (endgame == 2) { - strlcpy(chc_warnmsg, "你認輸了!", sizeof(chc_warnmsg)); - cuser.chc_lose++; - currutmp->chc_lose++; - } else { - strlcpy(chc_warnmsg, "和棋", sizeof(chc_warnmsg)); - cuser.chc_tie++; - currutmp->chc_tie++; + if (s != 0) { + if (endgame == 1) { + strlcpy(chc_warnmsg, "對方認輸了!", sizeof(chc_warnmsg)); + user1->win++; + currutmp->chc_win++; + } else if (endgame == 2) { + strlcpy(chc_warnmsg, "你認輸了!", sizeof(chc_warnmsg)); + user1->lose++; + currutmp->chc_lose++; + } else { + strlcpy(chc_warnmsg, "和棋", sizeof(chc_warnmsg)); + user1->tie++; + currutmp->chc_tie++; + } + } + else { + strlcpy(chc_warnmsg, "結束打譜", sizeof(chc_warnmsg)); } - cuser.chc_lose--; + user1->lose--; + + // if not watching + chcusr_put(&cuser, user1); passwd_update(usernum, &cuser); - chc_drawline(board, WARN_ROW); + chc_drawline(board, user1, user2, WARN_ROW); bell(); oflush(); } static void -chc_init(int s, board_t board) +chc_init(int s, chcusr_t *user1, chcusr_t *user2, board_t board) { userinfo_t *my = currutmp; setutmpmode(CHC); clear(); chc_warnmsg[0] = 0; - chc_my = my->turn; - chc_mateid = my->mateid; + if(s != 0){ // XXX mateid -> user2 + chc_my = my->turn; + chc_mateid = my->mateid; + } + else{ + chc_my = 1; + chc_mateid = cuser.userid; + } chc_firststep = 1; chc_init_board(board); - chc_redraw(board); + chc_redraw(user1, user2, board); chc_cursor.r = 9, chc_cursor.c = 0; add_io(s, 0); - if (my->turn) + if (my->turn) chc_recvmove(s); - passwd_query(usernum, &xuser); - cuser.chc_win = xuser.chc_win; - cuser.chc_lose = xuser.chc_lose + 1; - cuser.chc_tie = xuser.chc_tie; - cuser.money = xuser.money; - passwd_update(usernum, &cuser); - getuser(chc_mateid); - chc_hiswin = xuser.chc_win; - chc_hislose = xuser.chc_lose; - chc_histie = xuser.chc_tie; + user1->lose++; + // if not watching + passwd_query(usernum, &xuser); + chcusr_put(&xuser, user1); + passwd_update(usernum, &xuser); if (!my->turn) { chc_sendmove(s); - chc_hislose++; + user2->lose++; } - chc_redraw(board); + chc_redraw(user1, user2, board); +} + +static void +chc_userinit(char *userid1, char *userid2, chcusr_t *user1, chcusr_t *user2, play_func_t play_func[2]) +{ + getuser(userid1); + chcusr_get(&xuser, user2); + + getuser(userid2); + chcusr_get(&xuser, user2); } void -chc(int s) +chc(int s, int type) { board_t board; + chcusr_t user1, user2; + play_func_t play_func[2]; - chc_init(s, board); - mainloop(s, board); - close(s); + chc_userinit(cuser.userid, currutmp->mateid, &user1, &user2, play_func); + chc_init(s, &user1, &user2, board); + mainloop(s, &user1, &user2, board, play_func); + if (type == CHC_VERSUS) + close(s); add_io(0, 0); if (chc_my) pressanykey(); diff --git a/pttbbs/mbbsd/talk.c b/pttbbs/mbbsd/talk.c index 8246801b..e94bd9f4 100644 --- a/pttbbs/mbbsd/talk.c +++ b/pttbbs/mbbsd/talk.c @@ -1,4 +1,4 @@ -/* $Id: talk.c,v 1.112 2003/07/19 01:26:33 in2 Exp $ */ +/* $Id$ */ #include "bbs.h" #define QCAST int (*)(const void *, const void *) @@ -1292,7 +1292,7 @@ my_talk(userinfo_t * uin, int fri_stat) gomoku(msgsock); break; case SIG_CHC: - chc(msgsock); + chc(msgsock, CHC_VERSUS); break; case SIG_TALK: default: @@ -1345,6 +1345,12 @@ my_talk(userinfo_t * uin, int fri_stat) pressanykey(); } +static void +self_play(userinfo_t * uin, int fri_stat) +{ + chc(0, CHC_PERSONAL); +} + /* 選單式聊天介面 */ #define US_PICKUP 1234 #define US_RESORT 1233 @@ -2195,14 +2201,17 @@ userlist(void) case 't': if (HAS_PERM(PERM_LOGINOK)) { + move(1, 0); + clrtobot(); + move(3, 0); if (uentp->pid != currpid && strcmp(uentp->userid, cuser.userid) != 0) { - move(1, 0); - clrtobot(); - move(3, 0); my_talk(uentp, fri_stat); - redrawall = redraw = 1; } + else{ + self_play(uentp, fri_stat); + } + redrawall = redraw = 1; } break; case 'K': @@ -2605,7 +2614,7 @@ talkreply(void) gomoku(a); break; case SIG_CHC: - chc(a); + chc(a, CHC_VERSUS); break; case SIG_TALK: default: diff --git a/pttbbs/mbbsd/var.c b/pttbbs/mbbsd/var.c index 9c2c443c..277bef8d 100644 --- a/pttbbs/mbbsd/var.c +++ b/pttbbs/mbbsd/var.c @@ -390,7 +390,6 @@ rc_t chc_from, chc_to, chc_select, chc_cursor; int chc_lefttime; int chc_my, chc_turn, chc_selected, chc_firststep; char chc_warnmsg[64], *chc_mateid; -int chc_hiswin, chc_hislose, chc_histie; /* screen.c */ screenline_t *big_picture = NULL; -- cgit v1.2.3 From cbcbd2d01d2fa76ea963d9a823abc95b01e5a576 Mon Sep 17 00:00:00 2001 From: victor <victor@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Fri, 22 Aug 2003 08:24:17 +0000 Subject: merge from my branch git-svn-id: http://opensvn.csie.org/pttbbs/trunk@1125 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/include/modes.h | 7 ++++++- pttbbs/include/proto.h | 6 +++--- pttbbs/include/pttstruct.h | 10 +++++++++- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/pttbbs/include/modes.h b/pttbbs/include/modes.h index 3606cb1a..a70e7047 100644 --- a/pttbbs/include/modes.h +++ b/pttbbs/include/modes.h @@ -1,4 +1,4 @@ -/* $Id: modes.h,v 1.3 2003/05/26 05:23:13 in2 Exp $ */ +/* $Id$ */ #ifndef INCLUDE_MODES_H #define INCLUDE_MODES_H @@ -97,6 +97,11 @@ #define REEDIT 79 #define BLOGGING 80 +/* 象棋 */ +#define CHC_VERSUS 0 /* 雙人 */ +#define CHC_WATCH 1 /* 觀棋 */ +#define CHC_PERSONAL 2 /* 打譜 */ + /* menu.c 中的模式 */ #define QUIT 0x666 /* Return value to abort recursive functions */ #define XEASY 0x333 /* Return value to un-redraw screen */ diff --git a/pttbbs/include/proto.h b/pttbbs/include/proto.h index 5e902289..84db664c 100644 --- a/pttbbs/include/proto.h +++ b/pttbbs/include/proto.h @@ -165,16 +165,16 @@ int card_99(); int t_chat(); /* chc_draw */ -void chc_drawline(board_t board, int line); +void chc_drawline(board_t board, chcusr_t *user1, chcusr_t *user2, int line); void chc_movecur(int r, int c); -void chc_redraw(board_t board); +void chc_redraw(chcusr_t *user1, chcusr_t *user2, board_t board); /* chc_net */ void chc_sendmove(int s); int chc_recvmove(int s); /* chc_play */ -void chc(int s); +void chc(int s, int mode); /* chc_rule */ void chc_movechess(board_t board); diff --git a/pttbbs/include/pttstruct.h b/pttbbs/include/pttstruct.h index 2401c26b..1cb59f85 100644 --- a/pttbbs/include/pttstruct.h +++ b/pttbbs/include/pttstruct.h @@ -1,4 +1,4 @@ -/* $Id: pttstruct.h,v 1.43 2003/07/20 00:55:34 in2 Exp $ */ +/* $Id$ */ #ifndef INCLUDE_STRUCT_H #define INCLUDE_STRUCT_H @@ -425,4 +425,12 @@ typedef struct int recno; } TagItem; +/* 象棋 */ +typedef struct chcusr_t{ + char userid[IDLEN + 1]; + int uid; + int win; + int lose; + int tie; +} chcusr_t; #endif -- cgit v1.2.3 From 409daa963f7af0cacdddda9ef21211997cb085d7 Mon Sep 17 00:00:00 2001 From: victor <victor@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Fri, 22 Aug 2003 08:45:01 +0000 Subject: fix last commit bug git-svn-id: http://opensvn.csie.org/pttbbs/trunk@1126 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/chc_play.c | 2 +- pttbbs/mbbsd/talk.c | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/pttbbs/mbbsd/chc_play.c b/pttbbs/mbbsd/chc_play.c index d6a714cf..36992ae8 100644 --- a/pttbbs/mbbsd/chc_play.c +++ b/pttbbs/mbbsd/chc_play.c @@ -288,7 +288,7 @@ static void chc_userinit(char *userid1, char *userid2, chcusr_t *user1, chcusr_t *user2, play_func_t play_func[2]) { getuser(userid1); - chcusr_get(&xuser, user2); + chcusr_get(&xuser, user1); getuser(userid2); chcusr_get(&xuser, user2); diff --git a/pttbbs/mbbsd/talk.c b/pttbbs/mbbsd/talk.c index e94bd9f4..3e2e4b39 100644 --- a/pttbbs/mbbsd/talk.c +++ b/pttbbs/mbbsd/talk.c @@ -1348,7 +1348,9 @@ my_talk(userinfo_t * uin, int fri_stat) static void self_play(userinfo_t * uin, int fri_stat) { - chc(0, CHC_PERSONAL); + move(1, 2); + if (getans("[象棋] 你確定要打譜嗎?[N/y]") == 'y') + chc(0, CHC_PERSONAL); } /* 選單式聊天介面 */ -- cgit v1.2.3 From 1c27289be6d13d5758c5ec40c943ce7c90ef7c46 Mon Sep 17 00:00:00 2001 From: "(no author)" <(no author)@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sat, 23 Aug 2003 10:40:36 +0000 Subject: fix typo git-svn-id: http://opensvn.csie.org/pttbbs/trunk@1132 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/sample/crontab | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pttbbs/sample/crontab b/pttbbs/sample/crontab index 5cda4092..3eb4c4f3 100644 --- a/pttbbs/sample/crontab +++ b/pttbbs/sample/crontab @@ -97,7 +97,7 @@ 30 3 * * * bin/dailybackup.pl # 每日砍除 ALLPOST -30 5 * * * /bin/rm boards/A/ALLPOST; mkdir bords/A/ALLPOST +30 5 * * * /bin/rm boards/A/ALLPOST; mkdir boards/A/ALLPOST # utmpfix 0 2-20 * * * bin/shmctl utmpfix -n -- cgit v1.2.3 From c532c77faf0cbe0b289102e4d853adff0890e25c Mon Sep 17 00:00:00 2001 From: victor <victor@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Thu, 28 Aug 2003 02:27:47 +0000 Subject: It's not necessary to reload friend and eject list at the same time. git-svn-id: http://opensvn.csie.org/pttbbs/trunk@1134 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/friend.c | 59 +++++----- pttbbs/mbbsd/mbbsd.c | 2 +- pttbbs/mbbsd/talk.c | 298 ++++++++++++++++++++++++++++---------------------- 3 files changed, 202 insertions(+), 157 deletions(-) diff --git a/pttbbs/mbbsd/friend.c b/pttbbs/mbbsd/friend.c index 127f9f5d..23d5f85f 100644 --- a/pttbbs/mbbsd/friend.c +++ b/pttbbs/mbbsd/friend.c @@ -1,4 +1,4 @@ -/* $Id: friend.c,v 1.19 2003/05/18 07:31:09 in2 Exp $ */ +/* $Id$ */ #include "bbs.h" /* ------------------------------------- */ @@ -258,7 +258,7 @@ friend_editdesc(char *uident, int type) } void -friend_load() +friend_load(int type) { FILE *fp; int myfriends[MAX_FRIEND]; @@ -266,33 +266,38 @@ friend_load() int friendcount, rejectedcount; char genbuf[200]; - memset(myfriends, 0, sizeof(myfriends)); - friendcount = 0; - setuserfile(genbuf, fn_overrides); - if ((fp = fopen(genbuf, "r"))) { - int unum; - - while (fgets(genbuf, STRLEN, fp) && friendcount < MAX_FRIEND - 1) - if (strtok(genbuf, str_space)) - if ((unum = searchuser(genbuf))) - myfriends[friendcount++] = unum; - fclose(fp); + if (type & FRIEND_OVERRIDE) { + memset(myfriends, 0, sizeof(myfriends)); + friendcount = 0; + setuserfile(genbuf, fn_overrides); + if ((fp = fopen(genbuf, "r"))) { + int unum; + + while (fgets(genbuf, STRLEN, fp) && friendcount < MAX_FRIEND - 1) + if (strtok(genbuf, str_space)) + if ((unum = searchuser(genbuf))) + myfriends[friendcount++] = unum; + fclose(fp); + } + memcpy(currutmp->friend, myfriends, sizeof(myfriends)); } - memcpy(currutmp->friend, myfriends, sizeof(myfriends)); - - memset(myrejects, 0, sizeof(myrejects)); - rejectedcount = 0; - setuserfile(genbuf, fn_reject); - if ((fp = fopen(genbuf, "r"))) { - int unum; - - while (fgets(genbuf, STRLEN, fp) && rejectedcount < MAX_REJECT - 1) - if (strtok(genbuf, str_space)) - if ((unum = searchuser(genbuf))) - myrejects[rejectedcount++] = unum; - fclose(fp); + + if (type & FRIEND_EJECT) { + memset(myrejects, 0, sizeof(myrejects)); + rejectedcount = 0; + setuserfile(genbuf, fn_reject); + if ((fp = fopen(genbuf, "r"))) { + int unum; + + while (fgets(genbuf, STRLEN, fp) && rejectedcount < MAX_REJECT - 1) + if (strtok(genbuf, str_space)) + if ((unum = searchuser(genbuf))) + myrejects[rejectedcount++] = unum; + fclose(fp); + } + memcpy(currutmp->reject, myrejects, sizeof(myrejects)); } - memcpy(currutmp->reject, myrejects, sizeof(myrejects)); + if (currutmp->friendtotal) logout_friend_online(currutmp); login_friend_online(); diff --git a/pttbbs/mbbsd/mbbsd.c b/pttbbs/mbbsd/mbbsd.c index f4026102..660bdb80 100644 --- a/pttbbs/mbbsd/mbbsd.c +++ b/pttbbs/mbbsd/mbbsd.c @@ -753,7 +753,7 @@ setup_utmp(int mode) if (!(cuser.numlogins % 20) && cuser.userlevel & PERM_BM) check_BM(); /* Ptt 自動取下離職板主權力 */ #ifndef _BBS_UTIL_C_ - friend_load(); + friend_load(FRIEND_OVERRIDE | FRIEND_EJECT); nice(3); #endif } diff --git a/pttbbs/mbbsd/talk.c b/pttbbs/mbbsd/talk.c index 3e2e4b39..8a21c6c5 100644 --- a/pttbbs/mbbsd/talk.c +++ b/pttbbs/mbbsd/talk.c @@ -1099,11 +1099,107 @@ do_talk(int fd) #define lockreturn(unmode, state) if(lockutmpmode(unmode, state)) return +int make_connection_to_somebody(userinfo_t *uin, int timeout){ + int sock, length, pid, ch; + struct sockaddr_in server; + + sock = socket(AF_INET, SOCK_STREAM, 0); + if (sock < 0) { + perror("sock err"); + unlockutmpmode(); + return -1; + } + server.sin_family = PF_INET; + server.sin_addr.s_addr = INADDR_ANY; + server.sin_port = 0; + if (bind(sock, (struct sockaddr *) & server, sizeof(server)) < 0) { + close(sock); + perror("bind err"); + unlockutmpmode(); + return -1; + } + length = sizeof(server); + if (getsockname(sock, (struct sockaddr *) & server, (socklen_t *) & length) < 0) { + close(sock); + perror("sock name err"); + unlockutmpmode(); + return -1; + } + currutmp->sockactive = YEA; + currutmp->sockaddr = server.sin_port; + currutmp->destuid = uin->uid; + setutmpmode(PAGE); + uin->destuip = currutmp - &SHM->uinfo[0]; + pid = uin->pid; + if (pid > 0) + kill(pid, SIGUSR1); + clear(); + prints("正呼叫 %s.....\n鍵入 Ctrl-D 中止....", uin->userid); + + listen(sock, 1); + add_io(sock, timeout); + + while (1) { + ch = igetch(); + if (ch == I_TIMEOUT) { + ch = uin->mode; + if (!ch && uin->chatid[0] == 1 && + uin->destuip == currutmp - &SHM->uinfo[0]) { + bell(); + outmsg("對方回應中..."); + refresh(); + } else if (ch == EDITING || ch == TALK || ch == CHATING || + ch == PAGE || ch == MAILALL || ch == MONITOR || + ch == M_FIVE || ch == CHC || + (!ch && (uin->chatid[0] == 1 || + uin->chatid[0] == 3))) { + add_io(0, 0); + close(sock); + currutmp->sockactive = currutmp->destuid = 0; + outmsg("人家在忙啦"); + pressanykey(); + unlockutmpmode(); + return -1; + } else { +#ifdef linux + add_io(sock, 20); /* added for linux... achen */ +#endif + move(0, 0); + outs("再"); + bell(); + + uin->destuip = currutmp - &SHM->uinfo[0]; + if (pid <= 0 || kill(pid, SIGUSR1) == -1) { +#ifdef linux + add_io(sock, 20); /* added 4 linux... achen */ +#endif + outmsg(msg_usr_left); + refresh(); + pressanykey(); + unlockutmpmode(); + return -1; + } + continue; + } + } + if (ch == I_OTHERDATA) + break; + + if (ch == '\004') { + add_io(0, 0); + close(sock); + currutmp->sockactive = currutmp->destuid = 0; + unlockutmpmode(); + return -1; + } + } + return sock; +} + static void my_talk(userinfo_t * uin, int fri_stat) { - int sock, msgsock, length, ch, error = 0; - struct sockaddr_in server; + int sock, msgsock, error = 0, ch; pid_t pid; char c; char genbuf[4]; @@ -1117,7 +1213,16 @@ my_talk(userinfo_t * uin, int fri_stat) ch == MAILALL || ch == MONITOR || ch == M_FIVE || ch == CHC || (!ch && (uin->chatid[0] == 1 || uin->chatid[0] == 3)) || uin->lockmode == M_FIVE || uin->lockmode == CHC) { - outs("人家在忙啦"); + if (ch == CHC) { + kill(uin->pid, SIGUSR1); + sock = make_connection_to_somebody(uin, 20); + if (sock < 0) + vmsg("無法建立連線"); + strlcpy(currutmp->mateid, uin->userid, sizeof(currutmp->mateid)); + chc(sock, CHC_WATCH); + } + else + outs("人家在忙啦"); } else if (!HAS_PERM(PERM_SYSOP) && (((fri_stat & HRM) && !(fri_stat & HFM)) || ((!uin->pager) && !(fri_stat & HFM)))) { @@ -1177,94 +1282,7 @@ my_talk(userinfo_t * uin, int fri_stat) strlcpy(uin->mateid, currutmp->userid, sizeof(uin->mateid)); strlcpy(currutmp->mateid, uin->userid, sizeof(currutmp->mateid)); - sock = socket(AF_INET, SOCK_STREAM, 0); - if (sock < 0) { - perror("sock err"); - unlockutmpmode(); - return; - } - server.sin_family = PF_INET; - server.sin_addr.s_addr = INADDR_ANY; - server.sin_port = 0; - if (bind(sock, (struct sockaddr *) & server, sizeof(server)) < 0) { - close(sock); - perror("bind err"); - unlockutmpmode(); - return; - } - length = sizeof(server); - if (getsockname(sock, (struct sockaddr *) & server, (socklen_t *) & length) < 0) { - close(sock); - perror("sock name err"); - unlockutmpmode(); - return; - } - currutmp->sockactive = YEA; - currutmp->sockaddr = server.sin_port; - currutmp->destuid = uin->uid; - setutmpmode(PAGE); - uin->destuip = currutmp - &SHM->uinfo[0]; - if (pid > 0) - kill(pid, SIGUSR1); - clear(); - prints("正呼叫 %s.....\n鍵入 Ctrl-D 中止....", uin->userid); - - listen(sock, 1); - add_io(sock, 5); - while (1) { - ch = igetch(); - if (ch == I_TIMEOUT) { - ch = uin->mode; - if (!ch && uin->chatid[0] == 1 && - uin->destuip == currutmp - &SHM->uinfo[0]) { - bell(); - outmsg("對方回應中..."); - refresh(); - } else if (ch == EDITING || ch == TALK || ch == CHATING || - ch == PAGE || ch == MAILALL || ch == MONITOR || - ch == M_FIVE || ch == CHC || - (!ch && (uin->chatid[0] == 1 || - uin->chatid[0] == 3))) { - add_io(0, 0); - close(sock); - currutmp->sockactive = currutmp->destuid = 0; - outmsg("人家在忙啦"); - pressanykey(); - unlockutmpmode(); - return; - } else { -#ifdef linux - add_io(sock, 20); /* added for linux... achen */ -#endif - move(0, 0); - outs("再"); - bell(); - - uin->destuip = currutmp - &SHM->uinfo[0]; - if (pid <= 0 || kill(pid, SIGUSR1) == -1) { -#ifdef linux - add_io(sock, 20); /* added 4 linux... achen */ -#endif - outmsg(msg_usr_left); - refresh(); - pressanykey(); - unlockutmpmode(); - return; - } - continue; - } - } - if (ch == I_OTHERDATA) - break; - - if (ch == '\004') { - add_io(0, 0); - close(sock); - currutmp->sockactive = currutmp->destuid = 0; - unlockutmpmode(); - return; - } - } + sock = make_connection_to_somebody(uin, 5); msgsock = accept(sock, (struct sockaddr *) 0, (socklen_t *) 0); if (msgsock == -1) { @@ -1348,7 +1366,6 @@ my_talk(userinfo_t * uin, int fri_stat) static void self_play(userinfo_t * uin, int fri_stat) { - move(1, 2); if (getans("[象棋] 你確定要打譜嗎?[N/y]") == 'y') chc(0, CHC_PERSONAL); } @@ -2229,7 +2246,7 @@ userlist(void) case 'a': if (HAS_PERM(PERM_LOGINOK)) { friend_add(uentp->userid, FRIEND_OVERRIDE,uentp->username); - friend_load(); + friend_load(FRIEND_OVERRIDE); redrawall = redraw = 1; } break; @@ -2237,7 +2254,7 @@ userlist(void) case 'd': if (HAS_PERM(PERM_LOGINOK)) { friend_delete(uentp->userid, FRIEND_OVERRIDE); - friend_load(); + friend_load(FRIEND_OVERRIDE); redrawall = redraw = 1; } break; @@ -2525,21 +2542,65 @@ t_talk() return 0; } +static int +reply_connection_request(userinfo_t *uip) +{ + int a; + char buf[4], genbuf[200]; + struct hostent *h; + struct sockaddr_in sin; + + if (uip->mode != PAGE) { + snprintf(genbuf, sizeof(genbuf), + "%s已停止呼叫,按Enter繼續...", page_requestor); + getdata(0, 0, genbuf, buf, sizeof(buf), LCECHO); + return -1; + } + currutmp->msgcount = 0; + strlcpy(save_page_requestor, page_requestor, sizeof(save_page_requestor)); + memset(page_requestor, 0, sizeof(page_requestor)); + if (!(h = gethostbyname("localhost"))) { + perror("gethostbyname"); + return -1; + } + memset(&sin, 0, sizeof(sin)); + sin.sin_family = h->h_addrtype; + memcpy(&sin.sin_addr, h->h_addr, h->h_length); + sin.sin_port = uip->sockaddr; + a = socket(sin.sin_family, SOCK_STREAM, 0); + if ((connect(a, (struct sockaddr *) & sin, sizeof(sin)))) { + perror("connect err"); + return -1; + } + return a; +} + +static void +chc_watch_request(int signo) +{ + if (!(currstat & CHC)) + return; + chc_act_list *tmp; + for(tmp = act_list; tmp->next != NULL; tmp = tmp->next); + tmp->next = (chc_act_list *)malloc(sizeof(chc_act_list)); + tmp = tmp->next; + tmp->sock = reply_connection_request(uip); + tmp->next = NULL; +} + /* 有人來串門子了,回應呼叫器 */ static userinfo_t *uip; void talkreply(void) { - struct hostent *h; char buf[4]; - struct sockaddr_in sin; char genbuf[200]; int a, sig = currutmp->sig; talkrequest = NA; uip = &SHM->uinfo[currutmp->destuip]; snprintf(page_requestor, sizeof(page_requestor), - "%s (%s)", uip->userid, uip->username); + "%s (%s)", uip->userid, uip->username); currutmp->destuid = uip->uid; currstat = REPLY; /* 避免出現動畫 */ @@ -2547,16 +2608,16 @@ talkreply(void) prints("\n\n"); prints(" (Y) 讓我們 %s 吧!" - " (A) 我現在很忙,請等一會兒再 call 我\n", sig_des[sig]); + " (A) 我現在很忙,請等一會兒再 call 我\n", sig_des[sig]); prints(" (N) 我現在不想 %s" - " (B) 對不起,我有事情不能跟你 %s\n", - sig_des[sig], sig_des[sig]); + " (B) 對不起,我有事情不能跟你 %s\n", + sig_des[sig], sig_des[sig]); prints(" (C) 請不要吵我好嗎?" - " (D) 我要離站囉..下次再聊吧.......\n"); + " (D) 我要離站囉..下次再聊吧.......\n"); prints(" (E) 有事嗎?請先來信" - " (F) \033[1;33m我自己輸入理由好了...\033[m\n"); + " (F) \033[1;33m我自己輸入理由好了...\033[m\n"); prints(" (1) %s?先拿100銀兩來" - " (2) %s?先拿1000銀兩來..\n\n", sig_des[sig], sig_des[sig]); + " (2) %s?先拿1000銀兩來..\n\n", sig_des[sig], sig_des[sig]); getuser(uip->userid); currutmp->msgs[0].pid = uip->pid; @@ -2564,37 +2625,16 @@ talkreply(void) strlcpy(currutmp->msgs[0].last_call_in, "呼叫、呼叫,聽到請回答 (Ctrl-R)", sizeof(currutmp->msgs[0].last_call_in)); prints("對方來自 [%s],共上站 %d 次,文章 %d 篇\n", - uip->from, xuser.numlogins, xuser.numposts); + uip->from, xuser.numlogins, xuser.numposts); showplans(uip->userid); show_call_in(0, 0); snprintf(genbuf, sizeof(genbuf), - "你想跟 %s %s啊?請選擇(Y/N/A/B/C/D/E/F/1/2)[N] ", - page_requestor, sig_des[sig]); + "你想跟 %s %s啊?請選擇(Y/N/A/B/C/D/E/F/1/2)[N] ", + page_requestor, sig_des[sig]); getdata(0, 0, genbuf, buf, sizeof(buf), LCECHO); + a = reply_connection_request(uip); - if (uip->mode != PAGE) { - snprintf(genbuf, sizeof(genbuf), - "%s已停止呼叫,按Enter繼續...", page_requestor); - getdata(0, 0, genbuf, buf, sizeof(buf), LCECHO); - return; - } - currutmp->msgcount = 0; - strlcpy(save_page_requestor, page_requestor, sizeof(save_page_requestor)); - memset(page_requestor, 0, sizeof(page_requestor)); - if (!(h = gethostbyname("localhost"))) { - perror("gethostbyname"); - return; - } - memset(&sin, 0, sizeof(sin)); - sin.sin_family = h->h_addrtype; - memcpy(&sin.sin_addr, h->h_addr, h->h_length); - sin.sin_port = uip->sockaddr; - a = socket(sin.sin_family, SOCK_STREAM, 0); - if ((connect(a, (struct sockaddr *) & sin, sizeof(sin)))) { - perror("connect err"); - return; - } if (!buf[0] || !strchr("yabcdef12", buf[0])) buf[0] = 'n'; write(a, buf, 1); @@ -2602,7 +2642,7 @@ talkreply(void) if (!getdata(b_lines, 0, "不能的原因:", genbuf, 60, DOECHO)) strlcpy(genbuf, "不告訴你咧 !! ^o^", sizeof(genbuf)); write(a, genbuf, 60); - } + uip->destuip = currutmp - &SHM->uinfo[0]; if (buf[0] == 'y') switch (sig) { -- cgit v1.2.3 From 543f462a14136e83b8f96f3c7d44f3b5d36cd2a2 Mon Sep 17 00:00:00 2001 From: victor <victor@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Thu, 28 Aug 2003 02:33:52 +0000 Subject: wrong spell and missing :P git-svn-id: http://opensvn.csie.org/pttbbs/trunk@1135 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/friend.c | 7 ++++--- pttbbs/mbbsd/mbbsd.c | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/pttbbs/mbbsd/friend.c b/pttbbs/mbbsd/friend.c index 23d5f85f..39ef2148 100644 --- a/pttbbs/mbbsd/friend.c +++ b/pttbbs/mbbsd/friend.c @@ -257,6 +257,7 @@ friend_editdesc(char *uident, int type) } } +/* type == 0 : load all */ void friend_load(int type) { @@ -266,7 +267,7 @@ friend_load(int type) int friendcount, rejectedcount; char genbuf[200]; - if (type & FRIEND_OVERRIDE) { + if (!type || type & FRIEND_OVERRIDE) { memset(myfriends, 0, sizeof(myfriends)); friendcount = 0; setuserfile(genbuf, fn_overrides); @@ -282,7 +283,7 @@ friend_load(int type) memcpy(currutmp->friend, myfriends, sizeof(myfriends)); } - if (type & FRIEND_EJECT) { + if (!type || type & FRIEND_REJECT) { memset(myrejects, 0, sizeof(myrejects)); rejectedcount = 0; setuserfile(genbuf, fn_reject); @@ -456,7 +457,7 @@ friend_edit(int type) fclose(fp); } } - friend_load(); + friend_load(0); } } diff --git a/pttbbs/mbbsd/mbbsd.c b/pttbbs/mbbsd/mbbsd.c index 660bdb80..69b84742 100644 --- a/pttbbs/mbbsd/mbbsd.c +++ b/pttbbs/mbbsd/mbbsd.c @@ -753,7 +753,7 @@ setup_utmp(int mode) if (!(cuser.numlogins % 20) && cuser.userlevel & PERM_BM) check_BM(); /* Ptt 自動取下離職板主權力 */ #ifndef _BBS_UTIL_C_ - friend_load(FRIEND_OVERRIDE | FRIEND_EJECT); + friend_load(0); nice(3); #endif } -- cgit v1.2.3 From 435e6af2a3e360b52dacfcdc6fbba4a7fda050d8 Mon Sep 17 00:00:00 2001 From: victor <victor@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Thu, 28 Aug 2003 02:39:45 +0000 Subject: shouldn't appear now @@ git-svn-id: http://opensvn.csie.org/pttbbs/trunk@1136 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/talk.c | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/pttbbs/mbbsd/talk.c b/pttbbs/mbbsd/talk.c index 8a21c6c5..7b08e203 100644 --- a/pttbbs/mbbsd/talk.c +++ b/pttbbs/mbbsd/talk.c @@ -2575,19 +2575,6 @@ reply_connection_request(userinfo_t *uip) return a; } -static void -chc_watch_request(int signo) -{ - if (!(currstat & CHC)) - return; - chc_act_list *tmp; - for(tmp = act_list; tmp->next != NULL; tmp = tmp->next); - tmp->next = (chc_act_list *)malloc(sizeof(chc_act_list)); - tmp = tmp->next; - tmp->sock = reply_connection_request(uip); - tmp->next = NULL; -} - /* 有人來串門子了,回應呼叫器 */ static userinfo_t *uip; void @@ -2642,6 +2629,7 @@ talkreply(void) if (!getdata(b_lines, 0, "不能的原因:", genbuf, 60, DOECHO)) strlcpy(genbuf, "不告訴你咧 !! ^o^", sizeof(genbuf)); write(a, genbuf, 60); + } uip->destuip = currutmp - &SHM->uinfo[0]; if (buf[0] == 'y') -- cgit v1.2.3 From 14a57a472a163fa51e7767329106054304dded26 Mon Sep 17 00:00:00 2001 From: "(no author)" <(no author)@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Thu, 28 Aug 2003 08:47:32 +0000 Subject: register git-svn-id: http://opensvn.csie.org/pttbbs/trunk@1137 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/user.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pttbbs/mbbsd/user.c b/pttbbs/mbbsd/user.c index 124d08ed..aac88c47 100644 --- a/pttbbs/mbbsd/user.c +++ b/pttbbs/mbbsd/user.c @@ -1079,7 +1079,9 @@ static char *isvalidname(char *rname) char *rejectstr[] = {"肥", "胖", "豬頭", "小白", "小明", "路人", "老王", "老李", "寶貝", "先生", "師哥", "老頭", "小姊", "小姐", "美女", "小妹", "大頭", - "公主", "同學", "寶寶", "公子", "大頭", "小小", "小弟", "小妹", NULL}; + "公主", "同學", "寶寶", "公子", "大頭", "小小", "小弟", "小妹", + "妹妹", "嘿", "嗯", + NULL}; if( removespace(rname) && rname[0] < 0 && strlen(rname) >= 4 && !HaveRejectStr(rname, rejectstr) && -- cgit v1.2.3 From b2069ca40e9c7dc42ee8dd98c6d64558decef207 Mon Sep 17 00:00:00 2001 From: "(no author)" <(no author)@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Thu, 28 Aug 2003 08:50:12 +0000 Subject: warning free git-svn-id: http://opensvn.csie.org/pttbbs/trunk@1138 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/admin.c | 4 ++-- pttbbs/mbbsd/announce.c | 2 +- pttbbs/mbbsd/mail.c | 2 +- pttbbs/mbbsd/record.c | 6 +++--- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/pttbbs/mbbsd/admin.c b/pttbbs/mbbsd/admin.c index ccc3fe89..99c87621 100644 --- a/pttbbs/mbbsd/admin.c +++ b/pttbbs/mbbsd/admin.c @@ -1,4 +1,4 @@ -/* $Id: admin.c,v 1.44 2003/06/28 08:51:14 kcwu Exp $ */ +/* $Id$ */ #include "bbs.h" /* 使用者管理 */ @@ -1083,7 +1083,7 @@ give_id_money(char *user_id, int money, FILE * log_fp, char *mail_title, time_t prints("id:%s money:%d 不對吧!!", user_id, money); pressanykey(); } else { - fprintf(log_fp, "%ld %s %d", t, user_id, money); + fprintf(log_fp, "%d %s %d", (int)t, user_id, money); snprintf(tt, sizeof(tt), "%s : %d ptt 幣", mail_title, money); mail_id(user_id, tt, "~bbs/etc/givemoney.why", "[PTT 銀行]"); } diff --git a/pttbbs/mbbsd/announce.c b/pttbbs/mbbsd/announce.c index 4dc5438e..c8f69baf 100644 --- a/pttbbs/mbbsd/announce.c +++ b/pttbbs/mbbsd/announce.c @@ -438,7 +438,7 @@ static int a_pastetagpost(menu_t * pm, int mode) { fileheader_t fhdr; - boardheader_t *bh; + boardheader_t *bh = NULL; int ans = 0, ent = 0, tagnum; char title[TTLEN + 1] = "◇ "; char dirname[200], buf[200]; diff --git a/pttbbs/mbbsd/mail.c b/pttbbs/mbbsd/mail.c index 52c8884c..84fa9c3e 100644 --- a/pttbbs/mbbsd/mail.c +++ b/pttbbs/mbbsd/mail.c @@ -1514,7 +1514,7 @@ bsmtp(char *fpath, char *title, char *rcpt, int method) /* stamp the queue file */ strlcpy(buf, "out/", sizeof(buf)); for (;;) { - snprintf(buf + 4, sizeof(buf) - 4, "M.%ld.A", ++chrono); + snprintf(buf + 4, sizeof(buf) - 4, "M.%d.A", (int)++chrono); if (!dashf(buf)) { Link(fpath, buf); break; diff --git a/pttbbs/mbbsd/record.c b/pttbbs/mbbsd/record.c index e16b9404..55f78787 100644 --- a/pttbbs/mbbsd/record.c +++ b/pttbbs/mbbsd/record.c @@ -477,7 +477,7 @@ stampfile(char *fpath, fileheader_t * fh) while (*(++ip)); *ip++ = '/'; do { - sprintf(ip, "M.%ld.A.%3.3X", ++dtime, rand() & 0xFFF); + sprintf(ip, "M.%d.A.%3.3X", (int)++dtime, rand() & 0xFFF); if (fp == -1 && errno != EEXIST) return -1; } while ((fp = open(fpath, O_CREAT | O_EXCL | O_WRONLY, 0644)) == -1); @@ -503,7 +503,7 @@ stampdir(char *fpath, fileheader_t * fh) while (*(++ip)); *ip++ = '/'; do { - sprintf(ip, "D%lX", ++dtime & 07777); + sprintf(ip, "D%X", (int)++dtime & 07777); } while (mkdir(fpath, 0755) == -1); memset(fh, 0, sizeof(fileheader_t)); strlcpy(fh->filename, ip, sizeof(fh->filename)); @@ -525,7 +525,7 @@ stamplink(char *fpath, fileheader_t * fh) while (*(++ip)); *ip++ = '/'; do { - sprintf(ip, "S%lX", ++dtime); + sprintf(ip, "S%X", (int)++dtime); } while (symlink("temp", fpath) == -1); memset(fh, 0, sizeof(fileheader_t)); strlcpy(fh->filename, ip, sizeof(fh->filename)); -- cgit v1.2.3 From 612e2c7201cdd05ccbfc43b1e9957ae6de4d29fd Mon Sep 17 00:00:00 2001 From: victor <victor@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Thu, 28 Aug 2003 11:36:53 +0000 Subject: XD git-svn-id: http://opensvn.csie.org/pttbbs/trunk@1139 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/register.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pttbbs/mbbsd/register.c b/pttbbs/mbbsd/register.c index 51880eb7..a9c3d672 100644 --- a/pttbbs/mbbsd/register.c +++ b/pttbbs/mbbsd/register.c @@ -1,4 +1,4 @@ -/* $Id: register.c,v 1.13 2003/06/26 02:25:40 kcwu Exp $ */ +/* $Id$ */ #define _XOPEN_SOURCE #include "bbs.h" @@ -258,7 +258,6 @@ new_register() } newuser.userlevel = PERM_DEFAULT; newuser.uflag = COLOR_FLAG | BRDSORT_FLAG | MOVIE_FLAG; - newuser.uflag2 = FAVNEW_FLAG; newuser.firstlogin = newuser.lastlogin = now; newuser.money = 0; newuser.pager = 1; -- cgit v1.2.3 From b8fe36d967ef5c29e1f88f9672c7eeeabf577876 Mon Sep 17 00:00:00 2001 From: "(no author)" <(no author)@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Fri, 29 Aug 2003 15:14:12 +0000 Subject: add warning for using default pttbbs.conf git-svn-id: http://opensvn.csie.org/pttbbs/trunk@1140 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/docs/INSTALL | 10 +++++++--- pttbbs/sample/pttbbs.conf | 6 +++++- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/pttbbs/docs/INSTALL b/pttbbs/docs/INSTALL index 4311cc70..ebaae2eb 100644 --- a/pttbbs/docs/INSTALL +++ b/pttbbs/docs/INSTALL @@ -38,9 +38,13 @@ 更新至 pttbbs 最新的源碼. 如: cd /home/bbs/pttbbs; svn update - 8. 執行 cd ~bbs/pttbbs - 9. 如果之前沒有設定過 pttbbs.conf 的話, 請 cp sample/pttbbs.conf pttbbs.conf - 10.修改 pttbbs.conf + 8. 切換到 pttbbs 的目錄下 ( cd ~bbs/pttbbs ) + 9. 如果您的 pttbbs.conf並不存在, 可以拷一份預設的來用: + cp sample/pttbbs.conf pttbbs.conf + 10.依據您的須求, 修改 pttbbs.conf + 請注意, 預設的 pttbbs.conf是給相當大規模的 bbs用的. + 通常您須要進行修改以符合您的須求. + * 如果您是用 Linux系統, 請先安裝 pmake, 然後將 make alias 成 pmake * 11.執行 make BBSHOME=/home/bbs all install (如果出現 iconv.h找不到的話, 請見 FAQ 7 ) diff --git a/pttbbs/sample/pttbbs.conf b/pttbbs/sample/pttbbs.conf index 8811b6d9..854bbeb9 100644 --- a/pttbbs/sample/pttbbs.conf +++ b/pttbbs/sample/pttbbs.conf @@ -1,5 +1,9 @@ /* $Id: pttbbs.conf,v 1.14 2003/07/06 03:41:08 in2 Exp $ */ - +/* 請注意! 這個檔案是批踢踢實業坊(telnet://ptt.csie.ntu.edu.tw)的設定值, + * 這個設定在硬體資源足夠的前題下, 可以提供給上萬個人同時在線上. 若您的硬 + * 體資源並不足夠, 也不須負荷這麼多註冊人數/看板/上線人數, 請您務必要將相 + * 關設定值改小, 否則將會使用掉極為大量的記憶體. + */ /* 定義 BBS 站名位址 */ #define BBSNAME "新批踢踢" /* 中文站名 */ #define MYHOSTNAME "ptt2.cc" /* 網路位址 */ -- cgit v1.2.3 From f579af7e01ce76e1b9904de86f6e096a01bd0d07 Mon Sep 17 00:00:00 2001 From: victor <victor@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sun, 31 Aug 2003 16:59:06 +0000 Subject: add two kinds of pets git-svn-id: http://opensvn.csie.org/pttbbs/trunk@1144 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/chicken.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/pttbbs/mbbsd/chicken.c b/pttbbs/mbbsd/chicken.c index 553cdbd5..12f16f30 100644 --- a/pttbbs/mbbsd/chicken.c +++ b/pttbbs/mbbsd/chicken.c @@ -1,7 +1,7 @@ -/* $Id: chicken.c,v 1.12 2003/06/28 08:44:35 kcwu Exp $ */ +/* $Id$ */ #include "bbs.h" -#define NUM_KINDS 13 /* 有多少種動物 */ +#define NUM_KINDS 15 /* 有多少種動物 */ static const char *cage[17] = { "誕生", "週歲", "幼年", "少年", "青春", "青年", @@ -11,27 +11,27 @@ static const char *chicken_type[NUM_KINDS] = { "小雞", "美少女", "勇士", "蜘蛛", "恐龍", "老鷹", "貓", "蠟筆小新", "狗狗", "惡魔", "忍者", "ㄚ扁", -"馬英九"}; +"馬英九", "就可人", "羅莉"}; static const char *chicken_food[NUM_KINDS] = { "雞飼料", "營養厚片", "雞排便當", "死蝴蝶", "屍體", "小雞", "貓餅乾", "小熊餅乾", "寶錄", "靈氣", "飯團", "便當", -"雞腿"}; +"雞腿", "笑話文章", "水果沙拉"}; static const int egg_price[NUM_KINDS] = { 5, 25, 30, 40, 80, 50, 15, 35, 17, 100, 85, 200, -200}; +200, 100, 77}; static const int food_price[NUM_KINDS] = { 4, 6, 8, 10, 12, 12, 5, 6, 5, 20, 15, 23, -23}; +23, 10, 19}; static const char *attack_type[NUM_KINDS] = { "啄", "鞭打", "槌", "咬", "撞擊", "啄", "抓", "踢", "咬", "燃燒", "暗擊", "棍打", -"劍擊"}; +"劍擊", "冷凍光線", "香吻一枚"}; static const char *damage_degree[] = { "蚊子似的", "騷癢似的", "小力的", "輕微的", @@ -76,7 +76,11 @@ static const short time_change[NUM_KINDS][14] = /* 阿扁 */ {1, 1, 150, 4, 8, 13, 95, 25, 7, 10, 25, 5, 175, 85}, /* 馬英九 */ - {1, 1, 147, 2, 10, 10, 85, 20, 4, 25, 25, 5, 145, 95} + {1, 1, 147, 2, 10, 10, 85, 20, 4, 25, 25, 5, 145, 95}, + /* 就可人 */ + {1, 1, 200, 3, 15, 15, 50, 50, 10, 5, 10, 2, 300, 0}, + /* 羅利 */ + {1, 1, 80, 2, 9, 10, 2, 5, 7, 8, 12, 1, 135, 5}, }; int -- cgit v1.2.3 From b0a1274c6ce8aad89a44c1024eb9e5c5935fc2c0 Mon Sep 17 00:00:00 2001 From: victor <victor@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Mon, 1 Sep 2003 03:25:12 +0000 Subject: change prompt for getting a new pet git-svn-id: http://opensvn.csie.org/pttbbs/trunk@1145 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/chicken.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/pttbbs/mbbsd/chicken.c b/pttbbs/mbbsd/chicken.c index 12f16f30..23ed4279 100644 --- a/pttbbs/mbbsd/chicken.c +++ b/pttbbs/mbbsd/chicken.c @@ -106,13 +106,14 @@ new_chicken() move(2, 0); outs("歡迎觀臨 \033[33m◎\033[37;44m Ptt寵物市場 \033[33;40m◎\033[m.. " "目前蛋價:\n" - "(a)小雞 $5 (b)美少女 $25 (c)勇士 $30 (d)蜘蛛 $40 " + "(a)小雞 $5 (b)美少女 $25 (c)勇士 $30 (d)蜘蛛 $40 " "(e)恐龍 $80\n" - "(f)老鷹 $50 (g)貓 $15 (h)蠟筆小新$35 (i)狗狗 $17 " + "(f)老鷹 $50 (g)貓 $15 (h)蠟筆小新$35 (i)狗狗 $17 " "(j)惡魔 $100\n" - "(k)忍者 $85 (l)阿扁 $200 (m)馬英九 $200\n" + "(k)忍者 $85 (l)阿扁 $200 (m)馬英九 $200 (n)就可人$100 " + "[o]羅莉 $77\n" "[0]自己 $0\n"); - getdata_str(6, 0, "請選擇你要養的動物:", buf, 3, LCECHO, "0"); + getdata_str(7, 0, "請選擇你要養的動物:", buf, 3, LCECHO, "0"); buf[0] -= 'a'; if (buf[0] < 0 || buf[0] > NUM_KINDS - 1) -- cgit v1.2.3 From 93fba89d94468d5b23fd482063db063bbb7d3c20 Mon Sep 17 00:00:00 2001 From: victor <victor@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Mon, 1 Sep 2003 03:33:06 +0000 Subject: mbbsd.c for SSH_CLIENT user.c for passwd_update when changing the habit git-svn-id: http://opensvn.csie.org/pttbbs/trunk@1146 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/mbbsd.c | 15 ++++++++++++++- pttbbs/mbbsd/user.c | 1 + 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/pttbbs/mbbsd/mbbsd.c b/pttbbs/mbbsd/mbbsd.c index 69b84742..80428bef 100644 --- a/pttbbs/mbbsd/mbbsd.c +++ b/pttbbs/mbbsd/mbbsd.c @@ -5,7 +5,8 @@ #define TH_LOW 100 #define TH_HIGH 120 -static void do_aloha(char *hello); +static void do_aloha(char *hello); +static void getremotename(struct sockaddr_in * from, char *rhost, char *rname); #if 0 static jmp_buf byebye; @@ -798,6 +799,18 @@ user_login() resolve_boards(); memset(&water[0], 0, sizeof(water_t) * 6); strlcpy(water[0].userid, " 全部 ", sizeof(water[0].userid)); + + if(getenv("SSH_CLIENT") == NULL) + strcpy(fromhost, "localhost"); + else { + char frombuf[50]; + sscanf(getenv("SSH_CLIENT"), "%s", frombuf); + xsin.sin_family = AF_INET; + xsin.sin_port = htons(23); + inet_pton(AF_INET, frombuf, &xsin.sin_addr); + getremotename(&xsin, fromhost, remoteusername); /* FC931 */ + } + /* 初始化 uinfo、flag、mode */ setup_utmp(LOGIN); currmode = MODE_STARTED; diff --git a/pttbbs/mbbsd/user.c b/pttbbs/mbbsd/user.c index aac88c47..8849b9ff 100644 --- a/pttbbs/mbbsd/user.c +++ b/pttbbs/mbbsd/user.c @@ -266,6 +266,7 @@ static void Customize(void) default: done = 1; } + passwd_update(usernum, &cuser); } pressanykey(); } -- cgit v1.2.3 From 37475b1bf95bf269d1a59ad19a8671735febd966 Mon Sep 17 00:00:00 2001 From: victor <victor@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Mon, 1 Sep 2003 04:00:33 +0000 Subject: fix my problem @@ git-svn-id: http://opensvn.csie.org/pttbbs/trunk@1147 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/mbbsd.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/pttbbs/mbbsd/mbbsd.c b/pttbbs/mbbsd/mbbsd.c index 80428bef..3d5ba494 100644 --- a/pttbbs/mbbsd/mbbsd.c +++ b/pttbbs/mbbsd/mbbsd.c @@ -800,9 +800,7 @@ user_login() memset(&water[0], 0, sizeof(water_t) * 6); strlcpy(water[0].userid, " 全部 ", sizeof(water[0].userid)); - if(getenv("SSH_CLIENT") == NULL) - strcpy(fromhost, "localhost"); - else { + if(getenv("SSH_CLIENT") != NULL){ char frombuf[50]; sscanf(getenv("SSH_CLIENT"), "%s", frombuf); xsin.sin_family = AF_INET; -- cgit v1.2.3 From e3b4c25a979e57db7ccdb60bd891e8d42257d87a Mon Sep 17 00:00:00 2001 From: victor <victor@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Mon, 1 Sep 2003 04:12:08 +0000 Subject: add pic git-svn-id: http://opensvn.csie.org/pttbbs/trunk@1148 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/sample/etc/chickens/n0 | 12 ++++++++++++ pttbbs/sample/etc/chickens/n1 | 12 ++++++++++++ pttbbs/sample/etc/chickens/n10 | 0 pttbbs/sample/etc/chickens/n11 | 0 pttbbs/sample/etc/chickens/n12 | 0 pttbbs/sample/etc/chickens/n13 | 1 + pttbbs/sample/etc/chickens/n14 | 0 pttbbs/sample/etc/chickens/n15 | 0 pttbbs/sample/etc/chickens/n16 | 0 pttbbs/sample/etc/chickens/n2 | 11 +++++++++++ pttbbs/sample/etc/chickens/n3 | 11 +++++++++++ pttbbs/sample/etc/chickens/n4 | 12 ++++++++++++ pttbbs/sample/etc/chickens/n5 | 12 ++++++++++++ pttbbs/sample/etc/chickens/n6 | 12 ++++++++++++ pttbbs/sample/etc/chickens/n7 | 12 ++++++++++++ pttbbs/sample/etc/chickens/n8 | 12 ++++++++++++ pttbbs/sample/etc/chickens/n9 | 12 ++++++++++++ pttbbs/sample/etc/chickens/o0 | 12 ++++++++++++ pttbbs/sample/etc/chickens/o1 | 12 ++++++++++++ pttbbs/sample/etc/chickens/o10 | 12 ++++++++++++ pttbbs/sample/etc/chickens/o11 | 12 ++++++++++++ pttbbs/sample/etc/chickens/o12 | 12 ++++++++++++ pttbbs/sample/etc/chickens/o13 | 12 ++++++++++++ pttbbs/sample/etc/chickens/o14 | 12 ++++++++++++ pttbbs/sample/etc/chickens/o15 | 11 +++++++++++ pttbbs/sample/etc/chickens/o16 | 11 +++++++++++ pttbbs/sample/etc/chickens/o2 | 12 ++++++++++++ pttbbs/sample/etc/chickens/o3 | 12 ++++++++++++ pttbbs/sample/etc/chickens/o4 | 11 +++++++++++ pttbbs/sample/etc/chickens/o5 | 11 +++++++++++ pttbbs/sample/etc/chickens/o6 | 10 ++++++++++ pttbbs/sample/etc/chickens/o7 | 12 ++++++++++++ pttbbs/sample/etc/chickens/o8 | 12 ++++++++++++ pttbbs/sample/etc/chickens/o9 | 12 ++++++++++++ 34 files changed, 317 insertions(+) create mode 100644 pttbbs/sample/etc/chickens/n0 create mode 100644 pttbbs/sample/etc/chickens/n1 create mode 100644 pttbbs/sample/etc/chickens/n10 create mode 100644 pttbbs/sample/etc/chickens/n11 create mode 100644 pttbbs/sample/etc/chickens/n12 create mode 100644 pttbbs/sample/etc/chickens/n13 create mode 100644 pttbbs/sample/etc/chickens/n14 create mode 100644 pttbbs/sample/etc/chickens/n15 create mode 100644 pttbbs/sample/etc/chickens/n16 create mode 100644 pttbbs/sample/etc/chickens/n2 create mode 100644 pttbbs/sample/etc/chickens/n3 create mode 100644 pttbbs/sample/etc/chickens/n4 create mode 100644 pttbbs/sample/etc/chickens/n5 create mode 100644 pttbbs/sample/etc/chickens/n6 create mode 100644 pttbbs/sample/etc/chickens/n7 create mode 100644 pttbbs/sample/etc/chickens/n8 create mode 100644 pttbbs/sample/etc/chickens/n9 create mode 100644 pttbbs/sample/etc/chickens/o0 create mode 100644 pttbbs/sample/etc/chickens/o1 create mode 100644 pttbbs/sample/etc/chickens/o10 create mode 100644 pttbbs/sample/etc/chickens/o11 create mode 100644 pttbbs/sample/etc/chickens/o12 create mode 100644 pttbbs/sample/etc/chickens/o13 create mode 100644 pttbbs/sample/etc/chickens/o14 create mode 100644 pttbbs/sample/etc/chickens/o15 create mode 100644 pttbbs/sample/etc/chickens/o16 create mode 100644 pttbbs/sample/etc/chickens/o2 create mode 100644 pttbbs/sample/etc/chickens/o3 create mode 100644 pttbbs/sample/etc/chickens/o4 create mode 100644 pttbbs/sample/etc/chickens/o5 create mode 100644 pttbbs/sample/etc/chickens/o6 create mode 100644 pttbbs/sample/etc/chickens/o7 create mode 100644 pttbbs/sample/etc/chickens/o8 create mode 100644 pttbbs/sample/etc/chickens/o9 diff --git a/pttbbs/sample/etc/chickens/n0 b/pttbbs/sample/etc/chickens/n0 new file mode 100644 index 00000000..05d456bd --- /dev/null +++ b/pttbbs/sample/etc/chickens/n0 @@ -0,0 +1,12 @@ + ▄▅▇▇▇▅▄ + ▕ . ∵ ▏ + ▕ ◢ ◆ ◣ ▏ + ▕  ◤◥◤◥  ▏ + ▕  ︶ ︶  ▏ + ▕ ◥" ︶ "◤.▏ + ▕ ◢ 非 ◣ ▏ + ▕ ◥◢│◣◤ ▏ + ▕ . ◣│◢ . ▏ + ▕ ∵. . ▏ + ███████ + ████████ diff --git a/pttbbs/sample/etc/chickens/n1 b/pttbbs/sample/etc/chickens/n1 new file mode 100644 index 00000000..05d456bd --- /dev/null +++ b/pttbbs/sample/etc/chickens/n1 @@ -0,0 +1,12 @@ + ▄▅▇▇▇▅▄ + ▕ . ∵ ▏ + ▕ ◢ ◆ ◣ ▏ + ▕  ◤◥◤◥  ▏ + ▕  ︶ ︶  ▏ + ▕ ◥" ︶ "◤.▏ + ▕ ◢ 非 ◣ ▏ + ▕ ◥◢│◣◤ ▏ + ▕ . ◣│◢ . ▏ + ▕ ∵. . ▏ + ███████ + ████████ diff --git a/pttbbs/sample/etc/chickens/n10 b/pttbbs/sample/etc/chickens/n10 new file mode 100644 index 00000000..e69de29b diff --git a/pttbbs/sample/etc/chickens/n11 b/pttbbs/sample/etc/chickens/n11 new file mode 100644 index 00000000..e69de29b diff --git a/pttbbs/sample/etc/chickens/n12 b/pttbbs/sample/etc/chickens/n12 new file mode 100644 index 00000000..e69de29b diff --git a/pttbbs/sample/etc/chickens/n13 b/pttbbs/sample/etc/chickens/n13 new file mode 100644 index 00000000..96197489 --- /dev/null +++ b/pttbbs/sample/etc/chickens/n13 @@ -0,0 +1 @@ + -- ◥ ◣ > < ◢ ◤ diff --git a/pttbbs/sample/etc/chickens/n14 b/pttbbs/sample/etc/chickens/n14 new file mode 100644 index 00000000..e69de29b diff --git a/pttbbs/sample/etc/chickens/n15 b/pttbbs/sample/etc/chickens/n15 new file mode 100644 index 00000000..e69de29b diff --git a/pttbbs/sample/etc/chickens/n16 b/pttbbs/sample/etc/chickens/n16 new file mode 100644 index 00000000..e69de29b diff --git a/pttbbs/sample/etc/chickens/n2 b/pttbbs/sample/etc/chickens/n2 new file mode 100644 index 00000000..4c706ff5 --- /dev/null +++ b/pttbbs/sample/etc/chickens/n2 @@ -0,0 +1,11 @@ + ◢ ◆ ◣ +  ◤◥◤◥  +  ● ●  ◣ + ◥" ▼ "◤   + ◢ ◥ ◤ ◤ +    ◥◤  + ◥  ▄▄▄ + ◢◥█◤◣ + ◣◤ ◥◢ + █▌ █▌ + ◢ ◥ ◤ ◣ diff --git a/pttbbs/sample/etc/chickens/n3 b/pttbbs/sample/etc/chickens/n3 new file mode 100644 index 00000000..62f06de1 --- /dev/null +++ b/pttbbs/sample/etc/chickens/n3 @@ -0,0 +1,11 @@ + ◢ ◆ ◣ +  ◤◥◤◥  +  ● ︵  + ◢◣" ▼ "◢◣ + ◢◥ J ◤◣ + █ ◤ ◥ █ + ◥  ▄▄▄  ◤ + ◢◥█◤◣ + ◣◤ ◥◢ + █▌ █▌ + ◢ ◥ ◤ ◣ diff --git a/pttbbs/sample/etc/chickens/n4 b/pttbbs/sample/etc/chickens/n4 new file mode 100644 index 00000000..982240c1 --- /dev/null +++ b/pttbbs/sample/etc/chickens/n4 @@ -0,0 +1,12 @@ + ╱╲ ╱╲ + ▕◢ █ ◣▏ + █◤▄◥█ +  ● ●  + ◢◣" ︶ "◢◣ + ◢◥ J ◤◣ + █ ◤ ◥ █ + ◥  ▄▄▄  ◤ + ◢◥█◤◣ + ◣◤ ◥◢ + █▌ █▌ + ◢ ◥ ◤ ◣ diff --git a/pttbbs/sample/etc/chickens/n5 b/pttbbs/sample/etc/chickens/n5 new file mode 100644 index 00000000..339533e8 --- /dev/null +++ b/pttbbs/sample/etc/chickens/n5 @@ -0,0 +1,12 @@ + ╱╲ ╱╲ + ▕◢ █ ◣▏ + █◤▄◥█ +  ● ●  + ◢◣" ▼ "◢◣ + ▄ ◥ J ◤ ▄ + ◥█◤◤ ◥◥█◤ + ◥ ▄▄▄ ◤ + ◢◥█◤◣ + ◣◤ ◥◢ + █▌ █▌ + ◢ ◥ ◤ ◣ diff --git a/pttbbs/sample/etc/chickens/n6 b/pttbbs/sample/etc/chickens/n6 new file mode 100644 index 00000000..29fabf26 --- /dev/null +++ b/pttbbs/sample/etc/chickens/n6 @@ -0,0 +1,12 @@ + ╱╲ ╱╲ + ▕◢ █ ◣▏ + █◤▄◥█ + ◥ ◣ ︵ ︵ ◢ ◤ + ◥ ◢◣" ▼ "◢◣ ◤ + ▄ ◥ J ◤ ▄ + ◥█◤◤ ◥◥█◤ + ◥ ▄▄▄ ◤ + ◢◥█◤◣ + ◣◤ ◥◢ + █▌ █▌ + ◢ ◥ ◤ ◣ diff --git a/pttbbs/sample/etc/chickens/n7 b/pttbbs/sample/etc/chickens/n7 new file mode 100644 index 00000000..9965bed3 --- /dev/null +++ b/pttbbs/sample/etc/chickens/n7 @@ -0,0 +1,12 @@ + ╱╲ ╱╲ + ▕◢ █ ◣▏ + █◤▄◥█ + ◥ ◣ ◣ ◢ ◢ ◤ + ◥ ◢◣" ▼ "◢◣ ◤ + ◢◥ J ◤    + ◥█ ◤ ◥ ◤ + ▄█▄▄▄▄▄▄  + ◢◥◥◤◥◤◤ + ◣◤ ◥◢ + █▌ █▌ + ◢ ◥ ◤ ◣ diff --git a/pttbbs/sample/etc/chickens/n8 b/pttbbs/sample/etc/chickens/n8 new file mode 100644 index 00000000..665ef99b --- /dev/null +++ b/pttbbs/sample/etc/chickens/n8 @@ -0,0 +1,12 @@ + ╱╲ ╱╲ + ▕◢ █ ◣▏ + █◤▄◥█ + ◥ ◣ ︵ ︵ ◢ ◤ + ◥ ◢◣*˙*◢◣ ◤ + ◢◥ J ◤◣ + ◥█ ◤ ◥ █◤ + ◥  ▄▄▄  ◤ + ◢◥█◤◣ + ◣◤█◥◢ + █▌█ █▌ + ◢ ◥ █ ◤ ◣ diff --git a/pttbbs/sample/etc/chickens/n9 b/pttbbs/sample/etc/chickens/n9 new file mode 100644 index 00000000..c9b79651 --- /dev/null +++ b/pttbbs/sample/etc/chickens/n9 @@ -0,0 +1,12 @@ +  ╱╲ ╱╲  +  ▕◢ █ ◣▏  +  █◤▄◥█  + ◥ ◣ @ @ ◢ ◤ + ◥ ◢◣" 0 "◢◣ ◤ + ▄ ◥ J ◤ ▄ + ◥█◤◤ ◥◥█◤ + ◥ ▄▄▄ ◤ +  ◢◥█◤◣  +   ◣ ◤ ◥ ◢   +  █▌ █▌  + ◢ ◥ ◤ ◣ diff --git a/pttbbs/sample/etc/chickens/o0 b/pttbbs/sample/etc/chickens/o0 new file mode 100644 index 00000000..ce313964 --- /dev/null +++ b/pttbbs/sample/etc/chickens/o0 @@ -0,0 +1,12 @@ +  │ + │  + \   ╱ + \ ▕▎  / + ◤ ◣ + ╴╴╴  ▍ ╴╴╴ +  ▍ + ◣ ◢ +  ╱ ╲ + / │ ╲ + │ + diff --git a/pttbbs/sample/etc/chickens/o1 b/pttbbs/sample/etc/chickens/o1 new file mode 100644 index 00000000..ce313964 --- /dev/null +++ b/pttbbs/sample/etc/chickens/o1 @@ -0,0 +1,12 @@ +  │ + │  + \   ╱ + \ ▕▎  / + ◤ ◣ + ╴╴╴  ▍ ╴╴╴ +  ▍ + ◣ ◢ +  ╱ ╲ + / │ ╲ + │ + diff --git a/pttbbs/sample/etc/chickens/o10 b/pttbbs/sample/etc/chickens/o10 new file mode 100644 index 00000000..8b5a7f2e --- /dev/null +++ b/pttbbs/sample/etc/chickens/o10 @@ -0,0 +1,12 @@ + ◢ ◣ +  ◤◤◤◥  + 呀!  > <  +  ▼   哈! +      + ●▃d ▲▲ d▃● +   ◥◤   +  ***  + █ █ +  ▃ ◤ ◥ ▃  +   + diff --git a/pttbbs/sample/etc/chickens/o11 b/pttbbs/sample/etc/chickens/o11 new file mode 100644 index 00000000..d1038280 --- /dev/null +++ b/pttbbs/sample/etc/chickens/o11 @@ -0,0 +1,12 @@ + ◢ ◣  鵂s┬┬ +  岷  ◤◤◤◥   礜q┼┼┤ +  哈   ● ●   礜q┼┼┤ + 岷  ▼    礜r┴┴ + 哈        + ●▃d ▲▲ d▃● + ┼┼┼   ◥◤     + ┼┼┼  ***     + █ █   + █ ◥▅▅ 岷 + ▋  ◥ 哈 + ◢▋ diff --git a/pttbbs/sample/etc/chickens/o12 b/pttbbs/sample/etc/chickens/o12 new file mode 100644 index 00000000..6eeb2b11 --- /dev/null +++ b/pttbbs/sample/etc/chickens/o12 @@ -0,0 +1,12 @@ + ◢ ◣ +  ◤◤◤◥  +  ● ●  我要去上學囉∼ +  ︶   +  ◢▃◣  \  + ●▃▃ ◤◥ ▃▃● *  +     ╱  +  ▅▅▅  +  ◢███◣  +  ▋ ◥▅▅ +  ▋ ◥ + ◢▋ diff --git a/pttbbs/sample/etc/chickens/o13 b/pttbbs/sample/etc/chickens/o13 new file mode 100644 index 00000000..3a0751cc --- /dev/null +++ b/pttbbs/sample/etc/chickens/o13 @@ -0,0 +1,12 @@ + ◢███◣ + i◤◤◤◥i + i● ︽i +  ︶  今天的晚餐就交給我吧∼ + ◢▃◣ + ◢i█i◣ + ▌。 。▌ +  ▌ ◎  ▌  +    ̄   +   +   +   diff --git a/pttbbs/sample/etc/chickens/o14 b/pttbbs/sample/etc/chickens/o14 new file mode 100644 index 00000000..44e5b4ec --- /dev/null +++ b/pttbbs/sample/etc/chickens/o14 @@ -0,0 +1,12 @@ + ◢屆閒◣ +  ◤◤◤◥  +  ● ●  +  ︶   +  ◣▄◢  可以教我跳舞嗎? + ◢★◣ + ▌    +     + ◢﹒﹒﹒﹒﹒◣ + ◇◇◇◇◇◇◇ +  ╴ ╴  +  ▼ ▼ diff --git a/pttbbs/sample/etc/chickens/o15 b/pttbbs/sample/etc/chickens/o15 new file mode 100644 index 00000000..7e6b6402 --- /dev/null +++ b/pttbbs/sample/etc/chickens/o15 @@ -0,0 +1,11 @@ + ◢ ◣ +  ◤◤◤◥  +  > ●  +  •   咦? +  ▇ ▇  +  ▌Ψ▌ ◣ + ◥███◤ ◣ + ◢████◣  +  ◥█████◤ ◤ +  ◥◣◥▆▆◣ +  ◥◤ ◥ diff --git a/pttbbs/sample/etc/chickens/o16 b/pttbbs/sample/etc/chickens/o16 new file mode 100644 index 00000000..1ee3801f --- /dev/null +++ b/pttbbs/sample/etc/chickens/o16 @@ -0,0 +1,11 @@ + ◢ ◣ +  ◤◤◤◥  +  ● ●  +  ︶   全世界我最喜歡*s唷... +  ▇ ▇  +  ▌Ψ▌ ◣ + ◥███◤ ◣ + ◢████◣  +  ◥█████◤ ◤ +  ◥◣◥▆▆◣ +  ◥◤ ◥ diff --git a/pttbbs/sample/etc/chickens/o2 b/pttbbs/sample/etc/chickens/o2 new file mode 100644 index 00000000..9161372e --- /dev/null +++ b/pttbbs/sample/etc/chickens/o2 @@ -0,0 +1,12 @@ +  ▃▄▅▇▇▇▅▄▃ + ▕ . . ▏ + ▕ ∵    . ▏ + ┌────▕ ▕▎  ▏────┐ + ┌───▕ : ◤ ◣  ▏───┐ + ┌── ▕  ▍  :▏ ──┐ + ┌─▕ .  ▍ ∵ ▏─┐ + ─▕ ◣ ◢  ▏─ + ▕ ‥  . ▏ + ▕ ∴ . ∵ . ▏ + █████████ + ██████████ diff --git a/pttbbs/sample/etc/chickens/o3 b/pttbbs/sample/etc/chickens/o3 new file mode 100644 index 00000000..112fc914 --- /dev/null +++ b/pttbbs/sample/etc/chickens/o3 @@ -0,0 +1,12 @@ +  ▃▄▅▇▇▇▅▄▃ + ▕ . . ▏ + ▕ ∵◢ ◣ . ▏ + ┌────▕  ◤◤◤◥   ▏────┐ + ┌───▕ : ︾ ︾   ▏───┐ + ┌── ▕  ﹋   :▏ ──┐ + ┌─▕ .   ▇非▇  ∵ ▏─┐  + ─▕ ◤│◥ ▏─ + ▕ ‥ ◣│◢  . ▏ + ▕ ∴ . ∵ . ▏ + █████████ + ██████████ diff --git a/pttbbs/sample/etc/chickens/o4 b/pttbbs/sample/etc/chickens/o4 new file mode 100644 index 00000000..9e0fe255 --- /dev/null +++ b/pttbbs/sample/etc/chickens/o4 @@ -0,0 +1,11 @@ + + ◢ ◣ +  ◤◤◤◥  +  ● ●  +  ﹋   +  ▇ ▇   + ◢█●●█◣ + ▆▆▆ + ███ + ▋▍ + ▼▼ diff --git a/pttbbs/sample/etc/chickens/o5 b/pttbbs/sample/etc/chickens/o5 new file mode 100644 index 00000000..d38b64bd --- /dev/null +++ b/pttbbs/sample/etc/chickens/o5 @@ -0,0 +1,11 @@ + + ◢ ◣ +  ◤◤◤◥  +  ︵ ︵  你今天也好嗎? +  ▼   +  ▇ ▇   + ◢█●●█◣ + ▆▆▆ + ███ + ▋▍ + ▼▼ diff --git a/pttbbs/sample/etc/chickens/o6 b/pttbbs/sample/etc/chickens/o6 new file mode 100644 index 00000000..f92eb54b --- /dev/null +++ b/pttbbs/sample/etc/chickens/o6 @@ -0,0 +1,10 @@ + ◢ *◣ +  ◤◤◤◥  +  ︽ ︽  @ +  ▼    │ +  │ ▇e▄● +  x   + x  + e....  *s是大好人,謝謝你 + ▋▍ + ▼▼ diff --git a/pttbbs/sample/etc/chickens/o7 b/pttbbs/sample/etc/chickens/o7 new file mode 100644 index 00000000..123a2eef --- /dev/null +++ b/pttbbs/sample/etc/chickens/o7 @@ -0,0 +1,12 @@ + ◢ + █ ◢◣ +  岷  +  ◣  ── +  ◤◤◤◥  │▲▲│ +  ︽ ︽   < ◥◤│ +  ︶    ──  +  \ ◣ ◢  + \╴◢ ◣  + ▊    ≡  ▍ + ██  ██  + ◥ ◤ diff --git a/pttbbs/sample/etc/chickens/o8 b/pttbbs/sample/etc/chickens/o8 new file mode 100644 index 00000000..637aae53 --- /dev/null +++ b/pttbbs/sample/etc/chickens/o8 @@ -0,0 +1,12 @@ + ◢███◣ + i◤◤◤◥i + i● ●i +  ︶   +  ▃   + ◢ ◤◥ ◣ + ▌   ▌ + ▌● ●▌ + ◢███◣ + ▋▍ + ▋▍ + ◢▋▍◣ diff --git a/pttbbs/sample/etc/chickens/o9 b/pttbbs/sample/etc/chickens/o9 new file mode 100644 index 00000000..b0b2cf1a --- /dev/null +++ b/pttbbs/sample/etc/chickens/o9 @@ -0,0 +1,12 @@ + ◢ ◣ +  Ξ ◥◣ + ◢ ◣ ◤ +  ◤◤◤◥  +  ● ●  +  ο   別小看我唷∼ + ◢▃◣ + ◢ ◤◥ ▄▄▍ + m  + ◢█◣▄ ◥◣◥▅▅▅ + ███ ◥▅▅ ◥ + ◥█◤  ◥ -- cgit v1.2.3 From fcc89aea78bdab5b760fa0df76a6d32aabe99889 Mon Sep 17 00:00:00 2001 From: victor <victor@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Tue, 2 Sep 2003 06:32:49 +0000 Subject: attach SHM git-svn-id: http://opensvn.csie.org/pttbbs/trunk@1151 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/deluserfile.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pttbbs/util/deluserfile.c b/pttbbs/util/deluserfile.c index 73f3750a..83849b6c 100644 --- a/pttbbs/util/deluserfile.c +++ b/pttbbs/util/deluserfile.c @@ -104,6 +104,8 @@ int main(int argc, char **argv) printf("new version, deleting\n"); + attach_SHM(); + for (ch = 'A'; ch <= 'z'; ch++) { if(ch > 'Z' && ch < 'a') -- cgit v1.2.3 From 00471185fffecc4aa75e7e611718c5d6f18de780 Mon Sep 17 00:00:00 2001 From: "(no author)" <(no author)@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Tue, 2 Sep 2003 10:31:50 +0000 Subject: use LocalVars git-svn-id: http://opensvn.csie.org/pttbbs/trunk@1152 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/blog/index.pl | 1 + 1 file changed, 1 insertion(+) diff --git a/pttbbs/blog/index.pl b/pttbbs/blog/index.pl index 9b2e6dc1..b30ed178 100755 --- a/pttbbs/blog/index.pl +++ b/pttbbs/blog/index.pl @@ -2,6 +2,7 @@ # $Id$ use CGI qw/:standard/; use lib qw/./; +use LocalVars; sub main { -- cgit v1.2.3 From 7ec7b19a9fc01ce195c2d8eb4e18643d2242bb57 Mon Sep 17 00:00:00 2001 From: "(no author)" <(no author)@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Wed, 3 Sep 2003 02:22:59 +0000 Subject: typo git-svn-id: http://opensvn.csie.org/pttbbs/trunk@1153 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/mail.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pttbbs/mbbsd/mail.c b/pttbbs/mbbsd/mail.c index 84fa9c3e..bca23743 100644 --- a/pttbbs/mbbsd/mail.c +++ b/pttbbs/mbbsd/mail.c @@ -1304,7 +1304,7 @@ mail_waterball(int ent, fileheader_t * fhdr, char *direct) move(b_lines - 8, 0); outs("水球整理程式:\n" "系統將會按照和不同人丟的水球各自獨立\n" - "於整點的時候 (尖鋒時段除外) 將資料整理好寄送給您\n\n\n"); + "於整點的時候 (尖峰時段除外) 將資料整理好寄送給您\n\n\n"); if (address[0]) { snprintf(genbuf, sizeof(genbuf), "寄給 [%s] 嗎(Y/N/Q)?[Y] ", address); getdata(b_lines - 5, 0, genbuf, fname, 3, LCECHO); @@ -1359,7 +1359,7 @@ mail_waterball(int ent, fileheader_t * fhdr, char *direct) assert(fp); fprintf(fp, "%s\n%s\n%d\n", cuser.userid, address, cmode); fclose(fp); - vmsg("設定完成, 系統將在下一個整點(尖鋒時段除外)將資料寄給您"); + vmsg("設定完成, 系統將在下一個整點(尖峰時段除外)將資料寄給您"); return FULLUPDATE; } #endif -- cgit v1.2.3 From 279a022993b124a6d6838e32519c96e909a2e816 Mon Sep 17 00:00:00 2001 From: "(no author)" <(no author)@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Thu, 4 Sep 2003 08:13:43 +0000 Subject: add get_record_keep(). we don't need to open/close the same file every time in title search mode. git-svn-id: http://opensvn.csie.org/pttbbs/trunk@1155 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/include/proto.h | 1 + pttbbs/mbbsd/read.c | 16 +++++++++++++--- pttbbs/mbbsd/record.c | 18 +++++++++++++++++- 3 files changed, 31 insertions(+), 4 deletions(-) diff --git a/pttbbs/include/proto.h b/pttbbs/include/proto.h index 84db664c..073e9520 100644 --- a/pttbbs/include/proto.h +++ b/pttbbs/include/proto.h @@ -366,6 +366,7 @@ void UnTagger (int locus); int substitute_record(char *fpath, void *rptr, int size, int id); int lock_substitute_record(char *fpath, void *rptr, int size, int id, int); int get_record(char *fpath, void *rptr, int size, int id); +int get_record_keep(char *fpath, void *rptr, int size, int id, int *fd); void prints(char *fmt, ...) GCC_CHECK_FORMAT(1,2); int append_record(char *fpath, fileheader_t *record, int size); int stampfile(char *fpath, fileheader_t *fh); diff --git a/pttbbs/mbbsd/read.c b/pttbbs/mbbsd/read.c index 009b6912..1542ace5 100644 --- a/pttbbs/mbbsd/read.c +++ b/pttbbs/mbbsd/read.c @@ -289,6 +289,7 @@ thread(keeploc_t * locmem, int stype) register int now, pos, match, near = 0; fileheader_t fh; int circulate_flag = 1; /* circulate at end or begin */ + int fd = -1; match = hit_thread = 0; now = pos = locmem->crs_ln; @@ -357,10 +358,15 @@ thread(keeploc_t * locmem, int stype) do { if (!circulate_flag || stype & RS_RELATED) { if (stype & RS_FORWARD) { - if (++now > last_line) + if (++now > last_line){ + if( fd != -1 ) + close(fd); return DONOTHING; + } } else { - if (--now <= 0 || now < pos - 300) { + if (--now <= 0 || now < pos - 200) { + if( fd ) + close(fd); if ((stype & RS_FIRST) && (near)) { hit_thread = 1; return cursor_pos(locmem, near, 10); @@ -376,7 +382,7 @@ thread(keeploc_t * locmem, int stype) now = last_line; } - get_record(currdirect, &fh, sizeof(fileheader_t), now); + get_record_keep(currdirect, &fh, sizeof(fileheader_t), now, &fd); if (fh.owner[0] == '-') continue; @@ -384,6 +390,8 @@ thread(keeploc_t * locmem, int stype) if (stype & RS_THREAD) { if (strncasecmp(fh.title, str_reply, 3)) { hit_thread = 1; + if( fd ) + close(fd); return cursor_pos(locmem, now, 10); } continue; @@ -411,6 +419,8 @@ thread(keeploc_t * locmem, int stype) } } while (now != pos); + if( fd != -1 ) + close(fd); return match; } diff --git a/pttbbs/mbbsd/record.c b/pttbbs/mbbsd/record.c index 55f78787..491af517 100644 --- a/pttbbs/mbbsd/record.c +++ b/pttbbs/mbbsd/record.c @@ -55,12 +55,28 @@ get_sum_records(char *fpath, int size) return ans / 1024; } +int +get_record_keep(char *fpath, void *rptr, int size, int id, int *fd) +{ + /* 和 get_record() 一樣. 不過藉由 *fd, 可使同一個檔案不要一直重複開關 */ + if (id >= 1 && + (*fd > 0 || + ((*fd = open(fpath, O_RDONLY, 0)) > 0))){ + if (lseek(*fd, (off_t) (size * (id - 1)), SEEK_SET) != -1) { + if (read(*fd, rptr, size) == size) { + return 0; + } + } + } + return -1; +} + int get_record(char *fpath, void *rptr, int size, int id) { int fd = -1; - if (id < 1 || (fd = open(fpath, O_RDONLY, 0)) != -1) { + if (id >= 1 && (fd = open(fpath, O_RDONLY, 0)) != -1) { if (lseek(fd, (off_t) (size * (id - 1)), SEEK_SET) != -1) { if (read(fd, rptr, size) == size) { close(fd); -- cgit v1.2.3 From e11fa896cd28e47153a9c305749fbb1dca2c0177 Mon Sep 17 00:00:00 2001 From: "(no author)" <(no author)@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Thu, 4 Sep 2003 10:16:03 +0000 Subject: reduce usage of get_record() git-svn-id: http://opensvn.csie.org/pttbbs/trunk@1156 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/menu.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/pttbbs/mbbsd/menu.c b/pttbbs/mbbsd/menu.c index d7984950..c506b3e9 100644 --- a/pttbbs/mbbsd/menu.c +++ b/pttbbs/mbbsd/menu.c @@ -1,4 +1,4 @@ -/* $Id: menu.c,v 1.26 2003/05/22 01:16:45 in2 Exp $ */ +/* $Id$ */ #include "bbs.h" /* help & menu processring */ @@ -33,7 +33,6 @@ showtitle(char *title, char *mid) { char buf[40], numreg[50]; int nreg, spc = 0, pad, bid; - boardheader_t bh; static char lastboard[16] = {0}; spc = strlen(mid); @@ -74,10 +73,10 @@ showtitle(char *title, char *mid) if (strcmp(currboard, lastboard)) { /* change board */ if (currboard[0] != 0 && - (bid = getbnum(currboard)) > 0 && - (get_record(fn_board, &bh, sizeof(bh), bid) != -1)) { - board_hidden_status = ((bh.brdattr & BRD_HIDE) && - (bh.brdattr & BRD_POSTMASK)); + (bid = getbnum(currboard)) > 0) { + // XXX: bid starts from 1 + board_hidden_status = ((bcache[bid - 1].brdattr & BRD_HIDE) && + (bcache[bid - 1].brdattr & BRD_POSTMASK)); strncpy(lastboard, currboard, sizeof(lastboard)); } } -- cgit v1.2.3 From cbfd38a00c84789845ffafbded153bd81936908b Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Thu, 4 Sep 2003 11:01:57 +0000 Subject: read 8k once instead of 128bytes, reduce system calls. git-svn-id: http://opensvn.csie.org/pttbbs/trunk@1157 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/bbs.c | 18 ++++++------ pttbbs/mbbsd/read.c | 83 ++++++++++++++++++++++++++++++++--------------------- 2 files changed, 60 insertions(+), 41 deletions(-) diff --git a/pttbbs/mbbsd/bbs.c b/pttbbs/mbbsd/bbs.c index 50a5eee3..27c8ab25 100644 --- a/pttbbs/mbbsd/bbs.c +++ b/pttbbs/mbbsd/bbs.c @@ -659,16 +659,18 @@ do_generalboardreply(fileheader_t * fhdr) int getindex(char *fpath, char *fname, int size) { - int fd, now = 0; - fileheader_t fhdr; +#define READSIZE 64 // 8192 / sizeof(fileheader_t) + int fd, i, len, now = 1; /* now starts from 1 */ + fileheader_t fhdrs[READSIZE]; if ((fd = open(fpath, O_RDONLY, 0)) != -1) { - while ((read(fd, &fhdr, size) == size)) { - now++; - if (!strcmp(fhdr.filename, fname)) { - close(fd); - return now; - } + while( (len = read(fd, fhdrs, sizeof(fhdrs))) > 0 ){ + len /= sizeof(fileheader_t); + for( i = 0 ; i < len ; ++i, ++now ) + if (!strcmp(fhdrs[i].filename, fname)) { + close(fd); + return now; + } } close(fd); } diff --git a/pttbbs/mbbsd/read.c b/pttbbs/mbbsd/read.c index 1542ace5..cd20bd44 100644 --- a/pttbbs/mbbsd/read.c +++ b/pttbbs/mbbsd/read.c @@ -457,12 +457,13 @@ mail_forward(fileheader_t * fhdr, char *direct, int mode) static int select_read(keeploc_t * locmem, int sr_mode) { +#define READSIZE 64 // 8192 / sizeof(fileheader_t) char *tag, *query = NULL, *temp; - fileheader_t fh; + fileheader_t fhs[READSIZE]; char fpath[80], genbuf[MAXPATHLEN], buf3[5]; static char t_ans[TTLEN + 1] = ""; static char a_ans[TTLEN + 1] = ""; - int fd, fr, size = sizeof(fileheader_t); + int fd, fr, size = sizeof(fileheader_t), i, len; struct stat st; /* rocker.011018: make a reference number for process article */ int reference = 0; @@ -500,51 +501,67 @@ select_read(keeploc_t * locmem, int sr_mode) if (((fr = open(fpath, O_WRONLY | O_CREAT | O_TRUNC, 0600)) != -1)) { switch (sr_mode) { case RS_TITLE: - while (read(fd, &fh, size) == size) { - ++reference; - tag = subject(fh.title); - if (!strncmp(tag, query, 40)) { - fh.money = reference | FHR_REFERENCE; - write(fr, &fh, size); + while( (len = read(fd, fhs, sizeof(fhs))) > 0 ){ + len /= sizeof(fileheader_t); + for( i = 0 ; i < len ; ++i ){ + ++reference; + tag = subject(fhs[i].title); + if (!strncmp(tag, query, 40)) { + fhs[i].money = reference | FHR_REFERENCE; + write(fr, &fhs[i], size); + } } } break; case RS_RELATED: - while (read(fd, &fh, size) == size) { - ++reference; - tag = fh.title; - if (strcasestr(tag, query)) { - fh.money = reference | FHR_REFERENCE; - write(fr, &fh, size); + while( (len = read(fd, fhs, sizeof(fhs))) > 0 ){ + len /= sizeof(fileheader_t); + for( i = 0 ; i < len ; ++i ){ + ++reference; + tag = fhs[i].title; + if (strcasestr(tag, query)) { + fhs[i].money = reference | FHR_REFERENCE; + write(fr, &fhs[i], size); + } } } break; case RS_NEWPOST: - while (read(fd, &fh, size) == size) { - ++reference; - tag = fh.title; - temp = strstr(tag, query); - if (temp == NULL || temp != tag) { - fh.money = reference | FHR_REFERENCE; - write(fr, &fh, size); + while( (len = read(fd, fhs, sizeof(fhs))) > 0 ){ + len /= sizeof(fileheader_t); + for( i = 0 ; i < len ; ++i ){ + ++reference; + tag = fhs[i].title; + temp = strstr(tag, query); + if (temp == NULL || temp != tag) { + fhs[i].money = reference | FHR_REFERENCE; + write(fr, &fhs[i], size); + } } } + break; case RS_AUTHOR: - while (read(fd, &fh, size) == size) { - ++reference; - tag = fh.owner; - if (strcasestr(tag, query)) { - fh.money = reference | FHR_REFERENCE; - write(fr, &fh, size); + while( (len = read(fd, fhs, sizeof(fhs))) > 0 ){ + len /= sizeof(fileheader_t); + for( i = 0 ; i < len ; ++i ){ + ++reference; + tag = fhs[i].owner; + if (strcasestr(tag, query)) { + fhs[i].money = reference | FHR_REFERENCE; + write(fr, &fhs[i], size); + } } } break; - case RS_THREAD: - while (read(fd, &fh, size) == size) { - ++reference; - if (fh.filemode & FILE_MARKED) { - fh.money = reference | FHR_REFERENCE; - write(fr, &fh, size); + case RS_THREAD: + while( (len = read(fd, fhs, sizeof(fhs))) > 0 ){ + len /= sizeof(fileheader_t); + for( i = 0 ; i < len ; ++i ){ + ++reference; + if (fhs[i].filemode & FILE_MARKED) { + fhs[i].money = reference | FHR_REFERENCE; + write(fr, &fhs[i], size); + } } } break; -- cgit v1.2.3 From 6983880d852ea0d743ddf3fd4988fe65c26dbb66 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Thu, 4 Sep 2003 11:54:03 +0000 Subject: add modules git-svn-id: http://opensvn.csie.org/pttbbs/trunk@1158 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/blog/INSTALL | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pttbbs/blog/INSTALL b/pttbbs/blog/INSTALL index 29f1e566..64e60e8c 100644 --- a/pttbbs/blog/INSTALL +++ b/pttbbs/blog/INSTALL @@ -16,6 +16,9 @@ $Id: INSTALL,v 1.4 2003/07/06 03:58:43 in2 Exp $ Date::Calc /usr/ports/devel/p5-Date-Calc/ DBI /usr/ports/databases/p5-DBI/ DBD::mysql /usr/ports/databases/p5-DBD-mysql/ + MD5 /usr/ports/security/p5-MD5/ + Mail::Sender /usr/ports/mail/p5-Mail-Sender/ + OurNet::FuzzyIndex (還沒有進 ports, 請用 cpan 裝) 2.設定 apache 可以直接透過 mod_perl 來跑 perl script . 在您的 apache.conf (or httpd.conf)中, 應該會有: -- cgit v1.2.3 From 520ec4e2bceaa3debad68072d79f730d7003f1f7 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Thu, 4 Sep 2003 11:54:13 +0000 Subject: fix typo git-svn-id: http://opensvn.csie.org/pttbbs/trunk@1159 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/blog/builddb.pl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pttbbs/blog/builddb.pl b/pttbbs/blog/builddb.pl index 17c681fe..4c38c2a3 100755 --- a/pttbbs/blog/builddb.pl +++ b/pttbbs/blog/builddb.pl @@ -55,7 +55,7 @@ sub buildconfigure($$) my($board, $rch) = @_; my($outdir, $fn, $flag, %config, %attr); - $outdir = "$BLOGROOT/$board"; + $outdir = "$BLOGDATA/$board"; `/bin/rm -rf $outdir; /bin/mkdir -p $outdir`; tie(%config, 'DB_File', "$outdir/config.db", @@ -102,8 +102,8 @@ sub builddata($$$$$$) my($board, $rbh, $rebuild, $contentonly, $number, $force) = @_; my(%dat, $dbfn, $idxfn, $y, $m, $d, $t, $currid, $idx); - $dbfn = "$BLOGROOT/$board.db"; - $idxfn = "$BLOGROOT/$board.idx"; + $dbfn = "$BLOGDATA/$board.db"; + $idxfn = "$BLOGDATA/$board.idx"; if( $rebuild ){ unlink $dbfn; unlink $idxfn; -- cgit v1.2.3 From e0824354c67944868329dd7ba6496f66efc7b8dd Mon Sep 17 00:00:00 2001 From: kcwu <kcwu@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Fri, 5 Sep 2003 15:42:00 +0000 Subject: fix comment typo git-svn-id: http://opensvn.csie.org/pttbbs/trunk@1160 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/sample/pttbbs.conf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pttbbs/sample/pttbbs.conf b/pttbbs/sample/pttbbs.conf index 854bbeb9..0532cf04 100644 --- a/pttbbs/sample/pttbbs.conf +++ b/pttbbs/sample/pttbbs.conf @@ -14,7 +14,7 @@ #define BBSUID 9999 #define BBSGID 99 -/* 最大編輯行數, 以防有惡意使用使 post 巨大文章 */ +/* 最大編輯行數, 以防有惡意使用者 post 巨大文章 */ #define MAX_EDIT_LINE 2048 /* 若定義, 則可以免費隱形 */ @@ -23,7 +23,7 @@ /* 可以設定多重進站畫面 */ #define MULTI_WELCOME_LOGIN -/* 最大 CPU負荷, 超過的時候將拒決 login */ +/* 最大 CPU負荷, 超過的時候將拒絕 login */ #define MAX_CPULOAD (400) /* 最多註冊人數, 每個人會用掉 21 bytes 的 shared-memory */ -- cgit v1.2.3 From 537280b4347274976943dda29eb6caaf72f96c03 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sat, 6 Sep 2003 03:14:15 +0000 Subject: blog security fix git-svn-id: http://opensvn.csie.org/pttbbs/trunk@1161 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/announce.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/pttbbs/mbbsd/announce.c b/pttbbs/mbbsd/announce.c index c8f69baf..ac001d28 100644 --- a/pttbbs/mbbsd/announce.c +++ b/pttbbs/mbbsd/announce.c @@ -1133,8 +1133,16 @@ void BlogMain(int num) break; case '4':{ char hash[35]; + int i; getdata(16, 0, "請輸入該篇的雜湊值: ", hash, sizeof(hash), DOECHO); + for( i = 0 ; hash[i] != 0 ; ++i ) /* 前面用 getdata() 保證有 \0 */ + if( !islower(hash[i]) && !isnumber(hash[i]) ) + break; + if( i != 32 ){ + vmsg("輸入錯誤"); + break; + } if( hash[0] != 0 && getans("請確定刪除(Y/N)?[N] ") == 'y' ){ MYSQL mysql; -- cgit v1.2.3 From 4a36da6a44f47f7b815f79e5032e71bfd5218aea Mon Sep 17 00:00:00 2001 From: kcwu <kcwu@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sat, 6 Sep 2003 14:49:08 +0000 Subject: code cleanup git-svn-id: http://opensvn.csie.org/pttbbs/trunk@1162 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/cal.c | 4 +-- pttbbs/mbbsd/friend.c | 25 +++++++---------- pttbbs/mbbsd/gomo.c | 27 +++++++++--------- pttbbs/mbbsd/gomo1.c | 15 +++++++--- pttbbs/mbbsd/io.c | 78 ++++++++++++++++----------------------------------- pttbbs/mbbsd/mail.c | 2 +- pttbbs/mbbsd/page.c | 4 +-- pttbbs/mbbsd/stuff.c | 5 ++-- 8 files changed, 65 insertions(+), 95 deletions(-) diff --git a/pttbbs/mbbsd/cal.c b/pttbbs/mbbsd/cal.c index 1567f0c2..89383f99 100644 --- a/pttbbs/mbbsd/cal.c +++ b/pttbbs/mbbsd/cal.c @@ -1,4 +1,4 @@ -/* $Id: cal.c,v 1.27 2003/06/22 04:32:38 in2 Exp $ */ +/* $Id$ */ #include "bbs.h" /* 防堵 Multi play */ @@ -8,7 +8,7 @@ count_multiplay(int unmode) register int i, j; register userinfo_t *uentp; - for (i = j = 0; i < USHM_SIZE; i++) { + for (i = j = 0; i < USHM_SIZE; i++) { // XXX linear search uentp = &(SHM->uinfo[i]); if (uentp->uid == usernum) if (uentp->lockmode == unmode) diff --git a/pttbbs/mbbsd/friend.c b/pttbbs/mbbsd/friend.c index 39ef2148..16e36c63 100644 --- a/pttbbs/mbbsd/friend.c +++ b/pttbbs/mbbsd/friend.c @@ -56,22 +56,15 @@ setfriendfile(char *fpath, int type) setbfile(fpath, currboard, friend_file[type]); } -static unsigned int +static int friend_count(char *fname) { FILE *fp; int count = 0; char buf[200]; -#if 0 - if ((fp = fopen(fname, "r"))) - while (fgets(buf, 200, fp)) - count++; -#endif - - /* rocker.011018: 忘記關檔了... */ if ((fp = fopen(fname, "r"))) { - while (fgets(buf, 200, fp)) + while (fgets(buf, sizeof(buf), fp)) count++; fclose(fp); } @@ -218,7 +211,7 @@ friend_delete(char *uident, int type) setfriendfile(fn, type); sprintf(fnnew, "%s-", fn); - if ((fp = fopen(fn, "r")) && (nfp = fopen(fnnew, "w"))) { // XXX fclose(fp) if nfp fail + if ((fp = fopen(fn, "r")) && (nfp = fopen(fnnew, "w"))) { int length = strlen(uident); while (fgets(genbuf, STRLEN, fp)) @@ -235,11 +228,11 @@ friend_delete(char *uident, int type) static void friend_editdesc(char *uident, int type) { - FILE *fp, *nfp; - char fnnew[200], genbuf[200], fn[200]; + FILE *fp=NULL, *nfp=NULL; + char fnnew[200], genbuf[STRLEN], fn[200]; setfriendfile(fn, type); snprintf(fnnew, sizeof(fnnew), "%s-", fn); - if ((fp = fopen(fn, "r")) && (nfp = fopen(fnnew, "w"))) { // XXX fclose(fp) if nfp fail + if ((fp = fopen(fn, "r")) && (nfp = fopen(fnnew, "w"))) { int length = strlen(uident); while (fgets(genbuf, STRLEN, fp)) { @@ -251,10 +244,12 @@ friend_editdesc(char *uident, int type) fprintf(nfp, "%-13s%s\n", uident, buf); } } - fclose(fp); - fclose(nfp); Rename(fnnew, fn); } + if(fp) + fclose(fp); + if(nfp) + fclose(nfp); } /* type == 0 : load all */ diff --git a/pttbbs/mbbsd/gomo.c b/pttbbs/mbbsd/gomo.c index 3a8fcd5f..0b64e709 100644 --- a/pttbbs/mbbsd/gomo.c +++ b/pttbbs/mbbsd/gomo.c @@ -1,4 +1,4 @@ -/* $Id: gomo.c,v 1.12 2003/01/19 16:06:06 kcwu Exp $ */ +/* $Id$ */ #include "bbs.h" static char *chess[] = {"●", "○"}; @@ -113,7 +113,7 @@ gomo_key(int fd, int ch, Horder_t * mv) if (ch >= 'a' && ch <= 'o') { char pbuf[4], vx, vy; - *pbuf = ch; + pbuf[0] = ch; if (fd) add_io(0, 0); oldgetdata(17, 0, "直接指定位置 :", pbuf, sizeof(pbuf), DOECHO); @@ -130,16 +130,20 @@ gomo_key(int fd, int ch, Horder_t * mv) } else { switch (ch) { case KEY_RIGHT: - mv->x = (mv->x == BRDSIZ - 1) ? mv->x : mv->x + 1; + if(mv->x<BRDSIZ-1) + mv->x++; break; case KEY_LEFT: - mv->x = (mv->x == 0) ? 0 : mv->x - 1; + if(mv->x>0) + mv->x--; break; case KEY_UP: - mv->y = (mv->y == BRDSIZ - 1) ? mv->y : mv->y + 1; + if(mv->y<BRDSIZ-1) + mv->y++; break; case KEY_DOWN: - mv->y = (mv->y == 0) ? 0 : mv->y - 1; + if(mv->y>0) + mv->y--; break; case ' ': case '\r': @@ -164,7 +168,7 @@ int gomoku(int fd) { Horder_t mv; - int me, he, win, ch; + int me, he, ch; int hewantpass, iwantpass; userinfo_t *my = currutmp; Horder_t pool[BRDSIZ*BRDSIZ]; @@ -172,7 +176,6 @@ gomoku(int fd) HO_init(pool); me = !(my->turn) + 1; he = my->turn + 1; - win = 1; tick = now + MAX_TIME; lastcount = MAX_TIME; setutmpmode(M_FIVE); @@ -227,7 +230,6 @@ gomoku(int fd) if (lastcount <= -5 && !my->turn) { move(19, 40); outs("對手太久沒下, 你贏了!"); - win = 1; cuser.five_lose--; cuser.five_win++; my->five_win++; @@ -276,7 +278,6 @@ gomoku(int fd) } continue; } else if (hewantpass) { - win = 0; cuser.five_lose--; cuser.five_tie++; my->five_tie++; @@ -292,7 +293,6 @@ gomoku(int fd) if (ch != sizeof(Horder_t)) { lastcount = tick - now; if (lastcount >= 0) { - win = 1; cuser.five_lose--; if (countgomo(pool) >= 10) { cuser.five_win++; @@ -302,14 +302,12 @@ gomoku(int fd) outmsg("對方認輸了!!"); break; } else { - win = 0; outmsg("你超過時間未下子, 輸了!"); my->five_lose++; break; } } else if (mv.x == -2 && mv.y == -2) { if (iwantpass == 1) { - win = 0; cuser.five_lose--; cuser.five_tie++; my->five_tie++; @@ -329,6 +327,7 @@ gomoku(int fd) continue; } if (!my->turn) { + int win; win = chkmv(&mv, he, he == BBLACK); HO_add(&mv); hislasttick = tick; @@ -347,7 +346,6 @@ gomoku(int fd) passwd_update(usernum, &cuser); } else my->five_lose++; - win = -win; break; } my->turn = 1; @@ -361,6 +359,7 @@ gomoku(int fd) continue; if (!my->turn) { + int win; HO_add(&mv); BGOTO(mv.x, mv.y); outs(chess[me - 1]); diff --git a/pttbbs/mbbsd/gomo1.c b/pttbbs/mbbsd/gomo1.c index 260ce88f..49d484a5 100644 --- a/pttbbs/mbbsd/gomo1.c +++ b/pttbbs/mbbsd/gomo1.c @@ -1,4 +1,4 @@ -/* $Id: gomo1.c,v 1.4 2002/07/21 09:26:02 in2 Exp $ */ +/* $Id$ */ #include "bbs.h" #define QCAST int (*)(const void *, const void *) @@ -11,12 +11,15 @@ intrevcmp(const void *a, const void *b) return (*(int *)b - *(int *)a); } +// 以 (x,y) 為起點, 方向 (dx,dy), 傳回以 bit 表示相鄰哪幾格有子 +// 如 10111 表示該方向相鄰 1,2,3 有子, 4 空地 +// 最高位 1 表示對方的子, 或是牆 /* x,y: 0..BRDSIZ-1 ; color: CBLACK,CWHITE ; dx,dy: -1,0,+1 */ static int gomo_getindex(int x, int y, int color, int dx, int dy) { int i, k, n; - for (n = -1, i = 0, k = 1; i < 5; i++, k <<= 1) { + for (n = -1, i = 0, k = 1; i < 5; i++, k*=2) { x += dx; y += dy; @@ -73,9 +76,12 @@ dirchk(int x, int y, int color, int limit, int dx, int dy) if ((style == 3) || (style == 2)) { int i, n = 0, tmp, nx, ny; - n = adv[loc >> 1]; + n = adv[loc / 2]; - ((loc & 1) == 0) ? (n >>= 4) : (n &= 0x0f); + if(loc%2==0) + n/=16; + else + n%=16; ku[x][y] = color; @@ -110,6 +116,7 @@ getstyle(int x, int y, int color, int limit) if (ku[x][y] != BBLANK) return 0x0d; + // (-1,1), (0,1), (1,0), (1,1) for (i = 0; i < 4; i++) dir[i] = dirchk(x, y, color, limit, i ? (i >> 1) : -1, i ? (i & 1) : 1); diff --git a/pttbbs/mbbsd/io.c b/pttbbs/mbbsd/io.c index 0a48893d..6f3cff9e 100644 --- a/pttbbs/mbbsd/io.c +++ b/pttbbs/mbbsd/io.c @@ -324,8 +324,6 @@ igetch() return 0; } -#define min(a, b) (((a) > (b)) ? (b) : (a)) - int oldgetdata(int line, int col, char *prompt, char *buf, int len, int echo) { @@ -338,15 +336,12 @@ oldgetdata(int line, int col, char *prompt, char *buf, int len, int echo) strip_ansi(buf, buf, STRIP_ALL); if (prompt) { - move(line, col); - clrtoeol(); - outs(prompt); - x += strip_ansi(NULL, prompt, 0); } + if (!echo) { len--; clen = 0; @@ -357,32 +352,15 @@ oldgetdata(int line, int col, char *prompt, char *buf, int len, int echo) continue; } clen--; - if (echo) { - ochar(Ctrl('H')); - ochar(' '); - ochar(Ctrl('H')); - } continue; } - //Ptt -#ifdef BIT8 - if (!isprint2(ch)) -#else - if (!isprint(ch)) -#endif - { - if (echo) - bell(); + if (!isprint(ch)) { continue; } if (clen >= len) { - if (echo) - bell(); continue; } buf[clen++] = ch; - if (echo) - ochar(ch); } buf[clen] = '\0'; outc('\n'); @@ -392,31 +370,26 @@ oldgetdata(int line, int col, char *prompt, char *buf, int len, int echo) int currchar = 0; standout(); - for (clen = len--; clen; clen--) + for(i=0; i<len; i++) outc(' '); standend(); - buf[len] = 0; + len--; + buf[len] = '\0'; move(y, x); edit_outs(buf); clen = currchar = strlen(buf); while (move(y, x + currchar), (ch = igetkey()) != '\r') { switch (ch) { - case KEY_DOWN: - case Ctrl('N'): - buf[clen] = '\0'; /* Ptt */ - strncpy(lastcmd[cmdpos], buf, min(clen, 79)); - cmdpos += MAXLASTCMD - 2; - case Ctrl('P'): - case KEY_UP: - if (ch == KEY_UP || ch == Ctrl('P')) { - buf[clen] = '\0'; /* Ptt */ - strncpy(lastcmd[cmdpos], buf, min(clen, 79)); - } - cmdpos++; + case KEY_DOWN: case Ctrl('N'): + case KEY_UP: case Ctrl('P'): + strlcpy(lastcmd[cmdpos], buf, sizeof(lastcmd[0])); + if (ch == KEY_UP || ch == Ctrl('P')) + cmdpos++; + else + cmdpos += MAXLASTCMD - 1; cmdpos %= MAXLASTCMD; - strncpy(buf, lastcmd[cmdpos], min(len, 79)); - buf[len] = 0; + strlcpy(buf, lastcmd[cmdpos], len+1); move(y, x); /* clrtoeof */ for (i = 0; i <= clen; i++) @@ -449,7 +422,7 @@ oldgetdata(int line, int col, char *prompt, char *buf, int len, int echo) case Ctrl('Y'): currchar = 0; case Ctrl('K'): - buf[currchar] = 0; + buf[currchar] = '\0'; move(y, x + currchar); for (i = currchar; i < clen; i++) outc(' '); @@ -489,20 +462,18 @@ oldgetdata(int line, int col, char *prompt, char *buf, int len, int echo) } /* end case */ } /* end while */ - if (clen > 1) - for (cmdpos = MAXLASTCMD - 1; cmdpos; cmdpos--) { - strlcpy(lastcmd[cmdpos], lastcmd[cmdpos - 1], - sizeof(lastcmd[cmdpos])); - strncpy(lastcmd[0], buf, len); - } - if (echo) - outc('\n'); + if (clen > 1) { + strlcpy(lastcmd[0], buf, sizeof(lastcmd[0])); + memmove(lastcmd+1, lastcmd, (MAXLASTCMD-1)*sizeof(lastcmd[0])); + } + outc('\n'); refresh(); } - if ((echo == LCECHO) && ((ch = buf[0]) >= 'A') && (ch <= 'Z')) - buf[0] = ch | 32; + if ((echo == LCECHO) && isupper(buf[0])) + buf[0] = tolower(buf[0]); #ifdef SUPPORT_GB if (echo == DOECHO && current_font_type == TYPE_GB) { + // FIXME check buffer length strcpy(buf, hc_convert_str(buf, HC_GBtoBIG, HC_DO_SINGLE)); } #endif @@ -528,9 +499,8 @@ getans(char *prompt) int getdata_str(int line, int col, char *prompt, char *buf, int len, int echo, char *defaultstr) { - strncpy(buf, defaultstr, len); + strlcpy(buf, defaultstr, len); - buf[len - 1] = 0; return oldgetdata(line, col, prompt, buf, len, echo); } @@ -553,7 +523,7 @@ rget(int x, char *prompt) ch = igetch(); if (ch >= 'A' && ch <= 'Z') - ch |= 32; + ch = tolower(ch); return ch; } diff --git a/pttbbs/mbbsd/mail.c b/pttbbs/mbbsd/mail.c index bca23743..b45bde0c 100644 --- a/pttbbs/mbbsd/mail.c +++ b/pttbbs/mbbsd/mail.c @@ -1,6 +1,6 @@ /* $Id$ */ #include "bbs.h" -char currmaildir[32]; +static char currmaildir[32]; static char msg_cc[] = "\033[32m[群組名單]\033[m\n"; static char listfile[] = "list.0"; static int mailkeep = 0, mailsum = 0; diff --git a/pttbbs/mbbsd/page.c b/pttbbs/mbbsd/page.c index e1bcd052..9583f4c9 100644 --- a/pttbbs/mbbsd/page.c +++ b/pttbbs/mbbsd/page.c @@ -1,10 +1,10 @@ -/* $Id: page.c,v 1.11 2003/02/11 06:03:31 victor Exp $ */ +/* $Id$ */ #include "bbs.h" #define hpressanykey(a) {move(22, 0); prints(a); pressanykey();} #define TITLE "\033[1;37;45m 火車查詢系統 \033[1;44;33m原作者:Heat\033[m" -void +static void print_station(const char *addr[6][100], int path, int *line, int *num) { int i; diff --git a/pttbbs/mbbsd/stuff.c b/pttbbs/mbbsd/stuff.c index 80428954..9f13b2ef 100644 --- a/pttbbs/mbbsd/stuff.c +++ b/pttbbs/mbbsd/stuff.c @@ -1,4 +1,4 @@ -/* $Id: stuff.c,v 1.13 2003/07/20 00:55:34 in2 Exp $ */ +/* $Id$ */ #include "bbs.h" /* ----------------------------------------------------- */ @@ -158,8 +158,7 @@ trim(char *buf) int isprint2(char ch) { - return ((ch & 0x80) ? 1 : isprint(ch)); - //return 1; + return ((ch & 0x80) || isprint(ch)); } int -- cgit v1.2.3 From 62440ae3be847691d6944e64e81035de7c56b0df Mon Sep 17 00:00:00 2001 From: kcwu <kcwu@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sat, 6 Sep 2003 15:02:29 +0000 Subject: clean up git-svn-id: http://opensvn.csie.org/pttbbs/trunk@1163 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/include/common.h | 6 +-- pttbbs/include/config.h | 6 +-- pttbbs/mbbsd/xyz.c | 115 +++--------------------------------------------- 3 files changed, 11 insertions(+), 116 deletions(-) diff --git a/pttbbs/include/common.h b/pttbbs/include/common.h index 309f49c5..18d377c2 100644 --- a/pttbbs/include/common.h +++ b/pttbbs/include/common.h @@ -1,4 +1,4 @@ -/* $Id: common.h,v 1.6 2003/05/26 05:30:22 in2 Exp $ */ +/* $Id$ */ #ifndef INCLUDE_COMMON_H #define INCLUDE_COMMON_H @@ -175,10 +175,10 @@ #define MAX_MODES 127 #ifndef MIN -#define MIN(a,b) ((a<b)?a:b) +#define MIN(a,b) (((a)<(b))?(a):(b)) #endif #ifndef MAX -#define MAX(a,b) ((a>b)?a:b) +#define MAX(a,b) (((a)>(b))?(a):(b)) #endif #define char_lower(c) ((c >= 'A' && c <= 'Z') ? c|32 : c) diff --git a/pttbbs/include/config.h b/pttbbs/include/config.h index 23bca878..d7dd1606 100644 --- a/pttbbs/include/config.h +++ b/pttbbs/include/config.h @@ -1,4 +1,4 @@ -/* $Id: config.h,v 1.10 2003/05/10 16:52:01 bbs Exp $ */ +/* $Id$ */ #ifndef INCLUDE_CONFIG_H #define INCLUDE_CONFIG_H @@ -134,12 +134,8 @@ #undef HAVE_REPORT /* 系統追蹤報告 */ #undef HAVE_INFO /* 顯示程式板本說明 */ #undef HAVE_LICENSE /* 顯示 GNU 板權畫面 */ -#undef HAVE_TIN /* 提供 news reader */ -#undef HAVE_GOPHER /* 提供 gopher */ -#undef HAVE_WWW /* 提供 www browser */ #define FAST_LOGIN /* Login 不檢查遠端使用者 */ #define HAVE_CAL /* 提功計算機 */ -#undef HAVE_ARCHIE /* have arche */ #undef POSTBUG /* board/mail post 沒有 bug 了 */ #undef HAVE_REPORT /* 系統追蹤報告 */ #undef EMAIL_JUSTIFY /* 發出 InterNet Email 身份認證信函 */ diff --git a/pttbbs/mbbsd/xyz.c b/pttbbs/mbbsd/xyz.c index 9f9aa4d0..aead7e5d 100644 --- a/pttbbs/mbbsd/xyz.c +++ b/pttbbs/mbbsd/xyz.c @@ -1,4 +1,4 @@ -/* $Id: xyz.c,v 1.19 2003/03/31 08:27:50 in2 Exp $ */ +/* $Id$ */ #include "bbs.h" #if 0 @@ -244,13 +244,13 @@ note() collect = 1; while (total) { - snprintf(buf, sizeof(buf), "\033[1;31m╭┤\033[32m %s \033[37m(%s)", + snprintf(buf, sizeof(buf), "\033[1;31m┤\033[32m %s \033[37m(%s)", myitem.userid, myitem.username); len = strlen(buf); for (i = len; i < 71; i++) strcat(buf, " "); - snprintf(buf2, sizeof(buf2), " \033[1;36m%.16s\033[31m ├╮\033[m\n", + snprintf(buf2, sizeof(buf2), " \033[1;36m%.16s\033[31m ├\033[m\n", Cdate(&(myitem.date))); strcat(buf, buf2); fputs(buf, fp); @@ -263,12 +263,12 @@ note() fprintf(foo, "\033[1;31m│\033[m%-74.74s\033[1;31m│\033[m\n", myitem.buf[i]); } - fputs("\033[1;31m╰┬───────────────────────" - "────────────┬╯\033[m\n", fp); + fputs("\033[1;31m┬───────────────────────" + "────────────┬\033[m\n", fp); if (collect) { - fputs("\033[1;31m╰┬─────────────────────" - "──────────────┬╯\033[m\n", foo); + fputs("\033[1;31m┬─────────────────────" + "──────────────┬\033[m\n", foo); fclose(foo); collect = 0; } @@ -392,104 +392,3 @@ Goodbye() u_exit("EXIT "); return QUIT; } - -/* 支援外掛程式 : tin、gopher、www、bbsnet、game、csh */ -#define LOOKFIRST (0) -#define LOOKLAST (1) -#define QUOTEMODE (2) -#define MAXCOMSZ (1024) -#define MAXARGS (40) -#define MAXENVS (20) -#define BINDIR BBSHOME"/bin/" - -#ifdef HAVE_TIN -static int -x_tin() -{ - clear(); - return exec_cmd(NEWS, YEA, "bin/tin.sh", "TIN"); -} -#endif - -#ifdef HAVE_GOPHER -static int -x_gopher() -{ - clear(); - return exec_cmd(GOPHER, YEA, "bin/gopher.sh", "GOPHER"); -} -#endif - -#ifdef HAVE_WWW -static int -x_www() -{ - return exec_cmd(WWW, NA, "bin/www.sh", "WWW"); -} -#endif - -#ifdef HAVE_IRC -static int -x_irc() -{ - return exec_cmd(XMODE, NA, "bin/irc.sh", "IRC"); -} -#endif - -#ifdef HAVE_ARCHIE -static int -x_archie() -{ - char buf[STRLEN], ans[4]; - char genbuf1[100], genbuf2[200]; - char *s; - - setutmpmode(ARCHIE); - clear(); - outs("\n歡迎光臨【\033[1;33;44m" BBSNAME "\033[m】使用 " - "\033[32mARCHIE\033[m 功\能\n"); - outs("\n本功\能將為您列出在哪個 FTP 站存有您欲尋找的檔案.\n"); - outs("\n請輸入欲搜尋的字串, 或直接按 <ENTER> 取消。\n"); - outs("\n coder by Harimau\n"); - outs(" modified by Leeym\n"); - getdata(13, 0, "搜尋字串:", buf, 20, DOECHO, 0); - if (buf[0] == '\0') { - prints("\n取消搜尋.....\n"); - pressanykey(); - return; - } - for (s = buf; *s != '\0'; s++) { - if (isspace(*s)) { - prints("\n一次只能搜尋一個字串啦, 不能太貪心喔!!"); - pressanykey(); - return; - } - } - bbssetenv("ARCHIESTRING", buf); - exec_cmd(ARCHIE, YEA, "bin/archie.sh", ARCHIE); - log_usies("ARCHIE", ""); - strcpy(genbuf1, buf); - snprintf(buf, sizeof(buf), BBSHOME "/tmp/archie.%s", cuser.userid); - if (dashf(buf)) { - getdata(0, 0, "要將結果寄回信箱嗎(Y/N)?[N]", - ans, sizeof(ans), DOECHO, 0); - if (*ans == 'y') { - fileheader_t mhdr; - char title[128], buf1[80]; - - sethomepath(buf1, cuser.userid); - stampfile(buf1, &mhdr); - strcpy(mhdr.owner, cuser.userid); - sprintf(genbuf2, sizeof(genbuf2), - "Archie 搜尋檔案: %s 結果", genbuf1); - strcpy(mhdr.title, genbuf2); - mhdr.filemode = 0; - sethomedir(title, cuser.userid); - append_record(title, &mhdr, sizeof(mhdr)); - Link(buf, buf1); - } - more(buf, YEA); - unlink(buf); - } -} -#endif /* HAVE_ARCHIE */ -- cgit v1.2.3 From eae7607bcc465e193058b638ae9cf2ae4f217388 Mon Sep 17 00:00:00 2001 From: kcwu <kcwu@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sat, 6 Sep 2003 15:13:25 +0000 Subject: fix typo git-svn-id: http://opensvn.csie.org/pttbbs/trunk@1164 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/include/config.h | 4 ++-- pttbbs/mbbsd/menu.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pttbbs/include/config.h b/pttbbs/include/config.h index d7dd1606..88d70e5a 100644 --- a/pttbbs/include/config.h +++ b/pttbbs/include/config.h @@ -132,8 +132,8 @@ #undef HAVE_MAILCLEAN /* 清理所有使用者個人信箱 */ #undef HAVE_SUICIDE /* 提供使用者自殺功能 */ #undef HAVE_REPORT /* 系統追蹤報告 */ -#undef HAVE_INFO /* 顯示程式板本說明 */ -#undef HAVE_LICENSE /* 顯示 GNU 板權畫面 */ +#undef HAVE_INFO /* 顯示程式版本說明 */ +#undef HAVE_LICENSE /* 顯示 GNU 版權畫面 */ #define FAST_LOGIN /* Login 不檢查遠端使用者 */ #define HAVE_CAL /* 提功計算機 */ #undef POSTBUG /* board/mail post 沒有 bug 了 */ diff --git a/pttbbs/mbbsd/menu.c b/pttbbs/mbbsd/menu.c index c506b3e9..bca66e7b 100644 --- a/pttbbs/mbbsd/menu.c +++ b/pttbbs/mbbsd/menu.c @@ -412,7 +412,7 @@ static commands_t xyzlist[] = { {x_gpl, 0, "LLicense GNU 使用執照"}, #endif #ifdef HAVE_INFO - {x_program, 0, "PProgram 本程式之板本與板權宣告"}, + {x_program, 0, "PProgram 本程式之版本與版權宣告"}, #endif {x_boardman,0, "MMan Boards 《看板精華區排行榜》"}, // {x_boards,0, "HHot Boards 《看板人氣排行榜》"}, -- cgit v1.2.3 From 74c7e56bd69d31a5fc16b3badbf58099aa9e5c51 Mon Sep 17 00:00:00 2001 From: kcwu <kcwu@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sat, 6 Sep 2003 15:16:56 +0000 Subject: unused code git-svn-id: http://opensvn.csie.org/pttbbs/trunk@1165 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/descrypt.c | 621 ------------------------------------------------ 1 file changed, 621 deletions(-) delete mode 100644 pttbbs/mbbsd/descrypt.c diff --git a/pttbbs/mbbsd/descrypt.c b/pttbbs/mbbsd/descrypt.c deleted file mode 100644 index 30d33b8b..00000000 --- a/pttbbs/mbbsd/descrypt.c +++ /dev/null @@ -1,621 +0,0 @@ -/* $Id: descrypt.c,v 1.4 2002/07/21 09:26:02 in2 Exp $ */ - -/* - * FreeSec: libcrypt for NetBSD - * - * Copyright (c) 1994 David Burren All rights reserved. - * - * Adapted for FreeBSD-2.0 by Geoffrey M. Rehmet crypt.c should now *only* - * export crypt(), in order to make binaries of libcrypt exportable from the - * USA - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. 2. - * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. 4. Neither the name - * of the author nor the names of other contributors may be used to endorse - * or promote products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR - * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD: src/secure/lib/libcrypt/crypt.c,v 1.11 1999/08/28 01:30:24 peter - * Exp $ - * - * This is an original implementation of the DES and the crypt(3) interfaces by - * David Burren <davidb@werj.com.au>. - * - * An excellent reference on the underlying algorithm (and related algorithms) - * is: - * - * B. Schneier, Applied Cryptography: protocols, algorithms, and source code in - * C, John Wiley & Sons, 1994. - * - * Note that in that book's description of DES the lookups for the initial, - * pbox, and final permutations are inverted (this has been brought to the - * attention of the author). A list of errata for this book has been posted - * to the sci.crypt newsgroup by the author and is available for FTP. - * - * ARCHITECTURE ASSUMPTIONS: This code assumes that u_longs are 32 bits. It - * will probably not operate on 64-bit machines without modifications. It is - * assumed that the 8-byte arrays passed by reference can be addressed as - * arrays of u_longs (ie. the CPU is not picky about alignment). - */ - -#ifndef HAVE_DES_CRYPT - -#include <sys/types.h> -#include <sys/param.h> -#include <pwd.h> -#include <string.h> - -static unsigned char IP[64] = { - 58, 50, 42, 34, 26, 18, 10, 2, 60, 52, 44, 36, 28, 20, 12, 4, - 62, 54, 46, 38, 30, 22, 14, 6, 64, 56, 48, 40, 32, 24, 16, 8, - 57, 49, 41, 33, 25, 17, 9, 1, 59, 51, 43, 35, 27, 19, 11, 3, - 61, 53, 45, 37, 29, 21, 13, 5, 63, 55, 47, 39, 31, 23, 15, 7 -}; - -static unsigned char inv_key_perm[64]; -static unsigned char u_key_perm[56]; -static unsigned char key_perm[56] = { - 57, 49, 41, 33, 25, 17, 9, 1, 58, 50, 42, 34, 26, 18, - 10, 2, 59, 51, 43, 35, 27, 19, 11, 3, 60, 52, 44, 36, - 63, 55, 47, 39, 31, 23, 15, 7, 62, 54, 46, 38, 30, 22, - 14, 6, 61, 53, 45, 37, 29, 21, 13, 5, 28, 20, 12, 4 -}; - -static unsigned char key_shifts[16] = { - 1, 1, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 1 -}; - -static unsigned char inv_comp_perm[56]; -static unsigned char comp_perm[48] = { - 14, 17, 11, 24, 1, 5, 3, 28, 15, 6, 21, 10, - 23, 19, 12, 4, 26, 8, 16, 7, 27, 20, 13, 2, - 41, 52, 31, 37, 47, 55, 30, 40, 51, 45, 33, 48, - 44, 49, 39, 56, 34, 53, 46, 42, 50, 36, 29, 32 -}; - -/* - * No E box is used, as it's replaced by some ANDs, shifts, and ORs. - */ - -static unsigned char u_sbox[8][64]; -static unsigned char sbox[8][64] = { - { - 14, 4, 13, 1, 2, 15, 11, 8, 3, 10, 6, 12, 5, 9, 0, 7, - 0, 15, 7, 4, 14, 2, 13, 1, 10, 6, 12, 11, 9, 5, 3, 8, - 4, 1, 14, 8, 13, 6, 2, 11, 15, 12, 9, 7, 3, 10, 5, 0, - 15, 12, 8, 2, 4, 9, 1, 7, 5, 11, 3, 14, 10, 0, 6, 13 - }, - { - 15, 1, 8, 14, 6, 11, 3, 4, 9, 7, 2, 13, 12, 0, 5, 10, - 3, 13, 4, 7, 15, 2, 8, 14, 12, 0, 1, 10, 6, 9, 11, 5, - 0, 14, 7, 11, 10, 4, 13, 1, 5, 8, 12, 6, 9, 3, 2, 15, - 13, 8, 10, 1, 3, 15, 4, 2, 11, 6, 7, 12, 0, 5, 14, 9 - }, - { - 10, 0, 9, 14, 6, 3, 15, 5, 1, 13, 12, 7, 11, 4, 2, 8, - 13, 7, 0, 9, 3, 4, 6, 10, 2, 8, 5, 14, 12, 11, 15, 1, - 13, 6, 4, 9, 8, 15, 3, 0, 11, 1, 2, 12, 5, 10, 14, 7, - 1, 10, 13, 0, 6, 9, 8, 7, 4, 15, 14, 3, 11, 5, 2, 12 - }, - { - 7, 13, 14, 3, 0, 6, 9, 10, 1, 2, 8, 5, 11, 12, 4, 15, - 13, 8, 11, 5, 6, 15, 0, 3, 4, 7, 2, 12, 1, 10, 14, 9, - 10, 6, 9, 0, 12, 11, 7, 13, 15, 1, 3, 14, 5, 2, 8, 4, - 3, 15, 0, 6, 10, 1, 13, 8, 9, 4, 5, 11, 12, 7, 2, 14 - }, - { - 2, 12, 4, 1, 7, 10, 11, 6, 8, 5, 3, 15, 13, 0, 14, 9, - 14, 11, 2, 12, 4, 7, 13, 1, 5, 0, 15, 10, 3, 9, 8, 6, - 4, 2, 1, 11, 10, 13, 7, 8, 15, 9, 12, 5, 6, 3, 0, 14, - 11, 8, 12, 7, 1, 14, 2, 13, 6, 15, 0, 9, 10, 4, 5, 3 - }, - { - 12, 1, 10, 15, 9, 2, 6, 8, 0, 13, 3, 4, 14, 7, 5, 11, - 10, 15, 4, 2, 7, 12, 9, 5, 6, 1, 13, 14, 0, 11, 3, 8, - 9, 14, 15, 5, 2, 8, 12, 3, 7, 0, 4, 10, 1, 13, 11, 6, - 4, 3, 2, 12, 9, 5, 15, 10, 11, 14, 1, 7, 6, 0, 8, 13 - }, - { - 4, 11, 2, 14, 15, 0, 8, 13, 3, 12, 9, 7, 5, 10, 6, 1, - 13, 0, 11, 7, 4, 9, 1, 10, 14, 3, 5, 12, 2, 15, 8, 6, - 1, 4, 11, 13, 12, 3, 7, 14, 10, 15, 6, 8, 0, 5, 9, 2, - 6, 11, 13, 8, 1, 4, 10, 7, 9, 5, 0, 15, 14, 2, 3, 12 - }, - { - 13, 2, 8, 4, 6, 15, 11, 1, 10, 9, 3, 14, 5, 0, 12, 7, - 1, 15, 13, 8, 10, 3, 7, 4, 12, 5, 6, 11, 0, 14, 9, 2, - 7, 11, 4, 1, 9, 12, 14, 2, 0, 6, 10, 13, 15, 3, 5, 8, - 2, 1, 14, 7, 4, 10, 8, 13, 15, 12, 9, 0, 3, 5, 6, 11 - } -}; - -static unsigned char un_pbox[32]; -static unsigned char pbox[32] = { - 16, 7, 20, 21, 29, 12, 28, 17, 1, 15, 23, 26, 5, 18, 31, 10, - 2, 8, 24, 14, 32, 27, 3, 9, 19, 13, 30, 6, 22, 11, 4, 25 -}; - -static unsigned long bits32[32] = { - 0x80000000, 0x40000000, 0x20000000, 0x10000000, - 0x08000000, 0x04000000, 0x02000000, 0x01000000, - 0x00800000, 0x00400000, 0x00200000, 0x00100000, - 0x00080000, 0x00040000, 0x00020000, 0x00010000, - 0x00008000, 0x00004000, 0x00002000, 0x00001000, - 0x00000800, 0x00000400, 0x00000200, 0x00000100, - 0x00000080, 0x00000040, 0x00000020, 0x00000010, - 0x00000008, 0x00000004, 0x00000002, 0x00000001 -}; - -static unsigned char bits8[8] = {0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01}; - -static unsigned long saltbits; -static long old_salt; -static unsigned long *bits28, *bits24; -static unsigned char init_perm[64], final_perm[64]; -static unsigned long en_keysl[16], en_keysr[16]; -static unsigned long de_keysl[16], de_keysr[16]; -static int des_initialised = 0; -static unsigned char m_sbox[4][4096]; -static unsigned long psbox[4][256]; -static unsigned long ip_maskl[8][256], ip_maskr[8][256]; -static unsigned long fp_maskl[8][256], fp_maskr[8][256]; -static unsigned long key_perm_maskl[8][128], key_perm_maskr[8][128]; -static unsigned long comp_maskl[8][128], comp_maskr[8][128]; -static unsigned long old_rawkey0, old_rawkey1; - -static unsigned char ascii64[] = -"./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; -/* 0000000000111111111122222222223333333333444444444455555555556666 */ -/* 0123456789012345678901234567890123456789012345678901234567890123 */ - -static int -ascii_to_bin(char ch) -{ - if (ch > 'z') - return 0; - if (ch >= 'a') - return ch - 'a' + 38; - if (ch > 'Z') - return 0; - if (ch >= 'A') - return ch - 'A' + 12; - if (ch > '9') - return 0; - if (ch >= '.') - return ch - '.'; - return 0; -} - -static void -des_init() -{ - int i, j, b, k, inbit, obit; - unsigned long *p, *il, *ir, *fl, *fr; - - old_rawkey0 = old_rawkey1 = 0L; - saltbits = 0L; - old_salt = 0L; - bits24 = (bits28 = bits32 + 4) + 4; - - /* - * Invert the S-boxes, reordering the input bits. - */ - for (i = 0; i < 8; i++) - for (j = 0; j < 64; j++) { - b = (j & 0x20) | ((j & 1) << 4) | ((j >> 1) & 0xf); - u_sbox[i][j] = sbox[i][b]; - } - - /* - * Convert the inverted S-boxes into 4 arrays of 8 bits. Each will handle - * 12 bits of the S-box input. - */ - for (b = 0; b < 4; b++) - for (i = 0; i < 64; i++) - for (j = 0; j < 64; j++) - m_sbox[b][(i << 6) | j] = - (u_sbox[(b << 1)][i] << 4) | - u_sbox[(b << 1) + 1][j]; - - /* - * Set up the initial & final permutations into a useful form, and - * initialise the inverted key permutation. - */ - for (i = 0; i < 64; i++) { - init_perm[final_perm[i] = IP[i] - 1] = i; - inv_key_perm[i] = 255; - } - - /* - * Invert the key permutation and initialise the inverted key compression - * permutation. - */ - for (i = 0; i < 56; i++) { - u_key_perm[i] = key_perm[i] - 1; - inv_key_perm[key_perm[i] - 1] = i; - inv_comp_perm[i] = 255; - } - - /* - * Invert the key compression permutation. - */ - for (i = 0; i < 48; i++) { - inv_comp_perm[comp_perm[i] - 1] = i; - } - - /* - * Set up the OR-mask arrays for the initial and final permutations, and - * for the key initial and compression permutations. - */ - for (k = 0; k < 8; k++) { - for (i = 0; i < 256; i++) { - *(il = &ip_maskl[k][i]) = 0L; - *(ir = &ip_maskr[k][i]) = 0L; - *(fl = &fp_maskl[k][i]) = 0L; - *(fr = &fp_maskr[k][i]) = 0L; - for (j = 0; j < 8; j++) { - inbit = 8 * k + j; - if (i & bits8[j]) { - if ((obit = init_perm[inbit]) < 32) - *il |= bits32[obit]; - else - *ir |= bits32[obit - 32]; - if ((obit = final_perm[inbit]) < 32) - *fl |= bits32[obit]; - else - *fr |= bits32[obit - 32]; - } - } - } - for (i = 0; i < 128; i++) { - *(il = &key_perm_maskl[k][i]) = 0L; - *(ir = &key_perm_maskr[k][i]) = 0L; - for (j = 0; j < 7; j++) { - inbit = 8 * k + j; - if (i & bits8[j + 1]) { - if ((obit = inv_key_perm[inbit]) == 255) - continue; - if (obit < 28) - *il |= bits28[obit]; - else - *ir |= bits28[obit - 28]; - } - } - *(il = &comp_maskl[k][i]) = 0L; - *(ir = &comp_maskr[k][i]) = 0L; - for (j = 0; j < 7; j++) { - inbit = 7 * k + j; - if (i & bits8[j + 1]) { - if ((obit = inv_comp_perm[inbit]) == 255) - continue; - if (obit < 24) - *il |= bits24[obit]; - else - *ir |= bits24[obit - 24]; - } - } - } - } - - /* - * Invert the P-box permutation, and convert into OR-masks for handling - * the output of the S-box arrays setup above. - */ - for (i = 0; i < 32; i++) - un_pbox[pbox[i] - 1] = i; - - for (b = 0; b < 4; b++) - for (i = 0; i < 256; i++) { - *(p = &psbox[b][i]) = 0L; - for (j = 0; j < 8; j++) { - if (i & bits8[j]) - *p |= bits32[un_pbox[8 * b + j]]; - } - } - - des_initialised = 1; -} - -static void -setup_salt(long salt) -{ - unsigned long obit, saltbit; - int i; - - if (salt == old_salt) - return; - old_salt = salt; - - saltbits = 0L; - saltbit = 1; - obit = 0x800000; - for (i = 0; i < 24; i++) { - if (salt & saltbit) - saltbits |= obit; - saltbit <<= 1; - obit >>= 1; - } -} - -static int -des_setkey(const char *key) -{ - unsigned long k0, k1, rawkey0, rawkey1; - int shifts, round; - - if (!des_initialised) - des_init(); - - rawkey0 = ntohl(*(unsigned long *)key); - rawkey1 = ntohl(*(unsigned long *)(key + 4)); - - if ((rawkey0 | rawkey1) - && rawkey0 == old_rawkey0 - && rawkey1 == old_rawkey1) { - /* - * Already setup for this key. This optimisation fails on a zero key - * (which is weak and has bad parity anyway) in order to simplify the - * starting conditions. - */ - return 0; - } - old_rawkey0 = rawkey0; - old_rawkey1 = rawkey1; - - /* - * Do key permutation and split into two 28-bit subkeys. - */ - k0 = key_perm_maskl[0][rawkey0 >> 25] - | key_perm_maskl[1][(rawkey0 >> 17) & 0x7f] - | key_perm_maskl[2][(rawkey0 >> 9) & 0x7f] - | key_perm_maskl[3][(rawkey0 >> 1) & 0x7f] - | key_perm_maskl[4][rawkey1 >> 25] - | key_perm_maskl[5][(rawkey1 >> 17) & 0x7f] - | key_perm_maskl[6][(rawkey1 >> 9) & 0x7f] - | key_perm_maskl[7][(rawkey1 >> 1) & 0x7f]; - k1 = key_perm_maskr[0][rawkey0 >> 25] - | key_perm_maskr[1][(rawkey0 >> 17) & 0x7f] - | key_perm_maskr[2][(rawkey0 >> 9) & 0x7f] - | key_perm_maskr[3][(rawkey0 >> 1) & 0x7f] - | key_perm_maskr[4][rawkey1 >> 25] - | key_perm_maskr[5][(rawkey1 >> 17) & 0x7f] - | key_perm_maskr[6][(rawkey1 >> 9) & 0x7f] - | key_perm_maskr[7][(rawkey1 >> 1) & 0x7f]; - /* - * Rotate subkeys and do compression permutation. - */ - shifts = 0; - for (round = 0; round < 16; round++) { - unsigned long t0, t1; - - shifts += key_shifts[round]; - - t0 = (k0 << shifts) | (k0 >> (28 - shifts)); - t1 = (k1 << shifts) | (k1 >> (28 - shifts)); - - de_keysl[15 - round] = - en_keysl[round] = comp_maskl[0][(t0 >> 21) & 0x7f] - | comp_maskl[1][(t0 >> 14) & 0x7f] - | comp_maskl[2][(t0 >> 7) & 0x7f] - | comp_maskl[3][t0 & 0x7f] - | comp_maskl[4][(t1 >> 21) & 0x7f] - | comp_maskl[5][(t1 >> 14) & 0x7f] - | comp_maskl[6][(t1 >> 7) & 0x7f] - | comp_maskl[7][t1 & 0x7f]; - - de_keysr[15 - round] = en_keysr[round] = - comp_maskr[0][(t0 >> 21) & 0x7f] - | comp_maskr[1][(t0 >> 14) & 0x7f] - | comp_maskr[2][(t0 >> 7) & 0x7f] - | comp_maskr[3][t0 & 0x7f] - | comp_maskr[4][(t1 >> 21) & 0x7f] - | comp_maskr[5][(t1 >> 14) & 0x7f] - | comp_maskr[6][(t1 >> 7) & 0x7f] - | comp_maskr[7][t1 & 0x7f]; - } - return 0; -} - -static int -do_des(unsigned long l_in, unsigned long r_in, unsigned long *l_out, - unsigned long *r_out, int count) -{ - /* - * l_in, r_in, l_out, and r_out are in pseudo-"big-endian" format. - */ - unsigned long l, r, *kl, *kr, *kl1, *kr1; - unsigned long f, r48l, r48r; - int round; - - if (count == 0) { - return 1; - } else if (count > 0) { - /* - * Encrypting - */ - kl1 = en_keysl; - kr1 = en_keysr; - } else { - /* - * Decrypting - */ - count = -count; - kl1 = de_keysl; - kr1 = de_keysr; - } - - /* - * Do initial permutation (IP). - */ - l = ip_maskl[0][l_in >> 24] - | ip_maskl[1][(l_in >> 16) & 0xff] - | ip_maskl[2][(l_in >> 8) & 0xff] - | ip_maskl[3][l_in & 0xff] - | ip_maskl[4][r_in >> 24] - | ip_maskl[5][(r_in >> 16) & 0xff] - | ip_maskl[6][(r_in >> 8) & 0xff] - | ip_maskl[7][r_in & 0xff]; - r = ip_maskr[0][l_in >> 24] - | ip_maskr[1][(l_in >> 16) & 0xff] - | ip_maskr[2][(l_in >> 8) & 0xff] - | ip_maskr[3][l_in & 0xff] - | ip_maskr[4][r_in >> 24] - | ip_maskr[5][(r_in >> 16) & 0xff] - | ip_maskr[6][(r_in >> 8) & 0xff] - | ip_maskr[7][r_in & 0xff]; - - while (count--) { - /* - * Do each round. - */ - kl = kl1; - kr = kr1; - round = 16; - while (round--) { - /* - * Expand R to 48 bits (simulate the E-box). - */ - r48l = ((r & 0x00000001) << 23) - | ((r & 0xf8000000) >> 9) - | ((r & 0x1f800000) >> 11) - | ((r & 0x01f80000) >> 13) - | ((r & 0x001f8000) >> 15); - - r48r = ((r & 0x0001f800) << 7) - | ((r & 0x00001f80) << 5) - | ((r & 0x000001f8) << 3) - | ((r & 0x0000001f) << 1) - | ((r & 0x80000000) >> 31); - /* - * Do salting for crypt() and friends, and XOR with the permuted - * key. - */ - f = (r48l ^ r48r) & saltbits; - r48l ^= f ^ *kl++; - r48r ^= f ^ *kr++; - /* - * Do sbox lookups (which shrink it back to 32 bits) and do the - * pbox permutation at the same time. - */ - f = psbox[0][m_sbox[0][r48l >> 12]] - | psbox[1][m_sbox[1][r48l & 0xfff]] - | psbox[2][m_sbox[2][r48r >> 12]] - | psbox[3][m_sbox[3][r48r & 0xfff]]; - /* - * Now that we've permuted things, complete f(). - */ - f ^= l; - l = r; - r = f; - } - r = l; - l = f; - } - /* - * Do final permutation (inverse of IP). - */ - *l_out = fp_maskl[0][l >> 24] - | fp_maskl[1][(l >> 16) & 0xff] - | fp_maskl[2][(l >> 8) & 0xff] - | fp_maskl[3][l & 0xff] - | fp_maskl[4][r >> 24] - | fp_maskl[5][(r >> 16) & 0xff] - | fp_maskl[6][(r >> 8) & 0xff] - | fp_maskl[7][r & 0xff]; - *r_out = fp_maskr[0][l >> 24] - | fp_maskr[1][(l >> 16) & 0xff] - | fp_maskr[2][(l >> 8) & 0xff] - | fp_maskr[3][l & 0xff] - | fp_maskr[4][r >> 24] - | fp_maskr[5][(r >> 16) & 0xff] - | fp_maskr[6][(r >> 8) & 0xff] - | fp_maskr[7][r & 0xff]; - return 0; -} - -char * -crypt(char *key, char *setting) -{ - unsigned long count, salt, l, r0, r1, keybuf[2]; - unsigned char *p, *q; - static unsigned char output[21]; - - if (!des_initialised) - des_init(); - /* - * Copy the key, shifting each character up by one bit and padding with - * zeros. - */ - q = (unsigned char *)keybuf; - while (q - (unsigned char *)keybuf - 8) { - if ((*q++ = *key << 1)) - key++; - } - if (des_setkey((char *)keybuf)) - return NULL; - - /* - * "old"-style: setting - 2 bytes of salt key - up to 8 characters - */ - count = 25; - - salt = (ascii_to_bin(setting[1]) << 6) - | ascii_to_bin(setting[0]); - - output[0] = setting[0]; - /* - * If the encrypted password that the salt was extracted from is only 1 - * character long, the salt will be corrupted. We need to ensure that - * the output string doesn't have an extra NUL in it! - */ - output[1] = setting[1] ? setting[1] : output[0]; - - p = output + 2; - - setup_salt(salt); - /* - * Do it. - */ - if (do_des(0L, 0L, &r0, &r1, count)) - return NULL; - /* - * Now encode the result... - */ - l = (r0 >> 8); - *p++ = ascii64[(l >> 18) & 0x3f]; - *p++ = ascii64[(l >> 12) & 0x3f]; - *p++ = ascii64[(l >> 6) & 0x3f]; - *p++ = ascii64[l & 0x3f]; - - l = (r0 << 16) | ((r1 >> 16) & 0xffff); - *p++ = ascii64[(l >> 18) & 0x3f]; - *p++ = ascii64[(l >> 12) & 0x3f]; - *p++ = ascii64[(l >> 6) & 0x3f]; - *p++ = ascii64[l & 0x3f]; - - l = r1 << 2; - *p++ = ascii64[(l >> 12) & 0x3f]; - *p++ = ascii64[(l >> 6) & 0x3f]; - *p++ = ascii64[l & 0x3f]; - *p = 0; - - return (char *)output; -} -#endif -- cgit v1.2.3 From 8e14c77ef2bb46136c1d2f5b202a54f714badad0 Mon Sep 17 00:00:00 2001 From: kcwu <kcwu@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sat, 6 Sep 2003 19:52:57 +0000 Subject: clean up git-svn-id: http://opensvn.csie.org/pttbbs/trunk@1166 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/include/config.h | 13 ++---------- pttbbs/include/proto.h | 2 +- pttbbs/mbbsd/admin.c | 14 ++++--------- pttbbs/mbbsd/bbs.c | 4 ++-- pttbbs/mbbsd/board.c | 29 +-------------------------- pttbbs/mbbsd/cache.c | 2 +- pttbbs/mbbsd/cal.c | 22 ++++++++------------ pttbbs/mbbsd/chat.c | 37 ---------------------------------- pttbbs/mbbsd/chicken.c | 20 +++++++++---------- pttbbs/mbbsd/edit.c | 14 +------------ pttbbs/mbbsd/friend.c | 19 +++++++----------- pttbbs/mbbsd/gamble.c | 2 +- pttbbs/mbbsd/indict.c | 52 +++++++++++++++++++++--------------------------- pttbbs/mbbsd/mail.c | 18 ++++------------- pttbbs/mbbsd/mbbsd.c | 9 +++------ pttbbs/mbbsd/page.c | 4 +--- pttbbs/mbbsd/read.c | 8 ++++---- pttbbs/mbbsd/record.c | 4 ++-- pttbbs/mbbsd/register.c | 4 +--- pttbbs/mbbsd/talk.c | 28 +++++++------------------- pttbbs/mbbsd/user.c | 3 +-- pttbbs/mbbsd/var.c | 3 --- pttbbs/mbbsd/voteboard.c | 2 +- pttbbs/mbbsd/xyz.c | 20 +++++-------------- 24 files changed, 90 insertions(+), 243 deletions(-) diff --git a/pttbbs/include/config.h b/pttbbs/include/config.h index 88d70e5a..c3d7d2fa 100644 --- a/pttbbs/include/config.h +++ b/pttbbs/include/config.h @@ -29,7 +29,7 @@ #define MAX_POST_MONEY 100 #endif -#ifndef MAX_CHICKEN_MONEY /* 養雞場穫利上限 */ +#ifndef MAX_CHICKEN_MONEY /* 養雞場獲利上限 */ #define MAX_CHICKEN_MONEY 100 #endif @@ -121,7 +121,6 @@ #undef SUPPORT_GB /* 是否支援gb */ -#define DEFAULTBOARD "SYSOP" /* 預設看板 */ #define LOGINASNEW /* 採用上站申請帳號制度 */ #define NO_WATER_POST /* 防止BlahBlah式灌水 */ #define USE_BSMTP /* 使用opus的BSMTP 寄收信? */ @@ -135,8 +134,7 @@ #undef HAVE_INFO /* 顯示程式版本說明 */ #undef HAVE_LICENSE /* 顯示 GNU 版權畫面 */ #define FAST_LOGIN /* Login 不檢查遠端使用者 */ -#define HAVE_CAL /* 提功計算機 */ -#undef POSTBUG /* board/mail post 沒有 bug 了 */ +#define HAVE_CAL /* 提供計算機 */ #undef HAVE_REPORT /* 系統追蹤報告 */ #undef EMAIL_JUSTIFY /* 發出 InterNet Email 身份認證信函 */ #undef NEWUSER_LIMIT /* 新手上路的三天限制 */ @@ -158,13 +156,6 @@ #define SHOWBOARD /* 看見使用者看板 */ #define SHOWPID /* 看見使用者 PID */ -#define REALINFO /* 真實姓名 */ -#ifdef REALINFO -#undef ACTS_REALNAMES /* 主目錄的 (U)ser 顯示真實姓名 */ -#undef POST_REALNAMES /* 貼文件時附上真實姓名 */ -#undef MAIL_REALNAMES /* 寄站內信件時附上真實姓名 */ -#endif - #define DOTIMEOUT #ifdef DOTIMEOUT #define IDLE_TIMEOUT (43200) /* 一般情況之 timeout (12hr) */ diff --git a/pttbbs/include/proto.h b/pttbbs/include/proto.h index 073e9520..bbb603df 100644 --- a/pttbbs/include/proto.h +++ b/pttbbs/include/proto.h @@ -240,7 +240,7 @@ int guess_main(); /* indict */ int x_dict(); -int use_dict(); +int use_dict(char *dict,char *database); /* io */ int getdata(int line, int col, char *prompt, char *buf, int len, int echo); diff --git a/pttbbs/mbbsd/admin.c b/pttbbs/mbbsd/admin.c index 99c87621..e6f30b20 100644 --- a/pttbbs/mbbsd/admin.c +++ b/pttbbs/mbbsd/admin.c @@ -33,7 +33,7 @@ search_key_user(char *passwdfile, int mode) int ch; int coun = 0; FILE *fp1 = fopen(passwdfile, "r"); - char friendfile[128]="",buf[128], key[22], genbuf[8], + char friendfile[128]="", key[22], genbuf[8], *keymatch; @@ -46,8 +46,7 @@ search_key_user(char *passwdfile, int mode) while ((fread(&user, sizeof(user), 1, fp1)) > 0 && coun < MAX_USERS) { if (!(++coun & 15)) { move(1, 0); - snprintf(buf, sizeof(buf), "第 [%d] 筆資料\n", coun); - outs(buf); + prints("第 [%d] 筆資料\n", coun); refresh(); } keymatch = NULL; @@ -73,8 +72,7 @@ search_key_user(char *passwdfile, int mode) if(keymatch) { move(1, 0); - snprintf(buf, sizeof(buf), "第 [%d] 筆資料\n", coun); - outs(buf); + prints("第 [%d] 筆資料\n", coun); refresh(); user_display(&user, 1); @@ -110,11 +108,10 @@ search_key_user(char *passwdfile, int mode) return 0; } else { move(b_lines - 1, 0); - genbuf[0] = 'n'; getdata(0, 0, "目前的 PASSWD 檔沒有此 ID,新增嗎?[y/N]", genbuf, 3, LCECHO); - if (genbuf[0] == 'n') { + if (genbuf[0] != 'y') { outs("目前的PASSWDS檔沒有此id " "請先new一個這個id的帳號"); } else { @@ -479,9 +476,6 @@ x_file() case '9': fpath = "etc/hint"; break; - case 'a': - fpath = "etc/teashop"; - break; case 'b': fpath = "etc/sysop"; break; diff --git a/pttbbs/mbbsd/bbs.c b/pttbbs/mbbsd/bbs.c index 27c8ab25..47eeb65b 100644 --- a/pttbbs/mbbsd/bbs.c +++ b/pttbbs/mbbsd/bbs.c @@ -636,10 +636,10 @@ do_post() static void do_generalboardreply(fileheader_t * fhdr) { - char genbuf[200]; + char genbuf[3]; getdata(b_lines - 1, 0, "▲ 回應至 (F)看板 (M)作者信箱 (B)二者皆是 (Q)取消?[F] ", - genbuf, 3, LCECHO); + genbuf, sizeof(genbuf), LCECHO); switch (genbuf[0]) { case 'm': mail_reply(0, fhdr, 0); diff --git a/pttbbs/mbbsd/board.c b/pttbbs/mbbsd/board.c index eb6a13d4..5214d3cc 100644 --- a/pttbbs/mbbsd/board.c +++ b/pttbbs/mbbsd/board.c @@ -935,7 +935,7 @@ show_brdlist(int head, int clsflag, int newflag) move(1, 0); outs( " " - "◣ ╭—\033[33m●\n" + "◣ —\033[33m●\n" " 寣X \033[m " "◢█\033[47m☉\033[40m██◣蔌n" " \033[44m ︿︿︿︿︿︿︿︿ " @@ -1579,30 +1579,3 @@ New() currstat = stat0; return 0; } - -/* - * int v_favorite(){ char fname[256]; char inbuf[2048]; FILE* fp; int nGroup; - * char* strtmp; - * - * setuserfile(fname,str_favorite); - * - * if (!(fp=fopen(fname,"r"))) return -1; move(0,0); clrtobot(); - * fgets(inbuf,sizeof(inbuf),fp); nGroup=atoi(inbuf); - * - * currutmp->nGroup=0; currutmp->ninRoot=0; - * - * while(nGroup!=currutmp->nGroup+1){ fgets(inbuf,sizeof(inbuf),fp); - * prints("%s\n",strtmp=strtok(inbuf," \n")); - * strcpy(currutmp->gfavorite[currutmp->nGroup++],strtmp); - * while((strtmp=strtok(NULL, " \n"))){ prints(" %s - * %d\n",strtmp,getbnum(strtmp)); } currutmp->nGroup++; } - * prints("+++%d+++\n",currutmp->nGroup); - * - * fgets(inbuf,sizeof(inbuf),fp); - * - * for(strtmp=strtok(inbuf, " \n");strtmp;strtmp=strtok(NULL, " \n")){ if - * (strtmp[0]!='#') prints("*** %s %d\n",strtmp, getbnum(strtmp)); else - * prints("*** %s %d\n",strtmp+1, -1); currutmp->ninRoot++; } - * - * fclose(fp); pressanykey(); return 0; } - */ diff --git a/pttbbs/mbbsd/cache.c b/pttbbs/mbbsd/cache.c index 945fed88..7059d4e2 100644 --- a/pttbbs/mbbsd/cache.c +++ b/pttbbs/mbbsd/cache.c @@ -936,7 +936,7 @@ reload_fcache(void) while (fgets(buf, sizeof(buf), fp)) { if (buf[0] && buf[0] != '#' && buf[0] != ' ' && buf[0] != '\n') { - sscanf(buf, "%s", SHM->domain[SHM->top]); + sscanf(buf, "%s", SHM->domain[SHM->top]); // XXX check buffer size po = buf + strlen(SHM->domain[SHM->top]); while (*po == ' ') po++; diff --git a/pttbbs/mbbsd/cal.c b/pttbbs/mbbsd/cal.c index 89383f99..fceaf2b1 100644 --- a/pttbbs/mbbsd/cal.c +++ b/pttbbs/mbbsd/cal.c @@ -118,9 +118,7 @@ osong(char *defaultid) } move(12, 0); clrtobot(); - snprintf(buf, sizeof(buf), - "親愛的 %s 歡迎來到歐桑自動點歌系統\n", cuser.userid); - outs(buf); + prints("親愛的 %s 歡迎來到歐桑自動點歌系統\n", cuser.userid); trans_buffer[0] = 0; if (!defaultid) { getdata(13, 0, "要點給誰呢:[可直接按 Enter 先選歌]", @@ -174,12 +172,12 @@ osong(char *defaultid) "◇ %s 點給 %s ", (ano[0] == 'y') ? "匿名者" : cuser.userid, destid); - while (fgets(buf, 200, fp)) { + while (fgets(buf, sizeof(buf), fp)) { char *po; if (!strncmp(buf, "標題: ", 6)) { clear(); move(10, 10); - prints("%s", buf); + outs(buf); pressanykey(); fclose(fp); fclose(fp1); @@ -313,9 +311,7 @@ p_exmail() int n; if (cuser.exmailbox >= MAX_EXKEEPMAIL) { - snprintf(buf, sizeof(buf), - "容量最多增加 %d 封,不能再買了。", MAX_EXKEEPMAIL); - outs(buf); + prints("容量最多增加 %d 封,不能再買了。", MAX_EXKEEPMAIL); refresh(); return 0; } @@ -477,11 +473,11 @@ cal() float a = 0; char flo = 0, ch = 0; char mode[6] = {' ', '=', '+', '-', '*', '/'}, cmode = 0; - char buf[100] = "[ 0] [ ] ", b[20] = "0"; + char b[20] = "0"; move(b_lines - 1, 0); clrtoeol(); - outs(buf); + outs("[ 0] [ ] "); move(b_lines, 0); clrtoeol(); outs("\033[44m 小計算機 \033[31;47m (0123456789+-*/=) " @@ -502,8 +498,7 @@ cal() b[0] = '0'; b[1] = 0; move(b_lines - 1, 0); - snprintf(buf, sizeof(buf), "[%13.2f] [%c] ", a, ch); - outs(buf); + prints("[%13.2f] [%c] ", a, ch); break; case '.': if (!flo) @@ -527,8 +522,7 @@ cal() else b[0] = ch; move(b_lines - 1, 0); - snprintf(buf, sizeof(buf), "[%13s] [%c]", b, mode[(int)cmode]); - outs(buf); + prints("[%13s] [%c]", b, mode[(int)cmode]); break; case 'q': return 0; diff --git a/pttbbs/mbbsd/chat.c b/pttbbs/mbbsd/chat.c index 55d3129d..5493608f 100644 --- a/pttbbs/mbbsd/chat.c +++ b/pttbbs/mbbsd/chat.c @@ -295,43 +295,6 @@ chat_cmd(char *buf, int fd) return 0; } -#if 0 -static char * -select_address() -{ - int c; - FILE *fp; - char nametab[25][90]; - char iptab[25][18], buf[80]; - - move(1, 0); - clrtobot(); - outs("\n \033[36m【找個地方抬抬槓吧!】\033[m " - "◎ 【以下為本站登記有案的茶樓】 \n"); - trans_buffer[0] = 0; - if ((fp = fopen("etc/teashop", "r"))) { - for (c = 0; fscanf(fp, "%s%s", iptab[c], nametab[c]) != EOF; c++) { - snprintf(buf, sizeof(buf), - "\n (\033[36m%d\033[0m) %-30s [%s]", - c + 1, nametab[c], iptab[c]); - outs(buf); - } - getdata(20, 10, "★\033[32m 請選擇,[0]離開:\033[0m", buf, 3, - LCECHO); - if (buf[1]) - buf[0] = (buf[0] + 1) * 10 + (buf[1] - '1'); - else - buf[0] -= '1'; - if (buf[0] >= 0 && buf[0] < c) - strlcpy(trans_buffer, iptab[(int)buf[0]], sizeof(trans_buffer)); - } else { - outs("本站沒有登記任何合格茶樓"); - pressanykey(); - } - return trans_buffer; -} -#endif - #define MAXLASTCMD 6 static int chatid_len = 10; diff --git a/pttbbs/mbbsd/chicken.c b/pttbbs/mbbsd/chicken.c index 23ed4279..0c769fe7 100644 --- a/pttbbs/mbbsd/chicken.c +++ b/pttbbs/mbbsd/chicken.c @@ -6,39 +6,39 @@ static const char *cage[17] = { "誕生", "週歲", "幼年", "少年", "青春", "青年", "青年", "活力", "壯年", "壯年", "壯年", "中年", -"中年", "老年", "老年", "老摳摳", "古希"}; + "中年", "老年", "老年", "老摳摳", "古希"}; static const char *chicken_type[NUM_KINDS] = { "小雞", "美少女", "勇士", "蜘蛛", "恐龍", "老鷹", "貓", "蠟筆小新", "狗狗", "惡魔", "忍者", "ㄚ扁", -"馬英九", "就可人", "羅莉"}; + "馬英九", "就可人", "羅莉"}; static const char *chicken_food[NUM_KINDS] = { "雞飼料", "營養厚片", "雞排便當", "死蝴蝶", "屍體", "小雞", "貓餅乾", "小熊餅乾", "寶錄", "靈氣", "飯團", "便當", -"雞腿", "笑話文章", "水果沙拉"}; + "雞腿", "笑話文章", "水果沙拉"}; static const int egg_price[NUM_KINDS] = { 5, 25, 30, 40, 80, 50, 15, 35, 17, 100, 85, 200, -200, 100, 77}; + 200, 100, 77}; static const int food_price[NUM_KINDS] = { 4, 6, 8, 10, 12, 12, 5, 6, 5, 20, 15, 23, -23, 10, 19}; + 23, 10, 19}; static const char *attack_type[NUM_KINDS] = { "啄", "鞭打", "槌", "咬", "撞擊", "啄", "抓", "踢", "咬", "燃燒", "暗擊", "棍打", -"劍擊", "冷凍光線", "香吻一枚"}; + "劍擊", "冷凍光線", "香吻一枚"}; static const char *damage_degree[] = { "蚊子似的", "騷癢似的", "小力的", "輕微的", "有點疼的", "使力的", "傷人的", "重重的", "使全力的", "惡狠狠的", "危險的", "瘋狂的", "猛烈的", "狂風暴雨似的", "驚天動地的", -"致命的", NULL}; + "致命的", NULL}; enum { OO, FOOD, WEIGHT, CLEAN, RUN, ATTACK, BOOK, HAPPY, SATIS, @@ -104,7 +104,7 @@ new_chicken() clear(); move(2, 0); - outs("歡迎觀臨 \033[33m◎\033[37;44m Ptt寵物市場 \033[33;40m◎\033[m.. " + outs("歡迎光臨 \033[33m◎\033[37;44m Ptt寵物市場 \033[33;40m◎\033[m.. " "目前蛋價:\n" "(a)小雞 $5 (b)美少女 $25 (c)勇士 $30 (d)蜘蛛 $40 " "(e)恐龍 $80\n" @@ -167,7 +167,7 @@ show_file(char *filename, int y, int lines, int mode) move(y, 0); clrtoline(lines + y); if ((fp = fopen(filename, "r"))) { - while (fgets(buf, 256, fp) && lines--) + while (fgets(buf, sizeof(buf), fp) && lines--) outs(Ptt_prints(buf, mode)); fclose(fp); } else @@ -480,7 +480,7 @@ ch_sell() else if (money > MAX_CHICKEN_MONEY) money = MAX_CHICKEN_MONEY; //防止怪雞 - if (mychicken->type == 1 || mychicken->type == 7) { + if (mychicken->type == 1 || mychicken->type == 7) { outs("\n\033[31m ㄜ..親愛的..販賣人口是會犯法的唷..\033[m"); pressanykey(); return 0; diff --git a/pttbbs/mbbsd/edit.c b/pttbbs/mbbsd/edit.c index 202157ae..10f33d33 100644 --- a/pttbbs/mbbsd/edit.c +++ b/pttbbs/mbbsd/edit.c @@ -1,4 +1,4 @@ -/* $Id: edit.c,v 1.39 2003/07/17 06:11:14 victor Exp $ */ +/* $Id$ */ /* edit.c, 用來提供 bbs上的文字編輯器, 即 ve. * 現在這一個是惡搞過的版本, 比較不穩定, 用比較多的 cpu, 但是可以省下許多 * 的記憶體 (以 Ptt為例, 在九千人上站的時候, 約可省下 50MB 的記憶體) @@ -806,11 +806,7 @@ write_header(FILE * fp) if (curredit & EDIT_MAIL || curredit & EDIT_LIST) { fprintf(fp, "%s %s (%s)\n", str_author1, cuser.userid, -#if defined(REALINFO) && defined(MAIL_REALNAMES) - cuser.realname -#else cuser.username -#endif ); } else { char *ptr; @@ -869,20 +865,12 @@ write_header(FILE * fp) local_article ? str_post2 : str_post1, currboard); } else { fprintf(fp, "%s %s (%s) %s %s\n", str_author1, cuser.userid, -#if defined(REALINFO) && defined(POSTS_REALNAMES) - cuser.realname, -#else cuser.username, -#endif local_article ? str_post2 : str_post1, currboard); } #else /* HAVE_ANONYMOUS */ fprintf(fp, "%s %s (%s) %s %s\n", str_author1, cuser.userid, -#if defined(REALINFO) && defined(POSTS_REALNAMES) - cuser.realname, -#else cuser.username, -#endif local_article ? str_post2 : str_post1, currboard); #endif /* HAVE_ANONYMOUS */ diff --git a/pttbbs/mbbsd/friend.c b/pttbbs/mbbsd/friend.c index 16e36c63..3f97ee71 100644 --- a/pttbbs/mbbsd/friend.c +++ b/pttbbs/mbbsd/friend.c @@ -152,18 +152,14 @@ friend_append(int type, int count) for (j = i = 0; i <= 4; i++) if (i != type) { ++j; - snprintf(buf, sizeof(buf), - " (%d) %-s\n", j, friend_list[(int)i]); - outs(buf); + prints(" (%d) %-s\n", j, friend_list[(int)i]); } if (HAVE_PERM(PERM_SYSOP) || currmode & MODE_BOARD) for (; i < 8; ++i) if (i != type) { ++j; - snprintf(buf, sizeof(buf), - " (%d) %s 板的 %s\n", j, currboard, + prints(" (%d) %s 板的 %s\n", j, currboard, friend_list[(int)i]); - outs(buf); } outs(" (S) 選擇其他看板的特別名單"); getdata(11, 0, "請選擇 或 直接[Enter] 放棄:", buf, 3, LCECHO); @@ -187,7 +183,7 @@ friend_append(int type, int count) while (fgets(buf, 80, fp) && (unsigned)count <= friend_max[type]) { char the_id[15]; - sscanf(buf, "%s", the_id); + sscanf(buf, "%s", the_id); // XXX check buffer size if (!belong(fpath, the_id)) { if ((fp1 = fopen(fpath, "a"))) { flock(fileno(fp1), LOCK_EX); @@ -311,7 +307,7 @@ friend_water(char *message, int type) userinfo_t *uentp; int tuid; - sscanf(line, "%s", userid); + sscanf(line, "%s", userid); // XXX check buffer size if ((tuid = searchuser(userid)) && tuid != usernum && (uentp = (userinfo_t *) search_ulist(tuid)) && isvisible_uid(tuid)) @@ -344,8 +340,7 @@ friend_edit(int type) while (1) { stand_title(friend_list[type]); move(0, 40); - snprintf(line, sizeof(line), "(名單上限:%d個人)", friend_max[type]); - outs(line); + prints("(名單上限:%d個人)", friend_max[type]); count = 0; CreateNameList(); @@ -421,7 +416,7 @@ friend_edit(int type) snprintf(genbuf, sizeof(genbuf), "%s.old", fpath); if ((fp = fopen(genbuf, "r"))) { while (fgets(line, 80, fp)) { - sscanf(line, "%s", uident); + sscanf(line, "%s", uident); // XXX check buffer size sethomefile(genbuf, uident, type == FRIEND_ALOHA ? "aloha" : "postnotify"); del_distinct(genbuf, cuser.userid); @@ -431,7 +426,7 @@ friend_edit(int type) snprintf(genbuf, sizeof(genbuf), "%s", fpath); if ((fp = fopen(genbuf, "r"))) { while (fgets(line, 80, fp)) { - sscanf(line, "%s", uident); + sscanf(line, "%s", uident); // XXX check buffer size sethomefile(genbuf, uident, type == FRIEND_ALOHA ? "aloha" : "postnotify"); add_distinct(genbuf, cuser.userid); diff --git a/pttbbs/mbbsd/gamble.c b/pttbbs/mbbsd/gamble.c index 4e2f348f..53e076ad 100644 --- a/pttbbs/mbbsd/gamble.c +++ b/pttbbs/mbbsd/gamble.c @@ -17,7 +17,7 @@ load_ticket_record(char *direct, int ticket[]) snprintf(buf, sizeof(buf), "%s/" FN_TICKET_RECORD, direct); if (!(fp = fopen(buf, "r"))) return 0; - for (i = 0; i < MAX_ITEM && fscanf(fp, "%9d ", &ticket[i]); i++) + for (i = 0; i < MAX_ITEM && fscanf(fp, "%9d ", &ticket[i])==1; i++) total = total + ticket[i]; fclose(fp); return total; diff --git a/pttbbs/mbbsd/indict.c b/pttbbs/mbbsd/indict.c index cdd2712d..317fb5b0 100644 --- a/pttbbs/mbbsd/indict.c +++ b/pttbbs/mbbsd/indict.c @@ -1,12 +1,12 @@ -/* $Id: indict.c,v 1.13 2003/06/28 08:48:36 kcwu Exp $ */ +/* $Id$ */ #include "bbs.h" #define REFER "etc/dicts" static void -addword(char word[]) +addword(char *database,char word[]) { - char buf[150], temp[150], a[3]; + char buf[150], a[3]; FILE *fp = fopen(database, "r+"); if (fp == NULL) { @@ -19,8 +19,7 @@ addword(char word[]) clear(); move(4, 0); outs(" \033[31m警告\033[m:若蓄意填寫假資料將\033[36m砍id\033[m處份\n"); - snprintf(temp, sizeof(temp), "\n輸入範例\n:\033[33m%s\033[m", buf); - outs(temp); + prints("\n輸入範例\n:\033[33m%s\033[m", buf); outs("\n請依上列範例輸入一行資料(直接enter放棄)\n"); getdata(10, 0, ":", buf, 65, DOECHO); if (buf[0]) { @@ -34,11 +33,12 @@ addword(char word[]) } static int -choose_dict(void) +choose_dict(char *dict,int dictlen,char *database,int databaselen) { - int c; +#define MAX_DICT 10 + int n,c; FILE *fp; - char buf[10][21], data[10][21], cho[130]; + char buf[MAX_DICT][21], data[MAX_DICT][21], cho[10]; move(12, 0); clrtobot(); @@ -46,21 +46,18 @@ choose_dict(void) "● \033[45;33m字典唷 ◇ 要查哪一本?\033[m ●"); if ((fp = fopen(REFER, "r"))) { - for (c = 0; fscanf(fp, "%s %s", buf[c], data[c]) != EOF; c++) { - snprintf(cho, sizeof(cho), "\n " - "(\033[36m%d\033[m) %-20s大字典", c + 1, buf[c]); - outs(cho); + for(n=0; n<MAX_DICT && fscanf(fp,"%s %s",buf[n],data[n])==2; n++) { // XXX check buffer size + prints("\n " + "(\033[36m%d\033[m) %-20s大字典", n + 1, buf[n]); } fclose(fp); getdata(22, 14, " ★ 請選擇,[Enter]離開:", cho, 3, LCECHO); - cho[0] -= '1'; - if (cho[1]) - cho[0] = (cho[0] + 1) * 10 + (cho[1] - '1'); + c=atoi(cho); - if (cho[0] >= 0 && cho[0] < c) { - strlcpy(dict, buf[(int)cho[0]], sizeof(dict)); - strlcpy(database, data[(int)cho[0]], sizeof(database)); + if (c >= 1 && c <= n) { + strlcpy(dict, buf[c-1], dictlen); + strlcpy(database, data[c-1], databaselen); return 1; } else return 0; @@ -69,7 +66,7 @@ choose_dict(void) } int -use_dict() +use_dict(char *dict,char *database) { FILE *fp; char lang[150], word[80] = ""; @@ -88,13 +85,9 @@ use_dict() strlcpy(&buf[100], "\033[m\n", sizeof(buf) - 100); for (;;) { move(0, 0); - snprintf(lang, sizeof(lang), - " 請輸入關鍵字串(%s) 或指令(h,t,a)\n", dict); - outs(lang); - snprintf(lang, sizeof(lang), - "[\033[32m<關鍵字>\033[m|\033[32mh\033[m:help|\033[32m" + prints(" 請輸入關鍵字串(%s) 或指令(h,t,a)\n", dict); + prints("[\033[32m<關鍵字>\033[m|\033[32mh\033[m:help|\033[32m" "t\033[m:所有資料|\033[32ma\033[m:新增資料%s]\n:", sys); - outs(lang); getdata(2, 0, ":", word, 18, DOECHO); outs("資料搜尋中請稍候...."); str_lower(word, word); @@ -108,7 +101,7 @@ use_dict() clear(); move(4, 0); outs(buf); - addword(word); + addword(database,word); continue; } else if (word[0] == 't') word[0] = 0; @@ -162,7 +155,7 @@ use_dict() clear(); move(4, 0); outs(buf); - addword(word); + addword(database,word); } } } @@ -171,7 +164,8 @@ use_dict() int x_dict() { - if (choose_dict()) - use_dict(); + char dict[41], database[41]; + if (choose_dict(dict,sizeof(dict),database,sizeof(database))) + use_dict(dict,database); return 0; } diff --git a/pttbbs/mbbsd/mail.c b/pttbbs/mbbsd/mail.c index b45bde0c..da078f1e 100644 --- a/pttbbs/mbbsd/mail.c +++ b/pttbbs/mbbsd/mail.c @@ -15,7 +15,7 @@ setforward() sethomepath(buf, cuser.userid); strcat(buf, "/.forward"); if ((fp = fopen(buf, "r"))) { - fscanf(fp, "%s", ip); + fscanf(fp, "%s", ip); // XXX check buffer size fclose(fp); } getdata_buf(b_lines - 1, 0, "請輸入信箱自動轉寄的email地址:", @@ -811,23 +811,20 @@ m_new() static void mailtitle() { - char buf[256] = ""; + char buf[256]; showtitle("\0郵件選單", BBSName); - snprintf(buf, sizeof(buf), - "[←]離開[↑↓]選擇[→]閱\讀信件 [R]回信 [x]轉達 " + prints("[←]離開[↑↓]選擇[→]閱\讀信件 [R]回信 [x]轉達 " "[y]群組回信 [O]站外信:%s [h]求助\n\033[7m" "編號 日 期 作 者 信 件 標 題 \033[32m", HAS_PERM(PERM_NOOUTMAIL) ? "\033[31m關\033[m" : "開"); - outs(buf); buf[0] = 0; if (mailsumlimit) { snprintf(buf, sizeof(buf), "(容量:%d/%dk %d/%d篇)", mailsum, mailsumlimit, mailkeep, mailmaxkeep); } - snprintf(buf, sizeof(buf), "%s%*s\033[m", buf, 29 - (int)strlen(buf), ""); - outs(buf); + prints("%-29s\033[m", buf); } static void @@ -960,10 +957,6 @@ mail_read(int ent, fileheader_t * fhdr, char *direct) mail_del(ent, fhdr, direct); else { fhdr->filemode |= FILE_READ; -#ifdef POSTBUG - if (replied) - bug_possible = YEA; -#endif if ((currmode & MODE_SELECT)) { int index; @@ -972,9 +965,6 @@ mail_read(int ent, fileheader_t * fhdr, char *direct) substitute_record(direct, fhdr, sizeof(*fhdr), ent); } else substitute_record(currmaildir, fhdr, sizeof(*fhdr), ent); -#ifdef POSTBUG - bug_possible = NA; -#endif } return FULLUPDATE; } diff --git a/pttbbs/mbbsd/mbbsd.c b/pttbbs/mbbsd/mbbsd.c index 3d5ba494..92e3b5e5 100644 --- a/pttbbs/mbbsd/mbbsd.c +++ b/pttbbs/mbbsd/mbbsd.c @@ -255,18 +255,15 @@ talk_request(int sig) bell(); bell(); if (currutmp->msgcount) { - char buf[200]; char timebuf[100]; time_t now = time(0); - snprintf(buf, sizeof(buf), - "\033[33;41m★%s\033[34;47m [%s] %s \033[0m", + move(0, 0); + clrtoeol(); + prints("\033[33;41m★%s\033[34;47m [%s] %s \033[0m", SHM->uinfo[currutmp->destuip].userid, my_ctime(&now,timebuf,sizeof(timebuf)), (currutmp->sig == 2) ? "重要消息廣播!(請Ctrl-U,l查看熱訊記錄)" : "呼叫、呼叫,聽到請回答"); - move(0, 0); - clrtoeol(); - outs(buf); refresh(); } else { unsigned char mode0 = currutmp->mode; diff --git a/pttbbs/mbbsd/page.c b/pttbbs/mbbsd/page.c index 9583f4c9..1757412f 100644 --- a/pttbbs/mbbsd/page.c +++ b/pttbbs/mbbsd/page.c @@ -8,15 +8,13 @@ static void print_station(const char *addr[6][100], int path, int *line, int *num) { int i; - char genbuf[128]; *num = 0; move(*line,0); do{ for(i=0; i<7 && addr[path - 1][*num]!=NULL; i++){ - sprintf(genbuf, " %2d.%-6s", (*num)+1, addr[path - 1][*num]); + prints(" %2d.%-6s", (*num)+1, addr[path - 1][*num]); (*num)++; - outs(genbuf); } outs("\n"); (*line)++; diff --git a/pttbbs/mbbsd/read.c b/pttbbs/mbbsd/read.c index cd20bd44..8ad1b32e 100644 --- a/pttbbs/mbbsd/read.c +++ b/pttbbs/mbbsd/read.c @@ -630,10 +630,10 @@ i_read_key(onekey_t * rcmdlist, keeploc_t * locmem, int ch, int bid) return READ_REDRAW; case 'G': - if (select_read(locmem,RS_THREAD)) /* marked articles */ - return NEWDIRECT; - else - return READ_REDRAW; + if (select_read(locmem,RS_THREAD)) /* marked articles */ + return NEWDIRECT; + else + return READ_REDRAW; case '/': case '?': diff --git a/pttbbs/mbbsd/record.c b/pttbbs/mbbsd/record.c index 491af517..e4c2897f 100644 --- a/pttbbs/mbbsd/record.c +++ b/pttbbs/mbbsd/record.c @@ -582,9 +582,9 @@ append_record(char *fpath, fileheader_t * record, int size) strncpy(buf, fpath, n + 1); buf[n + 1] = 0; for (m = strlen(buf) - 2; buf[m] != '/' && m > 0; m--); - strcat(buf, ".forward"); + strcat(buf, ".forward"); // XXX check buffer size if ((fp = fopen(buf, "r"))) { - fscanf(fp, "%s", address); + fscanf(fp, "%s", address); // XXX check buffer size fclose(fp); if (buf[0] != 0 && buf[0] != ' ') { buf[n + 1] = 0; diff --git a/pttbbs/mbbsd/register.c b/pttbbs/mbbsd/register.c index a9c3d672..51540ba1 100644 --- a/pttbbs/mbbsd/register.c +++ b/pttbbs/mbbsd/register.c @@ -222,9 +222,7 @@ new_register() if (id == 999999) outs("此代號已經有人使用 是不死之身"); else { - snprintf(passbuf, sizeof(passbuf), - "此代號已經有人使用 還有%d天才過期 \n", id / (60 * 24)); - outs(passbuf); + prints("此代號已經有人使用 還有%d天才過期 \n", id / (60 * 24)); } } else break; diff --git a/pttbbs/mbbsd/talk.c b/pttbbs/mbbsd/talk.c index 7b08e203..32718676 100644 --- a/pttbbs/mbbsd/talk.c +++ b/pttbbs/mbbsd/talk.c @@ -26,9 +26,6 @@ typedef struct pickup_t { int friend, uoffset; } pickup_t; -//extern int bind( /* int,struct sockaddr *, int */ ); -//extern char *getuserid(); - /* 記錄 friend 的 user number */ // #define PICKUP_WAYS 7 @@ -320,22 +317,17 @@ my_kick(userinfo_t * uentp) static void chicken_query(char *userid) { - char buf[100]; - if (getuser(userid)) { if (xuser.mychicken.name[0]) { time_diff(&(xuser.mychicken)); if (!isdeadth(&(xuser.mychicken))) { show_chicken_data(&(xuser.mychicken), NULL); - snprintf(buf, sizeof(buf), - "\n\n以上是 %s 的寵物資料..", userid); - outs(buf); + prints("\n\n以上是 %s 的寵物資料..", userid); } } else { move(1, 0); clrtobot(); - snprintf(buf, sizeof(buf), "\n\n%s 並沒有養寵物..", userid); - outs(buf); + prints("\n\n%s 並沒有養寵物..", userid); } pressanykey(); } @@ -1465,7 +1457,7 @@ static char * descript(int show_mode, userinfo_t * uentp, time_t diff) { switch (show_mode) { - case 1: + case 1: return friend_descript(uentp); case 0: return (((uentp->pager != 2 && uentp->pager != 3 && diff) || @@ -2277,9 +2269,7 @@ userlist(void) if (HAS_PERM(PERM_LOGINOK) && strcmp(uentp->userid, cuser.userid) != 0) { move(b_lines - 2, 0); - snprintf(genbuf, sizeof(genbuf), - "要給 %s 多少錢呢? ", uentp->userid); - outs(genbuf); + prints("要給 %s 多少錢呢? ", uentp->userid); if (getdata(b_lines - 1, 0, "[銀行轉帳]: ", genbuf, 7, LCECHO)) { clrtoeol(); @@ -2291,10 +2281,8 @@ userlist(void) outs("\033[41m 現金不足~~\033[m"); } else { deumoney(uentp->uid, ch - give_tax(ch)); - snprintf(genbuf, sizeof(genbuf), - "\033[44m 嗯..還剩下 %d 錢.." + prints("\033[44m 嗯..還剩下 %d 錢.." "\033[m", demoney(-ch)); - outs(genbuf); snprintf(genbuf, sizeof(genbuf), "%s\t給%s\t%d\t%s", cuser.userid, uentp->userid, ch, @@ -2431,7 +2419,7 @@ t_idle(void) int mode0 = currutmp->mode; int stat0 = currstat; char genbuf[20]; - char buf[80], passbuf[PASSLEN]; + char passbuf[PASSLEN]; setutmpmode(IDLE); getdata(b_lines - 1, 0, "理由:[0]發呆 (1)接電話 (2)覓食 (3)打瞌睡 " @@ -2453,10 +2441,8 @@ t_idle(void) do { move(b_lines - 2, 0); clrtoeol(); - snprintf(buf, sizeof(buf), - "(鎖定螢幕)發呆原因: %s", (currutmp->destuid != 6) ? + prints("(鎖定螢幕)發呆原因: %s", (currutmp->destuid != 6) ? IdleTypeTable[currutmp->destuid] : currutmp->chatid); - outs(buf); refresh(); getdata(b_lines - 1, 0, MSG_PASSWD, passbuf, sizeof(passbuf), NOECHO); passbuf[8] = '\0'; diff --git a/pttbbs/mbbsd/user.c b/pttbbs/mbbsd/user.c index 8849b9ff..c3e63595 100644 --- a/pttbbs/mbbsd/user.c +++ b/pttbbs/mbbsd/user.c @@ -835,9 +835,8 @@ getfield(int line, char *info, char *desc, char *buf, int len) char prompt[STRLEN]; char genbuf[200]; - snprintf(genbuf, sizeof(genbuf), "原先設定:%-30.30s (%s)", buf, info); move(line, 2); - outs(genbuf); + prints("原先設定:%-30.30s (%s)", buf, info); snprintf(prompt, sizeof(prompt), "%s:", desc); if (getdata_str(line + 1, 2, prompt, genbuf, len, DOECHO, buf)) strcpy(buf, genbuf); diff --git a/pttbbs/mbbsd/var.c b/pttbbs/mbbsd/var.c index 277bef8d..5125442e 100644 --- a/pttbbs/mbbsd/var.c +++ b/pttbbs/mbbsd/var.c @@ -312,9 +312,6 @@ char *ModeTypeTable[MAX_MODES] = { "" }; -/* indict.c */ -char dict[41], database[41]; - /* term.c */ int b_lines = 23; int t_lines = 24; diff --git a/pttbbs/mbbsd/voteboard.c b/pttbbs/mbbsd/voteboard.c index d477a12d..a0db074e 100644 --- a/pttbbs/mbbsd/voteboard.c +++ b/pttbbs/mbbsd/voteboard.c @@ -1,4 +1,4 @@ -/* $Id: voteboard.c,v 1.18 2003/06/28 08:47:45 kcwu Exp $ */ +/* $Id$ */ #include "bbs.h" #define VOTEBOARD "NewBoard" diff --git a/pttbbs/mbbsd/xyz.c b/pttbbs/mbbsd/xyz.c index aead7e5d..e0b850b5 100644 --- a/pttbbs/mbbsd/xyz.c +++ b/pttbbs/mbbsd/xyz.c @@ -7,9 +7,7 @@ int x_90() { - strcpy(dict, "(90)准考證號/姓名/學校/科系/類組"); - strcpy(database, "etc/90"); - use_dict(); + use_dict("(90)准考證號/姓名/學校/科系/類組", "etc/90"); return 0; } @@ -17,27 +15,21 @@ x_90() int x_89() { - strcpy(dict, "(89)准考證號/姓名/學校/科系/類組"); - strcpy(database, "etc/89"); - use_dict(); + use_dict("(89)准考證號/姓名/學校/科系/類組", "etc/89"); return 0; } /* Ptt88年度大學聯招查榜系統 */ int x_88() { - strcpy(dict, "(88)准考證號/姓名/學校/科系/類組"); - strcpy(database, "etc/88"); - use_dict(); + use_dict("(88)准考證號/姓名/學校/科系/類組", "etc/88"); return 0; } /* Ptt87年度大學聯招查榜系統 */ int x_87() { - strcpy(dict, "(87)准考證號/姓名/學校/科系"); - strcpy(database, "etc/87"); - use_dict(); + use_dict("(87)准考證號/姓名/學校/科系", "etc/87"); return 0; } @@ -45,9 +37,7 @@ x_87() int x_86() { - strcpy(dict, "(86)准考證號/姓名/學校/科系"); - strcpy(database, "etc/86"); - use_dict(); + use_dict("(86)准考證號/姓名/學校/科系", "etc/86"); return 0; } -- cgit v1.2.3 From d64ff0764b1d2b5953a04d07a616a2971de17995 Mon Sep 17 00:00:00 2001 From: kcwu <kcwu@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sat, 6 Sep 2003 19:53:46 +0000 Subject: fix bug git-svn-id: http://opensvn.csie.org/pttbbs/trunk@1167 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/bbs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pttbbs/mbbsd/bbs.c b/pttbbs/mbbsd/bbs.c index 47eeb65b..defd0061 100644 --- a/pttbbs/mbbsd/bbs.c +++ b/pttbbs/mbbsd/bbs.c @@ -760,7 +760,7 @@ edit_post(int ent, fileheader_t * fhdr, char *direct) lock_substitute_record(direct, fhdr, sizeof(*fhdr), ent, LOCK_EX); setbpath(fpath, currboard); stampfile(fpath, &postfile); - strlcpy(genbuf, fhdr->filename, strlen(genbuf)); + strlcpy(genbuf, fhdr->filename, sizeof(genbuf)); setbfile(fpath0, currboard, fhdr->filename); for(num = 2; genbuf[num] != NULL; num++){ -- cgit v1.2.3 From e8dae69cf6d375cbcf12c3d9727f3af7d5bdbed5 Mon Sep 17 00:00:00 2001 From: kcwu <kcwu@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sun, 7 Sep 2003 05:49:13 +0000 Subject: code cleanup git-svn-id: http://opensvn.csie.org/pttbbs/trunk@1168 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/bbs.c | 2 +- pttbbs/mbbsd/chat.c | 124 ++++++++++++++++++---------------------------------- pttbbs/mbbsd/mail.c | 2 +- pttbbs/mbbsd/more.c | 17 +------ pttbbs/mbbsd/talk.c | 19 ++++---- 5 files changed, 54 insertions(+), 110 deletions(-) diff --git a/pttbbs/mbbsd/bbs.c b/pttbbs/mbbsd/bbs.c index defd0061..bb7d7f9a 100644 --- a/pttbbs/mbbsd/bbs.c +++ b/pttbbs/mbbsd/bbs.c @@ -1436,7 +1436,7 @@ del_post(int ent, fileheader_t * fhdr, char *direct) return DONOTHING; getdata(1, 0, msg_del_ny, genbuf, 3, LCECHO); - if (genbuf[0] == 'y' || genbuf[0] == 'Y') { + if (genbuf[0] == 'y') { strlcpy(currfile, fhdr->filename, sizeof(currfile)); if (!delete_file(direct, sizeof(fileheader_t), ent, cmpfilename)) { if (currmode & MODE_SELECT) { diff --git a/pttbbs/mbbsd/chat.c b/pttbbs/mbbsd/chat.c index 5493608f..d7ea2f53 100644 --- a/pttbbs/mbbsd/chat.c +++ b/pttbbs/mbbsd/chat.c @@ -1,7 +1,8 @@ /* $Id$ */ #include "bbs.h" -static int chatline, stop_line; +#define STOP_LINE (t_lines-3) +static int chatline; static FILE *flog; static void printchatline(char *str) @@ -9,11 +10,11 @@ printchatline(char *str) move(chatline, 0); if (*str == '>' && !PERM_HIDE(currutmp)) return; - else if (chatline < stop_line - 1) + else if (chatline < STOP_LINE - 1) chatline++; else { - region_scroll_up(2, stop_line - 2); - move(stop_line - 2, 0); + region_scroll_up(2, STOP_LINE - 2); + move(STOP_LINE - 2, 0); } outs(str); outc('\n'); @@ -26,7 +27,7 @@ printchatline(char *str) static void chat_clear() { - for (chatline = 2; chatline < stop_line; chatline++) { + for (chatline = 2; chatline < STOP_LINE; chatline++) { move(chatline, 0); clrtoeol(); } @@ -61,9 +62,8 @@ static char chatroom[IDLEN];/* Chat-Room Name */ static int chat_recv(int fd, char *chatid) { - static char buf[512]; + static char buf[128]; static int bufstart = 0; - char genbuf[200]; int c, len; char *bptr; @@ -94,9 +94,8 @@ chat_recv(int fd, char *chatid) case 't': move(0, 0); clrtoeol(); - snprintf(genbuf, sizeof(genbuf), "談天室 [%s]", chatroom); - prints("\033[1;37;46m %-21s \033[45m 話題:%-48s\033[m", - genbuf, bptr + 2); + prints("\033[1;37;46m 談天室 [%-12s] \033[45m 話題:%-48s\033[m", + chatroom, bptr + 2); } } else printchatline(bptr); @@ -106,8 +105,7 @@ chat_recv(int fd, char *chatid) } if (c > 0) { - strlcpy(genbuf, bptr, sizeof(genbuf)); - strlcpy(buf, genbuf, sizeof(buf)); + memmove(buf, bptr, sizeof(buf)-(bptr-buf)); bufstart = len - 1; } else bufstart = 0; @@ -124,7 +122,7 @@ printuserent(userinfo_t * uentp) if (!uentp) { if (cnt) printchatline(uline); - bzero(uline, 80); + bzero(uline, sizeof(uline)); cnt = 0; return 0; } @@ -309,8 +307,6 @@ t_chat() int newmail; int chatting = YEA; char fpath[80]; - char genbuf[200]; - char roomtype; outs(" 驅車前往 請梢候........ "); if (!(h = gethostbyname("localhost"))) { @@ -325,40 +321,30 @@ t_chat() memcpy(&sin.sin_addr, h->h_addr, h->h_length); sin.sin_port = htons(NEW_CHATPORT); cfd = socket(sin.sin_family, SOCK_STREAM, 0); - if (!(connect(cfd, (struct sockaddr *) & sin, sizeof sin))) - roomtype = 1; - else { - sin.sin_port = CHATPORT; - cfd = socket(sin.sin_family, SOCK_STREAM, 0); - if (!(connect(cfd, (struct sockaddr *) & sin, sizeof sin))) - roomtype = 2; - else { - outs("\n " - "哇! 沒人在那邊耶...要有那地方的人先去開門啦!..."); - system("bin/xchatd"); - pressanykey(); - return -1; - } + if (connect(cfd, (struct sockaddr *) & sin, sizeof sin) != 0) { + outs("\n " + "哇! 沒人在那邊耶...要有那地方的人先去開門啦!..."); + system("bin/xchatd"); + pressanykey(); + close(cfd); + return -1; } while (1) { - getdata(b_lines - 1, 0, "請輸入聊天代號:", inbuf, 9, DOECHO); - snprintf(chatid, sizeof(chatid), - "%s", (inbuf[0] ? inbuf : cuser.userid)); + getdata(b_lines - 1, 0, "請輸入聊天代號:", chatid, 9, DOECHO); + if(!chatid[0]) + strlcpy(chatid, cuser.userid, sizeof(chatid)); chatid[8] = '\0'; /* - * 舊格式: /! 使用者編號 使用者等級 UserID ChatID 新格式: /! - * UserID ChatID Password + * 新格式: /! UserID ChatID Password */ - if (roomtype == 1) - snprintf(inbuf, sizeof(inbuf), "/! %s %s %s", - cuser.userid, chatid, cuser.passwd); - else - snprintf(inbuf, sizeof(inbuf), "/! %d %d %s %s", - usernum, cuser.userlevel, cuser.userid, chatid); + snprintf(inbuf, sizeof(inbuf), "/! %s %s %s", + cuser.userid, chatid, cuser.passwd); chat_send(cfd, inbuf); - if (recv(cfd, inbuf, 3, 0) != 3) + if (recv(cfd, inbuf, 3, 0) != 3) { + close(cfd); return 0; + } if (!strcmp(inbuf, CHAT_LOGIN_OK)) break; else if (!strcmp(inbuf, CHAT_LOGIN_EXISTS)) @@ -378,7 +364,7 @@ t_chat() newmail = currchar = 0; cmdpos = -1; - memset(lastcmd, 0, MAXLASTCMD * 80); + memset(lastcmd, 0, sizeof(lastcmd)); setutmpmode(CHATING); currutmp->in_chat = YEA; @@ -386,15 +372,13 @@ t_chat() clear(); chatline = 2; - strlcpy(inbuf, chatid, sizeof(inbuf)); - stop_line = t_lines - 3; - move(stop_line, 0); + move(STOP_LINE, 0); outs(msg_seperator); move(1, 0); outs(msg_seperator); print_chatid(chatid); - memset(inbuf, 0, 80); + memset(inbuf, 0, sizeof(inbuf)); sethomepath(fpath, cuser.userid); strlcpy(fpath, tempnam(fpath, "chat_"), sizeof(fpath)); @@ -435,9 +419,7 @@ t_chat() chatting = chat_send(cfd, "/b"); break; } - continue; - } - if (isprint2(ch)) { + } else if (isprint2(ch)) { if (currchar < 68) { if (inbuf[currchar]) { /* insert */ int i; @@ -452,9 +434,7 @@ t_chat() move(b_lines - 1, currchar + chatid_len); outs(&inbuf[currchar++]); } - continue; - } - if (ch == '\n' || ch == '\r') { + } else if (ch == '\n' || ch == '\r') { if (*inbuf) { chatting = chat_cmd(inbuf, cfd); if (chatting == 0) @@ -473,9 +453,7 @@ t_chat() } print_chatid(chatid); move(b_lines - 1, chatid_len); - continue; - } - if (ch == Ctrl('H') || ch == '\177') { + } else if (ch == Ctrl('H') || ch == '\177') { if (currchar) { currchar--; inbuf[69] = '\0'; @@ -484,20 +462,15 @@ t_chat() clrtoeol(); outs(&inbuf[currchar]); } - continue; - } - if (ch == Ctrl('Z') || ch == Ctrl('Y')) { + } else if (ch == Ctrl('Z') || ch == Ctrl('Y')) { inbuf[0] = '\0'; currchar = 0; print_chatid(chatid); move(b_lines - 1, chatid_len); - continue; - } - if (ch == Ctrl('C')) { + } else if (ch == Ctrl('C')) { chat_send(cfd, "/b"); break; - } - if (ch == Ctrl('D')) { + } else if (ch == Ctrl('D')) { if ((size_t)currchar < strlen(inbuf)) { inbuf[69] = '\0'; memcpy(&inbuf[currchar], &inbuf[currchar + 1], 69 - currchar); @@ -505,23 +478,15 @@ t_chat() clrtoeol(); outs(&inbuf[currchar]); } - continue; - } - if (ch == Ctrl('K')) { + } else if (ch == Ctrl('K')) { inbuf[currchar] = 0; move(b_lines - 1, currchar + chatid_len); clrtoeol(); - continue; - } - if (ch == Ctrl('A')) { + } else if (ch == Ctrl('A')) { currchar = 0; - continue; - } - if (ch == Ctrl('E')) { + } else if (ch == Ctrl('E')) { currchar = strlen(inbuf); - continue; - } - if (ch == Ctrl('I')) { + } else if (ch == Ctrl('I')) { screenline_t *screen0 = calloc(t_lines, sizeof(screenline_t)); memcpy(screen0, big_picture, t_lines * sizeof(screenline_t)); @@ -531,9 +496,7 @@ t_chat() free(screen0); redoscr(); add_io(cfd, 0); - continue; - } - if (ch == Ctrl('Q')) { + } else if (ch == Ctrl('Q')) { print_chatid(chatid); move(b_lines - 1, chatid_len); outs(inbuf); @@ -555,6 +518,7 @@ t_chat() if (*ans == 'm') { fileheader_t mymail; char title[128]; + char genbuf[200]; sethomepath(genbuf, cuser.userid); stampfile(genbuf, &mymail); @@ -569,7 +533,3 @@ t_chat() } return 0; } -/* -------------------------------------------------- */ -#if 0 - -#endif diff --git a/pttbbs/mbbsd/mail.c b/pttbbs/mbbsd/mail.c index da078f1e..e0dced0f 100644 --- a/pttbbs/mbbsd/mail.c +++ b/pttbbs/mbbsd/mail.c @@ -776,7 +776,7 @@ read_new_mail(fileheader_t * fptr) getdata(1, 0, msg_sure_ny, genbuf, 2, LCECHO); if (genbuf[0] == 'y') { unlink(fname); - delmsgs[delcnt++] = idc; + delmsgs[delcnt++] = idc; // FIXME 一次刪太多信 out of array boundary } } clear(); diff --git a/pttbbs/mbbsd/more.c b/pttbbs/mbbsd/more.c index b4fe1948..2a476632 100644 --- a/pttbbs/mbbsd/more.c +++ b/pttbbs/mbbsd/more.c @@ -1,4 +1,4 @@ -/* $Id: more.c,v 1.24 2003/01/23 18:39:23 in2 Exp $ */ +/* $Id$ */ #include "bbs.h" #define MORE_BUFSIZE 4096 #define MORE_WINSIZE 4096 @@ -117,19 +117,6 @@ more_readln(int fd, unsigned char *buf) return bytes; } -/* - * not used static int readln(FILE *fp, char *buf) { register int ch, i, len, - * bytes, in_ansi; - * - * len = bytes = in_ansi = i = 0; while(len < 80 && i < ANSILINELEN && (ch = - * getc(fp)) != EOF) { bytes++; if(ch == '\n') break; else if(ch == '\t') do - * { buf[i++] = ' '; } while((++len & 7) && len < 80); else if(ch == '\a') - * beep = 1; else if(ch == '\033') { if(showansi) buf[i++] = ch; in_ansi = 1; - * } else if(in_ansi) { if(showansi) buf[i++] = ch; - * if(!strchr("[0123456789;,", ch)) in_ansi = 0; } else if(isprint2(ch)) { - * len++; buf[i++] = ch; } } buf[i] = '\0'; return bytes; } - */ - int more(char *fpath, int promptend) { @@ -137,8 +124,6 @@ more(char *fpath, int promptend) char *ptr, *word = NULL, buf[ANSILINELEN + 1]; struct stat st; - /* rocker */ - //FILE * fp; int fd, fsize; unsigned int pagebreak[MAX_PAGES], pageno, lino = 0; diff --git a/pttbbs/mbbsd/talk.c b/pttbbs/mbbsd/talk.c index 32718676..2ef59c86 100644 --- a/pttbbs/mbbsd/talk.c +++ b/pttbbs/mbbsd/talk.c @@ -37,7 +37,6 @@ static char *fcolor[11] = { }; static char save_page_requestor[40]; static char page_requestor[40]; -static char description[30]; static FILE *flog; int @@ -1414,14 +1413,13 @@ t_showhelp() /* Kaede show friend description */ static char * -friend_descript(userinfo_t * uentp) +friend_descript(userinfo_t * uentp, char *desc_buf, int desc_buflen) { char *space_buf = ""; - static char desc_buf[80]; char fpath[80], name[IDLEN + 2], *desc, *ptr; int len, flag; FILE *fp; - char genbuf[200]; + char genbuf[STRLEN]; if((set_friend_bit(currutmp,uentp)|IFH)==0) return space_buf; @@ -1443,7 +1441,7 @@ friend_descript(userinfo_t * uentp) } fclose(fp); if (flag) - strlcpy(desc_buf, desc, sizeof(desc_buf)); + strlcpy(desc_buf, desc, desc_buflen); else return space_buf; @@ -1456,9 +1454,10 @@ friend_descript(userinfo_t * uentp) static char * descript(int show_mode, userinfo_t * uentp, time_t diff) { + static char description[30]; switch (show_mode) { case 1: - return friend_descript(uentp); + return friend_descript(uentp, description, sizeof(description)); case 0: return (((uentp->pager != 2 && uentp->pager != 3 && diff) || HAS_PERM(PERM_SYSOP)) ? @@ -1473,13 +1472,11 @@ descript(int show_mode, userinfo_t * uentp, time_t diff) snprintf(description, sizeof(description), "%3d/%3d/%3d", uentp->five_win, uentp->five_lose, uentp->five_tie); - description[20] = 0; return description; case 3: snprintf(description, sizeof(description), "%3d/%3d/%3d", uentp->chc_win, uentp->chc_lose, uentp->chc_tie); - description[20] = 0; return description; default: syslog(LOG_WARNING, "damn!!! what's wrong?? show_mode = %d", @@ -1841,7 +1838,7 @@ userlist(void) static char show_uid = 0; static char show_board = 0; static char show_pid = 0; - char genbuf[256], skippickup = 0, redraw, redrawall; + char skippickup = 0, redraw, redrawall; int page, offset, pickup_way, ch, leave, fri_stat; int nfriend, myfriend, friendme, bfriend, badfriend, i; time_t lastupdate; @@ -2124,9 +2121,10 @@ userlist(void) case 'b': /* broadcast */ if (cuser.uflag & FRIEND_FLAG || HAS_PERM(PERM_SYSOP)) { + char genbuf[60]; char ans[4]; - if (!getdata(0, 0, "廣播訊息:", genbuf, 60, DOECHO)) + if (!getdata(0, 0, "廣播訊息:", genbuf, sizeof(genbuf), DOECHO)) break; if (getdata(0, 0, "確定廣播? [Y]", ans, sizeof(ans), LCECHO) && @@ -2268,6 +2266,7 @@ userlist(void) case 'g': if (HAS_PERM(PERM_LOGINOK) && strcmp(uentp->userid, cuser.userid) != 0) { + char genbuf[128]; move(b_lines - 2, 0); prints("要給 %s 多少錢呢? ", uentp->userid); if (getdata(b_lines - 1, 0, "[銀行轉帳]: ", -- cgit v1.2.3 From 991514bc8df9665e43bf2e23710bccb2f22eb3ab Mon Sep 17 00:00:00 2001 From: victor <victor@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Tue, 9 Sep 2003 04:30:38 +0000 Subject: admin.c: multiple reason for rejection mbbsd.c: change the sequence of some action git-svn-id: http://opensvn.csie.org/pttbbs/trunk@1169 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/admin.c | 16 ++++-- pttbbs/mbbsd/mbbsd.c | 156 +++++++++++++++++++++++++++++++-------------------- 2 files changed, 105 insertions(+), 67 deletions(-) diff --git a/pttbbs/mbbsd/admin.c b/pttbbs/mbbsd/admin.c index e6f30b20..a4770a18 100644 --- a/pttbbs/mbbsd/admin.c +++ b/pttbbs/mbbsd/admin.c @@ -779,6 +779,7 @@ scan_register_form(char *regfile, int automode, int neednum) "詳填連絡電話 (含區域碼, 中間不用加 \"-\", \"(\", \")\"等符號", "確實填寫註冊申請表", "用中文填寫申請單", + "輸入真實身分證字號", NULL }; char *autoid = "AutoScan"; @@ -920,11 +921,6 @@ scan_register_form(char *regfile, int automode, int neednum) char title[128], buf1[80]; FILE *fp; - i = buf[0] - '0'; - strlcpy(buf, reason[i], sizeof(buf)); - snprintf(genbuf, sizeof(genbuf), - "[退回原因] 請%s", buf); - sethomepath(buf1, muser.userid); stampfile(buf1, &mhdr); strlcpy(mhdr.owner, cuser.userid, sizeof(mhdr.owner)); @@ -933,7 +929,15 @@ scan_register_form(char *regfile, int automode, int neednum) sethomedir(title, muser.userid); if (append_record(title, &mhdr, sizeof(mhdr)) != -1) { fp = fopen(buf1, "w"); - fprintf(fp, "%s\n", genbuf); + + for(i = 0; buf[i] && i < sizeof(buf); i++){ + if (!isdigit(buf[i])) + continue; + snprintf(genbuf, sizeof(genbuf), + "[退回原因] 請%s", reason[buf[i] - '0']); + fprintf(fp, "%s\n", genbuf); + } + fclose(fp); } if ((fout = fopen(logfile, "a"))) { diff --git a/pttbbs/mbbsd/mbbsd.c b/pttbbs/mbbsd/mbbsd.c index 92e3b5e5..5cf1fb90 100644 --- a/pttbbs/mbbsd/mbbsd.c +++ b/pttbbs/mbbsd/mbbsd.c @@ -756,11 +756,94 @@ setup_utmp(int mode) #endif } +inline static void welcome_msg(void) { + prints("\033[m 歡迎您第 \033[1;33m%d\033[0;37m 度拜訪本站," + "上次您是從 \033[1;33m%s\033[0;37m 連往本站,\n" + " 我記得那天是 \033[1;33m%s\033[0;37m。\n", + ++cuser.numlogins, cuser.lasthost, Cdate(&cuser.lastlogin)); + pressanykey(); +} + +inline static void check_bad_login(void) { + char genbuf[200]; + setuserfile(genbuf, str_badlogin); + if (more(genbuf, NA) != -1) { + move(b_lines - 3, 0); + prints("通常並沒有辦法知道該ip是誰所有, " + "以及其意圖(是不小心按錯或有意測您密碼)\n" + "若您有帳號被盜用疑慮, 請經常更改您的密碼或使用加密連線"); + if (getans("您要刪除以上錯誤嘗試的記錄嗎(Y/N)?[Y]") != 'n') + unlink(genbuf); + } +} + +inline static void birthday_make_a_wish(struct tm *ptime, struct tm *tmp){ + if (currutmp->birth && tmp->tm_mday != ptime->tm_mday) { + more("etc/birth.post", YEA); + brc_initial("WhoAmI"); + set_board(); + do_post(); + } +} + +inline static void record_lasthost(char *fromhost){ + strncpy(cuser.lasthost, fromhost, sizeof(cuser.lasthost)); + cuser.lasthost[sizeof(cuser.lasthost - 1)] = '\0'; +} + +inline static void check_mailbox_and_read(void){ + if (chkmailbox()) + m_read(); +} + +static void init_guest_info(void) +{ + int i; + char *nick[13] = { + "椰子", "貝殼", "內衣", "寶特瓶", "翻車魚", + "樹葉", "浮萍", "鞋子", "潛水艇", "魔王", + "鐵罐", "考卷", "大美女" + }; + char *name[13] = { + "大王椰子", "鸚鵡螺", "比基尼", "可口可樂", "仰泳的魚", + "憶", "高岡屋", "AIR Jordon", "紅色十月號", "批踢踢", + "SASAYA椰奶", "鴨蛋", "布魯克鱈魚香絲" + }; + char *addr[13] = { + "天堂樂園", "大海", "綠島小夜曲", "美國", "綠色珊瑚礁", + "遠方", "原本海", "NIKE", "蘇聯", "男八618室", + "愛之味", "天上", "藍色珊瑚礁" + }; + i = login_start_time % 13; + snprintf(cuser.username, sizeof(cuser.username), + "海邊漂來的%s", nick[(int)i]); + strlcpy(currutmp->username, cuser.username, + sizeof(currutmp->username)); + strlcpy(cuser.realname, name[(int)i], sizeof(cuser.realname)); + //strlcpy(currutmp->realname, cuser.realname, sizeof(currutmp->realname)); + strlcpy(cuser.address, addr[(int)i], sizeof(cuser.address)); + cuser.sex = i % 8; + currutmp->pager = 2; +} + +#ifdef FOREIGN_REG +inline static void foreign_warning(void){ + if ((cuser.uflag2 & FOREIGN) && !(cuser.uflag2 & LIVERIGHT)){ + if (login_start_time - cuser.firstlogin > (FOREIGN_REG_DAY - 5) * 24 * 3600){ + mail_muser(cuser, "[出入境管理局]", "etc/foreign_expired_warn"); + } + else if (login_start_time - cuser.firstlogin > FOREIGN_REG_DAY * 24 * 3600){ + cuser.userlevel &= ~(PERM_LOGINOK | PERM_POST); + vmsg("警告:請至出入境管理局申請永久居留"); + } + } +} +#endif + static void user_login() { char i; - char genbuf[200]; struct tm *ptime, *tmp; time_t now; int a, ifbirth; @@ -827,74 +910,27 @@ user_login() if (cuser.userlevel) { /* not guest */ move(t_lines - 4, 0); - prints("\033[m 歡迎您第 \033[1;33m%d\033[0;37m 度拜訪本站," - "上次您是從 \033[1;33m%s\033[0;37m 連往本站,\n" - " 我記得那天是 \033[1;33m%s\033[0;37m。\n", - ++cuser.numlogins, cuser.lasthost, Cdate(&cuser.lastlogin)); - pressanykey(); + welcome_msg(); - if (currutmp->birth && tmp->tm_mday != ptime->tm_mday) { - more("etc/birth.post", YEA); - brc_initial("WhoAmI"); - set_board(); - do_post(); - } - setuserfile(genbuf, str_badlogin); - if (more(genbuf, NA) != -1) { - move(b_lines - 3, 0); - prints("通常並沒有辦法知道該ip是誰所有, " - "以及其意圖(是不小心按錯或有意測您密碼)\n" - "若您有帳號被盜用疑慮, 請經常更改您的密碼或使用加密連線"); - if (getans("您要刪除以上錯誤嘗試的記錄嗎(Y/N)?[Y]") != 'n') - unlink(genbuf); - } + birthday_make_a_wish(ptime, tmp); + check_bad_login(); + check_mailbox_and_read(); check_register(); - strncpy(cuser.lasthost, fromhost, 16); - cuser.lasthost[15] = '\0'; + record_lasthost(fromhost); restore_backup(); } else if (!strcmp(cuser.userid, STR_GUEST)) { - char *nick[13] = { - "椰子", "貝殼", "內衣", "寶特瓶", "翻車魚", - "樹葉", "浮萍", "鞋子", "潛水艇", "魔王", - "鐵罐", "考卷", "大美女" - }; - char *name[13] = { - "大王椰子", "鸚鵡螺", "比基尼", "可口可樂", "仰泳的魚", - "憶", "高岡屋", "AIR Jordon", "紅色十月號", "批踢踢", - "SASAYA椰奶", "鴨蛋", "布魯克鱈魚香絲" - }; - char *addr[13] = { - "天堂樂園", "大海", "綠島小夜曲", "美國", "綠色珊瑚礁", - "遠方", "原本海", "NIKE", "蘇聯", "男八618室", - "愛之味", "天上", "藍色珊瑚礁" - }; - i = login_start_time % 13; - snprintf(cuser.username, sizeof(cuser.username), - "海邊漂來的%s", nick[(int)i]); - strlcpy(currutmp->username, cuser.username, - sizeof(currutmp->username)); - strlcpy(cuser.realname, name[(int)i], sizeof(cuser.realname)); - //strlcpy(currutmp->realname, cuser.realname, sizeof(currutmp->realname)); - strlcpy(cuser.address, addr[(int)i], sizeof(cuser.address)); - cuser.sex = i % 8; - currutmp->pager = 2; + init_guest_info(); pressanykey(); - } else + } else { pressanykey(); + check_mailbox_and_read(); + } if (!PERM_HIDE(currutmp)) cuser.lastlogin = login_start_time; #ifdef FOREIGN_REG - if ((cuser.uflag2 & FOREIGN) && !(cuser.uflag2 & LIVERIGHT)){ - if (login_start_time - cuser.firstlogin > (FOREIGN_REG_DAY - 5) * 24 * 3600){ - mail_muser(cuser, "[出入境管理局]", "etc/foreign_expired_warn"); - } - else if (login_start_time - cuser.firstlogin > FOREIGN_REG_DAY * 24 * 3600){ - cuser.userlevel &= ~(PERM_LOGINOK | PERM_POST); - vmsg("警告:請至出入境管理局申請永久居留"); - } - } + foreign_warning(); #endif passwd_update(usernum, &cuser); @@ -973,8 +1009,8 @@ start_client() signal(SIGALRM, abort_bbs); alarm(600); login_query(); /* Ptt 加上login time out */ + m_init(); /* init the user mail path */ user_login(); - m_init(); if (now - SHM->close_vote_time > 86400) //改為一天一次 @@ -985,8 +1021,6 @@ start_client() if (!(cuser.uflag & COLOR_FLAG)) showansi = 0; signal(SIGALRM, SIG_IGN); - if (chkmailbox()) - m_read(); domenu(MMENU, "主功\能表", (currutmp->mailalert ? 'M' : 'C'), cmdlist); } -- cgit v1.2.3 From 32db8b811e2bde4df23155db4fe84ab5c8afeb0f Mon Sep 17 00:00:00 2001 From: victor <victor@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Tue, 9 Sep 2003 05:23:31 +0000 Subject: merge chc from my branch git-svn-id: http://opensvn.csie.org/pttbbs/trunk@1170 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/include/chc.h | 41 ++ pttbbs/include/proto.h | 21 +- pttbbs/mbbsd/chc.c | 1030 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 1075 insertions(+), 17 deletions(-) create mode 100644 pttbbs/include/chc.h create mode 100644 pttbbs/mbbsd/chc.c diff --git a/pttbbs/include/chc.h b/pttbbs/include/chc.h new file mode 100644 index 00000000..9305ab0d --- /dev/null +++ b/pttbbs/include/chc.h @@ -0,0 +1,41 @@ +/* 象棋 + * 雙人對戰時,雙方都會有一個 chc_act_list 的 linked-list,紀錄著每下一步 + * 棋,必須將這個訊息丟給那些人(socket)。 + * 一開始當然就是對手一個,每當一個觀棋者加入(觀棋可以從紅方或黑方的觀點 + * 進行),其中一方的下棋者的 act_list 就會多一筆記錄,之後就會將下的或收 + * 到對方下的每一步棋傳給 act_list 中所有需要的人,達到觀棋的效果。 + */ + +#define SIDE_ROW 7 +#define TURN_ROW 8 +#define STEP_ROW 9 +#define TIME_ROW 10 +#define WARN_ROW 12 +#define MYWIN_ROW 17 +#define HISWIN_ROW 18 + +#define CHC_VERSUS 1 /* 雙人 */ +#define CHC_WATCH 2 /* 觀棋 */ +#define CHC_PERSONAL 4 /* 打譜 */ +#define CHC_WATCH_PERSONAL 8 /* 觀人打譜 */ + +#define BLACK_COLOR "\033[1;36m" +#define RED_COLOR "\033[1;31m" +#define BLACK_REVERSE "\033[1;37;46m" +#define RED_REVERSE "\033[1;37;41m" +#define TURN_COLOR "\033[1;33m" + +typedef struct chcusr_t{ + char userid[IDLEN + 1]; + int win; + int lose; + int tie; +} chcusr_t; + +#define CHC_ACT_BOARD 0x1 /* set if transfered board to this sock */ + +typedef struct chc_act_list{ + int sock; + struct chc_act_list *next; +} chc_act_list; + diff --git a/pttbbs/include/proto.h b/pttbbs/include/proto.h index bbb603df..5c287dd1 100644 --- a/pttbbs/include/proto.h +++ b/pttbbs/include/proto.h @@ -164,24 +164,11 @@ int card_99(); /* chat */ int t_chat(); -/* chc_draw */ -void chc_drawline(board_t board, chcusr_t *user1, chcusr_t *user2, int line); -void chc_movecur(int r, int c); -void chc_redraw(chcusr_t *user1, chcusr_t *user2, board_t board); - -/* chc_net */ -void chc_sendmove(int s); -int chc_recvmove(int s); - -/* chc_play */ +/* chc */ void chc(int s, int mode); - -/* chc_rule */ -void chc_movechess(board_t board); -int chc_canmove(board_t board, rc_t from, rc_t to); -int chc_iskfk(board_t board); -int chc_ischeck(board_t board, int turn); -void chc_init_board(board_t board); +int chc_main(void); +int chc_personal(void); +int chc_watch(void); /* chicken */ int show_file(char *filename, int y, int lines, int mode); diff --git a/pttbbs/mbbsd/chc.c b/pttbbs/mbbsd/chc.c new file mode 100644 index 00000000..fbd716a1 --- /dev/null +++ b/pttbbs/mbbsd/chc.c @@ -0,0 +1,1030 @@ +#include "bbs.h" + +#define CENTER(a, b) (((a) + (b)) >> 1) +#define CHC_TIMEOUT 300 +#define CHC_LOG "chc_log" /* log file name */ + +extern userinfo_t *uip; + +typedef int (*play_func_t) (int, chcusr_t *, chcusr_t *, board_t, board_t); + +typedef struct drc_t { + rc_t from, to; +} drc_t; + +static rc_t chc_from, chc_to, chc_select, chc_cursor; +static int chc_lefttime; +static int chc_my, chc_turn, chc_selected, chc_firststep; +static char chc_mode; +static char chc_warnmsg[64]; +static char chc_ipass = 0, chc_hepass = 0; +/* fp is for logging the step */ +static FILE *fp = NULL; +static board_t *chc_bp; +static chc_act_list *act_list = NULL; + + +/* some constant variable definition */ + +static const char *turn_str[2] = {"黑的", "紅的"}; + +static const char *num_str[10] = { + "", "一", "二", "三", "四", "五", "六", "七", "八", "九" +}; + +static const char *chess_str[2][8] = { + /* 0 1 2 3 4 5 6 7 */ + {" ", "將", "士", "象", "車", "馬", "包", "卒"}, + {" ", "帥", "仕", "相", "車", "傌", "炮", "兵"} +}; + +static const char *chess_brd[BRD_ROW * 2 - 1] = { + /* 0 1 2 3 4 5 6 7 8 */ + "┌─┬─┬─┬─┬─┬─┬─┬─┐", /* 0 */ + "│ │ │ │\│/│ │ │ │", + "├─┼─┼─┼─┼─┼─┼─┼─┤", /* 1 */ + "│ │ │ │/│\│ │ │ │", + "├─┼─┼─┼─┼─┼─┼─┼─┤", /* 2 */ + "│ │ │ │ │ │ │ │ │", + "├─┼─┼─┼─┼─┼─┼─┼─┤", /* 3 */ + "│ │ │ │ │ │ │ │ │", + "├─┴─┴─┴─┴─┴─┴─┴─┤", /* 4 */ + "│ 楚 河 漢 界 │", + "├─┬─┬─┬─┬─┬─┬─┬─┤", /* 5 */ + "│ │ │ │ │ │ │ │ │", + "├─┼─┼─┼─┼─┼─┼─┼─┤", /* 6 */ + "│ │ │ │ │ │ │ │ │", + "├─┼─┼─┼─┼─┼─┼─┼─┤", /* 7 */ + "│ │ │ │\│/│ │ │ │", + "├─┼─┼─┼─┼─┼─┼─┼─┤", /* 8 */ + "│ │ │ │/│\│ │ │ │", + "└─┴─┴─┴─┴─┴─┴─┴─┘" /* 9 */ +}; + +static char *hint_str[] = { + " q 認輸離開", + " p 要求和棋", + "方向鍵 移動遊標", + "Enter 選擇/移動" +}; + +/* + * Start of the network communication function. + */ +static int +chc_recvmove(int s) +{ + drc_t buf; + + if (read(s, &buf, sizeof(buf)) != sizeof(buf)) + return 0; + chc_from = buf.from, chc_to = buf.to; + return 1; +} + +static int +chc_sendmove(int s) +{ + drc_t buf; + + buf.from = chc_from, buf.to = chc_to; + if (write(s, &buf, sizeof(buf)) != sizeof(buf)) + return 0; + return 1; +} + +static void +chc_broadcast(chc_act_list *p, board_t board){ + while(p){ + if (chc_sendmove(p->sock) < 0) { + if (p->next->next == NULL) + p = NULL; + else { + chc_act_list *tmp = p->next->next; + p->next = tmp; + } + free(p->next); + } + p = p->next; + } +} + +static int +chc_broadcast_recv(chc_act_list *act_list, board_t board){ + if (!chc_recvmove(act_list->sock)) + return 0; + chc_broadcast(act_list->next, board); + return 1; +} + +static void +chc_broadcast_send(chc_act_list *act_list, board_t board){ + chc_broadcast(act_list, board); +} + +/* + * End of the network communication function. + */ + +/* + * Start of the drawing function. + */ +static void +chc_movecur(int r, int c) +{ + move(r * 2 + 3, c * 4 + 4); +} + +static char * +getstep(board_t board, rc_t *from, rc_t *to) +{ + int turn, fc, tc; + char *dir; + static char buf[80]; + + turn = CHE_O(board[from->r][from->c]); + fc = (turn == (chc_my ^ 1) ? from->c + 1 : 9 - from->c); + tc = (turn == (chc_my ^ 1) ? to->c + 1 : 9 - to->c); + if (from->r == to->r) + dir = "平"; + else { + if (from->c == to->c) + tc = from->r - to->r; + if (tc < 0) + tc = -tc; + + if ((turn == (chc_my ^ 1) && to->r > from->r) || + (turn == chc_my && to->r < from->r)) + dir = "進"; + else + dir = "退"; + } + sprintf(buf, "%s%s%s%s", + chess_str[turn][CHE_P(board[from->r][from->c])], + num_str[fc], dir, num_str[tc]); + return buf; +} + +static void +showstep(board_t board) +{ + int eatten; + + prints("%s%s", CHE_O(board[chc_from.r][chc_from.c]) == 0 ? BLACK_COLOR : RED_COLOR, getstep(board, &chc_from, &chc_to)); + + eatten = board[chc_to.r][chc_to.c]; + if (eatten) + prints(": %s%s", + CHE_O(eatten) == 0 ? BLACK_COLOR : RED_COLOR, + chess_str[CHE_O(eatten)][CHE_P(eatten)]); + prints("\033[m"); +} + +static void +chc_drawline(board_t board, chcusr_t *user1, chcusr_t *user2, int line) +{ + int i, j; + + move(line, 0); + clrtoeol(); + if (line == 0) { + prints("\033[1;46m 象棋對戰 \033[45m%30s VS %-20s%10s\033[m", + user1->userid, user2->userid, chc_mode & CHC_WATCH ? "[觀棋模式]" : ""); + } else if (line >= 3 && line <= 21) { + outs(" "); + for (i = 0; i < 9; i++) { + j = board[RTL(line)][i]; + if ((line & 1) == 1 && j) { + if (chc_selected && + chc_select.r == RTL(line) && chc_select.c == i) + prints("%s%s\033[m", + CHE_O(j) == 0 ? BLACK_REVERSE : RED_REVERSE, + chess_str[CHE_O(j)][CHE_P(j)]); + else + prints("%s%s\033[m", + CHE_O(j) == 0 ? BLACK_COLOR : RED_COLOR, + chess_str[CHE_O(j)][CHE_P(j)]); + } else + prints("%c%c", chess_brd[line - 3][i * 4], + chess_brd[line - 3][i * 4 + 1]); + if (i != 8) + prints("%c%c", chess_brd[line - 3][i * 4 + 2], + chess_brd[line - 3][i * 4 + 3]); + } + outs(" "); + + if (line >= 3 && line < 3 + (int)dim(hint_str)) { + outs(hint_str[line - 3]); + } else if (line == SIDE_ROW) { + prints("\033[1m你是%s%s\033[m", + chc_my == 0 ? BLACK_COLOR : RED_COLOR, + turn_str[chc_my]); + } else if (line == TURN_ROW) { + prints("%s%s\033[m", + TURN_COLOR, + chc_my == chc_turn ? "輪到你下棋了" : "等待對方下棋"); + } else if (line == STEP_ROW && !chc_firststep) { + showstep(board); + } else if (line == TIME_ROW) { + prints("剩餘時間 %d:%02d", chc_lefttime / 60, chc_lefttime % 60); + } else if (line == WARN_ROW) { + outs(chc_warnmsg); + } else if (line == MYWIN_ROW) { + prints("\033[1;33m%12.12s " + "\033[1;31m%2d\033[37m勝 " + "\033[34m%2d\033[37m敗 " + "\033[36m%2d\033[37m和\033[m", + user1->userid, + user1->win, user1->lose - 1, user1->tie); + } else if (line == HISWIN_ROW) { + prints("\033[1;33m%12.12s " + "\033[1;31m%2d\033[37m勝 " + "\033[34m%2d\033[37m敗 " + "\033[36m%2d\033[37m和\033[m", + user2->userid, + user2->win, user2->lose - 1, user2->tie); + } + } else if (line == 2 || line == 22) { + outs(" "); + if (line == 2) + for (i = 1; i <= 9; i++) + prints("%s ", num_str[i]); + else + for (i = 9; i >= 1; i--) + prints("%s ", num_str[i]); + } +} + +static void +chc_redraw(chcusr_t *user1, chcusr_t *user2, board_t board) +{ + int i; + for (i = 0; i <= 22; i++) + chc_drawline(board, user1, user2, i); +} +/* + * End of the drawing function. + */ + + +/* + * Start of the log function. + */ +int +chc_log_open(chcusr_t *user1, chcusr_t *user2, char *file) +{ + char buf[128]; + if ((fp = fopen(file, "w")) == NULL) + return -1; + sprintf(buf, "%s V.S. %s\n", user1->userid, user2->userid); + fputs(buf, fp); + return 0; +} + +void +chc_log_close(void) +{ + if (fp) + fclose(fp); +} + +int +chc_log(char *desc) +{ + if (fp) + return fputs(desc, fp); + return -1; +} + +int +chc_log_step(board_t board, rc_t *from, rc_t *to) +{ + char buf[80]; + sprintf(buf, " %s%s\033[m\n", CHE_O(board[from->r][from->c]) == 0 ? BLACK_COLOR : RED_COLOR, getstep(board, from, to)); + return chc_log(buf); +} + +static int +chc_filter(struct dirent *dir) +{ + if (strcmp(dir->d_name, ".") == 0 || strcmp(dir->d_name, "..") == 0 ) + return 0; + return strstr(dir->d_name, ".poem") != NULL; +} + +int +chc_log_poem(void) +{ + struct dirent **namelist; + int n; + + n = scandir(BBSHOME"/etc/chess", &namelist, chc_filter, alphasort); + if (n < 0) + perror("scandir"); + else { + char buf[80]; + FILE *fp; + sprintf(buf, BBSHOME"/etc/chess/%s", namelist[rand() % n]->d_name); + if ((fp = fopen(buf, "r")) == NULL) + return -1; + + while(fgets(buf, sizeof(buf), fp) != NULL) + chc_log(buf); + while(n--) + free(namelist[n]); + free(namelist); + fclose(fp); + } + return 0; +} +/* + * End of the log function. + */ + + +/* + * Start of the rule function. + */ + +static void +chc_init_board(board_t board) +{ + memset(board, 0, sizeof(board_t)); + board[0][4] = CHE(1, chc_my ^ 1); /* 將 */ + board[0][3] = board[0][5] = CHE(2, chc_my ^ 1); /* 士 */ + board[0][2] = board[0][6] = CHE(3, chc_my ^ 1); /* 象 */ + board[0][0] = board[0][8] = CHE(4, chc_my ^ 1); /* 車 */ + board[0][1] = board[0][7] = CHE(5, chc_my ^ 1); /* 馬 */ + board[2][1] = board[2][7] = CHE(6, chc_my ^ 1); /* 包 */ + board[3][0] = board[3][2] = board[3][4] = + board[3][6] = board[3][8] = CHE(7, chc_my ^ 1); /* 卒 */ + + board[9][4] = CHE(1, chc_my); /* 帥 */ + board[9][3] = board[9][5] = CHE(2, chc_my); /* 仕 */ + board[9][2] = board[9][6] = CHE(3, chc_my); /* 相 */ + board[9][0] = board[9][8] = CHE(4, chc_my); /* 車 */ + board[9][1] = board[9][7] = CHE(5, chc_my); /* 傌 */ + board[7][1] = board[7][7] = CHE(6, chc_my); /* 炮 */ + board[6][0] = board[6][2] = board[6][4] = + board[6][6] = board[6][8] = CHE(7, chc_my); /* 兵 */ +} + +static void +chc_movechess(board_t board) +{ + board[chc_to.r][chc_to.c] = board[chc_from.r][chc_from.c]; + board[chc_from.r][chc_from.c] = 0; +} + +static int +dist(rc_t from, rc_t to, int rowcol) +{ + int d; + + d = rowcol ? from.c - to.c : from.r - to.r; + return d > 0 ? d : -d; +} + +static int +between(board_t board, rc_t from, rc_t to, int rowcol) +{ + int i, rtv = 0; + + if (rowcol) { + if (from.c > to.c) + i = from.c, from.c = to.c, to.c = i; + for (i = from.c + 1; i < to.c; i++) + if (board[to.r][i]) + rtv++; + } else { + if (from.r > to.r) + i = from.r, from.r = to.r, to.r = i; + for (i = from.r + 1; i < to.r; i++) + if (board[i][to.c]) + rtv++; + } + return rtv; +} + +static int +chc_canmove(board_t board, rc_t from, rc_t to) +{ + int i; + int rd, cd, turn; + + rd = dist(from, to, 0); + cd = dist(from, to, 1); + turn = CHE_O(board[from.r][from.c]); + + /* general check */ + if (board[to.r][to.c] && CHE_O(board[to.r][to.c]) == turn) + return 0; + + /* individual check */ + switch (CHE_P(board[from.r][from.c])) { + case 1: /* 將 帥 */ + if (!(rd == 1 && cd == 0) && + !(rd == 0 && cd == 1)) + return 0; + if ((turn == (chc_my ^ 1) && to.r > 2) || + (turn == chc_my && to.r < 7) || + to.c < 3 || to.c > 5) + return 0; + break; + case 2: /* 士 仕 */ + if (!(rd == 1 && cd == 1)) + return 0; + if ((turn == (chc_my ^ 1) && to.r > 2) || + (turn == chc_my && to.r < 7) || + to.c < 3 || to.c > 5) + return 0; + break; + case 3: /* 象 相 */ + if (!(rd == 2 && cd == 2)) + return 0; + if ((turn == (chc_my ^ 1) && to.r > 4) || + (turn == chc_my && to.r < 5)) + return 0; + /* 拐象腿 */ + if (board[CENTER(from.r, to.r)][CENTER(from.c, to.c)]) + return 0; + break; + case 4: /* 車 */ + if (!(rd > 0 && cd == 0) && + !(rd == 0 && cd > 0)) + return 0; + if (between(board, from, to, rd == 0)) + return 0; + break; + case 5: /* 馬 傌 */ + if (!(rd == 2 && cd == 1) && + !(rd == 1 && cd == 2)) + return 0; + /* 拐馬腳 */ + if (rd == 2) { + if (board[CENTER(from.r, to.r)][from.c]) + return 0; + } else { + if (board[from.r][CENTER(from.c, to.c)]) + return 0; + } + break; + case 6: /* 包 炮 */ + if (!(rd > 0 && cd == 0) && + !(rd == 0 && cd > 0)) + return 0; + i = between(board, from, to, rd == 0); + if ((i > 1) || + (i == 1 && !board[to.r][to.c]) || + (i == 0 && board[to.r][to.c])) + return 0; + break; + case 7: /* 卒 兵 */ + if (!(rd == 1 && cd == 0) && + !(rd == 0 && cd == 1)) + return 0; + if (((turn == (chc_my ^ 1) && to.r < 5) || + (turn == chc_my && to.r > 4)) && + cd != 0) + return 0; + if ((turn == (chc_my ^ 1) && to.r < from.r) || + (turn == chc_my && to.r > from.r)) + return 0; + break; + } + return 1; +} + +static void +findking(board_t board, int turn, rc_t * buf) +{ + int i, r, c; + + r = (turn == (chc_my ^ 1)) ? 0 : 7; + for (i = 0; i < 3; r++, i++) + for (c = 3; c < 6; c++) + if (CHE_P(board[r][c]) == 1 && + CHE_O(board[r][c]) == turn) { + buf->r = r, buf->c = c; + return; + } +} + +static int +chc_iskfk(board_t board) +{ + rc_t from, to; + + findking(board, 0, &to); + findking(board, 1, &from); + if (from.c == to.c && between(board, from, to, 0) == 0) + return 1; + return 0; +} + +static int +chc_ischeck(board_t board, int turn) +{ + rc_t from, to; + + findking(board, turn, &to); + for (from.r = 0; from.r < BRD_ROW; from.r++) + for (from.c = 0; from.c < BRD_COL; from.c++) + if (board[from.r][from.c] && + CHE_O(board[from.r][from.c]) != turn) + if (chc_canmove(board, from, to)) + return 1; + return 0; +} + +/* + * End of the rule function. + */ + +static void +chcusr_put(userec_t *userec, chcusr_t *user) +{ + userec->chc_win = user->win; + userec->chc_lose = user->lose; + userec->chc_tie = user->tie; +} + +static void +chcusr_get(userec_t *userec, chcusr_t *user) +{ + strlcpy(user->userid, userec->userid, sizeof(user->userid)); + user->win = userec->chc_win; + user->lose = userec->chc_lose; + user->tie = userec->chc_tie; +} + +static int +hisplay(int s, chcusr_t *user1, chcusr_t *user2, board_t board, board_t tmpbrd) +{ + int start_time; + int endgame = 0, endturn = 0; + + start_time = now; + while (!endturn) { + chc_lefttime = CHC_TIMEOUT - (now - start_time); + if (chc_lefttime < 0) { + chc_lefttime = 0; + + /* to make him break out igetkey() */ + chc_from.r = -2; + chc_broadcast_send(act_list, board); + } + chc_drawline(board, user1, user2, TIME_ROW); + move(1, 0); + oflush(); + switch (igetkey()) { + case 'q': + endgame = 2; + endturn = 1; + break; + case 'p': + if (chc_hepass) { + chc_from.r = -1; + chc_broadcast_send(act_list, board); + endgame = 3; + endturn = 1; + } + break; + case I_OTHERDATA: + if (!chc_broadcast_recv(act_list, board)) { /* disconnect */ + endturn = 1; + endgame = 1; + } else { + if (chc_from.r == -1) { + chc_hepass = 1; + strlcpy(chc_warnmsg, "\033[1;33m要求和局!\033[m", sizeof(chc_warnmsg)); + chc_drawline(board, user1, user2, WARN_ROW); + } else { + /* 座標變換 + * (CHC_WATCH_PERSONAL 設定時 + * 表觀棋者看的棋局為單人打譜的棋局) + * 棋盤需倒置的清況才要轉換 + */ + /* 1.如果在觀棋 且棋局是別人在打譜 且輪到你 或*/ + if ( ((chc_mode & CHC_WATCH) && (chc_mode & CHC_WATCH_PERSONAL)) || + /* 2.自己在打譜 */ + (chc_mode & CHC_PERSONAL) || + ((chc_mode & CHC_WATCH) && !chc_turn) + ) + ; // do nothing + else { + chc_from.r = 9 - chc_from.r, chc_from.c = 8 - chc_from.c; + chc_to.r = 9 - chc_to.r, chc_to.c = 8 - chc_to.c; + } + chc_cursor = chc_to; + if (CHE_P(board[chc_to.r][chc_to.c]) == 1) + endgame = 2; + endturn = 1; + chc_hepass = 0; + chc_drawline(board, user1, user2, STEP_ROW); + chc_log_step(board, &chc_from, &chc_to); + chc_movechess(board); + chc_drawline(board, user1, user2, LTR(chc_from.r)); + chc_drawline(board, user1, user2, LTR(chc_to.r)); + } + } + break; + } + } + return endgame; +} + +static int +myplay(int s, chcusr_t *user1, chcusr_t *user2, board_t board, board_t tmpbrd) +{ + int ch, start_time; + int endgame = 0, endturn = 0; + + chc_ipass = 0, chc_selected = 0; + start_time = now; + chc_lefttime = CHC_TIMEOUT - (now - start_time); + bell(); + while (!endturn) { + chc_drawline(board, user1, user2, TIME_ROW); + chc_movecur(chc_cursor.r, chc_cursor.c); + oflush(); + ch = igetkey(); + chc_lefttime = CHC_TIMEOUT - (now - start_time); + if (chc_lefttime < 0) + ch = 'q'; + switch (ch) { + case I_OTHERDATA: + if (!chc_broadcast_recv(act_list, board)) { /* disconnect */ + endgame = 1; + endturn = 1; + } else if (chc_from.r == -1 && chc_ipass) { + endgame = 3; + endturn = 1; + } + break; + case KEY_UP: + chc_cursor.r--; + if (chc_cursor.r < 0) + chc_cursor.r = BRD_ROW - 1; + break; + case KEY_DOWN: + chc_cursor.r++; + if (chc_cursor.r >= BRD_ROW) + chc_cursor.r = 0; + break; + case KEY_LEFT: + chc_cursor.c--; + if (chc_cursor.c < 0) + chc_cursor.c = BRD_COL - 1; + break; + case KEY_RIGHT: + chc_cursor.c++; + if (chc_cursor.c >= BRD_COL) + chc_cursor.c = 0; + break; + case 'q': + endgame = 2; + endturn = 1; + break; + case 'p': + chc_ipass = 1; + chc_from.r = -1; + chc_broadcast_send(act_list, board); + strlcpy(chc_warnmsg, "\033[1;33m要求和棋!\033[m", sizeof(chc_warnmsg)); + chc_drawline(board, user1, user2, WARN_ROW); + bell(); + break; + case '\r': + case '\n': + case ' ': + if (chc_selected) { + if (chc_cursor.r == chc_select.r && + chc_cursor.c == chc_select.c) { + chc_selected = 0; + chc_drawline(board, user1, user2, LTR(chc_cursor.r)); + } else if (chc_canmove(board, chc_select, chc_cursor)) { + if (CHE_P(board[chc_cursor.r][chc_cursor.c]) == 1) + endgame = 1; + chc_from = chc_select; + chc_to = chc_cursor; + if (!endgame) { + memcpy(tmpbrd, board, sizeof(board_t)); + chc_movechess(tmpbrd); + } + if (endgame || !chc_iskfk(tmpbrd)) { + chc_drawline(board, user1, user2, STEP_ROW); + chc_log_step(board, &chc_from, &chc_to); + chc_movechess(board); + chc_broadcast_send(act_list, board); + chc_selected = 0; + chc_drawline(board, user1, user2, LTR(chc_from.r)); + chc_drawline(board, user1, user2, LTR(chc_to.r)); + endturn = 1; + } else { + strlcpy(chc_warnmsg, "\033[1;33m不可以王見王\033[m", sizeof(chc_warnmsg)); + bell(); + chc_drawline(board, user1, user2, WARN_ROW); + } + } + } else if (board[chc_cursor.r][chc_cursor.c] && + CHE_O(board[chc_cursor.r][chc_cursor.c]) == chc_turn) { + chc_selected = 1; + chc_select = chc_cursor; + chc_drawline(board, user1, user2, LTR(chc_cursor.r)); + } + break; + } + } + return endgame; +} + +static void +mainloop(int s, chcusr_t *user1, chcusr_t *user2, board_t board, play_func_t play_func[2]) +{ + int endgame; + char buf[80]; + board_t tmpbrd; + + if (!(chc_mode & CHC_WATCH)) + chc_turn = 1; + for (endgame = 0; !endgame; chc_turn ^= 1) { + chc_firststep = 0; + chc_drawline(board, user1, user2, TURN_ROW); + if (chc_ischeck(board, chc_turn)) { + strlcpy(chc_warnmsg, "\033[1;31m將軍!\033[m", sizeof(chc_warnmsg)); + bell(); + } else + chc_warnmsg[0] = 0; + chc_drawline(board, user1, user2, WARN_ROW); + endgame = play_func[chc_turn] (s, user1, user2, board, tmpbrd); + } + + if (chc_mode & CHC_VERSUS) { + if (endgame == 1) { + strlcpy(chc_warnmsg, "對方認輸了!", sizeof(chc_warnmsg)); + user1->win++; + currutmp->chc_win++; + } else if (endgame == 2) { + strlcpy(chc_warnmsg, "你認輸了!", sizeof(chc_warnmsg)); + user1->lose++; + currutmp->chc_lose++; + } else { + strlcpy(chc_warnmsg, "和棋", sizeof(chc_warnmsg)); + user1->tie++; + currutmp->chc_tie++; + } + user1->lose--; + chcusr_put(&cuser, user1); + passwd_update(usernum, &cuser); + } + else if (chc_mode & CHC_WATCH) { + strlcpy(chc_warnmsg, "結束觀棋", sizeof(chc_warnmsg)); + } + else { + strlcpy(chc_warnmsg, "結束打譜", sizeof(chc_warnmsg)); + } + + chc_log("=> "); + if (endgame == 3) + chc_log("和局"); + else{ + sprintf(buf, "%s勝\n", chc_my && endgame == 1 ? "紅" : "黑"); + chc_log(buf); + } + + chc_drawline(board, user1, user2, WARN_ROW); + bell(); + oflush(); +} + +static void +chc_init_play_func(chcusr_t *user1, chcusr_t *user2, play_func_t play_func[2]) +{ + char userid[2][IDLEN + 1]; + + if (chc_mode & CHC_PERSONAL) { + strlcpy(userid[0], cuser.userid, sizeof(userid[0])); + strlcpy(userid[1], cuser.userid, sizeof(userid[1])); + play_func[0] = play_func[1] = myplay; + } + else if (chc_mode & CHC_WATCH) { + userinfo_t *uinfo = search_ulist_userid(currutmp->mateid); + strlcpy(userid[0], uinfo->userid, sizeof(userid[0])); + strlcpy(userid[1], uinfo->mateid, sizeof(userid[1])); + play_func[0] = play_func[1] = hisplay; + } + else { + strlcpy(userid[0], cuser.userid, sizeof(userid[0])); + strlcpy(userid[1], currutmp->mateid, sizeof(userid[1])); + play_func[chc_my] = myplay; + play_func[chc_my ^ 1] = hisplay; + } + + getuser(userid[0]); + chcusr_get(&xuser, user1); + getuser(userid[1]); + chcusr_get(&xuser, user2); +} + +static void +chc_watch_request(int signo) +{ + if (!(currstat & CHC)) + return; + chc_act_list *tmp; + for(tmp = act_list; tmp->next != NULL; tmp = tmp->next); + tmp->next = (chc_act_list *)malloc(sizeof(chc_act_list)); + tmp = tmp->next; + tmp->sock = reply_connection_request(uip); + if (tmp->sock < 0) + return; + tmp->next = NULL; + write(tmp->sock, chc_bp, sizeof(board_t)); + write(tmp->sock, &chc_my, sizeof(chc_my)); + write(tmp->sock, &chc_turn, sizeof(chc_turn)); + write(tmp->sock, &currutmp->turn, sizeof(currutmp->turn)); + write(tmp->sock, &chc_firststep, sizeof(chc_firststep)); + write(tmp->sock, &chc_mode, sizeof(chc_mode)); +} + +static void +chc_init(int s, chcusr_t *user1, chcusr_t *user2, board_t board, play_func_t play_func[2]) +{ + userinfo_t *my = currutmp; + + setutmpmode(CHC); + clear(); + chc_warnmsg[0] = 0; + + /* 從不同來源初始化各個變數 */ + if (!(chc_mode & CHC_WATCH)) { + if (chc_mode & CHC_PERSONAL) + chc_my = 1; + else + chc_my = my->turn; + chc_firststep = 1; + chc_init_board(board); + chc_cursor.r = 9, chc_cursor.c = 0; + } + else { + char mode; + read(s, board, sizeof(board_t)); + read(s, &chc_my, sizeof(chc_my)); + read(s, &chc_turn, sizeof(chc_turn)); + read(s, &my->turn, sizeof(my->turn)); + read(s, &chc_firststep, sizeof(chc_firststep)); + read(s, &mode, sizeof(mode)); + if (mode & CHC_PERSONAL) + chc_mode |= CHC_WATCH_PERSONAL; + } + + act_list = (chc_act_list *)malloc(sizeof(*act_list)); + act_list->sock = s; + act_list->next = 0; + + chc_init_play_func(user1, user2, play_func); + + chc_redraw(user1, user2, board); + add_io(s, 0); + + signal(SIGUSR1, chc_watch_request); + + if (my->turn && !(chc_mode & CHC_WATCH)) + chc_broadcast_recv(act_list, board); + + user1->lose++; + + if (chc_mode & CHC_VERSUS) { + passwd_query(usernum, &xuser); + chcusr_put(&xuser, user1); + passwd_update(usernum, &xuser); + } + + if (!my->turn) { + if (!(chc_mode & CHC_WATCH)) + chc_broadcast_send(act_list, board); + user2->lose++; + } + chc_redraw(user1, user2, board); +} + +void +chc(int s, int mode) +{ + chcusr_t user1, user2; + play_func_t play_func[2]; + board_t board; + char mode0 = currutmp->mode; + char file[80]; + + signal(SIGUSR1, SIG_IGN); + + chc_mode = mode; + chc_bp = &board; + + chc_init(s, &user1, &user2, board, play_func); + + setuserfile(file, CHC_LOG); + if (chc_log_open(&user1, &user2, file) < 0) + vmsg("無法紀錄棋局"); + + mainloop(s, &user1, &user2, board, play_func); + + /* close these fd */ + if (chc_mode & CHC_PERSONAL) + act_list = act_list->next; + while(act_list){ + close(act_list->sock); + act_list = act_list->next; + } + + add_io(0, 0); + if (chc_my) + pressanykey(); + + currutmp->mode = mode0; + + if (getans("是否將棋譜寄回信箱?[N/y]") == 'y') { + char title[80]; + sprintf(title, "%s V.S. %s", user1.userid, user2.userid); + chc_log("\n--\n\n"); + chc_log_poem(); + chc_log_close(); + mail_id(cuser.userid, title, file, "[楚河漢界]"); + } + else + chc_log_close(); + signal(SIGUSR1, talk_request); +} + +static userinfo_t * +chc_init_utmp(void) +{ + char uident[16]; + userinfo_t *uin; + + stand_title("楚河漢界之爭"); + generalnamecomplete(msg_uid, uident, sizeof(uident), + SHM->UTMPnumber, + completeutmp_compar, + completeutmp_permission, + completeutmp_getname); + if (uident[0] == '\0') + return NULL; + + if ((uin = search_ulist_userid(uident)) == NULL) + return NULL; + + uin->sig = SIG_CHC; + return uin; +} + +int +chc_main(void) +{ + userinfo_t *uin; + + if ((uin = chc_init_utmp()) == NULL) + return -1; + uin->turn = 1; + currutmp->turn = 0; + strlcpy(uin->mateid, currutmp->userid, sizeof(uin->mateid)); + strlcpy(currutmp->mateid, uin->userid, sizeof(currutmp->mateid)); + + my_talk(uin, friend_stat(currutmp, uin), 'c'); + return 0; +} + +int +chc_personal(void) +{ + chc(0, CHC_PERSONAL); + return 0; +} + +int +chc_watch(void) +{ + int sock, msgsock; + userinfo_t *uin; + + if ((uin = chc_init_utmp()) == NULL) + return -1; + + if (uin->uid == currutmp->uid || uin->mode != CHC) + return -1; + + if ((sock = make_connection_to_somebody(uin, 10)) < 0) { + vmsg("無法建立連線"); + return -1; + } + msgsock = accept(sock, (struct sockaddr *) 0, (socklen_t *) 0); + close(sock); + if (msgsock < 0) + return -1; + + strlcpy(currutmp->mateid, uin->userid, sizeof(currutmp->mateid)); + chc(msgsock, CHC_WATCH); + close(msgsock); + return 0; +} -- cgit v1.2.3 From 159c1882508313f9a740b29a82dbbf0a3df9dc5d Mon Sep 17 00:00:00 2001 From: victor <victor@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Tue, 9 Sep 2003 06:10:51 +0000 Subject: merge from my branch merge chc_*.c to chc.c merge gomo1.c into gomo.c add new feature to chc git-svn-id: http://opensvn.csie.org/pttbbs/trunk@1171 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/include/bbs.h | 1 + pttbbs/include/modes.h | 5 - pttbbs/include/proto.h | 8 +- pttbbs/include/pttstruct.h | 9 -- pttbbs/mbbsd/Makefile | 6 +- pttbbs/mbbsd/chc_draw.c | 183 ----------------------- pttbbs/mbbsd/chc_net.c | 25 ---- pttbbs/mbbsd/chc_play.c | 312 ---------------------------------------- pttbbs/mbbsd/chc_rule.c | 195 ------------------------- pttbbs/mbbsd/gomo.c | 135 +++++++++++++++++ pttbbs/mbbsd/gomo1.c | 138 ------------------ pttbbs/mbbsd/mbbsd.c | 2 +- pttbbs/mbbsd/name.c | 2 +- pttbbs/mbbsd/othello.c | 2 +- pttbbs/mbbsd/talk.c | 14 +- pttbbs/sample/etc/chess/1.poem | 10 ++ pttbbs/sample/etc/chess/10.poem | 10 ++ pttbbs/sample/etc/chess/11.poem | 6 + pttbbs/sample/etc/chess/12.poem | 6 + pttbbs/sample/etc/chess/13.poem | 6 + pttbbs/sample/etc/chess/14.poem | 10 ++ pttbbs/sample/etc/chess/15.poem | 2 + pttbbs/sample/etc/chess/16.poem | 2 + pttbbs/sample/etc/chess/2.poem | 10 ++ pttbbs/sample/etc/chess/3.poem | 6 + pttbbs/sample/etc/chess/4.poem | 10 ++ pttbbs/sample/etc/chess/5.poem | 8 ++ pttbbs/sample/etc/chess/6.poem | 6 + pttbbs/sample/etc/chess/7.poem | 10 ++ pttbbs/sample/etc/chess/8.poem | 10 ++ pttbbs/sample/etc/chess/9.poem | 6 + 31 files changed, 272 insertions(+), 883 deletions(-) delete mode 100644 pttbbs/mbbsd/chc_draw.c delete mode 100644 pttbbs/mbbsd/chc_net.c delete mode 100644 pttbbs/mbbsd/chc_play.c delete mode 100644 pttbbs/mbbsd/chc_rule.c delete mode 100644 pttbbs/mbbsd/gomo1.c create mode 100644 pttbbs/sample/etc/chess/1.poem create mode 100644 pttbbs/sample/etc/chess/10.poem create mode 100644 pttbbs/sample/etc/chess/11.poem create mode 100644 pttbbs/sample/etc/chess/12.poem create mode 100644 pttbbs/sample/etc/chess/13.poem create mode 100644 pttbbs/sample/etc/chess/14.poem create mode 100644 pttbbs/sample/etc/chess/15.poem create mode 100644 pttbbs/sample/etc/chess/16.poem create mode 100644 pttbbs/sample/etc/chess/2.poem create mode 100644 pttbbs/sample/etc/chess/3.poem create mode 100644 pttbbs/sample/etc/chess/4.poem create mode 100644 pttbbs/sample/etc/chess/5.poem create mode 100644 pttbbs/sample/etc/chess/6.poem create mode 100644 pttbbs/sample/etc/chess/7.poem create mode 100644 pttbbs/sample/etc/chess/8.poem create mode 100644 pttbbs/sample/etc/chess/9.poem diff --git a/pttbbs/include/bbs.h b/pttbbs/include/bbs.h index 71a3332f..666d30c7 100644 --- a/pttbbs/include/bbs.h +++ b/pttbbs/include/bbs.h @@ -60,6 +60,7 @@ #include "common.h" #include "perm.h" #include "modes.h" +#include "chc.h" #include "proto.h" #include "gomo.h" diff --git a/pttbbs/include/modes.h b/pttbbs/include/modes.h index a70e7047..8321fc8b 100644 --- a/pttbbs/include/modes.h +++ b/pttbbs/include/modes.h @@ -97,11 +97,6 @@ #define REEDIT 79 #define BLOGGING 80 -/* 象棋 */ -#define CHC_VERSUS 0 /* 雙人 */ -#define CHC_WATCH 1 /* 觀棋 */ -#define CHC_PERSONAL 2 /* 打譜 */ - /* menu.c 中的模式 */ #define QUIT 0x666 /* Return value to abort recursive functions */ #define XEASY 0x333 /* Return value to un-redraw screen */ diff --git a/pttbbs/include/proto.h b/pttbbs/include/proto.h index 5c287dd1..d1e51a48 100644 --- a/pttbbs/include/proto.h +++ b/pttbbs/include/proto.h @@ -218,10 +218,6 @@ int ticket(int bid); /* gomo */ int gomoku(int fd); -/* gomo1 */ -int getstyle(int x, int y, int color, int limit); -int chkwin(int style, int limit); - /* guess */ int guess_main(); @@ -292,6 +288,9 @@ void add_distinct(char *fname, char *line); void show_last_call_in(int save); int dosearchuser(char *userid); void u_exit(char *mode); +void talk_request(int sig); +int reply_connection_request(userinfo_t *uip); +void my_talk(userinfo_t * uin, int fri_stat, char defact); /* menu */ void showtitle(char *title, char *mid); @@ -492,6 +491,7 @@ int login_friend_online(); int isvisible_uid(int tuid); int friend_stat(userinfo_t *me, userinfo_t * ui); int call_in(userinfo_t *uentp, int fri_stat); +int make_connection_to_somebody(userinfo_t *uin, int timeout); /* tmpjack */ int reg_barbq(); diff --git a/pttbbs/include/pttstruct.h b/pttbbs/include/pttstruct.h index 1cb59f85..991b2154 100644 --- a/pttbbs/include/pttstruct.h +++ b/pttbbs/include/pttstruct.h @@ -424,13 +424,4 @@ typedef struct time_t chrono; int recno; } TagItem; - -/* 象棋 */ -typedef struct chcusr_t{ - char userid[IDLEN + 1]; - int uid; - int win; - int lose; - int tie; -} chcusr_t; #endif diff --git a/pttbbs/mbbsd/Makefile b/pttbbs/mbbsd/Makefile index 5762a2d7..e6a9adbd 100644 --- a/pttbbs/mbbsd/Makefile +++ b/pttbbs/mbbsd/Makefile @@ -1,4 +1,4 @@ -# $Id: Makefile,v 1.29 2003/07/20 00:55:34 in2 Exp $ +# $Id$ .include "../pttbbs.mk" @@ -9,8 +9,8 @@ LDFLAGS+= -L/usr/local/lib/mysql -lmysqlclient PROG= mbbsd OBJS= admin.o announce.o args.o bbs.o board.o cache.o cal.o card.o\ - chat.o chc_draw.o chc_net.o chc_play.o chc_rule.o chicken.o dark.o\ - edit.o friend.o gamble.o gomo.o gomo1.o guess.o indict.o io.o\ + chat.o chc.o chicken.o dark.o\ + edit.o friend.o gamble.o gomo.o guess.o indict.o io.o\ kaede.o lovepaper.o mail.o mbbsd.o menu.o more.o name.o osdep.o\ othello.o page.o read.o record.o register.o screen.o stuff.o\ talk.o term.o topsong.o user.o vice.o vote.o xyz.o\ diff --git a/pttbbs/mbbsd/chc_draw.c b/pttbbs/mbbsd/chc_draw.c deleted file mode 100644 index 2cca2f19..00000000 --- a/pttbbs/mbbsd/chc_draw.c +++ /dev/null @@ -1,183 +0,0 @@ -/* $Id$ */ -#include "bbs.h" - -#define SIDE_ROW 10 -#define TURN_ROW 11 -#define STEP_ROW 12 -#define TIME_ROW 13 -#define WARN_ROW 15 -#define MYWIN_ROW 17 -#define HISWIN_ROW 18 - -static char *turn_str[2] = {"黑的", "紅的"}; - -static char *num_str[10] = { - "", "一", "二", "三", "四", "五", "六", "七", "八", "九" -}; - -static char *chess_str[2][8] = { - /* 0 1 2 3 4 5 6 7 */ - {" ", "將", "士", "象", "車", "馬", "包", "卒"}, - {" ", "帥", "仕", "相", "車", "傌", "炮", "兵"} -}; - -static char *chess_brd[BRD_ROW * 2 - 1] = { - /* 0 1 2 3 4 5 6 7 8 */ - "┌─┬─┬─┬─┬─┬─┬─┬─┐", /* 0 */ - "│ │ │ │\│/│ │ │ │", - "├─┼─┼─┼─┼─┼─┼─┼─┤", /* 1 */ - "│ │ │ │/│\│ │ │ │", - "├─┼─┼─┼─┼─┼─┼─┼─┤", /* 2 */ - "│ │ │ │ │ │ │ │ │", - "├─┼─┼─┼─┼─┼─┼─┼─┤", /* 3 */ - "│ │ │ │ │ │ │ │ │", - "├─┴─┴─┴─┴─┴─┴─┴─┤", /* 4 */ - "│ 楚 河 漢 界 │", - "├─┬─┬─┬─┬─┬─┬─┬─┤", /* 5 */ - "│ │ │ │ │ │ │ │ │", - "├─┼─┼─┼─┼─┼─┼─┼─┤", /* 6 */ - "│ │ │ │ │ │ │ │ │", - "├─┼─┼─┼─┼─┼─┼─┼─┤", /* 7 */ - "│ │ │ │\│/│ │ │ │", - "├─┼─┼─┼─┼─┼─┼─┼─┤", /* 8 */ - "│ │ │ │/│\│ │ │ │", - "└─┴─┴─┴─┴─┴─┴─┴─┘" /* 9 */ -}; - -static char *hint_str[] = { - " q 認輸離開", - " p 要求和棋", - "方向鍵 移動遊標", - "Enter 選擇/移動" -}; - -void -chc_movecur(int r, int c) -{ - move(r * 2 + 3, c * 4 + 4); -} - -#define BLACK_COLOR "\033[1;36m" -#define RED_COLOR "\033[1;31m" -#define BLACK_REVERSE "\033[1;37;46m" -#define RED_REVERSE "\033[1;37;41m" -#define TURN_COLOR "\033[1;33m" - -static void -showstep(board_t board) -{ - int turn, fc, tc, eatten; - char *dir; - - turn = CHE_O(board[chc_from.r][chc_from.c]); - fc = (turn == (chc_my ^ 1) ? chc_from.c + 1 : 9 - chc_from.c); - tc = (turn == (chc_my ^ 1) ? chc_to.c + 1 : 9 - chc_to.c); - if (chc_from.r == chc_to.r) - dir = "平"; - else { - if (chc_from.c == chc_to.c) - tc = chc_from.r - chc_to.r; - if (tc < 0) - tc = -tc; - - if ((turn == (chc_my ^ 1) && chc_to.r > chc_from.r) || - (turn == chc_my && chc_to.r < chc_from.r)) - dir = "進"; - else - dir = "退"; - } - prints("%s%s%s%s%s", - turn == 0 ? BLACK_COLOR : RED_COLOR, - chess_str[turn][CHE_P(board[chc_from.r][chc_from.c])], - num_str[fc], dir, num_str[tc]); - eatten = board[chc_to.r][chc_to.c]; - if (eatten) - prints(": %s%s", - CHE_O(eatten) == 0 ? BLACK_COLOR : RED_COLOR, - chess_str[CHE_O(eatten)][CHE_P(eatten)]); - prints("\033[m"); -} - -void -chc_drawline(board_t board, chcusr_t *user1, chcusr_t *user2, int line) -{ - int i, j; - - move(line, 0); - clrtoeol(); - if (line == 0) { - prints("\033[1;46m 象棋對戰 \033[45m%30s VS %-30s\033[m", - user1->userid, user2->userid); - } else if (line >= 3 && line <= 21) { - outs(" "); - for (i = 0; i < 9; i++) { - j = board[RTL(line)][i]; - if ((line & 1) == 1 && j) { - if (chc_selected && - chc_select.r == RTL(line) && chc_select.c == i) - prints("%s%s\033[m", - CHE_O(j) == 0 ? BLACK_REVERSE : RED_REVERSE, - chess_str[CHE_O(j)][CHE_P(j)]); - else - prints("%s%s\033[m", - CHE_O(j) == 0 ? BLACK_COLOR : RED_COLOR, - chess_str[CHE_O(j)][CHE_P(j)]); - } else - prints("%c%c", chess_brd[line - 3][i * 4], - chess_brd[line - 3][i * 4 + 1]); - if (i != 8) - prints("%c%c", chess_brd[line - 3][i * 4 + 2], - chess_brd[line - 3][i * 4 + 3]); - } - outs(" "); - - if (line >= 3 && line < 3 + (int)dim(hint_str)) { - outs(hint_str[line - 3]); - } else if (line == SIDE_ROW) { - prints("\033[1m你是%s%s\033[m", - chc_my == 0 ? BLACK_COLOR : RED_COLOR, - turn_str[chc_my]); - } else if (line == TURN_ROW) { - prints("%s%s\033[m", - TURN_COLOR, - chc_my == chc_turn ? "輪到你下棋了" : "等待對方下棋"); - } else if (line == STEP_ROW && !chc_firststep) { - showstep(board); - } else if (line == TIME_ROW) { - prints("剩餘時間 %d:%02d", chc_lefttime / 60, chc_lefttime % 60); - } else if (line == WARN_ROW) { - outs(chc_warnmsg); - } else if (line == MYWIN_ROW) { - prints("\033[1;33m%12.12s " - "\033[1;31m%2d\033[37m勝 " - "\033[34m%2d\033[37m敗 " - "\033[36m%2d\033[37m和\033[m", - user1->userid, - user1->win, user1->lose - 1, user1->tie); - } else if (line == HISWIN_ROW) { - prints("\033[1;33m%12.12s " - "\033[1;31m%2d\033[37m勝 " - "\033[34m%2d\033[37m敗 " - "\033[36m%2d\033[37m和\033[m", - user2->userid, - user2->win, user2->lose - 1, user2->tie); - } - } else if (line == 2 || line == 22) { - outs(" "); - if (line == 2) - for (i = 1; i <= 9; i++) - prints("%s ", num_str[i]); - else - for (i = 9; i >= 1; i--) - prints("%s ", num_str[i]); - } -} - -void -chc_redraw(chcusr_t *user1, chcusr_t *user2, board_t board) -{ - int i; - - for (i = 0; i <= 22; i++) - chc_drawline(board, user1, user2, i); -} diff --git a/pttbbs/mbbsd/chc_net.c b/pttbbs/mbbsd/chc_net.c deleted file mode 100644 index 5a8c5169..00000000 --- a/pttbbs/mbbsd/chc_net.c +++ /dev/null @@ -1,25 +0,0 @@ -/* $Id: chc_net.c,v 1.4 2002/07/21 09:26:02 in2 Exp $ */ -#include "bbs.h" -typedef struct drc_t { - rc_t from, to; -} drc_t; - -int -chc_recvmove(int s) -{ - drc_t buf; - - if (read(s, &buf, sizeof(buf)) != sizeof(buf)) - return 1; - chc_from = buf.from, chc_to = buf.to; - return 0; -} - -void -chc_sendmove(int s) -{ - drc_t buf; - - buf.from = chc_from, buf.to = chc_to; - write(s, &buf, sizeof(buf)); -} diff --git a/pttbbs/mbbsd/chc_play.c b/pttbbs/mbbsd/chc_play.c deleted file mode 100644 index 36992ae8..00000000 --- a/pttbbs/mbbsd/chc_play.c +++ /dev/null @@ -1,312 +0,0 @@ -/* $Id$ */ -#include "bbs.h" -typedef int (*play_func_t) (int, chcusr_t *, chcusr_t *, board_t, board_t); - -static int chc_ipass = 0, chc_hepass = 0; - -#define CHC_TIMEOUT 300 -#define SIDE_ROW 10 -#define TURN_ROW 11 -#define STEP_ROW 12 -#define TIME_ROW 13 -#define WARN_ROW 15 -#define MYWIN_ROW 17 -#define HISWIN_ROW 18 - -static void -chcusr_put(userec_t *userec, chcusr_t *user) -{ - userec->chc_win = user->win; - userec->chc_lose = user->lose; - userec->chc_tie = user->tie; -} - -static void -chcusr_get(userec_t *userec, chcusr_t *user) -{ - strlcpy(user->userid, userec->userid, sizeof(user->userid)); - user->win = userec->chc_win; - user->lose = userec->chc_lose; - user->tie = userec->chc_tie; -} - -static int -hisplay(int s, chcusr_t *user1, chcusr_t *user2, board_t board, board_t tmpbrd) -{ - int start_time; - int endgame = 0, endturn = 0; - - start_time = now; - while (!endturn) { - chc_lefttime = CHC_TIMEOUT - (now - start_time); - if (chc_lefttime < 0) { - chc_lefttime = 0; - - /* to make him break out igetkey() */ - chc_from.r = -2; - chc_sendmove(s); - } - chc_drawline(board, user1, user2, TIME_ROW); - move(1, 0); - oflush(); - switch (igetkey()) { - case 'q': - endgame = 2; - endturn = 1; - break; - case 'p': - if (chc_hepass) { - chc_from.r = -1; - chc_sendmove(s); - endgame = 3; - endturn = 1; - } - break; - case I_OTHERDATA: - if (chc_recvmove(s)) { /* disconnect */ - endturn = 1; - endgame = 1; - } else { - if (chc_from.r == -1) { - chc_hepass = 1; - strlcpy(chc_warnmsg, "\033[1;33m要求和局!\033[m", sizeof(chc_warnmsg)); - chc_drawline(board, user1, user2, WARN_ROW); - } else { - chc_from.r = 9 - chc_from.r, chc_from.c = 8 - chc_from.c; - chc_to.r = 9 - chc_to.r, chc_to.c = 8 - chc_to.c; - chc_cursor = chc_to; - if (CHE_P(board[chc_to.r][chc_to.c]) == 1) - endgame = 2; - endturn = 1; - chc_hepass = 0; - chc_drawline(board, user1, user2, STEP_ROW); - chc_movechess(board); - chc_drawline(board, user1, user2, LTR(chc_from.r)); - chc_drawline(board, user1, user2, LTR(chc_to.r)); - } - } - break; - } - } - return endgame; -} - -static int -myplay(int s, chcusr_t *user1, chcusr_t *user2, board_t board, board_t tmpbrd) -{ - int ch, start_time; - int endgame = 0, endturn = 0; - - chc_ipass = 0, chc_selected = 0; - start_time = now; - chc_lefttime = CHC_TIMEOUT - (now - start_time); - bell(); - while (!endturn) { - chc_drawline(board, user1, user2, TIME_ROW); - chc_movecur(chc_cursor.r, chc_cursor.c); - oflush(); - ch = igetkey(); - chc_lefttime = CHC_TIMEOUT - (now - start_time); - if (chc_lefttime < 0) - ch = 'q'; - switch (ch) { - case I_OTHERDATA: - if (chc_recvmove(s)) { /* disconnect */ - endgame = 1; - endturn = 1; - } else if (chc_from.r == -1 && chc_ipass) { - endgame = 3; - endturn = 1; - } - break; - case KEY_UP: - chc_cursor.r--; - if (chc_cursor.r < 0) - chc_cursor.r = BRD_ROW - 1; - break; - case KEY_DOWN: - chc_cursor.r++; - if (chc_cursor.r >= BRD_ROW) - chc_cursor.r = 0; - break; - case KEY_LEFT: - chc_cursor.c--; - if (chc_cursor.c < 0) - chc_cursor.c = BRD_COL - 1; - break; - case KEY_RIGHT: - chc_cursor.c++; - if (chc_cursor.c >= BRD_COL) - chc_cursor.c = 0; - break; - case 'q': - endgame = 2; - endturn = 1; - break; - case 'p': - chc_ipass = 1; - chc_from.r = -1; - chc_sendmove(s); - strlcpy(chc_warnmsg, "\033[1;33m要求和棋!\033[m", sizeof(chc_warnmsg)); - chc_drawline(board, user1, user2, WARN_ROW); - bell(); - break; - case '\r': - case '\n': - case ' ': - if (chc_selected) { - if (chc_cursor.r == chc_select.r && - chc_cursor.c == chc_select.c) { - chc_selected = 0; - chc_drawline(board, user1, user2, LTR(chc_cursor.r)); - } else if (chc_canmove(board, chc_select, chc_cursor)) { - if (CHE_P(board[chc_cursor.r][chc_cursor.c]) == 1) - endgame = 1; - chc_from = chc_select; - chc_to = chc_cursor; - if (!endgame) { - memcpy(tmpbrd, board, sizeof(board_t)); - chc_movechess(tmpbrd); - } - if (endgame || !chc_iskfk(tmpbrd)) { - chc_drawline(board, user1, user2, STEP_ROW); - chc_movechess(board); - chc_sendmove(s); - chc_selected = 0; - chc_drawline(board, user1, user2, LTR(chc_from.r)); - chc_drawline(board, user1, user2, LTR(chc_to.r)); - endturn = 1; - } else { - strlcpy(chc_warnmsg, "\033[1;33m不可以王見王\033[m", sizeof(chc_warnmsg)); - bell(); - chc_drawline(board, user1, user2, WARN_ROW); - } - } - } else if (board[chc_cursor.r][chc_cursor.c] && - CHE_O(board[chc_cursor.r][chc_cursor.c]) == chc_turn) { - chc_selected = 1; - chc_select = chc_cursor; - chc_drawline(board, user1, user2, LTR(chc_cursor.r)); - } - break; - } - } - return endgame; -} - -static void -mainloop(int s, chcusr_t *user1, chcusr_t *user2, board_t board, play_func_t play_func[2]) -{ - int endgame; - board_t tmpbrd; - - play_func[chc_my] = myplay; - if(s != 0) - play_func[chc_my ^ 1] = hisplay; - else /* 跟自己下棋 */ - play_func[chc_my ^ 1] = myplay; - - for (chc_turn = 1, endgame = 0; !endgame; chc_turn ^= 1) { - chc_firststep = 0; - chc_drawline(board, user1, user2, TURN_ROW); - if (chc_ischeck(board, chc_turn)) { - strlcpy(chc_warnmsg, "\033[1;31m將軍!\033[m", sizeof(chc_warnmsg)); - bell(); - } else - chc_warnmsg[0] = 0; - chc_drawline(board, user1, user2, WARN_ROW); - endgame = play_func[chc_turn] (s, user1, user2, board, tmpbrd); - } - - if (s != 0) { - if (endgame == 1) { - strlcpy(chc_warnmsg, "對方認輸了!", sizeof(chc_warnmsg)); - user1->win++; - currutmp->chc_win++; - } else if (endgame == 2) { - strlcpy(chc_warnmsg, "你認輸了!", sizeof(chc_warnmsg)); - user1->lose++; - currutmp->chc_lose++; - } else { - strlcpy(chc_warnmsg, "和棋", sizeof(chc_warnmsg)); - user1->tie++; - currutmp->chc_tie++; - } - } - else { - strlcpy(chc_warnmsg, "結束打譜", sizeof(chc_warnmsg)); - } - user1->lose--; - - // if not watching - chcusr_put(&cuser, user1); - passwd_update(usernum, &cuser); - chc_drawline(board, user1, user2, WARN_ROW); - bell(); - oflush(); -} - -static void -chc_init(int s, chcusr_t *user1, chcusr_t *user2, board_t board) -{ - userinfo_t *my = currutmp; - - setutmpmode(CHC); - clear(); - chc_warnmsg[0] = 0; - if(s != 0){ // XXX mateid -> user2 - chc_my = my->turn; - chc_mateid = my->mateid; - } - else{ - chc_my = 1; - chc_mateid = cuser.userid; - } - chc_firststep = 1; - chc_init_board(board); - chc_redraw(user1, user2, board); - chc_cursor.r = 9, chc_cursor.c = 0; - add_io(s, 0); - - if (my->turn) - chc_recvmove(s); - - user1->lose++; - // if not watching - passwd_query(usernum, &xuser); - chcusr_put(&xuser, user1); - passwd_update(usernum, &xuser); - - if (!my->turn) { - chc_sendmove(s); - user2->lose++; - } - chc_redraw(user1, user2, board); -} - -static void -chc_userinit(char *userid1, char *userid2, chcusr_t *user1, chcusr_t *user2, play_func_t play_func[2]) -{ - getuser(userid1); - chcusr_get(&xuser, user1); - - getuser(userid2); - chcusr_get(&xuser, user2); -} - -void -chc(int s, int type) -{ - board_t board; - chcusr_t user1, user2; - play_func_t play_func[2]; - - chc_userinit(cuser.userid, currutmp->mateid, &user1, &user2, play_func); - chc_init(s, &user1, &user2, board); - mainloop(s, &user1, &user2, board, play_func); - if (type == CHC_VERSUS) - close(s); - add_io(0, 0); - if (chc_my) - pressanykey(); -} diff --git a/pttbbs/mbbsd/chc_rule.c b/pttbbs/mbbsd/chc_rule.c deleted file mode 100644 index df7964a1..00000000 --- a/pttbbs/mbbsd/chc_rule.c +++ /dev/null @@ -1,195 +0,0 @@ -/* $Id: chc_rule.c,v 1.4 2002/07/21 09:26:02 in2 Exp $ */ -#include "bbs.h" - -#define CENTER(a, b) (((a) + (b)) >> 1) - -void -chc_init_board(board_t board) -{ - memset(board, 0, sizeof(board_t)); - board[0][4] = CHE(1, chc_my ^ 1); /* 將 */ - board[0][3] = board[0][5] = CHE(2, chc_my ^ 1); /* 士 */ - board[0][2] = board[0][6] = CHE(3, chc_my ^ 1); /* 象 */ - board[0][0] = board[0][8] = CHE(4, chc_my ^ 1); /* 車 */ - board[0][1] = board[0][7] = CHE(5, chc_my ^ 1); /* 馬 */ - board[2][1] = board[2][7] = CHE(6, chc_my ^ 1); /* 包 */ - board[3][0] = board[3][2] = board[3][4] = - board[3][6] = board[3][8] = CHE(7, chc_my ^ 1); /* 卒 */ - - board[9][4] = CHE(1, chc_my); /* 帥 */ - board[9][3] = board[9][5] = CHE(2, chc_my); /* 仕 */ - board[9][2] = board[9][6] = CHE(3, chc_my); /* 相 */ - board[9][0] = board[9][8] = CHE(4, chc_my); /* 車 */ - board[9][1] = board[9][7] = CHE(5, chc_my); /* 傌 */ - board[7][1] = board[7][7] = CHE(6, chc_my); /* 炮 */ - board[6][0] = board[6][2] = board[6][4] = - board[6][6] = board[6][8] = CHE(7, chc_my); /* 兵 */ -} - -void -chc_movechess(board_t board) -{ - board[chc_to.r][chc_to.c] = board[chc_from.r][chc_from.c]; - board[chc_from.r][chc_from.c] = 0; -} - -static int -dist(rc_t from, rc_t to, int rowcol) -{ - int d; - - d = rowcol ? from.c - to.c : from.r - to.r; - return d > 0 ? d : -d; -} - -static int -between(board_t board, rc_t from, rc_t to, int rowcol) -{ - int i, rtv = 0; - - if (rowcol) { - if (from.c > to.c) - i = from.c, from.c = to.c, to.c = i; - for (i = from.c + 1; i < to.c; i++) - if (board[to.r][i]) - rtv++; - } else { - if (from.r > to.r) - i = from.r, from.r = to.r, to.r = i; - for (i = from.r + 1; i < to.r; i++) - if (board[i][to.c]) - rtv++; - } - return rtv; -} - -int -chc_canmove(board_t board, rc_t from, rc_t to) -{ - int i; - int rd, cd, turn; - - rd = dist(from, to, 0); - cd = dist(from, to, 1); - turn = CHE_O(board[from.r][from.c]); - - /* general check */ - if (board[to.r][to.c] && CHE_O(board[to.r][to.c]) == turn) - return 0; - - /* individual check */ - switch (CHE_P(board[from.r][from.c])) { - case 1: /* 將 帥 */ - if (!(rd == 1 && cd == 0) && - !(rd == 0 && cd == 1)) - return 0; - if ((turn == (chc_my ^ 1) && to.r > 2) || - (turn == chc_my && to.r < 7) || - to.c < 3 || to.c > 5) - return 0; - break; - case 2: /* 士 仕 */ - if (!(rd == 1 && cd == 1)) - return 0; - if ((turn == (chc_my ^ 1) && to.r > 2) || - (turn == chc_my && to.r < 7) || - to.c < 3 || to.c > 5) - return 0; - break; - case 3: /* 象 相 */ - if (!(rd == 2 && cd == 2)) - return 0; - if ((turn == (chc_my ^ 1) && to.r > 4) || - (turn == chc_my && to.r < 5)) - return 0; - /* 拐象腿 */ - if (board[CENTER(from.r, to.r)][CENTER(from.c, to.c)]) - return 0; - break; - case 4: /* 車 */ - if (!(rd > 0 && cd == 0) && - !(rd == 0 && cd > 0)) - return 0; - if (between(board, from, to, rd == 0)) - return 0; - break; - case 5: /* 馬 傌 */ - if (!(rd == 2 && cd == 1) && - !(rd == 1 && cd == 2)) - return 0; - /* 拐馬腳 */ - if (rd == 2) { - if (board[CENTER(from.r, to.r)][from.c]) - return 0; - } else { - if (board[from.r][CENTER(from.c, to.c)]) - return 0; - } - break; - case 6: /* 包 炮 */ - if (!(rd > 0 && cd == 0) && - !(rd == 0 && cd > 0)) - return 0; - i = between(board, from, to, rd == 0); - if ((i > 1) || - (i == 1 && !board[to.r][to.c]) || - (i == 0 && board[to.r][to.c])) - return 0; - break; - case 7: /* 卒 兵 */ - if (!(rd == 1 && cd == 0) && - !(rd == 0 && cd == 1)) - return 0; - if (((turn == (chc_my ^ 1) && to.r < 5) || - (turn == chc_my && to.r > 4)) && - cd != 0) - return 0; - if ((turn == (chc_my ^ 1) && to.r < from.r) || - (turn == chc_my && to.r > from.r)) - return 0; - break; - } - return 1; -} - -static void -findking(board_t board, int turn, rc_t * buf) -{ - int i, r, c; - - r = (turn == (chc_my ^ 1)) ? 0 : 7; - for (i = 0; i < 3; r++, i++) - for (c = 3; c < 6; c++) - if (CHE_P(board[r][c]) == 1 && - CHE_O(board[r][c]) == turn) { - buf->r = r, buf->c = c; - return; - } -} - -int -chc_iskfk(board_t board) -{ - rc_t from, to; - - findking(board, 0, &to); - findking(board, 1, &from); - if (from.c == to.c && between(board, from, to, 0) == 0) - return 1; - return 0; -} - -int -chc_ischeck(board_t board, int turn) -{ - rc_t from, to; - - findking(board, turn, &to); - for (from.r = 0; from.r < BRD_ROW; from.r++) - for (from.c = 0; from.c < BRD_COL; from.c++) - if (board[from.r][from.c] && - CHE_O(board[from.r][from.c]) != turn) - if (chc_canmove(board, from, to)) - return 1; - return 0; -} diff --git a/pttbbs/mbbsd/gomo.c b/pttbbs/mbbsd/gomo.c index 0b64e709..1b95ef4d 100644 --- a/pttbbs/mbbsd/gomo.c +++ b/pttbbs/mbbsd/gomo.c @@ -1,6 +1,8 @@ /* $Id$ */ #include "bbs.h" +#define QCAST int (*)(const void *, const void *) + static char *chess[] = {"●", "○"}; static int tick, lastcount, mylasttick, hislasttick; @@ -11,6 +13,139 @@ typedef struct { static Horder_t *v; +/* pattern and advance map */ + +static int +intrevcmp(const void *a, const void *b) +{ + return (*(int *)b - *(int *)a); +} + +// 以 (x,y) 為起點, 方向 (dx,dy), 傳回以 bit 表示相鄰哪幾格有子 +// 如 10111 表示該方向相鄰 1,2,3 有子, 4 空地 +// 最高位 1 表示對方的子, 或是牆 +/* x,y: 0..BRDSIZ-1 ; color: CBLACK,CWHITE ; dx,dy: -1,0,+1 */ +static int +gomo_getindex(int x, int y, int color, int dx, int dy) +{ + int i, k, n; + for (n = -1, i = 0, k = 1; i < 5; i++, k*=2) { + x += dx; + y += dy; + + if ((x < 0) || (x >= BRDSIZ) || (y < 0) || (y >= BRDSIZ)) { + n += k; + break; + } else if (ku[x][y] != BBLANK) { + n += k; + if (ku[x][y] != color) + break; + } + } + + if (i >= 5) + n += k; + + return n; +} + +int +chkwin(int style, int limit) +{ + if (style == 0x0c) + return 1 /* style */ ; + else if (limit == 0) { + if (style == 0x0b) + return 1 /* style */ ; + return 0; + } + if ((style < 0x0c) && (style > 0x07)) + return -1 /* -style */ ; + return 0; +} + +/* x,y: 0..BRDSIZ-1 ; color: CBLACK,CWHITE ; limit:1,0 ; dx,dy: 0,1 */ +static int +dirchk(int x, int y, int color, int limit, int dx, int dy) +{ + int le, ri, loc, style = 0; + + le = gomo_getindex(x, y, color, -dx, -dy); + ri = gomo_getindex(x, y, color, dx, dy); + + loc = (le > ri) ? (((le * (le + 1)) >> 1) + ri) : + (((ri * (ri + 1)) >> 1) + le); + + style = pat[loc]; + + if (limit == 0) + return (style & 0x0f); + + style >>= 4; + + if ((style == 3) || (style == 2)) { + int i, n = 0, tmp, nx, ny; + + n = adv[loc / 2]; + + if(loc%2==0) + n/=16; + else + n%=16; + + ku[x][y] = color; + + for (i = 0; i < 2; i++) { + if ((tmp = (i == 0) ? (-(n >> 2)) : (n & 3)) != 0) { + nx = x + (le > ri ? 1 : -1) * tmp * dx; + ny = y + (le > ri ? 1 : -1) * tmp * dy; + + if ((dirchk(nx, ny, color, 0, dx, dy) == 0x06) && + (chkwin(getstyle(nx, ny, color, limit), limit) >= 0)) + break; + } + } + if (i >= 2) + style = 0; + ku[x][y] = BBLANK; + } + return style; +} + +/* 例外=F 錯誤=E 有子=D 連五=C 連六=B 雙四=A 四四=9 三三=8 */ +/* 四三=7 活四=6 斷四=5 死四=4 活三=3 斷三=2 保留=1 無效=0 */ + +/* x,y: 0..BRDSIZ-1 ; color: CBLACK,CWHITE ; limit: 1,0 */ +int +getstyle(int x, int y, int color, int limit) +{ + int i, j, dir[4], style; + + if ((x < 0) || (x >= BRDSIZ) || (y < 0) || (y >= BRDSIZ)) + return 0x0f; + if (ku[x][y] != BBLANK) + return 0x0d; + + // (-1,1), (0,1), (1,0), (1,1) + for (i = 0; i < 4; i++) + dir[i] = dirchk(x, y, color, limit, i ? (i >> 1) : -1, i ? (i & 1) : 1); + + qsort(dir, 4, sizeof(int), (QCAST)intrevcmp); + + if ((style = dir[0]) >= 2) { + for (i = 1, j = 6 + (limit ? 1 : 0); i < 4; i++) { + if ((style > j) || (dir[i] < 2)) + break; + if (dir[i] > 3) + style = 9; + else if ((style < 7) && (style > 3)) + style = 7; + else + style = 8; + } + } + return style; +} static void HO_init(Horder_t *pool) { diff --git a/pttbbs/mbbsd/gomo1.c b/pttbbs/mbbsd/gomo1.c deleted file mode 100644 index 49d484a5..00000000 --- a/pttbbs/mbbsd/gomo1.c +++ /dev/null @@ -1,138 +0,0 @@ -/* $Id$ */ -#include "bbs.h" - -#define QCAST int (*)(const void *, const void *) - -/* pattern and advance map */ - -static int -intrevcmp(const void *a, const void *b) -{ - return (*(int *)b - *(int *)a); -} - -// 以 (x,y) 為起點, 方向 (dx,dy), 傳回以 bit 表示相鄰哪幾格有子 -// 如 10111 表示該方向相鄰 1,2,3 有子, 4 空地 -// 最高位 1 表示對方的子, 或是牆 -/* x,y: 0..BRDSIZ-1 ; color: CBLACK,CWHITE ; dx,dy: -1,0,+1 */ -static int -gomo_getindex(int x, int y, int color, int dx, int dy) -{ - int i, k, n; - for (n = -1, i = 0, k = 1; i < 5; i++, k*=2) { - x += dx; - y += dy; - - if ((x < 0) || (x >= BRDSIZ) || (y < 0) || (y >= BRDSIZ)) { - n += k; - break; - } else if (ku[x][y] != BBLANK) { - n += k; - if (ku[x][y] != color) - break; - } - } - - if (i >= 5) - n += k; - - return n; -} - -int -chkwin(int style, int limit) -{ - if (style == 0x0c) - return 1 /* style */ ; - else if (limit == 0) { - if (style == 0x0b) - return 1 /* style */ ; - return 0; - } - if ((style < 0x0c) && (style > 0x07)) - return -1 /* -style */ ; - return 0; -} - -/* x,y: 0..BRDSIZ-1 ; color: CBLACK,CWHITE ; limit:1,0 ; dx,dy: 0,1 */ -static int -dirchk(int x, int y, int color, int limit, int dx, int dy) -{ - int le, ri, loc, style = 0; - - le = gomo_getindex(x, y, color, -dx, -dy); - ri = gomo_getindex(x, y, color, dx, dy); - - loc = (le > ri) ? (((le * (le + 1)) >> 1) + ri) : - (((ri * (ri + 1)) >> 1) + le); - - style = pat[loc]; - - if (limit == 0) - return (style & 0x0f); - - style >>= 4; - - if ((style == 3) || (style == 2)) { - int i, n = 0, tmp, nx, ny; - - n = adv[loc / 2]; - - if(loc%2==0) - n/=16; - else - n%=16; - - ku[x][y] = color; - - for (i = 0; i < 2; i++) { - if ((tmp = (i == 0) ? (-(n >> 2)) : (n & 3)) != 0) { - nx = x + (le > ri ? 1 : -1) * tmp * dx; - ny = y + (le > ri ? 1 : -1) * tmp * dy; - - if ((dirchk(nx, ny, color, 0, dx, dy) == 0x06) && - (chkwin(getstyle(nx, ny, color, limit), limit) >= 0)) - break; - } - } - if (i >= 2) - style = 0; - ku[x][y] = BBLANK; - } - return style; -} - -/* 例外=F 錯誤=E 有子=D 連五=C 連六=B 雙四=A 四四=9 三三=8 */ -/* 四三=7 活四=6 斷四=5 死四=4 活三=3 斷三=2 保留=1 無效=0 */ - -/* x,y: 0..BRDSIZ-1 ; color: CBLACK,CWHITE ; limit: 1,0 */ -int -getstyle(int x, int y, int color, int limit) -{ - int i, j, dir[4], style; - - if ((x < 0) || (x >= BRDSIZ) || (y < 0) || (y >= BRDSIZ)) - return 0x0f; - if (ku[x][y] != BBLANK) - return 0x0d; - - // (-1,1), (0,1), (1,0), (1,1) - for (i = 0; i < 4; i++) - dir[i] = dirchk(x, y, color, limit, i ? (i >> 1) : -1, i ? (i & 1) : 1); - - qsort(dir, 4, sizeof(int), (QCAST)intrevcmp); - - if ((style = dir[0]) >= 2) { - for (i = 1, j = 6 + (limit ? 1 : 0); i < 4; i++) { - if ((style > j) || (dir[i] < 2)) - break; - if (dir[i] > 3) - style = 9; - else if ((style < 7) && (style > 3)) - style = 7; - else - style = 8; - } - } - return style; -} diff --git a/pttbbs/mbbsd/mbbsd.c b/pttbbs/mbbsd/mbbsd.c index 5cf1fb90..7968860e 100644 --- a/pttbbs/mbbsd/mbbsd.c +++ b/pttbbs/mbbsd/mbbsd.c @@ -249,7 +249,7 @@ dosearchuser(char *userid) return usernum; } -static void +void talk_request(int sig) { bell(); diff --git a/pttbbs/mbbsd/name.c b/pttbbs/mbbsd/name.c index b16f19ef..5c04a54a 100644 --- a/pttbbs/mbbsd/name.c +++ b/pttbbs/mbbsd/name.c @@ -1,4 +1,4 @@ -/* $Id: name.c,v 1.16 2003/02/20 16:12:13 in2 Exp $ */ +/* $Id$ */ #include "bbs.h" static word_t *current = NULL; diff --git a/pttbbs/mbbsd/othello.c b/pttbbs/mbbsd/othello.c index 6f6d69ab..96fea2e2 100644 --- a/pttbbs/mbbsd/othello.c +++ b/pttbbs/mbbsd/othello.c @@ -1,4 +1,4 @@ -/* $Id: othello.c,v 1.5 2002/07/21 09:26:02 in2 Exp $ */ +/* $Id$ */ #include "bbs.h" #define LOGFILE "etc/othello.log" diff --git a/pttbbs/mbbsd/talk.c b/pttbbs/mbbsd/talk.c index 2ef59c86..7ccd1e87 100644 --- a/pttbbs/mbbsd/talk.c +++ b/pttbbs/mbbsd/talk.c @@ -39,6 +39,8 @@ static char save_page_requestor[40]; static char page_requestor[40]; static FILE *flog; +userinfo_t *uip; + int iswritable_stat(userinfo_t * uentp, int fri_stat) { @@ -1187,8 +1189,8 @@ int make_connection_to_somebody(userinfo_t *uin, int timeout){ return sock; } -static void -my_talk(userinfo_t * uin, int fri_stat) +void +my_talk(userinfo_t * uin, int fri_stat, char defact) { int sock, msgsock, error = 0, ch; pid_t pid; @@ -1197,6 +1199,7 @@ my_talk(userinfo_t * uin, int fri_stat) unsigned char mode0 = currutmp->mode; + genbuf[0] = defact; ch = uin->mode; strlcpy(currauthor, uin->userid, sizeof(currauthor)); @@ -2215,7 +2218,7 @@ userlist(void) move(3, 0); if (uentp->pid != currpid && strcmp(uentp->userid, cuser.userid) != 0) { - my_talk(uentp, fri_stat); + my_talk(uentp, fri_stat, 0); } else{ self_play(uentp, fri_stat); @@ -2522,12 +2525,12 @@ t_talk() } if ((uentp = (userinfo_t *) search_ulistn(tuid, unum))) - my_talk(uentp, friend_stat(currutmp, uentp)); + my_talk(uentp, friend_stat(currutmp, uentp), 0); return 0; } -static int +int reply_connection_request(userinfo_t *uip) { int a; @@ -2561,7 +2564,6 @@ reply_connection_request(userinfo_t *uip) } /* 有人來串門子了,回應呼叫器 */ -static userinfo_t *uip; void talkreply(void) { diff --git a/pttbbs/sample/etc/chess/1.poem b/pttbbs/sample/etc/chess/1.poem new file mode 100644 index 00000000..f50247ab --- /dev/null +++ b/pttbbs/sample/etc/chess/1.poem @@ -0,0 +1,10 @@ +象弈 南宋 劉克莊 + + 或遲如圍莒,或速如入蔡。 + + 遠炮勿虛發,冗卒要精汰。 + + 負非由寡少,勝豈繫強大? + + 昆陽以象奔,陳濤以車敗。 + diff --git a/pttbbs/sample/etc/chess/10.poem b/pttbbs/sample/etc/chess/10.poem new file mode 100644 index 00000000..b9dc2107 --- /dev/null +++ b/pttbbs/sample/etc/chess/10.poem @@ -0,0 +1,10 @@ +無題 明 明太子朱高熾 + + 二國爭強各用兵,擺成隊伍定輸贏。 + + 馬行曲路當先道,將守深宮戒遠征。 + + 乘險出車收敗卒,隔河飛炮下重城。 + + 等閒識得軍情事,一著功成見太平。 + diff --git a/pttbbs/sample/etc/chess/11.poem b/pttbbs/sample/etc/chess/11.poem new file mode 100644 index 00000000..01331372 --- /dev/null +++ b/pttbbs/sample/etc/chess/11.poem @@ -0,0 +1,6 @@ +無題 不明 + + 清風明月之夜,詩歌唱詠; + + 古松流水之間,敲棋品茗。 + diff --git a/pttbbs/sample/etc/chess/12.poem b/pttbbs/sample/etc/chess/12.poem new file mode 100644 index 00000000..53a68b72 --- /dev/null +++ b/pttbbs/sample/etc/chess/12.poem @@ -0,0 +1,6 @@ +諷宋薛昂處士負棋作詩 不明 + + 好笑當年薛乞兒,荊公座上賭新詩, + + 而今又向江東去,奉勸先生莫下棋。 + diff --git a/pttbbs/sample/etc/chess/13.poem b/pttbbs/sample/etc/chess/13.poem new file mode 100644 index 00000000..01331372 --- /dev/null +++ b/pttbbs/sample/etc/chess/13.poem @@ -0,0 +1,6 @@ +無題 不明 + + 清風明月之夜,詩歌唱詠; + + 古松流水之間,敲棋品茗。 + diff --git a/pttbbs/sample/etc/chess/14.poem b/pttbbs/sample/etc/chess/14.poem new file mode 100644 index 00000000..d41950e8 --- /dev/null +++ b/pttbbs/sample/etc/chess/14.poem @@ -0,0 +1,10 @@ +無題 明 明象棋高手李開先 村翁 + + 小有兼逢大有年,田家多穫即為賢。 + + 有時撒網為漁父,日常登床作睡仙。 + + 破局棋堆隨手應,無弦琴不用音傳。 + + 一身之外無所慕,下有青山上碧天。 + diff --git a/pttbbs/sample/etc/chess/15.poem b/pttbbs/sample/etc/chess/15.poem new file mode 100644 index 00000000..139597f9 --- /dev/null +++ b/pttbbs/sample/etc/chess/15.poem @@ -0,0 +1,2 @@ + + diff --git a/pttbbs/sample/etc/chess/16.poem b/pttbbs/sample/etc/chess/16.poem new file mode 100644 index 00000000..139597f9 --- /dev/null +++ b/pttbbs/sample/etc/chess/16.poem @@ -0,0 +1,2 @@ + + diff --git a/pttbbs/sample/etc/chess/2.poem b/pttbbs/sample/etc/chess/2.poem new file mode 100644 index 00000000..119e98ae --- /dev/null +++ b/pttbbs/sample/etc/chess/2.poem @@ -0,0 +1,10 @@ +棋詩 明 曾子棨 + + 兩軍對敵立雙營,坐運神機決死生。 + + 千里封疆馳鐵馬,一川波浪動金兵。 + + 虞姬歌舞悲垓下,反將旌旗逼楚城。 + + 興盡計窮征戰罷,松蔭花影滿棋秤。 + diff --git a/pttbbs/sample/etc/chess/3.poem b/pttbbs/sample/etc/chess/3.poem new file mode 100644 index 00000000..d69636b7 --- /dev/null +++ b/pttbbs/sample/etc/chess/3.poem @@ -0,0 +1,6 @@ +觀棋 清 袁枚 + + 攏袖觀棋有所思,分明楚漢兩軍峙。 + + 非常喜歡非常惱,不著棋人總不如。 + diff --git a/pttbbs/sample/etc/chess/4.poem b/pttbbs/sample/etc/chess/4.poem new file mode 100644 index 00000000..f86edc12 --- /dev/null +++ b/pttbbs/sample/etc/chess/4.poem @@ -0,0 +1,10 @@ +和春深 唐 白居易 + + 何處深為好,春到博弈家。 + + 一先爭破眼,六聚斗成花, + + 鼓應投壹馬,兵沖象戲車。 + + 評棋局上事,最妙是長斜。 + diff --git a/pttbbs/sample/etc/chess/5.poem b/pttbbs/sample/etc/chess/5.poem new file mode 100644 index 00000000..cffd55e1 --- /dev/null +++ b/pttbbs/sample/etc/chess/5.poem @@ -0,0 +1,8 @@ +無題 宋 王安石 + + 飄飄凌雲志,強御莫能懾; + + 忘情塞上馬,適志夢中蝶; + + 經論安所施,有寓聊自愜。 + diff --git a/pttbbs/sample/etc/chess/6.poem b/pttbbs/sample/etc/chess/6.poem new file mode 100644 index 00000000..00c4cff8 --- /dev/null +++ b/pttbbs/sample/etc/chess/6.poem @@ -0,0 +1,6 @@ +無題 呂洞賓 + + 教著殘局山月曉, + + 一聲長嘯海天秋。 + diff --git a/pttbbs/sample/etc/chess/7.poem b/pttbbs/sample/etc/chess/7.poem new file mode 100644 index 00000000..b525cba0 --- /dev/null +++ b/pttbbs/sample/etc/chess/7.poem @@ -0,0 +1,10 @@ +吊棋 明 錢鶴灘 + + 敲棋終日與偏幽,誰道今朝結父仇。 + + 兵足下河車不救,將軍落水士難留。 + + 馬行千里隨波去,象渡三江逐淚流。 + + 炮響一聲驚霹靂,臥龍投起碧雲浮。 + diff --git a/pttbbs/sample/etc/chess/8.poem b/pttbbs/sample/etc/chess/8.poem new file mode 100644 index 00000000..01360b29 --- /dev/null +++ b/pttbbs/sample/etc/chess/8.poem @@ -0,0 +1,10 @@ +詠象戲 北宋 程顥 + + 大都博弈皆戲劇,象戲翻能學用兵。 + + 車馬尚存周戰法,偏裨兼備漢官名。 + + 中軍八面將軍重,河外尖斜步卒輕。 + + 卻憑紋楸聊自笑,雄如劉項亦間爭。 + diff --git a/pttbbs/sample/etc/chess/9.poem b/pttbbs/sample/etc/chess/9.poem new file mode 100644 index 00000000..01331372 --- /dev/null +++ b/pttbbs/sample/etc/chess/9.poem @@ -0,0 +1,6 @@ +無題 不明 + + 清風明月之夜,詩歌唱詠; + + 古松流水之間,敲棋品茗。 + -- cgit v1.2.3 From 5e1781467ed54b328322e402a0f59d70c5c0c1e2 Mon Sep 17 00:00:00 2001 From: victor <victor@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Wed, 10 Sep 2003 07:15:02 +0000 Subject: fix the bug with wrong length of fromhost git-svn-id: http://opensvn.csie.org/pttbbs/trunk@1173 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/mbbsd.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pttbbs/mbbsd/mbbsd.c b/pttbbs/mbbsd/mbbsd.c index 7968860e..f9bc80b3 100644 --- a/pttbbs/mbbsd/mbbsd.c +++ b/pttbbs/mbbsd/mbbsd.c @@ -786,9 +786,9 @@ inline static void birthday_make_a_wish(struct tm *ptime, struct tm *tmp){ } } -inline static void record_lasthost(char *fromhost){ - strncpy(cuser.lasthost, fromhost, sizeof(cuser.lasthost)); - cuser.lasthost[sizeof(cuser.lasthost - 1)] = '\0'; +inline static void record_lasthost(char *fromhost, int len){ + strncpy(cuser.lasthost, fromhost, len); + cuser.lasthost[len - 1] = '\0'; } inline static void check_mailbox_and_read(void){ @@ -916,7 +916,7 @@ user_login() check_bad_login(); check_mailbox_and_read(); check_register(); - record_lasthost(fromhost); + record_lasthost(fromhost, 16); restore_backup(); } else if (!strcmp(cuser.userid, STR_GUEST)) { init_guest_info(); -- cgit v1.2.3 From 6821e7f7bc89a028b8288bf4d64a74a539039659 Mon Sep 17 00:00:00 2001 From: kcwu <kcwu@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Wed, 10 Sep 2003 09:00:29 +0000 Subject: code clean up git-svn-id: http://opensvn.csie.org/pttbbs/trunk@1174 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/bbs.c | 20 +++++++++------ pttbbs/mbbsd/cal.c | 4 +-- pttbbs/mbbsd/chat.c | 7 +++--- pttbbs/mbbsd/dice.c | 13 +++------- pttbbs/mbbsd/io.c | 2 +- pttbbs/mbbsd/mbbsd.c | 69 ++++++++++++++++++++------------------------------- pttbbs/mbbsd/menu.c | 40 +++++++++++++++++------------ pttbbs/mbbsd/screen.c | 15 ++++------- pttbbs/mbbsd/talk.c | 2 +- pttbbs/mbbsd/var.c | 4 +-- 10 files changed, 81 insertions(+), 95 deletions(-) diff --git a/pttbbs/mbbsd/bbs.c b/pttbbs/mbbsd/bbs.c index bb7d7f9a..85c894a6 100644 --- a/pttbbs/mbbsd/bbs.c +++ b/pttbbs/mbbsd/bbs.c @@ -100,7 +100,6 @@ save_violatelaw() */ static time_t board_note_time; -static char *brd_title; void set_board() @@ -113,12 +112,10 @@ set_board() u_exit("access control violation!"); } board_note_time = bp->bupdate; - brd_title = bp->BM; - if (brd_title[0] <= ' ') - brd_title = "徵求中"; - snprintf(currBM, sizeof(currBM), "板主:%s", brd_title); - brd_title = ((bp->bvote != 2 && bp->bvote) ? "本看板進行投票中" : - bp->title + 7); + if(bp->BM[0] <= ' ') + strcpy(currBM, "徵求中"); + else + snprintf(currBM, sizeof(currBM), "板主:%s", bp->BM); currmode = (currmode & (MODE_DIRTY | MODE_MENU)) | MODE_STARTED; if (HAS_PERM(PERM_ALLBOARD) || is_BM_cache(currbid)) @@ -130,6 +127,15 @@ set_board() static void readtitle() { + boardheader_t *bp; + char *brd_title; + + bp = getbcache(currbid); + if(bp->bvote != 2 && bp->bvote) + brd_title = "本看板進行投票中"; + else + brd_title = bp->title + 7; + showtitle(currBM, brd_title); outs("[←]離開 [→]閱\讀 [^P]發表文章 [b]備忘錄 [d]刪除 [z]精華區 " "[TAB]文摘 [h]elp\n\033[7m 編號 日 期 作 者 文 章 標 題" diff --git a/pttbbs/mbbsd/cal.c b/pttbbs/mbbsd/cal.c index fceaf2b1..37123a01 100644 --- a/pttbbs/mbbsd/cal.c +++ b/pttbbs/mbbsd/cal.c @@ -409,11 +409,11 @@ p_give() int p_sysinfo(void) { - char buf[128], *cpuloadstr; + char *cpuloadstr; int load; extern char *compile_time; - load = cpuload(buf); + load = cpuload(NULL); cpuloadstr = (load < 5 ? "良好" : (load < 20 ? "尚可" : "過重")); clear(); diff --git a/pttbbs/mbbsd/chat.c b/pttbbs/mbbsd/chat.c index d7ea2f53..11988f9f 100644 --- a/pttbbs/mbbsd/chat.c +++ b/pttbbs/mbbsd/chat.c @@ -57,10 +57,8 @@ chat_send(int fd, char *buf) return (send(fd, genbuf, len, 0) == len); } -static char chatroom[IDLEN];/* Chat-Room Name */ - static int -chat_recv(int fd, char *chatid) +chat_recv(int fd, char chatroom[IDLEN], char *chatid) { static char buf[128]; static int bufstart = 0; @@ -299,6 +297,7 @@ static int chatid_len = 10; int t_chat() { + char chatroom[IDLEN];/* Chat-Room Name */ char inbuf[80], chatid[20], lastcmd[MAXLASTCMD][80], *ptr = ""; struct sockaddr_in sin; struct hostent *h; @@ -415,7 +414,7 @@ t_chat() printchatline("◆ 噹!郵差又來了..."); } if (ch == I_OTHERDATA) {/* incoming */ - if (chat_recv(cfd, chatid) == -1) { + if (chat_recv(cfd, chatroom, chatid) == -1) { chatting = chat_send(cfd, "/b"); break; } diff --git a/pttbbs/mbbsd/dice.c b/pttbbs/mbbsd/dice.c index 12572965..8fb0a9f9 100644 --- a/pttbbs/mbbsd/dice.c +++ b/pttbbs/mbbsd/dice.c @@ -1,4 +1,4 @@ -/* $Id: dice.c,v 1.7 2003/01/16 12:23:03 kcwu Exp $ */ +/* $Id$ */ #include "bbs.h" #define DICE_TXT BBSHOME "/etc/dice.txt" @@ -332,7 +332,7 @@ dice_main(void) char input[10], data[256], ch; dicedata_t table[256]; int bet[3], index, money = 0, i, ya = 0, j, total, sig = 0; - FILE *winfp /* , *lostfp */ ; + FILE *winfp; more(DICE_TXT, NA); reload_money(); @@ -344,8 +344,7 @@ dice_main(void) } lockreturn0(DICE, LOCK_MULTI); winfp = fopen(DICE_WIN, "a"); - /* lostfp = fopen(DICE_LOST,"a"); */ - if (!winfp /* || !lostfp */ ) + if (!winfp) return 0; do { @@ -433,7 +432,6 @@ dice_main(void) if (i == 0) { fclose(winfp); - /* fclose(lostfp); */ unlockutmpmode(); return 0; } @@ -445,10 +443,6 @@ dice_main(void) continue; ya = bingo(flag, table[j].mybet); if (ya == 0) { - /* - * sprintf(data, "%-15s 輸了 %-8d $", cuser.userid, - * table[j].mymoney); fprintf(lostfp, "%s\n", data); - */ continue; } demoney(table[j].mymoney * ya + table[j].mymoney); @@ -482,7 +476,6 @@ dice_main(void) input, 2, LCECHO); } while (input[0] != 'n' && input[0] != 'N'); fclose(winfp); - /* fclose(lostfp); */ unlockutmpmode(); return 0; } diff --git a/pttbbs/mbbsd/io.c b/pttbbs/mbbsd/io.c index 6f3cff9e..bb09d79f 100644 --- a/pttbbs/mbbsd/io.c +++ b/pttbbs/mbbsd/io.c @@ -492,7 +492,7 @@ getans(char *prompt) { char ans[5]; - getdata(t_lines - 1, 0, prompt, ans, sizeof(ans), LCECHO); + getdata(b_lines, 0, prompt, ans, sizeof(ans), LCECHO); return ans[0]; } diff --git a/pttbbs/mbbsd/mbbsd.c b/pttbbs/mbbsd/mbbsd.c index f9bc80b3..e419cc1d 100644 --- a/pttbbs/mbbsd/mbbsd.c +++ b/pttbbs/mbbsd/mbbsd.c @@ -92,29 +92,6 @@ reapchild(int sig) while ((pid = waitpid(-1, &state, WNOHANG | WUNTRACED)) > 0); } -#define BANNER \ -"【" BBSNAME "】◎ 台大流行網 ◎(" MYHOSTNAME ") 調幅(" MYIP ") " -/* check load and print approriate banner string in buf */ -static int -chkload(char *buf, int length) -{ - char cpu_load[30]; - int i; - - i = cpuload(cpu_load); - - buf[0] = 0; -#ifdef INSCREEN - if( i > MAX_CPULOAD ){ - strlcpy(buf, BANNER "\r\n系統過載, 請稍後再來\r\n", length); - } -#else - snprintf(buf, length, BANNER "%s\r\n", - (i > MAX_CPULOAD ? "高負荷量,請稍後再來(請利用port 3000~3010連線)" : "")); -#endif - return i > MAX_CPULOAD ? 1 : 0; -} - void log_user(char *msg) { @@ -1371,41 +1348,49 @@ static int check_ban_and_load(int fd) { FILE *fp; - static char buf[256]; static time_t chkload_time = 0; static int overload = 0; /* overload or banned, update every 1 * sec */ static int banned = 0; #ifdef INSCREEN - write(fd, INSCREEN, strlen(INSCREEN)); + write(fd, INSCREEN, sizeof(INSCREEN)); +#else +#define BANNER \ +"【" BBSNAME "】◎ 台大流行網 ◎(" MYHOSTNAME ") 調幅(" MYIP ") \r\n" + write(fd, BANNER, sizeof(BANNER)); #endif if ((time(0) - chkload_time) > 1) { - overload = chkload(buf, sizeof(buf)); - banned = !access(BBSHOME "/BAN", R_OK) && - (strcmp(fromhost, "localhost") != 0); + overload = 0; + banned = 0; + + if(cpuload(NULL) > MAX_CPULOAD) + overload = 1; + else if (SHM->UTMPnumber >= MAX_ACTIVE +#ifdef DYMAX_ACTIVE + || (SHM->GV2.e.dymaxactive > 2000 && + SHM->UTMPnumber >= SHM->GV2.e.dymaxactive) +#endif + ) { + ++SHM->GV2.e.toomanyusers; + overload = 2; + } else if(!access(BBSHOME "/" BAN_FILE, R_OK)) + banned = 1; + chkload_time = time(0); } - write(fd, buf, strlen(buf)); - if (banned && (fp = fopen(BBSHOME "/BAN", "r"))) { - // XXX this will mess up buf + if(overload == 1) + write(fd, "系統過載, 請稍後再來\r\n", 22); + else if(overload == 2) + write(fd, "由於人數過多,請您稍後再來。", 28); + else if (banned && (fp = fopen(BBSHOME "/" BAN_FILE, "r"))) { + char buf[256]; while (fgets(buf, sizeof(buf), fp)) write(fd, buf, strlen(buf)); fclose(fp); } - if (SHM->UTMPnumber >= MAX_ACTIVE -#ifdef DYMAX_ACTIVE - || (SHM->GV2.e.dymaxactive > 2000 && - SHM->UTMPnumber >= SHM->GV2.e.dymaxactive) -#endif - ) { - ++SHM->GV2.e.toomanyusers; - snprintf(buf, sizeof(buf), "由於人數過多,請您稍後再來。"); - write(fd, buf, strlen(buf)); - overload = 1; - } if (banned || overload) return -1; diff --git a/pttbbs/mbbsd/menu.c b/pttbbs/mbbsd/menu.c index bca66e7b..1e42410c 100644 --- a/pttbbs/mbbsd/menu.c +++ b/pttbbs/mbbsd/menu.c @@ -92,7 +92,27 @@ showtitle(char *title, char *mid) #define FILMROW 11 static unsigned char menu_row = 12; static unsigned char menu_column = 20; -static char mystatus[160]; + +static void +show_status(void) +{ + int i; + struct tm *ptime = localtime(&now); + char mystatus[160]; + char *myweek = "天一二三四五六"; + const char *msgs[] = {"關閉", "打開", "拔掉", "防水", "好友"}; + + i = ptime->tm_wday << 1; + snprintf(mystatus, sizeof(mystatus), + "\033[34;46m[%d/%d 星期%c%c %d:%02d]\033[1;33;45m%-14s" + "\033[30;47m 目前坊裡有 \033[31m%d\033[30m人, 我是\033[31m%-12s" + "\033[30m[扣機]\033[31m%s\033[0m", + ptime->tm_mon + 1, ptime->tm_mday, myweek[i], myweek[i + 1], + ptime->tm_hour, ptime->tm_min, currutmp->birth ? + "生日要請客唷" : SHM->today_is, + SHM->UTMPnumber, cuser.userid, msgs[currutmp->pager]); + outmsg(mystatus); +} static int u_movie() @@ -105,9 +125,6 @@ void movie(int i) { static short history[MAX_HISTORY]; - char *myweek = "天一二三四五六"; - const char *msgs[] = {"關閉", "打開", "拔掉", "防水", "好友"}; - struct tm *ptime = localtime(&now); int j; if ((currstat != CLASS) && (cuser.uflag & MOVIE_FLAG) && @@ -140,16 +157,7 @@ movie(int i) Jaky_outs(SHM->notes[i], 11); /* 只印11行就好 */ outs(reset_color); } - i = ptime->tm_wday << 1; - snprintf(mystatus, sizeof(mystatus), - "\033[34;46m[%d/%d 星期%c%c %d:%02d]\033[1;33;45m%-14s" - "\033[30;47m 目前坊裡有 \033[31m%d\033[30m人, 我是\033[31m%-12s" - "\033[30m[扣機]\033[31m%s\033[0m", - ptime->tm_mon + 1, ptime->tm_mday, myweek[i], myweek[i + 1], - ptime->tm_hour, ptime->tm_min, currutmp->birth ? - "生日要請客唷" : SHM->today_is, - SHM->UTMPnumber, cuser.userid, msgs[currutmp->pager]); - outmsg(mystatus); + show_status(); refresh(); } @@ -193,7 +201,7 @@ domenu(int cmdmode, char *cmdtitle, int cmd, commands_t cmdtable[]) total = show_menu(cmdtable); - outmsg(mystatus); + show_status(); lastcmdptr = pos = 0; do { @@ -296,7 +304,7 @@ domenu(int cmdmode, char *cmdtitle, int cmd, commands_t cmdtable[]) show_menu(cmdtable); - outmsg(mystatus); + show_status(); refscreen = NA; } cursor_clear(menu_row + pos, menu_column); diff --git a/pttbbs/mbbsd/screen.c b/pttbbs/mbbsd/screen.c index 1f27dd86..24dffc4d 100644 --- a/pttbbs/mbbsd/screen.c +++ b/pttbbs/mbbsd/screen.c @@ -1,4 +1,4 @@ -/* $Id: screen.c,v 1.16 2003/06/28 08:42:37 kcwu Exp $ */ +/* $Id$ */ #include "bbs.h" #ifdef SUPPORT_GB @@ -217,11 +217,11 @@ clear() register int i; docls = YEA; - cur_col = cur_ln = roll = downfrom = i = 0; - do { + cur_col = cur_ln = roll = downfrom = 0; + for(i=0; i<scr_lns; i++) { slp = &big_picture[i]; slp->mode = slp->len = slp->oldlen = 0; - } while (++i < scr_lns); + } } void @@ -473,12 +473,7 @@ outmsg(char *msg) { move(b_lines, 0); clrtoeol(); -#ifdef SUPPORT_GB - if (current_font_type == TYPE_GB) - msg = hc_convert_str(msg, HC_BIGtoGB, HC_DO_SINGLE); -#endif - while (*msg) - outc(*msg++); + outs(msg); } void diff --git a/pttbbs/mbbsd/talk.c b/pttbbs/mbbsd/talk.c index 7ccd1e87..7abb595a 100644 --- a/pttbbs/mbbsd/talk.c +++ b/pttbbs/mbbsd/talk.c @@ -396,7 +396,7 @@ my_query(char *uident) return DONOTHING; } -static char t_last_write[200] = ""; +static char t_last_write[80]; void water_scr(water_t * tw, int which, char type) diff --git a/pttbbs/mbbsd/var.c b/pttbbs/mbbsd/var.c index 5125442e..0ad9e78f 100644 --- a/pttbbs/mbbsd/var.c +++ b/pttbbs/mbbsd/var.c @@ -313,8 +313,8 @@ char *ModeTypeTable[MAX_MODES] = { }; /* term.c */ -int b_lines = 23; -int t_lines = 24; +int b_lines = 23; // bottom line of screen +int t_lines = 24; // term lines int p_lines = 20; int t_columns = 80; char *strtstandout = "\33[7m"; -- cgit v1.2.3 From 00362c2423cf62ee15ee1504a9a36f921b541a27 Mon Sep 17 00:00:00 2001 From: kcwu <kcwu@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Wed, 10 Sep 2003 09:13:24 +0000 Subject: code audit git-svn-id: http://opensvn.csie.org/pttbbs/trunk@1175 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/chc.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pttbbs/mbbsd/chc.c b/pttbbs/mbbsd/chc.c index fbd716a1..f63ae972 100644 --- a/pttbbs/mbbsd/chc.c +++ b/pttbbs/mbbsd/chc.c @@ -318,12 +318,13 @@ chc_log_poem(void) struct dirent **namelist; int n; + // TODO use readdir(), don't use lots of memory n = scandir(BBSHOME"/etc/chess", &namelist, chc_filter, alphasort); if (n < 0) perror("scandir"); else { char buf[80]; - FILE *fp; + FILE *fp; // XXX shadow global fp sprintf(buf, BBSHOME"/etc/chess/%s", namelist[rand() % n]->d_name); if ((fp = fopen(buf, "r")) == NULL) return -1; -- cgit v1.2.3 From bc5748775fa3b282b9802a1d9017745aa811cd3f Mon Sep 17 00:00:00 2001 From: kcwu <kcwu@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Thu, 11 Sep 2003 05:03:52 +0000 Subject: code cleanup git-svn-id: http://opensvn.csie.org/pttbbs/trunk@1176 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/guess.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pttbbs/mbbsd/guess.c b/pttbbs/mbbsd/guess.c index ece753b4..5ec40080 100644 --- a/pttbbs/mbbsd/guess.c +++ b/pttbbs/mbbsd/guess.c @@ -1,4 +1,4 @@ -/* $Id: guess.c,v 1.12 2003/01/17 07:59:35 kcwu Exp $ */ +/* $Id$ */ #include "bbs.h" #define LOGPASS BBSHOME "/etc/winguess.log" @@ -32,18 +32,18 @@ get_money(void) prints("您目前有:%d Ptt$", cuser.money); do { getdata(2, 0, "要賭多少(5-10或按q離開): ", data, 9, LCECHO); - money = strlen(data); + money = 0; if (data[0] == 'q' || data[0] == 'Q') { unlockutmpmode(); return 0; } - for (i = 0; i < money; i++) + for (i = 0; data[i]; i++) if (data[i] < '0' || data[i] > '9') { money = -1; break; } if (money != -1) { - money = atol(data); + money = atoi(data); reload_money(); if (money > cuser.money || money <= 4 || money > 10 || money < 1) -- cgit v1.2.3 From ae3657affb7a17998fc20326f5d7ae9199bb3497 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sat, 13 Sep 2003 03:04:47 +0000 Subject: touchdircache() after append_record() suggested by lihgong@ptt2 git-svn-id: http://opensvn.csie.org/pttbbs/trunk@1178 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/innbbsd/receive_article.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pttbbs/innbbsd/receive_article.c b/pttbbs/innbbsd/receive_article.c index 29790a96..f45fda75 100644 --- a/pttbbs/innbbsd/receive_article.c +++ b/pttbbs/innbbsd/receive_article.c @@ -873,8 +873,10 @@ char *pathname, *firstpath; append_record(index, &header, sizeof(header)); - if((bid = getbnum(board)) > 0) + if((bid = getbnum(board)) > 0){ touchbtotal(bid); + touchdircache(bid); + } return name; } -- cgit v1.2.3 From eb2ca254156a025b4f08e850374b7541f4be98d6 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sat, 13 Sep 2003 04:16:32 +0000 Subject: add buildtime git-svn-id: http://opensvn.csie.org/pttbbs/trunk@1179 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/staticweb/dir.html | 1 + pttbbs/staticweb/man.pl | 2 ++ pttbbs/staticweb/manbuilder.pl | 3 ++- 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/pttbbs/staticweb/dir.html b/pttbbs/staticweb/dir.html index c3ce33ac..50f5ef63 100644 --- a/pttbbs/staticweb/dir.html +++ b/pttbbs/staticweb/dir.html @@ -34,6 +34,7 @@ </form> [% END %] <hr /> +<font size="-1">[% IF gb %]秶釬奀潔[% ELSE %]製作時間[% END %]: [% buildtime %]</font><br> <a href="telnet://ptt.cc">[% IF gb %]蠶杺杺妗珛溶[% ELSE %]批踢踢實業坊[% END %]</a> (<a href="http://ptt.cc">PttWeb</a>) </td></tr> </table> diff --git a/pttbbs/staticweb/man.pl b/pttbbs/staticweb/man.pl index 729a78d1..274797af 100755 --- a/pttbbs/staticweb/man.pl +++ b/pttbbs/staticweb/man.pl @@ -13,6 +13,7 @@ use Data::Serializer; use Encode; use Time::HiRes qw/gettimeofday tv_interval/; use b2g; +use POSIX; use vars qw/%db $brdname $fpath $isgb %b2g/; @@ -80,6 +81,7 @@ sub dirmode $th{tmpl} = 'dir.html'; $th{isroot} = ($fpath eq '/') ? 1 : 0; + $th{buildtime} = POSIX::ctime($db{_buildtime} || 0); return \%th; } diff --git a/pttbbs/staticweb/manbuilder.pl b/pttbbs/staticweb/manbuilder.pl index c0b88db1..c135920a 100755 --- a/pttbbs/staticweb/manbuilder.pl +++ b/pttbbs/staticweb/manbuilder.pl @@ -1,5 +1,5 @@ #!/usr/bin/perl -# $Id: manbuilder.pl,v 1.9 2003/07/04 03:40:02 in2 Exp $ +# $Id$ use lib '/home/bbs/bin/'; use strict; use OurNet::FuzzyIndex; @@ -33,6 +33,7 @@ sub main $idx = OurNet::FuzzyIndex->new("$_.idx") if( !$Getopt::Std::opt_n ); build("/home/bbs/man/boards/".substr($_, 0, 1)."/$_", ''); + $db{_buildtime} = time(); untie %db; } } -- cgit v1.2.3 From 00ed55898539c02c4a4f6031d565c5625b591dc1 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sat, 13 Sep 2003 04:22:37 +0000 Subject: skip empty filename git-svn-id: http://opensvn.csie.org/pttbbs/trunk@1180 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/staticweb/manbuilder.pl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pttbbs/staticweb/manbuilder.pl b/pttbbs/staticweb/manbuilder.pl index c135920a..f3b18cf4 100755 --- a/pttbbs/staticweb/manbuilder.pl +++ b/pttbbs/staticweb/manbuilder.pl @@ -56,8 +56,8 @@ sub build($$) tie %bfh, 'BBSFileHeader', $basedir; foreach( 0..($bfh{num} - 1) ){ next if( $bfh{"$_.filemode"} & 32 ); # skip HIDDEN + next if( !($fn = $bfh{"$_.filename"}) ); # skip empty filename - $fn = $bfh{"$_.filename"}; if( $bfh{"$_.isdir"} ){ push @tdir, ["$doffset/$fn/", # 目錄結尾要加 / $db{"title-$doffset/$fn/"} = $bfh{"$_.title"}]; -- cgit v1.2.3 From 708f554f6522b5598af039b24260a9d041d9a01b Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sat, 13 Sep 2003 06:32:08 +0000 Subject: use 'mkdir -p' git-svn-id: http://opensvn.csie.org/pttbbs/trunk@1181 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/waterball.pl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pttbbs/util/waterball.pl b/pttbbs/util/waterball.pl index 651372fa..d3fcc343 100644 --- a/pttbbs/util/waterball.pl +++ b/pttbbs/util/waterball.pl @@ -1,4 +1,5 @@ #!/usr/bin/perl +# $Id$ use lib '/home/bbs/bin/'; use LocalVars; use Time::Local; @@ -17,7 +18,7 @@ foreach $fndes ( <$JOBSPOOL/water.des.*> ){ #des: userid, mailto, outmode next if( !$userid ); print "$userid, $mailto, $outmode\n"; `rm -Rf $TMP/water`; - `mkdir $TMP/water`; + `mkdir -p $TMP/water`; $fnsrc = $fndes; $fnsrc =~ s/\.des\./\.src\./; -- cgit v1.2.3 From 023d13b0a6fc4076671313704de085216d557cd7 Mon Sep 17 00:00:00 2001 From: victor <victor@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sat, 13 Sep 2003 13:43:05 +0000 Subject: fix bug - syntax error git-svn-id: http://opensvn.csie.org/pttbbs/trunk@1182 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/chc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pttbbs/mbbsd/chc.c b/pttbbs/mbbsd/chc.c index f63ae972..42abbe22 100644 --- a/pttbbs/mbbsd/chc.c +++ b/pttbbs/mbbsd/chc.c @@ -830,9 +830,9 @@ chc_init_play_func(chcusr_t *user1, chcusr_t *user2, play_func_t play_func[2]) static void chc_watch_request(int signo) { + chc_act_list *tmp; if (!(currstat & CHC)) return; - chc_act_list *tmp; for(tmp = act_list; tmp->next != NULL; tmp = tmp->next); tmp->next = (chc_act_list *)malloc(sizeof(chc_act_list)); tmp = tmp->next; -- cgit v1.2.3 From 9028ead17ad48ee93dc320c202a6fd1b52dc9890 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sun, 14 Sep 2003 09:10:46 +0000 Subject: security fix git-svn-id: http://opensvn.csie.org/pttbbs/trunk@1183 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/announce.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pttbbs/mbbsd/announce.c b/pttbbs/mbbsd/announce.c index ac001d28..a86c5577 100644 --- a/pttbbs/mbbsd/announce.c +++ b/pttbbs/mbbsd/announce.c @@ -874,7 +874,7 @@ a_menu(char *maintitle, char *path, int lastlevel) 須等該資料寫入 .DIR 內再 implement才有效率. */ if( !lastlevel && !HAS_PERM(PERM_SYSOP) && - !HAS_PERM(PERM_SYSSUBOP) && is_BM_cache(currbid) && + !HAS_PERM(PERM_SYSSUBOP) && !is_BM_cache(currbid) && dashd(fname) ) vmsg("只有板主才可以拷貝目錄唷!"); else -- cgit v1.2.3 From 2cb16683a65324e74db85da20e22b812692bd670 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sun, 14 Sep 2003 09:34:25 +0000 Subject: PERM_SYSSUBOP cound NOT copy dir of announce git-svn-id: http://opensvn.csie.org/pttbbs/trunk@1184 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/announce.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pttbbs/mbbsd/announce.c b/pttbbs/mbbsd/announce.c index a86c5577..c3a267a9 100644 --- a/pttbbs/mbbsd/announce.c +++ b/pttbbs/mbbsd/announce.c @@ -874,8 +874,7 @@ a_menu(char *maintitle, char *path, int lastlevel) 須等該資料寫入 .DIR 內再 implement才有效率. */ if( !lastlevel && !HAS_PERM(PERM_SYSOP) && - !HAS_PERM(PERM_SYSSUBOP) && !is_BM_cache(currbid) && - dashd(fname) ) + !is_BM_cache(currbid) && dashd(fname) ) vmsg("只有板主才可以拷貝目錄唷!"); else a_copyitem(fname, me.header[me.now - me.page].title, 0, 1); -- cgit v1.2.3 From 1e57ba40084658ea3e2293db3167b310db75983b Mon Sep 17 00:00:00 2001 From: victor <victor@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Mon, 15 Sep 2003 15:45:44 +0000 Subject: give a warning before giving money git-svn-id: http://opensvn.csie.org/pttbbs/trunk@1185 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/talk.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pttbbs/mbbsd/talk.c b/pttbbs/mbbsd/talk.c index 7abb595a..2a0a7fe6 100644 --- a/pttbbs/mbbsd/talk.c +++ b/pttbbs/mbbsd/talk.c @@ -2277,6 +2277,9 @@ userlist(void) clrtoeol(); if ((ch = atoi(genbuf)) <= 0 || ch <= give_tax(ch)) break; + sprintf(genbuf, "確定要給 %s %d Ptt 幣嗎? [N/y]", uentp->userid, ch); + if (getans(genbuf) != 'y') + break; reload_money(); if (ch > cuser.money) { -- cgit v1.2.3 From 12375ab9adc4c30c39143f4ed4c45560e4cdca7d Mon Sep 17 00:00:00 2001 From: victor <victor@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Tue, 16 Sep 2003 10:15:51 +0000 Subject: revert the disappered file git-svn-id: http://opensvn.csie.org/pttbbs/trunk@1186 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/sample/etc/chickens/n10 | 12 ++++++++++++ pttbbs/sample/etc/chickens/n11 | 12 ++++++++++++ pttbbs/sample/etc/chickens/n12 | 12 ++++++++++++ pttbbs/sample/etc/chickens/n13 | 13 ++++++++++++- pttbbs/sample/etc/chickens/n14 | 12 ++++++++++++ pttbbs/sample/etc/chickens/n15 | 12 ++++++++++++ pttbbs/sample/etc/chickens/n16 | 12 ++++++++++++ 7 files changed, 84 insertions(+), 1 deletion(-) diff --git a/pttbbs/sample/etc/chickens/n10 b/pttbbs/sample/etc/chickens/n10 index e69de29b..6bbb4100 100644 --- a/pttbbs/sample/etc/chickens/n10 +++ b/pttbbs/sample/etc/chickens/n10 @@ -0,0 +1,12 @@ + -------- ╱╲ ╱╲ + ------ ▕◢ █ ◣▏ + -------- █◤▄◥█ + -- ◥ ◣ > < ◢ ◤ + --- ◥ ◢◣" ▼ "◢◣ ◤ + ---- ◢█◥ J ◤ ▄ + ---- ▄ ◤ ◥◥█◤ + ---------- ▄▄▄ ◤ + -------- ◢◥█◤◣ + ------- ◣ ◤ ◥◢ + ------ █▌ █▌ + --- ◢ ◥ ◤ ◣ diff --git a/pttbbs/sample/etc/chickens/n11 b/pttbbs/sample/etc/chickens/n11 index e69de29b..939572c3 100644 --- a/pttbbs/sample/etc/chickens/n11 +++ b/pttbbs/sample/etc/chickens/n11 @@ -0,0 +1,12 @@ + ╱╲ ╱╲ + 幹 ▕◢ █ ◣▏ 幹 + █◤▄◥█ + 幹◥ ◣ ╲ ╱ ◢ ◤幹 + ◥ ◢◣" ▲ "◢◣ ◤ + 幹 ▄ ◥ J ◤ ▄ 幹 + ◥█◤◤ ◥◥█◤ + 幹 ◥ ▄▄▄ ◤ 幹 + ◢◥█◤◣ + 幹 ◣◤ ◥◢ 幹 + █▌ █▌ + 幹 ◢ ◥ ◤ ◣ 幹 diff --git a/pttbbs/sample/etc/chickens/n12 b/pttbbs/sample/etc/chickens/n12 index e69de29b..900740cf 100644 --- a/pttbbs/sample/etc/chickens/n12 +++ b/pttbbs/sample/etc/chickens/n12 @@ -0,0 +1,12 @@ + ╱╲ ╱╲ + ▕◢ █ ◣▏ + █◤▄◥█ + ◥█◣ • • ◢█◤ + ◥ ◢◣" • "◢◣ ◤ + ▄ ◥███◤ ▄ + ◥█◤◤ ◥◥█◤ + ◥ ▄▄▄ ◤ + ◢◥█◤◣ + ◣◤●◥◢ + █▌ █▌ + ◢ ◥ ◤ ◣ diff --git a/pttbbs/sample/etc/chickens/n13 b/pttbbs/sample/etc/chickens/n13 index 96197489..5fdba18f 100644 --- a/pttbbs/sample/etc/chickens/n13 +++ b/pttbbs/sample/etc/chickens/n13 @@ -1 +1,12 @@ - -- ◥ ◣ > < ◢ ◤ + ╱╲ ╱╲ + ▕◢ █ ◣▏ + █◤▄◥█ + ◥ ◣ ╲ ╱ ◢ ◤ + ◥ ◢◣" ︵ "◢◣ ◤╭─╮ + ▄ ◥ J ◤ █▌│●│ + ◥█◤◤ ◥ ◤ ╰─╯ + ◥ ▄▄▄ + ◢◥█◤◣ + ◣◤ ◥◢ + █▌ █▌ + ◢ ◥ ◤ ◣ diff --git a/pttbbs/sample/etc/chickens/n14 b/pttbbs/sample/etc/chickens/n14 index e69de29b..980f6117 100644 --- a/pttbbs/sample/etc/chickens/n14 +++ b/pttbbs/sample/etc/chickens/n14 @@ -0,0 +1,12 @@ + ╱╲ ╱╲ + ▕◢ █ ◣▏ + █◤▄◥█ + ◥ ◣ ╲ ╱ ◢ ◤ + ◥ ◢◣" 0 "◢◣ ◤╲│╱ + ◥  ◥ J ◤  ▌─○─ + █ ◤ ◥ ◤ ╱│╲ + ▄▄▄ + ◢ ◥█◤ ◣ + ◣◤ ◥◢ + █▌ █▌ + ◢ ◥ ◤ ◣ diff --git a/pttbbs/sample/etc/chickens/n15 b/pttbbs/sample/etc/chickens/n15 index e69de29b..9a46c040 100644 --- a/pttbbs/sample/etc/chickens/n15 +++ b/pttbbs/sample/etc/chickens/n15 @@ -0,0 +1,12 @@ + ◣◣▲◢◢ + ◥ ◣ ㄈ ◢ ◤ + ◥ ≡ ● ≡ ◤ + ◥█◣ ╱ ╲ ◢█◤ + ◥ ◢◣" ︵ "◢◣ ◤ + ◥███◤ + ◥█◤ ◥█◤ +  ▄▄▄  + ◢◥█◤◣ + ◣◤ ◥◢ + █▌ █▌ + ◢ ◥ ◤ ◣ diff --git a/pttbbs/sample/etc/chickens/n16 b/pttbbs/sample/etc/chickens/n16 index e69de29b..9f932fa5 100644 --- a/pttbbs/sample/etc/chickens/n16 +++ b/pttbbs/sample/etc/chickens/n16 @@ -0,0 +1,12 @@ + ╱╲ ╱╲ + ▕◢ █ ◣▏ +   █◤▄◥█   + ◥◥◣ ︵ ︵ ◢◤◤ + ◥ ◥◣" ▼ "◢◤ ◤ + ◢ J ◣ + ◤ ◥ + ▄▄▄ +  ◢◥█◤◣ + ◣◤ ◥◢ + █▌ █▌ + ◢ ◥ ◤ ◣ -- cgit v1.2.3 From 57999687e13560a7815459b082678675b256d563 Mon Sep 17 00:00:00 2001 From: victor <victor@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Fri, 19 Sep 2003 12:49:01 +0000 Subject: =?UTF-8?q?remove=20=E6=89=93=E8=AD=9C=20in=20userlist?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: http://opensvn.csie.org/pttbbs/trunk@1188 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/talk.c | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/pttbbs/mbbsd/talk.c b/pttbbs/mbbsd/talk.c index 2a0a7fe6..8e13029e 100644 --- a/pttbbs/mbbsd/talk.c +++ b/pttbbs/mbbsd/talk.c @@ -1357,13 +1357,6 @@ my_talk(userinfo_t * uin, int fri_stat, char defact) pressanykey(); } -static void -self_play(userinfo_t * uin, int fri_stat) -{ - if (getans("[象棋] 你確定要打譜嗎?[N/y]") == 'y') - chc(0, CHC_PERSONAL); -} - /* 選單式聊天介面 */ #define US_PICKUP 1234 #define US_RESORT 1233 @@ -2213,17 +2206,14 @@ userlist(void) case 't': if (HAS_PERM(PERM_LOGINOK)) { - move(1, 0); - clrtobot(); - move(3, 0); if (uentp->pid != currpid && - strcmp(uentp->userid, cuser.userid) != 0) { + strcmp(uentp->userid, cuser.userid) != 0) { + move(1, 0); + clrtobot(); + move(3, 0); my_talk(uentp, fri_stat, 0); + redrawall = redraw = 1; } - else{ - self_play(uentp, fri_stat); - } - redrawall = redraw = 1; } break; case 'K': -- cgit v1.2.3 From 0d059fad6da36762bfe1f18915409a5fb3125e15 Mon Sep 17 00:00:00 2001 From: victor <victor@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sat, 20 Sep 2003 06:55:31 +0000 Subject: talk.c : redraw friend.c: uident should be wall thanks akiecs.bbs@ptt2 git-svn-id: http://opensvn.csie.org/pttbbs/trunk@1189 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/friend.c | 2 +- pttbbs/mbbsd/talk.c | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/pttbbs/mbbsd/friend.c b/pttbbs/mbbsd/friend.c index 3f97ee71..8205686d 100644 --- a/pttbbs/mbbsd/friend.c +++ b/pttbbs/mbbsd/friend.c @@ -399,7 +399,7 @@ friend_edit(int type) dirty = 1; } else if (*uident == 'w' && count) { char wall[60]; - if (!getdata(0, 0, "群體水球:", uident, sizeof(wall), DOECHO)) + if (!getdata(0, 0, "群體水球:", wall, sizeof(wall), DOECHO)) continue; if (getdata(0, 0, "確定丟出群體水球? [Y]", line, 4, LCECHO) && *line == 'n') diff --git a/pttbbs/mbbsd/talk.c b/pttbbs/mbbsd/talk.c index 8e13029e..2d07abcf 100644 --- a/pttbbs/mbbsd/talk.c +++ b/pttbbs/mbbsd/talk.c @@ -2265,11 +2265,15 @@ userlist(void) if (getdata(b_lines - 1, 0, "[銀行轉帳]: ", genbuf, 7, LCECHO)) { clrtoeol(); - if ((ch = atoi(genbuf)) <= 0 || ch <= give_tax(ch)) + if ((ch = atoi(genbuf)) <= 0 || ch <= give_tax(ch)){ + redrawall = redraw = 1; break; + } sprintf(genbuf, "確定要給 %s %d Ptt 幣嗎? [N/y]", uentp->userid, ch); - if (getans(genbuf) != 'y') + if (getans(genbuf) != 'y'){ + redrawall = redraw = 1; break; + } reload_money(); if (ch > cuser.money) { -- cgit v1.2.3 From eb5e8080d889752a1ed59369c21c35ade005c7e5 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sun, 21 Sep 2003 16:34:04 +0000 Subject: add document git-svn-id: http://opensvn.csie.org/pttbbs/trunk@1190 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/staticweb/INSTALL | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 pttbbs/staticweb/INSTALL diff --git a/pttbbs/staticweb/INSTALL b/pttbbs/staticweb/INSTALL new file mode 100644 index 00000000..919d6bd4 --- /dev/null +++ b/pttbbs/staticweb/INSTALL @@ -0,0 +1,43 @@ +這篇文章介紹如何使用 web版精華區, 文章的版號及最後更動時間是: +$Id$ + +1.安裝好下列的東西, 我們並同時列上 FreeBSD ports內的目錄: + apache /usr/ports/www/apache13/ + perl /usr/ports/lang/perl5.8/ + mod_perl /usr/ports/www/mod_perl/ + + 以及下列的 module + Template /usr/ports/www/p5-Template-Toolkit/ + MD5 /usr/ports/security/p5-MD5/ + Data::Serializer /usr/ports/devel/p5-Data-Serializer/ + OurNet::FuzzyIndex (還沒有進 ports, 請用 cpan 裝) + +2. +須要三個目錄, 一個是放置 cgi程式的地方, 一個放置實際資料. 一個放置 +編譯過的 template , 其中放置編譯過的 template 目錄須要是 apache 可 +以寫入的. +將 pttbbs/staticweb/* 拷貝至放置 cgi程式的目錄內. +修改 /home/bbs/bin/LocalVars.pm , 將放置實際資料的目錄寫給 $MANDATA , +將放置編譯過 template 的目錄給 $MANCACHE. 這兩個請都使用絕對路徑. + +3. +使用 pttbbs/staticweb/manbuild.pl 來將當前的精華區建成資料庫. +usage: manbuild.pl [-n] [BoardName1/DB1 [BoardName2/DB2 [...]]] +其中 -n 表示不建立用來搜尋的索引檔, 後面請加要建立的看板名稱. +產生好後請將 *.db, *.idx移至 $MANDATA 中, 並且確認該檔案是 apache +可讀. + +4. +執行 + pttbbs/util/boardlist > boardlist.pm +再將 boardlist.pm 移入程式目錄. + +5. +設定 apache , 使用 mod_perl , 並開啟該目錄的 ExecCGI權限, 如: + <Directory "/home/bbs/web/cgi"> + Options ExecCGI + + # 下面兩行是使用 mod_perl 的. + AddHandler perl-script .pl + PerlHandler Apache::Registry + </Directory> -- cgit v1.2.3 -- cgit v1.2.3 From 1745fa28925b72f7d0e532230aeac5bc805f2db0 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sun, 21 Sep 2003 16:40:11 +0000 Subject: use Id git-svn-id: http://opensvn.csie.org/pttbbs/trunk@1192 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/README | 3 ++- pttbbs/blog/INSTALL | 4 ++-- pttbbs/docs/DONATE | 4 ++-- pttbbs/docs/FAQ | 3 ++- pttbbs/docs/INSTALL | 3 ++- pttbbs/staticweb/INSTALL | 2 +- 6 files changed, 11 insertions(+), 8 deletions(-) diff --git a/pttbbs/README b/pttbbs/README index 7825c087..a9281ad3 100644 --- a/pttbbs/README +++ b/pttbbs/README @@ -1,4 +1,5 @@ -$Id: README,v 1.3 2003/06/03 09:25:12 in2 Exp $ +文章的版號及最後編修時間是: +$Id$ 快速安裝請參考 docs/INSTALL 以及 docs/FAQ 詳細文件請見 docs/ diff --git a/pttbbs/blog/INSTALL b/pttbbs/blog/INSTALL index 64e60e8c..dfbfb3d0 100644 --- a/pttbbs/blog/INSTALL +++ b/pttbbs/blog/INSTALL @@ -1,5 +1,5 @@ -這篇文章在描述怎麼架設 PttBlog, 最後一次修正的時間為: -$Id: INSTALL,v 1.4 2003/07/06 03:58:43 in2 Exp $ +這篇文章在描述怎麼架設 PttBlog, 最後的編修及版號是: +$Id$ 請注意, PttBlog本來主要是設計給 Ptt2 站台使用, 目前正在開發階段, 並未接受嚴密的測試, 可能還缺少很多功能, 以及可能有許多的 bug. diff --git a/pttbbs/docs/DONATE b/pttbbs/docs/DONATE index 7b572441..a37c1d06 100644 --- a/pttbbs/docs/DONATE +++ b/pttbbs/docs/DONATE @@ -1,5 +1,5 @@ -這篇文章描述關於贊助 PttBBS . 最後一次修正的時間在: -$Id: DONATE,v 1.1 2003/06/03 08:51:25 in2 Exp $ +這篇文章描述關於贊助 PttBBS . 文章的版號及最後編修時間是: +$Id$ Donate to PttBBS! PttBBS 是免費自由軟體, 我們透過這套系統(正如您手上這一份), 在台大 diff --git a/pttbbs/docs/FAQ b/pttbbs/docs/FAQ index 41b5aae1..6b1ec820 100644 --- a/pttbbs/docs/FAQ +++ b/pttbbs/docs/FAQ @@ -1,4 +1,5 @@ -PttBBS FAQ: +這篇文章描述 PttBBS 中常被問到的問題及解決方式. 文章的版號及最後編修時間是: +$Id$ 1. PttBBS的討論區 2. 在 Linux底下出現 Makefile 錯誤. diff --git a/pttbbs/docs/INSTALL b/pttbbs/docs/INSTALL index ebaae2eb..8c953434 100644 --- a/pttbbs/docs/INSTALL +++ b/pttbbs/docs/INSTALL @@ -1,4 +1,5 @@ -底下是快速安裝的方法 +這篇文件說明快速安裝的方法, 文章的版號及最後編修時間是: +$Id$ ============== 以 root 的權限 diff --git a/pttbbs/staticweb/INSTALL b/pttbbs/staticweb/INSTALL index 919d6bd4..2eadd296 100644 --- a/pttbbs/staticweb/INSTALL +++ b/pttbbs/staticweb/INSTALL @@ -1,4 +1,4 @@ -這篇文章介紹如何使用 web版精華區, 文章的版號及最後更動時間是: +這篇文章介紹如何使用 web版精華區, 文章的版號及最後編修時間是: $Id$ 1.安裝好下列的東西, 我們並同時列上 FreeBSD ports內的目錄: -- cgit v1.2.3 From f22efb079e367e8430f5fdee444136c524b6d432 Mon Sep 17 00:00:00 2001 From: "(no author)" <(no author)@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Mon, 22 Sep 2003 03:40:29 +0000 Subject: git-svn-id: http://opensvn.csie.org/pttbbs/trunk@1193 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/include/common.h | 1 + pttbbs/include/pttstruct.h | 606 ++++++++++++++------------------------------- pttbbs/mbbsd/bbs.c | 91 +++++-- 3 files changed, 262 insertions(+), 436 deletions(-) diff --git a/pttbbs/include/common.h b/pttbbs/include/common.h index 18d377c2..786f13df 100644 --- a/pttbbs/include/common.h +++ b/pttbbs/include/common.h @@ -8,6 +8,7 @@ #define FN_PASSWD BBSHOME "/.PASSWDS" /* User records */ #define FN_USSONG "ussong" /* 點歌統計 */ #define FN_POST_NOTE "post.note" /* po文章備忘錄 */ +#define FN_POST_BID "post.bid" #define FN_APPLICATION "application" #define FN_MONEY "etc/money" #define FN_OVERRIDES "overrides" diff --git a/pttbbs/include/pttstruct.h b/pttbbs/include/pttstruct.h index 991b2154..786f13df 100644 --- a/pttbbs/include/pttstruct.h +++ b/pttbbs/include/pttstruct.h @@ -1,427 +1,189 @@ /* $Id$ */ -#ifndef INCLUDE_STRUCT_H -#define INCLUDE_STRUCT_H - -/* 小雞的資料 */ -typedef struct chicken_t { - char name[20]; - char type; /* 物種 */ - unsigned char tech[16]; /* 技能 */ - time_t birthday; /* 生日 */ - time_t lastvisit; /* 上次照顧時間 */ - int oo; /* 補品 */ - int food; /* 食物 */ - int medicine; /* 藥品 */ - int weight; /* 體重 */ - int clean; /* 乾淨 */ - int run; /* 敏捷度 */ - int attack; /* 攻擊力 */ - int book; /* 知識 */ - int happy; /* 快樂 */ - int satis; /* 滿意度 */ - int temperament; /* 氣質 */ - int tiredstrong; /* 疲勞度 */ - int sick; /* 病氣指數 */ - int hp; /* 血量 */ - int hp_max; /* 滿血量 */ - int mm; /* 法力 */ - int mm_max; /* 滿法力 */ - time_t cbirth; /* 實際計算用的生日 */ - int pad[2]; /* 留著以後用 */ -} chicken_t; - -#define IDLEN 12 /* Length of bid/uid */ -#define PASSLEN 14 /* Length of encrypted passwd field */ -#define REGLEN 38 /* Length of registration data */ - -typedef struct userec_t { - char userid[IDLEN + 1]; - char realname[20]; - char username[24]; - char passwd[PASSLEN]; - unsigned char uflag; - unsigned int userlevel; - unsigned short numlogins; - unsigned short numposts; - time_t firstlogin; - time_t lastlogin; - char lasthost[16]; - int money; - char remoteuser[3]; /* 保留 目前沒用到的 */ - char proverb; - char email[50]; - char address[50]; - char justify[REGLEN + 1]; - unsigned char month; - unsigned char day; - unsigned char year; - unsigned char sex; - unsigned char state; - unsigned char pager; - unsigned char invisible; - unsigned int exmailbox; - chicken_t mychicken; - time_t lastsong; - unsigned int loginview; - unsigned char channel; /* 動態看板 */ - unsigned short vl_count; /* ViolateLaw counter */ - unsigned short five_win; - unsigned short five_lose; - unsigned short five_tie; - unsigned short chc_win; - unsigned short chc_lose; - unsigned short chc_tie; - int mobile; - char mind[4]; - char ident[11]; - unsigned int uflag2; - unsigned char signature; - char pad[71]; -} userec_t; -/* these are flags in userec_t.uflag */ -#define PAGER_FLAG 0x4 /* true if pager was OFF last session */ -#define CLOAK_FLAG 0x8 /* true if cloak was ON last session */ -#define FRIEND_FLAG 0x10 /* true if show friends only */ -#define BRDSORT_FLAG 0x20 /* true if the boards sorted alphabetical */ -#define MOVIE_FLAG 0x40 /* true if show movie */ -#define COLOR_FLAG 0x80 /* true if the color mode open */ -#define MIND_FLAG 0x100 /* true if mind search mode open <-Heat*/ -/* these are flags in userec_t.uflag2 */ -#define WATER_MASK 000003 /* water mask */ -#define WATER_ORIG 0x0 -#define WATER_NEW 0x1 -#define WATER_OFO 0x2 -#define WATERMODE(mode) ((cuser.uflag2 & WATER_MASK) == mode) -#define FAVNOHILIGHT 0x10 /* false if hilight favorite */ -#define FAVNEW_FLAG 0x20 /* true if add new board into one's fav */ -#define FOREIGN 0x100 /* true if a foreign */ -#define LIVERIGHT 0x200 /* true if get "liveright" already */ - -#define BTLEN 48 /* Length of board title */ - -typedef struct boardheader_t { - char brdname[IDLEN + 1]; /* bid */ - char title[BTLEN + 1]; - char BM[IDLEN * 3 + 3]; /* BMs' userid, token '/' */ - unsigned int brdattr; /* board的屬性 */ - char pad[3]; /* 沒用到的 */ - time_t bupdate; /* note update time */ - char pad2[3]; /* 沒用到的 */ - unsigned char bvote; /* Vote flags */ - time_t vtime; /* Vote close time */ - unsigned int level; /* 可以看此板的權限 */ - int unused; /* 還沒用到 */ - int gid; /* 看板所屬的類別 ID */ - void *next[2]; /* 在同一個gid下一個看板 動態產生*/ - void *firstchild[2]; /* 屬於這個看板的第一個子看板 */ - void *parent; - int childcount; /* 有多少個child */ - int nuser; /* 多少人在這板 */ - char pad5[4]; /* original void *u */ - time_t endgamble; - char pad3[84]; -} boardheader_t; - -#define BRD_NOZAP 000000001 /* 不可zap */ -#define BRD_NOCOUNT 000000002 /* 不列入統計 */ -#define BRD_NOTRAN 000000004 /* 不轉信 */ -#define BRD_GROUPBOARD 000000010 /* 群組板 */ -#define BRD_HIDE 000000020 /* 隱藏板 (看板好友才可看) */ -#define BRD_POSTMASK 000000040 /* 限制發表或閱讀 */ -#define BRD_ANONYMOUS 000000100 /* 匿名板 */ -#define BRD_DEFAULTANONYMOUS 000000200 /* 預設匿名板 */ -#define BRD_BAD 000000400 /* 違法改進中看板 */ -#define BRD_VOTEBOARD 000001000 /* 連署機看板 */ -#define BRD_WARNEL 000002000 /* 連署機看板 */ -#define BRD_TOP 000004000 /* 熱門看板群組 */ -#define BRD_NORECOMMEND 000010000 /* 不可推薦 */ -#define BRD_BLOG 000020000 /* BLOG */ - -#define TTLEN 64 /* Length of title */ -#define FNLEN 33 /* Length of filename */ - -#define FHR_REFERENCE (1<<31) - -typedef struct fileheader_t { - char filename[FNLEN]; /* M.9876543210.A */ - char recommend; /* important level */ - char owner[IDLEN + 2]; /* uid[.] */ - char date[6]; /* [02/02] or space(5) */ - char title[TTLEN + 1]; - int money; /* rocker: if bit32 on ==> reference */ - unsigned char filemode; /* must be last field @ boards.c */ -} fileheader_t; - -#define FILE_LOCAL 0x1 /* local saved */ -#define FILE_READ 0x1 /* already read : mail only */ -#define FILE_MARKED 0x2 /* opus: 0x8 */ -#define FILE_DIGEST 0x4 /* digest */ -#define FILE_HOLD 0x8 /* holdmail for mail */ -#define FILE_SOLVED 0x10 /* problem solved, sysop only */ -#define FILE_HIDE 0x20 /* hild */ -#define FILE_BM 0x40 /* BM only */ -#define FILE_BOTH 0x80 /* both replay for mail and board */ -#define FILE_MULTI 0x100 /* multi send for mail */ - -#define STRLEN 80 /* Length of most string data */ - - -/* uhash is a userid->uid hash table -- jochang */ - -#define HASH_BITS 16 - -union xitem_t { - struct { /* bbs_item */ - char fdate[9]; /* [mm/dd/yy] */ - char editor[13]; /* user ID */ - char fname[31]; - } B; - struct { /* gopher_item */ - char path[81]; - char server[48]; - int port; - } G; -}; - -typedef struct { - char title[63]; - union xitem_t X; -} item_t; - -typedef struct { - item_t *item[MAX_ITEMS]; - char mtitle[STRLEN]; - char *path; - int num, page, now, level; -} gmenu_t; - -#define FAVMAX 1024 /* Max boards of Myfavorite */ -#define FAVGMAX 32 /* Max groups of Myfavorite */ -#define FAVGSLEN 8 /* Max Length of Description String */ - -typedef struct msgque_t { - pid_t pid; - char userid[IDLEN + 1]; - char last_call_in[80]; -} msgque_t; - -typedef struct userinfo_t { - int uid; /* Used to find user name in passwd file */ - pid_t pid; /* kill() to notify user of talk request */ - int sockaddr; /* ... */ - int destuid; /* talk uses this to identify who called */ - int destuip; /* dest index in utmpshm->uinfo[] */ - unsigned char active; /* When allocated this field is true */ - unsigned char invisible; /* Used by cloaking function in Xyz menu */ - unsigned char sockactive; /* Used to coordinate talk requests */ - unsigned int userlevel; - unsigned char mode; /* UL/DL, Talk Mode, Chat Mode, ... */ - unsigned char pager; /* pager toggle, YEA, or NA */ - unsigned char in_chat; /* for in_chat commands */ - unsigned char sig; /* signal type */ - char userid[IDLEN + 1]; - char chatid[11]; /* chat id, if in chat mode */ - char username[24]; - char from[27]; /* machine name the user called in from */ - int from_alias; - char birth; /* 是否是生日 Ptt*/ - char tty[11]; /* tty port */ - int friend[MAX_FRIEND]; - int friend_online[MAX_FRIEND];/* point到線上好友 utmpshm的位置 */ - /* 好友比較的cache 前兩個bit是狀態 */ - int reject[MAX_REJECT]; - int idoffset; /* shm id上的 offset */ - int lock; - int friendtotal; /* 好友比較的cache 大小 */ - unsigned char msgcount; - msgque_t msgs[MAX_MSGS]; - time_t uptime; - time_t lastact; /* 上次使用者動的時間 */ - unsigned int brc_id; - unsigned char lockmode; /* 不准 multi_login 玩的東西 */ - char turn; /* for gomo */ - char mateid[IDLEN + 1]; /* for gomo */ - unsigned short int five_win; - unsigned short int five_lose; - unsigned short int five_tie; - unsigned short int chc_win; - unsigned short int chc_lose; - unsigned short int chc_tie; - char mailalert; - char sex; - char color; - char mind[4]; -} userinfo_t; - -typedef struct water_t { - pid_t pid; - char userid[IDLEN + 1]; - int top, count; - msgque_t msg[MAX_REVIEW]; - userinfo_t *uin; // Ptt:這可以取代alive -} water_t; - -typedef struct { - fileheader_t *header; - char mtitle[STRLEN]; - char *path; - int num, page, now, level; -} menu_t; - -typedef struct onekey_t { /* Used to pass commands to the readmenu */ - int key; - int (*fptr)(); -} onekey_t; - -#define ANSILINELEN (511) /* Maximum Screen width in chars */ - -/* anti_crosspost */ -typedef struct crosspost_t { - int checksum[4]; /* 0 -> 'X' cross post 1-3 -> 簡查文章行 */ - int times; /* 第幾次 */ -} crosspost_t; - -#define SORT_BY_ID 0 -#define SORT_BY_CLASS 1 -#define SORT_BY_STAT 1 -#define SORT_BY_IDLE 2 -#define SORT_BY_FROM 3 -#define SORT_BY_FIVE 4 -#define SORT_BY_SEX 5 - -typedef struct keeploc_t { - char *key; - int top_ln; - int crs_ln; - struct keeploc_t *next; -} keeploc_t; - -#define USHM_SIZE (MAX_ACTIVE + 4) /* why+4? */ - -/* MAX_BMs is dirty hardcode 4 in mbbsd/cache.c:is_BM_cache() */ -#define MAX_BMs 4 /* for BMcache, 一個看板最多幾板主 */ - -typedef struct { - /* uhash */ - char userid[MAX_USERS][IDLEN + 1]; - int next_in_hash[MAX_USERS]; - int money[MAX_USERS]; - int hash_head[1 << HASH_BITS]; - int number; /* # of users total */ - int loaded; /* .PASSWD has been loaded? */ - - /* utmpshm */ - userinfo_t uinfo[USHM_SIZE]; - userinfo_t *sorted[2][8][USHM_SIZE]; - /* 第一維double buffer 由currsorted指向目前使用的 - 第二維sort type */ - int currsorted; - time_t UTMPuptime; - int UTMPnumber; - char UTMPneedsort; - char UTMPbusystate; - - /* brdshm */ - int BMcache[MAX_BOARD][MAX_BMs]; - boardheader_t bcache[MAX_BOARD]; - boardheader_t *bsorted[2][MAX_BOARD]; /* 0: by name 1: by class */ - fileheader_t dircache[MAX_BOARD][DIRCACHESIZE]; - time_t busystate_b[MAX_BOARD]; - int total[MAX_BOARD]; - int hbfl[MAX_BOARD][MAX_FRIEND + 1]; - time_t lastposttime[MAX_BOARD]; - time_t Buptime; - time_t Btouchtime; - int Bnumber; - int Bbusystate; - time_t close_vote_time; - - /* pttcache */ - char notes[MAX_MOVIE][200*11]; - char today_is[20]; - int n_notes[MAX_MOVIE_SECTION]; /* 一節中有幾個 看板 */ - int next_refresh[MAX_MOVIE_SECTION]; /* 下一次要refresh的 看板 */ - int max_film; - int max_history; - time_t Puptime; - time_t Ptouchtime; - int Pbusystate; - - int GLOBALVAR[10]; /* mbbsd間的 global variable - 用以做統計等資料 (非常態) */ - - union { - int v[256]; - struct { - int dymaxactive; /* 動態設定最大人數上限 */ - int toomanyusers; /* 超過人數上限不給進的個數 */ - int noonlineuser; /* 站上使用者不高亮度顯示 */ -#ifdef OUTTA_TIMER - time_t now; +#ifndef INCLUDE_COMMON_H +#define INCLUDE_COMMON_H + +#define STR_GUEST "guest" +#define DEFAULT_BOARD str_sysop + +#define FN_PASSWD BBSHOME "/.PASSWDS" /* User records */ +#define FN_USSONG "ussong" /* 點歌統計 */ +#define FN_POST_NOTE "post.note" /* po文章備忘錄 */ +#define FN_POST_BID "post.bid" +#define FN_APPLICATION "application" +#define FN_MONEY "etc/money" +#define FN_OVERRIDES "overrides" +#define FN_REJECT "reject" +#define FN_WATER "water" +#define FN_CANVOTE "can_vote" +#define FN_VISABLE "visable" +#define FN_USIES "usies" /* BBS log */ +#define FN_BOARD ".BRD" /* board list */ +#define FN_USEBOARD "usboard" /* 看板統計 */ +#define FN_NOTE_ANS "note.ans" +#define FN_TOPSONG "etc/topsong" +#define FN_OVERRIDES "overrides" +#define FN_TICKET "ticket" +#define FN_TICKET_END "ticket.end" +#define FN_TICKET_LOCK "ticket.end.lock" +#define FN_TICKET_ITEMS "ticket.items" +#define FN_TICKET_RECORD "ticket.data" +#define FN_TICKET_USER "ticket.user" +#define FN_TICKET_OUTCOME "ticket.outcome" +#define FN_TICKET_BRDLIST "boardlist" + +#define MSG_DEL_CANCEL "取消刪除" +#define MSG_SELECT_BOARD "\033[7m【 選擇看板 】\033[m\n" \ + "請輸入看板名稱(按空白鍵自動搜尋):" +#define MSG_CLOAKED "哈哈!我隱形了!看不到勒... :P" +#define MSG_UNCLOAK "我要重現江湖了...." +#define MSG_BIG_BOY "我是大帥哥! ^o^Y" +#define MSG_BIG_GIRL "世紀大美女 *^-^*" +#define MSG_LITTLE_BOY "我是底迪啦... =)" +#define MSG_LITTLE_GIRL "最可愛的美眉! :>" +#define MSG_MAN "麥當勞叔叔 (^O^)" +#define MSG_WOMAN "叫我小阿姨!! /:>" +#define MSG_PLANT "植物也有性別喔.." +#define MSG_MIME "礦物總沒性別了吧" +#define MSG_PASSWD "請輸入您的密碼: " +#define MSG_POSTER "\033[34;46m 文章選讀 "\ + "\033[31;47m (y)\033[30m回信 "\ + "\033[31m(=[]<>)\033[30m相關主題 "\ + "\033[31m(/?)\033[30m搜尋標題 "\ + "\033[31m(aA)\033[30m搜尋作者 "\ + "\033[31m(x)\033[30m轉錄 "\ + "\033[31m(V)\033[30m投票 \033[m" +#define MSG_SEPERATOR "\ +───────────────────────────────────────" + +#define MSG_CLOAKED "哈哈!我隱形了!看不到勒... :P" +#define MSG_UNCLOAK "我要重現江湖了...." + +#define MSG_WORKING "處理中,請稍候..." + +#define MSG_CANCEL "取消。" +#define MSG_USR_LEFT "User 已經離開了" +#define MSG_NOBODY "目前無人上線" + +#define MSG_DEL_OK "刪除完畢" +#define MSG_DEL_CANCEL "取消刪除" +#define MSG_DEL_ERROR "刪除錯誤" +#define MSG_DEL_NY "請確定刪除(Y/N)?[N] " + +#define MSG_FWD_OK "文章轉寄完成!" +#define MSG_FWD_ERR1 "轉寄失誤: system error" +#define MSG_FWD_ERR2 "轉寄失誤: address error" + +#define MSG_SURE_NY "請您確定(Y/N)?[N] " +#define MSG_SURE_YN "請您確定(Y/N)?[Y] " + +#define MSG_BID "請輸入看板名稱:" +#define MSG_UID "請輸入使用者代號:" +#define MSG_PASSWD "請輸入您的密碼: " + +#define MSG_BIG_BOY "我是大帥哥! ^o^Y" +#define MSG_BIG_GIRL "世紀大美女 *^-^*" +#define MSG_LITTLE_BOY "我是底迪啦... =)" +#define MSG_LITTLE_GIRL "最可愛的美眉! :>" +#define MSG_MAN "麥當勞叔叔 (^O^)" +#define MSG_WOMAN "叫我小阿姨!! /:>" +#define MSG_PLANT "植物也有性別喔.." +#define MSG_MIME "礦物總沒性別了吧" + +#define ERR_BOARD_OPEN ".BOARD 開啟錯誤" +#define ERR_BOARD_UPDATE ".BOARD 更新有誤" +#define ERR_PASSWD_OPEN ".PASSWDS 開啟錯誤" + +#define ERR_BID "你搞錯了啦!沒有這個板喔!" +#define ERR_UID "這裡沒有這個人啦!" +#define ERR_PASSWD "密碼不對喔!你有沒有冒用人家的名字啊?" +#define ERR_FILENAME "檔名不合法!" +#define MSG_MAILER \ +"\033[34;46m 鴻雁往返 \033[31;47m(R)\033[30m回信\033[31m(x)\033[30m轉達\ +\033[31m(y)\033[30m群組回信\033[31m(D)\033[30m刪除\ +\033[31m(c)\033[30m收入信件夾\033[31m(z)\033[30m信件夾 \033[31m[G]\033[30m繼續?\033[0m" +#define MSG_SHORTULIST "\033[7m\ +使用者代號 目前狀態 │使用者代號 目前狀態 │使用者代號 目前狀態 \033[0m" + + +#define STR_AUTHOR1 "作者:" +#define STR_AUTHOR2 "發信人:" +#define STR_POST1 "看板:" +#define STR_POST2 "站內:" + +/* Flags to getdata input function */ +#define NOECHO 0 +#define DOECHO 1 +#define LCECHO 2 + +#define YEA 1 /* Booleans (Yep, for true and false) */ +#define NA 0 + +/* 好友關係 */ +#define IRH 1 /* I reject him. */ +#define HRM 2 /* He reject me. */ +#define IBH 4 /* I am board friend of him. */ +#define IFH 8 /* I am friend of him. */ +#define HFM 16 /* He is friend of me. */ +#define ST_FRIEND (IBH | IFH | HFM) +#define ST_REJECT (IRH | HRM) + +/* 鍵盤設定 */ +#define KEY_TAB 9 +#define KEY_ESC 27 +#define KEY_UP 0x0101 +#define KEY_DOWN 0x0102 +#define KEY_RIGHT 0x0103 +#define KEY_LEFT 0x0104 +#define KEY_HOME 0x0201 +#define KEY_INS 0x0202 +#define KEY_DEL 0x0203 +#define KEY_END 0x0204 +#define KEY_PGUP 0x0205 +#define KEY_PGDN 0x0206 + +#define QCAST int (*)(const void *, const void *) +#define Ctrl(c) (c & 037) +#define chartoupper(c) ((c >= 'a' && c <= 'z') ? c+'A'-'a' : c) + +#define LEN_AUTHOR1 5 +#define LEN_AUTHOR2 7 + +/* ----------------------------------------------------- */ +/* 群組名單模式 Ptt */ +/* ----------------------------------------------------- */ +#define FRIEND_OVERRIDE 0 +#define FRIEND_REJECT 1 +#define FRIEND_ALOHA 2 +#define FRIEND_POST 3 +#define FRIEND_SPECIAL 4 +#define FRIEND_CANVOTE 5 +#define BOARD_WATER 6 +#define BOARD_VISABLE 7 + +#define LOCK_THIS 1 // lock這線不能重複玩 +#define LOCK_MULTI 2 // lock所有線不能重複玩 + +#define I_TIMEOUT (-2) /* Used for the getchar routine select call */ +#define I_OTHERDATA (-333) /* interface, (-3) will conflict with chinese */ + +#define CHE_O(c) ((c) >> 3) +#define CHE_P(c) ((c) & 7) +#define RTL(x) (((x) - 3) >> 1) +#define dim(x) (sizeof(x) / sizeof(x[0])) +#define LTR(x) ((x) * 2 + 3) +#define CHE(a, b) ((a) | ((b) << 3)) + +#define MAX_MODES 127 + +#ifndef MIN +#define MIN(a,b) (((a)<(b))?(a):(b)) +#endif +#ifndef MAX +#define MAX(a,b) (((a)>(b))?(a):(b)) #endif - int nWelcomes; - } e; - } GV2; - - /* fromcache */ - char domain[MAX_FROM][50]; - char replace[MAX_FROM][50]; - int top; - int max_user; - time_t max_time; - time_t Fuptime; - time_t Ftouchtime; - int Fbusystate; -} SHM_t; - -typedef struct { - unsigned char oldlen; /* previous line length */ - unsigned char len; /* current length of line */ - unsigned char mode; /* status of line, as far as update */ - unsigned char smod; /* start of modified data */ - unsigned char emod; /* end of modified data */ - unsigned char sso; /* start stand out */ - unsigned char eso; /* end stand out */ - unsigned char data[ANSILINELEN + 1]; -} screenline_t; - -typedef struct { - int r, c; -} rc_t; - -#define BRD_ROW 10 -#define BRD_COL 9 - -typedef int board_t[BRD_ROW][BRD_COL]; - -/* name.c 中運用的資料結構 */ -typedef struct word_t { - char *word; - struct word_t *next; -} word_t; - -typedef struct commands_t { - int (*cmdfunc)(); - int level; - char *desc; /* next/key/description */ -} commands_t; - -typedef struct MailQueue { - char filepath[FNLEN]; - char subject[STRLEN]; - time_t mailtime; - char sender[IDLEN + 1]; - char username[24]; - char rcpt[50]; - int method; - char *niamod; -} MailQueue; -enum {MQ_TEXT, MQ_UUENCODE, MQ_JUSTIFY}; +#define char_lower(c) ((c >= 'A' && c <= 'Z') ? c|32 : c) -typedef struct -{ - time_t chrono; - int recno; -} TagItem; +#define STR_CURSOR "●" +#define STR_UNCUR " " #endif diff --git a/pttbbs/mbbsd/bbs.c b/pttbbs/mbbsd/bbs.c index 85c894a6..82051438 100644 --- a/pttbbs/mbbsd/bbs.c +++ b/pttbbs/mbbsd/bbs.c @@ -448,8 +448,9 @@ do_allpost(fileheader_t *postfile, const char *fpath, const char *owner) } static int -do_general() +do_general(int isbid) { + bid_t bidinfo; fileheader_t postfile; char fpath[80], buf[80]; int aborted, defanony, ifuseanony; @@ -489,21 +490,51 @@ do_general() #endif #endif - setbfile(genbuf, currboard, FN_POST_NOTE); + if(!isbid) + setbfile(genbuf, currboard, FN_POST_NOTE); + else + setbfile(genbuf, currboard, FN_POST_BID); if (more(genbuf, NA) == -1) - more("etc/" FN_POST_NOTE, NA); - + { + if(!isbid) + more("etc/" FN_POST_NOTE, NA); + else + more("etc/" FN_POST_BID, NA); + } move(19, 0); - prints("發表文章於【\033[33m %s\033[m 】 \033[32m%s\033[m 看板\n\n", + prints("%s於【\033[33m %s\033[m 】 \033[32m%s\033[m 看板\n", + isbid?"公開招標":"發表文章", currboard, bp->title + 7); - + if(isbid) + { + prints("設定結標日期:"); + bidinfo.enddate = gettime(20, now+86400); + do + getdata_str(21,0,"底價:",buf, 8, LCECHO, "1"); + while((bidinfo.enddate=postfile.money=atoi(buf))<=0); + do + getdata_str(21,0, "每標至少增加多少:",buf, 5, LCECHO, "1"); + while((bidinfo.increment=atoi(buf))<=0); + getdata_str(22,0, + "付款方式: 1.Ptt幣 2.郵局或銀行轉帳 3.支票或電匯 4.郵局貨到付款 [1]:", + buf, 3, LCECHO,"1"); + bidinfo.payby=(buf[0]-'1'); + if(bidinfo.payby<0 ||bidinfo.payby>3)bidinfo.payby=0; + getdata_str(23,0, "運費(0:免運費或文中說明)[0]:", buf, 6, LCECHO, "0"); + bidinfo.shipping = atoi(buf); + if(bidinfo.shipping<0) bidinfo.shipping=0; + postfile.filemode |= FILE_BID ; + move(20,0); + clrtobot(); + } if (quote_file[0]) do_reply_title(20, currtitle); else { - getdata(21, 0, - "種類:1.問題 2.建議 3.討論 4.心得 5.閒聊 6.公告 7.情報 (1-7或不選)", + getdata(21, 0, + "種類:1.問題 2.建議 3.討論 4.心得 5.閒聊 6.公告 7.情報 (1-7或不選)", save_title, 3, LCECHO); + local_article = save_title[0] - '1'; if (local_article >= 0 && local_article <= 6) snprintf(save_title, sizeof(save_title), @@ -556,13 +587,18 @@ do_general() #endif /* 錢 */ aborted = (aborted > MAX_POST_MONEY * 2) ? MAX_POST_MONEY : aborted / 2; - postfile.money = aborted; + if(!isbid) + postfile.money = aborted; strlcpy(postfile.owner, owner, sizeof(postfile.owner)); strlcpy(postfile.title, save_title, sizeof(postfile.title)); if (islocal) /* local save */ postfile.filemode = FILE_LOCAL; setbdir(buf, currboard); + if(isbid) + { + append_record(buf, &postfile, sizeof(postfile)); + } if (append_record(buf, &postfile, sizeof(postfile)) != -1) { setbtotal(currbid); @@ -582,9 +618,14 @@ do_general() aborted = (aborted > MAX_POST_MONEY) ? MAX_POST_MONEY : aborted; #endif if (strcmp(currboard, "Test") && !ifuseanony) { - prints("這是您的第 %d 篇文章。 稿酬 %d 銀。", - ++cuser.numposts, aborted); - demoney(aborted); + prints("這是您的第 %d 篇文章。",++cuser.numposts); + if(!isbid) + { + prints(" 稿酬 %d 銀。",aborted); + demoney(aborted); + } + else + prints("招標文章沒有稿酬。"); passwd_update(usernum, &cuser); /* post 數 */ } else outs("測試信件不列入紀錄,敬請包涵。"); @@ -634,7 +675,18 @@ do_post() if (bp->brdattr & BRD_VOTEBOARD) return do_voteboard(); else if (!(bp->brdattr & BRD_GROUPBOARD)) - return do_general(); + return do_general(0); + touchdircache(currbid); + return 0; +} + +int +do_post_openbid() +{ + boardheader_t *bp; + bp = getbcache(currbid); + if (!bp->brdattr & BRD_VOTEBOARD) + return do_general(1); touchdircache(currbid); return 0; } @@ -1709,7 +1761,6 @@ static int b_post_note() { char buf[200], yn[3]; - if (currmode & MODE_BOARD) { setbfile(buf, currboard, FN_POST_NOTE); if (more(buf, NA) == -1) @@ -1719,6 +1770,17 @@ b_post_note() vedit(buf, NA, NULL); else unlink(buf); + + + setbfile(buf, currboard, FN_POST_BID); + if (more(buf, NA) == -1) + more("etc/" FN_POST_BID, NA); + getdata(b_lines - 2, 0, "是否要用自訂bid注意事項?", yn, sizeof(yn), LCECHO); + if (yn[0] == 'y') + vedit(buf, NA, NULL); + else + unlink(buf); + return FULLUPDATE; } return 0; @@ -2073,6 +2135,7 @@ struct onekey_t read_comms[] = { {'y', reply_post}, {'z', b_man}, {Ctrl('P'), do_post}, + {Ctrl('O'), do_post_openbid}, {Ctrl('W'), whereami}, {'\0', NULL} }; -- cgit v1.2.3 From 6ad48703f8fe89b59be05560a9d79402ddc615df Mon Sep 17 00:00:00 2001 From: "(no author)" <(no author)@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Mon, 22 Sep 2003 03:56:39 +0000 Subject: git-svn-id: http://opensvn.csie.org/pttbbs/trunk@1194 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/include/pttstruct.h | 617 +++++++++++++++++++++++++++++++-------------- 1 file changed, 433 insertions(+), 184 deletions(-) diff --git a/pttbbs/include/pttstruct.h b/pttbbs/include/pttstruct.h index 786f13df..41ff9b81 100644 --- a/pttbbs/include/pttstruct.h +++ b/pttbbs/include/pttstruct.h @@ -1,189 +1,438 @@ /* $Id$ */ -#ifndef INCLUDE_COMMON_H -#define INCLUDE_COMMON_H - -#define STR_GUEST "guest" -#define DEFAULT_BOARD str_sysop - -#define FN_PASSWD BBSHOME "/.PASSWDS" /* User records */ -#define FN_USSONG "ussong" /* 點歌統計 */ -#define FN_POST_NOTE "post.note" /* po文章備忘錄 */ -#define FN_POST_BID "post.bid" -#define FN_APPLICATION "application" -#define FN_MONEY "etc/money" -#define FN_OVERRIDES "overrides" -#define FN_REJECT "reject" -#define FN_WATER "water" -#define FN_CANVOTE "can_vote" -#define FN_VISABLE "visable" -#define FN_USIES "usies" /* BBS log */ -#define FN_BOARD ".BRD" /* board list */ -#define FN_USEBOARD "usboard" /* 看板統計 */ -#define FN_NOTE_ANS "note.ans" -#define FN_TOPSONG "etc/topsong" -#define FN_OVERRIDES "overrides" -#define FN_TICKET "ticket" -#define FN_TICKET_END "ticket.end" -#define FN_TICKET_LOCK "ticket.end.lock" -#define FN_TICKET_ITEMS "ticket.items" -#define FN_TICKET_RECORD "ticket.data" -#define FN_TICKET_USER "ticket.user" -#define FN_TICKET_OUTCOME "ticket.outcome" -#define FN_TICKET_BRDLIST "boardlist" - -#define MSG_DEL_CANCEL "取消刪除" -#define MSG_SELECT_BOARD "\033[7m【 選擇看板 】\033[m\n" \ - "請輸入看板名稱(按空白鍵自動搜尋):" -#define MSG_CLOAKED "哈哈!我隱形了!看不到勒... :P" -#define MSG_UNCLOAK "我要重現江湖了...." -#define MSG_BIG_BOY "我是大帥哥! ^o^Y" -#define MSG_BIG_GIRL "世紀大美女 *^-^*" -#define MSG_LITTLE_BOY "我是底迪啦... =)" -#define MSG_LITTLE_GIRL "最可愛的美眉! :>" -#define MSG_MAN "麥當勞叔叔 (^O^)" -#define MSG_WOMAN "叫我小阿姨!! /:>" -#define MSG_PLANT "植物也有性別喔.." -#define MSG_MIME "礦物總沒性別了吧" -#define MSG_PASSWD "請輸入您的密碼: " -#define MSG_POSTER "\033[34;46m 文章選讀 "\ - "\033[31;47m (y)\033[30m回信 "\ - "\033[31m(=[]<>)\033[30m相關主題 "\ - "\033[31m(/?)\033[30m搜尋標題 "\ - "\033[31m(aA)\033[30m搜尋作者 "\ - "\033[31m(x)\033[30m轉錄 "\ - "\033[31m(V)\033[30m投票 \033[m" -#define MSG_SEPERATOR "\ -───────────────────────────────────────" - -#define MSG_CLOAKED "哈哈!我隱形了!看不到勒... :P" -#define MSG_UNCLOAK "我要重現江湖了...." - -#define MSG_WORKING "處理中,請稍候..." - -#define MSG_CANCEL "取消。" -#define MSG_USR_LEFT "User 已經離開了" -#define MSG_NOBODY "目前無人上線" - -#define MSG_DEL_OK "刪除完畢" -#define MSG_DEL_CANCEL "取消刪除" -#define MSG_DEL_ERROR "刪除錯誤" -#define MSG_DEL_NY "請確定刪除(Y/N)?[N] " - -#define MSG_FWD_OK "文章轉寄完成!" -#define MSG_FWD_ERR1 "轉寄失誤: system error" -#define MSG_FWD_ERR2 "轉寄失誤: address error" - -#define MSG_SURE_NY "請您確定(Y/N)?[N] " -#define MSG_SURE_YN "請您確定(Y/N)?[Y] " - -#define MSG_BID "請輸入看板名稱:" -#define MSG_UID "請輸入使用者代號:" -#define MSG_PASSWD "請輸入您的密碼: " - -#define MSG_BIG_BOY "我是大帥哥! ^o^Y" -#define MSG_BIG_GIRL "世紀大美女 *^-^*" -#define MSG_LITTLE_BOY "我是底迪啦... =)" -#define MSG_LITTLE_GIRL "最可愛的美眉! :>" -#define MSG_MAN "麥當勞叔叔 (^O^)" -#define MSG_WOMAN "叫我小阿姨!! /:>" -#define MSG_PLANT "植物也有性別喔.." -#define MSG_MIME "礦物總沒性別了吧" - -#define ERR_BOARD_OPEN ".BOARD 開啟錯誤" -#define ERR_BOARD_UPDATE ".BOARD 更新有誤" -#define ERR_PASSWD_OPEN ".PASSWDS 開啟錯誤" - -#define ERR_BID "你搞錯了啦!沒有這個板喔!" -#define ERR_UID "這裡沒有這個人啦!" -#define ERR_PASSWD "密碼不對喔!你有沒有冒用人家的名字啊?" -#define ERR_FILENAME "檔名不合法!" -#define MSG_MAILER \ -"\033[34;46m 鴻雁往返 \033[31;47m(R)\033[30m回信\033[31m(x)\033[30m轉達\ -\033[31m(y)\033[30m群組回信\033[31m(D)\033[30m刪除\ -\033[31m(c)\033[30m收入信件夾\033[31m(z)\033[30m信件夾 \033[31m[G]\033[30m繼續?\033[0m" -#define MSG_SHORTULIST "\033[7m\ -使用者代號 目前狀態 │使用者代號 目前狀態 │使用者代號 目前狀態 \033[0m" - - -#define STR_AUTHOR1 "作者:" -#define STR_AUTHOR2 "發信人:" -#define STR_POST1 "看板:" -#define STR_POST2 "站內:" - -/* Flags to getdata input function */ -#define NOECHO 0 -#define DOECHO 1 -#define LCECHO 2 - -#define YEA 1 /* Booleans (Yep, for true and false) */ -#define NA 0 - -/* 好友關係 */ -#define IRH 1 /* I reject him. */ -#define HRM 2 /* He reject me. */ -#define IBH 4 /* I am board friend of him. */ -#define IFH 8 /* I am friend of him. */ -#define HFM 16 /* He is friend of me. */ -#define ST_FRIEND (IBH | IFH | HFM) -#define ST_REJECT (IRH | HRM) - -/* 鍵盤設定 */ -#define KEY_TAB 9 -#define KEY_ESC 27 -#define KEY_UP 0x0101 -#define KEY_DOWN 0x0102 -#define KEY_RIGHT 0x0103 -#define KEY_LEFT 0x0104 -#define KEY_HOME 0x0201 -#define KEY_INS 0x0202 -#define KEY_DEL 0x0203 -#define KEY_END 0x0204 -#define KEY_PGUP 0x0205 -#define KEY_PGDN 0x0206 - -#define QCAST int (*)(const void *, const void *) -#define Ctrl(c) (c & 037) -#define chartoupper(c) ((c >= 'a' && c <= 'z') ? c+'A'-'a' : c) - -#define LEN_AUTHOR1 5 -#define LEN_AUTHOR2 7 - -/* ----------------------------------------------------- */ -/* 群組名單模式 Ptt */ -/* ----------------------------------------------------- */ -#define FRIEND_OVERRIDE 0 -#define FRIEND_REJECT 1 -#define FRIEND_ALOHA 2 -#define FRIEND_POST 3 -#define FRIEND_SPECIAL 4 -#define FRIEND_CANVOTE 5 -#define BOARD_WATER 6 -#define BOARD_VISABLE 7 - -#define LOCK_THIS 1 // lock這線不能重複玩 -#define LOCK_MULTI 2 // lock所有線不能重複玩 - -#define I_TIMEOUT (-2) /* Used for the getchar routine select call */ -#define I_OTHERDATA (-333) /* interface, (-3) will conflict with chinese */ - -#define CHE_O(c) ((c) >> 3) -#define CHE_P(c) ((c) & 7) -#define RTL(x) (((x) - 3) >> 1) -#define dim(x) (sizeof(x) / sizeof(x[0])) -#define LTR(x) ((x) * 2 + 3) -#define CHE(a, b) ((a) | ((b) << 3)) - -#define MAX_MODES 127 - -#ifndef MIN -#define MIN(a,b) (((a)<(b))?(a):(b)) -#endif -#ifndef MAX -#define MAX(a,b) (((a)>(b))?(a):(b)) +#ifndef INCLUDE_STRUCT_H +#define INCLUDE_STRUCT_H + +#define IDLEN 12 /* Length of bid/uid */ +typedef struct bid_t { + int high; + int buyitnow; + int increment; + char userid[IDLEN + 1]; + time_t enddate; + int payby; /* 1 cash 2 check or mail 4 wire 8 credit 16 postoffice */ + int shipping; +}bid_t; + +/* 小雞的資料 */ +typedef struct chicken_t { + char name[20]; + char type; /* 物種 */ + unsigned char tech[16]; /* 技能 */ + time_t birthday; /* 生日 */ + time_t lastvisit; /* 上次照顧時間 */ + int oo; /* 補品 */ + int food; /* 食物 */ + int medicine; /* 藥品 */ + int weight; /* 體重 */ + int clean; /* 乾淨 */ + int run; /* 敏捷度 */ + int attack; /* 攻擊力 */ + int book; /* 知識 */ + int happy; /* 快樂 */ + int satis; /* 滿意度 */ + int temperament; /* 氣質 */ + int tiredstrong; /* 疲勞度 */ + int sick; /* 病氣指數 */ + int hp; /* 血量 */ + int hp_max; /* 滿血量 */ + int mm; /* 法力 */ + int mm_max; /* 滿法力 */ + time_t cbirth; /* 實際計算用的生日 */ + int pad[2]; /* 留著以後用 */ +} chicken_t; + +#define PASSLEN 14 /* Length of encrypted passwd field */ +#define REGLEN 38 /* Length of registration data */ + +typedef struct userec_t { + char userid[IDLEN + 1]; + char realname[20]; + char username[24]; + char passwd[PASSLEN]; + unsigned char uflag; + unsigned int userlevel; + unsigned short numlogins; + unsigned short numposts; + time_t firstlogin; + time_t lastlogin; + char lasthost[16]; + int money; + char remoteuser[3]; /* 保留 目前沒用到的 */ + char proverb; + char email[50]; + char address[50]; + char justify[REGLEN + 1]; + unsigned char month; + unsigned char day; + unsigned char year; + unsigned char sex; + unsigned char state; + unsigned char pager; + unsigned char invisible; + unsigned int exmailbox; + chicken_t mychicken; + time_t lastsong; + unsigned int loginview; + unsigned char channel; /* 動態看板 */ + unsigned short vl_count; /* ViolateLaw counter */ + unsigned short five_win; + unsigned short five_lose; + unsigned short five_tie; + unsigned short chc_win; + unsigned short chc_lose; + unsigned short chc_tie; + int mobile; + char mind[4]; + char ident[11]; + unsigned int uflag2; + unsigned char signature; + char pad[71]; +} userec_t; +/* these are flags in userec_t.uflag */ +#define PAGER_FLAG 0x4 /* true if pager was OFF last session */ +#define CLOAK_FLAG 0x8 /* true if cloak was ON last session */ +#define FRIEND_FLAG 0x10 /* true if show friends only */ +#define BRDSORT_FLAG 0x20 /* true if the boards sorted alphabetical */ +#define MOVIE_FLAG 0x40 /* true if show movie */ +#define COLOR_FLAG 0x80 /* true if the color mode open */ +#define MIND_FLAG 0x100 /* true if mind search mode open <-Heat*/ +/* these are flags in userec_t.uflag2 */ +#define WATER_MASK 000003 /* water mask */ +#define WATER_ORIG 0x0 +#define WATER_NEW 0x1 +#define WATER_OFO 0x2 +#define WATERMODE(mode) ((cuser.uflag2 & WATER_MASK) == mode) +#define FAVNOHILIGHT 0x10 /* false if hilight favorite */ +#define FAVNEW_FLAG 0x20 /* true if add new board into one's fav */ +#define FOREIGN 0x100 /* true if a foreign */ +#define LIVERIGHT 0x200 /* true if get "liveright" already */ + +#define BTLEN 48 /* Length of board title */ + +typedef struct boardheader_t { + char brdname[IDLEN + 1]; /* bid */ + char title[BTLEN + 1]; + char BM[IDLEN * 3 + 3]; /* BMs' userid, token '/' */ + unsigned int brdattr; /* board的屬性 */ + char pad[3]; /* 沒用到的 */ + time_t bupdate; /* note update time */ + char pad2[3]; /* 沒用到的 */ + unsigned char bvote; /* Vote flags */ + time_t vtime; /* Vote close time */ + unsigned int level; /* 可以看此板的權限 */ + int unused; /* 還沒用到 */ + int gid; /* 看板所屬的類別 ID */ + void *next[2]; /* 在同一個gid下一個看板 動態產生*/ + void *firstchild[2]; /* 屬於這個看板的第一個子看板 */ + void *parent; + int childcount; /* 有多少個child */ + int nuser; /* 多少人在這板 */ + char pad5[4]; /* original void *u */ + time_t endgamble; + char pad3[84]; +} boardheader_t; + +#define BRD_NOZAP 000000001 /* 不可zap */ +#define BRD_NOCOUNT 000000002 /* 不列入統計 */ +#define BRD_NOTRAN 000000004 /* 不轉信 */ +#define BRD_GROUPBOARD 000000010 /* 群組板 */ +#define BRD_HIDE 000000020 /* 隱藏板 (看板好友才可看) */ +#define BRD_POSTMASK 000000040 /* 限制發表或閱讀 */ +#define BRD_ANONYMOUS 000000100 /* 匿名板 */ +#define BRD_DEFAULTANONYMOUS 000000200 /* 預設匿名板 */ +#define BRD_BAD 000000400 /* 違法改進中看板 */ +#define BRD_VOTEBOARD 000001000 /* 連署機看板 */ +#define BRD_WARNEL 000002000 /* 連署機看板 */ +#define BRD_TOP 000004000 /* 熱門看板群組 */ +#define BRD_NORECOMMEND 000010000 /* 不可推薦 */ +#define BRD_BLOG 000020000 /* BLOG */ + +#define TTLEN 64 /* Length of title */ +#define FNLEN 33 /* Length of filename */ + +#define FHR_REFERENCE (1<<31) + +typedef struct fileheader_t { + char filename[FNLEN]; /* M.9876543210.A */ + char recommend; /* important level */ + char owner[IDLEN + 2]; /* uid[.] */ + char date[6]; /* [02/02] or space(5) */ + char title[TTLEN + 1]; + int money; /* rocker: if bit32 on ==> reference */ + unsigned char filemode; /* must be last field @ boards.c */ +} fileheader_t; + +#define FILE_LOCAL 0x1 /* local saved */ +#define FILE_READ 0x1 /* already read : mail only */ +#define FILE_MARKED 0x2 /* opus: 0x8 */ +#define FILE_DIGEST 0x4 /* digest */ +#define FILE_HOLD 0x8 /* holdmail for mail */ +#define FILE_SOLVED 0x10 /* problem solved, sysop only */ +#define FILE_HIDE 0x20 /* hild */ +#define FILE_BM 0x40 /* BM only */ +#define FILE_BOTH 0x80 /* both replay for mail and board */ +#define FILE_MULTI 0x100 /* multi send for mail */ +#define FILE_BID 0x200 /* for bid */ + +#define STRLEN 80 /* Length of most string data */ + + +/* uhash is a userid->uid hash table -- jochang */ + +#define HASH_BITS 16 + +union xitem_t { + struct { /* bbs_item */ + char fdate[9]; /* [mm/dd/yy] */ + char editor[13]; /* user ID */ + char fname[31]; + } B; + struct { /* gopher_item */ + char path[81]; + char server[48]; + int port; + } G; +}; + +typedef struct { + char title[63]; + union xitem_t X; +} item_t; + +typedef struct { + item_t *item[MAX_ITEMS]; + char mtitle[STRLEN]; + char *path; + int num, page, now, level; +} gmenu_t; + +#define FAVMAX 1024 /* Max boards of Myfavorite */ +#define FAVGMAX 32 /* Max groups of Myfavorite */ +#define FAVGSLEN 8 /* Max Length of Description String */ + +typedef struct msgque_t { + pid_t pid; + char userid[IDLEN + 1]; + char last_call_in[80]; +} msgque_t; + +typedef struct userinfo_t { + int uid; /* Used to find user name in passwd file */ + pid_t pid; /* kill() to notify user of talk request */ + int sockaddr; /* ... */ + int destuid; /* talk uses this to identify who called */ + int destuip; /* dest index in utmpshm->uinfo[] */ + unsigned char active; /* When allocated this field is true */ + unsigned char invisible; /* Used by cloaking function in Xyz menu */ + unsigned char sockactive; /* Used to coordinate talk requests */ + unsigned int userlevel; + unsigned char mode; /* UL/DL, Talk Mode, Chat Mode, ... */ + unsigned char pager; /* pager toggle, YEA, or NA */ + unsigned char in_chat; /* for in_chat commands */ + unsigned char sig; /* signal type */ + char userid[IDLEN + 1]; + char chatid[11]; /* chat id, if in chat mode */ + char username[24]; + char from[27]; /* machine name the user called in from */ + int from_alias; + char birth; /* 是否是生日 Ptt*/ + char tty[11]; /* tty port */ + int friend[MAX_FRIEND]; + int friend_online[MAX_FRIEND];/* point到線上好友 utmpshm的位置 */ + /* 好友比較的cache 前兩個bit是狀態 */ + int reject[MAX_REJECT]; + int idoffset; /* shm id上的 offset */ + int lock; + int friendtotal; /* 好友比較的cache 大小 */ + unsigned char msgcount; + msgque_t msgs[MAX_MSGS]; + time_t uptime; + time_t lastact; /* 上次使用者動的時間 */ + unsigned int brc_id; + unsigned char lockmode; /* 不准 multi_login 玩的東西 */ + char turn; /* for gomo */ + char mateid[IDLEN + 1]; /* for gomo */ + unsigned short int five_win; + unsigned short int five_lose; + unsigned short int five_tie; + unsigned short int chc_win; + unsigned short int chc_lose; + unsigned short int chc_tie; + char mailalert; + char sex; + char color; + char mind[4]; +} userinfo_t; + +typedef struct water_t { + pid_t pid; + char userid[IDLEN + 1]; + int top, count; + msgque_t msg[MAX_REVIEW]; + userinfo_t *uin; // Ptt:這可以取代alive +} water_t; + +typedef struct { + fileheader_t *header; + char mtitle[STRLEN]; + char *path; + int num, page, now, level; +} menu_t; + +typedef struct onekey_t { /* Used to pass commands to the readmenu */ + int key; + int (*fptr)(); +} onekey_t; + +#define ANSILINELEN (511) /* Maximum Screen width in chars */ + +/* anti_crosspost */ +typedef struct crosspost_t { + int checksum[4]; /* 0 -> 'X' cross post 1-3 -> 簡查文章行 */ + int times; /* 第幾次 */ +} crosspost_t; + +#define SORT_BY_ID 0 +#define SORT_BY_CLASS 1 +#define SORT_BY_STAT 1 +#define SORT_BY_IDLE 2 +#define SORT_BY_FROM 3 +#define SORT_BY_FIVE 4 +#define SORT_BY_SEX 5 + +typedef struct keeploc_t { + char *key; + int top_ln; + int crs_ln; + struct keeploc_t *next; +} keeploc_t; + +#define USHM_SIZE (MAX_ACTIVE + 4) /* why+4? */ + +/* MAX_BMs is dirty hardcode 4 in mbbsd/cache.c:is_BM_cache() */ +#define MAX_BMs 4 /* for BMcache, 一個看板最多幾板主 */ + +typedef struct { + /* uhash */ + char userid[MAX_USERS][IDLEN + 1]; + int next_in_hash[MAX_USERS]; + int money[MAX_USERS]; + int hash_head[1 << HASH_BITS]; + int number; /* # of users total */ + int loaded; /* .PASSWD has been loaded? */ + + /* utmpshm */ + userinfo_t uinfo[USHM_SIZE]; + userinfo_t *sorted[2][8][USHM_SIZE]; + /* 第一維double buffer 由currsorted指向目前使用的 + 第二維sort type */ + int currsorted; + time_t UTMPuptime; + int UTMPnumber; + char UTMPneedsort; + char UTMPbusystate; + + /* brdshm */ + int BMcache[MAX_BOARD][MAX_BMs]; + boardheader_t bcache[MAX_BOARD]; + boardheader_t *bsorted[2][MAX_BOARD]; /* 0: by name 1: by class */ + fileheader_t dircache[MAX_BOARD][DIRCACHESIZE]; + time_t busystate_b[MAX_BOARD]; + int total[MAX_BOARD]; + int hbfl[MAX_BOARD][MAX_FRIEND + 1]; + time_t lastposttime[MAX_BOARD]; + time_t Buptime; + time_t Btouchtime; + int Bnumber; + int Bbusystate; + time_t close_vote_time; + + /* pttcache */ + char notes[MAX_MOVIE][200*11]; + char today_is[20]; + int n_notes[MAX_MOVIE_SECTION]; /* 一節中有幾個 看板 */ + int next_refresh[MAX_MOVIE_SECTION]; /* 下一次要refresh的 看板 */ + int max_film; + int max_history; + time_t Puptime; + time_t Ptouchtime; + int Pbusystate; + + int GLOBALVAR[10]; /* mbbsd間的 global variable + 用以做統計等資料 (非常態) */ + + union { + int v[256]; + struct { + int dymaxactive; /* 動態設定最大人數上限 */ + int toomanyusers; /* 超過人數上限不給進的個數 */ + int noonlineuser; /* 站上使用者不高亮度顯示 */ +#ifdef OUTTA_TIMER + time_t now; #endif + int nWelcomes; + } e; + } GV2; + + /* fromcache */ + char domain[MAX_FROM][50]; + char replace[MAX_FROM][50]; + int top; + int max_user; + time_t max_time; + time_t Fuptime; + time_t Ftouchtime; + int Fbusystate; +} SHM_t; + +typedef struct { + unsigned char oldlen; /* previous line length */ + unsigned char len; /* current length of line */ + unsigned char mode; /* status of line, as far as update */ + unsigned char smod; /* start of modified data */ + unsigned char emod; /* end of modified data */ + unsigned char sso; /* start stand out */ + unsigned char eso; /* end stand out */ + unsigned char data[ANSILINELEN + 1]; +} screenline_t; + +typedef struct { + int r, c; +} rc_t; + +#define BRD_ROW 10 +#define BRD_COL 9 + +typedef int board_t[BRD_ROW][BRD_COL]; + +/* name.c 中運用的資料結構 */ +typedef struct word_t { + char *word; + struct word_t *next; +} word_t; + +typedef struct commands_t { + int (*cmdfunc)(); + int level; + char *desc; /* next/key/description */ +} commands_t; + +typedef struct MailQueue { + char filepath[FNLEN]; + char subject[STRLEN]; + time_t mailtime; + char sender[IDLEN + 1]; + char username[24]; + char rcpt[50]; + int method; + char *niamod; +} MailQueue; -#define char_lower(c) ((c >= 'A' && c <= 'Z') ? c|32 : c) +enum {MQ_TEXT, MQ_UUENCODE, MQ_JUSTIFY}; -#define STR_CURSOR "●" -#define STR_UNCUR " " +typedef struct +{ + time_t chrono; + int recno; +} TagItem; #endif -- cgit v1.2.3 From 026c8ace12b7c7db676e91cba0062387e6d30c3b Mon Sep 17 00:00:00 2001 From: "(no author)" <(no author)@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Mon, 22 Sep 2003 07:51:16 +0000 Subject: git-svn-id: http://opensvn.csie.org/pttbbs/trunk@1195 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/include/proto.h | 2 +- pttbbs/include/pttstruct.h | 3 +- pttbbs/mbbsd/bbs.c | 221 ++++++++++++++++++++++++++++++++++++--------- pttbbs/mbbsd/stuff.c | 13 ++- 4 files changed, 187 insertions(+), 52 deletions(-) diff --git a/pttbbs/include/proto.h b/pttbbs/include/proto.h index d1e51a48..a072c5d9 100644 --- a/pttbbs/include/proto.h +++ b/pttbbs/include/proto.h @@ -401,7 +401,7 @@ void initscr(); void Jaky_outs(char *str, int line); /* stuff */ -time_t gettime(int line, time_t dt); +time_t gettime(int line, time_t dt, char* head); void setcalfile(char *buf, char *userid); void stand_title(char *title); void pressanykey(); diff --git a/pttbbs/include/pttstruct.h b/pttbbs/include/pttstruct.h index 41ff9b81..f14317e7 100644 --- a/pttbbs/include/pttstruct.h +++ b/pttbbs/include/pttstruct.h @@ -6,6 +6,7 @@ typedef struct bid_t { int high; int buyitnow; + int usermax; int increment; char userid[IDLEN + 1]; time_t enddate; @@ -172,7 +173,7 @@ typedef struct fileheader_t { #define FILE_BM 0x40 /* BM only */ #define FILE_BOTH 0x80 /* both replay for mail and board */ #define FILE_MULTI 0x100 /* multi send for mail */ -#define FILE_BID 0x200 /* for bid */ +#define FILE_BID 0x20 /* for bid */ #define STRLEN 80 /* Length of most string data */ diff --git a/pttbbs/mbbsd/bbs.c b/pttbbs/mbbsd/bbs.c index 82051438..b08db231 100644 --- a/pttbbs/mbbsd/bbs.c +++ b/pttbbs/mbbsd/bbs.c @@ -146,12 +146,9 @@ static void readdoent(int num, fileheader_t * ent) { int type; - char *mark, *title, color, special = 0, isonline = 0; + char *mark, *title, color, special = 0, isonline = 0, recom[3]; userinfo_t *uentp; - if (ent->recommend > 9 || ent->recommend < 0) - ent->recommend = 0; -//Ptt:暫時 - type = brc_unread(ent->filename, brc_num, brc_list) ? '+' : ' '; + type = brc_unread(ent->filename, brc_num, brc_list) ? '+' : ' '; if ((currmode & MODE_BOARD) && (ent->filemode & FILE_DIGEST)) type = (type == ' ') ? '*' : '#'; @@ -166,13 +163,15 @@ readdoent(int num, fileheader_t * ent) type = 's'; } title = subject(mark = ent->title); - if (title == mark) + if (ent->filemode & FILE_BID) + color = '1', mark = "B:"; + else if (title == mark) color = '1', mark = "□"; else color = '3', mark = "R:"; - if (title[47]) - strlcpy(title + 44, " …", sizeof(title) - 44); /* 把多餘的 string 砍掉 */ + if (title[45]) + strlcpy(title + 42, " …", sizeof(title) - 42); /* 把多餘的 string 砍掉 */ if (!strncmp(title, "[公告]", 6)) special = 1; @@ -186,14 +185,19 @@ readdoent(int num, fileheader_t * ent) (uentp = search_ulist(uid)) && isvisible(currutmp, uentp)) isonline = 1; #endif + if(ent->recommend>99) + strcpy(recom,"--"); + else if(ent->recommend>0) + sprintf(recom,"%2d",ent->recommend); + else strcpy(recom," "); prints( #ifdef COLORDATE - "%6d %c\033[1;32m%c\033[%dm%-6s\033[m\033[%dm%-13.12s", + "%6d %c\033[1;32m%2.2s\033[%dm%-6s\033[m\033[%dm%-13.12s", #else - "%6d %c\033[1;32m%c\033[m%-6s\033[%dm%-13.12s", + "%6d %c\033[1;32m%2.2s\033[m%-6s\033[%dm%-13.12s", #endif - num, type, ent->recommend ? ent->recommend + '0' : ' ', + num, type, recom, #ifdef COLORDATE (ent->date[3] + ent->date[4]) % 7 + 31, #endif @@ -508,14 +512,17 @@ do_general(int isbid) currboard, bp->title + 7); if(isbid) { - prints("設定結標日期:"); - bidinfo.enddate = gettime(20, now+86400); + memset(&bidinfo,0,sizeof(bidinfo)); + bidinfo.enddate = gettime(20, now+86400,"結束標案於"); do getdata_str(21,0,"底價:",buf, 8, LCECHO, "1"); - while((bidinfo.enddate=postfile.money=atoi(buf))<=0); + while((bidinfo.high=postfile.money=atoi(buf))<=0); do - getdata_str(21,0, "每標至少增加多少:",buf, 5, LCECHO, "1"); + getdata_str(21,20, "每標至少增加多少:",buf, 5, LCECHO, "1"); while((bidinfo.increment=atoi(buf))<=0); + getdata(21,44, "直接購買價(可不設):",buf, 5, LCECHO); + bidinfo.buyitnow=atoi(buf); + getdata_str(22,0, "付款方式: 1.Ptt幣 2.郵局或銀行轉帳 3.支票或電匯 4.郵局貨到付款 [1]:", buf, 3, LCECHO,"1"); @@ -524,23 +531,25 @@ do_general(int isbid) getdata_str(23,0, "運費(0:免運費或文中說明)[0]:", buf, 6, LCECHO, "0"); bidinfo.shipping = atoi(buf); if(bidinfo.shipping<0) bidinfo.shipping=0; - postfile.filemode |= FILE_BID ; move(20,0); clrtobot(); } if (quote_file[0]) do_reply_title(20, currtitle); else { - getdata(21, 0, + if(!isbid) + { + getdata(21, 0, "種類:1.問題 2.建議 3.討論 4.心得 5.閒聊 6.公告 7.情報 (1-7或不選)", save_title, 3, LCECHO); - local_article = save_title[0] - '1'; - if (local_article >= 0 && local_article <= 6) + local_article = save_title[0] - '1'; + if (local_article >= 0 && local_article <= 6) snprintf(save_title, sizeof(save_title), "[%s] ", ctype[local_article]); - else + else save_title[0] = '\0'; + } getdata_buf(22, 0, "標題:", save_title, TTLEN, DOECHO); strip_ansi(save_title, save_title, 0); } @@ -592,12 +601,14 @@ do_general(int isbid) strlcpy(postfile.owner, owner, sizeof(postfile.owner)); strlcpy(postfile.title, save_title, sizeof(postfile.title)); if (islocal) /* local save */ - postfile.filemode = FILE_LOCAL; + postfile.filemode |= FILE_LOCAL; setbdir(buf, currboard); if(isbid) { - append_record(buf, &postfile, sizeof(postfile)); + sprintf(genbuf, "%s.bid", fpath); + append_record(genbuf,(void*) &bidinfo, sizeof(bidinfo)); + postfile.filemode |= FILE_BID ; } if (append_record(buf, &postfile, sizeof(postfile)) != -1) { setbtotal(currbid); @@ -619,7 +630,7 @@ do_general(int isbid) #endif if (strcmp(currboard, "Test") && !ifuseanony) { prints("這是您的第 %d 篇文章。",++cuser.numposts); - if(!isbid) + if(!(postfile.filemode&FILE_BID)) { prints(" 稿酬 %d 銀。",aborted); demoney(aborted); @@ -652,7 +663,7 @@ do_general(int isbid) strlcpy(postfile.owner, cuser.userid, sizeof(postfile.owner)); strlcpy(postfile.title, save_title, sizeof(postfile.title)); - postfile.filemode = FILE_BOTH; /* both-reply flag */ + postfile.filemode |= FILE_BOTH; /* both-reply flag */ sethomedir(genbuf, quote_user); if (append_record(genbuf, &postfile, sizeof(postfile)) == -1) msg = err_uid; @@ -685,7 +696,7 @@ do_post_openbid() { boardheader_t *bp; bp = getbcache(currbid); - if (!bp->brdattr & BRD_VOTEBOARD) + if (!(bp->brdattr & BRD_VOTEBOARD)) return do_general(1); touchdircache(currbid); return 0; @@ -1195,7 +1206,7 @@ hold_gamble(int ent, fileheader_t * fhdr, char *direct) } while (i < 10 || i > 10000); fprintf(fp, "%d\n", i); if (!getdata(3, 0, "設定自動封盤時間?(Y/n)", yn, 3, LCECHO) || yn[0] != 'n') { - bp->endgamble = gettime(4, now); + bp->endgamble = gettime(4, now, "封盤於"); substitute_record(fn_board, bp, sizeof(boardheader_t), currbid); } move(6, 0); @@ -1310,6 +1321,134 @@ recommend_cancel(int ent, fileheader_t * fhdr, char *direct) touchdircache(currbid); return FULLUPDATE; } +static int +do_add_recommend(char * direct,fileheader_t * fhdr, int ent, char*buf) +{ + char path[256]; + lock_substitute_record(direct, fhdr, sizeof(*fhdr), ent, LOCK_EX); + setdirpath(path, direct, fhdr->filename); + log_file(path, buf); + if (!(fhdr->recommend < 100)) + lock_substitute_record(direct, fhdr, sizeof(*fhdr), ent, LOCK_UN); + else{ + fhdr->recommend++; + passwd_update(usernum, &cuser); + lock_substitute_record(direct, fhdr, sizeof(*fhdr), ent, LOCK_UN); + substitute_check(fhdr); + touchdircache(currbid); + } + return 0; +} +static int +do_bid(int ent, fileheader_t * fhdr, boardheader_t *bp, char *direct, struct tm *ptime) +{ + char genbuf[200], fpath[256],say[30]; + bid_t bidinfo; + int i, next; + char *payby[4]={ "Ptt幣","郵局或銀行轉帳","支票或電匯","郵局貨到付款"}; + + setdirpath(fpath, direct, fhdr->filename); + strcat(fpath,".bid"); + get_record(fpath, &bidinfo, sizeof(bidinfo), 1); + + move(18,0); clrtobot(); + prints("競標主題: %s\n", fhdr->title); + prints("目前最高價:%-20d出價者:%-16s\n",bidinfo.high, bidinfo.userid); + prints("付款方式: %-20s結束於:%-16s\n",payby[bidinfo.payby%4],Cdate(& bidinfo.enddate)); + if(bidinfo.buyitnow) + prints("直接購買價:%-20d",bidinfo.buyitnow); + if(bidinfo.shipping) + prints("運費:%d", bidinfo.shipping); + prints("\n"); + if(now>bidinfo.enddate || bidinfo.high==bidinfo.buyitnow) + { + prints("此競標已經結束,"); + if( bidinfo.userid[0]) prints("恭喜%s得標!", bidinfo.userid); + else prints("無人得標!"); + pressanykey(); + return FULLUPDATE; + } + if(bidinfo.userid[0]) + { + prints("下次出價至少要:%d", bidinfo.high + bidinfo.increment); + if(bidinfo.buyitnow) + prints(" (超過 %d 等於直接購買)",bidinfo.buyitnow); + next=bidinfo.high + bidinfo.increment; + } + else + { + prints("起標價: %d", bidinfo.high); + next=bidinfo.high; + } + if(!strcmp(cuser.userid,bidinfo.userid)) + { + prints("你是最高得標者!"); + pressanykey(); + return FULLUPDATE; + } + getdata_str(23,0,"是否要下標? (y/N)", genbuf, 3, LCECHO,"n"); + if(genbuf[0]!='y') return FULLUPDATE; + + getdata(23, 0, "您的最高下標金額(0:取消):", genbuf, 8, LCECHO); + i=atoi(genbuf); + + get_record(fpath, &bidinfo, sizeof(bidinfo), 1); + if(bidinfo.userid[0]) + next=bidinfo.high; + else + next=bidinfo.high + bidinfo.increment; + + if(i< next); + { + outmsg("取消下標或標金不足"); + pressanykey(); + } + + getdata(23,0,"下標感言:",say,12,DOECHO); + snprintf(genbuf, sizeof(genbuf), + "\033[1;31m→ \033[33m%s\033[m\033[33m:%s\033[m%*s金額:%-15d標%15s %02d/%02d\n", + cuser.userid,say, + 31 - strlen(cuser.userid) - strlen(say), " ", + next, fromhost, + ptime->tm_mon + 1, ptime->tm_mday); + do_add_recommend(direct, fhdr, ent, genbuf); + if(next>bidinfo.usermax) + { + bidinfo.usermax=i; + bidinfo.high=next; + strcpy(bidinfo.userid,cuser.userid); + } + else if(next<bidinfo.usermax && i>bidinfo.usermax) + { + bidinfo.high=bidinfo.usermax+bidinfo.increment; + bidinfo.usermax=i; + strcpy(bidinfo.userid,cuser.userid); + + snprintf(genbuf, sizeof(genbuf), +"\033[1;31m→ \033[33m自動競標%s勝出\033[m\033[33m\033[m%*s金額:%-15d標 %02d/%02d\n", + cuser.userid, + 20 - strlen(cuser.userid) , " ", + bidinfo.high, + ptime->tm_mon + 1, ptime->tm_mday); + do_add_recommend(direct, fhdr, ent, genbuf); + } + else + { + if(i+bidinfo.increment<bidinfo.usermax) + bidinfo.high=i+bidinfo.increment; + else + bidinfo.high=bidinfo.usermax; /*這邊怪怪的*/ + snprintf(genbuf, sizeof(genbuf), +"\033[1;31m→ \033[33m自動競標%s勝出\033[m\033[33m\033[m%*s金額:%-15d標 %02d/%02d\n", + bidinfo.userid, + 20 - strlen(bidinfo.userid) , " ", + bidinfo.high, + ptime->tm_mon + 1, ptime->tm_mday); + do_add_recommend(direct, fhdr, ent, genbuf); + } + substitute_record(fpath, &bidinfo, sizeof(bidinfo), 1); + return FULLUPDATE; +} static int recommend(int ent, fileheader_t * fhdr, char *direct) @@ -1321,18 +1460,19 @@ recommend(int ent, fileheader_t * fhdr, char *direct) bp = getbcache(currbid); if( bp->brdattr & BRD_NORECOMMEND ){ - vmsg("抱歉, 本板禁止推薦"); + vmsg("抱歉, 本板禁止推薦或競標"); return FULLUPDATE; } if (!(currmode & MODE_POST) || bp->brdattr & BRD_VOTEBOARD) { - vmsg("您因權限不足無法推薦!"); + vmsg("您因權限不足!"); return FULLUPDATE; } + if( fhdr->filemode & FILE_BID) + return do_bid(ent, fhdr, bp, direct, ptime); + setdirpath(path, direct, fhdr->filename); - if (fhdr->recommend > 9 || fhdr->recommend < 0) - /* 暫時性的 code 原來舊有值取消 */ - fhdr->recommend = 0; + if (fhdr->recommend == 0 && strcmp(cuser.userid, fhdr->owner) == 0){ vmsg("警告! 本人不能推薦第一次!"); @@ -1348,6 +1488,7 @@ recommend(int ent, fileheader_t * fhdr, char *direct) } #endif + if (!getdata(b_lines - 2, 0, "推薦語:", path, 40, DOECHO) || path == NULL || !getdata(b_lines - 1, 0, "確定要推薦, 請仔細考慮(Y/N)?[n] ", @@ -1360,18 +1501,7 @@ recommend(int ent, fileheader_t * fhdr, char *direct) cuser.userid, path, 51 - strlen(cuser.userid) - strlen(path), " ", fromhost, ptime->tm_mon + 1, ptime->tm_mday); - lock_substitute_record(direct, fhdr, sizeof(*fhdr), ent, LOCK_EX); - setdirpath(path, direct, fhdr->filename); - log_file(path, buf); - if (!(fhdr->recommend < 9)) - lock_substitute_record(direct, fhdr, sizeof(*fhdr), ent, LOCK_UN); - else{ - fhdr->recommend++; - passwd_update(usernum, &cuser); - lock_substitute_record(direct, fhdr, sizeof(*fhdr), ent, LOCK_UN); - substitute_check(fhdr); - touchdircache(currbid); - } + do_add_recommend(direct, fhdr, ent, buf); lastrecommend = now; return FULLUPDATE; } @@ -1718,7 +1848,8 @@ b_note_edit_bname(int bid) } else { if (!getdata(2, 0, "設定有效期限天?(n/Y)", buf, 3, LCECHO) || buf[0] != 'n') - fh->bupdate = gettime(3, fh->bupdate ? fh->bupdate : now); + fh->bupdate = gettime(3, fh->bupdate ? fh->bupdate : now, + "有效日期至"); else fh->bupdate = 0; substitute_record(fn_board, fh, sizeof(boardheader_t), bid); @@ -1775,7 +1906,7 @@ b_post_note() setbfile(buf, currboard, FN_POST_BID); if (more(buf, NA) == -1) more("etc/" FN_POST_BID, NA); - getdata(b_lines - 2, 0, "是否要用自訂bid注意事項?", yn, sizeof(yn), LCECHO); + getdata(b_lines - 2, 0, "是否要用自訂競標文章注意事項?", yn, sizeof(yn), LCECHO); if (yn[0] == 'y') vedit(buf, NA, NULL); else diff --git a/pttbbs/mbbsd/stuff.c b/pttbbs/mbbsd/stuff.c index 9f13b2ef..d8201330 100644 --- a/pttbbs/mbbsd/stuff.c +++ b/pttbbs/mbbsd/stuff.c @@ -337,27 +337,30 @@ belong(char *filelist, char *key) #ifndef _BBS_UTIL_C_ /* getdata_buf */ time_t -gettime(int line, time_t dt) +gettime(int line, time_t dt, char*head) { char yn[7]; + int i; struct tm *ptime = localtime(&dt), endtime; memcpy(&endtime, ptime, sizeof(struct tm)); snprintf(yn, sizeof(yn), "%4d", ptime->tm_year + 1900); + move(line, 0); prints("%s",head); + i=strlen(head); do { - getdata_buf(line, 0, "西元年:", yn, 5, LCECHO); + getdata_buf(line, i, " 西元年:", yn, 5, LCECHO); } while ((endtime.tm_year = atoi(yn) - 1900) < 0 || endtime.tm_year > 200); snprintf(yn, sizeof(yn), "%d", ptime->tm_mon + 1); do { - getdata_buf(line, 13, "月:", yn, 3, LCECHO); + getdata_buf(line, i+15, "月:", yn, 3, LCECHO); } while ((endtime.tm_mon = atoi(yn) - 1) < 0 || endtime.tm_mon > 11); snprintf(yn, sizeof(yn), "%d", ptime->tm_mday); do { - getdata_buf(line, 22, "日:", yn, 3, LCECHO); + getdata_buf(line, i+24, "日:", yn, 3, LCECHO); } while ((endtime.tm_mday = atoi(yn)) < 1 || endtime.tm_mday > 31); snprintf(yn, sizeof(yn), "%d", ptime->tm_hour); do { - getdata_buf(line, 31, "時(0-23):", yn, 3, LCECHO); + getdata_buf(line, i+33, "時(0-23):", yn, 3, LCECHO); } while ((endtime.tm_hour = atoi(yn)) < 0 || endtime.tm_hour > 23); return mktime(&endtime); } -- cgit v1.2.3 From a7ee42a75940158f2ddf456c1b721caacdf40ea0 Mon Sep 17 00:00:00 2001 From: victor <victor@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Tue, 23 Sep 2003 15:05:24 +0000 Subject: same as last commit git-svn-id: http://opensvn.csie.org/pttbbs/trunk@1197 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/menu.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/pttbbs/mbbsd/menu.c b/pttbbs/mbbsd/menu.c index 1e42410c..b27abaf6 100644 --- a/pttbbs/mbbsd/menu.c +++ b/pttbbs/mbbsd/menu.c @@ -473,6 +473,7 @@ static int m_jcee() { static int forsearch(); static int playground(); +static int chessroom(); /* Ptt Play menu */ static commands_t playlist[] = { @@ -491,9 +492,22 @@ static commands_t playlist[] = { {chicken_main,PERM_LOGINOK, "CChicken " "【\033[1;34m Ptt養雞場 \033[m】"}, {playground,PERM_LOGINOK, "AAmusement 【\033[1;33m Ptt遊樂場 \033[m】"}, + {chessroom, PERM_LOGINOK, "BChineseChess 【\033[1;34m Ptt棋院\033[m】"}, {NULL, 0, NULL} }; +static commands_t chesslist[] = { + {chc_main, PERM_LOGINOK, "1ChessFight 【\033[1;33m 邀 局 \033[m】"}, + {chc_personal, PERM_LOGINOK, "2SelfPlay 【\033[1;34m 打 譜 \033[m】"}, + {chc_watch, PERM_LOGINOK, "3ChessWatch 【\033[1;35m 觀 棋 \033[m】"}, + {NULL, 0, NULL} +}; + +static int chessroom() { + domenu(CHC, "Ptt棋院", '1', chesslist); + return 0; +} + static commands_t plist[] = { /* {p_ticket_main, PERM_LOGINOK,"00Pre 【 總統機 】"}, -- cgit v1.2.3 From 4a835005725db2e567f8beb327520d0138c99676 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Fri, 26 Sep 2003 05:09:03 +0000 Subject: reduce sort times in utmpsortd git-svn-id: http://opensvn.csie.org/pttbbs/trunk@1199 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/util/shmctl.c | 71 ++++++++++++++++++++++++++++++++-------------------- 1 file changed, 44 insertions(+), 27 deletions(-) diff --git a/pttbbs/util/shmctl.c b/pttbbs/util/shmctl.c index 750f0763..92a220e4 100644 --- a/pttbbs/util/shmctl.c +++ b/pttbbs/util/shmctl.c @@ -205,7 +205,7 @@ cmputmpuid(const void *i, const void *j) return (*((userinfo_t **) i))->uid - (*((userinfo_t **) j))->uid; } -inline void utmpsort(void) +inline void utmpsort(int sortall) { userinfo_t *uentp; int count, i, ns; @@ -233,39 +233,49 @@ inline void utmpsort(void) qsort(SHM->sorted[ns][0], count, sizeof(userinfo_t *), cmputmpuserid); for (i = 0; i < count; ++i) ((userinfo_t *) SHM->sorted[ns][0][i])->idoffset = i; - memcpy(SHM->sorted[ns][1], SHM->sorted[ns][0], sizeof(userinfo_t *) * count); - memcpy(SHM->sorted[ns][2], SHM->sorted[ns][0], sizeof(userinfo_t *) * count); - memcpy(SHM->sorted[ns][3], SHM->sorted[ns][0], sizeof(userinfo_t *) * count); - memcpy(SHM->sorted[ns][4], SHM->sorted[ns][0], sizeof(userinfo_t *) * count); - memcpy(SHM->sorted[ns][5], SHM->sorted[ns][0], sizeof(userinfo_t *) * count); - memcpy(SHM->sorted[ns][6], SHM->sorted[ns][0], sizeof(userinfo_t *) * count); - memcpy(SHM->sorted[ns][7], SHM->sorted[ns][0], sizeof(userinfo_t *) * count); - qsort(SHM->sorted[ns][1], count, sizeof(userinfo_t *), cmputmpmode); - qsort(SHM->sorted[ns][2], count, sizeof(userinfo_t *), cmputmpidle); - qsort(SHM->sorted[ns][3], count, sizeof(userinfo_t *), cmputmpfrom); - qsort(SHM->sorted[ns][4], count, sizeof(userinfo_t *), cmputmpfive); - qsort(SHM->sorted[ns][5], count, sizeof(userinfo_t *), cmputmpchc); + memcpy(SHM->sorted[ns][6], + SHM->sorted[ns][0], sizeof(userinfo_t *) * count); + memcpy(SHM->sorted[ns][7], + SHM->sorted[ns][0], sizeof(userinfo_t *) * count); qsort(SHM->sorted[ns][6], count, sizeof(userinfo_t *), cmputmpuid); qsort(SHM->sorted[ns][7], count, sizeof(userinfo_t *), cmputmppid); + if( sortall ){ + memcpy(SHM->sorted[ns][1], + SHM->sorted[ns][0], sizeof(userinfo_t *) * count); + memcpy(SHM->sorted[ns][2], + SHM->sorted[ns][0], sizeof(userinfo_t *) * count); + memcpy(SHM->sorted[ns][3], + SHM->sorted[ns][0], sizeof(userinfo_t *) * count); + memcpy(SHM->sorted[ns][4], + SHM->sorted[ns][0], sizeof(userinfo_t *) * count); + memcpy(SHM->sorted[ns][5], + SHM->sorted[ns][0], sizeof(userinfo_t *) * count); + qsort(SHM->sorted[ns][1], count, sizeof(userinfo_t *), cmputmpmode); + qsort(SHM->sorted[ns][2], count, sizeof(userinfo_t *), cmputmpidle); + qsort(SHM->sorted[ns][3], count, sizeof(userinfo_t *), cmputmpfrom); + qsort(SHM->sorted[ns][4], count, sizeof(userinfo_t *), cmputmpfive); + qsort(SHM->sorted[ns][5], count, sizeof(userinfo_t *), cmputmpchc); + memset(nusers, 0, sizeof(nusers)); + for (i = 0; i < count; ++i) { + uentp = SHM->sorted[ns][0][i]; + if (uentp && uentp->pid && + 0 < uentp->brc_id && uentp->brc_id < MAX_BOARD) + ++nusers[uentp->brc_id - 1]; + } + for (i = 0; i < SHM->Bnumber; ++i) + if (SHM->bcache[i].brdname[0] != 0) + SHM->bcache[i].nuser = nusers[i]; + } + SHM->currsorted = ns; SHM->UTMPbusystate = 0; - - memset(nusers, 0, sizeof(nusers)); - for (i = 0; i < count; ++i) { - uentp = SHM->sorted[ns][0][i]; - if (uentp && uentp->pid && - 0 < uentp->brc_id && uentp->brc_id < MAX_BOARD) - ++nusers[uentp->brc_id - 1]; - } - for (i = 0; i < SHM->Bnumber; ++i) - if (SHM->bcache[i].brdname[0] != 0) - SHM->bcache[i].nuser = nusers[i]; } int utmpsortd(int argc, char **argv) { pid_t pid; int interval; // sleep interval in microsecond(1/10**6) + int sortall, counter = 0; if( fork() > 0 ){ puts("sortutmpd daemonized..."); @@ -273,8 +283,9 @@ int utmpsortd(int argc, char **argv) } setproctitle("shmctl utmpsortd"); - if( argc != 2 || (interval = atoi(argv[1])) < 500000 ) + if( argc < 2 || (interval = atoi(argv[1])) < 500000 ) interval = 1000000; // default to 1 sec + sortall = ((argc < 3) ? 1 : atoi(argv[2])); while( 1 ){ if( (pid = fork()) != 0 ){ @@ -287,8 +298,14 @@ int utmpsortd(int argc, char **argv) for( i = 0 ; SHM->UTMPbusystate && i < 5 ; ++i ) usleep(300000); - if( SHM->UTMPneedsort ) - utmpsort(); + if( SHM->UTMPneedsort ){ + if( ++counter == sortall ){ + utmpsort(1); + counter = 0; + } + else + utmpsort(0); + } usleep(interval); } -- cgit v1.2.3 From 41e85ef4bd39fbbeea4d3b0ed778c12051ac3a5a Mon Sep 17 00:00:00 2001 From: victor <victor@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sun, 28 Sep 2003 02:12:03 +0000 Subject: 1. do not allow guest to add/subscribe fav. 2. add 'K' to help page. git-svn-id: http://opensvn.csie.org/pttbbs/trunk@1203 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/board.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/pttbbs/mbbsd/board.c b/pttbbs/mbbsd/board.c index 5214d3cc..c29180d9 100644 --- a/pttbbs/mbbsd/board.c +++ b/pttbbs/mbbsd/board.c @@ -1037,7 +1037,7 @@ static char *choosebrdhelp[] = { "(r)(→)(Rtn) 進入多功\能閱\讀選單", "(q)(←) 回到主選單", "(y/Z) 我的最愛,訂閱\看板,所有看板/訂閱\新開看板", - "(L) 加入分隔線至我的最愛", + "(L/K) 加入分隔線至我的最愛 / 備份,清理我的最愛", "(v/V) 通通看完/全部未讀", "(S) 按照字母/分類排序", "(t/^T/^A/^D) 標記看板/取消所有標記/ 將已標記者加入/移出我的最愛", @@ -1379,9 +1379,12 @@ choose_board(int newflag) } break; case 'z': - vmsg("嘿嘿 這個功\能已經被我的最愛取代掉了喔!"); + if (HAS_PERM(PERM_BASIC)) + vmsg("嘿嘿 這個功\能已經被我的最愛取代掉了喔!"); break; case 'Z': + if (!HAS_PERM(PERM_BASIC)) + break; cuser.uflag2 ^= FAVNEW_FLAG; if(cuser.uflag2 & FAVNEW_FLAG){ char fname[80]; -- cgit v1.2.3 From 648e239ff9ce119ae4224b0b27b705b1b38b091f Mon Sep 17 00:00:00 2001 From: "(no author)" <(no author)@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sun, 28 Sep 2003 11:29:34 +0000 Subject: git-svn-id: http://opensvn.csie.org/pttbbs/trunk@1204 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/bbs.c | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/pttbbs/mbbsd/bbs.c b/pttbbs/mbbsd/bbs.c index b08db231..77a5ecc9 100644 --- a/pttbbs/mbbsd/bbs.c +++ b/pttbbs/mbbsd/bbs.c @@ -146,7 +146,7 @@ static void readdoent(int num, fileheader_t * ent) { int type; - char *mark, *title, color, special = 0, isonline = 0, recom[3]; + char *mark, *title, color, special = 0, isonline = 0, recom[5]; userinfo_t *uentp; type = brc_unread(ent->filename, brc_num, brc_list) ? '+' : ' '; @@ -164,7 +164,7 @@ readdoent(int num, fileheader_t * ent) } title = subject(mark = ent->title); if (ent->filemode & FILE_BID) - color = '1', mark = "B:"; + color = '1', mark = "$"; else if (title == mark) color = '1', mark = "□"; else @@ -186,16 +186,18 @@ readdoent(int num, fileheader_t * ent) isonline = 1; #endif if(ent->recommend>99) - strcpy(recom,"--"); + strcpy(recom,"1m爆"); + else if(ent->recommend>10); + sprintf(recom,"3m%2d",ent->recommend); else if(ent->recommend>0) - sprintf(recom,"%2d",ent->recommend); - else strcpy(recom," "); + sprintf(recom,"2m%2d",ent->recommend); + else strcpy(recom,"0m "); prints( #ifdef COLORDATE - "%6d %c\033[1;32m%2.2s\033[%dm%-6s\033[m\033[%dm%-13.12s", + "%6d %c\033[1;3%2.2s\033[%dm%-6s\033[m\033[%dm%-13.12s", #else - "%6d %c\033[1;32m%2.2s\033[m%-6s\033[%dm%-13.12s", + "%6d %c\033[1;3%2.2s\033[m%-6s\033[%dm%-13.12s", #endif num, type, recom, #ifdef COLORDATE @@ -1386,19 +1388,25 @@ do_bid(int ent, fileheader_t * fhdr, boardheader_t *bp, char *direct, struct t pressanykey(); return FULLUPDATE; } + if (strcmp(cuser.userid, fhdr->owner) == 0){ + vmsg("警告! 本人不能出價!"); + return FULLUPDATE; + } getdata_str(23,0,"是否要下標? (y/N)", genbuf, 3, LCECHO,"n"); if(genbuf[0]!='y') return FULLUPDATE; - getdata(23, 0, "您的最高下標金額(0:取消):", genbuf, 8, LCECHO); + wile + getdata(23, 0, "您的最高下標金額(0:取消):", genbuf, 7, LCECHO); + i=atoi(genbuf); get_record(fpath, &bidinfo, sizeof(bidinfo), 1); - if(bidinfo.userid[0]) + if(!bidinfo.userid[0]) next=bidinfo.high; else next=bidinfo.high + bidinfo.increment; - if(i< next); + if(i< next || (payby==0 && cuser.money<i )); { outmsg("取消下標或標金不足"); pressanykey(); -- cgit v1.2.3 From 3fa0d57c0f64354079ac5fa9e240fcfda2e2ec72 Mon Sep 17 00:00:00 2001 From: "(no author)" <(no author)@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sun, 28 Sep 2003 12:17:42 +0000 Subject: git-svn-id: http://opensvn.csie.org/pttbbs/trunk@1205 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/bbs.c | 88 +++++++++++++++++++++++++++++++++++------------------- 1 file changed, 57 insertions(+), 31 deletions(-) diff --git a/pttbbs/mbbsd/bbs.c b/pttbbs/mbbsd/bbs.c index 77a5ecc9..b3f5ec66 100644 --- a/pttbbs/mbbsd/bbs.c +++ b/pttbbs/mbbsd/bbs.c @@ -187,7 +187,7 @@ readdoent(int num, fileheader_t * ent) #endif if(ent->recommend>99) strcpy(recom,"1m爆"); - else if(ent->recommend>10); + else if(ent->recommend>10) sprintf(recom,"3m%2d",ent->recommend); else if(ent->recommend>0) sprintf(recom,"2m%2d",ent->recommend); @@ -452,7 +452,42 @@ do_allpost(fileheader_t *postfile, const char *fpath, const char *owner) setbtotal(getbnum(ALLPOST)); } } +static void +setupbidinfo(bid_t *bidinfo) +{ + char buf[256]; + bidinfo->enddate = gettime(20, now+86400,"結束標案於"); + do + getdata_str(21,0,"底價:",buf, 8, LCECHO, "1"); + while((bidinfo->high=atoi(buf))<=0); + do + getdata_str(21,20, "每標至少增加多少:",buf, 5, LCECHO, "1"); + while((bidinfo->increment=atoi(buf))<=0); + getdata(21,44, "直接購買價(可不設):",buf, 5, LCECHO); + bidinfo->buyitnow=atoi(buf); + + getdata_str(22,0, + "付款方式: 1.Ptt幣 2.郵局或銀行轉帳 3.支票或電匯 4.郵局貨到付款 [1]:", + buf, 3, LCECHO,"1"); + bidinfo->payby=(buf[0]-'1'); + if(bidinfo->payby<0 ||bidinfo->payby>3)bidinfo->payby=0; + getdata_str(23,0, "運費(0:免運費或文中說明)[0]:", buf, 6, LCECHO, "0"); + bidinfo->shipping = atoi(buf); + if(bidinfo->shipping<0) bidinfo->shipping=0; +} +static void +print_bidinfo(FILE *io, bid_t bidinfo) +{ + char *payby[4]={ "Ptt幣","郵局或銀行轉帳","支票或電匯","郵局貨到付款"}; + fprintf(io, "目前最高價:%-20d出價者:%-16s\n",bidinfo.high, bidinfo.userid); + fprintf(io, "付款方式: %-20s結束於:%-16s\n",payby[bidinfo.payby%4],Cdate(& bidinfo.enddate)); + if(bidinfo.buyitnow) + fprintf(io, "直接購買價:%-20d",bidinfo.buyitnow); + if(bidinfo.shipping) + fprintf(io, "運費:%d", bidinfo.shipping); + fprintf(io, "\n"); +} static int do_general(int isbid) { @@ -515,24 +550,8 @@ do_general(int isbid) if(isbid) { memset(&bidinfo,0,sizeof(bidinfo)); - bidinfo.enddate = gettime(20, now+86400,"結束標案於"); - do - getdata_str(21,0,"底價:",buf, 8, LCECHO, "1"); - while((bidinfo.high=postfile.money=atoi(buf))<=0); - do - getdata_str(21,20, "每標至少增加多少:",buf, 5, LCECHO, "1"); - while((bidinfo.increment=atoi(buf))<=0); - getdata(21,44, "直接購買價(可不設):",buf, 5, LCECHO); - bidinfo.buyitnow=atoi(buf); - - getdata_str(22,0, - "付款方式: 1.Ptt幣 2.郵局或銀行轉帳 3.支票或電匯 4.郵局貨到付款 [1]:", - buf, 3, LCECHO,"1"); - bidinfo.payby=(buf[0]-'1'); - if(bidinfo.payby<0 ||bidinfo.payby>3)bidinfo.payby=0; - getdata_str(23,0, "運費(0:免運費或文中說明)[0]:", buf, 6, LCECHO, "0"); - bidinfo.shipping = atoi(buf); - if(bidinfo.shipping<0) bidinfo.shipping=0; + setupbidinfo(&bidinfo); + postfile.money=bidinfo.high; move(20,0); clrtobot(); } @@ -571,7 +590,16 @@ do_general(int isbid) /* build filename */ setbpath(fpath, currboard); stampfile(fpath, &postfile); - + if(isbid) + { + aborted = (int)fopen(fpath, "w"); + if(aborted) + { + print_bidinfo((FILE*)aborted, bidinfo); + fclose((FILE*)aborted); + } + } + aborted = vedit(fpath, YEA, &islocal); if (aborted == -1) { unlink(fpath); @@ -1347,7 +1375,6 @@ do_bid(int ent, fileheader_t * fhdr, boardheader_t *bp, char *direct, struct t char genbuf[200], fpath[256],say[30]; bid_t bidinfo; int i, next; - char *payby[4]={ "Ptt幣","郵局或銀行轉帳","支票或電匯","郵局貨到付款"}; setdirpath(fpath, direct, fhdr->filename); strcat(fpath,".bid"); @@ -1355,17 +1382,17 @@ do_bid(int ent, fileheader_t * fhdr, boardheader_t *bp, char *direct, struct t move(18,0); clrtobot(); prints("競標主題: %s\n", fhdr->title); - prints("目前最高價:%-20d出價者:%-16s\n",bidinfo.high, bidinfo.userid); - prints("付款方式: %-20s結束於:%-16s\n",payby[bidinfo.payby%4],Cdate(& bidinfo.enddate)); - if(bidinfo.buyitnow) - prints("直接購買價:%-20d",bidinfo.buyitnow); - if(bidinfo.shipping) - prints("運費:%d", bidinfo.shipping); - prints("\n"); + print_bidinfo(0, bidinfo); if(now>bidinfo.enddate || bidinfo.high==bidinfo.buyitnow) { prints("此競標已經結束,"); - if( bidinfo.userid[0]) prints("恭喜%s得標!", bidinfo.userid); + if( bidinfo.userid[0]) + { + /*if(!payby && bidinfo.usermax!=-1) + {以Ptt幣自動扣款 + }*/ + prints("恭喜 %s 以 %d 得標!", bidinfo.userid, bidinfo.high); + } else prints("無人得標!"); pressanykey(); return FULLUPDATE; @@ -1395,7 +1422,6 @@ do_bid(int ent, fileheader_t * fhdr, boardheader_t *bp, char *direct, struct t getdata_str(23,0,"是否要下標? (y/N)", genbuf, 3, LCECHO,"n"); if(genbuf[0]!='y') return FULLUPDATE; - wile getdata(23, 0, "您的最高下標金額(0:取消):", genbuf, 7, LCECHO); i=atoi(genbuf); @@ -1406,7 +1432,7 @@ do_bid(int ent, fileheader_t * fhdr, boardheader_t *bp, char *direct, struct t else next=bidinfo.high + bidinfo.increment; - if(i< next || (payby==0 && cuser.money<i )); + if(i< next || (bidinfo.payby==0 && cuser.money<i )); { outmsg("取消下標或標金不足"); pressanykey(); -- cgit v1.2.3 From 40ffcdeec035409592935ebf930d3abbb1cde0b5 Mon Sep 17 00:00:00 2001 From: "(no author)" <(no author)@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sun, 28 Sep 2003 12:44:12 +0000 Subject: git-svn-id: http://opensvn.csie.org/pttbbs/trunk@1206 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/bbs.c | 35 +++++++++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 8 deletions(-) diff --git a/pttbbs/mbbsd/bbs.c b/pttbbs/mbbsd/bbs.c index b3f5ec66..032a8cda 100644 --- a/pttbbs/mbbsd/bbs.c +++ b/pttbbs/mbbsd/bbs.c @@ -195,9 +195,9 @@ readdoent(int num, fileheader_t * ent) prints( #ifdef COLORDATE - "%6d %c\033[1;3%2.2s\033[%dm%-6s\033[m\033[%dm%-13.12s", + "%6d %c\033[1;3%4.4s\033[%dm%-6s\033[m\033[%dm%-13.12s", #else - "%6d %c\033[1;3%2.2s\033[m%-6s\033[%dm%-13.12s", + "%6d %c\033[1;3%4.4s\033[m%-6s\033[%dm%-13.12s", #endif num, type, recom, #ifdef COLORDATE @@ -479,14 +479,33 @@ static void print_bidinfo(FILE *io, bid_t bidinfo) { char *payby[4]={ "Ptt幣","郵局或銀行轉帳","支票或電匯","郵局貨到付款"}; - - fprintf(io, "目前最高價:%-20d出價者:%-16s\n",bidinfo.high, bidinfo.userid); - fprintf(io, "付款方式: %-20s結束於:%-16s\n",payby[bidinfo.payby%4],Cdate(& bidinfo.enddate)); - if(bidinfo.buyitnow) + if(io) + { + if(!bidinfo.userid[0]) + fprintf(io,"起標價: %-20d\n",bidinfo.high); + else + fprintf(io, "目前最高價:%-20d出價者:%-16s\n",bidinfo.high, bidinfo.userid); + fprintf(io, "付款方式: %-20s結束於:%-16s\n",payby[bidinfo.payby%4],Cdate(& bidinfo.enddate)); + if(bidinfo.buyitnow) fprintf(io, "直接購買價:%-20d",bidinfo.buyitnow); - if(bidinfo.shipping) + if(bidinfo.shipping) fprintf(io, "運費:%d", bidinfo.shipping); - fprintf(io, "\n"); + fprintf(io, "\n"); + } + else + { + if(!bidinfo.userid[0]) + prints("起標價: %-20d\n",bidinfo.high); + else + prints("目前最高價:%-20d出價者:%-16s\n",bidinfo.high, bidinfo.userid); + prints("付款方式: %-20s結束於:%-16s\n",payby[bidinfo.payby%4],Cdate(& bidinfo.enddate)); + if(bidinfo.buyitnow) + prints("直接購買價:%-20d",bidinfo.buyitnow); + if(bidinfo.shipping) + prints("運費:%d", bidinfo.shipping); + prints("\n"); + } + } static int do_general(int isbid) -- cgit v1.2.3 From 77005fdb1ae2c1c6ee778ab7e248a94616b79d1f Mon Sep 17 00:00:00 2001 From: "(no author)" <(no author)@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sun, 28 Sep 2003 12:49:54 +0000 Subject: git-svn-id: http://opensvn.csie.org/pttbbs/trunk@1207 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/bbs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pttbbs/mbbsd/bbs.c b/pttbbs/mbbsd/bbs.c index 032a8cda..30fea150 100644 --- a/pttbbs/mbbsd/bbs.c +++ b/pttbbs/mbbsd/bbs.c @@ -187,7 +187,7 @@ readdoent(int num, fileheader_t * ent) #endif if(ent->recommend>99) strcpy(recom,"1m爆"); - else if(ent->recommend>10) + else if(ent->recommend>9) sprintf(recom,"3m%2d",ent->recommend); else if(ent->recommend>0) sprintf(recom,"2m%2d",ent->recommend); -- cgit v1.2.3 From c73e9fcd574e9607c8cf758eedf52fa5c68ed914 Mon Sep 17 00:00:00 2001 From: victor <victor@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sun, 28 Sep 2003 14:27:18 +0000 Subject: ask before watching a chc game. fix wrong flow git-svn-id: http://opensvn.csie.org/pttbbs/trunk@1208 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/chc.c | 3 +++ pttbbs/mbbsd/talk.c | 6 ++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/pttbbs/mbbsd/chc.c b/pttbbs/mbbsd/chc.c index 42abbe22..1fad931a 100644 --- a/pttbbs/mbbsd/chc.c +++ b/pttbbs/mbbsd/chc.c @@ -1015,6 +1015,9 @@ chc_watch(void) if (uin->uid == currutmp->uid || uin->mode != CHC) return -1; + if (getans("是否進行觀棋? [N/y]") != 'y') + return 0; + if ((sock = make_connection_to_somebody(uin, 10)) < 0) { vmsg("無法建立連線"); return -1; diff --git a/pttbbs/mbbsd/talk.c b/pttbbs/mbbsd/talk.c index 2d07abcf..a576fbf4 100644 --- a/pttbbs/mbbsd/talk.c +++ b/pttbbs/mbbsd/talk.c @@ -1212,8 +1212,10 @@ my_talk(userinfo_t * uin, int fri_stat, char defact) sock = make_connection_to_somebody(uin, 20); if (sock < 0) vmsg("無法建立連線"); - strlcpy(currutmp->mateid, uin->userid, sizeof(currutmp->mateid)); - chc(sock, CHC_WATCH); + else { + strlcpy(currutmp->mateid, uin->userid, sizeof(currutmp->mateid)); + chc(sock, CHC_WATCH); + } } else outs("人家在忙啦"); -- cgit v1.2.3 From 2a2fcfccb232aec55d2e388ca93ffaf52810daaa Mon Sep 17 00:00:00 2001 From: victor <victor@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sat, 4 Oct 2003 06:04:50 +0000 Subject: =?UTF-8?q?shift=20=E6=97=A5=E6=9C=9F=20of=20the=20title=20bar?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: http://opensvn.csie.org/pttbbs/trunk@1211 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/mbbsd/bbs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pttbbs/mbbsd/bbs.c b/pttbbs/mbbsd/bbs.c index 30fea150..756b8055 100644 --- a/pttbbs/mbbsd/bbs.c +++ b/pttbbs/mbbsd/bbs.c @@ -138,7 +138,7 @@ readtitle() showtitle(currBM, brd_title); outs("[←]離開 [→]閱\讀 [^P]發表文章 [b]備忘錄 [d]刪除 [z]精華區 " - "[TAB]文摘 [h]elp\n\033[7m 編號 日 期 作 者 文 章 標 題" + "[TAB]文摘 [h]elp\n\033[7m 編號 日 期 作 者 文 章 標 題" " \033[m"); } -- cgit v1.2.3 From a94fe7b873e50aec4d08cab1867e741998957605 Mon Sep 17 00:00:00 2001 From: in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sun, 5 Oct 2003 01:03:12 +0000 Subject: use bsearch in login_friend_online() save cpu but increase SHM_t (sizeof(short) * MAX_ACTIVE) bytes WARNING: SHM_t has been changed git-svn-id: http://opensvn.csie.org/pttbbs/trunk@1212 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/include/proto.h | 2 ++ pttbbs/include/pttstruct.h | 2 ++ pttbbs/mbbsd/friend.c | 2 ++ pttbbs/mbbsd/stuff.c | 25 +++++++++++++++++++++++++ pttbbs/mbbsd/talk.c | 27 +++++++-------------------- 5 files changed, 38 insertions(+), 20 deletions(-) diff --git a/pttbbs/include/proto.h b/pttbbs/include/proto.h index a072c5d9..41fa2a7f 100644 --- a/pttbbs/include/proto.h +++ b/pttbbs/include/proto.h @@ -445,6 +445,8 @@ int not_alpha(char ch); int valid_ident(char *ident); int userid_is_BM(char *userid, char *list); int is_uBM(char *list, char *id); +inline int *intbsearch(int key, int *base0, int nmemb); +int qsort_intcompar(const void *a, const void *b); #ifndef CRITICAL_MEMORY #define MALLOC(p) malloc(p) #define FREE(p) free(p) diff --git a/pttbbs/include/pttstruct.h b/pttbbs/include/pttstruct.h index f14317e7..5ec26a57 100644 --- a/pttbbs/include/pttstruct.h +++ b/pttbbs/include/pttstruct.h @@ -238,6 +238,8 @@ typedef struct userinfo_t { int from_alias; char birth; /* 是否是生日 Ptt*/ char tty[11]; /* tty port */ + short nFriends; /* 下面 friend[] 只用到前幾個, + 用來 bsearch */ int friend[MAX_FRIEND]; int friend_online[MAX_FRIEND];/* point到線上好友 utmpshm的位置 */ /* 好友比較的cache 前兩個bit是狀態 */ diff --git a/pttbbs/mbbsd/friend.c b/pttbbs/mbbsd/friend.c index 8205686d..ab9f1076 100644 --- a/pttbbs/mbbsd/friend.c +++ b/pttbbs/mbbsd/friend.c @@ -271,7 +271,9 @@ friend_load(int type) myfriends[friendcount++] = unum; fclose(fp); } + qsort(myfriends, friendcount, sizeof(int), qsort_intcompar); memcpy(currutmp->friend, myfriends, sizeof(myfriends)); + currutmp->nFriends = friendcount; } if (!type || type & FRIEND_REJECT) { diff --git a/pttbbs/mbbsd/stuff.c b/pttbbs/mbbsd/stuff.c index d8201330..a6aaec46 100644 --- a/pttbbs/mbbsd/stuff.c +++ b/pttbbs/mbbsd/stuff.c @@ -663,3 +663,28 @@ StringHash(unsigned char *s) } return (v * 2654435769UL) >> (32 - HASH_BITS); } + +inline int *intbsearch(int key, int *base0, int nmemb) +{ + /* 改自 /usr/src/lib/libc/stdlib/bsearch.c , + 專給搜 int array 用的, 不透過 compar function 故較快些 */ + const char *base = (char *)base0; + size_t lim; + int *p; + + for (lim = nmemb; lim != 0; lim >>= 1) { + p = (int *)(base + (lim >> 1) * 4); + if( key == *p ) + return p; + if( key > *p ){/* key > p: move right */ + base = (char *)p + 4; + lim--; + } /* else move left */ + } + return (NULL); +} + +int qsort_intcompar(const void *a, const void *b) +{ + return *(int *)a - *(int *)b; +} diff --git a/pttbbs/mbbsd/talk.c b/pttbbs/mbbsd/talk.c index a576fbf4..9633570d 100644 --- a/pttbbs/mbbsd/talk.c +++ b/pttbbs/mbbsd/talk.c @@ -155,33 +155,20 @@ modestring(userinfo_t * uentp, int simple) int set_friend_bit(userinfo_t * me, userinfo_t * ui) { - int unum, *myfriends, hit = 0, n; + int unum, *myfriends, hit = 0; /* 判斷對方是否為我的朋友 ? */ - unum = ui->uid; - myfriends = me->friend; - while ((n = *myfriends++)) { - if (unum == n) { - hit = IFH; - break; - } - } + if( intbsearch(ui->uid, me->friend, me->nFriends) ) + hit = IFH; /* 判斷我是否為對方的朋友 ? */ - myfriends = ui->friend; - while ((unum = *myfriends++)) { - if (unum == me->uid) { - hit |= HFM; - break; - } - } + if( intbsearch(me->uid, ui->friend, ui->nFriends) ) + hit |= HFM; /* 判斷對方是否為我的仇人 ? */ - - unum = ui->uid; myfriends = me->reject; - while ((n = *myfriends++)) { - if (unum == n) { + while ((unum = *myfriends++)) { + if (unum == ui->uid) { hit |= IRH; break; } -- cgit v1.2.3 -- cgit v1.2.3 From 4311844d85cc4e4feca1dc9221ce7725626e7c82 Mon Sep 17 00:00:00 2001 From: victor <victor@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sun, 5 Oct 2003 08:01:41 +0000 Subject: tmp git-svn-id: http://opensvn.csie.org/pttbbs/branches/victor.tmp@1216 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/docs/fav.txt | 36 +++++++ pttbbs/include/proto.h | 42 ++++++++ pttbbs/mbbsd/board.c | 264 +++++++++++++++++-------------------------------- 3 files changed, 170 insertions(+), 172 deletions(-) create mode 100644 pttbbs/docs/fav.txt diff --git a/pttbbs/docs/fav.txt b/pttbbs/docs/fav.txt new file mode 100644 index 00000000..c8edf8d9 --- /dev/null +++ b/pttbbs/docs/fav.txt @@ -0,0 +1,36 @@ +Favorite ver.4 + +Feature +======= +•重寫、整個架構改變 +•folding + +Structure +========= + fav4 的主要架構如下: + +•fav_t + 進入我的最愛時,看到的東西就是根據 fav_t 生出來的。 + 裡面紀錄者,這一個 level 中有多少個看板、目錄、分隔線。(favh) + +•fav_type_t + 這算是架在以下三個東西之上的介面,等於是將他們視為同一種東西,方便之後的存取。 + 用一個 void * 指標指向某塊記憶體,存取時可透過 type 變數來得知正確的型態。 + +•fav_board_t + 紀錄了 bid 及上次拜訪時間。 + +•fav_line_t + 紀錄了 lid + +•fav_folder_t + 紀錄了 fid 及可自訂的名稱。 + +•fav.c 中以 cast_(board|line|folder)_t() 來將一個 fav_type_t 轉為正確的型態。 + +Policy +====== +•為了避免過度的資料搬移,當將一個 item 從我的最愛中移除時,只將他的 FAVH_FAV + flag 移除。而沒有這個 flag 的 item 也不被視為我的最愛。 +•我的最愛中,沒設 FAVH_FAV 的資料,將在某些時候,如寫入檔案時,呼叫 + rebuild_fav 清除乾淨。 diff --git a/pttbbs/include/proto.h b/pttbbs/include/proto.h index 41fa2a7f..b202e20e 100644 --- a/pttbbs/include/proto.h +++ b/pttbbs/include/proto.h @@ -200,6 +200,48 @@ void editlock(char *fpath); void editunlock(char *fpath); int iseditlocking(char *fpath, char *action); +/* fav */ +fav_type_t *get_current_entry(void); +void fav_set_old_folder(fav_t *fp); +fav_t *get_current_fav(void); +int get_item_type(fav_type_t *ft); +char *get_folder_title(int fid); +void set_attr(fav_type_t *ft, int bit, int bool); +void fav_sort_by_name(void); +void fav_sort_by_class(void); +int fav_load(void); +int fav_save(void); +void fav_remove_current(void); +void fav_remove_board_from_whole(int bid); +char getbrdattr(short bid); +time_t getbrdtime(short bid); +void setbrdtime(short bid, time_t t); +int fav_getid(fav_type_t *ft); +int fav_add(fav_t *fp, fav_type_t *item); +void move_in_current_folder(int from, int to); +void fav_move(int from, int to); +fav_type_t *fav_add_line(int place); +fav_type_t *fav_add_folder(int place); +fav_type_t *fav_add_board(int bid, int place); +void fav_tag_current(int bool); +void fav_remove_all_tagged_item(void); +void fav_remove_all_tagged_item(void); +void fav_add_all_tagged_item(void); +void fav_remove_all_tag(void); +void fav_set_folder_title(fav_type_t *ft, char *title); +int fav_max_folder_level(void); +void fav_folder_in(void); +void fav_folder_out(void); +void fav_free(void); +int fav_v3_to_v4(void); +void fav_cursor_up(void); +void fav_cursor_down(void); +void fav_cursor_up_step(int step); +void fav_cursor_down_step(int step); +void fav_cursor_set(int where); +int is_set_attr(fav_type_t *ft, int bit); +void cleanup(void); + /* friend */ void friend_edit(int type); void friend_load(); diff --git a/pttbbs/mbbsd/board.c b/pttbbs/mbbsd/board.c index c29180d9..d7f4e0b7 100644 --- a/pttbbs/mbbsd/board.c +++ b/pttbbs/mbbsd/board.c @@ -272,154 +272,6 @@ fav_t *fav; static short brdnum; static char yank_flag = 1; -int cmpfav(const void *a, const void *b) -{ - if( *(short *)a > ((fav_board_t *)b)->bid ) - return 1; - else if( *(short *)a == ((fav_board_t *)b)->bid ) - return 0; - return -1; -} - -fav_board_t *getfav(short bid) -{ - int i; - for(i = 0; i < fav->nDatas; i++) - if(fav->b[i].bid == bid) - break; - return i == fav->nDatas ? NULL : &fav->b[i]; -} - -char getfavattr(short bid) -{ - fav_board_t *ptr = getfav(bid); - if( ptr == NULL ) - return 0; // default here - else - return ptr->attr; -} - -time_t getfavtime(short bid) -{ - fav_board_t *ptr = getfav(bid); - if( ptr == NULL ) - return login_start_time; // default here - else - return ptr->lastvisit; -} - -void basemovefav(int src, int des) -{ - int i; - fav_board_t tmp = fav->b[src]; - - if(src < des){ - for(i = src; i < des; i++) - fav->b[i] = fav->b[i + 1]; - } - else{ // des < src - for(i = src; i > des; i--) - fav->b[i] = fav->b[i - 1]; - } - fav->b[des] = tmp; - - brdnum = -1; -} - -void movefav(int old, int new) -{ - int i, src = -1, des = -1; - favchange = 1; - - for(i = 0; i < fav->nDatas; i++){ - if(nbrd[old].bid == fav->b[i].bid) - src = i; - if(nbrd[new].bid == fav->b[i].bid) - des = i; - } - - if(src == -1 || des == -1) - return; - basemovefav(src, des); -} - -void delfavline(int bid, int num) -{ - int i; - - movefav(num, --brdnum); - fav->nLines++; - fav->nDatas--; - - for(i = 0; i < fav->nDatas; i++) - if(fav->b[i].bid < bid) - fav->b[i].bid++; - for(i = 0; i < brdnum; i++) - if(nbrd[i].bid < bid) - nbrd[i].bid++; -} - -void setfav(short bid, char attr, char mode, time_t t) -{ - /* mode: 0: 設成 off, 1: 設成 on, 2: 反相 */ - fav_board_t *ptr = getfav(bid); - - favchange = 1; - - if( ptr != NULL ){ - if( mode == 2 ) - ptr->attr ^= attr; - else if( mode ) - ptr->attr |= attr; - else - ptr->attr &= ~attr; - if( t ) - ptr->lastvisit = t; - } - else{ - int where; - if( fav->nDatas == fav->nAllocs ){ -#ifdef DEBUG - vmsg("realloc fav"); -#endif - fav = realloc(fav, - sizeof(fav_t) + - sizeof(fav_board_t) * - (16 + fav->nAllocs)); - memset(&fav->b[fav->nDatas], 0, sizeof(fav_board_t) * 16); - fav->nAllocs += 16; - } - - where = fav->nDatas; - - if( attr & BRD_LINE ){ - fav->b[where].bid = --(fav->nLines); - fav->b[where].attr = mode ? (BRD_LINE | BRD_FAV) : 0; - } - else{ - fav->b[where].bid = bid ; - fav->b[where].attr = mode ? attr : 0; - } - - fav->b[where].lastvisit = t ? t : login_start_time; - fav->nDatas++; - } -} - -void imovefav(int old) -{ - char buf[5]; - int new; - - getdata(b_lines - 1, 0, "請輸入新次序:", buf, sizeof(buf), DOECHO); - new = atoi(buf) - 1; - if (new < 0 || brdnum <= new){ - vmsg("輸入範圍有誤!"); - return; - } - movefav(old, new); -} - #define BRD_OLD 0 #define BRD_NEW 1 #define BRD_END 2 @@ -473,19 +325,22 @@ void updatenewfav(int mode) } } -void favclean(fav_t *fav){ - int i; - boardheader_t *bptr; - - for(i = 0; i < fav->nDatas; i++){ - if(fav->b[i].attr & BRD_LINE) - continue; - bptr = &bcache[ fav->b[i].bid - 1 ]; - if(!(fav->b[i].attr & BRD_FAV) || !Ben_Perm(bptr)){ - basemovefav(i, fav->nDatas--); - continue; - } +void imovefav(int old) +{ + char buf[5]; + int new; + + getdata(b_lines - 1, 0, "請輸入新次序:", buf, sizeof(buf), DOECHO); + new = atoi(buf) - 1; + if (new < 0 || brdnum <= new){ + vmsg("輸入範圍有誤!"); + return; } + move_in_current_folder(old, new); +} + +inline int validboard(int bid){ + return bcache[bid].brdname[0]; } void freefav(fav_t *fav){ @@ -785,7 +640,7 @@ load_boards(char *key) if (class_bid <= 0) { if( yank_flag == 0 ){ // fav mode nbrd = (boardstat_t *)malloc(sizeof(boardstat_t) * fav->nDatas); - for( i = 0 ; i < fav->nDatas ; ++i ){ + for( i = 0 ; i < fav->nAllocs; ++i ){ if( fav->b[i].attr & BRD_FAV ){ if( fav->b[i].attr & BRD_LINE && !key[0]) addnewbrdstat(fav->b[i].bid - 1, BRD_FAV | BRD_LINE); @@ -963,15 +818,31 @@ show_brdlist(int head, int clsflag, int newflag) "\033[1;32m", "\033[1;33m"}; char *unread[2] = {"\33[37m \033[m", "\033[1;31mˇ\033[m"}; + if (yank_flag == 0 && nbrd[0].myattr == 0){ + move(3, 0); + prints(" --- 空目錄 ---"); + return; + } + while (++myrow < b_lines) { move(myrow, 0); clrtoeol(); if (head < brdnum) { ptr = &nbrd[head++]; - if(ptr->myattr & BRD_LINE){ + if (ptr->myattr & BRD_LINE){ prints("%5d %c ------------ ------------------------------------------", head, ptr->myattr & BRD_TAG ? 'D' : ' '); continue; } + else if (ptr->myattr & BRD_FOLDER){ + char *title = get_folder_title(ptr->bid); + prints("%5d %c %sMyFavFolder\033[m 目錄 □%-34s\033[m", + head, + ptr->myattr & BRD_TAG ? 'D' : ' ', + (cuser.uflag2 & FAVNOHILIGHT)? "" : "\033[1;36m", + title); + continue; + } + if (class_bid == 1) prints(" "); if (!newflag) { @@ -1080,6 +951,7 @@ choose_board(int newflag) do { if (brdnum <= 0) { load_boards(keyword); + fav_cursor_set(num); if (brdnum <= 0) { if (keyword[0] != 0) { mprints(b_lines - 1, 0, "沒有任何看板標題有此關鍵字 " @@ -1104,10 +976,16 @@ choose_board(int newflag) } head = -1; } - if (num < 0) + + /* reset the cursor when out of range */ + if (num < 0){ num = 0; - else if (num >= brdnum) + fav_cursor_set(num); + } + else if (num >= brdnum){ num = brdnum - 1; + fav_cursor_set(num); + } if (head < 0) { if (newflag) { @@ -1157,20 +1035,26 @@ choose_board(int newflag) case Ctrl('B'): if (num) { num -= p_lines; + fav_cursor_down_step(p_lines); break; } case KEY_END: case '$': num = brdnum - 1; + fav_cursor_set(num); break; case ' ': case KEY_PGDN: case 'N': case Ctrl('F'): - if (num == brdnum - 1) + if (num == brdnum - 1){ num = 0; - else + fav_cursor_set(num); + } + else{ num += p_lines; + fav_cursor_down_step(p_lines); + } break; case Ctrl('C'): cal(); @@ -1183,8 +1067,12 @@ choose_board(int newflag) case KEY_UP: case 'p': case 'k': - if (num-- <= 0) + if (num-- <= 0){ num = brdnum - 1; + fav_cursor_set(num); + } + else + fav_cursor_up(); break; case 't': ptr = &nbrd[num]; @@ -1194,11 +1082,13 @@ choose_board(int newflag) case KEY_DOWN: case 'n': case 'j': + fav_cursor_down(); if (++num < brdnum) break; case '0': case KEY_HOME: num = 0; + fav_cursor_set(num); break; case '1': case '2': @@ -1209,8 +1099,10 @@ choose_board(int newflag) case '7': case '8': case '9': - if ((tmp = search_num(ch, brdnum)) >= 0) + if ((tmp = search_num(ch, brdnum)) >= 0){ num = tmp; + fav_cursor_set(num); + } brdlist_foot(); break; case 'F': @@ -1342,6 +1234,16 @@ choose_board(int newflag) head = 9999; } break; + case 'T': + if (HAS_PERM(PERM_BASIC)) { + char title[64]; + fav_type_t *ft = get_current_entry(); + strlcpy(title, get_item_title(ft), sizeof(title)); + getdata_buf(b_lines - 1, 0, "請輸入檔名:", title, sizeof(title), DOECHO); + fav_set_folder_title(ft, title); + brdnum = -1; + } + break; case 'K': if (HAS_PERM(PERM_BASIC)) { char c, fname[80], genbuf[256]; @@ -1353,7 +1255,7 @@ choose_board(int newflag) break; switch(c){ case '1': - favclean(fav); + cleanup(); break; case '2': setuserfile(fname, FAV3); @@ -1361,7 +1263,7 @@ choose_board(int newflag) system(genbuf); break; case '3': - setuserfile(fname, FAV3); + setuserfile(fname, FAV4); sprintf(genbuf, "%s.bak", fname); if((fd = open(genbuf, O_RDONLY)) < 0){ vmsg("你沒有備份你的最愛喔"); @@ -1383,8 +1285,6 @@ choose_board(int newflag) vmsg("嘿嘿 這個功\能已經被我的最愛取代掉了喔!"); break; case 'Z': - if (!HAS_PERM(PERM_BASIC)) - break; cuser.uflag2 ^= FAVNEW_FLAG; if(cuser.uflag2 & FAVNEW_FLAG){ char fname[80]; @@ -1438,6 +1338,7 @@ choose_board(int newflag) break; } num = tmp; + fav_cursor_set(num); break; case 'E': if (HAS_PERM(PERM_SYSOP) || (currmode & MODE_MENU)) { @@ -1470,6 +1371,14 @@ choose_board(int newflag) brdnum = -1; } break; + case 'A': { + char buf[128]; + fav_type_t *ft = get_current_entry(); + fav_t *fp = get_current_fav(); + sprintf(buf, "d: %d b: %d f: %d bn: %d num: %d t: %d, id: %d", fp->nDatas, fp->nBoards, fp->nFolders, brdnum, num, ft->type, fav_getid(ft)); + vmsg(buf); + } + break; case KEY_RIGHT: case '\n': case '\r': @@ -1480,6 +1389,17 @@ choose_board(int newflag) ptr = &nbrd[num]; if(ptr->myattr & BRD_LINE) break; + else if (ptr->myattr & BRD_FOLDER){ + int t = num; + fav_folder_in(); + choose_board(0); + fav_folder_out(); + num = t; + fav_cursor_set(num); + brdnum = -1; + head = 9999; + break; + } if (!(B_BH(ptr)->brdattr & BRD_GROUPBOARD)) { /* 非sub class */ if (!(B_BH(ptr)->brdattr & BRD_HIDE) || -- cgit v1.2.3